stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#define _CRT_SECURE_NO_WARNINGS

#pragma comment(linker, "/stack:16777216")

#include <string>

#include <vector>

#include <map>

#include <list>

#include <iterator>

#include <cassert>

#include <set>

#include <queue>

#include <iostream>

#include <sstream>

#include <stack>

#include <deque>

#include <cmath>

#include <memory.h>

#include <cstdlib>

#include <cstdio>

#include <cctype>

#include <algorithm>

#include <utility>

#include <time.h>

#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 LL INF = 1000 * 1000 * 1000 + 7;

const LL LINF = INF * (LL)INF;



const int MAX = 2020;

int A[MAX];

int M[MAX];





int main()

{

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

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



	int n, k;

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



	FOR (i, 0, n)

	{

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

		M[i] = A[i];

	}



	LL res = LINF;



	FOR (it, 0, n+1)

	{

		LL cur = it * (LL)k;



		FOR (i, 0, n)

		{

			cur += M[i];

		}



		res = min(res, cur);

		FOR (i, 0, n)

		{

			int to = (i + it + 1) % n;

			M[to] = min(M[to], A[i]);

		}

	}



	cout<<res<<endl;



}


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

#include<algorithm>

using namespace std;

#define MAXN 2010

#define INF 2000000000000LL

#define LL long long

LL x,a[MAXN],ans;

LL dp[MAXN][MAXN];

int n;

int main()

{

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

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

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

	ans=INF;

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

	{

		dp[i][0]=dp[i-1][0]+a[i];

		LL mn=a[i];

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

		{

			int p=(i-j)<=0?(i-j+n):(i-j);

			mn=min(a[p],mn);

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

		}

	}

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

		ans=min(ans,dp[n][i]+i*x);

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

}
// Slower C++ solution:
// LNU_Algotesters

#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 <fstream>

#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 = 1000 * 3 + 47;







int A[MAX];

int D[MAX];



int main()

{

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

    int n, x;

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

    FOR(i, 0, n)scanf("%d", A + i);

    FOR(i, 0, n)D[i] = INF;

    LL res = LINF;

    FOR(i, 0, n)

    {

        FOR(j, 0, n)

        D[j] = min(D[j], A[(j - i + n) % n]);

        LL s = 0;

        FOR(j, 0, n)

            s += D[j];

        res = min(res, s + i * (LL)x);

    }

    cout << res << endl;

    return 0;

}




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

#include<algorithm>

using namespace std;

#define MAXN 2010

#define INF 2000000000000LL

#define LL long long

LL x,a[MAXN],ans;

LL dp[MAXN][MAXN];

int n;

int main()

{

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

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

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

	ans=INF;

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

	{

		dp[i][0]=dp[i-1][0]+a[i];

		LL mn=a[i];

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

		{

			int p=(i-j)<=0?(i-j+n):(i-j);

			mn=min(a[p],mn);

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

		}

	}

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

		ans=min(ans,dp[n][i]+i*x);

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

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



#define MAX_N 2005

#define bit(mask, i) (mask & (1<<i))



using namespace std;



typedef pair<int, int> ii;

typedef vector<ii> vii;

typedef vector<int> vi;

typedef vector<vi> vvi;

typedef long long ll;

typedef double lf;



class SegmentTree {

private:

    vector<ll> st, A;

    int n;

    int leftc(int p) { return (p << 1) + 1; }

    int rightc(int p) { return (p << 1) + 2; }

    ll join(ll a, ll b) { return min(a, b); }



    void build(int p, int L, int R) {

        if (L == R) { st[p] = A[L]; }

        else {

            int c = (L + R)/2, p1 = leftc(p), p2 = rightc(p);

            build(p1, L, c);

            build(p2, c + 1, R);

            st[p] = join(st[p1], st[p2]);

        }

    }



    ll query(int p, int L, int R, int i, int j) {

        if (i == L && j == R) { return st[p]; }

        int c = (L + R)/2, p1 = leftc(p), p2 = rightc(p);

        if ( j <= c ) { return query(p1, L, c, i, j); }

        if ( i > c ) { return query(p2, c + 1, R, i, j); }

        ll q1 = query(p1, L, c, i, c), q2 = query(p2, c + 1, R, c + 1, j);

        return join(q1, q2);

    }



public:

    SegmentTree(const vector<ll> &_A) {

        A = _A; n = (int)A.size();

        st.assign(4 * n, 0);

        build(0, 0, n - 1);

    }

    ll query(int i, int j) { return query(0, 0, n - 1, i, j); }

};



int main() {

    ios_base::sync_with_stdio(0);

    cin.tie(0);



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

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



    ll n, x;



    cin>>n>>x;

    vector<ll> colors(n);

    ll sol = 0;

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

        cin>>colors[i];

        sol += colors[i];

    }



    SegmentTree st(colors);



    ll psol, mincol;



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

        psol = x * p;

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

            mincol = st.query(max(0, i - p), i);

            if(p > i) { mincol = min(mincol, st.query(n - p + i, n - 1)); }

            psol += mincol;

        }

        sol = min(sol, psol);

    }



    cout<<sol<<"\n";



    return 0;

}

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

#include<algorithm>

using namespace std;

#define MAXN 2010

#define INF 2000000000000LL

#define LL long long

LL x,a[MAXN],ans;

LL dp[MAXN][MAXN];

int n;

int main()

{

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

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

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

	ans=INF;

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

	{

		dp[i][0]=dp[i-1][0]+a[i];

		LL mn=a[i];

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

		{

			int p=(i-j)<=0?(i-j+n):(i-j);

			mn=min(a[p],mn);

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

		}

	}

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

		ans=min(ans,dp[n][i]+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: 5.231987762767229x):
#include<cstdio>

#include<algorithm>

using namespace std;

#define MAXN 2010

#define INF 2000000000000LL

#define LL long long

LL x,a[MAXN],ans;

LL dp[MAXN][MAXN];

int n;

int main()

{

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

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

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

	ans=INF;

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

	{

		dp[i][0]=dp[i-1][0]+a[i];

		LL mn=a[i];

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

		{

			int p=(i-j)<=0?(i-j+n):(i-j);

			mn=min(a[p],mn);

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

		}

	}

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

		ans=min(ans,dp[n][i]+i*x);

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

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

using namespace std;

 

long long b[2020];

long long a[2020];

int main()

{

    long long n, x;

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

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

    {

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

        b[i] = a[i];

    }

    long long ans = -1;

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

    {

        long long t = k * x;

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

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

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

            t += b[j];

        if(ans == -1)

            ans = t;

        else

            ans = min(ans, t);

    }

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

    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.2021633289589495x):
#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);

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

#pragma comment(linker, "/stack:16777216")

#include <string>

#include <vector>

#include <map>

#include <list>

#include <iterator>

#include <cassert>

#include <set>

#include <queue>

#include <iostream>

#include <sstream>

#include <stack>

#include <deque>

#include <cmath>

#include <memory.h>

#include <cstdlib>

#include <cstdio>

#include <cctype>

#include <algorithm>

#include <utility>

#include <time.h>

#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 LL INF = 1000 * 1000 * 1000 + 7;

const LL LINF = INF * (LL)INF;



const int MAX = 2020;

int A[MAX];

int M[MAX];





int main()

{

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

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



	int n, k;

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



	FOR (i, 0, n)

	{

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

		M[i] = A[i];

	}



	LL res = LINF;



	FOR (it, 0, n+1)

	{

		LL cur = it * (LL)k;



		FOR (i, 0, n)

		{

			cur += M[i];

		}



		res = min(res, cur);

		FOR (i, 0, n)

		{

			int to = (i + it + 1) % n;

			M[to] = min(M[to], A[i]);

		}

	}



	cout<<res<<endl;



}


// Faster C++ solution for the same problem (measured speedup: 5.223488981001665x):
#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);

}
// Slower C++ solution:
// LNU_Algotesters

#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 <fstream>

#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 = 1000 * 3 + 47;







int A[MAX];

int D[MAX];



int main()

{

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

    int n, x;

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

    FOR(i, 0, n)scanf("%d", A + i);

    FOR(i, 0, n)D[i] = INF;

    LL res = LINF;

    FOR(i, 0, n)

    {

        FOR(j, 0, n)

        D[j] = min(D[j], A[(j - i + n) % n]);

        LL s = 0;

        FOR(j, 0, n)

            s += D[j];

        res = min(res, s + i * (LL)x);

    }

    cout << res << endl;

    return 0;

}




// Faster C++ solution for the same problem (measured speedup: 5.2233645883014175x):
#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);

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



#define MAX_N 2005

#define bit(mask, i) (mask & (1<<i))



using namespace std;



typedef pair<int, int> ii;

typedef vector<ii> vii;

typedef vector<int> vi;

typedef vector<vi> vvi;

typedef long long ll;

typedef double lf;



class SegmentTree {

private:

    vector<ll> st, A;

    int n;

    int leftc(int p) { return (p << 1) + 1; }

    int rightc(int p) { return (p << 1) + 2; }

    ll join(ll a, ll b) { return min(a, b); }



    void build(int p, int L, int R) {

        if (L == R) { st[p] = A[L]; }

        else {

            int c = (L + R)/2, p1 = leftc(p), p2 = rightc(p);

            build(p1, L, c);

            build(p2, c + 1, R);

            st[p] = join(st[p1], st[p2]);

        }

    }



    ll query(int p, int L, int R, int i, int j) {

        if (i == L && j == R) { return st[p]; }

        int c = (L + R)/2, p1 = leftc(p), p2 = rightc(p);

        if ( j <= c ) { return query(p1, L, c, i, j); }

        if ( i > c ) { return query(p2, c + 1, R, i, j); }

        ll q1 = query(p1, L, c, i, c), q2 = query(p2, c + 1, R, c + 1, j);

        return join(q1, q2);

    }



public:

    SegmentTree(const vector<ll> &_A) {

        A = _A; n = (int)A.size();

        st.assign(4 * n, 0);

        build(0, 0, n - 1);

    }

    ll query(int i, int j) { return query(0, 0, n - 1, i, j); }

};



int main() {

    ios_base::sync_with_stdio(0);

    cin.tie(0);



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

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



    ll n, x;



    cin>>n>>x;

    vector<ll> colors(n);

    ll sol = 0;

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

        cin>>colors[i];

        sol += colors[i];

    }



    SegmentTree st(colors);



    ll psol, mincol;



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

        psol = x * p;

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

            mincol = st.query(max(0, i - p), i);

            if(p > i) { mincol = min(mincol, st.query(n - p + i, n - 1)); }

            psol += mincol;

        }

        sol = min(sol, psol);

    }



    cout<<sol<<"\n";



    return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.357908305347775x):
#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);

}
// 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: 5.236900552738482x):
#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);

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

const long long inf=2e18;

#define N 2050

#define res register int

#define ll long long

using namespace std;

ll a[N],x,n,m,f[N][N],sum,ans;

int main()

{

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

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

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

	sum=inf;

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

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

	

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

	{

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

		{

			ll tim=i-j;

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

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

		}

	}

	

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

	{

		ans=0;

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

		ans+=f[j][i];

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

	}

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

}

// Faster C++ solution for the same problem (measured speedup: 5.1627247387129x):
#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);

}
// Slower C++ solution:
#pragma GCC optimize(2)

#include<bits/stdc++.h>

using namespace std;

typedef long long LL;

const int maxn = 2e3 + 5;

LL a[maxn],b[maxn][maxn];



int sleep() {

	int j=0;

	for(int i=1; i<2000001; i++) j++;

	return j;

}



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);

	}

	printf("%lld",sum);

	sleep();

	return 0;

}

// Faster C++ solution for the same problem (measured speedup: 5.219776914733039x):
#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);

}