#include #include using namespace std; int main() { freopen("shell.in", "r", stdin); freopen("shell.out", "w", stdout); int n; cin >> n; int score = 0; int a_values[n]; int b_values[n]; int g_values[n]; for (int i = 0; i < n; i++) { cin >> a_values[i] >> b_values[i] >> g_values[i]; } int shell_num; shell_num = 0; for (int i = 0; i < 3; i++) { shell_num = i + 1; for (int j = 0; j < n; j++) { int a, b, g; a = a_values[i]; b = b_values[i]; g = g_values[i]; if (a == shell_num) { shell_num = b; } else if (b == shell_num) { shell_num = a; } if (g == shell_num) { score++; } } } cout << score << endl; }