#include <cstring> const int maxn = 5500; const int INF = 100243535; int a[maxn], f[maxn], cnt[maxn]; int () { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { char s[10]; scanf("%s", s); a[i] = (s[0] == 'F' ? 0 : 1); } for (int k = 1; k <= n; k++) { memset(f, 0, sizeof(f)); int turns = 0; for (int i = 0; i < n; i++) {
if ((a[i] + turns) % 2 == 1) { if (i + k > n) { cnt[k] = INF; break; } f[i] = 1; cnt[k]++; turns++; } if (i - k + 1 >= 0) turns -= f[i - k + 1];
} } int ansK = 1;
for (int k = 2; k <= n; k++) if (cnt[k] < cnt[ansK]) ansK = k;