Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n,*l=map(int,open(0).read().split())
a=1
for i in sorted(l): a*=i
print([a,-1][a>10**18])

Fixed submission:
n=int(input())
l=list(map(int,input().split()))
if 0 in l:
  print(0)
  exit()
a=1
for i in l:
  a*=i
  if a>10**18:
    print(-1)
    exit()
print(a)

Buggy python submission (verdict: Time Limit Exceeded):
n,*l=map(int,open(0).read().split())
a=1
for i in l: a*=i
print([a,-1][a>10**18])

Fixed submission:
n=int(input())
l=list(map(int,input().split()))
if 0 in l:
  print(0)
  exit()
a=1
for i in l:
  a*=i
  if a>10**18:
    print(-1)
    exit()
print(a)
Buggy python submission (verdict: Runtime Error):
n=int(input())
d={2:0}
while n%2<1:  n//=2;  d[2]+=1
for i in range(3,int(n**0.5)+1,2):
  while n%i<1:  n//=i;  d[i]=d.get(i,0)+1
  if n<2: break
if n>1: d[x]=1
a=0
for i in d.values():
  t=c=0
  while t+c<i: c+=1; t+=c
  a+=c
print(a)

Fixed submission:
n=int(input())
if n==1: print(0); exit()
M=10**6+1
l=[]
p=[1]*M
p[0]=p[1]=0
for i in range(2,M):
  if p[i]:
    l.append(i)
    for j in range(2*i,M,i):
      p[j]=0
d={}
for k in l:
  c=0
  while n%k==0: n//=k; c+=1
  if c>0: d[k]=c
s=[1]
for i in range(2,9):
  s.append(s[-1]+i)
a=0
for i in d.values():
  for j in s:
    if j>i: break
    a+=1
print(a+(n>1))
Buggy python submission (verdict: Time Limit Exceeded):
M=998244353
n,s,*l=map(int,open(0).read().split())
dp=[[0]*(s+1) for _ in '01']
dp[0][0]=1
b=0
for i in range(n):
  b^=1
  for j in range(s+1):
    dp[b][j]=dp[b^1][j]*2%M
    if j>=l[i]: dp[b][j]+=dp[b^1][j-l[i]]
print(dp[n%2][s]%M)

Fixed submission:
M=998244353
n,s,*l=map(int,open(0).read().split())
dp=[[0]*(s+1) for _ in '01']
dp[0][0]=1
b=0
for i in range(n):
  b^=1
  for j in range(s+1):
    dp[b][j]=dp[b^1][j]*2
    if j>=l[i]: dp[b][j]+=dp[b^1][j-l[i]]
    dp[b][j]%=M
print(dp[n%2][s])

Buggy python submission (verdict: Time Limit Exceeded):
M=998244353
n,s,*l=map(int,open(0).read().split())
dp=[[0]*(s+1) for _ in '01']
dp[0][0]=1
b=0
for i in range(n):
  b^=1
  for j in range(s+1):
    dp[b][j]=dp[b^1][j]*2
    if j>=l[i]: dp[b][j]+=dp[b^1][j-l[i]]
    dp[b][j]%=M
print(dp[n%2][s])

Fixed submission:
M=998244353
n,s,*l=map(int,open(0).read().split())
dp=[[0]*(s+1) for _ in '01']
dp[0][0]=1
b=0
for i in range(n):
  b^=1
  for j in range(s+1):
    dp[b][j]=dp[b^1][j]*2
    if j>=l[i]: dp[b][j]+=dp[b^1][j-l[i]]
    dp[b][j]%=M
print(dp[n%2][s])
Buggy python submission (verdict: Time Limit Exceeded):
D=60
f=lambda:[*map(int,input().split())]
n,k=f()
l=f()
t=[[0]*n for _ in range(D)]
for i in range(n):
  t[0][i]=l[i]-1
for i in range(D-1):
  for j in range(n):
    t[i+1][j]=t[i][t[i][j]]
a=0
for i in range(D):
  if k%2: a=t[i][a]
  k//=2
print(a+1)

Fixed submission:
f=lambda:map(int,input().split())
n,k=f()
a=list(f())
lv=[-1]*n
lv[0]=0
p=0
for i in range(n):
  t=a[p]-1
  if lv[t]>=0:
    l,r=lv[t],i+1
    break
  lv[t]=i+1
  p=t
print(lv.index(l+(k-l)%(r-l) if k>l else k)+1)

Buggy python submission (verdict: Time Limit Exceeded):
D=60
n,k,*l=map(int,open(0).read().split())
to=[[0]*n for _ in range(D)]
for i in range(n):
  to[0][i]=l[i]-1
for i in range(D-1):
  for j in range(n):
    to[i+1][j]=to[i][to[i][j]]
a=0
for i in range(D):
  if k%2:
    a=to[i][a]
  k//=2
print(a+1)

Fixed submission:
f=lambda:map(int,input().split())
n,k=f()
a=list(f())
lv=[-1]*n
lv[0]=0
p=0
for i in range(n):
  t=a[p]-1
  if lv[t]>=0:
    l,r=lv[t],i+1
    break
  lv[t]=i+1
  p=t
print(lv.index(l+(k-l)%(r-l) if k>l else k)+1)
Buggy python submission (verdict: Time Limit Exceeded):
M=998244353
n,m,k=map(int,input().split())
a=m*pow(m-1,n-1,M)
c=1
for i in range(1,k+1):
  t=m*pow(m-1,n-i-1,M)
  c=c*(n-i)*pow(i,M-2,M)
  a+=t*c%M
print(a%M)

Fixed submission:
M=998244353
n,m,k=map(int,input().split())
p,c=[m]*n,[1]*n
for i in range(1,n):
  p[i]=p[i-1]*(m-1)%M
  c[i]=c[i-1]*(n-i)*pow(i,M-2,M)%M
print(sum(p[n-i-1]*c[i]%M for i in range(k+1))%M)

Buggy python submission (verdict: Time Limit Exceeded):
M=998244353
n,m,k=map(int,input().split())
a=m*pow(m-1,n-1,M)
c=1
for i in range(1,k+1):
  t=m*pow(m-1,n-i-1,M)
  c=c*(n-i)*pow(i,M-2,M)
  a+=t*c%M
print(a%M)

Fixed submission:
M=998244353
n,m,k=map(int,input().split())
p,c=[m]*n,[1]*n
for i in range(1,n):
  p[i]=p[i-1]*(m-1)%M
  c[i]=c[i-1]*(n-i)*pow(i,M-2,M)%M
print(sum(p[n-i-1]*c[i]%M for i in range(k+1))%M)
Buggy python submission (verdict: Time Limit Exceeded):
M,a,t,p=2019,0,0,1;l=[0]*M
for i in input()[::-1]:l[t]+=1;t=(t+int(i)*p)%M;a+=l[t];p*=10
print(a)

Fixed submission:
M=2019
s=input()[::-1]
a=t=0
p=1
l=[0]*M
for i in s:
  l[t]+=1
  t+=int(i)*p
  t%=M
  a+=l[t]
  p=p*10%M
print(a)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input());s=input();c=s.count;print(c('R')*c('G')*c('B')-sum(sorted(s[i:j+1:(j-i)//2])==list('BGR')for i in range(n-2)for j in range(i+2,n,2)))

Fixed submission:
n=int(input())
s=input()
c=s.count
r,g,b=c('R'),c('G'),c('B')
t=0
for i in range(n-2):
  for w in range(1,(n-i+1)//2):
    if s[i]+s[i+w]+s[i+w*2] in ('RGB','RBG','GRB','GBR','BRG','BGR'):
        t+=1
print(r*g*b-t)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
c=s.count
r,g,b=c('R'),c('G'),c('B')
t=0
for i in range(n-2):
  for j in range(i+1,n-1):
    k=j*2-i
    if k<n:
      if s[i]+s[j]+s[k] in ('RGB','RBG','GRB','GBR','BRG','BGR'):
        t+=1
print(r*g*b-t)

Fixed submission:
n=int(input())
s=input()
c=s.count
r,g,b=c('R'),c('G'),c('B')
t=0
for i in range(n-2):
  for w in range(1,(n-i+1)//2):
    if s[i]+s[i+w]+s[i+w*2] in ('RGB','RBG','GRB','GBR','BRG','BGR'):
        t+=1
print(r*g*b-t)
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
from fractions import gcd
if n<k: n,k=k,n
if n%k==0 and n//k%2==0:
  print(0)
else:
  print(gcd(n,k))

Fixed submission:
n,k=map(int,input().split());x=n%k;print(min(x,k-x))
Buggy python submission (verdict: Time Limit Exceeded):
f=lambda:map(int,input().split())
x,y,a,b,c=f()
p=sorted(f())[::-1]
q=sorted(f())[::-1]
r=sorted(f())[::-1]
lp,lq,lr=[0]*(a+1),[0]*(b+1),[0]*(c+1)
s=t=u=m=0
for i in range(a): s+=p[i]; lp[i+1]+=s
for i in range(b): t+=q[i]; lq[i+1]+=t
for i in range(c): u+=r[i]; lr[i+1]+=u
for i in range(min(x,c)+1):
  for j in range(min(y,c-i)+1):
    m=max(m,lp[x-i]+lq[y-j]+lr[i+j])
print(m)

Fixed submission:
f=lambda:map(int,input().split())
x,y,a,b,c=f()
l=sorted(sorted(f())[-x:]+sorted(f())[-y:]+list(f()))
print(sum(l[-x-y:]))

Buggy python submission (verdict: Time Limit Exceeded):
f=lambda:map(int,input().split())
x,y,a,b,c=f()
p=sorted(f())[::-1]
q=sorted(f())[::-1]
r=sorted(f())[::-1]
lp,lq,lr=[0]*(a+1),[0]*(b+1),[0]*(c+1)
s=t=u=m=0
for i in range(a): s+=p[i]; lp[i+1]+=s
for i in range(b): t+=q[i]; lq[i+1]+=t
for i in range(c): u+=r[i]; lr[i+1]+=u
for i in range(min(x,c)+1):
  for j in range(min(y,c-i)+1):
    m=max(m,lp[x-i]+lq[y-j]+lr[i+j])
print(m)

Fixed submission:
f=lambda:map(int,input().split())
x,y,a,b,c=f()
l=sorted(sorted(f())[-x:]+sorted(f())[-y:]+list(f()))
print(sum(l[-x-y:]))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l=list(map(int,input().split()))
from collections import *
c=Counter(l)
for i in l:
  d=c.copy()
  d[i]-=1
  a=0
  for j in d.values():
    a+=j*(j-1)//2
  print(a)

Fixed submission:
n=int(input())
l=list(map(int,input().split()))
from collections import *
c=Counter(l)
a=sum(i*(i-1)//2 for i in c.values())
for i in l: print(a-c[i]+1)
Buggy python submission (verdict: Time Limit Exceeded):
f=input
s=f()
n=int(f())
t=0
for i in range(n):
  q=f()
  if q[0]=='1': t=1-t
  elif int(q[2])+t==2: s+=q[4]
  else: s=q[4]+s
print(''.join([s,s[::-1]][t]))

Fixed submission:
from collections import deque
f=input
s=deque(f())
n=int(f())
t=0
for i in range(n):
  q=f()
  if q[0]=='1': t=1-t
  elif int(q[2])+t==2: s.append(q[4])
  else: s.appendleft(q[4])
print(''.join([s,list(s)[::-1]][t]))
Buggy python submission (verdict: Time Limit Exceeded):
n,a,b=map(int,input().split())
I=10**9+7
l=[1,1]
p=2
for i in range(1,n):
  p=p*2%I
  m=[1]
  for j in range(i):
    m.append((l[j]+l[j+1])%I)
  l=m+[1]
print((p-l[a]-l[b]-1)%I)

Fixed submission:
n,a,b=map(int,input().split())
M=10**9+7
def c(k):
  s=t=1
  for i in range(k): s=s*(n-i)%M; t=t*(i+1)%M
  return s*pow(t,M-2,M)%M
print((pow(2,n,M)-c(a)-c(b)-1)%M)

Buggy python submission (verdict: Time Limit Exceeded):
n,a,b=map(int,input().split())
I=10**9+7
def g(k,r):
  return 1 if k<2 or r in (0,k) else (g(k-1,r-1)+g(k-1,r))%I
p=1
for i in range(n):
  p=p*2%I
print((p-g(n,a)-g(n,b)-1)%I)

Fixed submission:
n,a,b=map(int,input().split())
M=10**9+7
def c(k):
  s=t=1
  for i in range(k): s=s*(n-i)%M; t=t*(i+1)%M
  return s*pow(t,M-2,M)%M
print((pow(2,n,M)-c(a)-c(b)-1)%M)
Buggy python submission (verdict: Runtime Error):
f=lambda:map(int,input().split())
h,n=f()
dp=[0]+[10**9]*h
for i in range(n):
  a,b=f()
  for j in range(h+1): dp[j]=min(dp[j],dp[j-a]+b)
print(dp[h])

Fixed submission:
import sys
f=lambda:map(int,sys.stdin.readline().split())
h,n=f()
INF=10**9
dp=[[INF]*(h+1) for _ in range(n+1)]
dp[0][0]=0
for i in range(n):
  a,b=f()
  for j in range(h+1):
    dp[i+1][j]=min(dp[i][j],dp[i+1][max(j-a,0)]+b)
print(dp[n][h])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
f=lambda:map(int,sys.stdin.readline().split())
h,n=f()
dp=[10**9]*(h+1)
dp[0]=0
for i in range(n):
  a,b=f()
  for j in range(h+1):
    dp[j]=min(dp[j],dp[max(j-a,0)]+b)
print(dp[h])

Fixed submission:
import sys
f=lambda:map(int,sys.stdin.readline().split())
h,n=f()
INF=10**9
dp=[[INF]*(h+1) for _ in range(n+1)]
dp[0][0]=0
for i in range(n):
  a,b=f()
  for j in range(h+1):
    dp[i+1][j]=min(dp[i][j],dp[i+1][max(j-a,0)]+b)
print(dp[n][h])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
f=lambda:map(int,sys.stdin.readline().split())
h,n=f()
INF=10**9
dp=[[INF]*(h+1) for _ in range(n+1)]
dp[0][0]=0
for i in range(n):
  a,b=f()
  for j in range(h+1):
    dp[i+1][j]=min(dp[i][j],dp[i+1][max(j-a,0)]+b)
print(dp[n][h])

Fixed submission:
import sys
f=lambda:map(int,sys.stdin.readline().split())
h,n=f()
INF=10**9
dp=[[INF]*(h+1) for _ in range(n+1)]
dp[0][0]=0
for i in range(n):
  a,b=f()
  for j in range(h+1):
    dp[i+1][j]=min(dp[i][j],dp[i+1][max(j-a,0)]+b)
print(dp[n][h])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(map(int, input().split()))

print(sum(l[i] == min(l[:i+1]) for i in range(n)))

Fixed submission:
n = int(input())
l = list(map(int, input().split()))

m = 200001
ans = 0

for i in range(n):
  if l[i] < m:
    m = l[i]
    ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
n, k, s = map(int, input().split())
mod = 10**9
l = [s]*k + [(s+1)%mod]*(n-k)
print(*l)

Fixed submission:
h = int(input())
w = int(input())
n = int(input())

print((n-1)//max(h,w)+1)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ll = [[0]*i for i in range(n)]
for i in range(n):
  x, l =map(int, input().split())
  ll[i] = [x-l, x+l]
ll = sorted(ll)

l = ll[0]
ans = n

for i in range(n-1):
  li = ll[i+1]
  if l[1] > li[0]:
    ans -= 1
  else:
    l = li

print(ans)

Fixed submission:
n = int(input())
ll = []
for i in range(n):
  x, l = map(int, input().split())
  ll.append([x-l, x+l])
ll = sorted(ll)

ans = n
r = ll.pop()[0]

while ll:
  while ll and ll[-1][1] > r:
    ans -= 1
    ll.pop()
  if ll:
    r = ll.pop()[0]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
ll = [[0]*i for i in range(n)]
for i in range(n):
  x, l =map(int, input().split())
  ll[i] = [x-l, x+l]
ll = sorted(ll)

l = ll[0]
ans = n

for i in range(n-1):
  if l[1] > ll[i+1][0]:
    ans -= 1
  else:
    l = ll[i+1]

print(ans)

Fixed submission:
n = int(input())
ll = []
for i in range(n):
  x, l = map(int, input().split())
  ll.append([x-l, x+l])
ll = sorted(ll)

ans = n
r = ll.pop()[0]

while ll:
  while ll and ll[-1][1] > r:
    ans -= 1
    ll.pop()
  if ll:
    r = ll.pop()[0]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

ll = [[0]*i for i in range(n)]
for i in range(n):
  x, l =map(int, input().split())
  ll[i] = [x-l, x+l]
ll = sorted(ll)

l = [1] * n

for i in range(n-1):
  for j in range(i+1, n):
    if l[i] == 0:
      continue
    elif ll[i][1] > ll[j][0]:
      l[j] = 0
    else:
      break

print(sum(l)) 

Fixed submission:
n = int(input())
ll = []
for i in range(n):
  x, l = map(int, input().split())
  ll.append([x-l, x+l])
ll = sorted(ll)

ans = n
r = ll.pop()[0]

while ll:
  while ll and ll[-1][1] > r:
    ans -= 1
    ll.pop()
  if ll:
    r = ll.pop()[0]

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

ll = [[0]*i for i in range(n)]
for i in range(n):
  x, l =map(int, input().split())
  ll[i] = [x-l, x+l]
ll = sorted(ll)

l = [1] * n

for i in range(n-1):
  for j in range(i+1, n):
    if l[i] == 1 and ll[i][1] > ll[j][0]:
      l[j] = 0

print(sum(l)) 

Fixed submission:
n = int(input())
ll = []
for i in range(n):
  x, l = map(int, input().split())
  ll.append([x-l, x+l])
ll = sorted(ll)

ans = n
r = ll.pop()[0]

while ll:
  while ll and ll[-1][1] > r:
    ans -= 1
    ll.pop()
  if ll:
    r = ll.pop()[0]

print(ans)
Buggy python submission (verdict: Runtime Error):
n, k, m = map(int, input().split())
l = list(map(int, input().split()))

A = n*m - sum(l)

print(max(0, A) if A <= k else -1)

Fixed submission:
print(chr(ord(input())+1))

Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())

lac = [0] * n
lwa = [0] * n

for i in range(m):
    p, s = input().split()
    p = int(p) - 1
    if lac[p] == 0:
        if s == 'WA':
            lwa[p] += 1
        if s == 'AC':
            lac[p] = 1

print(sum(lac), sum(x * y for x, y in zip(lac, lwa)))

Fixed submission:
print(chr(ord(input())+1))
Buggy python submission (verdict: Time Limit Exceeded):
n,m=map(int,input().split())
ll=[input().split() for _ in range(m)]
la=list({p for p,s in ll if s=='AC'})
a=len(la);lf=[1]*a;d={};w=0
for p,s in ll:
  if p in la and lf[la.index(p)]:
    if s=='WA': d[p]=d.get(p,0)+1
    else: w+=d.get(p,0); lf[la.index(p)]=0
print(a,w)

Fixed submission:
n, m = map(int, input().split())

lac = [0] * n
lwa = [0] * n

for i in range(m):
    p, s = input().split()
    p = int(p) - 1
    if lac[p] == 0:
        if s == 'WA':
            lwa[p] += 1
        if s == 'AC':
            lac[p] = 1

lwa = [x * y for x, y in zip(lac, lwa)]
print(sum(lac), sum(lwa))

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
ll=[input().split() for _ in range(m)]
la={p for p,s in ll if s=='AC'})
f,c=0,0
for p,s in ll:
  if s=='AC': 
  if 

Fixed submission:
n, m = map(int, input().split())

lac = [0] * n
lwa = [0] * n

for i in range(m):
    p, s = input().split()
    p = int(p) - 1
    if lac[p] == 0:
        if s == 'WA':
            lwa[p] += 1
        if s == 'AC':
            lac[p] = 1

lwa = [x * y for x, y in zip(lac, lwa)]
print(sum(lac), sum(lwa))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
lp, ls = [0] * m, [0] * m
for i in range(m):
    lp[i], ls[i] = input().split()

lpu = list(set(lp))
lac = [0] * len(lpu)
lwa = [0] * len(lpu)

for e, i in enumerate(lpu):
    if lac[e] == 0:
        for j in range(m):
            if lp[j] == i and ls[j] == 'WA':
                lwa[e] += 1
            if lp[j] == i and ls[j] == 'AC':
                lac[e] = 1
                break
        else:
            lwa[e] = 0
    else:
        break

print(sum(lac), sum(lwa))

Fixed submission:
n, m = map(int, input().split())

lac = [0] * n
lwa = [0] * n

for i in range(m):
    p, s = input().split()
    p = int(p) - 1
    if lac[p] == 0:
        if s == 'WA':
            lwa[p] += 1
        if s == 'AC':
            lac[p] = 1

lwa = [x * y for x, y in zip(lac, lwa)]
print(sum(lac), sum(lwa))

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
lp, ls = [0] * m, [0] * m
for i in range(m):
    lp[i], ls[i] = input().split()

lpu = list(set(lp))
lac = [0] * len(lpu)
lwa = [0] * len(lpu)

for e, i in enumerate(lpu):
    if lac[e] == 0:
        for j in range(m):
            if lp[j] == i and ls[j] == 'WA':
                lwa[e] += 1
            if lp[j] == i and ls[j] == 'AC':
                lac[e] = 1
                break
        else:
            lwa[e] = 0
    else:
        break

print(sum(lac), sum(lwa))

Fixed submission:
n, m = map(int, input().split())

lac = [0] * n
lwa = [0] * n

for i in range(m):
    p, s = input().split()
    p = int(p) - 1
    if lac[p] == 0:
        if s == 'WA':
            lwa[p] += 1
        if s == 'AC':
            lac[p] = 1

lwa = [x * y for x, y in zip(lac, lwa)]
print(sum(lac), sum(lwa))
Buggy python submission (verdict: Runtime Error):
mod = 10**9 + 7
n = int(input())
lx = list(map(int, input().split()))

from math import factorial as kj

d = 0
ans = 0

for i in range(1, n):
  d = (d * i + kj(i-1)) % mod
  ans = (ans * i + (lx[i] - lx[i-1]) * d) % mod

print(ans)

Fixed submission:
n = int(input())
l = [input().split() for _ in range(n)]
x = input()

flg = 0
ans = 0
for s, t in l:
    if flg == 1:
        ans += int(t)
    if s == x:
        flg = 1
print(ans)

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

from math import factorial as kj

d = 0
lk = [0] * n

for i in range(1, n):
  d += kj(n-1) // i
  lk[i] = (lx[i] - lx[i-1]) * d

print(sum(lk) % mod)

Fixed submission:
n = int(input())
l = [input().split() for _ in range(n)]
x = input()

flg = 0
ans = 0
for s, t in l:
    if flg == 1:
        ans += int(t)
    if s == x:
        flg = 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
mod = 10**9 + 7
n = int(input())
l = list(map(int, input().split()))

d = 0
ans = 0

for i in range(1, n):
  f = 1 if i == 1 else f * (i-1) % mod
  d = d * i + f
  ans = (ans * i + (l[i] - l[i-1]) * d) % mod

print(ans)

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

d = 0
ans = 0

for i in range(1, n):
  f = 1 if i == 1 else f * (i-1) % mod
  d = (d * i + f) % mod
  ans = (ans * i + (lx[i] - lx[i-1]) * d) % mod

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
mod = 10**9 + 7
n = int(input())
lx = list(map(int, input().split()))

from math import factorial as kj

d = 0
ans = 0

for i in range(1, n):
  d = (d * i + kj(i-1)) % mod
  ans = (ans * i + (lx[i] - lx[i-1]) * d) % mod

print(ans)

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

d = 0
ans = 0

for i in range(1, n):
  f = 1 if i == 1 else f * (i-1) % mod
  d = (d * i + f) % mod
  ans = (ans * i + (lx[i] - lx[i-1]) * d) % mod

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
mod = 10**9 + 7
n = int(input())
lx = list(map(int, input().split()))

from math import factorial as kj

d = 0
ans = 0

for i in range(1, n):
  d += kj(n-1) // i % mod
  ans = (ans + (lx[i] - lx[i-1]) * d) % mod

print(ans)

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

d = 0
ans = 0

for i in range(1, n):
  f = 1 if i == 1 else f * (i-1) % mod
  d = (d * i + f) % mod
  ans = (ans * i + (lx[i] - lx[i-1]) * d) % mod

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
mod = 10**9 + 7
n = int(input())
lx = list(map(int, input().split()))

from math import factorial as kj

d = 0
lk = [0] * n

for i in range(1, n):
  d += kj(n-1) // i % mod
  lk[i] = (lx[i] - lx[i-1]) * d % mod

print(sum(lk) % mod)

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

d = 0
ans = 0

for i in range(1, n):
  f = 1 if i == 1 else f * (i-1) % mod
  d = (d * i + f) % mod
  ans = (ans * i + (lx[i] - lx[i-1]) * d) % mod

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
mod = 10**9 + 7
n = int(input())
lx = list(map(int, input().split()))

from math import factorial as kj

d = 0
lk = [0] * n

for i in range(1, n):
  d += kj(n-1) // i
  lk[i] = (lx[i] - lx[i-1]) * d

print(sum(lk) % mod)

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

d = 0
ans = 0

for i in range(1, n):
  f = 1 if i == 1 else f * (i-1) % mod
  d = (d * i + f) % mod
  ans = (ans * i + (lx[i] - lx[i-1]) * d) % mod

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
mod = 10**9 + 7
n = int(input())
lx = list(map(int, input().split()))

from math import factorial as kj

d = 0
lk = [0] * n

for i in range(1, n):
  d += kj(n-1) // i
  lk[i] = (lx[i] - lx[i-1]) * d

print(sum(lk) % mod)

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

d = 0
ans = 0

for i in range(1, n):
  f = 1 if i == 1 else f * (i-1) % mod
  d = (d * i + f) % mod
  ans = (ans * i + (lx[i] - lx[i-1]) * d) % mod

print(ans)
Buggy python submission (verdict: Runtime Error):
n, m = map(int,input().split())
l = list(map(int,input().split()))
 
import math
 
def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x%y)
def lcm(x, y):
    return x * y / gcd(x, y)
 
ans = 1
tf = True
 
for i in l:
    i /= 2
    ans = lcm(ans, i)
    if (ans / i) % 2 == 0 or ans > m:
        print(0)
        tf = False
        break
 
if tf == True:
    print(math.ceil(m / (ans * 2)))

Fixed submission:
k, x = map(int, input().split())
print('Yes' if x <= 500 * k else 'No')

Buggy python submission (verdict: Runtime Error):
n, m = map(int,input().split())
l = list(map(int,input().split()))

import math

def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x%y)
def lcm(x, y):
    return x * y / gcd(x, y)

ans = 1
tf = True

for i in l:
    i /= 2
    ans = lcm(ans, i)
    if (ans / i) % 2 == 0:
        print(0)
        tf = False
        break
    if ans > m:
        print(0)
        tf = False
        break

if tf == True:
    print(math.ceil(m / (ans * 2)))

Fixed submission:
k, x = map(int, input().split())
print('Yes' if x <= 500 * k else 'No')
Buggy python submission (verdict: Time Limit Exceeded):
import math

for i in range(int(input()),100004):
  ri = math.floor(i**0.5) + 1
  for j in range(ri):
    for k in range(ri,i):
      if j*k == i:
        break
    else:
      continue
    break
  else:
    print(i)
    break

Fixed submission:
for i in range(int(input()),100004):
  for j in range(2, i):
    if i % j == 0:
      break
  else:
    print(i)
    break
Buggy python submission (verdict: Runtime Error):
n=int(input())
if n%2<1:
 a=n=n//10
 while n:n//=5;a+=n
print(a)

Fixed submission:
n=int(input())
if n%2: print(0); exit()
c=0
n//=2
while n: n//=5; c+=n
print(c)
Buggy python submission (verdict: Runtime Error):
f=lambda:map(int,input().split())
n,st,sa=f()
st-=1
sa-=1
g=[[] for _ in range(n)]
for _ in range(n-1):
  a,b=f()
  g[a-1].append(b-1)
  g[b-1].append(a-1)
def dfs(v,p=-1,d=0):
  l[v]=d
  for c in g[v]:
    if c==p: continue
    dfs(c,v,d+1)
def dist(s):
  global l
  l=[0]*n
  dfs(s)
  return l
lt=dist(st)
la=dist(sa)
m=0
for i in range(n):
  if lt[i]<la[i]: m=max(m,la[i])
print(m-1)

Fixed submission:
import sys
sys.setrecursionlimit(10**9)
f=lambda:map(int,input().split())
n,st,sa=f()
st-=1
sa-=1
g=[[] for _ in range(n)]
for _ in range(n-1):
  a,b=f()
  g[a-1].append(b-1)
  g[b-1].append(a-1)
def dfs(v,p=-1,d=0):
  l[v]=d
  for c in g[v]:
    if c==p: continue
    dfs(c,v,d+1)
def dist(s):
  global l
  l=[0]*n
  dfs(s)
  return l
lt=dist(st)
la=dist(sa)
m=0
for i in range(n):
  if lt[i]<la[i]: m=max(m,la[i])
print(m-1)