Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

ans = []
for i in range(int(input())):
    now = int(input())
    if now in ans:
        ans.remove(now)
    else:
        ans.append(now)
print(len(ans))


### FIXED CODE ###

time = int(input())
ans = []
n = 0
for i in range(time):
    ans.append(input())
ans.sort(key=int)
while n+1 < len(ans):
    if ans[n] == ans[int(n + 1)]:
        ans.pop(n)
        ans.pop(n)
    else:
        n += 1
print(len(ans))
### BUGGY CODE ###

S = str(input())
Q = int(input())
Qer = [list(map(str,input().split())) for i in range(Q)]
for i in range(Q):
    if Qer[i][0] == "1":
        S = S[::-1]
    else:
        if Qer[i][1] =="1":
            S = Qer[i][2] + S
        else:
            S = S+Qer[i][2]

print(S)

### FIXED CODE ###

from collections import deque
S = str(input())
Q = int(input())
Qer = [list(map(str,input().split())) for i in range(Q)]
flag = True
anss = deque(S)
for i in range(Q):
    if Qer[i][0] == "1":
        flag = not flag
    else:
        if flag ==True:
            if Qer[i][1] =="1":
                anss.appendleft(Qer[i][2])
            else:
                anss.append(Qer[i][2])
        else:
            if Qer[i][1] =="2":
                anss.appendleft(Qer[i][2])
            else:
                anss.append(Qer[i][2])
anss=''.join(anss)
if flag == True:
    print(anss)
else:
    anss = anss[::-1]
    print(anss)
### BUGGY CODE ###

H,W=map(int,input().split())

L=[[0]*W for i in range(H)]
R=[[0]*W for i in range(H)]
U=[[0]*W for i in range(H)]
D=[[0]*W for i in range(H)]

cntr=0
cntd=[0]*W
for i in range(H):
    temp=input()
    for j in range(W):
        if temp[j]!="#":
            if j==0:
                L[i][j]=1
            else:
                L[i][j]=L[i][j-1]+1
            cntr+=1
            if i == 0:
                U[i][j] = 1
            else:
                U[i][j]=U[i-1][j]+1
            cntd[j]+=1
        else:
            for k in range(cntr):
                R[i][j-1-k]=k+1
            cntr=0
            for k in range(cntd[j]):
                D[i-1-k][j]=k+1
            cntd[j]=0
    if cntr!=0:
        for k in range(cntr):
            R[i][W - 1 - k] = k + 1
        cntr=0
for i in range(W):
    if cntd[i]!=0:
        for k in range(cntd[i]):
            D[H-1-k][i]=k+1

ans=[]
for i in range(H):
    for j in range(W):
        ans.append(L[i][j]+R[i][j]+U[i][j]+D[i][j]-3)
print(max(ans))








### FIXED CODE ###

H,W=map(int,input().split())

s=[[0]*W for i in range(H)]

for i in range(H):
    cnt = 0
    temp=input()

    for j in range(W):
        if temp[j]!="#":
            cnt+=1
        else:
            if j==0:
                continue
            else:
                for k in range(cnt):
                    s[i][j-(1+k)]=cnt
                cnt=0
    if cnt!=0:
        for k in range(cnt):
            s[i][W-1 - k] = cnt
        cnt = 0

ans=[]
mx=0
for i in range(W):
    cnt=0
    for j in range(H):
        if s[j][i]!=0:
            cnt+=1
            mx=max(mx,s[j][i])
        else:
            if j==0:
                continue
            else:
                ans.append(mx+cnt-1)
                cnt=0
                mx=0
    if cnt!=0:
        ans.append(mx+cnt-1)
        mx=0
print(max(ans))
### BUGGY CODE ###


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

bits = [0] * 50

for i in range(N):
    for j in range(50):
        if A[i] >> j & 1:
            bits[j] += 1

ans = 0
for i in range(K+1):
    tmp = 0
    for j in range(50):
        bit_count = bits[j]
        if i >> j & 1:
            bit_count = N - bit_count
        tmp += 2 ** j * bit_count
    ans = max(ans, tmp)

print(ans)


### FIXED CODE ###

MAX_DIGIT = 50
SMALL = 1
EQUAL = 0

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

dp = [[-1 for _ in range(2)] for _ in range(100)]
dp[0][0] = 0

for d in range(MAX_DIGIT):
    mask = 1 << (MAX_DIGIT - d - 1)
    # A で元々 d 桁目にビットが立っているものの個数
    num = 0
    for i in range(N):
        if A[i] & mask:
            num += 1

    # X の d 桁目を 0, 1 にしたときのコスト
    cost0 = mask * num  # 元々の 1 の個数
    cost1 = mask * (N - num)  # 元々の 0 の個数(反転するから)

    # "K 未満 -> K 未満" の遷移
    if dp[d][SMALL] != -1:
        # 0 でも 1 でも自在に大きい方
        dp[d+1][SMALL] = max(dp[d+1][SMALL], dp[d][SMALL] + max(cost0, cost1))

    # "K ぴったり -> K 未満" の遷移
    if dp[d][0] != -1:
        if K & mask:
            # K の d 桁目が 1 だったら、X の d 桁目は 0 にする
            dp[d+1][SMALL] = max(dp[d+1][SMALL], dp[d][EQUAL] + cost0)

    # "K ぴったり -> K ぴったり" の遷移
    if dp[d][EQUAL] != -1:
        if K & mask:
            dp[d+1][EQUAL] = max(dp[d+1][EQUAL], dp[d][EQUAL] + cost1)
        else:
            dp[d+1][EQUAL] = max(dp[d+1][EQUAL], dp[d][EQUAL] + cost0)


ans = max(dp[MAX_DIGIT][EQUAL], dp[MAX_DIGIT][SMALL])
print(ans)
### BUGGY CODE ###

from itertools import accumulate, islice
from bisect import bisect_left

n = int(input())
xs = [int(x) for x in input().split()]

ys = list(accumulate(xs))
zs, total = ys[:-1], ys[-1]

res = max(xs) - min(xs)
for i, z in islice(enumerate(zs), 1, n-1):
    j = bisect_left(zs, z//2, hi=i)
    splits = ((zs[j+k], z - zs[j+k]) for k in (-1, 0, 1) if 0 <= j+k <= i)
    a, b = min(splits, key=lambda s:abs(s[0]-s[1]))

    j = bisect_left(zs, (total - z)//2 + z, lo=i)
    splits = ((zs[j+k] - z, total - zs[j+k]) for k in (-1, 0, 1) if i <= j+k <= n-2)
    c, d = min(splits, key=lambda s:abs(s[0]-s[1]))

    minn, _, _, maxx = sorted((a,b,c,d))
    if maxx - minn < res:
        res = maxx - minn

print(res)

### FIXED CODE ###

from itertools import accumulate, islice
from bisect import bisect_left

n = int(input())
xs = [int(x) for x in input().split()]
ys = list(accumulate(xs))
zs, total = ys[:-1], ys[-1]

rs = range(2, n-2)
v = []
for i, z in islice(enumerate(zs), 1, n-1):
    j = bisect_left(zs, z//2)
    splits = ((zs[j+k], z - zs[j+k]) for k in (-1, 0, 1) if 0 <= j+k <= i)
    a, b = min(splits, key=lambda s:abs(s[0]-s[1]))

    j = bisect_left(zs, (total - z)//2 + z)
    splits = ((zs[j+k] - z, total - zs[j+k]) for k in (-1, 0, 1) if i <= j+k <= n-2)
    c, d = min(splits, key=lambda s:abs(s[0]-s[1]))

    minn, _, _, maxx = sorted((a,b,c,d))
    v.append(maxx - minn)

print(min(v) if v else max(xs) - min(xs))
### BUGGY CODE ###

from collections import deque
import sys
sys.setrecursionlimit(10**7)

N=int(input())
M=N*(N-1)//2
D=[[]for i in range(M)]
F=[[]for i in range(M)]
for i in range(N):
  x=list(map(int,input().split()))
  for j in range(N-2):
    a,b,c=i+1,x[j],x[j+1]
    x1,x2=min(i+1,x[j]),max(i+1,x[j])
    y1,y2=min(i+1,x[j+1]),max(i+1,x[j+1])
    e=M-(N-x1)*(N-x1+1)//2
    f=e+(x2-x1-1)
    g=M-(N-y1)*(N-y1+1)//2
    h=g+(y2-y1-1)
    D[f].append(h)
    F[h].append(f)
P=[-1]*M
ans=0
def bfs(u):
  P[u]=0
  B.append(u)
  queue=deque([u])
  while queue:
    v=queue.popleft()    
    for i in D[v]:
      if i in B:
        print(-1)
        exit()
      if P[v]+1>P[i]:
        P[i]=P[v]+1
        queue.append(i)
for i in range(M):
  B=[]
  if len(F[i])==0:
    bfs(i)
if min(P)==-1:
  print(-1)
else:
  print(max(P)+1)

### FIXED CODE ###

from collections import deque
import sys
sys.setrecursionlimit(10**7)

N=int(input())
M=N*(N-1)//2
D=[[]for i in range(M)]
F=[[]for i in range(M)]
for i in range(N):
  x=list(map(int,input().split()))
  for j in range(N-2):
    a,b,c=i+1,x[j],x[j+1]
    x1,x2=min(i+1,x[j]),max(i+1,x[j])
    y1,y2=min(i+1,x[j+1]),max(i+1,x[j+1])
    e=M-(N-x1)*(N-x1+1)//2
    f=e+(x2-x1-1)
    g=M-(N-y1)*(N-y1+1)//2
    h=g+(y2-y1-1)
    D[f].append(h)
    F[h].append(f)
    
q=deque()
P=[0]*M
for i in range(M):
  if len(F[i])==0:
    q.append((i,0))

r=[]
while q:
  v1,cnt=q.popleft()
  r.append((v1,cnt))
  for v2 in D[v1]:
    P[v2]+=1
    if P[v2]==len(F[v2]):
      q.append((v2,cnt+1))

if len(r)!=M:
  print(-1)
else:
  print(r[-1][-1]+1)
### BUGGY CODE ###

from itertools import accumulate

N = int(input())
ts = list(map(int, input().split()))
vs = list(map(int, input().split()))

# 各区間の制限速度条件のみを満たす最大速度のグラフを求める
accTs = list(accumulate(ts))
sumT = accTs[-1]
vMaxs = [100] * (2 * sumT + 1)
for v, l, r in zip(vs + [0, 0], [0] + accTs[:-1] + [0, sumT], accTs + [0, sumT]):
    vms = []
    for t2 in range(sumT * 2 + 1):
        t = t2 / 2
        if t <= l:
            vms += [v + l - t]
        elif t <= r:
            vms += [v]
        else:
            vms += [v + t - r]

    # 最小値がその時刻における列車の速度になる
    vMaxs = list(map(min, vMaxs, vms))

print(sum(vMaxs) / 2)



### FIXED CODE ###

N = int(input())
ts = list(map(int, input().split()))
vs = list(map(int, input().split()))

sumT = sum(ts)
va = [min(i / 2, sumT - i / 2) for i in range(2 * sumT + 1)]

accT = 0
for t, v in zip(ts, vs):
    for i in range(accT, accT + 2 * t + 1):
        va[i] = min(va[i], v)
    accT += t * 2

for i in range(len(va) - 1):
    if va[i + 1] - va[i] > 0.5:
        va[i + 1] = va[i] + 0.5

for i in range(len(va) - 1)[::-1]:
    if va[i] - va[i + 1] > 0.5:
        va[i] = va[i + 1] + 0.5

print(sum(va) / 2)
### BUGGY CODE ###

from collections import defaultdict as dd
from copy import deepcopy as dc
import time
st = time.time()
N = int(input())
e = dd(list)

matche = dd(list)

for i in range(1, N + 1):
  e[i] = list(map(int, input().split()))

for i in range(1, N + 1):
  for j in range(N - 2):
    if matche[(min(e[i][j], i), max(e[i][j], i))] != []:
      matche[(min(e[i][j], i), max(e[i][j], i))].append((min(i, e[i][j + 1]), max(i, e[i][j + 1])))
    else:
      matche[(min(e[i][j], i), max(e[i][j], i))].append((min(i, e[i][j + 1]), max(i, e[i][j + 1])))
    #print(i, j, matche)
#print(matche)
matchkey = dc(matche)
S = matchkey.keys()
visited = dd(int)
depth = 0
#print(S)
def dfs(s):
  if time.time() - st > 1.90:
    print(N * (N - 1) // 2)
  global visited
  global depth
  temp = 0
  #print(s)
  if matche[s] != []:
    for c in matche[s]:
      if visited[c] == 1:
        print(-1)
        #print(visited, c)
        exit(0)
      else:
        depth += 1
        visited[c] = 1
        #print(depth)
        temp = max(dfs(c), temp)
        depth -= 1
        visited[c] = 0
  else:
    return depth
  return temp
temp = 0
for s in S:
  temp = max(dfs(s), temp)
print(temp + 1)

### FIXED CODE ###

N = int(input())
A = []
for i in range(N):
  A.append(list(map(int, input().split())))
#試合にコードを割り当てる
#of[l] = 前の番号の競技者の「既に数え上げた試合の数」
#r = 相手
#l = じぶん
def code(l, r, of):
  if l > r:
      l, r = r, l
  return of[l] + r - l - 1
#オフセットを作る。重複の試合を取り除くため、
#1ならN - 1試合、2ならN - 2試合...という風にする
of = [0] * (N + 1)
for i in range(N):
  of[i + 1] = of[i] + N - i - 1
#print(of)
#試合の前後関係を持つグラフ
#たぶんDAGになっている。なってないなら試合組めないと思う
g = [[] for _ in range(N * (N - 1) // 2)]
for i in range(N):
  for j in range(N - 2):
      fcode = code(i, A[i][j] - 1, of)
      tcode = code(i, A[i][j + 1] - 1, of)
      g[fcode].append(tcode)
#print(g)
def sort_topologically(g):
  n = len(g)
  #ecはコードによる試合頂点の入次数を記録
  ec = [0] * n
  for i in range(n):
    for e in g[i]:
      ec[e] += 1
  #print(ec)
  #retは入次数0の頂点を順にとってきている
  ret = [0] * n
  q = 0
  for i in range(n):
    if ec[i] == 0:
      ret[q] = i
      q += 1
  #p = 参照中の入次数0の試合
  #q = 入次数0の頂点数
  #while文はp == qの時点で終わる
  #for文では、入次数0の頂点pから出る有向辺を除去する
  #その上で入次数0の頂点が増えればretへ追加
  #このretは確かにトポロジカル順序になる
  p = 0
  #print(ret)
  while p < q:
    for to in g[ret[p]]:
      ec[to] -= 1
      if ec[to] == 0:
        ret[q] = to
        q += 1
    p += 1
  #ソートが終わったなら全ての辺は除去済みのはずである
  #このグラフは一応連結しているはずなので閉路検知ができる
  for i in range(n):
    if ec[i] > 0:
      return None
  return ret

od = sort_topologically(g)
#print(od)
#Noneなら閉路を持つので試合構築不可能
if not od:
  print(-1)
else:
  #dp = トポロジカル順序を持つ順序集合の先頭からi番目までを見た際の最大パス長
  dp = [1] * (N * (N - 1) // 2)
  for i in range(N * (N - 1) // 2):
    for e in g[od[i]]:
      dp[e] = max(dp[e], dp[od[i]] + 1)
  #print(dp)
  print(max(dp))
### BUGGY CODE ###

N = int(input())
A = []
for i in range(N):
  As = list(map(int, input().split()))
  A.append(As)
r = 0
for i in range(N):
  for j in range(i+1, N):
    ok = False
    for k in range(N):
      if A[i][j] > A[i][k]+A[k][j]:
        print(-1)
        exit()
      if A[i][j] == A[i][k]+A[k][j] and k != i and k != j:
        ok = True
    if not(ok):
      r += A[i][j]
print(r)


### FIXED CODE ###

N = int(input())
A = []
for i in range(N):
  As = list(map(int, input().split()))
  A.append(As)
r = 0
for i in range(N):
  for j in range(i+1, N):
    ok = False
    for k in range(N):
      if A[i][j] > A[i][k]+A[k][j]:
        print(-1)
        exit()
      if A[i][j] == A[i][k]+A[k][j] and k != i and k != j:
        ok = True
    if not(ok):
      r += A[i][j]
print(r)
### BUGGY CODE ###

import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]


N, M = map(int, input().split())
a = []
memo = [0]*(N+1)
for _ in range(M):
    a.append(int(input()))

safe = [True]*(N+1)
for i in range(M):
    safe[(a[i])] = False


def func(i):
    global safe
    if memo[i] != 0:
        return memo[i]

    if not(safe[i]):
        return 0
    if i == 0:
        return 1
    if i == 1:
        return 1
    ret = 0
    if i >= 2:
        ret += func(i-1)+func(i-2)
        memo[i] = ret
        return ret


print(func(N) % 1000000007)


### FIXED CODE ###

import math
import string
import collections
from collections import Counter
from collections import deque


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

N, M = map(int, input().split())
a = []
for _ in range(M):
    a.append(int(input()))
# print(a)
dp = [0]*(N+1)
#dp[0] = 1
#dp[1] = 1
# for i in range(2, N):
#    dp[i] = dp[i-1]+dp[i-2]
safe = [True]*(N+1)
for i in range(M):
    safe[(a[i])] = False
#print('safe', safe)
dp[0] = 1
if safe[1]:
    dp[1] = 1
for i in range(2, N+1):
    if safe[i]:
        dp[i] = dp[i-1]+dp[i-2]
    if not(safe[i]):
        dp[i] = 0
#print('dp', dp)
print(dp[N] % 1000000007)
### BUGGY CODE ###

n,m = map(int, input().split())
lr = [list(map(int, input().split())) for _ in range(m)]

nums = list(range(1,n+1))
ans = 0
for i in nums:
  for j in lr:
    if i < j[0] or i > j[1]:
      break
  else:
    ans += 1
print(ans)

### FIXED CODE ###

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

a = [0]*m
b = [0]*m
for i in range(m):
  l,r = map(int, input().split())
  a[i] = l
  b[i] = r

x = min(b)
y = max(a)
if x >= y:
  print(x-y+1)
else:
  print(0)
### BUGGY CODE ###

def t(n, k, q, a):
    p = [-q + k] * n
    for i in range(n):
        p[i] += a.count(i + 1)
    return ["Yes" if i > 0 else "No" for i in p]


if __name__ == "__main__":
    n, k, q = map(int, input().split())
    a = [int(input()) for i in range(q)]
    r = t(n, k, q, a)
    for i in r:
        print(i)


### FIXED CODE ###

def t(n, k, q, a):
    p = [-q + k] * n
    for i in range(q):
        p[a[i-1]-1] += 1
    return ["Yes" if i > 0 else "No" for i in p]
   

if __name__ == "__main__":
    n, k, q = map(int, input().split())
    a = [int(input()) for i in range(q)]
    r = t(n, k, q, a)
    for i in r:
        print(i)
### BUGGY CODE ###

import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
#logging.disable(logging.CRITICAL)


def main():
    N, K = map(int, input().split())
    A_i = list(map(int, input().split()))
    B_i = []
    cycle_list = []
    
    cycle = 0
    diff = 0
    counter = 0
    machi = 1
    while True:
        if machi in B_i:
            diff = B_i.index(machi)
            cycle = counter - diff
            cycle_list = B_i[diff:]
            break
        else:
            counter += 1
            machi = A_i[machi - 1]

    mod_K = (K - diff) % cycle

    print(cycle_list[mod_K])

if __name__ == "__main__":
    main()


### FIXED CODE ###

import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
#logging.disable(logging.CRITICAL)


def main():
    N, K = map(int, input().split())
    A_i = list(map(int, input().split()))
    B_i = [0 for i in range(N)]
    cycle_list = []
    diff_list = []
    cycle = 0
    diff = 0
    counter = 0
    machi = 1

    while counter < N:
        if B_i[machi - 1] == 1:
            diff = cycle_list.index(machi)
            cycle = counter - diff
            diff_list = cycle_list[:diff]
            cycle_list = cycle_list[diff:]
            break
        else:
            counter += 1
            B_i[machi - 1] = 1
            cycle_list.append(machi)
            machi = A_i[machi - 1]

    if K < diff:
        print(diff_list[K])
    else:
        mod_K = (K - diff) % cycle
        print(cycle_list[mod_K])

if __name__ == "__main__":
    main()
### BUGGY CODE ###

import collections

H,W=map(int,input().split())
S=[input() for i in range(H)]
cl=set()
for sy,sx in [[h,w] for h in range(H) for w in range(W)]:
    if S[sy][sx]!="#":
        for gy,gx in [[h,w] for h in range(H) for w in range(W)]:
            if S[gy][gx]!="#":
                stack=collections.deque([[sy,sx,0]])
                itta=set([sy*100+sx])
                #print(stack)
                while stack:
                    y,x,m=stack.popleft()
                    if y==gy and x==gx:
                        cl.add(m)
                        break
                    lst=[]

                    if y>0:lst.append([-1,0])
                    if y<H-1:lst.append([1,0])
                    if x>0:lst.append([0,-1])
                    if x<W-1:lst.append([0,1])

                    for a,b in lst:
                        Y=y+a
                        X=x+b
                        #print(Y,X)
                        if S[Y][X]=="." and not Y*100+X in itta:
                            stack.append([Y,X,m+1])
print(max(cl))


### FIXED CODE ###

import collections

H,W=map(int,input().split())
S=[input() for i in range(H)]
cl=set()
for sy,sx in [[h,w] for h in range(H) for w in range(W)]:
    if S[sy][sx]!="#":
        stack=collections.deque([[sy,sx,0]])
        itta=set([sy*100+sx])
        #print(stack)
        while stack:
            y,x,m=stack.popleft()
            cl.add(m)
            lst=[]

            if y>0:lst.append([-1,0])
            if y<H-1:lst.append([1,0])
            if x>0:lst.append([0,-1])
            if x<W-1:lst.append([0,1])

            for a,b in lst:
                Y=y+a
                X=x+b
                #print(Y,X)
                if S[Y][X]=="." and not Y*100+X in itta:
                    stack.append([Y,X,m+1])
                    itta.add(Y*100+X)
print(max(cl))
### BUGGY CODE ###

N, M = (int(i) for i in input().split()) 
PY = [[int(i) for i in input().split()] for i in range(M)] 
d = {}

for p, y in PY:
  if p not in d:
    d[p] = [y]
  else:
    d[p] = (d[p] + [y])

for x in d:
  d[x].sort()

for p, y in PY:
  print('{}{}'.format(str(p).zfill(6), str(d[p].index(y) + 1).zfill(6)))

### FIXED CODE ###

import bisect
N, M = (int(i) for i in input().split()) 
PY = [[int(i) for i in input().split()] for i in range(M)] 
D = [[] for _ in range(N)]

for i, (p, y) in enumerate(PY):
  D[p-1].append((y, i))

ans = [None] * M
output = [[] for _ in range(M)]
for i, d in enumerate(D):
  d.sort()
  for k, (y, j) in enumerate(d):
    ans[j] = (i, k)

for i, k in ans:
  print('{}{}'.format(str(i+1).zfill(6), str(k+1).zfill(6)))
### BUGGY CODE ###

delta = ((1, 0), (0, 1), (-1, 0), (0, -1))
def ds(here, lb, ub, field, count):
	result = 11
	if count == 11:
		return count
	for dx, dy in delta:
		next = (here[0]+dx,here[1]+dy)
		if ( not (lb[0] <= next[0] <= ub[0] and lb[1] <= next[1] <= ub[1]) or
		   field[next[1]][next[0]] == 1) :
		    continue
		tmp = slide(next, (dx,dy), lb, ub, field, count + 1) 
		if tmp < result:
			result = tmp
	return result

def slide(here, di, lb, ub, field, count):
	while lb[0] <= here[0] <= ub[0] and lb[1] <= here[1] <= ub[1]:
		if here == goal:
			result = count
			break
		if field[here[1]][here[0]] == 1:
			field[here[1]][here[0]] = 0
			result = ds((here[0]-di[0],here[1]-di[1]), lb, ub, field, count)
			field[here[1]][here[0]] = 1
			break
		here = (here[0]+di[0],here[1]+di[1])
	else:
		result = 11
	return result
while 1:
	w, h = map(int,raw_input().split(" "))
	if w == h == 0: break
	board = [[0 for _ in range(w)] for _ in range(h)]
	for j in range(h):
		inp = map(int,raw_input().split(" "))
		for i in range(w):
			tmp = inp[i]
			if tmp == 0: continue
			if tmp == 1: board[j][i] = 1
			elif tmp == 2: start = (i,j)
			else : goal = (i,j)
	count = ds(start, (0,0), (w-1,h-1), board, 0) 
	print count if count < 11 else -1

### FIXED CODE ###

delta = ((1, 0), (0, 1), (-1, 0), (0, -1))
def ds(here, field, count, lb, ub, min_count):
	if count == min_count:
		return min_count
	ans = min_count
	for dx, dy in delta:
		nx, ny = (here[0]+dx,here[1]+dy)
		neighbor = (nx, ny)
		while lb[0] <= nx <= ub[0] and lb[1] <= ny <= ub[1]:
			if field[ny][nx] == 1:
				if (nx, ny) != neighbor:
					field[ny][nx] = 0
					ans = ds((nx-dx,ny-dy),field, count+1, lb, ub, ans)
		    		field[ny][nx] = 1
				break
			if field[ny][nx] == 3:
				if count + 1 < ans:
					ans = count + 1
				break
			nx += dx
			ny += dy
	return ans
while 1:
	w, h = map(int,raw_input().split(" "))
	if w == h == 0: break
	board = [ map(int,raw_input().split(" ")) for _ in range(h)]
	for j in range(h):
		for i in range(w):
			if board[j][i] == 2:
				start = (i,j)
	result = ds(start, board, 0, (0,0), (w-1,h-1), 11)
	print result if result < 11 else -1
### BUGGY CODE ###

N,M = list(map(int,input().split()))
a = []
for _ in range(M):
    a.append(int(input()))
dp = [0] * (N + 1)
dp[0] = 1
if 1 in a:
    dp[1] = 0
else:
    dp[1] = 1
for i in range(2,N + 1):
    if i in a:
        dp[i] = 0
    else:
        dp[i] = dp[i-1] + dp[i-2]
        dp[i] %= 1000000007
print(dp[N])

### FIXED CODE ###

def main():
    import sys
    input = sys.stdin.readline
    N,M = list(map(int,input().split()))
    a = []
    A = [0] * (1 + 10 ** 5)
    for _ in range(M):
        A[int(input())] = 1
    dp = [0] * (N + 1)
    dp[0] = 1
    if A[1]:
        dp[1] = 0
    else:
        dp[1] = 1
    for i in range(2,N + 1):
        if A[i]:
            dp[i] = 0
        else:
            dp[i] = dp[i-1] + dp[i-2]
            dp[i] %= 1000000007
    print(dp[N])
if __name__ == '__main__':
    main()
### BUGGY CODE ###

s = input()
k = int(input())
arr =[]
for i in range(len(s)):
    for j in range(i,len(s)):
        if s[i:j+1] != '' and s[i:j+1] not in arr:
            arr.append(s[i:j+1])
def print_arr(arr):
    for i in range(len(arr)):
        print(arr[i],sep=" ",end="/")
    print()
   
arr = sorted(arr)
print(arr[k-1])

### FIXED CODE ###

s = input()
k = int(input())
arr =[]
for i in range(len(s)):
    for j in range(i,i+5):
        if s[i:j+1] != '' and s[i:j+1] not in arr:
            arr.append(s[i:j+1])
arr = sorted(arr)
def print_arr(arr):
    for i in range(len(arr)):
        print(arr[i],sep="",end="/")
    print()   
print(arr[k-1])