// // Problem: Step Aerobics // Solution by: MORI Shingo // O(n) // // #include #include int main() { int n; int test_case = 0; while (scanf("%d", &n) > 0 && n) { test_case++; int ans = 0; int state = 0; int next = 3; for (int i = 0; i < n; i++) { char c; int v = scanf(" %c %*c ", &c); assert(v == 1); int lr = (c == 'l') ? 1 : 0; state ^= (1 << lr); if (state == next) { ans++; next ^= 3; } } printf("%d\n", ans); } assert(test_case <= 150); }