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

n, a, b = list(map(int, input().split(' ')))
tmp = 0
count = 0
if a == 0:
    print(0)
elif n % (a+b) == 0:
    print(a*(n // (a+b)))
elif n % (a+b) == a:
    print(a*(n // (a+b)+1))
else:
    while count < 10**100:
        n -= a
        tmp += a
        if n <= 0:
            print(tmp + n)
            break
        n -= b
        if n <= 0:
            print(tmp)
            break
    

### FIXED CODE ###

n, a, b = list(map(int, input().split(' ')))
if a == 0:
    print(0)
elif n % (a+b) <= a:
    print(a*(n // (a+b))+ n % (a+b))
else:
    print( a*(n // (a+b))+a)
### BUGGY CODE ###

import sys
import numpy as np

def main():
    input = sys.stdin.readline
    H, W = map(int, input().split())
    A = [[0 if c == '.' else 1 for c in input().strip()] for _ in range(H)]

    A = np.array(A)
    N = np.array(np.nonzero(A))

    x = list(range(H)) * W
    x.sort()
    y = list(range(W)) * H
    P = np.array((x, y))

    dist = np.array([2001] * (H*W))

    _, n = N.shape
    for i in range(n):
        d = np.abs(P[0] - N[0][i]) + np.abs(P[1] - N[1][i])
        dist = np.minimum(d, dist)
    
    return np.max(dist)

if __name__ == '__main__':
    print(main())


### FIXED CODE ###

#ref: https://atcoder.jp/contests/agc033/submissions/5260580

import sys
import numpy as np

def main():
    input = sys.stdin.readline
    H, W = map(int, input().split())
    INF = H * W
    dp = [[INF if c == '.' else 0 for c in input().strip()] for _ in range(H)]
    dp = np.array(dp)

    for i in range(1, H):
        dp[i, :] = np.minimum(dp[i, :], dp[i-1, :] + 1)

    for i in range(H-2, -1, -1):
        dp[i, :] = np.minimum(dp[i, :], dp[i+1, :] + 1)

    for i in range(1, W):
        dp[:, i] = np.minimum(dp[:, i], dp[:, i-1] + 1)

    for i in range(W-2, -1, -1):
        dp[:, i] = np.minimum(dp[:, i], dp[:, i+1] + 1)

    return np.max(dp)

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

import numpy as np

N,K = map(int,input().split())
h = list(map(int,input().split()))
dp = np.zeros(N)
#print(h)
  
for i in range(N):
  if i < K:
    dp[i] = abs(h[0]-h[i])
  else:  
    cost = [dp[i-j]+abs(h[i]-h[i-j]) for j in range(1,K+1)]
    dp[i] = min(cost)
    #print(cost)
  #print(dp)
print(int(dp[N-1]))

### FIXED CODE ###

import numpy as np

N,K = map(int,input().split())
h = np.array(list(map(int,input().split())))
dp = np.zeros(N,dtype=int)
  
for i in range(N):
  if i <= K:
    dp[i] = abs(h[0]-h[i])
  else:
    cost = min(dp[i-K:i]+abs(h[i]-h[i-K:i]))
    dp[i] = cost
print(dp[N-1])
### BUGGY CODE ###

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

stu = [0] * n

for i in range(n):
    come = a.index(i + 1) + 1
    stu[i] = come
print(*stu)


### FIXED CODE ###

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

stu = [0] * n

for i in range(n):
    stu[a[i] - 1] = i + 1

print(*stu)
### BUGGY CODE ###

import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))
A_set = np.unique(A)
count_sum = np.sum([np.count_nonzero(A==i)*(np.count_nonzero(A==i)-1)/2 for i in A_set])
    
for i in A:
    print(int(count_sum-(np.count_nonzero(A==i)-1)))

### FIXED CODE ###


from collections import Counter
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))
A_set = np.unique(A)
count_dict= Counter(A)
count_sum = np.sum([count_dict[i]*(count_dict[i]-1)/2 for i in A_set])

out = [int(count_sum-count_dict[i]+1) for i in A]
for i in out:
    print(i)
### BUGGY CODE ###

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

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


### FIXED CODE ###

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

ans = 0
for x in range(0, k + 1):
    for y in range(0, k + 1):
        if 0 <= s - (x + y) <= k:
            ans += 1
print(ans)
### BUGGY CODE ###

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

for i in range(N):
    S[i]=input()


count=0

for l in range(N):
    JUDGE=1
    for j in range(N):
        for k in range(j+1,N):
            
            kk=(k-l)%N
            jj=(j-l)%N
            if S[j][kk]!=S[k][jj]:
                JUDGE=0
                #print([l,j,k,jj,kk])


    if JUDGE==1:
        count+=1

    

print(count*N)

### FIXED CODE ###

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

for i in range(N):
    S[i]=input()

count=0

for l in range(N):
    JUDGE=1
    for j in range(N):
        for k in range(j+1,N):
            
            if S[j][k-l]!=S[k][j-l]:
                JUDGE=0
                break
        if JUDGE==0:
            break

    if JUDGE==1:
        count+=1

print(count*N)
### BUGGY CODE ###

N=int(input())
mod=998244353
Combi=1
SC=0
for i in range(N,N//2,-1):
    SC=(SC+Combi*pow(2,N-i,mod))%mod
    Combi=Combi*(i)*pow(N-i+1,mod-2,mod)%mod
print((pow(3,N,mod)-SC*2)%mod)

### FIXED CODE ###

N=int(input())
mod=998244353

FACT=[1]
for i in range(1,N+1):
    FACT.append(FACT[-1]*i%mod)

FACT_INV=[pow(FACT[-1],mod-2,mod)]
for i in range(N,0,-1):
    FACT_INV.append(FACT_INV[-1]*i%mod)

FACT_INV.reverse()

POW=[1]
for i in range(N):
    POW.append(POW[-1]*2%mod)

def Combi(a,b):
    return FACT[a]*FACT_INV[b]*FACT_INV[a-b]%mod

SC=0
for i in range(N//2+1,N+1):
    SC+=Combi(N,i)*POW[N-i]

print((pow(3,N,mod)-SC*2)%mod)
### BUGGY CODE ###

K = int(input())

if K % 2 == 0:
    print(-1)
    exit()
rest = 7 % K
x = rest
ans = 1
while rest:
    ans += 1
    x = x*10 % K
    rest = (rest + x) % K
print(ans)

### FIXED CODE ###

K = int(input())

if K % 2 == 0 or K % 5 == 0:
    print(-1)
    exit()
rest = 7 % K
x = rest
ans = 1
while rest:
    ans += 1
    x = x*10 % K
    rest = (rest + x) % K
print(ans)
### BUGGY CODE ###

n = int(raw_input())
s = raw_input()
aa = s.split(" ")
aaa = []
for i in range(n):
	aaa.append((i+1,int(aa[i])))

ctr = 0

for (a,b) in aaa:
	if (b,a) in aaa:
		# aaa.remove((a,b))
		# aaa.remove((b,a))
		ctr = ctr + 1
ctr = ctr / 2
print(str(ctr))

### FIXED CODE ###

n = int(raw_input())
s = raw_input()
aa = s.split(" ")
aa = [int(x)-1 for x in aa]

ctr = 0

for i in range(n):
	if i == aa[aa[i]]:
		ctr = ctr + 1

ctr = ctr / 2

print(str(ctr))
### BUGGY CODE ###

N = int(input())
S = input().split()
num = [int(x) for x in S]
flag = True

for i in range(0, N):
    for j in range(i, N):
        if num[i] - num[j] >= 2:
            flag = False
            break
    else:
        continue
    break


print("Yes" if flag else "No")

### FIXED CODE ###

N = int(input())
num = [int(x) for x in input().split()]

if N == 1:
    print("Yes")
elif N == 2:
    if num[0] - num[1] < 2:
        print("Yes")
    else:
        print("No")
else:
    flag = True
    for i in range(N - 2, 0, -1):
        diff = num[i] - num[i + 1]
        if diff <= 0:
            pass
        elif diff == 1:
            num[i] -= 1
        else:
            flag = False
            break
    print("Yes" if flag else "No")
### BUGGY CODE ###

N = int(input())
A = [input() for i in range(N)]
M = 10465270
T = [0 for i in range(M)]

# 各文字をバイト列にした後、それらを10進数にして、文字列として結合する
def get_key(value: str) -> int:
    converted_value = ""
    for s in value:
        b = s.encode()
        converted_value += str(b[0])
    return int(converted_value)

def h1(key: int) -> int:
    return key % M

def h2(key: int) -> int:
    move_value = 1 + (key % (M-1))
    return move_value

def h(key:int, i:int) -> int:
    hash_value = (h1(key) + i+h2(key)) % M
    return hash_value

def find(key: int) -> bool:
    i = 0
    while True:
        j = h(key, i)
        if T[j] == key:
            return True
        elif T[j] == 0 or i >= M:
            return False
        else:
            i += 1


def insert(key: int) -> None:
    i = 0
    while True:
        j = h(key, i)
        if T[j] == 0:
            T[j] = key
            return
        else:
            i += 1


for row in A:
    order, value = row.split()
    key = get_key(value)
    if order[0] == "i":
        insert(key)
    else:
        if find(key):
            print("yes")
        else:
            print("no")


### FIXED CODE ###

N = int(input())
A = [input() for i in range(N)]

D = {}
for row in A:
    order, key = row.split()
    if order[0] == "i":
        D[key] = 1
    else:
        if key in D.keys():
            print("yes")
        else:
            print("no")
### BUGGY CODE ###

def main():
    n, K = map(int, input().split())
    H = list(map(int, input().split()))
    s = sorted(set(H+[0]))
    d = {i: j for j, i in enumerate(s)}
    l = len(s)
    m = max(s)
    a = [m-i for i in s]
    dp = [[10**13]*l for _ in range(K+1)]
    dp[0][0] = 0
    for h in H:
        dh = d[h]
        dp2 = [[10**13]*l for _ in range(K+1)]
        t = [[i+j for i, j in zip(a, kk)] for kk in dp]
        min_s = [[dp[i][j] for j in range(l)] for i in range(K+1)]
        for i in range(K+1):
            for j in range(l-2, -1, -1):
                min_s[i][j] = min(min_s[i][j+1], min_s[i][j])
            for j in range(1, l):
                t[i][j] = min(t[i][j-1], t[i][j])
            for j in range(l):
                t[i][j] = t[i][j]-a[j]
        for i in range(K):
            for j in range(l):
                dp2[i+1][j] = min(min_s[i][j], t[i][j])
        for i in range(K+1):
            dp2[i][dh] = min(dp2[i][dh], min(
                [dp[i][j]+max(h-s[j], 0) for j in range(l)]))
        dp = dp2
    print(min([min(i) for i in dp]))


main()


### FIXED CODE ###

def main():
    n, K = map(int, input().split())
    H = list(map(int, input().split()))
    s = sorted(set(H+[0]))
    d = {i: j for j, i in enumerate(s)}
    l = len(s)
    m = max(s)
    a = [m-i for i in s]
    dp = [[10**13]*l for _ in range(K+1)]
    dp[0][0] = 0
    for h in H:
        dh = d[h]
        dp2 = [[0]*l for _ in range(K+1)]
        dp2[0] = [10**13]*l
        t = [[0]*l for _ in range(K)]
        for i in range(K):
            for j in range(l):
                t[i][j] = dp[i][j]+a[j]
        min_s = [[10**13]*l for i in range(K+1)]

        for i in range(K):
            for j in range(l-2, -1, -1):
                min_s[i][j] = min(dp[i][j+1], min_s[i][j])
            for j in range(1, l):
                t[i][j] = min(t[i][j-1], t[i][j])
            for j in range(l):
                t[i][j] = t[i][j]-a[j]

        for i in range(K):
            for j in range(l):
                dp2[i+1][j] = min(min_s[i][j], t[i][j])

        for i in range(K+1):
            temp = 10**13
            for j in range(l):
                temp = min(temp, dp[i][j]+max(h-s[j], 0))
            dp2[i][dh] = min(dp2[i][dh], temp)
        dp = dp2
    print(min([min(i) for i in dp]))


main()
### BUGGY CODE ###

from collections import defaultdict

N, M = [int(x) for x in input().split()]
a = []

for _ in range(M):
    a.append(int(input()))

MOD = 1000000007

dict = defaultdict(int)
ans = 1
for i in range(M):
    dict[a[i]] = -10 ** 1000000000
    if i >= 1 and a[i] - a[i - 1] == 1:
        print("0")
        exit()

dict[0] = 1
for i in range(N):
    if dict[i] > 0:
        dict[i + 1] += dict[i]
        dict[i + 2] += dict[i]


print(dict[N] % MOD)




### FIXED CODE ###

from collections import defaultdict

N, M = [int(x) for x in input().split()]
a = []

for _ in range(M):
    a.append(int(input()))

MOD = 1000000007

dict = defaultdict(int)

for i in range(M):
    if i >= 1 and a[i] - a[i - 1] == 1:
        print("0")
        exit()

dict[0] = 1
a_s = set(a)
for i in range(N):
    if not i in a_s:
        dict[i + 1] += dict[i]
        dict[i + 2] += dict[i]


print(dict[N] % MOD)
### BUGGY CODE ###

H,W = map(int,input().split())
S = [input().strip() for _ in range(H)]
A = [[[0,0] for _ in range(W)] for _ in range(H)]
for i in range(H):
    cur = 0
    cnt = 0
    for j in range(W):
        if S[i][j]=="#":
            for k in range(cur,j):
                A[i][k][0] = cnt
            cur = j+1
            cnt = 0
        else:
            cnt += 1
    for k in range(cur,W):
        A[i][k][0] = cnt
for j in range(W):
    cur = 0
    cnt = 0
    for i in range(H):
        if S[i][j]=="#":
            for k in range(cur,i):
                A[k][j][1] = cnt
            cur = i+1
            cnt = 0
        else:
            cnt += 1
    for k in range(cur,H):
        A[k][j][1] = cnt
cmax = 0
for i in range(H):
    for j in range(W):
        cmax = max(cmax,sum(A[i][j]))
print(cmax-1)

### FIXED CODE ###

H,W = map(int,input().split())
S = [input().strip() for _ in range(H)]
L = [[0 for _ in range(W)] for _ in range(H)]
R = [[0 for _ in range(W)] for _ in range(H)]
U = [[0 for _ in range(W)] for _ in range(H)]
D = [[0 for _ in range(W)] for _ in range(H)]
for i in range(H):
    for j in range(W):
        if j==0 and S[i][j]==".":
            L[i][j] = 1
        elif j>0 and S[i][j]==".":
            L[i][j] = L[i][j-1]+1
        if i==0 and S[i][j]==".":
            U[i][j] = 1
        elif i>0 and S[i][j]==".":
            U[i][j] = U[i-1][j]+1
for i in range(H-1,-1,-1):
    for j in range(W-1,-1,-1):
        if j==W-1 and S[i][j]==".":
            R[i][j] = 1
        elif j<W-1 and S[i][j]==".":
            R[i][j] = R[i][j+1]+1
        if i==H-1 and S[i][j]==".":
            D[i][j] = 1
        elif i>0 and S[i][j]==".":
            D[i][j] = D[i+1][j]+1
cmax = 0
for i in range(H):
    for j in range(W):
        cmax = max(cmax,L[i][j]+R[i][j]+U[i][j]+D[i][j]-3)
print(cmax)
### BUGGY CODE ###

def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

N = INT()
S = input()

ans = 0

for i in range(0, N-2):
    for k in range(i+2, N):
        if S[i]==S[k]:
            continue
        for j in range(i+1, k):
            # print(S[i], S[j], S[k])
            if j-i!=k-j and S[i]!=S[j] and S[j]!=S[k]:
                ans += 1

print(ans)

### FIXED CODE ###

def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

N = INT()
S = input()

ans = 0

count_S = {
    "R": [0] * N,
    "G": [0] * N,
    "B": [0] * N,
}

count_S[S[-1]][-1] = 1
for i in reversed(range(N-1)):
    count_S["R"][i] = count_S["R"][i+1]
    count_S["B"][i] = count_S["B"][i+1]
    count_S["G"][i] = count_S["G"][i+1]
    count_S[S[i]][i] += 1


# for i in range(0, N-2):
#     for k in range(i+2, N):
#         if S[i]==S[k]:
#             continue
#         for j in range(i+1, k):
#             # print(S[i], S[j], S[k])
#             if j-i!=k-j and S[i]!=S[j] and S[j]!=S[k]:
#                 ans += 1


for i in range(0, N-3):
    for j in range(i+1, N-1):
        if S[i] == S[j]:
            continue
        for c in "RGB":
            if S[i] != c and S[j] != c:
                last_color = c
        ans += count_S[last_color][j+1]
        if j+j-i <= N-1 and S[j+j-i] == last_color:
            ans -= 1

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

n = int(input())
items = [tuple(map(int, input().split())) for _ in range(n)]

q = int(input())
v_to_qi = [[] for _ in range(n)]
v_to_l = [[] for _ in range(n)]
qv_list = []
for i in range(q):
    v, l = map(int, input().split())
    v -= 1
    qv_list.append(v)
    v_to_qi[v].append(i)
    v_to_l[v].append(l)

MAX = 10**5
# dp[i+1][j] = (i番目まで見て重さの合計がj以下のの時の価値の最大値)
dp = [[0] * (MAX + 1) for _ in range(20)]
ans = [0] * q

flag = [False] * n
for v in qv_list:
    flag[v] = True
    while v > 0:
        v = (v - 1) // 2
        flag[v] = True


def dfs(v, depth):
    for j in range(MAX + 1):
        if j < items[v][1]:
            dp[depth + 1][j] = dp[depth][j]
        else:
            dp[depth + 1][j] = max(dp[depth][j],
                                   dp[depth][j - items[v][1]] + items[v][0])

    if len(v_to_qi[v]) > 0:
        for qi, l in zip(v_to_qi[v], v_to_l[v]):
            ans[qi] = dp[depth + 1][l]

    if v * 2 + 1 < n and flag[v * 2 + 1]:
        dfs(v * 2 + 1, depth + 1)
    if v * 2 + 2 < n and flag[v * 2 + 2]:
        dfs(v * 2 + 2, depth + 1)


dfs(0, 0)
print(*ans, sep='\n')


### FIXED CODE ###

def main():
    import sys
    input = sys.stdin.readline

    n = int(input())

    L_MAX = 10**5
    D_TH = 10
    V_MAX = (1 << D_TH) - 1
    dp = [[0] * (L_MAX + 1)]
    # items = []
    items_v = []
    items_w = []

    for i in range(n):
        val, w = map(int, input().split())
        if i < V_MAX:
            i1 = i + 1
            i0 = (i + 1) >> 1
            dp_ = dp[i0][:]

            # for j in range(w):
            #     dp[i1][j] = dp[i0][j]
            for j in range(w, L_MAX + 1)[::-1]:
                if dp_[j] < dp_[j - w] + val:
                    dp_[j] = dp_[j - w] + val
            dp.append(dp_)
        else:
            # items.append((val, w))
            items_v.append(val)
            items_w.append(w)

    # items = tuple(items)

    q = int(input())
    for _ in range(q):
        v, l = map(int, input().split())
        v -= 1

        if v < V_MAX:
            ans = dp[v + 1][l]
        else:
            vv = []
            ww = []
            while v >= V_MAX:
                # vv.append(items[v - V_MAX][0])
                # ww.append(items[v - V_MAX][1])
                vv.append(items_v[v - V_MAX])
                ww.append(items_w[v - V_MAX])
                v = (v - 1) >> 1

            ans = dp[v + 1][l]
            # m = len(vv)
            m2 = 1 << len(vv)
            v_sub = [0] * m2
            w_sub = [0] * m2
            for bit in range(1, m2):
                bit_min = bit & (-bit)
                x = bit_min.bit_length() - 1

                s_w = w_sub[bit - bit_min] + ww[x]
                w_sub[bit] = s_w
                if s_w <= l:
                    s_val = v_sub[bit - bit_min] + vv[x]
                    v_sub[bit] = s_val
                    ans = max(ans, dp[v + 1][l - s_w] + s_val)

        print(ans)


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

import numpy as np
from numba import njit


@njit("i1(i1,i1[:])")
def solve(N, D):
    ans = 0
    for i in range(1 << N):
        clocks = np.zeros((N + 2), dtype=np.int8)
        clocks[-1] = 24
        for j in range(N):
            if i >> j & 1:
                clocks[j + 1] = D[j]
            else:
                clocks[j + 1] = 24 - D[j]
        clocks.sort()
        ans = max(ans, np.min(np.diff(clocks)))
    return ans


N = int(input())
D = np.array(input().split(), dtype=np.int8)
if N >= 24:
    print(0)
else:
    print(solve(N, D))


### FIXED CODE ###

from collections import Counter
from itertools import product


N = int(input())
D = list(map(int, input().split()))
D_cnt = Counter(D)
if N >= 24 or D_cnt[0] > 0 or D_cnt[12] > 1 or any(D_cnt[i] > 2 for i in range(1, 12)):
    print(0)
    exit()
clock = [0, 24]
undet = []
if 12 in D_cnt:
    clock.append(12)
for i in range(1, 12):
    if D_cnt[i] == 2:
        clock.append(i)
        clock.append(24 - i)
    elif D_cnt[i] == 1:
        undet.append(i)

ans = 0
for rp in product([0, 1], repeat=len(undet)):
    candidate = clock[:]
    for j, is_flipped in enumerate(rp):
        candidate.append(undet[j]) if is_flipped else candidate.append(24 - undet[j])
    candidate.sort()
    ans = max(ans, min(ca - cb for cb, ca in zip(candidate, candidate[1:])))
print(ans)
### BUGGY CODE ###

n,m = map(int, input().split())
l, r = [], []
c = 0

a = []
for _ in range(n):
    a.append(0)

for _ in range(m):
    l,r = map(int, input().split())
    for i in range(l-1, r):
        a[i] += 1
        
for i in range(n):
    if a[i] == m:
        c += 1

print(c)


### FIXED CODE ###

n,m = map(int, input().split())
l, r = [], []
x = 0
c = 0

a = []
for _ in range(n):
    a.append(0)

for _ in range(m):
    l,r = map(int, input().split())
    a[l-1] += 1
    if r != n:
        a[r] -= 1

for i in range(n):
    x += a[i]
    if(x == m):
        c += 1

print(c)
### BUGGY CODE ###

from array import array
from collections import Counter

h, w, n = map(int, input().split())
b = array('L', [0] * h)

for y, x in (map(int, input().split()) for _ in range(n)):
    b[y - 1] += 1 << (x - 1)

a = [[bin(b[y] & (7 << x)).count('1') for x in range(w - 2)] for y in range(h)]
c = Counter(sum(a[y + i][x] for i in range(3)) for y in range(h - 2) for x in range(w - 2))
for i in range(10):
    print(c[i] if i in c else 0)


### FIXED CODE ###

from collections import Counter, defaultdict

h, w, n = map(int, input().split())
hs, ws = h - 2, w - 2
dd = defaultdict(int)

for a, b in (map(int, input().split()) for _ in range(n)):
    for y in range(max(0, a - 3), min(a, hs)):
        for x in range(max(0, b - 3), min(b, ws)):
            dd[(y, x)] += 1

print(hs * ws - len(dd))

c = Counter(dd.values())
for i in range(1, 10):
    print(c[i] if i in c else 0)
### BUGGY CODE ###

n,k = map(int,input().split())
p = list(map(int,input().split()))
ave = []
ans = 0

for i in range(n):
  ave.append((p[i]+1)/2)

for i in range(n-k+1):
  ans = max(ans,sum(ave[i:i+k]))

print(ans)

### FIXED CODE ###

n,k = map(int,input().split())
p = list(map(int,input().split()))
ave = []
ans = 0
tmp = 0

for i in range(n):
  ave.append((p[i]+1)/2)

for j in range(n):
  tmp += ave[j]
  if j >= k:
    tmp -= ave[j-k]
    
  ans = max(ans,tmp)


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

def main():
    n=int(input())
    a=list(map(int,input().split()))
    ans=0
    temp=0
    MOD=10**9+7
    bin_a=[[0] * n for i in range(60)]
    cnt1=[0]*60
    for i in range(n):
        tmp=str(bin(a[i]))
        # print(a[i])
        # print(len(tmp))
        for j in range(len(tmp)-2):
            if tmp[len(tmp)-j-1] == 'b':
                break
            # print(tmp[len(tmp)-i-1])
            bin_a[j][i]=int(tmp[len(tmp)-j-1])
            cnt1[j]+=int(tmp[len(tmp)-j-1])

    for i in range(60):
        # cnt1=sum(bin_a[i])
        # cnt0=n-cnt1
        ans+=cnt1[i]*(n-cnt1[i])*2**i%MOD
    print(ans%MOD)

if __name__=='__main__':
    main()


### FIXED CODE ###

def main():
    n=int(input())
    a=list(map(int,input().split()))
    ans=0
    temp=0
    MOD=10**9+7
    cnt1=[0]*60
    for num in a:
        for i in range(60):
            cnt1[i] += (num >> i) & 1
    for i in range(60):
        ans += cnt1[i] * (n - cnt1[i]) * pow(2,i,MOD)
    print(ans % MOD)


if __name__=='__main__':
    main()