#include<bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define ll long long
using namespace std;
typedef pair<char,int> pii;
set<ll>mapa;
const int maxv=2300000;
int n,pos[maxv+10],br;
ll primes[maxv],rows[1010],cols[1010],aa[519][510];
vector<ll>a[510][510];
void check(){

ll maxx=LONG_MIN;
ll minn=LONG_MAX;
set<ll>mapa2;
    for(int i=1;i<=n;i++){

        for(int j=1;j<=n;j++){

            if(i<n){
                mapa.insert(max(aa[i][j],aa[i+1][j])%min(aa[i][j],aa[i+1][j]));
            }
            if(j<n){
                mapa.insert(max(aa[i][j],aa[i][j+1])%min(aa[i][j],aa[i][j+1]));
            }

            maxx=max(maxx,aa[i][j]);
            minn=min(minn,aa[i][j]);
            mapa2.insert(aa[i][j]);
        }

    }
printf("%d %d %lld %lld\n",mapa.size(),mapa2.size(),maxx,minn);
}
void sito(){

    for(int i=2;i<=maxv;i++){
        if(pos[i])continue;
        primes[++br]=i;
        for(int j=i;j<=maxv;j+=i)pos[j]=1;
    }

}
ll lcm(ll a,ll b){
  return (a/__gcd(a,b))*b;
}
void fix(int x,int y){

    ll lc=1;

    if(aa[x+1][y]!=0){lc=lcm(lc,aa[x+1][y]);}
    if(aa[x-1][y]!=0){lc=lcm(lc,aa[x-1][y]);}
    if(aa[x][y+1]!=0){lc=lcm(lc,aa[x][y+1]);}
    if(aa[x][y-1]!=0){lc=lcm(lc,aa[x][y-1]);}

    aa[x][y]=lc+1;
}
int dist(int x,int y,int x1,int y1){
   return abs(x-x1)+abs(y-y1);
}
int main(){

    ///freopen("test.txt","r",stdin);

    scanf("%d",&n);

    if(n==2){
        printf("4 7\n23 10\n");
        return 0;
    }

    sito();

    int curr=0;
    for(int i=0;i<n;i++)
        rows[i*2]=primes[++curr];

    for(int i=0;i<n;i++)
        cols[i*2]=primes[++curr];

    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){

            if(dist(1,1,i,j)%2==0){
                a[i][j].pb(rows[dist(1,1,i,j)]);
                aa[i][j]=rows[dist(1,1,i,j)];
            }

        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){

            if(n%2){
               if(dist(n,1,i,j)%2==0){
                a[i][j].pb(cols[dist(n,1,i,j)]);
                aa[i][j]*=cols[dist(n,1,i,j)];
               }
            }
            else{
                if(dist(n,1,i,j)%2==1){
                    a[i][j].pb(cols[dist(n,1,i,j)-1]);
                    aa[i][j]*=cols[dist(n,1,i,j)-1];
                }
            }

        }
    }

    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if((i+j)%2)fix(i,j);
            printf("%lld ",aa[i][j]);
        }
        printf("\n");
    }

    return 0;
}

#include<bits/stdc++.h>
#define Fail puts("NO"),exit(0);
#define eps 1e-10
#define maxn 505
#define maxm 4010
#define inf 1000000007
#define mod 998244353
#define pi acos(-1)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int>pii;
typedef bitset<maxn> bit;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n;
int prime[100010],primesize;
bool notprime[100010];
void get_prime()
{
    for(int i=2;i<=100000;i++)
    {
        if(!notprime[i])   prime[++primesize]=i;
        for(int j=1;j<=primesize&&i*prime[j]<=100000;j++)
        {
            notprime[i*prime[j]]=true;
            if(i%prime[j]==0)  break;
        }
    }
}
ll ans[maxn][maxn];
int xx[4]={0,0,1,-1};
int yy[4]={1,-1,0,0};
bool check(int x,int y)
{
    return (x>=1&&x<=n&&y>=1&&y<=n);
}
ll gcd(ll x,ll y)
{
    if(!y)  return x;
    return gcd(y,x%y);
}
ll lcm(ll x,ll y)
{
    return x*(y/gcd(x,y));
}
int main()
{
    get_prime();
    n=read();
    int l=1,r=(n<<1)+(!(n&1));
    for(int i=2;i<=(n<<1);i+=2)
    {
        int val;
        if(i%4==0)  val=prime[l++];
        else        val=prime[r--];
        for(int x=1;x<=n;x++)
        {
            int y=(i-x);
            if(y<=0||y>n)  continue;
            ans[x][y]=val;
        }
    }
    for(int i=-(n-1)/2*2;i<=(n-1)/2*2;i+=2)
    {
        int val;
        if(i%4==0)  val=prime[l++];
        else        val=prime[r--];
        for(int x=1;x<=n;x++)
        {
            int y=(i+x);
            if(y<=0||y>n)  continue;
            ans[x][y]*=val;
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if((i+j)&1)
            {
                for(int k=0;k<4;k++)
                {
                    int tx=i+xx[k],ty=j+yy[k];
                    if(check(tx,ty))
                    {
                        if(!ans[i][j])  ans[i][j]=ans[tx][ty];
                        else          ans[i][j]=lcm(ans[i][j],ans[tx][ty]);
                    }
                }
                ans[i][j]++;
            }
        }
    }
    if(n==2)  ans[1][2]=ans[1][2]*2-1;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)  printf("%lld ",ans[i][j]);
        puts("");
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxx = 110;
const int INF = 1 << 30;
int main()
{
	int n, p[maxx], m[maxx][maxx];

	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%d %d", &p[i - 1], &p[i]);

	for (int i = 1; i <= n; i++)
		m[i][i] = 0;

	for (int l = 2; l <= n; l++) {
		for (int i = 1; i <= n - l + 1; i++) {
			int j = i + l - 1;
			m[i][j] = INF;
			for (int k = i; k <= j - 1; k++)
				m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);

		}
	}
	printf("%d\n", m[1][n]);
	return 0;
}

/**
 * 	matrix chain multiplication
 * 	f(n,m) = multiply Mn*M(n+1)*...*M(m-1)*M(m)
 * 	f(n,n) = 1
 * 	r(n)=c(n-1)
 * 	f(n,n+1) = C(n) * R(n) * C(n+1) = c(n) * c(n-1) * c(n+1)
 * 	f(n,k,m) = f(n,k)*f(k+1,m)*C(n)*r(n)*c(k)
 * 	f(n,m) = min(f(n,k,m)
 */

#include <iostream>
#include <cmath>
#include <climits>

using namespace std;

int r[100] = {0};
int a[100][100] = {0};

int f(int n, int m);
int f(int n, int k, int m);

int f(int n, int k, int m)
{
	return f(n,k) + f(k+1,m) + (r[n] * r[k+1] * r[m+1]);
}

int f(int n, int m)
{
	if (n==m) return 0;
	int & ra = a[n][m];
	if (ra) return ra;
	ra = INT_MAX;
	for (int k=n;k<m;k++)
	{
		int ans = f(n,k,m);
		if (ans < ra) ra = ans;
	}
	return ra;
}

int main()
{
	int rr = 0;
	int cc = 0;
	int n = 0;
	cin >> n;
	for (int i=0;i<n;i++)
	{
		cin >> rr >> cc;
		r[i]=rr;
		r[i+1]=cc;
	}
	for (int i=0;i<n-1;i++)
	{
		a[i][i+1] = r[i] * r[i+1] * r[i+2];
	}
	int ans = f(0,n-1);
	cout << ans << endl;
}


#include <bits/stdc++.h>
#define boost_io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define num(a) a-'0'
#define maxself(a,b) if(b>a)a=b
#define minself(a,b) if(b<a)a=b;
#define debug(x) cout<<#x<<":"<<x<<" "
#define all(a) (a).begin(), (a).end()
#define vi vector<int>
#define vl vector<long long int>
#define v vector
#define p pair
#define pb push_back
#define mk make_pair
#define f first
#define s second
#define ln "\n"
typedef long long int ll;
typedef long double ld;
typedef double d;
using namespace std;
ll modF=1e9+7;
ll INF=1e11;

void solve(){
	int n;
	cin>>n;
	v<v<p<int,int>>> a(n);
	int h;
	rep(i,0,n){
		cin>>h;
		rep(j,0,h){
			int x,pos;
			cin>>x>>pos;
			a[i].pb(mk(x,pos));
		}
	}
	ll ans=0;
	for(int bit=0;bit<(1<<n);bit++){
		int counter=0;
		int pos=1;
		for(int j=0;j<n;j++){
			if(1<<j & bit){
				for(auto e:a[j]){
					h=((1<<(e.f-1)) & bit);
					if(h==0 && e.s==1){
						pos=0;
					}
					else if(h!=0 && e.s==0){
						pos=0;
						break;
					}
				}
				counter++;
			}
		}
		if(pos){
			maxself(ans,counter);
		}
	}
	cout<<ans<<ln;
}

int main(){
	boost_io;
	solve();
	return 0;
}

/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

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

signed main(){
	int n;
	cin>>n;
	vvi in(n,vi(2));
	rep(i,n)rep(j,2)cin>>in[i][j];
	sort(all(in),[](vi a,vi b){
		return a[0]+a[1]<b[0]+b[1];
	});
	vi dp(n+1,inf);
	dp[0]=0;
	rep(i,n){
		vi ndp=dp;
		rep(j,n){
			if(dp[j]<=in[i][0])
				cmin(ndp[j+1],dp[j]+in[i][1]);
		}
		dp=ndp;
	}
	int out=inf;
	rep(i,n+1)if(dp[i]-inf)out=i;
	cout<<out<<endl;
}


#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, s, n)    for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...)  type __VA_ARGS__; read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(sz, makeV<T>(initValue, args...));
}

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

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x): x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    var(int, N);
    string res;

    vector<int> a(N, -1);

    const auto ask = [&](int n) -> int {
        string res;
        cout << n << endl;
        cin >> res;
        if (res == "Vacant") return a[n] = 0;
        if (res == "Male") return a[n] = 1;
        return a[n] = 2;
    };

    if (ask(0) == 0) return 0;
    int begin = 0;
    int end = N;

    int cnt = 0;
    while (++cnt <= 20 && end - begin > 1) {
        const int mid = (begin + end) / 2;
        if (ask(mid) == 0) return 0;

        if ((a[begin] == a[mid]) == ((mid - begin) & 1)) {
            end = mid;
        } else {
            begin = mid;
        }
    }

    return 255;
}

#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<bool> ans(n, false);
    int cnt = 0;
    for (int i = n-1; i >= 0; --i) {
        bool flg = false;
        for (int j = i; j < n; j = j + (i+1)) {
            flg ^= ans[j];
        }
        if (flg ^ a[i]) {
            ++cnt;
            ans[i] = true;
        }
    }
    cout << cnt << endl;
    if (cnt == 0) return 0;
    rep(i, n) {
        if (ans[i]) {
            if (i >= 1) cout << " ";
            cout << i+1;
        }
    }
    cout << endl;
    return 0;
}


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

int w,h;

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

void dfs_aux(int sx, int sy, int map[WMAX][HMAX],int *min,int count){
  rep(r,4){
    int nx=sx,ny=sy;
    if(map[nx+dd[r]][ny+dd[r+1]]==1)
      continue;
    while(0<=nx+dd[r] && nx+dd[r]<w && 0<=ny+dd[r+1] && ny+dd[r+1]<h){
      nx+=dd[r];
      ny+=dd[r+1];
      if(map[nx][ny]==3)
	if(*min > count){
	  *min = count;
	  break;
	}
      if(map[nx][ny]==1){
	break;
      }
    }

    if(map[nx][ny]==1 && count <10){
      map[nx][ny]=0;
      nx-=dd[r];ny-=dd[r+1];
      dfs_aux(nx,ny,map,min,count+1);
      nx+=dd[r];ny+=dd[r+1];
      map[nx][ny]=1;
    }
  }
}

int dfs(int sx, int sy, int map[WMAX][HMAX]){
  int min=11;
  dfs_aux(sx,sy,map,&min,1);
  if(min>10)
    return -1;
  return min;
}

int main(){
  for(;;){
    scanf("%d %d",&w,&h);
    if(!(w+h)) break;
    int map[WMAX][HMAX],sx,sy;
    rep(i,h){
      rep(j,w){
	scanf("%d",&map[j][i]);
	if(map[j][i]==2){
	  sx=j;
	  sy=i;
	}
      }
    }
    printf("%d\n",dfs(sx,sy,map));
  }
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define pll pair<ll,ll>
#define v vector<ll>
#define st stack<ll>
#define pq  priority_queue <int>
#define q queue<ll>
#define mod 1000000005
using namespace std;
 char ch[1000000];
int main(){
    int n;
    cin>>n;
    cout<<n/3<<endl;
    return 0;
   }

//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

signed main(void)
{
  int n;
  cin >> n; cin.ignore();
  REP(i, n) {
    string s;
    getline(cin, s);
    FOR(j, 6, s.size()) {
      if(s.substr(j-6, 7) == "Hoshino") s[j] = 'a';
    }
    cout << s << endl;
  }

  return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <functional>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <unordered_map>
#include <cstdio>
#include <climits>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long ll;

ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}
ll kai(ll x, ll y, ll m) {
	ll res = 1;
	for (ll i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
ll mod_pow(ll x, ll y, ll m) {
	ll res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

ll comb(ll x, ll y, ll m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

string s, t;
int k;
int d[310][310][310];

signed main() {
	std::random_device rnd;
	std::mt19937_64 mt(rnd());
	cin >> s >> k;
	t = s;
	reverse(all(t));
	int n = (int)s.size();
	for (int i = 0; i < n; i++)for (int j = 0; j < n; j++) {
		if (n <= i + j)continue;
		for (int l = 0; l <= k; l++)d[i + 1][j + 1][l] = max(d[i][j + 1][l], d[i + 1][j][l]);
		if (s[i] == t[j])for (int l = 0; l <= k; l++)d[i + 1][j + 1][l] = max(d[i + 1][j + 1][l], d[i][j][l] + 1);
		else for (int l = 0; l < k; l++)d[i + 1][j + 1][l + 1] = max(d[i + 1][j + 1][l + 1], d[i][j][l] + 1);
	}
	int ans = 0;
	for (int i = 0; i <= n; i++)for (int j = 0; j <= n; j++) {
		if (n <= i + j - 2)continue;
		int ma = 0;
		for (int l = 0; l <= k; l++)ma = max(ma, d[i][j][l]);
		if (i + j == n + 1)ans = max(ans, 2 * ma - 1);
		else ans = max(ans, 2 * ma);
	}
	cout << ans << endl;
}

#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = 998244353;

int  N, M;
long long dat[2000009];

long long quickpow(long long b, long long e)
{
	return e ? ((e & 1 ? b : 1)*quickpow((b*b) % MOD, e >> 1)) % MOD : 1;
}

long long combi(int n, int m)
{
	long long retval = dat[n];
	retval = retval * quickpow(dat[n - m], MOD - 2);
	retval = retval % MOD;
	retval = retval * quickpow(dat[m], MOD - 2);
	retval = retval % MOD;
	return retval;
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> N >> M;
	dat[0] = 1;
	for (int i = 1; i < 2000009; i++) {
		dat[i] = dat[i - 1] * i;
		dat[i] = dat[i] % MOD;
	}
	int lb = min(N, M);
	long long ans = 0, tmp;
	for (int i = 0; i <= lb; i++) {
		if (3 * M - i >= 0 && (3 * M - i) % 2 == 0) {
			tmp = combi((3 * M - i) / 2 + N - 1, N - 1);
			tmp = tmp * combi(N, i);
			tmp = tmp % MOD;
			ans += tmp;
			ans = ans % MOD;
		}
	}
	tmp = combi(M + N - 1, N - 1);
	tmp = tmp + MOD - combi(M + N - 2, N - 2);
	tmp = tmp * N;
	tmp = tmp % MOD;
	ans = ans + MOD - tmp;
	ans = ans % MOD;
	cout << ans << E;
	//system("pause");
	return 0;
}


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

int main()
{
  string s;
  cin >> s;
  if (s.length() == 2)
  {
    if (s[0] == s[1])
    {
      cout << 1 << " " << 2 << endl;
      return 0;
    }
  }
  for (int i = 0; i < s.length() - 2; i++)
  {
    if (s[i] == s[i + 2])
    {
      cout << i + 1 << " " << i + 3 << endl;
      return 0;
    }
    else if (s[i] == s[i + 1])
    {
      cout << i + 1 << " " << i + 2 << endl;
      return 0;
    }
    else if (s[i + 1] == s[i + 2])
    {
      cout << i + 2 << " " << i + 3 << endl;
      return 0;
    }
  }
  cout << -1 << " " << -1 << endl;
}

#define LOCAL
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;

#define rep(i,s,n) for (int i = (ll)s; i < (ll)n; i++)
#define rrep(i,n,e) for (int i = (ll)n; i > (ll)e; i--)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // dist between two elements
// #define M_PI 3.14159265358979323846 // CF
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) cout << fixed << setprecision(10) << x << endl; // 小数点を10桁まで表示
#define endl "\n"
#define Case(x) printf("Case #%d: ", x); // gcj

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<char> vch;
typedef vector<vector<char>> vvch;

constexpr ll LINF = 1001002003004005006ll;
constexpr int INF = 1001001001;
constexpr int n_max = 2e5+10;

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

template<class T, class U>
T POW(T x, U n) {T ret=1; while (n>0) {if (n&1) {ret*=x;} x*=x; n>>=1;} return ret;};

// debug
template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';};
string to_string(const char c) {return to_string((string) &c);};
string to_string(bool b) {return (b ? "true" : "false");};
template <size_t N>
string to_string(bitset<N> v){
  string res = "";
  for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
  return res;
};
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for(const auto &x : v) {
    if(!first) res += ", ";
    first = false; res += to_string(x);
  }
  res += "}";
  return res;
};
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

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

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

void print() { cout << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
};

template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
};

template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
    print(vec);
  }
};

PI solve(string &s) {
  int n = s.size();
  vvi table(26);
  rep(i, 0, 26) {
    char ch = 'a'+i;
    rep(j, 0, n) {
      if (s[j] == ch) table[i].pb(j);
    }
  }

  rep(i, 0, 26) {
    rep(j, 0, table[i].size()-1) {
      if (table[i][j+1]-table[i][j] < 3) {
        return make_pair(table[i][j]+1,table[i][j+1]+1);
      }
    }
  }

  return make_pair(-1, -1);
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s; cin >> s;
  PI ans = solve(s);
  cout << ans.first << " " << ans.second << endl;

  return 0;
};


		#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <climits>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define in insert
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define f first
#define s second
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define int ll
#define sz(x) (ll)x.size()
#define all(x) (x.begin(),x.end())
using namespace std;

const ll INF = 1e12;
const ll N =(1e5+5); // TODO : change value as per problem
const ll MOD = 1e9+7;

void solve(){
	string s;
	cin >> s;
	int ans = 0;
	map<char,int> m;
	for(int i =s.size()-1;i>=0;i--){
		for(char c = 'a';c<='z';c++){
			if(c != s[i]){
				ans += m[c];
			}
		}
		m[s[i]]++;
	}
	ans++;
	cout << ans << endl;
}
signed main(){

    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
     // freopen(".in","r",stdin);freopen(".out","w",stdout);

     ll tt=1;
     // cin >> tt;
    while(tt--){
        solve();
    }
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <fstream>
#include <unordered_map>
#include <math.h>
#define MOD 1000000007

using namespace std;

ifstream fin("../data.txt");

int x;

unordered_map<int, long long> factorization(int x) {
  unordered_map<int, long long> factors;
  while(x % 2 == 0) {
    factors[2]++;
    x /= 2;
  }

  for (int i = 3; i <= sqrt(x); i++) {
    while(x % i == 0) {
      factors[i]++;
      x /= i;
    }
  }

  if (x != 1) factors[x]++;
  // for (auto aux : factors) {
  //   cout << "(" <<  aux.first << ", " << aux.second << ") ";
  // }
  // cout << "\n";
  return factors;
}

int main() {

  cin >> x;
  unordered_map<int, long long> factors;
  for (int n = 2; n <= x; n++) {
    unordered_map<int, long long> currFactors = factorization(n);
    for (auto aux : currFactors) {
      factors[aux.first] += aux.second;
    }
  }

  long long ans = 1;
  for (auto aux : factors) {
    ans *= (aux.second + 1LL);
    ans %= MOD;
  }

  cout << ans;

  return 0;
}


#include<iostream>
#include<algorithm>
#include<cstring>

using namespace std;

typedef pair<int,int> P;
const int MAX = 120;

int maze[MAX][MAX];
bool come[MAX][MAX];
P s,g;
int W,H,c;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};

void init(){
  memset(come,false,sizeof(come));
  memset(maze,0,sizeof(maze));
}

void input_B(){
  int n;
  cin >> n;
  while(n--){
    int c,d,x,y;
    cin >> c >> d >> x >> y;
    if(d){
      for(int i = y; i < y+4; i++)
	for(int j = x; j < x+2; j++)
	  maze[i][j] = c;
    }else{
      for(int i = y; i < y+2; i++)
	for(int j = x; j < x+4; j++)
	  maze[i][j] = c;
    }
  }
}

void solve(P p){

  if(come[p.second][p.first] == false){
    come[p.second][p.first] = true;
    for(int i = 0; i < 4; i++)
      if(0 < p.first+dx[i] && p.first+dx[i] <= W &&
	 0 < p.second+dy[i] && p.second+dy[i] <= H &&
	 maze[p.second+dy[i]][p.first+dx[i]] == c) solve(P(p.first+dx[i],p.second+dy[i]));
  }
}

void print(){
  for(int i = 1; i < H; i++){
    for(int j = 1; j < W; j++)// cout << come[i][j];
      cout << maze[i][j];
    cout << endl;
  }

}

int main(){
  while(cin >> W >> H && W+H){
    init();
    cin >> s.first >> s.second;
    cin >> g.first >> g.second;
    input_B();
    c = maze[s.second][s.first];
    solve(s);
    //print();
    if(come[g.second][g.first] && c) cout << "OK" << endl;
    else cout << "NG" << endl;
  }
  return 0;
}

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

const int LLINF = 1LL << 60;

char ch[] = "ENWS";
int mx[] = {1, 0, -1, 0};
int my[] = {0, 1, 0, -1};

signed main()
{
  int N, M;
  while(cin >> N, N) {

    bool mas[25][25] = {0};
    int A, B; char C;
    int x, y, cnt = 0; x = y = 10;

    Rep(i, N) {
      cin >> A >> B; mas[B][A] = true;
    }
    if(mas[10][10]) mas[10][10] = false, cnt++;
    cin >> M;
    while(M--) {
      cin >> C >> A;
      Rep(i, 4) {
	if(C == ch[i]) {
	  Rep(j, A) {
	    y += my[i], x += mx[i];
	    if(mas[y][x]) mas[y][x] = false, cnt++;
	  }
	}
      }
    }

    if(cnt == N) cout << "Yes" << endl;
    else cout << "No" << endl;

  }
  return 0;
}


///
// File:  grl_1_c.cpp
// Author: ymiyamoto
//
// Created on Thu Oct 19 23:14:36 2017
//

#include <cstdint>
#include <iostream>

using namespace std;

#define SIZE 100
#define INF INT32_MAX

static int64_t graph[SIZE][SIZE];

int32_t main()
{
  uint32_t V, E;
  cin >> V >> E;

  for (uint32_t i = 0; i < V; i++) {
    for (uint32_t j = 0; j < V; j++) {
      if (i == j)
        graph[i][j] = 0;
      else
        graph[i][j] = INF;
    }
  }

  for (uint32_t i = 0; i < E; i++) {
    int64_t s, t, d;
    cin >> s >> t >> d;
    graph[s][t] = d;
  }

  for (uint32_t k = 0; k < V; k++) {
    for (uint32_t i = 0; i < V; i++) {
      for (uint32_t j = 0; j < V; j++) {
        if (graph[i][k] == INF || graph[k][j] == INF) continue;
        if (graph[i][k] + graph[k][j] < graph[i][j]) {
          graph[i][j] = graph[i][k] + graph[k][j];
        }
      }
    }
  }

  for (uint32_t i = 0; i < V; i++) {
    if (graph[i][i] < 0) {
      cout << "NEGATIVE CYCLE" << endl;
      return 0;
    }
  }

  for (uint32_t i = 0; i < V; i++) {
    for (uint32_t j = 0; j < V; j++) {
      if (j != 0) cout << " ";
      if (graph[i][j] == INT32_MAX) {
        cout << "INF";
      } else {
        cout << graph[i][j];
      }
    }
    cout << endl;
  }

  return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
    int h, w;
    cin >> h >> w;
    map<int, int> m;
    multiset<int> v;
    for(int i = 0; i < w; i++)
        m[i] = i;
    for(int i = 0; i < w; i++)
        v.insert(0);
    for(int i = 0; i < h; i++){
        int a, b;
        cin >> a >> b;
        a--;
        auto it = m.lower_bound(a);
        int mm = -1;
        while(it != m.end() && it->first <= b){
            mm = max(mm, it->second);
            int x = it->first - it->second;
            v.erase(v.find(x));
            m.erase(it++);
        }
        if(mm != -1 && b < w){
            v.insert(b - mm);
            m[b] = mm;
        }
        int ans = -1;
        if(v.size() > 0)
            ans = *v.begin() + (i + 1);
        cout << ans << endl;
    }
    return 0;
}


/*
 * @Author: Kaizyn
 * @Date: 2020-08-29 19:57:44
 * @LastEditTime: 2020-08-30 10:24:35
 */
#include <bits/stdc++.h>

// #define DEBUG

using namespace std;

const int N = 2e5+7;
const int INF = 0x3f3f3f3f;

struct SegmentTree {
  struct TreeNode {
    int l, r, v, lazy;
  } tr[N<<2];
  void push_down(int i) {
    if (!tr[i].lazy) return;
    tr[i<<1].lazy = tr[i<<1|1].lazy = tr[i].lazy;
    tr[i<<1].v = tr[i<<1].l-tr[i].lazy;
    tr[i<<1|1].v = tr[i<<1|1].l-tr[i].lazy;
    tr[i].lazy = 0;
  }
  void build(int l, int r, int i = 1) {
    tr[i].l = l; tr[i].r = r;
    if (l == r) return;
    int mid = (l+r)>>1;
    build(l, mid, i<<1);
    build(mid+1, r, i<<1|1);
  }
  void update(int l, int r, int k, int i = 1) {
    if (l <= tr[i].l && r >= tr[i].r) {
      tr[i].v = tr[i].l-k;
      tr[i].lazy = k;
      return;
    }
    push_down(i);
    int mid = (tr[i].l+tr[i].r)>>1;
    if (l <= mid) update(l, r, k, i<<1);
    if (r >  mid) update(l, r, k, i<<1|1);
    tr[i].v = min(tr[i<<1].v, tr[i<<1|1].v);
  }
  int query(int x, int i = 1) {
    if (tr[i].l == tr[i].r) return tr[i].l-tr[i].v;
    push_down(i);
    int mid = (tr[i].l+tr[i].r)>>1;
    if (x <= mid) return query(x, i<<1);
    else return query(x, i<<1|1);
  }
};

int n, m;
SegmentTree seg;

signed main() {
  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  cin >> n >> m;
  seg.build(1, m);
  for (int i = 1, l, r; i <= n; ++i) {
    cin >> l >> r;
    if (l == 1) seg.update(l, r, -INF);
    else seg.update(l, r, seg.query(l-1));
    cout << (seg.tr[1].v > m ? -1 : seg.tr[1].v+i) << endl;
  }
  return 0;
}

#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define ppll pair<ll,pll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
// #define ll int
using namespace std;
const ll INF = 1 << 29;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const int MAX_V = 500;
// const ll mod = 998244353;
const ll MAX = 2100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[8] ={1,0,-1,0,1,-1,1,-1};
ll dy[8] ={0,1,0,-1,1,-1,-1,1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template< class flow_type >
struct Dinic {
    const flow_type inf;
    struct edge {
        int to;
        flow_type cap;
        int rev;
        edge(int to, flow_type cap, int rev) : to(to), cap(cap), rev(rev) {}
    };

    vector < vector < edge > > graph;
    vector < int > level, iter;

    Dinic(int V) : inf(numeric_limits< flow_type >::max()/2), graph(V) {}

    void add_edge(int from, int to, flow_type cap) {

        graph[from].emplace_back(to, cap, (int)graph[to].size());
        graph[to].emplace_back(from, 0, (int)graph[from].size() - 1);
    }

    void bfs(int source) {
        level.assign(graph.size(), -1);
        queue<int> que;
        que.push(source);
        level[source] = 0;
        while(!que.empty()) {
            int v = que.front(); que.pop();
            for(int i = 0; i < (int)graph[v].size(); i++) {
                edge &e = graph[v][i];
                if(e.cap > 0 && level[e.to] < 0) {
                    level[e.to] = level[v] + 1;
                    que.push(e.to);
                }
            }
        }
    }

    flow_type dfs(int v, int  sink, flow_type f) {
        if(v == sink) return f;
        for(int &i = iter[v]; i < (int)graph[v].size(); i++){
            edge &e = graph[v][i];
            if(e.cap > 0 && level[v] < level[e.to]) {
                flow_type d = dfs(e.to, sink, min(e.cap, f));
                if (d > 0) {
                    e.cap -= d;
                    graph[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }

    flow_type max_flow(int source, int sink) {
        flow_type flow = 0;
        while(true) {
            bfs(source);
            if(level[sink] < 0) return flow;
            iter.assign(graph.size(), 0);
            flow_type f;
            while((f = dfs(source, sink, inf)) > 0) flow += f;
        }
    }

};

void solve() {
    int n;
    cin>>n;
    Dinic<int> din(n*2+2);
    int a[110],b[110],c[110],d[110];
    rep(i,n) cin>>a[i]>>b[i];
    rep(i,n) cin>>c[i]>>d[i];
    rep(i,n) din.add_edge(0,i+1,1);
    rep(j,n) din.add_edge(n+j+1,2*n+1,1);
    rep(i,n){
        rep(j,n){
            if(a[i]<c[j]&&b[i]<d[j]){
                din.add_edge(i+1,n+j+1,1);
            }
        }
    }
    cout<<din.max_flow(0,2*n+1)<<endl;

}

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

    solve();

    return 0;
}


#include<bits/stdc++.h>
using std::cout;
using std::cin;
using std::endl;

std::vector<std::string> split(const std::string &str, char sep)
{
    std::vector<std::string> v;
    std::stringstream ss(str);
    std::string buffer;
    while( std::getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

int Stoi(const std::string &str)
{
    int num=0, i=0;
    std::string s = str;
    while (i<s.size())
    {
        if (s[i]<'0'||s[i]>'9')
            break;
        num = num * 10 + (str[i] - '0');
        i++;
    }

    return num;
}

std::string replace(const std::string &str1, int a, int b, const std::string &str2)
{
    std::string s1, s2;
    s1 = str1; s2 = str2;

    s1 = s1.erase(a, b-a+1);
    //cout << s1 << endl;
    s1 = s1.insert(a, s2);
    //cout << s1 << endl;
    return s1;
}

int main(){
    int a, b, count=1;
    long long n;
    std::string str, line, doubt, s;
    cin >> str;
    cin >> n;
    std::getline(cin, doubt);

    std::vector<std::string> Priope, v;
    std::vector<int> num(n);

    for (int i = 0; i < n; i++)
    {
        std::getline(cin, line);
        v = split(line, ' ');

        a = Stoi(v[1]); b = Stoi(v[2]);

        if (v[0] == "print")
        {
            s = str.substr(a, b-a+1);
            Priope.push_back(s);
            num.push_back(i);
            //cout << s << endl;
        }
        else if (v[0] == "reverse")
            {std::reverse(str.begin()+a, str.begin()+b+1); }//cout << str << endl;}
        else if(v[0] == "replace")
            str = replace(str, a, b, v[3]);
        else
        {
            cout << "Wrong Command:" << v[0] << endl;
            i--;
        }

    }
/*
    for (int i = 0; i < num.size(); i++)
        cout << Priope(i) << endl;
*/
    std::vector<std::string>::iterator itr;
    itr = Priope.begin();
    while (itr != Priope.end())
    {
        cout << *itr << endl;
        itr++;
    }

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define MN 200005
#define LL long long
#define mp make_pair
#define fir first
#define sec second
#define pii pair<int,int>
inline void chkmax(int &a,int b){if(a<b)a=b;}
inline void chkmin(int &a,int b){if(a>b)a=b;}
inline int read(){
	   int a=0,fh=1;char c=getchar();
	   while(c>'9'||c<'0'){if(c=='-')fh=-1;c=getchar();}
	   while('0'<=c&&c<='9'){
		   a=a*10+c-48;
		   c=getchar();
	   }
	   return a*fh;
}
const int py=6005;
int f[6005][16005],n,Mod;
void add(int &a,int b){((a+=b)>=Mod)?(a-=Mod):0;}
int main(){
	n=read()*3;Mod=read();
	f[0][py]=1;
	for(int i=0;i<n;++i){
		for(int j=-i;j<=i;++j){
			add(f[i+1][j+py+1],f[i][j+py]);
			add(f[i+2][j+py-1],(LL)f[i][j+py]*(i+1)%Mod);
			add(f[i+3][j+py],(LL)f[i][j+py]*(i+1)*(i+2)%Mod);
		}
	}
	LL ans=0;
	for(int i=0;i<=n;++i)ans+=f[n][i+py];
	printf("%lld\n",ans%Mod);
	return 0;
}


#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);

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

  int l = max(-1000000, x-(k-1));
  int r = min(100000, x+(k-1));

  for(int i = l; i <= r ; ++i){
    cout << i << " ";
  }
  cout << endl;
  return 0;
}

#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (int i=0; i<n; ++i)
#define all(obj) (obj).begin(),(obj).end()
using namespace std;
typedef long long ll;
long long GCD(long long x, long long y) { return y ? GCD(y, x%y) : x; }

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

}


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

struct SCC {
    int n;
    vector<vector<int>>& G;
    vector<vector<int>> G_rev;
    vector<int> comp, order;
    vector<bool> visited;

    SCC(vector<vector<int>>& G) : G(G), n(G.size()) {
        comp.resize(n, -1);
        visited.resize(n);
        G_rev.resize(n);
        for (int u = 0; u < n; u++) {
            for (int v : G[u]) {
                G_rev[v].push_back(u);
            }
        }

        for (int v = 0; v < n; v++) dfs(v);
        reverse(order.begin(), order.end());
        int c = 0;
        for (int v : order) if (comp[v] == -1) rdfs(v, c++);
    }

    int operator[](int k) {
        return comp[k];
    }

    void dfs(int u) {
        if (visited[u]) return;
        visited[u] = true;
        for (int v : G[u]) dfs(v);
        order.push_back(u);
    }

    void rdfs(int u, int c) {
        if (comp[u] != -1) return;
        comp[u] = c;
        for (int v : G_rev[u]) rdfs(v, c);
    }
};

struct UnionFind {
    vector<int> par, rank, size;

    UnionFind(int n) {
        par.resize(n);
        for (int i = 0; i < n; i++) par[i] = i;
        rank.resize(n);
        size.resize(n, 1);
    }

    int find(int x) {
        if (par[x] == x) return x;
        return par[x] = find(par[x]);
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;

        if (rank[x] < rank[y]) {
            par[x] = y;
            size[y] += size[x];
        } else {
            par[y] = x;
            size[x] += size[y];
            if (rank[x] == rank[y]) rank[x]++;
        }
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

    int get_size(int x) {
        return size[find(x)];
    }
};

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

    int V, E;
    cin >> V >> E;
    vector<vector<int>> G(V);
    for (int i = 0; i < E; i++) {
        int s, t;
        cin >> s >> t;
        G[s].push_back(t);
    }
    SCC scc(G);
    UnionFind uf(2 * V);
    for (int i = 0; i < V; i++) uf.unite(i, V + scc[i]);
    int Q;
    cin >> Q;
    for (int i = 0; i < Q; i++) {
        int u, v;
        cin >> u >> v;
        cout << (uf.same(u, v) ? 1 : 0) << '\n';
    }
}

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace __gnu_pbds;
using namespace __gnu_cxx;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the iterator to kth largest element.(0-based)
typedef long long int lli;
#define pb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pair<int,int>>
#define vc vector<char>
#define vs vector<string>
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define fastio	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
/*-------CONSTANTS------- */
const int MAXN = 1000005;
const int SQRTN = 1003;
const int LOGN = 22;
const double PI=acos(-1);
const int INF = 1000000000;
const int MOD = 1000000007;
const int FMOD = 998244353;
const double eps = 1e-9;
/*-----------------------------MATH STUFF----------------------------- */
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
int mod_neg(int a, int b, int c){int res;if(abs(a-b)<c)res=a-b;else res=(a-b)%c;return(res<0?res+c:res);}
int mulmod(int a, int b, int c){lli res=(lli)a*b;return(res>=c?res%c:res);}
template<typename T>T power_mod(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mulmod(x,p,m);p=mulmod(p,p,m);n>>=1;}return x;}
template<typename T>T extended_euclid(T a, T b, T &x, T &y){T xx=0,yy=1;y=0;x=1;while(b){T q=a/b,t=b;b=a%b;a=t;\
t=xx;xx=x-q*xx;x=t;t=yy;yy=y-q*yy;y=t;}return a;}
template<typename T>T mod_inverse(T a, T n){T x,y,z=0;T d=extended_euclid(a,n,x,y);return(d>1?-1:mod_neg(x,z,n));}
//Factorials upto 1e5%MOD,nCr%MOD,nPr%MOD
lli fact[100000+5],fact_modinv[100000+5];
void fact_init(){
    fact[0] = 1ll;
    fact_modinv[0] = mod_inverse(fact[0],1ll*MOD);
    for(int i = 1;i<=100000;i++){
        fact[i] = mulmod(fact[i-1],i,1ll*MOD);
        fact_modinv[i] = mod_inverse(fact[i],1ll*MOD);
    }
}
lli choose(int n,int r){
    return mulmod(fact_modinv[n-r],mulmod(fact[n],fact_modinv[r],MOD),MOD);
}
lli P(int n,int r){
    return mulmod(fact[n],fact_modinv[n-r],1ll*MOD);
}
/*-----------------------------START----------------------------- */

int n,m;
vector<int> g[10000+5],gr[10000+5];
vector<int> topo;
bool visited1[10000+5],visited2[10000+5];
vector<int> scc[10000+5];
int par[10000+5];
void dfs(int u){
    visited1[u] = true;
    for(auto x : g[u])
        if(!visited1[x])
            dfs(x);

    topo.push_back(u);
}

void dfs2(int u,int p){
    visited2[u] = true;
    par[u] = p;

    for(auto x : gr[u])
        if(!visited2[x])
            dfs2(x,p);
}
int main(){
    fastio;
    cin>>n>>m;
    for(int i = 0;i<m;i++){
        int u,v;
        cin>>u>>v;
        g[u].pb(v);
        gr[v].pb(u);
    }
    for(int i = 0;i<n;i++)
        if(!visited1[i])
            dfs(i);

    reverse(topo.begin(),topo.end());

    for(auto x : topo)
        if(!visited2[x])
            dfs2(x,x);

    int q;cin>>q;
    while(q--){
        int u,v;
        cin>>u>>v;
        cout<<(par[u] == par[v])<<endl;
    }

    return 0;
}


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

const int INF = 1000000000;
int n, k;
vector<P> way[128];

int query(int a, int b);

int main()
{
	while (scanf("%d %d", &n, &k), n != 0){
		for (int i = 1; i <= n; i++) way[i].clear();
		while (k-- > 0){
			int mode;
			scanf("%d", &mode);

			if (mode == 0){
				int a, b;
				scanf("%d %d", &a, &b);
				int cost = query(a, b);
				if (cost == INF) puts("-1");
				else printf("%d\n", cost);
			}
			else {
				int c, d, e;
				scanf("%d %d %d", &c, &d, &e);
				way[c].push_back(P(e, d));
				way[d].push_back(P(e, c));
			}
		}
	}

	return 0;
}

int query(int a, int b)
{
	static int mini[128];
	for (int i = 1; i <= n; i++) mini[i] = INF;

	priority_queue<P> q;
	q.push(P(0, a));
	mini[a] = 0;
	while (!q.empty()){
		P p = q.top(); q.pop();

		if (mini[p.second] < p.first) continue;
		for (int i = 0; i < way[p.second].size(); i++){
			P tmp = way[p.second][i];

			if (mini[tmp.second] > mini[p.second] + tmp.first){
				mini[tmp.second] = mini[p.second] + tmp.first;
				q.push(tmp);
			}
		}
	}

	return mini[b];
}


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

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

  bool f[10] = {};
  int num[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
  for (int i = 0; i < M; i++) {
    int A;
    cin >> A;
    f[A] = true;
  }
  vector<int> dp(N + 1, -1);
  dp[0] = 0;
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j < 10; j++) {
      if (!f[j] || i - num[j] < 0 || dp[i - num[j]] == -1) continue;
      dp[i] = max(dp[i], dp[i - num[j]] + 1);
    }
  }
  for (int i = N; i > 0;) {
    for (int j = 9; j >= 1; j--) {
      if (f[j] && i - num[j] >= 0 && dp[i] == dp[i - num[j]] + 1) {
        cout << j;
        i -= num[j];
        break;
      }
    }
  }
}

#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=105;
int n,m,a[maxn],b[maxn];
inline char nc(){
	static char buf[100000],*p1,*p2;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline int read(){
	int ret=0;bool f=0;char ch=nc();
	while(ch>'9'||ch<'0') f^=ch=='-',ch=nc();
	while(ch<='9'&&ch>='0') ret=ret*10+ch-'0',ch=nc();
	return f?-ret:ret;
}
int main(){
	n=read(),m=read();
	for (int i=1;i<=m;i++) a[i]=read();
	for (int i=2;i<=m;i++)
	if(a[i]&1) swap(a[i],a[1]);
	for (int i=m-1;i>1;i--)
	if(a[i]&1) swap(a[i],a[m]);
	for (int i=2;i<m;i++)
	if(a[i]&1) return puts("Impossible")&0;
	for (int i=1;i<=m;i++)
	printf("%d",a[i]),putchar(i==m?'\n':' ');
	if(a[1]>1) b[++b[0]]=a[1]-1;
	for (int i=2;i<m;i++) b[++b[0]]=a[i];
	if(m>1){
		b[++b[0]]=2;
		if(a[m]>1) b[++b[0]]=a[m]-1;
	}else b[++b[0]]=1;
	for (int i=0;i<=b[0];i++)
	printf("%d",b[i]),putchar(!i||i==b[0]?'\n':' ');
	return 0;
}


#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main()
{
  int n,t;
  cin>>n>>t;
  vector<vecint> dp(n+1, vecint(t+3001, 0));
  vector<tuple<int,int>> vt;
  for(int i:irange(0,n)) {
    int a,b;
    cin>>a>>b;
    vt.emplace_back(a,b);
  }
  boost::sort(vt);
  for(int i:irange(0,n)) {
    int a,b;
    tie(a,b) = vt[i];
    for(int j:irange(0,t+3001)) {
      dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
      if (j < t) {
        dp[i+1][j+a] = max(dp[i+1][j+a], dp[i][j] + b);
      }
    }
  }
  cout<<*boost::max_element(dp[n])<<endl;
  return 0;
}

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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
#define fs first
#define sc second
// 多倍長
#include <boost/rational.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using boost::rational;
using boost::multiprecision::cpp_int;

const int INF = 1e9;
const ll LLINF = 1e16;
const ll MOD = 1e9+7;
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}

// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;

int dp[3100][3100];

int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int n,t;
    cin >> n >> t;
    vector<pint> p(n);
    rep(i, n){
        cin >> p[i].fs >> p[i].sc;
    }
    sort(all(p));
    int ans = 0;
    rep(i, n){
        rep(j, t){
            chmax(dp[i + 1][j], dp[i][j]);
            if(j < p[i].fs) continue;
            chmax(dp[i + 1][j], dp[i][j - p[i].fs] + p[i].sc);
        }
        int now = dp[i][t - 1] + p[i].sc;
        chmax(ans, now);
    }
    print(ans);

}


#include <bits/stdc++.h>

#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define irrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define irrep2(i,n,a) for(int i = (int)(n); i >= (int)(a); i--)

#define fi first
#define se second

using namespace std;

using ll = long long;
using v_int = vector<int>;
using v2_int = vector<v_int>;
using v_ll = vector<ll>;
using v2_ll = vector<v_ll>;
using v_string = vector<string>;
using v_bool = vector<bool>;
using v2_bool = vector<v_bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

const double PI = 3.1415926535897932;
const int INF = (int)2e9;
const ll LINF = (ll)2e18;
const ll MOD = 1000000007;
const int dc[8] = {1, -1, 0,  0, 1, -1,  1, -1};
const int dr[8] = {0,  0, 1, -1, 1,  1, -1, -1};

template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p) {
    return o << "{" << p.first << "," << p.second << "}";
}
template<typename T> inline
istream& operator>>(istream &is, vector<T> &vec) {
    for(auto &v : vec) { is >> v; }
    return is;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<T> &vec) {
    for(auto &v : vec) { os << v << ",";}
    return os;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<vector<T> > &mat) {
    for(auto &row : mat) { os << row << endl; }
    return os;
}
template<typename T> inline
void chmin(T &a, T b) { a = min(a, b); }
template<typename T> inline
void chmax(T &a, T b) { a = max(a, b); }

void binary(int &l, int &r, v_int & v, int u)
{
    while(r-l>1) {
        int mid = (r+l)/2;
        if(v[mid] > u) {
            r = mid;
        } else {
            l = mid;
        }
    }
}

void binary2(int &l, int &r, v_int & v, int u)
{
    while(r-l>1) {
        int mid = (r+l)/2;
        if(v[mid] >= u) {
            r = mid;
        } else {
            l = mid;
        }
    }
}

int main(void)
{
    int n;
    cin >> n;

    v_int a(n), b(n), c(n);
    cin >> a >> b >> c;
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());

    ll ans = 0;

    irep(i, n) {
        int la = -1, ra = n;
        binary2(la, ra, a, b[i]);
        if(la == -1) { continue; }

        int lc = -1, rc = n;
        binary(lc, rc, c, b[i]);
        if(rc == n) { continue; }

        ans += (ll)(la+1) * (n-rc);
    }
    cout << ans << endl;
    return 0;
}

/*atcoder*/

// https://atcoder.jp/contests/abc077/tasks/arc084_a
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<int> A(N), B(N), C(N);
    REP(i, N) cin >> A[i];
    REP(i, N) cin >> B[i];
    REP(i, N) cin >> C[i];
    sort(ALL(A));
    sort(ALL(B));
    sort(ALL(C));

    int ans = 0;
    for (auto &x : B) {
        // 配列Aからxより小さい値を探す
        auto ia = lower_bound(ALL(A), x);
        int a = ia - A.begin();
        // 配列Cからxより大きい値を探す
        auto ic = lower_bound(ALL(C), x + 1);
        int c = C.end() - ic;
        ans += a * c;
    }
    cout << ans << endl;

    return 0;
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

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

const ll INF=1e9+7;

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

#if __has_include("debug.h")
    #include "debug.h"
#else
#include <bits/stdc++.h>
using namespace std;
#define d(...) 2;
#endif

#define int long long int

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"

#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ff first
#define ss second
#define eps 1e-10

#define gcd(a,b)            __gcd((a),(b))
#define lcm(a,b)            ((a*b)/gcd(a,b))

void solve();

int32_t main()
{
    #ifdef DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    #endif

    fast

    int t = 1;
	// cin>>t;

	while(t--)
	    solve();
	return 0;
}

void solve()
{
	int i,j;
	cin>>i>>j;
	cout<<i*j<<endl;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,x,y,z;
    cin>>a>>b;
    x=a+b;
    y=a-b;
    z=a*b;
    if(x>=y && x>=z)
    {
        cout<<x<<endl;
    }
    else if(y>=x && y>=z)
    {
        cout<<y<<endl;
    }
    else
    {
        cout<<z<<endl;
    }
    return 0;
}

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

int main() {
  int a,b;
  cin>>a>>b;
  int x=a+b,y=a-b,z=a*b;
  int A=max(x,max(y,z));
  cout<<A<<endl;
}


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

ll fastpower (ll b , ll p){
    ll k= p%2 ? b : 1 ;
    return p==0 ? 1 : k*(fastpower(b*b,p/2));
}

ld dp[305][305][305];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n;
	cin>>n;
	ll cnt[4]={0,0,0,0};
	ll x;
	for(int i=0;i<n;i++){
		cin>>x;
		cnt[x]++;
	}
	dp[0][0][0]=0;
	for(ll three=0;three<=n;three++){
		for(ll two=0;two<=n;two++){
			for(ll one=0;one<=n;one++){
				ld i=three,j=two,k=one;
				ll zero=n-two-three-one;
				ld zero1=zero,n1=n;
				if(zero<0 || zero==n) continue;
				ld value=1.0;
				if(three>0) value+=(i/n1)*dp[three-1][two+1][one];
				if(two>0) value+=(j/n1)*dp[three][two-1][one+1];
				if(one>0) value+=(k/n1)*dp[three][two][one-1];
				//dp[three][two][one]=(value)/(1-1.0*zero/n);
				dp[three][two][one]=(value*n1)/(i+j+k);
			}
		}
	}
	ld ans=dp[cnt[3]][cnt[2]][cnt[1]];
	cout.precision(20);
	cout<<ans;
}

#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int len;
    cin >> len;
    string s, t;
    cin >> s >> t;
    int slen = s.size(), tlen = t.size();
    for (; len > 0; len--) {
        int si = slen - len;
        int ti = 0;
        if (s.substr(si, len) == t.substr(ti, len)) {
            break;
        }
    }

    cout << s.size() * 2 - len << '\n';
}


#include <iostream>
#include <cstdlib>
#include <time.h>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <array>
#include <string>
using namespace std;

typedef long long int ll;

int main(){
	cin.sync_with_stdio(false);
	cin.tie(0);
	ll t;
	cin >> t;
	if(t < 1200)
		cout << "ABC";
	else if(t < 2800)
		cout << "ARC";
	else
		cout << "AGC";
	return 0;
}

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

int main(){
    int n,m;
    cin >> n;
    int r1,r2,r3;
    for(int i=0; i<999;i++){
        m = n;
       r1 = (n%10);
       n-=r1;
       n/=10;
       r2 = (n%10);
       n-=r2;
       n/=10;
       r3 = (n%10);
       n-=r2;
       if( r1 == r2 && r1 == r3){
           break;
       }
       m++;
       n=m;
    }
    cout << r1 << r2 << r3 << endl;
}


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

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

  double t=s.size();
  string a ;

  for(int i=0 ; i<(t/n) ; i++ ){
    a+=s.at(0+i*n);
  }

  cout << a << endl;
}

#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

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

void solve() {
    string s;
    int w;
    cin >> s;
    cin >> w;
    REP(i,s.size()) if(i%w == 0) cout << s[i];
    cout << endl;
}

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


#include<iostream>
using namespace std;

bool search(int);

int q,T[500];

int main(){

  int n,S[10000],counter=0;

  cin >>n;
  for(int i=0 ; i < n ; i++)cin >>S[i];

  cin >>q;
  for(int i=0 ; i < q ; i++)cin >>T[i];

  for(int i=0 ; i < n ; i++)counter+=search(S[i]);

  cout <<counter<<endl;

  return 0;
}

bool search(int s){

  for(int i=0 ; i < q ; i++){
    if( s == T[i] ){
      T[i]=-1;
      return 1;
    }
  }

  return 0;

}

#include <bits/stdc++.h>

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

using namespace std;
// using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef map<int, int> mpii;
typedef set<int> seti;

const int mxN = 2e5, iinf = 1e9 + 10, inf = 1e18 + iinf + 10, mod = 1000000007;
const ld pi = 4.0 * atanl(1.0), prec = .000001;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(c) c.begin(), c.end()
#define rall(c) c.end(), c.begin()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)

int n, m, t, a[mxN];

void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }

int main() {
  fast();
  cin >> n >> m;
  string s;
  cin >> s;
  if (s.size() < n + m + 1) {
    cout << "No";
    return 0;
  }
  if (s[n] != '-') {
    cout << "No";
    return 0;
  }
  for (int i = 0; i < s.size(); ++i) {
    if (i != n) {
      if (!isdigit(s[i])) {
        cout << "No";
        return 0;
      }
    }
  }
  cout << "Yes";

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B, M;
  cin >> A >> B >> M;
  vector<int> a(A);
  vector<int> b(B);
  for(int i = 0; i < A; i++) {
    cin >> a.at(i);
  }
  for(int i = 0; i < B; i++) {
    cin >> b.at(i);
  }
  int ans = 200000;
  for(int i = 0; i < M; i++) {
    int x, y, c;
    cin >> x >> y >> c;
    if(a.at(x - 1) + b.at(y - 1) - c < ans) {
      ans = a.at(x - 1) + b.at(y - 1) - c;
    }
    if(i == M - 1) {
      sort(a.begin(), a.end());
      sort(b.begin(), b.end());
      if(a.at(0) + b.at(0) < ans) {
        ans = a.at(0) + b.at(0);
      }
    }
  }
  cout << ans << endl;
}

#include<bits/stdc++.h>
using namespace std;
#define N 1001000
#define inf INT_MAX
inline int read()
{
    int s=0,w=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
    return s*w;
}
int n;
char a[N],b[N];
int pos[N],Ans,cnt,ans[N];
bool Chtholly=true;
int main()
{
    //freopen("game.in","r",stdin);
    //freopen("game.out","w",stdout);
    n=read();
    scanf("%s%s",a+1,b+1);
    int len=1;
    //while(a[len]==b[len])
    //for(int i=1;i<=n+10;i++) cout<<a[i]<<endl;
    while(a[len]==b[len]&&len<=n) len++;
    if(len==n+1) return puts("0"),0;
    int front=n+1,rear=n;
    int k=n+1;
    while(n)
    {
        int j=n;
        while(b[j-1]==b[n]&&j>=1) j--;
        k=min(k,j);
        while(a[k]!=b[n]&&k>=1) k--;
        if(!k) {Chtholly=false;break;}
        while(front<=rear&&pos[rear]-cnt>n) rear--;
        cnt++;
        front--;
        pos[front]=k+cnt;
        ans[front]=cnt;
        Ans=max(Ans,cnt-ans[rear]+1);
        n=j-1;
    }
    if(!Chtholly) {puts("-1");return 0;}
    printf("%d\n",Ans);
    return 0;
}


#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <complex>
#include <random>
#include <bitset>
#include <list>
// #include <prettyprint.hpp>
using namespace std;
#define repi(i,n) for(int i=0;i<n;++i)
#define rep(i,n) for(ll i=0;i<n;++i)
#define repinvi(i,n) for(int i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define sii(n) scanf("%d", &n);
#define slf(n) scanf("%lf", &n);
#define pll pair<ll,ll>
#define pii pair<int,int>
#define psi pair<si,si>
typedef long long ll;
typedef double lf;
typedef short int si;

void Main(){
    ll N, l;
    sll(N);
    // vector<ll> ls(N, 0);
    map<ll, ll> counter;
    rep(i, N){
        sll(l);
        counter[l] ++;
    }

    ll ans = 0;
    for(auto p1:counter){
        for(auto p2:counter){
            if(p1.first >= p2.first){
                continue;
            }
            for(auto p3:counter){
                if(p1.first >= p3.first){
                    continue;
                }else if(p2.first >= p3.first){
                    continue;
                }

                if(p3.first >= p1.first + p2.first){
                    continue;
                }

                ans += (p1.second * p2.second * p3.second);

            }
        }
    }

    cout << ans <<endl;
}

int main(){
    Main();
}

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

const int mod=1000000007;

int main(){
  int N;
cin>>N;
vector<int>A(N);
rep(i,N)cin>>A[i];
sort(A.begin(),A.end());
int ans=0;
rep(i,N){
  rep(j,i){
    rep(k,j){
      if(A[i]!=A[j]&&A[j]!=A[k]&&A[i]<A[j]+A[k])ans++;
    }
  }
}
cout<<ans<<endl;
return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;

int N, M;

int main()
{
    ios_base::sync_with_stdio(0);

    cin >> N >> M;
    ll nsum = 0, nans = 0;
    for (int i = 0; i < N; i++)
    {
        ll x;
        cin >> x;
        nans += (x * i - nsum);
        nans %= MOD;
        nsum = (nsum + x) % MOD;
    }
    ll msum = 0, mans = 0;
    for (int i = 0; i < M; i++)
    {
        ll x;
        cin >> x;
        mans += (x * i - msum);
        mans %= MOD;
        msum = (msum + x) % MOD;
    }

    cout << (nans * mans) % MOD << "\n";
}

#include <bits/stdc++.h>

using namespace std;

inline bool isLeapYear(int year) {
  return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
}

inline int countLeapYear(int year) {
  return year / 4 - year / 100 + year / 400;
}

inline int getMaxDay(int year, int month) {
  const int days[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  if (month == 2) return isLeapYear(year) ? 29 : 28;
  return days[month];
}

struct Day {
  int year, month, day;

  enum {SUN, MON, TUE, WED, THU, FRI, SAT};

  Day() : year(0), month(0), day(0) {}

  Day(int year, int month, int day) : year(year), month(month), day(day) {}

  int fairfield() const {
    int y = year, m = month;
    if (m <= 2) --y, m += 12;
    return 365 * y + countLeapYear(y) + (153 * (m + 1) / 5) + day - 428;
  }

  int operator-(const Day& day) const {
    return fairfield() - day.fairfield();
  }

  bool operator<(const Day& day) const {
    if (year != day.year) return year < day.year;
    if (month != day.month) return month < day.month;
    return this->day < day.day;
  }

  Day operator++() {
    ++day;
    if (getMaxDay(year, month) < day) {
      ++month;
      day = 1;
      if (month == 13) {
        ++year;
        month = 1;
      }
    }
    return *this;
  }

  int dayOfTheWeek() {
    return fairfield() % 7;
  }
};

bool solve() {
  int m, d;
  cin >> m >> d;
  if (m == 0 && d == 0) return false;
  Day day(2004, m, d);
  string week[]{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
  cout << week[day.dayOfTheWeek()] << endl;
  return true;
}

int main() {
  while (solve());
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdio>
#include<string>
#include<cmath>
typedef long long int ll;
#define VI vector<int>

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

int n,m;

using namespace std;

int main(){
	while(1){
		int num[10]={};
		int a=0;
		cin>>a;
		if(a==0)break;
		for(int cou=0;cou<a;cou++){
			int n;
			cin>>n;
			num[n]++;
		}
		rep(i,10){
			if(num[i]==0)cout<<"-"<<endl;
			else{
				rep(j,num[i])cout<<"*";
				cout<<endl;
			}
		}
	}
	return 0;
}

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

int main()
{
	string s;
	while (getline(cin, s))
	{
		string dec = s;
		while (true)
		{
			if (dec.find("the") != -1 || dec.find("this") != -1 || dec.find("that") != -1)
			{
				cout << dec << endl;
				break;
			}
			for (int i = 0; i < dec.size(); i++)
			{
				if ('a' <= dec[i] && dec[i] < 'z') dec[i]++;
				else if (dec[i] == 'z') dec[i] = 'a';
			}
		}
	}

	return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>

using namespace std;
using lint = int64_t;
using P = pair<int, int>;
using D = pair<double, double>;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
#define repn(i, a, b) for(int i = (a); i < (b); ++i)
#define Rep(i, n) for (int i = (n); i >= 0; --i)
#define All(vec) vec.begin(), vec.end()
#define cend printf("\n")

//constexpr lint mod = 998'244'353LL;
constexpr lint mod = 1000'000'007LL;
constexpr lint inf = 3LL * mod * mod;
const double Pi = 2.0 * acos(0.0);

template<class T> using prique     = priority_queue<T>;
template<class T> using prique_inv = priority_queue<T, vector<T>, greater<T>>;
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& rhs) { return is >> rhs.first >> rhs.second; }
template<class T, class U>inline ostream& operator<<(ostream& os, const pair<T, U>& rhs) { return os << rhs.first << " " << rhs.second << "\n"; }
template<class InputIterator> void arrin(InputIterator first, InputIterator last) { for (; first != last; ++first) cin >> (*first); }
template<class InputIterator> void arrout(InputIterator first, InputIterator last) {
	for (; first != last; ++first) {
		cout << (*first) << " ";
	}
	cout << "\n";
}

constexpr bool pri(lint x) { for (lint i = 2; i * i <= x; ++i) if (x % i == 0) return false; return 1 < x; }

inline double dis(D a, D b) { return hypot(a.first - b.first, a.second - b.second); }

lint fact[3000000];
void fact_init(lint n) {
	if (3000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (lint i = 2; i <= n; ++i) {
		fact[i] = i * fact[i - 1];
		if (mod <= fact[i]) fact[i] %= mod;
	}
}

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

lint intpow(lint x, lint n) {
	lint res = 1;
	while (n > 0) {
		if (n & 1) res *= x;
		x *= x;
		n >>= 1;
	}
	return res;
}

lint comb(lint n, lint r) {
	if (r == 0 || r == n) return 1;
	lint res = fact[n] * modpow(fact[n - r], mod - 2) % mod * modpow(fact[r], mod - 2) % mod;
	return res < 0 ? res + mod : res;
}

map<lint, lint> factring(lint n) {
	map<lint, lint> res;
	for (lint i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			++res[i];
		}
	}
	if (n != 1) ++res[n];
	return res;
}

int n, k;
bool f(vector<int>& a) {
	vector<int>b(n + 1);
	rep(i, n) {
		b[max(0, i - a[i])]++;
		b[min(n, i + a[i] + 1)]--;
	}
	rep(i, n) {
		b[i + 1] += b[i];
	}
	bool res = true;
	rep(i, n) {
		a[i] = b[i];
		res &= (a[i] == n);
	}
	return res;
}
int main() {
	cin >> n >> k;
	vector<int>a(n);
	rep(i, n) {
		cin >> a[i];
	}
	rep(i, k) {
		if (f(a)) break;
	}
	for (int e : a) cout << e << " ";
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    rep(i, k) {
        vector<ll> b(n + 1, 0);
        rep(j, n) {
            ll l = max(0LL, j - a[j]);
            ll r = min(n, j + a[j] + 1);
            b[l]++;
            b[r]--;
        }
        ll cnt = 0;
        rep(j, n) {
            b[j + 1] += b[j];
            a[j] = b[j];
            if (a[j] == n) cnt++;
        }
        if (cnt == n) break;
    }
    rep(i, n) printf("%lld%s", a[i], (i == (n - 1)) ? "\n" : " ");
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
typedef long long int LLI;

int main()
{
	int a, b, ans = 0;
	cin >> a >> b;
	int arr[a];
	for(int i = 0; i < a; i++)
		cin >> arr[i];
	sort(arr,arr+a);
	for(int i = a - b; i < a; i++)
		ans += arr[i];
	cout << ans;
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

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

  int n, k;
  cin >> n >> k;

  priority_queue<int, vector<int>, greater<int>> pq;

  for (int i = 0; i < n; ++i) {
    int x; cin >> x;

    if (pq.size() < k) pq.push(x);
    else if (pq.size() >= k && x > pq.top()) {
      pq.pop();
      pq.push(x);
    }
  }

  int res = 0;
  while (!pq.empty()) {
    res += pq.top(); pq.pop();
  }

  cout << res << "\n";
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()

int main(){
  int H,W,K;
  cin>>H>>W>>K;
  ll mod=1e9+7;
  ll dp[H+1][W]={};
  dp[0][0]=1;
  ll L[W]={};
  ll M[W]={};
  ll R[W]={};
  if(W>1) rep(i,(1<<(W-1))){
    int F=1;
    rep(j,W-2) if((i&(1<<j))&&(i&(1<<(j+1)))) F=0;
    if(F) rep(j,W-1){
      if(i&(1<<j)){
        R[j]++;
        L[j+1]++;
      }
    }
    if(F) rep(j,W){
      if(j==0){
        if((i&(1<<j))==0) M[j]++;
      }else if(j==W-1){
        if((i&(1<<(j-1)))==0) M[j]++;
      }else{
        if((i&(1<<(j-1)))==0&&(i&(1<<j))==0) M[j]++;
      }
    }
  }
  rep(i,H){
    rep(j,W){
      if(j==0) dp[i+1][j]=(dp[i][j]*M[j]+dp[i][j+1]*R[j])%mod;
      else if(j==W-1) dp[i+1][j]=(dp[i][j]*M[j]+dp[i][j-1]*L[j])%mod;
      else dp[i+1][j]=(dp[i][j]*M[j]+dp[i][j+1]*R[j]+dp[i][j-1]*L[j])%mod;
    }
  }
  if(W==1) cout<<1<<endl;
  else cout<<dp[H][K-1]<<endl;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.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;}
const ll INF = 1LL << 60;
const int MAX = 510000;
const ll MOD = 998244353;

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

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

int main() {
    ll n, m, k; cin >> n >> m >> k;
    COMinit();
    ll ans = 0;
    rep(i, k+1) ans += COM(n-1, i) * m % MOD * binarypow(m-1, n-i-1, MOD) % MOD;
    cout << ans % MOD << endl;
}


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

int main(){
  int N;
  cin>>N;
  string temp;
  string A[N];

  cout<<0<<endl;
  cin>>temp;
  if(temp=="Vacant"){
    cout<<0<<endl;
    return 0;
  }
  if(temp=="Male"){
    A[0]="Male";
  }
  if(temp=="Female"){
    A[0]="Female";
  }

  cout<<N-1<<endl;
  cin>>temp;
  if(temp=="Vacant"){
    cout<<N-1<<endl;
    return 0;
  }
  if(temp=="Male"){
    A[N-1]="Male";
  }
  if(temp=="Female"){
    A[N-1]="Female";
  }
  int l=N-1;
  int r=0;
  int k=22;
  while(k){
    k--;
    int m=(l+r)/2;
    cout<<m<<endl;
    cin>>temp;
    if(temp=="Vacant"){
      cout<<m<<endl;
      return 0;
    }
    if(temp=="Male"){
      A[m]="Male";
    }
    if(temp=="Female"){
      A[m]="Female";
    }
    if((l-m)%2 == 0 && A[l] == A[m]){
      l=m;
      continue;
    }
    if((l-m)%2 == 0 && A[l] != A[m]){
      r=m;
      continue;
    }
    if((l-m)%2 == 1 && A[l] == A[m]){
      r=m;
      continue;
    }
    if((l-m)%2 == 1 && A[l] != A[m]){
      l=m;
      continue;
    }

   }
  cout<<3<<endl;

  return 0;
}

#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph= vector<vector<int>>;
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}

int main(){
   int n ; cin>>n ;
   cout<< 0 <<endl ;
   string s ; cin >>s ;
   if(s=="Vacant") return 0 ;
   int l =0 ; int r= n ;
   while(1){
     int m = (r+l) /2 ;
     cout<< m<< endl ;
     string ss ;cin>>ss ;
     if(ss=="Vacant" ) break ;
     bool ok= (s==ss) ;
     int a = m%2 ;
     if(ok==a) r=m ;
    else l= m+1 ;

   }
 return 0 ;
}


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

bool sol(vector<int>d1,vector<int>d2){
    for(int i=0;i<4;i++){
        int tmp1=d1[0];
        d1[0]=d1[2], d1[2]=d1[5], d1[5]=d1[3], d1[3]=tmp1;
        for(int j=0;j<4;j++){
            int tmp2=d1[0];
            d1[0]=d1[1], d1[1]=d1[5], d1[5]=d1[4], d1[4]=tmp2;
            for(int k=0;k<4;k++){
                int tmp3=d1[1];
                d1[1]=d1[2], d1[2]=d1[4], d1[4]=d1[3], d1[3]=tmp3;
                if(equal(d1.cbegin(),d1.cend(),d2.cbegin())){
                    printf("No\n");
                    return false;
                }
            }
        }
    }
    return true;
}

int main(){
    int n;
    scanf("%d",&n);
    vector<vector<int>> d(n,vector<int>(6));
    for(int i=0;i<n;i++){
        for(auto&e:d[i]){
            scanf("%d",&e);
        }
    }
    bool flag;
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            flag=sol(d[i],d[j]);
            if(flag==false) return 0;;
        }
    }
    printf("Yes\n");
    return 0;
}

// ABC 080 B- Harshed Number
/*
  各桁の和ってどうプログラムすればええんだ
  あ、10で割り続けて、商と余りを考えればいいんだ
*/
#include <bits/stdc++.h>
using namespace std;

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

  int N2 = N;
  while (N != 0) { // Nが0になるまで割り続ける。
    sum += N % 10; // 総和を更新して
    N /= 10; // Nを更新 N = N / 10 → N /= 10
  }
  if (N2 % sum == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

const ll mod = 998244353;
const int N = 2500010;
ll fact[N], invf[N];

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

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

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

ll divll(ll x, ll y){
    return (x * powll(y,mod-2)) % mod;
}

ll nPr(ll n, ll r){
    if (n < r || r < 0) return 0;
    return mul(fact[n], invf[n-r]);
}

ll nCr(ll n, ll r){
    if (n < r || r < 0) return 0;
    return mul(mul(fact[n], invf[r]), invf[n-r]);
}

int main() {
    ll n, m;
    cin >> n >> m;
    fact[0] = invf[0] = 1;
    FOR(i,1,N-1){
        fact[i] = (fact[i-1] * i) % mod;
    }
    invf[N - 1] = divll(1, fact[N - 1]);
    FORR(i,N-1,1){
        invf[i - 1] = (invf[i] * i) % mod;
    }

    ll ans = 0;
    REP(x,m+1){
        if ((3 * m - x) % 2) continue;
        ll tmp = (nCr(n, x) * nCr(n + (3 * m - x) / 2 - 1, n - 1)) % mod;
        ans = (ans + tmp) % mod;
    }
    REP(i,m){
        ll tmp = (n * nCr(n + i - 2, n - 2)) % mod;
        ans = (ans - tmp + mod) % mod;
    }
    cout << ans << endl;

    return 0;
}

/**
*    created: 27.06.2020 19:04:28
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pcnt(bit) __builtin_popcountll(bit)
#define mod 1000000007
#define pi acos(-1.0)
using namespace std;
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b) {if (b < a) {a = b; return 1;} return 0;}

signed main() {

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

    int a, b;
    cin >> a >> b;
    if (a % b == 0) cout << 0 << endl;
    else cout << 1 << endl;
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <set>
#include <functional>
#include <map>
#include <queue>
#include <cmath>
#include <string>
#include <stack>
#define MX 1000005
#define INF 1000000005

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

struct UF
{
    int par[MX],rank[MX];

    void init(int n)
    {
        for(int i=0;i<n;i++)
        {
            par[i]=i;
            rank[i]=0;
        }
    }
    void rem(int i)
    {
        par[i]=i;
        rank[i]=0;
    }
    int find(int x)
    {
        if(x==par[x]) return x;
        return par[x]=find(par[x]);
    }
    void unite(int x,int y)
    {
        x=find(x);
        y=find(y);
        if(x==y) return;
        if(rank[x]<rank[y])
        {
            par[x]=y;
        }
        else
        {
            par[y]=x;
            if(rank[x]==rank[y]) rank[x]++;
        }
    }
    bool same(int x,int y)
    {
        return find(x)==find(y);
    }
};
UF uf;
vector <int> vec[MX];
vector <P> query[MX];
int id[MX];
bool use[MX];
int dp[MX];

int main()
{
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i=0;i<m;i++)
    {
        int p,q,c;
        scanf("%d %d %d",&p,&q,&c);p--,q--,c--;
        query[c].push_back(P(p,q));
    }
    int sz=n;
    for(int i=0;i<MX;i++)
    {
        if(query[i].empty()) continue;
        for(int j=0;j<query[i].size();j++)
        {
            P p=query[i][j];
            uf.rem(p.first);
            uf.rem(p.second);
            id[p.first]=id[p.second]=-1;
            use[p.first]=use[p.second]=false;
        }
        for(int j=0;j<query[i].size();j++)
        {
            P p=query[i][j];
            uf.unite(p.first,p.second);
        }
        for(int j=0;j<query[i].size();j++)
        {
            P p=query[i][j];
            if(!use[p.first])
            {
                use[p.first]=true;
                int r=uf.find(p.first);
                if(id[r]==-1) id[r]=sz++;
                //printf("%d %d: %d\n",r,id[r],p.first);
                vec[p.first].push_back(id[r]);
                vec[id[r]].push_back(p.first);
            }
            if(!use[p.second])
            {
                use[p.second]=true;
                int r=uf.find(p.second);
                if(id[r]==-1) id[r]=sz++;
                //printf("%d %d: %d\n",r,id[r],p.second);
                vec[p.second].push_back(id[r]);
                vec[id[r]].push_back(p.second);
            }
        }
    }
    queue <int> que;
    que.push(0);
    memset(dp,-1,sizeof(dp));
    dp[0]=0;
    while(!que.empty())
    {
        int v=que.front();que.pop();
        for(int i=0;i<vec[v].size();i++)
        {
            int to=vec[v][i];
            if(dp[to]==-1)
            {
                dp[to]=dp[v]+1;
                que.push(to);
            }
        }
    }
    if(dp[n-1]==-1) puts("-1");
    else printf("%d\n",dp[n-1]/2);
    return 0;
}

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

const int MaxN=1e5+5;

int N,M,K,Cnt0,Cnt1;
int Fa[MaxN],Size[MaxN],Col[MaxN];

vector<int> To[MaxN];

int Get_Fa(int x){
	return x==Fa[x]?x:Fa[x]=Get_Fa(Fa[x]);
}

bool Check(int u){
	int i,v;
	for(i=0;i<To[u].size();i++)
		if(!Col[v=To[u][i]]){
			Col[v]=3-Col[u];
			if(!Check(v))
				return false;
		}
		else if(Col[u]==Col[v])
			return false;
	return true;
}

int main(){
	int i,u,v,r1,r2;
	scanf("%d%d",&N,&M);
	for(i=1;i<=N;i++)
		Fa[i]=i,Size[i]=1;
	while(M--){
		scanf("%d%d",&u,&v);
		To[u].push_back(v);
		To[v].push_back(u);
		if((r1=Get_Fa(u))^(r2=Get_Fa(v)))
			Fa[r1]=r2,Size[r2]+=Size[r1];
	}
	for(i=1;i<=N;i++)
		if(i==Get_Fa(i)){
			if(Size[i]<2)
				K++;
			else{
				Col[i]=1;
				Check(i)?Cnt0++:Cnt1++;
			}
		}
	printf("%lld\n",2ll*K*N-1ll*K*K+2ll*Cnt0*Cnt0+1ll*Cnt1*Cnt1+2ll*Cnt0*Cnt1);
	return 0;
}


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

int main() {
	int N, M;

	while(cin >> N >> M, N || M) {
		vector<int> P;
		vector<int> v;
		for(int i = 0; i < N; i++) {
			int tmp;
			cin >> tmp;
			P.push_back(tmp);
		}
		P.push_back(0);

		for(int i = 0; i < P.size(); i++) {
			for(int j = 0; j < P.size(); j++) {
				v.push_back(P[i]+P[j]);
			}
		}
		sort(v.begin(), v.end());
		int j = v.size() - 1;
		int res = 0;
		for(int i = 0; i < v.size(); i++) {
			while(v[i]+v[j] > M && j >= 0)
				j--;
			if(j >= 0)
				res = max(res, v[i] + v[j]);
		}
		cout << res << endl;
	}
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

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

int main() {

	int m, nmin, nmax;
	while(cin >> m >> nmin >> nmax, m){
		vector<int> p(m);
		rep(i, m) cin >> p[i];

		int ans = 0;
		int maxi = 0;
		REP(i, nmin-1, nmax){
			if(maxi <= p[i] - p[i+1]){
				maxi = p[i] - p[i+1];
				ans = i + 1;
			}
		}
		cout << ans << endl;

	}

	return 0;
}


#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#define INF 100000000000000
using namespace std;
typedef long long llong;

//int isalpha(char ch): ch がアルファベットなら true を返す
//int isdigit(char ch): ch が数字なら true を返す
//int islower(char ch): ch が小文字なら true を返す
//int isupper(char ch): ch が大文字なら true を返す
//int tolower(char ch): ch の小文字を返す
//int toupper(char ch): ch の大文字を返す

//string型
//size()	文字数を返す
//insert()	（指定した場所に）文字・文字列を挿入する
//erase()	（指定した場所の）文字・文字列を削除する
//clear()	すべての文字を削除する
//substr()	文字列の（指定した）部分文字列を返す
//replace()	（指定した）部分文字列を新しい文字列に置換する
//文字列の比較は、<=や==などを使え
//replace関数を使い、簡単に文字列を置換
//リバース関数：reverse(str.begin(), str.end());
//map<type, type> dict;で宣言
//グラフ理論用変数
//vector<vector<llong> > graph(N);

//ソート
//降順sort(v.begin(), v.end(), std::greater<Type>());

//大文字から小文字へんかん
//w[i] = w[i]-'A'+'a';

bool isprime(llong num){
    if(num==1){
        return false;
    }
    if(num==2){
        return true;
    }
    for(int i=2; i<=sqrt(num); i++){
        if(num%i==0){
            return false;
        }
    }
    return true;
}

//約数列挙
void EnumerateFactor(vector<vector<llong> > &factor_list, llong num){
    llong cnt=0;
    for(int i=1; i<=sqrt(num); i++){
        if(num%i==0){
            factor_list[cnt].push_back(i);
            factor_list[cnt].push_back(num/i);
            cnt++;
        }
    }
}

int main(){
    llong n;
    llong ans=INF;
    llong temp=-1*INF;
    vector<vector<llong> > factor_list(100000);
    string A, B;

    scanf("%lld", &n);
    EnumerateFactor(factor_list, n);
    for(int i=0; i<factor_list.size(); i++){
        if(factor_list[i].size()==0){
            break;
        }
        A = to_string(factor_list[i][0]);
        B = to_string(factor_list[i][1]);
        temp = max(A.size(), B.size());
        ans  = min(temp, ans);
    }
    cout << ans << endl;
    return 0;

}

#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t m,j,l,q=0;
  cin>>m;
  for(j=1;j*j<=m;j++){
    if(m%j==0) l=m/j;
  }
  while(l>0){
    q++;
    l/=10;
  }
  cout<<q<<endl;
}


#include<bits/stdc++.h>
//#include <atcoder/all>
#define ll long long int
#define rep(i,n) for(ll i=0;i<n;i++)
#define vec vector<ll>
#define mat vector<vector<ll>>

using namespace std;
//using namespace atcoder;

const ll mod=1000000007;//998244353;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

int main(){

  string s;
  cin >> s;

  ll a=s[0]-'0',b=s[1]-'0',c=s[2]-'0',d=s[3]-'0';

  for(ll i=-1;i<2;i+=2){
    for(ll j=-1;j<2;j+=2){
      for(ll k=-1;k<2;k+=2){
        if(a+b*i+c*j+d*k==7){
          string t;
          t=to_string(a);
          char e;
          if(i<0)e='-';
          else e='+';
          t+=e;
          t+=to_string(b);
          if(j<0)e='-';
          else e='+';
          t+=e;
          t+=to_string(c);
          if(k<0)e='-';
          else e='+';
          t+=e;
          t+=to_string(d);
          t+="=7";
          cout << t << endl;
          return 0;
        }
      }
    }
  }

  return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define all(v) v.begin(), v.end()
#define sz size()
#define mp make_pair
#define pb push_back
#define rep(p, a, b) for (ll p = a; p < b; p++)
#define rap(p, a, b) for (ll p = a; p <= b; p++)
#define per(p, a, b) for (ll p = a; p >= b; p--)
#define F first
#define S second
using namespace std;

typedef vector<ll> vll;
typedef vector<ld> vld;
typedef pair<ll, ll> pll;

int main()
{
    ll t, i, j, k, ans, n;

    //cin>>t;
    t = 1;
    while (t--)
    {
        int a,b,c;
        cin>>a>>b>>c;
        set<ll> s;
        s.insert(a);s.insert(b);s.insert(c);

        if(s.sz==2)cout<<"Yes";
        else cout<<"No";
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int main(){
    int a,b,c;cin>>a>>b>>c;
    bool flag=false;
    if(a==b){
        if(a!=c){
            flag=true;
        }
    }else if(a==c){
        flag=true;
    }else{
        if(b==c){
            flag=true;
        }
    }
    if(flag){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


#include <algorithm>
#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;
using ll = long long;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;

// ===============================================================

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

ll lcm(ll a, ll b) //最小公倍数
{
	return a * b / gcd(a, b);
}

ll box(double a) //doubleの切り捨て
{
	ll b = a;
	return b;
}

ll fff(double a) //doubleの四捨五入
{
	ll b = a + 0.5;
	return b;
}

ll sum(ll n) { //整数sまでの合計
	if (n == 0) {
		return 0;
	}

	int s = sum(n - 1);
	return s + n;
}

bool prime(ll num)//素数判定、primeならtrue,違うならfalse
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	// 素数である
	return true;
}

// ===============================================================

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

#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n,k;
  cin >> n >> k;
  cout << (n%k==0?0:1) << endl;
}


#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

int a[1010], b[1010];
map<int, int> mpa, mpb;

int main(){
    int n, m;
    cin >> n >> m;
    rep(i, n){
        cin >> a[i];
        mpa[a[i]]++;
    }
    rep(i, m){
        cin >> b[i];
        mpb[b[i]]++;
    }
    if (mpa.size() != n || mpb.size() != m || (!mpa[m*n] || !mpb[m*n])) {
        cout << 0 << endl;
        return 0;
    }

    ll ans = 1;
    ll cnta = 0, cntb = 0;

    for(ll num = n*m; num > 0; num--){
        if (mpa[num] && mpb[num]) {
            cnta++;
            cntb++;
        }
        else if (mpa[num] && !mpb[num]){
            ans *= cntb;
            cnta++;
            ans %= MOD;
        }
        else if (!mpa[num] && mpb[num]){
            ans *= cnta;
            ans %= MOD;
            cntb++;
        }
        else {
            ans *= max(cnta * cntb - (n*m-num), (ll)0);
            ans %= MOD;
        }
    }

    cout << ans << endl;

    return 0;
}

#include <bits/stdc++.h>

#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)
#define MOD 1000000007

using namespace std;

using ll = long long;

ll solve() {

    int H, W;
    cin >> H >> W;
    vector<int> A(H), B(W);
    set<int> As, Bs;
    REP(i, H) {
        cin >> A[i];
        --A[i];
        As.insert(A[i]);
    }
    REP(i, W) {
        cin >> B[i];
        --B[i];
        Bs.insert(B[i]);
    }

    if (As.size() < H || Bs.size() < W) {
        return 0;
    }

    int n_used_rows = 0;
    int n_used_cols = 0;
    ll result = 1;
    RREP(x, H * W) {
        int n_filled = H * W - 1 - x;
        bool inA = As.count(x) > 0;
        bool inB = Bs.count(x) > 0;
        int n_ways;
        if (inA && inB) {
            n_ways = 1;
            ++n_used_rows;
            ++n_used_cols;
        } else if (inA && !inB) {
            n_ways = n_used_cols;
            ++n_used_rows;
        } else if (!inA && inB) {
            n_ways = n_used_rows;
            ++n_used_cols;
        } else {
            n_ways = n_used_rows * n_used_cols - n_filled;
            if (n_ways <= 0) return 0;
        }
        result = (result * n_ways) % MOD;
    }
    return result;
}

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

    cout << solve() << endl;

    return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#define MAX 30
using namespace std;
string S;

int main(){
    while (1) {
        int p;
        cin >> p;
        if (p!=0) {
            int stx[MAX],sty[MAX];
            for (int i = 0; i<p; i++){
                cin >> stx[i] >> sty[i];
            }
            int area[MAX][MAX]={};
            int pointx=10,pointy=10;
            int ord_num,ord_dis;
            char ord_dir;
            cin >> ord_num;
            for (int i =0; i<ord_num; i++) {
                cin >> ord_dir >> ord_dis;
                if (ord_dir=='N') {
                    for (int j=0; j<ord_dis; j++) {
                        pointy++;
                        area[pointx][pointy]=1;
                    }
                }if (ord_dir=='E') {
                    for (int j=0; j<ord_dis; j++) {
                        pointx++;
                        area[pointx][pointy]=1;
                    }
                }if (ord_dir=='S') {
                    for (int j=0; j<ord_dis; j++) {
                        pointy--;
                        area[pointx][pointy]=1;
                    }
                }if (ord_dir=='W') {
                    for (int j=0; j<ord_dis; j++) {
                        pointx--;
                        area[pointx][pointy]=1;
                    }
                }
            }
            int flag=0;
            for (int i=0; i<p; i++) {
                if (area[stx[i]][sty[i]]==1) {
                    flag++;
                }
            }
            if (flag==p) {
                cout << "Yes"<<"\n";
            }else{
                cout << "No" << "\n";

            }
        }else{
            break;
        }
    }

}

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

int main(){
	int n,a,b,c;

	while(true){
		scanf("%d",&n);
		if(n == 0)break;

		for(int i = 0; i < n; i++){
			scanf("%d %d %d",&a,&b,&c);
			if(a == 100 || b == 100 || c == 100 || a + b >= 180 || a+b+c >= 240){
				printf("A\n");
			}else if((a + b + c >= 210) || (a+b+c>=150 && (a >= 80 || b >= 80))){
				printf("B\n");
			}else{
				printf("C\n");
			}
		}

	}
    return 0;
}