Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from sys import stdin
import string
import heapq
h,w = map(int,stdin.readline().rstrip().split())
s = ""
for i in range(h):
    s += stdin.readline().rstrip()
task_4 = (h//2)*(w//2)
task_2 = (h%2)*(h//2)+(w%2)*(w//2)
task_1 = (h%2)*(w%2)
alpha = string.ascii_lowercase
li = [-s.count(i) for i in alpha if s.count(i) != 0]
heapq.heapify(li)
for i in range(task_4):
    if li[0] <= -4:
        k = heapq.heappop(li)
        if k+4 == 0:
            continue
        else:
            heapq.heappush(li,k+4)
    else:
        print("No")
        exit()
for i in range(task_2):
    if li[0] <= -2:
        k = heapq.heappop(li)
        if k+2 == 0:
            continue
        else:
            heapq.heappush(li,k+2)
    else:
        print("No")
        exit()
for i in range(task_1):
    if li[0] <= -1:
        k = heapq.heappop(li)
        if k+1 == 0:
            continue
        else:
            heapq.heappush(li,k+1)
    else:
        print("No")
        exit()
print("Yes")

Fixed submission:
from sys import stdin
import string
import heapq
h,w = map(int,stdin.readline().rstrip().split())
s = ""
for i in range(h):
    s += stdin.readline().rstrip()
task_4 = (h//2)*(w//2)
task_2 = (h%2)*(w//2)+(w%2)*(h//2)
task_1 = (h%2)*(w%2)
alpha = string.ascii_lowercase
li = [-s.count(i) for i in alpha if s.count(i) != 0]
heapq.heapify(li)
for i in range(task_4):
    if li[0] <= -4:
        k = heapq.heappop(li)
        if k+4 == 0:
            continue
        else:
            heapq.heappush(li,k+4)
    else:
        print("No")
        exit()
for i in range(task_2):
    if li[0] <= -2:
        k = heapq.heappop(li)
        if k+2 == 0:
            continue
        else:
            heapq.heappush(li,k+2)
    else:
        print("No")
        exit()
for i in range(task_1):
    if li[0] <= -1:
        k = heapq.heappop(li)
        if k+1 == 0:
            continue
        else:
            heapq.heappush(li,k+1)
    else:
        print("No")
        exit()
print("Yes")
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import permutations

N,M,R = map(int,input().split())
r = list(map(int,input().split()))

li = [[0 for i in range(N+1)]for j in range(N+1)]

for _ in range(M):
    a,b,c = map(int,input().split())
    li[a][b] = c
    li[b][a] = c

def all_pairs_shortest_paths(W):
    inf = 10**18
    # 頂点の数
    n = len(W)
    # 結果を格納する行列を用意する
    res = [[0] * n for i in range(n)]
    # 用意した行列を初期化する
    for i in range(n):
        for j in range(i, n):
            if i == j:
                val = 0
            elif W[i][j]:
                val = W[i][j]
            else:
                val = inf
            res[i][j] = res[j][i] = val
    # 動的計画法ですべての超点間の最短距離を求める
    for k in range(n):
        for u in range(n):
            for v in range(n):
                res[u][v] = min(res[u][v], res[u][k] + res[k][v])
    return res

lin = all_pairs_shortest_paths(li)

pos = list(permutations(r))

mi = 10**18

for i in pos:
    l = 0
    for j in range(1,R):
        l += lin[i[j-1]][i[j]]
    mi = min(mi,l)

print(mi)

Fixed submission:
from itertools import permutations

N,M,R = map(int,input().split())
r = list(map(int,input().split()))

li = [[0 for i in range(N+1)]for j in range(N+1)]

for _ in range(M):
    a,b,c = map(int,input().split())
    li[a][b] = c
    li[b][a] = c

def all_pairs_shortest_paths(W):
    inf = 10**18
    # 頂点の数
    n = len(W)
    # 結果を格納する行列を用意する
    res = [[0] * n for i in range(n)]
    # 用意した行列を初期化する
    for i in range(n):
        for j in range(i, n):
            if i == j:
                val = 0
            elif W[i][j]:
                val = W[i][j]
            else:
                val = inf
            res[i][j] = res[j][i] = val
    # 動的計画法ですべての超点間の最短距離を求める
    for k in range(n):
        for u in range(n):
            for v in range(n):
                res[u][v] = min(res[u][v], res[u][k] + res[k][v])
    return res

lin = all_pairs_shortest_paths(li)

pos = list(permutations(r))

mi = 10**18

for i in pos:
    l = 0
    for j in range(1,R):
        l += lin[i[j-1]][i[j]]
    mi = min(mi,l)

print(mi)
Buggy python submission (verdict: Runtime Error):
from sys import stdin
import math
n,k = [int(x) for x in stdin.readline().rstrip().split()]
li = list(map(int,stdin.readline().rstrip().split()))
if k > li[0]:
    print("IMPOSSIBLE")
    exit()
def gcd_all(list):
    return gcd_all([math.gcd(*list[:2])] + list[2:]) if len(list) > 1 else list[0]
gcd = gcd_all(li)
if k%gcd != 0:
    print("IMPOSSIBLE")
    exit()
print("POSSIBLE")

Fixed submission:
from sys import stdin
import fractions
n,k = [int(x) for x in stdin.readline().rstrip().split()]
li = list(map(int,stdin.readline().rstrip().split()))
li.sort()
if k > li[-1]:
    print("IMPOSSIBLE")
    exit()
gcd = li[0] 
for i in range(n-1):
    gcd = fractions.gcd(gcd,li[i+1])
if k%gcd != 0:
    print("IMPOSSIBLE")
    exit()
print("POSSIBLE")
Buggy python submission (verdict: Runtime Error):
from sys import stdin
from math import factorial

n,p = [int(x) for x in stdin.readline().rstrip().split()]
li = list(map(int,stdin.readline().rstrip().split()))

def combinations_count(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))

guusu = 0
kisuu = 0

for i in li:
    if i%2 == 0:
        guusu += 1
    else:
        kisuu += 1

point = 0

if p == 0:
    for i in range(guusu//2+1):
        point += combinations_count(guusu,i*2)
    for j in range(kisuu//2+1):
        point += combinations_count(kisuu,i*2)
if p == 1:
    for i in range(guusu+1):
        for j in range(kisuu//2 if kisuu%2 == 0 else kisuu//2+1):
            point += combinations_count(guusu,i)*combinations_count(kisuu,j*2+1)

print(point)

Fixed submission:
from sys import stdin

n,p = [int(x) for x in stdin.readline().rstrip().split()]
li = list(map(int,stdin.readline().rstrip().split()))

if all(i%2 == 0 for i in li):
    if p == 0:
        print(2**n)
    else:
        print(0)
else:
    print(2**(n-1))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
path = []

for i in range(n):
    x,y = map(int,input().split())
    path.append((x,y,i))

x_li = sorted(path)
y_li = sorted(path,key=lambda x:(x[1]))

inf = 10**18
cost = [[inf for i in range(n)]for j in range(n)]

for i in range(1,n):
    cost[x_li[i][2]][x_li[i-1][2]] = min(abs(x_li[i][0]-x_li[i-1][0]),abs(x_li[i][1]-x_li[i-1][1]))
    cost[x_li[i-1][2]][x_li[i][2]] = min(abs(x_li[i][0]-x_li[i-1][0]),abs(x_li[i][1]-x_li[i-1][1]))
    cost[y_li[i][2]][y_li[i-1][2]] = min(abs(y_li[i][0]-y_li[i-1][0]),abs(y_li[i][1]-y_li[i-1][1]))
    cost[y_li[i-1][2]][y_li[i][2]] = min(abs(y_li[i][0]-y_li[i-1][0]),abs(y_li[i][1]-y_li[i-1][1]))

def prim(n,cost):
    mincost = [float("inf")]*n
    used = [False] * n
    mincost[0] = 0
    res = 0   
    while True:
        v = -1
        for i in range(n):
            if (not used[i]) and (v == -1 or mincost[i] < mincost[v]):
                v = i
        if v == -1:
            break
        used[v] = True
        res += mincost[v]
        for i in range(n):
            mincost[i] = min(mincost[i],cost[v][i])
    return res

print(prim(n,cost))

Fixed submission:
n = int(input())
path = []

class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0] * n
        self.size = [1] * n
    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
    # 同じ集合に属するか判定
    def same(self, x, y):
        return self.find(x) == self.find(y)
    # すべての頂点に対して親を検索する
    def all_find(self):
        for n in range(len(self.par)):
            self.find(n)

for i in range(n):
    x,y = map(int,input().split())
    path.append((x,y,i))

x_li = sorted(path)
y_li = sorted(path,key=lambda x:(x[1]))

edge = []

for i in range(1,n):
    edge.append((x_li[i][2],x_li[i-1][2],x_li[i][0]-x_li[i-1][0]))
    edge.append((y_li[i][2],y_li[i-1][2],y_li[i][1]-y_li[i-1][1]))

edge.sort(key=lambda x:(x[2]))

uf = UnionFind(n)
cost = 0

for i,j,k in edge:
    if not uf.same(i,j):
        uf.union(i,j)
        cost += k

print(cost)
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
from itertools import accumulate
from itertools import permutations

n = int(stdin.readline().rstrip())
li = [int(stdin.readline().rstrip()) for _ in range(n)]

lin = list(permutations(li))

ma = 0

for i in lin:
    i = list(i)
    lis = list(accumulate(i))[::-1]
    for i in lis:
        if i % 10 == 0:
            continue
        ma = max(ma,i)
print(ma)

Fixed submission:
from sys import stdin
from itertools import accumulate

n = int(stdin.readline().rstrip())
li = [int(stdin.readline().rstrip()) for _ in range(n)]
li.sort()
lin = list(accumulate(li))
if lin[-1] %10 != 0:
    print(lin[-1])
    exit()
else:
    for i in li:
        if i % 10 == 0:
            continue
        print(lin[-1]-i)
        exit()
print(0)

Buggy python submission (verdict: Runtime Error):

for i in lin:
    i = list(i)
    lis = list(accumulate(i))[::-1]
    for i in lis:
        if i % 10 == 0:
            continue
        ma = max(ma,i)
print(ma)


Fixed submission:
from sys import stdin
from itertools import accumulate

n = int(stdin.readline().rstrip())
li = [int(stdin.readline().rstrip()) for _ in range(n)]
li.sort()
lin = list(accumulate(li))
if lin[-1] %10 != 0:
    print(lin[-1])
    exit()
else:
    for i in li:
        if i % 10 == 0:
            continue
        print(lin[-1]-i)
        exit()
print(0)
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n,a,b = map(int,input().split())
h = [int(input()) for _ in range(n)]
h = np.array(h)

gap = a-b
count = 0

while True:
    if np.count_nonzero(h<=0) == n:
        break
    h -= b
    h[np.argmax(h)] -= gap
    count += 1

print(count)

Fixed submission:
import numpy as np

n,a,b = map(int,input().split())
h = [int(input()) for _ in range(n)]
h = np.array(h)

hi = 10**10
low = -1

def calc(x):
    y = h-x*b
    y[y<0] = 0
    f = np.ceil(y/(a-b)).sum()
    return f

while hi-low > 1:
    ave = (hi+low)//2
    if calc(ave) <= ave:
        hi = ave
    else:
        low = ave
    
print(hi)
Buggy python submission (verdict: Runtime Error):
n,a,b = map(int,input().split())

print(max(b*(n-1)+a-(a*(n-1)+b)+1),0)

Fixed submission:
from sys import stdin
n,a,b = [int(x) for x in stdin.readline().rstrip().split()]

saisyou = a*(n-1)+b
saidai = b*(n-1)+a

if n == 1 and a!= b:
    print(0)
    exit()
elif a > b:
    print(0)
    exit()
else:
    print(saidai-saisyou+1)
Buggy python submission (verdict: Runtime Error):
from sys import stdin
n,m = map(int,stdin.readline().rstrip().split())
ab = [list(map(int,stdin.readline().rstrip().split())) for _ in range(n)]
li = [0 for _ in range(n+1)]
for a,b in ab:
    li[a] += 1
    li[b] += 1
for i in li:
    if i%2 == 1:
        print("NO")
        exit()
print("YES")

Fixed submission:
from sys import stdin
n,m = map(int,stdin.readline().rstrip().split())
ab = [list(map(int,stdin.readline().rstrip().split())) for _ in range(m)]
li = [0 for _ in range(n+1)]
for a,b in ab:
    li[a] += 1
    li[b] += 1
for i in li:
    if i%2 == 1:
        print("NO")
        exit()
print("YES")
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin,setrecursionlimit

n,w = [int(x) for x in stdin.readline().rstrip().split()]
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(n)]
def knapsack(n,w,li):
    #li[i][0]が重さ,li[i][1]が価値(ときどき逆になることがあるので注意)
    dp = [[0 for i in range(w+1)]for j in range(n+1)]
    #dp[i][total_w]はi-1回目までの商品を加えた時に重さがtotal_wを超えないような値の最大値
    for i in range(n):
        for total_w in range(w+1):
            if total_w - li[i][0] >= 0:
                dp[i+1][total_w] = max(dp[i][total_w],dp[i][total_w-li[i][0]]+li[i][1])
            else:
                dp[i+1][total_w] = dp[i][total_w]
    return max(dp[-1])
print(knapsack(n,w,li))

Fixed submission:
from sys import stdin,setrecursionlimit

n,w = [int(x) for x in stdin.readline().rstrip().split()]
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(n)]

jw = li[0][0]
omosa = [[] for _ in range(4)]

for i in li:
    omosa[i[0]-jw].append(i[1])

for i in range(len(omosa)):
    omosa[i].sort(reverse = True)

saidai = n
ma = 0

for i in range(len(omosa[0])+1):
    for j in range(len(omosa[1])+1):
        for k in range(len(omosa[2])+1):
            for l in range(len(omosa[3])+1):
                to_ka = omosa[0][:i]+omosa[1][:j]+omosa[2][:k]+omosa[3][:l]
                if i*jw+j*(jw+1)+k*(jw+2)+l*(jw+3) > w:
                    continue
                ma = max(ma,sum(to_ka))

print(ma)
Buggy python submission (verdict: Runtime Error):
from sys import stdin

a,b = [int(x) for x in stdin.readline().rstrip().split()]

if a == "H" and b == "H":
    print("H")
elif a == "H" and b == "D":
    print("D")
elif a == "D" and b == "H":
    print("D")
else:
    print("H")

Fixed submission:
from sys import stdin

a,b = [x for x in stdin.readline().rstrip().split()]

if a == "H" and b == "H":
    print("H")
elif a == "H" and b == "D":
    print("D")
elif a == "D" and b == "H":
    print("D")
else:
    print("H")
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin

a,b = [int(x) for x in stdin.readline().rstrip().split()]

if a > b:
    print(b//2)
    exit()

while True:
    if a*2 < b:
        a += 1
        b -= 2
    else:
        break
print(min(a,b//2))

Fixed submission:
from sys import stdin

a,b = [int(x) for x in stdin.readline().rstrip().split()]

if a > b//2:
    print(b//2)
else:
    print((b+2*a)//4)

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
import bisect

a,b = [int(x) for x in stdin.readline().rstrip().split()]

while True:
    if a*2 < b:
        a += 1
        b -= 2
    else:
        break
print(min(a,b//2))

Fixed submission:
from sys import stdin

a,b = [int(x) for x in stdin.readline().rstrip().split()]

if a > b//2:
    print(b//2)
else:
    print((b+2*a)//4)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))

ki = [sum(1 for i in a if i%2 == 1)]
gu = n-ki

if gu == ki:
    print("YES")
else:
    print("NO")

Fixed submission:
from sys import stdin

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))
count = 0
for i in li:
    if i%2 == 1:
        count += 1
if count %2 == 1:
    print("NO")
else:
    print("YES")
Buggy python submission (verdict: Runtime Error):
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

li = prime_factorize(total)
lin = []
for key, value in groupby(li):
    lin.append(len(list(value)))

point = 1

for i in lin:
    point *= i+1
    point %= 10**9+7

print(point)

Fixed submission:
from sys import stdin
import math
from itertools import groupby

n = int(stdin.readline().rstrip())
total = math.factorial(n)

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

li = prime_factorize(total)
lin = []
for key, value in groupby(li):
    lin.append(len(list(value)))

point = 1

for i in lin:
    point *= i+1
    point %= 10**9+7

print(point)
Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin

k,s = [int(x) for x in stdin.readline().rstrip().split()]

point = 0
for i in range(k+1):
    for j in range(k+1):
        for k in range(k+1):
            if i + k + j == s:
                point += 1

print(point)

Fixed submission:
from sys import stdin

k,s = [int(x) for x in stdin.readline().rstrip().split()]

point = 0

for i in range(k+1):
    for j in range(k+1):
        if 0<= s-i-j <= k:
            point += 1

print(point)
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())
li = [[0 for i in range(n)]for j in range(n)]
lis = []

def all_pairs_shortest_paths(W):
    inf = 10**18
    # 頂点の数
    n = len(W)
    # 結果を格納する行列を用意する
    res = [[0] * n for i in range(n)]
    # 用意した行列を初期化する
    for i in range(n):
        for j in range(i, n):
            if i == j:
                val = 0
            elif W[i][j]:
                val = W[i][j]
            else:
                val = inf
            res[i][j] = res[j][i] = val
    # 動的計画法ですべての超点間の最短距離を求める
    for k in range(n):
        for u in range(n):
            for v in range(n):
                res[u][v] = min(res[u][v], res[u][k] + res[k][v])
    return res

for _ in range(m):
    a,b,c = map(int,input().split())
    a -= 1
    b -= 1
    lis.append((a,b,c))
    li[a][b] = c
    li[b][a] = c

lin = all_pairs_shortest_paths(li)
point = 0

for path in lis:
    a,b,c = path
    flag = False
    for i in range(n):
        for j in range(n):
            if lin[i][a]+c+lin[b][j] == lin[i][j]:
                flag = True
    if not flag:
        point += 1

print(point)

Fixed submission:
n,m = map(int,input().split())
li = [[0 for i in range(n)]for j in range(n)]
lis = []

def all_pairs_shortest_paths(W):
    inf = 10**18
    # 頂点の数
    n = len(W)
    # 結果を格納する行列を用意する
    res = [[0] * n for i in range(n)]
    # 用意した行列を初期化する
    for i in range(n):
        for j in range(i, n):
            if i == j:
                val = 0
            elif W[i][j]:
                val = W[i][j]
            else:
                val = inf
            res[i][j] = res[j][i] = val
    # 動的計画法ですべての超点間の最短距離を求める
    for k in range(n):
        for u in range(n):
            for v in range(n):
                res[u][v] = min(res[u][v], res[u][k] + res[k][v])
    return res

for _ in range(m):
    a,b,c = map(int,input().split())
    a -= 1
    b -= 1
    lis.append((a,b,c))
    li[a][b] = c
    li[b][a] = c

lin = all_pairs_shortest_paths(li)
point = 0

for path in lis:
    a,b,c = path
    flag = False
    for i in range(n):
        for j in range(n):
            if lin[i][a]+c+lin[b][j] == lin[i][j]:
                flag = True
    if not flag:
        point += 1

print(point)
Buggy python submission (verdict: Runtime Error):
from sys import stdin
import math
from itertools import groupby

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))

li.sort()

if li[0] == 0 and li[1] == 0:
    print(0)
    exit()

lin = []
for key, value in groupby(li):
    lin.append(len(list(value)))

point = 1

for i in lin:
    if i >= 3:
        print(0)
        exit()
    point *= math.factorial(i)
    point %= 10**9+7

print(point)

Fixed submission:
from sys import stdin
import math
from itertools import groupby

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))

li.sort()

if len(li) == 1:
    if li[0] != 0:
        print(0)
        exit()
    else:
        print(1)
        exit()

if li[0] == 0 and li[1] == 0:
    print(0)
    exit()
    
lin = []
for key, value in groupby(li):
    lin.append(len(list(value)))

point = 1

for i in lin:
    if i >= 3:
        print(0)
        exit()
    point *= math.factorial(i)
    point %= 10**9+7

print(point)

Buggy python submission (verdict: Runtime Error):
from sys import stdin
import math
from itertools import groupby

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))

li.sort()

if li[0] == 0 and li[1] == 0:
    print(0)
    exit()

lin = []
for key, value in groupby(li):
    lin.append(len(list(value)))

point = 1

for i in lin:
    if i >= 3:
        print(0)
        exit()
    point *= 2
    point %= 10**9+7

print(point)

Fixed submission:
from sys import stdin
import math
from itertools import groupby

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))

li.sort()

if len(li) == 1:
    if li[0] != 0:
        print(0)
        exit()
    else:
        print(1)
        exit()

if li[0] == 0 and li[1] == 0:
    print(0)
    exit()
    
lin = []
for key, value in groupby(li):
    lin.append(len(list(value)))

point = 1

for i in lin:
    if i >= 3:
        print(0)
        exit()
    point *= math.factorial(i)
    point %= 10**9+7

print(point)
Buggy python submission (verdict: Runtime Error):
from sys import stdin
import math

n = int(stdin.readline().rstrip())
li = [list(map(int,stdin.readline().rstrip().split())) for _ in range(n)]
for i in range(1,n):
    if li[i][0] >= li[i-1][0] and li[i][1] >= li[i-1][1]:
        continue
    elif li[i][0] >= li[i-1][0] and li[i][1] < li[i-1][1]:
        bai = math.ceil(li[i-1][1]/li[i][1])
        li[i][0] *= bai
        li[i][1] *= bai
    elif li[i][0] < li[i-1][0] and li[i][1] >= li[i-1][1]:
        bai = math.ceil(li[i-1][0]/li[i][0])
        li[i][0] *= bai
        li[i][1] *= bai
    else:
        bai = max(math.ceil(li[i-1][0]/li[i][0]),math.ceil(li[i-1][1]/li[i][1]))
        li[i][0] *= bai
        li[i][1] *= bai
print(sum(li[-1]))

Fixed submission:
from sys import stdin

li = list(map(int,stdin.readline().rstrip().split()))

li = list(set(li))

print(len(li))
Buggy python submission (verdict: Runtime Error):
mod = 10**9+7

from scipy.special import comb

s = int(input())
if s==1 or s==2:
    print(0)
    exit()

pk_num = s//3-1
ans = 1
for i in range(pk_num):
    pk = (i+2)*3
    g = s - pk
    b = i+2
    ans += comb(g+b-1,b-1, exact=True)
    ans %=  mod
print(ans)

Fixed submission:
mod = 10**9+7

from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

s = int(input())
if s==1 or s==2:
    print(0)
    exit()

pk_num = s//3-1
ans = 1
for i in range(pk_num):
    pk = (i+2)*3
    g = s - pk
    b = i+2
    ans += cmb(g+b-1,b-1)
    ans %=  mod
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations
mod = 10**9+7

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

ans = 0

for i,j in combinations(li,2):
    ans += (i*j)
    ans = ans%mod
print(ans)

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

S = sum(li)
li2 = [x**2 for x in li]
S2 = sum(li2)

print((S**2-S2)//2%mod)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations
mod = 10**9+7

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

ans = 0

for i,j in combinations(li,2):
    ans += (i*j)%mod
    ans = ans%mod
print(ans)

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

S = sum(li)
li2 = [x**2 for x in li]
S2 = sum(li2)

print((S**2-S2)//2%mod)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations
mod = 10**9+7

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

ans = 0

for i,j in combinations(li,2):
    ans += (i*j)%mod
    ans = ans%mod
print(ans)

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

S = sum(li)
li2 = [x**2 for x in li]
S2 = sum(li2)

print((S**2-S2)//2%mod)