Harryxun/stf_run huggingface dataset:
n,x,m=map(int,input().split())
a=[0]*(m+2)
cnt=[0]*(m+2)
a[1],f=x,x
cnt[f]=1
for i in range(2,m):
  f=f*f%m
  a[i]=f
  if cnt[f]==0:
    cnt[f]=1
  else:
    break
ind=a[1:].index(f)+1
ans=sum(a[:ind])+sum(a[ind:i])*((n-ind+1)//(i-ind))
p=(n-ind+1)%(i-ind)
ans+=sum(a[ind:ind+p])
print(ans)

### FIXED CODE ###

import sys
n,x,m=map(int,input().split())
a=[0]*(m+2)
cnt=[0]*(m+2)
a[1],f=x,x
cnt[f]=1
if x==0:
  print(0)
  sys.exit()
for i in range(2,m+1):
  f=f*f%m
  a[i]=f
  if cnt[f]==0:
    cnt[f]=1
  else:
    break
ind=a[1:].index(f)+1
ans=sum(a[:ind])+sum(a[ind:i])*((n-ind+1)//(i-ind))
p=(n-ind+1)%(i-ind)
ans+=sum(a[ind:ind+p])
print(ans)
import sys
sys.setrecursionlimit(10000)

N = int(input())
H = [-1] + list(map(int, input().split()))

def func(i):
    if i == 0:
        return 0
    else:
        if i - 2 < 0:
            return 0
        elif i - 1 < 0:
            return 0
        elif i > N:
            return 0
        else:
            return min((func(i-1)+abs(H[i-1]-H[i]), func(i-2)+abs(H[i-2]-H[i])))

print(func(N))

### FIXED CODE ###

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

dp = [0] * N
dp[1] = abs(H[1]-H[0])
for i in range(2, N):
    dp[i] = min((dp[i-1]+abs(H[i-1]-H[i]), dp[i-2]+abs(H[i-2]-H[i])))

print(dp[N-1])
W,a,b = map(int,input().split())
start = max(a, b)
end = min(a+W, b+W)
print(max(start-end), 0)


### FIXED CODE ###

W,a,b = map(int,input().split())
start = max(a, b)
end = min(a+W, b+W)
print(max(start-end, 0))
x = input()
if int(x) % (int(x[0])+int(x[1])) == 0:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

x = input()
c = 0
for i in range(len(x)):
  c += int(x[i])
if int(x) % c == 0:
  print('Yes')
else:
  print('No')
#!/usr/bin/env python
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

def main():
    x = int(input())

    fact = factorization(x)
    fact = [[1]] + fact
    chk = 1
    for q in fact:
        p = q[0]
        a = p
        b = 0
        y = p ** 5
        while y <= x:
            y = a ** 5 - b ** 5
            if x == y:
                ret_a, ret_b = a, b
                chk = 0
                break
            a += 1
            b += 1
        if chk == 0:
            break

        a = p
        b = 0
        while a >= b:
            z = a ** 5 + b ** 5
            if x == z:
                ret_a, ret_b = a, -b
                chk = 0
                break
            a -= 1
            b += 1
        if chk == 0:
            break

    print(ret_a, ret_b)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python

def main():
    x = int(input())
    for i in range(1000):
        for j in range(0, i+1):
            y = i ** 5 - j ** 5
            z = i ** 5 + j ** 5
            if x == y:
                a = i
                b = j
                break
            elif x == z:
                a = i
                b = -j
                break
    print(a, b)


if __name__ == '__main__':
    main()
import sys
sys.setrecursionlimit(10**7)

n,m,k = map(int,input().split())

ab = [[] for j in range(n)]
cd = [[] for j in range(n)]

for i in range(m):
    a,b = map(int,input().split())
    ab[a-1].append(b-1)
    ab[b-1].append(a-1)
    
for i in range(k):
    c,d = map(int,input().split())
    cd[c-1].append(d-1)
    cd[d-1].append(c-1)
    
check = [-1]*n

def dfs(x,check):
    #if check[x] != -1:
    #    return
    for i in range(len(ab[x])):
        cho = ab[x][i]
        #print(cho,x)
        if check[cho] != -1:
            continue
        check[cho] = num
        dfs(cho,check)
    
    return

num = 0
for i in range(n):
    #print(i,check[i])
    if check[i] != -1:
        continue
    dfs(i,check)
    num += 1
#print(check)

grp_num = max(check)
grp_size = [0]*(grp_num+1)

for i in range(n):
    grp_size[check[i]] += 1
    
for i in range(n):
    hiku = 0
    for j in range(len(cd[i])):
        #print(cd[i],check[i],cd[i][j],check[cd[i][j]])
        if check[cd[i][j]] == check[i]:
            hiku += 1
            #print(hiku,hiku,hiku,hiku,hiku)
    print(grp_size[check[i]]-len(ab[i])-hiku-1,end=' ')

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)

n,m,k = map(int,input().split())

ab = [[] for j in range(n)]
cd = [[] for j in range(n)]

for i in range(m):
    a,b = map(int,input().split())
    ab[a-1].append(b-1)
    ab[b-1].append(a-1)
    
for i in range(k):
    c,d = map(int,input().split())
    cd[c-1].append(d-1)
    cd[d-1].append(c-1)
    
check = [-1]*n

def dfs(x,check):
    #if check[x] != -1:
    #    return
    for i in range(len(ab[x])):
        cho = ab[x][i]
        #print(cho,x)
        if check[cho] != -1:
            continue
        check[cho] = num
        dfs(cho,check)
    
    return

num = 0
for i in range(n):
    #print(i,check[i])
    if check[i] != -1:
        continue
    dfs(i,check)
    num += 1
#print(check)
grp_num = max(check)
grp_size = [0]*(grp_num+1)

for i in range(n):
    if check[i] == -1:
        continue
    grp_size[check[i]] += 1

for i in range(n):
    hiku = 0
    for j in range(len(cd[i])):
        #print(cd[i],check[i],cd[i][j],check[cd[i][j]])
        if check[cd[i][j]] == check[i]:
            hiku += 1
            #print(hiku,hiku,hiku,hiku,hiku)
    if check[i] == -1:
        print(0)
    else:
        print(grp_size[check[i]]-len(ab[i])-hiku-1,end=' ')
import requests
S = input()
s = requests.session()
data={
    "data":S
}
url = "http://13.231.150.9/b.php"
r = s.post(url,data=data)
print(r.text)

### FIXED CODE ###

#alphabet="abcdefghijklmnopqrstuvwxyz"
alphabet = [chr(ord('a')+i) for i in range(26)]
S=list(set(input()))
S.sort()

for i in alphabet:
    if i not in S:
        print(i)
        exit()
print("None")
N = int(input())
A = [int(i) for i in input().split()]
ans = 0

for i in range(n):
  if (i+1) % 2 == 1 and a[i] % 2 == 1:
    c += 1
else:
  print(ans)


### FIXED CODE ###

N = int(input())
A = [int(i) for i in input().split()]
c = 0
 
for i in range(N):
  if (i+1) % 2 == 1 and A[i] % 2 == 1:
    c += 1
else:
  print(c)
import math
from functools import reduce

N, X = tuple(int(i) for i in input().split())
x = [int(i) for i in input().split()]

x.append(X)
sx = sorted(x)
dx = [j - i for i, j in zip(sx[:-1], sx[1:])]

mdx = reduce(math.gcd, dx)

print(mdx)


### FIXED CODE ###

from fractions import gcd
from functools import reduce

N, X = tuple(int(i) for i in input().split())
x = [int(i) for i in input().split()]

x.append(X)
sx = sorted(x)
dx = [j - i for i, j in zip(sx[:-1], sx[1:])]

mdx = reduce(gcd, dx)

print(mdx)
H, W = map(int, input().split())
#左右に'.'を余分に付けて標準入力からリストを作成
grid = [list('.'+input()+'.') for i in range(H)]
#上下にも付けてやる
grid.insert(0, list('.' * (W + 2)))　#上
grid.append(list('.' * (W + 2)))　#下
#答えを入れるリスト
ans = []

#付け足した行列はカウントしない
for i in range(1, H + 1):
  for j in range(1, W + 1):
    if grid[i][j] == '#':
      ans.append('#')
    else:
      #8方向にある'#'の数をカウント
      #付け足したのは'.'なので条件分岐は不要
      #str型で出力しなければjoinできない
      ans.append(str((grid[i-1][j-1:j+2]+grid[i][j-1:j+2]+grid[i+1][j-1:j+2]).count('#')))
  #一行終わったので改行を入れる
  ans.append('\n')
print(''.join(ans)) #リストをつないで出力

### FIXED CODE ###

H, W = map(int, input().split())
#左右に'.'を余分に付けて標準入力からリストを作成
grid = [list('.'+input()+'.') for i in range(H)]
#上下にも付けてやる
grid.insert(0, list('.' * (W + 2)))
grid.append(list('.' * (W + 2)))
#答えを入れるリスト
ans = []
 
#付け足した行列はカウントしない
for i in range(1, H + 1):
  for j in range(1, W + 1):
    if grid[i][j] == '#':
      ans.append('#')
    else:
      #8方向にある'#'の数をカウント
      #付け足したのは'.'なので条件分岐は不要
      #str型で出力しなければjoinできない
      ans.append(str((grid[i-1][j-1:j+2]+grid[i][j-1:j+2]+grid[i+1][j-1:j+2]).count('#')))
  #一行終わったので改行を入れる
  ans.append('\n')
print(''.join(ans)) #リストをつないで出力
i,x = 0,input()
while x != 0':
  print('Case ' i ': ' x)
  i,x = i+1, input()


### FIXED CODE ###

i,x = 1,input()
while x != "0":
  print('Case '+str(i)+': '+x)
  i,x = i+1,input()
#coding:utf-8
while 1:
    try:
        #初期化
        key=[]
        for i in range(101):
            key.append(0)
        flag = 0
        #オイラー路：すべての頂点のうち、次数が奇数であるものがちょうど２つ(入口と出口)
        while 1:
            input = map(int, raw_input().split())
            if(input[0] == 0 and input[1] == 0):
                break
            key[input[0]]+=1
            key[input[1]]+=1

        for v in key:
            if v%2 == 1:
                flag+=1
        if(flag == 2 or flag == 0):
            print "OK"
        else:
            print "NG"
    except:
        break

### FIXED CODE ###

#coding:utf-8
while 1:
    try:
        #初期化
        key=[0]*101
        #オイラー路：すべての頂点のうち、次数が奇数であるものがちょうど２つ(入口と出口)
        while 1:
            input = map(int, raw_input().split())
            if(input[0] == 0 and input[1] == 0):
                break
            key[input[0]]+=1
            key[input[1]]+=1

        if(key[1]%2 == 1 and key[2]%2==1 and len(filter(lambda x:x%2==1,key[3:]))==0):
            print "OK"
        else:
            print "NG"
    except:
        break
def ball(nums):
????????b,c = 0,0
    for i in range(len(a)):
        if b < a[i]:
            b = a[i]
            continue
        if c < a[i]:
            c = a[i]
            continue
        return "NO"
    return "YES"
??
N = int(input())
??
for _ in range(N):
????????a = list(map(int, input().split()))
????????print(ball(a))

### FIXED CODE ###

def ball(nums):
    b, c = 0, 0
    for i in range(len(nums)):
        if b < nums[i]:
            b = nums[i]
            continue
        if c < nums[i]:
            c = nums[i]
            continue
        return "NO"
    return "YES"

N = int(input())

for _ in range(N):
    a = list(map(int, input().split()))
    print(ball(a))
# _*_ coding:utf-8 _*_
#  Atcoder_Grand_Contest029-B
#  https://agc029.contest.atcoder.jp/tasks/agc029_b
from collections import Counter

def  maxCountPair(n_ballCount,a_ballDatas):
	a_ballDatas.sort(reverse=True)
	ballDictBox = Counter(a_ballDatas)
	ballCountRange = range(0,n_ballCount)
	pairCount = 0
	for i in ballCountRange:
		getBallNumber = a_ballDatas[i]
		getBallNumberBin = getBallNumber.bit_length()
		nextTwoPower = 2**getBallNumberBin
		diffNumber = nextTwoPower - getBallNumber
		if 1 <= ballDictBox[diffNumber] :
			if getBallNumber != diffNumber:
				pairCount = pairCount + 1
				ballDictBox[getBallNumber]=ballDictBox[getBallNumber]-1
				ballDictBox[diffNumber] = ballDictBox[diffNumber]-1
			else:
				if 2 <= ballDictBox[diffNumber]:
					pairCount = pairCount + 1
					ballDictBox[diffNumber]=ballDictBox[diffNumber]-2
	answer = pairCount
	return answer


if __name__ == '__main__':
	n_ballCount=int(input())
	a_ballDatas=list((map(int,input().split(" "))))
	solution=maxCountPair(n_ballCount,a_ballDatas)
	print(solution)

### FIXED CODE ###

# _*_ coding:utf-8 _*_
#  Atcoder_Grand_Contest029-A
#  https://agc029.contest.atcoder.jp/tasks/agc029_a

def  irr_operation(givenString):

	allLength = len(givenString)
	allRange = range(0,allLength)
	bCounter =0
	bPosition = []
	for i in allRange:
		if givenString[i] == 'B':
			bPosition.append(i)
			bCounter=bCounter+1

	collectPosition =[]
	bLength = len(bPosition)
	bRange = range(allLength-bLength,allLength)
	for i in bRange:
		collectPosition.append(i)

	bLengthRange = range(0,bLength)
	diffPosition = 0
	for i in bLengthRange:
		diffPosition = diffPosition+(collectPosition[i]-bPosition[i])

	answer = diffPosition
	return answer


if __name__ == '__main__':
	bwstring = input()
	solution=irr_operation(bwstring)
	print(solution)
n, m = map(int, input().split())
a = []
for _ in range(m):
    a.append(int(input()))


def count_steps(NN):
    NN -= 1
    steps = [0] * (NN + 3)
    steps[1] = 1
    steps[2] = 2
    for i in range(3, NN + 1):
        steps[i] = steps[i - 1] + steps[i - 2]
    return steps[NN]

if a[0] == 1:
    ans = 1
else:
    ans = count_steps(a[0])

for i in range(1, len(a)):
    ans *= count_steps(a[i]-a[i-1]-1)
ans *= count_steps(n-a[-1])
print(ans%1000000007)

### FIXED CODE ###

n, m = map(int, input().split())
a = []
for _ in range(m):
    a.append(int(input()))


def count_steps(NN):

    steps = [0] * (NN + 3)
    steps[1] = 1
    steps[2] = 2
    for i in range(3, NN + 1):
        steps[i] = steps[i - 1] + steps[i - 2]
    return steps[NN]

if m == 0:
    ans = count_steps(n)
else:
    if a[0] == 1:
        ans = 1
    else:
        ans = count_steps(a[0] - 1)

    for i in range(1, len(a)):
        temp = a[i] - a[i - 1] - 2
        if temp < 0:
            ans = 0
        elif temp == 0:
            ans *= 1
        else:
            ans *= count_steps(temp)

    temp = n - a[-1] - 1
    if temp > 0:
        ans *= count_steps(temp)
print(ans%1000000007)
#import sys
#input = sys.stdin.readline
#sys.setrecursionlimit(10**6)

N, Q = map(int, input().split())
AB = [[int(x) for x in input().split()] for _ in range(N-1)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]
 
g = [[] for _ in range(N+1)]
for a,b in AB:
    g[a].append(b)
    g[b].append(a)
 
cnt = [0] * (N+1)
for p,x in PX:
    cnt[p] += x

def dfs(v, p, add):
    cnt[v] += add
    for nv in g[v]:
        if nv == p:
            continue
        dfs(nv, v, cnt[v])

dfs(1, 0, 0)

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


### FIXED CODE ###

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

N, Q = map(int, input().split())
AB = [[int(x) for x in input().split()] for _ in range(N-1)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]
 
g = [[] for _ in range(N+1)]
for a,b in AB:
    g[a].append(b)
    g[b].append(a)
 
cnt = [0] * (N+1)
for p,x in PX:
    cnt[p] += x

def dfs(v, p, add):
    cnt[v] += add
    for nv in g[v]:
        if nv == p:
            continue
        dfs(nv, v, cnt[v])

dfs(1, 0, 0)

print(' '.join(map(str, cnt[1:])))
a, b = map(int, input().split())
plus = a + b
minus = a - b
mult = a * b
ans = max(plus, minus)
ans = max(ans, mult)
print ans

### FIXED CODE ###

a, b = map(int, input().split())
plus = a + b
minus = a - b
mult = a * b
ans = max(plus, minus)
ans = max(ans, mult)
print(ans)
S =input()
S =int(S)
a = 0
b =0

while S>=500:
  S -=500
  a +=1
  g =S-(500*a)
  while g>=5:
    g -=5
    b +=1
h =1000*a +5*b
print(h)

### FIXED CODE ###

a = input()
a = list(a)
if a[2] == a[3] and a[4] ==a[5]:
  print("Yes")
else:
  print("No")
import sys
from math import factorial, ceil, floor
from bisect import bisect_right as bsr
from operator import itemgetter as ig
from collections import defaultdict as dd
from collections import deque

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)
def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]

# バイナリインデックス木(BIT)
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
      def sum(self, i):
        s = 0
        while 0 < i:
            s += self.tree[i]
            i -= i & -i
        return s
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

# エントリーポイント
def main():
    N, K = input(int, int)
    A = input([int, N])

    ppp = A
    bit = Bit(2010)
    ans = 0
    
    for k in range(1, K + 1):
        for i, p in enumerate(ppp):
            bit.add(p, 1)
            ans += (K * i + 1) - bit.sum(p)
            ans %= MOD
    print(ans)

if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()


### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)
from math import factorial, ceil, floor
from bisect import bisect_right as bsr
from operator import itemgetter as ig
from collections import defaultdict as dd
from collections import deque, Counter as cnt

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)
def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]
def nlist(n, v):
    if not n: return v.copy()
    return [nlist(n[1:], v) for _ in range(n[0])]

# バイナリインデックス木
class BIT:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
    def sum(self, i):
        s = 0
        while 0 < i:
            s += self.tree[i]
            s %= MOD
            i -= i & -i
        return s
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

# エントリーポイント
def main():
    N, K = input(int, int)
    A = input([int, N])

    MAX = 2010
    bit = BIT(MAX)
    # 最終周をカウントする
    sum1 = []
    for i, a in enumerate(A, start=1):
        bit.add(a, 1)
        sum1.append(i - bit.sum(a))
    # 繰り返し周をカウントする
    sum2 = []
    for a in A:
        sum2.append(N - bit.sum(a))
    # (1 + (K - 1))回分を集計する
    ans = 0
    for v1, v2 in zip(sum1, sum2):
        ans += K * v1 + ((K * (K - 1)) // 2) * v2
        ans %= MOD
    print(ans)

if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()
N = int(input())
h = list(map(int, input().split()))

N,K = list(map(int, N.split()))
h = list(map(int, h.split()))

dp = [np.inf] * N
dp[0] = 0
dp[1] = abs(h[1]-h[0])
for i in range(2,N):
    for j in range(0,K+1):
        if i - j >= 0:
            dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))
print(dp[N-1])

### FIXED CODE ###

import numpy as np

N, K = list(map(int, input().split()))
h = np.array(list(map(int, input().split())))

dp = np.array([np.inf] * N)
dp[0] = 0
dp[1] = abs(h[1]-h[0])
for i in range(2,N):
        if i - K >= 0:
            dp[i] = min(dp[i-K:i]+abs(h[i]-h[i-K:i]))
        else:
            dp[i] = min(dp[0:i]+abs(h[i]-h[0:i]))
print(int(dp[N-1]))
N=int(input())
s=[input() for _ in range(N)]
M=int(input())
t=[input() for _ in range(M)]
l=list(set(N))
print(max(0,max(s.count(l[i])-t.count(l[i]) for i in range(len(l)))))

### FIXED CODE ###

N=int(input())
s=[input() for _ in range(N)]
M=int(input())
t=[input() for _ in range(M)]
l=list(set(s))
print(max(0,max(s.count(l[i])-t.count(l[i]) for i in range(len(l)))))
n, y = map(int, input().split())
r = range(n+1)

ans = "-1 -1 -1"
for i in r:
    for j in r:
        k = (y-(10000*i+5000*j))//1000
        if k >= 0 and 10000*i+5000*j+1000*k == y and i+j+k == n:
            ans = f"{i} {j} {k}"

print(ans)


### FIXED CODE ###

N, Y = map(int, input().split())
ans = '-1 -1 -1'
for i in range(N + 1):
    for j in range(N + 1):
        k = N - (i + j)
        if k >= 0 and 10000 * i + 5000 * j + 1000 * k == Y:
            ans = '{} {} {}'.format(i, j, k)
            break
    else:
        continue
    break
print(ans)
s = input()
q = int(input())

query = [""]*q

for i in range(q):
    query[i] = input()
    if query[i]=="1":
        s = list(reversed(s))
    else:
        r = query[i].split()
        if r[1]=="1":
            s = r[2]+s
        else:
            s += r[2]

print(s)

### FIXED CODE ###

from collections import deque

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

query = []
rev=1

for i in range(q):
    query.append(input().split())

for i in range(q):
    if query[i][0]=="1":
        rev*=-1
    else:
        if rev==1:
            if query[i][1]=="1":
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])
        else:
            if query[i][1]=="2":
                s.appendleft(query[i][2])
            else:
                s.append(query[i][2])

result="".join(list(s))
if rev==-1:
    result = result[::-1]
print(result)
# input
N, M, Q = map(int, input().split())
train_query = {} # 対象区間とクエリを一緒にソート
for i in range(M + Q):
    train_query[i] = list(map(int, input().split()))

train_query = sorted(train_query.items(), key=lambda x: x[1], reverse = True)
# 辞書をソートするとリストが返ってくることに注意

a = [0 for _ in range(N)]

for j in range(M + Q):
    if train_query[j][0] < M: # 対象区間
        a[train_query[j][1][0]] = 1
    else: # クエリ
        ans = sum(a[train_query[j][1][0]:train_query[j][1][1]])
        print(ans)


### FIXED CODE ###

# input
N, M, Q = map(int, input().split())
train_query = {} # 対象区間とクエリを一緒にソート
for i in range(M + Q):
    train_query[i] = list(map(int, input().split()))

train_query = sorted(train_query.items(), key=lambda x: x[1][1])
# 辞書をソートするとリストが返ってくることに注意

StartPoints = [0 for _ in range(N)] # 対象区間の開始位置
ans = [0 for _ in range(Q)] # 各クエリに対する答え

for j in range(M + Q):
    if train_query[j][0] < M: # 対象区間
        StartPoints[train_query[j][1][0] - 1] += 1
    else: # クエリ
        ans[train_query[j][0] - M] = sum(StartPoints[(train_query[j][1][0] - 1):(train_query[j][1][1])])

for i in range(Q):
    print(ans[i])
N = int(input())
S = input()

num = []
for i in range(10):
    for j in range(10):
        for k in range(10):
            num.append(f"{i}{j}{k}")

ans = 0
for n in num:
    i = 0
    j = 0
    while j < N:
        # print(i, j)
        if n[i] == S[j]:
            i += 1
            j += 1
        else:
            j += 1
        if i == 3:
            ans += 1
            break
print(ans)


### FIXED CODE ###


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

num = []
for i in range(10):
    for j in range(10):
        for k in range(10):
            num.append("{}{}{}".format(i, j, k))

ans = 0
for n in num:
    i = 0
    j = 0
    while j < N:
        # print(i, j)
        if n[i] == S[j]:
            i += 1
            j += 1
        else:
            j += 1
        if i == 3:
            ans += 1
            break
print(ans)
k,n=map(int,input().split())
a=list(map(int,input().split())
lists=[]
for i in range(N):
       d=int(a[i+1]-a[i])
       lists.append(d)
lists.append(K-a[N-1]+a[0])
ans=K-max(b)
print(ans)

### FIXED CODE ###

k, n = map(int, input().split())
a = list(map(int, input().split()))
a2 = []
for i in range(n-1):
    d = int(a[i+1]-a[i])
    a2.append(d)
a2.append(k-a[n-1]+a[0])
ans = k - max(a2)
print(ans)
N, K = map(int, input().split())

if abs(N-K) < N:
    if N >= K:
        if K/(N%K) >= 1:
            print(K%(N%K))
        else:
            print(N % K)
    else:
        if N/(K%N) >= 1:
            print(N%(K%N))
        else:
            print(K % N)
else:
    print(N)

### FIXED CODE ###

#coding:utf-8

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

r1 = n % k
r2 = abs(k - r1)

ans = min(r1,r2)

print("{}".format(ans))
n = int(input())
a = [int(input()) for i in range(n)]
MAX = max(a)
se = list(reversed(sorted(set(a))))[1]
for i in range(n):
    if a[i] == MAX:
        print(se)
    else:
        print(MAX)

### FIXED CODE ###

n = int(input())
a = [int(input()) for i in range(n)]
MAX = max(a)
se = list(reversed(sorted(a)))[1]
for i in range(n):
    if a[i] == MAX:
        print(se)
    else:
        print(MAX)
a = input()
b = input()
 
answer_list = {"1","2","3"}
answer_list.remove(a)
answer_list.remove(b)
 
print(answer_list[0])

### FIXED CODE ###

a = input()
b = input()
 
answer_list = ["1","2","3"]
answer_list.remove(a)
answer_list.remove(b)
 
print(answer_list[0])
x = input()
print(int(x/2)+1)

### FIXED CODE ###

N = int(input())
print(int(N/2)+N%2)