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

n = int(input())

s = [0] * n
v = [0] * (n - 1)
w = [0]

for i in range(n):
    s[i] = input()

t = sorted(s)

for i in range(n - 1):
    if t[i] == t[i + 1]:
        v[i] = 1

u = sorted(set(t), key=t.index)

for i in range(n - 1):
    if v[i] != 0:
        w[len(w) - 1] += 1
    else:
        w.append(0)

for i in range(len(w)):
    if max(w) == w[i]:
        print(u[i])


### FIXED CODE ###

import collections
 
n = int(input())
s = [input() for i in range(n)]
 
count = collections.Counter(s)
 
max_v = max(count.values())
 
result = [key for key, val in count.items() if val == max_v]

print("\n".join(sorted(result)))
### BUGGY CODE ###

import re
s = input()
ans = 0
while True:
  st1 = re.split("10|01",s)
  if len(st1)==1:
    break
  ans += len(st1)-1
  s = "".join(st1)
print(ans*2)

### FIXED CODE ###

a,b=0,0
for s in input():
  if s=="0": a+=1
  else: b+=1
print(min(a,b)*2)
### BUGGY CODE ###

from collections import deque

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

class WorkList:
    def __init__(self):
        self.payList = [[] for _ in range(10001)]
        self.payList_sorted = []

    def add(self, a, b):
        if a <= M:
            self.payList[10001 - b].append(a)

    def sort_task(self):
        self.payList_sorted = [deque(sorted(l)) for l in self.payList]

    def get_task(self, deadline):
        for i, q in enumerate(self.payList_sorted):
            if len(q) > 0 and q[0] <= deadline:
                q.popleft()
                return 10001 - i
        return 0


w = WorkList()
for _ in range(N):
    A, B = map(int, input().split())
    w.add(A, B)

w.sort_task()

ans = 0

for d in range(M + 1):
    ans += w.get_task(d)

print(ans)

### FIXED CODE ###

import heapq
from collections import deque

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

work = [list(map(int,input().split())) for _ in range(N)]

wq = deque(sorted(work))

paytree = []

ans = 0

for day in range(M + 1):
    while len(wq) > 0 and wq[0][0] <= day:
        heapq.heappush(paytree, wq.popleft()[1] * (-1))
    if len(paytree) > 0:
        ans -= heapq.heappop(paytree)

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

N, K = [int(i) for i in input().split()]
H = [int(i) for i in input().split()]

dp = [float('inf')] * N
dp[0] = 0
for i in range(1, N):
    for j in range(1, K + 1):
        if i - j < 0:
            break
        dp[i] = min(dp[i], dp[i - j] + abs(H[i] - H[i - j]))
print(dp[N - 1])

### FIXED CODE ###

N, K = [int(i) for i in input().split()]
H = [int(i) for i in input().split()]

dp = [float('inf')] * N
dp[0] = 0
for i in range(1, N):
    for j in range(1, K + 1):
        if i - j < 0:
            break
        dp[i] = min(dp[i], dp[i - j] + abs(H[i] - H[i - j]))
print(dp[N - 1])
### BUGGY CODE ###

s=input()
ans=0
for i in range(4,len(s)+1):
  for j in range(len(s)-i+1):
    if(int(s[j:j+i])%2019==0):
      ans+=1
print(ans)

### FIXED CODE ###

s=input()
tmp,mod,n,ans=0,2019,len(s),0
dic={0:1}
for i in range(len(s)):
  tmp=(tmp+int(s[i])*pow(10,n-i-1,mod))%mod
  if tmp in dic.keys():
    dic[tmp]+=1
  else:
    dic[tmp]=1
for i in dic.items():
  ans+=(i[1]*(i[1]-1))//2
print(ans)
### BUGGY CODE ###

a,b=map(int,input().split())
n = input()
for i in range(b):
  s,t=map(int,input().split())
  print(n[s-1:t].count("AC"))

### FIXED CODE ###

a,b=map(int,input().split())
n = input()
m = [0]*a
for i in range(1,a):
  if n[i-1:i+1]=="AC":
    m[i]=m[i-1]+1
  else:
    m[i]=m[i-1]
for j in range(b):
  s,t=map(int,input().split())
  print(m[t-1]-m[s-1])
### BUGGY CODE ###

from sys import stdin
def S(): return stdin.readline().rstrip()

s = S()
ls = list(s)
l = []

while 0<len(ls):
    if len(l)<1:
        l.append(ls.pop(0))
    else:
        tmp = ls.pop(0)
        while tmp == l[len(l)-1]:
            if 0<len(ls):
                tmp += ls.pop(0)
            else:
                a = l.pop()
                tmp = a + tmp
                break
        l.append(tmp)

print(len(l))

### FIXED CODE ###

from sys import stdin
def S(): return stdin.readline().rstrip()

s = S()
ls = list(s)
l = []

tmp = ''
k = 0
for i in ls:
    k += 1
    if len(l)<1:
        l.append(i)
    else:
        tmp += i
        if tmp != l[len(l)-1]:
            l.append(tmp)
            tmp = ''
        else:
            if k == len(ls):
                a = l.pop()
                tmp = a+tmp
                l.append(tmp)

print(len(l))
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**6)
N, Q = map(int, input().split())
V = [[] for _ in range(N)]
X = [0 for _ in range(N)]

for _ in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    V[a].append(b)
    V[b].append(a)

for _ in range(Q):
    p, x = map(int, input().split())
    p -= 1
    X[p] += x
# p親、n現在、s合計
def dfs(p, n):
    for i in V[n]:
        if i == p:
            continue
        X[i] += X[n] 
        dfs(n, i)
dfs(-1,0)
print(*X)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 6)
def input():
    return sys.stdin.readline()[:-1]
 
n , q = map(int,input().split())
point = [0] * n
edge = [[] for i in range(n)]
 
for i in range(n-1):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)
 
for _ in range(q):
    a , b = map(int,input().split())
    point[a-1] += b
 
def dfs(now, last=-1):
    for nxt in edge[now]:
        if nxt==last: continue
        point[nxt] += point[now]
        dfs(nxt, now)
dfs(0)
print(*point)
### BUGGY CODE ###

n = int(input())
A = [int(i) for i in input().split(' ')] 

fl = "YES"
for i, a in enumerate(A):
  if a in A[i+1:]:
    fl = "NO"
    break

print(fl)

### FIXED CODE ###

n = int(input())
A = input().split(' ')

if len(A) == len(set(A)):
  print("YES")
else:
  print("NO")
### BUGGY CODE ###

import numpy as np
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
f=[int(i) for i  in input().split()]
#Aについても、修行前の大小で並べてしまって良いです
A=np.array(sorted(a))
F=np.array(sorted(f, reverse=True))
#最大値の最小化▶︎二分探索！
#答えxを決めて、A*Fペア全てをx以下にするために必要な修行がk回以下かを調べていく。(xについて二分探索)
left=-1
right=10**12
s=A.sum()
x=(left+right)//2
#A-x//Fは、x以下にするのに必要な最小の修行回数。
#np.maximum(A-x//F,0)は、２つの配列の大きい方を取っていきながらあたらしい配列を作っている。
while left+1<right:
    if s-np.minimum(A , x//F).sum()<=k:
        #この時答えはx以下なので
        right=x
    else:
        #この時答えはxより大きいので
        left=x
print(right)

### FIXED CODE ###

import numpy as np
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
f=[int(i) for i  in input().split()]
#Aについても、修行前の大小で並べてしまって良いです
A=np.array(sorted(a))
F=np.array(sorted(f, reverse=True))
#最大値の最小化▶︎二分探索！
#答えxを決めて、A*Fペア全てをx以下にするために必要な修行がk回以下かを調べていく。(xについて二分探索)
left=-1
right=10**12
s=A.sum()
#A-x//Fは、x以下にするのに必要な最小の修行回数。
#np.maximum(A-x//F,0)は、２つの配列の大きい方を取っていきながらあたらしい配列を作っている。
while left+1<right:
    x=(left+right)//2
    if np.maximum(A-x//F , 0).sum()<=k:
        #この時答えはx以下なので
        right=x
    else:
        #この時答えはxより大きいので
        left=x
print(right)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
from collections import defaultdict,deque
N = int(input())
abc = [list(map(int, input().split())) for _ in range(N-1)]
Q, K = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(Q)]

graph = defaultdict(lambda: defaultdict(int))

for a,b,c in abc:
    graph[a-1][b-1] = c
    graph[b-1][a-1] = c

def xfs(v,g):
    que = deque()
    que.append([v,0])
    while len(que) > 0:
        # i,dist = que.pop()  # 深さ優先探索        
        i,dist = que.popleft() #幅優先探索
        if i == g:
            return dist
        for n, val in graph[i].items():
            que.append([n,dist+val])
    return -1

distK = [-1 for _ in range(N)]
for i in range(N):
    distK[i] = xfs(K-1,i)

for x,y in xy:
    print(distK[x-1] + distK[y-1])


### FIXED CODE ###

# -*- coding: utf-8 -*-
from collections import defaultdict,deque
N = int(input())
abc = [list(map(int, input().split())) for _ in range(N-1)]
Q, K = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(Q)]

# graph = defaultdict(lambda: defaultdict(int))
graph = [defaultdict(int) for _ in range(N)]

for a,b,c in abc:
    graph[a-1][b-1] = c
    graph[b-1][a-1] = c

def xfs(v):
    dist = [-1 for _ in range(N)]
    dist[v] = 0
    que = deque()
    que.append(v)
    while len(que) > 0:
        i = que.pop()  # 深さ優先探索        
        # i = que.popleft() #幅優先探索
        for n, val in graph[i].items():
            if dist[n] == -1:
                dist[n] = dist[i] + val
                que.append(n)
    return dist

dist = xfs(K-1)

for x,y in xy:
    print(dist[x-1] + dist[y-1])
### BUGGY CODE ###

N = int(input())
S = input()
Lw = []
Le = []

cw = 0
ce = 0
for i in range(N):
  if S[i] == "W":
    cw += 1
  Lw.append(cw)
  if S[N - 1 - i] == "E":
    ce += 1
  Le.insert(0, ce)

min = min(Le[1], Lw[N-2])
for i in range(1, N-1):
  p = Le[i + 1] + Lw[i - 1]
  if p < min:
    min = p

print(min)

### FIXED CODE ###

N = int(input())
S = input()
Lw = [0]*N
Le = [0]*N

cw = 0
ce = 0
for i in range(N):
  if S[i] == "W":
    cw += 1
  Lw[i] = cw
  if S[N - 1 - i] == "E":
    ce += 1
  Le[N-1-i] = ce

min = min(Le[1], Lw[N-2])
for i in range(1, N-1):
  p = Le[i + 1] + Lw[i - 1]
  if p < min:
    min = p

print(min)
### BUGGY CODE ###

S = input()
count = 0
prev = -1
while True:
    count += 2*S.count('01')
    S = S.replace('01','')
    count += 2*S.count('10')
    S = S.replace('10','')
    if count == prev:
        break
    else:
        prev = count
print(count)

### FIXED CODE ###

S = input()
print(min(2*S.count('0'),2*S.count('1')))
### BUGGY CODE ###

import sys
from collections import Counter

inf = 1<<60

def solve():
    N, M = map(int, input().split())
    edges = [None]*M

    for i in range(M):
        ui, vi, ci = map(int, sys.stdin.readline().split())
        edges[i] = (ui-1, vi-1, -ci)

    ans = Bellmanford(N, M, edges)

    if ans is not None:
        print(-ans)
    else:
        print('inf')

def Bellmanford(N, M, edges):
    dist = [inf]*N
    dist[0] = 0
    flag = True

    while True:
        flag = False

        for (u, v, c) in edges:
            if dist[v] > dist[u] + c:
                dist[v] = dist[u] + c
                flag = True

        # print(dist)

        if not flag or dist[0] < 0:
            break

    if dist[0] >= 0:
        return dist[N - 1]
    else:
        return None

if __name__ == '__main__':
    solve()

### FIXED CODE ###

import sys
from collections import Counter

sys.setrecursionlimit(10**7)
 
inf = 1<<100
 
def solve():
    N, M = map(int, input().split())
    edges = [None]*M
    Adj = [[] for i in range(N)]
 
    for i in range(M):
        ui, vi, ci = map(int, sys.stdin.readline().split())
        ui, vi = ui - 1, vi - 1
        edges[i] = (ui, vi, -ci)
        Adj[ui].append(vi)

    visitable = [False]*N

    dfs(N, M, Adj, visitable, 0)

    reachable = [False]*N
    reachable[0] = True
    reachable[N - 1] = True

    for u in range(1, N - 1):
        visited = [False]*N

        dfs(N, M, Adj, visited, u)

        if visited[N - 1]:
            reachable[u] = True
 
    ans = Bellmanford(N, M, edges, visitable, reachable)
 
    if ans is not None:
        print(-ans)
    else:
        print('inf')

def dfs(N, M, Adj, visitable, u):
    visitable[u] = True

    for v in Adj[u]:
        if not visitable[v]:
            dfs(N, M, Adj, visitable, v)

def Bellmanford(N, M, edges, visitable, reachable):
    dist = [inf]*N
    dist[0] = 0
    flag = True

    cnt = 0
 
    for i in range(N):
        flag = False

        for (u, v, c) in edges:
            if dist[u] != inf and dist[v] > dist[u] + c:
                dist[v] = dist[u] + c

                if visitable[v] and reachable[v]:
                    flag = True

        # print(dist)

        if not flag:
            break

        if flag and i == N - 1:
            return None

    return dist[N - 1]
 
if __name__ == '__main__':
    solve()
### BUGGY CODE ###

from scipy.sparse.csgraph import shortest_path
import numpy as np
import sys

def get_path(start, goal, pred):
    return get_path_row(start, goal, pred[start])

def get_path_row(start, goal, pred_row):
    path = []
    i = goal
    while i != start and i >= 0:
        path.append(i)
        i = pred_row[i]
    if i < 0:
        return []
    path.append(i)
    return path[::-1]

N, M = map(int, input().split())
A = []
B = []
neighbor = np.array([[0 for x in range(N)] for y in range(N)])
for i in range(M):
    a, b = map(lambda x: int(x)-1, input().split())
    neighbor[a][b] = 1
    neighbor[b][a] = 1

d, p = shortest_path(neighbor, return_predecessors=True)

ans = []


for i in range(1,N):
    next_sign = get_path(0,i,p)
    if next_sign:
        ans.append(next_sign[-2]+1)
    else:
        print("No")
        sys.exit(0)
print("Yes")

for i in range(N-1):
    print(ans[i])


### FIXED CODE ###

from collections import deque

N,M = map(int, input().split())
ways = [[] for _ in range(N+1)]

for i in range(M):
    a,b = map(lambda x: int(x), input().split())
    ways[a].append(b)
    ways[b].append(a)

dq = deque([1])
sign = [None] * (N+1)
sign[0] = 0
sign[1] = 0

while(dq):
    now = dq.popleft()
    for w in ways[now]:
        if not sign[w]:
            sign[w] = now
            dq.append(w)

if None in sign:
    print("No")
else:
    print("Yes")
    for i in range(2, N+1):
        print(sign[i])
### BUGGY CODE ###

n = int(input())
d = list(map(int, input().split()))
k_count = 0
for i in range(min(d), max(d)):
    arc = len(list(filter(lambda x: x > i, d)))
    abc = len(list(filter(lambda x: x <= i, d)))
    if arc == abc:
        k_count += 1
print(k_count)

### FIXED CODE ###

n = int(input())
d = list(map(int, input().split()))
d.sort()
k_count = 0
i = n // 2 - 1
arc = len(list(filter(lambda x: x > d[i], d)))
abc = len(list(filter(lambda x: x <= d[i], d)))
if arc == abc:
    k_count += (d[i+1] - d[i])
print(k_count)
### 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


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


### 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 ###

n, m = map(int, input().split())
a = []
b = []
al = []
ans = 0
for i in range(n):
    al.append(list(map(int, input().split())))

for i in range(n):
    a.append(al[i][0])
    b.append(al[i][1])

ans = 0
while(m > 0):
    if m > b[a.index(min(a))]:
        m -= b[a.index(min(a))]
        ans += a[a.index(min(a))]*b[a.index(min(a))]
        b.pop(a.index(min(a)))
        a.pop(a.index(min(a)))
    else :
        ans += a[a.index(min(a))]*m
        break
print(ans)

### FIXED CODE ###

n, m = map(int, input().split())
ab = sorted([list(map(int,input().split()))for i in range(n)],key=lambda x:x[0])
ans = 0
i = 0
while m-ab[i][1]>0:
    m -= ab[i][1]
    ans += ab[i][0]*ab[i][1]
    i += 1
ans += ab[i][0] * m
print(ans)
### BUGGY CODE ###

# import math
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

N = int(input())
An = [int(x) for x in input().split()]  
Cn = [An.count(i) for i in range(1,N+1)]  # どの数字が何個あるか？

# ボールを全部使えるときの合計を求める
s = 0
for i in range(N):
    if Cn[i] > 1:
        # s += int(math.factorial(Cn[i]) / (math.factorial(Cn[i]-2) * 2))
        s += int(cmb(Cn[i],2))

for k in range(N):
    print(s - (Cn[An[k]-1]-1))

### FIXED CODE ###

import collections as c

# 入力
N = int(input())
An = [int(x) for x in input().split()]
 
# 各数字の個数を求める
Cn = c.Counter(An)
 
# 全部の組み合わせ
s = 0
for v in Cn.values():
    s += int(v*(v-1) / 2)

for i in range(0,N):
    print(s - (Cn[An[i]] - 1))
### BUGGY CODE ###

N=int(input())
s=set([])
for i in range(N):
    s=s^{int(input())}
print(len(s))

### FIXED CODE ###

N=int(input())
A=[int(input()) for _ in range(N)]
d={}
for a in A:d[a]=0
for a in A:d[a]+=1
cnt=0
for i in d:
    if d[i]%2:cnt+=1
print(cnt)
### BUGGY CODE ###

# encoding: utf-8
N, M = list(map(int, input().split()))
Amod = [int(A) % M for A in filter(lambda x: int(x) > 0, input().split())]

ans = 0
for l in range(len(Amod)):
    acm = 0
    for r in range(l, len(Amod)):
        acm = (acm + Amod[r]) % M
        if acm == 0: ans += 1

print(ans)

### FIXED CODE ###

# encoding: utf-8
N, M = list(map(int, input().split()))

d_sym = {}
sym = 0

# refresh

ans = 0
for A in map(int, input().split()):
    sym = (sym + A) % M
    #
    if sym == 0: ans += 1
    # 
    if str(sym) in d_sym.keys(): d_sym[str(sym)] += 1
    else: d_sym[str(sym)] = 1

print(int(ans + sum([val * (val - 1) / 2 for val in d_sym.values()])))
### BUGGY CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))

count = dict()
for i in a:
  count[i] = count.get(i, 0) + 1

ans = 0
while len(count) > k:
  key, value = min(count.items(), key=lambda x : x[1])
  del count[key]
  ans += value

print(ans)

### FIXED CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))

count = {}
for i in a:
  count[i] = count.get(i, 0) + 1

print(sum(sorted(count.values())[:-k]))
### BUGGY CODE ###

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

if N == 1:
  print(1)
  exit(0)
#
A.append(10000000) 
if N == 1:
  print(0)
  exit(0)
#
A.sort()
ans = 0

for i in range(N):
  if A[i] == A[i+1] or A[i-1] == A[i]:
    continue
  for j in range(i):
    if A[i] % A[j] == 0:
      break
  else:
    ans += 1
#

print(ans)


### FIXED CODE ###

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

cnt = [0] * 1000001

for i in A:
  if cnt[i] == 1:
    continue 
  if cnt[i] == 2:
    cnt[i] = 1
    continue
  cnt[i] = 2
  for j in range( (i+i),1000001,i):
    cnt[j] = 1
#
ans = 0
for i in range(1000001):
  if cnt[i] == 2:
    ans += 1
#
print(ans)
### BUGGY CODE ###

import sys

fin = sys.stdin.readline

N, M = map(int, fin().split())
As = list(map(int, fin().split()))
BC = [tuple(map(int, fin().split())) for _ in range(M)]

As = sorted(As)
# BC = sorted(BC, key=lambda x: x[1], reverse=True)

BC_ = {}
for num, val in BC:
    if val in BC_:
        BC_[val] += num
    else:
        BC_[val] = num

BC_ = sorted(BC_.items(), reverse=True)


def f(a, n, v):
    if a[min(n-1, len(a)-1)] < v:
        return v * min(n, len(a)), a[n:]
    count = 0
    for i in range(min(n, len(a))):
        if a[i] < v:
            count += 1
        else:
            break
    return v * count, a[count:]


sum__ = 0
for val, num in BC_:
    if len(As) == 0 or As[0] >= val:
        break
    sum_, As = f(As, num, val)
    sum__ += sum_

print(sum__ + sum(As))




### FIXED CODE ###

import sys

fin = sys.stdin.readline

N, M = map(int, fin().split())
As = list(map(int, fin().split()))
BC = [tuple(map(int, fin().split())) for _ in range(M)]

As = sorted(As)
# BC = sorted(BC, key=lambda x: x[1], reverse=True)

BC_ = {}
for num, val in BC:
    if val in BC_:
        BC_[val] += num
    else:
        BC_[val] = num

BC_ = sorted(BC_.items(), reverse=True)

#
# def f(a, n, v):
#     if a[min(n-1, len(a)-1)] < v:
#         return v * min(n, len(a)), a[n:]
#     count = 0
#     for i in range(min(n, len(a))):
#         if a[i] < v:
#             count += 1
#         else:
#             break
#     return v * count, a[count:]


sum__ = 0
now = 0
for val, num in BC_:
    if now >= len(As) or As[now] >= val:
        break

    if As[min(num - 1 + now, len(As) - 1)] < val:
        sum_ = val * min(num, len(As) - now)
        now += min(num, len(As) - now)
    else:
        count = 0
        for i in range(min(num, len(As)-now)):
            if As[i + now] < val:
                count += 1
            else:
                break
        sum_ = val * count
        now += count
    sum__ += sum_

print(sum__ + sum(As[now:]))
### BUGGY CODE ###

N = int(input())
A = list(input().split())
B = [int(a) for a in A]
x = 10**9+7
summation = 0
for i in range(N-1):
    for j in range(i+1,N):
        summation += (B[i] * B[j])
        summation % x
print(summation % x)

### FIXED CODE ###

N = int(input())
A = list(input().split())
B = [int(a) for a in A]
x = 10**9+7
summation1 = sum(B) ** 2
summation2 = sum(b ** 2 for b in B)
summation = ((summation1 - summation2) // 2) % x
print(summation)
### BUGGY CODE ###

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


### FIXED CODE ###

import sys
N=int(input())
A=[]
pai=int(1)
hantei=int(0)
A=list(map(int,input().split()))
for i in range(N):
    if A[i]==0:
        print("0")
        sys.exit()
for i in range(N):
    pai=pai*A[i]
    if pai>10**18:
        print("-1")
        hantei=int(1)
        break
if hantei==0:
    print(pai)
### BUGGY CODE ###

N, K = map(int, input().split())
trees = []
for _ in range(N):
    tree = int(input())
    trees.append(tree)

trees.sort()

m = max(trees[0:K]) - min(trees[0:K])
for i in range(1, N-K+1):
    m = min(m, max(trees[i:i+K]) - min(trees[i:i+K]))

print(m)

### FIXED CODE ###

N, K = map(int, input().split())
trees = []
for _ in range(N):
    tree = int(input())
    trees.append(tree)

trees.sort()

m = trees[K-1] -trees[0]
for i in range(1, N-K+1):
    m = min(m, trees[i+K-1] - trees[i])

print(m)
### BUGGY CODE ###

N = int(input())
D = {}
for n in range(N):
    w = input()
    if w not in D:
        D[w] = 0
    else:
        D[w] += 1
d = sorted(D.items())
d = sorted(D.items(),key=lambda x:-x[1])
m = d[0][1]
l = []
for (key, value) in d:
    if value == m:
        l.append(key)
    else:
        break
for s in sorted(l):
	print(s)

### FIXED CODE ###

N = int(input())
D = {}
for n in range(N):
    w = input()
    if w not in D:
        D[w] = 1
    else:
        D[w] += 1
m = max(D.values())
l = []
for (key, value) in D.items():
    if value == m:
        l.append(key)
for s in sorted(l):
	print(s)
### BUGGY CODE ###

N, X, M = map(int, input().split())
A = [[0] * (10**5+1) for _ in range(34)]
B = [[0] * (10**5+1) for _ in range(34)]

for i in range(10**5+1):
    A[0][i] = B[0][i] = i**2 % M
for i in range(33):
    for j in range(10**5+1):
        A[i+1][j] = A[i][A[i][j]]
        B[i+1][j] += B[i][j] + B[i][A[i][j]]
now = X
ans = X
i = 0
N -= 1
while N > 0:
    if N & 1:
        ans += B[i][now] 
        now = A[i][now]
    N >>= 1
    i += 1
print(ans)

### FIXED CODE ###

N, X, M = map(int, input().split())
A = [[0] * (10**5+1) for _ in range(34)]
B = [[0] * (10**5+1) for _ in range(34)]

for i in range(10**5+1):
    A[0][i] = B[0][i] = i**2 % M
for i in range(33):
    for j in range(10**5+1):
        A[i+1][j] = A[i][A[i][j]]
        B[i+1][j] += B[i][j] + B[i][A[i][j]]
now = X
ans = X
i = 0
N -= 1
while N > 0:
    if N & 1:
        ans += B[i][now] 
        now = A[i][now]
    N >>= 1
    i += 1
print(ans)