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

n = int(input())
s = [input() for _ in range(n)]

d = {}
for i in range(n):
  if s[i] in d.keys():
    d[s[i]] += 1
  else:
    d[s[i]] = 1

m = max(d.values())

ans = [k for k, v in d.items() if v == m]
ans.sort()

for i in range(len(ans)):
  print(ans[i])

### FIXED CODE ###

from collections import Counter

n = int(input())
s = [input() for _ in range(n)]

c = Counter(s)
c = c.most_common()
ans_number = c[0][1]
c.sort()

for i in range(len(c)):
  if c[i][1] == ans_number:
    print(c[i][0])
### BUGGY CODE ###

n = int(input())
s = input()
ans = n

for i in range(n):
    if i>0 and i< n-1:
        m = s[:i+1].count("W") + s[i+1:].count("E")
    elif i == 0:
        m = s[1:].count("E")
    elif i == n-1:
        m = s[:n-2].count("W")
    ans = min(ans,m)
    
print(ans)
         

### FIXED CODE ###

n = int(input())
s = input()
ans = n
w = [0 for i in range(n)]
e = [0 for i in range(n)]
m = [0 for i in range(n)]
for i in range(1,n):
    if s[i-1] == "W":
        w[i] = w[i-1] + 1
    else:
        w[i] = w[i-1]
for i in range(n-2,-1,-1):
    if s[i+1] == "E":
        e[i] = e[i+1] + 1
    else:
        e[i] = e[i+1]
for i in range(n):
    m[i] = e[i] + w[i]
print(min(m))
### BUGGY CODE ###

import math

if __name__ == "__main__":
    l = [0,2,5,5,4,5,6,3,7,6]
    n,m = list(map(int,input().split()))
    a = list(map(int,input().split()))
    dp = [[0,0,0] for i in range(n+1)]
    for i in range(n):
        for j in range(m):
            if dp[i][2] + l[a[j]] != i + l[a[j]] or i + l[a[j]] > n:
                pass
            elif dp[i][0] + a[j]*pow(10, dp[i][1]) >= dp[i + l[a[j]]][0]:
                dp[i + l[a[j]]][0] = dp[i][0] + a[j]*pow(10, dp[i][1])
                dp[i + l[a[j]]][1] = dp[i][1] + 1
                dp[i + l[a[j]]][2] = dp[i][2] + l[a[j]]
            else:
                pass
    print(dp[n][0])

### FIXED CODE ###

if __name__ == "__main__":
  l = [0,2,5,5,4,5,6,3,7,6]
  n,m = list(map(int,input().split()))
  a = list(map(int,input().split()))
  res = ''
  INF = 10**4
  
  dp = [[0,0] for i in range(n+1)]
  for i in range(n):
    for j in range(m):
      if dp[i][1] + l[a[j]] != i + l[a[j]] or i + l[a[j]] > n:
        pass
      else:
        dp[i + l[a[j]]][0] = max(dp[i][0] + 1, dp[i + l[a[j]]][0])
        dp[i + l[a[j]]][1] = dp[i][1] + l[a[j]]
  for i in range(1,n): dp[i][0] = -INF if dp[i][0] == 0 else dp[i][0]
  
  a.sort(reverse = True)
  i = n
  while i > 0:
    for j in range(m):
      if i >= l[a[j]] and dp[i - l[a[j]]][0] + 1 == dp[i][0]:
        res += str(a[j])
        i -= l[a[j]]
        break
      else:
        pass
  print(res)
### BUGGY CODE ###

N, *a = map(int, open(0).read().split())
ans = 0
flag = True
while flag:
    cnt = 0
    for i in range(N):
        if a[i] % 2 == 0 and cnt == 0:
            a[i] //= 2
            cnt += 1
        else:
            a[i] *= 3
    else:
        if cnt == 0:
            flag = False
        else:
            ans += 1

print(ans)


### FIXED CODE ###

N, *a = map(int, open(0).read().split())
ans = 0
for i in range(N):
    ans += len(bin(a[i])) - bin(a[i]).rfind('1') - 1
print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7 # 998244353
input = lambda:sys.stdin.readline().rstrip()
from functools import lru_cache
def resolve():
    n = int(input())
    counter = [0] * 3
    for a in map(int, input().split()):
        counter[a - 1] += 1

    @lru_cache(None)
    def dfs(i, j, k):
        s = i + j + k
        # base case
        if s == 0 or min(i, j, k) < 0:
            return 0
        # recursion
        res = n + i * dfs(i - 1, j, k) + j * dfs(i + 1, j - 1, k) + k * dfs(i, j + 1, k - 1)
        res /= s
        return res

    print(dfs(*counter))
resolve()

### FIXED CODE ###

import sys
sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7 # 998244353
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    n = int(input())
    counter = [0] * 3
    for a in map(int, input().split()):
        counter[a - 1] += 1

    # (i, j, k) -> (i - 1, j, k), (i + 1, j - 1, k), (i, j + 1, k - 1)
    # s = i + j + k の小さい方から遷移
    dp = [[[None] * (n + 1) for _ in range(n + 1)] for _ in range(n + 1)]
    dp[0][0][0] = 0
    for s in range(1, n + 1):
        for k in range(n + 1):
            for j in range(n + 1):
                i = s - j - k
                if i < 0:
                    break
                res = n
                if i: res += i * dp[i - 1][j][k]
                if j: res += j * dp[i + 1][j - 1][k]
                if k: res += k * dp[i][j + 1][k - 1]

                res /= s
                dp[i][j][k] = res

    i, j, k = counter
    print(dp[i][j][k])
resolve()
### BUGGY CODE ###

H, W, *S = open(0).read().split()
H, W = [int(_) for _ in [H, W]]
dist = [[float('inf')] * W for _ in range(H)]
dist[0][0] = 0
stack = [0]
while True:
    if not stack:
        break
    i = stack.pop()
    x, y = divmod(i, W)
    d = dist[x][y]
    for dx, dy in ((1, 0), (0, 1), (-1, 0), (0, -1)):
        nx, ny = x + dx, y + dy
        if 0 <= nx < H and 0 <= ny < W:
            if S[nx][ny] == '#' and S[x][y] == '.':
                if dist[nx][ny] > d + 1:
                    dist[nx][ny] = d + 1
                    stack += [nx * W + ny]
            elif dist[nx][ny] > d:
                dist[nx][ny] = d
                stack += [nx * W + ny]
ans = dist[-1][-1]
if S[0][0] == '#':
    ans += 1
print(ans)


### FIXED CODE ###

import collections
h, w = [int(_) for _ in input().split()]
S = [list('.' * (w + 1))] + [['.'] + list(input()) for _ in range(h)]
B = [[99999] * (w + 1) for _ in range(h + 1)]
B[1][1] = 0 if S[1][1] == '.' else 1
cand = collections.deque([(1, 2), (2, 1)])
while cand:
    x, y = cand.popleft()
    if B[x][y] == 99999:
        B[x][y] = min(B[x][y - 1] + (S[x][y] == '#' != S[x][y - 1]),
                      B[x - 1][y] + (S[x][y] == '#' != S[x - 1][y]))
        if x < h:
            cand += [(x + 1, y)]
        if y < w:
            cand += [(x, y + 1)]
print(B[-1][-1])
### BUGGY CODE ###

import sys
input = lambda : sys.stdin.readline().rstrip()

import collections
s = [int(c) for c in input()]
tmp = 1
mod = 0
count = collections.defaultdict(int)
for i,num in enumerate(s[::-1]):
    mod = (tmp * num + mod) % 2019
    count[mod] += 1
    tmp *= 10
count[0] += 1
print(sum((item*(item-1)//2 for item in count.values())))

### FIXED CODE ###

import sys
input = lambda : sys.stdin.readline().rstrip()

import collections
s = [int(c) for c in input()]
tmp = 1
mod = 0
count = collections.defaultdict(int)
for i,num in enumerate(s[::-1]):
    mod = (tmp * num + mod) % 2019
    count[mod] += 1
    tmp *= 10
    tmp %= 2019
count[0] += 1
print(sum((item*(item-1)//2 for item in count.values())))
### BUGGY CODE ###

from collections import Counter
N = int(input())
A = Counter((list(map(int, input().split(' ')))))
ans = 0
pre= 10**6+1
for i in sorted(A.keys(),reverse=True):
    flg = True
    if A[i] > 1:
        continue
    for j in range(1,min(int(pow(i,0.5))+2,pre)):
        if not i%j:
            if A[j] and i != j:
                flg = False
                break
            if j != i//j and A[i//j] and i//j != i:
                    flg = False
                    break
    if flg:
        ans += 1
    pre = i
print(ans)


### FIXED CODE ###

from collections import Counter
N = int(input())
A = Counter(list(map(int,input().split(' '))))
ans = 0
m = max(A.keys())
L = [1]*(10**6+1)
for i in sorted(A.keys()):
    if not L[i]:
        continue
    if A[i] == 1:
        ans += 1
    for j in range(i,m+1,i):
        L[j] = 0
print(ans)
### BUGGY CODE ###


N=input()
N=int(N)
A=10**12

for a in range(1,(10**12)+1):
    for b in range(1,(10**12)+1):
        if N==a*b:
            if a+b-2<A:
                A=a+b-2
            else:
                pass
        else:
            pass

print(A)


### FIXED CODE ###

N=int(input())
ans=1000000000000
import math

for i in range(int(math.sqrt(N))):
    j=N/(i+1)
    if j%1==0:
        if i+int(j)-1<ans:
            ans=i+int(j)-1

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

# -*- coding: utf-8 -*-
import numpy as np

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

scores = np.array([k] * n)

for i in range(q):
    ans = int(input())
    scores[:ans-1] = scores[:ans-1] - 1
    scores[ans:] = scores[ans:] - 1

for r in scores:
    if r > 0:
        print('Yes')
    else:
        print('No')


### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, K, Q, *A = map(int, read().split())

    B = [0] * N
    for a in A:
        B[a - 1] += 1

    ans = [0] * N
    for i, b in enumerate(B):
        if Q >= K + b:
            ans[i] = 'No'
        else:
            ans[i] = 'Yes'

    print('\n'.join(map(str, ans)))
    return


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

import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)
from numba import njit,i8


@njit(i8[:](i8,i8,i8[:]))
def loop(N,K,A):
    for j in range(K):
        B = np.zeros_like(A)
        for i in range(N):
            temp = A[i]
            left = i - temp
            right = i + temp + 1
            if left < 0:
                left = 0
            if right > N:
                right = N
            B[left:right] += 1
        A = B
    return A


def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    A = np.array(A)

    res = loop(N,K,A)

    print(*res)



main()


### FIXED CODE ###

import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)
from numba import njit,i8


@njit(i8[:](i8,i8,i8[:],i8,i8))
def loop(N,K,A,l,r):
    for j in range(K):
        B = np.zeros_like(A)
        for i in range(N):
            l = max(i - A[i],0)
            r = min(i + A[i],N-1)
            B[l] += 1
            if r + 1 < N:
                B[r+1] -= 1
        for i in range(1,N):
            B[i] += B[i-1]
        A = B
    return A


def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    A = np.array(A)

    if K >= 43:
        M = 43
    else:
        M = K

    res = loop(N,M,A,0,0)

    print(*res)



main()
### BUGGY CODE ###

import fractions
import math
n = int(input())
li = list(map(int,input().split()))

if len(list(set(li))) == 1:
    print(li[0])
else:
    all_li = []
    while len(li)>1:
        all_li = []
        for i,l in enumerate(li):
            if i == 0:
                continue
            else:
                all_li.append(fractions.gcd(l,li[i-1]))
        li = all_li
        #print(li,len(li))
    print(all_li[0])

### FIXED CODE ###

import fractions
import math
n = int(input())
li = list(map(int,input().split()))

if len(list(set(li))) == 1:
    print(li[0])
else:
    if len(li) == 1:
        print(li[0])
        exit()
    tmp_gcd = fractions.gcd(li[0],li[1])
    if len(li)>2:
        for i,l in enumerate(li):
            if i == 0 or i == 1:
                continue
            gc = fractions.gcd(tmp_gcd,l)
            tmp_gcd = gc
    print(tmp_gcd)
### BUGGY CODE ###

mod=10**9+7
n,m=map(int,input().split())
dp=[0]*(n+1)
dp[0]=1
a=[int(input()) for _ in range(m)]
for i in range(n):
    if i+1 not    in a:
        dp[i+1]+=dp[i]
        dp[i+1]%=mod
    if i+2<=n and i+2 not  in a:
        dp[i+2]+=dp[i]
        dp[i+1]%=mod
print(dp[-1]%mod)

### FIXED CODE ###

N,M = map(int,input().split())
A = set([int(input()) for i in range(M)])
MOD = 10**9+7

if 0 in A:
    print(0)
    exit()

dp = [0]*(N+1)
dp[0] = 1
for i in range(N):
    if i+1 not in A:
        dp[i+1] += dp[i]
        dp[i+1] %= MOD
    if i+2 <= N and i+2 not in A:
        dp[i+2] += dp[i]
        dp[i+2] %= MOD
print(dp[-1])
### BUGGY CODE ###

obj = input().strip().split(' ')
N, M = map(int, obj)

obj = input().strip().split(' ')
A_list = map(int, obj)

out_list = [item for item in A_list]

for _ in range(M):
    i = out_list.index(max(out_list))
    out_list[i] = out_list[i] // 2

print(sum(out_list))


### FIXED CODE ###

from heapq import heappush, heappop, heapify

obj = input().strip().split(' ')
N, M = map(int, obj)

obj = input().strip().split(' ')
val_list = [-1 * item for item in list(map(int, obj))]

heapify(val_list)

for _ in range(M):
    val = (-1) * ((heappop(val_list) * (-1)) // 2)
    heappush(val_list, val)

print(-1 * sum(val_list))
### BUGGY CODE ###

s = input()
mod = 1000000007
n = len(s)
dp = [[0]*13 for i in range(n+1)]
dp[0][0] = 1
k = 1
for i in range(n):
    t = 0
    for j in range(10):
        if s[n-i-1]=="?":
            for l in range(13):
                dp[i+1][(l+t)%13]+=dp[i][l]
                dp[i+1][(l+t)%13]%=mod
        elif int(s[n-i-1])==j:
            for l in range(13):
                dp[i+1][(l+t)%13]+=dp[i][l]
                dp[i+1][(l+t)%13]%=mod
        t+=k
        t%=13
    k=t
print(dp[n][5])

### FIXED CODE ###

s = input()
mod = 1000000007
n = len(s)
dp = [[0]*13 for i in range(n+1)]
dp[0][0] = 1
k = 1
for i in range(n):
    t = 0
    for j in range(10):
        if s[n-i-1]=="?":
            for l in range(13):
                dp[i+1][(l+t)%13]+=dp[i][l]
                dp[i+1][(l+t)%13]%=mod
        elif int(s[n-i-1])==j:
            for l in range(13):
                dp[i+1][(l+t)%13]+=dp[i][l]
                dp[i+1][(l+t)%13]%=mod
        t+=k
        t%=13
    k=t
print(dp[n][5])
### BUGGY CODE ###

#C問題
N, M = map(int, input().split())
N_list = []
for i in range (N):
    N_list.append(i+1)
for i in range(M):
    L, R = map(int, input().split())
    N_list= [i for i in N_list if i >= L and i<=R]
print(len(N_list))


### FIXED CODE ###

#C問題
import numpy as np
N, M = map(int, input().split())
L_list = []
R_list = []
for i in range(M):
    L, R = map(int, input().split())
    L_list.append(L)
    R_list.append(R)
if min(R_list) - max(L_list) < 0:
    print(0)
else:
    print(min(R_list) - max(L_list)+1)
### BUGGY CODE ###

#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math

import itertools

#import bisect

import copy
from functools import lru_cache

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]



def main():
    n=int(input())
    s=[]
    sn=[0 for i in range(n)]
    for i in range(n):
        a=input()
        if a in s:
            sn[s.index(a)]+=1
        else:
            s.append(a)
    maxn=max(sn)
    ans=[]
    for i in range(n):
        if sn[i]==maxn:
            ans.append(s[i])
    ans=sorted(ans)

    for i in ans:
        print(i)



if __name__ == "__main__":
    main()

### FIXED CODE ###

#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math

import itertools

#import bisect

import copy
from functools import lru_cache

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]



def main():
    n=int(input())
    s=[input() for i in range(n)]
    s=sorted(s)
    s.append("")
    tempn=0
    temp=s[0]
    maxn=0
    aa=[]
    for i in range(n+1):
        if temp==s[i]:
            tempn+=1
        else:

            aa.append([s[i-1],tempn])
            maxn=max(maxn,tempn)
            tempn=1
            temp=s[i]
    aa=sorted(aa)

    for a,b in aa:
        if b==maxn:
            print(a)



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

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

saidai = 0

for i in range (n):
    count = 0
    for j in range (n-i-1):
        if int(h[i+j])>=int(h[i+j+1]):
            count = count+1
        else :
            i = j
            break
    saidai = max(saidai,count)

print(saidai)


### FIXED CODE ###

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

for i in range (n-1):
    if h[i]>=h[i+1]:
        count += 1
    else:
        m = max(m,count)
        count = 0
m = max(m,count)
print(m)
### BUGGY CODE ###

N,K = map(int, input().split())
L = list()
R = list()
for _ in range(K):
    a,b = map(int, input().split())
    for _1 in range(_):
        x,y = L[_1],R[_1]
        if x <= a <= y or x <= b <= y :
            L[_1] = min(a,x)
            R[_1] = max(b,y)
            break
    else:
        L.append(a)
        R.append(b)
sep = len(L)


MOD = 998244353
dp = [0]*(N+2)
for l, r in zip(L, R):
    dp[min(N + 1, 1 + l)] += 1
    dp[min(N + 1, 1 + r + 1)] -= 1
for i in range(2,N+1):
    number = dp[i-1] + dp[i]
    if number > MOD:
        number -= MOD
    dp[i] = number
    for l, r in zip(L,R):
        dp[min(N + 1, i + l)] += dp[i]
        dp[min(N + 1, i + r +1)] -= dp[i]
print(dp[N]%MOD)

### FIXED CODE ###

N,K = map(int, input().split())
L,R = [0]*K, [0]*K

count = 0
for _ in range(K):
    a,b = map(int, input().split())
    for _1 in range(_):
        x,y = L[_1],R[_1]
        if x <= a <= y or x <= b <= y :
            L[_1] = min(a,x)
            R[_1] = max(b,y)
            break
    else:
        L[_],R[_] =a,b
        count += 1
L,R = L[0:count+1],R[0:count+1]

MOD = 998244353
dp = [0]*(4*10**5+100)
for l, r in zip(L, R):
    dp[min(N + 1, 1 + l)] += 1
    dp[min(N + 1, 1 + r + 1)] -= 1

for i in range(2,N+1):
    number = dp[i-1] + dp[i]
    if number > MOD:
        number -= MOD
    dp[i] = number
    for l, r in zip(L,R):
        dp[i + l] += number
        dp[i + l] %= MOD
        dp[i + r +1] -= number
        dp[i + r +1] %= MOD

print(dp[N]%MOD)
### BUGGY CODE ###

import numpy as np
room, route_count = map(int,input().split())
route = np.array([list(map(int,input().split())) for _ in range(route_count)])

object_nums = [1]
ans = np.array([0]*(room-1))

def mem_ans(ans, object_num, next):
    if next is not None:
      for n in next:
        if ans[n-2] == 0:
          ans[n-2] = object_num
    return ans

for object_num in object_nums:
    object_rows = route[np.any(route==object_num, axis=1)]
    route[np.any(route==object_num, axis=1)] = 0
    next = object_rows[object_rows!=object_num]
    ans = mem_ans(ans, object_num, next)
    object_nums.extend(next)

if 0 in set(ans):
  print('No')
else:
  print('Yes')
  for i in ans:
    print(i)

### FIXED CODE ###

import networkx as nx
room, route_count = map(int,input().split())
route = [list(map(int,input().split())) for _ in range(route_count)]

G = nx.Graph()
G.add_nodes_from(range(1,room+1))
G.add_edges_from(route)
pre = nx.predecessor(G, 1)

print('Yes')
for i in range(2,room+1):
  print(pre[i][0])
### BUGGY CODE ###

N=int(input())
s=[]
l=[]
for i in range(N):
  s.append(input())
  if len(l)==0:
    l.append(s[i])
  if len(l)>0:
    for j in range(len(l)):
      #print(s[i])
      if s[i]==l[j]:
        break
      if j==len(l)-1:
        l.append(s[i])
  
#print(l)
print(len(l))

### FIXED CODE ###

N=int(input())
l=[]
for i in range(N):
  l.append(input())

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

K = int(input())
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
sum = 0

for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            sum += gcd(i,j,k)

print(sum)


### FIXED CODE ###

K = int(input())
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)
sum=0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            sum += gcd(gcd(i,j),k)

print(sum)
# print(gcd(2,6))
### BUGGY CODE ###

import sys
input = sys.stdin.readline
from bisect import insort_left, bisect_left
from collections import defaultdict

def main():
    N = int(input())
    A = [int(i) for i in input().split()]

    # IDX[n]: nのindex
    IDX = defaultdict(int)
    for idx,a in enumerate(A):
        IDX[a] = idx

    ans = 0
    T = [-1, N]
    for n in range(1, N + 1):
        insort_left(T, IDX[n])
        idx = bisect_left(T, IDX[n])
        ans += (T[idx] - T[idx-1]) * (T[idx+1] - T[idx]) * n

    print(ans)

if __name__ == '__main__':
    main()

### FIXED CODE ###

import bisect
from collections import defaultdict
class SqrtSet:
    def __init__(self, block_limit=201):
        self.key = []
        self.child = [[]]
        self.block_limit = block_limit
 
    def search_lower(self, key):
        if key is None:
            return None
        ret = None
        i = bisect.bisect_left(self.key, key)
        if i != 0:
            ret = self.key[i - 1]
        block = self.child[i]
        i = bisect.bisect_left(block, key)
        if i != 0:
            ret = block[i - 1]
        return ret
        
    def search_higher(self, key):
        if key is None:
            return None
        ret = None
        i = bisect.bisect_right(self.key, key)
        if i != len(self.key):
            ret = self.key[i]
        block = self.child[i]
        i = bisect.bisect_right(block, key)
        if i != len(block):
            ret = block[i]
        return ret
 
    def insert(self, key):
        i = bisect.bisect(self.key, key)
        block = self.child[i]
        bisect.insort(block, key)
        if len(block) == self.block_limit:
            sep = self.block_limit // 2
            self.key.insert(i, block[sep])
            self.child.insert(i + 1, block[sep + 1:])
            self.child[i] = block[:sep]

def main():
    N = int(input())
    A = [int(i) for i in input().split()]

    # IDX[n] <-> A.index(n)
    IDX = defaultdict(int)
    for idx,a in enumerate(A):
        IDX[a] = idx

    SS = SqrtSet()
    SS.insert(-1)
    SS.insert(N)

    ans = 0
    for n in range(1, N + 1):
        H = SS.search_higher(IDX[n])
        L = SS.search_lower(IDX[n])
        ans += (IDX[n] - L) * (H - IDX[n]) *  n
        SS.insert(IDX[n])

    print(ans)

if __name__ == "__main__":
    main()