Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

#!/usr/bin/env python3

n, k = map(int, input().split())

#while n > abs(n-k):
#    n = abs(n-k)
while 2*n > k:
    
    if n > k:
        n = n-k
    elif n <= k:
        n = k-n
        
print(n)

### FIXED CODE ###

#!/usr/bin/env python3

n, k = map(int, input().split())

#while n > abs(n-k):
#    n = abs(n-k)
while 2*n > k:
    
    if n > k:
        n = n%k
    elif n <= k:
        n = k-n

print(n)
### BUGGY CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
foo = [[1 for k in range(N)] for k in range(42)]
for k in range(len(A)):
    foo[0][k] = A[k]
if K <42:
    for q in range(K):
        for k in range(N):
            for j in range(1, min(foo[q][k]+1, N-k)):
                foo[q+1][k+j] +=1
            for j in range(1, min(foo[q][k]+1, k+1)):
                foo[q+1][k-j] +=1
        count =0
        for l in range(N):
            if foo[q+1][l] < N:
                break
            else:
                count +=1
        
        if count == N:
            break
        
                        
        #print(foo)
    print(" ".join(map(str, foo[q+1])))

     
else:
    print((str(N)+" ")*(N-1)+str(N))




### FIXED CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
foo = [[0 for k in range(N)] for k in range(42)]
for k in range(len(A)):
    foo[0][k] = A[k]
if K <42:
    for q in range(K):
        unko = [0 for k in range(N)]
        for k in range(N):
            if k + foo[q][k]+1 < N:
                unko[k + foo[q][k]+1] -=1
            unko[max(k - foo[q][k], 0)] +=1
        unchi = 0
        for k in range(N):
            unchi += unko[k]
            foo[q+1][k] = unchi
        #print(unko)
        #print(foo[q+1])
        count =0
        for l in range(N):
            if foo[q+1][l] < N:
                break
            else:
                count +=1
        
        if count == N:
            break
        
                        
        #print(foo)
    print(" ".join(map(str, foo[q+1])))

     
else:
    print((str(N)+" ")*(N-1)+str(N))
### BUGGY CODE ###

N = int(input())
AA = list(map(int,input().split()))
res = AA[0]
for a in AA[1:]:
    res = res*a
if res>1e18:
  print('-1')
else:         
  print(res)

### FIXED CODE ###

N = int(input())
AA = list(map(int,input().split()))
res = AA[0]
if 0 in AA:
  print(0)
else:
  for a in AA[1:]:
    res = res*a
    if res>1e18:
      print('-1')
      exit()
  print(res)
### BUGGY CODE ###

import collections
s = list(input())
s = list(map(int,s))
s_mod =[0]
mod = 0
for i in range(len(s)):
    a = s[len(s) - 1- i]* (10**i)
    mod += a
    mod = mod % 2019
    s_mod.append(mod)
s_values = list(collections.Counter(s_mod).values())
print(int(sum(s_values[i]*(s_values[i]-1)/2 for i in range(len(s_values)))))

### FIXED CODE ###

S = input()
n = len(S)
dp = {0:1}
q = 1
p = 0
for i in range(n):
    p += int(S[n-1-i])*q
    q *= 10
    q = q % 2019
    p = p % 2019
    if p not in dp:
        dp[p] = 1
    else:
        dp[p] += 1
print(sum(dp[i]*(dp[i]-1)//2 for i in dp))
### BUGGY CODE ###

nk = input().split()
n = int(nk[0])
k = int(nk[1])
a = list(map(int, input().split()))

p = []
for i in range(k - 1, n):
    if i == k - 1:
        p_i = 1
        for j in range(k):
            p_i *= a[i - j]
        p.append(p_i)
    else:
        p_i = p[-1] / a[i - k] * a[i]
        p.append(p_i)

for i in range(len(p)):
    if i == 0:
        continue
    if p[i] > p[i - 1]:
        print("Yes")
    else:
        print("No")

### FIXED CODE ###

nk = input().split()
n = int(nk[0])
k = int(nk[1])
a = list(map(int, input().split()))

for i in range(k, n):
    if a[i] > a[i - k]:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

N = int(input())
A = [int(a) for a in input().split()]
dp = [[0] * (N+1) for _ in range(N+1)]

for d in range(N):
    for l in range(N-d):
        r = l + d
        if d == 0:
            dp[l][r] = A[l] * (-1)**(N+d+1)
            
        else:
            s = (-1)**(N+d+1)
            dp[l][r] = max(A[l] + dp[l+1][r] * s, A[r] + dp[l][r-1] * s) * s

print(dp[0][N-1])

### FIXED CODE ###

N = int(input())
A = [int(a) for a in input().split()]
dp = [[0] * (N+1) for _ in range(N+1)]

for d in range(N):
    for l in range(N-d):
        r = l + d
        if d == 0:
            dp[l][r] = A[l] * (-1)**(N+d+1)
            
        else:
            s = (-1)**(N+d+1)
            dp[l][r] = max(A[l] + dp[l+1][r] * s, A[r] + dp[l][r-1] * s) * s

print(dp[0][N-1])
### BUGGY CODE ###

N=int(input())
ans=0

for i in range(1,N+1):
  for j in range(1,(N+1)//i+1):
    if isinstance(i*j-N, int) and i*j-N<0:
      ans += 1
print(ans)

### FIXED CODE ###

N=int(input())
ans=0

for i in range(1,10**6):
  for j in range(i,10**6//i+1):
    if N > i*j:
      if i==j:
        ans += 1
      else:
        ans += 2

print(ans)
### BUGGY CODE ###

N,A,B=map(int, input().split())
turn=0
while A!=1 and B!=N or turn==0:
  if A!=B-1:
    A+=1
  else:
      A=A-1
  if B!=A+1:
    B=B-1
  else:
    B=B+1
  turn+=1
if A==1:
  print('Borys')
else:
  print('Alice')

### FIXED CODE ###

N,A,B=map(int, input().split())
turn=0
while A!=1 and B!=N or turn==0:
  if A!=B-1:
    A+=1
  else:
      A=A-1
  if A<1:
      A=1
  if B!=A+1:
    B=B-1
  else:
    B=B+1
  if B>N:
      B=N
  turn+=1
if A==1:
  print('Borys')
else:
  print('Alice')
### BUGGY CODE ###

n = int(input())
ta = [list(map(int, input().split())) for x in range(n)]


def fit(a, b):
    for i in range(1000, 1, -1):
        if a%i == b%i == 0:
            return a // i, b // i
    return a, b


def to(a, b, limit):
    cnt = 1
    while True:
        ac = a * cnt
        bc = b * cnt
        if limit[0] <= ac and limit[1] <= bc:
            return ac, bc
        cnt += 1


now = [1, 1]
for t, a in ta:
    t, a = fit(t, a)
    now = to(t, a, now)
print(sum(now))


### FIXED CODE ###

n = int(input())
ta = [list(map(int, input().split())) for x in range(n)]


def fit(a, b):
    for i in range(1000, 1, -1):
        if a%i == b%i == 0:
            return a // i, b // i
    return a, b


def to(a, b, limit):
    cnt = (limit[0] + a - 1) // a
    ac = a * cnt
    bc = b * cnt
    if limit[0] <= ac and limit[1] <= bc:
        return ac, bc

    cnt = (limit[1] + b - 1) // b
    ac = a * cnt
    bc = b * cnt
    if limit[0] <= ac and limit[1] <= bc:
        return ac, bc


now = [1, 1]
for t, a in ta:
    t, a = fit(t, a)
    now = to(t, a, now)
print(sum(now))
### BUGGY CODE ###

n, p = map(int,input().split())
s = input()
count = 0
for i in range(1, n + 1):
    for j in range(n - i + 1):
        num = 0
        for k in range(i):
            num += int(s[j + k]) * (10 ** (i - k - 1))
        if(num % p == 0):
            count += 1
print(count)

### FIXED CODE ###

n, p = map(int,input().split())
D = input()
out = 0


if 10 % p == 0:
    for i in range(n):
        if int(D[i]) % p == 0:
            out += i + 1
else:
    mod = 0
    count = [0] * p
    ten = 1
    count[mod] += 1
    for i in range(n):
        mod = (mod + int(D[n-i-1]) * ten) % p
        ten = ten * 10 % p
        count[mod] += 1
    for c in count:
        out += (c * (c - 1)) // 2
print(out)
### BUGGY CODE ###

n,k,l=[int(x) for x in input().split()]
from collections import deque
road=[[i] for i in range(n)]
rail=[[i] for i in range(n)]
for i in [0]*k:
    p,q=[int(x)-1 for x in input().split()]
    road[p].append(q)
    road[q].append(p)
for i in [0]*l:
    r,s=[int(x)-1 for x in input().split()]
    rail[r].append(s)
    rail[s].append(r)
flag=[0]*n
for i in range(n):
    if flag[i]==1:
        continue
    d=deque(road[i])
    while d:
        tmp=d.popleft()
        if flag[tmp]==1:
            continue
        flag[tmp]=1
        for j in road[tmp]:
            if j not in road[i]:
                d.append(j)
                road[i].append(j)
    for j in road[i]:
        road[j]=road[i]
flag=[0]*n
for i in range(n):
    if flag[i]==1:
        continue
    d=deque(rail[i])
    while d:
        tmp=d.popleft()
        if flag[tmp]==1:
            continue
        for j in rail[tmp]:
            if j not in rail[i] :
                d.append(j)
                rail[i].append(j)
    for j in rail[i]:
        rail[j]=rail[i]
ans=[]
for i,j in zip(road,rail):
    ans.append(str(len(set(i)&set(j))))
print(" ".join(ans))

### FIXED CODE ###

n,k,l=[int(x) for x in input().split()]
from collections import deque
road=[{i} for i in range(n)]
rail=[{i} for i in range(n)]
for i in [0]*k:
    p,q=[int(x)-1 for x in input().split()]
    road[p].add(q)
    road[q].add(p)
for i in [0]*l:
    r,s=[int(x)-1 for x in input().split()]
    rail[r].add(s)
    rail[s].add(r)
flag=[0]*n
for i in range(n):
    if flag[i]==1:
        continue
    flag[i]=1
    d=deque(road[i])
    while d:
        tmp=d.popleft()
        if flag[tmp]==1:
            continue
        flag[tmp]=1
        d.extend(road[tmp])
        road[i].update(road[tmp])
    for j in road[i]:
        road[j]=road[i]
flag=[0]*n
for i in range(n):
    if flag[i]==1:
        continue
    flag[i]=1
    d=deque(rail[i])
    while d:
        tmp=d.popleft()
        if flag[tmp]==1:
            continue
        flag[tmp]=1
        d.extend(rail[tmp])
        rail[i].update(rail[tmp])
    for j in rail[i]:
        rail[j]=rail[i]
ans=[0]*n
for i in range(n):
    if ans[i]!=0:
        continue
    sumset=road[i]&rail[i]
    for j in sumset:
        ans[j]=str(len(sumset))
print(" ".join(ans))
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
from collections import Counter


def solve(N: int, a: "List[int]"):

    c = [0]*4
    for A in a:
        c[A] += 1
    kitai = [[[0]*(c[1]+c[2]+c[3]+2) for _ in range(c[2]+c[3]+2)]
             for _ in range(c[3]+1)]
    for k in range(c[3]+1):
        for j in range(c[2]+c[3]+1):
            for i in range(c[1]+c[2]+c[3]+1):
                tot = i+j+k
                if tot == 0:
                    continue
                kitai[k][j][i] = N + kitai[k][j][i-1]*i + kitai[k][j-1][i+1]*j
                kitai[k][j][i] += kitai[k-1][j+1][i]*k
                kitai[k][j][i] /= tot
    print(kitai[c[3]][c[2]][c[1]])

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys


def solve(N: int, a: "List[int]"):

    c = [0]*4
    for A in a:
        c[A] += 1

    J = min(c[2]+c[3]+1, N+1)
    I = min(c[1]+c[2]+c[3]+1, N+1)
    kitai = [[[0]*(I+1) for _ in range(J+1)]
             for _ in range(c[3]+1)]
    for k in range(c[3]+1):
        for j in range(J):
            for i in range(I):
                tot = i+j+k
                if tot == 0 or tot > N:
                    continue
                res = N + kitai[k][j][i-1]*i + \
                    kitai[k][j-1][i+1]*j + kitai[k-1][j+1][i]*k
                kitai[k][j][i] = res/tot
    print(kitai[c[3]][c[2]][c[1]])

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

X,K,D=map(int,input().split())
kai = 0
xy = abs(X)
ds = D
if xy >= K*D:
    kotae = abs(xy-(K*D))
if xy < K*D:
    while xy >ds:
        ds=ds+D
        kai = kai+1
    ds = ds-D
    if (K-kai)%2==0:
        kotae = abs(xy-ds)
    if (K-kai)%2!=0:
        kouho1 = abs(xy-ds-D)
        kouho2 = abs(xy-ds+D)
        if kouho1>=kouho2:
            kotae = kouho2
        if kouho1<kouho2:
            kotae = kouho1
print(kotae)

### FIXED CODE ###

X,K,D=map(int,input().split())
kai = 0
xy = abs(X)
if xy >= K*D:
    kotae = abs(xy-(K*D))
if xy < K*D:
    kai, mod = divmod(xy, D)
    ds = kai*D
    if (K-kai)%2==0:
        kotae = abs(xy-ds)
    if (K-kai)%2!=0:
        kouho1 = abs(xy-ds-D)
        kouho2 = abs(xy-ds+D)
        if kouho1>=kouho2:
            kotae = kouho2
        if kouho1<kouho2:
            kotae = kouho1
print(kotae)
### BUGGY CODE ###

s = input()
q = int(input())

for _ in range(q):
    query = list(input().split())

    if query[0] == "1":
        s = s[::-1]

    elif query[0] == "2":
        if query[1] == "1":
            s = query[2] + s
        elif query[1] == "2":
            s = s + query[2]

print(s)

### FIXED CODE ###

s = input()
q = int(input())

up = 0

head = []
tail = []

for _ in range(q):
    query = list(input().split())

    if query[0] == "1":
        if up:
            up = 0
        else:
            up = 1

    elif query[0] == "2":
        if query[1] == "1":
            if up:
                tail.append(query[2])
            else:
                head.append(query[2])
        elif query[1] == "2":
            if up:
                head.append(query[2])
            else:
                tail.append(query[2])

head=''.join(map(str,head))
tail=''.join(map(str,tail))

ans = head[::-1] + s + tail

if up:
    ans = ans[::-1]
print(ans)
### BUGGY CODE ###

n=int(input())
a=[int(input()) for i in range(n)]

b=a[0]
cnt=1
while b!=2:
  b=a[b-1]
  cnt+=1
  if b==a[0]:
    print(-1)
    exit()
    
print(cnt)




### FIXED CODE ###

n=int(input())
a=[int(input()) for i in range(n)]

b=a[0]
cnt=1
if b==2:
  print(cnt)
else:
  
  while cnt<=n+2:
    b=a[b-1]
    cnt+=1
    if b==2:
      print(cnt)
      exit()
      
  print(-1)
### BUGGY CODE ###

A, B, Q = map(int, input().split())
S, T =[None] * (A+2), [None] * (B+2)
S[0], T[0] = -10**20, -10**20
for i in range(A):
    S[i+1] = int(input())
for i in range(B):
    T[i+1] = int(input())
S[-1] = 10**20
T[-1] = 10**20

def Bsearch(x, L, lenL):
    low, high = 0, lenL
    while high-low > 1:
        mid = (low+high)//2
        if L[mid] > x:
            high = mid
        else: low = mid
    return [x-L[low], L[low+1]-x]

lenS, lenT = len(S), len(T)
for _ in range(Q):
    x = int(input())
    sLength0, sLength1 = Bsearch(x, S, lenS)
    tLength0, tLength1 = Bsearch(x, T, lenT)
    Ans = (max(sLength0, tLength0), max(sLength1, tLength1), sLength0 + tLength1 + min(sLength0, tLength1), sLength1 + tLength0 + min(sLength1, tLength0))
    print(min(Ans))

### FIXED CODE ###

from bisect import bisect
A, B, Q = map(int, input().split())
S, T =[None] * (A+2), [None] * (B+2)
S[0], T[0] = -10**20, -10**20
for i in range(A):
    S[i+1] = int(input())
for i in range(B):
    T[i+1] = int(input())
S[A+1] = 10**20
T[B+1] = 10**20

lenS, lenT = len(S), len(T)
for _ in range(Q):
    x = int(input())
    si, ti = bisect(S, x, 0, lenS), bisect(T, x, 0, lenT)
    sLength0, sLength1 = x - S[si-1], S[si] - x
    tLength0, tLength1 = x - T[ti-1], T[ti] - x
    Ans = (max(sLength0, tLength0), max(sLength1, tLength1), sLength0 + tLength1 + min(sLength0, tLength1), sLength1 + tLength0 + min(sLength1, tLength0))
    print(min(Ans))
### BUGGY CODE ###

x, y, z, k = map(int, input().split())
X = [int(i) for i in input().split()]
Y = [int(i) for i in input().split()]
Z = [int(i) for i in input().split()]

count = []

for i in X:
    for j in Y:
        for l in Z:
            count.append(i+j+l)

count.sort(reverse=1)

for c in range(k):
    print(count[c])


### FIXED CODE ###

x, y, z, k = map(int, input().split())
X = [int(i) for i in input().split()]
Y = [int(i) for i in input().split()]
Z = [int(i) for i in input().split()]
X.sort(reverse=1)
Y.sort(reverse=1)
Z.sort(reverse=1)

answer = [i+j for i in X[:k] for j in Y[:k]]
answer.sort(reverse=1)

answer2 = [i+j for i in Z[:k] for j in answer[:k]]
answer2.sort(reverse=1)

for p in answer2[:k]:
    print(p)
### BUGGY CODE ###

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

dictS={}
dictS[0]=1

for n in range (1,N+1):
    if n-1<K:
        dictS[n]=A[n-1]*dictS[n-1]
    else:
        dictS[n]=A[n-1]*dictS[n-1]/A[n-1-K]

    if n>K:
        if dictS[n]>dictS[n-1]:
            print('Yes')
        else:
            print('No')


### FIXED CODE ###

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

for i in range (K,N):
    if A[i]>A[i-K]:
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###


n = int(raw_input())
stack = []
for i in range(n):
	i = raw_input()
	if "insert" in i:
		try:
		    stack.insert(0, int(i[7:]))
		except:
			pass
	elif "delete " in i:
		try:
		    stack.remove(int(i[7:]))
		except:
			pass
	elif "deleteFirst" in i:
		stack.pop(0)
	elif "deleteLast" in i:
		stack.pop()
print " ".join(map(str, stack))

### FIXED CODE ###

from collections import deque
n = int(raw_input())
stack = deque()
for i in range(n):
	i = raw_input()
	if "insert" in i:
		stack.appendleft(int(i[7:]))
	elif "delete " in i:
		if int(i[7:]) in stack:
		    stack.remove(int(i[7:]))
	elif "deleteFirst" in i:
		stack.popleft()
	elif "deleteLast" in i:
		stack.pop()
print " ".join(map(str, stack))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**7)
N=int(input())
List=[[] for i in range(N)]
for i in range(1,N):
  a=int(input())
  List[a-1].append(i)

def f(x):
  if len(List[x])==0:
    return 0
  L=list(map(lambda a:f(a),List[x]))
  L.sort(key=lambda x:-x)
  res=0
  for i in range(len(L)):
    res=max(res,L[i]+i+1)
  return res
print(f(0))
  

### FIXED CODE ###

import sys
from heapq import heapify,heappush,heappop
sys.setrecursionlimit(10**7)
input=sys.stdin.readline
N=int(input())
List=[[] for i in range(N)]
for i in range(1,N):
  a=int(input())
  List[a-1].append(i)

def f(x):
  if len(List[x])==0:
    return 0
  L=[]
  heapify(L)
  for a in List[x]:
    heappush(L,f(a))
  n=len(L)
  res=0
  for i in range(n):
    b=heappop(L)
    res=max(res,b+n-i)
  return res
print(f(0))
### BUGGY CODE ###

# E - Crested Ibis vs Monster
H, N = map(int, input().split())
AB = []
for i in range(N):
    a, b = map(int, input().split())
    AB.append((a,b))
AB.sort()

DP = [float('inf') for i in range(2*10**4 + 1)]
DP[0] = 0
for i in range(H):
    for ab in AB:
        DP[i+ab[0]] = min(DP[i+ab[0]], DP[i] + ab[1])

print(min(DP[H:]))


### FIXED CODE ###

# E - Crested Ibis vs Monster
H, N = map(int, input().split())
AB = []
for i in range(N):
    a, b = map(int, input().split())
    AB.append([a,b])
AB.sort()

DP = [float('inf') for i in range(2*10**4 + 1)]
DP[0] = 0
for i in range(H):
    for ab in AB:
        DP[i+ab[0]] = min(DP[i+ab[0]], DP[i] + ab[1])

print(min(DP[H:]))
### BUGGY CODE ###

n = int(input())

member = list(map(int, input().split()))
ans = []

for i in range(n):
    ans.append((member.index(i+1))+1)

# print(' '.join(map(str, ans)))    
print(*ans)


### FIXED CODE ###

n = int(input())

member = list(map(int, input().split()))
ans = [0]*n

for i,num in enumerate(member):
    ans[num-1] = i+1

# print(' '.join(map(str, ans)))    
print(*ans)
### BUGGY CODE ###

N = int(input())
S = [input() for _ in range(N)]

dic = {}

for s in S:
  if s not in dic.keys():
    dic.setdefault(s, 0)
  dic[s] += 1

answers = [k for k, v in dic.items() if v == max(dic.values())]
answers.sort()
for x in answers:
  print(x)

### FIXED CODE ###

import collections
N = int(input())
counter = collections.Counter([input() for _ in range(N)])
maximum = max(counter.values())
answers = [k for k, v in counter.items() if v == maximum]
answers.sort()
for x in answers:
  print(x)
### BUGGY CODE ###

X = int(input())
X_MOD = X % 100
X_DIV = X // 100

import sys
sys.setrecursionlimit(2000)
def dfs(sum_x, cnt_x):
    if cnt_x > X_DIV:
        return False
    if sum_x == X_MOD:
        return True

    
    return dfs(sum_x+1, cnt_x+1) or dfs(sum_x+1, cnt_x+2) or dfs(sum_x+3, cnt_x+1) or dfs(sum_x+4, cnt_x+1) or dfs(sum_x+5, cnt_x+1)
    

ans = int(dfs(0,0))
print(ans)

### FIXED CODE ###

X = int(input())
X_MOD = X % 100
X_DIV = X // 100

import sys
sys.setrecursionlimit(2000)
def dfs(sum_x, cnt_x, num):
    if cnt_x > X_DIV:
        return False
    if sum_x == X_MOD:
        return True

    if num == 1:
        return dfs(sum_x+1, cnt_x+1, 1) or dfs(sum_x+1, cnt_x+2, 2) or dfs(sum_x+3, cnt_x+1, 3) or dfs(sum_x+4, cnt_x+1, 4) or dfs(sum_x+5, cnt_x+1, 5)
    if num == 2:
        return dfs(sum_x+1, cnt_x+2, 2) or dfs(sum_x+3, cnt_x+1, 3) or dfs(sum_x+4, cnt_x+1, 4) or dfs(sum_x+5, cnt_x+1, 5)
    if num == 3:
        return dfs(sum_x+3, cnt_x+1, 3) or dfs(sum_x+4, cnt_x+1, 4) or dfs(sum_x+5, cnt_x+1, 5)
    if num == 4:
        return dfs(sum_x+4, cnt_x+1, 4) or dfs(sum_x+5, cnt_x+1, 5)
    if num == 5:
        return dfs(sum_x+5, cnt_x+1, 5)
    

ans = int(dfs(0,0,1))
print(ans)
### BUGGY CODE ###

n,q=map(int,input().split())
node=[0 for i in range(n)]
tree=[]
for i in range(n-1):
    tree.append(list(map(int,input().split())))
def counter(p,x,cnt):
    for i in range(n-1):
        if tree[i][0]==p:
            if cnt[tree[i][1]-1]!=1:
                node[tree[i][1]-1]+=x
                cnt[tree[i][1]-1]=1
                counter(tree[i][1],x,cnt)
            else:
                continue
        
        
for j in range(q):
    cnt=[0 for i in range(n)]
    p,x=map(int,input().split())
    cnt[p-1]=1
    node[p-1]+=x
    counter(p,x,cnt)

for i in range(n):
    node[i]=str(node[i])
print(' '.join(node))




### FIXED CODE ###

n,q=map(int,input().split())
c=[0 for i in range(n)]
tree=sorted([list(map(int,input().split())) for i in range(n-1)])
for j in range(q):
    p,x=map(int,input().split())
    c[p-1]+=x
for i in range(n-1):
    c[tree[i][1]-1]+=c[tree[i][0]-1]
for i in range(n):
    c[i]=str(c[i])
print(' '.join(c))
### BUGGY CODE ###

def main():
    import collections

    S = input()

    mod_list = [0]+[False for i in range(len(S))]

    for i in range(len(S)):
        index = len(S) - i - 1
        
        num = int(S[index:])
        mod_list[i+1] = num % 2019


    CTR_mod_list = collections.Counter(mod_list).most_common()
    cnt = 0

    for i in range(len(CTR_mod_list)):
        n = CTR_mod_list[i][1]

        if (n == 1):
            break
        
        cnt += n * (n - 1) // 2

    print(cnt)

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    import collections

    S = input()

    mod_list = [0]

    for i in range(len(S)):
        index = len(S) - i - 1
        num = int(S[index])

        mod_list.append((mod_list[-1] + num * pow(10, i, 2019)) % 2019)

    CTR_mod_list = collections.Counter(mod_list).most_common()
    cnt = 0

    for i in range(len(CTR_mod_list)):
        n = CTR_mod_list[i][1]

        if (n == 1):
            break

        cnt += n * (n - 1) // 2

    print(cnt)

if __name__ == '__main__':
    main()
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
inp = sys.stdin.buffer.readline
def inpS(): return input().rstrip().decode()
readlines = sys.stdin.buffer.readlines  

N = int(inp())
A = list(map(int, input().split()))
MOD = 10**9+7

ans = 0
for k in range(60):
  x0 = 0 # k桁目のbitが0になる総数
  x1 = 0 # k桁目のbitが1になる総数
  # k桁目が 0, 1 のどちらかを数えておく
  for a in A:
    if a>>k & 1:
      x1 += 1
    else:
      x0 += 1
  p = 1
  for i in range(k):
    p *= 2
    p %= MOD
  # x0 * x1 が 0, 1 の組み合わせ数
  cnt = (x0 * x1) % MOD
  ans += cnt * p
  ans %= MOD
print(ans)  
    
      

### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
inp = sys.stdin.buffer.readline
def inpS(): return input().rstrip().decode()
readlines = sys.stdin.buffer.readlines  

import numpy as np

N = int(inp())
A = np.array(inp().split(), dtype=np.int64)
MOD = 10**9+7

ans = 0
for k in range(60):
  x0 = 0 # k桁目のbitが0になる総数
  x1 = 0 # k桁目のbitが1になる総数
  B = (A>>k) & 1 # k桁目が1になる要素
  
  # k桁目が 0, 1 のどちらかを数えておく
  x1 = np.count_nonzero(B)
  x0 = N - x1
  # x0 * x1 が 0, 1 の組み合わせ数
  cmb = x0 * x1
  
  for _ in range(k): # 10進数に変換
    cmb *= 2
    cmb %= MOD
  ans += cmb
print(ans%MOD)