#include <iostream>
#include <string>
int main(){
  char s[10];
  for (int i = 0; i < 10; i++){
    std::cin >> s[i];
    if (i == 3){
      s[i] = '8';
    }
  }

  for (int i = 0; i < 10; i++){
    std::cout << s[i];
  }
  std::cout << std::endl;
  return 0;
}

#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll=long long;
using ld=long double;
//#define int long long
//#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int fact(int i) {
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int n;
int main(void) {
    cin>>n;
    cout << n / 3 << endl;
    return 0;
}


#include "bits/stdc++.h"

using namespace std;

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

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

int n,m;

int C[200][200];
int T[200][200];
int d[200];

int dijk(int s,int g,int r){
    bool used[200];
    rep(i,200)used[i]=false;
    rep(i,200)d[i]=999999999;

    d[s]=0;

    while(1){
        int v=-1;
        rep(u,m){
            if( !used[u]&&(v==-1||d[u]<d[v]) )v=u;
        }
        if(v==-1)break;

        used[v]=true;

        rep(u,m){
            if(r==0)
                d[u] = min(d[u],d[v]+C[v][u]);
            else
                d[u] = min(d[u],d[v]+T[v][u]);
        }
    }
    return d[g];
}

int main(){
    while(cin>>n>>m){
        if(n==0&&m==0)break;

        rep(i,200)rep(j,200){
            C[i][j]=999999999;
            T[i][j]=999999999;
        }
        rep(i,n){
            int a,b,c,t;
            cin>>a>>b>>c>>t;
            a--,b--;
            C[a][b]=c;
            C[b][a]=c;
            T[a][b]=t;
            T[b][a]=t;
        }

        int k;
        cin>>k;
        rep(i,k){
            int s,g,r;
            cin>>s>>g>>r;
            s--,g--;
            cout<<dijk(s,g,r)<<endl;
        }
    }
}

#include<bits/stdc++.h>
using namespace std;
using lli = long long;
#define rep(i,n) for(int i=0;i<n;i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

lli n, q, k;
vector<vector<pair<lli, lli>>> g;
vector<lli> dist;
vector<lli> x, y;

void dfs(lli x, lli d){
    dist[x] = d;
    for(auto i : g[x]){
        if(dist[i.second] >= 0) continue;
        dfs(i.second, lli(dist[x]+i.first));
    }
}

int main(void){
    cin >> n;
    g.resize(n);
    dist.assign(n, -1);
    rep(i, n-1){
        lli a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        g[a].push_back({c, b});
        g[b].push_back({c, a});
    }
    cin >> q >> k;
    k--;
    x.resize(q);
    y.resize(q);
    rep(i, q){
        cin >> x[i] >> y[i];
        x[i]--;
        y[i]--;
    }
    dist[k] = 0;
    dfs(k, 0);
    rep(i, q){
        cout << dist[x[i]]+dist[y[i]] << endl;
    }
    return 0;
}


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

#define rep(i,n) for(int i=0;i<(n);i++)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define dbg(x) cout<<#x"="<<x<<endl

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;

#define INF 1000000000
#define DAYS 100

int main(){
  int date[DAYS];

  while(true){
    int n,q;
    cin >> n >> q;
    if(n==0 && q==0) break;

    rep(i,DAYS) date[i]=0;

    rep(i,n){
      int m;
      scanf("%d",&m);
      rep(j,m){
	int d;
	scanf("%d", &d);
	date[d-1]++;
      }
    }

    int res=0, resN=q-1;
    rep(i,DAYS){
      if(date[i]>resN){
	res=i+1;
	resN=date[i];
      }
    }

    cout << res << endl;

  }

}

#include<iostream>
using namespace std;
int h,w,map[20][20];
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int f(int i,int j,int cnt)
{
	if(cnt>10)return 11;
	int ans=11;
	for(int r=0;r<4;r++)
	{
		int x=i+dx[r],y=j+dy[r];
		while(x>=0&&y>=0&&x<h&&y<w&&map[x][y]==0)x+=dx[r],y+=dy[r];
		if(x<0||y<0||x>=h||y>=w)continue;
		else if(map[x][y]==3)return cnt+1;
		else
		{
			map[x][y]=0;
			if(x-dx[r]!=i||y-dy[r]!=j)ans=min(ans,f(x-dx[r],y-dy[r],cnt+1));
			map[x][y]=1;
		}
	}
	return ans;
}
main()
{
	while(cin>>w>>h,h)
	{
		for(int i=0;i<h;i++)for(int j=0;j<w;j++)cin>>map[i][j];
		int sx,sy;
		for(int i=0;i<h;i++)for(int j=0;j<w;j++)
		{
			if(map[i][j]==2)
			{
				sx=i;sy=j;map[i][j]=0;
			}
		}
		int t=f(sx,sy,0);
		cout<<(t>10?-1:t)<<endl;
	}
}


#include <iostream>
#include <cmath>

using namespace std;

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

    double x1, y1, x2, y2;
    cin>>x1>>y1>>x2>>y2;
    cout<<hypot(x2-x1, y2-y1)<<'\n';
    return 0;
}

#include <stdio.h>
#include <math.h>
int main(){
  double vx,vy,v,x1,x2,y1,y2;
  scanf("%lf%lf%lf%lf", &x1,&y1,&x2,&y2);
  vx=(x2-x1)*(x2-x1);
  vy=(y2-y1)*(y2-y1);
  v=vx+vy;
  printf("%0.8f\n",sqrt(v));
  return 0;
}


#include <cstdio>
long long x[100001],p[100001],ans,n,s;
int main(){
	scanf("%d%d",&n,&s);
	for(int i=1;i<=n;i++)
		scanf("%d%d",&x[i],&p[i]);
	int i=1,j=n;
	while(i<=j){
		if(s<=x[i]){
			printf("%lld",x[j]-s+ans);
			return 0;
		}else if(s>=x[j]){
			printf("%lld",ans+s-x[i]);
			return 0;
		}
		if(p[i]>=p[j]){
			ans+=x[j]-x[i];
			while(i<j && p[i]>=p[j])p[i]+=p[j--];
		}else{
			ans+=x[j]-x[i];
			while(i<j && p[i]<p[j])p[j]+=p[i++];
		}
	}
}

#include <algorithm>
// #include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <bitset>
using namespace std;
typedef long long LL;
typedef double db;
const int oo=2139063143;
const int N=1010000;
const int P=1000000007;
const db eps=1e-7;
#define pritnf printf
//char buf[1<<22],*p1=buf,*p2=buf,obuf[1<<22],*O=obuf;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
template <typename T>
inline void sc (T &x)
{
    x=0; static int p; p=1; static char c; c=getchar();
    while (!isdigit(c)) { if (c=='-') p=-1; c=getchar(); }
    while ( isdigit(c)) { x=(x<<1)+(x<<3)+(c-48); c=getchar(); }
    x*=p;
}
template <typename T>
inline void print (T x)
{
    if (x< 0) putchar('-'),x=-x;
    if (x>=10) print(x/10);
    putchar(x%10+'0');
}
template <typename T>
inline void pr (T x) { print(x),putchar('\n'); }
template <typename T1,typename T2>
void chkmax (T1 &A,T2 B) { A=A>=B?A:B; }
template <typename T1,typename T2>
void chkmin (T1 &A,T2 B) { A=A<=B?A:B; }
int n,s,w[N]; LL a[N];
LL solve (int l,int r,int t)
{
	if (w[l]> s||w[r]< s) return max (abs (s-w[l]),abs (s-w[r]));
	if (a[l]>=a[r]) return a[l]+=a[r],a[r]=0,solve (l,r-1,l)+(t==r?w[r]-w[l]:0);
	return a[r]+=a[l],a[l]=0,solve (l+1,r,r)+(t==l?w[r]-w[l]:0);
}

int main ()
{
    // freopen (".in","r",stdin);
    // freopen (".out","w",stdout);
	sc(n),sc(s);
	for (int i=1; i<=n; i++)
		sc(w[i]),sc(a[i]);
	pr(solve (1,n,a[1]>=a[n]?n:1));

    return 0;
}


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

不妨设 n > 1 。

如果所有 a[i] 都是奇数，那么先手操作后会有一个偶数，约分后仍然有唯一偶数，
此时后手一定可以对唯一偶数操作，所有数成为奇数，约分后同样如此，
直到所有数都为 1 ，仍然没有偶数，那么当 a[i] 全是奇数时先手必败。

更一般的，假设 n 足够大奇数足够多，如果有偶数个偶数，
先手操作后有奇数个偶数，后手一定可以对偶数操作使得状态还原至奇数个偶数，
也就是说有奇数个偶数时先手必胜，反之先手必败。

特别的是，如果有偶数个偶数且奇数唯一，此时先手对唯一奇数操作后，所有数都是偶数，
此时一定可以约分，并且约分后的结果是难以推断的。
由于这种情况一定可以约分，那么所有数至少缩小一半，也就是最多进行 O(logn) 次，
每次碰到这种情况暴力约分即可，直到转为上述可以直接判断的情况。
#endif
#include <cstdio>
#include <algorithm>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long ll;

struct {
	inline operator int () { int x; return scanf("%d", &x), x; }
	inline operator ll () { ll x; return scanf("%lld", &x), x; }
	template<class T> inline void operator () (T &x) { x = *this; }
	template<class T, class ...A> inline void operator () (T &x, A &...a)
	{ x = *this; this -> operator ()(a...); }
} read;

const int maxn = 100005;
int a[maxn];

bool game(int n) {
	if(n == 1) return a[1] > 1;

	int even = 0;
	for(int i = 1; i <= n; i ++)
		if(!(a[i] & 1))
			++ even;

	if(even & 1) return 1;
	if(even != n - 1) return 0;

	for(int i = 1; i <= n; i ++)
		if(a[i] & 1) {
			if(a[i] == 1) return 0;
			-- a[i];
		}

	int gcd = a[1];
	for(int i = 2; i <= n; i ++)
		gcd = std::__gcd(gcd, a[i]);

	for(int i = 1; i <= n; i ++)
		a[i] /= gcd;

	return !game(n);
}

int main() {
	int n = read;

	for(int i = 1; i <= n; i ++)
		read(a[i]);

	if(n > 1) {
		int gcd = a[1];
		for(int i = 2; i <= n; i ++)
			gcd = std::__gcd(gcd, a[i]);

		for(int i = 1; i <= n; i ++)
			a[i] /= gcd;
	}

	puts(game(n) ? "First" : "Second");
}

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
    	if(c == '-') f = -1;
    	c = getchar();
    }
    while(c >= '0' && c <= '9') {
    	res = res * 10 +c - '0';
    	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
int N,A[MAXN];
int gcd(int a,int b) {
    return b == 0 ? a : gcd(b,a % b);
}
int check() {
    int c = 0,t;
    for(int i = 1 ; i <= N ; ++i) {
        if(A[i] & 1) {++c;t = A[i];}
    }
    if((N - c) & 1) return 1;
    if(c >= 2 || t == 1) return 0;
    return -1;
}
void Solve() {
    read(N);
    for(int i = 1 ; i <= N ; ++i) {
        read(A[i]);
    }
    int cnt = 0;
    while(1) {
        int x = check();
        if(x != -1) {
            if((x ^ cnt) == 1) puts("First");
            else puts("Second");
            return;
        }
        cnt ^= 1;
        int g = 0;
        for(int i = 1 ; i <= N ; ++i) {
            if(A[i] & 1) --A[i];
            g = gcd(g,A[i]);
        }
        for(int i = 1 ; i <= N ; ++i) {
            A[i] /= g;
        }
    }
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N,Q,K;
  cin>>N;
  vector<vector<pair<int,int>>> A(N);
  for(int i=1;i<N;i++){
    int a,b,c;
    cin>>a>>b>>c;
    A[a-1].push_back({b-1,c});
    A[b-1].push_back({a-1,c});
  }
  cin>>Q>>K;
  vector<int> B(N,-1);
  queue<int> q;
  B[K-1]=0;
  q.push(K-1);
  while(!q.empty()){
    int I=q.front();
    q.pop();
    for(pair<int,int> p:A[I])
      if(B[p.first]==-1){
        B[p.first]=B[I]+p.second;
        q.push(p.first);
      }
  }
  while(Q--){
    int x,y;
    cin>>x>>y;
    cout<<B[x-1]+B[y-1]<<endl;
  }
}

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999
//#define INF (1LL<<59)

#define MAX_V 100000
vector<int> G[MAX_V];   //???
vector<int> rG[MAX_V];  //??????

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

void dfs(int v, bool used[MAX_V], vector<int> &vs){
    used[v] = true;
    rep(i,G[v].size()){
        if(!used[G[v][i]])dfs(G[v][i],used,vs);
    }
    vs.push_back(v);
}

void rdfs(int v,int k,vector<int> &sccs, vector<int> &cmp, bool used[MAX_V]){
    used[v] = true;
    sccs.push_back(v);
    cmp[v] = k;
    rep(i,rG[v].size()){
        if(!used[rG[v][i]])rdfs(rG[v][i],k,sccs,cmp,used);
    }
}

int scc(int V, vector< vector<int> > &each_scc, vector<int> &cmp){
    vector<int> vs;
    bool used[MAX_V];
    rep(i,MAX_V)used[i] = false;
    vs.clear();
    rep(v,V){
        if(!used[v]) dfs(v, used, vs);
    }

    rep(i,MAX_V) used[i] = false;
    int k=0;
    for(int i=vs.size()-1;i>=0;i--){
        vector<int> sccs;
        if(!used[vs[i]]){
            rdfs(vs[i], k++, sccs, cmp, used);
            each_scc.push_back(sccs);
        }
    }
    return k;
}
/*
 vector<vector<int>> each_scc;  //????????????????????£?????????????????????
 vector<int> cmp(MAX_V);        //???????????????????±??????????????????£??????????????????( ??????each_scc????????????????????? )
 int k = scc(v,each_scc,cmp);   //?????£??????????????°???
*/

int main(){
    int V,E;
    cin>>V>>E;
    rep(i,E){
        int s,t;
        cin>>s>>t;
        add_edge(s,t);
    }
    vector<vector<int>> each_scc;
    vector<int> cmp(MAX_V);
    int k = scc(V,each_scc,cmp);

    int q;
    cin>>q;
    rep(i,q){
        int u,v;
        cin>>u>>v;
        if(cmp[u]==cmp[v])cout<<1<<endl;
        else cout<<0<<endl;
    }
}


#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

ll N, K;

ll solve(ll N);

int main()
{
    cin >> N >> K;
    cout << solve(N) << endl;
}

ll solve(ll N)
{
    if (N == 1)
    {
        return 2;
    }
    return min(solve(N - 1) * 2, solve(N - 1) + K);
}

#include<iostream>
using namespace std;

int main() {
    int N, K; cin >> N >> K;
    int ans = 1000;
    for (int i = 0; i <= N; i++) {
        int num = 1;
        for (int k = 0; k < i; k++) {
            num *= 2;
        }
        for (int k = 0; k < N - i; k++) {
            num += K;
        }
        ans = min(ans, num);
    }
    cout << ans << endl;
}


// #pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mod = 1e9 + 7;
const ll infll = 1e18 + 9;
const int infint = 1e9 + 7;
const int MAXN = 1e5 + 7;
const double eps = 1e-9;
const long double pi = 3.1415926535897932384626433832795;
const long double e = 2.71828182845904523536028747135266;
inline ll read()
{
    ll kr = 1, xs = 0;
    char ls;
    ls = getchar();
    while (!isdigit(ls))
    {
        if (!(ls ^ 45))
            kr = -1;
        ls = getchar();
    }
    while (isdigit(ls))
    {
        xs = (xs << 1) + (xs << 3) + (ls ^ 48);
        ls = getchar();
    }
    return xs * kr;
}
// inline __int128 read128()
// {
//     __int128 kr=1,xs=0;char ls;ls=getchar();
//     while(!isdigit(ls)){
//         if(!(ls^45)) kr=-1;ls=getchar();
//     }
//     while(isdigit(ls)){
//         xs=(xs<<1)+(xs<<3)+(ls^48);ls=getchar();
//     }
//     return xs*kr;
// }
inline ull readull()
{
    ull xs = 0;
    char ls;
    ls = getchar();
    while (!isdigit(ls))
        ls = getchar();
    while (isdigit(ls))
    {
        xs = (xs << 1) + (xs << 3) + (ls ^ 48);
        ls = getchar();
    }
    return xs;
}
inline void writeull(ull x)
{
    if (x < 0)
    {
        x *= -1;
        putchar('-');
    }
    if (x >= 10)
        writeull(x / 10);
    putchar('0' + x % 10);
}
inline void write(ll x)
{
    if (x < 0)
    {
        x *= -1;
        putchar('-');
    }
    if (x >= 10)
        write(x / 10);
    putchar('0' + x % 10);
}
// inline void write(__int128 x){
//     if(x<0){x*=-1;putchar('-');}
//     if(x>=10) write(x/10);
//     putchar('0'+x%10);
// }
///////////////////////////////////////////////////////////////////////////////////////
int a[MAXN];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // t = read();
    while (t--)
    {
        int n=read(),x=read(),T=read();
        n=n/x+(n%x?1:0);
        n*=T;
        printf("%d\n",n);
    }
    return 0;
}

    #include <bits/stdc++.h>
    #define rep(i,a,b) for(int i=(a);i<(b);i++)
    #define per(i,a,b) for(int i=(a);i>(b);i--)
    typedef long long ll;
    using namespace std;

    typedef double dd;

    int main(){
         ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,x,t;
    cin>>n>>x>>t;
    if((n%x)!=0) cout<<t*((n/x)+1);
    else {cout<<t*((n/x));return 0;}

        return 0;
    }


#include<iostream>
using namespace std;

int main() {
    int N;
    cin>>N;
    long A[N];
    for(int i=0;i<N;++i){
        cin>>A[i];
    }
    bool check = true;
    if(A[0]!=0)check = false;
    for(int i=1;i<N;++i){
        if(A[i]-A[i-1]>1)check = false;
    }
    long ans = A[N-1];
    if(check){
        for(int i=N-1;i>=1;--i){
            if(A[i]-A[i-1]!=1)ans += A[i-1];
        }
    }
    else ans = -1;
    cout<<ans<<endl;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
#define endl '\n'
#define pb push_back
#define fi first
#define se second
typedef long long ll;
#define double long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define all(con) con.begin(),con.end()
#define w(x) int x; cin>>x; while(x--)
const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;
//const int mod=998244353;
const int mod=1000000007;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cout<<fixed<<setprecision(8);
    ll n;
    cin>>n;
    vl a(n);
    ll neg = 0;
    ll mn = INT_MAX;
    rep(i,0,n)
    {
    	cin>>a[i];
    	mn = min(mn,abs(a[i]));
    	if(a[i] < 0)
    		neg++;
    }
    ll ans = 0;
    rep(i,0,n)
    	ans += abs(a[i]);
    if(neg&1^1)
    {
    	cout<<ans<<endl;
    }
    else
    {
    	ans -= 2*mn;
    	cout<<ans<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double db;
#define go(u) for(int i = head[u], v = e[i].to; i; i=e[i].lst, v=e[i].to)
#define rep(i, a, b) for(int i = a; i <= b; ++i)
#define pb push_back
#define re(x) memset(x, 0, sizeof x)
inline int gi() {
    int x = 0,f = 1;
    char ch = getchar();
    while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getchar();}
    while(isdigit(ch)) { x = (x << 3) + (x << 1) + ch - 48; ch = getchar();}
    return x * f;
}
template <typename T> inline bool Max(T &a, T b){return a < b ? a = b, 1 : 0;}
template <typename T> inline bool Min(T &a, T b){return a > b ? a = b, 1 : 0;}
const int N = 3e5 + 7;
int n, sz;
int a[4][N], inv[2], flip[2];
int tr[N];
int lowbit(int x) { return x & -x;}
void modify(int x, int y) { for(int i = x; i <= sz; i += lowbit(i)) tr[i] += y;}
int query(int x){
	int res = 0;
	for(int i = x; i; i -= lowbit(i)) res += tr[i];
	return res;
}
int main() {
#ifdef fwat
#endif
	n = gi(), sz = n * 3;
	rep(i, 1, 3)
	rep(j, 1, n) a[i][j] = gi();

	rep(j, 1, n) {
		int mi = min(a[1][j], min(a[2][j], a[3][j]));
		if(a[1][j] == mi) {
			if(!(a[2][j] == mi + 1 && a[3][j] == mi + 2)) return puts("No"), 0;
		}else if(a[3][j] == mi) {
			flip[j & 1] ^= 1;
			if(!(a[2][j] == mi + 1 && a[1][j] == mi + 2)) return puts("No"), 0;
		}else return puts("No"), 0;
		if(j % 2 == 1 && mi % 6 != 1) return puts("No"), 0;
		if(j % 2 == 0 && mi % 3 != 1) return puts("No"), 0;
	}
	for(int j = 1; j <= n; j += 2) {
		inv[1] ^= query(sz) - query(a[2][j]) & 1;
		modify(a[2][j], 1);
	}
	re(tr);
	for(int j = 2; j <= n; j += 2) {
		inv[0] ^= query(sz) - query(a[2][j]) & 1;
		modify(a[2][j], 1);
	}
	puts(flip[0] == inv[1] && flip[1] == inv[0] ? "Yes" : "No");
	return 0;
}

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

const int maxn=1e5+10;
int n,id[maxn],omove,orev,emove,erev,bit[maxn],rnk[maxn];
bool rev[maxn],vis[maxn];

inline void wrong(){
	puts("No");
	exit(0);
}
inline void add(int x,int val){
	while(x<maxn){
		bit[x]+=val;
		x+=x&-x;
	}
}
inline int sum(int x){
	int res=0;
	while(x){
		res+=bit[x];
		x-=x&-x;
	}
	return res;
}

int main(){
	cin>>n;
	for(int i=1,a;i<=n;++i){
		cin>>a;
		id[i]=(a+2)/3;
		rnk[id[i]]=i;
		if(vis[id[i]]||a==3*id[i]-1)
			wrong();
		vis[id[i]]=true;
		if(a==3*id[i])
			rev[i]=true;
	}
	for(int i=1,a;i<=n;++i){
		cin>>a;
		if(a!=3*id[i]-1)
			wrong();
	}
	for(int i=1,a;i<=n;++i){
		cin>>a;
		if(rev[i]&&a!=3*id[i]-2||!rev[i]&&a!=3*id[i])
			wrong();
	}
	for(int i=1;i<=n;++i)
		if((i&1)!=(id[i]&1))
			wrong();
	for(int i=1;i<=n;i+=2)
		add(i,1);
	for(int i=1;i<=n;i+=2){
		add(rnk[i],-1);
		omove+=sum(rnk[i]);
		orev+=rev[i];
	}
	memset(bit,0,sizeof(bit));
	for(int i=2;i<=n;i+=2)
		add(i,1);
	for(int i=2;i<=n;i+=2){
		add(rnk[i],-1);
		emove+=sum(rnk[i]);
		erev+=rev[i];
	}
	if((omove&1)!=(erev&1)||(emove&1)!=(orev&1))
		wrong();
	puts("Yes");
	return 0;
}


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

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

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

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

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

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

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

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

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

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

vector<string> split(const string &s, char delim) {
    vector<string> elems;
    string item;
    for (char ch: s) {
        if (ch == delim) {
            if (!item.empty())
                elems.push_back(item);
            item.clear();
        }
        else {
            item += ch;
        }
    }
    if (!item.empty())
        elems.push_back(item);
    return elems;
}

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

int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll n,m;
    cin >> n >> m;
    vector<ll> div = calc_divisor(m);
    sort(all(div));
    for(int i = sz(div) - 1; i >= 0; --i){
        if(n * div[i] <= m){
            print(div[i]);
            return 0;
        }
    }

}

#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;

bool is_prime(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;
}

int main() {
    ll N,M;
    cin>>N>>M;
    ll max_gcd=1;
    for(ll i= 1;i*i<=M;i++){
        if(M%i==0){
            if(M/i>=N){
                max_gcd=max(max_gcd,i);
            }
            if(i>=N){
                max_gcd=max(max_gcd,M/i);
            }

        }

    }
    cout<<max_gcd<<endl;

return 0;
}


    #include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>

    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()

    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<ll, ll>;

//const ll MOD = INF + 7;
//Combination MOD
const int MOD = 1e9 + 7;

int main(){
   int n;
   cin >> n;
   vector<int> a(n), b(n);
   vector<P> sum(n);
   rep(i, n){
      cin >> a[i] >> b[i];
      sum[i] = P(a[i] + b[i], i);
   }
   sort(ALL(sum), greater<P>());
   ll taka = 0, aok = 0;
   rep(i, n){
     //cout << sum[i].first << " " << sum[i].second << endl;
      if(i % 2 == 0){
         taka += a[sum[i].second];
      }
      else aok += b[sum[i].second];
   }
   cout << (ll)(taka - aok) << endl;
}

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

typedef long double ld;
typedef long long ll;

using namespace std;

struct dish {
	ll x, y;

	dish(ll tx = 0, ll ty = 0) {
		x = tx;
		y = ty;
	}

	void read() {
		cin >> x >> y;
	}

	bool operator<(const dish & d) const {
		return (x + y > d.x + d.y);
	}
};

#define MAXN (1 << 17)

dish a[MAXN];
int n;

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		a[i].read();
	}
	sort(a, a + n);
	ll ret = 0;
	for (int i = 0; i < n; i++) {
		if (i & 1) {
			ret -= a[i].y;
		} else {
			ret += a[i].x;
		}
	}
	cout << ret << endl;

	return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

using pv = pair<P,vector<int>>;
vector<int> graph[1005];

int main(){
    int n,m;
    cin >> n >> m;
    vector<P> edge(m);
    rep(i,m){
        cin >> edge[i].first >> edge[i].second;
        --edge[i].first;--edge[i].second;
        graph[edge[i].first].push_back(edge[i].second);
    }
    int id = -1;
    int mn = INF;
    vector<int> ans;
    rep(i,m){
        vector<bool> seen(n,false);
        queue<pv> q;
        q.push(pv(P(edge[i].second,0),{}));
        while(!q.empty()){
            int now = q.front().first.first;
            int c = q.front().first.second;
            vector<int> way = q.front().second;
            q.pop();
            if(now==edge[i].first){
                if(c < mn){
                    id = i;
                    mn = c;
                    way.push_back(now);
                    ans = way;
                    break;
                }else{
                    break;
                }
            }
            if(seen[now]) continue;
            seen[now] = true;
            way.push_back(now);
            for(int j:graph[now]){
                if(seen[j]) continue;
                q.push(pv(P(j,c+1),way));
            }
        }
    }
    if(mn==INF){
        cout << -1 << endl;
    }else{
        cout << (int)ans.size() << endl;
        rep(i,ans.size()) cout << ans[i]+1 << endl;
    }
    return 0;
}

//#define NDEBUG
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <utility>
#include <vector>

namespace n91 {

using i8 = std::int_fast8_t;
using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
using u8 = std::uint_fast8_t;
using u32 = std::uint_fast32_t;
using u64 = std::uint_fast64_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

struct rep {
  struct itr {
    usize i;
    constexpr itr(const usize i) noexcept : i(i) {}
    void operator++() noexcept { ++i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  const itr f, l;
  constexpr rep(const usize f, const usize l) noexcept
      : f(std::min(f, l)), l(l) {}
  constexpr auto begin() const noexcept { return f; }
  constexpr auto end() const noexcept { return l; }
};
struct revrep {
  struct itr {
    usize i;
    constexpr itr(const usize i) noexcept : i(i) {}
    void operator++() noexcept { --i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  const itr f, l;
  constexpr revrep(const usize f, const usize l) noexcept
      : f(l - 1), l(std::min(f, l) - 1) {}
  constexpr auto begin() const noexcept { return f; }
  constexpr auto end() const noexcept { return l; }
};
template <class T> auto md_vec(const usize n, const T &value) {
  return std::vector<T>(n, value);
}
template <class... Args> auto md_vec(const usize n, Args... args) {
  return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> constexpr T difference(const T &a, const T &b) noexcept {
  return a < b ? b - a : a - b;
}
template <class T> void chmin(T &a, const T &b) noexcept {
  if (b < a)
    a = b;
}
template <class T> void chmax(T &a, const T &b) noexcept {
  if (a < b)
    a = b;
}
template <class F> class rec_lambda {
  F f;

public:
  rec_lambda(F &&f) : f(std::move(f)) {}
  template <class... Args> auto operator()(Args &&... args) const {
    return f(*this, std::forward<Args>(args)...);
  }
};
template <class F> auto make_rec(F &&f) { return rec_lambda<F>(std::move(f)); }
template <class T> T scan() {
  T ret;
  std::cin >> ret;
  return ret;
}
constexpr char eoln = '\n';

} // namespace n91

#include <cassert>

namespace n91 {

void main_() {
  /*
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  //*/
  constexpr usize Inf = std::numeric_limits<usize>::max() / 2;
  const usize n = scan<usize>();
  const usize m = scan<usize>();
  auto g = md_vec(n, n, Inf);
  for (const usize i : rep(0, m)) {
    const usize a = scan<usize>() - 1;
    const usize b = scan<usize>() - 1;
    g[a][b] = 1;
  }
  for (const usize i : rep(0, n)) {
    for (const usize j : rep(0, n)) {
      for (const usize k : rep(0, n)) {
        chmin(g[j][k], g[j][i] + g[i][k]);
      }
    }
  }
  usize st = 0;
  for (const usize i : rep(0, n)) {
    if (g[i][i] < g[st][st]) {
      st = i;
    }
  }
  if (g[st][st] >= Inf) {
    std::cout << "-1" << eoln;
    return;
  }
  std::vector<usize> ans;
  usize v = st;
  do {
    for (const usize i : rep(0, n)) {
      if (g[v][i] == 1 && ans.size() + 1 + g[i][st] == g[st][st]) {
        ans.push_back(i);
        v = i;
        break;
      }
    }
  } while (ans.size() != g[st][st] - 1);
  ans.push_back(st);
  std::cout << ans.size() << eoln;
  for (const auto e : ans) {
    std::cout << e + 1 << eoln;
  }
}

} // namespace n91

int main() {
  n91::main_();
  return 0;
}


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

int main(){
  ll x;cin>>x;
  cout<<x/11*2+(x%11>6?2:x%11>0?1:0);;
}

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

int main(){
    long x, ans = 0;
    cin >> x;
    ans += 2 * (x / 11);
    x %= 11;
    if(x > 0) ans++;
    if(x > 6) ans++;
    cout << ans << endl;
    return 0;
}


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

// ----------- define --------------
#define int long long
#define vi vector<int>
#define vc vector<char>
#define ii pair<int,int>
#define fi first
#define sc second
#define stoi stoll
#define all(x) (x).begin(),(x).end()
#define get_bit(x, k) ((x >> k) & 1)
// ---------------------------------

void MAIN() {
  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.size()) {
    s += *d.begin();
    cout << s << '\n';
    return;
  }
  set<char> g;
  while (s.size()) {
    char c = s.back();
    s.pop_back();
    auto it = g.upper_bound(c);
    if (it != g.end()) {
      s += *it;
      cout << s << '\n';
      return;
    }
    g.insert(c);
  }
  cout << -1 << '\n';
}

signed main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
const int N = 2e5 + 10, OO = 0x3f3f3f3f, mod = 1e9 + 7;

#define PI acos(-1)
#define clr(arr, val) memset(arr, val, sizeof(arr))
#define loop(i, n) for (int i = 0; i < int(n); i++)
#define rloop(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define xloop(i, a, b) for (int i = int(a); i <= int(b); i++)
#define ALL(v) ((v).begin()), ((v).end())
#define SZ(v) ((int)((v).size()))
//int dx[] = {1, 0, -1, 0};
//int dy[] = {0, 1, 0, -1}; //4 Direction
//int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
//int dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; //8 direction
int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction

//-- "كلٌّ من يسعى لابد يصل .. كلٌّ من يسعى مضمون له الوصول" --//

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

	string s;
	cin >> s;
	int len = s.size();
	if(len < 26){
		int vis[26] = {};
		for(int i = 0 ; i < len ; ++i)
			vis[s[i]-'a']++;
		for(int i = 0 ; i < 26 ; ++i)
			if(!vis[i])
				return cout << s << char(i+'a') << "\n" , 0;
	}
	else{
		string temp = "";
		for(int i = 25 ; i >= 0 ; --i)
			temp += char(i + 'a');
		if(s == temp)
			cout << "-1\n";
		else{
			set < char > st;
			for(int i = 25 ; i >= 0 ; --i){
				st.insert(s[i]);
				if(s[i-1] < s[i]){ // abc
					char add = *st.upper_bound(s[i-1]);
					cout << s.substr(0 , i-1) << add << "\n";
					break;
				}
			}
		}
	}

    return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#define INF 999999
using namespace std;
int main(){
    int N;
    while(cin>>N,N){
        int ice[15]={0},X;
        while(N--){
            cin>>X;
            ice[X]++;
        }
        for(int i=0;i<10;i++){
            if(ice[i]==0)cout<<"-";
            else{
                while(ice[i]--){
                    cout<<"*";
                }
            }
            puts("");
        }
    }
    return 0;
}

#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<string.h>
using namespace std;

struct DICE
{
	int f[8];
};
DICE dice;

int  ch(char a)
{
	int s[60];
	for (int i = 1; i < 7; i++)
	{
		s[i] = dice.f[i];
	}
		int k = a;
	switch (k)
	{
	case 78://N
		dice.f[1] = s[2];
		dice.f[2] = s[6];
		dice.f[6] = s[5];
		dice.f[5] = s[1];
		break;
	case 69:
		dice.f[1] = s[4];
		dice.f[4] = s[6];
		dice.f[6] = s[3];
		dice.f[3] = s[1];
		break;
	case 83://S
		dice.f[2] = s[1];
		dice.f[1] = s[5];
		dice.f[5] = s[6];
		dice.f[6] = s[2];
		break;
	case 87:
		dice.f[4] = s[1];
		dice.f[1] = s[3];
		dice.f[3] = s[6];
		dice.f[6] = s[4];
		break;
	}
	return 0;
}

int main()
{

	for (int i = 1; i < 7; i++)cin >> dice.f[i];
	char d[10000];
	cin >> d;
	int z = strlen(d);
	for (int i = 0; i <z; i++)
	{
		int a=ch(d[i]);
	}

	cout << dice.f[1]<<endl;
}


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

const int MOD = 1000000007;
const int INF = 1e9;

long long gcd(long long x, long long y){
  if(y == 0) return x;
  else return gcd(y, x%y);
}

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<long long> EnumDivisors(long long n){
  vector<long long> res;

  for(long long i = 1; i * i <= n; i++){
    if(n % i == 0){
      res.push_back(i);
      if(n/i != i) res.push_back(n/i);
    }
  }
  sort(res.begin(), res.end());
  return res;
}

vector<pair<long long, long long>> PrimeFactorize(long long n){
  vector<pair<long long, long long>> res;

  long long a = 0;
  long long b = 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;

}

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

  vector<pair<long long, long long>> a_fac = PrimeFactorize(a);
  vector<pair<long long, long long>> b_fac = PrimeFactorize(b);

  // for(int i = 0; i < a_fac.size(); i++) cout << a_fac[i].first << ", " << a_fac[i].second << endl;
  // for(int i = 0; i < b_fac.size(); i++) cout << b_fac[i].first << ", " << b_fac[i].second << endl;

  long long ans = 0;
  for(int i = 0; i < a_fac.size(); i++){
    for(int j = 0; j < b_fac.size(); j++){
      if(a_fac[i].first == b_fac[j].first) {
        // cout << "i = " << i << ", j = " << j << endl;
        ans ++;
      }
    }
  }
  cout << ans + 1 << endl;

  return 0;
}

//int a = s - '0'; 文字から数字
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//例外処理は最初にする
//x = p^m + q^n...の約数の個数:(n+1)*(m+1)....
//N!のどの素因数で何回割れるか
//⇔1~Nまでの数がそれぞれどの素因数で何回割り切れるかの和
//パズルの問題->一般化して全探索
//stack<ll> s;
//s.push(要素);s.top();s.pop();
//queue<ll> q;
//q.push(要素);q.front();q.pop();
//同じ作業繰り返す系の問題：収束先を見つける
//過半数：N/2.0で判定
//優先度付きキュー
//priority_queue<
//ll,
//vector<ll>
//> q;
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
#define PI 3.14159265358979323846264338327950L
using namespace std;

//割るやつ
const ll MOD = (pow(10, 9) + 7);

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

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

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n * f(n - 1));
}

//Nのd桁目の数
ll dignum(ll N, ll d) {
	ll x = pow(10, d);
	N %= x;
	ll y = pow(10, d - 1);
	N /= y;
	return N;
}

//Nをdで何回割れるか
ll divcnt(ll N, ll d) {
	ll ans = 0;
	while (1) {
		if (N%d == 0) {
			ans++;
			N /= d;
		}
		else break;
	}

	return ans;
}

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

//フィボナッチ数列
vector<ll> memo(pow(10, 6) + 1);
ll fibo(ll n) {
	if (n == 1) return 1;
	else if (n == 2) return 1;
	else if (memo[n] != 0) return memo[n];
	else return memo[n] = fibo(n - 1) + f(n - 2);
}

ll RS(ll N, ll P, ll M) {
	if (P == 0) return 1;
	if (P % 2 == 0) {
		ll t = RS(N, P / 2, M);
		return t * t % M;
	}
	return N * RS(N, P - 1, M);
}

vector<int> IntegerToVector(int bit, int N) {
    vector<int> S;
    for (int i = 0; i < N; ++i) {
        if (bit & (1 << i)) {
            S.push_back(i);
        }
    }
    return S;
}

int main() {
	ll N, M;cin >> N >> M;
	vector<ll> L(M), R(M);
	rep(i,M) cin >> L[i] >> R[i];

	sort(ALL(L));
	sort(ALL(R));

	if(R[0] - L[M-1] + 1 < 0) cout << 0 << endl;
	else cout << R[0] - L[M-1] + 1 << endl;
}


		#include <bits/stdc++.h>
		using namespace std;
		typedef long long ll;
		#define PRINT(x,y) cout<<"Case #"<<(int)x<<": "<<(int)(y)<<endl;
		ll exp(ll x, ll y) {
			if(y==0) return 1;
			if(y==1) return x;
			if(y%2==0) return exp(x,y/2)*exp(x,y/2);
			else return x*exp(x,y/2)*exp(x,y/2);
		}
		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);
		}
		#define vec(n) vector<int> v((int)(n),0);
		#define vecl(n) vector<ll> v((ll)(n),0);
		#define sq(a) ((int)(a))*((int)(a));
		#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
		int l;
		ll fact(ll x) {
			if(x==1) return 1;
			else return x*fact(x-1);
		}
		bool isPrime(int x) {
			int ans  = 0;
			for(int i=2;i<=sqrt(x);++i) {
				if(x%i==0) {
					ans = 1; i=x;
				}
			}
			if(ans==0) return true;
			else return false;
		}
		ll isPerfect(ll x) {
			double y = sqrt(x);
			return (floor(y)==ceil(y));
		}

		int z = 0;
		void ask(int x, int y) {
			cout<<"? "<<x<<" "<<y<<endl;
			}

		void solve() {
			int n; cin>>n;
			vector<ll> v(n);
			for(int i=0;i<n;++i) cin>>v[i];
			ll suff[n+1] = {0};
		reverse(v.begin() , v.end());
			for(int i=n-1;i>=0;i--) {
				suff[i] = max(suff[i+1] , v[i]);
			}
			ll sum = 0;
			for(int i=0;i<n;++i) {
				if(v[i]<suff[i+1]) sum+=abs(v[i]-suff[i+1]);
			}
			cout<<sum;

		}

		int main() {
			io

			 solve();
		}

#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
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;}

int main(){
    ll n;
    cin >> n;
    vi a(n);
    rep(i, n) {
        cin >> a.at(i);
    }
    ll ans = 0;
    rep(i, n-1) {
        if(a.at(i) >= a.at(i+1)) {
            ans += a.at(i) - a.at(i+1);
            a.at(i+1) = a.at(i);
        }
    }
    cout << ans << endl;
    return 0;
}


#include <cstdio>

const int MAXN = 6005;

template<typename _T>
void read( _T &x )
{
	x = 0;char s = getchar();int f = 1;
	while( s > '9' || s < '0' ){if( s == '-' ) f = -1; s = getchar();}
	while( s >= '0' && s <= '9' ){x = ( x << 3 ) + ( x << 1 ) + ( s - '0' ), s = getchar();}
	x *= f;
}

template<typename _T>
void write( _T x )
{
	if( x < 0 ){ putchar( '-' ); x = ( ~ x ) + 1; }
	if( 9 < x ){ write( x / 10 ); }
	putchar( x % 10 + '0' );
}

int f[MAXN][MAXN << 1];
int N, M;

void add( int &x, const int v ) { x += v; if( x >= M ) x -= M; }

int main()
{
	read( N ), read( M );
	int t = N * 3;
	f[0][t] = 1;
	for( int i = 1 ; i <= t ; i ++ )
		for( int j = - t ; j <= t ; j ++ )
		{
			if( j > -t ) add( f[i][j + t], f[i - 1][j + t - 1] ); //长度为1
			if( j < t && i >= 2 ) add( f[i][j + t], 1ll * f[i - 2][j + t + 1] * ( i - 1 ) % M ); //长度为2
			if( i >= 3 ) add( f[i][j + t], 1ll * f[i - 3][j + t] * ( i - 1 ) % M * ( i - 2 ) % M ); //长度为3
		}
	int ans = 0;
	for( int i = 0 ; i <= t ; i ++ ) add( ans, f[t][i + t] );
	write( ans ), putchar( '\n' );
	return 0;
}

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

using namespace std;

// true:a < b false:a > b
bool mycomp(pair <int, int> a, pair <int, int> b)
{
	int c = a.first*a.first + a.second*a.second;
	int d = b.first*b.first + b.second*b.second;
	if (c == d){
		return a.first < b.first;
	}
	return c < d;
}

int main(void)
{
	int h, w;

	// cout << mycomp(make_pair(1, 2), make_pair(1, 3)) << endl;
	while (cin >> h >> w){
		if (h == 0 && w == 0){
			return 0;
		}
		pair <int, int> rect(h, w);
		pair <int, int> ret(-1, -1);
		int nowmax = 10e9;
		for (int i = 1; i <= 150; i++){
			for (int j = i+1; j <= 150; j++){
				if (i == h && j == w) continue;
				pair <int, int> tmp(i, j);
				if (mycomp(rect, tmp)){ // tmpの方が大きい
					if (ret.first == -1 || mycomp(tmp, ret)){
						ret = tmp;
					}
				}
			}
		}

		cout << ret.first << " " << ret.second << endl;
	}

	return 0;
}


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

vector<pair<long long,long long>> bunkai;

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

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

#define LL long long
#define DD long double

#define M 1000000007
#define INF 1e18

void setIO(string s = "") {
  cin.sync_with_stdio(0); cin.tie(0);
  if (s.size()) s += ".in", freopen(s.c_str(), "r", stdin);
}

int tt = 1;
void solve() {
  set<int> nums;
  int a;
  while (cin >> a) nums.insert(a);
  cout << ((nums.size() == 2) ? "Yes" : "No") << endl;
}

int main() {
  setIO();
  while (tt--) {
    solve();
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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

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

const ll MOD = 1e9 + 7;

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

  int N, M;
  cin >> N >> M;
  vector<int> A(N), B(M);

  rep(i, N) cin >> A[i];
  rep(i, M) cin >> B[i];

  sort(A.rbegin(), A.rend());
  sort(B.rbegin(), B.rend());

  queue<int> qA, qB;

  rep(i, N) qA.push(A[i]);
  rep(i, M) qB.push(B[i]);

  int now = N * M;
  ll ans = 1;
  ll cnt_a = 0;
  ll cnt_b = 0;
  while(now > 0){

    int fa = -1;
    int fb = -1;
    if(qA.size() > 0){
      fa = qA.front();
    }
    if(qB.size() > 0){
      fb = qB.front();
    }

    if(fb == now && fa == fb){
      qA.pop();
      qB.pop();
      cnt_a++;
      cnt_b++;
      now--;
    }else if(fb == now){
      ans = (ans * cnt_a) % MOD;
      qB.pop();
      cnt_b++;
      now--;
    }else if(fa == now){
      ans = (ans * cnt_b) % MOD;
      qA.pop();
      cnt_a++;
      now--;
    }else{

      if(cnt_a * cnt_b - (N * M - now) <= 0){
        ans = 0;
      }else{

        ans = (ans * (cnt_a * cnt_b - (N * M - now))) % MOD;

      }
      now--;
    }
  }

  cout << ans << endl;

  return 0;
}

#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <cstdio>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

map<int, int> mp;
vector<LL> A, B, arr;

bool ok[1000*1000+1];
int main() {
    int N = readInt();
    int M = readInt();

    REP(i, N) {
        int a = readInt();
        A.push_back(a);
        mp[a]++;
    }

    for(auto e: mp){
        if(e.second>=2){
            cout << 0 << endl;
            return 0;
        }
    }

    REP(i, M){
        int b = readInt();
        B.push_back(b);
        mp[b]++;
    }

    for(int i=0; i<N; ++i){
        for(int j=0; j<M; ++j){
            arr.PB(min(A[i], B[j]));
        }
    }

    //for(int i=0; i<N*M; ++i) cout << arr[i] << endl;

    sort(arr.begin(), arr.end());
    for(auto e: mp){
        if(e.second>=3){
            cout << 0 << endl;
            return 0;
        }else if(e.second==2){
            ok[e.first] = true;
        }
    }

    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    //for(int i=0; i<N*M; ++i) cout << arr[i] << endl;
    LL ans=1;
    for(int i=N*M; i>=2; --i){

        if(ok[i]){
            continue;
        }
        if((A.end() - lower_bound(A.begin(), A.end(), i)) * (B.end() - lower_bound(B.begin(), B.end(), i)) - (N*M-i) <= 0) {
            cout << 0 << endl;
            return 0;
        }
        if(find(A.begin(), A.end(), i)!=A.end()){
           ans *= B.end() - lower_bound(B.begin(), B.end(), i);
        }else if(find(B.begin(), B.end(), i)!=B.end()){
            ans *= A.end() - lower_bound(A.begin(), A.end(), i);
        }else{

        ans *= (A.end() - lower_bound(A.begin(), A.end(), i)) * (B.end() - lower_bound(B.begin(), B.end(), i)) - (N*M-i);

        }ans %= MOD;
    }
    cout << ans << endl;

	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <memory>
#include <string>

#include <algorithm>
#include <complex>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
#endif

#define ITER(c)         __typeof__((c).begin())
#define FOREACH(it, c)  for (ITER(c) it=(c).begin(); it != (c).end(); ++it)
#define RITER(c)        __typeof__((c).rbegin())
#define RFOREACH(it, c) for (RITER(c) it=(c).rbegin(); it != (c).rend(); ++it)
#define REP(i, n)       REPEAT(i, 0, n)
#define REPEAT(i, k, n) for (int i = (k); i < (n); ++i)
#define REVREP(i, n)    for (int i = ((n)-1); i >= 0; --i)
#define FIND(c, n)      std::find((c).begin(), (c).end(), (n));
#define BSEARCH(c, n)   std::binary_search((c).begin(), (c).end(), (n))
#define LLPOW(p1,p2)    ((ll)pow((double)(p1), (int)p2))
#define ESIZEOF(A)      (sizeof(A)/sizeof((A)[0]))
#define MIN(p1,p2)      (((p1)<(p2))?(p1):(p2))
#define MAX(p1,p2)      (((p1)>(p2))?(p1):(p2))
#define CIN_NO_SYNC     do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0)
#define GETSTR(p)       fgets((p), sizeof(p), stdin)
#define CHOMP(p)        do{ char *_q = (p) + strlen(p)-1; if(*_q == '\n') *_q = 0; } while(0)

typedef long long ll;
typedef unsigned long long ull;

#ifdef _DEBUG
#define pf printf
#define pr(n) do { cout << #n " = " << (n) << endl; } while(0)
#else
#define pf(...) /* */
#define pr(...) /* */
#endif

namespace roman {
struct romantbl_t {
    const char *rom;
    int num;
} table[] = {
    { "M",  1000,   },
    { "CM", 900,    },
    { "D",  500,    },
    { "CD", 400,    },
    { "C",  100,    },
    { "XC", 90,     },
    { "L",  50,     },
    { "XL", 40,     },
    { "X",  10,     },
    { "IX", 9,      },
    { "V",  5,      },
    { "IV", 4,      },
    { "I",  1,      },
};

map<int,string> num2rom;
map<string,int> rom2num;

void romaninit(){
    for(int i = 0; i < sizeof(table)/sizeof(table[0]); i++){
        rom2num.insert(make_pair(table[i].rom, table[i].num));
        num2rom.insert(make_pair(table[i].num, table[i].rom));
    }
}

int roman2num(string rom){
    int len = rom.length();
    int t = 0, p = 0;
    for(int i = len - 1; i >= 0; i--){
        string c = rom.substr(i,1);
        int n = rom2num[c];
        if(n < p){ t -= n; } else { t += n; }
        p = n;
    }
    return t;
}

string num2roman(int num){
    string t;
    for(int i = 0; i < sizeof(table)/sizeof(table[0]); i++){
        int n = table[i].num;
        while(num >= n){
            t += num2rom[n]; num -= n;
        }
    }
    return t;
}
}

using namespace roman;

int main(){
    string s;
    romaninit();
    while(getline(cin, s)){
        cout << roman2num(s) << endl;
    }
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

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

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

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

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

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

  ll n;
  cin >> n;
  vll v(n);
  rep(i, n) {
    cin >> v[i];
  }

  map<ll, ll> odd, even;
  rep(i, n) {
    if (i % 2 == 0) {
      odd[v[i]]++;
    } else {
      even[v[i]]++;
    }
  }

  ll k = n / 2;
  ll ans = 0;

  priority_queue<P> oq, eq;

  for (auto it : odd) {
    oq.emplace(it.second, it.first);
  }
  oq.emplace(0, -1);

  for (auto it : even) {
    eq.emplace(it.second, it.first);
  }
  eq.emplace(0, -1);

  if (oq.top().second != eq.top().second) {
    ans = n - (oq.top().first + eq.top().first);
  } else {
    ll ot, et;
    ot = oq.top().first;
    et = eq.top().first;
    oq.pop();
    eq.pop();
    ans = n - (ot + eq.top().first);
    chmin(ans, n - (et + oq.top().first));
  }

  cout << ans << endl;

  return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef pair<int,int> pii;
const int N = 1010;
const int dx[] = {-1, 1, 0, 0};
const int dy[] = {0, 0, -1, 1};
int _w;

int n, m;
char str[N][N];
int dis[N][N];
queue<pii> q;

bool inside( int x, int y ) {
	return x >= 1 && x <= n && y >= 1 && y <= m;
}

int main() {
	_w = scanf( "%d%d", &n, &m );
	for( int i = 1; i <= n; ++i )
		_w = scanf( "%s", str[i]+1 );
	memset(dis, -1, sizeof dis);
	for( int i = 1; i <= n; ++i )
		for( int j = 1; j <= m; ++j )
			if( str[i][j] == '#' )
				dis[i][j] = 0, q.push( pii(i, j) );
	int ans = 0;
	while( !q.empty() ) {
		pii now = q.front(); q.pop();
		ans = max(ans, dis[now.first][now.second]);
		for( int i = 0; i < 4; ++i ) {
			int nx = now.first + dx[i];
			int ny = now.second + dy[i];
			if( inside(nx, ny) && dis[nx][ny] == -1 ) {
				dis[nx][ny] = dis[now.first][now.second] + 1;
				q.push( pii(nx, ny) );
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
    int h, w;
    char t;
    cin >> h >> w;
    vector<vector<bool>> c(h, vector<bool>(w, false));
    queue<pair<int, int>> que1, que2;
    rep(i, h) rep(j, w){
        cin >> t;
        if(t == '#'){
            que2.push(make_pair(i, j));
            c[i][j] = true;
        }
    }
    pair<int, int> p;
    vector<int> dy ={1,0,-1,0}, dx={0,1,0,-1};
    int tx, ty, result = 0;
    while(!que2.empty()){
        ++result;
        que2.swap(que1);
        while(!que1.empty()){
            p = que1.front();
            que1.pop();
            rep(i, 4){
                ty = p.first + dy[i];
                tx = p.second + dx[i];
                if(ty==-1||tx==-1||ty==h||tx==w||c[ty][tx]) continue;
                que2.push(make_pair(ty, tx));
                c[ty][tx] = true;
            }
        }
    }
    cout(result-1);
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = (0); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define DEBUG(val) cout << #val << " : " << val << endl
#define MOD 1000000007

int main() {
  int k, t;
  cin >> k >> t;
  int ans = 0;
  int prev = -1;
  priority_queue<pair<int, int>> data;
  REP(i, t) {
    int x;
    cin >> x;
    pair<int, int> p = make_pair(x, i + 1);
    data.push(p);
  }

  while (!data.empty()) {
    pair<int, int> p1 = data.top();
    data.pop();
    if (data.empty()) {
      ans += (p1.first - 1);
      break;
    }
    pair<int, int> p2 = data.top();
    data.pop();
    if (p1.first != 1) {
      pair<int, int> p = make_pair(p1.first - 1, p1.second);
      data.push(p);
    }
    if (p2.first != 1) {
      pair<int, int> p = make_pair(p2.first - 1, p2.second);
      data.push(p);
    }
  }
  cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define INF 1000000001
//A=65,a=97

int main() {
    int k,t;cin >> k >> t;
    vector<int> a(t);for(int i=0;i<t;i++) cin >> a[i];
    sort(a.begin(),a.end());
    if(a[t-1]<=(k+1)/2){
        cout << 0 << endl;
        return 0;
    }

    a[t-1] -= k-a[t-1];
    cout << a[t-1]-1 << endl;

    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA
//long*long<0で判定するな
//開区間と閉区間
//アルファベットが何番目かは x=s[i]-'a'
//bfsはmain()内で　rep(i,h)rep(j,w)rep(i,4)でバグ
//切り上げ：(a+(b-1))/b
//32bit以上は 1ull<<j
// map 初期値0 for(auto itr=mp.begin();itr!=mp.end();++itr) itr->fi itr->se で全探索
// for(auto u:mp) u.fi u.se も可能
//n個のgcd,lcmは一つずつみて更新していく
//大きな数を扱うときは素因数分解した形で持っておく
// (l/a[i]) = l*powmod(a[i],MOD-2)%MOD;
//auto itr=lower_bound(ALL(a),key) a[itr-a.begin()]
const ll MOD = 1000000007;
signed main(){
    int h,w,k;
    cin >> h >> w >> k;
    k--;
    if(w==1){
        if(k==0) cout << 1 << endl;
        else cout << 0 << endl;
        return 0;
    }
    ll num[w-1],no[w];

    rep(i,w-1) num[i]=0;
    rep(i,w) no[i]=0;

    rep(i,(1<<(w-1))){
        bool kuji[w-1];
        rep(j,w-1){
            if(i&(1<<j)){
                kuji[j]=1;
            }else kuji[j]=0;
        }
        bool aa=0;
        rep(j,w-2) if(kuji[j]&&kuji[j+1]) aa=1;
        if(aa) continue;
        rep(j,w-1){
            if(kuji[j]) num[j]++;
            if(0<j&&!kuji[j]&&!kuji[j-1]) no[j]++;
        }
        if(!kuji[0]) no[0]++;
        if(!kuji[w-2]) no[w-1]++;
    }
    ll dp[h+1][w];
    memset(dp,0,sizeof(dp));
    dp[0][0]=1;
    rep(i,h+1){
        if(i==0) continue;
        rep(j,w){
            if(j>0) dp[i][j]+=(dp[i-1][j-1]*num[j-1])%MOD;
            dp[i][j]%=MOD;
            if(j+1<w) dp[i][j]+=(dp[i-1][j+1]*num[j])%MOD;
            dp[i][j]%=MOD;
            dp[i][j]+=(dp[i-1][j]*no[j])%MOD;
            dp[i][j]%=MOD;
        }
    }
    cout << dp[h][k] << endl;
}

/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

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

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

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

ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}

//-----------------------ここから-----------
ll h, w, k;
ll memo[110][10];

ll rec(ll i, ll j){
    if(i == 0 && j == 0) return 1;
    if(i == 0) return 0;
    if(memo[i][j] != -1) return memo[i][j];
    ll res = 0;
    //cout << i << " " << j << endl;
    for(ll bit = 0; bit < (1LL << (w - 1)); bit++){
        bool ok = true;
        for(ll ii = 0; ii < w - 2; ii++){
            if((bit & (1LL << ii)) && (bit & (1LL << (ii + 1)))){
                ok = false;
                break;
            }
        }
        if(ok){
            if(bit & (1LL << j) && j + 1 < w){
                res += rec(i - 1, j + 1);
            } else if(bit & (1 << (j - 1)) && j - 1 >= 0){
                res += rec(i - 1, j - 1);
            } else {
                res += rec(i - 1, j);
            }
            res %= MOD;
        }
    }
    return memo[i][j] = res;

}
int main(void){

    cin >> h >> w >> k;

    rep(i, 110) rep(j, 10) memo[i][j] = -1;
    cout << rec(h, k - 1) % MOD << endl;

}


#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 1e5 + 5;
int n, m, k;
int a[N];
ll ans;

int main() {
    cin >> n >> k;
    m = n;
    ans = LLONG_MAX;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        if (m == n && a[i] >= 0) {
            m = i;
        }
    }
    for (int i = 0; i <= min(k, m); ++i) {
        if (m + k - i - 1 >= n) continue;
        ll lv = 0;
        ll rv = 0;
        if (i)
            lv = -a[m - i];
        if (k - i)
            rv = a[m + k - i - 1];
        // cout << i << ' ' << lv << ' ' << rv << endl;
        ans = min(ans, min(lv, rv) * 2 + max(lv, rv));
    }
    cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  using P = pair<string, string>;
  vector<map<P, int>> lst(n + 1);
  rep(i, bit32(n)) {
    int x = __builtin_popcount(i);
    string a, b;
    rep(j, n) {
      ((bit32(j) & i) ? a : b) += s[j];
    }
    lst[x][P(a, b)] += 1;
  }
  i64 ans = 0;
  rep(i, bit32(n)) {
    int x = __builtin_popcount(i);
    string a, b;
    rep(j, n) {
      ((bit32(j) & i) ? a : b) += s[n + j];
    }
    reverse(all(a));
    reverse(all(b));
    ans += lst[x][P(a, b)];
  }
  cout << ans << endl;
}


#include <bits/stdc++.h>

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

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 1e5 + 5;
int n, m, x, y, t;

int main() {
    cin >> n >> m >> x >> y;
    for (int i = 0; i < n; ++i) {
        cin >> t;
        x = max(x, t);
    }
    for (int i = 0; i < m; ++i) {
        cin >> t;
        y = min(y, t);
    }
    if (x < y)
        cout << "No War" << endl;
    else
        cout << "War" << endl;
    return 0;
}

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

int main() {
	string s;cin>>s;
	auto pos = s.find("AC");
	if(pos!=string::npos){
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int n,q[40003];
long long ans,c[50];
int main(){
	cin>>n;
	char _a;
	for(int i=1,_n=n+1;i<_n;i++){
		cin>>_a;
		switch(_a){
			case 'R':
				q[i]=1;
				break;
			case 'G':
				q[i]=2;
				break;
			case 'B':
				q[i]=4;
				break;
		}
		c[q[i]]++;
	}
	ans=1ll*c[1]*c[2]*c[4];
	for(int i=1,_m=n-1;i<_m;i++){
		for(int j=i+1,_n=n+1;j<_n;j++){
			ans-=((q[i]|q[j]|q[j+j-i])==7);
		}
	}
	cout<<ans;
	return 0;
}

#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

const ll MOD = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

using namespace std;

int N, M;
vector<int> A, B;

long long solve()
{
    ll res = 1;
    int biggerX_a = 0, biggerX_b = 0; // A,B でxより大きい数値の個数

    for (int x = N * M; x >= 1; x--)
    {
        if (A[biggerX_a] > x)
            return 0;
        if (B[biggerX_b] > x)
            return 0;

        long long tmp = 1;
        if (A[biggerX_a] == x && B[biggerX_b] == x)
        {
            tmp = 1;
            ++biggerX_a, ++biggerX_b;
        }
        else if (A[biggerX_a] == x)
        {
            tmp = biggerX_b;
            ++biggerX_a;
        }
        else if (B[biggerX_b] == x)
        {
            tmp = biggerX_a;
            ++biggerX_b;
        }
        else
        {
            tmp = biggerX_a * biggerX_b - (N * M - x);
            if (tmp <= 0)
                return 0;
        }
        res = (res * tmp) % MOD;
    }
    return res;
}
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> N >> M;
    A.resize(N+1);
    B.resize(M+1);
    rep(i, N) cin >> A[i];
    rep(i, M) cin >> B[i];
    sort(ALL(A), greater<int>());
    sort(ALL(B), greater<int>());
    cout << solve() << endl;
}


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    int ok=0;
    for (int i=0;i+1<S.size();++i)
        if (S[i]=='A'&&S[i+1]=='C') ok=1;
    cout << (ok?"Yes":"No") << '\n';
}

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

int main(){
    string s;cin >>s;
    stack<char> st;
    st.push(s[0]);
    rep(i,s.size()-1){

        char ch = '.';
        if(st.size()){
            ch = st.top();
            //cout << ch << endl;
        }
        if(s[i+1]=='T'&&ch=='S'){
            st.pop();
        }else{
            st.push(s[i+1]);
        }
    }

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


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <functional>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int main() {
  vector<int> v1(10),v2(10);
  REP(i,10)
    cin >> v1[i];
  REP(i,10)
    cin >> v2[i];
  sort(ALL(v1), greater<int>());
  sort(ALL(v2), greater<int>());
  cout << v1[0]+v1[1]+v1[2] << " " << v2[0]+v2[1]+v2[2] << endl;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int X = A + B, Y = C + D;

  if (X > Y) cout << "Left" << endl;
  else if (X == Y) cout << "Balanced" << endl;
  else if (X < Y) cout << "Right" << endl;
}


#include <bits/stdc++.h>
using namespace std;
char s[100];
int main(){
    scanf("%s", s+1);
    if(strlen(s+1) == 3) reverse(s+1, s+1+strlen(s+1));
    printf("%s", s+1);
}

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

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

  if (s.size() == 2) {
    cout << s << endl;
    return 0;
  }

  reverse(s.begin(),s.end());
  cout << s << endl;

  return 0;
}


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

bool dfs(char board[8][8], bool v_used[], bool h_used[], bool dr_used[], bool dl_used[], int x, int y, int num) {
	if (num == 8) return true;
	for (int i = 0; i < 8; i++) {
		if (h_used[i]) continue;
		for (int j = 0; j < 8; j++) {
			if (board[i][j] != 'Q') {
				if (!v_used[j] && !h_used[i] && !dr_used[8 - j + i - 1] && !dl_used[i + j]) {
					v_used[j] = h_used[i] = dr_used[8 - j + i - 1] = dl_used[i + j] = true;
					board[i][j] = 'Q';
					bool ret = dfs(board, v_used, h_used, dr_used, dl_used, i, j, num + 1);
					if (ret) return true;
					v_used[j] = h_used[i] = dr_used[8 - j + i - 1] = dl_used[i + j] = false;
					board[i][j] = '.';
				}
			}
		}
	}
	return false;
}

int main() {
	int n;
	bool v_used[8], h_used[8], dr_used[16], dl_used[16];
	char board[8][8];

	// ?????????????????????
	for (int i = 0; i < 8; i++) {
		for (int j = 0; j < 8; j++) {
			board[i][j] = '.';
		}
		v_used[i] = h_used[i] = false;
	}

	for (int i = 0; i < 16; i++) {
		dr_used[i] = dl_used[i] = false;
	}

	std::cin >> n;

	for (int i = 0; i < n; i++) {
		int x, y;
		std::cin >> x >> y;
		board[x][y] = 'Q';

		v_used[y] = true;
		h_used[x] = true;
		dr_used[8 - y + x - 1] = true;
		dl_used[x + y] = true;
	}

	if (n == 8) {
		for (int k = 0; k < 8; k++) {
			for (int l = 0; l < 8; l++) {
				std::cout << board[k][l];
			}
			std::cout << std::endl;
		}
		return 0;
	}

	for (int i = 0; i < 8; i++) {
		if (h_used[i]) continue;
		for (int j = 0; j < 8; j++) {
			if (board[i][j] != 'Q') {
				if (!v_used[j] && !h_used[i] && !dr_used[8 - j + i - 1] && !dl_used[i + j]) {
					v_used[j] = h_used[i] = dr_used[8 - j + i - 1] = dl_used[i + j] = true;
					board[i][j] = 'Q';
					bool ret = dfs(board, v_used, h_used, dr_used, dl_used, i, j, n + 1);
					if (ret) {
						for (int k = 0; k < 8; k++) {
							for (int l = 0; l < 8; l++) {
								std::cout << board[k][l];
							}
							std::cout << std::endl;
						}
						return 0;
					}
					v_used[j] = h_used[i] = dr_used[8 - j + i - 1] = dl_used[i + j] = false;
					board[i][j] = '.';
				}
			}
		}
	}

}

#include <iostream>
#include <vector>
#include <queue>
#include <utility>

using namespace std;

int lr[4]={1, 0, -1, 0};
int ud[4]={0, 1, 0, -1};

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<int> > A(H, vector<int>(W));
    for(int h=0; h<H; h++) {
        for(int w=0; w<W; w++) {
            cin >> A[h][w];
        }
    }
    int dir=0;
    queue<pair<int, int> > que;
    que.push(make_pair(0, 0));
    vector<vector<bool> > seen(H, vector<bool>(W, false));
    vector<pair<pair<int, int>, pair<int, int> > > ans;
    while(!que.empty()) {
        pair<int, int> hw=que.front(); que.pop();
        int curh=hw.first, curw=hw.second;
        seen[curh][curw]=true;
        bool flag=false;
        if(A[curh][curw]%2) {
            flag=true;
        }
        int tmpd=dir;
        while(tmpd-dir<4) {
            if(curh+ud[tmpd%4]<0 || curh+ud[tmpd%4]>=H || curw+lr[tmpd%4]<0 || curw+lr[tmpd%4]>=W) {
                tmpd++;
                continue;
            }
            if(seen[curh+ud[tmpd%4]][curw+lr[tmpd%4]]) {
                tmpd++;
                continue;
            }
            if(flag) {
                A[curh+ud[tmpd%4]][curw+lr[tmpd%4]]++;
                ans.push_back(make_pair(make_pair(curh, curw), make_pair(curh+ud[tmpd%4], curw+lr[tmpd%4])));
            }
            que.push(make_pair(curh+ud[tmpd%4], curw+lr[tmpd%4]));
            dir = tmpd%4;
            break;
        }
    }
    cout << ans.size() << endl;
    for(int i=0; i<ans.size(); i++) {
        cout << ans[i].first.first+1 << " " << ans[i].first.second+1 << " " << ans[i].second.first+1 << " " << ans[i].second.second+1 << endl;
    }

    return 0;

}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <string.h>
using namespace std;
char str[1000000];
int main() {
  int ans, k, len, J, O, I;
  int a;
  //string str;

  while(scanf("%s", str) != EOF) {
    len = strlen(str);
    J=0, O=0, I=0;
    ans=0, k=0;
    //cout << len << endl;
    for(int i = 0 ; i < len ; i++) {
      if(str[i] != 'J') continue;

      if(str[i] == 'J') {
	if(str[i] != '#') a = i;
	while(str[a] == 'J') {
	  str[a] = '#';
	  a++;
	  J++;
	}
	if(str[a] == 'O') {
	  while(str[a] == 'O') {
	    a++;
	    O++;
	  }
	  if(str[a] == 'I') {
	    while(str[a] == 'I') {
	      a++;
	      I++;
	    }
	  }
	}
      }
      //printf("J = %d, O = %d, I = %d\n", J, O, I);
      if(O <= J && O <= I) k = min(J, min(O, I));
      //if(J == O && O == I /*|| J <= O && O >= I*/) k = min(J, min(O, I));
      //else J = 0; O = 0; I = 0;
      ans = max(k, ans);
      J = 0; O = 0; I = 0;

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

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

int main() {

  string s;
  int flag = -1, ans = 0;
  int J = 0, O = 0, I = 0;
  cin >> s;

  for(int i=0; i<s.size(); i++) {
    if( flag <= 0 && s[i] == 'J' ) {
      flag = 0;
      J++;
    }
    else if( flag == 0 && s[i] == 'O' ) {
      flag = 1; O++;
    }
    else if( flag == 1 && s[i] == 'O' ) {
      O++;
    }
    else if( flag == 1 && s[i] == 'I' ) {
      flag = 2;
      if( J >= O ) {
	I++;
	ans = max(1, ans);
      }
      else {
	flag = -1;
	J = O = I = 0;
      }
    }
    else if( flag == 2 && s[i] == 'I' ) {
      I++;
      if( I >= O ) {
	ans = max(ans, min(J, min(O, I)));
      }
    }
    else {
      if( s[i] == 'J' ) {
	flag = 0;
	J = 1; O = I = 0;
      }
      else {
	flag = -1;
	J = O = I = 0;
      }
    }
  }

  cout << ans << endl;
}


#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;

int n, m, in[1001], data[1002001];

main(){
  while(scanf("%d %d", &n, &m) && (n|m)){
    in[0] = 0;
    for(int i=1;i<=n;i++) scanf("%d", &in[i]);
    for(int i=0;i<=n;i++) for(int j=0;j<=n;j++) data[i*(n+1)+j] = in[i] + in[j];
    int size = (n+1)*(n+1), ans = 0;
    sort(data, data+size);
    for(int i=0;i<size;i++){
      int l = 0, r = size-1;
      while(r-l>1){
        int med = (l+r) / 2;
        if(data[i] + data[med] <= m) l = med;
        else r = med;
      }
      if(data[i] + data[l] <= m) ans = max(ans, data[i] + data[l]);
    }
    printf("%d\n", ans);
  }
}

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

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

	}

}


#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <boost/tokenizer.hpp>
#include <boost/lexical_cast.hpp>
#include <vector>
#include <list>

using namespace std;
using namespace boost;

int main(int argc, char* argv[])
{
	using sprtr = char_separator<char>;
	using tknzr = tokenizer<sprtr>;
	sprtr sep(" ", "", keep_empty_tokens);

	int f, mf, mo;

	string line;
	while(1) {

		int n, m;
		{
			getline(cin, line);
			tknzr tkns(line, sep);
			auto it = tkns.begin();
			n = lexical_cast<int>(*it++);
			m = lexical_cast<int>(*it);
		}

		if( n == 0 && m == 0 ) {
			break;
		}

		list<int> ps;
		{
			getline(cin, line);
			tknzr tkns(line, sep);
			for( auto p : tkns ) {
				//cout << p << endl;
				ps.push_back(lexical_cast<int>(p));
			}
		}

		ps.sort(greater<int>());

		int div = n / m;
		int mod = n % m;

		int sum = 0;
		auto it = ps.begin();
		for( int i = 0; i < div; i++ ) {
			for( int j = 0; j < m; j++ ) {
				auto p = *it++;
				if( j == m-1 ) continue;
				sum += p;
			}
		}

		if( mod ) {
			for( int i = 0; i < mod; i++ ) {
				auto p = *it++;
				sum += p;
			}
		}

		cout << sum << endl;

		ps.clear();

	}

    return 0;
}

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

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

int n, m;
int p[1010];

int main()
{
	while (cin >> n >> m, n){
		rep(i, n) cin >> p[i];
		sort(p, p + n, greater<int>());
		int res = 0;
		rep(i, n) res += p[i];
		for (int i = m - 1; i < n; i += m){
			res -= p[i];
		}
		cout << res << endl;
	}
}


#include <bits/stdc++.h>

#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

using namespace std;

#define F first
#define S second
#define EB emplace_back
#define PB push_back
#define ld long double
#define lb lower_bound
#define ub upper_bound
#define ar array
#define sz(x) (int)x.size()
#define bit(x) __builtin_popcount(x)
#define all(x) (x).begin(), (x).end()
#define FOR(c,l,r) for(int c=(l);c<=(r);c++)

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

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

using ll = long long;
//#define int ll

const int N = 2e6 + 7;
const int MOD = 1e9 + 7;
const int inf = 2e9 + 7;
const int  dx[]  = {-1,   0,   1,   0,  1, -1, -1,  1};
const int  dy[]  = { 0,   1,   0,  -1,  1, -1,  1, -1};
const char dt[] = {'U', 'R', 'D', 'L'};

map <int, int> mp;

int ok(int n) {
	while (n) {
		if (mp[n % 10]) return false;
		n /= 10;
	} return true;
}
void solve() {
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < k; i ++) {
		int x;
		cin >> x;
		mp[x] = 1;
 	}
	while (!ok(n)) {
		n ++;
	}
	cout << n;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int tt = 1;
   	//cin >> tt;
    while (tt --){
        solve();
        cout << '\n';
    }
}

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

void solve(void)
{
    ll n;
    cin >> n;
    n *= 2;
    vector<int> v(n);
    rep(i, n) cin >> v[i];
    sort(v.begin(), v.end());
    int ans = 0;
    for (int i = 0; i < n; i += 2)
    {
        ans += min(v[i], v[i + 1]);
    }
    cout << ans << endl;
}
int main(void)
{
    solve();
}


// 去吧！皮卡丘! 把AC带回来！
//      へ　　　　　／|
// 　　/＼7　　　 ∠＿/
// 　 /　│　　 ／　／								AC		AC		AC		AC
//    │　Z ＿,＜　／　　 /`ヽ						AC		AC		AC		AC
//    │　　　　　ヽ　　 /　　〉					AC		AC		AC		AC
// 　Y　　　　　`　 /　　/  /						AC		AC		AC		AC
// 　亻●　.　●　　〈　/　/						AC		AC		AC		AC
// 　()　 へ　　　　|　＼〈							AC		AC		AC		AC
// 　　>- ._　 ィ　 │ ／／							AC		AC		AC		AC
// 　 / へ　　 /　/＜| ＼＼							AC		AC		AC		AC
// 　 ヽ_/　　(_／　 │／／							AC		AC		AC		AC
// 　　 7　　　　　　　|／							AC		AC		AC		AC
// 　　 ＞―r￣￣`-―＿/							AC		AC		AC		AC
//**************************************Accepted*****************************************//

#include<bits/stdc++.h>

#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define Unique(x) x.erase(unique(all(x)),x.end());

#define CIN_FILE "input.txt"
#define COUT_FILE "output.txt"

#define Pig (OO)

using namespace std;

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

const int Days[]={-1,31,28,31,30,31,30,31,31,30,31,30,31};

inline int read()
{
	#define gc getchar
	int ans=0;
	bool f=1;
	char ch=gc();

	while(!isdigit(ch))f^=ch=='-',ch=gc();

	while(isdigit(ch))ans=((ans<<2)+ans<<1)+(ch^48),ch=gc();

	return f?ans:-ans;

	#undef gc
}

typedef long long ll;

int n,m;
vector<int> v[1010];
int vis[1010];
vector<int> path;
int indeg[1010],outdeg[1010];
bool edges[1010][1010];

bool OK()
{
	memset(indeg,0,sizeof(indeg));
	memset(outdeg,0,sizeof(outdeg));

	for(int i=0;i<path.size();i++)for(int j=0;j<path.size();j++)
	{
		if(indeg[path[i]]>1||outdeg[path[j]]>1)return 0;

		if(edges[path[i]][path[j]])indeg[path[i]]++,outdeg[path[j]]++;
	}

	for(int i=0;i<path.size();i++)if(indeg[path[i]]!=1||outdeg[path[i]]!=1)return 0;

	return 1;
}

void pprint()
{
	if(!OK())return;

	cout<<path.size()<<endl;for(int i=0;i<path.size();i++)cout<<path[i]<<endl;

	exit(0);
}

void DFS(int x)
{
	path.pb(x);
	vis[x]=2;

	for(int i=0;i<v[x].size();i++)
	{
		if(vis[v[x][i]]==0)DFS(v[x][i]);
		if(vis[v[x][i]]==2)pprint();
	}

	path.pop_back();
	vis[x]=1;
}

int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);

	cin>>n>>m;

	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;

		v[x].pb(y);

		edges[x][y]=1;
	}

	for(int i=1;i<=n;i++)
	{
		memset(vis,0,sizeof(vis));
		path.clear();

		if(!vis[i])DFS(i);
	}

	cout<<-1;

	//printf("Time used = %.12f",(double)(clock())/CLOCKS_PER_SEC);
	return 0;
}

/*  GOD BLESS  */

#include <bits/stdc++.h>

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

std::vector<std::vector<int>> StronglyConnectedComponents(
    const std::vector<std::vector<int>>& graph) {
  int n = graph.size();
  std::vector<int> nodes;
  std::vector<bool> visited(n);
  std::function<void(int)> dfs = [&](int u) {
    visited[u] = true;
    for (int v : graph[u]) {
      if (!visited[v]) {
        dfs(v);
      }
    }
    nodes.push_back(u);
  };
  for (int u = 0; u < n; ++u) {
    if (!visited[u]) dfs(u);
  }
  std::vector<std::vector<int>> rgraph(n);
  for (int u = 0; u < n; ++u) {
    for (int v : graph[u]) {
      rgraph[v].push_back(u);
    }
  }
  std::vector<bool> rvisited(n);
  std::vector<std::vector<int>> sccs;
  std::function<void(std::vector<int>&, int)> rdfs = [&](std::vector<int>& scc,
                                                         int u) {
    rvisited[u] = true;
    scc.push_back(u);
    for (int v : rgraph[u]) {
      if (!rvisited[v]) {
        rdfs(scc, v);
      }
    }
  };
  for (int i = n - 1; i >= 0; --i) {
    int u = nodes[i];
    if (!rvisited[u]) {
      std::vector<int> scc;
      rdfs(scc, u);
      sccs.push_back(scc);
    }
  }
  return sccs;
}

int main() {
  in(int, n, m);
  vector<vector<int>> graph(n);
  rep(i, m) {
    in(int, a, b);
    graph[a - 1].push_back(b - 1);
  }
  vector<vector<int>> sccs = StronglyConnectedComponents(graph);
  for (const vector<int>& scc : sccs) {
    if (scc.size() == 1) continue;
    set<int> scc_nodes(all(scc));
    int node = scc[0];
    map<int, int> next;
    map<int, int> prev;
    for (int n : scc_nodes) dbg(n);
    while (true) {
      for (int child : graph[node]) {
        if (scc_nodes.count(child) == 0) continue;
        next[node] = child;
        prev[child] = node;
        if (next.count(child) != 0) goto out;
        node = child;
        break;
      }
    }
 out:
    node = scc[0];
    if (prev.count(node) == 0) {
      while (true) {
        int child = next[node];
        next.erase(node);
        if (prev[child] != node) break;
        prev.erase(child);
        node = child;
      }
    }
    rep(u, n) for (int v : graph[u]) {
      if (next.count(u) > 0 && next.count(v) > 0) {
        int c = next[u];
        while (c != v) {
          int nc = next[c];
          next.erase(c);
          prev.erase(c);
          c = nc;
        }
        next[u] = v;
        prev[v] = u;
      }
    }
    vector<int> v;
    int u = next.begin()->first;
    do {
      v.push_back(u);
      u = next[u];
    } while (u != next.begin()->first);
    out(v.size());
    for (int u : v) out(u + 1);
    return 0;
  }
  out(-1);
}


#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define endl '\n'
#define snd second
#define fst first
#define fastio cin.tie(NULL),cout.sync_with_stdio(true)

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

const ll mod = 998244353;
//const ll mod = 1e9 + 7;
const ll INF = (1LL<<50);
const double EPSILON = 0.001;
const int N = 200005;
ll mul(ll a, ll b){
	return a*b%mod;
}
ll add(ll a, ll b){
	a += b;
	if(a >= mod)
		a-=mod;
	return a;
}
ll expo(ll a, ll b){
	ll r = 1;
	for(;b; b >>= 1, a = mul(a,a))
		if(b&1)
			r = mul(r, a);
	return r;
}
ll fact[N], ifact[N];
void init(){
	fact[0] = 1;
	for(ll i = 1; i < N; i++)
		fact[i] = mul(i, fact[i-1]);
	ifact[N-1] = expo(fact[N-1], mod-2);
	for(ll i = N-2; i >= 0; i--)
		ifact[i] = mul(ifact[i+1], i+1);
}
ll ncr(ll n, ll r){
	if(n < r)return 0;
	return mul(fact[n], mul(ifact[r], ifact[n-r]));
}
/*
	from n total blocks, (n-1) is the total of adj pairs.
	assuming we want to make only k pairs to have the same color
	doesn't matter how those pairs are distributed , the ways to
	color them always follow that formula : C(n-1,k) * m * 1^(k) * (m-1)^(n-1-k)
	so the final answer is:
			i:(0,k) Σ C(n-1,i) * m * 1^i * (m-1) ^(n-1-i)
*/
int main(){
	fastio;
	init();
	int n,m,k,ans = 0;
	cin >> n >> m >> k;
	for(int i = 0; i <= k; i++)
		ans = add(ans, mul(ncr(n-1, i), mul(m, expo(m-1, n-1-i))));
	cout << ans << '\n';
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5+5;

const int mod = 998244353;

int n;
int m;
int k;

long long inv[N];
long long fac[N];
long long finv[N];

void cominit(){
    fac[0] = fac[1] =1;
    finv[0] = finv[1] =1;
    inv[1] = 1;
    for(int i = 2; i < N; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i]= mod - inv[mod % i] * (mod / i) % mod;
        finv[i]= finv[i - 1] * inv[i] % mod;
    }
}

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

int fastP(int b, int e){
    if(!e)
        return 1;
    if(e & 1)
        return b * 1ll * fastP(b * 1ll * b % mod, e >> 1) % mod;
    return fastP(b * 1ll * b % mod, e >> 1) % mod;
}

void mul(long long & a , long long b){
    a *= b;
    a %= mod;
}

int main(){
    scanf("%d%d%d" , &n , &m , &k);
    cominit();
    long long ways = 0;
    for(int i = 0; i <= k; i++){
        long long sofar = 1;
        mul(sofar , m);
        mul(sofar , fastP(m - 1 , n - 1 - i));
        mul(sofar , nCr(n - 1 , i));
        ways += sofar;
        ways %= mod;
    }
    printf("%lld\n" , ways);
}


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

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

  int a[n];
  int all = 0;
  for(int i = 1; i <= n; i++){
    a[i] = l + i - 1;
    all += a[i];
  }

  int minu = 0,maxmin = 2000000;
  for(int i = 1; i <= n; i++){
    for(int j = 1; j <= n; j++){
      if(j != i){
        minu += a[j];
      }//if
    }//for
    if(abs(minu - all) < abs(maxmin - all)){
      maxmin = minu;
    }
    minu = 0;
  }

  cout << maxmin << endl;

}

/*16D8103008D 西村　悠輝　ALDS10C*/

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

string X, Y;
int v[1001][1001];

int  dp(string X, string Y) {
	int n = X.size();
	int m = Y.size();

	for (int i = 0; i <= n; i++) {
		v[i][0] = i;											///０のテーブル
		for (int j = 0; j <= m; j++) {
			v[0][j] = j;
		}
	}

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (X[i-1] == Y[j-1]) {

				v[i][j]= v[i-1][j-1];
			}
			else {
				int y = min(v[i][j - 1] + 1, v[i - 1][j] + 1);
				if (y > v[i - 1][j - 1] + 1) {
					v[i][j] = v[i - 1][j - 1] + 1;
				}else{
					v[i][j] = y;
				}
			}
		}
	}
	return v[n][m];
}

int main(void)
{

	cin >> X >> Y;
	int ans = dp(X, Y);
	cout << ans << endl;

}
/*
acac
acm
2
*/


#include <bits/stdc++.h>

///    ____ ____ ____ ____ ____
///   ||a |||t |||o |||d |||o ||
///   ||__|||__|||__|||__|||__||
///   |/__\|/__\|/__\|/__\|/__\|
///

using namespace std;

const int N_MAX = 302;
const int M_MAX = 302;

int n, m;

int a[N_MAX][M_MAX];

bool del[N_MAX];

int pos[N_MAX];

int cnt[M_MAX];

queue <int> q;

bool f (int mx)
{
    for(int i = 1; i <= m; i++)
    {
        del[i] = false;
        cnt[i] = 0;
    }
    while(!q.empty())
        q.pop();
    for(int i = 1; i <= n; i++)
    {
        pos[i] = 1;
        if(++cnt[a[i][1]] == mx + 1)
            q.push(a[i][1]);
    }
    while(!q.empty())
    {
        int f = q.front();
        q.pop();
        del[f] = true;
        for(int i = 1; i <= n; i++)
            if(del[a[i][pos[i]]] == true)
            {
                while(pos[i] <= m && del[a[i][pos[i]]] == true)
                    pos[i]++;
                if(pos[i] == m + 1)
                    return false;
                if(++cnt[a[i][pos[i]]] == mx + 1)
                    q.push(a[i][pos[i]]);
            }
    }
    return true;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
            cin >> a[i][j];
    int l = 1, r = n;
    while(l < r)
    {
        int mid = ((l + r) >> 1);
        if(f(mid) == true)
            r = mid;
        else
            l = mid + 1;
    }
    cout << l << "\n";
    return 0;
}

#include <cstdio>           // printf(), scanf()
#include <vector>
#include <algorithm>        // sort()

using namespace std;
static const int MAX_E = 100000;

class disjointSet
{
public:
	vector<int> rank;
	vector<int> par;

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

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

		return par[x];
	}

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

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

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

struct edge
{
	int from, to;
	int cost;
};

edge es[MAX_E];
int V, E;

bool
cmp_func(const edge &e1, const edge &e2)
{
	return e1.cost < e2.cost;
}

int
kruskal()
{
	sort(es, es + E, cmp_func);
	disjointSet dset = disjointSet(V);
	int res = 0;

	for (int i = 0; i < E; ++i)
	{
		edge e = es[i];
		if (!dset.same(e.from, e.to))
		{
			dset.unite(e.from, e.to);
			res += e.cost;
		}
	}

	return res;
}

int
main(int argc, char** argv)
{
	edge e;
	int s, t, w;
	int i;

	scanf("%d %d", &V, &E);
	for (i = 0; i < E; ++i)
	{
		scanf("%d %d %d", &s, &t, &w);
		e.from = s;
		e.to = t;
		e.cost = w;
		es[i] = e;
	}

	printf("%d\n", kruskal());
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define rep(i, n) repl(i, 0, n)
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18 + 10;
const int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	int h, n, k;
	cin >> h >> n >> k;
	vector<vector<ll>> table(n, vector<ll>(n));
	rep(bit, 1 << (n - 1)) {
		vector<int> a(n - 1);
		int p = bit;
		rep(i, n - 1) {
			if (p & 1) a[i] = 1;
			p >>= 1;
		}
		bool flag = 0;
		rep(i, n - 2) {
			if (a[i] + a[i + 1] == 2) flag = 1;
		}
		if (flag) continue;
		vector<int> T(n);
		rep(i, n) T[i] = i;
		rep(i, n - 1) {
			if (a[i] == 1) swap(T[i], T[i + 1]);
		}
		rep(i, n) table[i][T[i]]++;
	}
	vector<vector<ll>> dp(h + 1, vector<ll>(n));
	dp[0][0] = 1;
	rep(i, h) rep(j, n) rep(k, n) dp[i + 1][k] = (dp[i + 1][k] + dp[i][j] * table[j][k] % MOD) % MOD;
	cout << dp[h][k - 1] << endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 105
#define INF 1000000000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 100005;
const int MOD = 1000000007;
int dpo[10];
int dpx[10];
ll dp[105][10];
int w;
int d(int x){
    if(x<=0||x>w)return 1;
    else return (dpo[x]+dpx[x]);
}
int main(){
    int h,k;
    cin>>h>>w>>k;
    dpo[1]=1;dpx[1]=0;
    for(int i=1;i<w;i++){
        dpo[i+1]=dpo[i]+dpx[i];
        dpx[i+1]=dpo[i];
    }
    dp[0][1]=1;
    REP(i,h){
        for(int j=1;j<=w;j++){
            dp[i+1][j]+=(ll)dp[i][j]*d(j-1)*d(w-j);
            //cout<<dp[i][j]<<" "<<d(j-1)<<" "<<d(w-j);
            dp[i+1][j]%=MOD;
            dp[i+1][j]+=dp[i][j+1]*d(w-j-1)*d(j-1);
            dp[i+1][j]+=dp[i][j-1]*d(w-j)*d(j-2);
            dp[i+1][j]%=MOD;
            //OUT(dp[i+1][j]);
        }
    }
    OUT(dp[h][k]);
    return 0;
}