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

n = int(input())
s = input()
red = s.count('R')
green = s.count('G')
blue = s.count('B')
res = red * green * blue
k = n//2
for i in range(n-2):
    for t in range(i+1,((n-1+i)//2)+1):
        if set((s[i],s[t],s[2*t-i])) == set(('R','G','B')):
            res -= 1
print(res)

### FIXED CODE ###

n = int(input())
s = input()
red = s.count('R')
green = s.count('G')
blue = s.count('B')
res = red * green * blue
k = n//2
for i in range(n-2):
    for t in range(i+1,((n-1+i)//2)+1):
        if set((s[i],s[t],s[2*t-i])) == set(('R','G','B')):
            res -= 1
print(res)
### BUGGY CODE ###

import itertools

n, k = map(int, input().split())
S = input()
blocks = [(k, len(list(v))) for k, v in itertools.groupby(S)]
res = 0
i = 0
if blocks[i][0] == '0':
  res = max(res, sum([b[1] for b in blocks[i:i+2*k]]))
  i += 1

while i < len(blocks):
  res = max(res, sum([b[1] for b in blocks[i:i+2*k+1]]))
  i += 2
print(res)


### FIXED CODE ###

import itertools
 
_, k = map(int, input().split())
S = input()
blocks = [(key, len(list(v))) for key, v in itertools.groupby(S)]
res = 0
i = 0
if blocks[i][0] == '0':
  res = max(res, sum([b[1] for b in blocks[i:i+2*k]]))
  i += 1

crr = sum([b[1] for b in blocks[i:i+2*k+1]])
res = max(res, crr)
while i+2*k + 2 < len(blocks):
  i += 2
  crr = crr + blocks[i+2*k-1][1] + blocks[i+2*k][1]
  crr = crr - blocks[i-1][1] - blocks[i-2][1]
  res = max(res, crr)

crr = sum([b[1] for b in blocks[-2*k:]])
res = max(res, crr)
print(res)
### BUGGY CODE ###

import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

def sigma(func, frm, to):
    result = 0
    for i in range(frm, to+1):
        result += func(i)
    #print(result)

def f(x):
    return x

K = int(input())

#print(sigma(f,1,K))

#print(gcd(sigma(f,1,K),sigma(f,1,K),sigma(f,1,K)))

#sigma(sigma(sigma(gcd(), 1, K)))

#print(gcd(sigma(gcd,1,K),sigma(f(K),1,K),sigma(f(K),1,K)))

x = 0

#print()

for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            x += gcd(a, b, c)
            """print("a:",end="")
            print(a)
            print("b:",end="")
            print(b)
            print("c:",end="")
            print(c)"""

print(x)

#print(gcd(27,18,9))

### FIXED CODE ###

import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

def sigma(func, frm, to):
    result = 0
    for i in range(frm, to+1):
        result += func(i)
    #print(result)

def f(x):
    return x

K = int(input())

#print(sigma(f,1,K))

#print(gcd(sigma(f,1,K),sigma(f,1,K),sigma(f,1,K)))

#sigma(sigma(sigma(gcd(), 1, K)))

#print(gcd(sigma(gcd,1,K),sigma(f(K),1,K),sigma(f(K),1,K)))

x = 0

#print()

for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            x += gcd(a, b, c)
            """print("a:",end="")
            print(a)
            print("b:",end="")
            print(b)
            print("c:",end="")
            print(c)"""

print(x)

#print(gcd(27,18,9))
### BUGGY CODE ###

import itertools
import math
import fractions
import functools
n, m = map(int, input().split())
h = list(map(int, input().split()))
ab = []
for i in range(m):
    ai, bi = map(int, input().split())
    ab.append([ai-1,bi-1])

v = [True]*n
for i in range(m):
    for j in range(n):
        if ab[i][0] == j or ab[i][1] == j:
            if h[ab[i][0]] > h[ab[i][1]]:
                v[ab[i][1]] = False
            elif h[ab[i][0]] < h[ab[i][1]]:
                v[ab[i][0]]= False
            else:
                v[ab[i][0]]= False
                v[ab[i][1]]= False

print(v.count(True))

### FIXED CODE ###

import math
n, m = map(int, input().split())
h_list = list(map(int, input().split()))
h_count = [0] * n
ab_list = []
count = 0
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    ab_list.append([a, b])


for i in range(m):
    if h_list[ab_list[i][0]] > h_list[ab_list[i][1]]:
        h_count[ab_list[i][1]] += 1
    elif h_list[ab_list[i][0]] < h_list[ab_list[i][1]]:
        h_count[ab_list[i][0]] += 1
    else:
        h_count[ab_list[i][1]] += 1
        h_count[ab_list[i][0]] += 1


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

def check(A, n,  mi):
    i, E, s = 0, [0 for i in range(n)], 0
    while i < n:
        if s == mi: return True
        if E[i] == 0:
            s += A[i]
            E[i] = 1
            i = 0
        else:
            E[i] = 0
            s -= A[i]
            i += 1
    return False

def ALDS1_5A():
    n, A, q = int(input()),list(map(int, input().split())), int(input())
    for m in input().split():
        if check(A, n, int(m)):
            print('yes')
        else:
            print('no')

if __name__ == '__main__':
    ALDS1_5A()

### FIXED CODE ###

def ALDS1_5A():
    n, A, q = int(input()), list(map(int, input().split())), int(input())
    S=[False for i in range(2001)]
    for a in A:
        for i in range(2001-a, 0, -1):
            if S[i]: S[i+a] = True
        S[a] = True
    for mi in input().split():
        if S[int(mi)]:
            print('yes')
        else:
            print('no')

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

N, *A = open(0).read().split()

S = [[0] * 21 for _ in range(21)]

ans = 0
for a in A:
    if (idx := a.find(".")) == -1:
        c2 = c5 = 0
    else:
        c2 = c5 = -(len(a) - idx - 1)

    a = int(a.replace(".", ""))
    while a % 2 == 0:
        c2 += 1
        a //= 2
    while a % 5 == 0:
        c5 += 1
        a //= 5
    c2 = min(c2, 10)
    c5 = min(c5, 10)
    ans += sum(S[i][j] for i in range(10 - c2, 21) for j in range(10 - c5, 21))

    S[c2 + 10][c5 + 10] += 1

print(ans)

### FIXED CODE ###

N, *A = open(0).read().split()

S = [[0] * 21 for _ in range(21)]

ans = 0
for a in A:
    idx = a.find(".")
    if idx == -1:
        c2 = c5 = 0
    else:
        c2 = c5 = -(len(a) - idx - 1)

    a = int(a.replace(".", ""))
    while a % 2 == 0:
        c2 += 1
        a //= 2
    while a % 5 == 0:
        c5 += 1
        a //= 5
    c2 = min(c2, 10)
    c5 = min(c5, 10)
    ans += sum(S[i][j] for i in range(10 - c2, 21) for j in range(10 - c5, 21))

    S[c2 + 10][c5 + 10] += 1

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

import sys
sys.setrecursionlimit(1000000)
def dfs(vertex):
  visited[vertex] = True
  if vertex != 0:
    maxlen = 0
    x = a[vertex]
    for (L, z) in table:
      if z < x: # strict increasing
        maxlen = max(maxlen, L)
    table.append((maxlen+1, x))
  ans[vertex] = max(L for (L, _) in table)
  for node in adjacent[vertex]:
    if not visited[node]:
      dfs(node)
  table.pop()
  return
def notrecursion():
  visited[0] = True
  ans[0] = 1
  stack_nodes = [(node, 1) for node in adjacent[0]]
  while stack_nodes:
    node, depth = stack_nodes.pop()
    while len(table)>depth:
      table.pop()
    visited[node] = True
    maxlen = 0
    x = a[node]
    for (L, z) in table:
      if z < x: # strict increasing
        maxlen = max(maxlen, L)
    table.append((maxlen+1, x))
    ans[node] = max(L for (L, _) in table)
    for neighbour in adjacent[node]:
      if not visited[neighbour]:
        stack_nodes.append((neighbour, depth+1))
  
n = int(input())
a = list(map(int, input().split()))
adjacent = {i: [] for i in range(n)}
for _ in range(n-1):
  node1, node2 = map(int, input().split())
  node1 -= 1
  node2 -= 1
  adjacent[node1].append(node2)
  adjacent[node2].append(node1)
visited = [False]*n
ans = [0]*n
table = [(1, a[0])]
notrecursion()
[print(value) for value in ans]

### FIXED CODE ###

import sys
sys.setrecursionlimit(1000000)
from bisect import bisect, bisect_left
def longest_subsequence(sequence):
  subsequence = [float("inf") for _ in range(len(sequence)+1)]
  subsequence[0] = float("-inf")
  for value in sequence:
    j = bisect(subsequence, value)
    if subsequence[j-1] != value: # strict increasing
      subsequence[j] = value
  return bisect_left(dp, float("inf"))-1
# print(longest_subsequence([9, 13, 2, 10, 4, 13, 11, 13]))
# sys.exit()
def dfs(vertex):
  visited[vertex] = True
  value = a[vertex]
  j = bisect(subsequence, value)
  previous = subsequence[j]
  if subsequence[j-1] != value: # strict increasing
    subsequence[j] = value
  ans[vertex] = bisect_left(subsequence, float("inf"))-1
  for node in adjacent[vertex]:
    if not visited[node]:
      dfs(node)
  subsequence[j] = previous
  return
n = int(input())
a = list(map(int, input().split()))
adjacent = {i: [] for i in range(n)}
for _ in range(n-1):
  node1, node2 = map(int, input().split())
  node1 -= 1
  node2 -= 1
  adjacent[node1].append(node2)
  adjacent[node2].append(node1)
visited = [False]*n
ans = [0]*n
subsequence = [float("inf") for _ in range(n+1)]
subsequence[0] = float("-inf")
dfs(0)
[print(value) for value in ans]
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
res = 0

if sum(a) < sum(b):
    res = -1
else:
    c = [a[i] - b[i] for i in range(n)]
    c1 = [i if i > 0 else 0 for i in c]
    c2 = sum([i if i < 0 else 0 for i in c])
    c3 = sum([1 if i < 0 else 0 for i in c])
    if c2 < 0:
        c1.sort(reverse=True)
        for i in range(n):
            if sum(c1[0:i]) + c2 > 0:
                res = c3 + i
                break

print(res)


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
res = 0
d = 0

if sum(a) < sum(b):
    res = -1
else:
    c = [a[i] - b[i] for i in range(n)]
    c1 = [i if i > 0 else 0 for i in c]
    c2 = sum([i if i < 0 else 0 for i in c])
    c3 = sum([1 if i < 0 else 0 for i in c])
    if c2 < 0:
        c4 = sorted(c1, reverse=True)
        for i in range(n):
            d = d + c4[i]
            if d + c2 > 0:
                res = c3 + i + 1
                break

print(res)
### BUGGY CODE ###

#!/usr/bin/env python3
from collections import deque

import networkx as nx

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

g = nx.Graph()
for i in range(n - 1):
    g.add_edge(*map(int, input().split()))
nx.set_node_attributes(g, name="a", values=0)
nx.set_node_attributes(g, name="b", values=True)

for i in range(q):
    p, x = map(int, input().split())
    g.nodes[p]["a"] += x

d = deque([1])
g.nodes[1]["b"] = False
while len(d):
    p = d.popleft()
    for i in g.neighbors(p):
        if g.nodes[i]["b"]:
            g.nodes[i]["a"] += g.nodes[p]["a"]
            g.nodes[i]["b"] = False
            d.append(i)
for i in range(1, n + 1):
    print(g.nodes[i]["a"], end=" ")
print("")


### FIXED CODE ###

#!/usr/bin/env python3
from collections import deque

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

graph = [deque([]) for _ in range(n + 1)]
for _ in range(n-1):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

a = [0] * -~n
b = [True] * -~n
for i in range(q):
    p, x = map(int, input().split())
    a[p] += x

d = deque([1])
b[1] = False

while len(d):
    p = d.popleft()
    for i in graph[p]:
        if b[i]:
            a[i] += a[p]
            b[i] = False
            d.append(i)
print(*a[1:])
### BUGGY CODE ###

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

input = sys.stdin.readline

def main():
    n, m = [int(e) for e in input().split()]
    A = [int(e) for e in input().split()]
    A.sort()
    for l in sys.stdin:
        b, c = [int(e) for e in l.strip().split()]
        b_cnt = 0
        for i in range(len(A)):
            if A[i] < c:
                A[i] = c
                b_cnt += 1
            if b_cnt == b:
                break
        A.sort()
    print(sum(A))

main()


### FIXED CODE ###

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

input = sys.stdin.readline

def main():
    n, m = [int(e) for e in input().split()]
    A = [int(e) for e in input().split()]
    A.sort()

    M = []
    max_c = 0
    for l in sys.stdin:
        b, c = [int(e) for e in l.strip().split()]
        max_c = max(max_c, c)
        M.append([b, c])
    last_idx = len(A)
    for i in range(len(A)):
        if max_c < A[i]:
            last_idx = i + 1
            break

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


    idx = 0
    for m in M:
        b, c = m[0], m[1]
        b_cnt = 0
        for i in range(idx, last_idx):
            if A[i] > c:
                break
            if A[i] < c:
                A[i] = c
                b_cnt += 1
                idx += 1
            if b_cnt == b:
                break

    print(sum(A))

main()
### BUGGY CODE ###

from collections import defaultdict
from heapq import *
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

n,m=MI()
to=defaultdict(list)
inf=10**9
dist=defaultdict(int)
home=[set() for _ in range(n)]
for u in range(n):dist[u,-1]=inf
for _ in range(m):
    u,v,c=MI1()
    to[u,c].append((v,c))
    to[v,c].append((u,c))
    home[u].add(c)
    home[v].add(c)
    dist[u,c]=dist[v,c]=inf

hp=[]
dist[0,-1]=0
heappush(hp,(0,0,-1))
while hp:
    d,u,c=heappop(hp)
    #print(d,u,c,hp,dist)
    if u==n-1:
        print(d)
        break
    if d>dist[u,c]:continue
    if c==-1:
        for nc in home[u]:
            if d+1<dist[u,nc]:
                dist[u,nc]=d+1
                heappush(hp,(d+1,u,nc))
    else:
        if d<dist[u,-1]:
            dist[u,-1]=d
            heappush(hp,(d,u,-1))
        for v,_ in to[u,c]:
            if d>=dist[v,c]:continue
            dist[v,c]=d
            heappush(hp,(d,v,c))
else:
    print(-1)


### FIXED CODE ###

import sys

int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

from collections import deque

def solve():
    dist = [inf] * len(to)
    q = deque()
    q.append((0, 0))
    dist[0] = 0
    while q:
        d, i = q.popleft()
        if d > dist[i]: continue
        if i < n:
            for j in to[i]:
                if dist[j] <= d + 1: continue
                dist[j] = d + 1
                q.append((d + 1, j))
        else:
            for j in to[i]:
                if j == n - 1:
                    print(dist[i])
                    exit()
                if dist[j] <= d: continue
                dist[j] = d
                q.appendleft((d, j))
    print(-1)

inf=10**9
n,m=MI()
to=[]
uctoi={}

for u in range(n):
    to.append([])
    uctoi[u,0]=u

for _ in range(m):
    u,v,c=MI()
    u,v=u-1,v-1
    if (u,c) not in uctoi:
        i=uctoi[u,c]=len(to)
        to.append([])
        to[i].append(u)
        to[u].append(i)
    else:i=uctoi[u,c]
    if (v,c) not in uctoi:
        j=uctoi[v,c]=len(to)
        to.append([])
        to[j].append(v)
        to[v].append(j)
    else:j=uctoi[v,c]
    to[i].append(j)
    to[j].append(i)
#print(to)
#print(fin)

solve()
### BUGGY CODE ###

import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    s = input()
    len_s = len(s)

    a = []

    def rec(n,m):
        if n == len_s:
            a.append(m)
            return
        elif n > len_s:
            return
        if s[n] == "e":
            rec(n+5, m+"erase")
            rec(n+6, m+"eraser")

        elif s[n] == "d":
            rec(n+5, m+"dream")
            rec(n+7, m+"dreamer")

    ans = rec(0,"")
    if len(a) != 0:
        print("YES")
    else:
        print("NO")







if __name__=="__main__":
    main()


### FIXED CODE ###

import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    s = list(input())
    s.reverse()
    len_s = len(s)
    t = 0
    while True:
        if t == len_s:
            print("YES")
            exit()
        elif t > len_s:
            break
        else:
            if "".join(s[t:t+5]) == "maerd":
                t += 5
            elif "".join(s[t:t+7]) == "remaerd":
                t += 7
            elif "".join(s[t:t+5]) == "esare":
                t += 5
            elif "".join(s[t:t+6]) == "resare":
                t += 6
            else:
                break
    print("NO")


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

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

	#上下左右
	STAGE_score = []

	result = 0
	for y in range(H):
		count, score = 0, []
		for x in range(W):
			if STAGE[y][x] == ".":
				count += 1
				if x == W - 1:
					score += [count] * count
			else:
				if 0 < count:
					score += [count] * count
				score += [0]
				count = 0
		STAGE_score += [score]

	#for l in STAGE_score:
	#	print(*l)

	for y in range(H):
		for x in range(W):
			if STAGE[y][x] == "#":
				continue
			else:
				score = STAGE_score[y][x]
				for n in range(y - 1, -1, -1):
					if STAGE[n][x] == "#":
						break
					else:
						score += 1
				for n in range(y + 1, H):
					if STAGE[n][x] == "#":
						break
					else:
						score += 1
			result = max(result, score)
			#print(y, x, result)

	print(result)
main()

### FIXED CODE ###

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

sum_s = [[], []]

for y in range(H):
	count, line = 0, []
	for x in range(W):
		if STAGE[y][x] == ".":
			count += 1
		else:
			if 0 < count:
				line += [count] * count
			line += [0]
			count = 0
	else:
		if 0 < count:
			line += [count] * count
	sum_s[0] += [line]

for x in range(W):
	count, line = 0, []
	for y in range(H):
		if STAGE[y][x] == ".":
			count += 1
		else:
			if 0 < count:
				line += [count] * count
			line += [0]
			count = 0
	else:
		if 0 < count:
			line += [count] * count
	sum_s[1] += [line]
"""
for line in sum_s[0]:
	print(*line)
print()
for line in sum_s[1]:
	print(*line)
"""
max_score = 0
for y in range(H):
	for x in range(W):
		max_score = max(max_score, sum_s[0][y][x] + sum_s[1][x][y] - 1)

print(max_score)
### BUGGY CODE ###

import collections

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

ans = 0
for i in range(1000):
    key = str(i).zfill(3)
    k = 0
    for j in range(len(s)):
        if key[k] == s[j]:
            k += 1
        if k == 3:
            ans += 1
            break
print(ans)


### FIXED CODE ###

n = int(input())
s_list = list(input())

ans = 0
for i in range(1000):
    key = str(i).zfill(3)
    k = 0
    t = key[k]
    for s in s_list:
        if t == s:
            k += 1
            if k == 3:
                ans += 1
                break
            t = key[k]
print(ans)
### BUGGY CODE ###

import queue
INF = 100000000

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

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

def bfs(sx, sy, gx, gy):
    d = [[INF for i in range(W)] for j in range(H)]
    d[sx][sy] = 0

    q = queue.Queue()
    q.put([sx, sy])

    while not q.empty():
        p = q.get()
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]
            if (0 <= nx) & (nx < H) & (0 <= ny) & (ny < W):
                if (S[nx][ny] != "#") & (d[nx][ny] == INF):
                    d[nx][ny] = min(d[nx][ny], d[p[0]][p[1]] + 1)
                    q.put([nx, ny])

    if d[gx][gy] == INF:
        return 0
    else:
        return d[gx][gy]

res = 0
for sx in range(H):
    for sy in range(W):
        for gx in range(H):
            for gy in range(W):
                res = max(res, bfs(sx, sy, gx, gy))

print(res)


### FIXED CODE ###

import queue
INF = 100000000

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

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

def bfs(sx, sy):
    d = [[-1 for i in range(W)] for j in range(H)]
    d[sx][sy] = 0
    max_d = 0

    q = queue.Queue()
    q.put([sx, sy])

    while not q.empty():
        p = q.get()
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]
            if (0 <= nx) & (nx < H) & (0 <= ny) & (ny < W):
                if (S[nx][ny] != "#") & (d[nx][ny] == -1):
                    d[nx][ny] = d[p[0]][p[1]] + 1
                    q.put([nx, ny])
                    max_d = max(max_d, d[nx][ny])

    return max_d

res = 0
for sx in range(H):
    for sy in range(W):
        if S[sx][sy] == ".":
            res = max(res, bfs(sx, sy))

print(res)
### BUGGY CODE ###

# from sys import stdin, stdout
def helper(weights,values,n,capacity,memo):
    if(capacity==0 or n==0):
        return 0
    if((n,capacity) in memo):
        return memo[(n,capacity)]
    if(weights[n-1]<=capacity):
        memo[(n,capacity)]=max(values[n-1]+helper(weights,values,n-1,capacity- weights[n-1],memo),helper(weights,values,n-1,capacity,memo))
        return memo[(n,capacity)]
    memo[(n,capacity)]=helper(weights,values,n-1,capacity,memo)
    return memo[(n,capacity)]
n,capacity=map(int,input().split())
weights=[0]*n
values=[0]*n
for i in range(n):
    weights[i],values[i]=map(int,input().split())

memo={}
print(helper(weights,values,n,capacity,memo))

### FIXED CODE ###

n,capacity=map(int,input().split())
weights=[0]*n
values=[0]*n
for i in range(n):
    weights[i],values[i]=map(int,input().split())
maxValue=sum(values)
dp=[[float("inf")]*(maxValue+1) for i in range(n+1)]
for i in range(n+1):
    dp[i][0]=0

for i in range(1,n+1):
    for j in range(1,maxValue+1):
        if(values[i-1]<=j):
            dp[i][j]=min(weights[i-1]+dp[i-1][j- values[i-1]],dp[i-1][j])
        else:
            dp[i][j]=dp[i-1][j]

ans=0
for i in range(maxValue+1):
    if(dp[n][i]<=capacity):
        ans=i
print(ans)
### BUGGY CODE ###

n,m = map(int,input().split())
lst_l = []
lst_r = []
for _ in range(m):
    l,r = map(int,input().split())
    lst_l.append(l)
    lst_r.append(r)

count = 0
for i in range(n):
    if max(lst_l) <= i+1 <= min(lst_r):
        count += 1

print(count)

### FIXED CODE ###

n,m = map(int,input().split())
lst_l = []
lst_r = []
for _ in range(m):
    l,r = map(int,input().split())
    lst_l.append(l)
    lst_r.append(r)

max_l = max(lst_l)
min_r = min(lst_r)

count = 0
for i in range(n):
    if max_l <= i+1 <= min_r:
        count += 1

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

N = int(input())

nums = [0]*N
for i in range(0, N):
    nums[i] = int(input())

for i in range (0, N):
    test = nums[:i] + nums[i+1:]
    print(max(test))

### FIXED CODE ###

N = int(input())
no_1 = 0
pos_1 = 0
no_2 = 0
for i in range(0, N):
    num = int(input())
    
    if no_1 <= num:
        no_2 = no_1
        no_1 = num
        pos_1 = i
        
    elif no_2 < num:
        no_2 = num
    
for i in range (0, N):
    if i == pos_1:
        print(no_2)
    else:
        print(no_1)