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

def num():
    from sys import stdin
    h, n = map(int, input().split())
    magic = [list(map(int, stdin.readline().split())) for _ in range(n)]
    INF = float('inf')
    ans = [INF]*(h+1)
    ans[-1] = 0

    for i in range(h, 0, -1):
        if ans[i] != INF:
            for j in magic:
                if i-j[0] < 0:
                    if ans[0] > ans[i]+j[1]:
                        ans[0] = ans[i]+j[1]
                elif ans[i-j[0]] > ans[i]+j[1]:
                    ans[i-j[0]] = ans[i]+j[1]
    return ans[0]
print(num())




### FIXED CODE ###

def num():
    from sys import stdin
    h, n = map(int, input().split())
    magic = [list(map(int, stdin.readline().split())) for _ in range(n)]
    INF = float('inf')
    ans = [INF]*(h+1)
    ans[-1] = 0

    for i in range(h, 0, -1):
        if ans[i] != INF:
            for j, k in magic:
                if i-j < 0:
                    num = ans[i]+k
                    if ans[0] > num:
                        ans[0] = num
                else:
                    num = ans[i]+k
                    if ans[i-j] > num:
                        ans[i-j] = num
    return ans[0]
print(num())
### BUGGY CODE ###


import sys
from collections import deque, defaultdict
import copy
import bisect
#input=sys.stdin.readline
#sys.setrecursionlimit(10 ** 9)
import math
import heapq

H, W = list(map(int,input().split()))
A = []
for i in range(H):
	A.append(input())

dist = [[10000000 for i in range(W)] for j in range(H)]

times = 0
now = []
for i in range(H):
	for j in range(W):
		if A[i][j] == "#":
			now.append([i,j])
			dist[i][j] = times


while True:
	times += 1
	now2 = []
	for loc in now:
		if loc[0] < H - 1 and dist[loc[0] + 1][loc[1]] > times:
			dist[loc[0] + 1][loc[1]] = times
			now2.append([loc[0] + 1, loc[1]])
		if loc[0] > 0 and dist[loc[0] - 1][loc[1]] > times:
			dist[loc[0] - 1][loc[1]] = times
			now2.append([loc[0] - 1, loc[1]])
		if loc[1] < W - 1 and dist[loc[0]][loc[1] + 1] > times:
			dist[loc[0]][loc[1] + 1] = times
			now2.append([loc[0], loc[1] + 1])
		if loc[1] > 0 and dist[loc[0]][loc[1] - 1] > times:
			dist[loc[0]][loc[1] - 1] = times
			now2.append([loc[0], loc[1] - 1])
	if len(now2) == 0:
		break
	now = copy.deepcopy(now2)

num = 0
for i in range(H):
	for j in range(W):
		num = max(num, dist[i][j])
print(num)




### FIXED CODE ###


import sys
from collections import deque, defaultdict
import copy
import bisect
#input=sys.stdin.readline
#sys.setrecursionlimit(10 ** 9)
import math
import heapq

H, W = list(map(int,input().split()))
A = []
for i in range(H):
	A.append(input())

dist = [[10000000 for i in range(W)] for j in range(H)]

now = deque()
for i in range(H):
	for j in range(W):
		if A[i][j] == "#":
			now.append([i,j])
			dist[i][j] = 0


while len(now) > 0:
	loc = now.popleft()
	if loc[0] < H - 1 and dist[loc[0] + 1][loc[1]] > dist[loc[0]][loc[1]] + 1:
		dist[loc[0] + 1][loc[1]] = dist[loc[0]][loc[1]] + 1
		now.append([loc[0] + 1, loc[1]])
	if loc[0] > 0 and dist[loc[0] - 1][loc[1]] > dist[loc[0]][loc[1]] + 1:
		dist[loc[0] - 1][loc[1]] = dist[loc[0]][loc[1]] + 1
		now.append([loc[0] - 1, loc[1]])
	if loc[1] < W - 1 and dist[loc[0]][loc[1] + 1] > dist[loc[0]][loc[1]] + 1:
		dist[loc[0]][loc[1] + 1] = dist[loc[0]][loc[1]] + 1
		now.append([loc[0], loc[1] + 1])
	if loc[1] > 0 and dist[loc[0]][loc[1] - 1] > dist[loc[0]][loc[1]] + 1:
		dist[loc[0]][loc[1] - 1] = dist[loc[0]][loc[1]] + 1
		now.append([loc[0], loc[1] - 1])

num = 0
for i in range(H):
	for j in range(W):
		num = max(num, dist[i][j])
print(num)
### BUGGY CODE ###

n, a, b = map(int, input().split())
ans = []

def add_ball(a, b):
    ball_list = []
    for i in range(a):
        ball_list.append('b')
    for j in range(b):
        ball_list.append('r')
    return ball_list


for i in range((n // (a + b)) + 1):
    ball_list = add_ball(a, b)
    ans += ball_list

print(ans[:n].count('b'))


### FIXED CODE ###

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

ans = n // (a + b) * a
rem = n % (a + b)
ans += min(a, rem)  # ansとremを比較することでnの位置よって処理を変えられる

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

n = int(input())
x = [0] * n
for i in range(n):
  x[i] = sorted(list(input())) 
count = 0
for j in range(n):
  for k in range(j+1,n):
    if x[j] == x[k]:
      count += 1
print(count)

### FIXED CODE ###

ans=0
d={}
for i in [input() for i in range(int(input()))]:
    a=''.join(sorted([c for c in i]))
    if a in d:
        ans+=d[a]
        d[a]+=1
    else:
        d[a]=1
print(ans)
### BUGGY CODE ###

import copy
n=int(input())
a=[int(input()) for i in range(n)]
for i in range(n):
  temp=copy.deepcopy(a)
  temp.pop(i)
  print(max(temp))

### FIXED CODE ###

import copy
n=int(input())
a=[int(input()) for i in range(n)]
maxa=max(a)
if len(set(a))!=1:
  maxa2=sorted(set(a))[-2]
maxs=a.count(maxa)
for i in range(n):
  if maxs==1:
    print(maxa if a[i]!=maxa else maxa2)
  else:
    print(maxa)
### BUGGY CODE ###

n = int(input())
l = [input() for _ in range(n)]
mst = set((list("".join(l))))
l = [[x.count(a) for a in mst] for x in l]
result = 0
for i in range(n-1):
    result += l[i+1:].count(l[i])
print(result)

### FIXED CODE ###

from math import factorial
from collections import Counter
 
def conb(n):
    if n <= 1:
        return 0
    else:
        return factorial(n) // factorial(n-2) // factorial(2) 

n = int(input())
S = [''.join(sorted(list(input()))) for i in range(n)]

print(int(sum([conb(i) for i in Counter(S).values()])))
### BUGGY CODE ###

from collections import defaultdict

N = int(input())
A = [int(x) for x in input().split()]
k = defaultdict(lambda: 0)

for i in range(1, N + 1):
    k[i] = 0
    for a in A:
        if a == i:
            k[i] += 1

for j in k.values():
    print(j)


### FIXED CODE ###

from collections import Counter

N = int(input())
A = [int(x) for x in input().split()]
a = Counter(A)

for i in range(1, N + 1):
    print(a[i])
### BUGGY CODE ###

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

sum = 0
mod = 1000000000+7
for i in range(n):
    if a[i] >= mod:
        a[i] = a[i] % mod
for i in range(n-1):
    #if a[i] >= mod:
        #a[i] = a[i] % mod
    for j in range(i+1, n):
        #if a[j] >= mod:
            #a[j] = a[j] % mod
        sum = sum + a[i] * a[j]
        #print(sum)
        if sum >= mod:
            #print('no')
            sum = sum % mod
            #print(sum)
            #print('o')
print(sum)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
 
sum = 0
sum1 = 0
mod = 1000000000+7
for i in range(n):
    if a[i] >= mod:
        a[i] = a[i] % mod
    sum1 += a[i]
    sum1 %= mod
    
for i in range(n-1):
    #for j in range(i+1, n):
    sum1 -= a[i]
    #sum += a[i] * a[j]
    if sum1 < 0:
        sum1 += mod
    sum += a[i] * sum1
    sum %= mod
            
print(sum)
### BUGGY CODE ###

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

for i in range(M):
    l, r = map(int, input().split())
    if i == 0:
        s = set(range(l, r+1))
    s = s & set(range(l, r+1))

print(len(s))


### FIXED CODE ###

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

left = 0
right = N
for i in range(M):
    L, R = map(int, input().split())
    left = max(left, L)
    right = min(right, R)

if left > right:
    print(0)
else:
    print(right - left + 1)
### BUGGY CODE ###

from collections import deque

def bfs(S):
    qu = deque([(0,0,1)])
    while(len(qu) != 0):
        a = qu.popleft()
        p,q,r = a
        S[p][q] = 'a'
        for d in [(-1,0), (0,-1), (1,0), (0,1)]:
            dp,dq = d
            s = p+dp
            t = q+dq
            if (s < 0 or t < 0 or s >= H or t >= W):
                continue

            if (s == (H-1) and t == (W-1)):
                return r+1
            if S[s][t] == '.':
                qu.append((s,t,r+1))
    return -1

H, W = list(map(int, input().split()))
S = []

cnt = 0
for i in range(H):
    a = input()
    tmp = []
    for i in a:
        if (i == '.'):
            cnt += 1
        tmp.append(i)
    S.append(tmp)

step = bfs(S)

if (step != -1):
    print(cnt - step)
else:
    print(step)

### FIXED CODE ###

from collections import deque

def bfs(H,W,S):
	V = [[False for i in range(W)] for j in range(H)]
	qu = deque([(0,0,1)])
	V[0][0] = True
	while(qu):
		p,q,r = qu.popleft()
		S[p][q] = '#'
		for d in [(-1,0), (0,-1), (1,0), (0,1)]:
			s = p+d[0]
			t = q+d[1]
			if s < 0 or t < 0 or s >= H or t >= W:
				continue
			if s == (H-1) and t == (W-1) and S[s][t] == '.':
				return r+1
			if S[s][t] == '.' and V[s][t] == False:
				V[s][t] = True
				qu.append((s,t,r+1))
	return -1

H, W = list(map(int, input().split()))
S = []
cnt = 0
for i in range(H):
	a = str(input())
	tmp = []
	for i in a:
		if (i == '.'):
			cnt += 1
		tmp.append(i)
	S.append(tmp)

step = bfs(H, W, S)

if (step != -1):
	print(cnt - step)
else:
	print(step)
### BUGGY CODE ###


from collections import deque
HW = input().split()
H, W = int(HW[0]), int(HW[1])
C = input().split()
Ch, Cw = int(C[0]), int(C[1])
D = input().split()
Dh, Dw = int(D[0]), int(D[1])
route = []
for h in range(H):
    route.append(input())

visited = [[False]*W for x in range(H)]
kouho = deque()
kouho.append([Ch-1, Cw-1])
warpkouho = deque()

def check_walk(a, b):
    if 0 <= a <= H-1 and 0 <= b <= W-1: 
        if visited[a][b] == False and route[a][b] == ".":
            kouho.append([a, b])
def check_warp(a, b, cwarp):
    if 0 <= a <= H-1 and 0 <= b <= W-1:
        if visited[a][b] == False and route[a][b] == ".":
            warpkouho.append([a, b, cwarp+1])

def wizard():
    warp = 1
    while True:
        if len(kouho) != 0:
            tmp = kouho.popleft()
        elif len(warpkouho) != 0:
            tmp = warpkouho.popleft()
            warp = tmp[2]
        else:
            break
        h = tmp[0]
        w = tmp[1]
        if visited[h][w] == False:
            visited[h][w] = warp
            check_walk(h-1, w)
            check_walk(h+1, w)
            check_walk(h, w-1)
            check_walk(h, w+1)
            for n in range(5):
                for m in range(5):
                    if not((n==2 and m==(1 or 2 or 3))or(n==1 and m == 2)or(n == 3 and m ==2)):
                    	check_warp(h-2+n, w-2+m, warp)
        if h == Dh-1 and w == Dw-1:
            print(visited[h][w]-1)
            return
    print(-1)
wizard()
        
        

### FIXED CODE ###

from collections import deque
HW = input().split()
H, W = int(HW[0]), int(HW[1])
C = input().split()
Ch, Cw = int(C[0]), int(C[1])
D = input().split()
Dh, Dw = int(D[0]), int(D[1])
route = []
for h in range(H):
    route.append(input())

visited = [[False]*W for x in range(H)]
kouho = deque()
kouho.append([Ch-1, Cw-1])
warpkouho = deque()

def check_walk(a, b):
    if 0 <= a <= H-1 and 0 <= b <= W-1: 
        if visited[a][b] == False and route[a][b] == ".":
            kouho.append([a, b])
def check_warp(a, b, cwarp):
    if 0 <= a <= H-1 and 0 <= b <= W-1:
        if visited[a][b] == False and route[a][b] == ".":
            warpkouho.append([a, b, cwarp+1])

def wizard():
    warp = 1
    while True:
        if len(kouho) != 0:
            tmp = kouho.popleft()
        elif len(warpkouho) != 0:
            tmp = warpkouho.popleft()
            warp = tmp[2]
        else:
            break
        h = tmp[0]
        w = tmp[1]
        if visited[h][w] == False:
            visited[h][w] = warp
            check_walk(h-1, w)
            check_walk(h+1, w)
            check_walk(h, w-1)
            check_walk(h, w+1)
            for n in range(5):
                for m in range(5):
                  check_warp(h-2+n, w-2+m, warp)
        if h == Dh-1 and w == Dw-1:
            print(visited[h][w]-1)
            return
    print(-1)
wizard()
### BUGGY CODE ###

s = input()
k = int(input())



# S = []
# for i in range(len(s)+1):
#     for j in range(i+1,len(s)+1):
#         if not(s[i:j] in S):
#             S.append(s[i:j])
#         # print(s[i:j])

t = s
S = []

while(1):
    for i in range(t.index(min(t))+1,len(s)+1):
        if not(s[t.index(min(t)):i] in S):
            S.append(s[t.index(min(t)):i])
    if t.count(min(t)) == 1 and len(S)>=k: break
    else: t = t.replace(min(t),"z",1)
    # print(t)
    # print(S)

S.sort()

print(S[k-1])








### FIXED CODE ###

s = input()
k = int(input())



# S = []
# for i in range(len(s)+1):
#     for j in range(i+1,len(s)+1):
#         if not(s[i:j] in S):
#             S.append(s[i:j])
#         # print(s[i:j])

S = set()

for i in range(1, k+1):
    for j in range(len(s)-i+1):
            S.add(s[j:j+i])

T = sorted([x for x in S])

print(T[k-1])
### BUGGY CODE ###


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

def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)
 
def lcm(x, y):
    return (x * y) // gcd(x, y)

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

success = False
ans = 0
fans = ans

_lcm = lcm(len(S), len(T))
for k in list(reversed(range(1, (len(S) * len(T))//_lcm + 1))):
    ans = k * _lcm
    s = [(i * ans)//len(S) + 1 for i in range(len(S))]
    t = [(i * ans)//len(T) + 1 for i in range(len(T))]
    pool = s + t
    double_st = []
    
    for i in range(len(S)):
        if (len(T)*i)%len(S) == 0 and (len(T) * i)//len(S) <len(T):
            double_st += [(i * ans)//len(S) + 1]
    isImpossible = False

    for st in double_st:
        s_i = my_index(s, st, -1)
        t_i = my_index(t, st, -1)
        if s_i == -1 or t_i == -1:
            continue
        if S[s_i] != T[t_i]:
            isImpossible = True
            break

            
    if isImpossible:
        break
    else:
        success = True
        fans = ans

if not success:
    print(-1)
else:
    print(ans)

### FIXED CODE ###


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

def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)
 
def lcm(x, y):
    return (x * y) // gcd(x, y)

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

success = False
fans = 0

_lcm = lcm(len(S), len(T))

def isImpble(k, _lcm):
    global success
    global S
    global T
    global fans
    
    ans = k * _lcm
    double_st = []
    
    for i in range(len(S)):
        if (len(T)*i)%len(S) == 0 and (len(T) * i)//len(S) <len(T):
            double_st += [(i * ans)//len(S) + 1]
    isImpossible = False

    for st in double_st:
        s_i = ((st-1) * len(S))//ans
        t_i = ((st-1) * len(T))//ans
        if S[s_i] != T[t_i]:
            isImpossible = True
            break

            
    if isImpossible:
        return True
    else:
        success = True
        fans = k*_lcm
        return False
        

imp = isImpble((len(S) * len(T))//_lcm, _lcm)

if not imp:
    for k in range(1, (len(S) * len(T))//_lcm ):
        imp = isImpble(k, _lcm)
        if success:
            break
    

if not success:
    print(-1)
else:
    print(fans)
### BUGGY CODE ###

# コンテスト時にトライしていたアルゴリズム
# その後の検証でアルゴリズムは正しそうなのでコードエラーを探す

n, x = map(int, input().split())
city_list = list(map(int, input().split()))
 
import numpy as np
 
def getNearestValue(list, num):
    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]

# TLE対策 dist_listからmax_Dを求める
# nearest_city = getNearestValue(city_list, x)
# Dとなり最大値はXと最も近い都市との距離に等しい
# max_D = abs(nearest_city-x)

# TLE対策 都市との距離は事前に計算
dist_list = []
for city in city_list:
    dist_list.append(abs(city - x))

# TLE対策 mac_D対策
max_D = sorted(dist_list)[0]

for xx in reversed(range(1, max_D+1)):
    flag = True
    for dist in dist_list:
        if (dist % xx) != 0:
            flag = False
            break
    if flag:
        break
print(xx)

### FIXED CODE ###

import fractions

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

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

dist_list = []
for city in city_list:
    dist_list.append(abs(city - x))

max_common_value = dist_list.pop(0)

for dist in dist_list:
    # 今までのDと次の都市の距離との最大公約数を見つける
    max_common_value = fractions.gcd(max_common_value, dist)

print(max_common_value)
### BUGGY CODE ###

from collections import defaultdict
MAX_N = 10 ** 3 + 1
MAX_M = 2 * (10 ** 3) + 1
INF = -(10 ** 100)

def bfs(graph, N, M):
    que = []
    que.append([0, 0])
    visited = defaultdict(list)
    result = INF
    while (len(que) > 0):
        now = que[0]
        que.pop(0)

        pos = now[0]
        cost = now[1]

        if (pos in visited):
            visited_cost = visited[pos][0]
            visited_cnt = visited[pos][1]
            if (visited_cost >= cost):
                continue
            if (visited_cnt >= MAX_N):
                continue
            visited[pos] = [cost, visited_cnt + 1]
        else:
            visited[pos] = [cost, 0]

        if (pos == N - 1):
            result = max(result, cost)
            if (visited[pos][1] >= MAX_N):
                return (0, False)

        for val in graph[pos]:
            nxt = val[0]
            nxt_cost = val[1]
            if (nxt not in visited):
                que.append([nxt, nxt_cost + cost])
            elif(nxt_cost + cost > visited[nxt][0]):
                que.append([nxt, nxt_cost + cost])
    return (result, True)


if __name__ == "__main__":
    N, M = map(int, input().split())
    graph = defaultdict(list)
    for x in range(M):
        a,b,c = map(int, input().split())
        a -= 1
        b -= 1
        graph[a].append([b, c])
    res,ok = bfs(graph, N, M)
    if (not ok):
        print ('inf')
    else:
        print (res)


### FIXED CODE ###


MAX_N = 10 ** 3 + 10
MAX_M = 2 * (10 ** 3) + 1
INF = 10 ** 13

def bfs(graph, N, M):
    que = []
    que.append([0, 0])
    visited = [-INF for x in range(MAX_N)]
    update_cnt = [0 for x in range(MAX_N)]
    result = -INF
    while (len(que) > 0):
        now = que[0]
        que.pop(0)

        pos = now[0]
        cost = now[1]
        if (visited[pos] > cost):
            continue
        for val in graph[pos]:
            nxt = val[0]
            nxt_cost = val[1]

            if (cost + nxt_cost > visited[nxt] and update_cnt[nxt] < MAX_M):
                visited[nxt] = cost + nxt_cost
                update_cnt[nxt] += 1
                que.append([nxt, nxt_cost + cost])

    if (update_cnt[N - 1] >= MAX_N):
        return (0, False)
    return (visited[N - 1], True)


if __name__ == "__main__":
    N, M = map(int, input().split())
    graph = [[] for x in range(MAX_N)]
    for x in range(M):
        a,b,c = map(int, input().split())
        a -= 1
        b -= 1
        graph[a].append([b, c])
    res,ok = bfs(graph, N, M)
    if (not ok):
        print ('inf')
    else:
        print (res)
### BUGGY CODE ###

N = int(input())
L = list()
for i in range(N):
	A = int(input())
	if A in L:
		L.remove(A)
	else:
		L.append(A)
print(len(L))

### FIXED CODE ###

N = int(input())
ans = {}
for i in range(N):
  ai = int(input())
  if ans.get(ai):
    ans.pop(ai)
  else:
    ans[ai] = 1
print(len(ans))
### BUGGY CODE ###

#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
def main():
    n=I()
    lis=LI()
    def prime_factorize(n):
        a = []
        while n % 2 == 0:
            a.append(2)
            n //= 2
        f = 3
        while f * f <= n:
            if n % f == 0:
                a.append(f)
                n //= f
            else:
                f += 2
        if n != 1:
            a.append(n)
        return a
    lists=[Counter(prime_factorize(lis[i])) for i in range(n)]
    C=Counter([])
    for i in range(n):
        x=lists[i]
        for j in x.keys():
            C[j]=max(C[j],x[j])
    #print(C)
    
    ans=0
    for i in range(n):
        x=lists[i]
        y=1
        for j in C.keys():
            y=(y*pow(j,C[j]-x[j],mod))%mod
        #print(y%mod)
        ans=(ans+y)%mod
    print(ans%mod)
if __name__=="__main__":
    main()
        
        
    
    
        
    
    


### FIXED CODE ###

#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a // gcd(a, b) * b
#print(lcm(lcm(1000000,999999),999998))
#print(999998//2*999999)


#print(1000000*999999*999998%mod)
n=I()
lis=LI()
promod=1
LCM=1
for i in range(n):
    LCM=lcm(lis[i],LCM)
#print(LCM)
for i in range(n):
    promod=(promod*(lis[i]%mod))%mod
smmod=0
for i in range(n):
    smmod=(smmod+promod*pow(lis[i],mod-2,mod))%mod
#print(smmod)
x=(promod*pow(LCM,mod-2,mod))%mod
ans=(smmod*pow(x,mod-2,mod))%mod
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
N = int(input())
A = [int(x) for x in input().strip().split()]
MOD = 10 ** 9 + 7
ans = 0

for i in range(60+1):
    zero = 0
    one = 0
    for a in A:
        if a >> i & 1 == 1:
            one += 1
        else:
            zero += 1
    ans += (one * zero) * 2 ** i
    ans = ans % MOD
print(ans % MOD)

### FIXED CODE ###

def main():
    import sys
    input = sys.stdin.readline
    _ = int(input())
    A = [int(x) for x in input().strip().split()]
    MOD = 10 ** 9 + 7
    ans = 0

    for i in range(60+1):
        zero = 0
        one = 0
        m = 1 << i
        for a in A:
            if a & m:
                one += 1
            else:
                zero += 1
        ans += (one * zero) * m
        ans = ans % MOD
    print(ans % MOD)

if __name__ == '__main__':
    main()