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

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

ml = [0 for _ in range(n)]

while len(set(dl)) != 1 :
    m = max(dl)
    for i in range(n) :
        if dl[i] == m :
            if dl[i-1] >= dl[(i+1)%n] :
                lain = dl[i]-dl[(i+1)%n]
                dl[i-1] -= lain
                dl[i] -= lain
                ml[i] += 2*lain
            else :
                lain = dl[i]-dl[i-1]
                dl[i] -= lain
                dl[(i+1)%n] -= lain
                ml[(i+1)%n] += 2*lain
else :
    for i in range(n) :
        ml[i] += dl[-1]

for i in range(n) :
    print(ml[i],end=" ")

### FIXED CODE ###

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

# m0 + m1 + m2 + m3 + m4 = d0 + d1 + d2 + d3 + d5
# d0 = (m0 + m1)//2
# d1 = (m1 + m2)//2
# d2 = (m2 + m3)//2
# d3 = (m3 + m4)//2
# d4 = (m4 + m0)//2
# m0 =  d0 - d1 + d2 - d3 + d4
# m1 =  d0 + d1 - d2 + d3 - d4
# m2 = -d0 + d1 + d2 - d3 + d4
# m3 =  d0 - d1 + d2 + d3 - d4
# m4 = -d0 + d1 - d2 + d3 + d4   
s = sum(a)
p = [0 for _ in range(n)]
q = [0 for _ in range(n+1)]
for i in range(n) :
    if i>1 :
        p[i] = p[i-2] + a[i-2]
    q[n-i-2] = q[n-i] + a[n-i-1]

print(*[s-2*p[i]-2*q[i] for i in range(n)])
### BUGGY CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin

def enum_prime(m):
    L = range(2, m)
    P = []
    while L[0] ** 2 < m:
        P.append(L[0])
        L = [i for i in L if i % P[-1]]
    return P + L

P = enum_prime(50000)

for line in stdin:
    if line.startswith('0'):
        break
    n = int(line)
    cnt = 0
    if n % 2 == 0:
        for p in P:
            if (n - p) in P:
                cnt += 1
            elif p + p > n:
                break
    elif (n - 2) in P:
        cnt = 1
    print(cnt)

### FIXED CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin

def enum_prime(m):
    L = [True for _ in xrange(m + 1)]
    L[0] = L[1] = False

    for i in xrange(2, m + 1):
        if L[i]:
            for j in xrange(i + i, m + 1, i):
                L[j] = False
            if m < i * i:
                break
    return L

FLAGS = enum_prime(50000)
PRIMES = [i for i, isprime in enumerate(FLAGS) if isprime]

for line in stdin:
    if line.startswith('0'):
        break
    n = int(line)
    n2 = n // 2
    cnt = 0
    if n % 2 == 0:
        for p in PRIMES:
            if p > n2:
                break
            if FLAGS[n - p]:
                cnt += 1
    elif FLAGS[n - 2]:
        cnt = 1
    print(cnt)
### BUGGY CODE ###

def dijkstra(s, n, w, cost):
    # 始点sから各頂点への最短距離
    # n:頂点数,　w:辺の数, cost[u][v] : 辺uvのコスト(存在しないときはinf)
    d = [float("inf")] * n
    used = [False] * n
    d[s] = 0

    while True:
        v = -1
        # まだ使われてない頂点の中から最小の距離のものを探す
        for i in range(n):
            if (not used[i]) and (v == -1):
                v = i
            elif (not used[i]) and d[i] < d[v]:
                v = i
        if v == -1:
            break
        used[v] = True

        for j in range(n):
            d[j] = min(d[j], d[v] + cost[v][j])
    return d


################################
n = int(input())  # n:頂点数　w:辺の数
w = n - 1
cost = [[float("inf") for i in range(n)] for i in range(n)]
# cost[u][v] : 辺uvのコスト(存在しないときはinf この場合は10**10)
for i in range(w):
    x, y, z = map(int, input().split())
    cost[x-1][y-1] = z
    cost[y-1][x-1] = z

q, k = map(int, input().split())
list_XY = [ list(map(int,input().split(" "))) for i in range(q)]

ans = dijkstra(k-1, n, w, cost)

for x, y in list_XY:
    print(ans[x-1]+ans[y-1])

### FIXED CODE ###

import sys
sys.setrecursionlimit(500000)
 
N = int(input())
ABC = [list(map(int, input().split())) for i in range(N-1)]
Q, K = map(int, input().split())
D = [0] * (N+1)
L = [[] for i in range(N+1)]
for a, b, c in ABC:
    L[a].append([b, c])
    L[b].append([a, c])
 
 
def dfs(n, np):
    for nc in L[n]:
        if nc[0] == np:
            continue
        else:
            D[nc[0]] = D[n] + nc[1]
            dfs(nc[0], n)
 
 
dfs(K, 0)
for i in range(Q):
    x, y = map(int, input().split())
    print(D[x] + D[y])
### BUGGY CODE ###

posX,posY=0,0
H,W=map(int,input().split())
while not(H==W==0):
    tile=[[False for i in range(W)] for j in range(H)]
    tileinfo=[['' for i in range(W)] for j in range(H)]
    for i in range(H):
        tileinfo[i]=input().rstrip()
    while True:
        if tileinfo[posX][posY]=='>':
            posX+=1
            continue
        elif tileinfo[posX][posY]=='<':
            posX-=1
            continue
        elif tileinfo[posX][posY]=='v':
            posY+=1
            continue
        elif tileinfo[posX][posY]=='^':
            posY-=1
            continue
        elif tileinfo[posX][posY]=='.':
            print('{} {}'.format(posX,posY))
            break
        if tile[posX][posY]==True:
            print('LOOP')
            break
        else:
            tile[posX][posY]=True

### FIXED CODE ###

H,W=1,1
while True:
    posX,posY=0,0
    H,W=map(int,input().split())
    if (H==W==0)==True:
        break
    tile=[[False for i in range(W)] for j in range(H)]
    tileinfo=[['' for i in range(W)] for j in range(H)]
    for i in range(H):
        tileinfo[i]=input().rstrip()
    while True:
        if tile[posY][posX]==True:
            print('LOOP')
            break
        else:
            tile[posY][posX]=True
        if tileinfo[posY][posX]=='>':
            posX+=1
        elif tileinfo[posY][posX]=='<':
            posX-=1
        elif tileinfo[posY][posX]=='v':
            posY+=1
        elif tileinfo[posY][posX]=='^':
            posY-=1
        elif tileinfo[posY][posX]=='.':
            print('{} {}'.format(posX,posY))
            break
### BUGGY CODE ###

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

ans = 1
for i in range(n):
    ans = ans * a[i]

if ans > 10 ** 18:
    print(-1)
else:
    print(ans)


### FIXED CODE ###

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

if 0 in a:
    ans = 0
else:
    ans = 1
    for i in range(n):
        ans = ans * a[i]
        if ans > 10 ** 18:
            ans = -1
            break
print(ans)
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
total = 0
mod = 10**9+7
for i in range(N):
  for k in range(N):
    if i!=k and i<k:
      total+=(A[i]*A[k])%mod
print(total%(mod)) 

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
total = 0
mod = 10**9+7
an = sum(A)

for i in range(N):
  total+=(an-A[i])*A[i]
s = total//2
print(s%mod)
### BUGGY CODE ###

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

count=0
for l in range(N):
    for r in range(l,N):
        Left=Right=List[l]
        for i in range(l+1,r+1):
            Left=Left^List[i]
            Right+=List[i]
        if Left==Right:
            count+=1

print(count)

### FIXED CODE ###

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

count=0
SumL=SumR=0
R=0
for L in range(N):
    if L>R:
        R=L
    while R<N and SumL^List[R]==SumR+List[R]:
        SumR+=List[R]
        SumL^=List[R]
        R+=1

    SumR-=List[L]
    SumL^=List[L]
    count += R-L

print(count)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

n = int(input())
L = list(map(int, input().split()))
f =True
for i in range(n):
    if L[i] -min(L[i:])>=2:
        print('No')
        f = False
        break
if f==True:
    print('Yes')

### FIXED CODE ###

import sys
import numpy as np
input = sys.stdin.readline
n = int(input())

L = np.array(list(map(int, input().split())))

for i in range(n-1, 0, -1):
    if L[i]-L[i-1] ==-1:
        L[i-1] -=1

if np.all(L ==sorted(L)):
    print('Yes')
else:
    print('No')
### BUGGY CODE ###

N, M = map(int, input().split())

a = 1
b = 1
if N == M:
    for i in range(1,N+1):
        a *= i % 1000000007
    b = a

elif N - M == 1:
    for i in range(1,M+1):
        b *= i % 1000000007
    a = b * N 
elif M - N == 1:
    for i in range(1,N+1):
        a *= i % 1000000007
    b = a * M 
    

if abs(N-M) == 1:
    ans = a * b %1000000007
elif N == M:
    ans = 2*a*b % 1000000007
else:
    ans = 0

print(ans)

### FIXED CODE ###

import math
import time

N, M = map(int, input().split())

st = time.time()

a = math.factorial(N) % 1000000007
b = math.factorial(M) % 1000000007
"""
if N == M:
    for i in range(1,N+1):
        a *= i % 1000000007
    b = a

elif N - M == 1:
    for i in range(1,M+1):
        b *= i % 1000000007
    a = b * N 
elif M - N == 1:
    for i in range(1,N+1):
        a *= i % 1000000007
    b = a * M 
"""

if abs(N-M) == 1:
    ans = a * b %1000000007
elif N == M:
    ans = 2*a*b % 1000000007
else:
    ans = 0

print(ans)

ed = time.time() -st
#print(ed)
### BUGGY CODE ###

#!/usr/bin/env pypy3

import sys
import math
import itertools
import bisect

INF = int(1e18)

def main():
    n, t = map(int, sys.stdin.readline().split())

    nzshops = []
    zshops = []
    for _ in range(n):
        a, b = map(int, sys.stdin.readline().split())
        (zshops if a == 0 else nzshops).append((a, b))

    nzshops.sort(key=lambda x: x[0] / (x[0] + x[1] + 1), reverse=True)
    zshops.sort()

    dp = [0]
    for i in range(len(nzshops)):
        a, b = nzshops[i]
        dp.append(INF)
        for c in range(len(dp) - 1, 0, -1):
            x = dp[c - 1] + 1
            dp[c] = min(dp[c], x + x * a + b)
        dp = [x for x in dp if x <= t]

    rs = list(itertools.accumulate(1 + b for _, b in zshops))
    ans = max(c + bisect.bisect(rs, t - dp[c])
            for c in range(len(dp)) if dp[c] <= t)

    print(ans)

if __name__ == '__main__':
    main()

### FIXED CODE ###

#!/usr/bin/env pypy3

import sys
import math
import itertools
import bisect

INF = int(1e18)
T_MAX = int(1e9)

def main():
    N, T = map(int, sys.stdin.readline().split())
    shops = [tuple(map(int, sys.stdin.readline().split())) for _ in range(N)]

    nzshops = [(a, b) for a, b in shops if a > 0]
    zshops  = [(a, b) for a, b in shops if a == 0]

    nzshops.sort(key=lambda x: x[0] / (x[0] + x[1] + 1), reverse=True)
    zshops.sort()

    dp = [[0] + [INF] * int(math.log(T_MAX, 2)) for _ in range(len(nzshops) + 1)]
    for i in range(1, len(dp)):
        for c in range(1, len(dp[i])):
            a, b = nzshops[i - 1]
            t = dp[i - 1][c - 1] + 1
            dp[i][c] = min(dp[i - 1][c], t + t * a + b)

    rs = list(itertools.accumulate(1 + b for _, b in zshops))
    ans = max(c + bisect.bisect(rs, T - dp[-1][c])
            for c in range(len(dp[-1])) if dp[-1][c] <= T)

    print(ans)

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

def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    print(0, flush=True)
    sys.stdout.flush()
    s = input().strip()
    ls, rs = s, s
    l, r = 0, N
    while s != 'Vacant':
        m = (l + r) // 2
        print(m, flush=True)
        s = input().strip()
        if (m - l) % 2 == 0 and s != ls:
            r = m
        elif (m - l) % 2 == 1 and s == ls:
            r = m
        elif (r - m) % 2 == 0 and s != rs:
            l = m
        elif (r - m) % 2 == 1 and s == rs:
            l = m

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    print(0, flush=True)
    s = input().strip()
    if s == 'Vacant':
        return True
    ls, rs = s, s
    l, r = 0, N
    while True:
        m = (l + r) // 2
        print(m, flush=True)
        s = input().strip()
        if s == 'Vacant':
            return True
        if (m - l) % 2 == 0 and s != ls:
            r = m
            rs = s
        elif (m - l) % 2 == 1 and s == ls:
            r = m
            rs = s
        elif (r - m) % 2 == 0 and s != rs:
            l = m
            ls = s
        elif (r - m) % 2 == 1 and s == rs:
            l = m
            ls = s

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

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

root = {i:i for i in range(1, N+1)}
find = {idx+1:{n} for idx, n in enumerate(p)}

ans = 0
for i in range(M):
    x_, y_ = list(map(int, input().split()))
    x, y = x_, y_

    while x != root[x]:
        x = root[x]

    while y != root[y]:
        y = root[y]

    if x != y:
        find[x] |= find[y]
        find[y] = None
        root[x_] = root[y_] = root[y] = x

for i in range(1, N+1):
    r = root[i]
    while r != root[r]:
        r = root[r]

    if i in find[r]:
        find[r].remove(i)
        ans += 1
print(ans)

### FIXED CODE ###

def find(x):
    while union[x] != x:
        x = union[x]
        
    return x

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

union = [i for i in range(N+1)]

for i in range(M):
    x, y = map(int, input().split())
    x = find(x)
    while union[y] != y:
        union[y], y = x, union[y]
        
    union[y] = x
    
ans = 0
for idx, n in enumerate(p):
    if idx+1 == n:
        ans += 1
    else:
        x, y = find(idx+1), find(n)
        if x == y:
            ans += 1
        
print(ans)
### BUGGY CODE ###

import collections
N = int(input())
A = list(map(int,input().split()))
C = collections.Counter(A)

ans = {}
key = list(C.keys())
val = list(C.values())

for i in range(len(key)):
    ans[key[i]] = val[i] * (val[i]-1) //2

ans_val = [int(_) for _ in list(ans.values())]

for j in range(N):
    print(sum(ans_val) - (C[A[j]] - 1) )


### FIXED CODE ###

import collections
N = int(input())
A = list(map(int,input().split()))
C = collections.Counter(A)

ans = 0
for i in C.values():
    ans += int(0.5* i * (i-1))
for j in A:
    print(ans-C[j]+1)
### BUGGY CODE ###

import heapq

n,m = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n) :
  a[i] *= -1

for i in range(m) :
  heapq.heapify(a)
  at = -1*(-1*heapq.heappop(a)//2)
  heapq.heappush(a, at)

print(sum(a)*-1)

### FIXED CODE ###

import heapq

n,m = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n) :
  a[i] *= -1

heapq.heapify(a)
for i in range(m) :
  at = -1*(-1*heapq.heappop(a)//2)
  heapq.heappush(a, at)

print(sum(a)*-1)
### BUGGY CODE ###

n = input()
li = list(map(int, input().split()))
count = 0

while(a % 2 == 0 for a in li):
    li = [ a / 2 for a in li]
    count += 1
# a,b = map(int, input().split())
print(count)

### FIXED CODE ###

n = input()
li = list(map(int, input().split()))
count = 0


#all 全ての要素がTrueならTrue
while all(a % 2 == 0 for a in li):
    li = [ a / 2 for a in li]
    count += 1
# a,b = map(int, input().split())
print(count)
### BUGGY CODE ###

s = input()
k = int(input())
for i in range(5*10**15):
    s = s.replace('2','22')
    s = s.replace('3','333')
    s = s.replace('4','4444')
    s = s.replace('5','55555')
    s = s.replace('6','666666')
    s = s.replace('7','7777777')
    s = s.replace('8','88888888')
    s = s.replace('9','999999999')
    s = s[:k]
print(s)

### FIXED CODE ###

s = input()
k = int(input())
cnt = 0
while s[:1] == '1':
    s = s[1:]
    cnt +=1
if k <= cnt:
    print('1')
else:
    print(s[:1])
### BUGGY CODE ###

import sys
import itertools as it

N = int(input()) 

def prime_judge(N):
    if N % 2 == 0 or N % 3 ==0:
        return False
    for i in range(4,N):
        if N % i == 0:
            return False
            break
    if N % 5 == 1 :
        return True
    else: False

a = []
n = 0
p = 2

while True:
    if prime_judge(p):
        if len(a) == N:
            a_p5 = list(it.combinations(a, 5))
            t_sum = 0
            for a_p5i in a_p5:
                if not(prime_judge(sum(a_p5i))):
                    t_sum += 1
            if t_sum == len(a_p5):
                a = list(a)
                a2 = [str(i) for i in a]
                print(" ".join(a2))
                sys.exit()
        a.append(p)
    p += 1

### FIXED CODE ###

import sys

N = int(input()) 

def prime_judge(N):
    if N % 2 == 0 or N % 3 ==0:
        return False
    for i in range(4,N):
        if N % i == 0:
            return False
            break
    if N % 5 == 1 :
        return True
    else: False

a = []
n = 0
p = 2

while True:
    if prime_judge(p):
        if len(a) == N:
            a2 = [str(i) for i in a]
            print(" ".join(a2))
            sys.exit()
        a.append(p)
    p += 1
### BUGGY CODE ###

K, S = map(int, input().split())
ans = 0

for x in range(K+1):
    for y in range(K+1):
        for z in range(K+1):
            if x + y + z == S:
                ans += 1

print(ans)

### FIXED CODE ###

K, S = map(int, input().split())
ans = 0

for x in range(K+1):
    for y in range(K+1):
        if S - (x + y) <= K and S - (x + y) >= 0:
            ans += 1

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

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

limit_sum = sum(sorted(p_list, reverse=True)[:3])

scope_index = -1
max_sum = 0
for p_i in range(len(p_list)):
    now_sum = 0
    for i in range(k):
        if len(p_list) <= (p_i + i):
            break
        now_sum += p_list[p_i + i]

    if limit_sum == now_sum:
        max_sum = now_sum
        scope_index = p_i
        break

    if max_sum < now_sum:
        max_sum = now_sum
        scope_index = p_i

max_scope_list = []
for i in range(k):
    max_scope_list.append(p_list[scope_index + i])

ex = 0
for scope in max_scope_list:
    for num in range(1, scope+1):
        ex += num*1/scope
print(ex)


### FIXED CODE ###

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

scope_index = 0
max_sum = 0
for i in range(k):
    max_sum += p_list[i]

now_sum = max_sum
for p_i in range(k, len(p_list)):
    now_sum -= p_list[p_i - k]
    now_sum += p_list[p_i]

    if max_sum < now_sum:
        scope_index = p_i
        max_sum = now_sum

ex = (max_sum+k)/2
print(ex)
### BUGGY CODE ###

a, b, m = map(int, input().split())
priceOfMicrowaves = list(map(int, input().split()))
priceOfRefrigerators = list(map(int, input().split()))
priceTable = [list(map(int,input().split())) for i in range(m)]
cheepest = priceOfMicrowaves[0] + priceOfRefrigerators[0]
for p in priceOfMicrowaves:
    if p >= cheepest:
        continue
    for q in priceOfRefrigerators:
        if q >= cheepest:
            continue
        if p + q < cheepest:
            cheepest = p + q
for price in priceTable:
    if priceOfMicrowaves[price[0]-1]+priceOfRefrigerators[price[1]-1]-price[2] < cheepest:
        cheepest = priceOfMicrowaves[price[0]-1]+priceOfRefrigerators[price[1]-1]-price[2]
print(cheepest)


### FIXED CODE ###

a, b, m = map(int, input().split())
priceOfMicrowaves = list(map(int, input().split()))
priceOfRefrigerators = list(map(int, input().split()))
priceTable = [list(map(int,input().split())) for i in range(m)]
cheepest = priceOfMicrowaves[0] + priceOfRefrigerators[0]
for price in priceTable:
    if priceOfMicrowaves[price[0]-1]-price[2] >= cheepest:
        continue
    elif priceOfRefrigerators[price[1]-1]-price[2] >= cheepest:
        continue
    elif priceOfMicrowaves[price[0]-1]+priceOfRefrigerators[price[1]-1]-price[2] < cheepest:
        cheepest = priceOfMicrowaves[price[0]-1]+priceOfRefrigerators[price[1]-1]-price[2]
if cheepest > min(priceOfMicrowaves) + min(priceOfRefrigerators):
    cheepest = min(priceOfMicrowaves) + min(priceOfRefrigerators)
print(cheepest)
### BUGGY CODE ###

N = int(input())
A=[]
for i in range(N):
    A.append(int(input()))
for i in range(N):
    a = A.pop(i)
#     print(a,A)
    ans=max(A)
    print(ans)
    A.insert(i,a)

### FIXED CODE ###

import numpy as np
N = int(input())
A = np.array([int(input()) for i in range(N)])

max_index=np.argmax(A)
a_max=int(A[max_index])
a_second=int(np.amax(np.delete(A,max_index)))
A[:]=a_max
A[max_index]=a_second
for a in A:
    print(int(a))
### BUGGY CODE ###

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

x=max(XY)
y=min(XY)
x_dy=x%y

ans=0
for d in range(1,y+1):
    if y%d==0 and x_dy%d==0:
        ans=d

print(ans)

### FIXED CODE ###

def euclidean_alg(x,y):
    while y:
        x,y=y,x%y
    return x

XY=list(map(int,input().split()))
x=max(XY)
y=min(XY)

print(euclidean_alg(x,y))
### BUGGY CODE ###

#16:38
n,m = map(int,input().split())
raw = [[] for _ in range(n)]
root = [1 for _ in range(n)]
for _ in range(n-1+m):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  raw[a].append(b)
  root[b] = 0
for i in range(n):
  if root[i] == 1:
    r = i
    break
inf = 10**6
pre = [-1 for _ in range(n)]
now = [r]
while now:
  last = now
  now = []
  for x in last:
    for y in raw[x]:
      if pre[x] == y:
        continue
      pre[y] = x
      now.append(y)
for x in pre:
  print(x+1)

### FIXED CODE ###

#16:38
n,m = map(int,input().split())
raw = [[] for _ in range(n)]
precnt = [0 for _ in range(n)]
root = [1 for _ in range(n)]
for _ in range(n-1+m):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  raw[a].append(b)
  precnt[b] += 1
  root[b] = 0
for i in range(n):
  if root[i] == 1:
    r = i
    break
pre = [-1 for _ in range(n)]
now = [r]
#print(precnt)
while now:
  last = now
  now = []
  for x in last:
    for y in raw[x]:
      precnt[y] -= 1
      if precnt[y] == 0:
        now.append(y)
      pre[y] = x
#print(pre)
#print(precnt)
for x in pre:
  print(x+1)
### BUGGY CODE ###

import sys

N, Q = map(int, input().split())
 
S = input()
 
lr = [list(map(int, i.split())) for i in sys.stdin]

# for q in range(Q):
#  lr.append(list(map(int, input().split())))
  
for q in lr:
  st = q[0]-1
  en = q[1]
  s = S[st:en]
  print(s.count('AC'))

### FIXED CODE ###

import sys
 
N, Q = map(int, input().split())
 
S = input()
 
lr = [list(map(int, i.split())) for i in sys.stdin]

Sum = [0]

sum_ = 0

for i in range(len(S)-1):
  if S[i] == 'A' and S[i+1] == 'C':
    sum_ += 1
  Sum.append(sum_)

for  q in range(Q):
  ans = Sum[lr[q][1]-1]-Sum[lr[q][0]-1]
  print(ans)
### BUGGY CODE ###

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

for i in range(a, b+1):
    if a <= i <= a + k - 1 or b - k + 1 <= i <= b:
        print(i)

### FIXED CODE ###

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

for i in range(a, b+1):
    if a <= i <= a + k - 1 or b - k + 1 <= i <= b:
        print(i)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys, math, itertools, collections, bisect, heapq
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n,q=map(int,input().split())
# STX=[tuple(map(int,input().split())) for i in range(n)]
# D=[int(input()) for i in range(q)]
event=[]
for i in range(n):
  si,ti,xi = map(int,input().split())
  event.append((si-xi,0,xi))
  event.append((ti-xi,-1,xi))
for i in range(q):
  di=int(input())
  event.append((di,1,di))
event.sort()
hq=[]; S=set()
for time, query, number in event:
  if query == 0:
    heapq.heappush(hq,number)
    S.add(number)
  elif query == -1:
    S.remove(number)
  else:
    while hq and hq[0] not in S:
      heapq.heappop(hq)
    if not hq:
      print(-1)
    else:
      print(hq[0])




### FIXED CODE ###

#!/usr/bin/env python3
import sys, math, itertools, collections, bisect, heapq
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n,q=map(int,input().split())
STX=[tuple(map(int,input().split())) for i in range(n)]
D=[int(input()) for i in range(q)]
event=[]
for si,ti,xi in STX:
  event.append((si-xi,0,xi))
  event.append((ti-xi,-1,xi))
for di in D:
  event.append((di,1,di))
event.sort()
hq=[]; S=set()
for time, query, number in event:
  if query == 0:
    heapq.heappush(hq,number)
    S.add(number)
  elif query == -1:
    S.remove(number)
  else:
    while hq and hq[0] not in S:
      heapq.heappop(hq)
    if not hq:
      print(-1)
    else:
      print(hq[0])