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

int main(){
  int n,x;
  cin >> n >> x;
  rep(i,n){
    int a;
    cin >> a;
    if(a!=x) cout << a << " ";
  }
  cout << endl;
}

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

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (ll i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (ll i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;

//const ll MOD = 1000000007;
const ll MOD = 998244353;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        return mint(*this) /= a;
    }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

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

    int n, k;
    cin >> n >> k;
    vll a(n);
    REP(i, n) cin >> a[i];

    mint div = 1;
    vector<mint> s(k + 1);
    s[0] = n;

    vector<vector<mint>> p(k + 1, vector<mint>(n, 1));
    FOR(i, 1, k + 1) {
        div *= i;
        REP(j, n) {
            p[i][j] = p[i-1][j] * a[j];
            s[i] += p[i][j];
        }
        s[i] /= div;
    }

    mint f = 2;
    FOR(x, 1, k+1) {
        mint ans = 0;
        mint fact = 1;

        REP(i, x + 1) {
            ans += s[i] * s[x - i];
            if (i > 0) fact *= i;
        }

        ans *= fact;

        REP(i, n) {
            ans -= p[x][i] * f;
        }
        f *= 2;

        ans /= 2;

        print(ans);
    }
}


// #include <atcoder/all>
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
    return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
    return a > b && (a = b, true);
}
/*-------------------------------------------*/

int n;
ll a[200009], b[200009];

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

    cin >> n;
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];

    ll sum = 0;
    rep(i, n) sum += a[i];

    vector<int> odd, even;
    rep(i, n)(i & 1 ? odd : even).push_back(b[i] - a[i]);

    sort(ALL(odd), greater<int>());
    sort(ALL(even), greater<int>());

    ll ans = sum;
    rep(i, n / 2) chmax(ans, sum += odd[i] + even[i]);

    cout << ans << endl;

    return 0;
}

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int h, w, n, m;
    cin >> h >> w >> n >> m;
    vector<int> A(n), B(n), C(m), D(m);
    vector<vector<int>> g(h + 2, vector<int>(w + 2, 0));
    for (int i = 0; i < n; ++i) {
        cin >> A[i] >> B[i];
        g[A[i]][B[i]] = 1;
    }
    for (int i = 0; i < m; ++i) {
        cin >> C[i] >> D[i];
        g[C[i]][D[i]] = -1;
    }

    auto x = g;
    for (int i = 0; i < h; ++i) {
        int c = 0;
        for (int j = 0; j < w; ++j) {
            x[i + 1][j + 1] += c;
            if (g[i + 1][j + 1] >= 0) c += g[i+1][j+1];
            else c = 0;
        }
    }
    for (int i = 0; i < h; ++i) {
        int c = 0;
        for (int j = w-1; j >= 0; --j) {
            x[i + 1][j + 1] += c;
            if (g[i + 1][j + 1] >= 0) c += g[i+1][j+1];
            else c = 0;
        }
    }
    for (int j = 0; j < w; ++j) {
        int c = 0;
        for (int i = 0; i < h; ++i) {
            x[i + 1][j + 1] += c;
            if (g[i + 1][j + 1] >= 0) c += g[i+1][j+1];
            else c = 0;
        }
    }
    for (int j = 0; j < w; ++j) {
        int c = 0;
        for (int i = h-1; i >= 0; --i) {
            x[i + 1][j + 1] += c;
            if (g[i + 1][j + 1] >= 0) c += g[i+1][j+1];
            else c = 0;
        }
    }
    int ans = 0;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if(g[i+1][j+1] >= 0)ans += x[i+1][j+1] > 0;
        }
    }
    cout << ans << "\n";
    return 0;
}


#include<iostream>
#include<sstream>
#include<iomanip>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<numeric>
#include<queue>

#define rep(i,p) for(long long int i=0;i<p;i++)
#define reep(i,p) for(long long int i=1;i<=p;i++)
#define ll long long
#define MOD 1000000007

using namespace std;

int main(){

ll int N;
cin >> N;

ll int count = 0;
ll int kari;
map< ll int, ll int > ma;
for( ll int i = 2; i*i <= N; i++){
	kari = i;
	kari *= i;
	while( kari <= N && ma[kari] != 1 ){
		ma[kari]=1;
		count += 1;
		kari *= i;
	}
}

cout << N - count;

	return 0;

}

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

#define int long long int
#define double long double

#define all(x) begin(x), end(x)
#define Done(x) cout<<x<<endl; return;
#define endl '\n'

void solve(){
	int n; cin>>n;
	int m; cin>>m;
	map<int,int>occur;
	for(int i=0;i<n;i++){
		int a; cin>>a;
		int b; cin>>b; b++;
		int c; cin>>c;
		occur[a]+=c;
		occur[b]-=c;
	}
	int ans=0;
	int curr=0;
	int last=0;
	for(auto p:occur){
		int dist=p.first-last;
		ans+=dist*min(curr,m);
		last=p.first;
		curr+=p.second;
	}
	cout<<ans<<endl;
}

int32_t main(){
	// Remove for Interactive Problems
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);

	solve();

	cerr<<"Time : "<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms\n";
	return 0;
}


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

void chmin(int64_t& a, int64_t b) {
  if (a > b) a = b;
}

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

  vector<int64_t> h(n);
  vector<int64_t> w(m);
  for (int64_t i = 0; i < n; i++) cin >> h.at(i);
  for (int64_t i = 0; i < m; i++) cin >> w.at(i);

  sort(h.begin(), h.end());
  sort(w.begin(), w.end());
  int64_t ans = 1e16;

  vector<int64_t> sum1((n+1)/2, 0), sum2((n+1)/2, 0);
  for (int i = 0; i < n-1; i += 2) {
    sum1.at(i / 2 + 1) = sum1.at(i / 2) + h.at(i+1) - h.at(i);
  }
  for (int i = n-2; i > 0; i -= 2) {
    sum2.at(i / 2) = sum2.at(i / 2 + 1) + h.at(i+1) - h.at(i);
  }

  for (int64_t y : w) {
    int64_t x = lower_bound(h.begin(), h.end(), y) - h.begin();
    if (x & 1) x ^= 1;
    chmin(ans, sum1.at(x / 2) +  sum2.at(x / 2) + abs(h.at(x) - y));
  }

  cout << ans << endl;

  return 0;
}

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

typedef pair<int,int> pii;
typedef pair<string,int> psi;
typedef pair<int,string> pis;
typedef array<int,2> aii;
typedef array<int,3> aiii;
typedef array<int,4> aiiii;
typedef unsigned long long ull;
typedef long long int ll;
typedef array<ll,2> all;
typedef array<ll,3> alll;
typedef array<ll,4> allll;

#define pb push_back
#define ff first
#define ss second
#define MAX 300005
#define MOD 1000000007
#define INF 2e9
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
vector<aii>adj[MAX];
int xMove[] = { 0,1,0,-1,1,1,-1,-1, 2, 2, -2, -2, 1, 1, -1, -1 };
int yMove[] = { 1,0,-1,0,1,-1,1,-1, 1, -1, 1, -1, 2, -2, 2, -2 };

int main()
{
    //freopen("input.in","r",stdin);
    //freopen("output.txt","w",stdout);
    cin.tie(0),cout.tie(0);
    ios_base::sync_with_stdio(0);
    cout.setf(ios::fixed);
    cout.precision(10);
    int TC=1;
    int n,m,k;

    //cin>>TC;
    for(int t1=1; t1<=TC; t1++)
    {
        cin>>n>>m;
        int arr[n],w[m];
        for(int i=0;i<n;i++)
            cin>>arr[i];
        for(int i=0;i<m;i++)
            cin>>w[i];

        sort(arr,arr+n);

        ll csum[n][2];
        memset(csum,0,sizeof csum);
        for(int i=1;i<n;i++)
        {
            if(i&1)
                csum[i][0]=arr[i]-arr[i-1];
            csum[i][0]+=csum[i-1][0];
        }
        for(int i=2;i<n;i++)
        {
            if(i%2==0)
                csum[i][1]=arr[i]-arr[i-1];
            csum[i][1]+=csum[i-1][1];
        }

        ll ans=1e18;
        for(int i=0;i<m;i++)
        {
            int pos=lower_bound(arr,arr+n,w[i])-arr;
            if(pos&1)
            {
                ll cur=w[i]-arr[pos-1];
                cur+=csum[pos-1][0];
                cur+=csum[n-1][1]-csum[pos-1][1];
                ans=min(ans,cur);
            }
            else
            {
                ll cur=arr[pos]-w[i];
                cur+=csum[pos][0];
                cur+=csum[n-1][1]-csum[pos][1];
                ans=min(ans,cur);
            }
        }

        cout<<ans<<"\n";
    }

    return 0;
}


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

int main(){
	int n, w;
	cin >> n >> w;
	vector<pair<int, int>>sim;

	for(int i = 0; i<n; ++i){
		int s, t, p;
		cin >> s >> t >> p;
		sim.push_back(make_pair(s, p));
		sim.push_back(make_pair(t, -p));
	}

	sort(sim.begin(), sim.end());

	ll curr = 0;
	for(auto i : sim){
		curr += i.second;
		if(curr > w){
			cout << "No";
			return 0;
		}
	}

	cout << "Yes";
	return 0;
}

/*
https://atcoder.jp/contests/abc200/tasks/abc200_e

## 題意：

## 思路：

*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 0x3fffffff;
const ll LINF = 9223372036854775807;
#define dump(x) cout << #x << " = " << (x) << endl
#define ALL(x) begin(x),end(x)
#define rep(i,s,e) for(ll i=(s); i<=(e); ++i)
#define repRev(i,s,e) for(ll i=(s); i>=(e); --i)
#define range(i,s,n) for(ll i=(s), i_stop=(s)+(n); i<i_stop; ++i)
#define rangeRev(i,s,n) for(ll i=(s), i_stop=(s)-(n); i>i_stop; --i)
template<typename T> bool chmax(T& a, const T b) {if(a<b) {a=b;return true;} return false;}
template<typename T> bool chmin(T& a, const T b) {if(a>b) {a=b;return true;} return false;}

int n,m;
list<pair<int,int>> restri[110];

bool check(int msk) {
    int l=0; vector<int> tot(n+1, 0);
    range(i,0,n) if(msk & (1<<i)) {
        ++l; ++tot[i];
    }
    rep(i,1,n-1) tot[i] += tot[i-1];

    for(auto &p:restri[l]) {
        auto [y,z] = p;
        if(tot[y] > z) return false;
    }
    return true;
}

void solve() {
    cin>>n>>m;

    range(i,0,m) {
        int x,y,z; cin>>x>>y>>z;
        restri[x].push_back({y-1,z});
    }

    vector<ll> dp(1<<n, 0); dp[0] = 1;
    range(msk, 0, 1<<n) range(nxt, 0, n) if(!(msk & (1<<nxt))) {
        if(check(msk | (1<<nxt)))
            dp[msk | (1<<nxt)] += dp[msk];
    }

    cout<<dp[(1<<n)-1]<<endl;
}

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


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;
ll comb(ll a, ll b){
  ll ans = 1;
  for(int i=1;i<=b;i++){
    ans = ans * a / i;
    a--;
  }
/*  for(int i=1;i<=b;i++){
    ans = ans / i;
  }*/
  return ans;
}
int main()
{
  ll L; cin >> L;
  cout << comb(L-1,11)<< endl;
}

#include <iostream>
#include <vector>
#include <cstdint>

int main() {
  constexpr int N = 12;
  int L;
  std::cin >> L;
  std::vector<std::vector<std::int64_t>> counts(L + 1, std::vector<std::int64_t>(N + 1));
  counts[0][0] = 1;
  for (int i = 1; i <= L; ++i) {
    for (int j = 0; j < i; ++j) {
      for (int k = 1; k <= N; ++k) {
        counts[i][k] += counts[j][k - 1];
      }
    }
  }
  std::cout << counts[L][N] << std::endl;
  return 0;
}


// C++(GCC 9.2.1)
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
LL a[303030];

// ※※※ 以下のライブラリを使用(一部改変) ※※※.
// 遅延評価セグメント木をソラで書きたいあなたに.
// http://tsutaj.hatenablog.com/entry/2017/03/30/224339
// http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2236726
struct LazySegmentTree{
private:
    int n;
    vector<LL> node, lazy;
public:
    LazySegmentTree(vector<LL> v){
        int sz = (int)v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2 * n - 1);
        lazy.resize(2 * n - 1, 0);
        // 元配列 の 値 を, セグメント木のノード に 保存.
        rep(i, sz) node[i + n - 1] = v[i];
        repr(i, n - 2, 0) node[i] = node[i * 2 + 1] ^ node[i * 2 + 2];
    }
    void eval(int k, int l, int r){
        if(lazy[k] != 0) {
            node[k] ^= lazy[k];
            if(r - l > 1) {
                lazy[2 * k + 1] ^= lazy[k] / 2;
                lazy[2 * k + 2] ^= lazy[k] / 2;
            }
            lazy[k] = 0;
        }
    }
    void update(int a, int b, LL x, int k = 0, int l = 0, int r = -1){
        if(r < 0) r = n;
        eval(k, l, r);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b){
            lazy[k] += (r - l) * x;
            eval(k, l, r);
        }else{
            update(a, b, x, 2 * k + 1,           l, (l + r) / 2);
            update(a, b, x, 2 * k + 2, (l + r) / 2,           r);
            node[k] = node[2 * k + 1] ^ node[2 * k + 2];
        }
    }
    LL query(int a, int b, int k = 0, int l = 0, int r = -1){
        if(r < 0) r = n;
        eval(k, l, r);
        if(b <= l || r <= a) return 0;
        if(a <= l && r <= b) return node[k];
        LL vl = query(a, b, 2 * k + 1,           l, (l + r) / 2);
        LL vr = query(a, b, 2 * k + 2, (l + r) / 2,           r);
        return vl ^ vr;
    }

};

int main(){

    // 1. 入力情報.
    int N, Q;
    scanf("%d %d", &N, &Q);
    rep(i, N) scanf("%lld", &a[i]);

    // 2. 遅延評価セグメント木.
    LazySegmentTree seg(vector<LL>(N, 0));
    rep(i, N) seg.update(i, i + 1, a[i]);

    // 3. クエリ回答.
    rep(i, Q){
        int t;
        scanf("%d", &t);

        // t = 1 の 場合.
        if(t == 1){
            int x;
            LL y;
            scanf("%d %lld", &x, &y);
            x--;
            seg.update(x, x + 1, y);
        }

        // t = 2 の 場合.
        if(t == 2){
            int x, y;
            scanf("%d %d", &x, &y);
            x--;
            LL ans = seg.query(x, y);
            printf("%lld\n", ans);
        }
    }
    return 0;

}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<pair<int, int>> vii;
typedef pair<int, int> pi;
#define MOD 1000000007LL

int N, Q; int n2;
int stree[1200000]={};

void add(int v, int i) {
    i += n2;
    for (; i >= 1; i /= 2) stree[i] ^= v;
}

int sum(int a, int b) {
    a += n2; b += n2;
    int s = 0;
    while (a <= b) {
        if (a%2 == 1) s ^= stree[a++];
        if (b%2 == 0) s ^= stree[b--];
        a /= 2; b /= 2;
    }
    return s;
}

int main() {
    //freopen("feast.in", "r", stdin);
    //freopen("feast.out", "w", stdout);
    //ios_base::sync_with_stdio(false);
    //cin.tie(0);

    cin >> N >> Q;
    n2 = 1; while (n2 <= N) n2 *= 2;
    for (int i = 1; i <= N; i++) {
        int x; cin >> x; add(x, i);
    }
    while (Q--) {
        int T, X, Y; cin >> T >> X >> Y;
        if (T==1) {
            add(Y, X);
        } else {
            cout << sum(X, Y) << endl;
        }
    }
}


#include<cstdio>
#include<functional>
#include<utility>
#include<algorithm>
#include<set>
using namespace std;
using ll = long long;
using ull = unsigned long long;

int main(){
    int N, M;
    scanf("%d %d", &N, &M);
    pair<int, int> pawn[M];
    for (unsigned i = 0; i < M; i++) scanf("%d %d", &pawn[i].first, &pawn[i].second);
    set<int> valid_y;
    valid_y.insert(N);
    sort(pawn, pawn + M);
    bool pawn_exists_in_front = false, pawn_exists_in_left;
    for(unsigned i = 0;i < M;i++){
        pawn_exists_in_left = pawn_exists_in_front;
        pawn_exists_in_front = (valid_y.find(pawn[i].second) != valid_y.end()) && i < M-1 && pawn[i+1] == make_pair(pawn[i].first, pawn[i].second + 1);
        if(((i && pawn[i-1] == make_pair(pawn[i].first, pawn[i].second - 1)) ? pawn_exists_in_left : (valid_y.find(pawn[i].second - 1) != valid_y.end())) || (valid_y.find(pawn[i].second + 1) != valid_y.end())) valid_y.insert(pawn[i].second);
        else valid_y.erase(pawn[i].second);
    }
    printf("%u\n", valid_y.size());
	return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
long long n, k;
int arr[9][9] = {0,};
int visited[9]={0,};
int answer=0;
void dfs(int node, long long times){
  if(node<0 || node>=n || times>k){return;}
  if(visited[node]==1) return ;
  for(int i=0; i<n; i++){
    if(i == node){continue;}
    if(i==0 && visited[i]==1 && times+arr[node][i] == k){
      answer++;
      continue;
    }
    if(visited[i]==0){
        visited[node] =1;
        dfs(i, times+arr[node][i]);
        visited[node] = 0;

    }
  }
  return;
}
int main(){

  cin>>n>>k;
  for(int i=0; i<n; i++){
    for(int j=0; j<n; j++){
      cin>> arr[i][j];
    }
  }
  dfs(0,0);
  cout <<answer<<endl;
}


#include <bits/stdc++.h>
using namespace std;
int main(){

  int n;
  cin >> n;
  vector<long long> a(n), s(n+1, 0);
  for(auto &x : a) cin >> x;
  sort(a.rbegin(), a.rend());
  for(int i = 0; i < n; ++i){
    s[i+1] = s[i] + a[i];
  }
  long long ans = 0;
  for(int I = 1; I <= n; ++I){
    int i = I-1;
    ans += (n-I)*a[i] - (s[n]-s[I]);
  }
  cout << ans << '\n';

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<LD> VLD;
typedef vector<string> VS;
#define rep(i, min, max) for (int i = min; i < (int)(max); i++)

int main()
{
  LL N;
  cin>>N;
  VL X(N);
  for(LL& x: X) cin>>x;

  LL m = 0;
  rep(i,0,N) m += abs(X.at(i));

  LD e = 0;
  rep(i,0,N) e += X.at(i)*X.at(i);
  e = sqrt(e);

  LL c = 0;
  rep(i,0,N) c = max(c, abs(X.at(i)));

  cout<<fixed<<setprecision(0)<<m<<endl;
  cout<<fixed<<setprecision(15)<<e<<endl;
  cout<<fixed<<setprecision(0)<<c<<endl;

  return 0;
}


#include<iostream>
#include<iterator>
#include<set>
using namespace std;
int main()
{
	long n;
	cin >> n;
	set<long>ans;
	for(long d=1;d*d<=n;d++){
		if(n%d==0){
			ans.insert(d);
			ans.insert(n/d);
		}
	}

	for(auto x:ans)cout << x << endl;
}

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<bitset>
#include<cmath>
#include<ctime>
#include<queue>
#include<map>
#include<set>

#define int long long
#define lowbit(x) (x&(-x))
#define mid ((l+r)>>1)
#define lc (x<<1)
#define rc (x<<1|1)
#define max Max
#define min Min
#define abs Abs

using namespace std;

inline int read()
{
	int ans=0,f=1;
	char c=getchar();
	while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){ans=(ans<<1)+(ans<<3)+c-'0';c=getchar();}
	return ans*f;
}

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

template<typename T>inline T Abs(T a){return a>0?a:-a;};
template<typename T,typename TT>inline T Min(T a,TT b){return a>b?b:a;}
template<typename T,typename TT> inline T Max(T a,TT b){return a>b?a:b;}

int n,ans;

signed main()
{
	n=read();
	for(int i=1;i<=n;++i)
	{
		int p=i;
		int f1=1,f2=1;
		while(p)
		{
			if(p%10==7) f1=0;
			p/=10;
		}
		p=i;
		while(p)
		{
			if(p%8==7) f2=0;
			p/=8;
		}
		if(f1&&f2) ans++;
	}
	printf("%lld\n",ans);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
using ll = int64_t;

set<int> divisors(int M) {
    set<int> r;
    for (int i = 1; i * i <= M; ++i) {
        if (M % i != 0) continue;
        r.insert(i);
        r.insert(M / i);
    }
    return r;
}

int N;
vector<int> A;

int gcd(int a, int b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}

int solve() {
    int const L = *min_element(A.begin(), A.end());
    map<int,int> mp;
    for (auto a : A) {
        auto ds = divisors(a);
        for (auto v : ds) {
            if (v > L) continue;
            if (mp.count(v)) {
                mp[v] = gcd(mp[v],a);
            } else {
                mp[v] = a;
            }
        }
    }
    int ans = 0;
    for (auto e : mp) {
        int v, a;
        tie(v, a) = e;
        if (v == a) ++ans;
    }
    return ans;
}

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

    cin >> N;
    A.assign(N, 0);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    cout << solve() << endl;

    return 0;
}

#include <iostream>
#include <map>
using namespace std;
long long int parejas;
long long int n, aux;
map<int, long long int> arre;
int main()
{
    cin>>n;
    for(int i=1;i<=n;++i){
        cin>>aux;
        arre[aux]++;
    }
    aux=0;
    for(pair<int, long long int> recorre : arre){
        parejas+=((recorre.second*(n-recorre.second))-(aux*recorre.second));
        aux+=recorre.second;
    }
    cout<<parejas;
    return 0;
}


#pragma region templates
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using PQR = priority_queue<T,vector<T>,greater<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007; // 998244353;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const ld PI = acos((ld)-1);
constexpr ll dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
inline void Yes() { cout << "Yes" << ENDL; }
inline void No() { cout << "No" << ENDL; }
inline void YES() { cout << "YES" << ENDL; }
inline void NO() { cout << "NO" << ENDL; }

template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template <typename T>
vector<T> finddivisor(T x) {  //整数xの約数(xを含む)
  vector<T> divisor;
  for(T i = 1; (i * i) <= x; i++) {
    if(x % i == 0) {
      divisor.push_back(i);
      if(i * i != x) { divisor.push_back(x / i);}
    }
  }
  sort(divisor.begin(), divisor.end());
  return divisor;
}

template <typename T> V<T> prefix_sum(const V<T>& v) {
  int n = v.size();
  V<T> ret(n + 1);
  rep(i, 0, n) ret[i + 1] = ret[i] + v[i];
  return ret;
}

template<typename T>
T rand(T l,T r){
  static random_device rd;
  static mt19937 g(rd());
  return uniform_int_distribution<T>(l,r)(g);
}//[]

template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(auto&& x: vec) is >> x;
  return is;
}

template<typename T,typename Y>
ostream& operator<<(ostream& os,const pair<T,Y>& p){
  return os<<"{"<<p.fs<<","<<p.sc<<"}";
}

template<typename T> ostream& operator<<(ostream& os,const V<T>& v){
  os<<"{";
  for(auto e:v)os<<e<<",";
  return os<<"}";
}

template<typename ...Args>
void debug(Args&... args){
  for(auto const& x:{args...}){
    cerr<<x<<' ';
  }
  cerr<<ENDL;
}
#pragma endregion templates

signed main(){
  cin.tie(0);cerr.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n;cin>>n;
  V<ll> l(n),r(n);
  rep(i,0,n){
    ll t,a,b;cin>>t>>a>>b;
    a*=2;
    b*=2;
    if(t==1){
      l[i]=a;
      r[i]=b;
    }else if(t==2){
      l[i]=a;
      r[i]=b-1;
    }else if(t==3){
      l[i]=a+1;
      r[i]=b;
    }else{
      l[i]=a+1;
      r[i]=b-1;
    }
  }

  ll ans=0;
  rep(i,0,n){
    rep(j,i+1,n){
      if(!(r[i]<l[j]||r[j]<l[i])){
        ++ans;
      }
    }
  }
  cout<<ans<<ENDL;
}
//(・_・)(・_・)(・_・)(・_・)
//CHECK overflow,what to output?
//any other simpler approach?

#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define all(v) v.begin(), v.end()
#define rep(i, begin, end) for(auto i = begin; i < (end); i++)
#define contains(v, x) (find(all(v), x) != v.end())
template<class T> bool chmin(T& a, T b){ if (a > b){ a = b; return true; } return false; }
template<class T> bool chmax(T& a, T b){ if (a < b){ a = b; return true; } return false; }
template<class T> T roundup(T a, T b){ return (a + b - 1) / b; }
const vector<int> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
const vector<int> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};
using ll = long long;
const ll INF = 1e9;
const double EPS = 1e-10;
/* #include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;
using d32 = mp::number<mp::cpp_dec_float<32>>; */
const ll MOD = 1e9 + 7;
/* #include <atcoder/all>
using namespace atcoder;
using mint = modint1000000007; */
using P = pair<int, int>;
struct Edge{ int to; ll cost; Edge(int to, ll cost) : to(to), cost(cost) {} };
using Graph = vector<vector<int>>;

struct seg{  int t, l, r; };

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

    int n;
    cin >> n;
    vector<seg> s(n);
    for(auto&& [t, l, r] : s) cin >> t >> l >> r;

    sort(all(s), [&](seg a, seg b){ return a.r < b.r; });
    int ans = 0;
    rep(i, 0, n) rep(j, i + 1, n){
        if(s[i].r > s[j].l) ans++;
        else if(s[i].r == s[j].l && (s[i].t == 1 || s[i].t == 3) && (s[j].t == 1 || s[j].t == 2)) ans++;
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>
#include <chrono>

using namespace std;
using namespace chrono;

typedef long long int ll;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define pb push_back
#define odd(x) ((x)&1)
#define even(x) (!odd(x))
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(auto i=0;i<n;++i)
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define TEST_CASE int tc;cin>>tc;while(tc--)
#define Clock high_resolution_clock::now()

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

#ifdef LOCAL
#define cerr cout
#else
#endif

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
// #define TIME

/******************************************************************************************************************************/

const ll inf = 2e18;
const ll mod = 1e9+7;
const ll N = 2e6;

int main()
{
    auto start_time = Clock;
    FASTIO

    ll S,ans{0}; cin >> S;
    for(ll i=1;i<N;++i) {
    	ll n = 2*S+i-i*i;
    	ll d = 2*i;
    	if(n>0 && n%d==0) ans += 2;
    }

    cout << ans << "\n";

    auto end_time = Clock;
    #ifndef TIME
        return 0;
    #endif
    cout << "\nTime elapsed: "
    << (double)duration_cast<milliseconds>(end_time-start_time).count()
    << "ms";

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define ld long double
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define vl vector<lli>
#define vll vector<pair<lli,lli>>
#define vlll vector<pair<pair<lli,lli>,lli>>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

////////////////////////////////////////////////////////    By: Umang Srivastava

// lli extgcd(lli a, lli b, lli *x , lli *y)
// {
//   if(a==0)
//   {
//     *x=0;
//     *y=1;
//     return b;
//   }
//   lli x1 , y1;
//   lli gcd = extgcd(b%a , a , &x1 , &y1);
//   *x= y1 - (b/a) * x1;
//   *y=x1;
//   return gcd;
// }

// lli modinv(lli a, lli m)
// {
//   lli x,y;
//   lli g = extgcd(a,m,&x,&y);
//   if(g!=1)
//     return -1;
//   return (x%m+m)%m;
// }

// lli moddiv(lli a, lli b, lli m)
// {
//   a=a%m;
//   lli inv = modinv(b,m);
//   if(inv!=-1)
//     return ((a*inv + m)%m);
//   else
//     return -1;
// }

// lli binpow(lli a, lli b, lli m)
// {
//  lli res=1;
//  a=a%m;
//  while(b>0)
//  {
//    if(b & 1)
//    {
//      res = (res * a)%m;
//    }
//    b=b>>1;
//    a=(a*a)%m;
//  }
//  return res;
// }

// lli gcd(lli a, lli b)
// {
//     // if(b<a)
//     // {
//     //     lli t=a;
//     //     a=b;
//     //     b=t;
//     // }
//     if(a==0)
//         return b;
//     return gcd(b%a,a);
// }

// lli fac[1000005];
// void calcfac(lli m)
// {
//  fac[0]=1;
//  for(lli i=1;i<=1000001;i++)
//  {
//    fac[i]=(fac[i-1]*i)%m;
//  }
// }

// lli ncr(lli n,lli r,lli m)
// {
//   if(r==0 || r==n)
//     return 1;
//   return (((fac[n]*binpow(fac[r],m-2,m))%m)*(binpow(fac[n-r],m-2,m)))%m;
// }

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

int main()
{
  fastio
  lli n,m,i,j,k,t,a,b,c,d,x,y,q;
  t=1;
//   cin>>t;
  while(t--)
  {
    cin>>n;
    a=0;
    n*=2;
    set<lli>st;
    for(i=1;i*i<=n;i++)
    {
      if(n%i!=0)
      continue;
      a=n/i;
      if(a%2 == i%2)
      continue;
      st.insert(i);
    }
    cout<<2*st.size()<<endl;
  }

}


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

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define pb push_back
#define S second
#define F first
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vll vector<long long int>
#define vld vector<long double>
#define pll pair<long long int,long long int>
/* unordered_map<int,int>mp; mp.reserve(1024); mp.max_load_factor(0.25); */
#define mod 1000000007
#define mod2 998244353
#define ll long long int
#define ld long double
#define pi 3.141592653589793238
#define Endl endl
#define endl "\n"
const int N = 1e2 + 15;
const ll inf = 1e18;

vll a[N];
ll ans = 1;
vll done(N);
ll limit;
vll comp;
vll color(N);
void dfs(ll u)
{
        done[u] = true;
        for(auto v:a[u])
        {
                if(!done[v])
                        dfs(v);
        }
        comp.pb(u);
}

ll recur(ll idx)
{
        if(idx == limit)
                return 1ll;
        ll u = comp[idx];
        ll ans = 0;
        for(ll col = 0; col < 3; col++)
        {
                bool chk = true;
                for(auto v:a[u])
                {
                        if(color[v] == col)
                                chk = false;
                }
                if(chk)
                {
                        color[u] = col;
                        ans += recur(idx+1);
                        color[u] = -1;
                }
        }
        return ans;
}

void solve()
{
        ll n , m;
        cin >> n >> m;
        for(ll i=1;i<=m;i++)
        {
                ll u,v;
                cin >> u >> v;
                a[u].pb(v);
                a[v].pb(u);
        }
        ll ret = 1;
        for(ll i=1;i<=n;i++)
        {
                if(done[i] == 0)
                {
                        comp.clear();
                        dfs(i);
                        reverse(comp.begin(),comp.end());
                        limit = comp.size();
                        for(ll i=0;i<N;i++)
                                color[i] = -1;
                        ret *= recur(0);
                }
        }
        cout << ret;
}

void debug(ll tt) {}

signed main()
{
        FAST;
        ll t = 1;
        // cin >> t;
        while(t--)
        {
                solve();
        }
}
// freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);

// D - RGB Coloring 2
// sample code
// reference: https://atcoder.jp/contests/abc199/submissions/22053625
#include <bits/stdc++.h>
using namespace std;
#define vec vector
using vi = vec<int>;
using ll = int64_t;
#define rep(i,e) for(int i=0;i<(e);++i)

vec<vi> G;
vi IX; //dfs の順を記録。違う連結成分になら同じ index もある

ll dfs(int now, vi&v){
	for(int to:G[now]) if(v[to] == v[now]) return 0;
	ll res = 1;
	for(int to:G[now]){
		if(IX[to] == -1) IX[to] = IX[now] + 1;
		if(IX[to] == IX[now] + 1){
			ll tmp = 0;
			v[to] = (v[now] + 1) % 3;
			tmp += dfs(to, v);
			v[to] = (v[now] + 2) % 3;
			tmp += dfs(to, v);
			v[to] = -1;
			res *= tmp;
			if (tmp == 0) break;
			// tmp == 0 の時、早期に return してるので
			// IX が振り切れていない事に注意
		}
	}
	return res;
}

int main(){
	int n, m; cin>>n>> m;
	G.resize(n);
	rep(i, m){
		int a, b; cin>>a>>b; --a, --b;
		G[a].push_back(b);
		G[b].push_back(a);
	}

	IX.resize(n, -1);
	vi v(20, -1);
	ll ans = 1;
	rep(i, n){
		if(IX[i] != -1) continue;
		IX[i] = v[i] = 0;
		ans *= dfs(i, v) * 3;
	}
	cout<< ans <<endl;
}


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

void DBG() { cerr << endl; }
template<class Head, class... Tail>
void DBG(Head H, Tail... T) { cerr << ' ' << H; DBG(T...); }
#define dbg(...) cerr << "(" << (#__VA_ARGS__) << "):", DBG(__VA_ARGS__)

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

#define sqr(a) ll(a) * (a)
#define siz(a) int(a.size())
#define ints(a...) int a; read(a)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define trav(i, v) for (const auto i : v)
#define fill(a, b) memset(a, b, sizeof(a))
#define rep(i, b, n) for (auto i = b; i < n; i++)
#define per(i, b, n) for (auto i = b; i >= n; i--)
#define unify(a) sort(all(a)); a.resize(unique(all(a)) - a.begin())

template <class T> using vec = vector<T>;
template <class... Args> inline void read(Args&... args) { ((cin >> args), ...); }
template <class... Args> inline void show(Args... args) { ((cout << args << " "), ...); }
template <class T1, class T2> inline bool ckmin(T1 &a, T2 b) { return a > b ? a = b, 1 : 0; }
template <class T1, class T2> inline bool ckmax(T1 &a, T2 b) { return a < b ? a = b, 1 : 0;  }
template <class T> inline void operator>> (istream& in, vector<T>& v) { rep(i, 0, siz(v)) in >> v[i]; }
template <class T> inline void operator<< (ostream& out, const vector<T>& v) { rep(i, 0, siz(v)) out << v[i] << " \n"[i + 1 == siz(v)]; }

const int MOD = 1e9 + 7;
const int N = 101;
ld dp[N][N][N];

ld f(int a, int b, int c) {
    if (a == 100 || b == 100 || c == 100)
        return 0;
    if (dp[a][b][c] >= 0)
        return dp[a][b][c];

    ld res = 1, sum = a + b + c;
    res += a * f(a + 1, b, c) / sum;
    res += b * f(a, b + 1, c) / sum;
    res += c * f(a, b, c + 1) / sum;
    return dp[a][b][c] = res;
}

void solve() {
    ints(a, b, c);
    fill(dp, -1);
    cout << f(a, b, c);
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
    int _ = 1;
    // cin >> _;
    rep(i, 1, _ + 1) {
        // printf("Case %d: ", i);
        // Solution solve;
        solve();
    }
    return 0;
}

/*
    Author : zzugzx
    Lang : C++
    Blog : blog.csdn.net/qq_43756519
*/

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

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define endl '\n'
#define SZ(x) (int)x.size()
#define mem(a, b) memset(a, b, sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
//const int mod = 1e9 + 7;
const int mod = 998244353;

const double eps = 1e-8;
const double pi = acos(-1.0);
const int maxn = 1e6 + 10;
const int N = 1e2 + 10;
const ll inf = 0x3f3f3f3f;
const ll oo = 8e18;
const int dir[][2]={{0, 1}, {1, 0}, {0, -1}, {-1, 0}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
ll Pow(ll a, ll b){
	ll ans = 1;
	while(b > 0){
		if(b & 1){
			ans = ans * a % mod;
		}
		a = a * a % mod;
		b >>= 1;
	}
	return ans;
}
ll inv(ll b){
    return Pow(b,mod-2)%mod;
}
double dp[110][110][110];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
    int a, b, c;
    cin >> a >> b >> c;
    for (int i = 100; i >= a; i--)
        for (int j = 100; j >= b; j--)
            for (int k = 100; k >= c; k--) {
                if (i == 100 || j == 100 || k == 100) continue;
                double tmp = 0;
                if (i + 1 <= 100) tmp += dp[i + 1][j][k] * i / (i + j + k) + 1.0 / 3;
                if (j + 1 <= 100) tmp += dp[i][j + 1][k] * j / (i + j + k) + 1.0 / 3;
                if (k + 1 <= 100) tmp += dp[i][j][k + 1] * k / (i + j + k) + 1.0 / 3;
                dp[i][j][k] = tmp;
            }
    cout << fixed << setprecision(9) << dp[a][b][c] << endl;
    return 0;
}


#include "bits/stdc++.h"
using namespace std;
#define int               long long
#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define uniq(v)           (v).erase(unique(all(v)),(v).end())
#define sz(x)             (int)((x).size())
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.fr>>a.sc;return in;}
template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.fr<<" "<<a.sc;return out;}
template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;}

const long long INF=1e18;
const int32_t M=1e9+7;
const int32_t MM=998244353;

const int N=0;

void solve(){
	int n;
	cin>>n;
	int ans=0;
	for (int i = 1; i <= n; ++i) {
		int num=i;
		bool flag=1;
		while(num){
			if(num%10==7)flag=0;
			num/=10;
		}
		num=i;
		while(num){
			if(num%8==7)flag=0;
			num/=8;
		}
		ans+=(flag);
	}
	cout<<ans;
}
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	#ifdef SIEVE
		sieve();
	#endif
	#ifdef NCR
		init();
	#endif
	int t=1;
	//cin>>t;
	while(t--) solve();
	return 0;
}


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

int main(){

    cout.sync_with_stdio(0);
    cin.tie(0);

    int n; cin >> n;
    string s, t; cin >> s >> t;

    for(long long i = 0; i < n; i++){
        char c = s[i];
        if(c == '1')
            adj.push_back(i);
    }

    ll res = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == t[i]) {
            if (s[i] == '1') {
                adj.pop_front();
            }
            continue;
        }
        if(s[i] == '1'){
            adj.pop_front();
            if(adj.empty()){
                cout << -1 << endl;
                return 0;
            }
            res += adj.front() - i;
            s[adj.front()] = '0';
            adj.pop_front();
        }
        else{
            if(adj.empty()){
                cout << -1 << endl;
                return 0;
            }
            res += adj.front() - i;
            s[adj.front()] = '0';
            adj.pop_front();
        }
    }

    cout << res << endl;

	return 0;
}

#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 popcount(v) __builtin_popcount(v)
#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 modinv(ll a, ll m) {ll b = m, u = 1, v = 0;while (b) {ll t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
ll 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(){
    INT(n);
    vector<int> a(n);
    in(a);
    sort(all(a));
    rep(i,n){
        if(a[i]!=i+1){
            out("No");
            return 0;
        }
    }
    out("Yes");
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
template <class T = ll> using V = vector<T>;
#define loop(n) while(n--)
#define rep(i,n) for(int i=0; i<(n);++i)
#define repp(i, l, r) for(int i = (l); i < (r); ++i)
#define all(v) (v).begin(), (v).end()
#define LL(n) int n;cin >> n

int main()
{
    LL(n);
    V<ll> a(n);
    rep(i, n) cin >> a[i];
    sort(all(a));
    ll sum = accumulate(all(a), 0);
    sum = (sum+1)/2;

    bool dp[110][100010] = {};
    rep(i, 110) dp[i][0] = true;

    rep(i, n) rep(j, 100010){
        if(j - a[i] >= 0) dp[i+1][j] |= dp[i][j-a[i]];
        dp[i+1][j] |= dp[i][j];
    }

    rep(i, 100000){
        if(dp[n][i+sum]) {
            cout << i+sum << endl;
            break;
        }
    }

    return 0;
}

#include <chrono>
#include <thread>
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define T top()
#define E end()
#define PS push
#define Q queue
#define PP pop()
#define L0 (LL)0
#define V vector
#define ST stack
#define FI first
#define MAX 4e18
#define MIN -MAX
#define DQ deque
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define SE second
#define DL double
#define G getline
#define IN insert
#define endl "\n"
#define EM empty()
#define cnn continue
#define MD 1000000007
#define PSB push_back
#define PI acos(-1.00)
#define PPB pop_back()
#define PSF push_front
#define ub upper_bound
#define lb lower_bound
#define PPF pop_front()
#define CF cout.flush()
#define line cout<<endl
#define LL long long int
#define one cout<<1<<endl
#define zer cout<<0<<endl
#define PQ priority_queue
#define kth find_by_order
#define nil cout<<-1<<endl
#define N cout<<"NO"<<endl
#define NN cout<<"No"<<endl
#define Y cout<<"YES"<<endl
#define fndidx order_of_key
#define YY cout<<"Yes"<<endl
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#define MAU cout<<"Case "<<mau<<": "
#define SP(pre) fixed<<setprecision(pre)
#pragma GCC optimization ("unroll-loops")
#define MMAU cout<<"Case "<<mau<<":"<<endl
#define __lcm(A1,A2) (A1/(__gcd(A1,A2)))*A2
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)
#define UOSMOY v.C;w.C;ww.C;uu.C;uo.C;vo.C;vu.C;ab.C;bc.C;cc.C;uuu.C;a.C;b.C;c.C;u.C
typedef tree<LL, null_type, less<LL>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define remembermeforcenturies using namespace std::chrono_literals;std::this_thread::sleep_for(-4611686018427387904ms);
V<LL>v,w,ab,bc;
set<LL>uo;
map<LL,LL>ww,cc,u;
V<pair<LL,LL> >uu,su;
map<LL,V<LL> >uuu;
map<pair<LL,LL>,LL> vo,vu;
map<LL,pair<LL,pair<LL,LL > > > vs;
priority_queue<LL,V<LL>,greater<LL> > moy;
LL dx[]= {-1,0,1,0,1,1,-1,-1};
LL dy[]= {0,1,0,-1,-1,1,1,-1};
LL dxx[]= {2,1,-1,-2,-2,-1,1,2};
LL dyy[]= {1,2,2,1,-1,-2,-2,-1};
LL dp[101][10001];
LL ar[10][10];
bool mat[110][100010];
void ans()
{

    LL sumOfArray = 0;
    for(LL i = 0; i < v.SZ; i++)
    {
        sumOfArray = sumOfArray + v[i];
    }
    LL sum = sumOfArray / 2;
    for(LL i = 0; i < v.SZ; i++)
    {
        mat[i][0] = true;
    }
    for(LL j = 0; j <= sum; j++)
    {
        if(j == v[0])
        {
            mat[0][j] = true;
        }
    }

    for(LL i = 1; i < v.SZ; i++)
    {
        for(LL j = 1; j <= sum; j++)
        {

            if(mat[i - 1][j])
            {
                mat[i][j] = true;
            }
            else
            {
                if(j >= v[i])
                {
                    mat[i][j] = mat[i - 1][j - v[i]];
                }
            }
        }
    }

    LL lastRow = v.SZ - 1;
    LL firstPartitionSum = -1;

    for(LL j = sum; j >= 0; j--)
    {
        if(mat[lastRow][j])
        {
            firstPartitionSum = j;
            break;
        }
    }

    LL secondPartitionSum = sumOfArray - firstPartitionSum;
    cout<<max(firstPartitionSum,secondPartitionSum)<<endl;
}

int main()
{
//  BRR;
//  file;
    FAST;
    char ch;
    string a,b,c;
    DL x,y,d,e,f,g,h;
    LL n,i,j,k,p,q,o,l,s,tt=1,m,t,z,aa,r=0;
//    cin>>tt;
    for(LL mau=1; mau<=tt; mau++)
    {
        UOSMOY;
        ordered_set os;
        remembermeforcenturies;
        cin>>n;
        for(i=0; i<n; i++)
        {
            cin>>o;
            v.PSB(o);
        }
        if(n==1)
        {
            cout<<v[0]<<endl;
            cnn;
        }
        sort(v.B,v.E);
        ans();

    }
    return 0;
    //IN
    //AL
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for(int i = a; i < b; i++)
int A, B;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> A >> B;
    for(int i = -100; i <= 100; i++) {
        for(int j = -100; j <= 100; j++) {
            if((i + j == A) && (i - j == B)) {
                cout << i << " " << j << endl;
            }
        }
    }
    return 0;
}

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

int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */
    int a, b;
    cin >> a >> b;
    cout << ((a+b) >> 1) << " " << ((a-b) >> 1);
    return 0;
}


#include<bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#ifndef LOCAL
#define cerr if(0)cerr
#endif
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using pii = pair<int, int>;

const int N = 2e5+1;
int n, m, num[N];
vector<pii> g[N];
bool vis[N];
void dfs(int x, int p, int val) {
	vis[x] = 1;
	if(!p || num[p] == val) {
		num[x] = val%n+1;
	}
	else {
		num[x] = val;
	}
	for(auto i: g[x]) {
		if(!vis[i.st]) {
			dfs(i.st, x, i.nd);
		}
	}
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin>>n>>m;
	for(int i=0; i<m; ++i) {
		int a, b, c; cin>>a>>b>>c;
		g[a].push_back(mp(b, c));
		g[b].push_back(mp(a, c));
	}
	dfs(1, 0, 0);
	for(int i=1; i<=n; ++i) {
		cout<<num[i]<<'\n';
	}
}

#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

struct Edge {
    int t, c;
    Edge() = default;
    Edge(int t, int c) : t(t), c(c) {}
};

int main() {
    int N, M; cin >> N >> M;
    vector<vector<Edge>> E(N);
    REP(i, 0, M) {
        int u, v, c; cin >> u >> v >> c; u--; v--; c--;
        E[u].push_back({v, c});
        E[v].push_back({u, c});
    }

    vector<int> ans(N, -1);
    queue<pair<int, int>> Q;
    Q.push({0, -1});
    while (!Q.empty()) {
        auto q = Q.front(); Q.pop();
        int v = q.first;
        int p = q.second;
        if (ans[v] < 0) ans[v] = -1;
        set<int> labels;
        for (auto e : E[v]) {
            if (ans[e.t] != -1) continue;
            if (ans[v] == -1 || ans[v] != e.c) {
                ans[e.t] = e.c;
                labels.insert(e.c);
            } else {
                ans[e.t]--;
            }
            Q.push({e.t, e.c});
        }

        if (ans[v] < 0) {
            int c = 0;
            labels.insert(p);
            while (labels.count(c)) c++;
            ans[v] = c;
        }
    }
    for (auto a : ans) cout << a + 1 << endl;
    return 0;
}


#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstring>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<string>
#include<iterator>
#include<string>
#include<sstream>
#include <unordered_map>
#include<cmath>
using namespace std;
#define ll long long
int __gcd(int a,int b){return b==0 ? a : __gcd(b,a%b);}
ll __gcd(ll a,ll b){return b==0 ? a : __gcd(b,a%b);}
void scan(__int128 &x)//输入
{
    x = 0;
    int f = 1;
    char ch;
    if((ch = getchar()) == '-') f = -f;
    else x = x*10 + ch-'0';
    while((ch = getchar()) >= '0' && ch <= '9')
        x = x*10 + ch-'0';
    x *= f;
}

void print(__int128 x)//输出
{
    if(x < 0)
    {
        x = -x;
        putchar('-');
    }
     if(x > 9) print(x/10);
    putchar(x%10 + '0');
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    int _=1;
    while(_--){
        __int128 x,y,a,b; scan(x); scan(y); scan(a); scan(b);
        __int128 ans=0,cnt=0;
        //ll x,y,a,b; cin>>x>>y>>a>>b;
        //ll ans=0,cnt=0;
        while(1){
            if(x>=y) break;
            ans=max(ans,cnt+(y-1-x)/b);
            x*=a; ++cnt;
        }
        print(ans);
        cout<<"\n";
        //cout<<ans<<"\n";
    }
}

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

using ld=long double;
int32_t main(){
    ios::sync_with_stdio(0),cin.tie(0);
    int x,y,a,b;
    cin >> x >> y >> a >> b;
    int ans=0;
    while(x*a<=x+b and (ld)x*a+1e-8<(ld)y){
    	x*=a,ans++;
    }
    ans+=(y-1-x)/b;
    cout << ans;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define deb(x) cout<<#x<<" "<<x<<endl;
#define print(arr,n) for(int i=0;i<n;++i) { cout<<arr[i]<<" "; } cout<<endl;
#define ub(x,el) upper_bound(x.begin(),x.end(),el) - x.begin()
#define lb(x,el) lower_bound(x.begin(),x.end(),el) - x.begin();
#define bs(x,el) binary_search(x.begin(),x.end(),el)
#define MOD 1000000007
#define finish return 0
#define all(x) x.begin(),x.end()
using namespace std;
using namespace __gnu_pbds;
typedef long long int ll;
typedef tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
template<int D, typename T> struct Vec : public vector<Vec<D - 1, T>> { static_assert(D >= 1, "Vector dimension must be greater than zero!"); template<typename... Args> Vec(int n = 0, Args... args) : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) { }}; template<typename T> struct Vec<1, T> : public vector<T> { Vec(int n = 0, T val = T()) : vector<T>(n, val) { } };
inline ll mod(const ll& x) { return (x%MOD + MOD)%MOD; }
ll gcd(ll a, ll b, ll &x, ll &y){if(a == 0){x = 0, y = 1; return b;} ll x1, y1;  ll d = gcd(b%a, a, x1, y1); x = y1 - (b/a) * x1; y = x1; return d;}
ll power(ll x,ll y, ll p) { ll res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res*x) % p; y = y>>1; x = (x*x) % p;   } return res; }
ll power(ll x,ll y) { ll res = 1; while (y > 0) { if (y & 1) res = (res*x); y = y>>1; x = (x*x);   } return res; }
ll mod(ll num, ll den){ return mod(mod(num) * power(den,MOD-2,MOD)); }
vector<ll> primes(ll n) { vector<ll> p; vector<bool> v(n+1,true); for(ll i=2;i*i<=n;++i) { if(v[i]) { for(ll j=i*i;j<=n;j+=i) v[j] = false; } } for(ll i=2;i<=n;++i) if(v[i]) p.push_back(i); return p; }
vector<ll> lpf(ll n){ vector<ll> v(n+1); for(ll i=1;i<=n;++i) v[i] = i; for(ll i=2;i*i<=n;++i) { if(v[i] == i) { for(ll j=i*i;j<=n;j+=i) { v[j] = i; } } } return v; }
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    vector<ll> a(n);
    vector<ll> b(n);
    for(auto& i:a) cin>>i;
    for(auto& i:b) cin>>i;
    ll sum = 0;
    for(ll i=0;i<n;++i)
    {
        sum += a[i] * b[i];
    }
    if(sum == 0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

}


#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl
#define debug2(x, y) debug(x), debug(y)
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))
const int MOD = 998244353;

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

struct DSU{
	int S;
	struct node{
		int parent; ll sum;
	};
	vector<node> dsu;
	DSU(int n){
		S = n;
		rep(i, n){
			node tmp;
			tmp.parent = i; tmp.sum = 1;
			dsu.pb(tmp);
		}
	}
	int root(int u){
		if(dsu[u].parent == u) return u;
		dsu[u].parent = root(dsu[u].parent);
		return dsu[u].parent;
	}
	void merge(int u, int v){
		u = root(u); v = root(v);
		if(u == v) return;
		if(getsum(u) < getsum(v)) swap(u, v);
		dsu[v].parent = u;
		dsu[u].sum += dsu[v].sum;
	}
	bool sameset(int u, int v){
		if(root(u) == root(v)) return true;
		return false;
	}
	ll getsum(int u){
		return dsu[root(u)].sum;
	}
};

ll mypow(ll a, ll p){
	if(p <= 0) return 1LL;
	if(p & 1) return (a * mypow(a, p - 1)) % MOD;
	ll x = mypow(a, p / 2) % MOD;
	return (x * x) % MOD;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	vi f(n + 1);
	ll cyc  = 0LL;
	DSU dsu(n + 1);
	repn(i, 1, n + 1) cin >> f[i], dsu.merge(i, f[i]);
	repn(i, 1, n + 1) if(dsu.root(i) == i) cyc++;
	cout << mypow(2, cyc) - 1 << '\n';
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Make sure that max is large enough (2e9, 4e18)
	- Special cases
Be careful!
*/

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll ,ll> pll;
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(X) (X).begin(), (X).end()
#define REP(i,x,y) for(ll i = x;i <= y;++i)
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
vector<string> vec_splitter(string s) {
    for(char& c: s) c = c == ','?  ' ': c;
    stringstream ss; ss << s;
    vector<string> res;
    for(string z; ss >> z; res.push_back(z))
        ;
    return res;
}
void debug_out(vector<string> args, int idx) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, Head H, Tail... T) {
    if(idx > 0) cerr << ", ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __VA_ARGS__)
void localTest() {
    #ifndef ONLINE_JUDGE
        freopen("inp", "r", stdin);
        freopen("out", "w", stdout);
    #endif
}
const ll N = 2e5 + 5, MOD = 998244353;
ll A[N], sz, par[N];
ll find(ll x) {
    if(x == par[x]) {
        return x;
    }
    return par[x] = find(par[x]);
}
void merge(ll x, ll y) {
    ll rx = find(x), ry = find(y);
    if(rx == ry) {
        return;
    }
    par[ry] = rx;
    sz--;
}
ll power(ll a, ll b, ll c) {
    ll ret = 1;
    while(b) {
        if(b & 1) {
            ret = (ret * a) % c;
        }
        b >>= 1;
        a = (a * a) % c;
    }
    return ret;
}
int main() {

    localTest();
    fastio;
    ll n;
    cin >> n;
    sz = n;
    for(ll i = 1; i <= n; ++i) {
        par[i] = i;
    }
    for(ll i = 1; i <= n; ++i) {
        cin >> A[i];
        merge(A[i], i);
    }
    cout << (power(2, sz, MOD) - 1 + MOD) % MOD << "\n";

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T>  using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define ll           long long
#define rep(i,j,n)   for(int i=j;i<n;i++)
#define scn(a)       scanf("%d",&a)
#define scns(a,b)    scanf("%d %d",&a,&b)
#define print(a)     printf("%d\n",a)
#define vec          vector<int>
#define pb           push_back
#define pairs        pair<int,int>
#define f            first
#define s            second
#define all(v)       v.begin(),v.end()
#define mem(a,b)     memset(a,b,sizeof(a))
#define inf          INT_MAX
const int mod = 1e9+7;
const int N = 2e5+5;

int n;

int main()
{
	int test; test = 1;

    while(test--)
    {
        scn(n);

        int a[n],b[n];

        vector<pair<ll,pairs>> v1;

        ll sum1 = 0, sum2 = 0;

        rep(i,0,n)
        scns(a[i],b[i]), v1.pb({2LL*a[i]+b[i],{a[i],b[i]}}), sum1 += 1LL*a[i];

        sort(all(v1), greater<pair<ll,pairs>>());

        int cnt = 0;

        rep(i,0,n)
        {
            if(sum1 >= sum2)
            sum2 += 1LL*v1[i].f, cnt++;
            else
            break;
        }

        print(cnt);
    }
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,k;
	cin>>n>>k;
  long long int s=k;
  vector<pair<long long int,long long int> > v;
	///s=k;
	//cout<<s;
	//int p=k;
	for(int i=0;i<n;i++)
	{
		long long int a,b;
		cin>>a>>b;
		v.push_back(make_pair(a,b));
	}
	sort(v.begin(),v.end());
	//s=k;
	for(int i=0;i<n;i++)
	{
		if(s<v[i].first)
		break;

		s+=v[i].second;
		//k=s;
}
	cout<<s<<endl;
//	for(int i=0;i<v.size();i++)
//	cout<<v[i].first<<" "<<v[i].second;
	return 0;
}


#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
int a[10010];

int solve() {
    int res = 0;
    for (int i = 0; i < n; i++) {
        int k = 1;
        for (int j = i-1; j >= 0; j--) {
            if (a[i] <= a[j]) {
                k++;
            } else {
                break;
            }
        }
        for (int j = i+1; j < n; j++) {
            if (a[i] <= a[j]) {
                k++;
            } else {
                break;
            }
        }
        res = max(res, a[i] * k);
    }
    return res;
}

void input() {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
}

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

    input();
    cout << solve() << endl;
}

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

int main()
{
int m=1000000007;
ll n; cin >> n;
vector<ll> a(n);
rep(i,n) cin >>  a[i];
vector<vector<ll>> f(n+2,vector<ll>(2));
f[0][0]=0; f[0][1]=1;
rep(i,n){
    f[i+1][0]=f[i][1]%m;
    f[i+1][1]=(f[i][0]+f[i][1])%m;
}
ll ans=0;
rep(i,n){
    ans=(ans%m)+(a[i]%m)*(((f[i][1]*f[n-i][1])%m)-((f[i][0]*f[n-i][0])%m))%m;
}
ans%=m;
if (ans < 0) ans += m;
cout << ans << endl;
}


#include <bits/stdc++.h>

template <typename T> inline void rd(T& x) {
	int si = 1; char c = getchar(); x = 0;
	while(!isdigit(c)) si = c == '-' ? -1 : si, c = getchar();
	while(isdigit(c)) x = x * 10 + c - 48, c = getchar();
	x *= si;
}
template <typename T, typename... Args>
inline void rd(T& x, Args&... args) { rd(x); rd(args...); }
#define fi first
#define se second
#define mkp std::make_pair
typedef long long ll;
typedef double ff;
typedef std::pair <int, int> pii;
const int kN = 5e5 + 5, kInf = 0x3f3f3f3f;
const ll kMod = 998244353, kInfLL = 0x3f3f3f3f3f3f3f3fLL;

int n, C, cnt; ll ans = 0;
pii d[kN];

int main() {
#ifndef ONLINE_JUDGE
	freopen("a.in", "r", stdin);
	freopen("a.out", "w", stdout);
#endif
	int T = 1; //rd(T);
	while(T--) {
		rd(n, C);
		for(int i = 1; i <= n; ++i) {
			int a, b, c; rd(a, b, c);
			d[++cnt] = mkp(a, c);
			d[++cnt] = mkp(b + 1, -c);
		}
		std::sort(d + 1, d + cnt + 1);
		ll cur_c = 0, ans = 0;
		for(int i = 1; i < cnt; ++i) {
			cur_c += d[i].se;
			ans += std::min(cur_c, (ll)C) * (d[i + 1].fi - d[i].fi);
		}
		printf("%lld\n", ans);
	} return 0;
}

#include <bits/stdc++.h>
#define int long long
using namespace std;
int32_t main() {
    int n,C;
    cin>>n>>C;
    int a[n],b[n],c[n];
    map<int,int> m;
    set<int> s;
    for(int i=0;i<n;i++) {
        cin>>a[i]>>b[i]>>c[i];
        m[a[i]]+=c[i];
        m[b[i]+1]-=c[i];
        s.insert(a[i]);
        s.insert(b[i]+1);
    }
    vector<int> v(s.begin(),s.end());
    int size=v.size();
    int cost=0,ans=0;
    for(int i=0;i<size-1;i++) {
        cost+=m[v[i]];
        ans+=min(cost,C)*(v[i+1]-v[i]);
    }
    cout<<ans;
}


#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a))
#define MEM_1(a) memset((a),-1,sizeof(a))
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<db> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const int MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };
int ddx[] = { -1,-2,1,-2,2,-1,2,1 }, ddy[] = { -2,-1,-2,1,-1,2,1,2 };

int a[100000],b[100000],L[100005],R[100005];
int n,l;
map<int,int> M;
int main(){
	scanf("%d%d",&n,&l);
	fup(i,0,n-1,1)scanf("%d",a+i);
	fup(i,0,n-1,1)scanf("%d",b+i);
	ll ans=0;
	M[1]=-1;
	fup(i,0,n-1,1){
		if(b[i]<a[i]){
			auto it=M.find(b[i]-i);
			if(it==M.end())return !printf("-1\n");
			L[i]=i-it->Y;
		}
		M[a[i]-i]=i;
	}
	int tmp=0;
	fdn(i,n-1,0,1){
		if(L[i]>tmp){
			ans+=L[i];
			tmp=max(0,L[i]-1);
		}else{
			tmp=max(0,tmp-1);
		}
	}
	M.clear();
	M[l+1-n]=n;
	fdn(i,n-1,0,1){
		if(b[i]>a[i]){
			auto it=M.find(b[i]-i);
			if(it==M.end())return !printf("-1\n");
			R[i]=it->Y-i;
		}
		M[a[i]-i]=i;
	}
	tmp=0;
	fup(i,0,n-1,1){
		if(R[i]>tmp){
			ans+=R[i];
			tmp=max(0,R[i]-1);
		}else{
			tmp=max(0,tmp-1);
		}
	}
	printf("%lld\n",ans);
}

/*
after dusk passed,
there is a starry sky.
*/
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define m_k make_pair
#define int long long
using namespace std;
const int N=1e5+100;
int n,l,a[N],b[N],ans;
map <int,vector<int> > mp;
inline int read()
{
	int 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-'0';s=getchar();}
	return x*f;
}
inline void getup(int l,int r)
{
	for (int i=l;i<=r;)
	{
		int j=i,num=b[i]-i,pos=lower_bound(mp[num].begin(),mp[num].end(),i)-mp[num].begin();
		while(j<=r&&b[j]-j==b[i]-i) j++;
		ans+=mp[num][pos]-i;
		i=j;
	}
}
inline void getdown(int l,int r)
{
	for (int i=r;i>=l;)
	{
		int j=i,num=b[i]-i,pos=upper_bound(mp[num].begin(),mp[num].end(),i)-mp[num].begin()-1;
		while(j>=l&&b[j]-j==b[i]-i) j--;
		ans+=i-mp[b[i]-i][pos];
		i=j;
	}
}
signed main()
{
//	freopen("1.txt","r",stdin);
	n=read();l=read();
	for (int i=1;i<=n;i++) a[i]=read();
	for (int i=1;i<=n;i++) b[i]=read();
	a[0]=0;a[n+1]=l+1;
	for (int i=0;i<=n+1;i++) mp[a[i]-i].push_back(i);
	bool bl=1;
	for (int i=1;i<=n;i++) if (mp[b[i]-i].empty()) bl=0;
	if (!bl)
	{
		printf("-1\n");
		return 0;
	}
	// for (int i=0;i<(int)mp[0].size();i++) printf("%lld ",mp[0][i]);
	// printf("\n");
	for (int i=1;i<=n;)
	{
		int j=i;
		while(j<=n&&(b[j]<=a[j])==(b[i]<=a[i])) j++;
		if (b[i]<=a[i]) getdown(i,j-1);
		else getup(i,j-1);
		i=j;
	}
	printf("%lld\n",ans);
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

void solve() {
    int N, M;
    cin >> N >> M;
    vector<int> A(M);
    for (auto &x : A) {
        cin >> x;
    }
    sort(ALL(A));
    vector<int> df;
    // 左右の幅の最小値
    int minv = 1e9, before = 0;
    for (auto &x : A) {
        if (x - before - 1 >= 1) {
            minv = min(minv, x - before - 1);
            df.emplace_back(x - before - 1);
        }
        before = x;
    }
    if (before != N) {
        minv = min(minv, N - before);
        df.emplace_back(N - before);
    }
    int sum = 0;
    for (auto x : df) {
        sum += CEIL(x, minv);
    }
    cout << sum << endl;
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define pii pair<int,int>
#define fi first
#define se second
#define int long long
#define pb push_back
#define mod 998244353
#define pll pair<long long,long long>
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
long long power(long long a,long long b){
    long long ans=1;
    while(b>0){
        if(b&1){ans=(ans*a)%mod;}
                a=(a*a)%mod;
                b>>=1;
        }
    return ans;

}
int fact[1000005],fact_inv[1000005];
void pre(){
    fact[0]=1;
    fact_inv[0]=1;
    for(int i=1;i<200005;i++){
        fact[i]=fact[i-1]*i;
        fact[i]%=mod;
        fact_inv[i]=power(fact[i],mod-2);
    }
}
long long ncr(long long n,long long r){
    if(n<r){return 0;}
    if(n==r||r==0){return 1;}
    return (((fact[n]*fact_inv[n-r])%mod)*fact_inv[r])%mod;
    //return x;
}
//find_by_order() ->  iterator to the k-th largest element (counting from zero)
//order_of_key() ->    the number  items in a set that are strictly smaller than our item aka index in set
//upper bound : strictly greater than x
//lower bound : greater equal to x
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,m;
    cin>>n>>m;
    if(m==0){
        cout<<1;
        return 0;
    }
    int a[m];
    for(int i=0;i<m;i++){
        cin>>a[i];
    }
    sort(a,a+m);
    vector<int>v;
    if(a[0]!=1)v.pb(a[0]-1);
    if(a[m-1]!=n)v.pb(n-a[m-1]);
    for(int i=1;i<m;i++){
        if(a[i]==a[i-1]+1)continue;
        v.pb(a[i]-a[i-1]-1);
    }
    if(v.empty()){
        cout<<0;
        return 0;
    }
    sort(v.begin(),v.end());
    int ans=0;
    for(int i=0;i<v.size();i++){
        if(v[i]%v[0]==0)ans+=v[i]/v[0];
        else ans+=(v[i]/v[0])+1;
    }
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')';}
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) {os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
template<typename T> void dbg_a(T *a,int l,int r){cerr<<" {";for(int i = l;i<r;i++) cerr<<a[i]<<", ";cerr<<a[r]<<"}"<<endl;}
typedef long long ll;
#define int ll
inline int read(){
    int f(1),r(0);char c(getchar());
    while(c<'0'||c>'9'){if(c == '-') f = -1; c = getchar();}
    while(c>='0'&&c<='9'){ r = (r<<1) + (r<<3) + c - '0';c = getchar();}
    return f*r;
}
typedef pair<int,int> PII;
#define fi first
#define se second
#define mst(a,b) memset(a,b,sizeof(a))
#define For(i,a,b) for(int i = a;i<=b;i++)
#define For_(i,a,b) for(int i = a;i>=b;i--)
#define _for(i,a) for(int i = 0;i<a;i++)
#define _sum(a,l,r) accumulate(a + l,a + r + 1,0)
#define All(x) x.begin(),x.end()
#define lowbit(x) ((-x)&x)
//    For(i,1,n) For(j,1,m) printf("f[%lld][%lld] = %lld\n",i,j,f[i][j]);
//const ll INF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const int N = 1000 + 6,M = 2e5*2 + 6,Q = 2e6 + 5;
const int mod = 2017;
int n,m;

void solve(){
    int R = read();
    int X = read(),Y = read();
    //dbg_out((X*X + Y*Y)/R*R);
    int ans = ceil(sqrt((long double)(X*X + Y*Y)/(long double)(R*R)));
    if(R*R > X*X + Y*Y){
        ans = 2;
    }
    cout<<ans<<"\n";
}
signed main(){
    int T = 1;
    //T = read();
    while(T--) solve();
    system("pause");
    return 0;
}

#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <cmath>
#include <iterator>
#include <queue>
#define ll long long int
using namespace std;

bool isOk(ll r,ll x,ll y,ll num){
	if( (x*x + y*y) <= (num*num*r*r)){
		return true;
	}else{
		return false;
	}
}

int main()
{
	ll R,X,Y;
	cin>>R>>X>>Y;
	if( R*R > X*X + Y*Y){
		cout<<2<<endl;
	}else{
		for(ll i = 0; i < 2000000; i++){
			if( X*X + Y*Y <= i*i*R*R){
				cout<<i<<endl;
				break;
			}
		}
	}
	return 0;
}


#include<iostream>
using namespace std;
int main(){
  int n;
  cin>>n;
  if(n % 2 == 0)
    cout<<"White";
  else
    cout<<"Black";
  return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#define rep(i,n) for (int i=0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main(){

    int i;
    cin >> i;
    if(i < 0){
        i = 0;
    }
    cout << i << endl;
    return 0;
}


#include <bits/stdc++.h>

#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define FILL0(x) memset(x,0,sizeof(x))
#define FILL1(x) memset(x,-1,sizeof(x))

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

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

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

    int t;
    cin >> t;

    ll l, r;
    rep(i, t){

        cin >> l >> r;

        ll ans = max(0LL,(r-l-l+1))*max(0LL,(r-l-l+1+1))/2;

        cout << ans << endl;
    }

    return 0;

}

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

int solve(int L, int R) {
	int res = 0;
	int tmp = R - L;

	if (tmp < L)return 0;
	int ans = tmp - L + 1;

	//cout << ans << endl;
	res = ans * (ans + 1) / 2;
	return res;
}

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

	int t; cin >> t;
	while (t--) {
		int A, B, C; cin >> A >> B;
		cout << solve(A, B) << endl;
	}

	return 0;
}


#include <bits/stdc++.h>
#define int long long
#define PI pair<int,int>
using namespace std;
const int maxm=2e6+5;
struct Mat{
    int a[3][3];
    void init(){
        memset(a,0,sizeof a);
    }
    Mat operator*(const Mat& x){
        Mat ans;ans.init();
        for(int k=0;k<3;k++){
            for(int i=0;i<3;i++){
                for(int j=0;j<3;j++){
                    ans.a[i][j]+=a[i][k]*x.a[k][j];
                }
            }
        }
        return ans;
    }
};
int x[maxm],y[maxm];
Mat T[maxm];
int n,m,q;
void solve(){
    cin>>n;
    for(int i=1;i<=n;i++)cin>>x[i]>>y[i];
    cin>>m;
    T[0]={1,0,0,0,1,0,0,0,1};//T[0]是单位矩阵
    for(int i=1;i<=m;i++){
        int op;cin>>op;
        Mat t;
        if(op==1){//顺时针旋转90度
            t={0,1,0,-1,0,0,0,0,1};
        }else if(op==2){//逆时针旋转90度
            t={0,-1,0,1,0,0,0,0,1};
        }else if(op==3){//关于x=p对称
            int p;cin>>p;
            t={-1,0,2*p,0,1,0,0,0,1};
        }else if(op==4){//关于y=p对称
            int p;cin>>p;
            t={1,0,0,0,-1,2*p,0,0,1};
        }
        T[i]=t*T[i-1];
    }
    cin>>q;
    for(int i=1;i<=q;i++){
        int a,b;cin>>a>>b;
        Mat t={x[b],0,0,y[b],0,0,1,0,0};
        t=T[a]*t;
        cout<<t.a[0][0]<<' '<<t.a[1][0]<<endl;
    }
}
signed main(){
    ios::sync_with_stdio(0);
    solve();
    return 0;
}
/*
1.顺时针旋转90度:
(x,y)->(y,-x)

2.逆时针旋转90度:
(x,y)->(-y,x)

3.关于x=p对称:
(x,y)->(2p-x,y)

4.关于y=p对称:
(x,y)->(x,2p-y)

*/

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

P op1(P v) {
  return make_pair(v.second, -v.first);
}

P op2(P v) {
  return make_pair(-v.second, v.first);
}

P op3(P v, ll p) {
  return make_pair(2 * p - v.first, v.second);
}

P op4(P v, ll p) {
  return make_pair(v.first, 2 * p - v.second);
}

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

  vector<ll> X(N), Y(N);
  rep(i, N) cin >> X[i] >> Y[i];

  int M;
  cin >> M;
  vector<vector<P> > transformed(M + 1, vector<P>(3));
  transformed[0][0] = make_pair(0, 0);
  transformed[0][1] = make_pair(1, 0);
  transformed[0][2] = make_pair(0, 1);

  rep(i, M) {
    int op;
    cin >> op;
    if (op == 1) {
      transformed[i + 1][0] = op1(transformed[i][0]);
      transformed[i + 1][1] = op1(transformed[i][1]);
      transformed[i + 1][2] = op1(transformed[i][2]);
    } else if (op == 2) {
      transformed[i + 1][0] = op2(transformed[i][0]);
      transformed[i + 1][1] = op2(transformed[i][1]);
      transformed[i + 1][2] = op2(transformed[i][2]);
    } else {
      ll p;
      cin >> p;
      if (op == 3) {
        transformed[i + 1][0] = op3(transformed[i][0], p);
        transformed[i + 1][1] = op3(transformed[i][1], p);
        transformed[i + 1][2] = op3(transformed[i][2], p);
      } else if (op == 4) {
        transformed[i + 1][0] = op4(transformed[i][0], p);
        transformed[i + 1][1] = op4(transformed[i][1], p);
        transformed[i + 1][2] = op4(transformed[i][2], p);
      }
    }
  }

  int Q;
  cin >> Q;
  rep(i, Q) {
    int A, B;
    cin >> A >> B;
    cout << X[B - 1] * (transformed[A][1].first - transformed[A][0].first) + Y[B - 1] * (transformed[A][2].first - transformed[A][0].first) + transformed[A][0].first << ' ' << X[B - 1] * (transformed[A][1].second - transformed[A][0].second) + Y[B - 1] * (transformed[A][2].second - transformed[A][0].second) + transformed[A][0].second << endl;
  }

  return 0;
}


#include <bits/stdc++.h>
#include <unordered_set>
#include <cmath>

// URL: https://atcoder.jp/contests/abc190/tasks/abc190_c

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vs = vector<string>;

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

#define repll(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repsll(i, s, n) for (ll i = (ll)(s); i < (ll)(n); i++)

#define ALL(a) (a).begin(), (a).end()

#define pb push_back
#define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)

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

const ll INFL = 1e18;
const int INF = 1e9;

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

int main(){
    optimize_cin();

    int N, M;
    cin >> N >> M;
    vi A(M), B(M);
    rep(i, M){
        cin >> A.at(i) >> B.at(i);
    }

    int K;
    cin >> K;
    vi C(K), D(K);
    rep(i, K){
        cin >> C.at(i) >> D.at(i);
    }

    ll pattern = 1, diff = 0;
    rep(i, K) pattern *= 2;
    diff = pattern;
    pattern *= 2;

    int max = 0;

    repsll(i, diff, pattern){
        int cnt = 0, ord = 0, tmp = i;
        vi dish(N, 0);
        while(tmp > 0){
            if(tmp % 2 == 0) dish[C[ord] - 1]++;
            else dish[D[ord] - 1]++;
            tmp /= 2;
            ord++;
            if(ord == K) break;
        }
        rep(j, M){
            if(dish[A[j] - 1] > 0 && dish[B[j] - 1]) cnt++;
        }
        chmax(max, cnt);
    }

    cout << max << endl;

    return 0;
}

# pragma GCC optimize ("O3")
# pragma GCC optimize ("Ofast")
# pragma GCC optimize ("unroll-loops")
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i < (b); i++)
#define rep2(i,a,b) for(int i = (b) - 1; i >= (a); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define em emplace
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll
#define x first
#define y second
using namespace std;
using ll = long long;
using ld = long double;
using pi = pair<int, int>;
using ti = tuple<int, int, int>;
using pl = pair<ll, ll>;
using tl = tuple<ll, ll, ll>;

const int MOD = 998244353;
int N, W[111], tot;
template<class T> struct mi {
	T val;
	mi() { val = 0; }
	mi(const ll& v) {
		val = (-MOD <= v && v <= MOD) ? v : v % MOD;
		if (val < 0) val += MOD;
	}
	mi operator + (const mi& m) {
		T tmp = (val + m.val) % MOD;
		return tmp + (tmp < 0 ? MOD : 0);
	}
	mi operator - (const mi& m) {
		T tmp = (val - m.val) % MOD;
		return tmp + (tmp < 0 ? MOD : 0);
	}
	mi operator * (const mi& m) {
		T tmp = (val * m.val) % MOD;
		return tmp;
	}
	mi& operator += (const mi& m) {
		if ((val += m.val) >= MOD) val -= MOD;
		return *this;
	}
	mi& operator -= (const mi& m) {
		if ((val -= m.val) < 0) val += MOD;
		return *this;
	}
	mi& operator *= (const mi& m) {
		val = (val * m.val) % MOD;
		return *this;
	}
};
mi<ll> f[111], dp[111][11111], ans;
int main() {
    cin.tie(0) -> sync_with_stdio(false); cout.tie(0);
    cin >> N;
    rep(i, 0, N) {
        cin >> W[i];
        tot += W[i];
    }
    if(tot & 1){cout << "0\n"; return 0;}
    tot >>= 1;
    f[0] = 1;
    rep(i, 1, N + 1) f[i] = f[i - 1] * i;
    dp[0][0] = 1;
    rep(i, 0, N) rep2(j, 0, i + 1) rep(k, W[i], 100 * N + 1) {
        dp[j + 1][k] += dp[j][k - W[i]];
    }
    rep(j, 0, N + 1) ans += f[j] * f[N - j] * dp[j][tot];
    cout << ans.val << endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll r,x,y;
    cin >> r >> x >> y;
    ll po = x*x + y*y;
    ll res = 0;
    r *= r;
    res = po / r;
    //cout << res << endl;
    //cout << pow((ll)(sqrt(res)),2) << endl;
    if(pow((ll)(sqrt(res)),2) == res && po % r == 0){
        res = sqrt(res);
    }
    else {
        res = sqrt(res);
        res += 1;
        res = max(res,(ll)2);
    }
    cout << res << endl;
}

# include <cstdio>
int t[100],t_n=0;
bool b[12];
void work(int x) {
	int now=x;
	t[t_n++]=now; b[now]=true;
	while(!b[now*x%10]) now=now*x%10, b[now]=true, t[t_n++]=now;
}
int qpow(int x,int p,int mod) {
	int res=1;
	while(p) {
		if(p&1) res=1ll*res*x%mod;
		x=1ll*x*x%mod; p>>=1;
	}
	return (res-1+mod)%mod;
}
int main() {
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	work(a%10);
	printf("%d",t[qpow(b,c,t_n)]);
	return 0;
}


#include <string>
#include <iostream>
#include <stack>
#include <queue> // priority_queue も入ってる
#include <set>   // 要素数は size() で取得 multisetもある
#include <map>
#include <array> // sizeはコンパイル時定数で固定
#include <vector>
#include <numeric>   // accumulate, gcd
#include <algorithm> // count_ifに必要
#include <iomanip>   // cout << setprecision(15) << x で小数の出力精度を指定
#include <tuple>
#include <utility> //pair
#include <cmath>
#include <random>

using namespace std;
using ll = long long;

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

// BIT
// Binary Indexed Tree
// Fenwick Tree

// Inverse Semigroup で使えますが、普通は群でしょう。
// 可逆でなく、単なるモノイドの場合はセグメントツリーを使うこと。

// 0番は空けて、1-indexedです。

// 3 1 4 1 5 9 2 6 5 3 5を1回更新して1回区間和を出す例題になってます。

// 更新メソッド
// incrementは増分。新しい値そのものではないので注意！
int updateTree(vector<ll> &tree, int index, ll increment)
{
    while (index < tree.size())
    {
        tree[index] = tree[index] ^ increment;
        // 1110 = 1110 + 0010 → 10000 みたいな。一番下位の1を足す。
        index += (index & (-index));
    }
    return 0;
}

// 累積和取得メソッド。区間和の取得はこれの差で。
ll getSum(vector<ll> &tree, int index)
{
    ll result = 0;
    while (index > 0)
    {
        result = result ^ tree[index];
        index -= (index & (-index));
    }
    return result;
}

int main()
{
    // TODO: 入力を受け取る。
    ll n, q;
    cin >> n >> q;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    vector<ll> T(q), X(q), Y(q);
    rep(i, q) cin >> T[i] >> X[i] >> Y[i];

    // 構築。
    vector<ll> tree(n + 1, 0);
    for (int i = 1; i <= n; ++i)
    {
        updateTree(tree, i, a[i - 1]);
    }

    // TODO: クエリの処理
    rep(i, q)
    {
        // 0 <= i <= q-1
        if (T[i] == 1)
        {
            // update
            updateTree(tree, X[i], Y[i]);
        }
        else
        {
            // output
            ll result = getSum(tree, Y[i]) ^ getSum(tree, X[i] - 1);
            cout << result << endl;
        }
    }

    return 0;
}

#include <bits/stdc++.h>
#define isz(x) (int)(x).size()
struct Fenwick {
    std::vector<int> data;
    Fenwick(int n) : data(n,0) { }
    void inc(int p, int x) {
        for (int i = p; i < isz(data); i |= i+1)
            data[i] += x;
    }
    void inverse(int i) {
        int oldValue = get(i,i);
        int newValue = 1-oldValue;
        inc(i,newValue-oldValue);
    }
    int get(int r) {
        int res(0);
        while (r >= 0) {
            res += data[r];
            r = (r & (r+1)) - 1;
        }
        return res;
    }
    int get(int l, int r) {
        return get(r) - get(l-1);
    }
};
int main() {
    int n,q;
    scanf("%d %d", &n, &q);
    std::vector<Fenwick> fenw(30,Fenwick(1+n));
    for (int i = 1, a; i <= n; i++) {
        scanf("%d", &a);
        for (int bit = 0; bit < 30; bit++)
            if((a >> bit)&1)fenw[bit].inverse(i);
    }
    while (q --> 0) {
        int t,x,y; scanf("%d %d %d", &t, &x, &y);
        if (t == 1) {
            for (int bit = 0; bit < 30; bit++)
                if ((y >> bit) & 1) fenw[bit].inverse(x);
        } else {
            int answ{0};
            for (int bit = 0; bit < 30; bit++)
                answ |= (fenw[bit].get(x,y)&1) << bit;
            printf("%d\n", answ);
        }
    }
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  if (n % 2 == 0)
    cout << "White" << endl;
 else
   cout << "Black" << endl;
  return 0;
}

#include "bits/stdc++.h"
using namespace std;
typedef long long lint;
#define int lint
const int MOD = 1e9 + 7;
const int INF = 1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, k, n) for (int i = (k); i < (int)(n); ++i

signed main()
{
    int n;
    cin >> n;
    if (n % 2 == 0)
        cout << "White" << endl;
    else
        cout << "Black" << endl;
    return 0;
}


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

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

ll x;
map<ll, ll> sv;

ll f(ll y){
	if (sv.find(y) != sv.end()) return sv.find(y)->second;
	sv[y] = 0LL;
	ll &ans = sv[y];
	if (y>x){
		if (y&1){
			ll ri = y+1LL;
			ll le = y-1LL;
			return ans = min(f(ri)+1LL, f(le)+1LL);
		}else{
			ll ab = y-x;
			ll divi = y/2;
			return ans = min(f(x) + ab, f(divi) + 1);
		}
	}else if (y<x){
		return ans = x-y + f(x);
	}else return ans = 0LL;
}

void solve(){
	ll y; cin >> x >> y;
	cout << f(y) << '\n';
}

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

	int t = 1; //cin >> t;
	while(t--) solve();

	return 0;
}
// NK

#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
#define INF 1000000007
using namespace std;
int a,b,k,m,n,cnt=0,aa[110000];
string s,t;
char c;
signed main()
{
	cin>>n>>k>>m;
	rep(i,n-1){
		cin>>aa[i];
		cnt+=aa[i];
	}
	if(n*m-cnt>k){
		cout<<-1;
	}elif(n*m-cnt<0){
		cout<<0;
	}else{
		cout<<n*m-cnt;
	}
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(), a.end()
#define len(x) (int)(x).size()
#define dup(x, y) (((x) + (y)-1) / (y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int h, w, n, m;
  cin >> h >> w >> n >> m;
  map<P, int> ab;
  rep(i, 0, n) {
    int a, b;
    cin >> a >> b;
    ab[P(a - 1, b - 1)] = 0;
  }
  map<P, int> cd;
  rep(i, 0, m) {
    int c, d;
    cin >> c >> d;
    cd[P(c - 1, d - 1)] = 0;
  }
  Field(bool) yoko(h, vector<bool>(w, false));
    bool l = false;
  rep(i, 0, h) {
    int s = 0;
    l = false;
    rep(j, 0, w) {
      if (ab.find(P(i, j)) != ab.end()) {
        rep(k, s, j + 1) {
          yoko[i][k] = true;
        }
        l = true;
        s = j + 1;
      } else if (cd.find(P(i, j)) != cd.end()) {
        if (l) {
          l = false;
          rep(k, s, j) { yoko[i][k] = true; }
          s = j + 1;
        } else {
          rep(k, s, j) { yoko[i][k] = false; }
          s = j + 1;
        }
      }
    }
    if (l) {
      rep(k, s, w) {
        yoko[i][k] = true;
      }
    }
  }
  Field(bool) tate(h, vector<bool>(w, false));
  l = false;
  rep(i, 0, w) {
    int s = 0;
    l = false;
    rep(j, 0, h) {
      if (ab.find(P(j, i)) != ab.end()) {
        rep(k, s, j + 1) {
          tate[k][i] = true;
          l = true;
        }
        s = j + 1;
      } else if (cd.find(P(j, i)) != cd.end()) {
        if (l) {
          l = false;
          rep(k, s, j) { tate[k][i] = true; }
          s = j + 1;
        } else {
          rep(k, s, j) { tate[k][i] = false; }
          s = j + 1;
        }
      }
    }
    if (l) {
      rep(k, s, h) {
        tate[k][i] = true;
      }
    }
  }
  int ans = 0;
  rep(i,0,h) rep(j,0,w){
    if (yoko[i][j] || tate[i][j]) ans++;
  }
  cout << ans << endl;
  return 0;
}

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

#include <bits/stdc++.h>
// #include <atcoder/modint>
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define INF 2000000000000000000
#define ll long long
#define ld long double
#define pll pair<ll, ll>
using namespace std;
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; }

struct edge {ll to, cost, k;};
//=============dijkstra============================
vector<ll> dijkstra(ll s, ll V, vector<vector<edge>>& G)
{
  vector<ll> d(V, INF);
  typedef pair<ll, ll> P;// first は最短距離　second は頂点の番号
  priority_queue<P, vector<P>, greater<P>> que;
  d.at(s) = 0;
  que.push(P(0, s));
  while (!que.empty())
  {
    P p = que.top();
    que.pop();
    ll v = p.second;
    if (d.at(v) < p.first) continue;
    for (ll i = 0; i < G.at(v).size(); ++i)
    {
      edge e = G.at(v).at(i);
      if (d.at(e.to) > ((d.at(v) + e.k - 1) / e.k) * e.k + e.cost)
      {
        d.at(e.to) = ((d.at(v) + e.k - 1) / e.k) * e.k + e.cost;
        que.push(P(d.at(e.to), e.to));
      }
    }
  }
  return d;
}
//=================================================

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N, M, X, Y;
  cin >> N >> M >> X >> Y;
  X -= 1, Y -= 1;
  vector<vector<edge>> connection(N);
  for (ll i = 0; i < M; ++i) {
    ll a, b, t, k;
    cin >> a >> b >> t >> k;
    a -= 1, b -= 1;
    connection.at(a).push_back({b, t, k});
    connection.at(b).push_back({a, t, k});
  }
  vector<ll> d = dijkstra(X, N, connection);
  if (d.at(Y) == INF) {
    cout << -1 << "\n";
  }
  else {
    cout << d.at(Y) << "\n";
  }
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
int read(){
	int a=0,fh=1;char c=getchar();
	while(c>'9'||c<'0'){if(c=='-')fh=-1;c=getchar();}
	while('0'<=c&&c<='9'){
		a=a*10+c-48;
		c=getchar();
	}
	return a*fh;
}
#define MN 200005
#define pii pair<int,int>
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define vc vector
int n,k;
int id[MN],DEP[MN],dep[MN],fa[MN],w[MN],sec[MN];
int vis[MN],dfn[MN],cnt,ID[MN],siz[MN];
bool cmp(int a,int b){return dep[a]<dep[b];}
vector<int>e[MN];
void dfs(int x){
	dfn[x]=++cnt;
	ID[cnt]=x;
	dep[x]=dep[fa[x]]+1;
	siz[x]=1;
	for(int i=0;i<e[x].size();++i){
		int v=e[x][i];
		if(fa[x]==v)continue;
		fa[v]=x;dfs(v);
		if(DEP[v]>DEP[w[x]]){
			sec[x]=DEP[w[x]]+1;
			w[x]=v;
		}
		else sec[x]=max(sec[x],DEP[v]+1);
		siz[x]+=siz[v];
	}
	DEP[x]=DEP[w[x]]+1;
}
int mid,st[MN],top,FA[MN];
void DFS(int x){
	st[++top]=x;
	if(dep[x]>mid)FA[x]=st[top-mid];
	else FA[x]=1;
	for(int i=0;i<e[x].size();++i){
		int v=e[x][i];
		if(fa[x]==v)continue;
		DFS(v);
	}
	top--;
}
int mx[MN<<2];
#define Ls (x<<1)
#define Rs (x<<1|1)
void pushup(int x){
	mx[x]=max(mx[Ls],mx[Rs]);
}
void build(int x,int l,int r){
	if(l==r){mx[x]=dep[ID[l]];return;}
	int mid=l+r>>1;
	build(Ls,l,mid);
	build(Rs,mid+1,r);
	pushup(x);
}
void del(int x,int l,int r,int loc){
	if(l==r){mx[x]=0;return;}
	int mid=l+r>>1;
	if(loc<=mid)del(Ls,l,mid,loc);
	else del(Rs,mid+1,r,loc);
	pushup(x);
}
int ask(int x,int l,int r,int b,int e){
	if(b<=l&&r<=e)return mx[x];
	if(l>e||r<b)return 0;
	int mid=l+r>>1;
	if(e<=mid)return ask(Ls,l,mid,b,e);
	if(b>mid)return ask(Rs,mid+1,r,b,e);
	return max(ask(Ls,l,mid,b,e),ask(Rs,mid+1,r,b,e));
}
void fk(int x){
	if(vis[x])return;
	del(1,1,n,dfn[x]);
	vis[x]=1;
	for(int i=0;i<e[x].size();++i){
		int v=e[x][i];
		if(fa[x]==v)continue;
		if(!vis[v]){
			fk(v);
		}
	}
}
bool chk(){
	build(1,1,n);
	DFS(1);
	for(int i=1;i<=n;++i)vis[i]=0;
	int tot=0;
	for(int i=1;i<=n;++i){
		int x=id[i];
		if(!vis[x]){
			tot++;
			int u=FA[x],t=mid;
			fk(u);
			while(t&&fa[u]&&ask(1,1,n,dfn[fa[u]],dfn[fa[u]]+siz[fa[u]]-1)-dep[fa[u]]+1<=t){
				t--;u=fa[u];
				fk(u);
			}
		}
	}
	return tot<=k;
}
signed main(){
	n=read();k=read();
	for(int i=1;i<n;++i){
		int u=read(),v=read();
		e[u].pb(v);e[v].pb(u);
	}
	dfs(1);for(int i=1;i<=n;++i)id[i]=i;
	sort(id+1,id+1+n,cmp);reverse(id+1,id+1+n);
	int l=-1,r=n;
	while(l+1<r){
		mid=(l+r)>>1;
		if(chk())r=mid;
		else l=mid;
	}
	printf("%lld\n",r);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sz(v) int((v).size())
#define all(x) (x).begin(), (x).end()
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define int ll

int n, k;
vector<int> tree[222'222];
int cnt = 0;
int dfs(int now, int before, int U)
{
    int x = 0;
    for (int nxt: tree[now])
    {
        if (nxt == before) continue;
        int y = dfs(nxt, now, U);
        if (x > y) swap(x, y);
        if (x <= 0 && y > 0 && y - x <= U)
            x = y;
    }
    if (x == -U)
    {
        ++cnt;
        x = 1;
    }
    else if (x <= 0)
    {
        --x;
    }
    else ++x;
    return x;
}
bool test(int U)
{
    cnt = 0;
    int cur = dfs(0, 0, U);
    if (cur < 0) ++cnt;
    return cnt <= k;
}
void solve()
{
    cin>>n>>k;
    forn(_, n-1)
    {
        int a, b; cin>>a>>b; --a, --b;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    int lf = 0, rg = 222'222;
    while(lf < rg)
    {
        int mid =( lf + rg) / 2;
        if (test(mid)) rg = mid;
        else lf = mid + 1;
    }
    cout << lf << endl;
}
signed main(void)
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    signed T = 1; // cin >> T;
    for(int i=1;i<=T;++i)
    {
        solve();
    }
    return 0;
}