#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>
#include <string>

using namespace std;

int H,W;
char f[51][51];
bool reach[51][51] = {0};
int vx[4] = {1,0,-1,0};
int vy[4] = {0,1,0,-1};
int white = 0;
int check = -1;

struct corr{
    int x;
    int y;
    int d;
};

queue<corr> Q;

int bfs()
{
    while (!(Q.empty())){
        corr now = Q.front();
        Q.pop();
        int nowx = now.x;
        int nowy = now.y;
        int nowd = now.d;

        if (nowx == H-1 && nowy == W-1){
            check = nowd;
            break;
        }
        else {
            for (int i = 0;i < 4;i++){
                corr next;
                next.x = nowx+vx[i];
                next.y = nowy+vy[i];
                next.d = nowd+1;
                if (0 <= next.x && next.x < H && 0 <= next.y && next.y < W && f[next.x][next.y] == '.' && reach[next.x][next.y] == 0){
                    reach[next.x][next.y] = 1;
                    Q.push(next);
                }
            }
        }
    }
    if (check == -1){
        return -1;
    }
    else {
        return check;
    }
}

int main()
{
    cin >> H >> W;
    for (int i = 0;i < H;i++){
        for (int j = 0;j < W;j++){
            cin >> f[i][j];
            if (f[i][j] == '.'){
                white++;
            }
        }
    }

    corr start = {0,0,0};
    Q.push(start);
    reach[0][0] = 1;

    if (bfs() == -1){
        cout << -1 << endl;
    }
    else {
        cout << white - 1 - bfs() << endl;
    }
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair
 P2;
#define pu push
#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 POSR(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,m;
vector
vec;
int p[200005],q[200005],c[200005];
vector
edge[600105];
int dist[600105];
bool used[600105];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		scanf("%d%d%d",&p[i],&q[i],&c[i]);
		vec.pb(mp(p[i],c[i]));
		vec.pb(mp(q[i],c[i]));
	}
	SORT(vec); ERASE(vec);
	for(int i=0;i<vec.size();i++){
		int v = vec[i].fi;
		int ty = vec[i].sc;
		edge[v+500050].pb(mp(i,1));
		edge[i].pb(mp(v+500050,1));
	}
	for(int i=0;i<m;i++){
		int A = POSL(vec,mp(p[i],c[i]));
		int B = POSL(vec,mp(q[i],c[i]));
		edge[A].pb(mp(B,0));
		edge[B].pb(mp(A,0));
	}
	fill(dist,dist+600105,INF);
	dist[500051] = 0;
	deque<int>deq;
	deq.pb(500051);
	while(deq.size()){
		int q = deq.front(); deq.pop_front();
		if(used[q]) continue;
		used[q] = 1;
		for(int i=0;i<edge[q].size();i++){
			if(used[edge[q][i].fi]) continue;
			if(dist[edge[q][i].fi] > dist[q]+edge[q][i].sc){
			    dist[edge[q][i].fi] = dist[q]+edge[q][i].sc;
    			if(edge[q][i].sc == 0){
    				deq.push_front(edge[q][i].fi);
    			}
    			else{
    				deq.push_back(edge[q][i].fi);
    			}
			}
		}
	}
	if(dist[500050+n] == INF) cout << -1 << endl;
	else cout << (2+dist[500050+n])/2-1 << endl;
}


#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
#define mod 998244353
#define inv2 499122177
#define M 1000020
using namespace std;
namespace IO{
	int Top=0; char SS[20];
	void write(int x){
		if(!x){putchar('0');return;} if(x<0) x=-x,putchar('-');
		while(x) SS[++Top]=x%10,x/=10;
		while(Top) putchar(SS[Top]+'0'),--Top;
	}
	int read(){
		int nm=0,fh=1; char cw=getchar();
		for(;!isdigit(cw);cw=getchar()) if(cw=='-') fh=-fh;
		for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0');
		return nm*fh;
	}
}using namespace IO;
int mul(int x,int y){return (LL)x*(LL)y%mod;}
int add(int x,int y){return (x+y>=mod)?x+y-mod:x+y;}
int mus(int x,int y){return (x-y<0)?x-y+mod:x-y;}
int qpow(int x,int sq){
	int res=1;
	for(;sq;sq>>=1,x=mul(x,x)) if(sq&1) res=mul(res,x);
	return res;
}
int n,m,fac[M],ifac[M],ans;
int C(int tot,int tk){return mul(fac[tot],mul(ifac[tot-tk],ifac[tk]));}
int main(){
	n=read(),m=read(),fac[0]=1; if(n>m) swap(n,m);
	for(int i=1;i<=n+m;i++) fac[i]=mul(fac[i-1],i); ifac[n+m]=qpow(fac[n+m],mod-2);
	for(int i=n+m;i;i--) ifac[i-1]=mul(ifac[i],i);
	for(int i=1;i<=n;i++) ans=add(ans,mul(C(i<<1,i),C(n+m-(i<<1),n-i)));
	write(add(mul(ans,mul(inv2,qpow(C(n+m,m),mod-2))),m)),putchar('\n'); return 0;
}

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(_,v.size())cout<<" "<<v[_];cout<<endl;
#define show2d(v) rep(_,v.size()){rep(__,v[_].size())cout<<" "<<v[_][__];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
// typedef tuple<int,int,int> tp;
// typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 1e18+10 : 1e9+10;
// int dx[]={0,1,0,-1,1,1,-1,-1};
// int dy[]={1,0,-1,0,1,-1,1,-1};//RDLU
int dx[]={-1,-1,0,0,1,1};
int dy[]={-1,0,-1,1,0,1};//RDLU
//nCr mod m
#define MOD 998244353
#define M 1000100
vector<ll> fact;
bool h=false;
void init(){
	h=true;
	fact=vector<ll>(M);
	fact[0]=fact[1]=1;
	loop(i,2,M)fact[i]=fact[i-1]*i%MOD;
}
// a^b mod MOD
ll powmod(ll a,ll b,ll m=MOD){
	ll out=1;
	ll p=a%m;
	while(b){
		if(b&1)out=out*p%m;
		p=p*p%m;
		b>>=1;
	}
	return out;
}
//nCr
ll nCr(ll n,ll r,ll m=MOD){
	if(!h)init();
	if(n<0||r<0||n<r)return 1;//??????
	ll out=fact[n]*powmod(fact[r]*fact[n-r]%m,m-2,m)%m;
	return out;
}
int main(){
	ll n,m;
	cin>>n>>m;
	if(n>m)swap(n,m);
	ll out=m*nCr(n+m,n)%MOD;
	rep(i,n)(out+=nCr(2*i+m-n,i)*nCr(2*n-1-2*i,n-i)%MOD)%=MOD;
	cout<<out*powmod(nCr(n+m,n),MOD-2)%MOD<<endl;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
#include <stack>
#include <cctype>
#include <cmath>
#include <bitset>

using namespace std;

/* typedef */
typedef long long ll;

/* constant */
const int INF = 1 << 30;
const int NIL = -1;
const int MAX = 100000;
const int mod = 1000000007;
const double pi = 3.141592653589;

/* global variables */
vector<int> parent(MAX), prenum(MAX), lowest(MAX);
vector< vector<int> > Adj(MAX);
vector<bool> visited(MAX, false);
int N;
int timer;

/* function */
void dfs(int cur, int prev);
void art_points();

/* main */
int main() {
    int m;
    cin >> N >> m;
    for (int i = 0; i < m; i++) {
        int v, u;
        cin >> v >> u;
        Adj[v].push_back(u);
        Adj[u].push_back(v);
    }

    art_points();

}

void dfs(int cur, int prev) {
    // after visited node cur
    prenum[cur] = lowest[cur] = timer;
    timer++;
    visited[cur] = true;

    int next;
    for (int i = 0; i < Adj[cur].size(); i++) {
        next = Adj[cur][i];
        if ( !visited[next] ) {
            // before visiting next node
            parent[next] = cur;
            dfs(next, cur);
            // after visiting next node
            lowest[cur] = min(lowest[cur], lowest[next]);
        }
        else if (next != prev) {
            // Edge(cur, next) is Back-Edge
            lowest[cur] = min(lowest[cur], prenum[next]);
        }
    }
}

void art_points() {
    timer = 1;
    // calculate lowest
    dfs(0, -1); // 0 == root

    set<int> ap;
    int child_of_root = 0;
    for (int i = 1; i < N; i++) {
        int p = parent[i];
        if (p == 0) child_of_root++;
        else if (prenum[p] <= lowest[i]) ap.insert(p);
    }
    if (child_of_root >= 2) ap.insert(0);
    for (auto it = ap.begin(); it != ap.end(); it++) {
        cout << *it << '\n';
    }
}

#include "bits/stdc++.h"

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

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

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

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

class ConnectNodeInfo{
	vector<vector<pair<ll,ll>>> graph;
public:
	ConnectNodeInfo(int node_num){
		graph.resize(node_num);
	}
	void AddNonDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
		graph[v].emplace_back(u,w);
	}
	void AddDirectionalConnection(ll u,ll v,ll w){
		graph[u].emplace_back(v,w);
	}
	vector<pair<ll,ll>>& operator[](ll index){
		return graph[index];
	}
	size_t size(){return graph.size();}
};

class RootedNode{
public:
	vector<ll> parent;
	ll depth,dist;
	RootedNode():depth(0),dist(0){}
};

class RootedTree{
	int parent_size;
	vector<int> pre,low;
	int pre_count{0};

	void DFS(ConnectNodeInfo& connection,ll child,ll parent,ll dep,ll dist){
		pre[child] = low[child] = pre_count++;

		node[child].parent[0] = parent;
		node[child].depth = dep;
		node[child].dist = dist;

		bool isArticulation = false;
		int ct = 0;

		for(int i = 0;i < connection[child].size();i++){
			ll next_child = connection[child][i].first;
			if(pre[next_child]<0){
				ct++;
				DFS(connection,next_child,child,dep+1,dist+connection[child][i].second);
				low[child] = min(low[next_child],low[child]);
				if (~parent && pre[child] <= low[next_child]) isArticulation = true;
				if (pre[child]<low[next_child]) bridge.emplace_back(min(child,next_child),max(child,next_child));
			}
			else if(next_child != parent){
				low[child] = min(low[child],pre[next_child]);
			}
		}

		if(parent==-1 && ct>1) isArticulation = true;
		if(isArticulation) articulation.push_back(child);
	}
public:
	vector<RootedNode> node;
	vector<pair<ll,ll>> bridge;
	vector<ll> articulation;

	RootedTree(ConnectNodeInfo& connection){
		auto connection_size = connection.size();
		parent_size = 1;
		while((1LL<<parent_size)<connection_size) parent_size++;

		node.resize(connection_size);
		pre.resize(connection_size,-1);
		low.resize(connection_size);
		for(auto& x:node) x.parent.resize(parent_size,-1);
		DFS(connection,0,-1,0,0);
		for(int k=0;k<parent_size-1;k++){
			for(int v=0,ev=connection_size;v<ev;v++){
				if(node[v].parent[k] < 0) node[v].parent[k+1] = -1;
				else node[v].parent[k+1] = node[node[v].parent[k]].parent[k];
			}
		}
	}
	ll FindLCA(ll u,ll v){
		if(node[u].depth > node[v].depth) swap(u,v);
		for(int k=0;k<parent_size;k++){
			if((node[v].depth - node[u].depth) & (1LL<<k)){
				v = node[v].parent[k];
			}
		}
		if(u==v) return u;
		for(int k=parent_size-1;k>=0;k--){
			if(node[u].parent[k] != node[v].parent[k]){
				u = node[u].parent[k];
				v = node[v].parent[k];
			}
		}
		return node[u].parent[0];
	}
};

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

	int N=in(),M=in();
	ConnectNodeInfo connect(N);
	REP(i,M){
		int u=in(),v=in();
		connect.AddNonDirectionalConnection(u,v,1);
	}
	RootedTree tree(connect);
	sort(ALL(tree.articulation));
	for(auto& x:tree.articulation){
		out(x);
	}
	return 0;
}


#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repr(i,a,n) for(int i=a;i>=n;i--)
#define INF 999999999
#define INF_M 2147483647
#define pb(a) push_back(a)

using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef vector<pii> VP;

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

int main() {
    string s1,s2;
    cin >> s1 >> s2;

    int dp[1010][1010];
    rep(i,0,s1.size()+1) dp[i][0] = i;
    rep(j,0,s2.size()+1) dp[0][j] = j;

    rep(i,0,s1.size()) {
        rep(j,0,s2.size()) {
            dp[i+1][j+1] = min(dp[i][j+1], dp[i+1][j]) + 1;
            dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j] + (s1[i] != s2[j]));
        }
    }

    cout << dp[s1.size()][s2.size()] << endl;
    return 0;
}

#include <cstdio>
#include <algorithm>

using namespace std;

const int MAXN=1007;
char s1[MAXN];
char s2[MAXN];
int dp[MAXN][MAXN];

int main(){
    scanf("%s",s1+1);
    scanf("%s",s2+1);
    for(int i=1;s1[i];i++) dp[0][i]=i;
    for(int i=1;s2[i];i++) dp[i][0]=i;

    // puts(s1+1);
    // puts(s2+1);

    int i=1,j=1;
    for(;s2[i];i++){
        for(j=1;s1[j];j++){
            int temp=(s1[j]==s2[i]?dp[i-1][j-1]:dp[i-1][j-1]+1);
            dp[i][j]=min(min(temp,dp[i][j-1]+1),dp[i-1][j]+1);
        }
    }

    printf("%d\n",dp[i-1][j-1]);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1000000000;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define rep(i,n) REP(i, 0, n)
typedef pair<double, string> P;
const double EPS = 1.0e9;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    while(cin >> N && N){
        vector<P> L;
        vector<double> F(9);
        string s;
        rep(i, N){
            cin >> s;
            rep(j, 9) cin >> F[j];
            double time = F[1] + F[2] + F[3];
            double money = 0.0;
            rep(i, F[8]){
                time += F[4] + F[5];
                money += F[6] * F[7];
            }
            money -= F[0];
            L.push_back(P(money / time, s));
        }
        sort(L.begin(), L.end(), [](P a, P b){
            return a.first == b.first ? a.second < b.second : a.first > b.first;
        });
        for(P k : L) cout << k.second << endl;
        cout << "#" << endl;
    }
    return 0;
}

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
//datatypes
	#define ll 			long long
	#define vi 			vector<int>
	#define vll 		vector<ll>
	#define si 			set<int>
	#define vii 		vector<ii>
	#define ii 			pair<int,int>
	#define vpll		vector<pll>
	#define pii 		pair<int,int>
	#define pll 		pair<ll, ll>
	#define mii 		map<int,int>
	#define ord_set		tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
	#define M 			1000000007
	#define narak 		998244353
	#define pi 			acos(-1)
	#define inf 		2147483647
	#define infl 		9223372036854775807
	#define infd 		1.7e308
	#define invd 		1.7e-308
	#define sz(x) 		(ll)x.size()
	#define fr 			first
	#define sc 			second
	#define pb 			push_back
	#define mkp 		make_pair
	#define rep(i,a,b) 	for(int i=a; i<b; ++i)
	#define rep0(i,a)	for(int i=0; i<a; ++i)
	#define rep1(i,a)	for(int i=1; i<=a; ++i)
	#define trav(a) 	for(auto &x:a)
	#define test 		cout<<"hello\n";
	#define all(x) 		(x).begin(),(x).end()
	#define mem(x,val)	memset(x, val, sizeof(x))
	#define sa(x) 		std::sort(all(x))
	#define endl 		'\n'
	#define __lcm(m,n) 	m*(n/__gcd(m,n))
	#define fill(a,n) 	for(int xxx=0;xxx<n;++xxx) cin>>(a)[xxx]
	#define maxa(v)		*(max_element(all(v)))
	#define mina(v)		*(min_element(all(v))
	#define inputFile 	freopen("input.txt", "r", stdin);
	#define outputFile	freopen("output.txt", "w", stdout);
	#define disp(a) 	trav(a) cout<<x<<" "; cout<<endl;
  	//#define int long long

template<typename T, typename U> static inline void amin(T &x, U y){ if(y<x) x=y; }
template<typename T, typename U> static inline void amax(T &x, U y){ if(x<y) x=y; }
template<typename T,typename U> std::ostream& operator<<(std::ostream& out, std::pair<T,U> a) {out<<a.fr<<" "<<a.sc; return out;}
template<typename T,typename U> std::istream& operator>>(std::istream& in, std::pair<T,U> &a) {in>>a.fr>>a.sc; return in;}
template<typename T> static inline void sd(vector<T> &x) {sort(all(x), greater<T>()) ; }
const int N=301;
int n;
double dp[N][N][N]={};

signed solve()
{
	cin>>n;
    int cnt[4]={};
    rep(i,0,n){int x;
    	cin>>x;
    	cnt[x]++;
    }
    dp[0][0][0]=0;
    for(int three=0; three<=n; ++three)
    {
    	for(int two=0; two<=n; ++two)
    	{
    		for(int one=0; one<=n; ++one)
    		{
    			int zero = n -(three+two+one);
    			if(zero == n)
    				continue;
    			if(three+two+one > n)
    				continue;
    			double val = 1;
    			if(three>0)
    			val += (1.0*three/n)*(dp[three-1][two+1][one]);
    			if(two>0)
    			val += (1.0*two/n)*(dp[three][two-1][one+1]);
    			if(one>0)
    			val += (1.0*one/n)*(dp[three][two][one-1]);
    			val /= (1.0-1.0*zero/n);
    			dp[three][two][one] = val;
    		}
    	}
    }
    cout<<fixed<<setprecision(12)<<dp[cnt[3]][cnt[2]][cnt[1]];
	return 0;
}

signed main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t=1;
	//cin>>t;
	while(t--)
	{

		solve();

	}
	//cout << "\nTime : " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=100100;
inline long long read(){
    long long x=0,f=1;char c=getchar();
    while(c>'9'||c<'0'){if(c=='-') f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return f*x;
}
int val[maxn],tmp[maxn],n,num[maxn],m,x,ans[maxn];
long long k;double last[maxn];
int main(){
    n=read();
    for(register int i=1;i<=n;i++)
        val[i]=read(),tmp[i]=i,ans[i]=i;
    m=read();k=read()*1ll;
    for(register int i=1;i<=m;i++)
        x=read(),swap(tmp[x],tmp[x+1]);
    for(;k;k>>=1){
        if(k&1){
            for(register int i=1;i<=n;i++)
                num[i]=ans[tmp[i]];
            for(register int i=1;i<=n;i++)
                ans[i]=num[i];
        }
        for(register int i=1;i<=n;i++)
            num[i]=tmp[tmp[i]];
        for(register int i=1;i<=n;i++)
            tmp[i]=num[i];
    }
    for(register int i=1;i<=n;i++)
        last[i]=val[ans[i]]-val[ans[i]-1];
    for(register int i=1;i<=n;i++)
        printf("%.1lf\n",last[i]+=last[i-1]);
}

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=5e5;
int x[N],opt[N],id[N],p[N],vis[N],n,m,tmp[N];
long long s[N],K;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",x+i),id[i]=i;
    for(int i=n;i>=1;i--)x[i]-=x[i-1];
    scanf("%d%lld",&m,&K);
    for(int i=1;i<=m;i++)scanf("%d",opt+i),swap(id[opt[i]],id[opt[i]+1]);
    for(int i=1;i<=n;i++)p[id[i]]=i;
    for(int i=1;i<=n;i++)
    {
        if(vis[i])continue;
        int u=i,len=0;tmp[0]=u;vis[u]=1;
        while(p[u]!=i)u=p[u],tmp[++len]=u,vis[u]=1;
        ++len;
        for(int i=0;i<len;i++)p[tmp[i]]=tmp[(i+K)%len];
    }
    for(int i=1;i<=n;i++)id[p[i]]=i;

    for(int i=1;i<=n;i++)s[i]=s[i-1]+x[id[i]],printf("%.1lf\n",(double)s[i]);
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    ll n,x;
    cin >> n >> x;
    vector<ll>a(n);
    for(ll i=0;i<n;i++){
        cin >> a[i];
    }
    ll ans=0;
    for(ll i=1;i<n;i++){
        if(a[i-1]+a[i]>x){
            ll k=(a[i]+a[i-1]-x);
            ans+=k;
            a[i]-=k;
            if(a[i]<0) a[i]=0;
        }
    }
    cout << ans << endl;
}

#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<cmath>
#include<algorithm>
using namespace std;

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

int main(){
    int n,x,a;
    while(~scanf("%d%d%d",&n,&x,&a)){
        ll ans=0;
        if(a>x)
            ans+=a-x,a=x;
        while(--n){
            int b;
            scanf("%d",&b);
            if(a+b>x)
                ans+=a+b-x,a=x-a;
            else
                a=b;
        }
        printf("%lld\n",ans);
    }
    return 0;
}


#include<iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include<map>
#include<cstring>
#include<iomanip>
#include <string>
#include <vector>
#include<unordered_map>
#include<unordered_set>
using namespace std;

typedef long long unsigned llu;
typedef long double ld;
#define ll long long
#define PI 3.14159265358979323846
#define For(i, a, b) for (int i = a, sz = (int)b; i < sz; i++)
#define rFor(i, a, b, c) for (int i = (a); i >= (b); i -= (c))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fill(a, b) memset(a, b, sizeof(a))
#define IO ios_base::sync_with_stdio(false), cin.tie(0),cout.tie(0)
const int mod = 1000000007;
const ll inf = 1000000000009;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) { return a*b/gcd(a,b);}

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

int main()
{
	IO;
	int n{};
	cin>>n;
	vector<int>v(n);
	For(i,0,n)cin>>v[i];
	sort(all(v));
	if(n==3)cout<<"1\n";
	else
	{
		ll ans{};
		For(i,0,n)
		{
			For(j,0,i)
			{
				For(k,0,j)
				{
					if((v[k] != v[j] && v[i] != v[j]) && v[k]+v[j]>v[i])ans++;
				}
			}
		}
		cout<<ans<<'\n';
	}
	//system("pause");
	return 0;
}

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <fstream>
#include <cmath>
#include <limits>
#include <chrono>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
#include <cassert>
#pragma warning (disable: 4996)
using namespace std;

using ll = long long;
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

ll ll_gcd(ll a, ll b) {
    if (a < b) return ll_gcd(b, a);
    ll r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

struct UnionFind {
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

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

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

ll merge_cnt(vector<ll>& a) {
    int n = a.size();
    if (n <= 1) { return 0; }

    ll cnt = 0;
    vector<ll> b(a.begin(), a.begin() + n / 2);
    vector<ll> c(a.begin() + n / 2, a.end());

    cnt += merge_cnt(b);
    cnt += merge_cnt(c);

    int ai = 0, bi = 0, ci = 0;
    while (ai < n) {
        if (bi < b.size() && (ci == c.size() || b[bi] <= c[ci])) {
            a[ai++] = b[bi++];
        }
        else {
            cnt += n / 2 - bi;
            a[ai++] = c[ci++];
        }
    }
    return cnt;
}

int main() {
    ll n;
    cin >> n;
    cout << 0 << endl;
    string s;
    cin >> s;
    if (s == "Vacant")return 0;
    else {
        ll ok = 0;
        ll ng = n;
        while (true) {
            ll mid = (ok + ng) / 2;
            cout << mid << endl;
            string t;
            cin >> t;
            if (t == "Vacant")return 0;
            if (!((t == s) ^ (ok % 2 == mid % 2))) {
                ok = mid;
                s = t;
            }
            else ng = mid;
        }
    }
}


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

using namespace std;

void print(string word,vector<string>& output)
{
  int a,b;
  cin >> a >> b;
  output.push_back(word.substr(a,b-a+1));
}

void reverse(string& word)
{
  int a,b;
  cin >> a >> b;
  string temp = word.substr(a,b-a+1);
  reverse(temp.begin(),temp.end());
  word.replace(a,b-a+1,temp);
}

void replace(string& word)
{
  int a,b;
  string change;
  cin >> a >> b >> change;
  word.replace(a,b-a+1,change);
}

int main(int argc, char* argv[])
{
  string word,command;
  vector<string> output;
  int count;
  cin >> word >> count;
  for(int i=0;i<count;i++)
  {
    cin >> command;
    if(command=="print") print(word,output);
    else if(command=="reverse") reverse(word);
    else if(command=="replace") replace(word);
  }
  for(string n:output)
  {
    cout << n << endl;
  }
}

#include <bits/stdc++.h>

using namespace std;

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

    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        string op;
        int b, e;
        cin >> op;
        cin >> b >> e;
        if(op == "print"){
            cout << s.substr(b, e-b+1) << endl;
        }else{
            string x, y, z;
            x = s.substr(0, b);
            z = s.substr(e+1, s.size()-(e+1));
            if(op == "replace"){
                string r;
                cin >> y;
            }else{
                y = s.substr(b, e-b+1);
                reverse(y.begin(), y.end());
            }
            s = x + y + z;
        }
    }
}


#include <iostream>
#include <cctype>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <complex>
#include <cstring>
#include <set>
using namespace std;
#define loop(i,a,b) for(int i=a; i<b; i++)
#define rep(i,a) loop(i,0,a)

int input[1111][3];
int res[1111];

int main(){
    int a,b,c;
    while(cin>>a>>b>>c && a){
        int n;
        cin>>n;
        rep(i,n){
            rep(j,3){
                cin >> input[i][j];
            }
            cin>>res[i];
        }

        bool ok[1111]={};
        bool bad[1111]={};
        while(1){
            bool fine = true;
            rep(i,n){
                int a=0,b=0;
                int x,y,z;
                tie(x,y,z)=tie(input[i][0],input[i][1],input[i][2]);
                for(int j : {x,y,z}){
                    if(ok[j])a++;
                    if(bad[j])b++;
                }
                if(res[i]){
                    if(a!=3){
                        ok[x]=ok[y]=ok[z]=true;
                        fine = false;
                    }
                }else{
                    if(a==2 && b!=1){
                        for(int j : {x,y,z}){
                            if(!ok[j])bad[j]=true;
                            fine = false;
                        }
                    }
                }
            }
            if(fine) break;
        }
        for(int i=1;i<=a+b+c;i++){
            if(ok[i] && !bad[i])cout<<1;
            else if(!ok[i] && bad[i])cout<<0;
            else cout<<2;
            cout<<endl;
        }
    }
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef  long long int ll;
typedef long double db;
#define pb push_back
#define mp make_pair
#define ub(v,val) upper_bound(v.begin(),v.end(),val)-v.begin()
#define lb(v,val) lower_bound(v.begin(),v.end(),val)-v.begin()
#define sortv(vec) sort(vec.begin(),vec.end())
#define rev(p) reverse(p.begin(),p.end());
#define v vector
#define PI 3.1415926535
#define len length()
#define repc(i,s,e) for(ll i=s;i<e;i++)
#define np(str) next_permutation(str.begin(),str.end())
#define fi first
#define se second
#define mset(a,val) memset(a,val,sizeof(a));
#define mt make_tuple
#define repr(i,n) for(i=n-1;i>=0;i--)
#define rep(i,n) for( i=0;i<n;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int M = 1e9 + 7;
ll INF = 1e7;
ll n, m;

int main() {
	// your code goes here
	IOS;

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll  i, j,  k, x, y,   N;
	char z;
	cin >> n;
	unordered_map<ll, v<ll>> u, d, l, r, u1, u2, r1, r2, l1, l2, d1, d2;
	rep(i, n) {
		cin >> x >> y >> z;
		if (z == 'U') {
			u[x].pb(y);
			u1[x - y].pb(x);
			u2[x + y].pb(x);

		}
		if (z == 'R') {
			r[y].pb(x);
			r1[(x - y)].pb(x);
			r2[x + y].pb(x);

		}
		if (z == 'D') {
			d[x].pb(y);
			d1[(x - y)].pb(x);
			d2[x + y].pb(x);

		}
		if (z == 'L') {
			l[y].pb(x);
			l1[(x - y)].pb(x);
			l2[x + y].pb(x);
		}
	}
	for (auto &dm : u) {
		sortv(dm.se);
	}
	for (auto &dm : u1) {
		sortv(dm.se);
	}
	for (auto &dm : u2) {
		sortv(dm.se);
	}
	for (auto &dm : r) {
		sortv(dm.se);
	}
	for (auto &dm : r1) {
		sortv(dm.se);
	}
	for (auto &dm : r2) {
		sortv(dm.se);
	}
	for (auto &dm : l) {
		sortv(dm.se);
	}
	for (auto &dm : l1) {
		sortv(dm.se);
	}
	for (auto &dm : l2) {
		sortv(dm.se);
	}
	for (auto &dm : d) {
		sortv(dm.se);
	}
	for (auto &dm : d1) {
		sortv(dm.se);
	}
	for (auto &dm : d2) {
		sortv(dm.se);
	}
	ll ans = INF;
	//u and d;

	for (auto dm : u) {
		x = dm.fi;
		for (auto dm2 : u[x]) {
			auto ind = upper_bound(d[x].begin(), d[x].end(), dm2);
			if (ind != d[x].end()) {
				ans = min(ans, (*ind - dm2) * 5);
			}

		}
	}
	//r and l
	for (auto dm : r) {
		y = dm.fi;
		for (auto dm2 : r[y]) {
			auto ind = upper_bound(l[y].begin(), l[y].end(), dm2);
			if (ind != l[y].end()) {
				ans = min(ans, (*ind - dm2) * 5);
			}

		}
	}
	//u and l
	for (auto dm : u1) {
		ll diff = dm.fi;
		for (auto dm2 : u1[diff]) {
			auto ind = upper_bound(l1[diff].begin(), l1[diff].end(), dm2);
			if (ind != l1[diff].end()) {
				ans = min(ans, (*ind - dm2) * 10);
			}
		}
	}
	//u and r
	for (auto dm : r2) {
		ll sum = dm.fi;

		for (auto dm2 : r2[sum]) {
			auto ind = upper_bound(u2[sum].begin(), u2[sum].end(), dm2);
			if (ind != u2[sum].end()) {
				ans = min(ans, (*ind - dm2) * 10);
			}
		}
	}
	//d and l
	for (auto dm : d2) {
		ll sum = dm.fi;

		for (auto dm2 : d2[sum]) {
			auto ind = upper_bound(l2[sum].begin(), l2[sum].end(), dm2);
			if (ind != l2[sum].end()) {
				ans = min(ans, (*ind - dm2) * 10);
			}
		}
	}
	//d and r
	for (auto dm : r1) {
		ll diff = dm.fi;

		for (auto dm2 : r1[diff]) {
			auto ind = upper_bound(d1[diff].begin(), d1[diff].end(), dm2);
			if (ind != d1[diff].end()) {
				ans = min(ans, (*ind - dm2) * 10);
			}
		}
	}
	if (ans == INF)
		cout << "SAFE";
	else cout << ans;

	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 P = pair<int,int>;

int main(){
	int a,b,c,k;
	cin >> a >> b >> c >> k;
	int mn = max(a,max(b,c));
	int ans = a + b + c - mn + pow(2,k) * mn;
	cout << ans << endl;
}

#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A[3];
    rep(i, 3) cin >> A[i];
    int K; cin >> K;
    sort(A, A + 3);
    rep(i, K) A[2] *= 2;
    cout << A[0] + A[1] + A[2] << endl;

    return 0;
}


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

int main(){
    int a, b;
    int ans = 0;
    cin >> a >> b;
    string s;
    string r_s = "";
    for (int num = a; num < b + 1; num ++){
        r_s = "";
        s = to_string(num);
        for (int i = 0; i < s.size(); i ++){
            r_s += s[s.size() - 1 - i];
        }
        if (s == r_s){
            ans += 1;
        }
    }
    cout << ans << endl;
}

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

static long Gcd(long m, long n)
{
	long temp;
	while (m % n != 0)
	{
		temp = n;
		n = m % n;
		m = temp;
	}
	return n;
}

int charToInt(char c){
    char zero_num = '0';
    return (int)c - (int)zero_num;
}

map< int, int > prime_factor(int n) {
  map< int, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

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

    int gcd = Gcd(A,B);

/*    vec_int factors;

    for(int i=1;i*i<=gcd;i++){
        if(gcd%i==0){
            factors.push_back(i);
            factors.push_back(gcd/i);
        }
    }
    sort(factors.begin(), factors.end());
    */

   map<int, int> pfs = prime_factor(gcd);

   cout<<pfs.size()+1<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1001000;
int n;
char s[N],t[N];
deque<int> deq;
int main(){
	cin>>n;
	scanf("%s%s",s+1,t+1);
	int he=0,ta=1,l=n+1,tag=0,ans=0;
	deq.push_back(n+1);
	for(int i=n;i;--i){
		int tmp=l;
		while(l&&(l>i||s[l]!=t[i])) --l;
		if(!l) return puts("-1")&0;
		if(tmp==l){
			while(!deq.empty()&&deq.back()-tag>=i) deq.pop_back();
			deq.push_back(i+tag);
		}
		else{
			++tag;
			if(l!=i) ans=max(ans,(int)deq.size()),deq.push_front(l+tag);
		}
	}
	cout<<ans<<endl;
	return 0;
}

#include <cstdio>
#include <cstdlib>
#include <cstring>
#define CLR(x) memset((x), false, sizeof(x))
const int MAXD = 12801;
const int MAXN = 81;
int  A[2][MAXN][MAXN];
bool   dp[MAXN][MAXN][MAXD];
int H, W;

int solve() {
  CLR(dp);
  dp[0][0][0] = true;
  dp[0][1][0] = true;
  dp[1][0][0] = true;
  for (int i = 1; i <= H; ++i) {
    for (int j = 1; j <= W; ++j) {
      for (int k = 0; k < MAXD; ++k) {
        int d = std::abs(A[0][i][j] - A[1][i][j]);
        int nk1 = k + d;
        if (nk1 < MAXD) {
          dp[i][j][k] |= dp[i-1][j][nk1] | dp[i][j-1][nk1];
        }
        int nk2 = std::abs(k - d);
        dp[i][j][k] |= dp[i-1][j][nk2] | dp[i][j-1][nk2];
      }
    }
  }
  for (int k = 0; k < MAXD; ++k) {
    if (dp[H][W][k]) {
      return k;
    }
  }
  return -1;
}

int main() {
  scanf(" %d%d", &H, &W);
  for (int k = 0; k < 2; ++k) {
    for (int i = 1; i <= H; ++i) {
      for (int j = 1; j <= W; ++j) {
        scanf("%d", &A[k][i][j]);
      }
    }
  }
  printf("%d\n", solve());
  return 0;
}


#include <bits/stdc++.h>
#define rep(i , n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
int main (){
    ll N, L[2]{};
    cin >> N;
    set <int> S;
    while (cin >> N) {
        if (!S.insert(N).second) {
            S.erase(N);
            if (N > L[0]){
                L[1] = L[0], L[0] = N;
            }
            else if(N > L[1]){
                L[1] = N;
            }
        }
    }
    cout << L[0] * L[1] << endl;
}

#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

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

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

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

string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v) {
    string res = "";
    for (size_t i = 0; i < N; i++) {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

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

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

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

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

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin >> n;
    unordered_map<long long, int> mp;
    for (int i = 0; i < n; i++) {
        int x; cin >> x;
        mp[x]++;
    }
    vector<long long> ans(2);
    for (auto p : mp) {
        for (int i = 0; i < 2; i++) {
            if(p.second < 2) break;
            if (p.first > ans[i]) {
                ans[i] =  p.first;
                p.second -= 2;
            }
        }
        sort(ans.begin(), ans.end());
        debug(ans);
    }
    cout << ans[0] * ans[1];
    return 0;
}


#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    int n;
    cin >> n;

    vector<ll> a(n);
    for(auto &x:a)cin >> x;

    int ans=-1;
    for(int i=0;i<30;i++){
        for(int j=0;j<n;j++){
            if(a[j]%2==1){
                ans=i;
                break;
            }
            a[j]=a[j]/2;
        }
        if(ans!=-1)break;
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
  int n, min_count;
  cin >> n;
  min_count = 200;

  for (int i=0; i<n; i++) {
    int a, count = 0;
    cin >> a;

    if (a % 2 == 1) {
      min_count = 0;
      break;
    }

    while (a % 2 == 0) {
      a /= 2;
      count += 1;
    }
    if (min_count > count)
      min_count = count;
  }

  cout << min_count << endl;
}


#include <iostream>
#include <algorithm>
#include<string>
#include<vector>
int main() {
	int ining;
	std::cin >> ining;
	std::string s;
	for (int i = 0; i < ining; ++i) {
		int co = 0;
		int ch = 0;
		int c = 0;
		while (std::cin >> s) {
			if (s == "OUT") {
				++co;
			}
			if (co == 3) {
				break;
			}
			if (s == "HIT") {
				++ch;
			}
			if (ch == 4) {
				--ch;
				++c;
			}
			if (s == "HOMERUN") {
				c += ch + 1;
				ch = 0;
			}
		}
		std::cout << c << std::endl;
	}
	}

#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define rp(a) while(a--)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int n;
	while(cin>>n,n){
		vector<int>in(n+1);
		rep(i,n)cin>>in[i+1];
		n++;
		loop(i,1,n)in[i]+=in[i-1];
		int ma=-1e9;
		rep(i,n)loop(j,i+1,n)ma=max(ma,in[j]-in[i]);
		cout<<ma<<endl;
	}
}


#include<iostream>
using namespace std;
int main()
{
  int a,b,c,d;
  cin>>a;
  cin>>b;
  cin>>c;
  cin>>d;
  if(a<=b){
    if(c<=d){
      cout<<a+c;
    }
    else{
      cout<<a+d;
    }
  }
  else{
    if(c<=d){
      cout<<b+c;
    }
    else{
      cout<<b+d;
    }
  }
}

#include <bits/stdc++.h>
#include <ctime>
#define rep(i,a,b) for(int i =a;i<b;i++)
using namespace std;
typedef unsigned long long ll;
inline int cine() {int a; return scanf("%d", &a) ? a : 1e9;}

void solve() {
    int train, bus, mine = 1e9, sum = 0 ;
    rep(i, 0, 2) {
        cin >> train;
        mine = min(mine, train);
    }
    sum += mine;
    mine = 1e9;
    rep(i, 0, 2) {
        cin >> bus;
        mine = min(mine, bus);
    }
    sum += mine;
    cout << sum;
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("i.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    solve();
#ifndef ONLINE_JUDGE
    cout << "\nTime Elapsed :" << 0.1 * clock() / CLOCKS_PER_SEC << "s\n";
#endif
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define inf 1000000000
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
#define meM(y,a) memset(y,a,sizeof y)
#define sC(a) scanf("%d",&a)
#define alL(a) a.begin(),a.end()
#define prinT(a,sz)  cout<<a[0];for(int i=1;i<sz;i++)cout<<" "<<a[i];cout<<endl
#define ranD srand(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int,int>pi;
typedef pair<ll,ll>pll;
//int fx[]={0,0,1,-1};
//int fy[]={1,-1,0,0};
//int gx[]={0,0,1,1,1,-1,-1,-1};
//int gy[]={1,-1,0,1,-1,0,1,-1};
const int N=100010;
int ara[N];
int main()
{
    IOS;
    int n,k;cin>>n>>k;
    for(int i=1;i<=n;i++)
        cin>>ara[i];
    int ans=inf;
    for(int i=k;i<=n;i++)
    {
        if(ara[i]>0&&ara[i-k+1]<0){
            int sum=ara[i]-ara[i-k+1];
            int f1=sum+ara[i];
            int f2=sum-ara[i-k+1];
//            cout<<i<<" "<<f1<<" "<<f2<<endl;
            ans=min(ans,min(f1,f2));
        }
        else
        {
            int sum;
            if(ara[i]<0)sum=abs(ara[i-k+1]);
            else sum=ara[i];
            ans=min(ans,sum);

        }
    }
    cout<<ans<<endl;
}

/*
8 7
-10 -4 -2 0 5 6 8 13

8 5
-15 -12 -8 -7 -4 -1 8 15
*/

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);
ll dx[8]={0,0,-1,1,-1,1,-1,1};
ll dy[8]={1,-1,0,0,1,1,-1,-1};
vector<vector<ll> > c(10,vector<ll>(10,0));

int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}

    ll N,K; cin>>N>>K;
    vector<ll> minus;
    vector<ll> plus;
    vector<ll> zero;
    rep(i,N){
        ll x; cin>>x;
        if(x<0) minus.pb(x);
        else if(x==0) zero.pb(x);
        else plus.pb(x);
    }
    ll m=sz(minus),p=sz(plus),need=K-sz(zero);
    minus.pb(0);
    plus.pb(0);
    sort(all(minus),greater<ll>());
    sort(all(plus));

    ll ans=INF;
    rep(i,min(need,m)+1){
        if(need-i > p) continue;
        ll X=-minus[i];
        ll Y=plus[need-i];

        chmin(ans,max(X,Y)+min(X,Y)*2);
    }
    cout<<ans<<endl;
}


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

int main () {
  long long N;
  cin >> N;
  long long M = 1;

  for (long long i = 2; i <= sqrt(N); i++) {
    if (N % i == 0){
      M = i;
    }
  }

  long long L = max(M,N/M);
  int count = 0;
  for (int i = 0; i < 11; i++) {
    count++;
    if (L / 10 == 0){
      cout << count << endl;
      return 0;
    }
    L /= 10;
  }
}

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const double PI = 3.1415926535897932;
const int MOD = 1e9 + 7;

vector<pair<ll, ll>> prime_factorize(ll n) {
  vector<pair<ll, ll>> res;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i != 0) continue;
    ll ex = 0;
    while (n % i == 0) {
      ++ex;
      n /= i;
    }
    res.push_back({i, ex});
  }
  if (n != 1) res.push_back({n, 1});
  return res;
}

//cin.tie(0);ios::sync_with_stdio(false);
int main() {
  ll n;
  cin >> n;
  if (n == 1) {
    cout << 1 << endl;
    return 0;
  }
  vector<ll> primes;
  for (auto v : prime_factorize(n)) {
    for (ll i = 0; i < v.second; i++) {
      primes.push_back(v.first);
    }
  }
  vector<ll> ans;
  ll tmp1, tmp2;
  for (int bit = 0; bit < 1 << primes.size(); bit++) {
    tmp1 = tmp2 = 1;
    for (int j = 0; j < primes.size(); j++) {
      if (bit & 1 << j) {
	tmp1 *= primes[j];
      } else {
	tmp2 *= primes[j];
      }
    }
    ans.push_back(max(to_string(tmp1).size(), to_string(tmp2).size()));
  }

  cout << *min_element(ans.begin(), ans.end()) << endl;
  return 0;
}


#include <stdio.h>
#include <stdbool.h>

int main(void)
{
	bool flag = true;
	int cnt = 0;
	int n;
	scanf("%d", &n);
	int x[n];
	for(int i = 0; i < n; i++){
		scanf("%d", &x[i]);
	}
	while(flag){
		flag = false;
		for(int i = n - 1; i >= 0; i--){
			if(x[i] < x[i - 1]){
				int temp = x[i];
				x[i] = x[i - 1];
				x[i - 1] = temp;
				cnt++;
				flag = true;
			}
		}
	}
	for(int i = 0; i < n - 1; i++){
		printf("%d ", x[i]);
	}
	printf("%d\n%d\n", x[n - 1], cnt);
	return 0;
}

#include <bits/stdc++.h>
#define rep(i , n) for (int i = 0; i < (int)(n); i++)
const int INF = 1<<29;
using namespace std;
using ll = long long;
int n, sum, y, a[105];
double g, t = 1e9;
int main(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		sum += a[i];
	}
	g = 1.0 * sum / n;
	for(int i = 0; i < n; i++) {
		if(abs(a[i] - g) < t){
			t = abs(a[i] - g);
			y = i;
		}
	}
	cout << y << endl;;
}


#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX 51000;
#define PI 3.14159265359
using namespace std;
typedef long long llong;
typedef long double ldouble;

using Graph = vector<vector<int>>;

int main(){
	int N, M, X, Y;
	cin >> N >> M >> X >> Y;
	int maxx = -101;
	int miny = 101;
	for(int i=0; i<N; ++i){
		int x;
		cin >> x;
		maxx = max(maxx, x);
	}
	for(int i=0; i<M; ++i){
		int y;
		cin >> y;
		miny = min(miny, y);
	}
	maxx = max(maxx, X);
	miny = min(miny, Y);
	if(maxx<miny) cout << "No War" << endl;
	else cout << "War" << endl;
}

#include <iostream>
#include <vector>

void printArray(std::vector<int> a) {
  int n = (int)a.size();
  for (int i = 0; i < n; i++) {
    std::cout << a[i] <<std::endl;
  }
}

int insertionSort(std::vector<int> &a, int g) {
  int cnt = 0, n = (int)a.size();
  for (int i = g; i < n; i++) {
    int v = a[i];
    int j = i - g;
    while (j >= 0 && a[j] > v) {
      a[j + g] = a[j];
      j = j - g;
      cnt++;
    }
    a[j + g] = v;
  }
  return cnt;
}

int shellSort(std::vector<int> &a) {
  std::vector<int> g;
  for (int i = 1; i <= (int)a.size(); i = i * 3 + 1) {
    g.push_back(i);
  }
  int m = (int)g.size();
  std::cout << m << std::endl;

  int cnt = 0;
  for (int i = m - 1; i >= 0; i--) {
    cnt += insertionSort(a, g[i]);

    std::cout << g[i];
    if (i > 0)
      std::cout << " ";
    else
      std::cout << std::endl;
  }

  return cnt;
}

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

  std::cout << shellSort(a) << std::endl;
  printArray(a);
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int INF = 1e9;

int main()
{
  int n = 0;
  fscanf(stdin, "%d", &n);
  vector<ll> rows(n + 5), cols(n + 5);
  for (int i = 0; i < n; ++i) {
    fscanf(stdin, "%lld %lld", &rows[i + 1], &cols[i + 1]);
  }
  vector<vector<ll> > dp(n + 5, vector<ll>(n + 5, 0));
  for (int l = 2; l <= n; ++l) {
    for (int i = 1; i <= n - l + 1; ++i) {
      int j = l + i - 1;
      dp[i][j] = std::numeric_limits<ll>::max();
      for (int k = i; k <= j - 1; ++k) {
        dp[i][j] = min(dp[i][j],
                       dp[i][k] + dp[k + 1][j] + rows[i] * cols[k] * cols[j]);
      }
    }
  }
  fprintf(stdout, "%lld\n", dp[1][n]);
  return 0;
}

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

typedef long long LL;

const int M=18,mod=1000000007;

int add(int a,int b,int p=mod){return a+b>=p?a+b-p:a+b;}
int sub(int a,int b,int p=mod){return a-b<0?a-b+p:a-b;}
int mul(int a,int b,int p=mod){return (LL)a*b%p;}
void sadd(int &a,int b,int p=mod){a=add(a,b,p);}
void ssub(int &a,int b,int p=mod){a=sub(a,b,p);}
void smul(int &a,int b,int p=mod){a=mul(a,b,p);}
int Power(int a,int k,int p=mod){int res=1;for (;k;k>>=1,smul(a,a,p)) if (k&1) smul(res,a,p);return res;}

int n,m,a[3];

void into(){
  scanf("%d%d%d%d",&n,&a[0],&a[1],&a[2]);
  a[1]+=a[0];m=max(a[2]+=a[1],10);
}

int dp[2][(1<<M)+9],old,now,ans;

void Get_dp(){
  old=1;now=0;
  dp[now][0]=1;
  for (int i=1;i<=n;++i){
	old^=1;now^=1;
	for (int g=0;g<1<<m;++g) dp[now][g]=0;
	for (int g=0;g<1<<m;++g)
	  for (int j=1;j<=10;++j){
		int t=(g&(1<<m-j)-1)<<j|1<<j-1;
		if (t>>a[0]-1&1&&t>>a[1]-1&1&&t>>a[2]-1&1) continue;
		sadd(dp[now][t],dp[old][g]);
	  }
  }
  for (int g=0;g<1<<m;++g) sadd(ans,dp[now][g]);
}

void work(){
  Get_dp();
}

void outo(){
  printf("%d\n",sub(Power(10,n),ans));
}

int main(){
  into();
  work();
  outo();
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=100010,mod=998244353;
const char str[2][10]={"First","Second"};
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline int read(){
	int x=0,f=0;char ch=getchar();
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}
int n,a[maxn];
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int main(){
	n=read();
	FOR(i,1,n) a[i]=read();
	int t=0;
	while(true){
		int cnt1=0,cnte=0;
		FOR(i,1,n){
			if(a[i]==1) cnt1++;
			if(a[i]%2==0) cnte++;
		}
		if(cnte!=n-1 || cnt1==1){puts(cnte%2?str[t]:str[t^1]);break;}
		FOR(i,1,n) if(a[i]%2!=0){a[i]--;break;}
		int g=0;
		FOR(i,1,n) g=gcd(g,a[i]);
		FOR(i,1,n) a[i]/=g;
		t^=1;
	}
}
// coming soon 2020.5.11

#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<cstdio>
typedef unsigned long long ull;
#define rep(i,a) for(int i=0;i<a;i++)
#define loop(i,a,b) for(int i=a;i<b;i++)
using namespace std;
const double eps = 1e-10;
const double pi = acos(-1);
const double inf = (int)1e8;

int main(void){
  string str;
  int base=0,point=0,out=0;
  int n;
  cin>>n;
  getline(cin,str);
  while(getline(cin,str)){
    if(str[0] == 'O'){
      out++;
      //cout<<out<<endl;
      if(out==3){
	n--;
	printf("%d\n",point);
	base=0,point=0,out=0;
	if(n==0)break;
      }
    }
    else if(str[1] == 'I'){
      base ++;
      if(base>3){
	base --;
	point ++;
      }
    }
    else if(str[1] == 'O'){
      point += base + 1;
      base = 0;
    }

  }
  return 0;
}


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

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

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

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

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

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

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

#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <numeric>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long int int64;

const int N = (int) 1e5 + 100;

vector <int> ch[N];
int k;

struct Ans
{
    vector <int> v;

    Ans() : v({0}) {}

    void eprint()
    {
        for (int i = 0; i < min(k + 1, (int) v.size()); i++)
            eprintf("[%d] %d, ", i, v[(int) v.size() - 1 - i]);
        eprintf("\n");
    }
};

Ans dp[N];

int merge(int a, int b)
{
    if ((int) dp[a].v.size() < (int) dp[b].v.size())
        swap(a, b);

    for (int i = 0; i < (int) dp[b].v.size(); i++)
        dp[a].v[(int) dp[a].v.size() - 1 - i] += dp[b].v[(int) dp[b].v.size() - 1 - i];

    return a;
}

int goUp(int a)
{
    dp[a].v.push_back(1);
    if ((int) dp[a].v.size() >= k + 1)
        dp[a].v.back() += dp[a].v[(int) dp[a].v.size() - k - 1];

    int i = 2;
    while (i <= (int) dp[a].v.size() && dp[a].v[(int) dp[a].v.size() - i] > dp[a].v.back())
    {
        dp[a].v[(int) dp[a].v.size() - i] = dp[a].v.back();
        i++;
    }

    return a;
}

int solve(int v)
{
    int cur = v;
    for (int to : ch[v])
    {
        int nx = solve(to);
        cur = merge(cur, nx);
    }
    //eprintf("(%d): ", v); dp[cur].eprint();
    if (v != 0)
        cur = goUp(cur);
    //eprintf("(%d'): ", v); dp[cur].eprint();
    return cur;
}

int a[N];

int main(int,  char **)
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

    int n;
    scanf("%d%d", &n, &k);

    for (int i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
        a[i]--;
    }

    for (int i = 1; i < n; i++)
        ch[a[i]].push_back(i);

    int id = solve(0);

    int ans = dp[id].v[max(0, (int) dp[id].v.size() - k - 1)];

    if (a[0] != 0)
        ans++;

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

	return 0;
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int meiro[110][110];
int cc;
int w,h;
int xx[]={1,-1,0,0};
int yy[]={0,0,1,-1};

void dfs(int x,int y){
	meiro[y][x]=-1;
	int i;
	for(i=0;i<4;i++){
		if(x+xx[i]<0||w<=x+xx[i]||y+yy[i]<0||h<=y+yy[i])continue;
		if(meiro[y+yy[i]][x+xx[i]]!=cc)continue;
		dfs(x+xx[i],y+yy[i]);
	}
}

int main() {
	int xs,ys,xg,yg,n,c,d,x,y;
	while(w=in(),h=in()){
		cin>>xs>>ys>>xg>>yg>>n;
		xs--;ys--;xg--;yg--;
		int i;
		memset(meiro,0,sizeof(meiro));
		for(i=0;i<n;i++){
			cin>>c>>d>>x>>y;
			x--;y--;
//cout<<c<<" "<<d<<" "<<x<<" "<<y<<endl;
			if(d==0){
				meiro[y][x]=meiro[y][x+1]=meiro[y][x+2]=meiro[y][x+3]=meiro[y+1][x]=meiro[y+1][x+1]=meiro[y+1][x+2]=meiro[y+1][x+3]=c;
			}else{
				meiro[y][x]=meiro[y][x+1]=meiro[y+1][x]=meiro[y+1][x+1]=meiro[y+2][x]=meiro[y+2][x+1]=meiro[y+3][x]=meiro[y+3][x+1]=c;
			}
		}
		if(meiro[ys][xs]==0){
			cout<<"NG\n";
			continue;
		}
		cc=meiro[ys][xs];
//cout<<"hoge\n";
		dfs(xs,ys);
//cout<<"piyo\n";
		if(meiro[yg][xg]==-1)cout<<"OK\n";
		else cout<<"NG\n";
	}
	return 0;
}

#include<bits/stdc++.h>
#define pf(x) x*x
using namespace std;
int n, d[2], col[2][360007];
vector<pair<int, int> >e[2];
int id(int a, int b) { return a * 2 * n + b; }
int check(int pos) { return pos >= 0 && pos < 2 * n; }
int dfs(int p, int a, int b)
{
	for (int i = 0, lim = e[p].size(); i < lim; i++)
	{
		int c = a + e[p][i].first, d = b + e[p][i].second;
		if (!check(c) || !check(d))continue;
		if (!col[p][id(c, d)])
		{
			col[p][id(c, d)] = -col[p][id(a, b)];
			dfs(p, c, d);
		}
	}
	return 0;
}
int main()
{
	cin >> n >> d[0] >> d[1];
	for (int p = 0; p <= 1; p++)
		for (int x = 0; x <= d[p]; x++)
		{
			int y = sqrt(d[p] - x * x);
			if (x * x + y * y != d[p])continue;
			e[p].push_back(make_pair(x, y));
			e[p].push_back(make_pair(-x, y));
			e[p].push_back(make_pair(x, -y));
			e[p].push_back(make_pair(-x, -y));
		}
	for (int i = 0; i < 2 * n; i++)
		for (int j = 0; j < 2 * n; j++)
			for (int p = 0; p <= 1; p++)
				if (!col[p][id(i, j)])
				{
					col[p][id(i, j)] = 1;
					dfs(p, i, j);
				}
	int now,haha;
	int tot = 0;
	for (int i = 0; i < 2 * n; i++)
		for (int j = 0; j < 2 * n; j++)
			if (col[0][id(i, j)] == 1 && col[1][id(i, j)] == 1)
			{
				printf("%d %d\n", i, j);
				if (++tot == n * n)return 0;
			}
	return 0;
}


#include<cstdio>
#include<algorithm>
#include<functional>

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

using namespace std;

int main(){
	for(int n,m;scanf("%d%d",&n,&m),n;){
		int p[1000];
		rep(i,n)	scanf("%d",p+i);

		sort(p,p+n,greater<int>());

		int total=0;
		rep(i,n) if((i+1)%m!=0) total+=p[i];
		printf("%d\n",total);
	}

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(ull i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define iter(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define riter(i,c) for(auto i=(c).rbegin(); i!=(c).rend(); ++i)
const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;
namespace std {
    template<typename T>ostream&operator<<(ostream&os, vector<T>const&v){
        iter(it,v) os<<*it<<(it+1==v.end()?"":",");
        return os;
    }
    template<typename T, typename U>ostream&operator<<(ostream&os,const pair<T,U>&p){
        return os << "[" << p.dirst << "," << p.second << "]";
    }
}

#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

int main(){
    int m, n;
    while(cin>>n>>m && m|n){
        vi p(n);
        int free = 0;
        int sum = 0;
        rep(i,n){
            cin >> p[i];
            sum += p[i];
        }
        sort(all(p));
        // テ」ツ??」ツ?暗」ツ?凝」ツつ?
        for(int i=n-m;i>=0;i-=m)free+=p[i];
        cout << sum - free << endl;
    }
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;

int main(){
	while(1){
		int n, m, k;
		int t[2][101][101];

		scanf(" %d %d", &n, &m);
		if(n==0) break;
		memset(t, -1, sizeof(t));

		for(int i=0; i<n; ++i){
			int a, b, time, cost;
			scanf(" %d %d %d %d", &a, &b, &cost, &time);
			t[0][a][b]=t[0][b][a]=cost;
			t[1][a][b]=t[1][b][a]=time;
		}

		scanf(" %d", &k);
		for(int i=0; i<k; ++i){
			int p, q, r;
			scanf(" %d %d %d", &p, &q, &r);
			long a[101]; //各駅までの最小値

			for(int j=0; j<=100; ++j) a[j]=50000000;

			//bfs
			queue<int> que;
			a[p]=0;
			que.push(p);
			while( !que.empty() ){
				int v=que.front();
				que.pop();
				for(int j=1; j<=m; ++j){
					if(t[r][v][j]>=0 && a[j]>t[r][v][j]+a[v]){
						a[j]=t[r][v][j]+a[v];
						que.push(j);
					}
				}
			}

			printf("%ld\n",a[q]);
		}
	}
}


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

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

	vector<int> ac(A);
	vector<int> bc(B);

	int minA = 1<<30, minB = 1<<30;
	rep(i, A) {
		cin >> ac.at(i);
		minA = min(minA, ac.at(i));
	}
	rep(j, B) {
		cin >> bc.at(j);
		minB = min(minB, bc.at(j));
	}

	int ans = minA + minB;

	rep(i, C) {
		int m;
		int tmp=0;
		cin >> m;
		tmp += ac.at(m-1);
		cin >> m;
		tmp += bc.at(m - 1);
		cin >> m;
		tmp -= m;
		ans = min(ans, tmp);
	}
	cout << ans << endl;
}

#include <iostream>
#include <algorithm>

using namespace std;

int main(){
  int A, B, M;
  cin >> A >> B >> M;
  int a[A], b[B], c[M];
  for (int i = 0; i < A; i++){
    cin >> a[i];
  }

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

  for (int i = 0; i < M; i++){
    int x, y;
    cin >> x >> y >> c[i];
    c[i] = a[x-1] + b[y-1] - c[i];
  }

  sort(a, a+A);
  sort(b, b+B);
  sort(c, c+M);

  if (a[0] + b[0] > c[0]){
    printf("%d\n", c[0]);
  }else{
    printf("%d\n", a[0] + b[0]);
  }

}


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

#define int ll
#define REP(i,n) for (int i = 0; i < (n); ++i)
#define FORE(i, s, n) for (int i = (s); i <= (int)(n); i++)

#define ALL(vec) (vec).begin(), (vec).end()
#define REVALL(vec) (vec).rbegin(), (vec).rend()

#define debug(x) cerr << #x << ": " << x << '\n'
#define hyphen() cerr << "--\n"

#define fst first
#define pb push_back

const int MOD = (int)1e9 + 7;

int bigger(int a, int b) {
    return a >= b ? a : b;
}

int smaller(int a, int b) {
    return a >= b ? b : a;
}

signed main() {
    int N;

    cin >> N;

    vector<int> As(N);
    vector<int> Bs(N);
    REP(i, N) {
        cin >> As.at(i) >> Bs.at(i);
    }

    // (priority, score, ind)
    vector<tuple<int, int, int>> sorted_for_a(N);
    vector<tuple<int, int, int>> sorted_for_b(N);
    REP(i, N) {
        int a = As.at(i);
        int b = Bs.at(i);
        int priority = a + b;
        tuple<int, int, int> ta = make_tuple(priority, a, i);
        tuple<int, int, int> tb = make_tuple(priority, b, i);

        sorted_for_a.pb(ta);
        sorted_for_b.pb(tb);
    }

    sort(REVALL(sorted_for_a));
    sort(REVALL(sorted_for_b));

    queue<tuple<int, int, int>> a_queue;
    for (auto a : sorted_for_a) {
        a_queue.push(a);
    }

    queue<tuple<int, int, int>> b_queue;
    for (auto b : sorted_for_b) {
        b_queue.push(b);
    }

    // それが食べられたことを表す配列
    vector<bool> eaten(N, false);

    // ここから作業開始
    int score_a = 0;
    int score_b = 0;

    tuple<int,int,int> ta;
    tuple<int,int,int> tb;

    while(!a_queue.empty() || !b_queue.empty()) {
        // Aのターン

        // 食べられていない料理が見つかるまで捨てる
        while(true) {
            if (a_queue.empty()) {
                break;
            }

            ta = a_queue.front();
            a_queue.pop();

            int& ind = get<2>(ta);
            if (!eaten.at(ind)) {
                break;
            }
        }

        if (a_queue.empty()) {
            break;
        }

        // Aが食べる処理
        int& a = get<1>(ta);
        int& ind_a = get<2>(ta);
        debug(a);
        debug(ind_a);

        score_a += a;
        debug(ind_a);
        eaten.at(ind_a) = true;

        // 食べられていない料理が見つかるまで捨てる
        while(true) {
            if (b_queue.empty()) {
                break;
            }

            tb = b_queue.front();
            b_queue.pop();

            int& ind = get<2>(tb);
            if (!eaten.at(ind)) {
                break;
            }
        }

        // Bが食べる処理
        // 後攻はもう食べるものが無い可能性がある
        if (b_queue.empty()) {
            break;
        }

        int& b = get<1>(tb);
        int& ind_b = get<2>(tb);
        debug(b);
        debug(ind_b);

        score_b += b;
        debug(ind_b);
        eaten.at(ind_b) = true;
    }

    cout << score_a - score_b << endl;
}

#include <bits/stdc++.h>

using namespace std;
#define all(a)a.begin(),a.end()
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod = int(1e9)+7;
using V = vector<ll>;
using P = pair<ll,ll>;

int main()
{
   ll n;cin >>n;
   V a(n),b(n);rep(i,n)cin >>a[i]>>b[i];
   vector<P> s(n);
   rep(i,n){
    ll k=a[i]+b[i];
        s[i]=make_pair(k,i);
   }
   sort(s.rbegin(),s.rend());
   ll takahasi=0,aoki=0;
   rep(i,n){
    ll key=s[i].second;
    if(i%2==0){
        takahasi+=a[key];
    }
    else {
        aoki+=b[key];
    }
   }
   cout << takahasi-aoki<< endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define loop(k) rep(author_is_masa,k)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const long long INF = 1e18+10;

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

signed main(){
	int a,b;
	cin>>a>>b;
	int ans=0;
	loop(2){
		if(a>b){
			ans+=a;
			a--;
		}else{
			ans+=b;
			b--;
		}
	}
	cout<<ans<<endl;

	return 0;
}

#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

int main() {
  int A, B; cin >> A >> B;
  if (A == B) cout << 2 * A << endl;
  else if (A > B) cout << 2 * A - 1 << endl;
  else cout << 2 * B - 1 << endl;
}


#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 1e5 + 7, M = 1e7, OO = 0x3f3f3f3f;
#define AC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin.sync_with_stdio(0);
int main()
{
int sx,sy,tx,ty,i,x,y;
scanf("%d %d %d %d",&sx,&sy,&tx,&ty);
x=tx-sx;
y=ty-sy;
for(i=0;i<x;++i){
    printf("R");
}
for(i=0;i<y;++i){
    printf("U");
}
for(i=0;i<x;++i){
    printf("L");
}
for(i=0;i<y;++i){
    printf("D");
}
printf("D");
for(i=0;i<x+1;++i){
    printf("R");
}
for(i=0;i<y+1;++i){
    printf("U");
}
printf("L");
printf("U");
for(i=0;i<x+1;++i){
    printf("L");
}
for(i=0;i<y+1;++i){
    printf("D");
}
printf("R");

    return 0;
}

#include"bits/stdc++.h"
#include<iostream>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
#define rep(i, c) for(int i = 0; i < (int)c; i++)
const ll inf = 1000000007;

int main() {
	int a, b,c;
	cin >> a >> b >> c;
	if (a != b) {
		if (a==c || b==c) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	else {
		if (a != c) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  cout << n / 3 << endl;
}

#include <stdio.h>

int
main(void)
{
	char line[80];
	int x;

	if (gets(line)) {
		if (sscanf(line, "%d", &x) == 1) {
			printf("%d\n", x*x*x);
		}
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define co(a) cout<<a<<endl
#define sz size()
#define bgn begin()
#define en end()
#define pb(a) push_back(a)
#define pop pop_back
#define V vector
#define P pair
#define V2(a,b,c) V<V<int>> a(b,V<int>(c))
#define V2a(a,b,c,d) V<V<int>> a(b,V<int>(c,d))
#define incin(a) int a; cin>>a
#define yuko(a) setprecision(a)
//#define min min<int>
//#define max max<int>
template<class T>
 void cou(vector<vector<T>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}
/*template<>
 void cou(vector<vector<char>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}*/
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 int lcm(int a,int b){
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }
 bool prime(int a){
   if(a<2)
     return false;
   else if(a==2)
     return true;
   else if(a%2==0)
     return false;
   double b=sqrt(a);
    for(int i=3;i<=b;i+=2){
      if(a%i==0){
        return false;
      }
    }
   return true;
 }
struct Union{
  vector<int> par;
  Union(int n){
	par= vector<int>(n, -1);
  }
  int find(int x){
    if(par[x]<0)
      return x;
    else
      return par[x]=find(par[x]);
  }
  bool same(int a,int b){
    return find(a)==find(b);
  }
  int Size(int a){
    return -par[find(a)];
  }
  void unite(int a,int b){
    a=find(a);
    b=find(b);
    if(a==b)
      return;
    if(Size(b)>Size(a))
      swap<int>(a,b);
    par[a]+=par[b];
    par[b]=a;
  }
};
int ketas(int a){
  string b=to_string(a);
  int c=0;
  fo(i,keta(a)){
    c+=b[i]-'0';
  }
  return c;
}
/*struct aa{
	vector<int> gt;
  aa(int n){
	gt= vector<int>(n, 1);
  }
	void c(V<int> d,int b){
	if(d[b]==0){
		gt[d[b]-1]++;
		gt[gt.sz-1]++;
	}
	else{
		gt[d[b]-1]++;
		c(d,d[d[b]]-1);
	}
}
void cok(int a){
	cout<<gt[a-1]<<endl;
	fo(i,a-1)
	cout<<gt[i]<<endl;
}
};
*/
signed main(){
	int a,b;
	cin>>a>>b;
	cout<<a+1-b<<endl;
}

#include <cstdio>
#include <cmath>
#define N 100010
#define ll long long
#define mem(x, a) memset(x, a, sizeof x)
#define mpy(x, y) memcpy(x, y, sizeof y)
#define fo(x, a, b) for (int x = (a); x <= (b); x++)
#define fd(x, a, b) for (int x = (a); x >= (b); x--)
using namespace std;
int n, st, coo[N], go_[N], tot = 0;
ll ans = 0, hav[N];

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

void dfs(int l, int r) {
	if (l > r) return;
	if (st < coo[l]) dfs(l, r - 1), go_[++tot] = r;
	else if (st > coo[r]) dfs(l + 1, r), go_[++tot] = l;
	else if (hav[l] >= hav[r]) hav[l] += hav[r], dfs(l, r - 1), go_[++tot] = r;
	else hav[r] += hav[l], dfs(l + 1, r), go_[++tot] = l;
}

int main()
{
//	freopen("home.in", "r", stdin);
//	freopen("home.out", "w", stdout);
	n = read(), st = read();
	fo(i, 1, n) coo[i] = read(), hav[i] = read();
	dfs(1, n);
	ans = abs(coo[go_[1]] - st);
	fo(i, 2, n) ans += abs(coo[go_[i]] - coo[go_[i - 1]]);
	printf("%lld\n", ans);
	return 0;
}


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

int main() {
  vector<int> x(3);
  rep(i, 3) cin >> x.at(i);
  int cnt = 0;
  rep(i, 3) rep(j, 3) {
    if(i == j) continue;
    else if(x.at(i) == x.at(j)) cnt++;
  }
  if(cnt == 2) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
//#define DEBUG
#ifdef DEBUG
#define DEBUG_PRINT(fm, ...) do{std::printf("%s:%d(%s)", __FILE__, __LINE__, __func__);std::cout << "DEBUG PRINT ";std::printf(fm, __VA_ARGS__);}while(0)
#define DEBUG_VAL(a, b) do{std::printf("%s:%d(%s)", __FILE__, __LINE__, __func__);std::cout <<"DEBUG VAL " << a << ":" << b << endl;}while(0)
#else
#define DEBUG_PRINT(...)do{}while(0);
#define DEBUG_VAL(a, b)do{}while(0);
#endif

using namespace std;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

int main(){
    int A, B, M;
    cin >> A >> B >> M;
    v1 a(A+1);
    v1 b(B+1);
    int ma = 1e6;
    int mb = 1e6;
    rep(i, A){
        int aa;
        cin >> aa;
        a[i+1] = aa;
        ma = min(ma, aa);
    }
    rep(i, B){
        int bb;
        cin >> bb;
        b[i+1] = bb;
        mb = min(mb, bb);
    }
    int ans = ma+mb;
    rep(i, M){
        int x, y, c;
        cin >> x >> y >> c;
        int value = a[x] + b[y] -c;
        ans = min(ans, value);
    }
    cout << ans << endl;
}


/*
    ????????°??§???????????¨????????????
*/

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <limits.h>
#include <float.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iterator>
#include <vector>
#include <map>
#include <utility>
#define LLU unsigned long long int
#define LL long long int
#define LD long double
using namespace std;
#define Lfmax DBL_MAX
#define LLUmax ULLONG_MAX
#define LLmax LLONG_MAX
#define dmax INT_MAX
#define vd vector<int>
#define vLL vector<long long int>
#define vLLU vector<unsigned long long int>
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define debug printf("asd\n")
#define debugd(a) printf("--%d\n",a)
#define debugdd(a,b) printf("--%d %d\n",a,b)
#define debugarr(a,b) for(int i=0 ; i<b ; i++)printf("%d ",a[i]);printf("\n")
#define newline printf("\n")
#define forin(a,b,c) for(int a=b ; a<c ; a++)
#define forde(a,b,c) for(int a=b ; a>=c ; a--)

inline void scd(int &a){scanf("%d",&a);}
inline void scdd(int &a,int &b){scanf("%d %d",&a,&b);}
inline void sctd(int &a,int &b,int &c){scanf("%d %d %d",&a,&b,&c);}
inline void scdlld(LL &a,LL &b){scanf("%I64d %I64d",&a,&b);}
inline void sclld(LL &a){scanf("%I64d",&a);}

#define scarrd(a,b) for(int index=0 ; index<b ; index++)scanf("%d",&a[index])
#define prdlld(a,b) printf("%I64d %I64d",a,b)
#define prdd(a,b) printf("%d %d",a,b)
#define prd(a) printf("%d",a)
#define prarr(a,b) for(int i=0 ; i<b ; i++)printf("%d ",a[i])
#define iniarr(a,b) for(int i=0 ; i<b ;i++)a[i]=0
#define arr(a,b) int *a=(int *)malloc(b*sizeof(int))
#define llarr(a,b) long long int *a=(long long int *)malloc(b*sizeof(long long int))
#define st(a,b) char *a=(char *)malloc(b*sizeof(char))
#define grav 9.8
#define pi 3.14159265

int main()
{
	int n;
	scd(n);
	LL a,b;
	string c;
	while(n!=0)
	{
		vector<string> e;
		map<string,LL> d;
		int fl=0;
		forin(i,0,n)
		{
			cin>>c>>a>>b;
			fl=0;
			forin(i,0,e.size())
			{
				if(e[i]==c)
				{
					fl=1;
					break;
				}
			}
			if(fl==0)
			e.pb(c);

			d[c]+=a*b;
		}
		fl=0;
		int size=e.size();
		forin(i,0,size)
		{
			if(d[e[i]]>=1000000)
			{
				fl=1;
				cout<<e[i]<<endl;
			}
		}

		if(fl==0)
		printf("NA\n");

		scd(n);
	}

	return 0;
}

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

struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n=1):n(n), f(n+1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i*i; j <= n; j += i) {
        if (!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x;}
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<P> res(1, P(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
};

int main() {
  ll n;
  cin>>n;
  Sieve sv(55555);
  vector<int> v;
  v=sv.primes;
  ll now=0;
  vector<ll>A;
  rep(i,v.size()){
    if (v[i]%10==1) {
      now++;
      A.push_back(v[i]);
    }
  }
  rep(i,n){
    cout<<A[i]<<' ';
  }
}


#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);++i)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};

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

  int n,q;
  cin >> n >> q;
  vector<tuple<int,int,int>> stx(n);
  rep(i,n){
    cin >> get<1>(stx[i]) >> get<2>(stx[i]) >> get<0>(stx[i]);
  }
  sort(stx.begin(),stx.end());

  set<P> st;
  rep(i,q){
    int x;
    cin >> x;
    st.emplace(x,i);
  }

  vector<int> ans(q,-1);
  rep(i,n){
    int s = get<1>(stx[i]);
    int t = get<2>(stx[i]);
    int x = get<0>(stx[i]);
    //xの昇順で考えてぶつかったら，その人をerase
    auto first = st.lower_bound(P(s-x,0));//引っかかる人
    auto end = st.upper_bound(P(t-x-1,q));//引っかからない人

    for(auto it = first; it !=end; ++it) ans[it->second] = x;

    st.erase(first,end);
  }

  rep(i,q) cout << ans[i] << endl;
  return 0;
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

bool compare_by_a(tuple<ll, ll, ll> a, tuple<ll, ll, ll> b) {
    if(get<0>(a) != get<0>(b)){
        return get<0>(a) > get<0>(b);
    }else{
        return get<1>(a) > get<1>(b);
    }
}
int main()
{
    cout << fixed << setprecision(15);
    ll N, Q;
    cin >> N >> Q;

    vector<tuple<ll, ll, ll> > A(N);

    REP(i ,N){
        ll s, t, x;

        cin >> s;
        cin >> t;
        cin >> x;

        get<0>(A[i]) = x;
        get<1>(A[i]) = s;
        get<2>(A[i]) = t;
    }

    vector<ll> D(Q);
    REP(i, Q){
        cin >> D[i];
    }

    // 1つ目のキーで降順順ソート
    sort(A.begin(), A.end(), compare_by_a);

    // for(ll i=0; i<N; i++){
    //     cout << get<0>(A[i]) << " " << get<1>(A[i]) << " " << get<2>(A[i]) << endl;
    // }
    vector<queue<ll>> plus(Q+1);
    vector<queue<ll>> minus(Q+1);

    REP(i, N){
        ll start = get<1>(A[i]) - get<0>(A[i]);
        ll end = get<2>(A[i]) - get<0>(A[i]);

        start = max(0LL, start);
        end = max(0LL, end);

        auto Iter1 = lower_bound(D.begin(), D.end(), start);
        ll s_id = Iter1 - D.begin();

        auto Iter2 = lower_bound(D.begin(), D.end(), end);
        ll t_id = Iter2 - D.begin();

        // cout << "s_id: " << s_id << "t_id: " << t_id << endl;

        plus[s_id].push(get<0>(A[i]));
        minus[t_id].push(get<0>(A[i]));
        // for(ll j=max(0LL,s_id); j<min(Q, t_id); j++){
        //     ans[j] = get<0>(A[i]);
        // }
    }

    // cout << 2 << endl;
    // cout << 2 << endl;
    // cout << 10 << endl;
    // cout << -1 << endl;
    // cout << 13<< endl;
    // cout << -1 << endl;
    multiset<ll> ans;

    REP(i, Q){
        // cout << i << " : " << ans.size() << endl;
        //　候補のものをすべて入れる。
        while (!(plus[i].empty())) {
            ans.insert(plus[i].front());
            plus[i].pop();
        }

        // cout << "plusの後： ";
        // for(auto itr = ans.begin(); itr != ans.end(); ++itr) {
        //     cout << *itr << " ";
        // }
        // cout << endl;

        //　候補が終わったものを削除
        while (!(minus[i].empty())) {
            ll temp = minus[i].front();
            auto itr = ans.find(temp);
            if(itr != ans.end()){
                ans.erase(ans.find(temp));
            }
            // cout << *itr << endl;
            minus[i].pop();
        }
        // cout << "minusの後： ";
        // for(auto itr = ans.begin(); itr != ans.end(); ++itr) {
        //     cout << *itr << " ";
        // }
        // cout << endl;

        // 候補がないなら-1を出力
        if(ans.empty()){
            cout << -1 << endl;
        }
        else{
            auto itr = ans.begin();
            cout << *itr << endl;
        }
    }

    return 0;
}


#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<string>
#include<cstring>
#include<time.h>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;

//BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney,chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu, topologicalsort, kyourenketuseibun

#define PRI(s) cout << s << endl
#define PRIY PRI("Yes")
#define PRIN PRI("No")

int main() {

	int N;
	int R;
	cin >> N >> R;
	if (N >= 10) PRI(R);
	else PRI(R + 100 * (10 - N));

	return 0;
}

// Integral

#include <iostream>
using namespace std;

int main() {
	int d;
	while(cin >> d) {
		int x = 0;
		long long S = 0;
		for(int i = 1; i < 600/d; i++) {
			x += d;
			S += d * (x * x);
		}
		cout << S << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
while(1){
  int n,m;
  int p[10000];
  int sum=0;
  cin>>n>>m;
  if(n==0 && m==0) break;
  for(int i=0;i<n;i++){
    cin>>p[i];
    }
  for(int i=0;i<n;i++){
    for(int j=0;j<n-1;j++){
      if(p[j]<p[j+1]) swap(p[j],p[j+1]);
      }
    }
  for(int i=0;i<n;i++){
    if(i%m==m-1) p[i]=0;
    }
  for(int i=0;i<n;i++){
    sum+=p[i];
    }
  cout<<sum<<endl;
}

  return 0;
}

#include<bits/stdc++.h>
using namespace std;
/*
int dx[]={-1,1,0,0};
int dy[]={0,0,-1,1};
vector<long long int> adj[200001];
bool vis[200001];
*/
#define ull unsigned long long int
#define ll long long int
#define MAX 1000000007
//1e9+7

#define pll pair<ll,ll>
#define pii pair<int,int>
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FO ifstream fin("a.in");ofstream fout("a.out");
#define TEST ll t;cin>>t;while(t--)
#define all(x) (x).begin(),(x).end()
#define mset0(x) memset((x), 0, sizeof((x)));
#define mset1(x) memset((x), -1, sizeof((x)));

string cmp(string a,string b){
    int n=a.size(),m=b.size();
    if(n>m) return(a);
    if(m>n) return(b);
    for(int i=0;i<n;i++){
        if(a[i]==b[i]) continue;
        if((a[i]-'0')>(b[i]-'0')) return(a);
        else return(b);
    }
    return(a);
}
string ss="0123456789";
int main(){
    IO
    int n,m;
    cin>>n>>m;
    int mat[]={0,2,5,5,4,5,6,3,7,6};
    int arr[m];
    for(int i=0;i<m;i++) cin>>arr[i];
    sort(arr,arr+m);
    map<int,string> mp;
    //for(int i=0;i<=n;i++) mp[i]="";
    /*
    for(int i=0;i<m;i++){
        string s=mp[mat[arr[i]]];
        string p="";
        p+=ss[arr[i]];
        //cout<<s<<" "<<p<<endl;
        mp[mat[arr[i]]]=cmp(p,s);
    }
    */

    for(int i=0;i<=n;i++){
        for(int j=0;j<m;j++){
            if(i-mat[arr[j]]<0) continue;
            string s=mp[i-mat[arr[j]]];
            string p=mp[i];
            if(s=="" && i!=mat[arr[j]]) continue;
            s+=ss[arr[j]];
            sort(s.rbegin(),s.rend());
            mp[i]=cmp(s,p);
            /*
            cout<<"i is "<< i<<" ";
            cout<<"j is "<<j<<" ";
            cout<<" mat[arr["<<j<<"]] is "<<mat[arr[j]]<<" ";
            cout<<"mp["<<i<<"] is "<<mp[i]<<"\n";
            */
        }

    }
    /*
    for(int i=1;i<=n;i++){
        cout<<i<<" "<<mp[i]<<"\n";
    }
    */
    cout<<mp[n];
    return(0);
}


#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  vector<int>L(m);
  vector<int>R(m);
  for(int i=0;i<m;i++){
    cin>>L.at(i)>>R.at(i);
  }
  int l=0,r=999999;
  for(int i=0;i<m;i++){
    l=max(l,L.at(i));
    r=min(r,R.at(i));
  }
  int ans=0;
  for(int i=0;i<=n;i++){
    if(i>=l&&i<=r){
      ans++;
    }
  }
  cout<<ans<<endl;
}

/*input

*/
#include <bits/stdc++.h>
#define up(i,a,b) for(int (i) = (a);(i)<=(b);++(i))
#define down(i,b,a) for(int (i) = (b);i>=(a);--i)
#define debug(x) cerr << (x) << '\n';
#define bits(x,i) ((x >> i) & 1)
#define mid ((l+r)/2)
#define pr pair<int,int>
using namespace std;
const int N = 500005;
int bit[N],n,q, c[N];
int nxtColor[N], nxtPos[N], color[N];
struct query{
	int l,r, id;
	query(){l = r = id = 0;}
	query(int _l,int _r,int _id){l = _l; r = _r; id = _id;}
};
bool operator<(query a,query b){
	return a.l < b.l;
}
query question[N];
int ans[N];
void upd(int u,int val){
	while (u <= n) {
		bit[u] += val;
		u += (u &-u);
	}
}
int get(int u){
	int ans = 0;
	while (u){
		ans += bit[u];
		u -= (u &-u);
	}
	return ans;
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n >> q;
	for(int i=1;i<=n;++i){
		cin >> c[i];
	}
	for(int i=1;i<=q;++i){
		cin >> question[i].l >> question[i].r;
		question[i].id = i;
	}
	for(int i=n;i>=1;--i){
		nxtPos[i] = nxtColor[c[i]];
		nxtColor[c[i]] = i;
	}
	for (int i=1;i<=n;++i) if (nxtColor[c[i]] == i) upd(i, 1);

	int curPos = 1;
	sort(question+1, question+1+q);
	for(int i=1;i<=q;++i){
		while (question[i].l != curPos){
			int nxt = nxtPos[curPos];
			upd(curPos, -1);
			if (nxt) upd(nxt, 1);
			curPos++;
		}
		ans[question[i].id] = get(question[i].r);
	}
	for(int i=1;i<=q;++i) cout << ans[i] << '\n';
}


//Author - Rahil Malhotra
#include <bits/stdc++.h>
using namespace std;

template <typename T> void print(T t) { cout<<t<<endl; }
template<typename T, typename... Args> void print(T t, Args... args) { cout<<t<<" "; print(args...); }

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define int long long
#define double long double

void start() {
	#ifndef ONLINE_JUDGE
		freopen("in", "r", stdin);
		freopen("out", "w", stdout);
	#endif
}

int n, m;
int arr[82][82][2];
int cache[81][81][81*162];

int dp(int i, int j, int diff) {
    if(i >= n || j >= m)
        return 1e18;

    if(i == n-1 && j == m-1) {
        return min(abs(diff - arr[i][j][0] + arr[i][j][1]),
                    abs(diff + arr[i][j][0] - arr[i][j][1]));
    }

    int &ans = cache[i][j][diff];
    if(ans !=-1)
        return ans;

    int ans1 = min(dp(i+1, j, abs(diff - arr[i][j][0] + arr[i][j][1])),
                dp(i+1, j, abs(diff + arr[i][j][0] - arr[i][j][1])));
    int ans2 = min(dp(i, j+1, abs(diff - arr[i][j][0] + arr[i][j][1])),
                dp(i, j+1, abs(diff + arr[i][j][0] - arr[i][j][1])));
    ans = min(ans2, ans1);
    return ans;
}
int32_t main() {
    IOS;
    start();

    cin >> n >> m;
    for(int i = 0 ; i < n ; i++) {
        for(int j = 0 ; j < m ; j++) {
            cin >> arr[i][j][0];
        }
    }
    for(int i = 0 ; i < n ; i++) {
        for(int j = 0 ; j < m ; j++) {
            cin >> arr[i][j][1];
        }
    }

    memset(cache, -1, sizeof(cache));
    cout << dp(0, 0, 0) << endl;
}

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

int n,b,m;

vector<vector<int> > vec;
vector<int> dp;

int solve(int mask)
{
if(dp[mask]!=LLONG_MIN)
	return dp[mask];
// if all the rabbits in mask are
// in the same group

int res=0;
for(int i=0; i<n; i++)
{
	for(int j=i+1; j<n; j++)
	{
		if((mask&(1LL<<i))&&(mask&(1LL<<j)))
			res+=vec[i][j];
	}
}

// iterate through all submasks now : O(3^n)

for(int i=mask&(mask-1); i; i=(i-1)&mask)
{
res=max(res,solve(i)+solve(i^mask));
}

return dp[mask]=res;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	vec.assign(n,vector<int>(n));
	for(int i=0; i<n; i++)
	{
		for(int j=0; j<n;j++)
		{
			cin>>vec[i][j];
		}
	}
	dp.assign(1LL<<n,LLONG_MIN);
	cout<<solve((1LL<<n)-1);
	return 0;
}


#include <bits/stdc++.h>

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int N;
    cin >> N;
    vector<int> v(N);
    for(int i = 0; i < N; ++i) {
        cin >> v[i];
    }
    sort(all(v));

    LL a, b;
    a = 0, b = 0;
    for(int i = 0; i < N - 1; ++i) {
        if(v[i] == v[i + 1]) {
            b = a;
            a = v[i];
            i++;
        }
    }
    cout << a * b << endl;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    long long int a;
    map<long long int,int> mp;
    for(int i=0;i<n;i++){
        cin >> a;
        a *= (-1);
        mp[a]++;
    }
    long long int tmp=0;
    for(auto u:mp){
        if(u.second>=4){
            if(tmp<0){
                cout << tmp*u.first;
                return 0;
            }
            else{
                cout << u.first*u.first;
                return 0;
            }
        }
        else if(u.second>=2){
            if(tmp<0){
                cout << tmp*u.first;
                return 0;
            }
            else tmp=u.first;
        }
    }
    cout << 0;
}


//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
const ll MAX_N=1e5,MAX_X=1e5;
ll N,X,psm[MAX_N+2],inx[MAX_N+1];
typedef tuple<ll,ll,ll> TUP;
TUP blu[MAX_N+1];

ll tsm(ll i){
	return get<1>(blu[i])*get<0>(blu[i])+get<2>(blu[i])*(X-get<0>(blu[i]));
}
ll ptsm(ll i,ll n){
	return get<1>(blu[i])*min(n,get<0>(blu[i]))+get<2>(blu[i])*(n-min(n,get<0>(blu[i])));
}
bool C(ll x){
	ll n=x/X,m=x%X;
	ll sm=0;
	REP(i,N+1){
		ll tmp=psm[n];
		if(i<n){
			tmp-=tsm(i);
			tmp+=ptsm(i,m);
			tmp+=tsm(n);
		}else{
			tmp+=ptsm(i,m);
		}
		sm=max(sm,tmp);
	}
	REP(i,N)sm-=get<1>(blu[i])*get<0>(blu[i]);
	return sm>=0;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>N>>X;
	REP(i,N)cin>>get<0>(blu[i])>>get<1>(blu[i])>>get<2>(blu[i]);
	blu[N]=make_tuple(0,0,0);
	REP(i,N+1)inx[i]=i;
	sort(blu,blu+N+1,[](TUP x,TUP y){
		return get<1>(x)*get<0>(x)+get<2>(x)*(X-get<0>(x))
			>get<1>(y)*get<0>(y)+get<2>(y)*(X-get<0>(y));
	});
	psm[0]=0;
	REP(i,N+1){
		psm[i+1]=psm[i]+tsm(i);
	}
	ll lb=-1,ub=N*X;
	while(ub-lb>1){
		ll m=(lb+ub)>>1;
		if(C(m)){
			ub=m;
		}else{
			lb=m;
		}
	}
	cout<<ub<<endl;
}

// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

signed main() {
    int N, X; cin >> N >> X;
    vector< tuple<int, int, int> > tups;
    for(int i=0; i<N; i++) {
        int b, l, u; cin >> b >> l >> u;
        tups.emplace_back(b, l, u);
    }
    sort(tups.begin(), tups.end(), [&](auto x, auto y) {
            int xb, xl, xu, yb, yl, yu;
            tie(xb, xl, xu) = x;
            tie(yb, yl, yu) = y;

            int vl = xl * xb + xu * (X - xb);
            int vr = yl * yb + yu * (X - yb);
            return vl > vr;
        });

    int D = 0;
    vector<int> acc(N+1), val(N);
    for(int i=0; i<N; i++) {
        int b, l, u; tie(b, l, u) = tups[i];
        D -= b * l;
        val[i  ] = l * b + u * (X - b);
        acc[i+1] = acc[i] + val[i];
    }

    int ub = X*N, lb = -1;
    while(ub - lb > 1) {
        int mid = (ub + lb) / 2;

        bool ok = false;
        // 中途半端に選ぶものが i 番目の要素
        int q = mid / X, R = mid % X;
        for(int i=0; i<N; i++) {
            int d = D, r = R;
            int b, l, u; tie(b, l, u) = tups[i];
            d += l * min(r, b);
            r -= min(r, b);
            d += u * r;

            if(i < q) {
                d += acc[q+1] - val[i];
            }
            else {
                d += acc[q];
            }
            ok |= (d >= 0);
        }

        if(ok) ub = mid;
        else lb = mid;
    }
    cout << ub << endl;
    return 0;
}


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

using namespace std;

int main() {
	double n;
	cin >> n;
	n = 2 * n * acos(-1);
	cout << n << endl;
	return 0;
}

#include<iostream>
using namespace std;
int main (void)
{
  int r;
  cin>>r;
  r=r*2*3141592;
  cout<<r/1000000<<"."<<r%1000000;
}


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

int main() {

    double r, g;
    cin >> r >> g;
    cout << (2 * g) - r << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
const ll MOD=1000000007;
const long double PI=3.14159265358979;
const ll MAX=0;

int main() {
  ll a,b;
  cin>>a>>b;
  cout<<b+b-a;
}