alexjercan/bugnet huggingface dataset:
Problem p01300 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
#include <vector>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;

const int MOD = 11;

int main() {
  string in;

  while (cin >> in, in != "0") {
    int len = in.size();
    VVI dp(len, VI(MOD, 0));

    int ans = 0;
    dp[0][in[0] - '0'] = in[0] - '0' ? 1 : 0;
    for (int i = 1; i < len; ++i) {
      int x = in[i] - '0';
      for (int j = 0; j < MOD; ++j) {
        dp[i][(j * 10 + x) % MOD] += dp[i - 1][j];
      }
      if (x) {
        ++dp[i][x];
      }
      ans += dp[i][0];
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
#include <vector>

using namespace std;

typedef vector<int> VI;

int main() {
  string in;

  while (cin >> in, in != "0") {
    int len = in.size();
    VI odd_sum(len, 0), even_sum(len, 0);

    odd_sum[1] = in[1] - '0';
    even_sum[0] = in[0] - '0';

    for (int i = 3; i < len; i += 2) {
      odd_sum[i] += in[i] - '0' + odd_sum[i - 2];
    }
    for (int i = 2; i < len; i += 2) {
      even_sum[i] += in[i] - '0' + even_sum[i - 2];
    }

    int ans = 0;

    for (int i = 0; i < len; ++i) {
      if (in[i] == '0') {
        //++ans;
        continue;
      }
      for (int j = i + 1; j < len; ++j) {
        int o_h, o_t, e_h, e_t, sub_sum = 0;
        bool isOdd1 = i % 2, isOdd2 = j % 2, isEven1 = !isOdd1,
             isEven2 = !isOdd2;

        if (isOdd1 && isOdd2) {
          o_h = i;
          o_t = j;
          e_h = i + 1;
          e_t = j - 1;
        } else if (isOdd1 && isEven2) {
          o_h = i;
          o_t = j - 1;
          e_h = i + 1;
          e_t = j;
        } else if (isEven1 && isOdd2) {
          o_h = i + 1;
          o_t = j;
          e_h = i;
          e_t = j - 1;
        } else if (isEven1 && isEven2) {
          o_h = i + 1;
          o_t = j - 1;
          e_h = i;
          e_t = j;
        }
        sub_sum = (odd_sum[o_t] - odd_sum[o_h] + (in[o_h] - '0')) -
                  (even_sum[e_t] - even_sum[e_h] + (in[e_h] - '0'));
        if (sub_sum % 11 == 0) {
          ++ans;
        }
      }
    }

    cout << ans << endl;
  }
  return 0;
}
Problem p01303 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int X, Y, W, H, N, n;
  cin >> n;
  for (int j = 0; j < n; j++) {
    int count = 0;
    int x, y;
    cin >> X >> Y >> W >> H >> N;
    for (int i = 0; i < N; i++) {
      cin >> x >> y;
      if (X <= x && (X + W) >= x && Y <= y && (Y + H) >= y)
        count++;
    }
    cout << count << "\\n";
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int X, Y, W, H;
int serch(int x, int y) {
  if (X <= x && (X + W) >= x && Y <= y && (Y + H) >= y)
    return 1;
}
int main() {
  int n;
  cin >> n;
  for (int j = 0; j < n; j++) {
    int N, x, y, count = 0;
    cin >> X >> Y >> W >> H >> N;
    for (int i; i = N; i++) {
      cin >> x >> y;
      if (serch(x, y) == 1)
        count++;
    }
    cout << count << "\\n";
  }
  return 0;
}
Problem p01304 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int k;
  cin >> k;
  for (int i = 0; i < k; i++) {
    int gx, gy;
    cin >> gx >> gy;
    int p;
    cin >> p;
    int A[16][16][16][16] = {};
    for (int j = 0; j < p; j++) {
      int a, b, c, d;
      cin >> a >> b >> c >> d;
      A[a][b][c][d] = 1;
    }
    int B[16][16] = {};
    B[0][0] = 1;
    for (int t = 0; t <= gx; t++) {
      for (int j = 0; j <= gy; j++) {
        if (j == 0) {
          if (t != 0) {
            if (A[t - 1][0][t][0] == 0 && A[t][0][t - 1][0] == 0) {
              B[t][0] = B[t - 1][0];
            }
          }
        } else {
          if (t == 0) {
            if (A[0][j - 1][0][j] == 0 && A[0][j][0][j - 1] == 0) {
              B[0][j] = B[0][j - 1];
            }
          } else {
            if (A[t][j - 1][t][j] == 0 && A[t][j][t][j - 1] == 0) {
              B[t][j] += B[t][j - 1];
            }
            if (A[t - 1][j][t][j] == 0 && A[t][j][t - 1][j] == 0) {
              B[t][j] += B[t - 1][j];
            }
          }
        }
      }
    }
    if (B[gx][gy] == 0) {
      cout << "Miserable Hokusai!" << endl;
    } else {
      cout << B[gx][gy] << endl;
    }
  }
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int k;
  cin >> k;
  for (int i = 0; i < k; i++) {
    int gx1, gy1;
    cin >> gx1 >> gy1;
    const int gx = gx1;
    const int gy = gy1;
    int p;
    cin >> p;
    int A[15][15][15][15] = {};
    for (int j = 0; j < p; j++) {
      int a, b, c, d;
      cin >> a >> b >> c >> d;
      A[a][b][c][d] = 1;
    }
    int B[15][15] = {};
    B[0][0] = 1;
    for (int j = 0; j < gx; j++) {
      for (int t = 0; t < gy; t++) {
        if (j == 0) {
          if (t != 0) {
            if (A[t - 1][0][t][0] == 0) {
              B[t][0] = B[t - 1][0];
            }
          }
        } else {
          if (t == 0) {
            if (A[0][j - 1][0][j] == 0) {
              B[0][t] = B[0][t - 1];
            }
          } else {
            if (A[j - 1][t][j][t] == 0) {
              B[j][t] += B[j - 1][t];
            }
            if (A[j][t - 1][j][t] == 0) {
              B[j][t] += B[j][t - 1];
            }
          }
        }
      }
    }
    if (B[gx][gy] == 0) {
      cout << "Miserable Hokusai!" << endl;
    } else {
      cout << B[gx][gy] << endl;
    }
  }
}
Problem p01304 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  int a[20][20];
  int mata[20][20][20][20];
  int x, y, z, w, s, x1, y1, matatabi;
  cin >> s;
  for (int i = 0; i < s; i++) {
    cin >> x1 >> y1;
    for (int b = 0; b < 20; b++) {
      for (int c = 0; c < 20; c++) {
        a[b][c] = 0;
      }
    }
    a[0][0] = 1;
    for (int d = 0; d < 20; d++) {
      for (int e = 0; e < 20; e++) {
        for (int f = 0; f < 20; f++) {
          for (int g = 0; g < 20; g++) {
            mata[d][e][f][g] = 0;
          }
        }
      }
    }

    cin >> matatabi;
    for (int j = 0; j < matatabi; j++) {
      cin >> x >> y >> z >> w;
      mata[x][y][z][w] = 1;
    }
    for (int k = 0; k < x1; k++) {
      if (mata[k][0][k + 1][0] != 1 && mata[k + 1][0][k][0] != 1) {
        a[k + 1][0] = a[k][0];
      }
    }
    for (int l = 0; l < y1; l++) {
      if (mata[0][l][0][l + 1] != 1 && mata[0][l + 1][0][l] != 1) {
        a[0][l + 1] = a[0][l];
      }
    }
    for (int m = 1; m < y1 + 1; m++) {
      for (int n = 1; n < x1 + 1; n++) {
        if (mata[n - 1][m][n][m] != 1 && mata[n][m][n - 1][m] != 1) {
          a[n][m] += a[n - 1][m];
        }
        if (mata[n][m - 1][n][m] != 1 && mata[n][m][n][m - 1] != 1) {
          a[n][m] += a[n][m - 1];
        }
      }
    }

    if (a[x1][y1] == 0) {
      cout << "Miserable Hokusai!" << endl;
    } else {
      cout << a[x1][y1] << endl;
    }
  }
  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int times;
  int a[100][100] = {0};
  int m[100][100][100][100] = {0};
  int x, y, z, w, mata, x1, y1;
  a[0][0] = 1;
  cin >> times;
  for (int i = 0; i < times; i++) {
    cin >> x1 >> y1;
    cin >> mata;
    for (int j = 0; j < mata; j++) {
      cin >> x >> y >> z >> w;
      m[x][y][z][w] = 1;
    }
    for (int k = 0; k < x1; k++) {
      if (m[k][0][k + 1][0] != 1)
        a[k + 1][0] = a[k][0];
    }
    for (int l = 0; l < y1; l++) {
      if (m[0][l][0][l + 1] != 1)
        a[0][l + 1] = a[0][l];
    }
    for (int p = 0; p < y1 - 1; p++) {
      for (int q = 0; q < x1 - 1; q++) {
        if (m[q][p + 1][q + 1][p + 1] != 1) {
          a[q + 1][p + 1] += a[q][p + 1];
        }
        if (m[q + 1][p][q + 1][p + 1] != 1) {
          a[q + 1][p + 1] += a[q + 1][p];
        }
      }
    }
    if (a[x1][y1] == 0)
      cout << "Miserable Hokusai!" << endl;
    else
      cout << a[x1][y1] << endl;
  }
  return 0;
}
Problem p01304 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;
int a[16][16], mata[16][16];
int x, y, x1, x2, y1, y2, N, p;
void init() {
  for (int l = 0; l < 16; ++l) {
    for (int m = 0; m < 16; ++m)
      mata[l][m] = a[l][m] = 0;
  }
}

int main() {
  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> x >> y;
    cin >> p;
    init();
    for (int k = 0; k < p; ++k) {
      cin >> x1 >> y1 >> x2 >> y2;
      if (x1 == x2)
        mata[x1][min(y1, y2)] += 1;
      else
        mata[min(x1, x2)][y1] += 10;
    }
    for (int l = 0; l < y + 1; ++l) {
      for (int m = 0; m < x + 1; ++m) {
        if (m == 0 && l == 0)
          a[m][l] = 1;
        if (m != 0 && mata[m - 1][l] / 10 == 0)
          a[m][l] += a[m - 1][l];
        if (l != 0 && mata[m][l - 1] % 10 == 0)
          a[m][l] += a[m][l - 1];
      }
    }
    if (a[x][y] == 0)
      cout << "Miserable Hokusai!" << endl;
    else
      cout << a[x][y] << endl;
  }
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int a[16][16], mata[16][16];
int x, y, x1, x2, y1, y2, N, p;
void init() {
  for (int l = 0; l < 16; ++l) {
    for (int m = 0; m < 16; ++m)
      mata[l][m] = a[l][m] = 0;
  }
}

int main() {
  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> x >> y;
    cin >> p;
    init();
    for (int k = 0; k < p; ++k) {
      cin >> x1 >> y1 >> x2 >> y2;
      if (x1 == x2)
        mata[x1 - 1][max(y1, y2) - 1] += 1;
      else
        mata[max(x1, x2) - 1][y1 - 1] += 10;
    }
    for (int l = 0; l < y; ++l) {
      for (int m = 0; m < x; ++m) {
        if (m == 0 && l == 0)
          a[m][l] = 1;
        if (m != 0 && mata[m][l] % 10 == 0)
          a[m][l] += a[m - 1][l];
        if (l != 0 && mata[m][l] / 10 == 0)
          a[m][l] += a[m][l - 1];
      }
    }
    if (a[x - 1][y - 1] == 0)
      cout << "Miserable Hokusai!" << endl;
    else
      cout << a[x - 1][y - 1] << endl;
  }
}
Problem p01304 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int mt[16][16][16][16];
int dp[16][16];
int i, j, k, l, m, n, o, a, b, c, d, cnt, X, Y;
void init() {
  for (int i = 0; i < 16; i++) {
    for (int j = 0; j < 16; j++) {
      dp[i][j] = 0;
      for (int k = 0; k < 16; k++) {
        for (int l = 0; l < 16; l++) {
          mt[i][j][k][l] = 0;
        }
      }
    }
  }
}
int main() {
  int n;
  cin >> n;
  for (int data = 0; data < n; data++) {
    init();
    cin >> X >> Y >> m;
    for (int i = 0; i < m; i++) {
      cin >> a >> b >> c >> d;
      mt[a][b][c][d] = 1;
      mt[c][d][a][b] = 1;
    }
    dp[0][0] = 1;
    for (int i = 1; i <= X; i++) {
      if (mt[i][0][i - 1][0] == 1) {
        dp[i][0] = 0;
      } else {
        dp[i][0] = dp[i - 1][0];
      }
    }

    for (int i = 1; i <= Y; i++) {

      if (mt[0][i][0][i - 1]) {
        dp[0][i] = 0;
      } else {
        dp[0][i] = dp[0][i - 1];
      }

      for (int j = 1; j <= X; j++) {
        if (mt[j][i][j - 1][i] == 0) {
          dp[j][i] += dp[j - 1][i];
        }
        if (mt[j][i][j][i - 1] == 0) {
          dp[j][i] += dp[j][i - 1];
        }
      }
    }
    if (dp[X][Y] == 0) {
      cout << "Miserable Hokusai!" << endl;
    } else {
      cout << dp[X][Y] << endl;
    }
  }
  return 0;
}

Error: 4

Fixed submission:

#include <iostream>
using namespace std;
int mt[16][16][16][16];
int dp[16][16];
int i, j, k, l, m, n, o, a, b, c, d, cnt, X, Y;
void init() {
  for (int i = 0; i < 16; i++) {
    for (int j = 0; j < 16; j++) {
      dp[i][j] = 0;
      for (int k = 0; k < 16; k++) {
        for (int l = 0; l < 16; l++) {
          mt[i][j][k][l] = 0;
        }
      }
    }
  }
}
int main() {
  int n;
  cin >> n;
  for (int data = 0; data < n; data++) {
    init();
    cin >> X >> Y >> m;
    for (int i = 0; i < m; i++) {
      cin >> a >> b >> c >> d;
      mt[a][b][c][d] = 1;
      mt[c][d][a][b] = 1;
    }
    dp[0][0] = 1;
    for (int i = 1; i <= X; i++) {
      if (mt[i][0][i - 1][0] == 1) {
        dp[i][0] = 0;
      } else {
        dp[i][0] = dp[i - 1][0];
      }
    }

    for (int i = 1; i <= Y; i++) {

      if (mt[0][i][0][i - 1]) {
        dp[0][i] = 0;
      } else {
        dp[0][i] = dp[0][i - 1];
      }

      for (int j = 1; j <= X; j++) {
        if (mt[j][i][j - 1][i] == 0) {
          dp[j][i] += dp[j - 1][i];
        }
        if (mt[j][i][j][i - 1] == 0) {
          dp[j][i] += dp[j][i - 1];
        }
      }
    }
    if (dp[X][Y] == 0) {
      cout << "Miserable Hokusai!" << endl;
    } else {
      cout << dp[X][Y] << endl;
    }
  }
  return n;
}
Problem p01304 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;
int N, X, Y, ct, output[1000];
int main() {
  cin >> N;
  for (int g = 0; g < N; ++g) {
    cin >> X >> Y >> ct;
    int T[64][64] = {{0}}, up[200][200] = {{0}}, left[200][200] = {{0}};
    for (int i = 0; i < ct; ++i) {
      int x1, x2, y1, y2;
      cin >> x1 >> y1 >> x2 >> y2;
      if (x1 == x2)
        up[x1][max(y1, y2)] = 1;
      else
        left[max(x1, x2)][y1] = 1;
    }
    T[0][0] = 1;
    for (int x = 0; x <= X; ++x) {
      for (int y = 0; y <= Y; ++y) {
        if (up[x][y] == 0)
          T[x][y] += T[x][y - 1];
        if (left[x][y] == 0)
          T[x][y] += T[x - 1][y];
      }
    }
    output[g] = T[X][Y];
  }
  for (int i = 0; i < N; ++i) {
    if (output[i] == 0)
      cout << "Miserable Hokusai!" << endl;
    else
      cout << output[i] << endl;
  }
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int N, X, Y, ct, output[10];
int main() {
  cin >> N;
  for (int g = 0; g < N; ++g) {
    cin >> X >> Y >> ct;
    int T[64][64] = {{0}}, up[64][64] = {{0}}, left[64][64] = {{0}};
    for (int i = 0; i < ct; ++i) {
      int x1, x2, y1, y2;
      cin >> x1 >> y1 >> x2 >> y2;
      if (x1 == x2)
        up[x1][max(y1, y2)] = 1;
      else
        left[max(x1, x2)][y1] = 1;
    }
    T[0][0] = 1;
    for (int x = 0; x <= X; ++x) {
      for (int y = 0; y <= Y; ++y) {
        if (up[x][y] == 0)
          T[x][y] += T[x][y - 1];
        if (left[x][y] == 0)
          T[x][y] += T[x - 1][y];
      }
    }
    output[g] = T[X][Y];
  }
  for (int i = 0; i < N; ++i) {
    if (output[i] == 0)
      cout << "Miserable Hokusai!" << endl;
    else
      cout << output[i] << endl;
  }
}
Problem p01307 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

/* constant */

const int MAX_N = 1000;

/* typedef */

typedef map<string, bool> msb;

/* global variables */

int n;
int ds[MAX_N];

/* subroutines */

/* main */

int main() {
  int tn;
  cin >> tn;

  while (tn--) {
    string num;
    cin >> num;

    n = num.length();

    for (int i = 0; i < n; i++)
      ds[i] = num[i] - '0';

    int count = 0;
    while (n > 1) {
      count++;
      int sum = ds[n - 2] + ds[n - 1];
      if (sum < 10) {
        n--;
        ds[n - 1] = sum;
      } else {
        ds[n - 2] = 1;
        ds[n - 1] = sum % 10;
      }
    }
    // cout << count << endl;

    cout << ((count & 1) ? "Fabre" : "Audrey") << " wins." << endl;
  }

  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;

/* constant */

/* typedef */

typedef map<string, bool> msb;

/* global variables */

msb cache;

/* subroutines */

bool rec(string num) {
  msb::iterator mit = cache.find(num);
  if (mit != cache.end())
    return mit->second;

  int len = num.length();
  int prv = num[0] - '0';

  for (int i = 1; i < len; i++) {
    int cur = num[i] - '0';
    stringstream ss;
    for (int j = 0; j < i - 1; j++)
      ss << num[j];
    ss << (prv + cur);
    for (int j = i + 1; j < len; j++)
      ss << num[j];
    bool win = rec(ss.str());
    if (!win)
      return (cache[num] = true);
    prv = cur;
  }

  return (cache[num] = false);
}

/* main */

int main() {
  int tn;
  cin >> tn;

  while (tn--) {
    string num;
    cin >> num;

    cache.clear();
    for (char ch = '0'; ch <= '9'; ch++) {
      string d(1, ch);
      cache[d] = false;
    }

    bool fwin = rec(num);
    cout << (fwin ? "Fabre" : "Audrey") << " wins." << endl;
  }

  return 0;
}
Problem p01307 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
using namespace std;
// kaewasuretyuui
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int, pii> pip;
typedef vector<pip> vip;
const double PI = acos(-1);
const double EPS = 1e-8;
const int inf = 1e8;
string to_str(int a) {
  string s = "";
  while (a) {
    s = (char)(a % 10 + '0') + s;
    a /= 10;
  }
  if (s == "")
    s = "0";
  return s;
}
int main() {
  int q;
  cin >> q;
  while (q--) {
    string s;
    cin >> s;
    int out = 0;
    while (s.size() != 1) {
      int t = s[0] + s[1] - '0' - '0';
      s = to_str(t) + s.substr(2);
      out ^= 1;
    }
    if (!out)
      cout << "Audrey wins." << endl;
    else
      cout << "Fabre wins." << endl;
  }
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
using namespace std;
// kaewasuretyuui
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int, pii> pip;
typedef vector<pip> vip;
const double PI = acos(-1);
const double EPS = 1e-8;
const int inf = 1e8;
vector<map<string, int>> m;
string F(char a, char b) {
  int t = a + b - '0' - '0';
  string s = "";
  while (t) {
    s = (char)(t % 10 + '0') + s;
    t /= 10;
  }
  if (s == "")
    s = "0";
  return s;
}
int f(string s, int r) {
  if (s.size() < 2)
    return 2;
  if (m[r][s])
    return m[r][s];
  bool h = false;
  rep(i, s.size() - 1) {
    string t = s.substr(0, i) + F(s[i], s[i + 1]) + s.substr(i + 2);
    if (f(t, r ^ 1) == 1)
      h = true;
  }
  return m[r][s] = h + 1;
}
int main() {
  m = vector<map<string, int>>(2);
  int q;
  cin >> q;
  while (q--) {
    string s;
    cin >> s;
    if (f(s, 0) == 2)
      cout << "Audrey wins." << endl;
    else
      cout << "Fabre wins." << endl;
  }
}
Problem p01307 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int main() {
  int n;
  cin >> n;
  while (n--) {
    string str;
    cin >> str;
    int sum = 0;
    for (int i = 0; i < str.size(); i++)
      sum += (str[i] - '0');
    // Jèãªéñ
    int ct = 0;
    int s = sum;
    while (s >= 10) {
      ct += s / 10;
      int left = s % 10 + s / 10;
      s = left;
    }
    int cnt = ct + str.size() - 1;
    if (cnt % 2 == 0)
      cout << "Audrey ";
    else
      cout << "Fabre ";
    cout << "wins." << endl;
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <sstream>
#include <string>

using namespace std;

// ツ個サツ催敖づ個湘ウツ妥板づタツーツδ督つェツ嘉アツづづつォツつスツ人ツつェツ渉淞づづゥツつゥツづつ、ツつゥ
map<string, bool> dp;

bool dfs(string str, bool tern) {
  if (str.size() == 1)
    return false;
  else if (dp.find(str) != dp.end()) {
    // ツ堕環偲ィツつェツ渉淞づづゥツづ按づァtrue
    bool res = dp[str];
    return dp[str];
  }
  bool ok = false;
  for (int i = 0; i < str.size() - 1; i++) {
    int sum = str[i] + str[i + 1] - '0' - '0';
    stringstream ss;
    ss << sum;
    string s = ss.str();
    string nstr = str.substr(0, i) + s + str.substr(i + 2);
    // cout<<nstr<<endl;
    bool res = !(dfs(nstr, !tern));
    if (res) {
      ok = true;
      break;
    }
  }
  return dp[str] = ok;
}

int main() {

  int n;
  cin >> n;
  while (n--) {
    string str;
    cin >> str;
    bool res = dfs(str, true);
    if (!res)
      cout << "Audrey ";
    else
      cout << "Fabre ";
    cout << "wins." << endl;
  }

  return 0;
}
Problem p01307 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i, j) for (int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for (int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())

int main() {
  int T;
  cin >> T;
  while (T--) {
    string N;
    cin >> N;
    int cnt = 0;
    while (N.length() > 1) {
      int m = (N[0] - '0') + (N[1] - '0');
      stringstream ss;
      ss << m;
      N = ss.str() + N.substr(2);
      ++cnt;
    }
    cout << (cnt % 2 ? "Fabre wins." : "Audrey wins.") << endl;
  }
  return 0;
}

Error: MLE

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i, j) for (int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for (int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef pair<string, bool> P;

map<P, bool> memo;

bool solve(string n, bool t) {
  if (memo.find(P(n, t)) != memo.end())
    return memo[P(n, t)];
  if (n.length() <= 1) {
    if (t == 0)
      return memo[P(n, t)] = 0;
    else
      return memo[P(n, t)] = 1;
  }
  bool ret = (t ? 1 : 0);
  REP(i, (int)n.length() - 1) {
    int m = (n[i] - '0') + (n[i + 1] - '0');
    stringstream ss;
    ss << m;
    bool r = solve(n.substr(0, i) + ss.str() + n.substr(i + 2), (t + 1) % 2);
    if (t && !r)
      ret = 0;
    if (!t && r)
      ret = 1;
  }
  return memo[P(n, t)] = ret;
}

int main() {
  int T;
  cin >> T;
  while (T--) {
    memo = map<P, bool>();
    string N;
    cin >> N;
    cout << (solve(N, 0) ? "Fabre wins." : "Audrey wins.") << endl;
    // cout <<memo.size() <<endl;
    // for(auto i : memo) cout <<i.first.first <<", " <<i.first.second <<" : "
    // <<i.second <<endl;
  }
  return 0;
}