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

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

i = 0
cnt = 1
while True:
    if a[i] == 1:
        cnt = -1
        break
    elif a[i] == 2:
        break
    else:
        i = a[i] - 1
        cnt += 1
print(cnt)

### FIXED CODE ###

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

i = 0
cnt = 1
while True:
    if cnt > len(a):
        cnt = -1
        break
    if a[i] == 1:
        cnt = -1
        break
    elif a[i] == 2:
        break
    else:
        i = a[i] - 1
        cnt += 1
print(cnt)
### BUGGY CODE ###

n=int(input())

x=1
for i in range(1,n+1):
    x*=i
print(x%(10**9+7))

### FIXED CODE ###

n=int(input())

x=1
for i in range(1,n+1):
    x*=i
    x%=10**9+7

print(x)
### BUGGY CODE ###

#2020-04-29
k, s = map(int,input().split())
cou = 0
for i in range(k + 1):
    for j in range(k + 1):
        for t in range(k + 1):
            if s == i + j + t:
                cou += 1
print(cou)

### FIXED CODE ###

#2020-04-29
k, s = map(int,input().split())
cou = 0
for i in range(k + 1):
    for j in range(k + 1):
        z = s - i - j
        if 0 <= z <=k:
            cou += 1
print(cou)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
q = int(input())
change = [list(map(int, input().split())) for i in range(q)]
for i in range(q):
    a = [change[i][1] if j == change[i][0] else j for j in a]
    print(sum(a))

### FIXED CODE ###

import collections
n = int(input())
arr = list(map(int,input().split()))
cnt = collections.defaultdict(int)
for val in arr:
    cnt[val] += 1
sums = sum(arr)
q = int(input())
for _ in range(q):
    b, c = map(int,input().split())
    diff = (c-b)*(cnt[b])
    sums += diff
    print(sums)
    cnt[c] += cnt[b]
    cnt[b] = 0
### BUGGY CODE ###

S = input()

length = len(S)

cnt = 0
temp = int(S[ : 4])
for x in range(length):
    first = temp
    for i in range(x + 4, length + 1):
        if temp % 2019 == 0:
            cnt += 1
        #print(temp, cnt)

        if i < length:
            temp = temp * 10 + int(S[i])
        else:
            if x + 4 < length:
                temp = (first - (int(S[x]) * 1000))
                temp = temp * 10 + int(S[x + 4])



print(cnt)



### FIXED CODE ###

S = input()[::-1]

length = len(S)
dp = [0] * (length + 2)

times = 1
for x in range(1, length + 1):
    dp[x] += dp[x - 1]
    dp[x] %= 2019
    dp[x] += int(S[x - 1]) * times
    dp[x] %= 2019
    times *= 10
    times %= 2019


cnt = [0] * 2020
for x in range(length + 1):
    cnt[dp[x]] += 1

ans = 0
for c in cnt:
    ans += (c * (c - 1)//2)

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

import collections


def read_nums():
    return map(int, raw_input().split(' '))


H, W, N = read_nums()
As = [0 for _ in range(N)]
Bs = [0 for _ in range(N)]
vs = []
for i in range(-1, 2):
    for j in range(-1, 2):
        vs.append((i, j))

cnt = []
for i in range(N):
    a, b = read_nums()
    for v in vs:
        i, j = v
        x = a + i
        y = b + j
        if x >= 2 and x <= H-1 and y >= 2 and y <= W-1:
            cnt.append(x * W + y)
cnt = collections.Counter(cnt)
cnt2 = [0] * 10
cnt2[0] = (H - 2) * (W - 2)
for k, v in cnt.items():
    cnt2[v] += 1
    cnt2[0] -= 1
for c in cnt2:
    print c


### FIXED CODE ###

import collections


def read_nums():
    return map(int, raw_input().split(' '))


H, W, N = read_nums()

vs = []
for i in range(-1, 2):
    for j in range(-1, 2):
        vs.append((i, j))

cnt = []
for i in range(N):
    a, b = read_nums()
    for v in vs:
        i, j = v
        x = a + i
        y = b + j
        if x >= 2 and x <= H-1 and y >= 2 and y <= W-1:
            cnt.append(x * W + y)

cnt = collections.Counter(cnt)
cnt2 = [0] * 10
cnt2[0] = (H - 2) * (W - 2)

for k in cnt:
    cnt2[cnt[k]] += 1
    cnt2[0] -= 1

for c in cnt2:
    print c
### BUGGY CODE ###

N=int(input())
A=[int(input()) for i in range(N)]
print(len([i for i in list(set(A)) if A.count(i)%2==1]))

### FIXED CODE ###

N=int(input())
A=[int(input()) for i in range(N)]
dict = {}
for i in A:
  if i not in dict:
    dict[i] = 1
  else:
    dict[i] += 1
print(len([1 for i in dict.values() if i%2!=0]))
### BUGGY CODE ###

n,k = map(int,input().split())
a = [int(i) for i in input().split()]
a.sort()
L = -10**18-1
R = 10**18+1
while L+1 < R:
    M = (L+R)//2
    total = 0
    for i in range(n):
        l = -1
        r = n
        if a[i] < 0:
            while l+1 < r:
                m = (l+r)//2
                if a[m] * a[i] < M:
                    r = m
                else:
                    l = m
            total += n-r
        else:
            while l+1 < r:
                m = (l+r)//2
                if a[m] * a[i] < M:
                    l = m
                else:
                    r = m
            total += r
        if a[i]*a[i] < M: total -= 1
    total //= 2
    if total < k:
        L = M
    else:
        R = M
print(L)

### FIXED CODE ###

N,K = map(int,input().split())
plst = []
nlst = []
p = 0
z = 0
n = 0
for i in map(int,input().split()):
    if i > 0:
        p += 1
        plst.append(i)
    elif i == 0:
        z += 1
    else:
        n += 1
        nlst.append(i)
plst.sort()
nlst.sort()
zp = (p+n)*z + z*(z-1)//2
np = p*n
if K <= np:
    l = -10**18-1
    r = 0
    while l+1 < r:
        m = (l+r)//2
        total = 0
        idx = 0
        for i in range(p):
            while idx < n:
                if plst[i] * nlst[idx] < m:
                    idx += 1
                else:
                    total += idx
                    break
            else:
                total += idx
        if total < K:
            l = m
        else:
            r = m
    ans = l
elif K <= np+zp:
    ans = 0
else:
    l = 0
    r = 10**18+1
    while l+1 < r:
        m = (l+r)//2
        total = np+zp
        tmp = 0
        idx = 0
        for i in range(p)[::-1]:
            while idx < p:
                if plst[i] * plst[idx] < m:
                    idx += 1
                else:
                    tmp += idx
                    break
            else:
                tmp += idx
            if plst[i] * plst[i] < m: tmp -= 1
        tmp //= 2
        total += tmp
        tmp = 0
        idx = 0 
        for i in range(n):
            while idx < n:
                if nlst[i] * nlst[-idx-1] < m:
                    idx += 1
                else:
                    tmp += idx
                    break
            else:
                tmp += idx
            if nlst[i] * nlst[i] < m: tmp -= 1
        tmp //= 2
        total += tmp
        if total < K:
            l = m      
        else:
            r = m
    ans = l
print(ans)
### BUGGY CODE ###

n = int(input())

def primes(m) :
    ps = [2]
    for i in range(3, m) :
        for p in ps :
            if i%p == 0 :
                break
        else :
            ps.append(i)
    return ps

def fdivisor(m) :
    ps = primes(m)
    df = {p:0 for p in ps}
    for i in range(1, m+1) :
        ii = i
        while ii != 1 :
            for p in ps :
                if ii%p == 0 :
                    df[p] += 1
                    ii //= p
    return df

ans = 0
df = fdivisor(n)
over2 = len([v for v in df.values() if v >= 2])
over4 = len([v for v in df.values() if v >= 4])
over14 = len([v for v in df.values() if v >= 14])
over24 = len([v for v in df.values() if v >= 24])
over74 = len([v for v in df.values() if v >= 74])
ans += over4*(over4-1)//2*(over2-2)
ans += over14*(over4-1)
ans += over24*(over2-1)
ans += over74

print(ans)

### FIXED CODE ###

n = int(input())

def primes(m) :
    ps = [2]
    for i in range(3, m+1) :
        for p in ps :
            if i%p == 0 :
                break
        else :
            ps.append(i)
    return ps

def fdivisor(m) :
    ps = primes(m)
    df = {p:0 for p in ps}
    for i in range(1, m+1) :
        ii = i
        while ii != 1 :
            for p in ps :
                if ii%p == 0 :
                    df[p] += 1
                    ii //= p
    return df

ans = 0
df = fdivisor(n)
over2 = len([v for v in df.values() if v >= 2])
over4 = len([v for v in df.values() if v >= 4])
over14 = len([v for v in df.values() if v >= 14])
over24 = len([v for v in df.values() if v >= 24])
over74 = len([v for v in df.values() if v >= 74])
ans += over4*(over4-1)//2*(over2-2)
ans += over14*(over4-1)
ans += over24*(over2-1)
ans += over74

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

if __name__ == "__main__":
    x = input()
    x = int(x)

    digits = 200000
    index = 200000

    tmp1 = []
    for i in range(digits):
        tmp2 = pow(2,index)

        if(tmp2>x):
            continue
        tmp3 = x%tmp2
        if tmp2 != 0:
            x -= tmp3*index
            tmp1.append(tmp3)
        index -= 1
    result1 = sum(tmp1)

    if(result1%9 ==0):
        print("Yes")
    else:
        print("No")



### FIXED CODE ###

def check(st) : 
  
    # Compute sum of digits 
    n = len(st) 
    digitSum = 0
      
    for i in range(0,n) : 
        digitSum = digitSum + (int)(st[i]) 
  
    # Check if sum of digits 
    # is divisible by 9. 
    return (digitSum % 9 == 0) 
  
# Driver code 
x = input()
st= str(x)
  
if(check(st)) : 
    print("Yes") 
else :  
    print("No")
### BUGGY CODE ###

N = int(input())
P = list(map(int, input().split()))
count = 1
for i in range(1, N):
  if P[i] <= min(P[:i]):
    count += 1
print(count)

### FIXED CODE ###

N = int(input())
P = list(map(int, input().split()))
count = 1
min = P[0]
for i in range(1, N):
  if P[i] <= min:
    count += 1
    min = P[i]
print(count)
### BUGGY CODE ###

import sys

sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
s = input().rstrip()
gx, gy = map(int, input().split())
rx, ry = 0, 0
head, inst = 0, []
while head < len(s) and s[head] == "F":
    head += 1
    rx += 1
while head < len(s):
    tcnt = 0
    while head < len(s) and s[head] == "T":
        tcnt += 1
        head += 1
    fcnt = 0
    while head < len(s) and s[head] == "F":
        fcnt += 1
        head += 1
    inst.append((tcnt % 2, fcnt))

f_total = sum([f for (_, f) in inst])
f_rem = [0] * (len(inst) + 1)
f_rem[len(inst)] = 0
for i in range(len(inst) - 1, -1, -1):
    f_rem[i] = f_rem[i + 1] + inst[i][1]
assert f_rem[0] == f_total


visited = set()


def reach(i, x, y, dx, dy):
    dist = abs(gx - x) + abs(gy - y)
    # print(f"i={i} ({x},{y}) dist={dist}: inst={inst[i:]}")
    if i == len(inst):
        return dist == 0
    if (i, x, y, dx, dy) in visited:
        return False
    visited.add((i, x, y, dx, dy))
    if dist > f_rem[i] or dist % 2 != f_rem[i] % 2:
        return False
    t, f = inst[i]
    if t:
        dy, dx = dx, -dy
    if reach(i + 1, x + f * dx, y + f * dy, dx, dy):
        return True
    if reach(i + 1, x - f * dx, y - f * dy, -dx, -dy):
        return True
    return False


print("Yes" if reach(0, rx, ry, 1, 0) else "No")


### FIXED CODE ###

"""Knapsack"""
import sys

sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
s = input().rstrip()
gx, gy = map(int, input().split())
rx, ry = 0, 0
head, inst = 0, []
while head < len(s) and s[head] == "F":
    head += 1
    rx += 1

xlist, ylist = [], []
heading_x = True
while head < len(s):
    tcnt = 0
    while head < len(s) and s[head] == "T":
        tcnt += 1
        head += 1
    if head == len(s):
        break
    fcnt = 0
    while head < len(s) and s[head] == "F":
        fcnt += 1
        head += 1
    if ((tcnt % 2) == 1) ^ heading_x:
        heading_x = True
        xlist.append(fcnt)
    else:
        heading_x = False
        ylist.append(fcnt)


def fill(fs, goal_offset):
    f_total = sum(fs)
    if f_total < goal_offset:
        return False
    if f_total == goal_offset:
        return True
    f_diff = f_total - goal_offset
    if f_diff % 2 == 1:
        return False
    f_diff //= 2
    diffs = {0}
    for f in fs:
        for d in list(diffs):
            d2 = f + d
            if d2 > f_diff:
                continue
            if d2 == f_diff:
                return True
            diffs.add(d2)
    return False


if fill(xlist, abs(gx - rx)) and fill(ylist, abs(gy - ry)):
    print("Yes")
else:
    print("No")
### BUGGY CODE ###

N = int(input())
s = [sorted(input()) for _ in range(N)]
c = 0
print(sum([1 for i in range(N-1) for j in range(i+1, N) if s[i]==s[j]]))

### FIXED CODE ###

N = int(input())
o = {}
c = 0
for _ in range(N):
    k = "".join(sorted(input()))
    if k not in o:
        o[k] = 0
    else:
        o[k] += 1
        c += o[k]
print(c)
### BUGGY CODE ###

from functools import lru_cache
import sys
sys.setrecursionlimit(20000000)
INF = float('inf')

N, K = map(int, input().split())
h = list(map(int, input().split()))
n = len(h)-1

@lru_cache(maxsize=None)
def rec(i):
    if i==0:
        return 0
    res = INF
    for j in range(1,K+1):
        if i-j>=0:
            res = min(res, rec(i-j)+abs(h[i]-h[i-j]))
    return res
print(rec(n))

### FIXED CODE ###

def chmin(a,b):
    if a > b:
        return b
    else:
        return a


N, K = map(int, input().split())
h = list(map(int, input().split()))
INF = float('inf')
dp = [INF] * N
dp[0] = 0


for i in range(N):
    for j in range(1,K+1):
        if i+j < N:
            dp[i+j] = chmin(dp[i+j], dp[i] + abs(h[i] - h[i+j]))

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

def main():
    s = input()
    count = 0

    for i in range(1, len(s)):
        if s[i] == 'W':
            part_s = s[0:i]
            count += part_s.count('B')

    print(count)


if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    s = input()
    count = 0
    black_count = 0
    for i in range(len(s)):
        if s[i] == 'B':
            black_count += 1
        if s[i] == 'W':
            count += black_count

    print(count)


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

from bisect import bisect_left
def comb(n,k):
    nCk = 1
    mod = 10**9+7
    for i in range(n-k+1, n+1):
        nCk *= i
        nCk %= mod
    for i in range(1, k+1):
        nCk *= pow(i, mod-2, mod)
        nCk %= mod
    return nCk

n = int(input())
A = list(map(int,input().split()))
A.sort()
y = max(A)
idx = bisect_left(A, y//2)
ans = -1
x = idx
for i in range(max(0, idx-1), min(n+1, idx+1)):
    if comb(y, A[i]) > ans:
        ans = comb(y,A[i])
        x = A[i]
print(y,x)

### FIXED CODE ###

n = int(input())
lst = list(map(int,input().split()))
lst.sort()

m = lst[-1]
line = m / 2
r = 10**10

for i in range(n):
    if abs(r-line) > abs(lst[i]-line):
        r = lst[i]
print(m,r)
### BUGGY CODE ###

from collections import deque
import sys
input = sys.stdin.readline


N, M = map(int, input().split())

obvs = list(range(1,N+1,1))

obvs_height = list(map(int, input().split()))
#print(obvs)

def get_height_of_obvs(i):
    return obvs_height[i-1]

def remove_obvs_if_exist(i):
    if i in obvs:
        obvs.remove(i)

while True:
    #print(obvs)
    path = list(map(int, input().strip().split()))
    if path==[]:
        break
    if get_height_of_obvs(path[0]) == get_height_of_obvs(path[1]):
        remove_obvs_if_exist(path[0])
        remove_obvs_if_exist(path[1])

    elif get_height_of_obvs(path[0]) > get_height_of_obvs(path[1]):
        remove_obvs_if_exist(path[1])
    elif get_height_of_obvs(path[0]) < get_height_of_obvs(path[1]):
        remove_obvs_if_exist(path[0])

print(len(obvs))

### FIXED CODE ###

from collections import deque
import sys
input = sys.stdin.readline


N, M = map(int, input().split())

obvs = list(range(1,N+1,1))
obvs_height = list(map(int, input().split()))
#print(obvs)

obvs = {}
i = 1
for h in obvs_height:
    obvs[i] = h
    i += 1

obvs_remain = obvs.copy()

while True:
    path = list(map(int, input().strip().split()))
    if path==[]:
        break
    if obvs[path[0]] == obvs[path[1]]:
        obvs_remain.pop(path[0], None)
        obvs_remain.pop(path[1], None)
    elif obvs[path[0]] > obvs[path[1]]:
        obvs_remain.pop(path[1], None)
    elif obvs[path[0]] < obvs[path[1]]:
        obvs_remain.pop(path[0], None)

print(len(obvs_remain))
### BUGGY CODE ###

X = int(input())
lists = []
max = 1
for i in range(1,X+1):
    for j in range(2,X+1):
        if i**j <= X:
            if max < i**j:
                max = i**j
print(max)


### FIXED CODE ###

X = int(input())
lists = []
max = 1
for i in range(1,X+1):
    for j in range(2,X+1):
        if i**j <= X:
            if max < i**j:
                max = i**j
        elif i**j > X:
            break
print(max)
### BUGGY CODE ###

H, W = map(int, input().split())

S = []
for i in range(H):
    S.append(input())

b = [[[0, 0, 0, 0] for w in range(W)] for h in range(H)]

for h in range(H):
    for w in range(W):
        if S[h][w] == '#':
            continue
        # up
        if h-1 < 0 or S[h-1][w] == '#':
            b[h][w][0] = 0
        else:
            b[h][w][0] = b[h-1][w][0] + 1
        # left
        if w-1 < 0 or S[h][w-1] == '#':
            b[h][w][1] = 0
        else:
            b[h][w][1] = b[h][w-1][1] + 1

for h in range(H-1, -1, -1):
    for w in range(W-1, -1, -1):
        if S[h][w] == '#':
            continue
        # down
        if h+1 >= H or S[h+1][w] == '#':
            b[h][w][2] = 0
        else:
            b[h][w][2] = b[h+1][w][2] + 1
        # right
        if w+1 >= W or S[h][w+1] == '#':
            b[h][w][3] = 0
        else:
            b[h][w][3] = b[h][w+1][3] + 1

#for h in range(H):
#    print(b[h])
ans = 0
for h in range(H):
    for w in range(W):
        if S[h][w] == '#':
            continue
        tmp = sum(b[h][w]) + 1
        if tmp > ans:
            ans = tmp

print(ans)


### FIXED CODE ###

H, W = map(int, input().split())

S = []
for i in range(H):
    S.append(input())

U = [[0] * W for h in range(H)]
D = [[0] * W for h in range(H)]
L = [[0] * W for h in range(H)]
R = [[0] * W for h in range(H)]

for h in range(H):
    for w in range(W):
        if S[h][w] == 1:
            continue
        # up
        if h-1 < 0 or S[h-1][w] == '#':
            U[h][w] = 0
        else:
            U[h][w] = U[h-1][w] + 1
        # left
        if w-1 < 0 or S[h][w-1] == '#':
            L[h][w] = 0
        else:
            L[h][w] = L[h][w-1] + 1

for h in range(H-1, -1, -1):
    for w in range(W-1, -1, -1):
        if S[h][w] == 1:
            continue
        # down
        if h+1 >= H or S[h+1][w] == '#':
            D[h][w] = 0
        else:
            D[h][w] = D[h+1][w] + 1
        # right
        if w+1 >= W or S[h][w+1] == '#':
            R[h][w] = 0
        else:
            R[h][w] = R[h][w+1] + 1

ans = 0
for h in range(H):
    for w in range(W):
        if S[h][w] == '#':
            continue
        cnt = U[h][w] + L[h][w] + D[h][w] + R[h][w] + 1
        if cnt > ans:
            ans = cnt

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

def div(n):
    lower_div, upper_div = [], []
    i = 1
    while i * i <= n:
        if n % i == 0:
            lower_div.append(i)
            if i != n // i:
                upper_div.append(n // i)
        i += 1
    return lower_div + upper_div[::-1]

def main():
    from collections import Counter
    n = int(input())
    A = list(map(int, input().split()))
    s = set(A)
    c = Counter(A)
    cnt = 0
    for a in A:
        if c[a] >= 2:
            continue
        else:
            d = set(div(a))
            if len(d & s) == 1:
                cnt += 1
    print(cnt)
main()


### FIXED CODE ###

from collections import Counter
n = int(input())
A = sorted(map(int, input().split()))
M = A[-1]
c = Counter(A)
s = set()
ans = 0
for a in A:
    if a in s:
        continue
    if c[a] == 1:
        ans += 1
    i = 1
    while a * i <= M:
        s.add(a * i)
        i += 1
print(ans)
### BUGGY CODE ###

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

D={x:A.count(x) for x in set(A)}

for step in range(Q):
    b,c=map(int,input().split())
    if b not in D:
        print(somme)
        continue

    somme=somme+(c-b)*D[b]
    if c in D:
        D[c]=D[c]+D[b]
    else:
        D[c]=D[b]
    del D[b]    
    print(somme)

### FIXED CODE ###

N=int(input())
A=[int(x) for x in input().split()]
Q=int(input())
somme=sum(A)

from collections import Counter
D=Counter()

for l in A:
    D[l]+=1
    
for step in range(Q):
    b,c=map(int,input().split())

    if b not in D:
        print(somme)
        continue

    somme=somme+(c-b)*D[b]

    D[c]=D[c]+D[b]
    del D[b]    
    print(somme)
### BUGGY CODE ###

def ceil(a,b) :
    return (a + b - 1) // b

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

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

A.sort()

maxDigit = ceil(max(K,A[-1]), 2)

ans = 0

for i in range(maxDigit-1, -1, -1) :  # 上からi+1桁まではKと同じ
    if not K & (2**i) > 0  :  # i桁目が0の場合
        continue

    mask = 2**(maxDigit - 1)

    sumXor = 0
    # i桁目までの値
    for j in range(maxDigit-1, i, -1) :
        valK = (K & mask)
        for n in range(N) :
            val = (A[n] & mask)
            if not valK == val :
                sumXor += mask
        mask = mask // 2

    # i桁目 0にする
    for n in range(N) :
        if A[n] & mask > 0 :
            sumXor += mask

    mask = mask // 2

    # i-1桁以下
    for j in range(i-1, -1, -1) :
        count = 0
        for n in range(N) :
            val = (A[n] & mask) >> j
            count += val
        if count >= N // 2 :
            sumXor += count * mask
        else :
            sumXor += (N - count) * mask
        mask = mask // 2

    ans = max(ans, sumXor)

print(ans)



### FIXED CODE ###

N , K = map(int,input().split())
 
A = list(map(int,input().split()))
 
A.sort()
 
maxDigit = max(K,A[-1]).bit_length()
 
# 前計算
maxVal = [0] * maxDigit
for i in range(maxDigit) :
    count = 0
    mask = 2**i
    for a in A :
        count += (a & mask) // mask
    count = max(N - count, count)
    if i == 0 :
        maxVal[0] = count
    else :
        maxVal[i] = count * mask + maxVal[i-1]
 
valK = [0] * (maxDigit + 1)
for i in range(maxDigit-1, -1, -1) :
    mask = 2**i
    maskK = K & mask
    sumK = 0
    for a in A :
        val = a & mask
        if maskK != val :
            sumK += mask
    valK[i] = sumK + valK[i+1]
 
ans = valK[0]  # X = K
for i in range(maxDigit-1, -1, -1) :  # 上からi+1桁まではKと同じ
    if not K & (2**i) > 0  :  # i桁目が0の場合
        continue
 
    sumXor = valK[i+1]
 
    # i桁目 0にする
    mask = 2**i
    for n in range(N) :
        if A[n] & mask > 0 :
            sumXor += mask
 
    if i > 0 :
        sumXor += maxVal[i-1]
 
    ans = max(ans, sumXor)
 
print(ans)
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
mod = 10 ** 9 + 7
cnt = [0 for _ in range(60)]
for a in A:
    for i in range(60):
        cnt[i] += a & 1
        a >>= 1
cnt = [x * (N - x) % mod for x in cnt]
power = 1
ans = 0
for i in range(60):
    ans += power * cnt[i]
    power *= 2
    power %= mod
ans %= mod
print(ans)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
mod = 10 ** 9 + 7
cnt = [0 for _ in range(60)]
for a in A:
    for i in range(60):
        cnt[i] += a & 1
        a >>= 1
cnt = [x * (N - x) % mod for x in cnt]
power = 1
ans = 0
for i in range(60):
    ans += power * cnt[i]
    power *= 2
    power %= mod
ans %= mod
print(ans)