#include <bits/stdc++.h>

using namespace std;

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

	long long best = 0;
	long long curr = 0;

	for (long long i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			long long mul = n / i;

			long long digs_i = floor(log10(i) + 1);
			long long digs_mul = floor(log10(mul) + 1);

			curr = max(digs_i, digs_mul);
			best = max(best, curr);
		}
	}

	cout << curr << endl;

}

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define erep(i,N) for(int i = N - 1; i >= 0; i--)
const ll INF = 1000000000;
//const ll MOD = 1000000007;
const ld PI = (acos(-1));
using Graph = vector<vector<int>>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true;} return false;}
typedef pair<int, int> P;
typedef pair<ll,ll> PLL;
double rad(double a) {return a * 180 / PI;}

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

//dpTable
int dp[100050];

int main(){
    ll N;
    cin >> N;
    int sqrtN = sqrt(N);
    int A,B;
    for (int i = sqrtN; i >= 1; i--) {
        if (N % i == 0) {
            A = i;
            B = N / i;
            break;
        }
    }
    int cntA = 0,cntB = 0;
    while (A != 0) {
        A /= 10;
        cntA++;
    }
    while (B != 0) {
        B /= 10;
        cntB++;
    }
    cout << max(cntA,cntB) << endl;
    return 0;
}


#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int a[3];
    cin>>a[0]>>a[1]>>a[2];
  	sort(a,a+3);
    int k;
    cin>>k;
    cout<<a[0]+a[1]+(a[2]<<k);
}

#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
#include <iomanip>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int digit(int n){
   if(n < 10)  return n;
   return digit(n/10) + n%10;
}
int main(){
  int A,B,C,K;
  cin>>A>>B>>C>>K;

  cout<<max({A,B,C})*pow(2,K)+A+B+C-max({A,B,C});
return 0;}


#include<bits/stdc++.h>
using namespace std;
const int N=1e6+7;
#define ll long long
char a[N];
int main(){
    int n,q,k;
    scanf("%d\n",&n);
    scanf("%s",a);
    scanf("%d",&q);
    while(q--){
        scanf("%d",&k);
        ll nowd=0,nowm=0,cnt=0;
        ll sum=0;
        for(int i=0;i<n;i++){
            if(i-k>=0&&a[i-k]=='D'){
                nowd--;
                cnt-=nowm;
            }
            else if(i-k>=0&&a[i-k]=='M'){
                nowm--;
            }
            if(a[i]=='D')nowd++;
            if(a[i]=='M'){
                nowm++;
                cnt+=nowd;
            }
            if(a[i]=='C')sum+=cnt;
        }
        printf("%lld\n",sum);
    }
    return 0;
}

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


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

#define int long long

void read(int &x) {
    x=0;int f=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
    for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
}

void print(int x) {
    if(x<0) putchar('-'),x=-x;
    if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');}

#define lf double
#define ll long long

#define pii pair<int,int >
#define vec vector<int >

#define pb push_back
#define mp make_pair
#define fr first
#define sc second

#define data asd09123jdf02i3h

#define FOR(i,l,r) for(int i=l,i##_r=r;i<=i##_r;i++)

const int maxn = 1e6+10;
const int inf = 1e9;
const lf eps = 1e-8;
const int mod = 1e9+7;

int sta[maxn],top,a[maxn],n;

signed main() {
    read(n);
    for(int i=1;i<=n;i++) read(a[i]);
    int ans=0,lst=n+1;
    for(int i=n;i;i--) {
        int x=a[lst]-(lst-i);
        if(a[i]==x) continue;
        if(a[i]<x||a[i]>=i) return puts("-1"),0;
        ans+=a[i],lst=i;
    }
    write(ans);
    return 0;
}

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

int people[100005][4];
int sum[100005];

int main(){
  int N;
  scanf("%d", &N);
  std::vector<int > A(N);
  for (int i=0; i<N; i++){
    scanf("%d", &A[i]);
  }
  int prev=0;
  long long ans=0;
  if (A[0]!=0){
    std::cout << "-1" << std::endl;
    return 0;
  }
  for (int i=1; i<N; i++){
    if (A[i]>prev+1) {
      std::cout << "-1" << std::endl;
      return 0;
    } else if (A[i]==prev+1){
      ans++;
    } else {
      ans+=A[i];
    }
    prev = A[i];
  }
  std::cout << ans <<std::endl;
  return 0;
}


#include<iostream>
using namespace std;
int member[1000];
bool cp[1000][1000];
int main(){
  int n,q;
  while(cin>>n>>q,n){
    for(int i=0;i<1000;i++)member[i]=0;
    for(int i=0;i<1000;i++)
      for(int j=0;j<1000;j++)cp[i][j]=0;
    for(int i=0;i<n;i++){
      int num;
      cin>>num;
      int tmp;
      for(int j=0;j<num;j++){
	cin>>tmp;
	cp[i][tmp-1]=true;
      }
    }
    for(int i=0;i<n;i++){
      for(int j=0;j<1000;j++){
	if(cp[i][j]==true)member[j]++;
      }
    }
    int M=0;
    int ans;
    for(int i=999;i>=0;i--){
      M=max(member[i],M);
      if(member[i] == M){
	ans = i+1;
      }
    }

    if(M>=q){
      cout <<ans << endl;
    }else{
      cout << 0 << endl;
    }
  }
  return 0;
}

#include<iostream>
using namespace std;
int dy[4]={-1,0,1,0};
int dx[4]={0,1,0,-1};
int t[200][200],vd[200][200];
int W,H,sx,sy,gx,gy,n,key;

bool inField(int y,int x){
  if(y<0||y>=H)return false;
  if(x<0||x>=W)return false;
  return true;
}

bool solve(int y,int x){
  if(y==gy&&x==gx)return true;
  for(int i=0;i<4;i++){
    int ny=y+dy[i],nx=x+dx[i];
    if(!inField(ny,nx))continue;
    if(t[ny][nx]!=key)continue;
    if(vd[ny][nx]==1)continue;
    vd[ny][nx]=1;
    if( solve(ny,nx) ) return true;
  }
  return false;
}

void init(){
  for(int i=0;i<200;i++)
    for(int j=0;j<200;j++)
      t[i][j]=vd[i][j]=-1;
}

int main(){
  int a,b,x,y;
  while(cin>>W>>H){
    if(W==0&&H==0)break;
    init();
    cin>>sx>>sy>>gx>>gy>>n;
    sx--,sy--,gx--,gy--;
    for(int k=0;k<n;k++){
      cin>>a>>b>>x>>y;
      x--,y--;
      for(int i=0;i<(b==0?2:4);i++)
	for(int j=0;j<(b==0?4:2);j++)
	  t[y+i][x+j]=a;
    }
    key=t[sy][sx];
    cout<<(key!=-1&&solve(sy,sx)?"OK":"NG")<<endl;
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
// type
typedef long long ll;
typedef long double ld;
// loop
//#define For(i, l, r, x)     for (int i = l; i < r; i+=x)
//#define ForE(i, l, r, x)    for (int i = l; i <= r; i+=x)
//#define Ford(i, r, l)       for (int i = r; i > l; i--)
//#define FordE(i, r, l)      for (int i = r; i >= l; i--)
//#define Fora(i, a)          for (auto i : a)
// I/O
#define FAST_IO             std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
//#define PrintV(a)           Fora(ii, a) cout << ii << ' '; cout << rl;
//#define PrintVl(a)          Fora(ii, a) cout << ii << rl;
//#define PrintA(a, l, r)     for (int ii = l; ii <= r; ii++) cout << a[ii] << ' '; cout << rl;
//#define PrintAl(a, l, r)    for (int ii = l; ii <= r; ii++) cout << a[ii] << rl;
//#define Ptest(x)            return cout << x, 0;
#define setpre(n)           fixed << setprecision(n)
// pair
#define F                   first
#define S                   second
#define pii                 pair<int, int>
#define pll                 pair<ll, ll>
#define pdd                 pair<ld, ld>
// vector & !!?(string)
#define eb                  emplace_back
#define pb                  push_back
#define all(a)              a.begin(), a.end()
#define rall(a)             a.rbegin(), a.rend()
#define sz(a)               a.size()
#define len(a)              a.length()
// geometry calc
#define pi                  acos(-1.0)
#define g_sin(a)            sin(a*pi/180)
#define g_cos(a)            cos(a*pi/180)
#define g_tan(a)            tan(a*pi/180)
// set val
#define ms0(a)              memset(a,        0, sizeof(a));
#define ms1(a)              memset(a,        1, sizeof(a));
#define msn1(a)             memset(a,       -1, sizeof(a));
#define msinf(a)            memset(a, 0x3f3f3f, sizeof(a));
// constant
const int mod1 = 998244353, mod = 1e9+7;
const int MAXN = 100005, MAX_M = 200010;
// code
//#define int long long

int x[MAXN];
int sps[MAXN][20];
int n, q, l;
void Solve() {
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> x[i];
    cin >> l >> q;
    int jump = n;
    for (int i = n; i >= 1; i--){
		while(x[jump] - x[i] > l) jump--;
		sps[i][0] = jump;
    }
    for (int d = 1; d <= 19; d++){
        for (int i = 1; i + (1 << d) <= n; i++)
            sps[i][d] = sps[ sps[i][d-1] ][d-1];
    }
    while (q--){
        int a, b, ans = 0;
        cin >> a >> b;
        if (a > b) swap(a, b);
        for (int d = 19; d >= 0; d--){
            if (sps[a][d] < b && sps[a][d]){
                a = sps[a][d];
                ans += (1 << d);
            }
        }
        ans ++;
        cout << ans << endl;
    }
}

signed main(){
    FAST_IO;
    int TC = 1;
	//cin >> TC;
    while(TC--) Solve();
    return 0;
}

#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

string S[100];
int main()
{
	int A, B;
	cin >> A >> B;
	for (int i = 0; i < 50; i++) {
		for (int j = 0; j < 100; j++) {
			S[i].push_back('.');
		}
	}
	for (int i = 50; i < 100; i++) {
		for (int j = 0; j < 100; j++) {
			S[i].push_back('#');
		}
	}
	A--; B--;
	int i = 99, j = 2;
	while (A > 0) {
		S[i][j] = '.';
		j += 4;
		if (j >= 100) {
			i--;
			j = i % 2 * 2;
		}
		A--;
	}
	i = 0; j = 0;
	while (B > 0) {
		S[i][j] = '#';
		j += 4;
		if (j >= 100) {
			i++;
			j = i % 2 * 2;
		}
		B--;
	}
	cout << 100 << " " << 100 << endl;
	for (int i = 0; i < 100; i++) {
		cout << S[i] << endl;
	}
}


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

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,int> plli;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()

const ll mod = 1e9 + 7;
const ll INF = 1<<30;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

int n, k;

struct edge{int to, cost;};

vector<ll> dijkstra(int s, int n, vector<vector<edge>>& g){
    priority_queue<plli, vector<plli>, greater<plli>> que;
    vector<ll> d(n, LLONG_MAX/10); d[s] = 0;
    que.push(plli(0, s));

    while (!que.empty()){
        plli p = que.top();que.pop();
        int fr = p.second;
        if (d[fr] < p.first) continue;
        for (edge e: g[fr]){
            if (d[e.to] > d[fr] + e.cost){
                d[e.to] = d[fr] + e.cost;
                que.push(plli(d[e.to], e.to));
            }
        }
    }
    return d;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while (true) {
        cin >> n >> k;
        if (n == 0) break;
        vector<vector<edge>> g(100 + 5);
        rep(i, k) {
            int  a, b, c, d, e, com;
            cin >> com;
            if (com == 0) {
                cin >> a >> b;
                a--; b--;
                vector<ll> dist = dijkstra(a, n, g);
                if (dist[b] == LLONG_MAX / 10) cout << -1 << endl;
                else cout << dist[b] << endl;
            }
            else {
                cin >> c >> d >> e;
                c--; d--;
                g[c].push_back(edge{d, e});
                g[d].push_back(edge{c, e});
            }
        }
    }
}

#include<iostream>
#include<set>

using namespace std;

int main() {
  int n;
  while(cin>>n && n!=0) {
    set<pair<int, int> > mySet;
    for(int i=0; i<n; i++) {
      int x, y;
      cin>>x>>y;
      mySet.insert(make_pair(x, y));
    }
    int m;
    cin>>m;
    int nowX = 10, nowY = 10;
    string dir;
    int move;
    for(int i=0; i<m; i++) {
      cin>>dir;
      cin>>move;
      for(int j=0; j<move; j++) {
	if(dir == "N") {
	  nowY++;
	}
	else if(dir == "S") {
	  nowY--;
	}
	else if(dir == "E") {
	  nowX++;
	}
	else if(dir == "W") {
	  nowX--;
	}
	if(mySet.find(make_pair(nowX, nowY)) != mySet.end()) {
	  mySet.erase(make_pair(nowX, nowY));
	}
      }
    }
    if(mySet.empty()) {
      cout<<"Yes"<<endl;
    }
    else {
      cout<<"No"<<endl;
    }
  }
}


#include<stdio.h>
#include<string.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
static inline void PUT(char c)
{
  static char buf[1<<15],*ptr=buf;
  if(ptr==buf+strlen(buf)||c==0){fwrite(buf,1,ptr-buf,stdout),ptr=buf;}*ptr++=c;
}
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void OUT(int a)
{
  if(a<0)PUT('-'),a=-a;
  int d[40],i=0;do{d[i++]=a%10;}while(a/=10);
  while(i--){PUT(d[i]+48);}PUT('\n');
}
static inline int Min(int a,int b){return a<b?a:b;}
const int INF=0x3f3f3f3f;
int M,seg[800002],tag[800002];
static inline void upt(int x){seg[x]=Min(seg[x<<1],seg[x<<1|1]);}
static inline void nodeCover(int x,int l,int val){seg[x]=l-val;tag[x]=val;}
static inline void dnt(int x,int l,int r)
{
  if(tag[x])
  {
    int mid=(l+r)/2;
    nodeCover(x<<1,l,tag[x]);nodeCover(x<<1|1,mid+1,tag[x]);
    tag[x]=0;
  }
}
static inline void segCover(int u,int v,int t,int x=1,int l=1,int r=M)
{
  if(u<=l&&r<=v){nodeCover(x,l,t);return;}
  dnt(x,l,r);int mid=(l+r)/2;
  if(u<=mid){segCover(u,v,t,x<<1,l,mid);}
  if(v>mid){segCover(u,v,t,x<<1|1,mid+1,r);}
  upt(x);
}
static inline int segQuery(int p,int x=1,int l=1,int r=M)
{
  if(l==r){return p-seg[x];}dnt(x,l,r);int mid=(l+r)/2;
  return p<=mid?segQuery(p,x<<1,l,mid):segQuery(p,x<<1|1,mid+1,r);
}
int main()
{
  int N=IN()+1,count=0,cur=1,left,right;M=IN();
  while(N--)
  {
    left=IN(),right=IN();count++;
    if(cur>=left&&cur<=right)segCover(cur,right,-INF),cur=right+1;
    else if(cur<left)segCover(left,right,segQuery(left-1));
    if(cur>M){puts("");while(N--){puts("-1");}return 0;}
    OUT(seg[1]+count);if(N==1){return 0;}
  }
}

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>

using namespace std;

#define NIL -1
#define N 500001

//struct Node{
//	int val;
//	Node *p, *l, *r;
//};

struct Node {
	int val;
	Node *p, *l, *r;
	Node(int v) :val(v), p(NULL), l(NULL), r(NULL){}
	Node() :val(0), p(NULL), l(NULL), r(NULL){}
};

Node T[N];
int D[N], H[N];

Node *root;

void insert(int k){
	Node *y = NULL;
	Node *x = root;
	Node *z = new Node(k);

	while (x != NULL && x->val != k){
		y = x;
		if (k > x->val) x = x->r;
		else x = x->l;
	}
	z->p = y;
	if (y == NULL) root = z;
	else{
		if (k < y->val) y->l = z;
		else y->r = z;
	}
}

Node *find(int val){
	Node *p = root;
	while (p != NULL && p->val != val) {
		if (val < p->val) p = p->l;
		else p = p->r;
	}
	return p;
}

void ino(Node *p){
	if (p == NULL) return;
	ino(p->l);
	printf(" %d", p->val);
	ino(p->r);
}

void preo(Node *p){
	if (p == NULL) return;
	printf(" %d", p->val);
	preo(p->l);
	preo(p->r);
}

Node *mi(Node *z){
	while (z->l != NULL) z = z->l;
	return z;
}

Node *suc(Node *z){
	return mi(z->r);
	//if (z->r != NULL) return mi(z->r);
	//Node *y = z->p;
	//while (y != NULL && z == y->r) {
	//	z = y;
	//	y = y->p;
	//}
	//return y;
}

void del(Node *z){
	Node *y = NULL;
	Node *x = NULL;

	if (NULL == z->l || NULL == z->r) y = z;
	else y = suc(z);

	if (NULL != y->l) x = y->l;
	else x = y->r;

	if (NULL != x) x->p = y->p;

	if (NULL == y->p) root = x;
	else {
		if (y == y->p->l) y->p->l = x;
		else y->p->r = x;
	}

	if (y != z) z->val = y->val;
	delete y;
}

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

	int val;
	string com;
	for (int i = 0; i < n; ++i) {
		cin >> com;
		if (com[0] == 'f'){
			cin >> val;
			Node *p = find(val);
			cout << ((p == NULL) ? "no" : "yes") << endl;
		}
		else if (com[0] == 'i'){
			cin >> val;
			insert(val);
		}
		else if (com[0] == 'p'){
			ino(root); cout << "\n";
			preo(root); cout << "\n";
		}
		else if (com[0] == 'd'){
			cin >> val;
			del(find(val));
		}
	}

	return 0;
}

//yes
//yes
//yes
//no
//no
//no
//yes
//yes
//1 2 3 7 8 22
//8 2 1 3 7 22
//1 2 8 22
//8 2 1 22


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

int main() {
  int name1,name2,name3;
  cin >>name1>>name2;
  name3=name2*2-name1;
  cout<<name3<<endl;
}

#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Thousand "Hello World"
    int R, G;
    cin >> R >> G;
    if (R + ((G - R) * 2) / 2 == G){
        cout <<R + ((G - R) * 2) << endl;
    }
    else{
        cout << (R - G) * -1 << endl;
    }
}


#include<iostream>
using namespace std;
#define MAX 100
static const int dx[4] = {1, 0, -1, 0};
static const int dy[4] = {0, -1, 0, 1};
int w, h, sx, sy, gx, gy, G[MAX+2][MAX+2];
bool dfs( int x, int y, int color ){
 if ( color == 0 || G[x][y] != color ) return false;
 if ( x == gx && y == gy ) return true;
 G[x][y] = 0;
 for ( int r = 0; r < 4; r++ ){
if ( dfs(x + dx[r], y + dy[r], color) ) return true;
 }
 return false;
}
main(){
 int n, c, d, px, py, ww, hh;
 while( cin >> w >> h && w ){
cin >> sx >> sy >> gx >> gy >> n;
for ( int y = 0; y < h+2; y++ )
 for ( int x = 0; x < w+2; x++ ) G[x][y] = 0;
for ( int i = 1; i <=n; i++ ){
 cin >> c >> d >> px >> py;
 if ( d == 0 ) { ww = 4; hh = 2; }
 else { ww = 2; hh = 4; }
 for ( int y = 0; y <= hh-1; y++ )
for ( int x = 0; x <= ww-1; x++ ) G[px+x][py+y] = c;
}
if ( dfs(sx, sy, G[sx][sy]) ) cout << "OK" << endl;
else cout << "NG" << endl;
 }
}

#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

constexpr ll mod = 1e9 + 7;

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

/*-------------------------------------------*/

ll n, l, q;
ll x[100009], nxt[100009][17];

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

    cin >> n;
    rep(i, n) cin >> x[i];
    cin >> l;
    ll y = 0;
    rep(i, n) {
        while(y + 1 < n && x[i] + l >= x[y + 1]) {
            y++;
        }
        nxt[i][0] = y;
    }
    rep(i, 16) rep(j, n) nxt[j][i + 1] = nxt[nxt[j][i]][i];

    cin >> q;
    while(q--) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        if(b < a) swap(a, b);
        ll ans = 1;
        for(int i = 16; i >= 0; i--) {
            if(nxt[a][i] < b) {
                a = nxt[a][i];
                ans += 1 << i;
            }
        }
        cout << ans << endl;
    }

    return 0;
}


// abc141_f
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

ull func(vector<ull> a){
    int n = a.size();
    int rank = 0;
    REP_REV(i, 60) {
        int j;
        for (j = rank; j < n; j++) {
            if (a[j] & (1ull << i)) break;
        }
        if (j == n) continue;

        if (j > rank) a[rank] ^= a[j];

        for (j = 0; j < n; j++) {
            if (j == rank) continue;
            if (a[j] & (1ull << i)) a[j] ^= a[rank];
        }

        rank++;
    }
    ull x = 0;
    REP(i, n) {
        x ^= a[i];
    }

    return x;
}

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N;
    cin >> N;
    vector<ull> A(N);
    REP(i, N) cin >> A[i];

    ull allxor = 0;
    REP(i, N) allxor ^= A[i];
    REP(i, N) A[i] &= ~allxor;

    ull res = allxor + 2 * func(A);
    print(res);

    return 0;
}

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <math.h>
using namespace std;

const int MAXN = 1e5 + 10;
int N, M;
int A[MAXN];

int main() {
	register int i, j = 0, k = 0;
	scanf("%d%d", &N, &M);
	for(i = 1; i <= M; ++i)
		scanf("%d", A + i);
	if(M == 1) {
		if(A[1] == 1) return printf("1\n1\n1\n"), 0;
		printf("%d\n", A[1]);
		printf("%d\n", 2);
		printf("%d %d\n", A[1] - 1, 1);
		return 0;
	}
	for(i = 1; i <= M; ++i)
		if(A[i] & 1) {
			if(!j) j = i;
			else if(!k) k = i;
			else return puts("Impossible"), 0;
		}
	if(j) swap(A[j], A[1]);
	if(k) swap(A[k], A[M]);
	if(j && k && A[1] < A[M]) swap(A[1], A[M]);
	for(i = 1; i <= M; ++i)
		printf("%d%c", A[i], " \n"[i == M]);
	++A[1], --A[M];
	if(!A[M]) --M;
	printf("%d\n", M);
	for(i = 1; i <= M; ++i)
		printf("%d%c", A[i], " \n"[i == M]);
	return 0;
}


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

int main(int argc, char const *argv[]) {
    int p, q, r;
    cin >> p >> q >> r;

    int ans = min(p+q, min(q+r, r+p));
    cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h>

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

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

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

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

using ll = long long;

using namespace std;

int main() {
  in(ll, n);
  if (!n) {
    out(0);
    return 0;
  }
  string ans;
  ll bit = 1;
  while (n) {
    if (abs(n) % 2 == 1) {
      n -= 1;
      ans = '1' + ans;
    } else {
      ans = '0' + ans;
    }
    n /= -2;
    bit <<= 1;
  }
  out(ans);
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>
#include <unordered_map>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';

using namespace std;

ll cutter[]={1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288};

bool cut(int in, ll index){
    if(in/cutter[index]%2==0) return false;
    else return true;
}

int main(void){
    ll N;
    unordered_map<string, ll> kosuL;
    unordered_map<string, ll> kosuR;
    ll count=0;
    string S;
    cin>>N>>S;
    string SL="", SR="";
    rep(i, N){
        SL+=S[i];
        SR+=S[2*N-1-i];
    }
    ll ZENTAN_MAX=pow(2, N);
    rep(i, ZENTAN_MAX){
        string str="", str2="";
        rep(j, N) if(cut(i, j)) str+=SL[j]; else str2+=SL[j];
        //cout<<str<<sp<<str2<<endl;
        string ansstr=str+"#"+str2;
        kosuL[ansstr]++;
    }
    rep(i, ZENTAN_MAX){
        string str="", str2="";
        rep(j, N) if(cut(i, j)) str+=SR[j]; else str2+=SR[j];
        //cout<<str<<sp<<str2<<endl;
        string ansstr=str+"#"+str2;
        kosuR[ansstr]++;
    }
    for(auto itr : kosuR){
        count+=(itr.second)*kosuL[itr.first];
    }
    cout<<count<<endl;
    return 0;
}

#include<iostream>
#include<cstdio>
using namespace std;
int x,y;
int main()
{
	scanf("%d%d",&x,&y);
	int ans=0;
	if(x==1) ans+=30;
	else if(x==2) ans+=20;
	else if(x==3) ans+=10;
	if(y==1) ans+=30;
	else if(y==2) ans+=20;
	else if(y==3) ans+=10;
	if(x==1&&y==1) ans+=40;
	ans*=10000;
	printf("%d",ans);
	return 0;
}


#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 5050,inf=0x3f3f3f3f;
int n,f[N][N],res;
struct node{
	int p,h;
}a[N];
bool cmp(node a, node b){
//	return a.p+a.h<b.p+b.h;
	return min(a.h,b.h-a.p)>min(b.h,a.h-b.p);
}
int main() {
	read(n);rep(i,1,n)read(a[i].h),read(a[i].p);
	sort(a+1,a+n+1,cmp);
	rep(i,0,n)rep(j,0,n)f[i][j]=inf;f[0][0]=0;
	rep(i,0,n-1)rep(j,0,i)if(f[i][j]<inf){
		umin(f[i+1][j],f[i][j]);
		if(f[i][j]<=a[i+1].h)umin(f[i+1][j+1],f[i][j]+a[i+1].p),umax(res,j+1);
	}
	cout<<res;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N, M, Q, l, r;
    cin >> N >> M >> Q;
    vector<vector<int>> a(N, vector<int>(N));
    for (int i = 0; i < M; i++) {
        cin >> l >> r;
        l--, r--;
        a[l][r]++;
    }
    vector<vector<int>> s(N+1, vector<int>(N+1));
    for (int i = 0; i < N; i++)
        for (int j = 0; j < N; j++)
            s[i+1][j+1] = s[i+1][j] + s[i][j+1] - s[i][j] + a[i][j];

    for (int i = 0; i < Q; i++) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        cout << s[y+1][y+1] - s[x][y+1] - s[y+1][x] + s[x][x] << '\n';
    }
}


#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<int>>;
const ll mod=1000000007;
const int MAX_N = 1000;         // n の最大値

double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}

int main() {
string s;
cin>>s;
if(s.size()==2){
cout << s << endl;}
else{

cout << s.at(2)<<s.at(1)<<s.at(0) << endl;}}

 #include<bits/stdc++.h>
using namespace std;
int main()
  {
  string s;
  cin>>s;
  int l = s.length();
  if(l==3)
  reverse(s.begin(),s.end());

  cout<<s<<endl;
  }


//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    string s;
    cin >> s;
    int n = s.size();

    int ans = 0;
    reverse(all(s));
    s += '0';

    rep(i, n+1) {
        if(s[i] >= 6+'0' || s[i] == 5+'0' && s[i+1] >= 5+'0') {
            ans += 10-s[i]+'0';
            while(s[++i] == '9');
            ++s[i--];
        } else {
            ans += s[i] - '0';
        }
    }

    cout << ans << endl;
}


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

int main(){
  long n,m,p[1001];
  while(cin>>n>>m,n||m){
    for(int i=1;i<=n;++i) cin>>p[i];
    p[0]=0;
    vector<long> s(0);
    for(int i=0;i<=n;++i){
      for(int j=0;j<=n;++j) s.push_back(p[i]+p[j]);
    }
    sort(s.begin(),s.end());
    long a=0;
    for(vector<long>::iterator it=s.begin();*it<m/2;++it){
      a=max(a,*it+*(upper_bound(s.begin(),s.end(),m-*it)-1));
    }
    cout<<a<<endl;
  }
  return 0;
}

//Nayeem Shahriar Joy ,Applied Physics And Electronic Engineering , University of Rajshahi.

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

using namespace std;

   int main(){
    int m, d, w;
    int days[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    string weekName[7] = {"Sunday", "Monday", "Tuesday", "Wednesday",
                         "Thursday", "Friday", "Saturday"};
    while(1){
        cin >> m >> d;
        if(!(m || d)){
            return 0;
        }
        w = 3;
        for(int i = 1; i < m; i++){
            w += days[i - 1];
        }
        w += d;
        cout << weekName[w % 7] << endl;
    }
}


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

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    map<ll, int> nums;
    rep(i, n) {
        cin >> a[i];
        nums[a[i]]++;
    }

    sort(a.rbegin(), a.rend());
    int ans = 0, i = 0;
    while (i < n) {
        ll biggest_num = a[i++];
        if (nums[biggest_num] == 0) {
            continue;
        }
        nums[biggest_num]--;
        ll sumToBe = 0;
        while ((biggest_num >> sumToBe) > 0ll) {
            sumToBe++;
        }

        ll comp = (1 << sumToBe) - biggest_num;
        if (nums[comp]) {
            ans++;
            nums[comp]--;
        }
    }
    cout << ans << endl;
}

#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template<class _T> static void getint(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void getint(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void getint(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}

static void AGC005A();

#if 1
int main()
{
	AGC005A();
	fflush(stdout);
	return 0;
}
#endif

static void AGC005A()
{
	std::string orgs;
	std::cin >> orgs;

	int sCount = 0, eraseCount = 0;
	int len = orgs.length();
	for (int i = 0; i < len; i++) {
		if (orgs[i] == 'S') {
			sCount++;
		}
		else {
			if (sCount) {
				sCount--;
				eraseCount += 2;
			}
		}
	}
	printf("%d\n", len - eraseCount);
}


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

int main() {
    /* Input */
    int K;
    string S;
    cin >> K;
    cin >> S;

    /* Main Logic */
    if ((int)S.size() <= K) {
        cout << S << endl;
        return 0;
    } else {
        cout << S.substr(0, K) + "..." << endl;
        return 0;
    }
}

#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b;
	cin >> a >> b;
	int ans = 0, cnt = 1;
	while(cnt < b){
		cnt += a - 1;
		++ans;
	}
	cout << ans << endl;
	return 0;
}


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

int M = 1000000007;

int mod(int a){
	return (a%M + M)%M;
}
int mul(int a, int b){
	return mod(mod(a) * mod(b));
}
int add(int a, int b){
	return mod(mod(a) + mod(b));
}
int sub(int a, int b){
	return mod(mod(a) - mod(b));
}
main(){
	int n; cin>>n;
	int a[n];
	for(auto &it : a) cin>>it;

	int sum=0, sumsqr=0;
	for(int i=0; i<n; i++){
		sum = add(sum,a[i]);
		sumsqr = add(sumsqr, a[i]*a[i]);
	}
	int ans = mod(mul(sum,sum)-sumsqr);
	if(ans%2==0) cout<<ans/2;
	else cout<<mod((ans + M)/2);
}

#include <bits/stdc++.h>

#define nl '\n'

using namespace std;

typedef long long ll;

void solve() {
  int N;
  cin >> N;
  int A[N];
  for (int& i: A) cin >> i;

  ll ans = 0;
  const int mod = 1e9 + 7;
  int suff[N] = {0};
  suff[N - 1] = A[N - 1];
  for (int i = N - 2; i >= 0; i--)
    suff[i] = (A[i] + suff[i + 1]) % mod;
  for (int i = 0; i < N - 1; i++) ans = (ans + (1ll * A[i] * suff[i + 1]) % mod) % mod;

  cout << ans;
}

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

  // int t;
  // cin >> t;
  // while (t--) {
  solve();
  // cout << nl;
  // }

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main (void) {
    int N, A, B;
    cin >> N >> A >> B;
    vector<int> X(N);
    for ( int i = 0; i < N; i++ ) cin >> X.at(i);

    long long ans = 0;
    for ( int i = 0; i < N-1; i++ ) {
        int dist = X.at(i+1) - X.at(i);
        long long walk_cost = (long long)A * dist;
        long long tele_cost = B;
        if ( walk_cost < tele_cost ) ans += walk_cost;
        else ans += tele_cost;
    }

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

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

int n, a, b, x[100000];

int main(){
	//IO("input.txt", "output.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> a >> b >> x[0];
	long long cnt = 0;
	for(int i = 1; i < n; i++){
		cin >> x[i];
		cnt += min((long long)b, a * (long long)(x[i] - x[i - 1]));
	}
	cout << cnt << "\n";
	return 0;
}


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

int main() {
  int H, W; cin >> H >> W;
  int N = H*W;
  int A[N]; string str;
  int white_num = 0;
  for (int i = 0; i < H; i++) {
    cin >> str;
    for (int j = 0; j < W; j++) {
      white_num += A[i*W+j] = (str[j] == '.');
    }
  }
  queue<pair<int, int>> Q; Q.push(make_pair(0, 1));
  bool visited[N]; for (int i = 0; i < N; i++) visited[i] = false;
  visited[0] = true;
  int score = -1;
  while (!Q.empty()) {
    auto front = Q.front(); Q.pop();
    int u = front.first, d = front.second;
    if (u == H*W-1) { score = white_num-d; break; }
    vector<int> e;
    if (u >= W) e.push_back(u-W);
    if (u % W > 0) e.push_back(u-1);
    if (u % W < W-1) e.push_back(u+1);
    if (u / W < H-1) e.push_back(u+W);
    for (int v : e) {
      if (A[v] && !visited[v]) {
        visited[v] = true;
        Q.push(make_pair(v, d+1));
      }
    }
  }
  cout << score << endl;
}

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

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

int main() {
    int H, W;
    cin >> H >> W;

    vector<string> Graph(H);
    rep(i,H) cin >> Graph.at(i);

    vector<vector<int>> dist(H, vector<int>(W, -1)); // -1: 未訪問
    dist[0][0] = 0;

    int ans = -1;
    int wall = 0;
    rep(i,H) rep(j,W) if (Graph.at(i).at(j) == '#') ++wall;

    vector<string> G = Graph;
    vector<vector<int>> reached = dist;
    queue<P> que;

    que.push(make_pair(0, 0));
    dist[0][0] = 0;

    while (!que.empty()) {
        P p = que.front();
        que.pop();
        for (int direction = 0; direction < 4; ++direction) {
            int nh = p.first + dx[direction];
            int nw = p.second + dy[direction];
            if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
            if (dist.at(nh).at(nw) > -1) continue;
            if (Graph.at(nh).at(nw) == '#') continue;
            dist.at(nh).at(nw) = dist.at(p.first).at(p.second) + 1;
            if (nh == H - 1 && nw == W - 1) {
                ans = dist.at(nh).at(nw);
                break;
            }
            que.push(make_pair(nh, nw));
        }
    }
    if (ans == -1) cout << ans << endl;
    else
    cout << H * W - wall - (ans + 1) << endl;
}


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

int main(){

    int n,k;
    cin >> n >> k;
    vector<int> x(n);
    rep(i,n) cin >> x[i];
    int ans = INF;
    rep(i,n-k+1) {
        ans = min(ans,abs(x[i])+abs(x[i+k-1]-x[i]));
        ans = min(ans,abs(x[i+k-1])+abs(x[i+k-1]-x[i]));
    }
    cout << ans << endl;

    return 0;
}

#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647
// MAX O(n) 10^18

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

    int orderL = L;
    int orderR = L + N - 1;
    int eat;

    if(0 < orderL) {
        eat = orderL;
    } else if(orderR < 0) {
        eat = orderR;
    } else {
        eat = 0;
    }

    int ans = (orderL + orderR) * (orderR - orderL + 1) / 2 - eat;

    cout << ans << endl;

    return 0;
}


#include <iostream>
#include <vector>
#include <stack>

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;

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

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

  int in[N];
  vvi edge(N, vi());
  rep(i, N) in[i] = 0;
  rep(i, N-1+M) {
    int a, b; cin >> a >> b;
    --a; --b;
    edge[a].push_back(b);
    ++in[b];
  }
  stack<int> st;
  vi sorted, parent(N, -1);
  rep(i, N)
    if (in[i] == 0) st.push(i);

  while (!st.empty()) {
    int p = st.top(); st.pop();
    sorted.push_back(p);
    for (const auto& e : edge[p]) {
      --in[e];
      if (in[e] == 0) {
        st.push(e);
        parent[e] = p;
      }
    }
  }
  rep(i, N)
    cout << parent[i] + 1 << endl;

  return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
  int k,x;
  cin >> k >> x;
  k--;
  for (int i = x - k; i < x+k;i++){
    cout << i << " " << flush;
  }
  cout << x + k << endl;
  return 0;
}


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

int main(){
  string s;
  cin >> s;
  int ans =0;
  if(s == "RRR"){ans = 3;}
  if(s == "RRS"){ans = 2;}
  if(s == "RSR"){ans = 1;}
  if(s == "SRR"){ans = 2;}
  if(s == "RSS"){ans = 1;}
  if(s == "SRS"){ans = 1;}
  if(s == "SSR"){ans = 1;}
  if(s == "SSS"){ans = 0;}
  cout << ans << endl;
}

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

int main()
{
	string s;
	cin>>s;
	map<char,int> m;
	for(char c : s)
	{
		m[c]++;
	}
	for(char c='a';c<(char)('a'+26);c=(char)(c+1))
	{
		if(m[c]==0)
		{
			cout<<c<<endl;
			return 0;
		}
	}
	cout<<"None"<<endl;
	return 0;
}


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

static const int NIL = -1;

struct Vertex {
    vector<int> link;
    int parent = NIL;
    int ord;
    int lowlink;
    bool is_visit = false;
};

class ArticulationPoint {
private:
    int n;
    vector<Vertex> graph;
    int timer = 1;

public:
    ArticulationPoint() {}

    ArticulationPoint(int n)
    {
        this->n = n;
        graph.resize(n);
        int edge;
        cin >> edge;
        int s, t;
        for (int e = 0; e < edge; e++)
        {
            cin >> s >> t;
            graph[s].link.push_back(t);
            graph[t].link.push_back(s);
        }
    }

    void dfs(int current)
    {
        graph[current].is_visit = true;
        graph[current].ord = graph[current].lowlink = timer;
        timer++;

        for(int next : graph[current].link)
        {
            if(!graph[next].is_visit)
            {
                graph[next].parent = current;
                dfs(next);
                graph[current].lowlink = min(graph[current].lowlink, graph[next].lowlink); // 3.
            }
            else if(next != graph[current].parent)
            {
                // １回の移動で行くことのできる訪問済みの頂点は，Backedgeを除けば自分の親しかいない
                // つまりこのブロックにくるのはnextがBackedgeを通った訪問済みの頂点のとき
                graph[current].lowlink = min(graph[current].lowlink, graph[next].ord);
            }

        }
    }

    void articulation_point()
    {
        set<int> art_point;
        int root = 0;

        dfs(root);

        int root_child_num = 0;
        for(int u = 0; u < n; u++)
        {
            int p = graph[u].parent;
            if(p == NIL) continue;
            if(p == root)
            {
                root_child_num++;
                if(root_child_num >= 2)
                    art_point.insert(root);
            }
            else if(graph[p].ord <= graph[u].lowlink)
            {
                art_point.insert(p);
            }
        }

        for(int x : art_point)
            cout << x << endl;
    }
};

int main()
{
    int n;
    cin >> n;
    ArticulationPoint articulationPoint(n);
    articulationPoint.articulation_point();
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    EACH(x,vec) is >> x;
    return is;
}
template<typename T1, typename T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
    return os << p.first << " " << p.second;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    REP(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
    REP(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

vector<vector<ll>> G;
vector<bool> used;
vector<ll> order;
ll next_order = 0;
vector<ll> ans;
void add_ans(ll v) {
    ans.pb(v);
}
ll dfs(ll v, ll prev) {
    ll res = order[v] = next_order++;
    bool is_articulation = false;
    ll d = 0;
    EACH(to, G[v]) {
        if (to == prev) continue;
        if (order[to] >= 0) {
            res = min(res, order[to]);
        }
        else {
            ll low = dfs(to, v);
            if (prev >= 0 && low >= order[v]) {
                is_articulation = true;
            }
            res = min(res, low);
            ++d;
        }
    }
    if (prev < 0 && d >= 2) is_articulation = true;
    if (is_articulation) add_ans(v);
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, m; cin >> n >> m;
    vector<ll> g(n);
    G.resize(n);
    REP(i, m) {
        ll a, b; cin >> a >> b;
        G[a].pb(b);
        G[b].pb(a);
    }
    order.assign(n, -1);
    dfs(0, -1);
    sort(ALL(ans));
    EACH(a, ans) {
        cout << a << endl;
    }
}


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

typedef long long              ll;
typedef long double            ld;
typedef pair<int, int>         pi;
typedef vector<int>            vi;
typedef vector<pair<int, int>> vpi;

#define pb       push_back
#define all(x)   begin(x), end(x)
#define sz(x)    (int)(x).size()
#define ff       first
#define ss       second
#define mp       make_pair
#define lb       lower_bound
#define ub       upper_bound
#define tcase()  int t; cin >> t; while(t--)

const int MOD = 1e9 + 7; // 998244353;
const int MX  = 2e5 + 5;
const ll  INF = 1e18;
const ld  PI  = acos((ld) -1);

void setIO(string name = "") {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if(sz(name)){
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }
}

int main(){

    setIO();

    int n, m;
    cin >> n >> m;

    bool ok = true;

    int mpp[n + 1] = {0};

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

        if(x > n){
            ok = false;
        }

        if(mpp[x] != 0 && mpp[x] != y){
            ok = false;
        }

        if(x == 1 && y == 0) ok = false;

        else mpp[x] = y;
    }

    if(n == 1 && mpp[1] == 0){
        cout << 0;
        return 0;
    }

    if(m == 0 && n == 1){
        cout << 0;
        return 0;
    }

    if(m == 0 && n > 1){
        if(n == 2) cout << "10";
        else cout << "100";
        return 0;
    }

    if(!ok){
        cout << -1;
        return 0;
    }

    if(mpp[1] == 0){
        mpp[1] = 1;
    }

    for(int i = 1; i <= n; i++) cout << mpp[i];
}

#include<bits/stdc++.h>

using namespace std;

int main()
{
    int N,M;
    cin >> N >> M;
    vector<int> s(M);
    vector<int> c(M);
    int ans=0;

    if(M == 0 && N==1){
        cout << "0" << endl;
        return 0;
    }

    for(int i=0; i<M; i++){
        cin >> s.at(i) >> c.at(i);
        if(N>1 && s.at(i) == 1 && c.at(i) == 0){
            cout << "-1" << endl;
            return 0;
        }
    }

    vector<int> d(N);

    for(int i=0; i<M; i++){
        if(d.at(s.at(i)-1) == 1 && c.at(i) != ans/(int)(pow(10,N-s.at(i))) ) {
            cout << "-1" << endl;
            return 0;
        }
        if(d.at(s.at(i)-1) == 0){
            ans += c.at(i)*(int)pow(10,N-s.at(i)) ;
            d.at(s.at(i)-1)++;
        }
    }

    if(d.at(0) == 0){
        ans += (int)pow(10,N-1);
    }

    cout << ans << endl;

}


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

typedef long long ll;
const ll MOD = 1e9 + 7;

// Sum of digits in base 10 is a multiple of D
ll generate(ll depth, ll sum, bool tight, ll D, const string& digits, vector<vector<vector<ll>>>& memo) {
    if (depth == digits.size()) {
        return sum % D == 0;
    }
    if (memo[depth][sum][tight] != -1) {
        return memo[depth][sum][tight];
    }
    ll limSup = tight ? (digits[depth] - '0') : 9;
    ll ans = 0;
    for (ll d = 0; d <= limSup; d++) {
        bool newTight = tight && d == limSup;
        ans = (ans + generate(depth + 1, (sum + d) % D, newTight, D, digits, memo)) % MOD;
    }
    return memo[depth][sum][tight] = ans;
}

int main() {
    string s;
    cin >> s;
    ll D;
    cin >> D;
    ll n = s.size();
    vector<vector<vector<ll>>> memo(n, vector<vector<ll>>(D, vector<ll>(2, -1)));
    ll ans = generate(0, 0, true, D, s, memo);
    cout << (ans - 1 + MOD) % MOD << "\n"; // don't count 0
}

/// IN THE NAME OF METAL
#include <bits/stdc++.h>

using namespace std;

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

#define sz(x)                       (ll) x.size()
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second

ll Pow(ll a, ll b, ll md, ll ans = 1) {
    for (; b; b >>= 1, a = a * a % md)
        if (b & 1)
            ans = ans * a % md;
    return ans % md;
}

const ll MAXN = 1e6 + 10;
const ll INF = 8e18;
const ll MOD = 998244353;
ll n, k, fact[MAXN], inv[MAXN], res[MAXN];

ll C(ll x, ll y) {
    if (x > y) return 0;
    return fact[y] * inv[x] % MOD * inv[y - x] % MOD;
}

int main() {
    fact[0] = inv[0] = 1;
    for (ll i = 1; i < MAXN; i++) {
        fact[i] = fact[i - 1] * i % MOD;
        inv[i] = Pow(fact[i], MOD - 2, MOD);
    }
    scanf("%lld%lld", &k, &n);
    for (ll i = 2; i <= 2 * k; i++) {
        ll ans = 0;
        for (ll j = 0; j <= i / 2; j++) {
            if (j & 1) {
                ans = (ans - C(n - j - j, k + n - j * 2 - 1) * C(j, i / 2) % MOD + MOD) % MOD;
            } else {
                ans = (ans + C(n - j - j, k + n - j * 2 - 1) * C(j, i / 2) % MOD) % MOD;
            }
        }
        res[i] = ans;
        if (i <= k + 1) printf("%lld\n", res[i]);
        else printf("%lld\n", res[k + k + 2 - i]);
    }
    return 0;
}


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

int h, w;
int grid[MX][MX];

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

bool valid(int x, int y) {
    return (x >= 0 && x < h && y >= 0 && y < w);
}

int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin >> h >> w;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> grid[i][j];
        }
    }

    vector<pair<int, int>> starts, ends;

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (!grid[i][j]) continue;
            int fx = -1, fy = -1;
            bool set = false;
            for (int k = 0; k < 4; k++) {
                int a = i + dx[k], b = j + dy[k];
                if (!valid(a, b)) continue;
                if (grid[i][j] % 2 != grid[a][b] % 2) {
                    if (grid[i][j] % 2) fx = a, fy = b;
                } else if (grid[i][j] % 2 == 0 && grid[a][b] % 2 == 0) {
                    continue;
                } else {
                    starts.push_back({i, j});
                    ends.push_back({a, b});
                    grid[a][b]++;
                    grid[i][j]--;
                    set = true;
                    break;
                }
            }
            if (fx != -1 && !set) {
                starts.push_back({i, j});
                ends.push_back({fx, fy});
                grid[fx][fy]++;
                grid[i][j]--;
            }
        }
    }

    cout << starts.size() << '\n';
    for (int i = 0; i < (int)starts.size(); i++) {
        cout << starts[i].first + 1 << ' ' << starts[i].second + 1 << ' ' << ends[i].first + 1 << ' ' << ends[i].second + 1 << '\n';
    }
}

#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
//コンビネーションを10^9+7で割った余りを求める
const int MOD=1000000007;
int main(){
    int h,w;
    cin>>h>>w;
    vector<vector<int>> c(h,vector<int> (w));
    bool p=false;
    rep(i,h){
        rep(j,w){
            cin>>c[i][j];
        }
    }
    int l=0,r=0;
    int ans=0;
    string s="";
    while(1){

        if(c[l][r]%2!=0 && !p){
            p=true;
            if(l==h-1 && h%2==0 && r==0){}
            else if(l==h-1 && h%2==1 && r==w-1){}
            //cout<<l+1<<" "<<r+1<<" ";
            else{
                s+=to_string(l+1)+" "+to_string(r+1)+" ";
            }
        }
        else if(c[l][r]%2==0 && p){
            //cout<<l+1<<" "<<r+1<<endl;
            ans++;
            if(l==h-1 && h%2==0 && r==0 || l==h-1 && h%2==1 && r==w-1){
                s+=to_string(l+1)+" "+to_string(r+1)+"\n";
                break;
            }
            s+=to_string(l+1)+" "+to_string(r+1)+"\n";

            s+=to_string(l+1)+" "+to_string(r+1)+" ";
            //cout<<l+1<<" "<<r+1<<" ";
        }
        else if(c[l][r]%2!=0 && p){
            p=false;
            //cout<<l+1<<" "<<r+1<<endl;
            s+=to_string(l+1)+" "+to_string(r+1)+"\n";
            ans++;
        }
        else{//c[l][r]が偶数でコインを持ってない

        }

       //cout<<l<<" "<<r<<endl;
       if(l==h-1 && h%2==0 && r==0){
           break;
       }
       if(l==h-1 && h%2==1 && r==w-1){
           break;
       }
        if(r==w-1 && l%2==0){
            l++;
            continue;
        }
        if(r==0 && l%2==1){
            l++;
            continue;
        }
        if(l%2==0){
            r++;
        }
        else{
            r--;
        }
    }
    cout<<ans<<endl;
    cout<<s;
}


#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;
int INF = 1001001001;

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

  vector<int> p;
  rep(i, n) p.push_back(i);
  double ans = 0;
  do {
    double sum = 0;
    rep(i, n-1) {
      int xl = x[p[i+1]] - x[p[i]];
      int yl = y[p[i+1]] - y[p[i]];
      sum += sqrt(xl * xl + yl * yl);
    }
    ans += sum;
  } while(next_permutation(p.begin(), p.end()));

  int n2 = 1;
  for(int i=1; i<=n; i++) n2 *=i;

  ans /= n2;
  printf("%.10f", ans);
  return 0;
}


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

// ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

// const double PI = acos(-1);
// int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
// int a[12][12];

void solve() {
  string s; cin >> s;
  string hitachi = "";
  for (int i= 1; i <=5; i++) {
    hitachi += "hi";
    if (hitachi == s) {
      cout << "Yes" << endl;
      return;
    }
  }
  cout << "No" << endl;

}

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

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

int main(){
  string s;
  cin >> s;
  bool flg = true;
  rep(i, s.size()){
    if(i % 2 == 0 && s[i] == 'h' && s[i+1] == 'i') continue;
    else if(i % 2 == 1) continue;
    else{
      flg = false;
      cout << "No" << endl;
      break;
    }
  }
  if(flg) cout << "Yes" << endl;
  return 0;
}


#include<iostream>
#include<vector>

int main(void){
    int n;
    std::cin >> n;
    std::vector<int> a(n+1), b(n+1);
    a[0] = 0;
    for(int i = 1; i <= n; i++){
        std::cin >> a[i];
    }

    for(int i = n; i > 0; i--){
        int cnt = 0;
        for(int j = i; j <= n; j += i){
            if(b[j] == 1) cnt++;
        }
        cnt = cnt % 2;
        if(cnt != a[i]) b[i] = 1;
    }
    int zcnt = 0;
    for(int i = 1; i <= n; i++){
        if(b[i] == 1){
            zcnt++;
        }
    }
    std::cout << zcnt << std::endl;
    for(int i = 1; i <= n; i++){
        if(b[i] == 1){
            std::cout << i << " ";
        }
    }

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
  while(true){
    int n; cin>>n;
    if(!n) break;
    int a[10]={};
    for(int i=0;i<n;++i){
      int c;
      cin>>c;
      ++a[c];
    }
    for(int i=0;i<10;++i){
      for(int j=0;j<a[i];++j) cout<<"*";
      if(!a[i]) cout<<"-";
      cout<<"\n";
    }
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000000, mod = 998244353, inv2 = (mod + 1) / 2;
int n, m, s, w, d, w2, ans;
int fac[maxn + 10], ifac[maxn + 10], inv[maxn + 10];

inline int add(int x, int y) {
	x += y; return x < mod ? x : x - mod;
}
inline int dec(int x, int y) {
	x -= y; return x < 0 ? x + mod : x;
}
inline int mul(int x, int y) {
	return 1ll * x * y % mod;
}

void prework() {
	fac[0] = ifac[0] = 1;
	for (int i = 1; i <= maxn; ++i) {
		fac[i] = mul(fac[i - 1], i);
		inv[i] = i == 1 ? 1 : dec(0, mul(mod / i, inv[mod % i]));
		ifac[i] = mul(ifac[i - 1], inv[i]);
	}
}

int comb(int x, int y) {
	return y < 0 || y > x ? 0 : mul(fac[x], mul(ifac[y], ifac[x - y]));
}

int f(int x, int y) {
	return comb(x + y, x);
}

int main() {
	prework();
	scanf("%d%d", &n, &m);
	w = comb(n + m - 1, n); w2 = comb(n + m - 1, m); d = 1;
	s = add(s, add(w, w2));
	for (int i = m - 2; i >= -n - 1; --i) {
		ans = add(ans, mul(s, inv[d]));
		++d;
		if (d & 1) {
			w = add(w, mul(f(i + d / 2, n - d / 2), f(m - (i + d / 2) - 2, d / 2)));
			w2 = add(w2, mul(f(m - d / 2, n - (d - d / 2)), f(d / 2, d - d / 2 - 2)));
		} else {
			w = dec(w, mul(f(i + d / 2, n - d / 2), f(m - (i + d / 2) - 1, d / 2 - 1)));
			w2 = dec(w2, mul(f(m - d / 2, n - (d - d / 2)), f(d / 2 - 1, d - d / 2 - 1)));
		}
		s = add(s, add(w, w2));
	}
	printf("%d", mul(ans, mul(ifac[n + m], mul(fac[n], fac[m]))));
}

#include<bits/stdc++.h>
#define rg register
#define il inline
#define int long long
using namespace std;
typedef long long ll;
const int mod=1e9+7,O=200010;
il int gi(){
	rg int o=0,fl=1;char ch=getchar();
	while(!isdigit(ch)&&ch!='-')ch=getchar();
	if(ch=='-')fl=-1,ch=getchar();
	while(isdigit(ch))o=o*10+ch-'0',ch=getchar();
	return fl*o;
}
int h,w,a,b,fac[O],inv[O],ans;
il ll C(int n,int m){return 1ll*fac[n]*inv[m]%mod*inv[n-m]%mod;}
signed main(){
	fac[0]=inv[0]=inv[1]=fac[1]=1;
	for(int i=2;i<O;++i)fac[i]=1ll*fac[i-1]*i%mod,inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
	for(int i=2;i<O;++i)inv[i]=1ll*inv[i-1]*inv[i]%mod;
	scanf("%lld%lld%lld%lld",&h,&w,&a,&b);
	for(int i=1;i<=h-a;++i)
		(ans+=C(i+b-2,i-1)*C(h-i+w-b-1,h-i)%mod)%=mod;
	printf("%lld\n",ans);
	return 0;
}
//(1,1)->(i,b)*(i,b)->(n,m)


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define dob double
int main(){
	string arr[14] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
	string a;
	cin>>a;
	int ans = 0;
	bool ok = false;
	for (int i = 0; i<14; i++){
		if (ok){
			ans++;
		}
		if (ok && arr[i] == "SUN"){
			break;
		}
		if (arr[i] == a){
			ok = true;
		}
	}
	cout<<ans;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define fr(i,a,b) for(int i = a ; i <= b ; ++i)
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
#define fst first
#define snd second
using namespace __gnu_pbds;
using ordered_set =
 tree<int, null_type,less<int>,
 rb_tree_tag,tree_order_statistics_node_update>;
//find_by_order(k):returns iterator to kth element starting from 0
//order_of_key(k):returns count of elements strictly smaller than k
typedef long long ll;typedef pair<int, int> pii;
typedef vector<int> vi;typedef long double ld;
template<class T>
using min_heap = priority_queue<T,vector<T>,greater<T>>;
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<typename T>
void remdup(vector<T>& v) {
	sort(all(v)); v.erase(unique(all(v)), v.end());
}
template<typename T> void re(vector<T> &v) {trav(i,v) cin >> i;}
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
#ifdef np
#include "C:\Users\navodit\Desktop\mycodes\pr.h"
#else
#define trace(...)
#endif

#define MOD 1000000007

void solve(){
	map<string,int> week;
	week["MON"] = 1;
		week["TUE"] = 2; 	week["WED"] = 3; 	week["THU"] = 4; 	week["FRI"] = 5; 	week["SAT"] = 6;
			week["SUN"] = 0;
	string s;
	cin >> s;
	cout << 7 - week[s];
}
signed main() {
	unsyncIO();
	int tt =1 ;
	// cin >> tt;
	rep(i,0,tt) solve();

#ifdef np
	cout <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll, ll> PLL;
#define chmax(x, y) do { x = max(x, y); } while(0)
#define chmin(x, y) do { x = min(x, y); } while(0)
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) \
  for (ll i = static_cast<ll>(a); i < static_cast<ll>(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, ) (__VA_ARGS__)  // NOLINT
template<typename T>
using reversed_priority_queue = std::priority_queue<T, std::vector<T>, std::greater<T> >;

ll N, Q;
string s;

signed main() {
  cin >> N >> s >> Q;
  while (Q--) {
    ll k;
    cin >> k;
    vector<ll> d(N, 0), m(N, 0), dm(N, 0);
    // d, m, dm の構築
    if (s[0] == 'D') d[0] = 1;
    if (s[0] == 'M') m[0] = 1;
    for (int i = 1; i < N; i++) {
      d[i] = d[i-1];
      m[i] = m[i-1];
      dm[i] = dm[i-1];
      if (s[i] == 'D') {
        d[i] += 1;
      }
      if (s[i] == 'M') {
        m[i] += 1;
        dm[i] += d[i-1];
      }
    }
    ll ans = 0;
    // 集計
    for (int i = 2; i < N; i++) {
      if (s[i] != 'C') continue;
      ans += dm[i-1];
      if (i - k >= 0) {
        ans -= dm[i-k];
        ans -= d[i-k] * (m[i-1] - m[i-k]);
      }
    }
    cout << ans << endl;
  }
  return 0;
}

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

template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << ", " << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define f first
#define s second

void printer(char c, int dist) {
    for(int i = 0; i < dist; i++)
        cout << c;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int x, y, endx, endy;
    cin >> x >> y >> endx >> endy;
    int distx = abs(endx - x), disty = abs(endy - y);
    printer('U', disty);
    printer('R', distx);
    printer('D', disty);
    printer('L', distx);
    cout << 'L';
    printer('U', disty + 1);
    printer('R', distx + 1);
    cout << "DR";
    printer('D', disty + 1);
    printer('L', distx + 1);
    cout << 'U';
}


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

#define ll long long
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define ii pair<int,int>
#define vii vector<ii>
#define vi vector<int>

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)

// debug templates
#define debug(x)       cerr<< #x <<" : "<< x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";

void solve(){
	int n,q; cin >> n >> q;
	// [S,T),X
	set<pair<int,pair<int,int>>> st;
	FOR(n){
		int s,t,x; cin >> s >> t >> x;
		// [s-x,t-x) are the starting positions of people that get stuck in this blockade
		st.insert({s-x,{1,x}});
		st.insert({t-x,{-1,x}});
	}
	FOR(q){
		int d; cin >> d;
		st.insert({d,{2,i}});
	}
	int ans[q];
	memset(ans,0,sizeof(ans));
	set<int> blocked;
	// if type 1 then add x to blocked
	// if type -1 remove from blocked
	// if type 2 then check if it is being blocked currently
	for(pair<int,pair<int,int>> xx : st){
		if(xx.second.first == 1){
			blocked.insert(xx.second.second);
		} else if(xx.second.first == -1){
			blocked.erase(xx.second.second);
		} else{
			if(blocked.empty()){
				ans[xx.second.second] = -1;
			} else{
				ans[xx.second.second] = *(blocked.begin());
			}
		}
	}
	for(int yy : ans) cout << yy << '\n';
}

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

	solve();
	return 0;
}

#include<iostream>
#include<vector>
using namespace std;
#define INF 1980000001
int main(){
    int V, E;
    cin >> V >> E;
    vector<vector<int> > A(V, vector<int>(V, INF));
    for (int i = 0; i < V; i++) {
        A[i][i] = 0;
    }
    for (int i = 0; i < E; i++) {
        int s, t, d;
        cin >> s >> t >> d;
        A[s][t] = d;
    }
    for (int k = 0; k < V; k++) {
        for (int i = 0; i < V; i++) {
            for (int j = 0; j < V; j++) {
                if (A[i][k] == INF || A[k][j] == INF) continue;
                A[i][j] = min(A[i][j], A[i][k] + A[k][j]);
            }
        }
    }
    for (int i = 0; i < V; i++) {
        if (A[i][i] != 0) {
            cout << "NEGATIVE CYCLE" << endl;
            return 0;
        }
    }
    for (int i = 0; i < V; i++) {
        for (int j = 0; j < V; j++) {
            if (A[i][j] == INF) {
                cout << "INF";
            } else {
                cout << A[i][j];
            }
            cout << (j < V - 1 ? " " : "\n");
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
    ll S;
    ll N = 1;
    cin >> S;
    while (S/(ll)pow(10,N)) {
        //cout << pow(10,N) << endl;
        //cout << S/pow(10,N) << endl;
        //cout << N << endl;
        N++;
    }
    //cout << N << endl;
    ll ans = 1000;

    for(int i = 0; i < N-2; i++) {
        ans = min(ans,abs(753 - (S/(int)pow(10,i))%1000));
    }
    cout << ans << endl;

    return 0;
}

#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define st first
#define nd second
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
template <class T> T read(T &a) {
    a=0;char x=getchar();bool f=0;
    for(;x<'0'||x>'9';x=getchar())f|=x=='-';
	for(;x>='0'&&x<='9';x=getchar())a=(a<<3)+(a<<1)+x-'0';
    if(f)a=-a;
    return a;
}
using namespace std;

typedef pair<int, int> tp;

map<tp, LL> mp;

int main() {
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		double a;
		scanf("%lf", &a);
		a *= 1e9;
		LL b = llround(a);
		tp k;
		k.st = k.nd = 0;
		while (b % 5 == 0) {
			b /= 5;
			k.st++;
		}
		while (b % 2 == 0) {
			b /= 2;
			k.nd++;
		}
		mp[k]++;
	}
	map<tp, LL>::iterator i, j;
	int ci, cj;
	LL ans = 0;
	for (i = mp.begin(), ci = 0; i != mp.end(); ++i, ++ci) {
		for (j = mp.begin(), cj = 0; j != mp.end(); ++j, ++cj) {
			tp a = i->first, b = j->first;
			if (a.st + b.st >= 18 && a.nd + b.nd >= 18) {
				if (ci < cj) ans += i->second * j->second;
				if (ci == cj) ans += i->second * (i->second - 1) / 2;
			}
		}
	}
	cout << ans << endl;
    return 0;
}


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

int main()
{
    int k,n;
    double sum=0;
    cin>>n>>k;
    vector<double> p(n+1); //累積和
    for(int i=1;i<=n;i++){
        double a;
        cin>>a;
        a=(a+1)/2;
        sum+=a;
        p[i]=sum;
    }
    double ans=0;
    rep(i,n-k+1){
        ans=max(ans,p[i+k]-p[i]);
    }
    printf("%.10f",ans);
}

#include <bits/stdc++.h>

#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
// #define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)

template<typename T> void scan1(T& x) { fprintf(stderr, "unknown type\n"); }
template<> void scan1(long& x) { if( scanf("%ld", &x) < 0 ) exit(0); }
void scan() {}
template<typename Head, typename... Tail>
void scan(Head& x, Tail&... xs) {
  scan1(x); scan(xs...);
}

template<typename W>
struct N003 {
   typedef std::vector<long> LI;
   typedef std::vector<W>    LW;
   long n, e;
   LI ss, ds;
   LW ws;
   std::vector<LI> iss;
   N003(long n_, const LI& ss_, const LI& ds_, const LW& ws_)
      : n(n_), e(ss_.size()), ss(ss_), ds(ds_), ws(ws_) {
      iss.resize(n+1);
      for(long i = 0; i < e; ++i) {
         iss[ss[i]].push_back(i);
      }
   }
};

template<typename W>
struct N006 {
   std::vector<std::vector<W>> xss;
   bool negativeCycle;
   N006(const N003<W>& g, W inf) : negativeCycle(false) {
      xss.resize(g.n+1);
      for(auto& xs : xss) xs.resize(g.n+1, inf);
      for(long i = 0; i < g.n+1; ++i) xss[i][i] = 0;
      for(long i = 0; i < g.e; ++i) {
         xss[g.ss[i]][g.ds[i]] = g.ws[i];
      }
      for(long z = 0; z < g.n+1; ++z) {
         for(long x = 0; x < g.n+1; ++x) {
            for(long y = 0; y < g.n+1; ++y) {
               W d = xss[x][y];
               W nd = xss[x][z] + xss[z][y];
               xss[x][y] = std::min(d, nd);
            }
         }
      }
      for(long x = 0; x < g.n+1; ++x) {
         for(long y = 0; y < g.n+1; ++y) {
            if( xss[x][y] >= inf / 2 ) {
               xss[x][y] = inf;
            }
         }
         if( xss[x][x] < 0 ) {
            negativeCycle = true;
         }
      }
   }
};

struct Solver {
   Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
   ~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
   void solve() {
      typedef std::vector<long> LI;
      long v, e;
      scan(v, e);
      LI ss(e+1), ds(e+1);
      LI ws(e+1);
      for(long i = 0; i < e; ++i) {
         scan(ss[i], ds[i], ws[i]);
      }
      N003<long> g(v, ss, ds, ws);
      N006<long> warshallfloyd(g, (1LL << 60));
      if( warshallfloyd.negativeCycle ) {
         puts("NEGATIVE CYCLE");
      }
      else {
         for(long i = 0; i < v; ++i) {
            for(long k = 0; k < v; ++k) {
               if( warshallfloyd.xss[i][k] == (1LL << 60) ) {
                  printf("INF");
               }
               else {
                  printf("%ld", warshallfloyd.xss[i][k]);
               }
               putchar( k == v - 1 ? '\n' : ' ');
            }
         }
      }
   }
};

int main() {
  loop std::unique_ptr<Solver>(new Solver())->solve();
}


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

typedef pair<int, int> P;
const int N = (int)1e5 + 50, INF = (int)1e9;

int n, m;
map<int, vector<int> > G[N];
set<int> rem[N];
int dis[N];

deque<P> que;

void dfs(int v, int color, int d) {
//    printf("in %d , color: %d\n", v, color);
    rem[v].erase(color);
    if(d < dis[v]) {
        dis[v] = d;
        que.push_back({v, color});
    }
    for(int nxt : G[v][color]) {
        if(rem[nxt].find(color) != rem[nxt].end()) {
//            printf("from %d to %d\n", v, nxt);
            dfs(nxt, color, d);
        }
    }
}

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

    cin >> n >> m;
    fill(dis, dis + n, INF);
    for(int i = 0; i < m; i++) {
        int a, b, c; cin >> a >> b >> c; a--, b--, c--;
        G[a][c].push_back(b);
        G[b][c].push_back(a);
        rem[a].insert(c);
        rem[b].insert(c);
    }
    while(!rem[0].empty()) dfs(0, *rem[0].begin(), 1);
//    for(int i = 0; i < n; i++) {
//        printf("dis %d: %d\n", i + 1, dis[i]);
//    }
    while(!que.empty()) {
        P p = que.front();
        int v = p.first, c = p.second;
        que.pop_front();
        while(!rem[v].empty()) {
            dfs(v, *rem[v].begin(), dis[v] + 1);
        }
    }
    if(dis[n-1] == INF) dis[n-1] = -1;
    cout << dis[n - 1] << endl;
}

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

static const int MAX = 100000;

int n, num;
vector<int> V[MAX];
int prenum[MAX], lowest[MAX], parent[MAX];
bool B[MAX];

void dfs(int cur, int pre) { //dfs??¨?????????prenum, lowest, parent????¨????
	prenum[cur] = lowest[cur] = num++;
	B[cur] = true;

	int next;
	for (int i = 0; i < V[cur].size(); i++) {
		next = V[cur][i];
		if (!B[next]) {
			parent[next] = cur;
			dfs(next, cur);
			lowest[cur] = min(lowest[cur], lowest[next]); //?????????????°?????????????????°????????????°??????
		} else if (next != pre) {
			lowest[cur] = min(lowest[cur], prenum[next]); //back-edge
		}
	}
}

void artPoint() {
	set<int> ap;
	int np = 0;
	for (int i = 1; i < n; i++) {
		int p = parent[i];
		if (p == 0) np++; //root?????\?¶???????????????°
		else if (prenum[p] <= lowest[i]) {
			ap.insert(p);
		}
	}
	if (np > 1) ap.insert(0);
	for (set<int>::iterator it = ap.begin(); it != ap.end(); it++) {
		cout << *it << endl;
	}
}

int main() {
	int e;
	cin >> n >> e;
	int s, t;
	for (int i = 0; i < e; i++)	{
		cin >> s >> t;
		V[s].push_back(t);
		V[t].push_back(s);
	}

	for (int i = 0; i < n; i++)	{
		B[i] =  false;
	}

	num = 1;
	dfs(0, -1); //next?????¶???prev???????????????

	artPoint();

	return 0;
}


#include <stdio.h>
#include <string.h>

#define HIT 1
#define HR 2
#define OUT 3

int main(void){
    int outCnt, pt;
    int runner; // use bits
    char event[8];
    int eventID;
    int n;
    bool endInning;

    scanf("%d", &n);
    for (int i=0; i<n; i++){
        endInning = false;
        outCnt = runner = pt = 0;
        while (!endInning){
            scanf("%s", event);
            if (event[0]=='O') eventID=OUT;
            else if (event[1]=='I') eventID=HIT;
            else eventID=HR;
            switch (eventID){
            case HIT:
                if (runner & 0x4) pt++;
                runner = (runner<<1) & 0x7;
                runner |= 0x1;
                break;
            case HR:
                pt++;
                if (runner & 0x4) pt++;
                if (runner & 0x2) pt++;
                if (runner & 0x1) pt++;
                runner = 0;
                break;
            case OUT:
                if (++outCnt == 3) endInning = true;
                break;
            }
        }
        printf("%d\n",pt);
    }

    return 0;
}

#include <iostream>
#include <string>

using namespace std;

int main() {
	int point = 0, hits = 0, out = 0;
	int n; cin >> n;

	int i = 0;
	while (i < n) {
		string s; cin >> s;
		if (s == "HIT") {
			hits++;
			if (hits == 4) {
				point++;
				hits--;
			}
		}
		if (s == "OUT") {
			out++;
			if (out == 3) {
				hits = 0;
				out = 0;
				cout << point << endl;
				point = 0;
				i++;
			}
		}
		if (s == "HOMERUN") {
			point += hits + 1;
			hits = 0;
		}
	}

	return 0;
}


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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) ((v).begin(),(v).end())
#define COUT(x) cout<<(x)<<"\n"

int a[26];

int main(){
    string s;cin >> s;
    REP(i,s.size()){
        int num = s[i]-'a';
        a[num]++;
    }
    if(s.size()!=26){
        cout << s;
        REP(i,26){
            if(a[i]==0){
                COUT((char)('a'+i));
                break;
            }
        }
    }
    else{
        string past = s;
        do{
            if(s>past){
                for(int i=0;i<26;i++){
                    if(s[i]==past[i])cout << s[i];
                    else{
                        COUT(s[i]);
                        return 0;
                    }
                }
            }
        }while(next_permutation(s.begin(),s.end()));
        COUT(-1);
    }
    return 0;
}

const int isDebugMode = 0;
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
struct edge{long long to,cost;};
const int inf = 1 << 27;
const long long INF = 1LL << 60;
const int COMBMAX = 1001001;
const long long MOD = 1000000007;
const long long dy[] = {-1, 0, 0, 1};
const long long dx[] = {0, -1, 1, 0};
string abc = "abcdefghijklmnopqrstuvwxyz";
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define eachdo(v, e) for (const auto &e : (v))
#define all(v) (v).begin(), (v).end()
#define lower_index(v, e) (long long)distance((v).begin(), lower_bound((v).begin(), (v).end(), e))
#define upper_index(v, e) (long long)distance((v).begin(), upper_bound((v).begin(), (v).end(), e))
long long mpow(long long a, long long n, long long mod = MOD){long long res = 1; while(n > 0){if(n & 1)res = res * a % mod; a = a * a % mod; n >>= 1;} return res;}
void pt(){cout << endl; return;}
template<class Head> void pt(Head&& head){cout << head; pt(); return;}
template<class Head, class... Tail> void pt(Head&& head, Tail&&... tail){cout << head << " "; pt(forward<Tail>(tail)...);}
void dpt(){if(!isDebugMode) return; cout << endl; return;}
template<class Head> void dpt(Head&& head){if(!isDebugMode) return; cout << head; pt(); return;}
template<class Head, class... Tail> void dpt(Head&& head, Tail&&... tail){if(!isDebugMode) return; cout << head << " "; pt(forward<Tail>(tail)...);}
template<class T> void debug(T v){if(!isDebugMode) return; rep(i, v.size()) cout << v[i] << " " ; cout << endl;}
template<class T> void debug2(T v){if(!isDebugMode) return; rep(i, v.size()){rep(j, v[i].size()) cout << v[i][j] << " " ; cout << endl;}}
template<class T1, class T2> inline bool chmin(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}
template<class T1, class T2> inline bool chmax(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}
template<class T1, class T2> long long gcd(T1 a, T2 b){return a % b ? gcd(b , a % b) : b;}
template<class T1, class T2> void reduce(T1 &a, T2 &b){ll g = gcd(a, b); a /= g; b /= g; return;}
bool valid(long long H, long long W, long long h, long long w) { return 0 <= h && h < H && 0 <= w && w < W; }

int main(){
    string S; cin >> S;
    string cba = abc;
    reverse(all(cba));
    if (S == cba){
        pt(-1);
        return 0;
    }
    if(S.size() == 26){
        for(ll i = 25; 0 < i; i--){
            if(S[i] - 'a' > S[i - 1] - 'a'){
                ll lim = S[i - 1] - 'a';
                ll cnt = INF;
                for(ll j = i; j < 26; j++){
                    if(lim < S[j] - 'a') chmin(cnt, S[j] - 'a');
                }
                S[i - 1] = abc[cnt];
                pt(S.substr(0, i));
                return 0;
            }
        }
    }else{
        for(auto e : abc){
            if(find(all(S), e) == S.end()){
                S += e;
                pt(S);
                return 0;
            }
        }
    }
    return 0;
}


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

int main(){
  long long n,m,v,p,i;
  cin >> n >> m >> v >> p;
  vector<long long> a(n);
  for(i=0;i<n;i++){
    cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());

  long long s;
  s=n-1;
  while(a.at(s)+m<a.at(p-1)){
    s--;
  }
  s++;

  long long t,V;
  V=n*m;
  t=p-1;
  while(V>=m*v&&t<s){
    t++;
    if(t==n){
      break;
    }
    V=V-(a.at(t-1)-a.at(t))*(t-p+1);
  }

  cout << t << endl;
}

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

#define FAST ios_base::sync_with_stdio(0); cin.tie(); cout.tie();

#define MAXX 100005

#define PI 3.14159265358979323846264338327950

#define F first
#define S second

#define ll 	 long long int

#define mod  1000000007

int main()
{
	FAST;
	ll n, m, x, y;
	cin >> n >> m >> x >> y;
	ll a1= -555, a2 = 100; ll f;
	for(ll i = 0; i < n; i ++){
		cin >> f;
		a1 = max(a1, f);
	}
	for(ll i = 0; i < m; i ++){
		cin >> f;
		a2 = min(a2, f);
	}
	if(a1 < a2 && a2 <= y && a2 > x ){
		cout << "No War";
		return 0;
	}
	cout << "War";
	return 0;
}


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

int data[100];

int main(){
	int n;
	scanf("%d",&n);
	for(int i = 0; i < n * (n - 1) / 2; i++){
		int b[4];
		for(int k=0;k<4;k++) scanf("%d",&b[k]);
		if(b[2]>b[3]) data[b[0]-1]+=3;
		if(b[2]<b[3]) data[b[1]-1]+=3;
		if(b[2]==b[3]){ data[b[0]-1]++; data[b[1]-1]++; }
	}
	for(int i=0;i<n;i++){
		int res=1;
		for(int j=0;j<n;j++){
			if(data[i]<data[j]) res++;
		}
		printf("%d\n",res);
	}
}

#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;

bool Cmp(pii a,pii b){
  if(a.first>b.first){
    return true;
  }else{
    return false;
  }
}

int main(){
  int n;
  cin>>n;
  vector<pii>team;
  for(int j=0;j<n;j++) team.push_back(pii(0,j));
  for(int i=0;i<(n*(n-1))/2;i++){
    int ta,tb,sa,sb;
    cin>>ta>>tb>>sa>>sb;
    if(sa>sb){
      team[--ta].first+=3;
    }else if(sa<sb){
      team[--tb].first+=3;
    }else{
      team[--ta].first++;
      team[--tb].first++;
    }
  }
  sort(team.begin(),team.end(),Cmp);
  //for(pii a : team)cout <<"score :" << a.first << " team num: " <<a.second << endl;
  //cout << endl;
  int ans[n];
  for(int i=0;i<team.size();i++){
    int cnt=0;
      while(team[i].first==team[i-1-cnt].first)cnt++;
    ans[team[i].second]=i+1-cnt;
  }
  for(int i=0;i<n;i++){
    cout << ans[i] << endl;
  }
 return 0;
}


#include <bits/stdc++.h>
#include <string>
#include <cmath>
#include <sstream>
//#include <unordered_map>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORD(i, a, b) for(int i = (a-1); i >= (b); i--)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
typedef long long int ll;
using namespace std;
ll mod=1000000007;
//ll mod=67280421310721;
//ll mod=998244353;
ll INF=1e18;
ll po(ll a,ll b)
{
	ll re=1;
	while(b)
	{
		if(b%2==1)
		{
			re=(re*a);
			re%=mod;
		}
		a=(a*a);
		a%=mod;
		b>>=1;
	}
	return re;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
//	cin>>test;
	while(test--)
	{
		string s;
		cin>>s;
		int n=s.size();
		int ans=0;
		FORD(i,n,0)
		{
			if(s[i]=='5')
			{
				ans+=5;
				if(i!=0)
				{
					if(s[i-1]>='5')
					s[i-1]=(s[i-1]+1);
				}
			}
			else if(s[i]<'5')
			{
				ans+=(s[i]-'0');
			}
			else
			{
				ans+=(('9'-s[i])+1);
				if(i==0)
				ans++;
				else
				s[i-1]=(s[i-1]+1);
			}
		}
		cout<<ans;
	}
	return 0;
}

#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

void solve();

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

int dp[10000000+1][2];

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

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

  dp[0][0] = S[0] - '0';
  dp[0][1] = 10 - (S[0] - '0');

  for (int i = 1; i < S.size(); i++) {
    int s = S[i] - '0';
    if (0 < s && s < 9) {
      dp[i][0] = min(dp[i-1][0] + s, dp[i-1][1] + s + 1);
      dp[i][1] = min(dp[i-1][0] + (10 - s), dp[i-1][1] + (10 - (s + 1)));
    } else if (s == 0) {
      dp[i][0] = min(dp[i-1][0], dp[i-1][1] + 1);
      dp[i][1] = dp[i-1][1] + 9;
    } else if (s == 9) {
      dp[i][0] = dp[i-1][0] + 9;
      dp[i][1] = min(dp[i-1][0] + 1, dp[i-1][1]);
    }
  }

  cout << min(dp[S.size()-1][0], dp[S.size()-1][1]+1) << endl;
}


#include <stdio.h>
#define mod 1000000007
typedef long long ll;

ll mul(ll a, ll b) {
  return (a * b) % mod;
}

ll rev(ll a) {
  ll ans = 1, b = mod - 2;
  while(b) {
    if(b & 1) ans = mul(ans, a);
    a = mul(a, a), b >>= 1;
  }
  return ans;
}

ll sum(ll a) {
  return a * (a + 1) / 2;
}

int main(void) {
  ll i, j, n, m, k, ans = 0, c, now;
  scanf("%lld%lld%lld", &n, &m, &k);
  ll fact[n * m + 1];
  fact[0] = 1;
  for(i = 1; i <= n * m; ++i) fact[i] = mul(fact[i - 1], i);
  c = mul(fact[n * m - 2], mul(rev(fact[k - 2]), rev(fact[n * m - k])));
  for(i = 0; i < n; ++i) for(j = 0; j < m; ++j) {
    now = m * sum(i) + n * sum(j);
    now += sum(n - 1 - i) * m + sum(m - 1 - j) * n;
    now %= mod;
    now = mul(now, c);
    ans += now;
    ans %= mod;
  }
  ans = mul(ans, rev(2));
  printf("%lld", ans);
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
const int MAX = 510000;
const int MOD = 1000000007;

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

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
	ll n,m,k;
	cin>>n>>m>>k;
    COMinit();
    ll ans=0;
    for(ll i=1;;i++){
    	if(n-i==0){
    		break;
    	}
    	ll cnt=COM(n*m-2,k-2);
    	cnt*=m*m;
    	cnt%=inf;
    	cnt*=i*(n-i);
    	cnt%=inf;
    	ans+=cnt;
    	ans%=inf;
    }
    for(ll i=1;;i++){
    	if(m-i==0){
    		break;
    	}
    	ll cnt=COM(n*m-2,k-2);
    	cnt*=n*n;
    	cnt%=inf;
    	cnt*=i*(m-i);
    	cnt%=inf;
    	ans+=cnt;
    	ans%=inf;
    }
    cout <<ans;
	// your code goes here
	return 0;
}


#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 998244353;
const long long INF = 1e18;
typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> PLL;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned long long ULL;
//typedef boost::multiprecision::cpp_int bigint;

LL calc(LL N, LL M, LL D) {
	VLL V(M,1);
	LL ans = 0;
	while (true) {
		for (LL m = 0; m < M - 1; m++) {
			if (abs(V[m] - V[m + 1]) == D)ans++;
		}
		LL m = M-1;
		for (; m >= 0; m--) {
			if (V[m] != N)break;
		}
		if (m == -1)return ans;
		V[m]++;
		for (LL mm = m + 1; mm < M; mm++)V[mm] = 1;
	}
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	//for (LL n = 1; n <= 10; n++) {
	//	for (LL m = 2; m <= 6; m++) {
	//		for (LL d = 0; d < n; d++) {
	//			//cout << "n,m,d = " << n << "," << m << "," << d << ":";
	//			//cout << calc(n, m, d) << "/(n^m);\n";
	//			LL d0 = calc(n, m, d);
	//			LL d1 = 2*(m-1);
	//			for (LL p = 0; p < m - 2; p++)d1 *= n;
	//			d1 *= n - d;
	//			if (d0 != d1) {
	//				cout << "n,m,d = " << n << "," << m << "," << d << ":";
	//				cout << d0 << "vs" << d1 << "\n";
	//			}
	//		}
	//		cout << "\n";
	//	}
	//	cout << "####################\n";
	//}
	LL N, M, D;
	cin >> N >> M >> D;
	LD ans = (LD)2 * (M - 1) * (N - D) / N / N;
	if (D == 0)ans /= 2;
	cout << setprecision(12) << ans << "\n";
	return 0;
}

#include <iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
#include<set>
#include<deque>
#include<iomanip>
#include<tuple>
#include<stack>

#define _USE_MATH_DEFINES
#include<math.h>

using namespace std;
typedef long long ll;

typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef tuple<int, int, int> ti3;

const ll MOD_CONST = 1000000007;
//const ll MOD_CONST = 998244353;

const int BIG_NUM = 1000000005;
const ll INF = 1000000000000000000;

//const vector<vector<int>> DIR{ {1,0},{0,1},{-1,0},{0,-1} };

//const double EPS = 1e-10;

int main() {
	int n, m, d;
	cin >> n >> m >> d;
	double p = (d == 0) ? 1.0 / n : (2.0 * (n - d)) / n / n;
	std::cout << setprecision(20) << p * (m - 1) << endl;
}


#include<bits/stdc++.h>

using namespace std;
using   ll=long long;

#define fast        	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define endl        	"\n"
#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define int             long long int
#define pll				pair<int , int>

#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod 			1000000007
#define hell            998244353

ll mod_pow(ll a,ll b,ll m)
{
    ll res = 1;
    while(b)
    {
        if(b&1)
        {
        	res=(res*a) % m;
        }
        a=(a*a) % m;
        b>>=1;
    }
    return res;
}

ll mod_inverse(ll a)
{
	return mod_pow(a , mod-2 , mod);
}

void solve()
{
	int  l , r;

	cin >> l >> r;

	int lol = 2019;

	int ans = inf;

	for(int i = 1; i <= 2019; ++i) {
		int num = (l/2019)*2019;

		num += i;

		if(num < l) {
			num += 2019;
		}

		//cout << num << endl;

		if(num > r) {
			continue;
		}

		for(int j = 1; j <= 2019; ++j) {
			int tm;
			if(i == j) {
				tm = num + 2019;
			}
			else {
			tm = (l/2019)*2019;

			tm += j;

			if(tm < l) {
				tm += 2019;
			}

			}

			if(num >= l && num <= r && tm >= l && tm <= r) {
				ans = min(ans , (num*tm)%2019);
			}
		}
	}

	cout << ans;
}

signed main() {
    fast;

    int t = 1;

	//cin >> t;

    while(t--) {
        solve();
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 0; i < n; ++i)
#define rep3(i, a, b) for (ll i = a; i < b; ++i)
#define rep4(i, a, b, c) for (ll i = a; i < b; i += c)
#define erep(n) for (ll i = 0; i <= n; ++i)
#define erep2(i, n) for (ll i = 0; i <= n; ++i)
#define erep3(i, a, b) for (ll i = a; i <= b; ++i)
#define erep4(i, a, b, c) for (ll i = a; i <= b; i += c)
#define rrep(i, a, b) for (ll i = a; i > b; --i)
#define rrep2(i, a, b, c) for (ll i = a; i > b; i -= c)
#define errep(i, a, b) for (ll i = a; i >= b; --i)
#define errep2(i, a, b, c) for (ll i = a; i >= b; i -= c)
#define print(a) cout << a << endl;
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define cin(x) cin >> x;
const ll MOD = 1000000007;
const double PI = 3.14159265358979323846264338327950;
inline int newline() { putchar('\n'); return 0; }

int main() {
    ll left, right;
    cin(left); cin(right);

    if (2019 - left % 2019 <= right - left) {
        print(0);
        return 0;

    } else {
        ll result = LLONG_MAX;
        rep3(i, left, right) {
            erep3(j, i + 1, right) {
                if (i * j % 2019 < result) result = i * j % 2019;
            }
        }
        print(result);
        return 0;
    }
}


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

typedef long long ll;
typedef pair<int,int> P;
int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};

int main(){
  int n, m;
  cin >> n >> m;
  int x[n+1], y[m+1];
  cin >> x[0] >> y[0];
  for(int i=0; i<n; i++) cin >> x[i+1];
  for(int i=0; i<m; i++) cin >> y[i+1];
  sort(x, x+n+1);
  sort(y, y+m+1);
  string ans;
  if(x[n]>=y[0]) ans = "War";
  else ans = "No War";
  cout << ans << endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<ll> A(n); rep(i, n) cin >> A[i];
  multiset<ll> st;
  rep(i, n) {
    auto itr = st.upper_bound(A[i]-1);
    if(itr == st.begin()) {
      st.insert(A[i]);
    } else {
      st.erase(--itr);
      st.insert(A[i]);
    }
  }
  cout << st.size() << endk;
  return 0;
}