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: Wrong Answer)

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) std::cout<<arg<<"\n"
#define prin2(arg1,arg2) std::cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) std::memset(arg,n,sizeof(arg))
#define mp std::make_pair
#define pb push_back
using std::cin;
typedef long long ll;
typedef std::pair<int,int> pi;
typedef std::vector<int> vi;
typedef std::set<int> si;
typedef std::string str;
const int INF=1e+9;
const ll INFLL=1e+17;
const ll MOD=1e+9+7;
const int NMAX=3000;
int N;
ll x;
ll A[2010];
class RMQ{
public:
  ll dat[NMAX*2-1];//セグメント木を持つ配列
  int n;
  RMQ(int n_);//コンストラクタ
  void update(int k,ll a);//k番目(0-indexed)の値をaに変更
  ll query(int a,int b,int k,int l,int r);//[a,b)の最小値を求める
};
RMQ::RMQ(int n_){
  n=1;
  while(n<n_) n*=2;//簡単のため要素数を2のべき乗にする
  rep(i,2*n-1){
    dat[i]=INFLL;
  }
}
void RMQ::update(int k,ll a){//k番目(0-indexed)の値をaに変更
  k+=n-1;//a[k]=dat[k+n-1]
  dat[k]=a;
  while(k>0){
    k=(k-1)/2;
    dat[k]=std::min(dat[2*k+1],dat[2*k+2]);
  }
}
ll RMQ::query(int a,int b,int k,int l,int r){//[a,b)の最小値を求める。(k,l,r)=(節点の番号,節点の区間の左端,右端)。通常(a,b,0,0,n)と呼ぶ。
  if(r<=a||b<=l) return INFLL;//[a,b)と[l,r)が交差しなければINTMAXを返す
  if(a<=l&&r<=b) return dat[k];//[l,r)が[a,b)に完全に含まれていれば節点の値を返す
  else{//違うなら2つの子の最小値
    ll v1=query(a,b,2*k+1,l,(l+r)/2);
    ll v2=query(a,b,2*k+2,(l+r)/2,r);
    return std::min(v1,v2);
  }
}

int main(){
  cin>>N>>x;
  rep(i,N) cin>>A[i];
  RMQ rmq(N);
  rep(i,N){
    rmq.update(i,A[i]);
  }
  ll res=INFLL;
  for(ll num=0;num<N;num++){
    ll temp=x*num;
    rep(i,N){
      if(i-num>=0) temp+=rmq.query(i-num,i+1,0,0,N);
      else temp+=std::min(rmq.query(0,i+1,0,0,N),rmq.query(N-(num-i),N,0,0,N));
    }
    res=std::min(res,temp);
  }
  prin(res);
  return 0;
}