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

N, K = map(int, input().split())
int_list = []
val_list = []
for _ in range(N):
    A, B = map(int, input().split())
    int_list.append(A)
    val_list.append(B)

K_bin = bin(K)[2:]
max_len = len(K_bin)
for i in range(N):
    int_list[i] = bin(int_list[i])[2:].zfill(max_len)

or_list = [K_bin]
for i in range(max_len):
    if K_bin[i] == '1':
        or_list.append(K_bin[:i] + '0' + '1' * (max_len - i - 1))

ans = 0
for k in or_list:
    ans_k = 0
    for i in range(N):
        A = int_list[i]
        if len(A) > max_len:
            continue
        ok = 1
        for j, a in enumerate(A):
            if a == '1' and k[j] == '0':
                ok = 0
        if ok:
            ans_k += val_list[i]
    ans = max(ans, ans_k)

print(ans)


### FIXED CODE ###

import sys
input = sys.stdin.readline

N, K = map(int, input().split())
int_list = []
for _ in range(N):
    A, B = map(int, input().split())
    int_list.append([A, B])

K_bin = bin(K)[2:]
max_len = len(K_bin)
for i in range(N):
    int_list[i] = (bin(int_list[i][0])[2:].zfill(max_len), int_list[i][1])

or_list = [K_bin]
for i in range(max_len):
    if K_bin[i] == '1':
        or_list.append(K_bin[:i] + '0' + '1' * (max_len - i - 1))

ans = 0
for k in or_list:
    ans_k = 0
    for A, B in int_list:
        if len(A) > max_len:
            continue
        ok = 1
        for j, a in enumerate(A):
            if a == '1' and k[j] == '0':
                ok = 0
                break
        if ok:
            ans_k += B
    ans = max(ans, ans_k)

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

h,w = map(int,input().split())
ch,cw = map(int,input().split())
dh,dw = map(int,input().split())
road_map = []
for i in range(h):
    road = input()
    road_map.append(road)

queue = [[ch-1,cw-1,0]]
used_map = [[-1]*w for _ in range(h)]

while queue != []:
    dot = queue.pop()
    if dot[0] < 0 or dot[1] < 0 or dot[0] >= h or dot[1] >= w:
        continue
    if used_map[dot[0]][dot[1]] > -1 and used_map[dot[0]][dot[1]] <= dot[2]:
        continue
    if road_map[dot[0]][dot[1]] == "#":
        continue
    used_map[dot[0]][dot[1]] = dot[2]

    if not (dot[1] - 1 < 0):
        queue.append([dot[0],dot[1]-1,dot[2]])
    if not (dot[1] + 1 >= w):
        queue.append([dot[0],dot[1]+1,dot[2]])
    if not (dot[0]+1 >= h):
        queue.append([dot[0]+1,dot[1],dot[2]])
    if not (dot[0]-1 < 0):
        queue.append([dot[0]-1,dot[1],dot[2]])

    for x in range(-2,3,1):
        for y in range(-2,3,1):
            if not(dot[0]+ x < 0 or dot[1]+y < 0 or dot[0]+x >= h or dot[1]+y >= w):
                queue.append([dot[0]+x,dot[1]+y,dot[2]+1])
    
print(used_map[dh-1][dw-1])

### FIXED CODE ###

#shotoyooさんのコードをお借りしてテスト

import numpy as np
from numba import njit, b1, i4, i8, f8
from heapq import heappop as hpp, heappush as hp

@njit((b1[:, :],i8,i8,i8,i8), cache=True)
def main(ss,ch,cw,dh,dw):
    inf = 1<<30
    h,w = ss.shape
    start = ch*w+cw
    goal = dh*w+dw
    n = h*w
    seen = np.full(n, inf, np.int64)
    seen[start] = 0
    q = [(0, start)] # ワープ回数, 現在位置, 最後の道の位置
    while q:
        pnum,pu = hpp(q)
        ux,uy = divmod(pu,w)
        if pu==goal:
            break
        for xx in range(-2, 3):
            for yy in range(-2, 3):
                if xx==yy==0:
                    continue
                if abs(xx)+abs(yy)<=1:
                    vv = 0
                else:
                    vv = 1
                x,y = ux+xx, uy+yy
                u = x*w + y
                num = pnum+vv
                if x<0 or y<0 or x>=h or y>=w or ss[x][y]:
                    continue
        #         print(x,y)
                if seen[u]>num:
                    seen[u] = num
                    hp(q,(num, u))
                
    val = seen[goal]
    if val==inf:
        return -1
    else:
        return val
      

h,w = map(int, input().split())
ch,cw = map(int, input().split())
dh,dw = map(int, input().split())
ch -= 1
cw -= 1
dh -= 1
dw -= 1
ss = np.array([[c=="#" for c in input()] for _ in range(h)])

print(main(ss,ch,cw,dh,dw))
### BUGGY CODE ###

url = "https://atcoder.jp/contests/abc081/tasks/arc086_a"
import copy
def main():
    n, m = list(map(int, input().split()))
    li = list(map(int, input().split()))
    dic = {}

    for v in li:
        dic.setdefault(v, 0)
        dic[v] += 1

    if len(dic) <= m:
        print(0)
        exit()

    count = 0
    for i in range(len(dic) - m):
        key, val = min(dic.items(), key=lambda x: x[1])
        count += dic.pop(key)



    print(count)

if __name__ == '__main__':
    main()




### FIXED CODE ###

url = "https://atcoder.jp/contests/abc081/tasks/arc086_a"
import copy
def main():
    n, m = list(map(int, input().split()))
    li = list(map(int, input().split()))
    dic = {}

    for v in li:
        dic.setdefault(v, 0)
        dic[v] += 1

    if len(dic) <= m:
        print(0)
        exit()

    count = 0
    vals = sorted(list(dic.values()), reverse=True)
    for i in range(len(dic) - m):
        count += vals.pop(-1)



    print(count)

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

from collections import defaultdict
from bisect import bisect_left, insort_left
import sys
input = sys.stdin.readline
N = int(input())
S = list(input())

dic = defaultdict(list)
for i, s in enumerate(S):
    dic[s].append(i)

Q = int(input())
for _ in [0]*Q:
    t, *q = input().split()
    if t == '1':
        i, c = q
        i = int(i)-1

        s = S[i]
        S[i] = c
        dic[s].pop(bisect_left(dic[s], i))
        insort_left(dic[c], i)

    else:
        l, r = map(int, q)
        l -= 1
        r -= 1
        cnt = 0
        for L in dic.values():
            i = bisect_left(L, l)
            if i != len(L) and L[i] <= r:
                cnt += 1
        print(cnt)


### FIXED CODE ###

# AtCoder Beginner Contest 157
# E - Simple String Queries
# https://atcoder.jp/contests/abc157/tasks/abc157_e
from bisect import bisect_left, insort_left
import sys
input = sys.stdin.readline
OFS = ord('a')
_ = input()
S = list(input()[:-1])

D = [[] for _ in [0]*26]
for i, s in enumerate(S):
    D[ord(s)-OFS].append(i)

for _ in [0]*int(input()):
    Q = input()[:-1].split()
    if Q[0] == '1':
        i, c = int(Q[1])-1, Q[2]

        if S[i] != c:
            s = ord(S[i])-OFS
            D[s].pop(bisect_left(D[s], i))
            insort_left(D[ord(c)-OFS], i)
            S[i] = c

    else:
        l, r = int(Q[1])-1, int(Q[2])-1

        cnt = 0
        for L in D:
            i = bisect_left(L, l)
            if i < len(L) and L[i] <= r:
                cnt += 1

        print(cnt)
### BUGGY CODE ###

import sys
from collections import defaultdict as dd
from collections import deque as dq
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
N = int(input())
e = dd(list)
for _ in range(N - 1):
  u, v = map(int, input().split())
  e[u].append(v)
  e[v].append(u)

table = [[] for _ in range(N + 1)]
sta = []
for x in range(1, N + 1):
  Q = dq([])
  Q.append((x, 0))
  vis = set()
  while len(Q):
    y, n = Q.popleft()
    if n == 3:
      table[x].append(y)
      continue
    for q in e[y]:
      if q in vis: continue
      vis.add(q)
      Q.append((q, n + 1))
  sta.append((len(table[x]), x))
sta.sort()
nm = [0] * 3
for x in range(1, N + 1): nm[x % 3] += 1

res = [0] * (N + 1)

while nm[0]:
  _, x = sta.pop()
  res[x] = nm[0] * 3
  nm[0] -= 1

while nm[1]:
  _, x = sta[-1]
  ng = 0
  for y in table[x]:
    if res[y] % 3 == 1:
      ng = 1
      break
  if ng:
    continue
  sta.pop()
  res[x] = (nm[1] - 1) * 3 + 1
  nm[1] -= 1

while nm[2]:
  _, x = sta[-1]
  ng = 0
  for y in table[x]:
    if res[y] % 3 == 2:
      ng = 1
      break
  if ng: continue
  sta.pop()
  res[x] = (nm[2] - 1) * 3 + 2
  nm[2] -= 1

print(*res[1: ])

### FIXED CODE ###

import sys
from collections import defaultdict as dd
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
N = int(input())
e = dd(list)
for _ in range(N - 1):
  u, v = map(int, input().split())
  e[u].append(v)
  e[v].append(u)

cl = [0] * (N + 1)
vis = set()
def dfs(x):
  global cl
  global vis
  vis.add(x)
  for y in e[x]:
    if y in vis: continue
    cl[y] = (cl[x] + 1) % 2
    dfs(y)

dfs(1)
bl = cl.count(1)
wh = N - bl
res = [0] * (N + 1)
nm = [[] for _ in range(3)]
for i in range(1, N + 1): nm[i % 3].append(i)
#print(cl)
if bl <= N // 3:
  for i in range(1, N + 1):
    if cl[i]:
      res[i] = nm[0].pop()
    else:
      if len(nm[1]): res[i] = nm[1].pop()
      elif len(nm[2]): res[i] = nm[2].pop()
      else: res[i] = nm[0].pop()
  print(*res[1: ])
  exit(0)
if wh <= N // 3:
  for i in range(1, N + 1):
    if cl[i] == 0:
      res[i] = nm[0].pop()
    else:
      if len(nm[1]): res[i] = nm[1].pop()
      elif len(nm[2]): res[i] = nm[2].pop()
      else: res[i] = nm[0].pop()
  print(*res[1: ])
  exit(0)
#print(nm)
#print(cl, nm)
f = 0
for i in range(1, N + 1):
  if cl[i]:
    if len(nm[1]):
      res[i] = nm[1].pop()
    else:
      res[i] = nm[0].pop()
  else:
    if len(nm[2]):
      res[i] = nm[2].pop()
    else:
      res[i] = nm[0].pop()

print(*res[1: ])
### BUGGY CODE ###

x=input().split()
h=int(x[0])
n=int(x[1])
a=[]
b=[]
for k in range(n):
  x=input().split()
  a.append(int(x[0]))
  b.append(int(x[1]))  
m=max(a)  
dp=[10**8]*(h+m)
dp[0]=0
for k in range(h+m):
  for i in range(n):
    if k-a[i]<0:
      continue
    new=dp[k-a[i]]+b[i]
    if new < dp[k]:
      dp[k]=new
print(min(dp[h:h+m]))
      

### FIXED CODE ###

x=input().split()
h=int(x[0])
n=int(x[1])
import numpy as np
a=np.full(n,0,int)
b=np.full(n,0,int)
for k in range(n):
  x=input().split()
  a[k]=int(x[0])
  b[k]=int(x[1])
m=max(a)  
inf=10**8
dp=np.full(h+m,inf,int)
dp[0]=0
for k in range(1,h+m):
  dp[k]=(dp[k-a]+b).min()
print(dp[h:h+m].min())
### BUGGY CODE ###

n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]

for k in range(1, n+1):
    s = set([i+1 for i in range(m)])
    while s:
        memo = [0] * (m + 1)
        flag = [0] * (n + 1)
        for j in range(m):
            for i in range(n):
                if flag[i] == 0 and a[i][j] in s:
                    memo[a[i][j]] += 1
                    flag[i] = 1
                    if memo[a[i][j]] > k:
                        s.remove(a[i][j])
                        break
            else:
                continue
            break
        if max(memo) <= k:
            print(k)
            exit()



### FIXED CODE ###

n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]

s = set([])
ans = n
for _ in range(m):
    memo = [0] * (m + 1)
    flag = [0] * (n + 1)
    for j in range(m):
        for i in range(n):
            if flag[i] == 0 and a[i][j] not in s:
                memo[a[i][j]] += 1
                flag[i] = 1
    idx = 0
    mmax = 0
    for i, me in enumerate(memo):
        if me > mmax:
            idx = i
            mmax = me

    ans = min(ans, mmax)
    s.add(idx)

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

from collections import defaultdict
def solve(points):
    N = len(points)
    X = defaultdict(list)
    Y = defaultdict(list)

    for i,(x,y) in enumerate(points):
        X[x].append(i)
        Y[y].append(i)
    
    res = 0
    visited = [False]*N
    for p0 in range(N):
        if visited[p0]:
            continue
        stack = [p0]
        visited[p0] = True
        xx = set()
        yy = set()
        while stack:
            p = stack.pop()
            x,y = points[p]
            xx.add(x)
            yy.add(y)

            for q in X[x]:
                if not visited[q]:
                    visited[q] = True
                    stack.append(q)
            for q in Y[y]:
                if not visited[q]:
                    visited[q] = True
                    stack.append(q)
        res += len(xx)*len(yy)
    return res-N




if __name__ == '__main__':
    N = int(input())
    points = [tuple(map(int,input().split())) for _ in range(N)]
    print(solve(points))

### FIXED CODE ###

from bisect import bisect_left
N = int(input())
points = list(tuple(map(int,input().split())) for _ in range(N))

X = sorted(set(x for x,y in points))
Y = sorted(set(y for x,y in points))

points = set((bisect_left(X, x), bisect_left(Y, y)) for x,y in points)

xty = [list() for _ in range(len(X))]
ytx = [list() for _ in range(len(Y))]
for x,y in points:
    xty[x].append(y)
    ytx[y].append(x)

area = 0
visited = set()

for p in points:
    if p in visited:
        continue

    stack = [p]

    dx = set()
    dy = set()

    while stack:
        x,y = stack.pop()
        visited.add((x,y))
        if x not in dx:
            for yy in xty[x]:
                if yy != y:
                    stack.append((x,yy))
            dx.add(x)
        if y not in dy:
            for xx in ytx[y]:
                if xx != x:
                    stack.append((xx,y))
            dy.add(y)
    area += len(dx)*len(dy)

print(area-len(points))
### BUGGY CODE ###

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

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

aa = []
aa.append(0)
aa.append(c[0])

l = []
for i in range(1,a):
	aa.append(aa[i]+c[i])
d = 0
p = len(aa)
for i in range(p):
	for j in range(i+1,p):
		l.append(aa[j]-aa[i])
co = 0
la = 0
for i in range(40,-1,-1):
	for j in range(len(l)):
		if l[j] & (la + 2 ** i) == (la + 2 ** i):
			co += 1
	if co >= b:
		la += (2 ** i)
	co = 0

print(la)


### FIXED CODE ###

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

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

aa = []
aa.append(0)
aa.append(c[0])

l = []
for i in range(1,a):
	aa.append(aa[i]+c[i])
d = 0
p = len(aa)
for i in range(p):
	for j in range(i+1,p):
		l.append(aa[j]-aa[i])
co = 0
la = 0
for i in range(40,-1,-1):
	for j in range(len(l)):
		if l[j] & (la + 2 ** i) == (la + 2 ** i):
			co += 1
	if co >= b:
		la += (2 ** i)
	co = 0

print(la)
### BUGGY CODE ###

n,m=map(int,input().split())
a=[]
for i in range(m):
    A=int(input())
    a.append(A)
b=[0,1]
ans=1
for i in range(1,n+1):
    if i in a:
        b.append(0)
    else:
        b.append(b[i]+b[i-1])
    b[i]=b[i]%1000000007
print(b[len(b)-1]%1000000007)

### FIXED CODE ###

N,M = map(int,input().split())
a = [0]*M
for i in range(M):
    a[i] = int(input())

step = [0]*(N+1)
step[0] = 1

for i in range(M):
    step[a[i]] = -1

if 1 in a:
    step[1] = 0
else:
    step[1] = 1

for i in range(2,N+1):
    if step[i] == -1:
        step[i] = 0
    else:
        step[i] = (step[i-1] + step[i-2])%(10**9+7)

print(step[N])

#再起関数供養
def count_step(a,n):
    if n == 0:
        return 1
    if n == 1 and 1 not in a:
        return 1
    if n in a:
        return 0
    return (count_step(a,n-1)+count_step(a,n-2))%(10**9+7)
### BUGGY CODE ###

'''
☆長さnの数列Aの中央値がxであるとは
１．x以上の要素が (n + 1)// 2 個以上
２．そのようなxの中で最小
ということ。
'''

class BIT:
    def __init__(self, n):
        self.bit = [0] * (n+1)

    def sum(self, i):
        '''
        :param i: 
        :return: bit[i]までの和
        '''
        s = 0
        while i > 0:
            s += self.bit[i]
            i -= i & -i
        return s

    def add(self, i, x):
        '''
        :param i:
        :param x:
        :return: bit[i]にxを加える
        '''

        while i < len(self.bit):
            self.bit[i] += x
            i += i & -i

'''
def median(L):
    n = len(L)
    L.sort()
    return L[n // 2]
'''

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

def ans_bigger(X):
    '''
    答えがX以上かどうかを判定
    つまり、区間[l. r]のうち中央値がX以上であるものが ((N+1) * N /2 + 1 ) //2 個以上かを判定
    [l, r]の中央値がX以上 =
    '''
    a_X = [1 if a[i] >= X else -1 for i in range(N)]#1, -1に変換
    cum = [N]
    for i in range(N):
        cum.append(cum[i] + a_X[i]) #累積和を取るが、BITを使うため全部0以上に（初項N）
    b = BIT(2 * N + 1)
    ans = 0
    for j in range(N + 1):
        ans += b.sum(cum[j])
        b.add(cum[j], 1)
    if ans >= ((N+1) * N /2 + 1 ) //2:
        return True
    else:
        return False

l = min(a)
r = max(a) + 1
#区間[l, r)を2分探索
while r > l + 1:
    if ans_bigger((l + r) // 2):
        l = (l + r) // 2
    else:
        r = (l + r) // 2
print(l)

### FIXED CODE ###

'''
☆長さnの数列Aの中央値がxであるとは
１．x以上の要素が (n + 1)// 2 個以上
２．そのようなxの中で最小
ということ。
'''

class BIT:
    def __init__(self, n):
        self.bit = [0] * (n+1)

    def sum(self, i):
        '''
        :param i: 
        :return: bit[i]までの和
        '''
        s = 0
        while i > 0:
            s += self.bit[i]
            i -= i & -i
        return s

    def add(self, i, x):
        '''
        :param i:
        :param x:
        :return: bit[i]にxを加える
        '''

        while i < len(self.bit):
            self.bit[i] += x
            i += i & -i

'''
def median(L):
    n = len(L)
    L.sort()
    return L[n // 2]
'''

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

def ans_bigger(X):
    '''
    答えがX以上かどうかを判定
    つまり、区間[l. r]のうち中央値がX以上であるものが ((N+1) * N /2 + 1 ) //2 個以上かを判定
    [l, r]の中央値がX以上 =
    '''
    a_X = [1 if a[i] >= X else -1 for i in range(N)]#1, -1に変換
    cum = [N]
    for i in range(N):
        cum.append(cum[i] + a_X[i]) #累積和を取るが、BITを使うため全部0以上に（初項N）
    b = BIT(2 * N + 1)
    ans = 0
    for j in range(N + 1):
        ans += b.sum(cum[j])
        b.add(cum[j], 1)
    if ans >= ((N+1) * N /2 + 1 ) //2:
        return True
    else:
        return False

l = min(a)
r = max(a) + 1
#区間[l, r)を2分探索
while r > l + 1:
    if ans_bigger((l + r) // 2):
        l = (l + r) // 2
    else:
        r = (l + r) // 2
print(l)
### BUGGY CODE ###

n,k,q=map(int,input().split())
a=[int(input()) for _ in range(q)]
a=tuple(a)
for i in range(1,n+1):
  p=k-q+1*(a.count(i))
  if p>=1:
    print('Yes')
  else:
    print('No')

### FIXED CODE ###

n,k,q=map(int,input().split())
a=[]
for i in range(n):
  a.append(k-q)
for i in range(q):
  a[int(input())-1]+=1
for i in range(n):
  print('Yes' if a[i]>0 else 'No')
### BUGGY CODE ###

# -*- coding: utf-8 -*-
n = int(raw_input())
s = str(raw_input())

ans=[]
for i in range(0,n):
    ans.append(-1)
ans[0]=0

for i in range(1,n):
    if s[i] == ".":
        ans[i] = min(s[:i].count("#"), ans[i-1]+1)
    else:
        ans[i] = min(ans[i-1], s[:i].count("#")+1)

print ans[n-1]


### FIXED CODE ###

# -*- coding: utf-8 -*-
n = int(raw_input())
s = str(raw_input())

ans=[]
black=[]
for i in range(0,n):
    ans.append(-1)
    black.append(-1)
ans[0]=0
if s[0]==".":
    black[0]=0
else:
    black[0]=1

for i in range(1,n):
    if s[i] == ".":
        black[i] = black[i-1]
        ans[i] = min(black[i-1], ans[i-1]+1)
    else:
        black[i] = black[i-1] + 1
        ans[i] = min(ans[i-1], black[i-1]+1)

print ans[n-1]
### BUGGY CODE ###


def parse():
  H, W = map(int, input().split(" "))
  grid = []
  for y in range(H):
    grid.append(list(input()))
  return H, W, grid

def print_grid(grid):
  H = len(grid)
  print("grid:")
  for line in grid:
    for c in line:
      print(c, end="")
    print("")

def main():
  H, W, grid = parse()
  # print(H, W)
  # print_grid(grid)

  visited = []
  for y in range(H):
    visited.append([])
    for x in range(W):
      if grid[y][x] == ".":
        visited[y].append(H * W)
      else:
        visited[y].append(0)
    # print(visited[y])
  
  for y in range(H):  # ↓
    for x in range(1, W):  # →
      visited[y][x] = min(visited[y][x - 1] + 1, visited[y][x])
  for y in range(H):  # ↓
    for x in range(W - 2, -1, -1):  # ←
      visited[y][x] = min(visited[y][x], visited[y][x + 1] + 1)
  for x in range(W):  # →
    for y in range(1, H):  # ↓
      visited[y][x] = min(visited[y - 1][x] + 1, visited[y][x])
  for x in range(W):  # →
    for y in range(H - 2, -1, -1):  # ↑
      visited[y][x] = min(visited[y][x], visited[y + 1][x] + 1)
  
  max_len = 0
  for y in range(H):
    max_len = max_len if max_len > max(visited[y]) else max(visited[y])
  print(max_len)

if __name__ == "__main__":
  main()

### FIXED CODE ###


import numpy as np

def parse():
  H, W = map(int, input().split(" "))
  grid = [list(input()) for y in range(H)]
  return H, W, grid

def print_grid(grid):
  H = len(grid)
  print("grid:")
  for line in grid:
    for c in line:
      print(c, end="")
    print("")

def main():
  H, W, grid = parse()
  # print(H, W)
  # print_grid(grid)

  # visited = [[W * H if grid[y][x] == "." else 0 for x in range(W)] for y in range(H)]
  visited = np.zeros((H, W), int)
  for y in range(H):
    # visited.append([])
    for x in range(W):
      if grid[y][x] == ".":
        visited[y][x] = H * W

  for y in range(1, H):  # ↓
    # 要素ごとの処理
    # print(visited)
    visited[y][:] = np.minimum(visited[y][:], visited[y - 1][:] + 1)
    # print(visited)
    # input()
    # print(visited[y])
    # exit(0)

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

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

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

  # print(visited)
  # exit(0)

  # max_len = 0
  # for y in range(H):
  #   max_val = max(visited[y])
  #   max_len = max_len if max_len > max_val else max_val
  # print(max_len)
  print(np.max(visited))

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

nums = [int(e) for e in input().split()]
abcs = [nums[0],nums[0]+nums[1],nums[0]+nums[1]+nums[2]]
max = 0
for k in range(nums[3]):
    if k<abcs[0]:
        max+=1
    elif k<abcs[1]:
        continue
    elif k<abcs[2]:
        max-=1
print(max)


### FIXED CODE ###

nums = [int(e) for e in input().split()]

if nums[0]<nums[3]:
    max=nums[0]
    if nums[0]+nums[1]<nums[3]:
        max -= (nums[3]- (nums[0]+nums[1]))
else:
    max=nums[3]

print(max)
### BUGGY CODE ###

N = int(input())
A_l = [int(i) for i in input().split()]
a_sum = 0
for i in range(N):
    if A_l[i] == 0: continue
    for j in range(i+1,N):
        if A_l[j] == 0: continue
        a_sum = a_sum + (A_l[i] * A_l[j])
print(a_sum % (10**9+7))

### FIXED CODE ###

N = int(input())
A_l = [int(i) for i in input().split()]
a_sum = 0

A_l = [i for i in A_l if i != 0]

sum_l = [0] * len(A_l)
for i in range(len(A_l)):
    if i == 0:
        sum_l[i] = A_l[i]
    else:
        sum_l[i] = sum_l[i-1] + A_l[i]

for i in range(len(A_l)-1):
    a_sum = a_sum + sum_l[i] * A_l[i+1]
print(a_sum % (10**9+7))
### BUGGY CODE ###

import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int,input().split()))
mod = 10**9 + 7
ans = 0

ls_bin = []
for i in range(n):
    b = str(bin(a[i]))[2:]
    c = b.zfill(61)
    ls_bin.append(c)
# print(ls_bin)

ans = 0
for j in reversed(range(61)):
    one = 0
    zero = 0
    for i in range(n):
        s = int(ls_bin[i][j])
        if s==0:
            zero += 1
        else:
            one += 1
    ans_bit = zero * one
    ans += (ans_bit)*(2**(60-j)) % mod
print(ans%mod)

### FIXED CODE ###

import math
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def myinput():
    return map(int,readline().split())

n = int(readline())
a = list(myinput())
mod = 10**9 + 7
ans = 0

for j in range(60):
    k = 2**j
    one = 0
    zero = 0
    for i in range(n):
        if (a[i]&k):
            one += 1
        else:
            zero += 1
    ans_bit = zero * one
    ans += (ans_bit)*(2**j) 
    ans %= mod   

print(ans%mod)