Problem:
 Score : 400 points    Problem Statement Snuke lives in another world, where slimes are real creatures and kept by some people.
Slimes come in N colors. Those colors are conveniently numbered 1 through N .
Snuke currently has no slime. His objective is to have slimes of all the colors together.  Snuke can perform the following two actions:    Select a color i ( 1≤i≤N ), such that he does not currently have a slime in color i , and catch a slime in color i . This action takes him a_i seconds.    Cast a spell, which changes the color of all the slimes that he currently has. The color of a slime in color i ( 1≤i≤N-1 ) will become color i+1 , and the color of a slime in color N will become color 1 . This action takes him x seconds.    Find the minimum time that Snuke needs to have slimes in all N colors.      Constraints  2≤N≤2,000  a_i are integers.  1≤a_i≤10^9  x is an integer.  1≤x≤10^9         Input The input is given from Standard Input in the following format:  N  x  a_1  a_2  ...  a_N       Output Find the minimum time that Snuke needs to have slimes in all N colors.        Sample Input 1 2 10
1 100      Sample Output 1 12  Snuke can act as follows:   Catch a slime in color 1 . This takes 1 second.  Cast the spell. The color of the slime changes: 1 → 2 . This takes 10 seconds.  Catch a slime in color 1 . This takes 1 second.        Sample Input 2 3 10
100 1 100      Sample Output 2 23  Snuke can act as follows:   Catch a slime in color 2 . This takes 1 second.  Cast the spell. The color of the slime changes: 2 → 3 . This takes 10 seconds.  Catch a slime in color 2 . This takes 1 second.  Cast the soell. The color of each slime changes: 3 → 1 , 2 → 3 . This takes 10 seconds.  Catch a slime in color 2 . This takes 1 second.        Sample Input 3 4 10
1 2 3 4      Sample Output 3 10  Snuke can act as follows:   Catch a slime in color 1 . This takes 1 second.  Catch a slime in color 2 . This takes 2 seconds.  Catch a slime in color 3 . This takes 3 seconds.  Catch a slime in color 4 . This takes 4 seconds.

Solution (Python):
N, x = map(int, input().split())
A = list(map(int, input().split()))
A += A
INF = 10 ** 18
ans = INF
B = [INF] * N
for cnt in range(N):
    for i in range(N):
        B[i] = min(B[i], A[N + i - cnt])
    ans = min(ans, cnt * x + sum(B))

print(ans)

Solution (Python):
N, x = map(int, input().split())
A = [int(a) for a in input().split()]
M = [a for a in A]

mi = 10**100
for j in range(N):
    s = 0
    for i in range(N):
        s += M[i]
        
    mi = min(mi, s+x*j)
    M = [min(M[i], A[(i-j-1) % N]) for i in range(N)]

print(mi)

Solution (Python):
import numpy as np
N, x = map(int, input().split())
a = np.array(list(map(int, input().split())))
b = np.copy(a)
ans = float('inf') 
for i in range(N):
    c = np.roll(a,i)
    b = np.minimum(b,c)
    ans = min(ans, sum(b)+i*x)
print(ans)

Solution (Python):
N,X = map(int, input().split())
A = list(map(int, input().split()))

ans = float("inf")
bik = A[:]

get_idx_back = lambda idx,b: idx-b if idx>=b else idx+N-b

for loop in range(0, N+1):
  if loop == 0:
      bik = A[:]
  else: 
      for i in range(N):
          bik[i] = min(bik[i], A[ get_idx_back(i, loop) ])

  tmp = (loop)*X + sum(bik)

  ans = min(tmp, ans)
print(ans)
exit(0)

Solution (Python):


import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n, x = LI()
    A = LI()

    min_a, min_i = INF, -1
    res = 0
    for i, a in enumerate(A):
        if a < min_a:
            min_a = a
            min_i = i
        res += a
    A = A[min_i:] + A[:min_i]

    dp = [INF] + A
    for k in range(n - 1):
        tmp = 0
        for i in range(n)[::-1]:
            if dp[i + 1] > dp[i]:
                dp[i + 1] = dp[i]
            tmp += dp[i + 1]

        res = min(res, tmp + (k + 1) * x)

    return res


print(main())

Solution (Python):
n, x = map(int, input().split())
a = list(map(int, input().split()))

DP = a[:]
ans = sum(DP)
for i in range(n-1):
    new = [0]*n
    for j in range(n):
        new[j] = min(DP[j], DP[j-1])
    DP=new
    ans = min(ans, sum(DP) + (i+1)*x)
print(ans)

Solution (Python):
n, x = map(int, input().split())
a = list(map(int, input().split()))


DP = a[:]
ans = sum(DP)
for i in range(n-1):
    DP = [min(DP[j],DP[j-1]) for j in range(n)]
    ans = min(ans, sum(DP) + (i+1)*x)
print(ans)

Solution (Python):
import sys
input=sys.stdin.readline
n,x=map(int,input().split())
A=list(map(int,input().split()))
T=A[:]
ans=sum(T)
for j in range(1,n):
    T=[min(T[i],A[i-j]) for i in range(n)]
    ans=min(ans,sum(T)+x*j)
print(ans)

Solution (Python):
n,x = map(int,input().split())
a = list(map(int,input().split()))


p = [[0]*n for i in range(n)]


for i in range(n):
  p[i][0]=a[i]
  for j in range(1,n):
    if i-j>=0:
      p[i][j]=min(a[i-j],p[i][j-1])
    elif i-j == -1:
      p[i][j]=min(a[n-1],p[i][j-1])
    else:  
      p[i][j]=min(a[n-(j-i)],p[i][j-1])
p = list(zip(*p))
ans = sum(p[0])
for i in range(1,n):
  ans = min(ans,sum(p[i])+x*i)
print(ans)

Solution (Python):
loop, magic_cost = map(int, input().split(" "))
cost = [n for n in map(int, input().split(" "))]
answer = float("inf")
min_costs = [float("inf") for n in range(loop)]
for i in range(loop):
    for j in range(loop):
        min_costs[j] = min(min_costs[j], cost[(i - j) % loop])
    answer = min(answer, sum(min_costs) + (magic_cost * (i) ) )
print(answer)

Solution (Python):
n,x=map(int, input().split())
a=list(map(int, input().split()))
b=a[:]
ans=float('inf')
for i in range(n):
    for j in range(n):
        b[j]=min(b[j],a[j-i])
    ans=min(ans,sum(b)+x*i)
print(ans)

Solution (Python):
N, x = map(int, input().split())
a = list(map(int, input().split()))
INF = float("inf")
num = INF
rec = [INF] * N
for k in range(N):
    tmp = 0
    for j in range(N):
        rec[j] = min(rec[j], a[j - k])
        tmp += rec[j]

    num = min(tmp + k * x, num)

print(num)

Solution (Python):
n, x = map(int, input().split())
a = list(map(int, input().split()))

INF = float('inf')
dp = [[INF] * (n+10) for _ in range(n)]

for i in range(n):
    for k in range(n):
        if k == 0:
            dp[i][k] = a[i]
        else:
            dp[i][k] = min(dp[i][k-1], a[(i-k)%n])

ans = INF

for k in range(n):
    tmp = x * k
    for i in range(n):
        tmp += dp[i][k]
    ans = min(ans, tmp)

print(ans)

Solution (Python):
N, x = map(int,input().split())
A = list(map(int,input().split()))
T = [A[k] for k in range(N)]

ans = sum(A)
A = A+A

for k in range(1,N):
    for l in range(N):
        T[l] = min(T[l],A[N+l-k])
    ans = min(ans,sum(T)+k*x)

print(ans)

Solution (Python):
from collections import Counter
def inpl(): return list(map(int, input().split()))
N, x = inpl()
A = inpl()
B = [a for a in A]

ans = 1e15
for i in range(N+1):
    for j in range(N):
        B[j] = min(B[j], A[(j-i)%N])
    tmp = x*i + sum(B)
    ans = min(ans, tmp)
print(ans)

Solution (Python):
N,X = map(int,input().split())
A = list(map(int,input().split()))

INF = float('inf')
dp = [[INF]*N for i in range(N+1)]
dp[0] = A[:]

ans = sum(A)
for k in range(N):
    cost = k*X
    if cost > ans: break
    for i in range(N):
        dp[k+1][i] = min(dp[k][i], A[i-k])
    cost += sum(dp[k+1])
    ans = min(ans, cost)

print(ans)

Solution (Python):
n, x = map(int, input().split())
a = [int(m) for m in input().split()]


memos = []
for k in range(n):
    memos.append([float("INF") for i in range(n)])

def f(i,k):
    if k == 0:
        memos[k][i] = a[i]
        return a[i]
    if memos[k][i] != float("INF"):
        return memos[k][i]
    else:
        memos[k][i] = min(f(i, k - 1), a[i - k])
        return memos[k][i]

ansli = []
tmpsum = 0
for k in range(n):
    for i in range(n):
        tmpsum += f(i, k)
    ansli.append(x * k + tmpsum)
    tmpsum = 0

print(min(ansli))

Solution (Python):
N, x = map(int, input().split())
a_list = list(map(int, input().split()))

ans = float("inf")
cost_list = [float("inf") for _ in range(N)]
for i in range(N):
    cost = 0
    for j in range(N):
        if i == 0:
            cost += a_list[j]
            cost_list[j] = a_list[j]
        else:
            tmp = cost_list[j]
            if tmp > a_list[- i + j]:
                cost_list[j] = a_list[- i + j]
                cost += a_list[- i + j]
            else:
                cost += tmp

    cost += x * i
    ans = min(ans, cost)
print(ans)

Solution (Python):
N, x = map(int, input().split())
a_list = list(map(int, input().split()))
ex_list = a_list.copy()
ex_list.extend(a_list)

ans = float("inf")
cost_list = [float("inf") for _ in range(N)]
for i in range(N):
    cost = 0
    for j in range(N):
        if i == 0:
            cost += ex_list[N + j]
            cost_list[j] = ex_list[N + j]
        else:
            tmp = cost_list[j]
            if tmp > ex_list[N - i + j]:
                cost_list[j] = ex_list[N - i + j]
                cost += ex_list[N - i + j]
            else:
                cost += tmp

    cost += x * i
    ans = min(ans, cost)
print(ans)

Solution (Python):
N, x = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]

ans = sum(A)
for k in range(1, N + 1):
    A = [min(i, j) for i, j in zip(A, A[1:] + [A[0]])]
    ans = min(ans, x * k + sum(A))
print(ans)

Solution (Python):

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

M = [[float("inf")]*N for k in range(N)]
for k in range(N):
    M[0][k] = A[k]

for k in range(N):
    for l in range(N):
        M[k][l] = min(M[k-1][l],A[k-l])

ans = sum(A)
for k in range(1,N):
    ans = min(ans,sum(M[k])+x*k)

print(ans)

Solution (Python):
n, x = map(int, input().split())
a = list(map(int, input().split()))

min_list = [[a[i] for i in range(n)] for _ in range(n)]
for i in range(1, n):
	for j in range(n):
		min_list[i][j] = min(min_list[i-1][j], a[(j-i) % n])

ans = float("inf")
for i in range(n):
	ans = min(ans, x * i + sum(min_list[i]))

print(ans)

Solution (Python):
from copy import deepcopy
N,X=map(int,input().split())
A=[int(i) for i in input().split()]
B=deepcopy(A)
ans=sum(A)
for t in range(1,N):
    for i in range(N):
        if B[i]>A[i-t]:
            B[i]=A[i-t]
    ans=min(ans,sum(B)+t*X)
print(ans)

Solution (Python):
N,x=map(int,input().split())
a=[int(i) for i in input().split()]
for i in range(N):
  a.append(a[i])
dp=[[float("inf")]*N for i in range(N)]
ans=float("inf")
for k in range(N):
  for i in range(N):
    if k==0:
      dp[k][i]=a[N+i]
    else:
      dp[k][i]=min(dp[k-1][i],a[N+i-k])
  ans=min(ans,k*x+sum(dp[k]))
    
print(ans)

Solution (Python):
n, x = map(int, input().split())
a = list(map(int, input().split()))
 
b = a[::]
ans = sum(a)
 
for k in range(1, n):
    b = [min(b[i], a[i - k]) for i in range(n)]
    ans = min(ans, sum(b) + k * x)
print(ans)

Solution (Python):
from copy import deepcopy
N, x = map(int, input().split())
A = [int(a) for a in input().split()]

minA = deepcopy(A)
Ans = sum(minA) 
for i in range(1, N): 
    for j in range(N):
        minA[j] = min(minA[j], A[j-i])
    Ans = min(Ans, x * i + sum(minA))
print(Ans)

Solution (Python):
def inpl(): return [int(i) for i in input().split()]
import numpy as np
N, x = inpl()
a = np.array(inpl())
b = np.copy(a)
ans = float('inf') 
for i in range(N):
    c = np.roll(a,i)
    b = np.minimum(b,c)
    ans = min(ans, sum(b)+i*x)
print(ans)

Solution (Python):
n,x = map(int,input().split())
a = list(map(int,input().split()))
MIN = sum(a)
ans = MIN+0
tori = a + [0]
tori.pop()
for i in range(1,n):
  for j in range(n):
    ido = i+j
    if ido >= n:
      ido-=n
    if tori[j] > a[ido]:
      ans -= (tori[j] - a[ido])
      tori[j] = a[ido]
  MIN = min(ans + i*x,MIN)
print(MIN)

Solution (Python):
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,x = li()
a = list(li())

mins = [ai for ai in a]
a = a+a

ans = 10**18
for k in range(n):
    for i in range(n,2*n):
        mins[i-n] = min(mins[i-n], a[i-k])
        
    ans = min(ans, sum(mins) + x*k)
    
print(ans)

Solution (Python):
N,X = map(int,input().split())
A = list(map(int,input().split()))

ans = sum(A)
costs = A[:]
for i in range(1,N):
    cost = i*X
    if cost >= ans: break
    for j in range(N):
        costs[j] = min(costs[j], A[(j-i)%N])
        cost += costs[j]
    ans = min(ans, cost)

print(ans)

Solution (Python):
N, x = map(int, input().split())
As = list(map(int, input().split()))

ans = float('inf')
costs = list(As)
for i in range(N):
    ans = min(ans, sum(costs) + x * i)
    costs = list(map(min, zip(costs, As[-i-1:] + As[:-i-1])))

print(ans)

Solution (Python):

n,x = map(int, input().split())
a = [int(i) for i in input().split()]
b = [a[i] for i in range(n)]

ret = sum(a)
for k in range(n):
    for i in range(n):
        b[i] = min(b[i], a[(i+n-k)%n])
    ret = min(ret, k*x+sum(b))
print(ret)

Solution (Python):
r=lambda :map(int,input().split())
n,x=r()
*a,=r()
dp=[[0]*n for _ in range(n)]
for i,j in enumerate(a):
  dp[0][i]=j
for i in range(1,n):
  for j in range(n):
    dp[i][j]=min(dp[i-1][j],a[(j-i)%n])
print(min(i*x+sum(j) for i,j in enumerate(dp)))

Solution (Python):


INF = float('inf')


def inpl(): return list(map(int, input().split()))


N, x = inpl()
A = inpl()

min_index = A.index(min(A))
B = A[min_index:] + A[:min_index]

cost = [B[i] for i in range(N)]

ans = INF
for magic in range(N):
    for i in range(N):
        if i - magic >= 0:
            cost[i] = min(cost[i], B[i - magic])

    ans = min(ans, sum(cost) + x * magic)

print(ans)

Solution (Python):
n, x = map(int, input().split())
a = list(map(int, input().split()))

b = [] + a
ans = sum(a)
temp = [0 for _ in range(n)]
for i in range(1, n):
    r = a[n - i:] + a[:n - i]
    for j in range(n):
        temp[j] = min(b[j], r[j])
    ans = min(ans, sum(temp) + i * x)
    b = [] + temp

print(ans)

Solution (Python):
ai = lambda: list(map(int, input().split()))

n,x = ai()
a = ai()

ma = [[] for _ in range(n)]
for i in range(n):
    ma[i].append(a[i])
    for j in range(1,n):
        if ma[i][-1] > a[i-j]:
            ma[i].append(a[i-j])
        else:
            ma[i].append(ma[i][-1])


def m(k):
    return sum(ma[i][k] for i in range(n))


print(min(m(k) + x*k for k in range(n)))

Solution (Python):
n, x = map(int, input().split())
a = list(map(int, input().split()))
a += a
mah = [10000000000]*n
ans = float("inf")
for i in range(1, n+1):
    t = 0
    for j in range(n):
        if mah[j] > a[j + i]:
            mah[j] = a[j+i]
        t += mah[j]
    ans = min(ans, t+x*(i-1))
print(ans)

Solution (Python):
n,x = map(int,input().split())
a = list(map(int,input().split()))

ans = sum(a)
mini = []
for i in range(n):
    mini.append(a[i])


for k in range(1,n+1): 
    total = 0
    for i in range(n):
        if mini[i] > a[(i-k+n)%n]:
            mini[i] = a[(i-k+n)%n]
        total += mini[i]
    total += k*x
    if total < ans:
        ans = total

print(ans)

Solution (Python):
n, x = map(int, input().split())
a = list(map(int, input().split()))
ans = sum(a)
tempcost = ans
xt = 0
bc = a
for i in range(1, n):
    xt += x
    a = [a[-1]] + a[0:-1]
    bc = [v if v < bc[i] else bc[i] for (i, v) in enumerate(a)]
    tempcost = xt + sum(bc)
    ans = min(ans, tempcost)
print(ans)

Solution (Python):


INF = float('inf')


def inpl(): return list(map(int, input().split()))


N, x = inpl()
A = inpl()

min_cost_s = 0
tmp = INF
for i in range(N):
    if A[i] < tmp:
        min_cost_s = i
        tmp = A[i]

A = A[min_cost_s:] + A[:min_cost_s]
B = [A[i] for i in range(N)]

ans = INF
for shift in range(N):
    for i in range(N):
        if i - shift >= 0:
            B[i] = min(B[i], A[i - shift])
    

    ans = min(ans, shift * x + sum(B))

print(ans)

Solution (Python):
N, x, *A = map(int, open(0).read().split())

B = A[:]
ans = sum(A)

for k in range(1, N):
    B = [min(B[i], A[i - k]) for i in range(N)]
    tmp = sum(B) + k * x
    if tmp < ans:
        ans = tmp
    else:
        break
print(ans)

Solution (Python):
N, x = map(int, input().split())
A = list(map(int, input().split()))

B = A[:]
ans = sum(A)

for k in range(1, N):
    B = [min(B[i], A[i - k]) for i in range(N)]
    ans = min(ans, sum(B) + k * x)
print(ans)

Solution (Python):
N, x, *A = map(int, open(0).read().split())

B = A[:]
ans = sum(A)

for k in range(1, N):
    B = [min(v, A[i - k]) for i, v in enumerate(B)]
    ans = min(ans, sum(B) + k * x)
print(ans)

Solution (Python):
N, x, *A = map(int, open(0).read().split())

B = A[:]
ans = sum(A)

for k in range(1, N):
    B = [min(B[i], A[i - k]) for i in range(N)]
    ans = min(ans, sum(B) + k * x)
print(ans)

Solution (Python):
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

n,x = li()
a = li()

mins = [ai for ai in a]
a2 = a+a

ans = sum(mins)
for k in range(n):
    for i in range(n):
        mins[i] = min(mins[i],a2[i+k])
    
    temp = sum(mins)    
    ans = min(ans, temp + k*x)
    
print(ans)

Solution (Python):
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

n,x = li()
a = li()

mins = [ai for ai in a]
a2 = a+a

ans = sum(mins)
for k in range(n):
    for i in range(n):
        mins[i] = min(mins[i],a2[i+k])
    
    temp = sum(mins)    
    ans = min(ans, temp + k*x)
    
print(ans)

Solution (Python):

def inpl(): return list(map(int, input().split()))
N, x = inpl()
A = inpl()
ans = sum(A)

for i in range(1, N):
    A = [min(A[j], A[(j-1)%N]) for j in range(N)]
    ans = min(ans, sum(A) + x*i)

print(ans)

Solution (Python):
N,x=map(int,input().split())
a=[int(i) for i in input().split()]
b=[[0 for k in range(N)] for i in range(N)]
for k in range(N):
    for i in range(N):
        if k==0:
            b[i][k]=a[i]
        else:
            b[i][k]=min([b[i][k-1],a[i-k]])
ans=sum(a)
for k in range(N):
    tmp=k*x
    for i in range(N):
        tmp+=b[i][k]
    if tmp<ans:
        ans=tmp
print(ans)

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, X, A):

    ans = sys.maxsize
    mc = [(sys.maxsize, -1)] * N
    for k in range(N):
        ac = 0
        for i in range(N):
            mc[i] = min(mc[i], (A[i-k], k), key=lambda x: x[0])
            ac += A[i-mc[i][1]]
        ac += k*X
        ans = min(ans, ac)

    return ans


def main():
    N, X = read_int_n()
    A = read_int_n()
    print(slv(N, X, A))


if __name__ == '__main__':
    main()

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, X, A):

    ans = sys.maxsize
    mc = [(sys.maxsize, -1)] * N
    for k in range(N):
        ac = 0
        for i in range(N):
            mc[i] = min(mc[i], (A[i-k], k), key=lambda x: x[0])
            ac += A[i-mc[i][1]]
        ac += k*X
        ans = min(ans, ac)

    return ans


def main():
    N, X = read_int_n()
    A = read_int_n()
    print(slv(N, X, A))


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    n, x = map(int, input().split())
    a = list(map(int, input().split()))

    min_t = 10 ** 15
    b = [10 ** 10 for i in range(n)]
    for i in range(n):
        t = i * x
        for j in range(n):
            b[j] = min(b[j], a[(j-i) % n])
            t += b[j]

        min_t = min(min_t, t)

    print(min_t)


if __name__ == '__main__':
    main()

Solution (Python):
n, x = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]

B = A[:]
ans = sum(A)

for i in range(1, n):
    for j in range(n):
        B[j] = min(B[j], A[j-i])
    ans = min(ans, sum(B) + i * x)

print(ans)

Solution (Python):
n, x = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]

B = A[:]
ans = sum(A)

for i in range(1, n):
    B = [min(B[j], A[j-i]) for j in range(n)]
    ans = min(ans, sum(B) + i * x)

print(ans)

Solution (Python):
n, x = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]

B = A[:]
ans = sum(A)

for i in range(1, n):
    for j in range(n):
        B[j] = min(B[j], A[j-i])
    ans = min(ans, sum(B) + i * x)

print(ans)

Solution (Python):
n, x = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]

B = A[:]
ans = sum(A)

for i in range(1, n):
    for j in range(n):
        if A[j-i] < B[j]:
            B[j] = A[j-i]
    ans = min(ans, sum(B) + i * x)

print(ans)

Solution (Python):
n, x = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]

B = [a for a in A]
ans = sum(A)

for i in range(1, n):
    for j in range(n):
        if A[j-i] < B[j]:
            B[j] = A[j-i]
    ans = min(ans, sum(B) + i * x)

print(ans)

Solution (Python):
N, X = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]

def solve(N, X, A):
    M = A[:]
    result = sum(M)
    for i in range(1, N):
        M = [min(M[j], A[(j-i)%N]) for j in range(N)]
        r = sum(M) + X * i
        result = min(result, r)
    return result

print(solve(N, X, A))

Solution (Python):
N, X = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]

def solve0(N, X, A):
    A2 = A + A
    T = [
        [min(A2[N+j+1-i-1:N+j+1]) for j in range(N)]
        for i in range(N)
    ]
    mins = [
        sum(T[i]) + i * X
        for i in range(N)
    ]
    result = min(mins)
    return result

def solve(N, X, A):
    M = A[:]
    result = sum(M)
    for i in range(1, N):
        M = [min(M[j], A[(j-i)%N]) for j in range(N)]
        r = sum(M) + X * i
        result = min(result, r)
    return result

print(solve(N, X, A))

Solution (Python):
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect
from random import *

def read():
  return int(input())
 
def reads():
  return [int(x) for x in input().split()]

N, x = reads()
A = reads()

INF = 1 << 60
smin = [[INF] * N for _ in range(N)]
for i in range(N):
  smin[i][0] = A[i]
  for j in range(1, N):
    smin[i][j] = min(smin[i][j-1], A[(i-j)%N])

ans = INF
for j in range(N):
  h = sum(smin[i][j] for i in range(N)) + x * j
  ans = min(ans, h)
print(ans)

Solution (Python):
N, x = map(int, input().split())
A = list(map(int, input().split()))
ans = float("inf")
Mi = [float("inf")] * N
for i in range(N):
    for j in range(N):
        Mi[j] = min(Mi[j], A[j-i])
    ans = min(ans, x*i + sum(Mi))
print(ans)

Solution (Python):
n, x = map(int, input().split())
a = list(map(int, input().split()))

mins = a[:]
result = float("inf")

for k in range(n):
    for i in range(len(mins)):
        mins[i] = min(a[i - k], mins[i])
    result = min(x * k + sum(mins), result)

print(result)

Solution (Python):
n,x = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
ans,b,c = sum(a),[i for i in a],[i for i in range(n)]
for i in range(n):
	for j in range(n): c[j] = min(a[j-i],b[j])
	ans,b,c = min(ans,sum(c)+x*i),c,b
print(ans)

Solution (Python):
n, x = map(int,input().split())
slimes = list(map(int,input().split()))
p = slimes[:]
ans = 5000000000000000

for i in range(n):
    for j in range(n):
        if p[j] > slimes[j-i]:
            p[j] = slimes[j-i]
    ans = min(ans, sum(p) + i * x)
print(ans)

Solution (Python):
N,x=map(int,input().split())
A=[int(x) for x in input().split()]
dp=A[:]






ans=sum(A)
for k in range(1,N):
  for i in range(N):
    if dp[i]>A[i-k]:
      dp[i]=A[i-k]
  ans=min(ans,sum(dp)+x*k)

print(ans)

Solution (Python):
N, x = map(int, input().split())
a = list(map(int, input().split()))
ans = float("INF")
b = [float("INF")]*N
for k in range(N):
    temp_ans = k*x
    for i in range(N):
        t = a[i-k]
        if t < b[i]:
            b[i] = t
        temp_ans += b[i]
    ans = min(ans,temp_ans)
print(ans)

Solution (Python):
def main():
    N, x = map(int, input().split())
    a = list(map(int, input().split()))
    ans = float("INF")
    b = [float("INF")]*N
    for k in range(N):
        temp_ans = k*x
        for i in range(N):
            t = a[i-k]
            if t < b[i]:
                b[i] = t
            temp_ans += b[i]
        ans = min(ans,temp_ans)
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
def main():
    N, x = map(int, input().split())
    a = list(map(int, input().split()))
    ans = float("INF")
    b = [float("INF")]*N
    for k in range(N):
        temp_ans = k*x
        for i in range(N):
            b[i] = min(b[i],a[i-k])
            temp_ans += b[i]
        ans = min(ans,temp_ans)
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
N, x = map(int, input().split())
a = list(map(int, input().split()))

ans = float("INF")
b = [[float("INF")]*N for _ in range(N)]
b[0] = a
for k in range(N):
    for i in range(N):
        b[k][i] = min(b[k-1][i],a[i-k])
    ans = min(ans, sum(b[k])+k*x)

print(ans)

Solution (Python):
import sys

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, x] = [int(input_raw[0]), long(input_raw[1])]
    A = []
    input_raw = read_func().strip().split()
    for i in range(N):
        A.append(long(input_raw[i]))

    min_time = long(sys.maxint * sys.maxint)
    min_A = [0L for i in range(N)]
    for k in range(N):
        sum_min_A = 0L
        for i in range(N):
            if k == 0:
                min_A[i] = A[i]
            else:
                i + k
                min_A[i] = min(min_A[i], A[(i + k)%N])
            sum_min_A += min_A[i]
        time = sum_min_A + x * long(k)
        if time < min_time:
            min_time = time
    print min_time

























if __name__ == '__main__':
    main()

Solution (Python):
n, x = map(int, input().split())
a = [int(x) for x in input().split()]
b = [None] * n
for i, c in enumerate(a):
    b[i] = [None] * n
    b[i][0] = a[i]
    for j in range(1, n): b[i][j] = min(b[i][j - 1], a[(i - j) % n])
d = None
for i in range(n):
    c = i * x
    for j in range(n): c += b[j][i]
    if d is None or c < d: d = c
print(d)

Solution (Python):
n, x = map(int, input().split())
a = [int(x) for x in input().split()]
b = [None] * n
for i, c in enumerate(a):
    b[i] = [None] * n
    b[i][0] = a[i]
    for j in range(1, n): b[i][j] = min(b[i][j - 1], a[(i - j) % n])
d = None
for i in range(n):
    c = i * x
    for j in range(n): c += b[j][i]
    if d is None or c < d:
        d = c
print(d)

Solution (Python):
N, x = map(int, input().split())
A = list(map(int, input().split())) * 2
A = A[::-1]

effective_costs = [float('inf')] * N
ans = float('inf')


for k in range(N):
    effective_costs = [min(effective_costs[i], A[i+k]) for i in range(N)]
    ans = min(ans, sum(effective_costs) + k * x)

print(ans)

Solution (Python):
N, x = map(int, input().split())
A = list(map(int, input().split()))
lowest_costs = A[:]
ans = float('inf')

for k in range(N):
    lowest_costs = [min(lowest_costs[i], A[i-k]) for i in range(N)]
    ans = min(sum(lowest_costs) + x * k, ans)

print(ans)

Solution (Python):
n, x = map(int, input().split())
a = list(map(int, input().split()))


ans = sum(a)
time = a[:]


for j in range(1, n):
    
    for i in range(n):
        time[i] = min(time[i], a[i - j])
    ans = min(ans, j * x + sum(time))

print(ans)

Solution (Python):
N, x = list(map(int, input().split()))
a = list(map(int, input().split()))
s_cost = a.copy()
cost = sum(s_cost)
for k in range(1,N):
    for i in range(N):
        if s_cost[i] > a[(i-k)%N] :
            s_cost[i] = a[(i-k)%N]
    if cost > k*x + sum(s_cost):
        cost = k*x + sum(s_cost)
    else:
        break

print(cost)

Solution (Python):

N, x = map(int, input().split())
a = list(map(int, input().split()))

b = a[:]
ans = float('inf')
for i in range(N):
    b = [min(b[j], a[j - i]) for j in range(N)]
    ans = min(ans, i * x + sum(b))
print(ans)

Solution (Python):
N,X = map(int,input().split())
src = list(map(int,input().split()))
dp = src[:]
ans = float('inf')
for n in range(N):
    for m in range(N):
       if dp[m] > src[m-n]:
           dp[m] = src[m-n]
    ans = min(ans, sum(dp)+n*X)
print(ans)

Solution (Python):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = float("inf")
 
 
def main():
    N, x = map(int, input().split())
    a_list = list(map(int, input().split()))
 
    ans = INF
    m = [INF] * N
    for rotate in range(N):
        total_time = rotate * x
        for i in range(N):
            t = a_list[i - rotate]
            if t < m[i]:
                m[i] = t
            total_time += m[i]
        ans = min(ans, total_time)
    print(ans)
 
 
if __name__ == '__main__':
    main()