Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int, input().split())
if K==1:
    print(0)
    exit()
if K==2:
    if N%2==0:
        print(0)
        exit()
    else:
        print(1)
        exit()

def func(x,K):
    tmp=x-K
    if tmp<0:
        tmp*=(-1)
    return tmp
    
ans = N
while(True):
    N=func(N,K)
    if N<ans:
        ans=N
    else:
        break
print(ans)


Fixed submission:
N,K = map(int, input().split())
if N==0:
    print(0)
    exit()
if K==1:
    print(0)
    exit()
if K==2:
    if N%2==0:
        print(0)
        exit()
    else:
        print(1)
        exit()

def func(x,K):
    tmp=x-K
    if tmp<0:
        tmp*=(-1)
    return tmp

if (N>K):
    y=int(N/K)
    N=func(N,K*y)

ans = N
while(True):
    N=func(N,K)
    if N<ans:
        ans=N
    else:
        break
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
if N =="Sunny":
    ans="Cloudy"
elif N=="Cloudy":
    ans="Rainy"
elif N=="Rainy":
    ans="Sunny"
print(ans)

Fixed submission:
N = str(input())
ans=""
if N =="Sunny":
    ans="Cloudy"
elif N=="Cloudy":
    ans="Rainy"
elif N=="Rainy":
    ans="Sunny"
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
ans = N*(N-1)//2
print(int(ans))

Fixed submission:
pre = input()
gen = input()
ans=0
for i,k in zip(pre, gen):
    if i==k:
        ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=[]
D={}
cnt=0
for i in range(N):
    A.append(sorted(input()))

for sortstr in A:
    if sortstr in D:
        cnt+=D[sortstr]
        D[sortstr]+=1
    else:
        D[sortstr]=1
print(cnt)

Fixed submission:
N=int(input())
A=[]
D={}
cnt=0
for i in range(N):
    A.append(str(sorted(input())))

for sortstr in A:
    if sortstr in D:
        cnt+=D[sortstr]
        D[sortstr]+=1
    else:
        D[sortstr]=1
print(cnt)

Buggy python submission (verdict: Runtime Error):
N=int(input())
A=[]
D={}
count=0
for i in range(N):
    S=''.join(sorted(input()))
    A.append(S)

for s in A:
    if s in D:
        count+=1
    else:
        D+=s
print(count)

Fixed submission:
N=int(input())
A=[]
D={}
cnt=0
for i in range(N):
    A.append(str(sorted(input())))

for sortstr in A:
    if sortstr in D:
        cnt+=D[sortstr]
        D[sortstr]+=1
    else:
        D[sortstr]=1
print(cnt)

Buggy python submission (verdict: Runtime Error):
N = int(input())
L = [list(map(str, input().split())) for i in range(N)]

from collections import Counter
def verify_anagrams(first_word, second_word):
    def get_counter(s):
        return Counter(s.replace(' ', ''))
    if get_counter(first_word) == get_counter(second_word):
        return True
    else:
        return False

cnt=0
for i in range(N):
    for k in range(N):
        if k+1>len(L):
            continue
        if verify_anagrams(L[i],L[k+1]):
            cnt+=1

print(num)


Fixed submission:
N=int(input())
A=[]
D={}
cnt=0
for i in range(N):
    A.append(str(sorted(input())))

for sortstr in A:
    if sortstr in D:
        cnt+=D[sortstr]
        D[sortstr]+=1
    else:
        D[sortstr]=1
print(cnt)
Buggy python submission (verdict: Runtime Error):
N = int(input())
L = list(map(int, input().split()))

for i in L:
  for k in L[1:]:
    if i<=k || i-1<=k:
      ans="yes"
    else:
      ans="no"
      
print(ans)


Fixed submission:
N=int(input())
H=list(map(int, input().split()))
maxv=H[0]
ans="Yes"
for i in range(1, N):
  if maxv-H[i]>=2:
    ans="No"
    break
  maxv=max(maxv, H[i])
print(ans)

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

for i in L:
  for k in L[1:]:
    if i<=k || i-1<=k:
      ans=yes
    else:
      ans=no
      
print(ans)

Fixed submission:
N=int(input())
H=list(map(int, input().split()))
maxv=H[0]
ans="Yes"
for i in range(1, N):
  if maxv-H[i]>=2:
    ans="No"
    break
  maxv=max(maxv, H[i])
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
if a*b%2=0:
    print("Even")
else:
    print("odd")

Fixed submission:
a,b=map(int,input().split())
if a*b%2==0:
    print("Even")
else:
    print("Odd")
Buggy python submission (verdict: Runtime Error):
list=[int(i) for i in input().split()]
a=0
for i in list:
    if i==1:
        a=a+1
    elif:
        a=a+0
print(a)

Fixed submission:
print(input().count('1'))
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    # 整数の入力
    N = int(input())
    A = list(map(int, input().split()))

    count = 0
    for i in range(1, N + 1):
        for a in A:
            if a == i:
                count += 1
        print(count)
        count = 0


if __name__ == '__main__':
    main()



Fixed submission:
import numpy as np


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

    counter = np.zeros(N)
    for a in A:
        counter[a - 1] += 1

    for c in counter:
        print(int(c))


if __name__ == '__main__':
    main()
Buggy python submission (verdict: Runtime Error):

def main():
    # -*- coding: utf-8 -*-
    # 整数の入力
    a = int(input())
    # スペース区切りの整数の入力
    # b, c = map(int, input().split())
    # b, c = map(int, input())

    # # 文字列の入力
    # a = input()
    # 出力
    # print("{} {}".format(a+b+c, s))

    # mul = a

    if '7' in a:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    # main('123')
    main()
    

Fixed submission:

def main():
    # -*- coding: utf-8 -*-
    # 整数の入力
    # a = int(input())
    # スペース区切りの整数の入力
    # b, c = map(int, input().split())
    # b, c = map(int, input())

    # # 文字列の入力
    a = input()
    # 出力
    # print("{} {}".format(a+b+c, s))

    # mul = a

    if '7' in a:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    # main('123')
    main()
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
out = []
for i in range(1, N+1):
    if i not in A:
        print(0)
    else:
        print(A.count(i))


Fixed submission:
import collections

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

c = collections.Counter(A)

for i in range(1, N+1):
    if i not in c:
        print(0)
    else:
        print(c[i])

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int,input().split()))
out = []
for i in range(1, N+1):
    if i not in A:
        out.append(0)
    else:
        out.append(A.count(i))
for a in out:
  print(a)


Fixed submission:
import collections

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

c = collections.Counter(A)

for i in range(1, N+1):
    if i not in c:
        print(0)
    else:
        print(c[i])
Buggy python submission (verdict: Runtime Error):
n = int(input())
s = input()
out = 0

def rgb (tmpstr, j, i, s):
    if s[j] != s[i]:
        tmpstr = s[j + 1 :  n]
        remain = "RGB".replace(s[j],"").replace(s[i],"")
        num = tmpstr.count(remain) 
        if (j + (j - i)) < len(s):
            if  s[j + (j - i)]  == remain:
                num = num - 1
        return num
    else:
        return 0
    
    
out = sum([sum([rgb(s[j + 1 :  n], j, i, s) for j in range(i+1, n-1)]) for i in range(n-2)])
#for i in range(n-2):
#    out += sum([rgb(s[j + 1 :  n], j, i, s) for j in range(i+1, n-1)])
print(out)



Fixed submission:
s = input()
if s.find("7") != -1:
    print ("Yes")
else:
    print ("No")
Buggy python submission (verdict: Runtime Error):
a, b, m = map(int,str(input()).split())
a_cost_map = map(int,str(input()).split())
a_cost = list(a_cost_map)
b_cost_map = map(int,str(input()).split())
b_cost = list(b_cost_map)

coupons_map = [str(input()).split() for i in range(m)]
coupons_map_all =  [[int(coupons_map[i][t]) for t in range(len(coupons_map[i]))] for i in range(len(coupons_map))]

minimum = min(a_cost) + min(b_cost)
for coupon in coupons_map_all:
    coupon_use = (a_cost[coupon[0]-1] +  b_cost[coupon[1]-1] - coupon[2]) 
    print(coupon_use)
    if minimum > coupon_use:
        minimum = coupon_use
print(minimum)


Fixed submission:
test_input = str(input())
v = [(test_input[i*2]+test_input[i*2+1]) for i in range(int(len(test_input)/2))]
if len(test_input)%2 !=0:
    print("No")
elif set(v) == set(["hi"]):
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
n = int(input())
nums = list(map(int, input().split()))

values = {}
for i in nums:
  if i in values: values[i] += 1
  else: values[i] = 1

sums={} # 各値ごとの組み合わせ数
subsums={} # 各値ごとの組み合わせ数（ボールがないとき版
allsum = 0
for k,v in values.items():
  sums[k] = v * (v - 1) / 2
  undersum = (v - 2) * (v - 1) / 2 if v > 1 else 0
  subsums[k] = sums[k] - undersum
  allsum += sums[k]

# res={} # 各値のない時版 + 他の合計
# for k,v in sums.items():

for i in nums:
  print(int(allsum - subsums[i]))


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

print(int(n * (n-1) / 2 + m * (m - 1) / 2))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
a = map(int,input().split())
b = list(a)
for i in range(N):
    print(b.count(i+1))


Fixed submission:
N = int(input())
a = map(int,input().split())
b = list(a)
c = [0]*N
for i in range(N-1):
    c[b[i]-1] += 1
for j in range(N):
    print(c[j])
Buggy python submission (verdict: Time Limit Exceeded):
s=input()
q=int(input())

a=0
for i in range(q):
  t=input()
  if t=='1':
    a=a^1
  else:
    t, f, c = map(str, t.split())
    f=int(f)
    if (f^a)&1==0:
      s=s+c
    else:
      s=c+s
if a==1:
  s=s[::-1]
print(s)

Fixed submission:
s=input()
q=int(input())
head=''
foot=''

a=0
for i in range(q):
  t=input()
  if t=='1':
    a=a^1
  else:
    t, f, c = map(str, t.split())
    f=int(f)
    if (f^a)&1==0:
      foot+=c
    else:
      head=c+head
s=head+s+foot
if a==1:
  s=s[::-1]
print(s)

Buggy python submission (verdict: Runtime Error):
import sys
input=sys.stdin.readline

s=input()
q=int(input())
for i in range(q):
  t=input()
  if t=='1':
    s=s[::-1]
  else:
    t, f, c = map(str, t.split())
    if f =='1':
      s=c+s
    else:
      s=s+c
print(s)

Fixed submission:
s=input()
q=int(input())
head=''
foot=''

a=0
for i in range(q):
  t=input()
  if t=='1':
    a=a^1
  else:
    t, f, c = map(str, t.split())
    f=int(f)
    if (f^a)&1==0:
      foot+=c
    else:
      head=c+head
s=head+s+foot
if a==1:
  s=s[::-1]
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
q=int(input())
for i in range(q):
  t=input()
  if t=='1':
    s=s[::-1]
  else:
    t, f, c = map(str, t.split())
    if f =='1':
      s=c+s
    else:
      s=s+c
print(s)

Fixed submission:
s=input()
q=int(input())
head=''
foot=''

a=0
for i in range(q):
  t=input()
  if t=='1':
    a=a^1
  else:
    t, f, c = map(str, t.split())
    f=int(f)
    if (f^a)&1==0:
      foot+=c
    else:
      head=c+head
s=head+s+foot
if a==1:
  s=s[::-1]
print(s)
Buggy python submission (verdict: Time Limit Exceeded):
n, a, b = map(int, input().split())
mod = 10**9 + 7
u=1
d=1
ans=0

for i in range(1, n+1):
  u *= n+1-i
  d *= i
  if i != a and i != b:
    ans += u//d
    ans %= mod
print(ans)

Fixed submission:
n, a, b = map(int, input().split())
mod = 10**9 + 7
def c(x):
  out = 1
  for i in range(min(x, n-x)):
    out *= n-i
    out *= pow(i+1, mod-2, mod)
    out %= mod
  return out
ans = pow(2, n, mod) -1 -c(a)-c(b)
ans %= mod
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s=['']*n
sn=[0]*n
l=0

for _ in range(n):
  t = input()
  for i in range(l):
    if t == s[i]:
      sn[i]+=1
      break
      continue
  s[l]=t
  sn[l]+=1
  l+=1
m=max(sn)
ans=[]
for i in range(l):
  if sn[i]==m:
    ans.append(s[i])
ans.sort()
for i in range(len(ans)):
  print(ans[i])

Fixed submission:
n = int(input())
s=[input() for _ in range(n)]
s.sort()

c=1
m=0
for i in range(n-1):
  if s[i]==s[i+1]:
    c+=1
  else:
    if c > m:
      ans=[s[i]]
      m=c
      c=1
    elif c==m:
      ans.append(s[i])
      c=1
    else:
      c=1
if c > m:
  ans=[s[n-1]]
elif c==m:
   ans.append(s[n-1])
for i in range(len(ans)):
  print(ans[i])

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s=[[0, 'papa']]

for _ in range(n):
  t = str(input())
  l=len(s)
  for i in range(l):
    if t == s[i][1]:
      s[i][0]+=1
      break
      continue
  s.append([1, t])
s.sort()
l=len(s)
m=s[l-1][0]
for i in range(l):
  if s[i][0]==m:
    print(s[i][1])

Fixed submission:
n = int(input())
s=[input() for _ in range(n)]
s.sort()

c=1
m=0
for i in range(n-1):
  if s[i]==s[i+1]:
    c+=1
  else:
    if c > m:
      ans=[s[i]]
      m=c
      c=1
    elif c==m:
      ans.append(s[i])
      c=1
    else:
      c=1
if c > m:
  ans=[s[n-1]]
elif c==m:
   ans.append(s[n-1])
for i in range(len(ans)):
  print(ans[i])
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
p = list(map(int, input().split()))
dp = [1+p[i] for i in range(n)]

m = 0
for i in range(n-k+1):
  if m < sum(dp[i:i+k]):
    m = sum(dp[i:i+k])
print(m/2)

Fixed submission:
n, k = map(int, input().split())
p = list(map(int, input().split()))
s = sum(p[:k])
m = s
for i in range(1, n-k+1):
  s = s-p[i-1]+p[i+k-1]
  if s > m:
    m = s
print((m+k)/2)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
def input():
  return sys.stdin.readline()[:-1]
h, n = map(int, input().split())
a=[0]*n
b=[0]*n
for i in range(n):
  a[i], b[i] = map(int, input().split())

dp = [float('inf')]*(h+max(a))
dp[0] = 0 
for i in range(1, h+max(a)):
  for j in range(n):
    dp[i] = min(dp[i], dp[i-a[j]]+b[j])
print(min(dp[h:]))

Fixed submission:
import sys
def input():
  return sys.stdin.readline()[:-1]
h, n = map(int, input().split())
a=[0]*n
b=[0]*n
for i in range(n):
  a[i], b[i] = map(int, input().split())

dp = [float('inf')]*(h+max(a))
dp[0] = 0 
for i in range(1, h+max(a)):
  for j in range(n):
    dp[i] = min(dp[i], dp[i-a[j]]+b[j])
print(min(dp[h:]))

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

dp = [float('inf')]*(h+max(a))
dp[0] = 0 
for i in range(1, h+max(a)):
  for j in range(n):
    dp[i] = min(dp[i], dp[i-a[j]]+b[j])
print(min(dp[h:]))


Fixed submission:
import sys
def input():
  return sys.stdin.readline()[:-1]
h, n = map(int, input().split())
a=[0]*n
b=[0]*n
for i in range(n):
  a[i], b[i] = map(int, input().split())

dp = [float('inf')]*(h+max(a))
dp[0] = 0 
for i in range(1, h+max(a)):
  for j in range(n):
    dp[i] = min(dp[i], dp[i-a[j]]+b[j])
print(min(dp[h:]))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
x = list(map(int, input().split()))
ans = 0
p = 1
for i in range(1, n):
  p *= i
for i in range(n-1):
  ans += (x[n-1]-x[i])*p//(i+1)
ans %= 1000000007
print(ans)

Fixed submission:
n = int(input())
x = list(map(int, input().split()))
ans = 0
mod = 1000000007
p = 1
for i in range(1, n):
  p *= i
  p %= mod
for i in range(n-1):
  ans += (x[n-1]-x[i])*pow(i+1, mod-2, mod)
ans *= p
ans %= 1000000007
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
x = list(map(int, input().split()))
ans = 0
p = 1
for i in range(1, n):
  p *= i
for i in range(n-1):
  ans += (x[n-1]-x[i])*p//(i+1)
ans %= 1000000007
print(ans)

Fixed submission:
n = int(input())
x = list(map(int, input().split()))
ans = 0
mod = 1000000007
p = 1
for i in range(1, n):
  p *= i
  p %= mod
for i in range(n-1):
  ans += (x[n-1]-x[i])*pow(i+1, mod-2, mod)
ans *= p
ans %= 1000000007
print(ans)

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

n = int(input())
x = list(map(int, input().split()))
ans = 0
p = math.factorial(n-1)
for i in range(n-1):
  k = p//(i+1) % 1000000007
  ans += k * (x[n-1]-x[i])
  ans %= 1000000007
print(ans)


Fixed submission:
n = int(input())
x = list(map(int, input().split()))
ans = 0
mod = 1000000007
p = 1
for i in range(1, n):
  p *= i
  p %= mod
for i in range(n-1):
  ans += (x[n-1]-x[i])*pow(i+1, mod-2, mod)
ans *= p
ans %= 1000000007
print(ans)

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

n = int(input())
x = list(map(int, input().split()))
ans = 0
p = math.factorial(n-1)
for i in range(n-1):
  k = p//(i+1) % 1000000007
  ans += k * (x[n-1]-x[i])
  ans %= 1000000007
print(ans)

Fixed submission:
n = int(input())
x = list(map(int, input().split()))
ans = 0
mod = 1000000007
p = 1
for i in range(1, n):
  p *= i
  p %= mod
for i in range(n-1):
  ans += (x[n-1]-x[i])*pow(i+1, mod-2, mod)
ans *= p
ans %= 1000000007
print(ans)

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

n = int(input())
x = list(map(int, input().split()))
ans = 0
pattern = math.factorial(n-1)
p=1
k=pattern
while p < n:
  ans += k * (x[p]-x[p-1])
  ans %= 1000000007
  p += 1
  k += pattern//(p)
print(ans)

Fixed submission:
n = int(input())
x = list(map(int, input().split()))
ans = 0
mod = 1000000007
p = 1
for i in range(1, n):
  p *= i
  p %= mod
for i in range(n-1):
  ans += (x[n-1]-x[i])*pow(i+1, mod-2, mod)
ans *= p
ans %= 1000000007
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
x = list(map(int, input().split()))
ans = 0
pattern = 1
for i in range(1, n):
  pattern *= i
p=1
k=pattern
while p < n:
  ans += k * (x[p]-x[p-1])
  ans %= 1000000007
  p += 1
  k += pattern//(p)
print(ans)

Fixed submission:
n = int(input())
x = list(map(int, input().split()))
ans = 0
mod = 1000000007
p = 1
for i in range(1, n):
  p *= i
  p %= mod
for i in range(n-1):
  ans += (x[n-1]-x[i])*pow(i+1, mod-2, mod)
ans *= p
ans %= 1000000007
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = 0
b = 0

if n % 2 != 0 or n < 10:
  print(0)
else:
  while n % 10 != 0:
    n = n-2
  
  while n >= 10:
    b = n
    while b % 10 == 0:
      a += 1
      b = int(b/10)
    else:
      n = n-10
  
  print(a)

Fixed submission:
n = int(input())
a = 0

if n % 2 != 0 or n < 10:
  print(0)
else:
  i = 10
  while i <= n:
    a += n//i
    i *= 5
  print(a)
Buggy python submission (verdict: Runtime Error):
a = input()
b = 0
C = -1
d = 0

for i in range(len(a)):
	if a[b] != a[c]:
      d = d + 1
    b = b + 1
    C = c - 1

print(d/2)

Fixed submission:
a = input()
b = 0
c = -1
d = 0
 
for i in range(len(a)):
    if a[b] != a[c]:
      d = d + 1
    b = b + 1
    c = c - 1

print(d//2)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
mod = 1000000007
ml = len(bin(max(a)))-2
ans = 0
for i in range(ml):
  x = sum([1 for j in range(n) if ((a[j]>>i) & 1)])
  ans += x*(n-x)*(2**i)
  ans %= mod
print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
mod = 1000000007
ml = len(bin(max(a)))-2
ans = 0
for i in range(ml):
  x = sum([1 for j in a if ((j>>i) & 1)])
  ans += x*(n-x)*(2**i)
  ans %= mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
mod = 1000000007
ans = 0
for i in range(len(bin(max(a)))-2):
  x = sum([1 for j in range(n) if ((a[j]>>i) & 1)])
  ans += x*(n-x)*(2**i)
  ans %= mod
print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
mod = 1000000007
ml = len(bin(max(a)))-2
ans = 0
for i in range(ml):
  x = sum([1 for j in a if ((j>>i) & 1)])
  ans += x*(n-x)*(2**i)
  ans %= mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
mod = 1000000007
ans = 0
for i in range(len(bin(max(a)))-2):
  x = 0
  for j in range(n):
    if (a[j] >> i) & 1:
      x += 1
  ans += x*(n-x)*(2**i)
  ans %= mod
print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
mod = 1000000007
ml = len(bin(max(a)))-2
ans = 0
for i in range(ml):
  x = sum([1 for j in a if ((j>>i) & 1)])
  ans += x*(n-x)*(2**i)
  ans %= mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
mod = 1000000007
ans = 0
for i in range(60):
  x = 0
  for j in range(n):
    if (a[j] >> i) & 1:
      x += 1
  ans += x*(n-x)*(2**i)%mod
print(ans%mod)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
mod = 1000000007
ml = len(bin(max(a)))-2
ans = 0
for i in range(ml):
  x = sum([1 for j in a if ((j>>i) & 1)])
  ans += x*(n-x)*(2**i)
  ans %= mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
mod = 1000000007
ans = 0
for i in range(60):
  x = 0
  for j in range(n):
    if (a[j] >> i) & 1:
      x += 1
  ans += x*(n-x)*(2**i)
  ans %= mod
print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
mod = 1000000007
ml = len(bin(max(a)))-2
ans = 0
for i in range(ml):
  x = sum([1 for j in a if ((j>>i) & 1)])
  ans += x*(n-x)*(2**i)
  ans %= mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
mod = 1000000007
ans = 0
for i in range(n-1):
  for j in range(i+1, n):
    ans += a[i] ^ a[j]
    ans %= mod
print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
mod = 1000000007
ml = len(bin(max(a)))-2
ans = 0
for i in range(ml):
  x = sum([1 for j in a if ((j>>i) & 1)])
  ans += x*(n-x)*(2**i)
  ans %= mod
print(ans)
Buggy python submission (verdict: Runtime Error):
S = input()
a = 0

if S = 'SUN':
  a = 7
elif S = 'MON':
  a = 6
elif S = 'TUE':
  a = 5
elif S = 'WED':
  a = 4
elif S = 'THU':
  a = 3
elif S = 'FRI':
  a = 2
elif S = 'SAT':
  a = 1

print(a)

Fixed submission:
S = input()
a = 0
 
if S == 'SUN':
  a = 7
elif S == 'MON':
  a = 6
elif S == 'TUE':
  a = 5
elif S == 'WED':
  a = 4
elif S == 'THU':
  a = 3
elif S == 'FRI':
  a = 2
elif S == 'SAT':
  a = 1

print(a)
Buggy python submission (verdict: Runtime Error):
s=input()
rl=[]
ll=[]
c=0
for i in range(len(s)-1):
  c+=1
  if s[i]!=s[i+1]:
    if s[i]=='<':
      rl.append(c)
    else:
      ll.append(c)
    c=0
if s[len(s)-1]=='<':
  rl.append(c+1)
else:
  ll.append(c+1)

rn=len(rl)
ln=len(ll)
ans=0
if s[0]=='<':
  for i in range(ln):
    M=max(rl[i], ll[i])
    m=min(rl[i], ll[i])
    ans+=M*(M+1)//2+m*(m-1)//2
  if rn>ln:
    ans+=rl[-1]*(rl[-1]+1)//2
else:
  ans+=ll[0]*(ll[0]+1)//2
  for i in range(rn-1):
    M=max(rl[i], ll[i+1])
    m=min(rl[i], ll[i+1])
    ans+=M*(M+1)//2+m*(m-1)//2
  if rn==ln:
    ans+=rl[-1]*(rl[-1]+1)//2
  else:
    M=max(rl[-1], ll[-1])
    m=min(rl[-1], ll[-1])
    ans+=M*(M+1)//2+m*(m-1)//2
print(ans)

Fixed submission:
s=input()
rl=[]
ll=[]
c=0
for i in range(len(s)-1):
  c+=1
  if s[i]!=s[i+1]:
    if s[i]=='<':
      rl.append(c)
    else:
      ll.append(c)
    c=0
if s[len(s)-1]=='<':
  rl.append(c+1)
else:
  ll.append(c+1)

rn=len(rl)
ln=len(ll)
ans=0
if s[0]=='<':
  for i in range(ln):
    M=max(rl[i], ll[i])
    m=min(rl[i], ll[i])
    ans+=M*(M+1)//2+m*(m-1)//2
  if rn>ln:
    ans+=rl[-1]*(rl[-1]+1)//2
else:
  rl=[0]+rl
  ans+=ll[0]*(ll[0]+1)//2
  for i in range(1, ln):
    M=max(rl[i], ll[i])
    m=min(rl[i], ll[i])
    ans+=M*(M+1)//2+m*(m-1)//2
  if rn==ln:
    ans+=rl[-1]*(rl[-1]+1)//2
print(ans)

Buggy python submission (verdict: Runtime Error):
s=input()
rl=[]
ll=[]
c=0
for i in range(len(s)-1):
  c+=1
  if s[i]!=s[i+1]:
    if s[i]=='<':
      rl.append(c)
    else:
      ll.append(c)
    c=0
if s[len(s)-1]=='<':
  rl.append(c+1)
else:
  ll.append(c+1)

rn=len(rl)
ln=len(ll)
ans=0
if s[0]=='<':
  for i in range(ln):
    M=max(rl[i], ll[i])
    m=min(rl[i], ll[i])
    ans+=M*(M+1)//2+m*(m-1)//2
  if rn>ln:
    ans+=rl[-1]*(rl[-1]+1)//2
else:
  ans+=ll[0]*(ll[0]+1)//2
  for i in range(rn):
    M=max(rl[i], ll[i+1])
    m=min(rl[i], ll[i+1])
    ans+=M*(M+1)//2+m*(m-1)//2
  if rn==ln:
    ans+=rl[-1]*(rl[-1]+1)//2
print(ans)

Fixed submission:
s=input()
rl=[]
ll=[]
c=0
for i in range(len(s)-1):
  c+=1
  if s[i]!=s[i+1]:
    if s[i]=='<':
      rl.append(c)
    else:
      ll.append(c)
    c=0
if s[len(s)-1]=='<':
  rl.append(c+1)
else:
  ll.append(c+1)

rn=len(rl)
ln=len(ll)
ans=0
if s[0]=='<':
  for i in range(ln):
    M=max(rl[i], ll[i])
    m=min(rl[i], ll[i])
    ans+=M*(M+1)//2+m*(m-1)//2
  if rn>ln:
    ans+=rl[-1]*(rl[-1]+1)//2
else:
  rl=[0]+rl
  ans+=ll[0]*(ll[0]+1)//2
  for i in range(1, ln):
    M=max(rl[i], ll[i])
    m=min(rl[i], ll[i])
    ans+=M*(M+1)//2+m*(m-1)//2
  if rn==ln:
    ans+=rl[-1]*(rl[-1]+1)//2
print(ans)