#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

void abc_160a();

void abc_161a();

void abc_162a();

void abc_163a();

void abc_164a();

void abc_165a();

void abc_166a();

void abc_167a();

void abc_168a();

void abc_169();

int main()
{
  //abc_160a();
  //abc_161a();
  //abc_162a();
  //abc_163a();
  //abc_164a();
  //abc_165a();
  //abc_166a();
  //abc_167a();
  //abc_168a();
  abc_169();

}

void abc_160a()
{
  string S;
  cin >> S;

  if (S[2] == S[3] && S[4] == S[5]) cout << "Yes\n";
  else cout << "No\n";
}

void swap(int& a, int& b)
{
  int tmp;
  tmp = a;
  a = b;
  b = tmp;
}

void abc_161a()
{
  int x, y, z;
  cin >> x >> y >> z;

  swap(x, y);
  swap(x, z);

  cout << x << " " << y << " " << z << "\n";
}

void abc_162a()
{
  string s;
  cin >> s;
  for (char c : s)
  {
    if (c == '7')
    {
      cout << "Yes\n";
      return;
    }
  }

  cout << "No\n";
}

void abc_163a()
{
  int R;
  cin >> R;

  cout << (double)(2 * R * M_PI);
}

void abc_164a()
{
  int s, w;
  cin >> s >> w;

  if (s <= w) cout << "unsafe\n";
  else cout << "safe\n";
}

void abc_165a()
{
  int k, a, b;
  cin >> k >> a >> b;

  for (int i = a; i <= b; ++i)
  {
    if (i % k == 0)
    {
      cout << "OK\n";
      return;
    }
  }

  cout << "NG\n";
}

void abc_166a()
{
  string s;
  cin >> s;

  if (s == "ABC") cout << "ARC\n";
  if (s == "ARC") cout << "ABC\n";

}

void abc_167a()
{
  string s, t;
  cin >> s >> t;

  for (int i = 0; i < s.size(); ++i)
  {
    if (s[i] != t[i])
    {
      cout << "No\n";
      return;
    }
  }

  if ('a' <= t[t.size() - 1] && t[t.size() - 1] <= 'z') cout << "Yes\n";
  else cout << "No\n";

}

void abc_168a()
{
  string s;
  cin >> s;

  if (s[s.size() - 1] == '3') cout << "bon\n";
  else if (s[s.size() - 1] == '0' ||
    s[s.size() - 1] == '1' ||
    s[s.size() - 1] == '6' ||
    s[s.size() - 1] == '8') cout << "pon\n";
  else cout << "hon\n";
}

void abc_169()
{
  int a, b;
  cin >> a >> b;
  cout << a * b << "\n";
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define pb push_back
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v) cerr << #v << ":"; rep(i, v.size()) cerr << " " << v[i]; cerr << 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; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    int a, b;
    cin >> a >> b;
    cout << a * b << endl;
}

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


//Author:xht37
#include <bits/stdc++.h>

#define ui unsigned int
#define ll long long
#define ul unsigned ll
#define ld long double

#define pi pair <int, int>
#define fi first
#define se second
#define mp make_pair

#define ls (p << 1)
#define rs (ls | 1)
#define md ((t[p].l + t[p].r) >> 1)

#define vi vector <int>
#define pb push_back
#define pq priority_queue

#define dbg(x) cerr << #x" = " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)

#define fl(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)

using namespace std;

namespace io {
	const int SI = 1 << 21 | 1;
	char IB[SI], *IS, *IT, OB[SI], *OS = OB, *OT = OS + SI - 1, c, ch[100];
	int f, t;
	#define gc() (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin), IS == IT ? EOF : *IS++) : *IS++)
	inline void flush() {
		fwrite(OB, 1, OS - OB, stdout), OS = OB;
	}
	inline void pc(char x) {
		*OS++ = x;
		if (OS == OT) flush();
	}

	template <class I>
	inline void rd(I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + (c & 15), c = gc());
		x *= f;
	}
	template <class I>
	inline void rd(I &x, I &y) {
		rd(x), rd(y);
	}
	template <class I>
	inline void rd(I &x, I &y, I &z) {
		rd(x), rd(y), rd(z);
	}
	template <class I>
	inline void rda(I *a, int n) {
		for (int i = 1; i <= n; i++) rd(a[i]);
	}
	inline void rdc(char &c) {
		for (c = gc(); c < 33 || c > 126; c = gc());
	}
	inline void rds(char *s, int &n) {
		for (c = gc(); c < 33 || c > 126; c = gc());
		for (n = 0; c >= 33 && c <= 126; s[++n] = c, c = gc());
		s[n+1] = '\0';
	}
	inline void rds(string &s) {
		for (c = gc(); c < 33 || c > 126; c = gc());
		for (s.clear(); c >= 33 && c <= 126; s.pb(c), c = gc());
	}

	template <class I>
	inline void print(I x, char k = '\n') {
		if (!x) pc('0');
		if (x < 0) pc('-'), x = -x;
		while (x) ch[++t] = x % 10 + '0', x /= 10;
		while (t) pc(ch[t--]);
		pc(k);
	}
	template <class I>
	inline void print(I x, I y) {
		print(x, ' '), print(y);
	}
	template <class I>
	inline void print(I x, I y, I z) {
		print(x, ' '), print(y, ' '), print(z);
	}
	template <class I>
	inline void printa(I *a, int n) {
		for (int i = 1; i <= n; i++) print(a[i], " \n"[i==n]);
	}
	inline void printc(char c) {
		pc(c);
	}
	inline void prints(char *s, int n) {
		for (int i = 1; i <= n; i++) pc(s[i]);
		pc('\n');
	}
	inline void prints(string s) {
		int n = s.length();
		while (t < n) pc(s[t++]);
		pc('\n'), t = 0;
	}
	struct Flush {
		~Flush() {
			flush();
		}
	} flusher;
}
using io::rd;
using io::rda;
using io::rdc;
using io::rds;
using io::print;
using io::printa;
using io::printc;
using io::prints;

const int N = 1e5 + 7;
int n, x, p[N];
ll b[N], l[N], r[N], s[N], sum;

inline ll calc(int x, ll t) {
	return t <= b[x] ? t * l[x] : b[x] * l[x] + (t - b[x]) * r[x];
}

inline ll pd(ll t) {
	int w = t % x ? t % x : x, c = (t - w) / x;
	ll sum = 0, ret = 0;
	for (int i = 1; i <= c; i++) sum += s[p[i]];
	for (int i = c + 1; i <= n; i++)
		ret = max(ret, sum + calc(p[i], w));
	sum += s[p[c+1]];
	for (int i = 1; i <= c; i++)
		ret = max(ret, sum - s[p[i]] + calc(p[i], w));
	return ret;
}

int main() {
	rd(n, x);
	for (int i = 1; i <= n; i++)
		rd(b[i], l[i], r[i]), p[i] = i,
		s[i] = b[i] * l[i] + (x - b[i]) * r[i], sum += b[i] * l[i];
	sort(p + 1, p + n + 1, [&](int i, int j) { return s[i] > s[j]; });
	if (!sum) return print(0), 0;
	ll l = 1, r = 1ll * n * x;
	while (l < r) {
		ll mid = (l + r) >> 1;
		if (pd(mid) >= sum) r = mid;
		else l = mid + 1;
	}
	print(l);
	return 0;
}

#include <bits/stdc++.h>

#define PI 3.14159265358979323846264338327950288419

using namespace std;

int n, maxi;
int aoki[100005], lo[100005], up[100005];
long long score[100005];
bool higher[100005];

long long require;
long long ans, ans1, ans2;

vector<pair<long long, int> > chase;

int main(){
	scanf("%d %d", &n, &maxi);
	for(int i = 1; i <= n; i++){
		scanf("%d %d %d", &aoki[i], &lo[i], &up[i]);
		require += 1LL * aoki[i] * lo[i];
		score[i] = 1LL * aoki[i] * lo[i] + 1LL * (maxi - aoki[i]) * up[i];
		chase.push_back({-score[i], i});
	}
	sort(chase.begin(), chase.end());
	for(auto choice: chase){
		long long delta = choice.first;
		int id = choice.second;
		if(require + delta <= 0){
			// two scenarios
			// scenario 1: pick all "higher", one partial from "lower" ones
			int opt = maxi;
			for(int i = 1; i <= n; i++){
				if(!higher[i]){
					// see if it can make up the difference of delta
					if(score[i] < require){
						continue;
					}else if(1LL * aoki[i] * lo[i] >= require){
						opt = min(opt, (int)ceil((require + .0) / lo[i]));
					}else{
						opt = min(opt, aoki[i] + (int)ceil((require - 1.0 * aoki[i] * lo[i]) / up[i]));
					}
				}
			}
			ans1 = ans + opt;
			// scenario 2: pick all "higher" and this, then make one "higher" partial
			higher[id] = true;
			require += delta;
			opt = maxi;
			for(int i = 1; i <= n; i++){
				if(higher[i]){
					long long target = require + score[i]; // should be positive
					if(1LL * aoki[i] * lo[i] >= target){
						opt = min(opt, (int)ceil((target + .0) / lo[i]));
					}else{
						opt = min(opt, aoki[i] + (int)ceil((target - 1.0 * aoki[i] * lo[i]) / up[i]));
					}
				}
			}
			ans2 = ans + opt;
			printf("%lld\n", min(ans1, ans2));
			return 0;
		}
		higher[id] = true;
		require += delta;
		ans += maxi;
	}
	return 0;
}


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

template <typename Tp> inline void getint(Tp &num){
	register int ch, neg = 0;
	while(!isdigit(ch = getchar())) if(ch == '-') neg = 1;
	num = ch & 15;
	while(isdigit(ch = getchar())) num = num * 10 + (ch & 15);
	if(neg) num = -num;
}

int N, K;

int main(){
	getint(N), getint(K);
	return printf("%d\n", N - K + 1), 0;
}

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

void solve(long long N, long long K) {
cout<<N-K+1;}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  long long N;
  scanf("%lld", &N);
  long long K;
  scanf("%lld", &K);
  solve(N, K);
  return 0;
}


#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll mod=1e9+7;
const int inf=1<<30;

vector<vector<int> > to;
int color[100010];
bool isbi=true;
void dfs(int v,int c=0){
  color[v]=c;
  rep(i,to[v].size()){
    int nv=to[v][i];
    if(color[nv]==-1) dfs(nv,1-c);
    else if(color[nv]==1-c) continue;
    else isbi=false;
  }
}

int main(){
  ll N,M;
  cin >> N >> M;
  to.resize(N);
  rep(i,N) color[i]=-1;
  rep(i,M){
    int a,b;
    cin >> a >> b;
    a--; b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  dfs(0);
  ll ans;
  if(isbi){
    ll b=0,w=0;
    rep(i,N){
      if(color[i]==0) b++;
      else w++;
    }
    ans=b*w-M;
  }
  else{
    ans=N*(N-1)/2-M;
  }
  cout << ans << endl;
}

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

int main(){
    int tt,ts,h,t,o,a,b,tmp,count=0;
    cin>>a>>b;
    for(int i=a;i<=b;i++){
        tmp=i;
        tt=tmp/10000;
        tmp-=tt*10000;
        ts=tmp/1000;
        tmp-=ts*1000;
        h=tmp/100;
        tmp-=h*100;
        t=tmp/10;
        tmp-=t*10;
        o=tmp;
        if((tt==o)&&(ts==t))count++;
    }
    cout<<count<<endl;
    return 0;
}


#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>
#include <functional>
#include <chrono>
#include <stack>

using namespace std;

#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double

ostream& operator<< (ostream &out, const vector<int> &b) {
    for (auto k : b) out << k << " ";
    return out;
}

istream& operator>> (istream& in, pii& b) {
    in >> b.first >> b.second;
    return in;
}

ostream& operator<< (ostream& out, const pii& b) {
    out << "{" << b.first << ", " << b.second << "}";
    return out;
}

template <typename T1, typename T2> inline bool chkmin(T1 &x, const T2 &y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T1, typename T2> inline bool chkmax(T1 &x, const T2 &y) {if (x < y) {x = y; return 1;} return 0;}

#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << (x) << "\n";
    const int INF = 1e18;
    // const int mod = 2600000069;
    // const int p = 10;
#else
    #define dbg(x) 57
    const int INF = 1e18;
    // const int mod = 2600000069;
    // const int p = 179;
#endif

const ld PI = acos(-1);

#define time clock() / (double) CLOCKS_PER_SEC

// #pragma GCC optimize("Ofast,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,sse3,sse4")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC optimize("fast-math")
// #pragma GCC target("avx2")
// #pragma GCC optimize("section-anchors")
// #pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
// #pragma GCC optimize("vpt")
// #pragma GCC optimize("rename-registers")
// #pragma GCC optimize("move-loop-invariants")
// #pragma GCC optimize("unswitch-loops")
// #pragma GCC optimize("function-sections")
// #pragma GCC optimize("data-sections")

mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());

const int MAXN = 2e5 + 10;
const int K = 20;

int n, l, q;
int a[MAXN], up[MAXN][K];

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    cin >> l >> q;
    int ptr = 0;
    for (int i = 0; i < n; i++) {
        while (ptr < n - 1 && a[ptr + 1] - a[i] <= l) {
            ptr++;
        }
        up[i][0] = ptr;
    }
    for (int i = n - 1; i >= 0; i--) {
        for (int j = 1; j < K; j++) {
            up[i][j] = up[up[i][j - 1]][j - 1];
        }
    }
    for (int i = 0; i < q; i++) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        if (x > y) swap(x, y);
        int ans = 0;
        for (int i = K - 1; i >= 0; i--) {
            if (up[x][i] < y) {
                ans += (1 << i);
                x = up[x][i];
            }
        }
        cout << ans + 1 << "\n";
    }
}
/*

*/

#include <bits/stdc++.h>

using namespace std;

int A[100050];
int n,l,q;
int dp[100050][20];
int main(){
	//freopen("input.in","r",stdin);
	cin >> n;
	for(int i=1; i<=n; ++i) cin >> A[i];
	cin >> l;
	for(int i=1; i<=n; ++i) dp[i][0] = upper_bound(A+1,A+n+1,A[i]+l)-A-1;
	for(int k=1; k<=18; ++k){
		for(int i=1; i<=n; ++i){
			dp[i][k] = dp[dp[i][k-1]][k-1];
		}
	}
//	for(int k=0; k<=3; ++k){ for(int i=1; i<=n; ++i) printf("%d ", dp[i][k]); printf("\n"); }
	cin >> q;
	while(q--){
		int a, b; cin >> a >> b;
		if(a > b) swap(a,b);
		int ans = 0;
		while(a < b){
			int s=0,e=19,m;
			for(int k=0; k<=18; ++k) if(dp[a][k] < b) s=k;
			ans += (1<<s);
			a = dp[a][s];
		}
		cout << ans << "\n";
	}
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    char a,b,c;
    cin>>a>>b>>c;
    int ans = 0;
    if(a=='R'&&b=='R'&&c=='R')
        ans = 3;
    else if((a=='R' && b=='R')|| (b=='R'&&c=='R'))
        ans= 2;
    else if(a=='R'||b=='R'||c=='R')
        ans =1;
    cout<<ans;
    return 0;
}

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

using namespace std;

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

}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MOD=1e9+7;
const long double Pi=acos(-1);
using  P=pair<ll,ll>;
int main(){
  ll counte=0,countw=0;
  string str;
  cin>>str>>str;
  vector<ll> w((ll)str.size());
  vector<ll> e((ll)str.size());
  for(ll i=0;i<(ll)str.size();i++){
    if(i==0){
      if(str.at(i)=='E'){e.at(i)=1;w.at(i)=0;counte++;}
      else{e.at(i)=0;w.at(i)=1;countw++;}
    }
    else{
      if(str.at(i)=='E'){e.at(i)=e.at(i-1)+1;w.at(i)=w.at(i-1);counte++;}
      else{e.at(i)=e.at(i-1);w.at(i)=w.at(i-1)+1;countw++;}
    }
  }
  ll ans;
  for(ll i=0;i<(ll)str.size();i++){
    if(i==0){ans=counte-e.at(0);}
    else if(i==(ll)str.size()-1){ans=min(ans,w.at(i));}
    else{ans=min(ans,w.at(i-1)+counte-e.at(i));}
  }
  cout<<ans<<endl;
}

#include <bits/stdc++.h>
#define rep(i , n) for (int i = 0; i < (int)(n); i++)
const int INF = 1<<29;
using namespace std;
using ll = long long;
int main(){
    int N , sum = 0;
    string S;
    cin >> N >> S;
    for(int i = 0; i < N; i++){
        if(S[i] == 'E'){
            sum++;
        }
    }
    int t = sum;
    for(int i = 0; i < N; i++){
        if(S[i] == 'E'){
            sum--;
        }
        if(S[i] == 'W'){
            sum++;
        }
        t = min(t , sum);
    }
    cout << t << endl;
}


#include<iostream>
#include<vector>

using namespace std;

int foot(int);

int main() {

	int n;
	vector<int>floor;

	cin >> n;
	while (n != 0) {
		floor.push_back(n);
		cin >> n;
	}
	floor.push_back(0);

	int i = 0;
	while (floor[i] != 0) {

		int res = 0;
		res = foot(floor[i]) / 3650;
		if( foot(floor[i]) % 3650 != 0) res++;

		cout << res << endl;
		i++;
	}

	cin >> n;

	return 0;
}

int foot(int n) {

	if (n == 1)return 1;
	if (n == 2)return 2;
	if (n == 3)return 4;
	if (n < 1)return 0;

	return foot(n - 1) + foot(n - 2) + foot(n - 3);

}


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

using namespace std;
using namespace __gnu_pbds;

#define lint                     long long
#define setbits(x)              __builtin_popcountll(x)
#define zrbits(x)               __builtin_ctzll(x)
#define zlbits(x)               __builtin_clzll(x)
#define parsbits(x)             __builtin_parityll(x)
#define mem(a, b)               memset(a, (b), sizeof(a))
#define MOD                     1000000007
#define inf                     1e17
#define neginf                  -1e17
#define sp(x,y)                 fixed<<setprecision(x)<<y
#define testcase(t)             lint t; cin>>t; while(t--)
#define power(a,b)              (double)pow((double)a,(double)b)
#define FOR(i,n)                for(lint i=0;i<n;i++)
#define gcd(a,b)                __gcd(a,b)
#define PI                      3.1415926535
#define pb                      push_back
#define ss                      second
#define ff                      first
#define umap                    unordered_map
#define ummap                   unordered_multimap
#define uset                    unordered_set
#define umset                   unordered_multiset

typedef unsigned long long   ull;

typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;

void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  //  #ifndef ONLINE_JUDGE
    //freopen("C:\\Users\\pranjal bhatt\\Desktop\\code contests\\input1.txt", "r", stdin);
   /// freopen("C:\\Users\\pranjal bhatt\\Desktop\\code contests\\output1.txt", "w", stdout);
   // #endif
}

lint me(lint x, lint y, lint p)
{
    lint res = 1;

    x = x % p;

    if (x == 0) return 0;

    while (y > 0)
    {

        if (y & 1)
        res = (res*x) % p;

        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

    /*---------------------------SOLUTION---------------------------------*/

void solve()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    lint n,k;
    cin>>n>>k;
    lint arr[10]={0};
    for(lint i=0;i<k;i++)
    {
        lint u;
        cin>>u;
        arr[u]=1;
    }
    for(lint i=n;i<=100000;i++)
    {
        lint x=i;
        lint flg=0;
        while(x>0)
        {
            lint p=x%10;
            x=x/10;
            if(arr[p]==1)
                flg=1;
        }
        if(flg==0)
        {
            cout<<i<<endl;
            return;
        }
    }

}

int main()
{
    c_p_c();
    lint flg99=0;
    if(flg99==1)
    {
        testcase(t)
        {
             solve();
        }
    }
    else
    {
        solve();
    }
    return 0;

}

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
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 (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

int main() {
    int n, m; cin >> n >> m;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<int> s(n+1);
    rep(i, n) s[i+1] = (s[i]%m+a[i]%m)%m;
    map<int, int> mp;
    ll ans = 0;
    rep(i, n+1) {
        int num = s[i];
        int rem = num%m;
        ans += mp[rem];
        mp[rem]++;
        debug(i, num, rem, ans);
    }
    cout << ans << endl;
    // int db = 0;
    // rep(i, n) FOR(j, i, n) {
    //     ll tot = 0;
    //     FOR(k, i, j+1) tot += a[k];
    //     if (tot%m==0) {
    //         debug(i, j, tot);
    //         db++;
    //     }
    // }
    // debug(db);
}


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

class Dice{
public:
	long top, front, right, left, back, bottom;
	Dice(long top, long front, long right, long left, long back, long bottom);
	void north();
	void south();
	void west();
	void east();
	void rightTurn();
	void ChangeTop(long top);
};

Dice::Dice(long top, long front, long right, long left, long back, long bottom){
	this->top = top;
	this->front = front;
	this->right = right;
	this->left = left;
	this->back = back;
	this->bottom = bottom;
}

void Dice::north(){
	long sv[6];
	sv[0] = this->front;
	sv[1] = this->bottom;
	sv[2] = this->right;
	sv[3] = this->left;
	sv[4] = this->top;
	sv[5] = this->back;

	this->top = sv[0];
	this->front = sv[1];
	this->right = sv[2];
	this->left = sv[3];
	this->back = sv[4];
	this->bottom = sv[5];
}

void Dice::south(){
	long sv[6];
	sv[0] = this->back;
	sv[1] = this->top;
	sv[2] = this->right;
	sv[3] = this->left;
	sv[4] = this->bottom;
	sv[5] = this->front;

	this->top = sv[0];
	this->front = sv[1];
	this->right = sv[2];
	this->left = sv[3];
	this->back = sv[4];
	this->bottom = sv[5];
}

void Dice::west(){
	long sv[6];
	sv[0] = this->right;
	sv[1] = this->front;
	sv[2] = this->bottom;
	sv[3] = this->top;
	sv[4] = this->back;
	sv[5] = this->left;

	this->top = sv[0];
	this->front = sv[1];
	this->right = sv[2];
	this->left = sv[3];
	this->back = sv[4];
	this->bottom = sv[5];
}

void Dice::east(){
	long sv[6];
	sv[0] = this->left;
	sv[1] = this->front;
	sv[2] = this->top;
	sv[3] = this->bottom;
	sv[4] = this->back;
	sv[5] = this->right;

	this->top = sv[0];
	this->front = sv[1];
	this->right = sv[2];
	this->left = sv[3];
	this->back = sv[4];
	this->bottom = sv[5];
}

void Dice::rightTurn(){
	long vs[4];
	vs[0] = this->left;
	vs[1] = this->right;
	vs[2] = this->front;
	vs[3] = this->back;
	this->left = vs[2];
	this->right = vs[3];
	this->front = vs[1];
	this->back = vs[0];
}

void Dice::ChangeTop(long top){
	if (top == this->top) return;
	else if (top == this->back) Dice::south();
	else if (top == this->front) Dice::north();
	else if (top == this->left) Dice::east();
	else if (top == this->right) Dice::west();
	else for (long i = 0; i < 2; i++) Dice::north();
	return;
}

int main(){
	bool judge = 1;
	long n;
	cin >> n;
	//n = 4;
	vector< vector<long> > roll(n);
	for (long i = 0; i < n; i++){
		roll[i].resize(6);
		cin >> roll[i][0] >> roll[i][1] >> roll[i][2] >> roll[i][3] >> roll[i][4] >> roll[i][5];
	}
	/*
	roll[0][0] = 1;
	roll[0][1] = 2;
	roll[0][2] = 3;
	roll[0][3] = 4;
	roll[0][4] = 5;
	roll[0][5] = 6;
	roll[1][0] = 1;
	roll[1][1] = 2;
	roll[1][2] = 3;
	roll[1][3] = 4;
	roll[1][4] = 5;
	roll[1][5] = 7;
	roll[2][0] = 6;
	roll[2][1] = 2;
	roll[2][2] = 3;
	roll[2][3] = 4;
	roll[2][4] = 5;
	roll[2][5] = 1;
	roll[3][0] = 2;
	roll[3][1] = 4;
	roll[3][2] = 5;
	roll[3][3] = 6;
	roll[3][4] = 3;
	roll[3][5] = 1;
	*/
	for (long i = 0; i < n; i++){
		for (long j = i + 1; j < n; j++){
			long isum = 0, jsum = 0;
			for (long k = 0; k < 6; k++){
				isum += roll[i][k];
				jsum += roll[j][k];
			}
			//cout << isum << " " << jsum << endl;
			if (isum != jsum) continue;
			Dice *di, *dj;
			di = new Dice(roll[i][0], roll[i][1], roll[i][2], roll[i][3], roll[i][4], roll[i][5]);
			dj = new Dice(roll[j][0], roll[j][1], roll[j][2], roll[j][3], roll[j][4], roll[j][5]);
			di->ChangeTop(roll[0][0]);
			dj->ChangeTop(roll[0][0]);
			//cout << di->top << " " << dj->top << endl;
			for (long k = 0; k < 3; k++) if (di->front != dj->front) dj->rightTurn();
			//cout << di->front << " " << dj->front << endl;
			if (di->top == dj->top && di->front == dj->front && di->right == dj->right && di->left == dj->left && di->back == dj->back && di->bottom == dj->bottom){
				//cout << i << " " << j << endl;
				judge = 0;
				break;
			}
			delete di;
			delete dj;
		}
		if (judge == 0) break;
	}
	if (judge == 1) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

//#define _USE_MATH_DEFINES	//M_PI
#include <iostream>			//std::cout, std::cin
//#include <string>			//std::string
#include <vector>			//std::vector
//#include <valarray>			//std::valarray	??°????????????????¬???????
//#include <algorithm>		//std::sort
//#include <time.h>			//localtime_s
//#include <cstdlib>			//abs
//#include <cmath>			//abs, pow, sqrt, sin, cos,
//#include <fstream>			//std::ifstream
//#include <iomanip>			//std::setprecision
//#include <random>			//std::random(C++11)

int main(void) {

	//test??¨
	//std::ifstream in("test.txt");
	//std::cin.rdbuf(in.rdbuf());

	//??\???
	int n;
	std::cin >> n;
	std::vector<std::vector<int>> dice(n, std::vector<int>(6));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 6; j++) {
			std::cin >> dice[i][j];
		}
	}

	//??????
	bool flg = true;
	std::vector<int> dice1(6), dice2(6), temp1(6);
	for (int i = 0; i < n - 1; i++) {
		dice1 = dice[i];
		for (int j = i + 1; j < n; j++) {
			dice2 = dice[j];

			for (int x = 0; x < 4; x++) {
				for (int y = 0; y < 4; y++) {
					for (int z = 0; z < 4; z++) {
						if (std::equal(dice1.begin(), dice1.end(), dice2.begin())) {
							flg = 0;
							x = y = z = 4;
							i = j = n;
						}
						temp1[0] = dice1[3];
						temp1[1] = dice1[1];
						temp1[2] = dice1[0];
						temp1[3] = dice1[5];
						temp1[4] = dice1[4];
						temp1[5] = dice1[2];
						dice1 = temp1;
					}
					temp1[0] = dice1[1];
					temp1[1] = dice1[5];
					temp1[2] = dice1[2];
					temp1[3] = dice1[3];
					temp1[4] = dice1[0];
					temp1[5] = dice1[4];
					dice1 = temp1;
				}
				temp1[0] = dice1[0];
				temp1[1] = dice1[3];
				temp1[2] = dice1[1];
				temp1[3] = dice1[4];
				temp1[4] = dice1[2];
				temp1[5] = dice1[5];
				dice1 = temp1;
			}

		}
	}

	if (flg) {
		std::cout << "Yes" << std::endl;
	}
	else {
		std::cout << "No" << std::endl;
	}

}


#include<bits/stdc++.h>
#define ld double
#define ull unsigned long long
#define ll long long
#define pii pair<int,int >
#define iiii pair<int,pii >
#define mp make_pair
#define INF 1000000000
#define MOD 1000000007
#define rep(i,x) for(int (i)=0;(i)<(x);(i)++)
inline int getint(){
    int x=0,p=1;char c=getchar();
    while (c<=32)c=getchar();
    if(c==45)p=-p,c=getchar();
    while (c>32)x=x*10+c-48,c=getchar();
    return x*p;
}
using namespace std;
//ruogu_alter
const int N=605;
int dx[]={1,-1,-1,1};
int dy[]={-1,1,-1,1};
int n,cnt[2][2];
int col[N][N][2];
vector<pii >g[N][N];
bool vis[N][N];
//
inline bool isvalid(int x,int y){
	if(x<0||x>=2*n||y<0||y>=2*n)return false;
	return true;
}
void go(int x,int y,int z,int c){
	col[x][y][z]=c;
	vis[x][y]=true;
	rep(i,g[x][y].size()){
		pii u=g[x][y][i];
		if(!vis[u.first][u.second]){
			go(u.first,u.second,z,c^1);
		}
	}
}
void solve(int d,int x){
	rep(i,2*n)rep(j,2*n)g[i][j].clear();
	rep(i,2*n)if(i*i<=d){
		int j=sqrt(d-i*i);
		if(j*j+i*i!=d)continue;
		rep(x,2*n)rep(y,2*n)rep(k,4){
			int fx=x+i*dx[k],fy=y+j*dy[k];
			if(!isvalid(fx,fy))continue;
			g[x][y].push_back(mp(fx,fy));
		}
	}
	rep(i,2*n)rep(j,2*n)vis[i][j]=false;
	rep(i,2*n)rep(j,2*n)if(!vis[i][j]){
		go(i,j,x,0);
	}
}
int main(){
	n=getint();
	rep(i,2){
		int x=getint();
		solve(x,i);
	}
	rep(i,2*n)rep(j,2*n)cnt[col[i][j][0]][col[i][j][1]]++;
	rep(i,2)rep(j,2)if(cnt[i][j]>=n*n){
		int c=0;
		rep(x,2*n)rep(y,2*n){
			if(col[x][y][0]==i&&col[x][y][1]==j){
				printf("%d %d\n",x,y);
				++c;
			}
			if(c==n*n)return 0;
		}
		return 0;
	}
	return 0;
}

#include <iostream>
#include <map>
#include <cmath>
using namespace std;

int main() {
  int n; cin >> n;
  map<pair<int, int>, int> mp;
  long long ans = 0;
  for(int i = 0; i < n; i++) {
    double num; cin >> num;
    long long x = llround(num*1e9);

    int two = 0, five = 0;
    while(x % 2 == 0) two++, x /= 2;
    while(x % 5 == 0) five++, x /= 5;
    for(auto p: mp) {
      if(p.first.first+two >= 18 && p.first.second+five >= 18) ans += p.second;
    }
    mp[make_pair(two, five)]++;
  }
  cout << ans << endl;
  return 0;
}


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

const int kMaxFace = 6;

void PushWheel(int (&array)[kMaxFace], int a, int b, int c, int d)
{
    int temp = array[a];
    array[a] = array[b];
    array[b] = array[c];
    array[c] = array[d];
    array[d] = temp;
}

class Dice
{
public:
    Dice(const int (&inputArr)[kMaxFace]);
    void Write();

    void Rotation(const char dir);
    int Get();

private:
    enum EFace{UP, SOUTH, EAST, WEST, NORTH, BOTTOM};

    Dice(){}
    int faces[kMaxFace];    // up,S,E,W,N,bottom.
};

Dice::Dice(const int (&inputArr)[kMaxFace])
{
    for (int i=0; i<kMaxFace; ++i)
    {
        faces[i] = inputArr[i];
    }
}

void Dice::Rotation(const char dir)
{
    switch(dir)
    {
        // 5, 1, 3, 4, 6, 2.
        case 'S': PushWheel(faces, UP, NORTH, BOTTOM, SOUTH);   break;
        case 'E': PushWheel(faces, UP, WEST, BOTTOM, EAST); break;
        case 'W': PushWheel(faces, UP, EAST, BOTTOM, WEST); break;
        case 'N': PushWheel(faces, UP, SOUTH, BOTTOM, NORTH); break;
        default:      break;
    }
}

int Dice::Get()
{
    return faces[UP];
}

int main()
{
    int faces[kMaxFace] = {0};
    for (int i=0; i<kMaxFace; ++i)
    {
        cin >> faces[i];
    }

    Dice dice(faces);

    string str;
    cin >> str;
    for (int i=0; i<str.length(); ++i)
    {
        dice.Rotation(str[i]);
    }

    cout << dice.Get() << endl;

    return 0;
}

#include <iostream>
#include <string>

using namespace std;

int main(void)
{
	string str;
	string::size_type index;
	int num;
	int number;
	int i,j;

	cin >> num;
	getline(cin,str);//ツ催渉可づ個づ「ツづつつセツつッツ禿づ敖債楪づ慊つケ
	for(i=0;i<num;i++)
	{
		getline(cin,str);
		number = 0;
		while((index = str.find("Hoshino") ) != string::npos)
		{
			str.replace(index,7,"Hoshina");
		}
		cout << str << endl;
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <unordered_map>

using namespace std;
using Map = unordered_map<string, long>;

size_t n;

void dfs(string src, Map &m, size_t i=0, string s="", string t="") {
    if (i == n){
        m[s + ' ' + t]++;
    } else {
        dfs(src, m, i+1, s+src[i], t);
        dfs(src, m, i+1, s, t+src[i]);
    }
}

int main() {
    string src;
    Map m1, m2;
    cin >> n >> src;
    string left  = src.substr(0, n),
           right = src.substr(n);
    reverse(right.begin(), right.end());
    dfs(left, m1);
    dfs(right, m2);
    long cnt = 0;
    for (auto mp:m1)
        cnt += mp.second * m2[mp.first];
    cout << cnt << '\n';
    return 0;
}

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#include<assert.h>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
#define SZ(x) ((int)x.size())
using namespace std;
inline LL read()
{
	LL f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
template<typename T>inline void chkmin(T &x,T y){x=x<y?x:y;}
template<typename T>inline void chkmax(T &x,T y){x=x>y?x:y;}
#define ull unsigned long long
const int MAXN=20;
const int base=233;
char ch[2*MAXN];
int bin[MAXN];
map<ull,int> mp;
int main()
{
//	freopen("a.in","r",stdin);
	bin[1]=1;for(int i=2;i<MAXN;i++)bin[i]=bin[i-1]<<1;
	int n=read();scanf("%s",ch+1);
	for(int i=0;i<bin[n+1];i++)
	{
		ull sum=0;
		for(int j=1;j<=n;j++)if(i&bin[j])
			sum=(sum*base+ch[j]-'a'+1);
		sum=(sum*base+79);
		for(int j=1;j<=n;j++)if(!(i&bin[j]))
			sum=(sum*base+ch[j]-'a'+1);
		++mp[sum];
	}LL ans=0;
	for(int i=0;i<bin[n+1];i++)
	{
		ull sum=0;
		for(int j=1;j<=n;j++)if(i&bin[j])
			sum=(sum*base+ch[2*n-j+1]-'a'+1);
		sum=(sum*base+79);
		for(int j=1;j<=n;j++)if(!(i&bin[j]))
			sum=(sum*base+ch[2*n-j+1]-'a'+1);
		ans+=mp[sum];
	}pr2(ans);
	return 0;
}


#include <iostream>

using namespace std;

int main()
{
	int result = 0;

	int numberOfPerson, turnOffDelay;
	cin >> numberOfPerson >> turnOffDelay;

	int lastSwitch = 0;
	for (int i = 0; i < numberOfPerson; i++) {
		int time;
		cin >> time;
		int delta = time - lastSwitch;
		result += delta < turnOffDelay ? delta : turnOffDelay;
		lastSwitch = time;
	}
	result += turnOffDelay;

	cout << result << endl;
	return 0;
}

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp>
//#include <functional> // for less
#define PI acos(-1.0)
#define eps 1e-9
#define ll long long
#define ull unsigned long long
#define nl printf("\n")
#define sf scanf
#define pf printf
#define INF (ll)1e15
#define mod 1000000007

///#define isValid(n,m,nx,ny)nx>=0&&nx<n&&ny>=0&&ny<m
///int kx[]={1, 1, -1, -1, 2, 2, -2, -2}; //knight moves
///int ky[]={2,-2,  2, -2, 1,-1,  1, -1}; //knight moves
///int dx[]={1,-1,0,0,1,-1,1,-1};//eight direction
///int dy[]={0,0,1,-1,1,-1,-1,1};//eight direction

///using namespace __gnu_pbds;
using namespace std;

///inline double toRad(double deg){return deg*PI/180;}
///inline double toDeg(double rad){return rad*180/PI;}
///typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;

const int S=123456;
int main()
{
    #ifndef ONLINE_JUDGE
    //freopen("input.txt","r",stdin);
    #endif
    int n,t;
    while(sf("%d %d",&n,&t)==2)
    {
        int ara[n+5];
        for(int i=0;i<n;i++)
        {
            sf("%d",&ara[i]);
        }

        ll ans=0,cur=0,pre=0;
        for(int i=1;i<n;i++)
        {
            if(ara[i-1]+t>=ara[i])
            {
                cur=ara[i];
            }
            else
            {
                cur+=t;
                ans+=cur-pre;
                pre=ara[i];
                cur=ara[i];
            }
        }
        cur+=t;
        ans+=cur-pre;
        pf("%lld\n",ans);
    }
    return 0;
}


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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

const int INF = 1000100100;

int main()
{
    int n; cin >> n;
    int m; cin >> m;
    int s[m], c[m];
    rep(i,m) cin >> s[i] >> c[i];

    int rn, sn;
    if(n == 1) rn = 10, sn = 0;
    else if(n == 2) rn = 100, sn=10;
    else rn = 1000,sn=100;

    int res = INF;
    for(int i=sn; i<rn; i++){
        int cnt = 0;
        rep(j,m){
            int sj = n-s[j]+1;
            int num;
            if(sj == 1){
                num = i%10;
                if(c[j] == num) cnt++;
            }else if(sj ==2){
                num = i / 10;
                num %= 10;
                if(c[j] == num) cnt++;
            }else{
                num = i/100;
                if(c[j] == num) cnt++;
            }
        }
        if(cnt == m) res = min(i, res);
    }

    if(res == INF) cout << -1 << endl;
    else cout << res << endl;
}

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define prt(v) cout<<v<<"\n";
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
#define endl "\n"
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;

vector<vector<ll>> G(100007, vector<ll>(0));

void dfs(ll x,vl &d,ll dist){
    d[x]=dist;
    for(auto p: G[x]){
        if(d[p]==INF)dfs(p,d,dist+1);
    }
}

signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll u;
    cin >> u;u--;
    ll v;
    cin >> v;v--;
    vector<ll> A(N-1,0);
    vector<ll> B(N-1,0);
    for(ll i=0;i<N-1;++i){
        cin>>A[i]>>B[i];
        A[i]--;B[i]--;
        G[A[i]].emplace_back(B[i]);
        G[B[i]].emplace_back(A[i]);
    }
    vector<ll> du(N,INF);
    vector<ll> dv(N,INF);
    dfs(u,du,0);
    dfs(v,dv,0);
    ll mark;
    ll ou=-INF;
    for(ll i=0;i<N;++i){
        if(du[i]<dv[i]&&chmax(ou,dv[i]))mark=i;
    }
    ll nige=du[mark];
    ll ans=nige;
    ll S=ou-nige;//Sは1以上
    if(S==1)ans+=0;
    else if(S==2)ans++;
    else {
        ans+=((S-2)/2)*2;
        S-=((S-2)/2)*2;
        if(S==3)ans+=2;
        else ans++;
    }
    prt(ans)

    return 0;
}


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

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

/*
** author:mahmoud magdy
*/
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define endl "\n"

inline int D()
{
    int m ;
    cin>>m;
    return m ;
}
inline ll lD()
{
    ll m ;
    cin>>m;
    return m ;
}
inline double dD()
{
    double m;
    cin>>m;
    return m;
}
void fast()
{
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}
int main()
{
    fast();
    string s[7]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
    string s1;
    cin>>s1;
    int day;
    for(int i=0;i<7;i++){
        if(s[i]==s1){
            day=i+1;
            break;
        }
    }
    cout<<7-(day-1)<<endl;
}


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

int main(){
  int k;
  string s;

  cin >> k >> s;

  int cnt=0;
  for(int i=0;i<s.length();i++){
    cnt++;
  }

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

return 0;
}

#include <bits/stdc++.h>

using namespace std;
using ll =long long;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> PII;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
using P = pair<int,int>;
//Write From this Line

vector<int> sw(100010,0);
const int dx[] = {1,0,1,0};
const int dy[] = {1,1,0,0};
int main()
{
	int n;
	cin >> n;
	string s;
	cin >> s;

	rep(i,4){
		sw[0] = dx[i];
		sw[1] = dy[i];
		for(int j = 1; j < n -1; j++){
			if(sw[j]){
				// j匹目が羊の時、発言は真
				if(s[j]=='o'){
					sw[j+1] = sw[j-1];
				} else {
					sw[j+1] = 1 - sw[j-1];
				}
			} else {
				// j匹目が狼の時、発言は偽
				if(s[j] == 'o'){
					sw[j+1] = 1 - sw[j-1];
				} else {
					sw[j+1] = sw[j-1];
				}
			}
		}
		// n - 1 匹目の証言があっているかを確かめる。
		if(sw[0]){
			if(s[0] == 'o'){
				if(sw[1] == sw[n-1]){
					// OK
				} else {
					// NO
					continue;
				}
			} else {
				if(sw[1] != sw[n-1]){
				} else {
					// NO
					continue;
				}
			}
		} else {
			// n - 1 匹目狼
			if(s[0] == 'x'){
				if(sw[1] == sw[n-1]){
				} else {
					// NO
					continue;
				}
			} else {
				if(sw[1] != sw[n-1]){
				} else {
					// NO
					continue;
				}
			}
		}// n - 1 匹目の証言があっているかを確かめる。
		if(sw[n-1]){
			if(s[n-1] == 'o'){
				if(sw[0] == sw[n-2]){
					// OK
				} else {
					// NO
					continue;
				}
			} else {
				if(sw[0] != sw[n-2]){
				} else {
					// NO
					continue;
				}
			}
		} else {
			// n - 1 匹目狼
			if(s[n-1] == 'x'){
				if(sw[0] == sw[n-2]){
				} else {
					// NO
					continue;
				}
			} else {
				if(sw[0] != sw[n-2]){
				} else {
					// NO
					continue;
				}
			}
		}
		rep(j,n){
			if(sw[j]){
				cout << 'S';
			} else {
				cout << 'W';
			}
		} cout << endl;
		return 0;
	}
	cout << -1 << endl;
}


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

#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1

#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li n, m;
li a[111];

int main() {
    cin >> n >> m;
    li odd_cnt = 0;
    rep(i, m) {
        cin >> a[i];
        if (a[i] % 2 > 0) {
            odd_cnt++;
        }
    }

    if (odd_cnt > 2) {
        puts("Impossible");
        return 0;
    }

    vector<li> res;
    rep(i, m) {
        if (a[i] % 2 > 0 && i != 0) {
            swap(a[0], a[i]);
            break;
        }
    }
    rep(i, m - 1) {
        if (a[i] % 2 > 0 && i != 0) {
            swap(a[i], a[m - 1]);
            break;
        }
    }
    rep(i, m) {
        cout << a[i] << " ";
    } cout << endl;

    if (m == 1) {
        if (a[0] == 1) {
            cout << 1 << endl;
            cout << 1 << endl;
        } else {
            cout << 2 << endl;
            cout << a[0] - 1 << " " << 1 << endl;
        }
        return 0;
    }

    if (a[0] > 1)res.pb(a[0] - 1);
    res.pb(2);
    rep(i, m - 2) {
        res.pb(a[i + 1]);
    }
    if (a[m - 1] > 1)res.pb(a[m - 1] - 1);

    cout << sz(res) << endl;
    rep(i, sz(res))cout << res[i] << " ";
    cout << endl;

    return 0;
}


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

typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;

double kaijyo(int n){
    int k(1);
    for(int i=n;i>0;i--){
        k *= i;
    }

    return k;
}

double distance(int x[],int y[],int i,int j){
    int dx = (x[i] - x[j]) * (x[i] - x[j]);
    int dy = (y[i] - y[j]) * (y[i] - y[j]);
    return sqrt(dx+dy);
}

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

    int ans(0);
    switch (x)
    {
    case 1:
        ans += 300000;
        break;
    case 2:
        ans += 200000;
        break;
    case 3:
        ans += 100000;
        break;

    default:
        break;
    }
    switch (y)
    {
    case 1:
        ans += 300000;
        break;
    case 2:
        ans += 200000;
        break;
    case 3:
        ans += 100000;
        break;

    default:
        break;
    }

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

    cout << ans << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
//Write From this Line

int main()
{
	int n;
	cin >> n;
	vector<vector<int>> a(n, vector<int> (n-1));
	rep(i,n){
		rep(j,n-1){
			cin >> a[i][j];
			a[i][j]--;
		}
		reverse(a[i].begin(), a[i].end());
	}

	vector<P> q;
	auto check = [&](int i){
		if(a[i].size() == 0) return;
		int j = a[i].back();
		if(a[j].size() == 0) return;
		if(a[j].back() == i){
			P p(i,j);
			if(p.second < p.first) swap(p.first, p.second);
			q.push_back(p);
		}
	};
	rep(i,n){
		check(i);
	}
	int day = 0;
	while(q.size() > 0){
		day++;
		sort(q.begin(), q.end());
		q.erase(unique(q.begin(), q.end()), q.end());
		vector<P> prevQ;
		swap(prevQ, q);

		for(P p: prevQ){
			int i = p.first, j = p.second;
			a[i].pop_back();
			a[j].pop_back();
		}
		for(P p: prevQ){
			int i = p.first, j = p.second;
			check(i);
			check(j);
		}
	}
	rep(i,n){
		if(a[i].size() != 0){
			cout << -1 << endl;
			return 0;
		}
	}
	cout << day << endl;
}

#include<bits/stdc++.h>
using namespace std;
const int inf=1000000000;
int N=1000000;
vector<int>d(N,-inf);
vector<int>check(N,0);
vector<vector<int>>e(N);
int dfs(int v){
    if(d[v]!=-inf)return d[v];
    if(e[v].size()==0)return d[v]=1;
    for(int i=0;i<e[v].size();i++){
        int u=e[v][i];
        if(check[u]==1 && d[u]==-inf)return d[v]=inf;//non-DAG
        check[u]=1;
        d[v]=max(d[v],dfs(u)+1);
    }
    return d[v];
}
int main(){
    int n;
    cin>>n;
    int a[n][n-1];
    for(int i=0;i<n;i++){
        for(int j=0;j<n-1;j++){
            cin>>a[i][j];
            a[i][j]--;
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n-2;j++){
            e[min(i,a[i][j])*1000+max(i,a[i][j])].push_back
            (min(i,a[i][j+1])*1000+max(i,a[i][j+1]));
        }
    }
    int m=0;
    for(int i=0;i<N;i++)m=max(m,dfs(i));
    if(m>=inf)cout<<"-1"<<endl;
    else cout<<m<<endl;
    return 0;
}


#include<iostream>
#include<algorithm>
#include<functional>

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;

int N, X;
ll S[200];

ll dp[201][100000 + 1];

int main() {
	cin >> N >> X;
	for (int i = 0; i < N; i++)cin >> S[i];
	sort(S, S + N, greater<ll>());

	dp[0][X] = 1;
	for (int i = 0; i < N; i++) {
		for (int amari = 0; amari <= X; amari++) {
			//今見てるのを確定減少列にいれる
		//	if (amari >= S[i] ) {
				dp[i + 1][amari % S[i]] += dp[i][amari];
				dp[i + 1][amari % S[i]] %= MOD;
		//	}
			//いれない
			dp[i + 1][amari] += dp[i][amari] * (N - 1 - i);
			dp[i + 1][amari] %= MOD;
		}
	}
	ll ans = 0;

	for (int i = 0; i <= X; i++) {
		ans += i * dp[N][i];
		ans %= MOD;
	}
	cout << ans << endl;

	return 0;
}

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<pii, int> ppiii;
typedef pair<ll, ll> pll;
typedef pair<pii, pii> query;

ll facs[205];
ll ifacs[205];
const int MOD = 1000000007;

ll modpow(ll b, ll e, ll m) {
  ll r = 1;
  while(e) {
    if(e%2) {
      r *= b;
      r %= m;
    }
    b *= b;
    b %= m;
    e /= 2;
  }
  return r;
}

int l[205];
bool found[205][100005];
ll dp[205][100005];

int n;
ll solve(int k, int x) {
  if(k == 0) return x;
  if(found[k][x]) return dp[k][x];
  found[k][x] = true;
  dp[k][x] = solve(k-1, x%l[k-1]) + (k-1) * solve(k-1, x);
  dp[k][x] %= MOD;
  dp[k][x] *= modpow(k, MOD-2, MOD);
  dp[k][x] %= MOD;
  return dp[k][x];
}

void solve() {
  int m;
  cin >> n >> m;
  facs[0] = 1;
  for(int i = 1; i <= n; i++) {
    facs[i] = facs[i-1] * i;
    facs[i] %= MOD;
  }
  ifacs[n] = modpow(facs[n], MOD-2, MOD);
  for(int i = n-1; i >= 0; i--) {
    ifacs[i] = ifacs[i+1] * (i+1);
    ifacs[i] %= MOD;
  }
  for(int i = 0; i < n; i++) {
    cin >> l[i];
  }
  sort(l, l+n);
  ll ret = solve(n, m);
  ret *= facs[n];
  ret %= MOD;
  cout << ret << "\n";
}

void casesolve() {
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << " ";
    solve();
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  // casesolve();
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define P pair<int,int>
#define PI 3.141592653589793
const int INF = 1001001001;
const ll MX = 1e18;
const int mod = 1000000007;

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

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

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

	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (auto &t : a) {
		cin >> t;
	}
	for (int t = 0; t < k; t++) {
		vector<int> v(n);
		for (int i = 0; i < n; i++) {
			int l = i - a[i];
			int r = i + a[i];
			v[max(0, l)]++;
			if (r + 1 < n) v[r + 1]--;
		}
		for (int i = 1; i < n; i++) {
			v[i] += v[i - 1];
		}
		a = v;
		if (*min_element(a.begin(), a.end()) == n) break;
	}
	for (auto t : a) {
		cout << t << ' ';
	}
	cout << '\n';
}


#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <set>

using namespace std;
typedef long long LL;
static const double EPS = 1e-9;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
bool primecheck(int n){
  FOR(i,2,n/2)
    if(n%i == 0) return false;
  return true;
}

int main(void){
  int twinprime[1000] = {0};
  int ptr=0;
  FOR(i,3,9999){
    if(primecheck(i)&&primecheck(i+2))
      twinprime[ptr++] = i;
  }
  twinprime[ptr] = 10001;
  int n;
  while(cin>>n,n){
    int i=0;
    while(true){
      if(twinprime[i]+2>n){
        cout << twinprime[i-1] << " " << twinprime[i-1] + 2<< endl;
        break;
      }
      i++;
    }
  }
}

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(void)
{
  int n;
  cin >> n;
  getchar();
  for(int i=0;i<n;i++){
    string s;
    getline(cin,s);
    for(int j=0;j<(int)s.size()-6;j++){
      string hos = s.substr(j,7);
      if(hos == "Hoshino"){
	s[j+6] = 'a';
      }
    }
    cout << s << endl;
  }
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

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

int main(void) {
  int i,j;
  int n;
  while(1){
    cin>>n;
    if(n==0)break;
    cin.ignore();
    vector<string> name(n);
    pair<double,string> pp[50];
    rep(i,n){
      int p,a,b,c,d,e,f,s,m;
      cin>>pp[i].second>>p>>a>>b>>c>>d>>e>>f>>s>>m;
      int t=a+b+c+(d+e)*m;
      int in=f*s*m-p;
      pp[i].first=(double)in/t;
      pp[i].first*=-1;
    }
    sort(pp,pp+n);
    rep(i,n)cout<<pp[i].second<<endl;
    cout<<"#"<<endl;
  }
}

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

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

    int n;
    while(cin >> n && n){

        for(int i = 0; i < n; ++i){
            int pm, pe, pj;
            cin >> pm >> pe >> pj;  // ??°????????±????????????

            char ans = 'C';
            int ave = (pm + pe + pj) / 3;

            if(ave >= 50 && (pm >= 80 || pj >= 80)) ans = 'B';
            if(ave >= 70) ans = 'B';
            if(ave >= 80) ans = 'A';
            if(pm + pe >= 180) ans = 'A';
            if(pm == 100 || pe == 100 || pj == 100) ans = 'A';

            cout << ans << endl;
        }
    }

   return 0;
}


#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main(){
	int n;
	while(1){
		cin>>n;
		if(n==0) break;
		double m,e,j;
		rep(i,0,n){
			cin>>m>>e>>j;
			if(max(m,max(e,j))==100) o('A');
			else if(m+e>=180) o('A');
			else if(m+e+j>=240) o('A');
			else if(m+e+j>=210) o('B');
			else if(m+e+j>=150 && max(m,e)>=80) o('B');
			else o('C');
		}

	}
}

/*
 * src.cpp
 *
 *  Created on: 2016/08/04
 *      Author: joi
 */

#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

const int MAX_N=1e4;

int n;
int p[3];

char out[MAX_N+5];

int main(){
	do{
		cin>>n;
		if (n){
			REP(i,n){
				int ave=0;
				bool f=false;
				REP(j,3){
					cin>>p[j];
					ave+=p[j];
					if (p[j]==100){
						f=true;
					}
				}
				if (f){
					out[i]='A';
				}else if (p[0]+p[1]>=180){
					out[i]='A';
				}else if (ave>=80*3){
					out[i]='A';
				}else if (ave>=70*3){
					out[i]='B';
				}else if (ave>=50*3 && (p[0]>=80 || p[1]>=80)){
					out[i]='B';
				}else{
					out[i]='C';
				}
			}
			REP(i,n){
				cout<<out[i]<<endl;
			}
		}
	}while (n);
	return 0;
}


//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;
typedef struct pair<int,int> P;
int A,B,C,D,E,F;
int main() {
	cin>>A>>B>>C>>D>>E>>F;

	int M=A;
	if(B<M)M=B;
	if(C<M)M=C;
	if(D<M)M=D;
	int R=A+B+C+D-M;
	int L=0;
	if(E<F){
		L=F;
	}else{
		L=E;
	}

	cout<<R+L<<endl;
	return 0;
}

#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;

int main() {
	int A, B, C, D, E; char CH;
	while (cin >> A >> CH >> B >> CH >> C >> CH >> D >> CH >> E) {
		VI a = { A,B,C,D,E };
		VI cnt(9);
		SORT(a);
		int i = 0;
		while (i < 5) {
			int elem = a[i], Cnt = 0;
			while (i < 5 && a[i] == elem) { Cnt++; i++; }
			cnt[Cnt]++;
		}

		//check
		int ans = -1;
		if (cnt[4] == 1)ans = 7;
		else if (cnt[3] == 1 && cnt[2] == 1)ans = 6;
		else {
			bool flag = false;
			if (a[0] + 1 == a[1] && a[1] + 1 == a[2] && a[2] + 1 == a[3] && a[3] + 1 == a[4])flag = true;
			else if (a[0] == 1 && a[1] == 10 && a[2] == 11 && a[3] == 12 && a[4] == 13)flag = true;
			if (flag)ans = 5;
		}

		if (ans == -1) {
			if (cnt[3] == 1)ans = 4;
			else if (cnt[2] == 2)ans = 3;
			else if (cnt[2] == 1)ans = 2;
			else ans = 1;
		}

		string str;
		switch (ans) {
		case 1:
			str = "null";
			break;
		case 2:
			str = "one pair";
			break;
		case 3:
			str = "two pair";
			break;
		case 4:
			str = "three card";
			break;
		case 5:
			str = "straight";
			break;
		case 6:
			str = "full house";
			break;
		case 7:
			str = "four card";
			break;
		}

		cout << str << endl;
	}
}


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

long long a,b,x,y,k
;

int main(){
  cin>>a>>b;
  for(long long i=a;i<=b;i++){
   if(i%10==i/10000){
        x=i/10;
        y=i/1000;
    if((x%10)==(y%10))k++;
   }
  }
  cout<<k;
    return 0;
}

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repp(i, n, m) for(int (i) = (n); (i) < (m); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , "; logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005;

/* ...o(^-^)o... */

int main(){
    int a, b, ans; cin >> a >> b;
    ans = 0;

    repp(i, a, b+1){
        string s = to_string(i); int l = s.length();
        bool f = true;
        rep(j, l){
            if(s[j] != s[l-1-j]) f = false;
        }
        if(f) ans++;
    }

    out(ans);
}


#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
    int n; cin >> n;
    vector<vector<int>> a(n,vector<int>(n));
    vector<int> now(n,0);
    rep(i,n) rep(j,n-1) cin >> a[i][j], a[i][j]--;
    int total = n * (n-1) / 2;
    int ans = 0;
    queue<int> q;
    set<int> se;
    rep(i,n){
        if(a[a[i][0]][0] == i){
            if(se.find(i) == se.end() && se.find(a[i][0]) == se.end()){
                q.push(i);
                se.insert(i); se.insert(a[i][0]);
            }
        }
    }
    while(total > 0){
        se.clear();
        int m = q.size();
        total -= m;
        vector<int> wait;
        rep(j,m){
            int u = q.front(); q.pop();
            int v = a[u][now[u]];
            wait.push_back(u);
            wait.push_back(v);
            now[u]++;
            now[v]++;
        }
        for(auto u : wait){
            if(se.find(u) != se.end()) continue;
            if(now[u] == n-1) continue;
            int v = a[u][now[u]];
            if(se.find(v) != se.end()) continue;
            if(now[v] == n-1) continue;
            if(a[v][now[v]] != u) continue;
            q.push(u);
            se.insert(u);
            se.insert(v);
        }
        if(!m){
            puts("-1");
            return 0;
        }
        ans++;
    }
    cout << ans << "\n";
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    int n;
    cin >> n;
    vector<queue<int>> A(n);
    int a;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n-1; ++j) {
            cin >> a;
            A[i].push(a-1);
        }
    }

    int res = 0;
    while (1) {
        bool fin = true;
        bool loop = true;
        vector<bool> checked(n, false);
        for (int i = 0; i < n; ++i) {
            if (checked[i]) continue;

            if (A[i].empty()) {
                continue;
            } else {
                fin = false;
            }

            if (A[A[i].front()].front() == i && !checked[A[i].front()]) {
                checked[i] = true;
                checked[A[i].front()] = true;

                A[A[i].front()].pop();
                A[i].pop();
                loop = false;
            }
        }
        if (fin) break;
        if (loop) {
            cout << -1 << endl;
            return 0;
        }
        res++;
    }
    cout << res << endl;
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <cassert>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define INF 1000000007
#define pi 3.141592653589793
using namespace std;
int saidaikouyakusuu(int a,int b){
    if(b==0) return a;
    return saidaikouyakusuu(b,a%b);
}
int saisyoukoubaisuu(int a,int b){
    return a*b/saidaikouyakusuu(a,b);
}
int n,m,cnt=0,aa[220000],ans=0,x,y,ab[220000];
pair<int,int> pp[220000];
string s,ss[220000];
char c;
queue<int> que;
signed main(){
    cin>>n>>m>>x>>y;
    rep(i,n){
        cin>>aa[i];
        x=max(x,aa[i]);
    }
    rep(i,m){
        cin>>ab[i];
        y=min(y,ab[i]);
    }
    if(y<=x){
        cout<<"War"<<endl;
    }else{
        cout<<"No War"<<endl;
    }
}

#pragma region header
#define _GLIBCXX_DEBUG
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define ts to_string
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector <string>
#define vvs vector <vector<string>>
#define pq  priority_queue<int>
#define smallpq  priority_queue<int, vector<int>, greater<int>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
constexpr ll mod = 1e9 + 7;
constexpr ll inf = INT32_MAX / 2;
constexpr ll INF = LLONG_MAX / 2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */
/* --------------------テンプレート------------------ */
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;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if (b == 0) return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
bool isprime(ll a)//素数判定、primeならtrue,違うならfalse
{
    if (a < 2) return false;
    else if (a == 2) return true;
    else if (a % 2 == 0) return false;
    double m = sqrt(a);
    for (int i = 3; i <= m; i += 2)
    {
        if (a % i == 0)
        {
            return false;
        }
    }
    // 素数である
    return true;
}
ll keta(ll n) {        //桁数を求める
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    string S;
    cin >> S;
    int cnt = 0;
    rep(i, S.size()) {
        if (S[i] >= 97 && S[i] <= 122) cnt++;
    }
    if (S[0] == 'A' && S[0] != 'C' && S[1] != 'C' && S[S.size() - 1] != 'C' && count(all(S), 'C') == 1 && cnt == S.size() - 2) {
        puts("AC");
    }
    else puts("WA");
}


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

int main(){
    string s;
    cin >> s;
    int a = s.at(0) - '0', b = s.at(1) - '0', c = s.at(2) - '0', d = s.at(3) - '0';
    for(int i = 0; i < 8;i++){
        bitset<3> s(i);
        vector<char> fugou(3);
        int temp = a;
        if(s.test(0)) temp += b, fugou[0] = '+';
        else temp -= b, fugou[0] = '-';
        if(s.test(1)) temp += c, fugou[1] = '+';
        else temp -= c,  fugou[1] = '-';
        if(s.test(2)) temp += d, fugou[2] = '+';
        else temp -= d,  fugou[2] = '-';
        if(temp == 7){
            cout << a << fugou[0] << b << fugou[1] << c << fugou[2] << d << "=7" << endl;
            break;
        }
    }
    return 0;
}

#include <iostream>

using namespace std;

int order[4000];

bool search(int);

class Member {
public:
	Member() {sum = 0;}

	void add(long price, long num) {
		sum += (long long int)price*num;
	}

	bool milion()
	{
		if (sum >= 1000000) return true;
		else return false;
	}

private:
	long long int sum;
	int id;
};

bool search(int num)
{
	for (int i=0; i<4000; i++)
		if (order[i] == num ) return true;

	return false;

}

int main()
{
	int n, idx, memNum;
	long price, num;
	bool nothing;

	ios::sync_with_stdio();

	while (1) {
		Member *member = new Member[4000];
		memNum=0;
		nothing =true;

		for (int i=0; i<4000; i++) order[i] = -1;

		if (cin >> n, !n) break;
		for (int i=0; i<n; i++) {
			scanf("%d %ld %ld", &idx, &price, &num);
			member[idx].add(price, num);
			if (!search(idx)) order[memNum++] = idx;
		}

		for (int i=0; i<4000 && order[i] > 0; i++)
			if (member[order[i]].milion()) { cout << order[i] << endl; nothing = false; }
		if (nothing) cout << "NA" << endl;
	}
}


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

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

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

    int n;
    cin >> n;

    string s;
    cin >> s;

    int cand[2] = {0, 1};
    rep (i, 2)
    {
        rep (j, 2)
        {
            bool ok = true;
            vs32 ans(n);
            ans[0] = cand[i];
            ans[1] = cand[j];
            for (int k = 2; k < n; ++ k)
            {
                ans[k] = ans[k - 1] ^ ans[k - 2] ^ (s[k - 1] == 'x');
            }
            if ((ans[0] == ans[n - 1] ^ ans[n - 2] ^ (s[n - 1] == 'x')) && (ans[n - 1] == ans[0] ^ ans[1] ^ (s[0] == 'x')))
            {
                rep (k, n)
                {
                    cout << (ans[k] ? 'W' : 'S');
                }
                cout << "\n";
                return 0;
            }
        }
    }

    cout << "-1\n";
    return 0;
}

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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long

typedef pair<ll, ll> P;
int n;
string s;
vector<char> ans(100005);

void tyosa() {
    REPN(i, 1, n) {
        if(ans[i] == 'S') {
            if(s[i] == 'o') ans[(i+1)%n] = ans[i-1];
            else ans[(i+1)%n] = ans[i-1] == 'S' ? 'W' : 'S';
        } else {
            if(s[i] == 'x') ans[(i+1)%n] = ans[i-1];
            else ans[(i+1)%n] = ans[i-1] == 'S' ? 'W' : 'S';
        }
    }
}

bool hantei() {
    if(s[0] == 'o') {
        if(ans[0] == 'S') {
            if(ans[n-1] == ans[1]) {
                return true;
            }
        } else {
            if(ans[n-1] != ans[1]) {
                return true;
            }
        }
    } else {
        if(ans[0] == 'S') {
            if(ans[n-1] != ans[1]) {
                return true;
            }
        } else {
            if(ans[n-1] == ans[1]) {
                return true;
            }
        }
    }

    return false;
}

int main(){
    cin >> n >> s;
    char zenkai;

    /* 羊、羊 */
    ans[0] = 'S';
    zenkai = 'S';
    ans[1] = 'S';
    tyosa();
    if(zenkai == ans[0]) {
        if(hantei()) {
            REP(i, n) cout << ans[i];
            cout << endl;
            return 0;
        }
    }

    /* 羊、狼 */
    ans[0] = 'S';
    zenkai = 'S';
    ans[1] = 'W';
    tyosa();
    if(zenkai == ans[0]) {
        if(hantei()) {
            REP(i, n) cout << ans[i];
            cout << endl;
            return 0;
        }
    }

    /* 狼、羊 */
    ans[0] = 'W';
    zenkai = 'W';
    ans[1] = 'S';
    tyosa();
    if(zenkai == ans[0]) {
        if(hantei()) {
            REP(i, n) cout << ans[i];
            cout << endl;
            return 0;
        }
    }

    /* 狼、狼 */
    ans[0] = 'W';
    zenkai = 'W';
    ans[1] = 'W';
    tyosa();
    if(zenkai == ans[0]) {
        if(hantei()) {
            REP(i, n) cout << ans[i];
            cout << endl;
            return 0;
        }
    }

    cout << "-1" << endl;

    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--)

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

#define fi first
#define se second

#define vi vector<int>
#define pb push_back
#define mp make_pair

#define pcnt __builtin_popcount

typedef long long ll;

const ll inf = 99900100100;
const int MOD = 998244353;
const double EPS = 1e-9;

int dp[1100][1100] = {};
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    string s1,s2;
    cin >> s1;
    cin >> s2;
    rep(i,s1.size()+1) dp[i][0] = i;
    rep(j,s2.size()+1) dp[0][j] = j;

    REP(i,1,s1.size()+1){
      REP(j,1,s2.size()+1){
        int u = (s1[i-1]==s2[j-1])?0:1;
        dp[i][j] = min({dp[i-1][j]+1,dp[i][j-1]+1,dp[i-1][j-1]+u});
      }
    }
    cout << dp[s1.size()][s2.size()] << endl;
    return 0;
}

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

using namespace std;

#define whole(xs) (xs).begin(),(xs).end()

template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs) {
    if (xs.empty()) return os << "[]";
    os << "[" << xs[0];
    for (int i = 1; i < xs.size(); i++) os << ' ' << xs[i];
    return os << "]";
}

const int INF = 1<<28;
int LevenshteinDistance(const string& s, const string& t) {
    const int N = s.size(), M = t.size();
    vector< vector<int> > dp(2, vector<int>(M + 1, INF));
    for (int j = 0; j <= M; j++) dp[0][j] = j;
    for (int i = 1; i <= N; i++) {
        fill(whole(dp[i & 1]), INF);
        dp[i & 1][0] = i;
        for (int j = 1; j <= M; j++) {
            int& v = dp[i & 1][j];
            v = min(v, dp[(i - 1) & 1][j] + 1);
            v = min(v, dp[i & 1][j - 1] + 1);
            v = min(v, dp[(i - 1) & 1][j - 1] + (s[i - 1] != t[j - 1]));
        }
    }
    return dp[N & 1][M];
}

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


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

int main(){
	int n,m;
	while(cin >> n >> m,n){
		int p[1000],sum = 0;
		for(int i = 0;i < n;i++) cin >> p[i];
		sort(p,p + n,greater<int>());
		for(int i = 0;i < n;i++){
			if(i % m != m - 1) sum += p[i];
		}
		cout << sum << endl;
	}
	return 0;
}

// abc060_c
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N, T;
    cin >> N >> T;
    vector<int> A(N);
    REP(i, N) cin >> A[i];

    ll ans = 0;
    ll l = 0;
    ll r = 0;
    REP(i, N){
        if (r < A[i]){
            ans += r - l;
            l = A[i];
            r = A[i] + T;
        } else {
            r = A[i] + T;
        }
    }
    ans += r - l;
    print(ans);

    return 0;
}


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

int main(){
    vector<queue<char>> s(3);
    for(int ix=0;ix<3;ix++){
        string tmp;
        cin >> tmp;
        for(int ixx=0;ixx<tmp.size();ixx++) s.at(ix).push(tmp.at(ixx));
    }
    char card;
    int turnplayer = 0;
    while(!s.at(turnplayer).empty()){
        card = s.at(turnplayer).front();
        s.at(turnplayer).pop();
        turnplayer = card - 'a';
    }
    if(turnplayer == 0) cout << "A" << endl;
    if(turnplayer == 1) cout << "B" << endl;
    if(turnplayer == 2) cout << "C" << endl;
}

#include<iostream>
#include<vector>
#include<set>
#include<utility>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cctype>
#include<algorithm>
#include<cinttypes>
#include<stack>
#include<ctgmath>
using namespace std;

typedef long long ll;

#define ceil(a,b)  ( !(a%b) ? a/b : a/b+1 )
#define all(a)  (a).begin(),(a).end()
#define allr(a) (a).rbegin(),(a).rend()
#define endl '\n'
#define debug(a) cin>>#a>>a;
//vector<ll> primes{ }
template<typename T>
T gcd( T a, T b ) {
    return !a ? b : gcd( b%a, a);
}

template<typename T>
T lcm( T a, T b ){
    return (a*b)/gcd(a,b);
}

int main(){
    string sa,sb,sc;
    cin >> sa >> sb >> sc;
    reverse(sa.begin(),sa.end());
    reverse(sb.begin(),sb.end());
    reverse(sc.begin(),sc.end());
    char check = sa.back();
    sa.pop_back();
    if( sa.empty() ){
        std::cout << 'A' << endl;
    } else {
        bool flag = false;
        while(true){
            switch(check){
                case 'a':
                    if( sa.empty() ){
                        cout << 'A' << endl;
                        flag = true;
                    } else {
                        check = sa.back();
                        sa.pop_back();
                    }
                    break;
                case 'b':
                    if( sb.empty() ){
                        cout << 'B' << endl;
                        flag = true;
                    } else {
                        check = sb.back();
                        sb.pop_back();
                    }
                    break;
                case 'c':
                    if( sc.empty() ){
                        cout << 'C' << endl;
                        flag = true;
                    } else {
                        check = sc.back();
                        sc.pop_back();
                    }
                    break;
            }
            if(flag){
                break;
            }
        }
    }
    return 0;
}


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

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

int main() {
	int n, m;
	int s, c;
	int ans = 0;
	cin >> n >> m;
	vector<int> a(3);
	a[0] = a[1] = a[2] = 10;
	rep(i, m) {
		cin >> s >> c;
		if (a[s - 1] != 10 && a[s - 1] != c) {
			cout << -1 << endl;
			return 0;
		}
		else {
			a[s - 1] = c;
		}
	}
	if (a[0] == 0 && n != 1) {
		cout << -1 << endl;
		return 0;
	}
	else {
		if (a[0] == 10) {
			if (n == 1)a[0] = 0;
			else a[0] = 1;
		}
		for (int i = 1; i<n; i++) {
			if (a[i] == 10)a[i] = 0;
		}
		rep(i, n) {
			ans += a[i] * pow(10, n - i - 1);
		}
	}
	cout << ans << endl;

	return 0;
}

#include<bits/stdc++.h>
#include<string.h>
#define ll long long
#define pf printf
#define sf scanf
#define ff first
#define ss second
#define clr clear()
#define sz size()
#define pb push_back
#define mk make_pair
#define pi acos(-1)
#define inf 20000000000000000
#define mod 998244353
#define ull unsigned long long int
#define f(i,k,n) for(i=k;i<n;i++)
#define fr(i,n,k) for(i=n;i>=k;i--)
#define ent(a) scanf("%lld",&a)
#define ent2(a,b) scanf("%lld%lld",&a,&b)
#define ent3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define mem(a) memset(a,0,sizeof(a))
#define vec(v,s) vector<ll>v[s]
#define arr(a,s) ll a[s];
/*#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
//knight and king//
int dr[]= {2,2,-2,-2,1,-1,1,-1};
int dc[]= {1,-1,1,-1,2,2,-2,-2};
int dr1[]= {0,0,1,1,1,-1,-1,-1};
int dc1[]= {1,-1,1,0,-1,0,1,-1};
int dr2[]= {0,0,1,-1};
int dc2[]= {1,-1,0,0};
////////////////////////////
using namespace std;
#define ma 200
ll a[4][4];
ll mark[ma];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll i,j,x,y,n,m;
    while(cin>>n)
    {
        memset(mark,-1,sizeof(mark));
        cin>>m;
        vector<pair<ll,ll> >v;
        ll max1=n;
        for(i=0;i<m;i++)
        {
            cin>>x>>y;
            v.pb({x,y});
            mark[x]=y;
            max1=max(max1,x);
        }
        for(i=1;i<=max1;i++)
        {
            if(mark[i]==-1)
            {
                if(i==1&&max1>1)mark[i]=1;
                else mark[i]=0;
            }
        }
        bool f=0;

        for(i=0;i<v.sz;i++)
        {
            if(mark[v[i].ff]!=v[i].ss)f=1;
        }
        if(mark[1]==0&&max1>1)f=1;
        if(f)cout<<"-1"<<endl;
        else
        {
            for(i=1;i<=max1;i++)cout<<mark[i];
            cout<<endl;
        }

    }

    return 0;
}


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

int main()
{
  string s;
  int maxv = 0;
  int m[3] = {'J','O','I'};

  cin >> s;
  int i = 0;
  while(i < s.size()) {
    if(m[0] == s[i]) {
      int count[3] = {0};
      Rep(j,3)for(; m[j] == s[i]; i++, count[j]++);
      if(min(count[0],count[2]) < count[1])continue;
      maxv = max(maxv,count[1]);
    } else i++;
  }
  cout << maxv << endl;
  return 0;
}

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>

using namespace std;

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

int anser(string s) {
	if (s == "Male") {
		return 0;
	}
	if (s == "Female") {
		return 1;
	}
	if (s == "Vacant") {
		exit(0);
	}
	exit(-1);
}

int query(int p) {
	cout << p << endl;
	string s;
	cin >> s;
	return anser(s);

}

bool bingo(int d, int v1, int v2) {
	if (d % 2 == 0) {
		return v1 != v2;
	} else {
		return v1 == v2;
	}
}

int main() {
	int n;
	cin >> n;
	int from = 0;
	int to = n - 1;

	int from_q = query(from);
	int to_q = query(to);

	while(true) {
		int mid = from + (to - from) / 2;
		int mid_q = query(mid);

		if (bingo(mid - from,from_q, mid_q)) {
			to = mid;
			to_q = mid_q;
		} else if (bingo(to - mid, mid_q, to_q)) {
			from = mid;
			from_q = mid_q;
		} else {
			int a[0];
			a[-10000000] = 0;
		}
	}

	return 0;
}


#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;

const long long MAX = 1000100;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for(int i = 2;i < MAX;i++){
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
long long COM(int n, int k){
	if(n < k) return 0;
	if(n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
	COMinit();
	int n,m;
	cin >> n >> m;

	map<int,int> mp;
	for(int i = 2;i * i <= m;i++){
		while(m % i == 0){
			mp[i]++;
			m /= i;
		}
	}

	if(m != 1)mp[m]++;

	ll ans = 1;

	for(auto p:mp){
		ll com = COM(p.second+n-1,p.second);
		ans *= com;
		ans %= MOD;
	}

	cout << ans << endl;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;

int main() {
    int A,B; cin >> A >> B; // Aが白

    bool changed = false;
    if (A>B){
        swap(A,B);
        changed = true;
    }

    vector<vector<int>> T(100,vector<int>(100,0));

    int b = 1;
    while(b<=B){
        int yoko = (b-1)%25;
        yoko *= 4;
        int tate = (b-1)/25;
        tate *= 4;

        T[tate][yoko] = 1;
        T[tate][yoko+1] = 1;
        T[tate][yoko+2] = 1;
        T[tate+1][yoko] = 1;
        T[tate+1][yoko+1] = 1;
        T[tate+1][yoko+2] = 1;
        T[tate+2][yoko] = 1;
        T[tate+2][yoko+1] = 1;
        T[tate+2][yoko+2] = 1;

        b++;
    }

    int a = 1;
    while(a<=A-1){
        int yoko = (a-1)%25;
        yoko *= 4;
        int tate = (a-1)/25;
        tate *= 4;

        T[tate+1][yoko+1] = 0;

        a++;
    }

    cout << 100 << " " << 100 << endl;
    REP(i,100){
        REP(j,100){
            if(!changed){
                if(T[i][j]==0)cout << ".";
                else cout << "#";
            }else{
                if(T[i][j]==0)cout << "#";
                else cout << ".";
            }

        }
        cout << endl;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(inti=a;i<=b;i++)

#define MOD 1000000007
typedef long long int ll;
typedef vector<int>vi;
typedef pair<int,int>pi;

int main(){
string s ;
cin>>s;
int ans = s[0]-'0';
for(int op1 = 0 ;op1 < 2;op1++)
{
     if(op1)
        {
            ans+=(s[1]-'0');
        }
        else ans-=(s[1]-'0');
    for(int op2 = 0;op2<2;op2++)
    {
       if(op2)
        {
            ans+=(s[2]-'0');
        }
        else ans-=(s[2]-'0');
        for(int op3 = 0 ; op3<2;op3++)
        {
              if(op3)
            {
            ans+=(s[3]-'0');
            }
             else ans-=(s[3]-'0');

             if(ans==7)
             {
                 cout<<s[0];
                 if(op1)cout<<"+";
                 else cout<<"-";
                 cout<<s[1];
                 if(op2)cout<<"+";
                 else
                    cout<<"-";
                 cout<<s[2];
                  if(op3)cout<<"+";
                 else
                    cout<<"-";
                cout<<s[3] <<"=7"<<endl;
                 return 0;
             }

             if(op3)
            {
            ans-=(s[3]-'0');
            }
             else ans+=(s[3]-'0');

        }
          if(op2)
        {
            ans-=(s[2]-'0');
        }
        else ans+=(s[2]-'0');
    }

    if(op1)
        {
            ans-=(s[1]-'0');
        }
        else ans+=(s[1]-'0');
}

 return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int now[4];
char C[4], op[2] = {'+', '-'};

int main(){
  for (int i = 0; i < 4; i++){
    cin >> C[i];
    now[i] = C[i] - '0';
  }

  for (int i = 0; i < 8; i++){
    int val = now[0], num = i;

    for (int j = 1; j < 4; j++){
      val += pow(-1, num % 2) * now[j];
      num /= 2;
    }

    if (val == 7){
      num = i;
      cout << now[0];
      for (int j = 1; j < 4; j++){
        cout << op[num%2] << now[j];
        num /= 2;
      }

      cout << "=7" << endl;

      return 0;
    }

  }

  return 0;
}


#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)
#define rrep(i, j, n) for (int i = (int)n - 1; j <= i; --i)

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, 0, n) cin >> a[i];

  unordered_map<int, int> odd, even;
  rep(i, 0, n) {
    if (i & 1)
      odd[a[i]]++;
    else
      even[a[i]]++;
  }

  vector<pair<int, int>> o, e;
  for (auto p : odd) { o.emplace_back(p.second, p.first); }
  for (auto p : even) { e.emplace_back(p.second, p.first); }
  sort(o.rbegin(), o.rend());
  sort(e.rbegin(), e.rend());
  o.emplace_back(0, n / 2);
  e.emplace_back(0, n / 2);

  if (o[0].second == e[0].second) {
    cout << n - o[0].first - max(o[1].first, e[1].first) << endl;
  } else {
    cout << n - o[0].first - e[0].first << endl;
  }
  return 0;
}

#include <iostream>
#include <algorithm>
#include <string>
#include  <queue>
#include <vector>
#include  <cstdio>
#include <cstring>
#include<map>
#include<set>
//#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d",&a)
#define I2(a,b) scanf("%d%d",&a,&b)
#define I3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define L(a) scanf("%lld",&a)
#define L2(a,b) scanf("%lld%lld",&a,&b)
#define L3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define PI(a) printf("%d",a)
#define PL(a) printf("%lld",a)
#define PT(t) printf("Case %d: ",t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define SZ(a) ((int)a.size())-1
#define f(i,a,b) for(int i=a;i<=b; i++)
#define fr(i,a,b) for(int i=a;i<=b; i++)
#define frr(i,a,b) for(int i=a;i>=b; i--)
#define frv(i,a)  for(int i=0;i<a.size();i++)
#define pi 2.0*acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define Endl "\n"
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T mul(T p, T e, T M)
{
    ll ret = 0;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret + p) ;
        p = (p + p) ;
        if(ret>=M)ret-=M;
        if(p>=M)p-=M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a, T b)
{
    if(b == 0)return a;
    return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M)
{
    return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}

template <class T>bool ISLEFT(T a, T b, T c)
{
    if(((a.xx - b.xx) * (b.yy - c.yy) - (b.xx - c.xx) * (a.yy - b.yy)) < 0.0)return 1;  //Uporer dike //A,b,c, x okkher ordera sorted
    else return 0;
}

#define  mx 200004
#define base 193ll

typedef pair<int,int >P;
//////////////////////////
////////////////////////
#define F(i,a,b) for(int i=a;i<b; i++)
#define LL long long
#define MX  200007
#define md 998244353ll
///////////////////////////
///////////////////////////
///

int main(){

  int n;
  I(n);
  vector<int>v[2];
  for(int i = 1;i<=n;i++){
    int x;
    I(x);
    v[i%2].push_back(x);
  }

  int res = 0;

  map<int,int> mp[2];
  set< pair<int, int> >st[2];
  for(int i = 0;i<= 1;i++){
    int ma = 0;
    int cnt = 1;
    for(int j = 0;j<v[i].size();j++){
      mp[i][v[i][j]]++;
    }
  }

  for(int i = 0;i<= 1;i++){
    for(int j = 1;j<v[i].size();j++){
      st[i].insert(mk(-mp[i][v[i][j]], v[i][j]));
    }
  }

  int ans = n;
  int i = 0;
  for(auto it: st[0]){
    i++;
    if(i==3)break;
    int j = 0;
    for(auto it1: st[1]){
      j++;
      if(j==3)break;
      if(it.second == it1.second){
       // cout<<it.first<<" "<<it1.first<<endl;
        ans = min(ans, n - max(-it.first, -it1.first));
      }
      else {
        ans = min(ans, n+it.first +it1.first);
      }
    }
  }

  cout<<ans<<endl;

  return 0;
}


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

int main(){
  int N,K;
  while( cin >> N >> K){
    if( N == 0 && K == 0){ break;}
    vector<string> P(N);
    for(int i = 0; i < N; i++){ int c; cin >> c; P[i] = to_string(c);}

    set<string> s;

    if( K == 2){
      for(int i = 0; i < N-1; i++){
        for(int j = i+1; j < N; j++){
          vector<string> vec;
          vec.push_back(P[i]); vec.push_back(P[j]);
          sort(vec.begin(),vec.end());
        do{
          s.insert(vec[0]+vec[1]);
        }while(next_permutation(vec.begin(),vec.end()));

        }}}

    if( K == 3){
      for(int i = 0; i < N-2; i++){
        for(int j = i+1; j < N-1; j++){
          for(int k = j+1; k < N; k++){

          vector<string> vec;
          vec.push_back(P[i]); vec.push_back(P[j]); vec.push_back(P[k]);
          sort(vec.begin(),vec.end());
        do{
          s.insert(vec[0]+vec[1]+vec[2]);
        }while(next_permutation(vec.begin(),vec.end()));

          }
        }
      }
    }

    if( K == 4){
      for(int i = 0; i < N-3; i++){
        for(int j= i+1; j < N-2; j++){
          for(int k = j+1;k < N-1; k++){
            for(int l = k+1; l < N; l++){
         vector<string> vec;
          vec.push_back(P[i]); vec.push_back(P[j]); vec.push_back(P[k]); vec.push_back(P[l]);
          sort(vec.begin(),vec.end());
        do{
          s.insert(vec[0]+vec[1]+vec[2]+vec[3]);
        }while(next_permutation(vec.begin(),vec.end()));

            }
          }
        }
      }
    }
    cout << s.size() << endl;
  }

  return 0;}

#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[a]; if (a != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///
bool comp(pii a, pii b) {
	if (a.first*a.first + a.second*a.second == b.first*b.first + b.second*b.second) {
		return a.first < b.first;
	}
	else {
		return a.first*a.first+a.second*a.second < b.first*b.first+b.second*b.second;
	}
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	vector<pii> v;
	FOR(i, 1, 151) {
		FOR(j, i + 1, 151) {
			v.push_back({ i,j });
		}
	}
	sort(ALL(v), comp);
	while (1) {
		int h, w;
		cin >> h >> w;
		if (!h)break;
		int c = find(ALL(v), make_pair(h, w)) - v.begin();
		cout << v[c + 1].first << " " << v[c + 1].second << endl;
	}

	return 0;
}