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

a,aa=map(int,input().split())
b=list(map(int,input().split()))
c=[float("inf") for i in range(a)]
c[0]=0
for i in range(1,a):
  c[i] = min(c[j] + abs(b[i] - b[j]) for j in range(max(0,i-aa),i))
print(c[-1])

### FIXED CODE ###

def solve():
  a,aa=map(int,input().split())
  b=list(map(int,input().split()))
  c=[0]*a
  c[0]=0
  for i in range(1,a):
    c[i] = min(c[j] + abs(b[i] - b[j]) for j in range(max(0,i-aa),i))
  print(c[-1])
  
solve()
### BUGGY CODE ###

l,r=map(int,input().split())
temp=[]
if l-r>=2019:
    print(0)
else:
    for i in range(l,r):
        for j in range(i+1,r+1):
            temp.append((i*j)%2019)
    print(min(temp))


### FIXED CODE ###

l,r=map(int,input().split())
temp=[]
if r-l>=2019:
    print(0)
else:
    for i in range(l,r):
        for j in range(i+1,r+1):
            temp.append((i*j)%2019)
    print(min(temp))
### BUGGY CODE ###

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

H = i[0]
W = i[1]
amount = 0
count = 0
for j in range(H):
    for k in range(W):
        if count % 2 != 0:
            count += 1
        else:
            count += 1
            amount += 1

print(amount)

### FIXED CODE ###

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

H = i[0]
W = i[1]


if(W == 1):
    print(1)
elif(H == 1):
    print(1)
#横が偶数の時は、縦の偶奇によらない
elif(W % 2 == 0):
    yoko = W // 2
    print(yoko*H)
#横が奇数の時は、縦の偶奇による
elif(W % 2 != 0):
    yoko = W // 2 + 1
    #縦が偶数の時
    if(H % 2 == 0):
        print(yoko*(H//2)+(yoko-1)*(H//2))
    #縦が奇数の時
    else:
        print(yoko*(H//2+1)+(yoko-1)*(H//2))
### BUGGY CODE ###

N = int(input())
M = N-1
inf = float("inf")
dp = [[inf]*N for _ in [0]*N]
for i in range(N):dp[i][i] = 0
q = [list(map(int, input().split())) for i in range(M)]
Q , K = map(int, input().split())
p = [list(map(int, input().split())) for i in range(Q)]
ans = 0
 
for a,b,c in q:
    dp[a-1][b-1] = c
    dp[b-1][a-1] = c
for k in range(N):
    for i in range(N):
        for j in range(N):
            dp[i][j] = min(dp[i][j],dp[i][k]+dp[k][j])
for a,b in p:
    print(dp[a-1][K-1]+dp[K-1][b-1])



### FIXED CODE ###

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

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

Q, K = map(int, input().split())
K -= 1

depth = [0 for _ in range(N)]

def dfs(v, p = -1, d = 0):
    St = []
    St.append([v, p, d])
    # 空のシーケンスは偽になる
    while St:
        cur = St.pop()
        depth[cur[0]] = cur[2]
        for i, j in tree[cur[0]]:
            if i == cur[1]:
                continue
            St.append([i, cur[0], cur[2] + j])

dfs(K)

for i in range(Q):
    x, y = map(int, input().split())
    x -= 1; y -= 1
    print (depth[x] + depth[y])
### BUGGY CODE ###

H,W=map(int, input().split())
S=[]
for h in range(H):
    s=list(input())
    S.append(s)
ans=0
for h in range(H):
    for w in range(W):
        if S[h][w]==".":
            count=1
            que=[(h,w,"l"),(h,w,"u"),(h,w,"r"),(h,w,"d")]
            while len(que)>0:
                t=que.pop(0)
                h2,w2,to=t
                if to=="l":
                    nh=h2
                    nw=w2-1
                elif to=="u":
                    nh=h2+1
                    nw=w2
                elif to=="r":
                    nh=h2
                    nw=w2+1
                else:
                    nh=h2-1
                    nw=w2
                if 0<=nh<H and 0<=nw<W:
                    if S[nh][nw]==".":
                        count+=1
                        que.append((nh,nw,to))
            ans=max(ans, count)
print(ans)


### FIXED CODE ###

import numpy as np
H, W=map(int, input().split())
S=np.array([list(input()) for _ in range(H)])
S=np.where(S==".",1,0 )

left=np.zeros((H, W))
right=np.zeros((H, W))
top=np.zeros((H, W))
bottom=np.zeros((H, W))

for i in range(W):
  if i==0:
    left[:,i]=S[:,i]
    right[:,-i-1]=S[:,-i-1]
  else:
    left[:,i]=(left[:,i-1]+1)*S[:,i]
    right[:,-i-1]=(right[:,-i]+1)*S[:,-i-1]
    
for i in range(H):
  if i==0:
    top[i,:]=S[i,:]
    bottom[-1-i,:]=S[-i-1,:]
  else:
    top[i,:]=(top[i-1,:]+1)*S[i,:]
    bottom[-1-i,:]=(bottom[-i,:]+1)*S[-i-1,:]
    
ans=left+top+right+bottom-3
    

print(int(ans.max()))
### BUGGY CODE ###

import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
from collections import deque
from copy import deepcopy
def main():
    n, *a = map(int, read().split())
    if n == 1:
        print(1)
        sys.exit()
    if n == 2:
        if a[0] == a[1]:
            print(0)
            sys.exit()
        elif max(a) % min(a) == 0:
            print(0)
            sys.exit()
        else:
            print(2)
            sys.exit()
    a.sort()
    notdiv = [True] * n
    for i1, ae in enumerate(a):
        if notdiv[i1]:
            for i2 in range(i1+1, n):
                if notdiv[i2]:
                    notdiv[i2] = a[i2] % ae != 0
    if a[0] == a[1]:
        notdiv[0] = False
    if a[-1] == a[-2]:
        notdiv[-1] = False
    for j1 in range(1, n - 1):
        if a[j1-1] == a[j1] or a[j1] == a[j1+1]:
            notdiv[j1] = False
    r = sum(notdiv)
    print(r)
if __name__ == '__main__':
    main()

### FIXED CODE ###

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

    a.sort()
    tf = [0] * (a[-1] + 1)
    for ea in a:
        tf[ea] = 1
    for i1 in range(n - 1):
        if a[i1] == a[i1 + 1]:
            tf[a[i1]] = 0

        for i2 in range(2, a[-1]//a[i1] + 1):
            tf[a[i1] * i2] = 0
    r = sum(tf)
    print(r)


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

import itertools

def f(n):
  m = int(n**0.5)
  out = sum([True for x, y, z in itertools.product(range(1, n+1), repeat=3) if x**2+y**2+z**2+x*y+y*z+z*x==n])
  return out

N = int(input())
for n in range(1, N+1):
  print(f(n))


### FIXED CODE ###

import itertools
import collections



N = int(input())
count = [0]*N*100
m = int(N**0.5)
for x, y, z in itertools.combinations_with_replacement(range(1, m+1), 3):
  n = x**2+y**2+z**2+x*y+y*z+z*x
  k = len(set({x, y, z}))
  if k == 1:
    count[n] += 1
  elif k == 2:
    count[n] += 3
  else:
    count[n] += 6

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

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

l = []
for i in range(N):
    l.append((1+p[i])/2)

k = []
for i in range(len(l)):
    k.append(sum(l[i:i+K]))

print(max(k))

### FIXED CODE ###

import numpy as np
N,K = map(int,input().split())
p = list(map(int,input().split()))

l = []
for i in range(N):
    l.append((1+p[i])/2)

a = [0] * N
a[0] = l[0]
for i in range(1,len(l)):
    a[i] = a[i-1] + l[i]

ans = 0
for i in range(K,len(l)):
    ans = max(ans,a[i]-a[i-K])

if N == 1 or N - K == 0:
    print(max(a))
else:
    print(ans)
### BUGGY CODE ###

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

res=0
for i in range(0,n-k+1):
	tmp=sum(p[i:i+k])
	res=max(res,tmp)

print((float(res)+k)/2)

### FIXED CODE ###

from collections import deque

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

q=deque(p[0:k])
tmp=sum(q)
res=tmp
for i in range(k,n):
	q.append(p[i])
	tmp+=(p[i]-q.popleft())
	res=max(res,tmp)
	
print((float(res)+k)/2)
### BUGGY CODE ###

import sys
H, N = map(int, sys.stdin.readline().split())
m = map(int, sys.stdin.read().split())
AB = zip(m, m)
INF = float('inf')
dp = [[INF]*(H+10**4) for _ in range(N+1)]
dp[0][0] = 0
for i in range(1, N+1):
    a, b = next(AB)
    for j in range(H+10**4):
        dp[i][j] = min(dp[i-1][j], dp[i][j-a] + b if j-a >= 0 else INF)
# print(min([min(i[H:]) for i in dp]))
print(min(dp[-1][H:]))


### FIXED CODE ###

import sys
H, N = map(int, sys.stdin.readline().split())
m = map(int, sys.stdin.read().split())
AB = zip(m, m)
INF = 10**20
dp = [INF]*(H+10**4)
dp[0] = 0
for a, b in AB:
    for j in range(H+10**4):
        dp[j] = min(dp[j], dp[j-a] + b if j-a >= 0 else INF)
print(min(dp[H:]))
### BUGGY CODE ###

n,k,q = map(int, list(input().split()))
point=[k]*n
a=[]

for i in range(q*n):
	point[i%n]-=1
for i in range(q):
	a.append(int(input()))
	point[a[i]-1]+=1
max=max(point)
for i in range(n):
    if point[i]==max or point[i]>0:
        print("Yes")
    else:
        print("No")

### FIXED CODE ###

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

import numpy as np


def atcoder_input():
    H, W = (int(i) for i in input().split())
    _ = []

    for i in range(H):
        l = [j for j in input().split()]
        _.append(l)
    _ = np.array(_)

    A = np.zeros((H, W)).astype("int")

    for h in range(H):
        for w in range(W):
            if _[h][0][w] == ".":
                A[h][w] = 0
            else:
                A[h][w] = 1

    return A, H, W


def main():
    A, H, W = atcoder_input()
    """
    max_score = 0
    for i in range(H):
        for j in range(W):
            if(A[i,j]==0):
                score=np.min(np.abs(i - x_where) + np.abs(j - y_where))
                if score >= max_score:
                    max_score = score
    """

    y_where = np.where(A == 1)[0]
    x_where = np.where(A == 1)[1]

    counter = 0

    while np.min(A) == 0:
        counter += 1

        A[np.clip(y_where+1, 0, H - 1), np.clip(x_where, 0, W - 1), ] = 1
        A[np.clip(y_where, 0, H - 1), np.clip(x_where+1, 0, W - 1)] = 1
        A[np.clip(y_where - 1, 0, H - 1), np.clip(x_where, 0, W - 1)] = 1
        A[np.clip(y_where, 0, H - 1), np.clip(x_where - 1, 0, W - 1)] = 1

        y_where = np.where(A == 1)[0]
        x_where = np.where(A == 1)[1]

    print(counter)


if __name__ == "__main__":
    main()


### FIXED CODE ###

from collections import deque

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

# input black cells
black_cells = []

for h in range(H):
    line = list(input())
    for w in range(W):
        if line[w] == "#":
            black_cells.append(h * W + w)


# Graph
def r(p):
    q_list = []
    h = p // W
    w = p % W
    if h != 0:
        q_list.append(p - W)
    if h != H-1:
        q_list.append(p + W)
    if w != 0:
        q_list.append(p - 1)
    if w != W-1:
        q_list.append(p + 1)
    return q_list


queue = deque(black_cells)
d = [10000] * (H * W)
for i in black_cells:
    d[i] = 0

# dijkstra
while len(queue) > 0:
    p = queue.popleft()
    for q in r(p):
        if d[q] > d[p] + 1:
            d[q] = d[p] + 1
            queue.append(q)

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

from itertools import combinations

def resolve():
    N = int(input())
    S = str(input())
    ans = []
    for i in range(N):
        for j in range(i + 1, N):
            for k in range(j + 1, N):
                ans.append(S[i] + S[j] + S[k])

    print(len(set(ans)))
    return

resolve()


### FIXED CODE ###

def resolve():
    N = int(input())
    S = str(input())
    cnt = 0

    for i in range(1000):
        c = [int(i / 100), int(i / 10) % 10, int(i % 10)]
        f = 0

        for j in range(N):
            if S[j] == ('0' + str(c[f])) or S[j] == str(c[f]):
                f += 1
            if f == 3:
                break

        if f == 3:
            cnt += 1
    print(cnt)
    return

resolve()
### BUGGY CODE ###

import sys
import numpy as np

sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

H, W = map(int,input().split())
#A = [list(map(int,input().split())) for _ in range(H)]
A = np.array([list(input()) for _ in range(H)], 'U1')
eq = A == '.'

dp = np.zeros((H+1,W+1), dtype=int)
#np.zeros(W+1, dtype=int)
dp[0][1] = 1

for i in range(H):
    for j in range(W):
        if eq[i][j]:
            dp[i+1][j+1] = dp[i][j+1] + dp[i+1][j]
#            print(i,j,dp[i])
#            if i == 0 and j== 0:
#                dp[i+1][j+1] = 1
    dp[i+1] %= mod

print(dp[-1][-1])

### FIXED CODE ###

# -*- coding: utf-8 -*-
"""
Created on Sun Jan  6 21:36:22 2019

@author: Yamazaki Kenichi
"""

H,W = map(int,input().split())
a = [input() for i in range(H)]

r =[[0]*W for i in range(H)]
r[0][0]=1


for i in range(1,W):
    if a[0][i]== '.':
        r[0][i] = r[0][i-1]

for j in range(1,H):
    if a[j][0] =='.':
        r[j][0] = r[j-1][0]
            
for j in range(1,H):
    for i in range(1,W):
        if a[j][i] == '.':
            r[j][i] = r[j-1][i]+r[j][i-1]

print(r[H-1][W-1]%1000000007)
### BUGGY CODE ###

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

cum = 1
over = False
for x in a:
    if x == 0:
        cum = 0
        break

    cum *= x
    if (cum > 1e18):
        over = True

print(-1) if (over and cum != 0) else print(cum)


### FIXED CODE ###

from sys import stdin
input = stdin.readline

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

cum = 1
over = False
for x in a:
    if x == 0:
        cum = 0
        break

if cum == 0:
    print(0)
else:
    for x in a:
        cum *= x
        if (cum > 1e18):
            over = True
            break
    print(-1) if over else print(cum)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
from collections import deque
H, W = map(int, input().split())
C = [list(input()) for i in range(H)]
X = [1,0,-1,0]
Y = [0,-1,0,1]
Q = deque()
dist = [[0]*W for i in range(H)]
for i in range(H):
  for j in range(W):
    if C[i][j] == "#":
      Q.append((i,j))
      while Q:
        y,x = Q.popleft()
        for k in range(4):
          ny = y + Y[k]
          nx = x + X[k]
          if not (0 <= nx < W):
            continue
          if not (0 <= ny < H):
            continue
          if not (C[ny][nx] == "."):
            continue
          if not (dist[ny][nx] == 0 or dist[ny][nx] > dist[y][x]+1):
            continue
          Q.append((ny,nx))
          dist[ny][nx] = dist[y][x] + 1
ans = 0
for i in range(H):
  ans = max(ans,max(dist[i]))
print(ans)

### FIXED CODE ###

from collections import deque
H, W = map(int, input().split())
A = [input() for i in range(H)]
X = [1,0,-1,0]
Y = [0,-1,0,1]

INF = 99999
dp = [[-1]*W for i in range(H)]
q = deque()
for y, row in enumerate(A):
  for x,c in enumerate(row):
    if c == "#":
      dp[y][x] = 0
      q.append((y,x))
while q:
  y,x = q.popleft()
  d = dp[y][x]
  for i in range(4):
    nx = x + X[i]
    ny = y + Y[i]
    if (0 <= nx < W) and (0 <= ny < H) and (dp[ny][nx] == -1):
      dp[ny][nx] = d + 1
      q.append((ny,nx))
print(max(max(row) for row in dp))
### BUGGY CODE ###

n = int(raw_input())
ais = [int(raw_input()) for _ in range(n)]
tails = []
import bisect
for a in ais:
	if not(tails):
		tails = [a] + tails 
	else:
		m = -1
		for ii in range(len(tails)):
			if tails[ii] < a: m = max(ii, m)
		if m != -1:
			tails[m] = a
		else:
			tails.append(a)

print len(tails)

### FIXED CODE ###

n = int(raw_input())
ais = [int(raw_input()) for _ in range(n)]
tails = []
import bisect
for a in ais:
	if not(tails) or (tails[-1] >= a):
		tails.append(a)
	else:
		# maintain a decreaing tails
		986643321
		lo,hi = 0, len(tails) - 1
		while(lo<hi):
			med= (lo + hi)/2
			if tails[med] < a:
				hi = med
			else:
				lo = med + 1
		tails[lo] = a
print len(tails)
### BUGGY CODE ###

K,S = map(int,input().split())
flag = 1
s = 0
for l in range(K+1):
  if l == S+1:
    break
  for m in range(K+1):
    n = S - (l+m)
    if l == S+1:
      break
    elif (0<=n)and(n<=K) and (l+m+n == S):
      s = s+1
print(s)

### FIXED CODE ###

K,S = map(int,input().split())
flag = 1
s = 0
for l in range(K+1):
  for m in range(K+1):
    if (0 <= S-l-m)and(S-l-m<=K):
      s = s+1
print(s)
### BUGGY CODE ###

N = int(input())
X = list(input())


def f(cnt):
    if (cnt > 0):
        pcount = p_count(cnt)
        return f(cnt % pcount) + 1
    else:
        return 0


def p_count(x):
    cnt = 0
    while (x > 0):
        if x % 2 != 0:
            cnt += 1
        x //= 2
    return cnt


for i, x in enumerate(X):
    if (x == '1'):
        X[i] = '0'
        num = int(''.join(X), 2)
        print(f(num))
        X[i] = '1'
    else:
        X[i] = '1'
        num = int(''.join(X), 2)
        print(f(num))
        X[i] = '0'

### FIXED CODE ###

#!/usr/bin/env python3
N = int(input())
X = input()

x_num = int(X, 2)
cnt1 = X.count('1')

p_zero = x_num % (cnt1 + 1)
p_one = (x_num % (cnt1 - 1) if cnt1 - 1 > 0 else 1)


def f(cnt):
    if (cnt > 0):
        pcount = p_count(cnt)
        return f(cnt % pcount) + 1
    else:
        return 0


def p_count(x):
    cnt = 0
    while (x > 0):
        if x % 2 != 0:
            cnt += 1
        x //= 2
    return cnt


def f1(x):
    cnt = 0
    while (x > 0):
        x %= bin(x).count('1')
        cnt += 1
    return cnt


for i, x in enumerate(list(X)):
    if (x == '1'):
        #x_num = int(''.join(X), 2)
        if cnt1 - 1 > 0:
            xxx = (p_one - pow(2, (N - (i + 1)), cnt1 - 1)) % (cnt1 - 1)
            xxx += cnt1 - 1 if xxx < 0 else 0
            print(f1(xxx) + 1)
        else:
            print(0)
    else:
        #x_num = int(''.join(X), 2)
        xxx = (p_zero + pow(2, (N - (i + 1)), cnt1 + 1)) % (cnt1 + 1)
        xxx += cnt1 + 1 if xxx < 0 else 0
        print(f1(xxx) + 1)
### BUGGY CODE ###

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

dp = [[0] * (s + 1) for _ in range(n + 1)]
dp[0][0] = 1

for i, e in enumerate(a, 1):
    for j in range(s + 1):
        dp[i][j] += 2 * dp[i-1][j]
        if j - e >= 0:
            dp[i][j] += dp[i-1][j-e]

        dp[i][j] %= mod

ans = dp[n][s]
print(ans)



### FIXED CODE ###

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

dp = [[0] * (s + 1) for _ in range(n + 1)]
dp[0][0] = 1

for i, e in enumerate(a, 1):
    for j in range(s + 1):
        dp[i][j] += 2 * dp[i-1][j]
        if j - e >= 0:
            dp[i][j] += dp[i-1][j-e]

        dp[i][j] %= mod

ans = dp[n][s]
print(ans)
### BUGGY CODE ###

from collections import deque
N = int(input())
A = [int(a)-1 for a in input().split()]
M = N + 2
X = [max(min(i-1, j-1, M-2-i, M-2-j), -1) for j in range(M) for i in range(M)]
Y = [min(x, 0) + 1 for x in X]

def calc(i0):
    h = X[i0]
    if h < 0: return
    Q = deque([(i0, h)])
    X[i0] -= 1
    Y[i0] = 0
    S = {i0}
    dd = (-1, 1, M, -M)
    while Q:
        i, h = deque.popleft(Q)
        for d in dd:
            j = i + d
            if j in S: continue
            y = Y[j]
            if X[j] >= h + y:
                X[j] -= 1
                deque.append(Q, (j, h + y))
                S.add(j)
ans = 0
for a in A:
    aa = (a // N + 1) * M + a % N + 1
    ans += X[aa]
    calc(aa)
print(ans)

### FIXED CODE ###

from collections import deque
N = int(input())
A = [int(a)-1 for a in input().split()]
M = N + 2
X = [max(min(i-1, j-1, M-2-i, M-2-j), -1) for j in range(M) for i in range(M)]
Y = [min(x, 0) + 1 for x in X]

def calc(i0):
    h = X[i0]
    if h < 0: return
    Q = deque([(i0, h)])
    X[i0] -= 1
    Y[i0] = 0
    dd = (-1, 1, M, -M)
    while Q:
        i, h = deque.popleft(Q)
        for d in dd:
            j = i + d
            y = Y[j]
            if X[j] >= h + y:
                X[j] -= 1
                deque.append(Q, (j, h + y))
ans = 0
for a in A:
    aa = (a // N + 1) * M + a % N + 1
    ans += X[aa]
    calc(aa)
print(ans)
### BUGGY CODE ###

import queue

def dijkstra(g,node_count):
    conf = [0] * node_count
    root = [-1] * node_count

    q = queue.Queue()
    q.put(0)
    root[0] = 0
    conf[0] = 1
    while not q.empty():

        p = q.get()
        conf[p] = 1
        for i in range(node_count):
            if conf[i] == 0 and g[p][i] > 0 and i != p:
                q.put(i)
                root[i] = p
                conf[i] = 1
                if sum(conf) == node_count:
                    break
                
    return root


n, m = map(int, input().split())
r = []
#g = np.zeros((n,n))
g = [[0] * n for i in range(n)]

for i in range(m):
    a, b = map(int, input().split())
    g[a-1][b-1] = 1
    g[b-1][a-1] = 1
    #r.append([a,b])
#for i in range(n):
#    print(g[i])
#c = dijkstra_heapq(g,n,0)
#print(c)
c = dijkstra(g,n)

#c = np.array(c) + 1
#print(c)
ans = []
for i in range(1,n):
    if c[i] >= 0:
        ans.append(c[i]+1)
    else:
        print('No')
        exit()

print('Yes')
for i in range(len(ans)):
    print(ans[i])


### FIXED CODE ###

import queue
n, m = map(int, input().split())
g = [[] for _ in range(n+1)]

for i in range(m):
    a, b = map(int, input().split())
    g[a].append(b)
    g[b].append(a)

#print(g)

root = [0] * n
count = 0
q = queue.Queue()
q.put(0)
root[0] = 1
count += 1
while not q.empty():
    p = q.get()
    for i in g[p+1]:
        if root[i-1] <= 0:
            q.put(i-1)
            root[i-1] = p + 1
            count += 1
            #print(p,i,count,root)
            if count >= n:
                break


if count < n:
    print('No')
    exit()
else:
    print('Yes')
    for i in range(1,n):
        print(root[i])
### BUGGY CODE ###

Q = 10**9 + 7
def main():
    N = int( input())
    A = list( map( int, input().split()))
    T = [[0]*60 for _ in range(N)]
    for i in range(N):
        a = A[i]
        for j in range(60):
            T[i][j] = a%2
            a //= 2
    ans = 0
    for i in range(60):
        plus = sum( [1 for j in range(N) if T[j][i] == 1])
        minus = N - plus
        ans = (ans + plus*minus%Q*pow(2,i,Q))%Q
    print(ans)
        
if __name__ == '__main__':
    main()


### FIXED CODE ###

#import sys
#input = sys.stdin.readline
Q = 10**9 + 7
def main():
    N = int( input())
    A = list( map( int, input().split()))
    T = [[0]*60 for _ in range(N)]
    P = [0]*60
    for i in range(N):
        a = A[i]
        for j in range(60):
            T[i][j] = a%2
            P[j] += a%2
            a //= 2
    ans = 0
    for i in range(60):
        plus = P[i]
        minus = N - plus
        ans = (ans + plus*minus%Q*pow(2,i,Q))%Q
    print(ans)
        
if __name__ == '__main__':
    main()
### BUGGY CODE ###

import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
mod = 7 + 10**9
A = []
leng = len(format(max(a), 'b'))
bit_acc = [0 for i in range(leng)]
for i in range(n):
    A.append(list(map(int, format(a[i], 'b').zfill(leng))))
for i in range(leng):
    bit_acc[i] = sum([A[j][i] for j in range(n)]) 
ans = 0
for i in range(n):
    for j in range(leng):
        if A[i][j] == 1:
            ans += (n - bit_acc[j]) * pow(2,leng - j - 1,mod)
        else:
            ans += bit_acc[j] * pow(2,leng - j - 1,mod)
print((ans * 500000004) % mod)



### FIXED CODE ###

def main():
    import sys
    input = sys.stdin.readline
    n = int(input())
    a = list(map(int, input().split()))
    a.reverse()
    mod = 7 + 10**9
    leng = len(format(max(a), 'b'))
    bit_acc = [0 for i in range(leng)]
    for i in range(n):
        #先頭から二進数を0埋めした
        bit_data = format(a[i], 'b').zfill(leng)
        for j in range(leng):
            if bit_data[j] == '1':
                bit_acc[j] += 1
    ans = 0
    p = [pow(2,leng - 1 - j, mod) for j in range(leng)]
    for i in range(n):
        bit_data = format(a[i], 'b').zfill(leng)
        for j in range(leng):
            if bit_data[j] == '1':
                ans += (n - bit_acc[j]) * p[j]
            else:
                ans += bit_acc[j] * p[j]
            ans %= mod
    print((ans * 500000004) % mod)
if __name__ == "__main__":
    main()