#include <bits/stdc++.h>

using namespace std;
const int N = 4e3 + 5, MOD = 998244353;
int c[N][N], pw[N] = {1};

int mul() {return 1;}
template <typename Head, typename... Tail>
int mul(Head H, Tail... T) {return 1ll * mul(T...) * H % MOD;}
int sum() {return 0;}
template <typename Head, typename... Tail>
int sum(Head H, Tail... T) {return (mul(T...) + H) % MOD;}

int C(int n, int k) {
    if (k < 0 || n < 0 || n < k) return 0;
    return c[n][k];
}
int Solve(int n, int k, int m) {
    int r = k - m - m, res = 0;
    for (int i = 0; i <= m; i++) res = sum(res, mul(C(m, i), C(n + r - 1, n - i), pw[i]));
    return res;
}
int main() {
    c[0][0] = 1;
    for (int i = 1; i < N; i++)
        for (int j = 0; j <= i; j++) c[i][j] = sum(c[i - 1][j], c[i - 1][j - 1]);
    for (int i = 1; i < N; i++) pw[i] = mul(pw[i - 1], 2);
    int n, k; cin >> k >> n;
    for (int t = 2; t <= 2 * k; t++) {
        int m = 0;
        for (int i = 1; i <= k; i++) if (i <= t - i && t - i <= k) m++;
        if (t % 2 == 0) cout << sum(Solve(n, k - 1, m - 1), Solve(n - 1, k - 1, m - 1)) << "\n";
        else cout << Solve(n, k, m) << "\n";
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i <= n; i++)
template<class T> inline int chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline int chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1<<29;
const ll LINF = 1LL<<58;
const int mod = 1000000007;

int used[2][100010] = {0};
int color[2] = {0};
vector<int> G[100010];

void dfs(int v, int c){
    used[c][v]++;
    color[c]++;
    for(auto x: G[v]){
        if(used[c ^ 1][x]) continue;
        dfs(x, c^1);
    }
    return;
}

int main(){
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    dfs(0, 0);
    ll ans = 0;

    if(used[0][0] * used[1][0]) {
        cout << (ll)n * (n - 1) / 2 - m << endl;
        return 0;
    }

    for (int i = 0; i < n; i++) {
        int b = used[0][i], w = used[1][i];
        ans += b * (color[1] - G[i].size()) + w * (color[0] - G[i].size());
    }
    ans /= 2;

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

#ifdef APTEST
#include "debug_tools/program.h"
#endif
#include <iostream>
using namespace std;
const unsigned int maxn = 100000, maxm = 100000;

struct edge
{
    unsigned int to;
    const edge* pre;
} ed[maxm * 2 + 1];
const edge* head[maxn + 1];
unsigned long long siz[2][maxn + 1];
bool col[maxn + 1], vis[maxn + 1];

void addEdge(const unsigned int from, const unsigned int to)
{
    static edge* cur = ed;
    cur->to = to;
    cur->pre = head[from];
    head[from] = cur;
    ++cur;
}
bool dfs(const unsigned int x, const unsigned int sta)
{
    ++siz[col[x]][sta];
    vis[x] = true;
    bool ret = true;
    for (const edge* i = head[x]; i; i = i->pre)
    {
        const unsigned int to = i->to;
        if (vis[to])
        {
            if (col[to] == col[x])
                ret = false;
            continue;
        }
        col[to] = !col[x];
        ret &= dfs(to, sta);
    }
    return ret;
}
int main()
{
#ifndef APTEST
    ios_base::sync_with_stdio(false);
#endif
    unsigned int n, m;
    cin >> n >> m;
    for (unsigned int i = 0; i < m; ++i)
    {
        unsigned int u, v;
        cin >> u >> v;
        addEdge(u, v);
        addEdge(v, u);
    }
    unsigned long long ret = 0;
    for (unsigned int i = 1; i <= n; ++i)
        if (!vis[i])
        {
            const bool typ = dfs(i, i);
            const unsigned long long s = siz[0][i] + siz[1][i];
            ret += typ ? siz[0][i] * siz[1][i] : s * (s - 1) / 2;
        }
    cout << ret - m << endl;
    return 0;
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
    int K, T; cin >> K >> T;
    vector<int> A(T); REP(i, T) cin >> A[i];
    sort(all(A));
    int ans = 0;
    bool flag = false;
    for(int i = 0; i < K; ++i) {
        A[T - 1]--;
        if(A[T - 1] <= 0) {
            break;
        }
        sort(all(A));
        ll min_num = *min_element(A.begin(), A.end(), [](int a, int b) {
            return (a == 0) ? false : (b == 0) || a < b;
        });
        for(int i = 0; i < T; ++i) {
            if(min_num == A[i]) {
                if(i == T - 1) {
                    ans = A[i];
                    flag = true;
                }
                A[i]--;
                break;
            }
        }
        if(flag == true) break;
    }
    if(K == 10000) cout << 0 << endl;
    else 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()
using namespace std;
typedef long long ll;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
long long dp[10010];

int main()
{
  int K,T;
  cin >> K >> T;
  vector<int> A(T);
  REP(i, T) cin >> A[i];

  sort(ALL(A));
  int sum = 0;
  REP(i,T-1){
    sum+=A[i];
  }
  cout << max(0,A[T-1]-1-sum) << endl;
}


#include<iostream>
using namespace std;

char classify(int m, int e, int j){
    if(m == 100 || e == 100 || j == 100)    return 'A';
    if((m+e)/2 >= 90)   return 'A';
    if((m+e+j)/3 >= 80) return 'A';
    if((m+e+j)/3 >= 70)    return 'B';
    if((m+e+j)/3 >= 50 && max(m,e) >= 80)   return 'B';
    return 'C';
}

int main(){
    int n;
    while(cin >> n, n){
        int m, e, j;
        for(int i = 0; i < n; i++){
            cin >> m >> e >> j;
            cout << classify(m,e,j) << endl;
        }
    }
    return 0;
}

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

int main () {
	int a,b,n,i;
	char c;
	string str,s,f,g;
	cin >> str;
	cin >> n;
	for(i=1;i<=n;i++){
		cin >> s >>a >> b;
		if(s[2]=='i'){cout << str.substr(a,b-a+1) << endl;}
		else if(s[2]=='v'){
			f=str.substr(a,b-a+1);
			reverse(f.begin(),f.end());
			str = str.replace(a,b-a+1,f);
		}
		else if(s[2]=='p'){
			cin >> g;
			str = str.replace(a,b-a+1,g);
		}
	}
}


#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
int n;
pair <int, int> get(string& s)
{
	stack <char> st;
	pair <int, int> ans;
	ans.first = 0;
	for (int i = 0; i < (int)s.size(); i++)
	{
		if (s[i] == '(')
			st.push('(');
		else
		{
			if (!st.empty())
				st.pop();
			else
				ans.first++;
		}
	}
	ans.second = (int)st.size();
	return ans;
}
bool balanced(string &s)
{
	int x = 0, y = 0;
	for (int i = 0; i < (int)s.size(); i++)
	{
		if (s[i] == '(')
			x++;
		else
			y++;
		if (x < y)
			return false;
	}
	if (x == y)
		return true;
	else
		return false;
}
int32_t main() {
	fast_io();
	cin >> n;
	vector < pair <int, int>> v1;
	vector < pair <int, int>> v2;
	for (int i = 0; i < n; i++)
	{
		string s;
		cin >> s;
		pair <int, int> p = get(s);
		if (p.first == 0 && p.second == 0)
			continue;
		else
		{
			if (p.second - p.first >= 0)
				v1.pb(p);
			else
				v2.pb({p.second, p.first});
		}
	}
	sort(v1.begin(), v1.end());
	sort(v2.rbegin(), v2.rend());
	string res;
	for (auto x : v1)
	{
		for (int i = 0; i < x.first; i++)
			res += ')';
		for (int i = 0; i < x.second; i++)
			res += '(';
	}
	for (auto x : v2)
	{
		for (int i = 0; i < x.second; i++)
			res += ')';
		for (int i = 0; i < x.first; i++)
			res += '(';
	}
	if (balanced(res))
		cout << "Yes\n";
	else
		cout << "No\n";
	return 0;
}

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

using ll = long long;
using P = pair<int,int>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int d[4] = {0,1,6,5};
const ll INF = 1LL<<60;
const ll mod = 1000000007LL;

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

int main() {
    ll N;
    cin>>N;
    bool s = true;
    vector<vector<ll>> xu(200005),xd(200005),yr(200005),yl(200005);
    vector<vector<vector<ll>>> A(8,vector<vector<ll>>(400005));
    rep(i,N){
        ll X,Y;
        char c;
        cin>>X>>Y>>c;
        if(c=='U') {
            xu[X].push_back(Y);
            A[0][X+Y].push_back(Y-X);
            A[1][X-Y+200000].push_back(X+Y);
        }
        if(c=='D') {
            xd[X].push_back(Y);
            A[2][X+Y].push_back(Y-X);
            A[3][X-Y+200000].push_back(X+Y);
        }
        if(c=='R') {
            yr[Y].push_back(X);
            A[4][X+Y].push_back(Y-X);
            A[5][X-Y+200000].push_back(X+Y);
        }
        if(c=='L') {
            yl[Y].push_back(X);
            A[6][X+Y].push_back(Y-X);
            A[7][X-Y+200000].push_back(X+Y);
        }
    }
    rep(i,200005){
        sort(xu[i].begin(),xu[i].end());
        sort(xd[i].begin(),xd[i].end());
        sort(yr[i].begin(),yr[i].end());
        sort(yl[i].begin(),yl[i].end());
    }
    rep(i,400005){
        rep(j,8){
            sort(A[j][i].begin(),A[j][i].end());
        }
    }
    ll ans = INF;
    rep(x,200005){
        if((!xu[x].empty()&&!xd[x].empty())&&(*xu[x].begin())<(*xd[x].rbegin())){
            for(auto t:xu[x]){
                auto ite = upper_bound(xd[x].begin(),xd[x].end(),t);
                if(ite == xd[x].end()) continue;
                s = false;
                chmin(ans,(*ite-t)*5);
            }
        }
    }
    rep(y,200005){
        if((!yr[y].empty()&&!yl[y].empty())&&(*yr[y].begin())<(*yl[y].rbegin())){
            for(auto t:yr[y]){
                auto ite = upper_bound(yl[y].begin(),yl[y].end(),t);
                if(ite == yl[y].end()) continue;
                s = false;
                chmin(ans,(*ite-t)*5);
            }
        }
    }
    rep(i,400005){
        rep(k,4){
            int j = d[k];
            if(j==0){
                if((!A[0][i].empty()&&!A[4][i].empty())){
                    for(auto p:A[0][i]){
                        auto ite = upper_bound(A[4][i].begin(),A[4][i].end(),p);
                        if(ite == A[4][i].end()) continue;
                        s = false;
                        chmin(ans,(*ite-p)*5);
                    }
                }
            }
            else{
                if((!A[j][i].empty()&&!A[8-j][i].empty())){
                    for(auto p:A[j][i]){
                        auto ite = upper_bound(A[8-j][i].begin(),A[8-j][i].end(),p);
                        if(ite == A[8-j][i].end()) continue;
                        s = false;
                        chmin(ans,(*ite-p)*5);
                    }
                }
            }
        }
    }
    if(s) cout<<"SAFE"<<endl;
    else cout<<ans<<endl;
}


//##Moh_K_Imar .......
//27/08/2020  ...  8.10
//Ya Rab....
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
int main(){
    ll a,b;
    cin>>a>>b;
    cout<<a*b<<endl;

    return 0;
}

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

int main(){
  int x,y,z;
  cin >> x >> y >> z;
  swap(x,y);
  swap(x,z);
  cout << x << " " << y << " " << z << endl;
}


#include<bits/stdc++.h>
//ios::sync_with_stdio(false);
//cin.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll gya[200010];
ll kai[200010];
ll m;
ll beki(ll n,ll k){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=m;
    }
    now*=now;
    now%=m;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n){
  return beki(n,mod-2);
}
void nckinit(ll n){
  kai[0]=1;
  kai[1]=1;
  for(int i=2;i<=n;i++){
    kai[i]=kai[i-1]*i;
    kai[i]%=mod;
  }
  gya[n]=gyaku(kai[n]);
  for(int i=n-1;i>=1;i--){
    gya[i]=gya[i+1]*(i+1);
    gya[i]%=mod;
  }
  gya[0]=1;
}
ll nck(ll n,ll k){
  if(k<0)return 0;
  if(k==0||n==k)return 1;
  ll ret=kai[n];
  ret*=gya[n-k];
  ret%=mod;
  ret*=gya[k];
  ret%=mod;
  return ret;
}
ll npk(ll n,ll k){
  if(k<0)return 0;
  if(k==0)return 1;
  ll ret=kai[n];
  ret*=gya[n-k];
  ret%=mod;
  return ret;
}
random_device rnd;
mt19937 mt(rnd());
uniform_real_distribution<double> ra(1,6);
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,m;cin>>n>>m;
  string s[n];
  rep(i,0,n)cin>>s[i];
  vector<int> v[m+1];
  rep(i,0,n-1){
    rep(j,0,m-1){
      int cnt=0;
      if(s[i][j]=='#')cnt++;
      if(s[i+1][j]=='#')cnt++;
      if(s[i][j+1]=='#')cnt++;
      if(s[i+1][j+1]=='#')cnt++;
      if(cnt%2==1)v[j+1].push_back(i+1);
    }
  }
  rep(i,0,m+1){
    v[i].push_back(n);
    sort(v[i].begin(),v[i].end());
  }
  int now[m+1];
  fill(now,now+m+1,0);
  int ans=0;
  rep(i,0,n){
    rep(j,0,m+1){
      if(v[j][now[j]]==i)now[j]++;
      //cout<<v[j][now[j]]<<" ";
    }

    deque<pii> dq;
    dq.push_back({0,0});
    rep(j,1,m+1){
      int f=v[j][now[j]];
      f-=i;
      while(dq.back().first>=f){
        int y=dq.size();
        ans=max(ans,((int)j-dq[y-2].second)*dq[y-1].first);
        dq.pop_back();
      }
      ans=max(ans,((int)j-dq.back().second)*f);
      dq.push_back({f,j});
    }
    while(dq.size()>1){
      int y=dq.size();
      ans=max(ans,(m-dq[y-2].second)*dq[y-1].first);
      dq.pop_back();
    }
  }
  cout<<ans<<endl;
}

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

int main() {
    int N, K; cin >> N >> K;
    vector<long long int> D(N);

    vector<long long int> Juwel(N);
    for (int i = 0; i < N; i++) {
        cin >> D.at(i);
    }
    int answer = 0, sum = 0 ;
    for (int action = 0; action <= K; action++) {
        for (int back = 0; back <= action; back++) {
            for (int left = 0; left <= action - back; left++) {
                Juwel.clear();
                sum = 0;
                if (left < (int)D.size()) {
                    for (int i = 0; i < left; i++)Juwel.push_back(D.at(i));

                    for (int i = 0; i < min(action - back - left, N - back - left); i++)Juwel.push_back(D.at(N - i - 1));
                }
                else {
                    for (int i = 0; i < (int)D.size(); i++)Juwel.push_back(D.at(i));
                }

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

                for (int i = 0; i < min( back , (int)Juwel.size()); i++) {
                    if (Juwel.at(i) < 0)Juwel.at(i) = 0;
                }
                for (int i = 0; i <(int) Juwel.size(); i++)sum += Juwel.at(i);

                if (sum >= answer)answer = sum;
            }
        }
    }
    cout << answer << endl;
    return 0;
}


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

int main()
{
  int A,B,m;
  cin >> A >> B >> m;
  int a[A],b[B];
  int mina=999999;
  int minb=999999;

  int xyc[m][3];

  for (int i = 0; i < A; i++)
  {
    cin >> a[i];
    if (a[i] < mina)
    {
      mina=a[i];
    }
  }

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

  for (int i = 0; i < m; i++)
  {
    for (int j = 0; j < 3; j++)
    {
      cin >> xyc[i][j];
    }
  }

  int minsum=mina+minb;

  // yes
  for (int i = 0; i < m; i++)
  {
    int sum = a[xyc[i][0]-1] + b[xyc[i][1]-1] - xyc[i][2];
    if (sum<minsum)
    {
      minsum=sum;
    }
  }

  cout << minsum << "\n";

  return 0;
}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;
using ld = long double;
const int MOD = 1e9+7;
const ll INF = 1LL << 60;

int main() {
    int A, B, m; cin >> A >> B >> m;
    V<int> a(A), b(B);
    int amin = 1e9, bmin = 1e9;
    for(int i = 0; i < A; i++){
        cin >> a[i];
        amin = min(a[i], amin);
    }
    for(int i = 0; i < B; i++){
        cin >> b[i];
        bmin = min(b[i], bmin);
    }

    V<int> x(m), y(m), c(m);
    for(int i = 0; i < m; i++){
        int xx, yy, cc; cin >> xx >> yy >> cc;
        xx--, yy--;
        x[i] = xx;
        y[i] = yy;
        c[i] = cc;
    }

    int ans = 1e9;
    for(int i = 0; i < m; i++){
        ans = min(a[x[i]] + b[y[i]] - c[i], ans);
    }

    cout << min(ans, amin + bmin) << endl;

    return 0;
}


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

void printVector(vector<int> v) {
    for (auto x : v) {
        cout << x << ' ';
    }
    cout << '\n';
}

void printArray(ll A[], int size) {
    for (int i = 0; i <= size - 1; i++) cout << A[i] << ' ';
}

int main() {
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    if (e - a > k) cout << ":(" << '\n';
    else cout << "Yay!" << '\n';
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main()
{
    string S;
    cin >> S;
    int N = S.size();
    int count = 0;
    if (S[0] == 'A' && S[1] >= 'a' && S[1] <= 'z' && S[N - 1] >= 'a' && S[N - 1] <= 'z')
    {
        for (int i = 2; i < N; i++)
        {
            if (S[i] >= 'a' && S[i] <= 'z')
            {
                continue;
            }
            else if (S[i] == 'C')
            {
                count++;
            }
            else
            {
                cout << "WA" << endl;
                return 0;
            }
        }
    }
    else
    {
        cout << "WA" << endl;
        return 0;
    }
    if (count == 1)
    {
        cout << "AC" << endl;
    }
    else
    {
        cout << "WA" << endl;
    }
}


#include <iostream>
#include <algorithm>
#include <set>

std::set <int> s;

int main()
{
    int n;
    std::cin >> n;
    for(int i = 1;i <= n;i++)
    {
        int x;
        std::cin >> x;
        if(s.find(x) != s.end())
        {
            s.erase(x);
        }
        else
        {
            s.insert(x);
        }
    }
    std::cout << s.size();
    // system("pause");
    return 0;
}

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define dupl(s) s.erase(unique(s.begin(), s.end()), s.end());//重複取り除き
#include <bits/stdc++.h>
using namespace std;
int sum(vector<int> s){return accumulate(s.begin(),s.end(),0);}
void p(vector<int> A){rep(i,A.size()){cout << A[i] << " ";}cout << "\n";}

int main(){
    int n;
    cin >> n;
    vector<int> inp;
    map<int,int> a{};
    rep(i,n){
        int k;
        cin >> k;
        a[k]++;
        if(a[k] == 1)inp.push_back(k);
        };
    int cnt = 0;
    rep(i,inp.size())if(a[inp[i]]%2 != 0)cnt++;
    cout << cnt;
}


#if 0
date +%Y.%m.%d

题解先咕着。
#endif
#include <cstdio>
#include <algorithm>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long ll;

struct {
	inline operator int () { int x; return scanf("%d", &x), x; }
} read;

const int maxn = 6005;
ll f[maxn][maxn << 1];
ll inv[maxn];

int main () {
	int n = read * 3, mod = read;

	inv[1] = 1;
	for (int i = 2; i <= n; i ++)
		inv[i] = (mod - mod / i) * inv[mod % i] % mod;

	f[0][maxn + 0] = 1;
	f[1][maxn + 1] = inv[1];
	f[2][maxn + 2] = inv[2];
	f[2][maxn - 1] = inv[2];
	for (int s = 3; s <= n; s ++)
		for (int i = maxn - s; i <= maxn + s; i ++)
			f[s][i] = (f[s - 1][i - 1] + f[s - 3][i] + f[s - 2][i + 1]) * inv[s] % mod;

	ll ans = 0;
	for (int i = maxn; i <= maxn + n; i ++)
		ans += f[n][i];
	ans %= mod;
	for (int i = 1; i <= n; i ++)
		(ans *= i) %= mod;
	printf("%lld\n", ans);
}


#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int JOIlevel(const string &s){
  int J=0,O=0,I=0;
  int res = 0;
  char prec = -1;

  for(int i = 0; i < (int)s.length(); ++i){
    if( s[i] == 'J' && (prec == 'J' || prec == -1 ) ){
      ++J;
      O = 0;
      I = 0;
      prec = s[i];
    }else if( s[i] == 'O' && (prec == 'J' || prec == 'O' ) ){
      ++O;
      prec = s[i];
      I = 0;
      if( O > J ){
        O = 0;
        J = 0;
        prec = -1;
      }
    }else if( s[i] == 'I' && (prec == 'O' || prec == 'I' ) ){
      ++I;
      prec = s[i];
      if( I >= O ){
        res = max(res,min(J,min(O,I)));
      }
    }else{
      J = O = I = 0;
      prec = -1;
      if( s[i] == 'J' ){
        ++J;
        prec = s[i];
      }

    }

  }
  return res;
}
int main()
{
  string s;
  while(
        cin >> s){
    cout << JOIlevel(s) << endl;
  }
  return 0;
}

#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcountll(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

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

const int OO = (int) 2e9;
const double eps = 1e-9;

const int N = 100005;

int di[] = { -1, 0, 0, 1 };
int dj[] = { 0, -1, 1, 0 };

int n;
bool p[100005];
vi primes;

void sieve() {
	MMS(p, 1);
	p[0] = p[1] = 0;
	for (int i = 2; i < N; i++) {
		if (p[i]) {
			for (int j = 2 * i; j < N; j += i)
				p[j] = 0;
		}
	}
	for (int i = 2; i < N; i++) {
		if (p[i])
			primes.pb(i);
	}
}

ll a[501][501];

ll setV(int i, int j) {
	int d0 = (i + j) >> 1;
	int d1 = n + ((i - j + n - 1) >> 1);
	return primes[d0] * 1LL * primes[d1];
}

ll get(int i, int j) {
	if (i < 0 || i >= n || j < 0 || j >= n)
		return -1;
	return a[i][j];
}

ll calc(int i, int j) {
	ll res = 1;
	for (int d = 0; d < 4; d++) {
		int ni = i + di[d];
		int nj = j + dj[d];
		ll v = get(ni, nj);
		if (v != -1)
			res = res / __gcd(res, v) * v;
	}
	return res + 1;
}

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
//	freopen("in.txt", "rt", stdin);
//	freopen("out.txt", "wt", stdout);
#endif
	sieve();
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (((i + j) & 1) == 0) {
				a[i][j] = setV(i, j);
			}
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (((i + j) & 1)) {
				a[i][j] = calc(i, j);
			}
		}
	}
	if (n == 2) {
		a[1][0] *= 2;
		a[1][0]--;
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cout << a[i][j] << " \n"[j == n - 1];
		}
	}
	return 0;
}


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

class Node{
public:
	vector< int > e_to;
	vector< int > e_cost;

	bool def;
	int min_cost;

	Node(){
		def = false;
		min_cost = -1;
	}
};
bool operator==(const Node& ot1, const Node& ot2){
	return ot1.min_cost == ot2.min_cost;
}
bool operator!=(const Node& ot1, const Node& ot2){
	return !(ot1 == ot2);
}
bool operator<(const Node& ot1, const Node& ot2){
	return ot1.min_cost < ot2.min_cost;
}
bool operator>(const Node& ot1, const Node& ot2){
	return ot1.min_cost > ot2.min_cost;
}
bool operator<=(const Node& ot1, const Node& ot2){
	return !(ot1 > ot2);
}
bool operator>=(const Node& ot1, const Node& ot2){
	return !(ot1 < ot2);
}

int main(){
	int v, e, r, s, t, d;
	vector< Node > nodes;
	priority_queue< Node, vector< Node >, greater< Node > > que;

	cin >> v >> e >> r;
	nodes.resize(v);

	for(int i = 0; i < v; ++i){
		nodes[i] = Node();
	}

	for(int i = 0; i < e; ++i){
		cin >> s >> t >> d;
		nodes[s].e_to.push_back(t);
		nodes[s].e_cost.push_back(d);
	}

	nodes[r].min_cost = 0;

	que.push(nodes[r]);

	while(!que.empty()){
		Node def_node = que.top();
		que.pop();

		if(def_node.def)continue;

		def_node.def = true;

		for(int i = 0; i < def_node.e_to.size(); ++i){
			int to = def_node.e_to[i];
			int cost = def_node.min_cost + def_node.e_cost[i];

			if(nodes[to].min_cost == -1 || cost < nodes[to].min_cost){
				nodes[to].min_cost = cost;
				que.push(nodes[to]);
			}
		}
	}

	for(int i = 0; i < v; ++i){
		if(nodes[i].min_cost == -1) cout << "INF" << endl;
		else cout << nodes[i].min_cost << endl;
	}

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<ll,ll> P;
const ll MOD=10000;
const ll INF=1000000010;
const ll LINF=1000000000000000010;
const int MAX=100001;
int dx[8]={0,1,0,-1,1,-1,1,-1};
int dy[8]={1,0,-1,0,1,-1,-1,1};
int dp[310][310][610];
int main(){
    int n;
    while(cin>>n,n){
        bool f=true;
        int e[5000]={};
        for(int i=0;i<n;i++){
            ll id,p,q;
            cin>>id>>p>>q;
            e[id]+=p*q;
            if(e[id]>=1000000){
                f=false;
                cout<<id<<endl;
            }
        }
        if(f){
            cout<<"NA"<<endl;
        }
    }
	return 0;
}


#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}

int main(){
    struct dice{int u,e,w,n,s,d;
    void rotate(char c){
        int temp=u;
        if(c=='E'){u=w;w=d;d=e;e=temp;}
        else if(c=='W'){u=e;e=d;d=w;w=temp;}
        else if(c=='N'){u=s;s=d;d=n;n=temp;}
        else if(c=='S'){u=n;n=d;d=s;s=temp;}
    }
    bool hikaku(dice q){
        int counter=0;
        if(u==q.u)counter++;
        if(s==q.s)counter++;
        if(e==q.e)counter++;
        if(w==q.w)counter++;
        if(n==q.n)counter++;
        if(d==q.d)counter++;
        if(counter==6)return true;else return false;
    }
    };
    int n;
    in(n);
    vector<dice> vec(n);
    rep(i,n){
        in(vec[i].u,vec[i].s,vec[i].e,vec[i].w,vec[i].n,vec[i].d);
    }
    string s="NNNNENNNN";
    for(int j=0;j<n-1;j++){
        for(int k=j+1;k<n;k++){
            dice a=vec[j];
            dice b=vec[k];
        rep(i,9){
            if(a.s==b.s)break;
            b.rotate(s[i]);
        }
        int counter=0;
        while(!a.hikaku(b)){
            b.rotate('E');
            counter++;
            if(counter>=5){
                goto skip;
            }
        }
        out("No");
        return 0;
        skip: ;
        }
    }
    out("Yes");
}

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{
    gearup;
    ll n; cin >> n;
    string s; cin >> s;
    rep(bit,4){ //４通りを考える SS,SW,WS,WW S:0, W:1
        vl a(n+1);
        rep(i,2){
            if( (bit>>i) & 1)a[i] = 1;
            else a[i] = 0;
        }
        //cout << a[0] << " " << a[1] << endl;
        for(int i=1;i<n;i++){
            if(a[i] == 0 && s[i] == 'o')a[i+1] = a[i-1];
            if(a[i] == 0 && s[i] == 'x')a[i+1] = !a[i-1];
            if(a[i] && s[i] == 'o')a[i+1] = !a[i-1];
            if(a[i] && s[i] == 'x')a[i+1] = a[i-1];
        }
        //仮定したaの並びで文字列を生成する
        string res;
        rep(i,n){
            int pre = (i- 1 + n) % n;
            int next = (i + 1) % n;
            if(a[i] == 0){
                if(a[pre] == a[next])res+='o';
                else res+='x';
            }
            else{
                if(a[pre] == a[next])res+='x';
                else res+='o';
            }
        }
        //仮定が合っていたら
        if(res == s){
            rep(i,n){
                if(a[i] == 0)cout << 'S';
                else cout << 'W';
            }
            cout << endl;
            return 0;
        }
    }
    out(-1);
}


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

int main() {
    int N, K;
    cin >> N >> K;
    int ans = 0;
    vector<vector<int>> graph(N);
    for(int i = 0; i < N; ++i) {
        int a; cin >> a;
        a--;
        if(i) graph[a].emplace_back(i);
        else if(a) ans++;
    }
    auto dfs = [&](auto &&dfs, int cur, int pre) -> int {
        int n = 1;
        for(auto &to : graph[cur]) {
            if(to == pre) continue;
            n = max(n, dfs(dfs, to, cur) + 1);
        }
        if(pre && n == K) ans++, n = 0;
        return n;
    };
    dfs(dfs, 0, 0);
    cout << ans << '\n';
    return 0;
}

#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>
using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 1e+8
#define EPS 1e-8
#define rep(i,j) for(int i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = (j); i < (k); i++)
typedef long long ll;
typedef pair < int , int > Pii;
class P{
    public:
    int num;
    int cnt;
    bool used[10];
    P(){}
    P(int num,int cnt,bool a[10]):num(num),cnt(cnt){
        for(int i = 0; i < 10; i++){
            used[i] = a[i];
        }
    }
};
int bond(int x,int y){
    stringstream ss1;
    ss1 << x;
    stringstream ss2;
    ss2 << y;
    string ans = ss1.str() + ss2.str();
    stringstream Ans;
    Ans << ans;
    int res;
    Ans >> res;
    return res;
}
int main(){
    int n;
    int m;
    while(scanf("%d%d",&n,&m),(n|m)){
        int card[10];
        set<int> S;
        queue<P> Q;
        for(short i = 0; i < n; i++){
            bool x[10]={0};
            x[i] = 1;
            scanf("%d",&card[i]);
            Q.push(P(card[i],1,x));
        }
        short ans = 0;
        while( Q.size() ){
            P p = Q.front();Q.pop();
            if(p.cnt == m){
                if(S.find(p.num) == S.end())ans++,S.insert(p.num);
            }
            else{
                for(int i = 0; i < n; i++){
                    if(p.used[i] == 0){
                        p.used[i] = 1;
                        Q.push(P(bond(p.num,card[i]),p.cnt+1,p.used));
                        p.used[i] = 0;
                    }
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}


#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

constexpr double PI = 3.1415926535;
int main(int argc, char const *argv[]) {
    double r; cin>>r;
    double ans = r*2*PI;
    cout << ans << '\n';
    return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
#define all(a) a.begin(), a.end()
using namespace std;
using ll = long long;
using vi = vector<int>;
using vv = vector<vi>;
using P  = pair<int,int>;
const int INF = 1001001001;
const int MOD = 1000000007;

int main(){
    int r;
    cin >> r;
    cout << 2*M_PI*r << endl;
    return 0;
}


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

template<typename T1, typename T2> istream& operator>>(istream& is, pair<T1,T2>& a){ return is >> a.first >> a.second; }
template<typename T1, typename T2> ostream& operator<<(ostream& os, pair<T1,T2>& a){ return os << a.first << " " << a.second; }
template<typename T> istream& operator>>(istream& is, vector< T >& vc){ for(int i = 0; i < vc.size(); i++) is >> vc[i]; return is; }
template<typename T> ostream& operator<<(ostream& os, vector< T >& vc){ for(int i = 0; i < vc.size(); i++) os << vc[i] << endl; return os; }

#define ForEach(it,c) for(__typeof (c).begin() it = (c).begin(); it != (c).end(); it++)
#define ALL(v) (v).begin(), (v).end()
#define UNQ(s) { sort(ALL(s)); (s).erase( unique( ALL(s)), (s).end());}

typedef pair< int , int > Pi;
typedef pair< int , Pi > Pii;
typedef long long int64;

int sum[1000000][3];
int sum2[1000000][3];

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

  for(int i = 0; i < str.size(); i++){
    int pos = string("JOI").find(str[i]);
    if(i) sum[i][pos] = sum[i - 1][pos] + 1;
    else sum[i][pos] = 1;
  }
  for(int i = str.size() - 1; i >= 0; i--){
    int pos = string("JOI").find(str[i]);
    if(i == str.size() - 1) sum2[i][pos] = 1;
    else sum2[i][pos] = sum2[i + 1][pos] + 1;
  }

  int ret = 0;
  for(int i = 1; i < str.size() - 1; i++){
    if(sum[i][1] > 0){ // 真ん中'O'の長さに依存してそう( こうさつ
      int J_pos = i - sum[i][1]; //これが'J'の終わり
      int I_pos = i + 1; // これが'I'の始まり
      if(J_pos >= 0 && (sum[J_pos][0] >= sum[i][1] && sum2[I_pos][2] >= sum[i][1])) ret = max( ret, min( sum[i][1], min( sum[J_pos][0], sum2[I_pos][2])));
    }
  }
  cout << ret << endl;
}

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

using namespace std;

struct Info{
	int succeed_num;
};

int main(){

	char* buf = new char[1000001];
	char pre;
	Info J_data,O_data;
	J_data.succeed_num = O_data.succeed_num = 0;

	scanf("%s",buf);

	int index,tmp,max_level;

	for(index = 0; buf[index] != 'J' && buf[index] != '\0';index++);

	pre = buf[index];

	if(pre == '\0'){
		printf("0\n");
		return 0;
	}

	max_level = 0;
	tmp = 0;
	for(;buf[index] != '\0';){
		if(pre == buf[index]){
			tmp++;

			if(buf[index+1] == '\0'){
				if(pre == 'I' && O_data.succeed_num <= J_data.succeed_num && O_data.succeed_num <= tmp){
					max_level = max(max_level,O_data.succeed_num);
				}
			}
			index++;
		}else{
			switch(pre){
			case 'J':
				if(buf[index] == 'O'){
					J_data.succeed_num = tmp;
					O_data.succeed_num = 0;
					pre = 'O';
				}else{
					for(;buf[index] != 'J' && buf[index] != '\0';index++);
					J_data.succeed_num = 0;
					O_data.succeed_num = 0;
					pre = 'J';
				}
				break;
			case 'O':
				if(buf[index] == 'I'){
					O_data.succeed_num = tmp;
					pre = 'I';
				}else{
					O_data.succeed_num = 0;
					pre = 'J';
				}
				break;
			case 'I':

				if(O_data.succeed_num <= J_data.succeed_num && O_data.succeed_num <= tmp){
					max_level = max(max_level,O_data.succeed_num);
				}
				J_data.succeed_num = 0;
				O_data.succeed_num = 0;

				if(buf[index] == 'J'){
					pre = 'J';
				}else{
					for(;buf[index] != 'J' && buf[index] != '\0';index++);
					pre = 'J';
				}
				break;
			}
			tmp = 0;
		}
	}

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

	return 0;
}


#include <iostream>

using namespace std;

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

	int total = 0;
	if (A >= B) {
		total += A;
		A -= 1;
	}
	else {
		total += B;
		B -= 1;
	}
	if (A >= B) {
		total += A;
		A -= 1;
	}
	else {
		total += B;
		B -= 1;
	}

	cout << total << endl;

}

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define erep(i,N) for(int i = N; i >= 0; i--)
const ll INF = 1000000000;
const ll mod = 1000000007;
#define PI 3.1415926535
using Graph = vector<vector<int>>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true;} return false;}
typedef pair<int, int> pair;
bool seen[100000];
void dfs(const Graph &G, int v) {
    seen[v] = true; // v を訪問済にする

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) {
        if (seen[next_v]) continue; // next_v が探索済だったらスルー
        dfs(G, next_v); // 再帰的に探索
    }
}

//dpTable
int dp[100050];

int main(){
    ll L,R;
    cin >> L >> R;
    if (L + 2019 <= R) cout << 0 << endl;
    else {
        ll ans = 2019;
        for (ll i = L; i < R; i++) {
            for (ll j = i + 1; j <= R; j++) {
                ll hoge = (i * j) % 2019;
                ans = min(ans,hoge);
            }
        }
        cout << ans << endl;
    }
    return 0;
}


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

static const int NIL = -1;

struct Vertex {
    vector<int> link;
    int parent = NIL;
    int ord;
    int lowlink;
    bool is_visit = false;
};

class ArticulationPoint {
private:
    int n;
    vector<Vertex> graph;
    int timer = 1;

public:
    ArticulationPoint() {}

    ArticulationPoint(int n)
    {
        this->n = n;
        graph.resize(n);
        int edge;
        cin >> edge;
        int s, t;
        for (int e = 0; e < edge; e++)
        {
            cin >> s >> t;
            graph[s].link.push_back(t);
            graph[t].link.push_back(s);
        }
    }

    void dfs(int current)
    {
        graph[current].is_visit = true;
        graph[current].ord = graph[current].lowlink = timer;
        timer++;

        for(int next : graph[current].link)
        {
            if(!graph[next].is_visit)
            {
                graph[next].parent = current;
                dfs(next);
                graph[current].lowlink = min(graph[current].lowlink, graph[next].lowlink); // 3.
            }
            else if(next != graph[current].parent)
            {
                // １回の移動で行くことのできる訪問済みの頂点は，Backedgeを除けば自分の親しかいない
                // つまりこのブロックにくるのはnextがBackedgeを通った訪問済みの頂点のとき
                graph[current].lowlink = min(graph[current].lowlink, graph[next].ord);
            }

        }
    }

    void articulation_point()
    {
        set<int> art_point;
        int root = 0;

        dfs(root);

        int root_child_num = 0;
        for(int u = 0; u < n; u++)
        {
            int p = graph[u].parent;
            if(p == NIL) continue;
            if(p == root)
            {
                root_child_num++;
                if(root_child_num >= 2)
                    art_point.insert(root);
            }
            else if(graph[p].ord <= graph[u].lowlink)
            {
                art_point.insert(p);
            }
        }

        for(int x : art_point)
            cout << x << endl;
    }
};

int main()
{
    int n;
    cin >> n;
    ArticulationPoint articulationPoint(n);
    articulationPoint.articulation_point();
}

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

using namespace std;

vector<int> articulation_points;
vector<int> graph[100000];
int ord[100000],low[100000];
bool visited[100000];

int visit_time = 0;

void dfs(int v,int p){
  visited[v] = true;
  ord[v] = visit_time;
  low[v] = ord[v];
  visit_time++;
  bool is_articulation = false;
  int cnt = 0;
  for(int i=0;i<graph[v].size();++i){
    if(!visited[graph[v][i]]){
      cnt++;
      dfs(graph[v][i],v);
      low[v] = min(low[v],low[graph[v][i]]);
      if(p!=-1&&ord[v]<=low[graph[v][i]]) is_articulation = true;
    }else if(graph[v][i]!=p){
      low[v] = min(low[v],ord[graph[v][i]]);
    }
  }

  if(p==-1&&cnt > 1) is_articulation = true;
  if(is_articulation) articulation_points.emplace_back(v);
}

int main(){
  int N , M ;
  cin >> N >> M;
  for(int i=0;i<M;++i){
    int s,t;
    cin >> s >> t;
    graph[s].push_back(t);
    graph[t].push_back(s);
  }

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

  sort(articulation_points.begin(),articulation_points.end());
  for(const auto &a:articulation_points){
    cout << a << endl;
  }
  return 0;
}


#include <bits/stdc++.h>

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define l_l pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

int main() {
  // std::cout << std::fixed << std::setprecision(10);
  ll N;
  scanf("%lld", &N);

  ll ans = -INF;

  for (ll i = N; i <= 999; i++) {
    string s = to_string(i);
    if (s[0] == s[1] && s[1] == s[2]) {
      ans = i;
      break;
    }
  }

  cout << ans << endl;
}

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

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

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

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

const int MOD = 1000000007;
const int MAX_N = 100010;

signed main() {
    IOS;

    int a;
    cin >> a;
    print(a + a * a + a * a * a);

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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

// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

void solve()
{
  ll D, G; cin >> D >> G;
  vector<ll> p(D), c(D); rep(i, D) cin >> p[i] >> c[i];
  vector<ll> cp(D); rep(i, D) cp[i] = (i + 1) * p[i] * 100 + c[i];
  rep(i, D) cerr << i << " cp:" << cp[i] << endl;
  ll pmin = -1;
  for(ll i = 0; i < (1<<D); i++) {
    ll ttl = 0;
    ll nop = 0;
    for(ll j = 0; j < D; j++) {
      if(i & 1<<j) {
	ttl += cp[j];
	nop += p[j];
      }
    }
    cerr << i << " ttl:" << ttl << endl;
    if(ttl < G) {
      ll mxp ;
      for(mxp = D - 1; mxp >=0 && ((i & 1 << mxp) !=0); mxp--) ;
      cerr << " mxp:" << mxp << endl;
      rep(j, p[mxp] - 1) {
	ttl += (mxp + 1) * 100;
	nop ++;
	if(ttl >= G) break;
      }
    }
    cerr << " nop:" << nop << endl;
    if(ttl >= G &&(pmin < 0 || nop < pmin)) pmin = nop;
  }

  cout << pmin << endl;

}

int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a)
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
using namespace __gnu_pbds;

const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod;

inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}

const int maxn=100005;
//i_am_noob
int n,goal,a[10][2],cnt,x,ans=4e18;
bool flag;

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
    cin >> n >> goal;
    rep(n) rep1(j,2) cin >> a[i][j];
    rep(pow2(n)){
        cnt=x=0;
        rep1(j,n) if(i&pow2(j)){
            x+=a[j][0];
            cnt+=a[j][0]*(j+1)*100+a[j][1];
        }
        if(cnt>=goal){
            ans=min(ans,x);
            continue;
        }
        flag=false;
        rep3(j,n-1,0) if((i&pow2(j))==0){
            rep1(k,a[j][0]){
                x++;
                cnt+=(j+1)*100;
                if(cnt>=goal){
                    ans=min(ans,x);
                    flag=true;
                    break;
                }
            }
            if(flag) break;
        }
    }
    print1(ans);
	return 0;
}


#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

int main() {
    int n;
    while(cin>>n){
        if(n==0)break;
        queue<int> output;
        ll man[5000]={};
        rep(i,n){
            int a,b,c;
            cin>>a>>b>>c;
            if(man[a]==0){
                output.push(a);
            }
            if(man[a]<1000000){
                man[a]+=(ll)b*c;
            }
        }
//        while(output.size()){cout<<output.front();output.pop();}
        bool flag=true;
        while(output.size()){
            if(man[output.front()]>=1000000){
                cout<<output.front()<<endl;
                flag=false;
            }
            output.pop();
        }
        if(flag)cout<<"NA"<<endl;
    }

    return 0;
}


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

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	multiset<int,greater<int> > M;
	for(int i=1,x;i<=n;i++)
		cin>>x,M.insert(x);
	int ans = 0;
	while(M.size()){
		int x = *M.begin();
		M.erase(M.begin());
		int y = (1<<(32-__builtin_clz(x)))-x;
		if(M.count(y)){
			ans++;
			M.erase(M.find(y));
		}
	}
	cout<<ans<<endl;
}

#include <bits/stdc++.h>
#define int long long
#define gcd            __gcd
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define deci(x,y)      fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define nitin          ios_base::sync_with_stdio(false); cin.tie(NULL)
#define PI             3.141592653589793238
using namespace std;

int power(int x, int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
int modi(int a, int m)
{
    return power(a, m - 2, m);
}
string find_ans(int n,vector<int>& v,string s)
{
    if(n==1)
    {
        if(v[0]%2==0)
        {
            return s;
        }
        else{
            if(s=="First")
            return "Second";
            else
                return "First";
        }
    }
    int e=0;
    int o=0;
    for(auto c:v)
    {
        if(c%2==0)
            e++;
        else
            o++;
    }
    if(e==1 || e%2!=0)
    {
        return s;
    }
    else if(e%2==0 && o>1){
        if(s=="First")
            return "Second";
        else
            return "First";
    }
    else{
        int g=v[0];
        for(auto &c:v)
        {
            if(c&1)
                c-=1;
        }
        for(auto c:v)
        {
            g=gcd(g,c);
        }
        for(auto &c:v)
        {
            c=c/g;
        }
        if(s=="First")
            s="Second";
        else
            s="First";
        return find_ans(n,v,s);
    }
}
int32_t main()
{
    nitin;
    int n;
    cin>>n;
    vector<int>v(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    cout<<find_ans(n,v,"First")<<endl;
    return 0;
}


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

int main(){
    int k,t;
    cin >> k >> t;
    multiset<int> s;
    rep(i,t){
        int temp;
        cin >> temp;
        s.insert(temp);
    }
    int st = 0;
    rep(i,k){
        if(s.size()==0){
            cout << st << endl;
            return 0;
        }

        int temp = *(--s.end());
        --temp;
        //cout << " " << temp << endl;
        s.erase(--s.end());
        //cout << "  " << s.size() << endl;
        if(st>0&&i>0) s.insert(st);
        st = temp;
    }

    cout << 0 << endl;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 0; i < n; ++i)
#define rep3(i, a, b) for (ll i = a; i < b; ++i)
#define rep4(i, a, b, c) for (ll i = a; i < b; i += c)
#define erep(n) for (ll i = 0; i <= n; ++i)
#define erep2(i, n) for (ll i = 0; i <= n; ++i)
#define erep3(i, a, b) for (ll i = a; i <= b; ++i)
#define erep4(i, a, b, c) for (ll i = a; i <= b; i += c)
#define rrep(i, a, b) for (ll i = a; i > b; --i)
#define rrep2(i, a, b, c) for (ll i = a; i > b; i -= c)
#define errep(i, a, b) for (ll i = a; i >= b; --i)
#define errep2(i, a, b, c) for (ll i = a; i >= b; i -= c)
#define print(a) cout << a << endl;
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define cin(x) cin >> x;
const ll MOD = 1000000007;
const double PI = 3.14159265358979323846264338327950;
inline int newline() { putchar('\n'); return 0; }

int main() {
    ll left, right;
    cin(left); cin(right);

    if (2019 - left % 2019 <= right - left) {
        print(0);
        return 0;

    } else {
        ll result = LLONG_MAX;
        rep3(i, left, right) {
            erep3(j, i + 1, right) {
                if (i * j % 2019 < result) result = i * j % 2019;
            }
        }
        print(result);
        return 0;
    }
}


#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
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; }
struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } };
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void)
{
    ll k, x;
    cin >>k >>x;

    for(int i = x -(k-1); i <= x +(k-1); i++) {
        if (i == x +(k-1)) cout <<i << endl; else cout <<i << " ";
    }
}

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

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


#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>

typedef long double ld;
typedef long long ll;

using namespace std;

string a, b, c;
int n;

int main() {
	cin >> n;
	cin >> a >> b >> c;
	int ret = 0;
	for (int i = 0; i < n; i++) {
		set<char> s;
		s.insert(a[i]);
		s.insert(b[i]);
		s.insert(c[i]);
		//cerr << s.size() << endl;
		ret += s.size() - 1;
	}
	cout << ret << endl;
	return 0;
}

#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define pi 3.14159265358979323846264338327950L
using namespace std;

int main() {
  int N, ans;
  string A, B, C;
  cin >> N >> A >> B >> C;
  ans=0;
  for (int i=0; i<N; i++) {
    if (A[i]==B[i] && B[i]==C[i]) {
      ans=ans;
    }
    else {
      if (A[i]==B[i] || B[i]==C[i] || C[i]==A[i]) {
        ans=ans+1;
      }
      else {
        ans=ans+2;
      }
    }
  }
  cout << ans << endl;
}


#include <bits/stdc++.h>

using namespace std;

int N, M, A[1111], B[1111], V[1111];

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

    for (int i = 1; i <= N; i++)
        cin >> A[i];

    for (int i = 1; i <= M; i++)
        cin >> B[i];

    for (int i = 1; i <= M; i++)
    {
        for (int j = 1; i <= N; j++)
        {
            if (A[j] <= B[i])
            {
                V[j]++;

                break;
            }
        }
    }

    cout << distance(V, max_element(V, V + N)) << endl;

    return 0;
}

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

int main() {
  int N, M; cin >> N >> M;
  vector<int> cost(N);
  for(int i = 0; i < N; ++i)
    cin >> cost[i];
  vector<int> score(N, 0);
  while(M--) {
    int x; cin >> x;
    for(int i = 0; i < N; ++i) {
      if(cost[i] <= x) {
        score[i]++;
        break;
      }
    }
  }
  int argmax = find(score.begin(), score.end(), *max_element(score.begin(), score.end())) - score.begin();
  cout << argmax + 1 << endl;
}


#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;

constexpr int LIM = 10006;

char isprime[LIM];
int twinprime[LIM];

void setprime() {
    fill(isprime, isprime+LIM, 1);
    isprime[0] = isprime[1] = 0;
    for (int x = 2; x * x < LIM; ++x) {
        if (isprime[x]) {
            for (int y = x * x; y < LIM; y += x) {
                isprime[y] = 0;
            }
        }
    }
    for (int x = 5; x < LIM; ++x) {
        if (isprime[x-2] && isprime[x]) {
            twinprime[x] = x;
        } else {
            twinprime[x] = twinprime[x-1];
        }
    }
}

bool solve() {
    int n;
    cin >> n;
    if (n == 0) { return false; }
    int ans = twinprime[n];
    cout << (ans - 2) << ' ' << ans << endl;
    return true;
}

int main() {
    setprime();
    while(solve());
    return 0;
}

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

int main(){
  int prime[10001]={0};

  prime[0]=prime[1]=1;
  for(int i=2;i<sqrt(10000);i++){
    if(!prime[i]){
      for(int j=0;i*(j+2)<10000;j++){
	prime[i*(j+2)]=1;
      }
    }
  }

  int n;
  while(cin>> n,n){
    for(int i=n;i>1;i--){
      if(!prime[i] && !prime[i-2]){
	printf("%d %d\n",i-2,i);
	break;
      }
    }
  }
}


#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<time.h>
#include<cassert>

using namespace std;
#define ll long long
#define ld long double
#define int long long
#define all(a) (a).begin(),(a).end()
#define EPS (1e-13)
#define fs first
#define sc second
#define xx first
#define yy second.first
#define zz second.second
#define P pair<int, int>
#define Q pair<int, pair<int, int>>
#define rep(i,n) for(int (i) = 0 ; (i) < (n) ; (i)++)
#define mkp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define crdcomp(b) sort(all((b)));(b).erase(unique(all((b))),(b).end())
const int Mod = 1e9 + 7;
const int mod = 998244353;
const ll Inf = 3 * 1e18;
const int inf = 15 * 1e8;
ll read() {
	ll u, k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}
ll bcount(ll x) {
	int sum = 0;
	for (int i = 0; i < 20; i++)
		if ((1ll << i) & x) sum++;
	return sum;
}
const int fn_ = 2000000;
ll fact_[fn_], comp_[fn_];
ll comb(ll x, ll y, ll mod = Mod) {
	if (!fact_[0]) {
		fact_[0] = 1; comp_[0] = 1;
		for (int i = 1; i < fn_; i++) {
			fact_[i] = fact_[i - 1] * i % mod;
			comp_[i] = mod_pow(fact_[i], mod - 2, mod);
		}
	}
	if (x < y) return 0;
	return fact_[x] * comp_[x - y] % mod * comp_[y] % mod;
}
//---------------------------------------------------
int n, m;
int solve(int i, int n, int m) {
	return comb((m - i) / 2 + m + n - 1, n - 1, mod) * comb(n, i, mod);
}
signed main() {
	cin >> n >> m;
	int ans = 0;
	for (int i = 0; i <= m && i <= n; i++) {
		if ((m - i) % 2) continue;
		(ans += solve(i, n, m)) %= mod;
	}
	for (int i = 2 * m + 1; i <= 3 * m; i++) {
		(ans -= n * comb(3 * m - i + n - 2, n - 2, mod)) %= mod;
	}
	cout << (ans + mod) % mod << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; ll m; cin >> n >> m;
  vector<ll> A(n), sum(n+1);
  rep(i, n) {
    cin >> A[i];
    sum[i+1] = sum[i] + A[i];
  }
  map<ll, ll> rem;
  rep(i, n+1) rem[sum[i]%m]++;
  ll ans = 0;
  for(auto ele: rem) {
    ans += ele.second * (ele.second-1) / 2;
  }
  cout << ans << "\n";
  return 0;
}


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

int main(){
  int n;
  while(cin >> n,n){

    vector<pii> v(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;

      auto time=a+b+c+m*(d+e);
      auto price=m*s*f - p;

      v[i]=make_pair((double)price/(double)time,l);
    }

    sort(v.begin(),v.end(),[](auto x,auto y)->bool{
          return x.first == y.first ? x.second < y.second : (x.first > y.first);
        });

    for(auto i:v){
      cout<<i.second<<endl;
    }
    cout << "#" << endl;
  }
}

#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 each(itr,v) for(auto itr:v)
#define pb push_back
#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_popcount

#define INF INT_MAX/3

int m,nmin,nmax;
int a[1111];

int main(){
	cin.sync_with_stdio(false);
  while(cin>>m>>nmin>>nmax){
    if(m==0)break;
    rep(i,m)cin>>a[i];
    sort(a,a+m);
    reverse(a,a+m);
    int gap=0,res=-1;
    repl(i,nmin-1,nmax){
      if(gap<=a[i]-a[i+1]){
        gap=a[i]-a[i+1];
        res=i+1;
      }
    }
    cout<<res<<endl;
  }
	return 0;
}


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

int main()
{
	int n,i;
	int sum = 0;
	int d = 10000000;
	int a,b,c;
	int x;
	cin >> n;

	for(i = 0 ; i < 8 ; i++)
	{
		a = d*10;
		b = n/a;
		c = b*10;
		sum += n/d - c ;
		d /= 10;
	}
	x = n/sum;
	if (sum != 0 && x*sum == n)
	cout << "Yes" << endl;

	else
	cout << "No" << endl;

}

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

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

  int num = 0;

  for(int i = 0; i < (int)str.size(); ++i){
    num +=(int)(str[i] - '0');
  }

      int N = atoi(str.c_str());

  if(N % num == 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

}


#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	int i,a,b,m[3];
	scanf("%d %d",&a,&b);
	for(i=0;i<3;i++){
		m[0]=a+b;
		m[1]=a-b;
		m[2]=a*b;
	}
	sort(m,m+3);
	printf("%d\n",m[2]);
	return 0;
}

#include <iostream>

using namespace std;

int main(void) {
	int a, b;
	cin >> a >> b;
	int max = a + b;
	if (a - b > max)
		max = a - b;
	if (a*b > max)
		max = a * b;
	cout << max;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    int m = n;
    int wa=0;
    while(n>0){
        wa+=n%10;
        n/=10;
    }
    if(m%wa==0)cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

//

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll, string>;
using garph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
	string s;cin>>s;
	cout<<s.substr(0,s.size()-8)<<nnn;
    return 0;
}


#include<bits/stdc++.h>
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

struct st {
	int f[20][20], cnt, x, y, id;
};
int dx[]{ 1,-1,0,0 }, dy[]{ 0,0,1,-1 };
int main() {
	st in;
	int w, h;
	while (scanf("%d%d", &w, &h), w) {
		rep(i, h)rep(j, w) {
			scanf("%d", &in.f[i][j]);
			if (in.f[i][j] == 2)in.x = i, in.y = j;
		}
		in.cnt = 0;
		in.id = -1;
		queue<st>que;
		que.push(in);
		int Min = INT_MAX;
		while (!que.empty()) {
			st s = que.front(); que.pop();
			if (s.f[s.x][s.y] == 3) {
				Min = min(Min, s.cnt);
				continue;
			}
			if (s.id == -1) {
				rep(i, 4) {
					int nx = s.x + dx[i], ny = s.y + dy[i];
					if (0 <= nx&&nx < h && 0 <= ny&&ny < w&&s.f[nx][ny] != 1) {
						st p = s; p.cnt++; p.x = nx; p.y = ny; p.id = i;
						if (p.cnt <= 10 && p.cnt < Min)que.push(p);
					}
				}
			}
			else {
				int nx = s.x + dx[s.id], ny = s.y + dy[s.id];
				if (0 <= nx&&nx < h && 0 <= ny&&ny < w) {
					if (s.f[nx][ny] == 1) {
						st p = s; p.f[nx][ny] = 0; p.id = -1;
						que.push(p);
					}
					else {
						st p = s; p.x = nx; p.y = ny;
						que.push(p);
					}
				}
			}
		}
		if (Min == INT_MAX)puts("-1");
		else printf("%d\n", Min);
	}
}

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

#define rep(i,n) for(int i=0; i<n; i++)
#define reep(i,a,b) for(int i=a; i<b; i++)
#define fi first
#define se second

using pii = pair<int,int>;
using vint = vector<char>;
using vvint = vector<vector<char>>;
using bit = bitset<400>;

int w,h;
bool inside(int a, int b){
	return 0<=a&&a<h&&0<=b&&b<w;
}

int dd[] = {0,1,0,-1,0};

int main(){
	while(cin>>w>>h,w){
		pii start;
		pii goal;
		bit vv(0);
		rep(i,h) rep(j,w){
			int t;
			cin>>t;
			if(t==1) vv[i*20+j]=1;
			if(t==2){
				start = pii(i,j);
			}
			if(t==3){
				goal = pii(i,j);
			}
		}
		bool ok = false;
		queue<pair<pii,bit>> q;
		q.push(make_pair(start, vv));
		int ans = 20;
		rep(_,11){
			int qs = q.size();
			rep(i,qs){
				pii now = q.front().fi;
				bit vv = q.front().se;
				// rep(ii,h){
				// 	rep(jj,w){
				// 		cout<<vv[ii][jj]<<" ";
				// 	}
				// 	cout<<endl;
				// }
				q.pop();
				rep(j,4){
					pii next = now;
					next.fi += dd[j];
					next.se += dd[j+1];
					// cout<<next.fi<<" "<<next.se<<" "<<inside(next.fi, next.se)<<endl;
					if(inside(next.fi, next.se) && vv[next.fi*20+next.se]==0){
						// cout<<"hoge"<<endl;
						while(inside(next.fi, next.se)&&vv[next.fi*20+next.se]==0){
							// cout<<"vv "<<vv[next.fi*20+next.se]<<endl;
							if(next == goal) ans = min(ans, _+1);
							next.fi += dd[j];
							next.se += dd[j+1];
						}
						if(inside(next.fi, next.se)){
							vv[next.fi*20+next.se] = 0;
							next.fi -= dd[j];
							next.se -= dd[j+1];
							q.push(make_pair(next, vv));
							next.fi += dd[j];
							next.se += dd[j+1];
							vv[next.fi*20+next.se] = 1;
						}
					}
				}
			}
		}
		cout<<(ans<=10?ans:-1)<<endl;
	}
}


#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;

int main(){

	int N,Q,M,Date[101],i,l,k;

	while(0<=scanf("%d%d",&N,&Q)){
		for(i=0;i<101;i++){
			Date[i]=0;
		}

		if((N==0) && (Q==0)){
			break;
		}

		for(k=0;k<N;k++){
			scanf("%d",&M);
			if(M==0){
				continue;
			}else{
				for(i=0;i<M;i++){
					scanf("%d",&l);
					++Date[l];
				}
			}
		}
		l=0;
		i=0;
		for(k=0;k<100;k++){
			if(i<Date[k] && Date[k]>=Q){
				i=Date[k];
				l=k;
			}
		}

		printf("%d\n",l);
	}

	return 0;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init));

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

vector<string> Split(char c,string s){
  vector<string> res(0);
  string str = "";
  rep(i,s.size()){
    if(s[i] == c){
      res.push_back(str);
      str.clear();
    }
    else{
      str += s[i];
    }
  }
  res.push_back(str);
  return res;
}
template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,m;
  while(cin >> n >> m && n && m){
    vector<ll> v(101);
    ll k,tmp;
    rep(i,n){
      cin >> k;
      rep(j,k){
        cin >> tmp;
        v[tmp]++;
      }
    }
    ll ans = 0,cnt = m-1;
    rep(i,101){
      if(v[i] >= cnt){
        if(v[i] > cnt)
          ans = i;
        cnt = v[i];
      }
    }
    if(ans) cout << ans << endl;
    else cout << 0 << endl;
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  vector<pair<int,char>> vec;
  for(int i=0;i<m;i++){
    int s;
    char c;
    cin>>s>>c;
    vec.push_back(make_pair(s,c));
  }
  for(int i=0;i<1000;i++){
    string s=to_string(i);
    if(s.size()!=n)continue;
    bool ok=true;
    for(auto x:vec){
      int p=x.first;
      char moji=x.second;
      p--;
      if(s[p]!=moji)ok=false;
      if(n>1 && p==0 && moji=='0'){
        cout<<-1<<endl;
        return 0;
      }
    }
    if(ok){
      cout<<s<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;
  return 0;
}

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

using namespace std;

int main()
{
	int n,m;
	while(cin>>n>>m,n)
	{
		vector<int> G[500];
		int u,v;
		for(int i=0;i<m;i++)
		{
			cin>>u>>v;
			u--;v--;
			G[u].push_back(v);
			G[v].push_back(u);
		}
		vector<int> F;
		for(int i=0;i<G[0].size();i++)
		{
			F.push_back(G[0][i]);
			for(int j=0;j<G[G[0][i]].size();j++)
			{
				F.push_back(G[G[0][i]][j]);
			}
		}
		sort(F.begin(),F.end());
		F.erase(unique(F.begin(),F.end()),F.end());
		if(F.size())cout<<F.size()-1<<endl;
		else cout<<F.size()<<endl;
	}
	return 0;
}


#include <iostream>
using namespace std;

int main() {
	int numberA[4], b, c, i, min, ans=0;
	for (i = 0; i <= 3; i++) {
		cin >> numberA[i];
		if (i == 0) {
			min = numberA[0];
		}
		if (i > 0) {
			if (numberA[i] < min) {
				min = numberA[i];
			}
			else if (numberA[i] > min) {
				min = min;
			}
			else {
				min = min;
			}
		}
	}
	ans = (numberA[0] + numberA[1] + numberA[2] + numberA[3]) - min;

	cin >> b;
	cin >> c;
	if (b > c) {
		ans += b;
	}
	else if (b < c) {
		ans += c;
	}
	else {
		ans += b;
	}

	cout << ans << endl;

	return 0;
}

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

ll minimum(ll a,ll b,ll c,ll d,ll e){
  return min(min(a,min(b,c)),min(d,e));
}

int main(){
  ll n,a,b,c,d,e;
  cin >> n >> a >> b >> c >> d >> e;
  ll time=4;
  ll data=minimum(a,b,c,d,e);
  time+=(n/data);
  if(n%data!=0){
    time++;
  }
  cout << time << endl;
}


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

int main(){
  string s;
  cin>>s;
  bool at=true;
  if(s.size()%2!=0){
    cout<<"No"<<endl;
    return 0;
  }
  for(int i=0;i<s.size()-1;i+=2){
    if(s[i]!='h'||s[i+1]!='i'){
      at=false;
      break;
    }
  }
  if(at==true) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

class Dice{
 public:
  int face[7];

  Dice(){
   for(int i = 1; i <= 6; i++)
    cin >> face[i];
  }

  void roll_z(){ roll(2,3,5,4);}
  void roll_y(){ roll(1,3,6,4);} // to W
  void roll_x(){ roll(1,2,6,5);} // to N
  void roll(int i, int j, int k, int l){
   int t = face[i]; face[i] = face[j]; face[j] = face[k]; face[k] = face[l]; face[l] = t;
  }

  void Roll(char d){
   if(d == 'E') for(int i = 0; i < 3; i++) roll_y();
   if(d == 'W') roll_y();
   if(d == 'N') roll_x();
   if(d == 'S') for(int i = 0; i < 3; i++) roll_x();
  }
 };

int main(){
 Dice dice;
 string com;

 cin >> com;

 for(int i = 0; i < com.size(); i++)
  dice.Roll(com[i]);

 cout << dice.face[1] << endl;

 return 0;
}


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

int main() {
  ll n;
  cin >> n;
  map<char, vector<P>> mp;
  rep(i, n) {
    ll x, y;
    char c;
    cin >> x >> y >> c;
    mp[c].push_back({x, y});
  }
  ll ans = 1e18;
  map<ll, set<ll>> ds, ls;
  for(auto p : mp['D']) ds[p.first].insert(p.second);
  for(auto p : mp['U']) {
    ll x = p.first;
    ll y = p.second;
    auto in = ds[x].lower_bound(y);
    if(in == end(ds[x])) continue;
    ll now = (*in - y) * 5;
    ans = min(ans, now);
  }
  for(auto p : mp['L']) ls[p.second].insert(p.first);
  for(auto p : mp['R']) {
    ll x = p.first;
    ll y = p.second;
    auto in = ls[y].lower_bound(x);
    if(in == end(ls[y])) continue;
    ll now = (*in - x) * 5;
    ans = min(ans, now);
  }

  map<ll, set<ll>> u, d;
  for(auto p : mp['U']) u[p.first + p.second].insert(p.first);
  for(auto p : mp['D']) d[p.first - p.second].insert(p.first);
  for(auto p : mp['R']) {
    ll x = p.first;
    ll y = p.second;
    auto in = u[x + y].lower_bound(x);
    ll now;
    if(in != end(u[x + y])) {
      now = (*in - x) * 10;
      ans = min(ans, now);
    }
    in = d[x - y].lower_bound(x);
    if(in != end(d[x - y])) {
      now = (*in - x) * 10;
      ans = min(ans, now);
    }
  }

  u.clear();
  d.clear();
  for(auto p : mp['U']) u[p.first - p.second].insert(p.first);
  for(auto p : mp['D']) d[p.first + p.second].insert(p.first);
  for(auto p : mp['L']) {
    ll x = p.first;
    ll y = p.second;
    auto in = u[x - y].upper_bound(x);
    ll now;
    if(in != begin(u[x - y])) {
      in--;
      now = (x - *in) * 10;
      ans = min(ans, now);
    }
    in = d[x + y].upper_bound(x);
    if(in != begin(d[x + y])) {
      in--;
      now = (x - *in) * 10;
      ans = min(ans, now);
    }
  }

  if(ans == 1e18)
    cout << "SAFE" << endl;
  else
    cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100001,INF=1<<30;
int V;
vector<int> G[MAX],rG[MAX],vs;
bool used[MAX];
int cmp[MAX];

void add_edge(int from,int to){
    G[from].push_back(to);
    rG[to].push_back(from);
}

void DFS(int v){
    used[v]=1;
    for(int i=0;i<G[v].size();i++){
        if(used[G[v][i]]==0) DFS(G[v][i]);
    }
    vs.push_back(v);
}

void rDFS(int v,int k){
    used[v]=1;
    cmp[v]=k;
    for(int i=0;i<rG[v].size();i++){
        if(used[rG[v][i]]==0) rDFS(rG[v][i],k);
    }
}

int scc(){
    memset(used,0,sizeof(used));
    vs.clear();
    for(int v=0;v<V;v++){
        if(used[v]==0) DFS(v);
    }

    memset(used,0,sizeof(used));
    int k=0;
    for(int i=vs.size()-1;i>=0;i--){
        if(used[vs[i]]==0) rDFS(vs[i],k++);
    }
    return k;
}

int main(){

    int E;cin>>V>>E;
    for(int i=0;i<E;i++){
        int a,b;cin>>a>>b;
        add_edge(a,b);
    }

    scc();

    int Q;cin>>Q;
    for(int i=0;i<Q;i++){
        int a,b;cin>>a>>b;
        if(cmp[a]==cmp[b]) cout<<1<<endl;
        else cout<<0<<endl;
    }

}


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

int main ()
{
    double x1,y1,x2,y2,x3,y3;
    cin>>x1>>y1>>x2>>y2;
    x3=pow(x1-x2,2);
    y3=pow(y1-y2,2);
    printf("%f",sqrt(x3+y3));
    return 0;
}

#include<cstdio>

long double sqrt(double);

int main(void){
long double d;
double x1,y1,x2,y2,D;
scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
D=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
sqrt(D);
d=sqrt(D);
printf("% 8.8Lf\n",d);
return 0;
}

long double sqrt(double a){
int i;
long double b=3;
for(i=0;i<256;i++){
b=(b/2)+(a/(2*b));

}
return b;
}


#include <bits/stdc++.h>

using namespace std;

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

string solve() {
    size_t k; cin >> k;
    string s; cin >> s;
    if (s.size() > k) {
        return s.substr(0, k) + "...";
    }

    return s;
}

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

	cout << solve() << endl;
}

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

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

  if (s.size() <= k) cout << s << endl;
  else {
    for (int i = 0; i < k; i++) {
      cout << s.at(i);
    }
    cout << "..." << endl;
  }
}


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

//#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

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

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

const double EPS=1e-8;
const double INF=1e12;

typedef complex<double> P;

namespace std {
	bool operator<(const P &a,const P &b) {
		return real(a)!=real(b)?real(a)<real(b):imag(a)<imag(b);
	}
}

double cross(const P &a,const P &b) {
	return imag(conj(a)*b);
}

double dot(const P &a,const P &b) {
	return real(conj(a)*b);
}

int ccw(P a,P b,P c) {
	b-=a;c-=a;
	if(cross(b,c)>0) 	return +1;
	if(cross(b,c)<0) 	return -1;
	if(dot(b,c)<0)	 	return +2;
	if(norm(b)<norm(c)) return -2;
	return 0;
}

vector<P> convex(vector<P> ps) {
	int n=(int)ps.size(),k=0;
	sort(ALL(ps));
	vector<P> ch(2*n);
	for(int i=0;i<n;ch[k++]=ps[i++]) {
		while(k>=2&&ccw(ch[k-2],ch[k-1],ps[i])<=0) --k;
	}
	for(int i=n-2,t=k+1;i>=0;ch[k++]=ps[i--]) {
		while(k>=t&&ccw(ch[k-2],ch[k-1],ps[i])<=0) --k;
	}
	ch.resize(k-1);
	return ch;
}

int n;

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

	cin>>n;
	vector<P> ps;
	map<P,int> idx;
	REP(i,n) {
		double x,y;cin>>x>>y;
		ps.pb(P(x,y));
		idx[P(x,y)]=i;
	}
	vector<double> ans(n,0.0);
	vector<P> res=convex(ps);

	int sz=(int)res.size();
	if(sz==2) {
		for(auto p:res) ans[idx[p]]=0.5;
	}
	else {
		REP(i,sz) {
			P prv=res[(i-1+sz)%sz],crt=res[i],nxt=res[(i+1)%sz];
			double result=arg((crt-nxt)/(prv-crt));
			if(result<0) result+=2*PI;
			ans[idx[crt]]=result/(2*PI);
		}
	}
	REP(i,n) printf("%.12f\n",ans[i]);

	return 0;
}

#define _CRT_SECURE_NO_WARNINGS // #pragma warning(disable:4996)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <sstream>
#include <cmath>
#include <set>
#include <map>
#include <stack>
using namespace std;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define all(a) a.begin(),a.end()
#define len(x) ((int)(x).size())
#define tmax(a,b,c) max((a),max((b),(c)))
#define tmin(a,b,c) min((a),min((b),(c)))
#define debug(x) cerr << #x << " is " << x << endl;
#define debug2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define debugg(g,h,w) rep(i,0,h) { rep(j,0,w) cout << g[i][j] << " "; cout << endl;}
#define debugv(v) for(auto&& x : v){cout << x << " ";} cout << endl;

typedef pair<int, int> Pii;
typedef map<int, int> Mii;
typedef vector<int> Vi;
typedef vector<vector<int> > VVi;
typedef long long ll;
const int inf = 2e9;
const ll ll_inf = 1e17;
const int mod = 1e9 + 7;
const long double eps = 1e-10;
typedef pair<ll, ll> Pll;

bool opt(pair<double, string>  &lhs, pair<double, string>  &rhs)
{
	if (lhs.first == rhs.first) return lhs.second < rhs.second;
	else return lhs.first > rhs.first;
}

int main()
{
	int n;
	while (cin >> n && n) {
		vector<pair<double, string> > v(n);
		rep(i,0,n) {
			string l;
			int a,b,c,d,e,f,s,m,p;
			cin >> l >> p >> a >> b >> c >> d >> e >> f >> s >> m;
			double x = f*m * s - p;
			//printf("price = %lf, time = %d\n",x, (a+b+c)+m*(d+e));
			x /= (a+b+c) + m*(d+e);
			v[i] = mp(x,l);
			//printf("%s = %lf\n",l.c_str(),x);
		}
		sort(all(v), opt);
		rep(i,0,n) cout << v[i].second << endl;
		cout << "#" << endl;
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,-1,0};
int dy[4]={1,0,0,-1};
long double eps = 1e-6;
long double pi = acos(-1);

ll mod = 998244353;
template<typename T> void add(T &a,T b){a=(a+b)%mod;}
template<typename T> void sub(T &a,T b){a=(a+mod-b)%mod;}

int dp[333][333][333];

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

    string s;
    int k;
    cin>>s>>k;
    int n = s.size();
    int sum[n+1]={};
    int z = 0;
    int o = 0;
    for(int i=0;i<n;i++){
        if(s[i] == '0'){
            z++;
            sum[z+1] = sum[z];
        }
        else o++;
        sum[z+1] = o;
    }

    dp[0][0][0] = 1;
    for(int i=0;i<z;i++){
        for(int y=0;y<=min(k,o);y++){
            for(int j=sum[i];j<=min(o,sum[i]+k);j++){
                if(dp[i][j][y] == 0)continue;
                if(j-sum[i] > y)break;
                for(int p=max(j,sum[i+1]);p<=min(sum[i+1]+k,o);p++){
                    int ret = dp[i][j][y];
                    int cnt = y;
                    int dif = p - j;
                    dif -= sum[i+1] - sum[i];
                    dif = max(0,dif);
                    cnt += dif;
                    if(cnt <= k){
                        add(dp[i+1][p][cnt],ret);
                    }
                    else break;
                }
            }
        }
    }
    int ans = 0;
    for(int i=sum[z];i<=o;i++){
        for(int y=0;y<=min(o,k);y++){
            add(ans,dp[z][i][y]);
        }
    }
    cout << ans << endl;
}

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 303
const int mod=998244353;
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int n,m,gu,dp[N][N][N],a[N],ans,sum[N];
char s[N];
int main(){
	scanf("%s",s+1);
	n=strlen(s+1),m=read();
	s[++n]='0';
	m=min(n,m);
	for(int i=1;i<=n;++i){
		if(s[i]=='0')++gu;
		else ++a[gu+1];
	}
	for(int i=1;i<=gu;++i){
		sum[i]=a[i]+sum[i-1];
	}
	dp[0][0][0]=1;
	for(int i=1;i<=gu;++i){
		for(int j=sum[i];j<=n-gu;++j){
			int lim=min(j,n-sum[i-1]-gu);
			for(int k=0;k<=m;++k){
				for(int p=0;p<=lim;++p){
					if(max(0,p-a[i])<=k)dp[i][j][k]=(dp[i][j][k]+dp[i-1][j-p][k-max(0,p-a[i])])%mod;
				}
			}
		}
	}
	for(int k=0;k<=m;++k){
		ans=(ans+dp[gu][n-gu][k])%mod;
	}
	cout<<ans<<endl;
	return 0;
}


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

vector<int> suffix_array(vector<int>& s) {
    int n = s.size();
    vector<int> p(n), c(n), cnt(n);
    for (int i = 0; i < n; i++) cnt[s[i]]++;
    for (int i = 1; i < n; i++) cnt[i] += cnt[i-1];
    for (int i = 0; i < n; i++) p[--cnt[s[i]]] = i;
    int cl = 0;
    for (int i = 1; i < n; i++) {
        if (s[p[i]] != s[p[i-1]]) cl++;
        c[p[i]] = cl;
    }
    vector<int> pn(n), cn(n);
    for (int h = 0; (1 << h) < n; h++) {
        for (int i = 0; i < n; i++) {
            pn[i] = p[i] - (1 << h);
            if (pn[i] < 0) pn[i] += n;
        }
        fill(cnt.begin(), cnt.end(), 0);
        for (int i = 0; i < n; i++) cnt[c[pn[i]]]++;
        for (int i = 1; i < n; i++) cnt[i] += cnt[i-1];
        for (int i = n - 1; i >= 0; i--) {
            cnt[c[pn[i]]]--;
            p[cnt[c[pn[i]]]] = pn[i];
        }
        cn[p[0]] = 0;
        cl = 0;
        for (int i = 1; i < n; i++) {
            pair<int, int> cur(c[p[i]], c[(p[i] + (1 << h)) % n]);
            pair<int, int> prev(c[p[i-1]], c[(p[i-1] + (1 << h)) % n]);
            if (cur != prev) cl++;
            cn[p[i]] = cl;
        }
        swap(c, cn);
    }
    return p;
}

int bin_search(vector<int>& a, vector<int>& b, vector<int>& sa, bool lower) {
    int n = a.size();
    int lb = -1, ub = n;
    while (ub - lb > 1) {
        int m = (lb + ub) / 2;
        bool flag = false;
        for (int i = 0; i < n; i++) {
            int j = (sa[m] + i) % n;
            if (a[i] < b[j]) {
                ub = m;
                flag = true;
                break;
            }
            if (a[i] > b[j]) {
                lb = m;
                flag = true;
                break;
            }
        }
        if (!flag) {
            if (lower) ub = m;
            else lb = m;
        }
    }
    return ub;
}

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

    int N;
    cin >> N;
    vector<int> a(N), b(N);
    for (int i = 0; i < N; i++) cin >> a[i];
    for (int i = 0; i < N; i++) cin >> b[i];
    vector<int> cnt(N);
    for (int i = 0; i < 30; i++) {
        vector<int> c(N), d(N);
        for (int j = 0; j < N; j++) {
            c[j] = a[j] >> i & 1;
            d[j] = b[j] >> i & 1;
        }
        auto sa = suffix_array(d);
        int lb = bin_search(c, d, sa, true);
        int ub = bin_search(c, d, sa, false);
        for (int j = lb; j < ub; j++) cnt[(N - sa[j]) % N]++;

        for (int j = 0; j < N; j++) c[j] = 1 - c[j];
        lb = bin_search(c, d, sa, true);
        ub = bin_search(c, d, sa, false);
        for (int j = lb; j < ub; j++) cnt[(N - sa[j]) % N]++;
    }
    for (int k = 0; k < N; k++) {
        if (cnt[k] == 30) {
            int x = a[k] ^ b[0];
            cout << k << " " << x << "\n";
        }
    }
}


#include <iostream>
#include <cstdio>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());

int main(){
	int n;
	cin>>n;
	vector<ll> v(n,1);
	rep(i,n) cin>>v[i];
	ll tt=v[0];
	rep(i,n){
		tt=min(v[i],tt);
	}
	// cout<<tt<<endl;
	rep(i,tt){
		bool f=true;
		rep(j,n){
			if(v[j]%(i+1)==0) continue;
			else{
				f=false;
				break;
			}
		}
		if(f) cout<<i+1<<endl;
	}
}

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

#define MAX_INPUT_SIZE  1024

void trace(int num, int* array);
int bubbleSort(int num, int* array);

int
main(int argc, char* argv[])
{
    char input[MAX_INPUT_SIZE];

    int num = atoi(fgets(input, sizeof(input), stdin));
    int* array = new int[num];

    atoi(fgets(input, sizeof(input), stdin));
    for (int i = 0; i < num; i++) {
        array[i] = i == 0 ?
            atoi(strtok(input, " ")) : atoi(strtok(NULL, " "));
        //printf("%d\n", array[i]);
    }

    printf("%d\n", bubbleSort(num, array));

    if (array != NULL) {
        delete [] array;
    }

    return 0;
}

void
trace(int num, int* array)
{
    for (int i = 0; i < num; i++) {
        if (i != 0) {
            printf(" ");
        }
        printf("%d", array[i]);
    }
    printf("\n");
}

int
bubbleSort(int num, int* array)
{
    int ret = 0, loopCount = 0;

    for (int j = 0; j < num; j++) {
        for (int i = num-1; i > 0; i--) {
            if (array[i] < array[i-1]) {
                int tmp = array[i];
                array[i] = array[i-1];
                array[i-1] = tmp;
                ret++;
            }
        }
    }
    /*
    for (int i = 0; i < num; i++) {
        printf("%d\n", array[i]);
    }
    */
    trace(num, array);

    return ret;
}


#include <bits/stdc++.h>
using namespace std;
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0583

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

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

int main(){
    int n;
    int a,b,c;
    cin >> n;
    vector<int> ret;
    if (n==2){
        cin >> b >> c;
        int a = gcd<int>(b,c);
        ret = divisor<int>(a);
    }else if (n==3){
        cin >> a >> b >> c;
        int k = gcd<int>(a,gcd<int>(b,c));
        ret = divisor<int>(k);
    }
    for(const int &p :ret){
        printf("%d\n",p);
    }

}

#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int stage[12][12] = {{0}};
    int n;
    int j = 0;
    int x = 0,y = 0,xx = 0;
    for(;;){
        cin >> n;
        if(n == 0)break;
        for(int i = 0;i < n; i++){
            for(j = 0;j < n; j++){
                cin >> stage[i][j];
                x += stage[i][j];
                if(j == n-1){
                    stage[i][n] = x;
                    xx += stage[i][n];
                    x = 0;
                }
            }
        }
        for(int i = 0;i < n; i++){
            for(j = 0;j < n; j++){
                y += stage[j][i];
                if(j == n-1){
                    stage[n][i] = y;
                    y = 0;
                }
            }
        }
        stage[n][n] = xx;
        for(int i = 0;i <= n; i++){
            for(int j = 0;j <= n; j++){
                printf("%5d",stage[i][j]);
            }
            printf("\n");
        }
        x = 0,y = 0,xx = 0;
    }
    return 0;
}