Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
A,B,C,X,Y=map(int,input().split())

if A<=2*C amd B<=2*C:
    print(A*X+B*Y)
    
else:
    if X>=Y:
        print(min(A*(X-Y)+2*C*Y,2*C*X))
    else:
        print(min(B*(Y-X)+2*C*X,2*C*Y))

Fixed submission:
A,B,C,X,Y=map(int,input().split())

if A+B<=2*C:
    print(A*X+B*Y)
    
else:
    if X>=Y:
        print(min(A*(X-Y)+C*Y*2,C*X*2))
    else:
        print(min(B*(Y-X)+C*X*2,C*Y*2))

Buggy python submission (verdict: Runtime Error):
A,B,C,X,Y=map(int,input().split())

if A<=2*C amd B<=2*C:
    print(A*X+B*Y)
    
else:
    if X>=Y:
        print(min(A*(X-Y)+2*C*Y),2*C*X)
    else:
        print(min(B*(Y-X)+2*C*X,2*C*Y))

Fixed submission:
A,B,C,X,Y=map(int,input().split())

if A+B<=2*C:
    print(A*X+B*Y)
    
else:
    if X>=Y:
        print(min(A*(X-Y)+C*Y*2,C*X*2))
    else:
        print(min(B*(Y-X)+C*X*2,C*Y*2))

Buggy python submission (verdict: Runtime Error):
A,B,C,X,Y=map(int,input().split())

if A<=2*C amd B<=2*C:
    print(A*X+B*Y)
    
else:
    if X>=Y:
        print(min(A*(X-Y)+2*C*Y),2*C*X)
    else:
        print(B*(Y-X)+2*C*X,2*C*Y)

Fixed submission:
A,B,C,X,Y=map(int,input().split())

if A+B<=2*C:
    print(A*X+B*Y)
    
else:
    if X>=Y:
        print(min(A*(X-Y)+C*Y*2,C*X*2))
    else:
        print(min(B*(Y-X)+C*X*2,C*Y*2))
Buggy python submission (verdict: Runtime Error):
N=int(input())
ans=float('inf')

for i in range(1,N**0.5+1):
    if N%i==0:
        ans=min(ans,len(str(N//i)))
print(ans)

Fixed submission:
N=int(input())
ans=float('inf')

for i in range(1,int(N**0.5+1)):
    if N%i==0:
        ans=min(ans,len(str(N//i)))
print(ans)

Buggy python submission (verdict: Runtime Error):
N=int(input())
f=[]
for i in range(1,(N+1)//2):
    if N%i==0:
        f.append(max(len(str(i)),len(str(N//i))))
print(min(f))

Fixed submission:
N=int(input())
ans=float('inf')

for i in range(1,int(N**0.5+1)):
    if N%i==0:
        ans=min(ans,len(str(N//i)))
print(ans)

Buggy python submission (verdict: Runtime Error):
N=int(input())
f=[]
for i in range(1,(N+1)//2):
    if N%i==0:
        f.append(min(len(str(i)),len(str(N//i))))
print(max(f))

Fixed submission:
N=int(input())
ans=float('inf')

for i in range(1,int(N**0.5+1)):
    if N%i==0:
        ans=min(ans,len(str(N//i)))
print(ans)

Buggy python submission (verdict: Runtime Error):
N=int(input())
f=[]
for i in range(1,(N+1)//2):
    if N%i==0:
        f.append(min(len(str(i)),len(str(N//i))))
max(f)

Fixed submission:
N=int(input())
ans=float('inf')

for i in range(1,int(N**0.5+1)):
    if N%i==0:
        ans=min(ans,len(str(N//i)))
print(ans)
Buggy python submission (verdict: Runtime Error):
s=input

a=s.find('A')
z=s.rfind('Z')

print(z-a)


Fixed submission:
s=input()

a=s.find('A')
z=s.rfind('Z')

print(z-a+1)
Buggy python submission (verdict: Runtime Error):
x = int(input())

if(x == 0):
    print('1')
elif(x == 1):
    print('0')
else:

Fixed submission:
x = int(input())

if(x == 0):
    print('1')
elif(x == 1):
    print('0')
else:
    pass
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = []
A = input().split()
ans = 1

for x in range(N):
    for y in range(N):
        if(x == y):
            continue
        if(A[x] == A[y]):
            ans = 0
            break

if(ans == 1):
    print("YES")
else:
    print("NO")

Fixed submission:
S, T = map(str,input().split())
A, B = map(int,input().split())
U = str(input())

if(S == U):
    A -= 1
elif(T == U):
    B -= 1
else:
    A
    B
    
print("{} {}".format(A, B))
Buggy python submission (verdict: Runtime Error):
import random

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

X = A[0]
Y = A[1]
Z = 0
for a in A[2:]:
  Z ^= a

if ((X^Y)&1)!=(Z&1):
  print(-1)
  exit(1)

def solve(X2, Y2):
  if ((X2^Y2)&1)!=(Z&1):
    return -1
  d = 0
  for i in range(1, 100):
    if (((X2-d)^(Y2+d))>>i&1)!=(Z>>i&1):
      d += 1<<(i-1)
  if d<X2:
    return d
  else:
    return -1

ans = solve(X, Y)
for i in range(10000):
  if ans<=2:
    break
  r = random.randint(1, ans-1)
  a = solve(X-r, Y+r)
  if a!=-1 and r+a<ans:
    ans = r+a
print(ans)


Fixed submission:
import random

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

S = A[0]+A[1]
X = 0
for a in A[2:]:
  X ^= a

D = (S-X)>>1
if S!=X+(D<<1) or D>A[0] or (X&D)!=0:
  print(-1)
  exit(0)

a = 0
b = 2**64
while b>0:
  if (D&b)!=0:
    a |= b
  elif (X&b)!=0:
    if (a|b|D&(b-1))<=A[0]:
      a |= b
  b >>= 1
if a==0:
  print(-1)
  exit(0)
print(A[0]-a)
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())
E = [[] for _ in range(N)]
for _ in range(M):
  A, B = map(int, input().split())
  E[A-1] += [B-1]
  E[B-1] += [A-1]

ans = [-1]*N
T = [0]
while len(T)>0:
  P = T
  T = []
  for x in P:
    for e in E[x]:
      if ans[e]==-1:
        T += [e]
        ans[e] = x

print "Yes"
for a in ans[1:]:
  print(a+1)


Fixed submission:
N, M = map(int, input().split())
E = [[] for _ in range(N)]
for _ in range(M):
  A, B = map(int, input().split())
  E[A-1] += [B-1]
  E[B-1] += [A-1]

ans = [-1]*N
T = [0]
while len(T)>0:
  P = T
  T = []
  for x in P:
    for e in E[x]:
      if ans[e]==-1:
        T += [e]
        ans[e] = x

print("Yes")
for a in ans[1:]:
  print(a+1)
Buggy python submission (verdict: Runtime Error):
S = raw_input()
print "Bad" if A[0]==A[1] or A[1]==A[2] or A[2]==A[3] else "Good"


Fixed submission:
S = raw_input()
print "Bad" if S[0]==S[1] or S[1]==S[2] or S[2]==S[3] else "Good"
Buggy python submission (verdict: Runtime Error):
N, K = map(int, raw_input().split())

if K<=(N-1)*(N-2)/2:
  exit(-1)
else:
  print "-1"


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

if K<=(N-1)*(N-2)/2:
  E = []
  for i in range(N-1):
    for j in range(i):
      E += [(j, i)]
  E = E[:(N-1)*(N-2)/2-K]
  for i in range(N-1):
    E += [(i, N-1)]
  print len(E)
  for e in E:
    print e[0]+1, e[1]+1
else:
  print "-1"

Buggy python submission (verdict: Runtime Error):
N, K = map(int, raw_input().split())

if N-2<=K<=(N-1)*(N-2)/2:
  exit(-1)
else:
  print "-1"


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

if K<=(N-1)*(N-2)/2:
  E = []
  for i in range(N-1):
    for j in range(i):
      E += [(j, i)]
  E = E[:(N-1)*(N-2)/2-K]
  for i in range(N-1):
    E += [(i, N-1)]
  print len(E)
  for e in E:
    print e[0]+1, e[1]+1
else:
  print "-1"
Buggy python submission (verdict: Runtime Error):
N, M = map(int, raw_input().split())
S = [True]*(N+1)
for _ in range(M):
  a = input()
  S[a] = False
T = [0]*(N+1)
T[0] = 1
T[1] = 1 if S[1] else 0
for i in range(2, N+1):
  if S[i]:
    T[i] = (T[i-1]+T[i-2])%1000000007
print(T[N])

Fixed submission:
N, M = map(int, raw_input().split())
S = [True]*(N+1)
for _ in range(M):
  a = input()
  S[a] = False
T = [0]*(N+1)
T[0] = 1
T[1] = 1 if S[1] else 0
for i in range(2, N+1):
  if S[i]:
    T[i] = (T[i-1]+T[i-2])%1000000007
print T[N]

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, raw_input().split())
S = [True]*(N+1)
for _ in range(M):
  a = input()
  S[a] = False
T = [0]*(N+1)
T[0] = 1
T[1] = 1 if S[1] else 0
for i in range(2, N+1):
  if S[i]:
    T[i] = (T[i-1]+T[i-2])%1000000007
print T[N]

Fixed submission:
N, M = map(int, raw_input().split())
S = [True]*(N+1)
for _ in range(M):
  a = input()
  S[a] = False
T = [0]*(N+1)
T[0] = 1
T[1] = 1 if S[1] else 0
for i in range(2, N+1):
  if S[i]:
    T[i] = (T[i-1]+T[i-2])%1000000007
print T[N]
Buggy python submission (verdict: Runtime Error):
A, B = map(int, raw_input())
if A<=5:
  print 0
elif A<=12:
  print B/2
else:
  print B


Fixed submission:
A, B = map(int, raw_input().split())
if A<=5:
  print 0
elif A<=12:
  print B/2
else:
  print B
Buggy python submission (verdict: Runtime Error):
ans=0
for s not in raw_input():
  if s in "ACGT":
    ans+=1
print ans


Fixed submission:
s=-1
S=raw_input()+"!"
ans=0
for i in range(len(S)):
  if S[i]in "ATCG":
    if s==-1:
      s=i
  elif s!=-1:
    ans=max(ans, i-s)
    s=-1
print ans

Buggy python submission (verdict: Runtime Error):
ans=0
for s in raw_input():
  if s in “ACGT”:
    ans+=1
print ans

Fixed submission:
s=-1
S=raw_input()+"!"
ans=0
for i in range(len(S)):
  if S[i]in "ATCG":
    if s==-1:
      s=i
  elif s!=-1:
    ans=max(ans, i-s)
    s=-1
print ans
Buggy python submission (verdict: Runtime Error):
N, M = map(int, raw_input().split())
E = [[] for _ in range(N)]
for _ in range(M):
  a, b = map(int, raw_input().split())
  E[a-1] += [b-1]
  E[b-1] += [a-1]

ok = True
for e in E:
  if len(e)%2!=0:
    ok = False
if not ok:
  print "No"
  exit(0)

ok = False
for e in E:
  if len(e)>=6:
    ok = True
if ok:
  print "Yes"
  exit(0)

c = 0
for e in E:
  if len(e)==4:
    c += 1
if c>=3:
  print "Yes"
  exit(0)
if c<=1:
  print "No"
  exit(0)

for i in range(len(E)):
  if len(E[i])==4:
    c = 0
    for v in E[i]:
      p = i
      while len(v)==2:
        if E[v][0]==p:
          p = v
          v = E[v][1]
        else:
          p = v
          v = E[v][0]
      if v==i:
        c += 1
    if c==2:
      print "Yes"
      exit(0)
    else:
      print "No"
      exit(0)


Fixed submission:
N, M = map(int, raw_input().split())
E = [[] for _ in range(N)]
for _ in range(M):
  a, b = map(int, raw_input().split())
  E[a-1] += [b-1]
  E[b-1] += [a-1]

ok = True
for e in E:
  if len(e)%2!=0:
    ok = False
if not ok:
  print "No"
  exit(0)

ok = False
for e in E:
  if len(e)>=6:
    ok = True
if ok:
  print "Yes"
  exit(0)

c = 0
for e in E:
  if len(e)==4:
    c += 1
if c>=3:
  print "Yes"
  exit(0)
if c<=1:
  print "No"
  exit(0)

for i in range(len(E)):
  if len(E[i])==4:
    c = 0
    for v in E[i]:
      p = i
      while len(E[v])==2:
        if E[v][0]==p:
          p = v
          v = E[v][1]
        else:
          p = v
          v = E[v][0]
      if v==i:
        c += 1
    if c==2:
      print "Yes"
      exit(0)
    else:
      print "No"
      exit(0)
Buggy python submission (verdict: Runtime Error):
N,M = map(int, raw_input().split())
A = map(int, raw_input().split())

C = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]

T = [(-10**8,0)]*(N+1)
T[0] = (0, 0)
for i in range(1, N+1):
  for a in A:
    if C[a]>=0:
      T[i] = max(T[i], (T[i-C[a]][0]+1, a))

ans = ""
p = N
while p>0:
  ans += str(T[p][1])
  p -= C[T[p][1]]
print ans


Fixed submission:
N,M = map(int, raw_input().split())
A = map(int, raw_input().split())

C = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]

T = [(-10**8,0)]*(N+1)
T[0] = (0, 0)
for i in range(1, N+1):
  for a in A:
    if i-C[a]>=0:
      T[i] = max(T[i], (T[i-C[a]][0]+1, a))

ans = ""
p = N
while p>0:
  ans += str(T[p][1])
  p -= C[T[p][1]]
print ans

Buggy python submission (verdict: Runtime Error):
N,M = map(int, raw_input().split())
A = sorted(map(int, raw_input().split()))

C = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]

T = [(-10**8,0)]*(N+1)
T[0] = (0, 0)
for i in range(1, N+1):
  for a in A:
    if C[a]>=0 and T[i-C[a]][0]+1 >= T[i][0]:
      T[i] = (T[i-C[a]][0]+1, a)

ans = ""
p = N
while p>0:
  ans += str(T[p][1])
  p -= C[T[p][1]]
print ans


Fixed submission:
N,M = map(int, raw_input().split())
A = map(int, raw_input().split())

C = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]

T = [(-10**8,0)]*(N+1)
T[0] = (0, 0)
for i in range(1, N+1):
  for a in A:
    if i-C[a]>=0:
      T[i] = max(T[i], (T[i-C[a]][0]+1, a))

ans = ""
p = N
while p>0:
  ans += str(T[p][1])
  p -= C[T[p][1]]
print ans
Buggy python submission (verdict: Runtime Error):
# coding: utf-8

"""

o 999
o 2 3
x 2 0 2
o 2 1 2
x 2 1 2 1
o 2 1 3 1
o 2 1 3 2
o 3 1 3
x 3 2 3
o 3 2 2

- 0は両端のみ
- 偶奇の切り替わりが2回以下

zzoo
zzee
zzooee
zzeeoo
zzooeeoo xxx
zzeeooee
zz
???zz
"""

ooeeooee
L = input()
A = [input() for _ in range(L)]

T = [L,L,L,L,L,L,0,L]
for a in A:
  P = T
  o = 1-a%2
  e = 1-o
  if a==0:
    e = 2
  T = [
    min(P[0]+o, P[6]+o),
    min(P[1]+e, P[6]+e),
    min(P[2]+e, P[0]+e),
    min(P[3]+o, P[1]+o),
    min(P[4]+o, P[2]+o),
    min(P[5]+e, P[3]+e),
    P[6]+a,
    min(P)+a,
  ]
  #print a, T
print min(T[4:]+T[5:])



Fixed submission:
# coding: utf-8

"""

o 999
o 2 3
x 2 0 2
o 2 1 2
x 2 1 2 1
o 2 1 3 1
o 2 1 3 2
o 3 1 3
x 3 2 3
o 3 2 2

- 0は両端のみ
- 偶奇の切り替わりが2回以下

0 zzoo
1 zzee
2 zzooee
3 zzeeoo
4 zzeeooee
5 zz
6 ???zz
"""

L = input()
A = [input() for _ in range(L)]

T = [L,L,L,L,L,0,L]
for a in A:
  P = T
  o = 1-a%2
  e = 1-o
  if a==0:
    e = 2
  T = [
    min(P[0]+o, P[5]+o),
    min(P[1]+e, P[5]+e),
    min(P[2]+e, P[0]+e),
    min(P[3]+o, P[1]+o),
    min(P[4]+e, P[3]+e),
    P[5]+a,
    min(P)+a,
  ]
  #print a, T
print min(T)
Buggy python submission (verdict: Runtime Error):
N,X = map(int, raw_input().split())
A = [0]*N
B = [0]*N
A[0] = 1
B[0] = 1
for i in range(1,N):
  A[i] = 2*A[i-1]+3
  B[i] = 2*B[i-1]+1

def f(N,X):
  if N==0:
    return 1
  if X<=1:
    return 0
  if X<=1+A[N-1]:
    return f(N-1, X-1)
  if X<=1+A[N-1]+1:
    return B[N-1]+1
  if X<=1+A[N-1]+1+A[N-1]:
    return B[N-1]+1+f(N-1, X-2-A[N-1])
  if X<=1+A[N-1]+1+A[N-1]<=1:
    return 2*B[N-1]+1
  print N,X

print f(N,X)


Fixed submission:
N,X = map(int, raw_input().split())
A = [0]*N
B = [0]*N
A[0] = 1
B[0] = 1
for i in range(1,N):
  A[i] = 2*A[i-1]+3
  B[i] = 2*B[i-1]+1

def f(N,X):
  if N==0:
    return 1
  if X<=1:
    return 0
  if X<=1+A[N-1]:
    return f(N-1, X-1)
  if X<=1+A[N-1]+1:
    return B[N-1]+1
  if X<=1+A[N-1]+1+A[N-1]:
    return B[N-1]+1+f(N-1, X-2-A[N-1])
  if X<=1+A[N-1]+1+A[N-1]+1:
    return 2*B[N-1]+1
  print N,X

print f(N,X)
Buggy python submission (verdict: Runtime Error):
N = input()
A = map(int, raw_input().split())

"""
import itertools

ans = 0
for p in itertools.permutations(range(N)):
  F = [True]*N
  for i in range(N):
    ans += A[p[i]]
    F[p[i]] = False
    t = p[i]-1
    while 0<=t and F[t]:
      ans += A[t]
      t -= 1
    t = p[i]+1
    while t<N and F[t]:
      ans += A[t]
      t += 1
print ans
"""

M = 10**9+7

F = [0]*(N+1)
F[0] = 1
for i in range(1,N+1):
  F[i] = F[i-1]*i%M

R = [0]*(N+1)
for i in range(1,N+1):
  R[i] = pow(i, M-2, M)

T = [F[N]]*N
for i in range(N):
  T[i] = T[i]*R[i+1]%M

ans = 0
x = sum(T)
for i in range((N+1)/2):
  ans += (A[i] + (A[N-i-1] if N-i-1!=i else 0))*x
  ans %= M
  x -= T[-i-1]
  x += T[i+1]
  x %= M
print ans


Fixed submission:
N = input()
A = map(int, raw_input().split())

"""
import itertools

ans = 0
for p in itertools.permutations(range(N)):
  F = [True]*N
  for i in range(N):
    ans += A[p[i]]
    F[p[i]] = False
    t = p[i]-1
    while 0<=t and F[t]:
      ans += A[t]
      t -= 1
    t = p[i]+1
    while t<N and F[t]:
      ans += A[t]
      t += 1
print ans
"""

if N==1:
  print A[0]
  exit(0)

M = 10**9+7

F = [0]*(N+1)
F[0] = 1
for i in range(1,N+1):
  F[i] = F[i-1]*i%M

R = [0]*(N+1)
for i in range(1,N+1):
  R[i] = pow(i, M-2, M)

T = [F[N]]*N
for i in range(N):
  T[i] = T[i]*R[i+1]%M

ans = 0
x = sum(T)
for i in range((N+1)/2):
  ans += (A[i] + (A[N-i-1] if N-i-1!=i else 0))*x
  ans %= M
  x -= T[-i-1]
  x += T[i+1]
  x %= M
print ans
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int, raw_input().split())
MOD = 10**9+7
 
F = [0]*100100
F[0] = 1
for i in range(1,100100):
  F[i] = i*F[i-1]%MOD
 
ans = 1
d = 2
while M>1:
  c = 0
  while M%d==0:
    M /= d
    c += 1
  if c>0:
    ans *= F[N+c-1]
    ans %= MOD
    ans *= pow(F[N-1], MOD-2, MOD)
    ans %= MOD
    ans *= pow(F[c], MOD-2, MOD)
    ans %= MOD
  d += 1

print ans

Fixed submission:
N,M = map(int, raw_input().split())
MOD = 10**9+7

F = [0]*100100
F[0] = 1
for i in range(1,100100):
  F[i] = i*F[i-1]%MOD

ans = 1
d = 2
while M>1:
  c = 0
  while M%d==0:
    M /= d
    c += 1
  if c>0:
    ans *= F[N+c-1]
    ans %= MOD
    ans *= pow(F[N-1], MOD-2, MOD)
    ans %= MOD
    ans *= pow(F[c], MOD-2, MOD)
    ans %= MOD
  d += 1
  if d*d>M:
    d = M

print ans
Buggy python submission (verdict: Runtime Error):
import os
A,B = map(int, os.system("dd").split())
print (A-1)*(B-1)


Fixed submission:
A,B = map(int, raw_input().split())
print (A-1)*(B-1)
Buggy python submission (verdict: Runtime Error):
def solve(A,B):
  if A==B:
    return 0,A[:]
  a1 = 0
  for p1 in range(len(A)):
    if A[p1]>0:
      A[p1] -= 1
      a2 = 9999
      for p2 in range(len(B)):
        if B[p2]>0:
          B[p2] -= 1
          a,b = solve(A,B)
          a += 1
          if a<a2:
            a2 = a
            b2 = b
          B[p2] += 1
      if a2>a1:
        a1 = a2
        b1 = b2
      A[p1] += 1
  return a1,b2

#print solve([1,3], [2,2]) # (2, [1, 2])
#print solve([8,0,4], [3,1,8]) # (9, [3,0,0])
#print solve([3,3,1,1], [1,1,3,3]) # (7, [1, 0, 0, 0])
#print solve([4,3,1,1], [2,1,3,3]) # (8, [1, 0, 0, 0])
#print solve([2,2,3,1], [2,2,1,3]) # (7, [1, 0, 0, 0])

N = input()
A,B = [0]*N, [0]*N
for i in range(N):
  A[i], B[i] = map(int, raw_input().split())
c = 0
p = 0
for i in range(N):
  if A[i]>B[i]:
    c += 1
    p = i
if c==0:
  print 0
elif c==1:
  print sum(B)-B[p],1/0
else:
  print sum(A)-1


Fixed submission:
def solve(A,B):
  if A==B:
    return 0,A[:]
  a1 = 0
  for p1 in range(len(A)):
    if A[p1]>0:
      A[p1] -= 1
      a2 = 9999
      for p2 in range(len(B)):
        if B[p2]>0:
          B[p2] -= 1
          a,b = solve(A,B)
          a += 1
          if a<a2:
            a2 = a
            b2 = b
          B[p2] += 1
      if a2>a1:
        a1 = a2
        b1 = b2
      A[p1] += 1
  return a1,b2

#print solve([1,3], [2,2]) # (2, [1, 2])
#print solve([8,0,4], [3,1,8]) # (9, [3,0,0])
#print solve([3,3,1,1], [1,1,3,3]) # (7, [1, 0, 0, 0])
#print solve([4,3,1,1], [2,1,3,3]) # (8, [1, 0, 0, 0])
#print solve([2,2,3,1], [2,2,1,3]) # (7, [1, 0, 0, 0])
#print solve([2,2,2,0], [1,1,1,3]) # (5, [1, 0, 0, 0])
#print solve([1,1,1,0], [0,0,0,3]) # (3, [0, 0, 0, 0])
#print solve([1,2,1,0], [0,1,0,3]) # (4, [0, 0, 0, 0])
#print solve([1,2,2,0], [0,1,1,3]) # (5, [0, 0, 0, 0])
#print solve([3,3,3,0], [2,2,2,3]) # (7, [2, 0, 0, 0])

N = input()
A,B = [0]*N, [0]*N
for i in range(N):
  A[i], B[i] = map(int, raw_input().split())
t = 9999999999
for i in range(N):
  if A[i]>B[i]:
    t = min(t, B[i])
if t==9999999999:
  print 0
else:
  print sum(B)-t
Buggy python submission (verdict: Time Limit Exceeded):
import sys

test = False
N = 100

def check(n):
    if test:
        if n<=N and str(n)<=str(N) or n>N and str(n)>str(N):
            return "Y"
        else:
            return "N"
    else:
        print "?", n
        return raw_input()

for d in range(11):
    if check(10**d)=="N":
        d -= 1
        break
if d==10:
    for i in range(1,11):
        if check(10**i-1)=="Y":
            print "!", 10**(i-1)
            break
else:
    l = 10**d
    r = 10**(d+1)
    while r-l>1:
        m = (l+r)/2
        if check(m*10)=="Y":
            r = m
        else:
            l = m
    print "!", r
sys.stdout.flush()


Fixed submission:
import sys

test = False
N = 100

def check(n):
    if test:
        if n<=N and str(n)<=str(N) or n>N and str(n)>str(N):
            return "Y"
        else:
            return "N"
    else:
        print "?", n
        sys.stdout.flush()
        return raw_input()

for d in range(11):
    if check(10**d)=="N":
        d -= 1
        break
if d==10:
    for i in range(1,11):
        if check(10**i-1)=="Y":
            print "!", 10**(i-1)
            break
else:
    l = 10**d
    r = 10**(d+1)
    while r-l>1:
        m = (l+r)/2
        if check(m*10)=="Y":
            r = m
        else:
            l = m
    print "!", r
sys.stdout.flush()
Buggy python submission (verdict: Runtime Error):
N = input()
a = map(int, raw_input().split())

if max(a)-min(a)>=2:
  print "No"
elif max(a)-min(a)==0:
  if N>=2*a[0] or N==a[0]+1:
    print "Yes"
  else:
    print "No"
else:
  if a.count(max(a))>=2 and a.count(min(a))==min(a):
    print "Yes"
  else:
    exit(-1)
    print "No"


Fixed submission:
N = input()
a = map(int, raw_input().split())

if max(a)-min(a)>=2:
  print "No"
elif max(a)-min(a)==0:
  if N>=2*a[0] or N==a[0]+1:
    print "Yes"
  else:
    print "No"
else:
  cn = max(a)-a.count(min(a))
  if a.count(max(a))>=2 and cn>0 and N>=a.count(min(a))+2*cn:
    print "Yes"
  else:
    print "No"

Buggy python submission (verdict: Runtime Error):
N = input()
a = map(int, raw_input().split())

if max(a)-min(a)>=2:
  exit(-1)
  print "No"
elif max(a)-min(a)==0:
  exit(-1)
  if N>=2*a[0] or N==a[0]+1:
    print "Yes"
  else:
    print "No"
else:
  if a.count(max(a))>=2 and a.count(min(a))==min(a):
    print "Yes"
  else:
    print "No"


Fixed submission:
N = input()
a = map(int, raw_input().split())

if max(a)-min(a)>=2:
  print "No"
elif max(a)-min(a)==0:
  if N>=2*a[0] or N==a[0]+1:
    print "Yes"
  else:
    print "No"
else:
  cn = max(a)-a.count(min(a))
  if a.count(max(a))>=2 and cn>0 and N>=a.count(min(a))+2*cn:
    print "Yes"
  else:
    print "No"
Buggy python submission (verdict: Runtime Error):
s=raw_input()
print "First"if len(s)%2^s[0]==s[-1]else"Second"

Fixed submission:
s=raw_input()
print"First"if len(s)%2^int(s[0]==s[-1])else"Second"
Buggy python submission (verdict: Runtime Error):
N = int(input())
print(N*N*N)

Fixed submission:
N = input()
if N == 'Rainy':
 print('Sunny')
elif N == 'Sunny':
 print('Cloudy')
elif N == 'Cloudy':
  print('Rainy')
Buggy python submission (verdict: Runtime Error):
l = [int(x) for x in input().split()]
l = sorted(l)
if l.count(5)==2 and l.count(7)==1:
  print("YES")
else:
  print("NO"

Fixed submission:
l = [int(x) for x in input().split()]
l = sorted(l)
if l.count(5)==2 and l.count(7)==1:
  print("YES")
else:
  print("NO")
Buggy python submission (verdict: Runtime Error):
import numpy as np

n = int(input())
a = list(map(int, input().split()))
zenbu = sum(a)
ans = 0

for i in range(n):
  ans += a[i]*(zenbu-a[i])
 
print(ans // 2 % (1000000000+7))

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
zenbu = sum(a)
ans = 0

for i in range(n):
  ans += a[i]*(zenbu-a[i])
 
print(ans // 2 % 1000000007)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

ans = 0

for i in range(n):
  ans += a[i]*sum(a[i+1:n])
  ans %= 1000000000+7
  
print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
zenbu = sum(a)
ans = 0

for i in range(n):
  ans += a[i]*(zenbu-a[i])
 
print(ans // 2 % 1000000007)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

ans = sum([a[i]*sum(a[i+1:n]) for i in range(n)])
  
print(ans % (1000000000+7))


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
zenbu = sum(a)
ans = 0

for i in range(n):
  ans += a[i]*(zenbu-a[i])
 
print(ans // 2 % 1000000007)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

ans = 0

for i in range(n):
  ans += a[i]*sum(a[i+1:n])
  
print(ans % (1000000000+7))

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
zenbu = sum(a)
ans = 0

for i in range(n):
  ans += a[i]*(zenbu-a[i])
 
print(ans // 2 % 1000000007)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

ans = 0

for i in range(n-1):
  for j in range(i+1, n):
    ans += a[i]*a[j]
  
print(ans % (1000000000+7))

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
zenbu = sum(a)
ans = 0

for i in range(n):
  ans += a[i]*(zenbu-a[i])
 
print(ans // 2 % 1000000007)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

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

kumiawase = list(itertools.combinations(a, 2))
ans = 0

for i in range(len(kumiawase)):
  ans += kumiawase[i][0] * kumiawase[i][1]
  
print(ans % (1000000000+7))

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
zenbu = sum(a)
ans = 0

for i in range(n):
  ans += a[i]*(zenbu-a[i])
 
print(ans // 2 % 1000000007)