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

H, W = map(int, input().split())
HW = [0] * H
for i in range(H):
  HW[i] = str(input())
  
#縦  
T = [[0] * W for i in range(H)]  
for i in range(H):#4000000
  now = 0
  for j in range(W):
    if HW[i][j] == "#":
      T[i][j] = 0
      now = 0
    else:
      now += 1
      T[i][j] = now
      
  now = 0    
  for j in range(1, W + 1):
    if T[i][-j] == 0:
      now = 0
    elif now == 0:
      now = T[i][-j]
    else:
      T[i][-j] = now
    #print(i, now)  
  
#print(T)

#横
Y = [[0] * W for i in range(H)]  
for j in range(W):#4000000
  now = 0
  for i in range(H):
    if HW[i][j] == "#":
      Y[i][j] = 0
      now = 0
    else:
      now += 1
      Y[i][j] = now
      
  now = 0    
  for i in range(1, H + 1):
    if Y[-i][j] == 0:
      now = 0
    elif now == 0:
      now = Y[-i][j]
    else:
      Y[-i][j] = now
    #print(i, now)      
#print(Y)

ans = 0
for i in range(H):
  for j in range(W):
    if T[i][j] != 0 and Y[i][j] != 0:
      ans = max(ans, T[i][j] + Y[i][j] - 1)
      
print(ans)      
    


### FIXED CODE ###

H, W = map(int, input().split())
HW = [0] * H
for i in range(H):
  HW[i] = str(input())
  
#縦  
T = [[0] * W for i in range(H)]  
for i in range(H):#4000000
  now = 0
  for j in range(W):
    if HW[i][j] == "#":
      T[i][j] = 0
      now = 0
    else:
      now += 1
      T[i][j] = now
      
  now = 0    
  for j in range(1, W + 1):
    if T[i][-j] == 0:
      now = 0
    elif now == 0:
      now = T[i][-j]
    else:
      T[i][-j] = now
    #print(i, now)  
  
#print(T)

#横
Y = [[0] * W for i in range(H)]  
for j in range(W):#4000000
  now = 0
  for i in range(H):
    if HW[i][j] == "#":
      Y[i][j] = 0
      now = 0
    else:
      now += 1
      Y[i][j] = now
      
  now = 0    
  for i in range(1, H + 1):
    if Y[-i][j] == 0:
      now = 0
    elif now == 0:
      now = Y[-i][j]
    else:
      Y[-i][j] = now
    #print(i, now)      
#print(Y)

ans = 0
for i in range(H):
  for j in range(W):
    if T[i][j] != 0 and Y[i][j] != 0:
      ans = max(ans, T[i][j] + Y[i][j] - 1)
      
print(ans)
### BUGGY CODE ###

N = int(input())
S = input()
R = []
G = []
B = []
for i, s in enumerate(S):
    if s == 'R':
        R.append(i+1)
    elif s == 'G':
        G.append(i+1)
    else:
        B.append(i+1)
ans = len(R)*len(G)*len(B)
# (RG)B
for a in R:
    for b in G:
        if b > a:
            if b + (b-a) in B:
                ans -= 1
        else:
            if a + (a-b) in B:
                ans -= 1
# (RB)G
for a in R:
    for b in B:
        if b > a:
            if b + (b-a) in G:
                ans -= 1
        else:
            if a + (a-b) in G:
                ans -= 1
# (BG)R
for a in B:
    for b in G:
        if b > a:
            if b + (b-a) in R:
                ans -= 1
        else:
            if a + (a-b) in R:
                ans -= 1
print(ans)

### FIXED CODE ###

from collections import Counter

N = int(input())
S = input()
RGB_Counter = Counter(S)
ans = RGB_Counter['R'] * RGB_Counter['G'] * RGB_Counter['B']

dum = []
d = 0
while 3 + d*2 <= N:
    for i in range(N - 2*(d+1)):
        a = S[i]
        b = S[i+d+1]
        c = S[i+2*(d+1)]
        if a != b and b != c and c != a:
            ans -= 1
    d += 1

print(ans)
### BUGGY CODE ###

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

L_list = sorted(L_list)

count = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            if L_list[i] + L_list[j] > L_list[k]:
                count += 1
            else:
                break
            
print(count)

### FIXED CODE ###

import bisect

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

L_list = sorted(L_list)

total = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        total += bisect.bisect_left(L_list, L_list[i] + L_list[j]) - j -1

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

import numpy as np
from itertools import product
H, W, K = map(int, input().split())
G = np.array([list(map(int, list(input()))) for _ in range(H)])

ans = float("inf")

for pattern in product([0, 1], repeat = H - 1):
    div = [0] + [i for i, p in enumerate(pattern, 1) if p == 1] + [20]
    rows = []
    for i in range(len(div) - 1):
        rows.append(np.sum(G[div[i]: div[i + 1]], axis=0)) # 列方向

    flag = True
    for r in rows:
        if np.any(r > K):
            flag = False
            break
    if not flag:
        continue

    tmp_ans = 0
    cnt = [0] * len(rows)
    w = 0
    rows = [r.tolist() for r in rows]

    while w < W:
        for r in range(len(rows)):
            cnt[r] += rows[r][w]
        if np.any(np.array(cnt) > K):
            cnt = [0] * len(rows)
            tmp_ans += 1
            w -= 1
        w += 1
    
    tmp_ans += pattern.count(1)
    ans = min(ans, tmp_ans)

print(ans)

### FIXED CODE ###

from itertools import product
H, W, K = map(int, input().split())
G = [list(map(int, list(input()))) for _ in range(H)]

ans = float("inf")

for pattern in product([0, 1], repeat = H - 1):
    div = [0] + [i for i, p in enumerate(pattern, 1) if p == 1] + [H]
    rows = []
    for i in range(len(div) - 1):
        row = []
        for j in range(W):
            tmp = 0
            for k in range(div[i], div[i + 1]):
                tmp += G[k][j]
            row.append(tmp)
        rows.append(row)
        
    flag = True
    for row in rows:
        if [r for r in row if r > K]:
            flag = False
            break
    if not flag:
        continue

    tmp_ans = 0
    cnt = [0] * len(rows)
    w = 0

    while w < W:
        for r in range(len(rows)):
            cnt[r] += rows[r][w]
        if [c for c in cnt if c > K]:
            cnt = [0] * len(rows)
            tmp_ans += 1
            w -= 1
        w += 1
    
    tmp_ans += pattern.count(1)
    ans = min(ans, tmp_ans)

print(ans)
### BUGGY CODE ###

import numpy as np
n,x,y=map(int,input().split())
array=[]
for i in range(1,n):
    for j in range(i+1,n+1):
        array.append(min(abs(j-i),abs(x-j)+1+abs(y-i),abs(y-j)+1+abs(x-i)))
array=np.array(array)
for i in range(1,n):
    print(np.sum(array==i))


### FIXED CODE ###

n,x,y=map(int,input().split())
#array=[0 for i in range(n)]
array=[None]*n
for i in range(n):
    array[i]=0
for i in range(1,n):
    for j in range(i+1,n+1):
        res=min(abs(j-i),abs(x-j)+1+abs(y-i),abs(y-j)+1+abs(x-i))
        array[res]+=1
for i in range(1,n):
    print(array[i])
### BUGGY CODE ###

import sys
input = sys.stdin.readline
s = list(input())
ans = 0
s.append('n')
while 'n' in s:
    s = [i for i in s if i != 'n']
    for i in range(len(s)):
        if s[i:i+2]==['1', '0'] or s[i:i+2]==['0', '1']:
            ans += 2
            s[i:i+2] = ['n','n']
print(ans)


### FIXED CODE ###

s = input()
zero = 0
one = 0
for i in range(len(s)):
    if s[i]=='0':
        zero+=1
    else:
        one+=1
print(2*(min(zero,one)))
### BUGGY CODE ###

# -*- coding: utf-8 -*-
INF = 1000000

# ?¨??????\???????????\????????¢?????§????????????
# |V| |E|
# ai bi wi
V,E,r = map(int,raw_input().split())
edges = [[] for i in range(V)]	# ??£??\?????????

for i in xrange(E):
	a,b,w = map(int,raw_input().split())
	edges[a].append({'to':b,'weight':w})
	# edges[b].append({'to':a,'weight':w})

distance = [INF] * V
visited = [False] * V

distance[r] = 0
for i in range(V):
	min_v = -1
	for v in range(V):
		if not visited[v] and (min_v == -1 or distance[v] < distance[min_v]):
			min_v = v

	visited[min_v] = True
	for e in edges[min_v]:
		distance[e['to']] = min(distance[min_v] + e['weight'],distance[e['to']])

for d in distance:
	if d >= INF:
		print "INF"
	else:
		print d

### FIXED CODE ###

# -*- coding: utf-8 -*-
import Queue
INF = 10000000000000000

# ?¨??????\???????????\????????¢?????§????????????
# |V| |E|
# ai bi wi
V,E,r = map(int,raw_input().split())
edges = [[] for i in range(V)]	# ??£??\?????????

for i in xrange(E):
	a,b,w = map(int,raw_input().split())
	edges[a].append({'to':b,'weight':w})
	# edges[b].append({'to':a,'weight':w})

distance = [INF] * V
visited = [False] * V

distance[r] = 0
pq = Queue.PriorityQueue()
pq.put((0,r))
while not pq.empty():
	d,v = pq.get()
	visited[v] = True
	for e in edges[v]:
		if visited[e['to']] or distance[v]+e['weight'] > distance[e['to']]: continue
		distance[e['to']] = distance[v] + e['weight']
		pq.put((d+e['weight'],e['to']))

for d in distance:
	if d >= INF:
		print "INF"
	else:
		print d

# for i in range(V):
# 	min_v = -1
# 	for v in range(V):
# 		if not visited[v] and (min_v == -1 or distance[v] < distance[min_v]):
# 			min_v = v

# 	visited[min_v] = True
# 	for e in edges[min_v]:
# 		distance[e['to']] = min(distance[min_v] + e['weight'],distance[e['to']])

# for d in distance:
# 	if d >= INF:
# 		print "INF"
# 	else:
# 		print d
### BUGGY CODE ###

import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
# from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

s=input()
ab=[0,0]
ans=0
cnt=0
for i in range(len(s)):
    if s[i]=="A":
        ab[0]+=pow(3,cnt)
    elif s[i]=="B":
        ab[1]+=ab[0]
    elif s[i]=="C":
        ans+=ab[1]
    else:
        ans=ab[1]+3*ans
        ab[1]=ab[0]+3*ab[1]
        ab[0]=pow(3,cnt)+3*ab[0]
        cnt+=1
    ab[0]%=mod
    ab[1]%=mod
    ans%=mod
print(ans%mod)


### FIXED CODE ###

import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
# from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

s=input()
ab=[0,0]
ans=0
cnt=0
for i in range(len(s)):
    if s[i]=="A":
        ab[0]+=pow(3,cnt,mod)
    elif s[i]=="B":
        ab[1]+=ab[0]
    elif s[i]=="C":
        ans+=ab[1]
    else:
        ans=ab[1]+3*ans
        ab[1]=ab[0]+3*ab[1]
        ab[0]=pow(3,cnt,mod)+3*ab[0]
        cnt+=1
    ab[0]%=mod
    ab[1]%=mod
    ans%=mod
print(ans%mod)
### BUGGY CODE ###

n = int(input())
a = [int(v) for v in input().split()]
ans = 1
num = 1
limit = 1000000000000000000
for i in a:
    if i == 0:
        num = 0
        break
    if i >= limit:
        num = -1
        break
    else:
        num *= i
if num > limit:
    num = -1
ans = num
print(ans)


### FIXED CODE ###

n = int(input())
a = [int(v) for v in input().split()]
limit = 1000000000000000000
if 0 in a:
    print (0)
else:
    ans = 1
    num = 1
    for i in a:
        num *= i
        if num > limit:
            num = -1
            break
    ans = num
    print(ans)
### BUGGY CODE ###

import numpy as np
from numba import njit

N, K = list(map(int, input().strip().split()))
A = np.array(input().strip().split(), dtype=int)

@njit
def calc(A, step):
    b = np.array([0]*N)
    for i in range(N):
        left = int(max(0, i-A[i]))
        right = int(min(N-1, i+A[i]))
        b[left:right+1] +=1

    if A is not b and step < K:
        step += 1
        A = b.copy()
        return calc(A, step)
    else:
        return b.copy()

ans = calc(A, 1)
ans = [str(x) for x in ans]
print(" ".join(ans))

### FIXED CODE ###

import numpy as np
from numba import njit

N, K = list(map(int, input().strip().split()))
A = np.array(input().strip().split(), dtype=np.int64)

@njit(cache=True)
def calc(a, step):
    b = np.array([0]*N)
    for i in range(N):
        left = int(max(0, i-a[i]))
        right = int(min(N-1, i+a[i]))
        b[left] += 1
        if right + 1 < N:
            b[right+1] -= 1
    b = np.cumsum(b)
    
    if np.all(a==b) or step>=K:
        return b
    else:
        step += 1
        return calc(b, step)

ans = calc(A, 1)
ans = [str(x) for x in ans]
print(" ".join(ans))
### BUGGY CODE ###

n = int(input())
t = input()
_ = input()
mk = str.maketrans('DMCYQWERTUIOPASFGHJKLZXVBN','123' + '0'*23)
s = [0]*n + list(map(int, list(t.translate(mk))))

l = list(map(int, input().split()))
for k in l:
  d,m,dm,dmc = 0,0,0,0
  for i,j in zip(s[n:],s[n-k:]):
    if j == 1:
      d -= 1
      dm -= m
    elif j == 2:
      m -= 1
    if i == 1:
      d += 1
    elif i == 2:
      m += 1
      dm += d
    elif i == 3:
      dmc += dm
  print(dmc)

### FIXED CODE ###

def num(s,n,k):
  d,m,dm,dmc = 0,0,0,0
  for i in range(n,n*2):
    x,y = s[i],s[i-k]
    if y == 68:
      d -= 1
      dm -= m
    elif y == 77:
      m -= 1
    if x == 68:
      d += 1
    elif x == 77:
      m += 1
      dm += d
    elif x == 67:
      dmc += dm
  return dmc

def main():
  n = int(input())
  s = [0]*n + list(map(ord, list(input())))
  _ = input()
  l = list(map(int, input().split()))
  for k in l:
    print(num(s,n,k))

main()
### BUGGY CODE ###

N, M = map( int, input().split())
A = list( map( int, input().split()))
A = [ x%M for x in A]
SUM = [0]
for i in range(N):
    SUM.append(SUM[-1]+A[i])
ans = 0
cnt = 1
for l in range(N):
    if A[l] == 0:
        ans += cnt
        cnt += 1
    else:
        PART = 0
        for r in range(l+1,N+1):
            if (SUM[r] - SUM[l])%M == 0:
                PART += 1
        ans += cnt * PART
        cnt = 1
print(int(ans))

### FIXED CODE ###

N, M = map( int, input().split())
A = list( map( int, input().split()))
D = {0:1}
a = 0
ans = 0
for i in range(N):
    a = (a+A[i])%M
    ans += D.get(a,0)
    D[a] = 1 + D.get(a,0)
print(ans)
### BUGGY CODE ###

import bisect 

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

A=P[:K]
A.sort()

B=[]
for i in range(N-K):
  B.append(P[:i]+A+P[i+K:])  
  A.remove(P[i])
  #print(A)
  bisect.insort(A,P[i+K])
  #print(A)
B.append(P[:N-K]+A+P[N:])
B.sort()

ans=1
for i in range(1,len(B)):
  if B[i]!=B[i-1]:
    ans+=1
print(ans)

### FIXED CODE ###

from heapq import heappush, heappop

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

h_max = []
h_min = []
for i in range(K):
  heappush(h_min,  A[i])
  heappush(h_max, -A[i])

check = [0] * (N + 1)
tmp = [0] * N
tmp[0] = 1
for i in range(N - K):
  
  a_min =  heappop(h_min)
  a_max = -heappop(h_max)
  while check[a_min]:
    a_min =  heappop(h_min)
  while check[a_max]:
    a_max = -heappop(h_max)
  if A[i] == a_min and A[i + K] > a_max:
    tmp[i + 1] -= 1
  check[A[i]] = 1
  heappush(h_min,  a_min)
  heappush(h_max, -a_max)  
  heappush(h_min,  A[i + K])
  heappush(h_max, -A[i + K])  
  tmp[i + 1] += 1

B = [0]
for i in range(1, N):
  if A[i] > A[i - 1]:
    B.append(1)
  else:
    B.append(0)

sum_B = sum(B[1: K])
flag = 0
for i in range(N - K + 1):
  if sum_B == K - 1:
    if tmp[i]:
      flag = 1
      tmp[i] = 0
  if i == N - K:
    break
  sum_B = sum_B - B[i + 1] + B[i + K]

print(sum(tmp) + flag)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
n,p = [int(i) for i in input().split()]
s = input()
ans = 0
import collections

if p == 2 or p == 5:
    for i in range(n):
        if int(s[i]) % p == 0:
            ans += i + 1
    print(ans)
    exit()
    
else:
  chk = []
  m = 0
  chk = collections.deque(chk)
  for i in range(n)[::-1]:
    m = (int(s[i])*pow(10,n-1-i)+m)%p
    chk.append(m)
  chk.append(0)
  chk = list(chk)
  c = collections.Counter(chk)
  for i in range(p):
    ans += c[i]*(c[i]-1)/2
  print(int(ans))

### FIXED CODE ###

import sys
input = sys.stdin.readline
n,p = [int(i) for i in input().split()]
s = input()
ans = 0

import math
def nCr(n, r):
  if n < r:
    return 0
  return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

if p == 2 or p == 5:
    for i in range(n):
        if int(s[i]) % p == 0:
            ans += i + 1
    print(ans)
    exit()

else:
  chk = [0]*p
  chk[0] = 1
  m = 0
  for i in range(n)[::-1]:
    m = (int(s[i])*pow(10,n-1-i,p)+m)%p
    chk[m] += 1
  for i in chk:
    ans += nCr(i,2)
  print(ans)
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
ans=1
for i in range(n):
    ans*=a[i]
if ans>10**18:
    print("-1")
else:
    print(ans)

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
ans=1
if 0 in a:
    print(0)
else:
    for i in range(n):
        ans*=a[i]
        if ans>10**18:
            print("-1")
            exit()
    print(ans)
### BUGGY CODE ###

from collections import deque
N, M = map(int, input().split())
X = list(map(int, input().split()))
EDGE = [list(map(int, input().split())) for i in range(M)]
EDGE.sort(key=lambda x:x[2])

EDGELIST = [[] for i in range(N+1)]
for i in range(M):
    x, y, w = EDGE[i]
    EDGELIST[x].append(i)
    EDGELIST[y].append(i)

Group = [i for i in range(N+1)]

def find(x):
    while Group[x] != x:
        x = Group[x]
    return x

def Union(x, y):
    if find(x) != find(y):
        Group[find(y)] = Group[find(x)] = min(find(y), find(x))

USE = [0]*M
WEIGHTSUM = [0] + [X[i] for i in range(N)]

QUE = deque()

for i in range(M):
    x, y, w = EDGE[i]

    if find(x) != find(y):
        WEIGHTSUM[find(x)] = WEIGHTSUM[find(y)] = WEIGHTSUM[find(x)] + WEIGHTSUM[find(y)]
        Union(x, y)

    if w <= WEIGHTSUM[find(x)]:
        QUE.append(i)

while QUE:
    q = QUE.pop()
    x, y, w = EDGE[q]

    NQUE = deque([q])

    while NQUE:
        nq = NQUE.pop()

        if USE[nq] == 1:
            continue

        x, y, _ = EDGE[nq]
        for e in EDGELIST[x] + EDGELIST[y]:
            if EDGE[e][2] <= w:
                NQUE.append(e)
        USE[nq] = 1

print(USE.count(0))



### FIXED CODE ###

import sys
input = sys.stdin.readline
from collections import deque
N, M = map(int, input().split())
X = list(map(int, input().split()))
EDGE = [list(map(int, input().split())) for i in range(M)]
EDGE.sort(key=lambda x:x[2])

EDGELIST = [[] for i in range(N+1)]
for i in range(M):
    x, y, w = EDGE[i]
    EDGELIST[x].append(i)
    EDGELIST[y].append(i)

Group = [i for i in range(N+1)]

def find(x):
    while Group[x] != x:
        x = Group[x]
    return x

def Union(x, y):
    if find(x) != find(y):
        Group[find(y)] = Group[find(x)] = min(find(y), find(x))

USE = [0]*M
WEIGHTSUM = [0] + [X[i] for i in range(N)]

QUE = deque()

for i in range(M):
    x, y, w = EDGE[i]

    if find(x) != find(y):
        WEIGHTSUM[find(x)] = WEIGHTSUM[find(y)] = WEIGHTSUM[find(x)] + WEIGHTSUM[find(y)]
        Union(x, y)

    if w <= WEIGHTSUM[find(x)]:
        QUE.append(i)

while QUE:
    q = QUE.pop()
    x, y, w = EDGE[q]

    NQUE = deque([q])

    while NQUE:
        nq = NQUE.pop()

        if USE[nq] == 1:
            continue

        x, y, _ = EDGE[nq]
        for e in EDGELIST[x] + EDGELIST[y]:
            if EDGE[e][2] <= w:
                NQUE.append(e)
        USE[nq] = 1

print(USE.count(0))
### BUGGY CODE ###

from collections import deque
H, W = map(int, input().split())  # 迷路の縦、横の長さ
maze = [input() for iiii in range(H)]

# print(maze)
dist = [[-1] * W for iii in range(H)]  # スタートからの距離
check_que = deque()

for i in range(H):
    for j in range(W):
        if maze[i][j] == "#":
            dist[i][j] = 0
            check_que.append((i, j))
# print(dist)


def bfs(check_que,dist):  # distを編集する関数
    #print("{},{}".format(tate, yoko))
    while check_que:

        h, w = check_que.popleft()
        d = dist[h][w]
        for dh, dw in ((0, 1), (0, -1), (1, 0), (-1, 0)):
            h_prime, w_prime = h + dh, w + dw

            if 0 > h_prime or h_prime >= H or 0 > w_prime or w_prime >= W:
                continue
            if dist[h_prime][w_prime] == -1:
                dist[h_prime][w_prime] = d + 1
                check_que.append((h_prime, w_prime))

    return d


dis = bfs(check_que,dist)
# print(dist)
print(dis)


### FIXED CODE ###

from collections import deque
H, W = map(int, input().split())  # 迷路の縦、横の長さ
maze = []
for _ in range(H):
    maze.append(input())
# print(maze)
dist = [[-1] * W for iii in range(H)]  # スタートからの距離
check_que = deque()

d = 0

for i in range(H):
    for j in range(W):
        if maze[i][j] == "#":
            dist[i][j] = 0
            check_que.append((i, j))
# print(dist)


def bfs(initial_d):  # distを編集する関数
    dis = 0
    #print("{},{}".format(tate, yoko))
    while len(check_que) != 0:

        h, w = check_que.popleft()
        d = dist[h][w]
        for dh, dw in ((0, 1), (0, -1), (1, 0), (-1, 0)):
            h_prime, w_prime = h + dh, w + dw

            if 0 <= h_prime <= H - 1 and 0 <= w_prime <= W - 1:
                if dist[h_prime][w_prime] == -1:
                    dist[h_prime][w_prime] = d + 1
                    check_que.append((h_prime, w_prime))
                    if d + 1 > dis:
                        dis = d+1
    return dis


dis = bfs(0)
# print(dist)
print(dis)
### BUGGY CODE ###

n = int(input())
dll =[]
for i in range(n):
    command = input().split()
    if command[0] == 'insert':
        dll.insert(0, command[1])
    elif command[0] == 'delete':
       # for i in range(len(dll)):
            #if dll[i] == command[1]: 
                #dll.pop(i)
                #break
        indexes = [i for i, x in enumerate(dll) if x == command[1]]
        if len(indexes) != 0:
            dll.pop(indexes[0])
    elif command[0] == 'deleteFirst':
        dll.pop(0)
    else:
        dll.pop()

print(*dll)

### FIXED CODE ###

from collections import deque

n = int(input())
dll = deque()
for i in range(n):
    command = input().split()
    if command[0] == 'insert':
        dll.appendleft(command[1])
    elif command[0] == 'delete':
        try:
            dll.remove(command[1])
        except:
            pass
    elif command[0] == 'deleteFirst':
        dll.popleft()
    else:
        dll.pop()
print(*dll)
### BUGGY CODE ###

def minus(n):
    return n - 1

n,k,q = map(int,input().split())
a = [0] * q
b = [0] * n

member = [k]*n

for i in range(q):
    a[i] = int(input())
    member[a[i]-1] = member[a[i]-1] + 1
    member = list(map(minus, member))

for k in range(n):
    if member[k] <= 0:
        print("No")
    else:
        print("Yes")

### FIXED CODE ###

n,k,q = map(int,input().split())
a = [0] * q

member = [k] * n

for i in range(q):
    a[i] = int(input())
    member[a[i]-1] = member[a[i]-1] + 1

for j in range(n):
    if member[j] - q <= 0:
        print("No")
    else:
        print("Yes")
### BUGGY CODE ###

n = int(input())
p = list(map(int, input().split()))
count = 0
for i in range(n):
    if p[i]<=min(p[:i+1]):
        count += 1
print(count)

### FIXED CODE ###

n = int(input())
p = list(map(int, input().split()))
count = 0
Min = p[0]
for i in range(n):
    if Min >= p[i]:
        Min = p[i]
        count += 1

print(count)
### BUGGY CODE ###

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

LR = [list(map(int,input().split())) for _ in range(M)]

IDlist=[i for i in range(N)]

for l,r in LR:
    LRlist=[i for i in range(l-1,r)]
    IDlist=set(IDlist)&set(LRlist)
print(len(IDlist))

### FIXED CODE ###

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

LR = [list(map(int,input().split())) for _ in range(M)]

L=0
R=N
for l,r in LR:
    if L<l:
        L=l
    if R>r:
        R=r
    #print(str(L)+str(R))

if R-L+1<0:
    print(0)
else:
    
    print(str(R-L+1))
### BUGGY CODE ###

n=int(input())

X=list(map(int,input().split()))
Y=[]
for i in range(n):
    Y.append(X[i]-(i+1))

Z=list(set(Y))
res=10000000000000000
for i in range(len(Z)):
    cnt=0
    for j in  range(n):
        cnt+=abs(Y[j]-Z[i])
    if cnt<res:
        res=cnt
    
print(res)

### FIXED CODE ###

n=int(input())

X=list(map(int,input().split()))
Y=[]
for i in range(n):
    Y.append(X[i]-(i+1))
Y.sort()
res_1=0

if n%2==1:
    m=Y[int((n-1)/2)]
    for j in range(n):
        res_1+=abs(Y[j]-m)
else:
    m=(Y[int(n/2)-1]+Y[int(n/2)])//2
    for j in range(n):
        res_1+=abs(Y[j]-m)
        

        
print(res_1)