#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
using namespace std;
const int N=5e5+10;
int cnt[N],ans[N],a[N];
int n,q,bl;
int res;
struct node
{
    int l,r,p;

}e[N];
bool cmp(const node &a,const node &b)
{
    return (a.l/bl)==(b.l/bl) ? a.r<b.r :a.l>b.l;
}
void remove(int x)
{
    if((--cnt[a[x]])==0) res--;
}
void add(int x)
{
    if((++cnt[a[x]])==1) res++;
}
int main()
{
    scanf("%d %d",&n,&q);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
     bl=sqrt(n);
    for(int i=1,l,r;i<=q;i++)
    {
        scanf("%d %d",&l,&r);
        e[i]={l,r,i};
    }
  //  cout<<"--------------"<<endl;

    sort(e+1,e+1+q,cmp);
   // cout<<"*****"<<endl;
    res=0;
    int curL=1,curR=0;
    for(int i=1;i<=q;i++)
    {
        //cout<<i<<endl;
        int L=e[i].l,R=e[i].r;
        while(curL<L) remove(curL++);
        while(curL>L) add(--curL);
        while(curR<R) add(++curR);
        while(curR>R) remove(curR--);
        ans[e[i].p]=res;
    }
    for(int i=1;i<=q;i++) printf("%d\n",ans[i]);

}

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
static inline void PUT(char c)
{
  static char buf[1<<15],*ptr=buf;
  if(ptr==buf+strlen(buf)||c==0){fwrite(buf,1,ptr-buf,stdout),ptr=buf;}*ptr++=c;
}
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void OUT(int a)
{
  if(a<0)PUT('-'),a=-a;
  int d[40],i=0;do{d[i++]=a%10;}while(a/=10);
  while(i--){PUT(d[i]+48);}PUT('\n');
}
int N=0;
static inline void Add(int *fwt,int i,int v){while(i<N){fwt[i]+=v;i|=i+1;}}
static inline int Sum(int *fwt,int i){int v=0;while(i>=0){v+=fwt[i];i=(i&(i+1))-1;}return v;}
int main()
{
  N=IN();int Q=IN(),after[500001],dat[500000],fenwick[500000],id[500001],left[500001],pos[500000],result[500000];
  rep(i,N){dat[i]=IN()-1;}
  rep(i,Q){left[i+1]=IN()-1;int r=IN()-1;after[i+1]=id[r];id[r]=i+1;}
  for(int r=0;r<N;r++)
  {
    if(pos[dat[r]]){Add(fenwick,pos[dat[r]]-1,-1);}
    Add(fenwick,r,1);
    for(int i=id[r];i;i=after[i]){result[i-1]=Sum(fenwick,r)-Sum(fenwick,left[i]-1);}
    pos[dat[r]]=r+1;
  }
  rep(i,Q){OUT(result[i]);}
}


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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

struct Point{
    ll x;
    ll y;
    Point(ll x, ll y): x(x), y(y) {}
    Point(){}
};

ll field[21][21];

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

    // input
    for(;;){
        // jewel num
        ll N;
        cin >> N;

        if(N==0) return 0;

        Point p = Point(10, 10);

        FOR(i, 0, 21){
            FOR(j, 0, 21){
                field[i][j] = 0;
            }
        }

        // jewel position
        FOR(i, 0, N){
            ll x, y;
            cin >> x >> y;
            field[y][x] = 1;
        }

        // move
        ll count = 0;
        ll M; cin >> M;
        FOR(i, 0, M){
            char c; cin >> c;
            ll len; cin >> len;

            FOR(j, 0, len){
                if(c=='N') p.y++;
                if(c=='S') p.y--;
                if(c=='E') p.x++;
                if(c=='W') p.x--;
                if(field[p.y][p.x]==1){
                    field[p.y][p.x] = 0;
                    count++;
                }
            }
        }
        if(count==N){
            p_yes();
        }else{
            p_no();
        }
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;

class BVCC{
private:
    vector<int> ord,low,used;
    vector<vector<int>> g;
    vector<vector<P<int,int>>> bc;
    vector<P<int,int>> tmp;
    int N,K = 0;
public:
    set<int> ap;
    BVCC(int n,vector<vector<int>> v){
        N = n;
        g = v;
        ord = low = vector<int>(N,-1);
        used = vector<int>(N,0);
    }
    void dfs(int now,int prev){
        used[now] = 1;
        ord[now] = K++;
        low[now] = ord[now];
        int cnt = 0;
        for(auto x:g[now]) if(x!=prev){
            if(ord[x]<ord[now]){
                tmp.emplace_back(min(now,x),max(now,x));
            }
            if(!used[x]){
                cnt++;
                dfs(x,now);
                low[now] = min(low[now],low[x]);
                if(low[x]>=ord[now]){
                    if(now!=0) ap.insert(now);
                    bc.push_back({});
                    while(true){
                        P<int,int> e = tmp.back();
                        bc.back().emplace_back(e);
                        tmp.pop_back();
                        if(min(now,x)==e.first && max(now,x)==e.second) break;
                    }
                }
            }else low[now] = min(low[now],ord[x]);
        }
        if(now==0 && cnt>=2) ap.insert(now);
    }
    void decomposition(){
        dfs(0,-1);
    }
};

int N,M;
int main(){
    cin >> N >> M;
    vector<vector<int>> v(N);
    int a,b;
    for(int i=0;i<M;i++){
        cin >> a >> b;
        v[a].push_back(b); v[b].push_back(a);
    }
    BVCC bvcc(N,v);
    bvcc.decomposition();
    for(auto x:bvcc.ap) cout << x << endl;
}


#include<iostream>
#include<vector>
#include<queue>
using namespace std;

#define INF (1LL << 63)
struct edge{
    size_t to;
    size_t weight;
};

vector<size_t> dijkstra(vector<vector<edge>>& Graph, int& startPoint, int& vertexNum){
    vector<size_t> minimumWeight(vertexNum,INF);
    priority_queue<vector<pair<size_t,size_t>>, vector<pair<size_t,size_t>>, greater<pair<size_t,size_t>>> priorityQueue;
    priorityQueue.push({0,startPoint});
    minimumWeight[startPoint] = 0;
    while(!priorityQueue.empty()){
        pair<size_t,size_t> tmp = priorityQueue.top();
        edge Edge;
        Edge.to = tmp.second;
        Edge.weight = tmp.first;
        priorityQueue.pop();
        if(minimumWeight[Edge.to] < Edge.weight) continue;
        for(edge& edge : Graph[Edge.to]){
            if(minimumWeight[edge.to] < minimumWeight[Edge.to] + edge.weight) continue;
            minimumWeight[edge.to] = minimumWeight[Edge.to] + edge.weight;
            priorityQueue.push({minimumWeight[edge.to],edge.to});
        }
    }
    return minimumWeight;
}

int main(){
    int N,M;
    while(cin >> N >> M, N&&M){
        vector<vector<edge>> costGraph(M);
        vector<vector<edge>> timeGraph(M);

        for(int i = 0;i < N; i++){
            size_t a,b,c,t;
            cin >> a >> b >> c >> t;
            a--,b--;

            costGraph[a].push_back({b,c});
            costGraph[b].push_back({a,c});

            timeGraph[a].push_back({b,t});
            timeGraph[b].push_back({a,t});
        }

        int k;
        cin >> k;
        for(int j=0;j<k;j++){
            int p,q,r;
            cin >> p >> q >> r;
            p--, q--;
            vector<size_t> res;
            if(r == 0) res = dijkstra(costGraph, p, M);
            else res = dijkstra(timeGraph, p, M);

            cout << res[q] << endl;
        }
    }
}


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

int main() {
    string S; cin >> S;
    int ans = 10000;
    rep(s, S.size() - 2) {
        string T = S.substr(s, 3);
        int x = 0;
        rep(i, 3) x = x * 10 + (T[i] - '0');
        ans = min(ans, abs(753 - x));
    }
    cout << ans << endl;
    return 0;
}

#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
using namespace std;
typedef long long LL;
const int N=2e6;
int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
int s1[N],s2[N];
int L[N],R[N],st[N];
int main()
{
	int n=gi(),i,j,top=0,ans=0;char c;
	for (i=1;i<=n;s1[i++]=c-'a') while ((c=getchar())<'a');
	for (i=1;i<=n;s2[i++]=c-'a') while ((c=getchar())<'a');
	for (i=n;i&&s1[i]==s2[i];i--);if (!i) return puts("0"),0;
	for (i=j=n;i;L[j]=i--) {
		while (j&&s1[j]!=s2[i]) j--;
		if (!j) return puts("-1"),0;
		if (!R[j]) R[j]=i,st[++top]=j;
		j-=i==j;
	}
	reverse(st+1,st+1+top);
	for (i=j=1;i<=top;i++) {
		while (j<top&&st[j+1]-(j-i+1)<R[st[i]]) j++;
		ans=max(ans,j-i+1);
	}
	printf("%d\n",ans);
	return 0;
}


#include <cstdio>

#define F(i, a, b) for (LL i = a; i <= b; i ++)
#define G(i, a, b) for (LL i = a; i >= b; i --)
#define pf printf

typedef long long LL;

const LL N = 1e7 + 10;
const LL M = 20;

using namespace std;

LL D, L, Ans, Sum, total, w[M];
LL ten[M], v[M], tot[M], TOT[M];

void Dfs(LL k, LL s, LL S) {
	if (s < 0) return;
	if (s + 10 * v[k] < D) return;
	if (s - 10 * v[k] > D) return;
	if (k > L) {
		if (s == D) {
			Sum += S;
//			printf("Yes\n");
		}
		return;
	}
	F(i, -9, 9)
		w[k] = i, Dfs(k + 1, s + v[k] * i, S * (k == 1 ? TOT[i + 9] : tot[i + 9]));
}

int main() {
	scanf("%lld", &D);
//	F(i, 1, N - 10) {
//		LL rev = 0;
//		for (LL x = i; x; rev = rev * 10 + (x % 10), x /= 10);
//		if (rev - i == D)
//			printf("%lld\n", i), total ++;
//	}

//	puts("");

	F(i, 0, 9)
		F(j, 0, 9)
			tot[i - j + 9] ++;
	F(i, 0, 9)
		F(j, 1, 9)
			TOT[i - j + 9] ++;

	ten[0] = 1;
	F(i, 1, 18)
		ten[i] = ten[i - 1] * 10LL;
	F(i, 2, 18) {
		L = i / 2, Sum = 0;
		F(j, 1, L)
			v[j] = ten[i - j] - ten[j - 1];
		Dfs(1, 0, 1);
		Ans += Sum * ((i & 1) ? 10 : 1);
//		pf("%d\n", i);
	}
	pf("%lld\n", Ans);
}

#include <iostream>
#include <vector>
#include <ios>
#include <limits.h>
using namespace std;
#define FOR(i, s, e) for(int i = s; i < e; ++i)
typedef vector<long> vec;
long long c = 0;

void Merge(vec& vA, int l, int m, int r)
{
	int n1 = m - l;
	int n2 = r - m;
	vec vL(n1 + 1, 0);
	vec vR(n2 + 1, 0);
	FOR(i, 0, n1) vL[i] = vA[l + i];
	FOR(i, 0, n2) vR[i] = vA[m + i];
	vL[n1] = LONG_MAX;
	vR[n2] = LONG_MAX;
	int s = 0, t = 0;
	FOR(i, l, r){
		if ( vL[s] > vR[t]){
			vA[i] = vR[t];
			++t;
			c += n1 - s;
		}else{
			vA[i] = vL[s];
			++s;
		}
	}
}

void CountCross(vec& vA, int l, int r)
{
	if (l + 1 >= r) return;
	int m = (l + r) / 2;
	CountCross(vA, l, m);
	CountCross(vA, m, r);
	Merge(vA, l, m, r);
}

int main()
{
	int n;
	cin >> n;
	vec vA(n, 0);
	FOR(i, 0, n) cin >> vA[i];
	CountCross(vA, 0, n);
	cout << c << "\n";
	return 0;
}


#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define pb push_back
#define mpr make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ll long long
#define ld long double
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define INF 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846264338327950L
#define N 100005
#define mid(l, r) l + (r - l) / 2
#define vec vector<int>
#define vecl vector<ll>
#define umap unordered_map<ll,ll>
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define endl "\n"
using namespace std;

int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}

void test_case() {

    int a , b , c;
    cin>>a>>b>>c;

    swap(a,b);
    swap(a,c);

    cout<<a<<" "<<b<<" "<<c<<endl;

}

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

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

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

#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
//#include<bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 10000000000000000;
const int mod = 1000000007;
int test[12345678], kari[345678], aa[12345678];
signed main() {
	int n, a, b, ans; cin >> n >> a >> b;
	n++; cout << (n - a)*(n - b) << endl;
	cin >> n; return 0;
}


#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
#define F first
#define S second

int a[100009][20];
int b[100009];
int n,L,test;

signed main(){
	cin>>n;
	r(i,n) cin>>b[i];
	cin>>L;
	r(j,20){
		if(j==0){
			int id=0,sum=0;
			r(i,n){
				while(id<n-1 && sum+(b[id+1]-b[id])<=L) sum += b[id+1]-b[id],id++;
				a[i][j] = id;
				//cout<<id<<endl;
				if(i!=n-1 && sum)sum -=b[i+1]-b[i];
			}
		}
		else{
			r(i,n){
				a[i][j] = a[a[i][j-1]][j-1];
			}
		}
	}

	cin>>test;
	while(test--){
		int l,r;
		cin>>l>>r; l--; r--;
		if(r<l)swap(l,r);
		int sum=0;
		while(l<r){
			//cout<<l<<endl;
			for(int i=19;i>=0;i--){
				if(i&&( a[l][i]>=r ))continue;
				//cout<<l<<' '<<i<<' '<<a[l][i]<<' '<<i<<endl;
				l=a[l][i];
				sum+=pow(2,i);
				break;
			}
			//cout<<l<<endl;
		}
		cout<<sum<<endl;
	}
}

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

const int inf = 2e9;
const int N = 100100;

int n, x[N], L, Q, dp[N][17];

void calc() {
	for (int i = 0; i < N; i++)
		for (int j = 0; j < 17; j++)
			dp[i][j] = inf;
	for (int i = 1; i <= n; i++) {
		auto it = upper_bound(x + 1, x + 1 + n, x[i] + L);
		it--;
		dp[i][0] = it - x;
	}
	for (int j = 1; j < 17; j++)
		for (int i = 1; i <= n; i++)
			dp[i][j] = dp[dp[i][j - 1]][j - 1];
}

int get(int l, int r) {
	if (l > r) swap(l, r);
	int ll = 1, rr = n - 1, res = r - l;
	while (ll <= rr) {
		int mid = ll + rr >> 1, cur = l;
		for (int i = 0; i < 17; i++)
			if (mid & (1 << i)) cur = dp[cur][i];
		if (cur >= r) {
			res = mid;
			rr = mid - 1;
		} else ll = mid + 1;
	}
	return res;
}

int main() {
	cin >> n;
	fill(x, x + N, inf);
	for (int i = 1; i <= n; i++)
		cin >> x[i];
	cin >> L >> Q;
	calc();
	while (Q--) {
		int l, r;
		cin >> l >> r;
		cout << get(l, r) << '\n';
	}
}


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

int main() {
    ll N;
    cin >> N;
    string S;
    getline(cin, S);
    getline(cin, S);

    vector<ll> R;
    vector<ll> G;
    vector<ll> B;
    set<ll> RS;
    set<ll> GS;
    set<ll> BS;
    for (ll i = 0; i < S.length(); i++) {
        char c = S.at(i);
        if (c == 'R') {
            R.push_back(i);
            RS.insert(i);
        } else if (c == 'G') {
            G.push_back(i);
            GS.insert(i);
        } else {
            B.push_back(i);
            BS.insert(i);
        }
    }

    ll total = 0;
    // ll tpre = 0;
    for (ll i = 0; i < S.length(); i++) {
        char ci = S.at(i);
        for (ll j = i + 1; j < S.length(); j++) {
            char cj = S.at(j);
            ll notk = j + j - i;
            if (ci == 'R') {
                if (cj == 'G') {
                    total += B.end() - lower_bound(B.begin(), B.end(), j) - BS.count(notk);
                } else if (cj == 'B') {
                    total += G.end() - lower_bound(G.begin(), G.end(), j) - GS.count(notk);
                }
            } else if (ci == 'G') {
                if (cj == 'R') {
                    total += B.end() - lower_bound(B.begin(), B.end(), j) - BS.count(notk);
                } else if (cj == 'B') {
                    total += R.end() - lower_bound(R.begin(), R.end(), j) - RS.count(notk);
                }
            } else if (ci == 'B') {
                if (cj == 'R') {
                    total += G.end() - lower_bound(G.begin(), G.end(), j) - GS.count(notk);
                } else if (cj == 'G') {
                    total += R.end() - lower_bound(R.begin(), R.end(), j) - RS.count(notk);
                }
            }
            // if (tpre != total) {
            //     print(i, j, total - tpre);
            // }
            // tpre = total;
        }
    }
    print(total);
}

#include <bits/stdc++.h>

using namespace std;
const long long INF = 1LL <<60;

int main(void){
  long long res=0;
  long long i,j,k;
  long long l,m,h;
  string s;
  long long n_r=0,n_g=0,n_b=0;
  long long n_max=4010;
  long long n;
  long r[n_max]={},g[n_max]={},b[n_max]={};

  cin>>n;
  cin>>s;
  for(i=0;i<n;i++){
    if(s[i]=='R'){
      r[n_r]=i;
      n_r++;
    }
    else if(s[i]=='G'){
      g[n_g]=i;
      n_g++;
    }
    else{
      b[n_b]=i;
      n_b++;
    }
  }
  res=n_r*n_g*n_b;
  //cout<<n_r<<" "<<n_g<<" "<<n_b<<endl;

  for(i=0;i<n_r;i++){
    for(j=0;j<n_g;j++){
      h=max(r[i],g[j]);
      l=min(r[i],g[j]);
      if(2*l-h>=0 && s[2*l-h]=='B'){
        res--;
      }
      if(2*h-l<n && s[2*h-l]=='B'){
        res--;
      }
      if((h+l)%2==0 && s[(h+l)/2]=='B'){
        res--;
      }
    }
  }

  cout<<res<<endl;
  return 0;
}


#include "bits/stdc++.h"

#define REP(i,num) for(ll i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){T x; cin >> x; return (x);}
template<typename T=ll,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	string S=in<string>();
	map<char,ll> M;
	for(auto& x:S) M[x]++;
	ll N=S.size();
	ll A=N*(N-1LL)/2LL;
	for(auto& x:M){
		A -= x.second*(x.second-1LL)/2LL;
	}
	out(A+1LL);
	return 0;
}

#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<map>
#include<cstring>
#define p pair<int,int>
#define P pair<int,p>
using namespace std;

P a[100000];
int Par[10000], Rank[10000];
int saiki(int b) {
	if (Par[b] == b)return b;
	return Par[b]=saiki(Par[b]);
}
void unite(int b, int c) {
	b = saiki(b); c = saiki(c);
	if (Rank[b] > Rank[c]) {
		Par[c] = b;
	}
	else if (Rank[b] < Rank[c]) {
		Par[b] = c;
	}
	else {
		Par[c] = b;
		Rank[b]++;
	}
}
signed main() {
	int b, c; cin >> b >> c;
	for (int d = 0; d < c; d++) {
		int e, f, g; scanf("%d%d%d", &e, &f, &g);
		a[d] = P(g, p(e, f));
	}
	sort(a, a + c);
	int cost = 0;
	for (int i = 0; i < b; i++)Par[i] = i;
	for (P s : a) {
		if (saiki(s.second.first) != saiki(s.second.second)) {
			cost += s.first;
			unite(s.second.first, s.second.second);
		}
	}
	cout << cost << endl;
}


#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 1987654321987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const ll MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) {ll ret=1; for(;b;b>>=1,a=(a*a)%MMM)if(b&1)ret=(ret*a)% MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };

int n,A,B,C,D;
ll d[1001][1001];
ll fac[1001],inv[1001];
ll go(int N,int K)
{
	if(N==0)return fac[n];
	if(K>B)return 0;
	ll &ret=d[N][K];
	if(ret!=-1)return ret;
	ret=go(N,K+1);
	for(int i=C;i<=D && i*K<=N;i++)
	{
		ll tt=POW(inv[K],i);
		ll t=(tt*inv[i])%MOD;
		ret=(ret+t*go(N-i*K,K+1))%MOD;
	}
	return ret;
}
int main() {
	fac[0] = inv[0] = 1;
	fup(i, 1, 1000, 1)
		fac[i] = (fac[i - 1] * i) % MOD;
	inv[1000] = POW(fac[1000], MOD - 2);
	fdn(i, 999, 1, 1)
		inv[i] = (inv[i + 1] * (i+1)) % MOD;
	MEM_1(d);
	scanf("%d%d%d%d%d",&n,&A,&B,&C,&D);
	printf("%lld",go(n,A));
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
using Graph = vector<vector<int>>;
const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val)
{
    std::fill((T*)array, (T*)(array + N), val);
}

// dp[c1][c2][c3]: (1個の皿がc1枚，2個の皿がc2枚，3個の皿がc3枚の状態ですべて食べるまでの操作回数の期待値)
double dp[305][305][305];
int N;

double rec(int c1, int c2, int c3)
{
    if (dp[c1][c2][c3] != -1.0)
        return dp[c1][c2][c3];

    double ret = N;
    if (c1 >= 1) {
        ret += c1 * rec(c1 - 1, c2, c3);
    }
    if (c2 >= 1) {
        ret += c2 * rec(c1 + 1, c2 - 1, c3);
    }
    if (c3 >= 1) {
        ret += c3 * rec(c1, c2 + 1, c3 - 1);
    }
    ret /= (c1 + c2 + c3);

    return dp[c1][c2][c3] = ret;
}
int main()
{
    cin >> N;
    Fill(dp, -1.0);
    dp[0][0][0] = 0;
    int c1, c2, c3;
    c1 = c2 = c3 = 0;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        if (a == 1)
            c1++;
        if (a == 2)
            c2++;
        if (a == 3)
            c3++;
    }

    cout << fixed << setprecision(9);
    cout << rec(c1, c2, c3) << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int B = 100000007;
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) {
  cout << (expr ? "Yes" : "No") << "\n";
}
lint power(lint x, lint n, lint mod) {
  lint ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= mod;
    (x *= x) %= mod;
    n >>= 1;
  }
  return ret;
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int N;
  cin >> N;
  vector<lint> a(N);
  REP(i, N) cin >> a[i];
  vector<lint> b(N);
  REP(i, N) cin >> b[i];
  vector<lint> pa(N);
  vector<lint> pb(N);
  REP(i, N) {
    pa[i] = a[i] ^ a[(i+1)%N];
    pb[i] = b[i] ^ b[(i+1)%N];
  }
  lint hash = 0;
  lint target = 0;
  REP(i, N) {
    hash = (hash + pa[i]*power(B, i, MOD)) % MOD;
    target = (target + pb[i]*power(B, i, MOD)) % MOD;
  }
  vector<pair<lint, lint>> ans;
  REP(i, N) {
    //cout << hash << " " << target << endl;
    if(hash == target) {
      lint x = b[0] ^ a[i];
      ans.push_back(make_pair(i, x));
    }
    hash = hash * power(B, MOD-2, MOD) % MOD;
    hash = (hash - pa[i]*power(B, MOD-2, MOD) % MOD + pa[i]*power(B, N-1, MOD) + MOD) % MOD;
  }
  sort(ans.begin(), ans.end(), [](auto const &a, auto const &b) { return a.first < b.first; });
  REP(i, ans.size()) {
    cout << ans[i].first << " " << ans[i].second << "\n";
  }

}

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, a[200005] = {}, b[200005] = {}, c[600005] = {}, d[600005] = {};
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];
    a[n] = a[0]; b[n] = b[0];
    for (int i = 0; i < n; i++) c[i] = b[i] ^ b[i + 1];
    c[n] = -1;
    for (int i = n + 1; i <= n + n; i++) c[i] = a[i - n - 1] ^ a[i - n];
    for (int i = n + n + 1; i <= n + n + n; i++) c[i] = c[i - n];
    for (int i = 1; i <= n + n + n + 1; i++) {
        int x = i - 1;
        while (x && d[x] != i - 1 && c[d[x]] != c[i - 1]) x = d[x];
        if (x) d[i] = d[x] + 1;
    }
    for (int i = n + n + 1; i <= n + n + n; i++) if (d[i] == n) cout << i - n - n - 1 << ' ' << (a[i - n - n - 1] ^ b[0]) << '\n';
}


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

int main(){
	int n,m,i,j;
	while(cin >> n >> m, n && m){
		int ret = 0;
		vector<int> data(n+1);
		vector<int> all;
		for(i=0;i<n;i++)cin >> data[i];
		for(i=0;i<n+1;i++)
			for(j=i;j<n+1;j++)
				all.push_back(data[i]+data[j]);
		sort(all.begin(),all.end());

		for(i=0;i<all.size();i++){
			int t = m-all[i];
			vector<int>::iterator it = upper_bound(all.begin(),all.end(),t);
			if(it != all.begin()){
				ret = max(ret,all[i] + *(it-1) );
			}
		}
		cout << ret << endl;
	}
}

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

typedef pair<int,pair<int, int> > P;

int main() {

	while (1) {

		int h, w;
		vector<P> pos;
		cin >> h >> w;

		if (h == 0)break;

		int X = pow(h, 2) + pow(w, 2);
		//cout << X << endl;

		for (int i = 1; i <= 150; i++) {
			for (int j=i+1; j <= 150; j++) {
				int x = pow(i, 2) + pow(j, 2);
				if (x > X) {
					//cout << i << ' ' << j << ' ' << x << endl;
					pos.push_back(make_pair(x, make_pair(i, j)));
				}
				else if (x == X && i > h) {
					pos.push_back(make_pair(x, make_pair(i, j)));
				}
			}
		}

		int n = 10000, m, minx=pow(X,2);
		for (int i = 0; i < pos.size(); i++) {
			if (pos[i].first < minx) {
				minx = pos[i].first;
				n = pos[i].second.first;
				m = pos[i].second.second;
			}
			else if (pos[i].first == minx && pos[i].second.first < n) {
				minx = pos[i].first;
				n = pos[i].second.first;
				m = pos[i].second.second;
			}
		}

		cout << n << ' ' << m << endl;
	}
	return 0;
}


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

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int x, y;
	cin >> x >> y;
	int total = 0;
	if (x <= 3)
		total += 4 - x;
	if (y <= 3)
		total += 4 - y;
	if (x == 1 && x == y) {
		total += 4;
	}
	total *= int(1e5);
	cout << total;
}

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

typedef long long ll;
typedef pair<int, int> P;

#define mod 1000000007
#define inf 1000000000
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define popcount(x) __builtin_popcountll(x)

const long double PI = acos(-1);

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

int main(){
  ll x, y;
  cin >> x >> y;
  ll ans = 0;
  if(x == 1) ans += 300000;
  if(x == 2) ans += 200000;
  if(x == 3) ans += 100000;
  if(y == 1) ans += 300000;
  if(y == 2) ans += 200000;
  if(y == 3) ans += 100000;

  if(x == 1 && y == 1) ans += 400000;

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


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;

    }else{
        return a.second < b.second;
    }
}

bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};

int main() {
    ll A,B;
    cin >>A>>B;
    ll ans;
    if(A==B){
        ans = A+B;
    }else{
        ans = max(A,B)*2-1;
    }

    cout << ans << endl;

    return 0;

}

#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<math.h>
using namespace std;
using ll = int64_t;
using Graph = vector<vector<int> >;
const ll M = 1000000007;

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

    vector<int> w(n,0);
    vector<int> e(n,0);
    int cntw=0,cnte=0;
    for(int i=0;i<n;i++){
        if(s.at(i)=='W')cntw++;
        w.at(i)=cntw;
    }

    for(int i=n-1;i>=0;i--){
        if(s.at(i)=='E')cnte++;
        e.at(i)=cnte;
    }

    int ans=n;
    for(int i=0;i<n;i++){
        int tmp=e.at(i)+w.at(i)-1;
        ans=min(ans,tmp);
    }

    cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define read(n) cin>>n;
#define write(n) cout<<n;
#define loop(x,n) for(int x = 0; x < n; ++x)
#define vector_loop(x,n) for(int i = 0; x < n; i++)
#define vii vector<int> a(n)
typedef pair<int, int> pii;
#define endl "\n"
#define sd(val) scanf("%d", &val)
#define ss(val) scanf("%s", &val)
#define sl(val) scanf("%lld", &val)
#define debug(val) printf("check%d\n", val)
#define all(v) v.begin(), v.end()
#define MP make_pair
#define FF first
#define SS second
#define ll long long
#define MOD 1000000007
#define clr(val) memset(val, 0, sizeof(val))
#define what_is(x) cerr << #x << " is " << x << endl;
#define OJ                            \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define FIO                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

int main()
{
	FIO;

	int a;
	cin >> a;
	cout << a + a*a + a*a*a;

	return 0;
}

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
  int a,ans;
  cin>>a;
  ans=a+pow(a,2)+pow(a,3);
  cout<<ans<<endl;
  return 0;
}


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

int main() {
    int n;
    string s;
    cin >> n >> s;
    auto check = [&](char out0, char out1) {
        auto a = out0;
        char out2;
        auto v = vector<char>();
        v.push_back(out0);
        v.push_back(out1);
        auto f = [](char in1, char out0, char out1) {
            char out2;
            if (in1 == 'o') {
                if (out0 == 'S' && out1 == 'S') out2 = 'S';
                if (out0 == 'S' && out1 == 'W') out2 = 'W';
                if (out0 == 'W' && out1 == 'S') out2 = 'W';
                if (out0 == 'W' && out1 == 'W') out2 = 'S';
            } else {
                if (out0 == 'S' && out1 == 'S') out2 = 'W';
                if (out0 == 'S' && out1 == 'W') out2 = 'S';
                if (out0 == 'W' && out1 == 'S') out2 = 'S';
                if (out0 == 'W' && out1 == 'W') out2 = 'W';
            }
            return out2;
        };
        for (int i = 1; i < n; i++) {
            char in1 = s[i];
            out2 = f(in1, out0, out1);
            v.push_back(out2);
            out0 = out1;
            out1 = out2;
        }

        if (out2 == a) {
            v.erase(v.end() - 1);
            if (f(s[0], v[n - 1], v[0]) == v[1]) {
                return v;
            }
        }
        return vector<char>();
    };

    auto intToC = [](int a) {
        return a == 0 ? 'S' : 'W';
    };

    for (int i = 0; i < 4; i++) {
        char out0 = intToC(i % 2);
        char out1 = intToC(i / 2 % 2);
        auto v = check(out0, out1);
        if (v.size() > 0) {
            for (auto c : v) {
                putchar(c);
            }
            puts("");
            return 0;
        }
    }

    puts("-1");
}

#include <bits/stdc++.h>

using namespace std;

#define loop(i, n) for(int i = 0;i < int(n);i++)
#define rloop(i, n) for(int i = int(n);i >= 0;i--)
#define range(i, a, b) for(int i = int(a);i <= int(b);i++)
#define SZ(c) int(c.size())
#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()
#define PI acos(-1)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1, v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1, v2, v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1, v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1, v2, v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define endl '\n'

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

const int N = 1e5 + 5;
int dp[N][2][2];
int vis[N][2][2], visid;
int F, L;
string str;
int n;
//sheep 0 , wolf 1

int solve(int idx, int cur, int lst) {
    int &ret = dp[idx][cur][lst];
    if (vis[idx][cur][lst] == visid)return ret;
    vis[idx][cur][lst] = visid;
    if (idx == n - 1) {
        if (cur != L)return ret = 0;
        if (cur == 0) {
            ret = (str[idx] == 'o' && F == lst || str[idx] == 'x' && F != lst);
        } else {
            ret = (str[idx] == 'x' && F == lst || str[idx] == 'o' && F != lst);
        }
        return ret;
    }

    int nxt;
    if (cur == 0) {
        //truth
        nxt = (str[idx] == 'o') ? lst : (!lst);
        ret = solve(idx + 1, nxt, cur);
    } else {
        //lie
        nxt = (str[idx] == 'o') ? (!lst) : lst;
        ret = solve(idx + 1, nxt, cur);
    }
    return ret;
}

string ans;

void build(int idx, int cur, int lst) {
    ans += (cur ? 'W' : 'S');
    if (idx == n - 1)return;
    int nxt;
    if (cur == 0) {
        //truth
        nxt = (str[idx] == 'o') ? lst : (!lst);
        build(idx + 1, nxt, cur);
    } else {
        //lie
        nxt = (str[idx] == 'o') ? (!lst) : lst;
        build(idx + 1, nxt, cur);
    }
}

int main() {

#ifndef ONLINE_JUDGE
    freopen("in.in", "r", stdin);
    //freopen("out.in", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> str;

    loop(f, 2) {
        loop(l, 2) {
            F = f, L = l;
            visid++;
            if (solve(0, f, l)) {
                build(0, f, l);
                cout << ans << endl;
                return 0;
            }
        }
    }

    cout << -1 << endl;

    return 0;
}


#include <bits/stdc++.h>

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

using namespace std;

int main(){
	string s; cin>>s;
	cout<<s.substr(0,s.length()-8)<<'\n';
	return 0;
}

#include <iostream>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <float.h>
#include <limits>
#include <vector>
#include <string.h>
#include <iomanip>

#define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define INF 2147483647
#define ll long long
#define asort(a) sort(a.begin(),a.end());//昇順ソート
#define usort(a) sort(a.rbegin(),a.rend());//降順ソート

using namespace::std;

int jo(ll int a, ll int b){//累乗
    ll int num=1;
    rep(i,0,b) num=num*a;
    return num;
}
char tobig(char s){//char大文字化
  return (s-0x20);
}
char tolow(char s){//char小文字化
  return (s+0x20);
}
int ctoi(char a){//char->int
  if('0'<=a&&a<='9') return (a-'0');
  return -1;
}

int gcd(ll int a,ll int b) {//最大公約数
  if(a<b) return gcd(b,a);
  int c;
  while ((c=a%b)) {
    a=b;
    b=c;
  }
  return b;
}
int lcm(ll int a,ll int b){//最小公倍数
 return (a*b)/gcd(a,b);
}

int main(){
  string S;cin>>S;
  rep(i,0,8) S.pop_back();
  cout<<S;
}

// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//cout<<fixed<<setprecision(n);  //小数点n桁まで表示

//  vector<pair<int,int>> data(N);  //2つのデータを格納、.first/.secondで参照
// pairのソートはfirst優先の昇順


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

int main()
{
int n,g=0; cin>>n;
while(n>=3)
{
    g++; n-=3;
}
cout<<g;
return 0;
}

#include <iostream>
using namespace std;
int main (){

 int N;
  cin>>N;
  cout<<N/3;
  return 0;
}


#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
const long long INF = 1LL << 60;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int X,Y;
  cin >> X >> Y;
  if(X==1&&Y==1)
  {
    cout << 1000000 << endl;
    return 0;
  }
  int sum = 0;
  if(X==1)
  {
    sum += 300000;
  }
  else if(X==2)
  {
    sum += 200000;
  }
  else if(X==3)
  {
    sum += 100000;
  }
  if(Y==1)
  {
    sum += 300000;
  }
  else if(Y==2)
  {
    sum += 200000;
  }
  else if(Y==3)
  {
    sum += 100000;
  }
  cout << sum << endl;
  return 0;
}

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

typedef long long ll;
typedef pair<int, int> P;

struct edge {int to; ll cost; };

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

int main(){
  string s, t;
  cin >> s >> t;
  cout << t << s << endl;
  return 0;
}


#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int INF = 1e9+7;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define rtr(c, i) for(auto i = (c).rbegin(); i != (c).rend(); i++)
#define repab(i,a,b) for(auto i=a;i<(b);i++)
#define rep(i,b) for(auto i=0;i<(b);i++)
#define pb push_back
#define sz(c) int((c).size())

enum {
  FOUR_CARD,
  FULL_HOURSE,
  STRAIGHT,
  THREE_CARD,
  TWO_PAIR,
  ONE_PAIR,
  NULL_HAND,
} hands;

int check(map<int, int> m)
{
  int maxnr = 0;
  int minnr = INF;
  int maxv = 0;
  int minv = INF;
  int maxnr_count = 0;
  tr (m, i) {
    if (maxnr < i->second) {
      maxnr_count=1;
      maxnr = i->second;
    } else if (maxnr == i->second) {
      maxnr_count++;
    }
    minnr = min(minnr, i->second);
    maxv = max(maxv, i->first);
    minv = min(minv, i->first);
  }
  if (maxnr == 4)
    return FOUR_CARD;
  if (maxnr == 3 && minnr == 2)
    return FULL_HOURSE;
  if (minnr == 1 && maxnr == 1) {
    if ((maxv - minv == 4) || (m[10] && m[11] && m[12] && m[13] && m[1]))
      return STRAIGHT;
  }
  if (maxnr == 3)
    return THREE_CARD;
  if (maxnr == 2) {
    if (maxnr_count == 2)
      return TWO_PAIR;
    else
      return ONE_PAIR;
  }

  return NULL_HAND;
}
void phand(map<int, int> m)
{
  vector<string> hand_name = {
    "four card",
    "full house",
    "straight",
    "three card",
    "two pair",
    "one pair",
    "null",
  };
  cout << hand_name[check(m)] << endl;
}

int main(int argc, char **argv)
{
  vi v;
  map<int, int> m;
  char c;
  int x, minval;

  for (;;) {
    v.clear();
    m.clear();
    rep (i, 4) {
      cin >> x;
      cin >> c;
      v.pb(x);
    }
    cin >> x;
    v.pb(x);
    if (cin.eof())
      break;

    rep (i, 5) {
      m[v[i]]++;
    }
    phand(m);
  }
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
	int a[6] = {};
	while(scanf("%d",&a[0])!=EOF){
		for(int i=1;i<5;i++)scanf(",%d", &a[i]);
			int cnt=0,flag=true,card[13]={},max = 4;
		sort(a,a+5);
		for (int i=0;i<4;i++)for(int j=i+1;j<5;j++)
			if (a[i]==a[j])cnt++;
		int i=0;
		if(a[i]==1&&a[i+1]==10){
			i=1;
			max=5;
			a[5]=14;
		}
		for(;i<max;i++)if(a[i]+1!=a[i+1])flag=0;
if (cnt == 6)printf("four card\n");
else if (cnt == 4)printf("full house\n");
else if (flag)printf("straight\n");
else if (cnt == 3)printf("three card\n");
else if (cnt == 2)printf("two pair\n");
else if (cnt == 1)printf("one pair\n");
else printf("null\n");
}
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    if(s[0]=='S' && s[2]=='N')
        cout<<7-0;
    else if(s[2]=='T')
        cout<<7-6;
    else if(s[0]=='F')
        cout<<7-5;
    else if(s[2]=='U')
        cout<<7-4;
    else if(s[0]=='W')
        cout<<7-3;
    else if(s[2]=='E')
        cout<<7-2;
    else if(s[0]=='M')
        cout<<7-1;

   return 0;
}

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define itn int
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>=1;i--)
#define all(vec) vec.begin(),vec.end()
#define sort(vec) sort((vec).begin(),(vec).end())
#define rsort(vec) sort((vec).rbegin(), (vec).rend())
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;
const ll lnf=1ll<<60;

int main(){
  ll k; cin >> k;
  ll n=50;
  vector<ll> ans(50);
  rep(i,50) ans[i]=i+k/n;
  for(int i=n-k%n;i<n;i++) ans[i]++;
  cout << n << endl;
  rep(i,n) cout << ans[i] << " ";
  cout << endl;
}


//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

int main(){
    ll N;
    cin>>N;
    vector<ll> a(N),b(N),c(N),d(N);
    REP(i,N){
        cin>>a[i]>>b[i];
    }

    REP(i,N){
        cin>>c[i]>>d[i];
    }
    vector<vector<bool>> p(110,vector<bool>(110,false));
    ll cnt=0;
    REP(i,N){
        REP(j,N){
            if(a[i]<c[j]&&b[i]<d[j]){
                p[i][j]=true;
                cnt++;
            }
        }
    }
    ll lose=INF;
    ll ans=0;
    while(lose>0){
        ll lose_m=INF;
        ll idx=-1,jdx=-1;
        REP(i,N){
            REP(j,N){
                if(p[i][j]==false) continue;
                lose=0;
                REP(k,N){
                    if(p[i][k]==true) lose++;
                    if(p[k][j]==true) lose++;
                }
                lose--;
                if(lose<lose_m){
                    lose_m=lose;
                    idx=i;
                    jdx=j;
                }
            }
        }
        if(idx==-1||jdx==-1) break;
        REP(k,N){
            p[idx][k]=false;
            p[k][jdx]=false;
        }

        cnt-=lose_m;
        ans++;

    }
    cout<<ans<<endl;

}

#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

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

    vector<pair<int, int>> reds(N);
    for (int i = 0; i < N; i++) {
        int a, b;
        cin >> a >> b;
        reds[i] = {a, b};
    }
    // descending order by y
    sort(reds.begin(), reds.end(), [](const pair<int, int> a, const pair<int, int> b) {
            return a.second > b.second;
                    });

    vector<pair<int, int>> blues(N);
    for (int i = 0; i < N; i++) {
        int a, b;
        cin >> a >> b;
        blues[i] = {a, b};
    }
    sort(blues.begin(), blues.end());

    int cnt = 0;
    vector<bool> used_red(N, false);

    for (int bi = 0; bi < N; bi++) {
        for (int ri = 0; ri < N; ri++) {
            if (used_red[ri]) {
                continue;
            }
            auto blue = blues[bi];
            auto red = reds[ri];
            if (red.first < blue.first && red.second < blue.second) {
                cnt++;
                used_red[ri] = true;
                break;
            }
        }
    }

    cout << cnt << endl;
    return 0;
}


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

int main(){
  int N;
  string S;
  cin >> N >> S;
  vector<int> W(N,0);
  for(int i=0;i<N;i++){
    if(i==0 && S.at(i)=='W') W.at(i) = 1;
    else if(i==0 && S.at(i)=='E') W.at(i) = 0;
    else if(S.at(i)=='W') W.at(i) = W.at(i-1) +1;
    else W.at(i) = W.at(i-1);
  }
  int p_min = 0;
  for(int i=0;i<N;i++){
    if(i==0) p_min = N - 1 - W.at(N-1) + W.at(i);
    else if(p_min > W.at(i-1) + ( N - (i+1) ) - ( W.at(N-1) - W.at(i) ) ){
      p_min = W.at(i-1) + ( N - (i+1) ) - ( W.at(N-1) - W.at(i) );
    }
  }
  cout << p_min << endl;
}

#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

int main(){
  int n,k; cin >> n >> k;
  cout << n-k+1 << endl;
}


// https://atcoder.jp/contests/abc152/tasks/abc152_c

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

int main()
{
    long a, b;
    cin >> a >> b;
    long ans = 0;
    for (int x = a; x <= b; x++)
    {
        string s, t;
        s = to_string(x);
        t = s;
        reverse(t.begin(), t.end());
        if (s == t)
        {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
	int a, b;
	int c;
	int sum = 0;
	cin >> a >> b;
	c = a;
	for (int i= 0; i < b-a+1; i++)
	{
		if (c/10000 == c-(c/10)*10 && c/1000 - (c/10000)*10 == c/10 - (c/100)*10 )
		{
		sum += 1;
		c++;
		continue;
		}

		else
		{
			c++;
			continue;
		}

	}
	cout << sum << endl;
}


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

vector<int> FordFulkerson_dfs_sub(
    const vector<map<int, int>>& graph, // source, (target, capacity)
    int source, int target, set<int>& prev)
{
    if(source==target) return vector<int>{source};
    for(auto v : graph.at(source)){
        if(v.second == 0) continue;
        if(prev.count(v.first) > 0) continue;
        prev.insert(source);
        auto ret = FordFulkerson_dfs_sub(graph, v.first, target, prev);
        if(ret.size() != 0){
            ret.push_back(source);
            return ret;
        }
    }
    return vector<int>();
}

vector<int> FordFulkerson_dfs(
    const vector<map<int, int>>& graph, // source, (target, capacity)
    int source, int target)
{
    auto s = set<int>();
    auto ret = FordFulkerson_dfs_sub(graph, source, target, s);
    reverse(ret.begin(), ret.end());
    return ret;
}

// Graph: Directed, no loop
// Complexity: E * (max flow)
vector<map<int, int>> FordFulkerson(
    vector<map<int, int>> graph, // source, (target, capacity)
    int s, int t)
{
    const int N = graph.size();
    auto res = graph;

    // Add inverted edges
    for(int i=0; i<N; i++){
        for(auto e : res[i]){
            auto v = e.first;
            graph[v][i] = -0;
        }
    }

    while(true){
        auto path = FordFulkerson_dfs(graph, s, t);
        if(path.size()==0) break;
        int c_min = numeric_limits<int>::max();
        for(int i=0; i<path.size()-1; i++){
            auto u = path[i];
            auto v = path[i+1];
            c_min = min(c_min, graph[u][v]);
        }
        if(c_min == 0) break;
        for(int i=0; i<path.size()-1; i++){
            auto u = path[i];
            auto v = path[i+1];
            graph[u][v] -= c_min;
            graph[v][u] += c_min;
        }
    }
    for(int i=0; i<res.size(); i++){
        for(auto v : res[i]){
            res[i][v.first] = graph[v.first][i];
        }
    }
    return res;
}

vector<array<int, 2>> MaximumMatching(
    vector<vector<int>> graph // source, target
){
    const int N = graph.size();
    vector<map<int, int>> graph2(2 + 2 * N);
    for(int i=0;i<N;i++){
        graph2[2*N][i] = 1;
        graph2[N+i][2*N+1] = 1;
        for(auto v : graph[i]){
            graph2[i][v + N] = 1;
        }
    }
    auto ret = FordFulkerson(graph2, 2*N, 2*N+1);
    vector<array<int, 2>> res;
    for(int i=0;i<N;i++){
        for(auto m : ret[i]){
            if(m.second == 0) continue;
            res.push_back(array<int, 2>{i, m.first});
        }
    }

    return res;
}

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> B(N);
    vector<int> C(N);
    vector<int> D(N);
    for(int i=0;i<N;i++) cin >> A[i] >> B[i];
    for(int i=0;i<N;i++) cin >> C[i] >> D[i];
    vector<vector<int>> graph(N);
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(A[i] < C[j] && B[i] < D[j]){
                graph[i].push_back(j);
            }
        }
    }
    auto ret = MaximumMatching(graph);
    cout << ret.size() << endl;

    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<vector<int>> ab(N, vector<int>(2));
  for (int i = 0; i < N; i++) {
    cin >> ab.at(i).at(1) >> ab.at(i).at(0);
  }
  vector<vector<int>> cd(N, vector<int>(2));
  for (int i = 0; i < N; i++) {
    cin >> cd.at(i).at(0) >> cd.at(i).at(1);
  }
  sort(ab.begin(), ab.end());
  reverse(ab.begin(), ab.end());
  sort(cd.begin(), cd.end());
  int ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (cd.at(i).at(1) > ab.at(j).at(0) && cd.at(i).at(0) > ab.at(j).at(1)) {
        ans++;
        ab.at(j).at(0) = 200;
        ab.at(j).at(1) = 200;
        break;
      }
    }
  }
  cout << ans << endl;
}


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

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

  if(A+B<=16 && A<=8 && B<=8) cout << "Yay!" << endl;
  else cout << ":(" << endl;

}

#include <bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define e "\n"
#define MaRiaMa { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
#define fix(n) cout << fixed << setprecision(n);
using namespace std;
int main()
{
	MaRiaMa;
	int a, b,sum=16;
	cin >> a >> b;
	int s = max(a, b) - min(a, b);
	if (s == 0)
		cout << "Yay!";
	else
	{
		sum -= (2*min(a,b));
		if ((s += s) <= sum)
			cout << "Yay!";
		else
			cout << ":(";
	}
}


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

int main()
{
    int N, cnt = 0;
    cin >> N;
    vector<long long> vec(N);

    for (int i = 0; i < N; i++) {
        cin >> vec[i];
        if (vec[i] % 2 != 0) {
            cout << cnt << endl;
            return 0;
        }
    }

    while (true) {
        for (int i = 0; i < N; i++) {
            if (vec[i] % 2 != 0) {
                cout << cnt << endl;
                return 0;
            } else {
                vec[i] /= 2;
            }
        }
        cnt++;
    }
}

#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
int kai(int a) {
	int n = 0;
	while (1) {
		if (a % 2 == 0) {
			a = a / 2;
			n++;
		}
		else break;
	}
	return n;
}
int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	int count = 100000;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		count = min(kai(A[i]), count);
	}
	cout << count << endl;
	return 0;
}


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

void fnInput(vector<int> &a_rviTarget, vector<int> &a_rviSearch)
{
  int iTargetCnt;
  cin >> iTargetCnt;

  a_rviTarget.resize(iTargetCnt + 1);
  for (int i = 0; i < iTargetCnt; i++)
    cin >> a_rviTarget[i];

  int iSearchCnt;
  cin >> iSearchCnt;

  a_rviSearch.resize(iSearchCnt);
  for (int i = 0; i < iSearchCnt; i++)
    cin >> a_rviSearch[i];
}

void fnLinearSearch(vector<int> &a_rviTarget, const vector<int> &a_cnrviSearch, int &a_riFound)
{
  size_t zMaxSize = a_rviTarget.size() - 1;
  for (size_t zi = 0; zi < a_cnrviSearch.size(); zi++)
  {
    a_rviTarget[zMaxSize] = a_cnrviSearch[zi];
    size_t zj = 0;
    while (a_rviTarget[zj] != a_cnrviSearch[zi])
      zj++;
    if (zj != zMaxSize)
      a_riFound++;
  }
}

void fnResultOut(int a_iFound)
{
  cout << a_iFound << endl;
}

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

  vector<int> viTarget, viSearch;
  int iFound = 0;

  fnInput(viTarget, viSearch);
  fnLinearSearch(viTarget, viSearch, iFound);
  fnResultOut(iFound);

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;

lint fac[MAX], finv[MAX], inv[MAX];

void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }

    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    }
  int main(){
      lint n;
      cin>>n;
      tuple<lint,lint,lint> a[n];
      tuple<lint,lint,lint>b[n];
      rep(i,n){
          lint a1,b1;
          cin>>a1>>b1;
          a[i]=make_tuple(b1+a1,a1,i);
          b[i]=make_tuple(a1+b1,b1,i);
      }
      bool iseat[n];
      fill(iseat,iseat+n,false);
      sort(a,a+n,greater<tuple<lint,lint,lint>>());
      sort(b,b+n,greater<tuple<lint,lint,lint>>());
      lint ans=0;
      lint i=0,j=0,k=0;
      while(1){
          lint s1,v1,c1;
          tie(s1,v1,c1)=a[i];
           while(iseat[c1]){
               i++;
                tie(s1,v1,c1)=a[i];
           }
           iseat[c1]=true;
           ans+=v1;
           k++;
           if(k==n)break;
            tie(s1,v1,c1)=b[j];
           while(iseat[c1]){
               j++;
                tie(s1,v1,c1)=b[j];
           }
           iseat[c1]=true;
           ans-=v1;
           k++;
           if(k==n)break;
           i++;j++;
      }
      cout<<ans<<endl;
  }


#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int N,Q;
  cin >> N >> Q;
  ll S[N],T[N],X[N];
  vector<ll> vect;
  vect.push_back(-Mod * 1000LL);
  vect.push_back(Mod * 1000LL);
  for (int i = 0; i < N; i++) {
    cin >> S[i] >> T[i] >> X[i];
    vect.push_back(S[i]-X[i]);
    vect.push_back(T[i]-X[i]);
  }
  sort(vect.begin(),vect.end());
  vector<ll> vec;
  for (int i = 1; i < (int)vect.size(); i++) {
    if (vect[i-1] != vect[i]) {
      vec.push_back(vect[i-1]);
    }
  }
  vec.push_back(Mod * 1000LL);
  int sz = vec.size();
  vector<ll> ans(sz);
  vector<ll> L[sz];
  vector<ll> R[sz];
  for (int i = 0; i < N; i++) {
    int l = lower_bound(vec.begin(),vec.end(),S[i]-X[i]) - vec.begin();
    int r = lower_bound(vec.begin(),vec.end(),T[i]-X[i]) - vec.begin();
    L[l].push_back(i);
    R[r].push_back(i);
  }
  multiset<ll> Set;
  for (int i = 0; i < sz; i++) {
    for (int j = 0; j < (int)L[i].size(); j++) {
      Set.insert(X[L[i][j]]);
    }
    for (int j = 0; j < (int)R[i].size(); j++) {
      auto itr = Set.lower_bound(X[R[i][j]]);
      Set.erase(itr);
    }
    if (Set.empty()) {
      ans[i] = -1;
    } else {
      auto itr = Set.begin();
      ans[i] = *itr;
    }
  }

  for (int i = 0; i < Q; i++) {
    ll D;
    cin >> D;
    int w = lower_bound(vec.begin(),vec.end(),D) - vec.begin();
    if (vec[w] != D) {
      w--;
    }
    cout << ans[w] << endl;
  }
  return 0;
}

#include <iostream>
#include <vector>
using namespace std;
const int V_MAX = 100000;

struct LowLink
{
	const vector<vector<int>> &g;
	int V;
	vector<vector<int>> dfs_tree;
	vector<int> dfs_roots;
	int pre_order[V_MAX];
	int p_ord = 0;
	int lowlink[V_MAX];
	bool articulation[V_MAX] = {};
	vector<pair<int, int>> bridge;

	LowLink(const vector<vector<int>> &g) : g(g), V(g.size()), dfs_tree(g.size()) {}

	void dfs(int v, int parent) {
		lowlink[v] = pre_order[v] = p_ord;
		p_ord++;
		for (int nv : g[v]) {
			if (nv == parent) continue;
			if (pre_order[nv] == -1) {
				dfs_tree[v].push_back(nv);
				dfs(nv, v);
				lowlink[v] = min(lowlink[v], lowlink[nv]);
			}
			lowlink[v] = min(lowlink[v], pre_order[nv]);
		}
	}

	void calc() {
		p_ord = 0;
		fill(pre_order, pre_order+V_MAX, -1);
		for (int i = 0; i < V; i++) {
			if (pre_order[i] != -1) continue;
			dfs_roots.push_back(i);
			dfs(i, -1);
		}
		for (int i = 0; i < V; i++) {
			for (int j : dfs_tree[i]) {
				if (pre_order[i] < lowlink[j]) bridge.push_back({i, j});
			}
		}
		for (int i = 0, x = 0; i < V; i++) {
			bool ok = false;
			if (x < dfs_roots.size() && dfs_roots[x] == i) {
				if (dfs_tree[i].size() > 1) ok = true;
				x++;
			} else {
				for (int j : dfs_tree[i]) {
					if (pre_order[i] <= lowlink[j]) ok = true;
				}
			}
			articulation[i] = ok;
		}
	}
};

int main() {
	int V, E;
	cin >> V >> E;
	vector<vector<int>> g(V);
	for (int i = 0; i < E; i++) {
		int a, b;
		cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	LowLink L(g);
	L.calc();
	for (int i = 0; i < V; i++) {
		if (L.articulation[i]) cout << i << endl;
	}
	return 0;
}


#include<iostream>
#include<iomanip>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#define ll long long
#define db double
#define inf 301
#define INF (int)1e8
#define mod (int)(1e9+7)
#define pi acos(-1)
#define rd(n) {n=0;char ch;int f=0;do{ch=getchar();if(ch=='-'){f=1;}}while(ch<'0'||ch>'9');while('0'<=ch&&ch<='9'){n=(n<<1)+(n<<3)+ch-48;ch=getchar();}if(f)n=-n;}
using namespace std;

const int lim=18;
ll P10[20],cnt[20];

void pre_work(void){
    P10[0]=1LL;
    for (int i=1;i<=lim;i++){
        P10[i]=P10[i-1]*10LL;
    }
    for (int i=0;i<=9;i++){
        for (int j=0;j<=9;j++){
            cnt[i-j+10]++;
        }
    }
    return;
}

ll D,ans=0;

void dfs(int step,ll x,ll sum,int len){
    if (step>len/2-1){
        if (len&1){
            sum*=10LL;
        }
        if (x==D){
            ans+=sum;
        }
        return;
    }
    ll now=-9;
    while (now<=9 && x+now*(P10[len-step-1]-P10[step])<=D){
        now++;
    }
    now--;
    dfs(step+1,x+now*(P10[len-step-1]-P10[step]),sum*(cnt[now+10]-(step==0 && now>=0)),len);
    now++;
    if (now>9){
        return;
    }
    dfs(step+1,x+now*(P10[len-step-1]-P10[step]),sum*(cnt[now+10]-(step==0 && now>=0)),len);
    return;
}

int main(){
    rd(D)
    pre_work();
    for (int i=1;i<=18;i++){
        dfs(0,0LL,1LL,i);
    }
    printf("%lld\n",ans);
    return 0;
}

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "}"; return os; }

LL solve(vector<LL>& a){
    LL res = 0;
    for(LL d = 60; d >= 0; --d){
        LL cur = -1;
        for(LL i = 0; i < a.size(); ++i){
            if(a[i] & (1LL<<d)) cur = i;
        }
        if(cur < 0) continue;
        if((res & (1LL<<d)) == 0){
            res ^= a[cur];
        }
        for(LL i = 0; i < a.size(); ++i){
            if(a[i] & (1LL<<d)) a[i] ^= a[cur];
        }
    }
    return res;
}

int main(){
    LL n;
    cin >> n;
    vector<LL> a(n);
    for(LL i = 0; i < n; ++i){
        cin >> a[i];
    }
    vector<LL> cnt(61);
    for(LL i = 0; i < n; ++i){
        for(LL j = 0; j < 61; ++j){
            if((a[i]>>j)&1) cnt[j] += 1;
        }
    }
    LL ans = 0;
    LL mask = 0;
    for(LL j = 0; j < 61; ++j){
        if(cnt[j] % 2 == 1){
            ans += (1LL << j);
        }else{
            mask |= (1LL << j);
        }
    }
    for(LL i = 0; i < n; ++i){
        a[i] = (a[i] & mask);
    }
    ans += solve(a) * 2;
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof (x))
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define fi first
#define se second
#define kill _z_kill
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define outval(x) cerr<<#x" = "<<x<<endl
#define outv(x) cerr<<#x" = "<<x<<"  "
#define outtag(x) cerr<<"--------------"#x"---------------"<<endl
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
	For(_x,L,R) cerr<<a[_x]<<" ";cerr<<endl;
#define User_Time ((double)clock()/CLOCKS_PER_SEC)
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned uint;
typedef long double LD;
typedef vector <int> vi;
typedef pair <int,int> pii;
LL read(){
	LL x=0,f=0;
	char ch=getchar();
	while (!isdigit(ch))
		f=ch=='-',ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
//int Pow(int x,int y){
//	int ans=1;
//	for (;y;y>>=1,x=(LL)x*x%mod)
//		if (y&1)
//			ans=(LL)ans*x%mod;
//	return ans;
//}
//void Add(int &x,int y){
//	if ((x+=y)>=mod)
//		x-=mod;
//}
//void Del(int &x,int y){
//	if ((x-=y)<0)
//		x+=mod;
//}
//int Add(int x){
//	return x>=mod?x-mod:x;
//}
//int Del(int x){
//	return x<0?x+mod:x;
//}
//void ckmax(int &x,int y){
//	if (x<y)
//		x=y;
//}
//void ckmin(int &x,int y){
//	if (x>y)
//		x=y;
//}
int main(){
	string s;
	cin>>s;
	if (s.size()&1)
		return puts("No"),0;
	For(i,0,(int)s.size()-1)
		if ("hi"[i%2]!=s[i])
			return puts("No"),0;
	puts("Yes");
	return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T>
using vec = std::vector<T>;

int main() {
    string S;
    cin >> S;
    if(S=="hi"||S=="hihi"||S=="hihihi"||S=="hihihihi"||S=="hihihihihi"){
        cout << "Yes" << endl;
    } else{
        cout << "No" << endl;
    }
}


#include <iostream>
#include <string>
using namespace std;
int main(){
      string s;
      while(getline(cin,s)||!cin.eof()){
            for(int i=0;i<25;i++){
                  if(s.find("the")!=-1||s.find("this")!=-1||s.find("that")!=-1)break;
                  else for(int j=0;j<s.size();j++)if(s[j]>='a'&&s[j]<='z')s[j]!='z'?s[j]++:s[j]='a';
            }
            cout<<s<<endl;
      }
}

#include<stdio.h>
#include<string.h>

int main(){
	char s[85];
	int i;
	memset(s,'0',sizeof(s));
	while(fgets(s,83,stdin)){

		while(1){
			for(i=0;i<81;i++){
				switch(s[i]){
				case '.':
				case ' ':
				case '0':
				case '\0':
				case 10:
				case 13:
					continue;
				}
				s[i]='a'+(s[i]-'a'+1)%26;
			}
			if((NULL!=strstr(s,"the")) || (NULL!=strstr(s,"this")) || (NULL!=strstr(s,"that"))){
				printf("%s",s);
				memset(s,'0',sizeof(s));
				break;
			}
		}
	}
	return 0;
}


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

using namespace std;
using ll = long long;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n+1);
    for(int i = 1; i < n+1; i++){
        cin >> a[i];
    }
    vector<int> b(n+1);
    for(int i = n; i >= 1; i--){
        int sum = 0;
        for(int j = i+i; j <= n; j += i){
            sum ^= b[j];
        }
        b[i] = sum^a[i];
    }
    vector<int> ans;
    for(int i = 1; i <= n; i++){
        if(b[i]) ans.push_back(i);
    }
    cout << ans.size() << endl;
    for(int i = 0; i < ans.size(); i++){
        cout << ans[i] << " ";
    }
    cout << endl;
    return 0;
}

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

using namespace std;

int main() {
  int N, M{};
  cin >> N;
  vector<int> a(N+1), b(N+1);

  for (int i = 1; i <= N; ++i) {
    cin >> a[i];
  }
  for (int i = N; i; --i) {
    int s{};
    for (int j = 2*i; j <=N; j += i) s += b[j];
    if (a[i] != s%2) {
      b[i] = 1;
      ++M;
    }
  }

  cout << M << endl;
  if (!M) return 0;
  for (int i = 1; i <= N; i++) {
    if (!b[i]) continue;
    cout << (M?"":" ") << i;
    M = 0;
  }
  cout << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

int main() {
    ll n, k;
    cin >> n >> k;
    cout << n - k + 1 << "\n";
    return 0;
}

#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
#define fs first
#define sc second

const int INF = 1e9;
const ll LLINF = 1e16;
const ll MOD = 1e9+7;
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}

// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;

int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int n,k;
    cin >> n >> k;
    print(n - k + 1);

}


#include<bits/stdc++.h>
using namespace std;
const int maxn=2005;
int T,n,m,a[maxn<<1][maxn<<1],now;
int b[maxn<<1][maxn<<1],c[maxn<<1][maxn<<1],d[maxn<<1][maxn<<1];
bool vis[maxn][maxn];
inline int read(){
    int res=0,f_f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f_f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') res=(res<<3)+(res<<1)-'0'+ch,ch=getchar();
    return res*f_f;
}
inline bool check(int ux,int uy,int fx,int fy){
    if(ux==fx&&uy==fy) return false;
    if(ux<1||ux>n||uy<1||uy>m) return false;
    if(vis[ux][uy]||a[ux][uy]==0) return false;
    return true;
}
inline void dfs(int ux,int uy,int fx,int fy){
    vis[ux][uy]=true;
    if(fx&&fy) b[ux+fx][uy+fy]=1;
    if(check(ux+1,uy,fx,fy)) dfs(ux+1,uy,ux,uy);
    if(check(ux-1,uy,fx,fy)) dfs(ux-1,uy,ux,uy);
    if(check(ux,uy+1,fx,fy)) dfs(ux,uy+1,ux,uy);
    if(check(ux,uy-1,fx,fy)) dfs(ux,uy-1,ux,uy);
}
int main(){
    n=read(),m=read(),T=read();
    for (int i=1;i<=n;i++){
        for (int j=1;j<=m;j++){
            char ch=getchar();
            while(ch!='0'&&ch!='1') ch=getchar();
            a[i][j]=ch-'0';
        }
    }
    for (int i=1;i<=n;i++){
        for (int j=1;j<=m;j++){
            if(a[i][j]==1){
                if(!vis[i][j]) dfs(i,j,0,0);
                c[i<<1][j<<1]=1;
            }
        }
    }
    for (int i=1;i<=(n<<1);i++){
        for (int j=1;j<=(m<<1);j++){
            b[i][j]+=b[i][j-1];
            c[i][j]+=c[i][j-1];
        }
    }
    for (int i=1;i<=(n<<1);i++){
        for (int j=1;j<=(m<<1);j++){
            b[i][j]+=b[i-1][j];
            c[i][j]+=c[i-1][j];
        }
    }
    while(T--){
        int fx=read(),fy=read(),tx=read(),ty=read(),ans=0;
        ans+=c[tx<<1][ty<<1]-c[tx<<1][(fy<<1)-1]-c[(fx<<1)-1][ty<<1]+c[(fx<<1)-1][(fy<<1)-1];
        ans-=b[tx<<1][ty<<1]-b[tx<<1][(fy<<1)-1]-b[(fx<<1)-1][ty<<1]+b[(fx<<1)-1][(fy<<1)-1];
        printf("%d\n",ans);
    }
    return 0;
}

#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <unordered_set>
#include <vector>
#include <list>
#include <string>
#include <iterator>
#include <deque>
#include <array>
#include <forward_list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <climits>
#include <bitset>
#include <numeric>
using namespace std;

const long double PI = 3.14159265358979323846264338327950;
const int N = 1e5+5;

template <class T>
T gcd(T a, T b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

int ac[N], wa[N];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n, m, k;
	int a, b;
	string s;
	cin >> n >> m;
	for (int i = 0; i < m; ++i) {
		cin >> k >> s;
		if (s[0] == 'W' && ac[k] == 0) {
			wa[k]++;
		} else {
			ac[k]++;
		}
	}

	a = b = 0;
	for (int i = 0; i <= n; ++i) {
		if (ac[i]) {
			++a;
			if (wa[i]) b += wa[i];
		}
	}

	cout << a << ' ' << b << '\n';
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<ll(n);i++)
int main() {
    int n;
    cin >> n;
    int a;
    ll ans = 0;
    int m = 2e9;
    int cnt = 0;
    rep(i, n){
        cin >> a;
        if (a < 0) {
            cnt++;
            a *= -1;
        }
        m = min(m, a);
        ans += a;
    }
    if (cnt%2 == 1) {
        ans -= 2*m;
    }
    cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1;} return 0;}
struct init{init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}}init_;

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    ll N;
    cin >> N;
    vl A(N);
    rep(i, N) cin >> A[i];

    vvc<ll> dp(N + 1, vl(2, -INF));
    dp[0][0] = 0;

    rep(i, N){
        dp[i + 1][0] = max(dp[i][0] + A[i], dp[i][1] - A[i]);
        dp[i + 1][1] = max(dp[i][0] - A[i], dp[i][1] + A[i]);
    }

    cout << dp[N][0] << endl;
}


//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<P> lr(n);
    rep(i, n) cin >> lr[i];

    sort(all(lr));
    int ans = 0;
    vi mil(n+1, INT_MAX), mir(n+1, INT_MAX);
    rep(i, n) {
        mil[i+1] = min(mil[i], lr[i].second);
        mir[n-1-i] = min(mir[n-i], lr[n-1-i].second);
    }

    int min = INT_MAX;
    rep(i, n-1) {
        chmin(min, lr[i].second);
        if(min < lr[i].first) break;
        chmax(ans, min-lr[i].first + mir[i+1]-lr[n-1].first + 2);
    }
    rep(i, n) {
        chmax(ans, lr[i].second - lr[i].first + 1 + (mil[n] >= lr[n-1].first?mil[n]-lr[n-1].first+1:0));
    }

    cout << ans << endl;
}

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

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

    vl L(n), R(n);
    ll p = 0, q = 0;  // L[p]はLの最大値で、R[q]はRの最小値
    ll MAXL = 0, MINR = INF;
    rep(i, n) {
        cin >> L[i] >> R[i];
        R[i]++;
        if(MAXL < L[i]) {
            MAXL = L[i];
            p = i;
        }
        if(MINR > R[i]) {
            MINR = R[i];
            q = i;
        }
    }

    ll ans = 0;
    // 区間pと区間qを同じ集合に入れる場合
    rep(i, n) {
        if(i == p || i == q) {
            continue;
        }
        chmax(ans, max(0LL, R[q] - L[p]) + R[i] - L[i]);
    }

    // 区間pと区間qを違う集合に入れる場合
    vector<pair<ll, ll>> c(n);
    rep(i, n) {
        ll a = max(0LL, R[i] - L[p]);
        ll b = max(0LL, R[q] - L[i]);
        c[i] = make_pair(a, -b);
    }
    sort(all(c));
    ll u = abs(c[0].second);
    exrep(i, 1, n-1) {
        chmax(ans, c[i].first + u);
        chmin(u, abs(c[i].second));
    }

    out(ans);
    re0;
}


#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <complex>
#include <random>
#include <bitset>
#include <list>
// #include <prettyprint.hpp>
using namespace std;
#define repi(i,n) for(int i=0;i<n;++i)
#define rep(i,n) for(ll i=0;i<n;++i)
#define repinvi(i,n) for(int i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define sii(n) scanf("%d", &n);
#define slf(n) scanf("%lf", &n);
#define pll pair<ll,ll>
#define pii pair<int,int>
#define psi pair<si,si>
typedef long long ll;
typedef double lf;
typedef short int si;

void Main(){
    ll N, x, y;
    string u;
    map<ll,map<string, set<ll>>> leftup_group;
    map<ll,map<string, set<ll>>> rightup_group;
    map<ll,map<string, set<ll>>> updown_group;
    map<ll,map<string, set<ll>>> lr_group;
    sll(N);
    rep(i, N){
        sll(x);
        sll(y);
        cin >> u;
        leftup_group[x+y][u].insert(x);
        rightup_group[x-y][u].insert(x);
        if(u=="U" || u == "D"){
            updown_group[x][u].insert(y);
        }else if(u=="R" || u == "L"){
            lr_group[y][u].insert(x);
        }
    }
    // x + y -> u & r ^ u_x >= r_x , d & l ^ d_x <= l_x
    // x - y -> u & l ^ u_x <= l_x , d & r ^ d_x >= r_x
    ll min_v = 1e15;
    for(auto& p:leftup_group){
        auto each_g = p.second;
        for(auto c:each_g["R"]){
            auto iter = each_g["U"].upper_bound(c);
            if(iter != each_g["U"].end()){
                // cout << "x+y, R & U, R_x="<<c << " U_x="<<*iter<<endl;
                ll v = *iter;
                min_v = min((v-c)*10, min_v);
            }
        }

        for(auto c:each_g["D"]){
            auto iter = each_g["L"].upper_bound(c);
            if(iter != each_g["L"].end()){
                // cout << "x+y, L & D, L_x="<<c << " D_x="<<*iter<<endl;
                ll v = *iter;
                min_v = min((v-c)*10, min_v);
            }
        }
    }

    for(auto& p:rightup_group){
        auto each_g = p.second;
        for(auto c:each_g["U"]){
            auto iter = each_g["L"].upper_bound(c);
            if(iter != each_g["L"].end()){
                // cout << "x-y, U & L, U_x="<<c << " L_x="<<*iter<<endl;
                ll v = *iter;
                min_v = min((v-c)*10, min_v);
            }
        }

        for(auto c:each_g["R"]){
            auto iter = each_g["D"].upper_bound(c);
            if(iter != each_g["D"].end()){
                // cout << "x+y, R & D, R_x="<<c << " D_x="<<*iter<<endl;
                ll v = *iter;
                min_v = min((v-c)*10, min_v);
            }
        }
    }

    for(auto& p:updown_group){
        auto each_g = p.second;
        for(auto c:each_g["U"]){
            auto iter = each_g["D"].upper_bound(c);
            if(iter != each_g["D"].end()){
                ll v = *iter;
                min_v = min((v-c)*5, min_v);
            }
        }
    }

    for(auto& p:lr_group){
        auto each_g = p.second;
        for(auto c:each_g["R"]){
            auto iter = each_g["L"].upper_bound(c);
            if(iter != each_g["L"].end()){
                ll v = *iter;
                min_v = min((v-c)*5, min_v);
            }
        }
    }

    if(min_v == 1e15){
        cout << "SAFE" <<endl;
    }else{
        cout << min_v <<endl;
    }

}

int main(){
    Main();
    // string S = "ksdfjl";
    // char v = S[3];
    // S[3] = 'a';
    // cout << S <<endl;
}

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1e8;

int cal(vector<P> A) {
  sort(A.begin(), A.end());
  int res = INF;
  for (int i = 1; i < sz(A); i++) {
    if (A[i-1].second == 0 && A[i].second != 0) {
      res = min(res, A[i].first - A[i-1].first);
    }
  }
  return res;
}

int F(map<int, vector<P>>& mp) {
  int res = INF;
  for (auto p : mp) {
    res = min(res, cal(p.second));
  }
  return res;
}

int main() {
  int N;
  cin >> N;
  vector<int> X(N), Y(N), dir(N);
  // URDL → 0123
  rep(i, N) {
    char c;
    cin >> X[i] >> Y[i] >> c;
    if (c == 'U') dir[i] = 0;
    if (c == 'R') dir[i] = 1;
    if (c == 'D') dir[i] = 2;
    if (c == 'L') dir[i] = 3;
  }
  int ans = INF;
  rep(_, 4) {
    { // UD
      map<int, vector<P>> mp;
      rep(i, N) {
        if (dir[i] != 0 && dir[i] != 2) continue;
        mp[X[i]].emplace_back(Y[i], dir[i]);
      }
      ans = min(ans, F(mp));
    }
    { // UR
      map<int, vector<P>> mp;
      rep(i, N) {
        if (dir[i] != 0 && dir[i] != 1) continue;
        mp[X[i]+Y[i]].emplace_back(Y[i], dir[i]);
      }
      ans = min(ans, F(mp) * 2);
    }
    {
      // rotate clockwise
      rep(i, N) {
        int px = X[i], py = Y[i];
        X[i] = py;
        Y[i] = -px;
        dir[i] = (dir[i]+1)%4;
      }
    }
  }
  if (ans < INF) cout << ans * 5 << '\n';
  else puts("SAFE");
  return 0;
}


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

int n, s, x, p;
deque<pair<int, long long> > d;

long long amx(int a) {
	if(s >= d.back().first) {
		return s - d.front().first;
	} else if(s <= d.front().first) {
		return d.back().first - s;
	}
	int na;
	long long D = d.back().first - d.front().first;
	if(d.front().second >= d.back().second) {
		pair<int, long long> t = d.front();
		t.second += d.back().second;
		d.pop_back();
		d.pop_front();
		d.push_front(t);
		na = 0;
	} else {
		pair<int, long long> t = d.back();
		t.second += d.front().second;
		d.pop_front();
		d.pop_back();
		d.push_back(t);
		na = 1;
	}
	return amx(na) + (long long)(a != na) * D;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> s;
	for(int i = 1; i <= n; ++i) {
		cin >> x >> p;
		d.push_back({x, p});
	}
	cout << amx(2) << endl;
	return 0;
}

#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	int N, M;
	cin >> N >> M;
	vector<vector<int>> a(N, vector<int>(M));
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < M; ++j) {
			cin >> a[i][j]; --a[i][j];
		}
	}

	int ans = -1;
	for (int n = 1; n <= N; ++n) {
		vector<bool> sports(M, true);
		vector<int> join(N, 0);
		while (true) {
			bool ok = true;
			vector<int> cnt(M, 0);
			for (int i = 0; i < N; ++i) {
				while (join[i] <= M) {
					if (join[i] == M) {
						ok = false;
						break;
					}
					if (sports[ a[i][join[i]] ]) {
						++cnt[ a[i][join[i]] ];
						break;
					}
					++join[i];
				}
			}
			if (!ok) { break; }
			for (int i = 0; i < M; ++i) {
				if (cnt[i] > n) {
					ok = false;
					sports[i] = false;
				}
			}
			if (ok) {
				ans = n;
				break;
			}
		}
		if (ans > 0) { break; }
	}
	cout << ans << endl;

	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <iomanip>

using namespace std;

long long mod = 1000000007;

long long pow(long long x, long long k)
{
    if (k == 0)
    {
        return 1LL;
    }
    long long temp = pow(x, k / 2);
    if (k % 2 == 1)
    {
        return (((temp * temp) % mod) * x) % mod;
    }
    else
    {
        return (temp * temp) % mod;
    }
}

long long modular_inverse(long long x)
{
    return pow(x, mod - 2);
}

long long binomial(long long n, long long k)
{
    long long rez = 1;
    for (int i = n - k + 1; i <= n; i++)
    {
        rez *= i;
        rez %= mod;
    }
    long long temp = 1;
    for (int i = 1; i <= k; i++)
    {
        temp *= i;
        temp %= mod;
    }
    rez *= modular_inverse(temp);
    rez %= mod;
    return rez;
}

int score(int x)
{
    return max(100000 * (4 - x), 0);
}

int main()
{
    int x, y;
    cin >> x >> y;
    cout << score(x) + score(y) + ((x == y && x == 1) ? 400000 : 0);
    return 0;
}


#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;

typedef long long ll;

const int N = 401;
const vector<int> dx = {0, 0, 1, -1};
const vector<int> dy = {1, -1, 0, 0};

int used[N * N];
vector<int> g[N * N];

int n, m;
int a[N][N];

int get(int i, int j) {
	return i * m + j;
}

int ok(int i, int j) {
	return 0 <= i & i < n && 0 <= j && j < m;
}

void dfs(int cur, int &c0, int &c1) {
	used[cur] = 1;
	if (a[cur / m][cur % m] == 0) {
		c0++;
	} else {
		c1++;
	}
	for (auto t : g[cur]) {
		if (!used[t]) {
			dfs(t, c0, c1);
		}
	}
}

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

	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			char c;
			cin >> c;
			a[i][j] = (c == '#');
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			for (int f = 0; f < 4; f++) {
				int i1 = i + dx[f];
				int j1 = j + dy[f];
				if (ok(i1, j1) && a[i][j] != a[i1][j1]) {
					g[get(i, j)].push_back(get(i1, j1));
				}
			}
		}
	}
	ll ans = 0;
	for (int i = 0; i < n * m; i++) {
		if (!used[i]) {
			int c0 = 0;
			int c1 = 0;
			dfs(i, c0, c1);
			ans += c0 * c1;
		}
	}
	cout << ans << '\n';
}

#include <cstdio>
#include <cstring>
#include <algorithm>

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

using namespace std;

int n, m;
char s[1001];
char t[1001];
int dp[1001][1001];

int main(){
	scanf("%s%s", s, t);
	n = strlen(s);
	m = strlen(t);

	rep(i, n + 1){
		dp[i][0] = i;
	}
	rep(i, m + 1){
		dp[0][i] = i;
	}
	for(int i = 1; i <= n; ++i){
		for(int j = 1; j <= m ; ++j){
			dp[i][j] = min(dp[i - 1][j - 1] + (s[i - 1] != t[j - 1]), min(dp[i][j - 1], dp[i - 1][j]) + 1);
		}
	}
	printf("%d\n", dp[n][m]);
	return 0;
}


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

using namespace std;

struct data_t {
	string name;
	double eff;

	bool operator<(const data_t& right) const {
		if (eff == right.eff) {
			return (name < right.name);
		}
		else {
			return (eff > right.eff);
		}
	}
};

int main(void) {
	int N;
	while (cin >> N, N) {
		vector<data_t> data(N);
		int p,temp,d,e,f,m,s;
		for (int i = 0; i < N; ++i) {
			cin >> data[i].name;
			cin >> p;
			int time = 0;
			for (int i = 'A'; i <= 'C'; ++i) {
				cin >> temp;
				time += temp;
			}
			cin >> d >> e >> f >> s >> m;
			time += m * (d + e);
			data[i].eff = (double)((f * m * s) - p)/(double)time;
		}

		sort(data.begin(),data.end());

		for (int i = 0; i < N; ++i) {
			cout << data[i].name << endl;
		}
		cout << "#" << endl;
	}
	return 0;
}

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

struct f {
    string l;
    int  p, a, b, c, d, e, f, s, m;
    double rate;
    void input() {
        cin >> l >> p >> a >> b >> c >> d >> e >> f >> s >> m;
    }
    void calc() {
        double k = 0;
        rep(i, m) {
            if (i == 0) k += a+b+c+d+e;
            else k += d+e;
        }
        double kk = (f*m*s)-p;
        rate = kk/k;
    }
    void print() {
        cout << l << endl;
    }
};

int main() {
    int n;
    int count = 0;
    while (cin >> n) {
        if (n == 0) break;
        vector<f> a(n);
        rep(i, n) {
            a[i].input();
            a[i].calc();
        }
        sort(a.begin(), a.end(), [](const f& a, const f& b) {
            if (a.rate == b.rate) {
                return a.l < b.l;
            }
            return a.rate > b.rate;
        });
        rep(i, n) {
            a[i].print();
        }
        cout << "#" << endl;
    }
    return 0;
}


#include<stdio.h>
int main()
{
	char S[110];
	char T[110];

	scanf("%s%s", S, T);
	printf("%s%s", T, S);
return 0;
}

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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

int main() {
    int a, b;
    cin >> a >> b;
    cout << (a * b) << endl;

    return 0;
}


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

using namespace std;

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<int(n);i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using Pint = pair<int,int>;
const ll mod = 1e9+7;

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

  cout<<t<<s<<endl;

  return 0;
}

#include <stdio.h>

int main(){
	int s[100];
	int t[100];
	scanf ("%s %s",s,t);
	printf("%s%s\n",t,s);

	return 0;
}


#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 2000005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

ll n,x,a[maxn],F;

int main()
{
	n=read(); x=read(); rep(i,1,n) a[i]=read(); sort(a+1,a+n+1);
	ll tmp=0;
	rep(i,1,n)
	{
		tmp+=a[i];
		if(tmp==x) {F=1; cout<<i<<endl; break;}
		else if(tmp>x) {F=1; cout<<i-1<<endl; break;}
	}
	if(!F) cout<<n-1<<endl;
	return 0;
}

#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int dy[4]={1,0,-1,0};
int dx[4]={0,1,0,-1};
vector<vector<int>> graph;

bool sort_sec(const pair<int,int> &a,const pair<int,int> &b){
   if(a.second<b.second){
      return true;
   }
   return false;
}

void swap(int *a,int *b){
   int temp=*a;
   *a=*b;
   *b=temp;
}

int gcd(int a,int b){
   if(a%b==0) return b;
   return gcd(b,a%b);
}
int digit(int num){
   int cnt=0;
   while(num!=0){
      cnt+=num%10;
      num=num/10;
   }
   return cnt;
}
int main(void){
   int N;
   cin>>N;
   long long x;
   cin>>x;
   vector<long long> a(N);
   vector<long long> result(N);
   for(int i=0;i<N;i++){
      cin>>a[i];
   }
   sort(a.begin(),a.end());
   for(int i=0;i<N;i++){
      result[i]=min(x,a[i]);
      x-=result[i];
   }
   result[N-1]+=x;
   int ans=0;
   for(int i=0;i<N;i++){
      if(result[i]==a[i]) ans++;
   }
   cout<<ans<<endl;
   return 0;
}


#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b, c;
  while(cin>>a>>b>>c,a||b||c) {
    int N; cin >> N;
    int info_[4][N];
    FOR(i,0,N) FOR(j,0,4) cin >> info_[j][i];
    int info[a+b+c+1];
    FOR(i,0,a+b+c+1) info[i] = 2;
    // ???????????????????????¨?????????
    FOR(i,0,N) if(info_[3][i] == 1) FOR(j,0,3) info[info_[j][i]] = 1;

    // ?????????????????¨?????????
    FOR(i,0,N) {
      if(info_[3][i] == 0) {
        int cnt = 0;
        FOR(j,0,3) cnt += info[info_[j][i]];
        if(cnt == 4) {
          FOR(j,0,3) if(info[info_[j][i]] == 2) info[info_[j][i]] = 1000;
        }
      }
    }
    FOR(i,1,a+b+c+1) cout << (info[i] == 1000 ? 0 : info[i]) << '\n';
  }
  return 0;
}

#include<iostream>

using namespace std;

struct ST{
	int a;
	int b;
	int c;

	int an;
};

int reset(int, int */*[100 + 10]*/);

int main()
{
	int ans[1000 + 10];

	ST res[1000 + 10];

	int an, bn, cn, n;

	int ml;

	int ln;

	int i, j;
	int af, bf, cf;

	while (cin >> an >> bn >> cn, an != 0 && bn != 0 && cn != 0)
	{
		cin >> n;

		ln = n;

		ml = an + bn + cn;

		reset(ml, ans);

		for (i = 1; i <= ln; i++)
		{
			cin >> res[i].a >> res[i].b >> res[i].c >> res[i].an;

			if (res[i].an == 1)
			{
				ans[res[i].a] = 1;
				ans[res[i].b] = 1;
				ans[res[i].c] = 1;

				i--;
				ln--;
			}
		}

		for (i = 1; i <= ln; i++)
		{
			af = bf = cf = 0;

			if (ans[res[i].a] == 1) af = 1;
			if (ans[res[i].b] == 1) bf = 1;
			if (ans[res[i].c] == 1) cf = 1;

			if (af + bf + cf == 2)
			{
				if (af == 0)
				{
					ans[res[i].a] = 0;
				}
				if (bf == 0)
				{
					ans[res[i].b] = 0;
				}
				if (cf == 0)
				{
					ans[res[i].c] = 0;
				}
			}
		}

		for (i = 1; i <= ml; i++)
		{
			cout << ans[i] << endl;
		}
	}

	return 0;
}

int reset(int n,int *le)
{
	int i;
	for (i = 0; i < n; i++)
	{
		le[i] = 2;
	}
	return 0;
}


#include <iostream>
using namespace std;

int main(){
  int day30[4] = {4,6,9,11};

  while(1) {
  int m,d;
  cin >> m >> d;
  if(m == 0 && d == 0) break;
  int a = 1,b = 1,count = 0;

  while(1) {

    if(a == m && b == d) break;

    b++;
    count++;

    if(a == 2 && b == 30) {
      a++;
      b = 1;
    }
    else if(b == 31) {
      for(int i=0;i<4;i++)
	if(day30[i] == a) {
	  a++;
	  b = 1;
	  break;
	}
    }
    if( b == 32) {
      a++;
      b = 1;
    }
  }

  if(count % 7 == 4 ) cout <<"Monday"<<endl;
  else if(count % 7 == 5) cout << "Tuesday"<<endl;
  else if(count % 7 == 6) cout <<"Wednesday"<< endl;
  else if(count % 7 == 0) cout <<"Thursday"<< endl;
  else if(count % 7 ==1) cout << "Friday" << endl;
  else if(count % 7 ==2)cout << "Saturday" << endl;
  else if(count % 7 ==3) cout << "Sunday" << endl;

  }

  return 0;
}

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

int main(){
  vector<int> hand(5);
  char c;

  while(cin >> hand[0]>>c>>hand[1]>>c>>hand[2]>>c>>hand[3]>>c>>hand[4]){
    vector<int> cnt(15, 0);
    for(int i=0; i<5; i++){
      cnt[hand[i]]++;
      if(hand[i] == 1) cnt[14]++;
    }
    bool flag = false;

    // four card
    for(int i=1; i<=13; i++){
      if(cnt[i] == 4){
        cout << "four card" << endl; flag = true;
      }
    }
    if(flag) continue;

    // three card or full house
    for(int i=1; i<=13; i++){
      if(cnt[i] == 3){
        for(int j=1; j<=13; j++){
          if(cnt[j] == 2){
            cout << "full house" << endl; flag = true;
          }
        }
        if(flag) break;
        cout << "three card" << endl; flag = true;
      }
    }
    if(flag) continue;

    // two pair or one pair
    for(int i=1; i<=13; i++){
      if(cnt[i] == 2){
        for(int j=i+1; j<=13; j++){
          if(cnt[j] == 2){
            cout << "two pair" << endl; flag = true;
          }
        }
        if(flag) break;
        cout << "one pair" << endl; flag = true;
      }
    }
    if(flag) continue;

    // straight
    for(int i=1; i<=13; i++){
      if(cnt[i] == 1 && cnt[i+1] == 1 && cnt[i+2] == 1 && cnt[i+3] == 1 && cnt[i+4] == 1){
        cout << "straight" << endl; flag = true;
      }
    }
    if(flag) continue;

    //null
    cout << "null" << endl;
  }

}