#include"bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
	int n, q;
	cin >> n >> q;
	string s;
	cin >> s;
	vector<int>ac(n, 0), acsum(n + 1,0);
	for (int i = 0; i < n-1; i++) {
		if (s.substr(i, 2) == "AC") {
			ac[i]++;
			i++;
		}
	}
	rep(i, n)acsum[i + 1] = acsum[i] + ac[i];
	int l, r;
	rep(i, q) {
		cin >> l >> r;
		cout << acsum[r-1] - acsum[l-1] << endl;
	}
	return 0;
}

#include <bits/stdc++.h>

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

using namespace std;

using graph=vector<vector<int>>;

void add_directed_edge(graph& G,int u,int v){
	G[u].emplace_back(v);
}

vector<int> topological_order(const graph& D){
	int n=D.size();
	vector<int> deg(n);
	rep(u,n) for(int v:D[u]) deg[v]++;

	vector<int> res;
	queue<int> Q;
	rep(u,n) if(deg[u]==0) Q.emplace(u);
	while(!Q.empty()){
		int u=Q.front(); Q.pop();
		res.emplace_back(u);
		for(int v:D[u]) if(--deg[v]==0) Q.emplace(v);
	}
	return res;
}

int main(){
	int n,m; scanf("%d%d",&n,&m);
	m+=n-1;
	graph G(n);
	rep(i,m){
		int u,v; scanf("%d%d",&u,&v); u--; v--;
		add_directed_edge(G,u,v);
	}

	vector<int> dp(n);
	for(int u:topological_order(G)){
		for(int v:G[u]) dp[v]=max(dp[v],dp[u]+1);
	}

	vector<int> ans(n,-1);
	rep(u,n) for(int v:G[u]) if(dp[v]==dp[u]+1) ans[v]=u;
	rep(u,n) printf("%d\n",ans[u]+1);

	return 0;
}


#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
#define rg register
void read(int &x){
    char ch;bool ok;
    for(ok=0,ch=getchar();!isdigit(ch);ch=getchar())if(ch=='-')ok=1;
    for(x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar());if(ok)x=-x;
}
const int maxn=2010,mod=1e9+7,N=4e6;
int n,m,f[maxn][maxn],fac[maxn*maxn],inv[maxn*maxn];
int mul(int x,int y){return 1ll*x*y-1ll*x*y/mod*mod;}
int add(int x,int y){return x+y>=mod?x+y-mod:x+y;}
int del(int x,int y){return x-y<0?x-y+mod:x-y;}
int mi(int a,int b){int ans=1;while(b){if(b&1)ans=mul(ans,a);b>>=1,a=mul(a,a);}return ans;}
void prepare(){
    fac[0]=inv[0]=1;
    for(rg int i=1;i<=N;i++)fac[i]=mul(fac[i-1],i);
    inv[N]=mi(fac[N],mod-2);
    for(rg int i=N-1;i;i--)inv[i]=mul(inv[i+1],i+1);
}
int C(int n,int m){return mul(fac[n],mul(inv[m],inv[n-m]));}
int main(){
    read(n),read(m),prepare();
    if(m==1)return printf("1\n"),0;
    for(rg int i=1;i<=n;i++){
	f[i][0]=1;
	for(rg int j=1;j<=i;j++)
	    f[i][j]=add(f[i-1][j],mul(mul(f[i][j-1],n-j+1),C(n*m-(j-1)*(m-1)-i-1,m-2)));
    }
    printf("%d\n",f[n][n]);
}

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

int main()
{
	int n, k; cin >> n >> k;
	vector<double> v(n);
	vector<double> expected(n);
	for(int i = 0; i < n; ++i)
	{
		cin >> v[i];
		expected[i] = ((v[i]*(v[i]+1.0))/2.0)/v[i];

		if(i)
			expected[i] += expected[i-1];

	}
	double maxi = expected[k-1];
	double tolerance = 0.0000001;
	for(int i = k-1; i < n; ++i)
	{
		int pre = i - k;
		if(pre >= 0)
		{
			double cur = expected[i] - expected[pre];
			if(cur-maxi > tolerance)
				maxi = cur;
		}
	}

	cout << setprecision(17) <<  maxi;

	return 0;

}


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

int main() {

	int n, m; cin >> n >> m;
	string ans = "";
	for (int i = 0; i < n; i++) {
		ans += 'x';
	}
	for (int i = 0; i < m; i++) {
		int s; char c; cin >> s >> c;
		s--;
		if (ans[s] != 'x') {
			if (ans[s] == c) {}
			else { // ans[s] != c
				cout << -1 << endl;
				return 0;
			}
		}
		else { // ans[s] == 'x'
			ans[s] = c;
		}
	}
	for (int i = 0; i < n; i++) {
		if (i != 0 && ans[i] == 'x') ans[i] = '0';
		else if (i == 0 && ans[i] == 'x' && ans.size() != 1) ans[i] = '1';
		else if (i == 0 && ans[i] == 'x' && ans.size() == 1) ans[i] = '0';
	}
	if (ans[0] == '0' && 2 <= ans.size()) ans = "-1";
	cout << ans << endl;
    return 0;
}

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

vector<int> adj[MAX];
int visited[MAX];
int graph[MAX][MAX];

vector<int> dfs(int v, int root)
{
	vector<int> ans;
	visited[v] = 1;
	if (v != root)
	{
		for (int i : adj[v])
		{
			if (i != root && visited[i]) return ans;
		}
		if (graph[v][root])
		{
			ans.push_back(v);
			return ans;
		}
	}
	for (int i : adj[v])
	{
		vector<int> res = dfs(i, root);
		if (!res.empty())
		{
			int flag = 1;
			for (int j : res)
			{
				if (graph[v][j] && i != j)
				{
					flag = 0;
					break;
				}
			}
			if (!flag) continue;
			res.push_back(v);
			return res;
		}
	}
	visited[v] = 0;
	return ans;
}

int main(void)
{
	int N, M;
	cin >> N >> M;
	for (int i = 0; i < M; i++)
	{
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		adj[u].push_back(v);
		graph[u][v] = 1;
	}
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < N; j++) visited[j] = 0;
		vector<int> res = dfs(i, i);
		reverse(res.begin(), res.end());
		if (!res.empty())
		{
			cout << res.size() << endl;
			for (int j : res) cout << j + 1 << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}


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

const int maxn = 2010;
int H, W, f[maxn][maxn], pre[maxn], suf[maxn];
char s[maxn][maxn];
bool chk[maxn][maxn];

int main() {
    scanf("%d %d", &H, &W);
    for (int i = 1; i <= H; i++) {
        scanf("%s", s[i] + 1);
        for (int j = 1; j <= W; j++) {
            if (i > 1 && j > 1) {
                int cnt = (s[i][j] == '.') + (s[i - 1][j] == '.') +
                    (s[i][j - 1] == '.') + (s[i - 1][j - 1] == '.');
                if (cnt & 1) chk[i - 1][j - 1] = 1;
            }
        }
    }
    H--, W--;
    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            f[i][j] = chk[i][j] ? 0 : (f[i - 1][j] + 1);
        }
    }
    int ans = max(H + 1, W + 1);
    for (int i = 1; i <= H; i++) {
        stack<int> st;
        f[i][0] = f[i][W + 1] = -1;
        st.push(0);
        for (int j = 1; j <= W; j++) {
            while (f[i][st.top()] >= f[i][j]) st.pop();
            pre[j] = st.top(), st.push(j);
        }
        while (!st.empty()) st.pop();
        st.push(W + 1);
        for (int j = W; j; j--) {
            while (f[i][st.top()] >= f[i][j]) st.pop();
            suf[j] = st.top(), st.push(j);
        }
        for (int j = 1; j <= W; j++) {
            ans = max(ans, (f[i][j] + 1) * (suf[j] - pre[j]));
        }
    }
    printf("%d\n", ans);
    return 0;
}

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

int main(){
	int h,w; cin >> h >> w;
	vs s(h); rep(i,h) cin >> s[i];
	vl dist(h+1,-1);
	int ans = w;
	rep(j,w){
		vector<pii> st;
		st.emplace_back(0,0);
		REP(i,1,h+1){
			if(i < h){
				if(j==0 || dist[i] == 1){
					int d = 0;
					bool rev = s[i][j] != s[i-1][j];
					REP(k,j,w){
						if(rev == (s[i][k] != s[i-1][k])) d++;
						else break;
					}
					dist[i] = d;
				}else{
					dist[i]--;
				}
			}else{
				dist[i] = 0;
			}
			if(st.empty() || st.back().first < dist[i]){
				st.emplace_back(dist[i],i);
			}else{
				int pos = i;
				while(!st.empty()){
					if(st.back().first >= dist[i]){
						pii p = st.back();
						chmax(ans, p.first*(i-p.second)+p.first);
						pos = p.second;
						st.pop_back();
					}else{
						st.emplace_back(dist[i], pos);
						break;
					}
				}
			}
		}
	}
	cout << ans << "\n";
}


#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

int main(){
    ll N,D;
    ll A[200005];
    cin>>N>>D;
    ll ret = D*(N-1);
    for(int i = 0;i < N;i++){
        cin>>A[i];
        ret += A[i];
    }
    for(int i = 1;i < N;i++){
        A[i]=min(A[i-1]+D,A[i]);
    }
    for(int i = N-2;i >=0;i--){
        A[i]=min(A[i+1]+D,A[i]);
    }
    for(int i = 1;i < N-1;i++){
        ret += A[i];
    }
    cout<<ret<<endl;

}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=1<<18;
const ll INF=1LL<<55;

int n;
pair<ll,int> dat[2*MAX-1][2];

void init(int n_){
    n=1;
    while(n<n_) n*=2;
    for(int i=0;i<2*n-1;i++){
        dat[i][0]={INF,i-(n-1)};
        dat[i][1]={INF,i-(n-1)};
    }
}

void update(int k,ll a,int kind){
    k+=n-1;
    dat[k][kind].first=a;

    while(k>0){
        k=(k-1)/2;
        dat[k][kind]=min(dat[k*2+1][kind],dat[k*2+2][kind]);
    }
}

pair<ll,int> query(int a,int b,int k,int l,int r,int kind){

    if(r<=a||b<=l) return {INF,-1};
    if(a<=l&&r<=b) return dat[k][kind];
    else{
        pair<ll,int> vl=query(a,b,2*k+1,l,(l+r)/2,kind);
        pair<ll,int> vr=query(a,b,2*k+2,(l+r)/2,r,kind);
        return min(vl,vr);
    }
}

struct edge{
    int from;
    int to;
    ll dis;
};

bool compare(edge a,edge b){
    return a.dis<b.dis;
}

int par[MAX],size[MAX];

void initUF(int n){
    for(int i=0;i<n;i++){
        par[i]=i;
        size[i]=1;
    }
}

int root(int a){
    if(par[a]==a) return a;
    else return par[a]=root(par[a]);
}

void unite(int a,int b){
    if(root(a)!=root(b)){
        size[root(a)]+=size[root(b)];
        par[root(b)]=root(a);
    }
}

bool check(int a,int b){
    return root(a)==root(b);
}

int main(){

    ll N;
    ll D;cin>>N>>D;
    vector<ll> A(N);
    for(int i=0;i<N;i++) cin>>A[i];

    vector<int> id(N);
    iota(all(id),0);
    sort(all(id),[&](int i,int j){
        return A[i]<A[j];
    });

    init(N);

    vector<edge> S;

    for(int i:id){
        auto left=query(0,i+1,0,0,n,0),right=query(i,n+1,0,0,n,1);
        if(left.first!=INF){
            S.push_back({left.second,i,A[left.second]+A[i]+D*(i-left.second)});
        }
        if(right.first!=INF){
            S.push_back({i,right.second,A[i]+A[right.second]+D*(right.second-i)});
        }

        update(i,D*(N-1-i)+A[i],0);
        update(i,D*i+A[i],1);
    }

    sort(all(S),compare);

    initUF(N);

    ll ans=0;

    for(edge e:S){
        int a=e.from,b=e.to;
        ll c=e.dis;

        if(check(a,b)) continue;

        ans+=c;
        unite(a,b);
    }

    cout<<ans<<endl;

}


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

const int N = 1e5+7, K = 18;
vector<int> cld[N];
int par[N], level[N], anc[N][K];
bool done[N];

int n, k;
priority_queue<pair<int, int>> pq;

void setup(int u) {
    if (par[u] != u) level[u] = level[par[u]]+1;
    pq.push({level[u], u});
    anc[u][0] = par[u];
    for (int k=1; k<K; k++)     anc[u][k] = anc[anc[u][k-1]][k-1];
    for (int v: cld[u])         setup(v);
}

int getanc(int u, int d) {
    if (d >= N) d = N-1;
    for (int k=0; k<K; k++)
        if (d & (1<<k))
            u = anc[u][k];
    return u;
}

void dfs(int u) {
    if (done[u])    return;
    done[u] = 1;
    for (int v: cld[u])
        dfs(v);
}

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

    cin>>n>>k;
    cin>>par[1];
    int ans = 0;
    if (par[1] != 1)    ans++, par[1] = 1;

    for (int i=2; i<=n; i++) {
        cin>>par[i];
        cld[par[i]].push_back(i);
    }
    setup(1);

    while (pq.size()) {
        int u = pq.top().second;
        int d = pq.top().first;
        pq.pop();
//        cout<<u<<" --> "<<d<<endl;
        if (d <= k)     continue;
        if (done[u])    continue;

        int g = getanc(u, k-1);
        ans++;
        dfs(g);
    }
    cout<<ans<<endl;
}

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

int main(){
	ios::sync_with_stdio(false);

	int N,M; cin>>N;
	vector<string> s(N);
	rep(i,N) cin>>s[i];
	cin>>M;
	vector<string> t(M);
	rep(i,M) cin>>t[i];

	int ans=0;
	rep(i,N){
		string taka = s[i];
		int money = 0;
		rep(j,N){
			if(taka == s[j]) money++;
		}
		rep(k,M){
			if(taka == t[k]) money--;
		}
		ans = max(ans,money);
	}
	cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
using ii = pair<int, int>;
#define ff first
#define ss second

char s[1000010];

bool comp(ii a, ii b){
	return a.ss > b.ss;
}
int32_t main(){
	int n;
	scanf("%d", &n);
	vector<ii> v1, v2;
	for(int z=0; z<n; ++z){
		scanf("%s", s);
		int q = 0;
		int tam = int(strlen(s));
		int a=0, b=0;
		for(int i = 0; i<tam; ++i){
			if(s[i]==')'){
				if(q>0) --q;
				else ++b;
			}
			else ++q;
		}
		a = q;
		if(a>b) v1.emplace_back(a, b);
		else v2.emplace_back(a, b);
	}
	sort(v1.begin(), v1.end(), comp);
	sort(v2.begin(), v2.end());
	int q = 0;
	for(auto x:v2){
		int a = x.ff;
		int b = x.ss;
		if(a>q){
			printf("No\n");
			return 0;
		}
		q-=a;
		q+=b;
	}
	for(auto x:v1){
		int a = x.ff;
		int b = x.ss;
		if(a>q){
			printf("No\n");
			return 0;
		}
		q-=a;
		q+=b;
	}
	if(q==0)
		printf("Yes\n");
	else
		printf("No\n");
}

#include "bits/stdc++.h"
using namespace std;
#ifndef LOCAL
#define endl '\n'
#endif

#define fr(i, a, b) for(int i = a; i <= b; i++)
#define rf(i, a, b) for(int i = a; i >= b; i--)
#define pf push_front
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
#define lb lower_bound
#define ub upper_bound

typedef long long ll;
typedef long double f80;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int pct(int x) { return __builtin_popcount(x); }
int pct(ll x) { return __builtin_popcountll(x); }
int bt(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))
int bt(ll x) { return 63 - __builtin_clzll(x); } // floor(log2(x))
int cdiv(int a, int b) { return a / b + !(a < 0 || a % b == 0); }
ll cdiv(ll a, ll b) { return a / b + !(a < 0 || a % b == 0); }
int nxt_C(int x) { int c = x & -x, r = x + c; return (((r ^ x) >> 2) / c) | r; }
ll nxt_C(ll x) { ll c = x & -x, r = x + c; return (((r ^ x) >> 2) / c) | r; }

vector<int> get_bits(int mask) {
	vector<int> bb;
	while(mask) { int b = bt(mask); bb.pb(b); mask ^= (1 << b); }
	reverse(all(bb));
	return bb;
}

int get_mask(vector<int> v) {
	int mask = 0;
	for(int x : v) { mask ^= (1 << x); }
	return mask;
}

template<typename T>
void uniq(vector<T> &v) { sort(all(v)); v.resize(unique(all(v)) - v.begin()); }

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll rand(ll l, ll r){
	uniform_int_distribution<ll> uid(l, r);
	return uid(rng);
}

void sc() {}

template <typename Head, typename... Tail>
void sc(Head &H, Tail &... T) { cin >> H; sc(T...); }

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

// #ifndef LOCAL
// string to_string(__int128 x) {
// 	string s = "";
// 	bool neg = 0;
// 	if(x < 0) { s += "-"; neg = 1; x = -x; }
// 	if(!x) s += '0';
// 	while(x) {
// 		int rem = x % 10;
// 		s += to_string(rem);
// 		x /= 10;
// 	}
// 	reverse(s.begin() + neg, s.end());
// 	return s;
// }
// #endif

const int mod = 1e9 + 7; // 998244353;

int pwr(int a,ll b) {
	int ans = 1;
	while(b) {
		if(b & 1) ans = (ans * 1LL * a) % mod;
		a = (a * 1LL * a) % mod;
		b >>= 1;
	}
	return ans;
}

/*
	Lookout for overflows!!
	Check array sizes!!
	Clear before test cases!!
	Use the correct modulo!!
	Check for corner cases!!
	Are you forgetting something?!
	Read problem statement carefully!!!
*/

const int N = 2005;
int pre[3][N][N];
char a[N][N];

int get(int b,int r1,int c1,int r2,int c2) {
    if(r1 > r2 || c1 > c2) return 0;
    r1--, c1--;
    return pre[b][r2][c2] - pre[b][r1][c2] - pre[b][r2][c1] + pre[b][r1][c1];
}

void solve() {
    int n, m, q;
    sc(n, m, q);
    fr(i, 0, n + 1) {
        fr(j, 0, m + 1) {
            a[i][j] = '0';
        }
    }
    fr(i, 1, n) {
        fr(j, 1, m) {
            sc(a[i][j]);
            pre[0][i][j] = pre[0][i - 1][j] + pre[0][i][j - 1] - pre[0][i - 1][j - 1] + (a[i][j] == '1');
            pre[1][i][j] = pre[1][i - 1][j] + pre[1][i][j - 1] - pre[1][i - 1][j - 1] + (a[i][j] == '1' && a[i - 1][j] == '1');
            pre[2][i][j] = pre[2][i - 1][j] + pre[2][i][j - 1] - pre[2][i - 1][j - 1] + (a[i][j] == '1' && a[i][j - 1] == '1');
            debug(i, j, pre[0][i][j]);
        }
    }
    fr(i, 1, q) {
        int r1, c1, r2, c2;
        sc(r1, c1, r2, c2);
        int g1 = get(0, r1, c1, r2, c2);
        int g2 = get(1, r1 + 1, c1, r2, c2);
        int g3 = get(2, r1, c1 + 1, r2, c2);
        debug(g1, g2, g3);
        cout << g1 - g2 - g3 << endl;
    }
}

int main() {
	ios :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	// cin >> t;
	for(int tt = 1; tt <= t; tt++) {
		solve();
	}
	return 0;
}


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

typedef long long ll;
int main() {
    int n, x;
    cin >> n >> x;
    ll a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a, a + n);
    int ans = 0;
    int index = 0;
    while (x > 0 && index < n) {
        if (x >= a[index]) {
            ans++;
            x -= a[index];
            if (index == n - 1 && x > 0) {
                ans--;
                x = 0;
            }
        }
        index++;
    }
    cout << ans;
}

#include <bits/stdc++.h>
using namespace std;
#define INF_LL 1LL << 39
#define INF 100000000
#define MOD 1000000007LL
#define ll long long
#define all(x) x.begin(), x.end()
#define REP(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
#define prique priority_queue
#define PI acos(-1)
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<ll> vl;
typedef vector<vector<int>> matrix;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int sign[2] = {1, -1};
template <class T> bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
struct edge {
    int to, cost;
};

ll dp[202][100010];

signed main() {
    int n, x;
    cin >> n >> x;
    vi s(n);
    rep(i, n) cin >> s[i];
    sort(all(s), greater<int>());
    dp[0][x] = 1;
    rep(i, n) REP(j, 0, x + 1) {
        dp[i + 1][j % s[i]] += dp[i][j];
        dp[i + 1][j] += dp[i][j] * (n - i - 1);
        dp[i + 1][j] %= MOD;
    }
    // rep(i, n + 1) {
    //     rep(j, x + 1) cout << dp[i][j] << " ";
    //     cout << endl;
    // }
    ll res = 0;
    REP(i, 1, x + 1) {
        res += dp[n][i] * i;
        res %= MOD;
    }
    cout << res << endl;
}


#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n;
  string s;
  cin >> n >> s;

  vector<int> w(n + 1, 0), e(n + 1, 0);
  rep(i, 0, n) {
    if (s[i] == 'W')
      w[i + 1] = w[i] + 1;
    else
      w[i + 1] = w[i];
  }

  repr(i, 0, n) {
    if (s[i] == 'E')
      e[i] = e[i + 1] + 1;
    else
      e[i] = e[i + 1];
  }

  int ans = 1e9;
  rep(i, 1, n + 1) {
    // test
    chmin(ans, w[i - 1] + e[i]);
  }

  cout << ans << endl;
}

#include <bits/stdc++.h>

#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(pos,mp) for(ll pos=mp.begin();pos!=mp.end();pos -++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

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

    ll ans = 0;
    rep(left, min(n, k) + 1)rep(right, min(n, k) + 1 - left){
        vector<ll> res = v;
        res.erase(res.begin()+left, res.end()-right);

        sort(ALL(res));

       rep(i, k-left-right){
            if(res.empty() || res.front() >= 0)break;
            res.erase(res.begin());
        }

        ans = max(ans, accumulate(ALL(res), 0LL));
    }

    cout << ans << endl;
}


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

int main() {
  int N;
  cin>>N;
  vector<int> p(60000,1);
  vector<int> q;
  for(int i=2;i<55556;i++){
    if(p[i]){
      for(int j=i*2;j<=55555;j+=i){
        p[j]=0;
      }
      if(i%5==1){
        q.push_back(i);
      }
    }
  }
  for(int i=0;i<N;i++){
    cout<<q[i];
    if(i-1==N){
      cout<<endl;
    }
    else{
      cout<<" ";
    }
  }
}

const int LG = 21;
const int FN = 400005;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;

#include <bits/stdc++.h>

using namespace std;

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

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define pb push_back
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};
string Ans[2] = {"No", "Yes"};
string ANS[2] = {"NO", "YES"};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(FN);
    __ufact.resize(FN);
    __rev.resize(FN);
    __rev[1] = 1;
    for (int i = 2; i < FN; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < FN; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (k < 0 || k > n) return 0;
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

int Root(int x, vector<int> &root)
{
    if (x == root[x]) return x;
    return root[x] = Root(root[x], root);
}

void Merge(int v, int u, vector<int> &root, vector<int> &sz)
{
    v = Root(v, root), u = Root(u, root);
    if (v == u) return;
    if (sz[v] < sz[u])
    {
        sz[u] += sz[v];
        root[v] = u;
    }
    else
    {
        sz[v] += sz[u];
        root[u] = v;
    }
}

int ok(int x, int n)
{
    return 0 <= x && x < n;
}

void bfs(int v, vi &dist, vector<vi> &graph)
{
    fill(all(dist), -1);
    dist[v] = 0;
    vi q = {v};
    for (int i = 0; i < q.size(); i++)
    {
        for (auto u : graph[q[i]])
        {
            if (dist[u] == -1)
            {
                dist[u] = dist[q[i]] + 1;
                q.push_back(u);
            }
        }
    }
}

int A[505][505];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    for (int i = 6; n > 0; i += 5)
    {
        int t = 1;
        for (int j = 2; j < i; j++) if (i % j == 0) t = 0;
        if (t)
        {
            cout << i << " ";
            n--;
        }
    }
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/


//
// Created on 2020/08/10.
//

#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;

int main() {

    int n;
    cin>>n;
    vector<int>L;
    int init;
    cin>>init;
    L.push_back({init});
    for (int i = 1; i < n; ++i) {
        int a;
        cin>>a;
        int ok = L.size() - 1;
        int ng = -1;
        int mid = (ok + ng) / 2;
        while(1 < abs(ok - ng)){
            if(L[mid] < a){
                ok = mid;
            }else{
                ng = mid;
            }
            mid = (ok + ng) / 2;
        }
        if(L[ok] < a){
            L[ok] = a;
        }else if(L[ok] >= a){
            L.push_back(a);
        }}
    cout<<L.size()<<endl;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ASC(x) sort(ALL((x)))
#define DESC(x) sort(ALL((x)),greater<ll>())
#define REV(x) reverse(ALL((x)))
#define pb push_back

int main()
{
    ll H, W;
    cin >> H >> W;
    mat A(H+1, vec(W+1, 0)), B(H+1, vec(W+1, 0));
    REP(i,1,H+1) REP(j,1,W+1) cin >> A[i][j];
    REP(i,1,H+1) REP(j,1,W+1) cin >> B[i][j];

    ll K = 160 * 80;
    bool dp[H+1][W+1][K+1];
    REP(i,0,H+1) {
        REP(j,0,W+1) {
            REP(k,0,K+1) dp[i][j][k] = false;
        }
    }
    dp[0][1][0] = true;
    dp[1][0][0] = true;

    ll d;
    REP(i,1,H+1) {
        REP(j,1,W+1) {
            REP(k,0,K+1) {
                d = abs(A[i][j] - B[i][j]);
                if(k + d <= K) {
                    dp[i][j][k+d] |= dp[i][j-1][k];
                    dp[i][j][k+d] |= dp[i-1][j][k];
                }
                if(abs(k - d) <= K) {
                    dp[i][j][abs(k-d)] |= dp[i][j-1][k];
                    dp[i][j][abs(k-d)] |= dp[i-1][j][k];
                }
            }
        }
    }

    REP(k,0,K) {
        if(dp[H][W][k]) {
            PR(k);
            break;
        }
    }

    return 0;
}

/*

*/


# include <iostream>
using namespace std;

static const int ans[] = {
    0, 3, 14, 39, 84, 155, 258, 399, 584, 819, 1110
};

int main() {
    int a;
    cin >> a;
    cout << ans[a] << endl;
    return 0;
}

#include<iostream>
#include<string>
#include<algorithm>
#include<iterator>

int main(){
	std::string str;

	std::cin >> str;

	std::reverse_copy(str.begin(), str.end(),
		std::ostream_iterator<char>(std::cout,""));
  	std::cout << std::endl;
  	return 0;
}


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

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

ll fac[N << 1], inv[N << 1];
int h, w, a, b;

ll power(ll a, int b) {
	ll ans = 1;
	while(b) {
		if(b & 1) ans = ans * a % mod;
		a = a * a % mod; b >>= 1;
	}
	return ans;
}

ll C(int n, int m) {
	return fac[m] * inv[n] % mod * inv[m - n] % mod;
}

ll Calc(int h, int w) {return C(h - 1, h + w - 2);}

int main() {
	scanf("%d%d%d%d", &h, &w, &a, &b);
	fac[0] = inv[0] = 1;
	a = h - a + 1;
	for(int i = 1; i <= 200000; ++i) fac[i] = 1LL * fac[i - 1] * i % mod;
	for(int i = 1; i <= 200000; ++i) inv[i] = power(fac[i], mod - 2);
	ll ans = 0;
	for(int i = b + 1; i <= w; ++i) {
		ans = (ans + 1LL * Calc(a - 1, i) * Calc(h - a + 1, w - i + 1) % mod) % mod;
	}
	printf("%lld\n", ans);
	return 0;
}

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

int main()
{

    int a,b,c,d,k;
    cin>>a>>b>>c>>d>>k;

    int x  =  (c-a);
    int y  =  (d-b);
    int ans  =  (x*60)+y;
    ans=ans-k;

    cout<<ans<<endl;

}


#include <bits/stdc++.h>
#ifdef local
#define debug(a...) qqbx(#a, a)
template <typename H, typename ...T> void qqbx(const char *s, const H &h, T&&...a) {
    for(; *s && *s != ','; ++s) if(*s != ' ') std::cerr<<*s;
    std::cerr<<" = "<<h<<(sizeof...(T) ? ", " : "\n");
    if constexpr(sizeof...(T)) qqbx(++s, a...);
}
#else
#define debug(...) ((void)0)
#endif // local
#define pb emplace_back
#define all(v) begin(v),end(v)

using namespace std;
const int MOD = 1000000007, N = 200025, inf = 2e9;
int a[N], b[N], ca[N], cb[N];
int A[N], B[N];
signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++) cin >> b[i];
    for(int i = 0; i < n; i++) ++ca[a[i]];
    for(int i = 0; i < n; i++) ++cb[b[i]];
    for(int i = 1; i <= n; i++) if(ca[i] + cb[i] > n) return cout << "No\n", 0;
    for(int i = 1; i <= n; i++) ca[i] += ca[i-1];
    for(int i = 1; i <= n; i++) cb[i] += cb[i-1];
    int mx = 0;
    for(int i = 1; i <= n; i++) mx = max(mx, ca[i] - cb[i-1]);
    cout << "Yes\n";
    for(int i = 0; i < n; i++)
        cout << b[(i+n-mx)%n] << ' ';
    cout << '\n';
}

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

int main(void) {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> A(N);
  unordered_map<int, int> Acnt;
  rep(i, N) {
    cin >> A[i];
    Acnt[A[i]]++;
  }
  vector<int> B(N);
  unordered_map<int, int> Bcnt;
  rep(i, N) {
    cin >> B[i];
    Bcnt[B[i]]++;
  }

  for (auto& a : Acnt) {
    if (Bcnt.count(a.first) && (N < a.second + Bcnt[a.first])) {
      cout << "No" << endl;
      return 0;
    }
  }

  int j = 0;
  int prev = -1;
  rep(i, N) {
    if (prev != A[i]) j = 0;
    if (A[i] == B[i]) {
      for (; j < N; ++j) {
        if (A[i] != A[j] && A[i] != B[j]) {
          swap(B[i], B[j]);
          break;
        }
      }
    }
    prev = A[i];
  }

  cout << "Yes" << endl;
  rep(i, N) {
    if (i != 0) cout << " ";
    cout << B[i];
  }
  cout << endl;
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

#define loop(i,n)for(i=0;i<n;i++)
#define INF 1000000000
using ll = long long int;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;

#define MAX 100005

int main()
{
    IOS;
    //freopen("inputfile.txt","r",stdin);
  ll n;cin>>n;
  ll ar[n];
  ll count = 0;ll mi;
  for(ll i=0;i<n;i++)
  {
      ll x;cin>>x;
      if(i==0)mi = x;
      else if(x>mi)count++;
      else mi = x;
  }
  cout<<n-count<<endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define rep2(i,a,n) for(int i=(a); i<(n); i++)
#define all(vec) vec.begin(),vec.end()
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;

int main(){
  int N; cin >> N;
  vi P(N); rep(i,N) cin >> P[i];
  int count = 0;
  int minA = P[0];
  rep(i,N){
    if (P[i] <= minA) {count++; minA = P[i];}
  }
  cout << count << endl;
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

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

  string s;
  int w;
  cin >> s >> w;
  int n = s.length();

  string ans;
  for (int i = 0; i < n; i += w) {
    ans += s[i];
  }
  cout << ans << '\n';

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a) (a).begin(),(a).end()
#define ll long long
long long min(long long x,long long y){return (x<y ? x:y);}
long long max(long long x,long long y){return (x>y ? x:y);}
#define ld long double
int stoi(string s) {return atoi(s.c_str());}
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
#define LINEY "YES\n"
#define Liney "Yes\n"
#define LINEN "NO\n"
#define Linen "No\n"

int main(){
  int N,K; cin>>N>>K;
  int r = N-K+1;
  printf("%d\n",r);
}


#include <bits/stdc++.h>
#define pb          emplace_back
#define ll          long long
#define fi          first
#define se          second
#define mp          make_pair
#define sz(x)       int(x.size())
//#define int         int64_t

using namespace std;

typedef pair<int, int> pii;
const int N = 302;
const int mod = 998244353;

string s;
int k, n, f[N][N][N];

int DP(int l, int r, int k) {
    if(f[l][r][k] != -1) return f[l][r][k];
    if(r < l) return f[l][r][k] = 0;
    if(l == r) return f[l][r][k] = 1;
    if(l + 1 == r) {
       if(k >= 1 || s[l] == s[r]) return f[l][r][k] = 2;
       return f[l][r][k] = 1;
    }
    int&res = f[l][r][k];
    res = max(DP(l + 1, r, k), DP(l, r - 1, k));
    if(s[l] == s[r]) {
        res = max(res, DP(l + 1, r - 1, k) + 2);
    } else if(k >= 1) {
        res = max(res, DP(l + 1, r - 1, k - 1) + 2);
    }
    return res;
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define Task        "test"
    if(fopen(Task".inp", "r")) {
        freopen(Task".inp", "r", stdin);
        freopen(Task".out", "w", stdout);
    }
    cin >> s >> k; n = sz(s);
    s = ' ' + s;
    memset(&f, -1, sizeof f);
    cout << DP(1, n, k);
}

// luogu-judger-enable-o2
#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#include<bits/stdc++.h>
#define R register
using namespace std;
char s[351];int len,k;
int f[351][351][351],ans;
inline void read(R int &x)
{
    x=0;R int f=1;
	R char c=getchar();
	while(c<'0'||c>'9')
	{
        if(c=='-') f=-1;
        c=getchar();
    }
    while(c>=48&&c<=57)
	{
        x=(x<<1)+(x<<3)+(c^48);
        c=getchar();
    }
	x=x*f;
}
inline void input_data()
{
	char ch=getchar();
	while(ch>='a'&&ch<='z')
		s[++len]=ch,ch=getchar();
	read(k);return;
}
int dfs(R int k,R int l,R int r)
{
	if(l>r) return false;
	if(l==r) return s[l]==s[r];
	if(f[k][l][r]) return f[k][l][r];
	f[k][l][r]=max(dfs(k,l+1,r),dfs(k,l,r-1));
	if(s[l]==s[r]) f[k][l][r]=max(f[k][l][r],dfs(k,l+1,r-1)+2);
	if(k>=1) f[k][l][r]=max(f[k][l][r],dfs(k-1,l+1,r-1)+2);
	return f[k][l][r];
}
int main()
{
	input_data();
	for(R int i=0;i<=k;++i)
		ans=max(ans,dfs(i,1,len));
	printf("%d\n",ans);
	return 0;
}


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

int dummy_prime(int n,int i){return i>1 ? n%i ? dummy_prime(n,i-1) : 0 : 1;}
int isprime(int n){return n>1 ? dummy_prime(n,(int)sqrt(n)) : 0;}

int main(){
	int n;
	while(cin >> n && n){
		while(n>4){
			if(isprime(n) && isprime(n-2)){
				cout << n-2 << " " << n << endl;
				break;
			}
			n--;
		}
	}
}

#include<algorithm>
#include<functional>
#include<cstdio>
#include<iostream>
using namespace std;
int flg[1000000];
int main(void)
{
	int i,j,k,n,f;
	for(i=2;i<=1000000;i++) flg[i]=1;
	for(i=2;i*i<=1000000;i++){
		if(flg[i]==1){
			for(j=2;j*i<1000000;j++) flg[i*j]=0;
		}
	}
	cin>>n;
	while(n) {
		for(i=n;i>=4;i--) {
			if(flg[i]==1&&flg[i-2]==1) {
				cout<<i-2<<" "<<i<<endl;
				break;
			}
		}
		cin>>n;
	}
}


#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

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

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;

  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;

    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }

    res.push_back({i,ex});
  }

  if(n != 1) res.push_back({n,1});

  return res;

}

int main(){
  ll n; cin >> n;
  cout << 180*(n-2) << endl;

}

#include <bits/stdc++.h>

using namespace std;

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

    int n;
    cin >> n;
    cout << n / 3;

    return 0;
}


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

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

int n, k;
int d[11];

inline int nextCombination(int comb)
{
  int x = comb & -comb, y = comb + x;
  return (((comb & ~y) / x) >> 1) | y;
}

template<typename T> inline void _tostr(const T t, string& s){ostringstream o;o<<t;s=o.str();}
template<typename T> inline string _tostr(const T t){ostringstream o;o<<t;return o.str();}
template<typename T> inline void _toint(const string s, T& n){istringstream i(s);i>>n;}
template<typename T> inline T _toint(const string s){istringstream i(s);T n;i>>n;return n;}

int main(int argc, char *argv[])
{
  while(cin >> n, n){
    cin >> k;
    rep(i, n) cin >> d[i];

    vector<string> res;

    for(int comb = (1 << k) - 1; comb < (1 << n); comb = nextCombination(comb)){
      vector<int> vec;
      rep(mask, n) if(comb & 1 << mask) vec.push_back(mask);
      do{
        string s = "";
        rep(i, k) s += _tostr(d[vec[i]]);
        res.push_back(s);
      }while(next_permutation(vec.begin(), vec.begin() + k));
    }

    sort(res.begin(), res.end());
    res.erase(unique(res.begin(), res.end()), res.end());
    cout << res.size() << endl;
  }

  return 0;
}

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

int main(){
    int n, k;
    while(cin >> n >> k){
        if(n + k == 0)  break;
        string x[n];
        for(int i = 0; i < n; i++)  cin >> x[i];
        sort(x, x+n);

        set<int> ans;
        do{
            string tmp = "";
            for(int i = 0; i < k; i++)  tmp = tmp + x[i];
            ans.insert(stoi(tmp));
        }while(next_permutation(x, x+n));

        cout << ans.size() << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  int odd = 0;
  for (int i = 0; i < m; i++) {
    cin >> a[i];
    odd += a[i] & 1;
  }
  if (odd > 2) {
    cout << "Impossible\n";
    return 0;
  }
  for (int i = 0; i < m && odd > 0; i++) {
    if (a[i] & 1) {
      swap(a[i], a[0]);
      odd--;
      break;
    }
  }
  for (int i = m - 1; i >= 0 && odd > 0; i--) {
    if (a[i] & 1) {
      swap(a[i], a[m - 1]);
      odd--;
      break;
    }
  }
  for (int i = 0; i < m; i++) {
    cout << a[i] << ' ';
  }
  cout << '\n';
  vector<int> b;
  for (int i = 0; i < m; i++) {
    b.push_back(a[i] + (i == 0 ? -1 : (i == m - 1 ? 1 : 0)));
  }
  if (m == 1) {
    b.push_back(1);
  }
  cout << (int) b.size() - (b[0] == 0) << '\n';
  for (int i = (b[0] == 0); i < (int) b.size(); i++) {
    cout << b[i] << ' ';
  }
  cout << '\n';
  return 0;
}

////////////////////////// Author
////////////////////////// Nasim Hossain Rabbi
////////////////////////// JU-CSE28
////////////////////////// CF - imnasim3.1415
////////////////////////// UVA - imnasim3.1415
////////////////////////// Mail - imnasim3.1415@gmail.com
#include<bits/stdc++.h>
using namespace std;
#define E end()
#define B begin()
#define sz size()
#define EM empty()
#define fi first
#define se second
#define cl clear()
#define sqr(a) (a*a)
#define mk make_pair
#define po pop()
#define pu push
#define pb push_back
#define pf push_front
#define pob pop_back()
#define pof pop_front()
string en="\n";
string sp=" ";
string t="hello";
string Y="YES\n";
string N="NO\n";
#define rep(i,n) for(i=0;i<n;i++)
#define Rep(i,n) for(i=1;i<=n;i++)
#define per(i,n) for(i=n-1;i>=0;i--)
#define peR(i,n) for(i=n;i>0;i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define all(cont) cont.begin(),cont.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define pi 3.1415926535897932384626433832795
#define vi vector<long long>
#define vs  vector<string>
#define MX LLONG_MAX
#define MN LLONG_MIN
#define MOD 1000000007
#define vp(vi,x) cin>>x; vi.pb(x);
#define bsearch(a,x) binary_search(all(a),x)
#define LB(a,x) (lower_bound(all(a),x)-a.B)
#define UB(a,x) (upper_bound(all(a),x)-a.B)
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
bool isprm(LL a){if(a==1)return false; for(LL i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
bool palin(string a){for(int i=0;i<a.sz;i++){if(a.at(i)!=a.at(a.sz-i-1))return 0;} return 1;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
LL ceil2(LL a,LL b){LL c=a/b; if(a%b)c++; return c; }
LL bpow(LL a,LL b){if(b==0)return 1;LL r=bpow(a,b/2);if(b%2)return r*r*a;else return r*r;}
LL binpow(LL a,LL b){LL r=1;while(b>0){if(b&1)r=r*a;a=a*a;b>>=1;}return r;}
LL binpow(LL a,LL b,LL m){a%=m;LL r=1;while(b>0){if(b&1) r=r*a%m;a=a*a%m; b>>=1;}return r;}
template<typename T>inline T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<typename T>inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
int main()
{
//    fast;
    LL i,j,k,n,m,l,s=0,x,y,tc=1,p,q,a,b,c=0;
    bool f=0,ff=0;string st,s1,s2,s3; char ch;
    while(cin>>n>>m)
    {
        a=b=0;
        bool ar[n+5];
        rep(i,n+5)ar[i]=0;
        map<LL,LL>mp;
        while(m--)
        {
            cin>>p>>st;
            if(ar[p])continue;
            if(st=="AC") a++,ar[p]=1;
            else mp[p]++;
        }
        for(auto it=mp.B;it!=mp.E;it++)
        {
            if(ar[it->fi])b+=it->se;
        }
        cout<<a<<sp<<b<<en;
    }
    return 0;
}


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

char S[1001001];
int D[10], F[10];

int main()
{
	scanf ("%s", S);
	for (int i = 0; i < 10; i++) D[i] = i;

	for (int t = 0; S[t]; t++){
		for (int j = 0; j < 10; j++) F[j] = 1e9;
		for (int j = 0; j < 10; j++) for (int i = 0; i < 10; i++){
			int k = j * 10 + i - (S[t] - '0');
			if (k < 0) continue;
			int c = i + k / 10;
			k %= 10;
			if (F[k] > D[j] + c)
				F[k] = D[j] + c;
		}
		for (int j = 0; j < 10; j++) D[j] = F[j];
	}

	int ans = 1e9;
	for (int j = 0; j < 10; j++) if (ans > D[j] + j) ans = D[j] + j;
	printf ("%d\n", ans);
	return 0;
}

//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF INT_MAX
#define LLINF LLONG_MAX
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007

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

int main() {
	ll ans = 0;
	ll tmp;
	string s;
	cin >> s;
	s = "0" + s;
	int dp[s.size()][2] = {};
	dp[0][0] = 0;
	dp[0][1] = 1;
	REP1(i, s.size()-1){
		int num = s[i] - '0';
		dp[i][0] = min(dp[i-1][0] + num, dp[i-1][1] + 10 - num);
		dp[i][1] = min(dp[i-1][0] + num + 1, dp[i-1][1] + 10 - (num + 1));
	}
	cout << dp[s.size()-1][0] << endl;
}


#include <stdint.h>
#include <cstdlib>
#include <cstring>
#include <string>
#include <map>
#include <vector>
#include <iostream>
#include <bitset>
#include <array>
#include <stdio.h>
using namespace std;

# define MAX 1000
uint64_t D0[MAX]={0}, HP[MAX]={0}, HN[MAX]={0}, VP[MAX]={0}, VN[MAX]={0};
uint64_t Cmap[MAX][20] = {};

int Mayer(size_t M, size_t N, string &a, string &b){
    unsigned int tmax = (M - 1) >> 6;
    unsigned int tlen = M - tmax * 64;
    // cout << "M:" << M << " " << "N:" << N << endl;
    // cout << "tmax:" << tmax << endl;
    // cout << "tlen:" << tlen << endl;

    for(size_t i = 0; i < tmax; ++i) {
        for(size_t j = 0; j < 64; ++j) Cmap[a[i * 64 + j]][i] |= (1L << j);
    }

    for(size_t i = 0; i < tlen; ++i){
        Cmap[a[tmax * 64 + i]][tmax] |= (1L << i);
        // printf("%c\n", a[tmax * 64 + i]);
    }

    int D = tmax * 64 + tlen;

    uint64_t top = (1L << (tlen - 1));
    uint64_t lmb = (1L << 63);
    for(size_t i = 0; i < tmax; ++i) VP[i] = ~0;
    for(size_t i = 0; i < tlen; ++i) VP[tmax] |= (1L << i);

    for(size_t i = 0; i < N; ++i) {
        uint64_t *PM = Cmap[b[i]];
        for(int r = 0; r <= tmax; ++r) {
            uint64_t X = PM[r];
            if(r > 0 && (HN[r - 1] & lmb)) X |= 1L;
            D0[r] = (((X & VP[r]) + VP[r]) ^ VP[r]) | X | VN[r];
            HP[r] = VN[r] | ~(D0[r] | VP[r]);
            HN[r] = D0[r] & VP[r];
            X = (HP[r] << 1L);
            if(r == 0 || HP[r - 1] & lmb) X |= 1L;
            VP[r] = (HN[r] << 1L) | ~(D0[r] | X);
            if(r > 0 && (HN[r - 1] & lmb)) VP[r] |= 1L;
            VN[r] = D0[r] & X;
        }
        if(HP[tmax] & top) ++D;
        else if(HN[tmax] & top) --D;
    }

    // free(D0), free(HP), free(HN), free(VP), free(VN);
    return D;
}

int main() {
    string str1, str2;
    std::cin >> str1 >> str2;
    if(str1.length() > str2.length()){
        string tmp = str1;
        str1 = str2;
        str2 = tmp;
    }

    // int res = edit_distance_fixed_<1000, string, 1000>(str1,str2);
    int res = Mayer(str1.length(), str2.length(), str1, str2);
    std::cout << res << std::endl;
    return 0;
}


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

string field[12];

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

void sol(int x, int y);

int main()
{
  while (cin >> field[0]){
    long ct = 0;
    for (int i = 1; i < 12; i++){
      cin >> field[i];
    }
    for (int i = 0; i < 12; i++){
      for (int j = 0; j < 12; j++){
        if (field[i][j] == '1'){
          field[i][j] = '0';
          sol(i, j);
          ct++;
        }
      }
    }
    cout << ct << endl;
  }
}

void sol(int x, int y)
{
  for (int i = 0; i < 4; i++){
    if (!(0 <= x + dx[i] && 0 <= y + dy[i] && x + dx[i] < 12 && y + dy[i] < 12)) continue;
    if (field[x + dx[i]][y + dy[i]] == '1'){
      field[x + dx[i]][y + dy[i]] = '0';
      sol(x + dx[i], y + dy[i]);
    }
  }
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;

int dp[1 << 16], sum[1 << 16];

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

	int n;
	cin >> n;
	int a[n][n];
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			cin >> a[i][j];
		}
	}
	sum[0] = 0;
	for(int mask = 1; mask < (1LL << n); mask++) {
		vi v;
		for(int i = 0; i < n; i++) {
			if(mask & (1LL << i)) {
				v.pb(i);
			}
		}
		for(int i = 0; i < v.size(); i++) {
			for(int j = i + 1; j < v.size(); j++) {
				sum[mask] += a[v[i]][v[j]];
			}
		}
	}
	memset(dp, -63, sizeof(dp));
	dp[0] = 0;
	for(int mask = 1; mask < (1LL << n); mask++) {
		for(int s = mask; s > 0; s = mask & (s - 1)) {
			dp[mask] = max(dp[mask], sum[s] + dp[mask ^ s]);
		}
	}
	cout << dp[(1 << n) - 1];

	return 0;
}


#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;
#define INF 100000000

typedef long long ll;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
const int MAXN = 1010;

int dp[MAXN][MAXN];

int main(void) {
    string s1, s2;
    cin >> s1;
    cin >> s2;
    for (int i = 0; i <= s1.size(); i++) {
        dp[i][0] = i;
    }
    for (int i = 0; i <= s2.size(); i++) {
        dp[0][i] = i;
    }
    for (int i = 1; i <= s1.size(); i++) {
        for (int j = 1; j <= s2.size(); j++) {
            int cost;
            if (s1[i-1] == s2[j-1]) cost = 0;
            else cost = 1;
            dp[i][j] = dp[i-1][j-1] + cost;
            dp[i][j] = min(dp[i][j], dp[i][j-1] + 1);
            dp[i][j] = min(dp[i][j], dp[i-1][j] + 1);
//            cout << dp[i][j] << "  ";
        }
//        cout << endl;
    }
    cout << dp[s1.size()][s2.size()] << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int n, k;
    cin >> n >> k;
    int ans = 1;
    rep(i,n){
        if (ans * 2 > ans + k)  ans += k;
        else ans *= 2;
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define endl '\n';

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    cout << c  << " " << a << " " << b << endl;
}

#include <bits/stdc++.h>
#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 chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

void	solve()
{
	int n;
	cin >> n;
	if (n == 1)
		cout << "Hello World" << endl;
	else {
		int a, b;
		cin >> a >> b;
		cout << a + b << endl;
	}
}

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

	solve();
}


#include<bits/stdc++.h>
using namespace std;
string a;
int main()
{
	cin>>a;
	if(a.size()==2)
	cout<<a<<endl;
	else
	cout<<a[2]<<a[1]<<a[0]<<endl;
}

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 305;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); }
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
char s[MAXN];
int n, m, ans, dp[MAXN][MAXN][MAXN];
int main() {
	scanf("%s", s + 1);
	n = strlen(s + 1), read(m);
	for (int i = 1; i <= n; i++)
	for (int j = i; j <= n; j++)
	for (int k = 0; k <= n; k++)
		dp[i][j][k] = m + 1;
	dp[1][n][0] = 0;
	for (int i = 1; i <= n; i++)
	for (int j = n; j >= i; j--)
	for (int k = 0; k <= n; k++) {
		int tmp = dp[i][j][k];
		if (tmp == m + 1) continue;
		chkmin(dp[i + 1][j][k], tmp);
		chkmin(dp[i][j - 1][k], tmp);
		if (i == j) chkmax(ans, 2 * k + 1);
		else {
			int cost = s[i] != s[j];
			if (cost + tmp <= m) {
				chkmin(dp[i + 1][j - 1][k + 1], tmp + cost);
				chkmax(ans, 2 * k + 2);
			}
		}
	}
	writeln(ans);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

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

#define TT template<typename T>
TT T    sq(T x){ return x*x; }
TT int  ubnd(vector<T>& v,T x){ return upper_bound(v.begin(), v.end(), x) - v.begin(); }
TT int  lbnd(vector<T>& v,T x){ return lower_bound(v.begin(), v.end(), x) - v.begin(); }
TT void sort(T& v){ sort(v.begin(), v.end()); }
TT void revs(T& v){ reverse(v.begin(), v.end()); }
TT void uniq(T& v){ sort(v); v.erase(unique(v.begin(), v.end()), v.end()); }
TT void show(T& v,char d=' ',char e='\n'){for(int i=0;i<v.size();++i)cout<<v[i]<<((i==v.size()-1)?e:d);}
TT void inpt(vector<T>& v,int n){ v.reserve(n);for(int i=0;i<n;++i){T x; cin>>x; v.push_back(x);} }
TT T    In(T& x){ cin >> x; return x; }

static inline void fast_io(){ ios::sync_with_stdio(0); cin.tie(0); }
static inline int in(){ int x; scanf("%d", &x); return x; }
static inline string instr(){ string x; cin >> x; return x; }
static const int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
static const int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};

struct Rect {
  int h, w, d;
  Rect(int h, int w) : h(h), w(w), d(sq(h) + sq(w)) {}
  bool operator<(const Rect& x) const {
    return d == x.d ? h < x.h : d < x.d;
  }
};

int main()
{
  vector<Rect> v;
  int h, w;
  for (int x = 1; x <= 150; x++){
    for (int y = 1; y < x; y++){
      v.push_back(Rect(y, x));
    }
  }
  sort(v);

  while (h = in(), w = in(), h || w){
    Rect r = Rect(h, w);
    int index = ubnd(v, r);
    printf("%d %d\n", v[index].h, v[index].w);
  }
  return (0);
}

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cmath>

using namespace std;

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

int hikaku(int a,int b,int c,int d){
    int A=a*a+b*b;
    int C=c*c+d*d;

    if(A>C)return 1;
    if(C>A)return -1;
    if(a>c)return 1;
    if(c>a)return -1;
    return 0;
}

int main(void){

    int h,w;

    for(;;){
        cin >> h >> w;
        if(h==0)return 0;
        int retH=1000,retW=1000;
        for(int H=1;H<=150;H++){
            for(int W=H+1;W<=150;W++){
                if(h==H && w == W)continue;

                if(hikaku(h,w,H,W)<0){
                    if(hikaku(H,W,retH,retW)<0){
                        retH=H;
                        retW=W;
                    }
                }

            }
        }
        cout << retH <<" "<<retW<<endl;
    }

       	return 0;
}


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

using namespace std;

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

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

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

    int plug=1;
    int tap=0;
    while(plug<b){
        tap++;
        plug=plug-1+a;
    }

    cout << tap << endl;

    return 0;
}

#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N, M;
  cin>>N>>M;
  int arr[N+1];
  for(int i=0;i<=N;++i) arr[i] = 0;
  int L, R;
  for(int i=0;i<M;++i) {
    cin>>L>>R;
    L--;
    arr[L]++;
    arr[R]--;
  }
  for(int i=1;i<=N;++i) arr[i] += arr[i-1];
  int ans = 0;
  for(int i=0;i<=N;++i) {
    if(arr[i]==M) ans++;
  }
  cout<<ans<<endl;
}


#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

#define ANS(f) if(f) cout << "YES" << endl; else cout << "NO" << endl;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }
void debug(mat m){REP(i, m.size()){ REP(j, m[0].size()){ cout << m[i][j] << ","; } cout << endl; }}

class RMQ_segment_tree
{
    using data_type = int;

public:

    vector<data_type> dat;
    int N;
    data_type inf;

    RMQ_segment_tree(int n, data_type inf): inf(inf) {
        N = 1;
        while(n > N) N = N << 1;
        dat = vector<data_type>(2 * N - 1, inf);
    }

    //k番目の値をaに更新
    void update(int k, data_type a){
        k += N - 1;
        dat[k] = a;
        while(k > 0){
            k = (k - 1) / 2;
            dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
        }
    }

    //[a, b)の最小値
    data_type minval(int a, int b){
        return query(a, b, 0, 0, N);
    }

    data_type query(int a, int b, int k, int l, int r){
        if(r <= a || b <= l) return inf;
        if(a <= l && r <= b) return dat[k];
        else{
            data_type vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
            data_type vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
            return min(vl, vr);
        }
    }
};

signed main(){

    int N, Q, A, B; cin >> N >> Q >> A >> B;
    vec x(Q); readv(x);
    RMQ_segment_tree P(N + 1, INF), M(N + 1, INF);

    P.update(A, llabs(x[0] - B) + A);
    M.update(A, llabs(x[0] - B) - A);
    P.update(B, llabs(x[0] - A) + B);
    M.update(B, llabs(x[0] - A) - B);

    int ans = 0;
    FOR(i, 1, Q){
        int tmp = llabs(x[i] - x[i - 1]);
        ans += tmp;
        int mm = M.minval(0, x[i]) + x[i] - tmp;
        int mp = P.minval(x[i], N + 1) - x[i] - tmp;
        int v = P.minval(x[i - 1], x[i - 1] + 1) - x[i - 1];
        int m = min(v, min(mm, mp));
        P.update(x[i - 1], m + x[i - 1]);
        M.update(x[i - 1], m - x[i - 1]);
    }
    int m = INF;
    FOR(i, 1, N + 1) m = min(m, P.minval(i, i + 1) - i);
    ans += m;
    cout << ans;

    return 0;
}


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

int main(){
  string s;
  cin >> s;
  int n = s.size();
  cout << s.substr(0,n-8) << endl;
  return 0;
}

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    string s;
    int i;

    cin >> s;

    for(i=0; i<s.size(); i++){
        if(i < s.size() - 8){
            cout << s[i];
        }
    }

    cout << endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
using ll = long long;
using pll = pair<ll,ll>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using ld = long double;
using ui = unsigned int;
using ull = unsigned long long;
using ui128 = __uint128_t;
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define lc ind<<1
#define rc ind<<1|1
const int MN = 1e5 + 2, LOG = 17, INF = 1e8;
char s[MN];
int wot[MN];
int main () {
	int n;
	scanf ("%d",&n);
	auto nxt = [&] (int a) {int x = a + 1; return x > n ? 1 : x;};
	auto lst = [&] (int a) {int x = a - 1; return x < 1 ? n : x;};
	scanf ("%s",s+1);
	for (int a = 0; a < 2; a++) {
		for (int b = 0; b < 2; b++) {
			wot[1] = a; wot[2] = b;
			for (int i = 3; i <= n; i++) {
				if ((s[i-1] == 'o' && wot[i-1] == 0) || (s[i-1] == 'x' && wot[i-1] == 1)) wot[i] = wot[i-2];
				else wot[i] = wot[i-2] ^ 1;
			}
			bool ok = 1;
			for (int i = 1; i <= n; i++) {
				if ((s[i] == 'o' && wot[i] == 0) || (s[i] == 'x' && wot[i] == 1)) ok &= wot[nxt(i)] == wot[lst(i)];
				else ok &= wot[nxt(i)] != wot[lst(i)];
			}
			if (ok) {
				for (int i = 1; i <= n; i++) putchar(wot[i]?'W':'S');
				return 0;
			}
		}
	}
	printf ("-1\n");
    return 0;
}

#include <cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<set>
#include<tuple>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
ll n;
vector<vector<P>>v;
bool check(int bit) {
	for (int i = 0; i < n; i++) {
		if (!(bit & (1 << i)))continue;

		for (P id : v[i]) {
			int x = id.first;
			int y = id.second;

			if (y == 1 && !(bit & (1 << x))) {
				return false;
			}

			if (y == 0 && (bit & (1 << x))) {
				return false;
			}
		}
	}
	return true;
}
int main(void) {
	cin >> n;
	v.resize(n);
	for (int i = 0; i < n; i++) {
		int a; cin >> a;
		v[i].resize(a);
		for (int j = 0; j < a; j++) {
			cin >> v[i][j].first >> v[i][j].second;
			--v[i][j].first;
		}
	}

	int res = 0;
	for (int bit = 0; bit < (1 << n); bit++) {

		if (check(bit)) {
			int count = 0;
			for (int i = 0; i < n; i++) {
				if (bit & (1 << i)) {
					count++;
				}
			}
			res = max(res, count);
		}
	}
	cout << res << endl;
	return 0;
}


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

int main() {
  int board = 1;
  int N, K;
  cin >> N >> K;

  int i;
  for(i = 0; i < N; i++){
    if(board > K)
      break;
    board *= 2;
  }
  for(;i < N; i++)
    board += K;

  cout << board << endl;
}

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

int main()
{
    int a, b;
    cin >> a >> b;

    if (a < 9 && b < 9) {
        cout << "Yay!" << endl;
    } else {
        cout << ":(" << endl;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
const int mod = 1e9+7;
const int mx = INT_MAX;
const long double pi = 4*atan((long double)1);
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
#define file "orz"
const int mxN = 2e5+5;
int arr[mxN], st[20][mxN];
int jump(int pos, int x)
{
	for(int i=19;i>=0;i--)
		if((x>>i)&1)
			pos = st[i][pos];
	return pos;
}
int main()
{
    //freopen(file".inp","r",stdin);
    //freopen(file".out","w",stdout);
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    	cin>>arr[i];
    int L;
    cin>>L;
    for(int i=1;i<=n;i++)
    {
    	int l = ub(arr+1,arr+n+1,arr[i]+L)-arr-1;
		st[0][i]=l;
	}
	for(int i=1;i<20;i++)
		for(int j=1;j<=n;j++)
			st[i][j]=st[i-1][st[i-1][j]];
	int q;
	cin>>q;
	while(q--)
	{
		int x,y;
		cin>>x>>y;
		if(x>y)
			swap(x,y);
		int l=0, r=n;
		while(l<r)
		{
			int mid=(l+r)>>1;
			if(jump(x,mid)>=y)
				r = mid;
			else
				l = mid+1;
		}
		cout<<r<<endl;
	}
}

#include<iostream>
#include<string>

using namespace std;

int main() {
	string str, cmd;
	int a, b, q;
	cin >> str >> q;
	for (int i = 0; i < q; i++) {
		cin >> cmd >> a >> b;
		if (cmd == "print") {
			for (int j = a; j <= b; j++)
				cout << str[j]; cout << endl;
		}
		else if (cmd == "reverse") {
			int fend = (b - a + 1) / 2;
			for (int j = 0; j < fend; j++)
				swap(str[a++], str[b--]);
		}
		else if (cmd == "replace") {
			string p; int n = 0;
			cin >> p;
			for (int k = a; k <= b; k++) {
				str[k] = p[n++];
			}
		}
	}
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define f first
#define s second
using namespace std;

int main(){
   int x, y;
   cin >> x >> y;
   int a[100]; memset(a,0,sizeof(a));
   bool ok = true;
   int cnt = 0;
   for(int i = 1; i <= 16; i++){
   	cnt++;
   	if(cnt > 100){
   	 	ok = false; break;
   	}
   	int prev = i-1;
   	if(prev < 1)prev = 16;
    	if(a[i] == 0 && a[prev] != 1){
    	 	a[i] = 1;
    	 	x--;
    	 	if(x == 0)break;
    	}
    	if(i == 16)i = 0;
   }
   cnt = 0;

   for(int i = 1; i <= 16; i++){
		cnt++;
		int prev = i-1;
		if(prev < 1)prev = 16;
		if(cnt > 100){
		 	ok = false; break;
		}
		if(a[i] == 0 && a[prev] != 2){
		 	a[i] = 2;
		 	y--;
		 	if(y == 0)break;
    	}
    	if(i == 16)i = 0;
   }
   cout << (ok ? "Yay!" : ":(") << endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0 ,-1};
signed main(){
    int A,B;
    cin >> A >> B;
    if(A <= 8 && B <= 8) {
        cout << "Yay!" << endl;
    }
    else {
        cout << ":(" << endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;

    }else{
        return a.second < b.second;
    }
}

bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};
vector<ll>m(1002);
vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
        m[a]+=ex;
    }

    // 最後に残った数について
    if (N != 1){
        res.push_back({N, 1});
        m[N]++;
    }
    return res;
}

int main() {
    ll N;
    cin >>N;
    rep2(i,N){
        prime_factorize(i);
    }
    ll ans=1;
    rep2(i,N){
        ans= (ans*(m[i]+1))%mod;
    }
    cout << ans << endl;

    return 0;

}

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

int main() {
  ll n;cin>>n;
  string s;
  while(n){
    n--;
    s+=(char)('a'+n%26);
    n/=26;
  }
  reverse(all(s));
  cout<<s<<endl;
}


#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int>PA;
using namespace std;
#define MAX  999999
int main(){
    int n,s;
    while(cin >> n >> s,n+s){
        int temp = s;
        vi v(n,0); int count = 0; bool check = true;
        while(true){
            if(s != 0){s-=1;v[count]++; if(v[count] == temp){cout << count << endl; break;}
            }else if(s == 0){
                s+=v[count]; v[count] = 0;
            }
            if(count == n-1)
                count =0;
            else
                count++;

        }
    }
}

#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,p,P;
  int have[50];
  int remain=0;
  int plase=0;
  while(1){
    for(int i=0;i<50;i++){
      have[i]=0;
    }
    cin>>n>>p;
    P=p;
    plase=0;
    if(n==0 && p==0) break;
    while(1){
      if(have[plase%n]==P) break;
      if(p==0){
	p=have[plase%n];
	have[plase%n]=0;
	plase++;
      }else{
	have[plase%n]++;
	plase++;
	p--;
      }
    }
    cout<<plase%n<<endl;
  }
  return 0;
}


#include<bits/stdc++.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
using namespace std;
const int N=1000005;
int n,pos,ans,head,tail,q[N];
char s[N],t[N];
int main(){
    scanf("%d%s%s",&n,s+1,t+1);
    if(!strcmp(s+1,t+1)){
        puts("0");
        return 0;
    }
    pos=n;
    head=1,tail=0;
    for(int i=n;i>=1;i--){
        if(t[i]==t[i-1]){
            continue;
        }
        pos=min(pos,i);
        while(pos&&t[i]!=s[pos]){
            pos--;
        }
        if(!pos){
            puts("-1");
            return 0;
        }
        while(head<=tail){
            if(q[head]-(tail-head+1)+1>i){
                head++;
            }else{
                break;
            }
        }
        q[++tail]=pos;
        if(i!=pos){
            ans=max(ans,tail-head+1);
        }
    }
    printf("%d\n",ans+1);
    return 0;
}

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

int main() {
    //
    int num, l;
    int sum = 0;
    int small = 999999;

    cin >> num >> l;

    for (int i = 1; i <= num; i++) {
        int tmp;
        tmp = l + i - 1;
        sum += tmp;
        if (abs(tmp) < abs(small)) small = tmp;
    }

    cout << sum - small;
    //
}


#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int main(){
   double x1,x2,y1,y2;
   double d;
   cin >> x1 >> y1 >> x2 >> y2;

   d = (double)sqrt(((x2-x1)*(x2-x1))+((y2-y1)*(y2-y1)));
   printf("%.6lf\n",d);

   return 0;
}

#include "bits/stdc++.h"
using namespace std;
using ll = long long; using ull = unsigned long long;
#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9+7;
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
signed main(){
  cout << fixed << setprecision(10);
  double a,b;
  cin >> a >> b;
  complex<double> c = {a,b};
  cin >> a >> b;
  complex<double> d = {a,b};
  cout << abs(c-d) << endl;
}


#include<iostream>
#include<vector>
#include<map>
#include<utility>
#include<algorithm>
#include<queue>
#include<stack>
#include<string>
#include<stdlib.h>
#include<stdio.h>
#include<cmath>
#include<cstdlib>
#include<typeinfo>
#include<sstream>
#include<list>
#include<set>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define fori(i,k,n) for(int i=k;i<(int)n;i++)
using namespace std;
int in()
{
	int x;cin>>x;
	return x;
}
int stringInt(string a)
{
	return atoi(a.c_str());
}
string intString(int a)
{
	stringstream ss;
	ss<<a;
	return ss.str();
}
vector<int> SieveOfEratosthenes(int x)
{
	vector<int> a;
	vector<int> b(x+1,0);
	for(int i=2;i<=x;i++)
	{
		if(b[i]==0)
		{
			a.push_back(i);
			for(int l=i;l<=x;l+=i)
			{
				b[l]=1;
			}
		}
	}
	return a;
}

int main ()
{
	int n,m;
	while(cin>>n>>m&&n&&m)
	{
		vector<long long > a,b;
		b.push_back(0);
		rep(i,n)
		{
			b.push_back(in());
		}
		rep(i,n+1)
		{
			rep(l,n+1)
			{
				a.push_back(b[i]+b[l]);
			}
		}
		long long ans = 0;
		sort(a.begin(),a.end());
		rep(i,a.size())
		{
			vector<long long>::iterator t=upper_bound(a.begin(),a.end(),m-a[i]);
			if(t==a.begin())continue;
			t--;
			ans=max(ans,*t+a[i]);
		}
		cout<<ans<<endl;

	}

}


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

int main(){
	int n;
	cin>>n;
	vector<int> a;
	for(int i=1;i<=n;++i){
		if(i%3==0)
			a.push_back(i);
		else if(i%10==3)
			a.push_back(i);
		else if(i/10%10==3)
			a.push_back(i);
		else if(i/100%10==3)
			a.push_back(i);
		else if(i/1000%10==3)
			a.push_back(i);

	}
	sort(a.begin(),a.end());
	for(int i=0;i<a.size();++i){
	cout<<" "<<a[i];
	}
	cout<<endl;

	return 0;
}

/*void call(int n){
  int i = 1;
 CHECK_NUM:
  int x = i;
  if ( x % 3 == 0 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
 INCLUDE3:
  if ( x % 10 == 3 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
  x /= 10;
  if ( x ) goto INCLUDE3;
 END_CHECK_NUM:
  if ( ++i <= n ) goto CHECK_NUM;

  cout << endl;

}

int main()
{
	call(30);
}*/

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

void call(int);

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

    call(n);

    return 0;
}

void call(int n)
{
    for (int i = 1; i <= n; i++)
    {
        if (i % 3 == 0)
        {
            cout << " " << i;
            continue;
        }
        else if (i % 10 == 3 || (i / 10) % 10 == 3 || (i / 100) % 10 == 3 || (i / 1000) % 10 == 3 || (i / 10000) % 10 == 3)
        {
            cout << " " << i;
            continue;
        }
    }
    cout << endl;
}


//Tonight's the night and it is going to happen again and again.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define T ll t; cin>>t; while(t--)
#define mod 1000000007
#define inf 1000000000000000000
#define mem(name,val) memset(name,val,sizeof(name))
#define f(n) for(ll i=0;i<n;i++)
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define endl "\n"
ll gcd(ll a,ll b){if(b==0){return a;}return gcd(b,a%b);}
int main()
{
   ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
   #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
   #endif
   int n;ll sum=0;cin>>n;int a[n];
   f(n){cin>>a[i];}
   rep(i,1,n)
   {
    if(a[i]<a[i-1]){sum+=a[i-1]-a[i];a[i]=a[i-1];}
   }
   cout<<sum;
}

#include<bits/stdc++.h>
#define int long long int
#define mod 998244353
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
int32_t main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output1.txt","w", stdout);
    #endif
    int n;
    cin>>n;
    int a[n];
    for (int i = 0; i < n; ++i)
    {
        cin>>a[i];
    }
    int ans=0,s;
    s=a[0];
    for (int i = 1; i < n; ++i)
    {
        s=max(s,a[i]);
        ans+=(s-a[i]);
    }
    cout<<ans;
    #ifndef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
    return 0;
}


#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
const long long INF = 1LL << 60;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int K,T;
  cin >> K >> T;
  vector<int> a(T);
  rep(i,T) cin >> a[i];
  sort(ALL(a));
  int sum = 0;
  rep(i,T-1)
  {
    sum += a[i];
  }
  if(sum>a[T-1])
  {
    cout << 0 << endl;
  }
  else
  {
    cout << a[T-1] - sum - 1 << endl;
  }
  return 0;
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int n,m;cin >> n >> m;
  vector<int> a(m);
  rep(i,m) cin >> a[i];
  vector<vector<int>> dp(m+1, vector<int>(n+1, -1));
  sort(a.begin(), a.end());
  vector<int> b = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
  dp[0][0] = 0;
  rep1(i,m) {
    rep(j,n+1) {
      if(j - b[a[i-1]] >= 0) {
	if(dp[i][j - b[a[i-1]]] != -1) {
	  dp[i][j] = max(dp[i][j - b[a[i-1]]] + 1, dp[i-1][j]);
	}
	else dp[i][j] = dp[i-1][j];
      }
      else dp[i][j] = dp[i-1][j];
    }
  }

  // rep(i,m+1) {
  //   rep(j,n+1) {
  //     cout << dp[i][j] << " ";
  //   }
  //   cout << "\n";
  // }

  int x = m, y = n;
  while(y > 0 ) {
    if(y - b[a[x-1]] >= 0) {
      if( dp[x][y] - 1 == dp[x][y - b[a[x-1]]] ) {
	cout << a[x-1];
	y -= b[a[x-1]];
      }
      else x--;
    }
    else x--;
  }
  cout << "\n";
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    string str;
    int num,rest=0,result=0;
    cin>>str;
    for(long int i=str.size()-1;i>=0;i--){
        num=str[i]-'0'+rest;
        if(num<(10-num) || (num==5 && str[i-1]<'5')){
            rest=0;
            result+=num;
        }
        else{
            rest=1;
            result+=(10-num);
        }
    }
    result+=rest;
    cout<<result;
}

#include <bits/stdc++.h>

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

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

    string s;
    cin >> s;

    int64_t m = s.size();

    vector a(1, 0L);
    int64_t t = 0;
    for (auto c : s) {
        if (c == '0') {
            a.push_back(t);
        } else {
            ++t;
        }
    }
    a.push_back(t);

    int64_t k;
    cin >> k;
    k = min(k, a.back());

    int64_t n = a.size();

    constexpr auto M = 998244353L;

    vector dp(vector(k + 1, vector(a.back() + 1, 0L)));
    int64_t mk = 0;
    dp[0][0] = 1;
    for (auto i : irange(0L, n - 1)) {
        for (auto j : irange(mk, -1L, -1L)) {
            auto r = min(k - j, a[i + 1] - a[i]);
            for (auto d : irange(1L, r + 1L)) {
                auto w = j + d;
                for (auto c : irange(0L, a.back() - a[i + 1] + 1)) {
                    auto b = c + d;
                    dp[w][c] += dp[j][b];
                    if (dp[w][c] >= M) {
                        dp[w][c] -= M;
                    }
                }
            }

            for (auto c : irange(1L, a.back() - a[i + 1] + 1)) {
                dp[j][c] += dp[j][c - 1];
                if (dp[j][c] >= M) {
                    dp[j][c] -= M;
                }
            }
        }
        mk = min(k, mk + a[i + 1] - a[i]);
    }

    int64_t ans = 0;
    for (auto i : irange(0L, mk + 1)) {
        ans += dp[i][0];
    }

    cout << ans % M << "\n";
}


#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end()
#define rep(i, K, N)  for(long long int i = K; i < N; i++)
#define ll long long int
using namespace std;

int main(){
ll N, Ans = 1000000000, K;cin >> N >> K;
bool C = 0;
vector<ll> n;
vector<ll> p{0};

rep(i, 0, N){

    ll a;cin >> a;

    if(a == 0)continue;

    if(a > 0)C = 1;

    if(C)p.push_back(a);

    else n.push_back(a);

}

n.push_back(0);
reverse(ALL(n));

if(p == n && p.size() == 1){cout << 0;exit(0);}

//for(auto q : n)cout << q << endl;

int A = K - n.size() + 1, B = K, D = p.size() - 1;

for(ll i = max(A, 0); i <= min(B, D); i++){

    Ans = min(Ans, min(2*p[i] + abs(n[K - i]), 2*abs(n[K - i]) + p[i]));

}

cout << Ans;

}

#define _GLIBCXX_DEBUG

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

//loops
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define OneToN(i,n) for(ll i=1;i<(ll)(n+1);i++)
#define ZeroToN(i,n) for(ll i=0;i<(ll)(n+1);i++)
#define AToB(i,a,b) for(ll i=a;i<(ll)(b+1);i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)

//bitsearch
#define BITSEARCH(bit, n) for (int bit = 0; bit < (1<<n); ++bit)
#define isOne(bit, i) bit & (1<<i)

//arrays
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define add push_back

template<typename T>
std::vector<T> slice(std::vector<T> const &v, int m, int n)
{
    auto first = v.cbegin() + m;
    auto last = v.cbegin() + n + 1;

    std::vector<T> vec(first, last);
    return vec;
}

//v need to be sorted
#define remove_unique(v) v.erase(unique(ALL(v)), v.end())

//comparision
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 (a>b) { a=b; return 1; } return 0; }

//pair
#define fir first
#define sec second
#define mp make_pair

//types
#define ll long long
#define vec vector
#define cord2d pair<int,int>
#define intP pair<int, int>

//UNCOMMENT WHEN NEEDED
//#define int ll

//input
template <class T> T get(){ T s; cin >> s; return(s);}
#define gi get<int>()
#define gs get<string>()
#define gll get<ll>()

template <class T> vector<T> getv(int n) { vec<T> v(n); REP(i, n) cin >> v[i]; return v; }
#define gim(n) getv<int>(n)
#define gsm(n) getv<string>(n)
#define gllm(n) getv<ll>(n)

//output
void print(int a){ cout << a << endl; }
void print(long long a){ cout << std::fixed << a << endl; }
void print(string a){ cout << a << endl; }
void print(char a){ cout << a << endl; }
void print(double a){ cout << a << endl; }
void print(double a, int dig){ cout << std::setprecision(dig) << a << endl; }

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

template <class T = int>
void print(vec<T> v){ cout << v << endl; }

template <class T = int>
void print2dVec(vec<vec<T>> v2d){for(vec<T> v: v2d) {print(v);}}

void YesNo1(bool i = true){ return print(i?"Yes":"No"); }
void YESNO2(bool i = true){ return print(i?"YES":"NO"); }

//debug output
#define var_name(var) #var
template <class T> void debug(T &var, int nest = 0, string before = "") { cout << string("          ", nest) << before; print(var); }

//name replacement
#define y0 y0__
#define y1 y1__
#define j0 j0__
#define j1 j1__

//bool lambdas
#define lamb(exp) [](auto i){return exp;}
#define isEven [](int i){return i % 2 == 0;}
#define isOdd [](int i){return i % 2 != 0;}

//constants
const ll INF = 1e18;
const int MOD = 1000000007;
const vec<string> alphabets = { "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z" };

//maths
int factorial(int k){ int sum = 1; for (int i = 1; i <= k; ++i) { sum *= i; } return sum; }

ll gcd(ll a, ll b) { if (b == 0) { return a; } return gcd(b, a % b); }
ll lcm(ll a, ll b) { ll temp = gcd(a, b); return temp ? (a / temp * b) : 0; }

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

void Main() {
    //code here

    int n = gi, k = gi;
    vec<int> nums = gim(n);

    int minDif = INT_MAX;

    REP(i, n-k+1) {
        int l = i;
        int r = l+k-1;
        int dif = min(abs(nums[r]), abs(nums[l])) + abs(nums[l]-nums[r]);
        chmin(minDif, dif);
    }
    print(minDif);
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Main();
}


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

vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  return (ret);
}

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

    int64_t n,a,b,c; cin>>n>>a>>b; if(n==3)cin>>c;
    vector<int64_t> v;
    for(auto t:divisor(a))if(!(b%t))v.push_back(t);
    if(n==3)for(auto t:v)if(c%t)v.erase(find(v.begin(),v.end(),t));
    sort(v.begin(),v.end());
    for(auto t:v)cout<<t<<'\n';
}

// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
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; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

vi divisors(int n) {
  vi v;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      v.pb(i);
      if (n != 1 && i * i != n) v.pb(n / i);
    }
  }
  sort(all(v));
  return v;
}

void solve() {
  int n;
  cin >> n;
  vi a(n);
  rep(i, n) cin >> a[i];
  vvi x;
  transform(all(a), back_inserter(x), [](int x) {
    return divisors(x);
  });
  vi ds = accumulate(x.begin() + 1, x.end(), x.front(), [](vi a, vi x) {
    vi w;
    set_intersection(all(a), all(x), back_inserter(w));
    return w;
  });
  for (auto x : ds) cout << x << endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll N, O = 0;
  cin >> N;
  for (ll i = 0; i <= N; i++) {
    if (i % 3 != 0 && i % 5 != 0) {O += i;}
  }
  cout << O << endl;
}


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

int main(void) {
  int n; ll x, cnt=0;
  cin >> n >> x;
  ll a[n];
  rep(i,n) cin >> a[i];

  rep(i,n-1) {
    if(a[i+1] > 0) {
      if(a[i]+a[i+1]>x) {
        cnt += (min(a[i+1],a[i]+a[i+1]-x));
        a[i+1] -= min(a[i+1],a[i]+a[i+1]-x);
      } else ;
    }
    if(a[i]>0) {
      if(a[i]+a[i+1]>x) {
        cnt += (min(a[i],a[i]+a[i+1]-x));
        a[i] -= min(a[i],a[i]+a[i+1]-x);
      } else ;
    }
  }
  //rep(i,n) cout << a[i] << endl;
  cout << cnt << endl;
}

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

int main() {
  long long int N, X;
  cin >> N >> X;
  vector<long long int> A(N);
  long long int ans = 0;
  for (long long int i = 0; i < N; i++) cin >> A.at(i);
  for (long long int i = 1; i < N; i++) {
    if (A.at(i) + A.at(i - 1) > X) {
      ans += A.at(i) + A.at(i - 1) - X;
      if (A.at(i - 1) > X) {
        A.at(i - 1) = X;
        A.at(i) = 0;
      }
      else {
        A.at(i) = X - A.at(i - 1);
      }
    }
  }
  cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define int  long long int
#define fi first
#define se second
#define pb push_back
#define soo(v) sort(v.rbegin(),v.rend())
#define so(v) sort(v.begin(),v.end())
#define lb(v,x) lower_bound(v.begin(),v.end(),x)
#define ub(v,x) upper_bound(v.begin(),v.end(),x)
#define endl '\n'
#define dbv(v) cout<<endl;cout<<#v<<"-->> ";for(auto it:v){cout<<it<<" ";}cout<<endl;
#define dbm(m)cout<<endl;cout<<#m<<"-->> ";for(auto it:m){cout<<it.fi<<" "<<it.se.fi<<" "<<it.se.se<<endl;}
#define dbs(s)cout<<endl;cout<<#s<<"-->> ";for(auto it:s){cout<<it<<" ";}cout<<endl;
#define mod 1000000007
#define db1(x) cout<<#x<<"="<<x<<endl;
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl;
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<endl;
#define mx 1e18
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v)  *min_element(v.begin(),v.end())
#define double long double
int powe(int x,int n)
{
  if(n==0)return 1;
  if(n%2==0)
    return powe((x%mod*x%mod)%mod,n/2)%mod;
  return (x%mod*powe((x%mod*x%mod)%mod,(n-1)/2))%mod;
}
int gcd(int A,int B)
{
  if(B==0)return A;
  return gcd(B,A%B);
}
#define io std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define re(s) reverse(s.begin(),s.end())
int32_t main()
{
    io
int a;
cin>>a;
cout<<a*(1+a+a*a)<<endl;
}

#include <bits/stdc++.h>
using namespace std;
double solve(vector<vector<vector<double>>> &dp,int a, int b, int c, int n) {
  if (dp[a][b][c]) return dp[a][b][c];
  if (!a&&!b&&!c) return 0;
  dp[a][b][c] = 1.0*n/(a+b+c);
  if (a) dp[a][b][c] += solve(dp,a-1,b,c,n)*a/(a+b+c);
  if (b) dp[a][b][c] += solve(dp,a+1,b-1,c,n)*b/(a+b+c);
  if (c) dp[a][b][c] += solve(dp,a,b+1,c-1,n)*c/(a+b+c);
  return dp[a][b][c];
}
int main() {
  int N;
  cin >> N;
  int ones = 0, twos = 0, threes = 0, a;
  vector<vector<vector<double>>> dp(N+1,vector<vector<double>>(N+1,vector<double>(N+1)));
  for (int i = 0; i < N; i++) {
    cin >> a;
    ones += a == 1;
    twos += a == 2;
    threes += a == 3;
  }
  cout.precision(20);
  cout << solve(dp,ones,twos,threes,N);
}


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

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

signed main(){
    int N; cin>>N;
    vec_int A(N);
    rep(i,N)cin>>A.at(i);

    int status = 1;
    int tot = 0;
    for(int i=N-1;i>-1;i--){
        if(A.at(i)>i){
            cout<<-1<<endl;
            return 0;
        }

        if(status==1){
            tot += A.at(i);
            if(i>0){
                if(A.at(i-1)<A.at(i)){
                    status=0;
                    if(A.at(i)-A.at(i-1)>1){
            cout<<-1<<endl;
            return 0;

                    }
                }
            }
        }else{
            if(i>0){
                if(A.at(i-1)>=A.at(i))status=1;
            }
        }
    }
    cout<<tot<<endl;

    return 0;
}

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

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

#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD
ll inv(ll a);
// (a+b+c)%MOD
ll madd(ll a, ll b, ll c);
// (a-b)%MOD
ll msub(ll a, ll b);
// (a*b*c)%MOD
ll mtime(ll a, ll b, ll c);

int main() {
    ll n, ans = 0; cin >> n;
    vector<ll> a(n), b(n, 0);
    rep(i, n) cin >> a[i];
    if(a[0] != 0) {
        cout << -1 << endl;
        return 0;
    }
    else {
        rep(i, n-1) {
            if(a[i]+1 < a[i+1]) {
                cout << -1 << endl;
                return 0;
            }
        }
        rep(i, n) {
            b[i-a[i]]++;
        }
        ll index = 0;
        rep(i, n) {
            rep(j, b[i]) {
                a[index] = i;
                index++;
            }
        }
        set<ll> s;
        rep(i, n) {
            if(!s.count(a[n-1-i])) {
                s.insert(a[n-1-i]);
                ans += (n-1-i) - a[n-1-i];
            }
        }
        cout << ans << endl;
    }
    return 0;
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) {
    if(n == 0) return 1;

    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count));
}

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

ll inv(ll a) {
    return a_n(a, MOD-2);
}

ll madd(ll a, ll b, ll c) {
    ll ret = (a+b) % MOD;
    return (ret+c) % MOD;
}

ll msub(ll a, ll b) {
    if(a < b) return (a-b+MOD) % MOD;
    else return (a-b) % MOD;
}

ll mtime(ll a, ll b, ll c) {
    ll ret = (a*b) % MOD;
    return (ret*c) % MOD;
}


#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  string S;
  int w;
  cin >> S >> w;
  int i = 0;
  string ans = "";
  ans += S[0];
  while (i + w < S.length()) {
    i = i + w;
    ans += S[i];
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
	string S;
	int w;
	cin >> S >> w;
	rep(i, S.size()) {
		if (i % w == 0) {
			cout << S.at(i);
		}
	}
	cout << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,k;cin>>n>>k;
    vector<ll> x(n);rep(i,n)cin>>x[i];
    ll ans = INF;
    for(int i=0; i+k-1<n; i++){
        ll l = x[i], r = x[i+k-1];
        ll a;
        if(r<0)a=-l;
        else if(l<0)a=min(r-2*l, 2*r-l);
        else a=r;
        ans = min(ans, a);
    }
    cout<<ans<<endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, e) for (int i = s; i < e; ++i)
#define sort_(a) stable_sort(a.begin(), a.end())
#define rsort(a) stable_sort(a.rbegin(), a.rend())
#define sum(a) accumulate(a.begin(), a.end(), 0LL)
#define join(a, d) accumulate(a.begin() + 1, a.end(), a[0], [](string s, string t) {return s + d + t;})
#define all(a) a.begin(), a.end()
// #define __lcm(a, b) std::__detail::__lcm(a, b)
typedef long long ll;
const long mod = 1e9 + 7;

ll lcm(ll x, ll y) {
    return x / __gcd(x, y) * y;
}

int main(void) {
#ifdef DEBUG
  freopen("input.txt", "r", stdin);
#endif

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

  long N, K;
  cin >> N >> K;
  vector<long> A(N);
  rep(i, 0, N) cin >> A[i];
  long maxa = accumulate(all(A), A[0], [](long x, long y) {return max(x, y);});
  if (maxa < K) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }
  long gcd1 = accumulate(all(A), A[0], [](long x, long y) {return __gcd(x, y);});
  long gcd2 = __gcd(gcd1, K);
  if (gcd1 == gcd2) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
  return 0;
}