prithivMLmods/Coder-Stat huggingface dataset:
Problem p03190 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;

const int N = 5e3 + 5;
char S[N], T[N];
int n, ans = 1e9, cnt1, cnt2, A[N], B[N], tmpA[N], tmpB[N];

template <typename _Tp> inline void IN(_Tp &x) {
  char ch;
  bool flag = 0;
  x = 0;
  while (ch = getchar(), !isdigit(ch))
    if (ch == '-')
      flag = 1;
  while (isdigit(ch))
    x = x * 10 + ch - '0', ch = getchar();
  if (flag)
    x = -x;
}

int main() {
  IN(n), scanf("%s%s", S + 1, T + 1);
  cnt1 = (bool)(S[1] == '1'), cnt2 = (bool)(T[1] == '1');
  for (int i = 1; i < n; ++i)
    (S[i] != S[i + 1]) ? tmpA[++cnt1] = i : 0,
                         (T[i] != T[i + 1]) ? tmpB[++cnt2] = i : 0;
  (S[n] == '1') ? tmpA[++cnt1] = n : 0, (T[n] == '1') ? tmpB[++cnt2] = n : 0;
  int lim = cnt1 + cnt2 + cnt2;
  for (int i = cnt2 + 1; i <= lim; ++i)
    A[i] = (i <= cnt1 + cnt2) ? tmpA[i - cnt2] : n;
  for (int i = 0; i <= cnt1 + cnt2; i += 2) {
    int res = 0;
    for (int j = 1; j <= lim; ++j)
      B[j] = j <= i ? 0 : (j <= i + cnt2 ? tmpB[j - i] : n);
    for (int j = 1; j <= lim; ++j)
      res += abs(A[j] - B[j]);
    ans = min(ans, res);
  }
  return printf("%d\n", ans), 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;

const int N = 1e5 + 5;
char S[N], T[N];
int n, ans = 1e9, cnt1, cnt2, A[N], B[N], tmpA[N], tmpB[N];

template <typename _Tp> inline void IN(_Tp &x) {
  char ch;
  bool flag = 0;
  x = 0;
  while (ch = getchar(), !isdigit(ch))
    if (ch == '-')
      flag = 1;
  while (isdigit(ch))
    x = x * 10 + ch - '0', ch = getchar();
  if (flag)
    x = -x;
}

int main() {
  IN(n), scanf("%s%s", S + 1, T + 1);
  cnt1 = (bool)(S[1] == '1'), cnt2 = (bool)(T[1] == '1');
  for (int i = 1; i < n; ++i)
    (S[i] != S[i + 1]) ? tmpA[++cnt1] = i : 0,
                         (T[i] != T[i + 1]) ? tmpB[++cnt2] = i : 0;
  (S[n] == '1') ? tmpA[++cnt1] = n : 0, (T[n] == '1') ? tmpB[++cnt2] = n : 0;
  int lim = cnt1 + cnt2 + cnt2;
  for (int i = cnt2 + 1; i <= lim; ++i)
    A[i] = (i <= cnt1 + cnt2) ? tmpA[i - cnt2] : n;
  for (int i = 0; i <= cnt1 + cnt2; i += 2) {
    int res = 0;
    for (int j = 1; j <= lim; ++j)
      B[j] = j <= i ? 0 : (j <= i + cnt2 ? tmpB[j - i] : n);
    for (int j = 1; j <= lim; ++j)
      res += abs(A[j] - B[j]);
    ans = min(ans, res);
  }
  return printf("%d\n", ans), 0;
}
Problem p03191 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
const int N = 310, mod = 1e9 + 7;
int n, a[N], t[N], c[N], cnt, CNT;
void pls(int &x, int y) {
  x += y;
  x >= mod ? x -= mod : 0;
}
int dp[N << 1][N][N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= 2 * n; i++)
    scanf("%d", &a[i]);

  for (int i = 1; i <= 2 * n; i += 2)
    if (a[i] != -1 && a[i + 1] != -1)
      t[a[i]] = t[a[i + 1]] = 2;
    else if (a[i] != -1)
      t[a[i]] = 1;
    else if (a[i + 1] != -1)
      t[a[i + 1]] = 1;
    else
      CNT++;
  for (int i = 1; i <= 2 * n; i++)
    if (t[i] == 1)
      c[++cnt] = 1;
    else if (!t[i])
      c[++cnt] = 0;
  dp[cnt][0][0] = 1;
  for (int i = cnt; i; i--)
    for (int j = 0; j <= cnt && j <= n; j++)
      for (int k = 0; k <= cnt && k <= n; k++)
        if (c[i] == 1) {
          pls(dp[i - 1][j + 1][k], dp[i][j][k]);
          if (k)
            pls(dp[i - 1][j][k - 1], dp[i][j][k]);
        } else {
          pls(dp[i - 1][j][k + 1], dp[i][j][k]);
          if (k)
            pls(dp[i - 1][j][k - 1], dp[i][j][k]);
          if (j)
            pls(dp[i - 1][j - 1][k], (ll)dp[i][j][k] * j % mod);
        }
  ll ans = dp[0][0][0];
  for (int i = 1; i <= CNT; i++)
    ans = ans * i % mod;
  cout << ans;
}

Fixed submission:
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
const int N = 310, mod = 1e9 + 7;
int n, a[N << 1], t[N << 1], c[N << 1], cnt, CNT;
void pls(int &x, int y) {
  x += y;
  x >= mod ? x -= mod : 0;
}
int dp[N << 1][N][N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= 2 * n; i++)
    scanf("%d", &a[i]);

  for (int i = 1; i <= 2 * n; i += 2)
    if (a[i] != -1 && a[i + 1] != -1)
      t[a[i]] = t[a[i + 1]] = 2;
    else if (a[i] != -1)
      t[a[i]] = 1;
    else if (a[i + 1] != -1)
      t[a[i + 1]] = 1;
    else
      CNT++;
  for (int i = 1; i <= 2 * n; i++)
    if (t[i] == 1)
      c[++cnt] = 1;
    else if (!t[i])
      c[++cnt] = 0;
  dp[cnt][0][0] = 1;
  for (int i = cnt; i; i--)
    for (int j = 0; j <= cnt && j <= n; j++)
      for (int k = 0; k <= cnt && k <= n; k++)
        if (c[i] == 1) {
          pls(dp[i - 1][j + 1][k], dp[i][j][k]);
          if (k)
            pls(dp[i - 1][j][k - 1], dp[i][j][k]);
        } else {
          pls(dp[i - 1][j][k + 1], dp[i][j][k]);
          if (k)
            pls(dp[i - 1][j][k - 1], dp[i][j][k]);
          if (j)
            pls(dp[i - 1][j - 1][k], (ll)dp[i][j][k] * j % mod);
        }
  ll ans = dp[0][0][0];
  for (int i = 1; i <= CNT; i++)
    ans = ans * i % mod;
  cout << ans;
}
Problem p03191 (C++)

Buggy submission (status: Runtime Error):
using namespace std;
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstring>
#define N 310
#define mo 1000000007
#define ll long long
int n;
int bz[N];
int f[N * 2][N][N];
inline void add(int &a, ll b) { a = (a + b) % mo; }
int main() {
  //	freopen("in.txt","r",stdin);
  //	freopen("out.txt","w",stdout);
  scanf("%d", &n);
  for (int i = n; i >= 1; --i) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (x != -1 && y != -1)
      bz[x] = -1, bz[y] = -1;
    else if (x != -1)
      bz[x] = 1;
    else if (y != -1)
      bz[y] = 1;
  }
  int tmpn = n;
  n = 0;
  for (int i = 1; i <= tmpn * 2; ++i)
    if (bz[i] != -1)
      bz[++n] = bz[i];
  n >>= 1;
  f[2 * n + 1][0][0] = 1;
  for (int i = 2 * n + 1; i > 1; --i)
    for (int j = 0; j <= 2 * n - i + 1 && j <= n; ++j)
      for (int k = 0; j + k <= 2 * n - i + 1 && k <= n; ++k) {
        ll tmp = f[i][j][k];
        if (!tmp)
          continue;
        if (bz[i - 1] == 1) {
          add(f[i - 1][j][k + 1], tmp);
          if (j)
            add(f[i - 1][j - 1][k], tmp);
        } else {
          add(f[i - 1][j + 1][k], tmp);
          if (j)
            add(f[i - 1][j - 1][k], tmp);
          if (k)
            add(f[i - 1][j][k - 1], tmp * k);
        }
      }
  int cnt = 0;
  ll ans = 1;
  for (int i = 1; i <= 2 * n; ++i)
    if (bz[i] == 1)
      cnt++;
  for (int i = 1; i <= n - cnt; ++i)
    ans = ans * i % mo;
  ans = ans * f[1][0][0] % mo;
  printf("%lld\n", ans);
  return 0;
}

Fixed submission:
using namespace std;
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstring>
#define N 310
#define mo 1000000007
#define ll long long
int n;
int bz[N * 2];
int f[N * 2][N][N];
inline void add(int &a, ll b) { a = (a + b) % mo; }
int main() {
  //	freopen("in.txt","r",stdin);
  //	freopen("out.txt","w",stdout);
  scanf("%d", &n);
  for (int i = n; i >= 1; --i) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (x != -1 && y != -1)
      bz[x] = -1, bz[y] = -1;
    else if (x != -1)
      bz[x] = 1;
    else if (y != -1)
      bz[y] = 1;
  }
  int tmpn = n;
  n = 0;
  for (int i = 1; i <= tmpn * 2; ++i)
    if (bz[i] != -1)
      bz[++n] = bz[i];
  n >>= 1;
  f[2 * n + 1][0][0] = 1;
  for (int i = 2 * n + 1; i > 1; --i)
    for (int j = 0; j <= 2 * n - i + 1 && j <= n; ++j)
      for (int k = 0; j + k <= 2 * n - i + 1 && k <= n; ++k) {
        ll tmp = f[i][j][k];
        if (!tmp)
          continue;
        if (bz[i - 1] == 1) {
          add(f[i - 1][j][k + 1], tmp);
          if (j)
            add(f[i - 1][j - 1][k], tmp);
        } else {
          add(f[i - 1][j + 1][k], tmp);
          if (j)
            add(f[i - 1][j - 1][k], tmp);
          if (k)
            add(f[i - 1][j][k - 1], tmp * k);
        }
      }
  int cnt = 0;
  ll ans = 1;
  for (int i = 1; i <= 2 * n; ++i)
    if (bz[i] == 1)
      cnt++;
  for (int i = 1; i <= n - cnt; ++i)
    ans = ans * i % mo;
  ans = ans * f[1][0][0] % mo;
  printf("%lld\n", ans);
  return 0;
}
Problem p03191 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 605, mo = 1e9 + 7;
int a[N], ty[N], n, cnt, _;
ll f[2][N][N];
void move(ll &a, ll b) { a = (a + b) % mo; }
int main() {
  cin >> n;
  for (int i = 1; i <= 2 * n; i++)
    scanf("%d", &a[i]);
  for (int i = 1; i <= 2 * n; i += 2) {
    if (a[i] != -1 && a[i + 1] != -1)
      ty[a[i]] = ty[a[i + 1]] = 3;
    else if (a[i] != a[i + 1])
      ty[a[i] ^ a[i + 1] ^ -1] = 1;
    else
      cnt++;
  }
  f[_ = 1][0][0] = 1;
  for (int i = 2 * n; i >= 1; i--) {
    _ ^= 1;
    memset(f[_], 0, sizeof f[_]);
    for (int j = 0; j <= 2 * n - i + 1; j++)
      for (int k = 0; j + k <= 2 * n - i + 1; k++) {
        if (ty[i] == 1)
          move(f[_][j - 1][k], f[!_][j][k]), move(f[_][j][k + 1], f[!_][j][k]);
        if (ty[i] == 0)
          move(f[_][j - 1][k], f[!_][j][k]), move(f[_][j + 1][k], f[!_][j][k]),
              move(f[_][j][k - 1], (ll)f[!_][j][k] * k);
        if (ty[i] == 3)
          move(f[_][j][k], f[!_][j][k]);
      }
  }
  ll ans = f[_][0][0];
  for (; cnt; cnt--)
    ans = ans * cnt % mo;
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 605, mo = 1e9 + 7;
int a[N], ty[N], n, cnt, _;
ll f[2][N][N];
void move(ll &a, ll b) { a = (a + b) % mo; }
int main() {
  cin >> n;
  for (int i = 1; i <= 2 * n; i++)
    scanf("%d", &a[i]);
  for (int i = 1; i <= 2 * n; i += 2) {
    if (a[i] != -1 && a[i + 1] != -1)
      ty[a[i]] = ty[a[i + 1]] = 3;
    else if (a[i] != a[i + 1])
      ty[a[i] ^ a[i + 1] ^ -1] = 1;
    else
      cnt++;
  }
  f[_ = 1][0][0] = 1;
  for (int i = 2 * n; i >= 1; i--) {
    _ ^= 1;
    memset(f[_], 0, sizeof f[_]);
    for (int j = 0; j <= 2 * n - i + 1; j++)
      for (int k = 0; j + k <= 2 * n - i + 1; k++) {
        if (ty[i] == 1) {
          if (j)
            move(f[_][j - 1][k], f[!_][j][k]);
          move(f[_][j][k + 1], f[!_][j][k]);
        }
        if (ty[i] == 0) {
          if (j)
            move(f[_][j - 1][k], f[!_][j][k]);
          move(f[_][j + 1][k], f[!_][j][k]);
          if (k)
            move(f[_][j][k - 1], (ll)f[!_][j][k] * k);
        }
        if (ty[i] == 3)
          move(f[_][j][k], f[!_][j][k]);
      }
  }
  ll ans = f[_][0][0];
  for (; cnt; cnt--)
    ans = ans * cnt % mo;
  cout << ans << endl;
}
Problem p03191 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

const int N = 700;
const int MOD = 1e9 + 7;
int n;
int F[N][N][N], flg[N], fac = 1, rua;
void ADD(int &t, int d) {
  t += d;
  if (t >= MOD)
    t -= MOD;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    if ((a != -1) && (b != -1))
      flg[a] = flg[b] = 2;
    else if (a != -1)
      flg[a] = 1;
    else if (b != -1)
      flg[b] = 1;
    else
      rua++;
  }
  F[0][0][0] = 1;
  for (int i = 1; i <= 2 * n; ++i)
    for (int j = 0; j <= 2 * n; ++j)
      for (int k = 0; k <= 2 * n; ++k) {
        if (flg[i] == 2) {
          ADD(F[i][j][k], F[i - 1][j][k]);
        } else if (flg[i] == 1) {
          ADD(F[i][j][k + 1], F[i - 1][j][k]);
          if (j)
            ADD(F[i][j - 1][k], 1ll * F[i - 1][j][k] * j % MOD);
        } else {
          ADD(F[i][j][k + 1], F[i - 1][j][k]);
          ADD(F[i][j + 1][k], F[i - 1][j][k]);
          if (k)
            ADD(F[i][j][k - 1], F[i - 1][j][k]);
        }
      }
  for (int i = 1; i <= rua; ++i)
    fac = 1ll * fac * i % MOD;
  cout << 1ll * F[2 * n][0][0] * fac % MOD << endl;
}

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

const int N = 610;
const int MOD = 1e9 + 7;
int n;
int F[N][N][N], flg[N], fac = 1, rua;
void ADD(int &t, int d) {
  t += d;
  if (t >= MOD)
    t -= MOD;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    if ((a != -1) && (b != -1))
      flg[a] = flg[b] = 2;
    else if (a != -1)
      flg[a] = 1;
    else if (b != -1)
      flg[b] = 1;
    else
      rua++;
  }
  F[0][0][0] = 1;
  for (int i = 1; i <= 2 * n; ++i)
    for (int j = 0; j <= 2 * n; ++j)
      for (int k = 0; k <= 2 * n; ++k) {
        if (flg[i] == 2) {
          ADD(F[i][j][k], F[i - 1][j][k]);
        } else if (flg[i] == 1) {
          ADD(F[i][j][k + 1], F[i - 1][j][k]);
          if (j)
            ADD(F[i][j - 1][k], 1ll * F[i - 1][j][k] * j % MOD);
        } else {
          ADD(F[i][j][k + 1], F[i - 1][j][k]);
          ADD(F[i][j + 1][k], F[i - 1][j][k]);
          if (k)
            ADD(F[i][j][k - 1], F[i - 1][j][k]);
        }
      }
  for (int i = 1; i <= rua; ++i)
    fac = 1ll * fac * i % MOD;
  cout << 1ll * F[2 * n][0][0] * fac % MOD << endl;
}
Problem p03191 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
const int mod = 1000000007;
int N, A[610], c[610], f[610][310][310];
bool del[610];
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N * 2; i++)
    scanf("%d", A + i), c[A[i]]++;
  int m = 0;
  for (int i = 0; i < N * 2; i++) {
    if (A[i * 2] != -1 && A[i * 2 + 1] != -1)
      del[A[i * 2]] = del[A[i * 2 + 1]] = 1;
    if (A[i * 2] == -1 && A[i * 2 + 1] == -1)
      m++;
  }
  int s = 0, t = 0;
  f[N * 2][0][0] = 1;
  for (int i = N * 2; i; i--) {
    for (int j = 0; j <= N; j++)
      for (int k = 0; k <= N; k++)
        if (f[i][j][k]) {
          if (del[i])
            f[i - 1][j][k] = f[i][j][k];
          else {
            if (c[i])
              (f[i - 1][j][k + 1] += f[i][j][k]) %= mod;
            else
              (f[i - 1][j + 1][k] += f[i][j][k]) %= mod;
            if (c[i]) {
              if (j)
                (f[i - 1][j - 1][k] += f[i][j][k]) %= mod;
            } else {
              if (k)
                f[i - 1][j][k - 1] =
                    (f[i - 1][j][k - 1] + 1ll * k * f[i][j][k]) % mod;
              if (j && m + s + (j - k - t) / 2 > 0)
                f[i - 1][j - 1][k] =
                    (f[i - 1][j - 1][k] +
                     1ll * (m + s + (j - k - t) / 2) * f[i][j][k]) %
                    mod;
            }
          }
        }
    if (!del[i])
      s += c[i], t++;
  }
  printf("%d\n", f[0][0][0]);
}

Fixed submission:
#include <cstdio>
const int mod = 1000000007;
int N, A[610], c[610], f[610][310][310];
bool del[610];
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N * 2; i++)
    scanf("%d", A + i), c[A[i]]++;
  int m = 0;
  for (int i = 0; i < N; i++) {
    if (A[i * 2] != -1 && A[i * 2 + 1] != -1)
      del[A[i * 2]] = del[A[i * 2 + 1]] = 1;
    if (A[i * 2] == -1 && A[i * 2 + 1] == -1)
      m++;
  }
  int s = 0, t = 0;
  f[N * 2][0][0] = 1;
  for (int i = N * 2; i; i--) {
    for (int j = 0; j <= N; j++)
      for (int k = 0; k <= N; k++)
        if (f[i][j][k]) {
          if (del[i])
            f[i - 1][j][k] = f[i][j][k];
          else {
            if (c[i])
              (f[i - 1][j][k + 1] += f[i][j][k]) %= mod;
            else
              (f[i - 1][j + 1][k] += f[i][j][k]) %= mod;
            if (c[i]) {
              if (j)
                (f[i - 1][j - 1][k] += f[i][j][k]) %= mod;
            } else {
              if (k)
                f[i - 1][j][k - 1] =
                    (f[i - 1][j][k - 1] + 1ll * k * f[i][j][k]) % mod;
              if (j && m + s + (j - k - t) / 2 > 0)
                f[i - 1][j - 1][k] =
                    (f[i - 1][j - 1][k] +
                     1ll * (m + s + (j - k - t) / 2) * f[i][j][k]) %
                    mod;
            }
          }
        }
    if (!del[i])
      s += c[i], t++;
  }
  printf("%d\n", f[0][0][0]);
}
Problem p03191 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N = 300, mod = 1000000007;
int n, m, f[N][N], g[N][N];
bool fix[N], banned[N];
int main() {
  scanf("%d", &n);
  int t = 1;
  for (int i = 1, x, y; i <= n; i++) {
    scanf("%d%d", &x, &y);
    if (~x && ~y) {
      fix[x] = fix[y] = true;
    } else if (~x || ~y) {
      banned[x + y + 1] = true;
    } else {
      t = (ll)t * (++m) % mod;
    }
  }
  f[0][0] = 1;
  for (int x = n * 2; x; x--)
    if (!fix[x]) {
      memset(g, 0, sizeof g);
      for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++)
          if (f[i][j]) {
            if (banned[x]) {
              g[i][j + 1] = (g[i][j + 1] + f[i][j]) % mod;
              if (i)
                g[i - 1][j] = (g[i - 1][j] + f[i][j]) % mod;
            } else {
              g[i + 1][j] = (g[i + 1][j] + f[i][j]) % mod;
              if (i)
                g[i - 1][j] = (g[i - 1][j] + f[i][j]) % mod;
              if (j)
                g[i][j - 1] = (g[i][j - 1] + (ll)f[i][j] * j) % mod;
            }
          }
      }
      memcpy(f, g, sizeof g);
    }
  int ans = (ll)f[0][0] * t % mod;
  printf("%d\n", ans);
}


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

typedef long long ll;
const int N = 666, mod = 1000000007;
int n, m, f[N][N], g[N][N];
bool fix[N], banned[N];
int main() {
  scanf("%d", &n);
  int t = 1;
  for (int i = 1, x, y; i <= n; i++) {
    scanf("%d%d", &x, &y);
    if (~x && ~y) {
      fix[x] = fix[y] = true;
    } else if (~x || ~y) {
      banned[x + y + 1] = true;
    } else {
      t = (ll)t * (++m) % mod;
    }
  }
  f[0][0] = 1;
  for (int x = n * 2; x; x--)
    if (!fix[x]) {
      memset(g, 0, sizeof g);
      for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++)
          if (f[i][j]) {
            if (banned[x]) {
              g[i][j + 1] = (g[i][j + 1] + f[i][j]) % mod;
              if (i)
                g[i - 1][j] = (g[i - 1][j] + f[i][j]) % mod;
            } else {
              g[i + 1][j] = (g[i + 1][j] + f[i][j]) % mod;
              if (i)
                g[i - 1][j] = (g[i - 1][j] + f[i][j]) % mod;
              if (j)
                g[i][j - 1] = (g[i][j - 1] + (ll)f[i][j] * j) % mod;
            }
          }
      }
      memcpy(f, g, sizeof g);
    }
  int ans = (ll)f[0][0] * t % mod;
  printf("%d\n", ans);
}
Problem p03192 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

int main(int argc, char const *argv[]) {

  char s[4] = {'\0'};
  int n, count = 0, ret;

  ret = scanf("%d", &n);
  sprintf(s, "%d", n);
  for (int i = 0; i < 4; i++) {
    if (s[i] == '2')
      count++;
  }
  printf("%d\n", count);

  return 0;
}


Fixed submission:
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

int main(int argc, char const *argv[]) {

  char s[5];
  int n, count = 0, ret;

  ret = scanf("%d", &n);
  sprintf(s, "%d", n);
  for (int i = 0; i < 4; i++) {
    if (s[i] == '2')
      count++;
  }
  printf("%d\n", count);

  return 0;
}
Problem p03192 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, m, n) for (int i = m; i < n; i++)
#define co(n) cout << n << endl
using namespace std;
int main() {
  string s;
  int c = 0;
  rep(i, 0, 4) if (s.at(i) == '2') c++;
  co(c);

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, m, n) for (int i = m; i < n; i++)
#define co(n) cout << n << endl
using namespace std;
int main() {
  string s;
  cin >> s;

  int c = 0;
  rep(i, 0, 4) if (s.at(i) == '2') c++;
  co(c);

  return 0;
}
Problem p03192 (Python)

Buggy submission (status: Runtime Error):
def main(n):
    print(str(n).count("2"))


if __name__ == "__main__":
    n = int(input())
    main()


Fixed submission:
def main(n):
    print(str(n).count("2"))


if __name__ == "__main__":
    n = int(input())
    main(n)
Problem p03192 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

int main(int argc, char const *argv[]) {

  char s[4];
  int n, count = 0, ret;

  ret = scanf("%d", &n);
  sprintf(s, "%d", n);
  for (int i = 0; i < 4; i++) {
    if (s[i] == '2')
      count++;
  }
  printf("%d\n", count);

  return 0;
}

Fixed submission:
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

int main(int argc, char const *argv[]) {

  char s[5];
  int n, count = 0, ret;

  ret = scanf("%d", &n);
  sprintf(s, "%d", n);
  for (int i = 0; i < 4; i++) {
    if (s[i] == '2')
      count++;
  }
  printf("%d\n", count);

  return 0;
}
Problem p03193 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, H, W;
  cin >> N >> H >> W;
  vector<vector<long long>> vec(H, vector<long long>(W));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> vec.at(i).at(j);
    }
  }

  int ans = 0;
  for (int k = 0; k < N; k++) {
    if ((vec.at(k).at(0) >= H) && (vec.at(k).at(1) >= W)) {
      ans++;
    }
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, H, W;
  cin >> N >> H >> W;
  vector<vector<long long>> vec(N, vector<long long>(2));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 2; j++) {
      cin >> vec.at(i).at(j);
    }
  }

  int ans = 0;
  for (int k = 0; k < N; k++) {
    if ((vec.at(k).at(0) >= H) && (vec.at(k).at(1) >= W)) {
      ans++;
    }
  }
  cout << ans << endl;
}
Problem p03193 (Python)

Buggy submission (status: Runtime Error):
def read():
    N, H, W = list(map(int, input().strip().split()))
    A = []
    B = []
    for i in range(N):
        a, b = list(map(int, input().strip().split()))
        A.append(a)
        B.append(b)
    return N, H, W, A, B


def solve(N, H, W, A, B):
    count = 0
    for i in range(N):
        if A[i] >= H and B[i] >= W:
            count += 1
    return count


if __name__ == "__main__":
    inputs = read()
    print(solve(inputs))


Fixed submission:
def read():
    N, H, W = list(map(int, input().strip().split()))
    A = []
    B = []
    for i in range(N):
        a, b = list(map(int, input().strip().split()))
        A.append(a)
        B.append(b)
    return N, H, W, A, B


def solve(N, H, W, A, B):
    count = 0
    for i in range(N):
        if A[i] >= H and B[i] >= W:
            count += 1
    return count


if __name__ == "__main__":
    inputs = read()
    print(solve(*inputs))
Problem p03193 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <ctype.h>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int N, count = 0;
  int H, W;
  cin >> N >> H >> W;
  long int A[H], B[W];
  for (int i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
    if (A[i] >= H && B[i] >= W) {
      count++;
    }
  }
  cout << count << endl;
  return 0;
}

Fixed submission:
#include <cstdio>
#include <ctype.h>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int N, count = 0;
  int H, W;
  cin >> N >> H >> W;
  long int A[N], B[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
    if (A[i] >= H && B[i] >= W) {
      count++;
    }
  }
  cout << count << endl;
  return 0;
}
Problem p03194 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i > 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define INF 1999999999
#define VSORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
using namespace std;
typedef long long ll;

#ifdef INPUT
stringstream input(R"(
4 972439611840
)");
#define cin input
#endif

std::map<long long, int> primeFactors(long long n) {
  std::map<long long, int> m;

  for (int i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      ++m[i];
      n /= i;
    }
  }

  if (n > 1)
    ++m[n];

  return m;
}

int main() {
  ll n, p, a;
  ll ans = 1;
  cin >> n >> p;

  if (n == 1)
    ans = p;
  else if (p == 1)
    ans = 1;
  else {
    const auto m = primeFactors(p);
    for (const auto &i : m) {
      for (int j = 0; j < i.second / n; j++) {
        ans *= i.first;
      }
    }
  }

  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i > 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define INF 1999999999
#define VSORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
using namespace std;
typedef long long ll;

#ifdef INPUT
stringstream input(R"(
4 972439611840
)");
#define cin input
#endif

std::map<long long, int> primeFactors(long long n) {
  std::map<long long, int> m;

  for (long long i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      ++m[i];
      n /= i;
    }
  }

  if (n > 1)
    ++m[n];

  return m;
}

int main() {
  ll n, p, a;
  ll ans = 1;
  cin >> n >> p;

  if (n == 1)
    ans = p;
  else if (p == 1)
    ans = 1;
  else {
    const auto m = primeFactors(p);
    for (const auto &i : m) {
      for (int j = 0; j < i.second / n; j++) {
        ans *= i.first;
      }
    }
  }

  cout << ans << endl;
  return 0;
}
Problem p03194 (C++)

Buggy submission (status: Time Limit Exceeded):
// Created by sz
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int main() {
#ifdef LOCAL
  freopen("./input.txt", "r", stdin);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll N, P;
  cin >> N >> P;
  if (N == 1) {
    cout << P << endl;
    return 0;
  }

  ll p = P;
  ll divisor = 2;
  ll ans = 1;
  while (p && divisor < p) {
    while (p % divisor != 0) {
      divisor++;
    }
    int cnt = 0;
    while (p % divisor == 0) {
      p = p / divisor;
      ++cnt;
    }
    ans *= pow(divisor, cnt / N);
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
// Created by sz
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int main() {
#ifdef LOCAL
  freopen("./input.txt", "r", stdin);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll N, P;
  cin >> N >> P;
  if (N == 1) {
    cout << P << endl;
    return 0;
  }

  ll p = P;
  ll divisor = 2;
  ll ans = 1;
  while (p && pow(divisor, N) <= p) {
    while (p % divisor != 0) {
      divisor++;
    }
    int cnt = 0;
    while (p % divisor == 0) {
      p = p / divisor;
      ++cnt;
    }
    ans *= pow(divisor, cnt / N);
  }
  cout << ans << endl;
  return 0;
}
Problem p03194 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[1005], b[1005];
ll zyou(ll i, ll n) {
  ll k = 1;
  while (n > 0) {
    if (n & 1)
      k = k * i;
    i = i * i;
    n >>= 1;
  }
  return k;
}
int main(void) {
  ll n, p;
  cin >> n >> p;
  ll ans = 1;
  if (n == 1) {
    cout << p << endl;
    return 0;
  }
  for (ll i = 2; zyou(i, n) <= p; i++) {
    while (p % zyou(i, n) == 0) {
      ans = ans * i;
      p = p / zyou(i, n);
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[1005], b[1005];
ll zyou(ll i, ll n) {
  ll k = 1;
  while (n > 0) {
    if (n & 1)
      k = k * i;
    i = i * i;
    n >>= 1;
  }
  return k;
}
int main(void) {
  ll n, p;
  cin >> n >> p;
  ll ans = 1;
  if (n == 1) {
    cout << p << endl;
    return 0;
  }
  if (n >= 40) {
    cout << 1 << endl;
    return 0;
  }
  for (ll i = 2; zyou(i, n) <= p; i++) {
    while (p % zyou(i, n) == 0) {
      ans = ans * i;
      p = p / zyou(i, n);
    }
  }
  cout << ans << endl;
}
Problem p03194 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  ll N, P;
  cin >> N >> P;
  ll i = 2, l = 1;

  while (P != 1) {
    if (P % i == 0) {
      ll ni = 0;
      while (P % i == 0) {
        ni++;
        P /= i;
      }
      l *= pow(i, ni / N);
    } else {
      i++;
    }
  }
  cout << l << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  ll N, P;
  cin >> N >> P;
  ll i = 2, l = 1;

  while (P != 1) {
    if (P % i == 0) {
      ll ni = 0;
      while (P % i == 0) {
        ni++;
        P /= i;
      }
      l *= pow(i, ni / N);
    } else if (i * i > P) {
      if (N == 1)
        l *= P;
      break;
    } else {
      i++;
    }
  }
  cout << l << endl;
}
Problem p03194 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cmath>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

typedef long long ll;

vector<pair<ll, ll>> v;

int main() {
  ll n, p;
  cin >> n >> p;

  if (n == 1) {
    cout << p << endl;
    return 0;
  }

  ll ans = 1;
  for (ll i = 2;;) {
    ll po = pow(i, n);
    if (po > p) {
      break;
    } else if (p % po == 0) {
      p /= po;
      ans *= i;
    } else {
      i++;
    }
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <cmath>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

typedef long long ll;

vector<pair<ll, ll>> v;

int main() {
  ll n, p;
  cin >> n >> p;

  if (n == 1) {
    cout << p << endl;
    return 0;
  }

  if (n >= 40) {
    cout << 1 << endl;
    return 0;
  }

  ll ans = 1;
  for (ll i = 2;;) {
    ll po = pow(i, n);
    if (po > p) {
      break;
    } else if (p % po == 0) {
      p /= po;
      ans *= i;
    } else {
      i++;
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p03194 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <random>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

int main() {
  ll N, P, kN;
  cin >> N >> P;

  ll k = 2;
  ll ans = 1;
  while (P >= pow(k, N)) {
    kN = pow(k, N);
    if (P % kN == 0) {
      P /= kN;
      ans *= k;
    } else {
      k++;
    }
  }

  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <random>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

int main() {
  ll N, P, kN;
  cin >> N >> P;

  ll k = 2;
  ll ans = 1;
  if (N == 1)
    ans = P;
  else {
    while (P >= pow(k, N)) {
      kN = pow(k, N);
      if (P % kN == 0) {
        P /= kN;
        ans *= k;
      } else {
        k++;
      }
    }
  }

  cout << ans << endl;
}
Problem p03194 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
const double EPS = 1e-10;
// cout << fixed << std::setprecision(9)
// memset(a, 0, sizeof(a));
//--------------------------

ll Pow(ll x, ll k) {
  if (k == 0)
    return 1;
  if (k % 2 == 0)
    return Pow(x * x, k / 2);
  else
    return x * Pow(x, k - 1);
}

int main() {
  ll n, p;
  ll ans = 1;
  cin >> n >> p;

  if (n == 1) {
    cout << p << endl;
    return 0;
  }

  ll a = 2;
  while (a * a <= p) {
    if (p % a == 0) {
      ll div = Pow(a, n);
      while (p % div == 0) {
        p /= div;
        ans *= a;
      }
    }
    a++;
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
const double EPS = 1e-10;
// cout << fixed << std::setprecision(9)
// memset(a, 0, sizeof(a));
//--------------------------

ll Pow(ll x, ll k) {
  if (k == 0)
    return 1;
  if (k % 2 == 0)
    return Pow(x * x, k / 2);
  else
    return x * Pow(x, k - 1);
}

int main() {
  ll n, p;
  ll ans = 1;
  cin >> n >> p;

  if (n == 1) {
    cout << p << endl;
    return 0;
  }

  if (n > 40) {
    cout << 1 << endl;
    return 0;
  }

  ll a = 2;
  while (a * a <= p) {
    if (p % a == 0) {
      ll div = Pow(a, n);
      while (p % div == 0) {
        p /= div;
        ans *= a;
      }
    }
    a++;
  }

  cout << ans << endl;

  return 0;
}
Problem p03194 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>
#define INF 1000000007
using namespace std;

int main(void) {
  long long n, p, temp, ans = 1;
  int count = 0;
  cin >> n >> p;
  if (n >= 40) {
    cout << 1 << endl;
    return 0;
  }
  for (long long i = 2; i <= p; i++) {
    temp = 1;
    for (int j = 0; j < n; j++)
      temp *= i;
    while (p % temp == 0) {
      ans *= i;
      p /= temp;
    }
    while (p % i == 0)
      p /= i;
    if (temp >= p)
      break;
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>
#define INF 1000000007
using namespace std;

int main(void) {
  long long n, p, temp, ans = 1;
  int count = 0;
  cin >> n >> p;
  if (n >= 40) {
    cout << 1 << endl;
    return 0;
  }
  if (n == 1) {
    cout << p << endl;
    return 0;
  }
  for (long long i = 2; i <= p; i++) {
    temp = 1;
    for (int j = 0; j < n; j++)
      temp *= i;
    while (p % temp == 0) {
      ans *= i;
      p /= temp;
    }
    while (p % i == 0)
      p /= i;
    if (temp >= p)
      break;
  }
  cout << ans << endl;
  return 0;
}
Problem p03194 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cmath>
#include <iostream>
using namespace std;

int main() {
  long n, p;
  cin >> n >> p;
  if (n == 1) {
    cout << p << endl;
    return 0;
  } else if (n >= 40) {
    cout << 1 << endl;
    return 0;
  }
  int cnt = 0;
  int ans = 1;
  for (int i = 2; i <= p; i++) {
    //	  cout << "A" << i << endl;
    while ((p % i) == 0) {
      p /= i;
      cnt++;
      //		  cout << "b p;" << p << "cnt" << cnt << endl;
    }
    while (cnt >= n) {
      ans *= i;
      cnt -= n;
    }
    cnt = 0;
  }

  cout << ans << endl;
}


Fixed submission:
#include <cmath>
#include <iostream>
using namespace std;

int main() {
  long n, p;
  cin >> n >> p;
  if (n == 1) {
    cout << p << endl;
    return 0;
  } else if (n >= 40) {
    cout << 1 << endl;
    return 0;
  }
  int cnt = 0;
  int ans = 1;
  for (int i = 2; i <= p && i <= 1000000; i++) {
    //	  cout << "A" << i << endl;
    while ((p % i) == 0) {
      p /= i;
      cnt++;
      //		  cout << "b p;" << p << "cnt" << cnt << endl;
    }
    while (cnt >= n) {
      ans *= i;
      cnt -= n;
    }
    cnt = 0;
  }

  cout << ans << endl;
}
Problem p03194 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstddef>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <locale>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <valarray>
#include <vector>

using ll = long long;
using ull = unsigned long long;

// vector
template <class T> using vec = std::vector<T>;

template <class T> using vvec = vec<vec<T>>;

constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }

ll pow_n(ll l, ll n, ll p) {
  if (l > 1000000 && n >= 2)
    return -1;

  ll ret{1};

  for (ll i = 0; i < n; ++i) {
    ret *= l;
    if (ret > p || ret < 0) {
      ret = -1;
      break;
    }
  }

  return ret;
}

int main() {
  using namespace std;

  ll n, p;

  cin >> n >> p;

  ll ans{1};
  for (ll i = 2; pow_n(i, n, p) > 0; ++i) {
    auto po = pow_n(i, n, p);
    if (p % po == 0)
      ans = i;
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstddef>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <locale>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <valarray>
#include <vector>

using ll = long long;
using ull = unsigned long long;

// vector
template <class T> using vec = std::vector<T>;

template <class T> using vvec = vec<vec<T>>;

constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }

ll pow_n(ll l, ll n, ll p) {
  if (l > 1000000 && n >= 2)
    return -1;

  ll ret{1};

  for (ll i = 0; i < n; ++i) {
    ret *= l;
    if (ret > p || ret < 0) {
      ret = -1;
      break;
    }
  }

  return ret;
}

int main() {
  using namespace std;

  ll n, p;

  cin >> n >> p;

  if (n == 1) {
    cout << p << endl;
    return 0;
  }

  ll ans{1};
  for (ll i = 2; pow_n(i, n, p) > 0; ++i) {
    auto po = pow_n(i, n, p);
    if (p % po == 0)
      ans = i;
  }

  cout << ans << endl;

  return 0;
}
Problem p03194 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int INF = 1e9;
const int mod = 1e9 + 7;

int main() {
  ll n, p;
  cin >> n >> p;

  if (n == 1) {
    cout << p << endl;
    return 0;
  }
  ll ans = 1;
  for (int i = 2; i * i <= p; i++) {
    ll cnt = 0;
    while (p % i == 0) {
      p /= i;
      cnt++;
      if (cnt % n == 0)
        ans *= i;
    }
  }
  cout << ans << endl;
  return 0;
}

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

typedef long long ll;
typedef pair<int, int> P;

const int INF = 1e9;
const int mod = 1e9 + 7;

int main() {
  ll n, p;
  cin >> n >> p;

  if (n == 1) {
    cout << p << endl;
    return 0;
  }
  ll ans = 1;
  for (int i = 2; pow(i, n) <= p; i++) {
    while (p % (ll)pow(i, n) == 0) {
      p /= pow(i, n);
      ans *= i;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03194 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;

ll fastPow(ll i, ll x) {
  if (x == 0)
    return 1LL;
  if (x % 2 == 1)
    return i * fastPow(i, x - 1);
  else {
    ll ret = fastPow(i, x / 2);
    return ret * ret;
  }
}

int main() {
  ll n, p;
  cin >> n >> p;
  ll ans = 0;
  for (ll i = 1; pow(i, n) <= p; i++) {
    ll D = fastPow(i, n);
    if (p % D == 0)
      ans = max(ans, i);
  }
  cout << ans;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;

ll fastPow(ll i, ll x) {
  if (x == 0)
    return 1LL;
  if (x % 2 == 1)
    return i * fastPow(i, x - 1);
  else {
    ll ret = fastPow(i, x / 2);
    return ret * ret;
  }
}

int main() {
  ll n, p;
  cin >> n >> p;
  ll ans = 0;
  if (p == 1) {
    cout << 1;
    return 0;
  }
  if (n == 1) {
    cout << p;
    return 0;
  }
  for (ll i = 1; pow(i, n) <= p; i++) {
    ll D = fastPow(i, n);
    if (p % D == 0)
      ans = max(ans, i);
  }
  cout << ans;
}
Problem p03194 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  long long n, p;
  cin >> n >> p;
  long long ans = 1;
  if (n == 1) {
    cout << p << endl;
    return 0;
  }
  for (int i = 2; i * i <= p; ++i) {
    int cnt = 0;
    while (p % i == 0) {
      cnt++;
      p /= i;
      if (cnt == n) {
        ans *= i;
        cnt = 0;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <iostream>
using namespace std;
int main() {
  long long n, p;
  cin >> n >> p;
  long long ans = 1;
  if (n == 1) {
    cout << p << endl;
    return 0;
  }
  for (long long i = 2; i * i <= p; ++i) {
    int cnt = 0;
    while (p % i == 0) {
      cnt++;
      p /= i;
      if (cnt == n) {
        ans *= i;
        cnt = 0;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03194 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

class question {
public:
  ll N, P;
  ll pow(ll a, ll b) {
    if (b == 0)
      return 1;
    if (b % 2)
      return a * pow(a, b - 1);
    ll tmp = pow(a, b / 2);
    return tmp * tmp;
  }
  void ans() {
    cin >> N >> P;
    int res;
    for (int i = 1; pow(i, N) <= P && pow(i, N) > 0; i++) {
      if (P % pow(i, N) == 0)
        res = i;
    }
    cout << res << "\n";
  }
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  question q;
  q.ans();

  return 0;
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

class question {
public:
  ll N, P;
  ll pow(ll a, ll b) {
    if (b == 0)
      return 1;
    if (b % 2)
      return a * pow(a, b - 1);
    ll tmp = pow(a, b / 2);
    return tmp * tmp;
  }
  void ans() {
    cin >> N >> P;
    int res;
    if (N == 1) {
      cout << P << "\n";
      return;
    }
    for (int i = 1; pow(i, N) <= P && pow(i, N) > 0; i++) {
      if (P % pow(i, N) == 0)
        res = i;
    }
    cout << res << "\n";
  }
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  question q;
  q.ans();

  return 0;
}
Problem p03194 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <chrono>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF 1000000000
#define MOD 1000000007

long long power(long long a, long long b) {
  if (b == 0) {
    return 1;
  }

  long long result = 1;
  for (int i = 0; i < b; i++) {
    result *= a;
  }
  return result;
}

int main(int argc, char *argv[]) {
  long long N, P;
  cin >> N >> P;

  vector<long long> v;
  map<long long, long long> m;
  int i;

  if (N == 1) {
    // do nothing
  } else {
    for (i = 2; i * i <= P; i++) {
      while (P % i == 0) {
        m[i]++;
        //                v.push_back(i);
        P /= i;
      }
    }
  }

  if (P != 1) {
    //        v.push_back(P);
    m[P]++;
  }

  long long ans = 1;
  for (auto p : m) {
    if (p.second < N) {
      continue;
    } else {
      ans *= power(p.first, (p.second / N));
    }
    // cout << p.first << " -> " << p.second << endl;
  }
  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <chrono>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF 1000000000
#define MOD 1000000007

long long power(long long a, long long b) {
  if (b == 0) {
    return 1;
  }

  long long result = 1;
  for (int i = 0; i < b; i++) {
    result *= a;
  }
  return result;
}

int main(int argc, char *argv[]) {
  long long N, P;
  cin >> N >> P;

  vector<long long> v;
  map<long long, long long> m;
  ll i;

  if (N == 1) {
    // do nothing
  } else {
    for (i = 2; i * i <= P; i++) {
      while (P % i == 0) {
        m[i]++;
        //                v.push_back(i);
        P /= i;
      }
    }
  }

  if (P != 1) {
    //        v.push_back(P);
    m[P]++;
  }

  long long ans = 1;
  for (auto p : m) {
    if (p.second < N) {
      continue;
    } else {
      ans *= power(p.first, (p.second / N));
    }
    // cout << p.first << " -> " << p.second << endl;
  }
  cout << ans << endl;

  return 0;
}
Problem p03194 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
unsigned long long p;
unsigned long long quick(unsigned long long a, unsigned long long b) {
  if (b == 1)
    return a;
  unsigned long long ret = quick(a, b / 2);
  if (b % 2 == 1)
    return ret * ret * a;
  return ret * ret;
}
int main() {
  int n;
  unsigned long long pp = 2, ans = 1, tmp;
  scanf("%d%lld", &n, &p);
  if (n == 1) {
    printf("%lld", p);
    return 0;
  }
  while (p != 1) {
    tmp = quick(pp, n);
    if (p < tmp)
      break;
    while (p % tmp == 0) {
      p /= tmp;
      ans *= pp;
      if (p < tmp)
        break;
    }
    pp++;
  }
  printf("%lld", ans);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
unsigned long long p;
unsigned long long quick(unsigned long long a, unsigned long long b) {
  if (b == 1)
    return a;
  unsigned long long ret = quick(a, b / 2);
  if (b % 2 == 1)
    return ret * ret * a;
  return ret * ret;
}
int main() {
  int n;
  unsigned long long pp = 2, ans = 1, tmp;
  scanf("%d%lld", &n, &p);
  if (n == 1) {
    printf("%lld", p);
    return 0;
  }
  while (p != 1) {
    tmp = quick(pp, n);
    if (p < tmp || tmp == 0)
      break;
    while (p % tmp == 0) {
      p /= tmp;
      ans *= pp;
      if (p < tmp)
        break;
    }
    pp++;
  }
  printf("%lld", ans);
  return 0;
}
Problem p03194 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
int main(void) {
  ll n, p, a = 1, ans;
  cin >> n >> p;
  while (pow(a, n) <= p) {
    if (p % (ll)pow(a, n) == 0) {
      ans = a;
    }
    a++;
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
int main(void) {
  ll n, p, a = 1, ans;
  cin >> n >> p;
  if (n == 1) {
    cout << p << endl;
    return 0;
  }
  while (pow(a, n) <= p) {
    if (p % (ll)pow(a, n) == 0) {
      ans = a;
    }
    a++;
  }
  cout << ans << endl;
}
Problem p03194 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
typedef unsigned long long ull;
typedef long long ll;
#define MAX 1000000000001
using namespace std;

int main() {
  ull n, p;
  cin >> n >> p;
  ull max = 1, i = 2;
  while (pow(i, n) <= p) {
    if (p % (ull)pow(i, n) == 0) {
      max = i;
    }
    i++;
  }
  cout << max << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
typedef unsigned long long ull;
typedef long long ll;
#define MAX 1000000000001
using namespace std;

int main() {
  ull n, p;
  cin >> n >> p;
  ull max = 1, i = 2, x;
  if (n == 1) {
    cout << p << endl;
    return 0;
  }
  while ((x = pow(i, n)) && (x <= p)) {
    if (p % x == 0) {
      max = i;
    }
    i++;
  }
  cout << max << endl;
  return 0;
}