#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
#define read(a) scanf("%d", &a)
#define x first
#define y second

#define N 1011

int n, m;
int ans;
char a[N][N], b[N][N];

int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
bool vis[N];
bool v[N][N][4];

struct state {
	int x, y, d;
};

queue <state> q;
bool ok(int x, int y) {
	return 1 <= x && x <= n && 1 <= y && y <= m;
}

void check(char g[N][N]) {
	while (!q.empty()) {
		auto o = q.front(); q.pop();
		int x = o.x, y = o.y, d = o.d;
		if (g[x][y] == '#' || !ok(x + dx[d], y + dy[d])) {
			vis[y] = 1;
			for (int i = 0; i < 4; i++) {
				v[x][y][i] = 1;
			}
			for (d = 0; d < 4; d++) {
				if (ok(x + dx[d], y + dy[d])) {
					if ( !v[x + dx[d]][y + dy[d]][d] ) {
						v[x + dx[d]][y + dy[d]][d] = 1;
						q.push({x + dx[d], y + dy[d], d});
					}
				}
			}
		}
		else if (ok(x + dx[d], y + dy[d])) {
			if ( !v[x + dx[d]][y + dy[d]][d] ) {
				v[x + dx[d]][y + dy[d]][d] = 1;
				q.push({x + dx[d], y + dy[d], d});
			}
		}
	}
}
void work(char g[N][N]) {
	memset(vis, 0, sizeof vis);
	vis[1] = 1; vis[m] = 1;
	memset(v, 0, sizeof v);
	int tot = 0;
	v[1][1][0] = 1;
	q.push({1, 1, 0});
	v[1][1][1] = 1;
	q.push({1, 1, 1});
	check(g);

	vector <int> op;
	for (int i = 1; i <= m; i++) if (!vis[i]) {
		op.push_back(i);
		g[1][i] = '#';
		tot++;
		q.push({1, i, 0});
		check(g);
	}

	for (auto x : op) {
		g[1][x] = '.';
	}
	ans = min(ans, tot);
}

int main() {
	read(n); read(m);
	ans = n;
	for (int i = 1 ;i <= n; i++) {
		scanf("%s", a[i] + 1);
	}
	work(a);

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			b[j][i] = a[i][j];
		}
	}
	swap(n, m);
	work(b);

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

}

//W4P3R
#include<bits/stdc++.h>
#define inf 1e9
#define eps 1e-6
#define mp make_pair
#define pb push_back
#define re register ll
#define fr first
#define sd second
#define pa pair<ll,ll>
#define FOR(i,a,b) for(re i=a;i<=b;i++)
#define REP(i,a,b) for(re i=a;i>=b;i--)
#define MEM(a) memset(a,0,sizeof(a))
#define N 2010
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
inline ll read()
{
	char ch=getchar();
	ll s=0,w=1;
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
	return s*w;
}
inline ll lowbit(ll x){return x&(-x);}
char s[N][N];
int n,m,vis[N],fa[N];
int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);}
inline void add(int x,int y){x=find(x),y=find(y);fa[x]=y;}
int main()
{
	//ios::sync_with_stdio(false);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	n=read(),m=read();
	FOR(i,1,n+m)fa[i]=i;
	FOR(i,1,n)
	{
		scanf("%s",s[i]+1);
		FOR(j,1,m)if(s[i][j]=='#')add(i,j+n);
	}
	add(1,n+1);add(1,n+m);add(1,n);
	int ans=0,num=0;
	FOR(i,1,n)if(!vis[find(i)])vis[find(i)]=1,num++;
	ans=num-1;MEM(vis);num=0;
	FOR(i,1,m)if(!vis[find(i+n)])vis[find(i+n)]=1,num++;
	ans=min(ans,num-1);MEM(vis);
	cout<<ans<<'\n';
	return 0;
}
//gl


#include<bits/stdc++.h>

using namespace std;

#define  GODSPEED       ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(15);
#define  f              first
#define  s              second
#define  newl           cout<<"\n";
#define  pb             push_back
#define  mset(a,x)      memset(a,x,sizeof(a))
#define  debv(a)        for(auto it: a)cout<<it<<" ";newl;
#define  deb1(a)        cout<<a<<"\n";
#define  deb2(a,b)      cout<<a<<" "<<b<<"\n";
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<"\n";
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define  uniq(a)        a.resize(unique(a.begin(), a.end()) - a.begin());
#define  all(a)         a.begin(),a.end()

typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;

const ll   N     =  5e5+5;
const ll   M     =  4e6+5;
const ll   mod   =  1e9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;

ll n, a, b;

ll fastmod(ll x, ll y = mod - 2){
	ll res = 1;
	while(y){
		if(y&1) res = res * x % mod;
		x = x * x % mod;
		y /= 2;
	}
	return res;
}

ll sum(ll x){
	return x * (x + 1) % mod * fastmod(2) % mod;
}

ll mul(ll x, ll y){
	return x * y % mod;
}

void solve(){
	cin >> n >> a >> b;
	ll x = n - b + 1;
	ll y = n - a - b + 1;
	ll z = n - a + 1;
	if(y <= 0){
		deb1(0)
		return;
	}
	ll s1 = mul(mul(sum(y), x), z), s2 = mul(sum(y), sum(y));
	deb1((4*(s1 - s2) + 4*mod) % mod)
}

int main(){
	GODSPEED;
	int test = 1;
	cin >> test;
	for(int i = 1; i <= test; i++){
		solve();
	}
}

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

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

const int mod=1e9+7;

int find(int n)
{
    int z=(n+1)*(n+2);
    z%=mod;
    return z;
}

signed main()
{

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

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

    int t;
    cin>>t;
    while(t--)
    {
        int n,a,b;
        cin>>n>>a>>b;
        if(a+b>n)
        {
            cout<<0<<'\n';
            continue;
        }
        int x=find(n-a-b);
        int ans=x*(n-a+1)%mod*(n-b+1)%mod;
        ans*=2;
        ans%=mod;
        ans+=(mod-x*x%mod)%mod;
        ans%=mod;
        cout<<ans<<'\n';
    }

}


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

const ll INF = 1e18;
const int MX = 2005;

int main() {
    ll n;
    cin >> n;
    vector<ll>A(n);
    rep(i,n) cin >> A[i];
    vector<ll>maxS(n);
    vector<ll>sumS(n);
    rep(i,n){
        if(i == 0){
            sumS[i] = A[0];
            maxS[i] = max(0ll,A[0]);
        }else{
            sumS[i] = sumS[i-1] + A[i];
            maxS[i] = max(maxS[i-1],sumS[i-1] + A[i]);
        }
    }
    ll m = 0;
    ll sum = 0;
    for(int i = 0; i < n; i++){
        if(sum + maxS[i] > m){
            m = sum + maxS[i];
        }
        sum += sumS[i];
    }
    cout << m << endl;
}

#include <bits/stdc++.h>

#define Fast cin.tie(0), ios::sync_with_stdio(0)
#define All(x) x.begin(), x.end()
#define louisfghbvc int t; cin >> t; while(t--)
#define sz(x) (int)(x).size()
using namespace std;
typedef long long LL;
typedef pair<LL, LL> ii;
typedef vector<LL> vi;

template<typename T> istream& operator>>(istream &is, vector<T> &v) { for(auto &it : v) is >> it; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep = ""; for(const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cerr << " end.\n"; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

const int N = 1e5+5;
const int inf = 0x3f3f3f3f;
/**
Read problem statement carefully
sum + len*y == x
**/

void solve(){
    int n;
    cin >> n;
    LL res = 1e9;
    LL mnA = 1e9, mnB = 1e9;
    for(int i = 0; i < n; ++i){
        LL a, b;
        cin >> a >> b;
        res = min({res, a+b, max(a, mnB), max(b, mnA)});
        mnA = min(mnA, a);
        mnB = min(mnB, b);
    }
    cout << res << "\n";
}

int main()
{
    Fast;
    //louisfghbvc
        solve();
    return 0;
}

/**
Enjoy the problem.
**/


#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=1e9+7;
const int siz=2e5;
const int inf=1e9;
vector<pair<int,long>> g[siz];
long dist[siz];
void dfs(int v, int par, long d){
	dist[v] = d;
	for(pair<int,long> p:g[v]){
		int u = p.first;
		long w = p.second;
		if(u == par) continue;
		dfs(u, v, d ^ w);
	}
}
long calc(long x, int j){
  	rep(i,0,j) (x *= 2) %= mod;
  	return x;
}
int main(){
	int N; cin>>N;
	int a,b; long c;
	rep(i,0,N-1){
		cin>>a>>b>>c; a--; b--;
		g[a].push_back({b, c});
		g[b].push_back({a, c});
	}
	dfs(0, -1, 0);
	long cnt[60] = {};
	rep(i,0,N)rep(j,0,60){
		if(dist[i] & (1L<<j)) cnt[j]++;
	}
	long ans = 0;
	rep(j,0,60) (ans += calc(cnt[j] * (N-cnt[j]) % mod, j)) %= mod;
	cout<<ans<<endl;
}

//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")

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

#define ll long long
#define ld long double
#define mod 1000000007
#define pb push_back
#define inf 1000000000000000000
#define ff first
#define ss second
#define deb(x) cout<<#x<<" "<<x<<"\n"
#define Clear(x) memset(x,0,sizeof(x))
#define all(x) (x).begin(),(x).end()

void checkpoint1()
{
    /******think more code less******/
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
        freopen("Error.txt", "w", stderr);
    #endif
}

bool comp(pair< ll,ll > &a,pair< ll,ll > &b)
{
    if(a.ff!=b.ff)
        return a.ff<b.ff;
    else
    {
        if(a.ss>b.ss)
            return b.ss<a.ss;
        else if(a.ss<b.ss)
            return a.ss<b.ss;
    }
    return a.ff>b.ff;
}

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

void terminAtor()
{
    ll n;
    cin>>n;
    vector< pair< ll,ll > > adj[n+1];
    for(ll i=1;i<n;i++)
    {
        ll x,y,z;
        cin>>x>>y>>z;
        adj[x].pb({z,y});
        adj[y].pb({z,x});
    }
    vector< bool > vis(n+1,0);
    vector< ll > dis(n+1,0);
    queue< ll > q;
    q.push(1);
    while(!q.empty())
    {
        ll v=q.front();
        q.pop();
        vis[v]=1;
        for(auto u:adj[v])
        {
            if(!vis[u.ss])
            {
                q.push(u.ss);
                dis[u.ss]=dis[v]^u.ff;
            }
        }
    }
    ll ans=0;
    for(ll i=0;i<60;i++){
        ll tot0=0,tot1=0;
        for(ll ii=1;ii<=n;ii++)
        {
            if(dis[ii]&(1LL<<i))
                tot1++;
            else
                tot0++;
        }
        tot1*=tot0;
        tot1%=mod;
        ll ok=(1LL<<i);
        ok%=mod;
        tot1*=(ok);
        tot1%=mod;
        ans+=tot1;
        ans%=mod;
    }
    cout<<ans;
}

int main()
{
    checkpoint1();
/********************************************************/
    auto startrrr = high_resolution_clock::now();
    cout << setprecision(20);
/*******************************************************/

    terminAtor();

/*******************************************************/
    auto stoprrr = high_resolution_clock::now();
    auto duration = duration_cast<microseconds>(stoprrr - startrrr);
    #ifndef ONLINE_JUDGE
        cerr << "Time: " << duration.count()/1000.0<<"\n";
    #endif
/*******************************************************/
    return 0;
}


/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <fstream>
#include <stdio.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip> //setprecision
#include <map> // map
#include <unordered_map> //unordered_map
#include <queue> // queue, priority_queue
#include <set> // set,multiset
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#include <numeric> //accumulate,,,
#include <sstream>
#include <random>
#include <initializer_list>
#define endl "\n";
using namespace std;

const long long INF = 4000000000000000001;
const int inf = 1001001001;
const long long MOD = 998244353;
//const long long MAXIMUM = INFINITY;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M, long long mod) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % mod, M / 2,mod);
    //When end-of-a bit is 1, times simple N.
    if (M & 1) res = (res * N) % mod;
    return res %= mod;
}
long long gcd(long long a, long long b) {
    if (b == 0) return a; else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}
long long get_mod(long long res){
    if(res < 0) res += MOD;
    return res % MOD;
}

typedef tuple<int,long long,long long> tup;

vector<vector<tup>> Edge(100005);
vector<long long> pre(100005,-1);
vector<long long> dist(100005,INF);

void dijkstra(){
    priority_queue<pair<long long,int>,vector<pair<long long,int>>,greater<pair<long long,int>>> PQ;
    PQ.emplace(0,0);
    dist.at(0) = 0;
    while(!PQ.empty()){
        int now = PQ.top().second;
        long long d = PQ.top().first;
        PQ.pop();
        if(dist.at(now) < d) continue;

        for(tup t : Edge.at(now)){
            int to = get<0>(t);
            long long C = get<1>(t);
            long long D = get<2>(t);
            long long r = d;
            // rが一番いい時間として、Di/t+1 + t+1 の最小値は√Diで取る（それはそう）
            if(sqrt(D) < d) r = d;
            else r = sqrt(D);
            long long COST = C + D/(r+1);
            if(dist[to] > COST + r){
                dist[to] = COST + r;
                PQ.emplace(COST+r , to);
            }
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    /*FILE* in = freopen("answer.txt", "w", stdout);
    ifstream ifs("in.txt"); // 巨大ケースは in.txt に書いてifsで標準入力*/

    int N;cin >> N;
    int M;cin >> M;
    for(int i = 0;i<M;i++){
        int a,b;long long c,d;cin >> a >> b >> c >> d;a--;b--;
        if(a == b) continue;
        Edge.at(a).emplace_back(b,c,d);
        Edge.at(b).emplace_back(a,c,d);
    }

    dijkstra();

    if(dist[N-1] == INF){
        cout << -1 << endl;
    }
    else{
        cout << dist[N-1] << endl;
    }

}

#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>
#include <limits>
#include <math.h>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define Pll pair<long,long>
#define mp make_pair
#define INF 1000000001
#define INFl 1000000000000000001
#define ll long long
using namespace std;

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

long time(long t,long c,long d){
    if(t<0)return INFl;
    return c+d/(t+1);
}

struct edge{long to,c,d;};

int main() {
    int N,M;cin>>N>>M;

    int X,Y,V;//始点X終点Y頂点数V
    V=N;
    vector< vector< edge > > G(V,vector<edge>(0));
    rep(i,M){
        long a,b,c,d;cin>>a>>b>>c>>d;
        if(a==b)continue;
        a--;b--;
        edge e={b,c,d};
        G[a].push_back(e);
        edge e2={a,c,d};
        G[b].push_back(e2);
    }
    X=0;Y=N-1;

    vector<long>d(V,INFl);
    priority_queue<Pll,vector<Pll>,greater<Pll> > que;
    for(int i=0;i<V;i++){d[i]=INFl;}
    d[X]=0;
    que.push(Pll(0,X));//コスト，頂点

    while(!que.empty()){
        Pll p=que.top();que.pop();
        long v=p.second;
        if(d[v]<p.first)continue;
        for(int i=0;i<G[v].size();i++){
            edge e=G[v][i];
            long to=e.to;
            long c=e.c;
            long t=d[v];
            long D=e.d;
            long left=t;
            long right=INFl/10;

            for(int i=0;i<100;i++){
                long c1=(left*2+right)/3;
                long c2=(left+right*2)/3;
                long a1=c1+time(c1,c,D);
                long a2=c2+time(c2,c,D);
                if(a1>=a2){
                    left=c1;
                }else{
                    right=c2;
                }
            }
            long cost=INFl;
            long pc=INFl;
            for(long x=250;x>=-250;--x){
                if(left+x<t)break;
                cost=min(cost,left+x+time(left+x,c,D));
                if(cost>pc)break;
                pc=cost;
            }
            //cout<<v<<" "<<to<<" "<<left<<" "<<cost<<endl;
            if(d[to]>cost){
                d[to]=cost;
                que.push(Pll(d[to],to));
            }
        }
    }
    if(d[Y]==INFl)cout<<-1<<endl;
    else cout<<d[Y]<<endl;
}


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

using namespace std;
using LL = long long;
using P = pair<LL,int>;
const LL INF = (LL)1e18;

struct edge{
  int to;
  LL T, K;
  edge(int to, LL T, LL K) : to(to), T(T), K(K) {}
};

int main(){
  int N, M, X, Y;
  cin >> N >> M >> X >> Y;
  X--; Y--;
  vector<vector<edge>> G(N);
  rep(i,M){
    int a, b;
    LL t, k;
    cin >> a >> b >> t >> k;
    a--; b--;
    edge e1(b, t, k);
    edge e2(a, t, k);
    G[a].emplace_back(e1);
    G[b].emplace_back(e2);
  }
  priority_queue<P, vector<P>, greater<P>> q;
  vector<LL> dist(N, INF);
  dist[X] = 0;
  q.push(P(0, X));
  while(!q.empty()){
    P p = q.top(); q.pop();
    int u = p.second;
    LL d = p.first;
    if(d > dist[u]) continue;
    for(auto e : G[u]){
      int v = e.to;
      LL t = e.T, k = e.K;
      LL cost = t + k - d % k;
      if(d % k == 0) cost -= k;
      if(dist[v] < d + cost) continue;
      dist[v] = d + cost;
      q.push(P(dist[v], v));
    }
  }
  LL ans = dist[Y];
  if(ans == INF) ans = -1;
  cout << ans << endl;

  return 0;
}

#include<bits/stdc++.h>

using namespace std;

const int N=1e5+5;
const int mod=1e9+7;

bool visited[N];
long long dist[N];
vector<pair<int,pair<int,int>>>adj[N];
priority_queue<pair<long long,int>>pq;

void Dijkstra()
{
    int k,t,x,y;
    long long val;
    while(!pq.empty())
    {
        val=-pq.top().first;
        x=pq.top().second;
        pq.pop();
        if(visited[x])continue;
        visited[x]=1;
        for(auto it : adj[x])
        {
            y=it.first;
            t=it.second.first;
            k=it.second.second;
            if(dist[y] > ((val+k-1)/k)*k+t)
            {
                dist[y]=((val+k-1)/k)*k+t;
                pq.emplace(-dist[y],y);
            }
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b,i,k,m,n,t,x,y;
    cin >> n >> m >> a >> b;
    while(m--)
    {
        cin >> x >> y >> t >> k;
        adj[x].push_back({y,{t,k}});
        adj[y].push_back({x,{t,k}});
    }
    for(i=1;i<=n;i++)dist[i]=LLONG_MAX;
    dist[a]=0;
    pq.emplace(0,a);
    Dijkstra();
    if(dist[b] == LLONG_MAX)cout << "-1";
    else cout << dist[b];
    return 0;
}
//


#include <bits/stdc++.h>

clock_t start;

constexpr int H = 50, W = 50;
int si, sj;
int t[H][W], p[H][W];

struct cand {
    std::string s;
    int score, i, j;
    std::vector<bool> seen;
    bool operator<(const cand& rhs) const { return score < rhs.score; }
    bool valid(const char& c) {
        if (c == 'L') return (0 < j && !seen[t[i][j - 1]]);
        if (c == 'R') return (j < W - 1 && !seen[t[i][j + 1]]);
        if (c == 'U') return (0 < i && !seen[t[i - 1][j]]);
        if (c == 'D') return (i < H - 1 && !seen[t[i + 1][j]]);
    }
    cand move(const char& c) {
        cand ret = *this;
        ret.s.push_back(c);
        if (c == 'L') ret.j--;
        else if (c == 'R') ret.j++;
        else if (c == 'U') ret.i--;
        else ret.i++;
        ret.score += p[ret.i][ret.j];
        ret.seen[t[ret.i][ret.j]] = true;
        return ret;
    }
};

int main() {
    start = clock();

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

    std::cin >> si >> sj;
    for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) std::cin >> t[i][j];
    for (int i = 0; i < H; i++) for (int j = 0; j < W; j++) std::cin >> p[i][j];

    constexpr int N = 1000;
    int n = 1;
    std::vector<bool> seen(H * W, false);
    seen[t[si][sj]] = true;
    cand ans = {"", p[si][sj], si, sj, seen};
    std::vector<cand> c(N, ans);
    while (clock() - start <= 1.95 * CLOCKS_PER_SEC) {
        std::priority_queue<cand> pq;
        for (int i = 0; i < n; i++) {
            ans = std::max(ans, c[i]);
            if (c[i].valid('L')) pq.push(c[i].move('L'));
            if (c[i].valid('R')) pq.push(c[i].move('R'));
            if (c[i].valid('U')) pq.push(c[i].move('U'));
            if (c[i].valid('D')) pq.push(c[i].move('D'));
        }
        n = std::min(N, (int)pq.size());
        for (int i = 0; i < n; i++) {
            c[i] = pq.top();
            pq.pop();
        }
    }
    std::cout << std::max(ans, c[0]).s << '\n';
}

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

#define ll long long int
#define absdiff(a,b) (a>b)?a-b:b-a
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define fast  ios_base::sync_with_stdio(false);cin.tie(0);
#define MOD 1000000007
#define ll_MAX 19223372036859
#define endl "\n"
ll fast_expo(ll x,ll p){
  if(p==0) return 1;
  else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;}
  else return (x*(fast_expo(x,p-1))%MOD)%MOD;}

ll dp[1005][1005], n, m, arr1[1005], arr2[1005];
vector<ll> AdjL[1005];

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

  ll t_c; t_c = 1;
  // cin >> t_c;

  for(ll t_i = 0; t_i < t_c; ++t_i){
    ll n, m; cin >> n >> m;
    ll a[n + 1], b[m + 1];
    for(ll i = 1; i <= n; ++i)
      cin >> a[i];
    for(ll i = 1; i <= m; ++i)
      cin >> b[i];

    ll dp[n + 1][m + 1];
    for(ll j = 0; j <= m; ++j){
      dp[0][j] = j;
    }

    for(ll i = 1; i <= n; ++i){
      dp[i][0] = i;
      for(ll j = 1; j <= m; ++j){
        if(a[i] == b[j]) dp[i][j] = dp[i - 1][j - 1];
        else dp[i][j] = min({dp[i - 1][j] + 1, dp[i][j - 1] + 1, dp[i - 1][j - 1] + 1});
      }
    }

    cout << dp[n][m];
  }
  return 0;
}


#include<map>
#include<set>
#include<stack>
#include<queue>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>

#define NZB  ios::sync_with_stdio(false)

typedef long long ll;
const int inf = 1e9 + 7;
const int mod = 1e9 + 7;
const int MAX_N = 1e3 + 7;

using namespace std;

int a[MAX_N], b[MAX_N];
int dp[MAX_N][MAX_N];

int main()
{
	NZB;
	int N, M;
	cin>>N>>M;
	for(int i=1;i<=N;i++) cin>>a[i];
	for(int i=1;i<=M;i++) cin>>b[i];
	memset(dp, 63, sizeof(dp));
	for(int i=0;i<=N;i++) {
		for(int j=0;j<=M;j++) {
			if(!i || !j) {
				dp[i][j] = max(i, j);
				continue;
			}
			dp[i][j] = min(dp[i][j-1], dp[i-1][j]) + 1;
			if(a[i] == b[j]) dp[i][j] = min(dp[i][j], dp[i-1][j-1]);
			else dp[i][j] = min(dp[i][j], dp[i-1][j-1] + 1);
			//printf("(%d,%d,%d)", i,j ,dp[i][j]);
		}
	}
	cout<<dp[N][M]<<endl;
}

#include<bits/stdc++.h>

using namespace std;

long long n,L,A[2];

string s[200005];

int main() {
    cin>>n>>L;
    for(int i=1;i<=n;i++)
    	cin>>s[i];
    A[0]=1;
    for(int i=2;i<=n;i++) {
    	int cnt=0;
    	for(int j=0;j<L;j++)
    		if(s[i][j]!=s[1][j])
    			cnt++;
    	A[cnt%2]++;
 	}
 	cout<<A[0]*A[1];
	return 0;
   }


#include <bits/stdc++.h>
using namespace std;
using ll = long long;//大きなint型
using ld = long double;//大きなdouble型
using P = pair<int,int>;//pair型の型エイリアス
#define rep(i,n) for (int i = 0; i < (n); ++i)//iをnまですすめる。
#define PI 3.14159265359

int main(){
    int n,m;
    int ans = 0;
    int last_ans = 0;
    cin>>n>>m;
    int sara[n+1] = {0};
    vector<int> a(m),b(m);
    rep(i,m) cin>>a.at(i)>>b.at(i);
    int k;
    cin>>k;
    vector<int> c(k),d(k);
    rep(i,k) cin>>c.at(i)>>d.at(i);

    //bit全探索
    for(int bit = 0;bit < (1 << k); ++bit){
        rep(i,n+1) sara[i]=0;
        ans = 0;
        rep(i,k){
            if(bit & (1<<i)){//True
                sara[d.at(i)] = 1;
            }
            else sara[c.at(i)] = 1;
        }
        rep(i,m){
            //条件確認
            if(sara[a.at(i)] == 1 && sara[b.at(i)] == 1) ans++;
        }
        last_ans = max(ans,last_ans);//達成した条件数が大きいほうを保存

    }
    cout << last_ans;

}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int MAXN = 110;
int a[MAXN], b[MAXN];
int ball[MAXN];
int c[20], d[20];
int n, m, k;
int ans = 0;
void dfs(int x) {
    if (x > k) {
        int cnt = 0;
//        for (int i = 1; i <= n; i++) {
//            cout << ball[i] << " ";
//        }
//        cout << endl;
        for (int i = 1; i <= m; i++) {
            if (ball[a[i]] && ball[b[i]]) {
                //cout << c[i] << " " << d[i] << endl;
                cnt++;
            }
        }
        //cout << "cnt:" << cnt << endl;
        ans = max(ans, cnt);
        return;
    }
    ball[c[x]]++;
    dfs(x + 1);
    ball[c[x]]--;
    ball[d[x]]++;
    dfs(x + 1);
    ball[d[x]]--;
}
int main() {
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        cin >> a[i] >> b[i];
    }
    cin >> k;
    for (int i = 1; i <= k; i++) {
        cin >> c[i] >> d[i];
    }
    dfs(1);
    cout << ans;
    return 0;
}


# include<bits/stdc++.h>

using namespace std;
# define l long long
# define db double
# define rep(i,a,b) for(l i=a;i<b;i++)
# define vi vector<l>
# define vvi vector<vi>
# define vsi vector<set<l> >
# define pb push_back
# define mp make_pair
# define ss second
# define ff first
# define pii pair<l,l>
# define trvi(v,it) for(vi::iterator it=v.begin();it!=v.end();++it)
# define read(a) freopen(a,"r",stdin)
# define write(a) freopen(a,"w",stdout)
# define io ios::sync_with_stdio(false)

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ' ' << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }

#ifdef KRISHNAN_DEBUG
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

const bool MULTIPLE_TEST_CASES = false;

const l MOD=1e9+7;
const l N=1e5+5;
const l INF=1e12;

void solve() {
	l n,m;
	cin>>n>>m;
	cout<<(m%n==0?"Yes":"No")<<"\n";
	return;
}

int main(){
	io;
	int t=1;
	if (MULTIPLE_TEST_CASES) cin>>t;
	rep(i,0,t) {
		solve();
	}

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    int n;
    cin>>n;
    vector<pair<int,string>> v(n);
    rep(i,n){
        string s;
        int t;
        cin>>s>>t;
        v[i]={t,s};
    }

    sort(all(v));
    cout<<v[n-2].second<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define lli   long long int
#define nl    "\n"
#define pb(k)  push_back(k)
#define vi     vector<int>

bool ispali(string s)
{
    bool ispalin = true;
    int i = 0 ;
    int j = s.size() - 1 ;
    while(i<j)
    {
        if(s[i]!=s[j])
        {
            ispalin = false;
        }
        i++;
        j--;
    }
    return ispalin;
}
float distance(int x1, int y1, int x2, int y2)
{
    // Calculating distance
    return sqrt(pow(x2 - x1, 2) +
                pow(y2 - y1, 2) * 1.0);
}
void solve()
{

    int n;
    cin>>n;
    vi input1;
    vi input2;
    for(int i = 0 ; i<n ; ++i)
    {
        int k ;
        cin>>k;
        input1.pb(k);
    }
    for(int i = 0 ; i<n ; ++i)
    {
        int k ;
        cin>>k;
        input2.pb(k);
    }
    int sum = 0 ;
    for(int i = 0 ; i<n ; ++i)
    {
        sum += input1[i]*input2[i];
    }
    if(sum==0)
    {
        cout<<"Yes"<<nl;
    }
    else
    {
        cout<<"No"<<nl;
    }

}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   #ifndef ONLINE_JUDGE
    freopen("input.txt" , "r" , stdin);
    freopen("output.txt" , "w" , stdout);
    #endif
    solve();

}
//river
//


#include <bits/stdc++.h>

#define                 ll long long int
#define                 pii pair <int, int>
#define                 pb push_back
#define                 M 1000000007
#define                 umap unordered_map
#define                 uset unordered_set
#define                 endl "\n"
#define                 loop(i,x,n) for(ll i = x; i < n; i++)
#define                 rloop(i,x,n) for(ll i = n-1; i >= x ; i--)
#define                 SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define                 vi vector <ll>
#define                 all(x) x.begin(), x.end()
#define                 yes cout << "YES\n"
#define                 no cout << "NO\n"
#define                 f first
#define                 s second

using namespace std;

void seive(int N)
{
// move it up
    vi isprime(N , true);
    vi prime;
    vi SPF(N);
    vi primes;
// this block

    isprime[0] = isprime[1] = false ;

    for (ll i = 2; i < N ; i++)
    {
        if (isprime[i])
        {
            prime.push_back(i);
            SPF[i] = i;
        }
        for (ll j = 0;
                j < (int)prime.size() &&
                i * prime[j] < N && prime[j] <= SPF[i];
                j++)
        {
            isprime[i * prime[j]] = false;
            SPF[i * prime[j]] = prime[j] ;
        }
    }
    for (int i = 0; i < prime.size() && prime[i] <= N ; i++)
        primes.pb(prime[i]);
}

bool is_prime(ll n) {

    if (n == 1) {
        return false;
    }

    int i = 2;
    while (i * i <= n) {
        if (n % i == 0) {
            return false;
        }
        i += 1;
    }
    return true;
}

long long exponensiation(long long a, long long b) {
    a %= M;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a % M;
        b >>= 1;
    }
    return res;
}
//____________________________________________________________________________________________

vector <ll> dic;
void pre() {
    ll x = 0;
    for (int i = 1; i < 1000000; i++) {
        x += i;
        dic.pb(x);
    }
}

void solve()
{
    ll x;
    cin >> x;
    ll ans = lower_bound(dic.begin(), dic.end(), x) - dic.begin() + 1;
    cout << ans << '\n';
}

//____________________________________________________________________________________________

int main() {

//____________________________________________________________________________________________
//#ifndef ONLINE_JUDGE
//  freopen("input.txt", "r", stdin);
//  freopen("output.txt", "w", stdout);
//#endif
//____________________________________________________________________________________________

    SPEED;
    pre();
    double T = 1;
    //cin >> T;
    while (T--) {
        solve();
    }
    return 0;

}

/*****************************
*  Author :: Πρασαννα Κ. Ροι *
*****************************/

/***********************************
* Unus pro omnibus, omnes pro uno  *
***********************************/
#include<bits/stdc++.h>
using namespace std;
using namespace std::chrono;

#define __AcHiLlEs ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define span(a) begin(a), end(a)

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

int bSearch(int val) {
  int l = 0, r = 100000;
  while (r - l > 1) {
    int m = (l + r) >> 1;
    int sum = (m * (m + 1)) / 2;
    if (sum >= val) r = m;
    else l = m;
  }
  return r;
}

void solve() {
  int n;
  cin >> n;
  cout << bSearch(n) << "\n";
}

signed main() {
  // auto start = high_resolution_clock::now();
  __AcHiLlEs

  int t(1);
  // cin >> t;
  for (int i = 1; i <= t; /*cout << "Case " << i << ": ",*/ solve(), i++);
  // auto stop = high_resolution_clock::now();
  // double duration = duration_cast<microseconds>(stop - start).count();
  // cout << fixed << setprecision(4) << duration / 1000000 << "\n";
  return 0;
}


#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <stack>
#include <queue>
#include <vector>

static const int IINF = 1 << 30;
static const long long LINF = 1LL << 60;
static const long long MOD = 1.0e+9 + 7;

template <typename T> std::vector<T> vectors(std::size_t n, T val) {
  return std::vector<T>(n, val);
}

template <typename T, typename... Args>
auto vectors(std::size_t n, Args... args) {
  return std::vector<decltype(vectors<T>(args...))>(n, vectors<T>(args...));
}

template <class T> inline bool chmin(T &a, const T &b) {
  return (a > b) ? a = b, true : false;
}

template <class T> inline bool chmax(T &a, const T &b) {
  return (a < b) ? a = b, true : false;
}

template <class T> inline void chadd(T &a, const T &b) {
  a += b, a %= MOD;
  // TODO minus case
}

template <class T>
std::ostream &operator<<(std::ostream &stream, const std::vector<T> &vec) {
  for (auto val : vec) {
    if (std::is_fundamental<T>::value)
      stream << " " << val;
    else
      stream << std::endl << val;
  }
  return stream;
}

int main() {
  int n;
  std::cin >> n;
  std::vector<std::string> s(n);
  std::vector<std::pair<int, int>> ti(n);
  for (int i = 0; i < n; ++i) {
    int tmp;
    std::cin >> s[i] >> tmp;
    ti[i] = std::make_pair(tmp, i);
  }
  std::sort(ti.begin(), ti.end(), std::greater<std::pair<int, int>>());
  std::cout << s[ti[1].second] << std::endl;
}

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

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

    int n;
    cin >> n;
    vector<pair<int, string>> a(n);
    for (auto &[f, s] : a) {
        cin >> s >> f;
    }
    sort(a.rbegin(), a.rend());
    cout << a[1].second << endl;
}


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

#define ll long long
#define tej ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);

#define ve vector<int>
#define vl vector<long long int>
#define vp vector<pair<long long int,long long int>>
#define pb push_back
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define bp pop_back
#define fp pop_front
#define mp make_pair

#define fo(i,n) for(i=0;i<n;i++)
#define unq(v)      unique(v.begin(), v.end())-v.begin()
#define fnd(v,a)    find(v.begin(), v.end(), a)
#define uprb(v,a)   upper_bound(v.begin(), v.end(), a)
#define upra(v,n,a) upper_bound(v, v+n, a)
#define lowb(v,a)   lower_bound(v.begin(), v.end(), a)
#define lowa(v,n,a) lower_bound(v, v+n, a)
#define newuv(v)    v.erase(unique(v.begin(),v.end()),v.end())
#define rev(v)      reverse(v.begin(),v.end())
#define rndshf(v)   random_shuffle(v.begin(),v.end())
#define all(v)      v.begin(),v.end()

// ll po(ll a,ll b,ll m)
// {
// ll t=1;
// while(b>0)
// {
//     if(b%2!=0)
//     {
//         t=(t*a)%m;
//     }
//     a=(a*a)%m;
//     b=b/2;
// }
// return t;
// }
// ll po(ll a,ll b)
// {
// ll t=1;
// while(b>0)
// {
//     if(b%2!=0)
//     {
//         t=(t*a);
//     }
//     a=(a*a);
//     b=b/2;
// }
// return t;
// }
// ll inv(ll a,ll m)
// {
//   return po(a,m-2,m);
// }
// ll vis[100002]={0},x=0;
// vl v[100002];
// ll dfs(ll s)
// {
//   ll c=1,i;
//   for(i=0;i<v[s].size();i++)
//   {
//     if(vis[v[s][i]]==0)
//     {
//       vis[v[s][i]]=1;
//       c+=dfs(v[s][i]);
//     }
//   }
//   x+=c-1;
//   //cout<<x<<endl;
//   return c;
// }
//map<ll,ll>m;
void solve()
{
   ll n,m,i,x,mi,c=0;
   cin>>n>>m;
   vl v,v1;
   fo(i,m)
   {
    cin>>x;
    v.pb(x);
   }
   if(n==m)
   {
    cout<<0;
    return;
   }
   else if(m==0)
   {
    cout<<1;
    return;
   }
   sort(all(v));
   if(v[0]!=1)
    v1.pb(v[0]-1);

   for(i=1;i<m;i++)
   {
    if(v[i]-v[i-1]-1>0)
      v1.pb(v[i]-v[i-1]-1);
   }
    if(v[m-1]!=n)
    v1.pb(n-v[m-1]);

    if(v1.size()==0){
    cout<<"0\n";
    return ;
  }

  sort(all(v1));
  mi=v1[0];
  c=0;
   fo(i,v1.size())
   {

    c+=v1[i]/mi;
    if(v1[i]%mi!=0)
      c++;
   }

   cout<<c;
}

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

#include <algorithm>
#include <iostream>
#include <vector>

int main() {
    int n, m;
    std::cin >> n >> m;
    std::vector<int> a(m);
    for (int mi = 0; mi < m; ++mi) std::cin >> a[mi];

    std::vector<int> lengths;
    std::sort(a.begin(), a.end());
    for (int mi = 0; mi < m; ++mi) {
        int prev = (mi == 0 ? 0 : a[mi - 1]);
        if (a[mi] - prev - 1 > 0) lengths.push_back(a[mi] - prev - 1);
    }
    if (n - (a.size() > 0 ? a.back() : 0) > 0) lengths.push_back(n - (a.size() > 0 ? a.back() : 0));
    if (lengths.empty()) {
        std::cout << 0 << std::endl;
        return 0;
    }
    std::sort(lengths.begin(), lengths.end());
    int k = lengths[0];
    int ans = 0;
    for (int len : lengths) {
        ans += (len + k - 1) / k;
    }
    std::cout << ans << std::endl;
}


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

#define all(x) x.begin(), x.end()
#define rall (x) x.rbegin(), x.rend()
#define pb push_back
#define eb emplace_back
#define mp make_pair

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

const int MOD = 1e9+7;

int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    vi arr(4);
    int cs = 0;
    for (auto &i: arr)
        cin >> i, cs += i;
    bool pos = false;
    for (int i=0; i<4; i++){
        if (arr[i]==cs-arr[i]) pos = true;
    }
    for (int i=0; i<4; i++)
        for (int j=i+1; j<4; j++){
            int cur = arr[i]+arr[j];
            if (2*cur==cs) pos = true;
        }
    cout << (pos?"Yes\n":"No\n");
}

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

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

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

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

int main(void)
{

    ll Sc, P, N, M, Q, A, B, C, D, K, T;
    string Str, Pat, Text;
    cin >> N >> M >> T;
    vv<ll> times(M, vl(2, 0) );

    REP(i, M)
    {
        cin >> times[i][0] >> times[i][1];
    }

    bool res = true;
    ll rem = N;
    ll time = 0;
    REP(i, M)
    {
        rem -= times[i][0] - time;
        if(rem<=0)
        {
            res = false;
            break;
        }

        rem = min(rem+times[i][1]-times[i][0], N);

        time = times[i][1];
    }

    rem -= T-time;

    if(rem <= 0) res = false;

    if(res) cout << "Yes"<<endl;
    else cout << "No" << endl;

    return 0;
}


// Problem: A - Not coprime
// Contest: AtCoder - AtCoder Regular Contest 114
// URL: https://atcoder.jp/contests/arc114/tasks/arc114_a
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)

/* Author : Atahar Islam Shihab
   ICT'16th Batch,MBSTU
*/
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define ll long long
#define maxele(v) *max_element(v.begin(),v.end())
#define minele(v) *min_element(v.begin(),v.end())
#define deb(x) cout << #x << " -> " << x << endl
#define deb2(x, y) cout << #x << " -> " << x << " || " << #y << " -> " << y << endl
#define fast  (ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0))
#define all(v) v.begin(),v.end()
#define sz(x) x.size();
#define clr(x) memset(x, 0, sizeof(x))
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
const int mxn = 100005;

int main()
{
  fast;
  int tc ;
  int n;
  cin >> n;
  vector<ll>v(n);
  for(int i=0;i<n;++i){
  	cin >> v[i];
  }
  sort(all(v));

  vector<ll>prime;

  for(int i=2;i<=50;++i){
  	bool ok = true;
  	for(int j=2;j*j<=i;++j){
  		if (i%j==0) {
  			ok=false;
  			break;
  		}
  	}
  	if (ok) prime.pb(i);
  }

  vector<ll>sub;
  for(ll i=0; i< (1<<15) ;++i){
  	ll res=1;
  	for(ll j=0;j<15;++j){
  		if (i&(1<<j)){
  			res*=prime[j];
  		}
  	}
  	if (res>1)
  		sub.pb(res);
  }
  sort(all(sub));

  ll ans=0;
  for(int i=0;i<sub.size();++i){
  	bool ok = true;
  	for(int j=0;j<n;++j){
  		if (__gcd(sub[i],v[j])<2){
  			ok=false;
  			break;
  		}
  	}
  	if (ok){
  		cout << sub[i] <<'\n';
  		break;
  	}
  }

  return 0;
}

#include<bits/stdc++.h>
#define L(i, j, k) for(int i = j, i##E = k; i <= i##E; i++)
#define R(i, j, k) for(int i = j, i##E = k; i >= i##E; i--)
#define ll long long
#define ull unsigned long long
#define db double
#define pii pair<int, int>
#define mkp make_pair
#define sz(a) ((int) (a).size())
using namespace std;
const int N = 1e5 + 7;
int n, Prime[N], p[N], tot;
ll a[N], ans = 7e18;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cin >> n;
	L(i, 1, n) cin >> a[i];
	L(i, 2, 50) Prime[i] = true;
	L(i, 2, 50) L(j, 2, 50 / i) Prime[i * j] = false;
	L(i, 2, 50) if(Prime[i]) p[++tot] = i;
	L(i, 1, (1 << tot) - 1) {
		ll val = 1;
		L(j, 1, tot) if(i >> (j - 1) & 1) val *= p[j];
		bool ok = true;
		L(j, 1, n) {
			if(__gcd(a[j], val) == 1) {
				ok = false;
				break;
			}
		}
		if(ok) ans = min(ans, val);
	}
	cout << ans << "\n";
	return 0;
}


#include<iostream>
#include<vector>
using namespace std;
using ll=long long;

int main(){
  int n,k;cin>>n>>k;
  vector<vector<ll>>f(n+1,vector<ll>(n+1,-1));

  ll right=0,left=-1;
  for(int y=0;y<n;y++){
    for(int x=0;x<n;x++){
      cin>>f.at(x+1).at(y+1);
      right=max(right,f.at(x+1).at(y+1));
    }
  }

  while(right-left>1){
    ll mid=(right+left)/2;
    vector<vector<ll>>s(n+1,vector<ll>(n+1,0));
    bool judge=false;

    for(int y=1;y<=n;y++){
      for(int x=1;x<=n;x++){
	s.at(x).at(y)=s.at(x-1).at(y)+s.at(x).at(y-1)-s.at(x-1).at(y-1);
	if(f.at(x).at(y)>mid)s.at(x).at(y)++;
      }
    }

    for(int y=1;y+k-1<=n;y++){
      for(int x=1;x+k-1<=n;x++){
	ll tmp=s.at(x+k-1).at(y+k-1)-s.at(x-1).at(y+k-1)-s.at(x+k-1).at(y-1)+s.at(x-1).at(y-1);
	if(tmp<(k*k)/2+1)judge=true;
      }
    }

    if(judge)right=mid;
    else left=mid;
  }

  cout<<right<<endl;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb pushback
#define fr(i,n) for(int i=0;i<n;i++)
#define fro(i,j,n) for(int i=j;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)

int main() {
    int h,w;
	cin >> h>>w;
    string s[h];
  int ans=0;
    fr(i,h){
      cin >> s[i];
    }
    fr(i,h-1){
      fr(j,w-1){
        int count=0;
        if(s[i][j]=='#')count++;
        if(s[i+1][j]=='#')count++;
        if(s[i][j+1]=='#')count++;
        if(s[i+1][j+1]=='#')count++;
        if(count==1||count==3)ans++;
      }
    }
      cout << ans << endl;
}


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

const ll MX = 1e18;
const long double PI = acos(-1);

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T> inline vector<T> divisor(T n) {
    vector<T> ret;
    for (T i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}

template<class T> inline vector<pair<T, T>> prime_factor(T n) {
    vector<pair<T, T>> ret;
    for (T i = 2; i * i <= n; i++) {
        if (n % i != 0) continue;
        T tmp = 0;
        while (n % i == 0) {
            tmp++;
            n /= i;
        }
        ret.push_back(make_pair(i, tmp));
    }
    if (n != 1) ret.push_back(make_pair(n, 1));
    return ret;
}

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

    vector<int> bc(n); rep(i, n) bc[b[c[i]]] += 1;
    ll count = 0;
    rep(i, n)
    {
        count += bc[a[i]];
    }

    pri(count);
    return 0;
}

#include<bits/stdc++.h>
#define int long long
#define uc getchar()
#define ph putchar
#define R register
#define CN const
#define rint R int
#define cint CN int
#define ps ph(' ')
#define pe ph('\n')
using namespace std;
cint inf=1e9+7;
cint mix=2e7+5;
inline int in();
inline void out(rint x);
int n=in(),k=in();
int c[10],nt;
inline int f(rint x){
	nt=0;
	while(x)c[++nt]=x%10,x/=10;
	sort(c+1,c+nt+1);
//cerr<<nt<<endl;
	rint rt=0;
	for(rint i=1;i<=nt;++i)
	(rt*=10)+=c[nt+1-i]-c[i];
	return rt;
}
#undef int
int main() {
#define int long long
	while(k--)n=f(n);
	out(n),pe;
}
inline int in() {
	rint x=0;
	R bool f=0;
	R char s=uc;
	while((s<'0'||'9'<s)&&s!='-')s=uc;
	if(s=='-')f=1,s=uc;
	while('0'<=s&&s<='9')(x*=10)+=s^48,s=uc;
	return f?-x:x;
}
inline void out(rint x) {
	if(x<0)ph('-'),x=-x;
	rint y=x/10;
	if(y)out(y);
	ph((x-y*10)^48);
}


//#include <atcoder/all>
//using namespace atcoder;
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPR(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(x) int(x.size())
using P = pair<int, int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 2e9;
const ll LINF = (1LL<<60);

const int mod = 1000000007;
//const int mod = 998244353;
struct mint {
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t; cin >> t;
  while(t--){
    int n,a,b; cin >> n >> a >> b;
    if(n-a-b<0){
      cout << 0 << endl;
      continue;
    }

    mint ans = mint(n-a-b+2) * (n-a-b+1);
    ans = mint(n-a+1)*(n-b+1) - ans;
    ans *= ans;
    mint total = mint(n-a+1).pow(2) * mint(n-b+1).pow(2);
    cout << total - ans << endl;
  }

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,x,n) for(int i=x;i<(int)n;++i)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define out(a) cout<<a<<endl;
#define vout(v) rep(i,0,v.size())cout<<v[i]<<(i==v.size()-1?"\n":" ");
#define vvout(vv) rep(j,0,vv.size()){vout(vv[j])}
#define mout(m) for(auto&e:m)cout<<e.first<<": "<<e.second<<endl;
#ifdef _CHK_
#define chk(a) if constexpr(_CHK_){cout<<#a<<": ";out(a)}
#define vchk(v) if constexpr(_CHK_){cout<<#v<<": ";vout(v)}
#define vvchk(vv) if constexpr(_CHK_){cout<<#vv<<": "<<endl;vvout(vv)}
#define mchk(m) if constexpr(_CHK_){cout<<#m<<": "<<endl;mout(m)}
#else
#define chk(a) {}
#define vchk(v) {}
#define vvchk(vv) {}
#define mchk(m) {}
#endif

vector<vector<int64_t>> adj;
vector<int64_t> depth;
vector<int64_t> imos;
vector<int64_t> score;

void get_score(int64_t now, int64_t prv, int64_t scr){
    scr += imos[now];
    score[now] = scr;
    for (auto& nxt: adj[now]) {
        if(nxt==prv) continue;
        get_score(nxt, now, scr);
    }
}

void get_depth(int64_t now, int64_t prv, int64_t dpt){
    depth[now] = dpt;
    for (auto& nxt: adj[now]) {
        if(nxt==prv) continue;
        get_depth(nxt, now, dpt+1);
    }
}

int main(){
    int64_t N;
    cin>>N;
    adj.resize(N);
    vector<int64_t> A(N);
    vector<int64_t> B(N);
    for(int i = 0 ; i < N-1 ; i++){
        int64_t a,b;
        cin>>a>>b;
        --a;--b;
        adj[a].emplace_back(b);
        adj[b].emplace_back(a);
        A[i]=a;
        B[i]=b;
    }
    vvchk(adj)

    depth.resize(N);
    get_depth(0, -1, 0);
    vchk(depth)

    int64_t Q;
    cin>>Q;
    imos.resize(N);
    for(int i = 0 ; i < Q ; i++){
        int64_t t,e,x;
        cin>>t>>e>>x;
        --e;
        int64_t a=A[e], b=B[e];
        if(t==2) swap(a,b);
        if(depth[a]<depth[b]){
            imos[0]+=x;
            imos[b]-=x;
        }else{
            imos[a]+=x;
        }
    }
    vchk(imos)

    score.resize(N);
    get_score(0, -1, 0);
    for (auto& e: score) {
        out(e);
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int_;
# define rep(i,a,b) for(int i=(a); i<=(b); ++i)
inline int readint(){
	int a = 0; char c = getchar(), f = 1;
	for(; c<'0'||c>'9'; c=getchar())
		if(c == '-') f = -f;
	for(; '0'<=c&&c<='9'; c=getchar())
		a = (a<<3)+(a<<1)+(c^48);
	return a*f;
}

const int MaxN = 1000000;
int_ dp[5][3*MaxN+1];

int main(){
	int n = readint(), sum, A, B;
	dp[0][0] = 1;
	rep(i,1,3) rep(j,i,i*n){
		dp[i][j] = dp[i][j-1]+dp[i-1][j-1];
		if(j > n) dp[i][j] -= dp[i-1][j-n-1];
// printf("dp[%d,%d] = %d\n",i,j,dp[i][j]);
	}
	int_ k; scanf("%lld",&k);
	for(sum=3; k>dp[3][sum]; ++sum)
		k -= dp[3][sum];
	for(A=1; k>dp[2][sum-A]; ++A)
		k -= dp[2][sum-A];
	for(B=1; k>dp[1][sum-A-B]; ++B)
		k -= dp[1][sum-A-B];
	printf("%d %d %d\n",A,B,sum-A-B);
	return 0;
}

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;++i)
#define repn(i,n) for(int i=1;i<=n;++i)
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

LL n,t;

LL calc(LL sum)
{
  LL lb=sum-n,ub=sum-1;
  lb=max(lb,2LL);ub=min(ub,n*2);
  if(ub<n+1) return (lb+ub-2)*(ub-lb+1)/2;
  if(lb>n+1) return (n*4-lb-ub+2)*(ub-lb+1)/2;
  return (lb+n-1)*(n-lb+2)/2+(n*3-ub+1)*(ub-n)/2-n;
}

LL calc2(LL sum,LL i)
{
  if(sum-i<2||sum-i>2*n) return 0;
  if(sum-i<=n+1) return sum-i-1;
  return n*2-(sum-i)+1;
}

int main()
{
  cin>>n>>t;
  LL sum;
  for(LL i=3;;++i)
  {
    LL val=calc(i);
    if(t-val<=0)
    {
      sum=i;
      break;
    }
    t-=val;
  }
  LL bea;
  for(LL i=1;;++i)
  {
    if(t-calc2(sum,i)<=0)
    {
      bea=i;
      break;
    }
    t-=calc2(sum,i);
  }
  LL tas=1;if(sum-bea-1>n) tas+=sum-bea-1-n;
  tas+=t-1;
  cout<<bea<<' '<<tas<<' '<<sum-bea-tas<<endl;
  return 0;
}


#include <bits/stdc++.h>

//#include <atcoder/all>
#define For(i, a, b) for (int(i) = (int)(a); (i) < (int)(b); ++(i))
#define rFor(i, a, b) for (int(i) = (int)(a)-1; (i) >= (int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T div_floor(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a >= 0 ? a / b : (a + 1) / b - 1;
}
template <class T>
T div_ceil(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a > 0 ? (a - 1) / b + 1 : a / b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int main() {
    int n;
    scanf("%d", &n);
    double x[n];
    rep(i, n) scanf("%lf", &x[i]);
    {
        double ans = 0;
        rep(i, n) ans += abs(x[i]);
        printf("%.10lf\n", ans);
    }
    {
        double ans = 0;
        rep(i, n) ans += x[i] * x[i];
        printf("%.10lf\n", sqrt(ans));
    }
    {
        double ans = 0;
        rep(i, n) chmax(ans, abs(x[i]));
        printf("%.10lf\n", ans);
    }
}

#include "bits/stdc++.h"
using namespace std;
using ll = long long;

int main() {
    int n;
    cin >> n;
    vector<ll> x(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }
    ll d1, d2;
    ll d3;
    d1 = 0;
    d2 = 0;
    d3 = 0;
    for (int i = 0; i < n; i++) {
        d1 += abs(x[i]);
        d2 += x[i] * x[i];
        d3 = max(d3, abs(x[i]));
    }
    long double d4 = sqrt(d2);
    cout << d1 << endl;
    cout << setprecision(20) << d4 << endl;
    cout << (ll)d3 << endl;
    return 0;
}


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

#define REP(i, j, k) for (int i = j; i < k; i++)
#define RREP(i, j, k) for (int i = j; i >= k; i--)

typedef long long ll;
#define ALL(x) x.begin(), x.end()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;

#define MAXN 5005
#define MOD 998244353

int n, m;
ll pw[MAXN][MAXN];
ll ans;

int main() {
	scanf("%d%d", &n, &m);
	ans = n;
	REP (i, 0, n) {
		ans = ans * m % MOD;
	}
	REP (i, 0, MAXN) {
		pw[i][0] = 1;
		REP (j, 1, MAXN) {
			pw[i][j] = pw[i][j - 1] * i % MOD;
		}
	}
	REP (i, 0, m) {
		REP (j, 0, n - 1) {
			ans -= pw[i][j] * (n - j - 1) % MOD * pw[m][n - j - 2] % MOD;
			ans = (ans + MOD) % MOD;
		}
	}
	printf("%lld\n", ans);
	return 0;
}

#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
struct FIO{FIO(){std::cin.tie(0);std::ios_base::sync_with_stdio(0);std::cout<<std::fixed<<std::setprecision(15);}}fIO;
template<typename T> using V = std::vector<T>;
template<typename T> void fill(V<T>&v) { for(T&e:v) std::cin >> e; }
/*-*/

constexpr lnt MOD = 998244353;
struct mint
{
	lnt v;
	mint():v(0){}
	mint(lnt v):v((v+MOD)%MOD){}
	mint operator-()const{ return mint(0) - *this; }
	mint& operator+=(const mint& a){ if((v+=a.v)>=MOD) v-=MOD; return *this; }
	mint& operator-=(const mint& a){ if((v+=MOD-a.v)>=MOD) v-=MOD; return *this; }
	mint& operator*=(const mint& a){ (v*=a.v)%=MOD; return *this; }
	mint& operator/=(const mint& a){ (*this) *= a.inv(); return *this; }
	mint operator+(const mint& a)const{ return mint(*this) += a; }
	mint operator-(const mint& a)const{ return mint(*this) -= a; }
	mint operator*(const mint& a)const{ return mint(*this) *= a; }
	mint operator/(const mint& a)const{ return mint(*this) /= a; }
	bool operator<(const mint& a)const{ return v < a.v; }
	bool operator==(const mint& a)const{ return v == a.v; }
	mint pow(lnt k)const{ mint r(1),t(v); while(k){ if(k&1) r*=t; t*=t; k>>=1; } return r; }
	mint inv()const{ return pow(MOD-2); }
	static mint comb(lnt n, lnt k) { if(n-k<k) k=n-k; mint num(1), dom(1); for(int i=0;i<k;i++) { num*=n-i; dom*=i+1; } return num/dom; }
	static std::vector<mint> construct_comb(int n) {
		std::vector<mint> c(n+1); mint a = 1; c[0] = a; for(int i=1;i<=n;i++) { a = a*mint(n+1-i)/i; c[i] = a; } return c;
	}
	static std::vector<mint> construct_fact(int n) { std::vector<mint> f(n+1,1); for(int i=2;i<=n;i++) f[i]=f[i-1]*i; return f; }
};
std::istream& operator>>(std::istream&i,mint&a){ lnt t; i>>t; a=mint(t); return i; }
std::ostream& operator<<(std::ostream&o,const mint&a){ o<<a.v; return o; }

int main() {
	int n,m;
	std::cin >> n >> m;
	mint ans=mint(n)*mint(m).pow(n);
	for(int x=2;x<=n;x++) {
		mint o=0;
		for(int y=1;y<=m;y++) {
			o+=mint(m-y).pow(x-2)*mint(m).pow(n-x);
		}
		ans-=o*mint(n-x+1);
	}
	print(ans);
}


/**
 *    author:  pankaj_m05
 *    created: 19.12.2020 23:17:06
**/
#include<bits/stdc++.h>
#define sz(x) (int(x.size()))

using namespace std;

struct fenwick {
	int n;
	vector< int > bit;

	fenwick(int n) {
		this -> n = n;
		bit.assign(n + 1, 0);
	}

	fenwick(vector< int >& a) : fenwick(sz(a)) {
		for (int i = 1; i <= n; ++i)
			update(i, a[i - 1]);
	}

	void update(int idx, int k) {
		for (int i = idx; i <= n; i += i & -i)
			bit[i] ^= k;
	}

	int sum(int idx) {
		int ans = 0;
		for (int i = idx; i; i -= i & -i)
			ans ^= bit[i];
		return ans;
  }

	int range(int l, int r) {
  	return sum(r) ^ sum(l - 1);
	}
};

int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, q;
  cin >> n >> q;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
  	cin >> a[i];
  }
  fenwick f(a);
  while (q--) {
  	int t;
  	cin >> t;
  	if (t == 1) {
  		int x, v;
  		cin >> x >> v;
  		f.update(x, v);
  	} else {
  		int l, r;
  		cin >> l >> r;
  		cout << f.range(l, r) << '\n';
  	}
  }
  return 0;
}

#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<list>

#define DIV 1000000007
#define TE 2e5
using namespace std;
using ll = long long;
using ldb = long double;

int sol(const string& S) {
	const string A = "atcoder";
	if (S > A)return 0;
	int len = S.size(), K = 0;
	for (int i = 0; i < len; i++) {
		if (S[i] != 'a') {
			K = i;
			break;
		}
		if (i == len - 1)return -1;
	}

	if (S[1] != 'a')return 1;
	if (S[K] > 't')return K - 1;
	else return K;
}

int main() {
	int T; cin >> T;
	for (int i = 0; i < T; i++) {
		string S; cin >> S;
		cout << sol(S) << endl;
	}
}


#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
const int N=1e5+5,M=4e5+5;

int edge[M],Next[M],ver[M],head[N];
int tot=0,tmp=0;
int dfn[N],dis[N];
int n,m;

void add(int x,int y,int z){
	ver[++tot]=y,edge[tot]=z,Next[tot]=head[x],head[x]=tot;
}

void dfs(int x){
	dfn[x]=++tmp;
	for(int i=head[x];i;i=Next[i]){
		int y=ver[i];
		if(!dfn[y]){
			if(dis[x]!=edge[i])	dis[y]=edge[i];
			else				dis[y]=dis[x]%n+1;
			dfs(y);
		}
	}
}

int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		int u,v,w;
		scanf("%d%d%d",&u,&v,&w);
		add(u,v,w);add(v,u,w);
	}
	dis[1]=1;
	dfs(1);
	if(tmp<n-1)	puts("No");
	else{
		for(int i=1;i<=n;i++)	printf("%d\n",dis[i]);
	}
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T> using vt = vector<T>;
template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb push_back
#define SZ(x) ((int)((x).size()))
#define EACH(x, a) for (auto& x: a)
#define FOR(i,s,n) for (ll i = (s); (i) < (n); ++i)
#define FORD(i,s,l) for (ll i = (s); (i) >= l; --i)
#define F first
#define S second
#define TC int __tc; cin >> __tc; FOR(case_num,1,__tc+1)
#define TEST(x,i) ((x)&(1ll<<(i)))
#define SET(x,i) ((x)|(1ll<<(i)))
#define FLIP(x,i) ((x)^(1ll<<(i)))
#define CLEAR(x,i) ((x)&~(1ll<<(i)))
const double pi = 4 * atan(1);
using ll = long long;
using pll = pair<ll, ll>;

mt19937 mt_rng(chrono::steady_clock::now().time_since_epoch().count());
ll randint(ll a, ll b) {
	return uniform_int_distribution<ll>(a, b)(mt_rng);
}

template<class T> bool umin(T& a, const T& b) {
	return b<a?a=b, 1:0;
}
template<class T> bool umax(T& a, const T& b) {
	return a<b?a=b, 1:0;
}

template<class ForwardIterator> void print_vec(ForwardIterator first,
		ForwardIterator last, string sep = " ", string end = "\n") {
	bool ft = true;
	while (first != last) {
		if (!ft) {cout << sep;} else {ft = false;}
		cout << (*first);
		++first;
	}
	cout << end;
}

template<typename T1, typename T2>
std::ostream& operator<<(std::ostream &o, const pair<T1, T2> &p) {
	return o << p.F << " " << p.S;
}

inline ll floorDiv(ll x, ll y) {
	ll d = x / y;
	ll r = x % y;
	return r ? (d - ((x < 0) ^ (y < 0))) : d;
}

ll ceilDiv(ll x, ll y) {
	return -floorDiv(-x, y);
}

ll bin_search(ll lo, ll hi, function<bool(ll)> predicate) {
	int sign = lo < hi ? 1 : -1;
	lo *= sign;
	hi *= sign;
	hi++;
	while (lo < hi) {
		ll mid = lo + floorDiv(hi-lo, 2);
		if (!predicate(sign * mid)) {
			lo = mid + 1;
		} else {
			hi = mid;
		}
	}
	return sign * lo;
}
const ll MOD = 1000000007;
const int MAXN = 100005;

map<int,vector<int>> adj[MAXN];
map<int,map<int,int>> used;
bool visited[MAXN];
int n;

void dfs(int u, vector<int> &ans) {
	visited[u]=true;
	for (auto &p : adj[u]) {
		int val = p.F;
		for (auto v : p.S) {
			if (!visited[v]) {
				ans[v] = (ans[u] == val ? (val+1)%n : val);
				dfs(v, ans);
			}
		}
	}
}

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

	cin >> n;
	int m;
	cin >> m;

	vector<int> ans(n,-1);

	while(m--) {
		int x, y, v;
		cin >> x >> y >> v; x--; y--; v--;
		adj[x][v].pb(y);
		adj[y][v].pb(x);
	}

	ans[0]=0;
	dfs(0,ans);

	if (find(ans.begin(),ans.end(),-1) != ans.end()) {
		cout << "No\n";
	} else {
		for (auto v : ans) {
			cout << v+1 << "\n";
		}
	}

}


#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
#define ll long long
#define ar array
const ll mxN=2e5;
const int mod=1e9+7;
const ll INF=1e18;
#define what_is(x) cerr << #x << " is " << x << endl;
ll a,b,n,k,q,m,x,y,h,l,r,t;

void solve(){
	cin>>n;
	ll A[n],B[n],aoki=0,delta;
	vector<ll> benifit(n);
	for(int i=0;i<n;i++){
		cin>>A[i]>>B[i];
		aoki+=A[i];
		benifit[i]=2*A[i]+B[i];
	}
	delta=-aoki;
	sort(benifit.rbegin() , benifit.rend());
	int i=0;
	while(i<n && delta<=0){
		delta+=benifit[i];
		i++;

	}
	cout<<i<<endl;
}

signed main() {
	#ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        // freopen("output.txt","w",stdout);
    #endif
    // ios::sync_with_stdio(false);
    // cin.tie(0);
    // cout.tie(0);
    cout<<setprecision(12)<<fixed;
    // cin>>t;
    // while(t--)
    	solve();
	return 0;

}

#include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
//#include <boost/multiprecision/cpp_int.hpp>
//#include <boost/multiprecision/cpp_dec_float.hpp>
//using namespace boost::multiprecision;
using namespace std;

#pragma region Macros
using ll = long long;
#define int ll
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V<V<T>>;
#define IOS\
    ios::sync_with_stdio(false);\
    cin.tie(0);\
    cout.tie(0);
#define FOR(i,l,r) for(int i=(l);i<int(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(int i=(l);i>=int(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define SORT(name) sort(name.begin(), name.end())
#define RSORT(name)\
    SORT(name);\
    reverse(all(name));
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
template <class T> inline void print(T x){ cout << x << '\n';}
template<typename T1,typename T2> inline void chmin(T1 &a, T2 b){ if(a > b) a = b; }
template<typename T1,typename T2> inline void chmax(T1 &a, T2 b){ if(a < b) a = b; }

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
#pragma endregion

const int MOD = 1000000007;

#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const int MAX_N = 110;
int N;
int dp[MAX_N][2];
V<string> S;

int dfs(int i, int j) {
    if(i >= N + 1) {
        return j;
    }

    int& ret = dp[i][j];
    if(~ret) { return ret; }
    ret = 0;

    if(i == 0) {
        ret += dfs(i + 1, 1);
        ret += dfs(i + 1, 0);
        return ret;
    }

    // ここを 1 にする
    int nj;
    if(S[i] == "AND") {
        nj = j & 1;
        ret += dfs(i + 1, nj);
    }
    else {
        nj = j | 1;
        ret += dfs(i + 1, nj);
    }

    // ここを 0 にする
    if(S[i] == "AND") {
        nj = j & 0;
        ret += dfs(i + 1, nj);
    }
    else {
        nj = j | 0;
        ret += dfs(i + 1, nj);
    }
    return ret;
}

signed main() {
    IOS;
    cin >> N;
    S.resize(N + 1);
    REP(i, N) { cin >> S[i + 1]; }
    MINUS(dp);
    int ans = dfs(0, 0);
    print(ans);

    return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstddef>
#include<queue>
#include<math.h>
#include<iomanip>
using namespace std;
typedef long long ll;

int main()
{
    int n, maxcnt = 0, cnt = 0, ans = 0;
    cin >> n;
    vector<int> a(n),b(1000);
    for(int i = 0; i < n; ++i) cin >> a.at(i);
    for(int k = 2; k < 1001; ++k){
        for(int i = 0; i < n; ++i) if(a.at(i) % k == 0) cnt += 1;
        if(maxcnt < cnt){
            maxcnt = cnt;
            ans = k;
        }
        cnt = 0;
    }
    cout << ans << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define ll 				long long
#define pii             pair<ll,ll>
#define vi              vector<ll>
#define mii               map<ll,ll>
#define pqi             priority_queue<ll>			//max pq
#define pqd             priority_queue<ll,vi,greater<ll> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define MOD             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define pw(b,p)         pow(b,p) + 0.1
#define f(i,k,n)			for(ll i=k;i<n;i++)

ll power(ll a, ll b, ll mod) {ll res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) {if (b & 1)res = res * a % mod; a = a * a % mod;} return res;}
ll power(ll a, ll b) {ll res = 1; assert(b >= 0); for (; b; b >>= 1) {if (b & 1)res = res * a ; a = a * a;} return res;}
ll min( ll a,  ll b) { return (a < b) ? a : b;}
ll max(ll a, ll b) {return (a > b) ? a : b;}
ll gcd (ll a, ll b) {if (a == 0) return  b; return gcd(b % a, a);}

void bwayne()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

void solve() {
	ll n;
	cin >> n;
	vi a(n);
	f(i, 0, n) cin >> a[i];
	ll ans = 1;
	mii poss;
	f(i, 0, n) {
		ll el = a[i];
		for (ll j = 2; j * j <= a[i]; j++) {
			ll count = 0;
			while (el % j == 0) {
				count++;
				el /= j;
			}
			if (count >= 1) {
				poss[j]++;
			}
		}
		if (el > 1) {
			poss[el]++;
		}
	}
	mii m;
	for (auto i = poss.begin(); i != poss.end(); i++) {
		ll pos = i->first;
		f(j, 0, n) {
			if (a[j] % pos == 0) {
				m[pos]++;
			}
		}
	}
	ll maxx = 0;
	for (auto it = m.begin(); it != m.end(); it++) {
		if (it->second > maxx) {
			ans = it->first;
			maxx = it->second;
		}
	}
	cout << ans;

}
int main()
{
	bwayne();// remember
	ll t = 1;
	// cin >> t;

	for (ll tt = 1; tt <= t; tt++)
	{
		//	 cout<<"Case #"<<tt<<": ";
		solve();
	}

	return 0;
}


///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           nd(a,b,c)                   mp(mp(a,b),c)
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=2e18;
const int mod=998244353;
const int M=100005;
void solve()
{
   int h,w;
   cin>>h>>w;
   char yo[h+1][w+1];
   f(i,1,h)
   {
       f(j,1,w)
       {
           cin>>yo[i][j];
       }
       cin.ignore();
   }
   int ses=1;
   vector<pi>vec;
   for(int i=1;i<=h;i++)vec.pb({i,1});
   for(int j=2;j<=w;j++)vec.pb({h,j});
   for(auto z:vec)
   {
       int x=z.fi,y=z.si;
       int red=0,blue=0,no_colour=0;
       while(x>=1 && y<=w)
       {
             if(yo[x][y]=='B')blue++;
             else if(yo[x][y]=='R')red++;
             else no_colour++;
             x--;y++;
       }
       if(red>=1 && blue>=1)
       {
           cout<<"0\n";return ;
       }
       if(red==0 && blue==0)ses=(ses*2LL)%mod;
   }

   cout<<ses<<"\n";
}
 main()

{
    fast
    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;

}

#include <bits/stdc++.h>
#define rep(i,x,y) for(int i=x;i<=y;++i)
#define per(i,x,y) for(int i=x;i>=y;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int inf = 1e9;
const int mod=1e9+7;
const int N = 3e5 + 5;
int n;
int a[N];
int tr[N];
void add(int x,int k){
    while(x<=n) tr[x]+=k,x+=x&-x;
}
int dor(int x){
    int ret=0;
    while(x) ret+=tr[x],x-=x&-x;
    return ret;
}
int main() {
    cin>>n;
    rep(i,1,n){
        cin>>a[i];
        a[i]++;
    }
    ll ans=0;
    rep(i,1,n){
        ans+=dor(n)-dor(a[i]);
        add(a[i],1);
    }
    cout<<ans<<'\n';
    rep(i,1,n-1){
        ans+=dor(n)-dor(a[i]);
        ans-=dor(a[i]-1);
        cout<<ans<<'\n';
    }
    return 0;
}


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

typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define sz(x) int(x.size())
const int INF = 1001001001;
const ll mod = 1000000007;
const ll INFL = 1001001001001001000;

int main() {
    int n; cin >> n;
    ll x[n]; rep(i,n) cin >> x[i];
    ll md = 0; rep(i,n) md += abs(x[i]);
    ll cd = 0; rep(i,n) cd = max(cd, abs(x[i]));
    double ed = 0; rep(i,n) ed += (long double) x[i] * x[i];
    ed = sqrt(ed);
    cout << md << endl;
    cout << setprecision(15) << ed << endl;
    cout << cd << endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define sz(a) int(a.size())
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) { out << "(" << a.first << "," << a.second << ")"; return out; }
template <typename T, size_t N> ostream& operator <<(ostream& out, const array<T, N>& a) { out << "["; bool first = true; for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]"; return out; }
template <typename T> ostream& operator <<(ostream& out, const vector<T>& a) { out << "["; bool first = true; for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]"; return out; }
template <typename T, class Cmp> ostream& operator <<(ostream& out, const set<T, Cmp>& a) { out << "{"; bool first = true; for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}"; return out; }
template <typename U, typename T, class Cmp> ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) { out << "{"; bool first = true; for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}"; return out; }
template <typename Arg1> void __f(const char* name, Arg1&& arg1){ cerr << name << ": " << arg1 << endl; }
template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args){ const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << ": " << arg1 << " |"; __f(comma + 1, args...); }

#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif

void solve() {
	int n; cin >> n;
	vector<string> s(n);
	for(int i=0; i<n; i++) {
		cin >> s[i];
	}
	unordered_map<string, int> m;
	for(int i=0; i<n; i++) {
		auto ss = s[i];
		if(ss[0] == '!') {
			ss = ss.substr(1);
			m[ss] |= 1;
		} else {
			m[ss] |= 2;
		}
		if(m[ss] == 3) {
			cout << ss << endl;
			return;
		}
	}
	cout << "satisfiable" << endl;
}

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


#include <bits/stdc++.h>
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(),(x).end()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
using namespace std;
typedef double DB;
typedef long double LD;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<PII> VPII;
//head
const int N=1e4+5;
int n,a[N];
int main() {
    //freopen("E:/OneDrive/IO/in.txt","r",stdin);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    int res=0;
    for(int i=1;i<=n;i++) {
        int t=1;
        for(int j=i-1;j>=1;j--) {
            if(a[j]>=a[i]) ++t;
            else break;
        }
        for(int j=i+1;j<=n;j++) {
            if(a[j]>=a[i]) ++t;
            else break;
        }
        res=max(res,t*a[i]);
    }
    cout<<res<<'\n';
    return 0;
}

#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define rep(i,a,b)    for(ll i=a;i<b;i++)
#define repn(i,a,b)   for(ll i=a;i>=b;i--)
#define ld long double
#define fi first
#define se second
#define pii pair<ll,ll>
#define vi vector<ll>
#define vii vector<pii>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define sz(a) (ll)(a.size())
#define len(a) (ll)(a.length())
#define mem0(a) memset(a, 0, sizeof(a))
#define mem1(a) memset(a, -1, sizeof(a))
#define trav(a, x) for (auto &a : x)
#define popcount(x) __builtin_popcountll(x)
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define mod 1000000007
ll INF = 1e6;

void solve() {
    ll n;
    cin >> n;
    vi a(n), b(200);
    rep(i, 0, n) {
        cin >> a[i];
        b[a[i] % 200]++;
    }
    ll c = 0;
    rep(i, 0, 200) {
        c += b[i] * (b[i] - 1) / 2;
    }
    cout << c;

}
int main() {
    SPEED;
#ifndef ONLINE_JUDGE
    freopen("input1.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
#endif
    clock_t z = clock();
    ll t = 1;
    //cin >> t;
    while (t--) solve();
    debug("Total Time:%.3Lf\n", (ld)(clock() - z) / CLOCKS_PER_SEC);
    return 0;
}


#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define pb push_back
#define mp make_pair

typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;

const int N = 1001;

string s;
vi g[2 * N];
int vis[2 * N];
set<int > s1, s2;

void dfs(int c, int cmp) {
  if(vis[c]) return;
  vis[c] = cmp;
  rep(i,0,g[c].size()) {
    dfs(g[c][i], cmp);
  }
}

int main() {
  int n,m;
  S2(n,m);
  rep(i,0,n) {
    cin >> s;
    rep(j,0,m) if(((i == 0 || i == n - 1) && (j == 0 || j == m - 1)) ||s[j] == '#') {
      g[i + 1].pb(n + j + 1);
      g[n + j + 1].pb(i + 1);
    }
  }
  int cnt = 0;
  rep(i,1,n+m+1) if(!vis[i]) {
    ++cnt;
    dfs(i, cnt);
  }
  rep(i,1,n+m+1) {
    if(i <= n) s1.insert(vis[i]);
    else s2.insert(vis[i]);
  }
  P((int)min(s1.size(), s2.size()) - 1);
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

struct union_find {
    vector<int> par, siz;
    union_find(int n) {
        par.resize(n);
        siz.resize(n);
        for(int i = 0; i < n; i++){
            par[i] = i;
            siz[i] = 1;
        }
    }

    int find(int x) {
        if (par[x] == x) return x;
        return par[x] = find(par[x]);
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y)return;
        if (siz[x] < siz[y]) {
            par[x] = y;
            siz[y] += siz[x];
        }
        else {
            par[y] = x;
            siz[x] += siz[y];
        }
    }

    long long size(int x){
        return siz[find(x)];
    }

    bool same(int x, int y) {
        return (find(x) == find(y));
    }
};

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

    ll h, w; cin >> h >> w;
    string s[h];
    zep(i, 0, h)cin >> s[i];

    union_find u(h + w);

    u.unite(0, h - 1);
    u.unite(0, h);
    u.unite(0, h + w - 1);

    zep(i, 0, h){
        zep(j, 0, w){
            if(s[i][j] == '#'){
                u.unite(i, h + j);
            }
        }
    }

    set<ll> ansh, answ;
    zep(i, 0, h)ansh.insert(u.find(i));
    zep(j, 0, w)answ.insert(u.find(h + j));
    print(min(ansh.size(), answ.size()) - 1)

    return 0;
}


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

int main(){
  vector<int> A;
  vector<int> B;
  vector<int> product;
  int N,m;
  int result = 0;
  cin >> N;
  for(int i = 0;i < N;i++){
    cin >> m;
    A.push_back(m);
  }
  for(int i = 0;i < N;i++){
    cin >> m;
    B.push_back(m);
  }
  for(int i = 0;i < N;i++){
    int P;
    P = A[i]*B[i];
    product.push_back(P);
  }
  for(int i = 0;i < N;i++){
    result += product[i];
  }
  if(result == 0){
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
}

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

void solve() {
  int l,r;
  cin >> l >> r;
  long long marg = r-2*l;
  long long ans = (marg+1)*(marg+2)/2;
  if (marg < 0) ans = 0;
  cout << ans << endl;
}

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  for (int i=0;i<t;i++) solve();
}


#include <bits/stdc++.h>

using namespace std;

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    ostringstream name;
    name<<x;
    string l=name.str();
    res += to_string(l);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

int main()
{
    int n,m;
    scanf("%d %d",&n,&m);
    vector<int>a(n);
    for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	vector<int>b(m);
	for(int i=0;i<m;i++){
		scanf("%d",&b[i]);
	}
	for(int i=1;i<=1e3;i++){
		auto poz = binary_search(a.begin(),a.end(),i) ;
		auto poz2 = binary_search(b.begin(),b.end(),i) ;
		if((poz && !poz2) ||
			(!poz && poz2) ){
			printf("%d ",i);
		}

	}
	printf("\n");

    return 0;
}

#include <iostream>
#include <fstream>
#include <cstdio>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <iomanip>
#include <cassert>
#include <random>
#include <time.h>
using namespace std;

#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define pb push_back
#define FOR(i, n) for(int i = 0; i < (n); i++)
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

const int mod = 1e9 + 7;
const int mod2 = 998244353;

void fact_init(int n, int md);
ll exp(ll taban, ll us, ll md);
ll ebob(ll a, ll b);
ll ekok(ll a, ll b);
ll komb(int a, int b, int md);
ll mul(ll a, ll b, int md);

vector<ll> fact;
vector<ll> inv_fact;
void fact_init(int n, int md){
    fact.resize(n+5);
    inv_fact.resize(n+5);
    fact[0] = inv_fact[0] = 1;
    for(int i = 1; i <= n; i++){
        fact[i] = (fact[i-1] * i) % md;
        inv_fact[i] = exp(fact[i], md-2, md);
    }
}
ll exp(ll taban, ll us, ll md) {
    ll carpan = taban % md;
    if(carpan == 0) return 0;
    ll temp = us;
    ll res = 1;
    while(temp){
        if(temp % 2) res = (res*carpan) % md;
        temp /= 2;
        carpan = (carpan*carpan) % md;
    }
    return res;
}

ll ebob(ll a, ll b){
    if(!a)return b;
    return ebob(b%a, a);
}

ll ekok(ll a, ll b){
    return (a*b)/ebob(a, b);
}

ll komb(int a, int b, int md){
    if(a < b) return 0;
    return fact[a] * (inv_fact[a-b] * inv_fact[b] % md) % md;
}

ll mul(ll a, ll b, int md){
	return a*b % md;
}
const int N = 2e5 + 5;
vector<vector<int>> g(N);
int a[N], b[N];
bool vis[N];
int main(){
    ios::sync_with_stdio(false); cin.tie(NULL);
	int n, m; cin>>n>>m;
	for(int i = 1; i <= n; i++) cin>>a[i];
	for(int i = 1; i <= n; i++) cin>>b[i];
	for(int i = 0; i < m; i++){
		int u, v; cin>>u>>v;
		g[u].pb(v);
		g[v].pb(u);
	}
	bool check = true;
	for(int i = 1; i <= n; i++){
		if(vis[i]) continue;
		queue<int> q;
		q.push(i);
		vis[i] = true;
		vector<int> cur_nodes;
		while(!q.empty()){
			int cur = q.front();
			q.pop();
			cur_nodes.pb(cur);
			for(int node: g[cur]){
				if(vis[node]) continue;
				vis[node] = true;
				q.push(node);
			}
		}
		ll sum1 = 0, sum2 = 0;
		for(int node: cur_nodes){
			sum1 += a[node];
			sum2 += b[node];
		}
		check &= sum1 == sum2;
	}
	cout<<(check ? "Yes\n" : "No\n");
}


#include<bits/stdc++.h>
#define ll long long int
#define pii pair<int,pair<int,int> >
#define F first
#define S second
using namespace std;
#define mod 1000000007

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

///cout << "Case #"<<it<<": "<< res<< endl;

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int t=1;///cin>>t;
    while(t--){
        int arr[4];
        for(int i=0;i<4;i++) cin>>arr[i];
        sort(arr,arr+4);
        if(arr[3]==arr[0]+arr[1]+arr[2]){
            cout<<"Yes"<<endl;
        }else if(arr[3]+arr[0]==arr[1]+arr[2]){
            cout<<"Yes"<<endl;
        }else cout<<"No"<<endl;

    }

}

#include <bits/stdc++.h>
using namespace std;
#define IOS              ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define print(a)         for(int i=0;i<(a.size());i++){cout<<a[i]<<"\n";}
#define sortt(a)         sort(a.begin(),a.end())
#define loop(i,a,b)      for(int i=0;i<n;i++)
#define int              long long
#define pb               push_back
#define mod              1000000007
#define PQ               priority_queue
#define F                first
#define S                second

void S_G_()
{
  string s;
  cin>>s;
  map<char,int>mp;
  for(int i=0;i<3;i++)
  {
    mp[s[i]]++;
  }
  if(mp[s[0]]==3)
  {
    cout<<"Won"<<endl;
  }
  else
  {
    cout<<"Lost"<<endl;
  }
}
signed main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
  IOS;
  int t=1;
  // cin>>t;
  while(t--)
  {
    S_G_();
  }
  cerr<<"time taken :"<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

//#define debug(x) ;
#define debug(x) cerr << #x << " = " << x << "\n";

ostream& operator<<(ostream& cerr, vector<ll> aux) {
  cerr << "[";
  for (auto e : aux) cerr << e << ' ';
  cerr << "]";
  return cerr;
}

const int maxN = 3011;
ll mod = 998244353;

int n, k;
ll dp[maxN][maxN]; // i frac, j value

void add(ll& a, ll b) {
  a += b;
  if (a >= mod) a -= mod;
}

int main()
{
  //freopen("test.in", "r", stdin);

  cin >> n >> k;

  dp[n][k] = 1;
  for (int i = n; i >= 1; i--) {
    for (int j = 1; j <= i; j++) {
      if (dp[i][j] == 0) continue;

      add(dp[i - 1][j - 1], dp[i][j]);
      if (2 * j <= i)
        add(dp[i][2 * j], dp[i][j]);

      //cerr << i << ' ' << j << ' ' << dp[i][j] << '\n';
    }
  }

  cout << dp[0][0];

  return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long i64;
typedef unsigned long long ui64;
typedef vector<i64> vi;
typedef vector<vi> vvi;
typedef pair<i64, i64> pi;

#define pb push_back
#define sz(a) i64((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)
inline void RI(i64 &i) {scanf("%lld", &(i));}
inline void RVI(vi &v) { for(i64 i=0;i<sz(v);++i) { RI(v[i]); } }
inline void RVVI(vvi &vv) { for(i64 i=0;i<sz(vv);++i) { RVI(vv[i]); } }
inline void WI(const i64 &i) {printf("%lld\n", i);}
inline void WVI(const vi &v, char sep=' ') { for(i64 i=0;i<sz(v);++i) { if(i != 0){ printf("%c", sep); } printf("%lld", v[i]);} printf("\n"); }
inline void WS(const string &s) { printf("%s\n", s.c_str()); }
inline void WB(bool b, const string &yes, const string &no) { if(b){ WS(yes);} else { WS(no);} }
inline void YESNO(bool b) { WB(b, "YES", "NO"); }
inline void YesNo(bool b) { WB(b, "Yes", "No"); }
#define BUF_LENGTH 1000000
inline void RS(string &s) {static char buf[BUF_LENGTH]; scanf("%s", buf); s = buf;}
template<typename T> inline bool IN(T &S, const typename T::key_type &key) {
  return S.find(key) != S.end();
}
template<typename T> inline bool ON(const T &b, i64 idx) {
  return ((T(1) << idx) & b) != 0;
}

struct graph {
  using node_t = long long;
  using weight_t = long long;
  using edge_t = pair<node_t, weight_t>;

  graph(node_t n) {
    edges.resize(n);
  }
  virtual ~graph() {}
  void add_edge(node_t i, node_t j, weight_t w=1) {
    edges[i].push_back({j, w});
  }
  virtual vector<edge_t> get_edges(node_t n) const {
    assert(n < get_num_nodes());
    return edges[n];
  }
  int get_num_nodes() const {
    return int(edges.size());
  }
  vector<vector<edge_t>> edges;
};

// dijkstra
i64 dijkstra(const graph &g, graph::node_t start) {
  using node_t = graph::node_t;
  using distance_t = graph::weight_t;
  using flag_t = unsigned char;
  const distance_t unreachable = -1;
  using dn = pair<distance_t, node_t>;
  priority_queue<dn, vector<dn>, greater<dn>> pq;
  vector<distance_t> distances(g.get_num_nodes(), unreachable);
  for(auto &e: g.get_edges(start)) {
    node_t to = e.first;
    distance_t w = e.second;
    if(distances[to] == unreachable || w < distances[to]) {
      distances[to] = w;
    }
    pq.push({distances[to], to});
  }

  while(!pq.empty()) {
    dn cur_p = pq.top(); pq.pop();
    int cur_d = cur_p.first, cur = cur_p.second;
    if(distances[cur] != cur_d) {
      continue;
    }
    for(auto &e: g.get_edges(cur)) {
      node_t to = e.first;
      distance_t w = e.second;
      //cerr << cur << " -> " << to << ": " << w << endl;
      if(distances[to] == unreachable || cur_d + w < distances[to]) {
        distances[to] = cur_d + w;
        pq.push({distances[to], to});
      }
    }
  }
  return distances[start];
}

int main(int argc, char *argv[]) {
  i64 i, j, k;
  i64 N, M; cin >> N >> M;
  graph g(N);
  REP(0, M, i) {
    i64 a, b, c; RI(a); RI(b); RI(c); --a; --b;
    g.add_edge(a, b, c);
  }

  REP(0, N, i) {
    WI(dijkstra(g, i));
  }

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
using cd = complex<double>;
const double EPS = 1e-9;
bool isEq(double a, double b) {
	return abs(a - b) < EPS;
}
bool operator==(cd a, cd b) {
	return isEq(a.imag(), b.imag()) && isEq(a.real(), b.real());
}
bool operator!=(cd a, cd b) {
	return !(a == b);
}
#ifdef _DEBUG
#define show(x)          \
	cerr << #x << " : "; \
	showVal(x)
template <typename T>
void showVal(const T &a) { cerr << a << endl; }
template <typename T>
void showVal(const vector<T> &a) {
	for (const T &v : a) cerr << v << " ";
	cerr << endl;
}
template <typename T>
void showVal(const vector<vector<T>> &a) {
	cerr << endl;
	for (const vector<T> &v : a) showVal(v);
}
#else
#define show(x)
#endif
int main() {
	int n;
	cin >> n;
	vector<cd> s(n), t(n);
	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		s[i] = cd(a, b);
	}
	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		t[i] = cd(a, b);
	}
	if (n == 1) {
		cout << "Yes" << endl;
		return 0;
	}
	cd sg, tg;
	for (int i = 0; i < n; i++) {
		sg += s[i];
		tg += t[i];
	}
	sg = cd(sg.real() / n, sg.imag() / n);
	tg = cd(tg.real() / n, tg.imag() / n);
	for (int i = 0; i < n; i++) {
		s[i] -= sg;
		t[i] -= tg;
	}
	cd sn = s[0];
	if (sn == cd(0, 0)) {
		sn = s[1];
	}
	for (int ti = 0; ti < n; ti++) {
		if (!isEq(abs(sn), abs(t[ti]))) continue;
		double th = arg(sn) - arg(t[ti]);
		show(th);
		bool ok = true;
		for (int i = 0; i < n; i++) {
			cd z = t[i] * polar<double>(1, th);
			bool isEx = false;
			for (int j = 0; j < n; j++) {
				if (z == s[j]) {
					isEx = true;
				}
			}
			if (!isEx) {
				ok = false;
			}
		}
		if (ok) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define reps(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define repit(i,C) for (auto i = (C).begin(); i != (C).end(); i++)
#define pr(a) cout << a
#define prl(a) cout << (a) << endl
#define prld(a) cout << setprecision(15)<< (a) << endl
#define allrange(a) a.begin(),a.end()

bool solve_translated(vector<pair<int,int>> &S,vector<pair<int,int>> &T){
    int N = S.size();
    int dx = S[0].first-T[0].first;
    int dy = S[0].second-T[0].second;
    bool flg = true;
    reps(i,1,N){
        if(!((S[i].first==T[i].first+dx) && (S[i].second==T[i].second+dy))){flg = false; break;}
    }
    return flg;
}
/*ピタゴラ三角形
    5	12	13
    8	15	17
    3	4	5
*/
vector<pair<int,int>> Pitagora_rot(vector<pair<int,int>> &S,int a, int b , int c){
    int N = S.size();
    vector<pair<int,int>> PS(N);
    auto pt0 = S[0];
    PS[0] = pt0;
    bool flg = true;
    reps(i,1,N){
        int dx = S[i].first - pt0.first;
        int dy = S[i].second - pt0.second;
        if(((dx*b+dy*a)%c)!=0 || ((dx*a-dy*b)%c)!=0) {flg = false; break;}
        PS[i] = make_pair((dx*a-dy*b)/c+pt0.first, (dx*b+dy*a)/c+pt0.second);
    }
    if(flg) return PS;
    else return vector<pair<int,int>>();
}

int main(){
    std::cin.tie(0); // cinとcoutの同期を解除
    std::ios::sync_with_stdio(false);
    int N;cin >> N;

    vector<pair<int,int>> S(N),T(N);
    rep(i,N)
    {
        int x,y;
        cin >> x >> y;
        S[i].first = x;S[i].second = y;
    }

    rep(i,N)
    {
        int x,y;
        cin >> x >> y;
        T[i].first = x;
        T[i].second = y;
    }
    sort(allrange(T));

/*ピタゴラ三角形
    5	12	13
    8	15	17
    3	4	5
*/
    vector<vector<int>> tri(12);
    tri[0]={0,1,1};
    tri[1]={-1,0,1};
    tri[2]={0,-1,1};
    tri[3]={1,0,1};
    tri[4]={3,4,5};
    tri[5]={4,3,5};
    tri[6]={-3,4,5};
    tri[7]={-4,3,5};
    tri[8]={-3,-4,5};
    tri[9]={-4,-3,5};
    tri[10]={3,-4,5};
    tri[11]={4,-3,5};
/*
    vector<vector<int>> tri(0);
    tri.push_back(vector<int>({0,1,1}));
    tri.push_back(vector<int>({-1,0,1}));
    tri.push_back(vector<int>({0,-1,1}));
    tri.push_back(vector<int>({1,0,1}));
    tri.push_back(vector<int>({3,4,5}));
    tri.push_back(vector<int>({4,3,5}));
    tri.push_back(vector<int>({-3,4,5}));
    tri.push_back(vector<int>({-4,3,5}));
    tri.push_back(vector<int>({-3,-4,5}));
    tri.push_back(vector<int>({-4,-3,5}));
    tri.push_back(vector<int>({3,-4,5}));
    tri.push_back(vector<int>({4,-3,5}));
*/
 //   tri.push_back(vector<int>({-5, -12, 13}));
 //   tri.push_back(vector<int>({-12, -5, 13}));
 //   tri.push_back(vector<int>({-8,-15,17}));
 //   tri.push_back(vector<int>({-15,-8,17}));
 //   tri.push_back(vector<int>({5, 12, 13}));
 //   tri.push_back(vector<int>({12, 5, 13}));
 //   tri.push_back(vector<int>({8,15,17}));
 //   tri.push_back(vector<int>({15,8,17}));
 //   tri.push_back(vector<int>({-5, 12, 13}));
 //  tri.push_back(vector<int>({-12, 5, 13}));
  //  tri.push_back(vector<int>({-8,15,17}));
  //  tri.push_back(vector<int>({-15,8,17}));
 //   tri.push_back(vector<int>({5, -12, 13}));
 //   tri.push_back(vector<int>({12, -5, 13}));
 //   tri.push_back(vector<int>({8,-15,17}));
 //   tri.push_back(vector<int>({15,-8,17}));

    bool flg;

    if(S.size()==2 && T.size()==2){
        auto sx = S[0].first-S[1].first;
        auto sy = S[0].second-S[1].second;
        auto tx = T[0].first-T[1].first;
        auto ty = T[0].second-T[1].second;
        flg= (sx*sx+sy*sy==tx*tx+ty*ty);
    } else {
        rep(j,tri.size()){
            auto S2 = Pitagora_rot(S,tri[j][0],tri[j][1],tri[j][2]);
            if(S2.empty()) continue;
            sort(allrange(S2));
            flg = solve_translated(S2,T);
            if(flg) break;
        }
    }
    if(flg) prl("Yes"); else prl("No");
}