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

import heapq

def mk_idx(y,x):
    return y*32+x

H,W=map(int, input().split())
DINF = 100000
d = [ DINF for _ in range( mk_idx(22,22) ) ]
S = []
S.append('#' * (W+2))
for i in range(H):
    S.append('#'+ input() + '#')
S.append('#' * (W+2))
dmax = 0
G = [ [] for _ in range( mk_idx(22,22) ) ]
for y in range(1,H+1):
    for x in range(1,W+1):
        if (S[y][x] == '.'):
            idx = mk_idx(y,x)
            if (S[y-1][x] == '.'):  G[ mk_idx(y,x) ].append( mk_idx(y-1,x) )
            if (S[y][x-1] == '.'):  G[ mk_idx(y,x) ].append( mk_idx(y,x-1) )
            if (S[y+1][x] == '.'):  G[ mk_idx(y,x) ].append( mk_idx(y+1,x) )
            if (S[y][x+1] == '.'):  G[ mk_idx(y,x) ].append( mk_idx(y,x+1) )

for y in range(1,H+1):
    for x in range(1,W+1):
        if S[y][x] == '.':
            q = []
            heapq.heappush(q, [0, mk_idx(y,x)])
            while len(q) != 0:
                v = heapq.heappop(q)
                n = v[0]
                idx = v[1]
                d[ idx ] = n;
                for nv in G[ idx ]:
                    if d[ nv ] <= n+1 :
                        continue
                    heapq.heappush(q, [n+1, nv ] )
            for iy in range(1,H+1):
                for ix in range(1,W+1):
                    idx = mk_idx(iy,ix)
                    if d[idx] != DINF:
                        dmax = max(dmax, d[idx])
                    d[idx] = DINF
print(dmax)





### FIXED CODE ###

from collections import deque

def mk_idx(y,x):
    return y*22+x

H,W=map(int, input().split())
DINF = 100000
S = []
S.append('#' * (W+2))
for i in range(H):
    S.append('#'+ input() + '#')
S.append('#' * (W+2))
dmax = 0
G = [ [] for _ in range( mk_idx(22,22) ) ]
for y in range(1,H+1):
    for x in range(1,W+1):
        if (S[y][x] == '.'):
            if (S[y-1][x] == '.'):  G[ mk_idx(y,x) ].append( mk_idx(y-1,x) )
            if (S[y][x-1] == '.'):  G[ mk_idx(y,x) ].append( mk_idx(y,x-1) )
            if (S[y+1][x] == '.'):  G[ mk_idx(y,x) ].append( mk_idx(y+1,x) )
            if (S[y][x+1] == '.'):  G[ mk_idx(y,x) ].append( mk_idx(y,x+1) )

for y in range(1,H+1):
    for x in range(1,W+1):
        if S[y][x] == '.':
            d = [ DINF for _ in range( mk_idx(22,22) ) ]
            d[ mk_idx(y,x) ] = 0
            q = deque( [mk_idx(y,x)] )
            while len(q) != 0:
                v = q.popleft()
                n = d[v];
                dmax = max(dmax, n)
                for nv in G[v]:
                    if d[ nv ] <= n+1 :
                        continue
                    d[ nv ] = n+1
                    q.append(nv)
print(dmax)
### BUGGY CODE ###

import operator
from functools import reduce
import sys
input = sys.stdin.readline

count = int(input())
list = list(map(int, input().split()))
sum = reduce(operator.mul, list, 1)

if sum > 1000000000000000000:
    sum = -1

print(sum)

### FIXED CODE ###

from functools import reduce
from operator import mul
import sys
input = sys.stdin.readline

count = int(input())
list = list(map(int, input().split()))
sum = list[0]
if 0 in list:
    print(0)
    exit()
else:
    for i in range(count - 1):
        sum = sum * list[i + 1]
        if sum > 1000000000000000000:
            print(-1)
            exit()


    print(sum)
### BUGGY CODE ###

import heapq
def main():
    H, W = map(int, input().split())
    A = []
    for _ in range(H):
        A.append(input())
    cur = []
    visited = set()
    for i in range(H):
        for j in range(W):
            if A[i][j] == "#":
                heapq.heappush(cur, [0, i, j])
                visited.add((i, j))
    mv = [[1, 0], [-1, 0], [0, 1], [0, -1]]
    max_c = float('-inf')
    while cur:
        c, i, j= heapq.heappop(cur)
        max_c = max(max_c, c)
        for di, dj in mv:
            i1, j1 = i+di, j+dj
            if (i1, j1) not in visited and 0 <= i1 < H and 0 <= j1 < W:
                visited.add((i1, j1))
                heapq.heappush(cur, [c+1, i1, j1])
    return max_c

if __name__ == '__main__':
    print(main())

### FIXED CODE ###

import collections
def main():
    H, W = map(int, input().split())
    A = []
    for _ in range(H):
        A.append(input())
    cur = []
    visited = collections.defaultdict(dict)
    for i in range(H):
        for j in range(W):
            if A[i][j] == "#":
                cur.append([i, j])
                visited[i][j] = 1
            else:
                visited[i][j] = 0
    mv = [[1, 0], [-1, 0], [0, 1], [0, -1]]
    count = 0
    while cur:
        temp = []
        for i, j in cur:
            for di, dj in mv:
                i1, j1 = i+di, j+dj
                if 0 <= i1 < H and 0 <= j1 < W and not visited[i1][j1]:
                    visited[i1][j1] = True
                    temp.append([i1, j1])
        if len(temp) > 0:
            count += 1
        cur = temp
    return count

if __name__ == '__main__':
    print(main())
### BUGGY CODE ###

N=int(input())
A = [list(map(int, input().split())) for i in range(N)]
result=0
flag=True
isbreak=False
for m in range(N-1):
    for n in range(m+1,N):
        list_t=list(range(N))
        list_t.remove(m)
        list_t.remove(n)
        for t in list_t:
            if A[m][n]>A[m][t]+A[t][n]:
                result=-1                
                isbreak=True
                break
            elif A[m][n]==A[m][t]+A[t][n] and result!=-1:
                flag=False
                break
        if flag and result!=-1:
            result+=A[m][n]
        else:
            flag=True
        if isbreak:
            break
    if isbreak:
        break
print(result)

### FIXED CODE ###

N=int(input())
A = [list(map(int, input().split())) for i in range(N)]
result=0
flag=True
isbreak=False
for m in range(N-1):
    for n in range(m+1,N):
        list_t=list(range(N))
        list_t.remove(m)
        list_t.remove(n)
        for t in list_t:
            if A[m][n]>A[m][t]+A[t][n]:
                result=-1                
                isbreak=True
                break
            elif A[m][n]==A[m][t]+A[t][n] and result!=-1:
                flag=False
                break
        if flag and result!=-1:
            result+=A[m][n]
        else:
            flag=True
        if isbreak:
            break
    if isbreak:
        break
print(result)
### BUGGY CODE ###

from heapq import heapify, heappop, heappush
from math import ceil

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

b = []
for v in a:
    b.append([-v, -v, 1])

heapify(b)
for _ in range(k):
    x, y, z = heappop(b)
    heappush(b, [y/(z+1), y, z+1])

res = heappop(b)
print(ceil(-res[0]))

### FIXED CODE ###

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

hi = 10 ** 9
lo = 0
while hi - lo > 1:
    mid = (hi + lo) // 2

    cnt = 0
    for v in a:
        cnt += (v + mid - 1) // mid - 1

    if cnt <= k:
        hi = mid
    else:
        lo = mid

print(hi)
### BUGGY CODE ###

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

import sys
args = sys.argv

debug_flg = False
def debug(val1,val2="",val3="",val4=""):
    global debug_flg
    if debug_flg:
        print(val1,val2,val3,val4,sep=" , ")

if len(args) != 2:
    n= int(input())
    s= input()
else:
    debug_flg = True
    if args[1] == "2":
        n=39
        s="RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB"
    elif args[1] == "3":
        n=1
        s="R"
    else:
        n=4
        s="RRGB"

snum = []
for i in range(1,n+1):
    if s[i-1] == "R":
        snum.append(0)
    elif s[i-1] == "G":
        snum.append(1)
    elif s[i-1] == "B":
        snum.append(2)

ret =0
for i in range(1,n-1):
    for j in range(i,n):
        if snum[i-1] == snum[j-1]:
            continue
        for k in range(j,n+1):
            if j-i == k-j:
                continue
            if snum[i-1] == snum[k-1]:
                continue
            if snum[j-1] == snum[k-1]:
                continue
            ret += 1

print(ret)

### FIXED CODE ###

def main():
    n= int(input())
    s= input()

    r = s.count("R")
    g = s.count("G")
    b = s.count("B")

    ans = r * g * b
    snum = tuple(s[:])
    for i in range(1,n-1):
        for j in range(i,n):
            k = j * 2 - i
            if k > n:
                break

            if snum[i-1] != snum[j-1] and snum[i-1] != snum[k-1] and snum[j-1] != snum[k-1]:
                ans -= 1

    print(ans)


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

import math

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

if K >= sum(A):
    print(0)
    exit()

A.sort(reverse=True)
F.sort()

def is_ok(mid):
    cnt = 0
    for i in range(N):
        if A[i] * F[i] <= mid:
            continue
        else:
            cnt += math.ceil((A[i] * F[i] - mid) / F[i]) # A[i]が1減少するごとにF[i]減るのでF[i]で割る  
    
    return cnt <= K

# okは全員がX以下になる最小値に着地するので、A*F<=10**12 なので＋１して最大のケースにも対応する
ok = 10**12 + 1
# 0ではないことが上で保証されてるので、条件を満たさない最大値の0にしておく
ng = 0
while ok - ng > 1:
    
    mid = (ok + ng) // 2
    #print(ok,ng,mid)
    if is_ok(mid):
        ok = mid
    else:
        ng = mid

#print(ok,ng,mid)
print(ok)

### FIXED CODE ###

import math

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

if K >= sum(A):
    print(0)
    exit()

A.sort(reverse=True)
F.sort()

def is_ok(mid):
    cnt = 0
    for i in range(N):
        if A[i] * F[i] <= mid:
            continue
        else:
            cnt += math.ceil((A[i] * F[i] - mid) / F[i]) # A[i]が1減少するごとにF[i]減るのでF[i]で割る  
    
    return cnt <= K

# okは全員がX以下になる最小値に着地するので、A*F<=10**12 なので＋１して最大のケースにも対応する
ok = 10**12 + 1
# 0ではないことが上で保証されてるので、条件を満たさない最大値の0にしておく
ng = 0
while ok - ng > 1:
    
    mid = (ok + ng) // 2
    #print(ok,ng,mid)
    if is_ok(mid):
        ok = mid
    else:
        ng = mid

#print(ok,ng,mid)
print(ok)
### BUGGY CODE ###

from bisect import bisect_left
n = int(input())
a_list = []
for i in range(n):
    a = int(input())
    index = bisect_left(a_list, a)
    if index == 0:
        a_list = [a] + a_list
    else:
        a_list[index - 1] = a
print(len(a_list))

### FIXED CODE ###

from bisect import bisect_right
n = int(input())
a_list = []
for i in range(n):
    a = int(input())
    a_list.append(a)
a_list.reverse()
l_list = [a_list[0]]
for i in range(1, n):
    a = a_list[i]
    if l_list[-1] <= a:
        l_list.append(a)
    else:
        index = bisect_right(l_list, a)
        l_list[index] = a
print(len(l_list))
### BUGGY CODE ###

from collections import defaultdict
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
n = int(input())
A = []
M = [[-1 for _ in range(n)] for _ in range(n)]
cnt = 0
for i in range(n):
    for j in range(i+1,n):
        M[i][j] = cnt
        M[j][i] = cnt
        cnt += 1
ans = 0
nodes = []
adjacent_list = [[] for i in range(n*(n-1)//2)]
for i in range(n):
    tmp = list(map(int, input().split()))
    pre = tmp[0] - 1
    for j in tmp[1:]:
        adjacent_list[M[i][pre]].append(M[i][j-1])
        pre = j - 1
#まず、閉路検
seen = defaultdict(lambda: False)
visited = defaultdict(lambda: False)
def check(node):
    if visited[node]:
        return
    seen[node] = True
    for i in adjacent_list[node]:
        if seen[i] and (not visited[i]):
            print(-1)
            exit()
        check(i)
    visited[node] = True
def dfs_path(node):
    if not adjacent_list[node]:
        return 1
    if finish[node]:
        return finish[node]
    tmp = 0
    for i in adjacent_list[node]:
        tmp = max(tmp, dfs_path(i) + 1)
    finish[node] = tmp
    return finish[node]
finished = set()
finish = [0 for i in range(n*(n-1)//2)]
for i in range(n*(n-1)//2):
    check(i)
    dfs_path(i)
print(max(max(finish), 1))

### FIXED CODE ###

from collections import defaultdict
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
n = int(input())
A = []
M = [[-1 for _ in range(n)] for _ in range(n)]
cnt = 0
for i in range(n):
    for j in range(i+1,n):
        M[i][j] = cnt
        M[j][i] = cnt
        cnt += 1
ans = 0
nodes = []
adjacent_list = [[] for i in range(n*(n-1)//2)]
for i in range(n):
    tmp = list(map(int, input().split()))
    pre = tmp[0] - 1
    for j in tmp[1:]:
        adjacent_list[M[i][pre]].append(M[i][j-1])
        pre = j - 1
#まず、閉路検
seen = defaultdict(lambda: False)
visited = defaultdict(lambda: False)
def check(node):
    if visited[node]:
        return
    seen[node] = True
    for i in adjacent_list[node]:
        if seen[i] and (not visited[i]):
            print(-1)
            exit()
        check(i)
    visited[node] = True
def dfs_path(node):
    if not adjacent_list[node]:
        return 1
    if finish[node]:
        return finish[node]
    tmp = 0
    for i in adjacent_list[node]:
        tmp = max(tmp, dfs_path(i) + 1)
    finish[node] = tmp
    return finish[node]
finished = set()
finish = [0 for i in range(n*(n-1)//2)]
for i in range(n*(n-1)//2):
    check(i)
    dfs_path(i)
print(max(max(finish), 1))
### BUGGY CODE ###

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

def solve(i,m):
    a = 0
    if a ==m:
        return True
    if i >= len(A):
        return False
    
    res = solve(i+1,m) or solve(i+1,m-A[i])
    return res 

for k in M:
    print("yes" if solve(0,k) else "no")
        

### FIXED CODE ###

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

def makeSum(A,i,T):
    if i == len(A):
        T[sum(A)] = 0
    else:
        makeSum(A,i+1,T)
        ret = A[i]
        A[i] = 0
        makeSum(A,i+1,T)
        A[i] = ret

T = {}
makeSum(A,0,T)
for m in M:
    if m in T:
        print("yes")
    else:
        print("no")
### BUGGY CODE ###

n, m = map(int, input().split())
a = list(map(int, input().split()))
bc = [[int(i) for i in input().split()] for i in range(m)]

for i in range(m):
        a.sort()
        bc_temp = bc[i]
        for j in range(bc_temp[0]):
                if a[j] < bc_temp[1]:
                        a[j] = bc_temp[1]
                elif a[j] > bc_temp[1]:
                        break

print(sum(a)) 

### FIXED CODE ###

n, m = map(int, input().split())
a = list(map(int, input().split()))
bc = [[int(i) for i in input().split()] for i in range(m)]

bc.sort(key = lambda x:x[1], reverse = True)

a.sort()

a_count = 0
for b, c in bc:
        if c > a[a_count]:
                for i in range(b):
                        if c > a[a_count]:
                                a[a_count] = c
                                a_count += 1    
                        else:
                                break
                        if a_count == n:
                                        break

        else:
                break
        if a_count == n:
                break        

print(sum(a))
### BUGGY CODE ###

from sys import stdin

def main():
    n = int(stdin.readline().rstrip())
    xs = [int(stdin.readline().rstrip()) for _ in range(n)]

    for i in range(n):
        ys = xs[:]
        ys.pop(i)
        print(max(ys))

if __name__ == '__main__':
    main()


### FIXED CODE ###

from sys import stdin

def main():
    n = int(stdin.readline().rstrip())
    xs = [int(stdin.readline().rstrip()) for _ in range(n)]

    max_1, max_2 = sorted(xs)[-1], sorted(xs)[-2]

    for i in range(n):
        if xs[i] == max_1:
            print(max_2)
        else:
            print(max_1)
            
if __name__ == '__main__':
    main()
### BUGGY CODE ###

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

status = [10000]*H*W
targets = []
for i in range(H):
    s = input()
    for j, s_j in enumerate(s):
        if s_j == "#":
            targets.append((i, j))
            status[i*W+j] = 0

while True:
    try:
        i, j = targets.pop()
    except IndexError:
        break
    
    d = status[i*W+j] + 1
    
    if j != 0 and status[i*W+j-1] > d:
        status[i*W+j-1] = min(status[i*W+j-1], d) # left
        targets.append((i, j-1))

    if j != W-1 and status[i*W+j+1] > d:
        status[i*W+j+1] = min(status[i*W+j+1], d) # right
        targets.append((i, j+1))

    if i != 0 and status[(i-1)*W+j] > d:
        status[(i-1)*W+j] = min(status[(i-1)*W+j], d) # up
        targets.append((i-1, j))

    if i != H-1 and status[(i+1)*W+j] > d:
        status[(i+1)*W+j] = min(status[(i+1)*W+j], d) # down
        targets.append((i+1, j))


print(max(status))


### FIXED CODE ###

import numpy as np

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

status = np.full((H, W), H*W, dtype=int)
for i in range(H):
    s = input()
    for j in range(W):
        if s[j] == "#":
            status[i,j] = 0

for h in range(1, H):
    status[h, :] = np.minimum(status[h, :], status[h-1, :] + 1)
for h in range(0, H-1)[::-1]:
    status[h, :] = np.minimum(status[h, :], status[h+1, :] + 1)
for w in range(1, W):
    status[:, w] = np.minimum(status[:, w], status[:, w-1] + 1)
for w in range(0, W-1)[::-1]:
    status[:, w] = np.minimum(status[:, w], status[:, w+1] + 1)

print(np.max(status))
### BUGGY CODE ###

n = int(input())

import sys
a = []
for line in sys.stdin:
    a.append(int(line.rstrip("\n")))

check = []    
for i in set(a):
    if a.count(i) %2 == 1 :
         check.append(i)

print(len(check))

### FIXED CODE ###

n = int(input())

answer = {}
for i in range(n):
  ai = int(input())
  if answer.get(ai):
    answer.pop(ai)
  else:
    answer[ai] = 1
    
print(len(answer))
### BUGGY CODE ###

#2つの長さNの非負整数列a1,,,aNが与えられます。１<=i,j<=Nとなるように整数i,jを選ぶ方法はN~2通りありますが、
#このN~2通りのi,jそれぞれについて、ai+biを計算し、紙に書きだします。
#つまり紙にN~2個の整数を書きます。この整数のxorを計算してください。
#
import bisect

N = int(input())

a = [0]*N
b = [0]*N
ax = [0]*N
bx = [0]*N
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = [0]*30
n = int(0)

for K in range(30):
    for i in range(N):
        ax[i] = a[i]%(2**(K+1))
        bx[i] = b[i]%(2**(K+1))
    bx.sort()
    num = int(0)
    for i in range(N):
        loc1 = 2**K-ax[i]
        loc3 = 2*2**K-ax[i]
        loc2 = 3*2**K-ax[i]
        num += N - bisect.bisect_left(bx, loc1)
        num += N - bisect.bisect_left(bx, loc2)
        num -= N - bisect.bisect_left(bx, loc3)
    if num%2==1:
        ans[K]=1
#    print(bisect.bisect_left(bx, loc2))

#print(ans)

for i in range(30):
    n += (2**i)*ans[i]

print(n)

### FIXED CODE ###

def examD():
    N = I()
    a = LI();  b = LI()
    cura = [0]*N; curb=[0]*N
    ans = 0
    for i in range(28,-1,-1):
        T = (2 ** i)
        for j in range(N):
            cura[j] = a[j]%(2**(i+1))
            curb[j] = b[j]%(2**(i+1))
        curb.sort()
        cura.sort(reverse=1)
        f, l1, r1, l2 = 0, 0, 0, 0
        for x in cura:
            while l1 < N and x + curb[l1] < T:
                l1 += 1
            while r1 < N and x + curb[r1] < 2 * T:
                r1 += 1
            while l2 < N and x + curb[l2] < 3 * T:
                l2 += 1
            f += N - l2 + r1 - l1
        ans += T * (f & 1)
    print(ans)

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examD()
### BUGGY CODE ###

N = int(input())
L = list(map(int, input().split()))
ans = 0
for i in range(N):
  for j in range(i + 1, N):
    for k in range(j + 1, N):
      #print(str(i) + str(j) + str(k))
      if L[i] < L[j] + L[k] and abs(L[j] - L[k]) < L[i]:
        ans += 1
print(ans)

### FIXED CODE ###

import bisect
N = int(input())
#ソートしておく
L = sorted(list(map(int, input().split())))
ans = 0

#短い2辺を総当たりで選択
for i in range(N - 2):
  for j in range(i + 1, N - 1):
    #小さい順に並べた時の成立条件
    # l1 + l2 > l3
    l12 = L[i] + L[j]
    #l2の隣から　l12以下のところまで全部が対象、成立しない場合
    #ans += max(bisect.bisect_left(L, l12) - j - 1, 0)
    ans += bisect.bisect_left(L, l12) - j - 1
print(ans)
### BUGGY CODE ###

s = input()
K = int(input())
SK2 = list(s)
for i in range(2, len(s)+1):
  for j in range(len(s)-(i-1)):
    SK2.append(s[j:j+i])
SK3 = list(set(SK2))
SK3.sort()
print(SK3[K-1])

### FIXED CODE ###

s = input()
K = int(input())

S = [ss for ss in s]
S_set = list(set(S))
S_set.sort()

substring = []
for c in S_set:
  idx_c = [i for i, x in enumerate(s) if x == c]
  substring_c = []
  for x in idx_c:
    for dx in range(1, min(5, len(s)-x)+1):
      substring_c.append(s[x:x+dx])
  substring_c = list(set(substring_c))
  substring += substring_c
  if len(substring) >= 5:
    break

substring.sort()
print(substring[K-1])
### BUGGY CODE ###

from collections import deque
N=int(input())
A=tuple(map(str,input().split()))
B=deque()
for i in range(N):
  B.append(A[i])
  B.reverse()
ans=' '.join(list(B))
print(ans)

### FIXED CODE ###

n = int(input())
A = list(map(int,input().split()))
answer = A[1::2][::-1]+A[::2]
if n%2==1:
    answer=answer[::-1]
print(*answer)
### BUGGY CODE ###

N,Q = input().split(" ")
sentence = input()

for i in range(int(Q)):
	count = 0
	l,r = map(int, input().split(" "))
	for j in range(r-l):
		if sentence[l-1+j:l+j+1] == "AC":
			count += 1
	print(count)

### FIXED CODE ###

N,Q = map(int, input().split(" "))
sentence = input()

"""
###文章そのままの実装ー＞N,Q によりオーダーが大きくなりすぎる
for i in range(int(Q)):
	count = 0
	l,r = map(int, input().split(" "))
	for j in range(r-l):
		if sentence[l-1+j:l+j+1] == "AC":
			count += 1
	print(count)

"""

###累積和を用いて高速に計算
#予め累積和を計算　クエリで高速回答
#ACACTGC
#0112222
AC_list = [0]*(N)
count = 0
for i in range(N-1):
	if sentence[i : i+2] == "AC":
		count += 1
	AC_list[i+1] = count

for i in range(Q):
	l,r = map(int, input().split())
	print(AC_list[r-1]-AC_list[l-1])
### BUGGY CODE ###

n = input()
array = []
for i in range(n):
	inst = raw_input().split()
	if inst[0] == 'insert':
		array.append(int(inst[1]))
	if inst[0] == "delete":
		if int(inst[1]) in array:
			x = array[::-1].index(int(inst[1]))
			if x != -1 and int(inst[1]):
				del array[-x-1]
	if inst[0] == "deleteFirst":
		array.pop()
	if inst[0] == "deleteLast":
		array.pop(0)
print " ".join(map(str,array[::-1]))

### FIXED CODE ###

n = input()
array = []
base = 0
for i in xrange(n):
    inst = raw_input().split()
    if inst[0][0] == 'i':
        array.append(int(inst[1]))
    elif inst[0] == "delete":
        if int(inst[1]) in array:
            x = array[::-1].index(int(inst[1]))
            if x != -1 and int(inst[1]):
                del array[-x-1]
    elif inst[0][6] == 'F':
        array.pop()
    else:
        base += 1
print (" ".join(map(str,array[base:][::-1])))
### BUGGY CODE ###

# import bisect
# # import heapq
# # from copy import deepcopy
# # from collections import deque
# # from collections import Counter
# # from itertools import accumulate
# # from itertools import permutations
# import numpy as np
# # import math
# a,b,c = map(int, input().split())
n = int(input())
# p = list(map(int, input().split()))
lis = []

def dfs(s, var):
    if len(s) == n and s not in lis:
        lis.append(s)
    else:
        for i in range(var):
            dfs(s+chr(ord('a')+i), var)

        dfs(s+chr(ord('a')+var), var+1)


dfs('a', 1)
lis.sort()
for i in range(len(lis)):
    print(lis[i])

### FIXED CODE ###

# import bisect
# # import heapq
# # from copy import deepcopy
# # from collections import deque
# # from collections import Counter
# # from itertools import accumulate
# # from itertools import permutations
# import numpy as np
# # import math
# a,b,c = map(int, input().split())
n = int(input())
# p = list(map(int, input().split()))


def dfs(s, var):
    if len(s) == n:
        print(s)
    else:
        for i in range(var):
            dfs(s+chr(ord('a')+i), var)

        dfs(s+chr(ord('a')+var), var+1)

dfs('a',1)