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

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.338770560236849x):
#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,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.42173890522413x):
#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<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: 5.409468681209193x):
#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;

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

}

// Faster C++ solution for the same problem (measured speedup: 1.1190699776227977x):
#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 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.199755440198083x):
#include<cstdio>

#include<cstring>

#define LL long long

#define INF (LL)1e16

#define maxn 2005

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

#define max(a,b) ((a)>(b)?(a):(b))

int n,x,a[maxn],minx[maxn][maxn];

LL ans=INF;

int main()

{

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

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

	{

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

		minx[i][1]=a[i];

	}

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

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

			minx[i][j]=min(minx[(i==1)?n:(i-1)][j-1],a[i]);

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

	{

		LL tmp=0;

		for(int i=1;i<=n;i++) tmp+=1ll*minx[i][j];

		ans=min(ans,tmp+1ll*x*(j-1));

	}

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

}
// 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.2210712213861905x):
#include<cstdio>

#include<cstring>

#define LL long long

#define INF (LL)1e16

#define maxn 2005

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

#define max(a,b) ((a)>(b)?(a):(b))

int n,x,a[maxn],minx[maxn][maxn];

LL ans=INF;

int main()

{

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

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

	{

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

		minx[i][1]=a[i];

	}

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

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

			minx[i][j]=min(minx[(i==1)?n:(i-1)][j-1],a[i]);

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

	{

		LL tmp=0;

		for(int i=1;i<=n;i++) tmp+=1ll*minx[i][j];

		ans=min(ans,tmp+1ll*x*(j-1));

	}

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

#include<cstring>

#define LL long long

#define INF (LL)1e16

#define maxn 2005

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

#define max(a,b) ((a)>(b)?(a):(b))

int n,x,a[maxn],minx[maxn][maxn];

LL ans=INF;

int main()

{

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

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

	{

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

		minx[i][1]=a[i];

	}

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

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

			minx[i][j]=min(minx[(i==1)?n:(i-1)][j-1],a[i]);

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

	{

		LL tmp=0;

		for(int i=1;i<=n;i++) tmp+=1ll*minx[i][j];

		ans=min(ans,tmp+1ll*x*(j-1));

	}

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

#include<cstring>

#define LL long long

#define INF (LL)1e16

#define maxn 2005

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

#define max(a,b) ((a)>(b)?(a):(b))

int n,x,a[maxn],minx[maxn][maxn];

LL ans=INF;

int main()

{

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

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

	{

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

		minx[i][1]=a[i];

	}

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

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

			minx[i][j]=min(minx[(i==1)?n:(i-1)][j-1],a[i]);

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

	{

		LL tmp=0;

		for(int i=1;i<=n;i++) tmp+=1ll*minx[i][j];

		ans=min(ans,tmp+1ll*x*(j-1));

	}

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

#include<cstring>

#define LL long long

#define INF (LL)1e16

#define maxn 2005

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

#define max(a,b) ((a)>(b)?(a):(b))

int n,x,a[maxn],minx[maxn][maxn];

LL ans=INF;

int main()

{

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

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

	{

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

		minx[i][1]=a[i];

	}

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

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

			minx[i][j]=min(minx[(i==1)?n:(i-1)][j-1],a[i]);

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

	{

		LL tmp=0;

		for(int i=1;i<=n;i++) tmp+=1ll*minx[i][j];

		ans=min(ans,tmp+1ll*x*(j-1));

	}

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

}