#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 NN, the number of swaps (1N1001\le N\le 100). The next NN lines each describe one round of the game and contain three integers aa, bb, and gg, meaning Bessie swaps shells aa and bb, and then Elsie guesses shell gg. All three numbers are one of 11, 22, 33, and aba\neq b.

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 22 points. If the pebble starts under shell 11, then she guesses correctly once (the last time). If the pebble starts under shell 22, then she guesses correctly twice (the first two times). If the pebble starts under shell 33, then she does not guess correctly even once.

Translated by ChatGPT 5