Problem: Example

Input

2 2
..
..


Output

Second

Solution (in CPP):

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

int H,W;
char S[25][25];

int dp[25][25][25][25];

int solve(int x1,int y1,int x2,int y2){
  int &ret = dp[x1][y1][x2][y2];
  if( ret > -1 ) return ret;

  set<int> g;
  for(int x=x1;x<=x2;x++){
    for(int y=y1;y<=y2;y++){
      if( S[x][y] == 'X' ) continue;
      g.insert( solve(x1,y1,x-1,y-1) ^ solve(x+1,y1,x2,y-1) ^
                solve(x1,y+1,x-1,y2) ^ solve(x+1,y+1,x2,y2) );
    }
  }
  
  ret = 0;
  while( g.find( ret ) != g.end() ) ret++;
  return ret;
}

int main(){
  memset(dp,-1,sizeof(dp));
  cin >> H >> W;
  for(int i=1;i<=H;i++)
    for(int j=1;j<=W;j++)
      cin >> S[j][i];
  if( solve(1,1,W,H) ) cout << "First" << endl;
  else cout << "Second" << endl;
}