Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
input()
from collections import *
c=Counter(map(int,input().split()))
a=sorted(-k for k,v in c.items() if v>3)
if a: s=a[0]**2
l=sorted(-k for k,v in c.items() if v>1)
print(0 if len(l)<2 else max(s,l[0]*l[1]))

Fixed submission:
input()
from collections import *
c=Counter(map(int,input().split()))
a=0
r=sorted(-k for k,v in c.items() if v>1)
if len(r)>1: a=r[0]*r[1]
s=sorted(-k for k,v in c.items() if v>3)
if s: a=max(a,s[0]**2)
print(a)
Buggy python submission (verdict: Runtime Error):
print((int(input())-1)*(int(input())-1))

Fixed submission:
n,m = map(int,input().split())
print((n-1)*(m-1))
Buggy python submission (verdict: Runtime Error):
s = input()
print(l[0]+str((len(l)-2))+l[-1])

Fixed submission:
s = input()
print(s[0]+str((len(s)-2))+s[-1])
Buggy python submission (verdict: Runtime Error):
ans = 1
while ans <= int(input())//2:
  ans *= 2
print(ans)

Fixed submission:
n = int(input())
ans = 1
while ans <= n//2:
  ans *= 2
print(ans)
Buggy python submission (verdict: Runtime Error):
p = 1
for i in range(n):
  p = p*(i+1)%(10**9+7)
print(p)

Fixed submission:
p = 1
for i in range(int(input())):
  p = p*(i+1)%(10**9+7)
print(p)
Buggy python submission (verdict: Time Limit Exceeded):
k,s = map(int,input().split())
k += 1
ans = 0
for x in range(k):
  for y in range(k):
    for z in range(k):
      if x+y+z == s:
        ans += 1
print(ans)

Fixed submission:
k,s = map(int,input().split())
k += 1
ans = 0
for x in range(k):
  for y in range(k):
      if 0<=s-x-y<k:
        ans += 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
f=lambda:map(int,input().split())
a,b=f()
for _ in range(1,n):
  s,t=f(); x=y=0
  while x<a or y<b: x+=s; y+=t
  a,b=x,y
print(a+b)

Fixed submission:
n=int(input())
f=lambda:map(int,input().split())
a,b=f()
for _ in range(1,n):
  c,d=f()
  t=max(1,0--a//c,0--b//d)
  a,b=c*t,d*t
print(a+b)
Buggy python submission (verdict: Runtime Error):
n,_=map(int,input().split())
s=set(input())
while s&set(str(n)): n+=1
print(n

Fixed submission:
n,k=map(int,input().split())
l=input().split()
while 1:
  for i in str(n):
    if i in l: n+=1; break
  else: print(n); break
Buggy python submission (verdict: Runtime Error):
A,B,C,D = map(int, input().split())
if B < C or D < A:
  print('No')
else:
  print('Yes')

Fixed submission:
K = int(input())
ans = ''
for i in range(K):
  ans += 'ACL'
print(ans)
Buggy python submission (verdict: Runtime Error):
d = float(input())
t = float(input())
s = float(input())
 
if d / s < t:
  print('yes')
 
else:
  print('no')


Fixed submission:
d,t,s = map(int, input().split())
if t >= (d / s):
    print("Yes")
else:
    print("No")

Buggy python submission (verdict: Runtime Error):
d = input()
t = input()
s = input()

if d / s < t:
  return 'yes'

else:
  return 'no'

Fixed submission:
d,t,s = map(int, input().split())
if t >= (d / s):
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
n = int(input())
lst = list(map(int, input().split()))
ans = 1
for a in lst: 
    ans *= a
	if ans > 1000000000000000000:
		print(-1)
		return
if(ans>1000000000000000000): 
    print(-1)
else:
    print(ans)


Fixed submission:
n = int(input())
lst = list(map(int, input().split()))
lst.sort()
ans = 1
for a in lst: 
    ans *= a
    if ans > 1e18:
        print(-1)
        break
else:
    print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
lst = list(map(int, input().split()))
ans = 1
for a in lst: 
    ans *= a
	if ans > 1000000000000000000:
		print(-1);
		return;
if(ans>1000000000000000000): 
    print(-1)
else:
    print(ans)


Fixed submission:
n = int(input())
lst = list(map(int, input().split()))
lst.sort()
ans = 1
for a in lst: 
    ans *= a
    if ans > 1e18:
        print(-1)
        break
else:
    print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# Hello World program in Python
    
n = int(input())
lst = list(map(int, input().split()))
ans = 1
for a in lst: 
    ans *= a
if(ans>1000000000000000000): 
    print(-1)
else:
    print(ans)

Fixed submission:
n = int(input())
lst = list(map(int, input().split()))
lst.sort()
ans = 1
for a in lst: 
    ans *= a
    if ans > 1e18:
        print(-1)
        break
else:
    print(ans)
Buggy python submission (verdict: Runtime Error):
n = input()
if 9 in n:
    print("Yes")
else:
    print("No")

Fixed submission:
n = input()
if "9" in n:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,x,m = list(map(int, input().split()))
v = x
seen = [0]*m
c = 0
val = 0
count = 0
tmp = 0
if n>m:
    for i in range(m):
        if seen[v]==2:
            break
        if seen[v]==1:
            count += 1
            tmp += v
        else:
            val += v
            c += 1
        seen[v] += 1
        v = (v**2)%m
    ans = val + ((n-c)//count) * tmp
    for i in range((n-c)%(count)):
        ans += v
        v = (v**2)%m
else:
    ans = 0
    v = x
    for i in range(n):
        ans += v
        v = (v**2)%m
print(ans)

Fixed submission:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,x,m = list(map(int, input().split()))
v = x
seen = [0]*m
c = 0
val = 0
count = 0
tmp = 0
if n>m:
    while True:
        if seen[v]==2:
            break
        if seen[v]==1:
            count += 1
            tmp += v
        else:
            val += v
            c += 1
        seen[v] += 1
        v = (v**2)%m
    ans = val + ((n-c)//count) * tmp
    for i in range((n-c)%(count)):
        ans += v
        v = (v**2)%m
else:
    ans = 0
    v = x
    for i in range(n):
        ans += v
        v = (v**2)%m
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

# 二分探索木の代わり BST HST
# 存在しない要素に対するremoveはこないことを仮定している

h = []
from collections import Counter, defaultdict
from itertools import chain
ca = defaultdict(int)
ca.update(Counter(a))
cb = defaultdict(int)
cb.update(Counter(b))
ks = set(ca.keys()) | set(cb.keys())
ans = defaultdict(list)
done = 0
amari = 0
for k in ks:
    h.append((-ca[k], -cb[k], k))
h.sort(key=lambda x: x[0]+x[1])
la = []
lb = []
for va,vb,k in h:
    la.extend([k]*-va)
    lb.extend([k]*-vb)
na = [None]*n
nb = [None]*n
ia = 0
ib = n-1
ib2 = 0
for aa,bb,k in h:
    aa *= -1
    bb *= -1
    for _ in range(aa):
        na[ia] = k
        ia += 1
    for _ in range(bb):
        if na[ib]!=k:
            nb[ib] = k
            ib -= 1
        else:
            nb[ib2] = k
            ib2 += 1
if any((na[i]==nb[i]) for i in range(n)):
    print("No")
else:
    d = defaultdict(list)
    for i in range(n):
        d[la[i]].append(nlb[i])
    ans = []
    for i in range(n):
        ans.append(d[la[i]].pop())
    print("Yes")
    write(" ".join(map(str, ans)))

Fixed submission:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

# 二分探索木の代わり BST HST
# 存在しない要素に対するremoveはこないことを仮定している

h = []
from collections import Counter, defaultdict
from itertools import chain
ca = defaultdict(int)
ca.update(Counter(a))
cb = defaultdict(int)
cb.update(Counter(b))
ks = set(ca.keys()) | set(cb.keys())
ans = defaultdict(list)
done = 0
amari = 0
for k in ks:
    h.append((-ca[k], -cb[k], k))
h.sort(key=lambda x: x[0]+x[1])
la = []
lb = []
for va,vb,k in h:
    la.extend([k]*-va)
    lb.extend([k]*-vb)
na = [None]*n
nb = [None]*n
ia = 0
ib = n-1
ib2 = 0
for aa,bb,k in h:
    aa *= -1
    bb *= -1
    for _ in range(aa):
        na[ia] = k
        ia += 1
    for _ in range(bb):
        if na[ib]!=k:
            nb[ib] = k
            ib -= 1
        else:
            nb[ib2] = k
            ib2 += 1
if any((na[i]==nb[i]) for i in range(n)):
    print("No")
else:
    d = defaultdict(list)
    for i in range(n):
        d[na[i]].append(nb[i])
    ans = []
    for i in range(n):
        ans.append(d[a[i]].pop())
    print("Yes")
    write(" ".join(map(str, ans)))
Buggy python submission (verdict: Runtime Error):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")

n = int(input())

def hurui(n):
    """n以下の素数のリストを返す
    """
    l = list(range(2,n))
    p = 2
    i = 0
    while True:
        l = [item for item in l if item==p or item%p!=0]
        i += 1
        p = l[i]
        if p*p>n:
            break
    return l
l = hurui(n)
nums = list(range(n+1))
t = [1]*(n+1)
for p in l:
    for k in range(1, n//p+1):
        v = 0
        while nums[k*p]%p==0:
            v += 1
            nums[k*p]//=p
        t[k*p] *= (v+1)
ans = sum(i*t[i] for i in range(1,n+1))
print(ans)

Fixed submission:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")



n = int(input())
ans = 0
for i in range(1, n+1):
    v = (n)//i
    ans += i*(v+1)*v//2
print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())

def hurui(n):
    """n以下の素数のリストを返す
    """
    l = list(range(2,n))
    p = 2
    i = 0
    while True:
        l = [item for item in l if item==p or item%p!=0]
        i += 1
        p = l[i]
        if p*p>n:
            break
    return l
l = hurui(n)
nums = list(range(n+1))
t = [1]*(n+1)
for p in l:
    for k in range(1, n//p+1):
        v = 0
        while nums[k*p]%p==0:
            v += 1
            nums[k*p]//=p
        t[k*p] *= (v+1)
ans = sum(i*t[i] for i in range(1,n+1))
print(ans)

Fixed submission:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")



n = int(input())
ans = 0
for i in range(1, n+1):
    v = (n)//i
    ans += i*(v+1)*v//2
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")

x,n = map(int,input().split())
if n:
    p = list(map(int,input().split()))

p = set(p)
pp = set([item for item in range(0,101) if item not in p])
v = 3000
ans = -1
for item in pp:
    if v>abs(x-item):
        v = abs(x-item)
        ans = item
print(ans)

Fixed submission:
x,n = map(int,input().split())
if n:
    p = list(map(int,input().split()))
else:
    p = []
p = set(p)
pp = set([item for item in range(0,105) if item not in p])
v = 3000
ans = -1
for item in pp:
    if v>abs(x-item):
        v = abs(x-item)
        ans = item
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")

M =998244353

n, s = map(int, input().split())
a = list(map(int, input().split()))
dp = [[0]* (s+1) for _ in range(n+1)]
for i in range(n+1):
    dp[i][0] = 2**i
for i in range(1,n+1):
    for j in range(1,s+1):
        dp[i][j] = dp[i-1][j]*2
        if j>=a[i-1]:
             dp[i][j] += dp[i-1][j-a[i-1]]
        dp[i][j] %= M
print(dp[n][s])

Fixed submission:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")

M =998244353

n, s = map(int, input().split())
a = list(map(int, input().split()))
dp = [[0]* (s+1) for _ in range(n+1)]
for i in range(n+1):
    dp[i][0] = pow(2,i,M)
for i in range(1,n+1):
    for j in range(1,s+1):
        dp[i][j] = dp[i-1][j]*2
        if j>=a[i-1]:
             dp[i][j] += dp[i-1][j-a[i-1]]
        dp[i][j] %= M
print(dp[n][s])
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()
r = []
g = []
b = []
for i, item in enumerate(s):
    if item=="R":
        r.append(i)
    elif item=="G":
        g.append(i)
    else:
        b.append(i)

count = 0
for low,mid,high in [(r,g,b), (r,b,g), (g,r,b), (g,b,r), (b,r,g), (b,g,r)]:
    for m in mid:
        ind = len(high) - 1
        for l in low:
            if l >= m:
                continue
            while (l+high[ind] > m*2) and (ind>0):
                ind -= 1
            if m < high[ind]:
                if l+high[ind] == m*2:
                    count += 1

#                 print(l, m, high[ind])
print(len(r)*len(g)*len(b) - count)

Fixed submission:
n = int(input())
s = input()
r = []
g = []
b = []
for i, item in enumerate(s):
    if item=="R":
        r.append(i)
    elif item=="G":
        g.append(i)
    else:
        b.append(i)
if (not r) or (not g) or (not b):
    print(0)
else:
    count = 0
    for low,mid,high in [(r,g,b), (r,b,g), (g,r,b), (g,b,r), (b,r,g), (b,g,r)]:
        for m in mid:
            ind = len(high) - 1
            for l in low:
                if l >= m:
                    continue
                while (l+high[ind] > m*2) and (ind>0):
                    ind -= 1
                if m < high[ind]:
                    if l+high[ind] == m*2:
                        count += 1
    print(len(r)*len(g)*len(b) - count)
Buggy python submission (verdict: Runtime Error):
n, m = input().split(" ")
print(n*(n-1)/2 + m*(m-1)/2)

Fixed submission:
n, m = [int(c) for c in input().split()]
print(int(n*(n-1)/2 + m*(m-1)/2))
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n = int(input())
a = np.array([int(c) for c in input().split()], dtype=int)
c = np.zeros((n,), dtype=int)
for i in range(a.shape[0]):
    c[a[i]-1]+=1
count = (c * (c-1) / 2).sum()
for i in range(a.shape[0]):
    pp = c[a[i]-1]
    print(int(count - pp * (pp - 1) / 2 + (pp-1) * (pp-2) / 2))

Fixed submission:
n = int(input())
a = [int(c) for c in input().split()]
c = [0 for _ in range(n)]
for i in range(n):
    c[a[i]-1]+=1
count = sum(c[i] * (c[i]-1) / 2 for i in range(n))
for i in range(n):
    pp = c[a[i]-1]
    print(int(count - pp * (pp - 1) / 2 + (pp-1) * (pp-2) / 2))
Buggy python submission (verdict: Runtime Error):
# パナソニック2020D
import sys
def write(x):
	sys.stdout.write(x)
    sys.stdout.write("\n")
    
from queue import deque
n = int(input())
q = deque([("a", "a")])
while True:
    s, m = q.pop()
    if len(s)==n:
        write(s)
    elif len(s)>=n+1:
        break
    for o in range(ord("a"), ord(m)+2):
        if ord(m)<o:
            m = chr(o)
        q.appendleft((s + chr(o), m))

Fixed submission:
# パナソニック2020D
from queue import deque
n = int(input())
q = deque([("a", "a")])
while True:
    s, m = q.pop()
    if len(s)==n:
        print(s)
    elif len(s)>=n+1:
        break
    for o in range(ord("a"), ord(m)+2):
        if ord(m)<o:
            m = chr(o)
        q.appendleft((s + chr(o), m))
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
# lines = open("tmp_in").readlines()

# def _input():
#     for ss in lines:
#         yield ss.rstrip()
# input = _input().__next__

s = input()
q = int(input())
turn = 0
# ともにSに近い方から並べる
before = "" 
after = ""
for _ in range(q):
    tmp = input()
    if tmp=="1":
        turn += 1
    else:
        _,f,c = tmp.split()
        f = int(f)
        if (turn + f) % 2 == 1:
            before += c
        else:
            after += c
if turn%2==0:
    out = before[::-1] + s + after
else:
    out = after[::-1] + s[::-1] + before
print(out)

Fixed submission:

s = input()
q = int(input())
turn = 0
# ともにSに近い方から並べる
before = "" 
after = ""
for _ in range(q):
    tmp = input()
    if tmp=="1":
        turn += 1
    else:
        _,f,c = tmp.split()
        f = int(f)
        if (turn + f) % 2 == 1:
            before += c
        else:
            after += c
if turn%2==0:
    out = before[::-1] + s + after
else:
    out = after[::-1] + s[::-1] + before
print(out)
Buggy python submission (verdict: Runtime Error):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")



M = 10**9+7
N = 4*10**5+3 # 必要なテーブルサイズ

def cmb(n, r, M):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return (g1[n] * g2[r] * g2[n-r]) % M

g1 = [None] * (N+1) # 元テーブル
g2 = [None] * (N+1) #逆元テーブル
inverse = [None] * (N+1) #逆元テーブル計算用テーブル
g1[0] = g1[1] = g2[0] = g2[1] = 1
inverse[0], inverse[1] = [0, 1] 

for i in range( 2, N + 1 ):
    g1[i] = ( g1[i-1] * i ) % M 
    inverse[i] = ( -inverse[M % i] * (M//i) ) % M # ai+b==0 mod M <=> i==-b*a^(-1) <=> i^(-1)==-b^(-1)*aより
    g2[i] = (g2[i-1] * inverse[i]) % M 

n,k = map(int, input().split())
M = 10**9+7
if k<n:
    ans = 0
    for p in range(k+1):
        ans += cmb(n,p,M) * cmb(n-1+p, p)
        ans %= M
else:
    ans = cmb(2*n-1,n,M)
print(ans)

Fixed submission:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")



M = 10**9+7
N = 4*10**5+3 # 必要なテーブルサイズ

def cmb(n, r, M):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return (g1[n] * g2[r] * g2[n-r]) % M

g1 = [None] * (N+1) # 元テーブル
g2 = [None] * (N+1) #逆元テーブル
inverse = [None] * (N+1) #逆元テーブル計算用テーブル
g1[0] = g1[1] = g2[0] = g2[1] = 1
inverse[0], inverse[1] = [0, 1] 

for i in range( 2, N + 1 ):
    g1[i] = ( g1[i-1] * i ) % M 
    inverse[i] = ( -inverse[M % i] * (M//i) ) % M # ai+b==0 mod M <=> i==-b*a^(-1) <=> i^(-1)==-b^(-1)*aより
    g2[i] = (g2[i-1] * inverse[i]) % M 

n,k = map(int, input().split())
M = 10**9+7
if k<n:
    ans = 0
    for p in range(k+1):
        ans += cmb(n,p,M) * cmb(n-1, p, M)
        ans %= M
else:
    ans = cmb(2*n-1,n,M)
print(ans)
Buggy python submission (verdict: Runtime Error):
# ABC155E

s = input()
d0 = [0,1,2,3,4,5,6,7,8,9]
d1 = [0,1,2,3,4,5,5,4,3,2] # 通常時

a0 = d1[int(s[0])]
a1 = d1[int(s[0]) + 1]

for c in s[1:]:
    c = int(c)
    b0 = min(a0 + c, a1 + (10 - c))
    b1 = min(a0 + c + 1, a1 + (9 - c)) if c <=8 else a1
    a0, a1 = b0, b1
    
print(a0)

Fixed submission:
# ABC155E

s = input()
d0 = [0,1,2,3,4,5,6,7,8,9]
d1 = [0,1,2,3,4,5,5,4,3,2] # 通常時

a0 = d1[int(s[0])]
a1 = d1[int(s[0]) + 1] if int(s[0])<=8 else 1

for c in s[1:]:
    c = int(c)
    b0 = min(a0 + c, a1 + (10 - c))
    b1 = min(a0 + c + 1, a1 + (9 - c)) if c <=8 else a1
    a0, a1 = b0, b1
    
print(a0)
Buggy python submission (verdict: Runtime Error):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


M = 10**9+7 # 出力の制限
N = 10**6+2 # 必要なテーブルサイズ

g1 = [None] * (N+1) # 元テーブル
g2 = [None] * (N+1) #逆元テーブル
inverse = [None] * (N+1) #逆元テーブル計算用テーブル
g1[0] = g1[1] = g2[0] = g2[1] = 1
inverse[0], inverse[1] = [0, 1] 

for i in range( 2, N + 1 ):
    g1[i] = ( g1[i-1] * i ) % M 
    inverse[i] = ( -inverse[M % i] * (M//i) ) % M # ai+b==0 mod M <=> i==-b*a^(-1) <=> i^(-1)==-b^(-1)*aより
    g2[i] = (g2[i-1] * inverse[i]) % M 

def cmb(n, r, M):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return (g1[n] * g2[r] * g2[n-r]) % M

ans = 0
r1,c1,r2,c2 = map(int, input().split())
for c in range(c1, c2+1):
    ans += cmb(r2+c, r2, M) - cmb(r1-1+c, r1-1, M)
for r in range(r1, r2+1):
    ans += cmb(c2+r, c2, M) - cmb(c1-1+r, c1-1, M)
    
# for r in range(r1+1, r2+1):
#     val = cmb(r+c1, r, M)
#     ans += val * (c2-c1) * (r2-r+1)
#     ans += val
#     ans %= M
# ans += cmb(r1+c1, r1, M)
# for c in range(c1+1, c2+1):
#     val = cmb(r1+c, c, M)
#     ans += val * (r2-r1) * (c2-c+1)
#     ans += val
#     ans %= M
print(ans%M)

Fixed submission:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")

M = 10**9+7 # 出力の制限
N = 2*10**6+4 # 必要なテーブルサイズ

g1 = [None] * (N+1) # 元テーブル
g2 = [None] * (N+1) #逆元テーブル
inverse = [None] * (N+1) #逆元テーブル計算用テーブル
g1[0] = g1[1] = g2[0] = g2[1] = 1
inverse[0], inverse[1] = [0, 1] 

for i in range( 2, N + 1 ):
    g1[i] = ( g1[i-1] * i ) % M 
    inverse[i] = ( -inverse[M % i] * (M//i) ) % M # ai+b==0 mod M <=> i==-b*a^(-1) <=> i^(-1)==-b^(-1)*aより
    g2[i] = (g2[i-1] * inverse[i]) % M 

def cmb(n, r, M):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return (g1[n] * g2[r] * g2[n-r]) % M

ans = 0
r1,c1,r2,c2 = map(int, input().split())
for c in range(c1, c2+1):
    ans += cmb(r2+c, r2, M) - cmb(r1-1+c, r1-1, M)
for r in range(r1, r2+1):
    ans += cmb(c2+r, c2, M) - cmb(c1-1+r, c1-1, M)
    
# for r in range(r1+1, r2+1):
#     val = cmb(r+c1, r, M)
#     ans += val * (c2-c1) * (r2-r+1)
#     ans += val
#     ans %= M
# ans += cmb(r1+c1, r1, M)
# for c in range(c1+1, c2+1):
#     val = cmb(r1+c, c, M)
#     ans += val * (r2-r1) * (c2-c+1)
#     ans += val
#     ans %= M
print(ans%M)
Buggy python submission (verdict: Runtime Error):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = list(map(int, input().split()))

def gcd(a, b):
    while b:
        a, b = b, a%b
    return a
 
def lcm(a, b):
    return a*b*pow(gcd(a,b), M-2, M)
#     return a//gcd(a, b)*b

def lcms(a):
    l = a[0]
    for num in a[1:]:
        l = lcm(l, num)
    return l

l = lcms(a)    
ans = 0
M = 10**9+7
for num in a:
    ans += (l*pow(num, M-2, M))
    ans %= M
print(ans)

Fixed submission:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")

n = int(input())
a = list(map(int, input().split()))
M = 10**9+7

def factor(n, m=None):
    # mを与えると、高々その素因数まで見て、残りは分解せずにそのまま出力する
    arr = {}
    temp = n
    M = int(-(-n**0.5//1))+1
    if m is not None:
        M = min(m+1, M)
    for i in range(2, M):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr[i] = cnt

    if temp!=1:
        arr[temp] = 1

    if not arr:
        arr[n] = 1

    return arr

ds = [factor(num) for num in a]
D = {}
for d in ds:
    for k,v in d.items():
        if k in D:
            D[k] = max(D[k], v)
        else:
            D[k] = v
l = 1
for k,v in D.items():
    l *= pow(k,v,M)
    l %= M
ans = 0
for num in a:
    ans += (l*pow(num, M-2, M))
    ans %= M
print(ans)