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

n = int(input())
A = list(map(int, input().split()))
i = 1
count = 0

while A:
  a = A.pop(0)
  if i != a:
    count += 1
  else:
    i += 1
    
print(-1 if count == n else count)

### FIXED CODE ###

from collections import deque

n = int(input())
A = deque(map(int, input().split()))
i = 1
count = 0

while A:
  a = A.popleft()
  if i != a:
    count += 1
  else:
    i += 1
    
print(-1 if count == n else count)
### BUGGY CODE ###

from bisect import bisect_right
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    b = [int(i) for i in input().split()]
    c = [int(i) for i in input().split()]
    a.sort()
    b.sort()
    c.sort()

    cnt = 0
    for i in range(n):
        v = a[i]  
        idx_b = bisect_right(b, v) 
        for j in range(idx_b, n):
            u = b[j]
            idx_c = bisect_right(c, u)
            cnt += n-idx_c     
    print(cnt)
main()

### FIXED CODE ###

from bisect import bisect_left, bisect_right
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    b = [int(i) for i in input().split()]
    c = [int(i) for i in input().split()]
    a.sort()
    b.sort()
    c.sort()

    cnt = 0
    for i in range(n):
        v = b[i]
        idx_a = bisect_left(a, v) 
        idx_b = bisect_right(c, v)
        cnt += idx_a * (n-idx_b)     
    print(cnt)
main()
### BUGGY CODE ###

def main():
    x = input()
    tmp = x.replace("ST", "")
    while x != tmp:
        x = tmp
        tmp = tmp.replace("ST", "")
    print(len(x))

if __name__ == "__main__":
    main()

### FIXED CODE ###

def main():
    x = input()
    s, t = 0, 0
    for i in x:
        if i == "S":
            s += 1
        else:
            if s:
                s -= 1
            else:
                t += 1
    print(s + t)

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

N = int(input())
A = []
for n in range(N):
    A.append(int(input()))
B = [A[0]]
for n in range(N-1):
    B = B+[max(B[-1], A[n + 1])]
C = [A[-1]]
for n in range(N - 1):
    C = [max(C[0], A[-n - 2])] + C
for n in range(N):
    if n == 0:
        print(C[1])
    elif n == N - 1:
        print(B[N - 2])
    else:
        print(max(B[n-1], C[n+1]))


### FIXED CODE ###

N = int(input())
A = []
for n in range(N):
    A.append(int(input()))
B = [0 for n in range(N)]
B[0] = A[0]
for n in range(N-1):
    B[n+1] = max(B[n], A[n + 1])
C = [0 for n in range(N)]
C[-1] = A[-1]
for n in range(N - 1):
    C[-n-2] = max(C[-n-1], A[-n - 2])
for n in range(N):
    if n == 0:
        print(C[1])
    elif n == N - 1:
        print(B[N - 2])
    else:
        print(max(B[n-1], C[n+1]))
### BUGGY CODE ###

N, M = [int(x) for x in input().split()]
PY_list = []
lst = [[] for _ in range(N)] 
for _ in range(M):
    P, Y = [int(x)-1 for x in input().split()]
    PY_list.append((P, Y))
    lst[P].append(Y)
for i, Ys in enumerate(lst):
    lst[i] = sorted(Ys)
for p, y in PY_list:
    print('{:06}{:06}'.format(p+1, lst[p].index(y)+1))


### FIXED CODE ###

from bisect import bisect_left
N, M = [int(x) for x in input().split()]
PY_list = [[int(x)-1 for x in input().split()] for _ in range(M)]
lst = [[] for _ in range(N)] 
for P, Y in PY_list:
    lst[P].append(Y)
for l in lst:
    l.sort()
for p, y in PY_list:
    print('{:06}{:06}'.format(p+1, bisect_left(lst[p], y)+1))
### BUGGY CODE ###

num, K, *line = map(int, open(0).read().split())
def main():
  dp = [float("inf")]* num
  dp[0] = 0
  for i in range(1, num):
    min_j = max(0, i - K)
    dp[i] = min([dp[j] + abs(line[i] - line[j]) for j in range(min_j , i)])
  #kの範囲: k = 1,2,3...K 無理なときは k = 1,2..i
  print(dp[-1])
main()

### FIXED CODE ###

def ans():
    n, k, *h = map(int, open(0).read().split())
    dp = [float("inf")] * n
    dp[0] = 0
    for i in range(1, n):
        min_j = max(0, i-k)
        dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(min_j , i)])
    print(dp[n-1])
 
ans()
### BUGGY CODE ###

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

expect_value = []

for i in p:
    expect_value.append((1+i)/2)


max_expect_value = 0
for i in range(n - k + 1):
    tmp = 0
    tmp = sum(expect_value[i:i+k])
    max_expect_value = max(tmp, max_expect_value)

print(max_expect_value)


### FIXED CODE ###

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

sum_p =[0]
tmp = 0
for i in p:
    tmp += i
    sum_p.append(tmp)

max_expect = 0
for i in range(k, n+1):
    tmp = sum_p[i] - sum_p[i - k]
    max_expect = max(tmp, max_expect)

ans = (k + max_expect)/2
print(ans)
### BUGGY CODE ###

A,B,C,K = list(map(int, input().split()))
count = 0

if A + B + C == K:
    print(A - C)
else:
    for i in reversed(range(0, K)):
        if A > 0:
            count += 1
            A = A - 1
        elif B > 0:
            B = B - 1
        else: 
            count -= 1

    print(count)

### FIXED CODE ###

A,B,C,K = list(map(int, input().split()))
count = 0

if A + B + C == K:
    print(A - C)

elif A >= K:
    print(K)
elif A+B >= K:
    print(A)
else:
    t = K - A - B

    print(A - t)
### BUGGY CODE ###

n = int(input())
x = int(input(),2)

def popcount(n):
    return bin(n).count("1")

pops = popcount(x)
x_pop_p = x%(pops + 1)
try:
    x_pop_m = x%(pops - 1)
except:
    x_pop_m = 0
#print(x_pop_p)
#print(x_pop_m)
#print()
for i in reversed(range(0,n)):
    bit = x^(1<<i)
    #print(bin(bit))
    #print(bit)
    #print(popcount(bit))
    if bit == 0:
        print(0)
        continue
    if x&(1<<i):
        tmp = (x_pop_m - pow(2,i))%(pops - 1)
    else:
        tmp = (x_pop_p + pow(2,i)) % (pops + 1)
    #print(tmp)
    if tmp == 0:
        print(1)
        continue
    cnt = 2
    tmp_pop = popcount(tmp)
    if tmp_pop == 0:
        print(cnt-1)
        continue
    tmp = tmp % tmp_pop
    while tmp > 0:
        cnt += 1
        tmp_pop = popcount(tmp)
        if tmp_pop == 0:
            print(cnt-1)
            continue
        tmp %= tmp_pop
    print(cnt)
    #print()

### FIXED CODE ###

n = int(input())
s = input()
x = int(s, 2)
pcx = s.count("1")
pc1 = x % (pcx - 1) if pcx > 1 else 0
pc2 = x % (pcx + 1)

def f(j):
    cnt = 0
    while j:
        j %= bin(j).count("1")
        cnt += 1
    return cnt

for i, y in enumerate(s):
    k = n - 1 - i
    if y == "0":
        print(f((pc2 + pow(2, k, pcx + 1)) % (pcx + 1)) + 1)
    elif pcx > 1:
        print(f((pc1 - pow(2, k, pcx - 1)) % (pcx - 1)) + 1)
    else:
        print(0)
### BUGGY CODE ###

n= int(input())
s= input()

snum = tuple(s[:])
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 ###

k,s=map(int,input().split())
ans=0
for x in range(k+1):
    for y in range(k+1):
        for z in range(k+1):
            if x+y+z==s:ans+=1
print(ans)

### FIXED CODE ###

k, s = (int(x) for x in input().split())
 
count = 0
for x in range(k+1):
    for y in range(k+1):
        z = s-x-y
        if 0 <= z <= k:
            count += 1
print(count)
### BUGGY CODE ###

# ソートしている(a < b < c)とした三角形の存在条件
def triangle_check(a, b, c):
    if b - a < c and c < a + b:
        return True
    else:
        return False
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
cnt = 0
for i in range(N - 2):
    for k in range(i + 1, N - 1):
        for l in range(k + 1, N):
            if triangle_check(L[i], L[k], L[l]):
                cnt = l
                break
        for l in range(N-1, k, -1):
            if triangle_check(L[i], L[k], L[l]):
                ans += l - cnt + 1
                cnt = 0
                break
print(ans)

### FIXED CODE ###

import bisect
# ソートしている(a < b < c)として，三角形の存在条件は以下になる
def triangle_check(a, b, c):
    if c < a + b:
        return True
    else:
        return False
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
cnt = 0
for i in range(N - 2):
    for k in range(i + 1, N - 1):
        tmp = bisect.bisect_left(L, L[i] + L[k])
        ans += max(tmp - 1 - k, 0)
print(ans)
### BUGGY CODE ###

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

option = {(0, 0)}


def main():
    global option
    last_list = [0, 0, 0]
    N = int(input())
    for i in range(N):
        this_list = list(map(int, input().split()))
        add_option(this_list[0] - last_list[0], (this_list[1], this_list[2]))
        if (this_list[1], this_list[2]) not in option:
            print('No')
            return
        option = {(this_list[1], this_list[2])}
        last_list = this_list
    print('Yes')


def add_option(step, this_postion):
    global option
    xi, yi = this_postion
    for i in range(step):
        temp_option = set()
        rest = step - i
        for position in option:
            x, y = position
            diff = abs(x - xi) + abs(y - yi)
            if rest % 2 != diff % 2:
                continue
            if diff > rest:
                continue
            if x < 100000:
                temp_option.add((x + 1, y))
            if y < 100000:
                temp_option.add((x, y + 1))
            if x > 0:
                temp_option.add((x - 1, y))
            if y > 0:
                temp_option.add((x, y - 1))
        option = temp_option


main()


### FIXED CODE ###

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

judge = 'Yes'

N = int(input())
for i in range(N):
    t, x, y = map(int, input().split())
    if t < (x + y) or t % 2 != (x + y) % 2:
        judge = 'No'

print(judge)
### BUGGY CODE ###

n = int(input())
ls = list(map(int,input().split()))
ls.sort()
p = 0
for i in range(n):
    for j in range(i):
        if ls[j]*2 <= ls[i]:
            continue
        for k in range(j):
            if ls[i] < ls[k] + ls[j]:
                p += 1
print(p)

### FIXED CODE ###

n = int(input())
ls = list(map(int,input().split()))
ls.sort()
p = 0
def is_ok(arg,l):
    return ls[arg] < l
def meguru_bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        l = ls[i] + ls[j]
        if is_ok(mid,l):
            ok = mid
        else:
            ng = mid
    return ok
for i in range(n-2):
    for j in range(i+1,n-1):
        ng = n
        ok = j
        m = meguru_bisect(ng, ok)
        p += m-j 
print(p)
### BUGGY CODE ###

INF=10**6
f=lambda:map(int,input().split())
h,w=f()
ch,cw=f()
ch-=1
cw-=1
dh,dw=f()
dh-=1
dw-=1
g=[input() for _ in range(h)]
from collections import *
def grid_01_bfs(x,y):
  d=[[INF]*w for _ in range(h)]
  d[x][y]=0
  q=deque([(0,x,y)])
  while q:
    td,tx,ty=q.popleft()
    if d[tx][ty]<td: continue
    for dx,dy in [(1,0),(0,1),(-1,0),(0,-1)]:
      nx,ny=tx+dx,ty+dy
      if 0<=nx<h and 0<=ny<w and g[nx][ny]=='.' and d[nx][ny]>td:
        d[nx][ny]=td
        q.appendleft((d[nx][ny],nx,ny))
    for dx in range(-2,3):
      for dy in range(-2,3):
        nx,ny=tx+dx,ty+dy
        if 0<=nx<h and 0<=ny<w and g[nx][ny]=='.' and d[nx][ny]>td+1:
          d[nx][ny]=td+1
          q.append((d[nx][ny],nx,ny))
  return d
a=grid_01_bfs(ch,cw)[dh][dw]
print([-1,a][a<INF])

### FIXED CODE ###

INF=10**6
f=lambda:map(int,input().split())
h,w=f()
ch,cw=f()
ch-=1
cw-=1
dh,dw=f()
dh-=1
dw-=1
g=[input() for _ in range(h)]
from collections import *
def grid_01_bfs(x,y):
  d=[[INF]*w for _ in range(h)]
  d[x][y]=0
  q=deque([(0,x,y)])
  while q:
    td,tx,ty=q.popleft()
    if d[tx][ty]<td: continue
    for dx,dy in [(1,0),(0,1),(-1,0),(0,-1)]:
      nx,ny=tx+dx,ty+dy
      if 0<=nx<h and 0<=ny<w and g[nx][ny]=='.' and d[nx][ny]>td:
        d[nx][ny]=td
        q.appendleft((d[nx][ny],nx,ny))
    for dx in range(-2,3):
      for dy in range(-2,3):
        nx,ny=tx+dx,ty+dy
        if 0<=nx<h and 0<=ny<w and g[nx][ny]=='.' and d[nx][ny]>td+1:
          d[nx][ny]=td+1
          q.append((d[nx][ny],nx,ny))
  return d
a=grid_01_bfs(ch,cw)[dh][dw]
print([-1,a][a<INF])
### BUGGY CODE ###

S=input()
Q=int(input())
cnt=0
for i in range(Q):
    query_list=input().split()
    if query_list[0] == "1":
        cnt+=1
    else:
        if cnt%2==0:
            if query_list[1] == "1":
                S=query_list[2]+S
            else:
                S+=query_list[2]
        else:
            if query_list[1] == "1":
                S+=query_list[2]
            else:
                S=query_list[2]+S
if cnt%2==0:
    print(S)
else:
    print(S[::-1])

### FIXED CODE ###

from collections import deque
S = deque(input().rstrip())
Q=int(input())
cnt=True
for i in range(Q):
    query_list=input().split()
    if query_list[0] == "1":
        cnt=(cnt==False)
    else:
        if cnt:
            if query_list[1] == "1":
                S.appendleft(query_list[2])
            else:
                S.append(query_list[2])
        else:
            if query_list[1] == "1":
                S.append(query_list[2])
            else:
                S.appendleft(query_list[2])
if cnt:
    print("".join(S))
else:
    print("".join(reversed(S)))
### BUGGY CODE ###

if __name__ == "__main__":
    N = int(input())
    S = input()

    min_val = 0
    if N > 26:
        min_val = 1
    elif N >= (26 ** 2 + 1) * 2:
        min_val = 2

    for i in range(N//2, 0, -1):
        if i == min_val:
            print(i)
            exit()
        if N-i*2 == 0:
            tmp = S[i:]
            if tmp.find(S[:i]) != -1:
                print(i)
                exit()
        else:
            for index in range(N-i*2):
                # 仮の文字列の生成
                tmp = S[index+i:]
                if tmp.find(S[index:index+i]) != -1:
                    print(i)
                    exit()

    print('0')


### FIXED CODE ###

if __name__ == "__main__":
    N = int(input())
    S = input()

    dp = [[0] * 5005 for i in range(5005)]

    for i in range(N, 0, -1):
        for j in range(N, 0, -1):
            if S[i-1] != S[j-1]:
                dp[i][j] = 0
            else:
                dp[i][j] = dp[i+1][j+1] + 1

    result = 0
    for i in range(N):
        for j in range(N):
            if i >= j:
                continue
            now = min(dp[i][j], j-i)
            result = max([now, result])

    print(result)
### BUGGY CODE ###

n,m = map(int,input().split())
d = []
for _ in range(m):
  l,r,c = map(int,input().split())
  d.append([l,r,c])
d.sort(key=lambda x:x[0])
g = [float("inf") for _ in range(n+1)]
g[1] = 0
f = 1
for i in range(m):
  if d[i][0] > f:
    print(-1)
    exit()
  f = max(f,d[i][1])
  sm = d[i][2]+g[d[i][0]]
  if g[d[i][1]] > sm:
    g[d[i][1]] = sm
    j = d[i][1]-1
    while g[j] > sm:
      g[j] = sm
      j -= 1
if g[n] != float("inf"):
  print(g[n])
else:
  print(-1)

### FIXED CODE ###

n,m = map(int,input().split())
d = []
for _ in range(m):
  l,r,c = map(int,input().split())
  d.append([l,r,c])
d.sort(key=lambda x:x[0])
g = [float("inf") for _ in range(n+1)]
g[1] = 0
f = 1
for i in range(m):
  if d[i][0] > f:
    print(-1)
    exit()
  f = max(f,d[i][1])
  sm = d[i][2]+g[d[i][0]]
  if g[d[i][1]] > sm:
    g[d[i][1]] = sm
    j = d[i][1]-1
    while g[j] > sm:
      g[j] = sm
      j -= 1
if g[n] != float("inf"):
  print(g[n])
else:
  print(-1)
### BUGGY CODE ###

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

total = 0

for i in range(N):
    #print(i, A[i])
    sum = 0
    start = i + 1
    for j in range(start, N):
        #print(i, j)
        sum = sum + A[j]
    #print(A[i], sum)
    total = (total + A[i] * sum) % 1000000007

print(total)

### FIXED CODE ###

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

total = 0
left = 0
sum = sum(A)
#print(end)

for i in range(N - 1):
    #print(i, A[i])
    left = left + A[i]
    #start = i + 1
    #for j in range(start, N):
        #print(i, j)
        #sum = sum + A[j]
    #print(A[i], sum)
    right = sum - left
    #print(i, left, right, A[i])
    total = (total + A[i] * right) % 1000000007

print(total)
### BUGGY CODE ###

R,G,B,N=map(int,input().split())
ans=0
for i in range(N+1):
    for j in range(N+1):
        tmp=N-R*i-G*j
        if tmp>=0 and tmp%B==0:
            ans+=1
print(ans)

### FIXED CODE ###

def solve():
    R,G,B,N=map(int,input().split())
    ans=0
    for i in range(N+1):
        for j in range(N+1):
            tmp=N-(R*i+G*j)
            if tmp>=0 and tmp%B==0:
                ans+=1
    print(ans)

solve()
### BUGGY CODE ###

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

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


mycnt = 1
while mycnt <= M:
    mylist[mylist.index(max(mylist))] = max(mylist)//2
    #print(mylist[mylist.index(max(mylist))])
    mycnt += 1

mysum = sum(mylist)


    

print(mysum)

### FIXED CODE ###

import heapq
 
N,M = map(int,input().split())
 
A = [int(i)*-1 for i in input().split()]


heapq.heapify(A)
 
#print(A)

for _ in range(M):
  max = heapq.heappop(A) * -1
  #print(max, A)
  
  heapq.heappush(A,(max//2)*-1)
  
  #print(A)
 
print(sum(A)*-1)
### BUGGY CODE ###

s = input()
num = int(input())

for _ in range(num):
    row = input().split()
    if len(row) == 1:
        s = s[::-1]
    else:
        if row[1] == "1":
            s = row[2] + s
        else:
            s = s + row[2]

print(s)

### FIXED CODE ###

s = input()
num = int(input())
t = "X"
reverse = False

for _ in range(num):
    row = input().split()
    if len(row) == 1:
        if reverse == False:
            reverse = True
        else:
            reverse = False
    else:
        x = row[1]
        y = row[2]
        if x == "1" and reverse:
            t += y
        elif x == "1" and not reverse:
            t = y + t
        elif x == "2" and reverse:
            t = y + t
        else:
            t += y

if reverse:
    t = t.replace("X", s)
    print(t[::-1])
else:
    t = t.replace("X", s)
    print(t)
### BUGGY CODE ###

n,m=(int(i) for i in input().split(' '))
for i in range(1,m//n+1)[::-1]:
  if i==1:
    print(i)
    break
  if m%i==0 and m//i>=n:
    print(i)
    break

### FIXED CODE ###

import random

def is_prime(q,k=50):
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    d = (q-1)>>1
    while d&1 == 0:
        d >>= 1
    for i in range(k):
        a = random.randint(1,q-1)
        t = d
        y = pow(a,t,q)
        while t != q-1 and y != 1 and y != q-1: 
            y = pow(y,2,q)
            t <<= 1
        if y != q-1 and t&1 == 0:
            return False
    return True

n,m=(int(i) for i in input().split(' '))
for i in range(1,n):
  if m%i==0 and (is_prime(i) or i==1) and is_prime(m//i) and (i==1 or m//i<n):
    print('1')
    exit()
for i in range(n,m+1):
  if i==m:
    print(1)
    break
  if m%i==0:
    print(m//i)
    break
  if m-i-n>0 and m%(m-i-n)==0 and m//(m-i-n)>n:
    print(m-i-n)
    break
### BUGGY CODE ###

X = int(input())
c = 1
for b in range(1,X+1):
  for p in range(2,X+1):
    if b**p <= X: c=max(c,b**p)
print(c)

### FIXED CODE ###

X = int(input())
max_n = 1
for i in range(2,32):
  for j in range(2,10):
    tmp = i**j
    if X >= tmp and max_n < tmp:
      max_n = tmp
print(max_n)
### BUGGY CODE ###

# vim: set fileencoding=utf-8 :
n = int(raw_input())
a = map(int, raw_input().split())

diff = None
min_diff = 999999999999999999

for i in range(n - 1):
    x = sum(a[0:i + 1])
    y = sum(a[i + 1:])
    diff = abs(x - y)
    if diff < min_diff:
        min_diff = diff

print(min_diff)


### FIXED CODE ###

# vim: set fileencoding=utf-8 :
n = int(raw_input())
a = map(int, raw_input().split())

diff = None
min_diff = 999999999999999999
x = 0
y = sum(a)

for i in range(n - 1):
    x += a[i]
    y -= a[i]
    diff = abs(x - y)
    if diff < min_diff:
        min_diff = diff

print(min_diff)
### BUGGY CODE ###

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

L = [N]
c = 2
while c < N**0.5:
    if L[-1] != N//c:
        L.append(N//c)
    c += 1
if c > N**0.5:
    c -= 1
    L.append(c)
else:
    L.append(c)


L.reverse()
dp = [[0 for j in range(c+len(L))] for i in range(K+1)]

for j in range(1, c+1):
    dp[2][j] = N//j
for j in range(1, len(L)):
    dp[2][j+c] = N//L[j]*(L[j]-L[j-1])

for i in range(2, K):
    dp[i+1][-1] = dp[i][1]
    for j in range(2, c+len(L)):
        dp[i+1][c+len(L)-j] = dp[i+1][c+len(L)-j+1]+dp[i][j]
    for j in range(1, len(L)):
        dp[i+1][j+c] *= (L[j]-L[j-1])

        
print(sum(dp[K])%(10**9+7))

### FIXED CODE ###

from itertools import accumulate

N,K = map(int, input().split())
mod = 10**9+7
sqt = int(N**0.5)
cnt = [N // i-N // (i+1) for i in range(1, N//sqt)] + [1]*sqt
x = cnt
for _ in range(K):
    x = [(i*j)%mod for i, j in zip(accumulate(reversed(x)), cnt)]
    

print(x[-1])
### BUGGY CODE ###

input=input().split()
s=[int(s) for s in input]
while True:
    if s[0]==0:
        break
    else:
        print("#"*s[1])
        for i in range(s[0]-2):
            print("#"+"."*(s[1]-2)+"#")
        print("#"*s[1])
        print()


### FIXED CODE ###

while True:
    s=input().split()
    t=[int(i) for i in s]
    H=t[0]
    W=t[1]
    if H==0:
        break
    else:
        print("#"*W)
        for i in range(H-2):
            print("#"+"."*(W-2)+"#")
        print("#"*W)
        print()