stablegradients/pie-gem5-pairs huggingface dataset:
// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;



#ifdef Lin1043

    #define DEBUG(msg, ...) printf("(%s #%d) " msg, __FUNCTION__, __LINE__, __VA_ARGS__)

    #define massert(...) assert(...)

#else

    #define DEBUG(...)

    #define massert(...)

#endif



#define rep(i , l , r) for(int i = (l) , ___ = (r) ; i <= ___ ; ++i )

#define per(i , r , l) for(int i = (r) , ___ = (l) ; i >= ___ ; --i )



struct iopener

{

    iopener()

    {

#ifdef Lin1043

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

#endif

    }

} iop;



typedef long long LL;



template<typename T>inline bool chkmin(T &x , const T &y) { return x > y ? (x = y , 1) : 0; }

template<typename T>inline bool chkmax(T &x , const T &y) { return x < y ? (x = y , 1) : 0; }



template<typename T>inline T read(T &f)

{

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

    while(!isdigit(c)) x = (c == '-' ? -1 : 1) , c = getchar();

    while(isdigit(c)) (f *= 10) += c & 15 , c = getchar();

    return f = x * f;

}



const int N = 2000 + 5;



int n , m , A[N] , mn[N][N];



LL Ans = 1ll << 60;



int main()

{

    read(n) , read(m);

    rep(i , 1 , n) read(A[i]);

    rep(i , 1 , n)

    {

        int x = A[i];

        rep(j , i , n)

            chkmin(x , A[j]) , mn[i][j] = x;

    }

    rep(i , 0 , n - 1)

    {

        LL res = 1ll * i * m;

        rep(j , 1 , n)

        {

            res += j > i ? mn[j - i][j] :

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

        }

        chkmin(Ans , res);

    }

    cout << Ans << endl;

    return 0;

}


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

using namespace std;

#define ll long long

#define inf 0x3f3f3f3f3f3f3f3f

ll a[2050];ll n;ll x;

ll cyz[2050];

int main(){

	std::ios::sync_with_stdio(false);

	cin>>n;cin>>x;

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

		cin>>a[i];cyz[i]=a[i];

	}

	ll minn=inf;ll res=0;

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

		ll temp=0;

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

			int pos=i-k;

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

			cyz[i]=min(cyz[i],a[pos]);

			temp+=cyz[i];

		}

		temp+=x*k;

		minn=min(temp,minn);

	}

	cout<<minn<<endl;

}

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

 

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



typedef long long LL;



const int MAXN = 2000;

int n, x, a[MAXN + 5], mn[MAXN + 5];



template<typename Tp>

inline void chkmin ( Tp& a, const Tp b ) { if ( b < a ) a = b; }



int main () {

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

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

	LL ans = 1ll << 60;

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

		LL now = 1ll * k * x;

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

			chkmin ( mn[i], a[( i + k - 1 ) % n + 1] );

			now += mn[i];

		}

		chkmin ( ans, now );

	}

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

	return 0;

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



typedef long long LL;



const int MAXN = 2000;

int n, x, a[MAXN + 5], mn[MAXN + 5];



template<typename Tp>

inline void chkmin ( Tp& a, const Tp b ) { if ( b < a ) a = b; }



int main () {

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

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

	LL ans = 1ll << 60;

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

		LL now = 1ll * k * x;

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

			chkmin ( mn[i], a[( i + k - 1 ) % n + 1] );

			now += mn[i];

		}

		chkmin ( ans, now );

	}

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

	return 0;

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



typedef long long LL;



const int MAXN = 2000;

int n, x, a[MAXN + 5], mn[MAXN + 5];



template<typename Tp>

inline void chkmin ( Tp& a, const Tp b ) { if ( b < a ) a = b; }



int main () {

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

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

	LL ans = 1ll << 60;

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

		LL now = 1ll * k * x;

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

			chkmin ( mn[i], a[( i + k - 1 ) % n + 1] );

			now += mn[i];

		}

		chkmin ( ans, now );

	}

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

	return 0;

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



typedef long long LL;



const int MAXN = 2000;

int n, x, a[MAXN + 5], mn[MAXN + 5];



template<typename Tp>

inline void chkmin ( Tp& a, const Tp b ) { if ( b < a ) a = b; }



int main () {

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

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

	LL ans = 1ll << 60;

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

		LL now = 1ll * k * x;

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

			chkmin ( mn[i], a[( i + k - 1 ) % n + 1] );

			now += mn[i];

		}

		chkmin ( ans, now );

	}

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

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



typedef long long LL;



const int MAXN = 2000;

int n, x, a[MAXN + 5], mn[MAXN + 5];



template<typename Tp>

inline void chkmin ( Tp& a, const Tp b ) { if ( b < a ) a = b; }



int main () {

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

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

	LL ans = 1ll << 60;

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

		LL now = 1ll * k * x;

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

			chkmin ( mn[i], a[( i + k - 1 ) % n + 1] );

			now += mn[i];

		}

		chkmin ( ans, now );

	}

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

	return 0;

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



typedef long long LL;



const int MAXN = 2000;

int n, x, a[MAXN + 5], mn[MAXN + 5];



template<typename Tp>

inline void chkmin ( Tp& a, const Tp b ) { if ( b < a ) a = b; }



int main () {

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

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

	LL ans = 1ll << 60;

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

		LL now = 1ll * k * x;

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

			chkmin ( mn[i], a[( i + k - 1 ) % n + 1] );

			now += mn[i];

		}

		chkmin ( ans, now );

	}

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

	return 0;

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



typedef long long LL;



const int MAXN = 2000;

int n, x, a[MAXN + 5], mn[MAXN + 5];



template<typename Tp>

inline void chkmin ( Tp& a, const Tp b ) { if ( b < a ) a = b; }



int main () {

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

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

	LL ans = 1ll << 60;

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

		LL now = 1ll * k * x;

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

			chkmin ( mn[i], a[( i + k - 1 ) % n + 1] );

			now += mn[i];

		}

		chkmin ( ans, now );

	}

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

	return 0;

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



using namespace std;



#ifdef Lin1043

    #define DEBUG(msg, ...) printf("(%s #%d) " msg, __FUNCTION__, __LINE__, __VA_ARGS__)

    #define massert(...) assert(...)

#else

    #define DEBUG(...)

    #define massert(...)

#endif



#define rep(i , l , r) for(int i = (l) , ___ = (r) ; i <= ___ ; ++i )

#define per(i , r , l) for(int i = (r) , ___ = (l) ; i >= ___ ; --i )



struct iopener

{

    iopener()

    {

#ifdef Lin1043

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

#endif

    }

} iop;



typedef long long LL;



template<typename T>inline bool chkmin(T &x , const T &y) { return x > y ? (x = y , 1) : 0; }

template<typename T>inline bool chkmax(T &x , const T &y) { return x < y ? (x = y , 1) : 0; }



template<typename T>inline T read(T &f)

{

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

    while(!isdigit(c)) x = (c == '-' ? -1 : 1) , c = getchar();

    while(isdigit(c)) (f *= 10) += c & 15 , c = getchar();

    return f = x * f;

}



const int N = 2000 + 5;



int n , m , A[N] , mn[N][N];



LL Ans = 1ll << 60;



int main()

{

    read(n) , read(m);

    rep(i , 1 , n) read(A[i]);

    rep(i , 1 , n)

    {

        int x = A[i];

        rep(j , i , n)

            chkmin(x , A[j]) , mn[i][j] = x;

    }

    rep(i , 0 , n - 1)

    {

        LL res = 1ll * i * m;

        rep(j , 1 , n)

        {

            res += j > i ? mn[j - i][j] :

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

        }

        chkmin(Ans , res);

    }

    cout << Ans << endl;

    return 0;

}


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



typedef long long LL;



const int MAXN = 2000;

int n, x, a[MAXN + 5], mn[MAXN + 5];



template<typename Tp>

inline void chkmin ( Tp& a, const Tp b ) { if ( b < a ) a = b; }



int main () {

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

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

	LL ans = 1ll << 60;

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

		LL now = 1ll * k * x;

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

			chkmin ( mn[i], a[( i + k - 1 ) % n + 1] );

			now += mn[i];

		}

		chkmin ( ans, now );

	}

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

	return 0;

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

using namespace std;

#define ll long long

#define inf 0x3f3f3f3f3f3f3f3f

ll a[2050];ll n;ll x;

ll cyz[2050];

int main(){

	std::ios::sync_with_stdio(false);

	cin>>n;cin>>x;

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

		cin>>a[i];cyz[i]=a[i];

	}

	ll minn=inf;ll res=0;

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

		ll temp=0;

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

			int pos=i-k;

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

			cyz[i]=min(cyz[i],a[pos]);

			temp+=cyz[i];

		}

		temp+=x*k;

		minn=min(temp,minn);

	}

	cout<<minn<<endl;

}

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



typedef long long LL;



const int MAXN = 2000;

int n, x, a[MAXN + 5], mn[MAXN + 5];



template<typename Tp>

inline void chkmin ( Tp& a, const Tp b ) { if ( b < a ) a = b; }



int main () {

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

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

	LL ans = 1ll << 60;

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

		LL now = 1ll * k * x;

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

			chkmin ( mn[i], a[( i + k - 1 ) % n + 1] );

			now += mn[i];

		}

		chkmin ( ans, now );

	}

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

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



int main(){

    int n;

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

    cin >> n >> x;

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

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

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

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

            int pos = i - k;

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

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

        }

    }

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

        LL ans = 0;

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

            ans += b[i][k];

        }

        sum = min(sum,ans + x * k);//取最小值.

    }

    cout << sum << endl;

}


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



typedef long long LL;



const int MAXN = 2000;

int n, x, a[MAXN + 5], mn[MAXN + 5];



template<typename Tp>

inline void chkmin ( Tp& a, const Tp b ) { if ( b < a ) a = b; }



int main () {

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

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

	LL ans = 1ll << 60;

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

		LL now = 1ll * k * x;

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

			chkmin ( mn[i], a[( i + k - 1 ) % n + 1] );

			now += mn[i];

		}

		chkmin ( ans, now );

	}

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

	return 0;

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

 

using namespace std;

const int N=2000+10;

typedef long long ll;

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

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

int main()

{

    int n;

    ll x,ans=llf;

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

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

    {

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

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

    }

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

    {

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

        {

            int ind=j-i;

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

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

        }

    }

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

    {

        ll ant=0;

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

            ant+=dp[i][j];

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

       // cout<<ans<<endl;

    }

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

    return 0;

}

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



typedef long long LL;



const int MAXN = 2000;

int n, x, a[MAXN + 5], mn[MAXN + 5];



template<typename Tp>

inline void chkmin ( Tp& a, const Tp b ) { if ( b < a ) a = b; }



int main () {

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

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

	LL ans = 1ll << 60;

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

		LL now = 1ll * k * x;

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

			chkmin ( mn[i], a[( i + k - 1 ) % n + 1] );

			now += mn[i];

		}

		chkmin ( ans, now );

	}

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

	return 0;

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

using namespace std;



typedef long long ll;



int main() {

	ll N,x;

	cin>>N>>x;

	vector<ll> a(N), dp(N,LLONG_MAX);

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

		cin>>a[i];

	ll ret=LLONG_MAX;

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

		ll cur=0;

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

			dp[j]=min(dp[j],a[(j+N-i)%N]), cur+=dp[j];

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

	}

	cout<<ret<<"\n";

	return 0;

}

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



typedef long long LL;



const int MAXN = 2000;

int n, x, a[MAXN + 5], mn[MAXN + 5];



template<typename Tp>

inline void chkmin ( Tp& a, const Tp b ) { if ( b < a ) a = b; }



int main () {

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

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

	LL ans = 1ll << 60;

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

		LL now = 1ll * k * x;

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

			chkmin ( mn[i], a[( i + k - 1 ) % n + 1] );

			now += mn[i];

		}

		chkmin ( ans, now );

	}

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

	return 0;

}