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):
def ri(): return int(input())
def rli(): return list(map(int, input().split()))
def ris(): return list(input())
def pli(): return "".join(list(map(str, ans)))


N, x = rli()
a = rli()
ans = 2000000000001
magic_time = 0
s_min = a[:]
for i in range(0, N):
    for j in range(N):
        s_min[j] = min(a[j-i], s_min[j])
    ans = min(sum(s_min) + x*i, ans)
print(ans)

Solution (Python):
n,x=map(int,raw_input().split())
a=map(int,raw_input().split())
s=[[10**12]*n for _ in xrange(n)]
for i in xrange(n):
    for j in xrange(n):
        if j==0:s[i][j]=a[i]
        else:s[i][j]=min(s[i][j-1],a[(i-j)%n])
ans=float("inf")
for j in xrange(n):
    tmp=x*j
    for i in xrange(n):
        tmp+=s[i][j]
    ans=min(ans,tmp)
print ans

Solution (Python):
n,x = map(int, raw_input().split())
l = map(int, raw_input().split())
ret = sum(l)
ll = [i for i in l]
for k in range(1,n):
    for i in range(n):
        p = (i+n-k) % n
        ll[i] = min(ll[i], l[p])
    ret = min(ret, sum(ll) + k * x)
print ret

Solution (Python):
N, x = list(map(int, input().split()))
n = N
a = list(map(int, input().split()))
b = [[1000000000000000000000 for i in range(n)] for j in range(n)]
for i in range(n):
	b[i][0] = a[i]
	for j in range(1, n):
		b[i][j] = min(b[i][j-1], a[(i-j+n)%n])
s = [0 for i in range(n)]
for i in range(n):
	for j in range(n):
		s[j] += b[i][j]
ans = 1000000000000000000000
for i in range(n):
	for j in range(n):
		ans = min(ans, j*x+s[j])
print(ans)

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

pos = a.index(min(a))
na = [a[pos]] + a[pos+1:] + a[:pos]

ans = sum(a)
old_b = na[:]
for k in range(1, N):
    b = []
    for i in range(N):
        if i - k >= 0:
            b.append(min(old_b[i], na[i - k]))
        else:
            b.append(old_b[i])
    
    old_b = b
    ans = min(ans, k * x + sum(b))
print(ans)

Solution (Python):
def read():
	return [int(i) for i in input().split(" ")]
N, x = read()
A = read()
ans = sum(A)
tempcost = ans
BC = A[:]
xt = 0
for i in range(1, N):
	xt += x
	BC = [BC[j - 1] if BC[j - 1] < BC[j] else BC[j] for j in range(N)] 
	tempcost = xt + sum(BC)
	if(ans > tempcost):
		ans = tempcost
	else:
		break
print(ans)

Solution (Python):
def read():
	return [int(i) for i in input().split(" ")]
N, x = read()
A = read()
ans = sum(A)
tempcost = ans
BC = A[:]
for i in range(1, N):
	BC = [BC[j - 1] if BC[j - 1] < BC[j] else BC[j] for j in range(N)] 
	tempcost = x * i + sum(BC)
	if(ans > tempcost):
		ans = tempcost
	else:
		break
print(ans)

Solution (Python):
def read():
	return [int(i) for i in input().split(" ")]
N, x = read()
A = read()
ans = sum(A)
tempcost = ans
BC = A[:]
for i in range(1, N):
	BC = [BC[j - 1] if BC[j - 1] < BC[j] else BC[j] for j in range(N)] 
	tempcost = x * i + sum(BC)
	if(ans > tempcost):
		ans = tempcost

print(ans)

Solution (Python):
def read():
	return [int(i) for i in input().split(" ")]
N, x = read()
A = read()
ans = sum(A)
tempcost = ans
BC = A[:]
for i in range(1, N):
	BC = [BC[j - 1] if BC[j - 1] < BC[j] else BC[j] for j in range(N)] 
	tempcost = x * i + sum(BC)
	if(ans > tempcost):
		ans = tempcost
print(ans)

Solution (Python):
def read():
	return [int(i) for i in input().split(" ")]
N, x = read()
A = read()
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)
	if(ans > tempcost):
		ans = tempcost
	else:
		break
print(ans)

Solution (Python):
def read():
	return [int(i) for i in input().split(" ")]
N, x = read()
A = read()
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)
	if(ans > tempcost):
		ans = tempcost
print(ans)

Solution (Python):
n,x=map(int,raw_input().split(" "))
a=map(int,raw_input().split(" "))
t=[i for i in a]
s=10**15
for m in range(n):
    t=[min(t[j],a[(j-m)%n]) for j in range(n)]
    s=min(x*m+sum(t),s)
print s

Solution (Python):
def min_k_shift(k, a, N, x, range_min):
    cost = k*x
    for j in range(N):
        cost += range_min[(j-k)%N][j] 
    return cost

N, x = [int(s) for s in raw_input().split()]

a = [int(s) for s in raw_input().split()]

range_min = [[0]*N for st in range(N)]
for st in range(N):
    range_min[st][st] = a[st]

for k in range(1,N):
    for st in range(N):
        range_min[st][(st+k)%N] = min(range_min[st][(st+k-1)%N],a[(st+k)%N])

print(min(min_k_shift(k,a,N,x,range_min) for k in range(N)))

Solution (Python):



from __future__ import division, print_function, absolute_import, unicode_literals

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

arg_a = a.index(min(a))
a = a[arg_a:] + a[:arg_a]
ans = sum(a)
for t in range(1, N):
    for i in range(N-1, 0, -1):
        a[i] = min(a[i], a[i-1])
    tmp = (t*x) + sum(a)
    ans = min(ans, tmp)
print(ans)

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

Solution (Python):
import sys
import math
N,x = list(map(int,input().split()))
a = list(map(int,input().split()))
ans = sum(a)
mini = a
nx = 0
for i in range(1,N):
	nx += x
	mini = [k if k < mini[j-1] else mini[j-1] for j,k in enumerate(a)]
	s = sum(mini) + nx
	ans = min(s,ans)
print(ans)

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

ans = sum(a)
b = a[:]
c = [0]*n

for k in range(1, n):
	now = k * x
	for i in range(n):
		tmp = min(b[i-1], a[i])
		now += tmp
		c[i] = tmp
	ans = min(ans, now)
	b = c[:]
	
print(ans)

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

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

if __name__=="__main__":
    solve()

Solution (Python):
def mygets():
    return [int(v) for v in input().split(' ')]

n, x = mygets()
a = mygets()

b1 = a

ans = sum(a)
xt = 0
for i in range(1, n):
    xt += x
    b1 = [u if u < b1[k - 1] else b1[k - 1] for k, u in enumerate(a)]
    bsum = sum(b1) + xt
    if bsum < ans:
        ans = bsum
    else:
        break

print(ans)

Solution (Python):
def mygets():
    return [int(v) for v in input().strip().split(' ')]

n, x = mygets()
a = mygets()

b1 = a

ans = sum(a)

for i in range(1, n):
    b2 = [u if u < b1[k - 1] else b1[k - 1] for k, u in enumerate(a)]
    ans = min(ans, sum(b2) + i * x)
    b1 = b2

print(ans)

Solution (Python):
def mygets():
    return list(map(int, input().strip().split(' ')))

n, x = mygets()
a = mygets()

b1 = a

ans = sum(a)

def f(k, u):
    j = k - 1
    if j < 0:
        j = n - 1
    w = b1[j]
    if u < w:
        return u
    return w

for i in range(1, n):
    b2 = [f(k, u) for k, u in enumerate(a)]
    ans = min(ans, sum(b2) + i * x)
    b1 = b2

print(ans)

Solution (Python):
def solve(n, x, a):
	costs = []
	cost_min = 0
	for k in range(n):
		if k == 0:
			costs = a.copy()
		else:
			for i in range(n):
				costs[i] = min(costs[i], a[(i-k)%n])
		cost_k = sum(costs) + k*x
		if k == 0:
			cost_min = cost_k
		else:
			cost_min = min(cost_min, cost_k)
			if cost_min != cost_k:
				break
		if cost_min < (k+1) *x:
			break
 
	return cost_min
n, x = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
print(solve(n,x,a))

Solution (Python):

def solve_():
    import itertools
    N, x = map(int, input().split())
    a = list(map(int, input().split()))
    s_cost = a.copy()
    cost = sum(s_cost)

    for k, i in itertools.product(range(1, N), range(N)):
        s_cost[i] = a[(i - k) % N] if s_cost[i] > a[(i - k) % N] else s_cost[i]
        if i == N - 1 and cost > k*x + sum(s_cost):
            cost = k*x + sum(s_cost)

    print(cost)

solve_()

Solution (Python):
N, x = map(int, input().split())
a = list(map(int, input().split()))
B = a[:] 
         
ans = 10 ** 13
for i in range(N):
    B = [a[j - i] if B[j] > a[j - i] else B[j] for j in range(N)]
    tmp = sum(B) + i * x
    if ans > tmp:
        ans = tmp

print(ans)

Solution (Python):
N, x = map(int, input().split())
a = list(map(int, input().split()))
B = a[:] 
         
ans = 10 ** 13
for i in range(N):
    for j in range(N):
        if B[j] > a[j - i]:
            B[j] = a[j - i]
    tmp = sum(B) + i * x
    if ans > tmp:
        ans = tmp

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
A = A + A


ans = 10**18
for i in range(N):
    for j in range(N):
        if B[j] > A[j+N-i]:
            B[j] = A[j+N-i]

    
    t = sum(B) + x*i
    
    if ans > t:
        ans = t
print(ans)

Solution (Python):
import numpy as np
from copy import deepcopy

N, x = map(int,raw_input().split())
A = map(int,raw_input().split())

def myfunc(N, x, A):
  A = np.array(A)
  B = deepcopy(A)
  m = sum(B)
  for idx in xrange(1,N):
    A = np.append(A, A[0])
    A = np.delete(A, 0)
    np.fmin(B, A, out=B)
    m = min(np.sum(B)+idx*x, m)
  print int(m)

myfunc(N, x, A)

Solution (Python):
import numpy as np
from copy import deepcopy


N, x = map(int,raw_input().split())
A = map(int,raw_input().split())

def myfunc(N, x, A):
  B = deepcopy(np.array(A))
  m = sum(B)
  def apppop(A):
    A.append(A[0])
    A.pop(0)
  for idx in xrange(1,N):
    apppop(A)
    np.fmin(B, A, out=B)
    m = min(np.sum(B)+idx*x, m)
  print int(m)

myfunc(N, x, A)

Solution (Python):
import time
import numpy as np
import copy

tflag = False
if tflag:
  N = 2000
  m = 1000000000
  x = np.random.randint(m)
  A = list(np.random.randint(m,size=(N)))
  st = time.time()
else:
  N, x = map(int,raw_input().split())
  A = map(int,raw_input().split())


B = A
A = A + A
m = sum(B)
for idx in xrange(1,N):
  for jdx in xrange(N):
    if B[jdx] > A[jdx+N-idx]:
      B[jdx] = A[jdx+N-idx]



  m = min(sum(B)+idx*x, m)

print int(m)

Solution (Python):
n,x=map(int,raw_input().split())
a=map(int,raw_input().split())
ans=float('inf')
b=[[float('inf')]*n for _ in xrange(n)]
for i in xrange(n):
    b[i][0]=a[i]
for i in xrange(n):
    for j in xrange(1,n):
        b[i][j]=min(b[i][j-1],a[(i-j)%n])
for j in xrange(n):
    tmp=0
    for i in xrange(n):
        tmp+=b[i][j]
    ans=min(ans,tmp+j*x)
print(ans)

Solution (Python):
n, x = map(int, raw_input().split())
a = map(int, raw_input().split())
ans = 10 ** 18
for i in xrange(n):
    t = sum(a) + x * i
    if ans > t:
        ans = t
    t = a[-1]
    for j in xrange(n - 1, 0, -1):
        if a[j] > a[j-1]:
            a[j] = a[j-1]
    if a[0] > t:
        a[0] = t
print ans

Solution (Python):
def solve(n, x, a):
	costs = []
	cost_min = 0
	for k in range(n):
		if k == 0:
			costs = a.copy()
		else:
			for i in range(n):
				costs[i] = min(costs[i], a[(i-k)%n])
		cost_k = sum(costs) + k*x
		if k == 0:
			cost_min = cost_k
		else:
			cost_min = min(cost_min, cost_k)
			if cost_min != cost_k:
				break
		if cost_min < (k+1) *x:
			break

	return cost_min
n, x = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
print(solve(n,x,a))

Solution (Python):
n, x = map(int, raw_input().split())
a = map(int, raw_input().split())
b = a[:]
a = a + a
ans = 10 ** 18
for i in xrange(n):
    for j in xrange(n):
        if b[j] > a[j+n-i]:
            b[j] = a[j+n-i]
    t = sum(b) + x * i
    if ans > t:
        ans = t
print ans

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**9

def f():
    n,x = list(map(int, input().split()))
    a = list(map(int, input().split()))
    mi = a.index(min(a))
    a = a[mi:] + a[:mi]
    r = sum(a)
    for t in range(n-1):
        for i in range(n-1,0,-1):
            a[i] = min(a[i],a[i-1])
        tr = ((t+1)*x) + sum(a)
        if r > tr:
            r = tr
        else:
            break
    return r

print(f())