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

def main():
    H, W = map(int, input().split())
    S = []
    for _ in range(H):
        s = list(input())
        S.append(s)
    R = [[0]*W for _ in range(H)]
    L = [[0]*W for _ in range(H)]
    U = [[0]*W for _ in range(H)]
    D = [[0]*W for _ in range(H)]
    for i in range(H):
        cnt1 = 0
        cnt2 = 0
        for j in range(W):
            if S[i][j]=='#':
                cnt1 = 0
            else:
                cnt1 += 1
                L[i][j] = cnt1
        for j in range(W-1, -1, -1):
            if S[i][j]=='#':
                cnt2 = 0
            else:
                cnt2 += 1
                R[i][j] = cnt2

    for j in range(W):
        cnt1 = 0
        cnt2 = 0
        for i in range(H):
            if S[i][j]=='#':
                cnt1 = 0
            else:
                cnt1 += 1
                U[i][j] = cnt1
        for i in range(H-1,-1,-1):
            if S[i][j]=='#':
                cnt2 = 0
            else:
                cnt2 += 1
                D[i][j] = cnt2

    ans = 0
    for i in range(H):
        for j in range(W):
            ans = max(ans, L[i][j]+R[i][j]+U[i][j]+D[i][j]-3)
    print(ans)


if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    H, W = map(int, input().split())
    S = []
    for _ in range(H):
        s = list(input())
        S.append(s)
    R = [[0]*W for _ in range(H)]
    L = [[0]*W for _ in range(H)]
    U = [[0]*W for _ in range(H)]
    D = [[0]*W for _ in range(H)]
    for i in range(H):
        cnt = 0
        for j in range(W):
            if S[i][j]=='#':
                cnt = 0
            else:
                cnt += 1
                L[i][j] = cnt
    for i in range(H):
        cnt = 0
        for j in range(W-1, -1, -1):
            if S[i][j]=='#':
                cnt = 0
            else:
                cnt += 1
                R[i][j] = cnt
    for j in range(W):
        cnt = 0
        for i in range(H):
            if S[i][j]=='#':
                cnt = 0
            else:
                cnt += 1
                U[i][j] = cnt
    for j in range(W):
        cnt = 0
        for i in range(H-1,-1,-1):
            if S[i][j]=='#':
                cnt = 0
            else:
                cnt += 1
                D[i][j] = cnt
    ans = 0
    for i in range(H):
        for j in range(W):
            ans = max(ans, L[i][j]+R[i][j]+U[i][j]+D[i][j]-3)
    print(ans)


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

import sys
import heapq
input = sys.stdin.readline

max_cost = 10**9
n, k = map(int, input().split())
hs = list(map(int, input().split()))
min_cost = [float('inf')] * n
graph = [[(j, abs(hs[i] - hs[j])) for j in range(i+1, i+k+1) if j < n] for i in range(n)]

def dijkstra(source, target):
    hq = [(0, source)]
    while hq:
        cost, vertex = heapq.heappop(hq)
        min_cost[vertex] = cost
        if vertex == target:
            return min_cost[vertex]
        for adjacency_vertex, adjacency_cost in graph[vertex]:
            heapq.heappush(hq, (cost + adjacency_cost, adjacency_vertex))

print(dijkstra(0, n-1))


### FIXED CODE ###

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

n, k = map(int, input().split())
p = list(map(lambda v: (1+int(v))/2, input().split()))

res = 0
for i in range(n-k+1):
    res = max(res, sum(p[i:i+k]))
print(res)


### FIXED CODE ###

n, k = map(int, input().split())
p = list(map(lambda v: (1+int(v))/2, input().split()))

q = [0]
for v in p:
    q.append(q[-1] + v)

res = 0
for i in range(n-k+1):
    res = max(res, q[i+k] - q[i])

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

def main():
    n = int(input())
    s = input().rstrip()
    sets_l = [set() for _ in range(n)]
    sets_r = [set() for _ in range(n)]
    sets_l[0].add(s[0])
    for i in range(1, len(s)):
        sets_l[i] = sets_l[i] | sets_l[i-1]
        for j in range(i+1):
            sets_l[i].add(s[j:i+1])
    sets_r[n-1].add(s[n-1:])
    for i in reversed(range(len(s)-1)):
        sets_r[i] = sets_r[i] | sets_r[i+1]
        for j in reversed(range(i, len(s))):
            sets_r[i].add(s[i:j+1])
    ans = 0
    for i in range(i, len(s)-1):
        for v in sets_l[i]:
            if v in sets_r[i+1]:
                if ans < len(v):
                    ans = len(v)
    print(ans)

if __name__ == "__main__":
    main()

### FIXED CODE ###

def check(x, N, S):
    candidate = set()
    for i in range(N - 2*x + 1):
        candidate.add(S[i:i+x])
        if S[i+x:i+2*x] in candidate:
            return True
    return False

def main():
    n = int(input())
    s = input().rstrip()
    l = 0
    r = n
    while l < r:
        mid = (l+r+1) // 2
        if check(mid, n, s):
            l = mid
        else:
            r = mid-1
    print((l+r+1)//2)

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

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

ans=0

for i in range(y//10000,-1,-1):

    nokori=(y-i*10000)

    for j in range(min(n-i,nokori//5000),-1,-1):
 
        nokori2=nokori-j*5000
    
        for k in range(min(n-i-j,nokori2//1000),-1,-1):
            
            if 10000*i+5000*j+1000*k==y and i+j+k==n:
                print(i,j,k)
                ans=1
                break
                
        else:
            continue
        break
        
    else:
        continue
    break
    
if ans==0:
    print(-1,-1,-1)

### FIXED CODE ###

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

ans=0

for i in range(y//10000,-1,-1):

    nokori=(y-i*10000)

    for j in range(min(n-i,nokori//5000),-1,-1):
 
        nokori2=nokori-j*5000
    
        if 10000*i+5000*j+1000*(n-i-j)==y:
            print(i,j,n-i-j)
            ans=1
            break
            
    else:
        continue
    break
    
          
if ans==0:
    print(-1,-1,-1)
### BUGGY CODE ###


n = int(input())
ans = 0


def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

for i in range(1,n+1):
    ans += i*len(make_divisors(i))

print(ans)

### FIXED CODE ###


def calc(b,e):
    cnt = e // b
    return (b+e) * cnt//2


n = int(input())
ans = 0
for i in range(1,n+1):
    ans += calc(i,n//i * i)

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

N = int(input())
anagram = [''.join(sorted(input())) for _ in range(N)]
anagram_set = set(anagram)
test = lambda a: lambda b: a==b
print(sum({i:sum(range(sum(map(test(i),anagram)))) for i in anagram_set}.values()))

### FIXED CODE ###

from collections import Counter
N = int(input())
c = Counter(''.join(sorted(input())) for _ in range(N))
sum_ = lambda n: int(n*(n-1)/2)
print(sum(map(sum_,c.values())))
### BUGGY CODE ###

N, M = map(int,input().split())
H = list(map(int, input().split()))
arr = [list(map(int, input().split())) for i in range(M)]

tenbo = [True for i in range(N)]
for i in range(N):
    maxi = True
    if tenbo[i]:
        for a, b in arr:
            if a == i+1:
                if H[b-1]>=H[i]:
                   tenbo[i] = False
                else:
                   tenbo[b-1] = False
            elif b == i+1:
                if H[a-1]>=H[i]:
                    tenbo[i] = False
                else:
                   tenbo[a-1] = False

ans = 0
for t in tenbo:
  if t:
    ans+=1
print(ans)


### FIXED CODE ###

N, M = map(int,input().split())
H = list(map(int, input().split()))
arr = [list(map(int, input().split())) for i in range(M)]
highest_tenbo = [0 for i in range(N)]

for a, b in arr:
    highest_tenbo[a-1] = max(highest_tenbo[a-1], H[b-1])
    highest_tenbo[b-1] = max(highest_tenbo[b-1], H[a-1])

ans = 0
for i, t in enumerate(highest_tenbo):
  if t < H[i]:
    ans+=1
print(ans)
### BUGGY CODE ###

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

i=1
while 1:
    tmp=pow(P/i,1/N)
    if tmp%int(tmp)==0:
        break
    i+=1
print(int(tmp))

### FIXED CODE ###

import copy
N, P = map(int, input().split())

x=[i+1 for i in range(int(P**(1/2))) if P%(i+1)==0]
for i in range(len(x)):
    if P%x[i]==0:
        x.append(int(P/x[i]))
x.sort(reverse=True)

for i in range(len(x)):
    tmp=round(x[i]**(1/N),10)
    if tmp%int(tmp)==0:
            break

print(int(tmp))
### BUGGY CODE ###

x = map(int,raw_input().split(' '))
a = x[0]+x[1]
b = 1
c = 10**b
while True:
	if a/c != 0:
		b += 1
		continue
	else:
		break
print b

### FIXED CODE ###

while True:
	try:
		a,b = map(int,raw_input().split(' '))
		print len(str(a+b))
	except: break
### BUGGY CODE ###

S = input()
Q = int(input())
reverse = 0
for i in range(Q):
  q = list(input().split())
  if q[0] == '1':
    reverse += 1
  else:
    if reverse%2 == 1:
      if q[1] == '1':
        S = S + q[2]
      else:
        S = q[2] + S
    else:
      if q[1] == '1':
        S = q[2] + S
      else:
        S = S + q[2]
if reverse%2==1:
  print(S[::-1])
else:
  print(S)

### FIXED CODE ###

S = input()
Q = int(input())
reverse = -1
left = ""
right = ""
for i in range(Q):
  q = list(input().split())
  if q[0] == '1':
    reverse *= (-1)
  else:
    if reverse > 0:
      if q[1] == '1':
        right = right + q[2]
      else:
        left = q[2] + left
    else:
      if q[1] == '1':
        left = q[2] + left
      else:
        right = right + q[2]
if reverse>0:
  print((left+S+right)[::-1])
else:
  print(left+S+right)
### BUGGY CODE ###

def main():
    s=input()
    cnt=0
    n=len(s)
    for i in range(n):
        for j in range(i+1,n+1):
            if int(s[i:j])%2019 == 0:
                cnt += 1
    print(cnt)

if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    s=list(input())[::-1]
    ans,tot,x,m=0,0,1,2019
    cnt=[0]*m
    n=len(s)
    for i in range(n):
        cnt[tot] += 1
        tot += int(s[i])*x
        tot %= m
        ans += cnt[tot]
        x = x*10%m
    print(ans)

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

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

def expectation(pp):
    return (pp * (pp + 1) / 2) / pp

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

result = 0

save_max = 0
save_idx = 0

for i in range(N - K + 1):
    s = sum(p[i : i + K])
    if s > save_max:
        save_idx = i
        save_max = s
    
print(sum([expectation(pp) for pp in p[save_idx : save_idx + K]]))

### FIXED CODE ###

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

def expectation(pp):
    return 1 + (0.5 * (pp - 1))

p = list(map(int, input().split()))
ep = tuple(map(expectation, p))

cum = [0]
cum_append = cum.append
for i in range(N):
    cum_append(cum[i] + ep[i])

result = 0

for i in range(0, N - K + 1):
    tmp = cum[i + K] - cum[i]
    result = max(result, tmp)
    
print(result)
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
A.sort()
for k in range(N-1):
    if A[k]==A[k+1] and A[k]!=0:
        for j in range(N-1,k+1,-1):
            if A[j]==A[j-1] and A[j]!=0:
                A[j]=0
                A[k]=0
                break
count=0
dcount=0
for k in range(len(A)):
    if A[k]!=0:
        count+=1
for k in range(len(A)-1):
    if A[k]==A[k+1] and A[k]!=0:
        dcount+=2
print(count-dcount)

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
A.sort()
M=N
for k in range(N-1):
    if A[k]==A[k+1] and A[k]!=0:
        for j in range(M-1,k+1,-1):
            if A[j]==A[j-1] and A[j]!=0:
                A[j]=0
                A[k]=0
                M=j
                break
count=0
dcount=0
for k in range(len(A)):
    if A[k]!=0:
        count+=1
for k in range(len(A)-1):
    if A[k]==A[k+1] and A[k]!=0:
        dcount+=2
print(count-dcount)
### BUGGY CODE ###

n,m,k=map(int,input().split())
mod=10**9+7
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%mod
A=n*m
v=cmb(A-2,k-2)
t=0
y=0
for i in range(1,n):
  t+=i*(n-i)*m*m%mod
for i in range(1,m):
  y+=i*(m-i)*n*n%mod

ans=v*(t+y)
print(ans%mod)


### FIXED CODE ###

n,m,k=map(int,input().split())
mod=10**9+7
A=n*m-2
from math import factorial
def Comb(N, K):
    a = factorial(N) % mod
    b = factorial(K) % mod
    c = factorial(N-K) % mod
    return (a * pow(b, mod-2, mod) * pow(c, mod-2, mod)) % mod
v=Comb(A,k-2)
t=0
y=0
for i in range(1,n):
  t+=i*(n-i)*m*m%mod
for i in range(1,m):
  y+=i*(m-i)*n*n%mod

ans=v*(t+y)
print(ans%mod)
### BUGGY CODE ###

import math

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

ans = 0
for i in range(60):
    num1 = len([1 for j in range(N) if A[j] & 2**i])
    num0 = N - num1

    ans += ((num1 * num0) * (2 ** i))

print(ans % (10 ** 9 + 7))


### FIXED CODE ###

import math

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

ans = 0
fil = 1
for i in range(60):
    num1 = len([1 for j in range(N) if A[j] & fil])
    num0 = N - num1
    ans += (num1 * num0) * fil
    fil <<= 1

print(ans % (10 ** 9 + 7))
### BUGGY CODE ###

import decimal
n = int(input())
a=[input() for i in range(n)]
biga=[]
for i in range(n):
    num = decimal.Decimal(a[i])
    biga.append(int(num*10**9))
def fact25(n):
    cnt2=0
    cnt5=0
    while True:
        if n%2==0:
            n//=2
            cnt2+=1
        else:
            break
    while True:
        if n%5==0:
            n//=5
            cnt5+=1
        else:
            break
    return cnt2,cnt5
arr = [[0 for _ in range(50)] for _ in range(50)]
p25 = []
for i in range(n):
    cnt2,cnt5=fact25(biga[i])
    p25.append([cnt2,cnt5])
    arr[cnt2][cnt5]+=1
ans=0
for i in range(n):
    cnt2,cnt5=p25[i]
    n2=18-cnt2
    n5=18-cnt5
    arr[cnt2][cnt5]-=1
    for j in range(40): # 2
        for k in range(40): # 5
            if j>=n2 and k>=n5:
                ans+=arr[j][k]
    arr[cnt2][cnt5]+=1

print(ans//2)

### FIXED CODE ###

import decimal
n = int(input())
a=[input() for i in range(n)]
biga=[]
for i in range(n):
    num = decimal.Decimal(a[i])
    biga.append(int(num*10**9))
def fact25(n):
    cnt2=0
    cnt5=0
    while n%2==0:
        n//=2
        cnt2+=1
    while n%5==0:
        n//=5
        cnt5+=1
    return cnt2,cnt5

arr = [[0 for _ in range(20)] for _ in range(20)]
p25 = []
for i in range(n):
    cnt2,cnt5=fact25(biga[i])
    p25.append([cnt2,cnt5])
    cnt2=min(19,cnt2)
    cnt5=min(19,cnt5)
    arr[cnt2][cnt5]+=1

ans=0
for i in range(20): # 2
    for j in range(20): # 5
        if arr[i][j]==0:
            continue
        for k in range(20): # 2
            for l in range(20): # 5
                if i+k>=18 and j+l>=18:
                    if i==k and j==l:
                        ans+= (arr[i][j]-1)*arr[k][l]
                    else:
                        ans+= arr[i][j]*arr[k][l]

print(ans//2)
### BUGGY CODE ###

import sys
import numpy as np
from collections import Counter
input = sys.stdin.readline
n=int(input())
a = tuple(map(int,input().split()))
cnt = Counter(a)
    
def f(i,j,k):
    if [i,j,k] == [0,0,0]:
        return 0.0
    if dp[i][j][k] != 0.0:
        return dp[i][j][k]
    tmp = 0.0
    if i>0:
        tmp += f(i-1,j,k)*(i)/(i+j+k)
    if j>0:
        tmp += f(i+1,j-1,k)*(j)/(i+j+k)
    if k>0:
        tmp += f(i,j+1,k-1)*k/(i+j+k)
    tmp += (n)/(i+j+k)
    dp[i][j][k] = tmp
    return tmp
dp = np.zeros((n+1,n+1,n+1))
#dp = [[[0.0 for i in range(n+1)] for j in range(n+1)] for k in range(n+1)]
 
print(f(cnt[1],cnt[2],cnt[3]))

### FIXED CODE ###

import sys
input = sys.stdin.readline
n = int(input())
a = tuple(map(int,input().split()))
c1 = a.count(1)
c2 = a.count(2)
c3 = a.count(3)

dp = [[[0.0]*(n+1) for i in range(n+1)] for j in range(n+1)] 
dp[0][0][0] = 0
for i in range(c3+1):
    for j in range(c2+c3-i+1):
        for k in range(n-i-j+1):
            if i == j == k == 0:
                continue
            tmp = n
            if k != 0:
                tmp += k*dp[k-1][j][i]
            if j != 0:
                tmp += j*dp[k+1][j-1][i]
            if i != 0:
                tmp += i*dp[k][j+1][i-1]
            dp[k][j][i] = tmp/(i+j+k)

print(dp[c1][c2][c3])
### BUGGY CODE ###

# coding: utf-8
#N = int(input())
A,V=map(int, input().split())
B,W=map(int, input().split())
T=int(input())

if V<=W:
    print("NO")
    quit()

SA=abs(A-B)
i=0
while i<T:
    SA=SA-(V-W)
    i+=1
    
if SA<=0:
    print("YES")
else:
    print("NO")

### FIXED CODE ###

# coding: utf-8
#N = int(input())
A,V=map(int, input().split())
B,W=map(int, input().split())
T=int(input())

if V<=W:
    print("NO")
    quit()

SA=abs(A-B)
CHIJI=(V-W)
SA=SA-(CHIJI*T)
#print(SA)
    
if SA<=0:
    print("YES")
else:
    print("NO")
### BUGGY CODE ###

K,S = map(int,input().split())
#0<=S<=3K
res = 0
for X in range(0,K+1):
    if X > S:
        break
    for Y in range(0,K+1):
        if X + Y > S:
            break
        elif (0<=(S-X-Y)) and ((S-X-Y) <= K):
            res += 1
print(res)

### FIXED CODE ###

K,S = map(int,input().split())
print(sum([0<=S-X-Y<=K for X in range(0,K+1) for Y in range(0,K+1)]))
### BUGGY CODE ###

import math

n,d,a = map(int,input().split())
x = [0]*n
h = [0]*n
for i in range(n):
    x[i] , h[i] = map(int, input().split())
    
itv = [[0 for i in range(2)] for j in range(n)]
for i in range(n):
    itv[i][0] = x[i]
    itv[i][1] = h[i]
itv.sort()
ans = 0
    
for i in range(n):
    atk = 0
    if itv[i][1] > 0:
        atk = math.ceil(itv[i][1]/a)
        itv[i][1] = 0
        for j in range(i+1,n):
            if itv[j][0] <= itv[i][0] + (2*d):
                itv[j][1] -= atk * a
            else:
                break
    ans += atk
    
print(ans)

### FIXED CODE ###

import math
import bisect
 
n,d,a = map(int,input().split())
x = [0]*n
h = [0]*n
for i in range(n):
    x[i] , h[i] = map(int, input().split())
    
itv = [[0 for i in range(2)] for j in range(n)]
for i in range(n):
    itv[i][0] = x[i]
    itv[i][1] = h[i]
itv.sort()
ans = 0

x.sort()
x.append(1145141919810)
h.append(0)

imos = [0]*(n+1)

atk = math.ceil(itv[0][1]/a)
imos[0] += atk * a
b = bisect.bisect(x,itv[0][0] + (2*d))
imos[b] -= atk * a
ans += atk
    
for i in range(1,n):
    atk = 0
    imos[i] += imos[i-1]
    if itv[i][1] > imos[i]:
        atk = math.ceil((itv[i][1]-imos[i])/a)
        imos[i] += atk * a
        b = bisect.bisect(x,itv[i][0] + (2*d))
        imos[b] -= atk * a
    ans += atk

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

int_n = int(input())

power = 1

for i in range(1, int_n + 1):
    power = power * i

print(power % (10 ** 9 + 7))


### FIXED CODE ###

int_n = int(input())

power = 1

for i in range(1, int_n + 1):
    power = (power * i) % (10 ** 9 + 7)

print(power)
### BUGGY CODE ###

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

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
ans = 1
if 0 in a:
  print(0)
else:
  for i in range(n):
    ans *= a[i]
    if ans > pow(10,18):
        ans = -1
        print(ans)
        break
  if ans != -1:
    print(ans)
### BUGGY CODE ###

from functools import reduce
import sys
input = sys.stdin.readline

count = int(input())
list = list(map(int, input().split()))
sum = reduce(lambda x, y: x*y, list)


if sum > 1000000000000000000:
    sum = -1

print(sum)

### FIXED CODE ###

from functools import reduce
from operator import mul
import sys
input = sys.stdin.readline

count = int(input())
list = list(map(int, input().split()))
sum = list[0]
if 0 in list:
    print(0)
    exit()
else:
    for i in range(count - 1):
        sum = sum * list[i + 1]
        if sum > 1000000000000000000:
            print(-1)
            exit()


    print(sum)
### BUGGY CODE ###

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

max_index = 0
max_val = 0
for i in range(N-K+1):
    n = 0
    for j in range(K):
        n += P[i+j]
    if max_val < n:
        max_val = n
        max_index = i

ans = 0

for k in range(K):
    ans += 1.0/2.0*(P[max_index+k]+1)

print(ans)


### FIXED CODE ###

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

cml_sum = [(P[0]+1)/2.0]
for i in range(1, N):
    cml_sum.append(cml_sum[i-1] + (P[i]+1)/2.0)

ans = cml_sum[K-1]
for i in range(N-K):
    target = cml_sum[i+K] - cml_sum[i]
    if ans < target:
        ans = target

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

import sys

def segfunc(x, y):
    return min(x, y)

class segment_():
    def __init__(self, init_val, n, segfunc):
        self.ide_ele = 10**9+1
        # num: n以上の最小の2のべき乗
        self.num = 2**(n-1).bit_length()
        self.seg = [self.ide_ele]*2*self.num
        self.segfunc = segfunc
        # set_val
        for i in range(n):
            self.seg[i+self.num-1] = init_val[i]
        # built
        for i in range(self.num-2, -1, -1):
            self.seg[i] = self.segfunc(self.seg[2*i+1], self.seg[2*i+2])

    def update(self, k, x):
        k += self.num - 1
        self.seg[k] = x
        while k:
            k = (k-1)//2
            self.seg[k] = self.segfunc(self.seg[2*k+1], self.seg[2*k+2])

    def query(self, p, q):
        if q <= p:
            return self.ide_ele
        p += self.num - 1
        q += self.num - 2
        res = self.ide_ele
        while q-p>1:
            if p&1 == 0:
                res = self.segfunc(res, self.seg[p])
            if q&1 == 1:
                res = self.segfunc(res, self.seg[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        if p == q:
            res = self.segfunc(res, self.seg[p])
        else:
            res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q])
        return res

def main():
    n, x = map(int,sys.stdin.readline().split())
    A = list(map(int,sys.stdin.readline().split()))

    seg_ = segment_(A, n, lambda a, b: min(a, b))
    ans = 10**18
    for k in range(n):
        t = 0
        for i in range(n):
            if k <= i:
                t += seg_.query(i-k, i+1)
            else:
                t += min(seg_.query(0, i+1), seg_.query(n-(k-i), n))
        ans = min(t+k*x, ans)
    print(ans)

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys

n, x = map(int,sys.stdin.readline().split())
A = list(map(int,sys.stdin.readline().split()))

ans = 10**18
mins = [a for a in A]
for k in range(n):
    for i in range(n):
        if k <= i:
            mins[i] = min(A[i-k], mins[i])
        else:
            mins[i] = min(A[n-(k-i)], mins[i])
    ans = min(sum(mins)+k*x, ans)
print(ans)
### BUGGY CODE ###

def check_l3(l):
    
    if l[0] < l[1] + l[2] and l[1] < l[0] + l[2] and l[2] < l[1] + l[0]:
        return 1
    else:
        return 0
    
N = int(input())

L = list(map(int , input().split(" ")))

L3 = []

i = 0
j = i + 1
k = j + 1

for i in range(N-2):
    for j in range(j,N-1):
        
        for k in range(k,N):
            l3 = [L[i],L[j],L[k]]
            if l3 not in L3:
                L3.append(l3)
            k = k + 1

        j = j + 1
        k = j + 1
    i = i + 1
    j = i + 1
    k = j + 1

# print(L3) #!!!!!!!

result = 0
for i in range(len(L3)):
    result += check_l3(L3[i])
print(result)

### FIXED CODE ###

n = int(input())
l = list(map(int, input().split()))
# 昇順ソート 
l.sort()
# バイセクションサーチ（二分探索法）のライブラリbisect 
from bisect import bisect_left
# 満たされるべき条件は、a<b<c  a+b>c 
ans = 0
for i in range(n):
  for j in range(i+1, n):
    # ソートした最初の2つの数を足す
    t = l[i]+l[j]
    # bisect_left(対象リスト, 探したい値, lo=左側のインデックス, hi=右側のインデックス)
    # 2つの数の和と同じ数が、リストの何番目に入るかが求められる
    idx = bisect_left(l, t)
    # idxは、a+b=cになる境目
    # idx-(j+1)は a+b>c の条件をみたす、数がいくつあるかを計算している。
    ans += max(0, idx-j-1)
print(ans)
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
s = ''
for i in range(1, n+1):
  s = s + str(a.index(i)+1) + ' '
print(s[:-1])

### FIXED CODE ###

import numpy as np
n = int(input())
a = list(map(int, input().split()))
print(' '.join(list(map(str, np.argsort(a) + 1))))