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

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

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

mylist.sort(reverse=True)


mysum = sum(mylist)

mycnt = 1
while mycnt <= M:
    mylist[mylist.index(max(mylist))] = max(mylist)//2
    #print(mylist[mylist.index(max(mylist))])
    mycnt += 1

mysum = sum(mylist)


    

print(mysum)


### FIXED CODE ###

import heapq
 
N,M = map(int,input().split())
 
A = [int(i)*-1 for i in input().split()]


heapq.heapify(A)
 
#print(A)

for _ in range(M):
  max = heapq.heappop(A) * -1
  #print(max, A)
  
  heapq.heappush(A,(max//2)*-1)
  
  #print(A)
 
print(sum(A)*-1)
### BUGGY CODE ###

s = input()

mod = 10**9 + 7
l = len(s)
dp = [[0] * 13 for _ in range(l+1)]
dp[0][0] = 1
for i in range(1, l+1):
    if s[i-1] == '?':
        for j in range(10):
            for k in range(13): 
                dp[i][(k * 10 + j) % 13] = (dp[i][(k * 10 + j) % 13] + dp[i-1][k]) % mod
    else:
        for k in range(13):
            dp[i][(k * 10 + int(s[i-1])) % 13] = (dp[i][(k * 10 + int(s[i-1])) % 13] + dp[i-1][k]) % mod
print(dp[l][5])

### FIXED CODE ###

s = input()

mod = 10**9 + 7
l = len(s)
dp = [[0] * 13 for _ in range(l+1)]
dp[0][0] = 1
for i in range(1, l+1):
    if s[i-1] == '?':
        for j in range(10):
            for k in range(13): 
                dp[i][(k * 10 + j) % 13] = (dp[i][(k * 10 + j) % 13] + dp[i-1][k]) % mod
    else:
        for k in range(13):
            dp[i][(k * 10 + int(s[i-1])) % 13] = (dp[i][(k * 10 + int(s[i-1])) % 13] + dp[i-1][k]) % mod
print(dp[l][5])
### BUGGY CODE ###

n, k = map(int, input().split())
h = list(map(int, input().split()))
inf = 10 ** 10
dp = [inf for _ in range(n)]
dp[0] = 0
for i in range(1, n):
    for j in range(1, k+1):
        if i - j >= 0:
            dp[i] = min(dp[i], dp[i-j] + abs(h[i] - h[i-j]))
#print(dp)
print(dp[n-1])

### FIXED CODE ###

n, k = map(int, input().split())
h = list(map(int, input().split()))
inf = 10 ** 10
dp = [inf for _ in range(n)]
dp[0] = 0
for i in range(1, n):
    for j in range(1, k+1):
        if i - j >= 0:
            dp[i] = min(dp[i], dp[i-j] + abs(h[i] - h[i-j]))
#print(dp)
print(dp[n-1])
### BUGGY CODE ###

lis=list(map(int,input().split()))
bef=0
bbef=0
ans=0
while lis[0]>=0:
  bbef=bef
  bef=lis[0]
  lis[0]=abs(lis[0]-lis[1])
  if bbef==lis[0]:
    if bef>=lis[0]:
      print(lis[0])
      break
    else:
      print(bef)
      break


### FIXED CODE ###

lis=list(map(int,input().split()))
if lis[0]%lis[1]<=lis[1]/2:
  print(lis[0]%lis[1])
else:
  print(lis[1]-lis[0]%lis[1])
### BUGGY CODE ###

import sys
#input = sys.stdin.readline

def main():
    N = int(input())
    s = [list(map(str,input())) for _ in range(N)]
    s += s
    ans = 0
    for i in range(N):
        b = True
        for x in range(N):
            for y in range(x,N):
                if s[x+i][y] != s[y+i][x]:
                    b = False
        if b:
            ans += N
    
    print(ans)

if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys
#input = sys.stdin.readline
import numpy as np

def main():
    N = int(input())
    s = [list(map(str,input())) for _ in range(N)]
    s = np.array(s)
    ans = 0
    for i in range(N):
        T = np.vstack((s[i:],s[:i]))
        if np.all(T==T.T):
            ans += N
            
    print(ans)

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

N, M = map(int, input().split())
a = [int(input()) for _ in range(M)]
D = 1000000007
dp = [1]*(N+1)
for i in a:
    dp[i] = 0
for i in range(2, len(dp)):
    if i in a:
        continue
    dp[i] = dp[i-1] + dp[i-2]
print(dp[-1]%D)

### FIXED CODE ###

N, M = map(int, input().split())
a = [int(input()) for _ in range(M)]
D = 1000000007
dp = [1]*(N+1)
for i in a:
    dp[i] = 0
for i in range(2, len(dp)):
    if dp[i]==0:
        continue
    dp[i] = dp[i-1] + dp[i-2]
print(dp[-1]%D)
### BUGGY CODE ###

N = int(input())
ab = [list(map(int, input().split())) for _ in range(N - 1)]
M = int(input())
uv = [list(map(int, input().split())) for _ in range(M)]

class Tree:
  C, RL = {}, {}
  R, N, D, S, P = None, None, None, None, None
  def __init__(s, num):
    s.N = num
  def set(s, a, b):
    if a in s.C: s.C[a].append(b)
    else: s.C[a] = [b]
    if b in s.C: s.C[b].append(a)
    else: s.C[b] = [a]
  def dfs(s, x, y, r):
    if x == y:
      return [x]
    for i in s.C[x]:
      if i != r:
        t = s.dfs(i, y, x)
        if t != False:
          return [x] + t
    return False

T = Tree(N)
for a, b in ab:
  a -= 1
  b -= 1
  T.set(a, b)

ans = 1 << (N - 1)
c = 0
for i in range(1, 1 << M):
  t = i
  D = [[0] * N for _ in range(N)]
  cnt = 0
  f = 0
  for j in range(M):
    if t & 1:
      f += 1
      x, y, r = uv[j][0] - 1, uv[j][1] - 1, uv[j][0] - 1
      L = T.dfs(x, y, r)
      n = L[0]
      for k in range(1, len(L)):
        m = L[k]
        x, y = min(n, m), max(n, m)
        if D[x][y] == 0:
          cnt += 1
        D[x][y] += 1
        n = m
    t >>= 1
  if f % 2 == 1:
    c += pow(2, (N - 1 - cnt))
  else:
    c -= pow(2, (N - 1 - cnt))

print(ans - c)

### FIXED CODE ###

N = int(input())
ab = [list(map(int, input().split())) for _ in range(N - 1)]
M = int(input())
uv = [list(map(int, input().split())) for _ in range(M)]

class Tree:
  C, RL = {}, {}
  R, N, D, S, P = None, None, None, None, None
  def __init__(s, num):
    s.N = num
  def set(s, a, b):
    if a in s.C: s.C[a].append(b)
    else: s.C[a] = [b]
    if b in s.C: s.C[b].append(a)
    else: s.C[b] = [a]
  def dfs(s, x, y, r):
    if x == y:
      return [x]
    for i in s.C[x]:
      if i != r:
        t = s.dfs(i, y, x)
        if t != False:
          return [x] + t
    return False

T = Tree(N)
for a, b in ab:
  a -= 1
  b -= 1
  T.set(a, b)

D = [[-1] * N for _ in range(N)]
for i in range(N - 1):
  a, b = ab[i][0] - 1, ab[i][1] - 1
  a, b = min(a, b), max(a, b)
  D[a][b] = i

NL = [[] for _ in range(M)]
for i in range(M):
  x, y, r = uv[i][0] - 1, uv[i][1] - 1, uv[i][0] - 1
  L = T.dfs(x, y, r)
  n = L[0]
  t = 0
  for j in range(1, len(L)):
    m = L[j]
    x, y = min(n, m), max(n, m)
    t = t | (1 << D[x][y])
    n = m
  NL[i] = t
  

ans = 1 << (N - 1)
c = 0
for i in range(1, 1 << M):
  t = i
  f = 0
  k = 0
  for j in range(M):
    if t & 1:
      f += 1
      k = k | NL[j]
    t >>= 1
  cnt = bin(k).count("1")
  if f % 2 == 1:
    c += pow(2, (N - 1 - cnt))
  else:
    c -= pow(2, (N - 1 - cnt))
print(ans - c)
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
S=0
for i in range(N):
	S+=max(A[0:i+1])-A[i]
print(S) 

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
s=a[0]
ans=0
for i in range(n):
    if a[i]<s:
        ans+=s-a[i]
    else:
        s=a[i]
print(ans)
### BUGGY CODE ###

from heapq import heappush, heappop

X, Y, Z, K = map(int, input().split())
A = [int(s) for s in input().split()]
B = [int(s) for s in input().split()]
C = [int(s) for s in input().split()]
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
h = []

maxv = A[0] + B[0] + C[0]


def inv(v):
    return maxv - v


pushed = [[[False] * Z for _ in range(Y)] for _ in range(X)]
heappush(h, (0, 0, 0, 0))
for _ in range(K):
    invv, i, j, k = heappop(h)
    print(inv(invv))
    if i + 1 < X and not pushed[i + 1][j][k]:
        heappush(h, (inv(A[i + 1] + B[j] + C[k]), i + 1, j, k))
        pushed[i + 1][j][k] = True
    if j + 1 < Y and not pushed[i][j + 1][k]:
        heappush(h, (inv(A[i] + B[j + 1] + C[k]), i, j + 1, k))
        pushed[i][j + 1][k] = True
    if k + 1 < Z and not pushed[i][j][k + 1]:
        heappush(h, (inv(A[i] + B[j] + C[k + 1]), i, j, k + 1))
        pushed[i][j][k + 1] = True


### FIXED CODE ###

from heapq import heappush, heappop

X, Y, Z, K = map(int, input().split())
A = [int(s) for s in input().split()]
B = [int(s) for s in input().split()]
C = [int(s) for s in input().split()]
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
h = []

maxv = A[0] + B[0] + C[0]


def inv(v):
    return maxv - v


pushed = [[[] for _ in range(Y)] for _ in range(X)]
heappush(h, (0, 0, 0, 0))
for _ in range(K):
    invv, i, j, k = heappop(h)
    print(inv(invv))
    if i + 1 < X and k not in pushed[i + 1][j]:
        heappush(h, (inv(A[i + 1] + B[j] + C[k]), i + 1, j, k))
        pushed[i + 1][j].append(k)
    if j + 1 < Y and k not in pushed[i][j + 1]:
        heappush(h, (inv(A[i] + B[j + 1] + C[k]), i, j + 1, k))
        pushed[i][j + 1].append(k)
    if k + 1 < Z and k + 1 not in pushed[i][j]:
        heappush(h, (inv(A[i] + B[j] + C[k + 1]), i, j, k + 1))
        pushed[i][j].append(k + 1)
### BUGGY CODE ###

S = str(input())
N = len(S)

ans = 0
amari = [0] * 2019
follow = 0
for i in range(N):
  Amari_ = (int(int(S[N-i-1]) * pow(10, i)) + follow) % 2019
  amari[Amari_] += 1
  follow = Amari_
  if Amari_ == 0:
    ans += 1
  
for a in amari:
  ans += a * (a - 1) // 2
print(ans)

### FIXED CODE ###

S = str(input())
N = len(S)

ans = 0
amari = [0] * 2019
amari[0] = 1
follow = 0
POW = 1

for i in reversed(S):
  follow += int(i) * POW
  follow %= 2019
  amari[follow] += 1
  POW *= 10
  POW %= 2019
  
print(sum( i * (i-1) // 2 for i in amari ))
### BUGGY CODE ###

from collections import Counter

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

A_sort = sorted(set(A))
A_counter = Counter(A)
# print(A_sort)

res = 0
# res_list = []
for i in range(len(A_sort)):
    # print(A_sort[i], A_sort_tmp)
    if A_counter[A_sort[i]] >= 2:
        continue

    A_sort_tmp = A_sort[:i]
    for j in range(len(A_sort_tmp)):
        if A_sort[i] % A_sort_tmp[j] == 0:
            break
    else:
        res += 1
        # res_list.append(i + 1)

print(res)
# print(res_list)


### FIXED CODE ###

from collections import defaultdict

N = int(input())
A = list(map(int, input().split()))
A_sort = sorted(set(A))

bool_list = [True] * (10 ** 6 + 1)

duplicate_dic = defaultdict(int)
for a in A:
    duplicate_dic[a] += 1
    if duplicate_dic[a] > 1:
        bool_list[a] = False

for a in A_sort:
    for i in range(2*a, 10 ** 6 + 1, a):
        bool_list[i] = False

print(sum([1 for a in A_sort if bool_list[a]]))
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
input = sys.stdin.readline

MOD = (1 << 61) - 1
mod_pow = [1] * (10**6 + 10)
base = 1009

for i in range(10**6 + 1):
    mod_pow[i+1] = mod_pow[i] * base % MOD

class RollingHash():
    def __init__(self, s):
        self.length = len(s)
        self.base = 1009
        self.mod = (1 << 61) - 1
        self.hash = [0] * (self.length + 2)

        for i in range(self.length):
            self.hash[i+1] = (self.hash[i] + ord(s[i])) * self.base % self.mod

    def get(self, l, r):
        t = self.hash[r] - self.hash[l] * mod_pow[r-l] % self.mod
        return t % self.mod

ss = []
n = int(input())
for _ in range(n):
    ss.append(input().rstrip())
ss.sort(key=lambda x: len(x), reverse=True)

words = dict()
ans = 0
orda = ord("a")
for s in ss:
    word_len = len(s)
    s_rev = s[::-1]
    RH = RollingHash(s_rev)
    rh = RH.get(0, word_len-1)
    if rh in words:
        ans += words[rh][ord(s_rev[-1]) - orda]
    initial = set()
    for i, ch in enumerate(s):
        initial.add(ord(ch) - orda)
        for key in initial:
            rh = RH.get(0, word_len-i-1)
            if rh in words:
                words[rh][key] += 1
            else:
                words[rh] = [0] * 26
                words[rh][key] += 1
print(ans)

### FIXED CODE ###

#!/usr/bin/env python3
import sys
input = sys.stdin.readline
from collections import defaultdict

def empty_list():
    return [0] * 26

class RollingHash():
    def __init__(self, s):
        length = len(s)
        base = 1009
        # self.mod = (1 << 61) - 1
        self.mod = 67280421310721
        self.hash = [0] * (length + 2)
        self.pow = [1] * (length + 2)

        for i in range(length):
            self.hash[i+1] = (self.hash[i] + s[i]) * base % self.mod
            self.pow[i+1] = self.pow[i] * base % self.mod
        self.pow[length+1] = self.pow[length] * base % self.mod 

    def get(self, l, r):
        t = self.hash[r] - self.hash[l] * self.pow[r-l] % self.mod
        return t % self.mod

ss = []
n = int(input())
for _ in range(n):
    ss.append([ord(item) for item in input().rstrip()])
ss.sort(key=lambda x: len(x), reverse=True)

orda = ord("a")
words = defaultdict(empty_list)
ans = 0
for s in ss:
    word_len = len(s)
    s_rev = s[::-1]
    RH = RollingHash(s_rev)
    rh = RH.get(0, word_len-1)
    ans += words[rh][s_rev[-1] - orda]
    initial = [0] * 26 
    for i, ch in enumerate(s):
        initial[ch - orda] = 1
        for j, is_initial in enumerate(initial):
            if is_initial:
                rh = RH.get(0, word_len-i-1)
                words[rh][j] += 1
print(ans)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
bit_acc = [[0 for i in range(21)] for j in range(n+1)]
for i in range(1,n+1):
    k = format(a[i-1], '021b')
    for j in range(len(k)):
        if k[j] == "1":
            bit_acc[i][j] = bit_acc[i-1][j] + 1
        else:
            bit_acc[i][j] = bit_acc[i-1][j]
left = 0
ans = 0
while left <= n:
    last = n
    flag = False
    for right in range(left+1,n+1):
        for j in range(21):
            if bit_acc[right][j] - bit_acc[left][j] >= 2:
                last = right - 1
                flag = True
                break
        if flag:
            break
    #print("l {}, r {}".format(left, last))
    ans += last - left
    left += 1
print(ans)



### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
bit_acc = [[0 for i in range(21)] for j in range(n+1)]
for i in range(1,n+1):
    k = format(a[i-1], '021b')
    for j in range(len(k)):
        if k[j] == "1":
            bit_acc[i][j] = bit_acc[i-1][j] + 1
        else:
            bit_acc[i][j] = bit_acc[i-1][j]
right = 1
left = 0
ans = 0
while left <= n:
    flag = True
    for j in range(21):
        if bit_acc[right][j] - bit_acc[left][j] >= 2:
            #print("l {}, r {}".format(left, right))
            ans += right - 1 - left
            left += 1
            flag = False
            break
    if flag:
        if right < n:
            right += 1
        else:
            #print("l {}, r {}".format(left, right))
            ans += right - left
            left += 1
print(ans)
### BUGGY CODE ###

import sys
import heapq

def main():
  input = sys.stdin.readline
  n, m = map(int, input().split())
  s = input()
  
  inf = pow(10, 6)
  ans = [inf]*(n+1)
  key = []
  heapq.heapify(key)
  heapq.heappush(key, (0, n))
  ans[n] = 0
  index = n-1
  while key:
    sub = heapq.heappop(key)
    s1, s2 = sub[0], sub[1]
    subindex = s2
    for i in range(min([index, s2-1]), max([-1, s2-m-1]), -1):
      if ans[i] != inf:
        continue
      if s[i] == "1":
        continue
      heapq.heappush(key, (s1+1, i))
      ans[i] = s2
      subindex = i
    index = subindex
      
  
  if ans[0] == inf:
    print(-1)
  else:
    index = 0
    answer = []
    while True:
      subindex = ans[index]
      answer.append(subindex-index)
      if subindex == n:
        break
      index = subindex
  
    print(*answer)
  
if __name__ == "__main__":
  main()

### FIXED CODE ###

import sys
import heapq

def main():
  input = sys.stdin.readline
  n, m = map(int, input().split())
  s = input()
  
  inf = pow(10, 6)
  ans = [inf]*(n+1)
  key = []
  heapq.heapify(key)
  heapq.heappush(key, (0, n))
  ans[n] = 0
  index = n-1
  count = 0
  while key:
    sub = heapq.heappop(key)
    s1, s2 = sub[0], sub[1]
    if s1 < count:
      continue
    count = s1+1
    subindex = index
    for i in range(min([index, s2-1]), max([-1, s2-m-1]), -1):
      if ans[i] != inf:
        continue
      if s[i] == "1":
        continue
      heapq.heappush(key, (count, i))
      ans[i] = s2
      subindex = i
    index = subindex
      
  if ans[0] == inf:
    print(-1)
  else:
    index = 0
    answer = []
    while True:
      subindex = ans[index]
      answer.append(subindex-index)
      if subindex == n:
        break
      index = subindex
  
    print(*answer)
  
if __name__ == "__main__":
  main()
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**9)

n = int(input())
adjacency = [[] for i in range(n+1)] #adjacency[i]は頂点iと隣接する頂点のリスト
distance = {} # distance[(i,j)](i,jは隣接した頂点)は頂点i,jを結ぶ辺の長さ
for i in range(n-1):
    line = list(map(int, input().split()))
    adjacency[line[0]].append(line[1])
    adjacency[line[1]].append(line[0])
    distance[(line[0], line[1])] = line[2]
    distance[(line[1], line[0])] = line[2]
q, k = map(int, input().split())
x = []
y = []
for i in range(q):
    line = list(map(int, input().split()))
    x.append(line[0])
    y.append(line[1])

k_distance = [-1 for i in range(n+1)] # k_distance[i]は頂点i,kの距離
k_distance[k] = 0
reached = {k}
def dfs(v, d): # 現在いる頂点vと頂点v,k間の距離dを入力すると頂点vと隣接する未到達の頂点のk_distanceを計算してappendする
    for neighbor in adjacency[v]:
        if not neighbor in reached:
            reached.add(neighbor)
            k_distance[neighbor] = d + distance[(v, neighbor)]
            dfs(neighbor, k_distance[neighbor])
    return
dfs(k, 0)
for i in range(q):
    print(k_distance[x[i]] + k_distance[y[i]])


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)
from sys import stdin
input = stdin.readline

n = int(input())
adjacency = [[] for i in range(n+1)] #adjacency[i]は頂点iと隣接する頂点のリスト
distance = {} # distance[(i,j)](i,jは隣接した頂点)は頂点i,jを結ぶ辺の長さ
for i in range(n-1):
    line = list(map(int, input().split()))
    adjacency[line[0]].append(line[1])
    adjacency[line[1]].append(line[0])
    distance[(line[0], line[1])] = line[2]
    distance[(line[1], line[0])] = line[2]
q, k = map(int, input().split())
x = []
y = []
for i in range(q):
    line = list(map(int, input().split()))
    x.append(line[0])
    y.append(line[1])

k_distance = [-1 for i in range(n+1)] # k_distance[i]は頂点i,kの距離
k_distance[k] = 0
reached = {k}
def dfs(v, d): # 現在いる頂点vと頂点v,k間の距離dを入力すると頂点vと隣接する未到達の頂点のk_distanceを計算してappendする
    for neighbor in adjacency[v]:
        if not neighbor in reached:
            reached.add(neighbor)
            k_distance[neighbor] = d + distance[(v, neighbor)]
            dfs(neighbor, k_distance[neighbor])
    return
dfs(k, 0)
for i in range(q):
    print(k_distance[x[i]] + k_distance[y[i]])
### BUGGY CODE ###

from functools import reduce
from operator import mul

mod = 10**9 + 7

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

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

if N == K:
    print(reduce(mul, A)%mod)

else:

    AP = []
    AM = []
    for i in A:
        if i < 0:
            AM.append(i)
        else:
            AP.append(i)
            
    if len(AP) == 0 and K%2 != 0:
        AM.sort(reverse=True)
        AM = AM[:K]
        print(reduce(mul, AM)%mod)

    else:
        
        AP.sort(reverse=True)
        AM.sort()
        
        ans = 1
        p = 0
        m = 0
        cnt = 0
        while True:
            if (K - cnt) == 1:
                ans *= AP[p]
                print(ans%mod)
                break
                
            elif 2 <= len(AM) - m and 2 <= len(AP) - p:   
                if AP[p]*AP[p+1] >= AM[m]*AM[m+1]:
                    ans *= (AP[p]*AP[p+1])
                    p += 2
                    cnt += 2
                
                else:
                    ans *= (AM[m]*AM[m+1])
                    m += 2
                    cnt += 2 
                    
            elif 1 >= len(AP) - p and 2 <= len(AM) - m:
                ans *= (AM[m]*AM[m+1])
                m += 2
                cnt += 2 
            
            elif 2 <= len(AP) - p and 1 >= len(AM) - m:
                ans *= (AP[p]*AP[p+1])
                p += 2
                cnt += 2
            
            

            if cnt == K:
                print(ans%mod)
                break


### FIXED CODE ###

from bisect import bisect_left,bisect_right
p=10**9+7
n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))
pi=1
ni=0
ans=1
i=0
while i<k-1:
  if a[ni]*a[ni+1]>a[-pi]*a[-pi-1]:
    ans=ans*a[ni]*a[ni+1]%p
    ni+=2
    i+=2
  else:
    ans=ans*a[-pi]%p
    pi+=1
    i+=1
if i==k-1:
  ans=ans*a[-pi]%p
if a[-1]<0 and k%2==1:
  ans=1
  for i in a[n-k:]:
    ans=ans*i%p
print(ans)
### BUGGY CODE ###

N = int(input())
A = []
for n in range(N):
    A.append(int(input()))

for n in range(N):
    max_before = max(A[:n], default=0)
    max_after = max(A[n+1:], default=0)
    ans = max(max_before, max_after)
    print(ans)


### FIXED CODE ###

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

max_A = sorted(A)[-1]
second_A = sorted(A)[-2]

for n in range(N):
    if A[n] != max_A:
        print(max_A)
    else:
        print(second_A)
### BUGGY CODE ###

from operator import itemgetter
n,q=map(int,input().split())
c=list(map(int,input().split()))
l=[list(map(int,input().split())) for i in range(q)]
l2=sorted(l,key=itemgetter(1))

L=[-1 for i in range(max(c))]

class Bit:
  def __init__(self,n):
    self.size=n
    self.tree=[0]*(n + 1)
    self.depth=n.bit_length()

  def sum(self,i):
    s=0
    while i>0:
      s+=self.tree[i]
      i-=i&-i
    return s

  def add(self,i,x):
    while i<=self.size:
      self.tree[i]+=x
      i+=i&-i
 
  def lower_bound(self,x):
    sum_=0
    pos=0
    for i in range(self.depth,-1,-1):
      k=pos+(1<<i)
      if k<=self.size and sum_+self.tree[k]<x:
        sum_+=self.tree[k]
        pos+=1<<i
    return pos+1,sum_

BIT=Bit(n+1)

ans={}
ct=0
for i in range(q):
  while ct<=l2[i][1]:
    if L[c[ct-1]-1]!=-1:
      BIT.add(L[c[ct-1]-1],-1)
    L[c[ct-1]-1]=ct+1
    BIT.add(ct+1,1)
    ct+=1
  ans[l2[i][0],l2[i][1]]=BIT.sum(l2[i][1]+1)-BIT.sum(l2[i][0])

for i in range(q):
  print(ans[l[i][0],l[i][1]])

### FIXED CODE ###

n,q=map(int,input().split())
c=list(map(int,input().split()))
l=[list(map(int,input().split())) for i in range(q)]
for i in range(q):
  l[i].append(i)
l2=sorted(l,key=lambda x:x[1])

L=[-1]*(5*10**5+1)

class Bit:
  def __init__(self,n):
    self.size=n
    self.tree=[0]*(n + 1)
    self.depth=n.bit_length()

  def sum(self,i):
    s=0
    while i>0:
      s+=self.tree[i]
      i-=i&-i
    return s

  def add(self,i,x):
    while i<=self.size:
      self.tree[i]+=x
      i+=i&-i

BIT=Bit(n+1)

ans=[0]*q
ct=0
for i in range(q):
  while ct<=l2[i][1]:
    if L[c[ct-1]-1]!=-1:
      BIT.add(L[c[ct-1]-1],-1)
    L[c[ct-1]-1]=ct+1
    BIT.add(ct+1,1)
    ct+=1
  ans[l2[i][2]]=BIT.sum(l2[i][1]+1)-BIT.sum(l2[i][0])

for i in range(q):
  print(ans[i])
### BUGGY CODE ###

# coding: utf-8
# Here your code !

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

### FIXED CODE ###

N = int(input())
card = set()

for i in range(N):
    A = int(input())
    if A in card:
        card.remove(A)
    else:
        card.add(A)
print(len(card))
### BUGGY CODE ###

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

### FIXED CODE ###

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

n=int(input())
s_list=[]
unq_list=[]
for i in range(n):
  s_elem=''.join(sorted(list(input())))
  s_list.append(s_elem)
  if s_list.count(s_elem) == 2:
    unq_list.append(s_elem)

count=0

for j in range(len(unq_list)):
  match_n=s_list.count(unq_list[j])
  count+=sum(range(1, match_n))

print(count)

### FIXED CODE ###

n=int(input())
dic={}

count=0
for i in range(n):
  s_elem=''.join(sorted(list(input())))
  if s_elem in dic:
    count+=dic[s_elem]
    dic[s_elem]+=1
  else:
    dic[s_elem]=1

print(count)