Harryxun/stf_run huggingface dataset:
def insertionSort(lis,leng):
    for i in range(leng):
        v = lis[i]
        j = i - 1
        while j >= 0 and lis[j] > v:
            lis[j+1] = lis[j]
            j = j-1
        lis[j+1]=v
        print("".join(lis))

        
if __name__ == "__main__":
    lengg=int(input())
    liss=list(map(int,input().split()))
    insertionSort(liss,lengg)

### FIXED CODE ###

def insertionSort(lis,leng):
    for i in range(leng):
        v = lis[i]
        j = i - 1
        while j >= 0 and lis[j] > v:
            lis[j+1] = lis[j]
            j = j-1
        lis[j+1]=v
        print(*lis)

        
if __name__ == "__main__":
    lengg=int(input())
    liss=list(map(int, input().split()))
    insertionSort(liss,lengg)
N = int(input())
h = list(map(int,input().split()))
ans = h[0]
for i in range(1,N):
    if h[i]-h[i-1]>0:
        ans += h[i]-h[i-1]
print(ans)


### FIXED CODE ###

s = list(map(int,input().split()))
s.sort()
print(int(s[0]*s[1]/2))
n, x, m = map(int,input().split())
rem = [0] * m
chk = [0] * (m + 1)
rem[0] = x
for i in range(1,m):
  rem[i] = (rem[i - 1] ** 2) % m
  if chk[rem[i - 1] ** 2 % m] > 1:
    temp1 = (rem[i - 1] ** 2) % m
    temp2 = i
  else:
    temp1 = (rem[i - 1] ** 2) % m
    temp2 = i

for i in range(m):
  if rem[i] == temp1:
    temp3 = i
    break

if temp2 != temp3:
  num = (n - temp3) // (temp2 - temp3)
  S = sum(rem[:temp3]) + sum(rem[temp3:temp2]) * num + sum(rem[temp3:n - (num * (temp2 - temp3))])
  print(S)
else:
  print(sum(rem))

### FIXED CODE ###

n, x, m = map(int,input().split())
rem = [0] * m
chk = [0] * (m + 1)
rem[0] = x
if x == 0:
  print(0)
  exit()

for i in range(1,m):
  rem[i] = (rem[i - 1] ** 2) % m
  if chk[rem[i - 1] ** 2 % m] > 1:
    temp1 = (rem[i - 1] ** 2) % m
    temp2 = i
  else:
    temp1 = (rem[i - 1] ** 2) % m
    temp2 = i

for i in range(m):
  if rem[i] == temp1:
    temp3 = i
    break

if temp2 != temp3:
  num = (n - temp3) // (temp2 - temp3)
  S = sum(rem[:temp3]) + sum(rem[temp3:temp2]) * num + sum(rem[temp3:n - (num * (temp2 - temp3))])
  print(S)
else:
  print(sum(rem))
N = int(input())
H = raw_input().split()


tmp=[]
for i in range(len(H)-1, -1, -1):
    tmp.append(all([all(H[:i]<=H[i]), all(H[i]<=H[i+1:])]))
print(sum(tmp))

### FIXED CODE ###

import numpy as np
N = int(input())
H = np.array(list(map(int, input().split())))
tmp = []
for i in range(1, len(H)):
    tmp.append(all(H[:i]<=H[i]))
print(sum(tmp)+1)
n=int(input())
a=[int(i) for i in input().split()]
ans=0
for i in range(n):
  if (i+1)%2 ==1 and a[i]%2 ==1:
    c+=1
else:
  print(ans)

### FIXED CODE ###

N = int(input())
A = [int(i) for i in input().split()]
c = 0
 
for i in range(N):
  if (i+1) % 2 == 1 and A[i] % 2 == 1:
    c += 1
else:
  print(c)
from scipy.misc import comb
import math
MOD = 10 ** 9 + 7
N, K = map(int, input().split())
ans = 0
for j in range(min(K, N-K+1)):
    if j != N-K:
        tmp = (comb(N-K+1, j+1)) % MOD
    else:
        tmp = 1
    print(int((comb(K-1, j) * tmp) % MOD))
if min(K, N-K+1) == N-K+1:
    for i in range(N-K+1, K):
        print(0)


### FIXED CODE ###

def comb(n, r):
    return math.factorial(n) // math.factorial(r) // math.factorial(n-r)
import math

MOD = 10 ** 9 + 7
N, K = map(int, input().split())
ans = 0
for j in range(K):
    if N-K - j < 0:
        print(0)
        continue
    tmp = (comb(N-K+1, j+1)) % MOD
    print(int((comb(K-1, j) * tmp) % MOD))
n = int(input())
num=0
for i in range(1,n+1):
    k=0
    c=i
    while True:
        if c%2==0:
            c/=2
            k+=1
        else:
            break
    if k>num:
        num=k
        ans=i
print(ans)


### FIXED CODE ###

n = int(input())
num=0
if n==1:
    print(1)
    exit()
else:
    for i in range(1,n+1):
        k=0
        c=i
        while True:
            if c%2==0:
                c/=2
                k+=1
            else:
                break
        if k>num:
            num=k
            ans=i
print(ans)
A,B=map(int,input().split())
print("safe" if S>W else "unsafe")

### FIXED CODE ###

A,B=map(int,input().split())
print("safe" if A>B else "unsafe")
s = map(int,input())
a = map(str,input())
if s >= 3200:
 print("red")
else:
 print(s)

### FIXED CODE ###

a = int(input())
s = str(input())
if a >= 3200:
 print(s)
if a < 3200:
 print("red")
from collections import deque
H,W=map(int,input().split())
white=0
s=[]
for y in range(H):
   line=input()
    white+=line.count('.')
    s.append(list(line))
     
q = deque([(0,0,1)])
q_append=q.append
q_popleft=q.popleft
while q:
    x,y,l=q_popleft()
    if s[y][x]!='.':
        continue
    if x==W-1 and y==H-1:
        print(white-l)
        break
    s[y][x]='*'
    for d in [(1,0),(0,1),(-1,0),(0,-1)]:
        nx, ny=(x+d[0],y+d[1])
        if 0<=nx<W and 0<=ny<H:
            q_append((nx,ny,l+1))
else:
    print(-1)
        

### FIXED CODE ###

from collections import deque
H,W=map(int,input().split())
white=0
s=[]
for y in range(H):
    line=input()
    white+=line.count('.')
    s.append(list(line))

q = deque([(0,0,1)])
q_append=q.append
q_popleft=q.popleft
while q:
    x,y,l=q_popleft()
    if s[y][x]!='.':
        continue
    if x==W-1 and y==H-1:
        print(white-l)
        break
    s[y][x]='*'
    for d in [(1,0),(0,1),(-1,0),(0,-1)]:
        nx, ny=(x+d[0],y+d[1])
        if 0<=nx<W and 0<=ny<H:
            q_append((nx,ny,l+1))
else:
    print(-1)
import math
a,b,c,d=map(int,input().split())
f=lambda n:n-(n//c+n//d-n//(c*d//math.gcd(c,d)))
print(f(b)-f(a-1))

### FIXED CODE ###

import fractions 
a,b,c,d=map(int,input().split())
f=lambda n:n-(n//c+n//d-n//(c*d//fractions.gcd(c,d)))
print(f(b)-f(a-1))
x = int(input())

ans_list = [1]

for i in range(2,x+1):
    cnt = 2
    while True:
        tmp = i ** cnt
        if tmp > x:
            break
        ans_list += [tmp]
        cnt += 1
        
    
ans_list.sort()

for i in ans_list[::-1]:
    if i <= x:
        print(i)
        break

### FIXED CODE ###

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

if (abs((a - b)) <= d) and (abs((c - b)) <= d) or abs(c-a) <=d :
    print('Yes')
else:
    print('No')
import sys, heapq
from collections import deque
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''

N, K = map(int, input().split())
V_init = deque(map(int, input().split()))
max_score = 0
hands = [0] * K
heapq.heapify(hands)

for i_rget in range(K + 1):
	for i_lget in range(max(K - i_rget, 0) + 1):
		for i_del in range(max(K - i_rget - i_lget, 0) + 1):
			score = 0
			hands = [0] * K
			V = deque.copy(V_init)
			for i in range(i_rget + 1):
				if i > 0 and V:
					tmp = V.pop()					
					heapq.heappush(hands, tmp)
					score += tmp
				
			for i in range(i_lget + 1):
				if i > 0 and V:
					tmp = V.popleft()
					heapq.heappush(hands, tmp)
					score += tmp
			
			for i in range(i_del + 1):
				if i > 0:
					tmp = heapq.heappop(hands)
					score -= tmp
			
			if score > max_score:
				max_score = score

print(max_score)


### FIXED CODE ###

import sys, heapq, copy
from collections import deque
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''

N, K = map(int, input().split())
V_init = deque(map(int, input().split()))
max_score = 0
hands = [0] * K
heapq.heapify(hands)

for i_rget in range(K + 1):
	for i_lget in range(max(K - i_rget, 0) + 1):
		tmp = 0
		score = 0
		hands = [0] * K
		V = copy.copy(V_init)
		for i in range(i_rget + 1):
			if i > 0 and V:
				tmp = V.pop()					
				heapq.heappush(hands, tmp)
				score += tmp
			
		for i in range(i_lget + 1):
			if i > 0 and V:
				tmp = V.popleft()
				heapq.heappush(hands, tmp)
				score += tmp
		
		for i in range(max(K - i_rget - i_lget, 0) + 1):
			if i > 0:
				tmp = heapq.heappop(hands)
				if tmp < 0:
					score -= tmp
				else:
					break
		
		if score > max_score:
			max_score = score

print(max_score)
from collections import deque

N, M, K = [int(n) for n in input().split()]
desk_a = deque([int(n) for n in input().split()], maxlen=200001)
desk_b = deque([int(n) for n in input().split()], maxlen=200001)

def max_n_book(desk_a, desk_b, count=0, k=K):
    if k < 0:
        return count - 1
    if len(desk_a) != 0:
        book_a = desk_a.popleft()
        count_a = max_n_book(desk_a, desk_b, count=count+1, k=k-book_a)
    else:
        count_a = count
    # if len(desk_b) != 0:
    #     book_b = desk_b.popleft()
    #     count_b = max_n_book(desk_b, desk_b, count=count+1, k=k-book_b)
    # else:
    #     count_b = count
    # return max(count_a, count_b)
    return count_a

n_book = max_n_book(desk_a, desk_b, count=0, k=K)
print(n_book)


### FIXED CODE ###

N, M, K = map(int, input().split())
desk_a = list(map(int, input().split()))
desk_b = list(map(int, input().split()))

sum_a = [0]
sum_b = [0]

for i in range(N):
    sum_a.append(sum_a[-1] + desk_a[i])
for i in range(M):
    sum_b.append(sum_b[-1] + desk_b[i])

ans = 0
j = M
for i in range(N+1): 
    a = sum_a[i]
    if K - a < 0:
        break
    while sum_b[j] > K - a: 
        j -= 1
    ans = max(ans, i+j)

print(ans)
N=int(input())
S=input()
ans=0
for i in range(10):
  str_i = str(i)
  i_index==S.find(str_i)
  if i_index==-1:
    continue
  for j in range(10):
    str_j=str(j)
    j_index=S.find(str_j, i_index+1)
    if j_index==-1:
      continue
    for k in range(10):
      str_k=str(k)
      k_index=S.find(str_k, j_index+1) 
      if k_index!=-1:
        ans+=1
print(ans)

### FIXED CODE ###

N=int(input())
S=input()
ans=0
for i in range(10):
  str_i = str(i)
  i_index=S.find(str_i)
  if i_index==-1:
    continue
  for j in range(10):
    str_j=str(j)
    j_index=S.find(str_j, i_index+1)
    if j_index==-1:
      continue
    for k in range(10):
      str_k=str(k)
      k_index=S.find(str_k, j_index+1) 
      if k_index!=-1:
        ans+=1
print(ans)
n,m=map(int,input().split())
a=list(map(int,input().split()))
for i in range(m):
    m-=a[i]
if m>=0:
    print m
else:
    print -1

### FIXED CODE ###

n,m=map(int,input().split())
a=list(map(int,input().split()))
for i in range(m):
    n-=a[i]
if n>=0:
    print (n)
else:
    print (-1)
H,N=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(N)]
dp=[0]*(H)
for i in range (1,H+1):
    dp[i]=min(dp[i-a]+b for a,b in ab)
print(dp[H])

### FIXED CODE ###

H,N=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(N)]
x=max(a for a,b in ab)
dp=[0]*(H+x)
for i in range (1,H+x):
    dp[i]=min(dp[i-a]+b for a,b in ab)
print(dp[H])
A, B, K = [int(x) for x in input().split(" ")]

if A >= K:
  print("{} {}".format(A-K, B))
elif A < K and A+B >= K:
  print("{} {}".format(0, (A-K/2)+(B-K/2))
else:
  print(0)


### FIXED CODE ###

A, B, K = [int(x) for x in input().split(" ")]

if A >= K:
  print("{} {}".format(A-K, B))
elif A < K and A+B >= K:
  print("{} {}".format(0, int(A-K/2+B-K/2)))
else:
  print(0, 0)
a,b,c,d=map(int,input().split())

print("Yes" if ((abs(a-b)<=d and (abs(c-b)<=d or (abs(c-a)<=d) else "No") 


### FIXED CODE ###

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

print("Yes" if ((abs(a-b)<=d and (abs(c-b)<=d)) or abs(c-a)<=d) else "No")
D, N = map(int, input().split())
if D==0:
    list1  = range(1,100,1)
    print(list1[N-1])
elif D==1:
    list2 = range(100,100*100,100)
    print(list2[N-1])
elif D==2:
    list3 = range(1000,100*1000,1000)
    print(list3[N-1])

### FIXED CODE ###

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

if N == 100:
    print(101*100**D)
else:
    print(N*100**D)
n,m = input().split()
n = int(n)
m = int(m)
 
row_x = input().split()
for i in range(m):
    row_x[i] = int(row_x[i])
 
if n >= m:
    print(0)
else:
    difference = []
    maximun = []
    x = sorted(row_x)
 
    for i in range(m-1):
        diffe = x[i+1]-x[i]
        difference.append(diffe)
        if len(maximun) < (n-1):
            maximun.append(diffe)
        elif min(maximun) < diffe:
            maximun.remove(min(maximun))
            maximun.append(diffe)           

    print(sum(difference)-sum(maximun))

### FIXED CODE ###

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

if n >= m:
    print(0)
    exit()
else:
    difference = []
    x.sort()
 
    for i in range(m-1):
        difference.append(x[i+1]-x[i])
 
    difference.sort()
 
    print(sum(difference[:m-n]))
def main():
    n, a, b = map(int, input().split())
    
    ball = [0]*n
    count = 0
    flag = True
    if a == 0 :
        print(0)
        exit(0)

    while flag:
        while flag:
            ball[count]="b"
            count += 1
            if count == n:
                flag = False
            if count % a == 0:
                break
    
        while flag:
            ball[count]="r"
            count += 1
            if count == n:
                flag = False
            if count % (a + b) == 0:
                break
            
     

    print(ball.count("b"))


if __name__ == "__main__":
    main()

### FIXED CODE ###


def main():
    S = input()

    flag = False
    for i in range(2):
        tmp = S[i]
        if tmp != S[i+1]:
            flag = True
    if flag : print("Yes")
    else: print("No")

if __name__ == "__main__":
    main()
import itertools
N=int(input())
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
x=prime_factorize(N)
l=list(set(prime_factorize(N)))
s=[]
for i in range(len(l)):
    s.append([])
for i in l:
    a=l.index(i)
    b=i
    for j in range(x.count(i)):
        s[a].append(i)
        i*=b
t=list(itertools.chain.from_iterable(s))
ans=0
while len(t)>0:
    p=t.pop(t.index(min(t)))
    sp=s[l.index(p)]
    ssp=sp[len(sp)-1]
    sp.pop(sp.index(ssp))
    t.pop(t.index(ssp))
    ans+=1
print(ans)    
        





            
    


    


    
    














    


    














### FIXED CODE ###

import collections
N=int(input())
if N==1:
    print(0)
    exit()
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
c = collections.Counter(prime_factorize(N)) 
s=list(set(prime_factorize(N)))
ans=0
def a(n):
    return (1/2)*n*(n+1)
def f(n):
    ans=0
    x=1
    while n>=a(x):
        x+=1
        ans+=1
    return ans
for i in s:
    x=c[i]
    ans+=f(x)
print(ans)
N = int(input())
A = int(input())
B = int(input())

if N*A > B:
    print(B)
elif N*A < B:
    print(A*N)
else:
    print(A*N)

### FIXED CODE ###

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

if N*A>=B:
    print(B)
elif N*A<=B:
    print(N*A)
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


n, m = list(map(int, input().split()))
uf = UnionFind(n)
for i in range(m):
    a, b = map(int, input().split())
    uf.union(a, b)
print(uf.group_count()-1)


### FIXED CODE ###

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


n, m = list(map(int, input().split()))
uf = UnionFind(n)
for i in range(m):
    a, b = map(int, input().split())
    uf.union(a-1, b-1)
print(uf.group_count()-1)
import math

n, x = map(int, input().split())
num = list(map(int,input().split()))
d = abs(num[0]-x)
for nn in num:
    d=math.gcd(t,abs(n-x))
print(d)

### FIXED CODE ###

import fractions

n, x = map(int, input().split())
num = list(map(int,input().split()))
d = abs(num[0]-x)
for nn in num:
	d=fractions.gcd(d, abs(nn-x))
print(d)
a = int(input())
b = int(input())
A = -1000<= a <= 0, 0< b <= 1000
B =  0<= a, 0>b
C = a==b
if A:
    print(a<b)
elif B:
    print(a>b)
elif C:
    print(a=b)


### FIXED CODE ###

a,b = input().split()
a = int(a)
b = int(b)
if a < b:
    print("a < b")
elif a > b:
    print("a > b")
else:
    print("a == b")
N , Q = map(int,input().split())
graph = [[] for _ in range(N)]
point = [0] * N
for _ in range(N - 1):
    a , b = map(int,input().split())
    graph[a - 1].append(b - 1)
    graph[b - 1].append(a - 1)
#print(graph)
for _ in range(Q):
    a , b = map(int,input().split())
    a = a - 1
    point[a] += b
# dfsを用いて累積和を計算する
# 初期状態だと前の値がないためデフォルト引数に-1を代入
def dfs(now , prev = -1):
    for next in graph[now]:
        # 次のノードが前に参照した値の時はcontinue
        if next == prev:
            continue
        # 現在の値を次のポイントに加算することで累積和をとる
        point[next] += point[now]
        # 次のノードと現在のノードを引数にdfsを継続する
        dfs(next , now)
 
dfs(0)
print(*point)

### FIXED CODE ###

N, Q = map(int,input().split()) # 複数の数字を変数に格納
List_ab = [list(map(int,input().split())) for i in range(N-1)] # [[1,2],[3,4],[5,6]]
List_px = [list(map(int,input().split())) for i in range(Q)] # [[1,2],[3,4],[5,6]]

count_list = [0]*N

List_ab.sort()

for i in range(Q):
    count_list[List_px[i][0]-1] += List_px[i][1]
        
for i in range(N-1):
    count_list[List_ab[i][1]-1] += count_list[List_ab[i][0]-1]
    
print(*count_list)
a = int(input())
b = int(1)
while True:
	if b < a+1:
		x = map(int,input().split(' '))
		x.sort()
		if x[0]**2 + x[1]**2 == x[2]**2:
			print('YES')
		else:
			print('NO')
		b += 1
		continue
	else:
		break

### FIXED CODE ###

for val in range(input()):
	x = map(int,raw_input().split(' '))
	x.sort()
	if x[0]**2+x[1]**2==x[2]**2: print 'YES'
	else: print 'NO'
n = int(input())
commands = [input().split() for _ in range(n)]

l = []
for com in commands:
    val = com[1]
    com = com[0]
    if com=='insert':
        l.insert(0, val)
    elif com=='delete':
        l.remove(val)
    elif com=='deleteFirst':
        l.pop(0)
    elif com=='deleteLast':
        l.pop()
s = ' '.join(l)
print(s)


### FIXED CODE ###

from collections import deque

n = int(input())
commands = [input() for _ in range(n)] # splitとかしてると間に合わない

l = deque()
for com in commands:
    if com[0]=='i':
        l.appendleft(com[7:])
    elif com[6]=='F':
        l.popleft()
    elif com[6]=='L':
        l.pop()
    else:
        try:
            l.remove(com[7:])
        except:
            pass

s = ' '.join(l)
print(s)
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
import itertools

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


def resolve():
    n, m, q = map(int, input().split())
    a_d_list = []
    for i in range(q):
        a_d_list.append(list(map(int,input().split())))

    l = [i for i in range(1, m)]
    combi_list = list(itertools.combinations_with_replacement(l, n))

    ans_dic = {}
    for combi in combi_list:
        ans_dic[str(combi)] = 0

    for combi in combi_list:

        for i, a_d in enumerate(a_d_list):
            a = a_d[0]
            b = a_d[1]
            c = a_d[2]
            d = a_d[3]

            if combi[b-1] - combi[a-1] == c:

                ans_dic[str(combi)] += d


    print(max(ans_dic.values()))





if __name__ == "__main__":
    resolve()



### FIXED CODE ###

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
import itertools

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


def resolve():
    n, m, q = map(int, input().split())
    a_d_list = []
    for i in range(q):
        a_d_list.append(list(map(int,input().split())))

    l = [i for i in range(1, m+1)]
    combi_list = list(itertools.combinations_with_replacement(l, n))

    ans_dic = {}
    for combi in combi_list:
        ans_dic[str(combi)] = 0

    for combi in combi_list:

        for i, a_d in enumerate(a_d_list):
            a = a_d[0]
            b = a_d[1]
            c = a_d[2]
            d = a_d[3]

            if combi[b-1] - combi[a-1] == c:

                ans_dic[str(combi)] += d


    print(max(ans_dic.values()))





if __name__ == "__main__":
    resolve()
n = int(input())
length = int(n / 19) + 1 
d = []
for i in range(length):
    d += list(map(int, input().split()))

start, end = 1, 10
l = []
flag = False
for j in range(1, len(d)+1):
    for i in range(0, len(d)):
        tmp = ''.join(map(str, d[i:i+j]))
        if len(tmp) > 1 and tmp[0] == '0':
            pass
        elif len(tmp) == j:
            l.append(int(tmp))
    l = sorted(set(l))
    if start == 1:
        for k in range(0, 10):
            if k not in l:
                print(k)
                flag = True
                break
    else:
        for k in range(start, end):
            if k not in l:
                print(k)
                flag = True
                break
    if flag:
        break
    start, end = start*10, end*10
    l = []

### FIXED CODE ###

n = int(input())
length = int(n / 19) + 1
if n > 19 and n % 19 == 0:
    length -= 1
d = []
for i in range(length):
    d += list(map(int, input().split()))
start, end = 1, 10
l = []
flag = False
for j in range(1, len(d)+1):
    for i in range(0, len(d)):
        tmp = ''.join(map(str, d[i:i+j]))
        if len(tmp) > 1 and tmp[0] == '0':
            pass
        elif len(tmp) == j:
            l.append(int(tmp))
    l = sorted(set(l))
    if start == 1:
        for k in range(0, 10):
            if k not in l:
                print(k)
                flag = True
                break
    else:
        for k in range(start, end):
            if k not in l:
                print(k)
                flag = True
                break
    if flag:
        break
    start, end = start*10, end*10
    l = []