#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	int n;cin>>n;
	vector<ll> a(n);
	for(int i = 0; i < n; i++) {
		cin>>a[i];
	}
	vector<ll> sum_a(n + 1,0);
	vector<ll> max_a(n + 1,0);
	for(int i = 0; i < n; i++) {
		sum_a[i + 1] = sum_a[i] + a[i];
	}
	for(int i = 0; i < n; i++) {
		max_a[i + 1] = max(max_a[i],sum_a[i + 1]);
	}
	ll ans = 0;
	ll res = 0;
	for(int i = 1; i <= n; i++) {
		chmax(res,ans + max_a[i]);
		ans += sum_a[i];
	}
	cout << res << endl;
	return 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>

#define codeWizard      ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define testCase(tc)    while(tc--)
#define vi              vector<int>
#define vvi             vector<vi>
#define pi              pair<int,int>
#define int             long long
#define lb              lower_bound
#define ub              upper_bound
#define mod             1000000007
//#define mod           998244353
#define ff              first
#define ss              second
#define inf             (int)1e17
#define ninf            -inf
#define endl            "\n"
#define fill(a,b)       memset(a,b,sizeof(a))
#define all(v)          v.begin(),v.end()                               //codeWizard
int LCM(int a, int b) {return (a * b) / __gcd(a, b);}

void init_code() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
int n;
vvi player;
bool check(int x){
    set<int> st;

    for(auto k:player){
        int bit=0;
        int i=0;
        for(auto i:k){
            bit <<= 1;
                bit |= i >= x;

        }
        st.insert(bit);
    }

    for(auto x:st){
        for(auto y:st){
            for(auto z:st){
                if((x|y|z)==31)
                    return true;
            }
        }
    }
    return false;
}
void solve(){
   cin>>n;
   for(int i=1;i<=n;i++){
    vector<int> temp(5);
    for(int j=0;j<5;j++)
        cin>>temp[j];
    player.push_back(temp);
   }
   int low=1,high=1000000001;
   int ans=0;
   while(high>low+1){
    //cout<<low<<" "<<high<<endl;
    int mid=(low+high)/2;
    if(check(mid)){
        low=mid;
    }
    else
        high=mid;
   }
   cout<<low<<endl;
}
signed main()
{
    codeWizard;
    init_code();
    int tc = 1;
    //cin >> tc;
    int num=1;
    testCase(tc) {
        //cout<<"Case #"<<num<<": ";

        num++;
        solve();
    }

    //cout << "Time execute: " << clock() / (double)CLOCKS_PER_SEC << " sec" << endl;

}


#include <bits/stdc++.h>
#define ls (rt<<1)
#define rs (rt<<1|1)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=4e5+10;
const int INF=0x3f3f3f3f;
int a[N],n;
pii pa[N];
int mx[N<<2],lazy[N<<2];
int main() {
    auto push_down=[&](int rt){
        if(lazy[rt]){
            lazy[ls]+=lazy[rt];
            lazy[rs]+=lazy[rt];
            mx[ls]-=lazy[rt];
            mx[rs]-=lazy[rt];
            lazy[rt]=0;
        }
    };
    function<void(int,int,int)>build=[&](int l,int r,int rt){
        if(l==r){mx[rt]=l;return ;}
        int mid=l+r>>1;
        build(l,mid,ls);
        build(mid+1,r,rs);
    };
    function<int(int,int,int,int)>query=[&](int l,int r,int x,int rt){
        if(l==r)return mx[rt];
        push_down(rt);int mid=l+r>>1;
        if(x<=mid)return query(l,mid,x,ls);else return query(mid+1,r,x,rs);
    };
    function<void(int,int,int,int,int,int)>update=[&](int l,int r,int L,int R,int val,int rt){
        if(L<=l&&r<=R){mx[rt]-=val;lazy[rt]+=val;return ;}
        push_down(rt);int mid=l+r>>1;
        if(L<=mid)update(l,mid,L,R,val,ls);
        if(mid<R)update(mid+1,r,L,R,val,rs);
        mx[rt]=max(mx[ls],mx[rs]);
    };
    scanf("%d",&n);
    for(int i=1;i<=2*n;i++)scanf("%d",&a[i]),pa[i]=make_pair(a[i],i>n?i-n:n-i+1);
    sort(pa+1,pa+2*n+1);
    reverse(pa+1,pa+2*n+1);
    ll ans=0;
    build(1,n,1);
    for(int i=1;i<=2*n;i++){
        int x=pa[i].second;
        int val=query(1,n,x,1);
        if(val==0)continue;
        ans+=pa[i].first;
        int l=1,r=n,res=-1;
        while (l<=r){
            int mid=l+r>>1;
            if(query(1,n,mid,1)>=val){
                res=mid;
                r=mid-1;
            }else l=mid+1;
        }
        update(1,n,res,n,1,1);
    }
    cout<<ans;
    return 0;
}

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <fstream>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define x first
#define y second
#define Time (double)clock()/CLOCKS_PER_SEC
#define debug(x) std::cerr << #x << ": " << x << '\n';
#define FOR(i, n) for (int i = 0; i < n; ++i)
#define FORN(i, n) for (int i = 1; i <= n; ++i)
#define pb push_back
#define trav(a, x) for (auto& a : x)
using vi = vector<int>;
template <typename T>
std::istream& operator >>(std::istream& input, std::vector<T>& data)
{
    for (T& x : data)
        input >> x;
    return input;
}
template <typename T>
std::ostream& operator <<(std::ostream& output, const pair <T, T> & data)
{
    output << "(" << data.x << "," << data.y << ")";
    return output;
}
template <typename T>
std::ostream& operator <<(std::ostream& output, const std::vector<T>& data)
{
    for (const T& x : data)
        output << x << " ";
    return output;
}
ll div_up(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // divide a by b rounded up
ll div_down(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // divide a by b rounded down
ll math_mod(ll a, ll b) { return a - b * div_down(a, b); }
#define tcT template<class T
#define tcTU tcT, class U
tcT> using V = vector<T>;
tcT> void re(V<T>& x) {
    trav(a, x)
        cin >> a;
}
tcT> bool ckmin(T& a, const T& b) {
    return b < a ? a = b, 1 : 0;
} // set a = min(a,b)
tcT> bool ckmax(T& a, const T& b) {
    return a < b ? a = b, 1 : 0;
}
ll gcd(ll a, ll b) {
    while (b) {
        tie(a, b) = mp(b, a % b);
    }
    return a;
}
signed main() {
    #ifdef LOCAL
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    int n;
    cin >> n;
    vi a(2 * n);
    cin >> a;
    multiset <int> ms;
    int ans = 0;
    trav (e, a)
    	ans += e;
    FOR (i, n) {
    	int l = n - 1 - i;
    	int r = n + i;
    	ms.insert(a[l]);
    	ms.insert(a[r]);
    	ans -= *ms.begin();
    	ms.erase(ms.begin());
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
// (setq-default c-basic-offset 2)

int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  vector<long long> b(n);

  for (long long& ai : a) {
    cin >> ai;
  }
  for (long long& bi : b) {
    cin >> bi;
  }

  long long dot = 0;
  for (int i = 0; i < n; ++i) {
    dot += a[i] * b[i];
  }
  if (dot == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef	long long ll;
typedef long double ld;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef set<int> si;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef vector<pii> vii;
typedef vector<pll> vll;
#define fi first
#define se second
#define pi 3.141592653589793
#define mod 998244353
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define pqmax priority_queue<int>
#define pqmin priority_queue<int,vi,greater<int>>
#define fio ios_base::sync_with_stdio(0), cin.tie(NULL)
#define tc int tt;cin>>tt;for(int ti=1;ti<=tt;ti++)
#define case_g "Case #"<<ti<<": "
#define RED "\033[31m"
#define GREEN "\033[32m"
#define RESET "\033[0m"
#define sleep for (int i = 1, a;i < 100000000;i++, a = a * a)
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> ranked_pairset;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ranked_set;
typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ranked_map;

int main() {
	fio;
	int n;
	cin >> n;
	vl a(n);
	for (int i = 0;i < n;i++)
		cin >> a[i];
	ll ans = 0;
	for (int i = 0;i < n;i++) {
		ll b;
		cin >> b;
		ans += b * a[i];
	}
	(ans && cout << "No\n") || cout << "Yes\n";
}


#include<bits/stdc++.h>
#include<algorithm>
#define int long long
using namespace std;
signed main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	//MessageBox(GetForegroundWindow(),"标题","内容",MB_YESNO);
	int a,b,x,y;
	cin>>a>>b>>x>>y;
	int sum=0;
	if(x+x<y){
		y=x+x;
	}
	if(a>b){
		sum=(a-b-1)*y;
		sum+=x;
	}else if(a==b){
		sum=x;
	}else{
		sum=(b-a)*y;
		sum+=x;
	}
	cout<<sum<<endl;
	return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cerr<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

int main() {
  int a,b,x,y; cin >> a >> b >> x >> y;
  int ans;
  if(a>b){
    ans = min(((a-b)*2-1)*x, x+(a-b-1)*y);
  }else if(a == b){
    ans = x;
  }else{
    ans = min(((b-a)*2+1)*x, x+(b-a)*y);
  }
  cout << ans << endl;
  return 0;
}


#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define reps(i,s,n) for(int i=s;i<n;++i)
using namespace std;
using ll = long long;
using P = pair<ll, int>;
using T = tuple<int,int,int>;
int main()
{
    int n, m;
    cin >> n >> m;
    vector<vector<T>> g(n);
    rep(i, m)
    {
        ll a, b,c,d;
        cin >> a >> b >> c >> d;
        --a, --b;
        g[a].emplace_back(b, c, d);
        g[b].emplace_back(a, c, d);

    }

    const ll INF = 1e18;
    vector<ll> d(n, INF);
    priority_queue<P, vector<P>, greater<P>> pq;
    pq.emplace(0, 0);
    d[0] = 0;

    while (!pq.empty())
    {
        ll c = pq.top().first;
        int s = pq.top().second;
        pq.pop();
        if (d[s] < c) continue;
        for (const auto& gi: g[s])
        {
            int e, ci, di;
            tie(e, ci, di) = gi;
            int t = round(sqrt(di));
            ll next = d[s] + ci + di / max((ll)t, d[s] + 1) + max(0LL, t - 1 - d[s]);
            if (d[e] <= next) continue;
            d[e] = next;
            pq.emplace(d[e], e);
        }
    }
    ll ans = d[n - 1];

    if (ans == INF) cout << -1 << endl;
    else cout << ans << endl;

    return 0;
}

// #pragma GCC target ("avx,avx2")
// #include <bits/extc++.h>
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

#define f first
#define s second

using namespace std;
// using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
// typedef tree<int, null_type, less<int>,
// rb_tree_tag, tree_order_statistics_node_update> oset;
//========================================================
const int N = 1e5+5, K = 19, M = 5e4+5, mod = 1e9+7, len = 30, inf = 0x3f3f3f3f;
int n, m;
ll dist[N];

vector<pair<int, pair<ll, ll>>> adj[N];

void dijkstra(int src)
{
	priority_queue<pair<ll, int>> q;

	fill(dist, dist+n, 1e18);

	q.push({0, src});
	dist[src] = 0;

	while(!q.empty())
	{
		auto t = q.top();
		q.pop();

		int u = t.s;
		if(dist[u] != -t.f)
			continue;
		if(u == n-1)
			break;
		for(auto e : adj[u])
		{
			ll v = e.f, c = e.s.f, d = e.s.s;
			auto dis = [&](ll T)
			{
				ll res = c + ll(d / (T + 1)) + T;
				return res;
			};

			ll s = 1ll * sqrt(d) - 1;
			s = max(s, 0LL);
			if(dist[u] > s)
				s = dist[u];
			ll D = min(dis(s), dis(s+1));
			// assert(D > 0);
			if(dist[v] > D)
				dist[v] = D, q.push({-D, v});
		}
	}
	if(dist[n-1] == 1e18)
		dist[n-1] = -1;
}

void run_case()
{
	scanf("%d %d", &n, &m);
	for(int i=0, u, v, c, d; i<m; i++)
	{
		scanf("%d %d %d %d", &u, &v, &c, &d);
		adj[u-1].push_back({v-1, {c, d}});
		adj[v-1].push_back({u-1, {c, d}});
	}

	dijkstra(0);
	printf("%lld\n", dist[n-1]);
}

int main()
{
    // ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    // freopen("input.txt", "rt", stdin);
    // freopen("output.txt", "wt", stdout);
    int t;
    t = 1;
    // cin >> t;
    while(t--)
        run_case();
}


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

struct edge{
  long long v;
  long long c;
  long long d;
};

long long f(long long x, long long y){
  long long l = x, r = y+1;
  while(l<r){
    long long m1 = (r-l+1)/3 + l, m2 = (r-l+1)*2/3 + l;
    long long c1 = y/(m1+1) + m1 - x, c2 = y/(m2+1) + m2 - x;
    if(c1<c2) r = m2 - 1;
    else if(c1>c2) l = m1 + 1;
    else{
      for(int i=1;;i++){
        if(m1-i<l && m2+i>r){
          l = m1;
          r = m2;
          if(l+1==r) return c1;
          break;
        }
        if(m1-i>=l){
          long long c = y/(m1-i+1) + m1-i - x;
          if(c>c1){
            l = m1;
            break;
          }
          if(c<c1){
            r = m1-1;
            break;
          }
        }
        if(m2+i<=r){
          long long c = y/(m2+i+1) + m2+i - x;
          if(c>c1){
            r = m2;
            break;
          }
          if(c<c1){
            l = m2+1;
            break;
          }
        }
      }
    }
  }
  return y/(l+1) + l - x;
}

int main(){
  long long N,M;
  cin >> N >> M;
  vector<vector<edge>> G(N,vector<edge>(0));
  for(int i=0;i<M;i++){
    long long a,b,c,d;
    cin >> a >> b >> c >> d;
    a--;
    b--;
    edge e1 = {b,c,d}, e2 = {a,c,d};
    G[a].push_back(e1);
    G[b].push_back(e2);
  }

  vector<long long> V(N,-1);
  priority_queue<pair<long long,long long>> Q;
  Q.push(make_pair(0,0));
  V[0] = 0;
  while(!Q.empty()){
    auto p = Q.top();
    Q.pop();
    long long t = -p.first, u = p.second;
    if(t!=V[u]) continue;
    for(int i=0;i<G[u].size();i++){
      edge e = G[u][i];
      long long cost = e.c;
      if(e.d>=t+1) cost += f(t,e.d);
      if(V[e.v]==-1 || V[e.v]>V[u]+cost){
        V[e.v] = V[u] + cost;
        Q.push(make_pair(-V[e.v],e.v));
      }
    }
  }

  cout << V[N-1] << endl;
  return 0;
}

/*input

*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <iomanip>
#include <climits>
#define mod 1000000007

// templates
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define sz(x) (int)x.size()
#define po(x,y)   fixed<<setprecision(y)<<x
#define ss(s) scanf(" %[^\n]%*c", s)
#define ps(s) printf("%s\n",s)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;

void sc(int&n) {int number; scanf("%d", &number); n = number;}
void sc(ll&n) {ll number; scanf("%lld", &number); n = number;}
void _print(ll t) {printf("%lld", t);}
void _print(int t) {printf("%d", t);}
void _print(string t) {cout << t;}
void _print(char t) {printf("%c\n", t);}
void _print(lld t) {cout << t;}
void _print(double t) {cout << t;}
void _print(ull t) {cout << t;}

template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cout << "{"; _print(p.F); cout << ","; _print(p.S); cout << "}";}
template <class T> void _print(vector <T> v) {cout << "vec->[ "; for (T i : v) {_print(i); cout << " ";} cout << "]";}
template <class T> void _print(set <T> v) {cout << "set->[ "; for (T i : v) {_print(i); cout << " ";} cout << "]";}
template <class T> void _print(multiset <T> v) {cout << "multiset->[ "; for (T i : v) {_print(i); cout << " ";} cout << "]";}
template <class T, class V> void _print(map <T, V> v) {cout << "map->[ "; for (auto i : v) {_print(i); cout << " ";} cout << "]";}

const ll inf = (ll)1e17 + 10;
const int N = (int)1e5 + 10;
vector<array<ll, 3>>adj[N];

void bfs(int n) {

	vector<ll>dist(n + 1, 0);
	for (int i = 0; i <= n; ++i)
	{
		dist[i] = inf;
	}
	set<array<ll, 2>>pq;
	dist[0] = 0;
	pq.insert({0, 0});
	while (!pq.empty()) {

		auto [t, node] = *pq.begin();
		pq.erase(pq.begin());
		for (auto c : adj[node]) {
			ll cost = 0;
			ll sq = 0;
			cost = t + c[1] + (c[2] / (t + 1));
			sq = sqrt(c[2]);
			if (sq * sq != c[2])sq++;
			sq--;
			if (t < sq) {
				cost = min(cost, sq + c[1] + (c[2] / (sq + 1)));
			}
			if (dist[c[0]] > cost) {
				pq.erase({dist[c[0]], c[0]});
				dist[c[0]] = cost;
				pq.insert({dist[c[0]], c[0]});

			}

		}
	}
	if (dist[n - 1] == inf)dist[n - 1] = -1;
	_print(dist[n - 1]);
}
void solve()
{
	int n, m;
	sc(n), sc(m);
	for (int i = 0; i < m; ++i)
	{
		ll u, v, c, d;
		sc(u), sc(v), sc(c), sc(d);
		u--, v--;
		adj[u].push_back({v, c, d});
		adj[v].push_back({u, c, d});
	}
	bfs(n);
}

int main()
{
//#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//#endif
	int t = 1;
	// sc(t);
	while (t--) {
		solve();
	}
	return 0;

}


/*
皮卡丘冲鸭！
へ　　　　　／|
　　/＼7　　　 ∠＿/
　 /　│　　 ／　／
　│　Z ＿,＜　／　　 /`ヽ
　│　　　　　ヽ　　 /　　〉
　 Y　　　　　`　 /　　/
　ｲ●　､　●　　⊂⊃〈　　/
　()　 へ　　　　|　＼〈
　　>ｰ ､_　 ィ　 │ ／／
　 / へ　　 /　ﾉ＜| ＼＼
　 ヽ_ﾉ　　(_／　 │／／
　　7　　　　　　　|／
　　＞―r￣￣`ｰ―＿
*/
#include <iostream>
#define For(i,x,y) for(int i=(x); i<=(y); i++)
#define fori(i,x,y) for(int i=(x); i<(y); i++)
#define rep(i,y,x) for(int i=(y); i>=(x); i--)
#define mst(x,a) memset(x,a,sizeof(x))
#define pb push_back
#define sz(a) (int)a.size()
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int>pa;
typedef pair<ll,ll>pai;
const int N = 1e3;
const int M = 1e5;
ll f[66][2];
const string ju[]={"AND","OR"};
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin>>n;
    string s[70];
    ll a[70];
    For(i,1,n){
        cin>>s[i];
        a[i] = s[i]==ju[0]?1:0;
    }
    int pre = 0;
    int ans = 0;
    f[0][0] = 1;
    f[0][1] = 1;
    For(i,1,n){
        if(a[i]){
            f[i][0] = f[i-1][1] + f[i-1][0]*2;
            //f[i][1] = f[pre][1];
            f[i][1] = f[i-1][1];//if(pre!=0&&i-pre>1)f[i][1] = f[pre][1]*(1<<(i-pre-1)) + f[pre][0]*(1<<(i-pre-2));
            //else f[i][1] = f[pre][1];

        }else {
            f[i][1] = f[i-1][0] + f[i-1][1]*2;
            f[i][0] = f[i-1][0];
        }//ans = max(f[i][1],ans);
    }
    cout<<f[n][1]<<endl;
    return 0;
}

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

#define nl "\n"
#define nf endl
#define ll long long
#define pb push_back
#define _ << ' ' <<

#define INF (ll)1e18
#define mod 998244353
#define maxn 110

ll i, i1, j, k, k1, t, n, m, res, flag[10], a, b;
string s;

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

    #if !ONLINE_JUDGE && !EVAL
        ifstream cin("input.txt");
        ofstream cout("output.txt");
    #endif

    cin >> n >> s; s = '#' + s;

    if (s[1] != s[n]) {
        cout << 1 << nl; return 0;
    }

    for (i = 1; i <= n - 1; i++) {
        if (s[i] != s[1] && s[i + 1] != s[1]) {
            cout << 2 << nl; return 0;
        }
    }

    cout << -1 << nl;

    return 0;
}


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

//alias g++='g++ -I/mnt/c/Users/Owner/Desktop/ac-library'
using ll             = long long;
using ld             = long double;
using P              = pair<int, int>;
using PI             = pair<pair<int, int>, int>;
using PL             = pair<long long, long long>;
using PLL            = pair<pair<long long, long long>, long long>;
using Pxy            = pair<long double, long double>;
const int INF        = 1001001007;
const int modd       = 1000000007;
const long long modl = 1000000007LL;
const long long mod  = 998244353LL;
const ll inf         = 2e18;

void yes() { cout << "Yes" << endl; }
void no() { cout << "No" << endl; }
void yn(bool t) {if(t) yes(); else no();}
void Yes() { cout << "YES" << endl; }
void No() { cout << "NO" << endl; }
void YN(bool t) {if(t) Yes(); else No();}

vector<int> dx   = { 0, 1, 0, -1 };
vector<int> dy   = { 1, 0, -1, 0 };
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string alp = "abcdefghijklmnopqrstuvwxyz";

int main() {
       int N; cin >> N;
    int cou = 0;
    rep(i,N){
        int a; cin >>a;
        if((a-10)<0) continue;
        cou += (a-10);
    }
    cout << cou << endl;
}

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;

//#define ACL
#ifdef ACL
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
#if __has_include("acl-all.h")
#include "acl-all.h" //on Wandbox
using namespace atcoder;
#endif
#endif //#ifdef ACL

typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<ll, ll> > vpll;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
typedef vector<vector<bool> > vvb;
typedef pair<ll, ll> pll;

#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define rrep(i, n) for (int i = 1; i <= int(n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = int(n)-1; i >= 0; --i)

#define MES(a) MES2 a
#define MES2(a0,a1,a2,a3,a4,x,...) x
#define mes_1(x1) cout<<x1<<endl
#define mes_2(x1,x2) cout<<x1<<" "<<x2<<endl
#define mes_3(x1,x2,x3) cout<<x1<<" "<<x2<<" "<<x3<<endl
#define mes_4(x1,x2,x3,x4) cout<<x1<<" "<<x2<<" "<<x3<<" "<<x4<<endl
#define mes_5(x1,x2,x3,x4,x5) cout<<x1<<" "<<x2<<" "<<x3<<" "<<x4<<" "<<x5<<endl
#define mes(...) CHOOSE((__VA_ARGS__,mes_5,mes_4,mes_3,mes_2,mes_1,~))(__VA_ARGS__)

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)

#define Ynmes(a) (a) ? mes("Yes") : mes("No")
#define YNmes(a) (a) ? mes("YES") : mes("NO")
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define Rev(a) reverse(a.begin(), a.end())

int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } };
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

ll fact_mod(ll n, ll mod) {
    ll f = 1; for (ll i = 2; i <= n; i++) f = f * (i % mod) % mod;
    return f;
}

ll modpow(ll x, ll n, ll mod) {
    if(n == 0) return 1;
    ll res = modpow((x * x) % mod, n / 2 , mod);
    if(n & 1) res = (res * x) % mod;
    return res;
}

ll modncr(ll n, ll r, ll mod) {
    if(r > n-r) r = n-r;
    if(r == 0) return 1;
    ll a = 1;
    rep(i, r) a = a * ((n-i) % mod) % mod;
    ll b = modpow(fact_mod(r, mod), mod-2, mod);
    return (a % mod) * (b % mod) % mod;
}

signed main() {
	ll n;
    cin >> n;
    if (n < 999) {
        mes(0);
        re0;
    }

    ll r = 0;
    if (n > 999) {
        r += n-999;
    }

    if (n > 999999) {
        r += n-999999;
    }

    if (n > 999999999) {
        r += n-999999999;
    }
    if (n > 999999999999) {
        r += n-999999999999;
    }
    if (n > 999999999999999) {
        r += n-999999999999999;
    }

    mes(r);

}


#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define forn(i,n) for(int i = 0; i < (int) n; i++)
#define ios ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;
typedef long long ll;

ll stars3(ll x) {
  return (x + 2) * (x + 1) / 2;
}

ll n;

// a + b + c = x
// 0 <= a,b,c < n
ll count3(ll x) {
  ll ans = stars3(x);
  if (x >= n) ans -= stars3(x - n) * 3;
  if (x >= 2 * n) ans += stars3(x - 2 * n) * 3;
  if (x >= 3 * n) ans -= stars3(x - 3 * n);
  return ans;
}

// b + c = x
// 0 <= b,c < n
ll count2(ll x) {
  ll ans = x + 1;
  if (x >= n) ans -= (x - n + 1) * 2;
  if (x >= 2 * n) ans += (x - 2 * n + 1);
  return ans;
}

int main() {
  ll k;
  cin >> n >> k;

  ll sm, tot = 0;
  for(sm = 0; sm <= 3 * n - 3; sm++) {
    ll cnt = count3(sm);
    if (tot + cnt >= k) break;
    tot += cnt;
  }

  int a;
  for(a = 0; a < n; a++) {
    ll cnt = count2(sm - a);
    if (tot + cnt >= k) break;
    tot += cnt;
  }

  int fs = max(0ll, sm - a - n + 1);
  int b = fs + k - tot - 1;
  int c = sm - a - b;

  cout << a + 1 << " " << b + 1 << " " << c + 1 << "\n";
}

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

int N;
long long K, dp[4][3000001];

int main() {
    scanf("%d %lld", &N, &K);
    memset(dp,0,sizeof(dp));
    dp[0][0] = 1;
    for (int i = 1; i <= 3; ++i) {
        long long x = 0;
        for (int j = 0; j <= N*i; ++j) {
            dp[i][j] = x, x += dp[i-1][j];
            if (j >= N) x -= dp[i-1][j-N];
        }
    }
    int sum = 0;
    for (sum = 0; sum <= N*3 && K > dp[3][sum]; ++sum) K -= dp[3][sum];
    int num = 1;
    while (num <= N && K > max(min(N,sum-num-1) - max(1,sum-num-N) + 1,0))
        K -= max(min(N,sum-num-1) - max(1,sum-num-N) + 1,0), num++;
    int x = max(1,sum-num-N) + K - 1;
    printf("%d %d %d", num, x, sum - num - x);

    return 0;
}


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

using ll = long long;

int a[100001];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    fill(a + 1, a + n + 1, 2);
    for(int i = 2; i + i <= n; i++) {
        for(int j = i + i; j <= n; j += i) {
            a[j] += a[i] == a[j];
        }
    }
    cout << 1;
    for(int i = 2; i <= n; i++) {
        cout << ' ' << a[i];
    }
    return 0;
}

#include <cstdio>
#include <vector>
using namespace std;

int main (){
	bool notprime[100001] = {};
	int N;
	int v[100001] = {};
	vector<int> prime;
	scanf("%d", &N);
	notprime[1] = true;
	for (int i = 2; i <= N; i++)
		if (!notprime[i]){
			prime.push_back(i);
			for (long long j = (long long) i * i; j <= N; j += i)
				notprime[j] = true;
		}
	v[1] = 1;
	v[2] = v[3] = 2;
	for (int i = 4; i <= N; i++){
		int j = i;
		int index = 0;
		while (index < prime.size() && j > 1){
			if (prime[index] > j)
				break;
			else if (j % prime[index])
				index++;
			else {
				v[i] = max(v[i], v[i / prime[index]] + 1);
				while (j % prime[index] == 0)
					j /= prime[index];
			}
		}
	}
	for (int i = 1; i <= N; i++)
		printf("%d%c", v[i], i < N ? ' ' : '\n');
	return 0;
}


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

#define watch(x) cerr << (#x) << ": " << (x) << endl

typedef long long LL;

const int N = 100009;
int n, l, a[N], b[N];

LL ans;

void nope() {
    cout << -1 << endl;
    exit(0);
}

LL rgt(int i, int j) {
    LL ret = 0;

    int prevadd = 0;
    int cur = i+1;
    for(int index = i; index < j; index++) {
        while(cur <= j) {
            int seek = b[index] + (cur-index);
            if(seek < a[cur]) {
                nope();
            } else if (seek > a[cur]) {
                cur++;
            } else {
                int curadd = cur-index;
                if(prevadd-1 != curadd) {
                    ret += cur-index;
                }
                prevadd = curadd;
                break;
            }
        }
        if(cur > j) {
            nope();
        }
    }

    return ret;
}

LL lft(int i, int j) {
    LL ret  = 0;

    int prevadd = 0;
    int cur = j-1;
    for(int index = j; index > i; --index) {
        while(cur >= i) {
            int seek = b[index] - (index-cur);
            if(seek > a[cur]) {
                nope();
            } else if(seek < a[cur]) {
                cur--;
            } else {
                int curadd = index - cur;
                if(prevadd-1 != curadd) {
                    ret += index-cur;
                }
                prevadd = curadd;
                break;
            }
        }
        if(cur < i) {
            nope();
        }
    }
    return ret;
}

int main() {

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

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

    a[n+1] = b[n+1] = l+1;

    int state = 0; // 0 is adding to right chain, 1 is adding to left chain
    int prev = 0;
    for(int i = 0; i <= n+1; ++i) {
        if(a[i] == b[i]) {
            if(state == 0) {
                ans += rgt(prev, i);
                state = 1;
                prev = i;
            } else {
                ans += lft(prev, i-1);
                prev = i;
            }
        } else if(b[i] > a[i]) { //going right now
            if(state == 1) {
                ans += lft(prev, i-1);
                prev = i;
                state = 0;
            }
        } else { //going left now
            if(state == 0) {
                nope();
            }
        }
    }

    cout << ans << '\n';

    return 0;
}

/*
“The only way that we can live is if we grow.
 The only way we can grow is if we change.
The only way we can change is if we learn.
 The only way we can learn is if we are exposed.
 And the only way that we are exposed is if we throw ourselves into the open.”
 ***************************************   ************************   **********************************
*/
#include <bits/stdc++.h>
using namespace std;

//---------------------mishra ka idea------------------
#define int         long long
#define double      long double
#define pb          push_back
#define pf          push_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define endl        '\n'
#define sz(x)	    (int)(x).size()
#define ull       unsigned long long
//------------------------mishra ka idea-------------------

//-------------------------alsi hu mai-----------------------
#define fo(i,l,u)   for(i=l;i<u;i++)
#define rfo(i,l,u)  for(i=l;i>=u;i--)
#define allfo(s)    for(auto it=(s).begin();it!=(s).end();it++)
#define _init(b)     memset(b,-1,sizeof(b))
#define _init0(b)     memset(b,0,sizeof(b))
#define MOD         1000000007
#define hell        998244353
#define output(x) cout << (x ? "YES" : "NO")<<endl;
#define Output(x) cout << (x ? "Yes" : "No")<<endl;
//-------------------------alsi hu mai-----------------------

//--------------------het se uthaya---------------------
#define MOD2 (998244353)
#define MOD3 (1000000009)
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)

template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
ifstream cinn("in.txt");ofstream coutt("out.txt");
int poww(const int &a,int b,const int &m=MOD){if(b==0)return 1;int x=poww(a,b/2,m);x=x*x%m;if(b&1)x=x*a%m;return x;}

//--------------------het se uthaya-------------------------------------------------------------------

int gcd(int a, int b) {if(a>b)swap(a,b) ;  if (a == 0)  return b; return gcd(b % a, a); }
int rint(int  l , int r){return rand()%(r-l+1) + l ;}

//---------------------------aab code dekho bahut template dekh liya---------------------------------
const int N = 1e5+5;
vii graph[N];

 int lable[N],vis[N];
void dfs(int p , int par , int l ){
	if(vis[p]!=-1)return ;
	vis[p]=1;
	//cout<<p<<" "<<par<<" "<<l<<endl;
	if(l!=-1)lable[p]=l;

	for(auto aa : graph[p]){
		if(aa.x==par)continue;
		if(vis[aa.x]==-1){
			//cout<<aa.y<<"<<"<<endl;
			if(aa.y==lable[p])dfs(aa.x,p,-1);
			else dfs(aa.x,p,aa.y);
		}
	}
	int ans=1;
	if(l==-1){
		vi v;
		for(auto aa:graph[p]){
			v.pb(lable[aa.x]);
		}
		sort(all(v));
		for(auto aa:v){
			if(ans==aa)ans++;
		}
		lable[p]=ans;
	}
}

signed main()
{
   // freopen("input.txt", "r", stdin);
   // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int i,j,x;
   int n , m;
   cin>>n>>m;
   int a, b, c;
   fo(i,0,m){
   	cin>>a>>b>>c;
   	graph[a].pb({b,c});
   	graph[b].pb({a,c});
   }
   _init(vis);
   dfs(1,0,-1);
   fo(i,1,n+1){
   	cout<<lable[i]<<" ";
   }

    return 0;
}


#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <array>
#include <numeric>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;
typedef tuple<ll, ll, ll> tl3;

//typedef modint998244353 mint;

const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const double EPS = 1e-7;
const int MAX = 1e5 + 5;

const string ATC = "atcoder";

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	vector<int> b(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> b[i];
	}
	vector<int> c(n);
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		sum += b[i];
		c[i] = a[i] - b[i];
	}
	vector<priority_queue<ll>> pq(2);
	for (int i = 0; i < n; i++) {
		pq[i % 2].push(c[i]);
	}

	ll ans = sum;
	while (!pq[0].empty()) {
		ll p = pq[0].top() + pq[1].top();
		pq[0].pop();
		pq[1].pop();
		if (p <= 0) {
			break;
		}

		ans += p;
	}
	cout << ans << endl;
}

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

template <typename T> T my_gcd(T a, T b) {
  if (b == 0) {
    return a;
  }
  else {
    return my_gcd(b, a%b);
  }
}

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

  vector<int> x(n);
  for (int i = 0; i < n; i++) {
    cin >> x.at(i);
  }

  set<int> s;
  for (int i = 0; i < n; i++) {
    int now = x.at(i);
    for (int j = 2; j*j <= now; j++) {
      if (now%j == 0) {
        s.insert(j);
        while (now%j == 0) {
          now /= j;
        }
      }
    }
    if (now > 1) {
      s.insert(now);
    }
  }

  long long res = 1;
  vector<int> p;
  for (int e : s) {
    res *= e;
    p.push_back(e);
  }

  int m = p.size();
  for (int i = 0; i < (1 << m); i++) {
    long long now = 1;
    for (int j = 0; j < m; j++) {
      if (i & (1 << j)) {
        now *= p.at(j);
      }
    }
    if (now > res) {
      continue;
    }
    bool check = true;
    for (int k = 0; k < n; k++) {
      if (my_gcd(now, (long long)x.at(k)) == 1) {
        check = false;
        break;
      }
    }
    if (check) {
      res = min(res, now);
    }
  }

  cout << res << endl;
}


#include <iostream>
using namespace std;
int main(){
int a,b,c,d;
  cin>>a>>b>>c>>d;
  cout<<-(b*c-a*d);
  return 0;
}

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

#define pi 3.1415926535
#define endl "\n"
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define ll long long
#define setbits(x) __builtin_popcountll(x)
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define f(i,a,n) for(int i = a ; i < n ; i++)
#define rf(i,n,a) for(int i = n-1 ; i >= a ; i--)
#define F first
#define S second
#define mem(a,x) memset(a,x,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define get(a,n) f(i,0,n) cin >> a[i];
#define sp(x) fixed << setprecision(10) << x
#define nitro ios:: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define trace(x) cerr << '>' << #x << ':' << (x) << "\n"
#define trace2(x,y) cerr<< '>' << #x << ':' << (x) << " | " << #y << ':' << (y) << "\n"
#define trace3(a,b,c) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define trace4(a,b,c,d) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"
#define show(a,n) f(i,0,n) cout << a[i] << " "; cout << endl;

int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dy[] = {0, 0, -1, 1, 1, -1, 1, -1};
string ds = "DULR";

typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef map<int,int> mii;
typedef map<ll,ll> mll;

const int inf = 1e9;
const ll inf64 = 1e18;
const int mod = inf + 7;
const int N = 1e6 + 10;

void solve()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << a*d - b*c;
}

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


#include <bits/stdc++.h>

using namespace std;
#define fast	ios::sync_with_stdio(0);cin.tie(0);
#define ll	long long int
#define INFL    1e18L
#define INF     2e9
#define nl     	'\n'
#define ld long double
#define precision(x)	fixed << setprecision(x)
const ll mod = 998244353;

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

ll powm(ll a, ll b) {
	ll res = 1;
	while (b) {
		if (b & 1)
			res = (res * 1LL * a) % mod;
		b >>= 1LL;
		a = (a * 1LL * a) % mod;
	}
	return res;
}
const int N = 2e5 + 5;
const int M = 10;

//--------------------------------------------------------------------------------------------------------------------------//

void solve() {
	int n;
	cin >> n;
	ll mn[n][n];
	ll a[n];

	for (int i = 0; i < n; i++) cin >> a[i];
	ll ans = 0;
	for (int len = 1; len <= n; len++) {
		for (int i = 0; i <= n - len; i++) {
			int j = i + len - 1;
			if (i == j) {
				mn[i][j] = a[i];
				ans = max(ans, mn[i][j]);
			} else {
				mn[i][j] = min(a[j], mn[i][j - 1]);
				ans = max(ans, mn[i][j] * len);
			}
		}
	}
	cout << ans << nl;
}
int main() {
	fast
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int tc = 1;
	// cin >> tc;
	int _ = 0;
	while (_++ < tc) {
		solve();
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define endl "\n"
#define mod 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     ll tt,n;
//     cin >> tt;
//    while(tt--){
    cin>>n;
    int a[n+1];
    rep(i,n)
        cin>>a[i];
    stack<pair<int,int> >s;
    vector<int>v1,v2;
    for(int i=0;i<n;i++)    //smallest nearest to left
    {
        if(s.empty())
            v1.pb(0);
        else if(a[i]>s.top().second)
            v1.pb(s.top().first);
        else
        {
            while(s.size()>0&&s.top().second>=a[i])
                s.pop();
            if(s.empty())
                v1.pb(0);
            else
                v1.pb(s.top().first);
        }
        s.push(mp(i+1,a[i]));
    }
    while(!s.empty())
        s.pop();

    for(int i=n-1;i>=0;i--)    //smallest nearest to right
    {
        if(s.empty())
            v2.pb(n+1);
        else if(a[i]>s.top().second)
            v2.pb(s.top().first);
        else
        {
            while(s.size()>0&&s.top().second>=a[i])
                s.pop();
            if(s.empty())
                v2.pb(n+1);
            else
                v2.pb(s.top().first);
        }
        s.push(mp(i+1,a[i]));
    }
    reverse(v2.begin(),v2.end());

    ll ans=0,area=0;
    for(int i=0;i<n;i++)
    {
        area=a[i]*(v2[i]-v1[i]-1);
        ans=max(ans,area);
    }
    cout<<ans<<endl;

//    }
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#define rep(i,begin, end) for (ll i = begin; i < (ll)(end); i++)

using namespace std;
using ll = long long;

template<typename T>
using vec2 = vector<vector<T>>;
template<typename T>
using vec3 = vec2<vector<T>>;
template<typename T>
using vec4 = vec3<vector<T>>;
template<typename T>
using vec5 = vec4<vector<T>>;
template<typename T>
using vec6 = vec5<vector<T>>;

ll extGCD(ll a, ll b, ll &x, ll &y){
    if(b == 0){
        x = 1;
        y = 0;
        return a;
    }
    ll g = extGCD(b, a%b, y, x);
    y -= a/b * x;
    return g;
}
ll MOD = 1000000007;

vector<ll> mfact(1,1);

ll minv(ll a){
    ll x;ll y;
    extGCD(a, MOD, x, y);
    if(x<0){
        x+= ((-x)/MOD+1)*MOD;
        x %= MOD;
    }
    return x;
}

ll mpow(ll a,ll b){
    ll res = 1;
    while(b > 0){
        if(b%2==1)res=(res*a)%MOD;
        b/=2;
        a = (a*a)%MOD;
    }
    return res;
}

ll mfactorial(ll a){
    if(mfact.size()-1 >= a)return mfact[a];
    for(ll i = mfact.size();i<=a;i++){
        mfact.push_back((i * mfact[i-1])%MOD);
    }
    return mfact[a];
}

ll mcomb(ll n, ll r){
    return (((mfactorial(n) * minv(mfactorial(r)))%MOD) * minv(mfactorial(n-r)))%MOD;
}
ll ipow(ll a, ll b){
    ll res = 1;
    while(b > 0){
        if(b % 2 == 1)res*=a;
        a*=a;
        b/=2;
    }
    return res;
}

void factorize(map<ll,ll>& fac, vector<ll>& sieved, ll a){
    while(a != 1){
        if(fac.find(sieved[a]) == fac.end())fac[sieved[a]] = 0;
        fac[sieved[a]]++;
        a/=sieved[a];

    }
}
void primesieve(vector<ll>& res,ll n){
    res = vector<ll>(n+1, -1);
    for(int i = 2;i <= n;i++){
        if(res[i] != -1)continue;
        res[i] = i;
        for(int j = 2;j*i <= n;j++){
            res[j*i] = i;
        }
    }
}
vector<ll> primesuntil(ll n){
    vector<ll> res;
    vector<ll> sieved;
    primesieve(sieved, n);
    for(int i = 2;i <= n;i++){
        if(sieved[i] == i)res.push_back(i);
    }
    return res;
}
int gcd(int a, int b){
    if(b == 0)return a;
    return gcd(b, a%b);
}

void solve(){
    // cout<<"##########"<<endl;
    ll X,Y,P,Q;cin>>X>>Y>>P>>Q;
    ll res = -1;
    rep(q,0,Q){
        rep(y,0,Y){
            ll d = gcd(2*X+2*Y, -(P+Q));
            if((P+q-X-y) % d != 0)continue;
            // cout<<(P+q-X-y)<<endl;
            // cout<<d<<endl;
            ll s,t;
            extGCD((2*X+2*Y)/d, -(P+Q)/d, s,t);
            // cout<<s<<" "<<t<<endl;
            s *= (P+q-X-y)/d;
            t *= (P+q-X-y)/d;
            ll k = d<0 ? floor(min(-(double)d*(double)s/(double)(P+Q), -(double)d*(double)t/(double)(2*X+2*Y)))
                        : ceil(max(-(double)d*(double)s/(double)(P+Q), -(double)d*(double)t/(double)(2*X+2*Y)));
            // cout<<k<<endl;
            s += k*(P+Q)/d;
            t += k*(2*X+2*Y)/d;
            // cout<<2*X+2*Y<<" "<< (P+Q)<<" "<<s<<" "<<t<<endl;

            // cout<<2*X+2*Y<<" "<< (P+Q)<<" "<<s<<" "<<t<<endl;
            ll a = (2*X+2*Y)*s+X+y;
            if(res == -1)res = a;
            res = min(res,a);
            // cout<<a<<endl;
            // cout<<"!!!!!!!!!!!!!!!!"<<endl;

        }
    }

    cout<<(res==-1 ? "infinity" : to_string(res))<<endl;
}

int main(){
    int T;cin>>T;
    rep(i,0,T)solve();
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#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 MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
#define MOD(a, m) ((a % m + m) % m)
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 ll MOD = 1e9+7;

// 負の数にも対応した mod
// 例えば -17 を 5 で割った余りは本当は 3 (-17 ≡ 3 (mod. 5))
// しかし単に -17 % 5 では -2 になってしまう
inline long long mod(long long a, long long m) {
    return (a % m + m) % m;
}

// 拡張 Euclid の互除法
// ap + bq = gcd(a, b) となる (p, q) を求め、d = gcd(a, b) をリターンします
//
// ## TODO : 要確認
// ## ax + by = Aを満たす一般解(x, y)を求める
// auto d = extGcd(a, b, p, q);
// if(A % d != 0) continue;
// p *= A/d, q *= A/d;
// (x, y) = (p + k * (b/d), q - k * (a/d));
long long extGcd(long long a, long long b, long long &p, long long &q) {
    if (b == 0) { p = 1; q = 0; return a; }
    long long d = extGcd(b, a%b, q, p);
    q -= a/b * p;
    return d;
}

int main(){
    ll T;
    cin >> T;
    while(T--){
        ll X, Y, P, Q;
        cin >> X >> Y >> P >> Q;

        ll T_train = 2*X + 2*Y;
        ll T_player = P + Q;

        const ll INF = LLONG_MAX;
        ll ans = INF;
        for(ll t1 = X; t1 < X+Y; t1++){
            for(ll t2 = P; t2< P+Q; t2++){
                //// t1 - t2 = -T_train * n + T_player * m;
                ll n, m;
                auto d = extGcd(T_train, T_player, n, m);
                ll rhs = t1 - t2;
                if(rhs % d != 0) continue;
                n *= -rhs/d, m *= rhs/d;
                n = mod(n, T_player/d);
                //printf("%lld, %lld\n", t1 + T_train * n, t2 + T_player * m);
                chmin(ans, t1 + T_train * n);
            }
        }

        if(ans == INF){
            cout << "infinity" << endl;
        }
        else{
            cout << ans << endl;
        }
    }
    return 0;
}


/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */
#include <bits/stdc++.h>
using namespace std;

const bool ready = [](){
    ios_base::sync_with_stdio(false); cin.tie(0);
    cout << fixed << setprecision(12);
    return true;
}();

using ld=long double;
const ld PI = acos((ld)-1);
using ll= long long;
#define int ll
#define all(v) (v).begin(), (v).end()
#define fori(n) for(int i=0; i<int(n); i++)

#define cini(i) int i; cin>>i;
#define cins(s) string s; cin>>s;
#define cind(d) ld d; cin>>d;
#define cinai(a,n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s,n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a,n) vd a(n); fori(n) { cin>>a[i]; }

using pii= pair<int, int>;
using pdd= pair<ld, ld>;
using vd= vector<ld>;
using vb= vector<bool>;
using vi= vector<int>;
using vvi= vector<vi>;
using vs= vector<string>;

#define endl "\n"

/*
 * Consider 1,3,2
 * We would like to choose pos=2 to swap 3,2, but that not possible in
 * first operation.
 * So we must choose pos=1, which yields 3,1,2
 * Then we must choose pos=2, 3,2,1
 * 2,3,1
 * 2,1,3
 * 1,2,3
 * So, we swap the smallest inversion if possible, else the next position,
 * else the previous position.
 * How to maintain the "next inversion"?
 * -> Just use a pointer to current element, go left to right.
 *
 * How do we go left to right?
 * Invariant: a[0]..a[i] is sorted
 */
void solve() {
    cini(n);
    cinai(a,n);

    int i=0;
    while(i+1<n && a[i]<a[i+1])
        i++;

    int op=0;
    vi ans;
    while(i+1<n) {

        if(a[i]>a[i+1] && (i%2==op)) {
            swap(a[i], a[i+1]);
            ans.push_back(i+1);
            if(i>0)
                i--;
        } else if(i+2<n) {
            swap(a[i+1], a[i+2]);
            ans.push_back(i+2);
        } else  {
            assert(i>0);
            i--;
            swap(a[i], a[i+1]);
            ans.push_back(i+1);
            if(i>0)
                i--;
        }

        while(i+1<n && a[i]<a[i+1])
            i++;

        op=!op;
    }
    cout<<ans.size()<<endl;
    for(int i : ans)
        cout<<i<<" ";
    cout<<endl;
}

signed main() {
    cini(t);
    while(t--)
        solve();
}

#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[33;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(),v.end()),v.end());
}
ll rand_int(ll l, ll r) //[l, r]
{
	static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
	return uniform_int_distribution<ll>(l, r)(gen);
}
template<class T>
void print(T x,int suc=1)
{
	cout<<x;
	if(suc==1) cout<<'\n';
	else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
	for(int i=0;i<v.size();i++)
	print(v[i],i==(int)(v.size())-1?suc:2);
}
void solve()
{
    int n;
    cin>>n;
    vi p(n);
    vi pos(n);
    for(int i=0;i<n;i++)
    {
        cin>>p[i];
        p[i]--;
        pos[p[i]]=i;
    }
    if(n==4&&p[0]==3&&p[1]==2&&p[2]==1&&p[3]==0)
    {
        print(6);
        cout<<"1 2 3 2 1 2\n";
        return;
    }
    if(n==4&&p[0]==2&&p[1]==3&&p[2]==0&&p[3]==1)
    {
        print(6);
        cout<<"1 2 1 2 3 2\n";
        return;
    }
    //dbg(p);
    vi ans;
    auto change=[&](int x){
        assert(x%2==ans.size()%2&&x<n-1);
        ans.push_back(x+1);
        pos[p[x+1]]=x;
        pos[p[x]]=x+1;
        swap(p[x],p[x+1]);
    };
    auto waf=[&](){
        for(int i=0;i<n-1;i++)
        {
            if(i%2==0&&p[i]&&p[i+1])
            {
                change(i);
                break;
            }
        }
    };
    while(pos[0]!=0)
    {
        int tar=pos[0]-1;
        if(tar%2!=ans.size()%2)
            waf();
        change(tar);
    }
    auto cwp=[&](int x){
        assert(x);
        if(x%2==ans.size()%2) change(x);
        else{
            change(x-1);
            change(x);
            change(x-1);
            change(x);
            change(x-1);
        }
    };
    for(int i=1;i<n;i++)
    {
        //dbg(p);
        while(pos[i]!=i)
        {
            int tar;
            if(pos[i]>i) tar=pos[i]-1;
            else tar=pos[i];
            //dbg(tar);
            if(tar%2!=ans.size()%2)
            {
                if(abs(tar-i)<=1) cwp(tar);
                else {
                    for(int j=min(i,tar);j<=max(i,tar);j++)
                    {
                        if(j%2==ans.size()%2)
                        {
                            change(j);
                            break;
                        }
                    }
                }
            }
            else change(tar);
        }
    }
    print(ans.size());
    print(ans);
    //dbg(n,ans.size());
    assert(ans.size()<=n*n);
}
int main()
{
    cin.tie(nullptr)->sync_with_stdio(false);
    int T;
    cin>>T;
    while(T--) solve();
}

// 1 3 2
// 3 1 2
// 3 2 1
// 2 3 1
// 2 1 3
// 1 2 3


#include<bits/stdc++.h>
using namespace std;
const int N=505;
char pic[N][N];
int book[N][N];
const int mod=998244353;
vector<char> c[N*2];
int n,m;
struct node
{
    int x,y,d;
};
queue<node> q;
int check(int p)
{
    int b,r,d;
    b=r=d=0;
    for (int i=0;i<c[p].size();i++)
    {
        char x=c[p][i];
        //printf("%c \n",x);
        if (x=='.')
            d++;
        else if (x=='B')
            b++;
        else
            r++;
    }
    //printf("%d %d %d %d %d\n",p,b,r,d,c[p].size());
    if (r==0&&b==0)
        return 2;
    if (r!=0&&b!=0)
        return 0;
    return 1;
}
int main()
{

    scanf("%d%d\n",&n,&m);
    for (int i=0;i<n;i++)
        scanf("%s",pic[i]);

    q.push({0,0,0});
    int mx=0;
    while (!q.empty())
    {
        node t=q.front();
        q.pop();
        if (book[t.x][t.y])
            continue;
        book[t.x][t.y]=1;
        mx=max(mx,t.d);
        int x=t.x,y=t.y,d=t.d;
        //printf("%d %d %d %c\n",x,y,d,pic[x][y]);
        c[t.d].push_back(pic[t.x][t.y]);
        if (x+1<n&&!book[x+1][y])
            q.push({x+1,y,d+1});
        if (x-1>=0&&!book[x-1][y])
            q.push({x-1,y,d+1});
        if (y+1<m&&!book[x][y+1])
            q.push({x,y+1,d+1});
        if (y-1>=0&&!book[x][y-1])
            q.push({x,y-1,d+1});
    }
    long long ans=1;
    for (int i=0;i<=mx;i++)
    {
        ans=ans*check(i)%mod;
    }
    printf("%lld\n",ans);
}

#include <bits/stdc++.h>
#define int long long int
#define all(x) x.begin(), x.end()
#define send ios_base::sync_with_stdio(false);
#define help cin.tie(NULL)
#define inf (int)(1e17+1)
#define mod (int)(998244353)
#define N (int)(2e5+5)
#define fi first
#define se second
#define endl "\n"
#define double long double
#define eps (double)(1e-9)
#define sa cout<<"sa"<<endl
using namespace std;

namespace math{
	vector <int> fac(N,1);
	int exp(int a,int b){
		if(!b) return 1;
		if(b&1) return a*exp(a,b-1)%mod;
		int t=exp(a,b/2);
		return t*t%mod;
	}
	void fc(){for(int i=2;i<N;i++)fac[i]=i*fac[i-1]%mod;}
	int com(int n,int r){return (fac[n]*exp(fac[r]*fac[n-r]%mod,mod-2))%mod;}
	int per(int n,int r){return (fac[n]*exp(fac[n-r],mod-2))%mod;}
	vector <int> getpr(int x){
		vector <int> res;if(x!=1) res.push_back(x);
		for(int i=2;i*i<=x;i++){
			if(i*i==x) res.push_back(i);
			else if(x%i==0) res.push_back(i),res.push_back(x/i);;
	}return res;}
}using namespace math;

void solve(){
	int n,m;
	cin>>n>>m;
	vector <string> v(n);
	for(int i=0;i<n;i++) cin>>v[i];
	int ans=0;
	vector <int> path(m+n);
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if(v[i][j]=='B'&&path[i+j]==1) {cout<<0;return;}
			if(v[i][j]=='R'&&path[i+j]==2) {cout<<0;return;}
			if(v[i][j]=='B') path[i+j]=2;
			else if(v[i][j]=='R') path[i+j]=1;
		}
	}
	for(int i=0;i<n+m-1;i++) ans+=!path[i];
	cout<<exp(2,ans);
}

int32_t main(){
    send help;
    #ifdef LOCAL
  	freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout);
	#endif
	int t=1;
	//cin>>t;
	while(t--) solve();
	return 0;
}


/**
*    author:  Dooloper
*    created: 11.10.2020 23:54:26
**/

#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 t;
  cin >> t;
  while(t--){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    if(n%2){
      cout << "Second\n" << endl;
    }else{
      sort(a.begin(),a.end());
      bool win = false;
      for(int i = 0; i < n; i += 2) win |= a[i] != a[i+1];
      cout << (win ? "First": "Second") << "\n";
    }
  }
  return 0;
}

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

#ifdef LOCAL
#include "/debug.h"
#else
#define db(...)
#endif

#define all(v) v.begin(), v.end()
#define pb push_back
using ll = long long;
const int NAX = 2e5 + 5, MOD = 1000000007;

const string FIRST = "First";
const string SECOND = "Second";
auto solveCase(int n, const vector<int64_t> &a)
{
    // TODO: edit here
    if (n % 2)
        return SECOND;
    map<int, int> cnt;
    for (auto &x : a)
        cnt[x]++;
    for (auto &x : cnt)
    {
        if(x.second % 2)
            return FIRST;
    }
    return SECOND;

}

// generated by oj-template v4.7.2 (https://github.com/online-judge-tools/template-generator)
int main()
{
#ifndef LOCAL
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
#endif
    constexpr char endl = '\n';
    // failed to analyze input format
    // TODO: edit here
    int t, n;
    cin >> t;
    for (size_t i = 0; i < t; i++)
    {
        cin >> n;
        vector<int64_t> a(n);
        for (int i = 0; i < n; ++i)
            cin >> a[i];
        auto ans = solveCase(n, a);
        cout << ans << '\n';
    }

    return 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>

#define ll long long
#define ff first
#define ss second
#define pi pair<int, int>

const int MX=300000;
const ll mod=1e9+7;

int dp[100];

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

    int n; cin>>n;

    set<int>st;
    set<int>::iterator it;

    for(int i=1; i<=min(n-2, 1666); i++) st.insert(6*i);

    for(int i=1; ; i++)
    {
        if(st.size()==n-1 || 10*i>10000) break;
        st.insert(10*i);
    }

    for(int i=1; ; i++)
    {
        if(st.size()==n) break;
        st.insert(15*i);
    }

    for(it=st.begin(); it!=st.end(); it++) cout<<*(it)<<' ';
    cout<<endl;

    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
const double pi = acos(-1);
const double eps = 1e-8;
const ll mod = 1e9 + 7;
const ull base = 131;
const ull mod1 = 1e9 + 9;
const ull mod2 = 1610612741;

const int maxn = 5e5 + 10;
int x;

int main()
{
    cin >> x;
    cout << 100-x%100;
    return 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 fast { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
    #define pb push_back
    #define ll long long

    #define vi vector<int>
    #define vll vector<long long>
    #define mp make_pair
    #define infi INT_MAX
    #define infl LONG_LONG_MAX
    #define infd LDBL_MAX
    #define f(i,a,b) for(ll i=a;i<b;i++)
    #define ff first
    #define ss second
    #define pll pair<ll,ll>
    #define endl "\n"
    #define ALL(v) v.begin(),v.end()
    #define nl cout<<"\n";
    #define pr(x) cout<<x;
    #define pr1(x) cout<<x<<" ";
    #define pr2(x,y) cout<<x<<" "<<y;
    #define deb printf("*****************************\n");
    #define idk printf("idk idk ! \n");
    #define hi printf("hi ! \n");
    #define bye printf("bye bye ! \n");
    #define o_set(ll) tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
    #define number_of_set_bits  __builtin_popcountll
    #define ld long double
    //template<typename T>
    //#define o_set(T) tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>
    //member functions :
    //1. order_of_key(k) : number of elements strictly lesser than k
    //2. find_by_order(k) : k-th element in the set

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

        ll ntc=1;
     //   cin>>ntc;

        f(ks,1,ntc+1)
        {
          //cout<<"Case #"<<i<<": ";
         ll n; cin>>n;

         map<string,int> a,b;
         a.clear(), b.clear();
         bool ans = false; string print = "";
         f(i,0,n){
             string s; cin>>s;
            if(s[0] == '!'){
                string p = s.substr(1);
                if(a.count(p)) {
                    ans = true;
                    print = p;
                    break;
                }
                b[p]++;
            } else {
                if(b.count(s)){
                    ans = true;
                    print = s;
                    break;
                }
                a[s]++;
            }
         }
         if(ans) cout<<print<<endl;
         else cout<<"satisfiable"<<endl;
        }

        return 0;
    }

#include <bits/stdc++.h>

using namespace std;

long long int in[200007];
long long int ou[200007];
char s[27];

int main()
{
    long long int i, n, j, pin=0, pou=0, x, y;
    cin >> n;
    for(i=0; i<n; i++){
        cin >> s;
        x=1;
        y=0;
        for(j=0; j<strlen(s); j++){
            if(s[j]!='!'){
                y+=(s[j]-'a'+1)*x;
                x*=30;
            }
        }
        if(s[0]=='!'){
            ou[pou]=y;
            pou++;
        }
        else{
            in[pin]=y;
            pin++;
        }
    }
    sort(in, in+pin);
    sort(ou, ou+pou);
    for(x=0, y=0; (x<pin)&&(y<pou);){
        if(in[x]==ou[y]){
            break;
        }
        if(x==pin-1){
            y++;
            continue;
        }
        if(y==pou-1){
            x++;
            continue;
        }
        if(in[x]<ou[y]){
            x++;
        }
        else{
            y++;
        }
    }
    if(in[x]==ou[y]){
        while(in[x]){
            cout << (char)(in[x]%30-1+'a');
            in[x]/=30;
        }
        cout << '\n';
    }
    else{
        cout << "satisfiable\n";
    }
    return 0;
}


#pragma region Macros
// #pragma GCC target("avx2")
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define pb push_back
#define eb emplace_back
using namespace std;
using P = pair<int, int>;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main() {
  int n, m, q;
  cin >> n >> m >> q;
  vector<int> W(n), V(n), X(m);
  rep(i, n) cin >> W[i] >> V[i];
  rep(i, m) cin >> X[i];
  rep(i, q){
    int a, b;
    cin >> a >> b;
    a--;
    vector<int> X2;
    rep(j, m){
      if (j < a || b <= j){
        X2.push_back(X[j]);
      }
    }
    sort(ALL(X2));
    int k = X2.size();
    int ans = 0;
    vector<bool> used(n, false);
    rep(j, k){
      priority_queue<P> pq;
      rep(s, n){
        if(X2[j] >= W[s] & !used[s]){
          pq.push({V[s], s});
        }
      }
      if (!pq.empty()){
        ans += pq.top().first;
        used[pq.top().second] = true;
        pq.pop();
      }
    }
    cout << ans << endl;
  }
}

#include <bits/stdc++.h>

using namespace std;

#define int			long long
#define endl		"\n"
#define ff			first
#define ss			second
#define mod			1000000007
#define inf			1e18
#define ninf		(-1e18)
#define IOS			ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define debug(x)	cout << #x << " = " << x << endl;

void solve() {
	int n, m, q;
	cin >> n >> m >> q;
	vector<pair<int, int>> bag(n);
	vector<int> box(m);

	for (int i = 0 ; i < n ; i++) {
		cin >> bag[i].ff >> bag[i].ss;
	}

	for (int i = 0; i < m; i++) {
		cin >> box[i];
	}

	while (q--) {
		int l, r;
		cin >> l >> r;

		l--, r--;
		int ans = 0;

		vector<int> newBox;
		for (int i = 0; i < l; i++)
			newBox.push_back(box[i]);

		for (int i = r + 1; i < m; i++)
			newBox.push_back(box[i]);

		sort(newBox.begin(), newBox.end());
		vector<bool> vis(n, false);

		for (int cap : newBox) {
			int mx = 0;
			int ind = -1;
			for (int i = 0; i < n; i++) {
				if (vis[i])
					continue;

				if (bag[i].ff <= cap) {
					if (bag[i].ss > mx) {
						mx = bag[i].ss;
						ind = i;
					}
				}
			}
			if (ind != -1) {
				vis[ind] = 1;
				ans += mx;
			}
		}

		cout << ans << endl;
	}

	return;
}

int32_t main() {

	IOS;

	int t = 1;
	// cin >> t;

	while (t--) {
		solve();
	}

	return 0;
}


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

int main(){

    int v[109];
    for(int i=0;i<4;i++){
        cin>>v[i];
    }
    sort(v,v+4);
    cout<<v[0]<<endl;
    return 0;
}

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> order_set;
typedef long long  ll ;

#define     rep(i, begin, end)          for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define     what_is(x)                  cout << #x << " is " << x << endl;
// #define     endl                        '\n'
#define     fi                          first
#define     sec                         second
#define     pb                          push_back
#define     vi                          vector<int>
#define     vii                         vector<pair<int,int>>
#define 	fio 						ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define 	sz(x) 						(int)x.size()
#define 	all(x) 						begin(x), end(x)
void solve(){
    int a1,a2,a3,a4;
    cin>>a1>>a2>>a3>>a4;
    cout<<min(min(min(a1,a2),a3),a4)<<endl;
    return;

}
int main(){
    fio;
    int test;
    // cin>>test;
    test=1;
    while(test--){
        solve();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll s2[100];
ll n;
ll qpow(ll a,ll b)
{
    ll res=1;
    while(b)
    {
        if(b&1)
        {
            res=res*a;
        }
        a=a*a;
        b/=2;
    }
    return res;
}
ll f(ll i)
{
    ll res;
    if(i==0)
        res=1;
    else if(s2[i-1]==1)
          res=f(i-1);
    else
          res=qpow(2,i)+f(i-1);
    return res;
}
int main()
{
    //int n;
    cin>>n;
    string s;
    for(int i=0;i<n;i++)
    {
      cin>>s;
      if(s=="AND")
         s2[i]=1;
      else
         s2[i]=0;
    }
    ll ans=f(n);
    cout<<ans<<endl;
}

#include <bits/stdc++.h>

using namespace std;

void testcase(){
	int n;
	cin>>n;

	vector<int> v1(n), v2(n);

	for(int i = 0; i<n; i++){
		cin>>v1[i]>>v2[i];
	}

	int l1 = INT_MAX, l2 = INT_MAX;
	int p1, p2;
	for(int i = 0; i<n; i++){
		if(v1[i] < l1){
			l1 = v1[i];
			p1 = i;
		}
		if(v2[i] < l2){
			l2 = v2[i];
			p2 = i;
		}
	}

	if(p1!=p2){
		cout<<max(l1, l2);
	}
	else{

	int L1 = INT_MAX, L2 = INT_MAX;

		for(int i = 0; i<n; i++){
			if(i != p1){
				if(v1[i]< L1){
					L1 = v1[i];
				}
			}
			if(i != p2){
				if(v2[i] < L2){
					L2 = v2[i];
				}
			}
		}

		cout<<min({l1+l2, max(l1, L2), max(l2, L1)});

	}

}

int main(){
	ios_base::sync_with_stdio();
	cin.tie(NULL);

	testcase();
}


//libraries
#include<bits/stdc++.h>

//namespace
using namespace std;

//typedef
//typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<long long> vll;

//define
#define i(x) cin>>x;
#define il(X) ll X; cin>>X;
#define ol(X) cout<<X<<endl;
#define os(X) cout<<X<<" ";
#define inpv(a,n) vector<ll> a(n); for(ll i=0;i<n;i++){cin>>a[i];}
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define line cout<<"\n";
#define pbp(a,b) push_back(make_pair(a,b));
#define iniv(A,n,p) vector<ll> A(n,p);
#define vst(A) sort(A.begin(),A.end());
#define rvst(A) sort(A.rbegin(),A.rend());
#define forin(i,a,b) for(ll i=a;i<=b;i++)
#define forde(i,a,b) for(ll i=a;i>=b;i--)
#define fio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const long long inf=(long long)1e18;
long long MOD=(long long)(1e9+7);
ll mod=MOD;

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

ll modi(ll a)
{
    return binpow(a,mod-2,mod);
}
// ll n,m;
// vector<unordered_set<ll> > adj(100001);
// vector<unordered_set<ll> > adj_rev(100001);
// iniv(vis,100001,0);
// stack<ll> s;

// void dfs(ll x)
// {
//     if(vis[x]) return;
//     for(auto p:adj[x])
//     {
//         if(!vis[p]) dfs(p);
//     }
//     s.push(x);
// }

int main()
{
    #ifndef ONLINE_JUDGE
        freopen ("input.txt" , "r" , stdin);
        // freopen ("OUTPUT.txt" , "w" , stdout);
    #endif
    fio;
    ll tt=1; //cin>>tt;
    while(tt--)
    {
        il(n);
        inpv(a,n);
        vector<vll> adj(200001);
        iniv(vis,200001,0);
        ll ans=0;
        forin(i,0,n-1)
        {
            if(!vis[a[i]])
            {
                vis[a[i]]=1;
                ans++;
            }
        }
        ll l=0,r=n-1;
        while(l<r)
        {
            adj[a[l]].pb(a[r]);
            adj[a[r]].pb(a[l]);
            l++;
            r--;
        }
        forin(i,1,200000)
        {
            if(vis[i])
            {
                ans--;
                stack<ll> s;
                s.push(i);
                while(!s.empty())
                {
                    ll x=s.top();
                    s.pop();
                    if(!vis[x]) continue;
                    vis[x]=0;
                    for(auto p:adj[x])
                    {
                        if(vis[p])
                        {
                            s.push(p);
                        }
                    }
                }
            }
        }
        ol(ans);
    }
}

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define se second
#define fi first

typedef map<int, int> mi;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;

signed main() {
    #ifndef ONLINE_JUDGE
        freopen("inputf.txt", "r", stdin);
        freopen("outputf.txt", "w", stdout);
    #endif

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

    int h, w, x, y;
    cin >> h >> w >> x >> y;

    string s[h];

    for(int i=0; i<h; i++) {
        cin >> s[i];
    }

    x--;
    y--;
    int count=1;

    for(int i=x; i<h and s[i][y]!='#'; i++) {
        count++;
    }

    for(int i=x; i>=0 and s[i][y]!='#'; i--) {
        count++;
    }

    for(int i=y; i<w and s[x][i]!='#'; i++) {
        count++;
    }

    for(int i=y; i>=0 and s[x][i]!='#'; i--) {
        count ++;
    }

    cout << count-4;

    return 0;
}


#include<bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
using namespace std;
inline int read(){
	int res=0;
	bool zf=0;
	char c;
	while(((c=getchar())<'0'||c>'9')&&c!='-');
	if(c=='-')zf=1;
	else res=c-'0';
	while((c=getchar())>='0'&&c<='9')res=(res<<3)+(res<<1)+c-'0';
	if(zf)return -res;
	return res;
}
const int maxn=2e5+5,P=998244353;
int f[maxn],g[maxn];
int p[maxn],r;
int v[maxn],inv[25];
signed main(){
	int n=read(),m=read(),ans=1;
	inv[1]=1;
	for(register int i=2;i<=20;++i){
		inv[i]=1ll*inv[P%i]*(P-P/i)%P;
	}
	for(register int i=2,t;i<=m;++i){
		if(!v[i]){
			f[i]=n,g[i]=1,p[++r]=i;
		}
		for(register int j=1;j<=r&&(t=i*p[j])<=m;++j){
			v[t]=1;
			if(i%p[j]){
				f[t]=1ll*f[i]*n%P,g[t]=1;
			}
			else{
				f[t]=1ll*f[i]*(n+g[i])%P*inv[g[i]+1]%P,g[t]=g[i]+1;
				break;
			}
		}
		ans+=f[i];
		(ans>=P)&&(ans-=P);
	}
	printf("%d\n",ans);
	return 0;
}

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

const ll MOD = 998244353;
ll factorial[400005];
ll inverse[400005];
map<ll, ll> choosepre;

ll modpow(ll a, ll b) {
	if(b == 0) return 1 % MOD;
	ll half = modpow(a, b/2);
	ll res = half * half;
	res %= MOD;
	if(b % 2 == 1) {
		res *= a;
		res %= MOD;
	}
	return res;
}

ll choose(ll n, ll k) {
	// n! / k!(n-k)!
	// n * (n - 1) * (n - 2) * ... * (n - k + 1)
	ll ans = 1;
	for(int i = 0; i < k; i++) {
		ans *= (n - i);
		ans %= MOD;
	}
	ans *= inverse[k]; // inverse
	ans %= MOD;
	return ans;
}

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

	factorial[0] = 1;
	inverse[0] = 1;
	for(int i = 1; i < 400005; i++) {
		factorial[i] = factorial[i - 1] * i;
		factorial[i] %= MOD;
		inverse[i] = modpow(factorial[i], MOD - 2);
	}

	int N, M; cin >> N >> M;
	ll ans = 1;

	// huge overhead for choosing so precompute!!!!!!!
	for(int i = 0; i < 18; i++) {
		choosepre[i + N - 1] = choose(i + N - 1, N - 1);
	}

	for(int i = 2; i <= M; i++) {
		int num = i;
		ll expo_count = 0;
		ll curr_count = 1;
		double up = log(i) / log(2);
		ll l = 0, r = ceil(up), mid;
		while(l <= r) {
			mid = (l + r) / 2;
			ll power = modpow(2, mid);
			if(num % power == 0) {
				expo_count = max(expo_count, mid);
				l = mid + 1;
			}
			else {
				r = mid - 1;
			}
		}
		num /= modpow(2, expo_count);
		curr_count *= choosepre[expo_count + N - 1];
		curr_count %= MOD;

		for(int j = 3; j * j <= i; j += 2) {
			if(num % j == 0) {
				expo_count = 0;
				up = log(i) / log(j);
				l = 0, r = ceil(up);
				while(l <= r) {
					mid = (l + r) / 2;
					ll power = modpow(j, mid);
					if(num % power == 0) {
						expo_count = max(expo_count, mid);
						l = mid + 1;
					}
					else {
						r = mid - 1;
					}
				}
				curr_count *= choosepre[expo_count + N - 1];
				curr_count %= MOD;
				num /= modpow(j, expo_count);
			}
			//cout << i << ' ' << expo_count << '\n';
		}
		if(num > 2) { // still prime factor
			expo_count = 1;
			curr_count *= choosepre[expo_count + N - 1];
			curr_count %= MOD;
		}
		ans += curr_count;
		ans %= MOD;
	}
	cout << ans << '\n';
}


#include <bits/stdc++.h>
using namespace std;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(12), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
vector<int> leader;
int find(int x) {
    if (leader[x] == x) return x;
    return leader[x] = find(leader[x]);
}
int main() {
    int N, Q; cin >> N >> Q;
    vector<int> C(N); for (auto &c : C) cin >> c, c--;
    leader.resize(N);
    iota(begin(leader), end(leader), 0);
    vector<map<int, int>> A(N);
    for (int i = 0; i < A.size(); i++) {
        A[i][C[i]] = 1;
    }
    for (int i = 0; i < Q; i++) {
        int type; cin >> type;
        if (type == 1) {
            int a, b; cin >> a >> b; a--, b--;
            a = find(a), b = find(b);
            if (a != b) {
                if (A[a].size() < A[b].size()) swap(a, b);
                for (auto [c, n] : A[b]) {
                    A[a][c] += n;
                }
                A[b].clear();
                leader[b] = a;
            }
        } else {
            int x, y; cin >> x >> y; x--, y--;
            cout << A[find(x)][y] << '\n';
        }
    }
    return 0;
}

// Coder: @SumitRaut
#include <bits/stdc++.h>
#define speedup ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr),cout.precision(12)
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_map;
#define sbc __builtin_popcount
#define pb push_back
#define em emplace
#define emb emplace_back
#define ff first
#define ss second
#define ll long long
const ll mod = 1e9+7;

template<typename T> void smax(T& a, T b) { if(a<b) a=b; }
template<typename T> void smin(T& a, T b) { if(a>b) a=b; }
template<typename T> T pw(T a,T b) { T p=1,one=1; while(b) { if(b&one) p=p*a; a=a*a; b >>=1; } return p; }
template<typename T> T pwm(T a,T b,T md=mod) { T p=1,one=1; while(b) { if(b&one) p=p*a%md; a=a*a%md; b >>=1; } return p; }

template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for(auto& it:v)
    is>>it;
  return is;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (auto &it : v)
    os << it << ' ';
  return os;
}

#ifndef ONLINE_JUDGE
class Timer { chrono::high_resolution_clock::time_point start_t, end_t; public: Timer() { start_t=chrono::high_resolution_clock::now(); } ~Timer() { end_t = chrono::high_resolution_clock::now(); auto duration = chrono::duration_cast<chrono::milliseconds>(end_t-start_t); cerr<<"\nRunTime: "<<duration.count()<<"ms"<<'\n'; } };
void debug() { cerr << '\n'; }
template <typename T, typename... Args>
void debug(T print, Args... args) { cerr << ' ' << print; debug(args...); }
#define deb(...) cerr << "[" << #__VA_ARGS__ << "]" << " --> ", debug(__VA_ARGS__)
#else
#define deb(...) void(0)
#endif

class dsu {
public:
    vector<int> par;
    vector<map<int,int>>Mp;

    dsu() {}

    dsu(int n_,vector<int>& ar) : par(n_, -1) {
      Mp.resize(n_);
      for(int i=0;i<n_;++i) {
        Mp[i][ar[i]]=1;
      }
    }

    int find(int cur) {
        return par[cur] < 0 ? cur : (par[cur] = find(par[cur]));
    }

    bool Union(int a, int b) {
        a = find(a), b = find(b);
        if (a != b) {
            if (par[a] > par[b])
                swap(a, b);
            par[a] += par[b];
            for(auto& it:Mp[b]) {
              Mp[a][it.ff]+=it.ss;
            }
            Mp[b].clear();
            par[b] = a;
            return 1;
        }
        return 0;
    }

    bool isConnected(int a, int b) {
        return find(a) == find(b);
    }

    int size(int a) {
        return -par[find(a)];
    }

    int cnt(int a,int k) {
      return Mp[find(a)][k];
    }

};

void solve() {
  int n,q;
  cin>>n>>q;
  vector<int> que(n);
  cin>>que;
  dsu Ds(n,que);
  while(q--) {
    int op,x,y;
    cin>>op>>x>>y;
    if(op==1) {
      Ds.Union(x-1,y-1);
    } else {
      cout<<Ds.cnt(x-1,y)<<'\n';
    }
  }
}

int main() {
  #ifndef ONLINE_JUDGE
  Timer timer;
  #endif
  speedup;
  //int t; cin>>t; while(t--)
    solve();
}


#include<bits/stdc++.h>
using namespace std;
#define light ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define pb push_back
#define cases() ll t;cin>>t;while(t--)
#define all(c) c.begin(),c.end()
#define PI 3.14159265358979323846
const ll MAX = 2e6+5;
const ll INF = 1e18;
const ll MOD = 1e9+7;

vector<int> a[MAX];

int main()
{
    int i,j,k,l,p,q,x,y,n,m;
    cin >> n >> m;
    for(i=0;i<=n;i++)
        a[i].push_back(0);
    for(i=1;i<=n;i++)
    {
        cin >> l;
        a[l].push_back(i);
    }
    for(i=0;i<=n;i++)
        a[i].push_back(n+1);
    for(i=0;i<=n;i++)
    {
        for(j=0;j+1<a[i].size();j++)
        {
            if(a[i][j+1]-a[i][j]>m)
            {
                cout << i;
                return 0;
            }
        }
    }
}

#include<bits/stdc++.h>

#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define Bye return 0
#define CodeTyper main
#define ll int long long

using namespace std;
int const max_size = 1.5e6+1;
int freq[max_size];

void solve() {
    int n, m; cin>>n>>m;

    set<int> s;
    for (int i = 0; i<=max_size; i++)
        s.insert(i);

    memset(freq, 0, sizeof freq);

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

    for (int i = 0; i<m; i++){
        s.erase(a[i]);
        freq[a[i]]++;
    }

    int mex = min(*s.begin(), max_size);

    for (int i = m; i<n; i++){
        int l = i - m;

        freq[a[l]]--;
        freq[a[i]]++;

        s.erase(a[i]);

        if(freq[a[l]] <= 0)
            s.insert(a[l]);

        mex = min(mex, *(s.begin()));
    }

    cout<<mex<<endl;
}

int CodeTyper()
{
    boost;
    solve();
    Bye;
}

/*
    'Think FIRST, then CODE.'
    'May the CODE be with YOU.'
    'We are PROGRAMMERS, we have NO LIFE!'
*/


#include <bits/stdc++.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cmath>    // abs() for float, and fabs()
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

int main()
{
  // 入力
  int N, Q;
  cin >> N >> Q;

  vector<ll> A(N), K(Q), C(N);
  rep(i, N)
    cin >> A[i];

  rep(i, Q)
    cin >> K[i];

  rep(i, N)
    C[i] = A[i] - (i+1);

  rep(i, Q){
    ll vec_index = lower_bound(C.begin(), C.end(), K[i]) - C.begin();
    // cout << K[i] << ':' << vec_index << endl;
    if(vec_index == N){
      cout << A[N-1] + (K[i] - C[N-1]) << endl;
    }else{
      cout << (A[vec_index] - 1) - (C[vec_index] - K[i])  << endl;
    }
  }

}

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7;
int x,y;
map<int,int>mp,vis;
int func(int v){
    if(x>=v) return x-v;
    if(vis[v]) return mp[v];
    vis[v]=1;
    int ans=v-x;
    // if(v==1) {mp[v]=ans;return ans;}
    if(v%2==1){
        ans=min({ans,1+func(v+1),1+func(v-1)});
    }
    else{
        ans=min(ans,1+func(v/2));
    }
    mp[v]=ans;
    return ans;
}
void solve(){
    cin>>x>>y;
    cout<<func(y);
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int T=1;
    // cin>>T;
    while(T--){
        solve();
    }
}


#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>  using oset =
    tree<T, null_type, less<T>,
    rb_tree_tag, tree_order_statistics_node_update>;
#define odrkey order_of_key
#define fbodr find_by_order
#define ll long long
#define sq(a) ((a)*(a))
#define ull unsigned long long
#define all(x) (x).begin(),(x).end()
#define watch(x) cout << (#x) << " is " << (x) << endl
#define pi 3.1415926536
#define nwl cout << "\n"
#define sz 300000
ll Pow(ll a, ll b) {
    if(a==0) return 0LL;
	ll ans = 1;
	for (int i = 0; i < b; i++) {
		ans *= a;
	}
	return ans;
}
ll lcm(ll a, ll b) {
	return (a * b) / __gcd(a, b);
}
ll two_knights(ll  n) { // n>3
	ll ans = n * n * (n * n - 1);
	ans -= 8;
	ans -= 24;
	ans -= (n - 4) * 4 * 4;
	ans -= 16;
	ans -= (n - 4) * 6 * 4;
	ans -= (n - 4) * (n - 4) * 8;
	return ans / 2;
}
ll sm(ll n){
    return (n*(n+1))/2;
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    ll n;
    cin >> n;
    ll p=1;
    for(int i=2;i<sqrt(n)+1;(i>2 ? i+=2: i++)){
        ll cnt=0;
        while(n%i==0){
            cnt++;
            n/=i;
        }
        if(i%2==1)p*=(cnt+1);
    }
    if(n>1 && n%2) p*=2;
    cout << p*2 << endl;
}

#include <bits/stdc++.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define MOD 1000000007
typedef long long ll;
typedef pair<ll, ll> P;
int INF = 100000000;

int main()
{
  ll i, n, active = 0, ans = 0, n2, a, k;

  cin >> n;
  n2 = n * 2;
  auto solve = [&](ll k)
  {
    ll tmp;
    tmp =n2 / k - k + 1;

    if (abs(tmp) % 2 == 0)
      ans++;
  };

  for (ll i = 1; i * i <= n2; i++)
  {
    if (n2 % i !=0 )
      continue;

    ll j = n2 / i;

    solve(i);
    solve(j);
  }

  cout << ans << endl;

  return 0;
}


#include <iostream>//cout<<right で右揃え
#include <iomanip>//cout<<setw(数字) で空白による桁揃え
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <cstdlib>//abs()で整数絶対値
#include <cmath>//abs()かfabs()で少数絶対値
#include <functional>//sort第三引数greater<>()で降順
#include <map>

#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; i++)
#define ALL(x) (x).begin(),(x).end()
using namespace std;
using ll = long long int;

int main(){
    string s;cin>>s;
    vector<int> a(4);
    int ans = 0;
    rep(i,10000){
        int b = i;
        a[3] = b / 1000;
        b %= 1000;
        a[2] = b / 100;
        b %= 100;
        a[1] = b / 10;
        b %= 10;
        a[0] = b;
        bool flag = false;
        rep(i,4) if(s[a[i]]=='x') flag = true;
        if(flag) continue;

        vector<int> c(10);
        rep(i,4) c[a[i]]++;
        rep(i,10) if(s[i]=='o'&&c[i]==0) flag = true;
        if(flag) continue;

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

#include <bits/stdc++.h>
using namespace std;
//*************************MACROS*************************
#define endl "\n"
#define MOD = 1000000007

#define rep(i, k, n) for (i = k; i < n; ++i)
#define repr(i, k, n) for (i = n; i >= k; i--)
#define debug(x, y) cout << x << " : " << y << endl;
#define debugarr(arr, i, n) \
  for (i = 0; i < n; i++)   \
    cout << arr[i] << " ";  \
  cout << endl;
//*************************MACROS*************************

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  int n;
  cin>>n;
  vector<int> arr(n);
  int i;
  rep(i,0,n)
  cin>>arr[i];
  sort(arr.begin(),arr.end());
  rep(i,0,n)
    if(arr[i]!=i+1){
        cout<<"No"<<endl;
        return 0;
    }
  cout<<"Yes"<<endl;
  return 0;
}


#include <bits/stdc++.h>

void computeLPSArray(char* pat, int M, int* lps);

// Prints occurrences of txt[] in pat[]
int KMPSearch(char* pat, char* txt)
{
    int M = strlen(pat);
    int N = strlen(txt);

    // create lps[] that will hold the longest prefix suffix
    // values for pattern
    int lps[M];

    // Preprocess the pattern (calculate lps[] array)
    computeLPSArray(pat, M, lps);
    int gg=0;
    int i = 0; // index for txt[]
    int j = 0; // index for pat[]
    while (i < N) {
        if (pat[j] == txt[i]) {
            j++;
            i++;
        }

        if (j == M) {
            gg++;
            j = lps[j - 1];
        }

        // mismatch after j matches
        else if (i < N && pat[j] != txt[i]) {
            // Do not match lps[0..lps[j-1]] characters,
            // they will match anyway
            if (j != 0)
                j = lps[j - 1];
            else
                i = i + 1;
        }
    }
    return gg;
}

// Fills lps[] for given patttern pat[0..M-1]
void computeLPSArray(char* pat, int M, int* lps)
{
    // length of the previous longest prefix suffix
    int len = 0;

    lps[0] = 0; // lps[0] is always 0

    // the loop calculates lps[i] for i = 1 to M-1
    int i = 1;
    while (i < M) {
        if (pat[i] == pat[len]) {
            len++;
            lps[i] = len;
            i++;
        }
        else // (pat[i] != pat[len])
        {
            // This is tricky. Consider the example.
            // AAACAAAA and i = 7. The idea is similar
            // to search step.
            if (len != 0) {
                len = lps[len - 1];

                // Also, note that we do not increment
                // i here
            }
            else // if (len == 0)
            {
                lps[i] = 0;
                i++;
            }
        }
    }
}

// Driver program to test above function
int main()
{
    char txt[12];
    for(int i=0;i<12;i++){
    	scanf("%s",&txt[i]);
	}
    char pat[] = "ZONe";
    int ggg=KMPSearch(pat, txt);
    printf("%d",ggg);
    return 0;
}

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

int main(){
    string S;
    cin >> S ;
    int cnt = 0;
    for (int i = 0; i < S.size()-3; i++)
    {
        if(S.substr(i,4) =="ZONe"){
            cnt += 1;
        }
    }

    cout << cnt << endl;

}


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

inline long long read(){
    long long s = 0, w = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9'){
        if (ch == '-') w = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9'){
        s = s * 10 + ch - '0';
        ch = getchar();
    }
    return s * w;
}

int main(){
    int a = read(), b = read(), c = read();
    bool f = c;
    while(1){
        if(!f){
            if (a == 0){
                puts("Aoki");
                return 0;
            }
            a--;
        }
        else{
            if (b == 0){
                puts("Takahashi");
                return 0;
            }
            b--;
        }
        f ^= 1;
    }
    return 0;
}

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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int main(){
    int n, k, m; cin >> n >> k >> m;
    int c = n * m, sum = 0;
    REP(i, 0, n-1){
        int a; cin >> a;
        sum += a;
    }
    if(c - sum > k){
        cout << -1 << endl;
        return 0;
    }
    cout << max(c-sum, 0) << endl;
}


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

int main() {
    int n;
    cin>>n;
    cout<<n-1<<endl;
	return 0;
}

#pragma region Macros
#include <bits/stdc++.h>
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define ALL(v) (v).begin(), (v).end()
#define LLA(v) (v).rbegin(), (v).rend()
#define SZ(v) (int)(v).size()
#define INT(...)                                                               \
    int __VA_ARGS__;                                                           \
    read(__VA_ARGS__)
#define LL(...)                                                                \
    ll __VA_ARGS__;                                                            \
    read(__VA_ARGS__)
#define DOUBLE(...)                                                            \
    double __VA_ARGS__;                                                        \
    read(__VA_ARGS__)
#define CHAR(...)                                                              \
    char __VA_ARGS__;                                                          \
    read(__VA_ARGS__)
#define STRING(...)                                                            \
    string __VA_ARGS__;                                                        \
    read(__VA_ARGS__)
#define VEC(type, name, size)                                                  \
    vector<type> name(size);                                                   \
    read(name)
#define VEC2(type, name, height, width)                                        \
    vector<vector<type>> name(height, vector<type>(width));                    \
    read(name)
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
template <typename T> struct edge {
    int from, to;
    T cost;
    edge(int f, int t, T c) : from(f), to(t), cost(c) {}
};
template <typename T> using WGraph = vector<vector<edge<T>>>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;
const char newl = '\n';
template <class T> inline vector<T> make_vec(size_t a, T val) {
    return vector<T>(a, val);
}
template <class... Ts> inline auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec(ts...))>(a, make_vec(ts...));
}
void read() {}
template <class T> inline void read(T &a) { cin >> a; }
template <class T, class S> inline void read(pair<T, S> &p) {
    read(p.first), read(p.second);
}
template <class T> inline void read(vector<T> &v) {
    for(auto &&a : v)
        read(a);
}
template <class Head, class... Tail>
inline void read(Head &head, Tail &...tail) {
    read(head), read(tail...);
}
template <class T> void write(const T &a) { cout << a << '\n'; }
template <class T> void write(const vector<T> &a) {
    for(int i = 0; i < a.size(); i++)
        cout << a[i] << (i + 1 == a.size() ? '\n' : ' ');
}
template <class Head, class... Tail>
void write(const Head &head, const Tail &...tail) {
    cout << head << ' ';
    write(tail...);
}
template <class T> void writel(const T &a) { cout << a << '\n'; }
template <class T> void writel(const vector<T> &a) {
    for(int i = 0; i < a.size(); i++)
        cout << a[i] << '\n';
}
template <class Head, class... Tail>
void writel(const Head &head, const Tail &...tail) {
    cout << head << '\n';
    write(tail...);
}
template <class T> auto sum(const vector<T> &a) {
    return accumulate(ALL(a), T(0));
}
template <class T> auto min(const vector<T> &a) { return *min_element(ALL(a)); }
template <class T> auto max(const vector<T> &a) { return *max_element(ALL(a)); }
template <class T> inline void chmax(T &a, T b) { (a < b ? a = b : a); }
template <class T> inline void chmin(T &a, T b) { (a > b ? a = b : a); }
struct IO {
    IO() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        cout << fixed << setprecision(10);
    }
} io;
#pragma endregion

int main() {
    INT(n);
    write(n == 1 ? 0 : n - 1);
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double

class BIT{
    public:
    int size;
    vector<long long> tree;

    BIT(int n){
        size = n;
        tree = vector<long long>(n, 0);
        return;
    }

    void add(int n, long long a) {
        assert(n < size);
        int x = n;
        while (x < size){
            tree[x] += a;
            x |= x+1;
        }
        return;
    }

    long long getsum(int n) {
        assert(n < size);
        int x = n+1;
        long long sum = 0;
        while (x > 0) {
            sum += tree[x-1];
            x &= x-1;
        }
        return sum;
    }

};

int main() {
    int N;
    cin >> N;
    vector<ll> A(N), B(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        A[i] += i;
    }
    for (int i = 0; i < N; i++) {
        cin >> B[i];
        B[i] += i;
    }
    {
        vector<ll> C = A, D = B;
        sort(C.begin(), C.end());
        sort(D.begin(), D.end());
        if (C != D) {
            cout << -1 << endl;
            return 0;
        }
    }
    map<ll, ll> mp;
    set<ll> st;
    map<ll, ll> cnt;
    for (int i = 0; i < N; i++) {
        st.insert(A[i]);
        cnt[A[i]]++;
    }
    ll t = 0;
    for (ll n : st) {
        mp[n] = t;
        t += cnt[n];
    }
    map<ll, ll> cnt2;
    for (int i = 0; i < N; i++) {
        ll pre = A[i];
        A[i] = mp[A[i]]+cnt2[A[i]];
        cnt2[pre]++;
    }
    cnt2.clear();
    for (int i = 0; i < N; i++) {
        ll pre = B[i];
        B[i] = mp[B[i]]+cnt2[B[i]];
        cnt2[pre]++;
    }
    {
        vector<ll> tmp(N);
        for (int i = 0; i < N; i++) {
            tmp[B[i]] = i;
        }
        for (int i = 0; i < N; i++) {
            A[i] = tmp[A[i]];
        }
    }
    ll ans = 0;
    BIT bit(N);
    for (ll i = 0; i < N; i++) {
        ans += i - bit.getsum(A[i]);
        bit.add(A[i], 1);
    }
    cout << ans << endl;
    return 0;
}

// code by lynmisakura.wish to be accepted!
#include<bits/stdc++.h>
using namespace std;

#define REP(i,N) for(int i = 0;i < N;i++)
#define rng(i,a,b) for(int i = a;i < b;i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define mp make_pair
#define pb push_back
#define eb emplace_back

#define debug(arr) cout << #arr << " = " << arr << '\n'
#define debug2(a,b) cout<<"["<<#a<<","<<#b<<"] = "<<"["<<a<<","<<b<<"]\n"
#define debug3(a,b,c) cout<<"["<<#a<<","<<#b<<","<<#c<<"] = "<<"["<<a<<","<<b<<","<<c<<"]\n"
template<class T> ostream &operator << (ostream& out, const vector<T>& arr) {
    cout << "{"; for (int i = 0; i < arr.size(); i++)cout << (!i ? "" : ", ") << arr[i]; cout << "}";
    return out;
}
template<class T> ostream &operator << (ostream& out, const vector<vector<T> >& arr) {
    cout << "{\n"; for (auto& vec : arr)cout << "  " << vec << ",\n"; cout << "}";
    return out;
}
template<class S,class T> ostream &operator << (ostream& out, const pair<S,T>& p){
    cout << "{" << p.first << "," << p.second << "}" << '\n';
    return out;
}
template<class T> istream &operator >> (istream& in, vector<T>& arr) {
    for (auto& i : arr)cin >> i; return in;
}
template<class S,class T> istream &operator >> (istream& in,pair<S,T>& p){
    cin >> p.first >> p.second; return in;
}
template<class T> void debug_a(T *a , int N){
  cout << "debug array : {";
  for(int i = 0;i < N;i++){
    cout << *(a + i) << (i < N-1 ? ", " : "}\n");
  }
}
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;

template<class T> bool chmin(T& a,T b){ if(a > b){ a = b;return true;}else{return false;} }
template<class T> bool chmax(T& a,T b){ if(a < b){ a = b;return true;}else{return false;} }
template<class T> T __ceil(T a,T b){return (a + b - 1) / b;}

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

  string s;cin >> s;
  string t = "ZONe";

  int ans = 0;
  REP(i,9){
    ans += s.substr(i,4) == t;
  }

  cout << ans << endl;

}