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

Fixed submission:
# ノートに考察メモあり。
from collections import Counter, deque  # https://note.nkmk.me/python-scipy-connected-components/
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()


def resolve():
    def main():
        gg = Counter([])
        H, W = map(int, input().split())
        grid = [[_ for _ in input()] for _ in range(H)]
        for g in grid:
            gg.update(Counter(g))

        if H % 2 == 0 and W % 2 == 0:
            for i in gg.values():
                if i % 4 != 0:
                    return 'No'
            return 'Yes'

        elif H % 2 == 0 and W % 2 == 1:
            cnt = 0
            for i in gg.values():
                if i % 4 == 2:
                    cnt += 2
                elif i % 4 == 1 or i % 4 == 3:
                    return 'No'

            if cnt <= H:
                return 'Yes'
            else:
                return 'No'

        elif H % 2 == 1 and W % 2 == 0:
            cnt = 0
            for i in gg.values():
                if i % 4 == 2:
                    cnt += 2
                elif i % 4 == 1 or i % 4 == 3:
                    return 'No'

            if cnt <= W:
                return 'Yes'
            else:
                return 'No'

        else:
            cnt1 = 0
            cnt2 = 0
            for i in gg.values():
                if i % 4 == 1:
                    cnt1 += 1
                elif i % 4 == 2:
                    cnt2 += 2
                elif i % 4 == 3:
                    cnt2 += 2
                    cnt1 += 1
            if cnt1 == 1 and cnt2 <= (H + W - 2):
                return 'Yes'
            else:
                return 'No'

    print(main())


resolve()

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    def main():

        H,W=map(int,input().split())
        grid=[[_ for _ in input()] for _ in range(H)]
        for g in grid:
            gg=Counter(g)
            cnt=0
            for i in gg.values():
                if i%2==1:
                    cnt+=1
            if not ((cnt==1 and W%2==1) or (cnt==0 and W%2==0)):
                return 'No'

        grid=zip(*grid)
        W=H
        for g in grid:
            gg=Counter(g)
            cnt=0
            for i in gg.values():
                if i%2==1:
                    cnt+=1
            if not ((cnt==1 and W%2==1) or (cnt==0 and W%2==0)):
                return 'No'
        return 'Yes'
    print(main())







resolve()
Problem p03627 (python)

Fixed submission:
# import bisect
from collections import Counter, deque
# from copy import copy, deepcopy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
# from operator import xor
import sys

sys.setrecursionlimit(10 ** 5 + 10)


# input = sys.stdin.readline

def resolve():
    N = int(input())
    A = list(map(int, input().split()))

    AA = Counter(A).most_common()

    ls = []
    for i in range(len(AA)):
        if AA[i][1] >= 2:
            ls.append(AA[i])
        else:
            break

    ls=sorted(ls, key=lambda x: x[0])

    try:
        ans = ls[-1][0] * ls[-2][0]
        for i in reversed(range(len(ls))):
            if ls[i][1] >= 4:
                ans = max(ans, ls[i][0] ** 2)
        print(ans)
    except:
        print(0)


resolve()

Buggy submission (verdict: Runtime Error):
def resolve():

    N=int(input())
    A=sorted(list(map(int,input().split())),reverse=True)
    temp=-1
    maxans=0
    AA=Counter(A)
    for (i,j) in AA.items():
        if j>=4:
            maxans=max(i**2,maxans)
        if j>=2:
            if temp>=0:
                maxans=max(maxans,temp*i)
            temp=max(i,temp)
    print(maxans)




resolve()

Buggy submission (verdict: Runtime Error):

def resolve():

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

    AA=Counter(A).most_common()

    ls=[]
    for i in range(len(AA)):
        if AA[i][1]>=2:
            ls.append(AA[i][0])

    ls.sort()
    try:
        print(ls[-1]*ls[-2])
    except:
        print(0)



resolve()

Buggy submission (verdict: Runtime Error):

def resolve():

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

    AA=Counter(A).most_common()

    ls=[]
    for i in range(len(AA)):
        if AA[i][1]>=2:
            ls.append(AA[i][0])

    ls.sort()
    try:
        print(ls[-1]*ls[-2])
    except:
        print(0)



resolve()
Problem p03640 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():


    H, W = map(int, input().split())
    N=int(input())
    A = list(map(int,input().split()))

        


    route = []
    for h in range(H):
        if h % 2 == 0:
            route.extend([(h, w) for w in range(W)])
        else:
            route.extend([(h, w) for w in reversed(range(W))])
    
    ans=[[0]*W for _ in range(H)]
    val=1
    i=0
    cnt=0
    for i in range(N):
        for j in range(A[i]):
            ans[route[cnt][0]][route[cnt][1]]=i+1
            cnt+=1
    for i in ans:
        print(*i)



resolve()

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    n=int(input())
    A=list(map(int,input().split()))
    val=max(A)
    val2=0
    minabs=10**10
    for i in range(n):
        if abs(A[i]-(val//2))<minabs:
            minabs=abs(A[i]-(val//2))
            val2=A[i]
    print(val,val2)    



    
resolve()
Problem p03643 (python)

Fixed submission:
N=input()
print('ABC{}'.format(N))

Buggy submission (verdict: Runtime Error):
N=str(inputN=input()
print('ABC{}'.format(N))
Problem p03651 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():

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

    ma=max(A)

    from functools import reduce
    from fractions import gcd

    g=reduce(gcd,A)
    if K%g==0 and K<=ma:
        print('POSSIBLE')
    else: print('IMPOSSIBLE')

resolve()

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():

    n,k=map(int,input().split())
    A=list(map(int,input().split()))

    from functools import reduce
    from math import gcd
    G=reduce(gcd,A)

    if k%G==0 and k<=max(A):
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')

resolve()

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():

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

    ma=max(A)

    from functools import reduce
    from math import gcd

    g=reduce(gcd,A)
    if K%g==0 and K<=ma:
        print('POSSIBLE')
    else: print('IMPOSSIBLE')

resolve()
Problem p03672 (python)

Fixed submission:
# import bisect
# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate,permutations, combinations,combinations_with_replacement,product

def resolve():
    S=list(input())
    while True:
        S.pop(-1)
        l=len(S)
        if S[:l//2]==S[l//2:]:
            print(l)
            break



resolve()

Buggy submission (verdict: Runtime Error):
python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    s= str(input())
    ls=len(s)
    cur=ls//2
    i=0
    while True:
        i+=1
        cur-=1
        if s[:cur]==s[cur:ls-i*2]:
            print(ls-i*2)
            break


    
resolve()
Problem p03695 (python)

Fixed submission:
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    ls = [False] * 8
    cnt = 0
    for i in A:

        if i < 3200:
            ls[i // 400] = True
        else:
            cnt += 1

    if ls.count(True) == 0:
        if cnt == 0:
            minval = 0
        else:
            minval = 1
    else:
        minval = ls.count(True)

    if ls.count(False) <= cnt:
        maxval = 8+cnt-ls.count(False)
    else:
        maxval = 8 - (ls.count(False) - cnt)

    print(minval, maxval)


resolve()

Buggy submission (verdict: Runtime Error):
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    ls = [False] * 8
    cnt = 0
    for i in A:

        if i<3200:
            ls[i//400]=True
        else:
            cnt += 1

    if ls.count(True)==0:
        if cnt==0:
            minval=0
        else:
            minval=1
    if ls.count(False) <= cnt:
        maxval = 8
    else:
        maxval = 8 - (ls.count(False) - cnt)

    print(minval, maxval)


resolve()
Problem p03699 (python)

Fixed submission:
def resolve():
    N=int(input())
    S=sorted([int(input()) for i in range(N)])
    total=sum(S)
    if total%10!=0:
        print(total)
    else:
        for i in range(N):
            if S[i]%10!=0:
                print(total-S[i])
                break
            elif i==N-1:print(0)


resolve()

Buggy submission (verdict: Runtime Error):
from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
# from operator import xor
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():
    N=int(input())
    S=[int(input()) for i in range(N)]
    ls=[]
    for i in range(1, N + 1):
        for j in combinations(S,i):
            val=sum(j)
            if val%10!=0:
                ls.append(val)

    print(max(ls,default=0))


resolve()
Problem p03700 (python)

Fixed submission:
import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import statistics # Pythonのみ
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    # https://qiita.com/drken/items/97e37dd6143e33a64c8c#3-%E3%82%81%E3%81%90%E3%82%8B%E5%BC%8F%E4%BA%8C%E5%88%86%E6%8E%A2%E7%B4%A2%E3%81%AE%E3%81%95%E3%82%89%E3%81%AA%E3%82%8B%E5%88%A9%E7%82%B9

    n,a,b=map(int,input().split())
    h=[int(input()) for _ in range(n)]
    def is_ok(t):
        cnt=0
        for i in h:
            i-=b*t
            if i>0:
                cnt+=math.ceil(i / (a-b))
        return cnt<=t

    def bin_search_meguru():
        """
        初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
        まずis_okを定義すべし
        ng, okは,とり得る最小の値-1,とり得る最大の値+1
        """
    
        # 適当にいじる
        ng = 0  # ind=0が条件を満たすこともあるため
        ok = 10**18  # ind=len(a)-1が条件を満たさないこともあるため
    
        # いじらない
        # okとngのどちらが大きいかわからないことを考慮
        while (abs(ok - ng) > 1):
            mid = (ok + ng) // 2
            if is_ok(mid):
                ok = mid
            else:
                ng = mid
        return ok
    print(bin_search_meguru())
    

    
resolve()

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    # https://qiita.com/drken/items/97e37dd6143e33a64c8c#3-%E3%82%81%E3%81%90%E3%82%8B%E5%BC%8F%E4%BA%8C%E5%88%86%E6%8E%A2%E7%B4%A2%E3%81%AE%E3%81%95%E3%82%89%E3%81%AA%E3%82%8B%E5%88%A9%E7%82%B9

    n,a,b=map(int,input().split())
    h=[int(input()) for _ in range(n)]
    def is_ok(t):
        cnt=0
        for i in range(n):
            val=math.ceil((h[i]-b*t) / (a-b))
            cnt+=val
        if cnt<=t:
            return True
        else: return False

    def bin_search_meguru():
        """
        初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
        まずis_okを定義すべし
        ng, okは,とり得る最小の値-1,とり得る最大の値+1
        """
    
        # 適当にいじる
        ng = 0  # ind=0が条件を満たすこともあるため
        ok = 10**9+1  # ind=len(a)-1が条件を満たさないこともあるため
    
        # いじらない
        # okとngのどちらが大きいかわからないことを考慮
        while (abs(ok - ng) > 1):
            mid = (ok + ng) // 2
            if is_ok(mid):
                ok = mid
            else:
                ng = mid
        return ok
    print(bin_search_meguru())
    

    
resolve()
Problem p03759 (python)

Fixed submission:
a,b,c=map(int,input().split())
#print(sorted(B)[0])
if b-a==c-b:
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
A,B,C=map(int,input().split())
#print(sorted(B)[0])
if b-a==c-b:
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
A,B,C=map(str,input().split())
#print(sorted(B)[0])
if b-a==c-b:
    print('YES')
else:
    print('NO')
Problem p03773 (python)

Fixed submission:
A,B=map(int,input().split())
#print(sorted(B)[0])
print((A+B)%24)

Buggy submission (verdict: Runtime Error):
# import bisect
# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate,permutations, combinations,combinations_with_replacement,product

def resolve():
    N,M=map(int,input().split())
    A=[list(map(int,input().split())) for i in range(N)]
    B=[list(map(int,input().split())) for i in range(M)]

    for i in A:
        valmin=10**5
        cnt=0
        for j in B:
            if abs(i[0]-j[0])+abs(i[1]-j[1])<valmin:
                valmin=abs(i[0]-j[0])+abs(i[1]-j[1])
                ans=cnt+1
            cnt+=1
        print(ans)





resolve()

Buggy submission (verdict: Runtime Error):
A,B=map(str,input().split())
#print(sorted(B)[0])
print((A+B)%24)
Problem p03818 (python)

Fixed submission:
from collections import Counter, deque, OrderedDict
# from copy import copy, deepcopy
# from functools import reduce
# from heapq import heapify, heappop, heappush
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import statistics # Pythonのみ
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():

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

    AA = Counter(A)
    ans = 0
    val = 0
    for k, v in AA.items():
        if v % 2 == 0:
            ans += 1
        else:
            val += 1
    if ans % 2 !=0:
        ans -= 1
    print(val+ans)


resolve()

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():

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

    AA = Counter(A)
    ans = 0
    val = 0
    for k, v in AA.items():
        if v % 2 == 0:
            ans += 1
        else:
            val += 1
    if ans % 2 !=0:
        ans -= 1
    print(val+ans)


resolve()
Problem p03994 (python)

Fixed submission:
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    a = list(input())
    K = int(input())
    for i in range(len(a)):
        if a[i]=='a' and i!=len(a)-1:
            continue
        else:
            val = 123 - ord(a[i])
            if val <= K:
                a[i] = 'a'
                K -= val
            if i == len(a) - 1 and K > 0:
                a[-1] = chr(ord(a[-1]) + K % 26)
    print(''.join(a))


resolve()

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():

    a=list(input())
    K=int(input())
    for i in range(len(a)):
        val=123-ord(a[i])
        if val<=K:
            a[i]='a'
            K-=val
        if i==len(a)-1 and K>0:
            a[-1]=chr(ord(a[-1])+K)
    print(''.join(a))



resolve()
Problem p02731 (python)

Fixed submission:
l = int(input())
print((l/3) ** 3)

Buggy submission (verdict: Runtime Error):
l = input()
print(l/3 ** 3)
Problem p02789 (python)

Fixed submission:
n,m=map(int,input().split());print("YNeos"[n>m::2])

Buggy submission (verdict: Runtime Error):
n,m=map(int,input().split();print("YNeos"[n>m::2])
Problem p02813 (python)

Fixed submission:
from itertools import permutations

n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
for i, pi in enumerate(permutations(range(1, n+1))):
    if pi == p:
        a = i
    if pi == q:
        b = i
print(abs(a - b))

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

n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
for i, pi in enumerate(permutations(range(1, n+1))):
    if pi == p:
        a = i
    elif pi == q:
        b = i
print(abs(a - b))
Problem p03000 (python)

Fixed submission:
n, x = map(int, input().split())
l = [int(i) for i in input().split()]
b = 0
c = 1
for i in range(n):
    if b + l[i] <= x:
        b += l[i]
        c += 1
    else:
        break
print(c)

Buggy submission (verdict: Runtime Error):
n, x = map(int, input().split())
l = [int(i) for i in input().split()]
b = 0
c = 1
for i in range(n + 1):
    if b + l[i] <= x:
        b += l[i]
        c += 1
    else:
        break
print(c)
Problem p03400 (python)

Fixed submission:
n = int(input())
d, x = map(int, input().split())
a = [int(input()) for i in range(n)]
c = 0
for i in range(n):
    for j in range(1, d + 1):
        if a[i] == 1:
            c += 1
        elif j % a[i] == 1:
            c += 1
print(c + x)

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())
c = int(input())
d = int(input())
print(min(a, b) + min(c, d))
Problem p03417 (python)

Fixed submission:
n, m = map(int, input().split())
if n * m == 1:
  print(1)
elif n == 1 or m == 1:
  print(n + m - 3)
else:
  print((n - 2) * (m - 2))

Buggy submission (verdict: Runtime Error):
n, m = map(int, inout().split())
if n * m == 1:
  print(1)
elif n == 1 or m == 1:
  print(n + m - 1)
else:
  print((n - 2) * (m - 2))
Problem p03556 (python)

Fixed submission:
n = int(input())
m = int(n ** 0.5 + 3)
for i in range(m):
    if i ** 2 > n:
        print((i - 1) ** 2)
        break

Buggy submission (verdict: Runtime Error):
n = int(input())
for i in range(n ** 0.5 + 3):
  if i ** 2 > n:
    print((i - 1) ** 2)

Buggy submission (verdict: Runtime Error):
n = int(input())
m = n ** 0.5 + 3
for i in range(m,,-1):
  if i ** 2 < n:
    print(i ** 2)
    break
Problem p03636 (python)

Fixed submission:
s = input()
t = len(s) - 2
print(s[0] + str(t) + s[- 1])

Buggy submission (verdict: Runtime Error):
s = input()
t = len(s)
print(s[0] + t + s[- 1])

Buggy submission (verdict: Runtime Error):
s = input()
print(s[0] + (len(s) - 2) + s[- 1])
Problem p03695 (python)

Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
color = [0] * 8
any = 0
for i in a:
    if 1 <= i <= 399:
        color[0] = 1
    elif 400 <= i <= 799:
        color[1] = 1
    elif 800 <= i <= 1199:
        color[2] = 1
    elif 1200 <= i <= 1599:
        color[3] = 1
    elif 1600 <= i <= 1999:
        color[4] = 1
    elif 2000 <= i <= 2399:
        color[5] = 1
    elif 2400 <= i <= 2799:
        color[6] = 1
    elif 2800 <= i <= 3199:
        color[7] = 1
    else:
        any += 1
m = max(sum(color), 1)
M = sum(color) + any
print(m, M)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = [int(i) for i in input().split()]
color = [0] * 8
any = 0
for i in a:
    if 1 <= i <= 399:
        color[0] = 1
    elif 400 <= i <= 799:
        color[1] = 1
    elif 800 <= i <= 1199:
        color[2] = 1
    elif 1200 <= i <= 1599:
        color[3] = 1
    elif 1600 <= i <= 1999:
        color[4] = 1
    elif 2000 <= i <= 2399:
        color[5] = 1
    elif 2400 <= i <= 2799:
        color[6] = 1
    elif 2800 <= i <= 3199:
        color[7] = 1
    else:
        any += 1
m = max(sum(color), 1)
M = min(sum(color) + any)
print(m, M)
Problem p02601 (python)

Fixed submission:
a, b, c = map(int, input().split())
k = int(input())

if a<b and b<c:
  print("Yes")

else:
  while k != 0:
    if a >= b:
      b *= 2
      k -= 1
    else:
      c *= 2
      k -= 1
  
  if a<b and b<c:
    print("Yes")
  else:
    print("No")

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
k = int(input())

if a<b and b<c:
  print("Yse")

else:
  while k == 0:
    if a >= b:
      b *= 2
      k -= 1
    else:
      b >= c:
      c *= 2
      k -= 1
  
  if a<b and b<c:
    print("Yse")
  else:
    print("No")
Problem p02641 (python)

Fixed submission:
x ,n = map(int, input().split())
s = list(map(int, input().split()))
number = list(range(0,102))
min = 100
if n == 0:
  print(x)
  exit()
  
for i in range(n):
  number.remove(s[i])

for i in range(102 - n):
  if min > abs(x - number[i]):
    min = abs(x - number[i])
    j = i
print(number[j])

Buggy submission (verdict: Runtime Error):
x ,n = map(int, input().split())
s = list(map(int, input().split()))
number = list(range(0,102))
min = 100
if n == 0:
  print(x)
  exit()
  
for i in range(n):
  number.remove(s[i])

for i in range(100 - n):
  if min > abs(x - number[i]):
    min = abs(x - number[i])
    j = i
print(number[j])

Buggy submission (verdict: Runtime Error):
x ,n = map(int, input().split())
s = list(map(int, input().split()))
number = list(range(1,101))
min = 100
if n == 0:
  print(x)
  exit()
  
for i in range(n):
  number.remove(s[i])

for i in range(100 - n):
  if min > abs(x - number[i]):
    min = abs(x - number[i])
    j = i
print(number[j])
Problem p02675 (python)

Fixed submission:
n = int(input())

if n%10 in [2, 4, 5, 7, 9]:
  print('hon')
elif n%10 in [0, 1, 6, 8]:
  print('pon')
else:
  print('bon')

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

if n[lne(n) - 1] == '3':
  print('bon')
elif n[len(n) - 1] == '0' or '1' or '6' or '8':
  print('pon')
else:
  print('hon')
Problem p02958 (python)

Fixed submission:
N = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(N):
  if p[i] != i+1:
    ans += 1

if ans <= 2:
  print("YES")
else:
  print("NO")

Buggy submission (verdict: Runtime Error):
N = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(N):
  if p[i] != i+1:
    ans += 1

if ans <= 2:
  print("YES")
else:
  prin("NO")
Problem p03000 (python)

Fixed submission:

N, X = map(int, input().split())
L = list(map(int, input().split()))
cnt = 1
total = 0
for i in range(N):
  total += L[i]
  if total <= X:
    cnt += 1
  else:
    break
print(cnt)

Buggy submission (verdict: Runtime Error):
import sys
N, X = map(int, input().split())
L = list(map(int, input().split()))
cnt = 0
total = 0
for i in range(N+1):
  if total <= X:
    cnt += 1
    total += L[i]
  else:
    print(cnt)
    sys.exit()
print(N+1)

Buggy submission (verdict: Runtime Error):
import sys
N, X = map(int, input().split())
L = list(map(int, input().split()))
cnt = 0
total = 0
for i in range(N+1):
  if total <= X:
    cnt += 1
    total += L[i]
  else:
    print(cnt)
    sys.exit()
Problem p03131 (python)

Fixed submission:
K, A, B = map(int, input().split())
ans = 0
if B - A <= 2:
  print(K + 1)

else:
  K -= A - 1
  ans += (K//2) * (B - A) + A
  ans += K % 2
  print(ans)

Buggy submission (verdict: Runtime Error):
K, A, B = map(int, input().split())
count = 1
coin = 0
if B - A <= 2:
  print(K + 1)
  
else:
  for i in range(K):
    if coin == 1:
      count += B
      coin -= 1
    elif count >= A and i != k-1:
      count -= A
      coin += 1
    else:
      count += 1
  print(count)
Problem p03796 (python)

Fixed submission:
n = int(input())
ans = 1
for i in range(1, n+1):
  ans *= i
  if ans >= 10**9 + 7:
    ans %= 10**9 + 7
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
ans = 1
for i in range(1, n+1):
  ans *= i
print(ans/(10**9+7))