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

#import pysnooper
import os,re,sys,operator,math,heapq,string
from collections import Counter,deque
from operator import itemgetter
from itertools import accumulate,combinations,groupby
from sys import stdin,setrecursionlimit
from copy import deepcopy

setrecursionlimit(10**6)

def rec(pp,xx):
    for i in range(n):
        if gragh[pp][i]:
            cnt[i]+=xx
            hen[i]-=1
            if tree[i]:
                continue
            if hen[i]<0:
                rec(i,xx)
                break
            rec(i,xx)
    return
n,q=map(int,stdin.readline().rstrip().split())
gragh=[[0]*n for _ in range(n)]
cnt=[0]*n
tree=[0]*n
hen=[0]*n
for i in range(n-1):
    a,b=map(int,stdin.readline().rstrip().split())
    tree[a-1],tree[b-1]=0,1
    hen[a-1]+=1
    gragh[a-1][b-1]=1
for i in range(q):
    p,x=map(int,stdin.readline().rstrip().split())
    cnt[p-1]+=x
    rec(p-1,x)
print(*cnt)

### FIXED CODE ###

#import pysnooper
#import os,re,sys,operator,math,heapq,string
#from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby
from sys import stdin,setrecursionlimit
#from copy import deepcopy

setrecursionlimit(10**6)

def rec(pp,xx=-1):
    for i in gragh[pp]:
        if i==xx:
            continue
        ans[i]+=ans[pp]
        rec(i,pp)

n,q=map(int,stdin.readline().rstrip().split())
ans=[0]*n
gragh=[[]*n for _ in range(n)]
for _ in range(n-1):
    a,b=map(int,stdin.readline().rstrip().split())
    a-=1
    b-=1

    gragh[a].append(b)
    gragh[b].append(a)
for _ in range(q):
    p,x=map(int,stdin.readline().rstrip().split())
    ans[p-1]+=x
rec(0)
print(*ans)
### BUGGY CODE ###

K = int(input())

count = 0
if K < 10 ** 5 + 1:
    for _ in range(1, 3234566667):
        i = list(map(int, list(str(_))))
        for j in range(1, len(i)):
            if abs(i[j] - i[j - 1]) > 1:
                break
        else:
            count += 1
            if count == K:
                print(_)
                quit()


### FIXED CODE ###

from sys import stdin
from collections import deque

K = int(stdin.readline())

deque = deque()
for i in range(1, 10):
    deque.append(i)

for i in range(K - 1):
    s = deque.popleft()
    for j in range(-1, 2):
        add = (s % 10) + j
        if 0 <= add <= 9:
            deque.append(s * 10 + add)

print(deque.popleft())
### BUGGY CODE ###

N,K=map(int,input().split())
A=list(map(int,input().split()))
ans=list()
tmp=1
for i in range(K):
    tmp=tmp*A[i]
for i in range(K,N):
    tmp_old=tmp
    tmp=tmp_old*A[i]//A[i-K]
    if tmp_old<tmp:
        ans.append('Yes')
    else:
        ans.append('No')
for i in ans:
    print(i)

### FIXED CODE ###

N,K=map(int,input().split())
A=list(map(int,input().split()))
ans=list()
for i in range(K,N):
    if A[i-K]<A[i]:
        ans.append('Yes')
    else:
        ans.append('No')
for i in ans:
    print(i)
### BUGGY CODE ###

# 190928 D
from fractions import gcd

def divisor(n): #nの約数を全て求める
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table
def sieve(n):
    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False

    for i in range(2, n+1):
        if is_prime[i-1]:
            j = 2 * i
            while j <= n:
                is_prime[j-1] = False
                j += i
    table = [ i for i in range(1, n+1) if is_prime[i-1]]
    return is_prime, table

A,B = list(map(int,input().split()))
koyaku = gcd(A,B)
kotable = sorted(divisor(koyaku))
isprim, solist = sieve(koyaku)
output = []
for i in range(len(kotable)):
    if kotable[i] in solist:
        output.append(kotable[i])

print(len(output)+1)


### FIXED CODE ###

# 190928 D

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 = list(map(int,input().split()))
soA = prime_factorize(A)
soB = prime_factorize(B)
output = []
for i in range(len(soA)):
    if soA[i] in soB:
        output.append(soA[i])

print(len(list(set(output))) + 1)
### BUGGY CODE ###

n,q=map(int,input().split())
s=input()
c=[i for i in range(n-1) if (s[i]=="A" and s[i+1]=="C")]
d=[list(map(int,input().split())) for i in range(q)]
for i in range(q):
    e=0
    for j in c:
        if d[i][0]-1<=j and j+1<=d[i][1]-1:
            e+=1
    print(e)


### FIXED CODE ###

n,q=map(int,input().split())
s=input()
c1=[1 if (s[i]=="A" and s[i+1]=="C") else 0 for i in range(n-1) ]
#print(c1)
d=[list(map(int,input().split())) for i in range(q)]
c2=[0]*n
for i in range(1,n):
    #print(i)
    c2[i]=c2[i-1]+c1[i-1]
#print(c2)
for i in range(q):
    print(c2[d[i][1]-1]-c2[d[i][0]-1])
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
import itertools


def solve(X: int, Y: int, Z: int, K: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    AB = list( itertools.product(A,B) )

    ABS = list(map(lambda c: sum(c), AB))
    ABS.sort(reverse=True)
    ABS2 = ABS[0:K]

    ABC = list( itertools.product(ABS2,C) )
    ABCS = list(map(lambda c: sum(c), ABC))
    ABCS.sort(reverse=True)

    for k in range(K):
        print(ABCS[k])



# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    Z = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(X) ]  # type: "List[int]"
    B = [ int(next(tokens)) for _ in range(Y) ]  # type: "List[int]"
    C = [ int(next(tokens)) for _ in range(Z) ]  # type: "List[int]"
    solve(X, Y, Z, K, A, B, C)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys
import itertools


def solve(X: int, Y: int, Z: int, K: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    A.sort(reverse=True)
    B.sort(reverse=True)
    C.sort(reverse=True)

    ABC = []
    for x in range(X):
        for y in range(Y):
            if ((x+1)*(y+1)) > K:
                break
            for z in range(Z):
                if ((x+1)*(y+1)*(z+1)) > K:
                    break
                ABC.append(A[x]+B[y]+C[z])

    ABC.sort(reverse=True)

    for k in range(K):
        print(ABC[k])



# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    Z = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(X) ]  # type: "List[int]"
    B = [ int(next(tokens)) for _ in range(Y) ]  # type: "List[int]"
    C = [ int(next(tokens)) for _ in range(Z) ]  # type: "List[int]"
    solve(X, Y, Z, K, A, B, C)

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

n, m = map(int, input().split())
ab_list = []
for i in range(m):
	ab_list.append(list(map(int, input().split())))
first_list = filter(lambda x: x[0] == 1, ab_list)
second_list = filter(lambda x: x[1] == n, ab_list)
f_list = list(map(lambda f:f[1], first_list))
s_list = list(map(lambda f:f[0], second_list))
r = 'IMPOSSIBLE'
for f in f_list:
	if f in s_list:
		r = 'POSSIBLE'
		break
print(r)

### FIXED CODE ###

n, m = map(int, input().split())
ab_list = [0] * m
for i in range(m):
	ab_list[i] = list(map(int, input().split()))
a_list = []
b_list = []
for i in ab_list:
	if i[0] == 1:
		a_list.append(i[1])
	elif i[1] == n:
		b_list.append(i[0])
r = 'POSSIBLE' if set(a_list) & set(b_list) else 'IMPOSSIBLE'
print(r)
### BUGGY CODE ###

n,k = map(int,input().split())
p = list(map(int,input().split()))
e = [0] * (n-k+1)

for i in range(0,n-k+1):
    for j in range(i,i+k):
        e[i] += float(1/2 * (1 + p[j]))

print(max(e))


### FIXED CODE ###

n,k = map(int,input().split())
p = list(map(int,input().split()))
e = [0] * (n-k+1)

for i in range(k):
    e[0] += float(1/2 * (1 + p[i]))
for j in range(n-k):
    e[j+1] = e[j] + float(1/2 * (p[j+k]-p[j]))
print(max(e))
### BUGGY CODE ###

from sys import stdin
import numpy as np
input = stdin.readline

N = int(input())
A_list = list(map(int, input().split()))
ans_list =np.ones(N)
A_list = np.array(A_list)

for i in range(N):
    for j in range(i+1,N):
        if A_list[i] %  A_list[j] == 0:
            ans_list[i] = 0
            if (A_list[j] %  A_list[i] == 0):
                ans_list[j] = 0
        elif A_list[i] ==  A_list[j]:
                ans_list[i] = 0
                ans_list[j] = 0
        elif(A_list[j] %  A_list[i] == 0):
            ans_list[j] = 0
print(int(np.sum(ans_list)))

### FIXED CODE ###

from sys import stdin
import numpy as np
input = stdin.readline

N = int(input())
A_list = list(map(int, input().split()))
# ans_list =np.ones(N)
# A_list = np.array(A_list)

# for i in range(N-1):
#     for j in range(i+1,N):
#         if A_list[i] %  A_list[j] == 0:
#             ans_list[i] = 0
#             if (A_list[j] %  A_list[i] == 0):
#                 ans_list[j] = 0
#         elif(A_list[j] %  A_list[i] == 0):
#             ans_list[j] = 0
# print(int(np.sum(ans_list)))
A_set = list(set(A_list))
maxA =  A_set[-1]
dp = [1] * (( 10 ** 6) + 1)

cntli = [0] * (( 10 ** 6) + 1)
unique =[]
for i in A_list:
    cntli[i] += 1
for i in range((( 10 ** 6) + 1)):
    if cntli[i] == 1:
        unique.append(i)

for elem in A_set:
    for i in range(2 * elem,  10 ** 6 + 1, elem):
        dp[i] = 0

ans = 0
for i in unique:
    if not (dp[i] == 0):
        ans += 1

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

import sys
sys.setrecursionlimit(1000000)

n, q = map(int, input().split())
dic = {}

for _ in range(n - 1):
    a, b = map(int, input().split())
    if not (a in dic):
        dic[a] = []
    dic[a].append(b)

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

for _ in range(q):
    a, b = map(int, input().split())
    v_list[a-1] += b


def add_v(num,value):
    v_list[num] = v_list[num] + value
    if num+1 in dic:
        for root in dic[num+1]:
            add_v(root-1, v_list[num])


add_v(0,0)


print(*v_list)


### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)

n, q = map(int, input().split())
dic = {}

for _ in range(n - 1):
    a, b = map(int, input().split())
    if not (a in dic):
        dic[a] = []
    dic[a].append(b)

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

for _ in range(q):
    a, b = map(int, input().split())
    v_list[a-1] += b

key_list = list(dic.keys())
key_list.sort()

for a in key_list:
    for b in dic[a]:
        v_list[b-1] = v_list[a-1] + v_list[b-1]

print(*v_list)
### BUGGY CODE ###

N, Q = map(int, input().split())
S = input()
ans = []
for i in range(Q):
    l, r = map(int, input().split())
    ans.append(S[l - 1: r].count('AC'))

for i in ans:
    print(i)

### FIXED CODE ###

N, Q = map(int, input().split())
S = input()
lr = [[int(i) for i in input().split()] for i in range(Q)]
check = []
num, cnt = 0, 0

for i in range(N):
    if S[i] == 'A':
        cnt = 1
    elif S[i] == 'C':
        if cnt == 1:
            cnt = 0
            num += 1
    else:
        cnt = 0
    check.append(num)

for l, r in lr:
    print(check[r - 1] - check[l - 1])
### BUGGY CODE ###

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

def main():
  dp=[[0]*(k+1) for _ in range(n+1)]
  mod=1000000007
  #i人目までに0個配る方法は1通り
  for i in range(n+1):
    dp[i][0]=1
  for i in range(1,n+1):
    for j in range(1,k+1):
      tmp=dp[i - 1][j] + dp[i][j - 1]
      if tmp>=mod:
        tmp%=mod
      dp[i][j]=tmp
      if j-a[i-1]-1>=0:
        tmp=dp[i][j]-dp[i-1][j-a[i-1]-1]
        if tmp>=mod:
          tmp%=mod
        dp[i][j]=tmp
    #print(dp)   
  print(dp[n][k])
main()

### FIXED CODE ###

import sys
from itertools import accumulate

def main():
  input=sys.stdin.readline
  n,k=map(int,input().split())
  A=list(map(int,input().split()))
  mod=10**9+7
  dp=[0]*(k+1)
  dp[0]=1
  for a in A:
    dp=list(accumulate(dp))
    #print("accumulated",dp)
    for j,d in enumerate(dp[:k-a],start=a+1):
      dp[j]-=d
    dp=[dpi%mod for dpi in dp]
    #print(dp)
  print(dp[k])
"""
def main():
  dp=[[0]*(k+1) for _ in range(n+1)]
  mod=1000000007
  #i人目までに0個配る方法は1通り
  #for i in range(n+1):
  #  dp[i][0]=1
  for i in range(0,n+1):
    for j in range(0,k+1):
      if i==0 and j==0:
        dp[i][j]=1
        break
      if j==0:
        dp[i][j]=1
        continue
      tmp=dp[i - 1][j] + dp[i][j - 1]
      if tmp>=mod:
        tmp%=mod
      dp[i][j]=tmp
      if j-a[i-1]-1>=0:
        tmp=dp[i][j]-dp[i-1][j-a[i-1]-1]
        if tmp>=mod:
          tmp%=mod
        dp[i][j]=tmp
    #print(dp)   
  print(dp[n][k])"""
main()
### BUGGY CODE ###

S=(input())

Q=int(input())

for _ in range(Q):
    temp=list(input().split())
    if len(temp)==1:
        S=S[::-1]
    else:
        if temp[1]=="1":
            S=temp[2]+S
        else:
            S=S+temp[2]
            
print(S)

### FIXED CODE ###

# coding: utf-8
# Your code here!
from collections import deque
S=list(input())
Q=int(input())
r=0

d=deque(S)

for _ in range(Q):
    temp=list(input().split())
    if len(temp)==1:
        r^=1
    else:
        if r==0:
            if temp[1]=="1":
                d.appendleft(temp[2])
            else:
                d.append(temp[2])
        else:
            if temp[1]=="1":
                d.append(temp[2])
            else:
                d.appendleft(temp[2])
ans=list(d)
print("".join(ans) if r==0 else "".join(ans[::-1]))
### BUGGY CODE ###

import copy

def movable_state(state):
    x, y = None, None
    for i in range(3):
        for j in range(3):
            if state[3*i+j] == 0:
                x, y = i, j
                break

    rsts = []
    for r, c in [(x+1, y), (x-1, y), (x, y+1), (x, y-1)]:
        if 0 <= r and r < 3 and 0 <= c and c < 3:
            rst = copy.copy(state)
            rst[3*x+y], rst[3*r+c] = rst[3*r+c], rst[3*x+y]
            rsts.append(rst)
    return rsts

def hist_check(state, depth):
    for i in range(depth-2, -1, -1):
        for hist in state_history[i]:
            if hist == state:
                return True
    return False

puzzle = []
for i in range(3):
    puzzle.extend(list(map(int, input().split(' '))))
state_history = [[puzzle]]

goal = [1, 2, 3, 4, 5, 6, 7, 8, 0]
exchange_num = 0
depth = 0
still_not = True
while still_not:
    depth += 1
    state_history.append([])
    for hist in state_history[depth-1]:
        next_states = movable_state(hist)
        for next_stat in next_states:
            if hist_check(next_stat, depth): continue
            if next_stat == goal:
                still_not = False
                break
            state_history[depth].append(next_stat)
        if not still_not: break
print(depth)



### FIXED CODE ###

from collections import deque, OrderedDict

class Puzzle:
    def __init__(self, field=None, path=''):
        self.f = field
        self.space = None
        for i in range(9):
            if self.f[i] == 9:
                self.space = i
        self.path = path

    def __lt__(self, pzl): # <
        for i in range(9):
            if self.f[i] == pzl.f[i]:
                continue
            return self.f[i] > pzl.f[i]
        return False

    def __gt__(self, pzl): # >
        for i in range(9):
            if self.f[i] == pzl.f[i]:
                continue
            return self.f[i] < pzl.f[i]
        return False

dx = [-1, 0, 1, 0]
dy = [0, -1, 0, 1]
dir = ['u', 'l', 'd', 'r']

def is_target(pzl):
    for i in range(9):
        if pzl.f[i] != i+1:
            return False
    return True

def bfs(pzl):
    queue = deque([])
    V = {}
    pzl.path = ''
    queue.append(pzl)
    V[str(pzl.f)] = True
    if is_target(pzl): return pzl.path

    while len(queue) != 0:
        u = queue.popleft()
        sx, sy = u.space//3, u.space%3
        for r in range(4):
            tx, ty = sx + dx[r], sy + dy[r]
            if tx < 0 or ty < 0 or tx >= 3 or ty >= 3:
                continue
            v = Puzzle(field=[u.f[i] for i in range(9)], path=u.path)
            v.f[u.space], v.f[tx*3+ty] = v.f[tx*3+ty], v.f[u.space]
            v.space = tx*3 + ty
            if str(v.f) not in V:
                V[str(v.f)] = True
                v.path += dir[r]
                if is_target(v): return v.path
                queue.append(v)
    return 'unsolvable'

field = []
for i in range(3):
    field.extend(list(map(int, input().split(' '))))

for i in range(9):
    if field[i] == 0: field[i] = 9

pzl = Puzzle(field=field)
ans= bfs(pzl)
print(len(ans))
### BUGGY CODE ###

import sys
def input():
	return sys.stdin.readline()

N, Q = map(int, input().split())
S = input()
p = []
for _ in range(Q):
	p.append(tuple([int(_)-1 for _ in input().split()]))

def changeS(S):
	S_ = ['_'] * N
	for i in range(N-1):
		if S[i] == 'A' and S[i+1] == 'C':
			S_[i] = 'A'
	return S_

def cntdivS(S_, pi):
	return S_[pi[0]:pi[1]].count('A')

S_ = changeS(S)

for pi in p:
	print(cntdivS(S_, pi))

### FIXED CODE ###

import sys
def input():
	return sys.stdin.readline()

N, Q = map(int, input().split())
S = input()
p = []
for _ in range(Q):
	p.append(tuple([int(_)-1 for _ in input().split()]))

L = [0] * N
l = 0

for i in range(N-1):
	if S[i] == 'A' and S[i+1] == 'C':
		l += 1
	L[i] = l

for i in range(Q):
	print(L[p[i][1]-1] - L[p[i][0]-1])
### BUGGY CODE ###

#!/usr/bin/env python
from collections import deque

def main():
    n, q = map(int, input().split())
    link = [[] for _ in range(n+1)]
    for _ in range(n-1):
        a, b = map(int, input().split())
        link[a].append(b)
        link[b].append(a)
    manip = [list(map(int, input().split())) for _ in range(q)]

    child = [[] for _ in range(n+1)]
    parent = [0 for _ in range(n+1)]
    unchecked = [True for _ in range(n+1)]
    unchecked[1] = False
    que = deque([1])
    while que:
        p = que.popleft()
        for l in link[p]:
            if unchecked[l]:
                unchecked[l] = False
                child[p].append(l)
                parent[l] = p
                que.append(l)

    cnt = [0 for _ in range(n+1)]
    for m in manip:
        node, x = m
        cnt[node] += x

    que = deque([1])
    while que:
        node = que.pop()
        cnt[node] += cnt[parent[node]]
        que.extend(child[node])

    print(' '.join(map(str, cnt[1:])))

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python
from collections import deque

def main():
    n, q = map(int, input().split())
    link = [[] for _ in range(n+1)]
    for _ in range(n-1):
        a, b = map(int, input().split())
        link[a].append(b)
        link[b].append(a)
    manip = [list(map(int, input().split())) for _ in range(q)]

    cnt = [0 for _ in range(n+1)]
    for m in manip:
        node, x = m
        cnt[node] += x

    parent = [0 for _ in range(n+1)]
    unchecked = [True for _ in range(n+1)]
    unchecked[1] = False
    que = deque([1])
    while que:
        node = que.pop()
        for l in link[node]:
            if unchecked[l]:
                unchecked[l] = False
                cnt[l] += cnt[node]
                que.append(l)

    print(' '.join(map(str, cnt[1:])))

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

a, b, c, k = map(int, input().split())
sum = 0
for i in range(min(a, k)):
    sum += 1
if k-a-b > 0:
    for i in range(min(k-a-b, c)):
        sum += -1
print(sum)


### FIXED CODE ###

a, b, c, k = map(int, input().split())
sum = k
if k > a:
    sum = a
    if k-a <= b:
        sum = a
    else:
        sum = 2*a+b-k
print(sum)
### BUGGY CODE ###

S = str(input())
T = str(input())

dp = [[0] * (len(T) + 1) for _ in range(len(S) + 1)]

for i in range(len(S)):
    for j in range(len(T)):
        if S[i] == T[j]:
            dp[i + 1][j + 1] = dp[i][j] + 1
        else:
            dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j])

lst = []

N = i + 1
M = j + 1
while (N - 1) >= 0 and (M - 1) >= 0:
    if S[N - 1] == T[M - 1]:
        lst.append(S[N - 1])
        N -= 1
        M -= 1
    else:
        if dp[N][M] == dp[N - 1][M]:
            N -= 1
        else:
            M -= 1

print (*lst[::-1], sep = '')

### FIXED CODE ###

S = str(input())
T = str(input())

dp = [[0] * (len(T) + 1) for _ in range(len(S) + 1)]

for i in range(len(S)):
    for j in range(len(T)):
        if S[i] == T[j]:
            dp[i + 1][j + 1] = dp[i][j] + 1
        else:
            dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j])

lst = []

N = i + 1
M = j + 1
while (N - 1) >= 0 and (M - 1) >= 0:
    if S[N - 1] == T[M - 1]:
        lst.append(S[N - 1])
        N -= 1
        M -= 1
    else:
        if dp[N][M] == dp[N - 1][M]:
            N -= 1
        else:
            M -= 1

print (*lst[::-1], sep = '')
### BUGGY CODE ###

from collections import deque

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

head = 1
for _ in range(Q):
    cmd = input()
    if cmd == "1":
        head *= -1
    elif "2 1" == cmd[:3]:
        if head == 1:
            S.appendleft(cmd[4])
        else:
            S.append(cmd[4])
    else:
        if head == 1:
            S.append(cmd[4])
        else:
            S.appendleft(cmd[4])

ans = ""
for _ in range(len(S)):
    if head == 1:
        ans += S.popleft()
    else:
        ans += S.pop()

print(ans)


### FIXED CODE ###

from collections import deque

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

head = 1
for _ in range(Q):
    cmd = input()
    if cmd == "1":
        head *= -1
    elif "2 1" == cmd[:3]:
        if head == 1:
            S.appendleft(cmd[4])
        else:
            S.append(cmd[4])
    else:
        if head == 1:
            S.append(cmd[4])
        else:
            S.appendleft(cmd[4])

ans = ""
for _ in range(len(S)):
    if head == 1:
        ans += S.popleft()
    else:
        ans += S.pop()

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

n,m=map(int,input().split())
ken=[[] for i in range(n+1)]
inf=[[] for i in range(m)]
def f(x):
    m=0
    while x>0:
        m+=1
        x=x//10
    return m

for i in range(m):
    p,y=map(int,input().split())
    inf[i].append(p)
    inf[i].append(y)
    ken[p].append(y)

for i in range(n):
    ken[i+1]=sorted(ken[i+1])
for i in range(m):
    ans=""
    p=inf[i][0]
    y=inf[i][1]
    for j in range(6-f(p)):
        ans+="0"
    ans=ans+str(p)
    x=ken[p].index(y)+1
    for j in range(6-f(x)):
        ans=ans+"0"
    ans=ans+str(x)
    print(ans)
    
    
    
    



    
        
        
        
          


### FIXED CODE ###

n,m=map(int,input().split())
ken=[1 for i in range(n+1)]
inf=[[] for i in range(m)]
def f(x):
    m=0
    while x>0:
        m+=1
        x=x//10
    return m

for i in range(m):
    p,y=map(int,input().split())
    inf[i].append(i+1)
    inf[i].append(p)
    inf[i].append(y)
inf=sorted(inf, key=lambda x: x[2])

for i in range(m):
    inf[i].append(ken[inf[i][1]])
    ken[inf[i][1]]+=1
inf=sorted(inf)


for i in range(m):
    ans=""
    p=inf[i][1]
    y=inf[i][3]
    for j in range(6-f(p)):
        ans+="0"
    ans=ans+str(p)
    
    for j in range(6-f(y)):
        ans=ans+"0"
    ans=ans+str(y)
    print(ans)
### BUGGY CODE ###

a,b,x=map(int,input().split())
print(sum(1 for i in range(a,b+1) if i%x==0))

### FIXED CODE ###

a,b,x=map(int,input().split())
print(b//x-(a-1)//x)