stablegradients/pie-gem5-pairs huggingface dataset:
// 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.2887324528475315x):
#include<cstdio>

#include<algorithm>

using namespace std;



#define MAXN 2000

int N,X;

int Cost[MAXN+5],Change[MAXN+5][MAXN+5];



int main(){

    scanf("%d%d",&N,&X);

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

        scanf("%d",Cost+i);

    long long Ans=1ll<<60,tot=0;

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

        tot+=Change[i][0]=Cost[i];

    Ans=min(Ans,tot);

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

        tot=0;

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

            tot+=Change[i][k]=min(Change[i][k-1],Cost[i-k<1?N+i-k:i-k]);

        Ans=min(Ans,1ll*k*X+tot);

    }

    printf("%lld",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: 5.2205002980882x):
#include<cstdio>

#include<algorithm>

using namespace std;



#define MAXN 2000

int N,X;

int Cost[MAXN+5],Change[MAXN+5][MAXN+5];



int main(){

    scanf("%d%d",&N,&X);

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

        scanf("%d",Cost+i);

    long long Ans=1ll<<60,tot=0;

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

        tot+=Change[i][0]=Cost[i];

    Ans=min(Ans,tot);

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

        tot=0;

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

            tot+=Change[i][k]=min(Change[i][k-1],Cost[i-k<1?N+i-k:i-k]);

        Ans=min(Ans,1ll*k*X+tot);

    }

    printf("%lld",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: 5.158577843519815x):
#include<cstdio>

#include<algorithm>

using namespace std;



#define MAXN 2000

int N,X;

int Cost[MAXN+5],Change[MAXN+5][MAXN+5];



int main(){

    scanf("%d%d",&N,&X);

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

        scanf("%d",Cost+i);

    long long Ans=1ll<<60,tot=0;

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

        tot+=Change[i][0]=Cost[i];

    Ans=min(Ans,tot);

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

        tot=0;

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

            tot+=Change[i][k]=min(Change[i][k-1],Cost[i-k<1?N+i-k:i-k]);

        Ans=min(Ans,1ll*k*X+tot);

    }

    printf("%lld",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.299972876305007x):
#include<cstdio>

#include<cstring>

#include<algorithm>

using namespace std;

#define MAXN 2005

#define LL long long

LL n,x;

LL a[MAXN],dp[MAXN][MAXN];

int main()

{

	LL ans=1LL<<60LL;

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

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

	{

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

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

	}

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

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

		{

			int pos=i-j;

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

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

		}

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

	{

		LL sum=0;

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

			sum+=dp[i][j];

		ans=min(ans,sum+x*j);//x必须要开long long 否则x和j都是int 乘起来要爆掉的

	}

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

#include<cstring>

#include<algorithm>

using namespace std;

#define MAXN 2005

#define LL long long

LL n,x;

LL a[MAXN],dp[MAXN][MAXN];

int main()

{

	LL ans=1LL<<60LL;

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

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

	{

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

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

	}

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

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

		{

			int pos=i-j;

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

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

		}

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

	{

		LL sum=0;

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

			sum+=dp[i][j];

		ans=min(ans,sum+x*j);//x必须要开long long 否则x和j都是int 乘起来要爆掉的

	}

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

#include<cstring>

#include<algorithm>

using namespace std;

#define MAXN 2005

#define LL long long

LL n,x;

LL a[MAXN],dp[MAXN][MAXN];

int main()

{

	LL ans=1LL<<60LL;

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

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

	{

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

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

	}

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

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

		{

			int pos=i-j;

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

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

		}

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

	{

		LL sum=0;

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

			sum+=dp[i][j];

		ans=min(ans,sum+x*j);//x必须要开long long 否则x和j都是int 乘起来要爆掉的

	}

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

#include<cstring>

#include<algorithm>

using namespace std;

#define MAXN 2005

#define LL long long

LL n,x;

LL a[MAXN],dp[MAXN][MAXN];

int main()

{

	LL ans=1LL<<60LL;

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

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

	{

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

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

	}

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

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

		{

			int pos=i-j;

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

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

		}

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

	{

		LL sum=0;

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

			sum+=dp[i][j];

		ans=min(ans,sum+x*j);//x必须要开long long 否则x和j都是int 乘起来要爆掉的

	}

	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.29936167161207x):
#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>



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.287183066307802x):
#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 <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.218970900833825x):
#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<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.157066587061645x):
#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>

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.159543884821339x):
#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:
#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.304136822507199x):
#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;

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.291947243300482x):
#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;

}