peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
N = int(input())
A = list(map(int,input().split()))
U = [0]*(10**6+1)
for e in A:
    U[e] += 1
ans = 0
for k in range(1,10**6+1):
    if U[k] == 1:
        ans += 1
    if U[k] > 0:
        for l in range(2*k,10**6+1,k):
            if U[l] > 0:
                U[l] += 1
print(ans)
# Judge status: Accepted
n = int(input())
p = list(map(int, input().split()))
cnt = 0

for i in range(n-1):
    if p[i] == i+1:
        p[i], p[i+1] = p[i+1], p[i]
        cnt += 1
if p[n-1] == n:
    p[n-2], p[n-1] = p[n-1], p[n-2]
    cnt += 1

print(cnt)
# Judge status: Wrong Answer
a = int(input())
for i in range(4):
    e = int(input())
k = int(input())
if e - a <= 15:
    print('Yay!')
else:
    print(':(')
# Judge status: Accepted
import heapq
n,m = map(int,input().split())
al = [[] for i in range(10**5)]
ans = 0
h = []
for i in range(n):
    a,b = map(int,input().split())
    al[a-1] += [-b]
for i in range(m):
    for j in al[i]:
        heapq.heappush(h,j)
    if h:
        ans -= heapq.heappop(h)
print(ans)
# Judge status: Accepted
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
aa = []
bb = []
for _ in range(n):
    a, b = map(int, readline().split())
    aa.append(a)
    bb.append(b)
aa.sort()
bb.sort()
if n % 2 == 1:
    print(bb[n // 2] - aa[n // 2] + 1)
else:
    print(bb[n // 2] + bb[n // 2 - 1] - aa[n // 2] - aa[n // 2 - 1] + 1)
# Judge status: Accepted
n = int(input())
a = [int(input()) for _ in range(n)]
a.append(0)
ans = 0
for i in range(n):
    p,r = divmod(a[i],2)
    ans += p
    if a[i+1]: a[i+1] += r
print(ans)
# Judge status: Accepted
p = [int(input()) for i in range(5)]
k = int(input())
if p[4]-p[0]<=k: print('Yay!')
else: print(':(')
# Judge status: Accepted
n = int(input())
c = []
for i in range(1, n//2 +1):
    a = sum(map(int, str(i)))
    b = sum(map(int, str(n-i)))
    c.append(a+b)
print(min(c))
# Judge status: Accepted
n = int(input())
w = list(map(int, input().split()))
ans = []
for i in range(n+1):
    s1 = sum(w[:i])
    s2 = sum(w[i:])
    ans.append(abs(s1 - s2))
print(min(ans))
# Judge status: Accepted
from collections import Counter
N=int(input())
S=Counter([input() for i in range(N)])
M=int(input())
T=Counter([input() for i in range(M)])
ans=0
for key in S.keys():
    ans = max(S.get(key)-T.get(key,0),ans)
print(ans)
# Judge status: Wrong Answer
n = int(input())
num2alpha = lambda c: chr(c+64)
ans = []

while True:
    if n == 0:
        break

    i = n%26
    n = int(n/26)

    ans.append(num2alpha(i))

ans.reverse()
print("".join(ans).lower())
# Judge status: Accepted
A,B=map(int, input().split())
N=0
while(1+(A-1)*N<B):
  N+=1
  
print(N)
# Judge status: Accepted
n = int(input())
lst1 = list(map(int,input().split()))

i = 0
ans = 0
flag = 0
while True:
    if i+1 == lst1[i]:
        if i+1 == 1:
            ans += 1
            i += 2
        elif i+1 == n:
            ans += 1
            flag = 1
        else:
            ans += 1
            i += 2
    else:
        i+=1
    if flag or i >= n:
        break

print(ans)
# Judge status: Accepted
import math

a, b, x = map(int, input().split())
if 2 * x <= (a ** 2) * b:
    print(math.degrees(math.atan((a * (b ** 2)) / (2 * x))))
else:
    print(math.degrees(math.atan((2 / a) * (b - (x / a ** 2)))))
# Judge status: Accepted
n=int(input())
s=input()

ans=s[1:].count('E')
pin=ans

for i in range(1,n):
  if s[i-1]=='W':
    pin+=1
  if s[i]=='E':
    pin-=1
  ans=min(ans,pin)
  
print(ans)
# Judge status: Wrong Answer
n=int(input())
a=list(map(int,input().split()))
b=a
k=1
for i,j in enumerate(a,1):
  b[j-1]=i
print(*b)
# Judge status: Accepted
import bisect      
    
n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

A.sort()
B.sort()
C.sort()

count = 0

for b in B:
    
    c_num = len(C)-bisect.bisect_left(C,b+1)
    a_num = bisect.bisect_right(A,b-1)
    count+=c_num*a_num

print(count)
# Judge status: Accepted
X = int(input())
ans = 10 - X // 200
print(ans)
# Judge status: Accepted
o = input()
e = input()
k = []

for i in range(len(e)):
    k.append(o[i])
    k.append(e[i])

if len(o) > len(e):
    k.append(o[-1])

print(''.join(k))
# Judge status: Wrong Answer
a, b = map(int, input().split())

if a >= 13:
  print(b)
elif 6 <= a <= 12:
  print(b/2)
else:
  print(0)
# Judge status: Accepted
n = int(input())
print(int(0.5*n*(n+1)))
# Judge status: Accepted
n = int(input())
sp = []
for i in range(n):
    city, point = input().split()
    sp.append([city, int(point), int(i+1)])

sp.sort(key=lambda x: x[1], reverse=True)
sp.sort(key=lambda x: x[0])
for i in sp:
    print(i[2])
# Judge status: Accepted
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
B.sort()
C=list(map(int,input().split()))
C.sort()
from bisect import bisect_right
ret=0
Cb=[0]*(N+1)
for i in range(N):
  Cb[i]=N-bisect_right(C,B[i])
for i in range(N-1,-1,-1):
  Cb[i]+=Cb[i+1]
for a in A:
  bi=bisect_right(B,a)
  ret+=Cb[bi]
print(ret)
# Judge status: Accepted
import math
A, B, K = map(int, input().split())


def divisors(n):
    ret = set()
    for i in range(1, math.ceil(n**0.5) + 1):
        if n % i == 0:
            ret.add(i)
            ret.add(n//i)
    return ret


a = sorted(list(divisors(A) & divisors(B)))
print(a[-K])
# Judge status: Accepted
s = input()
n = len(s)
for i in range(2,n,2):
  if s[0:(n-i)//2] == s[(n-i)//2:n-i]:
    print(len(s[0:n-i]))
    break
# Judge status: Wrong Answer
def str_replace_to_lower() -> str:
    len_str, target_index = map(int, input().split())
    word = input()

    new = word.replace(word[target_index - 1], word[target_index - 1].lower(), 1)
    return new


print(str_replace_to_lower())
# Judge status: Wrong Answer
N=int(input())
S=input()
cntl=0
cntr=0
flag=0
for s in S:
    if cntr == 0 and cntl == 0: flag = 0
    if s==")" and cntr==0: cntl += 1
    elif s==")" and cntr>0 and flag:
        cntr -= 1
        if cntl > 0: cntl-= 1
    elif s=="(": 
        cntr += 1
        if flag == 0: flag = 1
    elif s=="(" and cntl>0 and flag: 
        cntl -= 1
        if cntr > 0: cntr -= 1
print(cntl, cntr)
print("("*cntl + S + ")"*cntr)
# Judge status: Accepted
A,B,K=list(map(int,input().split()))
if A>K:
    print(A-K,B)
elif A+B>K:
    print(0,A+B-K)
else:
    print(0,0)
# Judge status: Accepted
s=input()
t=input()
if s==t[:-1]:
  print("Yes")
else:
  print("No")
# Judge status: Accepted
import math
import sys

n, a, b = map(int, sys.stdin.readline().rstrip().split())

if (n - 1) * b + a - (n - 1) * a - b + 1 < 0:
    print(0)
else:
    print((n - 1) * b + a - (n - 1) * a - b + 1)
# Judge status: Wrong Answer
N, K = map(int, input().split())

ans = 0
for i in range(K, N+2):
  ans += int(K * (N-K+1) + 1)
  
print(ans)
# Judge status: Accepted
N=int(input())
num1=0
am=0
a2=0
for x in range(N):
  a=int(input())
  if am<a:
    a2=am
    num1=x
    am=a
  elif a2<a:
    a2=a
for y in range(N):
  if y==num1:
    print(a2)
  else:
    print(am)
# Judge status: Accepted
import math
a,b=map(int,input().split())
int(a)
int(b)
c=a*b
int(c)
if a==1 or b==1:
    print(1)
elif c%2==0:
    d = c/2
    print(int(d))
else:
    d = math.floor(c/2) + 1
    print(int(d))
# Judge status: Accepted
N = int(input())
A = [0]+list(map(int, input().split()))

l = -1
ans = "Yes"
for i in range(1, N+1):
    if A[i] > A[i-1]:
        A[i] -= 1
    elif A[i] == A[i-1]:
        continue
    else:
        ans = "No"
print(ans)
# Judge status: Accepted
N = int(input())
ans = [0] * (N + 1)   

for i in range(1, 100):
    for j in range(1, 100):
        for k in range(1, 100):
            a = i**2 + j**2 + k**2 + i*j + j*k + k*i
            if a <= N:
                ans[a]+=1
                
for i in range(1, N+1):
    print(ans[i])
# Judge status: Wrong Answer
x = int(input())
res = 1
for b in range(2, int(pow(1000, 1/2))+1):
    flag = True
    p = 2
    while b**p <= x and flag:
        p += 1
        flag = False
    if not flag: res = max(res, b**(p-1))
print(res)
# Judge status: Accepted
dic = {}
dic1 = {}
s=input()
t=input()
ans = "Yes"
for i in range(len(s)):
  try:
    if dic[s[i]]!=t[i]:
      ans = "No"
  except:
    dic[s[i]] = t[i]
  try:
    if dic1[t[i]]!=s[i]:
      ans = "No"
  except:
    dic1[t[i]] = s[i]
print(ans)
# Judge status: Accepted
n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))
now=0
c=0
while True:
    if now==1:
        print(c)
        break
    if c>=n:
        print(-1)
        break
    c+=1
    now=a[now]-1
# Judge status: Accepted
#import sys
#import math
#import numpy as np

'''a,b= map(int,input().split())'''
#a, b, c = [list(map(int, input().split())) for _ in range(3)]
#li0= [int(x) for x in input().split()]
#n,l= map(int, input().split())
#x = [list(map(int, input().split())) for _ in range(n)] 
a=int(input())
li=[int(x) for x in input().split()]
ans=ju=0
for i in range(a):
  ju=max(ju,li[i])
ans=sum(li)-ju
if ans-ju>0:
  print('Yes')
else:
  print('No')
# Judge status: Accepted
N,C,K = map(int,input().split())
T = [int(input()) for i in range(N)]

T.sort()

ans = 1
bus = [T[0]]
l = 1
for i in range(1,N):
    if T[i]-bus[0] <= K and l <= C-1:
        l += 1
    else:
        bus = [T[i]]
        l = 1
        ans += 1
print(ans)
# Judge status: Accepted
n = int(input())

ans = 1
cnt = 0
for i in range(1, n + 1):
    count = 0
    temp = i
    while temp % 2 == 0:
        count += 1
        temp //= 2

    if cnt < count:
        cnt = count
        ans = i

print(ans)
# Judge status: Accepted
a, b, c = map(int, input().split())
x = b//a
if x > c:
    x = c
print(x)
# Judge status: Accepted
import sys


def input():
    return sys.stdin.readline()[:-1]

s = input()
n = len(s)
if s[:(n-1)//2] == s[(n+3)//2-1:]:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
n = input()
 
if n in "7":
  print("Yes")
elif n not in "7":
  print("No")
# Judge status: Accepted
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = list(map(int, input().split()))
m = 0
for i in range(n):
    if a[i]<m:
        print("No")
        break
    m = max(m, a[i]-1)
else:
    print("Yes")
# Judge status: Wrong Answer
S = input()
T = input()

ans = 0
for i in range(len(S)-1):
    if S[i] != T[i]:
        ans += 1

print(ans)
# Judge status: Accepted
n,q=map(int,input().split())
s=input()
c=[0 for _ in range(n)]
p=''
d=0
for i in range(n):
  x=s[i]
  if p=='A' and x=='C':
    d+=1
  p=x
  c[i]=d
for i in range(q):
  ans=0
  l,r=map(int,input().split())
  ans=c[r-1]-c[l-1]

  print(ans)
# Judge status: Wrong Answer
n,k = map(int,input().split())
a = list(map(int,input().split()))
now = 1
x = 0
ss = set([1])
for i in range(k):
    now = a[now-1]
    ss.add(now)
    if len(ss) != i+2:
        x = 1
        break
if x == 1:
    aa = k%len(ss)
    for i in range(aa):
        now = a[now-1]
print(now)
# Judge status: Wrong Answer
x=int(input())

x1=x//100
x2=(x%100)//10
x3=x%10

if(x1==7 or x2==7 or x3==7):
  print("yes")
else:
  print("no")
# Judge status: Accepted
n,k = map(int,input().split())
l = list(map(int,input().split()))

cnt = 1
while n > 0:
    n -= k
    if n > 0:
        n += 1
        cnt += 1
print(cnt)
# Judge status: Accepted
x,y = list(map(int, input().split()))

if (x+y) % 3 != 0:
    print(0)
    exit()

a = (2*x - y) // 3
b = (2*y - x) // 3

if a < 0 or b < 0:
    # (x,y) = (1,5)とかは無理
    print(0)
    exit()
    
MOD = 10**9+7
def fact(x):
    f = 1
    for i in range(2, x+1):
        f *= i
        f %= MOD
    return f

def fact_inv(x):
    return pow(fact(x), MOD-2, MOD)

ans = fact(a+b) * fact_inv(a) * fact_inv(b) % MOD

print(ans)
# Judge status: Accepted
x,y=map(int,input().split())
if x%y==0:
    print(-1)
else:
    print(x)
# Judge status: Wrong Answer
S = int(input())
a = 2*S // 1000000000
for i in range(a + 1, 1000000000):
    if S%i == 0:
        print(0,0,0,i,S//i,0)
        break
# Judge status: Accepted
s = input()

a = -1
c = -1
lower = 0
for i in range(len(s)):
  if s[i] == 'A':
    a = i
  if s[i] == 'C':
    c = i
  if 'a' <= s[i] <= 'z':
    lower += 1

if a == 0 and 2 <= c <= len(s) - 2 and lower == len(s) - 2:
  print('AC')
else:
  print('WA')
# Judge status: Accepted
import itertools
import bisect
n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))

*per, = itertools.permutations(range(1, n+1))

a = bisect.bisect_right(per, p)
b = bisect.bisect_right(per, q)

print(abs(a-b))
# Judge status: Wrong Answer
import sys
from collections import defaultdict
def input(): return sys.stdin.readline().strip()

def main():
    N = int(input())
    S = input()
    height = 0
    deepest = 0
    for c in S:
        if c == '(':
            height += 1
        else:
            height -= 1
        deepest = min(deepest, height)
    print(deepest, height)
    ans = '(' * (-deepest) + S + ')' * (height - deepest)
    print(ans)

if __name__ == "__main__":
    main()
# Judge status: Accepted
import sys
input = sys.stdin.buffer.readline

def main():
    N,A,B = map(int,input().split())
    if A == B:
        print(1)
    elif A > B:
        print(0)
    else:
        if N == 1:
            print(0)
        elif N == 2:
            print(1)
        else:
            print(((N-1)*B+A)-((N-1)*A+B)+1)

if __name__ == "__main__":
    main()
# Judge status: Accepted
n  = int(input())

d = {}
for _ in range(n):
    string = "".join(sorted(list(input())))
    if string not in d:
        d[string] = 1
    else:
        d[string] += 1

ans = 0
for v in d.values():
    ans += v*(v-1)//2

print(ans)
# Judge status: Accepted
s=input()
if s[0]==s[1] and s[2]==s[3] and s[0]!=s[2]:
  print("Yes")
elif s[0]==s[2] and s[1]==s[3] and s[0]!=s[1]:
  print("Yes")
elif s[0]==s[3] and s[1]==s[2] and s[0]!=s[1]:
  print("Yes")
else:
  print("No")
# Judge status: Accepted
S = int(input())
x = (-S)%(10**9)
y = (S+x)//(10**9)
print(0,0,10**9,1,x,y)
# Judge status: Wrong Answer
n, m = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
between = [x[i] - x[i-1] - 2 for i in range(1,m)]
between.sort(reverse=True)
print(max(0, x[-1] - x[0] - sum(between[:n-1]) - n))
# Judge status: Accepted
if __name__ == "__main__":
    l = int(input())
    l1 = l / 3
    print(l1 ** 3)
# Judge status: Accepted
a = int(input())
b = int(input())
h = int(input())

s = 0
if 1 <= a <= 100 and 1 <= b <= 100 and 1 <= h <= 100 and h % 2 == 0:
  s = (a + b) * h / 2
  print(int(s))
# Judge status: Accepted
sx, sy, tx, ty = map(int, input().split())

tx = tx - sx
ty = ty - sy

ans = "" 
ans += "U" * ty
ans += "R" * tx
ans += "D" * ty
ans += "L" * tx
ans += "L"
ans += "U" * (ty + 1)
ans += "R" * (tx + 1)
ans += "D"
ans += "R"
ans += "D" * (ty + 1)
ans += "L" * (tx + 1)
ans += "U"

print(ans)
# Judge status: Accepted
import fractions
from functools import reduce
 
n = int(input())
a = list(map(int,input().split()))
 
#累積GCD
left = [0] * (n + 1)
right = [0] * (n + 1)
for i in range(n):
    left[i + 1] = (fractions.gcd(left[i],a[i]))
    right[n - i - 1] = (fractions.gcd(right[n - i],a[n - 1 - i]))
 
ans = 0
for i in range(n):
    ans = max(ans,fractions.gcd(left[i],right[i + 1]))
print(ans)
# Judge status: Accepted
import bisect
def make_divisors(N):
    divisors = []
    for i in range(1, int(N**0.5)+1):
        if N % i == 0:
            divisors.append(i)
            if i != N // i:
                divisors.append(N//i)
    divisors.sort()
    return divisors
N, M = map(int, input().split())
lst = make_divisors(M)
print(lst[bisect.bisect_right(lst, M//N)-1])
# Judge status: Accepted
n=int(input())
if n==0:
    print(0)
    exit()

ans=""
while n:
    if n%2:
        ans+=str(1)
        n-=1
    else:
        ans+="0"
    n//=-2
print(ans[::-1])
# Judge status: Accepted
A, B, C = list(map(int, input().split()))
clear = 0

for i in range(1, B):
    if (A * i) % B == C:
        clear = 1
        break

if clear == 0:
    print('NO')
else:
    print('YES')
# Judge status: Accepted
S = input()
D = 0

if len(S)%2 != 0:
    print("No")
    D = 1
    
else:
    for i in range(len(S)//2):
        if ((S[i * 2] == "h") & (S[(i * 2) + 1] == "i")) != True:
            print("No")
            D = 1
            break
        
if D == 0:
    print("Yes")
# Judge status: Wrong Answer
s = list(input())
t = list(input())

for i in s:
    if i in t:
        t.remove(i)
if not t:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
n, m = map(int, input().split())

s = [0] * n
s[0] = 1
b = [1] * n
for i in range(m):
    x, y = map(int, input().split())
    if s[x-1]:
        s[y-1] = 1
    if b[x-1] == 1:
        s[x-1] = 0
    b[x-1] -= 1
    b[y-1] += 1

ans = 0
for i in range(n):
    if s[i] and b[i]:
        ans += 1

print(ans)
# Judge status: Accepted
import sys
import math
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

a,b,h,m = map(int,readline().split())

degree = abs(h*30+30*(m/60) - m*6)
degree = min(degree,360-degree)
print(math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(degree))))
# Judge status: Wrong Answer
a=int(input())
b=input()
if a>=3200:
    print(b)
else:
    print('RED')
# Judge status: Accepted
a, b = map(int, input().split())

if b >= a:
    print(a)
elif a > b:
    print(a-1)
else:
    print(b)
# Judge status: Accepted
N,D=map(int,input().split())
XY= [input().split() for _ in range(N)]
ans=0
for i in XY:
    A=(int(i[0])**2+int(i[1])**2)**(1/2)
    if A<=D:
        ans+=1
print(ans)
# Judge status: Accepted
n, m = list(map(int, input().split()))

if 2 * n >= m:
    print(m // 2)
else:
    print(n + (m-(2*n))//4)
# Judge status: Accepted
a,b = map(int,input().split())
print('Yay!' if a <= 8 and b <= 8 else ':(')
# Judge status: Accepted
a, b = (int(i)for i in input().split())
ans =0
d = 1
while d<b:
  ans+=1
  d = d-1+a
print(ans)
# Judge status: Accepted
n,a,b=map(int,input().split())
if (b-a)%2==0:
  print((b-a)//2)
else:
  x=(a+b-1)//2
  l=[x,n-x]
  print(min(l))
# Judge status: Accepted
x, a, b = map(int, input().split())

if abs(x - a) > abs(x - b):
	print("B")
else:
	print("A")
# Judge status: Accepted
N = int(input())
cmin = 1000
for i in range(1,N):
    a = str(i)
    cnt = 0
    for j in range(len(a)):
        cnt += int(a[j])
    b = str(N-i)
    for j in range(len(b)):
        cnt += int(b[j])
    cmin = min(cmin,cnt)
print(cmin)
# Judge status: Accepted
a, v = map(int,input().split())
b, w = map(int,input().split())
t = int(input())
if abs(a-b) <= (v-w)*t :
    print("YES")
else:
    print("NO")
# Judge status: Wrong Answer
a, b = map(int, input().split())
print('Yay!') if(a < 9 or b < 9) else print(':(')
# Judge status: Accepted
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
scores = {'r':p, 's':r, 'p':s}
ans = 0
for i in range(k):
    ans += scores[t[i]]
    flg = False
    for j in range(i+k, n, k):
        if (not flg) and t[j]==t[j-k]:
            flg = True
            continue
        flg = False
        ans += scores[t[j]]
print(ans)
# Judge status: Accepted
n = int(input())
s = input()
t = input()

if s == t:
  print(n)
  exit()

ans = ''
for i in range(n):
  ss = s[n-i-1:]
  tt = t[:i+1]
  if ss == tt:
    ans = s[:n-i-1]+ss+t[i+1:]
if len(ans) == 0:
  print(len(s+t))
else:
  print(len(ans))
# Judge status: Wrong Answer
t = input()

stack = ''
ans = ''
for i in range(len(t)):
    word = t[i]
    if word == '?':
        if len(stack) <= 0:
            word = 'P'
        elif stack[-1] == 'P':
            word = 'D'
        elif stack[-1] == 'D' and i < len(t)-1 and t[i+1] == 'P':
            word = 'D'
        else:
            word = 'D'

    stack += word
    if 'PD' in stack or 'DD' in stack:
        ans += stack
        stack = ''

ans += stack
print(ans)
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))

a_min = min(a)
a_max = max(a)

a_sum = []
for i in range(a_min, a_max + 1):
    num=0
    for j in range(n):
        num += (a[j] - i) ** 2
    a_sum.append(num)
print(min(a_sum))
# Judge status: Accepted
n,k=map(int,input().split())
A=list(map(int,input().split()))
ans = [0]*(n)
for a in A:
  ans[a-1] += 1
ans.sort(reverse=True)
print(sum(ans[k:]))
# Judge status: Accepted
X = int(input())
l = -1
r = 10**10
while r - l > 1:
    m = l + (r-l)//2
    if m*(m+1)//2 > X:
        r = m
    else:
        l = m
    # print(l, m, r)
print(l if l*(l+1)//2 == X else r)
# Judge status: Accepted
from copy import deepcopy


def main():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    b = deepcopy(a)
    b.sort()
    for aa in a:
        if aa == b[-1]:
            print(b[-2])
        else:
            print(b[-1])


if __name__ == '__main__':
    main()
# Judge status: Accepted
N,K = map(int,input().split())

mod = 10**9+7
ans = 0

for i in range(K,N+2):
    min = (0+i-1)*i//2
    max = (N+N-i+1)*i//2
    
    ans += (max-min+1)%mod
    
print(ans%mod)
# Judge status: Wrong Answer
A,B,C,D=map(int,input().split())
p=min(C,D)-max(A,B)
if p<=0:
  print(0)
else:
  print(p)
# Judge status: Wrong Answer
n, x, t = map(int, input().split())
a = n/x
if n % x == 0:
  print(a*t)
else:
  print((int(a) + 1)*t)
# Judge status: Accepted
from math import pi
R = int(input())
print(R * 2 * pi)
# Judge status: Wrong Answer
a=input()
b=input()
la,lb = len(a), len(b)
if a==b:
    print('No')
elif (la< lb and set(a)==set(b)):
    print('Yes')
else:
    if (sorted(a[:lb], reverse = True) < sorted(b, reverse = True)):
        print('Yes')
    else:
        print('No')
# Judge status: Accepted
# coding: utf-8
N=int(input())

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

sA=[A[0]]
siA=[A[-1]]

for i in range(N-1):
    sA.append(sA[i]+A[i+1])
    siA.append(siA[i]+A[-(i+2)])

ans=10**15

for i in range(N-1):
    ans=min(ans,abs(sA[i]-siA[-(i+2)]))

# print(sA,siA)

print(ans)
# Judge status: Accepted
import math
import os
import random
import re
import sys

def check_non_decreasing_squares(n: int, a: list):
    for i in range(1, n):
        if a[i] != a[i - 1]:
            if a[i] - 1 < a[i - 1]:
                print("No")
                sys.exit(0)
            a[i] -= 1
    print("Yes")

if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().rstrip().split()))
    check_non_decreasing_squares(n, a)
# Judge status: Accepted
a,b,c=map(int,input().split())
print("win" if a+b+c<=21 else "bust")
# Judge status: Accepted
n,k=map(int,input().split())
p=list(map(int,input().split()))
p=[(i+1)/2 for i in p]
ans=0
cur_sum=0
for i in range(0,k):
  cur_sum+=p[i]
ans=cur_sum
for i in range(k,n):
  cur_sum+=p[i]
  cur_sum-=p[i-k]
  ans=max(ans,cur_sum)
print(ans)
# Judge status: Accepted
s = input()
if s[2] == s[3] and s[4] == s[5]:
  print("Yes")
else:
  print("No")
# Judge status: Accepted
x, y = map(int, input().split())
ans = 0
while True:
    if x > y:
        break
    ans += 1
    x *= 2
print(ans)
# Judge status: Accepted
a = int(input())

ans = a + a**2 + a**3

print(ans)
# Judge status: Accepted
n,k,q = map(int,input().split())
ans = [0]*n
for i in range(q):
    ans[int(input())-1] += 1
for i in range(n):
    dum = q - ans[i]
    if k-dum >0:
        print("Yes")
    else:
        print("No")
# Judge status: Accepted
x, y = map(int, input().split())
diff = abs(x - y)
ref = (min(x, y) - diff)//3
total = ref*2 + diff
mod = 10**9 + 7
ans = 1

if (x + y)%3 != 0 or ref < 0:
    print(0)
    exit()


for i in range(min(ref, total - ref)):
    ans = ans*(total - i)%mod
    ie = pow((i + 1), (mod - 2), mod)
    ans = ans*ie%mod

print(ans)
# Judge status: Wrong Answer
S = input()
C = [S.count('a'), S.count('b'), S.count('c')]
if (len(set(list(S))) == 3 and max(C) - min(C) < 2) or len(S) == 1:
    print('YES')
else:
    print('NO')
# Judge status: Accepted
A, B, C = map(int, input().split())

print(min(B//A, C))
# Judge status: Wrong Answer
N, M = map(int, input().split())

id_range = range(N + 1)

for m in range(M):
  L, R = map(int, input().split())
  if (L not in id_range) and (R not in id_range):
    id_range = range(0)
    break
  if L in id_range:
    id_range = range(L, id_range[len(id_range) - 1] + 1, 1)
  if R in id_range:
    id_range = range(id_range[0], R + 1, 1)
    
id_set = set(id_range)
print(len(set(range(1, N + 1, 1)) & id_set))