#include #include #include #include #include #include using namespace std; using ll = long long; #define umap unordered_map #define uset unordered_set #define int ll namespace std { template struct hash> { size_t operator()(const pair &a) const { return std::hash()(a.first) ^ (std::hash()(a.second) << 10); } }; } ll pascal(ll n, ll k) { static umap, ll> triangle; pair key = {n, k}; if (n == 0 || k == 0 || k == n) return 1; if (triangle.count(key)) { return triangle[key]; } ll a = pascal(n - 1, k - 1); ll b = pascal(n - 1, k); ll newVal = a + b; if (a < 0 || b < 0 || a + b < 0) { newVal = -1; } triangle[key] = newVal; return newVal; } signed main() { int cunt = 0; cin >> cunt; vector sumx(cunt + 1, 0); vector sumy(cunt + 1, 0); char current; string acum; for (int i = 0; i < cunt; ++i) { cin >> current; sumx[i + 1] = sumx[i] + (current == 'X'); sumy[i + 1] = sumy[i] + (current == 'O'); acum += current; // cout << current; } int possible = 0; for (int left = 0; left < cunt; ++left) { for (int right = cunt; right >= left; right--) { int x_count = sumx[right] - sumx[left]; int y_count = sumy[right] - sumy[left]; if (x_count > y_count) swap(x_count, y_count); if (x_count < 1 || y_count < 8) { break; } ll sqrtt = sqrt((double) x_count); if (sqrtt * sqrtt == x_count && (sqrtt + 1) * 4 == y_count) { possible++; if(x_count == y_count) possible++; // cout << "OK: "; } else { // cout << "Fricked: "; } // for (int i = left; i < right; ++i) { // cout << acum[i]; // } // cout << ": " << x_count << ":" << y_count << endl; } } cout << possible << endl; return 0; }