Problem p03865 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<pint> vpint;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
#define each(it, v)                                                            \
  for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a) < (b)) ? (b) : (a))
#define chmin(a, b) a = (((a) > (b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;

int main(void) {
  string s;
  cin >> s;

  if (s.size() == 3 && s[0] == s[2]) {
    printf("Second\n");
    return 0;
  }

  rep(i, s.size() - 2) {
    if (s[i] != s[i + 2])
      break;
    if (i == s.size() - 3) {
      printf("Second\n");
      return 0;
    }
  }

  bool flag = false;
  for (int i = 1; i < s.size() - 1; ++i) {
    if (s[i] == s[0] && s[i] == s[s.size() - 1])
      flag = true;
  }

  if (flag) {
    if (s[0] != s[s.size() - 1]) {
      if (s.size() % 2 == 0) {
        printf("Second\n");
      } else {
        printf("First\n");
      }
    } else {
      if (s.size() % 2 == 1) {
        printf("Second\n");
      } else {
        printf("First\n");
      }
    }
    return 0;
  } else {
    if (s[0] == s[s.size() - 1]) {
      rep(i, 100000000000) {
        int j;
        j++;
      }
    } else {
      if (s.size() % 2 == 0) {
        printf("Second\n");
      } else {
        printf("First\n");
      }
    }
    return 0;
  }

  if (s.size() % 2 == 0) {
    printf("Second\n");
  } else {
    printf("First\n");
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<pint> vpint;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
#define each(it, v)                                                            \
  for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a) < (b)) ? (b) : (a))
#define chmin(a, b) a = (((a) > (b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;

int main(void) {
  string s;
  cin >> s;

  if (s.size() == 3 && s[0] == s[2]) {
    printf("Second\n");
    return 0;
  }

  rep(i, s.size() - 2) {
    if (s[i] != s[i + 2])
      break;
    if (i == s.size() - 3) {
      printf("Second\n");
      return 0;
    }
  }

  bool flag = false;
  for (int i = 1; i < s.size() - 1; ++i) {
    if (s[i] == s[0] && s[i] == s[s.size() - 1])
      flag = true;
  }

  if (flag) {
    if (s[0] != s[s.size() - 1]) {
      if (s.size() % 2 == 0) {
        printf("Second\n");
      } else {
        printf("First\n");
      }
    } else {
      if (s.size() % 2 == 1) {
        printf("Second\n");
      } else {
        printf("First\n");
      }
    }
    return 0;
  } else {
    if (s[0] == s[s.size() - 1]) {
      printf("First\n");
      return 0;
    } else {
      if (s.size() % 2 == 0) {
        printf("Second\n");
      } else {
        printf("First\n");
      }
    }
    return 0;
  }

  if (s.size() % 2 == 0) {
    printf("Second\n");
  } else {
    printf("First\n");
  }
  return 0;
}