stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <iostream>

#include <algorithm>

#include <climits>

#define ll long long

using namespace std;

ll n, x, ans;

ll a[2005], b[2005];

int main()

{

	cin >> n >> x;

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

	{

		cin >> a[i];

		b[i] = a[i];

	};

	ans = LLONG_MAX;

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

	{

		ll tmp = 0;

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

		{

			int be = (i-k <= 0)? i-k+n: i-k;

			b[i] = min(b[i], a[be]);

			tmp += b[i];

		}

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

	}

	cout << ans << endl;



	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 5.223673613181666x):
#include<stdio.h>

#include<string.h>

#include<algorithm>

#include<math.h>

using namespace std;

long long int a[2010]={0};

long long int b[2010][2010]={0};

int main()

{   long long int n,x,i,j,sum,minx,temp;

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

 

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

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

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

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

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

            temp=i-j;

            if(temp<=0)

                temp=n+temp;

            b[i][j]=min(b[i][j-1],a[temp]);  

        }

    }

    minx=0x3f3f3f3f3f3f3f3f;

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

        sum=0;

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

            sum+=b[j][i];

        sum+=i*x;

        minx=min(sum,minx);

    }

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

    return 0;

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

#include<cstdio>

#include<cmath>

#define ll long long

#define mset(a,x) memset(a,x,sizeof(a))

using namespace std;

const double PI = acos(-1);

const int inf = 0x3f3f3f3f;

const double esp = 1e-6;

const int maxn = 1e6 + 5;

const int mod = 1e9 + 7;

int dir[4][2] = {0, 1, 1, 0, 0, -1, -1, 0};

ll gcd(ll a, ll b) {

    return b ? gcd(b, a % b) : a;

}

ll lcm(ll a, ll b) {

    return a / gcd(a, b) * b;

}

ll inv(ll b) {

    if(b == 1)return 1;

    return (mod - mod / b) * inv(mod % b) % mod;

}

ll fpow(ll n, ll k) {

    ll r = 1;

    for(; k; k >>= 1) {

        if(k & 1)r = r * n % mod;

        n = n * n % mod;

    }

    return r;

}

ll Fpow(ll n, ll k) {

    ll r = 1;

    for(; k; k >>= 1) {

        if(k & 1)r = r * n;

        n = n * n;

    }

    return r;

}

ll upd(ll x, ll v) {

    x = x + v >= mod ? x + v - mod : x + v;

    return x;

}

ll a[maxn], dp[2005][2005];

int main() {

    ll n, x, i, j, k;

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

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

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

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

    }

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

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

            int t = i - j;

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

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

        }

    }



    ll ans = 1e18;

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

        ll sum = 0;

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

            sum += dp[j][i];

        }

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

    }

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

}


// Faster C++ solution for the same problem (measured speedup: 5.161713518646135x):
#include<stdio.h>

#include<string.h>

#include<algorithm>

#include<math.h>

using namespace std;

long long int a[2010]={0};

long long int b[2010][2010]={0};

int main()

{   long long int n,x,i,j,sum,minx,temp;

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

 

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

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

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

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

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

            temp=i-j;

            if(temp<=0)

                temp=n+temp;

            b[i][j]=min(b[i][j-1],a[temp]);  

        }

    }

    minx=0x3f3f3f3f3f3f3f3f;

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

        sum=0;

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

            sum+=b[j][i];

        sum+=i*x;

        minx=min(sum,minx);

    }

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

    return 0;

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

using namespace std;

const int N = 2000 + 10;

int n, x, mn[N][N];

int main() {

    long long ans = 0;

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

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

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

        ans = ans + mn[i][i];

    }

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

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

            mn[i][j] = min(mn[i][j - 1], mn[j][j]);

        }

    }

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

        long long tmp = 1ll * k * x;

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

            if (i > k)

                tmp = tmp + mn[i - k][i];

            else

                tmp = tmp + min(mn[1][i], mn[n - k + i][n]);

        }

        ans = min(ans, tmp);

    }

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

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.164193048650265x):
#include<stdio.h>

#include<string.h>

#include<algorithm>

#include<math.h>

using namespace std;

long long int a[2010]={0};

long long int b[2010][2010]={0};

int main()

{   long long int n,x,i,j,sum,minx,temp;

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

 

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

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

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

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

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

            temp=i-j;

            if(temp<=0)

                temp=n+temp;

            b[i][j]=min(b[i][j-1],a[temp]);  

        }

    }

    minx=0x3f3f3f3f3f3f3f3f;

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

        sum=0;

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

            sum+=b[j][i];

        sum+=i*x;

        minx=min(sum,minx);

    }

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

    return 0;

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

using namespace std;

long long n,x,a[2010],b[2010],ans,tmp;

int main(){

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

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

    ans=1e14;memset(b,0x3f,sizeof(b));

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

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

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

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

}

// Faster C++ solution for the same problem (measured speedup: 5.244448333196961x):
#include<stdio.h>

#include<string.h>

#include<algorithm>

#include<math.h>

using namespace std;

long long int a[2010]={0};

long long int b[2010][2010]={0};

int main()

{   long long int n,x,i,j,sum,minx,temp;

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

 

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

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

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

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

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

            temp=i-j;

            if(temp<=0)

                temp=n+temp;

            b[i][j]=min(b[i][j-1],a[temp]);  

        }

    }

    minx=0x3f3f3f3f3f3f3f3f;

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

        sum=0;

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

            sum+=b[j][i];

        sum+=i*x;

        minx=min(sum,minx);

    }

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

    return 0;

}
// Slower C++ solution:
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>

#include <sstream>

#include <iomanip>

#include <cstdio>

#include <cstdlib>

#include <cmath>

#include <cctype>

#include <cstring>

#include <vector>

#include <list>

#include <queue>

#include <deque>

#include <stack>

#include <map>

#include <set>

#include <algorithm>

#include <iterator>

#include <bitset>

#include <ctime>

#include<unordered_set>

#include<complex>

using namespace std;



#define FOR(i,a,b) for (int i = (a); i < (b); i++)

#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)

#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)

#define FILL(a,value) memset(a, value, sizeof(a))



#define SZ(a) (int)a.size()

#define ALL(a) a.begin(), a.end()

#define PB push_back

#define MP make_pair



typedef long long LL;

typedef vector<int> VI;

typedef pair<int, int> PII;



const double PI = acos(-1.0);

const int INF = 1000 * 1000 * 1000 + 7;

const LL LINF = INF * (LL)INF;



const int MAX = 2000 + 47;



int A[MAX];

int B[MAX];

int B1[MAX];



int main()

{

	//freopen("in.txt", "r", stdin);

	//freopen("out.txt", "w", stdout);

	ios::sync_with_stdio(false); cin.tie(0);

	int n; 

	LL x;

	cin >> n >> x;

	FOR(i, 0, n)

	{

		cin >> A[i];

		B[i] = A[i];

	}



	LL ans = LINF;

	FOR(k, 0, n)

	{

		LL summ = 0;

		FOR(i, 0, n) summ += B[i];

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

		FOR(i, 0, n)

		{

			B1[i] = min(A[i], B[(i - 1 + n) % n]);

		}



		FOR(i, 0, n)

		{

			B[i] = B1[i];

		}

	}



	cout << ans << endl;

}


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

#include <cstring>

#include <algorithm>

#define ll long long

using namespace std;

const int N=2010;

ll n,x,a[N],mn[N],ans,sum;

int main(){

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

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

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

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

		sum=0ll;

		for(int j=0;j<n;j++) mn[j]=min(a[(j-i+n)%n],mn[j]),sum+=mn[j];

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

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

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



using namespace std;



long long n, x;

long long colors[2010], shift[2010];



int main()

{

    ios_base::sync_with_stdio(0);

    cin.tie(0);



    cin >> n >> x;



    int inicial;

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

        cin >> colors[i];

        shift[0] += colors[i];

    }



    long long best, aux;

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

        best = colors[c];

        for(int i = (c - 1 + n) % n, j = 1; i != c; --i, i+= n, i %= n, ++j){

            if(colors[i] < best)

                best = colors[i];

            shift[j] += best;

        }

    }



    long long corrimientos = 0, menor = shift[0];

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

        if(shift[i] + x * i < menor){

            corrimientos = i;

            menor = shift[i] + x * i;

        }

    }



    cout << menor << endl;



    return 0;

}


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

#include <cstring>

#include <algorithm>

#define ll long long

using namespace std;

const int N=2010;

ll n,x,a[N],mn[N],ans,sum;

int main(){

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

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

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

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

		sum=0ll;

		for(int j=0;j<n;j++) mn[j]=min(a[(j-i+n)%n],mn[j]),sum+=mn[j];

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

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

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

#include <algorithm>

#include <climits>

#define ll long long

using namespace std;

ll n, x, ans;

ll a[2005], b[2005];

int main()

{

	cin >> n >> x;

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

	{

		cin >> a[i];

		b[i] = a[i];

	};

	ans = LLONG_MAX;

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

	{

		ll tmp = 0;

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

		{

			int be = (i-k <= 0)? i-k+n: i-k;

			b[i] = min(b[i], a[be]);

			tmp += b[i];

		}

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

	}

	cout << ans << endl;



	return 0;

}


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

#include <cstring>

#include <algorithm>

#define ll long long

using namespace std;

const int N=2010;

ll n,x,a[N],mn[N],ans,sum;

int main(){

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

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

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

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

		sum=0ll;

		for(int j=0;j<n;j++) mn[j]=min(a[(j-i+n)%n],mn[j]),sum+=mn[j];

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

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

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

#include<cstdio>

#include<cmath>

#define ll long long

#define mset(a,x) memset(a,x,sizeof(a))

using namespace std;

const double PI = acos(-1);

const int inf = 0x3f3f3f3f;

const double esp = 1e-6;

const int maxn = 1e6 + 5;

const int mod = 1e9 + 7;

int dir[4][2] = {0, 1, 1, 0, 0, -1, -1, 0};

ll gcd(ll a, ll b) {

    return b ? gcd(b, a % b) : a;

}

ll lcm(ll a, ll b) {

    return a / gcd(a, b) * b;

}

ll inv(ll b) {

    if(b == 1)return 1;

    return (mod - mod / b) * inv(mod % b) % mod;

}

ll fpow(ll n, ll k) {

    ll r = 1;

    for(; k; k >>= 1) {

        if(k & 1)r = r * n % mod;

        n = n * n % mod;

    }

    return r;

}

ll Fpow(ll n, ll k) {

    ll r = 1;

    for(; k; k >>= 1) {

        if(k & 1)r = r * n;

        n = n * n;

    }

    return r;

}

ll upd(ll x, ll v) {

    x = x + v >= mod ? x + v - mod : x + v;

    return x;

}

ll a[maxn], dp[2005][2005];

int main() {

    ll n, x, i, j, k;

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

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

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

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

    }

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

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

            int t = i - j;

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

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

        }

    }



    ll ans = 1e18;

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

        ll sum = 0;

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

            sum += dp[j][i];

        }

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

    }

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

}


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

#include <cstring>

#include <algorithm>

#define ll long long

using namespace std;

const int N=2010;

ll n,x,a[N],mn[N],ans,sum;

int main(){

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

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

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

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

		sum=0ll;

		for(int j=0;j<n;j++) mn[j]=min(a[(j-i+n)%n],mn[j]),sum+=mn[j];

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

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

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

using namespace std;

const int N = 2000 + 10;

int n, x, mn[N][N];

int main() {

    long long ans = 0;

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

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

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

        ans = ans + mn[i][i];

    }

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

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

            mn[i][j] = min(mn[i][j - 1], mn[j][j]);

        }

    }

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

        long long tmp = 1ll * k * x;

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

            if (i > k)

                tmp = tmp + mn[i - k][i];

            else

                tmp = tmp + min(mn[1][i], mn[n - k + i][n]);

        }

        ans = min(ans, tmp);

    }

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

    return 0;

}

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

#include <cstring>

#include <algorithm>

#define ll long long

using namespace std;

const int N=2010;

ll n,x,a[N],mn[N],ans,sum;

int main(){

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

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

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

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

		sum=0ll;

		for(int j=0;j<n;j++) mn[j]=min(a[(j-i+n)%n],mn[j]),sum+=mn[j];

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

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

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

using namespace std;

long long n,x,a[2010],b[2010],ans,tmp;

int main(){

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

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

    ans=1e14;memset(b,0x3f,sizeof(b));

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

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

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

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

}

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

#include <cstring>

#include <algorithm>

#define ll long long

using namespace std;

const int N=2010;

ll n,x,a[N],mn[N],ans,sum;

int main(){

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

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

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

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

		sum=0ll;

		for(int j=0;j<n;j++) mn[j]=min(a[(j-i+n)%n],mn[j]),sum+=mn[j];

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

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

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

#include<cstdio>

#include<vector>

#include<limits>

#include<cmath>

using namespace std;

long long a[3000],minn[3000],n,x,sum=0,t=0,sum1;

int main()

{

	cin>>n>>x;

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

	{

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

		minn[i]=a[i];

		sum+=a[i];

	}

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

	{

		sum1=0;

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

		{

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

			sum1+=minn[j];

		}

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

	}

	cout<<sum;

	

	



}

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

#include <cstring>

#include <algorithm>

#define ll long long

using namespace std;

const int N=2010;

ll n,x,a[N],mn[N],ans,sum;

int main(){

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

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

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

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

		sum=0ll;

		for(int j=0;j<n;j++) mn[j]=min(a[(j-i+n)%n],mn[j]),sum+=mn[j];

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

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

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

using namespace std;

typedef long long LL;



const int maxn = 2e3 + 5;

LL a[maxn];

LL b[maxn][maxn];//b[i][k] : 当整个过程使用了【k】次魔法，获得【color i】时的最少花费的时间。(不包括【k * x】).



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]);//【b[i][k]】的转移方程.

        }

    }

    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: 4.837888673123983x):
#include <cstdio>

#include <cstring>

#include <algorithm>

#define ll long long

using namespace std;

const int N=2010;

ll n,x,a[N],mn[N],ans,sum;

int main(){

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

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

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

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

		sum=0ll;

		for(int j=0;j<n;j++) mn[j]=min(a[(j-i+n)%n],mn[j]),sum+=mn[j];

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

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

}
// Slower C++ solution:
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>

#include <sstream>

#include <iomanip>

#include <cstdio>

#include <cstdlib>

#include <cmath>

#include <cctype>

#include <cstring>

#include <vector>

#include <list>

#include <queue>

#include <deque>

#include <stack>

#include <map>

#include <set>

#include <algorithm>

#include <iterator>

#include <bitset>

#include <ctime>

#include<unordered_set>

#include<complex>

using namespace std;



#define FOR(i,a,b) for (int i = (a); i < (b); i++)

#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)

#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)

#define FILL(a,value) memset(a, value, sizeof(a))



#define SZ(a) (int)a.size()

#define ALL(a) a.begin(), a.end()

#define PB push_back

#define MP make_pair



typedef long long LL;

typedef vector<int> VI;

typedef pair<int, int> PII;



const double PI = acos(-1.0);

const int INF = 1000 * 1000 * 1000 + 7;

const LL LINF = INF * (LL)INF;



const int MAX = 2000 + 47;



int A[MAX];

int B[MAX];

int B1[MAX];



int main()

{

	//freopen("in.txt", "r", stdin);

	//freopen("out.txt", "w", stdout);

	ios::sync_with_stdio(false); cin.tie(0);

	int n; 

	LL x;

	cin >> n >> x;

	FOR(i, 0, n)

	{

		cin >> A[i];

		B[i] = A[i];

	}



	LL ans = LINF;

	FOR(k, 0, n)

	{

		LL summ = 0;

		FOR(i, 0, n) summ += B[i];

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

		FOR(i, 0, n)

		{

			B1[i] = min(A[i], B[(i - 1 + n) % n]);

		}



		FOR(i, 0, n)

		{

			B[i] = B1[i];

		}

	}



	cout << ans << endl;

}


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



typedef long long LL;



const int MAXN = 4005;



template<typename _T>

void read( _T &x )

{

	x = 0;char s = getchar();int f = 1;

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

	while( s >= '0' && s <= '9' ){x = ( x << 3 ) + ( x << 1 ) + ( s - '0' ), s = getchar();}

	x *= f;

}



template<typename _T>

void write( _T x )

{

	if( x < 0 ){ putchar( '-' ); x = ( ~ x ) + 1; }

	if( 9 < x ){ write( x / 10 ); }

	putchar( x % 10 + '0' );

}



template<typename _T>

_T MIN( const _T a, const _T b )

{

	return a < b ? a : b;

}



int q[MAXN];

int a[MAXN];

int N, x;



LL calc( const int l )

{

	LL ret = 1ll * l * x;

	int h = 1, t = 0, r = 1;

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

	{

		while( h <= t && q[h] < i ) h ++;

		for( ; r <= i + l ; r ++ )

		{

			while( h <= t && a[q[t]] >= a[r] )

				t --;

			q[++ t] = r;

		}

		ret += a[q[h]];

	}

	return ret;

}



int main()

{

	read( N ), read( x );

	for( int i = 1 ; i <= N ; i ++ ) read( a[i] ), a[i + N] = a[i];

	LL ans = 1e18;

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

		ans = MIN( ans, calc( i ) );

	write( ans ), putchar( '\n' );

	return 0;

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



using namespace std;



long long n, x;

long long colors[2010], shift[2010];



int main()

{

    ios_base::sync_with_stdio(0);

    cin.tie(0);



    cin >> n >> x;



    int inicial;

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

        cin >> colors[i];

        shift[0] += colors[i];

    }



    long long best, aux;

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

        best = colors[c];

        for(int i = (c - 1 + n) % n, j = 1; i != c; --i, i+= n, i %= n, ++j){

            if(colors[i] < best)

                best = colors[i];

            shift[j] += best;

        }

    }



    long long corrimientos = 0, menor = shift[0];

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

        if(shift[i] + x * i < menor){

            corrimientos = i;

            menor = shift[i] + x * i;

        }

    }



    cout << menor << endl;



    return 0;

}


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



typedef long long LL;



const int MAXN = 4005;



template<typename _T>

void read( _T &x )

{

	x = 0;char s = getchar();int f = 1;

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

	while( s >= '0' && s <= '9' ){x = ( x << 3 ) + ( x << 1 ) + ( s - '0' ), s = getchar();}

	x *= f;

}



template<typename _T>

void write( _T x )

{

	if( x < 0 ){ putchar( '-' ); x = ( ~ x ) + 1; }

	if( 9 < x ){ write( x / 10 ); }

	putchar( x % 10 + '0' );

}



template<typename _T>

_T MIN( const _T a, const _T b )

{

	return a < b ? a : b;

}



int q[MAXN];

int a[MAXN];

int N, x;



LL calc( const int l )

{

	LL ret = 1ll * l * x;

	int h = 1, t = 0, r = 1;

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

	{

		while( h <= t && q[h] < i ) h ++;

		for( ; r <= i + l ; r ++ )

		{

			while( h <= t && a[q[t]] >= a[r] )

				t --;

			q[++ t] = r;

		}

		ret += a[q[h]];

	}

	return ret;

}



int main()

{

	read( N ), read( x );

	for( int i = 1 ; i <= N ; i ++ ) read( a[i] ), a[i + N] = a[i];

	LL ans = 1e18;

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

		ans = MIN( ans, calc( i ) );

	write( ans ), putchar( '\n' );

	return 0;

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

#include <algorithm>

#include <climits>

#define ll long long

using namespace std;

ll n, x, ans;

ll a[2005], b[2005];

int main()

{

	cin >> n >> x;

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

	{

		cin >> a[i];

		b[i] = a[i];

	};

	ans = LLONG_MAX;

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

	{

		ll tmp = 0;

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

		{

			int be = (i-k <= 0)? i-k+n: i-k;

			b[i] = min(b[i], a[be]);

			tmp += b[i];

		}

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

	}

	cout << ans << endl;



	return 0;

}


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



typedef long long LL;



const int MAXN = 4005;



template<typename _T>

void read( _T &x )

{

	x = 0;char s = getchar();int f = 1;

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

	while( s >= '0' && s <= '9' ){x = ( x << 3 ) + ( x << 1 ) + ( s - '0' ), s = getchar();}

	x *= f;

}



template<typename _T>

void write( _T x )

{

	if( x < 0 ){ putchar( '-' ); x = ( ~ x ) + 1; }

	if( 9 < x ){ write( x / 10 ); }

	putchar( x % 10 + '0' );

}



template<typename _T>

_T MIN( const _T a, const _T b )

{

	return a < b ? a : b;

}



int q[MAXN];

int a[MAXN];

int N, x;



LL calc( const int l )

{

	LL ret = 1ll * l * x;

	int h = 1, t = 0, r = 1;

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

	{

		while( h <= t && q[h] < i ) h ++;

		for( ; r <= i + l ; r ++ )

		{

			while( h <= t && a[q[t]] >= a[r] )

				t --;

			q[++ t] = r;

		}

		ret += a[q[h]];

	}

	return ret;

}



int main()

{

	read( N ), read( x );

	for( int i = 1 ; i <= N ; i ++ ) read( a[i] ), a[i + N] = a[i];

	LL ans = 1e18;

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

		ans = MIN( ans, calc( i ) );

	write( ans ), putchar( '\n' );

	return 0;

}