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

Fixed submission:
h,w=map(int,input().split())

ans=[[0]*w for i in range(h)]
s=[[""]*w for i in range(h)]
for i in range(h):
  s[i]=input()

for i in range(h):
  for j in range(w):
    if (s[i][j]=="#"):
      ans[i][j]="#"
      if (i-1>=0 and j-1>=0):
        if (ans[i-1][j-1]!="#"):
            ans[i-1][j-1]+=1
      if (i-1>=0):
         if (ans[i-1][j]!="#"):
            ans[i-1][j]+=1
      if (i-1>=0 and j+1<w):
        if (ans[i-1][j+1]!="#"):
          ans[i-1][j+1]+=1
      if (j-1>=0):
        if (ans[i][j-1]!="#"):
          ans[i][j-1]+=1
      if (j+1<w):
        if (ans[i][j+1]!="#"):
          ans[i][j+1]+=1
      if (i+1<h and j-1>=0):
        if (ans[i+1][j-1]!="#"):
          ans[i+1][j-1]+=1
      if (i+1<h):
        if (ans[i+1][j]!="#"):
          ans[i+1][j]+=1
      if (i+1<h and j+1<w):
        if (ans[i+1][j+1]!="#"):
          ans[i+1][j+1]+=1
    

for i in range(h):
  answer=""
  for j in range(w):
    answer+=str(ans[i][j])
  print(answer)

Buggy submission (verdict: Runtime Error):
h,w=map(int,input().split())

ans=[[0]*w for i in range(h)]
s=[[""]*w for i in range(h)]
for i in range(h):
  s[i]=input()
  for j in range(w):
    if (s[i][j]=="#"):
      ans[i][j]="#"
      if (i-1>=0 and j-1>=0):
        ans[i-1][j-1]+=1
      if (i-1>=0):
        ans[i-1][j]+=1
      if (i-1>=0 and j+1<w):
        ans[i-1][j+1]+=1
      if (j-1>=0):
        ans[i][j-1]+=1
      if (j+1<w):
        ans[i][j+1]+=1
      if (i+1<h and j-1>=0):
        ans[i+1][j-1]+=1
      if (i+1<h):
        ans[i+1][j]+=1
      if (i+1<h and j+1<w):
      	ans[i+1][j+1]+=1
    

for i in range(h):
  answer=""
  for j in range(w):
    answer+=str(ans[i][j])
  print(answer)
Problem p03623 (python)

Fixed submission:
x,a,b=map(int,input().split())
print("A" if (abs(a-x)<abs(b-x)) else "B")

Buggy submission (verdict: Runtime Error):
x,a,b=map(int,input().split())
print("A" if (abs(a-b)<abs(a-c)) else "B")
Problem p03624 (python)

Fixed submission:
s=sorted(set(input()))
test="abcdefghijklmnopqrstuvwxyz"
for i in range(len(test)):
    if (s[i]!=test[i]):
        print(test[i])
        break
    if (s[i]==test[i] and i==len(s)-1 and i!=len(test)-1):
        print(test[i+1])
        break
else:
    print("None")

Buggy submission (verdict: Runtime Error):
s=sorted(set(input()))
test="abcdefghijklmnopqrstuvwxyz"
for i in range(len(test)):
    if (s[i]!=test[i]):
        print(test[i])
        break
    if (s[i]==test[i] and i==len(s)-1 and i!=len(test)):
        print(test[i+1])
        break
else:
    print("None")

Buggy submission (verdict: Runtime Error):
s=sorted(set(input()))
test="abcdefghijklmnopqrstuvwxyz"
for i in range(len(test)):
    if (s[i]!=test[i]):
        print(test[i])
        break
else:
    print("None")
Problem p03759 (python)

Fixed submission:
a,b,c=map(int,input().split())
print("YES" if (b-a==c-b) else "NO")

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
print("YES" if (b-a==c-b) else "NO)
Problem p02999 (python)

Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

X, A = map(int, input().split())
if X < A:
    print(0)
else:
    print(10)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

X, A = map(int, input().split())
if X < A:
    print(0)
else:jprint(10)
Problem p03211 (python)

Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys

S = input()

diff = 9999
for i in range(len(S)-2):
    s = int(S[i:i+3])
    if abs(s - 753) < diff:
        diff = abs(s - 753)
print(diff)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys

S = int(input())

diff = 9999
for i in range(N-2):
    s = int(S[i:i+3])
    if abs(s - 753) < diff:
        diff = s - 753
print(diff)
Problem p03239 (python)

Fixed submission:
N, T = map(int, input().split())
ans = 1e9
for n in range(N):
    c, t = map(int, input().split())
    if t <= T:
        ans = min(ans, c)
if ans == 1e9:
    print('TLE')
else:
    print(ans)

Buggy submission (verdict: Runtime Error):

N, T = map(int, input().split())
ans = 1e9
for n in range(T):
    c, t = map(int, input().split())
    if t <= T:
        ans = min(ans, c)
if ans == 1e9:
    print('TLE')
else:
    print(ans)
Problem p03261 (python)

Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys

N = int(input())
prev = None
ok = True
seen = set()
for n in range(N):
    w = input()
    if prev is None:
        prev = w
    else:
        if prev[-1] != w[0]:
            ok = False
    if w in seen:
        ok = False
    seen.add(w)
    prev = w
if ok:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys


N = int(input())
prev = None
ok = Truen
for n in range(N):
    w = input()
    if prev is None:
        prev = w
    else:
        if prev[-1] != w[0]:
            ok = False
    prev = w
if ok:
    print('Yes')
else:
    print('No')
Problem p03262 (python)

Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
from functools import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys

# python3.4では存在しない!!
# from math import gcd

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)

N, X = map(int, input().split())
Xs = map(int, input().split())
diffs = [abs(X - x) for x in Xs]
ans = reduce(gcd, diffs)
print(ans)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
from functools import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys
from math import gcd

N, X = map(int, input().split())
Xs = map(int, input().split())
diffs = [abs(X - x) for x in Xs]
ans = reduce(gcd, diffs)
print(ans)
Problem p03289 (python)

Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys

S = input()

if S[0] == 'A' and S[2:-1].count('C') == 1:
    S2 = S.replace('A', '').replace('C', '')
    if len(S2) == len(S) - 2 and S2.islower():
        print("AC")
        sys.exit(0)
print("WA")

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

if S[0] == 'A' and (S[:3] + S[-2:]).count('C') == 1:
    a = 0
    c = 0
    ng = 0
    for ch in S:
        if ch == 'A':
            a += 1
        elif ch == 'C':
            c += 1
        elif not ch.islower():
            ng += 1
    if a == 1 and c == 1 and ng == 0:
        print("AC")
        sys.exit(0)
print("WA")

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

if S[0] == 'A' and (S[:3] + S[-2:]).count('C') == 1:
    a = 0
    c = 0
    ng = 0
    for ch in S:
        if ch == 'A':
            a += 1
        elif ch == 'C':
            c += 1
        elif not ch.islower():
            ng += 1
    if a == 1 and c == 1 and ng == 0:
        print("AC")
        sys.exit(0)
print("WA")
Problem p03583 (python)

Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import re
import string

N = int(input())

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def solve(N):
    for a in range(1, 3501):
        N1 = 4*a - N
        N2 = N * a
        if N1 < 0: continue
        for b in range(1, 3501):
            N3 = b * N1 - N2
            N4 = b * N2
            if N4 > 0 and N3 > 0 and N4 % N3 == 0:
                print(a, b, N4//N3)
                return
    
solve(N)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import re
import string

N = int(input())

def get_a(N):
    a = 1
    while True:
        if N < 4 * a:
            return a, 4*a-N, N*a
        a += 1

def get_b(N1, N2):
    b = 1
    while True:
        if N2 < b * N1:
            return b, b*N1-N2, b*N2
        b += 1

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def solve(N):
    a, N1, N2 = get_a(N)
    # print("a,N1,N2 = ", a, N1, N2)
    b, N1, N2 = get_b(N1, N2)
    # print("b,N1,N2 = ", b, N1, N2)
    g = gcd(N1,N2)
    N1 //= g
    N2 //= g
    assert(N1 == 1)
    print(a, b, N2)

# for N in range(2, 100):
#     print("N:::", N)
#     solve(N)

solve(N)
Problem p03651 (python)

Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import re
import string

N, K = map(int, input().split())
As = list(sorted(set(map(int, input().split()))))

def gcd(a, b):
    while b:
    	a, b = b, a % b
    return a

# corner
if len(As) == 1:
    if K == As[0]:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")
else:        
    for i in range(len(As)-1):
        diff = As[i+1] - As[i]
        if i == 0:
            unit = diff
        else:
            unit = gcd(unit, diff)
    
    ok = False
    for a in As:
        if (a - K) % unit == 0 and K <= a:
            ok = True
    
    if ok:
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import re
import string

N, K = map(int, input().split())
As = list(sorted(set(map(int, input().split()))))

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

for i in range(len(As)-1):
    diff = As[i+1] - As[i]
    if i == 0:
        unit = diff
    else:
        unit = gcd(unit, diff)

ok = False
for a in As:
    if (a - K) % unit == 0 and K <= a:
        ok = True

if ok:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
Problem p04048 (python)

Fixed submission:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import functools

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
    
# @functools.lru_cache(maxsize = None)
# def func(N, X):
#     g = gcd(N, X)
#     if g == 1:
#         if X > N // 2:
#             return func(N, N - X)
#         if N == 2:
#             return 3
#         if N == 3:
#             return 6
#         return X * 3 + func(N-X, X)
#     else:
#         return g * func(N//g, X//g)


def func_fast(N, X):
    g = gcd(N, X)
    if g == 1:
        return 3 * N - 3
    else:
        return g * func_fast(N // g, X // g)

N,X = map(int,input().split())
print(func_fast(N,X))

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import functools

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
    
@functools.lru_cache(maxsize = None)
def func(N, X):
    g = gcd(N, X)
    if g == 1:
        if X > N // 2:
            return func(N, N - X)
        if N == 2:
            return 3
        if N == 3:
            return 6
        return X * 3 + func(N-X, X)
    else:
        return g * func(N//g, X//g)

N,X = map(int,input().split())
print(func(N,X))

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import functools

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
    
@functools.lru_cache(maxsize = None)
def func(N, X):
    g = gcd(N, X)
    if g == 1:
        if X > N // 2:
            return func(N, N - X)
        if N == 2:
            return 3
        if N == 3:
            return 6
        return X * 3 + func(N-X, X)
    else:
        return g * func(N//g, X//g)

N,X = map(int,input().split())
print(func(N,X))
Problem p02606 (python)

Fixed submission:
from __future__ import print_function
import sys


if sys.subversion[0] == "PyPy":
    import io, atexit

    sys.stdout = io.BytesIO()
    atexit.register(lambda: sys.__stdout__.write(sys.stdout.getvalue()))

    sys.stdin = io.BytesIO(sys.stdin.read())
    input = lambda: sys.stdin.readline().rstrip()
RS = raw_input
RA = lambda x=int: map(x, RS().split())
RN = lambda x=int: x(RS())


def solve():
    ans = 0
    for i in range(l, r+1):
        if i % d == 0:
            ans += 1
    print(ans)
    return





l, r, d = RA()
solve()

Buggy submission (verdict: Runtime Error):
from __future__ import print_function
import sys


if sys.subversion[0] == "PyPy":
    import io, atexit

    sys.stdout = io.BytesIO()
    atexit.register(lambda: sys.__stdout__.write(sys.stdout.getvalue()))

    sys.stdin = io.BytesIO(sys.stdin.read())
    input = lambda: sys.stdin.readline().rstrip()
RS = raw_input
RA = lambda x=int: map(x, RS().split())
RN = lambda x=int: x(RS())


def solve():
    ans = 0
    for i in range(1, n+1):
        if i % 2 == 1 and a[i-1] % 2 == 1:
            ans += 1
    print(ans)
    return




n = RN()
a = RA()
solve()

Buggy submission (verdict: Runtime Error):
from __future__ import print_function
import sys


if sys.subversion[0] == "PyPy":
    import io, atexit

    sys.stdout = io.BytesIO()
    atexit.register(lambda: sys.__stdout__.write(sys.stdout.getvalue()))

    sys.stdin = io.BytesIO(sys.stdin.read())
    input = lambda: sys.stdin.readline().rstrip()
RS = raw_input
RA = lambda x=int: map(x, RS().split())
RN = lambda x=int: x(RS())


def solve():
    ans = 0
    for i in range(l, r+1):
        if i % d == 0:
            ans += 1
    print(ans)
    return





l, r, d = RA()
solve()
Problem p02664 (python)

Fixed submission:
print(input().replace("?", "D"))

Buggy submission (verdict: Runtime Error):
import sys


input = lambda: sys.stdin.readline()[:-1]
RI = lambda x=int: x(input())
RA = lambda x=int: map(x, input().split())
RSS = lambda: input().split()


def solve():
    ans = []
    for i in s:
        if i == "P":
            ans.append("P")
        else:
            ans.append("D")
    print("".join(ans))
    return



s = RS()
solve()

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline.strip()
RS = input
RI = lambda x=int: x(RS())
RA = lambda x=int: map(x, RS().split())
RSS = lambda: RS().split()


def solve():
    ans = []
    for i in s:
        if i == "P":
            ans.append("P")
        else:
            ans.append("D")
    print("".join(ans))
    return



s = RS()
solve()
Problem p02678 (python)

Fixed submission:
import math

def solve():
    ans = [-1 for i in range(n+1)]
    remaining = set(range(1, n+1))
    remaining.remove(1)
    last_visited = [1]
    last_visited2 = []
    while remaining:
        c = len(remaining)
        for r in last_visited:
            for ad in adj[r]:
                if ad in remaining:
                    last_visited2.append(ad)
                    remaining.remove(ad)
                    ans[ad] = r
        last_visited = last_visited2
        last_visited2 = []
        if len(remaining) == c:
            print("No")
            return
    print("Yes")
    for i in ans[2:]:
        print(i)
    return

n, m = [int(ii) for ii in input().split()]
adj = [[] for _ in range(n + 1)]
for i in range(m):
    a, b = [int(ii) for ii in input().split()]
    adj[a].append(b)
    adj[b].append(a)
solve()

Buggy submission (verdict: Runtime Error):
import math

def solve():
    ans = [-1 for i in range(n+1)]
    remaining = set(range(1, n+1))
    remaining.remove(1)
    last_visited = [1]
    last_visited2 = []
    c = 0
    while remaining:
        print(remaining)
        for r in last_visited:
            for ad in adj[r]:
                if ad in remaining:
                    last_visited2.append(ad)
                    remaining.remove(ad)
                    ans[ad] = r
        last_visited = last_visited2
        last_visited2 = []
        c += 1
    if -1 in ans[2:]:
        print("No")
        return
    print("Yes")
    for i in ans[2:]:
        print(i)
    return

n, m = [int(ii) for ii in input().split()]
adj = [[] for _ in range(n + 1)]
for i in range(m):
    a, b = [int(ii) for ii in input().split()]
    adj[a].append(b)
    adj[b].append(a)
solve()
Problem p02684 (python)

Fixed submission:


def solve():
    hm = {}
    steps = k
    curr = 0
    loopsize = 0
    pre = 0
    while not str(curr) in hm and steps > 0:
        hm[str(curr)] = pre
        pre+=1
        curr = a[curr] - 1
        steps -= 1
        loopsize += 1
    if str(curr) in hm:
        loopsize -= hm[str(curr)]
    steps %= loopsize
    while steps > 0:
        curr = a[curr] - 1
        steps -= 1
    print(curr + 1)
    return



n, k = [int(i) for i in input().split(" ")]
a = [int(i) for i in input().split(" ")]
solve()

Buggy submission (verdict: Runtime Error):


def solve():
    hm = {}
    steps = k
    curr = 0
    loopsize = 0
    pre = 0
    while not str(curr) in hm and steps > 0:
        hm[str(curr)] = pre
        pre+=1
        curr = a[curr] - 1
        steps -= 1
        loopsize += 1
    loopsize -= hm[str(curr)]
    steps %= loopsize
    while steps > 0:
        curr = a[curr] - 1
        steps -= 1
    print(curr + 1)
    return



n, k = [int(i) for i in input().split(" ")]
a = [int(i) for i in input().split(" ")]
solve()
Problem p02761 (python)

Fixed submission:



def solve():
    ans = ["0"]*n
    if not n==1:
        ans[0] = "1"
    for i in range(len(s)):
        a = ((s[i]== 1) and c[i]==0) and (not n == 1)
        b = False
        for j in range(len(s)):
            b = b or (s[i] == s[j] and (not i==j) and not c[i]==c[j])
        if a or b:
            print(-1)
            exit()
        ans[s[i]-1] = str(c[i])
    ans = "".join(ans)
    print(ans)



    return




n, m = [int(s) for s in input().split(" ")]
s = []
c = []
for i in range(m):
    si, ci = [int(s) for s in input().split(" ")]
    s.append(si)
    c.append(ci)
solve()

Buggy submission (verdict: Runtime Error):



def solve():
    ans = ["0"]*len(s)
    ans[0] = "1"
    for i in range(len(s)):
        a = ((s[i]== 1) and c[i]==0)
        b = False
        for j in range(len(s)):
            b = b or (s[i] == s[j] and (not i==j) and not c[i]==c[j])
        if a or b:
            print(-1)
            exit()
        ans[s[i]-1] = str(c[i])
    ans = "".join(ans)
    print(ans)



    return




n, m = [int(s) for s in input().split(" ")]
s = []
c = []
for i in range(m):
    si, ci = [int(s) for s in input().split(" ")]
    s.append(si)
    c.append(ci)
solve()
Problem p02683 (python)

Fixed submission:
INF = pow(10, 9)


def main():
    n, m, x = map(int, input().split())
    i = 0
    c = []
    a = []

    for i in range(n):
        tmp = list(map(int, input().split()))
        c.append(tmp[0])
        a.append(tmp[1:])

    ans = INF
    for i in range(2**n):
        tmp = [0 for i in range(m)]
        cost = 0
        flag = True
        for j in range(n):
            if ((i >> j) & 1) == 1:
                tmp = [x+y for x, y in zip(tmp, a[j])]
                cost += c[j]
        # print(tmp)
        for j in range(m):
            if tmp[j] < x:
                flag = False
                break
        # print(cost)
        if flag == True:
            if cost < ans:
                ans = cost
    print(ans) if ans != INF else print(-1)

    return


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import numpy as np
INF = pow(10, 9)


def main():
    n, m, x = map(int, input().split())
    i = 0
    c = []
    a = []

    for i in range(n):
        tmp = list(map(int, input().split()))
        c.append(tmp[0])
        a.append(tmp[1:])

    ans = INF
    for i in range(2**n):
        tmp = np.array([0 for i in range(m)])
        cost = 0
        flag = True
        for j in range(n):
            if ((i >> j) & 1) == 1:
                tmp += a[j]
                cost += c[j]
        # print(tmp)
        for j in range(m):
            if tmp[j] < x:
                flag = False
                break
        # print(cost)
        if flag == True:
            if cost < ans:
                ans = cost
    print(ans) if ans != INF else print(-1)

    return


if __name__ == "__main__":
    main()
Problem p02691 (python)

Fixed submission:
J = [0 for i in range(int(2e5+3))]


def main():
    n = int(input())
    a = list(map(lambda x: int(x)-1, input().split()))

    for i in range(n):
        tmp = i - a[i]
        if 0 < tmp:
            J[tmp] += 1

    cnt = 0
    for i in range(n):
        tmp = a[i]+i+2
        if tmp < len(J)-1:
            cnt += J[tmp]

    print(cnt)
    return


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
J = [0 for i in range(int(2e5+3))]


def main():
    n = int(input())
    a = list(map(lambda x: int(x)-1, input().split()))

    for i in range(n):
        tmp = i - a[i]
        if 0 < tmp:
            J[tmp] += 1

    cnt = 0
    for i in range(n):
        tmp = a[i]+i+2
        cnt += J[tmp]

    print(cnt)
    return


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n = int(input())
    a = list(map(lambda x: int(x)-1, input().split()))
    J = [0 for i in range(int(2e5+3))]

    for i in range(n):
        tmp = i - a[i]
        if 0 <= tmp:
            J[tmp] += 1

    cnt = 0
    for i in range(n):
        tmp = a[i]+i+2
        cnt += J[tmp]

    print(cnt)
    return


if __name__ == "__main__":
    main()