peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
import sys

input = sys.stdin.readline
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))[::-1]
BC = sorted([list(map(int, input().split())) for _ in range(M)], key=lambda x: x[1])

ans = 0
for a in A:
    if N == 0:
        break
    while len(BC) > 0 and BC[-1][1] > a and N != 0:
        b, c = BC.pop()
        i = min(N, b)
        ans += i * c
        N -= i
    if N >= 1:
        ans += a
        N -= 1
print(ans)
# Judge status: Accepted
N, K = map(int, input().split())
P = [int(x) for x in input().split()]
P.sort()
i = 0
k = 0

for j in P:
    if k == K:
        break
    i += j
    k += 1

print(i)
# Judge status: Accepted
n,h=map(int,input().split())
p=[]
for i in range(n):
    a,b=map(int,input().split())
    p.append([a,0])
    p.append([b,1])

p=sorted(p,key=lambda x:-x[0])

i=0
ans=0
while h>0:
    if p[i][1]==1:
        h-=p[i][0]
        ans+=1
        i+=1
    else:
        ans-=(-h//p[i][0])
        break

print(ans)
# Judge status: Accepted
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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

s = set()

cnt = 0
while A % 2 == B % 2 == C % 2 == 0:
    if (A, B, C) in s:
        cnt = -1
        break
    s.add((A, B, C))
    A, B, C = B // 2 + C // 2, C // 2 + A // 2, A // 2 + B // 2
    cnt += 1

print(cnt)
# Judge status: Wrong Answer
a, b, c = map(int, input().split())
print(min(0, c-(a-b)))
# Judge status: Wrong Answer
"""
author : halo2halo
date : 16, Jan, 2020
"""

import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N = int(readline())
L = list(map(int, readline().split()))
S = sum(L)
ans = True
for i in L:
    if S >= i+i:
        ans = False
        break

print('Yes' if ans else 'No')
# Judge status: Accepted
x, y, z = input().split()
print(z,x,y)
# Judge status: Accepted
n, k = map(int, input().split())


def modify(x):
    return int(x) + 1


l = list(map(modify, input().split()))

s = sum(l[:k])
m = s
for i in range(k, n):
    s += l[i]
    s -= l[i-k]
    m = max(s, m)

print(m/2)
# Judge status: Accepted
a,b,c=list(map(int,input().split()))
n=0
H=[]
while True:
  S=[a,b,c]
  if S in H:
    print("-1")
    exit()
  H.append(S)
  if a%2!=0 or b%2!=0 or c%2!=0:
    print(n)
    exit()
  else:
    A=a/2
    B=b/2
    C=c/2
    a=int(B+C)
    b=int(A+C)
    c=int(A+B)
    n+=1
# Judge status: Wrong Answer
k = int(input())
a, b = map(int, input().split())
if k <= b - a or a % k  == 0 or b % k == 0:
  print('OK')
else:
  print('NG')
# Judge status: Wrong Answer
S=input()
ans=0
r=b=0
for s in S:
    if s=='0':
        if b>0:
            b-=0
            ans+=2
        else:
            r+=1
    else:
        if r>0:
            r-=1
            ans+=2
        else:
            b+=1
print(ans)
# Judge status: Wrong Answer
n, k = list(map(int, input().split()))
h = [int(input()) for i in range(n)]
h = sorted(h)

mins = 10000000000
for i in range(n - k+1):
  cost = max(h[i:i+k]) - min(h[i:i+k])
  if cost < mins:
    mins = cost
    
print(cost)
# Judge status: Accepted
# coding: utf-8


def main():
    _ = int(input())
    A = list(map(int, input().split()))
    B = [0] * 9
    mn, mx = 0, 0

    for a in A:
        a //= 400
        if a > 7: a = 8
        B[a] += 1
    
    for i in range(8):
        if B[i] > 0: mn += 1
    
    mx = mn + B[8]
    if mn == 0: mn += 1

    print(mn, mx)

if __name__ == "__main__":
    main()
# Judge status: Accepted
import fractions
n = int(input())
a = list(map(int, input().split()))
l = [0]*(n+1)
l[1] = a[0]
r = [0]*(n+1)
r[n-1] = a[n-1]
for i in range(1, n):
  l[i+1] = fractions.gcd(l[i], a[i])
  r[n-1-i] = fractions.gcd(r[n-i], a[n-1-i])

m = 0

for i in range(n):
  m = max(m, fractions.gcd(l[i], r[i+1]))
print(m)
# Judge status: Accepted
from collections import deque

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

rev = True

for i in range(q):
    q = list(input().split())
    if(int(q[0]) == 1):
        rev = rev ^ True
    else:
        n = int(q[1])
        if((n == 1 and rev) or (n == 2 and not rev)):
            s.appendleft(q[2])
        else:
            s.append(q[2])


txt = ''
if rev:
    txt = ''.join(s)
else:
    while not(not s):
        txt += s.pop()

print(txt)
# Judge status: Accepted
import itertools,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,K = LI()
h = LI()
dp = [float('INF')]*N
dp[0] = 0
for i,j in itertools.product(range(1,N),range(1,K+1)):
    if i-j>=0:
        dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))
print(dp[-1])
# Judge status: Accepted
A, B, C = map(int, input().split())
if not A % 2 or not B % 2 or not C % 2:
  print(0)
else:
  print(min(A * B, B * C, A * C))
# Judge status: Accepted
from fractions import gcd
from functools import reduce

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

lcm = reduce(lambda a, b: a * b // gcd(a, b), A)
print(sum(lcm // a for a in A) % 1000000007)
# Judge status: Wrong Answer
n = int(input())
ans = 0
for i in range(n):
    if i % 5 != 0 and i % 3 != 0:
        ans+=i
print(ans)
# Judge status: Wrong Answer
import math
x = int(input())

print(math.ceil(x/5.5))
# Judge status: Wrong Answer
def resolve():
    s = int(input())
    zandaka = s % 500
    zandaka2 = zandaka % 5
    ureshii_500 = (s - zandaka)/500*1000
    ureshii2 = (zandaka - zandaka2)/5*5
    goukei = ureshii2 + ureshii_500
    print(goukei)

resolve()
# Judge status: Accepted
n = int(input())
C = []
S = []
F = []
for _ in range(n-1):
    c, s, f = map(int, input().split())
    C.append(c)
    S.append(s)
    F.append(f)

def f(n, s, f):
    if n <= s:
        return s
    if n % f == 0:
        return n
    else:
        return n // f * f + f

for i in range(n-1):
    now = S[i] + C[i]
    for j in range(i+1, n-1):
        now = f(now, S[j], F[j]) + C[j]
    print(now)
print(0)
# Judge status: Wrong Answer
s = input()
s = set(list(s))
if len(s) == 1:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
N = int(input())
A = list(map(int, input().split()))
B = [0 for _ in range(N)]
B = B[:N//2] + A[N//2:]
for i in range(2, N+1):
  for j in range(N//(i+1), N//i):
    S = sum(B[m] for m in range(2*j+1, N, i))
    B[j] = (S + A[j]) % 2
C = []
for i in range(N):
  if B[i] == 1:
    C.append(i+1)
print(len(C))
for i in range(len(C)):
  if i != len(C) - 1:
    print(C[i], end = ' ')
  else:
    print(C[i])
# Judge status: Wrong Answer
n = int(input())
c = [0 for i in range(n-1)]
s = [0 for i in range(n-1)]
f = [0 for i in range(n-1)]
for i in range(n-1) :
  c[i],s[i],f[i] = map(int,input().split())
  
for i in range(0,n-1) :
  ans = 0
  for j in range(i,n-1) :
    if s[j] <= ans and ans%f[j] == 0 :
      ans += c[j]
    elif s[j] > ans :
      ans += c[j] + (s[j]-ans)
    elif ans%f[j] != 0 :
      ans += c[j] + ans - (ans//f[j]+1)*f[j]
  print(ans)
print(0)
# Judge status: Wrong Answer
n = int(input())
sp = [input().split() for i in range(n)]
sp = [s+str(100-int(i)) for s, i in sp]
print(*sorted(range(1, n+1), key=lambda x: sp[x-1]), sep='\n')
# Judge status: Accepted
a, b = map(int, input().split())

out = 1
i = 0
while(True):
    if out >= b:
        print(i)
        break
    else:
        out += a - 1
    i += 1
# Judge status: Accepted
n = int(input())
if n % 1000 == 0: print(0)
else: print(1000 - n % 1000)
# Judge status: Accepted
import bisect
n = int(input())
l = sorted(list(map(int, input().split())))

ans = 0
for i in range(n-1):
  for j in range(i+1, n):
    ans += bisect.bisect_left(l, l[i]+l[j]) - (j+1)
print(ans)
# Judge status: Accepted
n = int(input())
a= list(map(int,input().split()))

from fractions import gcd

ans =0
for i in range(n-1):
    if i==0:
        ans = gcd(a[i],a[i+1])
    else:
        ans = gcd(ans,a[i+1])

print(ans)
# Judge status: Accepted
A, B, C = map(int, input().split())
print('Yes' if A <= C and C <= B else 'No')
# Judge status: Accepted
import math
A,B,C = map(int,input().split())
num = math.gcd(math.gcd(A,B),C)
A = A//num
B = B//num
C = C//num
for i in range(1,100000):
    if (A*i)%B == 1:
        print('YES')
        exit()
print('NO')
# Judge status: Wrong Answer
H,A = map(int,input().split())
print(H//A + 1)
# Judge status: Accepted
# AtCoder Beginner Contest 044
# A - 高橋君とホテルイージー / Tak and Hotels (ABC Edit)
N = int(input())
K = int(input())
X = int(input())
Y = int(input())
total = 0
if N > K:
    total = X*K + Y*(N-K)
else:
    total = X*N
print(total)
# Judge status: Wrong Answer
o=input()
e=input()
ans=""
for i in range(len(e)):
    ans+=o[(i+1)//2]
    ans+=e[(i+1)//2]
if len(o)!=len(e):
    ans+=o[len(o)-1]
print(ans)
# Judge status: Wrong Answer
try:
  N, L = map(int, input().split())
  l = []
  for i in range(N):
      l.append(input())
  l_ = sorted(l)
  print(l_)
except EOFError:
  pass
# Judge status: Accepted
import sys
readline = sys.stdin.readline

def main():
    N = int(readline())
    P = list(map(int, readline().rstrip().split()))
    l = ['x' if p == i+1 else 'o' for i, p in enumerate(P)]
    l = ''.join(l)
    ll = l.replace('xx', '')
    ans = (len(l) - len(ll)) // 2 + ll.count('x')
    print(ans)
    

if __name__ == '__main__':
    main()
# Judge status: Accepted
def ceil(a, b):
    return (a + b - 1) // b


N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
n = sum(b) - sum(a)
for _a, _b in zip(a, b):
    if _a < _b:
        n -= ceil(_b - _a, 2)
if n >= 0:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
x = int(input())
if x % 2 == 0:
    print((x/2)**2)
else:
    print((x+1)/2*(x-1)/2)
# Judge status: Accepted
def main():
    s=input()
    s1=int(s[:2])
    s2=int(s[2:])
    yymm = 1 <= s2 <= 12
    mmyy = 1 <= s1 <= 12
    if yymm and mmyy:
        print("AMBIGUOUS")
    elif yymm:
        print("YYMM")
    elif mmyy:
        print("MMYY")
    else:
        print("NA")

if __name__ == "__main__":
    main()
# Judge status: Accepted
N, M = map(int, input().split())

P = []
Y = []

d = {}
ans = [0] * M
for i in range(1,N+1):
    d[i] = []

for i in range(M):
    p,y = map(int, input().split())
    d[p].append((i,y))

for k in d.keys():
    d[k] = sorted(d[k], key=lambda x: x[1])
    for i in range(len(d[k])):
        ans[d[k][i][0]] = '{}{}'.format(str(k).zfill(6),str(i+1).zfill(6))

for i in range(len(ans)):
    print(ans[i])
# Judge status: Accepted
str = input().split()
if len(str) != 3:
    print("input values is not three")
else:
    a = int(str[0])
    b = int(str[1])
    c = int(str[2])
    if a <= b * c:
         print("Yes")
    else:
         print("No")
# Judge status: Wrong Answer
abc = list(map(int,input().split()))
abc.sort()

memo1 = abc[2]-abc[0]
memo2 = abc[2]-abc[1]

if memo1%2 == memo2%2:
    print((memo1+memo2)//2)
else:
    print(((memo1+memo2)//2)+1)
# Judge status: Accepted
n,k = map(int,input().split())
d = list(map(str,input().split()))
while True:
  sn = str(n)
  l = len(sn)
  flag = True
  for i in range(l):
    if sn[i] in d:
      flag = False
      break
  if flag:
    print(n)
    exit()
  n += 1
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))
s = 0
l = sum(A)
r = []
for a in A[:-1]:
  s += a
  k = abs(l - 2*s)
  r.append(k)
r.sort()
print(r[0])
# Judge status: Accepted
Q,H,S,D = map(int,input().split())
N = int(input())
num = min(4*Q,2*H,S)
if num*2 <= D:
    print(N*num)
elif N % 2 == 0:
    print(N*D//2)
else:
    print(N//2*D+num)
# Judge status: Wrong Answer
n = int(input())
a,b=[],[]

for i in range(n):
    x,y = map(int,input().split())
    a.append(x)
    b.append(y)

a=list(reversed(a))
b=list(reversed(b))

ans=0
for i in range(n):
    if a[i]<=b[i]:
        ok=b[i]-a[i]
    else:
        ok=-(-a[i]//b[i])*b[i]-a[i]
    a=[j+ok for j in a]
    ans+=ok

print(ans)
# Judge status: Accepted
from sys import stdin
n = int(stdin.readline().rstrip())
s = stdin.readline().rstrip()
kuro = s.count("#")
shiro = n-kuro
mi = shiro
k = 0
sh = shiro
for i in range(n):
    if s[i] == "#":
        k += 1
    else:
        sh -= 1
    mi = min(mi,k+sh)
print(mi)
# Judge status: Accepted
x, y = map(int, input().split())
print(min(abs(~x+y), abs(y+x))+1)
# Judge status: Accepted
k, x = map(int, input().split())
for i in range(x - k + 1, x + k):
    print(i, end=" ")
# Judge status: Accepted
import math
s = int(input())
print(math.ceil(s / 2))
# Judge status: Wrong Answer
import numpy as np
import sys
n, m = map(int, input().split())
if n >= m:
    print(0)
    sys.exit()
x = [int(i) for i in input().split()]
x = np.array(sorted(x))
diff = np.abs(np.diff(x))
diff = sorted(diff)
print(sum(diff[:-n + 1]))
# Judge status: Accepted
n,k=map(int,input().split())
a=list(map(int,input().split()))

a.sort()

ans=1
n=n-k

while n>0:

    n=n-k+1
    ans+=1

print(ans)
# Judge status: Accepted
n = int(input())
l = []
for _ in range(2):
    a = list(map(int,input().split()))
    l.append(a)

if n == 1:
    print(l[0][0]+l[1][0])
    exit()

m1 = []
m2 = []
m1.append(0)
m1.append(l[0][0])
m2.append(0)
m2.append(l[1][0])

for i in range(1,n):
    m1.append(m1[i]+l[0][i])
    m2.append(m2[i]+l[1][i])

ans = [0]*n
for j in range(1,n+1):
    ans[j-1] = m1[j]+(m2[n]-m2[j-1])


print(max(ans))
# Judge status: Accepted
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse = True)
q.sort(reverse = True)
r.sort(reverse = True)
pp = p[:x]
qq = q[:y]
if x+y <= c:
  rr = r[:(x+y)]
else:
  rr = r
ppqqrr = pp + qq + rr
ppqqrr.sort(reverse = True)
print(sum(ppqqrr[:x+y]))
# Judge status: Wrong Answer
# coding: utf-8
# Your code here!

N = input()
L = input().split(' ')

l = len(L)
L = [int(s) for s in L]
L.sort()
if len(L) < 3:
    print(0)
    exit
  
a = 0
for i in range(l - 2):
    for j in range(i + 1, l - 1):
        for k in range(j + 1, l):
            if (L[i] + L[j]) > L[k]:
                if (L[i] != L[j]) and (L[k] != L[j]) and (L[i] != L[k]):
                    a += 1
print(int(a))
# Judge status: Accepted
n,m = map(int,input().split())
if n >=m//2:
    print(m//2)
else:
    print(n+(m-2*n)//4)
# Judge status: Accepted
n=input().split(" ")
print(int(n[0])*int(n[1]))
# Judge status: Wrong Answer
#import numpy as np
import sys
from collections import defaultdict
import math
import itertools
import bisect
import time
read = sys.stdin.buffer.read
readline = sys.stdin.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10000)

s = time.time()
N = int(readline())
tmp = list(map(int,input().split()))
A = []  
[bisect.insort_right(A, x) for x in tmp]
#tmp.sort()
e = time.time()
print(e-s)
# Judge status: Accepted
N=int(input())
ls=input().split()
l=[ int(v) for v in ls ]

l.sort(reverse=True)

A=0
B=0
for i in range(N):
    if i% 2 == 0:
        A+=l[i]
    else :
        B+=l[i]
print(A-B)
# Judge status: Accepted
N, L = map(int, input().split())

S = [input() for i in range(N)]

S.sort()

print("".join(S))
# Judge status: Wrong Answer
from functools import lru_cache
import numpy as np


@lru_cache(maxsize=None)
def lcm(x, y):

    def gcd(x, y):
        if x == 0:
            return y
        else:
            return gcd(y % x, x)

    return x * y // gcd(x, y)


n = int(input())
a = np.array(list(map(int, input().split())))
mod = 10**9 + 7
x = a[0]

for i in a[1:]:
    x = lcm(x, i)
r = x / a
print(int(sum(r) % mod))
# Judge status: Accepted
from functools import reduce

n = int(input())
def f(x, y):
    k = n // y
    return x + k * (y + y * k) // 2

ans = reduce(f, range(n + 1))
print(ans)
# Judge status: Wrong Answer
N,M = map(int,input().rstrip().split(" "))
ans = [False for _ in range(N + 1)]
balls = [1 for _ in range(N + 1)]
ans[1] = True
for i in range(M):
  q = list(map(int,input().rstrip().split(" ")))
  if ans[q[0]] == True:
    ans[q[1]] = True
  balls[q[0]] -= 1
  if balls[q[0]] == 0: ans[q[0]] = False
  balls[q[1]] += 1
ansi = 0
print(ans)
for i in range(N + 1):
  if ans[i]: ansi += 1
print(ansi)
# Judge status: Wrong Answer
n = int(input())
a = list(map(int, input().split()))
limit = 10**18
ans = 1




flag = True

if 0 in a:
  print(0)
  flag = False

if flag:
  for i in a:
    ans *= i
    if ans >= limit:
      print(-1)
      flag = False
      break

if flag:
  print(ans)
# Judge status: Wrong Answer
lit = input().split()
length = len(lit)
times = 0
if length != 1:
  for i in range(int(length/2)):
     if lit[i] != lit[length-1-i]:
       times += 1
  print(times)
else:
  print(times)
# Judge status: Accepted
a,b,c = map(int,input().split())
ans = a*b*c
if ans%2==0:
    print(0)
else:
    abc_list = [a,b,c]
    abc_list.sort()
    print(abc_list[0]*abc_list[1])
# Judge status: Accepted
X, K, D = map(int, input().split())
X = abs(X)

if X > K*D:
  print(X-K*D)
  exit()

K -= X//D

if K%2 == 0:
  print(abs(X-(X//D)*D))
else:
  print(abs(X-(X//D)*D-D))
# Judge status: Accepted
a , b, k = (int(x) for x in input().split())

if k > a:
    if b - k + a <= 0:
        b = 0
        a = 0
    else:
        b = b - k + a
        a = 0
    
else:
    a = a - k 


print(a,b)
# Judge status: Accepted
N = int(input())
A=[list(map(int, input().split())) for i in range(2)]

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

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

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

print(max)
# Judge status: Accepted
from collections import Counter

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

c = Counter(a)  # リストの要素をカウント
cnt = [k for k, v in c.items() if v >= 2]

if len(cnt) < 2:
    print(0)
else:
    cnt = sorted(cnt, reverse=True)
    if c[cnt[0]] >= 4:
        print(cnt[0] * cnt[0])
    else:
        print(cnt[0] * cnt[1])
# Judge status: Wrong Answer
x,n=map(int,input().split())
a=list(map(int,input().split()))
if n==0:
  print(x)
else:
  for i in range(n):
    y=x-i
    if y not in a:
      print(y)
      break
    z=x+i
    if z not in a:
      print(z)
      break
# Judge status: Accepted
N = int(input())
S = [input() for i in range(N)]

from collections import Counter
B = []
mycounter = Counter(S)
max_v = max(mycounter.values())
for s, v in mycounter.items():
  if v == max_v:
    B.append(s)
for a in sorted(B):
  print(a)
# Judge status: Accepted
n = int(input())
print(n * 800 - (n // 15 * 200))
# Judge status: Accepted
def fact(n):
    val = 1
    for i in range(2, n + 1):
        val *= i
        val %= 10**9 + 7
    return val

x, y = map(int,input().split())
ans = 1

if abs(x-y) > 1:
    print(0)

elif x == y:
    print((fact(x)**2 *2) % (10**9+7))

else:
    print((fact(x) * fact(y)) % (10**9+7))
# Judge status: Wrong Answer
x = int(input())

def calc(n):
  if n < 7:
    return 1
  elif n < 12:
    return 2
  else:
    return (n // 11)*2 + calc(n % 11)

print(calc(x))
# Judge status: Wrong Answer
S = input()

a = []
result = "Yes"
for s in S:
    if s in a:
        result = "No"
        break
    a.append(s)

print(result)
# Judge status: Wrong Answer
N = int(input())
a = list(map(int,input().split()))

color = [0 for j in range(9)]

for i in range(N):
    if a[i] >= 3200:
        color[8] += 1
    else:
        for j in range(8):
            if a[i] // 400 == j:
                color[j] += 1

color_min = 8 - color[:8].count(0)
if 8 - color_min <= color[8]:
    color_max = 8
else:
    color_max = color_min + color[8]
if color_min == 0:
        color_min = 1
print(color_min, color_max)
# Judge status: Accepted
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
# 
# 
# @stop_watch
def solve(N, A, B, C, D, E):
    tmp = min(A, B, C, D, E)
    tmp, tmp2 = divmod(N, tmp)
    tmp += 0 if tmp2 == 0 else 1
    print(tmp + 4)


if __name__ == '__main__':
    N = int(input())
    A = int(input())
    B = int(input())
    C = int(input())
    D = int(input())
    E = int(input())
    solve(N, A, B, C, D, E)

    # # test
    # from random import randint
    # from func import random_str
    # solve()
# Judge status: Accepted
def people(n):
  p=0
  while n>0:
    n-=(d*2+1)
    p+=1
  return p

def main():
  print(people(n))
  
if __name__=='__main__':
  n,d=map(int,input().split())
  main()
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))

cnt = 0
b = []
for i in range(n):
    if a[i] < 0:
        cnt += 1
    b.append(abs(a[i]))

if cnt % 2 == 0:
    ans = sum(b)
    print(ans)
else:
    ans = sum(b) - 2 * min(b)
    print(ans)
# Judge status: Wrong Answer
from collections import Counter

S = input()
d = Counter(S).values()
if len(d) == 3 and max(d) - min(d) <=1:
  ans = "YES"
else:
  ans = "NO"
print(ans)
# Judge status: Wrong Answer
a,b,t=map(int,input().split())
cnt=0
c=a
for i in range(a,t,c):
  cnt=cnt+b
print(cnt)
# Judge status: Accepted
S = input()
last = 'i'

if len(S) == 1:
    print("No")
    exit()

for c in S:
    if (last == 'i' and c != 'h') or (last == 'h' and c != 'i'):
        print("No")
        exit()
    last = c
if last != "i":
    print("No")
    exit()
print("Yes")
exit()
# Judge status: Accepted
n = int(input())
order = list(map(int, input().split()))
for i in range(n):
    order[i] -= 1
point = list(map(int, input().split()))
bonus = list(map(int, input().split()))

ans = 0
pre = -2 
for i in range(n):
    now = order[i]
    ans += point[now]
    
    if pre == now - 1:
        ans += bonus[pre]
    
    pre = now
    
print(ans)
# Judge status: Accepted
N, W = map(int, input().split())

dp = [[0]*(W+1) for _ in range(N+1)]

for i in range(1, N+1):
  w, v = map(int, input().split())
  for j in range(1, W+1):
    if j >= w:
      dp[i][j] = max(dp[i-1][j], dp[i-1][j-w]+v)
    else:
      dp[i][j] = dp[i-1][j]

print(dp[N][W])
# Judge status: Accepted
S=input()
B0=int(S[-1])
B1=10-int(S[-1])
for s in S[::-1][1:]:
    x=int(s)
    B0,B1=min(B0+x,B1+x+1),min(B0+(10-x),B1+(10-x-1))
print(min(B0,B1+1))
# Judge status: Accepted
# n, m, l = map(int, input().split())

# list_n = list(map(int, input().split()))

# n = input()
# list = [input() for i in range(N)

# list = [[i for i in range(N)] for _ in range(M)]

import sys
input = sys.stdin.readline

a, b = map(int, input().split())

if a > 0 and b > 0:
    print("Positive")
elif a * b <= 0:
    print("Zero")
elif (b - a) % 2 == 1:
    print("Positive")
else:
    print("Negative")
# Judge status: Accepted
import copy

a = []
a = list(map(int, input().split()))

ctn = 0
for i in a:
    if (i == 0):
        print(ctn+1)
    ctn += 1
# Judge status: Wrong Answer
n = int(input())
a_list = list(map(int,input().split()))
print(sum(a_list) - min(a_list))
# Judge status: Accepted
n = int(input())
A = list(map(int, input().split()))

money = 1000
stock = 0

schedule = []
for i in range(n-1):
    if A[i] < A[i+1]:
        schedule.append(i)

for i in schedule:
    stock, money = divmod(money, A[i])
    money = money+stock*A[i+1]
print(money)
# Judge status: Wrong Answer
import math
def combinations(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n,p=map(int,input().split())
a=list(map(int,input().split()))
n0=0
n1=0
ans=0
for i in range(len(a)):
  if a[i]%2:
    a[i]=1
    n1+=1
  else:
    a[i]=0
    n0+=1
s=sum(a)
for i in range(0,s+1,2):
  ans+=combinations(n1,i)
print(ans*(2**n0))
# Judge status: Wrong Answer
a,b,c=map(int,input().split())
if a==b and a==c:
    print(3)
elif a==b or a==c or b==c:
    print(2)
else:
    print(1)
# Judge status: Accepted
import math
all = input()
A = int(all.split(' ')[0])
B = int(all.split(' ')[1])
H = int(all.split(' ')[2])
M = int(all.split(' ')[3])
delta_ = H/12+(1/12)*(M/60)-M/60
c = (A**2+B**2-2*A*B*math.cos(2*delta_*math.pi))**0.5
print(c)
# Judge status: Accepted
import sys
from collections import Counter
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    count = Counter(readline().decode('utf-8').strip())
    for _ in range(N-1):
        count &= Counter(readline().decode('utf-8').strip())
    ans = ''
    for key, value in count.items():
        ans += key*value
    ans = sorted(ans)
    print(''.join(map(str,ans)))





if __name__ == '__main__':
    main()