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 in C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<int,int>;
using PP=pair<int,P>;
using Pl=pair<ll,ll>;
using PPl=pair<ll,Pl>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
template<typename Monoid>
struct SegTree{
    //0-indexed
    using F=function<Monoid(Monoid,Monoid)>;
    int size;       //要素数
    vector<Monoid> dat;
    const F func;   //二項演算
    const Monoid Mdef;  //初期値
    SegTree(int sz,const F func,const Monoid &Mdef):func(func),Mdef(Mdef)
    {
        size=1;
        while(size<sz){
            size*=2;
        }
        dat.assign(size*2,Mdef);
    }
    void set(int k,const Monoid&x){
        //k番目の要素をxで初期化
        //あとでbuildが必要
        dat[k+size-1]=x;
    }
    void build(){
        //構築 O(N)
        for(int k=size-2;k>=0;k--){
            dat[k]=func(dat[k*2+1],dat[k*2+2]);
        }
    }
    void update(int k,const Monoid& x){
        //k番目の要素をxに変更 O(log N)
        int now=k+size-1;
        dat[now]=x;
        while(now){
            now=(now-1)/2;
            dat[now]=func(dat[now*2+1],dat[now*2+2]);
        }
    }
    Monoid _query(int a,int b,int k,int l,int r){
        if(r<a||b<l){
            return Mdef;
        }
        if(a<=l&&b>=r){
            return dat[k];
        }
        auto tl=_query(a,b,k*2+1,l,(l+r)/2);
        auto tr=_query(a,b,k*2+2,(l+r)/2+1,r);
        return func(tl,tr);
    }
    Monoid query(int l,int r){
        //[l,r]に対する演算funcの結果を返す O(log N)
        return _query(l,r,0,0,size-1);
    }
    Monoid operator[](const int &k)const{
        return dat[k+size-1];
    }
    int Size(){
        return size;
    }
};
ll rmq(SegTree<ll>& tr,int l,int r){
    ll res;
    if(l<=r){
        res=tr.query(l,r);
    }else{
        res=min(tr.query(l,tr.Size()-1),tr.query(0,r));
    }
    return res;
}
int main(){
    int n;
    ll x;
    cin>>n>>x;
    SegTree<ll> tr(n,[](ll a,ll b){return min(a,b);},LINF);
    REP(i,n){
        ll t;
        cin>>t;
        tr.set(i,t);
    }
    tr.build();
    ll ans=LINF;
    REP(i,n){//何回魔法を使うか
        ll sum=x*i;
        REP(j,n){
            sum+=rmq(tr,(j-i+n)%n,j);
        }
        chmin(ans,sum);
    }
    cout<<ans<<endl;
    return 0;
}