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

long long N,M,K;
long long h,w;
long long X,Y,Z;
long long B;

const int MOD=1e9+7;

const int MAXN=5e5+5;
const int NAX=1005;
//vector<int> adj[MAXN];
vector<array<int,3>> adj[MAXN];
vector<Int> A;

Int ceilS(Int x,Int y){
    return (x+y-1)/y;
}

Int perform(Int x){
    return (x*(x+1))/2LL;
}

long long ModExpo(long long x,unsigned long long y,long long M){
    Int ans=1;
    ans=(long long)ans;

    while(y>0){
        if(y&1) ans=((ans%M)*(x%M))%M;
        y>>=1LL;
        x=((x%M)*(x%M))%M;
    }
    return ans%M;
}

long long ModInv(long long x){
    return ModExpo(x,MOD-2,MOD);
}
Int madd(Int x,Int y){
    return (x+y)%MOD;
}

Int mmul(Int x,Int y){
    return ((x%MOD)*(y%MOD))%MOD;
}
vector<long long> fac(MAXN);

Int performMod(Int x){
    return mmul(mmul(x,x+1),ModInv(2))%MOD;
}

void fill(){
    fac[0]=1;
    for(int i=1;i<MAXN;++i){
        fac[i]=mmul(fac[i-1],i)%MOD;
    }
}
long long choose(long long n,long long r){
    if(r==0||r==n) return 1;
    if(r>n) return 0;

    return mmul(mmul(fac[n],ModInv(fac[n-r])),ModInv(fac[r]))%MOD;
}

const int INF=1e9;
using D=long double;

vector<pair<int64_t,int64_t>> factorize(int64_t x){

    vector<pair<int64_t,int64_t>> factors;

    for(int64_t i=2;i*i<=x;++i){
        if(x % i) continue;
        int cnt=0;

        while(x % i ==0){
            x/=i;
            ++cnt;
        }
        factors.pb({i,cnt});
    }
    if(x > 1){
        factors.pb({x,1});
    }
    return factors;
}

struct TreeNode{
    int data;
    struct TreeNode* children[2];

    TreeNode(int x){
        data=x;
        for(int i=0;i<2;++i){
            children[i]=nullptr;
        }
    }
};

TreeNode* recur(int l,int r){
    if(r < l)  return nullptr;
    if(l==r){
        return new TreeNode(A[l]);
    }

    int mx=0,idx;
    for(int i=l;i<=r;++i){
        if(mx < A[i]){
            mx=A[i];
            idx=i;
        }
    }

    TreeNode* root=new TreeNode(mx);
    root->children[0]=recur(l,idx-1);
    root->children[1]=recur(idx+1,r);
    return root;

}

vector<int> depth;
void Preorder(TreeNode *root,int lvl){
    if(!root) return;

    depth[root->data]=lvl;

    Preorder(root->children[0],lvl+1);
    Preorder(root->children[1],lvl+1);
}

int main()
{

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

    cin>>N>>M>>X>>Y;
    for(int i=0;i<M;++i){
        int u,v,w,k;
        cin>>u>>v>>w>>k;
        --u;--v;
        adj[u].pb({v,w,k});
        adj[v].pb({u,w,k});
    }

    auto merge=[&](int64_t x,int64_t k){
            if(x % k==0) return 0LL;
            return (k - (x%k))*1LL;

        };

    auto dijkstra=[&](int src,int d){

        vector<int64_t> dis(N,1e15);

        priority_queue<array<int64_t,3>,vector<array<int64_t,3>>,greater<array<int64_t,3>>> pq;

        dis[src]=0;
        pq.push({dis[src],src,0});

        while(!pq.empty()){
            auto u=pq.top();
            pq.pop();

            if(dis[u[1]] < u[0]) continue;
            for(auto &v:adj[u[1]]){
                if(dis[u[1]] + v[1] +merge(dis[u[1]],v[2]) < dis[v[0]]){
                    dis[v[0]]=dis[u[1]] + v[1] + merge(dis[u[1]],v[2]);
                    pq.push({dis[v[0]],v[0],merge(dis[u[1]],v[2])});
                }
            }

        }

        cout<<(dis[d]==1e15 ? -1:dis[d])<<'\n';
    };

    dijkstra(--X,--Y);

}

#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
#define int long long
const int N = 2e5+10;
typedef pair<int, int> pii;
struct E{
  int v,t,k;
};
vector<E> e[N];
int n, m;
int dis[N];
bool vis[N];

void dijkstra(int s) {
  memset(dis, 0x3f, sizeof dis);
  dis[s] = 0;
  priority_queue<pii, vector<pii>, greater<pii>> q;
  q.push({0, s});
  while (!q.empty()) {
    auto t = q.top(); q.pop();
    int u = t.second, distance = t.first;
    if (vis[u]) continue;
    vis[u] = true;
    for (auto to: e[u]) {
      int v = to.v, t = to.t, k = to.k;
      int W = (distance + k - 1) / k * k + t;
      if (dis[v] > W) {
        dis[v] = W;
        q.push({dis[v], v});
      }
    }
  }
}

signed main() {
  int A, B;
  scanf("%lld%lld%lld%lld",&n,&m,&A,&B);
  while (m--) {
    int u, v, t, k;
    scanf("%lld%lld%lld%lld",&u,&v,&t,&k);
    e[u].push_back({v, t, k});
    e[v].push_back({u, t, k});
  }
  dijkstra(A);
  int ans = dis[B];
  if (ans == 0x3f3f3f3f3f3f3f3f) ans = -1;
  printf("%lld\n",ans);
  return 0;
}


#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
template<class V> struct BIT {
    BIT() {}  // [L, R)
    int NV;vector<V> bit;
    BIT(int n){ init(n); }
    void init(int n) { NV = 1; while (NV < n)NV *= 2; bit.resize(NV); clear(); }
    V operator[](int e) { V s = 0; e++; while (e) s += bit[e - 1], e -= e&-e; return s; }
    void add(int e, V v) { e++; while (e <= NV) bit[e - 1] += v, e += e&-e; }
    int lower_bound(V val) {
        V tv = 0; int i, ent = 0; for (i = NV - 1; i >= 0; i--)
        if(tv+bit[ent+(1<<i)-1]<=val)tv+=bit[ent+(1<<i)-1],ent += (1 << i);return ent;
    }
    V get(int L, int R) {
        assert(0 <= L); assert(R <= NV); assert(L <= R);
        V res = 0; if(R) res += operator[](R - 1); if (L) res -= operator[](L - 1);return res;
    }
    void clear() { rep(i, 0, NV) bit[i] = 0; }
	void update(int e, V v) { add(e, v - get(e, e + 1)); }
};
vector<int> compress1(int *v, int n) {
    vector<int> dic;
    rep(i, 0, n) dic.push_back(v[i]);
    sort(all(dic));
    dic.erase(unique(all(dic)), dic.end());
    rep(i, 0, n) v[i] = lower_bound(all(dic), v[i]) - dic.begin();
    return dic;
}
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/

int N, M, Q, T[201010], X[201010], Y[201010];
int A[201010], B[201010];
BIT<ll> Acnt(201010), Bcnt(201010);
BIT<ll> Atot(201010), Btot(201010);
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> M >> Q;
    rep(i, 0, Q) cin >> T[i] >> X[i] >> Y[i];

    auto ZY = compress1(Y, Q + 1);
    Acnt.add(0, N);
    Bcnt.add(0, M);

    ll ans = 0;
    rep(q, 0, Q) {
        if (T[q] == 1) {
            int x = X[q] - 1;
            int y = Y[q];
            ans -= Bcnt.get(0, A[x] + 1) * ZY[A[x]];
            ans -= Btot.get(A[x] + 1, 201010);

            Acnt.add(A[x], -1);
            Atot.add(A[x], -ZY[A[x]]);

            A[x] = y;

            ans += Bcnt.get(0, A[x] + 1) * ZY[A[x]];
            ans += Btot.get(A[x] + 1, 201010);

            Acnt.add(A[x], 1);
            Atot.add(A[x], ZY[A[x]]);
        }
        else {

            int x = X[q] - 1;
            int y = Y[q];
            ans -= Acnt.get(0, B[x] + 1) * ZY[B[x]];
            ans -= Atot.get(B[x] + 1, 201010);

            Bcnt.add(B[x], -1);
            Btot.add(B[x], -ZY[B[x]]);

            B[x] = y;

            ans += Acnt.get(0, B[x] + 1) * ZY[B[x]];
            ans += Atot.get(B[x] + 1, 201010);

            Bcnt.add(B[x], 1);
            Btot.add(B[x], ZY[B[x]]);
        }
        printf("%lld\n", ans);
    }
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
ll A[51];
ll X;
ll ret;
map<ll,ll> memo[55];

ll dfs(int cur,ll lef) {
	if(cur==N-1) {
		return 1;
	}

	if(memo[cur].count(lef)) return memo[cur][lef];
	ll ret=0;

	ll step=A[cur+1]/A[cur];
	ll a=lef%step;

	if(a==0) {
		ret+=dfs(cur+1,lef/step);
	}
	else {
		ret+=dfs(cur+1,lef/step);
		ret+=dfs(cur+1,lef/step+1);
	}
	return memo[cur][lef]=ret;
}

void solve() {
	int i,j,k,l,r,x,y; string s;

	cin>>N>>X;
	FOR(i,N) cin>>A[i];

	cout<<dfs(0,X)<<endl;
}

int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
//const lint MOD =1000000007;
const lint MOD=998244353;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
typedef map<lint,lint> M;
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)

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

void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint 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(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }

    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    }

    int main(){
        lint n,q,a,b;
        string s;
        cin>>a>>b;
    lint x=2*a+100;
    x-=b;
    chmax(x,0LL);
        cout<<x<<endl;
    }

#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int A,B,follow;
    cin>>A>>B;
    follow=2*A+100;
    cout<< follow - B<<"\n";
}


#include <bits/stdc++.h>
int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int main() {
	int h = ri();
	int w = ri();
	int x = ri() - 1;
	int y = ri() - 1;
	std::string s[h];
	for (auto &i : s) std::cin >> i;

	int cnt = -3;
	for (int i = x; i < h && s[i][y] != '#'; i++) cnt++;
	for (int i = x; i >= 0 && s[i][y] != '#'; i--) cnt++;
	for (int j = y; j < w && s[x][j] != '#'; j++) cnt++;
	for (int j = y; j >= 0 && s[x][j] != '#'; j--) cnt++;
	printf("%d\n", cnt);
	return 0;
}

#define ALL(x) (x).begin(), (x).end()
#include <bits/stdc++.h>

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

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

fastio _fast_io;

const int N = 105;
ll n, x, ans;
ll a[N];

void solve(ll num) {
    ll r = x % num;
    ll cur = x / num;
    vector<vector<ll>> dp(num + 1, vector<ll>(num, -1));
    dp[0][0] = 0;
    for (int i = 0; i < n; ++i) {
        auto dp2 = dp;
        for (int j = 0; j < num; ++j) {
            for (int k = 0; k < num; ++k) {
                if (dp[j][k] != -1) {
                    ll nk = (k + a[i]) % num;
                    ll add = (k + a[i]) / num;
                    if (dp2[j + 1][nk] == -1) {
                        dp2[j + 1][nk] = dp[j][k] + add;
                    } else {
                        dp2[j + 1][nk] = max(dp2[j + 1][nk], dp[j][k] + add);
                    }
                }
            }
        }
        dp = move(dp2);
    }
    if (dp[num][r] != -1)
        ans = min(ans, cur - dp[num][r]);
}

int main() {
    ans = std::numeric_limits<ll>::max();
    cin >> n >> x;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 1; i <= n; ++i) {
        solve(i);
    }
    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int N = 2e3 + 5;
vector<vector<int>> G(N);
vector<bool> vis(N);

void dfs(int u) {
    vis[u] = true;
    for (int v : G[u]) {
        if (vis[v] == true)
            continue;
        dfs(v);
    }
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n, m; cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        G[x].emplace_back(y);
    }

    int ans = 0;
    for (int i = 1; i <= n; i++) {
        dfs(i);
        for (int j = 1; j <= n; j++) {
            if (vis[j] == true)
                ans++;
            vis[j] = false;
        }
    }
    cout << ans << "\n";
}

#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<utility>
#include<map>
#include<tuple>
#include<deque>
using namespace std;
const int mod = 1000000007;
const int INF = 1001001001;
const long long LINF = 1001002003004005006;
const double PI = acos(-1);
int dir4row[] = { 1,0,-1,0 };
int dir4col[] = { 0,1,0,-1 };
int dir8row[] = { 1,1,0,-1,-1,-1,0,1 };
int dir8col[] = { 0,1,1,1,0,-1,-1,-1 };

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

int main() {
	int n, k; cin >> n >> k;
	vector<vector<int>> t(n, vector<int>(n));
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			cin >> t[i][j];
		}
	}
	vector<int> ord(n - 1);
	for (int i = 1; i < n; ++i) {
		ord[i - 1] = i;
	}
	int ans = 0;
	do {
		int now = 0;
		for (int i = 0; i < n - 2; ++i) {
			now += t[ord[i]][ord[i + 1]];
		}
		now += t[0][ord.front()];
		now += t[0][ord.back()];
		if (now == k) {
			ans++;
		}
	} while (next_permutation(ord.begin(), ord.end()));
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll>   vl;
#define f(i,n)  for(i=0;i<n;i++)
#define f1(i,n)  for(i=1;i<n;i++)
#define fr(i,n) for(i=n-1;i>=0;i--)
#define em emplace_back
// #define mp make_pair
#define in insert
#define fi first
#define sc second
#define b begin
#define e end
#define l length
#define c clear
#define si size
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
const double pi=3.141592653;
const ll infi=1000000001;
// const ll mod=1000000007;
// const ll mod=998244353;
const string no="NO\n",yes="YES\n",nl="\n";

// void dfs(vl v[],ll node,ll hai[]){
//     hai[node]=1;
//     for(auto i:v[node]){
//         if(hai[i]==0){
//             dfs(v,i,hai);
//         }
//     }
// }

// ll recur(vl v,ll in,ll m,ll n){
//     if(in==-1)  return 1000000000001;
//     ll d,e,c;
//     d=max(m/v[in],n*v[in]);
//     c=recur(v,in-1,m/v[in],n*v[in]);
//     e=recur(v,in-1,m,n);
//     return min(c,min(e,d));
// }

// ll bexpo(ll a,ll p){
//     ll x=1;
//     while(p){
//     if(p&1){
//         x=(x*a)%mod;
//     }
//     a=(a*a)%mod;
//     p>>=1;
//     }
//     return x;
// }
// int dx[8]{-1,0,0,1,-1,-1,1,1};
// int dy[8]{0,-1,1,0,-1,1,-1,1};
vi v[200009];
int p[200009];
int cc=0;
void dfs(int node,int par){
    cc++;
    p[node]++;
    for(auto j:v[node]){
        if(j!=par && p[j]==0){
            dfs(j,node);
        }
    }
}

int main() {

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

    fastio
    int t=1;
    // cin>>t;
    ll n,m,i,l,bank,k,j,x,y,ans,mid,q;
    // string s;

    while(t--){ans=0;
        cin>>n;
        map<pll,int> mp;
        ll a[n];
        f(i,n)  cin>>a[i];
        f(i,n/2){
            if(a[i]!=a[n-1-i]){
                x=a[i];
                y=a[n-1-i];
                v[x].em(y);
                v[y].em(x);
            }
        }
        f1(i,200001){
            if(p[i]==0){
                cc=0;
                dfs(i,-1);
                ans+=cc-1;
            }
        }
        cout<<ans;
    }

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10;
ll mn,mx,a,t,v,add;
int n,q;
int main(){
    scanf("%d",&n);
    mn=1e18,mx=-1e18;
    for(int i=1;i<=n;++i){
        scanf("%lld%lld",&a,&t);
        if(t==1)add+=a,mn+=a,mx+=a;
        else if(t==2)mn=max(mn,a),mx=max(mx,a);
        else mn=min(mn,a),mx=min(mx,a);
    }
    scanf("%d",&q);
    while(q--){
        scanf("%lld",&v);
        printf("%lld\n",min(mn,max(mx,v+add)));
    }
    return 0;
}


#define nl                  "\n"
#define ll                  long long
#define ull                 unsigned long long
#define pb                  push_back
#define SIZE(a)             (int)a.size()
#define SORT(v)             sort(v.begin(),v.end())
#define RSORT(v)            sort(v.rbegin(),v.rend())
#define REV(v)              reverse(v.begin(),v.end())
#define ff                  first
#define ss                  second
#define sq(a)               ((a)*(a))
#define For(i,a,b)          for(i=a;i<=b;i++)
#define Rof(i,a,b)          for(i=a;i>=b;i--)
#define Rep(i,b)            for(i=0;i<b;i++)
#define MOD                 1000000007
#define PI                  acos(-1.0)
#define eps                 1e-9
#define Linf                2e18
#define inf                 1<<30
#define MX5                 100005
#define MX6                 1000006
#define MX3                 1005
#define GCD(a,b)            __gcd(a,b)
#define Abs(a)              abs(a)
#define input(a,b)          scanf("%lld%lld",&a,&b)
#define in1(a)              scanf("%lld",&a)
#define output(a)           printf("%lld\n",a);
#define mem(a)              memset(a,-1,sizeof(a)) // complexity O(n)
#define clr(a)              memset(a,0,sizeof (a))
#define mk                  make_pair
#define pLL                 pair<ll,ll>
#define invcos(a)           (acos(a)*(180/3.14159265))
#define rtan(a)             (tan(a*3.14159265/180.0))
#define pip                 printf("pip")
#define Case(x)             printf("Case %lld: ",x)
#define timelimit           1.0*clock()/CLOCKS_PER_SEC
#define pc_one              __builtin_popcount
#define pcl_one             __builtin_popcountl
#define pcll_one            __builtin_popcountll
#define parity              __builtin_parity
#define parityl             __builtin_parityl
#define parityll            __builtin_parityll
#define infile              freopen("input.txt","r",stdin)
#define outfile             freopen("output.txt","w",stdout)
#define debug(x)            cerr << #x << " is " << x << endl
#define fast                ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
#define minheap             priority_queue<int, vector<int>, greater<int> >
//const ll Linf=2e18;
///4direction ->        int del_x[]={-1,0,1,0},del_y[]={0,1,0,-1};
///8direction ->        int del_x[]={-1,0,1,0,1,-1,-1,1},del_y[]={0,1,0,-1,-1,-1,1,1};

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

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
*/
ll find_lcm(ll a, ll b) { return ((a * b) / __gcd(a, b));}
ll bigmod(ll n, ll p) {if (p == 0) return 1; if (p == 1)return (n + MOD) % MOD; if (p % 2)return (bigmod(n, p - 1) * n + MOD) % MOD; else {ll x = bigmod(n, p / 2); return (x * x + MOD) % MOD;}}
ll modinverse(ll n) {return bigmod(n, MOD - 2) % MOD;}
bool check_2s_power(ll a) {return (pcll_one(a) == 1 ? true : false);}
ll check_Bit(ll n, ll k) { if (n & (1LL << k)) return true; return false; }
ll setBit(ll n, ll k) { return (n | (1LL << k)); }
ll clearBit(ll n, ll k) { return (n & (~(1LL << k))); }
ll toggleBit(ll n, ll k) { return (n ^ (1LL << k)); }

/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/
int main()
{
     ll n,sum=0,i;
     in1(n);
     for(i=1;;i++)
     {
         sum=(i*(i+1))/2;
         if(sum>=n)
         {
             output(i);
             return 0;
         }
     }
}

//By: Luogu@rui_er(122461)
#include <bits/stdc++.h>
#define rep(x,y,z) for(ll x=y;x<=z;x++)
#define per(x,y,z) for(ll x=y;x>=z;x--)
#define debug printf("Running %s on line %d...\n",__FUNCTION__,__LINE__)
using namespace std;
typedef long long ll;
const ll N = 1e5+5, mod = 1e9+7;

ll n, a[N], dp[N][2], ans;
template<typename T> void chkmin(T &x, T y) {if(x > y) x = y;}
template<typename T> void chkmax(T &x, T y) {if(x < y) x = y;}

int main() {
	scanf("%lld", &n);
	rep(i, 1, n) scanf("%lld", &a[i]);
	dp[1][1] = 1;
	rep(i, 2, n) {
		dp[i][1] = (dp[i-1][0] + dp[i-1][1]) % mod;
		dp[i][0] = dp[i-1][1];
	}
	ans = (dp[n][0] + dp[n][1]) * a[1] % mod;
	rep(i, 2, n) ans = (ans + (dp[i][1] * dp[n-i+2][1] % mod - dp[i][0] * dp[n-i+2][0] % mod + mod) % mod * a[i] % mod) % mod;
	printf("%lld\n", ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for (int i = k; i < (int)(n); i++)
#define repd(i, n) for (int i = n-1; i >= 0; i--)
#define rrepd(i, k, n) for (int i = n-1; i >= (int)(k); i--)
#define all(x) (x).begin(),(x).end()
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
//V,Pは大文字i,l,bは小文字
using ll = long long;
using Vi = vector<int>;
using VVi = vector<Vi>;
using Vl = vector<ll>;
using VVl = vector<Vl>;
using Vb = vector<bool>;
using VVb = vector<Vb>;
using P = pair<int,int>;
using Pl = pair<ll, ll>;
using Vs = vector<string>;
const ll mod = 1000000007;
const ll inf = 1000000000000000000;//10の18乗
#define yn {puts("Yes");}else{puts("No");}
#define dame { puts("-1"); return 0;}

int main() {
    ll n;
    cin >> n;
    Vl v(n);
    rep(i,n) cin >> v[i];
    ll now=0;//操作回数
    Vl whe(n);
    rep(i,n) whe[v[i]-1]=i;
    Vl ans;//あとでインクリメント
    Vl used(n-1,0);
    rep(i,n-1){
        ll x=whe[i];
        if(x<=i) continue;
        //ll y=x-i;
        for(int j=x-1;j>=i;j--){
            ans.PB(j);
            if(used[j])dame;
            used[j]++;
            now++;
            //cout << j << endl;
            swap(v[j],v[j+1]);
            whe[v[j]-1]=j;
            whe[v[j+1]-1]=j+1;
            //cout <<j<< endl;
        }

    }
    if(now!=n-1) dame;
    rep(i,n-1) cout << ans[i]+1 << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template <typename T>
void update_max(T& a, T b) {
    if (b > a) a = b;
}
template <typename T>
void update_min(T& a, T b) {
    if (b < a) a = b;
}
int main() {
#ifdef LOCAL_PROJECT
    freopen("input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, M;
    ll INF = 100000000000;
    cin >> N >> M;
    vector<vector<int>> graph(N);
    rep(i, 0, M) {
        int A, B;
        cin >> A >> B;
        A--;
        B--;
        graph[A].push_back(B);
        graph[B].push_back(A);
    }
    int K;
    cin >> K;
    vector<vector<ll>> dist(K, vector<ll>(K, INF));
    vector<int> C(K);
    unordered_map<int, int> C_map;
    rep(i, 0, K) {
        cin >> C[i];
        C[i]--;
        C_map[C[i]] = i;
    }
    rep(i, 0, K) { dist[i][i] = 0; }
    rep(i, 0, K) {
        // BFS
        queue<pair<int, int>> Q;  // {index, depth}
        vector<bool> visited(N, false);
        Q.push({C[i], 0});
        visited[C[i]] = true;
        while (!Q.empty()) {
            pair<int, long long> node = Q.front();
            Q.pop();
            for (int child : graph[node.first]) {
                if (!visited[child]) {
                    if (C_map.count(child) > 0) {
                        dist[C_map[C[i]]][C_map[child]] = min(
                            dist[C_map[C[i]]][C_map[child]], node.second + 1);
                    }
                    visited[child] = true;
                    Q.push({child, node.second + 1});
                }
            }
        }
    }
    rep(i, 0, K) {
        rep(j, 0, K) {
            if (dist[i][j] == INF) {
                cout << -1;
                return 0;
            }
        }
    }
    vector<vector<ll>> dp(K, vector<ll>(1 << K, INF));
    rep(i, 0, K) { dp[i][1 << i] = 0; }
    rep(mask, 0, 1 << K) {
        rep(i, 0, K) {
            if ((mask & (1 << i)) != 0) {
                rep(j, 0, K) {
                    if (i != j && (mask & (1 << j)) != 0) {
                        // dp[j][mask ^ (1 << i)] != INF &&
                        // dp[j][mask ^ (1 << i)] + dist[i][j] < dp[i][mask]

                        dp[i][mask] =
                            min(dp[i][mask],
                                min(dp[j][mask ^ (1 << i)] + dist[i][j],
                                    dp[j][mask] + dist[i][j]));
                    }
                }
            }
        }
    }
    ll answer = INF;
    rep(i, 0, K) { answer = min(answer, dp[i][(1 << K) - 1]); }
    cout << answer + 1;
    return 0;
}


#include<bits/stdc++.h>
#define Woody
#ifdef Woody
#define quick ios::sync_with_stdio(0);cin.tie(0);
#else
#define quick
#endif
#define int long long
#define rep(n) for(int i=0;i<n;i++)
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define mp make_pair
#define vi vector<int>
#define eb emplace_back
#define F first
#define S second
using namespace std;
signed main(){
	quick
	int X;
	while(cin>>X){
		int k=X/100+1;
		cout<<k*100-X<<"\n";
	}
}

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

typedef long long ll;

int main() {
  ll n;
  cin>>n;
  set<ll> st;
  for(ll a = 2; a * a <= n; a++) {
      for(ll b = a * a; b <= n; b *= a) {
          st.insert(b);
      }
  }
  cout<<n - (ll)st.size();
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define x first
#define y second
#define FOR(i, m, n) for (ll i(m); i < n; i++)
#define DWN(i, m, n) for (ll i(m); i >= n; i--)
#define REP(i, n) FOR(i, 0, n)
#define DW(i, n) DWN(i, n, 0)
#define F(n) REP(i, n)
#define FF(n) REP(j, n)
#define D(n) DW(i, n)
#define DD(n) DW(j, n)
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using tll = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vpll = vector<pll>;
using vtll = vector<tll>;
using gr = vector<vll>;
using wgr = vector<vpll>;
void add_edge(gr&g,ll x, ll y){ g[x].pb(y);g[y].pb(x); }
void add_edge(wgr&g,ll x, ll y, ll z){ g[x].eb(y,z);g[y].eb(x,z); }
template<typename T,typename U>
ostream& operator<<(ostream& os, const pair<T,U>& p) {
    cerr << ' ' <<  p.x << ',' << p.y; return os; }
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    for(auto x: v) os << ' ' <<  x; return os; }
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
    for(auto x: v) os << ' ' <<  x; return os; }
template<typename T,typename U>
ostream& operator<<(ostream& os, const map<T,U>& v) {
    for(auto x: v) os << ' ' <<  x; return os; }
struct d_ {
    template<typename T> d_& operator,(const T& x) {
        cerr << ' ' <<  x; return *this;}
} d_t;
#define dbg(args ...) { d_t,"|",__LINE__,"|",":",args,"\n"; }
#define deb(X ...) dbg(#X, "=", X);
#define EPS (1e-10)
#define INF (1LL<<61)
#define YES(x) cout << (x ? "YES" : "NO") << endl;
#define CL(A,I) (memset(A,I,sizeof(A)))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

ll mod(ll a, ll b) {
  return ((a%b)+b)%b;
}
ll extended_euclid(ll a,ll b,ll &x,ll &y) {
    if (a == 0) { x = 0; y = 1; return b;}
    ll x1, y1; ll d = extended_euclid(b%a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}

ll mod_inverse(ll a, ll n) {
  ll x, y;
  ll d = extended_euclid(a, n, x, y);
  if (d > 1) return -1;
  return mod(x,n);
}

void linear_diophantine(ll a, ll b, ll c, ll &x, ll &y) {
  ll d = __gcd(a,b);
  if (c%d) {
    x = y = -INF;
  } else {
    x = c/d * mod_inverse(a/d, b/d);
    y = (c-a*x)/b;
  }
}

void solve() {
    ll x,y,p,q; cin >> x >> y >> p >> q;
    ll u = 2*(x+y); ll v = p+q;
    ll ret = INF;
    FOR(X,x,x+y) FOR(Y,p,p+q) {
        ll k,l;
        linear_diophantine(u,-v,Y-X, k,l);
        if(k==-INF && l==-INF) continue;
        ll g = __gcd(u,v);
        ll s = v/g;
        if(k<0) k += ((-k+s-1)/s)*s;
        else k-= s*(k/s);
        ret = min(ret, k*u+X);
    }
    cout << (ret==INF?"infinity":to_string(ret)) << endl;
}

int main(void) {
    ios_base::sync_with_stdio(false);
    ll _T; cin >> _T;
    REP(_,_T) solve();
    return 0;
}

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

tuple<long long, long long, long long> ext_gcd(long long a, long long b) {
  if (b == 0) return {a, 1, 0};
  auto [gcd, y, x] = ext_gcd(b, a%b);
  y -= a/b * x;
  return {gcd, x, y}; // a*x + b*y = gcd
}

pair<long long,long long> crt(const vector<long long> &r, const vector<long long> &m) {
  /* return x that satisfies x = a mod b, for a in r, for b in m */
  /* O(n log lcm(m[i]))*/
  assert(r.size() == m.size());
  auto mod=[&](long long a,long long k){return (a%k+k)%k;}; // a mod k for negative a
  long long y = 0, lcm = 1; int n = r.size();
  for(int i=0; i<n; ++i) {
    assert(m[i] > 0);
    auto [g, p, q] = ext_gcd(lcm, m[i]);
    long long ry = mod(r[i],m[i]) - y;
    if(ry % g) return make_pair(0,0); // no solution exists
    long long s = ry / g * p % (m[i]/g);
    y = mod(y+lcm*s, lcm*(m[i]/g));
    lcm *= m[i] / g;
  }
  return make_pair(y, lcm); // x = y mod lcm
}

int main() {
  int T; cin >> T;
  while(T--) {
    int x,y,p,q; cin >> x >> y >> p >> q;
    const long long INF = 2e18;
    long long ans = INF;
    for(int a=x; a<x+y; ++a) for(int b=p; b<p+q; ++b) {
      // t = a mod (2x+2y)
      // t = b mod (p+q)
      vector<long long> r(2),m(2);
      r[0] = a, r[1] = b, m[0] = 2*(x+y), m[1] = p+q;
      auto [t,lcm] = crt(r,m);
      if(lcm) ans = min(ans,t);
    }
    if (ans == INF) cout << "infinity" << endl;
    else cout << ans << endl;
  }
}


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

int mod = 998244353;
long long dp[30][5005];

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

void COMinit() {
    fac[0] = fac[1] = finv[0] = finv[1] = inv[1] = 1;
    for(int i = 2; i <= 5000; 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() {
    int N,M;
    cin >> N >> M;
    dp[0][0] = 1;
    COMinit();
    for(int i = 0; i < 13; i++) {
        for(int j = 0; j <= N; j+=2) {
            for(int k = 0; k <= M; k++) {
                long long l = k+(j << i);
                if(l <= M) {
                    dp[i+1][l] += dp[i][k]*COM(N,j)%mod;
                    dp[i+1][l] %= mod;
                }
            }
        }
    }
    cout << dp[13][M] << endl;
}

#include<cstdio>
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define ll long long
#define I int
#define R read()
#define V void
using namespace std;
const I N=5005,mo=998244353;
I i,j,k,n,m,mc,num;
I dl[13];
ll f[14][N];
I jc[13];
I jc2[N],ny[N];
ll ch;
I R
{
	I x=0,ef=1;char s=getchar();
	while ((s<'0')||(s>'9')){if (s=='-')ef=-1;s=getchar();}
	while ((s>='0')&&(s<='9')) x=(x<<1)+(x<<3)+(s-'0'),s=getchar();
	return x*ef;
}
I ksm(I x,I y)
{
	ll l=x,r=1;I z=y;
	while (z)
	{
		if (z%2==1)r=r*l%mo;
		l=l*l%mo;z=z/2;
	}
	return r;
}
I C(I x,I y)
{
	ch=jc2[x];ch=ch*ny[y]%mo*ny[x-y]%mo;return ch;
}
I main()
{
	n=R;m=R;mc=m;
	while (mc){num++;dl[num]=mc%2;mc/=2;}
	jc[0]=1;fo(i,1,12){jc[i]=jc[i-1]*2;}
	ch=1;jc2[0]=1;ny[0]=1;fo(i,1,n){ch=ch*i%mo;jc2[i]=ch;}
	ch=ksm(ch,mo-2);ny[n]=ch;
	fd(i,n-1,1){ch=ch*(i+1)%mo;ny[i]=ch;}
	f[0][m]=1;
	fo(i,0,num-1)
	{
		fd(j,m,0)
		{
			if (f[i][j])
			{
			fo(k,0,n/2)
			{
				if (j/jc[i]<k*2)break;
				f[i+1][j-jc[i]*k*2]=(f[i+1][j-jc[i]*k*2]+f[i][j]*C(n,k*2))%mo;
			}
			}
		}
	}
	printf("%d\n",f[num][0]);
	fclose(stdin);
	fclose(stdout);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
  long long N;
  cin >> N;
  set<long long> st;
  for (long long i = 2; i * i <= N; i++){
    long long c = i;
    while (true){
      c *= i;
      if (c > N){
        break;
      }
      st.insert(c);
    }
  }
  cout << N - st.size() << endl;
}

#include<bits/stdc++.h>
#include<iostream>
#include<set>
#include<map>
#include<iterator>
#define ll              long long
#define lli             long long int
#define pb              push_back
#define mp              make_pair
#define RIP(i,n)        for(int i=0; i<n; i++)
#define F(i,a,b)        for(int i=a; i<b; i++)
#define RIP1(i,n)       for(int i=n-1; i>=0; i--)
#define FOR(i,a,b)      for(int i=a;i<(b); i++)
#define FOR1(i,a,b)     for(int i=a; i>=(b); i--)
#define sc(a)           scanf("%lld",&a)
#define SC(a)           scanf("%d",&a)
#define cin(a)          cin >> a
#define cout(a)         cout << a
#define pi              acos(-1)
#define pr(a)           printf("%lld\n",a)
#define PR(a)           printf("%lld ",a)
#define s(a,b)          sort(a,b)
#define sz(x)           (int)(x).size()
#define nl              '\n'
#define Max             10000000000
#define mod             1e9+7
using namespace std;
void F_I_O()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int main()
{
    ll n;
    cin >> n;
    ll ans=0;
    ll cnt=0;
    map<ll,ll>m;
    //set<ll>s;
   for(ll i=2; i*i<=n; i++)
    {
        ll r = sqrt(i);
        if(r*r!=i)
        {
            for(ll j=i*i; j<=n; j = j*i)
            {
                if(m[j]==0)
                {
                    ans++;
                    m[j]=1;
                }
            }
        }
    }
   /* for(ll i=2; i*i<=n; i++)
    {
        ll r = sqrt(i);
        if(r*r!=i)
        {
            double e = double(n);
            double f = double(i);
            ll p = (double)log(e)/(double)log(f);
            p++;
            ll g = pow(i,p);
            cout << p << ' ' << g << nl;
            if(g<=n)
            {
                ans+=(p-1);
            }
            else
            {
                ans+=(p-2);
            }
        }
    }*/
   n-=ans;
    cout << n<< nl;
}


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

vector<string> split(const string & s, char c=' ') {
   vector<string> v; stringstream ss(s); string x;
   while (getline(ss, x, c)) v.emplace_back(x); return move(v);
}
template<typename T, typename... Args>
inline string arrStr(T arr, int n) {
   stringstream s; s << "[";
   for(int i = 0; i < n - 1; i++) s << arr[i] << ",";
   s << arr[n - 1] << "]";
   return s.str();
}
#define EVARS(args...) {__evars_begin(__LINE__); __evars(split(#args, ',').begin(), args);}
inline void __evars_begin(int line) { cerr << "#" << line << ": "; }
template<typename T> inline void __evars_out_var(vector<T> val) { cerr << arrStr(val, val.size()); }
template<typename T> inline void __evars_out_var(T* val) { cerr << arrStr(val, 10); }
template<typename T> inline void __evars_out_var(T val) { cerr << val; }
inline void __evars(vector<string>::iterator it) { cerr << endl; }
template<typename T, typename... Args>
inline void __evars(vector<string>::iterator it, T a, Args... args) {
   cerr << it->substr((*it)[0] == ' ', it->length()) << "=";
   __evars_out_var(a);
   cerr << "; ";
   __evars(++it, args...);
}
template<typename T>
void maxa(T &a,T b){
  if(a<b) a=b;
}
template<typename T>
void mina(T &a,T b){
  if(a>b) a=b;
}

#define int long long
const int inf=1e18;
#define F first
#define S second
#define Z(c) (int)(c).size()
#define pii pair<int,int>
const int mod=1e9+7;
const int N=3e5+15;

  int n,k,tt;
  int a[808][808];
  int c[808][808];

  bool chk(int m){

     for(int i=1;i<=n;++i){
        for(int j=1;j<=n;++j){
           if(a[i][j]<=m) c[i][j]=1;
           else c[i][j]=0;
           c[i][j]+=c[i-1][j]+c[i][j-1]-c[i-1][j-1];
        }
     }

     for(int i=1;i<=n;++i){
         for(int j=1;j<=n;++j){
             if(i+k-1<=n&&j+k-1<=n){
                  int sm=c[i+k-1][j+k-1]+c[i-1][j-1]-c[i+k-1][j-1]-c[i-1][j+k-1];
                  // EVARS(i,j,sm);
                  if(sm>=tt) return true;
             }
         }
     }

     return false;
  }
  void boomer(){

      cin>>n>>k;
      tt=(k*k)/2;
      tt=k*k-tt;

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

      int lw=0,hg=1e9,mid;

      // EVARS(chk(3));

      while(lw<hg){
         mid=(lw+hg)/2;

         if(chk(mid))
          hg=mid;
         else
          lw=mid+1;
      }

      cout<<hg;
  }
  signed main()
  {
  ios_base::sync_with_stdio(0); cin.tie(0);

  int tc=1;

  // cin>>tc;
  for(int i=1;i<=tc;++i)
  {
  // cout<<"Case #"<<i<<": ";
  boomer();
  if(i<tc)
  cout<<"\n";
  }

  return 0;
  }

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

#define ll long long
typedef pair <int, int> ii;
typedef pair <ll, int> lli;
#define ar array
#define pb push_back
#define fi first
#define se second
#define sz size
#define mp make_pair
#define nl '\n'
#define all(x) (x).begin(), (x).end()
#define int_max numeric_limits<int>::max()
#define int_min numeric_limits<int>::min()
#define ll_max numeric_limits<ll>::max()
#define ll_min numeric_limits<ll>::min()

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define im(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

// custom sort example
//sort(all(a), [ ]( const auto& c, const auto& d) {
	//if (c.fi.se != d.fi.se) {
		//return c.fi.se < d.fi.se; // lower first
	//}
	//if (c.fi.fi != d.fi.fi) {
		//return c.fi.fi > d.fi.fi; // higher first
	//}
	//return c.se > d.se; // higher first
//});

struct chash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

template <class T>
auto lbf(const std::set<std::pair<T, T>>& s, T first)
{
   static constexpr T min = std::numeric_limits<T>::min();

   return s.lower_bound({first, min});
}

int MOD = 1000000007;

ll pw(ll n, ll k) {
	ll r = 1;
	for(; k; k >>= 1) {
		if(k&1) r = r * n % MOD;
		n = n * n % MOD;
	}
	return r;
}
ll inv(ll n) { return pw(n, MOD-2); }

int main () {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	//vector<vector<int>> h(100, vector<int>());
	vector<vector<vector<double>>> a(101, vector<vector<double>>(101, vector<double>(101)));
	int b, c, d;
	cin >> b >> c >> d;
	for (int i = 0; i < 101; i++) {
		for (int j = 0; j < 101; j++) {
			for (int k = 0; k < 101; k++) {
				a[i][j][k] = 0;
			}
		}
	}
	a[b][c][d] = 1;
	for (int i = 0; i < 100; i++) {
		for (int j = 0; j < 100; j++) {
			for (int k = 0; k < 100; k++) {
				if (a[i][j][k] == 0) {
					continue;
				}
				double pom = (double) i / (double) (i + j + k);
				a[i + 1][j][k] = max(a[i + 1][j][k], 0.0) + pom * a[i][j][k];
				pom = (double) j / (double) (i + j + k);
				a[i][j + 1][k] = max(a[i][j + 1][k], 0.0) + pom * a[i][j][k];
				pom = (double) k / (double) (i + j + k);
				a[i][j][k + 1] = max(0.0, a[i][j][k + 1]) + pom * a[i][j][k];
			}
		}
	}
	double res = 0;
	for (int i = 0; i < 100; i++) {
		for (int j = 0; j < 100; j++) {
			res = res + a[100][i][j] * ((100 - b) + (i - c) + (j - d));
		}
	}
	for (int i = 0; i < 100; i++) {
		for (int j = 0; j < 100; j++) {
			res = res + a[i][100][j] * ((100 - c) + (i - b) + (j - d));
		}
	}
	for (int i = 0; i < 100; i++) {
		for (int j = 0; j < 100; j++) {
			res = res + a[i][j][100] * ((100 - d) + (i - b) + (j - c));
		}
	}
	//debug() << a;
	cout << setprecision(10);
	cout << res << nl;
}


#include <bits/stdc++.h>
#include <chrono>
#include <ctime>
using namespace std;
using namespace std::chrono;
using i64 = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
constexpr int INF = 1001001001;

constexpr bool is_multiple = false;

struct Rect {
    int x1, y1, x2, y2;

    Rect() {}
    Rect(int a, int b, int c, int d) { x1 = a; y1 = b; x2 = c; y2 = d; }

    int get_area() {
        return (x2 - x1) * (y2 - y1);
    }

    bool is_valid() {
        return x1 < x2 && y1 < y2;
    }
};

Rect merge(Rect a, Rect b) {
    return (Rect){max(a.x1, b.x1), max(a.y1, b.y1), min(a.x2, b.x2), min(a.y2, b.y2)};
}

// 共通部分が存在しない判定
// 計算量: O(n)
bool is_ok(vector<Rect>& v, int i) {
    int n = v.size();

    bool flag = true;

    rep(j, n) {
        if (i == j) continue;

        auto mg = merge(v[i], v[j]);

        if (mg.is_valid()) flag = false;
    }

    return flag;
}

// スコア計算
// 計算量: O(n)
i64 calc_score(vector<Rect>& v, vec& r) {
    int n = r.size();
    double res = 0;

    rep(i, n) {
        int s = v[i].get_area();
        double t = (double)(min(r[i], s)) / max(r[i], s);
        res += 1 - (1 - t) * (1 - t);
    }

    res *= 1000000000;
    res /= n;

    i64 ret = round(res);

    return ret;
}

static uint32_t randXor()
{
    static uint32_t x = 123456789;
    static uint32_t y = 362436069;
    static uint32_t z = 521288629;
    static uint32_t w = 88675123;
    uint32_t t;

    t = x ^ (x << 11);
    x = y; y = z; z = w;
    return w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
}

static double next_double() {
    return (randXor() + 0.5) * (1.0 / UINT_MAX);
}

constexpr int expand_diff = 1;

bool modify(vector<Rect>& rects, vec& r, double prog) {
    int n = rects.size();
    int i = randXor() % n;

    // if (rects[i].get_area() >= r[i]) return;

    int side = randXor() % 4;

    if (side == 0 && rects[i].x1-expand_diff >= 0) rects[i].x1 -= expand_diff;
    else if (side == 1 && rects[i].y1-expand_diff >= 0) rects[i].y1 -= expand_diff;
    else if (side == 2 && rects[i].x2+expand_diff <= 10000) rects[i].x2 += expand_diff;
    else if (side == 3 && rects[i].y2+expand_diff <= 10000) rects[i].y2 += expand_diff;

    return is_ok(rects, i);
}

void solve() {
    int n;
    cin >> n;
    vec x(n), y(n), r(n);
    rep(i, n) cin >> x[i] >> y[i] >> r[i];

    vector<Rect> rects(n);
    // 初期化
    rep(i, n) {
        rects[i] = (Rect){x[i], y[i], x[i]+1, y[i]+1};
    }

    // 焼きなまし
    auto startClock = system_clock::now();

    const double start_temp = 1250;
    const double end_temp = 50;
    const double end_time = 4.8;

    double time = 0.0;

    do {
        const double progress_ratio = time / end_time;

        auto new_rects = rects;
        bool flag = modify(new_rects, r, progress_ratio);
        if (!flag) continue;

        auto new_score = calc_score(new_rects, r);
        auto pre_score = calc_score(rects, r);
        auto delta_score = new_score - pre_score;

        double temp = start_temp + (end_temp - start_temp) * progress_ratio;

        double prob = exp(delta_score / temp);

        if (prob > next_double()) {
            rects = new_rects;
        }

        time = (duration_cast<microseconds>(system_clock::now() - startClock).count() * 1e-6);
    }
    while (time < end_time);

    // printf("\n");

    rep(i, n) printf("%d %d %d %d\n", rects[i].x1, rects[i].y1, rects[i].x2, rects[i].y2);

    // auto l_sc = calc_score(rects, r);
    // cout << fixed << setprecision(15) << l_sc * 1e-9 << endl;
}

int main() {
    int t = 1;
    if (is_multiple) cin >> t;
    while (t--) solve();
    return 0;
}

#include <bits/stdc++.h>
#define CIT_MARK ios_base::sync_with_stdio(false);cin.tie(nullptr);
#define ll long long
#define pll pair<ll,ll>
#define pb push_back
#define M 1000000007
#define lc '\n'
using namespace std;
int main()
{
    CIT_MARK
    ll n;
    cin>>n;
    ll a[n][5];
    for(ll i=0;i<n;i++)
    {
        for(ll j=0;j<5;j++)
        {
            cin>>a[i][j];
        }
    }
    auto check=[&](ll mid){
        set<ll> st;
        for(ll i=0;i<n;i++)
        {
            ll val=0;
            for(ll j=0;j<5;j++)
            {
                if(a[i][j]>=mid)
                {
                    val+=pow(2LL,j);
                }
            }
            st.insert(val);
        }
        for(auto i:st)
        {
            for(auto j:st)
            {
                for(auto k:st)
                {
                    if((i | j | k)== 31)
                    {
                        return true;
                    }
                }
            }
        }
        return false;
    };
    ll l=0,r=1e9;
    ll ans=0;
    while(l<=r)
    {
        ll mid=(l+r)/2;
        bool is=check(mid);
        if(is)
        {
            ans=mid;
            l=mid+1;
        }
        else
        {
            r=mid-1;
        }
    }
    cout<<ans<<lc;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n){
    cin >> a.at(i);
  }
  ll ans=0,maxi=0;
  rep(i,n){
    ll mini=1e8;
    for(ll j=i;j<n;j++){
      mini=min(mini,a.at(j));
      maxi=mini*(j-i+1);
      ans=max(ans,maxi);
    }
  }
  cout << ans;
}

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

long long arr[100005];
int s[100005], top=0;
int l[100005], r[100005];

int main(){
	int n;
	cin >> n;
	arr[0] = arr[n+1] = -1;
	for (int i=1; i<=n; i++) cin >> arr[i];
	for (int i=1; i<=n; i++){
		while (arr[s[top]]>=arr[i]) top--;
		l[i] = i-s[top];
		s[++top]=i;
	}
	top=0;
	s[0]=n+1;
	for (int i=n; i>=1; i--){
		while (arr[s[top]]>=arr[i]) top--;
		r[i] = s[top]-i;
		s[++top]=i;
	}
	long long ans=0;
	for (int i=1; i<=n; i++){
		ans = max(ans, arr[i]*(l[i]+r[i]-1));
	}
	cout << ans;
	return 0;
}


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

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for(auto it = d.b;it != d.e;++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

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

  int a, b;cin >> a >> b;
  double ans = double(a - b) / (double)a;
  printf("%.9f\n", ans * 100.0);
}

/*
  Author     : MatsuTaku
  Date         : 03/27/21
  Certificate:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDF9T447OEo8XSQ6O1AznN5tKC8mzvYc4Zs3+oOKfMqgLXfOwQnpfcoxKs4MAP1eICBD13PkcIezJ9IlV6nKQZKs1BQmvjSXJ+zKK8YCKvAueNPuNO0Bim43IBaNHNFWcMvcmUvHgRb6hUSO0V8I7OsjiFo20KDBj3gAznu9tir0Q== CompetitiveProgrammingCertification:tkm.matsumoto@gmail.com
*/

#include <bits/stdc++.h>
using namespace std;
#include <x86intrin.h>
#define REP(i, f, n)      for (auto i = (f), i##_len = (n); i < i##_len; i++)
#define rep(i, n)         REP(i, (int) 0, n)
#define RREP(i, f, n)     for (auto i = (n)-1, i##_left = (f); i >= i##_left; i--)
#define rrep(i, n)        RREP(i, (int) 0, n)
using lint = long long int;
using ulint = unsigned long long int;
template<typename T>
using vvec = vector<vector<T>>;
template<typename T>
vvec<T> make_vvec(int n, int m, T v) { return vvec<T>(n, vector<T>(m, v)); }
template<typename T>
T& chmax(T& dst, T x) { return dst = max(dst, x); }
template<typename T>
T& chmin(T& dst, T x) { return dst = min(dst, x); }

class Solver {
 public:
  Solver();
  void solve();
};

Solver::Solver() {}

void Solver::solve() {
  int n,m; cin>>n>>m;
  vector<pair<int,char>> G[n];
  vector<pair<int,int>> E(m);
  auto id = [n](int a, int b) {
    if (a > b) swap(a,b);
    return a*n+b;
  };
  rep(i, m) {
    int a,b; char c; cin>>a>>b>>c;
    a--; b--;
    G[a].emplace_back(b,c-'a');
    G[b].emplace_back(a,c-'a');
    E[i] = {a,b};
  }
  vector<array<vector<int>, 26>> T(n);
  rep(i, n) {
    for (auto [t,c] : G[i]) {
      T[i][c].push_back(t);
    }
  }
  vector<int> W[n*n];
  rep(i, n) {
    REP(j, i, n) {
      auto s = id(i, j);
      rep(k, 26) {
        auto& l = T[i][k];
        auto& r = T[j][k];
        if (l.empty() or r.empty()) continue;
        for (auto u : l) {
          for (auto v : r) {
            auto t = id(u, v);
            W[s].push_back(t);
          }
        }
      }
    }
  }
  queue<int> qs;
  constexpr int INF = 1e9;
  vector<int> dist(n*n, INF);
  qs.push(id(0, n-1));
  dist[id(0, n-1)] = 0;
  while (!qs.empty()) {
    auto s = qs.front(); qs.pop();
    auto d = dist[s];
    for (auto t:W[s]) {
      if (dist[t] <= d+1) continue;
      dist[t] = d+1;
      qs.push(t);
    }
  }
  int ans = INF;
  rep(i, n) {
    chmin(ans, dist[id(i, i)]*2);
  }
  for (auto [a,b] : E) {
    chmin(ans, dist[id(a, b)]*2+1);
  }
  cout << (ans != INF ? ans : -1) << endl;
}

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(10);
  Solver solver;
  int t = 1;
//  cin>>t;
  while (t--) {
    solver.solve();
  }
  return 0;
}


#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

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

const int MOD = 1000000007;
const char nl = '\n';
const int MX = 200001; //check the limits, dummy

const ll identity = 0;
const ll SZ = 131072*2;

ll sum[2*SZ], lazy[2*SZ];

ll combine(ll A, ll B) {
    return A+B;
}

ll combineUpd(ll A, ll B) {
    return A+B;
}

void push(int index, ll L, ll R) {
    sum[index] = combineUpd(sum[index], lazy[index]);
    if (L != R) lazy[2*index] = combineUpd(lazy[2*index], lazy[index]), lazy[2*index+1] = combineUpd(lazy[2*index+1], lazy[index]);
    lazy[index] = identity;
}

void pull(int index) {
    sum[index] = combine(sum[2*index], sum[2*index+1]);
}

ll query(int lo, int hi, int index = 1, ll L = 0, ll R = SZ-1) {
    push(index, L, R);
    if (lo > R || L > hi) return identity;
    if (lo <= L && R <= hi) return sum[index];

    int M = (L+R) / 2;
    return combine(query(lo, hi, 2*index, L, M), query(lo, hi, 2*index+1, M+1, R));
}

void update(int lo, int hi, ll increase, int index = 1, ll L = 0, ll R = SZ-1) {
    push(index, L, R);
    if (hi < L || R < lo) return;
    if (lo <= L && R <= hi) {
        lazy[index] = increase;
        push(index, L, R);
        return;
    }

    int M = (L+R) / 2;
    update(lo, hi, increase, 2*index, L, M); update(lo, hi, increase, 2*index+1, M+1, R);
    pull(index);
}

vector<vi> graph(MX);
int tin[MX], tout[MX], ct = 0;
void dfs(int v, int p) {
    tin[v] = ct;
    ct++;
    trav(a, graph[v]) {
        if (a == p) continue;
        dfs(a, v);
    }
    tout[v] = ct-1;
}

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

    int N; cin >> N;
    vector<pi> edges;
    F0R(i, N-1) {
        int X, Y; cin >> X >> Y; X--; Y--; graph[X].pb(Y); graph[Y].pb(X);
        edges.pb({X, Y});
    }
    dfs(0, 0);
    int Q; cin >> Q;
    while(Q--) {
        int T, E, X; cin >> T >> E >> X;
        E--;
        int A = edges[E].f, B = edges[E].s;
        if (T == 2) swap(A, B);
        if (tin[B] < tin[A]) {
            update(tin[A], tout[A], X);
        } else {
            update(0, SZ-1, X);
            update(tin[B], tout[B], -X);
        }
    }
    F0R(i, N) {
        cout << query(tin[i], tin[i]) << nl;
    }

	return 0;
}

// read the question correctly (ll vs int)
// template by bqi343

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int,int>;
vector<vector<int>> es;
vector<int> depth;
void depth_dfs(int v, int pv=-1, int d=0) {
  depth[v] = d;
  for (int nv : es[v]) {
    if (nv == pv) continue;
    depth_dfs(nv, v, d+1);
  }
}
vector<ll> dp;
void imos_dfs(int v, int pv=-1) {
  if (pv>=0) dp[v] += dp[pv];
  for (int nv : es[v]) {
    if (nv == pv) continue;
    imos_dfs(nv, v);
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  es.resize(n);
  vector<int> a(n-1), b(n-1);
  rep(i,n-1) {
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
    es[a[i]].push_back(b[i]);
    es[b[i]].push_back(a[i]);
  }
  depth.resize(n);
  depth_dfs(0);
  int q;
  cin >> q;
  dp.resize(n+5);
  rep(qi, q) {
    int t,e,x;
    cin >> t >> e >> x;
    e--;
    if (t == 1) {
      if (depth[a[e]] < depth[b[e]]) {
        dp[0] += x;
        dp[b[e]] -= x;
      } else {
        dp[a[e]] += x;
      }
    } else {
      if (depth[a[e]] < depth[b[e]]) {
        dp[b[e]] += x;
      } else {
        dp[0] += x;
        dp[a[e]] -= x;
      }
    }
  }
  imos_dfs(0);
  rep(i,n) cout << dp[i] << endl;
  return 0;
}


#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define ins insert

#define debug(a) cerr<<(a)<<endl
#define dbrep(a,n) rep(_i,n) cerr<<(a[_i])<<" "; cerr<<endl
#define dbrep2(a,n,m) rep(_i,n){rep(_j,m) cerr<<(a[_i][_j])<<" "; cerr<<endl;}

using namespace std;

template<class A, class B>
ostream &operator<<(ostream &os, const pair<A,B> &p){return os<<"("<<p.fi<<","<<p.se<<")";}
template<class A, class B>
istream &operator>>(istream &is, pair<A,B> &p){return is>>p.fi>>p.se;}

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

/* Some Libraries */

//-------------------------------------------------

ll comb[61][32];

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A,B,K; cin>>A>>B>>K;

    comb[0][0] = 1;
    rep(i,60)rep(j,31){
        comb[i+1][j]+=comb[i][j];
        comb[i+1][j+1]+=comb[i][j];
    }

    int len = A+B;
    rep(i,len){
        if (A>0 && K<=comb[A+B-1][A-1]){
            cout<<'a';
            A--;
        }else{
            if (A>0) K-=comb[A+B-1][A-1];
            cout<<'b';
            B--;
        }
    }
    cout<<"\n";
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define F first
#define S second
#define um map <ll,ll>
#define rep(i,z,n)  for(int i=z;i<n;i++)
#define repi(i,z,n) for(int i=z;i<=n;i++)
#define repn(i,z,n) for(int i=n-1;i>=z;i--)
#define vec vector<ll>
#define vecp vector<pair<ll,ll>>
#define pi (double)3.14159265358979323846
#define ld long double
#define all(z) z.begin(),z.end()

ll power(ll a, ll b, ll m) { ll ans = 1; a = a % m; if (a == 0) return 0; while (b) { if (b & 1) ans = (ans * a) % m; b /= 2; a = (a * a) % m; } return ans; }
ll modInverse(ll a, ll m) {return power(a, m - 2, m);}
ll binpow(ll a, ll b) {ll res = 1; while (b > 0) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;}
ll binlog2(ll n) {ll logValue = -1; while (n) {logValue++; n >>= 1;} return logValue;}
ll ceil(ll t1, ll t2) {ll ans = (t1 + t2 - 1) / t2; return ans;}
void print(vec a) {rep(i, 0, a.size())cout << a[i] << " "; cout << endl;}
const ll mod = 1e9 + 7;
const ll N = 2e3 + 5;
const ll inf = 2e18;

ll n, m;
char a[N][N];
ll dp[N][N];
ll ph[N][N];
ll pv[N][N];
ll pd[N][N];

void recur(ll i, ll j) {
    if (i == 1 && j == 1) {
        return;
    }

    if (i <= 0 || j <= 0 || a[i][j] == '#')
        return;

    if (dp[i][j] != -1)
        return ;

    recur(i - 1, j);
    recur(i, j - 1);
    recur(i - 1, j - 1);

    dp[i][j] = (ph[i - 1][j] + pv[i][j - 1] + pd[i - 1][j - 1]) % mod;
    ph[i][j] = dp[i][j];
    pv[i][j] = dp[i][j];
    pd[i][j] = dp[i][j];
    ph[i][j] += ph[i - 1][j] ;
    pv[i][j] += pv[i][j - 1] ;
    pd[i][j] += pd[i - 1][j - 1];
    ph[i][j] %= mod;
    pv[i][j] %= mod;
    pd[i][j] %= mod;

}

void solve() {
    cin >> n >> m;
    rep(i, 1, n + 1)
    rep(j, 1, m + 1) {
        cin >> a[i][j];
    }

    repi(i, 0, n + 3)
    repi(j, 0, m + 3)
    dp[i][j] = -1;

    dp[1][1] = 1;
    ph[1][1] = 1;
    pd[1][1] = 1;
    pv[1][1] = 1;
    recur(n, m);
    cout << dp[n][m] << endl;
    // repi(i, 1, n) {
    //     repi(j, 1, m) {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }

}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    speed;
    int test = 1;
    // init();
    // cin >> test;
    // ll t1 = 1;
    while (test--) {
        // cout << "Case #" << t1 << ": ";
        solve();
        // t1++;
    }
    return 0;
}


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

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

struct mint {
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

//組み合わせ計算
mint choose(int n, int a) {
  mint x = 1, y = 1;
  rep(i,a) {
    x *= n-i;
    y *= i+1;
  }
  return x / y;
}

//繰り返し二乗法
mint f(int n) {
  if (n == 0) return 1;
  mint x = f(n/2);
  x *= x;
  if (n%2 == 1) x *= 2;
  return x;
}

int main(){
    ll h,w;
    cin >> h >> w;
    char grid[2005][2005];
    rep(i,h)rep(j,w){
        cin >> grid[i][j];
    }

    mint kazu[2005][2005];
    rep(i,h){
        rep(j,w){
            kazu[i][j]=0;
        }
    }

    kazu[0][0]=1;
    mint houkou[2005][2005][3];

    rep(i,h){
        rep(j,w){
            rep(k,3){
                houkou[i][j][k]=0;
            }
        }
    }

    houkou[0][0][0]=0;
    houkou[0][0][1]=0;
    houkou[0][0][2]=0;

    for(ll i=0;i<h;i++){
        for(ll j=0;j<w;j++){
            if(i!=0||j!=0){
                if(grid[i][j]=='.'){
                    kazu[i][j]=houkou[i][j][0]+houkou[i][j][1]+houkou[i][j][2];
                }
            }
            if(grid[i][j]=='#') continue;
            houkou[i+1][j][0]=houkou[i][j][0]+kazu[i][j];
            houkou[i+1][j+1][1]=houkou[i][j][1]+kazu[i][j];
            houkou[i][j+1][2]=houkou[i][j][2]+kazu[i][j];
        }
    }

    cout << kazu[h-1][w-1] << endl;

    return 0;
}

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define FAST  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define int long long
#define ll int
#define ull unsigned long long
#define all(a) a.begin(),a.end()
#define rev(a) a.rbegin(),a.rend()
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; //less_equal for multiset
#define ar array
#define pb push_back
#define fi(a,b) for(int i=a;i<(b);i++)
#define fj(a,b) for(int j=a;j<(b);j++)
#define fk(a,b) for(int k=a;k<(b);k++)
const double pi=acosl(-1);

int x,y;
map<int,int> mapka;
int rec(int val)
{
	if(mapka.find(val)!=mapka.end()) return mapka[val];
	if(val<=x)
	{
		return mapka[val]=x-val;
	}
	mapka[val]=val-x;
	if(val%2==0)
	{
		mapka[val]=min(mapka[val],1+rec(val/2));
	}
	else
	{
		mapka[val]=min({mapka[val],2+rec((val+1)/2),2+rec((val-1)/2)});
	}
	return mapka[val];

}

void solve()
{
	cin>>x>>y;
	if(x>=y)
	{
		cout<<x-y<<'\n';
		return ;
	}
	cout<<rec(y);

}

signed main()
{
	FAST;
	int tt=1;
	// cin>>tt;
	while(tt--)
	{
		solve();
	}
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define v(a, n) vector<int> a(n, 0)
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define print(v) rep(i, (int)v.size()) cout << v[i] << (i+1 == (int)v.size() ? "\n" : " ");
#define rfor(i, a, b) for (int i = a; i < b; i++)
const vector<int> maze = {0, 1, 0, -1, 0};
const int mod = 1e9+7;
ll gcd(ll a, ll b) {return b == 0 ? abs(a) : gcd(b, a%b);}
ll lcm(ll a, ll b) {return a*b/gcd(a, b);}
ll extgcd(ll a, ll b, ll &x, ll &y) {
  if (b == 0) {
    x = 1; y = 0;
    return a;
  } else {
    ll d = extgcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
  }
}
ll modpow(ll x, ll n, ll p) {
  ll ans = 1;
  while (n > 0) {
    if (n&1) ans = ans*x%p;
    x = x*x%p;
    n >>= 1;
  }
  return ans;
}
vector<vector<int>> g;
vector<int> depth;
void dfs(int par, int son){depth[son]=depth[par]+1;for(int i : g[son]){if(i==par)continue;dfs(son, i);}}

int main() {int n; cin >>n;vector<pair<int, int>>edge(n-1);g.resize(n);rep(i,n-1){int a,b;cin>>a>>b;a--;b--;edge[i].F=a;edge[i].S=b;g[a].push_back(b);g[b].push_back(a);}int q;cin>>q;vector<vector<int>> query(q,vector<int>(3));rep(i,q)cin>>query[i][0]>>query[i][1]>>query[i][2];depth.resize(n);depth[0]=0;for(int i : g[0])dfs(0,i);vector<ll> cnt(n,0);rep(i,q){int t=query[i][0],c=query[i][2];int a,b;if(t==1){a=edge[query[i][1]-1].F;b=edge[query[i][1]-1].S;}else{a=edge[query[i][1]-1].S;b=edge[query[i][1]-1].F;}if(depth[a]<depth[b]){cnt[0]+=c;cnt[b]-=c;}else{cnt[a]+=c;}}vector<bool> seen(n,false);seen[0]=true;vector<ll> ans(n, 0);ans[0]=cnt[0];queue<int> que;que.push(0);while(!que.empty()){int x=que.front();que.pop();for(int i:g[x]){if(seen[i])continue;seen[i]=true;ans[i]=ans[x]+cnt[i];que.push(i);}}print(ans);
}

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

#define int long long
//#define int unsigned int
#define mod 1000000007
#define double long double
//int d;
int p[200005];
vector <int> adj[200005];
int val[200005];
vector <int> vis(200005);
//vector <vector <int>> v(200005);

/*int fun(int a,int b){
    if(b==0)return 1;
    else if(a==1)return 1;
    int temp=fun(a,b/2)%mod;
    temp=(temp*temp)%mod;
     if(b%2==1)temp=(temp*a)%mod;
    return temp%mod;
}

int inv(int a,int b){
    return (a*fun(b,mod-2))%mod;
}
void dfs(int s){
    if(vis[s])return;
    val[s]+=val[p[s]];
    vis[s]=1;
    for(auto u:adj[s]){
        dfs(u);
    }
}
*/

signed main()
{   /*
   #ifndef ONLINE_JUDGE
   freopen("inputhsr.txt", "r", stdin);
   freopen("outputhsr.txt", "w", stdout);
   #endif
   */
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int i,j,k=0,n,t=1,m,l=0;

    //cin>>t;
    while(t--){
        cin>>n;

       for(i=0;i<=n;i++)vis[i]=0;
       for(i=0;i<=n;i++){
            adj[i].clear();
            val[i]=0;
       }
       vector <pair<int,int>> v;
       for(i=0;i<n-1;i++){
           cin>>l>>m;
           adj[l].push_back(m);
           adj[m].push_back(l);
           v.push_back({l,m});
       }
       //taking 1 ans the root;

       int d[n+1]; //d=distance

       for(i=0;i<=n;i++){d[i]=100000000000;p[i]=0;}
       queue <int> q;

       d[1]=0;     //if 1 is root
       q.push(1);
       vis[1]=1;
       while(!q.empty()){
           int s=q.front();
           q.pop();
           for(auto u:adj[s]){
               if(vis[u])continue;
               vis[u]=1;
               d[u]=d[s]+1;
               p[u]=s;
               q.push(u);
           }
       }

       int q1;
       cin>>q1;
       int sum=0;
       for(i=0;i<=n;i++)vis[i]=0;
       while(q1--){
          int x,y,z;
          cin>>x>>y>>z;
          //val[i]+=z;
          sum+=z;
          y--;
          int v1=v[y].first;
          int v2=v[y].second;
          if(x==1){
              //int v1=v[y].first;
              //int v2=v[y].second;
              if(d[v2]>d[v1]){
                  val[v2]-=z;
              }
              else{
                  val[v1]+=z;
                  val[1]-=z;
              }
          }
          else{
              swap(v1,v2);
              if(d[v2]>d[v1]){
                  val[v2]-=z;
              }
              else{
                  val[v1]+=z;
                  val[1]-=z;
              }

          }

       }
       int ans[n+1];
       for(i=0;i<=n;i++)ans[i]=0;
       q.push(1);
       vis[1]=1;
       while(!q.empty()){
           int s=q.front();
           val[s]+=val[p[s]];
           ans[s]=sum+val[s];
           q.pop();
           for(auto u:adj[s]){
               if(vis[u])continue;
               vis[u]=1;
               //d[u]=d[s]+1;
               //p[u]=s;
               q.push(u);
           }
       }

    for(i=1;i<=n;i++){
        cout<<ans[i]<<"\n";
    }
        //memset(a,0,sizeof(a));
        //cout<<fixed<<setprecision(10)<<ans<<"\n";

    }
    return 0;
}


#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ff(i,a,b) for(int i = a; i <= b; i++)
#define fb(i,b,a) for(int i = b; i >= a; i--)

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> pii;
const int mxN = 200005;
const int inf = 1e9 + 5;

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

// os.order_of_key(k) the number of elements in the os less than k
// *os.find_by_order(k)  print the k-th smallest number in os(0-based)

int n;
ll niz[mxN];

ll pref[mxN];

int main() {
    cin.tie(0)->sync_with_stdio(0);

    cin >> n; ff(i,1,n)cin >> niz[i];

    ff(i,1,n)pref[i] = pref[i - 1] + niz[i];

    ll tren = 0;
    ll mx = 0;
    ff(i,1,n){
        tren += pref[i];
        mx = max(mx, niz[i]);

        ll rez = tren + 1ll * i * mx;
        cout << rez << '\n';
    }

    return 0;
}
/**

// probati bojenje sahovski ili slicno

**/

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

int main(){
    long long i,j,k,l,m,n,t;
    cin>>n;
    k=0;
    m=0;
    l=0;
    for(i=0;i<n;i++) {
        cin>>j;
        k+=j;
        l+=k;
        if (m<j) m=j;
        cout<<l+m*(i+1)<<' ';
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define rng(v) v.begin(),v.end()
#define rngr(v) v.rbegin(),v.rend()
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using P3 = tuple<int, int, int>;
#define vi vector<int>
#define vvi vector<vi>
#define vll vector<ll>
#define vs vector<string>
using vp = vector<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; }
using CP = complex<double>;
double dot( const CP &z, const CP &w ){ return (z.real()*w.real() + z.imag()*w.imag()); }
double cross( const CP &z, const CP &w ){ return (z.real()*w.imag() - z.imag()*w.real()); }
int n, q;
vvi g, ql, qr, pre;
vi cnt, res;
void dfs(int i, int d){
    int m = ql[i].size();
    pre[i].resize(m);
    rep(mi, m){
        pre[i][mi] = cnt[ql[i][mi]];
    }
    cnt[d]++;
    for(auto j : g[i]){
        dfs(j, d+1);
    }
    rep(mi, m){
        int k = ql[i][mi];
        res[qr[i][mi]] = cnt[k]-pre[i][mi];
    }
}
int main()
{
    cin >> n;
    g.resize(n);
    ql.resize(n);
    qr.resize(n);
    cnt.resize(n);
    pre.resize(n);
    rep(i, n-1){
        int p;
        cin >> p;
        --p;
        g[p].eb(i+1);
    }
    cin >> q;
    res.resize(q);
    rep(qi, q){
        int u, d;
        cin >> u >> d;
        --u;
        ql[u].eb(d);
        qr[u].eb(qi);
    }
    dfs(0, 0);
    for(auto i : res) cout << i << endl;
    return 0;
}

#include <bits/stdc++.h>
#define db(a) cout << a << endl
#define db2(a,b) cout << a << " " << b << endl
#define dbd(a) cout << #a << ": " << a << endl
#define dbd2(a,b) cout << #a << ": " << a << ", " << #b << ": " << b << endl
#define dbp(a) cout << a.first << " " << a.second << endl
#define adb(a) for(auto _i:a) cout << _i << " "; cout << endl
#define adbp(a) for(auto _i:a) cout << _i.first << " " << _i.second << endl;
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define mod 1000000007
#define N 400010
#define M 100010
using namespace std;

vector<vector<int>> graph(N);
int depth[N], in[N], out[N], timer = 0;
vector<int> tour;

void dfs(int v, int p, int d)
{
    tour.push_back(v);
    in[v] = timer++;
    depth[v] = d;

    for(int x:graph[v])
        if(x != p)
            dfs(x, v, d + 1);

    tour.push_back(v);
    out[v] = timer++;
}

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif

    fastIO;
    int n;
    cin >> n;

    int p[n];
    for(int i=1; i<n; i++)
    {
        cin >> p[i], p[i]--;
        graph[i].push_back(p[i]);
        graph[p[i]].push_back(i);
    }

    dfs(0, -1, 0);

    vector<vector<int>> mp(N);

    for(int i=0; i<tour.size(); i++)
        mp[depth[tour[i]]].push_back(i);

    int q;
    cin >> q;

    while(q--)
    {
        int u, d;
        cin >> u >> d, u--;

        auto l = lower_bound(mp[d].begin(), mp[d].end(), in[u]);
        auto r = upper_bound(mp[d].begin(), mp[d].end(), out[u]);

        if(r == mp[u].end()) r--;

        int ans = (r - l + 1) / 2;
        cout << ans << endl;
    }
}


//#include <atcoder/maxflow.hpp>
#include <memory>
#include <iostream>
#include <map>
#include <list>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>
#include <complex>
#include <thread>
#include <bitset>

#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s

typedef long long ll;

using namespace std;
//using namespace atcoder;

ll modd = (1000LL * 1000LL * 1000LL + 7LL);
//ll modd = 998244353;

ll binary_search(function<bool(ll)> func, ll start, ll end) {
    /*      func:int ->bool
            returns smallest int x where func(x) evaluates to true, searches in [start,end), it is assumed the values are false, .. , false, true ...
             */
    if (end <= start) {   return end;  }   // has to be here, otherwise func(end-1) in next line could be a problem
    if (!func(end-1)) {  return end;  }
    while (end-start>1) {
        ll mid = (start+end)/2;
        if (func(mid)) {  end = mid;  } else { start = mid;   }
    }
    if (func(start)) {  return start;  } else {  return end;   }
};

int main(int argc, char *argv[])   {

    ios_base::sync_with_stdio(false);

    cout.precision(17);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int> rand_gen(0, modd);   // rand_gen(rng) gets the rand no

//    auto start = chrono::steady_clock::now();

//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readint(n); readint(m);
        vector<vector<int>> adj(n);
        forr(i,0,m) {
            readint(aa); readint(bb);
            --aa; --bb;
            adj[aa].push_back(bb);
            adj[bb].push_back(aa);
        }

        vector<int> pearls;
        readint(k);
        forr(i,0,k) {
            readint(aa); --aa; pearls.push_back(aa);
        }

        vector<vector<ll>> dist_(k, vector<ll>(k, modd));
        forr(i,0,k) {
            queue<pair<int,int>> todo; todo.push(make_pair(pearls[i],0));
            vector<int> dist(n, modd);
            while (!todo.empty()) {
                auto curr = todo.front(); todo.pop();
                dist[curr.first] = min(dist[curr.first], curr.second);
                if (dist[curr.first] == curr.second) {
                    for(auto nn : adj[curr.first]) {
                        todo.push(make_pair(nn, curr.second+1));
                    }
                }
            }
            forr(j,0,k) {
                dist_[i][j] = dist[pearls[j]];
                dist_[j][i] = dist_[i][j];
            }
        }

        vector<vector<ll>> mmin(k, vector<ll>(1<<k, modd));
        forr(i,0,mmin[0].size()) {
          forr(j,0,k) {
            if (i==0) { continue;  }
            if ((i & (1<<j))==0) { continue;  }
            if (i == 1<<j) {
                mmin[j][i] = 1; continue;
            }
            int ii = i^(1<<j);
            forr(r,0,k) {
                if (ii & (1<<r)==0) {continue;}
                mmin[j][i] = min(mmin[j][i], dist_[j][r] + mmin[r][ii]);
            }
          }
        }
        ll ret = modd;
        forr(i,0,k) {
            ret = min(ret, mmin[i][(1<<k)-1]);
        }

        cout << (ret>=modd ? -1 : ret) << endl;

    }

//        auto stop = chrono::steady_clock::now();
//        auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start);
//        cout << "Duration: " << duration.count() << endl;
    return 0;
}

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// #include<ext/pb_ds/tag_and_trait.hpp>
// using namespace __gnu_pbds;
// #include<boost/multiprecision/cpp_int.hpp>
// namespace multiprecisioninteger = boost::multiprecision;
// using cint=multiprecisioninteger::cpp_int;
using namespace std;
using ll=long long;
#define double long double
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
// using llset=tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>;
#define For(i,a,b) for(i=a;i<(ll)b;++i)
#define bFor(i,b,a) for(i=b,--i;i>=(ll)a;--i)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N,0)
#define brep1(i,N) bFor(i,N,1)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define endl "\n"
#define eb emplace_back
#define print(x) cout<<x<<endl
#define printyes print("Yes")
#define printno print("No")
#define printYES print("YES")
#define printNO print("NO")
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
#define matoutput(v) do{for(auto outimat:v)output(outimat);}while(0)
const ll mod=1000000007;
// const ll mod=998244353;
const ll inf=1LL<<60;
const double PI=acos(-1);
const double eps=1e-9;
template<class T,class E> ostream& operator<<(ostream& os,const pair<T,E>& p){return os<<"("<<p.first<<","<<p.second<<")";}
template<class T> ostream& operator<<(ostream& os,const vector<T>& v){
  os<<"{";ll i;
  rep(i,v.size()){
    if(i)os<<",";
    os<<v[i];
  }
  os<<"}";
  return os;
}
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;}
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;}
#ifdef DEBUG
void debugg(){cout<<endl;}
template<class T,class... Args>void debugg(const T& x,const Args&... args){cout<<" "<<x;debugg(args...);}
#define debug(...) cout<<__LINE__<<" ["<<#__VA_ARGS__<<"]:",debugg(__VA_ARGS__)
#else
#define debug(...) (void(0))
#endif

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas x,ddatas y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a,ll m=mod) {
  ll b=m,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+m)%m;
}

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

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  if(n<r)return 0;
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

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

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

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}
ll calc(ll N,ll R){
  ll i,res=1;
  rep(i,R){
    (res*=(N-i)%mod)%=mod;
    res=moddevide(res,i+1);
  }
  return res;
}
ll N,M,K,H,W,A,B,C,D;
string s,t;
ll ans;
int main(){
  startupcpp();
  // int codeforces;cin>>codeforces;while(codeforces--){
  ll i,j;
  cin>>N>>K;
  vec v(N);
  rep(i,N)cin>>v[i];
  B=accumulate(all(v),0LL);
  if(K<B){
    print(0);
    return 0;
  }
  A=K-B;
  print(calc(K+N,N+B));
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll ;
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define pb push_back

int main()
{
	int T=1;
	// cin >> T ;

	while(T--)
	{
		int x,y ;
		cin>>x>>y ;
		if(abs(x-y)<=2) cout<<"Yes\n" ;
		else cout<<"No\n" ;
	}
	return 0;
}

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0; i<(n); ++i)
#define fixed_setprecision(n) fixed << setprecision((n))
#define execution_time(ti) printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - ti) / CLOCKS_PER_SEC);
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9

using namespace std;
using ll = long long;
using P = pair<int,int>;
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; }
const long long INF = 1LL << 60;

int main() {
    int x, y;
    cin >> x >> y;

    if(max(x, y) < min(x, y) + 3) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


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

int main(){
    long long int X;
    cin >> X;
    int a;
    a = X%100;
    int ans;
    ans = 100 - a;
    cout << ans << endl;
}

//Author:RingweEH
#include <cstdio>
#include <algorithm>
#include <cstring>
#define ll long long
#define db double
using namespace std;
int min( int a,int b ) { return (a<b) ? a : b; }
int max( int a,int b ) { return (a>b) ? a : b; }
void bmin( int &a,int b ) { a=(a<b) ? a : b; }
void bmax( int &a,int b ) { a=(a>b) ? a : b; }
int read()
{
	int x=0,w=1; char ch=getchar();
	while ( ch>'9' || ch<'0' ) { if ( ch=='-' ) w=-1; ch=getchar(); }
	while ( ch<='9' && ch>='0' ) { x=x*10+ch-'0'; ch=getchar(); }
	return x*w;
}

int n;

int main()
{
	n=read();
	for ( int i=1; i<=n; i++ )
		printf( "%d %d\n",(i*2)%n+1,(i*2+1)%n+1 );

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<endl
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

vector<string> C(vector<string> s) {
  ll n=s.size();
  rep(i,n)REP(j,i+1,n) swap(s[i][j],s[j][i]);
  return s;
}

ll n,m;
string s[1000];

ll calc(vector<string> t) {
  ll cnt=0;
  rep(k,m) {
    ll f=0;
    rep(l,2) {
      rep(i,n) {
        rep(j,n) {
          if(t[i].substr(0,s[k].size())==s[k]) f=1;
          rotate(t[i].begin(),t[i].begin()+1,t[i].end());
        }
      }
      t=C(t);
    }
    cnt+=f;
  }
  return cnt;
}

vector<string> ans;
ll MM;

void solve(vector<string> t) {
  ll d=calc(t);
  if(MM<d) {
    MM=d;
    ans=t;
  }
  rep(k,5) {
    random_shuffle(all(t));
    rep(i,n) rotate(t[i].begin(),t[i].begin()+rand()%n,t[i].end());
    ll d=calc(t);
    if(MM<d) {
      MM=d;
      ans=t;
    }
  }
}

void Main() {
  srand((unsigned)time(NULL));
  cin >> n >> m;
  rep(i,m) R s[i];
  vector<string> v[15];
  rep(i,m) v[s[i].size()].pb(s[i]);
  rep(e,35) {
    vector<string> t(n);
    rrep(i,15) {
      random_shuffle(all(v[i]));
      rep(j,v[i].size()) {
        ll M=MAX,x=0;
        string rr;
        rep(k,n) {
          rep(l,t[k].size()+1) {
            string r1=t[k].substr(l);
            if(r1.size()<=v[i][j].size()) {
              string r2=v[i][j].substr(0,r1.size());
              if(r1==r2) {
                ll d=t[k].size()+v[i][j].size()-r1.size();
                if(d<=n&&M>d) {
                  M=d;
                  x=k;
                  rr=t[k]+v[i][j].substr(r1.size());
                }
              }
            }
            if(l+v[i][j].size()<=t[k].size()) {
              r1=t[k].substr(l,v[i][j].size());
              if(r1==v[i][j]) {
                M=0;
                x=k;
                rr=t[k];
              }
            }
          }
        }
        if(rand()%(i+3)==0) M=MAX;
        if(M!=MAX) t[x]=rr;
      }
    }
    rep(i,n) {
      while(t[i].size()<n) {
        //t[i]+='.';
        t[i]+=(char)(rand()%8+'A');
      }
    }
    solve(t);
  }
  rep(i,n) pr(ans[i]);
}

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

#include<iostream>
#include<cstring>
using namespace std;
const int BUF = 73;

int nPrime;
int prime[BUF];

void makePrime() {
    bool isPrime[BUF] = {};
    for (int i = 0; i < BUF; ++i) isPrime[i] = true;

    for (int i = 2; i * i < BUF; ++i) {
        if (isPrime[i]) {
            for (int j = i * 2; j < BUF; j += i) {
                isPrime[j] = false;
            }
        }
    }

    nPrime = 0;
    for (int i = 2; i < BUF; ++i) {
        if (isPrime[i]) {
            prime[nPrime++] = i;
        }
    }
}

long long A, B;

void read() {
    cin >> A >> B;
}

long long rec(int idx, int mask, long long dp[BUF][1 << 20]) {
    if (idx == B - A + 1) return 1;

    long long &ret = dp[idx][mask];
    if (ret != -1) return ret;

    ret = 0;

    long long val = A + idx;

    // Pick
    int nexMask = mask;
    for (int i = 0; i < nPrime; ++i) {
        if (val % prime[i] == 0) {
            if (nexMask & (1 << i)) goto _fail;
            nexMask |= 1 << i;
        }
    }

    ret += rec(idx + 1, nexMask, dp);

 _fail:

    // Don't pick
    ret += rec(idx + 1, mask, dp);

    return ret;
}

void work() {
    static long long dp[BUF][1 << 20];
    memset(dp, -1, sizeof(dp));
    cout << rec(0, 0, dp) << endl;
}

int main() {
    makePrime();
    read();
    work();
    return 0;
}


#include<bits/stdc++.h>

#define SORT(v) sort(v.begin(),v.end())
#define si(n) scanf("%d",&n)
#define sii(n,m) scanf("%d %d",&n,&m)
#define sl(n) scanf("%lld",&n)
#define sll(n,m) scanf("%lld %lld",&n,&m)
#define ss(cad) scanf("%s",cad)
#define all(v) (v).begin(), (v).end()
#define PB push_back
#define fst first
#define scn second
#define DBG(x) cerr << #x << " = " << (x) << endl;
#define M 1000000007
#define N_MAX 100010

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef pair<int,int> pi;
typedef vector<pi> vp;

int main(){
	int n, m;
	sii(n, m);
	pi vec[m+1];
	for(int i = 0; i < m; i++)
		sii(vec[i].fst, vec[i].scn);
	int k;
	si(k);
	pi ttt[k+1];
	for(int i = 0; i < k; i++)
		sii(ttt[i].fst, ttt[i].scn);

	bool posi[n+10];
	int ans = 0;
	for(int mask = 0; mask < (1<<k); mask++){
		memset(posi, 0, sizeof(posi));
		for(int i = 0; i < k; i++)
			if(mask&(1<<i))
				posi[ttt[i].fst] = 1;
			else
				posi[ttt[i].scn] = 1;
		int cnt = 0;
		for(int i = 0; i < m; i++)
			if(posi[vec[i].fst] && posi[vec[i].scn])
				cnt++;
		ans = max(ans, cnt);
	}
	printf("%d\n", ans);
	return 0;
}

#include<iostream>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<set>
#include<queue>
#include<cstring>

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

#define fi first
#define se second

using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstring = vector<string>;
using vb = vector<bool>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const double PI = 3.1415926535897932;
const int INF = (int)2e9;
const ll LINF = (ll)2e18;
//const ll MOD = 998244353;
const ll MOD = 1000000007;
const int dc[9] = {1, -1, 0,  0, 1, -1,  1, -1, 0};
const int dr[9] = {0,  0, 1, -1, 1,  1, -1, -1, 0};

template<typename T> inline
istream& operator>>(istream &is, vector<T> &vec) {
    for(auto &v : vec) { is >> v; } return is;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<T> &vec) {
    for(auto &v : vec) { os << v << ",";} return os;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<vector<T> > &mat) {
    for(auto &row : mat) { os << row << endl; } return os;
}
template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p) {
    return o << "{" << p.first << "," << p.second << "}";
}

template<typename T> inline void chmin(T &a, T b) { a = min(a, b); }
template<typename T> inline void chmax(T &a, T b) { a = max(a, b); }

bool solve(ll a, ll b, ll c, ll d)
{
    if(a+b == c+d) { return true; }
    if(a-b == c-d) { return true; }
    if(abs(a-c) + abs(b-d) <= 3) { return true; }
    return false;
}

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

    if(a == c && b == d) {
        cout << 0 << endl;
        return 0;
    }

    vector<pll> goal;

    if(solve(a,b,c,d)) {
        cout << 1 << endl;
        return 0;
    }

    if((a+b)%2 == (c+d)%2) { cout << 2 << endl; return 0 ; }

    for(int i = -2; i <= 2; i++) {
        for(int j = -2; j <= 2; j++) {
            goal.push_back({c+i,d+j});
        }
    }

    goal.push_back({c-3,d});
    goal.push_back({c+3,d});
    goal.push_back({c,d-3});
    goal.push_back({c,d+3});

    int n = goal.size();

    rep(i,n) {
        pll g = goal[i];
        ll c2 = g.fi, d2 = g.se;
        if(solve(a,b,c2,d2)) {
            cout << 2 << endl;
            return 0;
        }
    }
    cout << 3 << endl;

    return 0;

} /*atcoder*/


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <cstdint>
#include <cmath>
using namespace std;
using ll = long long ;
#define LINF (1LL<<60)
#define rep(i,n) for (int i=0; i < (n); ++i)
//#define LLONG_MAX 9223372036854775807i64

int ctoi(char c){
    return int(c)-int('0') ;
}

const int lim = 1e9 ;

int main() {
    int n ;
    cin >> n ;
    int  a[n] ;
    rep(i,n){
        cin >> a[i] ;
    }
    int ans = lim ;

    if(n==1){
        cout << a[0] << endl ;
        return 0 ;
    }

    for (int bit = 0; bit < (1 << (n-1)); bit++) {
        int tot = 0 ;
        int cur = a[0] ;
        for (int i = 1; i < n ; i++) {
            if (bit & (1 << i-1)){
                tot ^= cur ;
                cur = a[i] ;
            }else{
                cur |= a[i] ;
            }
        }
        tot ^= cur ;
        ans = min(ans,tot) ;
    }

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

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

#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using std::map;
using std::vector;

int main() {
    int h, w;
    cin >> h >> w;

    ll ans = 1;
    string s[h];
    REP(i, h) cin >> s[i];

    REP(sum, h + w) {
        int red = 0, blue = 0, empty = 0;
        REP(i, sum + 1) {
            if (i >= h) {
                continue;
            }
            int j = sum - i;
            if (j >= w) {
                continue;
            }
            char c = s[i][j];
            switch (c) {
                case 'B':
                    blue++;
                    break;
                case 'R':
                    red++;
                    break;
                case '.':
                    empty++;
                    break;
            }
        }
        if (red == 0 && blue == 0 && empty == 0) {
            continue;
        }
        if (red != 0 && blue != 0) {
            cout << 0;
            return 0;
        } else if (red == 0 && blue == 0) {
            ans *= 2;
            ans %= 998244353;
        }
    }
    cout << ans;

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#define int  long long
typedef vector<int> vi;
typedef pair<int, int> pii;

#define PI 3.14159265
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;

const int MAXN = 1000005, MAXK = 18;
int prime[MAXN];

void seive()
{

    for(int i=2;i<=MAXN;i++)
    {
        if(prime[i]==0)
        {
            for(int j=i;j<=MAXN;j+=i)
            {

                prime[j]++;
            }
        }
    }
}

int32_t main()
{

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

  }

   int ans=INT_MAX;
   for(int i=0;i<n;i++)
   {
       double time=0.5+(a[i][2]-1)*1.0;

       if(time>(double)a[i][0])
       {
           ans=min(ans,a[i][1]);
       }
   }

   if(ans==INT_MAX)
   {
       cout<<-1;
   }
   else
   {
       cout<<ans;
   }

    return 0;

}

#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <climits>

constexpr int SINT_MAX = std::numeric_limits<int>::max();
constexpr int SINT_MIN = std::numeric_limits<int>::min();

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

template<class T>
T choose(bool b, T t, T f)
{
    if (b) return t;
    else return f;
}

const char *YesNo(bool b)
{
    return choose(b, "Yes", "No");
}

const char *YESNO(bool b)
{
    return choose(b, "YES", "NO");
}

template<class NumT>
NumT diffabs(NumT l, NumT r)
{
    if (l < r) return r-l;
    else return l-r;
}

struct myinout_t {} io;

template<class T>
myinout_t &operator >>(myinout_t &my, T &i)
{
    cin >> i;
    return my;
}

myinout_t &operator >>(myinout_t &my, int &i)
{
    int r = scanf("%d", &i);
    if (r != 1) exit(EXIT_FAILURE);
    return my;
}

myinout_t &operator >>(myinout_t &my, ll &i)
{
    int r = scanf("%lld", &i);
    if (r != 1) exit(EXIT_FAILURE);
    return my;
}

template<class T>
myinout_t &operator <<(myinout_t &my, const T &i)
{
    cout << i;
    return my;
}

myinout_t &operator <<(myinout_t &my, int i)
{
    printf("%d", i);
    return my;
}

myinout_t &operator <<(myinout_t &my, ll i)
{
    printf("%lld", i);
    return my;
}

myinout_t &operator <<(myinout_t &my, double i)
{
    printf("%.20f", i);
    return my;
}

constexpr char BR = '\n';

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

bool f(int N, int M, int T, const vi &A, const vi &B)
{
    int b = N;
    int t = 0;
    for (int i = 0; i < M; i++)
    {
        if ((A[i] - t) >= b)
        {
            return false;
        }
        else
        {
            b += (B[i] - 2 * A[i] + t);
            b = min(b, N);
            t = B[i];
        }
    }
    return (T - t) < b;
}

int main()
{
    int N, M, T;
    io >> N >> M >> T;
    vi A(M), B(M);
    for (int i = 0; i < M; i++)
        io >> A[i] >> B[i];

    bool ans = f(N, M, T, A, B);
    io << YesNo(ans) << BR;
}