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

import sys
from collections import deque


fin = sys.stdin.readline
H, W = [int(elem) for elem in fin().split()]
A_list = [list(fin().rstrip("\n")) for _ in range(H)]
assert len(A_list[0]) == W

distances = [[float('inf')] * W for _ in range(H)]
que = deque((i, j, 0) for i in range(H) for j in range(W) if A_list[i][j] == "#")
max_dist = 0
while que:
    i, j, dist = que.popleft()
    for next_i, next_j in ((i + 1, j), (i - 1, j), (i, j + 1), (i, j - 1)):
        if not (0 <= next_i < H and 0 <= next_j < W):
            continue
        elif distances[next_i][next_j] < float('inf'):
            continue
        elif A_list[next_i][next_j] == "#":
            continue
        else:
            que.append((next_i, next_j, dist + 1))
            distances[next_i][next_j] = dist + 1
            max_dist = max(max_dist, dist + 1)
print(max_dist)


### FIXED CODE ###

import sys
from collections import deque


fin = sys.stdin.readline
H, W = [int(elem) for elem in fin().split()]
A_list = [fin().rstrip("\n") for _ in range(H)]
assert len(A_list[0]) == W

visited = [[False] * W for _ in range(H)]
que = deque((i, j, 0) for i in range(H) for j in range(W) if A_list[i][j] == "#")
max_dist = 0
while que:
    i, j, dist = que.popleft()
    for next_i, next_j in ((i + 1, j), (i - 1, j), (i, j + 1), (i, j - 1)):
        if not (0 <= next_i < H and 0 <= next_j < W):
            continue
        elif visited[next_i][next_j]:
            continue
        elif A_list[next_i][next_j] == "#":
            continue
        else:
            que.append((next_i, next_j, dist + 1))
            visited[next_i][next_j] = True
            max_dist = max(max_dist, dist + 1)
print(max_dist)
### BUGGY CODE ###

N = int(input())
A = [int(input()) for _ in range(N)]

for i in range(N):
  print(max(A[i+1:]+A[:i]))

### FIXED CODE ###


N = int(input())
A = [int(input()) for _ in range(N)]

m = [0, 0]
for i in range(N):
  if A[i] > m[0]:
    m[0] = A[i]
    m[1] = i  

m2 = 0
for i in range(N):
  if i == m[1]:
    continue
  m2 = max(A[i], m2)

res = []
for i in range(N):
  if i != m[1]:
    print(m[0])
  else:
    print(m2)
### BUGGY CODE ###

from itertools import accumulate

n, k = map(int, input().split())
k2 = k * 2
req_b = [[0] * k for _ in range(k)]
req_w = [[0] * k for _ in range(k)]
bc, wc = 0, 0
for i in range(n):
    x, y, c = input().split()
    x, y = int(x), int(y)
    rx, ry = x % k2, y % k2
    b = c == 'B'
    if rx >= k:
        rx -= k
        if ry >= k:
            ry -= k
        else:
            b = not b
    elif ry >= k:
        ry -= k
        b = not b
    if b:
        req_b[rx][ry] += 1
        bc += 1
    else:
        req_w[rx][ry] += 1
        wc += 1

req_b[0] = list(accumulate(req_b[0]))
req_w[0] = list(accumulate(req_w[0]))

for i in range(1, k):
    req_b[i][0] += req_b[i - 1][0]
    req_w[i][0] += req_w[i - 1][0]
    for j in range(1, k):
        req_b[i][j] += req_b[i][j - 1] + req_b[i - 1][j] - req_b[i - 1][j - 1]
        req_w[i][j] += req_w[i][j - 1] + req_w[i - 1][j] - req_w[i - 1][j - 1]

ans = 0
for dx in range(k):
    dxk_b = req_b[dx][-1]
    dxk_w = req_w[dx][-1]
    for dy in range(k):
        b1 = req_b[dx][dy]
        b2 = bc - req_b[k - 1][dy] - dxk_b + b1
        w1 = req_w[dx][dy]
        w2 = wc - req_w[k - 1][dy] - dxk_w + w1
        b, w = b1 + b2, w1 + w2
        ans = max(ans, b + wc - w, w + bc - b)
        # print(dx, dy, b, w, b + wc - w, w + bc - b)
print(ans)


### FIXED CODE ###

from itertools import accumulate

n, k = map(int, input().split())
k2 = k * 2
req_b = [[0] * k for _ in range(k)]
req_w = [[0] * k for _ in range(k)]
bc, wc = 0, 0
for i in range(n):
    x, y, c = input().split()
    x, y = int(x), int(y)
    rx, ry = x % k2, y % k2
    b = c == 'B'
    if rx >= k:
        rx -= k
        if ry >= k:
            ry -= k
        else:
            b = not b
    elif ry >= k:
        ry -= k
        b = not b
    if b:
        req_b[rx][ry] += 1
        bc += 1
    else:
        req_w[rx][ry] += 1
        wc += 1

req_b[0] = list(accumulate(req_b[0]))
req_w[0] = list(accumulate(req_w[0]))

for i in range(1, k):
    req_b[i][0] += req_b[i - 1][0]
    req_w[i][0] += req_w[i - 1][0]
    for j in range(1, k):
        req_b[i][j] += req_b[i][j - 1] + req_b[i - 1][j] - req_b[i - 1][j - 1]
        req_w[i][j] += req_w[i][j - 1] + req_w[i - 1][j] - req_w[i - 1][j - 1]

ans = 0
for dx in range(k):
    dxk_b = req_b[dx][-1]
    dxk_w = req_w[dx][-1]
    for dy in range(k):
        b1 = req_b[dx][dy]
        b2 = bc - req_b[k - 1][dy] - dxk_b + b1
        w1 = req_w[dx][dy]
        w2 = wc - req_w[k - 1][dy] - dxk_w + w1
        b, w = b1 + b2, w1 + w2
        ans = max(ans, b + wc - w, w + bc - b)
        # print(dx, dy, b, w, b + wc - w, w + bc - b)
print(ans)
### BUGGY CODE ###

from collections import deque
H,W = map(int, input().split())
CH,CW = map(lambda x: int(x) - 1, input().split())
DH,DW = map(lambda x: int(x) - 1, input().split())
S = [input() for i in range(H)]
INF = 10 ** 9
walk = [(0, 1), (0, -1), (-1, 0), (1, 0)]
warp = [(i, j) for i in range(-2, 3) for j in range(-2, 3) if (i, j) not in [(0, 0)] + walk]
h = CH
w = CW
Distance = [[INF] * W for _ in range(H)]
Distance[h][w] = 0
q = deque(())
q.append((h,w))
while q:
  h,w = q.popleft()
  if [h,w] == [DH,DW]:
    break
  for i,j in walk:
    hwalk = h + i
    wwalk = w + j
    if 0 <= hwalk < H and 0 <= wwalk < W and S[hwalk][wwalk] == '.' and Distance[h][w] < Distance[hwalk][wwalk]:
      Distance[hwalk][wwalk] = Distance[h][w]
      q.appendleft((hwalk,wwalk))
  for i,j in warp:
    hwalk = h + i
    wwalk = w + j
    if 0 <= hwalk < H and 0 <= wwalk < W and S[hwalk][wwalk] == '.' and Distance[h][w] + 1 < Distance[hwalk][wwalk]:
      Distance[hwalk][wwalk] = Distance[h][w] + 1
      q.append((hwalk,wwalk))
print(int(Distance[DH][DW]) if Distance[DH][DW] != INF else -1)

### FIXED CODE ###

from collections import deque
H,W = map(int, input().split())
CH,CW = map(lambda x: int(x) - 1, input().split())
DH,DW = map(lambda x: int(x) - 1, input().split())
S = [input() for i in range(H)]
INF = 10 ** 9
walk = [(0, 1), (0, -1), (-1, 0), (1, 0)]
warp = [(i, j) for i in range(-2, 3) for j in range(-2, 3) if (i, j) not in [(0, 0)] + walk]
h = CH
w = CW
Distance = [[INF] * W for _ in range(H)]
Distance[h][w] = 0
q = deque(())
q.append((h,w))
while q:
  h,w = q.popleft()
  if [h,w] == [DH,DW]:
    break
  for i,j in walk:
    hwalk = h + i
    wwalk = w + j
    if 0 <= hwalk < H and 0 <= wwalk < W and S[hwalk][wwalk] == '.' and Distance[h][w] < Distance[hwalk][wwalk]:
      Distance[hwalk][wwalk] = Distance[h][w]
      q.appendleft((hwalk,wwalk))
  for i,j in warp:
    hwalk = h + i
    wwalk = w + j
    if 0 <= hwalk < H and 0 <= wwalk < W and S[hwalk][wwalk] == '.' and Distance[h][w] + 1 < Distance[hwalk][wwalk]:
      Distance[hwalk][wwalk] = Distance[h][w] + 1
      q.append((hwalk,wwalk))
print(int(Distance[DH][DW]) if Distance[DH][DW] != INF else -1)
### BUGGY CODE ###

N, Ma, Mb = map(int, input().split())
Med = [tuple(map(int, input().split())) for _ in range(N)]
N *= 100
INF = 100000
dp = [[INF]*(N+1) for _ in range(N+1)] #dp[i,j]:Aがiグラム、Bがjグラムの時の最小予算
dp[0][0] = 0 
from itertools import product as prd
R = lambda x:reversed(range(x,N+1))
for a,b,c in Med:
    for i,j in prd(R(a),R(b)):
        dp[i][j] = min(dp[i][j], dp[i-a][j-b]+c)

ans = INF
for i,j in prd(R(1),R(1)):
    if i*Mb == j*Ma:
        ans = min(ans, dp[i][j])
print(ans if ans != INF else -1)

### FIXED CODE ###

import collections
import copy
INF = 10000

#入力
N, Ma, Mb = map(int, input().split())
medichine = [tuple(map(int, input().split())) for _ in range(N)]

dp = {}
#dp初期化
dp = collections.defaultdict(lambda:INF)
dp[0,0] = 0

for a, b, c in medichine:
    dp_ = copy.copy(dp)
    for ca,cb in dp.keys():
        dp_[ca+a, cb+b] = min(dp_[ca+a, cb+b], dp[ca,cb]+c)
    dp = dp_    

ans = INF
for ca,cb in dp.keys():
    if ca == cb == 0: continue
    if ca*Mb == cb*Ma:
        ans = min(ans, dp[ca,cb])
        
print(-1 if ans == INF else ans)
### BUGGY CODE ###

n = int(input())
s = list(input() for _ in range(n))
ss = sorted(list(set(s)))
lens = len(ss)
l = [0]*lens
for i in range(lens):
    l[i] = s.count(ss[i])
for i in range(lens):
    if l[i] == max(l):
        print(ss[i])

### FIXED CODE ###

N = int(input())

d = {}
for _ in range(N):
    S = input()
    if S in d:
        d[S] += 1
    else:
        d[S] = 1

m = max(d.values())
for s in sorted(k for k in d if d[k] == m):
    print(s)
### BUGGY CODE ###

n, m = map(int,input().split())
    
tbin_o = []
for i in range(m):
    xxx = list(map(int,input().split()))
    tbin_o.append(xxx)

tbin_2 = []
for i in range(len(tbin_o)):
    if tbin_o[i][0] == 1 or tbin_o[i][1] == n:
        tbin_2.append(tbin_o[i])

aaa = 0
for j in range(len(tbin_2)):
    for l in range(len(tbin_2)):
        if tbin_2[j][1] == tbin_2[l][0] and j != l:
            aaa = aaa + 1
            break
            
if aaa == 1 :
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

### FIXED CODE ###

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

boolins =[]
for i in range(n):
    boolins.append(0)
    
for i in range(m):
    xxx = list(map(int,input().split()))
    if xxx[0] == 1:
        boolins[xxx[1]] = boolins[xxx[1]] + 1
    elif xxx[1] == n :
        boolins[xxx[0]]=boolins[xxx[0]]+ 1
    else:
        None


if 2 in boolins:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')
### BUGGY CODE ###

import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect


def main():
    H, W = map(int, input().split())
    A = [list(input()) for _ in range(H)]

    que = deque()
    for h in range(H):
        for w in range(W):
            if A[h][w] == '#':
                que.append((h, w))

    ans = 0
    while que:
        # print(A)
        # print(len(que))
        q = deque()
        for h, w in que:
            dx4 = [0, 0, 1, -1]
            dy4 = [1, -1, 0, 0]
            for dx, dy in zip(dx4, dy4):
                nh = h + dy
                nw = w + dx

                if 0 <= nh < H and 0 <= nw < W and A[nh][nw] == '.':
                    q.append((nh, nw))
                    A[nh][nw] = '#'

        que = q

        if que:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect


def main():
    H, W = map(int, input().split())
    A = [list(input()) for _ in range(H)]

    checked = [[False] * W for _ in range(H)]
    ans = 0

    que = []
    for h in range(H):
        for w in range(W):
            if A[h][w] == '#' and not checked[h][w]:
                que.append((h, w))
                checked[h][w] = True
    while que:
        next_que = []
        while que:
            h, w = que.pop()
            dx4 = [0, 0, 1, -1]
            dy4 = [1, -1, 0, 0]

            for dx, dy in zip(dx4, dy4):
                next_h = h + dy
                next_w = w + dx
                if 0 <= next_h < H and 0 <= next_w < W and A[next_h][next_w] == '.' and not checked[next_h][next_w]:
                    A[next_h][next_w] = '#'
                    checked[h][w] = True
                    next_que.append((next_h, next_w))
        que = next_que
        if que:
            ans += 1

    print(ans)


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

h,w,d = map(int,raw_input().split(" "))

mp = []

for a in range(h):
  mp += map(int,raw_input().split(" "))

data = [-1] * (h*w + 1)

for a in range(d+1,h*w+1):
  l = mp.index(a-d)
  r = mp.index(a)
  x = abs((r/w) - (l/w))
  y = abs((r%w) - (l%w))
  data[a] = x+y

data2 = [-1] * (h*w + 1)

for a in range(d+1,h*w+1):
  if a - d <= 0:
    continue
  data2[a] = data2[a-d] + data[a]

q = int(raw_input())

for a in range(q):
  l,r = map(int,raw_input().split(" "))
  print data2[r] - data2[l]


### FIXED CODE ###

h,w,d = map(int,raw_input().split(" "))

mp = {}
now = 0

for a in range(h):
  z = map(int,raw_input().split(" "))
  for zz in z:
    mp[zz] = now
    now += 1

data = [-1] * (h*w + 1)
data2 = [-1] * (h*w + 1)

for a in range(d+1,h*w+1):
  l = mp[a-d]
  r = mp[a]
  x = abs((r/w) - (l/w))
  y = abs((r%w) - (l%w))
  data[a] = x+y
  if a - d <= 0:
    continue
  data2[a] = data2[a-d] + data[a]

q = int(raw_input())

for a in range(q):
  l,r = map(int,raw_input().split(" "))
  print data2[r] - data2[l]
### BUGGY CODE ###

class cumsum2D:
    def __init__(self, data):
        self.N = len(data)
        self.M= len(data[0])
        self.cum = [[0] * (self.M + 1) for _ in range(self.N + 1)]
        for i in range(self.N):
            for j in range(self.M):
                self.cum[i + 1][j + 1] = self.cum[i][j + 1] + self.cum[i + 1][j] - self.cum[i][j] + data[i][j]

    def get(self,x1,y1,x2,y2):
        """
        長方形の領域 [x1,x2)*[y1,y2) の範囲内にインプットされた数字の和を取る
        """
        return self.cum[x2][y2] - self.cum[x1][y2] - self.cum[x2][y1] + self.cum[x1][y1]

########################################################################################################
import sys
input = sys.stdin.readline
MOD = 10**9 + 7

N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
dp = [[0]*(M+1) for _ in range(N+1)]
cum = [[0] * (M + 1) for _ in range(N + 1)]
for i in range(N):
    for j in range(M):
        if S[i]==T[j]:
            dp[i][j] += cum[i][j] + 1
        cum[i + 1][j + 1] = cum[i][j + 1] + cum[i + 1][j] - cum[i][j] + dp[i][j]
print((cum[N][M]+1)%MOD)

### FIXED CODE ###

# https://atcoder.jp/contests/abc130/tasks/abc130_e
"""
タグ: LCS、二次元累積和
"""
import sys
input = sys.stdin.readline
MOD = 10**9 + 7

N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
dp = [[0]*(M+1) for _ in range(N+1)]
cum = [[0] * (M + 1) for _ in range(N + 1)]
for i in range(N):
    for j in range(M):
        if S[i]==T[j]:
            dp[i][j] += cum[i][j] + 1
            dp[i][j]%=MOD
        cum[i + 1][j + 1] = cum[i][j + 1] + cum[i + 1][j] - cum[i][j] + dp[i][j]
        cum[i + 1][j + 1]%=MOD
print(cum[N][M]+1)
### BUGGY CODE ###

n, k = map(int, input().split())
tenjo = n
a = list(map(int, input().split()))
for j in range(k):
  b = [0]*n
  for i in range(n):
    if max(0, i-a[i]) + min(n, i+a[i]+1) >= n:
      tenjo -= 1
    for e in range(max(0, i-a[i]), min(n, i+a[i]+1)):
      b[e] += 1
  a = b
  if a.count(tenjo) == n:
    break
print(" ".join(list(map(str, a))))
      
  

### FIXED CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
for j in range(min(k, 41)):
  b = [0]*n
  for i in range(n):
    l = max(0, i-a[i])
    r = min(n, i+a[i]+1)
    b[l] += 1
    if r < n:
      b[r] -= 1
  for i in range(1, n): 
    b[i]+=b[i-1]
  a = b

print(" ".join(list(map(str, a))))
### BUGGY CODE ###

N,K = map(int,input().split())
A = list(map(int,input().split()))
S = 1
for j in range(K):
  S = S * A[j]
for i in range(K,N):
  T = (S // A[i-K])*A[i]
  if S < T:
    print("Yes")
  else:
    print("No")
  S = T

          

### FIXED CODE ###

N,K = map(int,input().split())
A = list(map(int,input().split()))
for i in range(K,N):
    if A[i-K] < A[i]:
        print("Yes")
    else:
        print("No")
### BUGGY CODE ###

n, k = map( int, input().split() )
h = [ int( hi ) for hi in input().split() ]
#print( n, k )
#print( h )

cost = [ 1000000000 ] * n
cost[ 0 ] = 0
for ni in range( 1, n ):
    for ki in range( 1, min( k+1, ni+1 ) ):
#        print( ni, ki )
        costx = cost[ ni-ki ] + max( h[ ni ]-h[ ni-ki ], h[ ni-ki ]-h[ ni ] )
        cost[ ni ] = min( cost[ ni ], costx )

print( cost[ n-1 ] )


### FIXED CODE ###

import numpy as np
N,K = map(int,input().split())
h = np.array(list(map(int,input().split())))

dp = np.zeros(N,dtype=int)
for i in range(1,N):
    dp[i] = (dp[max(0,i-K):i] + np.abs(h[i]-h[max(0,i-K):i])).min()
print(dp[-1])
### BUGGY CODE ###

N = int(input())
L = [int(input()) for i in range(N)]
a = []
for i in L:
    if i in a:
        a.remove(i)
    else:
        a.append(i)
print(len(a))

### FIXED CODE ###

N = int(input())
L = [int(input()) for i in range(N)]
L.sort()
res = 0
i = 0
while i < len(L)-1:
    if L[i] == L[i+1]:
        res += 2
        i += 1
    i += 1
    
print(len(L)-res)
### BUGGY CODE ###

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

ans = 0
for x in range(K+1):
    for y in range(K+1):
        if x + y > S:
            break
        for z in range(K+1):
            if x + y + z == S:
                ans += 1

print(ans)

### FIXED CODE ###

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

ans = 0
for x in range(K+1):
    for y in range(K+1):
        x_y = x + y
        if x_y > S:
            break
        if S - x_y <= K:
            ans += 1

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

from collections import Counter
from scipy.misc import comb

N = int(input())
A = list(map(int, input().split()))
ans = 0
cumulative_sum = [0] + [sum(A[:i+1]) for i in range(N)]
counts = Counter(cumulative_sum)
ans = 0
for v in counts.values():
    ans += v * (v-1) // 2
    
print(ans)


### FIXED CODE ###

from collections import Counter
import numpy as np

N = int(input())
A = [0]+list(map(int, input().split()))

cumulative_sum = np.cumsum(A)
counts = Counter(cumulative_sum)
ans = 0
for v in counts.values():
    ans += v * (v-1) // 2
    
print(ans)
### BUGGY CODE ###

import numpy as np

def main():
    H, W = map(int, input().split())
    S = [list(input()) for _ in range(H)]
    
    left = np.zeros([H, W], dtype=np.int)
    right = np.zeros([H, W], dtype=np.int)
    up = np.zeros([H, W], dtype=np.int)
    down = np.zeros([H, W], dtype=np.int)

    for i in range(H):
        for j in range(W):
            if S[i][j] == '.':
                if j == 0:
                    left[i][j] = 0
                else:
                    left[i][j] = left[i][j-1] + 1
                if i == 0:
                    up[i][j] = 0
                else:
                    up[i][j] = up[i-1][j] + 1
            else:
                left[i][j] = -1
                up[i][j] = -1
            
            if S[-1-i][-1-j] == '.':
                if j == 0:
                    right[-1-i][-1-j] = 0
                else:
                    right[-1-i][-1-j] = right[-1-i][-1-(j-1)] + 1
                if i == 0:
                    down[-1-i][-1-j] = 0
                else:
                    down[-1-i][-1-j] = down[-1-(i-1)][-1-j] + 1
            else:
                right[-1-i][-1-j] = -1
                down[-1-i][-1-j] = -1
                
    print(np.max(left+right+up+down) + 1)

main()

### FIXED CODE ###

def main():
    H, W = map(int, input().split())
    S = [list(input()) for _ in range(H)]

    left = [[-1]*W for _ in range(H)]
    right = [[-1]*W for _ in range(H)]
    up = [[-1]*W for _ in range(H)]
    down = [[-1]*W for _ in range(H)]

    for i in range(H):
        for j in range(W):
            if S[i][j] == '.':
                if j == 0:
                    left[i][j] = 0
                else:
                    left[i][j] = left[i][j-1] + 1

    for i in range(H):
        for j in range(W):
            if S[-1-i][-1-j] == '.':        
                if j == 0:
                    right[-1-i][-1-j] = 0
                else:
                    right[-1-i][-1-j] = right[-1-i][-1-(j-1)] + 1

    for i in range(H):
        for j in range(W):
            if S[i][j] == '.':
                if i == 0:
                    up[i][j] = 0
                else:
                    up[i][j] = up[i-1][j] + 1

    for i in range(H):
        for j in range(W):
            if S[-1-i][-1-j] == '.':
                if i == 0:
                    down[-1-i][-1-j] = 0
                else:
                    down[-1-i][-1-j] = down[-1-(i-1)][-1-j] + 1
            
    ans = 0
    temp = [0] * W
    for i in range(H):
        for j in range(W):
            temp[j] = left[i][j] + right[i][j] + down[i][j] + up[i][j] + 1
        ans = max(ans, max(temp))
    print(ans)

main()
### BUGGY CODE ###

n, y = map(int, input().split())
z = y/1000
while True:
    for i in range(1,n+1):
        for j in range(0, n+1-i):
            for k in range(0, n+1-i-j):
                if 10*i + 5*j + 1*k == y:
                    print('i j k')
                    break
print('-1 -1 -1')

### FIXED CODE ###

n, y = map(int, input().split())
z = y/1000
for i in range(n+1):
    for j in range(n+1-i):
        k = n - i- j
        if 10*i + 5*j + k == z:
            print(i, j, k)
            exit(0)
print('-1 -1 -1')
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
ans = 0
for i in range(N):
  k = A[i]
  ans += len([0 for j in range(i + k, N) if j - i == A[i] + A[j]])
else:
  print(ans)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
L = {}
R = {}
ans = 0
for i in range(N):
  t = i + 1 + A[i]
  if t in L:
    L[t] += 1
  else:
    L[t] = 1
  t = i + 1 - A[i]
  if t > 0:
    if t in R:
      R[t] += 1
    else:
      R[t] = 1
for i in R:
  if i in L:
    ans += R[i] * L[i]
print(ans)
### BUGGY CODE ###

N, K, Q = map(int, input().split())
PO = [K]*N
while Q:
  c = int(input())
  for i in range(N):
    if i==(c-1):
      pass
    else:
      PO[i]-=1
  Q-=1
for i in range(N):
  if PO[i]>0:
    print("Yes")
  else:
    print("No")
    

### FIXED CODE ###

n, k, q = map(int, input().split())
po = [0]*n
r = q-k
while q:
  c = int(input())
  po[c-1]+=1
  q-=1
for i in range(n):
  if po[i]>r:
    print('Yes')
  else:
    print('No')
### BUGGY CODE ###

N = int(input())
A,B,C=[None]*N,[None]*N,dict()
for i in range(N):
  A[i],B[i] = [int(j) for j in input().split()]
  if not B[i] in C:
    C[B[i]] = []
  C[B[i]] += [[A[i],B[i]]]
C = sorted(C.items(), key=lambda C:C[0])
s=0
for k,v in C:
  for i in v:
    s+=i[0]
    if i[1]<s:
      print('No')
      exit()

print('Yes')

### FIXED CODE ###

N = int(input())
C=dict()
for i in range(N):
 A,B = [int(j) for j in input().split()]
 if not B in C:
   C[B] = []
 C[B] += [A]
C = sorted(C.items(), key=lambda C:C[0])
s=0
for k,v in C:
    s+=sum(v)
    if k<s:
        print('No')
        exit()
print('Yes')
### BUGGY CODE ###

n,t=map(int,input().split())
dish=[list(map(int,input().split())) for i in range(n)]
dish.sort()
dp=[0]*6001
for i in range(n):
    a,b=dish[i]
    for j in range(t-1,-1,-1):
        dp[j+a]=max(dp[j+a],dp[j]+b)
print(max(dp))

### FIXED CODE ###

n,t=map(int,input().split())
dish=[list(map(int,input().split())) for i in range(n)]
dish.sort()
dp=[0]*6001
for i in range(n):
    a,b=dish[i]
    for j in range(t-1,-1,-1):
        dp[j+a]=max(dp[j+a],dp[j]+b)
print(max(dp))
### BUGGY CODE ###

# -*- coding: utf-8 -*-
# D - Line++
# 標準入力の取得
N,X,Y = list(map(int, input().split()))

# 求解
# (i, j)間の最短距離はmin{|j-i|, |X-i|+1+|j-Y|, |Y-i|+1+|j-X|}であるため、
# (i, j)が決まれば、最短距離はO(1)で決まる。したがって、全(i, j)について、最短距離を求める。
k_list = [0 for i in range(1,N)]
for i in range(1, N):
    for j in range(i+1, N+1):
        min_path = min([abs(j-i), abs(X-i)+1+abs(j-Y), abs(Y-i)+1+abs(j-X)])
        k_list[min_path-1] += 1

# 結果出力
for k in k_list:
    print(k)

### FIXED CODE ###

# -*- coding: utf-8 -*-
# D - Line++
# 標準入力の取得
N,X,Y = list(map(int, input().split()))

# 求解
# (i, j)間の最短距離はmin{|j-i|, |X-i|+1+|j-Y|, |Y-i|+1+|j-X|}であるため、
# (i, j)が決まれば、最短距離はO(1)で決まる。したがって、全(i, j)について、最短距離を求める。
k_list = [0 for i in range(1,N)]
for i in range(1, N):
    diff_X_i = abs(X - i)
    diff_Y_i = abs(Y - i)
    for j in range(i+1, N+1):
        diff_j_i = abs(j - i)
        diff_j_X = abs(j - X)
        diff_j_Y = abs(j - Y)
        min_path = min([diff_j_i, diff_X_i+1+diff_j_Y, diff_Y_i+1+diff_j_X])
        k_list[min_path-1] += 1

# 結果出力
for k in k_list:
    print(k)
### BUGGY CODE ###

lenght = int(input())
 
x = list(map(int,input().split()))
first_value = 1
for i in range(lenght):
  first_value *= x[i]
  if first_value == 0:
    break
if first_value > 1e18:
  print(-1)
else:
  print(first_value)

### FIXED CODE ###

lenght = int(input())
 
x = list(map(int,input().split()))
x.sort(reverse=True)
check = False

if x[-1]==0:
  print(0)
else:
  first_value = 1
  for val in x:
    first_value *= val
    if first_value > 1e18:
      check=True
      break
  if check:
    print(-1)
  else:
  	print(first_value)