#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <deque>
#include <set>
#include <limits>
#include <string>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <numeric>

using namespace std;

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

/* input & output */
#define IN(a) cin >> a
#define OUT(a) cout << a << endl
#define OUT_PREC(a, n) cout << fixed << setprecision(n) << a << endl

/* vector */
#define VEC(t, v, n, ini) vector<t> v(n, ini)
#define VEC2(t, v, m, n, ini) vector<vector<t>> v(m, vector<t>(n, ini))
#define VEC3(t, v, k, m, n, ini) vector<vector<vector<t>>> v(k, vector<vector<t>>(m, vector<t>(n, ini)))

/* bit */
#define IS_TRUE(bit, i) (bit & (1 << i))   // bitのi成分
#define FLAG_ON(bit, i) (bit｜(1 << i))    // bitのi成分をtrueに
#define FLAG_OFF(bit, i) (bit & ~(1 << i)) // bitのi成分をfalseに
#define ALL_TRUE(n) (1 << n)               // 2^n
#define CMPSET(bit, s) (bit ^ s)           // sのbitに対する補集合
#define INCLUDES(a, b) ((a & b) == b)      // aはbを含むか

#define INF 1e12

ll solve()
{
    int n, m;
    cin >> n >> m;
    vector<ll> a(n), dp(n, INF);
    FOR(i, 0, n)
    {
        IN(a[i]);
    }

    vector<vector<int>> t(n, vector<int>{});

    FOR(i, 0, m)
    {
        int x, y;
        cin >> x >> y;
        --x;
        --y;
        t[y].emplace_back(x);
    }

    FOR(i, 0, n)
    {
        for (int j : t[i])
        {
            dp[i] = min(min(dp[i], dp[j]), a[j]);
        }
    }

    ll ans = -INF;

    FOR(i, 0, n)
    {
        if (a[i] - dp[i] > ans)
            ans = a[i] - dp[i];
    }

    return ans;
}

int main()
{
    /* solve */
    OUT(solve());
    system("pause");
}

#include <algorithm>
#include <array>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <utility>
#include <vector>
#include <stack>
using namespace std;
using ll = long long int;
// fast IO
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
////////// 	Template structure for debugging
#define tr(...) trace(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void trace(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void trace(const char* names, Arg1&& arg1, Args&&... args){
  const char *comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  trace(comma + 1, args...);
}
#define print(...) pr(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void pr(const char* name, Arg1&& arg1){
  cout << arg1 << endl;
}
template <typename Arg1, typename... Args>
void pr(const char* names, Arg1&& arg1, Args&&... args){
  const char *comma = strchr(names + 1, ',');
  cout << arg1 << " ";
  pr(comma + 1, args...);
}
void printV(vector<int> &arr)
{
	cout << "Vector : ";
	for(int i=0;i<arr.size();i++)
		cout << arr[i] << " \n"[ i == arr.size()-1 ];
}
void printV(vector<long long> &arr)
{
	cout << "Vector : ";
	for(int i=0;i<arr.size();i++)
		cout << arr[i] << " \n"[ i == arr.size()-1 ];
}
void printA(int arr[], int n) {
  cout << "Array : ";
  for (int i = 0; i < n; i++)
	cout << arr[i] << " \n"[i == n - 1];
}

/////////////////////////////////////////////////////////////////////////////
////////////////////// DO NOT TOUCH BEFORE THIS LINE ////////////////////////
/////////////////////////////////////////////////////////////////////////////
const ll INF = 1e15;
ll N, M, ans = -INF;
vector<ll> C, vis;
vector<vector<ll>> G;

ll dfs(ll curr, ll mn){
	vis[curr] = -INF;
	for(auto child: G[curr]){
		if(vis[child] == 0){
			vis[curr] = max(vis[curr], dfs(child, min(C[child], mn)));
		}
		else vis[curr] = max(vis[curr], vis[child]);
	}

	if(!G[curr].empty())ans = max(ans, vis[curr] - mn);
	//tr(curr, vis[curr], mn);
	vis[curr] = max(vis[curr], C[curr]);
	return vis[curr];
}
void solve(int tc = 1){
	cin >> N >> M;
	C.resize(N);
	vis.resize(N, 0);
	G.resize(N);
	for(auto &a: C)cin >> a;
	for(int i=0; i<M; i++){
		int a, b;
		cin >> a >> b;
		a--, b--;
		G[a].push_back(b);
	}
	for(int i=0; i<N; i++){
		if(vis[i])continue;
		dfs(i, C[i]);
	}
	cout << ans << endl;
}

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


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

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

    string temp="ZONe";
    int d=0;
    for(int i=0;i<s.size();++i){
        if(s[i]==temp[0]){
            int f=0;
            for(int j=0;j<temp.size();++j){
                if(s[i+j]!=temp[j]){
                    f=1;break;
                }
            }
            if(f==0)d++;
        }
    }
    cout<<d<<endl;
}

#include <bits/stdc++.h>
using namespace std;
char s[200005];
int cnt[10];
int n;
bool dfs(int i, int rem){
    if(i == n+1){
        if(rem == 0) return 1;
        return 0;
    }
    for(int j=1;j<=9;j++){
        if(cnt[j] > 0){
            cnt[j]--;
            if(dfs(i+1, (rem*10+j)%8)) return 1;
            cnt[j]++;
        }
    }
    return 0;
}
int main(){
    scanf("%s", s+1);
    n = strlen(s+1);
    for(int i=1;i<=n;i++) cnt[s[i]-'0']++;
    n = min(n, 3);
    bool ok = dfs(1, 0);
    if(ok) printf("Yes\n");
    else printf("No\n");
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ldb double
template<typename T>void ckmn(T&a,T b){a=min(a,b);}
template<typename T>void ckmx(T&a,T b){a=max(a,b);}
void rd(int&x){scanf("%i",&x);}
void rd(ll&x){scanf("%lld",&x);}
void rd(char*x){scanf("%s",x);}
void rd(ldb&x){scanf("%lf",&x);}
void rd(string&x){scanf("%s",&x);}
template<typename T1,typename T2>void rd(pair<T1,T2>&x){rd(x.first);rd(x.second);}
template<typename T>void rd(vector<T>&x){for(T&i:x)rd(i);}
template<typename T,typename...A>void rd(T&x,A&...args){rd(x);rd(args...);}
template<typename T>void rd(){T x;rd(x);return x;}
int ri(){int x;rd(x);return x;}
template<typename T>vector<T> rv(int n){vector<T> x(n);rd(x);return x;}
template<typename T>void ra(T a[],int n,int st=1){for(int i=0;i<n;++i)rd(a[st+i]);}
template<typename T1,typename T2>void ra(T1 a[],T2 b[],int n,int st=1){for(int i=0;i<n;++i)rd(a[st+i]),rd(b[st+i]);}
template<typename T1,typename T2,typename T3>void ra(T1 a[],T2 b[],T3 c[],int n,int st=1){for(int i=0;i<n;++i)rd(a[st+i]),rd(b[st+i]),rd(c[st+i]);}
void re(vector<int> E[],int m,bool dir=0){for(int i=0,u,v;i<m;++i){rd(u,v);E[u].pb(v);if(!dir)E[v].pb(u);}}
template<typename T>void re(vector<pair<int,T>> E[],int m,bool dir=0){for(int i=0,u,v;i<m;++i){T w;rd(u,v,w);E[u].pb({v,w});if(!dir)E[v].pb({u,w});}}

const int inf=1e9+7;
string atc="atcoder";
int Solve(string str,int pos){
	if(str.size()<=pos)return inf;
	int ans=0;
	for(int i=0;i<pos;i++){
		int o=-1;
		for(int j=i;j<str.size();j++){
			if(str[j]==atc[i]){
				o=j;
				break;
			}
		}
		if(o==-1)return inf;
		for(int j=o;j>i;j--){
			ans++;
			swap(str[j],str[j-1]);
		}
	}
	int o=-1;
	for(int j=pos;j<str.size();j++){
		if(str[j]>atc[pos]){
			o=j;
			break;
		}
	}
	if(o==-1)return inf;
	ans+=o-pos;
	return ans;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t;cin>>t;
	for(;t--;){
		string str;cin>>str;
		int ans=inf;
		for(int i=0;i<=atc.size();i++)ckmn(ans,Solve(str,i));
		if(ans==inf)cout<<"-1\n";
		else cout<<ans<<"\n";
	}
	return 0;
}

#include <bits/stdc++.h>
#define rep(i, N) for(int i = 0; i < (int)N; i++)
#define rep1(i, N) for(int i = 0; i <= (int)N; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
const int INF = 101010;

int main() {
    int q, m, ans = 0;
    const string t = "atcoder";
    cin >> q;
    while(q--){
        string s;
        cin >> s;
        if (s > t) {
            puts("0");
            continue;
        }

        int ans = INF;
        rep(i,s.size()){
            if (s[i] > 'a') {
                if (s[i] > 't') {
                    ans = i-1;
                }else{
                    ans = i;
                }
                break;
            }
        }
        if(ans == INF) puts("-1");
        else printf("%d\n", ans);
    }
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=(int)(x);i<(int)(y);i++)
#define print(A,x,n) {rep(I,0,n){cout<<(I ? " ":"")<<A[I]x;}cout<<endl;}
#define pprint(A,y,m,n) {rep(J,0,m){print(A[J],y,n);}}
const long mod=998244353;
const int siz=3e5;
const int inf=1e6;
int main(){
	int N; cin>>N;
	int w, sum = 0;
	long dp[N+1][10001] = {}; dp[0][0] = 1;
	rep(i,1,N+1){
		cin>>w;
		sum += w;
        for(int j = i; j > 0; j--){
            rep(k,w,10001) (dp[j][k] += dp[j-1][k-w]) %= mod;
        }
	}
	if(sum % 2 == 1){
		cout<<0<<endl;
		return 0;
	}
	long ans = 0;
	long fact[N+1]; fact[0] = 1;
	rep(i,1,N+1) fact[i] = fact[i-1] * i % mod;
	rep(i,1,N+1){
		long k = fact[i] * fact[N-i] % mod;
		(ans += dp[i][sum/2] * k % mod) %= mod;
	}
	cout<<ans<<endl;
}

/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Pine1999
 */

#include <bits/stdc++.h>

template<int mod>
class Modular {
private:
    int x;
public:
    Modular() : x(0) {}
    Modular(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    Modular &operator+=(const Modular& p) { if ((x += p.x) >= mod) x -= mod; return *this; }
    Modular &operator-=(const Modular& p) { if ((x -= p.x) < 0) x += mod; return *this; }
    Modular &operator*=(const Modular& p) { x = (int) (1LL * x * p.x % mod); return *this; }
    Modular &operator/=(const Modular& p) { *this *= p.Inverse(); return *this; }
    Modular operator-() const { return Modular(-x); }
    Modular operator+(const Modular& p) { return Modular(*this) += p; }
    Modular operator-(const Modular& p) { return Modular(*this) -= p; }
    Modular operator*(const Modular& p) { return Modular(*this) *= p; }
    Modular operator/(const Modular& p) { return Modular(*this) /= p; }
    bool operator==(const Modular& p) { return x == p.x; }
    bool operator!=(const Modular& p) { return x != p.x; }
    friend std::ostream& operator<<(std::ostream& out, const Modular& p) { return out << p.x; }
    friend std::istream& operator>>(std::istream& in, Modular& a) {
        long long t;
        in >> t;
        a = Modular<mod>(t);
        return in;
    }
    Modular Inverse() const {
        int a = x, m = mod, u = 1, v = 0, t;
        while (m > 0) {
            t = a / m;
            std::swap(a -= t * m, m);
            std::swap(u -= t * v, v);
        }
        return Modular(u);
    }
};

const int mod = 998244353;
using mint = Modular<mod>;

class Task {
    std::vector<mint> fact;
    void init(int n) {
        fact.resize(n + 1);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
    }
public:
    void solve(std::istream& in, std::ostream& out) {
        using namespace std;
        int n; in >> n;
        vector<int> w(n);
        for (int i = 0; i < n; ++i) in >> w[i];
        int sum = accumulate(w.begin(), w.end(), 0);
        if (sum & 1) {
            out << 0 << '\n';
            return;
        }
        const int MAX = (int) 1e5 + 50;
        vector<vector<mint>> dp(n + 1, vector<mint> (MAX));
        dp[0][0] = 1;
        for (int i = 0; i < n; ++i) {
            for (int j = n; j >= 1; --j) {
                for (int k = j * 100; k >= w[i]; --k) {
                    dp[j][k] += dp[j - 1][k - w[i]];
                }
            }
        }
        init(n);
        mint ans = 0;
        for (int i = 1; i < n; ++i) {
            ans += dp[i][sum / 2] * fact[i] * fact[n - i];
        }
        out << ans << '\n';
    }
};

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    Task solver;
    solver.solve(std::cin, std::cout);
    return 0;
}


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

int main(){
    int n;
    string s;
    cin>>n>>s;
    while(s.size()>1){
        while(n%3!=1){
            int k=1;
            string next;
            rep(i,s.size()-k){
                if((s[i]=='B'&&s[i+k]=='B')||(s[i]=='R'&&s[i+k]=='W')||(s[i]=='W'&&s[i+k]=='R')){
                    next+='B';
                }
                else if((s[i]=='R'&&s[i+k]=='R')||(s[i]=='B'&&s[i+k]=='W')||(s[i]=='W'&&s[i+k]=='B')){
                    next+='R';
                }else{
                    next+='W';
                }
            }
            s.erase();
            s=next;
            n=s.size();
            //cout<<s<<endl;
        }
        if(s.size()==1) break;
        while(n%3==1){
            int k=3;
            string next;
            for(int i=0;i<n;i+=3){
                next+=s[i];
            }
            s.erase();
            s=next;
            n=s.size();
            //cout<<s<<endl;
        }
    }
    cout<<s<<endl;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define PI acos(-1)
#define vi vector<int>
const int kMod = 998244353;
const int kInf = (~(1<<31)) / 2 - 500;
const ll kInfL = (~(1LL<<63)) / 2 - 2000;

int main() {
  ll B, C;
  cin >> B >> C;
  pair<ll, ll> plus = {B, B}, minus = {-B, -B};
  // plus
  plus.second = min(plus.second, B - C / 2);
  plus.first = max(plus.first, B + (C - 2) / 2);
  minus.second = min(minus.second, -B - (C - 1) / 2);
  minus.first = max(minus.first, -B + (C - 1) / 2);
  ll ans = 0;
  if (plus.second <= minus.first) {
    ans = max(plus.first, minus.first) - min(plus.second, minus.second) + 1;
  } else {
    ans += plus.first - plus.second + 1;
    ans += minus.first - minus.second + 1;
  }
  cout << ans << endl;
}


//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
#define eps 1e-8
//#define eq(x,y) (fabs((x)-(y)) < eps)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
const int mod= 1e9+7;
long double pi = acosl(-1);
//const ll infl = LLONG_MAX;
const int inf = 1e9+2;
const int nmax = 4e5+5;
//const int MAXLG = log2(nmax)+1;
//mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ost;

typedef long long LL;

struct Edge {
    int u, v;
    LL cap, flow;
    Edge() {}
    Edge(int u, int v, LL cap): u(u), v(v), cap(cap), flow(0) {}
};

struct Dinic {
    int N;
    vector<Edge> edges;
    vector<vector<int>> adj;
    vector<int> d, pt;

    Dinic(int N): N(N), edges(0), adj(N), d(N), pt(N) {}

    void AddEdge(int u, int v, LL cap) {
        if (u != v) {
            edges.emplace_back(u, v, cap);
            adj[u].emplace_back(edges.size() - 1);
            edges.emplace_back(v, u, 0);
            adj[v].emplace_back(edges.size() - 1);
        }
    }

    bool BFS(int S, int T) {
        queue<int> q({S});
        fill(d.begin(), d.end(), N + 1);
        d[S] = 0;
        while(!q.empty()) {
            int u = q.front(); q.pop();
            if (u == T) break;
            for (int k: adj[u]) {
                Edge &e = edges[k];
                if (e.flow < e.cap && d[e.v] > d[e.u] + 1) {
                    d[e.v] = d[e.u] + 1;
                    q.emplace(e.v);
                }
            }
        }
        return d[T] != N + 1;
    }

    LL DFS(int u, int T, LL flow = -1) {
        if (u == T || flow == 0) return flow;
        for (int &i = pt[u]; i < adj[u].size(); ++i) {
            Edge &e = edges[adj[u][i]];
            Edge &oe = edges[adj[u][i]^1];
            if (d[e.v] == d[e.u] + 1) {
                LL amt = e.cap - e.flow;
                if (flow != -1 && amt > flow) amt = flow;
                if (LL pushed = DFS(e.v, T, amt)) {
                    e.flow += pushed;
                    oe.flow -= pushed;
                    return pushed;
                }
            }
        }
        return 0;
    }

    LL MaxFlow(int S, int T) {
        LL total = 0;
        while (BFS(S, T)) {
            fill(pt.begin(), pt.end(), 0);
            while (LL flow = DFS(S, T))
                total += flow;
        }
        return total;
    }
};

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

    int n;
    cin>>n;
    vector<pii>v(n);
    for(pii &x : v) cin>>x.first>>x.second;
    vector<int>shob;
    for(pii z : v) shob.push_back(z.first), shob.push_back(z.second);
    sort(shob.begin(), shob.end());
    shob.erase(unique(shob.begin(), shob.end()), shob.end());
    for(pii &z : v){
        z.first = lower_bound(shob.begin(), shob.end(), z.first) - shob.begin();
        z.second = lower_bound(shob.begin(), shob.end(), z.second) - shob.begin();
    }
    int sz = shob.size();
    int N = sz + n + 2;
    int sorc = N-2, sink = N-1;
    Dinic flu(N);
    for(int i=0; i<n; i++){
        flu.AddEdge(sorc, sz+i, 1);
        flu.AddEdge(sz+i, v[i].first, 1);
        flu.AddEdge(sz+i, v[i].second, 1);
    }
    for(int i=0; i<sz; i++){
        flu.AddEdge(i, sink, 1);
    }
    cout<<flu.MaxFlow(sorc, sink)<<endl;
}
/*
*/

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

#ifdef Dhiraj
    #include "D:/dhiraj/Programming/debug.h"
#else
    #define d(...) 11
    #define cerr if(0) cerr
#endif

#define ll long long int
#define endl '\n'

template <typename T, typename U>
inline istream& operator >> (istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}
template <typename T>
inline istream& operator >> (istream& in, vector<T>& v) {
    for(T& x : v) in >> x;
    return in;
}

const ll MX = 4e5 + 5;

ll n, m;
vector<vector<ll>> g;
vector<ll> vis;

void clearAll()
{
    vis.assign(MX, 0);
    g.assign(MX, vector<ll>());
}

ll cc, edges;
void dfs(ll u)
{
    if(vis[u] || g[u].empty()) return;
    cc++;
    vis[u] = 1;
    for(ll v : g[u]) {
        edges++;
        dfs(v);
    }
}

void solve(int &tc)
{
    cin >> n;
    clearAll();

    for(ll i = 0; i < n; i++)
    {
        ll x, y;
        cin >> x >> y;
        g[x].emplace_back(y);
        g[y].emplace_back(x);
    }

    ll ans = 0;
    for(ll i = 0; i < MX; i++)
    {
        cc = edges = 0;
        dfs(i);
        edges /= 2;
        ans += min(cc, edges);
    }
    cout << ans << endl;
}

int main()
{
    #ifdef Dhiraj
        freopen("D:/dhiraj/Programming/i1.txt", "r", stdin);
        freopen("D:/dhiraj/Programming/o1.txt", "w", stdout);
        // freopen("D:/dhiraj/Programming/e1.txt", "w", stderr);
    #endif

    ios::sync_with_stdio(false);
    cin.tie(0);

    int tc = 1;
    for(int i = 1; i <= tc; i++) {
        cerr << "Case #" << i << "\n";
        solve(i);
    }
    return 0;
}


#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const ll MOD = 998244353;
const double PI = 3.141592653589793238;
int main(){
  auto start = chrono::system_clock::now();
  ll si, sj;
  cin >> si >> sj;
  ll nowi = si, nowj = sj;
  vector<ll> t(2500);
  for (ll i = 0; i < 50; ++i) {
    for (ll j = 0; j < 50; ++j) {
      cin >> t[50 * i + j];
    }
  }

  vector<ll> p(2500);
  for (ll i = 0; i < 50; ++i) for (ll j = 0; j < 50; ++j) cin >> p[50 * i + j];

  string lastans = "";
  ll lastpnt = 0;
  map<ll, bool> used;
  string ans = "";
  while (true) {
    ll id = 50 * nowi + nowj;
    ll maxi = -1;
    used[t[id]] = true;
    char togo = ' ';
    if (nowj != 0 && !used[t[id - 1]] && maxi < p[id - 1]) {
      togo = 'L';
      maxi = p[id - 1];
    }
    if (nowj != 49 && !used[t[id + 1]] && maxi < p[id + 1]) {
      togo = 'R';
      maxi = p[id + 1];
    }
    if (nowi != 0 && !used[t[id - 50]] && maxi < p[id - 50]) {
      togo = 'U';
      maxi = p[id - 50];
    }
    if (nowi != 49 && !used[t[id + 50]] && maxi < p[id + 50]) {
      togo = 'D';
      maxi = p[id + 50];
    }
    if(togo != ' ')ans += togo;
    switch (togo)
    {
    case 'L': --nowj;
      break;
    case 'R': ++nowj;
      break;
    case 'U': --nowi;
      break;
    case 'D': ++nowi;
      break;
    default:
      goto exit;
    }
  }
exit:;
  nowi = si, nowj = sj;
  lastans = ans;
  ll now = 50 * nowi + nowj;
  lastpnt += p[now];
  for (ll i = 0; i < ans.size(); ++i) {
    switch (ans[i]) {
    case 'L': --nowj;
      break;
    case 'R': ++nowj;
      break;
    case 'U': --nowi;
      break;
    case 'D': ++nowi;
      break;
    }
    lastpnt += p[now];
  }

  string sample = "LRUD";
  random_device rnd;
  mt19937 mt(rnd());
  uniform_int_distribution<> cha(0, 3), rand(1,1000);
  auto dur = chrono::system_clock::now() - start;

  while (chrono::duration_cast<std::chrono::milliseconds>(dur).count() < 1980) {
    ans = lastans;

    uniform_int_distribution<> change(0, ans.size());
    ll ch = change(mt), at = cha(mt), r = rand(mt);
    if (ch == ans.size()) ans.push_back(sample[at]);
    else ans[ch] = sample[at];

    nowi = si, nowj = sj;
    now = 50 * nowi + nowj;
    map<ll, bool> used;
    used[t[now]] = true;
    ll pnt = p[now];
    for (ll i = 0; i < ans.size(); ++i) {
      switch (ans[i]) {
      case 'L': --nowj;
        break;
      case 'R': ++nowj;
        break;
      case 'U': --nowi;
        break;
      case 'D': ++nowi;
        break;
      }
      if (nowi < 0 || 49 < nowi || nowj < 0 || 49 < nowj) {
        pnt = -1;
        break;
      }
      now = 50 * nowi + nowj;
      if (used[t[now]]) {
        pnt = -1;
        break;
      }
      used[t[now]] = true;
      pnt += p[now];
    }
    if (pnt >= lastpnt) {
      lastpnt = pnt;
      lastans = ans;
    }
    else if(pnt != -1 && r <= 125){
      lastpnt = pnt;
      lastans = ans;
    }
    dur = chrono::system_clock::now() - start;
  }
  cout << lastans << "\n";
}

// C++ (GCC9.2.1) AtCoder
/*
Ctrl+Option+N で　実行

*/

#include <bits/stdc++.h>
#define INF 100000000000
#define MOD 1000000007
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl;

typedef long long ll;

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N,K;
  cin>>N>>K;

  ll last = -1;

  map <ll,ll> mp;

  REP(i,N){
    ll a,b;
    cin>>a>>b;
    mp[a] += b;
  }

  ll ans = 0;
  ll money = K;
  ll now = 0;

  for(auto itr = mp.begin();itr != mp.end(); itr++ ){
    ll next = itr -> first;
    ll get = itr -> second;
    //print(next + 10000)
    //print(money)

    if(money - (next - now) >= 0){
      money -= (next - now);
      now = next;
      money = money + get ;
      continue;
    } else {
      print(now + money)
      return 0;
    }

  }
  //print(money)

  assert(money >= 0);
  now += money;
  print(now);

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ull unsigned long long
#define ff first
#define ss second
#define ld long double

template <class T>
void print(vector<T>& v){
    for(T x:v) cout<<x<<" ";
    cout<<"\n";
}

void inp(vector<int>& v, int n){
    for (int i=0; i<n; ++i) scanf("%d ", &v[i]);
}

const int nax=1e+5+5;

void sol(){
    int n;
    cin>>n;
    vector<int> nums(n);
    inp(nums, n);
    // cout<<n<<endl;
    // print(nums);
    ll curr=0, res=0, a=0, b=0;
    for (ll x:nums){
        a+=x;
        b=max(a, b);
        res=max(res, curr+b);
        curr+=a;
        // cout<<"curr ="<<curr<<" z="<<z<<endl;
        // res=max(res, curr);
    }
    cout<<res<<endl;
}

int main() {
    int t;
    // cin>>t;
    t=1;
    t++;
    // std::cout << std::setprecision(15);
    for (int i=1; i<t; ++i){
        // printf("Case #%d: ", i);
        sol();
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define Go_ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define llu long long unsigned int
#define pii pair<int ,int>
#define PII pair<ll ,ll>

const int Max=1e9+100;
const ll  MAX=1e18+500;
const int sz=2e5+100;

string str;
int dp[25][4];
int len;

int cholo(int id,int last)
{
    if(id>=len) {
       if(last==0) return 0;
       else return 100;
    }
    int &ret=dp[id][last];
    if(~ret) return ret;

    int  mx=cholo(id+1,(last + (str[id]-'0')%3)%3);

    mx=min(mx, 1+cholo(id+1, last));

    return (ret= mx);
}

int main()
{
    Go_
    ll a,b,c,i,j,k,q,p,x,y,ct,ct1,m,l,r,x1,y1,mn,h,sum1,in,z,mid,n,mx;
    char ch;
    double d;
    //tring str1,str2,str;

    cin>>n;

    mx=0;

    ll last=0;
    ll pre=0;
    ll le=0;

    for(ll i=1;i<=n;i++)
    {
        cin>>x;
        pre+=x;
        le=max(le, pre);
        mx=max(mx, last+le);
        last+=pre;
    }

    cout<<mx<<endl;

}


/*
ID: gurban1
LANG: C++
TASK:
*/
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

const int maxn=2e5+5;
int n;
ll dp[maxn][2];
pair<ll,ll>p[maxn];
ll l[maxn],r[maxn];

int main(){
	// freopen("","r",stdin);
	// freopen("","w",stdout);

	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> n;
	for(int i = 1;i <= n;i++) cin >> p[i].second>>p[i].first;

	sort(p+1,p+n+1);

	for(int i = n;i >= 1;i--){
		if(p[i].first != p[i+1].first) r[p[i].first] = p[i].second;
		if(p[i].first != p[i-1].first) l[p[i].first] = p[i].second;
	}

	int last = -1;
	for(int i = n;i >= 1;i--){
		if(l[i] == 0) continue;
		if(last == -1){
			dp[i][0] = llabs(l[i]-r[i]) + llabs(r[i]);
			dp[i][1] = llabs(l[i]-r[i]) + llabs(l[i]);
		}
		else {
			dp[i][0] = llabs(l[i]-r[i]) + min(llabs(r[i]-l[last])+dp[last][0],llabs(r[i]-r[last]) + dp[last][1]);
			dp[i][1] = llabs(l[i]-r[i]) + min(llabs(l[i]-l[last])+dp[last][0],llabs(l[i]-r[last]) + dp[last][1]);
		}
		last = i;
	}
	cout<<min(dp[last][0]+llabs(l[last]),dp[last][1]+llabs(r[last]));
}

#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ggdem=b;i<ggdem;++i)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define mset(a,v) memset((a),(v),sizeof(a))
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;

const int MAXN=400005;
vector<int> g[MAXN]; // [0,n)->[0,m)
int n,m;
int mt[MAXN],mt2[MAXN],ds[MAXN];
bool bfs(){
	queue<int> q;
	memset(ds,-1,sizeof(ds));
	fore(i,0,n)if(mt2[i]<0)ds[i]=0,q.push(i);
	bool r=false;
	while(!q.empty()){
		int x=q.front();q.pop();
		for(int y:g[x]){
			if(mt[y]>=0&&ds[mt[y]]<0)ds[mt[y]]=ds[x]+1,q.push(mt[y]);
			else if(mt[y]<0)r=true;
		}
	}
	return r;
}
bool dfs(int x){
	for(int y:g[x])if(mt[y]<0||ds[mt[y]]==ds[x]+1&&dfs(mt[y])){
		mt[y]=x;mt2[x]=y;
		return true;
	}
	ds[x]=1<<30;
	return false;
}
int mm(){
	int r=0;
	memset(mt,-1,sizeof(mt));memset(mt2,-1,sizeof(mt2));
	while(bfs()){
		fore(i,0,n)if(mt2[i]<0)r+=dfs(i);
	}
	return r;
}

ll a[MAXN],b[MAXN];

int main(){FIN;
	cin>>n;
	fore(i,0,n)cin>>a[i]>>b[i];
	fore(i,0,n){
		g[i].pb(a[i]);
		g[i].pb(b[i]);
	}
	cout<<mm()<<"\n";

	return 0;
}


#line 2 "/home/defineprogram/Desktop/Library/template/template.cpp"
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,n) for(ll i=1;i<n;i++)
#define rev(i,n) for(ll i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<ll,ll>
#define len(s) (ll)s.size()

template<class T,class U> inline bool chmin(T &a, U b){
	if(a>b){a=b;return true;}
	return false;
}
template<class T,class U> inline bool chmax(T &a, U b){
	if(a<b){a=b;return true;}
	return false;
}
constexpr ll inf = 3e18;
#line 3 "/home/defineprogram/Desktop/Library/structure/BIT.cpp"

template<class T>
class BIT{
	ll N;
	vector<T>bit;
	void add_(ll x,T y){
		while(x<=N){
			bit[x]+=y;x+=x&-x;
		}
	}
	T sum_(ll x){
		T res=0;
		while(x>0){
			res+=bit[x];x-=x&-x;
		}
		return res;
	}
public:
	ll lower_bound(T w){
		if(w<=0)return -1;
		ll x=0;
		ll k=1;while(k*2<=N)k*=2;
		for(;k>0;k/=2){
			if(x+k<=N&&bit[x+k]<w){
				w-=bit[x+k];
				x+=k;
			}
		}
		return x;
	}
	void add(ll x,T y){add_(x+1,y);}
	T sum(ll l,ll r){return sum_(r)-sum_(l);}
	BIT(ll x):N(x),bit(x+1){}
};
/*
@brief Binary Indexed Tree
@docs docs/BIT.md
*/
#line 3 "main.cpp"

int N;
int A[200005],B[200005];
int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	cin>>N;
	rep(i,N){
		cin>>A[i];
		B[A[i]]=i+1;
	}
	set<int>st;
	rep(i,N-1){
		st.insert(A[i]);
		if(st.upper_bound(i+1)==st.end()||++st.upper_bound(i+1)!=st.end()){
			cout<<"-1\n";return 0;
		}
	}
	st.clear();
	rev(i,N){
		if(!i)break;
		st.insert(A[i]);
		if(st.upper_bound(i)==st.begin()||--st.upper_bound(i)!=st.begin()){
			cout<<"-1\n";return 0;
		}
	}
	BIT<int> bit(N+5);
	ll cnt=0;
	rep(i,N){
		cnt+=bit.sum(A[i],N+1);
		bit.add(A[i],1);
	}
	if(cnt!=N-1){
		cout<<"-1\n";return 0;
	}
	rep(i,N){
		for(int j=B[i+1];j>i+1;j--){
			cout<<j-1<<"\n";
			B[A[j-2]]++;
			swap(A[j-2],A[j-1]);
		}
	}
}

#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<lli,lli> ii;
typedef vector<lli> vi;
#define deb(x) cout << #x": " << (x) << endl;

lli gauss(lli u) {
  if(u % 2) {
    lli v = (u - 1LL) / 2LL;
    return u * v;
  }
  lli v = (u - 1LL);
  u /= 2LL;
  return u * v;
}

void solve() {
  lli n, k; cin >> n >> k;
  lli lim = 3LL * n;
  vi cnt(lim + 1LL);
  lli next = 1;
  lli lim2;
  if(n % 2) lim2 = ((n + 1LL) * 3LL) / 2LL;
  else lim2 = ((n  * 3LL) + 2) / 2LL;
  for(lli i = 3LL; i <= n + 1LL; ++i) {
     cnt[i] = cnt[i - 1] + next;
     ++next;
  }
  for(lli i = n + 2LL; i <= lim2; ++i) {
    cnt[i] = cnt[i - 1] + next;
    next -= 2;
  }
  for(lli i = lim; i > lim2; --i) {
    cnt[i] = cnt[lim - i + 3LL];
  }
  lli x;
  for(lli i = 3LL; i <= lim; ++i) {
    if(k > cnt[i]) k -= cnt[i];
    else {
      x = i;
      break;
    }
  }
  //deb(k);
  for(lli i = 1LL; i <= n; ++i) {
    lli left = (x - i);
    if(left > (2LL * n)) continue;
    lli cur = (2LL * n) - left + 1LL;
    cur = min(cur, left - 1LL);
    //deb(left);
    //deb(cur);
    if(k > cur) {
      k -= cur;
      continue;
    }
    for(lli j = 1LL; j <= n; ++j) {
      cur = (left - j);
      if(cur > n) continue;
      if(k == 1) {
        cout << i << " " << j << " " << cur << ENDL;
        return;
      }
      else --k;
    }
  }
}

int main(){ _
  solve();
  return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#define ll long long
#define rep(i, a, b) for (int i = a; i <= (int)b; i ++)
#define per(i, a, b) for (int i = (int)a; i >= b; i --)
template < typename T > void read(T & x) {
    x = 0; int flag = 1; char c = getchar();
    for(; !isdigit(c); c = getchar()) if(c == '-') flag = -1;
    for(; isdigit(c); c = getchar()) x = x * 10 + c - '0';
    x *= flag;
}
using namespace std;
const int maxn = 200010;
int n, a[maxn], b[maxn];
ll f[maxn];
int main()
{
	scanf("%d", &n);
	rep(i, 1, n) scanf("%d", &a[i]), a[i] = max(a[i], a[i - 1]);
	rep(i, 1, n) scanf("%d", &b[i]), f[i] = max(f[i - 1], 1ll * b[i] * a[i]);
	rep(i, 1, n) printf("%lld\n", f[i]);
    return 0;
}

#include <bits/stdc++.h>

#define MAX 200005

using namespace std;

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

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

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

    long long maxA = 0, ans = 0;
    for (int i = 0; i < n; i++) {
        maxA = max(maxA, a[i]);
        ans = max(ans, maxA*b[i]);
        cout << ans << "\n";
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;
const int N = 2e5+10;
ll dp[N][17];
int cnt[N][17];
string n;
int K;
int get(char c)
{
    if(c >= '0' && c <= '9')
        return c - '0';
    return c - 'A' + 10;
}

ll dfs(int pos, int k, bool limited, bool pre_zero)
{
    if(pos == n.size())
        return (k == K && !pre_zero) ? 1 : 0;
    if(!limited && !pre_zero && dp[pos][k] != -1)
        return dp[pos][k];
    ll ret = 0;
    int up = limited ? get(n[pos]) : 15;
    if(limited)
    {
        if(pre_zero)
        {
            //继续还是0
            ret = dfs(pos + 1, k, false, true);
            //选up
            ret = (ret + dfs(pos + 1, k + 1, true, false)) % MOD;
            //选择小于up但不是0的
            if(up > 1)
                ret = (ret + (up - 1) * dfs(pos + 1, k + 1, false, false)) % MOD;
        }
        else
        {
            for(int i = 0; i <= up; ++i)
                ret = (ret + dfs(pos + 1, k + (cnt[pos][i] == 0), i == up, false)) % MOD;
        }
    }
    else
    {
        if(pre_zero)
        {
            //选择0
            ret = dfs(pos + 1, k, false, pre_zero);
            //选择非0
            ret = (ret + dfs(pos + 1, k + 1, false, false) * up) % MOD;
        }
        else
        {
            ret = dfs(pos + 1, k, false, false) * k + dfs(pos + 1, k + 1, false, false) * (up + 1 - k);
            ret %= MOD;
        }
    }
    if(!limited && !pre_zero)
        dp[pos][k] = ret;
    return ret;
}

int main()
{
    cin >> n >> K;
    memset(dp, -1, sizeof dp);
    for(int i = 0; i < n.size(); ++i)
    {
        cnt[i + 1][get(n[i])] = 1;
        for(int j = 0; j < 16; ++j)
            cnt[i + 1][j] += cnt[i][j];
    }

    cout << dfs(0, 0, true, true) << endl;
    return 0;
}

#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define all(x) x.begin(),x.end()
#define mod 1000000007
#define ad(a,b) a=(a+b)%mod;
#define X 5010
ll po(ll x,ll y){
	ll res=1;
	for(;y;y>>=1){
		if(y&1)res=res*x%mod;
		x=x*x%mod;
	}
	return res;
}
ll fac[X],ivf[X];
void init(){
	fac[0]=1;
	for(ll i=1;i<X;i++)fac[i]=fac[i-1]*i%mod;
	for(ll i=0;i<X;i++)ivf[i]=po(fac[i],mod-2);
}
ll C(ll n,ll k){
	return fac[n]*ivf[n-k]%mod*ivf[k]%mod;
}

#define N 100010
ll calc(ll n,vector<ll> a,vector<ll> b,ll L){
	/*cerr<<"calc:"<<n<<" "<<L<<endl;
	cout<<"A:";rep(i,n)cout<<a[i]<<" ";cout<<endl;
	cout<<"B:";rep(i,n)cout<<b[i]<<" ";cout<<endl;*/
	rep(i,n){
		a[i]-=i,b[i]-=i;
	}
	L-=n;
	a.push_back(L);
	ll res=0;
	ll k=-1;//index kまで更新したことがある
	ll val=-1e17;//更新した値
	rep(i,n){
		if(val==b[i])continue;
		ll l=k,r=a.size(),mid;
		while(l<r-1){
			mid=(l+r)>>1;
			if(b[i]<=a[mid])r=mid;
			else l=mid;
		}
		if(r==a.size())return -1;
		if(a[r]!=b[i])return -1;
		res+=r-i;//i~r-1
		k=r-1,val=b[i];
	}
	//cout<<"res="<<res<<endl;
	return res;
}

ll n,L,a[N],b[N];
ll solve(){
	cin>>n>>L;
	L++;
	rep(i,n)cin>>a[i];
	rep(i,n)cin>>b[i];
	vector<ll> A,B;
	ll tbef=-1;
	ll hudobef=0;
	ll ans=0;
	rep(i,n+1){
		ll t=-1;
		if(i<n){
			if(a[i]<b[i])t=0;
			if(a[i]==b[i])t=1;
			if(a[i]>b[i])t=2;
		}
		else{
			a[i]=b[i]=L;
			t=1;
		}
		if(tbef!=t){
			if(tbef==0&&t==2)return -1;
			if(tbef==0){
				ll cres=calc(A.size(),A,B,a[i]);
				if(cres==-1)return -1;
				ans+=cres;
			}
			if(tbef==2){
				rep(i,A.size())A[i]*=-1,B[i]*=-1;
				reverse(all(A));
				reverse(all(B));
				ll cres=calc(A.size(),A,B,-hudobef);
				if(cres==-1)return -1;
				ans+=cres;
			}
			A.clear();
			B.clear();
			tbef=t;
		}
		if(t==1){
			hudobef=a[i];
		}
		A.push_back(a[i]);
		B.push_back(b[i]);
	}
	return ans;
}
int main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<solve()<<endl;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define endl '\n'
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 1e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0',  ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} };

int main()
{
    ll n  = read();
    map<string,int> Map;
    vector<string> item;
    rep(i,1,n)
    {
        string s;
        cin>>s;
        Map[s] = 1;
        item.pb(s);
    }
    int flag = 0;
    rep(i,1,n)
    {
        if(item[i-1][0]=='!')
        {
            string t(item[i-1],1,item[i-1].size());
            if(Map[t])
            {
                cout<<t<<endl;
                flag = 1;
                break;
            }
        }
    }
    if(!flag) cout<<"satisfiable"<<endl;
    return 0;
}

#include<bits/stdc++.h>
#define ll long long
using namespace std;
void solve(){
    long long n,m,tot=0,cnt=0;
    string s,k="";
    bool ok=1;
    cin>>n;
    map<string,int>mp;
    for(int i=0;i<n;i++){
        cin>>s;
        if(s[0]=='!'){
           mp[s]++;
           s=s.substr(1);
           if(mp.find(s)!=mp.end()) k=s;
        }
        else{
           mp[s]++;
           s="!"+s;
           if(mp.find(s)!=mp.end()) k=s.substr(1);
        }
    }
    if(k=="") cout<<"satisfiable"<<endl;
    else cout<<k<<endl;
}
int main()
 {
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("bhar.txt", "w", stdout);
    #endif
    long long q(1);//cin>>q;
    while(q--){
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn=3e5+5;
int tree[4*maxn];

void upd(int node,int lo,int hi,int p,int val){
    if(lo>hi || lo>p || hi<p){
        return;
    }
    if(lo==hi){
        tree[node]^=val;
        return;
    }
    int mid=(lo+hi)/2;
    upd(node<<1,lo,mid,p,val);
    upd(node<<1 | 1,mid+1,hi,p,val);
    tree[node]=tree[node<<1]^tree[node<<1 | 1];
}

int get(int node,int lo,int hi,int l,int r){
    if(lo>hi || lo>r || hi<l){
        return 0;
    }
    if(lo>=l && hi<=r){
        return tree[node];
    }
    int mid=(lo+hi)/2;
    return get(node<<1,lo,mid,l,r)^get(node<<1 | 1,mid+1,hi,l,r);
}

int main()
{
    int n,q;
    cin>>n>>q;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
      	upd(1,0,n-1,i,a[i]);
    }
    while(q--){
        int ty;
        cin>>ty;
        if(ty==1){
            int i,val;
            cin>>i>>val;
            --i;
            upd(1,0,n-1,i,val);
        }
        else{
            int u,v;
            cin>>u>>v;
            --u,--v;
            cout<<get(1,0,n-1,u,v)<<'\n';
        }
    }
}

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

using ll=long long;
const int Nmax=200009;
int N, M, Q;
ll X[Nmax], Y[Nmax];
struct Data {ll a, b, c;};
Data xp[Nmax], yp[Nmax];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    xp[0]={1, 0, 0}; yp[0]={0, 1, 0};
    cin>>N;
    for(int i=1; i<=N; i++) cin>>X[i]>>Y[i];
    cin>>M;
    for(int i=1; i<=M; i++) {
        Data &x=xp[i-1], &y=yp[i-1];
        int op;
        cin>>op;
        if(op==1) {
            xp[i]={y.a, y.b, y.c};
            yp[i]={-x.a, -x.b, -x.c};
        }
        else if(op==2) {
            xp[i]={-y.a, -y.b, -y.c};
            yp[i]={x.a, x.b, x.c};
        }
        else if(op==3) {
            ll p;
            cin>>p;
            xp[i]={-x.a, -x.b, 2*p-x.c};
            yp[i]={y.a, y.b, y.c};
        }
        else if(op==4) {
            ll p;
            cin>>p;
            xp[i]={x.a, x.b, x.c};
            yp[i]={-y.a, -y.b, 2*p-y.c};
        }
    }
    cin>>Q;
    while(Q--) {
        int A, B;
        cin>>A>>B;
        cout<<(xp[A].a*X[B]+xp[A].b*Y[B]+xp[A].c)<<" ";
        cout<<(yp[A].a*X[B]+yp[A].b*Y[B]+yp[A].c)<<"\n";
    }
    return 0;
}


#include<bits/stdc++.h>
typedef unsigned long long ull;
typedef long long ll;
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define nep(i,r,l) for(int i=r;i>=l;i--)
void sc(int &x){scanf("%d",&x);}
void sc(int &x,int &y){scanf("%d%d",&x,&y);}
void sc(int &x,int &y,int &z){scanf("%d%d%d",&x,&y,&z);}
void sc(ll &x){scanf("%lld",&x);}
void sc(ll &x,ll &y){scanf("%lld%lld",&x,&y);}
void sc(ll &x,ll &y,ll &z){scanf("%lld%lld%lld",&x,&y,&z);}
void sc(char *x){scanf("%s",x);}
void sc(char *x,char *y){scanf("%s%s",x,y);}
void sc(char *x,char *y,char *z){scanf("%s%s%s",x,y,z);}
void out(int x){printf("%d\n",x);}
void out(ll x){printf("%lld\n",x);}
void out(int x,int y){printf("%d %d\n",x,y);}
void out(ll x,ll y){printf("%lld %lld\n",x,y);}
void out(int x,int y,int z){printf("%d %d %d\n",x,y,z);}
void out(ll x,ll y,ll z){printf("%lld %lld %lld\n",x,y,z);}
using namespace std;
const int N=3e5+5;
int n;
unordered_map<ll,int>vis;
int main()
{
    //freopen("1.in","r",stdin);freopen("1.out","w",stdout);
    sc(n);
    vis[0]++;
    ll sum=0,ans=0;
    while(n--)
    {
        int x;sc(x);
        if(n&1) sum+=x;
        else sum-=x;
        ans+=vis[sum];
        vis[sum]++;
    }
    out(ans);
}

#include <bits/stdc++.h>
using i64 = long long;
using u32 = unsigned;
using u64 = unsigned long long;
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    i64 n;
    std::cin >> n;
    std::map<i64, int> count;
    count[0]++;
    i64 ans = 0, sum = 0;
    for (int i = 0; i < n; i++) {
        int x;
        std::cin >> x;
        if (i % 2 == 0) {
            sum += x;
        } else {
            sum -= x;
        }
        ans += count[sum]++;
    }
    std::cout << ans << "\n";
    return 0;
}


#include <iostream>
using namespace std;
int main(){
  int a,b,w,n0,n1;
  cin >> a >> b;
  cin >> w;
  n0=(1000*w+b-1)/b;
  n1=1000*w/a;
  if(n0<=n1){
    cout << n0 << " " << n1 << endl;
  } else {
    cout << "UNSATISFIABLE" << endl;
  }
  return 0;
}

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

using std::cin;
using std::cout;
using std::string;
using std::vector;
using P = std::pair<int, string>;

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

	vector<P> a(n);
	rep(i, n) cin >> a[i].second >> a[i].first;

	sort(a.rbegin(), a.rend());

	cout << a[1].second << '\n';

	return 0;
}


#include <iostream>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <sstream>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vpii vector<pii>
#define V vector
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F first
#define S second
#define sqr(x) (x)*(x)
#define mp make_pair
#define mtp make_tuple
#define tpii tuple<int,int,int>
#define rep(n) for(int i=0;i<n;i++)
#define inf INT_MAX
#define debug(x) cerr<<x<<'\n';
#define sz(x) (int)((x).size())
#define int long long
#define ull unsigned long long
#define quick ios_base::sync_with_stdio(0),cin.tie(0);long double nownow=clock();
#define total_time cerr<<(clock()-nownow)/CLOCKS_PER_SEC*1000<<" (ms)\n";
using namespace std;
int gcd(int a,int b){return (a%b?gcd(b,a%b):b);}
template<typename T>void in(vector<T> &a){for(auto &i:a)cin>>i;}
template<typename T>void out(vector<T> &a){for(auto &i:a)cout<<i<<' ';cout<<'\n';}
template<typename T>void out(multiset<T> &a){for(auto i:a)cout<<i<<' ';cout<<'\n';}
template<typename T>void out(set<T> &a){for(auto i:a)cout<<i<<' ';cout<<'\n';}
#define yn(x) cout<<((x)?"Yes\n":"No\n");
#define YN(x) cout<<((x)?"YES\n":"NO\n");
#define mod (int)(1e9+7)

int n;
int bit[300001];
void update(int x){
    while(x<=n){
        bit[x]++;
        x+=x&(-x);
    }
}
int query(int x){
    int sum=0;
    while(x){
        sum+=bit[x];
        x-=x&(-x);
    }
    return sum;
}

signed main(){
    quick
    cin>>n;
    vi a(n);
    int last=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        last+=query(n)-query(a[i]+1);
        update(a[i]+1);
    }
    for(int i=0;i<n;i++){
        cout<<last<<'\n';
        last+=n-a[i]*2-1;
    }
    total_time
    return 0;
}

#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
#define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
using namespace std;
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
typedef long long lli;
typedef pair<int,int> ii;
typedef vector<int> vi;
#define deb(x) cout << #x": " << (x) << endl;

lli gcd(lli a, lli b){return (b?gcd(b,a%b):a);}
lli lcm(lli a, lli b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
int popcount(lli x) { return __builtin_popcountll(x); }

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// int rnd(int n){return uniform_int_distribution<int>(0, n-1)(rng);}

lli poww(lli a, lli b){
	lli res =1;
	while(b){ if(b&1) res = res * a; a = a*a; b/=2; }
	return res;
}

vvc<int> graph(int n, int m, bool dir=1){
	vv(int,v,n+1,0);
	fore(i,0,m){
		int a,b; cin>>a>>b;
		v[a].pb(b);
		if(dir)v[b].pb(a);
	}
	return v;
}
template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2;
// ---- コーディングはここから！ ('-')7
using T = array<lli,2>;
T ini = {0,0}, bad = {0,0};
using L = lli;
L nulo = 0;

struct LazyST{
  #define mid (l + r)/2
  #define left(u) (u + 1)
  #define right(u) (u + ((mid - l + 1) << 1))
  vector<T>st;
  vector<L>lazy;

  T op(T a, T b){return T{a[0]+b[0],a[1]+b[1]}; } // operacion de merge
  T cmp(T a, T b){return T{a[0]+b[0],a[1]+b[1]}; } //operacion en query

  LazyST(int n):st(2*n,ini), lazy(2*n,nulo){}

  void push(int u, int l, int r){
    if(l<r and lazy[u]!=nulo){
      st[left(u)][1] += (mid-l+1)*lazy[u];
      st[right(u)][1] += (r-mid)*lazy[u];
      lazy[left(u)] += lazy[u];
      lazy[right(u)]+= lazy[u];
      lazy[u]= nulo;
    }
  }

  void update(int u, int l, int r, int ll, int rr, lli x){
    push(u, l, r);
    if(r < ll or l > rr or l>r) return;
    if(ll <= l and r <= rr){
			if(ll==rr)st[u][0]=1;
      st[u][1]+=(r-l+1)*x;
			lazy[u]=x;
      return;
    }
    update(left(u), l, mid, ll, rr, x);
    update(right(u), mid + 1, r, ll, rr, x);
    st[u] = op(st[left(u)],st[right(u)]);
  }

  T query(int u, int l, int r, int ll, int rr){
    push(u, l, r);
    if(r < ll or l > rr or l>r) return bad;
    if(ll <= l and r <= rr)return st[u];
    return cmp(query(left(u),l,mid,ll,rr),query(right(u),mid+1,r,ll,rr));
  }
};

void solve(){
	int n; cin>>n;
	LazyST st(n);
	vi v(n); fore(i,0,n)cin>>v[i];
	for(int i = n-1;i>=0;i--){
		int a = v[i];
		auto q1 = st.query(0,0,n-1,0,a);
		st.update(0,0,n-1,a,a,q1[0]);  // menores a la derecha de mi.
	}
	cout<<st.query(0,0,n-1,0,n-1)[1]<<ENDL;
	fore(i,0,n-1){
		int a = v[i];
		auto q2 = st.query(0,0,n-1,a,a);
		st.update(0,0,n-1,a,a,-q2[1]);
		if(a!=n-1)st.update(0,0,n-1,a+1,n-1,1);
		cout<<st.query(0,0,n-1,0,n-1)[1]<<ENDL;
	}
}

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


//#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
#define endl '\n'

llo n,m;
llo it[501][501];
llo ans[501];
llo ans2[501];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n;
	llo cur=1;
	llo ind=0;
	for(int i=1;i<=n;i++){
		if(i==cur){
			ind++;
			cur*=2;
		}
		cout<<ind<<" ";
	}
	cout<<endl;

	return 0;
}

#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define rep(i, n) for(int i=0;i<n;i++)
#define all(i, v) for(auto& i : v)
using namespace std;

vector<int> div(int n){
    vector<int> v;
    for(int i=1;i*i<=n;i++){
        if(n % i == 0){
            if(n != i * i) v.pb(n / i);
            v.pb(i);
        }
    }
    return v;
}

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> ans(n + 1, 0);
    for(int i=1;i<=n;i++){
        vector<int> v(60, 1);
        all(e, div(i)) v[ans[e]] = 0;
        for(int j=1;j<=60;j++){
            if(v[j]){
                ans[i] = j;
                break;
            }
        }
    }
    rep(i, n) cout << ans[i + 1] << " ";
    return 0;
}


//#define MULTICASES
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(i=(a);i<=(b);++i)
#define per(i,a,b) for(i=(a);i>=(b);--i)
#define REP(i,a,b) for(i=(a);i< (b);++i)
#define PER(i,a,b) for(i=(a);i> (b);--i)
#define ERR(...) fprintf(stderr,__VA_ARGS__)
inline void ac();
int main(){
#ifdef MULTICASES
	int t;scanf("%d",&t);while(t--)ac();
#else
	ac();
#endif
	return 0;
}
const int MAXN=5005;
const ll p=998244353ll;
ll C[MAXN][MAXN],Z[MAXN],D[MAXN];
inline void ac(){
	int n,m,i,j,a,b;ll t;
	scanf("%d%d",&n,&m);
	if(m&1){puts("0");return;}
	m>>=1;
	rep(i,0,n){
		C[i][0]=1ll;
		rep(j,1,i)C[i][j]=(C[i-1][j]+C[i-1][j-1])%p;
	}
	rep(i,0,n>>1)Z[i]=C[n][i<<1];
	D[0]=1ll;
	for(j=1;j!=4096;j<<=1){
		per(i,m,j){
			a=0;b=i;t=D[i];
			for(++a,b-=j;b>=0;++a,b-=j)t=(t+Z[a]*D[b])%p;
			D[i]=t;
		}
		//rep(i,0,m)ERR("%lld ",D[i]);ERR("\n");
	}
	printf("%lld\n",D[m]);
}
/*
0. int overflow, array bounds
1. special cases (n=1? n=0?)
2. do smth instead of nothing and stay organized
3. WRITE STUFF DOWN
4. DON'T GET STUCK ON ONE APPROACH
5. STAY CALM AND DON'T GET EXPLODED
*/

#include<bits/stdc++.h>
using namespace std;
# define ll long long
# define read read1<ll>()
# define Type template<typename T>
Type T read1(){
	T t=0;
	char k;
	bool vis=0;
	do (k=getchar())=='-'&&(vis=1);while('0'>k||k>'9');
	while('0'<=k&&k<='9')t=(t<<3)+(t<<1)+(k^'0'),k=getchar();
	return vis?-t:t;
}
# define fre(k) freopen(k".in","r",stdin);freopen(k".out","w",stdout)
# define mod 998244353
int n,m,fac[5005],inv[5005];
void init(const int N=5000){
	fac[0]=inv[0]=inv[1]=fac[1]=1;
	for(int i=2;i<=N;++i)fac[i]=1ll*i*fac[i-1]%mod,inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
	for(int i=2;i<=N;++i)inv[i]=1ll*inv[i-1]*inv[i]%mod;
}
ll C(int n,int m){return 1ll*fac[n]*inv[m]%mod*inv[n-m]%mod;}
int f[5005],g[5005];
int main(){init();
	n=read,m=read;f[0]=1;
	for(int i=0;m>>i;++i){
		memset(g,0,sizeof(g));
		for(int k=0;k<=m;++k)
			for(int j=0;k+(j<<i)<=m&&j<=n;j+=2)
				g[k+(j<<i)]=(g[k+(j<<i)]+C(n,j)*f[k])%mod;
		memcpy(f,g,sizeof(f));
	}printf("%d",f[m]);
	return 0;
}


// D - RGB Coloring 2
// sample code
// reference: https://atcoder.jp/contests/abc199/submissions/22053625
#include <bits/stdc++.h>
using namespace std;
#define vec vector
using vi = vec<int>;
using ll = int64_t;
#define rep(i,e) for(int i=0;i<(e);++i)

vec<vi> G(20); // 隣接リスト
vi used(20, -1); // 彩色順（連結成分ごとに採番）
vi colors(20, -1); // 彩色された点

ll dfs(int now){
	ll res = 0;
	for(int to:G[now]) if(colors[to] == colors[now]) return res; // 隣接色かぶり
	res = 1;
	for(int to:G[now]){ // 隣接点
		if(used[to] == -1) used[to] = used[now] + 1; // 未訪問->彩色順を採番
		if(used[to] != used[now] + 1) continue; // 彩色順どおりでない->訪問済み
		ll tmp = 0;
		rep(i, 2){ // colors[now] で使っていない 2 色で再帰
			colors[to] = (colors[now] + i+1) % 3; // 隣接点を彩色
			tmp += dfs(to); // 隣接点へ
		}
		colors[to] = -1; // 無色に戻す
		res *= tmp;
		if(res == 0) break; // used が採番しきれていない点に注意
	}
 	return res;
}

int main(){
	int n, m; cin>>n>>m;
	rep(i, m){
		int a, b; cin>>a>>b; --a, --b;
		G[a].push_back(b);
		G[b].push_back(a);
	}

	ll ans = 1;
	rep(i, n){
		if(used[i] != -1) continue; // 採番済み->訪問済み
		used[i] = colors[i] = 0; // 開始点の訪問済み＆彩色
		ans *= dfs(i) * 3;
	}
	cout<< ans <<endl;
}

#include <bits/stdc++.h>
#include <sys/time.h>
#pragma GCC optimize "O3,omit-frame-pointer,inline"
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
//const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

constexpr ll CYCLES_PER_SEC = 2800000000;
constexpr double TL = 1990;
double get_ms() { struct timeval t; gettimeofday(&t, NULL); return (double)t.tv_sec * 1000 + (double)t.tv_usec / 1000; }
constexpr int dh[4] = {-1, 0, 1, 0};
constexpr int dw[4] = {0, 1, 0, -1};
constexpr char MOVE[4] = {'U', 'R', 'D', 'L'};

uint32_t XorShift(void) {
	static uint32_t x = 123456789;
	static uint32_t y = 362436069;
	static uint32_t z = 521288629;
	static uint32_t w = 88675123;
	uint32_t t;

	t = x ^ (x << 11);
	x = y; y = z; z = w;
	return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
}

double Prob(void){
	double ret = (double)XorShift() / UINT_MAX;
	return ret;
}

namespace AHC004{
    int N, M;
    vector<string> S;
    void input(){
        cin >> N >> M;
        S.resize(M);
        REP(i,M) cin >> S[i];
    }

    void output(){
        REP(i,N) cout << string(N, 'A') << endl;
    }

    void main(){
        input();
        output();
    }
}

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


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

int main() {
   int N;
   cin >> N;
   vector<int> A(N),P(N),X(N);
   for (int i=0;i<N;i++) {
       cin >> A.at(i) >> P.at(i) >> X.at(i);
   }
   vector<int> price(N);
   bool judge=false;

   for (int i=0;i<N;i++) {
       if (A.at(i)>=X.at(i)) {
       }
       else {
           judge=true;
           price.at(i)=P.at(i);
       }
   }
   if (judge) {
       sort(price.begin(),price.end());
       for (int i=0;i<N;i++) {
           if (price.at(i)==0) {
           }
           else {
               cout << price.at(i) <<endl;
               break;
           }
       }
   }
   else {
       cout << -1 << endl;
   }
}

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

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

vector<vector<int>> s(a,vector<int>(3));

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

    for(int j =0;j<3;j++){

cin>>s.at(i).at(j);

     }}

     int ans=s.at(0).at(1);
     bool bo =true;
     for(int i =0;i<a;i++){

         if(s.at(i).at(2)-s.at(i).at(0)>0){

             ans=min(s.at(i).at(1),ans);
            bo=false;
         }
     }

     if(!bo)cout<<ans<<endl;

     if(bo)cout<<"-1"<<endl;
}


#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define db double
#define rep(x,a,b) for(int x=(a);x<=(b);x++)
#define per(x,a,b) for(int x=(a);x>=(b);x--)
#define reP(x,a,b) for(int x=(a);x<(b);x++)
#define Per(x,a,b) for(int x=(a);x>(b);x--)
#define scf(a) scanf("%d",&a)
#define scfll(a) scanf("%lld",&a)
#define scfdb(a) scanf("%lf",&a)
#define ptf(a) printf("%d",a)
#define ptfll(a) printf("%lld",a)
#define ptfsp(a) printf("%d ",a)
#define ptfllsp(a) printf("%lld ",a)
#define pli(a,b) make_pair(a,b)
#define pb push_back
#define el puts("")
#define FS first
#define SE second
#define PI acos(-1)
#define ls (pos<<1)
#define rs (pos<<1|1)
/*ios::sync_with_stdio(false);
freopen("in.txt","r",stdin);
freopen("1.out","w",stdout);*/
using namespace std;
const ll mod=1e9+7;
const int maxn=1e6+5;
ll a[maxn];
int main(){
    ll n;scfll(n);
    int cnt=0;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            a[++cnt]=i;
            if(n/i!=i) a[++cnt]=n/i;
        }
    }
    sort(a+1,a+cnt+1);
    rep(i,1,cnt) ptfll(a[i]),el;
}

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)
using Graph = vector<vector<int>>;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    // 頂点数と辺数
    int N,k; cin >> N>>k;
    int arr[N][N];
    fr(i,N){
        fr(l,N){
            int a;
            cin>>a;
            arr[i][l]=a;
        }
    }
    // グラフ入力受取 (ここでは無向グラフを想定)
    ll conbu[50];
    conbu[0]=1;
    Fr(i,49){
        conbu[i]=((conbu[i-1]*(i+1))%998244353);
    }
    bool arrx[N][N]={};
    bool arry[N][N]={};
    fr(i,N){
        fr(l,N){
            for(int g=i+1;g<(N);++g){
               if(arr[i][l]+arr[g][l]>k) arrx[i][g]=1;
            }
            for(int g=l+1;g<(N);++g){
               if(arr[i][l]+arr[i][g]>k) arry[l][g]=1;
            }
        }
    }
    Graph Gx(N);
    Graph Gy(N);
    fr(i,N){
        for(int l=i+1;l<(N);++l){
            if(arrx[i][l]==0){
            Gx[l].push_back(i);
            Gx[i].push_back(l);
            }
            if(arry[i][l]==0){
            Gy[l].push_back(i);
            Gy[i].push_back(l);
            }
        }
    }
    vector<int> distx(N, -1);
    queue<int> que;
    ll ans=1;
    int count=1;
    for (int v = 0; v < N; ++v) {
        if (distx[v] != -1) continue; // v が探索済みならスルー
        distx[v] = 0, que.push(v);
        while (!que.empty()) {
            int v = que.front(); que.pop();
            for (auto nv : Gx[v]) {
                if (distx[nv] == -1) {
                    distx[nv] = distx[v] + 1;
                    que.push(nv);
                    ++count;
                }
            }
        }
        ans=(ans*conbu[count-1])%998244353;
        count=1;
    }
    vector<int> disty(N, -1);
    for (int v = 0; v < N; ++v) {
        if (disty[v] != -1) continue; // v が探索済みならスルー
        disty[v] = 0, que.push(v);
        while (!que.empty()) {
            int v = que.front(); que.pop();
            for (auto nv : Gy[v]) {
                if (disty[nv] == -1) {
                    disty[nv] = disty[v] + 1;
                    que.push(nv);
                    ++count;
                }
            }
        }
        ans=(ans*conbu[count-1])%998244353;
        count=1;
    }
    cout<<ans;
}


#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
#define ll long long
#define maxn 300005
using namespace std;
int n,maxx;
int vis[maxn];
struct nod{
	int id[2],val;
}x[maxn],y[maxn],ans[10];
int cmp(nod x,nod y){return x.val>y.val;}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>x[i].val>>y[i].val;
		x[i].id[0]=y[i].id[0]=i;
	}

	int m1,m2;
	sort(x+1,x+1+n,cmp);
	sort(y+1,y+1+n,cmp);
	ans[1].val=x[1].val-x[n].val,ans[1].id[0]=x[1].id[0],ans[1].id[1]=x[n].id[0];
	ans[2].val=y[1].val-y[n].val,ans[2].id[0]=y[1].id[0],ans[2].id[1]=y[n].id[0];
	ans[3].val=x[2].val-x[n].val,ans[3].id[0]=x[2].id[0],ans[3].id[1]=x[n].id[0];
	ans[4].val=x[1].val-x[n-1].val,ans[4].id[0]=x[1].id[0],ans[4].id[1]=x[n-1].id[0];
	ans[5].val=y[2].val-y[n].val,ans[5].id[0]=y[2].id[0],ans[5].id[1]=y[n].id[0];
	ans[6].val=y[1].val-y[n-1].val,ans[6].id[0]=y[1].id[0],ans[6].id[1]=y[n-1].id[0];

    int id1,id2;
	sort(ans+1,ans+1+10,cmp);
	for(int i=1;i<=10;i++)
	{
		if(i==1)
		{
			id1=ans[1].id[0],id2=ans[1].id[1];
		}
		if(ans[i].id[0]==id1&&ans[i].id[1]==id2)continue;
		if(ans[i].id[1]==id1&&ans[i].id[0]==id2)continue;
		cout<<ans[i].val;
		break;
	}
}

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

    cin >> s >> t;
    if (count(all(s), '1') != count(all(t), '1')) {
        cout << "-1" << endl;
        return;
    }
    int cnt = count(all(s), '0');
    int r = cnt, a = 0;
    rep(i, s.size()) {
        if (s[i] == '0') {
            if (t[i] == '0') {
                if (a == 0) r--;
            } else {
                a++;
            }
        } else if (t[i] == '0') {
            a--;
        }
    }
    cout << r << endl;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // int t;cin>>t;while(t--)
    solve();
    return 0;
}


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

typedef long long int ll;
ll powk(ll a, ll n = 2){
    ll r = 1;
    for(ll i = 0;i < n;i++){
        r *= a;
    }

    return r;
}

int main()
{
    string n;
    cin >> n;
    ll mc = (ll)n.size(), ans = 0;
    bool f = false;
    for(ll i = 0;i < 1 << ((ll)n.size());i++){
        ll cnt = 0, sum = 0;
        for(ll j = 0;j < (ll)n.size();j++){
           if(i & (1<<j)){
               sum += n[j] - '0';
           }
           else{
               cnt++;
           }
        }
        if(sum % 3 == 0 && mc > cnt){
            f = true;
            mc = cnt;
            ans = cnt;
        }
    }

    if(f){
        cout << ans;
    }
    else{
        cout << -1;
    }

    return 0;
}

// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <atcoder/all> // g++ main.cpp -std=c++17 -I .
using namespace std;
// using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
using ll=long long;

const int inf = INT_MAX / 2; const ll INF = 1LL << 60;
const int MOD = 1000000007;

//cout << fixed << setprecision(15) << x << endl;

////////////////////////////////////////////////////////////////////////////////////////////

int main() {
  int n;cin>>n;
  vector<int> a(n);
  for(auto&i:a) {
    cin>>i;
    i %= 200;
  }
  if(n>8) n=8;

  map<int, int> m;
  int first;
  int second;
  bool can = true;
  for(int i = 1; i < (1<<n); i++) {
    int temp = 0;
    rep(j, n) {
      if(i&(1<<j)) {
        temp += a[j];
        temp %= 200;
      }
    }
    if(m[temp]) {
      first = m[temp];
      second = i;
      break;
    }
    m[temp] = i;
    if(i == (1<<n)-1) can = false;
  }
  if(can) {
    cout << "Yes" << endl;
    cout << __builtin_popcount(first);

    rep(i, n) {
      if((first&(1<<i))) cout << " " << i+1;
    }
    cout << endl;
    cout << __builtin_popcount(second);
    rep(i, n) {
      // cout << "a:: " << second << endl;
      if((second&(1<<i))) cout << " " << i+1;
    }
    cout << endl;
  } else {
    cout << "No" << endl;
  }

}


#include <bits/stdc++.h>
#include <string>
#include <cmath>
#include <sstream>
#include <unordered_map>
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for(ll i = (a-1); i >= (b); i--)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define spre cout<<fixed<<setprecision(15);
typedef long long int ll;
using namespace std;
//ll mod=67280421310721;
// ll mod=998244353;
ll mod=1000000007;
ll INF=1e18;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
	// cin>>test;
	while(test--)
	{
		ll n;
		cin>>n;
		ll o=2,g;
		FOR(i,3,n+1)
		{
			g=__gcd(o,i);
			g=i/g;
			o*=g;
		}
		cout<<o+1;
	}
	return 0;
}

#include <math.h>

#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() { long long a,b=1,temp[32]={1,2,3,2,5,1,7,2,3,1,11,1,13,1,1,2,17,1,19,1,1,1,23,1,5,1,3,1,29,1,0,0};
    cin >> a;
    for (int i = 0; i < a;i++){
        b *= temp[i];
    }
    cout << b + 1 << endl;
}


#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
#define bit(n,k) ((n>>k)&1) //nのk　bit目
#define vec(T) vector<T>
#define vvec(T) vector<vector<T>>
using ll = long long;
using P = pair<int,int>;
using Pll = pair<ll,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 ll llINF = 1LL << 60;
const int iINF = 1e9;

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

struct Solver{

    ll M;
    vec(ll) S;

    bool f(ll n){
        bool res=true;
        ll mm=M;
        ll ten=1;

        for(int i=S.size()-1; i>=0 ; i--){
            mm -= S[i]*ten;
            if(mm<0) res = false;
            if(i>0 && M/n<ten) res=false;
            else ten*=n;
            if(!res) break;
        }
        return res;
    }

    ll bs(ll l, ll r){
        //cout << l << " " << r << endl;
        ll res;
        if(r-l==1) return l;
        ll n = (r+l)/2;
        if(f(n)) res=bs(n,r);
        else res=bs(l,n);
        return res;
    }

    void solve(){
        string X;
        cin >> X;
        cin >> M;

        int l = X.length();
        rep(i,l) S.push_back(X[i]-48);
        ll d=0;
        rep(i,l) chmax(d,S[i]);

        if(l==1){
            if(S[0]>M) cout << 0 << endl;
            else cout << 1 << endl;
            return;
        }

        ll ans;
        ans = bs(d,M+100) - d;
        cout << ans << endl;

        /*
        ll n = d+1;
        ll ans;
        while(){
            vec(ll) mv;
            ll mm = M;
            while(mm){
                mv.push_back(mm%n);
                mm/=n;
            }
            if( mv.size()>l ){
                n++;
            }else if( mv.size() < l){
                ans = n-d-1;
            }else{
                bool f=true;
                rep(i,l) if(mv[i]<)

            }

        }
        */

        /*

        if(l==1){
            if(S[0]>M) cout << 0 << endl;
            else cout << 1 << endl;
            return;
        }

        double ex = M / double(S[0]);
        ll nn = floor( pow(ex,1/double(l-1)));
        cout << nn-d-1 << endl;

        */

        /*
        ll nn =d+1;
        //ll nn=1;
        //ll ex = log10(M)/(l-1);
        //rep(i,ex) nn*=10;

        while(1){
            ll mm=M;
            ll ten=1;
            cout << "nn=" << nn << endl;
            for(int i=l-1; (i>=0 && mm>=0); i--){
                mm -= S[i]*ten;
                ten *=nn;
            }
            if(mm<0){
                cout << max(ll(0),nn-d-1) << endl;
                break;
            }
            nn++;
        }
        */

    }
};

int main(){
    int testcasenum=1;
    //cin >> testcasenum;
    rep1(ti,testcasenum){
        Solver solver;
        solver.solve();
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define Rep(i,j,n) for (ll i=(ll)(j);i<=(ll)(n);++i)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const int mod = 998244353;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << endl; }
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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

/*
ll ti=clock();
cout<<("Execution Time: %.4lf sec", 1.0 * (clock() - ti) / CLOCKS_PER_SEC)<<endl;
*/

int main(){
  ll n;
  cin>>n;
  vll rest(200,vl(0));//1-indexの番号保管
  vl a(n);
  ll x,y;
  rep(i,n){
      cin>>a[i];
      a[i]%=200;
      if(sz(rest[a[i]])==0){
          rest[a[i]].pb(i+1);
      }
      else{
          print("Yes");
          x=1;
          y=1;
          cout<<x<<" "<<rest[a[i]][0]<<endl;
          cout<<y<<" "<<i+1<<endl;
          return 0;
      }
  }

  Rep(i,1,199){
      if(sz(rest[i])!=1){
          continue;
      }
      Rep(j,1,i-1){
          if(sz(rest[j])>0){
              if(sz(rest[(i+j)%200])>0){
                  vl ans_x,ans_y;
                  print("Yes");
                  for(ll X:rest[(i+j)%200]){
                      ans_x.pb(X);
                  }
                  for(ll Y:rest[i]){
                      ans_y.pb(Y);
                  }
                  for(ll Y:rest[j]){
                      ans_y.pb(Y);
                  }
                  sort(all(ans_x));
                  sort(all(ans_y));
                  cout<<sz(rest[(i+j)%200])<<" ";
                  for(ll X:ans_x){
                      cout<<X<<" ";
                  }
                  cout<<endl;
                  cout<<sz(rest[i])+sz(rest[j])<<" ";
                  for(ll Y:ans_y){
                      cout<<Y<<" ";
                  }
                  return 0;
              }
              else{
                  for(ll k:rest[i]){
                    rest[(i+j)%200].pb(k);
                  }
                  for(ll k:rest[j]){
                    rest[(i+j)%200].pb(k);
                  }
              }
          }
      }
  }
  print("No");
}


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

int main() {
  int N, W;
  cin >> N >> W;
  int result = N / W;
  cout << result << endl;
}

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

int main() {
  START
  int N, W; cin >> N >> W;
  cout << N / W << endl;
}


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

int main() {
  ll N;
  cin >> N;
  cout << (100 - (N % 100)) << endl;
}

#include<iostream>
#include<iomanip>
#include<algorithm>
#include<math.h>
#include<vector>
using namespace std;

int main() {

	int x;
	cin >> x;
	cout << 100-(x % 100);
	return 0;
}


/* 	author : sgupta_2001 	*/

#include<bits/stdc++.h>

using namespace std;

using db = double;
using ll = long long;
using ld = long double;
using ull = unsigned long long;

//containers
#define sz(x) int((x).size())
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define rall(x) x.rbegin(), x.rend()
#define sor(x) sort(all(x))
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pb push_back
#define eb emplace_back
#define pf push_front

//pairs
#define mp make_pair
#define ff first
#define ss second

//loops
#define rep(i, a, b) for(int i = a; i < b; ++i)
#define per(i, a, b) for(int i = b - 1; i >= a; --i)
#define each(x, a) for(auto &x : a)

//popular constants
const int mod = 1e9 + 7; //998244353;
const ll inf = 1e18;
const ld pie = acos((ld) - 1);

//grid problems
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//modulo operations
ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}
ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}
ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}

#ifdef SGUPTA_2001
#define deb(x) cerr<< #x <<" "; __print(x); cerr<<'\n';
#else
#define deb(x);
#endif

//debug containers
template<class T> void __print(T x) {cerr<<x;}
template<class T, class U> void __print(pair<T,U> p) {cerr<<"{"<<p.ff<<", "<<p.ss<<"}";}
template<class T> void __print(vector<T> arr) { cerr<<"[ "; for(auto x:arr) { __print(x);cerr<<" "; } cerr<<"]"; }
template<class T> void __print(set<T> st) { cerr<<"{ "; for(auto x:st) { __print(x); cerr<<" "; } cerr<<"}";}
template<class T, class U> void __print(vector<pair<T,U>> arr) { cerr<<"[ "; for(auto x:arr) {__print(x);cerr<<", ";}cerr<<"]";}
template<class T, class U> void __print(unordered_map<T,U> arr) { cerr<<"{ "; for(auto x:arr) {__print(x);cerr<<", ";}cerr<<"}";}
template<class T, class U> void __print(map<T,U> arr) { cerr<<"{ "; for(auto x:arr) {__print(x);cerr<<", ";}cerr<<"}";}
template<typename... T> void read(T&... args) { ((cin>>args),...);}
template<typename... T> void write(T&&... args){((cout<<args<<" "),...);cout<<'\n';}

void solve() {

	int a, b, c;
	read(a, b, c);

	int ans = 0;

	ans = max(ans, a + b);
	ans = max(ans, c + b);
	ans = max(ans, a + c);

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

	return;
}

int main() {

	#ifdef SGUPTA_2001
		freopen("input.txt", "r", stdin);
		freopen("/home/shivansh/Desktop/error.txt", "w", stderr);
	#endif

	auto start = std::chrono::high_resolution_clock::now();

	int t;
	t=1;
	while(t--) solve();

  auto stop = std::chrono::high_resolution_clock::now();
  auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(stop - start);
  // cerr << "Time taken : " << ((long double)duration.count())/((long double) 1e9) <<"s "<< '\n';

	 /*
	 		STUFF TO LOOK:
			1. Check the constraints
			2. Corner cases(n == 0 || n == 1)
			3. Variables in loops
			4. Make sure two ints aren’t multiplied to get a long long
	*/

	return 0;
}

// NARUTO TRAINING TO BE RED
#include <bits/stdc++.h>
using namespace std;

#define all(v) v.begin(), v.end()
#define pi pair<ll, ll>
#define ll long long
#define ar array

const ll MOD = 1e9+7;
const int dx[4] = {-1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const int N = 3e5 + 1000;
//--------------------------------------------//
ll powmod(ll base, ll exp, ll MOD) { ll ans = 1; while (exp) { if (exp & 1)	ans = (ans * base) % MOD; base = (base * base) % MOD; exp >>= 1; } return ans; }
ll modInverse(ll n, ll p) { return powmod(n, p - 2, p); }
//ll f[N];
//ll choose(ll k, ll n) {if(k > n) return 0;  return (f[n] * modInverse((f[n - k] * f[k]) % MOD, MOD)) % MOD; }

void test_case() {
    int n;
    cin>>n;
    int ans =n;
    for(int i = 1; i <= n; ++i) {
        int old = i;
        while(old > 0) {
            if(old % 10 == 7) {
                --ans;
                break;
            }
            old /= 10;
        }
        if(old % 10 == 7)
            continue;
        old = i;
        while(old > 0) {
            if(old % 8 == 7) {
                --ans;
                break;
            }
            old /= 8;
        }
    }
    cout<<ans;
}

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


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll INF = 1e18;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main()
{
    ll n, x;
    cin >> n >> x;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    map<ll, ll> m;
    m[x] = 1;
    for(int i = n-1; i >= 0; i--)
    {
        map<ll, ll> tmp;
        ll t;
        if(i == n-1) t = INF;
        else t = a[i+1] / a[i];
        // (-t, t)
        for(auto p : m)
        {
            ll k = p.first;
            ll v = p.second;
            ll num = k % a[i];
            if(abs(k) / a[i] < t) tmp[num] += v;
            //cout << a[i] << " " << k << " " << v << " " << num << endl;
            if(abs(k) / a[i] < t-1 && num != 0)
            {
                if(num < 0) tmp[num+a[i]] += v;
                else tmp[num - a[i]] += v;
            }
        }
        swap(m, tmp);
    }
    ll ans = 0;
    for(auto i : m) ans += i.second;
    cout << ans << endl;
}

#include <bits/stdc++.h>
// clang-format off
using namespace std; using ll = int64_t; using ull = uint64_t; const ll INF = 9e18;
void print0() {}
template<typename Head,typename... Tail> void print0(Head head,Tail... tail){cout<<fixed<<setprecision(15)<<head;print0(tail...);}
void print() { print0("\n"); }
template<typename Head,typename... Tail>void print(Head head,Tail... tail){print0(head);if(sizeof...(Tail)>0)print0(" ");print(tail...);}
// clang-format on

using pll = pair<ll, ll>;
ll N,X;
vector<ll>A;
vector<map<ll, ll>> memo(52);
ll recur(ll rest, ll i) {
  if(rest==0){
    return 1;
  }
  if(memo[i].count(rest)){
    return memo[i][rest];
  }
  if(rest>0 && rest%A[i]==0){
      memo[i][rest] = 1;
  }
  if(rest>0 && rest%A[i]!=0){
      ll ansrec = 0;
      ll nrest1 = rest/A[i];
      if (i==N-1 || nrest1 < A[i+1] / A[i]) {
          ansrec += recur(rest - A[i]*nrest1, i-1);
      }
      ll nrest2 = 1+rest/A[i];
      if (i==N-1 || nrest2 < A[i+1] / A[i]) {
          ansrec += recur(rest - A[i]*nrest2, i-1);
      }
      memo[i][rest] = ansrec;
  }
  ll rrest = -rest;
  if(rrest>0 && rrest%A[i]==0){
      memo[i][rest] = 1;
  }
  if(rest<0 && rrest%A[i]!=0){
      ll ansrec = 0;
      ll nrest1 = rrest / A[i];
      if (i==N-1 || nrest1 < A[i+1] / A[i]) {
          ansrec += recur(rest + A[i]*nrest1, i-1);
      }
      ll nrest2 = 1 + rrest / A[i];
      if (i==N-1 || nrest2 < A[i+1] / A[i]) {
          ansrec += recur(rest + A[i]*nrest2, i-1);
      }
      memo[i][rest] = ansrec;
  }
  return memo[i][rest];
}
int main() {
    cin >> N>>X;
    A.resize(N);
    for (ll i = 0; i < N; i++) {
        cin>>A[i];
    }
    print(recur(X,N-1));

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"
template<class T> void chmax(T &a, const T b){ a = max(a, b); }
template<class T> void chmin(T &a, const T b){ a = min(a, b); }
long long gcd(long long a, long long b) { return (a % b) ? gcd(b, a % b) : b; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll a, b, c;
    cin >> a >> b >> c;
    cout << (((a * a + b * b) < (c * c)) ? "Yes" : "No") << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main() {
	int a,b,c;
	cin >> a >> b >> c ;
	if (a*a+b*b < c*c) cout << "Yes";
	else cout << "No";
}


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

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define fin(a) { cout << a << endl; return 0; }
#define debug(a) { cerr << #a << ": " << a << endl; }
#define endl '\n'
#define fi first
#define se second
using lint = long long;
using ld = long double;
using P = pair<int,int>;
using Pl = pair<lint,lint>;
template<class T> using V = vector<T>;
template<class T> using priq     = priority_queue<T>;
template<class T> using priq_inv = priority_queue<T, vector<T>, greater<T>>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
template<class T> T ceil(const T &a, const T &b) { return ((a)+(b)-1)/b; }
template<class T> bool chmin(T &a, T b) { if(a > b) { a = b; return 1; } return 0; }
template<class T> bool chmax(T &a, T b) { if(a < b) { a = b; return 1; } return 0; }
template<class T> void YesorNo(T x) { printf(x ? "Yes\n" : "No\n"); }
struct INF { template<class T> operator T() { return numeric_limits<T>::max() / 2; } } INF;

template<class T, class U> istream& operator>>(istream &in, pair<T,U> &p) {
    return in >> p.first >> p.second;
}
template<class T, class U> ostream& operator<<(ostream &out, const pair<T,U> &p) {
    return out << '{' << p.first << ',' << p.second << '}';
}
template<class T> istream& operator>>(istream &in, vector<T> &v) {
    for(auto &&e : v) in >> e;
    return in;
}
template<class T> ostream& operator<<(ostream &out, const vector<T> &v) {
    for(const auto &e : v) out << e << ' ';
    return out;
}

/*----------------------------------------------------------------------------------------------------*/

int main(){
    int a, b;
    cin >> a >> b;
    int c = a+b;
    int ans;
    if(c >= 15 && b >= 8) ans = 1;
    else if(c >= 10 && b >= 3) ans = 2;
    else if(c >= 3) ans = 3;
    else ans = 4;
    cout << ans << endl;
}

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

int main() {
  int A,B;
  cin >> A >> B;
  cout << 2*A+100 - B << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define x first
#define y second
#define FOR(i, m, n) for (ll i(m); i < n; i++)
#define DWN(i, m, n) for (ll i(m); i >= n; i--)
#define REP(i, n) FOR(i, 0, n)
#define DW(i, n) DWN(i, n, 0)
#define F(n) REP(i, n)
#define FF(n) REP(j, n)
#define D(n) DW(i, n)
#define DD(n) DW(j, n)
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using tll = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vpll = vector<pll>;
using vtll = vector<tll>;
using gr = vector<vll>;
using wgr = vector<vpll>;
void add_edge(gr&g,ll x, ll y){ g[x].pb(y);g[y].pb(x); }
void add_edge(wgr&g,ll x, ll y, ll z){ g[x].eb(y,z);g[y].eb(x,z); }
template<typename T,typename U>
ostream& operator<<(ostream& os, const pair<T,U>& p) {
    cerr << ' ' <<  p.x << ',' << p.y; return os; }
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    for(auto x: v) os << ' ' <<  x; return os; }
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
    for(auto x: v) os << ' ' <<  x; return os; }
template<typename T,typename U>
ostream& operator<<(ostream& os, const map<T,U>& v) {
    for(auto x: v) os << ' ' <<  x; return os; }
struct d_ {
    template<typename T> d_& operator,(const T& x) {
        cerr << ' ' <<  x; return *this;}
} d_t;
#define dbg(args ...) { d_t,"|",__LINE__,"|",":",args,"\n"; }
#define deb(X ...) dbg(#X, "=", X);
#define EPS (1e-10)
#define INF (1LL<<61)
#define CL(A,I) (memset(A,I,sizeof(A)))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void solve() {
    ll n; cin >> n;
    map<ll,bool> m;
    F(n) { ll x; cin>>x; m[x]^=1; }
    bool has = 0; for(auto &i: m) has |= i.y;
    if((n%2)==0 && has) cout << "First" << endl;
    else cout << "Second" << endl;
}

int main(void) {
    ios_base::sync_with_stdio(false);
    ll _T; cin >> _T;
    REP(_,_T) solve();
    return 0;
}

#include<bits/stdc++.h>
#define fi first
#define se second

using namespace std;
typedef long long ll;

ll rd(){
	ll x = 0;
	int f = 1;
	char ch = getchar();
	while(ch < '0' || ch > '9') {
		if(ch == '-') f = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	return x * f;
}

void solve(){
	int n = rd();
	map<int,int> mp;
	for(int i = 0;i < n;i++)
		mp[rd()]++;
	int num = mp.begin() -> se;
	if(n & 1) {
		puts("Second");
	}
	else{
		int flag = 0;
		for(auto it:mp){
			if(it.se & 1) {
				flag = 1;
			}
		}
		if(!flag) puts("Second");
		else puts("First");
	}
}

int main(){
	int T = rd();
	while(T--)
		solve();
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
const long double INF = 1e15;

int N = 30*30;
int L = 30;

// (i,j) i個下 , j個右
int ind(int a,int b){
	return a*L + b;
}
int Vi(int v){return v/L;}
int Vj(int v){return v%L;}

bool in(int i,int j,int si,int sj,int ti,int tj){
	if(i<min(si,ti) || max(si,ti)<i) return false;
	if(j<min(sj,tj) || max(sj,tj)<j) return false;
	return true;
}
int length(int v1,int v2){return abs(Vi(v1)-Vi(v2))+abs(Vj(v1)-Vj(v2));}

vector<int> VinRectangle(int si,int sj,int ti,int tj){
	// 四角形の中の頂点を始点からマンハッタン距離が小さい順に
	vector< pair<int,int> > Vs;
	FOR(i,min(si,ti),max(si,ti)+1){
		FOR(j,min(sj,tj),max(sj,tj)+1){
			Vs.push_back( { abs(i-si)+abs(j-sj) , ind(i,j) } );
		}
	}
	sort(Vs.begin(), Vs.end());
	vector<int> res;
	for(auto v:Vs) res.push_back(v.second);
	return res;
}

//vector< vector<string> > S(N,vector<string>(N));
vector< vector<long double> > Len(N,vector<long double>(N,INF));
//vector< vector<char> > C(N,vector<char>(N,'.'));
vector< vector<string> > route(N,vector<string>(N)); // Len の時のルートを示す文字列

void first_do_in_main(){
	FOR(i,0,N){
		int ai = Vi(i);
		int aj = Vj(i);
		if( in(ai+1,aj,0,0,L-1,L-1) ){
			Len[i][ind(ai+1,aj)] = 5000.0;
			route[i][ind(ai+1,aj)] = "D";
		}
		if( in(ai-1,aj,0,0,L-1,L-1) ){
			Len[i][ind(ai-1,aj)] = 5000.0;
			route[i][ind(ai-1,aj)] = "U";
		}
		if( in(ai,aj+1,0,0,L-1,L-1) ){
			Len[i][ind(ai,aj+1)] = 5000.0;
			route[i][ind(ai,aj+1)] = "R";
		}
		if( in(ai,aj-1,0,0,L-1,L-1) ){
			Len[i][ind(ai,aj-1)] = 5000.0;
			route[i][ind(ai,aj-1)] = "L";
		}
	}
}
string rev_route(string s){
	reverse(s.begin(), s.end());
	FOR(i,0,s.size()){
		if(s[i] == 'U'){
			s[i] = 'D';
		}else if(s[i] == 'D'){
			s[i] = 'U';
		}else if(s[i] == 'R'){
			s[i] = 'L';
		}else if(s[i] == 'L'){
			s[i] = 'R';
		}
	}
	return s;
}

string do_calc(int si,int sj,int ti, int tj){
	int start,finish;
	vector<long double> d(N,INF); // startからiまでの距離 d[i]
	vector<int> pv(N); // pv[i]はiの前の頂点
	vector<string> rv(N); // pv[i]からiへどうやって来たか

	start = ind(si,sj);
	finish = ind(ti,tj);
	d[start] = 0;
	auto Vs = VinRectangle(si,sj,ti,tj);
	int Nvs = Vs.size();
	FOR(i,0,Nvs){
		FOR(j,0,i){
			// a -> b へのルート
			int a = Vs[j];
			int b = Vs[i];
			if(route[a][b].size() > 0 && d[a]+Len[a][b] < d[b]){
				d[b] = d[a]+Len[a][b];
				pv[b] = a;
				rv[b] = route[a][b];
			}
		}
	}

	vector<string> s;
	while(finish != start){
		s.push_back(rv[finish]);
		finish = pv[finish];
	}

	string res;
	reverse(s.begin(), s.end());
	for(auto s_ : s) res += s_;
	return res;
}

bool check(string s,int si,int sj,int ti,int tj){
	for(char x:s){
		if(x=='U') si--;
		if(x=='D') si++;
		if(x=='R') sj++;
		if(x=='L') sj--;
	}
	return (si==ti)&&(sj==tj);
}

int main(){
	first_do_in_main();

	FOR(k,0,1000){
		int si,sj,ti,tj;
		cin >> si >> sj >> ti >> tj;
		string res = do_calc(si,sj,ti,tj);

		cout << res << endl;
		cout << flush;

		long double be;
		cin >> be;

		//assert(check(res,si,sj,ti,tj));
		//assert(check(rev_route(res),ti,tj,si,sj));

		/*int st = ind(si,sj);
		int fi = ind(ti,tj);
		route[st][fi] = res;
		Len[st][fi] = be;
		route[fi][st] = rev_route(res);
		Len[fi][st] = be;
		*/

	}

}

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)

using ll = long long;
using namespace std;

const int INF = 1 << 30;

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  int ans = INF;
  ans = min(ans, a);
  ans = min(ans, b);
  ans = min(ans, c);
  ans = min(ans, d);
  cout << ans << endl;
}


#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define rep2(i, a)for(auto i : a)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x, std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
#define INF (1ll << 60)
ll mod = 1000000007;
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p & 1)a *= x; x *= x; p >>= 1; }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p & 1)a = a * x % mod;  x = x * x % mod; p >>= 1; }return a; }
ll co(ll n, ll k) { ll a = 1; rep(i, 1ll, k + 1) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }
ll modinv(ll a) { ll b = mod, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); }u %= mod; if (u < 0) u += mod; return u; }

int main(void) {
	int n, k;
	cin >> n >> k;
	vector<vector<int>> a(n, vector<int>(n));
	int r = 0, l = 0;
	rep(i, 0, n)rep(j, 0, n)cin >> a[i][j], r = max(r, a[i][j]);
	while (r - l > 1) {
		int m = (r + l) / 2;
		vector<vector<int>> s(n + 1, vector<int>(n + 1));
		rep(i, 0, n) {
			rep(j, 0, n) {
				if (a[i][j] > m)s[i + 1][j + 1] = 1;
				s[i + 1][j + 1] += s[i][j + 1] + s[i + 1][j] - s[i][j];
			}
		}
		bool ok = false;
		rep(x, 0, n - k + 1) {
			rep(y, 0, n - k + 1) {
				if (s[x + k][y + k] - s[x][y + k] - s[x + k][y] + s[x][y] <= k * k / 2) {
					ok = true;
					break;
				}
			}
			if (ok)break;
		}
		if (ok)r = m;
		else l = m;
	}
	printf("%d\n", r);
	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define FORI(i,v) for (auto i = v.begin(); i != v.end(); i++)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define REV(v) reverse(ALL(v))
#define UNIQ(v) sort(ALL(v)); v.erase(unique(ALL(v)),end(v))
#define CHMIN(x,y) x = min(x, y)
#define CHMAX(x,y) x = max(x, y)
#define YES(b) cout << ((b) ? "YES" : "NO") << endl
#define Yes(b) cout << ((b) ? "Yes" : "No") << endl

const int MAX = 20;

int N, M;
vii X[MAX];
ll dp[1<<MAX];

int main() {
    cout << fixed << setprecision(15);
    cin >> N >> M;
    REP (i, M) {
        int x, y, z;
        cin >> x >> y >> z;
        X[x].push_back(make_pair(y, z));
    }

    vector<bool> visit(1<<N, false);
    queue<int> q;
    q.push(0);
    dp[0] = 1;
    while (q.size()) {
        int state = q.front(); q.pop();
        int b = __builtin_popcount(state) + 1;
        REP (i, N) if ((state & (1<<i)) == 0) {
            int next = state | (1<<i);
            bool check = true;
            FORE (x, X[b]) {
                if (__builtin_popcount(next&((1<<(x.first))-1)) > x.second) check = false;
            }
            if (check) {
                dp[next] += dp[state];
                if (!visit[next]) {
                    q.push(next);
                    visit[next] = true;
                }
            }
        }
    }
    cout << dp[(1<<N)-1] << endl;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
const int N = 2e5+5;
using namespace std;
int a[N];
int main()
{
	int n;
	cin>>n;
	int m = pow(2,n);
	for(int i=0;i<m;i++){
		cin>>a[i];
	}
	int lmax = 0,rmax = m/2;
	for(int i=0;i<m/2;i++){
		if(a[lmax]<a[i]) lmax = i;
	}
	for(int i=m/2;i<m;i++){
		if(a[rmax]<a[i]) rmax = i;
	}
	if(a[lmax]<a[rmax]) printf("%d",lmax+1);
	else printf("%d",rmax+1);
	return 0;
}

// Problem: A - Maxi-Buying
// Contest: AtCoder - AtCoder Beginner Contest 206（Sponsored by Panasonic）
// URL: https://atcoder.jp/contests/abc206/tasks/abc206_a
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Author: tooler!
//
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,a,b) for(int i=a;i<=b;i++)
inline ll rd() {
	ll x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c))x=x*10+c-'0',c=getchar();
	return x*f;
}
#define d rd()
#define pb push_back
double x;
int main(){
	cin>>x;
	x*=1.08;
	if((int)x<206)cout<<"Yay!";
	else if((int)x==206)cout<<"so-so";
	else cout<<":(";
	return 0;
}


#include <bits/stdc++.h>

#define _overload(_1, _2, _3, _4, name, ...) name
#define _rep1(Itr, N) _rep3(Itr, 0, N, 1)
#define _rep2(Itr, a, b) _rep3(Itr, a, b, 1)
#define _rep3(Itr, a, b, step) for (i64(Itr) = a; (Itr) < b; (Itr) += step)
#define repeat(...) _overload(__VA_ARGS__, _rep3, _rep2, _rep1)(__VA_ARGS__)
#define rep(...) repeat(__VA_ARGS__)

using namespace std;
using i64 = long long;
using u64 = unsigned long long;

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

    i64 t;
    cin >> t;

    auto f = [](string &s, string &t) {
        int i = 0;
        int j = 0;

        while (j < t.size()) {
            while (i < s.size() && s[i] != t[j]) {
                i++;
            }
            j++;
        }

        return i < s.size();
    };

    repeat(_, t) {
        i64 n;
        cin >> n;
        string s[3];
        cin >> s[0] >> s[1] >> s[2];

        string cmp[4];

        {
            cmp[0].reserve(2 * n + 1);
            repeat(i, n) cmp[0].push_back('0');
            repeat(i, n) cmp[0].push_back('1');
            cmp[0].push_back('0');
        }
        {
            cmp[1].reserve(2 * n + 1);
            repeat(i, n) cmp[1].push_back('0');
            repeat(i, n) cmp[1].push_back('1');
            cmp[1].push_back('1');
        }
        {
            cmp[2].reserve(2 * n + 1);
            repeat(i, n) cmp[2].push_back('1');
            repeat(i, n) cmp[2].push_back('0');
            cmp[2].push_back('0');
        }
        {
            cmp[3].reserve(2 * n + 1);
            repeat(i, n) cmp[3].push_back('1');
            repeat(i, n) cmp[3].push_back('0');
            cmp[3].push_back('1');
        }

        repeat(i, 3) s[i] += s[i];

        bool out = false;
        repeat(i, 4) {
            if (f(s[0], cmp[i]) && f(s[1], cmp[i]) && f(s[2], cmp[i])) {
                cout << cmp[i] << '\n';
                out = true;
                break;
            }
        }

        assert(out);
    }

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int read()
{
	int 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<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*w;
}
string s1,s2,s3;
int mp[400010],n;
signed main()
{
	int T=read(),dfx=0;
	while(T--)
	{
		n=read();
		cin>>s1>>s2>>s3;
		cout<<0;
		for(int i=1;i<=n;i++) cout<<1;
		for(int i=1;i<=n;i++) cout<<0;
		cout<<'\n';
	}
	return 0;
}