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

n, W = map(int, input().split())
w = [0]*n
v = [0]*n

dp = [[None for i in range(W+1)] for j in range(n+1)]

for i in range(n):
    v1, v2 = map(int, input().split())
#    v2, v1 = map(int, input().split())
    # w.append(v1)
    # v.append(v2)
    w[i] = v1
    v[i] = v2

# i: Index (Tracing all items)
# j: Remaining weight
# Return the sum of value
def knap(i, j):
    # print("\n# i: " + str(i))
    # print("# j: " + str(j))
    if dp[i][j] is not None:
        return dp[i][j]

    res = 0

    if i == n:
#        dp[i][j] = 0
        res = 0
    elif j < w[i]:
        res = knap(i+1, j)
    else:
        # if dp[i][j] is None:
        #     dp[i][j] = dp[i-1][j] + v[i]
        res = max(knap(i+1, j), knap(i+1, j-w[i]) + v[i])

    dp[i][j] = res
    return dp[i][j]
#    return res

print(knap(0, W))


### FIXED CODE ###

n, W = map(int, input().split())
w = [0]*(n+1)
v = [0]*(n+1)

#dp = [[None for i in range(W+1)] for j in range(n+1)]
dp = [[0 for i in range(W+1)] for j in range(n+1)]

for i in range(n):
    w[i], v[i] = map(int, input().split())

def knap(i, j):
    if dp[i][j] is not None:
        return dp[i][j]

    res = 0

    if i == n:
       	res = 0
    elif j < w[i]:
        res = knap(i+1, j)
    else:
        res = max(knap(i+1, j), knap(i+1, j-w[i]) + v[i])

    dp[i][j] = res
    return dp[i][j]

for i in reversed(range(n)):
    for j in range(W+1):
#        res = 0
        # if i == n-1:
        #     res = 0
        if j < w[i]:
            dp[i][j] = dp[i+1][j]
        else:
            dp[i][j] = max(dp[i+1][j], dp[i+1][j-w[i]] + v[i])

#print(knap(0, W))
print(dp[0][W])
### BUGGY CODE ###

N = int(input())

ans = []

for _ in range(N):
    tmp = input()

    # if len(ans) == 0:
    #     ans.append([tmp, 1])
    #     continue

    for a in ans:
        if a[0] == tmp:
            a[1] = a[1] + 1
            continue
    
    ans.append([tmp, 1])

n = 0
for a in ans:
    if a[1] > n:
        n = a[1]

last = []
for a in ans:
    if a[1] == n:
        last.append(a[0])
last.sort()
for l in last:
    print(l)

### FIXED CODE ###

N = int(input())

ans = {}
m = 1
for _ in range(N):
    w = input()
    c = ans.get(w)
    # print(c)
    # print(type(c))
    if c == None:
        ans[w] = 1
    else:
        ans[w] = c + 1
        if c + 1 > m:
            m = c + 1
# print(ans)

tmp = []
for a in ans:
    if ans[a] == m:
        tmp.append(a)

tmp.sort()
for t in tmp:
    print(t)
### BUGGY CODE ###


n, m = list(map(int, input().split()))
ab = []
for _ in range(n):
    ai, bi = list(map(int, input().split()))
    ab.append([ai,bi])
    
ab.sort(key=lambda x: x[0])
ab.sort(key=lambda x: x[1], reverse=True)

day = [0]*(m+1)
cnt = 0
for abi in ab:
    if abi[0] <= m:
        if day[m-abi[0]] == 0:
            day[m-abi[0]] = 1
            cnt += abi[1]
        else:
            i = 1
            while m-abi[0]-i>=0:
                if day[m-abi[0]-i] == 0:
                    day[m-abi[0]-i] = 1
                    cnt += abi[1]
                    break
                i += 1
print(cnt)


### FIXED CODE ###

import heapq

n, m = list(map(int, input().split()))
tasks = []
for i in range(n):
    ai, bi = list(map(int, input().split()))
    tasks.append((-bi, i, ai))
tasks.sort(key=lambda x: x[2])    
prtasks = []
money = 0
j = 0
for i in range(1,m+1):
    for k in range(j,len(tasks)):
        if tasks[k][2] <= i:
            heapq.heappush(prtasks, tasks[k])
            j += 1
        else:
            break
    if not prtasks:
        continue
    work = heapq.heappop(prtasks)
    money += work[0]

print(-money)
### BUGGY CODE ###

N=int(input())
Sarr1=[]
Sarr2=[]
for _ in range(N):
    s=input()
    if Sarr1.count(s)==0:
        Sarr1.append(s)
        Sarr2.append(0)
    else:
        i=Sarr1.index(s)
        Sarr2[i]+=1
ans=[]
for i in range(len(Sarr2)):
    if Sarr2[i]==max(Sarr2):
        ans.append(Sarr1[i])
    else:
        pass
FA=sorted(ans)
for z in FA:
    print(z)

### FIXED CODE ###

from collections import Counter

N=int(input())
S=[]

for _ in range(N):
    s=input()
    S.append(s)

c=Counter(S)
arr=c.most_common()

maxnum=arr[0][1]
ans=[]

for i in range(len(arr)):
    if arr[i][1]==maxnum:
        ans.append(arr[i][0])        
    else:
        break
FA=sorted(ans)
for j in FA:
    print(j)
### BUGGY CODE ###

import numpy as np
import sys
input=sys.stdin.readline

n,k=map(int,input().split())
p=np.array(list(map(int,input().split())))
p=(p+1.)/2.
max_p=0

for i in range(n-k+1):
    s=sum(p[i:i+k])
    if  max_p < s:
        max_p=s

print(max_p)

### FIXED CODE ###

#import numpy as np
import sys
input=sys.stdin.readline

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

#p=np.array(list(map(int,input().split())))
func=lambda x: ((int(x)+1.)/2.)
p=list(map(func,input().split()))

#p=(p+1.)/2.
s=sum(p[0:k])
max_p=s

#for i in range(n-k+1):
for i in range(n-k):
    #s=np.sum(p[i:i+k])
    s=s-p[i]+p[i+k]
    if  max_p < s:
        max_p=s

print(max_p)
### BUGGY CODE ###

N=int(input())

count=0
for i in range(1,N):
  count=count+i
print(count)

### FIXED CODE ###

N=int(input())
print((N)*(N-1)//2)
### BUGGY CODE ###

import queue

N, Q = map(int, input().split())
tree = [[] for _ in range(N+1)]
value = [0] * (N+1)
visit = [False] * (N+1)

# make_tree
for _ in range(N-1):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)

# make_value
for _ in range(Q):
    p, x = map(int, input().split())
    value[p] += x

# all_value_sum
q = queue.Queue()
q.put(1)
visit[1] = [True]
while not q.empty():
    now = q.get()
    for next in tree[now]:
        if not visit[next]:
            value[next] += value[now]
            q.put(next)
            visit[now] = True

# output_value
s = " ".join(map(str, value[1:]))
print(s)

### FIXED CODE ###

import sys
import queue
input = sys.stdin.readline

N, Q = map(int, input().split())
tree = [[] for _ in range(N+1)]
value = [0] * (N+1)
visit = [False] * (N+1)

# make_tree
for _ in range(N-1):
    a, b = map(int, input().split())
    tree[a].append(b)
    tree[b].append(a)

# make_value
for _ in range(Q):
    p, x = map(int, input().split())
    value[p] += x

# all_value_sum
q = queue.Queue()
q.put(1)
visit[1] = True
while not q.empty():
    now = q.get()
    for next in tree[now]:
        if not visit[next]:
            value[next] += value[now]
            q.put(next)
            visit[next] = True

# output_value
s = " ".join(map(str, value[1:]))
print(s)
### BUGGY CODE ###

n = input() 
for i in xrange (n): 
    x = raw_input()
    y = raw_input() 
    
    x = " " + x
    y = " " + y
    c = [[0 for i in xrange(len(x))] for j in xrange(len(y))]
    for i in xrange (1,len(y)):
        for j in xrange (1,len(x)):
            if x[j] == y[i]:
                c[i][j] = c[i-1][j-1] + 1
            elif c[i-1][j] >= c[i][j-1]:
                c[i][j] = c[i-1][j]
            else:
                c[i][j] = c[i][j-1]
    print max(max(c))

### FIXED CODE ###

def lcs():
    x, y = raw_input(), raw_input()
    b1 = [0 for k in range(len(y)+1)]
    for i in xrange(len(x)):
        a = x[i]
        b2 = b1 + []
        for j in xrange(len(y)):
            if a == y[j]:
                b1[j+1] = b2[j] + 1
            elif b1[j+1] < b1[j]:
                b1[j+1] = b1[j]
    print max(b1)
 
n = input()
for i in xrange(n):
    lcs()
### BUGGY CODE ###

#138_D
import sys
sys.setrecursionlimit(10 ** 6)

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

edges = [[] for _ in range(n)]
cnt = [0 for _ in range(n)]

for _ in range(n-1):
    a, b = map(int, input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)
    
for _ in range(q):
    p, x = map(int, input().split())
    cnt[p-1] += x
    
def dfs(frm, cur):
    for to in edges[cur]:
        if to != frm:
            cnt[to] += cnt[cur]
            dfs(cur, to)
dfs(-1, 0)          
print(*cnt)

### FIXED CODE ###

#138_D
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 6)

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

edges = [[] for _ in range(n)]
cnt = [0 for _ in range(n)]

for _ in range(n-1):
    a, b = map(int, input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)
    
for _ in range(q):
    p, x = map(int, input().split())
    cnt[p-1] += x
    
def dfs(frm, cur):
    for to in edges[cur]:
        if to != frm:
            cnt[to] += cnt[cur]
            dfs(cur, to)
dfs(-1, 0)          
print(*cnt)
### BUGGY CODE ###

n, a, b = list(map(int, input().split(' ')))
tmp = 0
count = 0
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 ###

N = int(input())
S = input()

# 1を満たす数
# 1,~2を満たす数を求める

def checkone(a,b,c):
	if (a!=c and b!=c and c!=a):
		return True
	else:
		return False

def check(i,j,N): # i,j,2j-iは違ったらTrue
	# i < jは保証
				# (0 > (2*i-j) or (2*i-j) >= N or checkone(S[i], S[j], S[2*i-j])) and
              	# (0 > (2*j-i) or (2*j-i) >= N or checkone(S[i], S[j], S[2*j-i])) #and
			  	# ( ((i+j)%2!=0) or checkone(S[i], S[j], S[abs(int((i+j)/2))]))
	if (0 > (2*j-i) or (2*j-i) >= N):
		# print("out of range")
		return False
	else:
		return checkone(S[i], S[j], S[2*j-i])

n_equal = 0
for i in range(N):
	for j in range(i,N):
		if( S[i]==S[j]):
			continue
		else:
			if(check(i,j,N)==True):
				n_equal+=1
				# print(i, j, 2*j-i)
				# print(S[i],S[j],S[2*j-i])
				# print("toukankaku")

# print("n_equal=",n_equal)

n_R = S.count('R')
n_G = S.count('G')
n_B = S.count('B')

n_all = n_R*n_G*n_B
# print("n_all=",n_all)

print(n_all-n_equal)

### FIXED CODE ###

N = int(input())
S = input()

# 1を満たす数
# 1,~2を満たす数を求める

# def checkone(a,b,c):
# 	if (a!=b and b!=c and c!=a):
# 		return True
# 	else:
# 		return False

def check(i,j,N): # i,j,2j-iは違ったらTrue
	# i < jは保証
				# (0 > (2*i-j) or (2*i-j) >= N or checkone(S[i], S[j], S[2*i-j])) and
              	# (0 > (2*j-i) or (2*j-i) >= N or checkone(S[i], S[j], S[2*j-i])) #and
			  	# ( ((i+j)%2!=0) or checkone(S[i], S[j], S[abs(int((i+j)/2))]))
	if (0 > (2*j-i) or (2*j-i) >= N):
		# print("out of range")
		return False
	else:
		return (S[j] != S[2*j-i] and S[2*j-i] != S[i])
		# return checkone(S[i], S[j], S[2*j-i])
# 2j-i <N
# j < (N+i)/2

n_equal = 0
for i in range(N):
	for j in range(i+1, int((N+i)/2)+1):
		if( S[i]==S[j]):
			continue
		else:
			if(check(i,j,N)==True):
				n_equal+=1
				# print(i, j, 2*j-i)
				# print(S[i],S[j],S[2*j-i])
				# print("toukankaku")

# print("n_equal=",n_equal)

n_R = S.count('R')
n_G = S.count('G')
n_B = S.count('B')

n_all = n_R*n_G*n_B
# print("n_all=",n_all)

print(n_all-n_equal)
### BUGGY CODE ###

import numpy as np
N,M=map(int,input().split())
A=[int(x) for x in input().split()]

for i in range(0,M):
    A[np.argmax(A)]=int(A[np.argmax(A)]/2)

print(sum(A))

### FIXED CODE ###

import heapq
N,M=map(int,input().split())
A=list(map(lambda x:int(x)*(-1),input().split()))
heapq.heapify(A)
    
for i in range(0,M):
    tmp=heapq.heappop(A)
    heapq.heappush(A,-int(-tmp/2))
print(-sum(A))
### BUGGY CODE ###

S = list(input())
Q = int(input())
x = 1
for i in range(Q):
    a, *b = input().split()
    if a == "1":
        x *= -1
    elif a == "2":
        c, d = b
        if c == "1":
            if x == -1:
                S.append(d)
            else:
                S.insert(0, d)
        elif c == "2":
            if x == -1:
                S.insert(0, d)
            else:
                S.append(d)
if x == -1:
    S = S[::-1]
print(*S, sep="")

### FIXED CODE ###

from collections import deque
S = deque(input())
Q = int(input())
x = 1
l=[]
for i in range(Q):
    a, *b = input().split()
    if a == "1":
        x *= -1
    elif a == "2":
        c, d = b
        if (c == "2" and x == -1) or  (c == "1" and x == 1):
            S.appendleft(d)
        else:
            S.append(d)
if x == -1:
    S.reverse()
print(*S, sep="")
### BUGGY CODE ###

import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

from bisect import bisect_right

N,M,Q = II()
x = []
for i in range(M):
    L,R = II()
    x.append([L-1, R-1])
p,q = Line(Q)


x.sort(key = lambda x:x[1])

y = [[] for _ in range(N)]
for i in range(M):
    for j in range(x[i][0]+1):
        y[j].append(x[i][1])

ans = 0
for i in range(Q):
    print(bisect_right(y[p[i]-1], q[i]-1))

### FIXED CODE ###

import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

N,M,Q = II()
x = []
for i in range(M):
    L,R = II()
    x.append([L-1, R-1])

p = [0]*Q
q = [0]*Q
for i in range(Q):
    p0,q0 = II()
    p[i] = p0-1
    q[i] = q0-1

a = [[0]*N for _ in range(N)]
for i in range(M):
    a[x[i][0]][x[i][1]] += 1

c = [[0]*N for _ in range(N)]
for i in range(N):
    for j in range(N):
        if j==0:
            temp = 0
        else:
            temp = c[i][j-1]
        c[i][j] = temp + a[i][j]

for i in range(Q):
    ans = 0
    for j in range(p[i],q[i]+1):
        ans += c[j][q[i]]
    print(ans)
### BUGGY CODE ###

s=input()
ans=0
while s.count("ABC")>0:
    x=s.count("ABC")
    ans+=x
    s=s.replace("ABC","BCA")
print(ans)


### FIXED CODE ###

s=input()
s=s.replace("BC","D")
n=len(s)
ans=0
cnt=0
for i in range(n-1,-1,-1):
    if s[i]=="B" or s[i]=="C":
        cnt=0
    elif s[i]=="D":
        cnt+=1
    else:
        ans+=cnt
print(ans)
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
def factorization(N):
    temp={}
    while True:
        divided=False
        for i in range(2, int(N**0.5)+1):
            if N%i==0:
                if i in temp:
                    temp[i]+=1
                else:
                    temp[i]=1
                N=N//i
                divided=True
                break
        if not divided:
            temp[1]=1
            if N in temp:
                temp[N]+=1
            else:
                temp[N]=1
            break
    return temp
G={}
for a in A:
    b=factorization(a)
    for k in b.keys():
        if k in G:
            G[k]=max(G[k], b[k])
        else:
            G[k]=b[k]
ans=0
P=10**9+7
for a in A:
    x=1
    b=factorization(a)
    for g in G:
        if g in b:
            x*=g**(G[g]-b[g])
        else:
            x*=g**(G[g])
    ans+=x
    ans%=P
print(ans)

### FIXED CODE ###

def gcd(a,b):
    if a>b:
        return gcd(b,a)
    if a==0:
        return b
    return gcd(b-a*(b//a),a)
def lcm(x,y):
    return (x*y)//gcd(x,y)
N=int(input())
A=list(map(int,input().split()))
s=1
for a in A:
    s=lcm(s,a)
ans=0
for a in A:
    ans+=s//a
print(ans%(10**9+7))
### BUGGY CODE ###

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

dp = [0] * n


for i in range(1,n):
    a = []
    if i-k < 0:
        start = 0
    else:
        start = i-k
    
    for j in range(start,i):
        a.append(dp[j] + abs(h[i] - h[j]))    
    
    dp[i] = min(a)
    
print(dp[-1])
                 

### FIXED CODE ###

# numpy version

import numpy as np

n, k = map(int, input().split())
h = np.array(list(map(int, input().split())))

dp = np.zeros(n)

for i in range(1,n): 
    j = max(0, i-k)
    dp[i] = np.min(dp[j:i] + np.abs(h[i] - h[j:i]))

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

import fractions
import math
import itertools
from functools import reduce

k = int(input())

def extract_gcd(limit):
    ran = range(1, limit + 1)
    for i in ran:
        for j in ran:
            for k in ran:
                yield math.gcd(math.gcd(i, j), k)
total = 0
for n in extract_gcd(k):
    total += n
    
print(total)
    


### FIXED CODE ###

from math import gcd
from collections import defaultdict

k = int(input())

memo = defaultdict(defaultdict)

rg = range(1, k + 1)
for i in rg:
    for j in rg:
        memo[i][j] = memo[j][i] = gcd(i, j)

ret = 0
for i in rg:
    for j in rg:
        tmp = memo[i][j]
        for k in rg:
            res = memo[k][tmp]
            ret += res

print(ret)
### BUGGY CODE ###

a,b,c,d=map(int,input().split())
def amari(a):
  return a % 998244353
import numpy as np
X=np.zeros((3, c, d),int)
X[0][a-1][b-1]=1
for j in range(b,d):
 X[0][a-1][j]=amari(X[0][a-1][j-1]*(a-1))
 X[1][a-1][j]=amari(X[0][a-1][j-1]+X[1][a-1][j-1]*(a-1))
 X[2][a-1][j]=amari(X[1][a-1][j-1]+X[2][a-1][j-1]*a)
for i in range(a,c):
 for j in range(b,d+1):
  X[1][i][j-1]=amari((X[0][i-1][j-1]+X[1][i-1][j-1]+X[2][i-1][j-1])*j)
  if j>=2:
   X[2][i][j-1]=amari(X[1][i][j-2]+X[2][i][j-2] *(i+1))
print(amari(X[0][c-1][d-1]+X[1][c-1][d-1]+X[2][c-1][d-1]))

### FIXED CODE ###

a,b,c,d=map(int,input().split())
def amari(a):
  return a % 998244353
X0=[[0]*d for i in range(c)]
X1=[[0]*d for i in range(c)]
X2=[[0]*d for i in range(c)]
X0[a-1][b-1]=1
for j in range(b,d):
 X0[a-1][j]=amari(X0[a-1][j-1]*(a-1))
 X1[a-1][j]=amari(X0[a-1][j-1]+X1[a-1][j-1]*(a-1))
 X2[a-1][j]=amari(X1[a-1][j-1]+X2[a-1][j-1]*a)
for i in range(a,c):
 for j in range(b,d+1):
  X1[i][j-1]=amari((X0[i-1][j-1]+X1[i-1][j-1]+X2[i-1][j-1])*j)
  if j>=2:
   X2[i][j-1]=amari(X1[i][j-2]+X2[i][j-2] *(i+1))
print(amari(X0[c-1][d-1]+X1[c-1][d-1]+X2[c-1][d-1]))
### BUGGY CODE ###

h, w, m = map(int, input().split())
boms = set()
# boms = [[0,0] for i in range(m)]
Hs = [0] * h
Ws = [0] * w
for i in range(m):
  _h, _w = map(int, input().split())
  boms.add((_h - 1,_w - 1))
  # boms[i][0] = _h - 1
  # boms[i][1] = _w - 1
  Hs[_h - 1] += 1
  Ws[_w - 1] += 1
Hmax = max(Hs)
Hcount = Hs.count(Hmax)
Wmax = max(Ws)
Wcount = Ws.count(Wmax)
Hindexs = [0] * Hcount
Windexs = [0] * Wcount
hcount = 0
wcount = 0
for i in range(h):
  if Hs[i] == Hmax:
    Hindexs[hcount] = i
    hcount += 1
for i in range(w):
  if Ws[i] == Wmax:
    Windexs[wcount] = i
    wcount += 1
count = 0
for bom in boms:
  if (bom[0] in Hindexs) and (bom[1] in Windexs):
    count += 1
if count == len(Hindexs) * len(Windexs):
  print(Hmax + Wmax - 1)
else:
  print(Hmax + Wmax)
# if m < len(Hindexs) * len(Windexs):
#   print(Hmax + Wmax)
#   exit()
# for hindex in Hindexs:
#   for windex in windexs:
#     if hindex in  and windex):
#       print(Hmax + Wmax)
#       exit()
# print(Hmax + Wmax -1)

### FIXED CODE ###

h, w, m = map(int, input().split())
boms = set()
Hs = [0] * h
Ws = [0] * w
for i in range(m):
  _h, _w = map(int, input().split())
  boms.add((_h - 1, _w - 1))
  Hs[_h - 1] += 1
  Ws[_w - 1] += 1
Hmax = max(Hs)
Hcount = Hs.count(Hmax)
Wmax = max(Ws)
Wcount = Ws.count(Wmax)
Hindexs = [0] * Hcount
Windexs = [0] * Wcount
hcount = 0
wcount = 0
for i in range(h):
  if Hs[i] == Hmax:
    Hindexs[hcount] = i
    hcount += 1
for i in range(w):
  if Ws[i] == Wmax:
    Windexs[wcount] = i
    wcount += 1
if m < len(Hindexs) * len(Windexs):
  print(Hmax + Wmax)
  exit()
for hindex in Hindexs:
  for windex in Windexs:
    if (hindex,windex) not in boms: 
      print(Hmax + Wmax)
      exit()
print(Hmax + Wmax -1)
### BUGGY CODE ###

def main():
  n=int(input())
  a=list(map(lambda x:list(map(int,list(bin(int(x))[2:]))),input().split()))
  mod=pow(10,9)+7
  ans=0
  len_ai=[]
  for ai in a:
    len_ai.append(len(ai))
  for i in range(61):# 2^iの位
    bit1=0
    for j in range(n):
      if len_ai[j]>=i+1:
        bit1+=a[j][-i-1]
    ans+=(pow(2,i,mod)*bit1*(n-bit1))%mod
    ans%=mod
  print(ans)
if __name__=='__main__':
  main()

### FIXED CODE ###

import sys
input = sys.stdin.readline
def main():
  n=int(input())
  a=list(map(int,input().split()))
  mod=pow(10,9)+7
  ans=0
  bit=[0]*61 #bit[i]:2^iの位が1である物の個数
  for ai in a:
    for j in range(61):
      if ((ai>>j) & 1):
        bit[j]+=1
  for i in range(61):
    ans+=(pow(2,i)%mod)*bit[i]*(n-bit[i])
    ans%=mod
  print(ans)
if __name__=='__main__':
  main()
### BUGGY CODE ###

# -*- coding: utf-8 -*-
"""
Created on Tue Jan 21 18:19:39 2020

@author: matsui
"""

def napsak(N,K):
    dp=[0]*(W+1)
    for i in range(1,N+1):
        #print(dp)
        w,v=map(int,input().split())
        A=dp[:w]
        A.extend([max(dp[j],dp[j-w]+v) for j in range(w,W+1)])
        dp=A
    return dp[-1]

N,W=map(int,input().split())   
print(napsak(N,W))


### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Tue Jan 21 18:19:39 2020

@author: matsui
"""


N,W=map(int,input().split())
dp=[0]*(W+1)
L = sorted([list(map(int,input().split())) for i in range(N)])
s=0

for w, v in L:
    s+=w
    for j in range(min(W,s),w-1,-1):
        if dp[j-w]+v > dp[j]: dp[j]=dp[j-w]+v
    
print(max(dp))
### BUGGY CODE ###

import math
k = int(input())
box = []
for i in range(1,k+1):
  for j in range(1,k+1):
    for l in range(1,k+1):
      gap = math.gcd(i,j)
      gap2 = math.gcd(gap,l)
      box.append(gap2)
print(sum(box))

### FIXED CODE ###

import math
k = int(input())
box = []
for i in range(1,k+1):
  for j in range(1,k+1):
    gap = math.gcd(i,j)
    if gap == 1:
      box.append(1*k)
    else:
      for l in range(1,k+1):
        gap2 = math.gcd(gap,l)
        box.append(gap2)        
print(sum(box))
### BUGGY CODE ###

n, k = [int(x) for x in input().strip().split()]
a = [int(x) for x in input().strip().split()]
assert len(a) == n
a = [0] + a
current = 1
way = [1]
for i in range(k):
  current = a[current]
  if current in way:
    li = way.index(current)
    loop = way[li:]
    print(loop[(k - li) % len(loop)])
    break
  else:
    way.append(current)
else:
  print(current)


### FIXED CODE ###

n, k = [int(x) for x in input().split()]
a = [int(x)-1 for x in input().split()]
assert len(a) == n
current = 0
visited = [-1] * n
visited[0] = 0
for i in range(1, k):
  current = a[current]
  if visited[current] == -1:
    visited[current] = i
  else:
    pre = visited[current]
    count = (k - pre) % (i - pre) + pre
    print(visited.index(count)+1)
    break
else:
  print(a[current]+1)
### BUGGY CODE ###

import copy
import math
 
d,g = [int(i) for i in input().split()]
P = []
C = []
for i in range(d):
    p,c = [int(i) for i in input().split()]
    P.append(p)
    C.append(c)
 
m = 10**9
def score(point = 0, n = 0, now=0, done=[]):
    global m
    if point >= g:
        if m > n: m = n
    elif point+100*(now+1)*P[now] >= g:
        n += math.ceil((g-point)/(100*(now+1)))
        if m > n: 
            m = n
    else:
        done.append(now)
        for i in range(d):
            if not i in done:
                score(point+P[now]*100*(now+1) + C[now], n + P[now], i, copy.copy(done))
 
for i in range(d):
    done = []
    score(0,0,i,done)
print(m)

### FIXED CODE ###

import math
 
d,g = [int(i) for i in input().split()]
P = []
C = []
for i in range(d):
    p,c = [int(i) for i in input().split()]
    P.append(p)
    C.append(c)

# cnt = 0
# def count():
#     global cnt
#     cnt+=1
#     print(cnt)

def flag(point,P,now):
    if point+100*(now+1)*(P-1) >= g: return 1
    elif point+100*(now+1)*P + C[now] >= g: return 2
    else: return 0

m = 10**9
def score(point = 0, n = 0, now=-1, remain = list(range(d))):
    global m
    if m <= n: return
    elif now == -1:
        for i in remain:
            score(point, n, i, remain)
    elif point >= g: m = n
    elif flag(point,P[now],now) == 1:
        n += math.ceil((g-point)/(100*(now+1)))
        if m > n: m = n
    elif flag(point,P[now],now) == 2:
        n += P[now]
        if m > n: m = n
    else:
        if m <= n+P[now]: return
        else:
            remain = remain[:]
            remain.remove(now)
            nxtp = point + P[now]*100*(now+1) + C[now]
            for i in remain:
                score(nxtp, n + P[now], i, remain)

score()
print(m)