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

#include <bits/stdc++.h>
#define int long long
#define r(i, n) for (int i = 0; i < n; i++)
using namespace std;

int x, y, z, a, b, c, n, s, ans[1111], dp1[1000], dp2[1000], M[1000][1000];

signed main() {
  cin >> x >> y >> z >> a >> b >> c >> n;
  r(i, x) dp1[abs(a - i) % n]++;
  r(i, n) r(j, n) { M[i][j] = (j - i + n) % n; }
  r(i, y) {
    int Y = abs(b - i) % n;
    r(j, n) dp2[j] += dp1[M[Y][j]];
  }
  r(i, z) {
    int Z = abs(c - i) % n;
    r(j, n) ans[j] += dp2[M[Z][j]];
  }
  r(i, n) cout << (i ? " " : "") << ans[i];
  cout << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define int long long
#define r(i, n) for (int i = 0; i < n; i++)
using namespace std;

int x, y, z, a, b, c, n, s, ans[1111], dp1[1000], dp2[1000];

signed main() {
  cin >> x >> y >> z >> a >> b >> c >> n;
  r(i, x) dp1[abs(a - i) % n]++;
  r(i, y) {
    int Y = abs(b - i) % n;
    r(j, n) dp2[j] += dp1[(j - Y + n) % n];
  }
  r(i, z) {
    int Z = abs(c - i) % n;
    r(j, n) ans[j] += dp2[(j - Z + n) % n];
  }
  r(i, n) cout << (i ? " " : "") << ans[i];
  cout << endl;
}
Problem p01784 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;

P StoP(string a) {
  int top = 0, first = 0;
  for (int i = 0; i < a.size(); i++) {
    if (a[i] == '(')
      top++;
    else if (top)
      top--;
    else
      first++;
  }
  return P(first, top);
}

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

  P p[101];
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    string tmp;
    cin >> tmp;
    p[i] = StoP(tmp);
    if (!p[i].second)
      cnt += p[i].first, i--, n--;
  }

  bool ans = 1, used[101] = {};
  int top = 0;
  for (int i = 0; i < n && ans; i++) {
    int idx = -1, mx = -110;
    for (int j = 0; j < n; j++) {
      if (used[j] || top - p[j].first < 0)
        continue;
      int k = p[j].second - p[j].first;
      if (mx < k)
        mx = k, idx = j;
    }
    if (idx == -1)
      ans = 0;
    top += mx;
    used[idx] = 1;
  }
  cout << (ans && !(top - cnt) ? "Yes" : "No") << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
#include <stdio.h>
using namespace std;
#define MAX 103
struct kuohao {
  int left;
  int right;
  int nicha() { return left - right; }
};

bool operator<(kuohao a, kuohao b) { return a.nicha() < b.nicha(); }

kuohao strval[MAX];

int main() {
  // freopen("input.txt","r",stdin);

  int n;
  char a[103];
  while (~scanf("%d", &n)) {
    memset(strval, 0, sizeof(strval));
    for (int i = 0; i < n; i++) {
      cin >> a;
      bool primer = false;
      int alength = strlen(a);
      for (int j = 0; j < alength; j++)
        if (a[j] == ')')
          if (primer) {
            if (strval[i].right)
              strval[i].right--;
            else
              strval[i].left++;
          } else
            strval[i].left++;
        else {
          primer = true;
          strval[i].right++;
        }
      if (strval[i].left == 0) {
        if (strval[0].left == 0) {
          if (strval[i].right > strval[0].right) {
            kuohao a = strval[i];
            strval[i] = strval[0];
            strval[0] = a;
          }
        } else {
          kuohao a = strval[i];
          strval[i] = strval[0];
          strval[0] = a;
        }
      }
      if (strval[i].right == 0) {
        if (strval[n - 1].right == 0) {
          if (strval[i].left > strval[n - 1].left) {
            kuohao a = strval[i];
            strval[i] = strval[n - 1];
            strval[n - 1] = a;
          }
        } else {
          kuohao a = strval[i];
          strval[i] = strval[n - 1];
          strval[n - 1] = a;
        }
      }
    }
    int left = 0;
    bool primer = true;
    if (strval[0].left == 0 && strval[n - 1].right == 0) {
      sort(strval + 1, strval + n - 1);
      for (int i = 0; i < n; i++) {
        left -= strval[i].left;
        if (left < 0)
          break;
        left += strval[i].right;
      }
      if (left == 0)
        primer = false;
    }
    if (primer)
      printf("No\\n");
    else
      printf("Yes\\n");
  }

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

#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
template <class T> using Table = vector<vector<T>>;
const ld eps = 1e-9;

//// < "D:\\D_Download\\Visual Studio
///2015\\Projects\\programing_contest_c++\\Debug\\a.txt"
int main() {
  int N;
  cin >> N;
  vector<pair<int, int>> ps;
  for (int i = 0; i < N; ++i) {
    string st;
    cin >> st;
    int sum = 0;
    int amin = 0;
    int amax = 0;
    for (int j = 0; j < st.size(); ++j) {
      if (st[j] == '(') {
        sum++;
      } else {
        sum--;
        amin = min(amin, sum);
      }
    }
    ps.push_back(make_pair(-amin, sum));
  }
  int nsum = 0;
  sort(ps.begin(), ps.end(),
       [](const pair<int, int> &l, const pair<int, int> &r) {
         if (l.second >= 0 && r.second >= 0) {
           return l.first < r.first;
         } else if (l.second < 0 && r.second < 0) {
           return l.first + l.second > r.first + r.second;

         } else if (l.second >= 0) {
           return true;
         } else {
           return false;
         }
       });
  bool ok = true;
  for (auto p : ps) {
    if (nsum >= p.first) {
      nsum += p.second;
    } else {
      ok = false;
    }
    if (nsum < 0)
      ok = false;
  }
  if (ok && !nsum) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
template <class T> using Table = vector<vector<T>>;
const ld eps = 1e-9;

//// < "D:\\D_Download\\Visual Studio
///2015\\Projects\\programing_contest_c++\\Debug\\a.txt"
int main() {
  int N;
  cin >> N;
  vector<pair<int, int>> ps;
  for (int i = 0; i < N; ++i) {
    string st;
    cin >> st;
    int sum = 0;
    int amin = 0;
    int amax = 0;
    for (int j = 0; j < st.size(); ++j) {
      if (st[j] == '(') {
        sum++;
      } else {
        sum--;
        amin = min(amin, sum);
      }
    }
    ps.push_back(make_pair(-amin, sum));
  }
  int nsum = 0;
  sort(ps.begin(), ps.end(),
       [](const pair<int, int> &l, const pair<int, int> &r) {
         if (l.first == 0)
           return true;
         else if (r.first == 0)
           return false;
         else {
           return l.first - l.second < r.first - r.second;
         }
       });
  bool ok = true;
  for (auto p : ps) {
    if (nsum >= p.first) {
      nsum += p.second;
    } else {
      ok = false;
    }
    if (nsum < 0)
      ok = false;
  }
  if (ok && !nsum) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}
Problem p01784 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

int N;
vector<pair<int, int>> xs, ys;
vector<bool> vis;

int main() {

  cin >> N;
  vector<pair<int, int>> ls, rs;
  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    int M = S.size();
    int mini = 0, cnt = 0;
    for (int j = 0; j < M; j++) {
      if (S[j] == '(')
        cnt++;
      else
        cnt--;
      mini = min(mini, cnt);
    }
    if (cnt >= 0)
      ls.emplace_back(mini, cnt);

    cnt = 0, mini = 0;
    for (int j = M - 1; j >= 0; j--) {
      if (S[j] == ')')
        cnt++;
      else
        cnt--;
      mini = min(mini, cnt);
    }
    if (cnt > 0)
      rs.emplace_back(mini, cnt);
  }

  sort(ls.begin(), ls.end(),
       [&](pair<int, int> const &l, pair<int, int> const &r) {
         return l.first != r.first ? l.first > r.first : l.second > r.second;
       });
  sort(rs.begin(), rs.end(),
       [&](pair<int, int> const &l, pair<int, int> const &r) {
         return l.first != r.first ? l.first > r.first : l.second > r.second;
       });

  int sum1 = 0;
  bool ok = 1;
  for (int i = 0; i < ls.size(); i++) {
    if (sum1 + ls[i].first < 0) {
      ok = 0;
    }
    sum1 += ls[i].second;
  }

  int sum2 = 0;

  for (int i = 0; i < rs.size(); i++) {
    if (sum2 + rs[i].first < 0) {
      ok = 0;
    }
    sum2 += rs[i].second;
  }

  cout << (ls.size() + rs.size() == N && ok && sum1 == sum2 ? "Yes" : "No")
       << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int N;
vector<pair<int, int>> vs;
vector<bool> vis;

bool dfs(int idx, int sum, int vcnt) {
  if (vcnt == N)
    return true; // sum == 0;
  for (int i = 0; i < N; i++) {
    if (vis[i])
      continue;
    int maxdecl, diff;
    tie(maxdecl, diff) = vs[i];
    if (sum + maxdecl < 0)
      continue;
    vis[i] = 1;
    if (dfs(i, sum + diff, vcnt + 1))
      return true;
    vis[i] = 0;
  }
  return false;
}

int main() {

  cin >> N;
  int sumdiff = 0;
  int startidx = -1;
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    int n = s.size();
    int diff = 0;
    int maxdecl = 0;
    for (int k = 0; k < n; k++) {
      if (s[k] == '(')
        diff++;
      else
        diff--;
      if (diff < maxdecl)
        maxdecl = diff;
    }
    vs.emplace_back(maxdecl, diff);
    sumdiff += diff;
    if (maxdecl == 0) {
      startidx = i;
    }
  }

  if (startidx == -1 || sumdiff != 0) {
    cout << "No" << endl;
  } else {
    vis.resize(N);
    vis[startidx] = 1;
    cout << (dfs(startidx, vs[startidx].second, 1) ? "Yes" : "No") << endl;
  }

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

#include <algorithm>
#include <set>
#include <stdio.h>
#include <string>
using namespace std;
char in[20][20];
char ret[20];
int used[20];
int t[20];
int n;
int m;
set<pair<pair<int, int>, string>> S;
int calc(int a, string b, int c) {
  if (S.count(make_pair(make_pair(a, c), b)))
    return 0;
  S.insert(make_pair(make_pair(a, c), b));
  if (a == n)
    return 1;
  //	printf("%d %s %s\\n",a,ret,b.c_str());
  for (int i = 0; i < n; i++) {
    if (used[i])
      continue;
    int at = 0;
    bool ok = true;
    for (int j = 0; j < n; j++)
      t[j] = 0;
    for (int j = 0; j < m; j++) {
      if (t[in[i][j] - 'A'])
        ok = false;
      while (n == at || (b[at] != '?' && b[at] != in[i][j])) {
        if (at < n && b[at] != '?')
          t[b[at] - 'A'] = 1;
        if (at >= n) {
          ok = false;
          break;
        }
        at++;
      }
      at++;
    }
    if (ok) {
      used[i] = 1;
      ret[a] = 'A' + i;
      string to = "";
      for (int j = 0; j < n; j++)
        t[j] = 0;
      for (int j = 0; j < m; j++) {
        to += in[i][m - 1 - j];
        t[in[i][m - 1 - j] - 'A'] = 1;
      }
      for (int j = 0; j < b.size(); j++)
        if (b[j] != '?' && !t[b[j] - 'A']) {
          to += b[j];
        }
      for (int j = to.size(); j < b.size(); j++)
        to += '?';
      if (calc(a + 1, to, c + (1 << i)))
        return 1;
      ret[a] = 0;
      used[i] = 0;
    }
  }
  return 0;
}
int main() {
  int a, b;
  scanf("%d%d", &a, &b);
  n = a;
  m = b;
  for (int i = 0; i < a; i++)
    scanf("%s", in[i]);
  string s = "";
  for (int i = 0; i < n; i++)
    s += "?";
  calc(0, s, 0);
  printf("%s\\n", ret);
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <stdio.h>
#include <string>
using namespace std;
char in[20][20];
char ret[20];
int used[20];
int t[20];
int n;
int m;
int calc(int a, string b) {
  if (a == n)
    return 1;
  // printf("%d %s %s\\n",a,ret,b.c_str());
  for (int i = 0; i < n; i++) {
    if (used[i])
      continue;
    int at = 0;
    bool ok = true;
    for (int j = 0; j < m; j++) {
      while (n == at || (b[at] != '?' && b[at] != in[i][j])) {
        if (at >= n - 1) {
          ok = false;
          break;
        }
        at++;
      }
      at++;
    }
    if (ok) {
      used[i] = 1;
      ret[a] = 'A' + i;
      string to = "";
      for (int j = 0; j < n; j++)
        t[j] = 0;
      for (int j = 0; j < m; j++) {
        to += in[i][m - 1 - j];
        t[in[i][m - 1 - j] - 'A'] = 1;
      }
      for (int j = 0; j < b.size(); j++)
        if (b[j] != '?' && !t[b[j] - 'A']) {
          to += b[j];
        }
      for (int j = to.size(); j < b.size(); j++)
        to += '?';
      if (calc(a + 1, to))
        return 1;
      ret[a] = 0;
      used[i] = 0;
    }
  }
  return 0;
}
int main() {
  int a, b;
  scanf("%d%d", &a, &b);
  n = a;
  m = b;
  for (int i = 0; i < a; i++)
    scanf("%s", in[i]);
  string s = "";
  for (int i = 0; i < n; i++)
    s += "?";
  calc(0, s);
  printf("%s\\n", ret);
}
Problem p01801 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
int h, w;
int memo[21][21][21][21]; // semiopen
bool mark[20][20];
void init() {
  REP(ys, 21) REP(yt, 21) REP(xs, 21) REP(xt, 21) {
    if (ys > yt || xs > xt)
      memo[ys][yt][xs][xt] = 0;
    else
      memo[ys][yt][xs][xt] = -1;
  }
  memset(mark, 0, sizeof(mark));
}

int grundy(int ys, int yt, int xs, int xt) {
  if (memo[ys][yt][xs][xt] != -1) {
    return memo[ys][yt][xs][xt];
  }
  vector<int> trans;
  for (int i = ys; i < yt; i++) {
    for (int j = xs; j < xt; j++) {
      if (mark[i][j])
        continue;
      int gn = 0;
      gn ^= grundy(ys, i, xs, j);
      gn ^= grundy(i + 1, yt, xs, j);
      gn ^= grundy(ys, i, j + 1, xt);
      gn ^= grundy(i + 1, yt, j + 1, xt);
      trans.push_back(gn);
    }
  }
  sort(trans.begin(), trans.end());
  trans.erase(unique(trans.begin(), trans.end()), trans.end());
  int res = 0;
  for (int i = 0; i < (int)trans.size(); i++) {
    if (trans[i] != i)
      break;
    res++;
  }
  memo[ys][yt][xs][xt] = res;
  return res;
}

int main() {
  init();
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      char c;
      cin >> c;
      if (c == 'X')
        mark[i][j] = true;
    }
  }
  if (grundy(0, h, 0, w) != 0) {
    cout << "First" << endl;
  } else {
    cout << "Second" << endl;
  }
  return 0;
}


Error: MLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int h, w;
string mark;
map<string, bool> memo;

bool solve(string &state) {
  if (memo.count(state) != 0) {
    return !memo[state];
  }
  bool res = false;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (state[i * w + j] == 'X' || mark[i * w + j] == 'X')
        continue;
      string next = state;
      next[i * w + j] = 'X';
      for (int d = 0; d < 4; d++) {
        int y = i + dy[d];
        int x = j + dx[d];
        while (0 <= y && y < h && 0 <= x && x < w && next[y * w + x] == '.') {
          next[y * w + x] = 'X';
          y += dy[d];
          x += dx[d];
        }
      }
      if (solve(next)) {
        res = true;
        i = h;
        break;
      }
    }
  }
  memo[state] = res;
  return !res;
}

int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    string s;
    cin >> s;
    mark += s;
  }
  string init(h * w, '.');
  bool res = solve(init);
  if (!res) {
    cout << "First" << endl;
  } else {
    cout << "Second" << endl;
  }
  return 0;
}
Problem p01802 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define inf 1e9
#define int long long

signed main() {
  double d, e;
  while (1) {
    cin >> d >> e;
    if (d == 0 & e == 0)
      break;

    double temp = inf;
    for (int i = 0; i <= d / 2; i++) {
      double ret = d - i;
      double t = (d - i) * (d - i) + i * i;
      temp = min(temp, abs(sqrt(t) - e));
    }
    cout << temp << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
const int N(55);
char a[N][N];
bool aeiou(char c) {
  return c == 'a' || c == 'i' || c == 'o' || c == 'e' || c == 'u';
}
int main() {
  for (;;) {
    int n;
    scanf("%d", &n);
    if (n == 0) {
      break;
    }
    int ans(0);
    for (int i(0); i < n; i++) {
      scanf("%s", a[i]);
      int len(strlen(a[i])), l1(0);
      for (int j(0); j < len; j++) {
        if (j == 0 || aeiou(a[i][j - 1])) {
          a[i][l1++] = a[i][j];
        }
      }
      a[i][l1] = 0;
      for (int j(i - 1); j >= 0; j--) {
        int res(1e9);
        for (int k(0); a[i][k] != 0 || a[j][k] != 0; k++) {
          if (a[i][k] != a[j][k]) {
            res = k + 1;
            break;
          }
        }
        ans = max(ans, res);
      }
    }
    if (ans == 1e9) {
      ans = -1;
    }
    printf("%d\\n", ans);
  }
}
Problem p01803 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define INF 1e9
#define llINF 1e18
#define MOD 1e9 + 7
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long
using namespace std;
int main() {
  int n;
  while (cin >> n, n) {
    string str[n + 10];
    for (int i = 0; i < n; i++) {
      cin >> str[i];
      string str2 = "";
      str2 += str[i][0];
      for (int j = 0; j < str[i].size(); j++) {
        if (!(str[i][j] != 'a' && str[i][j] != 'i' && str[i][j] != 'u' &&
              str[i][j] != 'e' && str[i][j] != 'o')) {
          if (j == str[i].size() - 1)
            break;
          str2 += str[i][j + 1];
        }
      }
      str[i] = str2;
      // cout<<str[i]<<endl;
    }
    bool flag = true;
    int ma = 1;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (i == j)
          continue;
        if (i != j && str[i] == str[j])
          flag = false;
        int cnt = 0;
        while (str[i][cnt] == str[j][cnt] && str[i].size() > cnt &&
               str[j].size() > cnt) {
          cnt++;
          // cout<<str[i][cnt]<<" "<<str[j][cnt]<<endl;
          ma = max(ma, cnt + 1);
        }
      }
    }
    cout << ((flag == true) ? ma : -1) << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define INF 1e9
#define llINF 1e18
#define MOD 1e9 + 7
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long
using namespace std;
int main() {
  int n;
  while (cin >> n, n) {
    int end[100] = {};
    string str[n];
    for (int i = 0; i < n; i++) {
      cin >> str[i];
      string str2 = "";
      for (int j = 0; j < str[i].size(); j++) {
        if (str[i][j] != 'a' && str[i][j] != 'i' && str[i][j] != 'u' &&
            str[i][j] != 'e' && str[i][j] != 'o') {
          str2 += str[i][j];
          while (str[i][j] != 'a' && str[i][j] != 'i' && str[i][j] != 'u' &&
                 str[i][j] != 'e' && str[i][j] != 'o')
            j++;

        } else
          str2 += str[i][j];
      }
      str[i] = str2;
    }
    bool flag = true;
    int ma = 1;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (i == j)
          continue;
        if (i != j && str[i] == str[j])
          flag = false;
        int cnt = 0;
        while (str[i][cnt] == str[j][cnt] && str[i].size() > cnt &&
               str[j].size() > cnt) {
          cnt++;
          // cout<<str[i][cnt]<<" "<<str[j][cnt]<<endl;
          ma = max(ma, cnt + 1);
        }
      }
    }
    cout << ((flag == true) ? ma : -1) << endl;
  }
  return 0;
}
Problem p01803 (C++) — buggy submission, verdict: Runtime Error

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

string s[51], t[51];

// ??????????????´?????????????????????????????¢??°
bool check(int n, int k) {
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      // cout << i << " " << j << " ";
      // cout << t[i].substr(0, k) << " " << t[j].substr(0, k) << endl;
      if (t[i].substr(0, k) == t[j].substr(0, k))
        return false;
    }
  }
  return true;
}

int main(void) {
  int n, ans = -1, m_size = 0;
  cin.tie(0);
  ios::sync_with_stdio(false);

  while (cin >> n, n) {
    ans = -1;
    for (int i = 0; i < n; i++)
      s[i] = t[i] = "";
    for (int i = 0; i < n; i++) {
      cin >> s[i];
      if (s[i].size() > m_size)
        m_size = s[i].size();
    }
    for (int j = 0; j < n; j++)
      t[j] = s[j][0]; // ?????????

    // for (int j = 0; j < n; j++) cout << t[j] << endl;

    for (int j = 0; j < n; j++) {
      for (int k = 1; k < s[j].size(); k++) {
        if (s[j][k - 1] == 'a' || s[j][k - 1] == 'i' || s[j][k - 1] == 'u' ||
            s[j][k - 1] == 'e' || s[j][k - 1] == 'o') {
          t[j] += s[j][k]; // ???????????????
        }
      }
    }
    // sort(t, t + n);
    // for (int k = 0; k < n; k++) cout << t[k] << endl;

    //????????????1?????????????¢????????????????????????´????????°??????????????????
    for (int i = 1; i <= m_size; i++) {
      // cout << i << endl;
      if (check(n, i)) {
        ans = i;
        break;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Error: -11

Fixed submission:

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

string s[51], t[51];

bool check(int n, int k) {
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      // cout << i << " " << j << " ";
      // cout << t[i].substr(0, k) << " " << t[j].substr(0, k) << endl;
      if (t[i].substr(0, k) == t[j].substr(0, k))
        return false;
    }
  }
  return true;
}

int main(void) {
  int n, ans = -1, m_size = 0;
  cin.tie(0);
  ios::sync_with_stdio(false);

  while (cin >> n, n) {
    ans = -1;
    memset(s, 0, sizeof(s));
    memset(t, 0, sizeof(t));
    for (int i = 0; i < n; i++) {
      cin >> s[i];
      if (s[i].size() > m_size)
        m_size = s[i].size();
    }
    for (int j = 0; j < n; j++)
      t[j] = s[j][0];

    // for (int j = 0; j < n; j++) cout << t[j] << endl;

    for (int j = 0; j < n; j++) {
      for (int k = 1; k < s[j].size(); k++) {
        if (s[j][k - 1] == 'a' || s[j][k - 1] == 'i' || s[j][k - 1] == 'u' ||
            s[j][k - 1] == 'e' || s[j][k - 1] == 'o') {
          t[j] += s[j][k];
        }
      }
    }
    // sort(t, t + n);
    // for (int k = 0; k < n; k++) cout << t[k] << endl;

    for (int i = 1; i <= m_size; i++) {
      // cout << i << endl;
      if (check(n, i)) {
        ans = i;
        break;
      }
    }
    cout << ans << endl;
  }
  return 0;
}