#P9958. [USACO19JAN] Shell Game B
[USACO19JAN] Shell Game B
Problem Description
To pass the time, the cow Bessie and her friend Elsie like to play a game they saw at an agricultural fair.
To set up the game, Bessie places three overturned shells on a table and hides a small pebble under one of the shells (at least she hopes it is a pebble—it was found on the ground in a pasture). Then Bessie swaps the shells in pairs, while Elsie tries to guess where the pebble is.
In the standard version of this game at the fair, the player can see the pebble’s initial position, and then must guess the pebble’s final position after all swaps are finished.
However, now the cows want to play a different version: Elsie does not know the pebble’s initial position, and she can make a guess after each swap. Bessie knows the correct answer, and at the end of the game she gives Elsie a score equal to the number of times Elsie guessed correctly.
Given all the swaps and Elsie’s guesses, but not the pebble’s initial position, find the maximum possible score Elsie can achieve.
Input Format
The first line contains an integer , the number of swaps (). The next lines each describe one round of the game and contain three integers , , and , meaning Bessie swaps shells and , and then Elsie guesses shell . All three numbers are one of , , , and .
Output Format
Output the maximum score Elsie can get.
3
1 2 1
3 2 1
1 3 1
2
Hint
Sample Explanation 1
In this example, Elsie can get at most points. If the pebble starts under shell , then she guesses correctly once (the last time). If the pebble starts under shell , then she guesses correctly twice (the first two times). If the pebble starts under shell , then she does not guess correctly even once.
Translated by ChatGPT 5