Harryxun/stf_run huggingface dataset:
import numpy as np
N=int(input())
A=list(map(int, input().split()))
A=np.array(A)
left=0 
right=N-1
while left<right:
  ans=0
  mid=(left+right)//2
  if A[:mid+1].sum()<A[mid+1:].sum():
    ans=min(ans,abs(A[:mid+1].sum()<A[mid+1:]))
    left=mid+1
  else:
    right=mid
print(abs(ans))

### FIXED CODE ###

import numpy as np
N=int(input())
A=list(map(int, input().split()))
A=np.array(A)
left=0 
right=N-1
while left<right:
  mid=(left+right)//2
  if A[:mid+1].sum()<A[mid+1:].sum():
    left=mid+1
  else:
    right=mid
if (abs(A[:left+1].sum()-A[left+1:].sum()))>(abs(A[:left].sum()-A[left:].sum())):
  print((abs(A[:left].sum()-A[left:].sum())))
else:
  print((abs(A[:left+1].sum()-A[left+1:].sum())))
n, a, b = map(int, input().split())

s = int(n / (a + b))

if n % (a + b) == 0:
  print(a * s)
else:
  rem = n % (a + b)
  if rem <= a:
    ans = a * s + rem
  else:
    ans = a * s + a
  print(ans)




### FIXED CODE ###

s = list(input())


if len(list(set(s))) == 1:
  print("No")
else:
  print("Yes")
from collections import deque
import sys

S = input()
Q = int(input())
q = deque([S])
reverse = False

for i in range(Q):
    X = sys.stdin.readline().split()
    if X[0] == "1":
        if reverse:
            reverse = False
        else:
            reverse = True
    elif X[0] == "2":
        if reverse:
            print(reverse)
            X[1] = str(3-int(X[1]))
        if X[1] == "1":
            q.appendleft(X[2])
        else:
            q.append(X[2])
        print(reverse, X[1], q)

if reverse: q.reverse()

for i in range(len(q)):
    print(q[i],end="")
print()

### FIXED CODE ###

from collections import deque

q = deque(input())
Q = int(input())
reverse = -1

for i in range(Q):
    X = input().split()
    if X[0] == "1":
        reverse *= -1
    # if X[1] == "1":
    elif X[1] == "1":
        if reverse == -1:
            q.appendleft(X[2])
        else:
            q.append(X[2])
    elif X[1] == "2":
        if reverse == -1:
            q.append(X[2])
        else:
            q.appendleft(X[2])
# if reverse == 1: q.reverse()

if reverse == -1:
    print(''.join(q))
else:
    print(''.join(list(q)[::-1]))
def make_divisors(n):
    divisors = []
    for i in range(int(n**0.5)+1, 0, -1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
        if len(divisors) == 2:
            break
        
    return divisors

def main():
    target = int(input())

    a, b = make_divisors(target)
    a -= 1
    b -= 1
    print(a+b)
        
        
if __name__ == "__main__":
    main()


### FIXED CODE ###

import math


def main():
    n = int(input())
    a = 1
    b = n
    
    ans = n - 1 
    
    for i in range(2, int(math.sqrt(n)) + 1):
        if n % i == 0:
            a = int(i)
            b = int(n / i)
            ans = min(ans, a+b-2)
    print(ans)
        
        
if __name__ == "__main__":
    main()
v

### FIXED CODE ###

import sys
import itertools
from operator import itemgetter #sortedの対象を決めたい
from fractions import gcd #最大公約数
from math import ceil, floor, sqrt, isinf #小数点切り上げ、切り捨て、平方根
from copy import deepcopy #参照で影響されないコピー
from collections import Counter, deque #要素ごとの出現回数、双方向アクセス可能データ型
import heapq
import numpy as np
from functools import reduce
sys.setrecursionlimit(200000)

input = sys.stdin.readline
# template


n = int(input())
h = list(map(int, input().split()))

dp = [1e9] * n

dp[0] = 0

for i in range(1, n):
    dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i-1]))
    if(i > 1):
         dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2]))

print(dp[-1])
s = input()
x, y = list(map(int, input().split()))
F = [len(fs) for fs in s.split('T')]
Fx = F[0::2]
Fy = F[1::2]

xt2 = sum(Fx)-x
yt2 = sum(Fy)-y
if xt2%2==1 or yt2%2==1:
    print('No')
    exit()

xt = xt2//2
yt = yt2//2

dpx = [False]*(xt+1)
dpx[0] = True
for f in Fx:
    for i in range(xt, f-1, -1): dpx[i] |= dpx[i-f]

dpy = [False]*(yt+1)
dpy[0] = True
for f in Fy:
    for i in range(yt, f-1, -1): dpy[i] |= dpy[i-f]

print('Yes' if dpx[xt] and dpy[yt] else 'No')

### FIXED CODE ###

s = input()
x, y = list(map(int, input().split()))
F = [len(fs) for fs in s.split('T')]
x -= F[0]
Fx = F[2::2]
Fy = F[1::2]

xt2 = sum(Fx)-x
yt2 = sum(Fy)-y
if xt2%2==1 or yt2%2==1 or xt2<0 or yt2<0:
    print('No')
    exit()

xt = xt2//2
yt = yt2//2

dpx = [False]*(xt+1)
dpx[0] = True
for f in Fx:
    for i in range(xt, f-1, -1): dpx[i] |= dpx[i-f]

dpy = [False]*(yt+1)
dpy[0] = True
for f in Fy:
    for i in range(yt, f-1, -1): dpy[i] |= dpy[i-f]

print('Yes' if dpx[xt] and dpy[yt] else 'No')
N = int(input())
A = [int(input()) for i in range(N)]
m1, m2 = sorted(A, reverse=True)[:2]

for i in range(N):
    if i == p:
        print(m2)
    else:
        print(m1)

### FIXED CODE ###

N = int(input())
A = [int(input()) for i in range(N)]
m = max(A)
p = A.index(m)
A.remove(m)
n = max(A)

for i in range(N):
    if i == p:
        print(n)
    else:
        print(m)
import pandas as pd
N = int(input())
sps = []
for i in range(1, N+1):
    s, p = input().split(' ')
    sps.append({'i': i, 's': s, 'p': p})
ret = pd.DataFrame(sps).sort_values(['s', 'p'], ascending=[True, False]).values.tolist()
for i in range(N):
    print(ret[i][0])

### FIXED CODE ###

N = int(input())  
sps = []
ss = []
for i in range(1, N+1):
    s, p = input().split(' ')
    sps.append([i, s, int(p)])
    if s not in ss:
        ss.append(s)

sps = sorted(sps, key=lambda x: x[2], reverse=True)
ss = sorted(ss)
ret = []
for s in ss:
    t = [tmp for tmp in sps if tmp[1]==s]
    ret.extend(t)

for i in range(N):
    print(ret[i][0])
N=int(input())
quotient=N//1000
for i in range(quotient+1):
  change=N-1000
  if change=<0:
    change=abs(change)
    print(change)
  else:
    continue
    

### FIXED CODE ###

N=int(input())
quotient=N//1000
for i in range(quotient+1):
    N=N-1000
    if N<=0:
        break
print(abs(N))
import numpy as np

N,K,*A = map(int,open(0).read().split())
na = np.array(A)

for i in range(K):
    if all(na) == N:
        break
    B = [0] * N
    nb = np.array(B)
    for n in range(N):
        L = max(0, n-na[n])
        R = min(N-1 , n + na[n])
        nb[L] += 1
        if R+1 != N:
            nb[R+1] -= 1
      
    na = nb.cumsum()        
 
print(*na,sep=" ")    
   


### FIXED CODE ###

from itertools import accumulate
#from operator import add

N,K = map(int,input().split())
A = map(int,input().split()) 
for k in range(K):
    B = [0] * N
    for i,x in enumerate(A):
        L = max(0, i-x)
        R = min(N-1, i+x)
        B[L] += 1
        if R+1 != N:
            B[R+1] -= 1
    #L = accumulate(B,add) 
    L = list(accumulate(B))[:]
    if L == A:
        break
    A = L
print(*A)
S = input().split("/")
if S[1]<=4:
    print("Heisei")
else:
    print("TBD")

### FIXED CODE ###

S = input().split("/")
tuki = S[1]
hi = S[2]
if int(tuki)<4:
    print("Heisei")
else:
    if int(tuki)==4 and int(hi)<=30:
        print("Heisei")
    else:
        print("TBD")
H, W = map( int, input().split() )
S = [ list( input() ) for _ in range(H) ]

dx = [1, -1, 0, 0]
dy = [0, 0, 1, -1]
# (i, j) から行けるペアの数
def dfs( x, y, isVisited ):
    ans = 0
    isVisited[x][y] = True
    for i in range(4):
        nx = x + dx[i]
        ny = y + dy[i]
        if S[x][y] == '#':
            if 0 <= nx and nx < H and 0 <= ny and ny < W and not isVisited[nx][ny]:
                if S[nx][ny] == '.': ans += dfs( nx, ny, isVisited )+1
        else:
            if 0 <= nx and nx < H and 0 <= ny and ny < W and not isVisited[nx][ny]:
                if S[nx][ny] == '#': ans += dfs( nx, ny, isVisited )
    return ans


ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
          isVisited = [ [False]*W for _ in range(H) ]
          ans += dfs( i, j, isVisited )

print( ans )


### FIXED CODE ###

from sys import setrecursionlimit
setrecursionlimit(200000)

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


isVisited = [ [False]*W for _ in range(H) ]
dx = [1, -1, 0, 0]
dy = [0, 0, 1, -1]
# (i, j) から行けるペアの数
def dfs( x, y ):
    isVisited[x][y] = True
    numBlack, numWhite = 0, 0
    if S[x][y] == '#': numBlack = 1
    else:              numWhite = 1
    for i in range(4):
        nx = x + dx[i]
        ny = y + dy[i]
        if 0 <= nx and nx < H and 0 <= ny and ny < W and not isVisited[nx][ny]:
            if S[x][y] != S[nx][ny]:
                tmpB, tmpW = dfs( nx, ny )
                numBlack += tmpB
                numWhite += tmpW
    return numBlack, numWhite

ans = 0
for i in range(H):
    for j in range(W):
        if not isVisited[i][j]: 
            numBlack, numWhite = dfs( i, j )
            ans += numBlack * numWhite

print( ans )
inverse = ['A': 'T', 'T': 'A', 'G': 'C', 'C': 'G']
print(inverse[input()])


### FIXED CODE ###

b = input()
if b == "A":
	print("T")
elif b == "T":
	print("A")
elif b == "G":
	print("C")
elif b == "C":
	print("G")
class Node:
  key = None
  left = None
  right = None
  def __init__(self, k):
    self.key = k

class BST:
  root = None
  def insert(self, k):
    x = self.root
    y = None
    z = Node(k)
    while x is not None:
      y = x
      if z.key < y.key:
        x = x.left
      elif y.key < z.key:
        x = x.right
    
    if y is None:
      # 初回値
      self.root = z
    else:
      if z.key < y.key:
        y.left = z
      elif y.key < z.key:
        y.right = z
        
  def inorder(self):
    # 中間巡回順で出力
    # 単純にソートでいいのでは
    return sorted(self.preorder())
    
  def preorder(self):
    # 先行巡回順で出力
    res = []
    cur_node = self.root
    right_successor = []
    left_successor = []
    # 現在の木がなにもない場合
    if cur_node is None:
      return res
    # そうでない場合
    while cur_node is not None:
      res.append(cur_node.key)
      # 次に調べるやつを追加する
      if cur_node.left is not None:
        left_successor.append(cur_node.left)
      if cur_node.right is not None:
        right_successor.append(cur_node.right)
      # 次に調べるやつを左、右の順でやっていく
      cur_node = left_successor.pop() if len(left_successor) > 0 else right_successor.pop() if len(right_successor) else None
    return res
n = int(input())
bst = BST()
for _ in range(n):
  query = [int(x) if x.isnumeric() else x for x in input().split()]
  if query[0] == 'insert':
    bst.insert(query[1])
  elif query[0] == 'print':
    ans = bst.inorder()
    print(" " + " ".join(list(map(str, ans))))
    ans = bst.preorder()
    print(" " + " ".join(list(map(str, ans))))


### FIXED CODE ###

class Node:
  key = None
  left = None
  right = None
  def __init__(self, k):
    self.key = k

class BST:
  root = None
  def insert(self, k):
    x = self.root
    y = None
    z = Node(k)
    while x is not None:
      y = x
      if z.key < y.key:
        x = x.left
      elif y.key < z.key:
        x = x.right
    
    if y is None:
      # 初回値
      self.root = z
    else:
      if z.key < y.key:
        y.left = z
      elif y.key < z.key:
        y.right = z

  def inorder(self, r, lis):
    # 中間巡回順で出力
    if r != None:
      self.inorder(r.left, lis)
      lis.append(r.key)
      self.inorder(r.right, lis)


  def preorder(self, r, lis):
    # 先行巡回順で出力
    if r != None:
      lis.append(r.key)
      self.preorder(r.left, lis)
      self.preorder(r.right, lis)

    
n = int(input())
bst = BST()
for _ in range(n):
  # query = [int(x) if re.match('[+|-]?\d', x) else x for x in input().split()]
  query = input().split()
  if query[0] == 'insert':
    bst.insert(int(query[1]))
  elif query[0] == 'print':
    root = bst.root
    in_lis = []
    pre_lis = []
    bst.preorder(root, pre_lis)
    bst.inorder(root, in_lis)
    print(" " + " ".join(list(map(str, in_lis))))
    print(" " + " ".join(list(map(str, pre_lis))))
from math import sin,cos
N,L=map(int,input().split())
S=N*(N-1)*(N-2)/6
T=[int(input())*pi/L for _ in range(N)]
print(sum([sum([cos((T[i]+T[j]))*(N+2*(i-j))for j in range(i+1, N)])for i in range(N)])/S,sum([sum([sin((T[i]+T[j]))*(N+2*(i-j))for j in range(i+1,N)])for i in range(N)])/S)

### FIXED CODE ###

from math import sin,cos,pi
N,L=map(int,input().split())
S=N*(N-1)*(N-2)/ 6
T=[int(input())*pi/L for _ in range(N)]
print(sum([sum([cos((T[i]+T[j]))*(N+2*(i-j)) for j in range(i+1, N)]) for i in range(N)])/S,sum([sum([sin((T[i]+T[j]))*(N+2*(i-j)) for j in range(i+1,N)]) for i in range(N)])/S)
def factorization(n) -> list:
    arr = []
    temp = n
    for i in range(2, int(- (- n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])
        if temp != 1:
            arr.append([temp, 1])
        if arr == []:
            arr.append([n, 1])
        return arr
      
print(factrization(24))

### FIXED CODE ###

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

print("Yes" if N == M else "No")
n = int(input())
s = str(input())
if len(s) <= n:
  print(s)
else:
  print(s[:k+1]+"...")

### FIXED CODE ###

n = int(input())
s = str(input())
if len(s) <= n:
  print(s)
else:
  print(s[:n]+"...")
from itertools import groupby

S = list(input())
K = int(input())

N = len(S)

if len(set(list(S))) == 1:
    print(N * K // 2)
else:
    G = list(map(lambda g: len(list(g[1])) // 2, (groupby(S))))
    cnt = sum(G)

    if S[0] != S[N - 1]:
        print(cnt * K)
    else:
        a = G[0]
        b = G[-1]
        print(cnt * K - (a // 2 - b // 2 + (a + b) // 2) * (K - 1))


### FIXED CODE ###

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

res = []

while len(B) > 0:
    p = -1
    for i, b in enumerate(B[::-1]):
        j = len(B) - i
        if b == j:
            p = j
            break
    if p == -1:
        print(-1)
        exit()
    else:
        res.append(p)
        B.pop(p - 1)

for r in res[::-1]:
    print(r)
import sys
input = sys.stdin.readline

def main():
    n, m, c = map(int, input().split())
    b = list(map(int, input().split()))
    a = [list(map(int, input().split())) for i in range(n)]

    ans = 0
    for i in a:
        cnt = c
        for j in range(m):
            cnt += i[j] * b[j]
        
        if cnt > 0:
            ans += 1
    print(ans)

if __name__ == "__main__":
    main()

### FIXED CODE ###

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

print(H * W - H * w - W * h + h * w)
a,b,h=map(int,input().split())
print((a+b)*h/2)

### FIXED CODE ###

a=int(input())
b=int(input())
h=int(input())
print(int((a+b)*h/2))
import tqdm
import sys
import math
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
p = list(map(int, input().split()))
ma = int(1e18)

for p_ in p:
    if p_ == 0:
        print(0)
        exit()

ans = 1
for p_ in p:
    ans *= p_
    if ans > ma:
        print(-1)
        exit()
print(ans)


### FIXED CODE ###

import sys
import math
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
p = list(map(int, input().split()))
ma = int(1e18)

for p_ in p:
    if p_ == 0:
        print(0)
        exit()

ans = 1
for p_ in p:
    ans *= p_
    if ans > ma:
        print(-1)
        exit()
print(ans)
N = int(input())
A = [list(map(int,input().split())) for i in range(N)]
a_max = max(A)[0]
count = A.count(a_max)

for i in range(N):
	if A[i] < a_max and count >= 2:
		print(a_max)
	else:
		b_max = 0
		for j in range(N):
				if A[j] == a_max:
					continue
				if A[j] > b_max:
					b_max = A[j]
		print(b_max)


### FIXED CODE ###

N = int(input())
A = [int(input()) for i in range(N)]
a_max = int(max(A))
count = A.count(a_max)

for i in range(N):
	if A[i] < a_max or count >= 2:
		print(a_max)
	else:
		b_max = 0
		for j in range(N):
				if A[j] == a_max:
					continue
				if A[j] > b_max:
					b_max = A[j]
		print(b_max)
n, m = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
import numpy as np
A = np.array(A)//2
A = A.tolist()
def gcd(a, b):
  if b == 0:
    return a
  else:
    return gcd(b, a%b)

def lcm (a, b):
  return (a*b)//gcd(a, b)

def gcd_many(l):
  if len(l) == 2:
    return gcd(l[0],l[1])
  else:
    return gcd_many(l[2:]+[gcd(l[0],l[1])])

def lcm_many(l):
  if len(l) == 2:
    return lcm(l[0],l[1])
  else:
    return lcm_many([lcm(l[0],l[1])] + l[2:])
lc = lcm_many(A)
ans = (m // lc) // 2 if lc < m else 0
if lc % 2 != 0:
  ans += 1
print(ans)

### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
from fractions import gcd
from functools import reduce
 
N,M,*A = map(int,read().split())
 
# 「奇数倍」に帰着
A = [x >> 1 for x in A]
 
def merge(a,b):
    g = gcd(a,b)
    a //= g; b //= g
    if a % 2 == 0:
        return 0
    if b % 2 == 0:
        return 0
    n = a * b * g
    if n > 10 ** 9:
        return 0
    return n
 
x = reduce(merge, A)
if x == 0:
    answer = 0
else:
    answer = (M//x) - (M//(x+x))
 
print(answer)
H, W = map(int,input().split())
a=[list(input()) for i in range(H)]
#yoko
while a.count(["."]*len(a[0]))>0:
    a.remove(["."]*len(a[0]))

a_t = tenchi(a)
while a_t.count(["."]*len(a_t[0]))>0:
    a_t.remove(["."]*len(a_t[0]))
ans = tenchi(a_t)
for i in range(len(ans)):
    ansa = "".join(ans[i])
    print(ansa)

def tenchi(gr):
    gr_t=[[0]*len(gr) for i in range(len(gr[0]))]
    for i in range(len(gr)):
        for j in range(len(gr[i])):
            gr_t[j][i] = gr[i][j]
    return gr_t

### FIXED CODE ###

def tenchi(gr):
    gr_t=[[0]*len(gr) for i in range(len(gr[0]))]
    for i in range(len(gr)):
        for j in range(len(gr[i])):
            gr_t[j][i] = gr[i][j]
    return gr_t

H, W = map(int,input().split())
a=[list(input()) for i in range(H)]
#yoko
while a.count(["."]*len(a[0]))>0:
    a.remove(["."]*len(a[0]))

a_t = tenchi(a)
while a_t.count(["."]*len(a_t[0]))>0:
    a_t.remove(["."]*len(a_t[0]))
ans = tenchi(a_t)
for i in range(len(ans)):
    ansa = "".join(ans[i])
    print(ansa)
from sortedcontainers import SortedList, SortedDict

s = input()

print('YES' if len(set(s)) == 2 else 'NO')

### FIXED CODE ###


S = input()

if len(set(S)) == 1:
    print("No")
else:
    print("Yes")
s = input()
print("Heisei") if s[5:7] =< 4 else print("TBD")

### FIXED CODE ###

s = input()
print("Heisei") if s[5:7] == "01" or s[5:7] == "02" or s[5:7] == "03" or s[5:7] == "04"  else print("TBD")
from math import factorial

N, K = map(int, input().split())
n_blue, n_red = K, N-K

for k in range(1, K+1):
    retval = (factorial(n_red+1) // (factorial(n_red-k+1) * factorial(k))) * (factorial(n_blue-1) // (factorial(n_blue-k) * factorial(k-1)))
    print(retval % (10**9 + 7))

### FIXED CODE ###

from math import factorial

N, K = map(int, input().split())
n_blue, n_red = K, N-K

for k in range(1, K+1):
    if k-1 > n_red:
        print(0)
        continue
    retval = (factorial(n_red+1) // (factorial(n_red-k+1) * factorial(k))) * (factorial(n_blue-1) // (factorial(n_blue-k) * factorial(k-1)))
    print(retval % (10**9 + 7))
import math
N, M = map(int, input().split())
_M = M
primes = [1]
prime = 2
for p in range(prime, int(math.sqrt(M))):
  while _M % p == 0:
    primes.append(p)
    _M //= p
    if _M == 1:
      break
  if p >= _M:
    break
if _M > 1:
  primes.append(_M)
ans = 1
devides = [0] * N
devides[1] = 1
for prime in primes:
  _devides = [d for d in devides]
  for i in range(N):
    if devides[i]:
      if i * prime < N:
        _devides[i * prime] = 1
      else:
        ans = max(M // i // prime, ans)
  devides = _devides
print(ans)

### FIXED CODE ###

import math
N, M = map(int, input().split())
_M = M
primes = [1]
prime = 2
for p in range(prime, int(math.sqrt(M))):
  while _M % p == 0:
    primes.append(p)
    _M //= p
    if _M == 1:
      break
  if p >= _M:
    break
if _M > 1:
  primes.append(_M)
ans = 1
devides = [0] * N
if N > 1:
  devides[1] = 1
  for prime in primes:
    _devides = [d for d in devides]
    for i in range(N):
      if devides[i]:
        if i * prime < N:
          _devides[i * prime] = 1
        else:
          ans = max(M // i // prime, ans)
    devides = _devides
else:
  ans = M
print(ans)
import sys
 
sys.setrecursionlimit(200000000)
 
n, q = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n-1)]
px = [list(map(int, input().split())) for _ in range(q)]
 
l = [[] for i in range(n+1)]
for pi in ab:  
    l[pi[0]].append(pi[1])
    l[pi[1]].append(pi[0])
 
def dfs(graph, start, oya):
    if start != 1:
        graph[start].remove(oya)
    if len(graph[start]) == 0:
        return
    else:
        for i in graph[start]:
            dfs(graph, i, start)
 
dfs(l, 1, 1)
 
def dfs_2(graph, start, ans, x):
    ans[start] += x
    if len(graph[start]) == 0:
        return
    else:
        for i in graph[start]:
            dfs_2(graph, i, ans, x)
 
ans = [0 for i in range(n+1)]
for p, x in px:
    dfs_2(l, p, ans, x)
        
for i in range(1, n+1):
    print(ans[i], end=' ')
print()

### FIXED CODE ###

a = int(input())
s = input()
if a >= 3200:
    print(s)
else:
    print('red')
n = int(input())
a = [int(input()) for x in range(n)]

copied_arr = a.copy()
max1 = max(a)
copied_arr.remove(max1)
max2 = max(copied_arr)

for x in a:
    if x == max1:
        print(max2)
    else:
        print(max1)


### FIXED CODE ###

n = int(input())
a = [int(input()) for x in range(n)]

copied_arr = a.copy()
max1 = max(a)
copied_arr.remove(max1)
max2 = max(copied_arr)

for x in a:
    if x == max1:
        print(max2)
    else:
        print(max1)
a,b = map(int,input().split()

print(a*b, a*2 + b*2)

### FIXED CODE ###

a,b=map(int, input().split())
print(a*b,2*a+2*b)
#test
def hersCode(L, n):
  ok = len(L)
  ng = l
  while abs(ok - ng) > 1:
    mid = abs(ok + ng) // 2
    if L[mid] >= n:
      ok = mid
    else:
      ng = mid
  return ok

def main():
  N, Q = list(map(int, input().split()))
  STX = [list(map(int, input().split())) for _ in range(N)]
  D = [int(input()) for _ in range(Q)]

  STX.sort(key = lambda x: x[2])

  L = [[-1, -1]] * Q
  for s, t, x in STX:
    l = hersCode(D, s - x)
    r = hersCode(D, t - x)
    continue
    while l < r:
      if L[l][1] == -1:
        L[l] = [x, r]
        l += 1
      else:
        l = L[l][1]

  for i in L:
    print(i[0])

main()


### FIXED CODE ###

import heapq
def main():
  N, Q = list(map(int, input().split()))
  STX = tuple(list(map(int, input().split())) for _ in range(N))
  D = tuple([int(input()) for _ in range(Q)])

  L = []
  for s, t, x in STX:
    L.append((x, s - x, t - x))

  L.sort(key = lambda x: x[1])
  q = []
  cnt = 0
  push = heapq.heappush
  pop = heapq.heappop
  t = []
  for i in range(Q):
    while cnt < len(L) and D[i] >= L[cnt][1]:
      if t != []:
        push(q, t)
        t = []
      push(q, L[cnt])
      cnt += 1
    if t != [] and t[2] > D[i]:
      print(t[0])
    else:
      while q != []:
        t = pop(q)
        if t[2] > D[i]:
          print(t[0])
          break
      else:
        t = []
        print(-1)

main()
import sys
input = sys.stdin.readline
H,W=map(int,input().split())
s=[]
s.append("".join("#" for _ in range(W+2)))
cnt=0
for i in range(H):
    ss=input().strip()
    s.append("#"+ss+"#")
    for w in range(W):
        if ss[w]==".":
            cnt+=1

s.append("".join("#" for _ in range(W+2)))
#print(s)

def solv(h,w,cnt):
    #print(h,w)
    #print(a)
    #print(s)
    if a[h][w]>cnt+1 and s[h][w]==".":
        a[h][w]=cnt+1
        solv(h-1,w,cnt+1)
        solv(h,w-1,cnt+1)
        solv(h+1,w,cnt+1)
        solv(h,w+1,cnt+1)
    return 

a=[[1000000]*(W+2) for _ in range(H+2)]
solv(1,1,0)
print(cnt-a[-2][-2] if a[-2][-2]!= 1000000 else -1)


### FIXED CODE ###

import sys
input = sys.stdin.readline
H,W=map(int,input().split())
s=[]
s.append("".join("#" for _ in range(W+2)))
cnt=0
for i in range(H):
    ss=input().strip()
    s.append("#"+ss+"#")
    for w in range(W):
        if ss[w]==".":
            cnt+=1

s.append("".join("#" for _ in range(W+2)))
#print(s)
import sys
sys.setrecursionlimit(300000)
def solv(h,w,cnt):
    #print(h,w)
    #print(a)
    #print(s)
    if a[h][w]>cnt+1 and s[h][w]==".":
        a[h][w]=cnt+1
        solv(h-1,w,cnt+1)
        solv(h,w-1,cnt+1)
        solv(h+1,w,cnt+1)
        solv(h,w+1,cnt+1)
    return

a=[[1000000]*(W+2) for _ in range(H+2)]
solv(1,1,0)
print(cnt-a[-2][-2] if a[-2][-2]!= 1000000 else -1)