#include <bits/stdc++.h>
using namespace std;


vector<string> detonate(const vector<string>& grid) {
    int rows = grid.size();
    int cols = grid[0].size();
    vector<string> result(rows, string(cols, 'O')); // Create a grid full of bombs



           cout<<"before detonating"<<endl;
           
         for (int i = 0; i < rows; ++i) {
        for (int j = 0; j < cols; ++j) {
              cout<<result[i][j]<<" ";
        }
        cout<<endl;
       }
       
       
    for (int i = 0; i < rows; ++i) {
        for (int j = 0; j < cols; ++j) {
            if (grid[i][j] == 'O') {
                // Detonate bomb and clear surrounding cells
                result[i][j] = '.';
                if (i > 0) result[i - 1][j] = '.';
                if (i < rows - 1) result[i + 1][j] = '.';
                if (j > 0) result[i][j - 1] = '.';
                if (j < cols - 1) result[i][j + 1] = '.';
            }
        }
    }
    
    
        cout<<"After detonating"<<endl;
           
         for (int i = 0; i < rows; ++i) {
        for (int j = 0; j < cols; ++j) {
              cout<<result[i][j]<<" ";
        }
        cout<<endl;
       }
    return result;
}

vector<string> bomberMan(int n, vector<string> grid) {
      if (n == 1) return grid;
    if (n % 2 == 0) return vector<string>(grid.size(), string(grid[0].size(), 'O'));

    vector<string> firstDetonation = detonate(grid);
    vector<string> secondDetonation = detonate(firstDetonation);

   // intial state at 1
   // 3->7->11>15->19 this all will be same as 1st state
   // 5->9>13->17->21 this all will be asme as 2nd state
   // 1st state find if(n%4 == 3) that means it there is the 1st state grid
   // 2nd state finding if (n%4 == 1) RETURN the 2nd second State Grid
      if(n%4 == 1) return secondDetonation;
      return firstDetonation;
  }
  
  
int main() 
{
   int rows = 3;
    int cols = 3;
    vector<string> grid(rows, string(cols, '.'));

    grid[1][1] = 'O';
    
     vector<string> st = bomberMan(11,grid);
     
    // for(int i = 0; i<st.size(); i++){
    //   for(int j = 0; j<st[i].size(); j++){
    //     cout<<st[i][j]<<" ";
    //   }
    //   cout<<endl;
    // }
    return 0;
} 
by