peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted

S = input()

S = S[::-1]

cand = {'maerd', 'remaerd', 'esare', 'resare'}

can = True

while S not in cand:
    ok = False
    for x in cand:
        if S[:len(x)] == x:
            S = S[len(x):]
            ok = True
            break
    if ok == False:
        can = False
        break

if can == True:
    print('YES')
else:
    print('NO')
# Judge status: Wrong Answer
import sys
readline = sys.stdin.readline

S = readline().strip()
T = readline().strip()

s = len(S)
t = len(T)
ans = t
for i in range(0, s-t):
  n = t
  for j in range(t):
    if S[i+j] == T[j]:
      n -= 1
  if n < ans:
    ans = n
  if ans == 0:
    break
print(ans)
# Judge status: Accepted
n,k=map(int,input().split())
A=list(map(int,input().split()))
C=[n for _ in range(n)]

while k!=0:
    B=[0 for _ in range(n+1)]
    for i,j in enumerate(A):
        B[max(0,i-j)] +=1
        B[min(n,i+j+1)] -=1
    for i in range(1,n):
        B[i] +=B[i-1]
    A=B[:n]
    k -=1
    if A==C:break
print(*A)
# Judge status: Wrong Answer
H = int(input())

cnt = 0
while H > 3:
    H = H//2
    cnt += 1
ans = 0
for i in range(cnt):
    ans += 2**i
print(int(((2**cnt)*3)+ans))
# Judge status: Wrong Answer
A,B,C=map(int,input().split())
p=3
if A==B:
  p=p-1
if A==C:
  p=p-1
print(p)
# Judge status: Accepted
N = int(input())
ans = 1000 - (N%1000)
if ans == 1000:
    print(0)
else:
    print(ans)
# Judge status: Wrong Answer
n=int(input())
k = [list(map(int, input().split())) for i in range(n)]
import math
ans=0
for i in range(n-1):
    for j in range(i+1,n):
        z=math.sqrt((k[i][0]-k[j][0])**2+((k[i][0]-k[j][0])**2))
        ans+=2*z
print(ans)
# Judge status: Wrong Answer
n,m = map(int,input().split())
A = list(map(int,input().split()))
for i,a in enumerate(A):
    A[i] //=2
from math import gcd,ceil
def lcm(a, b):
    return a*b//gcd(a,b)
b = 1
for i in range(n):
    a = A[i]
    b = lcm(a,b)
    if b >m:print(0);exit()

print(ceil((m//b)/2))
# Judge status: Accepted
import numpy as np
 
X = int(input())
X_lcm = np.lcm(360, X)
print(X_lcm // X)
# Judge status: Accepted
K,N=map(int,input().split())
A=list(map(int,input().split()))
a=A[N-1]-A[0]
for i in range(1,N):
    if i!=N-1:
        a=min(a,K+A[i-1]-A[i],K+A[i+1]-A[i])
    else:
        a=min(a,K+A[i-1]-A[i])
print(a)
# Judge status: Accepted
n=int(input())
a=int(input())
print('Yes' if a-(n%500) >= 0 else 'No')
# Judge status: Accepted
N = int(input())
s = [int(input()) for _ in range(N)]

if sum(s)%10 != 0:
    print(sum(s))
    exit()

ans = 0

for i in s:
    tmp = sum(s) - i
    if tmp%10 != 0:
        ans = max(ans,tmp)

print(ans)
# Judge status: Accepted
N,K = map(int, input().split())
# p[i]での出目の期待値
P = [(int(i) + 1) / 2 for i in input().split()]

from itertools import accumulate

P = [0] + list(accumulate(P))

ans = 0
for i in range(N - K + 1):
    ans = max(ans, P[i + K] - P[i])

print(ans)
# Judge status: Wrong Answer
n, m = map(int, input().split())

if n == m == 1:
    print(0)
elif min(n, m) == 1:
    print(max(n,m)-2)
else:
    print((n-2) * (m-2))
# Judge status: Accepted
n = int(input())

ans = []
for i in range(1,10**6+1):
    if n % i == 0:
        ans.append(i+(n//i)-2)

print(min(ans))
# Judge status: Accepted
s = input()
odd = []
even = []
for i in range(len(s)):
    if i % 2 == 0:
        even.append(s[i])
    else:
        odd.append(s[i])

ans = even.count('0') + odd.count('1')
if ans > even.count('1') + odd.count('0'):
    ans = even.count('1') + odd.count('0')

print(ans)
# Judge status: Accepted
import math

X = int(input())
sqX = math.floor(X**(1/2))
temp = sqX**2
i = 0
while True:
    t = sqX + i
    temp = t*(t+1) // 2
    if temp >= X:
        print(sqX + i)
        break
    i += 1
# Judge status: Accepted
n, k = map(int, input().split())
d = list(map(str, input().split()))
"""
l = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
for i in range(k):
    for j in range(len(l)):
        if d[i] == l[j]:
            l.pop(j)
            break
"""
while True:
    tmp = list(str(n))
    flag = True
    for i in range(len(d)):
        if d[i] in tmp:
            flag = False
            break
    if flag:
        break
    n += 1
print(n)
# Judge status: Accepted
n = int(input())
a = [int(input()) for _ in range(n)]

my_set = set()

for item in a:
    if item in my_set:
        my_set.remove(item)
    else:
        my_set.add(item)

print(len(my_set))
# Judge status: Wrong Answer
L=int(input())
print(L)
print('{:.6f}'.format(L**3/27))
# Judge status: Accepted
n, k = map(int, input().split())
A = tuple(map(int, input().split()))
A = sorted(A, reverse=True)

l = 0
r = max(A)+1
def cut(l, k):
    # 長さlの丸太を最大とすることができるかどうかを返す
    for a in A:
        if a > l:
            k -= (-(-a//l) - 1)
    return k >= 0

while r-l > 1:
    mid = (r+l)//2
    if cut(mid, k):
        r = mid
    else:
        l = mid
print(r)
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))
sum = 1

for i in range(n):
    if a[i] == 0:
        print(0)
        exit(0)

for i in range(n):
    sum *= a[i]
    if(sum > 1000000000000000000):
        print(-1)
        exit(0)

print(sum)
# Judge status: Wrong Answer
s, t = input().split()
a, b = list(map(int, input().split()))
u = input()
if s == u:
  print(a-1, b)
elif s == t:
  print(a, b-1)
# Judge status: Accepted
X, Y = map(int, input().split())

ans = 0
num = X
while num<= Y:
    ans += 1
    num *= 2

print(ans)
# Judge status: Accepted
N=int(input())
A=[int(i) for i in input().split()]
A.sort()
cnt={}
K=list(set(A))
K.sort()
for k in K:
  cnt[k]=0
for a in A:
  cnt[a]+=1
E=[]
for k in K:
  if cnt[k]>=2:
    if cnt[k]>4:
      E.append(k)
    E.append(k)
E.sort()
# print(E)
if len(E)>=2:
  print(E[-1]*E[-2])
else:
  print(0)
# Judge status: Accepted
N,M = map(int,input().split())
a = [int(input()) for i in range(M)]
a = set(a)

dp = [0]*(N+100)
for i in range(N+1):
  if i == 0:
    dp[i] = 1
    continue
  if i in a:
    continue
  elif i-1 in a:
    dp[i] = dp[i-2]
  elif i-2 in a:
    dp[i] = dp[i-1]
  elif i-1 in a and i-2 in a:
    break
  else:
    dp[i] = dp[i-1] + dp[i-2]
  dp[i] = dp[i]%(7+10**9)
    
print(dp[N]%(7+10**9))
# Judge status: Accepted
# AtCoder
from collections import Counter
S = list(input())
T = list(input())
if sorted(Counter(S).values()) == sorted(Counter(T).values()):
    print('Yes')
else:
    print('No')
# Judge status: Accepted
D, T, S = map(int, input().split())

if D > T * S:
    print("No")
else:
    print("Yes")
# Judge status: Accepted
n,k = map(int,input().split())
ans = 0

for i in range(n):
  count = i+1
  p = 1/n
  
  while count < k:
    count = count*2
    p = p/2
  
  ans = ans + p
  
print(ans)
# Judge status: Accepted
N = int(input())
A = [int(x) for x in input().split()]
B = [int(y) for y in input().split()]
sum = 0
for i in range(N):
    sum += min(A[i],B[i])
    sum += min(max(B[i]-A[i],0),A[i+1])
    A[i+1] += max(min(A[i]-B[i],0),-A[i+1])
print(sum)
# Judge status: Accepted
n = input()
val = int(n)+1
s = 0
for i in range(val):
    s += i
else:
    print(s)
# Judge status: Wrong Answer

N,T = map(int,input().split())
ans = [1000,0]
status = 0

for i in range(N):
    c,t = map(int,input().split())

    if t <= T and c < ans[0]:
        ans[0] = c
        ans[1] = t
        status = 1
    else:
        pass

if status == 0:
    print("TLE")
else:
    print(ans[0])
# Judge status: Wrong Answer
k,s = map(int,input().split())
ans = 0
if s>3*k:
    print(0)
elif s==3*k:
    print(1)
elif s-k<=0:
    for i in range(s+1,0,-1):
        ans += i
else:
    for i in range(k+1):
        for j in range(k+1):
            if s-k<=i+j<=s: 
                ans += 1
print(ans)
# Judge status: Accepted
List=list(map(int,input().split()))
List.sort()
K=int(input())
for i in range(K):
    List[2]*=2
print(sum(List))
# Judge status: Accepted
x, n = map(int, input().split())
if n == 0:
    print(x)
    exit()
p = sorted([-999] + list(map(int, input().split())) + [999])

from bisect import bisect_left, bisect_right

if x not in p:
    print(x)
    exit()

# 小さい方
m = p.index(x) - 1
target_L = x - 1
while True:
    if target_L not in p:
        break
    target_L -= 1

target_R = x + 1
while True:
    if target_R not in p:
        break
    target_R += 1

if abs(target_L - x) <= abs(target_R - x):
    print(target_L)
else:
    print(target_R)
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))

money = 1000
ticket = 0
for i in range(N - 1):
    # buy
    if A[i] < A[i + 1]:
        ticket += money // A[i]
        money -= (money // A[i]) * A[i]
    elif A[i] == A[i + 1]:
        pass
    # sell
    else:
        money += A[i] * ticket
        ticket = 0

money += A[-1] * ticket

print(money)
# Judge status: Accepted
n=list(map(int,input()))[0]
a = list(map(int, input().split()))
count=1

l=[]
for i in a:
    l.append(i-count)
    count+=1
import numpy
l=numpy.array(l)
b=numpy.median(l)
ans=0
for i in l:
    ans+=abs(i-b)
print(int(ans))
# Judge status: Accepted
N = int(input())
rem = N%1000
if rem == 0:
    print(0)
else:
    print(1000 - N%1000)
# Judge status: Wrong Answer
N = int(input())
Dp = [a for a in range(N + 1)]
for i in range(1, N + 1):
    for j in range(1,7):
        if i > (6 ** j):
            Dp[i] = min(Dp[i], Dp[i-6**j] + 1)
    for h in range(1,6):
        if i > (9 ** h):
            Dp[i] = min(Dp[i], Dp[i-9**h] + 1)
print(Dp[N])
# Judge status: Wrong Answer
def main():
    X = input()
    count = 0
    for i in range(2*10**2):
        count += X.count("ST")
        X = X.replace("ST","")
    print(len(X))


if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
n,t = map(int, input().split())
y = 10**5
for i in range(n):
    c,x = map(int,input().split())
    if x<=t:
        y=min(y,c)
print(y)
# Judge status: Wrong Answer


import numpy as np

n=int(input())
a=np.array([int(input()) for i in range(n)])
a=np.sort(a)
ans=0
for i in range(n):
    c=0
    while(i<=n-2 and a[i]==a[i+1]):
        i+=1
        c+=1
    if(c%2==1):ans+=1
print(ans)
# Judge status: Wrong Answer
piza = list(map(int,input().split()))
x = piza[0] * piza[3] + piza[1] * piza[4] #普通に買うパターン
y = piza[2] * 2 * max(piza[3],piza[4])

if piza[3] >= piza[4]:
    z = piza[2] * (2 * piza[4]) + piza[0] * (piza[3] - piza[4])
else:
    z = piza[2] * (2 * piza[3]) + piza[0] * (piza[4] - piza[3])
print(min(x,y,z))
# Judge status: Wrong Answer
n,m=map(int,input().split())
if m%2 == 0:
	[print(n // 2 - i, 1 + i) for i in range(m // 2)]
	[print(n // 2 + 1 + i, n // 2 + m // 2 + 1 - i) for i in range(m // 2)]
else:
	[print(n // 2 - i, 1 + i) for i in range(m // 2)]
	[print(n // 2 + m//2 + i + 1, n // 2 + m // 2 - i) for i in range(m // 2 + 1)]
# Judge status: Accepted
import heapq
N,M = map(int, input().split())
A = list(map(lambda x: -int(x), input().split()))
heapq.heapify(A)
ans = 0
for i in range(M):
    most_expensive = -heapq.heappop(A)
    most_expensive //= 2
    heapq.heappush(A, -most_expensive)
print(-sum(A))
# Judge status: Accepted
import fractions
from functools import reduce

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

n,x = map(int,input().split())
y = list(map(int,input().split()))
dist = []
for b in y:
    dist.append(abs(b-x))
print(gcd_list(dist))
# Judge status: Accepted
n,m=map(int,input().split())
make=min(n,m//2)
n-=make ; m-= make*2
print(make + max(0,m//4))
# Judge status: Wrong Answer
n, k = map(int, input().split())
a = list(map(int, input().split()))

print(-(-n//(k-1)) if n != k else 1)
# Judge status: Wrong Answer
x,y,a,b,c=map(int,input().split())
P=sorted(list(map(int,input().split())))[::-1]
Q=sorted(list(map(int,input().split())))[::-1]
R=sorted(list(map(int,input().split())))[::-1]+[0]*(x+y)
L=sorted(P[:x]+Q[:y])[::-1]
l=r=0
for i in range(x+y):    
    if r+R[i]<l+L[-i-1]:
        break
    r+=R[i]
    l+=L[-i-1]
print(sum(L[:x+y-i])+r)
# Judge status: Accepted
n,m=map(int,input().split())
a=list(map(int,input().split()))
if sum(a)>n:
  print(-1)
else:
  print(n-sum(a))
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))

b = [0]*n
for i in range(n)[::-1]:
    tmp = 0
    for j in range(n//(i+1)):
        tmp += b[(i+1)*(j+1)-1]
    if tmp%2 != a[i]:
        b[i] += 1

print(sum(b))
ans = [i+1 for i in range(n) if b[i]]
print(*ans)
# Judge status: Accepted
N = int(input())
a = list(map(int,input().split()))

acnt =0
bcnt=0
a.sort(reverse=True)

for i in range(len(a)):
    if i%2==0:
        acnt += a[i]
    else:
        bcnt += a[i]
    
print(acnt-bcnt)
# Judge status: Accepted
import math
N, D = map(int, input().split())
ans = 0
for _ in range(N):
    x, y = map(int, input().split())
    if math.sqrt( x ** 2 + y ** 2 ) <= D:
        ans += 1
print(ans)
# Judge status: Accepted
S = input()

ans = 0

def f(i):
  ans = 0
  for c in S:
    if int(c)==i: ans += 1
    i = (i+1)%2
  return ans

ans = min(f(0),f(1))

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

print(min(abs(x-a),abs(x-b)))
# Judge status: Accepted
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    n, p = map(int, input().split())
    A = list(map(int, input().split()))

    dp = [1, 0]
    for a in A:
        if a & 1:
            s = sum(dp)
            dp = [s, s]
        else:
            dp = [dp[0] * 2, dp[1] * 2]

    print(dp[p])
resolve()
# Judge status: Wrong Answer
a,b = map(int,input().split())
print((a + b) / 2)
# Judge status: Accepted
N, K = map(int, input().split())
H = [int(i) for i in input().split()]

H.sort(reverse = True)

print(sum(H[K:]))
# Judge status: Wrong Answer
import sys
input = sys.stdin.readline
MOD = 10**9 + 7
INF = float('INF')

def main():
    s = input()
    ans = 0

    for i in range(len(s)//2 + 1):
        if s[i] != s[-(i+1)]:
            ans += 1

    print(ans)

if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
import collections
s = str(input())
l = []
for i in range(0,4):
  l.append(s[i])
  i += 1
c = collections.Counter(l)
print(len(c))
# Judge status: Wrong Answer
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

vals = []
for _ in range(M):
    i, j, v = map(int, input().split())
    print(i, j, v)
    vals.append( a[i - 1] + b[j - 1] - v)

vals.append(min(a) + min(b))
print(min(vals))
# Judge status: Accepted
x = int(input())
y = x//11
ans = 2*y

if x-y*11 == 0:
    pass
elif x-y*11 <= 6:
    ans += 1
else:
    ans += 2

print(ans)
# Judge status: Wrong Answer
n = int(input())
A = []
for _ in range(n):
    a = int(input())
    A.append(a)
ans = 0
tmp = 1
if n==1:print(1);exit()
for i in range(n-1):
    if A[i]>=A[i+1]:
        tmp += 1
        ans = max(ans,tmp)
    else:
        tmp = 1
print(ans)
# Judge status: Wrong Answer
A, B, C, X = [int(input()) for i in range(4)]
print(500*a+100*b+50*c == X for a in range(A+1) for b in range(B+1) for c in range(C+1))
# Judge status: Wrong Answer
d,n =map(int,input().split())
if n%100 != 0:
    ans = 10**d*n
else:
    ans = 10**d*n+1
print(ans)
# Judge status: Accepted
a,b,c=map(int,input().split())
x=b+c-a if a<b+c else 0;print(x)
# Judge status: Wrong Answer
a = {1, 2, 3}
a.remove(int(input()))
a.remove(int(input()))
print(list(a))
# Judge status: Accepted
n = int(input())
a = [int(i) for i in input().split()]
a.sort(reverse=True)
b = list(set(a))
b.sort(reverse=True)
l = len(b)
c = [0 for _ in range(l)]
prei = b[0]
j = 0
for i in a:
    if i != prei:
        j += 1
    c[j] += 1
    prei = i
x = []
for i in range(l):
    if c[i] >= 2:
        x.append(b[i])
    if c[i] >= 4:
        x.append(b[i])
if len(x) >= 2:
    ans = x[0] * x[1]
    print(ans)
else:
    print(0)
# Judge status: Accepted
import fractions
A,B = map(int,input().split())
print(A*B//fractions.gcd(A,B))
# Judge status: Wrong Answer
a, b, c = list(map(int, input().split()))

if (b<=a) and (c<=a):
    print("delicious")
elif (b<=a) and (c>a):
    print("safe")
elif (b>a) and (c>a):
    print("dangerous")
# Judge status: Accepted
n = int(input())
now = 1
num = 1
for i in range(1, n+1):
    now = int(i*(i+1)/2)
    if now >= n:
        num = i
        break
diff = now - n

for i in range(1,num+1):
    if i == diff:
        pass
    else:
        print(i)
# Judge status: Accepted
n, k = map(int, input().split())

x = n % k
print(min(abs(x-k), x))
# Judge status: Accepted

n,x = map(int,input().split())
l = list(map(int,input().split()))
count = 0
d = [0]

for i in range(1,len(l)+1):
    d.append(l[i-1]+d[i-1])

for i in range(len(d)):
    if d[i] <= x:
        count += 1

print(count)
# Judge status: Accepted
X=int(input())
t=int((2*X)**0.5)+1
ans=0
for i in range(t,0, -1):
    if X <= i*(i+1)/2:
        ans=i
    else:
        break
print(ans)
# Judge status: Accepted
n=int(input())
ans=0
for i in range(n):
  ans+=n-i
print(ans)
# Judge status: Accepted
N = int(input())
A = []
ex = [0]*N
light = 0
c = 0
for i in range(N) :
    A.append(int(input()))

while light != 1 :
    if ex[light] == 1 :
        print('-1')
        exit()
    ex[light] = 1
    light = A[light]-1
    c += 1
    

print(c)
# Judge status: Accepted
a, b = map(int, input().split())
 
if (a + b) % 3 == 0 or a % 3 == 0 or b % 3 == 0:
  print("Possible")
else:
  print('Impossible')
# Judge status: Accepted
N=int(input())
s=set()
for i in range(N):
    s.add(input())
print(len(s))
# Judge status: Wrong Answer
N, R1, R2 = map(int, input().split())
count={}
for m in range(N-1):
    count[m+1] = 0 
for i in range(N):
    for j in range(i+1, N):
        if i <= R1-1 and j >= R2-1:
            count[j-i-(R2-R1-1)] +=1
        else:
            count[j-i] += 1
for k in count.values():
    print(k)
# Judge status: Accepted
def Csum(a):
    b,c=[0],0
    for i in range(len(a)):
        c+=a[i]
        b.append(c)
    return b

n,k=map(int,input().split())
a=list(map(int,input().split()))
if k>100:
    a=[n]*n
    print(*a)
    exit()
for i in range(k):
    b=[0]*(n+1)
    for j in range(n):
        l,r=max(0,j-a[j]),min(n,j+a[j]+1)
        b[l]+=1
        b[r]-=1
    a=Csum(b)[1:-1]
print(*a)
# Judge status: Accepted
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=0
for i in range(n):
    if b[i]>a[i]:
        ans+=a[i]
        b[i]-=a[i]
        if b[i]>a[i+1]:
            ans+=a[i+1]
            a[i+1]=0
        else:
            a[i+1]-=b[i]
            ans+=b[i]
    else:
        ans+=b[i]
print(ans)
# Judge status: Wrong Answer
N = int(input())
A = list(map(int, input().split()))

mod = 10**9 + 7

ans = 0
for i in range(60):
    X = sum([1 for x in A if (x >> 1) & 1])
    ans += (1 << i) * X * (N - X)
    ans %= mod

print(ans)
# Judge status: Accepted
n,m = map(int,input().split())
l = [list(map(int,input().split())) for i in range(n)]
a,b = [list(i) for i in zip(*l)]
l = [list(map(int,input().split())) for i in range(m)]
c,d = [list(i) for i in zip(*l)]

for i in range(n):
    p = 10 ** 9
    t = 50
    for j in range(m):
        e = abs(a[i] - c[j]) + abs(b[i] - d[j])
        if p > e:
            p = e
            t = j + 1
    print(t)
# Judge status: Accepted
n=int(input())
A =list(map(int,input().split()))
k = sum(A)/2
cnt=0
cnt2 = 0
for i in A:
    k -= i
    if k < 0:
        cnt += abs(k) 
        cnt2 += k + i
        break
    
print(int(2*min(cnt,cnt2)))
# Judge status: Accepted
N = int(input())
count = [[0 for _ in range(10)] for _ in range(10)]
for i in range(1, N + 1):
    st, ed = int(str(i)[0]), int(str(i)[-1])
    count[st][ed] += 1

ans = 0
for i in range(10):
    for j in range(10):
        ans += count[i][j] * count[j][i]
print(ans)
# Judge status: Accepted
n = int(input())
a = list(map(int,input().split()))
m = 1000
s = 0
for i in range(n-1):
    if s == 0:
        if a[i+1]>a[i]:
            s += m//a[i]
            m = m%a[i]
    if s != 0:
        if a[i+1]<a[i]:
            m += s*a[i]
            s = 0
    #print(i,m)
if s != 0:
    m += s*a[n-1]
    s = 0
print(m)
# Judge status: Accepted
N = int(input())
print(1- (N // 2) / N)
# Judge status: Accepted
A, B = map(int, input().split())
C = 0
while (True):
  if(A*C-C+1 >= B):
    break
  C += 1
print(C)
# Judge status: Accepted
stdin = open(0).read().rstrip().split('\n')
N = int(stdin[0])
A = list(map(int,stdin[1].split()))
ans =[0]*N
for i in range(N):
     ans[A[i]-1] = i+1
print(' '.join(map(str,ans)))
# Judge status: Accepted
n = int(input())

sList = []
for i in range(n):
  sList.append(input())

cList = []
sN = ord('a')
while True:
  if ord('z')+1 == sN:
    break
  sA = 50
  for i in range(n):
    tmp = sList[i].count(chr(sN))
    if sA > tmp:
      sA = tmp
  cList.append(sA)
  sN += 1

cS = ''
for i in range(len(cList)):
  cS += chr(ord('a')+i)*cList[i]
  
 
print(cS)
# Judge status: Accepted
def main():
    n, a, b = map(int, input().split())
    if a == b:
        print(1)
        return 0
    elif a > b or n == 1:
        print(0)
        return 0
    else:
        print((b-a)*(n-2)+1)
        return 0

if __name__ == '__main__':
    main()
# Judge status: Accepted
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
print(max(sum(a[:i+1])+sum(b[i:]) for i in range(n)))
# Judge status: Accepted
import bisect
import numpy as np
n = int(input())


arr = np.arange(4500) + 1
arr = arr.cumsum()

div = bisect.bisect_left(arr, n) + 1

arr = np.arange(div) + 1
rem = arr.sum() - n
arr = arr[np.where(arr != rem)]

print(*arr, sep="\n")
# Judge status: Accepted
a,b=map(int,input().split())
if a<=0 and b>=0:print("Zero")
if a>0:print("Positive")
if b<0:print("Positive" if (b-a)%2 else "Negative")
# Judge status: Accepted
N =int(input())
flag = False
for i in range(N):
    for j in range(N):
        if(4*i+7*j==N):
            flag=True
            break
    if(flag):
        break
if(flag):
    print("Yes")
else:
    print("No")
# Judge status: Accepted
def joinstring(O, E) : 
  if len(O) - len(E) > 0 : 
    str = "".join([i + j for i, j in zip(O, E)])
    str += O[-1]
    return str
  else : 
    str = "".join([i + j for i, j in zip(O, E)])
  return str


O = input()
E = input()

print(joinstring(O, E))
# Judge status: Wrong Answer
a,b=map(int,input().split())
if a==b:
    print("Possible")
elif a%2==0 and b%2==0:
    print("Possible")
else:
    print("Impossible")
# Judge status: Accepted
n, r = map(int, input().split())
for i in range(1, 10**100):
  if r ** (i - 1) <= n < r ** i:
    print(i)
    exit()
# Judge status: Accepted
def sum_digits(n):
    total = 0
    while n > 0:
        total += n % 10
        n //= 10
    return total


N, A, B = map(int, input().split())
ans = 0

for i in range(1, N + 1):
    n = sum_digits(i)
    if n >= A and n <= B:
        ans += i

print(ans)
# Judge status: Accepted
def main():
    n=int(input())
    ans=[0]*8
    other = 0
    for a in map(int,input().split()):
        if a >= 3200:
            other+=1
        else:
            ans[a//400] = 1
    a = ans.count(1)
    print(a if a != 0 else 1, a+other)
    
if __name__ == "__main__":
    main()
# Judge status: Accepted
A = [1, 3, 5, 7, 8, 10, 12]
B = [4, 6, 9, 11]
C = [2]

x, y = map(int, input().split())
ans = "No"
for group in [A, B, C]:
  if x in group and y in group:
    ans = "Yes"
print(ans)
# Judge status: Accepted
x = int(input())

for i in range(1000):
    for j in range(1000):
        a = i**5
        b = j**5
        if a-b == x:
            print(i,j)
            exit()
        elif a+b == x:
            print(i,-j)
            exit()
        elif -a-b == x:
            print(-i,-j)
            exit()
# Judge status: Wrong Answer
# -*- coding: utf-8 -*-
"""
Created on Sun Jun  7 14:28:00 2020

@author: NEC-PCuser
"""

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

for i in range(M):
    x_tmp, y_tmp = map(int, input().split())
    x.append(x_tmp)
    y.append(y_tmp)

box = [1] * N 
ball_set = set()
ball_set.add(1)
start_flg = True
for i in range(len(x)):
    ball_set.add(y[i])
    box[x[i] - 1] -= 1
    box[y[i] - 1] += 1
    if box[x[i] - 1] == 0:
        ball_set.discard(x[i])

print(len(ball_set))
# Judge status: Accepted
X, Y = list(map(int, input().split()))

cnt = 1
x = X
while True:
    x = 2 * x
    if x > Y:
        break
    cnt += 1
print(cnt)
# Judge status: Accepted
n=input()
a=n.count("a")
b=n.count("b")
c=n.count("c")
if a==1 and b==1 and c==1:
    print("Yes")
else:
    print("No")