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

def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return(a)


def make_divisors(n):
    divisors = []
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.append(n)
    return divisors


def pri(n):
    if n == 1:
        return 1

    for i in range(2, int(n/2 + 1)):
        if n % i == 0:
            return 0

    else:
        return 1


A, B = map(int, input().split())

C = gcd(A, B)

d = make_divisors(C)
d.append(1)
d = list(set(d))

cnt = 0
for i in d:
    cnt += pri(i)

print(cnt)


### FIXED CODE ###

def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return(a)


def make_divisors(n):
    divisors = []
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.append(n)
    return divisors


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)

    return a


A, B = map(int, input().split())

C = gcd(A, B)

d = prime_factorize(C)
d.append(1)

print(len(list(set(d))))
### BUGGY CODE ###

S = input()[::-1]
rem = [0]*2019

n = 0
d = 0

for s in S:
    n = n%2019 + (int(s)*10**d)%2019
    tmp = n%2019
    rem[tmp] += 1
    d += 1
    
ans = 0
for i in rem:
    ans += ((i*(i-1))//2)

print(ans+rem[0])

### FIXED CODE ###

S = input()[::-1]
rem = [0]*2019

n = 0
d = 1

for s in S:
    n = n%2019 + (int(s)*d)%2019
    tmp = n%2019
    rem[tmp] += 1
    d *= 10
    d %= 2019
    
ans = 0
for i in rem:
    ans += ((i*(i-1))//2)

print(ans+rem[0])
### BUGGY CODE ###

arr = input().split()
n = int(arr[0])
m = int(arr[1])

a = [0] * m
b = [0] * m

mat = [[0] * n for i in range(n)]
path = []
for i in range(m):
    tmp = input().split()
    a[i] = int(tmp[0])
    b[i] = int(tmp[1])
    mat[a[i]-1][b[i]-1] = 1
    if a[i] == 1:
        path.append(b[i]-1)

flag = False
for i in range(len(path)):
        if mat[path[i]][n-1] == 1: 
            flag = True
            break

if flag == True:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')
    

### FIXED CODE ###

arr = input().split()
n = int(arr[0])
m = int(arr[1])

x = []
y = []

for i in range(m):
    a,b = map(int, input().split())
    if a == 1:
        x.append(b)
    if b == n:
        y.append(a)

if len(set(x+y)) < len(x) + len(y):
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')
### BUGGY CODE ###

R, C, K = map(int, input().split())

I = [[0 for j in range(C)] for i in range(R)]
for _ in range(K):
    r, c, v = map(int, input().split())
    I[r-1][c-1] = v   # 0-indexed

dp = [[[0 for k in range(4)]
       for j in range(C+1)] for i in range(R+1)]
for i in range(R):
    for j in range(C):
        for k in range(2, -1, -1):
            dp[i][j][k+1] = max(dp[i][j][k+1], dp[i][j][k]+I[i][j])
        for k in range(4):
            dp[i+1][j][0] = max(dp[i+1][j][0], dp[i][j][k])
            dp[i][j+1][k] = max(dp[i][j+1][k], dp[i][j][k])


# print(*dp, sep=' \n')

ans = 0
for k in range(4):
    ans = max(ans, dp[R-1][C-1][k])
print(ans)


### FIXED CODE ###

import sys
input = sys.stdin.readline

R, C, K = map(int, input().split())

I = [[0]*C for i in range(R)]
for _ in range(K):
    r, c, v = map(int, input().split())
    I[r-1][c-1] = v   # 0-indexed

dp0 = [[0 for j in range(C+1)] for i in range(R+1)]
dp1 = [[0 for j in range(C+1)] for i in range(R+1)]
dp2 = [[0 for j in range(C+1)] for i in range(R+1)]
dp3 = [[0 for j in range(C+1)] for i in range(R+1)]
for i in range(R):
    for j in range(C):
        dp3[i][j] = max(dp3[i][j], dp2[i][j]+I[i][j])
        dp2[i][j] = max(dp2[i][j], dp1[i][j]+I[i][j])
        dp1[i][j] = max(dp1[i][j], dp0[i][j]+I[i][j])
        dp0[i+1][j] = max(dp0[i+1][j], dp0[i][j], dp1[i]
                          [j], dp2[i][j], dp3[i][j])
        dp0[i][j+1] = max(dp0[i][j+1], dp0[i][j])
        dp1[i][j+1] = max(dp1[i][j+1], dp1[i][j])
        dp2[i][j+1] = max(dp2[i][j+1], dp2[i][j])
        dp3[i][j+1] = max(dp3[i][j+1], dp3[i][j])


# print(*dp, sep=' \n')

ans = max(dp0[R-1][C-1], dp1[R-1][C-1], dp2[R-1][C-1], dp3[R-1][C-1])
print(ans)
### BUGGY CODE ###

import sys
 
sys.setrecursionlimit(10 ** 6)
"""
def input():
    return sys.stdin.readline().strip()
"""
def main():
    N,Q = map(int,input().split())
    K = [[] for _ in range(N+1)]
    nums = [0 for _ in range(N+1)]

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

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

    def dfs(now,parent):
        for i in K[now]:
            if i != parent:
                nums[i] += nums[now]
                dfs(i,now)

    dfs(1,0)
    print(*nums[1:])

if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
 
sys.setrecursionlimit(10 ** 6)

def input():
    return sys.stdin.readline().strip()
def main():
    N,Q = map(int,input().split())
    K = [[] for _ in range(N+1)]
    nums = [0 for _ in range(N+1)]

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

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

    def dfs(now,parent):
        for i in K[now]:
            if i != parent:
                nums[i] += nums[now]
                dfs(i,now)

    dfs(1,0)
    print(*nums[1:])

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

X, K, D = map(int, input().split())
for i in range(K):
    if abs(X+D) > abs(X-D):
        X = X-D

    else:
        X = X+D

print(abs(X))

### FIXED CODE ###

X, K, D = map(int, input().split())

num = abs(X)//D
if num >= K:
    X = abs(X) - K*D

else:
    if num%2 == K%2:
        X = abs(X) - D*num
    else:
        X = abs(X) - D*(num+1)
        
print(abs(X))
### BUGGY CODE ###

n = int(input())
a = [int(input()) for i in range(n)]
on = 1
count = 0
on_li = [1]
while True:
    on = a[on-1]
    count += 1
    if on == 2:
        print(count)
        exit()

    if on in on_li:
        print(-1)
        exit()
    else:
        on_li.append(on)

### FIXED CODE ###

n=int(input())
a=[int(input()) for i in range(n)]

c,s=1,a[0]

while s!=2 and c<n:
    c,s=c+1,a[s-1]

print(c if c<n else -1)
### BUGGY CODE ###

from collections import Counter

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

maxA = [0 for _ in range(N + 1)]
minA = [float('inf') for _ in range(N + 1)]

for i, a in enumerate(A):
    minA[i + 1] = min(minA[i], a)
for i, a in enumerate(reversed(A)):
    maxA[-1 - i] = max(maxA[-1 - (i - 1)], a)

maxProfit = 0
for i in range(1, N):
    if maxProfit < maxA[i + 1] - minA[i]:
        maxProfit = maxA[i + 1] - minA[i]

pairs = set([])
for i in range(1, N):
    if maxProfit == maxA[i + 1] - minA[i]:
        pairs.add((minA[i], maxA[i + 1]))

ans = 0
for minVal, maxVal in pairs:
    right = N - 1
    maxCount = 0
    while A[right] != maxVal:
        right -= 1
    for i in range(right):
        if A[i] == minVal:
            maxCount += 1
    left = 0
    minCount = 0
    while A[left] != minVal:
        left += 1
    for i in range(left, N):
        if A[i] == maxVal:
            minCount += 1
    ans += min(maxCount, minCount)

print(ans)

### FIXED CODE ###

from collections import Counter

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

maxA = [0 for _ in range(N + 1)]
minA = [float('inf') for _ in range(N + 1)]

for i, a in enumerate(A):
    minA[i + 1] = min(minA[i], a)
for i, a in enumerate(reversed(A)):
    maxA[-1 - i] = max(maxA[-1 - (i - 1)], a)

maxProfit = 0
for i in range(1, N):
    if maxProfit < maxA[i + 1] - minA[i]:
        maxProfit = maxA[i + 1] - minA[i]

pairs = set([])
for i in range(1, N):
    if maxProfit == maxA[i + 1] - minA[i]:
        pairs.add((minA[i], maxA[i + 1]))

ans = len(pairs)
print(ans)
### BUGGY CODE ###

from collections import deque
h, w = map(int, input().split())
que = deque()

blck = [1] * (w + 2)
data = [blck]
for ln in range(1, h+1):
    line = list(input().rstrip())
    lineN = [0] * (w+2)
    lineN[0] = 1
    lineN[-1] = 1
    for r, letter in zip(range(1, w+1), line):
        if letter == '#':
            lineN[r] = 1
            que.append((ln, r))
    data.append(lineN)
data.append(blck)


count = 0
next = deque()
while len(que) > 0:
    count += 1
    while len(que) > 0:
        r, c = que.popleft()

        r -= 1
        if data[r][c] == 0:
            next.append((r, c))
            data[r][c] = 1

        r += 2
        if data[r][c] == 0:
            next.append((r, c))
            data[r][c] = 1

        r-=1
        c-=1
        if data[r][c] == 0:
            next.append((r, c))
            data[r][c] = 1

        c+=2
        if data[r][c] == 0:
            next.append((r, c))
            data[r][c] = 1
    que, next = next, que

print(count - 1)

### FIXED CODE ###

from collections import deque
H,W = map(int, input().split())
A = 0
dp = [None] * H
mat = [None] * (H*W)
matS = matE = 0
for h in range(H):
    s = list(input())
    for w, x in zip(range(W), s):
        if x == "#":
            mat[matE] = (h, w, 0)
            matE+=1
    dp[h] = s

def search(dp, mat, nH, nW, cnt):
    global matE
    if dp[nH][nW] == ".":
        mat[matE] = (nH, nW, cnt+1)
        matE+=1
        dp[nH][nW] = "#"

while matS < matE:
    h, w, cnt = mat[matS]
    matS += 1

    if h > 0:
        search(dp, mat, h - 1, w, cnt)
    if h < H-1:
        search(dp, mat, h + 1, w, cnt)
    if w > 0:
        search(dp, mat, h , w - 1, cnt)
    if w < W-1:
        search(dp, mat, h , w + 1, cnt)

print(cnt)
### BUGGY CODE ###

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

for i in range(N):
  for j in range(i+1,N):
    p = A[i]*A[j]
    P += p
    
sum = P%(10**9+7)
print(sum)


### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
P = 0
S = sum(A)
m = 10**9+7

for i in range(N):
  S -= A[i]
  P += A[i]*S
  
ans = P%m
print(ans)
### BUGGY CODE ###

from collections import Counter

N = int(input())
A = list(map(int,input().split()))
a = list(set(A))
cc = Counter(A)
dup = [x for x in a if cc[x] > 1]
c_l = [(cc[i]-1)*(cc[i])/2 for i in a]
al = sum(c_l)

# for k in A:
#     if k in dup:
#         print(int(al-cc[k]+1))
#     else :
#         print(int(al))
[print(int(al-cc[k]+1)) if k in dup else print(int(al)) for k in A]

### FIXED CODE ###

from collections import Counter

N = int(input())
A = list(map(int,input().split()))
a = list(set(A))
cc = Counter(A)
dup = set([x for x in a if cc[x] > 1])
c_l = [(cc[i]-1)*(cc[i])/2 for i in a]
al = sum(c_l)

# for k in A:
#     if k in dup:
#         print(int(al-cc[k]+1))
#     else :
#         print(int(al))
[print(int(al-cc[k]+1)) if k in dup else print(int(al)) for k in A]
### BUGGY CODE ###

N, K = list(map(int, input().split()))
P =[]
max_l = 0
max_v = 0
P = list(map(int, input().split()))
for i, p in enumerate(P):
  if i <= N-K:
    #print(P[i:K+i])
    if max_v < sum(P[i:K+i]):
      max_v = sum(P[i:K+i])
      
      max_l = P[i:K+i]
#print(max_v)
ans = 0
for l in max_l:
  ans += (l+1)*l/2/l
print(ans)

### FIXED CODE ###

n,k = map(int, input().split())
P = list(map(int, input().split()))
PP = [(i+1)/2 for i in P]
ans = 0
ttl = 0
for i,p in enumerate(PP):
    ttl += p
    if i >= k:
        ttl -= PP[i-k]
    ans = max(ttl, ans)
print(ans)
### BUGGY CODE ###

na = 1
a = []
b = []
n = int(input())

for i in range(n):
    a.append(int(input()))

for _ in range(n):
    if a[na - 1] in b:
        print(-1)
        break
    else:
        b.append(a[na - 1])
        if a[na - 1] == 2:
            print(len(b))
            break
        na = a[na - 1]

### FIXED CODE ###

na = 0
a = []
b = []
n = int(input())

for i in range(n):
    a.append(int(input()))

for i in range(n):
    b.append(a[na])
    if a[na] == 2:
        print(i + 1)
        break
    na = a[na] - 1
else:
    print(-1)
### BUGGY CODE ###

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

BC = []
for i in range(Q):
    BC.append(list(map(int, input().split())))

for i in range(Q):
    B = [BC[i][1] if l == BC[i][0] else l for l in A]
    print(sum(B))
    A = B

### FIXED CODE ###

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

A_list = [0]*10**5
for i in A:
    A_list[i - 1]+=1

goukei = sum(A)

for i in range(Q):
    B, C = map(int, input().split())
    goukei = goukei + A_list[B - 1] * (C - B)
    print(goukei)
    A_list[C - 1] += A_list[B - 1]
    A_list[B - 1] = 0
### BUGGY CODE ###

N, W = map(int, input().split())
wv = [list(map(int, input().split())) for x in range(N)]
ws = [x[0] for x in wv]
vs = [x[1] for x in wv]

# depthまでの荷物で、value以上になる重さの最小
dp = [[None] * (sum(vs) + 1) for _ in range(N)]
def dfs(value=0, depth=N - 1):
    if value <= 0:
        return 0

    if depth == -1:
        return float("inf")

    if dp[depth][value] is not None:
        return dp[depth][value]

    weight = min(dfs(value, depth - 1), dfs(value - vs[depth], depth - 1) + ws[depth])
    dp[depth][value] = weight
    return weight

for i in range(sum(vs) + 1):
    if dfs(i) > W:
        print(i - 1)
        break
else:
    print(i)


### FIXED CODE ###

N, W = map(int, input().split())
wv = [list(map(int, input().split())) for x in range(N)]
ws = [x[0] for x in wv]
vs = [x[1] for x in wv]

# # depthまでの荷物で、value以上になる重さの最小
dp = [[None] * (sum(vs) + 1) for _ in range(N + 1)]
# def dfs(value=0, depth=N - 1):
#     if value <= 0:
#         return 0
#
#     if depth == -1:
#         return float("inf")
#
#     if dp[depth][value] is not None:
#         return dp[depth][value]
#
#     weight = min(dfs(value, depth - 1), dfs(value - vs[depth], depth - 1) + ws[depth])
#     dp[depth][value] = weight
#     return weight
#
# for i in range(sum(vs) + 1):
#     if dfs(i) > W:
#         print(i - 1)
#         break
# else:
#     print(i)

dp[-1] = [float("inf")] * len(dp[-1])
s = sum(vs)
for depth in range(N):
    for value in range(s + 1):
        if value - vs[depth] >= 0:
            dp[depth][value] = min(dp[depth - 1][value], dp[depth - 1][value - vs[depth]] + ws[depth])
        else:
            dp[depth][value] = min(dp[depth - 1][value], ws[depth])


import bisect
print(bisect.bisect_left(dp[N - 1], W + 1))
### BUGGY CODE ###


N,K = map(int,input().split())
P_List=list(map(int,input().split()))
#print(N,K)
#print(P_List)

def Kitaichi(p):
    result = 0
    for i in range(p):
        result += (i+1)*1/p
    #print(p,result)
    return result

kitaichi_list=[]
for a in range(N):
    kitaichi_list.append(Kitaichi(P_List[a]))

#print(kitaichi_list)

pre_max=0
temp_max=0
max_num=0
for j in range(N-(K-1)):
    for k in range(K):
        #temp_max += P_List[j+k]
        #temp_max += Kitaichi(P_List[j+k])
        temp_max += kitaichi_list[j+k]
    #print(temp_max)

    if pre_max < temp_max:
        pre_max = temp_max
        max_num = j
    temp_max=0

#print('max_num:',max_num)
#result = 0
#for l in range(K):
#    result += Kitaichi(P_List[max_num+l])

#print(result)
print(pre_max)

### FIXED CODE ###


N,K = map(int,input().split())
P_List=list(map(int,input().split()))
#print(N,K)
#print(P_List)

def Kitaichi(p):
    result = 0
    for i in range(p):
        result += (i+1)*1/p
    #print(p,result)
    return result

def Kitaichi2(p):
    return (p+1)*0.5

kitaichi_list=[]
ruisekiwa_list=[]
ruisekiwa=0
for a in range(N):
    kitaichi_list.append(Kitaichi2(P_List[a]))
    ruisekiwa += Kitaichi2(P_List[a])
    ruisekiwa_list.append(ruisekiwa)

#print(kitaichi_list)
#print(ruisekiwa_list)
pre_max=0
temp_max=0
max_num=0
for j in range(N-(K-1)):
    if j == 0:
        temp_max = ruisekiwa_list[j+K-1] - 0
    else:
        temp_max = ruisekiwa_list[j+K-1] - ruisekiwa_list[j-1]
    

    if pre_max < temp_max:
        pre_max = temp_max
    temp_max=0

print(pre_max)
### BUGGY CODE ###

import math
N, D, A = list(map(int, input().split()))
data = []
for _ in range(N):
    x, h = list(map(int, input().split()))
    data.append((x, h))
data = sorted(data, key=lambda x: x[0])

c = 0
for i in range(N):
    x, h = data[i]
    if h <= 0:
        continue

    # 爆破回数
    attack = math.ceil(h / A)
    c += attack

    # 爆破場所
    # x + D
    for j in range(i+1, N):
        _x, _h = data[j]        
        if _x <= x + D + D:
            _h -= A * attack
            data[j] = (_x, _h)
        else:
            break

print(c)

    


### FIXED CODE ###

import math
from collections import deque

N, D, A = list(map(int, input().split()))
data = []
for _ in range(N):
    x, h = list(map(int, input().split()))
    data.append((x, math.ceil(h/A)))
data = sorted(data, key=lambda x: x[0])

c = 0
damage_que = deque()
attack = 0 # 有効なダメージ合計
for i in range(N):
    x, h = data[i]

    # 爆破範囲が届いていなければ削除していく
    while damage_que and x > damage_que[0][0]:
        _, a = damage_que.popleft()
        attack -= a
    
    # 有効な過去の爆破攻撃を受ける
    remain = max(h - attack, 0)
    # 0になるまで爆破    
    attack += remain
    c += remain

    # 爆破回数追加    
    damage_que.append([x+2*D, remain])

print(c)
### BUGGY CODE ###

N = int(input())
num_list = list(map(int, input().split()))
cumulative_sum_list = [0]
c_s = 0
for i in num_list:
    c_s += i
    cumulative_sum_list.append(c_s)
cumulative_sum_list.sort()
cumulative_sum_set = set(cumulative_sum_list)
s = 0
for i in cumulative_sum_set:
    c = cumulative_sum_list.count(i)
    s += c * (c - 1) // 2
print(s)


### FIXED CODE ###

from itertools import accumulate
from collections import Counter

N = int(input())
num_list = list(map(int, input().split()))
cumulative_sum_list = list(accumulate(num_list))
cumulative_sum_list.append(0)

c = Counter(cumulative_sum_list)
s = 0
for i in c.values():
    s += i * (i - 1) // 2
print(s)
### BUGGY CODE ###

n = int(input())
x = int(input(),2)

def popcount(n):
    return bin(n).count("1")

x_pop = popcount(x)
for i in reversed(range(0,n)):
    bit = x^(1<<i)
    if x&(1<<i):
        tmp_pop = x_pop - 1
    else:
        tmp_pop = x_pop + 1
    if tmp_pop == 0:
        print(0)
        continue
    tmp = bit % tmp_pop
    if tmp == 0:
        print(1)
        continue
    cnt = 2
    tmp_pop = popcount(tmp)
    if tmp_pop == 0:
        print(cnt-1)
        continue
    tmp = tmp % tmp_pop
    while tmp > 0:
        cnt += 1
        tmp_pop = popcount(tmp)
        if tmp_pop == 0:
            print(cnt-1)
            continue
        tmp %= tmp_pop
    print(cnt)

### FIXED CODE ###

n = int(input())
s = input()
x = int(s, 2)
pcx = s.count("1")
pc1 = x % (pcx - 1) if pcx > 1 else 0
pc2 = x % (pcx + 1)

def f(j):
    cnt = 0
    while j:
        j %= bin(j).count("1")
        cnt += 1
    return cnt

for i, y in enumerate(s):
    k = n - 1 - i
    if y == "0":
        print(f((pc2 + pow(2, k, pcx + 1)) % (pcx + 1)) + 1)
    elif pcx > 1:
        print(f((pc1 - pow(2, k, pcx - 1)) % (pcx - 1)) + 1)
    else:
        print(0)
### BUGGY CODE ###

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

for i in range(k):
    if a > 0:
        a -= 1
    elif b > 0:
        b -= 1
    else:
        break
print(a,b)
    

### FIXED CODE ###

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

if a + b < k:
    i = 0
    m = 0
elif a <= k:
    i = 0
    m = b - (k-a)
else:
    i = a-k
    m=b
print(i,m)
### BUGGY CODE ###

import numpy as np

# =============================================================================
# s = np.array(input().split()).astype(int)
# =============================================================================
# =============================================================================
# if s.find("A") >= 0 and s.find("B") >= 0:
#     print("Yes")
# else:
#     print("No")
# =============================================================================

# =============================================================================
# N,A,B = s
# 
# print(N//(A+B)*A + np.array([N%(A+B),A]).min())
# =============================================================================

# =============================================================================
# A,B = s
# 
# eight =  100/8
# ten = 100/10
# x1 = A*eight
# x2 = A*ten
# ans = []
# 
# for i in np.arange(0,np.array([x1,x2]).max().astype(int) + 100):
#     if int(i * 1/eight) == A and int(i * 1/ten) == B:
#         ans.append(i)
# if len(ans) == 0:
#     print(-1)
# else:
#     print(np.array(ans).min().astype(int))
# 
# =============================================================================

query = []
front = ""
back = ""
s = input()
q = int(input())
for ss in range(q):
    query.append(input())
for qi in query:
    if len(qi) <= 2:
# =============================================================================
#         tmp = front
#         front = back[::-1]
#         back = front[::-1]
# =============================================================================
        s = s[::-1]
    else:
        _,F,C = qi.split()
        if int(F) == 1:
            s = C + s
          
        elif int(F) == 2:
            s = s + C
            
print(s)
        
        
    


### FIXED CODE ###

from collections import deque

S = input()
Q = int(input())

t = deque(S)
reverse = False
for _ in range(Q):
    query = input()
    if query[0] == '1':
        reverse = not reverse
    elif query[0] == '2':
        _, F, C = query.split()
        if F == '1':
            if reverse:
                t.append(C)
            else:
                t.appendleft(C)
        elif F == '2':
            if reverse:
                t.appendleft(C)
            else:
                t.append(C)
result = ''.join(t)
if reverse:
    result = result[::-1]
print(result)
### BUGGY CODE ###

N = int(input())

def cal(i):
    flagx = True
    count = 0
    x=1
    y=1
    z=1
    while(flagx):
        flagy = True
        while(flagy):
            flagz = True
            while(flagz):
                ans = x**2 + y**2 + z**2 + x*y + y*z + z*x
                if (ans == i):
                    count+=1
                elif (ans > i):
                    flagz = False
                    z -= 1
                z += 1
            y += 1
            if (z == 1):
                flagy = False
            else:
                z = 1
        x += 1
        if (y == 2):
            flagx = False
        else:
            y = 1

    return count

def main():
    for i in range(1, N+1):
        print(cal(i))

if __name__ == '__main__':
    main()

### FIXED CODE ###

n = int(input())

def main():
    ans = [0]*(n+1)
    for x in range(1, 101):
        for y in range(1, 101):
            for z in range(1, 101):
                fn = x**2 + y**2 + z**2 + x*y + y*z + z*x
                if fn > n:
                    break
                else:
                    ans[fn] += 1

    for i in range(1, n+1):
        print(ans[i])

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

from heapq import heappush, heappop

N, M = map(int, input().split())
AB = []

for i in range(N):
  ab = list(map(int, input().split()))
  #Ai > M の仕事はいらない
  if ab[0] <= M:
    AB.append(ab)

#最終日はAi=1の仕事のみ選べる。その前の日はAi<=2, ...
#終わりから考えればよさそう
AB.sort()
hq = []
ans = 0
for i in range(1, M + 1):
  while len(AB) > 0 and AB[0][0] <= i:
    heappush(hq, -1 * AB.pop(0)[1])
  if len(hq) > 0:
    m = -1 * heappop(hq)
    ans += m

print(ans)

### FIXED CODE ###

from heapq import heappush, heappop

N, M = map(int, input().split())
jobs = [[] for _ in range(M)]

for i in range(N):
  ab = list(map(int, input().split()))
  #Ai > M の仕事はいらない
  if ab[0] <= M:
    jobs[ab[0] - 1].append(ab[1])

#最終日はAi=1の仕事のみ選べる。その前の日はAi<=2, ...
#終わりから考えればよさそう
hq = []
ans = 0
for i in range(M):
  for b in jobs[i]:
    heappush(hq, -1 * b)
  if len(hq) > 0:
    m = -1 * heappop(hq)
    ans += m

print(ans)