Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
import math
#from functools import reduce

k = int(input())

lis = [(0)] * (250*250)
ans = 0
for a in range(1,k+1):
  for b in range(1,k+1):
    for c in range(1,k+1):
      x = math.gcd(b,c)
      lis[b + (250*c)] = (x)
      ans += lis[a + (250*x)]

print(ans)


Fixed submission:
from math import gcd
#from functools import reduce

k = int(input())

ans = 0
for a in range(1,k+1):
  for b in range(1,k+1):
    for c in range(1,k+1):
      ans += gcd(gcd(b,c),a)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

k = int(input())
ans = 0
for a in range(1,k+1):
  for b in range(1,k+1):
    for c in range(1,k+1):
      ans += gcd(a,b,c)

print(ans)

Fixed submission:
from math import gcd
#from functools import reduce

k = int(input())

ans = 0
for a in range(1,k+1):
  for b in range(1,k+1):
    for c in range(1,k+1):
      ans += gcd(gcd(b,c),a)

print(ans)
Buggy python submission (verdict: Runtime Error):
S = input()

if (s=='AAA') or (S=='BBB'):
  print('No')
  exit()
else:
  print('Yes')

Fixed submission:
s = input()

if (s == 'AAA' ) or (s == 'BBB') :
  print('No')
else:
  print('Yes')
Buggy python submission (verdict: Time Limit Exceeded):

s = input()
q = int(input())
t = []
 
def F(f,ans,c):
  if f == '1':
     return c + ans
  if f == '2':
    return ans + c
 
def R(r):
  if r == '1':return '2'
  if r == '2':return '1'
 
ans = s
r = '1'
for n in range(q):
  t = input().split()
  if t[0] == '1':
    r = R(r)
  else:
    if r =='2':
      t[1] = R(t[1])
    ans = F(t[1],ans,t[2])
 
    
if r == '1': 
   print(ans)
else:
  print(ans[::-1])

Fixed submission:

s = input()
q = int(input())
t = []
 
def F(f,fr,ba,c):
  if f == '1':
     return c + fr, ba
  if f == '2':
    return fr,ba + c

def R(r):
  if r == '1':return '2'
  if r == '2':return '1'

ans = s
fr = ''
ba = ''
r = '1'
for n in range(q):
  t = input().split()
  if t[0] == '1':
    r = R(r)
  else:
    if r =='2':
      t[1] = R(t[1])
    fr, ba = F(t[1],fr,ba,t[2])
 
    
if r == '1': 
   print(fr + ans + ba)
else:
  print(ba[::-1] + ans[::-1]+ fr[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
t = []

def F(f,fr,ba,c):
  if f == '1':
     return c + fr, ba
  if f == '2':
    return fr, ba + c

def R(r):
  if r == '1':return '2'
  if r == '2':return '1'

fr = ''
ba = ''
r = '1'
for n in range(q):
  t = input().split()
  if t[0] == '1':
    r = R(r)
  else:
    if r =='2':
      t[1] = R(t[1])
    fr,ba = F(t[1],fr,ba,t[2])


    
if r == '1': 
   print(fr + s + ba)
else:
  a = ''
  ans = fr + s + ba
  for n in ans:
    a = n + a
  print(a)



Fixed submission:

s = input()
q = int(input())
t = []
 
def F(f,fr,ba,c):
  if f == '1':
     return c + fr, ba
  if f == '2':
    return fr,ba + c

def R(r):
  if r == '1':return '2'
  if r == '2':return '1'

ans = s
fr = ''
ba = ''
r = '1'
for n in range(q):
  t = input().split()
  if t[0] == '1':
    r = R(r)
  else:
    if r =='2':
      t[1] = R(t[1])
    fr, ba = F(t[1],fr,ba,t[2])
 
    
if r == '1': 
   print(fr + ans + ba)
else:
  print(ba[::-1] + ans[::-1]+ fr[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
s = input()
q = int(input())
t = []

def F(f,ans,c):
  if f == '1':
     return c + ans
  if f == '2':
    return ans + c

def R(r):
  if r == '1':return '2'
  if r == '2':return '1'

ans = s
r = '1'
for n in range(q):
  t = input().split()
  if t[0] == '1':
    r = R(r)
  else:
    if r =='2':
      t[1] = R(t[1])
    ans = F(t[1],ans,t[2])

    
if r == '1': 
   print(ans)
else:
  a = ''
  for n in ans:
    a = n + a
  print(a)

Fixed submission:

s = input()
q = int(input())
t = []
 
def F(f,fr,ba,c):
  if f == '1':
     return c + fr, ba
  if f == '2':
    return fr,ba + c

def R(r):
  if r == '1':return '2'
  if r == '2':return '1'

ans = s
fr = ''
ba = ''
r = '1'
for n in range(q):
  t = input().split()
  if t[0] == '1':
    r = R(r)
  else:
    if r =='2':
      t[1] = R(t[1])
    fr, ba = F(t[1],fr,ba,t[2])
 
    
if r == '1': 
   print(fr + ans + ba)
else:
  print(ba[::-1] + ans[::-1]+ fr[::-1])
Buggy python submission (verdict: Runtime Error):
N,M = list(map(int,input().split()))
SC = [0]*(M+1)
if M == 0:
  print(1*10**(N-1))
  exit()
for m in range(M):
  sc = list(map(int,input().split()))
  if (sc[0] == 1) and (sc[1] == 0):
    print(-1)
    exit()
  elif sc[0] > N:
    print(-1)
    exit()
  elif SC[sc[0]] == 0:
    SC[sc[0]] = sc[1]
  else:
    if SC[sc[0]] != sc[1]:
      print(-1)
      exit()


if SC[1]==0:
  SC[1] = 1
ans = 0
for i in range(N):
  ans += 10**(N-i-1)*SC[i+1]

print(ans)

Fixed submission:
N,M = list(map(int,input().split()))
SC = [0]*(N+1)
if M == 0:
  if N==1:
    print(0)
    exit()
  else:
    print(1*10**(N-1))
    exit()

for m in range(M):
  sc = list(map(int,input().split()))
  if (sc[0] == 1) and (sc[1] == 0):
    if N==1:
      continue
    else:
      print(-1)
      exit()
  elif sc[0] > N:
    print(-1)
    exit()
  elif SC[sc[0]] == 0:
    SC[sc[0]] = sc[1]
  else:
    if SC[sc[0]] != sc[1]:
      print(-1)
      exit()

if (SC[1]==0) and (N > 1):
  SC[1] = 1
ans = 0
for i in range(N):
  ans += 10**(N-i-1)*SC[i+1]

print(ans)

Buggy python submission (verdict: Runtime Error):
N,M = list(map(int,input().split()))
SC = [0]*(M+1)
for m in range(M):
  sc = list(map(int,input().split()))
  if (sc[0] == 1) and (sc[1] == 0):
    print(-1)
    exit()
  if sc[0] > N:
    print(-1)
    exit()
  if SC[sc[0]] == 0:
    SC[sc[0]] = sc[1]
  else:
    if SC[sc[0]] != sc[1]:
      print(-1)
      exit()


if SC[1]==0:
  SC[1] = 1
ans = 0
for i in range(N):
  ans += 10**(N-i-1)*SC[i+1]

print(ans)


Fixed submission:
N,M = list(map(int,input().split()))
SC = [0]*(N+1)
if M == 0:
  if N==1:
    print(0)
    exit()
  else:
    print(1*10**(N-1))
    exit()

for m in range(M):
  sc = list(map(int,input().split()))
  if (sc[0] == 1) and (sc[1] == 0):
    if N==1:
      continue
    else:
      print(-1)
      exit()
  elif sc[0] > N:
    print(-1)
    exit()
  elif SC[sc[0]] == 0:
    SC[sc[0]] = sc[1]
  else:
    if SC[sc[0]] != sc[1]:
      print(-1)
      exit()

if (SC[1]==0) and (N > 1):
  SC[1] = 1
ans = 0
for i in range(N):
  ans += 10**(N-i-1)*SC[i+1]

print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
P = list(map(int,input().split()))

res = [False for x in range(N)]
for i in range(1,N):
  if P[i-1] >= P[i] :
    res[i] = True

print(int(sum(res)+1))

Fixed submission:
a,b = list(map(int,input().split()))

ab = str(a) *b
ba = str(b) *a

print(min([ab,ba]))

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

res = [False for x in range(N)]
for i in range(1,N):
  if P[i-1] >= P[i] :
    res[i] = True
  
print(sum(res)+1)

Fixed submission:
a,b = list(map(int,input().split()))

ab = str(a) *b
ba = str(b) *a

print(min([ab,ba]))

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

res = [False for x in range(N)]
for i in range(1,N):
  if P[i-1] > P[i] :
    res[i] = True
  
print(sum(res)+1)

Fixed submission:
a,b = list(map(int,input().split()))

ab = str(a) *b
ba = str(b) *a

print(min([ab,ba]))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = [x for x in input()]

def p(S):
  s = len(S)
  e = 0
  while s != e:
    s = len(S)
    for i in range(s-1):
      if i >= len(S)-1:break
      if S[i] == S[i+1]:S.pop(i)
      e = len(S)
  return len(S)

print(p(S))


Fixed submission:
N = int(input())
S = [x for x in input()]

def p(S):
  s = len(S)
  e = 0
  cnt = 0
  while s != e:
    cnt += 1
    if cnt > N:break
    s = len(S)
    for i in range(s-1):
      if i >= len(S)-1:break
      if S[i] == S[i+1]:S.pop(i)
      e = len(S)
  return len(S)

print(p(S))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
S = [x for x in S]

s = len(S)
e = 0
while s != e:
  s = len(S)
  for i in range(len(S)-1):
    if i >= len(S)-1:break
    if S[i] == S[i+1]:
      S = S[:i] + S[i+1:]
    e = len(S)

print(len(S))

Fixed submission:
N = int(input())
S = [x for x in input()]

def p(S):
  s = len(S)
  e = 0
  cnt = 0
  while s != e:
    cnt += 1
    if cnt > N:break
    s = len(S)
    for i in range(s-1):
      if i >= len(S)-1:break
      if S[i] == S[i+1]:S.pop(i)
      e = len(S)
  return len(S)

print(p(S))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
S = [x for x in S]

s = len(S)
e = 0
while s != e:
  s = len(S)
  for i in range(len(S)-1):
    if i >= len(S)-1:break
    if S[i] == S[i+1]:S.pop(i)
    e = len(S)

print(len(S))


Fixed submission:
N = int(input())
S = [x for x in input()]

def p(S):
  s = len(S)
  e = 0
  cnt = 0
  while s != e:
    cnt += 1
    if cnt > N:break
    s = len(S)
    for i in range(s-1):
      if i >= len(S)-1:break
      if S[i] == S[i+1]:S.pop(i)
      e = len(S)
  return len(S)

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

dict = {}
ni=1
for ai in list(a):
    dict[ai] = ni
    ni = ni +1

ans = ''
for x in dict.values():
    ans = ans + str(x)+ ' '

print(ans)

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

dict = {}
ni=1
for ai in list(a):
    dict[ai] = ni
    ni = ni +1

print(*list(dict.values()))
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int, input().split())
A = []
comp = sum(10**(x-1) for x in range(1,N+1))
for m in range(M):
  a, b = map(int, input().split())
  c = list(map(int, input().split()))
  box = sum(10**(x-1) for x in c)
  A.append([box, a])
  ci = len(A)-1
  for i in range(0,len(A)-1):
    A.append([A[0|i][0] + A[ci][0], 
              A[0|i][1] + A[ci][1]])

if max([A[x][1] for x in range(len(A))]) >= comp:
  ans = min([A[x][1] for x in range(len(A))
           if len(str(A[x][0]).replace('0','')) >= len(str(comp))] )
else:
  ans = -1
print(ans)

Fixed submission:
import itertools

N,M = map(int, input().split())
A = []
C = []
comp = sum(1<<int(x) for x in range(N))
for m in range(M):
  a, b = map(int, input().split())
  A.append(a)
  c = list(map(int, input().split()))
  C.append(sum(1<<(int(x)-1) for x in c))

INF = 10**18
dp = [INF] * (1<<N)
dp[0] = 0

for n,(a,c) in itertools.product(range(1<<N),zip(A,C)):
    m = n|c
    x = dp[n]+a
    if dp[m] > x:
      dp[m] = x

answer = dp[-1]
if answer == INF:
    answer = -1
print(answer)

Buggy python submission (verdict: Runtime Error):
import itertools

N,M = map(int, input().split())
A = []
comp = sum(10**(x-1) for x in range(1,N+1))
for m in range(M):
  a, b = map(int, input().split())
  c = list(map(int, input().split()))
  box = sum(10**(x-1) for x in c)
  A.append([box, a])

  for i in range(0,len(A)-1):
    A.append([A[0|i][0] + A[m][0], 
              A[0|i][1] + A[m][1]])

ans = min([A[x][1] for x in range(len(A))
           if A[x][0] >= comp] )

print(ans)

Fixed submission:
import itertools

N,M = map(int, input().split())
A = []
C = []
comp = sum(1<<int(x) for x in range(N))
for m in range(M):
  a, b = map(int, input().split())
  A.append(a)
  c = list(map(int, input().split()))
  C.append(sum(1<<(int(x)-1) for x in c))

INF = 10**18
dp = [INF] * (1<<N)
dp[0] = 0

for n,(a,c) in itertools.product(range(1<<N),zip(A,C)):
    m = n|c
    x = dp[n]+a
    if dp[m] > x:
      dp[m] = x

answer = dp[-1]
if answer == INF:
    answer = -1
print(answer)
Buggy python submission (verdict: Runtime Error):

n = int(input())
ab = [list(map(int,input().split())) for _ in range(n)]
cd = [list(map(int,input().split())) for _ in range(n)]

ab.sort()
cd.sort()

abf = [0]*n
cdf = [0]*n
que = [[] for _ in range(n)]
for i in range(n):
  for j in range(n):
    if ab[j][0] < cd[i][0] and ab[j][1] < cd[i][1] and \
        abf[j] == 0 and cdf[i] == 0:
      que[i].append(j)

qn = []
for i in range(n):
  qn.append([i,len(que[i])])
qn.sort()
print(qn)
while len(qn) > 0:
  for i in range(len(qn)):
    for idx in que[qn[i][0]]:
      print(idx)
      if abf[idx] == 0:
        abf[idx] = 1
        qn.pop(i)
  
print(sum(abf))


Fixed submission:
n = int(input())
AB = [list(map(int,input().split())) for _ in range(n)]
CD = [list(map(int,input().split())) for _ in range(n)]

que = [[] for _ in range(n)]
for i in range(n):
  for j in range(n):
    if AB[i][0] < CD[j][0] and AB[i][1] < CD[j][1]:
      que[j].append(i)

def dfs(i,v):
  
  for a in que[i]:
    if a in v:
      continue
    v.add(a)
    if ab[a] == -1 or dfs(ab[a], v):
      ab[a] = i
      return True
  return False
      
v = [set() for _ in range(n)]   
ab = [-1]*n

print(sum(dfs(i, set()) for i in range(n)))
Buggy python submission (verdict: Runtime Error):
s = input()
t = input()

s = [x for x in s[::-1]]
t = [x for x in t[::-1]]    

for i in range(len(s)-len(t)):
  flg = False
  cnt = 0
  for j in range(len(t)):
    if s[i+j] == '?':
      cnt += 1
      continue
    if s[i+j] == t[j]:
      flg = True
    else:
      flg = False
      break
  if flg or cnt == len(t):
    s[i:i+len(t)] = t
    flg = True
    break

if not flg:
    print('UNRESTORABLE')
    exit()

ans = ''
s = [x for x in s[::-1]]
for i in range(len(s)):
  if s[i] == '?':
    s[i] = 'a'
  ans += s[i]
print(ans)


Fixed submission:
s = input()
t = input()

if len(s) < len(t):
    print('UNRESTORABLE')
    exit()

s = [x for x in s[::-1]]
t = [x for x in t[::-1]]    

for i in range(len(s)-len(t)+1):
  flg = False
  cnt = 0
  for j in range(len(t)):
    if s[i+j] == '?':
      cnt += 1
      continue
    if s[i+j] == t[j]:
      flg = True
    else:
      flg = False
      break
  if flg or cnt == len(t):
    s[i:i+len(t)] = t
    flg = True
    break

if not flg:
    print('UNRESTORABLE')
    exit()

ans = ''
s = [x for x in s[::-1]]
for i in range(len(s)):
  if s[i] == '?':
    s[i] = 'a'
  ans += s[i]
print(ans)
Buggy python submission (verdict: Runtime Error):
k,s  = list(map(int,input().split()))
cnt = 0

def est():
  for x in range(k+1):
    for y in range(k+1):
      if s-(x+y) >=0 and s-(x+y) <= k:
        cnt += 1
  return cnt
print(est())

Fixed submission:
k,s = list(map(int,input().split()))

def fact(n):
  return sum([x for x in range(1,n+1)])

ans = 0
r = 0
for x in range(k+1):
  for y in range(x,k+1):
    if 0 <= s - (x+y) <= k:
      if (x==y):
          ans += 1
      else:
          ans += 2

print(ans)

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

def fact(n):
  return sum([x for x in range(1,n+1)])

ans = 0
r = 0
for x in range(k+1):
  for y in range(x,k+1):
    for z in range(y,k+1):
      if x+y+z == s:
        if x == y == z:
          ans += 1
        elif (x==y) or (x==z) or (y==z):
          ans += fact(2)
        else:
          ans += fact(3)

print(ans)


Fixed submission:
k,s = list(map(int,input().split()))

def fact(n):
  return sum([x for x in range(1,n+1)])

ans = 0
r = 0
for x in range(k+1):
  for y in range(x,k+1):
    if 0 <= s - (x+y) <= k:
      if (x==y):
          ans += 1
      else:
          ans += 2

print(ans)

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


ans = 0
for x in range(k+1):
  for y in range(k+1):
    for z in range(k+1):
      if x+y+z == s:
        ans += 1
        
print(ans)


Fixed submission:
k,s = list(map(int,input().split()))

def fact(n):
  return sum([x for x in range(1,n+1)])

ans = 0
r = 0
for x in range(k+1):
  for y in range(x,k+1):
    if 0 <= s - (x+y) <= k:
      if (x==y):
          ans += 1
      else:
          ans += 2

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
As = list(map(int, input().split()))
for i in range(K):
  if min(As) == N:
    break
  dBs = [0]*(N+1)
  for i in range(N):
    A = As[i]
    dBs[max(0, i-A)] += 1
    dBs[min(N, i+A+1)] -= 1
  #print(dBs)
  Bs = [dBs[0]]
  for i in range(1, N):
    B = Bs[i-1]+dBs[i]
    Bs.append(B)
  As = Bs
print(" ".join(map(str, As)))


Fixed submission:
N, K = map(int, input().split())
As = list(map(int, input().split()))
for i in range(K):
  if min(As) == N:
    break
  dBs = [0]*(N+1)
  for i in range(N):
    A = As[i]
    dBs[max(0, i-A)] += 1
    dBs[min(N, i+A+1)] -= 1
  #print(dBs)
  Bs = [dBs[0]]
  for i in range(1, N):
    B = Bs[i-1]+dBs[i]
    Bs.append(B)
  As = Bs
print(" ".join(map(str, As)))
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
As = list(map(int, input().split()))
As = [A-1 for A in As]
Vs = [-1]*N
p = 0
p0 = -1
Rs = [p]
Vs[p] = p
for i in range(N):
  n = As[p]
  Rs.append(n)
  if not Vs[n] < 0:
    p0 = Vs[n]
    break
  p = n
  Vs[p] = p
#print(Rs, p0)
if K <= p0:
  r = Rs[K]
else:
  r = Rs[p0+(K-p0)%(len(Rs)-p0+1)]
print(r+1)


Fixed submission:
N, K = map(int, input().split())
As = list(map(int, input().split()))
As = [A-1 for A in As]
Vs = [False]*N
p = 0
Rs = [p]
Vs[p] = True
for i in range(N+3):
  n = As[p]
  Rs.append(n)
  if Vs[n]:
    break
  p = n
  Vs[p] = True
p0 = Rs.index(Rs[-1])
#print(Rs, p0)
if K <= p0:
  r = Rs[K]
else:
  r = Rs[p0+(K-p0)%(len(Rs)-p0-1)]
print(r+1)

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
As = list(map(int, input().split()))
As = [A-1 for A in As]
Vs = [-1]*N
p = 0
p0 = -1
Rs = [p]
Vs[p] = p
for i in range(N):
  n = As[p]
  Rs.append(n)
  if not Vs[n] < 0:
    p0 = Vs[n]
    break
  p = n
  Vs[p] = p
#print(Rs, p0)
if K <= p0:
  r = Rs[K]
else:
  r = Rs[p0+1+(K-p0)%(len(Rs)-p0)]
print(r+1)


Fixed submission:
N, K = map(int, input().split())
As = list(map(int, input().split()))
As = [A-1 for A in As]
Vs = [False]*N
p = 0
Rs = [p]
Vs[p] = True
for i in range(N+3):
  n = As[p]
  Rs.append(n)
  if Vs[n]:
    break
  p = n
  Vs[p] = True
p0 = Rs.index(Rs[-1])
#print(Rs, p0)
if K <= p0:
  r = Rs[K]
else:
  r = Rs[p0+(K-p0)%(len(Rs)-p0-1)]
print(r+1)
Buggy python submission (verdict: Runtime Error):
S = input()
if S = "ABC":
  print("ARC")
if S = "ARC":
  print("ABC")


Fixed submission:
S = input()
if S == "ABC":
  print("ARC")
if S == "ARC":
  print("ABC")
Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())
def calcgcd(a, b):
  if a > b:
    a, b = b, a
  while a > 0:
    a, b = b%a, a
  return b
r = 0
for a in range(1, K+1):
  for b in range(1, K+1):
    ab = calcgcd(a, b)
    for c in range(1, K+1):
      g = calcgcd(ab, c)
      r += g
print(r)


Fixed submission:
K = int(input())
def calcgcd(a, b):
  if a > b:
    a, b = b, a
  while a > 0:
    a, b = b%a, a
  return b
r = 0
for a in range(1, K+1):
  for b in range(1, K+1):
    ab = calcgcd(a, b)
    for c in range(1, K+1):
      g = calcgcd(ab, c)
      r += g
print(r)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
As = list(map(int, input().split()))
r = 0
#for i in range(N):
#  for j in range(i+1, N):
#    r = (r+(As[i]^As[j]))%1000000007
for i in range(64):
  n = 0
  for A in As:
    if A&(1<<i) != 0:
      n += 1
  #print(i, n)
  d = n*(N-n)%1000000007
  d2 = (d<<i)%1000000007
  r = (r+d2)%1000000007
print(r)


Fixed submission:
N = int(input())
As = list(map(int, input().split()))
r = 0
#for i in range(N):
#  for j in range(i+1, N):
#    r = (r+(As[i]^As[j]))%1000000007
for i in range(64):
  n = 0
  for A in As:
    if A&(1<<i) != 0:
      n += 1
  #print(i, n)
  d = n*(N-n)%1000000007
  d2 = (d<<i)%1000000007
  r = (r+d2)%1000000007
print(r)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
As = list(map(int, input().split()))
r = 0
#for i in range(N):
#  for j in range(i+1, N):
#    r = (r+(As[i]^As[j]))%1000000007
for i in range(64):
  n = 0
  for A in As:
    if A&(1<<i) != 0:
      n += 1
  #print(i, n)
  r = (r+n*(N-n)*2**i)%1000000007
print(r)


Fixed submission:
N = int(input())
As = list(map(int, input().split()))
r = 0
#for i in range(N):
#  for j in range(i+1, N):
#    r = (r+(As[i]^As[j]))%1000000007
for i in range(64):
  n = 0
  for A in As:
    if A&(1<<i) != 0:
      n += 1
  #print(i, n)
  d = n*(N-n)%1000000007
  d2 = (d<<i)%1000000007
  r = (r+d2)%1000000007
print(r)
Buggy python submission (verdict: Runtime Error):
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
sA = T1*A1+T2*A2
sB = T1*B1+T2*B2
if sA == sB:
  print("infinity")
hA = T1*A1
hB = T1*B1
if sA > sB:
  hA, sA, hB, sB = hB, sB, hA, sA
#print(hA, sA, hB, sB)
if hA < hB:
  print(0)
n = 2*((hA-hB)//(sB-sA))+1
print(n)


Fixed submission:
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
sA = T1*A1+T2*A2
sB = T1*B1+T2*B2
if sA == sB:
  print("infinity")
  exit()
hA = T1*A1
hB = T1*B1
if sA > sB:
  hA, sA, hB, sB = hB, sB, hA, sA
#print(hA, sA, hB, sB)
if hA < hB:
  print(0)
  exit()
if (hA-hB)%(sB-sA) == 0:
  r = 2*((hA-hB)//(sB-sA))
else:
  r = 2*((hA-hB)//(sB-sA))+1
print(r)
Buggy python submission (verdict: Time Limit Exceeded):
X, Y = map(int, input().split())
if (X+Y)%3 != 0:
  print(0)
  exit()
N = (X+Y)//3
# C_N_X-N

MAX = 3000000
MOD = 1000000007
fac = [0]*MAX
finv = [0]*MAX
inv = [0]*MAX
fac[0] = 1
fac[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, MAX):
  fac[i] = fac[i-1]*i%MOD
  inv[i] = MOD - inv[MOD%i]*(MOD//i)%MOD
  finv[i] = finv[i-1]*inv[i]%MOD
def COM(n, k):
  if n < 0 or k < 0 or n < k:
    return 0
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD
r = COM(N, X-N)
print(r)


Fixed submission:
X, Y = map(int, input().split())
if (X+Y)%3 != 0:
  print(0)
  exit()
N = (X+Y)//3
# C_N_X-N
MAX = 700000
MOD = 1000000007
fac = [0]*MAX
finv = [0]*MAX
inv = [0]*MAX
fac[0] = 1
fac[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, MAX):
  fac[i] = fac[i-1]*i%MOD
  inv[i] = MOD - inv[MOD%i]*(MOD//i)%MOD
  finv[i] = finv[i-1]*inv[i]%MOD
def COM(n, k):
  if n < 0 or k < 0 or n < k:
    return 0
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD
r = COM(N, X-N)
print(r)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
As = list(map(int, input().split()))
Fs = list(map(int, input().split()))
As.sort()
Fs.sort(reverse=True)
def check(x):
  k = 0
  for i in range(N):
    k += max(0, As[i]-x//Fs[i])
  return k <= K
a = 0
b = As[-1]*Fs[0]
while a < b:
  i = (a + b)//2
  if check(i):
    b = i
  else:
    if a == i:
      break
    a = i
r = b
print(r)


Fixed submission:
N, K = map(int, input().split())
As = list(map(int, input().split()))
Fs = list(map(int, input().split()))
As.sort()
Fs.sort(reverse=True)
def check(x):
  k = 0
  for i in range(N):
    k += max(0, As[i]-x//Fs[i])
  return k <= K
a = 0
b = As[-1]*Fs[0]
while a < b:
  i = (a + b)//2
  if check(i):
    b = i
  else:
    if a == i:
      break
    a = i
r = b
print(r)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
E = [set() for i in range(N)]
for i in range(M):
  s, t = map(int, input().split())
  s, t = s-1, t-1
  E[s].add(t)
Vs = [1000000.0]*N
Vs[-1] = 0
for i in reversed(range(N-1)):
  js = E[i]
  v = 0
  for j in js:
    v += Vs[j]
  v = 1+v/len(js)
  Vs[i] = v
r = Vs[0]
rs = [r]
Vs0 = Vs
for n in range(N-1):
  Vs = [1000000.0]*N
  for i in range(n+1, N):
    Vs[i] = Vs0[i]
  for i in reversed(range(n+1)):
    js = E[i]
    if i == n:
      jmin = max(js, key=lambda j: Vs[j])
      js = js-{jmin}
    if len(js) == 0:
      break
    #p = 1/len(js)
    v = 0
    for j in js:
      v += Vs[j]
    v = 1+v/len(js)
    Vs[i] = v
  r = Vs[0]
  rs.append(r)
#print(rs)
r = min(rs)
print(r)


Fixed submission:
N, M = map(int, input().split())
E = [set() for i in range(N)]
for i in range(M):
  s, t = map(int, input().split())
  s, t = s-1, t-1
  E[s].add(t)
Vs = [1000000.0]*N
Vs[-1] = 0
for i in reversed(range(N-1)):
  js = E[i]
  v = 0
  for j in js:
    v += Vs[j]
  v = 1+v/len(js)
  Vs[i] = v
r = Vs[0]
rs = [r]
Vs0 = Vs
for n in range(N-1):
  Vs = [1000000.0]*N
  for i in range(n+1, N):
    Vs[i] = Vs0[i]
  for i in reversed(range(n+1)):
    js = E[i]
    if i == n:
      jmin = max(js, key=lambda j: Vs[j])
      js = js-{jmin}
    if len(js) == 0:
      break
    #p = 1/len(js)
    v = 0
    for j in js:
      v += Vs[j]
    v = 1+v/len(js)
    Vs[i] = v
  r = Vs[0]
  rs.append(r)
#print(rs)
r = min(rs)
print(r)