int max = 0; int l = -1, r = -1; for (int i = 0; i < n; i++) { int j = i; int zero = 0, one = 0; while (s[j] == '0') { j++; zero++; } while (s[j] == '1') { j++; one++; } if (zero + one > max && zero != 0 && one != 0) { max = zero + one; l = i, r = j - 1; } } int ans = 1; if (l == -1 && r == -1) { ans = 0; for (int i = 0; i < n; i++) { int j = i; bool ok = false; while (j < n && s[j] == '0') { j++; ok = true; } if (ok) { ans++; i = j - 1; } } for (int i = 0; i < n; i++) { int j = i; bool ok = false; while (j < n && s[j] == '1') { j++; ok = true; } if (ok) { ans++; i = j - 1; } } } else { for (int i = 0; i < l; i++) { int j = i; bool ok = false; while (j < l && s[j] == '0') { j++; ok = true; } if (ok) { ans++; i = j - 1; } } for (int i = 0; i < l; i++) { int j = i; bool ok = false; while (j < l && s[j] == '1') { j++; ok = true; } if (ok) { ans++; i = j - 1; } } for (int i = r + 1; i < n; i++) { int j = i; bool ok = false; while (j < n && s[j] == '0') { j++; ok = true; } if (ok) { ans++; i = j - 1; } } for (int i = r + 1; i < n; i++) { int j = i; bool ok = false; while (j < n && s[j] == '1') { j++; ok = true; } if (ok) { ans++; i = j - 1; } } } std::cout << ans << "\n"; }
i64 ans = 0; for (i64 i = -r; i <= r; i++) { i64 small = 1LL * r * r - i * i; i64 big = 1LL * (r + 1) * (r + 1) - i * i - 1; ans += 2 * static_cast<i64>(sqrtl(big) - ceil(sqrtl(small)) + 1); } std::cout << ans - 2 << "\n"; }