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

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

R = [0] * N
G = [0] * N
B = [0] * N

for i in range(N):
    if S[i] == 'R':
        R[i] = 1
    elif S[i] == 'G':
        G[i] = 1
    else:
        B[i] = 1

sumR = sum(R)
sumG = sum(G)
sumB = sum(B)

cnt = 0
for i in range(N):
    sumR -= R[i]
    sumG -= G[i]
    sumB -= B[i]
    sum_r = sumR
    sum_g = sumG
    sum_b = sumB
    for j in range(i + 1, N):
        sum_r -= R[j]
        sum_g -= G[j]
        sum_b -= B[j]
        if S[j] == 'R':
            if S[i] == 'B':
                cnt += sum_g
                if j + (j - i) < N:
                    cnt -= G[j + (j - i)]
            if S[i] == 'G':
                cnt += sum_b
                if j + (j - i) < N:
                    cnt -= B[j + (j - i)]
        elif S[j] == 'G':
            if S[i] == 'R':
                cnt += sum_b
                if j + (j - i) < N:
                    cnt -= B[j + (j - i)]
            if S[i] == 'B':
                cnt += sum_r
                if j + (j - i) < N:
                    cnt -= R[j + (j - i)]
        else:
            if S[i] == 'R':
                cnt += sum_g
                if j + (j - i) < N:
                    cnt -= G[j + (j - i)]
            if S[i] == 'G':
                cnt += sum_r
                if j + (j - i) < N:
                    cnt -= R[j + (j - i)]
print(cnt)


### FIXED CODE ###

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

R = [0] * N
G = [0] * N
B = [0] * N

for i in range(N):
    if S[i] == 'R':
        R[i] = 1
    elif S[i] == 'G':
        G[i] = 1
    else:
        B[i] = 1

sumR = sum(R)
sumG = sum(G)
sumB = sum(B)

cnt = 0
for i in range(N):
    sumR -= R[i]
    sumG -= G[i]
    sumB -= B[i]
    sum_r = sumR
    sum_g = sumG
    sum_b = sumB
    for j in range(i + 1, N):
        sum_r -= R[j]
        sum_g -= G[j]
        sum_b -= B[j]
        check_index = j + (j - i)
        if S[j] == 'R':
            if S[i] == 'B':
                cnt += sum_g
                if check_index < N:
                    cnt -= G[check_index]
            if S[i] == 'G':
                cnt += sum_b
                if check_index < N:
                    cnt -= B[check_index]
        elif S[j] == 'G':
            if S[i] == 'R':
                cnt += sum_b
                if check_index < N:
                    cnt -= B[check_index]
            if S[i] == 'B':
                cnt += sum_r
                if check_index < N:
                    cnt -= R[check_index]
        else:
            if S[i] == 'R':
                cnt += sum_g
                if check_index < N:
                    cnt -= G[check_index]
            if S[i] == 'G':
                cnt += sum_r
                if check_index < N:
                    cnt -= R[check_index]
print(cnt)
### BUGGY CODE ###

h,n=map(int,input().split())
a,b=[],[]
for i in range(n):
    a_sub,b_sub=map(int,input().split())
    a.append(a_sub)
    b.append(b_sub)
inf=10000000000000
ma=max(a)
dp=[inf]*(h+1+ma)
dp[0]=0
for i in range(n):
    x=[a[i],b[i]]
    for j in range(h):
        if dp[j]!=inf:
            if j+x[0]<=h+ma:
                dp[j+x[0]]=min(dp[j+x[0]],dp[j]+x[1])
            else:
                break
print(min(dp[h:]))


### FIXED CODE ###

h,n=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
ab.sort(reverse=True)
inf=1000000000
ma=ab[0][0]
dp=[inf]*(h+1+ma)
dp[0]=0
for i in range(n):
    x=ab[i]
    for j in range(h):
        if dp[j]!=inf:
            if j+x[0]<=h+ma:
                if j+x[0]>=h:
                    dp[h]=min(dp[h],dp[j]+x[1])
                else:
                    dp[j+x[0]]=min(dp[j+x[0]],dp[j]+x[1])
            else:
                break
print(dp[h])
### BUGGY CODE ###

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

# dp[i] := 足場iに来るのにかかる最小のコスト
INF = 10**18
dp = [INF] * N
dp[0] = 0
for i in range(1, N):
    for j in range(1, K + 1):
        idx = i - j
        if idx < 0:
            continue
        v = dp[idx] + abs(H[i] - H[idx])
        dp[i] = min(dp[i], v)
# print('dp', dp)
ans = dp[-1]
print(ans)


### FIXED CODE ###

N, K = map(int, input().split())
H = list(map(int, input().split()))
H = [H[0]] * K + H

# dp[i] := 足場iに来るのにかかる最小のコスト
INF = 10**18
dp = [INF] * (K + N)
dp[0] = 0
for i in range(K, N + K):
    h = H[i]
    dp[i] = min(x + abs(y - h) for x, y in zip(dp[i - K:i], H[i - K:i]))
#     for j in range(1, K + 1):
#         v = dp[i - j] + abs(H[i] - H[i - j])
#         dp[i] = min(dp[i], v)
# print('dp', dp)
ans = dp[-1]
print(ans)
### BUGGY CODE ###

import itertools, bisect

N = int(input())
L = list(map(int, input().split()))
L.sort()

ans = 0
for i in range(N):
    for j in range(i+1, N):
        cindex = bisect.bisect_left(L, int(L[i]) + int(L[j]))
        for _ in reversed(range(j+1, cindex)):
            ans += 1

print(ans)

### FIXED CODE ###

import itertools, bisect

N = int(input())
L = list(map(int, input().split()))
L.sort()

ans = 0
for i in range(N):
    for j in range(i+1, N):
        cindex = bisect.bisect_left(L, int(L[i]) + int(L[j]))
        ans += cindex-1 - j

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

x, y = map(int, input().split())
if x == y:
    print(-1)
elif y == 1:
    print(-1)
else:
    cnt = x+1
    for i in range(cnt, 10**9):
        if i % x == 0:
            if not i % y == 0:
                print(i)
                exit()


### FIXED CODE ###

x, y = map(int, input().split())
if x % y == 0:
    print(-1)
else:
    print(x)
### BUGGY CODE ###

N,K=map(int,input().split())
A=list(map(int,input().split()))
F=list(map(int,input().split()))
A.sort()
F.sort(reverse=True)

def judge(x):
    res=K
    for n in range(N):
        over=max(A[n]*F[n]-x,0)
        res-=-(-over//F[n])
    return res>=0

left=-1
right=10**12*+1
while left+1<right:
    mid=(left+right)//2
    if judge(mid):
        right=mid
    else:
        left=mid
print(right)

### FIXED CODE ###

import numpy as np

N,K=map(int,input().split())
A=list(map(int,input().split()))
F=list(map(int,input().split()))
A.sort()
F.sort(reverse=True)

A=np.array(A)
F=np.array(F)

def judge(x):
    over=np.maximum(A*F-x,0)
    shug=-(-over//F).sum()
    return shug<=K

left=-1
right=10**12*+1
while left+1<right:
    mid=(left+right)//2
    if judge(mid):
        right=mid
    else:
        left=mid
print(right)
### BUGGY CODE ###

s = list(input())
x = ["x"]
if len(s) == 1:
  print(0)
  exit()
ans = 0
while len(s) > 1:
  if s[0] == s[-1]:
    s = s[1:len(s)-1]
  else:
    if s[0] == "x":
      s = s + x
      ans += 1
    elif s[-1] == "x":
      s = x + s
      ans += 1
    else:
      print(-1)
      exit()
print(ans)

### FIXED CODE ###

s = input()
if len(s) == 1:
  print(0)
  exit()
l = 0
r = len(s) - 1
cnt = 0
while l < r:
  if s[l] == s[r]:
    l += 1
    r -= 1
  else:
    if s[l] == "x":
      l += 1
      cnt += 1
    elif s[r] == "x":
      r -= 1
      cnt += 1
    else:
      print(-1)
      exit()
print(cnt)
### BUGGY CODE ###

s = input()
t = input()

s_len = len(s)

def index_list(char):
    word = s
    ret = list()
    sum = 0
    try:
        while True:
            index = word.index(char)+ 1        
            sum+=index
            ret.append(sum)
            word = word[index:]
    except:
        if sum == 0:
            ret.append(-1)
    return ret

alpha_dict = dict()
for char in 'abcdefghijklmnopqrstuvwxyz':
    alpha_dict[char] = index_list(char)

index_old = 0
n_s = 0
for char in t:
    index = alpha_dict[char]
    
    if index[0] == -1:
        index_old = -1
        break
    
    flg = True
    for i in index:
        if i>index_old:
            index_old = i
            flg =False
            break
    if flg:
        index_old = index[0]
        n_s += 1

if index_old == -1:
    print(-1)
else:
    print(n_s*s_len + index_old)
        

### FIXED CODE ###

import sys
s = input()
t = input()
tset = set(t)
slen = len(s)
if len(tset - set(s)) != 0:
    print(-1)
    sys.exit()
s2t = [i - ord('a') for i in (s + s).encode('ascii')]
lut = [[-1 for _ in range(slen)] for _ in range(26)]
for c in tset:
  b = ord(c) - ord('a')
  j = 0
  for i in range(slen * 2 - 1, -1, -1):
    if s2t[i] == b:
      j = 0
    else:
      j += 1
    if i < slen:
      lut[b][i] = j
p = 0
for c in t:
  b = ord(c) - ord('a')
  p += lut[b][p % slen] + 1
print(p)
### BUGGY CODE ###

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

event=[]
for _ in range(n):
    s,t,x=map(int,input().split())
    event.append([s-x,1,x])
    event.append([t-x,-1,x])
event.sort()
d=[int(input()) for _ in range(q)]

k=0
stop=set()
hq=[]
for i in range(q):
    while k<2*n and event[k][0]<=d[i]:
        x=event[k][2]
        if event[k][1]==1:
            heapq.heappush(hq,x)
            stop.add(x)
        else:
            stop.remove(x)
        k+=1
    while hq and hq[0] not in stop:
        heapq.heappop(hq) 
    print(hq[0] if hq else -1)

### FIXED CODE ###

def main():
    from heapq import heappush, heappop
    import sys
    sys.setrecursionlimit(10 ** 7)

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

    event=[]
    for _ in range(n):
        s,t,x=map(int,input().split())
        event.append((s-x,1,x))
        event.append((t-x,-1,x))

    for i in range(q):
        event.append((int(input()),2,i))
    event.sort()

    ans=[0]*q

    stop=set()
    hq=[]
    for t,op,x in event:
        if op==1:
            heappush(hq,x)
            stop.add(x)
        elif op==-1:
            stop.remove(x)

        else:
            while hq and hq[0] not in stop:
                heappop(hq) 
            ans[x]=hq[0] if hq else -1
        
    for x in ans:
        print(x)

main()
### BUGGY CODE ###

N, W =  list(map(int, input().split()))
w_list = []
v_list = []
dp = []
for _ in range(N):
    w, v = list(map(int, input().split()))
    w_list.append(w)
    v_list.append(v)
    dp.append({})

dp.append({})

for i in range(N + 1):
    for w in range(0, W + 1):
        dp[i][w] = 0


for i in range(N):
    for j in range(W + 1):
        sum_w = j
        if sum_w - w_list[i] >= 0:
            dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w - w_list[i]] + v_list[i])
        dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w])

print(max(max(x.values()) for x in dp))


### FIXED CODE ###

def main():
    N, W =  list(map(int, input().split()))

    dp = [-1] * (W + 1)
    dp[0] = 0

    for _ in range(N):
        w, v = map(int, input().split())
        for i in range(W - w, -1, -1):
            if dp[i] != -1 and dp[i + w] < dp[i] + v:
                dp[i + w] = dp[i] + v

    print(max(dp))

main()
### BUGGY CODE ###

N,x=map(int,input().split())
a=[int(i) for i in input().split()]
b=[[0 for k in range(N)] for i in range(N)]
for k in range(N):
    for i in range(N):
        if k==0:
            b[i][k]=a[i]
        else:
            b[i][k]=min([b[i][k-1],a[i-k]])
ans=sum(a)
for k in range(N):
    tmp=k*x
    for i in range(N):
        tmp+=b[i][k]
    if tmp<ans:
        ans=tmp
print(ans)


### FIXED CODE ###

N,x=map(int,input().split())
a=[int(i) for i in input().split()]
b=[[0 for k in range(N)] for i in range(N)]
for k in range(N):
    for i in range(N):
        if k==0:
            b[i][k]=a[i]
        else:
            b[i][k]=min([b[i][k-1],a[i-k]])
ans=sum(a)
for k in range(N):
    tmp=k*x
    for i in range(N):
        tmp+=b[i][k]
    if tmp<ans:
        ans=tmp
print(ans)
### BUGGY CODE ###

def strKey(key):
    if key == 0:
        return '000'
    if 1<= key <= 9:
        return '00' + str(key)
    if 10<= key <=99:
        return '0' + str(key) 
    return str(key)

N = int(input())
s  = input().strip()

cnt = 0
for key in range(1000):
    key = strKey(key)    #; print(key)
    isFlag = False
    for i0 in range(N-2):
        if isFlag == True:
            break
        if s[i0] == key[0]:
            for i1 in range(i0+1, N-1):
                if isFlag == True:
                    break
                if s[i1] == key[1]:
                    for i2 in range(i1+1, N):
                        if s[i2] == key[2]:
                            cnt += 1     #; print(i0, i1, i2, key)
                            isFlag = True
                            break
                        
print(cnt)            

### FIXED CODE ###

N = int(input())
s  = input().strip()

cnt = 0
for key in range(1000):
    key = '{:0>3}'.format(str(key))    #; print(key)
    i0 = s.find(key[0])
    if 0 <= i0 < N-2:
        i1 = s.find(key[1], i0+1)
        if 0 < i1 < N-1:
            i2 = s.find(key[2], i1+1)
            if i2 != -1:
                cnt += 1
            else:
                continue
        else:
            continue        
    else:
        continue
                                   
print(cnt)
### BUGGY CODE ###

from collections import deque
N, Q = map(int, input().split())
edges = [list(map(int, input().split())) for _ in range(N-1)]
operations = [list(map(int, input().split())) for _ in range(Q)]

edge_map = {}
for i in range(N):
    edge_map[i] = deque([])

for edge in edges:
    a = edge[0]
    b = edge[1]
    edge_map[a-1].append(b-1)
    edge_map[b-1].append(a-1)


counters = [0 for i in range(N)]

for operation in operations:
    p = operation[0]
    x = operation[1]
    counters[p-1] += x


res_list = [counters[i] for i in range(N)]
calculated = [False for i in range(N)]

target = [0]
while len(target) > 0:
    t = target.pop()
    calculated[t] = True
    for child in edge_map[t]:
        if calculated[child]:
            continue
        target.append(child)
        res_list[child] += res_list[t]


ans = " ".join([str(i) for i in res_list])
print(ans)


### FIXED CODE ###

from collections import deque
N, Q = map(int, input().split())
edges = [list(map(int, input().split())) for _ in range(N-1)]
operations = [list(map(int, input().split())) for _ in range(Q)]

edge_map = [[] for i in range(N)]

for edge in edges:
    a = edge[0]
    b = edge[1]
    edge_map[a-1].append(b-1)
    edge_map[b-1].append(a-1)


counters = [0]*N

for operation in operations:
    p = operation[0]
    x = operation[1]
    counters[p-1] += x


res_list = [counters[i] for i in range(N)]
calculated = [False for i in range(N)]

target = [0]
while len(target) > 0:
    t = target.pop()
    calculated[t] = True
    for child in edge_map[t]:
        if calculated[child]:
            continue
        target.append(child)
        res_list[child] += res_list[t]

print(*res_list)
### BUGGY CODE ###

from math import factorial
N = int(input())
A = list(map(int, input().split()))
n = [0] * (2 * 10 ** 5 + 1)
for i in range(N):
    n[A[i]] += 1
for i in range(N):
    n[A[i]] -= 1
    ans = 0
    for j in range(2 * 10 ** 5 + 1):
        if n[j] > 1:
            ans += factorial(n[j]) // 2 // factorial(n[j]-2)
    n[A[i]] += 1
    print(ans)


### FIXED CODE ###

from math import factorial
N = int(input())
A = list(map(int, input().split()))
n = {}
s = 0
for i in range(N):
    if A[i] not in n:
        n[A[i]] = 1
    else:
        n[A[i]] += 1
for j in n:
    if n[j] > 1:
        s += factorial(n[j]) // 2 // factorial(n[j]-2)
for i in range(N):
    print(s-n[A[i]]+1)
### BUGGY CODE ###


def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n=n0()
A=n1()

import numpy as np
d=deque(A)
ans=np.array([0]*n)

for i in range(n):
    if i%2==0:
        ans+=np.array(d)
    else:
        ans-=np.array(d)
    d.append(d.popleft())
print(*ans)

### FIXED CODE ###


def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n=n0()
A=n1()

ans=[0]*n

ans[0]=sum([A[i]*((-1)**i) for i in range(n)])
for i in range(1,n):
    ans[i]=2*A[i-1]-ans[i-1]
print(*ans)
### BUGGY CODE ###

from collections import deque
from heapq import heappush,heapify,heappop
n, m = map(int, input().split())
es = [[] for i in range(n)]
co = [[] for i in range(n)] # 有効辺の向きを逆にした
for i in range(n - 1 + m):
    a, b = map(int, input().split())    
    es[a - 1].append(b - 1)
    co[b - 1].append(a - 1)

v = 0
while co[v]:
    v = co[v][0]

def dijkstra(s):
    prev = [-1] * n  # 経路復元
    INF = -(1 << 32)
    d = [INF] * n  # 頂点sからの最短距離
    v = -1
    que = [(0, s)]
    heapify(que)
    d[s] = 0
    while que:
        p = heappop(que)
        v = p[1]
        if d[v] > -p[0]:
            continue
        for e in es[v]:
            if d[e] < d[v] + 1:
                d[e] = d[v] + 1
                heappush(que, (-d[e], e)) 
                prev[e] = v
    return d, prev
_, parent = dijkstra(v)


for i in parent:
    print(i+1)

### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000000)
input = sys.stdin.readline
n, m = map(int, input().split())
es = [[] for i in range(n)]
co = [[] for i in range(n)] # 有効辺の向きを逆にした
for i in range(n - 1 + m):
    a, b = map(int, input().split())    
    es[a - 1].append(b - 1)
    co[b - 1].append(a - 1)

dp = [-1] * n

def memo(v):
    if dp[v] != -1: #更新済
        return dp[v]
    a = 0
    for i in co[v]:
        a = max(a, memo(i) + 1)
    dp[v] = a
    return a

for i in range(n):
    memo(i)

parent = [0] * n
for v in range(n):
    for e in es[v]:
        if dp[v] + 1 == dp[e]:
            parent[e] = v + 1

for i in parent:
    print(i)
### BUGGY CODE ###

import collections

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

a_processed = []

for i in a:
    a_processed[n:n] = [i-1, i, i+1]

print(a_processed.count(collections.Counter(a_processed).most_common()[0][0]))


### FIXED CODE ###

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

ans_l = [0]*(10**5 + 2)

for i in a:
    ans_l[i-1] += 1
    ans_l[i] += 1
    ans_l[i+1] += 1

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

import numpy as np

n = int(input())
a = list(map(int, input().split()))
sum = 0
x = [-1 for i in range(n)]
for i in range(n):
    if a[i % n] == 0:
        x[i % n] = 0
        x[(i + 1) % n] = 0
i = 0
while (-1 in x):
    if a[i % n] == -1 and a[i + 2] != -1:
        x[i] = a[i] * 2 - a[i + 1] * 2 - x[i + 2]
    i += 1
for i in x:
    print(i,end = "")
    print(" ", end = "")

### FIXED CODE ###

import numpy as np

n = int(input())
a = list(map(int, input().split()))
s = 0
x = [-1 for i in range(n)]
for i in range(1,n):
    if i % 2 == 1:
        s += a[i]
x[0] = sum(a) - s * 2
for i in range(1, n):
    x[i] = a[i - 1] * 2 - x[i - 1]
for i in x:
    print(i,end = "")
    print(" ", end = "")
### BUGGY CODE ###

import collections
import itertools as it
import math
import numpy as np

# A = input()
# A = int(input())
# A = map(int, input().split())
# A = list(map(int, input().split()))
# A = [int(input()) for i in range(N)]
#
# c = collections.Counter()

N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [tuple(map(int, input().split())) for i in range(M)]

cl = collections.Counter(A)
for key in cl:
  BC.append((cl[key], key))

BC = sorted(BC, key=lambda x: -x[1])

c = 0
total = 0
for (n, key) in BC:
  for i in range(n):
    if c < N:
      c += 1
      total += key

print(total)

### FIXED CODE ###

import collections
 
# A = input()
# A = int(input())
# A = map(int, input().split())
# A = list(map(int, input().split()))
# A = [int(input()) for i in range(N)]
#
# c = collections.Counter()
 
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [tuple(map(int, input().split())) for i in range(M)]
 
cl = collections.Counter(A)
BC += [(cl[key], key) for key in cl]
BC = sorted(BC, key=lambda x: -x[1])
 
c = 0
total = 0
for (n, key) in BC:
  if (c + n) < N:
    c += n
    total += key * n
  else:
    total += key * (N - c)
    break

print(total)
### BUGGY CODE ###

import math

def factorization(n):
  divided = n
  prime_factor = []

  for i in range(2, int(math.sqrt(n)//1)+1):
    while divided%i == 0:
      prime_factor.append(i)
      divided //= i
  if divided != 1:
    prime_factor.append(divided)
  
  return prime_factor

Q = int(input())
ans = []
for _ in range(Q):
  counter = 0
  l, r = map(int, input().split())
  for odd in range(l, r+1, 2):
    if len(factorization(odd)) == 1 and len(factorization((odd+1)/2)) == 1:
      counter += 1
  ans.append(counter)

for item in ans:
  print(item)

### FIXED CODE ###

import math

def is_prime(x):
  if x <= 0 or x%1 != 0:
    return False
  elif x == 1:
    return False
  elif x == 2:
    return True
  elif x%2 == 0:
    return False
  else:
    for i in range(3, int(math.sqrt(x)//1)+1, 2):
      if x%i == 0:
        return False
    return True

S = [0] * (10**5+1)
for i in range(1, 10**5+1):
  if is_prime(i) and is_prime((i+1)/2):
    S[i] += 1
  S[i] += S[i-1]

Q = int(input())
for _ in range(Q):
  l, r = map(int, input().split())
  print(S[r] - S[l-1])
### BUGGY CODE ###

N = int(input())
H = list(map(int, input().split()))
max = 0
 
for i in range(N-1):
  cnt = 0
  now = i
  while H[now] >= H[now+1]:
    now += 1
    cnt += 1
    if now >= N-1:
      break
  if max < cnt:
    max = cnt
print(max)

### FIXED CODE ###

N = int(input())
H = list(map(int, input().split()))
H.reverse()
max = 0
cnt = 0
 
for i in range(N-1):
  if H[i] <= H[i+1]:
    cnt += 1
  else:
    cnt = 0
  if cnt > max:
    max = cnt
if cnt > max:
  max = cnt
print(max)
### BUGGY CODE ###

M = 1000000007

def pow(k):
    ans = 1
    for _ in range(k):
        ans *= 2
        ans % M
    return ans

def main():
    n = int(input())
    a = list(map(int, input().split()))
    bit_size = len(bin(max(a))[2:])
    for i in range(n):
        a[i] = bin(a[i])[2:].zfill(bit_size)

    sum = 0
    for i in range(bit_size):
        one = 0
        zero = 0
        for j in range(n):
            if a[j][i] == '1':
                one += 1
            else: 
                zero += 1
        sum += pow(bit_size - i - 1) * (one % M) * (zero % M)
        sum %= M
    print(sum)

if __name__ == '__main__':
    main()



### FIXED CODE ###

M = 1000000007
def pow(k):
    ans = 1
    for _ in range(k):
        ans *= 2
        ans %= M
    return ans

def main():
    n = int(input())
    a = list(map(int, input().split()))
    bit_size = len(bin(max(a))[2:])
    for i in range(n):
        a[i] = bin(a[i])[2:].zfill(bit_size)

    sum = 0
    for i in range(bit_size):
        one = 0
        zero = 0
        for j in range(n):
            if a[j][i] == '1':
                one += 1
            else: 
                zero += 1
        sum += pow(bit_size - i - 1) * (one % M) * (zero % M)
        sum %= M
    print(sum)

if __name__ == '__main__':
    main()