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

Fixed submission:
H,W = map(int,input().split())
s = [input() for _ in range(H)]

DP = [[1000]+[0]*W for _ in range(H+1)]
re = [[0]*(W+1) for _ in range(H+1)]
DP[0] = [1000]*(W+1)
DP[0][1] = DP[1][0] = 0

for i in range(1,H+1):
    for j in range(1,W+1):
        if s[i-1][j-1] == ".":
            DP[i][j] = min(DP[i-1][j],DP[i][j-1])
        else:
            u = DP[i-1][j]+1-re[i-1][j]
            l = DP[i][j-1]+1-re[i][j-1]
            DP[i][j] = min(u, l)
            re[i][j] = 1

print(DP[H][W])

Buggy submission (verdict: Runtime Error):
H,W = map(int,input().split())
s = [input() for _ in range(H)]
import math
DP = [[math.inf]+[0]*W for _ in range(H+1)]
re = [[0]*(W+1) for _ in range(H+1)]
DP[0] = [math.inf]*(W+1)
DP[0][1] = DP[1][0] = 0

for i in range(1,H+1):
    for j in range(1,W+1):
        if s[i-1][j-1] == ".":
            DP[i][j] = min(DP[i-1][j],DP[i][j-1])
        else:
            u = DP[i-1][j]+1-re[i-1][j]
            l = DP[i][j-1]+1-re[i][j-1]
            DP[i][j] = min(u, l)
            re[i][j] = 1
            if u < l and re[i-1][j] == 0:
                DP[i][j] += 1
            elif u > l and re[i][j-1] == 0:
                count += 1
            elif u == l:
                count += 1 - re[i-1][j]*re[i][j-1]
                
print(DP[H][W])
Problem p02546 (python)

Fixed submission:
n = input()
a = 's'
b = 'es'
if n[-1] == 's':
    n = n + b
else:
    n = n + a
print(n)

Buggy submission (verdict: Runtime Error):
list = []
x = 0
y = 0
n = int(input())
for i in range(n):
    a,b = map(int,input().split())
    list.append(a)
    list.append(b)
for _ in range(n):
    if list[x] == list[x+1]:
        n = n - 1
        if not list[x+1] == list[-1]:
            if list[x+2] == list[x+3]:
                n = n - 1
                if not list[x+3] == list[-1]:
                    if list[x+4] == list[x+5]:
                         n = n - 1
                         y = 1
    x = x + 2
if y == 0:
    print('No')
else:
    print('Yes')

Buggy submission (verdict: Runtime Error):
list = []
x = 0
y = 0
n = int(input())
for i in range(n):
    a,b = map(int,input().split())
    list.append(a)
    list.append(b)
for _ in range(n):
    if list[x] == list[x+1]:
        n = n - 1
        if not list[x+1] == list[-1]:
            if list[x+2] == list[x+3]:
                n = n - 1
                if not list[x+3] == list[-1]:
                    if list[x+4] == list[x+5]:
                         n = n - 1
                         y = 1
    x = x + 2
if y == 0:
    print('No')
else:
    print('Yes')

Buggy submission (verdict: Runtime Error):
list = []
x = 0
y = 0
n = int(input())
for i in range(n):
    a,b = map(int,input().split())
    list.append(a)
    list.append(b)
for _ in range(n):
    if not list[x-1] == list[-1]:
        if list[x] == list[x+1]:
            if not list[x+1] == list[-1]:
                if list[x+2] == list[x+3]:
                    if not list[x+3] == list[-1]:
                        if list[x+4] == list[x+5]:
                            y = 1
    x = x + 2
if y == 0:
    print('No')
else:
    print('Yes')

Buggy submission (verdict: Runtime Error):
list = []
x = 0
y = 0
n = int(input())
for i in range(n):
    a,b = map(int,input().split())
    list.append(a)
    list.append(b)
for _ in range(n):
    if list[x] == list[x+1]:
        if not list[x+1] == list[-1]:
            if list[x+2] == list[x+3]:
                if not list[x+3] == list[-1]:
                    if list[x+4] == list[x+5]:
                        y = 1
    if not x+7 > len(list):
        x = x + 2
if y == 0:
    print('No')
else:
    print('Yes')
Problem p02625 (python)

Fixed submission:
n, m = map(int, input().split())
mod = 10 ** 9 + 7

f = [1, 1]
f_inv = [1, 1]
inv = [0, 1]
 
for i in range(2, m+1):
    f.append((f[-1] * i ) % mod)
    inv.append((-inv[mod % i] * (mod // i)) % mod)
    f_inv.append((f_inv[-1] * inv[-1]) % mod)

def comb(n, k):
    return f[n] * f_inv[k] * f_inv[n-k] % mod

def per(n, k):
    return f[n] * f_inv[n-k] % mod

ans = 0
for i in range(0, n+1):
    res = comb(n, i) *  per(m, i) * (per(m-i, n-i) ** 2)
    if i % 2 == 1:
        res *= -1
    ans += res
    ans %= mod

print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
mod = 10 ** 9 + 7

fac = [1 for _ in range(m+1)]
for i in range(1, m):
    fac[i+1] = fac[i] * (i+1) % mod

dp = [0 for _ in range(n+1)]
dp[1] = m - n
for i in range(2, n+1):
    dp[i] = dp[i-1] * i + fac[i-1] * (i-1)
    dp[i] %= mod


ans = dp[n]

tmp = m
for _ in range(n):
    ans *= tmp
    ans %= mod
    tmp -= 1

print(ans)1
Problem p02862 (python)

Fixed submission:
#145_D
x,y=map(int,input().split())
mod=10**9+7
if (x+y)%3!=0:
    print(0)
else:
    n=(2*x-y)//3
    m=(2*y-x)//3
    if n<0 or m<0:
        print(0)
    else:
        f=[1 for i in range(m+n+1)]
        for i in range(2,m+n+1):
            f[i]=f[i-1]*i%mod
        print(f[m+n]*pow(f[n],mod-2,mod)*pow(f[m],mod-2,mod)%mod)

Buggy submission (verdict: Runtime Error):
#145_D
x,y=map(int,input().split())
mod=10**9+7
if (x+y)%3!=0:
    print(0)
else:
    n=(2*x-y)//3
    m=(2*y-x)//3
    f=[1 for i in range(m+n+1)]
    for i in range(2,m+n+1):
        f[i]=f[i-1]*i%mod
    print(f[m+n]*pow(f[n],mod-2,mod)*pow(f[m],mod-2,mod)%mod)
Problem p02925 (python)

Fixed submission:
from collections import Counter
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
n = int(input())
edges = [[] for _ in range(n * 1001)]
memo = []
start = set()
for i in range(n):
    A = list(map(int, input().split()))
    for j in range(n-1):
        if i < A[j] - 1:
            A[j] = i * 1000 + A[j] - 1
        else:
            A[j] = (A[j] - 1) * 1000 + i

    for j in range(n-2):
        edges[A[j]].append(A[j+1])
    memo.append(A[0])

memo = Counter(memo).most_common()
for x, t in memo:
    if t > 1:
        start.add(x)

#閉路検出/最長のパス
d = [-1 for _ in range(1001 * n)]
def dfs(v):
    d[v] = -2
    l = 0
    for to in edges[v]:
        if d[to] == -2:
            print(-1)
            exit()
        if d[to] == -1:
            dfs(to)
        l = max(l, d[to] + 1)
    d[v] = l

if len(start) == 0:
    print(-1)
    exit()
for i in start:
    dfs(i)
print(max(d) + 1)

Buggy submission (verdict: Runtime Error):
from collections import Counter
n = int(input())
edges = [[] for _ in range(n * 1001)]
memo = []
start = set()
for i in range(n):
    A = list(map(int, input().split()))
    for j in range(n-1):
        if i < A[j] - 1:
            A[j] = i * 1000 + A[j] - 1
        else:
            A[j] = (A[j] - 1) * 1000 + i

    for j in range(n-2):
        edges[A[j]].append(A[j+1])
    memo.append(A[0])

memo = Counter(memo).most_common()
for x, t in memo:
    if t > 1:
        start.add(x)

#閉路検出/最長のパス
d = [-1 for _ in range(1001 * n)]
def dfs(v):
    d[v] = -2
    l = 0
    for to in edges[v]:
        if d[to] == -2:
            print(-1)
            exit()
        if d[to] == -1:
            dfs(to)
        l = max(l, d[to] + 1)
    d[v] = l

if len(start) == 0:
    print(-1)
    exit()
for i in start:
    dfs(i)
print(max(d) + 1)

Buggy submission (verdict: Runtime Error):
n = int(input())
edges = [[] for _ in range(n * 1001)]
memo = []
for i in range(n):
    A = list(map(int, input().split()))
    for j in range(n-1):
        if i < A[j] - 1:
            A[j] = i * 1000 + A[j] - 1
        else:
            A[j] = (A[j] - 1) * 1000 + i

    for j in range(n-2):
        edges[A[j]].append(A[j+1])
    memo.append(A[0])

seen = [False for _ in range(1001 * n)]
def dfs(start, frm, cur, flg):
    for to in edges[cur]:
        if to == frm:
            continue
        if to == start:
            return False
        else:
            d[to] = max(d[cur] + 1, d[to])
            flg = dfs(start, cur, to, flg)

    return flg


flg = True
ans = []
for x in memo:
    d = [0 for _ in range(n * 1001)]
    d[x] = 1
    if dfs(x, -1, x, True):
        ans.append(max(d))
    else:
        flg = False

if flg:
    print(max(ans))
else:
    print(-1)
Problem p02990 (python)

Fixed submission:
#132_D
n,k=map(int,input().split())
mod=10**9+7

f=[1 for i in range(n+2)]
f_inv=[1 for i in range(n+2)]
for i in range(1,n+2):
    f[i]=f[i-1]*i%mod
    f_inv[i]=pow(f[i],mod-2,mod)
    
def comb(n,k):
    if k>n:
        return 0
    return f[n]*f_inv[k]*f_inv[n-k]%mod

for i in range(1,k+1):
    print(comb(n-k+1,i)*comb(k-1,i-1)%mod)

Buggy submission (verdict: Runtime Error):
#132_D
n,k=map(int,input().split())
mod=10**9+7

f=[1 for i in range(n-k+2)]
f_inv=[1 for i in range(n-k+2)]
for i in range(1,n-k+2):
    f[i]=f[i-1]*i%mod
    f_inv[i]=pow(f[i],mod-2,mod)
    
def comb(n,k):
    if k>n:
        return 0
    return f[n]*f_inv[k]*f_inv[n-k]%mod

for i in range(1,k+1):
    print(comb(n-k+1,i)*comb(k-1,i-1)%mod)
Problem p03013 (python)

Fixed submission:
#129_C
n,m=map(int,input().split())
a={int(input()) for _ in range(m)}
mod=10**9+7
dp=[0 for i in range(n+1)]
dp[0]=1
for i in range(1,n+1):
    if i in a:
        dp[i]=0
    else:
        dp[i]=(dp[i-1]+dp[i-2])%mod
        
print(dp[n])

Buggy submission (verdict: Runtime Error):
#129_C
n,m=map(int,input().split())
a=[int(input()) for _ in range(m)]
mod=10**9+7
dp=[1 for i in range(n+1)]
for i in range(1,n+1):
    if i in a:
        dp[i]=0
    elif i==1:
        dp[i]=dp[i-1]
    else:
        dp[i]=(dp[i-1]+dp[i-2])%mid
        
print(dp[n]%mod)
Problem p03033 (python)

Fixed submission:
import heapq, sys
input = sys.stdin.readline
n, q = map(int, input().split())
event = []
for _ in range(n):
    s, t, x = map(int, input().split())
    event.append((s-x, 1, x))
    event.append((t-x, -1, x))

for _ in range(q):
    d = int(input())
    event.append((d, 2, 0))

event.sort(key=lambda x: (x[0], x[1]))
now = []
memo = set()

tmp = 0

for i, (t, flg, x) in enumerate(event):
    if flg == -1:
        memo.remove(x)
    elif flg == 1:
        heapq.heappush(now, x)
        memo.add(x)
    else:
        while len(now) > 0 and now[0] not in memo:
            heapq.heappop(now)
        if len(now) > 0:
            print(now[0])
        else:
            print(-1)

Buggy submission (verdict: Runtime Error):
import heapq
n, q = map(int, input().split())
event = []
for _ in range(n):
    s, t, x = map(int, input().split())
    event.append((s-x, 1, x))
    event.append((t-x, -1, x))

for _ in range(q):
    d = int(input())
    event.append((d, 2, 0))

event.sort()
now = []
memo = set()

tmp = 0
for i, (t, flg, x) in enumerate(event):
    if flg == -1:
        memo.remove(x)
    elif flg == 1:
        heapq.heappush(now, x)
        memo.put(x)

    else:
        while now[0] in memo:
            heapq.heappop(now)
        if len(now) > 0:
            print(now[0])
        else:
            print(-1)
Problem p03108 (python)

Fixed submission:
#120_D
#Union-Find
n,m=map(int,input().split())
edges=[]
for _ in range(m):
    a,b=map(int,input().split())
    edges.append((a-1,b-1))
edges=edges[::-1]

par=[i for i in range(n)]
size=[1 for _ in range(n)]
rank=[0 for _ in range(n)]

def find(x):#木の根を求める
    if par[x]==x:
        return x
    else:
        par[x]=find(par[x])
        return par[x]
    
def merge(x,y):#併合
    x=find(x)
    y=find(y)
    if x==y:
        return
    if rank[x]>rank[y]:
        par[y]=x
        size[x]+=size[y]
    else:
        par[x]=y
        size[y]+=size[x]
        if rank[x]==rank[y]:
            rank[y]+=1
            
def same(x,y):
    return find(x)==find(y)
    

ans=[n*(n-1)//2 for i in range(m)]
for i in range(0,m-1):
    a,b=edges[i]
    ans[i+1]=ans[i]
    if not same(a,b):
        ans[i+1]-=size[find(a)]*size[find(b)]
        merge(a,b)
        

ans=ans[::-1]
for i in range(m):
    print(ans[i])

Buggy submission (verdict: Runtime Error):
#120_D
#Union-Find
n,m=map(int,input().split())
edges=[]
for _ in range(m):
    a,b=map(int,input().split())
    edges.append((a-1,b-1))
edges=edges[::-1]

par=[i for i in range(n)]
size=[1 for _ in range(n)]

def find(x):#木の根を求める
    if par[x]==x:
        return x
    else:
        return find(par[x])
    
def merge(x,y):#併合
    x=find(x)
    y=find(y)
    if x==y:
        return
    par[y]=x
    size[x]+=size[y]
            
def same(x,y):
    return find(x)==find(y)
    

ans=[n*(n-1)//2 for i in range(m)]
for i in range(0,m-1):
    a,b=edges[i]
    ans[i+1]=ans[i]
    if not same(a,b):
        ans[i+1]-=size[find(a)]*size[find(b)]
        merge(a,b)
        

ans=ans[::-1]
for i in range(m):
    print(ans[i])

Buggy submission (verdict: Runtime Error):
#120_D
#Union-Find
n,m=map(int,input().split())
edges=[]
for _ in range(m):
    a,b=map(int,input().split())
    edges.append((a-1,b-1))
edges=edges[::-1]

par=[i for i in range(n)]
size=[1 for _ in range(n)]

def find(x):#木の根を求める
    if par[x]==x:
        return x
    else:
        return find(par[x])
    
def merge(x,y):#併合
    x=find(x)
    y=find(y)
    if x==y:
        return
    par[y]=x
    size[x]+=size[y]
            
def same(x,y):
    return find(x)==find(y)
    

ans=[n*(n-1)//2 for i in range(m)]
for i in range(0,m-1):
    a,b=edges[i]
    ans[i+1]=ans[i]
    if not same(a,b):
        ans[i+1]-=size[find(a)]*size[find(b)]
        merge(a,b)
        

ans=ans[::-1]
for i in range(m):
    print(ans[i])
Problem p03805 (python)

Fixed submission:
#054_C
from itertools import permutations
n,m=map(int,input().split())
edges=[[False for _ in range(n)] for _ in range(n)]
for _ in range(m):
    a,b=map(int,input().split())
    a,b=a-1,b-1
    edges[a][b]=edges[b][a]=True

ans=0
for l in permutations(range(1,n),n-1):
    l=[0]+list(l)
    if all(edges[l[i]][l[i+1]] for i in range(n-1)):
        ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
#054_C
from itertools import permutations
n,m=map(int,input().split())
edges=[[False for _ in range(n)] for _ in range(n)]
for _ in range(m):
    a,b=map(int,input().split())
    a,b=a-1,b-1
    edges[a][b]=edges[b][sa]=True

ans=0
for l in permutations(range(1,n),n-1):
    l=[0]+list(l)
    if all(edges[l[i]][l[i+1]] for i in range(n-1)):
        ans+=1
print(ans)
Problem p02594 (python)

Fixed submission:
X = int(input())

if 30<= X:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
if 30<= x:
  print"Yes"
else:
  print"No"
Problem p02546 (python)

Fixed submission:
sentence = input()
if sentence[-1] == 's':
  print(sentence+'es')
else:
  print(sentence+'s')

Buggy submission (verdict: Runtime Error):
n,x,m = map(int,input().split())
def jouken(a,waru):
    return a**2%waru
ni = 0
num =0
for i in range(n-1):
    ni = x
    if i ==0:
        num+=x
    x = jouken(ni,m)
    num+=x
print(num)
Problem p02570 (python)

Fixed submission:
D,T,S = map(int,input().split())
if D/T <= S:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
s = input()
t = input()
S,T = len(s),len(t)

ans = T

for i in range(S-T+1):
    tmp = [c1!=c2 for c1,c2 in zip(s[i:i+T],t)].count(True)
    ans = min(ans,tmp)

print(ans)
Problem p02546 (python)

Fixed submission:
S = input()

if S[-1] == 's':
    print(S + 'es')
else:
    print(S + 's')

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

LR = [list(map(int, input().split())) for i in range(K)]
S = set()
for i in LR:
    for j in range(i[0], i[1]+1):
        S.add(j)
L = sorted(list(S))

dp = [0 for i in range(N)]
dp[0] = 1
for i in range(1, N):
    x = bisect.bisect(L, i)
    t = L[:x]
    for j in t:
        dp[i] += dp[i-j]
    dp[i] = dp[i] % 998244353

print(dp[-1] % 998244353)
Problem p02547 (python)

Fixed submission:
N = int(input())
D = [list(map(int, input().split())) for i in range(N)]

seq = 0
for i in range(len(D)-2):
    if D[i][0] == D[i][1]:
        if D[i+1][0] == D[i+1][1]:
            if D[i+2][0] == D[i+2][1]:
                print('Yes')
                exit()
print('No')

Buggy submission (verdict: Runtime Error):
N = int(input())
D = [map(int, input().split()) for i in range(N)]

seq = 0
for i in range(len(D)):
    if D[i][0] == D[i][1]:
        if D[i+1][0] == D[i+1][1]:
            if D[i+2][0] == D[i+2][1]:
                print('Yes')
                exit()

print('No')
Problem p02623 (python)

Fixed submission:
import bisect

N, M, K = input().split()

desk1 = list(map(int, input().split()))
desk2 = list(map(int, input().split()))

max_time = int(K)
item1 = [0]
item2 = [0]
for i in desk1:
    item1.append(item1[-1] + i)
for i in desk2:
    item2.append(item2[-1] + i)

ret = 0
for i, t in enumerate(item1):
    remain_time = max_time - t
    if remain_time >= 0:
        j = bisect.bisect(item2, remain_time) - 1
        ret = max(ret, i + j)

print(ret)

Buggy submission (verdict: Runtime Error):
import bisect

N, M, K = input().split()

desk1 = list(map(int, input().split()))
desk2 = list(map(int, input().split()))

max_time = int(K)
item1 = [0]
item2 = [0]
for i in desk1:
    item1.append(item1[-1] + i)
for i in desk2:
    item2.append(item2[-1] + i)

ret = 0
for i, t in enumerate(item1):
    remain_time = max_time - t
    if remain_time > 0:
        j = bisect.bisect(item2, remain_time) - 1
        if j < 0:
            j = 0
        ret = max(ret, i + j)
    else:
        ret = max(ret, i)
print(ret)import bisect

N, M, K = input().split()

desk1 = list(map(int, input().split()))
desk2 = list(map(int, input().split()))

max_time = int(K)
item1 = [0]
item2 = [0]
for i in desk1:
    item1.append(item1[-1] + i)
for i in desk2:
    item2.append(item2[-1] + i)

ret = 0
for i, t in enumerate(item1):
    remain_time = max_time - t
    if remain_time > 0:
        j = bisect.bisect(item2, remain_time) - 1
        if j < 0:
            j = 0
        ret = max(ret, i + j)
    else:
        ret = max(ret, i)
print(ret)
Problem p02793 (python)

Fixed submission:
from fractions import gcd
from functools import reduce
N = int(input())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7

def lcm(a,b):
    return (a * b // gcd(a, b))

def modpow(a, n, mod): # a^n mod
    result = 1
    while n > 0:
        if n & 1: result = result * a % mod
        a = a * a % mod
        n >>= 1
    return result

h = reduce(lcm, A)
B = [h * modpow(A[i], MOD-2, MOD) for i in range(N)]
print(sum(B) % MOD)

Buggy submission (verdict: Runtime Error):
from math import gcd
from functools import reduce
N = int(input())
A = list(map(int, input().split()))
B = [i for i in range(N)]
MOD = 10 ** 9 + 7
def lcm(a,b):
    return a * b // gcd(a, b)
h = reduce(lcm, A)

for i in range(N):
    B[i] = (h // A[i] % MOD)

print(sum(B) % MOD)
Problem p03012 (python)

Fixed submission:
import sys

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

dif = 9999999999

for i in range(1,N):
    tmp = abs(sum(W[:i]) - sum(W[i:]))
    if dif > tmp:
        dif = tmp
print(dif)

Buggy submission (verdict: Runtime Error):
import sys

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

dif = math.inf

for i in range(1,N):
    tmp = abs(sum(W[:i]) - sum(W[i:]))
    if dif > tmp:
        dif = tmp
print(dif)

Buggy submission (verdict: Runtime Error):
import sys
import math
N = int(input())
W = list(map(int,input().split()))

dif = math.inf

for i in range(1,N):
    tmp = abs(sum(W[:i]) - sum(W[i:]))
    print(i,tmp)
    if dif > tmp:
        dif = tmp
print(dif)
Problem p02546 (python)

Fixed submission:
S = input()
l = len(S)
if S[l-1]=='s':
    S = S + 'es'
else:
    S = S + 's'
print(S)

Buggy submission (verdict: Runtime Error):
import math

N = int(input())
cnt = 0
if N == 2:
    cnt = 1
elif N == 3:
    cnt = 3
elif N > 3:
    cnt = 3
    for i in range(1,N-1):
        A = N-i
        rA = math.sqrt(A)
        intA = math.floor(rA)
        if rA == intA:
            cnt -= 1
        if intA == 1:
            cnt += 1
        else:
            for j in range(1,intA+1):
                if A%j == 0:
                    cnt += 2

print(cnt)

Buggy submission (verdict: Runtime Error):
import math

N = int(input())

if N == 2:
    cnt = 1
elif N == 3:
    cnt = 3
elif N > 3:
    cnt = 3
    for i in range(1,N-1):
        A = N-i
        rA = math.sqrt(A)
        intA = math.floor(rA)
        if rA == intA:
            cnt -= 1
        if intA == 1:
            cnt += 1
        else:
            for j in range(1,intA+1):
                if A%j == 0:
                    cnt += 2

print(cnt)

Buggy submission (verdict: Runtime Error):
import math

N = int(input())

if N == 2:
    cnt = 1
elif N == 3:
    cnt = 3
    
elif N > 3:
    for i in range(1,N-1):
        A = N-i
        rA = math.sqrt(A)
        intA = math.floor(rA)
        if rA == intA:
            cnt -= 1
        if intA == 1:
            cnt += 1
        else:
            for j in range(1,intA+1):
                if A%j == 0:
                    cnt += 2

print(cnt)
Problem p03286 (python)

Fixed submission:
import math
N = int(input())

ans = ""
if N == 1:
    print("1") 
elif N == 0:
    print("0")  
elif N == -1:
    print("10")
else:
    while True:
        r = N % 2
        N = (N-r) /-2
        ans = str(int(r)) + ans
        if N == 0 or N == 1:
            ans = str(int(N)) + ans
            break

    print(ans)

Buggy submission (verdict: Runtime Error):

ans = ""
if N == 1:
    print("1")
elif N == -1:
    print("10")
else:
    while True:
        r = N % 2
        N = (N-r) /-2
        ans = str(int(r)) + ans
        if N == 0 or N == 1:
            ans = str(int(N)) + ans
            break

    print(ans)
Problem p02546 (python)

Fixed submission:
word = input()
if word[-1] == 's':
  print(word+'es')
else:
  print(word+'s')

Buggy submission (verdict: Runtime Error):
word = input()
if word[-1] == 's':
  return ''.join(word, 'es')
else:
  return ''.join(word, 's')
Problem p02987 (python)

Fixed submission:
a = input()
if len(set(a)) == 2:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
if len(set(input())) ==2: print("Yes)
else: print("No")
Problem p02546 (python)

Fixed submission:
s = input()
if s[-1] == "s":
    print(s + "es")
else:
    print(s + "s")

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


A = [-1]*(M+100)
A[0] = X
i = 0
tmpans = 0
flag = False
check = [-1]*(M+1)
slice = -1
while i< N-1:
    newa = A[i]**2%M
    i+= 1
    if check[newa] != -1:
        flag = True
        slice = check[newa]
        break
    A[i] = newa
    check[newa] = i

if not flag:
    print(sum(A[:i+1]))

else:
    print(sum(A[:slice])+ sum(A[slice:i])*((N-slice)//(i-slice))+sum(A[slice:slice + (N-slice)%(i-slice)]))
Problem p02550 (python)

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


A = [-1]*(M+100)
A[0] = X
i = 0
tmpans = 0
flag = False
check = [-1]*(M+1)
slice = -1
while i< N-1:
    newa = A[i]**2%M
    i+= 1
    if check[newa] != -1:
        flag = True
        slice = check[newa]
        break
    A[i] = newa
    check[newa] = i

if not flag:
    print(sum(A[:i+1]))

else:
    print(sum(A[:slice])+ sum(A[slice:i])*((N-slice)//(i-slice))+sum(A[slice:slice + (N-slice)%(i-slice)]))

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


A = [-1]*M
A[0] = X
i = 0
tmpans = 0
flag = False
check = [-1]*(M+1)
slice = -1
while i< N-1:
    newa = A[i]**2%M
    i+= 1
    if check[newa] != -1:
        flag = True
        slice = check[newa]
        break
    A[i] = newa
    check[newa] = i

if not flag:
    print(sum(A[:i+1]))

else:
    print(sum(A[:slice])+ sum(A[slice:i])*((N-slice)//(i-slice))+sum(A[slice:slice + (N-slice)%(i-slice)]))

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


A = [-1]*M
A[0] = X
i = 0
tmpans = 0
flag = False
check = [-1]*(M+1)
slice = -1
while i< N-1:
    newa = A[i]**2%M
    i+= 1
    if check[newa] != -1:
        flag = True
        slice = check[newa]
        break
    A[i] = newa
    check[newa] = i

if not flag:
    print(sum(A[:i+1]))

else:
    print(sum(A[:slice])+ sum(A[slice:i])*((N-slice)//(i-slice))+sum(A[slice:(N-slice)%(i-slice)]))