#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,0); vector sumy(cunt,0); char current; cin >> current; if(current == 'X') { sumx[0] = 1; } else { sumy[0] = 1; } for (int i = 1; i < cunt; ++i){ cin >> current; sumx[i] = sumx[i-1] + (current =='X'); sumy[i] = sumy[i-1] + (current =='O'); } int possible = 0; for(int right = cunt - 1; right >= 0 ; right--){ int x_count = sumx[right]; int y_count = sumy[right]; if(x_count == 0 || y_count == 0){ break; } if(x_count > y_count) swap(x_count,y_count); ll sqrtt = sqrt(x_count); if(sqrtt * sqrtt == x_count && (sqrtt+1)*4 == y_count) { possible ++; } } for (int left = 0; left < cunt; ++left){ for(int right = cunt - 1; right >= left ; right--){ int x_count = sumx[right] - sumx[left]; int y_count = sumy[right] - sumy[left]; if(x_count == 0 || y_count == 0){ break; } if(x_count > y_count) swap(x_count,y_count); ll sqrtt = sqrt(x_count); if(sqrtt * sqrtt == x_count && (sqrtt+1)*4 == y_count) { possible ++; } } } cout << possible << endl; return 0; }