Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
def main():
    n, m = map(int, input().split())

    ans = [None for _ in range(m)]
    used = set()
    a = 1
    b = n
    good = True
    for i in range(m):
        if b - a == n - (b - a):
            a += 1
            b -= 1
        ans[i] = (a, b)
        if (b - a) in used:
            good = False
            break
        else:
            used.add(b - a)
        if (n - (b - a)) in used:
            good = False
            break
        else:
            used.add(n - (b - a))
        a += 1
        b -= 1

    if not good:
        ans = [None for _ in range(m)]
        used = set()
        a = 1
        b = n-1
        good = True
        for i in range(m):
            if b - a == n - (b - a):
                a += 1
                b -= 1
            ans[i] = (a, b)
            if (b - a) in used:
                good = False
                break
            else:
                used.add(b - a)
            if (n - (b - a)) in used:
                good = False
                break
            else:
                used.add(n - (b - a))
            a += 1
            b -= 1

    for i in range(m):
        print(ans[i][0], ans[i][1])

if __name__ == '__main__':
    main()


Fixed submission:
def main():
    n, m = map(int, input().split())

    ans = [None for _ in range(m)]
    used = set()
    a = 1
    b = n
    good = True
    for i in range(m):
        if b - a == n - (b - a):
            a += 1
            b -= 1
        ans[i] = (a, b)
        if (b - a) in used:
            good = False
            break
        else:
            used.add(b - a)
        if (n - (b - a)) in used:
            good = False
            break
        else:
            used.add(n - (b - a))
        a += 1
        b -= 1

    if not good:
        ans = [None for _ in range(m)]
        used = set()
        a = 1
        b = n-1
        good = True
        for i in range(m):
            if b - a == n - (b - a):
                a += 1
                b -= 1
            ans[i] = (a, b)
            if (b - a) in used:
                good = False
                break
            else:
                used.add(b - a)
            if (n - (b - a)) in used:
                good = False
                break
            else:
                used.add(n - (b - a))
            a += 1
            b -= 1

    if not good:
        ans = [None for _ in range(m)]
        used = set()
        a = 1
        b = n
        good = True
        dec = False
        for i in range(m):
            if b - a == n - (b - a):
                b -= 1
            if not dec and ((b - a) in used or (n - (b - a)) in used):
                b -= 1
            ans[i] = (a, b)
            if (b - a) in used:
                good = False
                break
            else:
                used.add(b - a)
            if (n - (b - a)) in used:
                good = False
                break
            else:
                used.add(n - (b - a))
            a += 1
            b -= 1


    for i in range(m):
        print(ans[i][0], ans[i][1])

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

def main():
    h, n = map(int, input().split())
    ab = []
    for i in range(n):
        ab.append(tuple(map(int, input().split())))

    dp = np.zeros(h+1, dtype='i8')
    for i in range(h):
        dp[i] = 10**18
    for i in range(h, 0, -1):
        for j in range(n):
            dp[max(0, i-ab[j][0])] = min(dp[max(0, i - ab[j][0])], dp[i] + ab[j][1])

    print(dp[0])


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    h, n = map(int, input().split())
    ab = []
    for i in range(n):
        ab.append(tuple(map(int, input().split())))

    dp = []
    for i in range(h+1):
        dp.append(10**18)
    dp[h] = 0
    for i in range(h, 0, -1):
        for j in range(n):
            dp[max(0, i-ab[j][0])] = min(dp[max(0, i - ab[j][0])], dp[i] + ab[j][1])

    print(dp[0])


if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):

def main():
    h, n = map(int, input().split())
    ab = []
    for i in range(n):
        ab.append(tuple(map(int, input().split())))

    dp = []
    for i in range(h+1):
        dp.append(10**18)
    dp[h] = 0
    for i in range(h, 0, -1):
        for j in range(n):
            dp[max(0, i-ab[j][0])] = min(dp[max(0, i - ab[j][0])], dp[i] + ab[j][1])

    print(dp[0])


if __name__ == '__main__':
    main()


Fixed submission:
def main():
    h, n = map(int, input().split())
    ab = []
    for i in range(n):
        ab.append(tuple(map(int, input().split())))

    dp = []
    for i in range(h+1):
        dp.append(10**18)
    dp[h] = 0
    for i in range(h, 0, -1):
        for j in range(n):
            dp[max(0, i-ab[j][0])] = min(dp[max(0, i - ab[j][0])], dp[i] + ab[j][1])

    print(dp[0])


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):

def main():
    buf = input()
    buflist = buf.split()
    N = int(buflist[0])
    K = int(buflist[1])
    buf = input()
    buflist = buf.split()
    V = list(map(int, buflist))
    max_value = 0
    for i in range(K+1):
        push_limit = K - i
        for j in range(i+1):
            jewel = []
            for k in range(-i+j, j):
                jewel.append(V[k])
            jewel = list(sorted(jewel))
            value = sum(jewel)
            for k in range(push_limit):
                if k >= len(jewel):
                    break
                if jewel[k] < 0:
                    value += -jewel[k]
                else:
                    break
            if value > max_value:
                max_value = value
    print(max_value)


if __name__ == '__main__':
    main()


Fixed submission:

def main():
    buf = input()
    buflist = buf.split()
    N = int(buflist[0])
    K = int(buflist[1])
    buf = input()
    buflist = buf.split()
    V = list(map(int, buflist))
    max_value = 0
    for i in range(min(N+1, K+1)):
        push_limit = K - i
        for j in range(i+1):
            jewel = []
            for k in range(-i+j, j):
                jewel.append(V[k])
            jewel = list(sorted(jewel))
            value = sum(jewel)
            for k in range(push_limit):
                if k >= len(jewel):
                    break
                if jewel[k] < 0:
                    value += -jewel[k]
                else:
                    break
            if value > max_value:
                max_value = value
    print(max_value)


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

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

const ll mod = 1000000007;

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

  vector<int> n(4);
  for (auto &x: n) cin >> x;

  sort(n.begin(), n.end());
  if (n[0] == 1 && n[1] == 4 && n[2] == 7 && n[3] == 9) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }

  return 0;
}


Fixed submission:

def main():
    buf = input()
    buflist = buf.split()
    N = list(map(int, buflist))
    if 1 in N and 9 in N and 7 in N and 4 in N:
        print("YES")
    else:
        print("NO")

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

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

const ll mod = 1000000007;

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

  string s;
  cin >> s;

  int n = s.length();

  string keyence = "keyence";
  int p = 0;
  for (int i = 0; i < 7; i++) {
    if (s[i] == keyence[p]) p++;
    else break;
  }
  for (int i = n-7+p; i < n; i++) {
    if (s[i] == keyence[p]) p++;
    else break;
  }

  if (p == 7) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}


Fixed submission:

def main():
    buf = input()
    S = buf
    if S[0:len("keyence")] == "keyence" or S[len(S)-len("keyence"):len(S)] == "keyence":
        print("YES")
        return
    for i in range(len("keyence")):
        if S[0:i] == "keyence"[0:i] and S[len(S)-(len("keyence")-i):len(S)] == "keyence"[i:len("keyence")]:
            print("YES")
            return
    print("NO")

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):

def main():
    buf = input()
    buflist = buf.split()
    N = int(buflist[0])
    M = int(buflist[1])
    # 最大値は多くともM/N
    limit = int(M / N)
    max = 1
    for i in range(2, limit+1):
        # Mがiで割り切れる、かつ割ったときの値がN以上なら可能なはず
        if M % i == 0 and M / i >= N:
            max = i
    print(max)

if __name__ == '__main__':
    main()


Fixed submission:
import math

def main():
    buf = input()
    buflist = buf.split()
    N = int(buflist[0])
    M = int(buflist[1])
    max = 1
    for i in get_divisor_list(M):
        # Mがiで割り切れる、かつ割ったときの値がN以上なら可能なはず
        if M % i == 0 and M / i >= N:
            max = i
    print(max)

# 約数のリストを取得
def get_divisor_list(num):
    div_list = [1, num]
    limit = int(math.sqrt(num))
    for i in range(2, limit+1):
        if num % i == 0:
            div_list.append(i)
            div_list.append(int(num / i))
    return sorted(div_list)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):

def main():
    buf = input()
    N = int(buf)
    if N % 2 == 0:
        print(N // 2, N, N)
        return
    else:
        divisor = N
        mult = 1
        while True:
            prime_factor = prime_factorization(divisor)
            for h in prime_factor:
                for n in prime_factor:
                    for w in prime_factor:
                        if h + n + w == 4 * mult:
                            print(divisor // h, divisor // n, divisor // w)
                            return
            divisor += N
            mult += 1

def prime_factorization(number):
    n = number
    i = 2
    factor = {1: 1}
    while i * i <= n:
        while n % i == 0:
            if i in factor:
                factor[i] += 1
            else:
                factor.update({i : 1})
            n //= i
        i += 1
    if n > 1 or not factor:
        if n in factor:
            factor[n] += 1
        else:
            factor.update({n : 1})
    return factor

if __name__ == '__main__':
    main()


Fixed submission:
def main():
    buf = input()
    N = int(buf)
    if N % 2 == 0:
        print(N // 2, N, N)
        return
    else:
        divisor = N
        mult = 1
        while True:
            factor = factorization(divisor)
            for h in factor:
                for n in factor:
                    for w in factor:
                        if h + n + w == 4 * mult:
                            print(divisor // h, divisor // n, divisor // w)
                            return
            divisor += N
            mult += 1

def factorization(number):
    i = 2
    factor = {1, number}
    while i * i <= number:
        if number % i == 0:
            factor.add(i)
            factor.add(number // i)
        i += 1
    return factor

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

def main():
    n, m, q = map(int, input().split())
    r = list(map(int, input().split()))
    dist = [[10**18 for _ in range(n)] for _ in range(n)]
    for i in range(m):
        a, b, c = map(int, input().split())
        dist[a-1][b-1] = c
        dist[b-1][a-1] = c

    for k in range(n):
        for i in range(n):
            for j in range(n):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

    ans = 10 ** 18
    for p in itertools.permutations(r):
        total = 0
        for i in range(q-1):
            total += dist[p[i]-1][p[i+1]-1]
        ans = min(ans, total)

    print(ans)

if __name__ == '__main__':
    main()


Fixed submission:
import itertools

def main():
    n, m, q = map(int, input().split())
    r = list(map(int, input().split()))
    dist = [[10**18 for _ in range(n)] for _ in range(n)]
    for i in range(m):
        a, b, c = map(int, input().split())
        dist[a-1][b-1] = c
        dist[b-1][a-1] = c

    for k in range(n):
        for i in range(n):
            for j in range(n):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

    ans = 10 ** 18
    for p in itertools.permutations(r):
        total = 0
        for i in range(q-1):
            total += dist[p[i]-1][p[i+1]-1]
        ans = min(ans, total)

    print(ans)

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

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

const ll mod = 1000000007;

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

  string s;
  cin >> s;

  int n = s.length();
  int ans = 0;
  for (int i = 1; i * 2 < n; i++) {
    bool good = true;
    for (int j = 0; j < i; j++) {
      if (s[j] != s[j+i]) {
        good = false;
        break;
      }
    }
    if (good) ans = i * 2;
  }

  cout << ans << endl;

  return 0;
}


Fixed submission:
def main():
    s = input()

    n = len(s)
    for i in range(n // 2):
        s = s[:-2]
        if s[0:n//2-i-1] == s[n//2-i-1:n-i*2-2]:
            print(n-i*2-2)
            return

if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

result = 0
for A in range(1, N + 1):
    for B in range(1, (N // A) + 1):
        C = N - A * B
        if C == 0:
            continue
        result += 1
print(result)


Fixed submission:
N = int(input())

result = 0
for A in range(1, N + 1):
    for B in range(1, (N // A) + 1):
        C = N - A * B
        if C == 0:
            continue
        result += 1
print(result)
Buggy python submission (verdict: Runtime Error):
l = input()
a = l.split(' ')

tmp = 0
tmp2 = 0

for i in range(n):
    tmp += int(a[i])

for i in range(n):
    tmp2 += int(a[i])*int(a[i])

print((tmp*tmp-tmp2)//2%1000000007)

Fixed submission:
from itertools import accumulate

m = 1000000007

N, *A = map(int, open(0).read().split())

result = 0
b = list(accumulate(A))
for i in range(N):
    result += A[i] * (b[N - 1] - b[i])
    result %= m
print(result)
Buggy python submission (verdict: Runtime Error):
from math import gcd
from functools import reduce

def make_prime_table(n):
    sieve = list(range(n + 1))
    sieve[0] = -1
    sieve[1] = -1
    for i in range(4, n + 1, 2):
        sieve[i] = 2
    for i in range(3, int(n ** 0.5) + 1, 2):
        if sieve[i] != i:
            continue
        for j in range(i * i, n + 1, i * 2):
            if sieve[j] == j:
                sieve[j] = i
    return sieve


def prime_factorize(n):
    result = []
    while n != 1:
        p = prime_table[n]
        e = 0
        while n % p == 0:
            n //= p
            e += 1
        result.append((p, e))
    return result


def f():
    s = set()
    for i in range(N - 1, -1. -1):
        t = prime_factorize(A[i])
        for p, _ in t:
            if p in s:
                return False
            s.add(p)
    return True


N, *A = map(int, open(0).read().split())

prime_table = make_prime_table(10 ** 6)
if f():
    print('pairwise coprime')
elif reduce(gcd, A) == 1:
    print('setwise coprime')
else:
    print('not coprime')


Fixed submission:
from math import gcd
from functools import reduce

def make_prime_table(n):
    sieve = list(range(n + 1))
    sieve[0] = -1
    sieve[1] = -1
    for i in range(4, n + 1, 2):
        sieve[i] = 2
    for i in range(3, int(n ** 0.5) + 1, 2):
        if sieve[i] != i:
            continue
        for j in range(i * i, n + 1, i * 2):
            if sieve[j] == j:
                sieve[j] = i
    return sieve


def prime_factorize(n):
    result = []
    while n != 1:
        p = prime_table[n]
        e = 0
        while n % p == 0:
            n //= p
            e += 1
        result.append((p, e))
    return result


def f():
    s = set()
    for i in range(N - 1, -1, -1):
        t = prime_factorize(A[i])
        for p, _ in t:
            if p in s:
                return False
            s.add(p)
    return True


N, *A = map(int, open(0).read().split())

prime_table = make_prime_table(10 ** 6)
if f():
    print('pairwise coprime')
elif reduce(gcd, A) == 1:
    print('setwise coprime')
else:
    print('not coprime')
Buggy python submission (verdict: Runtime Error):
H, W, M = map(int, input().split())

hc = [0] * H
wc = [0] * W
hwc = [[0] * W for _ in range(H)]
for _ in range(M):
    h, w = map(lambda x: int(x) - 1,input().split())
    hc[h] += 1
    wc[w] += 1
    hwc[h][w] += 1

result = 0
for h in range(H):
    for w in range(W):
        result = max(result, hc[h] + wc[w] - hwc[h][w])
print(result)


Fixed submission:
H, W, M = map(int, input().split())

hc = [0] * H
wc = [0] * W
d = {}
for _ in range(M):
    h, w = map(lambda x: int(x) - 1,input().split())
    hc[h] += 1
    wc[w] += 1
    d.setdefault(h, {})
    d[h][w] = 1

result = 0
hm = max(hc)
wm = max(wc)
hi = [i for i in range(H) if hc[i] == hm]
wi = [i for i in range(W) if wc[i] == wm]

for h in hi:
    for w in wi:
        if h in d and w in d[h]:
            result = max(result, hm + wm - 1)
        else:
            result = max(result, hm + wm)
            break
print(result)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))

result = -float('inf')
for i in range(N):
    p = P[i] - 1
    c = C[p]
    k = K - 1
    t = c
    while p != i and k != 0:
        p = P[p] - 1
        c += C[p]
        t = max(t, c)
        k -= 1
    if k == 0 or c <= 0:
        result = max(result, t)
        continue
    l = K - k
    c = c * (K // l - 1)
    k = K - (K // l - 1) * l
    t = c
    while k != 0:
        p = P[p] - 1
        c += C[p]
        t = max(t, c)
        k -= 1
    result = max(result, t)
print(result)

Fixed submission:
N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))

result = -float('inf')
for i in range(N):
    p = P[i] - 1
    c = C[p]
    k = K - 1
    t = c
    while p != i and k != 0:
        p = P[p] - 1
        c += C[p]
        t = max(t, c)
        k -= 1
    if k == 0 or c <= 0:
        result = max(result, t)
        continue
    l = K - k
    c = c * (K // l - 1)
    k = K - (K // l - 1) * l
    t = c
    while k != 0:
        p = P[p] - 1
        c += C[p]
        t = max(t, c)
        k -= 1
    result = max(result, t)
print(result)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))

result = -float('inf')
for i in range(N):
    p = P[i] - 1
    c = C[p]
    k = K - 1
    t = c
    while p != i and k != 0:
        p = P[p] - 1
        c += C[p]
        t = max(t, c)
        k -= 1
    if k == 0 or c <= 0:
        result = max(result, t)
        continue
    l = K - k
    c = c * (K // l - 1)
    k = K - (K // l - 1) * l
    t = c
    while k != 0:
        p = P[p] - 1
        c += C[p]
        t = max(t, c)
        k -= 1
    result = max(result, t)
print(result)


Fixed submission:
N = int(input())
c = input()

d = list(c)

i = 0
j = N - 1
result = 0
while True:
    while i < N and d[i] != 'W':
        i += 1
    while j > 0 and d[j] != 'R':
        j -= 1
    if i == N or j == -1 or i >= j:
        break
    d[i] = 'R'
    d[j] = 'W'
    result += 1
print(result)

Buggy python submission (verdict: Runtime Error):
N = int(input())
c = input()

d = list(c)

i = 0
j = N - 1
result = 0
while i != j:
    if d[i] == 'W':
        while d[j] != 'R' and i != j:
            j -= 1
        d[i] = 'R'
        d[j] = 'W'
        result += 1
    i += 1
print(result)


Fixed submission:
N = int(input())
c = input()

d = list(c)

i = 0
j = N - 1
result = 0
while True:
    while i < N and d[i] != 'W':
        i += 1
    while j > 0 and d[j] != 'R':
        j -= 1
    if i == N or j == -1 or i >= j:
        break
    d[i] = 'R'
    d[j] = 'W'
    result += 1
print(result)
Buggy python submission (verdict: Runtime Error):
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

b_sum = 0
for i in range(M):
    b_sum += B[i]
    if b_sum > K:
        b_sum -= B[i]
        j = i - 1
        break
result = j + 1

a_sum = 0
for i in range(N):
    a_sum += A[i]
    if a_sum > K:
        break
    while a_sum + b_sum > K:
        b_sum -= B[j]
        j -= 1
    result = max(result, (i + 1) + (j + 1))
print(result)


Fixed submission:
from itertools import accumulate
from bisect import bisect_left

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a = list(accumulate(A))
b = list(accumulate(B))

result = 0
j = bisect_left(b, K)
if j == M:
  result = M
elif b[j] == K:
    result = j + 1
else:
    result = j
for i in range(N):
    t = K - a[i]
    if t < 0:
        break
    j = bisect_left(b, t)
    if j == M:
        result = max(result, i + 1 + M)
    elif b[j] == t:
        result = max(result, i + 1 + j + 1)
    else:
        result = max(result, i + 1 + j)
print(result)

Buggy python submission (verdict: Runtime Error):
from itertools import accumulate
from bisect import bisect_left

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a = [0] + list(accumulate(A))
b = [0] + list(accumulate(B))

result = 0
for i in range(N):
    t = K - a[i]
    if t < 0:
        break
    j = bisect_left(b, t)
    if b[j] == t:
        result = max(result, i + j + 1)
    else:
        result = max(result, i + j)
print(result)


Fixed submission:
from itertools import accumulate
from bisect import bisect_left

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a = list(accumulate(A))
b = list(accumulate(B))

result = 0
j = bisect_left(b, K)
if j == M:
  result = M
elif b[j] == K:
    result = j + 1
else:
    result = j
for i in range(N):
    t = K - a[i]
    if t < 0:
        break
    j = bisect_left(b, t)
    if j == M:
        result = max(result, i + 1 + M)
    elif b[j] == t:
        result = max(result, i + 1 + j + 1)
    else:
        result = max(result, i + 1 + j)
print(result)
Buggy python submission (verdict: Runtime Error):
from sys import stdin
readline = stdin.readline

N = int(readline())
A = list(map(int, readline().split()))
Q = int(readline())

t = [0] * (N + 1)
s = sum(A)
for a in A:
    t[a] += 1

for _ in range(Q):
    B, C = map(int, readline().split())
    s -= B * t[B]
    s += C * t[B]
    t[C] += t[B]
    t[B] = 0
    print(s)


Fixed submission:
from sys import stdin
readline = stdin.readline

N = int(readline())
A = list(map(int, readline().split()))
Q = int(readline())

t = sum(A)
d = {}
for a in A:
    d.setdefault(a, 0)
    d[a] += 1

for _ in range(Q):
    B, C = map(int, readline().split())
    d.setdefault(B, 0)
    d.setdefault(C, 0)
    t -= B * d[B]
    t += C * d[B]
    d[C] += d[B]
    d[B] = 0
    print(t)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

A.sort()
result = 0
for i in range(N):
    for j in range(i):
        count += 1
        if A[i] % A[j] == 0:
            break
    else:
        result += 1
print(result)


Fixed submission:
N = int(input())
A = list(map(int, input().split()))

d = {}
for a in A:
    d.setdefault(a, 0)
    d[a] += 1

A = sorted(set(A))
t = [True] * (10 ** 6 + 1)

for a in A:
    for i in range(a + a, 10 ** 6 + 1, a):
        t[i] = False

for a in d:
    if d[a] > 1:
        t[a] = False

result = 0
for a in A:
    if t[a]:
        result += 1
print(result)