Harryxun/stf_run huggingface dataset:
n , m  = map(int, input().split())
l_1 = [] #左から1桁目の数字のりすと
l_2 = [] #左から2桁目の数字のりすと
l_3 = [] #左から3桁目の数字のりすと
nocounter = 0
answer = 100  
 
if m == 0:
  print(0)
else:
  for i in range(m):
    a, b = map(int, input().split())
    if a == 1:
      l_1.append(b)
    elif a == 2:
      l_2.append(b)
    else:
      l_3.append(b)
  if len(l_1) > 0:
    pv = l_1[0]
    for j in range(len(l_1)):
      if not pv  == l_1[j]:
        nocounter += 1
      if l_1[j] == 0:
        nocounter += 1
  if len(l_2) > 0:
    pv = l_2[0]
    for j in range(len(l_2)):
      if not pv  == l_2[j]:
        nocounter += 1
  if len(l_3) > 0:
    pv = l_3[0]
    for j in range(len(l_3)):
      if not pv  == l_3[j]:
        nocounter += 1
  if nocounter > 0:
    print(-1)
  else:
    if n == 1:
      print(l_3[0])
    elif n == 2 and len(l_2)*lemn(l_1) == 1:
      print(10*l_1[0] + l_2[0])
    elif n == 2 and len(l_1) == 0:
      print(10 + l_2[0])
    elif n == 2 and len(l_2) == 0:
      print(10*l_1[0])
    elif len(l_1)*len(l_2)*len(l_3) == 1:
      print(100*l_1[0] + 10*l_2[0] + l_3[0])
    elif len(l_1) == 0 and len(l_2) == 0:
      print(100 + l_3[0])
    elif len(l_1) == 0 and len(l_3) == 0:
      print(100 + l_2[0])
    elif len(l_1) == 0:
      print(100 + 10*l_2[0] + l_3[0])
    elif len(l_2) == 0 and len(l_3) == 0:
      print(100*l_1[0])
    elif len(l_2) == 0 :
      print(100*l_1[0] + l_3[0])
    else:
      print(100*l_1[0] + 10*l_2[0])

### FIXED CODE ###

n , m  = map(int, input().split())
l_1 = [] #左から1桁目の数字のりすと
l_2 = [] #左から2桁目の数字のりすと
l_3 = [] #左から3桁目の数字のりすと
nocounter = 0
 
if m == 0:
  if n == 1:
    print(0)
  elif n == 2:
    print(10)
  else:
    print(100)
else:
  for i in range(m):
    a, b = map(int, input().split())
    if a == 1:
      l_1.append(b)
    elif a == 2:
      l_2.append(b)
    else:
      l_3.append(b)
  if len(l_1) > 0:
    pv = l_1[0]
    for j in range(len(l_1)):
      if not pv  == l_1[j]:
        nocounter += 1
      if l_1[j] == 0 and n > 1:
        nocounter += 1
  if len(l_2) > 0:
    pv = l_2[0]
    for j in range(len(l_2)):
      if not pv  == l_2[j]:
        nocounter += 1
  if len(l_3) > 0:
    pv = l_3[0]
    for j in range(len(l_3)):
      if not pv  == l_3[j]:
        nocounter += 1
  if nocounter > 0:
    print(-1)
  else:
    if n == 1:
      print(l_1[0])
    elif n == 2 and len(l_2)*len(l_1) > 0:
      print(10*l_1[0] + l_2[0])
    elif n == 2 and len(l_1) == 0:
      print(10 + l_2[0])
    elif n == 2 and len(l_2) == 0:
      print(10*l_1[0])
    elif len(l_1)*len(l_2)*len(l_3) > 0:
      print(100*l_1[0] + 10*l_2[0] + l_3[0])
    elif len(l_1) == 0 and len(l_2) == 0:
      print(100 + l_3[0])
    elif len(l_1) == 0 and len(l_3) == 0:
      print(100 + 10*l_2[0])
    elif len(l_1) == 0:
      print(100 + 10*l_2[0] + l_3[0])
    elif len(l_2) == 0 and len(l_3) == 0:
      print(100*l_1[0])
    elif len(l_2) == 0 :
      print(100*l_1[0] + l_3[0])
    else:
      print(100*l_1[0] + 10*l_2[0])
num = int(input())
strng = ""
while num >= 1 :
    kalan = num % 26
    strng = chr(97+kalan-1)+strng
    num = num // 26
print(strng)

### FIXED CODE ###

import re
txt=input()
x = re.search("[A-Z]", txt)
if(x):
  print("A")
else:
  print("a")
s = str(input())
t = str(input())
k = False
for i in range(len(s)):
  s = s[-i] + s[:-i]
  if s == t:
    k = True
    break
    
print('Yes' if k else 'No')

### FIXED CODE ###

s = str(input())
t = str(input())

for i in range(len(s)):
    ss = s[-i:]+s[:-i]
    if ss == t:
        print('Yes')
        exit()
print('No')
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
m = 0
 
for i in range(n):
  m += b[a[i]-1]
  if i==0:
    continue
  if a[i] == a[i-1]+1:
    m += c[i]
    
print(m)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
m = 0
 
for i in range(n):
  m += b[a[i]-1]
  if i==0:
    continue
  if a[i] == a[i-1]+1:
    m += c[a[i]-2]
    
print(m)
inf = 2**60
'''
def table(size, init): #配列生成
  x = len(size)
  l = [init for i in range(size[x-1])]
  for i in range(x-1):
    l = [l for k in range(size[x-2-i])]
  return l
'''

n, W = map(int, input().split())
w, v = [[0]*n for i in range(2)]
for i in range(n):
  w[i], v[i] = map(int, input().split())

dp = [[-1] * (100011) for i in range(n+1)]
dp[0][0] = 0

for i in range(n):
  for j in range(100010):
    if dp[i][j] != -1:
      dp[i+1][j] = max(dp[i][j], dp[i+1][j])
      if dp[i][j]+w[i] <= W:
        dp[i+1][j+v[i]] = max(dp[i][j] + w[i], dp[i+1][j+w[i]])

for i in range(100010):
  if dp[n][100010-i] != -1:
    print(100010-i)
    break

### FIXED CODE ###

n, W = map(int, input().split())
w = [0] * n
v = [0] * n
for i in range(n):
    w[i], v[i] = map(int, input().split())

INF = 10**10

dp = [[INF for i in range(100010)] for j in range(n+1) ]

dp[0][0] = 0

for i in range(n):
    for j in range(100010):
        dp[i+1][j] = min(dp[i][j], dp[i+1][j])
        if j>=v[i]:
            dp[i+1][j] = min(dp[i][j-v[i]]+w[i], dp[i+1][j])

for j in range(100010):
    if dp[n][100009-j] <= W:
        print(100009-j)
        break
K=int(input())
S=input()
B=0
D=0
B=len(S)
B=int(B)
D=S+'...'
if S>=K:
    print(S)
else:
    print(D)


### FIXED CODE ###

K=int(input())
S=input()
if len(S)<=K:print(S)
else:print(S[0:K]+'...')
a = list(int(input()))
count = 0
for i in range(len(a)):
  if a[i] == 1:
    count += 1
print(count)

### FIXED CODE ###

a = list(input())
count = 0
for i in range(len(a)):
  if a[i] == "1":
    count += 1
print(count)
for i in range(9):
     for i in range(9):
         qq = i * j
         print("qq")

### FIXED CODE ###

for i in range(1,10):
    for j in range(1,10):
        print(str(i)+"x"+str(j)+"="+str(i*j))
S,T = input("Enter the color").split()
A,B = int(input("Enter two value: ").split()) 
U = input("Color you want")
if U==S:
  A=A-1
  print(A)
else:
  B=B-1
  print(B)

### FIXED CODE ###

S,T = input().split(" ")
A,B = map(int,input().split(" "))
U = input()
if S==U:
  A-=1
else:
  B-=1
print("{} {}".format(A,B))
n = int(input())

print(math.factorial(n) // math.factorial(n - 3))

### FIXED CODE ###

N = int(input())
print(N*N*N)
S=input()
Sn=0
for i in range(1, 10):
	if i > len(S):break
	Sn+=int(S[-i])
ans = "No"
if int(S) / Sn == 0:ans = "Yes"
print(ans)

### FIXED CODE ###

S=input()
Sn=0
for i in range(1, 10):
	if i > len(S):break
	Sn+=int(S[-i])
ans = "No"
if Sn == 0 or int(S) % Sn == 0:ans = "Yes"

print(ans)
import math
a,b = map(int,input().split())
ans = a*b/math.gcd(a,b)
print(ans)

#LCM = X*Y/GCD
#LCM = 最小公倍数
#GCD = 最大公約数

### FIXED CODE ###

import fractions
a,b = map(int,input().split())
ans = a*b/fractions.gcd(a,b)
print(int(ans))

#LCM = X*Y/GCD
#LCM = 最小公倍数
#GCD = 最大公約数
def main():
    N = int(input())
    dp = [0]*N
    array = []
    sum = 0
    for i in range(N):
        array2 = list(map(int,input().split()))
        array.append(array2)
    num = [[0,0,0] for z in range(N)]
    dp[0] = max(array[0][n] for n in range(3))
    for m in range(3):
        if dp[0] == array[0][m]:
            num[0][m] = 1
    
    
    for z in range(3):
        if num[0][z] == 1:
            dp[1] = max(dp[1],max(array[1][1],array[1][2])+dp[0])
            num[1][z] = 1
    

    for j in range(2,N):
        dpj = []
        for z in range(3):
            if 1 == num[j-1][z]:
                num[j][z] = 1
                dpj.append(max(array[j][1],array[j][2])+dp[j-1])
        dp[j] = max(dpj)
    
    print(dp[-1])
    
main()

### FIXED CODE ###

def main():
    N = int(input())
    
    array = []
    
    for i in range(N):
        array2 = list(map(int,input().split()))
        array.append(array2)

    num = [[0,0,0] for z in range(N)]
    for m in range(3):
        num[0][m] = array[0][m]

    

    for j in range(1,N):
        
        for z in range(3):
            if z == 0:
                num[j][z] = array[j][z]+max(num[j-1][1],num[j-1][2])
                    
            if z == 1:
                num[j][z] =array[j][z]+max(num[j-1][0],num[j-1][2])
            if z == 2:
                num[j][z] =array[j][z]+max(num[j-1][1],num[j-1][0])
        
    
    print(max(num[-1]))
    
main()
n, m = map(int, input().split())

l, r = map(int, input().split())


def check(i, l, r):
    if i == m:
        print(r - l + 1)
        exit(0)
    l_, r_ = map(int, input().split())
    nl = max(l, l_)
    nr = min(r, r_)
    i += 1
    check(i, nl, nr)


check(1, l, r)


### FIXED CODE ###

n, m = map(int, input().split())
l, r = map(int, input().split())
li = []


for _ in range(m - 1):
    l_, r_ = map(int, input().split())
    l = max(l, l_)
    r = min(r, r_)


print(max(r - l + 1, 0))
N, M = map(int, input().split())
p = [int(i) for i in input().split()]

class Unionfind:
    def __init__(self, num):
        self.num = num
        self.par = [int(i) for i in range(num+1)]

    def root(self, x):
        if self.par[x] == x:
            return x
        else:
            return self.root(self.par[x])

    def unite(self, u, v):
        ru = self.root(u)
        rv = self.root(v)
        if ru != rv:
            self.par[ru] = rv

    def same(self, u, v):
        return self.root(u) == self.root(v)

uni = Unionfind(N)
for i in range(M):
    x, y = map(int, input().split())
    uni.unite(x, y)

count = 0
for i in range(N, 0, -1):
    if uni.same(i, p[i-1]):
        count += 1

print(count)


### FIXED CODE ###

N, M = map(int, input().split())
p = [int(i) for i in input().split()]

class Unionfind:
    def __init__(self, num):
        self.par = [i for i in range(num+1)]
        self.rank = [0] * (num+1)

    def root(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.root(self.par[x])
            return self.par[x]

    def unite(self, u, v):
        ru = self.root(u)
        rv = self.root(v)
        if self.rank[ru] < self.rank[rv]:
            self.par[ru] = rv
        else:
            self.par[rv] = ru
            if self.rank[ru] == self.rank[rv]:
                self.rank[ru] += 1

    def same(self, u, v):
        return self.root(u) == self.root(v)

uni = Unionfind(N)
for i in range(M):
    x, y = map(int, input().split())
    uni.unite(x, y)

count = 0
for i in range(1, N+1):
    if uni.same(i, p[i-1]):
        count += 1

print(count)
N = int(input())
x = 800*N
if 15 <= N <30 :
    y = 200
elif  30<= N <45:
    y = 400
elif 45 <= N <60:
    y = 600
elif 60 <= N < 75:
    y = 800
elif 75 <= N < 90:
    y = 1000
elif 90 <= N < 100:
    y = 1200
elif N ==100:
    y = 1200
print(x - y)

### FIXED CODE ###

n = int(input())
print(800 * n - 200 * (n // 15))
A = input()

if (int(A[0])+int(A[2])+int(A[4]))>=22:
    print('bust')
else:
    print('win')



### FIXED CODE ###

a,b,c=(int(x) for x in input().split())

if (a+b+c)>=22:
    print('bust')
else:
    print('win')
from sys import stdin

def main():

    input = stdin.readline

    N,K = map(int,input().split())

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

    itta_list = []
    idou_num = 0

    pos = 0

    for i in range(K):
        # itta_list記憶
        if pos not in itta_list:
            itta_list.append(pos)
        else:
            idou_num = i
            break

        # 次の街へ
        pos = A[pos] - 1

    roop_list = itta_list[itta_list.index(pos):]

    amari = (K - idou_num) % len(roop_list)

    ans_pos = roop_list[amari] + 1

    print(ans_pos)

if __name__ == "__main__":
    main()

### FIXED CODE ###

from sys import stdin

def main():

    input = stdin.readline

    N,K = map(int,input().split())

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

    itta_set = set()
    itta_list = []
    idou_num = 0

    pos = 0

    for i in range(K):
        # itta_list記憶
        if pos not in itta_set:
            itta_set.add(pos)
            itta_list.append(pos)
        else:
            idou_num = i
            break

        # 次の街へ
        pos = A[pos] - 1
    else:
        ans_num = pos + 1
        print(ans_num)
        return

    roop_list = itta_list[itta_list.index(pos):]

    amari = (K - idou_num) % len(roop_list)

    ans_pos = roop_list[amari] + 1

    print(ans_pos)

if __name__ == "__main__":
    main()
n  = input()

if n == "1"
    print("Hello World")
else:
    a = int(input())
    b = int(input())
    print(a + b)

### FIXED CODE ###

n  = input()

if n == "1":
    print("Hello World")
else:
    a = int(input())
    b = int(input())
    print(a + b)
x, a = map(int, input())
 
if x < a:
  print(0)
else:
  print(10)

### FIXED CODE ###

x, a = map(int, input().split())
 
if x < a:
  print(0)
else:
  print(10)
x = input()
y = input()

cnt = 0

while x <= y:
    x *= 2
    cnt += 1

print (cnt)

### FIXED CODE ###

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

cnt = 0

while x <= y:
    x *= 2
    cnt += 1

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

f = 0
d = 0
for x in a:
    if x % 4 == 0:
        f += 1
    elif x % 2 == 0:
        d += 1

if 0 < d < n:
    d -= 1

if n > f * 2 + 1 + d:
    print('No')
else:
    print('Yes')


### FIXED CODE ###

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

h = 0
w = 0

ans = [[0 for _ in range(W)] for _ in range(H)]
for i in range(n):
    for j in range(a[i]):
        ans[h][w] = i + 1
        if h % 2 == 0:
            if w == W - 1:
                h += 1
            else:
                w += 1
        else:
            if w == 0:
                h += 1
            else:
                w -= 1

for p in ans: print(' '.join(map(str, p)))
n = input()
if not n[0] == 7 and n[1] == 7 and n[2] == 7:
    print(No)
else:
    print(Yes)

### FIXED CODE ###

n = str(input())
if n[0] == "7" or n[1] == "7" or n[2] == "7":
    print("Yes")
else:
    print("No")
A = input()

S = 0
for i in A:
  S += A[i]
  
if int(A) % S == 0:
  print("Yes")
else:
  print("No")  


### FIXED CODE ###

A = input()

S = 0
for i in A:
  S = S + int(i)
  
if (int(A) % S) == 0:
  print("Yes")
else:
  print("No")
import numpy as np
import functools
import operator

def calc(n):
    return n / 1000000

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

#z = functools.partial(functools.reduce, operator.mul)
#count = z(A)

count = np.prod(A)

#print(count)

count = count * 1000000 ** len(A)

if 10 ** 18 < count:
    count = -1
print(count)


### FIXED CODE ###

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

if 0 in A:
    print(0)
    exit()

count = 1
for i in A:
    count *= i
    if 10 ** 18 < count:
        break

if 10 ** 18 < count:
    count = -1

print(count)
n=int(input());print(int(round(int(input()))*2)+1if n!=1else"1")

### FIXED CODE ###

n,c=int(input()),0
for j in range(n+1):
  if c<n:c+=j+1
  else:break	
for i in range(j,0,-1):
  if i<=n:print(i);n-=i
N, m = map(int, input().split())

if n > m:
    k = n
    n = m
    m = k

if m > 2 and n > 2:
    print((m-2)*(n-2))

elif n == 1:
    if m == 1:
        print(1)
    else:
        print(m - 2)

elif n == 2:
    print(0)

### FIXED CODE ###

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

if n > m:
    k = n
    n = m
    m = k

if m > 2 and n > 2:
    print((m-2)*(n-2))

elif n == 1:
    if m == 1:
        print(1)
    else:
        print(m - 2)

elif n == 2:
    print(0)
num = int(input())
input_line = input().split()

num_list = [int(input_line[i]) for i in range(num)]
law = 10 ** 9 + 7
sigma = 0
for i in range(num):
	num_a = num_list[i]
    temp_sum = 0
	for j in range(i+1,num):
		temp_sum += num_list[j]
    	
    
    sigma += num_a * temp_sum

sigma %= law
print(sigma)


### FIXED CODE ###

num = int(input())
input_line = input().split()

law = 10 ** 9 + 7
num_list = [int(input_line[i])%law for i in range(num)]

sigma = 0
temp_sum = 0
for j in range(num):
	temp_sum += num_list[j]

for i in range(num):
	num_a = num_list[i]
	temp_sum -= num_a
	sigma += num_a * temp_sum


sigma %= law
print(sigma)
a=input()
b=input()
l=[1,2,3]
l.remove(a)
l.remove(b)
ans=l[0]
print(ans)

### FIXED CODE ###

a=int(input())
b=int(input())
l=[1,2,3]
l.remove(a)
l.remove(b)
ans=l[0]
print(ans)
N = int(input())

a = 0
for i in range(3):
  if N[i] == 7:
    a = 1
    
if a = 1:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

N = input()

a = 0
for i in range(3):
  if N[i] == '7':
    a = 1
    
if a == 1:
  print('Yes')
else:
  print('No')
N = int(input())
#S = [input() for _ in range(N)]
S = ["".join(sorted(input())) for _ in range(N)]

ans = 0
for i in range(N):
    for j in range(i+1,N):
        if S[i] == S[j]:
            ans += 1
            S.pop(j)
            break
        break
print(ans)

### FIXED CODE ###

N = int(input())
S =  ["".join(sorted(input())) for _ in range(N)]

Sdic = {}
ans = 0

for i in range(N):
    if S[i] not in Sdic.keys():
        Sdic[S[i]] = 1
    else:
        ans += Sdic[S[i]]
        Sdic[S[i]] += 1
print(ans)
x = int(raw_input(x))
print x*x*x

### FIXED CODE ###

x = int(raw_input())
print x*x*x
n, m = map(int, input().split())

acList = [False] * n
waCount = 0
for i in range(m):
  p, s = map(str, input().split())
  p = int(p) - 1 # インデックスの調整
  print(acList)
  if acList[p]:
    continue
  if s == 'WA':
    waCount += 1
    continue
  acList[p] = True

print(sum(acList), waCount)


### FIXED CODE ###

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

acList = [False] * n
waList = [0] * n
waCount = 0
for i in range(m):
  p, s = map(str, input().split())
  p = int(p) - 1 # インデックスの調整
  if acList[p]:
    continue
  if s == 'WA':
    waList[p] += 1
    continue
  waCount += waList[p]
  acList[p] = True

print(sum(acList), waCount)
import math
n = int(input())
a = list(map(int, input().split()))
lsize = len(a)
bef = a[0]
for i in range(1, lsize):
  bef = math.gcd(bef,a[i])
print(bef)

### FIXED CODE ###

def gcd(m, n):
  x = max(m, n)
  y = min(m, n)
  if x % y == 0:
    return y
  else:
    while x % y != 0:
      z = x % y
      x = y
      y = z
    else:
      return z
n = int(input())
a = list(map(int, input().split()))
lsize = len(a)
bef = a[0]
for i in range(1, lsize):
  bef = gcd(bef,a[i])
hp = bef
print(hp)
from heapq import heappop, heappush
heap = []
N, M = map(int, input().split())
for i in list(map(int,input().split())):
    heappush(heap, i*-1)
for j in range(M):
    num = -((-heappop(heap))//2)
    heappush(heap)

print(sum(heap))

### FIXED CODE ###

from heapq import heappop, heappush
heap = []
N, M = map(int, input().split())
for i in list(map(int,input().split())):
    heappush(heap, i*-1)
for j in range(M):
    num = -((-heappop(heap))//2)
    heappush(heap, num)

print(sum(heap) * - 1)
from decimal import *
import math
a,b=map(str,input().split())
c=Decimal("a")
d=Decimal("b")
e=c*d
f=math.floor(e)
print(f)

### FIXED CODE ###

from decimal import *
import math
a,b=map(str,input().split())
c=Decimal(a)
d=Decimal(b)
e=Decimal(c*d)
f=math.floor(e)
print(f)
# -*- coding: utf-8 -*- 

number, length = map(int, input().split())
lst = []
for n in range(number):
    input = input()
    lst.append(input)

lst.sort()
moji = ""
for n in lst:
    moji += n
print(moji)


### FIXED CODE ###

# -*- coding: utf-8 -*-

input_list = input().split()

cnt7 = 0
cnt5 = 0

for n in input_list:
    if int(n) == 7:
        cnt7 += 1
    elif int(n) == 5:
        cnt5 += 1
    else:
        continue
if cnt7 == 1 and cnt5 == 2:
    print("YES")
else:
    print("NO")
if __name__ == '__main__':
  numbers = list(map(int, input().split()))
  k = int(input())
  sum = 0
  for i in range(3):
    if i == numbers.index(max(numbers)):
      sum += max(numbers) * pow(2, k)
    else:
      sum += numbers[i]
  print(sum)

### FIXED CODE ###

a, b = map(int,input().split())
if a <= b:
  print(a)
elif a > b:
  print(a-1)
N, K = map(int, input().split())
V = list(map(int, input().split()))

def calc(l, r, d):
    hold = []
    for i in range(l):
        hold.append(V[i])
    for i in range(N-1, max(N-1-r,-1), -1):
        hold.append(V[i])
    hold.sort()
    return 0 if d >= len(hold) else sum(hold[d:]) 

ret = 0
for l in range(K+1):
    for r in range(K+1-l):
        d = max(K - l - r, 0)
        ret = max(ret, calc(l, r, d))
print(ret)

### FIXED CODE ###

N, K = map(int, input().split())
V = list(map(int, input().split()))
U = V[::-1]
ret = 0

m = min(N, K)
for l in range(m+1):
    for r in range(m+1-l):
        hold = V[:l] + U[:r]
        hold.sort()
        for d in range(K+1-l-r):
            ret = max(ret, sum(hold[d:]))

print(ret)
a = input().split('/')
if a[0] > 2019 and a[1] > 5:
  print('TBD')
  
else:
  print('Heisei')


### FIXED CODE ###

a = input().split('/')
if a[1][0] == '0':
  a[1] = a[1][1]
if int(a[0]) >= 2019 and int(a[1]) >= 5:
  print('TBD')
  
else:
  print('Heisei')
N = int(input())
s_cnt = []
for i in range(N):
    cnt = {}
    s = input()
    for si in s:
        if si in cnt:
            cnt[si] += 1
        else:
            cnt[si] = 1
    s_cnt.append(cnt)
#from collections import defaultdict
#min_ = defaultdict(int)
min_ = {}
for i in s_cnt:
    for j in i:
        for i in range(N):
           if j not in s_cnt[i]:
               continue
        if j not in min_:
            min_[j] = i[j]
        else:
            min_[j] = min(min_[j], i[j])
string = ''
for i in min_:
    #list_.append(i * min_[i])
    string += i * min_[i]
s = sorted(string)
print(''.join(s))


### FIXED CODE ###

N = int(input())
s_cnt = []
for i in range(N):
    cnt = {}
    s = input()
    for si in s:
        if si in cnt:
            cnt[si] += 1
        else:
            cnt[si] = 1
    s_cnt.append(cnt)
min_ = {}
for i in s_cnt:
    for j in i:
        if any([j not in s_cnt[k] for k in range(N)]):
               continue
        if j not in min_:
            min_[j] = i[j]
        else:
            min_[j] = min(min_[j], i[j])
string = ''
for i in min_:
    #list_.append(i * min_[i])
    string += i * min_[i]
s = sorted(string)
print(''.join(s))
import math

# inputList=[]
# for i in range(6):
#     inputNum = input()
#     inputList.append(inputNum)
inputa = input().split()
# inputb = input().split()

a = int(inputa[0])
# b = int(inputa[1])
# c = int(inputa[2])

# x = int(inputb[0])
# y = int(inputb[1])

if a == 1:
    print("Hello World")
    
elif a == 2:
    inputb = input().split()
    inputc = input().split()

b = int(inputb[0])
c = int(inputc[0])

print(b + c)

### FIXED CODE ###

import math

# inputList=[]
# for i in range(6):
#     inputNum = input()
#     inputList.append(inputNum)
inputa = input().split()
# inputb = input().split()

a = int(inputa[0])
# b = int(inputa[1])
# c = int(inputa[2])

# x = int(inputb[0])
# y = int(inputb[1])

if a == 1:
    print("Hello World")

elif a == 2:
    inputb = input().split()
    inputc = input().split()

    b = int(inputb[0])
    c = int(inputc[0])
    
    print(b + c)
a, b = map(int,raw_input().split())

if a<b:
    print "a < b"
elif a>b:
    print "a > b"
elif a==b:
    print "a == b"
else:
    print "none"


### FIXED CODE ###

a,b = map(int, input().split())
if a < b:
    print("a < b")
elif a > b:
    print("a > b")
else:
    print("a == b")
Alp =[A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z]*2
N = int(input())
S = list(input())
for i in range(len(S)):
	Anum = Alp.index(S[i])
    S.replace(S[i],Alp[Anum+N])
print("".join(S))

### FIXED CODE ###

Alp =["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]*2
N = int(input())
S = list(input())
for i in range(len(S)):
	Anum = Alp.index(S[i])
	S[i] = Alp[Anum+N]
print("".join(S))