Buggy python submission (verdict: Time Limit Exceeded):
N, x = map(int,input().split())
a = list(map(int,input().split()))

inf = float('inf')
ans = inf

time = [[inf] * N for _ in range(N)]

for i in range(N):
    tmp = inf
    for k in range(N):
        ni = i + k
        if ni > N - 1:
            ni %= N
        tmp = min(tmp, a[ni])
        time[i][k] = tmp

# k回魔法を唱える
for k in range(N):
    res = k*x
    for i in range(N):
        res += time[i][k]
    ans = min(ans, res)

print(ans)

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

inf = float('inf')
ans = inf

time = [[inf] * N for _ in range(N)]

for i in range(N):
    tmp = inf
    for k in range(N):
        ni = i + k
        if ni > N - 1:
            ni %= N
        tmp = min(tmp, a[ni])
        time[i][k] = tmp

# k回魔法を唱える
for k in range(N):
    res = k*x
    for i in range(N):
        res += time[i][k]
    ans = min(ans, res)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, x = map(int,input().split())
a = list(map(int,input().split()))

inf = float('inf')
ans = inf

class SegmentTree:
    def __init__(self, N):
        self.N = 2**(N-1).bit_length()
        self.data = [inf for _ in range(2*self.N)]
    
    def update(self, k, x):
        k += self.N-1
        self.data[k] = x
        while k >= 0:
            k = (k - 1) // 2
            self.data[k] = min([self.data[2*k+1], self.data[2*k+2]])
            
    
    # [l,r)
    def query(self, l, r):
        L = l + self.N
        R = r + self.N
        s = inf
        while L < R:
            if R & 1:
                R -= 1
                s = min([s, self.data[R-1]])
            
            if L & 1:
                s = min([s, self. data[L-1]])
                L += 1
            L >>= 1; R >>= 1
        return s

st = SegmentTree(N)
for i, ai in enumerate(a):
    st.update(i, ai)

def time(i, k):
    if i+k+1 <= N:
        tmp = st.query(i, i+k+1)
    else:
        tmp = min(st.query(0, (i+k) % N + 1), st.query(i, N))
    return tmp

# k回魔法を唱える
for k in range(N):
    res = k*x
    for i in range(N):
        res += time(i, k)
    ans = min(ans, res)

print(ans)

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

inf = float('inf')
ans = inf

time = [[inf] * N for _ in range(N)]

for i in range(N):
    tmp = inf
    for k in range(N):
        ni = i + k
        if ni > N - 1:
            ni %= N
        tmp = min(tmp, a[ni])
        time[i][k] = tmp

# k回魔法を唱える
for k in range(N):
    res = k*x
    for i in range(N):
        res += time[i][k]
    ans = min(ans, res)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N, x = map(int,input().split())
a = list(map(int,input().split()))

inf = float('inf')
ans = inf

class SegmentTree:
    def __init__(self, N):
        self.N = 2**(N-1).bit_length()
        self.data = [inf for _ in range(2*self.N)]
    
    def update(self, k, x):
        k += self.N-1
        self.data[k] = x
        while k >= 0:
            k = (k - 1) // 2
            self.data[k] = min([self.data[2*k+1], self.data[2*k+2]])
            
    
    # [l,r)
    def query(self, l, r):
        L = l + self.N
        R = r + self.N
        s = inf
        while L < R:
            if R & 1:
                R -= 1
                s = min([s, self.data[R-1]])
            
            if L & 1:
                s = min([s, self. data[L-1]])
                L += 1
            L >>= 1; R >>= 1
        return s

st = SegmentTree(N)
for i, ai in enumerate(a):
    st.update(i, ai)

def time(i, k):
    if i+k+1 <= N:
        tmp = st.query(i, i+k+1)
    else:
        tmp = min(st.query(0, (i+k) % N + 1), st.query(i, N))
    return tmp

# k回魔法を唱える
for k in range(N):
    res = k*x
    for i in range(N):
        res += time(i, k)
    ans = min(ans, res)

print(ans)

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

inf = float('inf')
ans = inf

time = [[inf] * N for _ in range(N)]

for i in range(N):
    tmp = inf
    for k in range(N):
        ni = i + k
        if ni > N - 1:
            ni %= N
        tmp = min(tmp, a[ni])
        time[i][k] = tmp

# k回魔法を唱える
for k in range(N):
    res = k*x
    for i in range(N):
        res += time[i][k]
    ans = min(ans, res)

print(ans)