peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Wrong Answer
n,k = map(int, input().split())
s = input()

rl_cnt = 0
for s1,s2 in zip(s[:-1],s[1:]):
    if s1 == 'R' and s2 == 'L':
        rl_cnt += 1

left_happy = 1 if s[0] == 'R' else 0
right_happy = 1 if s[-1] == 'L' else 0

first_happy = n - rl_cnt*2 -2 + left_happy + right_happy

if k <= rl_cnt:
    print(first_happy + k*2)
else:
    rem = k-rl_cnt
    ans = first_happy + k*2 + min(rem, left_happy+right_happy)
    print(ans)
# Judge status: Accepted
a,b=map(int,input().split())
s=input()
num_list=["0","1","2","3","4","5","6","7","8","9"]
for i in range(a+b+1):
  if i==a:
    if s[i] != "-":
      print("No")
      exit()
  else:
    if s[i] not in num_list:
      print("No")
      exit()
print("Yes")
# Judge status: Accepted
N = int(input())
v = list(map(int, input().split()))

v = sorted(v)
total = v[0]
for i in range(1, N):
    total = (total + v[i]) / 2

print(total)
# Judge status: Wrong Answer
N, K = map(int, input().split())
p = list(map(int, input().split()))
print(sum(sorted(p)[:3]))
# Judge status: Accepted
import sys


def main():
    input = sys.stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))
    ans = 0
    for i in range(0, n, 2):
        ans += a[i] % 2 == 1
    print(ans)


if __name__ == "__main__":
    main()
# Judge status: Accepted
N = int(input())

XA = []
XB = []
for i in range(N):
    A, B = (int(i) for i in input().split())
    XA.append(A)
    XB.append(B)

XA.sort()
XB.sort()

if N % 2 == 1:
    aa = XA[ (N - 1) // 2] 
    bb = XB[ (N - 1) // 2]
    print(bb - aa + 1)
else:
    aa1 = XA[N // 2]
    bb1 = XB[N // 2]
    aa = XA[N // 2 - 1]
    bb = XB[N // 2 - 1]
    print((bb1 + bb) - (aa1 + aa) + 1)
# Judge status: Accepted
s = input()
a = s.count("a")
b = s.count("b")
c = s.count("c")
if max(a,b,c) - min(a,b,c) <= 1:
  print("YES")
else:
  print("NO")
# Judge status: Wrong Answer
n,m = map(int,input().split())
if m%n==0:
    print(int(m//n))
    exit()
else:
  a = m//n
  l = []
  for i in range(int(a**0.5)+1,1,-1):
    if m%i==0:
      print(i)
      exit()
print(1)
# Judge status: Accepted
a,b,c,d=map(int,input().split())
xy=[a*c,a*d,b*c,b*d]
print(max(xy))
# Judge status: Accepted
from math import gcd
from functools import reduce

input()
a = list(map(int, input().split()))
print(reduce(gcd, a))
# Judge status: Accepted
a, b = map(int, input().split())
print(a * b)
# Judge status: Accepted
n = int(input())

l = {}
for i in range(1, n+1):
    l[i] = 0

for x in range(1, min(101, n)):
    for y in range(1, min(101, n)):
        for z in range(1, min(101, n)):
            m = (x + y + z) ** 2 - (x*y + y*z + z*x)
            if m <= n:
                l[m] += 1
for i in range(1, n+1):
    print(l[i])
# Judge status: Accepted
N,K=map(int,input().split())
S=input()
#LとRが入れ替わる回数-2Kが、終わった後の入れ替わる数
#Total-入れ替わる数-1がこたえ

trans=0
for i in range(N-1):
  if S[i]!=S[i+1]:
    trans += 1
trans_new = max(trans - 2*K,0)
print(N-trans_new-1)
# Judge status: Accepted
N = int(input())
sum = 0
for i in range(0,N+1):
  sum += i
 
print(sum)
# Judge status: Wrong Answer
import numpy as np

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

print(np.where(A == 0)[0][0])
# Judge status: Accepted
a,b,c = map(int,input().split("/"))
ans = "Heisei"
if b > 4:
  ans = "TBD"
print(ans)
# Judge status: Wrong Answer
N = int(input())
A = [int(input()) for _ in range(N)]

ans = 0
rest = 0
for a in A:
    if rest == 0:
        ans += a // 2
        rest = a % 2
    else:
        if (ans + rest) % 2 == 0:
            ans += (a + rest) // 2
            rest = (a + rest) % 2
        else:
            ans += a % 2
            rest = 0

print(ans)
# Judge status: Wrong Answer
import copy
a,b,c = map(int,input().split())
cnt = 0
while 1:
    cnt += 1 
    next_a = b // 2 +  c // 2
    next_b = a // 2 + c // 2
    next_c = a // 2 + b // 2
    if a == next_a and b == next_b and c == next_c:
        print(-1)
        break
    elif (next_a % 2 == 1) or (next_b % 2 == 1) or (next_c % 2 == 1):
        print(cnt)
        break
    a = copy.deepcopy(next_a)
    b = copy.deepcopy(next_b)
    c = copy.deepcopy(next_c)
# Judge status: Accepted
W,H,N = map(int,input().split())
w = W*[1]
h = H*[1]

for n in range(N):
  x,y,a = map(int,input().split())
  if a == 1:
    w[:x] = x*[0]
  elif a == 2:
    w[x:] = (W-x)*[0]
  elif a == 3:
    h[:y] = y*[0]
  else:
    h[y:] = (H-y)*[0]

print(w.count(1)*h.count(1))
# Judge status: Wrong Answer
n = int(input())
ans = 0
while True:
    if n < pow(2, ans + 1):
        break
    else:
        ans += 1
print(ans)
# Judge status: Wrong Answer
K,S=map(int,input().split())
ans=0
#a=max(0,S-2*K)
for i in range(K+1):
  if i>S:
    break
  for j in range(K+1):
    if S-i+j<=K :
      ans+=1

print(ans)
# Judge status: Accepted
card = []
check = [False for i in range(9)]
for i in range(3):
  card += list(map(int, input().split()))
N = int(input())
for i in range(N):
  a = int(input())
  if a in card:
    check[card.index(a)] = True
ans = "No"
for i in range(3):
  if check[i] and check[3+i] and check[6+i]:
    ans = "Yes"
  if check[i*3] and check[i*3+1] and check[i*3+2]:
    ans = "Yes"
if check[4] and ((check[0] and check[8])or(check[2] and check[6])):
  ans = "Yes"
  
print(ans)
# Judge status: Wrong Answer
import math
N = int(input())

sum = 0
for i in range(1, N):
    count = 2 
    for j in range(2, int(math.floor(math.sqrt(i)))+1):
        if i % j == 0:
            if i/j == j:
                count += 1
            else:
                count += 2
    sum += count

print(sum)
# Judge status: Accepted
a = int(input())
ans = a + a**2 + a**3
print(int(ans))
# Judge status: Accepted
from fractions import gcd
from functools import reduce

N, *A = map(int, open(0).read().split())

def lcm(x, y):
    return x * y // gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

MOD = 10 ** 9 + 7
num = lcm_list(A)
print(sum(num * pow(v, MOD - 2, MOD) for v in A) % MOD)
# Judge status: Accepted
N,M= map(int, input().split())
if N==M:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
arr = []
for _ in range(4):
  arr.append(int(input()))

if arr[1] > arr[0]:
  arr[1] = arr[0]
charge = arr[1]*arr[2] + (arr[0]-arr[1])*arr[3]
print(charge)
# Judge status: Accepted
s = int(input())
lst = [0 for i in range(s)]
def find(x):
    if (x < 6):
        return(1)
    else:
        ans = 0
        for i in range(x - 3):
            ans = ans + lst[i]
        return (ans + 1)

for i in range(s):
    if (i < 2):
        pass
    else:
        j = i + 1
        lst[i] = find(j)%(10**9 + 7)

print(lst[s - 1])
# Judge status: Accepted
N = int(input())

ans = 0
for i in range(1,N+1):
    if len(str(i)) % 2 == 1:
        ans += 1

print(ans)
# Judge status: Accepted
import collections
N = int(input())
A = list(map(int, input().split()))

C = collections.Counter(A)

for i in range(1, N+1):
    if i in C.keys():
        print(C[i])
    else:
        print(0)
# Judge status: Accepted
x, y = map(int, input().split())
count = 0

for num in range(x + 1):
   if  num * 4 + (x - num) * 2 == y:
       count += 1

print("Yes" if count > 0 else "No")
# Judge status: Accepted
def solve_131b(n, l):
    sum = 0
    min = 100000
    for i in range(1, n+1):
        sum += (l + i - 1)
    
    if l >= 0:
        min = l
    elif l + n - 1 <= 0:
        min = l + n - 1
    else:
        min = 0
    
    return sum - min

n, l = map(int, input().split())
print(solve_131b(n, l))
# Judge status: Wrong Answer
import numpy as np
c = np.ones([3,3])
for i in range(3):
    c[i] = [int(j) for j in input().split()]
    
if ((((c[2]-c[1])/(c[2]-c[1])[0])).all() ==(((c[2]-c[0])/(c[2]-c[0])[0])).all()) & ((((c[:][2]-c[:][1])/((c[:][2]-c[:][1])[0])).all()) ==(((c[:][2]-c[:][0])/(c[:][2]-c[:][0])[0])).all()):
    print("Yes")
else:
    print("No")
# Judge status: Accepted
n, k = map(int, input().split())
h = list(map(int, input().split()))

INF = 10**12
dp = [INF] * n
dp[0] = 0

for i in range(n):
    if i == 1:
        dp[1] = abs(h[1] - h[0])
        continue

    for j in range(1, k + 1):
        if i - j < 0:
            continue
        dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]))
print(dp[-1])
# Judge status: Accepted
d,t,s=map(int,input().split())
print('Yes' if d/s<=t else 'No')
# Judge status: Accepted
N = int(input())
a = [input()]
for i in range(N-1):
    w = input()
    if not w in a and a[-1][-1] == w[0]:
        a.append(w)
    else:
        print("No")
        break
else:
    print("Yes")
# Judge status: Accepted
D=int(input())
C=list(map(int,input().split()))
S=[list(map(int,input().split())) for i in range(D)]
T=[]
result=0
last=[0 for i in range(26)]

#初期解の算出
for i in range(D):
    change=[S[i][j]-(last[j]+1)*C[j] for j in range(26)]
    t=change.index(max(change))
    T.append(t+1)
    result+=S[i][t]
    last[t]=-1
    for j in range(26):
        last[j]+=1
        result-=C[j]*last[j]

for i in range(D):
    print(T[i])
# Judge status: Wrong Answer
N, A, B = map(int, input().split())
D = B - A
if D % 2 == 0:
    print(D // 2)
else:
    print(min(B - 1, N - A))
# Judge status: Wrong Answer
Q, H, S, D = map(int, input().split())
N = int(input())

# Q,H を 1Lあたりの費用に変換する

Q *= 4
H *= 2

one_litter = min(Q, H, S)  # 1L はこれを使う

if 2 * one_litter < D:  # 2Lをサイズのほうが高いときは1Lですべて買う
    ans = N * one_litter
else:  # 偶数を2Lサイズで買い、余りを1Lサイズで買う
    ans = N // 2 * D + one_litter

print(ans)
# Judge status: Wrong Answer
h,w = map(int,input().split())
if(h*w%2 ==0):
    print(int(h*w/2))
else:
    print(int(h*w/2)+1)
# Judge status: Accepted
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
#%%code
def resolve():
    N,M=pin()
    
    t=M//2
    if t<N:
        print(t)
        return
    M-=N*2
    ans=N
    ans+=M//4
    print(ans)
#%%submit!
resolve()
# Judge status: Accepted
import bisect

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

ans = 0
for i in range(N):
    for j in range(i+1, N):
        ans += bisect.bisect_left(L, L[i]+L[j]) - 1 - j

print(ans)
# Judge status: Wrong Answer
N, M = input().split()
 
if N==M :
  print('YES')
else:
  print('NO')
# Judge status: Accepted
def main():
    N, K = (int(i) for i in input().split())
    _ = [int(i) for i in input().split()]
    print(0--(N-1)//(K-1))


if __name__ == '__main__':
    main()
# Judge status: Accepted
a, b, c = map(int, input().split())

if a + b == c or a + c == b or b + c == a:
  print("Yes")
else:
  print("No")
# Judge status: Accepted
N, M = map(int,input().split())
alist = list()
for _ in range(M):
    alist.append(int(input()))


li = {}
li[0] = 1

for i in range(1,N+1):
    if len(alist)>=1 and i ==  alist[0]:
        li[i] = 0
        alist.pop(0)
    else:
        if i == 1:
            li[i] = 1
        else:
            li[i] = ((li[i-1] + li[i-2])%(10**9+7))
print(li[N]%(10**9+7))
# Judge status: Wrong Answer
import sys
input = sys.stdin.readline

N=int(input())
A=list(map(int,input().split()))
total = sum(A)
mindif = 1e12
sub = 0
for i in range(N):
    sub += A[i]
    dif = abs(total-sub-sub)
    if dif < mindif:
        mindif = dif
    else:
        break
print(mindif)
# Judge status: Accepted
print(sum(sorted(list(map(int,input().split())))[:2]))
# Judge status: Wrong Answer
A, B, C, K = map(int, input().split())

m = A - B

if (K % 2 == 0):
    print(m)
else:
    if (abs(m) >= 10**18):
        print('Unfair')
    print(abs(m))
# Judge status: Wrong Answer
O =input()
E = input()
for a,b in zip(O,E):
    print(a+b, end="")
# Judge status: Accepted
n = int(input())
al = list(map(int, input().split()))

ans = 0
for i in range(n-1):
    if al[i] >= al[i+1]:
        ans += al[i]-al[i+1]
        al[i+1] += (al[i]-al[i+1])

print(ans)
# Judge status: Wrong Answer
a , b, c = map(int, input().split())

if a + b + c < 22:
  	print('win')
else:
  	print('burst')
# Judge status: Accepted
N, A, B = map(int, input().split())
ans = 0
for i in range(1, N+1):
  j = list(str(i))
  n = len(j)
  a = 0
  for l in range(n):
    a += int(j[l])
  if a >= A and a <= B:
    ans += i
print(ans)
# Judge status: Accepted
import sys
import math
import bisect

def main():
    n, m = map(int, input().split())
    A = list(map(int, input().split()))
    B = [0]
    for a in A:
        B.append(B[-1] + a)
    ans = 0
    for b in B:
        if b <= m:
            ans += 1
    print(ans)

if __name__ == "__main__":
    main()
# Judge status: Wrong Answer
import math
import sys
import collections
import bisect
readline = sys.stdin.readline


def main():
    keyence = "keyence"
    s = readline().rstrip()
    lenS = len(s)
    for i in range(1, 7):
        if s.count(keyence[0:i]) > 0:
            idx = s.index(keyence[0:i]) + i
            if s[idx-1:lenS].count(keyence[i:7]) > 0:
                print("YES")
                return
    print("NO")


if __name__ == '__main__':
    main()
# Judge status: Accepted
import math
from functools import reduce

def gcd(numbers):
    return reduce(math.gcd, numbers)

def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    ans = gcd(sorted(A,reverse=True))
    print(ans)

if __name__ == '__main__':
    main()
# Judge status: Accepted
from bisect import bisect_right

N, M, K = map(int, input().split())
A = [0] + list(map(int, input().split()))
B = [0] + list(map(int, input().split()))

for i in range(1, N+1):
    A[i] += A[i-1]

for i in range(1, M+1):
    B[i] += B[i-1]

b_cnt = M

ans = 0
for a_cnt in range(N+1):
    if A[a_cnt] > K:
        continue

    rest = K - A[a_cnt]

    while A[a_cnt] + B[b_cnt] > K:
        b_cnt -= 1

    ans = max(ans, a_cnt + b_cnt)

print(ans)
# Judge status: Accepted
def main():
    S = input()
    L = len(S)
    a, b = 0, 0
    for i in range(L):
        if i % 2 == 0:
            if S[i] == '0':
                a += 1
            else:
                b += 1
        else:
            if S[i] == '1':
                a += 1
            else:
                b += 1
    print(min(a, b))


if __name__ == '__main__':
    main()
# Judge status: Accepted
a = int(input())
if a >= 30:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
N,M=map(int,input().split())
arr=[[0,1,0] for _ in range(N)]
arr[0]=[1,1,1]
for i in range(M):
  a,b=map(int,input().split())
  arr[a-1][1]-=1
  arr[b-1][1]+=1
  if arr[a-1][0]==1:
    arr[b-1][0]=1
  if arr[a-1][2]==1:
    arr[a-1][2],arr[b-1][2]=0,1
  if arr[a-1][1]==0:
    arr[a-1][0]=0
ans=0
for i in range(N):
  if arr[i][0]==1 and arr[i][1]!=0:
    ans+=1
print(ans)
# Judge status: Accepted
n = int(input())
x = list(map(int, input().split()))
a = sorted(x)

mid_n = len(a)//2
right = a[mid_n]
left = a[mid_n-1]

for i in range(n):
    if right > x[i]:
        print(right)
    else:
        print(left)
# Judge status: Accepted
from collections import Counter
S = list(input())
c = Counter(S)
c0 = c['0']
c1 = c['1']
print(2*min(c0, c1))
# Judge status: Accepted
li = ["SUN","MON","TUE","WED","THU","FRI","SAT"]
st = input()
print(7-li.index(st))
# Judge status: Accepted
n = int(input())
l = [list(map(int,input().split())) for i in range(n-1)]
for i in range(n):
    ans = 0
    if i == n-1:
        print(0)
        exit()
    for j in range(i,n-1):
        ans = l[j][0]+l[j][1]+l[j][2]*(max(((ans-l[j][1]+l[j][2]-1)//l[j][2]),0))

    print(ans)
# Judge status: Accepted
from sys import stdin, stdout
input = stdin.readline
print = stdout.write
n, m, k = map(int, input().split())
a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))
for i in range(1, n + 1):
    a[i] += a[i - 1]
for i in range(1, m + 1):
    b[i] += b[i - 1]
i, j, z = 0, m, 0
while i <= n and a[i] <= k:
    while b[j] > k - a[i]:
        j -= 1
    z = max(z, i + j)
    i += 1
print(str(z))
# Judge status: Wrong Answer
x,y=map(int,input().split())
if y%x==0:
	print(-1)
else:
	print(x)
# Judge status: Accepted
n,m = map(int,input().split())
a = [list(map(int, input().split())) for _ in range(n)]
ans = 0
cnt = 0
a = sorted(a, key=lambda x:x[0])
for i in range(n):
    if cnt + a[i][1] <m:
        ans += a[i][0]*a[i][1]
        cnt +=a[i][1]
    else:
        ans += a[i][0]*(m-cnt)
        break
print(ans)
# Judge status: Accepted
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

MOD = 10 ** 9 + 7
N, K = lr()
answer = 0
for i in range(K, N+2):
    low = i * (i-1) // 2
    high = i * (N+N-i+1) // 2
    answer += high - low + 1
    answer %= MOD

print(answer%MOD)
# Judge status: Accepted
s = input()
lst1 = []

for i in s:
    if i in lst1:
        print("no")
        exit()
    else:
        lst1.append(i)

print("yes")
# Judge status: Accepted
import math        # factorical（階乗) # hypot(距離)
import heapq
# from fractions import gcd # Python3.5以前 # lcm（最小公倍数） = (a*b)//gcd(a,b)
# from fractions import Fraction
# from math import gcd # Python3.6以降
# --------------------------------------------------------------

n,m = map(int,input().split())
price = list(map(int,input().split()))

price = [-i for i in price]

heapq.heapify(price)

for i in range(m):
    sm = heapq.heappop(price)
    sm = -(-sm//2)
    heapq.heappush(price,sm)

price = [-i for i in price]

print(sum(price))
# Judge status: Accepted
x = int(input())
n = 120
for i in range(n):
  for j in range(i):
    if x == i**5-j**5:
      print(i,j)
      exit(0)
    if x == i**5+j**5:
      print(i,-j)
      exit(0)
# Judge status: Wrong Answer
A, B, C = map(int, input().split())

left = C // 2
right = C - left

ans = A * B * abs(left - right)
print(ans)
# Judge status: Accepted
n,y=map(int,input().split())
for i in range(n+1):
    for j in range(n-i+1):
        if 10000*i+5000*j==y-1000*(n-i-j):
            print(i,j,n-i-j)
            exit()
print(-1,-1,-1)
# Judge status: Accepted
s = input()

if s[-1] == 's':
  print(s + 'es')
else:
  print(s + 's')
# Judge status: Accepted
a,b,c = map(int,input().split())

if a < c < b or b < c < a:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
a,b=map(float,input().split())
print(int(a*(int(b*100))/100))
# Judge status: Accepted
from collections import Counter


def main():
    N = int(input())
    A = [input() for _ in range(N)]

    C = Counter(A)
    most_c = C.most_common()
    max_num = most_c[0][1]
    ANS = []
    for c in most_c:
        if c[1] < max_num:
            break
        ANS.append(c[0])
    for ans in sorted(ANS):
        print(ans)


if __name__ == '__main__':
    main()
# Judge status: Accepted
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
s=0
K=int(input())
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            s=s+gcd(i,j,k)
print(s)
# Judge status: Accepted
s = input()
t =s[::-1]
a = s.index('A')
z = t.index('Z')

print(len(s)-a-z)
# Judge status: Wrong Answer
# C - Same Integers
# https://atcoder.jp/contests/abc093/tasks/arc094_a

nums = list(map(int,input().split()))
abc= sum(nums)
X = max(nums)


if X%2 != abc%2:
    X + 1
print((3*X - abc)//2)


# 増加させるかず -> 3X - abc
# 操作回数      -> (3X - abc) //2
# Judge status: Accepted
n = int(input())
if n % 2 == 1:
    print(0)
else:
    n //= 2
    ans = 0
    while n >= 5:
        n //= 5
        ans += n
    print(ans)
# Judge status: Accepted
a,b = map(int,input().split())
if a >b:
    print(2*a-1)
elif a == b:
    print(a+b)
else:
    print(2*b-1)
# Judge status: Accepted
a,b = map(int,input().split())

if a % 3 == 0 or b % 3 == 0 or (a + b) % 3 == 0:
    print("Possible")
else:
    print("Impossible")
# Judge status: Accepted
import sys
import math

count = 0
N, D = map(int, input().split())
for _ in range(N):
  x, y = map(int, input().split())
  dis = math.sqrt(x ** 2 + y ** 2)
  if dis <= D:
    count += 1
print(count)
# Judge status: Accepted
# coding: utf-8
# Your code here!

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

for i in range(A, B + 1):
    if i % K == 0:
        print('OK')
        exit()
else:
    print('NG')
# Judge status: Wrong Answer
K,A,B=map(int,input().split())
bis=1
if K==1:
  bis+=1
elif A>=B-1 or K-A+1<=0:
  bis+=K
else:
  if (K-(A-1))%2==0:
    bis=A+int((B-A)*(K-(A-1))//2)
  else:
    bis=A+(B-A)*(K-(A-1))//2+1
print(bis)
# Judge status: Accepted
import sys

L,R,d = map(int, sys.stdin.readline().split())
#N = int(sys.stdin.readline())

ans = 0
for i in range(1,int(R/d) + 1):
    if d * i < L:
        continue
    if d * i > R:
        break

    ans += 1

print(ans)
# Judge status: Accepted
n = int(input())
w = list(map(int,input().split()))
l = []
for i in range(n):
    a = (abs(sum(w[:i+1]) - sum(w[i+1:])))
    l.append(a)
print(min(l))
# Judge status: Wrong Answer
import sys
import collections
INF = 10**18
ans = 0
import math

if __name__ == "__main__":
    n = int(input())
    a = sorted(list(map(int,input().split())))
    l = 1
    for i in range(1,n):
        c = math.gcd(a[0],a[i])
        ans = max(ans,c)
    print(ans)
# Judge status: Accepted
a,b=map(int,input().split())
s=str(input())
f= s[a]=="-" and len(s)==a+b+1 and s.count("-")==1
print("Yes" if f is True else "No")
# Judge status: Accepted
N=int(input())
A=[int(s) for s in input().split(" ")]
B=[int(s) for s in input().split(" ")]

Ans1=0
Ans1=sum(A)

for i in range(N):
    if B[i]-A[i]<0:
        A[i]=A[i]-B[i]
    else:
        A[i+1]=max(A[i+1]-(B[i]-A[i]),0)    
        A[i]=0

Ans2=0
Ans2=sum(A)        
        
print(Ans1-Ans2)
# Judge status: Wrong Answer
s = input()

ans0 = 0
ans1 = 0
for i, s_i in enumerate(s):
    if i % 2 == 0:
        if s_i == '0':
            ans1 += 1
        else:
            ans0 += 1
    else:
        if s_i == '0':
            ans0 += 1
        else:
            ans1 += 1
print(ans0, ans1)
print(min(ans0, ans1))
# Judge status: Accepted
def main():
    import sys

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

    s = input()
    word = ['eraser', 'erase', 'dreamer', 'dream']
    for x in word:
        s = s.replace(x, '')
    if s == '':
        print('YES')
    else:
        print('NO')
        
        
        
            
        
    
    
if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
n = int(input())
s = list(input())
mod = 10**9+7
alp = [0] * 26

for i in range(n):
    alp[ord(s[i]) - ord("a")] += 1

ans = 1
for c in alp:
    if (c != 0):
        ans *= (c+1) % mod

print(ans - 1)
# Judge status: Accepted
n, y = map(int, input().split())
for i in range(n + 1):
  for ii in range(n - i + 1):
    if 10000 * i + 5000 * ii + 1000 * (n - i - ii) == y:
      print('{} {} {}'.format(i, ii, n - i - ii))
      exit()
print('-1 -1 -1')
# Judge status: Wrong Answer
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
cd=[list(map(int,input().split())) for _ in range(m)]
for i in ab:
	e=10**8
	f=0
	for p,j in enumerate(cd):
		g=abs(i[0]-j[0])+abs(i[1]-j[1])
		if e>g:
			e,f=g,p
	print(f+1)
# Judge status: Wrong Answer
import cmath
import sys

INF=10**18
MOD=10**9+7
MAX=10**5+7



def main():
  A,B,M=map(int, input().split())
  a=list(map(int, input().split()))
  b=list(map(int, input().split()))
  
  ans=min(a)+min(b)
  for i in range(M):
    x,y,c=map(int, input().split())
    x-=1
    y-=1
    ans=max(ans, a[x]+b[y]-c)
  
  print(ans)
  
  
if __name__=='__main__':
    main()
# Judge status: Accepted
N=int(input())

A=[0]*(N+1)
for k in range(1,N+1):
    A[k]=int(input())

T=[False]*(N+1)
x=1
I=0
while not T[x] and x!=2:
    T[x]=True
    I+=1
    x=A[x]
    
if x==2:
    print(I)
else:
    print(-1)
# Judge status: Accepted
N = int(input())
k = 0

while True:
    if 2**k > N:
        break

    ans = 2 ** k
    k +=1
print(ans)
# Judge status: Accepted
n,a,b=map(int,input().split())

if a>b:
  print(0)
elif a==b:
  print(1)
elif n==1:
  print(0)
elif n==2:
  print(2)
else:
  print((b-a)*(n-2)+1)
# Judge status: Accepted
N,K = map(int,input().split())

N = N % K

if K - N > N:
  print(N)
  exit()
print(K - N)
# Judge status: Accepted
n = int(input())
line = list(input())

# 各地点の人について，背を向けている人を数える。無駄が多い？
back = [0] * n
wester, easter = 0, 0
for i, p in enumerate(line):
    back[i] = wester

    if p == 'W':
        wester += 1
i = n
for p in line[::-1]:
    i -= 1
    back[i] += easter

    if p == 'E':
        easter += 1

print(min(back))