#include <iostream>
using namespace std;
int main() {
  int sx, sy, gx, gy;
  cin >> sx >> sy >> gx >> gy;
  if (sy < 0) {
    if (gy < 0) {
      gy = -gy;
    }
  } else {
    if (gy > 0) {
      gy = -gy;
    }
  }
  double a = (double)(gy - sy) / (gx - sx);
  double b = sy - a * sx;
  double x = (0.0 - b) / a;
  printf("%.7f\n", x);
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define DEBUG
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    for(int i = 0; i < (int)v.size(); i++) {
        if(i) { os << ','; }
        os << v[i];
    }
    os << '}';
    return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
    cerr << " " << x;
    debugg(args...);
}
#define debug(...)                                                             \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,-1,0,1,1,-1,-1,1};
ll dx[8] = {-1,0,1,0,1,-1,1,-1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    int sz = a.size();
    for(auto itr = a.begin(); itr != a.end(); itr++){
		cout << *itr;
        sz--;
        if(sz) cout << " ";
	}
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){
	cout << a << " " << b << "\n";
}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
void mark() {cout << "#" << "\n";}
ll pcount(ll x) {return __builtin_popcountll(x);}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	int sx,sy,gx,gy; cin >> sx >> sy >> gx >> gy;
	double t = abs(sy) / (double)abs(sy+gy);
	double ans = t * (gx-sx) + sx;
	printf("%.12f\n",ans);
}


#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
#define rprintf(fmt, begin, end) do { const auto end_rp = (end); auto it_rp = (begin); for (bool sp_rp=0; it_rp!=end_rp; ++it_rp) { if (sp_rp) putchar(' '); else sp_rp = true; printf(fmt, *it_rp); } putchar('\n'); } while(0)
template<class T> struct Fenwick {
    int n;
    T* d;
    Fenwick() : n(0), d(NULL) {}
    Fenwick(int n_) : n(n_) {
	d = new T[n_]();
    }
    Fenwick(const Fenwick &y) : n(y.n) {
	d = new T[n];
	memcpy(d, y.d, sizeof (T) * n);
    }
    ~Fenwick() {
	delete[] d; d = NULL;
	n = 0;
    }
    friend void swap(Fenwick &x, Fenwick &y) {
	swap(x.n, y.n); swap(x.d, y.d);
    }
    Fenwick& operator=(Fenwick y) {
	swap(*this, y);
	return *this;
    }
    inline void add(int i, const T &x) {
	for (; i<n; i|=i+1) d[i] += x;
    }
    inline T sum(int r) const {
	T s = T();
	for (; r; r&=r-1) s += d[r-1];
	return s;
    }
    T sum(int l, int r) const {
	return sum(r) - sum(l);
    }
    int lower_bound(const T &x) const { // sum(ret) < x <= sum(ret+1);
	if (n == 0) return 0;
	int i = 0; T s = T();
	for (int k=1<<__lg(n); k; k>>=1) {
	    if (i+k <= n && s + d[i+k-1] < x) {
		i += k; s += d[i-1];
	    }
	}
	return i;
    }
    int upper_bound(const T &x) const { // sum(ret) <= x < sum(ret+1);
	if (n == 0) return 0;
	int i = 0; T s = T();
	for (int k=1<<__lg(n); k; k>>=1) {
	    if (i+k <= n && !(x < s + d[i+k-1])) {
		i += k; s += d[i-1];
	    }
	}
	return i;
    }
};

int H, W, M;
int R[200011], C[200011];
int idx[200011];
bool use[200011];
bool act[200011];

void MAIN() {
    scanf("%d%d%d", &H, &W, &M);
    REP (i, M) scanf("%d%d", R+i, C+i), R[i]--, C[i]--;

    LL ans = 0;
    if (M == 0) {
	ans = (LL) H * W;
    } else {
	int minR = H;
	int minC = W;
	REP (i, M) {
	    if (R[i] == 0) amin(minC, C[i]);
	    if (C[i] == 0) amin(minR, R[i]);
	}

	ans += (LL)H * W;
	ans -= W - minC;
	ans -= H - minR;

	REP (i, M) idx[i] = i;
	sort(idx, idx + M, [&](int i, int j) {
		return C[i] < C[j];
		});

	for (int i=minR; i<H; i++) use[i] = true;

	REP (i, M) {
	    if (!use[R[idx[i]]]) {
		use[R[idx[i]]] = true;
		act[idx[i]] = true;
	    }
	}

	Fenwick<LL> F(H+11);

	LL bad = 0;
	int p = M-1;
	for (int i=W-1; i>0; i--) {
	    int nxt = H;

	    int q = p;
	    while (q >= 0 && C[idx[q]] == i) {
		q--;
	    }

	    for (int k=p; k>q; k--) {
		int r = R[idx[k]];
		int c = C[idx[k]];
		amin(nxt, r);
	    }

	    if (minC <= i) nxt= 0;
	    F.add(nxt, 1);

	    for (int k=p; k>q; k--) {
		int r = R[idx[k]];
		int c = C[idx[k]];

		// [c, Right[r]);
		if (r != 0 && act[idx[k]]) {
		    bad += F.sum(0, r+1);
		}
	    }

	    p = q;
	}

	for (int i=minR; i<H; i++) {
	    bad += F.sum(0, i+1);
	}

	ans -= bad;
    }
    printf("%lld\n", ans);

}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}

#include <vector>

template <typename T, typename F>
class segment_tree {
public:
	segment_tree(int n, const F& f, const T& e)
		: f(f), e(e)
	{
		sz = 1;
		while (sz < n) {
			sz *= 2;
		}
		dat.assign(2 * sz, e);
	}

	void update(int i, const T& x) {
		i += sz;
		dat[i] = x;
		while (i > 1) {
			i /= 2;
			dat[i] = f(dat[2 * i + 0], dat[2 * i + 1]);
		}
	}

	T query(int i) const {
		return dat[i + sz - 1];
	}

	T query(int a, int b) const {
		T l = e;
		T r = e;
		a += sz;
		b += sz;
		for (; a < b; a /= 2, b /= 2) {
			if (a & 1) {
				l = f(l, dat[a]);
				++a;
			}
			if (b & 1) {
				--b;
				r = f(dat[b], r);
			}
		}
		return f(l, r);
	}

private:
	F f;
	T e;
	int sz;
	std::vector<T> dat;
};

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

using namespace std;

int main()
{
	int H, W, M;
	cin >> H >> W >> M;
	vector<int> X(M), Y(M);
	for (int k = 0; k < M; ++k) {
		cin >> X[k] >> Y[k];
		--X[k];
		--Y[k];
	}

	vector<vector<int>> o_cols(H);
	vector<vector<int>> o_rows(W);

	for (int k = 0; k < M; ++k) {
		o_cols[X[k]].push_back(Y[k]);
		o_rows[Y[k]].push_back(X[k]);
	}

	for (int i = 0; i < H; ++i) {
		sort(o_cols[i].begin(), o_cols[i].end());
	}
	for (int j = 0; j < W; ++j) {
		sort(o_rows[j].begin(), o_rows[j].end());
	}

	if (!o_cols[0].empty()) {
		int leftmost = o_cols[0][0];
		for (int col = leftmost + 1; col < W; ++col) {
			o_cols[0].push_back(col);
		}
		sort(o_cols[0].begin(), o_cols[0].end());
		o_cols[0].erase(unique(o_cols[0].begin(), o_cols[0].end()), o_cols[0].end());
	}

	long long ans = 0;

	int j_max = o_cols[0].empty() ? W : o_cols[0][0];
	for (int j = 0; j < j_max; ++j) {
		int upmost = o_rows[j].empty() ? H : o_rows[j][0];
		ans += upmost;
	}

	// range sum query
	auto f = [](int a, int b) { return a + b; };
	auto e = 0;
	segment_tree<int, decltype(f)> seg(W, f, e);

	int i_max = o_rows[0].empty() ? H : o_rows[0][0];
	for (int i = 1; i < i_max; ++i) {
		for (auto& col : o_cols[i - 1]) {
			seg.update(col, 1);
		}
		int leftmost = o_cols[i].empty() ? W : o_cols[i][0];
		ans += seg.query(0, leftmost);
	}

	cout << ans << endl;
}


#include <bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fod(i,a,b) for(int i=a;i>=b;i--)
#define me0(a) memset(a,0,sizeof(a))
#define me1(a) memset(a,-1,sizeof(a))
#define op freopen("in.txt", "r", stdin)
#define op1 freopen("C:\\acm\\Cproj\\in.txt","r",stdin);
#define pr freopen("C:\\acm\\Cproj\\out.txt","w",stdout)
#define pr2 freopen("C:\\acm\\Cproj\\std.txt","w",stdout)
#define pii pair<int,int>
#define Please return
#define AC 0
using namespace std;
const int INF = 0x3f3f3f3f;
typedef long long LL;
template <class T>
void read(T &val) { T x = 0; T bz = 1; char c; for (c = getchar(); (c<'0' || c>'9') && c != '-'; c = getchar()); if (c == '-') { bz = -1; c = getchar(); }for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48; val = x * bz; }
const int mod=998244353;
const int maxn = 1e6+10;

int n,m,a[maxn],q,t;
char s[maxn];

int flag;
void dfs(int step,LL nw){
    if(step>4){
        if(nw==0) flag = 1;
        return;
    }
    if(a[step]<=nw) dfs(step+1,nw-a[step]);
    dfs(step+1,nw);
}

int main(){
    LL sum = 0;
    fo(i,1,4) read(a[i]),sum+=a[i];
    if(sum&1){
        puts("No");return 0;
    }
    dfs(1,sum/2);
    if(flag) puts("Yes");
    else puts("No");
    Please AC;
}

#include<bits/stdc++.h>
#define ll long long
ll a,b,c,d,s;
int main(){
    scanf("%lld%lld%lld%lld",&a,&b,&c,&d);s=a+b+c+d;
    if(a==s-a||b==s-b||c==s-c||d==s-d)puts("Yes");
    else if(a+b==s-a-b||a+c==s-a-c||a+d==s-a-d||b+c==s-b-c||b+d==s-b-d||c+d==s-c-d)puts("Yes");
    else puts("No");
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

void solve(){
	int n;
		cin >> n;
		int a[n];
		for(int i = 0; i < n; ++i)
			cin >> a[i];
		sort(a, a + n);
		if(n & 1){
			cout << "Second\n";
		}else{
			// 1 2 4 5
			// 100
			// 101
			// 010
			// 001
			for(int i = 0; i < n; i += 2){
				if(a[i] != a[i + 1]){
					cout << "First\n";
					return;
				}
			}
			cout << "Second\n";
		}
}
int main()
{
	int T;
	cin >> T;
	while(T--){
		solve();
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
long long INF = 1LL<<60;
using ll = long long;
using vll = vector<ll>;
using mll = map<ll, ll>;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

const string YES = "Yes";
const string NO = "No";

void solve(long long S, long long P){
    for(ll x = 1; x * x <= P; x++){
        if(P % x != 0) continue;
        if(P/x + x == S){
            cout << YES << endl; return;
        }
    }
    cout << NO << endl;
}

int main(){
    long long S;
    scanf("%lld",&S);
    long long P;
    scanf("%lld",&P);
    solve(S, P);
    return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int res, matrix[4];
    for (auto i = 0; i < 4; i++)
    {
        cin >> matrix[i];
    }
    res = matrix[0] * matrix[3] - matrix[1] * matrix[2];
    cout << res;
    return 0;
}

#include<bits/stdc++.h>
#define fo(i,a,b) for((i)=(a);i<=(b);i++)
#define rfo(i,a,b) for((i)=(a);i>=(b);i--)
#define inrange(x,y,z) (((x)>=(y))&&((x)<=(z)))
#define ALL(vec) (vec).begin(),(vec).end()
#define SOR(vec) sort(ALL(vec))
#define UNI(vec) (vec).erase(unique(ALL(vec)),(vec).end())
using namespace std;
int a,b,c,d;
int main(){
	#ifdef FILIN
		#ifndef DavidDesktop
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>a>>b>>c>>d;
	cout<<a*d-b*c<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define boost ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//#define mp make_pair
#define pb push_back
#define fp first
#define sp second
typedef long long int ll;
typedef pair<ll,ll> pp;
#define check(x, i) ((x>>i)&1LL)
#define set(x,i) (x|(1LL<<i))
#define unset(x,i) (x&~(1LL<<i))
#define INF LONG_MAX
#define MAX_N 20
#define MAX 200005
#define mod 1000000007
#define REP(i,n) for(i=0;i<n;i++)
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define RFOR(i,a,b) for(i=a;i>=b;i--)
#define len(i,s) for(i=0;s[i];i++)
#define T() ll t;cin>>t;while(t--)
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2")
ll gcd (ll a, ll b){return (a?gcd(b%a,a):b);}
ll pow1(ll a,ll b,ll MOD){ll ans=1;while(b!=0){if(b&1)ans=(ans*a)%MOD;a=(a*a)%MOD;b=b/2;}return ans;}
ll modInverse(ll a,ll p){return pow1(a,p-2,p);}
void ash(){
	boost
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

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

int main()
{
	ash();
	ll n;
	cin>>n;
	cout<<n-1<<"\n";

}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 2e5 + 5;

struct Person {
    int val, id, ok, nxt;
}a[maxn], q[maxn];

struct D {
    int a, b;
};

int n, fflag, ansflag = 1;
int b[maxn], p[maxn];
vector<D> ans;

int cmp(const Person &a, const Person &b) {
    return a.val > b.val;
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i].val);
        a[i].id = i;
    }
    for (int i = 1; i <= n; i++) scanf("%d", b + i);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i].nxt);
        if (a[i].val <= b[a[i].nxt] && a[i].nxt != i)
            fflag = 1;
        if (a[i].nxt != i)
            ansflag = 0;
        else
            a[i].ok = 1;
    }

    if (ansflag) {
        printf("0\n");
        return 0;
    }

    if (fflag) {
        printf("-1\n");
        return 0;
    }

    for (int i = 1; i <= n; i++) q[i] = a[i];
    sort(a + 1, a + n + 1, cmp);

    for (int i = 1; i <= n; i++) {
        if (!q[a[i].id].ok) {
            while (a[i].nxt != a[i].id) {
                ans.push_back((D){a[i].id, a[i].nxt});
                q[a[i].nxt].ok = 1;
                a[i].nxt = q[a[i].nxt].nxt;
            }
            a[i].ok = 1;
        }
    }

    cout << ans.size() << endl;
    for (const auto &i : ans) {
        printf("%d %d\n", i.a, i.b);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define int long long
#define pb push_back
#define pii pair<int,int>
#define endl "\n"
#define gok ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int mod = 1e9 + 7,mxn=2e5 + 5;
/*struct cmp
{
    bool operator() (pair<int,pii> a, pair<int,pii> b)
    {
        return a.first > b.first;
    }
};*/

signed main(){
    gok

  int k;
  string n;
  cin>>n>>k;

  for(int i=0;i<k;i++)
  {
      string n1 = n,n2 = n;
      sort(n1.begin(),n1.end());
      sort(n2.rbegin(),n2.rend());
      int v1 = stoi(n1);
      int v2 = stoi(n2);
      v2 -= v1;
      n = to_string(v2);
  }

  cout<<n;

        return 0;

    }

//  RAKSHIT KADAM
 #include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 3
// #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>
#warning check the size of arrays!!!
// NUMERIC DEFINITIONS :
    #define INF 1000000000000000005
    #define inf 1000000004
    #define MOD  1000000007
    #define mod 998244353
    #define MAX 300006
    #define pi 3.1415926535897932384626433832795
#define ld long double
 #define ll long long
 #define int long long
 #define P(gg) for(auto rax:gg){cout<<rax<<" ";}cout<<endl;
 #define Need_for_speed(activated) ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
 #define satisfy ll ter; cin>> ter; while(ter--)
 #define inp(n) int n;cin >> n
 #define mp make_pair
 #define pb push_back
 #define endl "\n"
 #define x first
 #define y second
 #define fore(i,a,b) for(ll i=a;i<b;i++)
 #define forci(i,n) for(ll i=0;i<n;i++)
 #define vi vector<ll>
 #define Endl endl
 #define lb lower_bound
 #define ub upper_bound
#define pii pair<ll,ll>

 #define input freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout)
 #define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;

//ll gcd(ll a, ll b){if (b == 0)return a;return gcd(b, a % b);}
//
//int power(int x, unsigned int y, unsigned int m){ if (y == 0) return 1;int p = power(x, y/2, m) % m;  p = (p * p) % m;return (y%2 == 0)? p : (x * p) % m;}
//ll modInverse(int a, int m){{ return power(a, m-2, m);}}
//
//const int maxn = 500003;
//
//ll fact[200009];
//ll modIN[200009];
//void facto()
//{
//    ll lim =200005;fact[0]=1;
//    for(ll i=1;i<lim;i++)
//    {
//        fact[i]=(fact[i-1]*i)%MOD;
//    }
//
//}
//ll ncr(ll a,ll b)
//{
//    ll ret = 0;
//    if(b==0)return 1;
//    if(b>a)return 0;
//    ret = fact[a]*(modInverse(fact[b],MOD));
//
//    ret%=MOD;
//    ret*=modInverse(fact[a-b],MOD);
//    ret%=MOD;
//
//    return ret;
//}
//  """""   1LL << x    """""

void solve()
{
    ll n,k;cin>>n>>k;
    while(k--)
    {
        string s = to_string(n);
        sort(s.begin(),s.end());
        string a = s;
        string b = s;
        reverse(b.begin(),b.end());
        ll x= 0;
        for(auto it:a)
        {
            x*=10;
            x+=it-'0';
        }
        ll y = 0;
        for(auto it:b)
        {
            y*=10;
            y+=it-'0';
        }
        n=abs(y-x);
        if(n==0)
        {
            cout<<0<<endl;return;
        }
    }
    cout<<n<<endl;
}

signed main()
{
   Need_for_speed(activated);

//    satisfy
//    {
// solve();
//    }
    solve();

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '['; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << ']'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '{' << p.first << ", " << p.second << '}'; }
template<typename T> ostream& operator<<(ostream &os, const set<T> &s) { os << '{'; string sep; for (const auto &x : s) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const map<A, B> &mp) { os << '['; string sep; for (const auto &x : mp) os << sep << x, sep = ", "; return os << ']'; }
template<typename T> ostream& operator<<(ostream &os, const multiset<T> &s) { os << '{'; string sep; for (const auto &x : s) os << sep << x, sep = ", "; return os << '}'; }

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

#ifndef ONLINE_JUDGE
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "] =", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

#define int long long
#define mod 1000000007
#define inf 1e18
#define endl '\n'
#define pb push_back
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)(x).size()
#define sb(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define rall(x) (x).rbegin(), (x).rend()

int decimaltoOctal(int deciNum)
{
    int octalNum = 0, countval = 1;
    int dNo = deciNum;
    while (deciNum != 0) {
        int remainder = deciNum % 8;
        octalNum += remainder * countval;
        countval = countval * 10;
        deciNum /= 8;
    }
    return octalNum;
}

bool check(int n) {
    while (n > 0) {
        int digit = n % 10;
        if (digit == 7) return false;
        n /= 10;
    }
    return true;
}

void solve()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //cout << fixed << setprecision(10);
    int n; cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (check(i) && check(decimaltoOctal(i))) {
            ans++;
        }
    }
    dbg(ans);
    // for (int i = 1; i <= n; i++) {
    //     if (check(decimaltoOctal(i))) {
    //         dbg(decimaltoOctal(i));
    //         ans++;
    //     }
    // }
    cout <<  ans << endl;
}

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

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

int main(){
    ll N;
    cin >> N;
    unordered_set<ll> s;
    for(ll a = 2; a * a <= N; a++){
        ll x = a * a;
        while(x <= N){
            s.insert(x);
            x *= a;
        }
    }
    cout << N - s.size() << endl;
}


#include <bits/stdc++.h>
// #include <atcoder/all>

using namespace std;
// using namespace atcoder;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x) REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n) REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x) REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m) REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

//cout << setfill('0') << right << setw`(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
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;} }
template<class T> bool isIn(T a,vector<T> v){ for(T x:v){ if(a==x){return true;}} return false;}
string strReplace(string s,string target, string replacement){
    if (!target.empty()) {
      std::string::size_type pos = 0;
      while ((pos = s.find(target, pos)) != std::string::npos) {
        s.replace(pos, target.length(), replacement);
        pos += replacement.length();
      }
    }
    return s;
}
const ll MOD = 998244353;
// using mint = static_modint<MOD>;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair

bool DEBUG = 0;
template<class T> void dprint(T s){
  if(DEBUG){ cout << s << "\n"; }
}

void solve(){
  int N; cin>>N;
  vector<int> a(N),b(N);
  int M = N*2;
  vector<int> tp(M,0),com(M,-1);

  REP(i,N){
    cin >> a[i] >> b[i];
    if(a[i]!=-1){
      --a[i];
      if(tp[ a[i] ]!=0){ cout << Linn; return; }
      tp[ a[i] ] = i+1;
    }
    if(b[i]!=-1){
      --b[i];
      if(tp[ b[i] ]!=0 ){cout << Linn; return;}
      tp[ b[i] ] = -(i+1);
    }
    if(a[i]!=-1 && b[i]!=-1){
      com[ a[i] ] = b[i];
      com[ b[i] ] = a[i];
    }
  }
  dprint("---78----");

  vector<bool> dp(M+1,false);
  dp[0] = true;
  REP(i,M){
    if(!dp[i]){continue;}
    dprint("--");

    for(int j=i+1;j<M;++j){
      int w = j - i + 1;
      if(w%2){continue;}
      w /= 2;
      bool ok = true;
      vector<bool> exist(N,false);

      REP(k,w){
        int start = i+k;
        int stop = i+k+w;
        if(com[start] != -1 && !(i<=com[start] && com[start]<=j) ){
          ok = false;
          break;
        }
        dprint("r1");
        if(com[stop] != -1 && !(i<=com[stop] && com[stop]<=j)){
          ok = false;
          break;
        }
        dprint("r2");

        if(tp[start] != 0 && tp[stop] != 0){
          if( tp[start]<0 || tp[start]+tp[stop] != 0){
            ok = false;
            break;
          }
        }
        dprint("r3");
        if(tp[start]<0 || tp[stop]>0){
          ok = false;
          break;
        }
        dprint("r4");
        if(tp[start] != 0){
          int temp = tp[start]-1;
          if(exist[temp]){
            ok = false;
            break;
          }
          exist[temp] = 1;
        }
        dprint("r5");
      }
      if(ok){
        dp[j+1] = 1;
      }
    }
  }
  dprint("---130---");
  REP(i,M+1){
    dprint(dp[i]);
  }
  if(dp[M]){ cout << Liny; }
  else{ cout << Linn; }
  return;
}

int main(int argc, char *argv[]){
  if(argc>1 && argv[1][0]=='D'){ DEBUG = 1;}
  solve();
  return 0;
}

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

template<typename T>
ostream& operator<<(ostream &os, vector<T> &v){
    string sep = " ";
    if(v.size()) os << v[0];
    for(int i=1; i<v.size(); i++) os << sep << v[i];
    return os;
}

template<typename T>
istream& operator>>(istream &is, vector<T> &v){
    for(int i=0; i<v.size(); i++) is >> v[i];
    return is;
}

#ifdef DBG
void debug_(){ cout << endl; }
template<typename T, typename... Args>
void debug_(T&& x, Args&&... xs){
    cout << x << " "; debug_(forward<Args>(xs)...);
}
#define dbg(...) debug_(__VA_ARGS__)
#else
#define dbg(...)
#endif

int main() {
    ios_base::sync_with_stdio(false);
    cout << setprecision(20) << fixed;

    int n; cin >> n;
    vector<int> s(2*n), d(2*n);
    for(int i=0; i<n; i++){
        int a, b; cin >> a >> b;
        a--; b--;
        if(a>=0&&b>=0){
            if(b<=a||s[a]!=0||s[b]!=0) {
                cout << "No" << endl;
                return 0;
            }
            s[a] = (i+1);
            s[b] = -(i+1);
            d[a] = b-a;
            d[b] = a-b;
        } else if(a>=0){
            if(s[a]!=0){
                cout << "No" << endl;
                return 0;
            }
            s[a] = i+1;
        } else if(b>=0){
            if(s[b]!=0){
                cout << "No" << endl;
                return 0;
            }
            s[b] = -(i+1);
        }
    }

    vector<bool> dp(2*n+1);

    dp[0] = true;

    for(int i=0; i<2*n; i++){
        if(!dp[i]) continue;
        for(int j=i+1; j<2*n; j+=2){
            int w = (j-i+1)/2;
            bool ok = true;
            for(int k=0; k<w; k++){
                int p = i+k, q = i+w+k;
                if(d[p]!=0&&p+d[p]!=q) ok = false;
                if(d[q]!=0&&q+d[q]!=p) ok = false;

                if(s[p]!=0&&s[q]!=0&&s[p]+s[q]!=0) ok = false;
                if(s[p]<0 || 0<s[q]) ok = false;

                // if(s[p]<0) ok = false;
                // if(d[p]!=0&&d[p]!=w) ok = false;

                // if(s[q]>0) ok = false;
                // if(d[p]!=0&&d[q]!=-w) ok = false;
            }
            if(ok) dp[j+1] = true;
        }
    }

    cout << (dp[2*n]?"Yes":"No") << endl;

    return 0;
}


/*
			Saturday 08 May 2021 05:51:43 PM IST
					@uthor::astrainL3gi0N
*/

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

typedef long long int ll;
typedef std::vector<int> vi;
typedef std::pair<int,int> ii;
typedef std::vector<ii> vii;
typedef std::vector<ll> vl;

#define pb push_back
#define mp make_pair
#define debg(x)	std::cerr<<(#x)<<" => "<<x<<'\n';
#define debgg(x,y)	std::cerr<<(#x)<<" => "<<x<<'\t'<<(#y)<<' '<<y<<'\n';
#define len(a) (int)(a).size()
#define all(x) x.begin(),x.end()

const int mod = 200;
const int modd = 998244353;
const int esc = -1;
const string ys = "Yes\n";
const string no = "No\n";

bool comp (int x, int y) {
    return x > y;
}
void printarr (int arr[], int n) {
    for(int i = 0; i < n; ++i)
        cout<<arr[i]<<(i<n-1?' ':'\n');
}
template < typename T> void  printv (T &a) {
    for (auto it = a.begin(); it != a.end(); ++it)
        cout<<*it<<' ';
    cout<<'\n';
}
int gint() {
    int n;  cin>>n;
    return n;
}
//int t[510][510];
ll ans;

void solve () {
    map <int,int> freq;
    set <int> hsh;
    ans = 0;
    bool ok = false;
    int n = gint();
    vi arr(100,0);
    for (int i = 0; i < n;++i) {
        arr[i] = gint()%200;
    }
    int res = 0;
	for (int b = 1; b < (1<<(min(10,n))); ++b) {
	    ans = 0;
	    ok = 1;
		for (int i = 0;i < min(n,30); ++i) {
			if (b & (1<<i))	{
			    ans += arr[i];
			    ans %= mod;
            }
		}
		if (ok)
		if (freq[ans]) {
		    res = b;
		    break;
        }
        freq[ans] = b;
    }
    vi rs1,rs2;

    cout<<(res?"YES":"NO");
    cout<<'\n';
    if (res) {
        int temp = freq[ans];
		for (int i = 0; i < 10; ++i) {
			if (res & (1<<i))	{
			    rs1.pb(i+1);
            }
			if (temp & (1<<i))	{
			    rs2.pb(i+1);
            }
		}
		cout<<len(rs1)<<' ';
		printv(rs1);
		cout<<len(rs2)<<' ';
		printv(rs2);

    }
}
void sol () {
    //test
}

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

    //cout << setprecision(15) << fixed;
    int testcases = 1;
    for (int t = 0; t < testcases; ++t) {
        //cout<<"Case #"<<t+1<<": ";
        solve();
    }

    return 0;
}

/*#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")*/
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
typedef long long ll;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++)
#define RFOR(i, a, n) for (ll i = (ll)n - 1; i >= (ll)a; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define bra(firstsecond) '(' << first< ',' << second< ')'
//constexpr ll MOD = 1000000007;
//constexpr ll MOD = 998244353;
constexpr ll MOD = 3;
ll INF = 1001001001001001001;
long double EPS = 1e-8;
long double PI = 3.141592653589793238;
template <typename T>
void remove(std::vector<T> &vector, unsigned int index)
{
   vector.erase(vector.begin() + index);
}

random_device seed_gen;
mt19937_64 rnd(seed_gen());

ll range_rand(ll a,ll b){
    uniform_int_distribution<ll> dist_res(a,b);
    return dist_res(rnd);
}

using Graph = vector<vector<ll>>;

// MOD確認

ll N;
ll A[210];
set<set<ll>> dp[210][210];

int main(){
   cin >> N;
   rep(i,N) cin >> A[i];
   set<ll> sstt;
   dp[0][0].insert(sstt);
   rep(i,N){
      rep(j,200){
         for(auto itr = dp[i][j].begin();itr != dp[i][j].end();itr++){
            if(dp[i+1][(A[i]+j) % 200].size() >= 3 && dp[i+1][j].size() >= 2) break;
            set<ll> st = *itr;
            st.insert(i);
            dp[i+1][(A[i]+j) % 200].insert(st);
            dp[i+1][j].insert(*itr);
         }
      }
   }
   rep(i,200){
      if(dp[N][i].size() >= 2){
         set<ll> st1,st2,st;
         ll cnt = 0;
         ll n = dp[N][i].size();
         for(auto itr = dp[N][i].begin();itr != dp[N][i].end();itr++){
            st = *itr;
            cnt++;
            if(st.size() != 0 && cnt != n){
               st1 = *itr;
               itr++;
               st2 = *itr;
               break;
            }
         }
         if(st1.size() != 0){
            cout << "Yes" << endl;
         }else{
            continue;
         }
         if(st1 == st2) continue;
         cout << st1.size() << ' ';
         for(auto itr = st1.begin();itr != st1.end();itr++){
            cout << *itr + 1 << ' ';
         }
         cout << endl;
         cout << st2.size() << ' ';
         for(auto itr = st2.begin();itr != st2.end();itr++){
            cout << *itr + 1 << ' ';
         }
         cout << endl;
         return 0;
      }
   }
   cout << "No" << endl;
}


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

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(n, m);
    rvi(a, n);

    vi len(m, 0);
    vi prv(m, -1);
    fi(i, n) {
        i64 k = a[i];
        if (k >= m) continue;
        len[k] = max(len[k], i - prv[k]);
        prv[k] = i;
    }
    dbg(prv);
    fi(i,m) {
        len[i] = max(len[i], n - prv[i]);
    }
    dbg(len);

    i64 res = m;
    fr(i, m) {
        if (len[i] > m) res = i;
    }
    wl(res);

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
auto fl = [](auto a, auto b) { assert(b != 0); return a / b - (a % b != 0 && ((a >= 0) != (b >= 0)) ? 1 : 0); };
auto ce = [](auto a, auto b) { assert(b != 0); return a / b + (a % b != 0 && ((a >= 0) == (b >= 0)) ? 1 : 0); };
auto mo = [](auto a, auto b) { assert(b != 0); a %= b; if(a < 0) { a += abs(b); } return a; };
LL gcd(LL a, LL b) { return (b == 0 ? a : gcd(b, a % b)); }
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)

// ---- ----

int main() {
	int n, m, k;
	cin >> n >> k >> m;
	vector<int> a(n - 1);
	inc(i, n - 1) { cin >> a[i]; }

	int s = 0;
	inc(i, n - 1) { s += a[i]; }

	int ans = max(n * m - s, 0);

	cout << (ans <= k ? ans : -1) << endl;

	return 0;
}


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

using ll = long long;

#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define FOR(i, n, m) for(int (i) = (n); (i) < (m); ++(i))

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return 1; } return 0; }
constexpr int INF = 1e9;
constexpr ll INFL = 1LL << 61;
constexpr ll mod = 1e9+7;

double dp[105][105][105];
bool flag[105][105][105];

double rec(int A, int B, int C){
  if(flag[A][B][C]) return dp[A][B][C];
  if(A==100 || B == 100 || C == 100){
    return 0;
  }
  flag[A][B][C] = true;
  double sum = A + B + C;
  double res = A / sum * (rec(A+1, B, C)+1) + B / sum * (rec(A, B+1, C)+1) + C / sum * (rec(A, B, C+1)+1);
  return dp[A][B][C] = res;
}
int main(){
  int A, B, C;
  cin >> A >> B >> C;
  printf("%.9f\n", rec(A, B, C));

  return  0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60;
const double PI = acos(-1.0);
/*const double PI = atan2(0.0,-1.0)*/
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep1(i,aa,n) for(ll i = aa; i <= (ll)(n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define ar_init(aa,val) rep(i,aa.size()) aa[i]=val;
#define v2d(aa,val1,val2,ini) vector<vector<ll>> aa(val1,vector<ll>(val2,ini));
#define pqe priority_queue<ll>
#define pqeg priority_queue<ll,vector<ll>,greater<ll>>
#define lcin(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define eout(...) COU(__VA_ARGS__);
#define sout(...) SCOU(__VA_ARGS__);
#define scin(...) string __VA_ARGS__;CINT(__VA_ARGS__)
#define lb(aa,val) lower_bound(ALL(aa),val)
#define pb push_back
#define mkp make_pair
#define si size()

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}

void COU(){}
template <class Head,class... Tail>
void COU(Head&& head,Tail&&... tail){
    cout<<head<<endl;
    COU(move(tail)...);
}

void SCOU(){}
template <class Head,class... Tail>
void SCOU(Head&& head,Tail&&... tail){
    cout<<head<<" ";
    SCOU(move(tail)...);
}

template <class T = ll>
T IN(){T x;cin>>x;return (x);}

using pii = pair<ll,ll>;
using v2 = vector<vector<ll>>;
using v1 = vector<ll>;
using v2p = vector<vector<pii>>;
using v1p = vector<pii>;
//ll mo=1000000007;
ll mo=998244353;

ll mod_pow(ll N,ll n){
if(n==0) return 1;
ll pp,hh;
pp=n/2;
hh=n%2;
int tt=mod_pow(N,n/2);
if(hh==0)return tt%mo*tt%mo;
else {return tt%mo*tt%mo*N%mo;}
}
long long extGCD(long long a, long long b, long long &x, long long &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a%b, y, x); // 再帰的に解く
    y-=a/b*x;
    return d;
}

ll modpow(ll a, ll n = mo-2) {
	ll r=1;a%=mo;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}

v2d (aa,5003,5003,0);
v2d (dp,5003,5003,0);
int main(){

lcin(h,w);
lcin(k);

dp[0][0]=1;
rep(i,k){
ll a,b;
char f;

cin>>a>>b>>f;
if(f=='R'){
aa[a-1][b-1]=1;
}else if(f=='D'){
aa[a-1][b-1]=2;
}else{
aa[a-1][b-1]=3;
}
}

ll g=2*modpow(3);

rep(i,h){
rep(j,w){

if(aa[i][j]){
if(aa[i][j]!=1)dp[i+1][j]+=dp[i][j];
if(aa[i][j]!=2)dp[i][j+1]+=dp[i][j];

}else{

dp[i+1][j]+=g*dp[i][j]%mo;
dp[i][j+1]+=g*dp[i][j]%mo;
dp[i+1][j]%=mo;
dp[i][j+1]%=mo;
}

}
}

eout(mod_pow(3,h*w-k)*dp[h-1][w-1]%mo);

}


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

int n;
int dp[200001][8] ;
string s, x ;

bool fun(int idx, int num) {
	if (idx > n) return (num == 0) ;
	int &ret = dp[idx][num] ;
	if (ret != -1) return ret ;
	int cur = 0 ;
	if (x[idx] == 'A') {
		cur = fun(idx+1, (num * 10)%7) ;
		if (cur == 1) cur = fun(idx+1, (num * 10 + (s[idx] - '0'))%7) ;
	}
	else {
		cur = fun(idx+1, (num * 10)%7) ;
		if (cur == 0) cur = fun(idx+1, (num * 10 + (s[idx] - '0'))%7) ;
	}
	return ret = cur ;
}

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

    cin >> n >> s >> x;
    s = "#" + s ;
    x = "#" + x ;
    memset(dp, -1, sizeof(dp)) ;
    bool ok = fun(1, 0) ;
    string ans = "Aoki" ;
    if (ok) ans = "Takahashi" ;
    cout << ans << endl ;
    return 0;
}

#ifdef LOGX
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;

/*---------macro---------*/
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = s; i < (int)(n); ++i)
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define mybit(i,j) (((i)>>(j))&1)

/*---------type/const---------*/
typedef long long ll;
typedef unsigned long long ull;
typedef std::string::const_iterator state; //構文解析
const ll big=1000000007;
//const ll big=998244353;
const double EPS=1e-8; //適宜変える
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const char newl='\n';
struct{
    constexpr operator int(){return -int(1e9)-10;}
    constexpr operator ll(){return -ll(1e18)-10;}
}neginf;
struct{
    constexpr operator int(){return int(1e9)+10;}
    constexpr operator ll(){return ll(1e18)+10;}
    constexpr auto operator -(){return neginf;}
}inf;

/*---------debug---------*/
#ifdef LOGX
#include <template/debug.hpp>
#else
#define dbg(...) ;
#define dbgnewl ;
#define prt(x) ;
#define _prt(x) ;
#endif

/*---------function---------*/
template<typename T> T max(const std::vector<T> &a){T ans=a[0];for(T elem:a){ans=max(ans,elem);}return ans;}
template<typename T> T min(const std::vector<T> &a){T ans=a[0];for(T elem:a){ans=min(ans,elem);}return ans;}
template<typename T,typename U> bool chmin(T &a,const U b){if(a>b){a=b;return true;}return false;}
template<typename T,typename U> bool chmax(T &a,const U b){if(a<b){a=b;return true;}return false;}
bool valid(int i,int j,int h,int w){return (i>=0 && j>=0 && i<h && j<w);}
template<class T,class U>T expm(T x,U y,const ll mod=big){T res=1;while(y){if(y&1)(res*=x)%=mod;(x*=x)%=mod;y>>=1;}return res;}
template<class T,class U>T exp(T x,U y){T res=1;while(y){if(y&1)res*=x;x*=x;y>>=1;}return res;}

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.precision(10);
    /*--------------------------------*/

    int n;cin >> n;
    string s;cin >> s;
    string x;cin >> x;
    //「高橋の勝ち」.
    vector<vector<bool>> dp(n+1,vector<bool>(7,false));
    dp[n][0]=true;
    for(int i=n-1;i>=0;i--){
        int now=expm(10,n-i-1,7);
        if(x[i] == 'T'){
            rep(j,7){
                if(dp[i+1][j] || dp[i+1][(j+now*(s[i]-'0')) %7]){
                    dp[i][j]=true;
                }
                else{
                    dp[i][j]=false;
                }
            }
        }
        else{
            rep(j,7){
                if((!dp[i+1][j])|| !dp[i+1][(j+now*(s[i]-'0')) %7]){
                    dp[i][j]=false;
                }
                else{
                    dp[i][j]=true;;
                }
            }
        }
    }
    cout << (dp[0][0] ? "Takahashi" : "Aoki") << newl;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define fi first
#define se second
#define endl '\n'
#define MAX INT_MAX
#define MIN INT_MIN
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mod 1000000007
#define pb push_back
#define sz(a) (int)((a).size())
#define all(a) a.begin(),a.end()
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define forn(i, n) for (int i = 0; i < n; i++)
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef pair< int,int > pii;

int32_t main()
{
    fast

   int test=1;
   //cin>>test;
  while(test--)
  {

    int n;
    cin>>n;
    set<int> s;
    int x;
    forn(i,n)
    {
        cin>>x;
        s.insert(x);
    }

    while(s.size()>1)
    {
        int mn=*s.begin();
        int mx=*s.rbegin();
        s.erase(mx);
        s.insert(mx-mn);
    }

    cout<<*s.begin();

  //while loop ending
  }

  return 0;
  }

#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>
//#include<atcoder/all>

using namespace std;
//using namespace atcoder;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.12f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX_N = 1010101;

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// mod.m での a の逆元 a^ { -1 } を計算する
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x /gcd(x, y) * y );
}

//union-find木について
ll par[101010];
ll rank2[101010];

void init(ll n) {
	rep(i, n) {
		par[i] = i;
		rank2[i] = 0;
	}
}

ll find(ll x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}

void unite(ll x, ll y) {
	x = find(x);
	y = find(y);
	if (x == y)return;
	if (rank2[x] < rank2[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (rank2[x] == rank2[y]) {
			rank2[x]++;
		}
	}
}

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

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	ll n;
	cin >> n;
	vector<ll>a(n);
	priority_queue<ll>q1;
	rep(i, n) {
		cin >> a[i];
	}
	ll ans = a[0];
	rep(i, n) {
		ans = gcd(ans, a[i]);
	}
	cout << ans << endl;
	return 0;
}


#pragma GCC optimize(2)
//#include <bits/stdc++.h>
#include <iostream>
#include <set>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <utility>
#include <map>
#define rush()      int T; while(cin>>T) while(T--)
#define ms(a,b)     memset(a,b,sizeof a)
#define lowbit(x)   ((x)&(-x))
#define inf         0x7f7f7f7fll
#define eps         1e-11
#define sd(a)       scanf("%d",&a)
#define sll(a)      scanf("%lld",&a)
#define sll2(a,b)   scanf("%lld%lld",&a,&b)
#define sll3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define sdd(a,b)    scanf("%d%d",&a,&b)
#define sddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sf(a)       scanf("%lf",&a)
//#define sc(a)       scanf("%c\n",&a)
#define ss(a)       scanf("%s",a)
#define pd(a)       printf("%d\n",a)
#define pdd(a,b)    printf("%d %d\n",a,b)
#define pddd(a,b,c) printf("%d %d %d\n",a,b,c)
#define pll(a)      printf("%lld\n",a)
#define pf(a)       printf("%.1lf\n",a)
#define pc(a)       printf("%c",a)
#define ps(a)       printf("%s\n",a)
#define rep(i,a,b)  for(int i=(a);i<=(b);i++)
#define forn(i,a,b,x)  for(int i=(a);i<=(b);i+=(x))
#define per(i,a,b)  for(int i=(b);i>=(a);i--)
#define pb(a)       push_back(a)
#define mp(a,b)     make_pair(a,b)
#define debug(a)    cout<<#a<<" : "<<a<<" "<<" ; "
#define dbg(a)      cout<<#a<<" : "<<a<<endl
#define show(a,b)   cout<<a<<" :\t"<<b<<"\t*"<<endl
#define IOS         ios::sync_with_stdio(0); cin.tie(0)
#define PAUSE       system("pause")
#define all(x)      x.begin(),x.end()
//#define print(a)    cout<<a<<endl;continue;
#define fr          first
#define sc          second
#define ceils(a,b)  ((a-1ll+b)/(b))
#define floors(a,b) floor(double(a)/double(b))
using namespace std;
//inline void swap(int &x,int &y){x^=y^=x^=y;}
typedef long long ll;
//using ui=unsigned int;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const double pi=acos(-1.0);
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};
const int limit=5e5;

int read()
{
	int s=0;
	char c=getchar(),lc='+';
	while (c<'0'||'9'<c) lc=c,c=getchar();
	while ('0'<=c&&c<='9') s=s*10+c-'0',c=getchar();
	return lc=='-'?-s:s;
}

void write(int x)
{
	if (x<0) putchar('-'),x=-x;
	if (x<10) putchar(x+'0');
	else write(x/10),putchar(x%10+'0');
}

void print(int x,char c='\n')
{
	write(x);
	putchar(c);
}

ll mod=2147483648;
const int N=3e5+5;

    int n, m, _;
    int i, j, k;
    int a[N];
    int pos[N];
    vector<int> ans;

signed main()
{
    //IOS;
    rush(){
        sd(n);
        rep(i, 1, n) sd(a[i]), pos[a[i]] = i;
        int opt = 1;
        rep(i, 1, n){
            if(i == pos[i]) continue;
            if((pos[i] - 1) % 2 != opt){
                if(pos[i] - 2 >= i){
                    ans.pb(pos[i] - 2);
                    int x = pos[i] - 2, y = pos[i] - 1;
                    swap(pos[a[x]], pos[a[y]]);
                    swap(a[x], a[y]);
                    opt ^= 1;
                }
                else if(pos[i] == i + 1){
                    ans.pb(i - 1);
                    ans.pb(i);
                    ans.pb(i - 1);
                    ans.pb(i);
                    ans.pb(i - 1);
                    //ans.pb(i);
                    opt ^= 1;
                    int x = pos[i], y = pos[i] - 1;
                    swap(pos[a[x]], pos[a[y]]);
                    swap(a[x], a[y]);
                    continue;
                }
            }
            for(int j = pos[i] - 1; j >= i; j--){
                ans.pb(j);
                int x = j, y = j + 1;
                swap(pos[a[x]], pos[a[y]]);
                swap(a[x], a[y]);
                opt ^= 1;
            }
        }
        pd(ans.size());
        for(auto it : ans) printf("%d ", it);
        puts("");
        ans.clear();
    }
    //PAUSE;
    return 0;
}

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

#define rep(i, a, b) for(int i=a; i<=b; i++)
#define trav(a, x) for(auto &a:x)
#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define f first
#define s second
#define nl '\n'
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

int n, turn, t;
int a[501];
int pos[501];
vi ans;

void swap(int i){
	swap(a[i], a[i+1]);
	swap(pos[a[i]], pos[a[i+1]]);
	ans.pb(i);
	turn++;
}

void solve3(){
	while(!(a[1]==1 && a[2]==2 && a[3]==3)){
		if(turn&1) swap(1);
		else swap(2);
	}
}

void solve4(){
	while(a[4]!=4){
		if(turn&1){
			if(a[1]==4) swap(1);
			else swap(3);
		}
		else swap(2);
	}
	solve3();
}

int main(){
	cin.tie(0)->sync_with_stdio(0);
	// freopen("input.txt", "r", stdin);

	cin >> t;
	while(t--){
		turn=1;
		ans.clear();
		cin >> n;
		rep(i, 1, n){
			cin >> a[i];
			pos[a[i]]=i;
		}

		if(n==2){
			if(a[1]==1) cout << "0";
			else cout << "1\n1";
			cout << nl;
			continue;
		}
		if(n==3) solve3();
		else if(n==4) solve4();
		else{
			turn=1;
			for(int i=n; i>=5; i--) {
				if(pos[i]==i) continue;
				if(turn%2!=pos[i]%2){
					if(pos[i]-3>=1) swap(pos[i]-3);
					else swap(pos[i]+1);
				}
				while(pos[i]!=i){
					swap(pos[i]);
				}
			}
			solve4();
		}

		cout << sz(ans) << nl;
		trav(k, ans) cout << k << " ";
		cout << nl;
	}
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
#define int long long
typedef int ll;
typedef long double ld;
const ll N = 505;
char en = '\n';
ll inf = 1e16;
ll mod = 998244353;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}

using namespace __gnu_pbds; //(or pb_ds)
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    pbds;

char arr[N][N];

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

  ll n;
  cin >> n;

  ll a[n + 5];
  ll b[n + 5];

  map<ll, vector<ll>> indices;
  for (ll i = 1; i <= n; i++) {
    cin >> a[i];
    indices[i + a[i]].push_back(i);
  }
  for (ll i = 1; i <= n; i++) {
    cin >> b[i];
  }

  for (auto &it : indices) {
    reverse(it.second.begin(), it.second.end());
  }
  pbds X;
  ll res = 0;

  for (ll i = 1; i <= n; i++) {
    ll req = b[i] + i;
    if (indices.find(req) == indices.end()) {
      cout << -1 << en;
      return 0;
    }
    vector<ll> &vect = indices[req];
    ll indx = vect.back();
    vect.pop_back();
    if (vect.empty()) {
      indices.erase(req);
    }

    // adjust for changes
    // find indices > indx
    ll change = (i - 1) - X.order_of_key(indx);

    X.insert(indx);
    res += indx + change - i;
  }
  cout << res << en;

  return 0;
}

#include <bits/stdc++.h>
#define mod 998244353

using namespace std;

int n,i,x;
int a[200005];
long long ans;
vector<int> seg;
map<int, vector<int>> m;

void upd(int stt, int drt, int st, int dr, int p, int val)
{
    if(stt==st && drt==dr)
    {
        seg[p]+=val;
        return;
    }

    int mij=(st+dr)/2;

    if(drt<=mij)
        upd(stt, drt, st, mij, 2*p, val);
    else if(stt>mij)
        upd(stt, drt, mij+1, dr, 2*p+1, val);
    else
    {
        upd(stt, mij, st, mij, 2*p, val);
        upd(mij+1, drt, mij+1, dr, 2*p+1, val);
    }
}
int query(int i, int st, int dr, int p)
{
    if(st==dr)
        return seg[p];

    int mij=(st+dr)/2;

    if(i<=mij)
        return seg[p]+query(i, st, mij, 2*p);
    else
        return seg[p]+query(i, mij+1, dr, 2*p+1);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin>>n;

    seg.resize(4*n+4);

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

    for(i=n;i>=1;i--)
    {
        upd(i, i, 1, n, 1, i);
        m[a[i]].push_back(i);
    }

    for(i=1;i<=n;i++)
    {
        cin>>x;
        x+=i;

        if(m[x].empty())
        {
            cout<<-1;
            return 0;
        }

        int p=m[x].back();
        m[x].pop_back();

        ans+=query(p, 1, n, 1)-i;

        if(p>1)
            upd(1, p-1, 1, n, 1, 1);
    }

    cout<<ans;
    return 0;
}


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

typedef int_fast32_t int32;
typedef int_fast64_t int64;

const int32 inf = 1e9+7;
const int32 MOD = 1000000007;
const int64 llinf = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define all(obj) (obj).begin(),(obj).end()
#define rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int64 n,k;
  cin >> n >> k;
  while(k > 0){
    if(n % 200 == 0){
      n = n / 200;
      --k;
    }else{
      if(k >= 2){
        n = 5 * n + 1;
        k -= 2;
      }else{
        n = 1000 * n + 200;
        --k;
      }
    }
  }
  ANS(n);
  return 0;
}

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

int main() {
long long N, K;
  cin >> N >> K;
  rep(i, K){
    if(N % 200 == 0){
      N /= 200;
      continue;
    }
    else{
      N *= 1000;
      N += 200;
    }
  }
  cout << N << endl;
}


//ver 8.1
#include <bits/stdc++.h>
using namespace std;
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vd = vector<ld>;
using vs = vector<string>;
using vb = vector<bool>;
using vvl = vector<vector<ll>>;
using vvd = vector<vector<ld>>;
using vvs = vector<vector<string>>;
using vvb = vector<vector<bool>>;
using pll = pair<ll,ll>;
using mll = map<ll,ll>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
#define each(x,v) for(auto& x : (v))
#define reps(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define mp make_pair
const ll INF = 1LL << 60;
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) ((a)<=(x)&&(x)<=(b))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) //被り削除
#define debug cout << "line : " << __LINE__ << " debug" << endl;
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ind(...) long double __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define inc(...) char __VA_ARGS__; in(__VA_ARGS__)
void in(){}
template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
template <typename T> void in1(T &s) {rep(i,s.size()){in(s[i]);}}
template <typename T> void in2(T &s,T &t) {rep(i,s.size()){in(s[i],t[i]);}}
template <typename T> void in3(T &s,T &t,T &u) {rep(i,s.size()){in(s[i],t[i],u[i]);}}
template <typename T> void in4(T &s,T &t,T &u,T &v) {rep(i,s.size()){in(s[i],t[i],u[i],v[i]);}}
template <typename T> void in5(T &s,T &t,T &u,T &v,T &w) {rep(i,s.size()){in(s[i],t[i],u[i],v[i],w[i]);}}
void out(){cout << endl;}
template <typename T,class... U> void out(const T &t,const U &...u){cout << t; if(sizeof...(u)) cout << " "; out(u...);}
void die(){cout << endl;exit(0);}
template <typename T,class... U> void die(const T &t,const U &...u){cout << t; if(sizeof...(u)) cout << " "; die(u...);}
template <typename T> void outv(T s) {rep(i,s.size()){if(i!=0)cout<<" ";cout<<s[i];}cout<<endl;}
template <typename T> void out1(T s) {rep(i,s.size()){out(s[i]);}}
template <typename T> void out2(T s,T t) {rep(i,s.size()){out(s[i],t[i]);}}
template <typename T> void out3(T s,T t,T u) {rep(i,s.size()){out(s[i],t[i],u[i]);}}
template <typename T> void out4(T s,T t,T u,T v) {rep(i,s.size()){out(s[i],t[i],u[i],v[i]);}}
template <typename T> void out5(T s,T t,T u,T v,T w) {rep(i,s.size()){out(s[i],t[i],u[i],v[i],w[i]);}}
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
template <typename T> T allSum(vector<T> a){T ans=T();each(it,a)ans+=it;return ans;}
template<typename T> bool inside(T a,T b){auto it=a.begin()-1;each(x,b){it=find(it+1,a.end(),x);if(it==a.end())return false;}return true;}
ll ceilDiv(ll a,ll b) {return (a+b-1)/b;}
ld dist(pair<ld,ld> a, pair<ld,ld> b){return sqrt(abs(a.fi-b.fi)*abs(a.fi-b.fi)+abs(a.se-b.se)*abs(a.se-b.se));} // ２点間の距離
ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b;}
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
#define YES(n) ((n) ? "YES" : "NO"  )
#define Yes(n) ((n) ? "Yes" : "No"  )
#define yes(n) ((n) ? "yes" : "no"  )

int main(){
  init();
  inl(a,b,c);
  out(21-a-b-c);
  return 0;
}

#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
const vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T>void debag(const vector<T> &a){cerr<<"debag :";for(auto v:a)cerr<<v<<" ";cerr<<"\n";}
template<class T>void print(const vector<T> &a){for(auto v:a)cout<<v<<" ";cout<<"\n";}
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  cout<<21-(a+b+c)<<"\n";
}


#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(long i=0; i<(long)(n);i++)
#define REP(i,s,t) for(long i=s; i<t; i++)
#define RNG(i,s,t,u) for(long i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(){
  string s;
  cin >> s;
  int sum = 0;
  vi cnt(3,0);
  rep(i,s.size()){
    int num = s.at(i) - '0';
    sum += num;
    cnt.at(num % 3)++;
  }

  if(sum % 3 == 0){

    cout << 0 << endl;
    return 0;
  }
  if(s.size() == 1){
    cout << -1 << endl;
    return 0;
  }else if(s.size() == 2){
    if(cnt.at(0) == 0){
      cout << -1 << endl;
    }else{
      cout << 1 << endl;
    }
    return 0;
  }else{
    int a = cnt.at(1);
    int b = cnt.at(2);
    int mini = 10000;
    for(int i=a;i>=0;i-=3){
      for(int j=b;j>=0;j-=3){
        //cout << i << j << endl;
        chmin(mini,abs(i-j));
      }
    }
    cout << mini << endl;
  }

}


#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
using namespace std;

void three(int x, int y, int z,int* hi){
    if(x < y){
        if(x < z){
            return;
        }
        hi[0] = z;
        hi[2] = x;
        return;
    }
    else if(y < z){
        hi[0] = y;
        hi[1] = x;
        return;
    }
    hi[0] = z;
    hi[2] = x;
    return;
}

int equal(const vector<int>a,const vector<int>b,int n){
    for(int i = 0; i < n; i++){
        if(a[i] != b[i]){
            return false;
        }
    }
    return true;
}

int main(){
    vector<vector<vector<int>>> eight(9);
    int a,b,c;
    int e;
    for(int i = 13; i < 125; i++){
        e = 8*i;
        a = e/100;
        e -= a*100;
        b = e/10;
        c = e - b*10;
        if(b > 0 && c > 0){
            int hi[] = {a,b,c};
            eight[hi[0]-1].push_back({hi[1],hi[2]});
            eight[hi[1]-1].push_back({hi[0],hi[2]});
            eight[hi[2]-1].push_back({hi[1],hi[0]});
        }
    }
    string s;
    cin >> s;
    int n = s.length();
    int ans = 0;
    char a_c;
    vector<int> judge(9,1);
    vector<int> owari(9);
    if(n == 1){
        if((int)s[0] % 8 == 0){
            ans = 1;
        }
    }
    else if(n == 2){
        if((10*(int)(s[0]- '0') + (int)(s[1]-'0')) % 8 == 0 || (10*(int)(s[1]-'0') + (int)(s[0]-'0')) % 8 == 0 ){
            ans = 1;
        }
    }
    else{
        int count = 0;
        for(int x = 0; x < n-2; x++){
            a_c = s[x];
            a = (int)(a_c - '0')-1;
            if(judge[a] != 0){
                for(int i = 0; i < eight[a].size(); i++){
                    count = 0;
                    b = eight[a][i][0];
                    c = eight[a][i][1];
                    for(int y = x+1; y < n; y++){
                        int s_y = (int)(s[y] - '0');
                        if(s_y == b){
                            b = 0;
                            count++;
                        }
                        else if(s_y == c){
                            c = 0;
                            count++;
                        }
                        if(count == 2){
                            cout << "Yes" << endl;
                            return 0;
                        }
                    }
                }
            }
            judge[a] = 0;
            if(equal(judge, owari, 9)){
                break;
            }
        }
    }

    if(ans == 0){
        cout << "No" << endl;
    }
    else{
        cout << "Yes" << endl;
    }
    return 0;
}

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

bool f(int i, map<char, int> a){
  string s = to_string(i);
  for(auto c : s){
    if(a[c] == 0) return 0;
    else a[c]--;
  }
  return 1;
}

int main() {
  string s;
  cin >> s;
  int n = s.size();
  map<char, int> a;
  for(auto c : s) a[c]++;
  string ans = "No";
  if(n == 1){
    if(s == "8") ans = "Yes";
  }
  else if(n == 2){
    for(int i = 16; i < 100; i += 8){
      if(f(i,a)) ans = "Yes";
    }
  }
  else {
    for(int i = 104; i < 1000; i += 8){
      if(f(i,a)) ans = "Yes";
    }
  }
  cout << ans << endl;
  return 0;
}


#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <bits/stdc++.h>
#include <queue>
#include <math.h>
#include <bitset>
#include <map>
#include <vector>
#include <cstdio>
#include <climits>
#define white 0
#define gray 1
#define black 2
#define LIMIT (1<<30)
#define MOD 1000000007
#define ll long long
using namespace std;

class DisjointSet{
    public:
        vector<ll> rank, p;
        DisjointSet(){}
        DisjointSet(ll size){
            rank.resize(size, 0);
            p.resize(size, 0);
            for(ll i=0; i<size; i++) makeSet(i);
        }

        void makeSet(ll x){
            p[x]=x;
            rank[x]=0;
        }

        bool same(ll x, ll y){
            return findSet(x) == findSet(y);
        }

        void unite(ll x, ll y){
            link(findSet(x), findSet(y));
        }

        void link(ll x, ll y){
            if(rank[x]>rank[y]){
                p[y]=x;
            }else{
                p[x]=y;

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

        ll findSet(ll x){
            if(x!=p[x]){
                p[x]=findSet(p[x]);
            }

            return p[x];
        }
};

int main(){
    ll n, m;
    cin >> n >> m;
    ll a[n], b[n];
    for(ll i=0; i<n; i++) cin >> a[i];
    for(ll i=0; i<n; i++) cin >> b[i];

    DisjointSet ds = DisjointSet(n + 1);

    for(ll i=0; i<m; i++){
        ll c, d;
        cin >> c >> d;
        ds.unite(c, d);
    }

    map<ll, ll> mpA, mpB;
    for(ll i=1; i<=n; i++){
        mpA[ds.findSet(i)] += a[i - 1];
        mpB[ds.findSet(i)] += b[i - 1];
        //cout << ds.findSet(i) << endl;
    }

    bool ans = true;
    for(auto it = mpA.begin(); it != mpA.end(); it++){
        ll num = it -> first;
        //cout << num << " " << mpA[num] << " " << mpB[num] << endl;
        if(mpA[num] != mpB[num]){
            ans = false;
            break;
        }
    }

    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

#define int long long
#define mod 1000000007
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define pb push_back
#define endl '\n'
vector<int> vis;
vector<vector<int>> g;

int dfs(int u){
	int ans=1;
	vis[u]=1;
	for(auto v:g[u]) if(!vis[v]) ans+=dfs(v);
	return ans;
}
void tests(){
	int n, m;
	cin>>n>>m;

	g.resize(n+1);
	int res=0;
	for(int i=0;i<m;i++){
		int u, v;
		cin>>u>>v;
		g[u].push_back(v);
	}
	for(int i=1;i<=n;i++){
		vis.assign(n+1,0);
		res+=dfs(i);
	}
	cout<<res<<endl;
}
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL) ;
	int t = 1;
	// cin>>t;
	while(t--){
		tests();
	}
 	return 0 ;
}


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

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

  map<int, string> mountain;

  for (int i = 0; i < N; i++) {
    string S;
    int T;
    cin >> S >> T;
    mountain[T] = S;
  }

  auto no2 = mountain.end();
  advance(no2, -2);
  cout << no2->second << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
using ll = long long;
const int INF = 1001001001;
const ll LINF = 1002003004005006007ll;

void solve(){
  int n;
  cin >> n;
  string s;
  int t;
  priority_queue<pair<int,string> > memo;
  rep(i,n){
    cin >> s >> t;
    memo.push(make_pair(t,s));
  }
  memo.pop();
  cout << memo.top().second << endl;
    return;
}

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

  solve();
    return 0;
}


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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;
    X--;
    Y--;
    map<int, vector<tuple<int, int, int>>> mp;
    vector<int> A(M), B(M), T(M), K(M);
    for (int i = 0; i < M; i++) {
        cin >> A[i] >> B[i] >> T[i] >> K[i];
        A[i]--;
        B[i]--;
        mp[A[i]].emplace_back(B[i], T[i], K[i]);
        mp[B[i]].emplace_back(A[i], T[i], K[i]);
    }

    // time, node
    priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> que;
    que.emplace(0, X);
    const ll INF = 1LL << 60;
    vector<ll> used(N, INF);
    used[X] = 0;
    ll ans = -1;
    while (que.size()) {
        ll time;
        int node;
        tie(time, node) = que.top();
        que.pop();
        if (time > used[node]) continue;
        used[node] = true;
        if (node == Y) {
            ans = time;
            break;
        }
        for (auto tp : mp[node]) {
            int nx, cost, mag;
            tie(nx, cost, mag) = tp;
            int dif = (time % mag == 0 ? 0 : mag - time % mag);
            ll reach_time = time + dif + cost;
            if (chmin(used[nx], reach_time)) {
                que.emplace(reach_time, nx);
            }
        }
    }
    cout << ans << endl;

    return 0;
}

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

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

int N,Q;
int C[202020];
map<int,int> M[202020];
int P[202020];

template<int um> class UF {
	public:
	vector<int> par,rank,cnt;
	UF() {par=rank=vector<int>(um,0); cnt=vector<int>(um,1); for(int i=0;i<um;i++) par[i]=i;}
	void reinit() {int i; FOR(i,um) rank[i]=0,cnt[i]=1,par[i]=i;}
	int operator[](int x) {return (par[x]==x)?(x):(par[x] = operator[](par[x]));}
	int count(int x) { return cnt[operator[](x)];}
	int operator()(int x,int y) {
		if((x=operator[](x))==(y=operator[](y))) return x;

		if(cnt[x]<cnt[y]) cnt[y]=cnt[x]+cnt[y]; return par[x]=y;
		cnt[x]=cnt[x]+cnt[y]; return par[y]=x;
	}
};
UF<202020> uf;

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

	cin>>N>>Q;
	FOR(i,N) {
		cin>>C[i+1];
		M[i+1][C[i+1]]=1;
		P[i+1]=i+1;
	}
	while(Q--) {
		cin>>i>>x>>y;
		if(i==1) {
			x=uf[x];
			y=uf[y];
			if(x!=y) {
				uf(x,y);
				i=uf[x];
				j=x+y-i;

				if(M[i].size()<M[j].size()) swap(M[i],M[j]);
				FORR(m,M[j]) M[i][m.first]+=m.second;
			}
		}
		else {
			x=uf[x];
			cout<<M[x][y]<<endl;
		}
	}
}

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


#include <cstdio>
#include <algorithm>

using namespace std;

int a[300000];

int main() {
    int n, k, c, i, j;
    long long ans = 0;

    scanf("%d %d", &n, &k);

    for (i = 0; i < n; i++) scanf("%d", &a[i]);

    sort(a, a + n);

    c = k;

    for (i = 0, j = 0; ; i++) {
        int x = 0;

        while (j < n && a[j] == i) {
            x++;
            j++;
        }

        if (x < c) {
            ans += (long long)i * (c - x);

            c = x;
        }

        if (c == 0) break;
    }

    printf("%lld\n", ans);

    return 0;
}

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

class UnionFind {
public:
	UnionFind(int n) : par(n), rank(n, 0) {
		for (int i = 0; i < n; ++i) {
			par[i] = i;
		}
	}

	int root(int x) {
		return par[x] == x ? x : par[x] = root(par[x]);
	}

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

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

		if (rank[x] < rank[y]) {
			par[x] = y;
		}
		else {
			par[y] = x;
			if (rank[x] == rank[y]) {
				++rank[x];
			}
		}
	}
private:
	vector<int> par, rank;
};

const int MAX = 200001;

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

	vector<int> v(n);
	for (auto& nx : v) {
		cin >> nx;
	}

	UnionFind uf(MAX);
	for (int i = 0; i < n / 2; ++i) {
		uf.unite(v[i], v[n - 1 - i]);
	}

	int ans = 0;
	for (int j = 0; j < MAX; ++j) {
		if (uf.root(j) != j) {
			++ans;
		}
	}
	cout << ans << endl;
	return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <iomanip>
#include <set>
using ll = long long;
const double PI = 3.1415926535897932;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main()
{
    int n, m, t;
    int a[1010];
    int b[1010];

    cin >> n >> m >> t;

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

    b[0] = 0;
    bool bat = true;
    int battery = n;
    for(int j = 1; j <= m; j++)
    {
        battery -= a[j] - b[j - 1]; if(battery <= 0) bat = false;
        battery += b[j] - a[j]; if(battery > n) battery = n;
    }
    battery -= t - b[m]; if(battery <= 0) bat = false;

    if(bat) cout << "Yes" << endl;
    else cout << "No" << endl;
}

//debug icin gdb kullanmayi dene
#include<bits/stdc++.h>
using namespace std;
#define mods 1000000007
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define rs resize
#define pii pair<lint,lint>
#define piii pair<lint,pair<lint,lint> >
#define inf LLONG_MAX-7
#define vvL vector<vector<lint> >
#define vvB vector<vector<bool> >
#define vvvL vector<vector<vector<lint> > >
#define vL vector<lint>
#define vB vector<bool>
typedef long long int lint;
typedef unsigned long long int ulint;
lint fastpow(lint tab,lint us){
	if(tab==0) return 0;
	if(tab==1) return 1;
	if(us==0) return 1;
	if(us==1) return tab%mods;
	tab%=mods;
	if(us%2==1) return tab*fastpow(tab,us-1)%mods;
	lint a=fastpow(tab,us/2)%mods;
	return a*a%mods;
}
lint t=1;

void solve(){
	lint l=0,a,b,i,j,k,n,m,T,sum;
	cin>>n>>m>>T;
	sum=n;
	for(i=0;i<m;i++){
		cin>>a;
		n-=a-l;
		if(n<=0){cout<<"No"<<endl; return;}
		cin>>b;
		n+=b-a;
		n=fmin(n,sum);
		l=b;
	}
	n-=T-l;
	if(n<=0){cout<<"No"<<endl; return;}
	cout<<"Yes"<<endl;
	return;
}

int main(){
//	freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
//	cin>>t;
	while(t--) solve();
	return 0;
}


#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef __int128 it;
typedef long double ldb;
int main(){
	ll s,p;
	scanf("%lld%lld",&s,&p);
	it sqt=it(s)*s-it(p<<2);
//	if(p*4<(s*2-1)){
//		puts("No");
//		return 0;
//	}
	ldb tmp=sqrt(ldb(s)*s-(p<<2));
	for(it i=max(tmp-1000000,ldb(0)),ed=tmp+1000000; i<=ed; ++i)
		if(i*i==sqt){
			if((i+s)&1){
				puts("No");
				return 0;
			}
			puts("Yes");
			return 0;
		}
	puts("No");
	return 0;
}

/*
Author: QAQAutoMaton
Lang: C++
Code: A.cpp
Mail: lk@qaq-am.com
Blog: https://www.qaq-am.com/
*/
#include<bits/stdc++.h>
#define int long long
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define DEBUG printf("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define Debug debug("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define all(x) x.begin(),x.end()
#define x first
#define y second
using namespace std;
typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef complex<double> cp;
typedef pair<int,int> pii;
int inf;
const double eps=1e-8;
const double pi=acos(-1.0);
template<class T,class T2>int chkmin(T &a,T2 b){return a>b?a=b,1:0;}
template<class T,class T2>int chkmax(T &a,T2 b){return a<b?a=b,1:0;}
template<class T>T sqr(T a){return a*a;}
template<class T,class T2>T mmin(T a,T2 b){return a<b?a:b;}
template<class T,class T2>T mmax(T a,T2 b){return a>b?a:b;}
template<class T>T aabs(T a){return a<0?-a:a;}
template<class T>int dcmp(T a,T b){return a>b;}
template<int *a>int cmp_a(int x,int y){return a[x]<a[y];}
template<class T>bool sort2(T &a,T &b){return a>b?swap(a,b),1:0;}
#define min mmin
#define max mmax
#define abs aabs
struct __INIT__{
	__INIT__(){
		fill((unsigned char*)&inf,(unsigned char*)&inf+sizeof(inf),0x3f);
	}
}__INIT___;
namespace io {
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	// getchar
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	// print the remaining part
	inline void flush () {
		fwrite (obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	// putchar
	inline void putc (char x) {
		*oS ++ = x;
		if (oS == oT) flush ();
	}
	template<typename A>
	inline bool read (A &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;else if(c==EOF)return 0;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = x * 10 + (c & 15); x *= f;
		return 1;
	}
	inline bool read (char &x) {
		while((x=gc())==' '||x=='\n' || x=='\r');
		return x!=EOF;
	}
	inline bool read(char *x){
		while((*x=gc())=='\n' || *x==' '||*x=='\r');
		if(*x==EOF)return 0;
		while(!(*x=='\n'||*x==' '||*x=='\r'||*x==EOF))*(++x)=gc();
		*x=0;
		return 1;
	}
	template<typename A,typename ...B>
	inline bool read(A &x,B &...y){
		return read(x)&&read(y...);
	}
	template<typename A>
	inline bool write (A x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
		return 0;
	}
	inline bool write (char x) {
		putc(x);
		return 0;
	}
	inline bool write(const char *x){
		while(*x){putc(*x);++x;}
		return 0;
	}
	inline bool write(char *x){
		while(*x){putc(*x);++x;}
		return 0;
	}
	template<typename A,typename ...B>
	inline bool write(A x,B ...y){
		return write(x)||write(y...);
	}
	//no need to call flush at the end manually!
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io :: read;
using io :: putc;
using io :: write;
signed main(){
#ifdef QAQAutoMaton
	freopen("A.in","r",stdin);
	freopen("A.out","w",stdout);
#endif
	int s,p;
	read(s,p);
	for(int i=1;i*i<=p;++i)if(!(p%i)){
		if(i+p/i==s)return write("Yes\n");
	}
	return write("No\n");
}


#line 1 "A.cpp"
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

#if defined(DONLINE_JUDGE)
	#define NDEBUG
#elif defined(ONLINE_JUDGE)
	#define NDEBUG
#endif

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

int main() {
	int x, y, z; scanf("%d%d%d", &x, &y, &z);

//	cout << "test" << endl;

	for(int i = 1e6; i >= 0; i--) {
		if(y * z <= x * i) continue;
		printf("%d\n", i);
		return 0;
	}
	return 0;
}

//#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <map>
#include <vector>

using namespace std;
typedef long long ll;
//typedef vector<long long> vll;

#define rep(i,n)      for(long long(i)=0;(i)<(n);(i)++)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

int main(){

    double x,y,z;
    cin >> x >> y >> z;

    cout << (long)((y * z - 1) / x) << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template<class T> bool chmin(T& a,T b){if(a>b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b){if(a<b) {a = b; return true;} return false;}
#define rep(i,n) for(int i=0;i<(n);i++)
#define drep(i,n) for(int i=(n)-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define debug(x)  cerr << #x << " = " << (x) << endl;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H,W;
    cin >> H >> W;
    vvec<char> S(H,vec<char>(W));
    rep(i,H) rep(j,W) cin >> S[i][j];
    int ans = 0;
    rep(i,H-1) rep(j,W-1){
        int c = 0;
        rep(a,2) rep(b,2) c += S[i+a][j+b];
        if(c%2) ans++;
    }
    cout << ans << "\n";
}

#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define u unsigned
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mod 1000000007
#define f(i,n) for(int i=0;i<n;i++)
#define f1(i,n) for(int i=1;i<n;i++)
#define in(i,arr) for(auto &i:arr)cin>>i;
#define out(i,arr) for(auto &i:arr)cout<<i<<" ";
#define all(x) (x).begin(), (x).end()
#define vpii vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define eb empalce_back
#define fe first
#define se second
#define uset unordered_set
#define umap unordered_map

template <typename T>
ll powe(T base, T to){ll ans=1;while(to>0){if (to & 1)ans =(ans*base)%mod, to--;else base = (base*base)%mod, to /= 2;}return ans;}
ll gcd(ll a,ll b){return (b==0)?a:gcd(b,a%b);}
bool prime(ll n){if(n==1)return 0;for(ll i=2;i*i<=n;i++)if(n%i==0)return 0;return 1;}

int main() {
    fast;
    int tl = 1;
    //cin>>tl;
    while (tl--) {
        int h, w;
        cin >> h >> w;
        char mat[h][w];
        f(i, h)f(j, w)cin >> mat[i][j];
        int ans = 0;
        f(i, h)
            f(j, w) {
                if (mat[i][j] == '#' && mat[i][j - 1] == '.') {
                    if ((mat[i - 1][j] != mat[i][j]) || (mat[i - 1][j - 1] == '#'))
                        ans++;
                }
            }
        f(j, w)
            f(i, h) {
                if (mat[i][j] == '#' && mat[i][j - 1] == '.') {
                    if ((mat[i - 1][j] != mat[i][j]) || (mat[i - 1][j - 1] == '#'))
                        ans++;
                }
            }
//            cout<<ans<<" ";
        f(i, h / 2)f(j, w) {
                swap(mat[i][j], mat[h - i - 1][j]);

            }
        f(j, w / 2)f(i, h) {
                swap(mat[i][j], mat[i][w - j - 1]);

            }

//        f(i,h)
//        {
//            f(j,w)cout<<mat[i][j];
//            cout<<"\n";
//        }
        f(i, h)
            f(j, w) {
                if (mat[i][j] == '#' && mat[i][j - 1] == '.') {
                    if ((mat[i - 1][j] != mat[i][j]) || (mat[i - 1][j - 1] == '#'))
                        ans++;
                }
            }
        f(j, w)
            f(i, h) {
                if (mat[i][j] == '#' && mat[i][j - 1] == '.') {
                    if ((mat[i - 1][j] != mat[i][j]) || (mat[i - 1][j - 1] == '#'))
                        ans++;
                }
            }
        cout << ans;
    }
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N;
    cin >> N;
    map<ll,ll> A;
    REP(i,0,N) {
        ll a;
        cin >> a;
        ++A[a%200];
    }

    ll cnt = 0;
    FORR(a,A) cnt += a.second * (a.second - 1) / 2;
    PR(cnt);

    return 0;
}

/*

*/

#include <bits/stdc++.h>
#define int long long
using namespace std;
#define se second
#define fi first
#define M 1e9+7
#define N 1e9

double dp[102][102][102];

void F(){
	int a, b, c;
	cin >> a >> b >> c;
	for(int i = 100; i >= a; i--){
		for(int j = 100; j >= b; j--){
			for(int k = 100; k >= c; k--){
				if(i == 100 || j == 100 || k == 100){
					dp[i][j][k] = 0;
					continue;
				}
				double w = i + j + k, x = i, y = j, z = k;
				dp[i][j][k] += (dp[i+1][j][k] + 1) * x / w;
				dp[i][j][k] += (dp[i][j+1][k] + 1) * y / w;
				dp[i][j][k] += (dp[i][j][k+1] + 1) * z / w;
			}
		}
	}
	cout << fixed << setprecision(12) << dp[a][b][c];
}

signed main() {
	int T = 1;
	//cin >> T;
	for(int X = 1; X <= T; X++){
		F();
	}
}


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

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#define F first
#define S second
#define all(x) begin(x), end(x)
#define allr(x) rbegin(x), rend(x)
using ll = long long;
using ull = unsigned long long;
using ld = long double;
constexpr ll INF = 2e18;
constexpr ld EPS = 1e-9;
constexpr int MOD = 1e9 + 7;
#define int long long

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

	size_t operator()(uint64_t x) const
	{
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(x + FIXED_RANDOM);
	}
};
// Use int type for keys
template <typename T1, typename T2>
using safe_map = unordered_map<T1, T2, custom_hash>;

// Operator overloads
// cin >> pair<T1, T2>
template<typename T1, typename T2>
istream& operator>>(istream &istream, pair<T1, T2> &p)
{
    istream >> p.first >> p.second;
    return istream;
}
// cin >> vector<T>
template<typename T>
istream& operator>>(istream &istream, vector<T> &v)
{
    for (auto &it : v) cin >> it;
    return istream;
}
// cout << pair<T1, T2>
template<typename T1, typename T2>
ostream& operator<<(ostream &ostream, const pair<T1, T2> &p)
{
    ostream << p.first << " " << p.second;
    return ostream;
}
// cout << vector<T>
template<typename T>
ostream& operator<<(ostream &ostream, const vector<T> &c)
{
    for (auto &it : c) cout << it << " ";
    return ostream;
}

// Utility functions
template <typename T>
void print(T &&t)
{
    cout << t << "\n";
}
template <typename T, typename... Args>
void print(T &&t, Args &&... args)
{
	cout << t << " ";
	print(forward<Args>(args)...);
}

template <typename T>
int32_t size_i(T &container) { return static_cast<int32_t>(container.size()); }

// Mathematical functions
int GCD(int a, int b)
{
	if (!b) return a;
	return GCD(b, a % b);
}
int LCM(int a, int b)
{
	return (a * b) / GCD(a, b);
}
int modpow(ll x, int n, int m = MOD) {
    ll res = 1;
    while (n > 0)
	{
        if (n & 1)
            res = (res * x) % m;
        x = (x * x) % m;
        n >>= 1;
    }
    return res;
}

int binpow(int x, int n) {
    int res = 1;
    while (n > 0)
	{
        if (n & 1)
            res = res * x;
        x = (x * x);
        n >>= 1;
    }
    return res;
}
// @param m should be prime
int modinv(int x, int m = MOD)
{
	return modpow(x, m - 2, m);
}

// Flags to use: -std=c++17 -O2 -Wshadow -DLOCAL_PROJECT -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -fsanitize=address -fsanitize=undefined
////////////////////////////////// START CODE HERE //////////////////////////////////

void preSolve()
{
}

void solve(int tc)
{
    int a, b;
    cin >> a >> b;
    int ans = 1;
    for (int i = 2; i <= 1e5; i++)
    {
        int y = (b / i) * i;
        int x = (a / i) * i;
        if (x < a) x += i;
        if (x < y) ans = i;
    }
    print(ans);
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(0);
    cout << setprecision(12) << fixed;

    preSolve();
    int tests = 1;
    // cin >> tests;
    for (int t = 1; t <= tests; t++)
        solve(t);
    return 0;
}

#include<bits/stdc++.h>

using namespace std;

int main()
{
    int a,b;
    cin>>a>>b;
    int l = b - a;
    for (int i = l; i >= 1; i--)
    {
        int x = (a+i-1)/i;
        if (b-x*i>=i)
        {
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<a<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double lf;

// #define int ll
#define FOR(i, f, t) for (int i = (f), ed##i = (t); i <= ed##i; ++i)
#define ROF(i, t, f) for (int i = (t), ed##i = (f); i >= ed##i; --i)
#define DBG(x) (cerr << "(dbg) " << #x " = " << (x) << '\n')
#define FIO(x) (freopen(x ".in", "r", stdin), freopen(x ".out", "w", stdout))
#define y1 y1__

// clang-format off
struct Reader{template<class T>Reader&operator()(T&x){x=0;T f=1;char ch=getchar();while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();x*=f;return*this;}ll operator()(){ll x;operator()(x);return x;}Reader&operator()(char*x){scanf("%s",x);return*this;}template<class T>Reader&operator()(vector<T>&v,int n){T x;FOR(i,1,n){operator()(x),v.push_back(x);}return*this;}template<class T>Reader&operator()(T*x,int n,int st=1){FOR(i,st,n){operator()(x[i]);}return*this;}}in;template<class T>T Abs(const T&a){return a>0?a:-a;}template<class T>void Up(T&a,const T&b){b>a&&(a=b);}template<class T>void Down(T&a,const T&b){b<a&&(a=b);}template<class T,size_t E>void Fill(T(&a)[E],const int&x){memset(a,x,E*sizeof(*a));}ll Pow(ll a,ll b,const ll&m){ll res=1;a%=m;while(b>0){if(b&1)res=res*a%m;a=a*a%m,b>>=1;}return res;}template<class T>T Gcd(T a,T b){T t;while(b!=0)t=a%b,a=b,b=t;return a;}
// clang-format on

const int N = 2e6 + 5;

typedef pair<int, int> pii;

int n, m, q, x[N], rn[N];
pii a[N];
bitset<N> ban;

void Solve(int l, int r) {
  ban.reset();
  int ans = 0;
  FOR (i, l, r) { ban[i] = 1; }
  FOR (i, 1, n) {
    FOR (j, 1, m) {
      if (!ban[rn[j]] && x[rn[j]] >= a[i].first) {
        // cerr << "put " << i << " to " << j << '\n';
        ban[rn[j]] = 1;
        ans += a[i].second;
        break;
      }
    }
  }
  // cerr << "end\n";
  cout << ans << '\n';
}

signed main() {
  in(n)(m)(q);
  FOR (i, 1, n) { in(a[i].first)(a[i].second); }
  sort(a + 1, a + 1 + n, [](pii a, pii b) { return a.second > b.second; });
  in(x, m);
  FOR (i, 1, m) { rn[i] = i; }
  sort(rn + 1, rn + 1 + m, [](int a, int b) { return x[a] < x[b]; });
  FOR (_, 1, q) {
    int l = in(), r = in();
    Solve(l, r);
  }
  return 0;
}

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

int main() {
    int n, m, q;
    cin >> n >> m >> q;
    int x[m];
    vector<pair<int, int>> vw(n);
    rep(i, 0, n) {
        int w, v;
        cin >> w >> v;
        vw[i].first = v, vw[i].second = w;
    }
    rep(i, 0, m) cin >> x[i];
    sort(vw.rbegin(), vw.rend());

    auto query = [&](int l, int r) {
        vector<int> tmpm;
        rep(i, 0, m) {
            if (l <= i && i < r) continue;
            tmpm.push_back(x[i]);
        }
        sort(tmpm.begin(), tmpm.end());

        bool conf[n] = { 0 };
        int res = 0;
        for (auto t : tmpm) {
            int maxv = 0;
            rep(i, 0, n) {
                if (vw[i].second > t || conf[i]) continue;
                maxv = max(maxv, vw[i].first);
                conf[i] = true;
                break;
            }
            res += maxv;
        }
        return res;
    };

    rep(i, 0, q) {
        int l, r;
        cin >> l >> r;
        cout << query(l - 1, r) << endl;
    }

}


#include <bits/stdc++.h>
#define REP(i, nn ) for(int i = 0 ; i < (int) nn; i++)
#define REPS(i, ss, nn ) for(int i = ss ; i < (int) nn; i++)
#define REV(i, ss, nn ) for(int i = ss ; i >= nn; i--)
#define deb(x) std::cout << #x << " " << x << endl;
#define debl(x) std::cout << #x << " " << x << " ";
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
namespace std{
    template<class Fun>
    class y_combinator_result{
        Fun fun_;
        public:
            template<class T>
            explicit y_combinator_result(T &&fun) : fun_(std::forward<T>(fun)){}
            template<class ...Args>
            decltype(auto) operator()(Args&&...args){
                return fun_(std::ref(*this), std::forward<Args>(args)...);
            }
    };
    template<class Fun>
    decltype(auto) y_combinator(Fun && fun){
        return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));
    }
};
template<typename T>
bool u_max(T& a, T b){
    if( a < b){
        a = b;
        return true;
    }
    return false;
}
template<typename T>
bool u_min(T& a, T b){
    if( a > b){
        a = b;
        return true;
    }
    return false;
}
struct edge{
    int to, from;
    // ll cost;
    edge(){ edge(0,0);}
    // edge(int to_, ll cost_){ edge(to_, -1, cost_);}
    // edge(int to_, int from_, ll cost_) : to(to_), from(from_), cost(cost_){}
    edge(int to_, int from_) : to(to_), from(from_){};
};

template<typename... T>
void read(T& ... a){
    ((cin >> a),...);
}

void dfs(int node, int par, vector<vector<int>>& adj, vector<int>& parent){
    parent[node] = par;
    for(const auto & vert : adj[node]){
        if(vert == par) continue;
        dfs(vert, node, adj, parent);
    }
}

void summary(int node, int par, ll acc, vector<vector<int>>& adj, vector<ll>& add, vector<ll>& results){
    results[node] += acc;
    for(const auto & vert : adj[node]){
        if(vert == par) continue;
        summary(vert, node,  acc + add[vert], adj, add, results);
    }
}

void solve(){
    int n;
    read(n);
    vector<edge> edges(n);
    vector<vector<int>> adj(n);
    REP(i, n - 1){
        int a, b;
        read(a, b);
        a--; b--;
        edges[i].from = a;
        edges[i].to = b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    vector<int> parent(n, -1);
    int root = 0;
    dfs(root, -1, adj, parent);
    // cout << "dfs done" << endl;
    vector<ll> add(n);
    int q;
    read(q);
    REP(i, q){
        int t, e, x;
        read(t,e, x);
        e--;
        int a = edges[e].from;
        int b = edges[e].to;
        if(t == 2){
            swap(a, b);
        }
        //apply left a but not right b
        if( a == parent[b]){
            add[root] += x;
            add[b] -= x;
        }else{
            add[a] += x;
        }
    }
    vector<ll> results(n);
    summary(root, -1, add[0], adj, add, results);
    REP(i, n){
        cout << results[i] << "\n";
    }
}

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/
    solve();
    return 0;
}

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

#define int long long
#define fi first
#define se second
#define pb push_back

int n,query,i,a[200010],b[200010],dis[200010],c[200010],e,x,s,t;
bool vis[200010];
vector<int> adj[200010];
queue<int> q;

signed main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin>>n;
	for (i=1;i<n;i++) cin>>a[i]>>b[i];
	for (i=1;i<n;i++) {adj[a[i]].pb(b[i]);adj[b[i]].pb(a[i]);}

	for (i=1;i<n+1;i++) vis[i]=false;
	dis[1]=0;vis[1]=true;q.push(1);
	while (!q.empty())
	{
		s=q.front();q.pop();
		for (auto u:adj[s])
		{
			if (vis[u]) continue;
			vis[u]=true;
			dis[u]=dis[s]+1;
			q.push(u);
		}
	}

	for (i=1;i<n+1;i++) c[i]=0;s=0;
	cin>>query;
	for (i=1;i<query+1;i++)
	{
		cin>>t>>e>>x;
		if (t==2) swap(a[e],b[e]);
		if (dis[a[e]]>dis[b[e]]) c[a[e]]=c[a[e]]+x;
		else
		{
			s=s+x;c[b[e]]=c[b[e]]-x;
		}
		if (t==2) swap(a[e],b[e]);
	}

	t=s;

	for (i=1;i<n+1;i++) vis[i]=false;
	dis[1]=c[1];q.push(1);vis[1]=true;
	while (!q.empty())
	{
		s=q.front();q.pop();
		for (auto u:adj[s])
		{
			if (vis[u]) continue;
			vis[u]=true;
			dis[u]=dis[s]+c[u];
			q.push(u);
		}
	}
	for (i=1;i<n+1;i++) dis[i]=dis[i]+t;
	for (i=1;i<n+1;i++) cout<<dis[i]<<"\n";
}