#include #include #include using namespace std; int main() { int nmbTiles; string input; cin >> nmbTiles; cin >> input; vector xCount; vector oCount; int xSum = 0; int oSum = 0; xCount.push_back(xSum); oCount.push_back(oSum); for (int i = 0; i < input.size(); i++) { if (input[i] == 'X') { xSum++; } else { oSum++; } xCount.push_back(xSum); oCount.push_back(oSum); } int out = 0; for (size_t right = 0; right <= input.size(); right++) { for (int left = 0; left < right; left++) { int xInside = xCount[right] - xCount[left]; int oInside = oCount[right] - oCount[left]; if (oInside == 0 || xInside < 8) { break; } int n = (int)sqrt(oInside); if (n * n != oInside) { continue; // skip if O is not n^2 } int xExpected = 4 * n + 4; if (xInside == xExpected) { out++; } } } int out2 = 0; for (size_t right = 0; right <= input.size(); right++) { for (int left = 0; left < right; left++) { int oInside = xCount[right] - xCount[left]; int xInside = oCount[right] - oCount[left]; if (oInside == 0 || xInside < 8) { break; } int n = (int)sqrt(oInside); if (n * n != oInside) { continue; // skip if O is not n^2 } if (xInside == 4 * n + 4) { out2++; } } } int sum = out + out2; cout << sum << endl; // // int out = 0; // for (size_t i = 0; i < input.size(); i++) { // for (int j = 0; j < i; j++) { // // int xCount = 0, oCount = 0; // for (int k = j; k <= i; k++) { // if (input[k] == 'X') { // xCount++; // } else { // oCount++; // } // } // // int n = (int)sqrt(oCount); // if (n * n != oCount || oCount == 0) { // continue; // skip if O is not n^2 // } // // if (xCount == 4 * n + 4) { // out++; // } // } // } // // int out2 = 0; // for (size_t i = 0; i < input.size(); i++) { // for (int j = 0; j < i; j++) { // // int xCount = 0, oCount = 0; // for (int k = j; k <= i; k++) { // if (input[k] == 'O') { // xCount++; // } else { // oCount++; // } // } // // int n = (int)sqrt(oCount); // if (n * n != oCount || oCount == 0) { // continue; // skip if O is not n^2 // } // // if (xCount == 4 * n + 4) { // out2++; // } // } // } // // int sum = out + out2; // cout << sum << endl; return 0; }