#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<sstream>
#include<stack>
#include<string>
#include<set>
#include<vector>
using namespace std;
#define PI acos(-1.0)
#define pppp cout<<endl;
#define EPS 1e-8
#define LL long long
#define ULL unsigned long long     //1844674407370955161
#define INT_INF 0x3f3f3f3f      //1061109567
#define LL_INF 0x3f3f3f3f3f3f3f3f //4557430888798830399
// ios::sync_with_stdio(false);
// 那么cin, 就不能跟C的 scanf，sscanf, getchar, fgets之类的一起使用了。
const int dr[]= {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[]= {-1, 1, 0, 0, -1, 1, -1, 1};
int read()//输入外挂
{
    int ret=0, flag=0;
    char ch;
    if((ch=getchar())=='-')
        flag=1;
    else if(ch>='0'&&ch<='9')
        ret = ch - '0';
    while((ch=getchar())>='0'&&ch<='9')
        ret=ret*10+(ch-'0');
    return flag ? -ret : ret;
}
const int maxn=100005;
LL dist[maxn];
bool vis[maxn];
int head[maxn];
int tot,n;
int fa[maxn];

struct node
{
    int from,to;
    LL w;
    int next;
} edge[maxn*4];
struct Point
{
    int id;
    int x,y;

} p[maxn];

void add(int u,int v,LL w)
{
    edge[tot].from=u;
    edge[tot].to=v;
    edge[tot].w=w;
    edge[tot].next=head[u];
    head[u]=tot++;
}
int Find(int x)
{
    if(x==fa[x])
        return x;
    else
        return fa[x]=Find(fa[x]);
}
bool cmp1(Point a,Point b)
{
    return a.x<b.x;
}
bool cmp2(Point a,Point b)
{
    return a.y<b.y;
}
bool cmp3(node a,node b)
{
    return a.w<b.w;
}
int main()
{
    memset(head,-1,sizeof(head));
    for(int i=1; i<=maxn; i++)
        fa[i]=i;

    scanf("%d",&n);

    for(int i=1; i<=n; i++)
    {
        scanf("%d%d",&p[i].x,&p[i].y);
        p[i].id=i;
    }

    sort(p+1,p+n+1,cmp1);
    for(int i=2; i<=n; i++)
        add(p[i-1].id,p[i].id,p[i].x-p[i-1].x);

    sort(p+1,p+n+1,cmp2);
    for(int i=2; i<=n; i++)
        add(p[i-1].id,p[i].id,p[i].y-p[i-1].y);

    sort(edge,edge+tot,cmp3);
    int cnt=0;
    LL ans=0;
    for(int i=0; i<tot; i++)
    {
        int fu=Find(edge[i].from);
        int fv=Find(edge[i].to);
        if(fu!=fv)
        {
            fa[fu]=fv;
            cnt++;
            ans+=edge[i].w;
            if(cnt==n-1)
                break;
        }
    }
    printf("%lld\n",ans);
    return 0;

}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7,INF=mod*mod*3;//M_PI
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)
#define pb push_back

ll N;
ll u,v;
ll ans;
vector<ll> vec[100005];
ll parent[100005];
bool leaf[100005]; //falseなら葉
void tree(ll par,ll n){
    if(parent[n]!=0)  return;
    parent[n]=par;
    for(auto &i:vec[n]) tree(n,i);
    return;
}
ll Adis[100005];
ll Tdis[100005];
void Adfs(ll n,ll dis){
    if(Adis[n]!=-1) return;
    Adis[n]=dis;
    for(auto&i:vec[n]) Adfs(i,dis+1);
    return;
}
void Tdfs(ll n,ll dis){
    if(Tdis[n]!=-1) return;
    Tdis[n]=dis;
    for(auto&i:vec[n]) Tdfs(i,dis+1);
    return;
}
int main(){

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

cin>>N>>u>>v;
rep(i,N-1){
    ll a,b;
    cin>>a>>b;
    vec[a].pb(b);
    vec[b].pb(a);
}
tree(-1,v);
rep1(i,N+1){
    ll n=parent[i];
    if(n!=-1) leaf[n]=true;
}
fill(Adis+1,Adis+N+1,-1);
fill(Tdis+1,Tdis+N+1,-1);
Adfs(v,0);
Tdfs(u,0);
rep1(i,N+1){
    if(!leaf[i]){
        if(Tdis[i]<Adis[i]) ans=max(ans,Adis[i]);
    }
}
cout<<ans-1<<endl;

}


#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<iomanip>
#include<complex>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef stack<int> SI;
typedef queue<int> QI;
typedef list<int> LI;
typedef pair<int,int> PII;
typedef long long LL;

#define d(x)  cout<<#x<<" = "<<(x)<<endl;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define EMP empty()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define REACH(i,c) for(typeof((c).rbegin()) i=(c).rbegin(); i!=(c).rend(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c,n) sort(c,c+n)
#define VSORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define DFOR(i,b,a) for(int i=(b)-1;i>=(a);--i)
#define DREP(i,n) DFOR(i,n,0)
#define INF 1000000000
#define PI  acos(-1.0)
////////////////////////////////////////////////
#define N 8
int row[N],col[N],dpos[N*2-1],dneg[N*2-1];
bool X[N][N];

void print()
{
	REP(i,N)
	{
		REP(j,N)
		{
			if(X[i][j])
			{
				if(row[i]!=j)return ;
			}
		}
	}
	REP(i,N)
	{
		REP(j,N)
		{
			cout<<((row[i]==j)?"Q":".");
		}
		cout<<endl;
	}
}

void recursive(int i)
{
	if(i==N)
	{
		print();
		return;
	}

	REP(j,N)
	{
		if(col[j]+dpos[i+j]+dneg[i-j+N-1]!=0)continue;
		row[i]=j;col[j]|=1;dpos[i+j]|=1;dneg[i-j+N-1]|=1;
		recursive(i+1);
		row[i]^=row[i];col[j]^=col[j];dpos[i+j]^=dpos[i+j];dneg[i-j+N-1]^=dneg[i-j+N-1];
	}
}
int main()
{
	int k;
	scanf("%d",&k);
	REP(i,k)
	{
		int r,c;
		scanf("%d%d",&r,&c);
		X[r][c]=true;
	}
	recursive(0);
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<int,int>
#define poly vector<ll>
#define mem(a) memset((a),0,sizeof(a))
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define fi first
#define se second
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=305;
int n,a[N<<1][N<<1];
void hf(int x,int de){
	int t=0;
	while(x%4==0){x/=4; t++;}
	if(x%4==2){
		For(i,0,2*n-1){
			For(j,0,2*n-1)if(i>>t&1)a[i][j]|=de;
		}
	}else {
		For(i,0,2*n-1){
			For(j,0,2*n-1)if(((i>>t)+(j>>t))&1)a[i][j]|=de;
		}
	}
}
vector<PI> v[4];
int main(){
	n=read(); int d1=read(),d2=read();
	hf(d1,1);
	hf(d2,2);
	For(i,0,2*n-1)For(j,0,2*n-1)v[a[i][j]].pb(mp(i,j));
	For(i,0,3)if(v[i].size()>=n*n){
		For(j,0,n*n-1)wri(v[i][j].fi),writeln(v[i][j].se); return 0;
	}
}


#include <iostream>

#define Free (-1)
#define NonFree (-2)
#define NoQ (-3)
using namespace std;
const int N = 8;
int row[N];
int col[N];
int dpos[15];
int dneg[15];

int inits[N];

void printBoard() {
    for (int r = 0; r < N; ++r) {
        for (int c = 0; c < N; ++c) {
            if (row[r] != c) {
                cout << ".";
            } else {
                cout << "Q";
            }
        }
        cout << endl;
    }
};

void putQueen(int i) {
    int j;
    if (i == N) {
        printBoard();
        return;
    }
    if (inits[i] == Free) {
        for (j = 0; j < N; ++j) {
            if (col[j] == NonFree ||
                dpos[i + j] == NonFree ||
                dneg[i - j + N - 1] == NonFree) {
                continue;
            }
            row[i] = j;
            col[j] = dpos[i + j] = dneg[i - j + N - 1] = NonFree;
            putQueen(i + 1);
            row[i] = NoQ;
            col[j] = dpos[i + j] = dneg[i - j + N - 1] = Free;
        }
    }else{
        putQueen(i + 1);
    }
};
void DeskSetup(int r, int c) {  // Basic
    row[r] = c;
    col[c] = dpos[r + c] = dneg[r - c + N - 1] = NonFree;
}

void InitDesk() { // Basic
    for (int j = 0; j < N; ++j) {
        row[j] = NoQ;
        col[j] = inits[j] = Free;
    }
    for (int j = 0; j < 15; ++j) {
        dpos[j] = dneg[j] = Free;
    }

};

int main() {
    int r, c, i;
    InitDesk();
    cin >> i;
    for (int k = 0; k < i; ++k) {
        cin >> r >> c;
        DeskSetup(r, c);
        inits[r] = NonFree;
    }
    putQueen(0);
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
ll mod=1e9+7;

int main() {
  ll m;
  cin >> m;
  ll n=0;
  ll d=0;
  for(ll i=0;i<m;i++) {
    ll tc,td;
    cin >> td >> tc;
    n+=tc;
    d+=td*tc;
  }
  cout << n-1+(d-1)/9 << endl;
}


#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <stdlib.h>
#include <vector>
#include <stack>

using namespace std;

int main(){

	int n, p;

	while(1){
		cin >> n;
		cin >> p;
		if(n ==0 && p==0) break;

		int sum[n];
		int win=p;
		int winner;
		int flag = 0;

		for(int i=0 ; i<n ; i++){
			sum[i] = 0;
		}

		while(1){
			for(int i=0 ; i<n ; i++){
				if(p>0){
					sum[i]++;
					p--;
					if(sum[i]==win){
						flag = 1;
						winner = i;
						break;
					}
				}else{
					p = sum[i];
					sum[i] = 0;
				}
			}

			if(flag == 1) break;
		}

		cout << winner << endl;
	}
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

int main(void) {
    ll N, A, B;
    cin >> N;
    if(N == 1) {
        cout << "Hello World" << endl;
    } else {
        cin >> A >> B;
        cout << A + B << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
struct Graph{
  Graph(int n):E(n),d(n){}
  vector<vector<tuple<int,int,int>>>E;
  vector<int>d;
  void add_edge(int a,int b,int c,int d){
    E[a].push_back(make_tuple(b,c,d));
  }
  void dijkstra(int s,int f){
    priority_queue<P,vector<P>,greater<P>>q;
    fill(d.begin(),d.end(),1e9);
    q.push({d[s]=0,s});
    while(q.size()){
      auto p=q.top();q.pop();
      if(p.first>d[p.second])continue;
      for(auto& a:E[p.second]){
        int x=get<0>(a),y=get<1>(a)+p.first;
        if(f)y=get<2>(a)+p.first;
        if(y<d[x])d[x]=y,q.push({y,x});
      }
    }
  }
};
main(){
  int n,m,a,b,c,d,k;
  while(cin>>n>>m,n){
    Graph E(m);
    for(int i=0;i++<n;E.add_edge(--a,--b,c,d),E.add_edge(b,a,c,d))cin>>a>>b>>c>>d;
    cin>>k;
    for(int i=0;i++<k;cout<<E.d[--b]<<endl){
      cin>>a>>b>>c;
      E.dijkstra(--a,c);
    }
  }
}

#include<iostream>
#include<algorithm>
using namespace std;
#define MAX 1000000
int main(){
	int n, m, a, b, cost, ti, k, p, q, r, point = 0;
	int cost_[101][101], time_[101][101];
	while ( cin >> n >> m && (n != 0 && m != 0)){
		for (int i = 0; i < m; i++)
		for (int j = 0; j < m; j++) { cost_[i][j] = time_[i][j] = MAX; }
		for (int i = 0; i < n; i++){
			cin >> a >> b >> cost >> ti;
			cost_[a-1][b-1] = cost;
			cost_[b-1][a-1] = cost;
			time_[a-1][b-1] = ti;
			time_[b-1][a-1] = ti;
		}
		for (int i = 0; i < m; i++){
			for (int j = 0; j < m; j++){
				for (int o = 0; o < m; o++){
						cost_[j][o] = min(cost_[j][o], cost_[j][i] + cost_[i][o]);
						time_[j][o] = min(time_[j][o], time_[j][i] + time_[i][o]);
				}
			}
		}cin >> k;
		for (int i = 0; i < k; i++){
			cin >> p >> q >> r;
			if (r != 1) cout << cost_[p-1][q-1] << endl;
			else cout << time_[p-1][q-1] << endl;
		}
	}
	return 0;
}


#include<stdio.h>
#include<string.h>
int main(void) {
	int a[10000],n,b=0,i,x,d=3;
	char r[10000];
	char s[10000];
	scanf("%d", &n);
	sprintf(s, "%d", d);
	for(i = 1; i <= n; i++) {
		sprintf(r,"%d", i);
		if (i % 3 == 0) {
			a[b] = i;
			b++;
		}
		else if (strstr(r,s) != NULL) {
			a[b] = i;
			b++;
	}

	}
	for (x = 0; x < b; x++) {
		if (x == 0) {
			printf(" ");
	}
		printf("%d",a[x]);
		if (x == b - 1) {
			printf("\n");
		}
		else {
			printf(" ");
		}
	}
	return 0;
}

#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;

void call(int n) {
	int i = 1;
	int x;
	bool flg = false;
	while (1) {
		// CHECK_NUM
		x = i;
		if ( x % 3 == 0 ){
			cout << " " << i;
		}
		else {
			while (1) {
				// INCLUDE3
				if ( x % 10 == 3 ){
					cout << " " << i;
					flg = true;
				}
				else {
					x /= 10;
					if ( x ) {
						continue;
					}
					else {
						flg = true;
					}
				}
				if (flg == true) {
					break;
				}
			}
		}
		flg = false;
		// END_CHECK_NUM
		if ( ++i <= n ) {
			continue;
		}
		else {
			cout << endl;
			break;
		}
	}
}

int main(void)
{
	int n;
	cin >> n;
	call(n);
	return 0;
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  int A, B; cin >> A >> B;
  vector<string> C(100);
  for (int i = 0; i < 50; ++i) {
    C[i] = string(100, '.'); // White
  }
  for (int i = 50; i < 100; ++i) {
    C[i] = string(100, '#'); // Black
  }

  --A, --B;

  for (int i = 0; i < 50 && B > 0; i += 2) {
    for (int j = 0; j < 100 && B > 0; j += 2) {
      C[i][j] = '#'; --B;
    }
  }
  for (int i = 99; i > 50 && A > 0; i -= 2) {
    for (int j = 0; j < 100 && A > 0; j += 2) {
      C[i][j] = '.'; --A;
    }
  }

  cout << 100 << " " << 100 << endl;
  for (auto s : C) cout << s << endl;
}

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

using namespace std;

int main(void) {
    int A, B;
    cin >> A >> B;
    cout << 100 << " " << 100 << endl;
    vector< vector<int> > grad(100, vector<int>(100));
    for(int i=0; i<50; i+=2) {
        for(int j=0; j<100; j+=2) {
            if(A > 1) {
                grad[i][j] = 1;
                --A;
            }
        }
    }
    for(int i=50; i<100; i++) {
        for(int j=0; j<100; j++) {
            grad[i][j] = 1;
            if(B > 1 && i>50 && i%2 == 1 && j%2) {
                grad[i][j] = 0;
                --B;
            }
        }
    }
    for(int i=0; i<100; i++) {
        for(int j=0; j<100; j++) {
            if(grad[i][j]) {
                cout << '.';
            } else {
                cout << '#';
            }
        }
        cout << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define ld long double
#define PI 3.141592653L
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll INF = (ll)1e18;
const int N = 2e5 + 5;
const ll MOD = 1e9+7;

int parent[N];

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

int lcm(int a, int b) {
    return (a*b)/gcd(a,b);
}

ll pow(ll x, ll y, ll p) {
    if(y == 0) return 1;
    ll res = 1;
    x %= p;
    if(x == 0) return 0LL;
    while(y > 0) {
        if(y & 1) res = (res*x) % p;
        y >>= 1;
        x = (x*x) % p;
    }
    return res;
}

int find(int x) {
    return x == parent[x] ? x : parent[x] = find(parent[x]);
}

void Union(int x, int y) {
    int xPar = find(x), yPar = find(y);
    if(xPar != yPar) parent[xPar] = yPar;
}

ll nCr(ll n, ll r) {
    ll res = 1;
    for(ll i=1;i<=r;i++) {
        res = res * (n - r + i) / i;
        // is different from
        // res *= (n -r + i) / i;
    }
    return res;
}

int ask(int i, int j) {
    cout << "? " << i + 1 << ' ' << j + 1 << endl;
    int v;
    cin >> v;
    return v;
}

void solve() {
    int n, x, t;
    cin >> n >> x >> t;
    cout << (int)(ceil)(n / (double)x) * t << endl;
    return;
}

int main()
{
    IOS
    //int t;
    //cin >> t;
    //while(t--)
    solve();
    return 0;
}

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

int main() {
	int N, X, T;
	cin >> N >> X >> T;
	cout << (N + X - 1) / X * T << endl;
}


#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef double db;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef pair<ll,ll> PLL;

#define REP(x,l,u) for(ll x = l; x < u; x++)
#define RREP(x,l,u) for(ll x = l; x >= u; x--)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mst(x,v) memset(x, v, sizeof(x))
#define sz(x) (ll)x.size()

string to_string(string s) {return s;}
string to_string(char c) {string s = string(1, c);return s;}
template <typename A, typename B> string to_string(pair<A,B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(vector<A> v) { string s = "("; int first = 1; for (A a : v) { if (!first) { s += ", "; } first = 0; s += to_string(a); } s += ")"; return s; }
template <typename A> string to_string(set<A> v) { string s = "("; int first = 1; for (A a : v) { if (!first) { s += ", "; } first = 0; s += to_string(a); } s += ")"; return s; }

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

void in() {}
template <typename A> void in(A & x) { cin >> x; }
template <typename A, typename B> void in(pair<A,B> & x) { in(x.first); in(x.second); }
template <typename A> void in(vector<A> & x) { REP(i,0,(ll)x.size()) in(x[i]); }
template <typename Head, typename... Tail> void in(Head & H, Tail & ... T) {in(H); in(T...); }

#ifndef ONLINE_JUDGE
#define debug(...) do { cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__); } while (false)
#else
#define debug(...) do { } while (false)
#endif

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

ll nax = 1005;
VLL p(nax*nax, 1);
VLL P;

void init() {
	p[0] = 0;
	p[1] = 0;

	for (ll x = 2; x < nax*nax; x++) {
		if (p[x] == 0) {
			continue;
		}

		P.push_back(x);

		for (ll f = x; x * f < nax * nax; f++) {
			p[x*f] = 0;
		}
	}
}

map<ll,ll> pf(ll x) {
    map<ll,ll> f;
    REP(i,0,sz(P)) {
        if (P[i] * P[i] > x) break;
        while (x % P[i] == 0) {
            f[P[i]]++;
            x /= P[i];
        }
    }
    if (x > 1) f[x]++;
    return f;
}

VLL F(100500, -1);
VLL INVF(100500, -1);

ll pow(ll a, ll b) {
	if (b == 0) return 1;
	ll h = pow(a, b/2);
	ll ans = b % 2 ? h * h % mod * a : h * h;
	ans %= mod;
	return ans;
}

ll f(ll x) {
	if (F[x] != -1) return F[x];
	if (x == 0) return 1;
	F[x] = f(x-1) * x % mod;
	return F[x];
}

ll invf(ll x) {
	if (INVF[x] != -1) return INVF[x];
	INVF[x] = pow(f(x), mod-2);
	return INVF[x];
}

ll ncr(ll n, ll r) {
	// n! / r! / (n-r)!
	ll ans = f(n);
	ans *= invf(r);
	ans %= mod;
	ans *= invf(n-r);
	ans %= mod;
	return ans;
}

void solve() {
	ll n, m;
	in(n, m);

	map<ll,ll> factors = pf(m);

	REP(i,0,n) f(i); // ease on the recursion

	ll ans = 1;
	for (PLL a : factors) {
		ans *= ncr(a.second + n - 1, a.second) % mod;
		ans %= mod;
	}
	cout << ans << endl;

}

signed main() {
	init();
	ll t = 1;
	REP(i,0,t) solve();
	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};
vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}
const int MAX = 510000;
const int MOD = 1000000007;

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

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int 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(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    COMinit();
    ll N,M;
    cin >>N>>M;
    ll ans=1;
    const auto &res = prime_factorize(M);
    for (auto p : res) {
        ans = (ans*COM(N+p.second-1,p.second))%mod;
    }

    cout << ans << endl;

    return 0;

}


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

int n, m;
unordered_map<string, int> mp;

int main(void){
	cin >> n;
	rep(i, n){
		string s;
		cin >> s;
		mp[s]++;
	}
	cin >> m;
	rep(i, m){
		string t;
		cin >> t;
		mp[t]--;
	}
	int ans = -INT_MAX;
	for(auto i : mp){
		ans = max(ans, i.second);
	}
	cout << max(ans, 0) << endl;
	return 0;
}

#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <stack>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;
typedef long long int ll;
const ll modP = 1000000007;

int main()
{
	int n;
	cin>>n;
	vector<ll> A(n);
	rep(i,n) cin>>A[i];
	vector<ll> x(n+1,0);
	vector<ll> y(n+1,0);
	vector<ll> z(n+1,0);
	for(int i = 0; i < n; i++){
		x[i+1] = x[i];
		y[i+1] = y[i];
		z[i+1] = z[i];
		if( A[i] == x[i]){
			x[i+1]++;
		}else if(A[i] == y[i]){
			y[i+1]++;
		}else{
			z[i+1]++;
		}
	}
	ll ans = 1;
	for(int i = 0; i < n; i++){
		int t = 0;
		if( x[i] == A[i]) t++;
		if( y[i] == A[i]) t++;
		if( z[i] == A[i]) t++;
		ans = (ans * t) % modP;
	}
	cout<<ans<<endl;
	return 0;
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>

using namespace std;

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

const int N = 16;
const int M = (1 << N);
const int INF = 0x3f3f3f3f;

int dp[N][M], g[N][N], n, m, rv[M];

int f(int st, int msk){
    if(st == n - 1) return 0;
    if(dp[st][msk] != -1) return dp[st][msk];
    int sol = INF;
    for(int msk1 = (msk - 1) & msk; msk1 ; msk1 = (msk1 - 1) & msk){
        int msk2 = msk ^ msk1;
        if(msk1 & (1 << (n - 1))) continue;
        if(msk2 & (1 << st)) continue;
        int sum = 0;
        for(int t1 = msk1; t1 ; t1 -= t1 & (-t1)){
            for(int t2 = msk2 ; t2 ; t2 -= t2 & (-t2)){
                sum += g[rv[t1 & (-t1)]][rv[t2 & (-t2)]];
            }
        }
        for(int t2 = msk2 ; t2 ; t2 -= t2 & (-t2)){
            if(g[st][rv[t2 & (-t2)]]){
                sol = min(sol, f(rv[t2 & (-t2)], msk2) + sum - g[st][rv[t2 & (-t2)]]);
            }
        }

    }
    return dp[st][msk] = sol;
}

int main(){
    memset(dp, -1, sizeof(dp));
    for(int i = 0;i<N;i++) rv[(1 << i)] = i;
    memset(dp, -1, sizeof(dp));
    scanf("%d%d", &n, &m);
    for(int i = 0;i<m;i++){
        int x, y;scanf("%d%d", &x, &y);x--;y--;
        scanf("%d", &g[x][y]);
        g[y][x] = g[x][y];
    }
    printf("%d\n", f(0, (1 << n) - 1));
}

#pragma GCC optmize(3)
#include <cstdio>
#include <iostream>
#include <cstring>
#include <ctime>
#define rus register unsigned short
#define rs register short
using namespace std;

const int N = 15;

int G[N][N], dp[N][1 << N], cost[N][1 << N];
int n, m;

inline void upd(int &x, int y) {
  if (x == -1) x = y;
  else x = min(x, y);
}

inline int set_set(int x, int y) {
  int ret = 0;
  for (rs i = 0; i < n; i ++)
    if (x & (1 << i)) ret += cost[i][y];
  return ret;
}

int main() {
  memset(dp, -1, sizeof dp);
  scanf("%d%d", &n, &m);
  for (int i = 1, x, y, z; i <= m; i ++) {
    scanf("%d%d%d", &x, &y, &z);
    x --; y --;
    G[x][y] = G[y][x] = z;
  }
  int t = 1 << n;
  for (rus s = 1; s < t; s ++)
    for (rs i = 0; i < n; i ++)
      if (s & (1 << i)) {
	for (rs j = 0; j < n; j ++) cost[j][s] += G[i][j];
      }
  dp[0][1] = 0;
  for (rus s = 1; s < t; s += 2) {
    rus u = s ^ (t - 1);
    for (rs i = 0; i < n; i ++)
      if (s & (1 << i)) {
	if (dp[i][s] == -1) continue;
	for (rs j = 0; j < n; j ++)
	  if (!(s & (1 << j)) && G[i][j]) upd(dp[j][s | (1 << j)], dp[i][s] + cost[j][s ^ (1 << i)]);
	for (rus v = u; v; v = (v - 1) & u)
	  upd(dp[i][v | s], dp[i][s] + set_set(v, s ^ (1 << i)));
      }
  }
  printf("%d\n", dp[n - 1][t - 1]);
  return 0;
}


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

int main() {
	int n;
	cin >> n;
	int a[n], b[n], c[n], 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];
	}

	int blue_XtoY[205];
	int red_XtoY[205];

	memset(blue_XtoY, -1, sizeof(blue_XtoY));
	memset(red_XtoY, -1, sizeof(red_XtoY));

	for (int i = 0; i < n; i++) {
		blue_XtoY[c[i]] = d[i];
		red_XtoY[a[i]] = b[i];
	}

	int ans = 0;
	set<int> st;
	for (int right = 200; right >= 0; right--) {
		if (red_XtoY[right] != -1) {
			if (st.lower_bound(red_XtoY[right]) != st.end()) {
				ans++;
				st.erase(*st.lower_bound(red_XtoY[right]));
			}
		}
		if (blue_XtoY[right] != -1) {
			st.insert(blue_XtoY[right]);
		}
	}

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

#include<bits/stdc++.h>
using namespace std;
int n,a[203],ans;
int main(){
	cin>>n;
	for(int i=0;i<2*n;i++)
		cin>>a[i];
	sort(a,a+2*n);
	for(int i=0;i<2*n;i+=2)
		ans+=a[i];
	cout<<ans;
}


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

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}

void _main() {
        int n; cin >> n;
        string s; cin >> s;
        vector<int> w(n), e(n);
        for (int i = 0; i < n; i++) {
                if (i) w[i] = w[i - 1];
                w[i] += s[i] == 'W';
        }

        for (int i = n - 1; i >= 0; i--) {
                if (i + 1 < n) e[i] = e[i + 1];
                e[i] += s[i] == 'E';
        }

        int ans = n;
        for (int i = 0; i < n; i++) {
                ans = min(ans, (i ? w[i - 1] : 0) + (i + 1 < n ? e[i + 1] : 0));
        }

        cout << ans;
}

signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}

#include <bits/stdc++.h>
#include<math.h>
#include<algorithm>
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
using vi = vector<int> ;
using vvi = vector<vector<int>> ;
using vl = vector<ll> ;
using vvl = vector<vector<ll>> ;
using vs = vector<string> ;
using vvs = vector<vector<string>> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18

int main() {
    ll n ;
    cin >> n ;
    vl a(n), b(n), c(n) ;
    rep(i, n) cin >> a[i] ;
    rep(i, n) cin >> b[i] ;
    rep(i, n) cin >> c[i] ;
    sort(a.begin(), a.end()) ;
    sort(b.begin(), b.end()) ;
    sort(c.begin(), c.end()) ;
    ll ans = 0 ;
    rep(i, n){
        ll u = (lower_bound(a.begin(), a.end(), b[i]) - a.begin()) ;
        ll v = n - (upper_bound(c.begin(), c.end(), b[i]) - c.begin()) ;
        ans += u * v ;
    }
    cout << ans << endl ;
}


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

int main(int argc, char **argv) {
	string s;
	cin >> s;
	bool ok = false;
	for (int i = 0; i < s.length() - 1; ++i) {
		ok |= s[i] == 'A' && s[i + 1] == 'C';
	}
	cout << (ok ? "Yes" : "No") << endl;
}

#include<iostream>
#include<stdio.h>//printf("%.*f\n",*********);
#include<vector>//s.erase(n),vector
#include<algorithm>//next_permutation
#include<set>
#include<string>//char('a'=32+'A')
                //to_string,string,substr
#include<sstream>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>//min,max
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap
#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)//start==1
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)//end==1
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define Yay(ans) if(ans)cout<<"Yay!"<<rt;else cout<<":("<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(a,n) rep(i,n)cin>>a[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//昇順
#define reve(s) reverse(s.begin(),s.end())//反転
#define please return
#define AC 0
#define rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define pi 3.1415926535897932384626//pi
#define nine 1000000000//10^9

using namespace std;
typedef vector<int> vint;
typedef long double ldouble;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef vector<double> vdouble;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

int KETA(int n) { //Sum of Each Digit
	int sum = 0;
	while (n > 0) {
		sum += n % 10; n /= 10;
	}
	return sum;
}

unsigned ND(unsigned num) {//Number of Digits
	return std::to_string(num).length();//outmax=10
}

bool KIBN(string s) {
	rep(i, s.size() / 2) {
		if (s[i] != s[s.size() - 1 - i])return false;
	}
	return true;
}

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */

int main(void) {
	rapid_pleaseAC_fast;

	string s;
	cin >> s;
	rep(i, s.size() - 1) {
		if (s.substr(i, 2) == "AC") {
			cout << "Yes" << rt;
			return 0;
		}
	}
	cout << "No" << rt;

	please AC;
}
//参考：---


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

int main() {
    int N; cin >> N;
    for (int i = 100; i > 0; i /= 10) {
        if (N / i == 7) {
            cout << "Yes" << endl;
            return 0;
        }
        N %= i;
    }
    cout << "No" << endl;
}

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC optimize("Ofast")
//*********************************************DO IT NOW****************************************************************
#include<bits/stdc++.h>
#include<random>
#define int long long
#define pp pair<int,int>
#define ss second
#define ff first
#define pb push_back
#define mod 1000000007
#define pi 3.14159265359
#define mk(arr,n,type)  type *arr=new type[n];
#define sl s1.length();
#define yes cout<< "YES"<<endl
#define no  cout<< "NO"<<endl
#define all(v) (v).begin(),(v).end()
#define s(v)   sort(v,v+n)
#define  mt mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define read(a,n) for(int i=0;i<n;i++)cin>>a[i]
#define print(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" "
using namespace std;
//**********************************************DO IT NOW***************************************************************
void fastio()
{
  #ifndef ONLINE_JUDGE
  freopen("INPUT.txt","r",stdin);
  freopen("OUTPUT.txt","w",stdout);
  #endif
  ios_base :: sync_with_stdio(false);
  cin.tie(NULL) ;
  cout.tie(NULL);
}
int dp[101][1001],ans1=1e9,dp1[1000001];
int num[10];
int a[1000000];
int pr(int n)
{
 for(int i=2;i*i<=n;i++)
      {
          if(n%i==0)
          return 0;
      }
      return 1;
}
signed main()
{
    fastio();
    int t=1;
   // cin>>t;
    while(t--)
    {
      string s;
      cin>>s;
      int c=0;
      for(int i=0;i<s.length();i++)
      {
          if(s[i]=='7')
          c++;

      }
      if(c)
      cout<<"Yes";
      else
      cout<<"No";
    }

}
// 🍪 🍪 🍪


#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

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

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

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

    ll L, R;
    cin >> L >> R;

    if (R - L >= 2018) {
        print(0);
    } else {
        L %= 2019, R %= 2019;

        int ans = 2018;
        FOR(i, L, R + 1) FOR(j, i + 1, R + 1) {
            ans = min(ans, i * j % 2019);
        }
        print(ans);
    }

}

#include <iostream>
using namespace std;
int main() {
    int A, B; cin >> A >> B;
    printf("%d\n", max(A + B, max(A - B, A * B)));
}


#include<bits/stdc++.h>
using namespace std;
const int inf=1<<30,maxn=2000005;
int i,j,k,n,v[100000005];
int f[maxn],prime[maxn],tot,e[100005];
long long ans[505][505],mx;
map<long long,int> p;
void shai()
{
    tot=0;
    for(int i=2;i<maxn;i++)
    {
        if(!f[i])
            prime[tot++]=i;
        for(int j=0;j<tot&&prime[j]*i<maxn;j++)
        {
            f[i*prime[j]]=1;
            if(i%prime[j]==0)
            {
                break;
            }
        }
    }
}
long long gcd(long long a,long long b)
{
	if(!b)
		return a;
	return gcd(b,a%b);
}
long long lcm(long long a,long long b)
{
	if(a==0)
		return b;
	if(b==0)
		return a;
	return a/gcd(a,b)*b;
}
int main()
{
	shai();
	scanf("%d",&n);
	int m=0;
	for(i=1;i<=499;i+=2)
		e[i]=++m;
	for(i=2;i<=499;i+=2)
		e[i]=++m;
	for(i=500;i>=1;--i)
		for(j=500;j>=1;--j)
			if((i+j)&1)
			{
				for(k=prime[e[(i+j)/2]-1];v[k];k+=prime[e[(i+j)/2]-1]);
				ans[i][j]=k;
				v[k]=1;
				p[k]=1;
			}
	for(i=1;i<=500;++i)
		for(j=1;j<=500;++j)
			if(ans[i][j]==0)
			{
				long long s=lcm(lcm(ans[i-1][j],ans[i][j-1]),lcm(ans[i+1][j],ans[i][j+1]));
				ans[i][j]=s+1;
				while(p[ans[i][j]])
					ans[i][j]+=s;
				p[ans[i][j]]=1;
			}
	for(i=1;i<=n;++i)
	{
		for(j=1;j<=n;++j)
		{
			printf("%lld ",ans[i][j]);
			//mx=max(mx,ans[i][j]);
		}
		printf("\n");
	}
	//cout<<mx<<endl;
}


#include <bits/stdc++.h>		//万能头文件
using namespace std;

int main()
{
	string a;
	int pos=0;		//记录位置
	cin>>a;
	a=a+"D";		//为防止最后一个字母是"A",添加一个不是"C"的字母
	while(1)
	{
		pos=a.find("A",pos);		//find()函数查找位置
		if(pos<0)		//如果没找到，返回-1
		{
			cout<<"No"<<endl;		//endl养成好习惯
			break;		//跳出循环
		}
		if(a[pos+1]=='C')		//判断"A"下一个是不是"C"
		{
			cout<<"Yes"<<endl;
			break;		//跳出循环
		}
		pos++;		//下一次从pos+1找起
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define For(i, s, e) for(int i = s;i <= e;i++)
#define Sort(v, n) sort(v, v+n);
#define VSort(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define cY cout<<"Yes";
#define cN cout<<"No";
#define cA(a) cout<<a;
const ll MOD = 1000000007;

int main() {
    string s;
    cin >> s;
    bool a=0,ac=0;
    rep(i,s.size()-1) {
        if(s[i] == 'A' && s[i+1] == 'C') ac = 1;
    }
    if(ac) cout << "Yes";
    else cout << "No";
}


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

int N,M0,M1;
vector<int> adj[2][MAXN];
vector<int> s[2][MAXN];

int p[2][MAXN];
void dfs(int u, int x, int f){
	p[f][u] = x;
	s[f][x].push_back(u);

	int v;
	for(int k=0;k<adj[f][u].size();k++){
		v = adj[f][u][k];
		if(!p[f][v]) dfs(v, x, f);
	}
}

int ans[MAXN], vis[MAXN];
void work(int id){
	int x = p[0][id];
	int v;
	for(int k=0;k<s[0][x].size();k++){
		v = s[0][x][k];
		vis[p[1][v]]++;
	}

	for(int k=0;k<s[0][x].size();k++){
		v = s[0][x][k];
		ans[v] = vis[p[1][v]];
	}

	for(int k=0;k<s[0][x].size();k++){
		v = s[0][x][k];
		vis[p[1][v]]--;
	}
}

int main(){
	ios::sync_with_stdio(0);
	cin>>N>>M0>>M1;

	int u,v;
	for(int i=1;i<=M0;i++){
		cin>>u>>v;
		adj[0][u].push_back(v);
		adj[0][v].push_back(u);
	}
	for(int i=1;i<=M1;i++){
		cin>>u>>v;
		adj[1][u].push_back(v);
		adj[1][v].push_back(u);
	}

	for(int i=1;i<=N;i++){
		if(!p[0][i]){
			dfs(i,i,0);
		}
		if(!p[1][i]){
			dfs(i,i,1);
		}
	}

	for(int i=1;i<=N;i++){
		if(ans[i] == 0){
			work(i);
		}
	}

	//for(int i=1;i<=N;i++) cout<<p1[i]<<" "<<p2[i]<<endl;
	for(int i=1;i<=N;i++) cout<<ans[i]<<" ";
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
struct _IO{_IO(){ios::sync_with_stdio(0);cin.tie(0);}}_io;

typedef long long ll;
typedef long double db;
typedef unsigned long long ull;
typedef vector<int> vi; typedef vector<vi> vii;
typedef pair<int, int> pi;
typedef tuple<int, int, int> t3;
typedef map<int, int> mi;
#define fi first
#define se second
#define vt vector
#define be begin()
#define ed end()
#define sz size()
#define cl clear()
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define lb(v, x) lower_bound(v.begin(), v.end(), x)
#define lbi(v, x) (lb(v, x) - v.begin())
#define tp(t, x, y) t x, y; tie(x, y)
#define tp3(t, x, y, z) t x, y, z; tie(x, y, z)
#define mp make_pair
#define mt make_tuple
#define co const
#define fc(x) for(int x = 1, _end = ri(); x <= _end; x++)
void uni(vi &v) { sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); }

db rd() { db x; cin >> x; return x; }
ll ri() { ll x; cin >> x; return x; }
string rs() { string s; cin >> s; return s; }
pi rpi() { pi x; cin >> x.fi >> x.se; return x; }
vi rvi(int n, int f = 0) { vi v(n + f); for (int i = f; i < v.size(); i++) cin >> v[i]; return v; }
vii rvii(int n, int m, int f = 0) { vii v(n + f, vi(n + f)); for (int i = f; i < v.size(); i++) for (int j = f; j < v[0].size(); j++) cin >> v[i][j]; return v; }
void pr() {}; template <class T, class ...U> void pr(T x, U ...y) { cout << x << ' ', pr(y...); }
void prl() { cout << '\n'; }; template <class T, class ...U> void prl(T x, U ...y) { cout << x << ' ', prl(y...); }
void pr(const vi &v, int f = 0) { for (int i = f; i < v.size(); i++) cout << v[i] << ' '; }
void prl(const vi &v, int f = 0) { pr(v, f); cout << '\n'; }
void pr(const pi &x) { cout << x.fi << ' ' << x.se; };
void prl(const pi &x) { pr(x); cout << '\n'; }

#define rep(i, l, r) for (int i = l; i < r; i++)
#define per(i, l, r) for (int i = l; i >= r; i--)

const int N = 2e5 + 5, M = 1e9 + 7;

int fa[N];
int fi(int x) {
  return !fa[x] || fa[x] == x ? x : fa[x] = fi(fa[x]);
}

vi g[N];
map<int, vi> cnt;
bool vis[N];
void dfs(int u) {
  vis[u] = 1;
  cnt[fi(u)].pb(u);
  for (auto &v : g[u]) {
    if (!vis[v]) dfs(v);
  }
}

int main() {
  int n = ri(), a = ri(), b = ri();
  rep(i, 0, a) {
    int x = ri(), y = ri();
    fa[fi(x)] = fi(y);
  }
  rep(i, 0, b) {
    int u = ri(), v = ri();
    g[u].pb(v);
    g[v].pb(u);
  }
  vi ans(n + 1);
  rep(i, 1, n + 1) {
    if (!vis[i]) {
      cnt.clear();
      dfs(i);
      for (auto &p : cnt) {
        for (auto &v : p.se) {
          ans[v] = p.se.sz;
        }
      }
    }
  }
  pr(ans, 1);
}


#include<bits/stdc++.h>

using namespace std;

#define ii pair<int,int>
#define fi first
#define se second

#define FOR(a,b,c) for(int a=b, __c=c; a<=__c; ++a)

const int N=2e5+5;
int n,a[N],b[N];
int cnt[N],d[N],ans[N];

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

   cin>>n;
   FOR(i,1,n) cin>>a[i];
   FOR(i,1,n) cin>>b[i];
   FOR(i,1,n) cnt[a[i]]++, cnt[b[i]]++, d[b[i]]++;
   multiset<ii> s;
   FOR(i,1,n) if(d[i]) s.insert({cnt[i],i});
   FOR(i,1,n){
      auto p=*s.rbegin();
      s.erase(p);
      if(p.se==a[i]){
         if(s.empty()) return cout<<"No\n",0;
         p=*s.rbegin();
         s.erase(p);
         s.insert(make_pair(cnt[a[i]],a[i]));
      }
      s.erase(make_pair(cnt[p.se],p.se));
      d[p.se]--;
      cnt[p.se]--;
      if(d[a[i]]) s.erase({cnt[a[i]],a[i]});
      cnt[a[i]]--;
      if(d[p.se]) s.insert({cnt[p.se],p.se});
      if(d[a[i]]) s.insert({cnt[a[i]],a[i]});
      ans[i]=p.se;
   }
   cout<<"Yes\n";
   FOR(i,1,n) cout<<ans[i]<<' ';
}

// ALDS1_6_B.cpp
// Sort II - Partition

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

int Partition(vector<int>& A, int p, int r)
{
	int tmp = A[r];
	int i = p - 1;
	for (int j = p; j < r; j++) {
		if (A[j] <= tmp) {
			i++;
			swap(A[i], A[j]);
		}
	}
	swap(A[++i], A[r]);
	return i;
}

int main()
{
	int n;
	cin >> n;
	vector<int> A(n);
	for (int i = 0; i < n; i++) {
		cin >> A[i];
	}
	int pivot = Partition(A, 0, n - 1);
	for (int i = 0; i < n; i++) {
		if (i > 0) cout << " ";
		if (i == pivot) printf("[%d]", A[i]);
		else cout << A[i];
	}
	cout << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define ssort(n) sort((n).begin(),(n).end())
#define rsort(n) sort((n).begin(),(n).end(),greater<int>())
#define mp make_pair
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
typedef pair<P,int> COST;
#define repl(i,n) for(ll i=0;i<(n);++i)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
using Graf=vector<vector<ll>>;
#define MAX 1000000007

int main()
{
    int n;double l;
    cin >> n >> l;
    vector<double> taste(n);
    rep(i,n){
        taste[i]=l+i+1-1;
    }
    double sum=0;
    rep(i,n){
        sum+=taste[i];
    }

    int ans_i=MAX;
    int p;
    rep(i,n){
        if(abs(taste[i]-0)<ans_i){
            p=i;
            ans_i=abs(taste[i]-0);
        }
    }
    sum-=taste[p];
    cout << sum << endl;
}

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

int main() {
    int K,X;cin>>K>>X;
    for (int i = X-K+1; i <= X+K-1; i++)cout<<i<<" ";
    cout<<endl;
}


#include<cstdio>
#include<cstring>
#include<stack>
#include<algorithm>
using namespace std;
const long long MAXN=1000005;

int n,m;
char S[MAXN],T[MAXN];
stack<int> s[30];
pair<int,int> que[MAXN];
int hd,tl;

int main()
{
    scanf("%d%s%s",&n,S+1,T+1);
	for(int i=1;i<=n;i++)
		s[S[i]-'a'].push(i);
	hd=1;tl=0;
	int now=n,last=n+1,c=0;
	int ans=0;
    for(int i=n;i>=1;i--)
	{
		now=min(now,i);
		while(!s[T[i]-'a'].empty()&&s[T[i]-'a'].top()>now)
			s[T[i]-'a'].pop();
		if(s[T[i]-'a'].empty())
		{
			puts("-1");
			return 0;
		}
		now=s[T[i]-'a'].top();
		if(now==i||now==last)
		{
			last=now;
			continue;
		}
		last=now;
		while(hd<=tl&&que[hd].first-que[hd].second-c+1>i)
		{
			ans=max(ans,que[hd].second+c);
			hd++;
		}
		c++;
		que[++tl]=make_pair(now,1-c);
	}
	for(int i=hd;i<=tl;i++)
		ans=max(ans,que[i].second+c);
	printf("%d\n",ans);

    return 0;
}

#define _DEBUG 1
#define _GLIBCXX_DEBUG

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

using ll = long long;

#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z)                                                     \
  cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
       << endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define dump3(x, y, z)
#define check(s)
#endif

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

const ll LINF = 2e18;
const int INF = 1e9;

void solve(ll N, ll Q, std::string S, std::vector<ll> l, std::vector<ll> r) {
  vector<ll> a(N, 0);
  FOR(i, 1, N) {
    a.at(i) = a.at(i - 1);
    if (S.at(i) == 'C' && S.at(i - 1) == 'A') a.at(i) += 1;
  }

  rep(i, Q) cout << a.at(r.at(i) - 1) - a.at(l.at(i) - 1) << endl;
}

int main() {
  ll N;
  scanf("%lld", &N);
  ll Q;
  scanf("%lld", &Q);
  std::string S;
  std::cin >> S;
  std::vector<ll> l(Q);
  std::vector<ll> r(Q);
  for (int i = 0; i < Q; i++) {
    scanf("%lld", &l[i]);
    scanf("%lld", &r[i]);
  }
  solve(N, Q, S, std::move(l), std::move(r));
  return 0;
}


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

int main() {
  int n, m;
  long long p[1000];

  while(1) {
    cin >> n >> m;
    if (n == 0 && m == 0) break;

    long long ans = 0;
    for (int i = 0; i < n; i++) {
      cin >> p[i];
      ans += p[i];
    }

    sort(p, p+n, std::greater<long long>());

    for (int i = m-1; i < n; i += m) {
      ans -= p[i];
    }

    cout << ans << endl;
  }

}


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

const string check = "Hoshino";

int main()
{
	int n;
	string str;
	cin >> n;
	getline(cin,str);
	for(int loop=0;loop<n;loop++){
		getline(cin,str);
		for(unsigned i=0;i<str.size();i++){
			bool flag = true;
			for(unsigned j=0;j<check.size();j++){
				if(i+j < str.size()){
					if(str[i+j] != check[j])
						flag = false;
					else{
						if(j == check.size()-1 && flag)
							str[i+j] = 'a';
					}
				}
			}
		}
		cout << str << endl;
	}
	return 0;
}

#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

int main() {

	int n;
	string sn;
	getline(cin, sn);
	n = atoi(sn.c_str());
	REP(i, n){
		string s;
		getline(cin, s);
		while (s.find("Hoshino") != string::npos){
			s[s.find("Hoshino") + 6] = 'a';
		}
		cout << s << endl;
	}
}


#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cstdio>
#include<cmath>
#include<deque>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<tuple>
#include<utility>
#include<vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<vector<int>> vvi;

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define REP(i, n)  for(int i=0; i<(int)(n); i++)
#define REPS(i, n)  for(int i=1; i<=(int)(n); i++)
#define PER(i, n) for(int i=(int)(n)-1; i>= 0; i--)
#define PERS(i, n)  for(int i=(int)(n); i>0; i--)
#define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i!=(c).end(); i++)
#define RFOR(i, c)  for(__typeof((c).rbegin()) i=(c).rbegin(); i!=(c).end(); i++)
#define ALL(container)  (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) (container).size()
#define FILL0(n)  setfill('0') << right << setw(n)
#define mp(a, b)  make_pair(a, b)
#define toLower(c)  c+0x20
#define toUpper(c)  c-0x20
#define pb  push_back
#define eb  emplace_back

const int INF = 1e9;
const long long LLINF = 1e18;
const ull MOD = 998244353;
const int MSIZE = 100007;
const double Pi = 3.14159265358979323146;

int main(){
  int match[10] = {6,2,5,5,4,5,6,3,7,6};
  int n, m; cin >> n >> m;
  vector<int> num(m), dp(n+100, -INF);
  REP(i, m){
    cin >> num[i];
  }
  dp[0]=0;
  sort(RALL(num));
  string ans = "";
  for(int i=1; i<=n; i++){
    REP(j, m){
      if(i-match[num[j]]<0) continue;
      dp[i] = max(dp[i], dp[i-match[num[j]]]+1);
    }
  }
  //cout << n << ":" << ans << endl;

  while(n>0){
    REP(j, m){
      if(n-match[num[j]]<0) continue;
      if(dp[n-match[num[j]]]==dp[n]-1){
        ans += ('0'+num[j]);
        n-=match[num[j]];
        //cout << n << ":" << ans << endl;
        break;
      }
    }
  }
  cout << ans << endl;
}

#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define mod 1000000007
using ll=long long;
const int INF=1000000000;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

struct IOSetup{
    IOSetup(){
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(12);
    }
} iosetup;

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

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

template<typename T1,typename T2>
istream &operator>>(istream &is,pair<T1,T2>&p){
    is>>p.first>>p.second;
    return is;
}

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

int dp[310][310][610];
signed main(){
    string s;cin>>s;
    int m;cin>>m;
    int n=(int)s.size();
    if(m>=n){
        cout<<n<<endl;
        return 0;
    }
    string t=s;
    reverse(ALL(t));

    rep(i,n)rep(j,n)rep(k,m+1){
        chmax(dp[i+1][j+1][k],dp[i][j][k]+(s[i]==t[j]));
        chmax(dp[i+1][j+1][k],dp[i][j+1][k]);
        chmax(dp[i+1][j+1][k],dp[i+1][j][k]);
        chmax(dp[i+1][j+1][k+1],dp[i][j][k]+1);
    }
    int res=0;
    // t=rev(s)
    // s = [a   ][b     ]
    // t = [rb    ][ra  ]
    // LCS(a,rb)=LCS(b,ra)
    // 文字同士をマッチングさせることを考えるとそれはそう
    rep(i,n+1)chmax(res,2*dp[i][n-i][m]);
    rep(i,n)  chmax(res,2*dp[i][n-1-i][m]+1);
    cout<<res<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,s;
deque<pair<ll,ll> >vec;
ll rec(){
	if(vec.empty()) return 0LL;
	int sz = vec.size();
	if(vec[0].sc >= vec[sz-1].sc){
		vec[0].sc += vec[sz-1].sc;
		ll pos = vec[sz-1].fi;
		vec.pop_back();
		sz--;
		if(vec[0].fi > s){
			return pos-s;
		}
		else if(vec[sz-1].fi < s){
			return s-vec[0].fi-vec[0].fi+pos;
		}
		else{
			if(vec[0].sc >= vec[sz-1].sc){
				ll cst = pos-vec[sz-1].fi;
				ll ans = rec();
				return ans+cst;
			}
			else{
				ll cst = pos-vec[0].fi;
				ll ans = rec();
				return ans+cst;
			}
		}
	}
	else{
		vec[sz-1].sc += vec[0].sc;
		ll pos = vec[0].fi;
		vec.pop_front();
		sz--;
		if(vec[sz-1].fi < s){
			return s-pos;
		}
		else if(vec[0].fi > s){
			return vec[sz-1].fi-s-pos+vec[sz-1].fi;
		}
		else{
			if(vec[0].sc >= vec[sz-1].sc){
				ll cst = vec[sz-1].fi-pos;
				ll ans = rec();
				return ans+cst;
			}
			else{
				ll cst = vec[0].fi-pos;
				ll ans = rec();
				return ans+cst;
			}
		}
	}
}
int main(){
	cin>>n>>s;
	rep(i,n){
		int x,p ; cin>>x>>p;
		vec.pb(pair<ll,ll>(x,p));
	}
	if(vec[0].fi > s){
		cout<<vec[n-1].fi-s<<endl;
		return 0;
	}
	if(vec[n-1].fi < s){
		cout<<s-vec[0].fi<<endl;
		return 0;
	}
	ll ans = rec();
	cout<<ans<<endl;
}


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

int main(){
    ll n, t;
    cin >> n >> t;
    ll ans=0;
    ll pre=0;
    ll push=0;
    cin >> pre;
    for(int i=0; i<n-1; i++){
        pre = push;
        cin >> push;
        if(push-pre < t) ans += push-pre;
        else ans += t;
    }
    ans += t; //最後の一回
    cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const long long INF = 1LL << 60;
const int MOD = 1000000007;

int main() {
    ll N;
    cin >> N;
    vector<ll> A(N+2);
    A[0] = 0;
    for (int i = 1; i <= N; i++) cin >> A[i];
    A[N+1] = 0;

    ll sum = 0;
    for (int i = 0; i <= N; i++){
      sum += abs(A[i] - A[i + 1]);
    }

    for (int i = 0; i < N; i++) {
      cout << sum - abs(A[i + 1] - A[i]) - abs(A[i + 1] - A[i + 2]) +abs(A[i] - A[i + 2])<< endl;
    }
    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long LL;

LL n,d;
LL col[2][500005] = {0};
LL v[4][500005],cnt[4] = {0};

LL id(LL x,LL y){ return x * n + y + 1; } // (x,y) -> id
LL getx(LL x){ return (x - 1) / n; } // id(x,y) -> x
LL gety(LL y){ return (y - 1) % n; } // id(x,y) -> y

void dfs(LL u,LL idd){
	LL tx = getx(u),ty = gety(u);
	for(LL dy,dx = 0;dx <= n;dx ++){
		if(dx * dx > d) continue;
		dy = sqrt(d - dx * dx);
		if(dx * dx + dy * dy != d) continue;

		if(tx + dx < n && ty + dy < n)
			if(col[idd][id(tx + dx,ty + dy)] == -1) { col[idd][id(tx + dx,ty + dy)] = 1 - col[idd][u]; dfs(id(tx + dx,ty + dy),idd); }
		if(tx + dx < n && ty - dy >= 0)
			if(col[idd][id(tx + dx,ty - dy)] == -1) { col[idd][id(tx + dx,ty - dy)] = 1 - col[idd][u]; dfs(id(tx + dx,ty - dy),idd); }
		if(tx - dx >= 0 && ty + dy < n)
			if(col[idd][id(tx - dx,ty + dy)] == -1) { col[idd][id(tx - dx,ty + dy)] = 1 - col[idd][u]; dfs(id(tx - dx,ty + dy),idd); }
		if(tx - dx >= 0 && ty - dy >= 0)
			if(col[idd][id(tx - dx,ty - dy)] == -1) { col[idd][id(tx - dx,ty - dy)] = 1 - col[idd][u]; dfs(id(tx - dx,ty - dy),idd); }
	}
}

int main(){
	memset(col,-1,sizeof(col));
	cin >> n; n <<= 1;
	cin >> d;
	for(LL i = 0;i < n;i ++)
		for(LL j = 0;j < n;j ++)
			if(col[0][id(i,j)] == -1){ col[0][id(i,j)] = 1; dfs(id(i,j),0); }
	cin >> d;
	for(LL i = 0;i < n;i ++)
		for(LL j = 0;j < n;j ++)
			if(col[1][id(i,j)] == -1){ col[1][id(i,j)] = 1; dfs(id(i,j),1); }
	/*
	for(LL i = 0;i < n;i ++)
		for(LL j = 0;j < n;j ++)
			cout << col[0][id(i,j)] << (j == n - 1 ? '\n' : ' ');
	for(LL i = 0;i < n;i ++)
		for(LL j = 0;j < n;j ++)
			cout << col[1][id(i,j)] << (j == n - 1 ? '\n' : ' ');
	*/
	for(LL i = 1;i <= id(n - 1,n - 1);i ++){
		LL co = col[0][i] + col[1][i] * 2;
		v[co][++ cnt[co]] = i;
	}
	for(LL i = 0;i < 4;i ++){
		if(cnt[i] >= n * n / 4){
			for(LL j = 1;j <= n * n / 4;j ++) cout << getx(v[i][j]) << ' ' << gety(v[i][j]) << '\n';
			break;
		}
	}
	return 0;
}

// template version 1.8

// varibable settings {{{
using namespace std;
#include <iostream>
#include <bits/stdc++.h>

#define int long long
#define INF 1e18
// #define INF 2147483647
#define MOD 998244353
#define infile "../test/sample-1.in"
int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
#define fi first
#define se second

// }}}

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;

// dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;
// }}}

int dp[300][90005];
int dp2[300][90005];

int solve(){
  int n;
  cin>>n;
  vi a(n); rep(i, n) {cin>>a[i];}
  sort(all(a));
  int S = accumulate(all(a), 0LL);

  int r = (S%2==0 ? S/2 : S/2+1);
  dump(S, r);

  dp[0][a[0]]=1;
  dp[0][0]=2;
  rep(i, 1, n){
    rep(j, S+5){
      dp[i][j+a[i]] += dp[i-1][j];
      dp[i][j+a[i]] %= MOD;
      dp[i][j] += 2*dp[i-1][j];
      dp[i][j] %= MOD;
    }
  }
  int x = 0;
  rep(i, r, S+5){
    x+=dp[n-1][i];
    x%=MOD;
  }

  int A = 1;
  rep(i, n){
    A *= 3;
    A %= MOD;
  }

  int res;
  if (S%2!=0){
    res = A - 3*x;
    res %=MOD;
  }
  else{
    dp2[0][a[0]]=1;
    dp2[0][0]=1;
    rep(i, 1, n){
      rep(j, S+5){
        dp2[i][j+a[i]] += dp2[i-1][j];
        dp2[i][j+a[i]] %= MOD;
        dp2[i][j] += dp2[i-1][j];
        dp2[i][j] %= MOD;
      }
    }
    res = A - (3*x-dp2[n-1][S/2]*3);
    res %=MOD;
  }
  cout << (res<0 ? res+MOD : res) << endl;

  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


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

int main(){
	// sengen
	LL n,a[5];
	// nyuryoku
	cin >> n >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
	// keisan
	LL ans = 4;
	LL plus = 0;
	if(n%a[0] == 0){
		plus = n/a[0];
	}else{
		plus = n/a[0] + 1;
	}
	for(int i=1;i<5;i++){
		if(n%a[i] == 0){
			plus = max(plus,n/a[i]);
		}else{
			plus = max(plus,n/a[i] + 1);
		}
	}
	// syutsuryoku
	cout << plus + ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#define vi vector<int>
template <class t, class u>
bool chmax(t &a, u b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class t, class u>
bool chmin(t &a, u b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}
signed main()
{
    ll n;
    cin >> n;
    vector<ll> a;
    rep(i, 5)
    {
        ll b;
        cin >> b;
        a.push_back(b);
    }
    sort(all(a));
    cout << (n + a[0] - 1LL) / a[0] + 4LL << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define pll pair <ll , ll>

#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair

#define X first
#define Y second

#define LB(x) ((x) & -(x))
#define BIT(a , b) (((a)>>(b)) & 1)

vector <ll> o;
vector <ll> e;
vector <ll> a;
vector <ll> b;

void print()
{
    for (ll i = 0; i < a.size(); i++)
    {
        cout << a[i] << " ";
    }
    cout << endl;

    cout << b.size() << endl;
    for (ll i = 0; i < b.size(); i++)
    {
        cout << b[i] << " ";
    }
    cout << endl;
}

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

	ll n , m;
	cin >> n >> m;

	for (ll i = 1; i <= m; i++)
    {
        ll x;
        cin >> x;

        if (x & 1)
        {
            o.pb(x);
        }
        else
        {
            e.pb(x);
        }
    }

    if (o.size() == 0)
    {
        b.pb(1);
        for (ll i = 0; i < (ll)(e.size()) - 1; i++)
        {
            a.pb(e[i]);
            b.pb(e[i]);
        }
        a.pb(e.back());
        b.pb(e.back() - 1);

        print();
        return 0;
    }

    if (o.size() == 1)
    {
        if (n == o[0])
        {
            a.pb(o[0]);
            if (o[0] > 1)
            {
                b.pb(o[0] - 1);
            }
            b.pb(1);
        }
        else
        {
            a.pb(o[0]);
            b.pb(o[0] + 1);
            for (ll i = 0; i < (ll)(e.size()) - 1; i++)
            {
                a.pb(e[i]);
                b.pb(e[i]);
            }
            a.pb(e.back());
            b.pb(e.back() - 1);
        }

        print();
        return 0;
    }

    if (o.size() == 2)
    {
        a.pb(o[0]);
        if (o[0] > 1)
        {
            b.pb(o[0] - 1);
        }

        for (ll i = 0; i < e.size(); i++)
        {
            a.pb(e[i]);
            b.pb(e[i]);
        }
        a.pb(o[1]);
        b.pb(o[1] + 1);

        print();
        return 0;
    }

    cout << "Impossible";
    return 0;
}

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

int dr[4]={-1,0,0,1};
int dc[4]={0,-1,1,0};

void bfs(const vector<vc> &field, vector<vi> &dist){
    queue<pair<int,int>> que;
    que.push({1,1});
    dist[1][1]=0;
    while(!que.empty()){
        auto x=que.front(); que.pop();
        for(int i=0;i<4;i++){
            int nr=x.first+dr[i];
            int nc=x.second+dc[i];
            if(field[nr][nc]=='#') continue;
            if(dist[nr][nc]!=-1) continue;
            dist[nr][nc]=dist[x.first][x.second]+1;
            que.push({nr,nc});
        }
    }
}

int main(){
    int r,c;
    cin >> r >> c;
    vector<vc> field(r+2,vc(c+2,'#'));
    int ans=0;
    for(int i=1;i<=r;i++){
        for(int j=1;j<=c;j++){
            cin >> field[i][j];
            if(field[i][j]=='.') ans++;
        }
    }
    vector<vi> dist(r+2,vi(c+2,-1));
    bfs(field,dist);
    if(dist[r][c]==-1){
        cout << "-1" << endl;
        return 0;
    }
    cout << ans-dist[r][c]-1 << endl;

}


#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second

const int MAXN = 100000;

typedef pair<int, int> ii;
typedef vector<ii> vii;

vii adjList[MAXN];

int dist[MAXN]; bitset<MAXN> inq;
queue<int> q;

int main(){

    int N, E, S;
    cin >> N >> E >> S;

    for (int i=0; i<E; i++){
        int s, t, d;
        cin >> s >> t >> d;

        adjList[s].push_back(ii(d,t));
    }

    memset(dist, -1, sizeof(dist)); dist[S] = 0;
    inq.reset(); inq[S] = 1;

    q.push(S);
    while (!q.empty()) {
        int x = q.front(); q.pop();

        inq[x] = 0;
        for (vii::iterator it = adjList[x].begin(); it != adjList[x].end(); ++it) {
            int nn = it->se;
            int nd = dist[x]+it->fi;

            if (dist[nn] != -1 && dist[nn] <= nd) continue;

            dist[nn] = nd;
            if (!inq[nn]) q.push(nn);
            inq[nn] = 1;
        }
    }

    for (int i=0; i<N; i++){
        if (dist[i] == -1) cout << "INF" << endl;
        else cout << dist[i] << endl;
    }
}

#include <bits/stdc++.h>

//{{{ graph.hpp
#ifndef INCLUDE_GRAPH_HPP
#define INCLUDE_GRAPH_HPP
#include <vector>
namespace orislib {
struct Edge {
  typedef int weight_t;
  int from, to;
  weight_t w;
  Edge(int from, int to, weight_t w) : from(from), to(to), w(w) {}
  bool operator<(const Edge& e) const {
    return w > e.w;
  }
};
typedef std::vector<Edge> Edges;
typedef std::vector<Edges> Graph;
}
#endif
//}}}

using namespace orislib;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tuple<int, int> duo;
//{{{ templates
#define TMPINL_(...) template<__VA_ARGS__>inline
#define TT_ TMPINL_(typename T)
#define TTF_ TMPINL_(typename T,typename F)
#define TTTS_ TMPINL_(typename T,typename...Ts)
#define TITS_ TMPINL_(size_t I=0,typename...Ts)
TT_ T sq(T x){return x*x;}
TT_ T In(){T x;cin>>x;return x;}
TT_ void Out(T&x){cout<<x;}
TT_ void sort(T&v){sort(begin(v),end(v));}
TT_ void revs(T&v){reverse(begin(v),end(v));}
TT_ void uniq(T&v){sort(v);v.erase(unique(begin(v),end(v)),end(v));}
TT_ int ubnd(T&v,typename T::value_type&x){return upper_bound(begin(v),end(v),x)-begin(v);}
TT_ int lbnd(T&v,typename T::value_type&x){return lower_bound(begin(v),end(v),x)-begin(v);}
TTF_ void inpt(T&v,int n,F f){for(v.reserve(n);n--;v.emplace_back(f()));}
TTF_ void show(T&v,F f,string d=" ",string e="\n"){int i=0;for(auto&x:v)i++&&(cout<<d),f(x);cout<<e;}
TITS_ typename enable_if<I==tuple_size<tuple<Ts...>>::value-1,string>::type join(string s,tuple<Ts...>t){return to_string(get<I>(t));}
TITS_ typename enable_if<I<tuple_size<tuple<Ts...>>::value-1,string>::type join(string s,tuple<Ts...>t){return to_string(get<I>(t))+s+join<I+1>(s,t);}
TT_ string join(string s,T t){return to_string(t);}
TTTS_ string join(string s,T t,Ts...ts){return join(s,t)+s+join(s,ts...);}

inline void fast_io(){ios::sync_with_stdio(0);cin.tie(0);}
inline int in(){int x;scanf("%d",&x);return x;}
inline ll pow_mod(ll a,ll k,ll m){ll r=1;for(;k>0;a=a*a%m,k>>=1)if(k&1)r=r*a%m;return r;}
inline ll mod_inv(ll a,ll p){return pow_mod(a,p-2,p);}
inline int puts(const string&s){ return puts(s.c_str()); }
//}}} priority_queue queue deque front stringstream max_element min_element insert count make_tuple
const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
const int Mod = 1000000000 + 0;

void dijkstra(const Graph& g, int s, vector<Edge::weight_t>& dist, vector<int>& prev)
{
  const int V = g.size();
  const Edge::weight_t INF = INT_MAX;
  prev.assign(V, -1);
  dist.assign(V, INF);
  dist[s] = 0;
  priority_queue<Edge> pq;
  for (pq.push(Edge(-2, s, 0)); !pq.empty(); pq.pop()){
    Edge c = pq.top();
    if (prev[c.to] != -1) continue;
    prev[c.to] = c.from;
    dist[c.to] = c.w;
    for (const auto& e : g[c.to]){
      pq.push(Edge(e.from, e.to, e.w + c.w));
    }
  }
}

int main()
{
  int V, E, r;
  V = in(), E = in(), r = in();
  Graph g(V);
  for (int i = 0; i < E; i++){
    int s, t, d;
    s = in(), t = in(), d = in();
    g[s].emplace_back(s, t, d);
  }
  vector<Edge::weight_t> ws;
  vector<int> prev;

  dijkstra(g, r, ws, prev);
  show(ws, [](int v){
      if (v == INT_MAX) cout << "INF";
      else cout << v;
  }, "\n");
  return 0;
}


#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007

using namespace std;
typedef pair<int,int> pii;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#define ps(arr) \
    debug("size %ld: ", arr.size()); \
    for(auto e: arr) cout << e << " "; \
    cout << endl;
#else
#define debug(fmt, ...)
#define ps(arr)
#endif

int main(void) {
    string str;
    cin >> str;
    stack<char> stack;
    for(int i = 0; i < str.length(); i++) {
        char ch = str[i];
        switch(ch) {
            case 'S':
                stack.push('S');
                break;
            case 'T':
                if((!stack.empty()) && stack.top() == 'S') {
                    stack.pop();
                } else {
                    stack.push('T');
                }
                break;
            default:
                break;
        }
        debug("size: %ld\n", stack.size());
    }
    cout << stack.size() << endl;
    return 0;
}

#include <iostream>
#include <cstring>
#include <stack>
using namespace std;

stack<char> stacky;

int solve(string X, int N, int ans) {
      for(int i=0; i<N; i++) {
            if(X[i] == 'S') stacky.push('S');
            else {      // encounter 't'
                  if(!stacky.empty()) stacky.pop();
                  else ans++;
            }
      }
      ans += stacky.size();
      return ans;
}

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

      string X;
      cin >> X;
      int N = X.size();

      cout << solve(X, N, 0) << endl;
}


#include<stdio.h>
#include<algorithm>
using namespace std;
int a[200000];
int main()
{
	int i,n,flag=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
	  scanf("%d",&a[i]);
	}
	sort(a,a+n);
	for(i=0;i<n-1;i++)
	{
	   if(a[i]==a[i+1])
	   {
	      flag=1;
	      break;
	   }
	}
	if(flag==1)
	{
		printf("NO\n");
	}
	else
	{
		printf("YES\n");
	}
	return 0;
 }

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

int main() {

	ll n; cin >> n;
	map<ll, ll> mp;
	for (int i = 0; i < n; i++) {
		ll a; cin >> a;
		mp[a]++;
	}
	ll cnt = 0;
	for (auto u : mp) {
		if (1 < u.second) cnt++;
	}
	string ans = "YES";
	if (1 <= cnt) ans = "NO";
	cout << ans << endl;
    return 0;
}


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 998244353

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

// x^{-1}
ll mod_inv(ll x) { return mod_pow(x, MOD - 2); }

vector<ll> fact;
vector<ll> fact_inv;

void init_fact(int n) {
  fact.resize(n + 1);
  fact_inv.resize(n + 1);
  fact[0] = fact_inv[0] = 1;
  for (int i = 0; i < n; ++i) {
    fact[i + 1] = fact[i] * (i + 1) % MOD;
    fact_inv[i + 1] = fact_inv[i] * mod_inv(i + 1) % MOD;
  }
}

ll nCr(ll n, ll r) {
  if (n < r || n < 0 || r < 0) return 0;
  return fact[n] * fact_inv[r] % MOD * fact_inv[n - r] % MOD;
}

ll nPr(ll n, ll r) { return nCr(n, r) * fact[r] % MOD; }

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  init_fact(n);
  ll ans = 0;
  for (int i = 0; i <= k; ++i) {
    ll res = nCr(n - 1, n - 1 - i);
    res = (res * m) % MOD;
    res = (res * mod_pow(m - 1, n - 1 - i)) % MOD;
    ans = (ans + res) % MOD;
  }
  cout << ans << endl;
  return 0;
}

using namespace std;
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops")
#include<iostream>
#include<algorithm>
#include<ctime>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#include<numeric>
#include<queue>
#include<deque>
#include<cfloat>
#include<functional>
#include<tuple>
#include<math.h>
#include<bitset>
#include<stack>
#include<set>
#include<random>
#include<stdlib.h>
#define rip(i,n) for(ll i=0;i<n;i++)
#define Rip(i,n) for(ll i=1;i<n;i++)
#define all(V) V.begin(),V.end()
#define ll long long
#define ld long double
#define MOD 1000000007
#define mod MOD
#define sec setprecision
constexpr double eps = 1e-9;
constexpr double PI = 3.141592653589793238462643383279;
ll gcd(ll a, ll b) {
	if (a % b == 0)	return(b);
	else return(gcd(b, a % b));
}
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void cominit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll 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;
	}
}
vector<ll> soinnsuubunnkai(ll n) {
	vector<ll>a;
	while (n % 2 == 0) {
		a.push_back(2);
		n /= 2;
	}
	ll f = 3;
	while (f * f <= n) {
		if (n % f == 0) {
			a.push_back(f);
			n /= f;
		}
		else f += 2;
	}
	if (n != 1)
		a.push_back(n);
	return(a);
}
long long com(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
ll pow(ll a, ll b) {
	a = a % mod;
	if (b == 0)return(1);
	else if (b % 2 == 0)return(pow((a * a) % mod, b / 2));
	else return(a * (pow(a, b - 1)));
}
void solve() {
}
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (max(a, b) >= c && min(a, b) <= c)cout << "Yes" << endl;
	else cout << "No" << endl;
}


#include <bits/stdc++.h>

using namespace std;

const int lim = 4e4, Nmax = 505;
typedef long long ll;

int i, j;
ll a[Nmax][Nmax];
vector<int> primes;
bool used[lim+2];

void run_primes()
{
    int i;
    for(i=2; i<=lim; ++i)
        if(!used[i])
        {
            primes.push_back(i);
            for(j=i*i; j<=lim; j+=i) used[j] = 1;
        }
}

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

    run_primes();

    int n, N;
    cin >> N;
    n = N + ((N&1)^1);

    for(i=0; i<n; ++i)
        for(j=0; j<n; ++j)
            if(!((i+j)&1)) a[i][j] = (ll) primes[(i+j)/2] * primes[(i-j)/2 + n + 1];

    for(i=0; i<n; ++i)
        for(j=0; j<n; ++j)
            if((i+j)&1)
            {
                if(j && j<n-1) a[i][j] = a[i][j-1] * a[i][j+1] + 1;
                    else a[i][j] = a[i-1][j] * a[i+1][j] + 1;
            }

    for(i=0; i<N; ++i)
        for(j=0; j<N; ++j)
            cout << a[i][j] << " \n"[j==N-1];

    return 0;
}

#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
using namespace std;
int p = 998244353;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define rep(i,n) for(long long i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define V vector
#define Endl endl
#define veb vector<bool>
#define sq(a) (a)*(a)
#define rev(s) reverse(s.begin(),s.end())
#define end_program(s) cout << s <<endl;return 0
int kai_size = 500001;
vel kai(kai_size, 1);
vel ink(kai_size, 1);
vel dist;
int RE() {
	vel v(3, 2);
	return v.at(4);
}
int ru(int a, int r) {
	if (r == 0) { return 1; }
	int ans = ru(a, r / 2);
	ans *= ans; ans %= p;
	if (r % 2 == 1) { ans *= a; }
	return ans % p;
}
int inv(int a) {
	return ru(a, p - 2);
}
void make_kai() {
	rep(i, kai_size-1) { kai[i + 1] = (kai[i] * (i + 1)) % p; }
	rep(i, kai_size) { ink[i] = inv(kai[i]); }
}
int com(int n, int r) {
	if (r < 0 || n < r) { return 0; }
	int ans = kai[n] * ink[r];
	ans %= p; ans *= ink[n - r]; ans %= p;
	return ans;
}
vel dis(int mid1, vvel &way) {
	int n = way.size();
	vel dist(n, -1); dist[mid1] = 0;
	queue<int> q;
	q.push(mid1);
	while (!q.empty()) {
		int st = q.front(); q.pop();
		rep(i, way[st].size()) {
			int to = way[st][i];
			if (dist[to] == -1) {
				dist[to] = dist[st] + 1;
				q.push(to);
			}
		}
	}
	return dist;
}
pin most_far(int now, int n, vvel &way) {
	vel dist1 = dis(now, way);
	pin ans = mkp(-1, 0);
	rep(i, n) {
		if (dist1[i] > ans.first) { ans = mkp(dist1[i], i); }
	}
	return ans;
}

int per(int a, int b) {
	int ans = a % b;
	if (ans < 0) { ans += b; }
	return ans;
}
vel uni(vel &v) {
	sor(v);
	vel ans(1, v[0]);
	for (int i = 1; i < v.size(); i++) {
		if (v[i] != v[i-1]) { ans.push_back(v[i]); }
	}
	v = ans;
	return v;
}
int s_gcd(int a, int b) {
	if (b == 0) { return a; }
	return s_gcd(b, a%b);
}
int gcd(int a, int b) {
	if (a < b) { swap(a, b); }
	return s_gcd(a, b);
}
bool is_prime(int i) {
	for (int j = 2; j*j <= i; j++) {
		if (i%j == 0) { return false; }
	}
	return true;
}
int get(int i, int j, vvel &ans) {
	int n = ans.size();
	if (i < 0 || n <= i || j < 0 || n <= j) { return 1; }
	return ans[i][j];
}
int lcm(int a, int b) {
	return a * b / gcd(a, b);
}
int solve(int a, int b) {
	if (a < b) { swap(a, b); }
	if (b == 1) { return 1; }
	return a % b;
}
signed main() {
	int n; cin >> n;
	vel prime(0);
	int mod = 510;
	for (int i = 1000; i < 10000; i++) {
		if (is_prime(i)) { prime.push_back(i); }
	}
	vvel ans(n, vel(n,1));
	rep(i, n) {
		rep(j, n) {
			if ((i + j) % 2 == 0) {
				int x = (i + j) / 2;
				int y = per((i - j) / 2, mod);
				ans[i][j] = prime[x] * prime[y];
			}
		}
	}
	rep(i, n) {
		rep(j, n) {
			if ((i + j) % 2 == 1) {
				j--;
				int x = (i + j) / 2;
				int y = per((i - j) / 2, mod);
				ans[i][j+1] = prime[x] * prime[y];
				j += 2;
				x = (i + j) / 2;
				y = per((i - j) / 2, mod);
				ans[i][j-1] *= prime[x] * prime[y];
				j--;
				ans[i][j]++;
			}
			cout << ans[i][j];
			if (j == n - 1) { cout << endl; }
			else { cout << " "; }
		}
	}
	return 0;
}


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

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

  if (a!=b) {
    cout << max(a,b)*2-1 << endl;
  }
  else
    cout << a*2 << endl;
}

#include <bits/stdc++.h>
#include <vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;
using Field=vector<vector<int>>;

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

int main(){
    int a,b;
    cin>>a>>b;
    vector<int> s(3);
    s[0]=a+a-1;
    s[1]=b+b-1;
    s[2]=a+b;
    int ans=0;
    rep(i,3){
        ans=max(ans,s[i]);
    }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int N, X;
ll B[MAX_N], L[MAX_N], R[MAX_N];
int idx[MAX_N];
int fid[MAX_N];
ll RS[MAX_N], LS[MAX_N];

bool ok(ll m) {
	int q = m / X;
	int r = m % X;
	rep(i, 0, N) {
		ll tmp = 0;
		if(r == 0) {
			tmp += RS[q];
			tmp += LS[N] - LS[q];
		}
		else {
			if(B[i] > r) tmp += L[i] * (r - B[i]);
			else tmp += R[i] * (r - B[i]);

			if(fid[i] < q) {
				tmp -= R[i] * (X - B[i]);
				tmp += RS[q + 1];
				tmp += LS[N] - LS[q + 1];
			}
			else {
				tmp -= -L[i] * B[i];
				tmp += RS[q];
				tmp += LS[N] - LS[q];
			}
		}
		if(tmp >= 0) {
			return true;
		}
	}
	return false;
}

void solve() {
	cin >> N >> X;
	rep(i, 0, N) {
		cin >> B[i] >> L[i] >> R[i];
		idx[i] = i;
	}
	sort(idx, idx + N, [](int i, int j){
			return R[i] * (X - B[i]) + L[i] * B[i] > R[j] * (X - B[j]) + L[j] * B[j];
			});
	// rep(i, 0, N) {
	// 	debug(R[i] * (X - B[i]) - L[i] * B[i], B[i], L[i], R[i]);
	// }
	// debug(vi(idx, idx + N));
	rep(i, 0, N) {
		int at = idx[i];
		fid[at] = i;
		RS[i + 1] = RS[i] + R[at] * (X - B[at]);
		LS[i + 1] = LS[i] - L[at] * B[at];
	}

	ll lv = -1, rv = 1ll * N * X;
	while(rv - lv > 1) {
		ll m = (lv + rv) / 2;
		if(ok(m)) rv = m;
		else lv = m;
	}
	cout << rv << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif
	solve();
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k) for(int i=(j); i<=(k); i++)
#define FFOR(i, j, k) for(int i=(j); i<(k); i++)
#define DFOR(i, j, k) for(int i=(j); i>=(k); i--)
#define bug(x) cerr<<#x<<" = "<<(x)<<'\n'
#define pb push_back
#define mp make_pair
#define bit(s, i) (((s)>>(i))&1LL)
#define mask(i) ((1LL<<(i)))
#define builtin_popcount __builtin_popcountll
#define __builtin_popcount __builtin_popcountll
using ll=long long; using ld=long double;
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); const ld pi=acos(0)*2;
template <typename T> inline void read(T &x){char c; bool nega=0; while((!isdigit(c=getchar()))&&(c!='-')); if(c=='-'){nega=1; c=getchar();} x=c-48; while(isdigit(c=getchar())) x=x*10+c-48; if(nega) x=-x;}
template <typename T> inline void writep(T x){if(x>9) writep(x/10); putchar(x%10+48);}
template <typename T> inline void write(T x){if(x<0){ putchar('-'); x=-x;} writep(x);}
template <typename T> inline void writeln(T x){write(x); putchar('\n');}
template <typename CT, typename T> inline void reset_container(CT &c, int sz, T v){c.resize(sz); for(auto &x: c) x=v;}
#define taskname "C"
int n;
ll x;
ll start;
class subject{
public:
    ll b, l, u, w;
    void input(){
        read(b);
        read(l);
        read(u);
        start+=b*l;
        w=(x-b)*u+b*l;
    }
    ll cost(ll x){
        if(x<=b*l){
            return (x-1)/l+1;
        }
        else{
            x-=b*l;
            return b+(x-1)/u+1;
        }
    }
} s[100001];
ll f[100001];
int get(int i){
    int res=n;
    int low=0, high=n-1, mid;
    while(low<=high){
        mid=(low+high)/2;
        ll sum=f[mid];
        if(mid<i) sum+=s[i].w;
        if(sum>=start){
            res=mid;
            high=mid-1;
        }
        else low=mid+1;
    }
    return res;
}
int main(){
    #ifdef Aria
        if(fopen(taskname".in", "r"))
            freopen(taskname".in", "r", stdin);
    #endif // Aria
    read(n);
    read(x);
    FOR(i, 1, n) s[i].input();
    sort(s+1, s+n+1, [](subject A, subject B){
        return A.w>B.w;
    });
    ll ans=x*n;
    FOR(i, 1, n) f[i]=f[i-1]+s[i].w;
    FOR(i, 1, n){
        int j=get(i);
        ll res=x*j;
        if(j>i) res-=x;
        ll now=start-f[j];
        if(j>i) now+=s[i].w;
        if(now>0) ans=min(ans, res+s[i].cost(now));
        else ans=min(ans, res);
    }
    writeln(ans);
}


#include <cstdio>
#include <cstring>
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
typedef long long ll;
const int maxN=200+5;
int T;
int N;
ll A[maxN];
ll base[64];
char S[maxN];
void ins(ll x) {
	for(int i=62;~i;--i) if(x>>i&1) {
		if(base[i]) x^=base[i];
		else {
			for(int j=i+1;j<63;++j) if(base[j]>>i&1) {
				base[j]^=x;
			}
			for(int j=i-1;~j;--j) if(x>>j&1) {
				x^=base[j];
			}
			base[i]=x;
			break;
		}
	}
}
bool sol() {
	memset(base,0,sizeof(base));
	for(int i=N;i>=1;--i) {
		if(S[i]=='0') {
			ins(A[i]);
		}
		else {
			for(int j=62;~j;--j) if(A[i]>>j&1) {
				if(!base[j]) return 1;
				A[i]^=base[j];
			}
		}
	}
	return 0;
}
int main() {
	scanf("%d",&T);
	for(int kase=1;kase<=T;++kase) {
		scanf("%d",&N);
		for(int i=1;i<=N;++i) scanf("%lld",&A[i]);
		scanf("%s",S+1);
		printf("%d\n",sol());
	}
	return 0;
}

#include<bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define rep(i,n) for(int i = 0;  i < n ; ++i)
#define REP(i,a,b) for(int i = a ; i <= b ; ++i)
#define filei freopen("input.txt", "r", stdin);
#define fileo freopen("output.txt", "w", stdout);
#define gooi cout<<"Case #"<<i+1<<" :";
#define s(n) scanf("%d",&n)
#define rev(i,n) for(int i = n ; i >= 0 ; --i)
#define REV(i,a,b) for(int i = a ; i >= b ; --i)
#define miN(a,b) (((a)<(b))?(a):(b))
#define sc(n) scanf("%c",&n)
#define tr(c,i) for(typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define INF 1000000000
#define pii pair<long long int,long long int>
#define pb(a) push_back(a)
#define F first
#define S second
typedef long long ll;
using namespace std;
void pre(){}
void solve(){
    ll n;cin>>n;
    ll arr[n];
    for(int i=0;i<n;i++){
        cin>>arr[n-i-1];
    }
    string s;cin>>s;
    set<ll,greater<ll>>basis;
    reverse(s.begin(),s.end());
    for(int i=0;i<n;i++){
        for(auto j:basis){
            arr[i]=min(arr[i],arr[i]^j);
        }
        if(arr[i]==0){
            continue;
        }
        if( s[i]=='0' )
            basis.insert(arr[i]);
        if( s[i]=='1' ){
            cout<<1<<"\n";
            return;
        }
    }
    cout<<0<<"\n";
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    pre();
    long long int num = 1;
    cin>>num;
    for(long long int i=0;i<num;i++){
       	solve();
    }
}


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

int main(){
while(1){
int sina[1000],n,m,sum=0;
scanf("%d%d",&n,&m);
if(n==0&&m==0)return 0;
for(int i=0;i<n;i++){
scanf("%d",&sina[i]);
sum+=sina[i];
}
sort(sina,sina+n);
for(int i=n-m;i>=0;i-=m){
sum-=sina[i];
}
printf("%d\n",sum);
}
}

#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <boost/tokenizer.hpp>
#include <boost/lexical_cast.hpp>
#include <vector>
#include <list>

using namespace std;
using namespace boost;

int main(int argc, char* argv[])
{
	using sprtr = char_separator<char>;
	using tknzr = tokenizer<sprtr>;
	sprtr sep(" ", "", keep_empty_tokens);

	int f, mf, mo;

	string line;
	while(1) {

		int n, m;
		{
			getline(cin, line);
			tknzr tkns(line, sep);
			auto it = tkns.begin();
			n = lexical_cast<int>(*it++);
			m = lexical_cast<int>(*it);
		}

		if( n == 0 && m == 0 ) {
			break;
		}

		list<int> ps;
		{
			getline(cin, line);
			tknzr tkns(line, sep);
			for( auto p : tkns ) {
				//cout << p << endl;
				ps.push_back(lexical_cast<int>(p));
			}
		}

		ps.sort(greater<int>());

		int div = n / m;
		int mod = n % m;

		int sum = 0;
		auto it = ps.begin();
		for( int i = 0; i < div; i++ ) {
			for( int j = 0; j < m; j++ ) {
				auto p = *it++;
				if( j == m-1 ) continue;
				sum += p;
			}
		}

		if( mod ) {
			for( int i = 0; i < mod; i++ ) {
				auto p = *it++;
				sum += p;
			}
		}

		cout << sum << endl;

		ps.clear();

	}

    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};
vector<long long> enum_divisors(long long N) {
    vector<long long> res;
    for (long long i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            // 重複しないならば i の相方である N/i も push
            if (N/i != i) res.push_back(N/i);
        }
    }
    // 小さい順に並び替える
    sort(res.begin(), res.end());
    reverse(all(res));
    return res;
}

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

    const auto &res = enum_divisors(M);
    for (int i = 0; i < res.size(); ++i){
        if(res[i]<= (M/N)){
            cout<<res[i]<<endl;
            return 0;
        }
    }

    return 0;

}

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

int main()
{
  int n, k;
  cin >> n >> k;
  unordered_set<int> s;
  for(int i = 0; i < k; i++) {
    int d;
    cin >> d;
    s.insert(d);
  }
  while(true) {
    int temp = n;
    bool ok = true;
    while(temp) {
      int digit = temp % 10;
      if(s.count(digit)) {
        ok = false;
        break;
      }
      temp /= 10;
    }
    if(ok) break;
    n++;
  }
  cout << n;
}


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

typedef long long ll;

const int Maxn = 6005;
const int Maxm = 2005;

int n, mod;
int dp[Maxn][Maxm];

int main()
{
    scanf("%d %d", &n, &mod);
    dp[0][0] = 1;
    for (int i = 1; i <= 3 * n; i++)
        for (int j = 0; j <= n; j++) {
            dp[i][j] = (dp[i][j] + dp[i - 1][j]) % mod;
            if (i >= 2 && j >= 1)
                dp[i][j] = (dp[i][j] + ll(dp[i - 2][j - 1]) * (i - 1)) % mod;
            if (i >= 3 && j >= 1)
                dp[i][j] = (dp[i][j] + ll(dp[i - 3][j - 1]) * (i - 1) % mod * (i - 2)) % mod;
        }
    int res = 0;
    for (int j = 0; j <= n; j++)
        res = (res + dp[3 * n][j]) % mod;
    printf("%d\n", res);
    return 0;
}

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

const int MOD = 1e9 + 7;
const int MAXS = 1 << 16;

int main() {
	int N, X, Y, Z;
	cin >> N >> X >> Y >> Z;

	int xyz = (1 << (X + Y + Z - 1)) | (1 << (Y + Z - 1)) | (1 << (Z - 1));
	int mask = (1 << (X + Y + Z)) - 1;
	int mask2 = mask >> 1;

	int dp[2][MAXS];
	int idx = 0, _idx;
	dp[idx][0] = 1;
	for (int k = 0; k < N; ++k) {
		_idx = idx;
		idx ^= 1;
		memset(dp[idx], 0, sizeof(dp[idx]));
		for (int i = 0; i <= mask2; ++i) {
			if (dp[_idx][i] > 0) {
				for (int j = 1; j <= 10; j++) {
					int _i = ((i << j) | (1 << (j-1)));
					if ((_i&xyz) != xyz) (dp[idx][_i&mask2] += dp[_idx][i]) %= MOD;
				}
			}
		}
	}
	long res = 1;
	for (int i = 0; i < N; ++i) (res *= 10) %= MOD;
	for (int i = 0; i <= mask2; ++i) (res -= dp[idx][i]) %= MOD;

	cout << (res + MOD) % MOD << endl;

	return 0;
}


#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define lf else if

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

const int N=5e6+19;

int D,c,L,a,b,top;
int coe[2][50];
ll val[20],ans;
pair<ll,ll> A[N],B[N];

ll Pow(ll a,int b){
	ll res=1;
	for (;b;b>>=1,a=a*a) if (b&1) res=res*a;
	return res;
}
void dfs_1(int x,ll v,ll coef){
	if (x==top/2){
		A[++a]=mp(v,coef);
		return;
	}
	For(i,-9,10){
		dfs_1(x+1,v+i*val[x],coef*coe[x==0][i+10]);
	}
}
void dfs_2(int x,ll v,ll coef){
	if (x==top){
		B[++b]=mp(v,coef);
		return;
	}
	For(i,-9,10){
		dfs_2(x+1,v+i*val[x],coef*coe[x==0][i+10]);
	}
}
void Main(){
	a=0,b=0;
	top=L/2;
	For(i,0,L) val[i]=Pow(10,L-1-i)-Pow(10,i);
	if (L%2==0){
		dfs_1(0,0,1);
		dfs_2(top/2,0,1);
	} else{
		dfs_1(0,0,L==1?1:10);
		dfs_2(top/2,0,L==1?1:1);
	}
	sort(A+1,A+a+1);
	sort(B+1,B+b+1);
	c=b;
	for (int la=1,ra;la<=a;la=ra+1){
		ll tmp=A[la].se;
		for (ra=la;ra+1<=a&&A[ra+1].fi==A[ra].fi;ra++) tmp+=A[ra+1].se;
		for (;c>=1&&A[la].fi+B[c].fi>D;c--);
		for (;c>=1&&A[la].fi+B[c].fi==D;c--) ans+=tmp*B[c].se;
	}
}

int main(){
	For(a,0,10) For(b,0,10) coe[0][a-b+10]++;
	For(a,1,10) For(b,1,10) coe[1][a-b+10]++;
	D=IN();
	for (L=1;L<=18;L++) Main();
	cout<<ans<<endl;
}

#include<bits/stdc++.h>

using namespace std;

#define int long long

int n, pw10[19], nDig, ans;

bool ok(int a, int b, int mod) { return ( ( (a % mod) + mod) % mod) == ( ( (b % mod) + mod) % mod); }

int bt(int pos, int d) {
    int ret = 0;
    if(pos == nDig / 2 + 1) {
        return (d == 0) * (nDig % 2 ? 10 : 1);
    }
    for (int sub = -9; sub < 10; ++ sub) {
        if( ok(d, sub * 9 * pw10[pos - 1], 9 * pw10[pos]) ) {
            d -= sub * (pw10[nDig - pos] - pw10[pos - 1]);
            int temp = 10 - abs(sub);
            if(pos == 1) temp --;
            ret += bt(pos + 1, d) * temp;
            d += sub * (pw10[nDig - pos] - pw10[pos - 1]);
        }
    }
    return ret;
}

signed main () {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;

    pw10[0] = 1; for (int i = 1; i < 19; ++i) pw10[i] = 10 * pw10[i - 1];
    for (int i = 1; i <= 18; ++i) nDig = i, ans += bt(1, n);

    cout << ans;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
// #define DEBUGGING

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename Head, typename... Tail> const Head& var_min(const Head &head, const Tail&... tail) { return min(head, var_min(tail...)); }
template <typename Head, typename... Tail> const Head& var_max(const Head &head, const Tail&... tail) { return max(head, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }

namespace __init {

struct InitIO {
    InitIO() {
        cin.tie(0);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
#include "../debug.cpp"
#else
#define DEBUG(...) 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

VV<ll> edges;

pair<ll, bool> dfs(ll now, V<ll> &depth, ll d) {
    PLL ret(1, true);
    depth[now] = d;
    for(ll nxt : edges[now]) {
        if(depth[nxt] != -1) {
            ll d1 = depth[nxt];
            ll d2 = depth[now];
            if((d1 % 2) == (d2 % 2)) ret.second = false;
        } else {
            auto tmp = dfs(nxt, depth, d + 1);
            ll t1;
            bool t2;
            tie(t1, t2) = tmp;
            ret.first += t1;
            ret.second &= t2;
        }
    }
    return ret;
}

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

    edges.resize(N);
    for(ll i = 0; i < M; i++) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }

    V<ll> depth(N, -1);
    V<pair<ll, bool>> subg;
    ll tcnt = 0, lcnt = 0, ocnt = 0;
    for(ll i = 0; i < N; i++) {
        if(depth[i] != -1) continue;
        auto ret = dfs(i, depth, 0);
        ll s;
        bool tree;
        tie(s, tree) = ret;
        if(s == 1) {
            ocnt++;
        } else {
            subg.emplace_back(s, tree);
            (tree ? tcnt : lcnt)++;
        }
    }

    ll ans = 0;
    for(const auto &ele : subg) {
        ll n;
        bool t;
        tie(n, t) = ele;
        ans += tcnt + lcnt;
        ans += (ll)(t) * tcnt;
        ans += n * ocnt;
    }

    DEBUG(ans);

    ans += N * ocnt;

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<int,ii> eg;
typedef vector<eg> el;
typedef vector<ii> vii;
typedef vector<vii> al;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
vvi g;
int cs[512][512][4];
const int MN = 17;
const int SH = 8;
int am[MN][MN];
int n;
const int MSK = 1<<15;
const int HL = (1<<SH)-1;
void pre() {
	memset(cs,0,sizeof(cs));
	for(int fm=0;fm<=HL;fm++) {
		for(int sm=0;sm<=HL;sm++) {
			for(int id=0;id<4;id++) {
				ll a = fm,b = sm;
				if(id&2) {
					a <<= SH;
				}
				if(id&1) {
					b <<= SH;
				}
				for(int i=0;i<n;i++) {
					if(!((1<<i)&a)) continue;
					for(int j=0;j<n;j++) {
						if(!((1<<j)&b)) continue;
						cs[fm][sm][id] += am[i][j];
					}
				}
			}
		}
	}
}
ll calc(int a, int b) {
	ll res = 0;
	for(int i=0;i<4;i++) {
		int fm=a,sm = b;
		if(i&2) {
			fm >>= SH;
		} else {fm &= HL;}
		if(i&1) {
			sm >>= SH;
		} else {sm &= HL;}
		res += cs[fm][sm][i];
	}
	return res;
}
ll dp[1<<MN][MN];
int main() {
	int m;
	scanf("%d %d",&n,&m);
	memset(am,0,sizeof(am));
	for(int i=0;i<1<<MN;i++) {
		for(int j=0;j<MN;j++) {
			dp[i][j] = 1e12;
		}
	}
	g.assign(n,vi());
	for(int i=0;i<m;i++) {
		int a,b,c;
		scanf("%d %d %d",&a,&b,&c);
		a--;b--;
		am[a][b] = am[b][a] = c;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	pre();
	dp[1][0] = 0;
	for(int i=0;i<(1<<n);i++) {
		for(int j=0;j<n;j++) {
			for(int k=0;k<g[j].size();k++) {
				int u = g[j][k];
				dp[i|(1<<u)][u] = min(dp[i|(1<<u)][u],dp[i][j]+calc(i&(~(1<<j)),1<<u));
			}
			int mm = 1<<n;
			int msk = ((1<<n)-1)&(~i);
			while(1) {
				mm--;
				mm &= msk;
				if(mm <= 0) break;
				dp[mm|i][j] = min(dp[mm|i][j],dp[i][j]+calc(i&(~(1<<j)),mm));
			}
		}
	}
	printf("%lld\n",dp[(1<<n)-1][n-1]);
}