#include <iostream>
#include <queue>
#define INF 1000000000
#define NV 100000
using namespace std;
class edge
{
  public:
  int t;
  int d;
  edge *nextedge;
  edge(int,int);
};

edge::edge(int tt,int dd)
{
  t=tt;
  d=dd;
  nextedge=NULL;
}

class vertice
{
  public:
  edge *firstedge;
  void create_edge(int,int);
};

void vertice::create_edge(int t,int d)
{
  edge *newedge=new edge(t,d);
  if(firstedge==NULL)
    firstedge=newedge;
  else
  {
    edge *tmp=firstedge;
    while(tmp->nextedge!=NULL)
    {
      tmp=tmp->nextedge;
    }
    tmp->nextedge=newedge;
  }
}

class source
{
  public:
  int n;
  int dis;
  friend bool operator<(source,source);
};

bool operator<(source a, source b)
{
  return a.dis>b.dis;
}

int main()
{
  int v,e,r;
  cin>>v>>e>>r;
  source weight[v];
  vertice vertices[v];
  for(int i=0;i<v;i++)
  {
    vertices[i].firstedge=NULL;
    weight[i].n=i;
    weight[i].dis=INF;
  }
  for(int i=0;i<e;i++)
  {
    int s,t,d;
    cin>>s>>t>>d;
    vertices[s].create_edge(t,d);
  }
  weight[r].dis=0;
  int current_vertex=r;
  priority_queue<source> queue;
  queue.push(weight[r]);
  while(queue.size()!=0)
  {
    source del=queue.top();
    queue.pop();
    current_vertex=del.n;
    edge *neighbor=vertices[current_vertex].firstedge;
    while(neighbor!=NULL)
    {
      int vn=neighbor->t;
      if(weight[vn].dis>weight[current_vertex].dis+neighbor->d)
      {
        weight[vn].dis=weight[current_vertex].dis+neighbor->d;
        queue.push(weight[vn]);
      }
      neighbor=neighbor->nextedge;
    }
  }
  for(int i=0;i<v;i++)
    if(weight[i].dis>=INF)
      cout<<"INF"<<endl;
    else
      cout<<weight[i].dis<<endl;
}

#include <vector>
#include <algorithm>
#include <iostream>
#include <queue>
#include <set>
#define INF 100000000
#define ll long long
using namespace std;

class Bit{
private:
  ll *par, *rk, size;
public:
  Bit(ll size){
    par = new ll[size];
    rk = new ll[size];
    for(ll i = 0; i < size; i++){
      par[i] = i;
      rk[i] = 0;
    }
  }
  ll find(ll x){
    if(x == par[x])
      return x;
    else
      return par[x] = find(par[x]);
  }
  void merge(ll x,ll y){
    x = find(x);
    y = find(y);
    if(rk[x] > rk[y]){
      par[y] = x;
    }else if(rk[x] < rk[y]){
      par[x] = y;
    }else{
      par[y] = x;
      rk[x]++;
    }
  }
  bool same(ll x, ll y){
    return find(x) == find(y);
  }
};
int main(){
  ll V, E;
  cin >> V >> E;
  Bit bit(V);
  priority_queue< pair<ll, pair<ll,ll> >, vector< pair<ll, pair<ll,ll> > >, greater< pair<ll, pair<ll,ll> > > > pq;
  for(ll i = 0; i < E; i++){
    ll s,t,w;
    cin >> s >> t >> w;
    pq.push(make_pair(w, make_pair(s,t)));
  }
  ll cost = 0;
  for(ll i = 0; i < V - 1; i++){
    while(1){
      if(bit.same(pq.top().second.first, pq.top().second.second)){
	pq.pop();
      }else{
	break;
      }
    }
    bit.merge(pq.top().second.first, pq.top().second.second);
    cost += pq.top().first;
  }
  cout << cost << endl;
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main() {
    int a, b;
    cin >> a >> b;
    if (a > b) {
        cout << 2*a-1 << "\n";
    }
    else if (b > a) {
        cout << 2*b-1 << "\n";
    }
    else {
        cout << a + b << "\n";
    }
    return 0;
}

#include<iostream>
using namespace std;
int main()
{
  int a,b,ans=0;
  cin>>a>>b;
  for(int i=0;i<2;i++)
  {
    if(a>=b)
    {
      ans+=a;
      a--;
    }
    else if(b>a)
    {
      ans+=b;
      b--;
    }
  }
  cout<<ans;
}


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

typedef long long ll;

int main() {
    ll R[400009];
    string s;
    cin >> s;
    ll n = s.size();
    map<char, int>mp;
    for (int i = 0; i < n; i++) {
        mp[s[i]]++;
    }
    ll ans = n*(n-1)/2;
    for (auto& p : mp) {
        ll v = p.second;
        ans -= v*(v-1)/2;
    }
    cout << ans + 1 << endl;
}

#include<bits/stdc++.h>
#define mo 1000000007
#define pi 3.1415926535898
using namespace std;
long long read(){
    long long xx=0,flagg=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')
        ch=getchar();
    if(ch=='-'){
        flagg=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        xx=xx*10+ch-'0';
        ch=getchar();
    }
    return xx*flagg;
}
void pus(long long xx,long long flagg){
    if(xx<0){
        putchar('-');
        xx=-xx;
    }
    if(xx>=10)
        pus(xx/10,0);
    putchar(xx%10+'0');
    if(flagg==1)
        putchar(' ');
    if(flagg==2)
        putchar('\n');
    return;
}
long long ksm(long long u,long long v){
	long long o=1;
	while(v){
		if(v&1)
			o=o*u%mo;
		u=u*u%mo;
		v>>=1;
	}
	return o;
}
int n,k,i,x,ans,f[100005];
int top,nex[200005],to[200005],fir[100005];
void lj(int u,int v){
	top++;
	nex[top]=fir[u];
	fir[u]=top;
	to[top]=v;
}
void ss(int u,int v){
	for(int top1=fir[v];top1;top1=nex[top1]){
		ss(v,to[top1]);
		f[v]=max(f[to[top1]],f[v]);
	}
	if(v==1)
		return;
	f[v]++;
	if(f[v]==k&&u!=1){
		ans++;
		f[v]=0;
	}
}
int main(){
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
   	n=read();k=read();
   	x=read();
   	if(x!=1)
   		ans++;
   	for(i=2;i<=n;i++){
   		x=read();
   		lj(x,i);
   	}
   	ss(1,1);
   	pus(ans,2);
    return 0;
}


/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t N, M;
  cin >> N >> M;
  for (int64_t g = M / N; g >= 1; --g) {
    if (M % g == 0 && M / g >= N) {
      cout << g << endl;
      return 0;
    }
  }
  cout << 1 << endl;
  return 0;
}

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

vector < int > v;

bool check(int n, int m, int mid){

    int x=(m-mid);
    long long int y=(n-1)*1LL*mid;
    return (x>=y && x%mid==0);
    ///return (m/mid>=n && m%mid==0);
}

int cal(int n, int m){
    int ans=0;
    for(int i=1; i*i<=m; i++){
        if(m%i==0){
             if(check(n,m,i))ans=max(ans,i);
             if(check(n,m,m/i))ans=max(ans,m/i);
        }
    }
    return ans;
}

int main(){

    int n,m;
    cin>>n>>m;
    int ans=cal(n,m);
    cout<<ans<<endl;
    return 0;
}


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

int main() {
  int a;
  cin >> a;
  if(a < 1200) cout << "ABC\n";
  else if(a < 2800) cout << "ARC\n";
  else cout << "AGC\n";
}

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;
template<typename T> bool chmax(T &a, T b) {if(a <= b){a = b; return true;}return false;}
template<typename T> bool chmin(T &a, T b) {if(a >= b){a = b; return true;}return false;}

#define ABC 001
#define ARC 010
#define AGC 100

int main(void){
    int r;
    cin >> r;
    int frag = AGC;
    if(r < 1200){
        frag |= ABC;
        frag |= ARC;
    }else if( r < 2800){
        frag |= ARC;
    }
    if(frag & ABC)cout << "ABC" << endl;
    else if(frag & ARC)cout << "ARC" << endl;
    else cout << "AGC" << endl;
}


#include <cstdlib>
#include <string>
#include <iostream>
#include <sstream>

using namespace std;

int main()
{
    string str[2];

    for (int i = 0; i < 2; i++)
    {
        getline(cin, str[i]);
//        cout << "Input: " << str[i] << endl;
    }
    str[1] += ' ';

    int num = atoi(str[0].c_str());
//    cout << "Input Number: " << num << endl;

    long* a = new long[num];

    stringstream ss;
//    ss = stringstream(str[1]);
    ss << str[1];

    string buff;
    int n = 0;
    while (getline(ss, buff, ' '))
    {
        if (n >= num) break;

        a[n] = atoi(buff.c_str());
//        cout << "Input Number: " << a[n] << endl;

        n++;
    }

    for (int x = 0; x < num - 1; x++)
    {
        for (int y = 0; y < num - 1 - x; y++)
        {
            if (a[y] > a[y+1])
            {
                swap(a[y], a[y+1]);
            }
        }

//        for (int i = 0; i < num; i++)
//        {
//            cout << "Step " << x << ": " << a[i] << endl;
//        }

    }

    long min = a[0];
    long max = a[num - 1];
    long long sum = 0;
    for (int i = 0; i < num; i++)
    {
        sum += a[i];
//        cout << "Sorted Number: " << a[i] << endl;
    }

    delete [] a;

    cout << min << " " << max << " " << sum << endl;

    return 0;
}

#include<cstdio>
#include<algorithm>
#define Rint register int
using namespace std;
typedef long long LL;
const int N = 200003;
int n;
LL ans, d, a[N], f[N], g[N];
int main(){
	scanf("%d%lld", &n, &d);
	for(Rint i = 1;i <= n;i ++){
		scanf("%lld", a + i);
		ans += a[i];
	}
	f[1] = a[1];
	for(Rint i = 2;i <= n;i ++) f[i] = min(f[i - 1] + d, a[i]);
	g[n] = a[n];
	for(Rint i = n - 1;i;i --) g[i] = min(g[i + 1] + d, a[i]);
	for(Rint i = 2;i < n;i ++) ans += min(f[i], g[i]);
	printf("%lld\n", ans + (n - 1) * d);
}


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

double distance(double, double, double, double);

int main(){
  double x1 ,y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  cout << fixed << setprecision(12);
  cout << distance(x1, y1, x2, y2) << endl;
}

double distance(double x1, double y1, double x2, double y2){
  double sumsq;
  sumsq = (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
  return pow(sumsq, 0.5);
}

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

int main() {
  int A, B, C;
  cin >> A >> B;
  C=max((A+B),(A-B));
  cout << max(C,(A*B)) << endl;
}


#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 9000000000000000000 //9e18:極めて大きい値
#define MOD 998244353
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
#define LOGMAXR 18 // floor(log2(10^5)) + 1: 配列の最大のrangeのlog
//略記
//#define PB push_back //vectorヘの挿入
//#define MP make_pair //pairのコンストラクタ
//#define F first //pairの一つ目の要素
//#define S second //pairの二つ目の要素

ll modpow(ll n, ll p){
  ll ret = 1;
  while(p){
    if(p & 1){
      ret *= n;
      ret %= MOD;
    }
    p >>= 1;
    n = n * n;
    n %= MOD;
  }
  return ret;
}

map<ll, ll> modinv_memo;
ll modinv(ll n) {
  if(modinv_memo.count(n)) return modinv_memo[n];
  // ll b = MOD, u = 1, v = 0;
  // while (b) {
  //   ll t = n / b;
  //   n -= t * b; swap(n, b);
  //   u -= t * v; swap(u, v);
  // }
  // u %= MOD;
  // if (u < 0) u += MOD;
  //modinv_memo[n] = u;
  ll ret = modpow(n, MOD-2);
  modinv_memo[n] = ret;
  return ret;
}

int main(){
  ll N, M, K;
  cin >> N >> M >> K;
  if(M == 1){
    if(K == N - 1){
      cout << 1 << endl;
    }else{
      cout << 0 << endl;
    }
    return 0;
  }
  ll ret = 0;
  ll it = (M * modpow(M - 1, N - 1)) % MOD;
  REP(k, K + 1){
    ret += it;
    ret %= MOD;
    it *= modinv(k + 1);
    it %= MOD;
    it *= (N - 1 - k);
    it %= MOD;
    it *= modinv(M - 1);
    it %= MOD;
  }
  cout << ret << endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll P = 998244353;
ll f(ll b, ll n) {if (n <= 0) return 1; auto p = f(b, n / 2); return p * p % P * (n % 2 ? b : 1) % P;}
ll ms[200001];
int main()
  {int N, M, K, ans = 0; cin >> N >> M >> K;
  ms[0] = 1; for (int r = 1; r <= K; ++r) ms[r] = ms[r - 1] * (N - 1 - r + 1) % P * f(r, P - 2) % P;
  for (int k = 0; k <= K; ++k) ans = (ans + ms[k] * M % P * f(M - 1, N - k - 1) % P) % P;
  cout << ans << endl;}


#include <iostream>

using namespace std;

int main()
{
    string S;
    cin>>S;
    char a=S[0]=='R';
     char b=S[1]=='R';
      char c=S[2]=='R';

     if(a&b&c)
     {
         cout<<"3";
     }
     else if(a&b||b&c)
     {
         cout<<"2";
     }
     else if(a|b|c)
     {
         cout<<"1";

     }
     else
     {

    cout<<"0";
     }
    return 0;
    }

#include <bits/stdc++.h>

using namespace std;

int n;
char x[5];

int main() {
	scanf("%s", x);
	int ans = 0, cur = 0;
	for (int i = 0; x[i]; i++)
		if (x[i] == 'R')
			ans = max(ans, ++cur);
		else
			cur = 0;
	printf("%d\n", ans);
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod=1e9+7;
ll n,m,k;
ll poww(ll x,ll k)
{
	ll base=x,ans=1;
	while(k)
	{
		if(k&1)ans=ans*base%mod;
		base=base*base%mod;
		k>>=1;
	}
	return ans;
}
ll nok(ll x)
{
	ll ans=1;
	for(int i=1;i<=x;i++)ans=ans*i%mod;
	return ans;
}
int main()
{
	ll ans=0,dlt;
	scanf("%lld %lld %lld",&n,&m,&k);
	dlt=nok(n*m-2)*poww(nok(k-2),mod-2)%mod*poww(nok(n*m-k),mod-2)%mod;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			ans=(ans+(1+n-i)*(n-i)/2*m%mod*dlt%mod)%mod;
			ans=(ans+(1+m-j)*(m-j)/2*n%mod*dlt%mod)%mod;
		}
	}
	printf("%lld\n",ans);
	return 0;
}

#include "bits/stdc++.h"

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  while(res<0)res=res + mod;
  return res;
}

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

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

struct UnionFind{
  ll N;
  llvec p;
  llvec cnt;
  UnionFind(ll n){
    N = n;
    p=llvec(N);
    cnt=llvec(N, 0);
    rep(i, N){
      p[i] = i;
      cnt[i] = 1;
    }
  }

  void con(ll a, ll b){
    P at = root(a);
    P bt = root(b);
    if(at.second!=bt.second){
      if(at.first>bt.first){
        swap(at, bt);
        swap(a, b);
      }
      p[at.second] = bt.second;
      cnt[bt.second]+=cnt[at.second];
      p[a]=bt.second;
    }
  }

  P root(ll a){
    ll atmp = a;
    ll c=0;
    while(atmp!=p[atmp]){
      atmp = p[atmp];
      c++;
    }
    p[a] = atmp;
    return {c, atmp};
  }

  bool is_con(ll a, ll b){
    P at=root(a);
    P bt=root(b);
    return at.second == bt.second;
  }

};

struct dijkstra{
  ll N;
  llvec d;
  vector<vector<edge>> e;
  dijkstra(ll n){
    N = n;
    //d = llvec(N, 1e18);
    e = vector<vector<edge>>(N);
  }

  void add_edge(ll from, ll to, ll cost){
    e[from].push_back({to, cost});
  }

  void run(ll start){
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, start});
    d = llvec(N, 1e18);
    d[start]=0;
    while(!que.empty()){
      P q = que.top();que.pop();
      ll dc = q.first;
      ll x = q.second;
      if(dc>d[x]){
        continue;
      }else{
        for(auto ip: e[x]){
          if(d[ip.x]<=d[x]+ip.c){
            continue;
          }else{
            d[ip.x]= d[x]+ip.c;
            que.push({d[ip.x], ip.x});
          }
        }
      }
    }
  }
};

ll fact[500000];
ll ifact[500000];

void gen(){
  fact[0]=ifact[0]=1;
  rep(i, 200100){
    fact[i+1]=mod(fact[i]*(i+1), MOD);
    ifact[i+1]=modinv(fact[i+1], MOD);
  }
}

ll comb(ll n, ll k){
  return mod(mod(fact[n]*ifact[n-k], MOD)*ifact[k], MOD);
}

/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N, M, K;
  cin >> N >> M >> K;
  ll ans = 0;
  gen();
  rep(i, N*M){
    ll x = i/N+1;
    ll y = i/M+1;
    ans =mod(ans+ (M-x)*(M-x+1)/2*N, MOD);
    ans =mod(ans+ (N-y)*(N-y+1)/2*M, MOD);
  }
  cout << mod(ans*comb(N*M-2, K-2),MOD)<<endl;
  return 0;
}


/**
*    created: 25.07.2020 06:24:27
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
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;}
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int dx2[8]={0, 1, 0, -1, 1, 1,-1, -1};
const int dy2[8]={1, 0,-1, 0, 1, -1, 1, -1};
const long double pi = acos(-1.0);
const int MAX = 1000010;
const int INF = 1LL << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;

void gridbfs(int i,int j,vector<string> s,vector<vector<int>> &dis) {
    int h = s.size(), w = s[0].size();
    queue<vector<int>> q; q.push({i,j});
    dis[i][j] = 0;
    while (!q.empty()) {
        auto v = q.front(); q.pop();
        if (v[0] > 0 && s[v[0] - 1][v[1]] == '.' && dis[v[0] - 1][v[1]] == -1) {
           dis[v[0] - 1][v[1]] = dis[v[0]][v[1]] + 1;
           q.push({v[0] - 1, v[1]});
        }
        if (v[1] > 0 && s[v[0]][v[1] - 1] == '.' && dis[v[0]][v[1] - 1] == -1) {
           dis[v[0]][v[1] - 1] = dis[v[0]][v[1]] + 1;
           q.push({v[0], v[1] - 1});
        }
        if (v[0] < h - 1 && s[v[0] + 1][v[1]] == '.' && dis[v[0] + 1][v[1]] == -1) {
            dis[v[0] + 1][v[1]] = dis[v[0]][v[1]] + 1;
            q.push({v[0] + 1, v[1]});
        }
        if (v[1] < w - 1 && s[v[0]][v[1] + 1] == '.' && dis[v[0]][v[1] + 1] == -1) {
            dis[v[0]][v[1] + 1] = dis[v[0]][v[1]] + 1;
            q.push({v[0], v[1] + 1});
        }
    }
    return;
}

signed main() {

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

    int h, w; cin >> h >> w;
    vector<string> v(h);
    int bcnt = 0;
    rep(i,h) cin >> v[i];
    rep(i,h) rep(j,w) if (v[i][j] == '#') bcnt++;
    vector<vector<int>> dis(h,vector<int>(w,-1));
    gridbfs(0,0,v,dis);
    if (dis[h-1][w-1] == -1) cout << -1 << endl;
    else cout << h * w - bcnt - dis[h-1][w-1] - 1 << endl;
    return 0;
}


// Abu Hurayra (HurayraIIT)
// IIT, Jahangirnagar University

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <bitset>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <math.h>
#include <stdio.h>
#include <string.h>
using namespace std;

typedef long long LL;
typedef long long int int64;
typedef unsigned long long int  uint64;
typedef vector<int> vi;

#define READ freopen("input.txt", "r", stdin);
#define WRITE freopen("output.txt", "w", stdout);
#define fast_io ios_base::sync_with_stdio(0);  cin.tie(0);
#define sz(a) int((a).size())
#define space " "
#define all(x) (x).begin(), (x).end()
#define endl '\n'
#define pi acos(-1.0)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define MOD 1000000007
#define PRECISION(x) cout << fixed << setprecision(x);

int main()
{
    fast_io
    string s ;
    cin >> s ;
    int a = s[0]-'0', b = s[1]-'0' , c = s[2]-'0' , d = s[3]-'0' ;

    if(a+b+c+d==7) cout << a << "+" << b << "+" << c << "+" << d << "=7\n";
    else if(a-b-c-d==7) cout <<a<<"-"<<b<<"-"<<c<<"-"<<d<< "=7\n";
    else if(a+b+c-d==7) cout <<a<<"+"<<b<<"+"<<c<<"-"<<d<< "=7\n";
    else if(a+b-c+d==7) cout <<a<<"+"<<b<<"-"<<c<<"+"<<d<< "=7\n";
    else if(a-b+c+d==7) cout <<a<<"-"<<b<<"+"<<c<<"+"<<d<< "=7\n";
    else if(a-b-c+d==7) cout <<a<<"-"<<b<<"-"<<c<<"+"<<d<< "=7\n";
    else if(a-b+c-d==7) cout <<a<<"-"<<b<<"+"<<c<<"-"<<d<< "=7\n";
    else if(a+b-c-d==7) cout <<a<<"+"<<b<<"-"<<c<<"-"<<d<< "=7\n";

    return 0;
}

#define _USE_MATH_DEFINES  // M_PI等のフラグ

#include <iostream>
#include <bitset>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <map>
#include <vector>
#include <list>

#define MOD 1000000007
#define COUNTOF(array) (sizeof(array)/sizeof(array[0]))

using namespace std;

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

    for (int bit=0; bit<(1<<3); bit++) {
        string ans = s.substr(0,1);
        int result = s.at(0) - '0';

        for (int i=0; i<3; i++) {
            if (bit>>i&1) {
                // iビット目が1なら+演算する
                result += s.at(i+1)-'0';
                ans += "+";
            }
            else {
                // iビット目が0なら-演算する
                result -= s.at(i+1)-'0';
                ans += "-";
            }
            ans.push_back(s.at(i+1));
        }

        if (result == 7) {
            cout << ans << "=7" << endl;
            return;
        }
    }
}

int main(int argc, char const *argv[]){
    solve();
    return 0;
}


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

int main() {
    int N, Q, a, b, c;
    cin >> N >> Q;
    fenwick_tree<ll> fw(N);
    rep(i, N) {
        cin >> a;
        fw.add(i, a);
    }
    rep(i, Q) {
        cin >> a >> b >> c;
        if (a) {
            cout << fw.sum(b, c) << endl;
        } else {
            fw.add(b, c);
        }
    }
}

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

#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define fr(i,k,n) for (int i = k; i < n; ++i)
#define fri(i,k,n) for (int i = k; i >= n; --i)
#define INF (int)1e9
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define all(arr) arr.begin(),arr.end()

void boost(){
  ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const int N=5e5+5;
ll tree[N];

ll read(int idx) {
  ll sum = 0;
  while (idx > 0) {
    sum += tree[idx];
    idx -= (idx & -idx);
  }
  return sum;
}

void update(int idx, ll val) {
  while (idx <N) {
    tree[idx] += val;
    idx += (idx & -idx);
  }
}

void solve(){
  int n,q;
  cin>>n>>q;
  int x;
  fr(i,1,n+1){
    cin>>x;
    update(i,x);
  }
  int t,l,r;
  while(q--){
    cin>>t>>l>>r;
    if(t==0){
      update(l+1,r);
    }
    else{
      cout<<read(r)-read(l)<<endl;
    }
  }
  return;
}

int main()
{
  boost();

  int tc=1;
  //cin>>tc;
  while(tc--)
    solve();
  return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
char a[105][105];
int f[2][105][105][105],line[105][105],list[105][105],n,m;
void upd(int &x,int w){
	x=(x<w)?w:x;
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%s",a[i]+1);
	int x,y;
	for(int i=1;i<=n;i++){
		for(int p=1;p<=m;p++){
			if(a[i][p]=='E') x=i,y=p;
			line[i][p]=line[i][p-1]+(a[i][p]=='o');
			list[i][p]=list[i-1][p]+(a[i][p]=='o');
		}
	}
	int pre=0,nxt=1,ans=0;
	for(int i=0;i<=n-x;i++,pre^=1,nxt^=1){
		memset(f[nxt],0,sizeof(f[nxt]));
		for(int p=0;p<x;p++){
			for(int j=0;j<=m-y;j++){
				for(int k=0;k<y;k++){
					int w=f[pre][p][j][k],W;
					if(x+i+1<=n-p) W=max(0,line[x+i+1][min(m-k,y+j)]-line[x+i+1][max(j,y-k-1)]);
					else W=0;
					upd(f[nxt][p][j][k],w+W);
					if(x-p-1>i) W=max(0,line[x-p-1][min(m-k,y+j)]-line[x-p-1][max(j,y-k-1)]);
					else W=0;
					upd(f[pre][p+1][j][k],w+W);
					if(y+j+1<=m-k) W=max(0,list[min(n-p,x+i)][y+j+1]-list[max(i,x-p-1)][y+j+1]);
					else W=0;
					upd(f[pre][p][j+1][k],w+W);
					if(y-k-1>j) W=max(0,list[min(n-p,x+i)][y-k-1]-list[max(i,x-p-1)][y-k-1]);
					else W=0;
					upd(f[pre][p][j][k+1],w+W);
					ans=max(ans,f[pre][p][j][k]);
				}
			}
		}
	}
	printf("%d",ans);
	return 0;
}

#include <iostream>
#include <vector>

using namespace std;

void solve()
{
	int N, M;
	cin >> N >> M;
	vector<int> A(N);
	vector<int> B(M);
	for(int i = 0; i < N; ++i)
	{
		cin >> A[i];
	}
	for(int i = 0; i < M; ++i)
	{
		cin >> B[i];
	}
	vector<int> point(N);
	int max = 0;
	for(int i = 0; i < M; ++i)
	{
		for(int j = 0; j < N; ++j)
		{
			if(B[i] >= A[j])
			{
				++point[j];
				if(max < point[j])
				{
					max = point[j];
				}
				break;
			}
		}
	}
	for(int i = 0; i < M; ++i)
	{
		if(max == point[i])
		{
			cout << i + 1 << endl;
		}
	}
}

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


#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<tuple>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef unsigned long long int ull;
const int INF=1e9;
const ll MOD=1e9+7;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int MAXN=2e5;

int h,w;
vector<vector<char> > a(1000,vector<char>(1000));
vector<vector<int> > d(1000,vector<int>(1000,INF));

int main(){
    cin>>h>>w;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>a[i][j];
        }
    }
    int ans=0;
    queue<ii> que;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(a[i][j]=='#'){
                d[i][j]=0;
                que.push(make_pair(i,j));
            }
        }
    }
    while(!que.empty()){
        ii p=que.front();que.pop();
        int y=p.first,x=p.second;
        for(int i=0;i<4;i++){
            int ny=y+dy[i],nx=x+dx[i];
            if(ny>=0&&ny<h&&nx>=0&&nx<w&&d[ny][nx]>d[y][x]+1){
                d[ny][nx]=d[y][x]+1;
                que.push(make_pair(ny,nx));
                ans=max(ans,d[ny][nx]);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

#include <bits/stdc++.h>

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

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int h,w;
    cin >> h >> w;
    vector<bool> a(h*w,false);

    queue<int> que;
    for(int i = 0; i < h; i++) {
        string tmp;
        cin >> tmp;
        for(int j = 0; j < w; j++) {
            int idx=i*w+j;
            if(tmp[j]=='#'){
                a[idx]=true;
                que.push(idx);
            }
        }
    }

    int cnt=0;
    int ans=0;
    while(cnt<h*w) {
        int n=que.size();
        cnt+=n;
        for(int i = 0; i < n; i++) {
            int idx=que.front();
            int add[4]={1,-1,w,-w};
            for(int j = 0; j < 4; j++) {
                int t=idx+add[j];
                int r=idx/w+add[j]/w;
                int c=idx%w+add[j]%w;
                if(r<0||r>=h||c<0||c>=w||a[t]==true) continue;
                a[t]=true;
                que.push(t);
            }
            que.pop();
        }
        ans++;
    }
    cout << ans-1 << "\n";

    return 0;
}


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

bool is_integer(double x){
    return std::floor(x) == x;
}

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

    while(true){
        if(is_integer(sqrt(n))){
            put(n);
            return 0;
        }
        n--;
    }
}

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

int main(){
    ll n;
    cin >> n;
    ll ans = 0;
    ans += n/11*2;
    if(n%11 != 0) ans += (n%11-1)/6 + 1;
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <string>
#include <regex>
using namespace std;
int main() {
  string input;
  cin >> input;
  regex pattern("^A[a-z]+C[a-z]+$");
  if (regex_match(input, pattern))
  {
    cout << "AC" << endl;
  }
  else
  {
    cout << "WA" << endl;
  }
  return 0;
}

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

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

  bool b=true;
  int cnt=0,x;
  if(s[0]!='A') b=false;
  for(int i=2;i<s.size()-1;i++){
    if(s[i]=='C'){
      cnt++;
      x=i;
    }
  }
  if(cnt!=1) b=false;
  for(int i=1;i<s.size();i++){
    if(i==x) continue;
    if(s[i]<'a' || s[i]>'z') b=false;
  }
  if(b) cout<<"AC"<<endl;
  else cout<<"WA"<<endl;

  return 0;
}


#include <vector>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <stack>
#include <queue>
#include <list>

const long long int INF = 6000000000;
const int MOD = (int)1e9 + 7;

using ll = long long;

using namespace std;

typedef pair<int,int> P;

struct edge{
  int to;
  int cost;
};

int V,E;
long long d[200][200];

int main(){

  cin >> V >> E;
  for( int i = 0; i < V; ++i){
    for( int j = 0; j < V; ++j){
      d[i][j] = INF;
    }
  }

  for( int i = 0; i < V; ++i){
    d[i][i] = 0;
  }

  for( int i = 0; i < E; ++i){
    int a,b,c;
    cin >> a >> b >> c;
    d[a][b] = c;
  }

  for( int k = 0; k < V; ++k){
    for( int i = 0; i < V; ++i){
      for( int j = 0; j < V; ++j){
        d[i][j] = min( d[i][j], d[i][k]+d[k][j]);
      }
    }
  }

  bool f = false;
  for( int i = 0; i < V; ++i){
    if( d[i][i] < 0 ){
      f = true;
    }
  }

  if(f){
    cout << "NEGATIVE CYCLE" << endl;
  }else{
    for( int i = 0; i < V; ++i){
      for( int j = 0; j < V; ++j){
        if(j) cout << " ";
        if( d[i][j]  >= 3000000000 ){
          cout << "INF";
        }else{
          cout << d[i][j];
        }
      }
      cout << endl;
    }
  }

}

#include<stdio.h>

int GCD(int a, int b) {
	int A, B, buff;
	// A >= B
	if (b > a) {
		A = b; B = a;
	}
	else { A = a; B = b; }
	while (A%B) {
		buff = B;
		B = A % B;
		A = buff;
	}
	return B;
}

int main() {
	int N, a, b, c;
	int G;
	int GC[1000000];
	scanf("%d", &N);
	if (!(N - 2)) {
		scanf("%d %d", &a, &b);
		G = GCD(a, b);
		for (int i = 1; i <= G; i++) {
			if (a%i == 0 && b%i == 0) {
				GC[i] = i;
			}
			else GC[i] = -i;
		}
		for (int j = 1; j <= G; j++) {
			if (GC[j] < 0)continue;
			printf("%d\n", GC[j]);
		}
	}
	else {
		scanf("%d %d %d", &a, &b, &c);
		G = GCD(c, GCD(a, b));
		for (int i = 1; i <= G; i++) {
			if (a%i == 0 && b%i == 0 && c%i == 0) {
				GC[i] = i;
			}
			else GC[i] = -i;
		}
		for (int j = 1; j <= G; j++) {
			if (GC[j] < 0)continue;
			printf("%d\n", GC[j]);
		}
	}

	return 0;
}


#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 100001
#define i197 1000000007

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<int,ll>Pil;
typedef pair<P1,ll> P2;
typedef list<int> li;
typedef list<li> lli;
typedef pair<string,string> Ps;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	// 1 変数を入れる;
	ll a;
	int b;
};

int main(){

	int d,t,s;
	cin>>d>>t>>s;
	if(t*s>=d)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;
}

#include <iostream>
using namespace std;

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

void solve(long long A, long long B){
    long long ans = -1000001;
    chmax(ans, A + B);
    chmax(ans, A - B);
    chmax(ans, A * B);
    cout << ans << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


#include <cstdio>
#include <algorithm>

using i8 = std::int8_t;
using u8 = std::uint8_t;
using i16 = std::int16_t;
using u16 = std::uint16_t;
using i32 = std::int32_t;
using u32 = std::uint32_t;
using i64 = std::int64_t;
using u64 = std::uint64_t;
using usize = std::size_t;

i32 a[200000];

auto main() -> i32 {
	i32 n, k;
	scanf("%d%d", &n, &k);
	for (i32 i = 0; i < n; i += 1) {
		scanf("%d", a + i);
	}
	i32 b[200001];
	for (i32 step = 0; step < std::min(64, k); step += 1) {
		std::fill(b, b + n + 1, 0);
		for (i32 i = 0; i < n; i += 1) {
			b[std::max(0, i - a[i])] += 1;
			b[std::min(n, i + a[i] + 1)] -= 1;
		}
		a[0] = b[0];
		for (i32 i = 1; i < n; i += 1) {
			b[i] += b[i - 1];
			a[i] = b[i];
		}
	}
	for (i32 i = 0; i < n; i += 1) {
		printf("%d%c", a[i], i == n - 1 ? '\n' : ' ');
	}
	return 0;
}

#include<bits/stdc++.h>

using namespace std;
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define mp make_pair
#define ld long double
typedef pair<int, int> pii;
typedef priority_queue<int, vector<int>, greater<int> > small_heap;
typedef priority_queue<int> big_heap;
const int N = 2e5 + 100;
int T;

int n, k, a[N];

bool work() {
    static int s[N];
    memset(s, 0, sizeof(s));
    for (int i = 1; i <= n; i++) {
        int l = max(1, i - a[i]), r = min(n, i + a[i]);
        s[l]++, s[r + 1]--;
    }
    bool res = false;
    for (int i = 1; i <= n; i++) {
        s[i] += s[i - 1];
        if (s[i] != a[i]) {
            res = true;
            a[i] = s[i];
        }
    }
    return res;
}

int main() {
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; i++)
        scanf("%d", &a[i]);
    for (int i = 1; i <= k; i++)
        if (!work()) break;
    for (int i = 1; i <= n; i++)
        printf("%d ", a[i]);
    printf("\n");
    return 0;
}


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

#define repeat(i,n) for (int i = 0; i < (n); ++i)
#define repeat_from(i,m,n) for (int i = m; i < (n); ++i)

#define MAX_S 1000
int dp[2][MAX_S+1];

int main() {
    string s1, s2;
    getline(cin, s1);
    getline(cin, s2);
    int *cur = dp[0]; repeat (i,s2.size()+1) cur[i] = i;
    int *prv = dp[1];
    repeat_from (i,1,s1.size()+1) {
        swap(cur,prv);
        cur[0] = prv[0] + 1;
        repeat_from (j,1,s2.size()+1) {
            cur[j] = min(cur[j-1]+1,
                    min(prv[j]+1,
                        prv[j-1]+(s1[i-1]==s2[j-1]?0:1)));
        }
    }
    cout << cur[s2.size()] << endl;
    return 0;
}

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
#define IOI 101
#define IOIOIOIOI 101010101
int dp[10 * IOI][10 * IOI];
string s, t;
int main() {
    for (int i = 0; i < 10 * IOI; i++) {
        for (int j = 0; j < 10 * IOI; j++) {
            dp[i][j] = IOIOIOIOI;
        }
    }
    cin >> s; cin >> t;
    for (int i = 0; i <= s.size(); i++)dp[i][0] = i;
    for (int i = 0; i <= t.size(); i++)dp[0][i] = i;
    for (int i = 0; i < s.size(); i++) {
        for (int j = 0; j < t.size(); j++) {
            dp[i + 1][j + 1] = min(dp[i][j], min(dp[i + 1][j], dp[i][j + 1])) + 1;
            if (s[i] == t[j]) dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j]);
        }
    }
    cout << dp[s.size()][t.size()] << endl;
    return 0;
}


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

const int mul[2] = {233, 19260817};
const int mod[2] = {998244353, 1000000007};

#define pb push_back

int n;
vector <int> a, b, na, nb, pw[2], hsh[2];
int get(int l, int r, int k) {return (hsh[k][r] + mod[k] - 1LL * pw[k][r - l] * hsh[k][l] % mod[k]) % mod[k];}

int main() {
	ios :: sync_with_stdio(0);
	cin >> n;
	for (int i = 0; i < n; ++ i) {int x; cin >> x; a.pb(x);}
	for (int i = 0; i < n; ++ i) {int x; cin >> x; b.pb(x);}
	for (int i = 0; i < n; ++ i) na.pb(a[i] ^ a[(i + 1) % n]);
	for (int i = 0; i < n; ++ i) na.pb(na[i]);
	for (int i = 0; i < n; ++ i) nb.pb(b[i] ^ b[(i + 1) % n]);
	int hb[2];
	for (int k = 0; k < 2; ++ k) {
		pw[k].pb(1); for (int i = 1; i <= n * 2; ++ i) pw[k].pb(1LL * mul[k] * pw[k].back() % mod[k]);
		hsh[k].pb(0); for (int i = 0; i < n * 2; ++ i) hsh[k].pb((1LL * mul[k] * hsh[k].back() + na[i]) % mod[k]);
		hb[k] = 0; for (int i = 0; i < n - 1; ++ i) hb[k] = (1LL * mul[k] * hb[k] + nb[i]) % mod[k];
	}
	for (int i = 0; i < n; ++ i)
		if (get(i, i + n - 1, 0) == hb[0] && get(i, i + n - 1, 1) == hb[1] && na[i + n - 1] == nb[n - 1])
			cout << i << " " << (a[i] ^ b[0]) << "\n";
	return 0;
}

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

vector<int> mp(vector<int> s) {
  int n = s.size();
  vector<int> ret(n + 1);
  ret[0] = -1;
  int j = -1;
  rep(i, n) {
    while (j >= 0 && s[i] != s[j]) j = ret[j];
    ret[i + 1] = ++j;
  }
  return ret;
}

vector<int> kmp(vector<int> str, vector<int> word) {
  vector<int> table = mp(word), ret;
  int m = 0, i = 0, n = str.size();
  while (m + i < n) {
    if (word[i] == str[m + i]) {
      if (++i == (int)(word.size())) {
        ret.push_back(m);
        m = m + i - table[i];
        i = table[i];
      }
    }
    else {
      m = m + i - table[i];
      if (i > 0) i = table[i];
    }
  }
  return ret;
}

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

  vector<int> c(n * 2), d(n);
  rep(i, n) {
    c[i] = a[i] ^ a[(i + 1) % n];
    c[i + n] = c[i];
  }
  rep(i, n) d[i] = b[i] ^ b[(i + 1) % n];

  vector<int> res = kmp(c, d);
  rep(i, res.size()) {
    int k = res[i];
    if (k >= n) break;
    int x = a[k] ^ b[0];
    cout << k << " " << x << endl;
  }

  return 0;
}


#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>

using namespace std;

template <class T>
using gp_queue=priority_queue<T, deque<T>, less<T>>;

using Weight=long long;
static const Weight INF=1LL<<57;

struct Edge {
    size_t src, dst;
    Weight weight;
    Edge() {}
    Edge(size_t src, size_t dst, Weight weight=1):
        src(src), dst(dst), weight(weight)
    {}
};

bool operator<(const Edge &e, const Edge &f) {
    if (e.weight != f.weight) {
        return e.weight > f.weight;
    } else {
        return e.src!=f.src? e.src<f.src : e.dst<f.dst;
    }
}

using Edges=vector<Edge>;
using Vertex=vector<Edge>;
using Graph=vector<Vertex>;

void join(Graph &g, size_t s, size_t d, Weight w=1) {
    // non-directed
    g[s].push_back(Edge(s, d, w));
    g[d].push_back(Edge(d, s, w));
}

void connect(Graph &g, size_t s, size_t d, Weight w=1) {
    // directed
    g[s].push_back(Edge(s, d, w));
}

vector<vector<Weight>> shortest_distance(Graph g) {
    /* Johnson */
    size_t V=g.size();
    vector<Weight> h(V);
    for (size_t k=0; k<V; ++k)
        for (size_t i=0; i<V; ++i)
            for (const Edge &e: g[i])
                if (h[e.dst] > h[e.src] + e.weight) {
                    h[e.dst] = h[e.src] + e.weight;
                    if (k == V-1)
                        return vector<vector<Weight>>();
                }

    for (size_t i=0; i<V; ++i)
        for (Edge &e: g[i])
            e.weight += h[e.src] - h[e.dst];

    vector<vector<Weight>> d(V, vector<Weight>(V, INF<<1));
    vector<vector<size_t>> prev(V, vector<size_t>(V, -1));
    for (size_t s=0; s<V; ++s) {
        gp_queue<Edge> q; q.push(Edge(s, s, 0));
        d[s][s] = 0;
        while (!q.empty()) {
            Edge e=q.top(); q.pop();
            if (~prev[s][e.dst]) continue;

            prev[s][e.dst] = e.src;
            for (const Edge &f: g[e.dst]) {
                if (d[s][f.dst] > e.weight + f.weight) {
                    d[s][f.dst] = e.weight + f.weight;
                    q.push(Edge(f.src, f.dst, e.weight+f.weight));
                }
            }
        }
        for (size_t u=0; u<V; ++u)
            d[s][u] += h[u] - h[s];
    }

    return d;
}

int main() {
    size_t V, E;
    scanf("%zu %zu", &V, &E);

    Graph g(V);
    for (size_t i=0; i<E; ++i) {
        size_t s, t;
        Weight d;
        scanf("%zu %zu %lld", &s, &t, &d);

        connect(g, s, t, d);
    }

    vector<vector<Weight>> d=shortest_distance(g);
    if (d.empty())
        return !printf("NEGATIVE CYCLE\n");

    for (vector<Weight> w: d)
        for (size_t i=0; i<V; ++i)
            if (w[i] < INF) {
                printf("%lld%c", w[i], i<V-1? ' ':'\n');
            } else {
                printf("INF%c", i<V-1? ' ':'\n');
            }

    return 0;
}

#include<iostream>
#include<queue>
#include<vector>
#include<functional>
using namespace std;
typedef pair<int,int> P;	//現在コスト、島の番号

int n,k;
int cost[101][101];
int Dijkstra(int left,int get){
	int done[101] = {0};	//確定後のコストを格納
	int mincost[101];
	for(int i = 0;i < 101;i++)
		mincost[i] = 500000000;
	priority_queue<P,vector<P>,greater<P> >que;
	P edge;
	que.push(P(0,left));
	while(done[get] == 0 && !que.empty()){
		edge.first = que.top().first;
		edge.second = que.top().second;
		que.pop();
		//何度も同じ頂点にコストが更新される(pushされる)ことがあるので、確定後に残りのケースが作動しないようにする。
		if(done[edge.second])
			continue;
		//確定後のコスト
		done[edge.second] = edge.first;
		//確定した頂点から枝を伸ばす(今までの最小を記録することで重複探索を減らす)
		for(int i = 1;i <= n;i++){
			if(cost[edge.second][i] > 0 && done[i] == 0 && mincost[i] > edge.first+cost[edge.second][i]){
				mincost[i] = edge.first+cost[edge.second][i];
				que.push(P(edge.first+cost[edge.second][i],i));
			}
		}
	}
	if(done[get])
		return done[get];
	return -1;
}
int mincost[50000],mcor = 0;
int main(){
	int i,j,a,b,c,d;
	while(true){
		cin >> n >> k;
		if(n == 0 && k == 0)
			break;
		for(i = 0;i < 101;i++){
			for(j = 0;j < 101;j++){
				cost[i][j] = 0;
			}
		}
		for(i = 0;i < k;i++){
			cin >> a;
			if(a == 0){
				cin >> b >> c;
				mincost[mcor] = Dijkstra(b,c);
				mcor++;
			}
			else{
				cin >> b >> c >> d;
				if(cost[b][c] == 0 || cost[b][c] > d)
					cost[b][c] = d;
				if(cost[c][b] == 0 || cost[c][b] > d)
					cost[c][b] = d;
			}
		}
	}
	for(i = 0;i < mcor;i++){
		cout << mincost[i] << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using P = pair<int, int>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion
#pragma region chminmax
template <typename T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion
using vvll = vector<vll>;
const ll INF = 1e12;
int main()
{
    string s;
    cin >> s;
    int n = s.size();

    vvll dp(n + 1, vll(2, INF));
    dp[0][0] = 0;
    dp[0][1] = 1;

    rep(i, n)
    {
        int x = s[i] - '0';
        chmin(dp[i + 1][0], dp[i][0] + x);
        chmin(dp[i + 1][1], dp[i][0] + x + 1);
        chmin(dp[i + 1][0], dp[i][1] + (10 - x));
        chmin(dp[i + 1][1], dp[i][1] + (10 - x) - 1);
    }

    cout << dp[n][0] << endl;
    return 0;
}

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

template <typename T> void print(T t) { cout<<t<<endl; }
template<typename T, typename... Args> void print(T t, Args... args) { cout<<t<<" "; print(args...); }

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define int long long
#define double long double

int n;
string s;
int cache[1000004][3];
int dp(int pos,int carr)
{
    if(pos==n)
        return carr;
    int &ans=cache[pos][carr];
    if(ans!=-1)
        return ans;
    ans=1e18;
    for(int i=0;i<10;i++)
    {
        int dig1=i;
        int dig2=(i+carr+s[pos]-'0')%10;
        ans=min(ans,dig1+dig2+dp(pos+1,(i+carr+s[pos]-'0')/10));
    }
    return ans;
}
int32_t main()
{
    cin>>s;
    reverse(s.begin(),s.end());
    n=s.length();
    memset(cache,-1,sizeof(cache));
    print(dp(0,0));
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define endl '\n';
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

int main() {

    int n;
    cin>>n;
    string a,b,c;
    cin>>a>>b>>c;
    int ans=0;
    rep(i,n){
        if(a[i]==b[i]&&a[i]==c[i])continue;
        if(a[i]==b[i]||a[i]==c[i]||c[i]==b[i])ans++;
        else ans+=2;
    }
    fin(ans);
}

#include <bits/stdc++.h>
using namespace std;
int main()
  {int i, c{}; string A, B, C; cin >> i >> A >> B >> C;
  while (i--) c += set<char>{A[i], B[i], C[i]}.size() - 1;
  cout << c;}


#include<bits/stdc++.h>

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

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

#define MAXN 88
#define MAXS 13000

int dp[MAXN][MAXN][MAXS];

int main(){
  int h,w;cin>>h>>w;
  vector<vector<int>> scores(h);
  rep(i, h)rep(j, w){
    int a;cin>>a;
    scores[i].push_back(a);
  }
  rep(i, h)rep(j, w){
    int a;cin>>a;
    scores[i][j] -= a;
    if(scores[i][j] < 0)scores[i][j] *= -1;
  }

  dp[0][0][scores[0][0]] = 1;
  rep(i, h)rep(j, w)rep(k, MAXS){
    int s = scores[i][j];
    int mpre = k-s;
    if(mpre<0)mpre *= -1;
    if(i && dp[i-1][j][mpre]==1)dp[i][j][k]=1;
    if(j && dp[i][j-1][mpre]==1)dp[i][j][k]=1;

    int ppre = k+s;
    if(ppre<=7000){
      if(i && dp[i-1][j][ppre]==1)dp[i][j][k]=1;
      if(j && dp[i][j-1][ppre]==1)dp[i][j][k]=1;
    }
  }

  int result = 0;
  rrep(i, MAXS)if(dp[h-1][w-1][i])result = i;

  cout<<result<<endl;

  return 0;

  rep(i, h){
    rep(j, w)cout<<scores[i][j]<<' ';cout<<endl;
  }
cout<<"###"<<endl;

rep(k, 15){
cout<<k<<endl;
  rep(i, h){
    rep(j, w)cout<<dp[i][j][k]<<' ';cout<<endl;
  }
  cout<<"---"<<endl;
}

  return 0;
}


#include<iostream>
int main(){
	int N;
	std::cin>>N;
	long int* A=new long int[N];
	long sum=0;
	for(int i=0;i<N;i++){
		std::cin>>A[i];
		sum+=A[i];
		sum%=1000000007;
	}
	long ans=0;
	for(int i=0;i<N;i++){
		sum-=A[i];
		if(sum<0){
			sum+=1000000007;
		}
		ans+=sum*A[i];
		ans%=1000000007;
	}
	std::cout<<ans;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E18;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int main(){fastio
    ll n;cin>>n;
    ll a[n];rep(i,0,n-1)cin>>a[i];
    ll b=0;
    ll c=0;
    rep(i,0,n-1){
        b+=a[i];
        c+=a[i]*a[i];
        b=mod(b);
        c=mod(c);
    }
    ll ans=mod(b*b-c);
    if(ans%2==0){
        cout<<mod(ans/2)<<endl;
    }else{
        cout<<mod((ans+i_7)/2)<<endl;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
  int q,z,y=0;
  cin>>q;
  z=q;
  while(z>0){
    y+=z%10;
    z/=10;
  }
  if(q%y==0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


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

int main(){
    int N, count;
    cin >> N;
    count = 0;
    vector<int> vec(N);
    for(int i = 0; i < N; i++){
        cin >> vec.at(i);
    }
    for(int i = 0; i < N; i++){
        for(int j = 0; j < i; j++){
            for(int k = 0; k < j; k++){
                if((abs(vec.at(i) - vec.at(j)) < vec.at(k) && vec.at(k) < vec.at(i) + vec.at(j)) && vec.at(i) != vec.at(j) && vec.at(j) != vec.at(k)&& vec.at(k) != vec.at(i))
                count++;
        }

     }

	}
  cout << count << endl;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,x,y) for(ll i=x;i<=y;i++)
#define imin INT_MIN
#define imax INT_MAX
int mod =1e9+7;
//~ vector<bool> cats;

//~ ll ans;
//~ ll n,m;
//~ void dfs(vector<vector<int>>& graph,int s,int consCats,int parent){
	//~ if(consCats>m) return;
	//~ if(graph[s].size()==1 && graph[s][0]==parent)
	//~ {
		//~ if(cats[s]) consCats++;
		//~ if(consCats<=m) ans++;
		//~ return;
	//~ }
	//~ if(!cats[s]) consCats=0;
	//~ else consCats++;
	//~ for(auto val:graph[s]){
		//~ if(val!=parent)
		//~ dfs(graph,val,consCats,s);
	//~ }

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

	ll n;
	cin>>n;
	vector<int> a(n);

	rep(i,0,n-1) cin>>a[i];
	sort(a.begin(),a.end());
	ll ans=0;
	int i=0;
	while(i<n-2){
		int j=i+1;
		int outer=0;

		while(j<n-1){
			int local=0;
			if(a[j]!=a[i])
			rep(k,j+1,n-1){
				if(a[k]!=a[j])
					if(a[i]+a[j]>a[k])
					local++;
			}
			int tmp=a[j];
			while(j<n-1 && a[j]==tmp) {
				outer+=local;
				j++;
			}
		}
		int tmp=a[i];
		while(i<n-2 && a[i]==tmp){
		ans+=outer;
		i++;}
	}
	cout<<ans;

	return 0;
}


#include<iostream>
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
int n, q, inf=2e9, cnt;
vector<int> par ;
vector<pair<int,pair<int,int> > > v;
map<int,int> id ;
int tree[3000006];
void update(int node, int s, int e, int l, int r, int val)
{
    if(s>r||e<l)
        return ;
    if(s>=l && e<=r)
    {
        tree[node]=min(tree[node],val);
        return ;
    }
    int m=(s+e)/2;
    update(2*node,s,m,l,r,val);
    update(2*node+1,m+1,e,l,r,val);
}
int solve(int node, int s,int e, int pos)
{
    if(s==e)
        return tree[node];
    int m=(s+e)/2;
    tree[2*node]=min(tree[node],tree[2*node]);
    tree[2*node+1]=min(tree[node],tree[2*node+1]);
    return pos<=m ? solve(2*node,s,m,pos) : solve(2*node+1,m+1,e,pos);
}
int main()
{
    IO
    cin>>n>>q;
    for(int i=1; i<=3e6; i++)
        tree[i]=inf;
    for(int i=1; i<=n; i++)
    {
        int s, t, x;
        cin>>s>>t>>x;
        v.push_back({x,{s-x,t-x-1}});
        id[s-x]++;
        id[t-x-1]++;
    }
    for(int i=1; i<=q; i++)
    {
        int d;
        cin>>d;
        id[d]++;
        par.push_back(d);
    }
    for(auto i : id)
        id[i.first]=++cnt;
    for(int i=0; i<n; i++)
    {
        int l=id[v[i].second.first], r=id[v[i].second.second];
        update(1,1,cnt,l,r,v[i].first);
    }
    for(int i=0; i<q; i++)
    {
        int ans=solve(1,1,cnt,id[par[i]]);
        if(ans==inf)
            ans=-1;
        cout<<ans<<"\n";
    }
}

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

typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int N, Q;
    cin >> N >> Q;
    int Si, Ti, Xi, Di;
    vector<array<int, 3>> stx(N);
    for(int i=0;i<N;i++){
        cin >> Si >> Ti >> Xi;
        auto l = Si-Xi;
        auto r = Ti-Xi;
        if(l<0) l=0;
        stx[i] = array<int, 3>{l, r, Xi};
    }
    sort(stx.begin(), stx.end(), [](array<int, 3>& a, array<int, 3>& b){return a[2] < b[2];});
    set<int> D;
    map<int, int> res;
    for(int i=0;i<Q;i++){
        cin >> Di;
        D.insert(Di);
    }

    for(auto v : stx){
        auto itrl = D.lower_bound(v[0]);
        auto itrr = D.upper_bound(v[1]-1);
        for(auto itr = itrl; itr != itrr; ++itr){
            res[*itr] = v[2];
        }
        D.erase(itrl, itrr);
    }
    for(auto v : D){
        res[v] = -1;
    }
    for(auto m : res){
        cout << m.second << endl;
    }

    return 0;
}


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

class LinearSearch {
public:
	int n, q;
	vector< int > S, T;

	LinearSearch() {}

	void solve() {
		int ans = 0;

		for (int i = 0; i < q; ++i) {
			int tar = T[i];

			for (int j = 0; j < n; ++j) {
				if (S[j] == tar) {
					++ans;
					break;
				}
			}
		}

		cout << ans << endl;
	}
};

int main() {
	LinearSearch ls;

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

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

	ls.solve();
}

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

int main(){
    int n,q,ans=0,chk=0;
    scanf("%d",&n);
    vector<int> s(n);
    for(auto&e:s){
        scanf("%d",&e);
    }
    sort(s.begin(),s.end());

    scanf("%d",&q);
    vector<int> t(q);
    for(auto&e:t){
        scanf("%d",&e);
    }
    sort(t.begin(),t.end());

    for(int i=0;i<q;i++){
        for(int j=chk;j<n;j++){
            if(t[i]==s[j]){
                ans++;
                break;
            }else if(t[i]<s[j]){
                break;
            }
            chk=j;
        }
    }
    printf("%d\n",ans);
    return 0;
}


#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;
void chmax(LL& a, LL b) {
	a = max(a, b);
}
void chmin(LL& a, LL b) {
	a = min(a, b);
}
//////////////

void solve() {
	int H, W, K;
	cin >> H >> W >> K;
	/*
	縦棒がW本ある。W-1個のあるなしで全探索。って
	*/

	//左付きで棒があるかないか
	vector<vector<bool>> BF;
	vector<int> BF_num;
	for (int s = 0; s < (1 << (W-1)); ++s) {
		int ter = s;
		vector<bool> res(W - 1);
		int cnt = 0;
		for (int i = 0; i < W-1; ++i) {
			if (ter & 1) {
				res[i] = true;
				cnt++;
			}
			else {
				res[i] = false;
			}
			ter /= 2;
		}
		bool flag = true;
		for (int i = 0; i < W - 1 - 1; ++i) {
			if (res[i] == true && res[i + 1] == true) {
				flag = false;
				break;
			}
		}
		if (flag == true) {
			BF.push_back(res);
			BF_num.push_back(cnt);
		}
	}

	/*
	H+1 * W * (K+1)個必要
	*/
	//高さと位置のみ
	vector<vector<LL>> dp(H + 1,vector<LL>(W, 0));
	dp[0][0] = 1;
	int BF_len = BF.size();
	for (int h = 0; h < H; ++h) {//上から順に
		//dp[h]->dp[h+1]
		for (int s = 0; s < BF_len; ++s) {//全ての横棒で
			vector<bool> B = BF[s];

			for (int w = 0; w < W; ++w) {
				//dp[h][k]
				if (w+1 <W && B[w] == true) {//右へ
					dp[h + 1][w + 1] += dp[h][w];
					dp[h + 1][w + 1] %= MOD;
				}
				else if (w - 1 >= 0 && B[w - 1] == true) {//左
					dp[h + 1][w - 1] += dp[h][w];
					dp[h + 1][w - 1] %= MOD;
				}
				else{//真下へ
					dp[h + 1][w] += dp[h][w];
					dp[h + 1][w] %= MOD;
				}
			}
		}
	}
	//[H][K-1]
	LL ans = dp[H][K-1];

	cout << ans << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別

	solve();
}


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

int main() {

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

    int n;
    cin >> n;
    vector<int> a(2 * n);

    for (int i = 0; i < (n << 1); i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    int ans = 0;
    for (int i = 0; i < (n << 1); i+=2) {
        ans += a[i];
    }
    cout << ans;

}

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

int main() {
    int n;
    cin >> n;
    int a[n + 2];
    for (int i = 1; i < n + 1; i++) cin >> a[i];
    a[0] = 0, a[n + 1] = 0;

    ll s = 0;
    rep(i, n + 1) s += abs(a[i + 1] - a[i]);

    for (int i = 1; i < n + 1; i++) {
        cout << s + abs(a[i - 1] - a[i + 1]) -
                    abs(abs(a[i - 1] - a[i]) + abs(a[i] - a[i + 1]))
             << endl;
    }
    return 0;
}


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

const ll INF = 1001001001;
const ll mod = 1000000007;

ll dp[105][11];

int main(){
    int h, w, k; cin >> h >> w >> k;
    dp[0][1] = 1;
    for(int i = 1; i <= h; i++){
        for(int l = 1; l <= w; l++){
            ll a = 0, b = 0, c = 0;
            for(int j = 0; j < (1 << w-1); j++){
                bool ok = true;
                for(int m = 0; m < w - 2; m++){
                    if(j & (1 << (m + 1)) && j & (1 << m)) ok = false;
                }
                if(!ok) continue;
                int mask1 = 1 << (l - 1), mask2 = 1 << (l - 2);
                if(l >= 2 && (mask2 & j)) a++;
                else if(mask1 & j) c++;
                else b++;
            }
            dp[i][l] = (dp[i-1][l-1]*a%mod+dp[i-1][l]*b%mod + dp[i-1][l+1]*c%mod)%mod;
        }
    }
    cout << dp[h][k] << endl;
}

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

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

const int mod = 1e9+7;
const int N = 123;

long long p[N];
int H, W, K;
long long dp[N][8];

bool check(int x) {
  int prev = 0;
  while (x) {
    if ((x&1) && prev) return false;
    prev = x&1;
    x >>= 1;
  }
  return true;
}

long long rek(int h, int pos) {
  if (h == H) return pos == (K-1);
  long long &ret = dp[h][pos];
  if (ret != -1) return ret;
  ret = 0;
  for (int j = 0; j < 3; ++j) {
    if (pos == 0 && j == 1) continue;
    if (pos == W-1 && j == 2) continue;
    long long cur = 0;
    int lmt = pos-1;
    if (j == 1) --lmt;
    for (int i = 0; i < (1 << max(lmt, 0)); ++i) {
      if (!check(i)) continue;
      ++cur;
    }
    long long cur2 = 0;
    lmt = W-1-pos-1;
    if (j == 2) --lmt;
    for (int i = 0; i < (1 << max(lmt, 0)); ++i) {
      if (!check(i)) continue;
      ++cur2;
    }
    cur *= cur2;
    if (j == 1) {
      ret = (ret + cur*rek(h+1, pos-1)%mod) % mod;
    } else if (j == 2) {
      ret = (ret + cur*rek(h+1, pos+1)%mod) % mod;
    } else {
      ret = (ret + cur*rek(h+1, pos)%mod) % mod;
    }
  }
  return ret;
}

void solve() {
  memset(dp, -1, sizeof(dp));
  scanf("%d%d%d", &H, &W, &K);
  printf("%lld", rek(0, 0));
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define N 100000
#define pb push_back

int n, k, len, a[N + 5], d[N + 5], vis[N + 5], ans;
vector<int> G[N + 5];

struct Cmp {
	bool operator () (const int &a, const int &b) const {
		return d[a] < d[b];
	}
};
priority_queue<int, vector<int>, Cmp> pq;

void dfs1(int u) {
	for (int i = 0, v; i < G[u].size(); ++i) {
		v = G[u][i];
		d[v] = d[u] + 1;
		dfs1(v);
	}
}

void dfs2(int u) {
	len++;
	if (u == 1)
		return ;
	dfs2(a[u]);
}

void mark(int u) {
	vis[u] = 1;
	for (int i = 0, v; i < G[u].size(); ++i) {
		v = G[u][i];
		if (vis[v])
			continue;
		mark(v);
	}
}

int main() {
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; ++i)
		scanf("%d", &a[i]);
	dfs2(a[1]);
	for (int i = 2; i <= n; ++i)
		G[a[i]].pb(i);
	dfs1(1);
	bool flag = 1;
	for (int i = 1; i <= n; ++i)
		if (d[i] > k || (k - d[i]) % len) {
			flag = 0;
			break;
		}
	if (flag)
		ans = 0;
	else {
		if (a[1] != 1) ans = 1;
		else ans = 0;
		a[1] = 1;
		for (int i = 2; i <= n; ++i)
			pq.push(i);
		while (!pq.empty()) {
			int u = pq.top(), v; pq.pop();
			if (d[u] <= k || vis[u])
				continue;
			ans++;
			v = u;
			for (int i = 1; i <= k - 1; ++i)
				v = a[v];
			a[v] = 1;
//			printf("u:%d v:%d\n", u, v);
			mark(v);
		}
	}
	printf("%d\n", ans);
//	for (int i = 1; i <= n; ++i) printf("%d ", a[i]);
//	printf("\n");
	return 0;
}

////////////////////////////////////////////
///                                      ///
///         Template ver. 1 rapel        ///
/// Fear is Temporary, Regret is Forever ///
///          Must Try and Get AC         ///
///                                      ///
////////////////////////////////////////////
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>

#include <math.h>
#include <complex>

#include <assert.h>
#include <time.h>
//#include <chrono>
//#include <random>

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <bitset>

#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define endl '\n'
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

void desperate_optimization(int precision){
  	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(precision);
}

const int N = 1e5;
int arr[N + 5];
vector<int> lst[N + 5];
int tot = 0;
int depth[N + 5];
int n, k;

void dfs(int idx) {
	depth[idx] = 0;
	for(auto x: lst[idx]) {
		dfs(x);
		depth[idx] = max(depth[idx], depth[x] + 1);
	}
//	cout<<"IDX "<<idx<<" "<<depth[idx]<<endl;
	if(depth[idx] == k - 1 && arr[idx] != 1 && idx != 1) {
		depth[idx] = -1;
		tot++;
	}
}

void hora(int tc) {
	cin>>n>>k;
	for(int i = 1;i <= n;i++) {
		cin>>arr[i];
		if(i != 1) lst[arr[i]].PB(i);
	}
	if(arr[1] != 1) tot++;
	dfs(1);
	cout<<tot<<endl;
}

int main(){
	desperate_optimization(10);
	int ntc = 1;
	//cin>>ntc;
	for(int tc = 1;tc <= ntc;tc++) hora(tc);
	return 0;
}


#include <cstdio>
#include <algorithm>
#include <vector>
#define file(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)

inline int read()
{
	int data = 0, w = 1; char ch = getchar();
	while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
	if (ch == '-') w = -1, ch = getchar();
	while (ch >= '0' && ch <= '9') data = data * 10 + (ch ^ 48), ch = getchar();
	return data * w;
}

const int N(2e5 + 10), Mod(1e9 + 7);
int fac[N], inv[N], f[N], n, m, A, B;
int C(int n, int m) { return 1ll * fac[n + m] * inv[m] % Mod * inv[n] % Mod; }
int fastpow(int x, int y)
{
	int ans = 1;
	for (; y; y >>= 1, x = 1ll * x * x % Mod)
		if (y & 1) ans = 1ll * ans * x % Mod;
	return ans;
}

int main()
{
	n = read() - 1, m = read() - 1, A = read() - 1, B = read() - 1, fac[0] = inv[0] = 1;
	if (A == n || B == m) return puts("0"), 0;
	for (int i = 1; i <= n + m; i++) fac[i] = 1ll * fac[i - 1] * i % Mod;
	inv[n + m] = fastpow(fac[n + m], Mod - 2);
	for (int i = n + m - 1; i; i--) inv[i] = 1ll * inv[i + 1] * (i + 1) % Mod;
	int ans = C(n, m);
	for (int i = 0; i <= A; i++)
		ans = (ans - 1ll * C(i, m - B - 1) * C(n - i, B) % Mod + Mod) % Mod;
	printf("%d\n", ans);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7;

int h,w,a,b,fac[200006],ans=0,inv_fac[200006];
int binpow(int x,int y){
	if(y==0) return 1;
	else{
		long long tmp=binpow(x,y/2);
		if(y%2==1) return ((tmp*tmp)%mod*x)%mod;
		else return (tmp*tmp)%mod;
	}
}

int C(int k,int n) {
	return fac[n]*inv_fac[k]%mod*inv_fac[n-k]%mod;
}

int path(int x1,int y1,int x2,int y2) {
	if(x1>x2||y1>y2) return 1;
	return  C(x2-x1,x2-x1+y2-y1)%mod;
}

signed main() {
	cin>>h>>w>>a>>b;
	fac[0]=1;
	inv_fac[0]=1;
	for(int i=1;i<=200005;++i)
	{
		fac[i]=((i % mod)*fac[i-1])%mod;
		inv_fac[i]=binpow(fac[i],mod-2)%mod;
	}
	for(int i=1;i<=h-a;++i) {
		ans+=((path(1,1,i,b)%mod)*(path(i,b+1,h,w)%mod))%mod;
	}
	cout<<ans%mod;
}


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

int main(){
  long long n,q;
  cin >> n >> q;
  long long s[n],t[n],x[n],d[q];
  pair<long long, int> p[n];
  for(int i=0;i<n;i++){
    cin >> s[i] >> t[i] >> x[i];
    p[i]=make_pair(x[i], i);
  }
  sort(p, p+n);
  vector<pair<long long, int> > vec;
  bool active[n];
  for(int i=0;i<n;i++){
    vec.push_back(make_pair(s[p[i].second]-x[p[i].second]-1, i));
    vec.push_back(make_pair(t[p[i].second]-x[p[i].second]-1, i));
    active[i]=false;
  }
  for(int i=0;i<q;i++){
    cin >> d[i];
    vec.push_back(make_pair(d[i], -1));
  }
  sort(vec.begin(), vec.end());
  priority_queue<int, vector<int>, greater<int> > que;
  for(size_t i=0;i<vec.size();i++){
    if(vec[i].second == -1){
      if(!que.empty()){
        cout << p[que.top()].first << endl;
      }else{
        cout << -1 << endl;
      }
    }else{
      long long idx = vec[i].second;
      if(active[idx]){ //工事終了
        active[idx] = false;
        if(idx == que.top()){
          que.pop();
          while(!que.empty()){
            if(active[que.top()]){
              break;
            }else{
              que.pop();
            }
          }
        }
      }else{ //工事開始
        active[idx] = true;
        que.push(idx);
      }
    }
  }
  return 0;
}

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

struct ppp{ll l,r,v,tag;}tree[4000005];

struct ttt{ll s,t,x;}b[200005];

bool cmp(ttt l,ttt r){return l.x>r.x;}

ll p[200005];

set<ll> k;

vector<ll> a;

void push(ll i){

    tree[i*2].tag=tree[i].tag;

	tree[i*2+1].tag=tree[i].tag;

	tree[i*2].v=(tree[i*2].r-tree[i*2].l+1)*tree[i*2].tag;

	tree[i*2+1].v=(tree[i*2+1].r-tree[i*2+1].l+1)*tree[i*2+1].tag;

	tree[i].tag=0;

}

void buildtree(ll i,ll l,ll r){

	tree[i].l=l;tree[i].r=r;

	if(l==r){

		tree[i].v=-1;

		return;

	}

	buildtree(i*2,l,(l+r)/2);

	buildtree(i*2+1,(r+l)/2+1,r);

	tree[i].v=tree[i*2].v+tree[i*2+1].v;

}

void update(ll i,ll l,ll r,ll k){

    if(tree[i].l>=l&&tree[i].r<=r){

        tree[i].tag=k;

		tree[i].v=(tree[i].r-tree[i].l+1)*k;

        return ;

    }

    if(tree[i].tag) push(i);

    ll m=(tree[i].l+tree[i].r)/2;

    if(l<=m) update(i*2,l,r,k);

    if(r>m) update(i*2+1,l,r,k);

    tree[i].v=tree[i*2].v+tree[i*2+1].v;

}

ll query(ll i,ll l,ll r){

    if(tree[i].l>=l&&tree[i].r<=r){

        return tree[i].v;

    }

    if(tree[i].tag) push(i);

    ll m=(tree[i].r+tree[i].l)/2,ans=0;

    if(l<=m) ans+=query(i*2,l,r);

    if(r>m) ans+=query(i*2+1,l,r);

    return ans;

}

int main(){

	ll n,q;

	cin>>n>>q;

	a.push_back(-1e9);

	for(ll i=1;i<=n;i++){

		cin>>b[i].s>>b[i].t>>b[i].x;

		k.insert(max(b[i].s-b[i].x,(ll)0));

		k.insert(max(b[i].t-1-b[i].x,(ll)0));

	}

	for(ll i=1;i<=q;i++){

		cin>>p[i];k.insert(p[i]);

	}

	for(auto x:k){

		a.push_back(x);

	}

	buildtree(1,1,a.size());

	sort(b+1,b+1+n,cmp);

	for(ll i=1;i<=n;i++){

		ll l=lower_bound(a.begin(),a.end(),max((ll)0,b[i].s-b[i].x))-a.begin();

		ll r=lower_bound(a.begin(),a.end(),max((ll)0,b[i].t-b[i].x-1))-a.begin();

		update(1,l,r,b[i].x);

	}

	for(ll i=1;i<=q;i++){

		ll l=lower_bound(a.begin(),a.end(),p[i])-a.begin();

		cout<<query(1,l,l)<<endl;

	}

}


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

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

typedef long long ll;

int main() {
    int n,m,q;cin>>n>>m>>q;
    int a[n][n];

    rep(i,n)rep(j,n)a[i][j]=0;

    int tmp_r,tmp_l;
    rep(i,m){
        cin>>tmp_l>>tmp_r;
        --tmp_l,--tmp_r;
        ++a[tmp_l][tmp_r];
    }

    int b[n][n];
    rep(i,n)rep(j,n)b[i][j]=a[i][j];
    rep(i,n)rep(j,n-1)b[i][j+1]+=b[i][j];

    int ql,qr;
    rep(i,q){
        int ans = 0;
        cin>>ql>>qr;
        --ql,--qr;
      ans = b[qr][qr];
        REP(j,ql,qr)ans+=b[j][qr];
//      if(ql!=0)REP(j,ql,qr+1)ans-=b[ql-1][j];

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

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
const int maxn=1e6+10;
const int mod=1e9+7;
const double pi=3.1415926535;
int w[3005],v[3005];
int dp[3005][3005][2];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,t;
    cin>>n>>t;
    for(int i=1;i<=n;i++)
    {
        cin>>w[i]>>v[i];
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=t-1;j++)
        {
            dp[i][j][1]=max(dp[i-1][j][1],dp[i-1][j][0]+v[i]);
            if(j>=w[i])
            {
                dp[i][j][0]=max(dp[i-1][j][0],dp[i-1][j-w[i]][0]+v[i]);
                dp[i][j][1]=max(dp[i][j][1],dp[i-1][j-w[i]][1]+v[i]);
            }
            else
            {
                dp[i][j][0]=dp[i-1][j][0];
            }
        }
    }
    cout<<dp[n][t-1][1]<<'\n';

}


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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const long long INF = 2e18;
const long long MOD = 1e9+7;

#define sx(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i < n; i++)
#define ALL(a) begin(a),end(a)

int main(void) {
    int n;
    while (cin >> n, n) {
        vector<pair<int,ll>> s(4000, {inf, 0});
        vector<bool> ip(4000,false);
        REP(i,n) {
            ll e,p,q;
            cin >> e >> p >> q;
            e--;
            if (ip[e]) {
                s[e].se += p*q;
            }
            else {
                s[e] = make_pair(i,p*q);
                ip[e] = true;
            }
        }
        vector<pair<int,int>> ans;
        REP(i, 4000) {
            if (s[i].se >= 1000000) {
                ans.pb({s[i].fi, i+1});
            }
        }
        sort(ALL(ans));
        REP(i,ans.size()) cout << ans[i].se << endl;
        if (ans.size() == 0) cout << "NA" << endl;
    }
    return 0;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const long double PI = acos(-1);

using Edge = pair<int, ll>;
using Graph = vector<vector<Edge>>;

Graph G;
vector<ll> dist;

void dfs(int cur, int pre, ll sum) {
	dist[cur] = sum;

	for (auto to : G[cur]) {
		if (to.first != pre) {
			dfs(to.first, cur, sum + to.second);
		}
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	int n;
	cin >> n;

	G.resize(n);

	rep(i, n - 1) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		G[a].push_back(make_pair(b, c));
		G[b].push_back(make_pair(a, c));
	}

	int q, k;
	cin >> q >> k;
	k--;

	dist.resize(n, 0);

	dfs(k, -1, 0);

	rep(i, q) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		out(dist[x] + dist[y]);
	}

	return 0;
}


#include <bits/stdc++.h>

int main(void) {

  int n;
  int q;
  int S[16384];
  int T[512];

  std::cin >> n;
  for(int i = 0; i < n; ++i) {
    std::cin >> S[i];
  }
  std::cin >> q;
  for(int i = 0; i < q; ++i) {
    std::cin >> T[i];
  }

  int ans = 0;
  for(int i = 0; i < q; ++i) {
    int num = T[i];
    for(int j = 0; j < n; ++j) {
      if( S[j] == num ) {
        ans += 1;
        break;
      }
    }
  }

  std::cout << ans << std::endl;

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e15;

#include <math.h>
#define PI 3.14159265358979323846264338327950L
const int mxN = 1e9 + 7;

char s[100005];
long long dp[100005][13];

int minimum_Color(vector<int> a, int n) {
    multiset<int> last;

    for (int i = 0; i < n; i++) {
        auto it = last.lower_bound(a[i]);
        if (it == last.begin()) {
            last.insert(a[i]);
        }
        else {
            it--;
            last.erase(it);
            last.insert(a[i]);
        }
    }
    return last.size();
}

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


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

int main(){
 string s1,s2;
  cin>>s1>>s2;
  cout<<s2+s1<<endl;
}

#include<stdio.h>
	int main(){
		int A,B,C;

		scanf ("%d",&A);
		scanf ("%d",&B);
		scanf ("%d",&C);

		if (A==B && A==C && B==A && B==C && C==A && C==B){
			printf ("No\n");
		}else if (A==B||A==C||B==A||B==C||C==A||C==B){
			printf("Yes\n");
		}else {
			printf ("No\n");
		}
	}


#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <limits.h>
#include <string>
#include <string.h>
#include <sstream>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>

using namespace std;

typedef long long ll;

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

  printf("%d\n", (int)pow( num, 3 ));
  return 0;
}

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

int main()
{
	string s; cin>>s;
	int x=stoi(s);
	int y=x*x*x;
	cout<<to_string(y)<<endl;
}


#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <random>
#include <tuple>
#include <iomanip>
#include <cstring>

using namespace std;

typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n-1); i >= 0; i--)
#define pb push_back
#define f first
#define s second
const ll INFL = 1LL << 60;//10^18 = 2^60
const int INF = 1 << 30;//10^9
ll MOD = 1000000007;
//ll MOD  = 998244353;
vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};

ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}
ll pow_mod(ll x, ll k){
  x %= MOD; x += MOD; x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

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

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

ll kai_mod(ll x){
  if(x == 0) return 1;
  return x * kai_mod(x-1) % MOD;
}

/*
//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}
*/

//MODなしバージョン
vector<vector<ll>> memo(60, vector<ll>(60, -1));
//コンビネーション
ll comb(int n, int k){
    if(memo[n][k] != -1) return memo[n][k];
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    if(n == 0 || k == 0) return 1;
    return memo[n][k] = comb(n-1, k) + comb(n-1, k-1);
}

ll N, M;
string S, T;
ll solve(string blue, string red){
  //Tを使って、red, blueを作る。
  if(blue.size() < red.size()) swap(red, blue);

  ll rl = red.size();
  ll dp[N+1][rl+1];
  rep(i, N+1){
    rep(j, rl + 1){
      dp[i][j] = 0;
    }
  }
  dp[0][0] = 1;
  rep(i, N){
    rep(j, rl + 1){
      if(j != rl && T[i] == red[j]){
        dp[i+1][j+1] += dp[i][j];
      }
      if(T[i] == blue[i-j]){
        dp[i+1][j] += dp[i][j];
      }
    }
  }
  return dp[N][rl];
}

int main(){
  cin >> N >> S;
  T = S;
  reverse(T.begin(), T.end());
  ll ans = 0;
  rep(i, (1 << N)){
    string red = "", blue = "";
    rep(j, N){
      if((i >> j) & 1) red += S[j];
      else blue += S[j];
    }
    ans += solve(red, blue);
  }
  cout << ans << endl;
}

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

int main() {
  int n;
  string str;

  cin >> n;
  cin >> str;

  vector<int> vW(n+1,0),vE(n+1,0);

  for(int i=0;i<n;i++){
    vW[i+1]+=vW[i];
    if(str[i]=='W') vW[i+1]++;
    vE[i+1]+=vE[i];
    if(str[i]=='E') vE[i+1]++;
  }

  int ans=999999999;
  int now;

  for(int i=0;i<n;i++){
    now=vW[i]+(vE[n]-vE[i+1]);
    if(ans>now) ans=now;
  }

  cout << ans << endl;
}


#include <iostream>

using namespace std;

int main(){
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	if(a+b < c+d) cout << "Right";
	else if(a+b > c+d) cout << "Left";
	else cout << "Balanced";
	cout << endl;
	return 0;
}


#include <stdio.h>
#include <vector>
#include <queue>
using namespace std;
struct side{
    int n;
    int m;
    int l;
};
side sides[100000];
void mergesort(int l,int r){
    if(l==r)return;
    side temp;
    if(l==r-1){
        if(sides[l].l>sides[r].l){
            temp=sides[l];
            sides[l]=sides[r];
            sides[r]=temp;
        }
        return;
    }
    int mid=(l+r)/2,now=0;
    side b[r-l+1];
    mergesort(l,mid-1);
    mergesort(mid,r);
    for(int i=0;i<=r-l;i++){
        if(sides[i+l-now].l<sides[mid+now].l){
            b[i]=sides[i+l-now];
            if(i+l-now==mid-1){
                for(i++;i<=r-l;i++){
                    b[i]=sides[mid+now];
                    now++;
                }
            }
        }
        else{
            b[i]=sides[mid+now];
            now++;
            if(mid+now>r){
                for(i++;i<=r-l;i++)
                    b[i]=sides[i+l-now];
            }
        }
    }
    for(int i=0;i<=r-l;i++)
        sides[i+l]=b[i];
}
int main(){
    int n,m,a,ans=0,c=1;
    bool tree[10000];
    scanf("%d%d",&n,&m);
    if(m==0){
        printf("0\n");
        return 0;
    }
    tree[0]=true;
    for(int i=1;i<n;i++){
        tree[i]=false;
    }
    for(int i=0;i<m;i++){
        scanf("%d%d%d",&sides[i].n,&sides[i].m,&sides[i].l);
    }
    mergesort(0,m-1);
    while(c<n){
        a=0;
        while(tree[sides[a].n]==tree[sides[a].m])a++;
        ans+=sides[a].l;
        tree[sides[a].n]=tree[sides[a].m]=true;
        c++;
    }
    printf("%d\n",ans);
}

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

struct Edge {
	int start;
	int target;
	int weight;
};

class UnionFind {
	std::vector<int> m_nodes;

public:
	UnionFind(size_t size) : m_nodes(size) {
		for (size_t i = 0; i < size; i++)
			m_nodes[i] = i;
	}

	int find(int index) {
		int ret = m_nodes[index];
		if (ret == index) return ret;

		ret = find(ret);
		m_nodes[index] = ret;
		return ret;
	}

	void merge(int x, int y) {
		x = find(x);
		y = find(y);
		m_nodes[x] = y;
	}
};

int main()
{
	int v, e;
	std::cin >> v >> e;

	std::vector<Edge> edges;
	edges.reserve(e);

	for (int i = 0; i < e; i++) {
		Edge edge;
		std::cin >> edge.start >> edge.target >> edge.weight;
		edges.push_back(edge);
	}

	std::sort(edges.begin(), edges.end(), [](Edge& x, Edge& y) { return x.weight < y.weight; });

	UnionFind uf(v);
	uint_least64_t weight = 0;

	for (Edge& edge : edges) {
		int s = uf.find(edge.start);
		int t = uf.find(edge.target);

		if (s != t) {
			uf.merge(s, t);
			weight += edge.weight;
		}
	}

	std::cout << weight << std::endl;

	return 0;
}


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

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

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

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

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

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

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

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

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

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

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

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

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

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

#include <bits/stdc++.h>
#include <cmath>

const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<string, vector<string>, greater<string> > PQ_ASK;

#include <iostream>
#include <vector>

using namespace std;

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

    vector<int> numbers(n);
    rep(i, n) cin >> numbers[i];

    if (numbers.front() != 0) {
        cout << -1 << endl;
        ret();
    }

    vector<int> dp(n);
    dp.back() = numbers.back();
    for (int i = n - 2; i >= 0; i--) {
        dp[i] = max(numbers[i], dp[i + 1] - 1);
    }

    rep(i, n) {
        if (numbers[i] < dp[i]) {
            cout << -1 << endl;
            ret();
        }
    }
    ll ans = 0;
    rep(i, n - 1) {
        if (dp[i] > dp[i + 1] - 1) {
            ans += dp[i];
        }
    }
    ans += numbers.back();

    cout << ans << endl;

}


#include <bits/stdc++.h>

using namespace std;

const int N = (int) 5e5 + 55;

int fen[N];

void upd(int x, int y) {
  while (x < N) {
    fen[x] += y;
    x |= (x + 1);
  }
}

int get(int x) {
  int res = 0;
  while (x >= 0) {
    res += fen[x];
    x = (x & (x + 1)) - 1;
  }
  return res;
}

int res[N];
vector<pair<int, int>> vec[N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  vector<int> c(n);
  for (int i = 0; i < n; i++) {
    cin >> c[i];
    --c[i];
  }
  for (int i = 0; i < q; i++) {
    int l, r;
    cin >> l >> r;
    --l; --r;
    vec[r].emplace_back(l, i);
  }
  vector<int> last(n, -1);
  for (int i = 0; i < n; i++) {
    if (last[c[i]] != -1) {
      upd(last[c[i]], -1);
    }
    last[c[i]] = i;
    upd(i, 1);
    for (auto u : vec[i]) {
      res[u.second] = get(i) - get(u.first - 1);
    }
  }
  for (int i = 0; i < q; i++) {
    cout << res[i] << '\n';
  }
  return 0;
}

#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 10;

int n, m, siz, num;
int w[N], cnt[N], belong[N];
int now, ans[N];

struct query{
	int l, r, id;
}q[N];

//bool cmp(query a, query b)
//{
//	return (belong[a.l] ^ belong[b.l]) ? belong[a.l] < belong[b.l] : ((belong[a.l] & 1) ? a.r < b.r : a.r > b.r);
//}
bool cmp(query a, query b) {
    return (belong[a.l] ^ belong[b.l]) ? belong[a.l] < belong[b.l] : ((belong[a.l] & 1) ? a.r < b.r : a.r > b.r);
}

void add(int pos)
{
	if(!cnt[w[pos]]) ++now;
	++cnt[w[pos]];
}

void del(int pos)
{
	--cnt[w[pos]];
	if(!cnt[w[pos]]) --now;
}

int main()
{
	scanf("%d%d", &n, &m);
	siz = sqrt(n);
	num = ceil((double) n / siz);
//	cout << num << endl;
	for (int i = 1; i <= num; i ++)
	{
		for (int j = (i - 1) * siz + 1; j <= i * siz; j ++)
		{
			belong[j] = i;
		}
	}
	for (int i = 1; i <= n; i ++) scanf("%d", &w[i]);
	for (int i = 1; i <= m; i ++)
	{
		q[i].id = i;
		scanf("%d%d", &q[i].l, &q[i].r);
	}
	sort(q + 1, q + m + 1, cmp);
	int l = 1, r = 0;
	for (int i = 1; i <= m; i ++)
	{
		int ql = q[i].l, qr = q[i].r;
		while(l < ql) del(l ++);
		while(l > ql) add(-- l);
		while(r < qr) add(++ r);
		while(r > qr) del(r --);
		ans[q[i].id] = now;
	}
	for (int i = 1; i <= m; i ++)
		printf("%d\n", ans[i]);
}


#include <bits/stdc++.h>

void print_array(int A[], int N) {
  for(int i = 0; i < N-1; ++i) {
    std::cout << A[i] << " ";
  }
  std::cout << A[N-1] << std::endl;
  return;
}

int count;

void bubbleSort(int A[], int N) {
  bool flag = true;
  while( flag ) {
    flag = false;
    for(int j = N-1; j >= 1; --j) {
      if( A[j] < A[j-1] ) {
        std::swap(A[j], A[j-1]);
        flag = true;
        count += 1;
      }
    }
  }
  return;
}

int main(void) {

  int N;
  int A[128];

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

  bubbleSort(A, N);

  print_array(A, N);
  std::cout << count << std::endl;

  return 0;
}

#define LOCAL

#undef _GLIBCXX_DEBUG

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

#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define LLINF 1e18
#define INF (int)1e9+1

// Copied from Gennady-Korotkevich's template

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
	return '"' + s + '"';
}

string to_string(const char* s) {
	return to_string((string)s);
}

string to_string(bool b) {
	return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
	bool first = true;
	string res = "{";
	for (int i = 0; i < static_cast<int>(v.size()); i++) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(v[i]);
	}
	res += "}\n";
	return res;
}

template <size_t N>
string to_string(bitset<N> v) {
	string res = "";
	for (size_t i = 0; i < N; i++) {
		res += static_cast<char>('0' + v[i]);
	}
	return res;
}

template <typename A>
string to_string(A v) {
	bool first = true;
	string res = "{";
	for (const auto& x : v) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(x);
	}
	res += "}\n";
	return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
	return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

template <typename A, typename B, typename C, typename D, typename E>
string to_string(tuple<A, B, C, D, E> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + "," + to_string(get<4>(p)) + ")";
}

void debug_out() {
	cerr << endl;
}

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

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

// End of Gennady-Korotkevich's template

using llong = long long;
using PII = pair<int, int>;

const llong MOD = 998244353LL;

int main() {
	IOS;
	bool suc = true;
	int n; cin >> n; set<int > a;
	for (int i = 0; i < n; i++) {
		int k; cin >> k;
		if (a.count(k)) suc = false;
		a.insert(k);
	}
	if (suc) cout << "YES";
	else cout << "NO";
}


#include <bits/stdc++.h>
using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define int long long
  #define endl "\n"
  #define all(v) v.begin(),v.end()
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  const int N = 200005;

  int dp[101][101];

int32_t main()
{

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    IOS

    string s;
    cin >> s;

    set<char> ss(s.begin(),s.end());

    for(int i = 0; i < 26; i++)
    {
      char ch = 'a' + i;
      if(!ss.count(ch))
      {
        cout << ch;
        return 0;
      }
    }

    cout << "None";
    return 0;
}

#include <cstdio>

char S[101010];

int main()
{
	scanf("%s", S);

	bool app[26];
	for (int i = 0; i < 26; ++i) {
		app[i] = false;
	}
	for (int i = 0; S[i] != '\0'; ++i) {
		app[S[i] - 'a'] = true;
	}
	for (int i = 0; i < 26; ++i) {
		if (!app[i]) {
			printf("%c\n", (char)(i + 'a'));
			return 0;
		}
	}
	puts("None");
	return 0;
}


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

int main(){
    int H, W;
    cin >> H >> W;
    vector<vector<int>> S(H);
    for(int i=0; i<H; i++){
        string s;
        cin >> s;
        for(int j=0; j<W; j++) S[i].push_back(s[j] == '#');
    }
    int ans = max(H, W);
    vector<int> h(W);
    for(int i=0; i<H; i++){
        stack<pair<int, int>> st;
        for(int j=0; j<W; j++){
            int pos = j;
            while(st.size() && st.top().first > h[j]){
                auto& p = st.top();
                int res = (p.first+1) * (j-p.second+1);
                ans = max(ans, res);
                pos = p.second;
                st.pop();
            }
            if(st.size() == 0 || st.top().first < h[j]) st.push({h[j], pos});
        }
        if(i<H-1) for(int j=0; j<W-1; j++){
            if((S[i][j] + S[i+1][j] + S[i][j+1] + S[i+1][j+1]) % 2){
                h[j] = 0;
            }else{
                h[j]++;
            }
        }
    }
    cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
static const long long INF=1000000000000000000;

int main(){
  long long N;
  long long K;
  cin>>N>>K;
  long long X[N];

  for(long long i=0;i<N;i++){
    cin>>X[i];
  }
  long long ans=INF;
  for(long long i=0;i<N-K+1;i++){
    ans=min(ans,abs(X[i])+abs(X[i]-X[i+K-1]));
    ans=min(ans,abs(X[i+K-1])+abs(X[i]-X[i+K-1]));
  }
  cout<<ans<<endl;
  return 0;
}


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

int min(int a, int b, int c) {
    if (a < b) {
        if (a < c) {
            return a;
        } else {
            return c;
        }
    } else {
        if (b < c) {
            return b;
        } else {
            return c;
        }
    }
}

int level(int j, int o, int i) {
    int c = min(j, o, i);
    if (c == o) return c;
    else return 0;
}

int main() {
    string s; cin >> s;
    int j_count = 0, o_count = 0, i_count = 0;
    int count = 0;
    char state = 'f';  // f: first, J: J, O: O, I: I
    for (string::iterator p = s.begin(); p != s.end(); p++) {
        switch (state) {
            case 'f':
                if (*p == 'J') {
                    j_count = 1;
                    state = 'J';
                }
                break;
            case 'J':
                if (*p == 'J') {
                    j_count++;
                } else if (*p == 'O') {
                    o_count = 1;
                    state = 'O';
                } else {
                    j_count = 0;
                    o_count = 0;
                    i_count = 0;
                    state = 'f';
                }
                break;
            case 'O':
                if (*p == 'O') {
                    o_count++;
                } else if(*p == 'I') {
                    i_count = 1;
                    state = 'I';
                    if (p == s.end()-1) {
                        int _count = level(j_count, o_count, i_count);
                        if (count < _count) {
                            count = _count;
                        }
                    }
                } else {
                    if (*p == 'J') {
                        j_count = 1;
                        o_count = 0;
                        i_count = 0;
                        state = 'J';
                    } else {
                        j_count = 0;
                        o_count = 0;
                        i_count = 0;
                        state = 'f';
                    }
                }
                break;
            case 'I':
                if (*p == 'I') {
                    i_count++;
                    if (p == s.end()-1) {
                        int _count = level(j_count, o_count, i_count);
                        if (count < _count) {
                            count = _count;
                        }
                    }
                }
                if (*p != 'I') {
                    int _count = level(j_count, o_count, i_count);
                    if (count < _count) {
                        count = _count;
                    }
                    if (*p == 'J') {
                        state = 'J';
                        j_count = 1;
                        o_count = 0;
                        i_count = 0;
                    } else {
                        state = 'f';
                        j_count = 0;
                        o_count = 0;
                        i_count = 0;
                    }
                }
                break;
        }
    }
    cout << count << endl;
    return 0;
}

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>

int main() {
    std::string s; std::cin >> s;
    int n = s.size();
    if (n & 1) {
        std::cout << "No" << std::endl;
        return 0;
    }
    for (int i = 0; i < n - 1; i += 2) {
        if (s[i] != 'h' || s[i + 1] != 'i') {
            std::cout << "No" << std::endl;
            return 0;
        }
    }
    std::cout << "Yes" << std::endl;
    return 0;
}