#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
template<typename T> auto compare = [](T x, T y) -> bool{return (x < y);};
const int MOD = 1000000007;

int N, a[100010];
string S;

signed main(){
    cin >> N >> S;
    REP(st, 4){
        if(st & 1){
            a[0] = 1;
            if(st & 2) a[N - 1] = 1;
            else a[N - 1] = 0;
        }else{
            a[0] = 0;
            if(st & 2) a[N - 1] = 1;
            else a[N - 1] = 0;
        }
        REP(i, N){
            if(a[i] == 0){
                if(S[i] == 'o') a[(i + 1 + N) % N] = a[(i - 1 + N) % N];
                else a[(i + 1 + N) % N] = 1 - a[(i - 1 + N) % N];
            }else{
                if(S[i] == 'o') a[(i + 1 + N) % N] = 1 - a[(i - 1 + N) % N];
                else a[(i + 1 + N) % N] = a[(i - 1 + N) % N];
            }
        }
        if(st & 1){
            if(a[0] == 0) continue;
            if(st & 2){
                if(a[N - 1] == 0) continue;
            }else{
                if(a[N - 1] == 1) continue;
            }
        }else{
            if(a[0] == 1) continue;
            if(st & 2){
                if(a[N - 1] == 0) continue;
            }else{
                if(a[N - 1] == 1) continue;
            }
        }
        REP(i, N){
            if(a[i] == 0) cout << "S";
            else cout << "W";
        }
        cout << endl;
        return 0;
    }
    PRINT("-1");
    return 0;
}

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 <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <time.h>
#include <unordered_set>
#include <bitset>
#include <deque>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> 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 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};

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 (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

const int N = 100500;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    string S;
    cin >> n >> S;
    for (int a = 0; a < 2; a++)
    {
        for (int b = 0; b < 2; b++)
        {
            string s(n, ' ');
            if (a == 0) s[0] = 'S'; else s[0] = 'W';
            if (b == 0) s[1] = 'S'; else s[1] = 'W';
            for (int i = 1; i + 1 < n; i++)
            {
                if ((s[i] == 'S' && S[i] == 'o') || (s[i] == 'W' && S[i] == 'x')) s[i + 1] = s[i - 1];
                else s[i + 1] = 'S' + 'W' - s[i - 1];
            }
            int t = 1;
            if ((s.back() == 'S' && S.back() == 'o') || (s.back() == 'W' && S.back() == 'x')) t &= (s[n - 2] == s[0]);
            else t &= (s[n - 2] != s[0]);
            if ((s[0] == 'S' && S[0] == 'o') || (s[0] == 'W' && S[0] == 'x')) t &= (s[1] == s.back());
            else t &= (s[1] != s.back());
            if (t) cout << s, exit(0);
        }
    }
    cout << -1 << "\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.
*/


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;
/* ちゃんと考えてわかって実装 */

// O(\sqrt{n})
vector<ll> divisor(ll n){
    vector<ll> res;
    for(ll i=1; i*i <= n; i++){
        if(n%i == 0){
            res.push_back(i);
            if(i != n / i) res.push_back(n / i);
        }
    }
    return res;
}

int main(void){
    ll n, m;
    cin >> n >> m;
    vector<ll> divs = divisor(m);
    sort(divs.begin(), divs.end());

    ll ans;
    for(ll i=0; i<divs.size(); i++){
        if(divs[i] * n <= m){
            ans = divs[i];
        }
    }
    cout << ans << endl;
    return 0;
}

#include<cstdio>
#include<utility>
#include<iostream>
#define RI register int
#define CI const int&
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef pair <int,int> pi;
const int N=1005,dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
inline char get_ch(void)
{
	char ch; while (ch=getchar(),ch!='#'&&ch!='.'); return ch;
}
int n,m,stp[N][N],ans; pi q[N*N];
int main()
{
	RI i,j,H=0,T=0; for (scanf("%d%d",&n,&m),i=1;i<=n;++i)
	for (j=1;j<=m;++j) if (get_ch()=='#') q[++T]=mp(i,j); else stp[i][j]=1e9;
	while (H<T)
	{
		int nx=q[++H].fi,ny=q[H].se; for (i=0;i<4;++i)
		{
			int tx=nx+dx[i],ty=ny+dy[i];
			if (tx>=1&&tx<=n&&ty>=1&&ty<=m&&stp[tx][ty]>stp[nx][ny]+1)
			stp[tx][ty]=stp[nx][ny]+1,q[++T]=mp(tx,ty);
		}
	}
	for (i=1;i<=n;++i) for (j=1;j<=m;++j) ans=max(ans,stp[i][j]);
	return printf("%d",ans),0;
}


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

const lld N = 200043;
const lld MOD = 1000000007;

lld add(lld x, lld y)
{
    x =((x%MOD)+(y%MOD))%MOD;
    while(x >= MOD) x -= MOD;
    while(x < 0) x += MOD;
    return x;
}

lld mul(lld x, lld y)
{
    return ((x%MOD)*(y%MOD))% MOD;
}

lld binpow(lld x, lld y)
{
    lld z = 1;
    while(y)
    {
        if(y & 1) z = mul(z, x);
        x = mul(x, x);
        y >>= 1;
    }
    return z;
}

lld inv(lld x)
{
    return binpow(x, MOD - 2);
}

lld divide(lld x, lld y)
{
    return mul(x, inv(y));
}

// Combinations

/*
lld fact[N];

void precalc()
{
    fact[0] = 1;
    for(lld i = 1; i < N; i++)
        fact[i] = mul(fact[i - 1], i);
}

lld C(lld n, lld k)
{
    return divide(fact[n], mul(fact[k], fact[n - k]));
}
*/
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lld t,i,j;
    //cin>>t;
    t=1;
    while(t--)
    {
        lld n;
        cin>>n;
        vector<lld>ar(n);
        for(i=0;i<n;i++)
            cin>>ar[i];
        sort(ar.begin(),ar.end());
        lld ans=0;
        for(i=0;i<n;i++)
        {
            for(j=i+1;j<n;j++)
            {
                for(lld k=j+1;k<n;k++)
                    if(ar[i]+ar[j]>ar[k] && ar[i]!=ar[j] && ar[i]!=ar[k]  && ar[k]!=ar[j])
                    ans++;
            }
        }
        cout<<ans<<endl;
    }
}

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

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

	for(int i=1;i<N;i++){
		if(A[i]<A[i-1]){
			ans+=A[i-1]-A[i];
			A[i] = A[i-1];
		}
	}
	cout<<ans<<endl;
}


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

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

    int ans = 1000;
    for(int i = 0; i+2 < s.length(); i++){
        int num = (s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0');
        if(abs(753-num) < ans) ans = abs(753-num);
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  ll ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (i % 3 && i % 5) ans += i;
  }
  cout << ans << endl;
  return 0;
}


#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <bitset>
#include <complex>
using namespace std;

const double EPS = 1e-9;
const double PI = 3.14159265359;

typedef complex<double> P;

typedef long long int li;

int main(){
	int n;
	string hos = "Hoshino";

	cin >> n;
	cin.ignore();
	while(n--){
		string s;
		getline(cin, s);

		int k = s.size()+1-hos.size();
		for(int i = 0; i < k; i++){
			if(s.substr(i, hos.size()) == hos){
				s[i+hos.size()-1] = 'a';
			}
		}

		cout << s << endl;
	}

    return 0;
}

#include <bits/stdc++.h>
#define pb push_back
#define pll pair <ll, ll>
#define mp make_pair
#define pyshnapyshnakaa ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define x first
#define y second
#pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
#define plll pair <ll, pair <ll, ll>>
#define pllll pair <pair <ll, ll>, pair <ll, ll> >
#define psl pair <string, ll>
#define all(a) a.begin(), a.end()
#define vvl vector <vector <ll> >

typedef long long ll;

typedef long double ld;

using namespace std;

const ll maxn = 1e3 + 10;

ll n, m, k, t;

ll x, y;

ll ANS[maxn][maxn];

int main() {
    pyshnapyshnakaa;
    ll q, w, e, a, b, c;
    cin >> n >> m >> x >> y;
    for (q = 0; q < n; q++) {
        for (w = 0; w < x; w++) {
            ANS[q][w] = 0;
        }
        for (w = x; w < m; w++) {
            ANS[q][w] = 1;
        }
    }
    for (q = 0; q < y; q++) {
        for (w = 0; w < m; w++) {
            ANS[q][w] ^= 1;
        }
    }
    for (q = 0; q < n; q++) {
        for (w = 0; w < m; w++) {
            cout << ANS[q][w];
        }
        cout << endl;
    }
    return 0;
}


#include <iostream>
#include <math.h>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cstdlib>
#include <unordered_map>
#include <numeric>
#include <functional>
#include <limits.h>
#include <utility>
#include <stack>

using namespace std;

#define fs first
#define sc second

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

const ll mod = 998244353;
ll fact[5010200];
ll invfact[5010200];

inline ll take_mod(ll a){
    return (a % mod + mod) % mod;
}

inline ll add(ll a, ll b){
    return take_mod(a+b);
}

inline ll sub(ll a, ll b){
    return take_mod(a + mod -b);
}

inline ll mul(ll a, ll b){
    return take_mod(a * b);
}

inline ll pow(ll x, ll n){
    ll res = 1LL;
    while(n > 0){
        if(n & 1) res = mul(res, x);
        x = mul(x, x);
        n >>= 1;
    }
    return res;
}

ll mod_inv(ll x){
    return pow(x, mod-2);
}

// nは上限
void make_fact(ll n){
    fact[0] = 1;
    ll res = 1;
    for(int i = 1; i <= n; i++){
        fact[i] = res;
        res = mul(res, i+1);
    }
}

// nは上限
void make_invfact(ll n){
    invfact[0] = 1;
    invfact[n] = mod_inv(fact[n]);
    for(int i = n-1; i >= 1; i--){
        invfact[i] = mul(invfact[i + 1], i + 1);
    }
}

ll perm(ll n, ll k){
    return mul(fact[n], invfact[n-k]);
}

ll comb(ll n, ll k){
    if(k == 0){
        return 1;
    }
    return mul(mul(fact[n], invfact[n-k]), invfact[k]);
}

int main(){
    ll N, M;
    cin >> N >> M;
    make_fact(5010000);
    make_invfact(5010000);

    ll res = 1;
    res = mul(res, comb(3 * M + N - 1, N-1));

    for(ll i = 2 * M + 1; i <= 3 * M; i++){
        ll remain = 3 * M - i;
        ll tmp = mul(N, comb(N + remain - 2, N-2));
        res = sub(res, tmp);
    }
    for(ll x = M + 1; x <= N; x++){
        if(3 * M - x < 0 || (3 * M - x) % 2 == 1){
            continue;
        }
        if(x > N){
            continue;
        }
        ll ball = (3 * M - x) / 2;

        ll tmp = mul(comb(N, x), comb(ball + N - 1, N-1));
        res = sub(res, tmp);
    }

    cout << res << endl;
}

#include<bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
using namespace std;
inline int read(){
	int v=0,f=1;
	char c=getchar();
	while (c<'0' || c>'9'){
		if (c=='-') f=-1;
		c=getchar();
	}
	while (c>='0' && c<='9'){
		v=v*10+c-'0';
		c=getchar();
	}
	return v*f;
}
const int Maxn=2000005;
const int mod=998244353;
int fact[Maxn],ivf[Maxn];
int qp(int x,int p){
	int ret=1;
	while (p){
		if (p&1) ret=1ll*ret*x%mod;
		x=1ll*x*x%mod;
		p>>=1;
	}
	return ret;
}
int inv(int x){
	return qp(x,mod-2);
}
int C(int x,int y){
	return 1ll*fact[x]*ivf[y]%mod*ivf[x-y]%mod;
}
void _init(){
	fact[0]=1;
	for (int i=1;i<Maxn;i++){
		fact[i]=1ll*fact[i-1]*i%mod;
		ivf[i]=inv(fact[i]);
	}
	ivf[0]=1;
}
int main(){
	_init();
	int n,m;
	scanf("%d %d",&n,&m);
	int ans=0;
	for (int i=m;i>=0;i-=2){
		if (i>n) continue;
		int rem=(3*m-i)/2;
		ans+=1ll*C(n,i)*C(rem+n-1,n-1)%mod;
		if (ans>=mod) ans-=mod;
	}
//	cout<<ans<<endl;
	for (int i=m;i>=0;i-=2){
		if (i>n) continue;
		int rem=(3*m-i)/2;
		rem-=m;
		ans-=1ll*C(n,i)*C(rem+n-1,n-1)%mod*i%mod;
		if (ans<0) ans+=mod;
	}
	for (int i=m;i>=0;i-=2){
		if (i>n) continue;
		int rem=(3*m-i)/2;
		rem-=m+1;
		if (rem<0) continue;
		ans-=1ll*C(n,i)*C(rem+n-1,n-1)%mod*(n-i)%mod;
		if (ans<0) ans+=mod;
	}
	printf("%d\n",ans);
	return 0;
}


#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);++i)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};

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

  int n,q;
  cin >> n >> q;
  vector<tuple<int,int,int>> stx(n);
  rep(i,n){
    cin >> get<1>(stx[i]) >> get<2>(stx[i]) >> get<0>(stx[i]);
  }
  sort(stx.begin(),stx.end());

  set<P> st;
  rep(i,q){
    int x;
    cin >> x;
    st.emplace(x,i);
  }

  vector<int> ans(q,-1);
  rep(i,n){
    int s = get<1>(stx[i]);
    int t = get<2>(stx[i]);
    int x = get<0>(stx[i]);
    //xの昇順で考えてぶつかったら，その人をerase
    auto first = st.lower_bound(P(s-x,0));//引っかかる人
    auto end = st.upper_bound(P(t-x-1,q));//引っかからない人

    for(auto it = first; it !=end; ++it) ans[it->second] = x;

    st.erase(first,end);
  }

  rep(i,q) cout << ans[i] << endl;
  return 0;
}

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

using ll = long long;

const ll INF = 1e18;

const int S = 1 << 18;
ll seg[2*S];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N, Q; cin >> N >> Q;
	vector<pair<pair<ll, ll>, ll>> blocks(N);
	for (int i = 0; i < N; i++) {
		ll s, t, x; cin >> s >> t >> x;
		s -= x, t -= x;
		blocks[i] = {{s,t}, x};
	}
	vector<ll> D(Q);
	for (int q = 0; q < Q; q++) {
		cin >> D[q];
	}

	for (int i = 0; i < 2 * S; i++) {
		seg[i] = INF;
	}

	for (int i = 0; i < N; i++) {
		ll s = blocks[i].first.first, t = blocks[i].first.second, x = blocks[i].second;
		int si = int(lower_bound(D.begin(), D.end(), s) - D.begin());
		int ti = int(lower_bound(D.begin(), D.end(), t) - D.begin());
		for (int a = S+si, b = S+ti; a < b; a /= 2, b /= 2) {
			if (a & 1) {
				seg[a] = min(seg[a], x);
				a++;
			}
			if (b & 1) {
				--b;
				seg[b] = min(seg[b], x);
			}
		}
	}
	for (int i = 1; i < S; i++) {
		seg[2*i+0] = min(seg[2*i+0], seg[i]);
		seg[2*i+1] = min(seg[2*i+1], seg[i]);
	}
	for (int i = 0; i < Q; i++) {
		if (seg[S+i] == INF) cout << -1 << '\n';
		else cout << seg[S+i] << '\n';
	}
	return 0;
}


/*
 * Project: AtCoder Beginners Contest 137 B - One Clue
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/09/01
 * Copyright (c) 2020 toms74209200
 *
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
#include <cstdint>
using namespace std;

int32_t k;
int32_t coord_x;

void solve() {

    for (int i=-k+1;i<k;i++) {
        printf("%d ", coord_x+i);
    }

    printf("\n");

}

int main() {

    scanf("%d", &k);
    scanf("%d", &coord_x);

    solve();

}

#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 <iomanip>       // fixed, setprecision
using namespace std;

int main()
{
  int K, X, start = 0, end = 0;
  cin >> K >> X;
  start = X - K + 1;
  end = X + K - 1;
  for (int i = start; i <= end; i++)
  {
    cout << i << " ";
  }
  cout << endl;
}


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

const int N = 1e3 + 7, mod = 1e9 + 7;

int POW(int a, int b, int mod) {
	a %= mod; int r = 1;
	for(int i = b; i > 0; i >>= 1) {
		if(i & 1) r = (r * a) % mod;
		a = (a * a) % mod;
	}
	return r;
}

int f[N], n, dp[10001][1001];

vector <tuple <int, int, int> > v;

vector <int> nxt;

int g(int lft, int idx) {
	if(idx >= v.size()) {
		return (lft == 0 ? f[n] : 0);
	}
	if(~dp[idx][lft]) {
		return dp[idx][lft];
	}
	int res = g(lft, idx + 1);
	int x, y, z; tie(x, y, z) = v[idx];
	if(x * y <= lft) {
		res += g(lft - x * y, nxt[idx]) * z % mod;
		res %= mod;
	}
	return dp[idx][lft] = res;
}

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

	f[0] = 1;
	for(int i = 1; i < N; i++) {
		f[i] = (f[i - 1] * i) % mod;
	}

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

	for(int i = a; i <= b; i++) {
		int k = POW(f[i], mod - 2, mod), p = 1;
		for(int j = 1; j <= c; j++) {
			p = (p * k) % mod;
		}
		for(int j = c; j <= d; j++) {
			if(i * j <= n) {
				v.push_back(make_tuple(i, j, (p * POW(f[j], mod - 2, mod)) % mod));
			}
			p = (p * k) % mod;
		}
		while(nxt.size() < v.size()) {
			nxt.push_back(v.size());
		}
	}
	memset(dp, -1, sizeof dp);
	cout << g(n, 0) << 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>;

const int MOD = 1e9+7;

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

  vector<int> dp(n+1);
  dp[0] = 1;
  vector<int> clr(3, 0);
  rep(i, n) {
    int c = 0;
    rep(ci, 3) if (clr[ci] == a[i]) ++c;
    dp[i+1] = (ll)dp[i] * c % MOD;
    rep(ci, 3) {
      if (clr[ci] == a[i]) {
        clr[ci]++;
        break;
      }
    }
  }
  cout << dp[n] << endl;
  return 0;
}


#include <iostream>
using namespace std;

int main(){
  int N;

  cin >> N;

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

  return 0;
}

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

int main() {
  string s;
  cin >> s;
  vector<bool> v(26, true);
  for(int i=0; i<s.size(); i++) v[s[i]-'a'] = false;

  char ans;
  for(int i=0; i<26; i++) {
    if(v[i]) {
      ans = i+'a';
      cout << ans << endl;
      break;
    }
    else if(i==25) cout << "None" << endl;
  }
  return 0;
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;

ll dp[200005][5];

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    V<ll> a(n);
    cinf(n,a);
    ll k=1+n%2;
    rep(i,n+1)rep(j,k+1)dp[i][j]=-INF;
    dp[0][0]=0;
    rep(i,n){
        rep(j,k+1){
            chmax(dp[i+1][j+1],dp[i][j]);
            ll now=dp[i][j];
            if((i+j)%2==0) now+=a[i];
            chmax(dp[i+1][j],now);
        }
    }
    cout<<dp[n][k]<<endl;
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
(全探索できるなら全探索しろ)
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'\n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え(=でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
*/


#include <bits/stdc++.h>
using namespace std;
int main()
{
	// freopen("AGC010-D.in", "r", stdin);
	int n, cur = 0;
	cin >> n;
	vector<int> arr(n);
	copy(istream_iterator<int>(cin), istream_iterator<int>(), arr.begin());
	string str[] = {"First", "Second"}, ans;
	while (ans.empty()) {
		int cnt = count_if(arr.begin(), arr.end(), [&] (int x) { return x % 2 == 0; });
		if (cnt & 1) {
			ans = str[cur];
			break;
		}
		cur ^= 1;
		if (cnt != n - 1) {
			ans = str[cur];
		}
		int g = 0;
		for_each(arr.begin(), arr.end(), [&] (int x) {
			if (x == 1) {
				ans = str[cur];
			}
			x -= x & 1;
			while (x) {
				int r = g % x;
				g = x;
				x = r;
			}
		});
		if (!g) {
			break;
		}
		for_each(arr.begin(), arr.end(), [&] (int &x) { x /= g; });
	}
	cout << ans << endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const double pi = acos(-1.0);
const double EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int N;
int A[100000];

int res(){
    int K = 0;
    rep(i, N){
        if(A[i]%2 == 0) K++;
    }
    if(K&1) return 1;
    if(K != N-1) return 0;
    int g = A[0]&~1;
    rep(i, N){
        if(A[i] == 1) return 0;
        if(A[i]%2 == 1) A[i]--;
        g = gcd(g, A[i]);
    }
    rep(i, N) A[i] /= g;
    return res()^1;
}

int main(){
    cin >> N;
    rep(i, N) cin >> A[i];
    cout << (res()? "First" : "Second") << endl;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <stack>
#include <complex>
#include <functional>
#include <tuple>

using namespace std;

#define Rep(i,a,b) for(ll i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")

using ll = long long;

constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 1e9 + 7;
// 0~3までは右下左上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, -1 };
constexpr int dy[] = { 0, 1, 0, -1, 1, 1 };

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

    // 標準出力
    void Write(long long x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Write(const T& x, const char* end = "\n") { std::cout << x << end; }
    template <typename T, typename U> void Write(const T& x, const U& y, const char* end = "\n") { std::cout << x << " " << y << end; }
    template <typename T, typename U, typename V> void Write(const T& x, const U& y, const V& z, const char* end = "\n") { std::cout << x << " " << y << " " << z << end; }
    //template <typename... Args> void Write(Args const&... args) { bool a = true; for (auto const& x : { args... }) { if (a) a = false; else std::cout << " "; std::cout << x; } std::cout << "\n"; }
    template <typename T> void Write(const std::vector<T>& x, const char* sep = " ", const char* end = "\n") { for (std::size_t i = 0, sz = x.size(); i < sz; ++i) { std::cout << x[i] << (i == sz - 1 ? end : sep); } }
    template <typename T> void Write(const std::vector<std::vector<T>>& x, const char* sep = " ", const char* end = "\n") { for (auto v : x) Write(v, sep, end); }

    // 標準入力
    struct Read {
        std::size_t szi, szj;
        Read(std::size_t _szi = 1, std::size_t _szj = 1) : szi(_szi), szj(_szj) {}
        template <typename T> operator T () const { T a; std::cin >> a; return a; }
        template <typename T> operator std::vector<T>() const { std::vector<T> a(szi); for (std::size_t i = 0; i < szi; ++i) std::cin >> a[i]; return a; }
        template <typename T> operator std::vector<std::vector<T>>() const {
            std::vector<std::vector<T>> a(szi, std::vector<T>(szj));
            for (std::size_t i = 0; i < szi; ++i) for (std::size_t j = 0; j < szj; ++j) cin >> a[i][j]; return a;
        }
        template <typename T, typename U> operator std::vector<std::pair<T, U>>() const {
            std::vector<std::pair<T, U>> a(szi);
            for (std::size_t i = 0; i < szi; ++i) std::cin >> a[i].first >> a[i].second; return a;
        }
    };
    struct Reads {
        template <typename T> Reads(T& a) { std::cin >> a; }
        template <typename T, typename U> Reads(T& a, U& b) { std::cin >> a >> b; }
        template <typename T, typename U, typename V> Reads(T& a, U& b, V& c) { std::cin >> a >> b >> c; }
        template <typename T, typename U, typename V, typename W> Reads(T& a, U& b, V& c, W& d) { std::cin >> a >> b >> c >> d; }
    };

    Read read;
}

int main() {

    int k, t; Reads(k, t);
    vector<int> a = Read(t);

    int ans = *max_element(allof(a)) * 2 - k - 1;
    chmax(ans, 0);

    Write(ans);

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define mes(a,b) memset((a),(b),sizeof((a)))
#define syio std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0);
#define lson l, mid, rt << 1
#define rson mid+1, r, rt << 1 | 1
typedef long long ll;
typedef long double real;
typedef pair<int, int> pii;

const int oo = ~0u >> 2;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int mxn = 200033;
inline int read(){
    int x = 0,f = 1;char c = getchar();
    while(!isdigit(c))f = c == '-' ? -1 : 1,c = getchar();
    while(isdigit(c))x = x * 10 + c - '0',c = getchar();
    return x * f;
}
int n, a[mxn];
int main()
{
    syio;
    cin>>n;
    for (int i = 1; i <= n; ++ i) cin>>a[i];
    ll res = 0;
    for (int i = 2; i <= n; ++ i)
    {
        if (a[i] < a[i - 1])
        {
            res += a[i - 1] - a[i];
            a[i] += a[i - 1] - a[i];
        }
    }
    cout<<res<<endl;
    return 0;
}


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

struct CumulativeSum {
  vector<long long> csum;
  template<typename T>
  CumulativeSum(vector<T> input) : csum(input.size() + 1, 0) {
    for(int i = 0; i < (int)input.size(); i++) csum[i+1] = csum[i] + input[i];
  }
  long long query(int l, int r) { /* 0-indexed, inclusive */ return csum[r+1] - csum[l]; }
};

struct CumulativeSum2D {
  vector<vector<long long>> csum;
  template<typename T>
  CumulativeSum2D(vector<vector<T>> input) : csum(input.size() + 1, vector<long long>(input[0].size() + 1, 0)) {
    for(int i = 0; i < (int)input.size(); i++) for(int j = 0; j < (int)input[i].size(); j++)
      csum[i+1][j+1] += csum[i+1][j] + csum[i][j+1] - csum[i][j] + input[i][j];
  }
  CumulativeSum2D(vector<string> input, char target) : csum(input.size() + 1, vector<long long>(input[0].size() + 1, 0)) {
    for(int i = 0; i < (int)input.size(); i++) for(int j = 0; j < (int)input[i].size(); j++)
      csum[i+1][j+1] += csum[i+1][j] + csum[i][j+1] - csum[i][j] + (input[i][j]==target);
  }
  long long query(int y_top, int x_left, int y_bottom, int x_right) { /* 0-indexed, inclusive */
    return csum[y_bottom+1][x_right+1] - csum[y_top][x_right+1] - csum[y_bottom+1][x_left] + csum[y_top][x_left];
  }
};

signed main() {
#if 1 // https://atcoder.jp/contests/abc122/tasks/abc122_c
  int n,q; cin >> n >> q;
  string s; cin >> s;
  vector<bool> ac(n);
  for(int i=0; i<n-1; ++i) ac[i] = s[i] == 'A' && s[i+1] == 'C';
  CumulativeSum cs(ac);
  while(q--) {
    int l,r; cin >> l >> r; --l, r-=2;
    cout << cs.query(l,r) << endl;
  }
#elif 1 // https://atcoder.jp/contests/abc005/tasks/abc005_4
  int n; cin >> n;
  vector<vector<int>> grid(n, vector<int>(n, 0));
  for(int i=0; i<n; ++i) for(int j=0; j<n; ++j) cin >> grid[i][j];
  CumulativeSum2D cs(grid);

  vector<int> ans(n*n+1);
  for(int y1=0; y1<n; ++y1) for(int x1=0; x1<n; ++x1) for(int y2=y1; y2<n; ++y2) for(int x2=x1; x2<n; ++x2) {
    int w = x2 - x1 + 1, h = y2 - y1 + 1;
    ans[w*h] = max(ans[w*h], (int)cs.query(y1,x1,y2,x2));
  }
  for(int i=1; i<= n*n; ++i) ans[i] = max(ans[i], ans[i-1]);

  int q; cin >> q;
  while(q--) {
    int p; cin >> p;
    cout << ans[p] << endl;
  }
#else // http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0560
  int n,m,k; cin >> m >> n >> k;
  vector<string> grid(m);
  for(int i=0; i<m; ++i) cin >> grid[i];

  CumulativeSum2D J(grid, 'J');
  CumulativeSum2D O(grid, 'O');
  CumulativeSum2D I(grid, 'I');

  for(int i=0; i<k; ++i) {
    int x1,y1,x2,y2; cin >> y1 >> x1 >> y2 >> x2;
    --x1, --y1, --x2, --y2;
    cout << J.query(y1,x1,y2,x2) << " ";
    cout << O.query(y1,x1,y2,x2) << " ";
    cout << I.query(y1,x1,y2,x2) << endl;
  }
#endif
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

int main() {
    int N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    vector<int> AC;
    AC.push_back(0);

    //入力
    vector<int> X(Q), Y(Q);
    for(int i=0; i<Q; i++) {
        int a,b;
        cin >> X[i] >> Y[i];
    }

    //Sの"AC"をカウントして存在した位置をvectorにpush_back
    int count = 0;
    for(int i=1; i<N; i++) {
        if(S[i-1] == 'A' && S[i] == 'C'){
            count++;
        }
        AC.push_back(count);
    }

    for(int i=0; i<Q; i++) {
        cout << AC[Y[i]-1] - AC[X[i]-1] << endl;
    }
}


#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>

using namespace std; typedef long long ll;
typedef pair<string,string> P; const int INF = 1e9+1;
int main() {
  int n; cin>>n;
  string s; cin>>s;

  map<P, ll> mp;
  for(int i=0;i<(1<<n);i++) {
    string s1, s2;
    for(int j=0;j<n;j++) {
      if (i & (1<<j)) s1+=s[j];
      else s2+=s[j];
    }
    reverse(s1.begin(), s1.end());
    reverse(s2.begin(), s2.end());
    mp[make_pair(s1,s2)]++;
  }
  ll an=0;
  for(int i=0;i<(1<<n);i++) {
    string s1, s2;
    for(int j=0;j<n;j++) {
      if (i & (1<<j)) s1+=s[n+j];
      else s2+=s[n+j];
    }
    an += mp[make_pair(s1,s2)];
  }
  cout<<an<<endl;
}

//* AuThOr GaRyMr *//
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define niv vector<int>
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define ff fflush(stdout)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int n;
LL res;
int dp[20][20];
// dp[i][j] 前i个组成长度为j的B的前缀
string r_s="";
int check(string A,string B){
//	cout<<A<<" "<<B<<" "<<r_s<<endl;

	A='$'+A;
	B='^'+B;
	rb(i,0,19)
		rb(j,0,19) dp[i][j]=0;
	dp[0][0]=1;
	rb(i,1,n/2){
		rb(j,1,min((int)(B.length()-1),i)){
			if(r_s[i]==B[j]){
				dp[i][j]+=dp[i-1][j-1];
			}
			if(r_s[i]==A[i-j]){
				dp[i][j]+=dp[i-1][j];
			}
		}
	}
	return dp[n/2][B.length()-1];
}	string s;
void dfs1(string A,string B,int now){
	if(now>(n>>1)){
		res+=check(A,B);
	}
	else{
		dfs1(A+s[now],B,now+1);
		dfs1(A,B+s[now],now+1);
	}
}
int main(){
	cin>>n;
	n=n+n;
	cin>>s;
	s='$'+s;
	rl(i,n,n/2+1) r_s+=s[i];r_s='%'+r_s;
	dfs1("","",1);
	cout<<res+res<<endl;
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define MAX 1000005
#define MOD (ll)(1e9+7)
#define INF INT32_MAX
#define INFL INT64_MAX
#define con(x,y)	((x)*(m)+(y))
using namespace std;

int dsu[MAX];
int sz[MAX];

int search(int a)	{
	if(dsu[a]==a)	return a;
	return dsu[a]=search(dsu[a]);
}

void join(int a, int b)	{
	a = search(a);
	b = search(b);
	if(sz[a]<sz[b])	{
		dsu[b]=a;
		sz[a]+=sz[b];
	}
	else {
		dsu[a]=b;
		sz[b]+=sz[a];
	}
}

void solve()	{
	int n,m;
	cin >> n >> m;
	string s[n];
	for(int i=0; i<m*n; i++)	{
		sz[i]=1;
		dsu[i]=i;
	}
	for(int i=0; i<n; i++)	cin >> s[i];
	for(int i=0; i<n; i++)	{
		for(int j=0; j<m; j++)	{
			//cout << con(i,j) << endl;
			if(j+1<m && s[i][j]=='#' && s[i][j+1]=='#')	{
				if(search(con(i,j))!=search(con(i,j+1)))
					join(con(i,j),con(i,j+1));
			}
			if(i+1<n && s[i][j]=='#' && s[i+1][j]=='#')	{
				if(search(con(i,j))!=search(con(i+1,j)))
					join(con(i,j),con(i+1,j));
			}
		}
	}
	bool f=0;
	for(int i=0; i<n; i++)	{
		for(int j=0; j<m; j++)	{
			if(s[i][j]=='#')	{
				if(sz[search(con(i,j))]==1)	{
					f=1; break;
				}
			}
		}
	}
	if(f)	cout << "No\n";
	else cout << "Yes\n";
}

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

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

int main()
{
  int h,w; //h side w vertical
  cin >> h >> w;

  char s[h][w];
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      cin >> s[i][j];
    }
  }

  int flag = 0;
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      if(s[i][j] == '#'){
        if(s[i-1][j] == '#' && i != 0){
          continue;
        }else if(s[i][j-1] == '#' && j != 0){
          continue;
        }else if(s[i][j+1] == '#' && j != w-1){
          continue;
        }else if(s[i+1][j] == '#' && i != h-1){
          continue;
        }else{
          flag = 1;
          break;
        }//else
      }//if
    }//for
    if(flag == 1){
      break;
    }
  }//for

  if(flag == 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

}


#include <iostream>
using namespace std;

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

  if(a < b){
    if(c >= a && c <= b){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }else{
    if(c >= b && c <= a){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define all(v) v.begin(), v.end()

const ll mod=1000000007;

ll countBits(ll in){
  int res=0;
  for(;in>0;in>>=1){
    if((in&0x01)!=0){
      res++;
    }
  }
  return res;
}

template<typename T>
void show2dVector(vector<vector<T>>& v){
  for(int i=0;i<v.size();i++){
    int m=v[i].size();
    cout<<i<<" : ";
    for(int j=0;i<m;i++){
      cout<<v[i][j]<<" ";
    }
    cout<<endl;
  }
}

void bfs(const vector<vector<int>>&g, int v, vector<bool>& seen){
  seen[v]=true;
  cout<<v<<" ";
  for(auto next: g[v]){
    if(seen[next]){
      continue;
    }
    bfs(g,next,seen);
  }
}

bool dfs(vector<vector<int>> &g,int start,int goal,vector<bool>&seen){
  bool res=false;
  seen[start]=true;
  if(start==goal){
    return true;
  }
  for(auto next: g[start]){
    if(seen[next]){
      continue;
    }
    res=dfs(g,next,goal,seen);
    if(res){
      break;
    }
  }
  return res;
}

ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}

char toLowerCase(char c){
  if(isLowerCase(c)){
    return c;
  }else{
    return c+'a'-'A';
  }
}
char toUpperCase(char c){
  if(isLowerCase(c)){
    return c-('a'-'A');
  }else{
    return c;
  }
}
ll powm(ll a,ll n, ll m){
  ll ret=1;
  while(n>0){
    if(n%2==1){
      ret=(ret*a)%m;
    }
    n>>=1;
    a=(a*a)%m;
  }
  return ret;
}

const string yesno(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  bool ans=false;
  int a,b,c;cin>>a>>b>>c;
  if(a<=c&&c<=b){
    ans=true;
  }else if(b<=c&&c<=a){
    ans=true;
  }
  cout<<yesno(ans)<<endl;
  return 0;
}


#include<iostream>
#include<stdio.h>//printf("%.*f\n",*********);
#include<vector>//s.erase(n),vector
#include<algorithm>//next_permutation
#include<set>
#include<string>//char('a'=32+'A')
                //to_string,string,substr
#include<sstream>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>//min,max
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap
#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)//start==1
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)//end==1
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define Yay(ans) if(ans)cout<<"Yay!"<<rt;else cout<<":("<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(a,n) rep(i,n)cin>>a[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//昇順
#define reve(s) reverse(s.begin(),s.end())//反転
#define please return
#define AC 0
#define rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define pi 3.1415926535897932384626//pi
#define nine 1000000000//10^9

using namespace std;
typedef vector<int> vint;
typedef long double ldouble;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef vector<double> vdouble;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

int KETA(int n) { //Sum of Each Digit
	int sum = 0;
	while (n > 0) {
		sum += n % 10; n /= 10;
	}
	return sum;
}

unsigned ND(unsigned num) {//Number of Digits
	return std::to_string(num).length();//outmax=10
}

bool KIBN(string s) {
	rep(i, s.size() / 2) {
		if (s[i] != s[s.size() - 1 - i])return false;
	}
	return true;
}

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */

int main(void) {
	rapid_pleaseAC_fast;

	vint a(2);
	vcin(a, 2);
	int ans = 0;
	rep(i, 2) {
		if (a[i] == 3) {
			ans += 100000;
		}
		if (a[i] == 2) {
			ans += 200000;
		}
		if (a[i] == 1) {
			ans += 300000;
		}
	}
	if (a[0] == 1 && a[1] == 1) {
		ans += 400000;
	}
	cout << ans << rt;

	please AC;
}
//参考：---

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
#define PB push_back
#define ar2 array<int,2>
typedef long long LL;
const LL P = 1e9+7;
const int INF = 0x3fffffff;
const int N = 25;
mt19937 rng(time(0));

int x,y,ans;

int calc(int x){
	if(x==1) return 300000;
	if(x==2) return 200000;
	if(x==3) return 100000;
	return 0;
}

int main(){
	#ifndef ONLINE_JUDGE
	//freopen("test.in","r",stdin);
	#endif
	cin>>x>>y;
	ans = calc(x) + calc(y);
	if(x==1 && y==1) ans += 400000;
	cout<<ans<<endl;
	return 0;
}


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

#define ll long long
#define vvi vector< vector<int> >
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
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;}

int main(){

  int n;

  while (cin >> n,n){
    int x[100];
    int y[100];

    int gem[25][25] = {0};

    REP(i,n){
      cin >> x[i] >> y[i];
      gem[x[i]][y[i]] = 1;
    }
    int m;

    cin >> m;

    char d[100];
    int l[100];

    int nowx=10;
    int nowy=10;

    REP(j,m){
      cin >> d[j] >> l[j];
      if (d[j]=='E'){
	REP(k,l[j]){
	  nowx ++;
	  gem[nowx][nowy]=0;
	}
      }else if(d[j]=='W'){
	REP(k,l[j]){
	  nowx --;
	  gem[nowx][nowy]=0;
	}
      }else if(d[j]=='S'){
	REP(k,l[j]){
	  nowy --;
	  gem[nowx][nowy]=0;
	}
      }else if(d[j]=='N'){
	REP(k,l[j]){
	  nowy ++;
	  gem[nowx][nowy]=0;
	}
      }
      //      cout << nowx << "," << nowy << endl; //
    }
    int tf=0;

    /*
	REP(piyo,25){
	REP(are,25){
	cout << gem[piyo][are] << ",";
	}}
    */

    REP(hoge,25){
      REP(huga,25){
	tf += gem[hoge][huga];
      }
    }

    if(tf){
      cout<<"No"<<endl;
    }else{
      cout<<"Yes"<<endl;
    }
  }
}

#include "bits/stdc++.h"
#define ll long long
#define lld long double
#define MOD 1000000007
#define inf 1000000000000000000ll
#define pii pair<int,int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll power(ll x,ll y, ll md=inf){ll res = 1;x%=md;while(y){if(y&1)res = (res*x)%md;x *= x; if(x>=md) x %= md; y >>= 1;}return res;}

using namespace std;

#define endl '\n'
#define int ll

signed main() {
	fast;

	int h,w;
	cin>>h>>w;

	pii v[200002];
	for(int i=0;i<h;i++) cin>>v[i].f>>v[i].s;

	map<int,int> mp;
	for(int i=1;i<=w;i++) mp[i] = 0;

	map<int,int> mini = {{0,w}};

	for(int i=0;i<h;i++) {
		int r = v[i].s;

		auto it = mp.lower_bound(v[i].f);
		int mn = inf;

		while(it!=mp.end() && it->f <= r) {
			mn = min(mn, r+1-(it->f)+(it->s));
			auto it1 = it++;
			auto it2 = mini.find(it1->s);
			if(it2->s==1) mini.erase(it2);
			else it2->s --;
			mp.erase(it1);
		}

		if(r+1<=w && mn<inf) {
			if(it!=mp.end() && it->f == r + 1) {
				if(it->s > mn) {
					auto it1 = mini.find(it->s);
					if(it1->s ==1) mini.erase(it1);
					else it1->s --;
					mini[mn]++;
					it->s = mn;
				}
			}
			else {
				mp.insert({r+1,mn});
				mini[mn]++;
			}
		}

		if(mini.size()) cout<<mini.begin()->f+i+1<<endl;
		else cout<<-1<<endl;

	}
}


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

int n, k;
vector<string> v;
set<string> s;

void dfs(string str, int flag, int count) {
    if (count == k) {
        s.insert(str);
        return ;
    }
    for (int i = 0; i < n; i++) {
        if (flag & (1 << i)) continue;
        dfs(str + v[i], flag | (1 << i), count + 1);
    }
}

int main() {
    while (cin >> n >> k, n || k) {
        v.resize(0);
        for (int i = 0; i < n; i++) {
            string str;
            cin  >> str;
            v.push_back(str);
        }

        s.clear();
        dfs("", 0, 0);
        cout << s.size() << endl;
    }

    return 0;
}

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

string ab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, key[100];
    string cip;
    while(cin >> n && n){
        for(int i = 0; i < n; i++){
            cin >> key[i];
        }
        cin >> cip;
        for(int i = 0; i < cip.size(); i++){
            int ind = lower_bound(ab.begin(), ab.end(), cip[i])-ab.begin();
            cout << ab[(ind - key[i%n] + 52) % 52];
        }
        cout << endl;
    }
    return 0;
}


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

const int MAX_N = 501, MAX_M = 2e5+10;
int N, M, Q;
int L[MAX_M], R[MAX_M];
int p[MAX_M], q[MAX_M];
ll ans[MAX_N][MAX_N];

void solve()
{
	for(int i=0;i<M;++i){
		for(int le=1;le<=L[i];++le)ans[le][R[i]]++;
	}
	for(int i=1;i<=N;++i)for(int j=1;j<=N;++j){
        ans[i][j] += ans[i][j-1];
	}
	for(int i=0;i<Q;++i){
		cout << ans[p[i]][q[i]] << '\n';
	}
}

int main()
{
	cin >> N >> M >> Q;
	for(int i=0;i<M;++i) cin >> L[i] >> R[i];
	for(int i=0;i<Q;++i) cin >> p[i] >> q[i];
	solve();
	return 0;
}

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

vector<int> to[100005];
vector<int> dist;
int n;

void dfs(int v, int d=0, int p=-1) {
    dist[v] = d;
    for (int u : to[v]) {
        if (u == p) continue;
        dfs(u,d+1,v);
    }
}

vector<int> calc(int x) {
    dist = vector<int>(n);
    dfs(x);
    return dist;
}

int main() {
    int u, v;
    cin >> n >> u >> v;
    u--; v--;
    rep(i,n-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }

    vector<int> distU = calc(u);
    vector<int> distV = calc(v);

    int ans = 0;
    rep(i,n) {
        if (distU[i] < distV[i]) {
            ans = max(ans, distV[i]-1);
        }
    }
    cout << ans << endl;
    return 0;
}


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

#define REP(i,e,s) for(register int i=e; i<=s; i++)
#define DREP(i,e,s) for(register int i=e; i>=s; i--)
#define ll long long
#define DE(...) fprintf(stderr,__VA_ARGS__)
#define DEBUG(a) DE("DEBUG: %d\n",a)

#define int long long

int read() {
	int x=0,f=1,ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
const int MOD=1e9+7,MAXN=200000+10;

int fac[MAXN],inv[MAXN];

int qpow(int a,int b) {
	int ans=1;
	while(b) {
		if(b&1) ans=(ans*a)%MOD;
		a=(a*a)%MOD;
		b>>=1;
	}
	return ans;
}

int c(int m,int n) {
	if(n==m||!m||!n) return 1;
	return ((fac[m]*inv[n]%MOD)*inv[m-n])%MOD;
}

int calc(int x_1,int y_1,int x_2,int y_2) {
	return c(abs(x_2-x_1)+abs(y_2-y_1),abs(x_2-x_1));
}

signed main() {
	int h=read(),w=read(),a=read(),b=read();
	fac[0]=1;
	REP(i,1,h+w) fac[i]=(fac[i-1]*i)%MOD;

	REP(i,1,h+w) inv[i]=qpow(fac[i],MOD-2);
	int ans=0;
	REP(i,1,h-a) {
		ans=(ans+calc(1,1,b,i)*(calc(b+1,i,w,h)))%MOD;
	}

	printf("%lld\n",ans%MOD);
	return 0;
}

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

int main(void) {
	string S;
	cin >> S;
	if (S.length() == 3) reverse(S.begin(), S.end());
	cout << S << "\n";
	return 0;
}


#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
#define db(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<'\n'
const int inf = 1e9+7;
const int N = 1e6+9;

int main() {
    ios_base::sync_with_stdio(0);
    int a,b,n;
    string s;
    cin>>s;
    int sum=0, mx=0;
    for(char ch: s) {
        if(ch=='R') sum++;
        else sum=0;
        mx = max(mx, sum);
    }
    cout<<mx<<endl;
    return 0;
}

#include <bits/stdc++.h>
#define endl "\n"
#define ff first
#define ss second
#define PB push_back
#define MP make_pair
#define ll long long
#define llu unsigned long long
#define MAX(a, b)  (((a) > (b)) ? (a) : (b))
#define MIN(a, b)  (((a) < (b)) ? (a) : (b))
#define ABS(X) ((X)< 0 ? -(X): (X))
#define LCM(X, Y)  ( ( (X) / (GCD( (X)  , (Y) ))) * (Y) )
#define MEM( A,  B) memset((A), (B), sizeof(A))
#define MEM_VEC(V, FILL ) fill( V.begin(), V.end(), FILL)
#define FOR_EACH(IT, V) for (auto IT = V.begin(); IT != V.end(); IT++)
#define DEBUG_ARRAY_PRINT(A,I) cout<<"at pos "<< I <<"  value is: "<< A[I]
#define TURBO ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0)
const double EPS =1e-9 ;
const double PI = 3.1415926535897932384626433832795 ;
using namespace std ;
inline ll GCD(ll A, ll B){
      if ( B == 0 ) return A;
      return GCD( (B) ,  (A % B) );
}
inline ll POW(ll BASE, ll EXP) {
   ll RES = 1;
   for(ll I= 0; I < EXP; I++) RES *= BASE ;
   return RES;
}

inline ll BIGMOD  ( ll a, ll p, ll m ) {
   ll res = 1 % m;
   ll x = a % m;
   while ( p > 0 ) {
       if ( (p & 1) > 0 ) res = ( res * x ) % m;
       x = ( x * x ) % m; p >>= 1;
   }
   return res;
}
inline void FILE_HANDLE( ){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

}

int main()
{

            TURBO;
            //FILE_HANDLE() ;
            string s;
            cin >> s ;
            int ans = 0 ;
            if(s[1] == 'R' && s[2] == 'R' && s[0] == 'R') ans = 3 ;
            else if(s[1] == 'R' && s[2] == 'R' ) ans = 2 ;
            else if(s[1] == 'R' && s[0] == 'R' ) ans = 2 ;
            else if(s[0] == 'R' || s[1] == 'R' || s[2] == 'R') ans = 1 ;
            cout << ans << endl ;
}


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

ll Ep(int x, int y){
  if(y == 1) return x;
  ll r = Ep(x,y/2);
  if(y%2 == 1) return r *r%MOD *x%MOD;
  else return r *r%MOD;
}

int main(){
  int n, x;
  cin >> n;
  cin >> x;
  if(x != 0){
    cout << 0 << endl;
    return 0;
  }
  map<int, int> mp;
  for(int i=1; i<n; ++i){
    cin >> x;
    if(x == 0){
      cout << 0 << endl;
      return 0;
    }
    ++mp[x];
  }
  ll ans = 1;
  for(auto p: mp){
    if(p.first == 1) continue;
    ans *= Ep(mp[p.first-1], p.second);
    ans %= MOD;
  }
  cout << ans << endl;
}

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

const int MOD = 1000000007;
const int MAX = 2*1e5;

bool IsPrime(long long n){
  if(n == 1) return false;
  for(long long i = 2; i * i < n; i++){
    if(n%i == 0) return false;
  }
  return true;
}

vector<pair<long long, long long>> PrimeFactorize(long long n){
  vector<pair<long long, long long>> res;
  long long a = 0;
  for(long long i = 2; i * i <= n; i++){
    a = 0;
    if(n%i == 0){
      if(IsPrime(i)){
        while(n % i == 0){
          n /= i;
          a++;
        }
        res.push_back(make_pair(i, a));
    }}}
  if(n!= 1) res.push_back(make_pair(n, 1));
  return res;
}

long long modpow(long long a, long long n, long long mod){
  long long res = 1;
  while(n > 0){
    //nを２進数に分解してビットの立っているところだけ掛け算していく。
    if (n &  1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

// a inverse (mod m)
// a^(-1) = a^(p-2) (mod p)
long long modinv(long long a, long long mod){
  return modpow(a, mod-2, mod);
}

long long Comb(long long n, long long k){
  if(n < k) return 0;
  if(n < 0 || k < 0) return 0;
  // return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
  long long ans = 1;
  for(long long i = 0; i < k; i++){
    ans = ans * (n - i) % MOD;
    ans = ans * modinv(k - i, MOD) % MOD;
  }
  return ans;
}

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

  vector<pair<long long, long long>> res;
  res = PrimeFactorize(m);

  // CombInit();

  long long ans = 1;
  long long size = res.size();
  for(long long i = 0; i < size; i++){
    long long num = Comb(res[i].second + n - 1, res[i].second);
    // ans = (ans * Comb(res[i].second + n - 1, res[i].second)) % MOD;
    ans = (ans * num) % MOD;
  }

  cout << ans << endl;

  return 0;
}


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

int main() {
	// your code goes here
	string s,t;
	cin>>s;
	cin>>t;
	for(int i = 0; t[i]!='\0'; i++)
	{
		cout<<t[i];
	}
	for(int i = 0; s[i]!='\0'; i++)
	{
		cout<<s[i];
	}
	return 0;
}

#include <iostream>

int main(int argc, char *argv[])
{
	int x = 0;

	std::cin >> x;
	x = x * x * x;
	std::cout << x << std::endl;
	return 0;
}


#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P std::pair<int,int>
#define PiP std::pair<int,std::pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp std::make_pair
#define prique(T) std::priority_queue<T,vector<T>,greater<T>>
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = std::max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = std::min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	std::random_device rnd;
	std::mt19937 mt32(rnd());
	std::uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt32);
}
/*--------Library Zone!--------*/

int n, q;
string s;
int summ[1000005];
signed main() {
	cin >> n >> s >> q;
	rep(i, n) {
		if (s[i] == 'M')summ[i]++;
		summ[i + 1] = summ[i];
	}
	while (q--) {
		int k; cin >> k;
		int ans = 0;
		int d = 0, dm = 0;
		rep(i, n) {
			if (s[i] == 'D')d++;
			else if (s[i] == 'M')dm += d;
			else if (s[i] == 'C')ans += dm;
			if (i >= k - 1 && s[i - k + 1] == 'D') {
				d--;
				dm -= summ[i] - (i >= k ? summ[i - k] : 0);
			}
		}
		cout << ans << endl;
	}
}

#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int n;string s;

ll solve(int k){
    ll d=0,m=0,dm=0,ret=0;
    rep(i,k){
        if(s[i]=='D')d++;
        if(s[i]=='M'){
            dm+=d;
            m++;
        }
        if(s[i]=='C')ret+=dm;
    }
    for(int i=k;i<n;i++){
        if(s[i-k]=='D'){
            dm-=m;d--;
        }
        if(s[i-k]=='M')m--;

        if(s[i]=='D') d++;
        if(s[i]=='M'){
            dm+=d;
            m++;
        }
        if(s[i]=='C')ret+=dm;
    }
    return ret;
}

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

    cin>>n;
    cin>>s;

    vector<ll> ans;
    int q;cin>>q;
    while(q--){
        int k;cin>>k;
        ans.push_back(solve(k));
    }
    for(auto x:ans){
        cout<<x<<endl;
    }
    return 0;
}


// C++ 14
#include <bits/stdc++.h>
using namespace std;
template <typename T>  ostream& operator<<(ostream& os, const vector<T>& v)  {  os << "[";  for (int i = 0; i < v.size(); ++i) {  os << v[i];  if (i != v.size() - 1)  os << ", ";  }  os << "]";  return os;  }
template <typename T> void print(T v, string s = "\n") { cout << v << s; }
template <typename T> void in(T &v) { cin >> v; }
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

int main() {
  int n, m; in(n),in(m);
  vector<bool> ac(n+1, false);
  vector<int> wa(n+1, 0);
  int p; string s;
  loop(i,0,m) {
    in(p),in(s);
    if (ac[p]) continue;
    if (s == "WA") wa[p]++;
    else ac[p] = true;
  }
  loop(p,1,n+1) if (!ac[p]) wa[p] = 0;

  int ans1 = 0;
  for (auto&&b: ac) ans1+=b;
  int ans2 = 0;
  for (auto&&w: wa) ans2+=w;
  print(ans1, " ");
  print(ans2);
  return 0;
}

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
struct UnionFind {
	vector<int> par;
	vector<int> rank;
	vector<int> cmp;
	int size;
	UnionFind(int n) :size(n) {
		par.resize(size);
		rank.resize(size);
		cmp.resize(size);
		for (int i = 0; i < size; i++) {
			par[i] = i;
			rank[i] = 0;
			cmp[i] = 1;
		}
	}
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;
		if (rank[x] < rank[y]) {
			par[x] = y;
			cmp[y] += cmp[x];
		}
		else {
			par[y] = x;
			cmp[x] += cmp[y];
			if (rank[x] == rank[y]) rank[x]++;
		}
	}
	int find(int x) {
		if (par[x] == x) return x;
		return par[x] = find(par[x]);
	}
	bool same(int x, int y) {
		x = find(x);
		y = find(y);
		return x == y;
	}
};
map<int, int> cnt[200000];
int main() {
	int N, K, L;
	cin >> N >> K >> L;
	UnionFind u1(N), u2(N);
	for (int i = 0; i < K; i++) {
		int p, q;
		cin >> p >> q;
		p--; q--;
		u1.unite(p, q);
	}
	for (int i = 0; i < L; i++) {
		int r, s;
		cin >> r >> s;
		r--; s--;
		u2.unite(r, s);
	}
	for (int i = 0; i < N; i++) {
		int x = u1.find(i);
		int y = u2.find(i);
		cnt[x][y]++;
	}

	for (int i = 0; i < N; i++) {
		int x = u1.find(i);
		int y = u2.find(i);
		cout << cnt[x][y] << " ";
	}
	cout << endl;
 }


#include<iostream>
using namespace std;

int main(void){
	int n, q;
	cin >> n;
	int s[n];

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

	cin >> q;
	int t[q];

	for(int i = 0; i < q; i++){
		cin >> t[i];
	}
	int count = 0;
	for(int i = 0; i < q; i++){
		for(int j = 0; j < n; j++){
			if(t[i] == s[j]){
				count++;
				break;
			}
			else continue;

		}
	}
	cout << count << endl;
}

#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define vv(T) std::vector<std::vector<T>>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;

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

	vector<bool> seen(1'000'000'000);
	bool ans = true;
	for (int i = 0; i < n; ++i)
	{
		int a;
		cin >> a;
		if (seen[a])
			ans = false;
		seen[a] = true;
	}
	cout << (ans ? "YES" : "NO") << endl;
}


// This amazing code is by Eric Sunli Chen.
#include<bits/stdc++.h>
using namespace std;
template<typename T> bool get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'&&t!=EOF; t=getchar());
	if(t=='-')neg=true,t=getchar();if(t==EOF)return false;
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;return true;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) (get1(a)&&get1(b))
#define get3(a,b,c) (get1(a)&&get2(b,c))
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

const int maxn=100111;
int n,s,x[maxn];
LL p[maxn],ans;

int calc(int l,int r)
{
	if(x[r]<s)
	{
		ans+=s-x[l];
		return l;
	}
	if(x[l]>s)
	{
		ans+=x[r]-s;
		return r;
	}
	if(p[l]>=p[r])
	{
		p[l]+=p[r];
		ans+=x[r]-x[calc(l,r-1)];
		return r;
	}
	else
	{
		p[r]+=p[l];
		ans+=x[calc(l+1,r)]-x[l];
		return l;
	}
}

int main()
{
	get2(n,s);
	for(int i=1;i<=n;i++)get2(x[i],p[i]);
	calc(1,n);
	printendl(ans);
	return 0;
}

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = (1e+9)+7;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
vector<int> v;
int main() {
	int n; ll s; cin >> n >> s;
	ll x[100000]; ll p[100000];
	rep(i, n) {
		cin >> x[i] >> p[i];
	}
	int j, k; j = 0; k = n - 1;
	while (j < k) {
		if (p[j] < p[k]) {
			p[k] += p[j];
			if (s > x[j]) {
				v.push_back(j);
			}
			j++;
		}
		else if (p[j] >= p[k]) {
			p[j] += p[k];
			if (s < x[k]) {
				v.push_back(k);
			}
			k--;
		}
	}
	v.push_back(j);
	int len = v.size();
	ll sum = 0; ll now = s;
	per(i, len) {
		sum += abs(x[v[i]] - now);
		now = x[v[i]];
	}
	cout << sum << 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 <bits/stdc++.h>

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef tuple<ll, ll, ll> ti;
ll mod=1E9+7;

#define REP(a,b,c) for(ll a=b;a<(c);a++)
#define PER(a,b,c) for(ll a=b;a>=(c);a--)

ll ii(){ ll x; cin >> x; return x; }
string is(){ string x; cin >> x; return x; }
ld id(){ ld x; cin >> x; return x; }
void oi(ll x){ cout << x; }
void od(ld x){ cout << fixed << setprecision(10) << x; }
void os(string x){ cout << x; }
void oe(){ cout << endl; }
void oie(ll x){ oi(x); oe(); }
void ode(ld x){ od(x); oe(); }
void ose(string x){ os(x); oe(); }

int main(){
    ll N=ii();
    ll M=ii();

    ll r=((N-1)/2);
    ll r3=r/2;
    ll r2=r-r3;

    REP(i,0,min(r2,M)){
        oi(i+1);
        os(" ");
        oie(2*r2-i);
    }

    REP(i,0,min(r3,M-r2)){
        oi(2*r2+i+1);
        os(" ");
        oie(2*(r2+r3)+1-i);
    }

    return 0;
}


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

int H, W;
int a[510][510];
vector<T> ans;

signed main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> H >> W;
    rep(i, H) rep(j, W) cin >> a[i][j];
    rep(i, H) {
        if (i%2==0) {
            rep(j, W) {
                if (i==H-1 && j==W-1) continue;
                int ni, nj;
                if (j==W-1) ni = i+1, nj = W-1;
                else ni = i, nj = j+1;
                if (a[i][j]%2==1) {
                    ans.pb(make_tuple(i+1, j+1, ni+1, nj+1));
                    a[ni][nj]++;
                }
            }
        }
        else {
            for (int j=W-1; j>=0; j--) {
                if (i==H-1 && j==0) continue;
                int ni, nj;
                if (j==0) ni = i+1, nj = 0;
                else ni = i, nj = j-1;
                if (a[i][j]%2==1) {
                    ans.pb(make_tuple(i+1, j+1, ni+1, nj+1));
                    a[ni][nj]++;
                }
            }
        }
    }
    cout << ans.size() << endl;
    rep(i, ans.size()) cout << get<0>(ans[i]) << " " << get<1>(ans[i]) << " " << get<2>(ans[i]) << " " << get<3>(ans[i]) << endl;
}

#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 h, w;
    cin >> h >> w;
    vector<vector<bool>> odd(h, vector<bool>(w, false)); // 奇数ならtrue;
    vector<pair<P,P>> ans;
    rep(i, h) {
        rep(j, w) {
            ll a; cin >> a;
            if((a%2) == 1) odd[i][j] = true;
        }
    }
    rep(i, h) {
        bool ok = false; // 奇数から取ったコインを移動中
        rep(j, w) {
            if(odd[i][j]) {
                if(ok) {
                    ok = false;
                }
                else {
                    ok = true;
                    if(j != w-1) ans.push_back(make_pair(P(i+1,j+1), P(i+1,j+2)));
                }
            }
            else {
                if(ok && (j != w-1)) {
                    ans.push_back(make_pair(P(i+1,j+1), P(i+1,j+2)));
                }
            }
        }
        if(ok && i != h-1) {
            ans.push_back(make_pair(P(i+1,w), P(i+2,w)));
            odd[i+1][w-1] = !(odd[i+1][w-1]);
        }
    }
    cout << ans.size() << endl;
    rep(i, ans.size()) {
        cout << ans[i].first.first << ' ';
        cout << ans[i].first.second << ' ';
        cout << ans[i].second.first << ' ';
        cout << ans[i].second.second << 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;
}


#pragma region header
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr ll inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    int h,w;cin >> h >> w;
    vvb bo(h,vb(w));
    vector<P> v;
    rep(i, h) {
        rep(j, w) {
            char c;cin >> c;
            if(c=='#') {
                bo[i][j]=true;
                v.pb({i,j});
            }
            else bo[i][j]=false;
        }
    }
    bool ok = true;
    rep(i, v.size()) {
        rep(j, 4) {
            int x=v[i].first+dx[j],y=v[i].second+dy[j];
            if(x<0||x>=h||y<0||y>=w||!bo[x][y]) {
                // cout << i << endl;
                if(j==3) {
                    cout << "No" << endl;
                    return 0;
                }
                continue;
            }
            break;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

int main(void) {
	int H, W;
	scanf("%d %d", &H, &W);
	string s[50];
	for (int i = 0; i < H; i++) {
		cin >> s[i];
	}
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			bool paintable = false;
			if (s[i][j] != '#') continue;
			if (j != W - 1 && s[i][j + 1] == '#') paintable = true;
			if (j != 0     && s[i][j - 1] == '#') paintable = true;
			if (i != H - 1 && s[i + 1][j] == '#') paintable = true;
			if (i != 0     && s[i - 1][j] == '#') paintable = true;
			// cout << i << " " << j << " " << paintable << "\n";
			if (!paintable) {
				printf("No\n");
				return 0;
			}
		}
	}
	printf("Yes\n");
	return 0;
}


#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;

    int mx = 55555;

    vector<vector<int>> G(10);

    vector<bool> isPrime(mx + 2, true);
    isPrime[0] = isPrime[1] = false;
    for (int i = 2; i <= mx; ++i) {
        if (isPrime[i]) {
            G[i % 10].push_back(i);
            for (int j = i + i; j <= mx; j += i) {
                isPrime[j] = false;
            }
        }
    }

    for (auto x : G[1]) {
        cout << x;
        if (--n == 0) {
            cout << '\n';
            break;
        } else {
            cout << ' ';
        }
    }

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
inline int read(){
    int res=0;
    char c;
    bool zf=0;
    while(((c=getchar())<'0'||c>'9')&&c!= '-');
    if(c=='-')zf=1;
    else res=c-'0';
    while((c=getchar())>='0'&&c<='9')res=(res<<3)+(res<<1)+c-'0';
    if(zf)return -res;
    return res;
}
int tot[26];
signed main(){
	string ss;cin>>ss;int n=ss.size(),s=0;
	for(register int i=0;i<n;i++)tot[ss[i]-'a']++,s++;
	long long ans=1ll*s*(s-1)/2;for(register int i=0;i<26;i++)ans-=1ll*tot[i]*(tot[i]-1)/2;printf("%lld\n",ans+1);
	return 0;
}


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

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

int main(){
    int h,w;cin >> h >> w;
    queue<int> q;
    rep(i,h)rep(j,w){
        char ch;cin >> ch;
        if(ch == '#'){
            dist[i][j]=0;
            q.push(w*i+j);
        }else dist[i][j] = -1;
    }

    while(q.size()){
        int ind = q.front();
        q.pop();
        int y = ind/w;
        int x = ind%w;
        for(int i = 0;i < 4;i++){
            int ny = y + dy[i];
            int nx = x + dx[i];
            if(ny < 0 || nx < 0 || h <= ny || w <= nx) continue;
            if(dist[ny][nx]!=-1) continue;
            dist[ny][nx] = dist[y][x] + 1;
            q.push(w*ny+nx);
        }
    }
    int ans = 0;
    rep(i,h){
        rep(j,w){
            ans = max(ans,dist[i][j]);
        }
    }
    cout << ans << endl;

}

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;
typedef complex<ld> com;
constexpr int inf = 1000000000;
constexpr ll INF = 1000000000000000000;
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }

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

	int n;
	string s;
	cin >> n >> s;
	rep(i, 4) {
		string t = "";
		rep(j, 2) {
			if ((i >> j) & 1) t += 'S';
			else t += 'W';
		}
		for (int i = 1; i < n - 1; i++) {
			int cnt = 0;
			if (t[i - 1] == 'S') cnt ^= 1;
			if (t[i] == 'S') cnt ^= 1;
			if (s[i] == 'o') cnt ^= 1;
			if (cnt) t += 'S';
			else t += 'W';
		}
		int check = 0;
		if (t[n - 2] == 'S') check ^= 1;
		if (t[n - 1] == 'S') check ^= 1;
		if (t[0] == 'S') check ^= 1;
		if (s[n - 1] == 'o') check ^= 1;
		if (check) continue;
		if (t[n - 1] == 'S') check ^= 1;
		if (t[0] == 'S') check ^= 1;
		if (t[1] == 'S') check ^= 1;
		if (s[0] == 'o') check ^= 1;
		if (check) continue;
		cout << t << '\n';
		return 0;
	}
	cout << -1 << '\n';
}


#include <iostream>
#include <string>
using namespace std;
long long solve(long long x){
    if(x <= 6){
        return 1;
    }
    if(x <= 11){
        return 2;
    }
    long long res;
    res = x % 11;
    if(res == 0){
        return x / 11 * 2;
    }
    if(res <= 6){
        return x / 11 * 2 + 1;
    }
    else{
        return x / 11 * 2 + 2;
    }
}
int main(void){
    long long x;
    cin >> x;
    long long ans = solve(x);
    cout << ans << endl;

}

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

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

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  string s;
  cin >> s;
  set<char> d;
  for (char c = 'a'; c <= 'z'; c++) d.insert(c);
  for (auto &i : s) d.erase(i);
  if (d.empty()) cout << "None" << '\n';
  else cout << *d.begin() << '\n';
}


#include<bits/stdc++.h>

//      DEEP

using namespace std;
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define fwd(i,a,n) for(int i=a;i<=n;i++)
#define bak(i,a,n) for(int i=a;i>=n;i--)
#define all(v) v.begin(),v.end()
#define pb push_back
#define lop '\n'
#define mp make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pi;
typedef set<int> si;
const ll mod = 1e9 + 7;
const ll mod1=998244353;
                                                    //power
ull power(ull x,ull y){
   if(y==0) return 1;
   else{
     if(y%2==0) return power(x*x,y/2);
     else return x*power(x*x,(y-1)/2);
   }
}

                        //                    Modular Exponentiation

ll mod_power(ll x, ll y, ll m)
{
    ll r = 1;     // Initialize result

    x = x % m; // Update x if it is more than or equal to m

    if (x == 0) return 0; // In case x is divisible by m;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            r = (r*x) % m;

        // y must be even now
        y = y/2;
        x = (x*x) % m;
    }
    return r;
}

                                                      //GCD
ull gcd(ull x,ull y){
   if(y==0)return x;
   return gcd(y,x%y);
}
//                                         EXTENDED_EUCLID
vector<ll>extended_Euclid(ll a,ll b){
    vector<ll>v(3);
    if(b==0){
        v[0]=a;v[1]=1;v[2]=0;
        return v;
    }
    else{
         vector<ll>v1 = extended_Euclid(b,a%b);    //recursive call
         v[0]=v1[0];
         v[1]=v1[2];
         v[2]=v1[1]-(a/b)*v1[2];
         return v;
    }
}
                                          // DFS ( number of connected components  )
//vector<vector<ll> >adj(200001);
//bool visited[200001];
/*ll dfs(int x,int c){                         // x - > node      c - > number of edges in the component
    if(visited[x])return c;
    else{
        visited[x]=true;
        int y=c;
        for(int i=0;i<adj[x].size();i++){
            if(!visited[adj[x][i]]){
                c+=1;
                int d=dfs(adj[x][i],y);
                c+=d;
            }
        }
        return c;
    }
}
*/
                                              // SIEVE

/*
bool isPrime[100001];
void sieve(int N) {

        for(int i = 0; i <= N;++i) {
            isPrime[i]=true;
        }
        isPrime[0]=false;
        isPrime[1]=false;

        for(int i = 2; i * i <= N; ++i) {
             if(isPrime[i] == true) {
                 for(int j = i * i; j <= N ;j += i)
                     isPrime[j] = false;
            }
        }
    }
*/
                               // Binary Search
/*
ll bin_search(ll y){
  while(lo<hi){
    x=lo+(hi-lo)/2;
    if(condition){
            .....
    }
    else{
                  // increase lo or decrease hi suitably
            }
   }
}
*/

int main(){
    boost;
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        string s;
        cin>>s;
        if(s[0]==s[1] && s[0]==s[2])cout<<s<<endl;
        else{
            if(s[1]>s[0]){
                char x=s[0];
                x++;
                cout<<x<<x<<x<<endl;
            }
            else{
                if(s[1]==s[0]){
                if(s[2]<s[1])cout<<s[0]<<s[0]<<s[0]<<endl;
                else{
                    char x=s[0];
                    x++;
                    cout<<x<<x<<x<<endl;
                }
                }
                else{
                    cout<<s[0]<<s[0]<<s[0]<<endl;
                }
            }
        }
    }

}
/* Be careful about integer ranges;
   Check the corner cases before submitting.
*/

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int main()
{
	string str;
	map<char, int> p;

	p.insert(map<char, int>::value_type('I', 1));
	p.insert(map<char, int>::value_type('V', 5));
	p.insert(map<char, int>::value_type('X', 10));
	p.insert(map<char, int>::value_type('L', 50));
	p.insert(map<char, int>::value_type('C', 100));
	p.insert(map<char, int>::value_type('D', 500));
	p.insert(map<char, int>::value_type('M', 1000));

	while(cin >> str)
	{
		int len = str.size();
		vint num(len);

		rep(i, len)
			num[i] = p[str[i]];

		int res = num[len-1];
		rep(i, len-1)
		{
			if(num[i+1] <= num[i])
			{
				res += num[i];
			}
			else
			{
				res -= num[i];
				if(i + 1 != len - 1) res += num[i+1];
				i++;
			}
		}

		cout << res << endl;
	}
}


#include "bits/stdc++.h"
using namespace std;
template<typename Itr>
auto partition2(const Itr first, const Itr last){
  auto i=first;
  for(auto j=first; j!=last; ++j){
    if(*j<=*last){
      iter_swap(i, j);
      ++i;
    }
  }
  iter_swap(i, last);
  return i;
}
int32_t main(){
  size_t n; cin>>n;
  vector<uint32_t> a(n); for(auto&& e:a) cin>>e;
  const auto last=--end(a);
  auto mid=partition2(begin(a), last);
  for(auto i=begin(a); i!=mid; ++i) cout<<*i<<' ';
  cout<<'['<<*mid<<"] ";
  for(auto i=next(mid); i!=last; ++i) cout<<*i<<' ';
  cout<<*last<<'\n';
}

#include <iostream>
#include <cassert>
#include <queue>

#define INF 922337203685477580
typedef long long ll;

using namespace std;

int partition(int *A, int p, int r) {
  int x = A[r];
  int i = p - 1;
  for (int j = p; j < r; j++) {
    if (A[j] <= x) {
      i++;
      int a = A[i];
      A[i] = A[j];
      A[j] = a;
    }
  }
  int a = A[r];
  A[r] = A[i + 1];
  A[i + 1] = a;

  return i + 1;
}
int main() {
  int n;
  cin >> n;

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

  int pos = partition(A, 0, n - 1);
  for (int i = 0; i < n; i++) {
    if (i) cout << " ";
    if (i == pos) {
      cout << "[" << A[i] << "]";
    } else {
      cout << A[i];
    }
  }
  cout << endl;
  return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{

    int n;
    cin>>n;
    vector<int> v(n);
    for(int i = 0;i<n;i++)
    {
        cin>>v[i];
    }

    int minsofar = INT_MAX;
    int count = 0;
    for(int i = 0;i<n;i++)
    {
        minsofar = min(minsofar,v[i]);
        if(v[i] <= minsofar)
        {
            count++;
        }
    }

    cout<<count;

    return 0;
}

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

#define sz(x) (int)(x.size())
#define FOR(x,y,z) for(int x = y; x <= z; x++)
#define int long long

const int N = 1e5 + 2, inf = 1e18;

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

    int n, m;
    cin >> n >> m;
    if(n > m)
        swap(n, m);
    int k;
    cin >> k;
    int ans = 0;
    while(k > 0){
        k -= m;
        ans++;
    }
    cout << ans;
}


#include <bits/stdc++.h>
using namespace std;
#define all(n) begin(n), end(n)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    int N;
    cin >> N;
    int first = 0, last = (N - 1);
    vector<string> mem(N);
    string str1, str2;
    if (mem[first] == "")
    {
        cout << first << endl;
        cin >> str1;
        if (str1 == "Vacant")
            return 0;
        mem[first] = str1;
    }

    if (mem[last] == "")
    {
        cout << last << endl;
        cin >> str2;
        if (str2 == "Vacant")
            return 0;
        mem[last] = str2;
    }
    for (size_t i = 0; i < 18; i++)
    {
        int mid = (first + last) / 2;
        string str;
        if(mem[mid]=="")
        {
            cout<<mid<<endl;
            cin>>str;
            if(str == "Vacant")
            return 0 ;
            mem[mid]=str;
        }

        if (abs(first - mid) % 2 == 0)
        {
            if (mem[first] == mem[mid])
                first = mid;
            else
                last = mid;
        }
        else if (abs(first - mid) % 2 != 0)
        {
            if (mem[first] == mem[mid])
                last = mid;
            else
                first = mid;
        }
    }

    return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair

typedef pair<int, int> ii;

int n;
string s, temp;
vector<int> vec;

int main() {
    cin.tie(0), ios::sync_with_stdio(0);
    cin >> n;
    cout << 0 << "\n";
    cout.flush();
    cin >> s;
    temp = s;
    if(temp == "Vacant")
        exit(0);
    for(int i = 2; i < n; i+=2)
        vec.pb(i);
    int l = 0;
    for(int i = 20; i >= 0; i--){
        if(l + (1 << i) < n){
            cout << l + (1 << i) << "\n";
            cout.flush();
            cin >> s;
            if(s == "Vacant")
                exit(0);
            else{
                if(temp == s)
                    l += (1 << i);
            }
        }
    }
    cout << l + 1 << "\n";
    cout.flush();
    cin >> s;
    exit(0);
}


#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define ll long long

int main() {
	int n;
	scanf("%d", &n);
	int arr[n + 1];
	map<int, int> mp;
	for (int i = 0; i < n; i++) {
		scanf("%d", &arr[i]);
		if (mp[arr[i]] == 0) mp[arr[i]] = 1;
		else mp[arr[i]] = 0;
	}
	long long ans = 0;
	for (auto c : mp){
		ans += c.second;
	}
	printf("%lld" , ans);
}

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

int main(){
    int n;
    cin>>n;
    int a[n];
    int x;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    int tmp=0;
    int ans=0;
    while(tmp<n){
        int tmp2=a[tmp];
        int cnt=0;
        while(tmp<n&&a[tmp]==tmp2){
            tmp++;
            cnt++;
        }
        ans+=cnt%2;
    }
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;
const int inf = 1000000000; //10^9
const ll inff = 1000000000000000000; //10^18

int main(){
    string s;
    cin >> s;
    int n = s.size();
    bool a[26];
    rep(i, 26) a[i] = false;

    rep(i, n) {
        a[s[i] - 'a'] = true;
    }

    rep(i, 26) {
        if(!a[i]) {
            cout << (char)(i + 'a') << endl;
            return 0;
        }
    }

    cout << "None" << endl;

    return 0;
}

#include <iostream>
#include <string>
#include <map>
#include <string.h>
using namespace std;
int main(){
  map<char,int> ch;//文字の数字辞書登録
  ch['I']=1;
  ch['V']=5;
  ch['X']=10;
  ch['L']=50;
  ch['C']=100;
  ch['D']=500;
  ch['M']=1000;

  int ans=0;
  int len=0;
  char s[1111];
  while(cin >> s){
    len=strlen(s);
    for(int i=0;i<len;i++){
      if(ch[s[i]]<ch[s[i+1]]){//もしも引き算をすべき場合だったら
	ans-=ch[s[i]];
      }else{
	ans+=ch[s[i]];
      }
    }
    cout << ans << endl;
    ans=0;
  }
}


#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; ++i)
#define debug(s, param) std::cerr << s << param << std::endl;

using namespace std;
using ll = long long;

const ll MOD = 1000000007;

int bfs(const vector<string>& grids, int h, int w) {
  vector<vector<int>> deltas{{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
  vector<vector<bool>> visit(h, vector<bool>(w, false));
  queue<pair<int, int>> q;
  auto isAvailable = [h, w](int row, int col) { return (row >= 0 && row < h && col >= 0 && col < w); };
  q.emplace(0, 0);
  visit[0][0] = true;
  int steps = 0;
  while (!q.empty()) {
    int size = (int)q.size();
    rep (i, size) {
      int row = q.front().first, col = q.front().second;
      if (row == h - 1 && col == w - 1) return steps;
      q.pop();
      for (const auto& delta : deltas) {
        int nextRow = row + delta[0], nextCol = col + delta[1];
        if (isAvailable(nextRow, nextCol) && grids[nextRow][nextCol] == '.' && !visit[nextRow][nextCol]) {
          visit[nextRow][nextCol] = true;
          q.emplace(nextRow, nextCol);
        }
      }
    }
    ++steps;
  }
  return -1;
}

int main() {
  int h, w;
  cin >> h >> w;
  int blackNums = 0;
  vector<string> grids(h, "");
  rep (i, h) {
    cin >> grids[i];
    rep (j, w) if (grids[i][j] == '#') ++blackNums;
  }
  int res = bfs(grids, h, w);
  if (res == -1) cout << -1 << endl;
  else  cout << h * w - (blackNums + res + 1) << endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O0")
typedef long long int ll;
typedef long double ld;
const ll mod = 1e9+7;
const ll INF = 1e18;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define Rep(i,a,n) for (ll i = (a); i < (n); ++i)
#define All(a) (a).begin(),(a).end()
#define Pi acos(-1)
using Graph = vector<vector<ll>>;
using V = vector<ll>;
using P = pair<ll,ll>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  chrono::system_clock::time_point start,end;
  start = chrono::system_clock::now();

  ll h, w;
  cin >> h >> w;
  vector<string> grid(h);
  rep(i,h) cin >> grid[i];
  Graph d(h, V(w,-1));
  ll sy = 0, sx = 0, gy = h-1, gx = w-1;
  d[sy][sx] = 0;
  queue<P> q;
  vector dy = {0,1,0,-1};
  vector dx = {1,0,-1,0};

  q.push(make_pair(sy,sx));
  while(!q.empty()) {
    ll y = q.front().first, x = q.front().second;
    if (d[gy][gx] != -1) break;
    rep(i,4) {
      ll ny = y + dy[i], nx = x + dx[i];
      if (ny < 0 || nx < 0 || ny >= h || nx >= w) continue;
      if (grid[ny][nx] == '.' && d[ny][nx] == -1) {
        d[ny][nx] = d[y][x]+1;
        q.push(make_pair(ny,nx));
      }
    }
    q.pop();
  }

  ll cnt = 0;
  rep(i,h) rep(j,w) {
    if (grid[i][j] == '.') ++cnt;
  }

  if (d[gy][gx] == -1) cout << -1 << '\n';
  else cout << cnt - d[gy][gx] - 1 << '\n';

  end = chrono::system_clock::now();
  auto elapsed = chrono::duration_cast< chrono::milliseconds >(end - start).count();
  cerr << elapsed << "ms" << '\n';
}


#include <stdio.h>
#include <set>
using namespace std;
int gcd(int a,int b){return b==0?a:gcd(b,a%b);}
int main(){
    int n,ans,temp;
    set<long long int> s;
    scanf("%d%d",&n,&ans);
    n--;
    while(n--){
        scanf("%d",&temp);
        ans=gcd(ans,temp);
    }
    for(long long int i=1;i*i<=ans;i++)if(ans%i==0){
            s.insert(i);
            s.insert(ans/i);
    }
    for(auto u:s)printf("%lld\n",u);
}

#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <utility>

int main(){
  int N, M;
  scanf("%d", &N);
  scanf("%d", &M);
  std::vector<int > A(N);
  for (int i=0; i<N; i++){
    scanf("%d", &A[i]);
  }
  int sum=0;
  std::map<int, int> mp;
  mp[0]++;
  long long ans = 0;
  for (int i=0; i<N; i++){
    sum+=A[i];
    sum %= M;
    ans += mp[sum];
    mp[sum]++;
  }
  std::cout << ans << std::endl;
  return 0;
}


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

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=100005;
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }

    ll ans = 0;
    ll digits = 1;
    for(int i = 0; i < 60; i++){
        ll zero = 0, one = 0;
        for(int j = 0; j < n; j++){
            int x = (a[j]>>i) & 1;
            if(x == 0) zero++;
            else one++;
        }
        ll cnt = zero * one;
        cnt %= MOD;
        cnt *= digits;
        cnt %= MOD;
        ans += cnt;
        ans %= MOD;

        digits *= 2L;
        digits %= MOD;
    }

    cout << ans << endl;

    return 0;
}

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

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

  int64_t a[n+1];
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  a[n] = 100000001;

  sort(a,a+n);
  int64_t ans = 0,count = 1;
  for(int i = 0; i < n; i++){
    if(a[i] == a[i+1]){
      count++;
    }else{
      if( (count % 2) == 1){
        ans++;
      }
      count = 1;
    }
  }

  cout << ans << endl;
}


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

int main(){
    int m,n;
    priority_queue<int> que;

    while(cin>>n>>m,m|n){
        int sum=0;

        for(int i=0;i<n;i++){
            int p;
            cin>>p;
            que.push(p);
        }

        vector<int> bag;

        while(que.size()){
            int p=que.top();que.pop();
            bag.push_back(p);
            if(que.empty() || bag.size()==m){
                for_each(bag.begin(),bag.end(),[&sum](int v){sum += v;});
                if(bag.size()==m) sum-=p;
                bag.clear();
            }
        }

        cout<<sum<<endl;
    }

    return 0;
}

#include<iostream>
using namespace std;
long long cnt = 0;
void merge(int* arr, int left, int mid, int right) {
	int len1 = mid - left + 1;
	int len2 = right - mid;
	int* tempL = new int[len1];
	int* tempR = new int[len2];
	for (int i = 0; i < len1; i++)tempL[i] = arr[left + i];
	for (int i = 0; i < len2; i++)tempR[i] = arr[mid+1 + i];
	int i = 0, j = 0;
	for (int k = left; k <= right; k++)
		if (i < len1 && (j >= len2 || tempL[i] <= tempR[j]))
			arr[k] = tempL[i++];
		else {
			arr[k] = tempR[j++];
			cnt += (len1 - i);
		}
	delete[]tempL;
	delete[]tempR;
}
void mergeSort(int* arr, int left, int right) {
	int mid = (left + right) / 2;
	if (left < mid) {
		mergeSort(arr, left, mid);
		mergeSort(arr, mid + 1, right);
	}
	merge(arr, left, mid, right);
}
int main() {
	int len;
	cin >> len;
	int* arr = new int[len];
	for (int i = 0; i < len; i++)
		cin >> arr[i];
	mergeSort(arr, 0, len - 1);
	cout << cnt << endl;
	delete[]arr;
	return 0;
}


#include<bits/stdc++.h>
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int&
#define I inline
#define W while
#define N 300
#define X 998244353
#define Inc(x,y) ((x+=(y))>=X&&(x-=X))
using namespace std;
int n,m,a[N+5],f[N+5][N+5][N+5];char s[N+5];
int main()
{
	RI i,j,k,cnt=1;for(scanf("%s",s+1),n=strlen(s+1),i=1;i<=n;++i) s[i]^'0'?++a[cnt]:++cnt;//转化
	RI p;scanf("%d",&m),m=min(n,m),f[0][0][0]=1;//初始化
	for(i=0;i^cnt;++i) for(j=0;j<=m;++j) for(k=0;k<=m;++k) if(f[i][j][k])//枚举状态，如果状态能达到再去刷表
	{
		Inc(f[i+1][j][k],f[i][j][k]);//不操作
		for(p=m-j;p;--p) Inc(f[i+1][j+p][k+p],f[i][j][k]);//加上一个数
		for(p=min(a[i+1],k);p;--p) Inc(f[i+1][j][k-p],f[i][j][k]);//减去一个数
	}
	RI t=0;for(i=0;i<=m;++i) Inc(t,f[cnt][i][0]);return printf("%d\n",t),0;//输出答案
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 998244353;
string S;
int K, M;
int memo[400][400][400];
bool visited[400][400][400];
map<int,int> memo_g;
int g(int q) {
	if (memo_g.count(q)) return memo_g[q];
	int r = 0, qq = q;
	while (qq >= 0 && S[qq] == '1') { -- qq; ++ r; }
	return memo_g[q] = r;
}
int f(int p, int r, int s) {
	if (r > K) return 0;
	if (p == (int)S.length()) {
		return 1;
	}
	if (visited[p][r][s]) return memo[p][r][s];
	visited[p][r][s] = true;
	int q = M-p-s;
	int res = 0;
	if (q >= 0 && S[q] == '0') {
		res += f(p+1, r, s);
	} else {
		int x = g(q);
		int qq = q-x;
		if (qq >= 0 && S[qq] == '0') {
			res += f(p+1, r+x, s+x);
		}
	}
	if (q >= 0 && S[q] == '1') {
		res += f(p+1, r, s);
	} else if (s > 0) {
		res += f(p+1, r, s-1);
	}
	return memo[p][r][s] = res % mod;
}
int main() {
	cin >> S >> K;
	M = (int)S.length()-1;
	cout << f(0, 0, 0) << endl;
}