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

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <string.h>
#include <vector>
using namespace std;

#define abs(x) ((x) > 0 ? (x) : -(x))
bool prime[11000000];
bool b[11000000];
int n;
bool used[210], go[210][210];
int ans;
int ind[210];
int cnt0, cnt1;
int m;
int Link[210];

bool fi(int x) {
  for (int i = 1; i <= m; i++)
    if (go[x][i] && !used[i]) {
      if (!Link[i] || fi(Link[i])) {
        Link[i] = x;
        return true;
      }
    }
  return false;
}

int main() {
  scanf("%d", &n);
  for (int i = 2; i <= 10000000; i++)
    prime[i] = true;
  for (int i = 1; i * i <= 10000000; i++)
    if (prime[i])
      for (int j = i * i; j <= 10000000; j += i)
        prime[j] = false;
  prime[2] = false;

  for (int i = 1; i <= n; i++) {
    int t;
    scanf("%d", &t);
    b[t] ^= 1;
    b[t + 1] ^= 1;
  }
  for (int i = 1; i <= 10000001; i++)
    if (b[i]) {
      m += 1;
      ind[m] = i;
    }
  for (int i = 1; i <= m; i++)
    if (ind[i] % 2 == 0) {
      cnt0 += 1;
      for (int j = 1; j <= m; j++)
        if (ind[j] % 2 == 1 && prime[abs(ind[i] - ind[j])])
          go[i][j] = true;
    }
  int ans = 0;
  for (int i = 1; i <= m; i++)
    if (ind[i] % 2 == 0) {
      memset(used, false, sizeof used);
      if (fi(i))
        ans += 1;
    }
  int aa = ans;
  cnt1 = m - cnt0;
  // printf("?? %d %d\n", cnt0, cnt1);
  cnt0 -= ans;
  cnt1 -= ans;
  if (cnt0 % 2 == 0)
    aa += cnt0 + cnt1;
  else
    aa += 3 + (cnt0 - 1) + cnt1 - 1;
  printf("%d\n", aa);
}


Fixed submission:
#include <cstdio>
#include <string.h>
#include <vector>
using namespace std;

#define abs(x) ((x) > 0 ? (x) : -(x))
bool prime[11000000];
bool b[11000000];
int n;
bool used[210], go[210][210];
int ans;
int ind[210];
int cnt0, cnt1;
int m;
int Link[210];

bool fi(int x) {
  for (int i = 1; i <= m; i++)
    if (go[x][i] && !used[i]) {
      used[i] = true;
      if (!Link[i] || fi(Link[i])) {
        Link[i] = x;
        return true;
      }
    }
  return false;
}

int main() {
  scanf("%d", &n);
  for (int i = 2; i <= 10000000; i++)
    prime[i] = true;
  for (int i = 1; i * i <= 10000000; i++)
    if (prime[i])
      for (int j = i * i; j <= 10000000; j += i)
        prime[j] = false;
  prime[2] = false;

  for (int i = 1; i <= n; i++) {
    int t;
    scanf("%d", &t);
    b[t] ^= 1;
    b[t + 1] ^= 1;
  }
  for (int i = 1; i <= 10000001; i++)
    if (b[i]) {
      m += 1;
      ind[m] = i;
    }
  for (int i = 1; i <= m; i++)
    if (ind[i] % 2 == 0) {
      cnt0 += 1;
      for (int j = 1; j <= m; j++)
        if (ind[j] % 2 == 1 && prime[abs(ind[i] - ind[j])])
          go[i][j] = true;
    }
  int ans = 0;
  for (int i = 1; i <= m; i++)
    if (ind[i] % 2 == 0) {
      memset(used, false, sizeof used);
      if (fi(i))
        ans += 1;
    }
  int aa = ans;
  cnt1 = m - cnt0;
  // printf("?? %d %d\n", cnt0, cnt1);
  cnt0 -= ans;
  cnt1 -= ans;
  if (cnt0 % 2 == 0)
    aa += cnt0 + cnt1;
  else
    aa += 3 + (cnt0 - 1) + cnt1 - 1;
  printf("%d\n", aa);
}
Problem p03642 (C++)

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

#define REP(i, a, b) for (int i = a; i <= b; ++i)
typedef long long ll;

using namespace std;

void File() {
  freopen("ARC80F.in", "r", stdin);
  freopen("ARC80F.out", "w", stdout);
}

const int maxn = 100 + 10;
int n, a[maxn], pos[maxn], tot, cnt, ans;
int be[maxn], cnte, to[maxn * maxn], las[maxn * maxn], beg[maxn];
bool vis[maxn];

void add(int u, int v) {
  las[++cnte] = beg[u];
  beg[u] = cnte;
  to[cnte] = v;
}

bool pd(int x) {
  if (x == 1 || x == 2)
    return false;
  int y = sqrt(x);
  REP(i, 2, y) if (x % i == 0) return false;
  return true;
}

bool Hungary(int u) {
  for (int i = beg[u]; i; i = las[i]) {
    if (vis[to[i]])
      continue;
    vis[to[i]] = 1;
    if (!be[to[i]] || Hungary(be[to[i]])) {
      be[to[i]] = u;
      return true;
    }
  }
  return false;
}

int main() {
  // File();
  scanf("%d", &n);
  REP(i, 1, n) {
    scanf("%d", &a[i]);
    if (i == 1 || a[i - 1] < a[i] - 1)
      pos[++tot] = a[i];
    if (i != 1 && a[i] > a[i - 1] + 1)
      pos[++tot] = a[i - 1] + 1;
  }
  pos[++tot] = a[n] + 1;
  REP(i, 1, tot) if (pos[i] % 2)++ cnt;
  REP(i, 1, tot) if (pos[i] % 2 == 0) {
    REP(j, 1, tot) if (pos[j] % 2 == 1 && pd(abs(pos[j] - pos[i]))) add(i, j);
  }
  REP(i, 1, tot) if (pos[i] % 2 == 0) {
    memset(vis, 0, sizeof(vis));
    ans += Hungary(i);
  }
  printf("%d\n", ans + (tot - ans * 2) + (cnt - ans) % 2);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

#define REP(i, a, b) for (int i = a; i <= b; ++i)
typedef long long ll;

using namespace std;

void File() {
  freopen("ARC80F.in", "r", stdin);
  freopen("ARC80F.out", "w", stdout);
}

const int maxn = 500 + 10;
int n, a[maxn], pos[maxn], tot, cnt, ans;
int be[maxn], cnte, to[maxn * maxn], las[maxn * maxn], beg[maxn];
bool vis[maxn];

void add(int u, int v) {
  las[++cnte] = beg[u];
  beg[u] = cnte;
  to[cnte] = v;
}

bool pd(int x) {
  if (x == 1 || x == 2)
    return false;
  int y = sqrt(x);
  REP(i, 2, y) if (x % i == 0) return false;
  return true;
}

bool Hungary(int u) {
  for (int i = beg[u]; i; i = las[i]) {
    if (vis[to[i]])
      continue;
    vis[to[i]] = 1;
    if (!be[to[i]] || Hungary(be[to[i]])) {
      be[to[i]] = u;
      return true;
    }
  }
  return false;
}

int main() {
  // File();
  scanf("%d", &n);
  REP(i, 1, n) {
    scanf("%d", &a[i]);
    if (i == 1 || a[i - 1] < a[i] - 1)
      pos[++tot] = a[i];
    if (i != 1 && a[i] > a[i - 1] + 1)
      pos[++tot] = a[i - 1] + 1;
  }
  pos[++tot] = a[n] + 1;
  REP(i, 1, tot) if (pos[i] % 2)++ cnt;
  REP(i, 1, tot) if (pos[i] % 2 == 0) {
    REP(j, 1, tot) if (pos[j] % 2 == 1 && pd(abs(pos[j] - pos[i]))) add(i, j);
  }
  REP(i, 1, tot) if (pos[i] % 2 == 0) {
    memset(vis, 0, sizeof(vis));
    ans += Hungary(i);
  }
  printf("%d\n", ans + (tot - ans * 2) + (cnt - ans) % 2);
  return 0;
}
Problem p03642 (C++)

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

const int MAX_N = 205;

class Edge {
public:
  int nxt, to;
} e[MAX_N * MAX_N];

int head[MAX_N], cnt;
void addedge(int u, int v) { e[++cnt] = (Edge){head[u], v}, head[u] = cnt; }

bool isprime(int x) {
  for (int i = 2; i * i <= x; ++i)
    if (x % i == 0)
      return false;
  return true;
}

int N, pos[MAX_N], tot, val[MAX_N], match[MAX_N];
map<int, bool> vis;
bool bad[MAX_N];

bool dfs(int x) {
  if (vis[x])
    return false;
  bad[x] = 1;
  for (int i = head[x]; i; i = e[i].nxt)
    if (!match[e[i].to] || dfs(match[e[i].to])) {
      match[e[i].to] = x;
      return true;
    }
  return false;
}

int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i)
    scanf("%d", &pos[i]);
  pos[0] = -1;
  for (int i = 1; i <= N; ++i) {
    if (pos[i - 1] != pos[i] - 1)
      val[++tot] = pos[i];
    if (pos[i + 1] != pos[i] + 1)
      val[++tot] = pos[i] + 1;
  }

  int odd = 0, even = 0;

  for (int i = 1; i <= tot; ++i)
    if (val[i] & 1) {
      odd++;
      for (int j = 1; j <= tot; ++j)
        if (!(val[j] & 1) && abs(val[i] - val[j]) > 1 &&
            isprime(abs(val[i] - val[j])))
          addedge(i, j);
    } else {
      even++;
    }

  int num = 0;
  for (int i = 1; i <= tot; ++i)
    if (val[i] & 1) {
      memset(bad, 0, sizeof bad);
      num += dfs(i);
    }

  printf("%d\n",
         num + ((odd - num) / 2 + (even - num) / 2) * 2 + (odd - num) % 2 * 3);
  return 0;
}


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

const int MAX_N = 205;

class Edge {
public:
  int nxt, to;
} e[MAX_N * MAX_N];

int head[MAX_N], cnt;
void addedge(int u, int v) { e[++cnt] = (Edge){head[u], v}, head[u] = cnt; }

bool isprime(int x) {
  for (int i = 2; i * i <= x; ++i)
    if (x % i == 0)
      return false;
  return true;
}

int N, pos[MAX_N], tot, val[MAX_N], match[MAX_N];
map<int, bool> vis;
bool bad[MAX_N];

bool dfs(int x) {
  if (bad[x])
    return false;
  bad[x] = 1;
  for (int i = head[x]; i; i = e[i].nxt)
    if (!match[e[i].to] || dfs(match[e[i].to])) {
      match[e[i].to] = x;
      return true;
    }
  return false;
}

int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i)
    scanf("%d", &pos[i]);
  pos[0] = -1;
  for (int i = 1; i <= N; ++i) {
    if (pos[i - 1] != pos[i] - 1)
      val[++tot] = pos[i];
    if (pos[i + 1] != pos[i] + 1)
      val[++tot] = pos[i] + 1;
  }

  int odd = 0, even = 0;

  for (int i = 1; i <= tot; ++i)
    if (val[i] & 1) {
      odd++;
      for (int j = 1; j <= tot; ++j)
        if (!(val[j] & 1) && abs(val[i] - val[j]) > 1 &&
            isprime(abs(val[i] - val[j])))
          addedge(i, j);
    } else {
      even++;
    }

  int num = 0;
  for (int i = 1; i <= tot; ++i)
    if (val[i] & 1) {
      memset(bad, 0, sizeof bad);
      num += dfs(i);
    }

  printf("%d\n",
         num + ((odd - num) / 2 + (even - num) / 2) * 2 + (odd - num) % 2 * 3);
  return 0;
}
Problem p03642 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
bool bo[10001000], vis[410];
int st[410], mp[410][410], part[410], top, js0, js1;
bool isprime(int p) {
  if ((p <= 2) || (!(p & 1)))
    return false;
  for (int i = 2; i * i <= p; i++)
    if (p % i == 0)
      return false;
  return true;
}
bool search(int s) {
  vis[s] = true;
  for (int i = 1; i <= top; i++)
    if (mp[s][i]) {
      if (!part[i]) {
        part[i] = s;
        return true;
      } else if ((!vis[i]) && (search(part[i]))) {
        part[i] = s;
        return true;
      }
    }
  return false;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int w;
    scanf("%d", &w);
    bo[w] = true;
  }
  for (int i = 1; i <= 10000001; i++)
    if (bo[i] ^ bo[i - 1]) {
      st[++top] = i;
      if (i & 1)
        js1++;
      else
        js0++;
    }
  for (int i = 1; i <= top; i++)
    if (st[i] & 1)
      for (int j = 1; j <= top; j++)
        if (isprime(abs(st[i] - st[j])))
          mp[i][j] = 1;
  int sum = 0;
  for (int i = 1; i <= top; i++)
    if (st[i] & 1) {
      memset(vis, 0, sizeof(vis));
      sum += search(i);
    }
  js0 -= sum;
  js1 -= sum;
  cout << sum + js0 + js1 + (js0 & js1 & 1) << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
bool bo[10001000], vis[410];
int st[410], mp[410][410], part[410], top, js0, js1;
bool isprime(int p) {
  if ((p <= 2) || (!(p & 1)))
    return false;
  for (int i = 2; i * i <= p; i++)
    if (p % i == 0)
      return false;
  return true;
}
bool search(int s) {
  vis[s] = true;
  for (int i = 1; i <= top; i++)
    if (mp[s][i]) {
      if (!part[i]) {
        part[i] = s;
        return true;
      } else if ((!vis[part[i]]) && (search(part[i]))) {
        part[i] = s;
        return true;
      }
    }
  return false;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int w;
    scanf("%d", &w);
    bo[w] = true;
  }
  for (int i = 1; i <= 10000001; i++)
    if (bo[i] ^ bo[i - 1]) {
      st[++top] = i;
      if (i & 1)
        js1++;
      else
        js0++;
    }
  for (int i = 1; i <= top; i++)
    if (st[i] & 1)
      for (int j = 1; j <= top; j++)
        if (isprime(abs(st[i] - st[j])))
          mp[i][j] = 1;
  int sum = 0;
  for (int i = 1; i <= top; i++)
    if (st[i] & 1) {
      memset(vis, 0, sizeof(vis));
      sum += search(i);
    }
  js0 -= sum;
  js1 -= sum;
  cout << sum + js0 + js1 + (js0 & js1 & 1) << endl;
}
Problem p03642 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <vector>
using namespace std;
const int maxn = 101;

int n, a[maxn];
vector<int> q, odd, eve;
vector<int> po[maxn * 2], pe[maxn * 2];
int to, te, s;
bool vis[maxn * 2];
int match[maxn * 2];

bool prime(int p) {
  if (p <= 2)
    return false;
  for (int i = 2; i <= sqrt(p); i++)
    if (p % i == 0)
      return false;
  return true;
}

bool calc(int p) {
  for (int i = 0; i < po[p].size(); i++) {
    int nxt = po[p][i];
    if (vis[nxt])
      continue;

    if (!match[nxt] || calc(match[nxt])) {
      match[nxt] = p;
      return true;
    }
  }
  return false;
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);

  q.push_back(a[1]);
  for (int i = 1; i < n; i++) {
    if (a[i] + 1 < a[i + 1]) {
      q.push_back(a[i] + 1);
      q.push_back(a[i + 1]);
    }
  }
  q.push_back(a[n] + 1);

  odd.push_back(0);
  eve.push_back(0);
  for (int i = 0; i < q.size(); i++) {
    if (q[i] % 2)
      odd.push_back(q[i]), to++;
    else
      eve.push_back(q[i]), te++;
  }

  for (int i = 1; i <= to; i++) {
    for (int j = 1; j <= te; j++) {
      if (prime(abs(odd[i] - eve[j]))) {
        po[i].push_back(j);
        pe[j].push_back(i);
      }
    }
  }

  s = 0;
  for (int i = 1; i <= to; i++) {
    for (int j = 1; j <= te; j++)
      vis[j] = false;
    if (calc(i))
      s++;
  }

  int ans = s + ((to - s) / 2 + (te - s) / 2) * 2 + (to - s) % 2 * 3;
  printf("%d\n", ans);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <vector>
using namespace std;
const int maxn = 101;

int n, a[maxn];
vector<int> q, odd, eve;
vector<int> po[maxn * 2], pe[maxn * 2];
int to, te, s;
bool vis[maxn * 2];
int match[maxn * 2];

bool prime(int p) {
  if (p <= 2)
    return false;
  for (int i = 2; i <= sqrt(p); i++)
    if (p % i == 0)
      return false;
  return true;
}

bool calc(int p) {
  for (int i = 0; i < po[p].size(); i++) {
    int nxt = po[p][i];
    if (vis[nxt])
      continue;
    vis[nxt] = true;

    if (!match[nxt] || calc(match[nxt])) {
      match[nxt] = p;
      return true;
    }
  }
  return false;
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);

  q.push_back(a[1]);
  for (int i = 1; i < n; i++) {
    if (a[i] + 1 < a[i + 1]) {
      q.push_back(a[i] + 1);
      q.push_back(a[i + 1]);
    }
  }
  q.push_back(a[n] + 1);

  odd.push_back(0);
  eve.push_back(0);
  for (int i = 0; i < q.size(); i++) {
    if (q[i] % 2)
      odd.push_back(q[i]), to++;
    else
      eve.push_back(q[i]), te++;
  }

  for (int i = 1; i <= to; i++) {
    for (int j = 1; j <= te; j++) {
      if (prime(abs(odd[i] - eve[j]))) {
        po[i].push_back(j);
        pe[j].push_back(i);
      }
    }
  }

  s = 0;
  for (int i = 1; i <= to; i++) {
    for (int j = 1; j <= te; j++)
      vis[j] = false;
    if (calc(i))
      s++;
  }

  int ans = s + ((to - s) / 2 + (te - s) / 2) * 2 + (to - s) % 2 * 3;
  printf("%d\n", ans);
  return 0;
}
Problem p03643 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <stdio.h>
#include <string>
#include <typeinfo>
using namespace std;

int main() {
  char s1[] = "ABC";
  char s2[4];
  cin >> s2;
  strcat(s1, s2);
  cout << s1;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <stdio.h>
#include <string>
#include <typeinfo>
using namespace std;

int main() {
  int a;
  cin >> a;
  cout << "ABC" << a;
}
Problem p03643 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  int n, c, i = 0;
  cin >> n;
  while (n >= 0) {
    c = n % 10;
    n /= 10;
    i += 1;
  }
  if (i == 3) {
    cout << 'A' << 'B' << 'C' << n;
  } else if (i == 2)
    cout << 'A' << 'B' << n;
  else
    cout << 'A' << n;
  return 0;
}


Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int N;
  cin >> N;
  cout << "ABC" << N;
  return 0;
}
Problem p03643 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  printf("ABC");
  int a;
  scanf("%d", a);
  printf("%d\n", a);
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  printf("ABC");
  int a;
  scanf("%d", &a);
  printf("%d\n", a);
}
Problem p03643 (Python)

Buggy submission (status: Runtime Error):
N = int(input())
print(f"ABC{N}")


Fixed submission:
N = int(input())
print("ABC" + str(N))
Problem p03643 (Python)

Buggy submission (status: Runtime Error):
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())

print("ABC" + N)


Fixed submission:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())

print("ABC" + str(N))
Problem p03643 (Python)

Buggy submission (status: Runtime Error):
n = input()
print(int(n[3:]))


Fixed submission:
n = input()
print("ABC" + n)
Problem p03643 (Python)

Buggy submission (status: Runtime Error):
n = int(input())

print("ABC" + n)


Fixed submission:
n = int(input())

print("ABC" + str(n))
Problem p03644 (C++)

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

int func(int x) {
  if (x % 2 == 1)
    return 0;
  return func(x / 2) + 1;
}
int main() {
  int N;
  cin >> N;
  int ans = 1;
  for (int i = 0; i < N; i++) {
    if (func(i) > func(ans)) {
      ans = i;
    }
  }
  cout << ans << endl;
}

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

int func(int x) {
  if (x % 2 == 1)
    return 0;
  return func(x / 2) + 1;
}
int main() {
  int N;
  cin >> N;
  int ans = 1;
  for (int i = 1; i <= N; i++) {
    if (func(i) > func(ans)) {
      ans = i;
    }
  }
  cout << ans << endl;
}
Problem p03644 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>
#include <vector>

int main(void) {
  std::int64_t N; //,A,B;
  std::cin >> N;

  if (N == 1) {
    std::cout << 1 << std::endl;
    return 1;
  }

  int ctr = 1;
  int tmp = 2;
  while (tmp <= N) {
    tmp *= 2;
    ctr++;
  }
  std::cout << tmp / 2 << std::endl;

  return 0;
}


Fixed submission:
#include <cstdio>
#include <iostream>
#include <vector>

int main(void) {
  std::int64_t N; //,A,B;
  std::cin >> N;

  if (N == 1) {
    std::cout << 1 << std::endl;
    return 0;
  }

  int ctr = 1;
  int tmp = 2;
  while (tmp <= N) {
    tmp *= 2;
    ctr++;
  }
  std::cout << tmp / 2 << std::endl;

  return 0;
}
Problem p03644 (C++)

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

int main() {
  int n, li[100] = {0};
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int tmp = i;

    while (true) {
      if (tmp % 2 == 0) {
        tmp /= 2;
        li[i - 1]++;
      }
    }
  }

  int max_i, max = -1;
  for (int i = 1; i <= n; i++) {
    if (li[i - 1] > max) {
      max = li[i - 1];
      max_i = i;
    }
  }

  cout << max_i << endl;
}

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

int main() {
  int n, li[100] = {0};
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int tmp = i;

    while (true) {
      if (tmp % 2 == 0) {
        tmp /= 2;
        li[i - 1]++;
      } else {
        break;
      }
    }
  }

  int max_i, max = -1;
  for (int i = 1; i <= n; i++) {
    if (li[i - 1] > max) {
      max = li[i - 1];
      max_i = i;
    }
  }

  cout << max_i << endl;
}
Problem p03644 (C++)

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

int main() {
  int N;
  cin >> N;
  int out = 1;
  while ((N / 2) != 0) {
    out *= 2;
  }
  cout << out << endl;
}


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

int main() {
  int N;
  cin >> N;
  int out = 1;
  while ((N / 2) != 0) {
    N /= 2;
    out *= 2;
  }
  cout << out << endl;
}
Problem p03644 (C++)

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end)                                                     \
  for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end)                                                    \
  for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main() {
  int n;
  cin >> n;
  vector<int> v(n + 1);
  for (int i = 1; (1 << i) <= n; i++) {
    for (int j = 1; i * j <= n; j++) {
      if ((1 << i) * j > n + 1)
        break;
      v[(1 << i) * j] = i;
    }
  }
  int ans = 0;
  int out = 1;
  for (int i = 0; i < n + 1; i++) {
    if (v[i] > ans) {
      ans = v[i];
      out = i;
    }
  }
  cout << out << "\n";
  return 0;
}

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end)                                                     \
  for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end)                                                    \
  for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main() {
  int n;
  cin >> n;
  vector<int> v(n + 1);
  for (int i = 1; (1 << i) <= n; i++) {
    for (int j = 1; i * j <= n; j++) {
      if ((1 << i) * j > n)
        break;
      v[(1 << i) * j] = i;
    }
  }
  int ans = 0;
  int out = 1;
  for (int i = 0; i < n + 1; i++) {
    if (v[i] > ans) {
      ans = v[i];
      out = i;
    }
  }
  cout << out << "\n";
  return 0;
}
Problem p03644 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <string>

using namespace std;

int main() {
  int N;
  int large;
  int counter, high_count;
  int target;
  cin >> N;
  high_count = 0;
  for (int i = 0; i < N + 1; i++) {
    int aNumber = i;
    counter = 0;
    while (aNumber % 2 == 0)
      aNumber /= 2, counter++;
    if (counter > high_count) {
      target = i;
      high_count = counter;
    }
  }

  cout << target << endl;
}


Fixed submission:
#include <iostream>
#include <string>

using namespace std;

int main() {
  int N;
  int large;
  int counter, high_count;
  int target;
  cin >> N;
  high_count = 0;
  target = 1;
  for (int i = 1; i < N + 1; i++) {
    int aNumber = i;
    counter = 0;
    while (aNumber % 2 == 0)
      aNumber /= 2, counter++;
    if (counter > high_count) {
      target = i;
      high_count = counter;
    }
  }

  cout << target << endl;
}
Problem p03644 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define SORT(x) sort(x.begin(), x.end())
#define REVE(x) reverse(x.begin(), x.end())
#define all(x) (x).begin(), (x).end()
#define fst first
#define mp make_pair
#define pb push_back
using LL = long long;
using ULL = unsigned long long;
#define FOR(i, m, n) for (int i = m; i < n; i++)
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, A;
  cin >> N;
  for (int i = 0; i <= N; i *= 2) {
    A = i;
  }

  cout << A;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define SORT(x) sort(x.begin(), x.end())
#define REVE(x) reverse(x.begin(), x.end())
#define all(x) (x).begin(), (x).end()
#define fst first
#define mp make_pair
#define pb push_back
using LL = long long;
using ULL = unsigned long long;
#define FOR(i, m, n) for (int i = m; i < n; i++)
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, A;
  cin >> N;
  for (int i = 1; i <= N; i *= 2) {
    A = i;
  }

  cout << A;
}
Problem p03644 (C++)

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

int main() {
  int n;
  cin >> n;
  int ans = 0;
  int maxc = 0;
  for (int i = 1; i <= n; i++) {
    int count = 0;
    while (i > 0) {
      if (i % 2 == 0) {
        count++;
        i /= 2;
      } else
        break;
    }
    maxc = max(maxc, count);
    if (maxc == count)
      ans = i;
  }
  cout << ans << endl;
}

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

int main() {
  int n;
  cin >> n;
  if (n < 2)
    cout << 1 << endl;
  else if (n < 4)
    cout << 2 << endl;
  else if (n < 8)
    cout << 4 << endl;
  else if (n < 16)
    cout << 8 << endl;
  else if (n < 32)
    cout << 16 << endl;
  else if (n < 64)
    cout << 32 << endl;
  else if (n < 128)
    cout << 64 << endl;
}
Problem p03644 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int j = 0;
  int count = 0;
  for (int i = 1; i <= n; i++) {
    while (i > 0) {
      if (i % 2 == 0) {
        i /= 2;
        count++;
      }
    }
    if (count > j)
      j = count;
  }
  cout << j << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  if (n >= 64)
    cout << 64 << endl;
  else if (32 <= n && n < 64)
    cout << 32 << endl;
  else if (16 <= n && n < 32)
    cout << 16 << endl;
  else if (8 <= n && n < 16)
    cout << 8 << endl;
  else if (4 <= n && n < 8)
    cout << 4 << endl;
  else if (2 <= n && n < 4)
    cout << 2 << endl;
  else
    cout << 1 << endl;
}
Problem p03644 (C++)

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


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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int N;
  cin >> N;
  int mx = 0;
  int ans = 0;
  for (int i = 1; i < N + 1; i++) {
    int x = 0;
    while (true) {
      if (i % 2 == 0) {
        i /= 2;
        x++;
      } else
        break;
    }
    mx = (mx, x);
    if (mx == x)
      ans = i;
  }

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


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

int main() {
  int N;
  cin >> N;
  int ans;
  if (N < 2)
    ans = 1;
  else if (N < 4)
    ans = 2;
  else if (N < 8)
    ans = 4;
  else if (N < 16)
    ans = 8;
  else if (N < 32)
    ans = 16;
  else if (N < 64)
    ans = 32;
  else
    ans = 64;

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

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

int main() {
  int n;
  cin >> n;
  int res = 0;
  int num = 1;
  for (int i = 0; i < n; i++) {
    int res1 = 0;
    int j = i;
    while (j % 2 == 0) {
      j /= 2;
      ++res1;
    }
    if (res1 > res) {
      res = res1;
      num = i;
    }
  }
  cout << num << endl;

  return 0;
}

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

int main() {
  int n;
  cin >> n;
  int res = 0;
  int num = 1;
  for (int i = 1; i <= n; i++) {
    int res1 = 0;
    int j = i;
    while (j % 2 == 0) {
      j /= 2;
      ++res1;
    }
    if (res1 > res) {
      res = res1;
      num = i;
    }
  }
  cout << num << endl;

  return 0;
}
Problem p03644 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  int max = 0;
  int ans = 0;
  for (int i = 0; i <= n; ++i) {
    int count = 0;
    int target = i;
    while (target % 2 == 0) {
      target /= 2;
      count++;
    }
    if (max < count) {
      max = count;
      ans = i;
    }
  }
  cout << ans << "\n";
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  int max = 0;
  int ans = 1;
  for (int i = 1; i <= n; ++i) {
    int count = 0;
    int target = i;
    while (target % 2 == 0) {
      target /= 2;
      count++;
    }
    if (max < count) {
      max = count;
      ans = i;
    }
  }
  cout << ans << "\n";
  return 0;
}
Problem p03644 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;

int main() {
  int N;
  scanf("%d", &N);
  int num[N + 1];
  int max = 0;
  int max_N = 0;
  for (int i = 0; i < N + 2; i++) {
    int t = 0;
    int k = i;
    while (k % 2 == 0) {
      t++;
      k = k / 2;
    }
    if (t > max) {
      max = t;
      max_N = i;
    }
  }
  cout << max_N << endl;

  return 0;
}

Fixed submission:
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;

int main() {
  int N;
  scanf("%d", &N);
  int num[N + 1];
  int max = 0;
  int max_N = 1;
  for (int i = 1; i < N + 1; i++) {
    int t = 0;
    int k = i;
    while (k % 2 == 0) {
      t++;
      k = k / 2;
    }
    if (t > max) {
      max = t;
      max_N = i;
    }
  }
  cout << max_N << endl;

  return 0;
}
Problem p03644 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  int N;
  cin >> N;
  int ans = 1;
  while (ans <= N) {
    if (ans * 2 <= N) {
      ans *= 2;
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int N;
  cin >> N;
  int ans = 1;
  while (ans <= N) {
    if (ans * 2 <= N) {
      ans *= 2;
    } else {
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03644 (C++)

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define m0(x) memset(x, 0, sizeof(x))

int dx4[4] = {1, 0, -1, 0}, dy4[4] = {0, 1, 0, -1};

int main() {
  int n, ans = 0;
  cin >> n;

  while (ans * 2 <= n) {
    ans *= 2;
  }
  cout << ans << endl;

  return 0;
}

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define m0(x) memset(x, 0, sizeof(x))

int dx4[4] = {1, 0, -1, 0}, dy4[4] = {0, 1, 0, -1};

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

  while (ans * 2 <= n) {
    ans *= 2;
  }
  cout << ans << endl;

  return 0;
}
Problem p03644 (C++)

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

int main() {

  long long N;
  cin >> N;

  vector<int> v;
  int cnt = 0;
  int tmp = 0;

  if (N == 1) {

    cout << 1 << endl;

    return 1;
  }

  while (1) {
    tmp = pow(2, cnt);
    if (tmp > 100) {
      break;
    } else {
      v.push_back(tmp);

      cnt++;
    }
  }

  int imax = 0;
  for (int i = 0; i < v.size(); i++) {
    if (v[i] <= N) {
      imax = max(imax, v[i]);
    }
  }

  cout << imax << endl;
}

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

int main() {

  long long N;
  cin >> N;

  vector<int> v;
  int cnt = 0;
  int tmp = 0;

  if (N == 1) {

    cout << 1 << endl;

    return 0;
  }

  while (1) {
    tmp = pow(2, cnt);
    if (tmp > 100) {
      break;
    } else {
      v.push_back(tmp);

      cnt++;
    }
  }

  int imax = 0;
  for (int i = 0; i < v.size(); i++) {
    if (v[i] <= N) {
      imax = max(imax, v[i]);
    }
  }

  cout << imax << endl;
}
Problem p03644 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int ans = 1;
  while (N > 0) {
    N / 2;
    ans *= 2;
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int ans = 1;
  while (N > 1) {
    N = N / 2;
    ans *= 2;
  }
  cout << ans << endl;
}
Problem p03644 (Python)

Buggy submission (status: Runtime Error):
import sys

N = int(sys.stdin.readline())

sorted_list = [1, 2, 4, 8, 16, 32, 64, N][::1]
min_index = sorted_list[sorted_list.index(N) + 1]
print(min_index)


Fixed submission:
import sys

N = int(sys.stdin.readline())

if N in [1, 2, 4, 8, 16, 32, 64]:
    print(N)
else:
    sorted_list = sorted([1, 2, 4, 8, 16, 32, 64, N])[::-1]
    min_index = sorted_list[sorted_list.index(N) + 1]
    print(min_index)
Problem p03644 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int i;
  cin >> i;
  int flag = 0;
  for (int j = i; j >= 0; j--) {
    // cout<<j<<endl;
    for (int k = j;;) {
      // cout<<k<<" ";
      if (k % 2 != 0)
        break;
      if (k == 2) {
        flag = 1;
        break;
      }
      k = k / 2;
    }
    // cout<<endl;
    if (flag) {
      cout << j << endl;
      break;
    }
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int i;
  cin >> i;
  int flag = 0;
  for (int j = i; j >= 0; j--) {
    // cout<<j<<endl;
    for (int k = j;;) {
      // cout<<k<<" ";
      if (k == 1) {
        flag = 1;
        break;
      }
      if (k % 2 != 0)
        break;
      if (k == 2) {
        flag = 1;
        break;
      }
      k = k / 2;
    }
    // cout<<endl;
    if (flag) {
      cout << j << endl;
      break;
    }
  }
  return 0;
}
Problem p03644 (Python)

Buggy submission (status: Runtime Error):
# https://atcoder.jp/contests/abc068/tasks/abc068_b


def two_factor(x):
    cnt = 0
    while x % 2 == 0:
        cnt += 1
        x //= 2
    return cnt


N = int(input())
a = map(two_factor, range(1, N + 1))
max_cnt = max(a)
print(a.index(max_cnt) + 1)


Fixed submission:
# https://atcoder.jp/contests/abc068/tasks/abc068_b


def two_factor(x):
    cnt = 0
    while x % 2 == 0:
        cnt += 1
        x //= 2
    return cnt


N = int(input())
a = list(map(two_factor, range(1, N + 1)))
max_cnt = max(a)
print(a.index(max_cnt) + 1)
Problem p03644 (Python)

Buggy submission (status: Runtime Error):
n = int(input())
for i in range(7):
    if (2**i) < n:
        ans = 2**i
print(ans)


Fixed submission:
n = int(input())
for i in range(7):
    if (2**i) <= n:
        ans = 2**i
print(ans)
Problem p03644 (Python)

Buggy submission (status: Runtime Error):
from sys import stdin
import math


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N = int(_in[0])  # type:int
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    cnt = 2 ** math.floor(math.log2(N))
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)


Fixed submission:
from sys import stdin
import math


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N = int(_in[0])  # type:int
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    cnt = 2 ** math.floor(math.log(N, 2))
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)
Problem p03644 (C++)

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

int main(void) {
  int N;
  scanf("%d", &N);
  int divMax = 0;
  int ans = 1;
  for (int i = 1; i <= N; i++) {
    int cnt = 0;
    while (i % 2 == 0) {
      i %= 2;
      cnt++;
    }
    if (cnt > divMax) {
      divMax = cnt;
      ans = i;
    }
  }
  printf("%d\n", ans);
  return 0;
}


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

int main(void) {
  int N;
  scanf("%d", &N);
  int divMax = 0;
  int ans = 1;
  for (int i = 1; i <= N; i++) {
    int cnt = 0;
    int tmp = i;
    while (tmp > 0) {
      // cout << tmp << "\n";
      if (tmp % 2 == 0) {
        tmp /= 2;
        cnt++;
      } else {
        break;
      }
    }
    if (cnt > divMax) {
      divMax = cnt;
      ans = i;
    }
  }
  printf("%d\n", ans);
  return 0;
}
Problem p03644 (C++)

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

int main() {

  int N;
  cin >> N;
  int res = -1;
  int count = 0;
  for (int i = N / 2; i < N; i++) {
    while (i % 2 == 0) {
      i /= 2;
      count++;
    }
    if (res < count)
      res = count;
  }
  cout << res << endl;
}


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

int main() {

  int n;
  cin >> n;
  if (n >= 1 && n < 2)
    cout << 1 << endl;
  if (n >= 2 && n < 4)
    cout << 2 << endl;
  if (n >= 4 && n < 8)
    cout << 4 << endl;
  if (n >= 8 && n < 16)
    cout << 8 << endl;
  if (n >= 16 && n < 32)
    cout << 16 << endl;
  if (n >= 32 && n < 64)
    cout << 32 << endl;
  if (n >= 64 && n <= 100)
    cout << 64 << endl;
}
Problem p03644 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a;
  cin >> a;
  for (; (a & -a) != a; a ^= a & -a)
    ;
  return 0, printf("%d\n", a);
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a;
  cin >> a;
  for (; (a & -a) != a; a ^= a & -a)
    ;
  return printf("%d\n", a), 0;
}
Problem p03645 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793
ll gcd(ll a, ll b) {
  if (b > a)
    swap(a, b);
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a / g * b;
}

int main() {
  int n, m;
  cin >> n >> m;
  bool flag = false;
  vector<int> A(n, 0);
  vector<int> B(n, 0);
  vector<int> C(n, 0);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    if (a == 1) {
      A[b - 1]++;
    } else if (b == n) {
      B[a - 1]++;
    }
  }
  rep(i, m) {
    C[i] = A[i] + B[i];
    if (C[i] == 2)
      flag = true;
  }
  if (flag)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793
ll gcd(ll a, ll b) {
  if (b > a)
    swap(a, b);
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a / g * b;
}

int main() {
  int n, m;
  cin >> n >> m;
  bool flag = false;
  vector<int> A(n, 0);
  vector<int> B(n, 0);
  vector<int> C(n, 0);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    if (a == 1) {
      A[b - 1]++;
    } else if (b == n) {
      B[a - 1]++;
    }
  }
  rep(i, n) {
    C[i] = A[i] + B[i];
    if (C[i] == 2)
      flag = true;
  }
  if (flag)
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;
  return 0;
}
Problem p03645 (C++)

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

using namespace std;

int main() {
  int N, M, x, y;
  bool ans = false;
  cin >> N >> M;
  vector<vector<int>> ab(M);
  for (int i = 0; i < M; i++) {
    cin >> x >> y;
    x--;
    y--;
    ab[x].push_back(y);
    ab[y].push_back(x);
  }

  for (int i = 0; i < ab[0].size(); i++) {
    for (int j = 0; j < ab[ab[0][i]].size(); j++) {
      if (ab[ab[0][i]][j] == N - 1) {
        ans = true;
      }
    }
  }

  if (ans) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

int main() {
  int N, M, x, y;
  bool ans = false;
  cin >> N >> M;
  vector<vector<int>> ab(N);
  for (int i = 0; i < M; i++) {
    cin >> x >> y;
    x--;
    y--;
    ab[x].push_back(y);
    ab[y].push_back(x);
  }

  for (int i = 0; i < ab[0].size(); i++) {
    for (int j = 0; j < ab[ab[0][i]].size(); j++) {
      if (ab[ab[0][i]][j] == N - 1) {
        ans = true;
      }
    }
  }

  if (ans) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
}
Problem p03645 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll MOD = 1000000007;
const ll INF = 1000000000LL;
const int MAX = 100001;
const double EPS = 1e-10;
struct edge {
  int to, cost;
};
typedef pair<int, int> P;
int V;
vector<edge> G[114514];
int d[114514];
void dijkstra(int s) {
  priority_queue<P, vector<P>, greater<P>> que;
  fill(d, d + V, INF);
  d[s] = 0;
  que.push(P(0, s));
  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first) {
      continue;
    }
    for (int i = 0; i < G[v].size(); i++) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}

int main() {
  int n, m;
  cin >> n >> m;
  V = n;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back({b, 1});
    G[b].push_back({a, 1});
  }
  dijkstra(0);
  if (d[n - 1] == 2) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll MOD = 1000000007;
const ll INF = 1000000000LL;
const int MAX = 100001;
const double EPS = 1e-10;
struct edge {
  int to, cost;
};
typedef pair<int, int> P;
int V;
vector<edge> G[214514];
int d[214514];
void dijkstra(int s) {
  priority_queue<P, vector<P>, greater<P>> que;
  fill(d, d + V, INF);
  d[s] = 0;
  que.push(P(0, s));
  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first) {
      continue;
    }
    for (int i = 0; i < G[v].size(); i++) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}

int main() {
  int n, m;
  cin >> n >> m;
  V = n;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back({b, 1});
    G[b].push_back({a, 1});
  }
  dijkstra(0);
  if (d[n - 1] == 2) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
}
Problem p03645 (C++)

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  vector<int> b(m);
  int cur = 0, now = 0;
  for (int i = 0; i < m; i++) {
    cin >> a.at(i) >> b.at(i);
    if (a.at(i) == 1) {
      cur++;
    } else if (b.at(i) == n) {
      now++;
    }
  }
  vector<int> start(cur);
  vector<int> goal(now);
  int c = 0, d = 0;
  int k = 0, ok = 0;
  if (cur != 0 || now != 0) {
    for (int i = 0; i < m; i++) {
      if (a.at(i) == 1) {
        start.at(c) = b.at(i);
        c++;
      } else if (b.at(i) == n) {
        goal.at(d) = a.at(i);
        d++;
      }
    }
    sort(goal.begin(), goal.end());
    for (int i = 0; i < cur; i++) {
      k = lower_bound(goal.begin(), goal.end(), start.at(i)) - goal.begin();
      if (goal.at(k) == start.at(i)) {
        ok++;
        break;
      }
    }
  }
  if (ok != 0) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  vector<int> b(m);
  int cur = 0, now = 0;
  for (int i = 0; i < m; i++) {
    cin >> a.at(i) >> b.at(i);
    if (a.at(i) == 1) {
      cur++;
    } else if (b.at(i) == n) {
      now++;
    }
  }
  vector<int> start(cur);
  vector<int> goal(now);
  int c = 0, d = 0;
  int k = 0, ok = 0;
  if (cur != 0 || now != 0) {
    for (int i = 0; i < m; i++) {
      if (a.at(i) == 1) {
        start.at(c) = b.at(i);
        c++;
      } else if (b.at(i) == n) {
        goal.at(d) = a.at(i);
        d++;
      }
    }
    sort(goal.begin(), goal.end());
    for (int i = 0; i < cur; i++) {
      k = lower_bound(goal.begin(), goal.end(), start.at(i)) - goal.begin();
      if (k < now) {
        if (goal.at(k) == start.at(i)) {
          ok++;
          break;
        }
      }
    }
  }
  if (ok != 0) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
}
Problem p03645 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define INF 1000000000000
using namespace std;
using ll = long long;
int main() {
  ll n, m;
  cin >> n >> m;
  vector<pair<ll, ll>> p(n);
  bool val[200010] = {};
  bool ans = false;
  for (ll i = 0; i < m; i++) {
    ll x, y;
    cin >> x >> y;
    p[i] = make_pair(x, y);
    if (x == 1) {
      val[y] = true;
    } else if (y == 1) {
      val[x] = true;
    }
  }
  for (ll i = 0; i < m; i++) {
    if (val[p[i].first] == true) {
      if (p[i].second == n) {
        ans = true;
      }
    } else if (val[p[i].second] == true) {
      if (p[i].first == n) {
        ans = true;
      }
    }
  }
  if (ans == true) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define INF 1000000000000
using namespace std;
using ll = long long;
int main() {
  ll n, m;
  cin >> n >> m;
  vector<pair<ll, ll>> p(m);
  bool val[200010] = {};
  bool ans = false;
  for (ll i = 0; i < m; i++) {
    ll x, y;
    cin >> x >> y;
    p[i] = make_pair(x, y);
    if (x == 1) {
      val[y] = true;
    } else if (y == 1) {
      val[x] = true;
    }
  }
  for (ll i = 0; i < m; i++) {
    if (val[p[i].first] == true) {
      if (p[i].second == n) {
        ans = true;
      }
    } else if (val[p[i].second] == true) {
      if (p[i].first == n) {
        ans = true;
      }
    }
  }
  if (ans == true) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
}
Problem p03645 (C++)

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

int main() {
  ll n, m;
  cin >> n >> m;
  ll a[m], b[m];
  // pair<ll,ll>ab[m];
  int t[100005];
  for (ll i = 0; i < 100005; i++)
    t[i] = 0;
  for (ll i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    // ab[i] = make_pair(a[i],b[i]);
    if (a[i] == 1)
      t[b[i]] = 1;
    // cout<<"aaa"<<endl;
  }
  // sort(ab,ab+m);
  for (ll i = 0; i < m; i++) {
    if (b[i] != n)
      continue;
    if (t[a[i]] == 1) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}


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

int main() {
  ll n, m;
  cin >> n >> m;
  ll a[m], b[m];
  // pair<ll,ll>ab[m];
  int t[200005];
  for (ll i = 0; i < 200005; i++)
    t[i] = 0;
  for (ll i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    // ab[i] = make_pair(a[i],b[i]);
    if (a[i] == 1)
      t[b[i]] = 1;
    // cout<<"aaa"<<endl;
  }
  // sort(ab,ab+m);
  for (ll i = 0; i < m; i++) {
    if (b[i] != n)
      continue;
    if (t[a[i]] == 1) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}