#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); } }; } 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; ) { 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 sx = sqrt((double) x_count); ll sy = sqrt((double) y_count); ll diff = 1; if (sx * sx == x_count && (sx + 1) * 4 == y_count) { possible++; } else { diff = min(abs((sx + 1) * 4 - y_count),diff); } if (sy * sy == y_count && (sy + 1) * 4 == x_count) { possible++; } else { diff = min(abs((sy + 1) * 4 - x_count),diff); } if(diff> 1) { right-= diff; } else { right--; } // for (int i = left; i < right; ++i) { // cout << acum[i]; // } // cout << ": " << x_count << ":" << y_count << endl; } } cout << possible << endl; return 0; }