inlinevoidmain(){ read(n), read(T); while (T--) { scanf("%s", s+1); len = strlen(s+1); tot = 0; memset(a, 0, sizeof a); for (int i = 1; i <= len; ++i) { if (s[i] == s[i-1]) a[tot]++; else a[++tot] = 1; } bool flag = false; for (int i = 1; i <= tot; ++i) { if (a[i] > 1) a[i] = 1, flag = true; else a[i] = 0; } if (!flag) continue; int l = tot >> 1, r = l + 1; while (l && !a[l]) l--; while (r <= tot && !a[r]) r++; if (!l) { ans += r; continue; } if (r > tot) { ans += tot - l + 1; continue; } if ((r - l) * 2 >= tot) ans += r - l + 1; else ans += tot / 2 + 1; } printf("%d\\n", ans); }