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

import numpy as np
N,X,Y = map(int, input().split())
X -= 1
Y -= 1
D = np.zeros((N,N))
for i in range(N-1):
  for j in range(i+1,N):
    D[i][j] = min(abs(i-j),abs(X-i)+abs(Y-j)+1,abs(Y-i)+abs(X-j)+1) 
for k in range(1,N):
  print (np.count_nonzero(D == k))

### FIXED CODE ###

from collections import defaultdict as dd
N,X,Y = map(int, input().split())
D = dd(int)
for i in range(1,N):
  for j in range(i+1,N+1):
    D[min(abs(i-j),abs(X-i)+abs(Y-j)+1,abs(Y-i)+abs(X-j)+1)] += 1 
for k in range(1,N):
  print (D[k])
### BUGGY CODE ###

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

a = []
b = []
num_attack = 0

for _ in range(N):
	a_i, b_i = map(int, input().split())
	a.append(a_i)
	b.append(b_i)

Strong_b = [b_i for b_i in b if b_i > max(a)]

while sum(Strong_b) < H :
	H -= max(a)
	num_attack += 1

while H > 0 :
	H -= max(Strong_b)
	max_index = Strong_b.index(max(Strong_b))
	Strong_b[max_index] = 0
	num_attack += 1			 

print(num_attack)


### FIXED CODE ###

import sys
import math
N, H = map(int, input().split())

a = []
b = []
num_attack = 0

for _ in range(N):
	a_i, b_i = map(int, input().split())
	a.append(a_i)
	b.append(b_i)
max_a = max(a)
Strong_b = [b_i for b_i in b if b_i > max_a]

if sum(Strong_b) >= H:
	Strong_b = sorted(Strong_b, reverse = True)
	for i in range(N):
		H -= Strong_b[i]
		if H <= 0:
			print(i+1)
			sys.exit()

H -= sum(Strong_b)
num_attack = len(Strong_b) + math.ceil(H/max_a)
print(num_attack)
### BUGGY CODE ###

from collections import deque

s = deque(list(input()))
q = int(input())

for i in range(q):
  a = list(input().split())
  if a[0] == '1':
    s.reverse()
  elif a[0] == '2':
    if a[1] == '1':
      s.appendleft(a[2])
    elif a[1] == '2':
      s.append(a[2])
      
print(''.join(s))

### FIXED CODE ###

from collections import deque
count = 0
s = deque(list(input()))
q = int(input())

for i in range(q):
  a = list(input().split())
  if a[0] == '1':
    count += 1
    continue
    
  if count%2 == 0:
    if a[0] == '2':
      if a[1] == '1':
        s.appendleft(a[2])
      elif a[1] == '2':
        s.append(a[2])
        
  if count%2 == 1:
    if a[0] == '2':
      if a[1] == '1':
        s.append(a[2])
      elif a[1] == '2':
        s.appendleft(a[2])
      
ans = ''.join(s)
print(ans if count%2 == 0 else ''.join(list(reversed(ans))))
### BUGGY CODE ###

import numpy as np
n = list(map(int, input().split()))
d = np.array(list(map(int, input().split())))

while 1:
    a = (n[0] % 10000) // 1000
    b = (n[0] % 1000) // 100
    c = (n[0] % 100) // 10
    e = n[0] % 10
    f = n[0] // 10000
    
    if np.any(d == f):
        n[0] = f * 10000
    elif np.any(d == a):
        n[0] = f * 10000 + (a + 1) * 1000
    elif  np.any(d == b):
        n[0] = a * 1000 + (b + 1) * 100
    elif np.any(d == c):
        n[0] = a * 1000 + b * 100 + (c + 1) * 10
    elif np.any(d == e):
        n[0] += 1
    else:
        print(n[0])
        break

### FIXED CODE ###

import numpy as np

n = list(map(int, input().split()))
d = np.array(list(map(int, input().split())))
a = len(str(n[0]))
x = np.zeros(a + 1)

for i in range(a + 1):
    x[i] = (n[0] % np.power(10, a - i + 1)) // np.power(10, a - i)

i = 0
while i != a:
    i += 1
    while np.any(d == x[i]):
        x[i] += 1
        if i != a:
            x[i + 1:] = 0
        if x[i] == 10:
            x[i - 1] += 1
            x[i:] = 0
            i -= 1

ans = 0
for i in range(a + 1):
    ans += x[i] * np.power(10, a - i)

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

N, K, Q = map(int,input().split())
a = []
b = [K] * N
for i in range(Q):
    A = int(input())
    a.append(A)

for i in a:
    for j in range(1,N + 1):
        if i != j:
            b[j - 1] -= 1
for i in b:
    if i > 0:
        print('Yes')
    else:
        print('No')






### FIXED CODE ###

N, K, Q = map(int,input().split())
a = []
b = [0] * N
for i in range(Q):
    A = int(input())
    a.append(A)

for i in a:
    b[i - 1] += 1
for i in b:
    if i > Q - K:
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

A, B, K = map(int, input().split())
ans = list()
for num in range(A, B + 1):
    if num < A + K or num > B - K:
        print(num)


### FIXED CODE ###

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

x = b - a
if x < 2 * k:
    for i in range(a, b + 1):
        print(i)
else:
    for i in range(a, a + k):
        print(i)

    for i in range(b - k + 1, b + 1):
        print(i)
### BUGGY CODE ###

import sys
import math
import itertools
import collections
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()

NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()

def main():
    N, M = NMI()
    ab = [NLI() for _ in range(M)]
    
    ENDsorted_sections= sorted(ab, key=lambda x: x[1])
    
    bridge = [1 for _ in range(N-1)]
    
    ans = 0
    section_end = ENDsorted_sections[0][1]#終端ソートしたとき最初の区間の終端
    bridge[section_end-2] = 0#section_end へかかる橋を落とす

    if N == 2:
        ans = 1
    else:
        for m in range(M):
            if bridge[ENDsorted_sections[m][0]-1:ENDsorted_sections[m][1]-1].count(0) == 0:
                bridge[ENDsorted_sections[m][1]-2] = 0
    print(bridge.count(0))

    

if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
import math
import itertools
import collections
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()

NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()

def main():
    N, M = NMI()
    ab = [NLI() for _ in range(M)]
    
    ENDsorted_sections= sorted(ab, key=lambda x: x[1])
    
    ans = 1
    dropped_bridge = ENDsorted_sections[0][1]

    for m in range(M):
        if ENDsorted_sections[m][0] >= dropped_bridge:#新しく橋を落とさないといけない
            ans += 1
            dropped_bridge = ENDsorted_sections[m][1]
    print(ans)    

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

import sys
input = sys.stdin.readline
N = int(input())
S = []
S_append = S.append
for i in range(N):
  data=input()
  if data not in S:
    S_append(data)
print(len(S))

### FIXED CODE ###

N = int(input())
S = list()
for i in range(N):
  x = input()
  S.append(x)
  
A = set(S)
print(len(A))
### BUGGY CODE ###

"""
E-Knapsack2
Wが10**9まであるのでdpの置き方を工夫する。
dp[i]:=価値がiのときのナップザックの重さ
"""
N,W = map(int,input().split())
dp = [0]+[W+1]*(N*10**3)
for i in range(N):
    w,v = map(int,input().split())
    for j in range(N*10**3+1-v)[::-1]:
        dp[j+v] = min(dp[j+v],dp[j]+w)
for i in range(N*10**3+1)[::-1]:
    if dp[i]<=W:
        print(i)
        exit()

### FIXED CODE ###

"""
E-Knapsack2
Wが10**9まであるのでdpの置き方を工夫する。
dp[i]:=価値がiのときのナップザックの重さ
"""
N,W = map(int,input().split())
dp = [0]+[W+1]*(N*10**3)
for i in range(N):
    w,v = map(int,input().split())
    for j in range(N*10**3+1-v)[::-1]:
        dp[j+v] = min(dp[j+v],dp[j]+w)
for i in range(N*10**3+1)[::-1]:
    if dp[i]<=W:
        print(i)
        exit()
### BUGGY CODE ###

def bisect_right_reverse(a, x):
    if a[0] < x:
        return 0
    if x <= a[-1]:
        return len(a)
    ok = len(a) - 1
    ng = 0
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if a[mid] < x:
            ok = mid
        else:
            ng = mid
    return ok

#import bisect
X, Y, A, B, C = map(int, input().split())
red = [int(x) for x in input().split()]
gre = [int(x) for x in input().split()]
non = [int(x) for x in input().split()]
red.sort(reverse=True)
gre.sort(reverse=True)
non.sort()
ans = red[:X] + gre[:Y]
ans.sort(reverse=True)

while non[-1] > ans[-1]:
    c = non[-1]
    index = bisect_right_reverse(ans, c)
    ans.insert(index, c)
    non.pop(-1)
    ans.pop(-1)
    if non == []:
        break
print(sum(ans))

### FIXED CODE ###

X, Y, R, G, N = map(int, input().split())
r = [int(x) for x in input().split()]
g = [int(x) for x in input().split()]
n = [int(x) for x in input().split()]
r = sorted(r)[R-X:]
g = sorted(g)[G-Y:]
n = sorted(n, reverse=True)

nr = 0; ng = 0; nn = 0
for i in range(N):
    if n[nn] <= min(r[nr], g[ng]):
        break
    if r[nr] < g[ng]:
        r[nr] = n[nn]
        nr += 1
        if nr == X:
            nr = X-1
    else:
        g[ng] = n[nn]
        ng += 1
        if ng == Y:
            ng = Y-1
    nn += 1

print(sum(r) + sum(g))
### BUGGY CODE ###

R, C, K = map(int, input().split())
rcvs = [list(map(int, input().split())) for _ in range(K)]

for i in range(len(rcvs)):
    rcvs[i][0] -= 1
    rcvs[i][1] -= 1

rewards = [[0 for _ in range(C)] for _ in range(R)]

for rcv in rcvs:
    rewards[rcv[0]][rcv[1]] = rcv[2]
    
#%%

dp = [[[0 for _ in range(4)] for _ in range(C+1)] for _ in range(R+1)]
answer = 0

for i in range(R):
    for j in range(C):
        reward = rewards[i][j]
        dp[i+1][j+1][0] = max(dp[i][j+1])
        dp[i+1][j+1][1] = dp[i+1][j+1][0] + reward
        
        for k in range(4): # move downside without selecting
            candidate = dp[i+1][j][k]
            dp[i+1][j+1][k] = max(dp[i+1][j][k], dp[i+1][j+1][k])
        for k in range(3):
            dp[i+1][j+1][k+1] = max(dp[i+1][j][k]+reward,dp[i+1][j+1][k+1])
print(max(dp[-1][-1]))

### FIXED CODE ###

import sys
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8
import sys

R, C, K = map(int, input().split())
rcvs = [list(map(int, input().split())) for _ in range(K)]
rcvs = np.array(rcvs, dtype=np.int64)

@njit(i8(i8[:,:]), cache=True)
def main(rcvs):
    rewards = np.zeros((R, C), dtype=np.int64)
    
    for i in range(len(rcvs)):
        rewards[rcvs[i][0]-1][rcvs[i][1]-1] = rcvs[i][2]
    
    dp = np.zeros((R+1, C+1, 4), dtype=np.int64)
    
    for i in range(R):
        for j in range(C):
            reward = rewards[i][j]
            dp[i+1][j+1][0] = max(dp[i][j+1])
            dp[i+1][j+1][1] = dp[i+1][j+1][0] + reward
            
            for k in range(4): # move downside without selecting
                dp[i+1][j+1][k] = max(dp[i+1][j][k], dp[i+1][j+1][k])
            if reward > 0:
                for k in range(3):
                    dp[i+1][j+1][k+1] = max(dp[i+1][j][k]+reward,dp[i+1][j+1][k+1])
    return max(dp[-1][-1])

print(main(rcvs))
### BUGGY CODE ###

N = int(input())
S = [sorted(list(input()))for i in range(N)]
count = 0
for i in range(N):
    for j in range(N):
        if S[i]==S[j]:
            count+=1
print((count-N)//2)

### FIXED CODE ###

N = int(input())
s = [sorted(input()) for _ in range(N)]
s.sort()

cnt = 0
ans = 0
for i in range(N-1):
    if s[i] == s[i+1]:
        cnt +=1
        ans += cnt
    else:
        cnt = 0
print(ans)
### BUGGY CODE ###

import math
n=int(input())
cell = list(map(lambda x: {"B": True, "W": False}[x], input()))
section = 0
ans = 1
flag = True
for val in cell:
    buf = val if section % 2 == 0 else not val
    if buf:
        section += 1
    else:
        if section > 0:
            ans *= section
            section -= 1
        else:
            flag = False
            break
if section== 0 and flag:
    print((math.factorial(n)*ans)%(10**9+7))
else:
    print(0)

### FIXED CODE ###

import math

n = int(input())
cell = map(lambda x: {"B": True, "W": False}[x], input())
section = 0
ans = 1
for val in cell:
    if section % 2 == 0:
        buf = val
    else:
        buf = not val
    if buf:
        section += 1
    else:
        ans *= section
        ans %= 10 ** 9 + 7
        section -= 1
if section == 0:
    print(((math.factorial(n) % (10 ** 9 + 7)) * ans) % (10 ** 9 + 7))
else:
    print(0)
### BUGGY CODE ###

import sys

n = int(input())

ai = []
for i in range(0, n):
    ai.append(int(input()))

count = 0
iter = 0
r = 1

if len(ai) == 1:
    print(ai[0] - 1)
    sys.exit()

while True:
    if iter == 0 and ai[0] > 1:
        ai[0] -= 1
        count += 1
    else:
        while ai[iter] <= r + 1:
            r = max(r, ai[iter])
            iter += 1
            if iter >= len(ai):
                print(count)
                sys.exit()
        if ai[iter] - (r + 1) == r + 1:
            ai[iter] = 1
            count += 1
        else:
            ai[iter] -= r + 1
            count += 1

### FIXED CODE ###

import sys

n = int(input())

ai = []
for i in range(0, n):
    ai.append(int(input()))

count = 0
iter = 0
r = 1

if len(ai) == 1:
    print(ai[0] - 1)
    sys.exit()

while True:
    if iter == 0 and ai[0] > 1:
        count += ai[0] - 1
        ai[0] = 1
    else:
        while ai[iter] <= r + 1:
            r = max(r, ai[iter])
            iter += 1
            if iter >= len(ai):
                print(count)
                sys.exit()
        div = int(ai[iter] / (r + 1))
        mod = ai[iter] % (r + 1)
        if mod == 0:
            count += div - 1
            ai[iter] = 1
        else:
            count += div
            ai[iter] = mod
### BUGGY CODE ###

s = input()
n = len(s)
mod = 1000000007
dp = [[0 for i in range(13)] for j in range(n+1)]
dp[0][0] = 1
s = s[::-1]
dec = 1
for i in range(n):
    x = s[i]
    dec %= 13
    if x != '?':
        x = int(x)
        r = (dec * x) % 13
        for j in range(13):
            dp[i+1][j] = dp[i][(j-r)%13]
    else:
        for j in range(10):
            r = (dec * j) % 13
            for k in range(13):
                dp[i+1][k] += dp[i][(k-r)%13] % mod
    dec *= 10
print(dp[-1][5] % mod)
#print(dp)        

### FIXED CODE ###

s = input()
n = len(s)
mod = 1000000007
dp = [[0 for i in range(13)] for j in range(n+1)]
dp[0][0] = 1
s = s[::-1]
dec = 1
for i in range(n):
    x = s[i]
    dec %= 13
    if x != '?':
        x = int(x)
        r = (dec * x) % 13
        for j in range(13):
            dp[i+1][j] = dp[i][(j-r)%13]
    else:
        for j in range(10):
            r = (dec * j) % 13
            for k in range(13):
                dp[i+1][k] += dp[i][(k-r)%13] % mod
    dec *= 10
print(dp[-1][5] % mod)
#print(dp)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
N=int(input())
L=tuple(map(int,input().split()))
if 1 not in L:
  print(-1)
  sys.exit()
for i in range(1,N+1):
  if i not in L:
    print(N+1-i)
    sys.exit()
  else:
    a=L.index(i)
    L=L[a:]
print(0)

### FIXED CODE ###

N=int(input())
L=list(map(int,input().split()))
i=0
n=1
while True:
  if i==N:
    break
  if L[i]==n:
    n+=1
  i+=1
if n==1:
  print(-1)
else:
  print(N-n+1)
### BUGGY CODE ###

from itertools import combinations,combinations_with_replacement

N = int(input())

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

comb_list = list(combinations(L,3))

ans = 0

for i in range(len(comb_list)):

	a, b, c = comb_list[i]
	if (a < b + c) and (b < a + c) and (c < a + b):
		ans += 1

print(ans)

### FIXED CODE ###

def findnumberofTriangles(arr): 
  
    n = len(arr) 
    arr.sort() 
    count = 0
  
    for i in range(0,n-2): 
   
        k = i + 2
  
        for j in range(i+1,n): 
  
            while (k < n and arr[i] + arr[j] > arr[k]): 
                k += 1
            if(k>j): 
                count += k - j - 1
  
    return count 

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

print(findnumberofTriangles(L))
### BUGGY CODE ###

# -*- coding: utf-8 -*-
from pprint import pprint

MAX_bin = 20
N = int(input())
An = list(map(int, input().split()))

rui = []
bin_rui = [[0 for _ in range(MAX_bin)] for _ in range(N+1)]

tmp = 0
tmp_bin = [0 for _ in range(MAX_bin)]
for i,A in enumerate(An):
    rui.append(A+tmp)
    tmp += A

    binA = bin(A)[2:]
    tmpA = "0"*(MAX_bin - len(binA)) + binA

    for k in range(MAX_bin):
        bin_rui[i+1][k] = tmp_bin[k] + int(tmpA[k])
        tmp_bin[k] += int(tmpA[k])

# 尺取
renzoku = []
cnt = 0
l = 1
r = 1
while l <= N and r <= N:
    bin_l = bin_rui[l-1]
    bin_r = bin_rui[r]
    bin_diff = [0 for _ in range(MAX_bin)]
    # bin_r - bin_l
    for k in range(MAX_bin):
        bin_diff[k] = bin_r[k] - bin_l[k]

    if sum([1 for b in bin_diff if b > 1]) == 0:
        cnt += 1
        r += 1
        if r > N:
            renzoku.append(cnt)
            cnt = 0
            l += 1
            r = l
    else:
        renzoku.append(cnt)
        cnt = 0
        l += 1
        r = l

# pprint(renzoku)
print(sum(renzoku))


### FIXED CODE ###

# -*- coding: utf-8 -*-
N = int(input())
An = list(map(int, input().split()))

# 尺取
ans = 0
l = 0
r = 0
Asum = An[0]
Axor = An[0]
while l < N and r < N:
    if Asum == Axor:
        ans += r-l+1
        r += 1
        if r < N:
            Asum += An[r]
            Axor ^= An[r]
    else:
        if l < N:
            Asum -= An[l]
            Axor ^= An[l]
        l += 1

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

import itertools
#n, k = map(int,input().split())
n = int(input())
al = list(map(int,input().split()))

ans = 0
for v in itertools.product(range(2),repeat=n):
    money = 1000
    kabu = 0

    for i in range(n):
        if v[i] == 0:
            kabu += money // al[i]
            money = money % al[i]
        elif v[i] == 1:
            money += kabu * al[i]
            kabu = 0
        else:
            continue
    ans = max(ans, money)
print(ans)


### FIXED CODE ###

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

kabu = 0
money = 1000
for i in range(n-1):
    if al[i] < al[i+1]:
        # 全部売る
        money += kabu * al[i]
        kabu = 0
        # 全部買う
        kabu += money // al[i]
        money = money % al[i]
    else:
        # 全部売る
        money += kabu * al[i]
        kabu = 0

print(money+ kabu*al[-1])
### BUGGY CODE ###

n = int(input())
x = list(map(int, input().split()))
ans = 0
p = 1
for i in range(1, n):
  p *= i
for i in range(n-1):
  ans += (x[n-1]-x[i])*p//(i+1)
ans %= 1000000007
print(ans)

### FIXED CODE ###

n = int(input())
x = list(map(int, input().split()))
ans = 0
mod = 1000000007
p = 1
for i in range(1, n):
  p *= i
  p %= mod
for i in range(n-1):
  ans += (x[n-1]-x[i])*pow(i+1, mod-2, mod)
ans *= p
ans %= 1000000007
print(ans)
### BUGGY CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
now_sum_val = 1
for i in range(K):
    now_sum_val *= A[i]
for i in range(K, N):
    next_sum_val = now_sum_val // A[i - K] * A[i]
    if next_sum_val > now_sum_val:
        print('Yes')
    else:
        print('No')
    now_sum_val = next_sum_val

### FIXED CODE ###

N, K = map(int, input().split())
A = list(map(int, input().split()))
for i in range(K, N):
    # next_sum_val = now_sum_val // A[i - K] * A[i]
    if A[i] > A[i - K]:
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
cnt = 0

for i in range(N):
  while A[i]%2 == 0:
    cnt += 1

print(cnt)
    

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
cnt = 0
 
for i in range(N):
  while A[i]%2 == 0:
    A[i] = A[i]/2
    cnt += 1
    
print(cnt)
### BUGGY CODE ###

n = int(input())
a = list(map(int,input().split()))
a.sort(reverse = True)
p = 0

for i in range(n):
    j = i + 1
    for j in range(n):
        if i == j:
            pass
        elif a[i] % a[j] == 0:
            break
        else:
            pass
        if j == n - 1:
                p += 1

print(p)

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
m = max(a)
flag = [True]*(m+1)
c = [0]*(m+1)
b = list(sorted(a))
for i in b:
    x = i + i
    while x <= m:
        flag[x] = False
        x += i
    c[i] += 1
ans = 0
x = 0
l = []
ans = 0
for i in a:
    if flag[i] and c[i] <= 1:
        ans += 1
print(ans)
### BUGGY CODE ###

def resolve():
    N = int(input())
    S = list(input())

    ans = 0

    for i in range(N):
        for ii in range(i, N):
            for iii in range(ii, N):
                if ((ii - i) == (iii - ii)):
                    continue
                if (S[i] != S[ii] and S[ii] != S[iii] and S[i] != S[iii]):
                    ans += 1

    print(ans)


resolve()

### FIXED CODE ###

from collections import Counter


def resolve():
    n = int(input())
    s = input()
    cnt = Counter(s)
    ans = cnt['R'] * cnt['G'] * cnt['B']

    for i in range(n - 1):
        for j in range(i + 1, n):
            ken = j * 2 - i
            if (ken >= n):
                continue
            if (s[i] != s[j] and s[j] != s[ken] and s[i] != s[ken]):
                ans -= 1

    print(ans)

resolve()
### BUGGY CODE ###

import math
n=int(input())
b=1
a=list(map(int,input().split()))
for i in range(n):
    b=b*a[i]
x=math.pow(10,18)
if(b>x):
    b=-1
print(b);

### FIXED CODE ###

import math
n=int(input())
b=1
a=list(map(int,input().split()))
x=1000000000000000000
for i in range(n):
    if(a[i]==0):
        print(0)
        exit(0);

for i in range(n):
    b=b*a[i]
    if(b>x):
        print(-1)
        exit(0)

print(b);
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
input = lambda: sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**8)
inf = float('inf')
mod = 10**9+7

def dfs(node):
    for v in G[node]:
        if not visited[v]:
            visited[v]=1
            data[v]+=data[node]
            dfs(v)
    return 0



n,q=map(int,input().split())
G=[[] for i in range(n)]
for i in range(n-1):
    a,b=map(int,input().split())
    a-=1;b-=1
    G[a].append(b)
    G[b].append(a)
data=[0]*n
for i in range(q):
    p,x=map(int,input().split())
    data[p-1]+=x
visited=[0]*n
visited[0]=1
dfs(0)
print(*data)


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**8)
input = lambda: sys.stdin.readline()[:-1]
n,q=map(int,input().split())
ab=[tuple(map(int,input().split())) for i in range(n-1)]
px=[tuple(map(int,input().split())) for i in range(q)]
# ab.sort(key=lambda tup:(tup[0],tup[1]))
visited=[0]*(n+1)
cnt=[0]*(n+1)
data=[[] for i in range(n+1)]

for i in ab:
	data[i[0]].append(i[1])
	data[i[1]].append(i[0])
for j in px:
	cnt[j[0]]+=j[1]
	# print(cnt)
# count=0
def plus(now,value,parent):
	for i in data[now]:
		# global count
		# count+=1
		if i==parent:continue
			
		cnt[i]+=value
		visited[i]=1
		# print(cnt)	
		
		plus(i,cnt[i],now)
		
		
visited[1]=1
plus(1,cnt[1],0)
print(*cnt[1:])
# print(count)

# ans=sorted(cnt.items())
# print(*[i[1] for i in ans])
### BUGGY CODE ###

data = input()
data_list = [c for c in data]
#print(data_list)
count = 1
delete_count = 0
while ('0' in data_list) and ('1' in data_list):
    if data_list[count - 1] != data_list[count]:
        del data_list[count - 1: count + 1]
        delete_count += 2
        count = 1
    else:
        count += 1

print(delete_count)


### FIXED CODE ###

data = input()
data_list = [c for c in data]
# print(data_list)
count = 1
delete_count = 0
number_of_one = data_list.count('1')
number_of_zero = data_list.count('0')

min_num = min(number_of_zero, number_of_one)
print(min_num * 2)
### BUGGY CODE ###

from collections import deque


def main():
    a = input()
    d = deque(a)
    n = int(input())
    for i in range(n):
        j = input().split()
        if len(j) == 3 and j[1] == "1":
            d.appendleft(j[2])
        elif len(j) == 3 and j[1] == "2":
            d.append(j[2])
        else:
            d.reverse()
    ans = ""
    for j in d:
        ans = ans + j
    print(ans)


if __name__ == '__main__':
    main()

### FIXED CODE ###

from collections import deque
import sys
sys.setrecursionlimit(10 ** 7)
readline = sys.stdin.readline


def main():
    a = input()
    d = deque(a)
    n = int(input())
    flagr = 1
    for i in range(n):
        j = list(readline().split())
        if len(j) == 3 and j[1] == "1" and flagr == 1:
            d.appendleft(j[2])
        elif len(j) == 3 and j[1] == "2" and flagr == 1:
            d.append(j[2])
        elif len(j) == 3 and j[1] == "2" and flagr == -1:
            d.appendleft(j[2])
        elif len(j) == 3 and j[1] == "1" and flagr == -1:
            d.append(j[2])
        else:
            flagr *= -1
    if flagr == -1:
        d.reverse()
    ans = ""
    for j in d:
        ans = ans + j
    print(ans)


if __name__ == '__main__':
    main()