#ifdef __GNUC__
#pragma GCC target("avx2")
#pragma GCC optimize ("O30")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC optimize("unroll-loops")
#define iss std::cin
#endif
#include "bits/stdc++.h"
#define rep(i, times) for(ll i = 0; i < (times); ++i)
#define p(x) (cout << (x) << "\n")
using ll = long long; using ld = long double; using namespace std;

ll N, cnt;
void all( ) {
	vector<vector<ll>> A;
	iss >> N; A.resize(3, vector<ll>(N));
	for (auto &abc : A) {
		for (auto &a : abc)  iss >> a;
	}
	sort(begin(A[0]), end(A[0]));
	sort(begin(A[2]), end(A[2]));
	for (auto &b : A[1]) {
		cnt += (end(A[2]) - upper_bound(begin(A[2]), end(A[2]), b))
			* (lower_bound(begin(A[0]), end(A[0]), b) - begin(A[0]));
	}
	p(cnt);
}
int main( ) {
	cin.tie(0);	ios::sync_with_stdio(0);
	all( );
}

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

int main() {
	ll n, ans = 0;
	cin >> n;
	vector<ll> a(n), b(n), c(n);
	rep(i,n) cin >> a[i];
	sort(a.begin(), a.end());
	rep(i,n) cin >> b[i];
	sort(b.begin(), b.end());
	rep(i,n) cin >> c[i];
	sort(c.begin(), c.end());

	for (int i = 0; i < n; i++) {
		ll L = -1 , R = n;

		while (abs(L - R) > 1) {
			int mid = (L + R) / 2;
			if (a[mid] < b[i]) L = mid;
			else R = mid;
		}
		ll down = L;

		L = -1; R = n;

		while (abs(L - R) > 1) {
			int mid = (L + R) / 2;
			if (c[mid] > b[i]) R = mid;
			else L = mid;
		}
		ll up = R;
		ans += (down + 1) * (n - up);
	}
	cout << ans << endl;
	return 0;
}


#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007

//edit
template<typename T>
class Sum2d {
    vector<vector<T> > vv;
    unsigned xSize{};
    unsigned ySize{};
public:
    Sum2d(unsigned xSize, unsigned ySize) {
        vector<vector<T> > vv(xSize + 2, vector<T>(ySize + 2));
        this->vv = vv;
        this->xSize = xSize + 2;
        this->ySize = ySize + 2;
    }

    void add(int x, int y, T value) {
        x++;
        y++;
        this->vv[x][y] += value;
    }

    void set_sum() {
        for (int i = 0; i < xSize - 1; i++) {
            for (int j = 0; j < ySize; j++) {
                this->vv[i + 1][j] += vv[i][j];
            }
        }
        for (int i = 0; i < xSize; i++) {
            for (int j = 0; j < ySize - 1; j++) {
                this->vv[i][j + 1] += vv[i][j];
            }
        }
    }

    //[sx,tx],[sy,ty]の範囲を求めるZE
    T calc(int sx, int sy, int tx, int ty) {
        tx++;
        ty++;
        return this->vv[tx][ty] + this->vv[sx][sy] - this->vv[tx][sy] - this->vv[sx][ty];
    }
};

class Solve {
public:
    void solve() {
        Int N, M, Q;
        cin >> N >> M >> Q;
        vector<string> S(N);
        Sum2d<int> V(2 * N, 2 * M), E(2 * N, 2 * M);
        for (int i = 0; i < N; ++i) {
            cin >> S[i];
            for (int j = 0; j < M; ++j) {
                if (S[i][j] == '1') {
                    V.add(2 * i, 2 * j, 1);
                }
            }
        }

        for (int i = 0; i < N; ++i) {
            for (int j = 0; j + 1 < M; ++j) {
                if (S[i][j] == '1' && S[i][j + 1] == '1') {
                    E.add(2 * i, 2 * j + 1, 1);
                }
            }
        }
        for (int j = 0; j < M; ++j) {
            for (int i = 0; i + 1 < N; ++i) {
                if (S[i][j] == '1' && S[i + 1][j] == '1') {
                    E.add(2 * i + 1, 2 * j, 1);
                }
            }
        }
        V.set_sum();
        E.set_sum();

        for (int i = 0; i < Q; ++i) {
            int x1, y1, x2, y2;
            cin >> x1 >> y1 >> x2 >> y2;
            x1--, y1--, x2--, y2--;
            int r1 = 2 * x1;
            int c1 = 2 * y1;
            int r2 = 2 * x2;
            int c2 = 2 * y2;
            Int v1 = V.calc(r1, c1, r2, c2);
            Int e1 = E.calc(r1, c1, r2, c2);
            Int tmp = V.calc(r1, c1, r2, c2) - E.calc(r1, c1, r2, c2);
            cout << tmp << endl;
        }

    }
};

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

    Solve().solve();

    return 0;
}


//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int find_(int x,vector<pair<ll,ll>> &v){
    if(v[x].first<0) return x;
    v[x].first=find_(v[x].first,v);
    return v[x].first;
}

int same_(int a,int b,vector<pair<ll,ll>> &v){
    if(find_(a,v)==find_(b,v)) return 1;
    return 0;
}

void union_(int a,int b,vector<pair<ll,ll>> &v){
    if(same_(a,b,v)) return;
    int a_p=find_(a,v),b_p=find_(b,v);
    if(a_p>b_p) swap(a_p,b_p);
    v[a_p].first+=v[b_p].first;
    v[a_p].second+=v[b_p].second;
    v[b_p].first=a_p;
}

/*
void print_v(vector<pp> v){
    rep(i,v.size()) cout<<v[i]<<" ";
    cout<<endl;
}

int size_(int a,vector<pp> &v){
    return -v[find_(a,v)];
}
*/

int main() {
    int h,w; cin>>h>>w;
    vector<string> s(h,"");
    rep(i,h) cin>>s[i];
    vector<pair<ll,ll>> v(h*w,mk(-1,0));
    rep(i,h*w){
        if(s[i/w][i%w]=='#') v[i].second=-1;
    }
    rep(i,(h-1)*w) if(s[i/w][i%w]!=s[i/w+1][i%w]) union_(i,i+w,v);
    rep(i,h*w){
        if(i%w==w-1) continue;
        if(s[i/w][i%w]!=s[i/w][i%w+1]) union_(i,i+1,v);
    }
    ll ans=0;
    rep(i,h*w){
        if(v[i].first<0)
        ans+=(-v[i].second)*(v[i].second-v[i].first);
    }
    cout<<ans<<endl;
}

#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using P = pair<int,int>;

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

int main()
{
  int H,W;
  cin >> H >> W;
  vector<string> A(H);
  REP(i, H) cin >> A[i];

  vector<vector<int>> dist(H,vector<int> (W,-1));
  ll ans = 0;
  REP(i,H){
    REP(j,W){
      if(A.at(i).at(j)=='#'&&dist[i][j]==-1){
        ll cntblack = 1;
        ll cntwhite = 0;
        queue<P> que;
        que.push(make_pair(i,j));
        dist[i][j]=0;
        while(!que.empty()){
          int vy = que.front().first;
          int vx = que.front().second;
          que.pop();
          REP(k,4){
            int nvy = vy+dy[k];
            int nvx = vx+dx[k];
            if(nvy<0||nvy>H-1||nvx<0||nvx>W-1||dist[nvy][nvx]!=-1||(A[vy][vx]=='#'&&A[nvy][nvx]!='.')||(A[vy][vx]=='.'&&A[nvy][nvx]!='#')) continue;
            dist[nvy][nvx]=0;
            que.push(make_pair(nvy,nvx));
            if(A[nvy][nvx]=='#'){
              cntblack++;
            }else{
              cntwhite++;
            }
          }
        }
        ans+=cntblack*cntwhite;
      }
    }
  }

  cout << ans << endl;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pci pair <char, int>
#define pld pair <ld, ld>
#define ppld pair <pld, pld>
#define ppll pair <pll, pll>
#define pldl pair <ld, ll>
#define vll vector <ll>
#define vvll vector <vll>
#define vpll vector <pll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mll map <ll, ll>
#define fastmap gp_hash_table
#define cd complex <double>
#define vcd vector <cd>
#define PI 3.14159265358979
#pragma 03
using namespace std;
using namespace __gnu_pbds;
ll n;
multiset <ll> st;
int main(){
	fastio;
	ll t, k, ans = 0;
	cin >> n;
	for (ll i = 0; i < n; i++) cin >> t, st.insert(t);
	while (st.size() > 1){
		auto it = st.end();
		it--; t = *it;
		st.erase(it);
		for (k = 1; k <= t; k *= 2);
		it = st.find(k - t);
		if (it != st.end()){
			st.erase(it); ans++;
		}
	}
	cout << ans << endl;
}

#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

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

int main() {

	ll N;
	cin >> N;

	vector<ll> A(N + 1,0);
	repn(i, N) cin >> A[i];

	sort(++A.begin(), A.end());

	vector<ll> B(1);
	vector<ll> C(1);
	ll M = 0;

	repn(i, N) {
		if (A[i] != A[i - 1]) {
			M++;
			C.push_back(A[i]);
			B.push_back(1);
		}

		else { B[M]++; }
	}

	ll ans = 0;

	for (ll i = M; i > 0; i--) {
		ll p = 1;

		while (p <= C[i]) {
			p *= 2;
		}

		ll X = p - C[i];
		auto itr = lower_bound(++C.begin(), C.end(), X);
		ll j = distance(C.begin(), itr);

		if (C[j] != X) { continue; }

		if (i == j) { ans += B[i] / 2; }
		if (j < i) { ans += min(B[i], B[j]); B[j] -= min(B[i], B[j]); }

	}

	cout << ans;

	system("PAUSE");

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,x,y,z;
    cin>>a>>b;
    x=a+b;
    y=a-b;
    z=a*b;
    if(x>=y && x>=z)
    {
        cout<<x<<endl;
    }
    else if(y>=x && y>=z)
    {
        cout<<y<<endl;
    }
    else
    {
        cout<<z<<endl;
    }
    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>;
using Graph = vector<vector<int>>;
int main(int argc, const char * argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int a,b;
    cin>>a>>b;
    int ans=-1e9;
    ans=max(ans,a+b);
    ans=max(ans,a-b);
    ans=max(ans,a*b);
    cout<<ans<<endl;

    return 0;
}


#include<bits/stdc++.h>
#define fo(i,a,b) for((i)=(a);i<=(b);i++)
#define rfo(i,a,b) for((i)=(a);i>=(b);i--)
#define inrange(x,y,z) (((x)>=(y))&&((x)<=(z)))
#define ALL(vec) (vec).begin(),(vec).end()
#define SOR(vec) sort(ALL(vec))
#define UNI(vec) (vec).erase(unique(ALL(vec)),(vec).end())
using namespace std;
int n;
double val;
long long a,res;
int two,five;
map<pair<int,int>,int> cnt;
int main(){
	#ifdef FILIN
		#ifndef DavidDesktop
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>val;
		a=llround(val*1e9);
		two=five=0;
		while(a%2==0){
			two++;
			a/=2;
		}
		while(a%5==0){
			five++;
			a/=5;
		}
		cnt[make_pair(two,five)]++;
	}
	for(auto p1:cnt){
		for(auto p2:cnt){
			if((p1.first.first+p2.first.first)>=18&&(p1.first.second+p2.first.second)>=18){
				if(p1==p2) res+=(long long)(p1.second)*(long long)(p1.second-1);
				else res+=(long long)(p1.second)*(long long)(p2.second);
			}
		}
	}
	cout<<res/2LL<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 5;
typedef long long ll;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); }
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
int get(int h, int m) {
	return h * 60 + m;
}
int main() {
	int h1, m1, h2, m2, k;
	read(h1), read(m1), read(h2), read(m2), read(k);
	cout << get(h2, m2) - get(h1, m1) - k << endl;
	return 0;
}

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

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

void solve(){

  int n,M;
    cin>>n>>M;
    int a,b;
    if(M%2==0){
        a=M/2;
        b=M/2;
    }else{
        a=M/2;
        b=M-a;
    }
    for(int i=1;i<=a;++i){
        cout<<i<<" "<<2*a+2-i<<endl;
    }
    for(int i=1;i<=b;++i){
        cout<<i+2*a+1<<" "<<M*2+2-i<<endl;
    }

}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout<<fixed<<setprecision(20);
    int t = 1;
   //  cin >> t;
    while (t--)
    {
        solve();
    }
}


#include<iostream>
using namespace std;
long long n;
long long a[200003];
long long dp[200003];
long long sumb[200003];
long long ans=-2e18;
long long sum;
long long su;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	dp[1]=a[1];
	dp[2]=a[2];
	sumb[n]=a[n];
	sumb[n-1]=a[n-1];
	for(int i=3;i<=n;i++) dp[i]=dp[i-2]+a[i];
	for(int i=n-2;i>=1;i--) sumb[i]=sumb[i+2]+a[i];
	sum=dp[n];
	if(n%2==0){
		ans=max(dp[n-1],dp[n]);
		for(int i=1;i<=n;i+=2) ans=max(ans,dp[i]+sumb[i+3]);
		cout<<ans<<endl;
		return 0;
	}
	for(int i=1;i<=n;i++){
		if(i%2==0) su+=a[i];
		else{
			su=max(su-a[i],-a[i]);
			ans=max(ans,sum+su);
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

void gauss(vector<ll>& a){
  ll n=a.size();
  ll rank=0;
  for(ll b=(1LL<<60LL);b>=1;b>>=1){
    ll p=rank;
    while(p<n&&!(a[p]&b))p++;
    if(p==n)continue;
    swap(a[rank],a[p]);
    rep(i,n){
      if(i==rank)continue;
      if(a[i]&b)a[i]^=a[rank];
    }
    rank++;
  }
  a.resize(rank);
  sort(all(a));
  reverse(all(a));
}

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

  ll n;
  vector<ll> a;
  cin>>n;
  ll sum=0;
  a.resize(n);
  rep(i,n){
    cin>>a[i];
    sum^=a[i];
  }

  rep(i,n){
    rep(j,60){
      if((sum>>j)&1LL){
        if((a[i]>>j)&1LL){
          a[i]^=(1LL<<j);
        }
      }
    }
  }

  sort(all(a));
  gauss(a);

  ll mx=0;
  rep(i,a.size()){
    if(mx<(mx^a[i])){
      mx^=a[i];
    }
  }
  cout<<mx*2+sum<<endl;

  return 0;
}


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

#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;

typedef vector<int> vi;;
typedef vector<ll> vll;

#define l() length()
#define sz() size()

#define b() begin()
#define e() end()
#define all(x) x.begin(), x.end()

#define pb(i) push_back(i)
#define PB() pop_back()

typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
#define mp make_pair
#define Fi first
#define Se second

const int maxx=1e6+9;

// Happy Coding!

ll _find(int d,int n){
    return n<100 ? pow(100,d)*n : 101*pow(100,d);
}

void solve(){

    int n;
    cin>>n;
    map<string,int> f;
    for(int i=0;i<n;i++){
        string s;cin>>s;
        f[s]++;
    }

    int m;
    cin>>m;
    for(int i=0;i<m;i++){
        string s;cin>>s;
        f[s]--;
    }
    int ans=0;
    for(auto P:f){
        ans=max(ans,P.Se);
    }
    cout<<ans<<endl;
}

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


#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define ll long long
using namespace std;
int main() {
  ll N = 0, A,B;;
  cin >> N >> A >> B;
  if(N == 1){
    cout << "Hello World";
  }
  else{
    cout << A + B;
  }
}

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <numeric>
#include <random>
#include <vector>
#include <array>
#include <bitset>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>

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

int main() {
    string a, b ,c;
    cin >> a >> b >> c;
    if(a.back() == b.front() && b.back() == c.front()){
        cout << "YES";
    }else{
        cout << "NO";
    }
    return 0;
}


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

int main() {
  int n = 0, tmp0 = 0, tmp1 = 0;
  int tmp2 = 0, tmp3, out1 = 0, out2 = 0;
  int a[100];
  scanf("%d", &n);
  while (n) {
    for (tmp3=0;tmp3<100;tmp3++) a[tmp3] = 0;
    tmp0 = 0, out2 = 0;
    while (tmp0 < n) {
      tmp1 = 0, out1 = 0;
      while (tmp1 < n) {
        scanf("%d", &tmp2);
        a[tmp1] += tmp2;
        printf("%5d", tmp2);
        out1 += tmp2;
        tmp1++;
      }
      printf("%5d\n", out1);
      a[tmp1] += out1;
      tmp0++;
    }
    tmp0 = 0;
    while (tmp0 < n) {
      printf("%5d", a[tmp0]);
      tmp0++;
    }
    printf("%5d\n", a[tmp0]);
    scanf("%d", &n);
  }
  return 0;
}

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

int main(){
	int n,field[11][11];
	while (cin >> n, n){
		for (int i = 0; i < 11; i++){
			for (int j = 0; j < 11; j++) field[i][j] = 0;
		}
		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++) cin >> field[i][j];
		}
		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++) field[n][i] += field[j][i];
		}
		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++) field[i][n] += field[i][j];
		}
		for (int i = 0; i < n; i++) field[n][n] += field[n][i];
		for (int i = 0; i <= n; i++){
			for (int j = 0; j <= n; j++)  printf("%5d",field[i][j]);
			puts("");
		}
	}
	return 0;
}


// ABC 089 A- Grouping 2

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

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

#include<iostream>
using namespace std;
int main(){
	int a,b=0;
	cin>>a;
	if(a%3==0 && a>0){
		b=(a/3)+b;

	}
	else if(a%3==1 && a>1){
		a-=4;
		b++;
		b=(a/3)+b;
	}
	else if(a%3==2 && a>2){
		a-=5;
		b++;
		b=(a/3)+b;
	}
	else{
		system("pause");
	}
	cout<<b;
}


#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;

//using Graph = vector<vector<edge>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

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; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define RES(a,i,j) a.resize(i);rep(ii,i)a[ii].resize(j);
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout<<a<<" "<<b<<" "<<c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define ssum(a) accumulate(a,0ll)
#define gre(n) greater<n>()

typedef long long ll;
//
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
//typedef long long T;
const int INF = 1000000000;
const double dINF = 1000000000;
const ll INF64 = 922337203685477580ll;
const ll MOD = 998244353ll;
//const ll MOD = 67280421310721ll;
const dou pi=3.141592653589793;
//メモ
//二次元配列のresizeのしかた
//vv.resize(n);
//for(size_t i=0; i<n; i++){
// vv[i].resize(n);
//}

//メモ
//負の辺を持つ最短経路問題では到達不可経路でも初期化値より小さくなりうるので注意しよう
int main(){
    int n,m,v,p;
    std::cin >> n>>m>>v>>p;
    VEC(ll,a,n);
    std::vector<ll> sa(n+1);

    sort(all(a),gre(ll));
    rep(i,n){
        sa[i+1]=sa[i]+a[i];
    }
    int ans=p;
    int dd=a[p-1];
    rrep(i,p,n){
        ll can=a[i]+m;
        ll need=max(0ll,ll(i-(p-1))-(n-v))*m;
        bool b=0;
      //  ll d=0;
        ll dd=(i-p+1)*can-(sa[i]-sa[p-1]);
       // pppri(i,p-1,sa[i]-sa[p-1]);
        if(can<a[p-1])break;
        if(dd>=need)ans++;
        /*
        rrep(j,p-1,i){
          //  std::cout << j << std::endl;
            if(can<a[j]){
                b=1;
                break;
            }
            d+=can-a[j];
            //if(d>=need)ans++;
        }
        */
        if(b)break;
        //ppri(d,dd);

    }
    std::cout << ans << std::endl;
}

#include <cstdio>
#include <algorithm>

const int N = 100000;
int n, m, v, p, a[N];

bool test(int t)
{
	t = n - t;
	int amt = v - t - 1;
	int i;
	for (i = n - 1; a[t] + m < a[i]; --i, --amt);
	long long to = 0;
	for (int j = i; j > t; --j) to += a[t] + m - a[j];
	for (; i > t && to < (long long)amt * m; --i) {
		--amt;
		to -= a[t] + m - a[i];
	}
	return n - i <= p;
}

int main()
{
	scanf("%d%d%d%d", &n, &m, &v, &p);
	for (int i = 0; i < n; ++i) scanf("%d", a + i);
	std::sort(a, a + n);
	int l = p, r = n;
	int ans;
	while (l <= r) {
		int m = (l + r) >> 1;
		if (test(m)) {
			ans = m;
			l = m + 1;
		}
		else r = m - 1;
	}
	printf("%d\n", ans);
	return 0;
}


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

namespace ABC168
{

  class B
  {
  public:
    B() = default;
    ~B() = default;

    void Run()
    {

      std::string S;
      int K= 0;
      std::cin >> K;
      std::cin >> S;

      std::string answer = S;
      if (S.length() > K)
      {
        answer = S.substr(0, K);
        answer.append("...");
      }

      std::cout << answer << std::endl;
    }
  };

}
int main()
{

  ABC168::B prob;
  prob.Run();

  return 0;
}

#include<bits/stdc++.h>
#define ll long long

const ll mod = 1000000007 ;

bool isInteger(double n)
{
	if(floor(n)==ceil(n))
		return true ;
	return false ;
}

using namespace std ;

int main()
{
	int k;
	cin>>k;
	string s;
	cin>>s;
	string s1="" ;
	if(s.length()<=k)
		cout<<s;
	else
	{
		for(int i=0 ;i<s.length() ;i++)
		{
			if(i<k)
				s1+=s[i];
		}
		s1+="...";
		cout<<s1;
	}

}


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

int main(){
    int h,w;
    cin >> h >> w;
    char s[h+2][w+2];
    for(int i=0;i<h+2;i++){
        if(i==0 || i==h+1){
            for(int j=0;j<w+2;j++) s[i][j]='.';
        }else{
            for(int j=0;j<w+2;j++){
                if(j==0 || j==w+1){
                    s[i][j]='.';
                }else{
                    cin >> s[i][j];
                }
            }
        }
    }

    /*for(int i=0;i<h+2;i++){
        for(int j=0;j<w+2;j++){
            cout << s[i][j];
        }
        cout << endl;
    }*/

    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            if(s[i][j]=='#'){
                if(s[i+1][j]=='.' && s[i-1][j]=='.' && s[i][j+1]=='.' && s[i][j-1]=='.'){
                    cout << "No" << endl;
                    return 0;
                }
            }
        }
    }

    cout << "Yes" << endl;
}

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;

const int N=2005;

int n,m,t,ans;
int dp[N][N],mp[N][N],st[N],f[N],g[N];
char s[N][N];

bool pd(int x1,int y1,int x2,int y2){
	int sum;
	sum=mp[x1][y1]+mp[x1][y2]+mp[x2][y1]+mp[x2][y2];
	return !(sum&1);
}

void init(){
	int i,j,k;
	for (i=1;i<n;i++){
		for (j=m-1;j;j--){
			if (pd(i,j,i+1,j+1)) dp[i][j]=dp[i][j+1]+1;
			else dp[i][j]=0;
		}
	}
}

void work(){
	int i,j;
	for (i=1;i<m;i++){
		t=0;
		for (j=1;j<n;j++){
			while (t&&dp[j][i]<dp[st[t]][i]){
				f[st[t]]=j; t--;
			}
			st[++t]=j;
		}
		for (j=1;j<=t;j++) f[st[j]]=n;
		t=0;
		for (j=n-1;j;j--){
			while (t&&dp[j][i]<dp[st[t]][i]){
				g[st[t]]=j+1; t--;
			}
			st[++t]=j;
		}
		for (j=1;j<=t;j++) g[st[j]]=1;
		for (j=1;j<n;j++) ans=max(ans,(f[j]-g[j]+1)*(dp[j][i]+1));
	}
}

int main(){
	int i,j;
	scanf("%d%d",&n,&m); ans=max(n,m);
	for (i=1;i<=n;i++){
		scanf("%s",s[i]+1);
		for (j=1;j<=m;j++) mp[i][j]=s[i][j]=='.';
	}
	init();
	work();
	printf("%d\n",ans);
	return 0;
}


#include<cstdio>
#include<utility>
#include<vector>
#include<queue>
using namespace std;
typedef pair<int, int> P;

const int INF = 1050;
struct vertex {
    vector<int> to;
    int dist = INF;
};

int n, m;
int sd[1000], prv[1000];
vertex ver[1000];
priority_queue<P, vector<P>, greater<P>> q;

int main() {
    scanf("%d %d", &n, &m);
    for (int i = 0; i < m; i++) {
        int a, b;
        scanf("%d %d", &a, &b);
        ver[a - 1].to.emplace_back(b - 1);
    }
    for (int i = 0; i < n; i++) sd[i] = INF;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) ver[j].dist = INF;
        ver[i].dist = 0;
        q.emplace(0, i);
        while(!q.empty()) {
            P p = q.top(); q.pop();
            if (p.second != i && ver[p.second].dist != p.first) continue;
            if (p.second == i && p.first != 0 && sd[i] != p.first) continue;
            for (auto &j : ver[p.second].to) {
                if (j != i && p.first + 1 < ver[j].dist) {
                    ver[j].dist = p.first + 1;
                    q.emplace(ver[j].dist, j);
                }
                if (j == i && p.first + 1 < sd[i]) {
                    sd[i] = p.first + 1;
                    q.emplace(sd[i], i);
                }
            }
        }
    }

    int minsd = INF, ind;
    for (int i = 0; i < n; i++) {
        if (sd[i] < minsd) {
            minsd = sd[i];
            ind = i;
        }
    }
    if (minsd == INF) {
        printf("-1\n");
        return 0;
    }

    for (int i = 0; i < n; i++) ver[i].dist = INF;
    ver[ind].dist = 0;
    sd[ind] = INF;
    q.emplace(0, ind);
    while(!q.empty()) {
        P p = q.top(); q.pop();
        if (p.second != ind && ver[p.second].dist != p.first) continue;
        if (p.second == ind && p.first != 0 && sd[ind] != p.first) continue;
        for (auto &i : ver[p.second].to) {
            if (i != ind && p.first + 1 < ver[i].dist) {
                ver[i].dist = p.first + 1;
                q.emplace(ver[i].dist, i);
                prv[i] = p.second;
            }
            if (i == ind && p.first + 1 < sd[ind]) {
                sd[ind] = p.first + 1;
                q.emplace(sd[ind], ind);
                prv[i] = p.second;
            }
        }
    }

    printf("%d\n", minsd);
    for (int i = 0, j = ind; i < minsd; i++) {
        printf("%d\n", j + 1);
        j = prv[j];
    }
    return 0;
}

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

#define MAXN 1005

vector<int> g[MAXN];
vector<vector<int>> cycles;
int par[MAXN];

void dfs(int u) {
	//$ cerr << u << endl;
	for(int v : g[u]) {
		if(par[v] == -1) {
			par[v] = u;
			dfs(v);
		} else {
			int cur = u;
			vector<int> cyc = {u};
			while(cur != v && par[cur] != -2) {
				cyc.push_back(par[cur]);
				cur = par[cur];
			}

			if(cyc.back() == v)
				cycles.push_back(cyc);
		}
	}
}

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

	int n, m;
	cin >> n >> m;
	for(int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		u--, v--;
		g[u].push_back(v);
	}

	for(int i = 0; i < n; i++) {
		memset(par, -1, sizeof par);
		par[i] = -2;
		dfs(i);
	}

	for(vector<int> v : cycles) {
		set<int> s(v.begin(), v.end());
		bool ok = true;
		for(int i = 0; i < (int) v.size(); i++) {
			int cnt = 0;
			for(int nei : g[v[i]]) {
				if(s.count(nei)) {
					cnt++;
				}
			}
			if(cnt > 1) {
				ok = false;
			}
			//$ cerr << v[i] << " : nei's = " << cnt << endl;
		}

		//$ cerr << endl;

		if(ok) {
			cout << v.size() << '\n';
			for(int i = 0; i < (int) v.size(); i++) {
				cout << v[i]+1 << '\n';
			}
			return 0;
		}
	}

	cout << -1 << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll n,a,b;
  cin>>n;
  cout<<50<<endl;
  a=n/50;
  b=n%50;
  for(int i=0;i<b;i++){
    cout<<50+a-i<<" ";
  }
  for(int i=b;i<50;i++){
    cout<<max(0LL,49+a-i)<<" ";
  }
}

#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
LL x[50];

int main() {
    LL K;
    scanf("%lld", &K);
    LL rd = K / 50;
    for (int i = 0; i < 50; i++)
        x[i] = 50 - 1 + rd;
    for (int i = 0; i < (K % 50); i++) {
        int idx = 0;
        for (int j = 0; j < 50; j++)
            if (x[j] <= x[idx]) idx = j;
        for (int j = 0; j < 50; j++) {
            if (j == idx) x[j] += 50;
            else x[j]--;
        }
    }
    printf("%d\n", 50);
    for (int i = 0; i < 50; i++)
        printf("%lld ", x[i]);
    puts("");
    return 0;
}


#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ldouble = long double;

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s) cout << fixed << setprecision(10) << s << endl;

int main()
{
	ll m, n, x, y;
	cin >> m >> n >> x >> y;

	vector<ll> a(m);
	ll a0 = -101;
	for (ll i = 0; i < m; i++)
	{
		cin >> a[i];

		a0 = max(a0, a[i]);
	}

	vector<ll> b(n);
	ll b0 = 101;
	for (ll i = 0; i < n; i++)
	{
		cin >> b[i];

		b0 = min(b0, b[i]);
	}

	string res = "No War";

	if (a0 >= b0)
	{
		res = "War";
	}

	if (b0 <= x)
	{
		res = "War";
	}

	if (a0 >= y)
	{
		res = "War";
	}

	println(res);
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int f(int n)
{
    return ((n & 1) ? 3 * n + 1 : n / 2);
}

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> x(n + 1), y(m + 1);
    cin >> x[0] >> y[0];
    rep2(i, 1, n + 1) cin >> x[i];
    rep2(i, 1, m + 1) cin >> y[i];

    sort(all(x));
    sort(all(y));

    cout << ((x[n] < y[0]) ? "No War" : "War") << '\n';
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN=1e5+5;
const int MAXB=65;
typedef long long ll;
int n;
ll a[MAXN],p[MAXN],sum;
bool vis[MAXB];
void ins(ll x){
	for (ll i=60;i>=0;i--){
		if (!vis[i]) continue;
		if (x&(1ll<<i)){
			if (!p[i]) p[i]=x;
			x^=p[i];
		}
	}
}
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		sum^=a[i];
	}
	for (int i=0;i<=60;i++){
		if (!(sum&(1ll<<i))) vis[i]=1;
	}
	for (int i=1;i<=n;i++) ins(a[i]);
	ll res=0;
	for (int i=60;i>=0;i--){
		if (vis[i]&&(!(res&(1ll<<i)))) res^=p[i];
	}
	printf("%lld\n",res+(sum^res));
	return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
# define ll int64_t
# define str string
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;

#define INF 2000000000
#define MAX_V 10

bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

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

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

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

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

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

    ll n,sum=0;
    cin>>n;
    vec<ll> a(n+2);
    rrep(i,n) cin>>a[i];
    a[n+1]=0;
    rrep(i,n+1){
        sum+=abs(a[i]-a[i-1]);
    }
    for(ll i=1;i<=n;i++){
        ll num=sum;
        if(a[i-1]<a[i] && a[i]>a[i+1]){
            num-=(abs(a[i]-a[i-1])+abs(a[i]-a[i+1]));
            num+=abs(a[i-1]-a[i+1]);
        }else if(a[i-1]>a[i] && a[i]<a[i+1]){
            num-=(abs(a[i]-a[i-1])+abs(a[i]-a[i+1]));
            num+=abs(a[i-1]-a[i+1]);
        }
        cout<<num<<endl;
    }
    return 0;
}


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

int main() {
  int N, M;
  cin >> N;
  M = N;
  int sum = 0;

  for (int i=8; i>=0; i--) {
    int W=1;
    for (int j=0; j<i; j++){
      W *= 10;
    }
    int x;
    x = N / W;
    sum += x;
    N = N - x*W;
  }
  if (M % sum == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


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

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main() {
  long long x;
  cin >> x;

  long long count = (x / (5 + 6)) * 2;
  if (x % (5 + 6) == 0) {}
  else if (x % (5 + 6) <= 6) count++;
  else count += 2;

  cout << count << endl;

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<ll> VLL;
typedef vector<vector<ll>> VVLL;
typedef pair<ll, ll> Pair;
template <class T> T input() {T t; cin>>t; return t;}
#define FOR(i,a,b) for (ll i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (ll i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,x) for (ll i = 0; i < x.size(); i++)
#define RREPALL(i,x) for (ll i = x.size()-1; i >= 0; i--)
#define REPITR(itr,x) for (auto itr = (x).begin(); itr != (x).end(); itr++)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort(ALL(x))
#define MIN_ELEMENT(x) min_element(ALL(x))
#define MAX_ELEMENT(x) max_element(ALL(x))
#define COUNT(x,num) count(ALL(x), num)
#define MEMSET(x,val) memset(x, val, sizeof(x))
#define CHMAX(a,b) a = max(a,b)
#define CHMIN(a,b) a = min(a,b)
#define FIND(x,key) x.find(key) != x.end()
#define IN_RANGE_V2(v,k,x,y) (0<=x+dx[k]&&x+dx[k]<v[y].size()&&0<=y+dy[k]&&y+dy[k]<v.size())
#define debug(x) cerr<<__LINE__<<": "<<(#x)<<" = "<<(x)<<endl;
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
#define PRINT_ARRAY_H(a) REPALL(__i,a) {cout<<a[__i]<<(__i != a.size()-1 ? " " : "");} newline;
#define PRINT_ARRAY_V(a) REPALL(__i,a) {cout<<a[__i]<<endl;}
#define e1 first
#define e2 second
#define newline putchar('\n')
#define cspace ' '
#define sspace " "
const int INF = 1e7;
const ll MOD = 1e9 + 7;
const double pi = 3.141592653589793;
const VI dx = {1, 0, -1, 0};
const VI dy = {0, 1, 0, -1};
//const VI dx = {1, 1, 0, -1, -1, -1, 0, 1};
//const VI dy = {0, 1, 1, 1, 0, -1, -1, -1};

void solve()
{
    ll a, b, c, d, n, m, l, r, k, x, y, z, ans = 0ll;
    string s, t;
    cin>>n;
    l = 0, r = n;
    ll mid = (l + r) / 2;;
    string s0;
    cout<<0<<endl;
    cin>>s0;
    if (s0 == "Vacant") {
        return;
    }

    while (true) {
        mid = (l + r) / 2;
        cout<<mid<<endl;
        cin>>s;

        if (s == "Vacant") {
            break;
        } else if (s == s0) {
            if (l % 2 == mid % 2) {
                l = mid;
                s0 = s;
            } else {
                r = mid;
            }
        } else {
            if (l % 2 == mid % 2) {
                r = mid;
            } else {
                l = mid;
                s0 = s;
            }
        }
    }
}

int main()
{
    cout<<fixed<<setprecision(20);
    int __t = 1;
    //cin>>__t;
    REP(i,__t) {
        solve();
    }
    return 0;
}


#include<bits/stdc++.h>
const int N = 5005;
const long long inf = 1e18;
using namespace std;

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

int n, ans;
long long dp[N][N], Min[N];

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++){
        int x, y; cin >> x >> y;
        x += y;
        mv.push_back(ii(x, y));
    }
    sort(mv.begin(), mv.end());
    for (int i = 0; i < N; i++) Min[i] = inf;
    Min[0] = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = i; j >= 1; j--){
            if (mv[i-1].first - mv[i-1].second >= Min[j-1]) dp[i][j] = Min[j-1] + mv[i-1].second;
            else dp[i][j] = inf;
            Min[j] = min(Min[j], dp[i][j]);
            if (dp[i][j] != inf) ans = max(ans, j);
        }
    }
    cout << ans;
}

#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
ll dp[5555];
int main(void)
{
    int n;
    cin>>n;
    vector < pii > s(n);
    for (auto &it : s)
        cin>>it.fi>>it.se;
    sort(all(s),[&](pii x,pii y)
         {
            return (x.fi + x.se) < (y.fi + y.se);
         });
    for (int i = 1;i <= n;++i)
        dp[i] = 1e18;
    dp[0] = 0;
    for (auto it : s)
        for (int i = n;i;--i)
            if (dp[i - 1] <= it.fi)
                smin(dp[i],dp[i - 1] + it.se);
    int ans = 0;
    for (int i = 0;i <= n;++i)
        if (dp[i] < 1e18)
            ans = i;
    cout << ans << '\n';
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define iinf 2000000000
#define linf 1000000000000000000LL
#define ulinf 10000000000000000000ull
#define MOD1 1000000007LL
#define mpr make_pair
typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned long UL;
typedef unsigned short US;
typedef pair < int , int > pii;
clock_t __stt;
inline void TStart(){__stt=clock();}
inline void TReport(){printf("\nTaken Time : %.3lf sec\n",(double)(clock()-__stt)/CLOCKS_PER_SEC);}
template < typename T > T MIN(T a,T b){return a<b?a:b;}
template < typename T > T MAX(T a,T b){return a>b?a:b;}
template < typename T > T ABS(T a){return a>0?a:(-a);}
template < typename T > void UMIN(T &a,T b){if(b<a) a=b;}
template < typename T > void UMAX(T &a,T b){if(b>a) a=b;}
int n,m,a[20][20],pc[20][1000000],dp[20][1000000],rv[1000000];
int main(){
    // inputting start
    // 数据结构记得初始化！ n，m别写反！
    int i,j,k,u,v,w;
	scanf("%d%d",&n,&m);
	for(i=0;i<m;++i){
		scanf("%d%d%d",&u,&v,&w);
		--u;--v;
		a[u][v]=a[v][u]=w;
	}
    #ifdef LOCAL
        TStart();
    #endif
    // calculation start
    // 数据结构记得初始化！ n，m别写反！
	for(i=0;i<n;++i) rv[1<<i]=i;
    for(i=0;i<n;++i){
		for(j=0;j<n;++j){
			for(k=0;k<(1<<n);++k){
				if(k&(1<<j)) pc[i][k]+=a[i][j];
			}
		}
	}
	for(i=0;i<n;++i) fill(dp[i],dp[i]+(1<<n),iinf);
	dp[0][1]=0;
	for(j=0;j<(1<<n);++j){
		for(i=0;i<n;++i){
			if(!(j&(1<<i)) || dp[i][j]==iinf) continue;
			int v=dp[i][j],msk=(((1<<n)-1)^j),cst=0;
			for(k=0;k<=msk;){
				UMIN(dp[i][j|k],v+cst);
				int cp=msk;
				while(cp && (cp&(-cp))==(k&(-k))){
					int cv=(k&(-k));
					cst-=pc[rv[cv]][j^(1<<i)];
					k^=cv;
					cp^=cv;
				}
				if(!k && !cp) break;
				int cv=cp&(-cp);
				cst+=pc[rv[cv]][j^(1<<i)];
				k|=cv;
			}
			for(k=0;k<n;++k){
				if(a[i][k] && !(j&(1<<k))){
					UMIN(dp[k][j|(1<<k)],v+pc[k][j^(1<<i)]);
				}
			}
		}
	}
	printf("%d\n",dp[n-1][(1<<n)-1]);
    #ifdef LOCAL
        TReport();
    #endif
    return 0;
}


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

// Acknowledgement: Special thanks to kyomukyomupurin, who developed this
// template.
template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int n = 0;
  for (auto e : vec) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int n = 0;
  for (auto e : st) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int n = 0;
  for (auto e : mp) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#ifdef LOCAL
#define debug(...) \
  std::cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}
using namespace std;
using int64 = long long;

map<int64, int64> decomposition(int64 N) {
  map<int64, int64> result;
  int64 tmp = N;
  int64 amari;
  for (int64 i = 2; i * i <= N; i++) {
    if (tmp == 1) {
      break;
    }
    amari = tmp % i;
    if (amari == 0) {
      result[i] = 0;
      while (amari == 0) {
        tmp /= i;
        result[i]++;
        amari = tmp % i;
      }
    }
  }
  if (tmp != 1) result[tmp] = 1;
  return result;
}

int main() {
  int64 A, B;
  cin >> A >> B;
  int64 gcd = __gcd(A, B);
  map<int64, int64> mp = decomposition(gcd);
  cout << mp.size() + 1 << endl;
  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>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)

const int INF = 1e9 + 10;

int A, B;

int main() {
    cin >> A >> B;
    cout << A * B << endl;
}


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

int base[3] = {0, 0, 0};

void Hit()
{
	if (base[2] == 1)
	{
		base[2] = 0;
	}
	if (base[1] == 1)
	{
		base[2] = 1;
	}
	if (base[0] == 1)
	{
		base[1] = 1;
	}
	else if (base[0] == 0)
	{
		base[0] = 1;
	}

}

void Homerun()
{
	for (int i = 0; i < 3; i++)
	{
		base[i] = 0;
	}

}

int main()
{
	int out = 0;
    int score = 0;
	int n;
	string s;
    vector <string> event;
	int eventnum = 0;

	cin >> n;
	int a = 0;
	for (int i = 0; i < 3 * n; i++)
	{
		while (true)
		{
			cin >> s;
			event.push_back(s);
			if (event.at(a) == "OUT")
			{
				a += 1;
				eventnum += 1;
				break;
			}
			else
			{
				a += 1;
				eventnum += 1;
			}

		}
	}

	for (int i = 0; i < eventnum; i++)
	{
		if (event.at(i) == "HIT")
		{
			if (base[2] == 1)
			{
				score += 1;
			}
			Hit();
		}
		else if (event.at(i) == "HOMERUN")
		{
			score += base[0] + base[1] + base[2] + 1;
			Homerun();
		}
		else
		{
			out += 1;
			if (out == 3)
			{
				cout << score << endl;
				for (int i = 0; i < 3; i++)
				{
					base[i] = 0;
				}
				score = 0;
				out = 0;
			}
		}
	}

	return 0;
}

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
  int n;
  cin >> n;
  while(n--) {
    string s;
    int out = 0;
    vector<int> rui(3);
    int ten = 0;
    while(out < 3) {
      // FOR(it,rui)
      //   cout << *it << " ";
      // cout << endl;
      cin >> s;
      if (s == "HIT") {
        if (rui[2]) ten++;
        rui[2] = rui[1];
        rui[1] = rui[0];
        rui[0] = 1;
      } else if (s == "HOMERUN") {
        REP(i,3) {
          ten += rui[i];
        }
        ten++;
        rui = vector<int>(3);
      } else
        out++;
    }
    cout << ten << endl;
  }
}


#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <sstream>
#include <string>
#include <utility>
#include <map>
#include <memory>
#include <set>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>
// #include <array>

using namespace std;

class MSTree
{
public:
  int solve();
};

int MSTree::solve()
{
  int n;
  cin >> n;

  vector<vector<int>> adj(n, vector<int>(n));
  list<int> t, vt;

  for ( auto i = 0; i < n; ++i )
    for ( auto j = 0; j < n; ++j )
      cin >> adj[i][j];

  t.push_back( 0 );

  for ( auto i = 1; i < n; ++i )
    vt.push_back( i );

  int w = 0;

  while ( vt.size() )
    {
      int mw = 4000;
      list<int>::iterator itm;

      for ( auto ita = t.begin(); ita != t.end(); ++ita )
        for ( auto itb = vt.begin(); itb != vt.end(); ++itb )
          {
            if ( adj[*ita][*itb] >= 0 && mw > adj[*ita][*itb] )
              {
                itm = itb;
                mw = adj[*ita][*itb];
              }
          }

      w += mw;
      t.push_back( *itm );
      vt.erase( itm );
    }

  cout << w << endl;

  return 0;
}

int main()
{
  MSTree m;

  m.solve();

  return 0;
}

//g++ -std=gnu++14 a.cpp

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>
#include <stdio.h>

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;
ll MODP = 998244353;

ll per(ll a){
  ll res = 1;
  for(int i = 1;i <= a;i++){
    res *= i;
  }
  return res;
}

int main(){
  ll N;
  cin >> N;
  vector<long double> x(N),y(N);
  rep(i,N)cin >> x[i] >> y[i];
  vector<vector<int>> kumi;
  vector<int> v;
  for(int i = 1;i <= N;i++)v.push_back(i);
  do{
    kumi.push_back(v);
  }while(next_permutation(v.begin(), v.end()));
  long double ans = 0;
  for(auto a : kumi){
    rep(i,a.size()-1){
      long double t = (x[a[i]-1]-x[a[i+1]-1])*(x[a[i]-1]-x[a[i+1]-1]);
      t += (y[a[i]-1]-y[a[i+1]-1])*(y[a[i]-1]-y[a[i+1]-1]);
      ans += sqrt(t);
    }
  }
  long double all = kumi.size();
  ans /= all;
  cout << fixed << setprecision(8) << ans << endl;

  return 0;
}


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

template<typename T>
void chmax(T &a,T b){
  if(a<b)a=b;
}
struct maxhist{
  vector<int> hist;
  struct rect{int height,idx;};

  void add_hist(int a){
    hist.push_back(a);
  }

  int get_max(){
    int res=0;
    stack<rect> s;
    for(int j=0;j<hist.size();j++){
      if((!s.size())||s.top().height<hist[j])s.push({hist[j],j});
      else if(s.top().height>hist[j]){
        int left;
        while(s.top().height>hist[j]){
          rect tmp=s.top();s.pop();
          left=tmp.idx;
          //chmax(res,tmp.height*(j-left));
          chmax(res,(tmp.height+1)*(j-left+1));
          if(!s.size())break;
        }
        s.push({hist[j],left});
      }
    }
    while(s.size()){
      rect tmp=s.top();s.pop();
      //chmax(res,tmp.height*(hist.size()-tmp.idx));
      chmax(res,(tmp.height+1)*((int)hist.size()-tmp.idx+1));
    }
    return res;
  }
};
struct maxrect{
  vector<vector<bool>> rect;

  void add_line(vector<bool> &v){
    rect.push_back(v);
  }
  void add_dot(int h,bool f){
    if(rect.size()<=h)rect.resize(h+1);
    rect[h].push_back(f);
  }

  int get_max(){
    int res=0;
    int h=rect.size();
    vector<vector<int>> hist(h);
    for(int i=0;i<h;i++)hist[i].resize(rect[i].size());
    for(int i=0;i<h;i++){
      maxhist mh;
      for(int j=0;j<hist[i].size();j++){
        if(i){
          if(hist[i-1].size()<=j)hist[i][j]=rect[i][j];
          else hist[i][j]=(hist[i-1][j]+rect[i][j])*rect[i][j];
        }
        else hist[i][j]=rect[i][j];
        mh.add_hist(hist[i][j]);
      }
      chmax(res,mh.get_max());
    }
    return res;
  }
};

signed main(){
  int h,w;cin>>h>>w;
  vector<string> s(h);
  for(int i=0;i<h;i++)cin>>s[i];
  maxrect m;
  vector<bool> f(w-1);
  for(int i=1;i<h;i++){
    for(int j=0;j<w-1;j++){
      int a=(s[i-1][j]=='#')+(s[i-1][j+1]=='#')+(s[i][j]=='#')+(s[i][j+1]=='#');
      f[j]=(a&1)^1;
    }
    m.add_line(f);
  }
  cout<<max({h,w,m.get_max()})<<endl;
}

/*
解説AC
広義唐草模様の面積求めたくなって、どこがダメな場所かも分かったけど最大長方形のアルゴリズムを知らず
時間かければ自分で思いつきそうな気もするけどコスパ悪いし見ていいでしょ
面白かった
*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int mod=998244353;
int dp[4][310*310],a[310];
inline int add_mod(int x){
	return x<mod?x:x-mod;
}
int main(){
	int n,ret=1,sum=0,minus=1;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",a+i);
		ret=(ll)ret*3%mod;
		minus=add_mod(minus+minus);
		sum+=a[i];
	}
	ret=add_mod(ret+mod-3);
	minus=add_mod(minus+mod-2);
	ret=add_mod(ret+mod-(ll)minus*3%mod);
	memset(dp,0,sizeof dp);
	dp[0][0]=1;
	for(int i=1;i<=n;i++){
		for(int j=sum;j>=a[i];j--){
			for(int s=0;s<4;s++){
				dp[s|1][j]=add_mod(dp[s|1][j]+dp[s][j-a[i]]);
				dp[s|2][j]=add_mod(dp[s|2][j]+dp[s][j-a[i]]);
			}
		}
	}
	for(int i=1;i+i<=sum;i++)
		ret=add_mod(ret+mod-(ll)dp[3][i]*3%mod);
	printf("%d\n",ret);
	return 0;
}


#include<cstdio>
#include<vector>
#include<map>
#include<climits>
#include<algorithm>
#include<iostream>
using namespace std;
typedef pair<int,int> Pt;
#define MAX 1000001
#define fr first
#define sc second
int main(){
  string s;
  int ans = 0;
  cin >> s;
  for(int i=0;i<s.size();){
    int a = 0,b = 0,c = 0;
    for(;s[i]=='J';a++) i++;
    for(;s[i]=='O';b++) i++;
    for(;s[i]=='I';c++) i++;
    if(a>=b && b<=c) ans = max(ans,b);
  }
  cout << ans << endl;
}

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

int main() {
    ios_base::sync_with_stdio(false);
    ll r;
    cin >> r;
    if(r < 1200) {
        cout << "ABC\n";
    } else if (r < 2800) {
        cout << "ARC\n";
    } else {
        cout << "AGC\n";
    }
    return 0;
}


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

void chmax(string &a, string b) {
  if (a == "-")
    a = b;
  else if (a.size() < b.size())
    a = b;
  else if (a.size() == b.size()) {
    if (a < b) a = b;
  }
}

long long num[10] = {2, 5, 5, 4, 5, 6, 3, 7, 6};
string dp[11000];

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

  for (int i = 0; i < 11000; ++i) dp[i] = "-";
  dp[0] = "";
  for (int i = 0; i <= N; ++i) {
    if (dp[i] == "-") continue;
    for (auto a : A) {
      string b = dp[i] + (char)('0' + a);
      chmax(dp[i + num[a - 1]], b);
    }
  }
  cout << dp[N] << endl;
}

#include <bits/stdc++.h>

#define ll long long
#define sz(x) (int)x.size()

using namespace std;

int main(){
	int n,k;
	cin>>n>>k;
	vector<int> a(n);
	for(int&i:a)cin>>i;
	sort(a.begin(), a.end());
	reverse(a.begin(), a.end());
	ll ans=0;
	for(int i=0;i<k;i++)ans+=a[i];
	cout<<ans;

}


#include <iostream>

int main() {
  int N;
  std::cin >> N;

  int abc_in;
  if (N % 111 == 0)
    abc_in = N;
  else
    abc_in = ((N / 111) + 1) * 111;

  std::cout << abc_in << std::endl;
  return 0;
}

#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define ld long double
using namespace std;
const int N = 1e6 + 5;
const int MOD = 1e9 + 7;

int main(){
	fast;
	string s;
	cin >> s;
	if(s == "SUN") cout << "7\n";
	else if(s == "SAT") cout << "1\n";
	else if(s == "FRI") cout << "2\n";
	else if(s == "THU") cout << "3\n";
	else if(s == "WED") cout << "4\n";
	else if(s == "TUE") cout << "5\n";
	else if(s == "MON") cout << "6\n";
	return 0;
}


#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF (1<<30)-1
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(b<a) { a=b; return 1; } return 0; }

int main(){
  string sa,sb,sc; cin >> sa >> sb >> sc;
  int a = 0, b = 0, c = 0;
  char now = 'a';
  char winner;
  while(true){
    if(now == 'a'){
      if(a == sa.size()){
        winner = 'A';
        break;
      }
      now = sa[a];
      a++;
    }else if(now == 'b'){
      if(b == sb.size()){
        winner = 'B';
        break;
      }
      now = sb[b];
      b++;
    }else if(now == 'c'){
      if(c == sc.size()){
        winner = 'C';
        break;
      }
      now = sc[c];
      c++;
    }
  }
  cout << winner;
  cout << "\n";
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
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;
}

#ifdef DEBUG
void debug() { cerr << "\n"; }
template <class T> void debug(const T &x) { cerr << x << "\n"; }
template <class T, class... Args> void debug(const T &x, const Args &... args) {
    cerr << x << " ";
    debug(args...);
}
template <class T> void debugVector(const vector<T> &v) {
    for(const T &x : v) {
        cerr << x << " ";
    }
    cerr << "\n";
}
#else
template <class T, class... Args>
void debug(const T &x, const Args &... args) {}
template <class T> void debugVector(const vector<T> &v) {}
#endif

using ll = long long;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s[3];
    for(int i = 0; i < 3; i++) {
        cin >> s[i];
    }
    int nowTurn = 0;
    int nowId[3] = {0, 0, 0};
    while(1) {
        if(nowId[nowTurn] >= s[nowTurn].size()) {
            cout << (char)('A' + nowTurn) << endl;
            break;
        }
        int nxtTurn = s[nowTurn][nowId[nowTurn]] - 'a';
        nowId[nowTurn]++;
        nowTurn = nxtTurn;
    }
}


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

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000000
#define MOD 1000000007
#define MAXR 100000
#define _GLIBCXX_DEBUG

int threemax(int a, int b, int c) {
	if (a >= b && a >= c) {
		return a;
	}
	else if (b >= a && b >= c) {
		return b;
	}
	else {
		return c;
	}
}

int threemin(int a, int b, int c) {
	if (a <= b && a <= c) {
		return a;
	}
	else if (b <= a && b <= c) {
		return b;
	}
	else {
		return c;
	}
}

void chmaxl(ll &a,ll b){
	if(a<b){
		a=b;
	}
	return;
}

void chminl(ll &a,ll b){
	if(a>b){
		a=b;
	}
	return;
}

void chmaxi(int &a,int b){
	if(a<b){
		a=b;
	}
	return;
}

void chmini(int &a,int b){
	if(a>b){
		a = b;
	}
	return;
}

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

#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
int main(){
    int n;
    cin >> n;
    string s,t;
    cin >> s>>t;
    for(int i=n;i>=1;i--){
        if(t.substr(0,i)==s.substr(n-i,i)){
            cout<<2*n-i<<endl;
            return 0;

        }
    }
    cout<<2*n<<endl;
  return 0;
}


#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
int n,a,b,c,d,jun[101],x;
typedef pair<int,int> P;
P t[101];

bool cmp(const P& a,const P& b){
	return a.first == b.first ? a.second < b.second : a.first > b.first;
}

int main()
{
	cin>>n;
	for(int i=1;i<=n;i++) t[i].second=i;
	for(int i=1;i<=n*(n-1)/2;i++){
		cin>>a>>b>>c>>d;
		if(c>d) t[a].first+=3;
		else if(c<d) t[b].first+=3;
		else {t[a].first++; t[b].first++;}
	}
	sort(t+1,t+n+1,cmp);
	for(int i=1;i<=n;i++){
		if(i>1&&t[i].first==t[i-1].first){
			jun[t[i].second]=x;
		}
		else{
			jun[t[i].second]=i;
			x=i;
		}
	}
	for(int i=1;i<=n;i++){
		cout<<jun[i]<<endl;
	}
}

#include <bits/stdc++.h>

using namespace std;
#define inf             0x3f3f3f3f
#define INF             2e18
#define eps             1e-9

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define fRead           freopen("input.txt","r",stdin)
#define fWrite          freopen("output.txt","w",stdout)

#define LL              long long
#define ull            unsigned long long
#define PI              acos(-1.0)
#define pb              push_back
#define mk              make_pair
#define pii             pair<int,int>
#define pLL             pair<LL,LL>
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define SQR(a)          ((a)*(a))
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define vi              vector <int>
#define vL              vector <LL>
#define LB(a,x)         (lower_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which does not compare less than val.
#define UB(a,x)         (upper_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which compares greater than val.
#define prec(n)         fixed << setprecision(n)

#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())

#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 REP(i,b)        for(int i=0;i<b;i++)
#define IT(it,x)	    for(it=x.begin();it!=x.end();it++)
vector<pLL>v;
LL n;
double s=0;
void f(vector<pLL>vt)
{
    LL x=v[0].ff,y=v[0].ss;
    for(LL i=0;i<v.size();i++)
    {
        s+=sqrtl((v[i].ff-x)*(v[i].ff-x)+(v[i].ss-y)*(v[i].ss-y));
    }
}
int main()
{
   cin>>n;
   for(LL i=0;i<n;i++)
   {
       LL x,y;
       cin>>x>>y;
       v.pb({x,y});
   }
   sort(all(v));
   do{
        f(v);

   } while(next_permutation(all(v)));
   LL x=1;
   for(LL i=1;i<=n;i++)
    x=x*i;
//    cout<<s<<" "<<x<<endl;
   cout<<prec(10)<<s/x;

}


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

#define int long long

const int maxn = 1e5 + 10;
int n, a[maxn];
int c0, c1, cnt, GCD;

bool solve() {
	c1 = 0, c0 = 0, cnt = 0, GCD = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] == 1) {
			c1++;
			cnt++;
			continue;
		}
		if (a[i] % 2) {
			c1++;
			a[i]--;
		}
		else
			c0++;
		GCD = __gcd(GCD, a[i]);
	}
	if (c0 % 2) 		 return 1;
	if (cnt || c1 > 1) return 0;
	for (int i = 0; i < n; i++) a[i] /= GCD;
	return !solve();
}
int32_t main() {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	if (solve())
		cout << "First";
	else
		cout << "Second";
	return 0;
}

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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  ll N;
  IN(N);

  ll start = 0;
  ll end = N-1;
  ll start_sex = 0;
  string str;
  std::cout << 0 << std::endl;
  IN(str);
  if(str=="Male") start_sex = 0;
  else if(str=="Female") start_sex = 1;
  else return 0;

  while(end-start>1){
    ll mid = (start+end)/2;
    std::cout << mid << std::endl;
    IN(str);
    ll sex = 0;
    if(str=="Male") sex = 0;
    else if(str=="Female") sex = 1;
    else return 0;
    if((mid-start)&1){
      if(start_sex!=sex){
        start = mid;
        start_sex = sex;
      }else{
        end = mid;
      }
    }else{
      if(start_sex!=sex){
        end = mid;
      }else{
        start = mid;
        start_sex = sex;
      }
    }
  }

  std::cout << start << std::endl;
  IN(str);
  if(str=="Vacant") return 0;

  std::cout << end << std::endl;
  IN(str);

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define Time (double)clock()/CLOCKS_PER_SEC
const int N = 601, C = 2e5 + 7;
int sqr[C];
int n, num[N][N], d[2];
vector <int> g[2][N * N];
bool c[2][N * N], used[N * N];
void dfs(bool t, int u) {
    used[u] = 1;
    for (int v : g[t][u]) {
        if (!used[v]) {
            c[t][v] = c[t][u] ^ 1;
            dfs(t, v);
        }
    }
}
vector <ii> ans[2][2];
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    for (int i = 0; i < C; ++i) sqr[i] = -1;
    for (int i = 0; i < C; ++i) if (i * i < C) sqr[i * i] = i;
    cin >> n >> d[0] >> d[1];
    int p = 0;
    for (int i = 0; i < 2 * n; ++i)
        for (int j = 0; j < 2 * n; ++j)
            num[i][j] = p++;
    for (int t = 0; t < 2; ++t) {
        vector <ii> v;
        for (int i = 0; i * i <= d[t]; ++i)
            if (sqr[d[t] - i * i] != -1) {
                v.app(mp(i, sqr[d[t] - i * i]));
                v.app(mp(i, -sqr[d[t] - i * i]));
                v.app(mp(-i, sqr[d[t] - i * i]));
                v.app(mp(-i, -sqr[d[t] - i * i]));
            }
        for (int i = 0; i < 2 * n; ++i)
            for (int j = 0; j < 2 * n; ++j)
                for (auto e : v) if (0 <= i + e.f && i + e.f < 2 * n && 0 <= j + e.s && j + e.s < 2 * n)
                    g[t][num[i][j]].app(num[i + e.f][j + e.s]);
        memset(used, 0, sizeof used);
        for (int i = 0; i < 4 * n * n; ++i)
            if (!used[i]) {
                dfs(t, i);
            }
    }
    for (int i = 0; i < 4 * n * n; ++i) ans[c[0][i]][c[1][i]].app(mp(i / (n << 1), i % (n << 1)));
    for (int i = 0; i < 2; ++i)
        for (int j = 0; j < 2; ++j)
            if (ans[i][j].size() >= n) {
                cerr << Time << '\n';
                for (int k = 0; k < n * n; ++k) cout << ans[i][j][k].f << ' ' << ans[i][j][k].s << '\n';
                exit(0);
            }
    exit(1);
}

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define qwq(x) cout<<"# "<<#x<<" = "<<x<<endl;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define f(x,y) g[(x)][(y)+52]
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int N=1005;
int f[N][N],n,d1,d2,cnt;

void doit(int d){
	int k=1;
	while(d%4==0)d>>=2,k<<=1;
	REP(i,n*2)REP(j,n*2)
		f[i][j]+=(d&1)&&(i/k+j/k)%2==0||!(d&1)&&i/k%2==0;
}

int main(){
	read(n),read(d1),read(d2);
	doit(d1),doit(d2);
	REP(i,n*2)REP(j,n*2)
		if(f[i][j]==2&&cnt<n*n)
			printf("%d %d\n",i,j),++cnt;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> pll;
const int INF=1e9;
const ll MOD=1e9+7;

ll gcd(ll x,ll y){
    if(y==0) return 0;
    return gcd(y,x%y);
}

int dis2(int x1,int y1,int x2,int y2){
    return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
}

int main(){
    int n;cin>>n;
    int a[n];
    double avg=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        avg+=a[i];
    }
    avg=(double)avg/(double)n;
    double sub=1000000;
    int ans=-1;
    for(int i=0;i<n;i++){
        if(sub>abs(a[i]-avg)){
            sub=abs(a[i]-avg);
            ans=i;
        }
    }
    cout<<ans<<endl;
}

#include <iostream>
using namespace std;

int bubbleSort(int a[],int n){
	int sw=0;
	bool flag=1;
	for(int i=0;flag;i++){
		flag=0;
		for(int j=n-1;j>=i+1;j--){
			if(a[j]<a[j-1]){
				swap(a[j],a[j-1]);
				flag=1;
				sw++;
			}
		}
	}
	return sw;
}

int main(){
	int n,a[100],sw;
	cin>>n;
	for(int i=0;i<n;i++) cin>>a[i];
	sw=bubbleSort(a,n);
	for(int i=0;i<n;i++){
		if(i) cout<<" ";
		cout<<a[i];
	}
	cout<<endl;
	cout<<sw<<endl;
	return 0;
}


#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <vector>

using namespace std;

typedef long long LL;
static const LL INF = 1LL << 60;

template<typename T, int SIZE, T DEF_VAL, const T& Compare(const T&, const T&)>
class SegmentTree {
	vector<T> val;
public:
	SegmentTree() : val(SIZE * 2, DEF_VAL) { }
	void update(int i, const T& value) {
		i += SIZE;
		val[i] = value;
		while (i > 1) i >>= 1, val[i] = Compare(val[i * 2], val[i * 2 + 1]);
	}
	T get(LL a, LL b, int l = 0, int r = SIZE, size_t i = 1) {
		if (r <= a || b <= l) return DEF_VAL;
		if (a <= l && r <= b) return val[i];
		return Compare(get(a, b, l, (l + r) / 2, i * 2), get(a, b, (l + r) / 2, r, i * 2 + 1));
	}
	LL find_leftmost_index(LL a, LL b, const T& value, int l = 0, int r = SIZE, int i = 1) {
		if (Compare(val[i], value) != val[i]) return -1;
		if (r <= a || b <= l) return -1;
		if (i >= SIZE) return i - SIZE;
		LL leftmost_index = find_leftmost_index(a, b, value, l, (l + r) / 2, i * 2);
		if (leftmost_index >= 0) return leftmost_index;
		return find_leftmost_index(a, b, value, (l + r) / 2, r, i * 2 + 1);
	}
	LL find_rightmost_index(LL a, LL b, const T& value, int l = 0, int r = SIZE, int i = 1) {
		if (Compare(val[i], value) != val[i]) return -1;
		if (r <= a || b <= l) return -1;
		if (i >= SIZE) return i - SIZE;
		LL rightmost_index = find_rightmost_index(a, b, value, (l + r) / 2, r, i * 2 + 1);
		if (rightmost_index >= 0) return rightmost_index;
		return find_rightmost_index(a, b, value, l, (l + r) / 2, i * 2);
	}
};

void solve(long long H, long long W, std::vector<long long> &A, std::vector<long long> &B) {
	SegmentTree<long long, 1 << 18, INF, min> st;
	for (int i = 0; i < W; ++i) {
		st.update(i, 0);
	}
	for (LL y = 0; y < H; ++y) {
		LL a = A[y], b = B[y];
		while (true) {
			LL min_value = st.get(a, b);
			if (min_value == INF) break;
			LL index = st.find_leftmost_index(a, b, min_value);
			LL next_cost = min_value + b - index;
			if (b < W && next_cost < st.get(b, b + 1)) {
				st.update(b, next_cost);
			}
			st.update(index, INF);
		}
		LL cost = y + 1 + st.get(0, W);
		cout << (cost < INF ? cost : -1) << endl;
	}
}

int main() {
    long long H;
	scanf("%lld", &H);
	long long W;
	scanf("%lld", &W);
	std::vector<long long> A(H);
	std::vector<long long> B(H);
	for (int i = 0; i < H; i++) {
		scanf("%lld", &A[i]); A[i]--;
		scanf("%lld", &B[i]);
	}
	solve(H, W, A, B);
	return 0;
}

#include <bits/stdc++.h>
#include <time.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P  = pair<ll,ll>;
using vi = vector<ll>;
using vv = vector<vi>;
const ll INF = 1001001001;
const ll NUM = 1<<10;

//(開始, 今)を管理
//例:
//(0,0), (1,1), (2,2), (3,3), (4,4), (5,5)
//壁(1,2)   .      .(該当領域)
//(0,0), (1,3), (2,3), (3,3), (4,4), (5,5) ->(1,3),(2,3)は消す
//(0,0),               (3,3), (4,4), (5,5)
//壁(2,3)                 .(該当領域)
//(0,0),               (3,4), (4,4), (5,5) ->(3,4)は消す
//(0,0),                      (4,4), (5,5)
//
//・順序集合(map)を使う: map[今]=開始の最大値
//・ans = min(今-開始), multisetで管理
//・該当領域+1の範囲で開始が一番右のものだけ残す
//・それ以外はansからもmapからも消す

//

int main(){
    int h,w;
    cin >> h >> w;
    map<int,int> s;
    multiset<int> m;
    rep(i,w)s[i] = i;
    rep(i,w)m.insert(0);

    rep(i,h){
        int l,r;
        cin>>l>>r;
        --l;

        auto itr = s.lower_bound(l);
        int maxstart= -1;
        while(itr!=s.end() && itr->first<=r){
            maxstart= max(maxstart, itr->second);
            int c = itr->first - itr->second;
            m.erase(m.find(c));
            s.erase(itr++);
            //itr=s.erase(itr);//これでもいい
            //s.erase(*itr); itr++;//これはだめ
        }
        if(r<w && maxstart != -1){
            s[r] = maxstart;
            m.insert(r-maxstart);
        }
        int ans = -1;
        if(!m.empty())
            ans = *m.begin() + (i+1);
        cout<<ans<<endl;
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <queue>
using namespace std;
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];
    map<int, int> odd, even;
    for(int i = 0; i < N; ++i){
        if(i%2 == 0) even[V[i]]++;
        else odd[V[i]]++;
    }
    priority_queue<pair<int, int> > qOdd, qEven;
    qOdd.emplace(0,0); qEven.emplace(0,0);
    for(auto it : odd) qOdd.emplace(it.second, it.first);
    for(auto it : even) qEven.emplace(it.second, it.first);

    if(qOdd.top().second != qEven.top().second) {
        int ans = N - qOdd.top().first - qEven.top().first;
        cout << ans << '\n';
    } else {
        int a = qOdd.top().first;
        int b = qEven.top().first;
        qOdd.pop();
        qEven.pop();
        int c = qOdd.top().first;
        int d = qEven.top().first;
        int ans = min(N - a - d, N - b - c);
        cout << ans << '\n';
    }
    return 0;
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n, x[100], y[100];
map<double, int> mp;
double TAU = atan2(0, -1) * 2;

void add(double l, double r) {
	if(l < 0.0) { add(1.0 + l, 1.0); add(0, r      ); return; }
	if(r > 1.0) { add(      l, 1.0); add(0, r - 1.0); return; }
	mp[l]++;
	mp[r]--;
}

int main() {
	cin >> n;
	inc(i, n) { cin >> x[i] >> y[i]; }

	inc(i, n) {
		mp.clear();
		mp[0.0] = 0;
		mp[1.0] = 0;

		inc(j, n) {
			if(i == j) { continue; }

			double v = atan2(y[j] - y[i], x[j] - x[i]) / TAU + 0.5;
			add(v - 0.25, v + 0.25);
		}

		double ans = 0.0, pre = 0.0;
		int c = 0;
		for(auto && e: mp) {
			if(c == 0) { ans += e.FI - pre; }
			c += e.SE;
			pre = e.FI;
		}

		printf("%.8f\n", ans);
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++)
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll mod = 2019;

int main() {
    ll l, r;
    cin >> l >> r;
    map<ll, ll> m;
    for (ll i = l; i <= r && i <= l+5000; i++){
        m[i%mod]++;
    }
    ll ans = 2020;
    vector<ll> a;
    for (auto x: m){
        rep1(i, x.second) a.push_back(x.first);
    }
    ll n = a.size();
    for (ll i=0; i<(n); i++){
        for (ll j=i+1; j<(n); j++){
            ans = min(ans, a[i]*a[j]%2019);
        }
    }
    cout << ans << endl;
    //printf("%.12f", ans);
}

#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;
ll search(ll l, ll r) {
  ll ret = INF;
  for (ll i = l; i <= r; i++) {
    for (ll j = i + 1; j <= r; j++) {
      ret = min((i * j) % 2019, ret);
    }
  }
  return ret;
}
int main() {
  ll l, r;
  cin >> l >> r;
  if (l <= 2019 && 2019 <= r) {
    cout << 0 << endl;
  } else if (l < 2019 && r < 2019) {
    cout << search(l, r) << endl;
  } else if (r - l < 2019) {
    cout << search(l, r) << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;
}


#include <bits/stdc++.h>

const int N = 100054;

int n, K, ans;
int p[N], fc[N], nc[N], f[N];

inline void up(int &x, const int y) {x < y ? x = y : 0;}
inline void link(int x, int px) {nc[x] = fc[px], fc[px] = x;}

void dfs(int x, int dep = 0) {
	for (int y = fc[x]; y; y = nc[y]) dfs(y, dep + 1), up(f[x], f[y] + 1);
	if (dep > 1 && f[x] >= K - 1) ++ans, f[x] = -1;
}

int main() {
	scanf("%d%d%d", &n, &K, &ans), ans = ans != 1;
	for (int i = 2; i <= n; ++i) scanf("%d", p + i), link(i, p[i]);
	dfs(1), printf("%d\n", ans);
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define sz(x) ((int) ((x).size()))
typedef long long ll;
typedef long double ld;

int n, k, r, a[100100];
vector<int> e[100100];

int dfs(int i = 0) {
  int d = 0;
  for (int j : e[i])
    d = max(d, dfs(j) + 1);
  if (d + 1 >= k) {
    r += a[i] != 0;
    return -1;
  }
  return d;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(10);
  cin >> n >> k;
  for (int i = 0; i < n; i++)
    cin >> a[i], a[i]--;
  r += a[0] != 0;
  a[0] = 0;
  for (int i = 1; i < n; i++)
    e[a[i]].push_back(i);
  dfs();
  cout << r << "\n";
}


/*
Writer: SPD_9X2
https://atcoder.jp/contests/arc081/tasks/arc081_d

長方形にできる必要十分条件は、
内側にある四つ角の周り全てに関して、周りにある黒が偶数個
→そのような条件を満たす四つ角グリッドを考えると最大長方形になる

幅1の長方形に関しては全て作れるので、ans初期値はmax(H,W)
*/

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n,m) for(int (i)=(n);(i)<(m);(i)++)
#define rrep(i,n,m) for(int (i)=(n);(i)>(m);(i)--)
using ll = long long;
const ll mod = 1000000007;
const ll half = 500000004;

int LRIH(vector<int>& lis){

    vector<vector<int>> stk(0);

    int ans = 0;
    int N = lis.size();

    rep(i,0,N){

        if (stk.size() == 0){
            stk.push_back({lis[i],i});
        }else if (stk[stk.size()-1][0] < lis[i]){
            stk.push_back({lis[i],i});
        }else if (stk[stk.size()-1][0] > lis[i]){

            int lastpos = -1;

            while ( (stk.size()>0) && (stk[stk.size()-1][0] > lis[i])){

                int nh = stk[stk.size()-1][0];
                int np = stk[stk.size()-1][1];
                lastpos = np;
                stk.pop_back();

                ans = max(ans , (nh+1)*(i-np+1));
            }

            stk.push_back({lis[i] , lastpos});
        }
    }

    return ans;
}

int main(){

    int H,W;
    cin >> H >> W;

    vector<vector<char>> S(H,vector<char> (W));
    rep(i,0,H){
        rep(j,0,W){
            cin >> S[i][j];
        }
    }

    vector<vector<int>> lis(H-1,vector<int> (W-1,0));

    rep(i,0,H-1){
        rep(j,0,W-1){
            if (S[i][j] == '#') lis[i][j] += 1;
            if (S[i+1][j] == '#') lis[i][j] += 1;
            if (S[i][j+1] == '#') lis[i][j] += 1;
            if (S[i+1][j+1] == '#') lis[i][j] += 1;
            lis[i][j] %= 2;
        }
    }

    vector<vector<int>> hist(H-1,vector<int> (W,0));

    rep(i,0,H-1){
        rep(j,0,W-1){

            if (lis[i][j] == 0){
                if (i==0){
                    hist[i][j] = 1;
                }else{
                    hist[i][j] = hist[i-1][j] + 1;
                }
            }

        }
    }

    int ans = max(H,W);
    rep(i,0,H-1){
        ans = max(ans , LRIH(hist[i]));
    }

    cout << ans << endl;
}


#include <bits/stdc++.h>
#define MAX 100005
#define bit(x) (1ll << x)

using namespace std;

int n;
int cnt[64];
long long a[MAX], ans;

inline long long Rd() {
	long long x = 0; char ch = getchar();
	while(!isdigit(ch)) ch = getchar();
	while(isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
	return x;
}

struct linear_base {
	long long u[60];
	inline void insert(long long val) {
		for(int i = 59; i >= 0; --i) {
			if(val & bit(i)) {
				if(u[i]) val ^= u[i];
				else {
					u[i] = val;
					return;
				}
			}
		}
	}
	inline long long query() {
		long long res = 0;
		for(int i = 59; i >= 0; --i)
			if((res ^ u[i]) > res) res ^= u[i];
		return res;
	}
}lsk;

int main() {
	n = Rd();
	for(int i = 1; i <= n; ++i) {
		a[i] = Rd();
		for(int j = 59; j >= 0; --j)
			if(a[i] & bit(j)) ++cnt[j];
	}

	for(int i = 59; i >= 0; --i) {
		if(cnt[i] & 1) {
			ans += bit(i);
			for(int j = 1; j <= n; ++j) {
				if(a[j] & bit(i)) {
					a[j] ^= bit(i);
				}
			}
		}
	}
	for(int i = 1; i <= n; ++i) lsk.insert(a[i]);

	cout << ans + 2ll * lsk.query() << endl;
	return 0;
}

#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int a[220];
int n;
int main(){
    cin >> n;
    for(int i=0;i<2*n;i++){
        cin >> a[i];
    }
    sort(a,a+n*2);
    int len=0;
    for(int i=0;i<n;i++){
        len+=a[2*i];
    }
    cout << len;
}


#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const int INF=1e9;
const ll MX = 1e18;
const ll MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define YN {puts("YES");}else{puts("NO");}
const ll MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {fac[0] = fac[1] = 1;finv[0] = finv[1] = 1;inv[1] = 1;for (ll i = 2; i < MAX; i++){fac[i] = fac[i - 1] * i % MOD;inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;finv[i] = finv[i - 1] * inv[i] % MOD;}}
long long COM(ll n, ll k){if (n < k) return 0;if (n < 0 || k < 0) return 0;return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;}
ll llpow(ll n,ll i){ll cnt=n;  for(ll j=0;j<i-1;j++){n*=cnt;}return n;}

int main(){
  int a,b;
  cin>>a>>b;
  ll cnt=0;
  if(a<=b){
    cout<<min(abs(abs(a)-abs(b))+1,b-a)<<endl;
    return 0;
  }
  if(a>b){
    if(a>0&&b>0){
      cout<<a-b+2<<endl;
      return 0;
    }
    if(a<0&&b<0){
      cout<<a-b+2<<endl;
      return 0;
    }
    else{
      cout<<abs(abs(a)-abs(b))+1<<endl;
      return 0;
    }
  }
}

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

lint gcd(lint x, lint y) {
  if(x == 0) { return y; }
  else { return gcd(y%x,x); }
}

lint lcm(lint x, lint y) { return x/gcd(x,y)*y; }

int main() {
  lint x,y,ans; cin >> x >> y;

  if(abs(x) == abs(y)) {
    ans = 1;
  } else if(abs(x) < abs(y)) {
    ans = abs(y)-abs(x);
    if(x < 0) { ans++; }
    if(y < 0) { ans++; }
  } else if(abs(x) > abs(y)) {
    ans = abs(x)- abs(y);
    if(x > 0) { ans++; }
    if(y > 0) { ans++; }
  }

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


#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL -1
using namespace std;
const int64_t MOD = 1e9 + 7;

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

	int64_t rt = sqrt(N);
	for (int64_t i = rt; i > 0; i--) {
		if (N % i == 0) {
			//cout << i << endl;
			int64_t n = N / i;

			int64_t cnt = 0;
			int64_t m = N / i;
			while (m) {
				cnt++;
				m /= 10;
			}

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

#include<iostream>
using namespace std;

int count(long long n){
    int cnt=0;
    while(n>0){
        n/=10;
        cnt++;
    }
    return cnt;
}

int main(){
    long long n;
  	long long b;
    int cur=0;
  	int ans=100000;
    cin>>n;
    for(long long i=1;i*i<=n;i++){
       if(n%i==0){
       b=n/i;
       cur=max(count(i),count(b));
       if(ans>cur)ans=cur;
        }
    }
    cout<<ans<<endl;
    return 0;
}


/* When Talent doesn't work, Hard work beats Talent*/

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

#include"bits/stdc++.h"

using namespace std;

#define Fast_D cout<<fixed<<setprecision(2);
#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define nl "\n"
#define sp " "
#define int long long
#define double long double
#define all(v) v.begin(),v.end()
#define scanstr(s) cin>>ws; getline(cin,s);

const double PI=3.141592653589793;

void solve()
{
	string s[3];
	for(int i=0;i<3;i++) cin >> s[i];
	for(auto &c : s) reverse(all(c));
	int cur=0;
	while(s[cur].size()>0)
	{
		int x=cur;
		cur=s[x].back() - 'a';
		s[x].pop_back();
	}
	char ans= 'A'+cur;
	cout << ans << nl;
}

int32_t main()
{
	FastIO;
	Fast_D;
	int T;
	T=1;
	while(T--)
	{
		solve();
	}
	return 0;
}

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

int main() {
  vector<queue<char>> v(3);

  string s;
  cin >> s;
  for (char c : s) v[0].push(c);

  cin >> s;
  for (char c : s) v[1].push(c);

  cin >> s;
  for (char c : s) v[2].push(c);

  char c = 'a';
  while (true)
  {
    char i = c - 'a';
    if (v[i].empty())
    {
      putchar(toupper(c));
      return 0;
    }

    c = v[i].front(); v[i].pop();
  }
}


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

vec<int> mult(vec<int>& A,vec<int>& B){
    vec<int> C(A.size());
    for(int i=0;i<A.size();i++) C[i] = B[A[i]];
    return C;
}

vec<int> pow(vec<int>& A,ll n){
    if(n==1) return A;
    vec<int> R = pow(A,n>>1);
    R = mult(R,R);
    if(n&1) R = mult(A,R);
    return R;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vec<int> X(N);
    vec<int> D(N-1);
    for(int i=0;i<N;i++){
        cin >> X[i];
        if(i) D[i-1] = X[i]-X[i-1];
    }
    vec<int> perm(N-1);
    iota(perm.begin(),perm.end(),0);
    int M;
    ll K;
    cin >> M >> K;
    for(int i=0;i<M;i++){
        int a;
        cin >> a;
        a -= 2;
        swap(perm[a],perm[a+1]);
    }
    auto res = pow(perm,K);
    ll s = X[0];
    for(int i=0;i<N;i++){
        cout << s << "\n";
        if(i!=N-1) s += D[res[i]];
    }
}

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

int MAX_N=262144*2;
vector<int64_t> seg(MAX_N*2-1);
int64_t qu(int a,int b,int k,int l, int r){
  if(r<=a||b<=l){
    return 0;
  }
  else if(a<=l&&r<=b){
    return seg[k];
  }
  else{
    int64_t X=qu(a,b,k*2+1,l,(l+r)/2);
    int64_t Y=qu(a,b,k*2+2,(l+r)/2,r);
    return X+Y;
  }
}
void pu(int64_t a,int b){
  int D=MAX_N-1+b;
  while(D>0){
    seg[D]+=a;
    D--;
    D/=2;
  }
  seg[0]+=a;
}

int main() {
  int N,Q;
  cin>>N>>Q;
  vector<int> p(N);
  for(int i=0;i<N;i++){
    cin>>p[i];
    p[i]--;
  }
  vector<tuple<int,int,int>> q(Q);
  for(int i=0;i<Q;i++){
    int a,b;
    cin>>a>>b;
    q[i]=make_tuple(b,a,i);
  }
  sort(q.begin(),q.end());
  vector<int> la(N,-1);
  vector<int> an(Q);
  int W=0;
  for(int i=0;i<Q;i++){
    int a,b,c;
    tie(a,b,c)=q[i];
    while(W<a){
      if(la[p[W]]!=-1){
        pu(-1,la[p[W]]);
      }
      la[p[W]]=W;
      pu(1,W);
      W++;
    }
    an[c]=qu(b-1,a,0,0,MAX_N);
  }
  for(int i=0;i<Q;i++){
    cout<<an[i]<<endl;
  }
}


#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 998244353;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

ll modadd(ll x, ll y) {
    return ((x + y) % mod + mod) % mod;
}

ll modminus(ll x, ll y) {
    return (x - y + mod) % mod;
}

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

ll modpower(ll x, ll y) {
    if (y == 0) {
        return 1;
    } else if (y == 1) {
        return x % mod;
    } else if (y % 2 == 0) {
        ll p = modpower(x, y / 2);
        return p * p % mod;
    } else {
        ll p = modpower (x, y / 2);
        return (p * p) % mod * (x % mod) % mod;
    }
}

ll dp[310][90010];
ll dpb[310][90010];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll a[N];
    ll sum = 0;
    REP(i, 0, N) {
        cin >> a[i];
        sum += a[i];
    }
    dp[0][0] = 1;
    dpb[0][0] = 1;
    REP(i, 0, N) {
        REP(j, 0, 90000) {
            dp[i + 1][j] = modadd(dp[i + 1][j], multiply(dp[i][j], 2));
            dpb[i + 1][j] = modadd(dpb[i + 1][j], dpb[i][j]);
            if (j + a[i] <= 90000) {
                dp[i + 1][j + a[i]] = modadd(dp[i + 1][j + a[i]], dp[i][j]);
                dpb[i + 1][j + a[i]] = modadd(dpb[i + 1][j + a[i]], dpb[i][j]);
            }
        }
    }
    ll dis = 0;
    ll disa = 0;
    REP(i, (sum + 1) / 2, sum) {
        dis = modadd(dis, dp[N][i]);
    }
    dis = multiply(dis, 3);
    if (sum % 2 == 0) {
        disa = dpb[N][sum / 2];
    }
    disa = multiply(disa, 3);
    ll base = modadd(modpower(3, N), -3);
    ll ans = modadd(base, - modadd(dis, - disa));
    cout << ans << endl;
}

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

using namespace std;

const int MOD = 1000000007;

int main(){
    const int maxSize = 100001;
    vector<long long> inv(maxSize);
    vector<long long> fact(maxSize);
    vector<long long> factInv(maxSize);
    for(int i=0;i<2;i++) inv[i] = fact[i] = factInv[i] = 1;
    for(int i=2;i<maxSize;i++){
        inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
        fact[i] = fact[i-1] * i % MOD;
        factInv[i] = factInv[i-1] * inv[i] % MOD;
    }
    int N, X; cin >> N >> X;
    vector<int> S(N);
    for(auto& t : S) cin >> t;
    sort(S.begin(), S.end());
    vector<int> sum(100001, 0);
    for(auto& t : S) sum[t] = 1;
    for(int i=1;i<=100001;i++) sum[i] += sum[i-1];
    vector dp(X+1, vector(N+1, 0LL));
    dp[X][N-sum[X]] = 1;
    for(int i=X;i>=S[0];i--){
        for(int j=N;j>=0;j--){
            if(!dp[i][j]) continue;
            if(j > 0){
                dp[i][j-1] += dp[i][j] * j;
                dp[i][j-1] %= MOD;
            }
            for(int k=0;k<sum[i];k++){
                int dst = i%S[k];
                int add = sum[i] - sum[dst] - 1;
                dp[dst][j+add] += dp[i][j];
                dp[dst][j+add] %= MOD;
            }
        }
    }
    long long res = 0;
    for(int i=1;i<S[0];i++){
        for(int j=0;j<=N;j++){
            res += dp[i][j] * fact[j] % MOD * i % MOD;
            res %= MOD;
        }
    }
    cout << res << endl;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int time(int a,int b,int c,int d,int e,int m){
	int ret =  a+b+c+d+e;
	rep(i,m-1){
		ret += d+e;
	}
	return ret;
}
bool cmp(const pair<double,string>&a,const pair<double,string>&b){
	if( fabs(a.first-b.first) < 1e-8){
		return a.second < b.second;
	}
	return a.first > b.first;
}
int main(){
	int n;

	while(cin >> n , n){
		vector< pair<double,string> > data(n);
		rep(i,n){
			string l; int p,a,b,c,d,e,f,s,m;
			cin >> l >> p >> a >> b >> c >> d >> e >> f >> s >> m;
			data[i].first = (double)(f*s*m-p)/time(a,b,c,d,e,m);
			data[i].second = l;
		}
		sort(data.begin(),data.end(),cmp);
		rep(i,n){
			cout << data[i].second << endl;
		}
		cout << "#" << endl;
	}
}

#include <iostream>
#define N 100
#define WHITE 0
#define BLACK 1
#define INF 10000

using namespace std;

int M[N][N],n,d[N];

void prim(){
  int color[n],p[n];
  for(int i=0;i<n;i++){
    color[i]=WHITE;
    d[i]=INF;
  }
  d[0]=0;
  p[0]=-1;
  while(1){
    int mincost=INF;
    int u;
    for(int i=0;i<n;i++){
      if(color[i]!=BLACK && d[i]<mincost){
        mincost=d[i];
        u=i;
      }
    }
    if(mincost==INF) break;
    //connect u to p[u]
    color[u]=BLACK;
    for(int v=0;v<n;v++){
      if(color[v]!=BLACK && M[u][v]!=-1){
        if(M[u][v]<d[v]){
          d[v]=M[u][v];
          p[v]=u;
        }
      }
    }
  }
}

int main(){
  cin >> n;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++) cin >> M[i][j];
  }
  prim();
  int sum=0;
  for(int i=0;i<n;i++) sum+=d[i];
  cout << sum << endl;
}