Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
#substring列挙したらTLE(部分点)
s = input()
k = int(input())
s_set_sort = sorted(set(s))

li = []
count = 0
while count < k:
    s_head = s_set_sort.pop(0)
    for i in range(len(s)):
        if s[i] == s_head:
            count2 = 0
            for j in range(len(s)-i):
                if s[i:i+j+1] not in li:
                    count += 1
                    count2 += 1
                    li.append(s[i:i+j+1])
                    if count2 >= k:
                        break
li.sort()
print(li[k-1])

Fixed submission:
#substring列挙したらTLE(部分点)
s = input()
k = int(input())
s_set_sort = sorted(set(s))

li = []
count = 0
while count < k:
    s_head = s_set_sort.pop(0)
    for i in range(len(s)):
        if s[i] == s_head:
            for j in range(k):
                if s[i:i+j+1] not in li:
                    count += 1
                    li.append(s[i:i+j+1])
li.sort()
print(li[k-1])

Buggy python submission (verdict: Time Limit Exceeded):
#substring列挙したらTLE(部分点)
s = input()
k = int(input())
s_set_sort = sorted(set(s))

li = []
count = 0
while count < k:
    s_head = s_set_sort.pop(0)
    for i in range(len(s)):
        if s[i] == s_head:
            for j in range(len(s)-i):
                if s[i:i+j+1] not in li:
                    count += 1
                    li.append(s[i:i+j+1])
li.sort()
print(li[k-1])

Fixed submission:
#substring列挙したらTLE(部分点)
s = input()
k = int(input())
s_set_sort = sorted(set(s))

li = []
count = 0
while count < k:
    s_head = s_set_sort.pop(0)
    for i in range(len(s)):
        if s[i] == s_head:
            for j in range(k):
                if s[i:i+j+1] not in li:
                    count += 1
                    li.append(s[i:i+j+1])
li.sort()
print(li[k-1])
Buggy python submission (verdict: Time Limit Exceeded):
import copy
n = int(input())
x = list(map(int,input().split()))
for i in range(n):
    xi = copy.deepcopy(x)
    xi.pop(i)
    xi = sorted(xi,reverse=True)
    print(xi[(n-2)//2])

Fixed submission:
n = int(input())
x = list(map(int,input().split()))
x_sort = sorted(x)
med_l = x_sort[n//2-1]
med_r = x_sort[n//2]
for i in range(n):
    x[i]
    if x[i] <= med_l:
        print(med_r)
    else:
        print(med_l)
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())print(3)
s=input()
f=1
for i in range(a):
   if s[i]=='-':
      f=0
if s[a]!='-':
   f=0
for j in range(b):
   if s[a+1+j]=='-':
      f=0
if f:
   print('Yes')
else:
   print('No')

Fixed submission:
a,b=map(int,input().split())
s=input()
f=1
for i in range(a):
   if s[i]=='-':
      f=0
if s[a]!='-':
   f=0
for j in range(b):
   if s[a+1+j]=='-':
      f=0
if f:
   print('Yes')
else:
   print('No')
Buggy python submission (verdict: Time Limit Exceeded):
def Lucas(n):
	if n==0:
		return 2
	elif n==1:
		return 1
	else:
		return Lucas(n-1)+Lucas(n-2)

print(Lucas(int(input())))

Fixed submission:
dp=[0 for _ in range(88)]

dp[0]=2
dp[1]=1

for i in range(88):
	if i>1:
		dp[i]=dp[i-1]+dp[i-2]

print(dp[int(input())])
Buggy python submission (verdict: Runtime Error):
x, a, b - map(int,input().split())
if abs(x-a)<abs(x-b):
    print(a)
else:
    print(b)

Fixed submission:
x, a, b = map(int,input().split())
if abs(x-a)<abs(x-b):
    print('A')
else:
    print('B')
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
flag=False
one = []
enu = []
for i in range(m):
  a,b=map(int,input().split())
  if a==1:
    one.append(b)
  elif b==n:
    enu.append(a)

for i in one:
  if i in enu:
    flag=True
    break

if flag: print('POSSIBLE')
else: print('IMPOSSIBLE')

Fixed submission:
n,m=map(int,input().split())
li = []
for i in range(m):
  a,b=map(int,input().split())
  if a==1:
    li.append(b)
  elif b==n:
    li.append(a)

if len(set(li))==len(li): print('IMPOSSIBLE')
else: print('POSSIBLE')

Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
flag=False
one = []
enu = []
for i in range(m):
  a,b=map(int,input().split())
  if a==1:
    one.append(b)
  elif b==n:
    enu.append(a)

for i in one:
  if i in enu:
    flag=True

if flag: print('POSSIBLE')
else: print('IMPOSSIBLE')

Fixed submission:
n,m=map(int,input().split())
li = []
for i in range(m):
  a,b=map(int,input().split())
  if a==1:
    li.append(b)
  elif b==n:
    li.append(a)

if len(set(li))==len(li): print('IMPOSSIBLE')
else: print('POSSIBLE')

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
flag=false
one = []
enu = []
for i in range(m):
  a,b=map(int,input().split())
  if a==1:
    one.append(b)
  elif b==n:
    enu.append(a)

for i in one:
  if i in enu:
    flag=true

if flag: print('POSSIBLE')
else: print('IMPOSSIBLE')
    

Fixed submission:
n,m=map(int,input().split())
li = []
for i in range(m):
  a,b=map(int,input().split())
  if a==1:
    li.append(b)
  elif b==n:
    li.append(a)

if len(set(li))==len(li): print('IMPOSSIBLE')
else: print('POSSIBLE')
Buggy python submission (verdict: Runtime Error):
=int(input())
a=[]
for i in range(n):
    ai=int(input())
    a.append(ai)
finish=False
for i in range(n):
    if i==0:
        next=a[a[0]-1]
    else:
        next=a[next-1]
    if next==2:
        print(i+2)
        finish=True
        break
if not finish:
    print(-1)

Fixed submission:
n=int(input())
a=[]
for i in range(n):
    ai=int(input())
    a.append(ai)
finish=False
for i in range(n):
    if a[0]==2:
        print(1)
        finish=True
        break
    if i==0:
        next=a[a[0]-1]
    else:
        next=a[next-1]
    if next==2:
        print(i+2)
        finish=True
        break
if not finish:
    print(-1)
Buggy python submission (verdict: Runtime Error):
a,b,c=mqp(int,input().split())
if a<=c<=b:
  print('Yes')
else:
  print('No')

Fixed submission:
a,b,c=map(int,input().split())
if a<=c<=b:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
print(sum(x for x in range(1,n)))

Fixed submission:
n = int(input())
print((n*(n-1))//2)
Buggy python submission (verdict: Time Limit Exceeded):
from queue import Queue

n, q = map(int, input().split())
adj = [[] for _ in range(n + 1)]
lazy = [0] * (n + 1)

for _ in range(n - 1):
    u, v = map(int, input().split())
    adj[u].append(v)
    adj[v].append(u)

for _ in range(q):
    p, x = map(int, input().split())
    lazy[p] += x

qu = Queue()
qu.put((1, 0))
while not qu.empty():
    pair = qu.get()
    u = pair[0]
    for v in adj[u]:
        if v == pair[1]: continue
        lazy[v] += lazy[u]
        qu.put((v, u))

for i in range(1, n + 1):
    print(str(lazy[i]), end=' ')
 

Fixed submission:
from queue import Queue
from sys import stdin, stdout
input = stdin.readline
print = stdout.write

n, q = map(int, input().split())
adj = [[] for _ in range(n + 1)]
lazy = [0] * (n + 1)

for _ in range(n - 1):
    u, v = map(int, input().split())
    adj[u].append(v)
    adj[v].append(u)

for _ in range(q):
    p, x = map(int, input().split())
    lazy[p] += x

qu = Queue()
qu.put((1, 0))
while not qu.empty():
    pair = qu.get()
    u = pair[0]
    for v in adj[u]:
        if v == pair[1]: continue
        lazy[v] += lazy[u]
        qu.put((v, u))

for i in range(1, n + 1):
    print(str(lazy[i]) + ' ')
Buggy python submission (verdict: Runtime Error):
from sys import stdin,stdout
inp = stdin.readline
out = stdout.write
n = int(inp())
dp = [[0 for _ in range(3)] for _ in range(n)]
dp[0] = map(int,inp().split())
for i in range(1,n):
    a,b,c = map(int,inp().split())
    dp[i][0] = max(dp[i][1]+b[i],dp[i][2]+c[i])
    dp[i][1] = max(dp[i][0]+a[i],dp[i][2]+c[i])
    dp[i][2] = max(dp[i][1]+b[i],dp[i][0]+a[i])
out(str(max(dp[n-1])))

Fixed submission:
from sys import stdin,stdout
inp = stdin.readline
out = stdout.write
n = int(inp())
dp = [[0 for _ in range(3)] for _ in range(n)]
dp[0] = list(map(int,inp().split()))
for i in range(1,n):
    a,b,c = map(int,inp().split())
    dp[i][0] = max(dp[i-1][1],dp[i-1][2])+a
    dp[i][1] = max(dp[i-1][0],dp[i-1][2])+b
    dp[i][2] = max(dp[i-1][1],dp[i-1][0])+c
out(str(max(dp[n-1])))
Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == '__main__':
    n, x, y = map(int, input().split())
    x, y = x - 1, y - 1
    k = [0] * (n - 1)
    for i in range(n):
        tmp = 0
        for j in range(i):
            if i == j:
                continue
            t = min(abs(i - j), abs(i - x) + 1 + abs(y - j), abs(i - y) + 1 + abs(x - j))
            k[t - 1] += 1
    for i in k:
        print(i)


Fixed submission:
if __name__ == '__main__':
    n, x, y = map(int, input().split())
    x, y = x - 1, y - 1
    k = [0] * (n - 1)
    for i in range(n):
        tmp = 0
        for j in range(i):
            if i == j:
                continue
            t = min(abs(i - j), abs(i - x) + 1 + abs(y - j), abs(i - y) + 1 + abs(x - j))
            k[t - 1] += 1
    for i in k:
        print(i)
Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == '__main__':
    def comb(n, k):
        a = n * (n - 1)
        return a // 2
    n = int(input())
    a = list(map(int, input().split()))
    count = {}
    for i in a:
        count[i] = count.get(i, 0) + 1

    for i in a:
        ans = 0
        for k, v in count.items():
            if k == i:
                ans += comb(v - 1, 2)
            else:
                ans += comb(v, 2)
        print(ans)



Fixed submission:
if __name__ == '__main__':
    def comb(n, k):
        a = n * (n - 1)
        return a // 2
    n = int(input())
    a = list(map(int, input().split()))

    count = {}
    # 10 ** 5
    for i in a:
        count[i] = count.get(i, 0) + 1

    all_sum = 0
    # 10 ** 5
    for i in count.values():
        all_sum += comb(i, 2)

    # 10 ** 5
    for i in a:
        ans = all_sum - comb(count[i], 2) + comb(count[i] - 1, 2)
        print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 9 + 7)
ans = 10 ** 9 + 7
def solve(x, y, cnt):
    global ans
    if x == w - 1 and y == h - 1:
        if field[y][x] == "#":
            cnt += 1
        ans = min(ans, cnt)
        return

    if 0 <= x < w and 0 <= y < h:
        if field[y][x] == "#":
            solve(x + 1, y, cnt + 1)
            solve(x, y + 1, cnt + 1)
        else:
            solve(x + 1, y, cnt)
            solve(x, y + 1, cnt)
    else:
        return

h, w = map(int, input().split())
field = []

for i in range(h):
    field.append(list(input()))

solve(0, 0, 0)
print(ans)


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

for i in range(h):
    field.append(list(input()))

dp = [[0 for i in range(w)] for j in range(h)]

for i in range(1, w):
    if field[0][i - 1] == field[0][i]:
        dp[0][i] = dp[0][i - 1] 

    else:
        if field[0][i - 1] == "." and field[0][i] == "#":
            dp[0][i] = dp[0][i - 1] + 1
        else:
            dp[0][i] = dp[0][i - 1]

for i in range(1, h):
    if field[i][0] == field[i - 1][0]:
        dp[i][0] = dp[i - 1][0]
    else:
        if field[i - 1][0] == "." and field[i][0] == "#":
            dp[i][0] = dp[i - 1][0] + 1
        else:
            dp[i][0] = dp[i - 1][0]

for y in range(1, h):
    for x in range(1, w):
        dp[y][x] = min(dp[y - 1][x] + (1 if field[y][x] != field[y - 1][x] and field[y - 1][x] == "." else 0), dp[y][x - 1] + (1 if field[y][x] != field[y][x - 1] and field[y][x - 1] == "."  else 0))

print(dp[h - 1][w - 1] + (1 if field[0][0] == "#" else 0))
Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
q = int(input())

rev = 0

for i in range(q):
    t = list(input().split())
    if t == ['1']:
        rev += 1
        continue
    if t[1] == '1':
        if rev % 2 == 0:
            s.insert(0, t[2])
        else:
            s.append(t[2])
    else:
        if rev % 2 == 0:
            s.append(t[2])
        else:
            s.insert(0, t[2])
if rev % 2 != 0:
    s.reverse()

print(''.join(s))


Fixed submission:
from collections import deque
s = list(input())
q = int(input())

s = deque(s)
rev = 0

for i in range(q):
    t = list(input().split())
    if len(t) == 1:
        rev += 1
        continue
    if t[1] == '1':
        if rev % 2 == 0:
            s.appendleft(t[2])
        else:
            s.append(t[2])
    else:
        if rev % 2 == 0:
            s.append(t[2])
        else:
            s.appendleft(t[2])
if rev % 2 != 0:
    s.reverse()

print(''.join(s))

Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
q = int(input())

rev = 0

for i in range(q):
    t = list(input().split())
    if t == ['1']:
        rev += 1
        continue
    if t[1] == '1':
        if rev % 2 == 0:
            s = [t[2]] + s
        else:
            s.append(t[2])

    else:
        if rev % 2 == 0:
            s.append(t[2])
        else:
            s = [t[2]] + s
if rev % 2 != 0:
    s.reverse()

print(''.join(s))


Fixed submission:
from collections import deque
s = list(input())
q = int(input())

s = deque(s)
rev = 0

for i in range(q):
    t = list(input().split())
    if len(t) == 1:
        rev += 1
        continue
    if t[1] == '1':
        if rev % 2 == 0:
            s.appendleft(t[2])
        else:
            s.append(t[2])
    else:
        if rev % 2 == 0:
            s.append(t[2])
        else:
            s.appendleft(t[2])
if rev % 2 != 0:
    s.reverse()

print(''.join(s))
Buggy python submission (verdict: Time Limit Exceeded):
import bisect

if __name__ == '__main__':
    def check(mid):
        count = 0
        for i in range(n):
            position = bisect.bisect_left(a, (mid - a[i]))
            count += (n - position)
        return count < m


    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort()
    # 左手でa[i]の手を握るとする
    # a[i]を持っているときに和がx未満になるときの右手の数字はx - a[i]未満の数字である
    # lower_bound
    # この値をNから引くことで和がx以上になるペアの個数がわかる
    # この値の合計がM未満になればそこが最大の幸福度である

    # 要するに、M個のペアを作るためには最大いくらの和を採用できるかを二分探索する

    ng = 0
    ok = 10 ** 5 * (n + 1)

    while 1 < abs(ok - ng):
        # mid -> boundとなる和。これより大きい和をもつペアをM個作れるかを判定する
        mid = (ok + ng) // 2
        c = check(mid)
        # ペアの個数がmより小さい場合は、okの範囲を下げる
        if c:
            ok = mid
        # そうでない場合はまだ余裕があるので、ngをあげる
        else:
            ng = mid

    # ここが終了した時点でngにはm個以上のペアを作るための最大のboundが入っている

    # upper_boundで左手にa[i]がある場合のng - a[i]の数を判定する
    # ansに求めた数 * a[i] + 右手に持つ幸福度の総和を足す
    # mから求めた数を引く

    ans = 0
    sum_array = [0] * (n + 1)
    # 累積和で高速化をする
    # (x + a[i]) + (x + a[i + 1) + (x + a[i + 2]).....
    #   -> (x * 個数) * (a[i] + a[i + 1] + a[i + 2])

    for i in range(n):
        sum_array[i + 1] = sum_array[i] + a[i]
    for i in range(n):
        position = bisect.bisect_right(a, ng - a[i])
        ans += (n - position) * a[i] + sum_array[n] - sum_array[position]
        m -= (n - position)

    ans += ng * m
    print(ans)


Fixed submission:
import bisect

if __name__ == '__main__':
    def check(mid):
        count = 0
        for i in range(n):
            position = bisect.bisect_left(a, (mid - a[i]))
            count += (n - position)
        return count < m


    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort()
    # 左手でa[i]の手を握るとする
    # a[i]を持っているときに和がx未満になるときの右手の数字はx - a[i]未満の数字である
    # lower_bound
    # この値をNから引くことで和がx以上になるペアの個数がわかる
    # この値の合計がM未満になればそこが最大の幸福度である

    # 要するに、M個のペアを作るためには最大いくらの和を採用できるかを二分探索する

    ng = 0
    ok = 10 ** 5 * (n + 1)

    while 1 < abs(ok - ng):
        # mid -> boundとなる和。これより大きい和をもつペアをM個作れるかを判定する
        mid = (ok + ng) // 2
        c = check(mid)
        # ペアの個数がmより小さい場合は、okの範囲を下げる
        if c:
            ok = mid
        # そうでない場合はまだ余裕があるので、ngをあげる
        else:
            ng = mid

    # ここが終了した時点でngにはm個以上のペアを作るための最大のboundが入っている

    # upper_boundで左手にa[i]がある場合のng - a[i]の数を判定する
    # ansに求めた数 * a[i] + 右手に持つ幸福度の総和を足す
    # mから求めた数を引く

    ans = 0
    sum_array = [0] * (n + 1)
    # 累積和で高速化をする
    # (x + a[i]) + (x + a[i + 1) + (x + a[i + 2]).....
    #   -> (x * 個数) * (a[i] + a[i + 1] + a[i + 2])

    for i in range(n):
        sum_array[i + 1] = sum_array[i] + a[i]
    for i in range(n):
        position = bisect.bisect_right(a, ng - a[i])
        ans += (n - position) * a[i] + sum_array[n] - sum_array[position]
        m -= (n - position)

    ans += ng * m
    print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
ans = 0
now = 1
for i in a:
    if i == now:
        now += 1
print(-1 if now == 1 else n - now + 1)
index197511@index197511-VirtualBox:~/comp

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
ans = 0
now = 1
for i in a:
    if i == now:
        now += 1
print(-1 if now == 1 else n - now + 1)
Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == '__main__':
    MOD = 10 ** 9 + 7
    n = int(input())
    a = list(map(int, input().split()))
    ans = 0
    for i in range(60):
        flag1 = sum([1 for x in a if x & (1 << i)])
        flag0 = n - flag1
        ans += (1 << i) * (flag1 * flag0)
        ans %= MOD
    print(ans)


Fixed submission:
if __name__ == '__main__':
    MOD = 10 ** 9 + 7
    n = int(input())
    a = list(map(int, input().split()))
    res = 0
    two_factor = 1

    for d in range(60):
        even, odd = 0, 0
        for i in range(n):
            if a[i] & (1 << d):
                odd += 1
            else:
                even += 1
        add = (odd * even) % MOD * two_factor % MOD
        res = (res + add) % MOD
        two_factor = two_factor * 2 % MOD

    print(res)

Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == '__main__':
    MOD = 10 ** 9 + 7
    n = int(input())
    a = list(map(int, input().split()))
    ans = 0
    for i in range(60):
        flag1 = sum([1 for x in a if x & (1 << i)])
        flag0 = sum([1 for x in a if not (x & (1 << i))])
        ans += (1 << i) * (flag1 * flag0)
        ans %= MOD
    print(ans)


Fixed submission:
if __name__ == '__main__':
    MOD = 10 ** 9 + 7
    n = int(input())
    a = list(map(int, input().split()))
    res = 0
    two_factor = 1

    for d in range(60):
        even, odd = 0, 0
        for i in range(n):
            if a[i] & (1 << d):
                odd += 1
            else:
                even += 1
        add = (odd * even) % MOD * two_factor % MOD
        res = (res + add) % MOD
        two_factor = two_factor * 2 % MOD

    print(res)

Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == '__main__':
    MOD = 10 ** 9 + 7
    n = int(input())
    a = list(map(int, input().split()))
    res = 0
    two_factor = 1

    for d in range(60):
        even, odd = 0, 0
        for i in range(n):
            if a[i] & (1 << d):
                odd += 1
            else:
                even += 1
        add = (odd * even) % MOD * two_factor % MOD
        res = (res + add) % MOD
        two_factor = two_factor * 2 % MOD

    print(res)


Fixed submission:
if __name__ == '__main__':
    MOD = 10 ** 9 + 7
    n = int(input())
    a = list(map(int, input().split()))
    res = 0
    two_factor = 1

    for d in range(60):
        even, odd = 0, 0
        for i in range(n):
            if a[i] & (1 << d):
                odd += 1
            else:
                even += 1
        add = (odd * even) % MOD * two_factor % MOD
        res = (res + add) % MOD
        two_factor = two_factor * 2 % MOD

    print(res)
Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == '__main__':
    n = int(input())
    s = list(input())
    ans = 0
    for i in range(10):
        for j in range(10):
            for k in range(10):
                pin = str(i) + str(j) + str(k)
                t = 0
                for x in s:
                    if pin[t] == x:
                        t += 1
                    if t == 3:
                        ans += 1
                        break
    print(ans)


Fixed submission:
n = int(input())
s = list(input())
ans = 0
for i in range(0, 10):
    for j in range(0, 10):
        for k in range(0, 10):
            t = str(i) + str(j) + str(k)
            tmp = []
            for z in s:
                if t[len(tmp)] == z:
                    tmp.append(0)
                if len(tmp) == 3:
                    ans += 1
                    break
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = list(input())
ans = 0
for i in range(0, 10):
    for j in range(0, 10):
        for k in range(0, 10):
            t = str(i) + str(j) + str(k)
            tmp = []
            for z in s:
                if t[len(tmp)] == z:
                    tmp.append(0)
                if len(tmp) == 3:
                    ans += 1
                    break
print(ans)


Fixed submission:
n = int(input())
s = list(input())
ans = 0
for i in range(0, 10):
    for j in range(0, 10):
        for k in range(0, 10):
            t = str(i) + str(j) + str(k)
            tmp = []
            for z in s:
                if t[len(tmp)] == z:
                    tmp.append(0)
                if len(tmp) == 3:
                    ans += 1
                    break
print(ans)
Buggy python submission (verdict: Runtime Error):
from functools import reduce


def modcombination(n, k, mod):
    # nCk % mod
    num = reduce(lambda x, y: x * y % mod, range(n, n - k, -1))
    den = reduce(lambda x, y: x * y % mod, range(1, k + 1))
    return num * pow(den, mod - 2, mod) % mod


if __name__ == '__main__':
    MOD = 10 ** 9 + 7
    x, y = map(int, input().split())
    if (x + y) % 3 != 0:
        print(0)
        exit(0)

    m = (2 * x - y) // 3
    n = x - (2 * m)
    if n < 0 or m < 0:
        print(0)
        exit(0)
    print(modcombination(n + m, n, MOD) % MOD)


Fixed submission:
from functools import reduce


def modcombination(n, k, mod):
    # nCk % mod
    num = reduce(lambda x, y: x * y % mod, range(n, n - k, -1))
    den = reduce(lambda x, y: x * y % mod, range(1, k + 1))
    return num * pow(den, mod - 2, mod) % mod


if __name__ == '__main__':
    MOD = 10 ** 9 + 7
    x, y = map(int, input().split())
    if (x + y) % 3 != 0:
        print(0)
        exit(0)

    m = (2 * x - y) // 3
    n = x - (2 * m)
    if n < 0 or m < 0:
        print(0)
        exit(0)
    if n == 0 or m == 0:
        print(1)
        exit(0)
    print(modcombination(n + m, n, MOD) % MOD)
Buggy python submission (verdict: Runtime Error):
if __name__ == '__main__':
    n = int(input())
    print(sum(list(range(1, n + 1))) - n)

Fixed submission:
if __name__ == '__main__':
    n = int(input())
    t = (1 + n) * n // 2
    print(t - n)

Buggy python submission (verdict: Time Limit Exceeded):
if __name__ == '__main__':
    n = int(input())
    r = [n]
    for i in range(1, n):
        r.append(i)
    ans = 0
    for i in range(n):
        ans += r[i] % (i + 1)
    print(ans)

Fixed submission:
if __name__ == '__main__':
    n = int(input())
    t = (1 + n) * n // 2
    print(t - n)
Buggy python submission (verdict: Runtime Error):
from scipy.special import comb
n = int(input())
s = sorted([''.join(sorted(list(input()))) for i in range(n)])
ans = 0
tmp = 1
for i in range(1, n):
    if s[i] == s[i - 1]:
        tmp += 1
    else:
        ans += comb(tmp, 2, exact = True)
        tmp = 1
ans += comb(tmp, 2, exact = True)
print(ans)


Fixed submission:
from scipy.misc import comb
n = int(input())
s = sorted([''.join(sorted(list(input()))) for i in range(n)])
ans = 0
tmp = 1
for i in range(1, n):
    if s[i] == s[i - 1]:
        tmp += 1
    else:
        ans += comb(tmp, 2, exact = True)
        tmp = 1
ans += comb(tmp, 2, exact = True)
print(ans)