Harryxun/stf_run huggingface dataset:
N, K = map(int, input().split())
S = 'R' + input() + 'L'
UH = [0] * (N + 1)
d = 'R'
for i, s in enumerate(S):
  if s == 'R':
    if S[i + 1] == 'L':
      UH[i] += 1
  else:
    if S[i - 1] == 'R':
      UH[i - 1] += 1
UH[0] = min(UH[0], 1)
UH[N] = min(UH[N], 1)
UH.sort(reverse=True)
for i in range(K):
  UH[i] = 0
if sum(UH) == 0:
  UH[0] = 1
print(N - sum(UH))

### FIXED CODE ###

N, K = map(int, input().split())
S = 'R' + input() + 'L'
UH = [0] * (N + 1)
d = 'R'
for i, s in enumerate(S):
  if s == 'R':
    if S[i + 1] == 'L':
      UH[i] += 1
  else:
    if S[i - 1] == 'R':
      UH[i - 1] += 1
UH[0] = min(UH[0], 1)
UH[N] = min(UH[N], 1)
UH.sort(reverse=True)
for i in range(min(K, N + 1)):
  UH[i] = 0
if sum(UH) == 0:
  UH[0] = 1
print(N - sum(UH))
n,a,b = map(int, input().split())
print(min(b,a*n)

### FIXED CODE ###

n,a,b = map(int, input().split())
print(min(b,a*n))
import numpy as np
N=int(input())
A=list(map(int,input().split()))
A=np.array(A)
v=0
j=0
k=0
for i in reversed(range(0, N+1)):
  j+=A[i]/(2**i)
  if i==N:
    k=A[i]
  else:
    k=min(k+A[i],2**i-np.sum(np.array([A[k]*(2**(i-k)) for k in range(i)])))
  v+=k

if j>1:
  print(-1)
else:
  print(int(v))

### FIXED CODE ###

import numpy as np
N=int(input())
A=np.array(list(map(int,input().split())))
B=np.sum(A)-np.cumsum(np.append(0, A[:len(A)-1]))
v=0
k=0
for i in range(N+1):
  if i==0:
    if N==0 and A[0]==1:
      k=1
    elif A[0]==0:
      k=1
    else:
      print(-1)
      break
  elif i==N:
    if B[i]<=2*(k-A[i-1]):
      k=B[i]
    else:
      k=0
      print(-1)
      break
  else:
    k=min(2*(k-A[i-1]),B[i])
    if k<=0:
      print(-1)
      break
  v+=k
if k>0:
  print(v)
import sys
input = sys.stdin.buffer.readline
n = int(input())
a = list(map(int, input().split()))
from fractions import gcd
def lcm(x,y):
  return (x*y)//gcd(x,y)
l = 1
mod = 10**9+7
for i in range(n):
  l = lcm(l, a[i])
ans = 0
for i in range(n):
  ans += l // a[i]
  ans %= mod
print(ans)


### FIXED CODE ###

if eval(input().replace(' ','==')):
  print('Yes')
else:
  print('No')
from sys import stderr
from functools import reduce
from operator import add
def f(): return [int(i) for i in input().split()]
def debug(*x): stderr.write(reduce(add,repr(x)).strip("()\',")+'\n')

a = int(input())
b = int(input())

print("Yay!") if abs(a-b) <= 1 else print(":(")

### FIXED CODE ###

from sys import stderr
from functools import reduce
from operator import add
def f(): return [int(i) for i in input().split()]
def debug(*x): stderr.write(reduce(add,repr(x)).strip("()\',")+'\n')

a,b = f()

print("Yay!") if abs(a-b) <= 1 else print(":(")
import fractions

from numba import njit
import numpy as np
from sys import stdin


@njit
def calc_ans(a, lcm):
    ans = 0

    for ai in a:
        ans += lcm // ai

    ans %= 10 ** 9 + 7

    return ans


def main():
    n = int(stdin.readline())
    a = list(map(int, stdin.readline().split()))
    sa = set(a)
    a = np.array(a)

    lcm = 1

    for ai in sa:
        lcm = (ai * lcm) // fractions.gcd(ai, lcm)

    print(calc_ans(a, lcm))


if __name__ == "__main__":
    main()


### FIXED CODE ###

import fractions

from sys import stdin


def main():
    n = int(stdin.readline())
    a = list(map(int, stdin.readline().split()))
    sa = set(a)

    lcm = 1

    for ai in sa:
        lcm = (ai * lcm) // fractions.gcd(ai, lcm)

    ans = 0

    for ai in a:
        ans += lcm // ai
    ans %= 10 ** 9 + 7

    print(ans)


if __name__ == "__main__":
    main()
from bisect import insort_left

N = int(input())
*A, = map(int, input().split())
operations = []
pos = []; zero = []; neg = [];
for a in A:
    if a > 0: insort_left(pos, a)
    elif a == 0: zero.append(a)
    else: insort_left(neg, a)
if len(neg) == 0:
    pos = zero + pos
    operations.append((pos[0], pos[-1]))
    neg = [pos[0] - pos[-1]]
    pos = pos[1:-1]
elif len(pos) == 0:
    neg = neg + zero
    operations.append((neg[-1], neg[0]))
    pos = [neg[-1] - neg[0]]
    neg = neg[1:-1]
else:
    neg  = neg + zero
neg = neg[::-1]
while len(pos) > 1 and len(neg) > 1:
    n, p = neg.pop(), pos.pop()
    operations.append((p, n))
    pos.append(p-n)
if len(neg) == 1:
    while len(pos) > 1:
        n, p = neg.pop(), pos.pop()
        operations.append((n, p))
        neg.append(n-p)
else:
    while len(neg) > 1:
        n, p = neg.pop(), pos.pop()
        operations.append((p, n))
        neg.append(p-n)
operations.append((pos[0], neg[0]))
ans = pos[0] - neg[0]
print(ans)
for x, y in operations:
    print(x, y)

### FIXED CODE ###

N = int(input())
*A, = map(int, input().split())
operations = []
pos = []; zero = []; neg = [];
for a in A:
    if a > 0: pos.append(a)
    elif a == 0: zero.append(a)
    else: neg.append(a)
pos.sort(); neg.sort()
if N == 2:
    a, b = max(A), min(A)
    ans = a - b
    operations.append((a, b))
else:
    if len(neg) == 0:
        pos = zero + pos
        operations.append((pos[0], pos[-1]))
        neg = [pos[0] - pos[-1]]
        pos = pos[1:-1]
    elif len(pos) == 0:
        neg = neg + zero
        operations.append((neg[-1], neg[0]))
        pos = [neg[-1] - neg[0]]
        neg = neg[1:-1]
    else:
        neg = neg + zero
    neg = neg[::-1]
    while len(pos) > 1 and len(neg) > 1:
        n, p = neg.pop(), pos.pop()
        operations.append((p, n))
        pos.append(p-n)
    if len(neg) == 1:
        while len(pos) > 1:
            n, p = neg.pop(), pos.pop()
            operations.append((n, p))
            neg.append(n-p)
    else:
        while len(neg) > 1:
            n, p = neg.pop(), pos.pop()
            operations.append((p, n))
            pos.append(p-n)
    operations.append((pos[0], neg[0]))
    ans = pos[0] - neg[0]
print(ans)
for x, y in operations:
    print(x, y)
def gcd_list(numbers):
    return reduce(gcd, numbers)

K = ii()
ans = 0

memo = dp3(-1, K+1, K+1, K+1)

for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            #l = sorted([i, j, k])
            #l = [i, j, k]
            #a, b, c = l[0], l[1], l[2]
            a, b, c = i, j, k
            if memo[a][b][c] != -1:
                ans += memo[a][b][c]
            else:
                memo[a][b][c] = gcd_list([a, b, c])
                memo[i][k][j] = memo[k][i][j] = memo[k][j][i] = memo[j][i][k] = memo[j][k][i] = memo[i][j][k]
                #memo[i][k][j] = memo[i][j][k]
                #memo[k][i][j] = memo[i][j][k]
                #memo[k][j][i] = memo[i][j][k]
                #memo[j][j][i] = memo[i][j][k]
                #memo[j][i][k] = memo[i][j][k]
                ans += memo[a][b][c]
            #ans += gcd_list([i, j, k])


print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
from math import gcd
from functools import reduce

def gcd_list(numbers):
    return reduce(gcd, numbers)

K = ii()
ans = 0

memo = dp3(-1, K+1, K+1, K+1)

for i in range(1, K+1):
    for j in range(i+1, K+1):
        for k in range(j+1, K+1):
            '''
            #l = sorted([i, j, k])
            l = [i, j, k]
            a, b, c = l[0], l[1], l[2]
            if memo[a][b][c] != -1:
                ans += memo[a][b][c]
            else:
                memo[a][b][c] = gcd_list(l)
                #memo[i][k][j] = memo[k][i][j] = memo[k][j][i] = memo[j][i][k] = memo[j][k][i] = memo[i][j][k]
                #memo[i][k][j] = memo[i][j][k]
                #memo[k][i][j] = memo[i][j][k]
                #memo[k][j][i] = memo[i][j][k]
                #memo[j][j][i] = memo[i][j][k]
                #memo[j][i][k] = memo[i][j][k]
                ans += memo[a][b][c]
                '''
            ans += gcd_list([i, j, k])*6

for i in range(1, K+1):
    for j in range(1, K+1):
        if i!=j:
            ans += gcd_list([i, i, j])*3

for i in range(1, K+1):
    ans += gcd_list([i, i, i])

print(ans)
N,M,K = list(map(int,input().split()))

MOD = 998244353
F = 10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, F + 1 ):
    g1.append( ( g1[-1] * i ) % MOD )
    inverse.append( ( -inverse[MOD % i] * (MOD//i) ) % MOD )
    g2.append( (g2[-1] * inverse[-1]) % MOD )

def cmb(n, r, MOD):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % MOD

A = [M*pow(M-1,N-1-i,MOD) % MOD for i in range(K+1)]
A = [A[i] * cmb(N-1,i,MOD) % MOD for i in range(K+1)]
print(sum(A) % MOD)

### FIXED CODE ###

N,M,K = list(map(int,input().split()))
MOD = 998244353

fac = [1] * (N+1)
inv = [1] * (N+1)
ifac = [1] * (N+1)
for i in range(2,N+1):
    fac[i]=(fac[i-1]*i)%MOD
    inv[i]= -(inv[MOD%i]*(MOD//i))%MOD
    ifac[i]=(ifac[i-1]*inv[i])%MOD

cmbarr = [1] * N
for r in range(N-1):
    cmbarr[r+1] = cmbarr[r] * (N - 1 - r) * inv[r + 1] % MOD

A = [M*pow(M-1,N-1-i,MOD)*cmbarr[i] % MOD for i in range(K+1)]
print(sum(A) % MOD)
from bisect import bisect_left, bisect_right
 
N = int(input())
A = list(map(int, input().split(" ")))
A.sort()
 
ans = 0
while len(A) > 1:
    pow2 = 1 << (len(bin(A[-1])) - 2)
    idx = bisect_left(A, pow2 - A[-1])
    if A[idx] + A[-1] == pow2 and idx != len(A) - 1:
        A.pop(idx)
        ans += 1
    A.pop(-1)
print(ans)
from bisect import bisect_left, bisect_right

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

ans = 0
while len(A) > 1:
    pow2 = 1 << (len(bin(A[-1])) - 2)
    idx = bisect_left(A, pow2 - A[-1])
    if A[idx] + A[-1] == pow2 and idx != len(A) - 1:
        A.pop(idx)
        ans += 1
    A.pop()
print(ans)

### FIXED CODE ###

from bisect import bisect_left, bisect_right
from collections import deque

N = int(input())
A = list(map(int, input().split(" ")))
A.sort()
A = deque(A)
ans = 0
t_max = len(bin(A[-1])) - 2
for t in range(t_max, 0, -1):
    if len(A) < 2: break
    while len(bin(A[-1])) - 2 > t:
        A.pop()
        if len(A) < 2: break
    if len(A) < 2: break
    pow2 = 1 << t
    A_tmp = deque()
    while t == len(bin(A[-1])) - 2:
        r = A.pop()
        idx = bisect_left(A, pow2 - r)
        for _ in range(idx):
            A_tmp.appendleft(A.popleft())
        if len(A) == 0: break
        if A[0] + r == pow2:
            A.popleft()
            ans += 1
        if len(A) < 2: break
    A.extendleft(A_tmp)
                    
print(ans)
A,V=map(int,input().split())
B,W=map(int,input().split())
T=int(input())
v=V-W
l=B-A
if l < v*T:
  if l%v==0:
    print("YES")
  else:
    print("NO")
else:
  print("NO")


### FIXED CODE ###

a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())

print('YES' if abs(b-a) <= (v-w) * t else 'NO')
def inp():
    return input()
def iinp():
    return int(input())
def inps():
    return input().split()
def miinps():
    return map(int,input().split())
def linps():
    return list(input().split())
def lmiinps():
    return list(map(int,input().split()))
def lmiinpsf(n):
    return [list(map(int,input().split()))for _ in range(n)]

n = iinp()
q = lmiinps()

b = [0]*n
d = [0]*n

k = 1
l = 0
s = 0

a = sorted(q)
a.append(0)

def re(n):
  if n < 2:
    return 1
  return n*re(n-1)

def c(n,r):
  return re(n)//re(n-r)//2

for i in range(n):
    if a[i] == a[i+1]:
        k += 1
    else:
        l = c(k,2)
        s += l
        b[a[i]-1]=l
        d[a[i]-1]=k
        k = 1

for j in q:
    if (d[j-1] == 0) or d[j-1] == 1:
        continue
    p = s-((b[j-1])-((b[j-1] *(d[j-1]-2)) // d[j-1]))
    print(p)

### FIXED CODE ###

def inp():
    return input()
def iinp():
    return int(input())
def inps():
    return input().split()
def miinps():
    return map(int,input().split())
def linps():
    return list(input().split())
def lmiinps():
    return list(map(int,input().split()))
def lmiinpsf(n):
    return [list(map(int,input().split()))for _ in range(n)]

n = iinp()
q = lmiinps()

k = 1
l = 0
s = 0

a = sorted(q)
a.append(0)

b = [0]*(a[n-1])
d = [0]*(a[n-1])

for i in range(n):
    if a[i] == a[i+1]:
        k += 1
    else:
        l = ((k*(k-1))//2)
        s += l
        b[a[i]-1]=l
        d[a[i]-1]=k
        k = 1

for j in q:
    p = s-((b[j-1])-((b[j-1] *(d[j-1]-2)) // d[j-1]))
    print(p)
1<=A<=100
1<=B<=100
A = input(int())
B = input(int())
sum = A*B
print(sum)


### FIXED CODE ###

a, b =map(int,input().split())
print(a*b)
n,l=map(int,input().split())
c=[]
for i range(n):
  c.append(input())
c.sort()
print("",join(c))
  
    


### FIXED CODE ###

n,l=map(int,input().split())
c=[]
for i in range(n):
  c.append(input())
c.sort()
print("".join(c))
n,k=map(int,input().split())
p=tuple(map(float,input().split()))
exp=tuple([(pi+1)/2 for pi in p])
ans=0
for i in range(0,n-k+1):
  ans=max(ans,sum(exp[i:i+k]))
print(ans)

### FIXED CODE ###

s,t=map(str,input().split())
a,b=map(int,input().split())
u=str(input())
if u==s:
  print(a-1,b)
else:
  print(a,b-1)
c = input()
if c == ('a' or 'b' or 'c' or 'd' or 'e'):
    print(vowel)
else:
    print(consonant)


### FIXED CODE ###

c = input()
if c == 'a' or c == 'e' or c == 'i' or c == 'o' or c == 'u':
    print("vowel")
else:
    print("consonant")
import sys

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

for x in A:
    if (x % 2 == 0) and (x % 3 != 0) and (x % 5 != 0):
        print('DENIED')
        sys.exit()

print ('APPROVED')


### FIXED CODE ###

i = list(map(int, input().split()))
a = i[0]
b = i[1]
c = i[2]

isPoor = False

if (a == b or a == c) and b != c:
    isPoor = True
elif (b == a or b == c ) and a != c:
    isPoor = True
elif (c == a or c == b) and a != b:
    isPoor = True

if isPoor:
    print('Yes')
else:
    print('No')
import numpy as np

n, m = map(int, input().split())
g = np.zeros((n, n), dtype=int)
for _ in range(m):
    a, b = map(int, input().split())
    g[a-1, b-1] = 1
    g[b-1, a-1] = 1

res = 'IMPOSSIBLE'
for i in range(n):
    if g[n-1, i] == 0:
        continue
    if g[i, 0] == 1:
        res = 'POSSIBLE'
        break

print(res)


### FIXED CODE ###

import numpy as np

n, m = map(int, input().split())
from_1 = np.zeros(n+1, dtype=np.int)
to_n = np.zeros(n+1, dtype=np.int)
for i in range(m):
    a, b = map(int, input().split())
    if a == 1:
        from_1[b] = 1
    elif b == n:
        to_n[a] = 1

print('IMPOSSIBLE') if np.sum(from_1*to_n) == 0 else print('POSSIBLE')
def aaa(n,m):
    count1 = 1
    count2 = 1
    if n % 2 == 1:
        count1 = count1 + n//2
        count2 = count2 + n//2 + 1
    else:
        count1 = count1 + n//2
        count2 = count2 + n//2
    if m % 2 == 1:
        count1 = count1 + m//2 + 1
        count2 = count2 + m//2
    else:
        count1 = count1 + m//2
        count2 = count2 + m//2
    l3 = [count1,count2]
    l1 = l1 + l3 + l2
    return l1
s = list(input())
j = 0
a = 0
b = 0
l = []
for i in range(len(s)):
    if s[i] == "R" and j == 0:
        a = a + 1
    elif s[i] == "R" and j == 1:
        l = l + aaa(a-1,b-1)
        a = 1
        b = 0
        j = 0
    else:
        b = b + 1
        j = 1
l = l + aaa(a-1,b-1)
for x in l:
    print(x,end=" ")

### FIXED CODE ###

def aaa(n,m):
    count1 = 1
    count2 = 1
    if n % 2 == 1:
        count1 = count1 + n//2
        count2 = count2 + n//2 + 1
    else:
        count1 = count1 + n//2
        count2 = count2 + n//2
    if m % 2 == 1:
        count1 = count1 + m//2 + 1
        count2 = count2 + m//2
    else:
        count1 = count1 + m//2
        count2 = count2 + m//2
    l3 = [count1,count2]
    return l3
s = list(input())
n = len(s)
j = 0
a = 0
b = 0
l = [0]*n
for i in range(len(s)):
    if s[i] == "R" and j == 0:
        a = a + 1
    elif s[i] == "R" and j == 1:
        l[c-1] = aaa(a-1,b)[0]
        l[c] = aaa(a-1,b)[1]
        a = 1
        b = 0
        j = 0
    elif s[i] == "L" and j == 0:
        j = 1
        c = i
    elif s[i] == "L" and j == 1:
        b = b + 1
l[c-1] = aaa(a-1,b)[0]
l[c] = aaa(a-1,b)[1]
for x in l:
    print(x,end=" ")
a=[]
while 1:
 n=input()
 if n=='0 0':break
 x,y=map(int,n.split())
 if x>y:print(y+' '+x)
 else:print(n)

### FIXED CODE ###

import sys
for s in sys.stdin:
 if'0 0\n'==s:break
 print(*sorted(map(int,s.split())))
W, H, x, y, r = [int(i) for i in input().split]


if x + r <= W:
    print("No")
if x - r <= W:
    print("No")
else:
    print("Yes")

### FIXED CODE ###

W, H, x, y, r = [int(i) for i in input().split()]


if x + r <= W and y - r >= 0 and x - r >= 0 and y + r <= H:
    print("Yes")
else:
    print("No")
num = list(map(int,input().split()))
for l in range(len(num)):
    ans *= num[l] 
if ans < 10**18:
    print(ans)
elif ans >= 10**18:
    print(-1)

### FIXED CODE ###

# %%
def main():
    N = input()
    A = list(map(int, input().split()))
    if 0 in A:
        print(0)
        return
    ans = 1
    for a in A:
        ans *= a
        if ans > 10**18:
            print(-1)
            return
    print(ans)
if __name__ == '__main__':
    main()
cnt = int(input())
li = list(map(int,input().split()))
re_li = li[::-1]
for i in range(cnt):
    print(' '.join(map(int,re_li[i])


### FIXED CODE ###

cnt = int(input())
li = list(map(int,input().split()))
re_li = li[::-1]
print(' '.join(map(str,re_li)))
N = int(input())
H = list(map(int, input().split()))

ans = 'Yes'

for i in reversed(range(0, N-1)):
    if H[i] > H[i+1] + 1:
        ans += 1
    elif H[i] == H[i+1] + 1:
        H[i] -= 1

if ans == 0:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

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

ans = 'Yes'

for i in reversed(range(0, N-1)):
    if H[i] > H[i+1] + 1:
        ans = 'No'
    elif H[i] == H[i+1] + 1:
        H[i] -= 1

print(ans)
N,X = map(int, input().split())
L = list(map(int, input().split()))
count = 0
D = 0
i = 0

while D < X+1:
  count += 1
  D += L[i]
  i += 1
  
if D <= X:
  count += 1
  
print(count)
  

### FIXED CODE ###

N,X = map(int, input().split())
L = list(map(int, input().split()))
count = 1
D = 0

for i in range(N):
  D += L[i]
  if D <= X:
    count += 1
  else:
    break

print(count)
n=int(input())
s=list(input())
for i in range(len(s)):
  s[i]=chr((ord(s[i])-ord('A')+n)%26+ord('A'))
print(''.join(s))


### FIXED CODE ###

s = input()
print(['', 'SAT', 'FRI', 'THU', 'WED', 'TUE', 'MON', 'SUN'].index(s))
a = int(input())
s = int(input())
# C = int(input())
# b = input()
print(s if a >= 3200 else "red")

### FIXED CODE ###

a = int(input())
# s = int(input())
# C = int(input())
s= input()
print(s if a >= 3200 else "red")
n = input()
a = [int(i) for i in input.split()]
X = 0
ans = 0
for i in a:
	X += i
    if X > 0:
      b = -1 - X
      ans += b - a(i+1)
    else X < 0:
      b = 1 - X
      ans += b - a(i+1)
    return ans
print (ans)

### FIXED CODE ###

n=input()
a=[int(i) for i in input().split()]
def chk(a,t):
    ans=0
    x=0
    for i in a:
        x+=i
        if t==True and x<1:
            ans+=1-x
            x=1
        elif t==False and x>-1:
            ans+=x+1
            x=-1
        t=not t
    return ans
print(min(chk(a,True),chk(a,False)))
n = int(input())
ans = [] 

for i in range(n):
    a = int(input())
    if a in ans:
        ans.remove(a)
    else:
        ans.add(a)
print(len(ans))



### FIXED CODE ###

n = int(input())
ans = set() 

for i in range(n):
    a = int(input())
    if a in ans:
        ans.remove(a)
    else:
        ans.add(a)
print(len(ans))
n,x,m = map(int,input().split())
mod = m
num = []
ans = 0
cnt = 0
ch = x

#ループの始まりを特定
while True:
    if ch not in num:
        num.append(ch)
    else:
        st = ch #ループの開始している配列の初めの数字
        break
    ch *= ch
    ch %= mod

#ループの始まりの配列の添え字を特定
for i in range(len(num)):
    if num[i] == st:
        stnum = i #ループ開始の最初の配列のの番号
        break
else:
    stnum = len(num) - 1


if 0 in num:
    ans = sum(num[:n])
else:
    if (len(num)-stnum) != 0:
        rest = (n-stnum)%(len(num)-stnum) #余り
        qu = (n-stnum)//(len(num)-stnum)  #商
    else:
        rest = n
        qu = 0
    if n <= stnum + 1:
        ans = sum(num[:n])
    else:
        ans = sum(num[:stnum]) + sum(num[stnum:stnum+rest]) + sum(num[stnum:])*sho
print(ans)

### FIXED CODE ###

n,x,m=map(int,input().split())
p=[0]*(m+1)
a=x
t=0
s=0
for i in range(2*m):
    if p[a]==1:
        p[a]=2
        break
    else:
        p[a]=1
        a=a**2%m
a=x
S=0
for i in range(2*m):
    if p[a]==1:
        s+=1
        S+=a
        a=a**2%m
    else:
        s+=1
        S+=a
        break
T=0
A=0
for i in range(2*m):
    a=a**2%m
    t+=1
    T+=a
    if p[a]==2:
        A=a
        break
a = x
if n <= s:
    ans=0
    for i in range(n):
        ans+=a
        a=a**2%m
    print(ans)
else:
    ans=S
    a=A
    n-=s
    ans+=(n//t)*T
    n=n%t
    for i in range(n):
        a=a**2%m
        ans+=a
    print(ans)
n, k = map(int, input().split())
h = list(map(int,input().split()))
oppai = 0
for i in range(n):
  if h[i] >= k:
    oppai += 1
print(oppai)
    


### FIXED CODE ###

n = int(input())
if n % 2 == 0:
  print(1/2)
else:
  print((n/2 + 0.5)/n)
n = input()
inf = 1000000000
M = [[inf for i in range(n)] for i in range(n)]
for i in range(n):
  str = raw_input().split()
  u = int(str[0])
  k = int(str[1])
  for j in range(k):
    v = int(str[1+j])
    c = int(str[2+j])
    M[u][v] = c
d = [inf for i in range(n)]
color = [0 for i in range(n)]

d[0] = 0
color[0] = 1

while 1:
  minv = inf
  u = -1
  for i in range(n):
    if minv>d[i] and color[i]!=2:
      u = i
      minv = d[i]
    print minv
  if u == -1:
    break
  color[u] = 2
  for v in range(n):
    if color[v]!=2 and M[u][v]!=inf:
      if d[v]>d[u]+M[u][v]:
        d[v] = d[u] + M[u][v]
        color[v] = 1
for i in range(n):
  if d[i]==inf:
    print '%d -1' % i
  else:
    print '%d %d' % (i, d[i])

### FIXED CODE ###

n = input()
inf = 1000000000
M = [[inf for i in range(n)] for i in range(n)]
for i in range(n):
  str = map(int, raw_input().split())
  u = str[0]
  k = str[1]
  for j in range(k):
    v = str[2+2*j]
    c = str[3+2*j]
    M[u][v] = c
d = [inf for i in range(n)]
color = [0 for i in range(n)]
 
d[0] = 0
color[0] = 1
 
while 1:
  minv = inf
  u = -1
  for i in range(n):
    if minv>d[i] and color[i]!=2:
      u = i
      minv = d[i]
  if u == -1:
    break
  color[u] = 2
  for v in range(n):
    if color[v]!=2 and M[u][v]!=inf:
      if d[v]>d[u]+M[u][v]:
        d[v] = d[u] + M[u][v]
        color[v] = 1
for i in range(n):
  if d[i]==inf:
    print '%d -1' % i
  else:
    print '%d %d' % (i, d[i])
import sys
sys.setrecursionlimit(10000)

def gcd(i,j):
  if i>j:
    i,j=j,i
  if j%i==0:
    return i
  return gcd(i,j-i)

n=int(input())
l=[int(i) for i in input().split()]
g=gcd(l[0],l[1])
for i in range(2,len(l)):
  g=gcd(g,l[i])
print(g)

### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)

def gcd(i,j):
  if i>j:
    i,j=j,i
  if j%i==0:
    return i
  return gcd(j-i,i)

n=int(input())
l=[int(i) for i in input().split()]
l.sort()
g=gcd(l[0],l[1])
for i in range(2,len(l)):
  g=gcd(g,l[i])
print(g)
n = int(input())
s = input()
q = int(input())
for i in range(q):
	c=list(input().split())
	if c[0]=="1":
		s=s[:int(c[1])-1]+c[2]+s[int(c[1]):]
	else:
		print(len(set(s[int(c[1])-1:int(c[2])])))

### FIXED CODE ###

n = int(input())
print((n+1)//2)
N = int(input())

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

ans = [0]*N
[ans[j-1]=i+1 for i,j in enumerate(A)]
print(*ans)

### FIXED CODE ###

N = int(input())

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

ans = [0]*N
for i,j in enumerate(A):
    ans[j-1]=i+1
print(*ans)
n = int(input())
d = list(map(int,input().split()))
p = 0
q = 0
m = 0
d.sort()
if (len(d))%2 == 0:
  m = (d[(len(d)//2)-1]+d[len(d)//2])/2
else:
  m = d[(len(d)//2)]
for i in range((len(d)//4),len(d)):
  if d[i]>=m:
    if d[i] == d[i+1]:
      break
    else:
      p = d[i]
      q = d[i-1]
      break
print(p-q)

### FIXED CODE ###

n = int(input())
d = sorted(list(map(int,input().split())))
print(d[n//2]-d[n//2-1])