Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02697 (python)

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 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()
Problem p03032 (python)

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 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()
Problem p03149 (python)

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 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;
}
Problem p03150 (python)

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 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;
}
Problem p03672 (python)

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 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;
}
Problem p02574 (python)

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 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')
Problem p02630 (python)

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 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)
Problem p02632 (python)

Fixed submission:
# フェルマーの小定理
K = int(input())
S = input()

m = 1000000007


def make_factorial_table(n):
    result = [0] * (n + 1)
    result[0] = 1
    for i in range(1, n + 1):
        result[i] = result[i - 1] * i % m
    return result


def mcomb(n, k):
    if n == 0 and k == 0:
        return 1
    if n < k or k < 0:
        return 0
    return fac[n] * pow(fac[n - k], m - 2, m) * pow(fac[k], m - 2, m) % m


fac = make_factorial_table(len(S) + K)

result = 0
for i in range(K + 1):
    result += pow(26, i, m) * mcomb(len(S) - 1 + K - i, len(S) - 1) * pow(25, K - i, m)
    result %= m
print(result)

Buggy submission (verdict: Runtime Error):
K = int(input())
S = input()

m = 1000000007

result = 0
t = pow(26, K, m)
u = pow(26, -1, m) * 25 % m
l = len(S)
for i in range(K + 1):
    # result += pow(26, K - i, m) * mcomb(len(S) - 1 + i, i) * pow(25, i, m)
    result = (result + t) % m
    t = (t * u) % m * (l + i) % m * pow(i + 1, -1, m) % m
print(result)

Buggy submission (verdict: Runtime Error):
# フェルマーの小定理
K = int(input())
S = input()

m = 1000000007

l = len(S)
result = 0

a = pow(26, K, m)
inv26 = pow(26, -1K, m)
b = 1
c = 1
d = 1
for i in range(K + 1):
    # result += pow(26, K - i, m) * mcomb(len(S) - 1 + i, i) * pow(25, i, m)
    result += a * (b * pow(c, -1, m)) * d
    result %= m
    a *= inv26
    a %= m
    b *= l + i
    b %= m
    c *= i + 1
    c %= m
    d *= 25
    d %= m
print(result)
Problem p02642 (python)

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)

Buggy 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)
Problem p02683 (python)

Fixed submission:
N, M, X = map(int, input().split())

C = []
A = []
for i in range(N):
    t = list(map(int, input().split()))
    C.append(t[0])
    A.append(t[1:])

result = -1
for i in range(1 << N):
    t = [0] * M
    c = 0
    for j in range(N):
        if (i >> j) & 1 == 0:
            continue
        c += C[j]
        a = A[j]
        for k in range(M):
            t[k] += a[k]
    if all(x >= X for x in t):
        if result == -1:
            result = c
        else:
            result = min(result, c)
print(result)

Buggy submission (verdict: Runtime Error):
from itertools import product

N, M, X = map(int, input().split())

C = []
A = []
for i in range(N):
    t = list(map(int, input().split()))
    C.append(t[0])
    A.append(t[1:])

result = float('inf')
for p in product([True, False], N):
    t = [0] * M
    c = 0
    for j in range(N):
        if not p[j]:
            continue
        c += C[j]
        for k in range(M):
            t[k] += A[j][k]
    if all(x >= X for x in t):
        result = min(result, c)
print(result)
Problem p02686 (python)

Fixed submission:
def scan(s):
    m = 0
    a = 0
    for c in s:
        if c == '(':
            a += 1
        elif c == ')':
            a -= 1
        m = min(m, a)
    return m, a


def key(v):
    m, a = v
    if a >= 0:
        return 1, m, a
    else:
        return -1, a - m, a

N = int(input())
S = [input() for _ in range(N)]

c = 0
for m, a in sorted([scan(s) for s in S], reverse=True, key=key):
    if c + m < 0:
        c += m
        break
    c += a

if c == 0:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
from functools import reduce
from itertools import permutations

def f(s):
    while True:
        t = s.replace('()', '')
        if t == s:
            return s
        s = t

N = int(input())
S = [input() for _ in range(N)]

l = 0
r = 0
for s in S:
    t = s.count('(')
    l += t
    r += len(s) - t
if l != r:
    print('No')
    exit()

S = [s for s in map(f, S) if s != ""]

if len(S) == 0:
    print('Yes')
    exit()

lS = [s for s in S if s[0] == "("]
rS = [s for s in S if s[0] == ")"]

ld = {}
for s in lS:
    ld.setdefault(s, 0)
    ld[s] += 1

rd = {}
for s in rS:
    rd.setdefault(s, 0)
    rd[s] += 1

for k1 in ld:
    for k2 in rd.keys():
        if f(k1 + k2) != '':
            continue
        t = max(ld[k1], rd[k2])
        ld[k1] -= t
        rd[k2] -= t

if len(ld) == 0 and len(rd) == 0:
    print('Yes')
    exit()

SS = []
for k in ld:
    for i in range(ld[k]):
        SS.append(k)
for k in rd:
    for i in range(rd[k]):
        SS.append(k)

for ss in permutations(SS, len(SS)):
    t = reduce(lambda x, y: x + y, ss)
    if f(t) == '':
        print('Yes')
        exit()
print('No')
Problem p02697 (python)

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

for i in range(1, M + 1):
    if i % 2 == 1:
        j = (i - 1) // 2
        print(1 + j, M + 1 - j)
    else:
        j = (i - 2) // 2
        print(M + 2 + j, 2 * M + 1 - j)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())

sieve = [0] * (100000 + 1)
sieve[0] = -1
sieve[1] = -1
for i in range(2, 100000 + 1):
    if sieve[i] != 0:
        continue
    sieve[i] = i
    for j in range(i * i, 100000 + 1, i):
        if sieve[j] == 0:
            sieve[j] = i

p = []
for i in range(N - 1, -1, -1):
    if sieve[i] == i:
        p.append(i)
p.append(1)

t = set()
pp = 0
for i in range(M):
    x = i + 1
    y = x + p[pp]
    while y in t:
        pp += 1
        y = x + p[pp]
    t.add(x)
    t.add(y)
    print(x, y)
    pp += 1
Problem p02715 (python)

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

MOD = 10 ** 9 + 7

cache = {}
def f(k, n):
    if k == 1:
        return 1
    if k in cache:
        return cache[k]
    result = pow(k, n, MOD)
    for i in range(2, k + 1):
        result -= f(k // i, n)
        result %= MOD
    cache[k] = result
    return result

result = 0
for i in range(2, K + 1):
    result += f(K // i, N) * i
result += f(K, N)
result %= MOD
print(result)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())

MOD = 10 ** 9 + 7

cache = {}
def f(k, n):
    if k == 1:
        return 1
    if k in cache:
        return cache[k]
    result = pow(k, n, MOD)
    for i in range(2, k + 1):
        result -= f(k // i, n)
        result %= MOD
    cache[k] = result
    return result


result = 0
for i in range(K + 1):
    result += f(K // i, N) * i
    result %= MOD
print(result)
Problem p02761 (python)

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

t = [-1] * N
for _ in range(M):
    s, c = map(int, input().split())
    s -= 1
    if t[s] != -1 and t[s] != c:
        print(-1)
        exit()
    t[s] = c

if N == 1 and t[0] == 0:
    print(0)
    exit()

if N == 1 and t[0] == -1:
    print(0)
    exit()

if t[0] == 0:
    print(-1)
    exit()

if t[0] == -1:
    t[0] = 1

for i in range(1, N):
    if t[i] == -1:
        t[i] = 0

print(''.join(map(str, t)))

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
sc = [tuple(map(int, input().split())) for _ in range(M)]

for i in range(1000):
    t = str(i)
    if len(t) != N:
        continue
    ok = True
    for s, c in sc:
        if t[int(s)] != int(c):
            ok = False
            break
    if ok:
        print(i)
        exit()
print(-1)
Problem p02775 (python)

Fixed submission:
N = input()

N = '0' + N
result = 0
carry = 0
for i in range(len(N) - 1, 0, -1):
    c = int(N[i]) + carry
    n = int(N[i - 1])
    if c < 5 or (c == 5 and n < 5):
        result += c
        carry = 0
    else:
        result += 10 - c
        carry = 1
result += carry
print(result)

Buggy submission (verdict: Runtime Error):
N = input()

for i in range(len(N) - 1, -1, -1):
    t = int(N[i])
    a, b = min(a + t, b + (t + 1)), min(a + (10 - t), b + (10 - (t + 1)))
print(min(a, b + 1))

Buggy submission (verdict: Runtime Error):
N = input()

a = 0  # not carried
b = 0  # carried
t = int(N[-1])
a, b = a + t, a + (10 - t)

for i in range(1, len(N))
    t = int(N[-i])
    a, b = min(a + t, b + (t + 1)), min(a + (10 - t), b + (10 - (t + 1)))
print(min(a, b + 1))

Buggy submission (verdict: Runtime Error):
N = input()

a = 0  # not carried
b = 0  # carried
t = int(N[:-1]) % 10
a, b = a + t, a + (10 - t)
N = N[:-1]
while N != 0:
    t = int(N[:-1]) % 10
    a, b = min(a + t, b + (t + 1)), min(a + (10 - t), b + (10 - (t + 1)))
    N = N[:-1]
print(min(a, b + 1))

Buggy submission (verdict: Runtime Error):
def main():
    from builtin import min
    N = int(input())

    a = 0  # not carried
    b = 0  # carried
    t = N % 10
    a, b = a + t, a + (10 - t)
    N //= 10
    while N != 0:
        t = N % 10
        a, b = min(a + t, b + (t + 1)), min(a + (10 - t), b + (10 - (t + 1)))
        N //= 10
    print(min(a, b + 1))


main()

Buggy submission (verdict: Runtime Error):
def main():
    from builtin import min
    N = int(input())

    a = 0  # not carried
    b = 0  # carried
    while N != 0:
        t = N % 10
        a, b = min(a + t, b + (t + 1)), min(a + (10 - t), b + (10 - (t + 1)))
        N //= 10
    print(min(a, b + 1))


main()

Buggy submission (verdict: Runtime Error):
def main():
    from builtin import min
    N = int(input())

    a = 0 // carried
    b = 0 // not carried
    while N != 0:
        t = N % 10
        a = min(a + t + 1, b + t)
        b = min(a + 9 - t, a + 10 - t)
        n //= 10
    print(min(a + 1, b))


main()
Problem p02787 (python)

Fixed submission:
def main():
    from sys import stdin
    readline = stdin.readline
    H, N = map(int, readline().split())
    AB = [list(map(int, readline().split())) for _ in range(N)]

    dp = [100000000] * (H + 10 ** 4 + 1)
    dp[0] = 0
    for i in range(H):
        if dp[i] == 100000000:
            continue
        for j in range(N):
            a, b = AB[j]
            if dp[i] + b < dp[i + a]:
                dp[i + a] = dp[i] + b
    print(min(dp[H:]))


main()

Buggy submission (verdict: Runtime Error):
H, N = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]

dp = [1000000] * (10 ** 5)
dp[0] = 0
for i in range(H):
    if dp[i] == 1000000:
        continue
    for j in range(N):
        a, b = AB[k]
        if dp[i] + b < dp[i + a]:
            dp[i + a] = dp[i] + b
print(min(dp[H:]))
Problem p02804 (python)

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

fac = [0] * (N + 1)
fac[0] = 1
for i in range(N):
    fac[i + 1] = fac[i] * (i + 1) % 1000000007


def mcomb(n, k):
    if n == 0 and k == 0:
        return 1
    if n < k or k < 0:
        return 0
    return fac[n] * pow(fac[n - k], 1000000005, 1000000007) * pow(fac[k], 1000000005, 1000000007) % 1000000007


A.sort(reverse = True)
result = 0
for i in range(N - K + 1):
    result += A[i] * mcomb(N - (i + 1), K - 1)
    result %= 1000000007

A.sort()
t = 0
for i in range(N - K + 1):
    t += A[i] * mcomb(N - (i + 1), K - 1)
    t %= 1000000007

result -= t
result += 1000000007
result %= 1000000007
print(result)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))

fac = [0] * (N + 1)
fac[0] = 1
for i in range(N):
    fac[i + 1] = fac[i] * (i + 1) % p


def mcomb(n, k):
    if n == 0 and k == 0:
        return 1
    if n < k or k < 0:
        return 0
    return fac[n] * pow(fac[n - k], p - 2, p) * pow(fac[k], p - 2, p) % p


A.sort(reverse=True)
result = 0
for i in range(N - K + 1):
    result += A[i] * mcomb(N - (i + 1), K - 1)
    result %= p

A.sort()
for i in range(N - K + 1):
    result -= A[i] * mcomb(N - (i + 1), K - 1)
    result %= p

# result += p
# result %= p
print(result)