stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
//2018.9.29 by ljz

#include<bits/stdc++.h>

using namespace std;

#define res register LL

#define LL long long

#define inf 0x3f3f3f3f

#define eps 1e-15

inline LL read(){

    res s=0;

    bool w=0;

    char ch=getchar();

    while(ch<'0'||ch>'9'){if(ch=='-')w=1;ch=getchar();}

    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=getchar();

    return w?-s:s;

}

inline void _swap(res &x,res &y){

    x^=y^=x^=y;

}

inline LL _abs(const res &x){

    return x>0?x:-x;

}

inline LL _max(const res &x,const res &y){

    return x>y?x:y;

}

inline LL _min(const res &x,const res &y){

    return x<y?x:y;

}

const LL N=2e3+10;

namespace MAIN{

    LL n,x;

    LL a[N],b[N][N],ans;

    inline void MAIN(){

        n=read(),x=read();

        for(res i=1;i<=n;i++)a[i]=read(),ans+=a[i];

        for(res i=1;i<=n;i++){

            b[i][i]=a[i];

            for(res j=i+1;j<=n;j++)b[i][j]=_min(b[i][j-1],a[j]);

        }

        for(res i=0;i<=n;i++){

            res ret=i*x;

            for(res j=1;j<=n;j++){

                res k=j-i;

                if(k<=0)k+=n,ret+=_min(b[k][n],b[1][j]);

                else ret+=b[k][j];

            }

            ans=_min(ans,ret);

        }

        printf("%lld\n",ans);

    }

}

int main(){

    MAIN::MAIN();

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.143038463553054x):
#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

int n,a[3000],x,am[3000];

long long ans=0;

int main()

{

	scanf("%d%d",&n,&x);

	for (int i=1;i<=n;i++) scanf("%d",a+i),am[i]=a[i];

	for (int i=1;i<=n;i++) ans+=a[i];

	for (int i=1;i<n;i++)

	{

		long long tmp=0;

		for (int j=1;j<=n;j++) am[j]=min(am[j],a[(j+i-1)%n+1]),tmp+=am[j];

		tmp+=1ll*x*i;

		ans=min(ans,tmp);

	}

	printf("%lld\n",ans);

}
// Slower C++ solution:
#include <stdio.h>

#include <bits/stdc++.h>



#define pb push_back

#define pp pop_back

#define mp make_pair

#define f first

#define s second

#define all(x) x.begin(), x.end()

typedef long long ll;



using namespace std;



const int N = 4000 + 111, inf = 1e9, mod = 1e9 + 7;

const ll INF = 1e18;

const double pi = acos(-1.0), eps = 1e-10;



int n;

ll a[N], x, mn[N / 2][N], ans = INF;



int main(){

	srand(time(NULL));

	cin.tie(0);

	cout.tie(0);

	ios_base::sync_with_stdio(0);

	cout << setprecision(10) << fixed;



	cin >> n >> x;



	for(int i = 1; i <= n; ++i)

		cin >> a[i];



	for(int i = n + 1; i <= n + n; ++i)	

		a[i] = a[i - n];



	for(int i = 1; i <= n; ++i){

		ll m = inf;

		for(int j = i; j <= n + n; ++j)

			m = min(m, a[j]), mn[i][j] = m;

	}	



	for(int i = 0; i <= n; ++i){

		ll answer = i * x;

		for(int j = 1; j <= n; ++j)

			answer += mn[j][j + i];

		ans = min(ans, answer); 

	}



	cout << ans;



	return 0;

 	//cout << (clock() + 0.0) / CLOCKS_PER_SEC;	

}

// Faster C++ solution for the same problem (measured speedup: 5.298095782524218x):
#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

int n,a[3000],x,am[3000];

long long ans=0;

int main()

{

	scanf("%d%d",&n,&x);

	for (int i=1;i<=n;i++) scanf("%d",a+i),am[i]=a[i];

	for (int i=1;i<=n;i++) ans+=a[i];

	for (int i=1;i<n;i++)

	{

		long long tmp=0;

		for (int j=1;j<=n;j++) am[j]=min(am[j],a[(j+i-1)%n+1]),tmp+=am[j];

		tmp+=1ll*x*i;

		ans=min(ans,tmp);

	}

	printf("%lld\n",ans);

}
// Slower C++ solution:
#include <bits/stdc++.h>



#define f first 

#define s second 

#define pb push_back               

#define mp make_pair 



using namespace std;                    



typedef long long ll;

typedef pair<int, int> pii;

typedef pair<long long, long long> pll;



const int N = (int)1e5 + 123, mod = (int)1e9 + 7, inf = (int)1e9;



ll n, x, ans = 1e18, a[N], b[N];

int main(){    

	cin >> n >> x;

	for(int i = 0; i < n; i++){

		cin >> a[i];

		b[i] = a[i];

	}



	for(int i = 0; i <= n; i++){

		ll cur = 0;

		for(int j = 0; j < n; j++){

			b[j] = min(b[j], a[(j - i + n) % n]);

			cur += b[j];

		}

		ans = min(ans, cur + i * x);

	}

	cout << ans;

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.21223118897307x):
#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

int n,a[3000],x,am[3000];

long long ans=0;

int main()

{

	scanf("%d%d",&n,&x);

	for (int i=1;i<=n;i++) scanf("%d",a+i),am[i]=a[i];

	for (int i=1;i<=n;i++) ans+=a[i];

	for (int i=1;i<n;i++)

	{

		long long tmp=0;

		for (int j=1;j<=n;j++) am[j]=min(am[j],a[(j+i-1)%n+1]),tmp+=am[j];

		tmp+=1ll*x*i;

		ans=min(ans,tmp);

	}

	printf("%lld\n",ans);

}
// Slower C++ solution:
#include <bits/stdc++.h>

#define ll long long

#define res register ll

#define inf 2e18

#define N 2005

using namespace std;

ll n,a[N],ans=inf,x,b[N];

inline ll read(){

	res X=0,w=0;char ch=0;

	while(!isdigit(ch)){w|ch=='-';ch=getchar();}

	while(isdigit(ch)){X=(X<<1)+(X<<3)+(ch^48);ch=getchar();}

	return w?-X:X;

}

int main(){

	n=read(),x=read();

	for(res i=0;i<n;i++)

	  a[i]=read();

	for(res i=0;i<n;i++)

	  b[i]=inf;

	for(res i=0;i<n;i++){

		res sum=0;

		for(res j=0;j<n;j++)

		  b[j]=min(b[j],a[(j-i+n)%n]);

		for(res j=0;j<n;j++)

		  sum+=b[j];

		ans=min(ans,sum+i*x);

	}

	printf("%lld\n",ans);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.134109029825084x):
#include<cstdio>

#include<algorithm>

using namespace std;

typedef long long ll;

int n;

ll x;

ll a[2048];

ll md[2048][2048];

int main()

{

	scanf("%d%lld", &n, &x);

	for (int i = 0; i < n; i++) scanf("%lld", &a[i]);

	for (int i = 0; i < n; i++)

	{

		md[i][i] = a[i];

		for (int j = 1; j < n; j++)

			md[i][(i + j) % n] = min(a[(i + j) % n], md[i][(i + j - 1) % n]);

	}

	ll ans = -1;

	for (int y = 0; y < n; y++)

	{

		ll tot = x * y;

		for (int i = 0; i < n; i++)

		{

			tot += md[i][(i + y) % n];

		}

		if (ans<0 || ans>tot) ans = tot;

	}

	printf("%lld\n", ans);

	return 0;

}
// Slower C++ solution:
//2018.9.29 by ljz

#include<bits/stdc++.h>

using namespace std;

#define res register LL

#define LL long long

#define inf 0x3f3f3f3f

#define eps 1e-15

inline LL read(){

    res s=0;

    bool w=0;

    char ch=getchar();

    while(ch<'0'||ch>'9'){if(ch=='-')w=1;ch=getchar();}

    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=getchar();

    return w?-s:s;

}

inline void _swap(res &x,res &y){

    x^=y^=x^=y;

}

inline LL _abs(const res &x){

    return x>0?x:-x;

}

inline LL _max(const res &x,const res &y){

    return x>y?x:y;

}

inline LL _min(const res &x,const res &y){

    return x<y?x:y;

}

const LL N=2e3+10;

namespace MAIN{

    LL n,x;

    LL a[N],b[N][N],ans;

    inline void MAIN(){

        n=read(),x=read();

        for(res i=1;i<=n;i++)a[i]=read(),ans+=a[i];

        for(res i=1;i<=n;i++){

            b[i][i]=a[i];

            for(res j=i+1;j<=n;j++)b[i][j]=_min(b[i][j-1],a[j]);

        }

        for(res i=0;i<=n;i++){

            res ret=i*x;

            for(res j=1;j<=n;j++){

                res k=j-i;

                if(k<=0)k+=n,ret+=_min(b[k][n],b[1][j]);

                else ret+=b[k][j];

            }

            ans=_min(ans,ret);

        }

        printf("%lld\n",ans);

    }

}

int main(){

    MAIN::MAIN();

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.13730402123329x):
#include<cstdio>

#include<algorithm>

using namespace std;

typedef long long ll;

int n;

ll x;

ll a[2048];

ll md[2048][2048];

int main()

{

	scanf("%d%lld", &n, &x);

	for (int i = 0; i < n; i++) scanf("%lld", &a[i]);

	for (int i = 0; i < n; i++)

	{

		md[i][i] = a[i];

		for (int j = 1; j < n; j++)

			md[i][(i + j) % n] = min(a[(i + j) % n], md[i][(i + j - 1) % n]);

	}

	ll ans = -1;

	for (int y = 0; y < n; y++)

	{

		ll tot = x * y;

		for (int i = 0; i < n; i++)

		{

			tot += md[i][(i + y) % n];

		}

		if (ans<0 || ans>tot) ans = tot;

	}

	printf("%lld\n", ans);

	return 0;

}
// Slower C++ solution:
#include <stdio.h>

#include <bits/stdc++.h>



#define pb push_back

#define pp pop_back

#define mp make_pair

#define f first

#define s second

#define all(x) x.begin(), x.end()

typedef long long ll;



using namespace std;



const int N = 4000 + 111, inf = 1e9, mod = 1e9 + 7;

const ll INF = 1e18;

const double pi = acos(-1.0), eps = 1e-10;



int n;

ll a[N], x, mn[N / 2][N], ans = INF;



int main(){

	srand(time(NULL));

	cin.tie(0);

	cout.tie(0);

	ios_base::sync_with_stdio(0);

	cout << setprecision(10) << fixed;



	cin >> n >> x;



	for(int i = 1; i <= n; ++i)

		cin >> a[i];



	for(int i = n + 1; i <= n + n; ++i)	

		a[i] = a[i - n];



	for(int i = 1; i <= n; ++i){

		ll m = inf;

		for(int j = i; j <= n + n; ++j)

			m = min(m, a[j]), mn[i][j] = m;

	}	



	for(int i = 0; i <= n; ++i){

		ll answer = i * x;

		for(int j = 1; j <= n; ++j)

			answer += mn[j][j + i];

		ans = min(ans, answer); 

	}



	cout << ans;



	return 0;

 	//cout << (clock() + 0.0) / CLOCKS_PER_SEC;	

}

// Faster C++ solution for the same problem (measured speedup: 5.292188452667602x):
#include<cstdio>

#include<algorithm>

using namespace std;

typedef long long ll;

int n;

ll x;

ll a[2048];

ll md[2048][2048];

int main()

{

	scanf("%d%lld", &n, &x);

	for (int i = 0; i < n; i++) scanf("%lld", &a[i]);

	for (int i = 0; i < n; i++)

	{

		md[i][i] = a[i];

		for (int j = 1; j < n; j++)

			md[i][(i + j) % n] = min(a[(i + j) % n], md[i][(i + j - 1) % n]);

	}

	ll ans = -1;

	for (int y = 0; y < n; y++)

	{

		ll tot = x * y;

		for (int i = 0; i < n; i++)

		{

			tot += md[i][(i + y) % n];

		}

		if (ans<0 || ans>tot) ans = tot;

	}

	printf("%lld\n", ans);

	return 0;

}
// Slower C++ solution:
#include <bits/stdc++.h>



#define f first 

#define s second 

#define pb push_back               

#define mp make_pair 



using namespace std;                    



typedef long long ll;

typedef pair<int, int> pii;

typedef pair<long long, long long> pll;



const int N = (int)1e5 + 123, mod = (int)1e9 + 7, inf = (int)1e9;



ll n, x, ans = 1e18, a[N], b[N];

int main(){    

	cin >> n >> x;

	for(int i = 0; i < n; i++){

		cin >> a[i];

		b[i] = a[i];

	}



	for(int i = 0; i <= n; i++){

		ll cur = 0;

		for(int j = 0; j < n; j++){

			b[j] = min(b[j], a[(j - i + n) % n]);

			cur += b[j];

		}

		ans = min(ans, cur + i * x);

	}

	cout << ans;

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.206419597377508x):
#include<cstdio>

#include<algorithm>

using namespace std;

typedef long long ll;

int n;

ll x;

ll a[2048];

ll md[2048][2048];

int main()

{

	scanf("%d%lld", &n, &x);

	for (int i = 0; i < n; i++) scanf("%lld", &a[i]);

	for (int i = 0; i < n; i++)

	{

		md[i][i] = a[i];

		for (int j = 1; j < n; j++)

			md[i][(i + j) % n] = min(a[(i + j) % n], md[i][(i + j - 1) % n]);

	}

	ll ans = -1;

	for (int y = 0; y < n; y++)

	{

		ll tot = x * y;

		for (int i = 0; i < n; i++)

		{

			tot += md[i][(i + y) % n];

		}

		if (ans<0 || ans>tot) ans = tot;

	}

	printf("%lld\n", ans);

	return 0;

}
// Slower C++ solution:
#include<iostream>

#include<cstdio>

#include<cmath>

#include<cstring>

#include<map>

#include<set>

#include<vector>

#include<stack>

#include<queue>

#include<algorithm>

#define ll long long

using namespace std;

const ll inf=0x3f3f3f3f3f3f3f3f;

ll cost[2010];

ll res[2010]; 

int main()

{

	ll n,x;

	cin>>n>>x;

	for(int i=1;i<=n;i++)

	{

		scanf("%lld",&cost[i]);

		res[i]=cost[i];

	}

	ll ans=inf;

	for(int k=0;k<n;k++)//xiugai k ci

	{

		ll temp=0;

		for(int i=1;i<=n;i++)//mei ge slime

		{

			ll low;

			if(i<=k)

			{

				low=min(res[i],cost[n-(k-i)]);

			}

			else

			{

				low=min(res[i],cost[i-k]);

			}

			res[i]=low;

			temp+=low;

		}

		temp+=k*x;

		ans=min(ans,temp);

	}

	printf("%lld",ans);

} 

// Faster C++ solution for the same problem (measured speedup: 5.210693290429141x):
#include<cstdio>

#include<algorithm>

using namespace std;

typedef long long ll;

int n;

ll x;

ll a[2048];

ll md[2048][2048];

int main()

{

	scanf("%d%lld", &n, &x);

	for (int i = 0; i < n; i++) scanf("%lld", &a[i]);

	for (int i = 0; i < n; i++)

	{

		md[i][i] = a[i];

		for (int j = 1; j < n; j++)

			md[i][(i + j) % n] = min(a[(i + j) % n], md[i][(i + j - 1) % n]);

	}

	ll ans = -1;

	for (int y = 0; y < n; y++)

	{

		ll tot = x * y;

		for (int i = 0; i < n; i++)

		{

			tot += md[i][(i + y) % n];

		}

		if (ans<0 || ans>tot) ans = tot;

	}

	printf("%lld\n", ans);

	return 0;

}
// Slower C++ solution:
#include<iostream>

#include<string>

#include<cstring>

#include<map>

#include<algorithm>

#include<set>

#include<vector>

#include<cstdio>

#include<cmath>

#include<queue>

using namespace std;

typedef long long LL;



const int maxn = 2e3 + 5;

LL a[maxn];

LL b[maxn][maxn];

int main(){

    int n;

    LL x,sum = 1LL << 60LL;

    cin >> n >> x;

    for(int i = 1;i <= n;i++) cin >> a[i];

    for(int i = 1;i <= n;i++){

        b[i][0] = a[i];

        for(int k = 1;k <= n - 1;k++){

            int pos = i - k;

            if(pos <= 0) pos = n - abs(pos);

            b[i][k] = min(b[i][k - 1],a[pos]);

        }

    }

    for(int k = 0;k <= n - 1;k++){

        LL ans = 0;

        for(int i = 1;i <= n;i++){

            ans += b[i][k];

        }

        sum = min(sum,ans + x * k);

    }

    cout << sum << endl;

}

// Faster C++ solution for the same problem (measured speedup: 5.226352091626753x):
#include<cstdio>

#include<algorithm>

using namespace std;

typedef long long ll;

int n;

ll x;

ll a[2048];

ll md[2048][2048];

int main()

{

	scanf("%d%lld", &n, &x);

	for (int i = 0; i < n; i++) scanf("%lld", &a[i]);

	for (int i = 0; i < n; i++)

	{

		md[i][i] = a[i];

		for (int j = 1; j < n; j++)

			md[i][(i + j) % n] = min(a[(i + j) % n], md[i][(i + j - 1) % n]);

	}

	ll ans = -1;

	for (int y = 0; y < n; y++)

	{

		ll tot = x * y;

		for (int i = 0; i < n; i++)

		{

			tot += md[i][(i + y) % n];

		}

		if (ans<0 || ans>tot) ans = tot;

	}

	printf("%lld\n", ans);

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

const int N=2010;

typedef long long ll;

const ll llf=(1ll<<63)-1;

ll dp[N][N],a[N]; 

ll x,ans=llf;int n;

int main()

{

   

    scanf("%d%lld",&n,&x);

    for(int i=1;i<=n;i++)

    {

        scanf("%lld",&a[i]);

        dp[0][i]=a[i];

    }

    for(int i=1;i<=n-1;i++)

    {

        for(int j=1;j<=n;j++)

        {

            int ind=j-i;

            if(ind<=0)ind=n+ind;

            dp[i][j]=min(dp[i-1][j],a[ind]);

        }

    }

    for(int i=0;i<=n-1;i++)

    {

        ll ant=0;

        for(int j=1;j<=n;j++)ant+=dp[i][j];

        ans=min(ans,ant+i*x);

    }

    printf("%lld\n",ans);

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.153619108504064x):
#include<cstdio>

#include<algorithm>

using namespace std;

typedef long long ll;

int n;

ll x;

ll a[2048];

ll md[2048][2048];

int main()

{

	scanf("%d%lld", &n, &x);

	for (int i = 0; i < n; i++) scanf("%lld", &a[i]);

	for (int i = 0; i < n; i++)

	{

		md[i][i] = a[i];

		for (int j = 1; j < n; j++)

			md[i][(i + j) % n] = min(a[(i + j) % n], md[i][(i + j - 1) % n]);

	}

	ll ans = -1;

	for (int y = 0; y < n; y++)

	{

		ll tot = x * y;

		for (int i = 0; i < n; i++)

		{

			tot += md[i][(i + y) % n];

		}

		if (ans<0 || ans>tot) ans = tot;

	}

	printf("%lld\n", ans);

	return 0;

}
// Slower C++ solution:
#include <iostream>

#include <algorithm>

using namespace std;

//const ll llf=(1ll<<63)-1;

typedef long long ll;

const ll llf=(1ll<<63)-1;

ll dp[2010][2010];ll a[2010];

int main()

{

    ll n,x;

    cin>>n>>x;

    int i;

    for(i=1;i<=n;i++)

        cin>>a[i];

    int k;

    for(i=1;i<=n;i++)

        dp[i][0]=a[i];

    for(k=1;k<n;k++)

    {

        for(i=1;i<=n;i++)

        {

            int temp=i-k;

            if(temp<=0) temp+=n;

            dp[i][k]=min(dp[i][k-1],(ll)a[temp]);

        }

    }

    ll sum=0;ll ans=llf;

    for(i=0;i<n;i++)

    {

        sum=0;

        for(int j=1;j<=n;j++)

            sum+=dp[j][i];

        sum+=i*x;

        ans=min(ans, sum);

    }

    cout<<ans<<endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.213244106837153x):
#include<cstdio>

#include<algorithm>

using namespace std;

typedef long long ll;

int n;

ll x;

ll a[2048];

ll md[2048][2048];

int main()

{

	scanf("%d%lld", &n, &x);

	for (int i = 0; i < n; i++) scanf("%lld", &a[i]);

	for (int i = 0; i < n; i++)

	{

		md[i][i] = a[i];

		for (int j = 1; j < n; j++)

			md[i][(i + j) % n] = min(a[(i + j) % n], md[i][(i + j - 1) % n]);

	}

	ll ans = -1;

	for (int y = 0; y < n; y++)

	{

		ll tot = x * y;

		for (int i = 0; i < n; i++)

		{

			tot += md[i][(i + y) % n];

		}

		if (ans<0 || ans>tot) ans = tot;

	}

	printf("%lld\n", ans);

	return 0;

}
// Slower C++ solution:
#include<iostream>

#include<cstdio> 

using namespace std;

typedef long long ll;

const int N=2005;



int n,x,mymin,mymini;

ll ans,dp[N][N],a[N];



int main(){

	scanf("%d%d",&n,&x);

	for (int i=1;i<=n;i++) scanf("%d",&a[i]);

	for (int i=1;i<=n;i++) dp[i][0]=a[i];

	for (int i=1;i<=n;i++)

		for (int j=1;j<n;j++){

			int k=i-j;

			if (k<=0) k+=n;

			dp[i][j]=min(dp[i][j-1],a[k]);

		}

	ll ans=1e18;

	for (int i=0;i<n;i++){

		ll sum=0;

		for (int j=1;j<=n;j++) sum+=dp[j][i];

		ans=min(ans,sum+i*x);

	}

	printf("%lld",ans);

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.149129456512322x):
#include<cstdio>

#include<algorithm>

using namespace std;

typedef long long ll;

int n;

ll x;

ll a[2048];

ll md[2048][2048];

int main()

{

	scanf("%d%lld", &n, &x);

	for (int i = 0; i < n; i++) scanf("%lld", &a[i]);

	for (int i = 0; i < n; i++)

	{

		md[i][i] = a[i];

		for (int j = 1; j < n; j++)

			md[i][(i + j) % n] = min(a[(i + j) % n], md[i][(i + j - 1) % n]);

	}

	ll ans = -1;

	for (int y = 0; y < n; y++)

	{

		ll tot = x * y;

		for (int i = 0; i < n; i++)

		{

			tot += md[i][(i + y) % n];

		}

		if (ans<0 || ans>tot) ans = tot;

	}

	printf("%lld\n", ans);

	return 0;

}
// Slower C++ solution:
#include<bits/stdc++.h>

using namespace std;

long long n,x,a[2001],f[2001][2001],minn,ans=2e18;

int main(){

	cin>>n>>x;

	for(int i=1;i<=n;++i){

		scanf("%d",&a[i]);

	}

	for(int i=1;i<=n;++i){

		f[i][0]=a[i];

		for(int j=1;j<n;++j){

			long long p=i-j;

			if(p<=0)p=n-abs(p);

			f[i][j]=min(f[i][j-1],a[p]);

		}

	}

	for(int i=0;i<n;++i){

		minn=0;

		for(int j=1;j<=n;++j){

			minn+=f[j][i];

		}

		ans=min(ans,minn+i*x);

	}

	cout<<ans;

}

// Faster C++ solution for the same problem (measured speedup: 5.247445963850809x):
#include<cstdio>

#include<algorithm>

#include<cstring>

using namespace std;

long long f[2002][2002],n,a[2002],x;//f[i][j]:使用j次魔法，获得color i的最小花费的时间（不包括k*x）

int main()

{

	scanf("%lld%lld",&n,&x);

	for(int i=1;i<=n;i++)

		scanf("%lld",&a[i]);

	for(int i=1;i<=n;i++)

	{

		f[i][0]=a[i];

		for(int j=1;j<n;j++)

		{

			int pos=i-j;

			if(pos<=0)pos=n+pos;

			f[i][j]=min(f[i][j-1],a[pos]);

		}

	}

	long long ans=1LL<<60LL,h;

	for(int j=0;j<n;j++)

	{

		h=0;

		for(int i=1;i<=n;i++)

			h+=f[i][j];

		ans=min(ans,h+x*j);

	}

	printf("%lld",ans);

}
// Slower C++ solution:
#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <iostream>

#include <algorithm>

using namespace std;

typedef long long LL;

const int maxn = 2005;

const int mod = 1e9 + 7;

LL a[maxn], n, x, b[maxn], ans;

int main() {

    cin>>n>>x;

    for (int i=0; i<n; i++) cin>>a[i];

    ans = 1LL * maxn * 1e9;

    memset(b, 0x3f, sizeof(b));

    for (int i=0; i<n; i++) {

        LL tmp = 0;

        for (int j=0; j<n; j++)

            b[j] = min(b[j], a[(j-i+n)%n]);

        for (int j=0; j<n; j++)

            tmp += b[j];

        ans = min(ans, i * x + tmp);

    }

    cout<<ans<<endl;

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.391218960585731x):
#include<cstdio>

#include<cctype>

#define reg register

inline int read(){

	reg int x=0,f=1;reg char ch=getchar();

	for(;!isdigit(ch);f=ch=='-'?-1:1,ch=getchar());

	for(;isdigit(ch);x=(x<<3)+(x<<1)+(ch^48),ch=getchar());

	return x*f;

}

#define min(a,b) (a<b?a:b)

#define loop(a) (a<1?(n+a):a)

typedef long long ll;

ll a[2005],f[2005][2005],ans=1ll<<55;

int main(){

	reg int n=read(),x=read();

	for(reg int i=1;i<=n;i++)a[i]=f[i][0]=read();

	for(reg int i=1;i<=n;i++)

		for(reg int j=1;j<n;j++)

			f[i][j]=min(a[loop((i-j))],f[i][j-1]);

	for(reg int i=0;i<n;i++){

		ll t=x*1ll*i;

		for(reg int j=1;j<=n;j++)t+=f[j][i];

		ans=min(ans,t);

	}

	printf("%lld\n",ans);

	return 0;

}
// Slower C++ solution:
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;

#define INF (1<<30)

#define INFLL (1ll<<60)

typedef pair<int, int> P;

typedef pair<int, P> E;

#define gt first

#define gc second.first

#define gr second.second

#define MOD (1000000007ll)

#define l_ength size

#define PI 3.14159265358979



void mul_mod(ll& a, ll b){

	a *= b;

	a %= MOD;

}



void add_mod(ll& a, ll b){

	b += MOD;

	a += b;

	a %= MOD;

}



int n;

ll a[2222],memo[2222][2222];

bool done[2222][2222];



ll sgmn(int l, int r){

	if(done[l][r]){

		return memo[l][r];

	}

	done[l][r] = true;

	if(l > r){

		memo[l][r] = min(sgmn(l,n-1),sgmn(0,r));

	}else if(l == r){

		memo[l][r] = a[l];

	}else{

		memo[l][r] = min(sgmn(l,r-1),a[r]);

	}

	return memo[l][r];

}



int main(void){

	int i,j;

	ll x,tmp,ans=INFLL;

	fill(done[0],done[2222],false);

	cin >> n >> x;

	for(i=0; i<n; ++i){

		cin >> a[i];

	}

	for(i=0; i<n; ++i){

		tmp = i * x;

		for(j=0; j<n; ++j){

			tmp += sgmn((j-i+n)%n,j);

		}

		ans = min(tmp,ans);

	}

	cout << ans << endl;

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 6.0928251415803985x):
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;

const int INF = (1<<30);

const ll INFLL = (1ll<<60);

const ll MOD = (ll)(1e9+7);

const int zero = 12826;



#define l_ength size



void mul_mod(ll& a, ll b){

	a *= b;

	a %= MOD;

}



void add_mod(ll& a, ll b){

	a = (a<MOD)?a:(a-MOD);

	b = (b<MOD)?b:(b-MOD);

	a += b;

	a = (a<MOD)?a:(a-MOD);

}



ll a[2222],s[2222];



int main(void){

	int n,i,j;

	ll x,tmp,ans=INFLL;

	cin >> n >> x;

	fill(s,s+n,INFLL);

	for(i=0; i<n; ++i){

		cin >> a[i];

	}

	for(j=0; j<n; ++j){

		tmp = x*j;

		for(i=0; i<n; ++i){

			s[i] = min(a[(i-j+n)%n],s[i]);

			tmp += s[i];

		}

		ans = min(ans,tmp);

	}

	cout << ans << endl;

	return 0;

}