#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>
#include <bitset>
#include <functional>
#include <cassert>
//#include <atcoder/all>

using namespace std;
//using namespace atcoder;

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using ld = long double;
using vld = vector<ld>;
using vb = vector<bool>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define dbg(x) true
#endif

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}
template <class T> ostream& operator<<(ostream& s, const vector<T>& a) { for(auto i : a) s << i << ' '; return s; }

constexpr ll INFL = 1LL << 60;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

void solve() {
    ll n, cp;
    cin >> n >> cp;
    vpll p;
    rep(i, n) {
        ll a, b, c;
        cin >> a >> b >> c;
        p.emplace_back(a, c);
        p.emplace_back(b+1, -c);
    }
    sort(p.begin(), p.end());
    vpll p2;
    for(auto i : p) {
//        cout << i.first << ' ' << i.second << endl;
        ll sz = p2.size();
//        rep(j, sz) cout << p2[j].first << ':' << p2[j].second << endl;
        if(sz > 0 && p[sz-1].first == i.first) {
//            cout << p[sz-1].second << endl;
            p2[sz-1].second += i.second;
//            cout << "a" << endl;
//            cout << p[sz-1].second << endl;
        }
        else {
            p2.push_back(i);
        }
    }
//    cout << "end" << endl;
    ll last = 0;
    ll now = 0;
    ll ans = 0;
    for(auto i : p2) {
//        cout << i.first << ' ' << i.second << endl;
        ll span = i.first - last;
        ans += min(now, cp) * span;
        last = i.first;
        now += i.second;
    }
    cout << ans << endl;
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
const vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T>void debag(const vector<T> &a){cerr<<"debag :";for(auto v:a)cerr<<v<<" ";cerr<<"\n";}
template<class T>void print(const vector<T> &a){for(auto v:a)cout<<v<<" ";cout<<"\n";}
int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    n++;
    V<ll> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    ll mi=inf;
    for(int i=1;i<n;i++){
         chmin(mi,abs(a[i-1]-a[i]));
    }
    V<ll> res(n);
    for(int i=0;i<n;i++){
          res[i]=a[i]/mi;
          a[i]%=mi;
    }
V<V<ll>> ans(mi,res);
int num=0;
   while(*max_element(all(a))!=0){
          for(int i=0;i<n;i++){
              if(a[i]!=0){
                ans[num][i]++;
                a[i]--;
              }
          }
          num++;
   }
   cout<<mi<<"\n";
   for(int i=0;i<mi;i++)print(ans[i]);
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn=1001000,maxm=0,mod=998244353;
int n;
//int a[maxn];
//vector <int> v;
//char s[maxn];
inline int read(){
    int res=0;
    char ch=getchar(),ch1=ch;
    while(!isdigit(ch))ch1=ch,ch=getchar();
    while(isdigit(ch))res=(res<<3)+(res<<1)+ch-'0',ch=getchar();
    return ch1=='-'?-res:res;
}
void proc(){
    int n=read();
    int ans=0;
    for(int i=1;i<=n;++i){
        ans+=max(0,read()-10);
    }
    cout<<ans<<endl;
}
int main(){
    int T=1;
    while(T--)proc();
    return 0;
}

#include <bits/stdc++.h>
#define int long long
#define sum(v) accumulate(v.begin(), v.end(), 0)
#define $ cout<<"YES\n"
#define _$ cout<<"NO\n"
using namespace std;

int32_t main(){
	int k,y,a,b,t; cin>>t;
	int ans = 0;
	while(t--){
		cin>>a;
		if (a>10)
		{
			ans=ans+(a-10);
		}
	}cout<<ans;
	return 0;
}


#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#include<iostream>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

int A[200200];
const int mod = 998244353;
constexpr ll modpow(ll A, ll B) {
	ll kotae = 1;
	while (B > 0) {
		if (B & 1) kotae = kotae * A % mod;
		A = A * A % mod;
		B >>= 1;
	}
	return kotae;
}
const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += 72 - dig >> 3;
	return tmp;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N = getint();
	rep1(i, N) A[i] = getint();

	int kotae = 0;
	rep1(i, N) {
		if (A[i] < 0) continue;
		int k = i;
		while (A[k] > 0) {
			int tmp = A[k];
			A[k] = -i;
			k = tmp;
		}
		kotae += (A[k] == -i);
	}

	co(modpow(2, kotae) - 1);

	Would you please return 0;
}

#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (b) - 1; i >= (a); i--)
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define ALL(i) (i).begin(),(i).end()
#define RALL(i) (i).begin(),(i).end(),greater<int>()

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second

typedef long long ll;
#define TENNINE 1000000005
#define TENFIVE 100005
#define TENFIVE2 200005
// #define int long long
const int INF = 999999999;
const int MOD = 1e9 + 7;
const double EPS = 1e9 + 7;
const double PI = acos(-1);
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

inline int in(){int x;std::cin>>x;return x;}

using lint = long long;
using pint = pair<int, int>;
using vi = vector<int>;
using vii = vector<vector<int> >;
using vl = vector<long long>;
using vp = vector<pint>;

template <typename T> void print(T x) { std::cout << x << '\n'; }
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T*)array, (T*)(array + N), val);
}
signed main(){
  string S;
  string T;
  cin>>S>>T;
  if (S =="Y"){
    // string newT ="";

    if(T=="a")T="A";
    if(T=="b")T="B";
    if(T=="c")T="C";

  }
  print(T);

  return 0;
}


#include <bits/stdc++.h>

#include <iostream>
using namespace std;

vector<vector<vector<double>>> dp(
    110, vector<vector<double>>(110, vector<double>(110, -1)));

double query(int x, int y, int z) {
    // cout << x << " " << y << " " << z << endl;
    if (x >= 100 || y >= 100 || z >= 100) {
        return 0;
    } else if (dp[x][y][z] >= 0) {
        return dp[x][y][z];
    } else {
        double s = x + y + z;
        dp[x][y][z] = double(x) / s * (query(x + 1, y, z) + 1) +
                      double(y) / s * (query(x, y + 1, z) + 1) +
                      double(z) / s * (query(x, y, z + 1) + 1);
        return dp[x][y][z];
    }
}

int main() {
    int A, B, C;
    cin >> A >> B >> C;

    cout << setprecision(12) << query(A, B, C) << endl;

    return 0;
}

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
#define fast
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
   /* ll t;
    cin >> t;
    while (t--)
    {*/
      ll a,b,c;
      cin>>a>>b>>c;
      ll x,y,z;
      x=a*a;
      y=b*b;
      z=c*c;
      if(x+y<z){
          cout<<"Yes"<<endl;
      }
      else{
          cout<<"No"<<endl;
      }

   // }
    return 0;
}


// Created by ...
#include <bits/stdc++.h>

#define vll vector< ll >
#define M 100000
#define MD 1000000007
#define pb push_back
#define sz(x) (int)(x).size()
#define rep(i,a,b) for(ll i = a; i <= b; ++i)
#define per(i,a,b) for(ll i = a; i >= b; --i)
#define pii pair<ll,ll>
#define vec(a) vector<a >
#define all(a) (a).begin(),(a).end()
#define EACH(x, a) for (auto& x:a)
#define se second
#define fi first
#define inf 0xffffffff
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

using namespace std;
using ll = long long;
ll md=MD;

ll exp(ll a,ll b){ll r=1ll;while(b>0){if(b&1){r=r*(a%md);r=(r+md)%md;}b>>=1;a=(a%md)*(a%md);a=(a+md)%md;}return (r+md)%md;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
template<class T> T Min(T a,T b){if(a<b)return a; return b;}
template<class T> T Max(T a,T b){if(a>b)return a; return b;}

int32_t main() {
    IOS;

        ll n;
        cin>>n;
        vll v(2*n);
        rep(i,0,2*n-1) cin>>v[i];
        vll o(2*n);
        iota(all(o),0);
        sort(all(o),[&](int i,int j){
            return v[i]<v[j];
        });
        rep(i,0,n-1)v[o[i]]=0;
        rep(i,n,2*n-1)v[o[i]]=1;
        string ans;
        stack<int> st;
        rep(i,0,2*n-1){
            if(st.empty()){
                ans+='(';
                st.push(v[i]);
            }
            else{
                if(st.top()==v[i]){
                    st.push(v[i]);
                    ans+='(';
                }
                else{
                    ans+=')';
                    st.pop();
                }
            }
        }
        cout<<ans;
        cout<<'\n';
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;
template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
// long long mod = 998244353;
#define REP(i, n) for (long long i = 0; i < (n); i++)
#define rep(i, a, n) for (long long i = a; i < (n); i++)
typedef long long ll;
typedef pair<ll, ll> P;
long long mod = 1000000007;
long long modpow(long long m, long long n, long long modvalue) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2, modvalue);
        return t * t % modvalue;
    } else {
        return modpow(m, n - 1, modvalue) * m % modvalue;
    }
}

long long moddiv(long long a, long long b, ll modvalue) { return (a * modpow(b, mod - 2, modvalue)) % modvalue; }

const ll INF = 1LL << 60;

string change_binary(long long a) {
    string ret;
    for (int i = 31; i >= 0; i--) {
        ret += (a >> i & 1) + '0';
    }
    return ret;
}

ll nCkmod(ll n, ll k, ll modvalue) {
    ll numera = 1;
    for (int i = n; i > n - k; i--) {
        numera *= i;
        numera %= modvalue;
    }
    ll denomi = 1;
    REP(i, k) {
        denomi *= (i + 1);
        denomi %= modvalue;
    }
    return moddiv(numera, denomi, modvalue);
}

map<ll, ll> cnt;
void primeFactors(long long n) {
    while (n % 2 == 0) {
        cnt[2]++;
        n = n / 2;
    }
    for (int i = 3; i <= sqrt(n); i = i + 2) {
        while (n % i == 0) {
            cnt[i]++;
            n = n / i;
        }
    }
    if (n > 2) {
        cnt[n]++;
    }
}
vector<ll> dijkstra(vector<vector<P>> graph, ll s) {
    vector<ll> ans(graph.size(), -1);
    priority_queue<P, vector<P>, greater<P>> pq;
    pq.push({0, s});
    while (pq.size() > 0) {
        ll cur1 = 0;
        ll cur2 = 0;
        if (ans[pq.top().second] != -1) {
            pq.pop();
        } else {
            cur1 = pq.top().first;
            cur2 = pq.top().second;
            pq.pop();
            ans[cur2] = cur1;
            for (ll i = 0; i < graph[cur2].size(); i++) {
                pq.push({cur1 + graph[cur2][i].first, graph[cur2][i].second});
            }
        }
    }
    return ans;
}
ll gcd(ll a, ll b) {
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}
struct UnionFind {
    vector<int> parent, size;
    UnionFind(int n) {
        parent.resize(n, -1);
        size.resize(n, 1);
    }
    void unite(int x, int y) {
        if (same(x, y)) {
            return;
        }
        x = root(x);
        y = root(y);
        if (size[x] <= size[y]) {
            swap(x, y);
        }
        parent[y] = x;
        size[x] += size[y];
    }
    bool same(int x, int y) { return (root(x) == root(y)); }
    int root(int x) {
        while (parent[x] != -1) {
            x = parent[x];
        }
        return x;
    }
    int getsize(int x) { return size[root(x)]; }
};
double dp[103][103][103];
int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << a * d - b * c << endl;
}


#include <bits/stdc++.h>
using namespace std;

int str(string n)   {
        return (n[0] - '0') + (n[1]- '0') + (n[2]- '0');
}

int main()
{
    string a,b;
    cin>>a>>b;

    printf("%d\n",max(str(a),str(b)));

    return 0;
}

#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <tuple>
#include <utility>
#include <functional>
#include <set>
#include <map>
#include <bitset>
#include <list>
#include<iomanip>

using namespace std;
using ll = long long;
using ULL = unsigned long long;
using pll = std::pair<ll, ll>;
using vi = std::vector<int>;
using vl = std::vector<ll>;
using vb = std::vector<bool>;
using db = double;
using vdb = std::vector<db>;
using qlg= std::priority_queue<ll, vl, std::greater<ll> > ; //ascending
using qll= std::priority_queue<ll, vl, std::less<ll> > ; // descending
using qdg= std::priority_queue<db, vdb, std::greater<db> > ; //ascending
using qdl= std::priority_queue<db, vdb, std::less<db> > ; // descending
template<class T>
using vv = std::vector<std::vector<T> >;

#define REPL(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FORL(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define REP(i, n) FORL(i, 0, n)

#define MREP(i, n) for (ll i= (ll)(n)-1; i>=0; i-- )
#define MFOR(i, a, b) for (ll i = (ll)(b)-1; i >= (ll)(a); i--)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rreps(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define bit(n) (1LL << (n))
#define INF pow(10, 10)

int main(void)
{
    ll S, P, N, M, Q, a, b, c, x, y, K;
    string Str;
    cin >> a >> b;

    ll d =0, e=0;
    while(a>0)
    {
        d += a%10;
        a/= 10;
    }

    while(b>0)
    {
        e += b%10;
        b/= 10;
    }

    cout << max(d, e)<< endl;

    return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#include<stdio.h>
#include<math.h>
#include<string.h>
using namespace std;

int main() {
   long long int t,n,i,j,k,l,m,max1=0,count=0;
  long long int a[300001];
   scanf("%lld",&n);
   max1=n%100;
   if(max1==0)
   printf("100");
   else
   printf("%lld\n",100-max1);

	return 0;
}

#include <iostream>
#include <cmath>
using namespace std;

int main(){
  int n;
  cin >> n;
  cout << ceil(n/100.0) ;

}


//================code===================//

#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>

#define ci(t) cin>>t
#define co(t) cout<<t
#define LL long long
#define fa(i,a,b) for(int i=a;i<b;++i)
#define fd(i,a,b) for(int i=a;i>b;--i)
#define setp pair<pair<int,int>,int>
#define setl pair<LL,LL>
#define M_PI 3.14159265358979323846
#define micro 0.000001

#ifdef OHSOLUTION
#define ce(t) cerr<<t
#define AT cerr << "\n=================ANS=================\n"
#define AE cerr << "\n=====================================\n"
#else
#define AT
#define AE
#define ce(t)
#endif

using namespace std;

LL gcd(LL a, LL b) { return a % b ? gcd(b, a % b) : b; }
LL lcm(LL a, LL b) { return (a * b) / gcd(a, b); }

pair <int, int> vu[8] = { {0,1},{1,0},{0,-1} ,{-1,0},{-1,1}, {0,1} , {1,1},{1,-1} }; //RDLU EWSN

template<typename T, typename U>
void ckmax(T& a, U b) { a = a < b ? b : a; }
template<typename T, typename U>
void ckmin(T& a, U b) { a = a > b ? b : a; }
struct gcmp { bool operator()(LL a, LL b) { return a < b; } };
struct lcmp { bool operator()(LL a, LL b) { return a > b; } };

const int max_v = 4e5 + 7;
const int INF = 1e9 + 7;
const LL LNF = 1e18 + 7;
const LL mod = 123456789;

int p[max_v];
int np[max_v];
int vist[max_v];
bool check[max_v];
vector <int> vi;

int find(int idx,bool num=false)
{
	if (num) return np[idx] < 0 ? idx : np[idx] = find(np[idx],num);
	return p[idx] < 0 ? idx : p[idx] = find(p[idx],num);
}

void merge(int a, int b,bool num=false)
{
	a = find(a,num);
	b = find(b,num);

	if (a == b) return;

	if (num)
	{
		np[a] += np[b];
		np[b] = a;
		return;
	}

	merge(vi[a], vi[b],true);
	p[a] += p[b];
	p[b] = a;

}

int main()
{
#ifdef OHSOLUTION
	freopen("input.txt", "r", stdin);
#endif
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n; ci(n);
	memset(p, -1, sizeof(p));
	memset(np, -1, sizeof(np));

	vi.resize(n+1);

	fa(i, 1, n + 1)
	{
		int x, y; ci(x >> y);
		merge(x, y, true);
		vi[i] = x;

		if (vist[x]) merge(vist[x], i);
		else { vist[x] = i;  }
		if (vist[y]) merge(vist[y], i);
		else { vist[y] = i;}

	}

	LL ans = 0;

	fa(i, 1, n + 1)
	{
		int x = find(i);
		if (!check[x])
		{
			check[x] = true;

			ce(p[x] * -1 << " " << np[find(vi[x])] * -1 << endl);

			ans += min(p[x] * -1, np[find(vi[x],true)] *-1 );
		}
	}

	AT;
	co(ans);
	AE;

	return 0;
}

#include<bits/stdc++.h>
#define maxn 100005
#define LL long long
using namespace std;
struct edge{
	int nxt,to;
}e[maxn<<1];
int first[maxn],tot;
void add_edge(int x,int y){
	tot++;
	e[tot].nxt=first[x];
	e[tot].to=y;
	first[x]=tot;
}

LL sz[maxn];
LL dp[maxn];
int n;
bool pd(int x){
	LL k=3*sz[x]-2;
	if(k&1)return 1;else return 0;
}
void dfs(int x){
	sz[x]=1;
	for(int i=first[x];i!=-1;i=e[i].nxt){
		int y=e[i].to;
		dfs(y);
		sz[x]+=sz[y];
	}
}

void dfs2(int x){
	dp[x]=1;
	int cnt0=0,cnt1=0;
	multiset<LL>s0,s1;
	LL sum=0;
	s0.clear(),s1.clear();
	for(int i=first[x];i!=-1;i=e[i].nxt){
		int y=e[i].to;
		dfs2(y);
		if(sz[y]&1){
			cnt1++;
			s1.insert(dp[y]);
		}
		else{
			cnt0++;
			s0.insert(dp[y]);
		}
	}
	for(multiset<LL>::iterator it=s0.begin();it!=s0.end();it++){
		if(*it<0)
			dp[x]+=*it;
		else
			sum+=*it;
	}
	int f=0;
	for(multiset<LL>::iterator it=s1.begin();it!=s1.end();it++){
		f=1-f;
		if(f)dp[x]+=*it;else dp[x]-=*it;
	}
	s0.clear(),s1.clear();
	if(cnt1&1)dp[x]-=sum;else dp[x]+=sum;
}

int main(){
	cin>>n;
	memset(first,-1,sizeof(first));
	for(int i=2;i<=n;i++){
		int x;
		cin>>x;
		add_edge(x,i);
	}
	dfs(1);
	dfs2(1);
	cout<<(n+dp[1])/2<<endl;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin() ,(x).end()

const int N = 3e5 + 5;
const ll inf = 1e16;

int dx[] = {1 , 0 , -1 , -1 , 0 , 1};
int dy[] = {1 , 1 ,  0 , -1 , -1 , 0};

void solve() {
	string s;
	cin >> s;

	if (s > "atcoder") {
		cout << "0\n";
		return;
	}
	int n = s.size();
	int pos = -1;
	for (int i = 0 ; i < n ; i++) {
		if (s[i] != 'a') {
			pos = i;
			break;
		}
	}

	if (pos == -1)
		cout << "-1\n";
	else if (s[pos] > 't') cout << pos - 1 << "\n";
	else cout << pos << "\n";
}
int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int t = 1;
	cin >> t;

	while (t--)
		solve();

	return 0;
}

#include <bits/stdc++.h>

#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define reset(a,v) memset((a), v, sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

const int N = (1<<16) + 5;

int n;
int dat[N];
vi players;

int main() {
	scanf("%d", &n);
	for (int i = 0; i < (1<<n); ++i) {
		scanf("%d", &dat[i]);
		players.push_back(i);
	}

	while (sz(players) > 2) {
		vi newPlayers;
		for (int i = 0; i < sz(players); i += 2) {
			if (dat[players[i]] > dat[players[i+1]]) newPlayers.push_back(players[i]);
			else newPlayers.push_back(players[i+1]);
		}

		players = newPlayers;
	}

	if (dat[players[0]] > dat[players[1]]) printf("%d\n", players[1]+1);
	else printf("%d\n", players[0]+1);
	return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
	int a, b;
  	cin >> a >> b;
  	cout << (max(a,b)-min(a,b) < 3 ? "Yes" : "No") << endl;
}

#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int A,B;

signed main(){
	cin>>A>>B;
	if(A>B){
		if(A<B+3){
			cout<<"Yes"<<endl;
		}
		else{
			cout<<"No"<<endl;
		}
	}
	else{
		if(A+3>B){
			cout<<"Yes"<<endl;
		}
		else{
			cout<<"No"<<endl;
		}
	}
	return 0;
}


#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, j, n, ans = 0;
  scanf("%lld", &n);
  ll ca[n + 1], b[n], c;
  for(i = 0; i <= n; ++i) ca[i] = 0;
  for(i = 0; i < n; ++i) scanf("%lld", &c), ca[c]++;
  for(i = 0; i < n; ++i) scanf("%lld", &b[i]);
  for(i = 0; i < n; ++i) scanf("%lld", &c), ans += ca[b[--c]];
  printf("%lld", ans);
  return 0;
}

#pragma region Template  // clang-format off
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
// #include <atcoder/all>
// using namespace atcoder;
#define rep(i, m, n) for (int i = m; i < (int)(n); i++)
#define repe(i, m, n) for (int i = m; i <= (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define yesno {cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using pii = pair<int,int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#pragma endregion Template  // clang-format on

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n);
  rep(i, 0, n) cin >> a[i];
  rep(i, 0, n) cin >> b[i];
  rep(i, 0, n) cin >> c[i];

  vi cnta(n + 1);
  vi cntb(n + 1);

  rep(i, 0, n) {
    cnta[a[i]]++;
    cntb[b[c[i] - 1]]++;
  }

  ll ans = 0;
  repe(i, 1, n) ans += (ll)cnta[i] * cntb[i];

  cout << ans << endl;
}


#include <cassert>
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <complex>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <string>
#include <cstdlib>
#include <memory.h>
#include <ctime>
#include <bitset>
#include <fstream>
#include <queue>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <time.h>
#include <chrono>
#include <random>
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#define UI unsigned int
#define LL long long
#define ll long long
#define GT(it,v) for(auto it:v)
#define FU(i,a,b) for(int i=(a);i<(b);i++)
#define FD(i,a,b) for(int i=(a);i>(b);i--)
#define LD long double
#define PI 3.1415926535897932384626
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define VLL vector<long long >
#define VVLL vector<vector<long long > >
#define VPLL vector<pair<long long, long long>>
#define VVPLL vector<vector<pair<long long, long long>>>
#define VD vector<double>
#define VVD vector<vector<double> >
#define VPD vector<pair<double,double> >
#define MP make_pair
#define PB push_back
#define FI first
#define SE second
#define SORT(v) std::sort(v.begin(),v.end())
#define GSORT(v,T) sort(v.begin(),v.end(),greater<T>)
#define UNIQUE(v) decltype(v.begin()) it = unique(v.begin(),v.end()); v.resize(distance(v.begin(),it))
using namespace std;
LL inp, Inp; LL i1, i2, i3, i4, i5, i6, i7, i8;
LL MOD = 998244353, MOD1 = (LL)1e9 + 7, MOD2 = (LL)1e9 + 9; long long MOD3 = (long long)1e9 + 21 /*33*/;  double eps = 1e-9;
LL TMP = (chrono::high_resolution_clock::now().time_since_epoch().count() % MOD + MOD) % MOD;
auto STTMP = chrono::steady_clock::now();//auto ENTMP = chrono::steady_clock::now();
//ELTIME = double(chrono::duration_cast<chrono::milliseconds>(ENTMP - STTMP).count());
//time_t result = time(NULL); char SS[26]; ctime_s(SS, sizeof SS, &result);
//transform(SS, SS + 26, SS, [](char ch) {return ch == ' ' ? '_' : ch; }); printf("%s", SS);;
vector<vector<int>> G;
vector<int> vis, minD, maxN, neis;

int main() {
    ios_base::sync_with_stdio(0);
    std::cin.tie(0);
    std::cout.precision(20);
    srand((unsigned int)TMP);
    int N, K; cin >> N >> K;
    G.resize(N, vector<int>());
    for (int i = 0; i < N - 1; i++){
        cin >> i1 >> i2; i1--, i2--;
        G.at(i1).push_back(i2);
        G.at(i2).push_back(i1);
    }

    int low = 1, up = N;
    while (low < up) {
        int mid = (low + up) / 2;
        int use = 0;
        LL vcnt = 0;
        vis.assign(N, 0);
        minD.assign(N, 1e9);
        maxN.assign(N, -1e9);
        neis.assign(N, 0);
        for (int i = 0; i < N; i++) {
            neis.at(i) = G.at(i).size();
        }
        queue<int> leafs;
        for (int i = 0; i < N; i++) {
            if (neis.at(i) <= 1) {
                leafs.push(i);
                neis.at(i)++;
                maxN.at(i) = 0;
            }
        }
        while (!leafs.empty()) {
            int leaf = leafs.front(); leafs.pop();
            neis.at(leaf)--;
            if (!vis.at(leaf) && neis.at(leaf) <= 1) { // leaf
                vis.at(leaf) = 1; vcnt++;
                if (maxN.at(leaf) + minD.at(leaf) <= mid) {
                    maxN.at(leaf) = minD.at(leaf) - mid - 1;
                }
                else if(maxN.at(leaf) >= mid || vcnt == N){
                    minD.at(leaf) = 0, maxN.at(leaf) = -mid - 1; use++;
                }
                for (auto nei : G.at(leaf)) {
                    minD.at(nei) = min(minD.at(nei), minD.at(leaf) + 1);
                    maxN.at(nei) = max(maxN.at(nei), maxN.at(leaf) + 1);
                    leafs.push(nei);
                }
            }
        }
        if (use > K) {
            low = mid + 1;
        }
        else {
            up = mid;
        }
    }
    cout << low << "\n";

    return 0;
}

/**
*    author:  Dooloper
*    created: 11.10.2020 23:12:53
**/

#pragma region Macros
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
using P = pair<int,int>;
using ll = long long;

#define rep(i,n) for(int i = 0; i < (n); i++)
#define repn(i,n) for(int i = 1; i <= (n); i++)
#define pb push_back
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

const double PI = acos(-1);
const int mod = 1000000007;
class mint {
   long long x;
public:
   mint(long long x=0) : x((x%mod+mod)%mod) {}
   mint operator-() const {
     return mint(-x);
   }
   mint& operator+=(const mint& a) {
       if ((x += a.x) >= mod) x -= mod;
       return *this;
   }
   mint& operator-=(const mint& a) {
       if ((x += mod-a.x) >= mod) x -= mod;
       return *this;
   }
   mint& operator*=(const  mint& a) {
       (x *= a.x) %= mod;
       return *this;
   }
   mint operator+(const mint& a) const {
       mint res(*this);
       return res+=a;
   }
   mint operator-(const mint& a) const {
       mint res(*this);
       return res-=a;
   }
   mint operator*(const mint& a) const {
       mint res(*this);
       return res*=a;
   }
   mint pow(ll t) const {
       if (!t) return 1;
       mint a = pow(t>>1);
       a *= a;
       return a;
   }
   // for prime mod
   mint inv() const {
       return pow(mod-2);
   }
   mint& operator/=(const mint& a) {
       return (*this) *= a.inv();
   }
   mint operator/(const mint& a) const {
       mint res(*this);
       return res/=a;
   }

   friend ostream& operator<<(ostream& os, const mint& m){
       os << m.x;
       return os;
   }
};
#pragma endregion

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n,m;
  cin >> n >> m;
  vector<int> w(n);
  vector<int> sums(1 << n), mn(1 << n);
  rep(i,n) cin >> w[i];
  int mx = *max_element(w.begin(),w.end());
  for(int s = 0; s < (1 << n); ++s){
    int x = 0;
    for(int i = 0; i < n; ++i) if(s >> i & 1) x+= w[i];
    sums[s] = x;
  }
  for(int i = 0; i < m; ++i){
    int l,v;
    cin >> l >> v;
    if(v < mx){
      cout << -1 << "\n";
      return 0;
    }
    for(int s = 0; s < (1 << n); ++s) if(sums[s] > v) mn[s] = max(mn[s],l);
  }
  int ans = 1e9;
  vector<int> perm(n);
  iota(perm.begin(), perm.end(), 0);
  do{
    vector<int> pos(n);
    for(int i = 1; i < n; ++i){
      int s = 1 << perm[i];
      for(int j = i-1; j >= 0; --j){
        s |= 1 << perm[j];
        pos[i] = max(pos[i], pos[j] + mn[s]);
      }
    }
    ans = min(ans, pos[n-1]);
  }while(next_permutation(perm.begin(), perm.end()));
  cout << ans << "\n";
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main() {
    ll b, c;
    cin >> b >> c;
    ll result = 0;
    if (c == 1) {
        if (b == 0) {
            cout << 1 << endl;
        } else {
            cout << 2 << endl;
        }
        return 0;
    }
    if (b > 0) {
        result = b + (c - 2) / 2 - max(1ll, b - c / 2) + 1;
        result += min(-1ll, - b + (c - 1) / 2) + b + (c - 1) / 2 + 1;
        if (b <= c / 2) {
            result++;
        }
    } else if (b < 0) {
        result = -b + (c - 1) / 2 - max(1ll, -b - (c - 1) / 2) + 1;
        result += min(-1ll, b + (c - 2) / 2) - b + c / 2 + 1;
        if (-b <= (c-1) / 2) {
            result++;
        }
    } else {
        result = (c - 1) / 2 + c / 2 + 1;
    }
    cout << result << endl;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll mod=1e9+7;
#define rep(i,n) for (int i = 0; i < (n); i++)
ll b,c,ans;
int main(){
    cin >> b >> c;
    ll k=c/2;
    if(c==1){
        if(b==0)ans=1;
        else ans=2;
    }
    else if(c%2==1) ans=(k*4+1)-max(0LL,min(b+k-1,k-b)-max(-b-k,b-k)+1);
    else ans=(k*4-1)-max(0LL,min(b+k-1,k-b-1)-max(-b-k+1,b-k)+1);
    cout << ans << endl;
    return 0;

}


#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

template<int64_t MOD> struct Mint {
  int64_t v;
  Mint() { v = 0; }
  Mint(int64_t x) { v = x % MOD; if(v < 0) v += MOD; }

  Mint operator-() { return Mint(-v); };
  Mint operator+(Mint x) { return Mint(v + x.v); };
  Mint operator-(Mint x) { return Mint(v - x.v); };
  Mint operator*(Mint x) { return Mint(v * x.v); };
  Mint operator/(Mint x) { return Mint(v * pow(x.v, MOD-2).v); };

  Mint& operator+=(Mint x) { return *this = (*this + x); };
  Mint& operator-=(Mint x) { return *this = (*this - x); };
  Mint& operator*=(Mint x) { return *this = (*this * x); };
  Mint& operator/=(Mint x) { return *this = (*this / x); };

  static Mint pow(Mint base, int64_t exp) {
    if(exp == 0) return Mint(1);
    return pow(base*base, exp/2) * (exp&1 ? base : Mint(1));
  }

  friend ostream& operator<<(ostream& os, Mint x) { return os << x.v; }
};
using mint = Mint<1000000007>;

template<typename T> vector<T> tensor(int n, T v){ return vector<T>(n, v); }
template<typename... Ts> auto tensor(int n, Ts... ts) {
  return vector<decltype(tensor(ts...))>(n, tensor(ts...));
}

int main() {
  lint h, w;
  cin >> h >> w;
  auto S = tensor(h+2, w+2, '#');
  for(lint i=1; i<=h; i++)
  for(lint j=1; j<=w; j++) {
    cin >> S[i][j];
  }

  auto dp = tensor(h+2, w+2, 4, 1);
  for(lint i=1; i<=h; i++)
  for(lint j=1; j<=w; j++) {
    if(S[i][j] == '.') {
      dp[i][j+1][0] = dp[i][j][0] + 1;
      dp[i+1][j][1] = dp[i][j][1] + 1;
    } else {
      dp[i][j][0] = dp[i][j][1] = 0;
    }
  }

  for(lint i=h; i>=1; i--)
  for(lint j=w; j>=1; j--) {
    if(S[i][j] == '.') {
      dp[i][j-1][2] = dp[i][j][2] + 1;
      dp[i-1][j][3] = dp[i][j][3] + 1;
    } else {
      dp[i][j][2] = dp[i][j][3] = 0;
    }
  }

  lint dot = 0;
  for(lint i=1; i<=h; i++)
  for(lint j=1; j<=w; j++) {
    dot += S[i][j] == '.';
  }

  mint ans = 0;
  for(lint i=1; i<=h; i++)
  for(lint j=1; j<=w; j++) {
    lint count = 0;
    for(lint k=0; k<4; k++) count += dp[i][j][k];
    count = max(count-3, 0LL);
    ans += mint::pow(2, dot) - mint::pow(2, dot-count);
  }
  cout << ans << endl;
}

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

const int MOD=1e9+7;
int D[2010][2010];
int E[2010][2010];

ll modpow(ll x,ll n){
  ll ans=1;
  while(n){
    if(n&1) ans=ans*x %MOD;
    x=x*x %MOD;
    n/=2;
  }
  return ans;
}

int a;
int f(int i,int j){
  return ((modpow(2,D[i][j])-1+MOD)%MOD)*modpow(2,a-D[i][j])%MOD;
}

int main(){
  int h,w;
  cin>>h>>w;

  vector<string> A(h);
  rep(i,h) cin>>A[i];

  int cnt=0;
  rep(i,h){
    rep(j,w){
      if(A[i][j]=='#'){
        D[i][j]=0;
        cnt++;
      }
      else{
        if(j==0) D[i][j]=1;
        else D[i][j]=D[i][j-1]+1;
      }
    }
  }
  rep(i,h){
    for(int j=max(w-2,0);j>=0;j--){
      if(D[i][j]==0) continue;
      if(D[i][j]<D[i][j+1]) D[i][j]=D[i][j+1];
    }
  }

  rep(j,w){
    rep(i,h){
      if(A[i][j]=='#') E[i][j]=0;
      else{
        if(i==0) E[i][j]=1;
        else E[i][j]=E[i-1][j]+1;
      }
    }
  }
  rep(j,w){
    for(int i=max(h-2,0);i>=0;i--){
      if(E[i][j]==0) continue;
      if(E[i][j]<E[i+1][j]) E[i][j]=E[i+1][j];
    }
  }

  rep(i,h){
    rep(j,w){
      D[i][j]=max(D[i][j]+E[i][j]-1,0);
    }
  }

  a=h*w-cnt;
  ll ans=0;
  rep(i,h){
    rep(j,w){
      ans=(ans+f(i,j))%MOD;
    }
  }
  cout<<ans<<endl;

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=998244353;
int n,m,ans;
int Power(int x,int y){
	int ret=1;
	while(y) {
		if(y&1)ret=1ll*ret*x%mod;
		x=1ll*x*x%mod,y>>=1;
	}
	return ret;
}
int main(){
	cin>>n>>m;
	int w1=Power(m*m,mod-2);
	int w2=Power(m,mod-2);
	for(int i=2,l=Power(m,n);i<=n;i++){
		for(int j=1;j<=m;j++){
			int p=1ll*w1*Power(1ll*(m-j)*w2%mod,i-2)%mod*(n-i+1)%mod;
			ans=(ans+1ll*p*l)%mod;
		}
	}
	cout<<(1ll*n*Power(m,n)%mod-ans+mod)%mod;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define N 200005
#define mod 998244353
int n,k,ans,a[N],sum[N][305],fac[N],inv[N];
int c(int n,int m){
	return 1LL*fac[n]*inv[m]%mod*inv[n-m]%mod;
}
int main(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=1;i<=n;i++){
		int ss=1;
		for(int j=0;j<=k;j++){
			sum[i][j]=(sum[i-1][j]+ss)%mod;
			ss=1LL*ss*a[i]%mod;
		}
	}
	fac[0]=inv[0]=inv[1]=1;
	for(int i=1;i<=k;i++)fac[i]=1LL*fac[i-1]*i%mod;
	for(int i=2;i<=k;i++)inv[i]=1LL*(mod-mod/i)*inv[mod%i]%mod;
	for(int i=2;i<=k;i++)inv[i]=1LL*inv[i-1]*inv[i]%mod;
	for(int i=1;i<=k;i++){
		ans=0;
		for(int j=0;j<=i;j++){
			ans=(ans+(1LL*sum[n][j]*sum[n][i-j]-sum[n][i]+mod)%mod*(mod+1)/2%mod*c(i,j))%mod;
		}
		printf("%d\n",ans);
	}
}


#include<bits/stdc++.h>
using namespace std;

const long long MOD = 1e9+7;
const long long N = 1e5+10;

typedef long long ll;
typedef long double ld;

void test_case()
{
	ld r, x, y;
	cin >> r >> x >> y;
	ld dis = sqrt(x * x + y * y);
	ld res = dis/r;
	ll ans = ceil(res);
	if(ans == 1 && ceil(res) != floor(res))
		ans++;
	cout << ans << '\n';
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int tc = 1;
    // cin >> tc;
    while(tc--)
       test_case();
    return 0;
}

#include <vector>
#include <cstdlib>
#include <math.h>
#include <algorithm>
#include <tuple>
#include <set>
#include <map>
#include <iostream>
#include <iomanip>
#include <limits>
using namespace std;
# define rep(i, n) for (long long i = 0; i < (long long)(n); i++)

int main() {
  long long r, x, y;
  cin >> r >> x >> y;
  long long answer = 0;

  long long d2 = (x * x) + (y * y);
  double d = sqrt(d2);

  if(fmod(d, r) == 0){
    answer = d / r;
  }else if(d < r * 2){
    answer = 2;
  }else{
    answer = ceil(d / r);
  }
  cout << answer << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
/* ループ処理 0からnまで*/
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main()
{
  double A, B;
  cin >> A >> B;
  cout << A / 100.0 * B << endl;
  return 0;
}

#include<bits/stdc++.h>
using namespace std;

int main() {
  int A, B;
  cin >> A >> B;
  cout << A * B / 100.0 << endl;
}


//Let's join Kaede Takagaki Fan Club !!
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//#define int long long
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define a first
#define b second
#define fi first
#define sc second
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define all(x) x.begin(),x.end()
#define si(x) int(x.size())

#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif

template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b;return true;}else return false;}
template<class t,class u> bool chmin(t&a,u b){if(b<a){a=b;return true;}else return false;}

template<class t> using vc=vector<t>;

template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
	return os<<"{"<<p.fi<<","<<p.sc<<"}";
}

template<class t> ostream& operator<<(ostream& os,const vc<t>& v){
	os<<"{";
	for(auto e:v)os<<e<<",";
	return os<<"}";
}

template<class T>
void g(T &a){
	cin >> a;
}
template<class T>
void o(const T &a,bool space=false){
	cout << a << (space?' ':'\n');
}
//ios::sync_with_stdio(false);
const ll mod = 1000000007;//998244353
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
template<class T>
void add(T&a,T b){
	a+=b;
	if(a >= mod) a-=mod;
}
ll modpow(ll x,ll n){
	ll res=1;
	while(n>0){
		if(n&1) res=res*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return res;
}
int pr[15]={2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47};
int v[55];
void solve(){
	int n; cin >> n;
	rep(i, n){
		int p; cin >> p;
		int mask = 0;
		rep(j,15){
			if(p%pr[j] == 0) mask|=(1<<j);
		}
		v[i] = mask;
	}
	ll ans = 1e18, tmp;
	rep(mask,(1<<15)){
		rep(i,n) if( (v[i] & mask) == 0 ) goto fail;
		tmp = 1;
		rep(i,15)if(((mask>>i)&1)) tmp=tmp*pr[i];
		chmin(ans,tmp);
		fail:;
	}
	o(ans);
}
signed main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);
	int t; t = 1; //cin >> t;
	while(t--) solve();
}

#include<bits/stdc++.h>
using namespace std;

void solve()
{
    int a,b;
    cin >> a >> b;
    int mx=0;
    for (int k=1; k<=b; k++)
    {
      int z = (a+k-1)/k;
      int first = z*k;
      int second = (z+1)*k;
      if (first>=a && second<=b) mx = k;
    }
    cout << mx;
}

int main()
{
int t=1;
//cin >> t;
while (t--) solve();
}


#include <iostream>

using namespace std;

int main(){
    int x, y;
    cin >> x >> y;
    switch(x+y){
        case 0: cout << 0 << endl; break;
        case 1: cout << 2 << endl; break;
        case 2: cout << 1 << endl; break;
        case 3: cout << 0 << endl; break;
        case 4: cout << 2 << endl; break;
    }
    return 0;
}

#include <bits/stdc++.h>
#include <string>
typedef long long int ll;
typedef long double ld;
using namespace std;
ll mod = 1e9 + 7;

int solve()
{
    return 0;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll x, y;
    cin >> x >> y;
    if (x == y)
        cout << x << endl;
    else if ((x == 0 && y == 1) || (x == 1 && y == 0))
        cout << 2 << endl;
    else if ((x == 1 && y == 2) || (x == 2 && y == 1))
        cout << 0 << endl;
    else if ((x == 0 && y == 2) || (x == 2 && y == 0))
        cout << 1 << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a,b,c,l,r;
int main(){
	cin>>a>>b>>c;
	c*=1000;
	l=c/b;
	if(c%b!=0)l++;
	r=c/a;
	if(r<l)puts("UNSATISFIABLE");
	else cout<<l<<" "<<r;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
#define MottoHayaku ios::sync_with_stdio(0);cin.tie(0);
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define F first
#define S second
#define pb push_back
const ll INF=2e18;

signed main()
{
    MottoHayaku
    ll a,b,c;
    cin>>a>>b>>c;
    c*=1000;
    ll mn=INF,mx=-1;
    rep1(i,1000000)
    {
        double tmp=c;
        double k=c/(double)i;
        if(k<=b&&k>=a) mn=min(mn,i),mx=max(mx,i);
    }
    if(mn==INF) cout<<"UNSATISFIABLE\n";
    else cout<<mn<<" "<<mx<<"\n";
}


#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <vector>
#include <map>
#include<cstdio>
#include<functional>
#include <bitset>
#include <iomanip>
#include <cctype>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define ll long long
using namespace std;
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
using vv = vector<vector<ll>>;
using vec = vector<ll>;
using P = pair<ll, ll>;

int main()
{
	ll n; cin >> n;
	map<ll, ll> mp;
	vec al(n);
	rep(i, n) {
		ll a; cin >> a;
		al[i] = a;
	}
	repi(i, 2, 1001) {
		rep(j, n) {
			if (al[j] >= i && al[j]%i == 0) {
				mp[i]++;
			}
		}
	}
	ll ans = 0;
	ll max = 0;
	for (auto item : mp) {
		if (item.second > max) {
			max = item.second;
			ans = item.first;
		}
	}
	cout << ans << endl;
	system("Pause");
}

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
#define LL long long
#define ld long double
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rnd(time(0));

long long powm(long long a, long long b,long long mod) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a %mod;
        a = a * a %mod;
        b >>= 1;
    }
    return res;
}

int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

signed main()
{

ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(0);

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
        freopen("INPUT.txt","r",stdin);
        freopen("OUTPUT.txt","w",stdout);
    }
#endif

    ld a,b;
    cin>>a>>b;
    b=a-b;
    ld ans=(b/a)*100;
    cout<<fixed<<setprecision(6)<<ans;

}


#include<bits/stdc++.h>
using namespace std;

//Replace each 0 with a 0,
//each 1 with a 1, each 6 with a 9, each 8 with an 8, and each 9 with a 6.

int main()
{
  string s;cin>>s;
  for(int i=s.length()-1;i>=0;i--)
  {if(s[i]=='6')
    s[i]='9';
   else if(s[i]=='9')
     s[i]='6';
   cout<<s[i];
  }
 // cout<<s;

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;
const ll INF = 1LL << 30;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
int main() {
  ll N;
  cin >> N;
  ll cut = 0, ans = 0;
  while(cut < N) {
    cut += ans+1;
    ans++;
  }
  cout << ans << endl;
}


#include <iostream>

using namespace std;

int main()
{
    char c[3];
    for(int i=0;i<3;i++)
    {
        cin>>c[i];
    }
    for(int i=0;i<2;i++)
    {
        if(c[i]!=c[i+1])
        {
            cout<<"Lost";
            return 0;
        }
    }
    cout<<"Won";
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

int a[2];

int main() {
    cin >> a[0] >> a[1];
    if (a[0] == a[1]) {
        cout << a[0] << endl;
    } else {
        for (int i = 0; i < 3; ++i) {
            bool flag = 1;
            for (int j = 0; j < 2; ++j) {
                if (a[j] == i) {
                    flag = 0;
                    break;
                }
            }
            if (flag) {
                cout << i << endl;
                break;
            }
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main(){
  int x;
  cin >> x;
  cout << max(0, x) << endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main() {
  int x;
  cin >> x;

  if (x < 0) {
    cout << 0 << endl;
  }
  else {
    cout << x << endl;
  }
}


#include<bits/stdc++.h>
using namespace std;
#define reg register
typedef long long ll;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
static char buf[1<<21],*p1=buf,*p2=buf;
#define flush() (fwrite(wbuf,1,wp1,stdout),wp1=0)
#define putchar(c) (wp1==wp2&&(flush(),0),wbuf[wp1++]=c)
static char wbuf[1<<21];int wp1;const int wp2=1<<21;
inline int read(void){
	reg char ch=getchar();
	reg int res=0;
	while(!isdigit(ch))ch=getchar();
	while(isdigit(ch))res=10*res+(ch^'0'),ch=getchar();
	return res;
}

inline void write(reg int x){
	static char buf[32];
	reg int p=-1;
	if(!x) putchar('0');
	else while(x) buf[++p]=(x%10)^'0',x/=10;
	while(~p) putchar(buf[p--]);
	return;
}

const int MAXN=500;

int n;
int p[MAXN];

int main(void){
	reg int t=read();
	while(t--){
		n=read();
		for(reg int i=0;i<n;++i)
			p[i]=read()-1;
		vector<int> ans;
		for(int i=0;i<n;++i){
			reg int j=find(p,p+n,i)-p;
			if(i!=j){
				if(!((j^ans.size())&1)){
					if(j>=i+2){
						ans.push_back(j-2);
						swap(p[j-2],p[j-1]);
					}
					else{
						ans.push_back(i-1),ans.push_back(i),ans.push_back(i-1),ans.push_back(i),ans.push_back(i-1);
						swap(p[i],p[j]);
						continue;
					}
				}
				for(int k=j-1;k>=i;--k){
					ans.push_back(k);
					swap(p[k],p[k+1]);
				}
			}
		}
		write(ans.size()),putchar('\n');
		if(ans.size())
			for(reg int i=0,siz=ans.size();i<siz;++i)
				write(ans[i]+1),putchar(i==siz-1?'\n':' ');
		else
			putchar('\n');
	}
	flush();
	return 0;
}

#include <algorithm>
#include <climits>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define REP(i, n) for(int i = 0; i < n; ++i)
using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

struct Vector
{
	LLONG x, y;

	Vector()
	{
		x = y = 0;
	}

	Vector(LLONG x, LLONG y) : x(x), y(y) {}

	const Vector operator+(const Vector& rhs) const
	{
		return { x + rhs.x, y + rhs.y };
	}
};

struct Matrix
{
	LLONG a, b, c, d;

	Matrix()
	{
		a = b = c = d = 0;
	}

	Matrix(LLONG a, LLONG b, LLONG c, LLONG d)
		: a(a), b(b), c(c), d(d) {}

	const Matrix operator*(const Matrix& rhs) const
	{
		return { a * rhs.a + b * rhs.c, a * rhs.b + b * rhs.d,
				 c * rhs.a + d * rhs.c, c * rhs.b + d * rhs.d };
	}

	const Vector operator*(const Vector& rhs) const
	{
		return { a * rhs.x + b * rhs.y, c * rhs.x + d * rhs.y };
	}
};

int main()
{
	int N; cin >> N;
	vector<Vector> xs(N);
	REP(i, N)
	{
		LLONG x, y; cin >> x >> y;
		xs[i] = Vector(x, y);
	}
	int M; cin >> M;
	vector<Matrix> ms(M + 1);
	ms[0] = Matrix(1, 0, 0, 1);
	vector<Vector> vs(M + 1);
	REP(i, M)
	{
		int op; cin >> op;
		if (op == 1)
		{
			ms[i + 1] = Matrix(0, 1, -1, 0) * ms[i];
			vs[i + 1] = Matrix(0, 1, -1, 0) * vs[i];
		}
		else if (op == 2) {
			ms[i + 1] = Matrix(0, -1, 1, 0) * ms[i];
			vs[i + 1] = Matrix(0, -1, 1, 0) * vs[i];
		}
		else if (op == 3)
		{
			LLONG p; cin >> p;
			ms[i + 1] = Matrix(-1, 0, 0, 1) * ms[i];
			vs[i + 1] = Matrix(-1, 0, 0, 1) * vs[i] + Vector(2 * p, 0);
		}
		else if(op == 4)
		{
			LLONG p; cin >> p;
			ms[i + 1] = Matrix(1, 0, 0, -1) * ms[i];
			vs[i + 1] = Matrix(1, 0, 0, -1) * vs[i] + Vector(0, 2 * p);
		}
	}
	int Q; cin >> Q;
	REP(i, Q)
	{
		int ai, bi; cin >> ai >> bi; --bi;
		const auto v = ms[ai] * xs[bi] + vs[ai];
		cout << v.x << ' ' << v.y << endl;
	}
}


#include <bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using V = vector<int>;

int main()
{
    int a, b;
    string ans;
    cin >> a >> b;
    ans = b % a == 0 ? "Yes" : "No";

    cout << ans << endl;
    return 0;
}

#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	ll b, c; cin >> b >> c;
	if (b == 0) {
		ll l1 = c >> 1;
		ll l2 = (c - 1) >> 1;
		cout << l2 + l1 + 1 << '\n';
	}
	else {
		if (c == 1) { cout << 2 << '\n'; }
		else if (c == 2) {
			set<ll> s = { b, b - 1, -b };
			cout << s.size() << '\n';
		}
		else {
			pair<ll, ll> p1(b - (c >> 1), b + ((c - 2) >> 1));
			pair<ll, ll> p2(-b -((c - 1) >> 1), -b + ((c - 1) >> 1));

			if (p1.first > p2.first) swap(p1, p2);
			ll l1 = p1.second - p1.first + 1;
			ll l2 = p2.second - p2.first + 1;
			ll l3 = max(0ll, p1.second - p2.first + 1);
			cout << l1 + l2 - l3 << '\n';
		}
	}
	cin.ignore(2); return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

template <typename T, typename F>
T binarySearch(T ok, T ng, F isOK, T bound = 1) {
    while (abs(ng - ok) > bound) {
        T m = (ng + ok) / 2;
        if (isOK(m))
            ok = m;
        else
            ng = m;
    }
    return ok;
}

void solve() {
    int N;
    cin >> N;
    // 等差数列の和　S = n(a + l) / 2
    auto fn = [&](int m) { return (m * (m + 1) / 2 <= N + 1); };
    cout << N - binarySearch(0LL, (int)2e9, fn) + 1 << endl;
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

const int MA = 200;

int main(void){
  int n; cin >> n;
  vector<ll> a(2*MA+1,0);
  rep(i,n){
    int tmp; cin >> tmp;
    a[MA+tmp]++;
  }

  ll ans = 0;
  for(int i = 0;i < 2*MA+1;i++){
    for(int j = 0;j < 2*MA+1;j++){
      ans += a[i]*a[j]*(i-j)*(i-j);
    }
  }
  ans /= 2;

  cout << ans << endl;

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

void fastStd()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
}

const int MOD = 1e9+7;

int n;
vector<int> arr;
vector<long long> minim;
vector<pair<long long, long long>> dp;
vector<pair<long long, long long>> dp2;

long long generate(bool plus, int index){
	if(index == n-1){
		if(plus){
			return dp[index].first;
		} else {
			return dp[index].second;
		}
	}
	if(plus){
		if(dp[index+1].first != -1 && dp[index+1].second != -1){
			dp[index].first = (dp[index+1].first + dp[index+1].second) % MOD;
		} else if(dp[index+1].first != -1) {
			dp[index].first = (dp[index+1].first + generate(false, index+1)) % MOD;
		} else if(dp[index+1].second != -1){
			dp[index].first = (generate(true, index+1) + dp[index+1].second) % MOD;
		} else {
			dp[index].first = (generate(true, index+1) + generate(false, index+1)) % MOD;
		}
		return dp[index].first % MOD;
	} else {
		if(dp[index+1].first != -1){
			dp[index].second = dp[index+1].first;
 		} else {
 			dp[index].second = generate(true, index+1);
 		}
 		return dp[index].second % MOD;
	}
}

long long generate2(bool plus, int index){
	if(index == 1){
		if(plus){
			return dp2[index].first;
		} else {
			return dp2[index].second;
		}
	}
	if(plus){
		if(dp2[index-1].first != -1 && dp2[index-1].second != -1){
			dp2[index].first = (dp2[index-1].first + dp2[index-1].second) % MOD;
		} else if(dp2[index-1].first != -1) {
			dp2[index].first = (dp2[index-1].first + generate2(false, index-1)) % MOD;
		} else if(dp2[index-1].second != -1){
			dp2[index].first = (generate2(true, index-1) + dp2[index-1].second) % MOD;
		} else {
			dp2[index].first = (generate2(true, index-1) + generate2(false, index-1)) % MOD;
		}
		return dp2[index].first % MOD;
	} else {
		if(dp2[index-1].first != -1){
			dp2[index].second = dp2[index-1].first;
 		} else {
 			dp2[index].second = generate2(true, index-1);
 		}
 		return dp2[index].second % MOD;
	}
}

int main()
{
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	scanf("%d", &n);
	arr.resize(n);
	long long sum = 0;
	for(int &x : arr){
		scanf("%d", &x);
		sum += x % MOD;
		sum %= MOD;
	}
	if(n == 1){
		printf("%d\n", arr[0]);
		return 0;
	}
	minim.resize(n);
	dp.resize(n, {-1, -1});
	dp[n-1] = {1,1};
	dp2.resize(n, {-1, -1});
	dp2[1] = {1, 1};
	long long x = generate(true, 1);
	x = generate(false, 1);
	x = generate2(true, n-1);
	x = generate2(false, n-1);
	long long ans = (sum * ((dp[1].first + dp[1].second) % MOD)) % MOD;
	// printf("%lld\n", ans);
	for(int i = 1; i < n; i++){
		minim[i] = ((dp[i].second % MOD) * (dp2[i].second % MOD)) % MOD;
		ans -= ((arr[i] * minim[i] % MOD) * 2) % MOD;
		ans = (ans + MOD) % MOD;
		// printf("%lld %lld %lld %lld\n", dp[i].first, dp[i].second, minim[i], ans);
	}
	printf("%lld\n", ans);

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T,class U>
inline bool chmax(T &a,U b){
    if(a<b){
        a=b;
        return true;
    }
    return false;
}
template<class T,class U>
inline bool chmin(T &a,U b){
    if(a>b){
        a=b;
        return true;
    }
    return false;
}
constexpr int INF=1000000000;
constexpr ll llINF=3000000000000000000;
constexpr int mod=998244353;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
/*
vector<vector<ll>>C,sC;
void init_comb(int n,int m){
    C.resize(n+1,vector<ll>(m+1,0));
    sC.resize(n+1,vector<ll>(m+1,0));
    C[0][0]=1;
    for(int i=1;i<=n;i++){
        C[i][0]=1;
        for(int j=1;j<=m;j++){
            C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
        }
    }
    rep(i,n+1){
        rep(j,m){
            sC[i][j+1]=(sC[i][j]+C[i][j])%mod;
        }
    }
}*/
ll gcd(ll a,ll b){
    while(a%b){
        a%=b;
        swap(a,b);
    }
    return b;
}
ll lcm(ll a,ll b){
    return a/gcd(a,b)*b;
}
bool isprime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
vector<int>primes;
void init_prime(int n){
	primes.push_back(2);
    for(int i=3;i<=n;i+=2){
        bool f=true;
        for(int j:primes){
            if(j*j>i)break;
            if(i%j==0){
                f=false;
                break;
            }
        }
        if(f)primes.push_back(i);
    }
}
ll modpow(ll a,ll b){
    ll res=1;
    while(b){
        if(b&1){
            res*=a;
            res%=mod;
        }
        a*=a;
        a%=mod;
        b>>=1;
    }
    return res;
}
vector<ll>inv,fact,factinv;
void init_fact(int n){
    inv.resize(n+1);
    fact.resize(n+1);
    factinv.resize(n+1);
    inv[0]=0;
    inv[1]=1;
    fact[0]=1;
    factinv[0]=1;
    for(ll i=1;i<=n;i++){
        if(i>=2)inv[i]=mod-((mod/i)*inv[mod%i]%mod);
        fact[i]=(fact[i-1]*i)%mod;
        factinv[i]=factinv[i-1]*inv[i]%mod;
    }
}
ll _inv(ll a,ll m=mod){
    //gcd(a,m) must be 1
    ll b=m,u=1,v=0;
    while(b){
        ll t=a/b;
        a-=t*b;swap(a,b);
        u-=t*v;swap(u,v);
    }
    u%=m;
    if(u<0)u+=m;
    return u;
}
ll comb(int a,int b){
    if(a<b)return 0;
    if(a<0)return 0;
    return fact[a]*factinv[a-b]%mod*factinv[b]%mod;
}
ll multicomb(int a,int b){
    return comb(a+b-1,b);
}
void solve(){
    int n,a[20];
    cin>>n;
    rep(i,n)cin>>a[i];
    int ans=(1<<30);
    rep(s,1<<(n-1)){
        int X=0,O=a[0];
        rep(i,n-1){
            if((s>>i)&1){
                O|=a[i+1];
            }
            else{
                X^=O;
                O=a[i+1];
            }
        }
        X^=O;
        chmin(ans,X);
    }
    cout<<ans<<endl;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    //int t;cin>>t;while(t--)
    solve();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define rrepa(i,a,n) for(int i=n;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

int main(){

    int h,w;
    cin>>h>>w;
    int sum=0,tmp,mi=100;
    rep(i,h)rep(j,w){
        cin>>tmp;
        sum+=tmp;
        cmin(mi,tmp);
    }

    cout<<sum-(mi*h*w);

    return 0;

}

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <bitset>
#include <complex>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <cassert>
#include <functional>

using ll = long long;
using namespace std;

template<typename A, typename B>
bool chmin(A &a, const B b) {
  if (a <= b) return false;
  a = b;
  return true;
}

template<typename A, typename B>
bool chmax(A &a, const B b) {
  if (a >= b) return false;
  a = b;
  return true;
}

#ifndef LOCAL
#define debug(...) ;
#else
#define debug(...) cerr << __LINE__ << " : " << #__VA_ARGS__ << " = " << _tostr(__VA_ARGS__) << endl;

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v);

template<typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}

void _tostr_rec(ostringstream &oss) {
  oss << "\b\b \b";
}

template<typename Head, typename... Tail>
void _tostr_rec(ostringstream &oss, Head &&head, Tail &&...tail) {
  oss << head << ", ";
  _tostr_rec(oss, forward<Tail>(tail)...);
}

template<typename... T>
string _tostr(T &&...args) {
  ostringstream oss;
  int size = sizeof...(args);
  if (size > 1) oss << "{";
  _tostr_rec(oss, forward<T>(args)...);
  if (size > 1) oss << "}";
  return oss.str();
}
#endif

constexpr int mod = 1'000'000'007; //1e9+7(prime number)
constexpr int INF = 1'000'000'000; //1e9
constexpr ll LLINF = 2'000'000'000'000'000'000LL; //2e18
constexpr int SIZE = 200010;

ll power(ll k, ll n, int M) {
  ll res = 1;
  for (; n; n /= 2) {
    if (n & 1) res = res * k % M;
    k = k * k % M;
  }
  return res;
}

int main() {
  int N, P;

  cin >> N >> P;

  ll ans = (ll)(P - 1) * power(P - 2, N - 1, mod);

  cout << ans % mod << endl;

  return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <cassert>

using namespace std;

vector<int> opos(const string& s) {
    int n = s.length();
    vector<int> ps;
    for (int i = 0; i < n; ++i) {
        if (s[i] == '1') ps.push_back(i);
    }
    return ps;
}

void solve() {
    int n;
    string s, t;
    cin >> n >> s >> t;

    if (count(s.begin(), s.end(), '0') !=
        count(t.begin(), t.end(), '0')) {
        cout << "-1\n";
        return;
    }

    int ans = 0;
    for (int q = 0; q < 2; ++q) {
        auto sps = opos(s), tps = opos(t);
        int m = sps.size();

        int p = 0;
        for (int i = 0; i < m; ++i) {
            auto& si = sps[i];
            auto ti = tps[i];

            si = max(si, p);
            if (si < ti) {
                ans += ti - si;
                si = ti;
            }
            p = si + 1;
        }

        reverse(s.begin(), s.end());
        reverse(t.begin(), t.end());
    }

    cout << ans << "\n";
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    solve();

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < ll(n); i++)
#define REPD(i, n) for(ll i = n-1; i >= 0; i--)
#define FOR(i, a, b) for(ll i = a; i < ll(b); i++)
#define FORD(i, a, b) for(ll i = a; i > ll(b); i--)
#define START ios::sync_with_stdio(false);cin.tie(0);

int main() {
  START
  int N;
  cin >> N;

  if (N % 2 == 0) cout << "White" << endl;
  else cout << "Black" << endl;
}

#include <bits/stdc++.h>
using namespace std;

int main(){
    int x;
    cin>>x;
    if(x>=0){
        cout<<x;
    }
    else{
        cout<<0;
    }
}


#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
*/
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define rrep(i,a,b) for(ll i=a;i>=b;--i)
#define FOR(i,n)  for(ll i=0;i<n;i++)
#define pb push_back
#define mp make_pair
#define PI 3.14159265358979323846
#define fi first
#define se second
#define all(x)  x.begin(),x.end()
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

const ll INF = 1e18+7;
const ll mod = 998244353;
const ll MAXN = 2e6+100;

ll poww(ll a, ll b) {
    if(b<0) return 0LL;
    ll ans = 1;
    while (b) {
        if (b & 1)ans = ans * a;
        a = a * a;
        b >>= 1;
    }
    return ans;
}
ll binpow(ll a, ll b)
{
    if (b < 0) return 0LL;
    if (a <= 0)return 0LL;
    a %= mod;

    ll ans = 1LL;
    while (b) {
        if (b & 1)ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans;
}
ll modinv(ll n) {
    return binpow(n, mod - 2);
}

vector<pair<ll,ll>> func(vector<ll> a, vector<ll> b) {
    vector<ll> x((ll)(b.size()),INF);
    ll i=0,j=0;
    while(i<(ll)a.size() && j<(ll)b.size()) {
        x[j] = min(x[j],abs(a[i]-b[j]));
        if(a[i]<=b[j]) i++;
        else j++;
    }
    vector<pair<ll,ll>> temp;
    FOR(i,(ll)(x.size())) {
        temp.pb(mp(x[i],i));
    }
    sort(all(temp));
    return temp;
}

void solve() {
    ll n; cin>>n;
    vector<ll> r,g,b;
    FOR(i,2*n) {
        ll a; char c; cin>>a>>c;
        if(c=='R') r.pb(a);
        if(c=='G') g.pb(a);
        if(c=='B') b.pb(a);
    }
    ll sr = r.size(), sb = b.size(), sg = g.size();

    sort(all(r)); sort(all(g)); sort(all(b));
    if(sr%2==0 && sb%2==0 && sg%2==0) {
        cout<<0;
    }
    else {
        if(sr%2 && sb%2) {
            vector<pair<ll,ll>> t = func(r,b);
            ll mn = t[0].fi;
            if(sg > 0) {
                vector<pair<ll,ll>> t1,t2;
                t1 = func(r,g); t2 = func(b,g);
                if(t1[0].se!=t2[0].se) {
                    mn = min(mn,t1[0].fi+t2[0].fi);
                }
                else {
                    mn = min(mn,min(t1[1].fi + t2[0].fi, t1[0].fi + t2[1].fi));
                }
            }
            cout<<mn;
        }
        else if(sr%2 && sg%2) {

            vector<pair<ll,ll>> t = func(r,g);
            ll mn = t[0].fi;
            if(sb > 0) {
                vector<pair<ll,ll>> t1,t2;
                t1 = func(r,b); t2 = func(g,b);
                if(t1[0].se!=t2[0].se) {
                    mn = min(mn,t1[0].fi+t2[0].fi);
                }
                else {
                    mn = min(mn,min(t1[1].fi + t2[0].fi, t1[0].fi + t2[1].fi));
                }
            }
            cout<<mn;
        }
        else {
            vector<pair<ll,ll>> t = func(g,b);
            ll mn = t[0].fi;
            if(sr > 0) {
                vector<pair<ll,ll>> t1,t2;
                t1 = func(g,r); t2 = func(b,r);
                if(t1[0].se!=t2[0].se) {
                    mn = min(mn,t1[0].fi+t2[0].fi);
                }
                else {
                    mn = min(mn,min(t1[1].fi + t2[0].fi, t1[0].fi + t2[1].fi));
                }
            }
            cout<<mn;
        }
    }
}

int main() {
    IOS;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    //ll no_of_test_cases; cin>>no_of_test_cases;
    ll no_of_test_cases = 1;
    //cout<<fixed<<setprecision(10);

    for(ll i=1; i<=no_of_test_cases; i++) {
        solve();
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

// clang-format off
#define rep(i, n) for ( int i = 0; i < (int)(n); i += 1)
#define rrep(i, n) for ( int i = (n) - 1; i >= 0; i -= 1)
#define range(i, l, r) for ( int i = (int)(l); i < (int)(r); (i) += 1 )
#define rrange(i, l, r) for ( int i = (int)(r)-1; i >= (int)(l); (i) -= 1 )
#define debug(x) cerr << #x << ": " << (x) << endl;
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << p.first << ' ' << p.second; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &v) { for ( pair<T1, T2> x : v ) { os << x << "\n"; } return os; }
template <typename T> ostream &operator<<(ostream &os, queue<T> v) { if(!v.empty()) { os << v.front(); v.pop(); } while (!v.empty()) { os << " " << v.front(); v.pop(); } return os; }
template <typename T> ostream &operator<<(ostream &os, stack<T> v) { if(!v.empty()) { os << v.top(); v.pop(); } while (!v.empty()) { os << " " << v.top(); v.pop(); } return os; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { bool is_f = true; for ( T x : v ) { os << (is_f ? "" : " ") << x; is_f = false; } return os; }
template <typename T> ostream &operator<<(ostream &os, const deque<T> &v) { bool is_f = true; for ( T x : v ) { os << (is_f ? "" : " ") << x; is_f = false; } return os; }
template <typename T> ostream &operator<<(ostream &os, const set<T> &v) { bool is_f = true; for ( T x : v ) { os << (is_f ? "" : " ") << x; is_f = false; } return os; }
using ull = unsigned long long;
using ll = long long;
using Pll = pair<ll, ll>;
using P = pair<int, int>;
constexpr ll INF64 = INT64_MAX / 2;
constexpr int INF32 = INT32_MAX / 2;
constexpr int dy[] = { 0, -1, 1, 0, -1, 1, -1, 1 };
constexpr int dx[] = { -1, 0, 0, 1, -1, -1, 1, 1 };
constexpr int mod998244353 = 998244353;
constexpr int mod1000000007 = (int)1e9 + 7;
constexpr char newl = '\n';
// clang-format on

int main() {
  int n;
  string s;
  cin>>n>>s;
  vector<int> a(n+1);
  for(auto &A:a) cin>>A;

  ll k=INF64;
  rep(i,n) chmin(k,abs(a[i]-a[i+1]));

  vector<vector<int>> ans(k,vector<int>(n+1));
  rep(j,n+1){
    int rem=a[j]%k;
    rep(i,k){
      ans[i][j]=a[j]/k;
      if(i<rem) ans[i][j]++;
    }
  }

  cout<<k<<endl;
  rep(i,k){
    cout<<ans[i]<<newl;
  }
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// --------------------------------------------------------
template<class T> bool chmax(T& a, const T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T b) { if (b < a) { a = b; return 1; } return 0; }
#define FOR(i,l,r) for (ll i = (l); i < (r); ++i)
#define RFOR(i,l,r) for (ll i = (r)-1; (l) <= i; --i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define MIN(c) *min_element(ALL(c))
#define MAX(c) *max_element(ALL(c))
#define SUMLL(c) accumulate(ALL(c), 0LL)
#define SZ(c) ((ll)(c).size())
#define BIT(b,i) ((b>>i) & 1)
#define PCNT(b) __builtin_popcountll(b)
#define CIN(c) cin >> (c)
#define COUT(c) cout << (c) << '\n'
#define debug(x) cerr << "l." << __LINE__ << " : " << #x << " = " << (x) << '\n'
ll llceil(ll a, ll b) { return (a + b - 1) / b; }
string toupper(const string& S) { string T(S); REP(i,SZ(T)) T[i] = toupper(T[i]); return T; }
string tolower(const string& S) { string T(S); REP(i,SZ(T)) T[i] = tolower(T[i]); return T; }
using P = pair<ll,ll>;
using VP = vector<P>;
using VVP = vector<VP>;
using VS = vector<string>;
using VVS = vector<VS>;
using VLL = vector<ll>;
using VVLL = vector<VLL>;
using VVVLL = vector<VVLL>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VVVB = vector<VVB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VVVD = vector<VVD>;
static const double EPS = 1e-10;
static const double PI  = acos(-1.0);
static const ll MOD = 1000000007;
// static const ll MOD = 998244353;
static const ll INF = (1LL << 62) - 1;  // 4611686018427387904 - 1
// --------------------------------------------------------
// #include <atcoder/all>
// using namespace atcoder;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    ll B, C; cin >> B >> C;

    if (C == 0) { COUT(1); return 0; }

    ll ans = 1;  // B or -B
    if (B == 0) {
        // 0 --> INF
        ans += (C-2) / 2;
        // 0 --> -INF
        ans += C / 2;
    } else if (B > 0) {
        ans++;  // -B
        // B --> 0
        ans += min(C/2, B);
        // B --> INF
        ans += (C-2) / 2;
        // B ---> -1
        ans += min((C-1)/2, B-1);
        // B --> -INF
        ans += (C-1) / 2;
    } else {
        ans++;  // B
        // -B --> 0
        ans += min((C-1)/2, -B);
        // -B --> INF
        ans += (C-1) / 2;
        // -B ---> -1
        ans += min((C-1)/2, -B-1);
        // -B --> -INF
        ans += C / 2;
    }
    COUT(ans);

    return 0;
}


#include "bits/stdc++.h"
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vll=vector<ll>;
using vvll=vector<vll>;
using pii=pair<int,int>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sor(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define pb push_back
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
//const int INF = 1123456789;
//const int mod = 1e9+7;
const int mod=998244353;

ll kaijo[105];
void cal(){
    ll res=1;
    for(int i=1;i<105;i++){
        (res*=i)%=mod;
        kaijo[i]=res;
    }
}
int main(){
    cal();
    int n; cin>>n;
    ll sum=0;
    vll w(n); rep(i,n) {cin>>w[i]; sum+=w[i];}
    if(sum%2){cout<<0<<endl; return 0;}
    vector<vvll> dp(n+1,vvll(10001,vll(n+1)));
    dp[0][0][0]=1;
    rep(i,n){
        rep(j,10001)rep(k,n){
            (dp[i+1][j][k]+=dp[i][j][k])%=mod;
            if(j+w[i]<=10000)(dp[i+1][j+w[i]][k+1]+=dp[i][j][k])%=mod;
        }
    }
    sum/=2;
    ll ans=0;
    rep(i,n+1){
        (ans+=dp[n][sum][i]*kaijo[i]%mod*kaijo[n-i])%=mod;
    }
    cout<<ans<<endl;
}

#include <bits/stdc++.h>
#include <string>
#include <cmath>
#include <sstream>
#include <unordered_map>
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for(ll i = (a-1); i >= (b); i--)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define spre cout<<fixed<<setprecision(15);
typedef long long int ll;
using namespace std;
//ll mod=67280421310721;
ll mod=998244353;
ll INF=1e9;
ll po(ll a,ll b)
{
	ll re=1;
	while(b)
	{
		if(b%2==1)
		{
			re=(re*a);
			re%=mod;
		}
		a=(a*a);
		a%=mod;
		b>>=1;
	}
	return re;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	#ifndef ONLINE_JUDGE
	freopen("INPUT.txt", "r", stdin);
	freopen("OUTPUT.txt", "w", stdout);
	#endif
	int test=1;
	// cin>>test;
	while(test--)
	{
		ll n;
		cin>>n;
		vector<ll> ans;
		for(ll i=1;i*i<=n;i++)
		{
			if((n%i)==0)
			{
				ans.pb(i);
				if((i*i)!=n)
				{
					ans.pb(n/i);
				}
			}
		}
		sort(ans.begin(),ans.end());
		FOR(i,0,ans.size())
		cout<<ans[i]<<'\n';
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //int:2*10**9
typedef long double ld;
typedef pair<ll,ll> P;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define vec2(name,i,j,k) vector<vector<ll>> name(i,vector<ll>(j,k))
#define vec3(name,i,j,k,l) vector<vector<vector<ll>>> name(i,vector<vector<ll>>(j,vector<ll>(k,l)))
#define pb push_back
#define MOD 1000000007 //998244353
#define PI 3.141592653
#define INF 100000000000000 //14
//cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);

ll powe(ll a, ll b){//aのb乗のmod
  ll ret = 1;
  while(0 < b){
    if((b%2) == 0){
      a = (a*a);
      b >>= 1;
    }
    else{
      ret = (ret*a);
      b--;
    }
  }
  return ret;
}

int main(){
  vector<vector<string>> ansl(9);
  FOR(i,1,8){
    string d = "";
    REP(j,(1ll<<i-1)) d+="AB";
    ansl[i].pb(d);
  }
  FOR(i,1,7){
    REP(j,ansl[i].size()){
      string v = ansl[i][j];
      string w = "";
      string x = "";
      REP(k,v.length()){
        if (v[k]=='A') {
          w+="AA";
          x+="AB";
        }
        else {
          w+="BB";
          x+="BA";
        }
      }
      ansl[i+1].pb(w);
      ansl[i+1].pb(x);
    }
  }
  ll n; cin >> n;
  cout << ansl[n].size() << endl;
  REP(i,ansl[n].size()) {
    cout << ansl[n][i] << endl;
  }
}

#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 4000000000000000000 //オーバーフローに注意
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int POW[10];
char table[260];

//最大公約数
ll gcd(ll x,ll y){

	x = abs(x);
	y = abs(y);

	if(x < y){
		swap(x,y);
	}
	if(y == 0){
		return x;
	}else{
		return gcd(y,x%y);
	}
}

//最小公倍数
ll lcm(ll x,ll y){

	return (x*y)/gcd(x,y);
}

int main(){

	POW[0] = 1;
	for(int i = 1; i < 10; i++){

		POW[i] = POW[i-1]*2;
	}

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

	if(N == 1){

		printf("1\n");
		printf("AB\n");
		return 0;
	}

	printf("%d\n",POW[N]-1);

	for(int i = 1; i <= POW[N]-1; i++){
		for(int k = 0; k < POW[N]; k++){
			int num = __builtin_popcount(i&k);
			if(num%2 == 0){

				printf("A");
			}else{

				printf("B");
			}
		}
		printf("\n");
	}

	return 0;
}


#include <stdlib.h>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <string>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;

int main(){
  string X;
  cin >> X;

  ll index=-1;
  for(ll i=0;i<X.size();++i){
    if(X[i]=='.'){
      X.erase(i);
      break;
    }
  }

  cout << X << endl;

  return 0;
}

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

int main() {
  string s;
  cin >> s;
  string t;
  for(int i = 1; i < s.size(); i++) t += s[i];
  t += s[0];
  cout << t << endl;
}


#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; debug_print(__VA_ARGS__); } while(false)
template<typename T, typename... Ts> void debug_print(const T &t, const Ts &...ts) { cerr << t; ((cerr << ", " << ts), ...); cerr << endl; }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, const T& b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, const T& b) { if (a < b) {a = b; return true; } return false; }
template<typename T, typename... Ts> void print(const T& t, const Ts&... ts) { cout << t; ((cout << ' ' << ts), ...); cout << '\n'; }
template<typename... Ts> void input(Ts&... ts) { (cin >> ... >> ts); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

template<ll MOD = 1000000007>
class ModInt {
    ll n;
    ModInt constexpr inverse() const {
        return ModInt::pow(*this, MOD - 2);
    }

public:
    ModInt() : n(0) {}
    ModInt(ll _n) : n(((_n % MOD) + MOD) % MOD) {}
    ModInt operator+=(const ModInt &m) {
        n += m.n;
        if (n >= MOD) n -= MOD;
        return *this;
    }
    ModInt operator-=(const ModInt &m) {
        n -= m.n;
        if (n < 0) n += MOD;
        return *this;
    }
    ModInt operator*=(const ModInt &m) {
        n *= m.n;
        if (n >= MOD) n %= MOD;
        return *this;
    }
    ModInt operator/=(const ModInt &m) {
        (*this) *= m.inverse();
        return *this;
    }
    friend ModInt operator+(ModInt t, const ModInt &m) {
        return t += m;
    }
    friend ModInt operator-(ModInt t, const ModInt &m) {
        return t -= m;
    }
    friend ModInt operator*(ModInt t, const ModInt &m) {
        return t *= m;
    }
    friend ModInt operator/(ModInt t, const ModInt &m) {
        return t /= m;
    }
    ModInt operator=(const ll l) {
        n = l % MOD;
        if (n < 0) n += MOD;
        return *this;
    }
    friend ostream &operator<<(ostream &out, const ModInt &m) {
        out << m.n;
        return out;
    }
    friend istream &operator>>(istream &in, ModInt &m) {
        ll l;
        in >> l;
        m = l;
        return in;
    }
    static constexpr ModInt pow(const ModInt x, ll p) {
        ModInt<MOD> ans = 1;
        for (ModInt<MOD> m = x; p > 0; p /= 2, m *= m) {
            if (p % 2) ans *= m;
        }
        return ans;
    }
    static constexpr ll mod() {
        return MOD;
    }
};
using mint = ModInt<>;
mint operator"" _m(unsigned long long m) {
    return mint(m);
}

const int maxn = 3010;
mint dp[maxn][maxn];
mint mp[maxn][maxn];

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin, n;
    vector<ll> a(n);
    rep(i, 0, n) {
        cin, a[i];
    }
    dp[0][0] = 1;
    mint ans = 0;
    vector<ll> sum(n + 1, 0);
    rep(i, 0, n) {
        sum[i + 1] = sum[i] + a[i];
        rep(j, 0, n) {
            mp[j][sum[i] % (j + 1)] += dp[i][j];
        }
        rep(j, 0, n) {
            dp[i + 1][j + 1] += mp[j][sum[i + 1] % (j + 1)];
            /*
            rep(k, 0, i + 1) {
                if (sum[i + 1] % (j + 1) == sum[k] % (j + 1)) {
                    dp[i + 1][j + 1] += dp[k][j];
                }
            }
            //*/
        }
    }
    rep(i, 0, n + 1) {
        ans += dp[n][i];
    }
    print(ans);
    return 0;
}

#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

const long long P = 1e9 + 7;
const double EPS = 1e-9;

using namespace std;

void solve() {
  int n;
  cin >> n;
  vector<long long> v(n);
  for (int i = 0; i < n; i++)
    cin >> v[i];

  vector<vector<long long>> dp(n, vector<long long>(n + 1));
  // dp[i][j]: num ways for v[0..i] with j segments
  // dp[i][j] = r[SUM(v[0..i]) % j]
  for (int i = 0; i < n; i++)
    dp[i][1] = 1;
  for (int k = 2; k <= n; k++) {
    long long s = 0;
    vector<long long> ct(k, 0);
    for (int i = 0; i < n; i++) {
      s = (s + v[i]) % k;
      dp[i][k] = ct[s];
      ct[s] = (ct[s] + dp[i][k - 1]) % P;
    }
  }
  long long res = 0;
  for (int k = 1; k <= n; k++)
    res = (res + dp[n - 1][k]) % P;
  cout << res << '\n';
}

/*
  YOU CAN DO THIS!! ;)
  1. Note the limits!
  2. Give logical, short variable names
  3. If you are stuck for a long time, skip to next problem
  4. Can't prove a pattern (Esp Game Theory)? Brute force for small numbers and observe!
*/
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  // int t;
  // cin >> t;
  while (t--) {
    solve();
  }
}


#pragma region
//#pragma optimize("Ofast")
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
#define tr t[root]
#define lson t[root << 1]
#define rson t[root << 1 | 1]
#define rep(i, a, n) for (int i = a; i <= n; ++i)
#define per(i, a, n) for (int i = n; i >= a; --i)
#pragma endregion
const int maxn = 2e5 + 5;
int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    m *= 100;
    rep(i, 1, n) {
        int x, y;
        scanf("%d%d", &x, &y);
        m -= x * y;
        if (m < 0) {
            printf("%d\n", i);
            return 0;
        }
    }
    puts("-1");
}

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> plp;
typedef pair<pll,ll> ppl;
typedef pair<pll,pll> ppp;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<pll> vpll;
typedef vector<plp> vplp;
typedef vector<ppl> vppl;
typedef vector<ppp> vppp;
typedef vector<vpll> vvpll;
typedef vector<bool> vbool;
typedef vector<vbool> vvbool;
typedef vector<double> vd;
typedef priority_queue<pll,vpll,greater<pll> > pqpll;
typedef priority_queue<pll,vpll> pqrpll;
typedef priority_queue<ll, vll, greater<ll> > pqll;
typedef priority_queue<ll, vll> pqrll;

struct edge{ ll to,cost; edge(ll to,ll cost): to(to), cost(cost){} };
typedef vector<vector<edge>> Graph;

#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n-1; i >= a;i--)
#define LINF 1000000000000000000
#define INF 1000000000
#define fs first
#define sc second
#define EPS 1e-10
#define ALL(a) a.begin(), a.end()

template<typename T> ll sz(vector<T> &vec){ return (ll)vec.size(); }
template<typename T> ll sz(priority_queue<T, vector<T> > &pq) {return (ll)pq.size(); }
template<typename T> ll sz(priority_queue<T, vector<T>, greater<T> > &pq) {return (ll)pq.size(); }
ll sz(string &s) {return (ll)s.size(); }

void chmin(ll &a, ll &b) { if(a > b) a = b; }
void chmax(ll &a, ll &b) { if(a < b) a = b; }

ll gcd(ll a,ll b){ return ((!b) ?a :gcd(b, a%b)); }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b; }
ll dx[4] = {0,-1,1,0},dy[4] = {-1,0,0,1};
bool checkindex(ll i,ll n){ return (i < n && i >= 0); }

int main(){
    ll t;
    cin >> t;
    rep(i,0,t){
        string s,t;
        cin >> s;
        string memo = "atcoder";

        t = s;
        sort(ALL(t),greater<char>());

        if(memo < s) cout << 0 << endl;
        else if(memo >= t) cout << -1 << endl;
        else{
            ll ans = LINF;
            rep(i,0,sz(memo)){
                rep(j,i,sz(s)){
                    if(s[j] > memo[i]){
                        ans = min(ans,j-i);
                        break;
                    }
                }
                if(s[i] < memo[i]) break;
            }
            rep(i,0,sz(s)) if(s[i] != 'a') {ans = min(ans,i); break;}
            cout << ans << endl;
        }
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define gcd __gcd
#define INF LONG_LONG_MAX
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main(){
    string str;
    cin >> str;
    int ans=0;
    rep(i,10000){
        vector<bool> flag(10);
        //最初にフラグを立てる．
        int x=i;
        rep(j,4){
            flag[x%10]=true;
            x/=10;
        }
        //フラグが立っているかをチェック．
        int flag2=true;
        rep(k,10){
            if(str[k]=='o' && flag[k]!=true) flag2=false;
            if(str[k]=='x' && flag[k]==true) flag2=false;
        }
        //cout << i << endl;
        ans+=flag2;
    }
    cout << ans << endl;
    return 0;
}

#include <iostream>
using namespace std;

int main()
{
   char a,b,c;
   cin >> a >>b >> c ;
   cout << b<<c<<a;
    return 0;
}


#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <utility>
#include <random>
#include <chrono>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//const int mod = 1e9+7;
const int MAXN = 110;
double d[MAXN], h[MAXN];
int N;
double D, H;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

double solve(int idx) {
    if(d[idx] == D) {
        return H;
    }
    return ((H + h[idx])*(D-d[idx]) + h[idx]*d[idx] - H*D)/(D - d[idx]);
}

int main() {
    quickread();
    cin >> N >> D >> H;
    for (int i = 0; i < N; i++) {
        cin >> d[i] >> h[i];
    }
    double res = 0;
    for (int i = 0; i < N; i++) {
        res = max(solve(i), res);
    }
    cout << fixed << setprecision(6) << res << endl;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

ll K,N,M;
class Node{
public:
    ll diff,b,pos;
    Node(ll _d = 0,ll _b = 0,ll _p = 0):diff(_d),b(_b),pos(_p){

    }
};
bool operator < (const Node &A,const Node &B){
    return A.diff > B.diff;
}
void solve(){
    vector<ll> vec;
    for(int i=0;i<K;i++){
        ll value;
        cin >> value;
        vec.push_back(value);
    }
    vector<Node> vn;
    vector<ll> res(K,0);
    ll sum = 0;
    for(int i=0;i<K;i++){
        ll bi = vec[i]*M/N;
        ll diff = abs(bi*N - vec[i]*M);
        sum += bi;
        vn.push_back(Node(diff,bi,i));
    }
    ll leave = M-sum;
    sort(vn.begin(),vn.end());
    // for(int i = 0;i< K;i++){
    //     cout << vn[i].diff << " " << vn[i].b << " " << vn[i].pos << endl;
    // }
    for(int i = 0;i<leave;i++){
       vn[i].b += 1;
    }
    for(int i = 0;i< K;i++){
        res[vn[i].pos] = vn[i].b;
    }
    for(int i = 0;i< K;i++){
        cout << res[i] << (i == K-1? '\n':' ');
    }
}
int main(void){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> K >> N >> M;
    solve();

    return 0;
}


#line 1 "main_d.cpp"
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <utility>
#include <limits>
#include <list>
#include <type_traits>

/* template start */

using i64=std::int_fast64_t;
using u64=std::uint_fast64_t;

#define rep(i, a, b) for (i64 i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()

#ifdef LOCAL
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  if(sizeof...(t)>0)std::cout<<" :";
  debug_out(t...);
}

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}

template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}

template<typename Num>
constexpr Num mypow(Num a, u64 b,Num id=1) {
  if(b==0)return id;
  Num x = id;
  while (b > 0) {
    if(b & 1)x*=a;
    a*=a;
    b >>= 1;
  }
  return x;
}

/* template end */

void solve(){
  i64 n;
  std::cin>>n;

  std::vector<i64> a(n);
  for(auto&& e:a)std::cin>>e;

  if(n%2==0){
    std::sort(all(a));
    bool firstwin=false;
    rep(i,0,n/2){
      if(a[2*i] < a[2*i+1])firstwin=true;
    }

    if(firstwin)std::cout<<"First\n";
    else std::cout<<"Second\n";

    return;
  }else{
    std::cout<<"Second\n";
    return;
  }
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  i64 test;
  std::cin>>test;

  while(test--)solve();

  return 0;
}

#include<bits/stdc++.h>
using namespace std;
using namespace std::chrono;
const int mod=1e9+7;
const int mex=2002;
#define ll long long
#define test int t;cin>>t;while(t--)
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fo(i,a,n) for(int i=a;i<n;i++)
#define rfo(i,a,b) for(int i=a;i>=b;i--)
#define bg begin()
#define en end()
#define fi first
#define se second
#define ub upper_bound
#define lb lower_bound
#define pb push_back
#define veci vector<int>
#define veclli vector<long long int>
#define all(x) x.begin(),x.end()
#define sci(x) scanf("%d",&x);
#define scc(x) scanf("%c",&x);
#define scs(x) scanf("%s",x);
#define debug(arr,n) for(int i=0;i<n;i++) printf("%d ",arr[i]);
#define sz(x) x.size()
#define loop(x) for(auto it=x.begin();it!= x.end();it++)
#define int long long
signed main()
{
    int n;
    cin>>n;
    int a[n],b[n],mx=0,mx2=0;
    fo(i,0,n)
    cin>>a[i];
    fo(i,0,n)
    {
        cin>>b[i];
        mx=max(a[i],mx);
        mx2=max(mx2,b[i]*mx);
        cout<<mx2<<endl;
    }

}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=100000;
int n;
int p[maxn+1],a[maxn+1];

int main(){
	cin>>n;
	iota(p,p+n+1,0);
	for (int i=2;;++i){
		int j=i*i;
		if (j>n) break;
		if (p[i]!=i) continue;
		while (j<=n) {
			p[j]=i;
			j+=i;
		}
	}
	a[1]=1;
	cout<<1;
	for  (int i=2;i<=n;++i){
		if (p[i]!=i) a[i]=a[i/p[i]]+1;
		else a[i]=2;
		cout<<' '<<a[i];
	}
	cout<<'\n';
	return 0;
}

#include <iostream>
#include <cstdio>
#include <string>
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 10010;

int main() {
    string s;
    cin >> s;
    ll n = s.size();

    deque<char> dQ;

    ll flip = 0;  // sが反転してたら1
    rep(i, n) {
        if(s[i] == 'R') {
            flip = 1 - flip;
        }
        else {
            if(flip) {
                dQ.push_front(s[i]);
            }
            else {
                dQ.pb(s[i]);
            }
        }
    }

    if(flip) {
        reverse(all(dQ));
    }

    string t = "";
    for(auto c : dQ) {
        t.push_back(c);
        ll m = t.size();
        if(m >= 2 && t[m-2] == t[m-1]) {
            rep(i, 2) {
                t.pop_back();
            }
        }
    }

    out(t);
    re0;
}


//#pragma GCC optimize "trapv"
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define ll long long int
#define fab(a,b,i) for(int i=a;i<b;i++)
#define pb push_back
#define db double
#define mp make_pair
#define endl "\n"
#define f first
#define se second
#define all(x) x.begin(),x.end()
#define MOD 1000000007
#define vll vector<ll>
#define vi vector<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define quick ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
ll add(ll x, ll y) {ll res = x + y; return (res >= MOD ? res - MOD : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= MOD ? res % MOD : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + MOD : res);}
ll power(ll x, ll y) {ll res = 1; x %= MOD; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
ll mod_inv(ll x) {return power(x, MOD - 2);}

using namespace std;
map<int,int> m;
void fac(int n)
{
    fab(1,sqrt(n)+1,i)
    {
        if(n%i==0)
        {
            m[i]++;
            if(n/i!=i)

            {
                m[n/i]++;
            }
        }
    }
}
int main()
{ quick;

    int n;
    cin>>n;
    ll a[n];
    fab(0,n,i)
    {
        cin>>a[i];
    }
    ll sum=0;
    ll ans=0;
    ll prev=0;
    ll pref=0;
    fab(0,n,i)
    {
        ans=max(ans,sum+prev);

        sum+=pref;
        sum+=a[i];
        pref+=a[i];
      //  cout<<"i:"<<i<<" "<<sum<<" "<<prev<<endl;
        prev=max(prev,pref);
    }
    ans=max(ans,sum);
    cout<<ans<<endl;

 //cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define Pint pair<int,int>
#define Pll pair<ll,ll>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000;
constexpr ll llINF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
ll modpow(ll a,ll b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    ll memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<ll>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(ll i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
vector<vector<ll>>C,sC;
void init_comb(int n,int m){
    C.resize(n+1,vector<ll>(m+1,0));
    sC.resize(n+1,vector<ll>(m+1,0));
    C[0][0]=1;
    for(int i=1;i<=n;i++){
        C[i][0]=1;
        for(int j=1;j<=m;j++){
            C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
        }
    }
    rep(i,n+1){
        rep(j,m){
            sC[i][j+1]=(sC[i][j]+C[i][j])%mod;
        }
    }
}
ll comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*invkaijo[a-b]%mod*invkaijo[b]%mod;
}
ll inv(ll x){
    x=modpow(x,mod-2);
    return x;
}
void solve(){
    int n;
    cin>>n;
    ll ans=0,cur=0,sum=0,masum=0;
    rep(i,n){
        ll a;
        cin>>a;
        sum+=a;
        chmax(masum,sum);
        chmax(ans,cur+masum);
        cur+=sum;
    }
    cout<<ans<<endl;
}
int main(){
    //int t;cin>>t;while(t--)
    solve();
    return 0;
}