#include <bits/stdc++.h>
using namespace std;
#define ld long double
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000;
constexpr ll llINF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<int>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
vector<vector<int>>C,sC;
void init_comb(int n,int m){
    C.resize(n+1,vector<int>(m+1,0));
    sC.resize(n+1,vector<int>(m+1,0));
    C[0][0]=1;
    for(int i=1;i<=n;i++){
        C[i][0]=1;
        for(int j=1;j<=m;j++){
            C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
        }
    }
    rep(i,n+1){
        rep(j,m){
            sC[i][j+1]=(sC[i][j]+C[i][j])%mod;
        }
    }
}
int comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*invkaijo[a-b]%mod*invkaijo[b]%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
signed main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<int>p(2*n),pa(2*n,-1);
    rep(i,n){
        int a,b;
        cin>>a>>b;
        if(a>=0){
            a--;
            if(p[a]){
                puts("No");
                return 0;
            }
            p[a]=(i+1);
        }
        if(b>=0){
            b--;
            if(p[b]){
                puts("No");
                return 0;
            }
            p[b]=-(i+1);
        }
        if(a>=0&&b>=0){
            if(a>b){
                puts("No");
                return 0;
            }
            pa[a]=b;
            pa[b]=a;
        }
    }
    vector<bool>dp(2*n,false);
    dp[0]=true;
    rep(i,2*n){
        for(int j=i+1;j<2*n;j+=2){
            int t=(j-i+1)/2;
            bool ok=true;
            rep(k,t){
                int x=i+k,y=x+t;
                if(pa[x]>=0&&pa[y]!=x){
                    ok=false;
                }
                if(pa[x]!=y&&pa[y]>=0){
                    ok=false;
                }
                if(p[x]!=0&&p[y]!=0&&p[x]+p[y]!=0){
                    ok=false;
                }
                if(p[x]<0&&p[y]>0){
                    ok=false;
                }
            }
            dp[j+1]=dp[j+1]|(dp[i]&ok);
        }
    }
    cout<<(dp[2*n]?"Yes":"No")<<endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
const int maxn = 204;
bool dp[maxn][maxn];

int l[maxn],r[maxn],vis[maxn];
int w[maxn];

int main()
{
    int n;
    scanf("%d",&n);
    bool ok = true;
    for(int i = 1,a,b;i <= n;++i){
        scanf("%d%d",&a,&b);
        if(a!=-1&&b==-1){
            if(vis[a]){
                ok = false;
            }
            vis[a] = 1;
            l[a] = 1;
        }
        else if(a==-1&&b!=-1){
            if(vis[b]){
                ok = false;
            }
            vis[b] = 1;
            r[b] = 1;
        }
        else if(a!=-1&&b!=-1){
            if(vis[a]||vis[b]||a>=b){
                ok = false;
            }
            vis[a] = vis[b] = 1;
            l[a] = r[b] = 1;
            w[a] = w[b] = b-a;
        }
    }
    if(!ok){
        printf("No\n");
        return 0;
    }
    for(int len = 2;len <= 2*n;len += 2){
        for(int i = 1;i <= 2*n;++i){
            int j = i+len-1;
            if(j > 2*n)break;
            int tmp = len/2;
            bool ok = true;
            for(int k = i;k <= j-tmp;++k){
                if(r[k])ok=0;
                if(l[k]&&w[k]>0){
                    if(w[k]!=tmp)ok=0;
                }
                if(!w[k]&&l[k]&&r[k+tmp])ok=0;
            }
            for(int k = j-tmp+1;k <= j;++k){
                if(l[k])ok=0;
            }
            dp[i][j] |= ok;
            for(int k = i;k < j;++k){
                dp[i][j] |= dp[i][k]&dp[k+1][j];
            }
        }
    }
    if(dp[1][2*n])printf("Yes\n");
    else printf("No\n");
    return 0;
}


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

#define ll long long
#define ri register int
#define rep(io, st, ed) for(int io = st; io <= ed; io ++)
#define drep(io, ed, st) for(int io = ed; io >= st; io --)

#define gc getchar
inline int read() {
	int p = 0, w = 1; char c = gc();
	while(c > '9' || c < '0') { if(c == '-') w = - 1; c = gc(); }
	while(c >= '0' && c <= '9') p = p * 10  + c - '0', c = gc();
	return p * w;
}

const int limn = 8e5 + 5;

int n, far, lst, cnt;
int cap[limn], node[limn], nxt[limn], dep[limn], maxd[limn], son[limn];

void addedge(int u, int v) {
	nxt[++ cnt] = cap[u]; cap[u] = cnt; node[cnt] = v;
}

void dfs(int o, int fa) {
	#define cur node[i]
	maxd[o] = o; son[o] = 0;
	for(int i = cap[o]; i; i = nxt[i]) if(fa != cur) {
		dep[cur] = dep[o] + 1;
		dfs(cur, o);
		if(dep[ maxd[cur] ] > dep[ maxd[o] ])
			maxd[o] = maxd[cur], son[o] = cur;
	}
}

int E[limn];
void dfs2(int o, int fa) {
	E[o] = E[lst] + dep[o] + dep[lst] - 2 * dep[fa]; lst = o;
	for(int i = cap[o]; i; i = nxt[i])
		if(cur != fa && cur != son[o]) dfs2(cur, o);
	if(son[o]) dfs2(son[o], o);
}

int main() {
	n = read();
	rep(i, 2, n) {
		int u = read(), v = read();
		addedge(u, v); addedge(v, u);
	}
	dfs(1, 0); //find the diamter
	int u = maxd[1];
	dep[u] = 1; dfs(u, 0); //reset it!
	dfs2(u, 0);
	rep(i, 1, n) printf("%d ", E[i]); printf("\n");
	return 0;
}

// Template
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <tuple>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <array>
#include <cassert>
#include <cmath>
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep3(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll infll = 3003003003003003003LL;
template <typename T>
inline bool chmin(T &x, const T &y) {
    if (x > y) {
        x = y;
        return true;
    }
    return false;
}
template <typename T>
inline bool chmax(T &x, const T &y) {
    if (x < y) {
        x = y;
        return true;
    }
    return false;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &element : vec) is >> element;
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    for (int i = 0, vec_len = (int)vec.size(); i < vec_len; ++i) {
        os << vec[i] << (i + 1 == vec_len ? "" : " ");
    }
    return os;
}
struct IOSET {
    IOSET() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
    }
} ioset;

// Main
int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        g[a].push_back(b);
    }

    int ans = 0;
    rep(i, n) {
        queue<int> q;
        vector<int> ch(n, 0);
        q.push(i);
        ch[i] = 1;
        while (!q.empty()) {
            int v = q.front();
            q.pop();
            for (int u : g[v]) {
                if (exchange(ch[u], 1) == 0) q.push(u);
            }
        }
        ans += accumulate(all(ch), 0);
    }
    cout << ans << '\n';
}


#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>
#include <stdio.h>

using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

void display_2int(vector<vector<int>> vec) {
    int N = vec.size();
    for (int i=0; i<N; i++) {
        for (int j=0; j<vec.at(i).size(); j++) {
            cout << vec.at(i).at(j);
            if (j < vec.at(i).size()-1) {
                cout << " ";
            }
        }
        cout << endl;
    }
}

void display_1string(vector<string> strlist) {
    int N = strlist.size();
    for (int i=0; i<N; i++) {
        cout << strlist.at(i) << endl;
    }
}

void display_1int(vector<int> intlist) {
    int N = intlist.size();
    if (N>0){
      for (int i=0; i<N - 1; i++) {
          cout << intlist.at(i) << " ";
      }
      cout << intlist.at(N-1) << endl;
    }else{
      cout << endl;
    }
}

vvi saiki(int n, int r, int &ans){
    if(n==r){
        vvi lst(1, vi(n));
        for(int i=0; i<n; i++){
            lst.at(0).at(i) = i;
        }
        ans++;
        return lst;
    }
    if(r==0){
        vvi lst(1, vi(0));
        ans++;
        return lst;
    }
    vvi lst;
    vvi lst1 = saiki(n-1, r, ans);
    vvi lst2 = saiki(n-1, r-1, ans);
    for(int i=0; i<lst1.size(); i++){
        lst.push_back(lst1.at(i));
    }
    for(int i=0; i<lst2.size(); i++){
        lst2.at(i).push_back(n-1);
        lst.push_back(lst2.at(i));
    }
    return lst;
}

int main(){
    int ans=0;
    int cnt = 0;
    //vvi a = saiki(6, 2, ans);
    //display_2int(a);
    //cout << ans << endl;
    int H, W, A, B;
    cin >> H >> W >> A >> B;
    vvi lst=saiki(H*W, A, ans);
    int bit = pow(2, A);
    if (A ==8){
        if (H == 4){
            cout << 36 << endl;
        }
        else{
            cout << 34 << endl;
        }
    }else{
            for (int i=0; i<ans; i++){
        for(int j=0; j<bit; j++){
            int b = j;
            vi bitlst(A);
            for(int k=0; k<A; k++){
                //cout << b << endl;
                int a = b/(int)pow(2, A-k-1);
                bitlst.at(k) = a;
                b = b % (int)pow(2, A-k-1);
            }
            //display_1int(bitlst);
            vvi board(H, vi(W));
            bool bb = true;
            for(int k=0; k<A; k++){
                int c = lst.at(i).at(k);
                int y = c/W;
                int x = c%W;
                if(bitlst.at(k) == 0){
                    if(x == W-1){
                        bb = false;
                        break;
                    }if(board.at(y).at(x)==1 || board.at(y).at(x+1) ==1){
                        bb = false;
                        break;
                    }
                    board.at(y).at(x)=1;
                    board.at(y).at(x+1) =1;
                }else{
                    if(y == H-1){
                        bb = false;
                        break;
                    }if(board.at(y).at(x)==1 || board.at(y+1).at(x) ==1){
                        bb = false;
                        break;
                    }
                    board.at(y).at(x)=1;
                    board.at(y+1).at(x) =1;
                }
            }
            if(bb){
                cnt++;
            }
        }
    }

    cout << cnt << endl;
    }

}

#include <iostream>
#include <cmath>
using namespace std;
int main() {
    double a,b,c,d;
    cin >> a >> b >> c >> d;
    if(c*d-b<=0) cout << -1 << endl;
    else {
        cout << ceil(a/(c*d-b)) << endl;
    }

    return 0;
}


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

const int N = 10005;

int n, e;
int a[N], L[N], R[N], h[N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    while (cin >> n) {
        for (int i = 1; i <= n; i++) cin >> a[i];
        e = 0;
        for (int i = 1; i <= n; i++) {
            while (e > 0 && a[i] < a[h[e - 1]]) R[h[--e]] = i;
            h[e++] = i;
        }
        while (e > 0) R[h[--e]] = n + 1;
        // for (int i = 1; i <= n; i++) cout << R[i] << ' ';
        // puts("");

        e = 0;
        for (int i = n; i >= 1; i--) {
            while (e > 0 && a[i] < a[h[e - 1]]) L[h[--e]] = i;
            h[e++] = i;
        }
        while (e > 0) L[h[--e]] = 0;

        int ans = 0;
        for (int i = 1; i <= n; i++) ans = max(ans, a[i] * (R[i] - L[i] - 1));
        cout << ans << '\n';
    }
    return 0;
}

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RREP(i, n) for(int i = (n)-1; i >= 0; i--)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define RRANGE(i, a, b) for(int i = (b)-1, i##_MACRO = (a); i >= i##_MACRO; i--)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))
#define PRECISION(x) std::fixed << std::setprecision(x)

using namespace std;

using ll = long long;
using VI = std::vector<int>;
using VI2D = std::vector<vector<int>>;
using VLL = std::vector<long long>;
using VLL2D = std::vector<vector<long long>>;

constexpr int INF = 2e9;
constexpr long long INFLL = 2e18;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

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

template <typename T, std::size_t N>
struct make_vector_type {
	using type =
		typename std::vector<typename make_vector_type<T, (N - 1)>::type>;
};

template <typename T>
struct make_vector_type<T, 0> {
	using type = typename std::vector<T>;
};

template <typename T, size_t N>
auto make_vector_impl(const std::vector<std::size_t>& ls, T init_value) {
	if constexpr(N == 0) {
		return std::vector<T>(ls[N], init_value);
	} else {
		return typename make_vector_type<T, N>::type(
			ls[N], make_vector_impl<T, (N - 1)>(ls, init_value));
	}
}

template <typename T, std::size_t N>
auto make_vector(const std::size_t (&ls)[N], T init_value) {
	std::vector<std::size_t> dimensions(N);
	for(int i = 0; i < N; i++) {
		dimensions[N - i - 1] = ls[i];
	}
	return make_vector_impl<T, N - 1>(dimensions, init_value);
}

template <typename T>
std::vector<T> make_vector(std::size_t size, T init_value) {
	return std::vector<T>(size, init_value);
}

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr bool chmax(T& m, U x) {
	m = max<T>(m, x);
	return m < x;
}

template <typename T, typename U>
constexpr bool chmin(T& m, U x) {
	m = min<T>(m, x);
	return m > x;
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

template <typename T>
constexpr T pow(T a, int n) {
	T ret = 1;
	while(n != 0) {
		if(n % 2) {
			ret *= a;
		}
		a *= a;
		n /= 2;
	}
	return ret;
}

template <typename T>
constexpr T diff(T a, T b) {
	return abs(a - b);
}

const int MOD = 200;

int main() {
	int n;
	cin >> n;
	VI a(n);
	EACH(e, a) { cin >> e; }

	EACH(e, a) { e %= MOD; }

	int x = min(n, 8);
	VI count(MOD, 0);
	RANGE(s, 1, 1 << x) {
		int mod_sum = 0;
		REP(i, x) {
			if((s & (1 << i)) != 0) {
				mod_sum += a[i];
				mod_sum %= MOD;
			}
		}
		count[mod_sum]++;
	}

	auto found_iter = find_if(ALL(count), [](auto x) { return x >= 2; });
	if(found_iter == count.end()) {
		cout << "No" << endl;
		return 0;
	}
	int found_num = distance(count.begin(), found_iter);

	VI result;
	RANGE(s, 1, 1 << x) {
		int mod_sum = 0;
		REP(i, x) {
			if((s & (1 << i)) != 0) {
				mod_sum += a[i];
				mod_sum %= MOD;
			}
		}
		if(mod_sum == found_num) {
			result.push_back(s);
		}
	}

	cout << "Yes" << endl;
	REP(k, 2) {
		cout << __builtin_popcount(result[k]) << " ";
		REP(i, 8) {
			if((result[k] & (1 << i)) != 0) {
				cout << i + 1 << " ";
			}
		}
		cout << endl;
	}
	return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define FOR(i, a, b) for (int i = a; i <= (b); i++)
#define ROF(i, a, b) for (int i = a; i >= (b); i--)
#define y1 awefakhlrv

using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long;
using pll = pair<ll, ll>; using vpll = vector<pll>;
using vll = vector<ll>; using vvll = vector<vll>;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int x, y; cin >> x >> y;
    cout <<  (abs(x - y) <= 2 ? "Yes" : "No") << endl;
}

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

int main(){
    int x, y;
    cin >> x >> y;
    if((x < y && y - x < 3) || (x > y && x - y < 3)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = 1; i <= (int)(n); i++)
#define drep(i, n) for(int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
#define dup(x,y) (((x)+(y)-1)/(y))
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
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 int mod = 1000000007;
// const int mod = 998244353;

int main() {
  int n, m;
  cin >> n >> m;
  vvi g(n);
  vi a(n);
  rep(i, n) cin >> a[i];
  rep(i, m) {
    int x, y;
    cin >> x >> y;
    --x; --y;
    g[x].push_back(y);
  }
  vi dp(n, INF*2);
  int ans = -INF;
  rep(i, n) {
    chmax(ans, a[i] - dp[i]);
    for (int j : g[i]) {
      chmin(dp[j], dp[i]);
      chmin(dp[j], a[i]);
    }
  }
  cout << ans << endl;
}

#include <bits/stdc++.h>
#define INF 1'000'000'000'000'000'000
#define MAX_N 200'000
#define MAX_M 200'000
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

ll N, M;
ll A[MAX_N];
ll B[MAX_N];
ll X[MAX_M], Y[MAX_M];

void solve() {
  for (ll i = 0; i < N; ++i) {
    B[i] = A[i];
  }
  vector<pll> V;
  for (ll i = 0; i < M; ++i) {
    V.push_back({X[i], Y[i]});
  }
  sort(V.begin(), V.end());
  ll res = -INF;
  for (auto [x, y] : V) {
    res = max(res, A[y] - B[x]);
    B[y] = min(B[x], B[y]);
  }
  printf("%lld\n", res);
}

int main() {
  cin >> N >> M;
  for (ll i = 0; i < N; ++i) {
    cin >> A[i];
  }
  for (ll i = 0; i < M; ++i) {
    cin >> X[i] >> Y[i];
    --X[i];
    --Y[i];
  }
  solve();
}


  /*
    Auther: ghoshashis545 Ashis Ghosh 😎
    College: Jalpaiguri Govt Enggineering College
*/
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
#include<algorithm>
#include<string>
using namespace std;
#define ll int
// #define int long long
#define ld long double
#define ff first
#define ss string
#define se second
#define sp(x) cout << fixed << setprecision(x)
#define endl "\n"
#define ub upper_bound
#define lb lower_bound
#define vi vector<int>
#define ipair pair<int,int>
#define vpi vector<ipair>
#define clr(a,x) memset(a,x,sizeof(a))
#define alt(v) v.begin(),v.end()
#define ralt(v) v.rbegin(),v.rend()
#define pb emplace_back
#define mp make_pair
#define PI 3.1415926535897932384626
#define cntb(x) __builtin_popcount(x)
#define fab(i,a,b) for(int i=(a);i<(b);i++)
#define fba(i,a,b) for(int i=(b);i>=(a);i--)

bool ispoweroftwo(int n){return n&(!(n&(n-1)));}
int mod=1000000007;
// int mod=998244353;
int dx[] = {1,0,-1,0};
int dy[] = {0,-1,0,1};

bool test  = 0;

// const int inf = 1e18;
const int N = 2e5+5;

int n,q;
vector<int>adj[N];
int depth[N],ans[N];
vector<pair<int,int>>res[N];

void dfs(int u){
    for(auto it : adj[u]){
        depth[it] = depth[u] + 1;
        dfs(it);
    }
}

vector<vector<int>>m;
void dfs1(int u,int c){
    int sz = (int)adj[u].size();
    for(auto it : res[u]){
        int x = c+it.ff;
        if(x == c+1)
            ans[it.se] += sz;
        else
            m[x].pb(it.se);
    }
    for(auto it : m[c+1])
        ans[it] += sz;
    for(auto it : adj[u])
        dfs1(it,c+1);

    for(auto it : res[u]){
        int x = c+it.ff;
        if(x != c+1)
            m[x].pop_back();
    }
}

void solve(int tc = 0)
{
    cin >>n;
    for(int i = 2,x; i <= n; ++i)
        cin >>x,adj[x].pb(i);
    dfs(1);
    cin >>q;
    for(int i = 1; i <= q; ++i){
        int x,d;
        cin >> x >> d;
        if(depth[x] > d)
            continue;
        else if(depth[x] == d){
            ans[i] = 1;
            continue;
        }
        res[x].push_back({d-depth[x],i});
    }
    m.resize(n+1);
    dfs1(1,0);
    for(int i = 1; i <= q; ++i)
        cout<<ans[i]<<"\n";
}

signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    int t=1;
    if(test)
    cin>>t;
    for(int i = 1; i <= t; ++i){
       // cout<<"Case #"<<i<<": ";
        solve(i);
    }
    return 0;
}

#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
template<class S, class T> inline S max_L(S a,T b){
  return a>=b?a:b;
}
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(long long &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(char &c){
  int i;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c = i;
}
inline int rd(char c[]){
  int i;
  int sz = 0;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = my_getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
int N;
char X[70];
long long M;
int main(){
  int i;
  long long res = 0;
  long long d;
  long long mx;
  long long b;
  __int128_t val;
  N = rd(X);
  rd(M);
  for(i=(0);i<(N);i++){
    X[i] -= '0';
  }
  int Q5VJL1cS;
  char e98WHCEY;
  if(N==0){
    e98WHCEY = 0;
  }
  else{
    e98WHCEY = X[0];
    for(Q5VJL1cS=(1);Q5VJL1cS<(N);Q5VJL1cS++){
      e98WHCEY = max_L(e98WHCEY, X[Q5VJL1cS]);
    }
  }
  d =e98WHCEY;
  if(N==1){
    if(X[0] <= M){
      res++;
    }
    wt_L(res);
    wt_L('\n');
    return 0;
  }
  long long FmcKpFmN;
  long long xr20shxY;
  long long WYIGIcGE;
  FmcKpFmN = d;
  xr20shxY = 1e18;
  while(FmcKpFmN < xr20shxY){
    if((FmcKpFmN + xr20shxY)%2==0){
      WYIGIcGE = (FmcKpFmN + xr20shxY) / 2;
    }
    else{
      WYIGIcGE = (FmcKpFmN + xr20shxY + 1) / 2;
    }
    val = 0;
    for(i=(0);i<(N);i++){
      val = val * WYIGIcGE + X[i];
      if(val > M){
        break;
      }
    }
    if(val <= M){
      FmcKpFmN = WYIGIcGE;
    }
    else{
      xr20shxY = WYIGIcGE - 1;
    }
  }
  b =xr20shxY;
  res = b - d;
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay version 20210103-1 [bug fixed 4]

// --- original code ---
// int N; char X[70];
// ll M;
// {
//   ll res = 0, d, mx, b;
//   __int128_t val;
//   rd(X@N,M);
//   rep(i,N) X[i] -= '0';
//   d = max(X(N));
//
//   if(N==1){
//     if(X[0] <= M) res++;
//     wt(res);
//     return 0;
//   }
//   // if(N==2){
//   //   res = (M - X[1]) / X[0] - d;
//   //   res >?= 0;
//   //   wt(res);
//   //   return 0;
//   // }
//   b = bsearch_max[ll,b,d,1e18][
//     val = 0;
//     rep(i,N){
//       val = val * b + X[i];
//       if(val > M) break;
//     }
//   ](val <= M);
//   res = b - d;
//   wt(res);
// }


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

int main(){
  int a, b, c, d;
  cin >>a>>b>>c>>d;
  cout << a*d-b*c <<endl;
}

#include <iostream>
using namespace std;
typedef long long ll;
ll x,y,a,b,cnt,A;
int main(void){
    cin>>x>>y>>a>>b;
    while(1){
        if(y/a<=x){
            cnt+=(y-x-1)/b;
            break;
        }
        if(x*a<x+b){
            x*=a;
            cnt++;
        }
        else{
            A=(x*a-x)/b;
            cnt+=A;
            x+=b*A;
        }
    }
    cout<<cnt<<endl;
}


#include<bits/stdc++.h>
#include<stdio.h>
#define int long long
#define pb push_back
#define fo(i,a,n) for(int i=a;i<n;i++)
#define foo(i,a,n) for(int i=a;i>=n;i--)
#define sn s.length()
#define get(n) cin>>n
#define put(n) cout<<n
//getline(cin >> ws, x);   eats whitespace
// round()  nearest int after round
using namespace std;

signed main()
{
    int t=1;
   // cin>>t;
    while(t--)
    {
        int n,x;
        cin>>n;
        string s;
        cin>>s;
        vector<char>c;
        fo(i,0,n)
        {
            if(s[i]=='x'&&c.size()>1)
            {
                x=c.size();
                char cc=c[x-1];
                c.pop_back();
                x=c.size()-1;
                if(c[x]=='f'&&cc=='o')
                c.pop_back();
                else
                {
                    c.push_back(cc);
                    c.pb(s[i]);
                }
            }
            else
            c.pb(s[i]);
        }
        cout<<c.size();
    }
}

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

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

int  H, W;
char S[10][10];
int dh[8]{ -1, -1,  0,  1,  1,  1,  0, -1 };
int dw[8]{  0,  1,  1,  1,  0, -1, -1, -1 };

bool check(int h, int w, int d, char c) {
  return S[h+dh[d%8]][w+dw[d%8]] == c;
}

int main() {
  cin >> H >> W;
  REP(i, H) REP(j, W) cin >> S[i][j];

  int ans = 0;
  REP(i, H) REP(j, W) if (S[i][j] == '#') {
    for (int k = 0; k < 8; k += 2) {
       ans += (check(i, j, k, '.') && check(i, j, k+2, '.'));
       ans += (check(i, j, k, '#') && check(i, j, k+1, '.') && check(i, j, k+2, '#'));
    }
  }
  cout << ans << endl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0 ; i < (n) ; i++)
#define rep1(i,n) for(int i = 1 ; i <= (n) ; i++)
#define rrep(i,n) for(int i = (n) - 1 ; i >= 0 ; i--)
#define rrep1(i,n) for(int i = (n) ; i > 0 ; i--)
#define INF 1001001001
#define MOD 1000000007
using ll = int64_t;
using P = pair<int, int>;
using PL = pair<ll,ll>;
using PD = pair<double,double>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using p_q = priority_queue<int, vi, greater<int>>;
#define v(n) vector<n>
#define vv(n) vector<vector<n>>
#define vvv(n) vector<vector<vector<n>>>
#define p_q(n) priority_queue<(n), v(n), greater<n>>
#define line cout << "================================" << endl;
#define Yn(x) ((x) ? "Yes" : "No")
#define yn(x) ((x) ? "yes" : "no")
#define mmax(a,b) a = max(a,b)
#define mmin(a,b) a = min(a,b)
#define debug(x) cout << #x" : " << (x) << endl;
#define output(x) cout << (x) << endl;
#define outs(x) cout << #x << endl;
#define mod(n,x) ((n)%(x))
#define all(a) (a).begin(),(a).end()

class alucrex{
    public:
    void vin(vi& a){rep(i,a.size())cin>>a[i];}
    void vvin(vvi& a){rep(i,a.size())rep(j,a[i].size())cin>>a[i][j];}
    void vvdes(vvi& a){rep(i,a.size()){rep(j,a[i].size()){
        cout << a[i][j] << " ";}cout<<endl;
    }}
    void vinl(vl& a){rep(i,a.size())cin>>a[i];}
    void vvinl(vvl& a){rep(i,a.size())rep(j,a[i].size())cin>>a[i][j];}
    void vvdesl(vvl& a){rep(i,a.size()){rep(j,a[i].size()){
        cout << a[i][j] << " ";}cout<<endl;
    }}
};

int main(){
    alucrex al;
    ll a, b, c;cin >> a >> b >> c;
    a *= a;
    b*= b;
    c*= c;
    cout << Yn(a+b<c) << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define sorts(s) sort(s.begin(), s.end())
#define sortu(s) sort(s.begin(), s.end(), greater<>())
typedef long long int ll;
using Graph = vector<vector<int>>;

int main(void) {
    int i = 0, j = 0, k = 0;
    int N; ll MOD = (1e+9)+7;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) {
        cin >> A[i];
    }
    vector<ll> fib(N+1);
    rep(i, N) {
        if (i == 0) {
            fib[i+1] = 1;
        } else if (i == 1) {
            fib[i+1] = 2;
        } else {
            fib[i+1] = (fib[i-1] + fib[i]) % MOD;
        }
    }
    vector<ll> plus(N-1), mins(N-1);
    rep(i, N-1) {
        if (i == 0) {
            plus[i] = 1; mins[i] = 1;
        } else {
            plus[i] = (plus[i-1] + mins[i-1]) % MOD;
            mins[i] = plus[i-1];
        }
    }
    rep(i, N-2) {
        plus[i] = (fib[N-1-i] * plus[i]) % MOD;
        mins[i] = (fib[N-2-i] * mins[i]) % MOD;
    }
    ll ans = (A[0] * fib[N]) % MOD;
    rep(i, N-1) {
        ans += (A[i+1] * plus[i]) % MOD;
        ans %= MOD;
        ans -= (A[i+1] * mins[i]) % MOD;
        if (ans < 0) {
            ans += MOD;
        } else {
            ans %= MOD;
        }
    }
    cout << ans << endl;
    //cout << fixed << setprecision(4) << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define pri_que priority_queue
#define vint vector<int>
#define vvint vector<vector<int>>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vs vector<string>
#define vvc vector<vector<char>>
#define vc vector<char>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define show(x) cout<<#x<<"="<<x<<endl;
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e15;
const long long MOD = 1e9+7;

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

    int a,b; cin >> a >> b;
    cout<<max(2*a+100-b,0LL)<<endl;
}

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

int main() {
    int a, b;
    cin >> a >> b;
    int ans = 2 * a + 100 - b;
    cout << ans << endl;
    return 0;
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define m_p make_pair
#define sz(x) (int)x.size()
#define line cerr<<"--------------------\n";
#define see(x) cerr<<x<<" "
#define seeln(x) cerr<<x<<endl
#define out(x) cerr<<#x<<" = "<<x<<" "
#define outln(x) cerr<<#x<<" = "<<x<<endl
#define outarr(x,l,r) cerr<<#x"["<<l<<"-"<<r<<"] = "; for (int _i=l;_i<=r;++_i) cerr<<x[_i]<<" ";cerr<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define gc() getchar()
//char buf[1<<23],*p1=buf,*p2=buf;
//#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
template <class T> void read(T &x)
{
    x=0; char c=gc(); int flag=0;
    while (c<'0'||c>'9') flag|=(c=='-'),c=gc();
    while (c>='0'&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=gc();
    if (flag) x=-x;
}
template <class T> inline T _max(T a,T b){return a>b ? a : b;}
template <class T> inline T _min(T a,T b){return a<b ? a : b;}
template <class T> inline bool checkmax(T &a,T b){return b>a ? a=b,1 : 0;}
template <class T> inline bool checkmin(T &a,T b){return b<a ? a=b,1 : 0;}
int n,k,mod;
int Add(int x,int y){x+=y; return x>=mod ? x-mod : x;}
int Sub(int x,int y){x-=y; return x<0 ? x+mod : x;}
int Mul(int x,int y){return (ll)x*y%mod;}
void add(int &x,int y){x=Add(x,y);}
void sub(int &x,int y){x=Sub(x,y);}
void mul(int &x,int y){x=Mul(x,y);}
int dp[102][128000];
void init()
{
	read(n); read(k); read(mod);
	dp[0][0]=1;
	for (int i=1;i<=n;++i)
	{
		int tmp=_min(i,50);
		for (int r=0;r<=k;++r)
		{
			for (int j=r*i;j<=tmp*(tmp+1)/2*k;++j)
			{
				add(dp[i][j],dp[i-1][j-r*i]);
			}
		}
	}
}

int calc(int x)
{
	int tmp=_min(x-1,n-x);
	int ans=0;
	for (int i=0;i<=tmp*(tmp+1)/2*k;++i)
	{
		if (i) add(ans,Mul(Mul(dp[x-1][i],dp[n-x][i]),k+1));
		else add(ans,k);
	}
	return ans;
}

void solve()
{
	for (int i=1;i<=n;++i)
	{
		printf("%d\n",calc(i));
	}
}

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

/* Average = a is the same as sum of abs(i-a) = 0
 * which is the same as sum of i-a (for all i to the left) = a-i (for all i to the right)
 * so let dp[i][j] = number of ways to form sum of j using 1...i
 */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(ll i = (ll)a; i <= (ll)b; i++)
#define DEC(i, a, b) for(ll i = (ll)a; i >= (ll)b; i--)
typedef pair<ll, ll> pi;
typedef pair<pi, ll> pii;
typedef pair<ll, pi> ipi;
typedef pair<pi, pi> pipi;
#define mp make_pair
#define f first
#define s second
typedef vector<ll> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define size(v) (ll) v.size()
#define disc(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
#define INF (ll) 1e9 + 100
#define LLINF (ll) 1e18
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sandybridge __attribute__((optimize("Ofast"), target("arch=sandybridge")))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss

ll n, k, mod, dp[105][1000005];

int main() {
	fastio; cin >> n >> k >> mod;
	dp[0][0] = 1;
	FOR(i, 1, n) {
		vi v(i, 0);
		FOR(j, 0, k*n*(n+1)/2) {
			ll m = j % i;
			v[m] = (v[m] + dp[i-1][j]) % mod;
			if (j - ((k+1) * i) >= 0) v[m] = (v[m] - dp[i-1][j - ((k+1) * i)] + mod) % mod;
			dp[i][j] = v[m];
		}
	}
	FOR(i, 1, n) {
		ll ans = 0;
		FOR(j, 0, k*i*(i+1)/2) (ans += dp[i-1][j] * dp[n-i][j]) %= mod;
		cout << (ans * (k+1) - 1 + mod) % mod << "\n";
	}
}


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

using namespace std;

int h, w;
int memo[2000][2000];
int inf = INT_MAX;
string s[2000];

int f(int i, int j)
{
    if (i == h - 1 && j == w - 1) return 0;
    if (memo[i][j] != -inf) return memo[i][j];
    int res = -inf;
    if (i < h - 1) res = max(res, (s[i + 1][j] == '+' ? 1 : -1) - f(i + 1, j));
    if (j < w - 1) res = max(res, (s[i][j + 1] == '+' ? 1 : -1) - f(i, j + 1));
    return memo[i][j] = res;
}

int main()
{
    cin >> h >> w;
    rep(i, h) cin >> s[i];
    rep(i, h) rep(j, w) memo[i][j] = -inf;
    int ans = f(0, 0);
    if (ans == 0) cout << "Draw";
    if (ans > 0) cout << "Takahashi";
    if (ans < 0) cout << "Aoki";

    return 0;
}

#include <bits/stdc++.h>

#define fileio                                                  \
    freopen("C:\\Users\\PRISM17\\Desktop\\in.txt", "r", stdin); \
    freopen("C:\\Users\\PRISM17\\Desktop\\out.txt", "w", stdout);
#define fastio                   \
    ios::sync_with_stdio(false); \
    cin.tie(0);                  \
    cout.tie(0);
#define dbg(x) cout << #x << " : " << x << endl;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)

#define mid (st[id].l + st[id].r >> 1)
#define lson (id << 1)
#define rson (id << 1 | 1)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> PII;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const int inf = 0x3f3f3f3f;
const int INF = 1e9;

const int N = 2e3 + 7;
char mp[N][N];
int n, m;
int dp[N][N][2];

inline int get(int x, int y){
    char ch = mp[x][y];
    return ch == '+' ? 1 : -1;
}
int dfs(int x, int y, int op) {
    if (x == n && y == m) return 0;
    int &ans = dp[x][y][op];
    if (ans != -1) return ans;
    if (op) {
        ans = -inf;
        if (x < n) ans = max(dfs(x + 1, y, op ^ 1) + get(x + 1, y), ans);
        if (y < m) ans = max(dfs(x, y + 1, op ^ 1) + get(x, y + 1), ans);
    } else {
        ans = inf;
        if (x < n) ans = min(dfs(x + 1, y, op ^ 1) - get(x + 1, y), ans);
        if (y < m) ans = min(dfs(x, y + 1, op ^ 1) - get(x, y + 1), ans);
    }
    return ans;
}

int main() {
    memset(dp, -1, sizeof dp);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cin >> mp[i][j];
        }
    }
    int res = dfs(1, 1, 1);
    if (res > 0) puts("Takahashi");
    else if (res < 0) puts("Aoki");
    else puts("Draw");
}


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

void print(vector<int> &a){for(auto l : a) cout<<l<<" "; cout<<'\n';}

void solve(){
    int n,m;
    cin>>n>>m;
    int a[n][m];
    int mi = INT_MAX;
    for(int i=0;i<n;++i){
        for(int j=0;j<m;++j) cin>>a[i][j], mi=min(mi,a[i][j]);
    }
    int ans = 0;
    for(int i=0;i<n;++i){
        for(int j=0;j<m;++j) ans+= a[i][j] - mi;
    }
    cout<<ans;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("lex.in", "r", stdin);//freopen("output.txt", "w", stdout);
    int t = 1;
    //cin>>t;
    while(t--){
        solve();
    }
}

#include <bits/stdc++.h>
#include <stdlib.h>
#include <ctype.h>
#include <regex>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())

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

    vector<vector<int>> data(H, vector<int>(W));

    rep(i,H){
        rep(j,W){
            cin >> data.at(i).at(j);
        }
    }
    int min = data.at(0).at(0);

    rep(i,H){
        rep(j,W){
            if(data.at(i).at(j) < min){
                min = data.at(i).at(j);
            }
        }
    }

    int count = 0;
    rep(i,H){
        rep(j,W){
            count += (data.at(i).at(j) - min);
        }
    }
    cout << count;

}


#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define ld long double
#define fi first
#define se second
#define all(uiet) uiet.begin(),uiet.end()
#define read(UIET, n) for(int i = 0; i < n; ++i) cin >> UIET[i]
#define out(UIET, n) for(int i = 0; i < n; ++i) cout << UIET[i] << " "
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vpp vector<pair< int, int > >
#define pll pair<int , int >
#define ppll pair < pll , pll >
#define debug(n1) cout << n1 << endl
#define len(a) ((int) (a).size())
#define endl "\n"
#define mod 1000000007
const int INF = (1LL<<60)-1;
const int maxN = 1000001;
int32_t main(){
    SPEED;
    int t = 1;
    //cin >> t;
    while(t--){
        int n, m;
        cin >> n >> m;
        if(abs(n - m) < 3) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
*/

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

int main(){
	int x,y,abs;
    cin >> x >> y;
    abs = max(x-y,y-x);
  	if(abs<3){
      cout << "Yes";
    }
  else{
    cout << "No";
  }

}


/*
 © 2021-03-28 06:53:10 Franco1010 All Rights Reserved
*/

// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
// #pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<lli,lli> ii;
typedef vector<lli> vi;
#define deb(x) cout << #x": " << (x) << endl;
using uint=unsigned;
using ull=unsigned long long;
struct modinfo{uint mod,root;};
template<modinfo const&ref>
struct modular{
	static constexpr uint const &mod=ref.mod;
	static modular root(){return modular(ref.root);}
	uint v;
	//modular(initializer_list<uint>ls):v(*ls.bg){}
	modular(lli vv=0){s(vv%mod+mod);}
	modular& s(uint vv){
		v=vv<mod?vv:vv-mod;
		return *this;
	}
	modular operator-()const{return modular()-*this;}
	modular& operator+=(const modular&rhs){return s(v+rhs.v);}
	modular&operator-=(const modular&rhs){return s(v+mod-rhs.v);}
	modular&operator*=(const modular&rhs){
		v=ull(v)*rhs.v%mod;
		return *this;
	}
	modular&operator/=(const modular&rhs){return *this*=rhs.inv();}
	modular operator+(const modular&rhs)const{return modular(*this)+=rhs;}
	modular operator-(const modular&rhs)const{return modular(*this)-=rhs;}
	modular operator*(const modular&rhs)const{return modular(*this)*=rhs;}
	modular operator/(const modular&rhs)const{return modular(*this)/=rhs;}
	modular pow(int n)const{
		modular res(1),x(*this);
		while(n){
			if(n&1)res*=x;
			x*=x;
			n>>=1;
		}
		return res;
	}
	modular inv()const{return pow(mod-2);}

	friend modular operator+(int x,const modular&y){
		return modular(x)+y;
	}
	friend modular operator-(int x,const modular&y){
		return modular(x)-y;
	}
	friend modular operator*(int x,const modular&y){
		return modular(x)*y;
	}
	friend modular operator/(int x,const modular&y){
		return modular(x)/y;
	}
	friend ostream& operator<<(ostream&os,const modular&m){
		return os<<m.v;
	}
	friend istream& operator>>(istream&is,modular&m){
		lli x;is>>x;
		m=modular(x);
		return is;
	}
	bool operator<(const modular&r)const{return v<r.v;}
	bool operator==(const modular&r)const{return v==r.v;}
	bool operator!=(const modular&r)const{return v!=r.v;}
	explicit operator bool()const{
		return v;
	}
};

extern constexpr modinfo base{998244353,3};
// extern constexpr modinfo base{1000000007,0};
//modinfo base{1,0};
using mint=modular<base>;

//COMBI

const int vmax=(1<<21)+10;
mint fact[vmax],finv[vmax],invs[vmax];
void initfact(){
	fact[0]=1;
	fore(i,1,vmax)fact[i]=fact[i-1]*i;
	finv[vmax-1]=fact[vmax-1].inv();
	for(int i=vmax-2;i>=0;i--)finv[i]=finv[i+1]*(i+1);
	for(int i=vmax-1;i>=1;i--)invs[i]=finv[i]*fact[i-1];
}
mint choose(int n,int k){
	return fact[n]*finv[n-k]*finv[k];
}
mint binom(int a,int b){
	return fact[a+b]*finv[a]*finv[b];
}
mint catalan(int n){
	return binom(n,n)-(n-1>=0?binom(n-1,n+1):0);
}
const lli N = 2e5 + 5;
lli p[N];
vi primes;
lli n, m;
set<vi> st;
void dfs(vi& v, lli cur){
  if(sz(v) == n){
    st.insert(v);
    return;
  }
  lli foo = cur;
  while(foo <= m){
    v.pb(foo);
    dfs(v, foo);
    v.pop_back();
    foo += cur;
  }
}
mint f(lli x){
  mint res = 1;
  while(x > 1){
    lli foo = p[x];
    lli cnt = 0;
    while(p[x] == foo){
      x /= p[x];
      cnt++;
    }
    res *= choose(n - 1 + cnt, cnt);
  }
  return res;
}
int main(){ _
  p[0] = p[1] = 1;
  for(lli i = 2; i < N; i++) if(!p[i]) for(lli j = i; j < N; j += i) p[j] = i;
  // fore(i, 0, N) if(!p[i]) primes.pb(i);
  // freopen("file.in","r",stdin);
  // freopen("file.out","w",stdout);
  initfact();
  cin >> n >> m;
  mint ans = 0;
  fore(i, 2, m + 1){
    ans += f(i);
  }
  cout << ans + mint(1) << ENDL;
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef  long long int ll;
typedef pair<ll, ll> pll;
#define pb push_back
typedef long double ld;
#define fi first
#define se second
#define PI 3.14159265358979323846264338327950288419716939937510
#define mp make_pair
#define vvl vector<vector<ll>>
#define vll vector<ll>
#define vpll vector<pll>
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
*/

ll inf = 1e18;
ll p = 998244353 ;
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
ll pwr(ll x, ll y)
{
    ll res = 1;
    x = x ;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) ;
        y = y >> 1;
        x = (x * x) ;
    }
    return res;
}
ll modInverse(ll n, ll p)
{
    return power(n, p - 2, p);
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll i,  y, x,  z, g, key,   h, n, m, t, a, b, c, j, k;
    ll t2, t3, t4, t1, t5, t6;
    string s;
    ll l, r;
    //cin >> t;
    t = 1;
    while (t--)
    {
        cin >> n >> x;
        ll ncr[x + 1][x + 1];
        memset(ncr, 0, sizeof(ncr));
        ncr[0][0] = 1;
        vll val(x + 1, 0);
        val[0] = n;
        ll arr[n];
        for (i = 0; i < n; i++)
        {
            cin >> arr[i];
            t1 = arr[i];
            for (j = 1; j <= x; j++)
            {
                val[j] = (val[j] + t1) % p;
                t1 = (t1 * arr[i]) % p;

            }
        }
        for (i = 1; i <= x; i++)
        {
            for (j = 0; j <= x; j++)
            {
                ncr[i][j] = ncr[i - 1][j];
                if (j)
                {
                    ncr[i][j] = (ncr[i][j] + ncr[i - 1][j - 1]) % p;
                }

            }
        }
        for (k = 1; k <= x; k++)
        {
            ll ans = 0;
            for (i = 0; i <= k; i++)
            {
                t1 = (ncr[k][i] * val[i]) % p;
                t1 = (t1 * val[k - i]) % p;
                ans = (ans + t1);
            }
            //cout << ans << "\n";
            t2 = power(2, k, p);
            t2 = (t2 * val[k]) % p;
            ans = ((ans - t2) % p + p) % p;
            ans = (ans * modInverse(2, p)) % p;
            cout << ans << "\n";
        }

    }

    return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <vector>
#include <math.h>
#include <iomanip>
#include <set>
#define I int
#define LL long long
#define F float
#define S string
#define B bool
#define C char
#define N 200001
#define PI 3.14159265358979
using namespace std;
int main()
{
    C a,b,c;
    cin>>a>>b>>c;
    if(a==b&&b==c)
    {
        cout<<"Won";
    }
    else cout<<"Lost";
    return 0;
}

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#define res register int
#define LL long long
#define oo 0x3f3f3f3f
using namespace std;
LL Fastmul(LL a,LL b,LL p){
	LL ans=0;
	while(b>0){
		if(b&1)	ans=(ans+a)%p;
		a=a*2%p;
		b>>=1;
	}
	return ans;
}
LL Fastpow(LL a,LL b,LL p){
	LL ans=1;
	while(b>0){
		if(b&1)	ans=ans*a%p;
		a=Fastmul(a,a,p);
		b>>=1;
	}
	return ans%p;
}
int mp[10][4]={{0,0,0,0},{1,1,1,1},{2,4,8,6},{3,9,7,1},{4,6,4,6},{5,5,5,5},{6,6,6,6},{7,9,3,1},{8,4,2,6},{9,1,9,1}};
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	b=Fastpow(b,c,4);
	a=a%10;
	if(b==0)	b=4;
	cout<<mp[a][b-1];
	return 0;
}


// ARC107.cpp
#include <iostream>
using namespace std;
using ll = long long;
int n;
ll f(int k) {
    return max(0,min(k - 1, 2 * n - k + 1));
}
// a+b==c+d+Kなら
// a+b==xの時、
// c+d==x-K
int main()
{
    int k;
    cin >> n >> k;
    ll ans = 0;

    for (int x = 2; x <= 2 * n;x++) {
        ans += f(x) * f(x - k);
    }
    cout << ans << endl;
}

// *********************************************************************************
// *                        MURTAZA MUSTAFA KHUMUSI                                *
// *                        NIT-DGP,CSE - 2019-2023                                *
// *********************************************************************************

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007;
#define loop(i, a, n) for (int i = a; i < n; i++)
#define loop1(i, b, n) for (int i = b; i <= n; i++)
#define loopit(a) for (auto it = a.begin(); it != a.end(); it++)
#define ms(a, b) memset(a, b, sizeof(a))
#define pb(a) push_back(a)
#define MP make_pair
#define pi pair<int, int>
#define ff first
#define ss second
#define bloop(i, a, b) for (int i = a; i > b; i--)
#define bloop1(i, a, b) for (int i = a; i >= b; i--)
#define PQ priority_queue<int> pq;
#define vi vector<int>
#define si set<int>
#define MPQ priority_queue<pi, vector<int>, greater<pi>> mpq;
#define io                        \
    ios_base::sync_with_stdio(0); \
    cin.tie(NULL);
const int maxm = 300005;
// ll m = 1e9 + 7;
ll m = 998244353;
vector<vi> adj;
vi h;
vi sz;
vi in;

ll add(ll a, ll b, ll mod = m)
{
    return ((a % mod) + (b % mod)) % mod;
}
ll mul(ll a, ll b, ll mod = m)
{
    return ((a % mod) * (b % mod)) % mod;
}
ll sub(ll a, ll b, ll mod = m)
{
    return ((a % mod) - (b % mod) + mod) % mod;
}

ll modmul(ll a, ll b, ll mod = m)
{
    ll ans = 0;
    a = a % mod;
    while (b)
    {
        if (b & 1)
            ans = add(ans, a, mod);
        a = mul(a, 2, mod);
        b >>= 1;
    }
    return ans;
}

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

ll fe(ll base, ll exp, ll mod = m)
{
    ll ans = 1;
    while (exp)
    {
        if (exp & 1)
            ans = mul(ans, base, mod);
        base = mul(base, base, mod);
        exp >>= 1;
    }
    return ans;
}

void dfs_h_sz(int cur, int par)
{
    h[cur] = h[par] + 1;
    sz[cur]++;
    for (const auto &v : adj[cur])
    {
        if (v == par)
            continue;
        dfs_h_sz(v, cur);
        sz[cur] += sz[v];
    }
}

void buildGraph(int n, int m)
{
    adj = vector<vi>(n + 1);
    h = vector<int>(n + 1);
    sz = vector<int>(n + 1);
    in = vector<int>(n + 1);

    loop(i, 0, m)
    {
        int a, b;
        cin >> a >> b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    dfs_h_sz(1, 0);
}
struct cmp
{
    bool operator()(const pi &a, const pi &b)
    {
        return a.ff < b.ff;
    }
};

ll modin(ll a)
{
    return fe(a, m - 2);
}

ll sum(ll a)
{
    return mul(mul(a, a + 1), modin(2));
}
void solve()
{
    int n,k;
    ll sum = 0;
    cin>>n>>k;
    int a = abs(k);
    int arr[maxm]  ={0};
    // int arr[maxm] = {0};

    loop1(i,1,2*n){
        if(i<=n)
        arr[i] = i-1;
        else
        arr[i] = 2*n-i+1;
    }

    loop1(i,2,2*n){
        if(2<=i+k && i+k<=2*n)
        sum += 1LL*arr[i]*arr[i+k];
    }
    cout<<sum<<"\n";
}
int main()
{
    io;

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int test;
    // cin >> test;
    test = 1;
    while (test--)
    {
        solve();
    }
    return 0;
}


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

using ll = long long;
using Vi = std::vector<int>;
using Vl = std::vector<ll>;
using Pii = std::pair<int, int>;
using Pll = std::pair<ll, ll>;

constexpr int I_INF = std::numeric_limits<int>::max();
constexpr ll L_INF = std::numeric_limits<ll>::max();

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

template <std::ostream& os = std::cout>
class Prints {
private:
    class __Prints {
    public:
        __Prints(const char* sep, const char* term) : sep(sep), term(term) {}
        template <class... Args>
#if __cplusplus >= 201703L
        auto operator()(const Args&... args) const -> decltype((os << ... << std::declval<Args>()), void()) {
#else
        void operator()(const Args&... args) const {
#endif
            print(args...);
        }
        template <typename T>
#if __cplusplus >= 201703L
        auto pvec(const T& vec, size_t sz) const -> decltype(os << std::declval<decltype(std::declval<T>()[0])>(), void()) {
#else
        void pvec(const T& vec, size_t sz) const {
#endif
            for (size_t i = 0; i < sz; i++)
                os << vec[i] << (i == sz - 1 ? term : sep);
        }
        template <typename T>
#if __cplusplus >= 201703L
        auto pmat(const T& mat, size_t h, size_t w) const -> decltype(os << std::declval<decltype(std::declval<T>()[0][0])>(), void()) {
#else
        void pmat(const T& mat, size_t h, size_t w) const {
#endif
            for (size_t i = 0; i < h; i++)
                for (size_t j = 0; j < w; j++)
                    os << mat[i][j] << (j == w - 1 ? term : sep);
        }

    private:
        const char *sep, *term;
        void print() const { os << term; }
        void print_rest() const { os << term; }
        template <class T, class... Tail>
        void print(const T& head, const Tail&... tail) const { os << head, print_rest(tail...); }
        template <class T, class... Tail>
        void print_rest(const T& head, const Tail&... tail) const { os << sep << head, print_rest(tail...); }
    };

public:
    Prints() {}
    __Prints operator()(const char* sep = " ", const char* term = "\n") const { return __Prints(sep, term); }
};

Prints<> prints;
Prints<std::cerr> prints_err;

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

ll dp[101][101];

void solve() {
    ll N, K;
    cin >> N >> K;
    Vl A(N);
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
    }
    ll ans = L_INF;
    for (ll k = 1; k <= N; k++) {
        for (ll j = 0; j <= k; j++) {
            for (ll r = 0; r < k; r++) {
                dp[j][r] = -L_INF;
            }
        }
        dp[0][0] = 0;
        for (ll i = 0; i < N; i++) {
            for (ll j = k; j >= 0; j--) {
                for (ll r = 0; r < k; r++) {
                    ll r_nxt = (r + A[i]) % k;
                    if (j > 0 && dp[j - 1][r] != -L_INF) {
                        chmax(dp[j][r_nxt], dp[j - 1][r] + A[i]);
                    }
                }
            }
        }
        ll mx = dp[k][K % k];
        if (mx != -L_INF) {
            chmin(ans, (K - mx) / k);
        }
    }
    prints()(ans);
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    std::cin.tie(nullptr), std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    std::ifstream ifs("./in_out/input.txt");
    std::cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    std::ofstream ofs("./in_out/output.txt");
    std::cout.rdbuf(ofs.rdbuf());
#endif
    std::cout << std::setprecision(18) << std::fixed;
    solve();
    std::cout << std::flush;
    return 0;
}

#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <set>
#include <vector>
#include <queue>
#include <map>
#include <numeric>
#include <math.h>
#include <complex>

using namespace std;

#define rep(i, n) for (long long int i = 0; i < (long long int)(n); i++)
#define irep(i, n) for (long long int i = 1; i <= (long long int)(n); i++)
#define drep(i, n, diff) for (long long int i = 0; i < (long long int)(n); i += diff)
#define mod 1000000007
#define INF 1001001001001001011
#define ld(val) printf("%s : %lld\n", #val, val);
#define sd(val) printf("%s : %s\n", #val, val.c_str());

typedef long long int ll;
typedef pair<ll, ll> P;
typedef pair<P, P> PP;
typedef tuple<ll, ll, ll> TP;

int main() {
  ll x, y, a, b;
  cin >> x >> y >> a >> b;
  ll ans =0;
  while((double)a<(double)y/x && a*x<x+b) {
    x*=a;
    ans++;
  }
  ll v = (y-x-1)/b;
  cout << ans + v << endl;
  return 0;
}


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

int main(){
  ll n;
  cin >> n;
  vector<ll> a(n);
  ll tmp1=0, tmp2=0;
  for(ll i=0; i<n; i++){
    cin >> a[i];
    tmp1 += a[i];
    tmp2 += a[i]*a[i];
  }
  ll ans;
  ans = n*tmp2 - tmp1*tmp1;
  cout << ans << endl;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

int main() {
	int n;
	cin >> n;
	// std::vector<int> vect(n);
	std::vector<int> v(401,0);
	long long int temp;
	for (int i = 0; i < n; ++i)
	{
		// cin >> vect[i];
		cin >> temp;
		v[temp+200]++;
	}
	long long int res = 0;
	for (int i = 1; i < 401; ++i)
	{
		for (int j = 0; j < i; ++j)
		{
			temp = i-j;
			res += (temp * temp) * v[i] * v[j];
		}
	}
	cout << res << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
const double pi = 3.14159265358979;
const ll inf = 1e17;
const int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
#define pii pair<int,int>
#define pll pair<ll,ll>
#define endl "\n"
#define dtor(deg) (((deg)/360)*2*pi)
#define all(a) a.begin(),a.end()
#define overload(_1,_2,_3,_4,name,...) name
#define _rep1(n) for(int i = 0; i < (n); i++)
#define _rep2(i,n) for(int i = 0; i < (n); i++)
#define _rep3(i,a,b) for(int i = (a); i < (b); i++)
#define _rep4(i,a,b,c) for(int i = (a); i < (b); i += (c))
#define rep(...) overload(__VA_ARGS__,_rep4,_rep3,_rep2,_rep1)(__VA_ARGS__)
#define _rrep1(n) for(int i = (n) - 1; i >= 0; i--)
#define _rrep2(i,n) for(int i = (n) - 1; i >= 0; i--)
#define _rrep3(i,a,b) for(int i = (b) - 1; i >= (a); i--)
#define _rrep4(i,a,b,c) for(int i = (b) - 1; i >= (a); i -= (c))
#define rrep(...) overload(__VA_ARGS__,_rrep4,_rrep3,_rrep2,_rrep1)(__VA_ARGS__)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define vv(type,name,size,...) vector<vector<type>> name(size,vector<type>(__VA_ARGS__))
#define ForEach(a,b) for_each(a.begin(),a.end(),b)
struct Edge { int to; ll cost; Edge(int to, ll cost) : to(to), cost(cost) {} };
using Graph = vector<vector<Edge>>;
template <class T> bool chmin(T& a, T b){ if(a > b){ a = b; return 1; } return 0; }
template <class T> bool chmax(T& a, T b){ if(a < b){ a = b; return 1; } return 0; }

void Main(){
    ll n;
    cin >> n;
    cout << max((ll)0, n - 999999999999999) + max((ll)0, n - 999999999999) + max((ll)0, n - 999999999) + max((ll)0, n - 999999) + max((ll)0, n - 999) << endl;
}

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

#include <bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define fixx(n) fixed << setprecision(n)
#define F first
#define S second
#define PI  3.14159265358979323846
#define ll  long long int
#define int ll
#define double long double
const int mod = 1e9 + 7;
const int modd = 998244353;
const int N = 1e5;

signed main()
{

    FAST;
    int n;
    cin >> n;
    int k = 1000;
    int ans = 0;
    while(k <= n){
        ans += (n - k + 1);
        k *= 1000;
    }
    cout << ans << endl;
    return 0;
}


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

#define MAX 100
double dp[MAX+1][MAX+1][MAX+1];

int main(void){
    int a, b, c;

    cin >> a >> b >> c;

    for (int i = MAX-1; i >= 0; i--){
        for (int j = MAX-1; j >= 0; j--){
            for (int k = MAX-1; k >= 0; k--){
                double now = 0;
                if (i+j+k == 0) continue;
                now += dp[i+1][j][k] * i;
                now += dp[i][j+1][k] * j;
                now += dp[i][j][k+1] * k;
                dp[i][j][k] = now / (i + j + k) + 1;
            }
        }
    }

    printf("%.10f\n", dp[a][b][c]);

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forin(in) for(ll i=0; i<(ll)in.size(); i++) cin>>in[i]
#define forout(out) for(ll i=0; i<(ll)out.size(); i++) cout<<out[i]<<endl
#define rep(i, n) for(ll i=0; i<(n); i++)
#define rep_up(i, a, n) for (ll i = a; i < n; ++i)
#define rep_down(i, a, n) for (ll i = a; i >= n; --i)
#define P pair<ll, ll>
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; }
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define vvvll vector<vector<vector<ll>>>
#define vvll vector<vector<ll>>
#define vll vector<ll>
#define pqll priority_queue<ll>
#define pqllg priority_queue<ll, vector<ll>, greater<ll>>
constexpr ll INF = (1ll << 60);
constexpr ll mod = 1000000007;

double v[110][110][110];
//func(a,b,c):v[a][b][c]を返す
double func(int a,int b,int c) {
    if(a >= 100||b >= 100||c >= 100) return 0.0;
    if(v[a][b][c] > -1) return v[a][b][c];

    double ans = 0;
    ans += (double)(a) / (a+b+c)*(func(a+1,b,c) + 1);
    ans += (double)(b) / (a+b+c)*(func(a,b+1,c) + 1);
    ans += (double)(c) / (a+b+c)*(func(a,b,c+1) + 1);
    v[a][b][c] = ans;
    return v[a][b][c];
}

int main() {
    int a, b, c; cin >> a >> b >> c;
    memset(v, -1, sizeof(v));
    cout << fixed << setprecision(10) << func(a,b,c) << endl;
}


#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#include<iostream>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 320000;
char cn[CM], * ci = cn, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += 72 - dig >> 3;
	return tmp;
}
const int MAX = 10000;
class shuturyoku_unko {
public:
	char C[MAX * 5];
	constexpr shuturyoku_unko() : C() {
		rep(i, MAX) {
			int X = i;
			rep(j, 4) {
				C[i * 5 + 3 - j] = '0' + X % 10;
				X /= 10;
			}
			C[i * 5 + 4] = '\n';
		}
	}
};
constexpr shuturyoku_unko f;
const int dm = 260000;
char dn[dm], * di = dn;
void putint(ll A) {
	int dig = 1;
	if (A >= 100000000) {
		if (A >= 100000000000) dig = 4;
		else if (A >= 10000000000) dig = 3;
		else if (A >= 1000000000) dig = 2;
		memcpy(di + 4 + dig, f.C + A % 10000 * 5, 5);
		A /= 10000;
		memcpy(di + dig, f.C + A % 10000 * 5, 4);
		memcpy(di, f.C + A / 10000 * 5 + 4 - dig, dig);
		di += 9 + dig;
	}
	else {
		if (A >= 10000) {
			if (A >= 10000000) dig = 4;
			else if (A >= 1000000) dig = 3;
			else if (A >= 100000) dig = 2;
			memcpy(di + dig, f.C + A % 10000 * 5, 5);
			memcpy(di, f.C + A / 10000 * 5 + 4 - dig, dig);
			di += 5 + dig;
		}
		else {
			if (A >= 1000) dig = 4;
			else if (A >= 100) dig = 3;
			else if (A >= 10) dig = 2;
			memcpy(di, f.C + A * 5 + 4 - dig, dig + 1);
			di += 1 + dig;
		}
	}
}

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

	fread(cn, 1, 320000, stdin);
	int T = getint();

	rep(t, T) {
		int L = getint(), R = getint();

		ll tmp = R - L - L;
		if (tmp >= 0) putint((tmp + 2) * (tmp + 1) >> 1);
		else putint(0);
	}
	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}


#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using ld = long double;
const int INF = 1e9;
const ll LIN = 1e18;

int main() {
  ll N;
  cin >> N;
  ll ans = LIN;
  for (ll i = 0; i < 64;i++) {
    ll b = ((ll)1 << i);
    ll a = N / b, c = N % b;
    ans = min(ans, a + i + c);
  }
  cout<<ans<<endl;
}

#include<iostream>

using namespace std;

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

	cout << N - 1 << endl;

	return 0;
}


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

#define asll unsigned long long
#define ll long long
#define ld long double
#define imt int
#define pii pair<int,int>
#define st first
#define nd second
#define psbk(x) push_back(x);
#define For(x,a,b) for(int x=(a);x!=(b+((b-a)/abs(b-a)));x+=(b-a)/abs(b-a))
#define FOR(x,n) for(int x=0;x<(n);x++)
#define m_p make_pair

#define kj <<" "<<
#define kjb <<" ";
#define dg <<","<<
#define ml <<endl;
#define co cout<<
#define ter cout<<endl;
#define sibi cout<<"TES"<<endl;
#define tes(x) cout<<"TES"<<x<<endl;
#define kpr(x) cout<<"("<<x.st dg x.nd <<")" ml
#define kkor(p) cout<<"("<<p.x dg p.y <<")" ml
#define kera(x,m) for( int i = 0;i < m ; i++ ){ cout<<"x["<< i <<"] =" kj x[i] ml}

asll M=1e9+7;
int h,w,n,m;
int p,q,r;

int ma[1505][1505];
int terang[1505][1505];

int main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(0);
	//freopen("stdin.in", "r", stdin)
 	//freopen("stdout.out", "w", stdout)
	srand(time(0));
	cin>>h>>w>>n>>m;
	FOR(i,h+1){
		//hix[i]=0;
		FOR(j,w+1){
			ma[i][j]=1;
			terang[i][j]=0;
			//hiy[j]=0;
		}
	}
	FOR(i,n){
		cin>>p>>q;
		ma[p][q]=2;
		//hiy[q]=1;
	}
	FOR(i,m){
		cin>>p>>q;
		ma[p][q]=0;
	}
	ll ctr=0;
	//c//o "-" ml
	int kai=0;
	For(i,1,h){
		kai=0;
		For(j,1,w){
			if(ma[i][j]==2){
				kai=1;
			}
			else if(ma[i][j]==0){
				kai=0;
			}
			if(kai==1 && ma[i][j]){
				terang[i][j]=1;
			}
		}
	}
	kai=0;
	For(i,1,h){
		kai=0;
		For(j,w,1){
			if(ma[i][j]==2){
				kai=1;
			}
			else if(ma[i][j]==0){
				kai=0;
			}
			if(kai==1 && ma[i][j]){
				terang[i][j]=1;
			}
		}
	}
	kai=0;
	For(j,1,w){
		kai=0;
		For(i,1,h){
			if(ma[i][j]==2){
				kai=1;
			}
			else if(ma[i][j]==0){
				kai=0;
			}
			if(kai==1 && ma[i][j]){
				terang[i][j]=1;
			}
		}
	}
	kai=0;
	For(j,1,w){
		kai=0;
		For(i,h,1){
			if(ma[i][j]==2){
				kai=1;
			}
			else if(ma[i][j]==0){
				kai=0;
			}
			if(kai==1 && ma[i][j]){
				terang[i][j]=1;
			}
		}
	}
	For(i,1,h){
		For(j,1,w){
			//co terang[i][j] kjb;
			if(terang[i][j]){
				ctr++;
			}
		}
		//ter
	}
	co ctr ml

}

#include <stack>
#include <queue>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <set>
#include <tuple>
#include <cmath>
#include <random>
#include <algorithm>
#include <vector>
#include <iostream>
#include <fstream>
#include <chrono>
#include <numeric>

#define fio ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)
#define rng mt19937_64 rnd(chrono::system_clock::now().time_since_epoch().count())

#define ri(...) i64 __VA_ARGS__; rx(__VA_ARGS__)
#define rc(...) char __VA_ARGS__; rx(__VA_ARGS__)
#define rs(...) string __VA_ARGS__; rx(__VA_ARGS__)
#define rvi(x, n) vi x(n); cin >> x
#define rvvi(x, n, m) vvi x(n, vi(m)); cin >> x

#ifndef ONLINE_JUDGE
#define dbg(...) cerr << '[' << #__VA_ARGS__ << "]: "; dbg_log(__VA_ARGS__)
#else
#define dbg(...) ;;
#endif

#define fa(i, v) for (auto &i : v)
#define fi(i, n) for (i32 i = 0; i < n; i++)
#define fp(i, n) for (i32 i = 1; i < n; i++)
#define fr(i, n) for (i32 i = n - 1; i >= 0; i--)
#define fu(i) ri(__i); fi(i, __i)

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;

typedef uint32_t u32;
typedef int32_t i32;
typedef uint64_t u64;
typedef int64_t i64;
#ifdef __SIZEOF_INT128__
typedef __uint128_t u128;
typedef __int128_t i128;
#endif
typedef vector<i64> vi;
typedef vector<vi> vvi;
typedef pair<i64, i64> pi;

template<typename T>
inline istream &operator>>(istream &in, vector<T> &v) {
    fa(x, v) in >> x;
    return in;
}

template<typename T>
inline ostream &operator<<(ostream &out, const vector<T> &v) {
    fa(x, v) out << x << ' ';
    return out;
}

template<typename T>
inline void rx(T &x) {
    cin >> x;
}

template<typename T, typename... R>
inline void rx(T &x, R &... l) {
    cin >> x;
    rx(l...);
}

template<typename T>
inline void dbg_log(const T &x) {
    cerr << x << endl;
}

template<typename T, typename... R>
inline void dbg_log(const T &x, const R &... l) {
    cerr << x << ", ";
    dbg_log(l...);
}

template<typename T>
inline void wl(const T &x) {
    cout << x << '\n';
}

template<typename T, typename... R>
inline void wl(const T &x, const R &... l) {
    cout << x << ' ';
    wl<R...>(l...);
}

int main() {
    fio;

    ri(h, w, n, m);
    vvi mat(h, vi(w));
    fi(i, n) {
        ri(a, b);
        mat[a - 1][b - 1] |= 0x10;
    }
    fi(i, m) {
        ri(c, d);
        mat[c - 1][d - 1] |= 0x20;
    }

    fi(i, h) {
        fp(j, w) {
            if (!(mat[i][j] & 0x30) && (mat[i][j - 1] & 0x11)) {
                mat[i][j] |= 0x01;
            }
        }
        fp(j, w) {
            if (!(mat[i][w - j - 1] & 0x30) && (mat[i][w - j] & 0x12)) {
                mat[i][w - j - 1] |= 0x02;
            }
        }
    }
    fi(j, w) {
        fp(i, h) {
            if (!(mat[i][j] & 0x30) && (mat[i - 1][j] & 0x14)) {
                mat[i][j] |= 0x04;
            }
        }
        fp(i, h) {
            if (!(mat[h - i - 1][j] & 0x30) && (mat[h - i][j] & 0x18)) {
                mat[h - i - 1][j] |= 0x08;
            }
        }
    }
    fa(row, mat) {
        dbg(row);
    }

    i64 res = 0;
    fi(i, h) {
        fi (j, w) {
            if (mat[i][j] & 0x1F) {
                res++;
            }
        }
    }
    wl(res);

    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <math.h>
#include <limits.h>
#include <string>
#include <bitset>

using namespace std;

#define pb push_back
#define mp make_pair
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define manytests int TT;cin >> TT; while (TT--)

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define FORd(i,a,b) for (int i = (a); i >= (b); --i)

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

#define ll long long
#define ld long double
#define fi first
#define se second
#define rev reverse

#define vi vector<int>
#define vl vector<ll>
#define vc vector<char>
#define vd vector<double>
#define vs vector<string>
#define vld vector<ld>
#define vb vector<bool>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpi vector<pii>

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

    int x, y;
    cin >> x >> y;
    if (x > y) swap(x, y);
    if (x+3>y) cout << "Yes\n";
    else cout << "No\n";

    return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;

#define MULTI 1

void pre()
{
}

#define SQR(x) ((x)*(x))
void solve()
{
	ll l, r; cin >> l >> r;
	if (r >= 2 * l) {
		ll x = r - 2 * l + 1;
		ll ans;
		if (x % 2 == 1) ans = SQR((x + 1) / 2);
		else ans = x / 2 * (x / 2 + 1);
		cout << 2 * ans - (r / 2 - l + 1) << endl;
	} else cout << 0 << endl;
}

int main()
{
	pre();
#ifdef MULTI
	int T;
	cin >> T;
	for (int t = 0; t < T; ++t) {
#endif
		solve();
#ifdef MULTI
	}
#endif
	return 0;
}


#include <string>
#include <iostream>
using namespace std;
using ll=long long;
using ull=unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

const int W=30, H=30;
const int query_num = 1000;

int main(){
  for(int i=0; i<query_num; i++){
    int sy,sx,ty,tx; cin >> sy >> sx >> ty >> tx;
    string ans = "";
    while(sx != tx){
      if(sx < tx){ ans += "R"; sx++; }
      else{ ans += "L"; sx--; }
    }
    while(sy != ty){
      if(sy < ty){ ans += "D"; sy++; }
      else{ ans += "U"; sy--; }
    }
    cout << ans << "\n" << flush;
    int result; cin >> result;
  }
  return 0;
}

struct ios_do_not_sync{
  ios_do_not_sync(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
  }
} ios_do_not_sync_instance;


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

int main() {
  long long a,b,c,d;
  cin >> a >> b >> c >> d;
  long long n = 0;
  long long mizu = a;
  long long aka = 0;
  if (b >= c*d){
    cout << -1 << endl;
  }

  else {
    while (mizu > aka * d) {
    mizu += b;
    aka += c;
    n++;
    }
    cout << n << endl;
  }
}

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

int main(){

  int n,k,m,ans;
  cin >> n >> k >> m;
  int a[n],sum=0;
  rep(i,n-1){
    cin >> a[i];
    sum += a[i];
  }
  ans = n*m - sum;
  if(ans>k) cout << "-1" << endl;
  else if(ans<0) cout << "0" << endl;
  else cout << ans << endl;

  return 0;
}


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

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

	vector<ullong> A(N);
	for (auto &x: A) cin >> x;
	sort(A.begin(), A.end());

	for (int q = 0; q < Q; ++q) {
		ullong K;
		cin >> K;
		ullong target = K;

		size_t d1 = 0;
		while (true) {
			auto pos = lower_bound(A.begin(), A.end(), target);
			size_t d2 = distance(A.begin(), pos);
			ullong num = 0;

			if (d1 == d2) {
				if (*pos == target) {
					num = d2 + 1;
				}
				else {
					cout << target << endl;
					break;
				}
			}
			else {
				if (*pos == target)
					num = d2 + 1;
				else
					num = d2;
			}
			d1 = d2;
			target = K + num;
		}
	}

}

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
long long int missingK(long long int arr[],int n, long long int k)
{
  long long int l = 0, u = n - 1, mid;
  while(l <= u)
  {
    mid = (l + u)/2;
    long long int numbers_less_than_mid = arr[mid] - (mid + 1);
    if(numbers_less_than_mid == k)
    {
      if(mid > 0 && (arr[mid - 1] - (mid)) == k)
      {
        u = mid - 1;
        continue;
      }
      return arr[mid]-1;
    }
    if(numbers_less_than_mid < k)
    {
      l = mid + 1;
    }
    else if(k < numbers_less_than_mid)
    {
      u = mid - 1;
    }
  }

  if(u < 0)
    return k;

  long long int less = arr[u] - (u + 1);
  k -= less;

  return arr[u] + k;
}
int main(){
  int n,q;
  cin>>n>>q;
  long long int a[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
  long long int k;
  while(q--){
      cin>>k;
      cout<<missingK(a,n,k)<<endl;
  }
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define PI acos(-1)
#define ld long double
template<class T> bool chmin(T& a, const T& b) {return a>b? a=b, true:false;}
template<class T> bool chmax(T& a, const T& b) {return a<b? a=b, true:false;}
const int mod = 1e9+7, N = 2e5+5;
inline int msb(int val){return sizeof(int)*8-__builtin_clzll(val)-1;}
int a[N], n, m, k;
int b[N];
void solve(int test_case){
	int i, j;
	cin >> n;
	for(i=0;i<n;i++)
		cin >> a[i] >> b[i];

	int ans = mod;
	for(i=0;i<n;i++){
		chmin(ans, a[i] + b[i]);
	}
	for(i=0;i<n;i++){
		int al = a[i];
		int mn = mod;
		for(j=0;j<n;j++){
			if(i == j)continue;
			chmin(mn, b[j]);
		}
		chmin(ans, max(al,mn));
	}
	cout << ans << '\n';
	return;
}

signed main(){
	FASTIO;
//~ #define MULTITEST 1
#if MULTITEST
	int _T;
	cin >> _T;
	for(int T_CASE = 1; T_CASE <= _T; T_CASE++)
		solve(T_CASE);
#else
	solve(1);
#endif
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
using I=int;
const int M = 1<<18;

I n,s,t,F[M],p[M],E[M],d[M],D;
vector<I>G[M];
void dfs(I x,I f,I&s) {
	F[x]=f;d[x]=d[f]+1;if(d[x]>d[s])s=x;
	for (I&y:G[x])if(y^f)dfs(y,x,s);
}

void dfs2(I u,I f) {
	E[u]=++D;
	for(I&v:G[u])if(v!=f&&!p[v])dfs2(v,u);
	for(I&v:G[u])if(v!=f&&p[v])dfs2(v,u);
	++D;
}

I main() {
	cin>>n;
	for(I u,v,i=1;i<n;++i) {
		cin>>u>>v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dfs(1,0,s),dfs(s,0,t);
	for(I u=t;u;u=F[u])p[u]=1;
	dfs2(s,0);
	for(I i=1;i<=n;++i)cout<<E[i]<<" \n"[i==n];
}


#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  int64_t K;
  cin >> K;
  vector<vector<int64_t>> dp(4, vector<int64_t>(4 * N + 10, 0));
  dp[0][0] = 1;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3 * N + 1; j++) {
      dp[i + 1][j + 1] += dp[i][j];
      dp[i + 1][j + N + 1] -= dp[i][j];
    }
    for (int j = 0; j < 3 * N + 1; j++) {
      dp[i + 1][j + 1] += dp[i + 1][j];
    }
  }
  int x = 0;
  for (int i = 0; i < 3 * N + 1; i++) {
    if (K <= dp[3][i]) {
      x = i;
      break;
    }
    K -= dp[3][i];
  }
  for (int i = 1; i < N + 1; i++) {
    int mi = max(1, x - i - N);
    int ma = min(N, x - i - 1);
    if (mi > ma) continue;
    if (K > ma - mi + 1) {
      K -= ma - mi + 1;
      continue;
    }
    int j = mi + K - 1;
    int k = x - i - j;
    cout << i << ' ' << j << ' ' << k << '\n';
    return 0;
  }
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7,INF=1e18;
#define ll long long
#define line cout<<"\n";
#define flush cout<<endl;
#define pll pair<ll,ll>
#define x first
#define y second
#define p_all(arr) for(auto i:arr){cout<<i<<" ";}cout<<"\n";
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    ll t=1;
    // cin>>t;
    for(ll test=1;test<=t;test++)
    {
        string s;
        ll k;
        cin>>s>>k;
        ll n=s.size();
        vector<ll> num(n);
        for(int i=0;i<n;i++)
        {
            if(s[i]<='9')
            {
                num[i]=s[i]-'0';
            }
            else
            {
                num[i]=10+s[i]-'A';
            }
        }
        ll dp[n+1][17][2];
        memset(dp,0,sizeof(dp));
        dp[0][1][1]=num[0]-1;
        for(int i=0;i<n;i++)
        dp[i][0][1]=1;
        set<ll> set1;
        set1.insert(num[0]);
        dp[0][1][0]=1;
        for(int i=1;i<n;i++)
        {
            ll c1=0,c2=num[i];
            for(auto v:set1)
            {
                if(v<num[i])
                c1++;
            }
            c2-=c1;
            set1.insert(num[i]);
            dp[i][set1.size()][0]=1;
            for(ll l=0;l<=16;l++)
            {
                dp[i][l][1]=(dp[i][l][1]+l*dp[i-1][l][1])%mod;
                if(l<16)
                {
                    if(l==0)
                    dp[i][l+1][1]=(dp[i][l+1][1]+(15LL-l)*dp[i-1][l][1])%mod;
                    else
                    dp[i][l+1][1]=(dp[i][l+1][1]+(16LL-l)*dp[i-1][l][1])%mod;
                }
                dp[i][l][1]=(dp[i][l][1]+c1*dp[i-1][l][0])%mod;
                if(l<16)
                dp[i][l+1][1]=(dp[i][l+1][1]+c2*dp[i-1][l][0])%mod;
            }
        }
        cout<<(dp[n-1][k][0]+dp[n-1][k][1])%mod<<"\n";
    }
    return 0;
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)
#define REPO(i, n) for (ll i = 1; i <= n; i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(), n.end()
#define MOD 1000000007
#define P pair<ll, ll>

int main(){
    ll t;
    cin >> t;
    REP(i, t){
        ll n;
        string a;
        cin >> n >> a >> a >> a;
        cout << 0;
        REP(i, n)cout << 1;
        REP(i, n)cout << 0;
        cout << endl;
    }
}

/*  -*- coding: utf-8 -*-
 *
 * a.cc: A - Long Common Subsequence
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

/* global variables */

char s[MAX_N * 2 + 4];

/* subroutines */

/* main */

int main() {
  int tn;
  scanf("%d", &tn);

  while (tn--) {
    int n;
    scanf("%d", &n);

    for (int i = 0; i < 3; i++) scanf("%s", s);

    for (int i = 0; i < n; i++) putchar('0');
    for (int i = 0; i < n; i++) putchar('1');
    putchar('0'); putchar('\n');
  }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FASTIO {ios_base::sync_with_stdio(false);cin.tie(NULL);}

//************ functions

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

ll pow(ll a,ll m){

    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
        return 0;

    while (a > 1) {
        // q is quotient
        ll q = a / m;
        ll t = m;

        // m is remainder now, process same as
        // Euclid's algo
        m = a % m, a = t;
        t = y;

        // Update y and x
        y = x - q * y;
        x = t;
    }

    // Make x positive
    if (x < 0)
        x += m0;

    return x;
}

int main(){
	FASTIO;
	//sieve();
	int t;
	cin>>t;
	while(t--){
		ll n,s,k;
		cin>>n>>s>>k;
		ll a,b,c;
		ll d=gcd(k,gcd(n-s,n));
		a=k/d;
		b=(n-s)/d;
		c=n/d;
		//cout<<a<<' '<<b<<' '<<c<<' '<<d<<endl;
		if(gcd(a,c)!=1) cout<<-1;
		else{
			cout<<pow(a,c)*b%c;
		}
		cout<<endl;
	}
}

#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<set>
#include<cstdlib>
#include<cmath>
#include<numeric>//fill
#include<iomanip>
#include<functional>//https://cpprefjp.github.io/reference/functional/function.html
#include<cstdlib>//https://cpprefjp.github.io/reference/cstdlib.html
#include<queue>
#include<deque>
#include<cassert>
#include<stack>
#include <iterator>     // std::back_inserter
//#include<atcoder/all>
using namespace std;
//using namespace atcoder;
const double PI = acos(-1);
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n)for(ll i=0;i<(n);i++)
#define repp(x,arr) for(auto& x:arr)
#define repp2(x,y,arr) for(auto& [x,y]:arr)
#define all(a) (a.begin()),(a.end())
const ll MOD = 1e9 + 7;
const ll inf = (ll)1e18+6;

// デフォルトは整数部も含めた桁数指定
//cout <<setprecision();
ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}
double dl[4] = { 0,0,0.1,0.1 };
double dr[4] = { 0,-0.1,0,-0.1 };
int main() {
	ios::sync_with_stdio(false);
	//ll a, b, c, d;
	//cin >> a >> b >> c >> d;
	//if (a == 0) {
	//	cout << 0;
	//	return 0;
	//}
	//if (c <= b) {
	//	cout << -1;
	//	return 0;
	//}

	//ll aka = 0;
	//ll mizu = a;
	//ll ans = 0;
	//while (mizu > aka * d) {
	//	ans++;
	//	aka += c;
	//	mizu += b;
	//}
	//cout << ans;
	ll N;
	cin >> N;
	vector<double>l(N), r(N);
	rep(i, N) {
		int t;
		cin >>t>> l[i] >> r[i];
		t--;
		l[i] += dl[t];
		r[i] += dr[t];
	}
	ll ans = 0;
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			if(r[j]<l[i]||r[i]<l[j])continue;
				ans++;
		}
	}
	cout << ans;

}


#include <cstdio>
const int Maxn=400000;
int fac[Maxn+5],num[Maxn+5],inv_f[Maxn+5],inv_n[Maxn+5];
void init(){
	fac[0]=1;
	for(int i=1;i<=Maxn;i++){
		fac[i]=fac[i-1],num[i]=num[i-1];
		int x=i;
		while(x%3==0){
			x/=3;
			num[i]++;
		}
		fac[i]=1ll*fac[i-1]*x%3;
	}
	inv_f[Maxn]=fac[Maxn],inv_n[Maxn]=num[Maxn];
	for(int i=Maxn-1;i>=0;i--){
		int x=i+1;
		inv_f[i]=inv_f[i+1],inv_n[i]=inv_n[i+1];
		while(x%3==0){
			x/=3;
			inv_n[i]--;
		}
		inv_f[i]=1ll*inv_f[i+1]*x%3;
	}
}
int C(int n,int m){
	if(num[n]-inv_n[m]-inv_n[n-m]!=0){
		return 0;
	}
	return fac[n]*inv_f[m]*inv_f[n-m]%3;
}
char s[Maxn+5];
int main(){
	init();
	int n;
	scanf("%d",&n);
	scanf("%s",s+1);
	int ans=0;
	for(int i=1;i<=n;i++){
		int val=(s[i]=='B'?0:(s[i]=='W'?1:2));
		ans=(ans+1ll*C(n-1,i-1)*val)%3;
	}
	if(ans==0){
		putchar('B');
	}
	else if((ans&1)^(n&1)){
		putchar('R');
	}
	else{
		putchar('W');
	}
	return 0;
}

using namespace std;
#include <bits/stdc++.h>
#define N 400005
#define ll long long
int n;
char str[N];
int c[3][3];
int C(int m,int n){
//	if (m<n) return 0;
//	return fac[m]*ifac[n]%mo*ifac[m-n]%mo;
	if (m<3 && n<3)
		return c[m][n];
	return C(m/3,n/3)*C(m%3,n%3);
}
int id[255];
int re[3]={'B','W','R'};
int main(){
//	freopen("in.txt","r",stdin);
	scanf("%d%s",&n,str);
	for (int i=0;i<3;++i){
		c[i][0]=1;
		for (int j=1;j<3;++j)
			c[i][j]=(c[i-1][j-1]+c[i-1][j])%3;
	}
	int ans=0;
	id['B']=0,id['W']=1,id['R']=2;
	for (int i=0;i<n;++i)
		ans+=id[str[i]]*C(n-1,i);
	if (n-1&1) ans*=-1;
	ans=(ans%3+3)%3;
	printf("%c\n",re[ans]);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
set<string> Set;
LL getMin(string s){
    sort(s.begin(), s.end());
    LL ans = 0;
    for(int i = 0;i<s.size();++i)
    {
        ans = ans *10+s[i]-'0';

    }
    return ans;
}
LL getMax(string s){
    sort(s.begin(), s.end(), greater<LL>());
    LL ans = 0;
    for(int i = 0;i<s.size();++i)
    {
        ans = ans *10+s[i]-'0';

    }
    return ans;
}
string getString(LL d){
    string s="";
    if(d==0)
    {
        return "0";
    }
    while(d){
        s += d%10+'0';
        d/=10;
    }
    reverse(s.begin(),s.end());
    return s;
}
int main() {
    string s;
    LL d;
    cin >> d;
    s = getString(d);
    int n;
    cin >> n;

    LL b=d, a=0;
    while(n--){
         a = getMin(s);
         b = getMax(s);
        s = getString(b-a);
        //cout << a << " " << b << " " << s  << "\n";

    }
    cout <<s << "\n";
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif

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

	auto f = [](int64_t x) -> int64_t {
		string s(to_string(x)), t(s);

		sort(s.begin(), s.end(), greater<>());
		sort(t.begin(), t.end());

		return stoll(s) - stoll(t);
	};

	int64_t a = n;

	for (int64_t i = 0; i < k; i++)
	{
		a = f(a);
	}

	cout << a << endl;

	return 0;
}


// {{{ by unolight
#include <bits/stdc++.h>
#include <unistd.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-function"
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x),end(x)
#define RALL(x) rbegin(x),rend(x)
#define REP(i,n) for ( int i=0; i<int(n); i++ )
#define REP1(i,a,b) for ( int i=(a); i<=int(b); i++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef pair<int,int> PII;
typedef vector<int> VI;

namespace { namespace unolight {
// Read Input
template<class T> void _R( T &x ) { cin>>x; }
void _R( int &x ) { scanf("%d",&x); }
void _R( int64_t &x ) { scanf("%" PRId64,&x); }
void _R( double &x ) { scanf("%lf",&x); }
void _R( char &x ) { scanf(" %c",&x); }
void _R( char *x ) { scanf("%s",x); }
void R() {}
template<class T, class... U> void R( T& head, U&... tail ) { _R(head); R(tail...); }
// Write Output
template<class T> void _W( const T &x ) { cout<<x; }
void _W( const int &x ) { printf("%d",x); }
void _W( const int64_t &x ) { printf("%" PRId64,x); }
void _W( const double &x ) { printf("%.16f\n",x); }
void _W( const char &x ) { putchar(x); }
void _W( const char *x ) { printf("%s",x); }
template<class T> void _W( const vector<T> &x ) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W( const T& head, const U&... tail ) { _W(head); putchar(sizeof...(tail)?' ':'\n'); W(tail...); }

#ifdef UNOLIGHT
#include "dump.hpp"
#else
#define dump(...)
#endif

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}
// }}}

void main() {
    int n;
    R(n);
    VI a(n),b(n);
    REP(i,n) R(a[i]);
    REP(i,n) R(b[i]);
    int l=0,r=1000;
    REP(i,n) {
        chmax(l,a[i]);
        chmin(r,b[i]);
    }
    int ans=max(0,r-l+1);
    W(ans);
}

 // {{{ main
}}
int main() { unolight::main(); return 0; }
// }}}

#include "bits/stdc++.h"

#define int long long

using namespace std;
using i128 = __int128_t;

random_device rd;
mt19937 gen(rd());

#define random_shuffle(begin, end) shuffle(begin, end, gen)

template <typename T, typename U>
ostream& operator << (ostream& out, const pair <T, U> &p) {
    out << p.first << ": " << p.second;
    return out;
}

template <typename Container>
ostream& print_container(ostream& out, const Container &container, const string &open, const string &close, const string sep=", ") {
    out << open;
    for (const auto &elem : container)
        out << elem << sep;
    out << "\b\b" << close << endl;
    return out;
}

template <typename T>
ostream& operator << (ostream& out, const vector<T> &v) {
    return print_container(out, v, "[", "]");
}

template <typename T>
ostream& operator << (ostream& out, const set<T> &s) {
    return print_container(out, s, "{", "}");
}

template <typename T>
ostream& operator << (ostream& out, const unordered_set<T> &s) {
    return print_container(out, s, "{", "}");
}

template <typename K, typename V>
ostream& operator << (ostream& out, const map<K, V> &s) {
    return print_container(out, s, "{", "}");
}

template <typename K, typename V>
ostream& operator << (ostream& out, const unordered_map<K, V> &s) {
    return print_container(out, s, "{", "}");
}

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

namespace std {
    template <typename T, typename U> struct hash<pair <T, U> > {
        size_t operator()(const pair <T, U> &p) const {
            hash<int> hasher;
            size_t seed = 0;
            seed ^= hasher(p.first) + 0x9e3779b9 + (seed<<6) + (seed>>2);
            seed ^= hasher(p.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
            return seed;
        }
    };
}

// End of template

int32_t main() {
    ios_base::sync_with_stdio(false);

#ifdef LOCAL_JUDGE
    if (freopen("input.txt", "r", stdin) == NULL) {
        cerr << "Couldn't open file for reading" << endl;
        return 0;
    }
#endif
	int n;
    cin >> n;
    vector <int> a(n), b(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    for (int i = 0; i < n; ++i)
        cin >> b[i];
    int ma = a[0], mi = b[0];
    for (int i = 0; i < n; ++i) {
        ma = max(ma, a[i]);
        mi = min(mi, b[i]);
    }
    cout << max(0LL, mi - ma + 1) << endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
//#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//g++ a.cpp
//./a.out
//oj d https://atcoder.jp/contests/abc205/tasks/abc205_a
//oj t

int main(){
    double a, b;
    cin >> a >> b;
    double c;
    c = a / 100;
    double d;
    d = c * b;
    cout << d << endl;
}

#include <bits/stdc++.h>

using namespace std;

int main(){
    double a,b;cin>>a>>b;
    cout<<(a/100)*b;
    return 0;
}


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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int v, t, s, d;
	cin >> v >> t >> s >> d;
	if (v * t <= d && d <= v * s) {
		cout << "No\n";
	} else {
		cout << "Yes\n";
	}
	return 0;
}

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

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(c%2==0){
        a = abs(a);
        b = abs(b);
        if(a>b){
            cout<<">";
            return 0;
        }else if(a==b){
            cout<<"=";
            return 0;
        }else{
            cout<<"<";
            return 0;
        }
    }
    // if i'm here c is odd so now if a>b

    if(a>b){
        cout<<">";
        return 0;
    }else if(a==b){
        cout<<"=";
        return 0;
    }else{
        cout<<"<";
        return 0;
    }
}


#include <bits/stdc++.h>
// #include <atcoder/all>
// using namespace atcoder;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for(int i=int(n-1);i>=int(0);--i)
#define fore(i,a) for(auto &i:a)
#define all(x) x.begin(),x.end()
#define sz(x) ((int)(x).size())
#define bp(x) (__builtin_popcount((long long)(x)))
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define V vector
#define P pair<int,int>
#define TP tuple<int,int,int>
#define F first
#define S second
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; }
using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1001001001;
const ll INFL = 1001001001001001001;
const int MAX = 2e6+1;

template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
const int MOD = 1000000007;
//const int MOD = 998244353;
using mint = Fp<MOD>;

int main() {
    int n;cin>>n;
    V<ll> a(n);
    rep(i,n)cin>>a[i];
    a.push_back(0);
    sort(all(a));
    mint ans=1;
    rep(i,1,n+1){
        ans*=a[i]-a[i-1]+1;
    }
    cout<<ans<<endl;
    return 0;
}

#include <bits/stdc++.h>

// #include <atcoder/all>
#define rep(i, s, t) for (int i = s; i < t; ++i)
using namespace std;
// using namespace atcoder;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = (int)2e9;
constexpr ll INFll = (ll)1e18;
constexpr int MOD = 1e9 + 7;

struct edge {
  int to, cost;
  edge(int t, int c) : to(t), cost(c) {}
};

vector<vector<edge>> G;
int R, C;

int dijkstra(int s, int t) {
  priority_queue<P, vector<P>, greater<P>> que;
  vector<int> d(2 * R * C, INF);

  que.emplace(s, 0);
  d[s] = 0;

  while (!que.empty()) {
    auto p = que.top();
    que.pop();
    int curd = p.first, curv = p.second;
    if (curd > d[curv]) continue;
    for (auto e : G[curv]) {
      if (curd + e.cost < d[e.to]) {
        d[e.to] = curd + e.cost;
        que.emplace(d[e.to], e.to);
      }
    }
  }
  return d[t];
}

int main() {
  cin >> R >> C;
  G.resize(2 * R * C);
  rep(r, 0, R) rep(c, 0, C - 1) {
    int a;
    cin >> a;
    G[r * C + c].emplace_back(r * C + c + 1, a);
    G[r * C + c + 1].emplace_back(r * C + c, a);
  }
  rep(r, 0, R - 1) rep(c, 0, C) {
    int b;
    cin >> b;
    G[r * C + c].emplace_back((r + 1) * C + c, b);
  }
  rep(r, 0, R) rep(c, 0, C) {
    G[r * C + c].emplace_back(r * C + c + R * C, 1);
    G[r * C + c + R * C].emplace_back(r * C + c, 0);
  }
  rep(r, 0, R - 1) rep(c, 0, C) {
    G[(r + 1) * C + c + R * C].emplace_back(r * C + c + R * C, 1);
  }

  cout << dijkstra(0, R * C - 1) << endl;
}