#include #include #include using namespace std; int main() { int n; cin >> n; if (n == 2) { cout << 1 << endl; return 0; } vector t(n - 2), s(n - 2), d(n - 2); int cd = 1; string cur; cin >> cur; int single_idx = -1; for (int i = 0; i < n - 2; i++) { cin >> cur; for (int j = 0; j < cur.length() - 1; j++) { if (cur[j] == 't') t[i]++; else s[i]++; } if (cur[cur.length() - 1] == '{') d[i] = cd++; else d[i] = --cd; if (d[i] == 1) single_idx = i; } if (single_idx == -1) { cout << 1 << endl; return 0; } for (int ans = 1; ans <= 1000; ans++) { int k = t[single_idx] * ans + s[single_idx]; bool ok = true; for (int i = 0; i < n - 2; i++) { if (t[i] * ans + s[i] != d[i] * k) { ok = false; break; } } if (ok) { cout << ans << endl; return 0; } } cout << -1 << endl; return 0; }