#include <bits/stdc++.h>

#define debug(x) cerr << #x << " = " << x << endl

using namespace std;
typedef long long LL;

template <class T>
void read(T& x) {
    x = 0;
    T f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') f = (ch == '-' ? -1 : 1), ch = getchar();
    while (ch >= '0' && ch <= '9') x = x * 10 + ch - 48, ch = getchar();
    x *= f;
}

template <class T, class... Args>
void read(T& x, Args&... args) {
    read(x), read(args...);
}

template <class T>
void write(T x) {
    if (x < 0) putchar('-'), x = -x;
    if (x > 9) write(x / 10);
    putchar(x % 10 + '0');
}

const int MAXN = 2E5 + 5;
const int MOD = 1E9 + 7;
int n, m, q, a[MAXN], b[MAXN];

struct Node {
    int lson, rson, cnt;
    LL sum;
    Node() { cnt = sum = lson = rson = 0; }
} tr[MAXN * 80];

int roota, rootb;

int newNode() {
    static int cntNode = 1;
    return cntNode++;
}

void update(int cur) {
    tr[cur].cnt = tr[tr[cur].lson].cnt + tr[tr[cur].rson].cnt;
    tr[cur].sum = tr[tr[cur].lson].sum + tr[tr[cur].rson].sum;
}

void modify(int cur, int L, int R, int x, bool tag) {
    if (x == L && x == R) {
        if (tag == 0) {
            tr[cur].sum -= x;
            tr[cur].cnt--;
        } else {
            tr[cur].sum += x;
            tr[cur].cnt++;
        }
        return;
    }
    int mid = L + R >> 1;
    if (!tr[cur].lson) tr[cur].lson = newNode();
    if (!tr[cur].rson) tr[cur].rson = newNode();
    if (x <= mid)
        modify(tr[cur].lson, L, mid, x, tag);
    else
        modify(tr[cur].rson, mid + 1, R, x, tag);
    update(cur);
}

LL qsum(int cur, int L, int R, int l, int r) {
    if (!cur) return 0;
    if (l == L && r == R) return tr[cur].sum;
    int mid = L + R >> 1;
    if (r <= mid)
        return qsum(tr[cur].lson, L, mid, l, r);
    else if (l > mid)
        return qsum(tr[cur].rson, mid + 1, R, l, r);
    else
        return qsum(tr[cur].lson, L, mid, l, mid) +
               qsum(tr[cur].rson, mid + 1, R, mid + 1, r);
}

int qcnt(int cur, int L, int R, int l, int r) {
    if (!cur) return 0;
    if (l == L && r == R) return tr[cur].cnt;
    int mid = L + R >> 1;
    if (r <= mid)
        return qcnt(tr[cur].lson, L, mid, l, r);
    else if (l > mid)
        return qcnt(tr[cur].rson, mid + 1, R, l, r);
    else
        return qcnt(tr[cur].lson, L, mid, l, mid) +
               qcnt(tr[cur].rson, mid + 1, R, mid + 1, r);
}

signed main() {
    // freopen("1.in", "r", stdin);
    read(n, m, q);
    roota = newNode();
    rootb = newNode();
    LL ans = 0;
    for (int i = 1; i <= q; i++) {
        int t, x, y;
        read(t, x, y);
        if (t == 1) {
            int pre = a[x];
            a[x] = y;
            LL presum = qsum(rootb, 0, 1E8, pre, 1E8) +
                        1ll * (m - qcnt(rootb, 0, 1E8, pre, 1E8)) * pre;
            LL cursum = qsum(rootb, 0, 1E8, y, 1E8) +
                        1ll * (m - qcnt(rootb, 0, 1E8, y, 1E8)) * y;
            modify(roota, 0, 1E8, y, 1);
            modify(roota, 0, 1E8, pre, 0);
            ans = ans - presum + cursum;
        } else {
            int pre = b[x];
            b[x] = y;
            LL presum = qsum(roota, 0, 1E8, pre, 1E8) +
                        1ll * (n - qcnt(roota, 0, 1E8, pre, 1E8)) * pre;
            LL cursum = qsum(roota, 0, 1E8, y, 1E8) +
                        1ll * (n - qcnt(roota, 0, 1E8, y, 1E8)) * y;
            modify(rootb, 0, 1E8, y, 1);
            modify(rootb, 0, 1E8, pre, 0);
            ans = ans - presum + cursum;
        }
        printf("%lld\n", ans);
    }

    return 0;
}

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

int main(){
  int a, b; cin >> a >> b;
  long long k; cin >> k;
  vector<vector<long long>> s(a+1, vector<long long>(b+1));
  for(int i = a; i >= 0; i--){
  	for(int j = b; j >= 0; j--){

    	if(i==a || j==b) s[i][j] = 1;

    	else{
        	s[i][j] = s[i+1][j] + s[i][j+1];
        }
    }
  }

  string ans;
  long long min = 0;
  int i = 0, j = 0;
  for(int p = 0; p < a+b; p++){
  	if(i==a){
    	ans += 'b';
    	continue;
    }
  	if(j==b){
    	ans += 'a';
    	continue;
    }

  	if(k <= min + s[i+1][j]){
    	ans += 'a';
      	i++;
    }

  	else{
    	ans += 'b';
      	min += s[i+1][j];
      	j++;
    }

    //cout << min << endl;
  }

  cout << ans << endl;

  /*for(int x = 0; x <= a; x++){
  for(int y = 0; y <= b; y++){
  	cout << s[x][y] << " ";}
  cout << endl;
  }*/
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define abs(x)(x<0 ? -x : x)

int main(){
    int x,y,a,b;
    cin>>x>>y>>b>>a;
    int t;
    if(2*b<a){
        a=2*b;
    }
    if(y>x){
        cout<<(a*(y-x))+b;
    }else if(x-y<2){
        cout<<b;
    }else{
        cout<<(a*(x-y-1))+b;
    }
}

#include<bits/stdc++.h>
using namespace std;
#define ALL(x) begin(x),end(x)
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define mod 1000000007
using ll=long long;
const int INF=1000000000;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

struct IOSetup{
    IOSetup(){
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(12);
    }
} iosetup;

template<typename T>
ostream &operator<<(ostream &os,const vector<T>&v){
    for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==(int)v.size()?"":" ");
    return os;
}
template<typename T>
istream &operator>>(istream &is,vector<T>&v){
    for(T &x:v)is>>x;
    return is;
}

template<typename T>
vector<T> dijkstra(int s,vector<vector<pair<int,T>>> &G){
    const T TINF=numeric_limits<T>::max();
    using P=pair<T,int>;
    int n=G.size();
    vector<T> d(n,TINF);
    vector<int> b(n,-1);//previous point
    priority_queue<P,vector<P>,greater<P>> q;
    d[s]=0;
    q.emplace(d[s],s);
    while(!q.empty()){
        P p=q.top();q.pop();
        int v=p.second;
        if(d[v]<p.first) continue;
        for(auto& e:G[v]){
            int u=e.first;
            T c=e.second;
            if(d[u]>d[v]+c){
                d[u]=d[v]+c;
                b[u]=v;
                q.emplace(d[u],u);
            }
        }
    }
    return d;
}

signed main(){

    int a,b,x,y;cin>>a>>b>>x>>y;a--,b--;
    int n=100;
    vector<vector<pair<int,ll>>> g(2*n);
    rep(i,n){
        g[i].emplace_back(i+n,x);
        g[i+n].emplace_back(i,x);
        if(i+1<n){
        g[i+1].emplace_back(i+n,x);
        g[i+n].emplace_back(i+1,x);
        g[i].emplace_back(i+1,y);
        g[i+1].emplace_back(i,y);
        g[i+n].emplace_back(i+1+n,y);
        g[i+1+n].emplace_back(i+n,y);
        }
    }

    auto d=dijkstra(a,g);
    cout<<d[b+n]<<endl;
    return 0;
}


#include "bits/stdc++.h"
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

typedef long long ll;
typedef string str;
typedef double db;
typedef long double ld;
typedef pair<int, int> pi;
#define fi first
#define se second

#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define endl "\n"

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

const ll MOD = 1e9 + 7; //998244353
const ll INF = 1e18;
const ll MX = 1e9 + 10;
const int nx[4] = {0, 0, 1, -1}, ny[4] = {1, -1, 0, 0}; //right left down up

#ifndef LOCAL
#define cerr if(false) cerr
#endif
#define debug(x) cerr << #x << " : " << x << endl;
#define debugs(x,y) cerr << #x << " : " << x << " / " << #y << " : " << y << endl;
#define debugv(v) cerr << #v << " : " << "[ "; for(auto it : v) cerr << it << ' '; cerr << ']' << endl;
#define here() cerr << "here" << endl;

void IO() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

ll solve(ll n)
{
    return n*(n-1)/2;
}
int main()
{
    boost;
    IO();

    ll n;
    cin >> n;
    vector<ll> arr(n);

    FOR(i, 0, n)
    {
        cin >> arr[i];
        arr[i]%=200;
    }

    vector<ll> vis(200, 0);
    vector<ll> res;

    FOR(i, 0, n)
    {
        vis[arr[i]]++;
    }

    FOR(i, 0, 200)
    {
        if(vis[i]>0)
            res.pb(vis[i]);
    }

    ll sum = 0;
    ll len = res.size();
    FOR(i, 0, len)
    {
        ll temp = res[i];
        sum+=solve(temp);
    }

    cout << sum << endl;

    return 0;
}

#include <bits/stdc++.h>

using namespace std;

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

using ll = long long;
using ld = long double;

#define mp make_pair

int p = 1e9 + 7;

int mul(int a, int b) {
    return (1LL * a * b) % p;
}

int add(int a, int b) {
    int s = (a+b);
    if (s>=p) s-=p;
    return s;
}

int sub(int a, int b) {
    int s = (a+p-b);
    if (s>=p) s-=p;
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int inv(int n)
{
    return po(n, p-2);
}

mt19937 rnd(time(0));

const int N = 1000005;

vector<int> facs(N), invfacs(N);

void init()
{
    facs[0] = 1;
    for (int i = 1; i<N; i++) facs[i] = mul(facs[i-1], i);
    invfacs[N-1] = inv(facs[N-1]);
    for (int i = N-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1);
}

int C(int n, int k)
{
    if (n<k) return 0;
    if (n<0 || k<0) return 0;
    return mul(facs[n], mul(invfacs[k], invfacs[n-k]));
}

/*struct DSU
{
    vector<int> sz;
    vector<int> parent;

    void make_set(int v) {
        parent[v] = v;
        sz[v] = 1;
    }

    int find_set(int v) {
        if (v == parent[v])
            return v;
        return parent[v] = find_set(parent[v]);
    }

    void union_sets(int a, int b) {
        a = find_set(a);
        b = find_set(b);
        if (a != b) {
            if (sz[a] < sz[b])
                swap(a, b);
            parent[b] = a;
            sz[a] += sz[b];
        }
    }

    DSU (int n)
    {
        parent.resize(n);
        sz.resize(n);
        for (int i = 0; i<n; i++) make_set(i);
    }
};*/

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

    int n; cin>>n;
    string s;
    cin>>s;
    vector<char> a(2e5);
    int cur = 0;
    for (auto c: s)
    {
        a[cur] = c;
        if (cur>=2 && a[cur-2]=='f' && a[cur-1]=='o' && a[cur]=='x') cur-=3;
        cur++;
    }
    cout<<cur;
}


#include <bits/stdc++.h>

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

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

  int n;
  cin >> n;
  vector<int> as(n), bs(n), ps(n);
  for (int i = 0; i < n; i++) {
    cin >> as[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> bs[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> ps[i];
    ps[i]--;
  }

  for (int i = 0; i < n; i++) {
    if (i != ps[i] && as[i] <= bs[ps[i]]) {
      cout << -1 << endl;
      return 0;
    }
  }

  vector<int> used(n);
  vector<tuple<int, int>> outputs;
  for (int i = 0; i < n; i++) {
    if (i == ps[i]) {
      continue;
    }
    if (used[i]) {
      continue;
    }
    vector<int> cycle;
    int current = i;
    while (true) {
      if (used[current]) break;
      used[current] = true;
      cycle.push_back(current);
      current = ps[current];
    }
    reverse(cycle.begin(), cycle.end());

    int min_b = INT_MAX;
    int min_b_arg = -1;
    for (int j = 0; j < cycle.size(); j++) {
      if (bs[ps[cycle[j]]] < min_b) {
        min_b = bs[ps[cycle[j]]];
        min_b_arg = j;
      }
    }

    for (int j = 0; j + 1 < cycle.size(); j++) {
      int k1 = cycle[(j + min_b_arg) % cycle.size()];
      int k2 = cycle[(j + min_b_arg + 1) % cycle.size()];
      outputs.push_back({k1, k2});
    }
  }
  cout << outputs.size() << endl;
  for (const auto [k1, k2] : outputs) {
    cout << k1 + 1 << " " << k2 + 1 << "\n";
  }
}

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = false;
//---------------------------------//

int main() {
	int N;
	cin >> N;
	vector<int> A(N), B(N), P(N);
	REP(i, N) scanf("%d", &A[i]);
	REP(i, N) scanf("%d", &B[i]);
	REP(i, N) scanf("%d", &P[i]), --P[i];
	vector<pii> ans;

	auto P2 = P;

	vector<bool> done(N, false);
	vector<int> prv(N, -1);
	REP(i, N) {
		if (done[i]) continue;
		if (P[i] == i) continue;
		vector<int> g;
		g.emplace_back(i);
		int pos = P[i];
		while (pos != i) {
			g.emplace_back(pos);
			pos = P[pos];
		}

		for (int p : g) {
			if (A[p] <= B[P[p]]) {
				puts("-1");
				return 0;
			}
			prv[P[p]] = p;
		}

		set<int> ss;
		for (int p : g) if (A[p] > B[P[P[p]]]) ss.insert(p);

		int cnt = 0;
		while (!ss.empty()) {
			int p = *ss.begin();
			ss.erase(p);
			if (p == P[p]) continue;
			if (A[p] <= B[P[p]] || A[P[p]] <= B[P[P[p]]]) continue;
			ans.emplace_back(p, P[p]);
			ss.erase(P[p]);
			ss.erase(prv[p]);
			int tmp = P[p];
			swap(P[p], P[tmp]);
			if (P[p] != p) if (A[p] > B[P[P[p]]]) ss.insert(p);

			prv[P[p]] = p;
			p = prv[p];
			if (P[p] != p) if (A[p] > B[P[P[p]]]) ss.insert(p);

			++cnt;
		}
		if (cnt + 1 != g.size()) {
			assert(false);
			// こないはず
		}

		for (int j : g) done[j] = true;
	}

	{
		bool ok = true;
		P = P2;
		for (auto [i, j] : ans) {
			// assert(A[i] > B[P[i]]);
			// assert(A[j] > B[P[j]]);
			swap(P[i], P[j]);
		}
		// REP(i, N) assert(i == P[i]);
	}

	cout << ans.size() << endl;
	for (auto [i, j] : ans) printf("%d %d\n", i + 1, j + 1);

}


#include <cstdio>
#include <random>
#include <ctime>
using namespace std;
std::mt19937 rnd(time(0));
long long gcd(long long a,long long b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}
bool f;
int ans[135];
void solve(long long x,long long y,int &now)
{
    if(now>130)
    {
        f=false;
        return;
    }
    if(x==1&&y==0)
    {
        ans[now]=1;
        return;
    }
  	if(x==0&&y==1)
    {
      	ans[now]=2;
      	return;
    }
    if(x>=y)
    {
        ans[now]=3;
      	now++;
        solve(x-y,y,now);
    }
    else
    {
        ans[now]=4;
      	now++;
        solve(x,y-x,now);
    }
}
int main()
{
    long long n,x,y;
    int now;
    scanf("%lld",&n);
    for(int i=0;i<1000000;i++)
    {
        x=n;
        y=1LL*rnd()*rnd()%n;
        if(gcd(x,y)!=1)
        {
            i--;
            continue;
        }
        f=true;
        now=1;
        solve(x,y,now);
        if(f)
        {
            printf("%d\n",now);
            for(int j=now;j>=1;j--)
                printf("%d\n",ans[j]);
            break;
        }
    }
    return 0;
}

#include <iostream>
#include <queue>
#include <map>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstdarg>
#include <set>
#include <limits>
#include <iomanip>

using namespace std;
#define INF 2e9 + 9
#define MOD 1000000007
#define ALL(v) v.begin() , v.end()
#define Int int64_t
#define pll pair<Int,Int>
template<class T> using pql = priority_queue<T, vector<T>>;
template<class T> using pq = priority_queue<T, vector<T>, greater<T>>;
#define ll(n) Int n; cin >> n;
#define LL(...) Int __VA_ARGS___; cin >> __VA_ARGS___;
#define OUT(...) cout << __VA_ARGS___;
#define RP(n, i, s) for(Int i = s ;i < n ;i++)
#define REP(n, i) for (Int i = 0; i < n; i++)
#define REPe(n, i) for (Int i = 1; i <= n; i++)
#define RPe(n, i, s) for (Int i = s; i <= n; i++)
#define upd_max(maxer, updater) if (maxer < updater) maxer = updater;
#define upd_min(miner, updater) if (miner > updater) miner = updater;
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif
// 実数の場合
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

void ansYes(bool flag){
    if (flag) cout << "Yes" << endl; else  cout << "No" << endl;
}

void ansYES(bool flag){
    if (flag) cout << "YES" << endl; else  cout << "NO" << endl;
}

struct node {
    Int to;
    Int length;
};

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

vector<Int> divisor(Int n) {
    vector<Int> ret;
    for (Int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    return (ret);
}

Int dx8[8] = {0, -1, -1, -1, 0, 1, 1, 1};
Int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};

//UnionFind群
/*
class UnionFind {
protected:
    vector<Int> par;
    vector<Int> data;
    Int cnt;
public:
    UnionFind() : par(1), data(1), cnt(1) {};
    UnionFind(Int N);
    Int root(Int x);
    Int marge(Int x, Int y);
    bool same(Int x, Int y);
    Int add();
    Int add(Int x);
    Int solve();
    inline Int getSize(Int x) { return data.at(root(x)); };
};

UnionFind::UnionFind(Int N) : par(N), data(N), cnt(N) {
    for (Int i = 0; i < N; i++) {
        par.at(i) = -1;
        data.at(i) = 1;
    }
}

Int UnionFind::root(Int x) {
    if (par.at(x) == -1) return x;
    return par.at(x) = root(par.at(x)); // 経路圧縮
}

Int UnionFind::marge(Int x, Int y) {
    Int rx = root(x);
    Int ry = root(y);
    if (rx == ry) return rx;
    else { // ノード数の少ない方に接続
        if (data.at(rx) < data.at(ry)) swap(rx, ry);
        par.at(ry) = rx;
        data.at(rx) += data.at(ry);
        return rx;
    }
    return rx;
}

bool UnionFind::same(Int x, Int y) {
    return root(x) == root(y);
}

Int UnionFind::add() {
    par.push_back(cnt);
    cnt++;
    return cnt - 1;
}

Int UnionFind::add(Int x) {
    par.push_back(cnt);
    cnt++;
    return marge(x, cnt);
}

Int UnionFind::solve() {
    for (Int i = 0; i < cnt;i++) {
        if (par.at(i) == -1) {

        }
    }
}*/

/*
Int dfs(Int par, Int maxs, bool ans) {
    if (mita.at(par) == 1) return 0;
    if (maxs > h.at(par)) {
        maxs = h.at(par);
        ans = true;
    }else if (maxs == h.at(par)){
        ans = false;
    }

    Int maxer = 0;
    for (auto z : to[par]){
        mita.at(par) = 1;
        maxer = dfs(z,maxs,ans);
    }
}*/

int main() {
    Int n , a, b;
    cin >> n >> a >> b;
    cout << n - a + b << endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	for(int i=s.size()-1;i>=0;i--)
	{
		if(s[i]=='1' || s[i]=='0' || s[i]=='8')
		cout<<s[i];
		if(s[i]=='6')
		cout<<'9';
		if(s[i]=='9')
		cout<<'6';
	}
	return 0;
}

#include<bits/stdc++.h>
#define ll long long int
#define f first
#define s second
#define pb(x) push_back(x)
#define inf (int)1e9
#define PI 3.1415926535897932384626433832795
#define mod 1000000007
#define imax INT_MAX
#define imin INT_MIN

using namespace std;

char c[5000000];

void input() {

	string s;
	cin>>s;

	string ans;

	int r=0;

	int x = s.size();

	int l = 500000,r1=500001;

	for(int i=0;i<x;i++) {
		if(s[i] == 'R') {
			r++;
			continue;
		}
		if(r%2) {
			c[l] = s[i];
			l--;
		}
		else {
			c[r1] = s[i];
			r1++;
		}
	}

	string a1;

	for(int i=l+1;i<r1;i++) {
		a1 += c[i];
	}

	if(r%2) {
		reverse(a1.begin(), a1.end());
	}

	ans = a1;

	// cout<<a1<<"\n";
	// cout<<ans<<"\n";

	stack<char> st;

	x = ans.size();

	for(int i=0;i<x;i++) {
		if(!st.empty() && st.top() == ans[i]) {
			st.pop();
		}
		else {
			st.push(ans[i]);
		}
	}

    string a;

    while(!st.empty()) {
    	a += st.top();
    	st.pop();
    }

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

    cout<<a<<"\n";
}

int main(){

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

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

    input();

    return 0;
}


#include <bits/stdc++.h>
// clang-format off
using namespace std; using ll=long long; using ull=unsigned long long; using pll=pair<ll,ll>; const ll INF=4e18;
void print0(){}; template<typename H,typename... T> void print0(H h,T... t){cout<<h;print0(t...);}
void print(){print0("\n");}; template<typename H,typename... T>void print(H h,T... t){print0(h);if(sizeof...(T)>0)print0(" ");print(t...);}
void perr0(){}; template<typename H,typename... T> void perr0(H h,T... t){cerr<<h;perr0(t...);}
void perr(){perr0("\n");}; template<typename H,typename... T>void perr(H h,T... t){perr0(h);if(sizeof...(T)>0)perr0(" ");perr(t...);}
void ioinit() { cout << fixed << setprecision(15); cerr<<fixed<<setprecision(6); ios_base::sync_with_stdio(0); cin.tie(0); }
// clang-format on

ll fibrest(ll x0, ll y0, ll n, bool isx) {
    ll iter = 0;
    vector<ll> fib = {x0, y0};
    ll x = x0;
    ll y = y0;
    ll op = 0;
    while (true) {
        if (isx) {
            x = x + y;
        } else {
            y = y + x;
        }
        if (x >= n) break;
        op++;
        isx = !isx;
    }
    return op;
}
void op(vector<ll> &ops, ll &x, ll &y, ll t) {
    if (t == 1) {
        x = x + 1;
    }
    if (t == 2) {
        y = y + 1;
    }
    if (t == 3) {
        x = x + y;
    }
    if (t == 4) {
        y = y + x;
    }
    ops.push_back(t);
}
void output(vector<ll> &ops) {
    ll k = ops.size();
    print(ops.size());
    for (auto ope : ops) {
        print(ope);
    }
}

int main() {
    ioinit();
    ll n;
    cin >> n;
    ll x = 0;
    ll y = 0;
    vector<ll> ops;
    op(ops, x, y, 1);
    bool isx = true;
    while (true) {
        if (x + y > n || n < 10) {
            while (x < n) {
                op(ops, x, y, 1);
            }
            break;
        }
        ll curop = fibrest(x, y, n, isx);
        while (true) {
            ll nx = isx ? x+1 : x;
            ll ny = isx ? y : y+1;
            if (fibrest(nx, ny, n, isx) != curop) break;
            if(isx){
              op(ops, x, y, 1);
            }else{
              op(ops, x, y, 2);
            }
        }
        if (isx) {
            op(ops, x, y, 3);
        } else {
            op(ops, x, y, 4);
        }
        isx = !isx;
    }
    output(ops);
}


#include <bits/stdc++.h>

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    string S;
    cin >> S;
    int N = S.size();
    const int INF = 1 << 29;
    vector<vector<int>> dp(N + 1, vector<int>(3, INF));
    dp[0][0] = 0;
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < 3; j++) {
            int nj = (j + S[i] - '0') % 3;
            dp[i + 1][nj] = min(dp[i + 1][nj], dp[i][j]);
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + 1);
        }
    }
    if (dp[N][0] == N) {
        cout << -1 << endl;
    } else {
        cout << dp[N][0] << endl;
    }
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);

    solve();
}

#include "bits/stdc++.h"
#define int long long
#define endl '\n'
using namespace std;

typedef long long ll;
typedef long double ld;
#define db(x) cerr << #x << ": " << x << '\n';
#define read(a) int a; cin >> a;
#define reads(s) string s; cin >> s;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}

#define print(a) cout << a << endl;
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;}
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define rz(v, n) v.resize((n) + 1);
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define vvi vector <vi>
#define setprec cout << fixed << showpoint << setprecision(20);
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 998244353;
const ll N = 2e5 + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int power (int a, int b = mod - 2)
{
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}

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

	readb(n, m);
	int one[n + 1][m + 1] = {}, zer[n + 1][m + 1] = {};
	int onesum[n + 1][m + 1] = {}, zersum[n + 1][m + 1] = {};

	int precalc[m + 1][n + 1] = {};
	FOR (i, 1, m) precalc[i][0] = 1;
	FOR (i, 1, m)
	    FOR (j, 1, n)
	        precalc[i][j] = i*precalc[i][j - 1] % mod;

	FOR (i, 1, n)
	    FOR (j, 1, m)
	    {
	        one[i][j] = (one[i][j - 1] + onesum[i - 1][j - 1] + zersum[i - 1][j - 1] + precalc[j][i] - precalc[j - 1][i]) % mod;
	        zer[i][j] = (one[i][j] + onesum[i - 1][j] + zersum[i - 1][j]) % mod;

	        onesum[i][j] = (onesum[i - 1][j]*(j + 1) + one[i][j]) % mod;
	        zersum[i][j] = (zersum[i - 1][j]*j + zer[i][j]) % mod;
	    }

    print((one[n][m] + 5*mod) % mod);
}


#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++)
#define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yes(ans) if(ans)printf("yes\n");else printf("no\n")
#define Yes(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YES(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector1d(type,name,...) vector<type>name(__VA_ARGS__)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
const int MOD2=998244353;
const int INF=1<<30;
const ll INF2=(ll)1<<60;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}
template<class T> void chmax(T &a,const T b){if(b>a)a=b;}
template<class T> void chmin(T &a,const T b){if(b<a)a=b;}

int main(){
    LL(n,t);
    vector<ll> a(n),suma(1,0),sumb(1,0);
    in(a);
    int pre;
    for(int i=0;i<n/2;i++){
        pre=suma.size();
        for(int j=0;j<pre;j++){
            if(suma[j]+a[i]<=t)suma.emplace_back(suma[j]+a[i]);
        }
    }
    for(int i=n/2;i<n;i++){
        pre=sumb.size();
        for(int j=0;j<pre;j++){
            if(sumb[j]+a[i]<=t)sumb.emplace_back(sumb[j]+a[i]);
        }
    }
    sort(all(suma));
    sort(all(sumb));
    ll ans=0,d,bt,bi=sumb.size()-1;
    for(int i=0;i<suma.size();i++){
        bt=t-suma[i];
        while(sumb[bi]>bt)bi--;
        chmax(ans,suma[i]+sumb[bi]);
    }
    out(ans);
}

//g++  7.4.0

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAXN 200005
vector<ll> adj[MAXN];
ll vis[MAXN];
ll dp[MAXN];
ll A[MAXN];

void DFS(ll s)
{
    vis[s] = 1;

    for(auto it: adj[s])
    {
        ll v = it;
        if(!vis[v])
            DFS(v);

        ll val = max(A[v],dp[v]);
        dp[s] = max(dp[s],val);
    }
}

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

    ll N,M; cin>>N>>M;

    for(ll i=0;i<N;++i)
        cin>>A[i + 1];

    for(ll i=0;i<M;++i)
    {
        ll u,v; cin>>u>>v;
        adj[u].push_back(v);
    }

    for(ll i=1;i<=N;++i)
    {
        if(!vis[i])
            DFS(i);
    }

    ll ans = LLONG_MIN;

    for(ll i=1;i<=N;++i)
    {
        if(adj[i].size()) //Not a leaf
        {
            ans = max(ans,dp[i] - A[i]);
        }
    }

    cout<<ans<<endl;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1000000007;
int quickpower(int a,int b){
	int ans=1;
	a%=mod;
	while(b){
		if(b&1) ans=(ans*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return ans%mod;
}
int C(int n,int m){
	if(n<m) return 0;
	if(m*2>n)  m=n-m;
	if(m==0) return 1;
	int up=1,down=1;
	for(int i=1;i<=m;i++){
		up=(up*(n-i+1))%mod;
		down=(down*i)%mod;
	}
	return up*quickpower(down,mod-2)%mod;
}
signed main(){
	int n,m,s=0;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		int k;
		cin>>k;
		s+=k;
	}
	cout<<C(m+n,s+n);
	return 0;
}

#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
int N;
int M;
int L[200000];
int R[200000];
int main(){
  int i;
  int fg = 0;
  rd(N);
  rd(M);
  if(M==0){
    int i;
    for(i=(0);i<(N);i++){
      wt_L(2*i+1);
      wt_L(' ');
      wt_L(2*i+2);
      wt_L('\n');
    }
    return 0;
  }
  if(M < 0){
    fg = 1;
    M *= -1;
  }
  if(M > N-2 || fg==1){
    wt_L(-1);
    wt_L('\n');
    return 0;
  }
  for(i=(0);i<(N);i++){
    {
      auto cTE1_r3A = (200000000+2*i);
      auto RZTsC2BF = ( 200000000+2*i+1);
      L[i] = cTE1_r3A;
      R[i] = RZTsC2BF;
    }
  }
  {
    auto FmcKpFmN = (1);
    auto xr20shxY = ( 100000000);
    L[0] = FmcKpFmN;
    R[0] = xr20shxY;
  }
  {
    auto WYIGIcGE = (2);
    auto t_ynMSdg = ( 3);
    L[1] = WYIGIcGE;
    R[1] = t_ynMSdg;
  }
  for(i=(0);i<(M);i++){
    {
      auto tU__gIr_ = (10+2*i);
      auto a2conNHc = ( 10+2*i+1);
      L[2+i] = tU__gIr_;
      R[2+i] = a2conNHc;
    }
  }
  for(i=(0);i<(N);i++){
    wt_L(L[i]);
    wt_L(' ');
    wt_L(R[i]);
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20201115-2

// --- original code ---
// int N, M, L[2d5], R[2d5];
// {
//   int fg = 0;
//   rd(N,M);
//
//   if(M==0){
//     rep(i,N) wt(2*i+1, 2*i+2);
//     return 0;
//   }
//
//   if(M < 0) fg = 1, M *= -1;
//   if(M > N-2 || fg==1) wt(-1), return 0;
//
//   rep(i,N) (L[i], R[i]) = (2d8+2*i, 2d8+2*i+1);
//   (L[0], R[0]) = (1, 1d8);
//   (L[1], R[1]) = (2, 3);
//   rep(i,M) (L[2+i], R[2+i]) = (10+2*i, 10+2*i+1);
//
//   rep(i,N) wt(L[i], R[i]);
// }


#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#define fs(i,x,y) for(int i=(x),_=(y);i<=_;++i)
#define fn(i,x,y) for(int i=(x),_=(y);i>=_;--i)
#define tor(i,v,x) for(int i=head[x],v=to[i];i;i=nxt[i],v=to[i])
#define Li inline
#define R register int
#define ls(x) ch[x][0]
#define rs(x) ch[x][1]
#define mpi(x,y) make_pair(x,y)
#define pi pair<int,int>
#define int ll
using namespace std;
typedef long long ll;
template<typename T>
void read(T &x){
	x=0;char ch=getchar();bool f=0;
	while(ch<'0'||ch>'9'){
		if(ch=='-')f=1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
	x=f?-x:x;
}

const int N=2e5+7;
const double eps=1e-8;
int n,m,k;
int a[N];
double dp1[N],dp2[N];
double suf1[N],suf2[N];
bool vis[N];

signed main(){
	read(n);read(m);read(k);
	fs(i,1,k)read(a[i]),vis[a[i]]=true;
	fn(i,n-1,0){
		dp1[i]=(suf1[i+1]-suf1[i+m+1])/m+1.0;
		dp2[i]=(suf2[i+1]-suf2[i+m+1])/m;
		fs(j,1,k){
			if(i+1<=a[j]&&a[j]<=i+m)dp2[i]+=1.0/m;
		}
		if(vis[i])dp1[i]=dp2[i]=0;
		suf1[i]=suf1[i+1]+dp1[i];
		suf2[i]=suf2[i+1]+dp2[i];
	}
	if(fabs(1.0-dp2[0])<eps)printf("-1");
	else printf("%lf",dp1[0]/(1-dp2[0]));
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=1;i<=n;++i)
#define mp make_pair
#define pb push_back
#define size sze
#define inf 998244353
int n,k;
vector<int> g[210000];
int v[210000],dep[210000];
int q[210000];
int f[210000][20],size[210000],son[210000],minp[210000];
int father[210000],root;
struct node
{
    int adj,valid,next;
}edge[2*210000];
int gh[210000],top;
void addedge(int x, int y) {
	edge[++top].adj = y;
	edge[top].valid = 1;
	edge[top].next = gh[x];
	gh[x] = top;
}
void get_size(int x, int root=0) {
	size[x] = 1; son[x] = 0;
	int dd = 0;
	for (int p=gh[x]; p; p=edge[p].next)
		if (edge[p].adj != root && edge[p].valid) {
			get_size(edge[p].adj, x);
			size[x] += size[edge[p].adj];
			if (size[edge[p].adj] > dd) {
				dd = size[edge[p].adj];
				son[x] = edge[p].adj;
			}
		}
}
int getroot(int x) {
	get_size(x);
	int sz = size[x];
	while (size[son[x]] > sz/2)
		x = son[x];
	return x;
}
int dc(int x,int fa) {
	x = getroot(x);
    father[x]=fa;
	for (int p=gh[x]; p; p=edge[p].next)
		if (edge[p].valid) {
			edge[p].valid = 0;
			edge[p^1].valid = 0;
			dc(edge[p].adj,x);
		}
    return x;
}
bool cmp(int x,int y)
{
    return dep[x]>dep[y];
}
void dfs(int x,int pre,int depp)
{
    f[x][0]=pre;
    for(int i=1;i<=17;i++)f[x][i]=f[f[x][i-1]][i-1];
    dep[x]=depp;
    for(int p=gh[x];p;p=edge[p].next)
        if (edge[p].adj!=pre)dfs(edge[p].adj,x,depp+1);
}
int jump(int x,int d)
{
    int delta=dep[x]-d;
    for(int i=17;i>=0;i--)
        if (delta & (1<<i))x=f[x][i];
    return x;
}
int lca(int x,int y)
{
    if (dep[x]<dep[y])swap(x,y);
    x=jump(x,dep[y]);
   // cout<<x<<" "<<y<<endl;
    if (x==y)return x;
    for(int i=17;i>=0;i--)
        if (f[x][i]!=f[y][i])
        {
            x=f[x][i];
            y=f[y][i];
        }
    return f[x][0];
}
int dis(int x,int y)
{
    return dep[x]+dep[y]-2*dep[lca(x,y)];
}
void insert(int x)
{
    int now=x;
    while (now!=0)
    {
        if (minp[now]==n+1 || dis(now,x)<dis(now,minp[now]))minp[now]=x;
        now=father[now];
    }
}
int get(int x)
{
    int ret=2147483647;
    int now=x;
    while (now!=0)
    {
        if (minp[now]!=n+1)ret=min(ret,dis(x,minp[now]));
        now=father[now];
    }
    return ret;
}
bool check(int lim)
{
    for(int i=1;i<=n;i++)minp[i]=n+1;
    int tot=0;
    for(int i=1;i<=n;i++)
    {
        //cout<<q[i]<<endl;
        if (get(q[i])>lim)
        {
            int fa=jump(q[i],max(dep[q[i]]-lim,0));
            insert(fa);
            tot++;
        }
        if (tot>k)return 0;
    }
    return 1;
}

int main()
{
    cin>>n>>k; top=1;
    for(int i=1;i<n;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        addedge(x,y);
        addedge(y,x);
    }

    dfs(1,0,0);

    root=dc(1,0);
    //cout<<lca(3,2)<<" "<<lca(3,5)<<" "<<lca(4,5)<<endl;
    for(int i=1;i<=n;i++)q[i]=i;
    sort(q+1,q+n+1,cmp);
    long long l=1; long long r=n;

    //for(int i=1;i<=n;i++)cout<<father[i]<<" "; puts("");
    while (l<r)
    {
        int mid=(l+r)/2;
       // cout<<mid<<endl;
        if (check(mid))r=mid;
        else l=mid+1;
    }
    cout<<l<<endl;
    return 0;
}


#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <bits/stdc++.h>
using namespace std;

const long long MOD = 1000000007;
const long long small = 100;
vector<long long> fac, finv, inv;

void COMinit(int max) {
	vector<long long> f(max+1);
	vector<long long> finv(max+1);
	vector<long long> inv(max+1);
	f[0] = 1;
	finv[0] = 1;
	inv[0] = 1;
	for (int i = 1; i <= max; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
vector<long> BINARY;
int biFind(long Key,int mode) {
	//need sort beforehand
	//mode 0:first > 1:first >=
	//return -1 if the last is <= or <

	if (mode == 0) {
		if (Key >= BINARY[BINARY.size() - 1]) {
			return -1;
		}
		int l, r, m;
		l = 0;
		r = BINARY.size();
		while (l < r) {
			m = (l + r) / 2;
			if (Key >= BINARY[m]) {
				l = m + 1;
			}
			else {
				r = m;
			}
		}
		return l;
	}
	else {
		if (Key > BINARY[BINARY.size() - 1]) {
			return -1;
		}
		int l, r, m;
		l = 0;
		r = BINARY.size();
		while (l < r) {
			m = (l + r) / 2;
			if (Key > BINARY[m]) {
				l = m + 1;
			}
			else {
				r = m;
			}
		}
		return l;
	}
}
bool biFind(long Key) {
	int l, r, m;
	l = 0;
	r = BINARY.size();
	while (l < r) {
		m = (l + r) / 2;
		if (Key == BINARY[m]) {
			break;
		}
		if (Key > BINARY[m]) {
			l = m + 1;
		}
		else {
			r = m;
		}
	}
	return Key == BINARY[l];
}

int main() {
	//cout << fixed << setprecision(16);
	long N;
	cin >> N;
	vector<long> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	sort(A.begin(), A.end());
	vector<long> B(1, 1);
	int pos = 0;
	for (int i = 1; i < N; i++) {
		if (A[i] == A[i-1]) {
			B[pos]++;
		}
		else {
			B.push_back(1);
			pos++;
		}
	}
	long R = 0;
	for (int i = 0; i < B.size(); i++) {
		//cout << B[i] << endl;
		R += B[i] * (N - B[i]);
	}
	cout << R/2 << endl;
}

#include<bits/stdc++.h>
using namespace std;
#define     ll long long
#define     endl "\n"
#define     f(i,n) for(ll i=0;i<n;i++)
#define     fa(i,a,n) for(ll i=a;i<n;i++)
#define     M 1000000007
#define     pb push_back
#define     vl vector
#define     sp(x) setprecision(x)

void code()
{
  ll n;
  cin>>n;
  ll a[n];
  f(i,n)
  cin>>a[i];
  ll c=0;
  unordered_map<int,int> m;
f(i,n)
{
    m[a[i]]++;
}
f(i,n-1)
{
    if(m[a[i]]>1){
 c+=(n-1-i)-(m[a[i]]-1);
 m[a[i]]--;
    }else if(m[a[i]]==1)
    c+=(n-1-i);
}
cout<<c<<endl;
}
int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   ll t;
   t=1;
   //cin>>t;
   while(t--)
   {
     code();
   }
   return 0;
}


/** made by amunduzbaev **/

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

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(),x.rend()
#define NeedForSpeed ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define vv vector
#define tut(x) array<int, x>
#define int long long
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vii;
typedef vector<pii> vpii;
template<class T> bool umin(T& a, const T& b) {return a > b? a = b, true:false;}
template<class T> bool umax(T& a, const T& b) {return a < b? a = b, true:false;}
void fropen(string s) {  freopen((s+".in").c_str(),"r",stdin);  freopen((s+".out").c_str(),"w",stdout);  }

const int N = 3e5+5;
const int mod = 1e9+7;
const ll inf = 1e18;
const ld Pi = acos(-1);

#define MULTI 0
int n, m, k, res, ans, a[N];

void solve(int t_case){
	cin>>n>>k;
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a, a+n);
	multiset<int> ss;
	for(int i=0;i<k;i++) ss.insert(0);
	for(int i=0;i<n;i++){
		auto pos = ss.find(a[i]);
		if(pos != ss.end()){
			ss.erase(pos);
			ss.insert(a[i]+1);
		}
		//for(auto x:ss) cout<<x<<" ";
		//cout<<"\n";
	}
	for(auto x:ss) res += x;
	cout<<res<<"\n";
}

signed main(){
	NeedForSpeed

	if(!MULTI) {
		solve(1);
	} else {
		int t; cin>>t;
		for(int t_case = 1; t_case <= t; t_case++) solve(t_case);
	}
	return 0;
}

  #include<bits/stdc++.h>
  using namespace std;
  using ll = long long;
  #define rep(i,f,n) for(ll i=(f); (i) < (n); i++)
  #define repe(i,f,n) for(ll i=(f); (i) <= (n); i++)
  #define repc(i,f,n) for(char i=(f); (i) <= (n); i++)
  #define PI 3.14159265358979323846264338327950ll
  #define debug(x) cout<<#x<<" :: "<<x<<"\n";
  #define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
  #define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
  #define Pl pair<ll, ll>
  #define dvec vector<vector<ll>>
  #define OUT(x) cout << x << endl; return 0;
  //printf("%.10f\n")
  //cout << fixed << setprecision(10);
  template<class T> inline bool chmax(T& a, T b){if (a < b) { a = b; return true; } return false;}
  template<class T> inline bool chmaxe(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;}
  const ll MOD = 1000000007ll;
  const ll INF = 1e+18;
  const int iINF = 1e9;
  const double EPS = 1e-8;

int
main()
{
  ll H, W; cin >> H >> W;
  vector<string> grd(H);
  rep(i, 0, H){
    cin >> grd[i];
  }
  vector<vector<ll>> dp(H, vector<ll>(W, -INF));
  dp[H - 1][W - 1] = 0;

  for(ll h = H - 1; h >= 0; h -= 1){
    for(ll w = W - 1; w >= 0; w -= 1){
      if((h + w) % 2 == 0){
        ll cmp = -INF;
        if(h + 1 < H) chmax(cmp, dp[h + 1][w] + (grd[h + 1][w] == '+' ? 1 : -1));
        if(w + 1 < W) chmax(cmp, dp[h][w + 1] + (grd[h][w + 1] == '+' ? 1 : -1));
        if(cmp != -INF)dp[h][w] = cmp;
      } else {
        ll cmp = INF;
        if(h + 1 < H) chmin(cmp, dp[h + 1][w] + (grd[h + 1][w] == '+' ? -1 : 1));
        if(w + 1 < W) chmin(cmp, dp[h][w + 1] + (grd[h][w + 1] == '+' ? -1 : 1));
        if(cmp != INF)dp[h][w] = cmp;
      }
    }
  }

  ll rt = dp[0][0];
  if(rt == 0){OUT("Draw")}
  else if(rt > 0){OUT("Takahashi")}
  else{OUT("Aoki")}
}


#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define REP(i, n) for(int i = 0; i < n; ++i)
using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
	int N; cin >> N;
	vector<vector<int>> adList(N);
	REP(i, N)
	{
		string S; cin >> S;
		REP(j, N)
		{
			if (S[j] == '1')
			{
				adList[i].push_back(j);
			}
		}
	}
	vector<set<int>> ss(N);
	REP(s, N)
	{
		deque<int> Q{ s };
		vector<bool> arrived(N, false);
		arrived[s] = true;
		while (!Q.empty())
		{
			int t = Q.front(); Q.pop_front();
			ss[t].insert(s);
			for (const int n : adList[t])
			{
				if (arrived[n]) continue;
				Q.push_back(n);
				arrived[n] = true;
			}
		}
	}

	double ans = 0.0;
	REP(s, N)
	{
		const double sv = static_cast<double>(ss[s].size());
		ans += 1.0 / sv;
	}
	cout << setprecision(12) << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using pii = pair<int, int>;

string dispVec(vector<int> b){
    string ret = to_string(b.size()) + " ";
    rep(i,b.size()) ret += to_string(b[i] + 1) + " ";
    return ret;
}

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int b = min(n,8);
    vector<vector<int>> can(200);
    rep(i,1<<b ){
        if(i==0) continue;
        ll m = 0;
        vector<int> v;
        rep(j,b) if(i >> j & 1) {
            m = m + a[j];
            v.push_back(j);
        }
        if (can[m%200].size() > 0){
            cout << "Yes" << endl;
            cout << dispVec(can[m%200]) << endl;
            cout << dispVec(v) << endl;
            return 0;
        } else {
            can[m%200] = v;
        }
    }
    cout << "No" << endl;
}


#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
#define double long double
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
#define eps 1e-12
//priority_queue<int,vector<int>, greater<int> > q2;

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

	int N; cin >> N;
	VP A(N);
	REP(i, N)cin >> A[i].first >> A[i].second;
	bool F = 0;

	REP(i, N) {
		FOR(j, i + 1, N) {
			FOR(k, j + 1, N) {
				int x1 = A[i].first, y1 = A[i].second;
				int x2 = A[j].first, y2 = A[j].second;
				int x3 = A[k].first, y3 = A[k].second;

				int ax = x2 - x1;
				int ay = y2 - y1;

				int bx = x3 - x1;
				int by = y3 - y1;

				int tmp = abs(ax*by - bx * ay);
				if (tmp == 0) {
					F = 1;
				}

			}
		}
	}

	if (F)cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

//CODED BY SUMIT KUMAR PRAJAPATI
#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int>  pii;
typedef pair<ll, ll>  pl;

#define PI 3.1415926535897932384626
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
#define watch(x) cerr<<#x<<" = "<<x<<'\n'
#define rep(i,n) for(ll i=0;i<n;i++)
#define repe(i,n) for(ll i=1;i<=n;i++)
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define printar(a,s,e) FOR(i,s,e)cout<<a[i]<<" ";cout<<'\n'
#define curtime chrono::high_resolution_clock::now()
#define timedif(start,end) chrono::duration_cast<chrono::nanoseconds>(end - start).count()

const ll INF=1e18;
const int MX=1e5+5;
const int MD=1e9+7;
const int MDL=99824453;
auto time0 = curtime;

string X;

ll maxCanGo(ll base){
    ll ans=(log2(INF)/log2(base))+1;
    //cout<<ans<<" ^ \n";
    return ans;
}

ll evaluate(ll base,ll n){
    ll res=0;
    ll cur_power=1;
    for(ll i=n-1;i>=0;i--){
        res+=(cur_power*(X[i]-'0'));
        cur_power*=base;
    }
    return res;
}

void solve(){

    ll M;
    cin>>X>>M;
    ll n=X.length();
    if(n==1){
        ll one=X[0]-'0';
        if (one<=M){
            cout<<"1";

        }
        else cout<<"0";
        return;
    }
    char max_digit;
    for(auto ch:X)
        if(max_digit<ch)
            max_digit=ch;

    ll cur_digit=max_digit-'0'+1;
    //cout<<cur_digit<<'\n';
    ll cur_value;
    ll ans=0;
    ll l=cur_digit,r=1e18,mid;
    while(l<=r){
        mid=(l+r)>>1;

        if(maxCanGo(mid)>=n && evaluate(mid,n)<=M){
            //cout<<mid<<" "<<ans<<" "<<evaluate(mid,n)<<'\n';
            ans=mid;
            l=mid+1;
        }
        else
            r=mid-1;

    }
    //cout<<ans<<'\n';
    if(ans!=0){
        ans=(ans-(cur_digit)+1);

    }

    cout<<ans<<'\n';
}

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

    srand(time(0));
    time0 = curtime;

    ll t=1;
    //cin>>t;
    repe(tt,t){
        //cout<<"Case #"<<tt<<": ";
        solve();
    }

    cerr<<"Execution Time: "<<timedif(time0,curtime)*1e-9<<" sec\n";
    return 0;

}


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

const int inf=0x3f3f3f3f;
const ll mod=998244353;

ll n,k;
ll f[3010][3010];

int read(){
    int f=1,x=0;
    char ss=getchar();
    while(ss<'0'||ss>'9'){if(ss=='-')f=-1;ss=getchar();}
    while(ss>='0'&&ss<='9'){x=x*10+ss-'0';ss=getchar();}
    return f*x;
}

ll calc(int n,int k){
    if (n<k)return 0;
    ll &ret=f[n][k];
    if (ret!=-1)return ret;
    ret=0;
    if (k==0)ret=0;
    else if (n==k)ret=1;
    else if (n==1)ret=1;
    else ret=(calc(n-1,k-1)+calc(n,2*k))%mod;
    return ret;
}

int main()
{
    n=read();k=read();
    for (int i=1;i<=n;i++)for(int j=1;j<=n;j++)f[i][j]=-1;
    printf("%lld\n",calc(n,k));

    return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define int long long

int n;

map<pair<int, int>, int> ans;

int solve(vector<int> & a, int x, int st)
{
    if (ans[{x, st}])
    {
        return ans[{x, st}];
    }
    if (st == n - 1)
    {
        return 1;
    }
    if (x % (a[st + 1] / a[st]) == 0)
    {
        int k = (a[st + 1] / a[st]);
        int res = solve(a, x / k, st + 1);
        ans[{x, st}] = res;
        return res;
    }
    int k = (a[st + 1] / a[st]);
    int res = solve(a, x / k, st + 1) + solve(a, x / k + 1, st + 1);
    ans[{x, st}] = res;
    return res;
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); srand(clock());
    int x;
    cin >> n >> x;
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
    }
    cout << solve(a, x, 0) << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

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

	int tc;
	cin >> tc;
	while(tc--){
		int n;
		cin >> n;
		vector<long long> a(n);
		for(int i=0;i<n;i++) cin >> a[i];

		if(n&1){
			cout << "Second\n";
		}else{
			sort(a.begin(),a.end());

			bool bo=true;
			for(int i=0;i<n;i+=2){
				if(a[i]!=a[i+1]) bo=false;
			}

			if(bo){
				cout << "Second\n";
			}else{
				cout << "First\n";
			}
		}
	}
	return 0;
}

#include <bits/stdc++.h>
#define pb push_back
#define SZ(x) ((int)(x.size()))
#define FOR(i,s,n) for (ll i = (s); (i) < (n); ++i)
#define FORD(i,s,l) for (ll i = (s); (i) >= l; --i)
#define F first
#define S second
#define TC int __tc; cin >> __tc; FOR(case_num,1,__tc+1)
#define TEST(x,i) ((x)&(1ll<<(i)))
#define SET(x,i) ((x)|(1ll<<(i)))
#define FLIP(x,i) ((x)^(1ll<<(i)))
#define CLEAR(x,i) ((x)&~(1ll<<(i)))
const double pi = 4 * atan(1);
using namespace std;
typedef long long ll;

template<class ForwardIterator> void print_vec(ForwardIterator first, ForwardIterator last, string sep = " ", string end="\n") {
	bool ft = true;
	while (first != last) {
		if (! ft) {cout << sep;} else {ft = false;}
		cout << (*first);
		++first;
	}
	cout << end;
}

inline ll floorDiv(ll x, ll y) {
	ll d = x / y;
	ll r = x % y;
	return r ? (d - ((x < 0) ^ (y < 0))) : d;
}

ll ceilDiv(ll x, ll y) {
	return -floorDiv(-x, y);
}

bool predicate(ll mid) {
	return mid > 10;
}

ll bin_search(ll lo, ll hi) {
	int sign = lo < hi ? 1 : -1;
	lo *= sign;
	hi *= sign;
	hi++;
	while (lo < hi) {
		ll mid = floorDiv(lo + hi, 2);
		if (!predicate(sign * mid)) {
			lo = mid + 1;
		} else {
			hi = mid;
		}
	}
	return sign * lo;
}
const ll MOD = 1000000007;
const int MAXN = 200005;

ll num[MAXN];
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	TC {
		int n;
		cin >> n;
		FOR(i,0,n){
			cin >> num[i];
		}
		if (n%2 == 1) {
			cout << "Second\n";
			continue;
		}
		map<ll,int> cnt;
		FOR(i,0,n) {
			cnt[num[i]]++;
		}
		bool g = true;
		for (auto &p : cnt) {
			if (p.S%2!=0) {
				g=false;
				break;
			}
		}
		cout << (g ? "Second\n" : "First\n" );
	}

}


//g++ -std=gnu++14 a.cpp

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

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define P pair<ll,ll>
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;
ll MODP = 998244353;
const ll M = 2000000;

ll lmax(ll x,ll y){
  if(x < y) return y;
  else return x;
}

ll lmin(ll x, ll y){
  if(x > y)return y;
  else return x;
}

ll gen(ll x,ll y){
  if(y == 0)return 1;
  if(y == 1)return x;
  if(y%2 == 1){
    return ((x%M)*gen(x,y-1)%M)%M;
  }else{
    ll res = gen(x,y/2)%M;
    return ((res%M)*(res%M))%M;
  }
}

ll gcd(ll x, ll y){
  if(x < y) swap(x,y);
  if(y == 0) return x;
  return gcd(y,x%y);
}

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

struct UnionFind{
  vector<ll> d;
  vector<P> m;
  UnionFind(int n) : d(n,-1),m(n,make_pair(-INFL,INFL)) {};
  int find(int x){
    if(d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x,int y){
    x = find(x);
    y = find(y);
    if(x == y) return false;
    if(d[x] > d[y])swap(x,y); //yをxにくっつける
      d[x] += d[y];
      d[y] = x;
      m[y].first = lmax(m[x].first,m[y].first);
      m[y].second = lmin(m[x].second,m[y].second);

    return true;
  }
  bool same(int x,int y){
    return find(x)==find(y);
  }
  int size(int x){
    return -d[find(x)];
  }
};

int main(){
  ll n,x;
  cin >> n >> x;
  vector<ll> ans;
  rep(i,n){
    ll a;
    cin >> a;
    if(a != x)ans.push_back(a);
  }
  for(auto x : ans){
    cout << x << " ";
  }
  cout << endl;

  return 0;
}

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

int main()
{
  int N;
  int64_t X;
  std::cin>>N>>X;

  std::vector<int64_t> A(N);
  for(auto &e:A)std::cin>>e;

  std::string result;
  result.reserve(11*N);
  for(auto e:A)if(e!=X)(result+=std::to_string(e))+=' ';
  if(result.empty()==false)result.pop_back();

  std::cout<<result<<std::endl;

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=55;
struct to {
	int x,y,id;
} dd[5],d[5];
int a[maxn][maxn],w[maxn][maxn],ans[maxn*maxn],temp[maxn*maxn],vis[maxn*maxn],sum=0,n=50,finalans=0,s[maxn];
char p[5]= {'\0','D','R','U','L'};
bool cmp(to a,to b) {
	return s[a.id]>s[b.id];
}
int get(int x,int y,to a) {
	x=x+a.x;
	y=y+a.y;
	if(vis[::a[x][y]]||x>n||y>n||x<1||y<1) {
		return -1;
	}
	return w[x][y];
}
void dfs(int x,int y) {
	if(1.0*clock()/CLOCKS_PER_SEC>1.8) {
		if(sum>finalans) {
			finalans=sum;
			memcpy(ans,temp,sizeof(temp));
		}
		for(int i=1; i<=ans[0]; i++) {
			cout<<p[ans[i]];
		}
		exit(0);
	}
	vis[a[x][y]]=1;
//	temp[++temp[0]]=
	sum+=w[x][y];
	int fl=0;
	to d[5];
	memcpy(d,dd,sizeof(d));
//	random_shuffle(d+1,d+4+1);
	for(int i=1;i<=4;i++) {
		s[i]=get(x,y,d[i]);
	}
	sort(d+1,d+4+1,cmp);
	for(int i=1; i<=4; i++) {
		int nx=x+d[i].x,ny=y+d[i].y;
		if(!vis[a[nx][ny]]&&nx<=n&&nx>=1&&ny<=n&&ny>=1) {
			temp[++temp[0]]=d[i].id;
			dfs(nx,ny);
			fl=1;
			--temp[0];
		}
	}
	if(fl==0) {
		if(sum>finalans) {
			finalans=sum;
			memcpy(ans,temp,sizeof(temp));
		}
	}
	sum-=w[x][y];
	vis[a[x][y]]=0;
}
int main() {
	dd[1]=(to) {
		1,0,1
	};
	dd[2]=(to) {
		0,1,2
	};
	dd[3]=(to) {
		-1,0,3
	    };
	dd[4]=(to) {
		0,-1,4
	};
	int x,y;
	cin>>x>>y;
	x++,y++;
	for(int i=1; i<=n; i++) {
		for(int j=1; j<=n; j++) {
			cin>>a[i][j];
		}
	}
	for(int i=1; i<=n; i++) {
		for(int j=1; j<=n; j++) {
			cin>>w[i][j];
		}
	}
	srand(time(0));
	dfs(x,y);
	for(int i=1; i<=ans[0]; i++) {
		cout<<p[ans[i]];
	}
	exit(0);
}

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define MOD 1000000007ll
#define INF 1000000000000000000ll
#define pb push_back
#define fs first
#define sc second
const double pi = acos(-1);

vector<bool> dfs(int start, vector<vector<int>>& adj) {
	stack<int> s;
	s.push(start);
	vector<bool> vis(adj.size(), false);
	vis[start] = true;
	while (s.size()) {
		int cur = s.top();
		s.pop();
		for (int nxt : adj[cur]) {
			if (!vis[nxt]) {
				s.push(nxt);
				vis[nxt] = true;
			}
		}
	}
	return vis;
}

int n;
vector<pair<int, int>> A;
bool can(double r) {
	set<pair<int, int>> points;
	for (int i = 0; i < n; i++) {
		points.insert(A[i]), points.insert(make_pair(A[i].fs, 100)), points.insert(make_pair(A[i].fs, -100));
	}
	map<pair<int, int>, int> from;
	int idx = 0;
	for (pair<int, int> point : points) {
		from[point] = idx++;
	}

	int m = points.size();
	vector<vector<int>> adj(m);
	for (pair<int, int> point1 : points) {
		for (pair<int, int> point2 : points) {
			ll dx = abs(point1.fs - point2.fs), dy = abs(point1.sc - point2.sc);
			if (sqrt(dx * dx + dy * dy) < 2 * r)
				adj[from[point1]].pb(from[point2]);
		}
	}

	for (int i = 0; i < n; i++) {
		pair<int, int> curs = make_pair(A[i].fs, 100);
		vector<bool> reach = dfs(from[curs], adj);
		for (int j = 0; j < n; j++) {
			pair<int, int> cor = make_pair(A[j].fs, -100);
			if (reach[from[cor]]) {
				return false;
			}
		}
	}
	return true;
}

void solve() {
	cin >> n;
	A = vector<pair<int, int>>(n);
	for (int i = 0; i < n; i++)
		cin >> A[i].fs >> A[i].sc;
	double lo = 0, hi = 200, bst = 0;
	while (abs(hi - lo) > 1e-7) {
		double mid = (hi + lo) / 2;
		if (can(mid)) {
			lo = mid;
			bst = mid;
		}
		else {
			hi = mid;
		}
	}
	cout << fixed << setprecision(12) << bst << endl;
}

signed main() {
	ios_base::sync_with_stdio(false);
	/*int t;
	cin >> t;
	while (t--)*/
		solve();
}


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

const int N = 1e5 + 10;

int n, m;
int tot, Head[N], ver[N << 1], Next[N << 1], Leng[N << 1];
int fa[N], ans[N];

void add(int x, int y, int z) {
	tot++;
	ver[tot] = y;
	Leng[tot] = z;
	Next[tot] = Head[x];
	Head[x] = tot;
}

int findfa(int x) { return x == fa[x] ? x : fa[x] = findfa(fa[x]); }

void merge(int x, int y) { fa[findfa(x)] = findfa(y); }

void dfs(int x, int f) {
	for (int i = Head[x]; i; i = Next[i]) {
		int y = ver[i];
		if (y == f) continue;
		if (Leng[i] == ans[x]) {
			if (ans[x] == 1) ans[y] = 2;
			else ans[y] = 1;
		}
		else ans[y] = Leng[i];
		dfs(y, x);
	}
}

int main() {
	cin >> n >> m;
	for (int i = 1; i <= n; i++) fa[i] = i;
	for (int i = 1; i <= m; i++) {
		int x, y, z;
		scanf("%d%d%d", &x, &y, &z);
		if(findfa(x) != findfa(y)) {
			merge(x, y);
			add(x, y, z);
			add(y, x, z);
		}
	}
	ans[1] = 1;
	dfs(1, 0);
	for (int i = 1; i <= n; i++) printf("%d\n", ans[i]);
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
using namespace std::chrono;
const int mod=1e9+7;
const int mex=300005;
#define ll long long
#define test int t;cin>>t;while(t--)
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fo(i,a,n) for(int i=a;i<n;i++)
#define rfo(i,a,b) for(int i=a;i>=b;i--)
#define bg begin()
#define en end()
#define fi first
#define se second
#define ub upper_bound
#define lb lower_bound
#define pb push_back
#define veci vector<int>
#define veclli vector<long long int>
#define all(x) x.begin(),x.end()
#define sci(x) scanf("%d",&x);
#define scc(x) scanf("%c",&x);
#define scs(x) scanf("%s",x);
#define debug(arr,n) for(int i=0;i<n;i++) printf("%d ",arr[i]);
#define sz(x) x.size()
#define loop(x) for(auto it=x.begin();it!= x.end();it++)
vector<pair<int,int> > v[mex];
int vis[mex],val[mex];
int N;
void dfs(int n)
{
    vis[n]=1;
    if(val[n]==0) val[n]=1;
    fo(i,0,sz(v[n]))
    {
        if(vis[v[n][i].fi]==0&&val[v[n][i].fi]==0)
        {
            if(val[n]!=v[n][i].se) val[v[n][i].fi]=v[n][i].se;
            else val[v[n][i].fi]=v[n][i].se%N+1;
            dfs(v[n][i].fi);
        }
    }
}
int main()
{
    int n,m;
    cin>>n>>m;
    N=n;
    fo(i,0,m)
    {
        int a,b,c;
        cin>>a>>b>>c;
        v[a].pb({b,c});
        v[b].pb({a,c});
    }
    dfs(1);
    fo(i,1,n+1)
    cout<<val[i]<<endl;

}


#include <bits/stdc++.h>
using namespace std;
#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()
using P = pair<int,int>;
using ll = long long;
using ull = unsigned long long;
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; }
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<int> vint;
const int INF=1001001001;

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

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (long long i = 0; i < (n); i++)
using ll = long long;
using P = pair<ll, ll>;
template<class T>
bool chmax(T &a, T b) {if (a < b) {a = b;return true;}else return false;}
template<class T>
bool chmin(T &a, T b) {if (a > b) {a = b;return true;}else return false;}
// struct Edge { ll to; ll cost; Edge(ll t, ll c) { to = t; cost = c;} };
// using Graph = vector<vector<Edge>>;
// using Graph = vector<vector<ll>>;
// priority_queue<P, vector<P>, greater<P>> q;

const int INF = (1 << 30) - 1;
const ll LINF = (1LL << 60) - 1;
const double PI = acos(-1);

ll n, A;
ll a[110];

// dpテーブル

bool dp[110][100100];

int main() {
    cin >> n;
    ll sum = 0;
    rep(i, n) {
        ll val; cin >> val;
        sum += val;
        a[i] = val;
    }

    memset(dp, 0, sizeof(dp));  // 一旦すべて false に
    dp[0][0] = true;  // dp[0][0] だけ true に

    rep(i, n) {
        rep(j, sum+1) {
            dp[i+1][j] |= dp[i][j];
            if (j >= a[i]) dp[i+1][j] |= dp[i][j-a[i]];
        }
    }
    ll cnt = 100100;
    for (ll ans = sum; ans >= 0; ans--) {

        if (dp[n][ans]) {
            ll big = max(ans, sum - ans);
            // cout << ans << " " << sum-ans << endl;
            cnt = min(cnt, big);
        }
    }
    cout << cnt << endl;
    return 0;

}

//小数点の出力
//cout << fixed << std::setprecision(15) << ans << endl;


#include <bits/stdc++.h>

template <class T>
inline void read(T &x) {
	static char ch;
	static bool opt;
	while (!isdigit(ch = getchar()) && ch != '-');
	x = (opt = ch == '-') ? 0 : ch - '0';
	while (isdigit(ch = getchar()))
		x = x * 10 + ch - '0';
	if (opt)
		x = ~x + 1;
}

template <class T>
inline void putint(T x) {
	static char buf[45], *tail = buf;
	if (!x)
		putchar('0');
	else {
		if (x < 0)
			putchar('-'), x = ~x + 1;
		for (; x; x /= 10) *++tail = x % 10 + '0';
		for (; tail != buf; --tail) putchar(*tail);
	}
}

template <class T>
inline bool tense(T &x, const T &y) {
	return y < x ? x = y, true : false;
}

template <class T>
inline bool relax(T &x, const T &y) {
	return x < y ? x = y, true : false;
}

template <class T>
inline T getAbs(const T &x) {
	return x < 0 ? -x : x;
}

typedef long long s64;
typedef long double ld;
typedef std::vector<int> vi;
typedef std::pair<int, int> pii;
#define mp(x, y) std::make_pair(x, y)

using std::cout;
using std::cerr;

int t, n;

inline s64 getless(s64 k) {
	s64 l = 1, r = k + 1, res = 1;
	while (l <= r) {
		s64 mid = (l + r) >> 1;
		if ((100 + t) * mid / 100 > k)
			res = mid, r = mid - 1;
		else
			l = mid + 1;
	}
	// cerr << k << ' ' << res - 1 << '\n';
	return res - 1;
}

inline s64 findnth(int n) {
	s64 l = 1, r = 1e18, res = 1;

	while (l <= r) {
		s64 mid = (l + r) >> 1;
		if (mid - getless(mid) >= n)
			res = mid, r = mid - 1;
		else
			l = mid + 1;
	}
	return res;
}

int main() {
#ifdef orzczk
	freopen("a.in", "r", stdin);
#endif

	read(t), read(n);

	cout << findnth(n) << '\n';

	return 0;
}

#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
const long long MOD = 1000000007;

signed main(){
    ll N;
    cin >> N;
    ll a = 3, b = 5;
    FOR(A, 1, 100){
        b = 5;
        FOR(B, 1, 100){
            if(a + b == N){
                cout << A << " " << B << endl;
                return 0;
            }
            if(5 * b > N) break;
            else b *= 5;
        }
        if(3 * a > N) break;
        else a *= 3;
    }
    PRINT(-1);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <utility>
#include <numeric>
#define pb push_back
#define mk make_pair
#define endl "\n"
#define mod 1000000007
#define mod1 1610612741
#define mul 31
#define PI 3.14159265358979323846264
//#include bits/stdc++.h
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
typedef long long int lli;
typedef long double ld;
typedef pair<lli,lli> ii;
//priority_queue <lli, vector<lli>, greater<lli> > ti;
//priority_queue<pair<lli,pair<lli,lli>>>e;
vector <lli> p[300005],q[300005],f(200005,-1),d(300005,0),a(300005);
//vector<set<lli>>s(200005);
//set<pair<lli,lli>>s;
//vector<vector<lli>> dp(200005,vector<lli>(25,0));
//vector<lli>f(10000005);
//lli b[1000005],l[1000005];
//vector<vector<lli>> d(300005,vector<lli>(18,0));
//vector<pair<lli,ii>>p[300005];
//map<pair<lli,lli>,lli>mp,np;
//vector<pair<pair<lli, lli>,lli> > st;
//queue<lli> qy;
//freopen("codecoder.in", "r", stdin);
//freopen("codecoder.out", "w", stdout);
lli gcd(lli a, lli b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
lli bpow(lli a, lli b) {
    lli res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a)%mod;
        a = (a * a)%mod;
        b >>= 1;
    }
    return res%mod;
}
void fact(lli i)
{
    f[0]=1;
    for(lli k=1;k<=i;k++)
    {
        (f[k]=f[k-1]*k)%=mod;
    }
}
lli isprime(lli n)
{
    if(n==1)
        return 0;
    for(lli i=2;i<=sqrt(n);i++)
        if(n%i==0)
            return 0;
    return 1;
}
lli find(lli x)
{
    if(f[x]==x)
        return x;
    else
        return f[x]=find(f[x]);
}
bool cmp(lli x,lli y)
{
    return x<y;
}
void check()
{
    cout<<"HI"<<endl;
}
lli comb(lli i,lli j)
{
    if(j>i)return 0;
    lli k=f[i];
    lli g=(f[j]*(f[i-j]))%mod;
    lli h=bpow(g,mod-2);
    return (k*h)%mod;
}
pair<ld,ld>az(ld a,ld b,ld c,ld d,ld u)
{
    ld x1=(a-c)*cos(u)-(b-d)*sin(u)+c;
    ld y1=(a-c)*sin(u)+(b-d)*cos(u)+d;
    return {x1,y1};
}
/*void sieve()
{
    for(lli i=2;i<=sqrt(10000000);i++)
    {
        if(b[i]==0)
        {
            k.pb(i);
        for(lli j=2;i*j<=sqrt(10000000);j++)
        {
            b[i*j]=1;
        }
        }
    }
}*/
int main ()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli t;t=1;
    while(t--)
    {
        lli n;cin>>n;
        vector<lli> a(n);
        for(lli i=0;i<n;i++)
            cin>>a[i];
        lli cnt=min(8ll,n);
        vector<vector<lli>> b(200,vector<lli>(0));
        for(lli i=1;i<(1ll<<cnt);i++)
        {
            vector<lli>v;
            lli s=0;
            for(lli j=0;j<cnt;j++)
            {
                if(i&(1ll<<j))
                {
                    v.pb(j+1);
                    (s+=a[j])%=200;
                }
            }
            if(b[s].size()!=0)
            {
                cout<<"Yes"<<endl;
                cout<<b[s].size()<<" ";
                for(lli j=0;j<b[s].size();j++)
                {
                    cout<<b[s][j]<<" ";
                }
                cout<<endl;
                cout<<v.size()<<" ";
                for(lli j=0;j<v.size();j++)
                {
                    cout<<v[j]<<" ";
                }
                cout<<endl;
                return 0;
            }
            else
            {
                b[s]=v;
            }
        }
        cout<<"No"<<endl;
    }
}

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

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

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

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    for (auto &i : a) cin >> i;

    vector<ll> b, c;
    vector<vector<ll>> v(200);
    for (int i = 0; i < n; i++) {
        if (v[a[i] % 200].size() == 0)
            v[a[i] % 200].push_back(i);
        else {
            b.push_back(i);
            c = (v[a[i] % 200]);
            goto END;
        }

        for (int j = 0; j < 200; j++) {
            if (v[j].size() == 0) continue;
            if (j == a[i] % 200) continue;
            ll t = (a[i] + j) % 200;
            if (v[t].size() == 0) {
                if (find(v[j].begin(), v[j].end(), i) != v[j].end()) continue;
                v[t] = v[j];
                v[t].push_back(i);
            } else {
                if (find(v[j].begin(), v[j].end(), i) != v[j].end()) continue;
                b = v[j];
                b.push_back(i);
                c = v[t];
                goto END;
            }
        }
    }
END:

    if (b.size() != 0 && c.size() != 0) {
        cout << "Yes" << endl;
        std::sort(b.begin(), b.end());
        std::sort(c.begin(), c.end());
        cout << b.size() << " ";
        for (auto i : b) cout << i + 1 << " ";
        cout << endl << c.size() << " ";
        for (auto i : c) cout << i + 1 << " ";
        cout << endl;
    } else {
        cout << "No" << endl;
    }
}


//Ctrl+Shift+Bでコンパイル
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    long t,N;
    cin >> t >> N;
    long long ans = 0;

    long num = N/t;
    int num_a = N%t;
    if(num_a == 0){
        ans = num*(100+t) - 1;
    }
    else{
        ans = num*(100+t);
        double num_aa = double(num_a);
        double tt = double(t);

        vector<int> a ;
        int prs = 0;
        for(int i = 1; i < 100; i++){
            int buy = i*(100.0+tt)/100.0;
            if(buy == prs+1){
                prs = buy;
            }
            else{
                a.push_back(buy-1);
                prs = buy;
            }
        }

        ans += a.at(num_a-1);

    }

    cout << ans << endl;

}

#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<utility>
using namespace std;
#define pb push_back
#define mp make_pair
#define fs first
#define sec second
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define ll long long int
#define endl "\n"
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i, n) for(int i=n-1;i>=0;i--)
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pl;
typedef vector<int>     vi;
typedef vector<ll>      vl;
typedef vector<pii>     vpii;
typedef vector<pl>      vpl;
typedef vector<vi>      vvi;
typedef vector<vl>      vvl;
long long int mod=1000000007;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif

    ll t,n;
    cin>>t>>n;

    ll r=n*100;
    ll s=r%t;
    if(r%t)
      cout<<r/t+n<<endl;
      else
       cout<<r/t+n-1<<endl;

    return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>
#include <sstream>
#include <cstring>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <string.h>
#include <assert.h>
#include <iomanip>
#include <bitset>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
#define int long long
#define ull unsigned long long
#define F first
#define S second
#define nl "\n"
#define ld long double
#define sortv(v) sort(v.begin(),v.end())
#define rsortv(v) sort(v.rbegin(),v.rend())
#define all(v) v.begin(),v.end()
#define div 1000000007
#define div2 998244353
#define PI 3.141592653589793
#define inf 1000000000000000000LL
#define blk 320
#define pb push_back

void solve()
{
    int a,b,c,d;cin>>a>>b>>c>>d;
    if(d*c-b<=0)
    {
        cout<<-1;
        return;
    }
    int x=d*c-b;
    int ans=(a+x-1)/x;
    cout<<ans;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
        int t=1;
        //cin>>t;
        while(t--)
        {
            solve();
        }
}

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

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

  double n,x,y;
  cin>>n>>x>>y;

  double maxi=INT_MAX;
  while(n--)
  {

     double u,i;
     cin>>u>>i;
     maxi=min(maxi,x*((y-i)/(x-u)));

  }

  if((y-maxi)<0)
  cout<<0.0<<"\n";
 else
  cout<<y-maxi<<"\n";
}


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

int main(){
    long long int N, T;
    cin >> T;
    for(int i = 0; i < T; i++){
        cin >> N;
        if(N % 2 == 0){
            if(N % 4 == 0){
                cout << "Even" << endl;
            }else{
                cout << "Same" << endl;
            }
        }else{
            cout << "Odd" << endl;
        }
    }
    return 0;
}

#include  <map>
#include  <set>
#include  <math.h>
#include  <queue>
#include  <cstdio>
#include  <vector>
#include  <climits>
#include  <cstring>
#include  <cstdlib>
#include <ctime>

#include  <iostream>
#include  <algorithm>

#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
#define f(i,a,b) for( int i=a;i<=b;++i)
#define ff(i,a,b) for( int i=a;i>=b;--i)
#define debug(x) cerr << #x << " : " << x << " " << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
const ll mod = 1e9 + 7;
const ll mod2 = 998244353;
const ll inf = 2e18;
const double tiaohe = 0.57721566490153286060651209;
ll oula(ll x) { ll res = x;f(i, 2, x / i) { if (x % i == 0) { res = res / i * (i - 1);while (x % i == 0) x /= i; } }if (x > 1) res = res / x * (x - 1);return res; }
ll quickmod(ll a, ll n, ll m) { ll s = 1;while (n) { if (n & 1) { s = s * a % m; }a = (a*a) % m;n = n / 2; }return s; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
void ex_gcd(ll a, ll b, ll &x, ll &y, ll &d) { if (!b) { d = a, x = 1, y = 0; } else { ex_gcd(b, a % b, y, x, d);y -= x * (a / b); } }
ll inv(ll t, ll p) { ll d, x, y;ex_gcd(t, p, x, y, d);return d == 1 ? (x % p + p) % p : -1; }
bool isPrime(ll x) { if (x == 2)return true;if (x % 2 == 0)return false;for (ll i = 2;i*i <= x;i++) if (x % i == 0)return false; return true; }
inline ll in() { char ch = getchar();ll x = 0, f = 1;while (ch<'0' || ch>'9') { if (ch == '-')f = -1;ch = getchar(); }while (ch >= '0'&&ch <= '9') { x = x * 10 + ch - '0';ch = getchar(); }return x * f; }
void print(double x) { printf("%.6lf\n", x); }
//double a = log(n) +tiaohe + 1.0 / (2 * n);
double eqa = (1 + sqrt(5.0)) / 2.0;
double E = 2.7182818284;
const double eps = 1e-10;
const double pi = 3.1415926535;
const int N = 1e6 + 100;

int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
#endif
	int t;
	cin >> t;
	while (t--) {
		ll n;
		cin >> n;
		int num = 0;
		while (n % 2 == 0) {
			n /= 2;
			num++;
		}
		if (num == 1) {
			puts("Same");
		}
		else if (num >= 2) {
			puts("Even");
		}
		else puts("Odd");
	}
	return 0;
}


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

int main()
{
  string s;
  cin>>s;
  int ans=0;
  for(int i=0;i<=9999;i++)
  {
    bool flag[10]={false};
    int x=i;
    for(int j=0;j<4;j++)
    {
      flag[x%10]=true;
      x/=10;
    }

  int f2=1;
  for(int i=0;i<10;i++)
  {
    if(s[i]=='o'&&flag[i]==false)
      f2=0;
    if(s[i]=='x'&&flag[i])
      f2=0;
  }
    if(f2==1)
    ans+=1;
  }

  cout<<ans<<endl;

  return 0;
}

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define FOR(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v),end(v)
#ifdef NDEBUG
  #define assert(e) if(!(e)){stod("");}
#endif
#ifdef ONLINE_JUDGE
  #define debug(x)
  #define debug2(x,y)
  #define debug3(x,y,z)
#else
  #define debug(x) std::cerr<<#x<<": "<<x<<"\n"
  #define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
  #define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"
#endif

using ll=long long;
using vi=std::vector<int>;
using vvi=std::vector<vi>;
using vll=std::vector<ll>;
using vvll=std::vector<vll>;
template<typename T> using vvec=std::vector<std::vector<T>>;
template<typename T>
auto make_v(size_t sz){return std::vector<T>(sz);}
template<typename T,typename... Ts>
auto make_v(size_t sz,Ts...ts){return std::vector<decltype(make_v<T>(ts...))>(sz,make_v<T>(ts...));}
template<typename T>
void fill_v(T&var,const T&x){var=x;}
template<typename V,typename T>
void fill_v(V&v,const T&x){for(auto&& w:v){fill_v(w,x);}}

template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<std::vector<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<std::deque<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s, const std::set<T>&v){
  s<<"\n";for(auto&& elm:v){s<<elm<<"\t";}s<<"\n";return s;}

inline void scan(int&a){scanf("%d",&a);}
inline void scan(ll&a){scanf("%lld",&a);}
inline void scan(char&a){scanf(" %c",&a);}
inline void scan(double&a){scanf("%lf",&a);}
template<typename T>
inline void scan(std::vector<T>&v){for(auto&& sv:v){scan(sv);}}
template<typename First,typename...Args>
inline void scan(First&f,Args&...args){scan(f);scan(args...);}
inline void scan(std::string&s){char BUF[3000000];scanf(" %s",BUF);s=std::string(BUF);}
inline void print(int a){printf("%d\n",a);}
inline void print(ll a){printf("%lld\n",a);}
inline void print(double a){printf("%.12f\n",a);}
inline void print(std::string s){std::cout<<s<<"\n";}

using namespace std;

void solve() {
  int n, d, h;
  scan(n, d, h);
  vi x(n), y(n);
  rep (i, n) {
    scan(x[i], y[i]);
  }
  double ans = 0;
  rep (i, n) {
    double needed = y[i] - (double)(h - y[i]) / (d - x[i]) * x[i];
    ans = max(ans, needed);
  }
  print(ans);
}

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


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

inline ll read()
{
	ll f=1,x=0;char s=getchar();
	while(s<'0'||s>'9')
	{
		if(s=='-') f=-1;
		s=getchar();
	}
	while(s>='0'&&s<='9')
	{
		x=x*10+s-48;
		s=getchar();
	}
	return f*x;
}

ll mul(ll a,ll b,ll mod)
{
    ll res=0;
    while(b>0)
    {
        if(b&1) res=(res+a)%mod;
        a=(a+a)%mod;
        b>>=1;
    }
    return res;
}

ll exgcd(ll a,ll b,ll &x,ll &y)
{
    if(b==0){x=1;y=0;return a;}
    ll gcd=exgcd(b,a%b,x,y);
    ll tp=x;
    x=y; y=tp-a/b*y;
    return gcd;
}
int n=2;
ll ai[20],bi[20];

ll excrt()
{
    ll x,y,k;
    ll M=bi[1],ans=ai[1];
    for(int i=2;i<=n;i++)
    {
        ll a=M,b=bi[i],c=(ai[i]-ans%b+b)%b;
        ll gcd=exgcd(a,b,x,y),bg=b/gcd;
        if(c%gcd!=0) return -1;
        x=mul(x,c/gcd,bg);
        ans+=x*M;
        M*=bg;
        ans=(ans%M+M)%M;
    }
    return (ans%M+M)%M;
}

const ll LLINF=1ll<<62;
int main()
{
	int T=read();
	while(T--)
	{
		int x=read(),y=read(),p=read(),q=read();
		ll A=2*x+2*y,B=p+q;
		ll ans=LLINF;
		for(int i=0;i<y;i++)
			for(int j=0;j<q;j++)
			{
				ai[1]=i+x,bi[1]=A;
				ai[2]=j+p,bi[2]=B;
				ll res=excrt();
				if(res!=-1) ans=min(ans,res);
			}
		if(ans==LLINF) puts("infinity");
		else printf("%lld\n",ans);
	}
	return 0;
}


#include<bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i) < (n);(i)++)
#define repsec(i,m,n) for(int (i)=(m);(i) < (n);(i)++)
#define ll long long
#define mod 998244353
#define MOD 1000000007

using namespace std;

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

int main(){
  int n,ans;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i < n;i++){
    cin >> a[i];
    if(i == 0) ans = a[i];
    else ans = gcd(ans,a[i]);
  }
  cout << ans << endl;
  return 0;
}

//#pragma GCC optimize(4)
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define REP(u) for(int i=p[u];i!=-1;i=e[i].nxt)
#define ll long long
#define ull unsigned long long
#define PII pair<int,int>
#define rd (rand()<<16^rand())
#define pb push_back
#define iter multiset<int>::iterator
using namespace std;
inline int gi()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=(x<<3)+(x<<1)+(ch^48);
		ch=getchar();
	}
	return (f==1)?x:-x;
}
inline int max(int a,int b){return a>b?a:b;}
inline int min(int a,int b){return a<b?a:b;}
multiset<int>s;
int n,x;
int main()
{
	n=gi();
	FOR(i,1,n)
	{
		x=gi();
		s.insert(x);
	}
	while(s.size())
	{
		int x=*s.begin();
		iter it=s.end();
		--it;
		int y=*it;
		if(x==y)break;
		else {s.erase(y);s.insert(y-x);}
	}
	printf("%d\n",*s.begin());
	return 0;
}


#include <iostream>

using namespace std;

int main() {
	int H, W, aij;
	cin >> H >> W;
	int minblock = 1e9;
	int sum = 0;
	for (int i = 0; i < W; i++) {
		for (int j = 0; j < H; j++) {
			cin >> aij;
			minblock = min(aij, minblock);
			sum += aij;
		}
	}
	cout << sum - (minblock * H * W) << endl;
}

#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

#define max(a, b) (a < b? b : a)
#define min(a, b) ((a>b)?b:a)

#define MOD 1000000007

#define FOR(a,c)   for ( ll (a)=0; (a)<(c); (a)++)
#define FORL(a,b,c)  for ( ll (a)=(b); (a)<(c); (a)++)
#define FORR(a,b,c)  for (  ll (a)=(b); (a)>=(c); (a)--)

#define INF 9223372036854775807
//18446744073709551615
#define abs llabs
#define by_ANIKET ios::sync_with_stdio(false);  cin.tie(NULL); cout.tie(NULL);

#define no cout<<"NO\n";
#define yes cout<<"YES\n";

#define Clear( a, b ) memset( a, b, sizeof( a ) )
#define run if(1)cout<<__LINE__<<endl;

#define pr3(a,b,c) cerr<<#a<<"="<<a<<"\t"<<#b<<"="<<b<<"\t"<<#c<<"="<<c<<"\n";
#define pr2(a,b) cerr<<#a<<"="<<a<<"\t"<<#b<<"="<<b<<"\n";
#define pr1(a) cerr<<#a<<"="<<a<<"\n";
#define debug(x)       cerr<< #x <<" : "<< x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";
typedef unsigned long long ull;
typedef long long int ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;

#define F first
#define S second
#define PB push_back
#define POB pop_back
#define MP make_pair

inline long long  max3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  min3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}

void solve()
{
	int n,m,t=0,k=0,l,x=0,y=0,z=0;//,p,a1,a2,a3,a4,a5,ex,che,var=1,yd,f=INF,templ,tempr;
	cin>>n>>m;
	// vi a(n);
	// FOR(i,n)cin>>a[i];
	int a[n][m];
	z=100;
	FOR(i,n)
	{
		FOR(j,m)
		{
			cin>>a[i][j];
			z=min(z,a[i][j]);
		}
	}
	FOR(i,n)
	{
		FOR(j,m)
		{
			x+=(a[i][j]-z);
			// z=min(z,a[i][j]);
		}
	}
	cout<<x<<"\n";
}

int main()
{
	by_ANIKET
	ll T=1,t=0;
	// cin>>T;
	while(t++<T)
	{
		//cout<<"Case "<<t<<":"<<' ';
        solve();
        //cout<<'\n';
	}
	cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}
//   ©
//                      ______  __    __ ______ __    __ ________ ________
//                     /      \|  \  |  \      \  \  /  \        \        \
//                    |  ▓▓▓▓▓▓\ ▓▓\ | ▓▓\▓▓▓▓▓▓ ▓▓ /  ▓▓ ▓▓▓▓▓▓▓▓\▓▓▓▓▓▓▓▓
//  ______ ______     | ▓▓__| ▓▓ ▓▓▓\| ▓▓ | ▓▓ | ▓▓/  ▓▓| ▓▓__      | ▓▓
// |      \      \    | ▓▓    ▓▓ ▓▓▓▓\ ▓▓ | ▓▓ | ▓▓  ▓▓ | ▓▓  \     | ▓▓
//  \▓▓▓▓▓▓\▓▓▓▓▓▓    | ▓▓▓▓▓▓▓▓ ▓▓\▓▓ ▓▓ | ▓▓ | ▓▓▓▓▓\ | ▓▓▓▓▓     | ▓▓
//                    | ▓▓  | ▓▓ ▓▓ \▓▓▓▓_| ▓▓_| ▓▓ \▓▓\| ▓▓_____   | ▓▓
//                    | ▓▓  | ▓▓ ▓▓  \▓▓▓   ▓▓ \ ▓▓  \▓▓\ ▓▓     \  | ▓▓
//                     \▓▓   \▓▓\▓▓   \▓▓\▓▓▓▓▓▓\▓▓   \▓▓\▓▓▓▓▓▓▓▓   \▓▓


#include <stdio.h>
#include <vector>
#include <utility>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pl;

int main(void) {
  ll i, j, n, m, x, y, z, cnt;
  scanf("%lld%lld", &n, &m);
  vector<pl> vec[n + 1];
  ll dp[1 << n], sum[n];
  for(i = 0; i < 1 << n; ++i) dp[i] = 0;
  dp[0] = 1;
  for(i = 0; i < m; ++i) {
    scanf("%lld%lld%lld", &x, &y, &z);
    vec[x].push_back(make_pair(--y, z));
  }
  for(i = 0; i < 1 << n; ++i) {
    cnt = 0;
    for(j = 0; j < n; ++j) {
      sum[j] = i & (1 << j) ? 1 : 0, cnt += sum[j];
      if(j) sum[j] += sum[j - 1];
    }
    for(j = 0; j < vec[cnt].size(); ++j)
      if(sum[vec[cnt][j].first] > vec[cnt][j].second) dp[i] = 0;
    if(dp[i]) for(j = 0; j < n; ++j) if(!(i & (1 << j))) dp[i | (1 << j)] += dp[i];
  }
  printf("%lld", dp[(1 << n) - 1]);
  return 0;
}

#pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
// #include <atcoder/all>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vii = V<int>;
using vvll = V<vll>;
using vvii = V< V<int> >;
using PII = P<int, int>;
using PLL = P<ll, ll>;
#define RevREP(i,n,a) for(ll i=n;i>a;i--)  // (a,n]
#define REP(i,a,n) for(ll i=a;i<n;i++)  // [a,n)
#define rep(i, n) REP(i,0,n)
#define ALL(v) v.begin(),v.end()
#define eb emplace_back
#define pb push_back
#define sz(v) int(v.size())

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; }
template< class A, class B > ostream& operator <<(ostream& out, const P<A, B> &p) {
    return out << '(' << p.first << ", " << p.second << ')';
}
template< class A > ostream& operator <<(ostream& out, const V<A> &v) {
    out << '[';
    for (int i=0;i<int(v.size());i++) {
        if (i) out << ", ";
        out << v[i];
    }
    return out << ']';
}

template<class A, class B> istream& operator >>(istream& in, P<A, B> &p) {
    return in >> p.first >> p.second;
}
template<class A> istream& operator >>(istream& in, V<A> &v) {
    for (int i = 0; i < int(v.size()); i++) in >> v[i];
    return in;
}

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    V< V<PII> > xyz(n + 1);
    rep(i, m) {
        int x, y, z; cin >> x >> y >> z;
        xyz[x].eb(PII(y - 1, z));
    }

    vll dp(1 << n, 0);
    dp[0] = 1;
    rep(bit, 1 << n) {
        int tx = __builtin_popcount(bit);
        rep(i, n) {
            if (!(bit >> i & 1)) {
                ll tobit = bit | (1 << i);
                vii acc(n, 0);
                rep(j, n) if (tobit >> j & 1) acc[j]++;
                rep(j, n - 1) acc[j + 1] += acc[j];
                bool ok = true;
                for (auto [y, z]: xyz[tx + 1]) {
                    if (acc[y] > z) ok = false;
                }
                if (ok) dp[tobit] += dp[bit];
            }
        }
    }
    cout << dp.back() << '\n';
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0,endrep=(n); i<endrep; ++i)
#define rep1(i,n) for(ll i=1,endrep=(n); i<=endrep; ++i)
#define revrep(i,n) for(ll i=(ll)(n)-1; i>=0; --i)
inline constexpr ll Inf = (1ULL << 60) -123456789;
#define fastio cin.tie(0); ios_base::sync_with_stdio(false); cout<<fixed<<setprecision(10);
#define newl '\n'
#define YN(e) ((e)?"Yes":"No")
#define all(a) begin(a),end(a)
#define rall(a) rbegin(a),rend(a)
#define delif(c,pred) (c).erase(remove_if(all(c),(pred)), end(c))
template <class T,class U> bool updmax(T& a, U b) { if(b>a){ a=b; return true;} return false;}
template <class T,class U> bool updmin(T& a, U b) { if(b<a){ a=b; return true;} return false;}
inline constexpr int Mod = 1000000007;
//inline constexpr int Mod = 998244353;
#define dbg(a) cerr << #a << ": " << a << endl;
#define dbgs(s) cerr << #s << endl;
#define dbg1(a,n) cerr<<#a<<": "; rep(i,n) cerr<<a[i]<<" "; cerr<<endl;
#define dbg2(m,h,w) cerr<<#m<<":"<<endl; rep(i,h){ rep(j,w)cerr<<m[i][j]<<" "; cerr<<endl; }
template <class T, class U> ostream& operator << (ostream& os, pair<T,U> v) {os<<v.first<<","<<v.second;return os;}
template <class T, size_t N> ostream& operator << (ostream& os, array<T,N> v) {rep(i,N)os<<v[i]<<(i+1<(ll)N?" ":"");return os;}
int rng(int n) { return rand()/(RAND_MAX+1.0)*n; }

ll dp[1<<18];
int main() {
    fastio;
    ll ans{};
    ll N,M;
    cin >> N >> M;
    vector<vector<array<ll,2>>> m(N+1);
    rep(i,M) {
        ll x,y,z;
        cin >> x >> y >> z;
        m[x].push_back({y,z});
    }
    dp[0] = 1;
    rep(p,1<<N) {
        rep(j,N) {
            if (p>>j&1) continue;
            int to = p|(1<<j);
            dp[to] += dp[p];
            for (auto [y,z]:m[__builtin_popcount(p)+1]) {
                int c = to & ((1<<y)-1);
                if (__builtin_popcount(c) > z) {
                    dp[to] = 0;
                    break;
                }
            }
        }
    }
    ans = dp[(1<<N)-1];
    cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
static const int INF=1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
int A[200010];
int dp[200010];

int main(){
  int n,m;
  cin>>n>>m;
  rep(i,n) cin>>A[i];
  vector<int>edge[n];
  rep(i,m){
    int a,b;
    cin>>a>>b;
    a--;
    b--;
    edge[a].push_back(b);
  }
  rep(i,n) dp[i]=INF;
  for(int i=0;i<n;i++){
    for(auto j:edge[i]){
      dp[j]=min(dp[j],min(dp[i],A[i]));
    }
  }
  int ans=-INF;
  rep(i,n){
    if(dp[i] != INF){
      ans=max(ans,A[i]-dp[i]);
    }
  }
  cout<<ans<<endl;
  return 0;
}


#include<bits/stdc++.h>
#define re register
#define mod 998244353
#define eps (1e-10)
#define int long long
using namespace std;
#define N 100010
int n;
double f[N];
template <class T> inline void read(T &x)
{
	x=0;int g=1;char ss=getchar();
	for (;ss>'9'||ss<'0';ss=getchar()) if (ss=='-') g=-1;
	for (;ss<='9'&&ss>='0';ss=getchar()) x=(x<<1)+(x<<3)+(ss^48);
	x*=g;
}
signed main()
{
	read(n);
	f[1]=0;
	for(int i=2;i<=n;i++)
	{
		f[i]=f[i-1]*(n-i+1)/n+1;
		f[i]/=1-(i-1.0)/n;
	}
	printf("%.8lf",f[n]);
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  double sum = 0;
  for(int i = 1; i < N; i++){
    sum += double(1) / i;
  }
  cout << fixed << setprecision(7);
  cout << N * sum << endl;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    int a, b;
    cin >> a >> b;

    vector<int> x(200001, 0);
    for (int i = 1; i <= b; ++i) {
        x[i] = b / i - (a - 1) / i;
    }

    int ret = 1;
    for (int i = 1; i < 200001; ++i) {
        if (x[i] >= 2) {
            if (ret < i) ret = i;
        }
    }
    cout << ret << endl;

    return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <array>
#include <queue>
#include <cstring>
#include <unordered_map>
#include <set>
#include <climits>
#include <cmath>
using namespace std;
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define MOD 1000000007
#define MAX 100005
using ll = long long int;
#define all(x) (x).begin(), (x).end()

const int N = 1e3 + 1;

int main()
{
	speed;
	ll a, b;
	cin >> a >> b;
	ll total = 2 * a + 100;
	cout << total - b << '\n';

	return 0;
}


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

int solve(int nkr, int b, int a, int i) {
    if (nkr == 0) return 0;

    int cur = 1;
    while (true) {
        int we = nkr / cur;
        if (we < a) return -1;
        else if (we < b) return cur;

        cur++;
    }
}

int main() {
    int a, b, w;
    cin >> a >> b >> w;
    int w1000 = w * 1000;

    int INF =1001001001;
    int mi=INF;
    int bmax = w1000 / b;
    for (int i = bmax; i >= 0; --i) {
        int sol = solve(w1000 - i * b, b, a, i);
        if (sol != -1) { mi = i + sol; break; }
    }

    int ma;
    int amax = w1000 / a;
    for (int i = amax; i >= 0; --i) {
        int sol = solve(w1000 - i * a, b, a, i);
        if (sol != -1) { ma = i + sol; break; }
    }

    // if (w1000/a == w1000/b) cout << "UNSATISFIABLE" << endl;
    if (mi==INF) cout << "UNSATISFIABLE" << endl;
    else cout << mi << " " << ma << endl;
}

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

int main() {
    ld a,b,c,d;
    std::cin >> a>>b>>c>>d;

    d *= -1;

    std::cout <<setprecision(20)<< -b*(c-a)/(d-b)+a << std::endl;
}