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

Fixed submission:
a = int(input())
print(a + a ** 2 + a ** 3)

Buggy submission (verdict: Runtime Error):
def resolve():
    def dfs(a, b, k):
        nonlocal cnt
        seen[a][b] = True
        na = a + 1
        nb = b + 1
        if na <= N and seen[na][b] is False and k >= book_a[na]:
            k -= book_a[na]
            cnt = max(cnt, na + b)
            dfs(na, b, k)
        if nb <= M and seen[a][nb] is False and k >= book_b[nb]:
            k -= book_b[nb]
            cnt = max(cnt, a + nb)
            dfs(a, nb, k)

    N, M, k = map(int, input().split())
    book_a = [int(x) for x in input().split()]
    book_b = [int(x) for x in input().split()]
    book_a.insert(0, 0)
    book_b.insert(0, 0)
    cnt = 0
    seen = [[False] * (M + 1) for _ in range(N + 1)]
    dfs(0, 0, k)
    print(cnt)


if __name__ == "__main__":
    resolve()

Buggy submission (verdict: Runtime Error):
def dfs(a, b, k):
    global cnt
    seen[a][b] = True
    na = a + 1
    nb = b + 1
    if na <= N and seen[na][b] is False and k >= book_a[na]:
        k -= book_a[na]
        cnt = max(cnt, na + b)
        dfs(na, b, k)
    if nb <= M and seen[a][nb] is False and k >= book_b[nb]:
        k -= book_b[nb]
        cnt = max(cnt, a + nb)
        dfs(a, nb, k)
        
N, M, k = map(int, input().split())
book_a = [int(x) for x in input().split()]
book_b = [int(x) for x in input().split()]
book_a.insert(0, 0)
book_b.insert(0, 0)
cnt = 0
seen = [[False] * (M + 1) for _ in range(N + 1)]
dfs(0, 0, k)
print(cnt)
Problem p02642 (python)

Fixed submission:
import numpy as np

n = int(input())
a = list(map(int, input().split()))
a_max = max(a)
lst = [0] * (a_max + 1)
cnt = 0
# if len(a) <= 1:
#     print(0)
# else:
for i in a:
    if lst[i] > 1:  # 配列中のカウントが2以上なら以降の処理を省略
        continue
    for j in range(a_max // i + 1):  # Aiの倍数にインクリメント(配列の上限はa[-1])
        lst[i * j] += 1
    # lst[1::i] += 1
for i in a:
    if lst[i] == 1:
        cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
a_max = max(a)
lst = [0] * (a_max + 1)
cnt = 0
for i in a:
    if lst[i] > 1:  # 配列中のカウントが2以上なら以降の処理を省略
        continue
    for j in range(a_max // i + 1):  # Aiの倍数にインクリメント(配列の上限はa[-1])
        lst[i * j] += 1
    lst[1::i] += 1
for i in a:
    if lst[i] == 1:
        cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
a_max = max(a)
lst = [0] * (a_max + 1)
cnt = 0
for i in a:
    if lst[i] > 1:  # 配列中のカウントが2以上なら以降の処理を省略
        continue
    lst[1::i] += 1
    # for j in range(a_max // i + 1):  # Aiの倍数にインクリメント(配列の上限はa[-1])
    #     lst[i * j] += 1
for i in a:
    if lst[i] == 1:
        cnt += 1
print(cnt)
Problem p02646 (python)

Fixed submission:
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
if v <= w:
    print('NO')
else:
    if 1 <= (abs(b - a) / (v - w)) <= t:
        print('YES')
    else:
        print('NO')

Buggy submission (verdict: Runtime Error):
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
if v <= w:
    print('NO')
else:
    elif 1 <= ((b - a) / (v - w)) <= t:
        print('YES')
    else:
        print('NO')

Buggy submission (verdict: Runtime Error):
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
if v <= w:
    print('NO')
else:
    elif 1 <= ((b - a) / (v - w)) <= t:

        print('YES')
    else:
        print('NO')

Buggy submission (verdict: Runtime Error):
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
if v = w and a == b:
    print('YES')
elif v = w and a != b:
    print('NO')
elif a == b:
    print('YES')
else:
    if 0 <= ((b - a) / (v - w)) <= t:
        print('YES')
    else:
        print('NO')

Buggy submission (verdict: Runtime Error):
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
if v = w and a != b:
    print('NO')
else:
    if 0 <= ((b - a) / (v - w)) <= t:
        print('YES')
    else:
        print('NO')

Buggy submission (verdict: Runtime Error):
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
if 0 <= ((b - a) / (v - w)) <= t:
    print('YES')
else:
    print('NO')
Problem p02684 (python)

Fixed submission:
#!/usr/bin/env python3
def main():
    N, K = map(int, input().split())
    A = [int(x) - 1 for x in input().split()]

    way = []
    seen = [False for _ in [0] * (2 * 10 ** 5 + 1)]
    now = 0
    for _ in range(K):
        if seen[now]:
            loop_start = way.index(now)
            loop = way[loop_start:]
            K -= len(way[:loop_start])
            now = loop[K % len(loop)]
            break
        way.append(now)
        seen[now] = True
        now = A[now]
    print(now + 1)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
def main():
    N, K = map(int, input().split())
    A = [int(x) - 1 for x in input().split()]

    way = []
    now = 0
    for _ in range(K):
        if now in way:
            loop_start = way.index(now)
            loop = way[loop_start:]
            K -= len(way[:loop_start])
            now = loop[K - len(way[:loop_start]) % len(loop)]
            break
        way.append(now)
        now = A[now]
    print(now + 1)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
def main():
    N, K = map(int, input().split())
    A = [int(x) - 1 for x in input().split()]

    route = []
    now = 0
    for k in range(K):
        if now in route:
            break
        route.append(now)
        now = A[now]

    loop_start = route.index(now)
    K -= len(route[:loop_start])
    K %= len(route[loop_start:])
    for k in range(K):
        now = A[now]
    print(now + 1)


if __name__ == '__main__':
    main()
Problem p03162 (python)

Fixed submission:
def resolve():
    import sys
    import itertools
    import numpy as np

    readline = sys.stdin.readline

    N = int(readline())
    lst = [list(map(int, readline().split())) for _ in [0] * N]

    dp = np.full((N, 3), -1, np.int32)
    for i in range(N):
        for a, b in itertools.permutations([0, 1, 2], 2):
            if a == b:
                continue
            if i == 0:
                dp[i][a] = lst[i][a]
            else:
                dp[i][a] = max(dp[i][a], dp[i - 1][b] + lst[i][a])
    print(max(dp[-1]))

resolve()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
def main():
    import numpy as np

    N = int(input())
    happiness = [list(map(int, input().split())) for _ in range(N)]

    dp = np.zeros((N, 3), dtype=np.int64)
    dp[0] = happiness[0]
    for i in range(1, N):
        for a, yesterday in enumerate(dp[i - 1]):
            for b, today in enumerate(happiness[i]):
                if a == b:
                    continue
                dp[i][b] = max(dp[i][b], yesterday + today)
    print(max(dp[-1]))


if __name__ == '__main__':
    main()
Problem p03163 (python)

Fixed submission:
def resolve():
    import sys
    
    readline = sys.stdin.readline

    N, W = map(int, readline().split())
    lst = [list(map(int, readline().split())) for _ in [0] * N]
    
    dp = [[0] * (W + 1) for _ in [0] * N]

    for i in range(N):
        w, v = lst[i][0], lst[i][1]
        for sum_w in range(W + 1):
            if sum_w >= w:
                dp[i][sum_w] = max(dp[i][sum_w],
                                   dp[i - 1][sum_w - w] + v)
            dp[i][sum_w] = max(dp[i][sum_w], dp[i - 1][sum_w])
    print(max(dp[-1]))


resolve()

Buggy submission (verdict: Runtime Error):
def resolve():
    import sys
    import numpy as np
 
    readline = sys.stdin.readline
 
    N, W = map(int, readline().split())
    lst = [list(map(int, readline().split())) for _ in [0] * N]
    
    dp = np.zeros((N, W + 1), np.int64)
 
    for i in range(N):
        w, v = lst[i][0], lst[i][1]
        for sum_w in range(W + 1):
            if sum_w >= w:
                dp[i][sum_w] = max(dp[i][sum_w],
                                   dp[i - 1][sum_w - w] + v)
            dp[i][sum_w] = max(dp[i][sum_w], dp[i - 1][sum_w])
    print(max(dp[-1]))
 
 
resolve()
Problem p03471 (python)

Fixed submission:
# C - Otoshidama(https://atcoder.jp/contests/abc085/tasks/abc085_c)
n, y = map(int, input().split())
end = 0
for i in range(n + 1):
    if n < i:
        break
    for j in range(n + 1):
        if n - i - j < 0:
            break
        if 10000 * i + 5000 * j + 1000 * (n - i - j) == y:
            print(i, j, n - i - j)
            end += 1
    if end:
        break
if end == 0:
    print(-1, -1, -1)

Buggy submission (verdict: Runtime Error):
# C - Otoshidama(https://atcoder.jp/contests/abc085/tasks/abc085_c)
import sys

n, y = map(int, input().split())
for i in range(n):
    if n < i:
        break
    for j in range(n):
        if n - i - j < 0:
            break
        if 100_00 * i + 5000 * j + 1000 * (n - i - j) == y:
            print(i, j, n - i - j)
            sys.exit()
print(-1, -1, -1)
Problem p03545 (python)

Fixed submission:
lst = [int(a) for a in input()]
for bit in range(1 << len(lst)):
    sum = 0
    op_lst = []
    for i in range(len(lst)):
        if bit & (1 << i):
            sum += lst[i]
            op_lst.append('+')
        else:
            sum -= lst[i]
            op_lst.append('-')
    if sum == 7:
        print(lst[0], op_lst[1], lst[1], op_lst[2], lst[2], op_lst[3], lst[3], '=7', sep='')
        break

Buggy submission (verdict: Runtime Error):
    lst = [int(a) for a in input()]
    for bit in range(1 << len(lst)):
        sum = 0
        op_lst = []
        for i in range(len(lst)):
            if bit & (1 << i):
                sum += lst[i]
                op_lst.append('+')
            else:
                sum -= lst[i]
                op_lst.append('-')
        if sum == 7:
            print(lst[0], op_lst[1], lst[1], op_lst[2], lst[2], op_lst[3], lst[3], '=7', sep='')
            break
Problem p02972 (python)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
ans = []
temp = [0]*n
for i in range(n):
    x = n-i
    y = 0
    for j in range(n):
        if x*(j+2) <= n:
            if temp[x*(j+2)-1] == 1:
                y += 1
        else:
            break
    if not y%2 == a[x-1]:
        ans.append(x)
        temp[x-1] += 1
s = len(ans)
print(s)
if s > 0:
    print(" ".join([str(i) for i in ans]))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
ans = []
temp = [0]*80
for i in range(n):
    x = n-i
    y = 0
    for j in range(n):
        if x*(j+2) <= n:
            if temp[x*(j+2)-1] == 1:
                y += 1
        else:
            break
    if not y%2 == a[x-1]:
        ans.append(x)
        temp[x-1] += 1
s = len(ans)
print(s)
if s > 0:
    print(" ".join([str(i) for i in ans]))
Problem p03049 (python)

Fixed submission:
n = int(input())
s = []
for i in range(n):
  s.append(input())
     
ab = 0
ab_ = 0
a = 0
b = 0
for i in s:
  ab += i.count("AB")
  if i[0] == "B" and i[-1] == "A":
    ab_ += 1
  if i[0] == "B":
    b += 1
  if i[-1] == "A":
    a += 1
if ab_ == a and ab_ == b and not ab_ == 0:
  print(ab+ab_-1)
else:
  print(ab+min([a,b]))

Buggy submission (verdict: Runtime Error):
        n = int(input())
        s = []
        for i in range(n):
          s.append(input())
         
        ab = 0
        ab_ = 0
        a = 0
        b = 0
        for i in s:
          ab += i.count("AB")
          if i[0] == "B" and i[-1] == "A":
            ab_ += 1
          if i[0] == "B":
            b += 1
          if i[-1] == "A":
            a += 1
        if ab_ == a and ab_ == b and not ab_ == 0:
          print(ab+ab_-1)
        else:
          print(ab+min([a,b]))

Buggy submission (verdict: Runtime Error):
    n = int(input())
    s = []
    for i in range(n):
      s.append(input())
     
    ab = 0
    ab_ = 0
    a = 0
    b = 0
    for i in s:
      ab += i.count("AB")
      if i[0] == "B" and i[-1] == "A":
        ab_ += 1
      if i[0] == "B":
        b += 1
      if i[-1] == "A":
        a += 1
    if ab_ == a and ab_ == b and not ab_ == 0:
      print(ab+ab_-1)
    else:
      print(ab+min([a,b]))

Buggy submission (verdict: Runtime Error):
    n = int(input())
    s = []
    for i in range(n):
      s.append(input())
     
    ab = 0
    ab_ = 0
    a = 0
    b = 0
    for i in s:
      ab += i.count("AB")
      if i[0] == "B" and i[-1] == "A":
        ab_ += 1
      if i[0] == "B":
        b += 1
      if i[-1] == "A":
        a += 1
    if ab_ == a and ab_ == b and not ab_ == 0:
      print(ab+ab_-1)
    else:
      print(ab+min([a,b]))
Problem p03262 (python)

Fixed submission:
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i:
        divisors.append(n//i)
  divisors.append(n)
  return divisors
n,x=map(int,input().split())
y=list(map(int,input().split()))
y.append(x)
y.sort()
z=[]
for i in range(n):
  z.append(y[i+1]-y[i])
z.sort()
p=make_divisors(z[0])
a=[]
for i in p:
  for j in z:
    if j%i:
      break
  else:
    a.append(i)
print(max(a))

Buggy submission (verdict: Runtime Error):
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i:
        divisors.append(n//i)
  divisors.append(n)
  return divisors
n,x=map(int,input().split())
y=list(map(int,input().split()))
y.append(x)
y.sort()
z=[]
for i in range(n-1):
  z.append(y[i+1]-y[i])
z.sort()
p=make_divisors(z[0])
a=[]
for i in p:
  for j in z:
    if j%i:
      break
  else:
    a.append(i)
print(max(a))
Problem p03379 (python)

Fixed submission:
n=int(input())
x=list(map(int,input().split()))
s=sorted(x)
p,q=s[n//2-1],s[n//2]
for i in x:
  if i<=p:
    print(q)
  else:
    print(p)

Buggy submission (verdict: Runtime Error):
n=int(input())
x=list(map(int,input().split()))
s=sorted(x)
p,q=s[n//2],s[n//2+1]
for i in x:
  if i<=p:
    print(q)
  else:
    print(p)
Problem p03401 (python)

Fixed submission:
n=int(input())
a=[0]
a.extend(list(map(int,input().split())))
a.append(0)
s=0
for i in range(n+1):
  s+=abs(a[i+1]-a[i])
for i in range(1,n+1):
  print(s-abs(a[i+1]-a[i])-abs(a[i]-a[i-1])+abs(a[i+1]-a[i-1]))

Buggy submission (verdict: Runtime Error):
n=int(input())
a=[0]
a.extend(list(map(int,input().split())))
a.append([0])
s=0
for i in range(n+1):
  s+=abs(a[i+1]-a[i])
for i in range(1,n+1):
  print(s-abs(a[i+1]-a[i])-abs(a[i]-a[i-1])+abs(a[i+1]-a[i-1]))
Problem p03548 (python)

Fixed submission:
x,y,z=map(int,input().split())
print((x-z)//(y+z))

Buggy submission (verdict: Runtime Error):
x,y,z=map(int,input())
print((x-1)//(y+z))
Problem p03671 (python)

Fixed submission:
a,b,c = map(int,input().split())
print(min([a+b,b+c,c+a]))

Buggy submission (verdict: Runtime Error):
a,b,c = map(int,input(),split())
print(min([a+b,b+c,c+a]))
Problem p03680 (python)

Fixed submission:
n=int(input())
a=[int(input())-1 for i in range(n)]
c,x=1,0
for i in range(n):
  x=a[x]
  if x==1:
    print(i+1)
    break
else:
  print(-1)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=[(i,int(input())-1) for i in range(n)]
c,x=0,0
for i in range(n):
  x=a[x]
  if x==2:
    print(i+1)
    break
else:
  print(-1)
Problem p03699 (python)

Fixed submission:
n=int(input())
s=[int(input()) for _ in range(n)]
x=sum(s)
if x%10:
  print(x)
else:
  a=[]
  for i in s:
    if i%10:
      a.append(i)
  if a:
    print(x-min(a))
  else:
    print(0)

Buggy submission (verdict: Runtime Error):
n=int(input())
s=[int(input()) for _ in range(n)]
x=sum(s)
if x%10:
  print(x)
else:
  a=[]
  for i in s:
    if i%10:
      a.appned(i)
  if a:
    print(x-min(a))
  else:
    print(0)
Problem p03712 (python)

Fixed submission:
h,w=map(int,input().split())
print("#"*(w+2))
for _ in range(h):
  print("#"+input()+"#")
print("#"*(w+2))

Buggy submission (verdict: Runtime Error):
h,w=map(int,input())
print("#"*(w+2))
for _ in range(h):
  print("#"+input()+"#")
print("#"*(w+2))
Problem p03730 (python)

Fixed submission:
a,b,c=map(int,input().split())
a_=a
s=set()
while True:
  x=a_%b
  if x==c:
    print("YES")
    break
  elif x in s:
    print("NO")
    break
  else:
    s.add(x)
  a_+=a

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input())
s=set()
while True:
  x=a%b
  if x==c:
    print("YES")
    break
  elif x in s:
    print("NO")
    break
  else:
    s.add(x)
Problem p03731 (python)

Fixed submission:
n,t=map(int,input().split())
x=list(map(int,input().split()))
a=t
for i in range(n-1):
  a+=min(x[i+1]-x[i],t)
print(a)

Buggy submission (verdict: Runtime Error):
n,t=map(int,input().split())
x=list(map(int,input().split()))
a=t
for i in range(n-1):
  a.append(min(x[i+1]-x[i],t))
print(a)
Problem p03760 (python)

Fixed submission:
o,e=input(),input()
ans=[]
for i in range(len(o)):
  ans.append(o[i])
  if i<len(e):
    ans.append(e[i])
print("".join(ans))

Buggy submission (verdict: Runtime Error):
o,e=input(),input()
ans=[]
for i in range(len(o)):
  ans.append(o[i])
  if e:
    ans.append(e[i])
print("".join(ans))
Problem p03777 (python)

Fixed submission:
a,b=input().split()
if a==b:
  print("H")
else:
  print("D")

Buggy submission (verdict: Runtime Error):
if eval(input().replace(" ","==")):
  print("H")
else:
  print("D")
Problem p03944 (python)

Fixed submission:
w,h,n=map(int,input().split())
p,q,r,s=0,w,0,h
for i in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    p=max(p,x)
  elif a==2:
    q=min(q,x)
  elif a==3:
    r=max(r,y)
  elif a==4:
    s=min(s,y)
print(max(0,q-p)*max(0,s-r))

Buggy submission (verdict: Runtime Error):
w,h,n=map(int,input().split())
p,s,r,s=0,w,0,h
for i in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    p=max(p,x)
  elif a==2:
    q=min(q,x)
  elif a==3:
    r=max(r,y)
  elif a==4:
    s=min(s,y)
print((p-q)*(r-s))
Problem p03997 (python)

Fixed submission:
print((int(input())+int(input()))*(int(input())//2))

Buggy submission (verdict: Runtime Error):
print((int(input()+int(input())*(int(input())//2))
Problem p04012 (python)

Fixed submission:
from collections import defaultdict
s=list(input())
d=defaultdict(int)
for i in s:
  d[i]+=1
for i in d.values():
  if i%2:
    print("No")
    break
else:
  print("Yes")

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
s=list(input())
d=defaultdict(0)
for i in s:
  d[i]+=1
for i in d.values():
  if i%2:
    print("No")
    break
else:
  print("Yes")
Problem p02899 (python)

Fixed submission:
import numpy as np
 
N = int(input())
A = list(map(int, input().split()))
A = np.array(A)
 
AA = np.argsort(A) + 1

print(*AA)

Buggy submission (verdict: Runtime Error):
import numpy as np

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

AA = np.argsort(A) + 1

print(AA.to_list())
Problem p02957 (python)

Fixed submission:
A,B = map(int, raw_input().split(' '))


if (A+B) % 2 == 1:
      print("IMPOSSIBLE")
else:
      print((A+B)/2)

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

count = 0
zan_A_i = A[N]

for i in range(N):
    zan_B_i = B[N-1-i] - zan_A_i

    if zan_B_i < 0:
        #count += zan_B_i #A_i res
        zan_B_i = 0
    zan_A_i = A[N-1-i] - zan_B_i
    if zan_A_i < 0:
        count += zan_A_i 
        zan_A_i = 0

print(sum(B)+count)
Problem p02981 (python)

Fixed submission:
N, A, B = raw_input().split(' ')
 
print(min(int(A) * int(N), int(B)))

Buggy submission (verdict: Runtime Error):
N, A, B = int(raw_input().split(' '))

print(min(int(A) * int(N), int(B)))
Problem p03005 (python)

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


if K == 1:
      print(0)
else:
      print(N-K)

Buggy submission (verdict: Runtime Error):
N = int(raw_input())
K = int(raw_input())

if K ==1:
      print(0)
else:
      print(N-K)

Buggy submission (verdict: Runtime Error):
N = int(raw_input())
K = int(raw_input())

if K ==1:
      print(0)
else:
      print(N-K)
Problem p03068 (python)

Fixed submission:
N = int(raw_input())
S = list(raw_input())
K = int(raw_input())

hoge = S[K-1]

for i in range(N):

      if S[i] != hoge:
            S[i] = "*"

print("".join(S))

Buggy submission (verdict: Runtime Error):
N = int(raw_input())
S = list(raw_input())


hoge = S[K-1]

for i in range(N):
      if S[i] != hoge:
            S[i] = "*"

print("".join(S))
Problem p03836 (python)

Fixed submission:
sx, sy, tx, ty = map(int, input().split())

ans = ""
for j in range(ty-sy):
    ans += "U"
for i in range(tx-sx):
    ans += "R"
for j in range(ty-sy):
    ans += "D"
for i in range(tx-sx+1):
    ans += "L"
for j in range(ty-sy+1):
    ans += "U"
for i in range(tx-sx+1):
    ans += "R"
ans += "D"
ans += "R"
for j in range(ty-sy+1):
    ans += "D"
for i in range(tx-sx+1):
    ans += "L"
ans += "U"

print(ans)

Buggy submission (verdict: Runtime Error):
H,W,A,B = map(int, input().split())
MOD = 10 ** 9 + 7

N = H+W+1

def power(base, num):
    if num == 0:
        return 1
    elif num % 2==0:
        return power(base, num//2) **2 % MOD
    elif num==1:
        return base % MOD
    else:
        return power(base, num//2) **2 * base % MOD

fact = [0 for i in range(N)]
inv_fact = [0 for i in range(N)]

fact[0] = 1
for i in range(1, N):
    fact[i] = fact[i-1] * i % MOD
    
inv_fact[H+W] = power(fact[H+W], MOD-2)
for i in range(1, N):
    inv_fact[N-1-i] = inv_fact[N-i] * (N-i) % MOD

    
def comb(x,y):
    return (fact[x] * inv_fact[y])%MOD * inv_fact[x-y] % MOD

ans = 0

for i in range(1, W-B+1):
    ans += comb(H-A+B-2+i, H-A-1) * comb(A-1+W-B-i, A-1) % MOD
    ans %= MOD
print(ans%MOD)
Problem p03846 (python)

Fixed submission:
N = int(raw_input())
A=map(int, raw_input().split(' '))
A.sort()
flug = 0
if N % 2 == 0:
    for i in range(N):
        if not A[i] == 2*(i/2)+1:
            flug = 1
            break

else:
    for i in range(N):
        if i % 2 == 0:
            if not A[i] == i:
                flug =1
                break
        else:
            if not A[i] == i+1:
                flug = 1
                break
if flug == 0:
    print(pow(2, N/2))%(pow(10,9)+7)
else:
    print 0

Buggy submission (verdict: Runtime Error):
N = int(raw_input())
A=map(int, raw_input().split(' '))
A.sort()
flug = 0
if N % 2 == 0:
    for i in range(N):
        if not A[i] == 2*(i/2)+1:
          N = int(raw_input())
A=map(int, raw_input().split(' '))
A.sort()
flug = 0
if N % 2 == 0:
    for i in range(N):
        if not A[i] == 2*(i/2)+1:
            print 0
            flug = 1
            break
 
else:
    for i in range(N):
        if i % 2 == 0:
            if not A[i] == i:
                print 0
                flug =1
                break
        else:
            if not A[i] == i+1:
                print 0
                flug = 1
                break
if flug == 0:
    print(pow(2, N/2))
            flug = 1
            break
 
else:
    for i in range(N):
        if i % 2 == 0:
            if not A[i] == i:
           
                flug =1
                break
        else:
            if not A[i] == i+1:
                
                flug = 1
                break
if flug == 0:
    print(pow(2, N/2))
else:
    print 0
Problem p03854 (python)

Fixed submission:
s = input()

ans = 1
while(len(s)>0):
    if s[-5:] == "dream" or s[-5:] == "erase":
        s = s[:-5]
    elif s[-7:] == "dreamer":
        s = s[:-7]
    elif  s[-6:] == "eraser":
        s = s[:-6]
    else:
        s = ""
        ans = 0
if ans > 0:
    print("YES")
else:    
    print("NO")

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

while(len(s)>0):
    if s[-5:] == dream or s[-5:] == erase:
        s = s[:-5]
    elif s[-7:] == dreamer:
        s = s[:-7]
    elif  s[-6:] == eraser:
        s = s[:-6]
    else:
        s = ""
if len(s) > 0:
    print("Yes")
else:    
    print("No")
Problem p03962 (python)

Fixed submission:
a,b,c = raw_input().split()
a=int(a)
b=int(b)
c=int(c)
A = {a:1,b:1,c:1}

print len(A)

Buggy submission (verdict: Runtime Error):
a,b,c = raw_input().split()

A = {a:1,b:1,c:1}
print len(A)