Language: C++

#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}

inline template<typename T>
T up(const T& l, const T& r) {//SegmentTreeのupdate関数
    T res;
    res = min<T>(l,r);
    return res;
}

inline template<typename T>
class SegmentTree {
public:
    vector<T> seg;
    int sz = 1;
    T unit;
    //T (*up)(const T& l,const T& r);
    SegmentTree(int n, T unit = 0) {
        this->unit = unit;
        //int sz = 1;
        while (sz < n) sz <<= 1;
        seg.resize(sz * 2, unit);
        //up = &up1;
    }
    void set(const int& k, const T& x) {//左からk番目の葉にxを代入する
        seg[sz - 1 + k] = x;
    }
    T get(const int& k) {//左からk番目の葉を得る
        return seg[sz - 1 + k];
    }
    void update(int k, const T& v) {// k 番目の値をvに変更
        k += sz - 1;
        seg[k] = v;
        while (k > 0) {
            k = (k - 1) / 2;
            seg[k] = up(seg[2 * k + 1], seg[2 * k + 2]);
        }
    }
    T query(int a, int b, int k, int l,int r) {//[a,b)のupの合成を求める(a,b,0,0,sz)のように使う
        if (r <= a || b <= l) {
            return unit;
        }
        if (a <= l && r <= b) {
            return seg[k];
        }
        else {
            T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
            T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
            return up(vl, vr);
        }
    }
};

int main(){
    int n;
    ll x;
    cin >> n >> x;
    vector<ll> a(n*2);
    REP(i,n){
        cin >> a[i];
        a[i+n] = a[i];
    }
    SegmentTree<ll> sg(n*2,LLONG_MAX);
    Rep(i,n){
        sg.update(i,a[i]);
        sg.update(i+n,a[i+n]);
    }
    ll res = LLONG_MAX;
    Rep(k,n){
        ll cost = k*x;
        int sz = sg.sz;
        Rep(j,n){
            if(j-k<0){
                cost+=sg.query(j-k+n,j+1+n,0,0,sz);
            }else{
                cost+=sg.query(j-k,j+1,0,0,sz);
            }
        }
        chmin(res,cost);
    }
    put(res);
    return 0;
}



Compiler output:
a.cc:19:16: error: expected unqualified-id before '<' token
   19 | inline template<typename T>
      |                ^
a.cc:24:2: error: expected ';' before 'inline'
   24 | }
      |  ^
      |  ;
   25 | 
   26 | inline template<typename T>
      | ~~~~~~
a.cc: In function 'int main()':
a.cc:78:5: error: 'SegmentTree' was not declared in this scope
   78 |     SegmentTree<ll> sg(n*2,LLONG_MAX);
      |     ^~~~~~~~~~~
a.cc:78:19: error: expected primary-expression before '>' token
   78 |     SegmentTree<ll> sg(n*2,LLONG_MAX);
      |                   ^
a.cc:78:21: error: 'sg' was not declared in this scope
   78 |     SegmentTree<ll> sg(n*2,LLONG_MAX);
      |                     ^~