#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, a[N], b[N], p[N], rp[N], id[N];
void gao(int x, int y)
{
	if(a[x]<=b[p[x]] || a[y]<=b[p[y]])
	{
		puts("-1");
		exit(0);
	}
	rp[p[y]] = x, rp[p[x]] = y;
	swap(p[x], p[y]);
}
int main()
{
	scanf("%d", &n);
	for(int i=1; i<=n; i++) scanf("%d", a+i);
	for(int i=1; i<=n; i++) scanf("%d", b+i);
	for(int i=1; i<=n; i++) scanf("%d", p+i), rp[p[i]] = i;
	iota(id+1, id+n+1, 1);
	sort(id+1, id+n+1, [&](int x, int y) { return a[x] < a[y]; });
	vector<pair<int, int>> seq;
	for(int i=1; i<=n; i++)
	{
		int j = id[i], k = rp[j];
		if(j==k) continue;
		if(a[k]>b[p[j]])
		{
			gao(j, k);
			seq.emplace_back(j, k);
		}
		else
		{
			gao(k, n);
			seq.emplace_back(k, n);
			gao(j, n);
			seq.emplace_back(j, n);
		}
	}
	for(int i=1; i<=n; i++) assert(i==p[i]);
	printf("%d\n", (int)seq.size());
	for(auto &it : seq) printf("%d %d\n", it.first, it.second);
	return 0;
}

//#define _GLIBCXX_DEBUG

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}
template<typename T>void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++){cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++){for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>vector<vector<T>>vec(ll x, ll y, T w){vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,-1,0,0,1,1,-1,-1};vector<ll>dy={0,0,1,-1,1,-1,1,-1};
template<typename T>vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<typename T1, typename T2>ostream &operator<<(ostream &os, const pair<T1, T2>&p){return os << p.first << " " << p.second;}
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v){for(auto &z:v)os << z << " ";cout<<"|"; return os;}
template<typename T>void rearrange(vector<ll>&ord, vector<T>&v){
  auto tmp = v;
  for(int i=0;i<tmp.size();i++)v[i] = tmp[ord[i]];
}
template<typename Head, typename... Tail>void rearrange(vector<ll>&ord,Head&& head, Tail&&... tail){
  rearrange(ord, head);
  rearrange(ord, tail...);
}
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
int popcount(ll x){return __builtin_popcountll(x);};
int poplow(ll x){return __builtin_ctzll(x);};
int pophigh(ll x){return 63 - __builtin_clzll(x);};

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n;cin>>n;
  vector<ll>a(n),b(n),p(n);
  rep(i,0,n)cin>>a[i];
  rep(i,0,n)cin>>b[i];
  rep(i,0,n)cin>>p[i],p[i]--;
  vector<ll>rev(n);
  rep(i,0,n){
    rev[p[i]]=i;
    if(i!=p[i]&&a[i]<=b[p[i]]){
      cout<<-1<<endl;
      return 0;
    }
  }
  vector<P>ret;
  vector<bool>ok(n);
  rep(i,0,n){
    if(ok[i])continue;
    vector<ll>v;
    ll now=i;
    while(!ok[now]){
      ok[now]=true;
      v.PB(now);
      now=p[now];
    }
    sort(ALL(v),[&](ll x,ll y){
      return b[x]>b[y];
    });
    rep(j,0,(ll)v.size()-1){
      ll x=rev[v[j]],y=v[j];
      ret.EB(x+1,y+1);
      swap(p[x],p[y]);
      swap(rev[p[x]],rev[p[y]]);
    }
  }
  //debug(p,n);
  cout<<ret.size()<<endl;
  for(auto z:ret)cout<<z<<endl;
  return 0;
}


//ABC182_C_To 3 bit_all+組み合わせ//
#include <bits/stdc++.h>
//repマクロの定義//
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int f(long long a){
    long long ga=a;
    int A[11];
    int j=0;

    while(ga>0){
        A[j]=ga%10;
        ga/=10;
        j++;
    }
    sort(A,A+j);

    int g=0;
    int G=0;

    long long gj=1;
    long long Gj=1;
    rep(m,j-1){
        Gj*=10;
    }

    for (int i=0;i<j;i++){
        g+=A[i]*gj;
        G+=A[i]*Gj;
        gj*=10;
        Gj/=10;
    }

    return g-G;
}

int main(){
    //入力を用意//
    long long K,N;
    cin >> N >> K;

    int a=f(N);

    if(K==0){
        a=N;
    }else if(K==1){
        a=f(N);
    }else{
        for(int i=1;i<K;i++){
            a=f(a);
        }
    }

    //出力//
    cout << a << endl;

    return 0;

}

#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,k,a[20],b[20];
ll getlen(){
	for(ll i=10;i>=1;i--){
		if(a[i]!=0)return i;
	}
	return 0;
}
int main(){
	cin >> n >> k;
	if(k==0){
		cout << n;
		return 0;
	}
	ll i=0;
	while(n>0){
		i++;
		a[i]=n%10;
		n/=10;
	}
	while(k--){
		ll t=getlen();
		//printf("t=%lld\n",t);
		sort(a+1,a+t+1);
		n=0;
		for(ll i=t;i>=1;i--){
			n=n*10+a[i];
		}
		ll m=0;
		for(ll i=1;i<=t;i++){
			m=m*10+a[i];
			a[i]=0;
		}
		n-=m;
		if(k==0)cout << n;
		i=0;
		while(n>0){
			i++;
			a[i]=n%10;
			n/=10;
		}
	}
}


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

string S;
int main(){
  cin >> S;
  int ans = 0;
  for(int i=0; i<S.size(); i++){
    if(i%2==0){
      //奇数番目
      if(isupper(S[i])){
        ans += 1;
      }
    }
        //大文字の時
    else{
      if(islower(S[i])){
              //偶数番目
        ans += 1;
      }
    }
  }
  if(ans == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define MOD 1000000007
#define fi(i,a,n) for(lli i = a; i < n; i++)
#define fd(i,a,n) for(lli i = a; i > n; i--)
#define fv(i,a) for(auto i:a)
#define pb push_back
#define mp make_pair

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

// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
lli t=1;
//cin>>t;
while(t--)
{
	string s;
	cin>>s;
	fi(i,0,s.size()){
		if(i%2==0 && isupper(s[i])) {
			cout<<"No";
			return 0;
		}
		if(i%2==1 && islower(s[i])) {
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
}
return 0;
}


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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    rep(i,n) cin >> a[i] >> b[i];

    int ans = INT_MAX;

    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            ans = min(ans, max(a[i], b[j]));
            ans = min(ans, max(a[j], b[i]));
        }
    }

    for(int i=0; i<n; i++){
        ans = min(ans, a[i]+b[i]);
    }

    cout << ans << endl;

    return 0;
}

#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("fast-math")

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define deb(x) cout << #x << " is " << x << "\n"
#define int long long
#define MOD 1000000007LL
#define PI acos(-1)

template <typename T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;

template <typename T>
using max_heap = priority_queue<T>;

template <class T>
using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

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

template <typename... T>
void write(T &&...args) {
    ((cout << args), ...);
}

template <typename T>
void readContainer(T &t) {
    for (auto &e : t) {
        read(e);
    }
}

template <typename T>
void writeContainer(T &t) {
    for (const auto &e : t) {
        write(e, " ");
    }
    write("\n");
}

auto speedup = []() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    return nullptr;
}();

void solve(int tc) {
    int N;
    read(N);
    vector<pair<int, int>> taken(N);
    for (int i = 0; i < N; i++) {
        read(taken[i].first, taken[i].second);
    }
    int ans = INT_MAX;
    for (int i = 0; i < N; i++) {
        ans = min(ans, taken[i].first + taken[i].second);
        for (int j = 0; j < N; j++) {
            if (i != j) {
                ans = min({ans, max(taken[i].first, taken[j].second), max(taken[i].second, taken[j].first)});
            }
        }
    }
    write(ans);
}

signed main() {
    int tc = 1;
    // read(tc);
    for (int curr = 1; curr <= tc; ++curr) {
        solve(curr);
    }
    return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;
typedef long double ld;
map<ll,ld> dp;
ld dfs(ll a,ll b,ll c){
  if(a>=100 || b>=100 || c>=100) return 0;
  else if(dp.count(10000*a+100*b+c)>=1) return dp[10000*a+100*b+c];
  else{
    ld res = 0;
    res += (ld)((1.0+dfs(a+1,b,c))*a)/(a+b+c);
    res += (ld)((1.0+dfs(a,b+1,c))*b)/(a+b+c);
    res += (ld)((1.0+dfs(a,b,c+1))*c)/(a+b+c);
    dp[10000*a+100*b+c] = res;
    return res;
  }
}
int main(){
  ll a,b,c;
  cin >> a >> b >> c;
  printf("%.12Lf\n",dfs(a,b,c));
  return 0;
}

#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

double dp[105][105][105];
bool visited[105][105][105];

int main(void) {
    int A, B, C;
    cin >> A >> B >> C;

    dp[A][B][C] = 1;

    queue<tuple<int, int, int>> q;
    q.push(make_tuple(A, B, C));
    visited[A][B][C] = true;

    while (!q.empty()) {
        tuple<int, int, int> elem = q.front();
        q.pop();

        int a, b, c;
        tie(a, b, c) = elem;

        double prob = dp[a][b][c];
        dp[a + 1][b][c] += prob * double(a) / double(a + b + c);
        if (a + 1 < 100 && !visited[a + 1][b][c]) {
            q.push(make_tuple(a + 1, b, c));
            visited[a + 1][b][c] = true;
        }
        dp[a][b + 1][c] += prob * double(b) / double(a + b + c);
        if (b + 1 < 100 && !visited[a][b + 1][c]) {
            q.push(make_tuple(a, b + 1, c));
            visited[a][b + 1][c] = true;
        }
        dp[a][b][c + 1] += prob * double(c) / double(a + b + c);
        if (c + 1 < 100 && !visited[a][b][c + 1]) {
            q.push(make_tuple(a, b, c + 1));
            visited[a][b][c + 1] = true;
        }
    }

    double ans = 0;
    for (int a = 0; a <= 100; a++) {
        for (int b = 0; b <= 100; b++) {
            for (int c = 0; c <= 100; c++) {
                if (a == 100 || b == 100 || c == 100) {
                    ans += dp[a][b][c] * ((a + b + c) - (A + B + C));
                }
            }
        }
    }

    printf("%.7f\n", ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
long double pi = 2 * acos(0.0);
const ll mod = 998244353;

void solve() {
    ll n;
    cin >> n;
    vector<pair<ll, ll>> v(n);
    for(ll i = 0; i < n; i++) cin >> v[i].first >> v[i].second;
    ll ans = 0;
    for(ll i = 0; i < n; i++) {
        for(ll j = i + 1; j < n; j++) {
            ld m = (ld)(v[j].second - v[i].second) / (v[j].first - v[i].first);
            if(m >= -1 && m <= 1) ans++;
        }
    }
    cout << ans;
}

int main() {
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
    ll t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define ALL(x) ::std::begin(x), ::std::end(x)
using namespace std;

char solve(int64_t A, int64_t B, int64_t C) {
    if((C % 2) == 0){
        A *= A;
        B *= B;
    }
    if(A == B) return '=';
    if(A < B) return '<';
    if(A > B) return '>';
}

// generated by online-judge-template-generator v4.7.1 (https://github.com/online-judge-tools/template-generator)
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    constexpr char endl = '\n';
    int64_t A, B, C;
    cin >> A >> B >> C;
    auto ans = solve(A, B, C);
    cout << ans << endl;
    return 0;
}

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

// typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update>PBDS;
#define mod 1000000007
#define INF 10000000000007
#define DEBUG false
#define N 200005
ll gcd(ll a , ll b) {return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b)
{
	return (a / gcd(a, b)) * b;
}

void solve()
{
	ll a, b, c;
	cin >> a >> b >> c;
	if (c % 2 == 0) {
		a = a * a;
		b = b * b;
	}
	if (a > b)cout << ">";
	else if (a < b)cout << "<";
	else cout << "=";
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output2.txt", "w", stdout);
#endif
	ll t = 1;
	//cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}


#include <bits/stdc++.h>
#define fi first
#define se second
//#define ivorysi
#define enter putchar('\n')
#define space putchar(' ')

#define pii pair<int,int>
typedef long long int64;
using namespace std;

template<class T>
void read(T &res) {
	res = 0;T f = 1;char c = getchar();
	while(c < '0' || c > '9') {
		if(c == '-') f = -1;
		c = getchar();
	}
	while(c >= '0' && c <= '9') {
		res = res * 10 + c - '0';
		c = getchar();
	}
	res *= f;
}
template<class T>
void out(T x) {
	if(x < 0) {x = -x;putchar('-');}
	if(x >= 10) out(x / 10);
	putchar('0' + x % 10);
}
const int MAXM = 100005;
int N,M;
int64 w[10],l[MAXM],v[MAXM],ans,sum[10],dis[10][10],dp[10];
int64 val[MAXM],len[MAXM];
int a[10],id[MAXM];
bool vis[10];
void dfs(int d) {
	if(d > N) {
		for(int i = 1 ; i <= N ; ++i) {
			sum[i] = sum[i - 1] + w[a[i]];
		}
		memset(dis,0,sizeof(dis));
		for(int j = 1 ; j <= N ; ++j) {
			for(int t = j + 1 ; t <= N ; ++t) {
				int cv = sum[t] - sum[j - 1];
				int p = lower_bound(val + 1,val + M + 1,cv) - val - 1;
				if(val[p] < cv) {
					dis[j][t] = len[p];
				}
			}
		}
		memset(dp,0,sizeof(dp));
		for(int i = 1 ; i <= N ; ++i) {
			for(int j = i + 1 ; j <= N ; ++j) {
				dp[j] = max(dp[j],dp[i] + dis[i][j]);
			}
		}
		ans = min(ans, dp[N]);
		return;
	}
	for(int i = 1 ; i <= N ; ++i) {
		if(!vis[i]) {
			a[d] = i;
			vis[i] = 1;
			dfs(d + 1);
			vis[i] = 0;
		}
	}
}
int main() {
#ifdef ivorysi
	freopen("f1.in","r",stdin);
#endif
	read(N);read(M);
	for(int i = 1 ; i <= N ; ++i) read(w[i]);
	for(int i = 1 ; i <= M ; ++i) {
		read(l[i]);read(v[i]);
		id[i] = i;
		ans += l[i];
	}
	ans = ans * N;
	sort(id + 1,id + M + 1,[](int a,int b) {return v[a] < v[b] || (v[a] == v[b] && l[a] > l[b]);});
	for(int i = 1 ; i <= M ; ++i) {
		val[i] = v[id[i]];
		len[i] = l[id[i]];
		len[i] = max(len[i],len[i - 1]);
	}
	for(int i = 1 ; i <= M ; ++i) {
		for(int j = 1 ; j <= N ; ++j) {
			if(w[j] > v[i]) {
				puts("-1");
				return 0;
			}
		}
	}
	dfs(1);
	out(ans);enter;
	return 0;
}

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>
//#include <atcoder/all>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define sz(v) (int)(v).size()
#define vi vector<int>
#define vll vector<long long>

using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//using mint = modint998244353;
//using mint = modint;

typedef long long ll;
typedef long double ld;

using P = pair<ll, ll>;
template<typename T>
struct Edge {
    int u, v;
    T cost;
    Edge(int u, int v, T c) : u(u), v(v), cost(c) {}
    bool operator< (const Edge &e) const {return cost < e.cost;}
};

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

ll ans = LINF;

int main(void) {
    int N, M;
    cin >> N >> M;
    vll W(N, 0), perm(N, 0);
    vector<P> V;

    rep(i, 0, N) cin >> W[i];
    rep(i, 0, N) perm[i] = i;
    rep(i, 0, M) {
        ll l, v;
        cin >> l >> v;
        V.pb(mp(v, l));
    }

    sort(all(V));
    rep (i, 0, N) if (W[i] > V[0].first) {
      puts("-1");
      return 0;
    }
    rep(i, 1, M) V[i].second = max(V[i].second, V[i-1].second);

    // ラクダの順列全探索
    do {
        vll dist(N, 0); // ラクダの配置座標

        rep(i, 1, N) {
            ll w = W[perm[i]];
            dist[i] = dist[i-1];
            per(j, 0, i) {
                w += W[perm[j]];
                int x = lower_bound(all(V), mp(w, 0LL)) - V.bg;
                if (x==0) continue;
                ll mxl = V[x-1].second;
                dist[i] = max(dist[i], dist[j]+mxl);
            }
        }
        ans = min(dist[N-1], ans);

    } while (next_permutation(all(perm)));

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


//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0xccccccc;
const ll LINF = 0xcccccccccccccccLL;
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);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

struct UnionFind {
	vector<int> par; // 親を指すvector,-par[親]は木のサイズ
	UnionFind(int n):par(n, -1) {} // uniteで親を埋め込んでいく必要あり
	int root(int x) { // 親をたどる&データの整理
		if(par[x] < 0) return x;
		return par[x] = root(par[x]);
	}
	bool unite(int x, int y) { // データの結合
		x = root(x);
		y = root(y);
		if(x == y) return false;
		if(par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}
	bool same(int x, int y) {return root(x) == root(y);} // 所属判定
	int size(int x) {return -par[root(x)];} // 木のサイズ
};

//head

#define N 400010

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vi cnt(N);
	UnionFind uft(N);
	rep(i, n) {
		int a, b;
		cin >> a >> b;
		uft.unite(a, b);
		cnt[a]++;
	}
	rep(i, N) if(uft.root(i) != i) cnt[uft.root(i)] += cnt[i];
	int ans = 0;
	rep(i, N) if(uft.root(i) == i) {
		ans += min(uft.size(i), cnt[i]);
	}
	cout << ans << endl;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef pair<int, pair<int,int> > ppi;
const ll mod = 1e9+7;
const int MAXN=4e5+3;
void pvec(vi v){
    for(auto x:v){
        cout << x << " ";
    }cout << endl;
}
ll gcd(ll x, ll y){
    if(y==0){
        return x;
    }else{
        return gcd(y, x%y);
    }
}

ll binpow(ll a, ll b) {
    if(b==0){
        return 1;
    }
    ll res = 1;
    ll tmp = binpow(a,b/2);
    res = (tmp*tmp);
    if(b%2==1){
        res = (res*a);
    }
    return res;
}

vector<vi> ad(MAXN);
vector<bool> vis(MAXN,false), mk(MAXN,false);
vi sz(MAXN, 1);
void dfs(int u, int st, int par=0){
    vis[u] = true;
    for(int v : ad[u]){
        if(!vis[v]){
            sz[st]++;
            dfs(v, st, u);
        }else if(v != par){
            mk[st] = true;
        }
    }
}
void solve(){
    int n;
    cin>>n;
    vi gd(MAXN, 0);
    for(int i=0; i<n; i++){
        int x,y;
        cin>>x>>y;
        if(x==y){
            // mk[x] = true;
            // gd[x] = 1;
            ad[x].push_back(x);
        }else{
            ad[x].push_back(y);
            ad[y].push_back(x);
        }
    }
    int s=0;
    for(int i=1; i<MAXN; i++){
        if(!vis[i]){
            dfs(i,i);
            s += sz[i];
            if(!mk[i] && gd[i]==0) s--;
            // if(sz[i]>1) cout << i << " "  << sz[i] << "\n";
        }
    }
    cout << s << "\n";
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
}


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

#define rep(i, a, b) for(int i=a; i<=b; i++)
#define trav(a, x) for(auto& a:x)
#define all(x) begin(x), end(x)
#define sz(x) (int) x.size()
#define f first
#define s second
#define nl "\n"
#define pb push_back
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
const int MOD=3;
template<class T> using pqg=priority_queue<T, vector<T>, greater<T>>;

int col[400000];
int cnt[400001];
int n;
string s;
map<char, int> mp;
map<int, char> rmp;
const int MAXN=500000;
ll fac[MAXN+5];

ll inv(ll a){
  if(a==1) return 1;
  if(a==2) return 2;
}

ll choose(ll n, ll k){
  if(k>n) return 0;
  if(cnt[n]>cnt[n-k]+cnt[k]) return 0;
  return (fac[n]*inv(fac[k])*inv(fac[n-k]))%3;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);

  cin >> n;
  fac[0]=1;
  for(ll i=1; i<=n; i++){
    int x=i;
    while(x/3){
      cnt[i]+=x/3;
      x/=3;
    }
    x=i;
    while(x%3==0) x/=3;
    fac[i]=(fac[i-1]*x)%3;
    // cout << i << " fac " << fac[i] << nl;
  }

  cin >> s;
  mp['R']=0;
  mp['B']=1;
  mp['W']=2;
  rmp[0]='R';
  rmp[1]='B';
  rmp[2]='W';
  int ans=0;
  rep(i, 0, n-1){
    // cout << mp[s[i]] << nl;
    // cout << choose(n-1, i) << " ";
    ans+=choose(n-1, i)*mp[s[i]];
    ans%=3;
  }
  if(n%2==0) ans=(3-ans)%3;
  cout << rmp[ans];
}

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

// nCk mod p
struct Lucas {
    vector<vector<long long>> table;
    long long p; // prime number
    Lucas(long long _p) : p(_p) { init(p); }

    void init(long long p) {
        table.assign(p, vector<long long> (p));
        table[0][0] = 1;
        for(int i = 1; i < p; i++) {
            table[i][0] = 1;
            for(int j = i; j > 0; j--) {
                table[i][j] = (table[i - 1][j - 1] + table[i - 1][j]) % p;
            }
        }
    }

    long long comb(long long n, long long k) {
        long long ret = 1;
        while(n | k) {
            ret *= table[n % p][k % p];
            ret %= p;
            n /= p;
            k /= p;
        }
        return ret;
    }

};

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

    int n; string s; cin >> n >> s;
    int B = 0, W = 1, R = 2;
    vector<int> a(n);
    rep(i,n){
        if(s[i] == 'B') a[i] = B;
        if(s[i] == 'W') a[i] = W;
        if(s[i] == 'R') a[i] = R;
    }

    Lucas l(3);
    int ans = 0;
    rep(i,n) ans = (ans + l.comb(n - 1, i) * a[i]) % 3;
    if(n % 2 == 0) ans = (-ans + 3) % 3;
    if(ans == B) cout << 'B' << endl;
    if(ans == W) cout << 'W' << endl;
    if(ans == R) cout << 'R' << endl;
}


#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <cstring>
#include <queue>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cstdlib>
#include <sstream>
#include <bitset>

using namespace std;

using ll = long long;
using Vec = vector<ll>;
using P = pair<ll, ll>;
using VecP = vector<P>;
#define rep(i, n) for(ll i=0;i<(n);i++)
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

//static const ll MOD = 1000000007;
//static const ll INF = 1000000000;
//#define PI 3.14159265359

int main() {
    // input
    ll X, Y;
    cin >> X >> Y;

    // process
    ll W = max(X, Y);
    ll L = min(X, Y);

    if (W < L + 3) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#pragma GCC optimize ("-O3")
#define int long long
#define ld long double
#define endl "\n"

#define rep(i,begin,end) for (__typeof(end) i=begin-(begin>end); i!=(end)-(begin>end); i+=1-2*(begin>end))
#define umap unordered_map
#define pq priority_queue
#define pb push_back
#define mp make_pair
#define fs first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define mii map<int,int>
#define pii pair<int,int>
#define vc vector
#define vi vc<int>
#define vvi vc<vi>
#define all(v) v.begin(),v.end()
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define w(t) int t; cin>>t; rep(tc,0,t)
#define clr(a,x) memset(a,x,sizeof a)
#define chkbit(x,i) ((x)&(1LL<<(i)))
#define setbit(x,i) ((x)|(1LL<<(i)))
#define setbits(x)  __builtin_popcountll(x)
#define zerobits(x) __builtin_ctzll(x)
#define ps(x,y) fixed<<setprecision(y)<<x
#define print(a, n) rep(i,0,n) cout<<a[i]<<" "; cout<<endl;
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const int mod = 1e9+7;
const int mod2 = 998244353;
const long long inf = 1e18;
const long double PI = 3.141592653589793;

template<typename... T>
void in(T&... args) {((cin>>args), ...);}

template<typename... T>
void out(T&&... args) {((cout<<args<<" "), ...);}

template<typename... T>
void outln(T&&... args) {((cout<<args<<" "), ...); cout<<endl;}

int nxt(){int x;cin>>x;return x;}

int add(int a,int b,int mod=mod){int res=(a+b)%mod;return (res<0)?res+mod:res;}

int mul(int a,int b,int mod=mod){int res=(a*1LL*b)%mod;return (res<0)?res+mod:res;}

struct customCompare {
    bool operator () (int x, int y) {
        return x>y;
    }
};

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

const int N = 2e5;
int codejam = 0, testcases = 0;

void solve() {
    int x, y;
    cin >> x >> y;
    if (max(x, y) < min(x, y)+3) {
        cout << "Yes";
    }
    else {
        cout << "No";
    }
}

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

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

    int t = 1;
    if (testcases)
        cin >> t;
    for (int tc = 1; tc <= t; ++tc) {
        if (codejam)
            cout << "Case #" << tc << ": ";
        solve();
    }

    // printclock;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){
    int N;
    cin >> N;
    int price = (int)(floor(1.08 * N));
    if (price == 206){
        cout << "so-so"<<endl;
    } else {
        cout << (price < 206? "Yay!":":(") <<endl;
    }

    return 0;
}

#include <iostream>

using namespace std;

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

	for (int i = 0; i < N; ++i) {
		int a = (2 * i + 0) % N;
		int b = (2 * i + 1) % N;
		cout << a + 1 << " " << b + 1 << endl;
	}
}


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

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

template<typename... T>
void write(T... a){
    ((cout << a),...);
}

template<typename T>
vector<T> read_array(int sz){
    vector<T> ret(sz);
    for(auto & x : ret) cin >> x;
    return ret;
}

constexpr int mxN = 101;
ll a[mxN];
int n;
ll best[mxN];
ll x, y;
ll dp[mxN][mxN][mxN];

void solve(){
    read(n);
    read(x);
    REP(i, n){
        read(a[i]);
    }
    ll ans = x - a[0];

    REPS(sz, 1, n + 1){
        y = x % sz;
        //initialization
        REP(i, n){
            int need = min(i + 1, sz);
            REPS(j,1 ,need + 1){
                REP(k, sz){
                    dp[i][j][k] = 0;
                }
            }
        }

        // deb(sz)
        dp[0][1][a[0] % sz] = a[0];

        REPS(i, 1, n){
            int need = min(i + 1, sz);
            REPS(j,1 ,need + 1){
                REP(k, sz){
                    umax(dp[i][j][k], dp[i-1][j][k]);
                    if( j == 1){
                        if(a[i] % sz == k ) umax(dp[i][j][k], a[i]);
                        continue;
                    }
                    int k2 = (sz + k - a[i] % sz) % sz;
                    if(dp[i-1][j-1][k2] > 0)
                        umax(dp[i][j][k], dp[i-1][j-1][k2] + a[i]);

                    // debl(i) debl(j) debl(k)
                    // deb(dp[i][j][k])
                }
            }
        }

        REP(i, n){
            if(dp[i][sz][y] > 0)
                umin(ans, (x - dp[i][sz][y]) / sz );
        }

    }
    cout << ans << endl;
}

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

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>
#include <cstddef>
#include <type_traits>
#include <vector>

using namespace std;
using lint = long long int;
long long int INF = 1e18;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

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

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i, n) for(int i=0;i<(int)(n);i++)

int main() {

  lint n, x; cin >> n >> x;
  vector<lint> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  lint ans = INF;
  for (lint k = 1; k <= n; k++) {
    vector<vector<lint>> dp(k + 1, vector<lint>(k, -INF));

    dp[0][x % k] = 0;
    for (int i = 0; i < n; i++) {
      vector<vector<lint>> nxt(k + 1, vector<lint>(k, -INF));

      for (int j = 0; j <= k; j++) {
        for (int l = 0; l < k; l++) {
          if (dp[j][l] == -INF) continue;
          // 使わない
          chmax(nxt[j][l], dp[j][l]);
          // 使う
          if (j + 1 <= k) {
            chmax(nxt[j + 1][(l + 10000000 * k - a[i]) % k], dp[j][l] + a[i]);
          }
        }
      }
      swap(dp, nxt);
    }

    // cerr << "k = " << k << ", dp = " << dp[k][0] << endl;
    if (dp[k][0] == -INF) continue;
    else {
      // assert((x - dp[k][0]) % k == 0);
      chmin(ans, (x - dp[k][0]) / k);
    }
  }

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


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi (3.141592653589)
#define mod 1000000007
#define float double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rrep(i, n) for(int i=n-1;i>=0;i--)
#define rep(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

vector<int> primeFactors(int n)
{
    vector<int> ans;
    for(int i=1;i*i<=n;i++)
    {
        if(n%i == 0)
        {
            ans.push_back(i);
            if(n/i != i)
                ans.push_back(n/i);
        }
    }
    return ans;
}
bool perfectCube(int N)
{
    int cube_root;
    cube_root = round(cbrt(N));

    // If cube of cube_root is equals to N,
    // then print Yes Else print No
    if (cube_root * cube_root * cube_root == N) {
        // cout << "Yes";
        return 1;
    }
    else {
        // cout << "NO";
        return 0;
    }
}
void solve()
{
    int t=1;
    // cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        map<char,int> mp;
        int ans = 0;
        int n = s.size();
        mp[s[n-1]] += 1;
        for(int i=n-2;i>=0;i--)
        {
            if(s[i] == s[i+1])
            {
                int minus = 0;
                if(mp.find(s[i]) != mp.end())
                    minus = mp[s[i]];

                ans += (n-1-i) - minus;
                mp.clear();
                mp[s[i]] = n-i;
            }
            else
            {
                mp[s[i]] += 1;
            }

        }
        cout<<ans;
    }
}

int32_t main(){

    solve();
    return 0;
}

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

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define ll long long
#define int ll
#define ld long double
#define pii pair<int, int>
#define f first
#define s second
#define readl(_s) getline(cin, (_s));
#define boost() cin.tie(0); cin.sync_with_stdio(0)

string s;
int cnt[26];

int32_t main() {
    boost();

    cin >> s;
    int ans = 0;
    reverse(s.begin(), s.end());
    //cnt[s[0] - 'a']++, cnt[s[1] - 'a']++;
    for (int i = 2; i < s.size(); i++) {
        cnt[s[i - 2] - 'a']++;
        if (s[i] == s[i - 1] && s[i] != s[i - 2]) {
            int id = s[i] - 'a';
            ans += i - 1 - cnt[id];
            for (int j = 0; j < 26; j++) cnt[j] = 0;
            cnt[id] = i - 1;
        }
    }
    printf("%lld\n", ans);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define SORT(a) sort(a.begin(),a.end())
#define rSORT(a) sort(a.rbegin(),a.rend())
#define fSORT(a,f) sort(a.begin(),a.end(),f)
#define all(a) a.begin(),a.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define tp(a,i) get<i>(a)
#ifdef _DEBUG
#define line cout << "-----------------------------\n"
#define stop system("pause")
#define debug(x) print(x)
#endif
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }
template<class T>inline T sum(const vector<T>& a, int l, int r) { return a[r] - (l == 0 ? 0 : a[l - 1]); }
template<class T>inline void END(T s) { print(s); exit(0); }
void END() { exit(0); }

int main() {
    init();

    int n; cin >> n;
    VI a(n), b(n), p(n); cin >> a >> b >> p;

    set<pair<int, int>> s; // {持てる重さ、index}
    FOR(i, 0, n) {
        --p[i];
        if (a[i] <= b[p[i]] && p[i] != i)END(-1);
        if (i != p[i]) {
            s.emplace(a[i], i);
        }
    }

    vector<pair<int, int>> ans;
    while (!s.empty()) {
        int cur = s.rbegin()->second;
        int to = p[cur];
        ans.emplace_back(cur, to);
        if (p[to] == cur) {
            s.erase(pair<int, int>(a[cur], cur));
            s.erase(pair<int, int>(a[to], to));
        }
        else {
            s.erase(pair<int, int>(a[to], to));
            p[cur] = p[to];
        }
    }

    print(ans.size());
    for (auto [x, y] : ans)print(x + 1, y + 1);

    return 0;
}

#include<bits/stdc++.h>
using ll= long long;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define ALL(x) x.begin(),x.end()

#define INF (ll)1e9 //10^9:∞
#define LLINF (ll)1e12
#define MOD (ll)(1e9+7) //10^9+7:合同式の法
#define PI 3.141592653589
#define PB push_back
#define F first
#define S second
#define __MAGIC__ ios::sync_with_stdio(false);cin.tie(nullptr);

#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

#define Graph vector<vector<int>>
#define PII pair<int,int>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VPII vector<pair<int,int>>

#define DDD fixed<<setprecision(10)
#define endl "\n"

using namespace std;
/*..................DEFINE GLOBAL VARIABLES...................*/

/*.....................DEFINE FUNCTIONS ......................*/

/*.........................kemkemG0...........................*/
signed main() {
	__MAGIC__

	int A,B;
	cin>>A>>B;
	cout<<(2*A+100)-B<<endl;

		return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
typedef vector<int> vi;
typedef vector<string> vs;
const int mod = 1000000007;
const int inf = 1061109567;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
signed main()
{
    int h, w;
    cin >> h >> w;
    vs s(h);
    rep(i,h) cin >> s[i];

    set<pair<int, int> > cur;

    int ans = 0;
    for(int i=1; i<h-1; i++){
        int j = 1;
        int a = 1, b = w-1;
        bool check = false;
        set<pair<int, int> > now;
        while(1){
            if(s[i][j] == '#'){
                if(check) b = j;
                else{
                    a = j;
                    b = j;
                    check = true;
                }
            }
            else{
                if(check){
                    int plus = 4;
                    for(auto u : cur){
                        if(u.first == a && u.second == b) plus = 0;
                        else if(u.first == a || u.second == b) plus -= 2;
                    }
                    //cout << plus << endl;
                    ans += plus;
                    now.insert(make_pair(a, b));
                    check = false;
                }
            }
            j++;
            if(j == w) break;
        }
        //for(auto u : now) cout << u.first << ' ' << u.second << endl;
        cur = now;
    }

    cout << ans << endl;

    return 0;
}

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

#define PI 3.141592653589
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define ii pair<int,int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pll pair<ll,ll>
#define vv vector
#define all(v) (v).begin(),(v).end()
#define MAXN 300005
int MOD=1e9+7;
ll power(ll a, ll b){//a^b
    ll res=1;
    a=a%MOD;
    while(b>0){
        if(b&1){res=(res*a)%MOD;b--;}
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
ll min(ll a,ll b){return (a>b)?b:a;}
ll max(ll a,ll b){return (a>b)?a:b;}
bool prime[1000001];
vi primes;
void SieveOfEratosthenes(int n)
{
    memset(prime, true, sizeof(prime));
    prime[0]=prime[1]=0;
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for(int p=2;p<1000001;p++)
        if(prime[p])
            primes.pb(p);
}
ll fact[1000010];
ll finv[1000010];
void factorial(int n){
    fact[0]=1;
    finv[0]=1;
    for(int i=1;i<=n;i++)
        fact[i]=fact[i-1]*i,fact[i]%=MOD,finv[i]=fermat_inv(fact[i]);
}
ll ncr(ll n,ll r)
{
    if(n<r)
        return 0;
    else{
        ll x=finv[r]*finv[n-r]%MOD;
        return fact[n]*x%MOD;
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    int te=1;
    //cin>>te;
    //SieveOfEratosthenes(1000000);
    //factorial(1000005);
    while(te--){
        int h,w;
        cin>>h>>w;
        string a[h];
        for(int i=0;i<h;i++)
            cin>>a[i];
        int ans=0;
        for(int i=1;i<h-1;i++){
            for(int j=1;j<w-1;j++){
                if(a[i][j]=='.')
                    continue;
                if(a[i][j-1]=='.'&&a[i-1][j]=='.')
                    ans++;
                if(a[i][j+1]=='.'&&a[i-1][j]=='.')
                    ans++;
                if(a[i][j-1]=='.'&&a[i+1][j]=='.')
                    ans++;
                if(a[i][j+1]=='.'&&a[i+1][j]=='.')
                    ans++;
                if(a[i][j-1]=='#'&&a[i-1][j]=='#'&&a[i-1][j-1]=='.')
                    ans++;
                if(a[i][j+1]=='#'&&a[i-1][j]=='#'&&a[i-1][j+1]=='.')
                    ans++;
                if(a[i][j-1]=='#'&&a[i+1][j]=='#'&&a[i+1][j-1]=='.')
                    ans++;
                if(a[i][j+1]=='#'&&a[i+1][j]=='#'&&a[i+1][j+1]=='.')
                    ans++;
            }
        }
        cout<<ans;
    }
}


#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define rep(i, a, n) for (int i=(a); i<(n); i++)
#define per(i, a, n) for (int i=(a); i>(n); i--)
typedef long long ll;
const int maxn = 2e5+5;
const int mod = 1e9+7;
using namespace std;

void solve() {
	string s, tmp;
	ll n; cin >> n >> tmp;
	ll k = (n+2)/3;
	if (tmp == "1") return cout << ll(1e10)*2 << '\n',void(0);
	rep(i,0,k) s+="110";
	if (s.find(tmp) == string::npos) k++, s += "110";
	if (s.find(tmp) == string::npos) return cout << "0\n", void(0);
	cout << ll(1e10)-k+1 << '\n';
}

int main(int argc, char * argv[])
{
	ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef DEBUG
	freopen("C:/Users/Fish_Brother/Desktop/in", "r", stdin);
	//freopen("C:/Users/Fish_Brother/Desktop/out", "w", stdout);
#endif

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

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
s.find_by_order(x) xth element in set
x.order_of_key(x) number of elements <x*/
#define ll long long
#define vi vector<int>
#define si set<int>
#define mii map<int,int>
#define pb push_back
#define pf push_front
#define PI acos(-1)
#define pii pair<int,int>
#define extract_word(s)  stringstream str(s); while(str>>word)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define SET(s) cout<<fixed<<setprecision(s)
#define set0(a) memset(a,0,sizeof(a))
#define endl "\n"
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define lower_string(s) transform(all(s),s.begin(),::tolower)
#define upper_string(s) transform(all(s),s.begin(),::toupper)
#define size(s) (int)s.size()
template<typename T,typename U>
bool compare(T x,U y){return(abs(x-y)<=1e-9);}
const int MOD=1e9+7;
void solve()
{
int a,b;
cin>>a>>b;
cout<<a/b;
}
int main()
{
//code
fastio
int t;
t=1;
while(t--)
{
solve();
cout<<endl;
}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a,b) memset(a,b,sizeof a)
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
int t,n,s,k;
void exgcd(ll a,ll b,ll &x,ll &y){
	if(!b){
		x=1,y=0;
		return;
	}
	exgcd(b,a%b,y,x); //这里仔细体会一下,这里我们将x1赋给y,y1赋给x
	y-=(a/b)*x;
}
int main(){
	scanf("%d",&t);
	while(t--){
		scanf("%d%d%d",&n,&s,&k);
		ll c=n-s;
		ll g=__gcd(k,n);
		if(c%g) puts("-1");
		else {
			ll x,y;
			exgcd(k,n,x,y);
			ll tmp=c/g;
			ll d=n/g;
			x*=tmp;
			x=(x%d+d)%d;
			if(c%k==0) printf("%lld\n",c/k);
			else printf("%lld\n",x);
		}
	}
	return 0;
}

#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define Pii pair<int,int>
#define Pll pair<long long,long long>
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
//vector<vector<ll>> dp(n,vector<ll>(n))
//2-dim:vector<vector<Type>> vv(n, vector<Type>(m, d));
//3-dim:vector<vector<vector<Type>>> vvv(n, vector<vector<Type>>(m, vector<Type>(l, d)));

using namespace std;

long long extGCD(long long a, long long b, long long &x, long long &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a%b, y, x);
    y -= a/b * x;
    return d;
}

long long gcd(long long a,long long b){
    if(b==0) return a;
    return gcd(b,a%b);
}
long long lcm(long long a,long long b){
    return a/gcd(a,b)*b;
}

signed main(){
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    int test; cin >> test;
    while(test--){
        ll n,s,k; cin >> n >> s >> k;
        if(s%gcd(n,k)!=0){
            cout << -1 << endl;
            continue;
        }
        ll ggg = gcd(gcd(n,k),s);
        n/=ggg; k/=ggg; s/=ggg;

        ll gc = gcd(n,k);
        n/=gc;
        k/=gc;
        ll x,y;
        extGCD(n,k,x,y);
        //cout << x << " " << y << endl;continue;
        x *= s;
        y *= s;
        y *= gc;

        ll g = n/gc;

        y = -y;
        if(y>0){
            ll kk = y/g;
            y -= kk*g;
        }else if(y<0){
            ll kk = (-y)/g;
            kk++;
            y += kk*g;
        }
        cout << y << "\n";
    }
    return 0;
}
// g++ main.cpp -o a.out && ./a.out


#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <math.h> // sqrt
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <iomanip> // setprecision
#include <bitset> // bitset
#include <functional> // greater,int>()
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<long long>;
using pii = pair<int, int>;
using psi = pair<string, int>;
#define rep(i, n) for(ll i = 0; i < (ll) n; i++)
#define FOR(i, a, b) for(ll i = a; i < (ll) b; i++)
#define ALL(x) x.begin(),x.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define COUT(ans) cout<<ans<<endl;
#define COUTD(ans) cout<<fixed<<setprecision(10)<<ans<<endl;

int i;
bool check;

ll f (map<char,int> &m, string s, vll &a) {
    ll ans = 0;
    for (char c : s) {
        ll num = 0;
        if (m.count(c)) {
            num = m.at(c);
        }
        else {
            num = a[i];
            m[c] = a[i];
            i++;
        }
        ans *= 10;
        ans += num;
        if (ans == 0) {
            check = true;
            return 0;
        }
    }
    return ans;
}

int main() {
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    vi data(26, 0);
    for(char c :s1) {
        int a = c - 'a';
        data[a]++;
    }
    for (char c : s2) {
        int a = c - 'a';
        data[a]++;
    }
    for (char c : s3) {
        int a = c - 'a';
        data[a]++;
    }
    int count = 0;
    rep(i, 25) {
        if (data[i] > 0) {
            count++;
        }
    }
    if (count > 10) {
        COUT("UNSOLVABLE")
        return 0;
    }
    vll a = {1,0,2,3,4,5,6,7,8,9};
    bool finish = false;
    do {
        i = 0;
        check = false;
        map<char, int> m;
        ll n1 = f(m, s1, a);
        ll n2 = f(m, s2, a);
        ll n3 = f(m, s3, a);
        if (check) {
            continue;
        }
        if (n1 + n2 == n3) {
            COUT(n1)
            COUT(n2)
            COUT(n3)
            finish = true;
            break;
        }
    } while(next_permutation(a.begin(), a.end()));
    if (!finish) {
        COUT("UNSOLVABLE")
    }
}

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

#define II pair<int, int>
#define III pair<II, int>
#define X first.first
#define Y first.second
#define Z second
#define all(a) (a).begin(), (a).end()
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)

int const oo = 1000000007, e5 = 100007, e6 = 1000007;
int N, M;
vector<int> edges[2005];
bool visited[2005];
int res = 0;

int __init__() {
    return 0;
}

void print01(int val, int showNums = 20) {
    char answer[showNums];
    for0(i, showNums) {
        answer[showNums - 1 - i] = val % 2 + '0';
        val /= 2;
    }
    cout << answer;
}

void DFS(int node) {
    if (visited[node]) return;
    ++res;
    visited[node] = 1;
    for0(i, edges[node].size()) {
        DFS(edges[node][i]);
    }
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);__init__();
    // freopen("test.txt", "r", stdin);
    int a, b;
    cin >> N >> M;
    for0(i, M) {
        cin >> a >> b;
        edges[a].push_back(b);
    }
    for1(i, N) {
        for1(i, N) visited[i] = 0;
        DFS(i);
    }
    cout << res;
}


#include<bits/stdc++.h>
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define INF 10000000000000001
#define F first
#define S second
#define LB lower_bound
#define UB upper_bound
#define vc vector
#define vll vector<long long>
#define pll pair<long long,long long>
#define pb push_back
#define all(v) v.begin(),v.end()
#define T ll test;cin>>test; while(test--)
#define forn(i,a,n) for(ll i=a;i<(long long)n;++i)
#define backn(i,n,a) for(ll i=n;i>(long long)a;--i)
#define MAX 200005
#define sz(x) (ll)x.size()
#define ins insert
#define mp make_pair
#define lld long long int
#define cy cout<<"Yes\n";
#define cno cout<<"No\n";
typedef  long long ll;
typedef long double ld;
using namespace std;

signed main()
{
  	FASTIO
  	int a,b,c;
  	cin >> a >> b >> c;
  	int x=2*a;
  	int y=2*b;
  	int z=2*c;
  	if(x==b+c)
  	{
  		cout << "Yes"<< endl;
  		return 0;
	}
	else if(y==a+c)
  	{
  		cout << "Yes"<< endl;
  		return 0;
	}
	else if(z==a+b)
  	{
  		cout << "Yes"<< endl;
  		return 0;
	}
	else
	{
		cout << "No" << endl;
	}
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
constexpr ll MOD = 1e9 + 7;
//constexpr ll MOD = 998244353;
//constexpr ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
constexpr ll INF = 1LL << 60;
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;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)

int main()
{
  ll N = 3;
  vector<ll> A(N);
  for (ll i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());

  cout << ((A.at(2) - A.at(1) == A.at(1) - A.at(0)) ? "Yes" : "No") << endl;
}


#include <bits/stdc++.h>
// #include <atcoder/all>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
// using namespace atcoder;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("->");}else{puts("<-");}
#define MAX_N 205

struct edge{
    int to, id, dir;
};

vector<edge> G[MAX_N];
int ans[100000];
int c[1000];

void dfs(int x){
    rep(i,G[x].size()){
        edge e = G[x][i];
        int y = e.to;
        int id = e.id;
        int dir = e.dir;
        if(ans[id] != 0) continue;
        if(c[y] < c[x]){
            ans[id] = dir;
            continue;
        }
        ans[id] = dir;
        dfs(y);
    }
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a, b;
    rep(i,m){
        int aa, bb;
        cin >> aa >> bb;
        aa--; bb--;
        edge e;
        e.to = bb;
        e.id = i;
        e.dir = 1;
        G[aa].push_back(e);
        e.to = aa;
        e.dir = 2;
        G[bb].push_back(e);
        a.push_back(aa);
        b.push_back(bb);
    }

    rep(i,n) cin >> c[i];

    if(m == 0){
        return 0;
    }

    vector<P> v;
    rep(i,n){
        v.push_back(P(c[i],i));
    }
    sort(v.begin(), v.end(), greater<P>());

    rep(i,v.size()){
        int x = v[i].second;
        dfs(x);
    }

    rep(i,m){
        if(ans[i] == 1) yn;
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
void fast() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
}
void ran() {
	srand(chrono::steady_clock::now().time_since_epoch().count());
}
long long get_rand() {
	long long a = rand();
	long long b = rand();
	return a * (RAND_MAX + 1ll) + b;
}
void usaco() {
	freopen("problem.in", "r", stdin);
	freopen("problem.out", "w", stdout);
}
template<typename T>
using min_pq = priority_queue<T, vector<T>, greater<T>>;
// #define endl '\n'
// #define double long double
// #define int long long
// const int MOD = 1000 * 1000 * 1000 + 7;
// const int MOD = 998244353;

int n, m;
const int MXN = 105, MXM = 10005;
vector<pair<int, int>> ed;
int reach[MXN];
int dir[MXM];
vector<pair<int, int>> adj[MXN], nadj[MXN];

vector<int> act;
int state[MXN];

map<pair<int, int>, int> enm;

bool stop = false;

void dfs(int node, int par) {
	if (stop) return;
	if (state[node] == 1) {
		// on stack
		bool consid = false;
		vector<int> actr;
		for (int i=0; i<act.size(); i++) {
			if (act[i] == node) {
				consid = !consid;
			}
			if (consid) {
				actr.push_back(act[i]);
			}
		}
		// cout << "cyc" << endl;
		for (int i=0; i<actr.size(); i++) {
			// cout << actr[i] << ' ';
			int a = actr[i], b = actr[(i+1)%actr.size()];
			int x = enm[{a, b}];
			if (ed[x].first == a) {
				dir[x] = 1;
			}
			else {
				dir[x] = -1;
			}
		}
		stop = true;
		// cout << endl;
		return;
	}
	state[node] = 1;
	act.push_back(node);
	for (auto x: adj[node]) {
		if (stop) return;
		int ot = x.first;
		if (ot == par) continue;
		if (dir[x.second] != 0) continue;
		dfs(ot, node);
	}
	state[node] = 0;
	act.pop_back();
}

void cycle(int x) {
	while (true) {
		for (int i=0; i<MXN; i++) state[i] = 0;
		act.clear();
		stop = false;
		dfs(x, -1);
		if (!stop) return;
	}
}

void dfsn(int node, int par) {
	for (auto x: nadj[node]) {
		int ot = x.first;
		if (ot == par) continue;
		int num = x.second;
		if (ed[num].first == node) {
			dir[num] = 1;
		}
		else {
			dir[num] = -1;
		}
		dfsn(ot, node);
	}
}

signed main() {

	ran(); fast();

	cin >> n >> m;
	for (int i=0; i<m; i++) {
		int a, b;
		cin >> a >> b;
		ed.push_back({a, b});
		enm[ed.back()] = i;
		enm[{b, a}] = i;
	}
	for (int i=1; i<=n; i++) {
		cin >> reach[i];
	}

	for (int i=0; i<m; i++) {
		int a = ed[i].first, b = ed[i].second;
		if (reach[a] == reach[b]) {
			adj[a].push_back({b, i});
			adj[b].push_back({a, i});
		}
		else {
			if (reach[a] > reach[b]) dir[i] = 1;
			else dir[i] = -1;
		}
	}

	for (int i=1; i<=n; i++) {
		if (adj[i].size()) {
			cycle(i);
		}
	}

	for (int i=1; i<=n; i++) {
		for (auto x: adj[i]) {
			if (dir[x.second] == 0) {
				nadj[i].push_back(x);
				// cout << i << ' ' << x.first << ' ' << x.second << endl;
			}
		}
	}

	for (int i=1; i<=n; i++) {
		if (nadj[i].size() == 1) {
			dfsn(i, -1);
		}
	}

	for (int i=0; i<m; i++) {
		if (dir[i] == 1) cout << "->" << endl;
		else if (dir[i] == -1) cout << "<-" << endl;
		else assert(false);
	}

}


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

#define ll long long
#define deb(x) cerr << #x << ":" << x << "\n"
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pi;

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define int ll

void solve()
{
    ll n;
    cin>>n;
    int p=1,ans=INT64_MAX;
    for(int b=0;b<64 && p<=n;b++){
        int c=n%p;
        int a=n/p;
        ans=min(ans,a+b+c);
        p*=2;
    }
    cout<<ans<<"\n";
}

int32_t main()
{
#ifndef ONLINE_JUDGE
    freopen("../text_files/input.txt", "r", stdin);
    freopen("../text_files/output.txt", "w", stdout);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	if(n%100==0)
	{
		cout<<n/100;
		return 0;
	}
	cout<<n/100+1;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fi first
#define se second
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep0(i, n) for (ll i = 0; i <= (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep1(i, n) for (ll i = (n); i > 0; --i)
#define rrep0(i, n) for (ll i = (n); i >= 0; --i)
#define srep(i, s, t) for (ll i = s; i < t; ++i)
#define srep1(i, s, t) for (ll i = s; i <= t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define snuke srand((unsigned)clock() + (unsigned)time(NULL));
#define show(x) cerr << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
constexpr ll MAX = 200002;

int main()
{
    ll n, w;
    vl table(MAX + 1, 0);
    cin >> n >> w;
    rep1(i, n)
    {
        ll s, t, p;
        cin >> s >> t >> p;
        table[s] += p;
        table[t] -= p;
    }
    rep1(i, MAX)
    {
        table[i] += table[i - 1];
        if (table[i] > w || table[i - 1] > w)
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"
#define pi 3.1415926535897932384626433832795028841971693993751058
#define maxn 100005

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define pq priority_queue
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
#define ceil(a,b) (a+b-1)/b

using namespace std;

int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

//START OF CODE ->->->->->->->

void solve()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    int q;
    cin>>q;
    int cnt = 0;
    rep(i,0,q){
        int ch;
        cin>>ch;
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        if ( ch == 1 ){
            if ( cnt & 1 ){
                a = (a<n)?a+n:a-n;
                b = (b<n)?b+n:b-n;
                swap(s[a],s[b]);
            }
            else{
                swap(s[a],s[b]);
            }
        }
        else{
            cnt++;
        }
    }

    if ( cnt & 1 ){
        string ans = "";
        rep(i,n,s.length()){
            ans += s[i];
        }
        rep(i,0,n){
            ans += s[i];
        }

        cout<<ans<<endl;
    }
    else{
        cout<<s<<endl;
    }
}

//END OF CODE ->->->->->->->->

signed main()
{
    fast;
    int t = 1;
    // cin>>t;
    for ( int i = 1 ; i <= t ; i++ ){
        // cout<<"Case #"<<i<<": ";
        solve();
    }
    return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
#define pr pair<int,int>
#define vect vector <int> v1
#define pb push_back
#define sortv sort(v1.begin(),v1.end());
#define loop(i,a,b)  for(int i=(a);i<(b);i++)
#define inputarr loop(i,0,n) cin>>ar[i];
const int mod=1e9+7;
int calpowof2(int a, int b)
{
    if(b==0)
    return 1;
    if(b%2==0)
    {
        int ans=calpowof2(a,b/2);
        return (ans%mod*ans%mod)%mod;
    }

        int ans=calpowof2(a,b-1);
        return (a%mod*ans%mod)%mod;
}
void solve()
{
  int i,j,n,t,m,k,ct=0,sum=0,flag=0;
   cin>>n;
   set<int> s;
   s.insert(0);
   loop(i,0,n)
   {
       cin>>j;
       s.insert(j);
   }
   sum=1;
   for(auto it=s.begin();it!=s.end();it++)
   {
       ct++;
       if(ct==s.size())
       {
           break;
       }
       auto it1=next(it,1);
       sum=sum*((*it1-*it+1)%mod)%mod;
   }
   cout<<sum;
}
signed main()
{
//freopen("lineup.in","r",stdin);
//freopen("lineup.out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(NULL);
// WATCH FOR SAME VARIABLE USAGE CLEARLY!!!
// AFTER WA VERDICT CHECK FIRSTLY YOUR WHOLE CODE AND THEN MOVE ON TO LOGIC ERROR
//MAKE SURE TO MAKE A DUPLICATE OF ANYTHING IF PERFORMING OPERATION DIRECTLY ON SOMETHING !!!
int t=1;
//cin>>t;
while(t--)
{
  solve();
}

cerr<< endl << clock() * 1000.0 / CLOCKS_PER_SEC <<'m'<<'s';
    return 0;
}

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

int main(){
    int N;
    cin>>N;
    vector<ll> A(N);
    for(int i=0;i<N;i++) cin>>A[i];
    sort(A.begin(),A.end());
    ll ans=A[0]+1;
    map<ll,bool> seen;
    seen[A[0]]=true;
    for(int i=1;i<N;i++){
        if(seen[A[i]]) continue;
        ans*=(A[i]-A[i-1]+1);
        ans%=mod;
        seen[A[i]]=true;
    }
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define F first
#define S second
#define YES(n)cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define _GLIBCXX_DEBUG
const ll INF = 1e12;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b)cout<<c<<endl;
    else if(a==c)cout<<b<<endl;
    else if(b==c)cout<<a<<endl;
    else cout<<0<<endl;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

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

#define rep(i, f, t) for (int i = (f), ed##i = (t); i <= ed##i; ++i)
#define re(i, t) rep (i, 1, t)
#define per(i, t, f) for (int i = (t), ed##i = (f); i >= ed##i; --i)
#define ste(i, f, t, s) for (int i = (f), ed##i = (t); i <= ed##i; i += s)
#define each(i, x) for (auto &i : (x))
#define nx(i, f) for (int i = h[f]; i; i = e[i].n)
#define nxt(i, f, g) for (int i = g.h[f]; i; i = g.e[i].n)
#define dbg(x) (cerr << "(dbg) " << #x " = " << (x) << '\n')
#define fio(x) (freopen(x ".in", "r", stdin), freopen(x ".out", "w", stdout))
#define y1 y1__
#define umod(x) ((x) >= mo && ((x) -= mo))
#define outl(x) (cout << (x) << '\n')
#define outs(x) (cout << (x) << ' ')
#define errl(x) (cerr << (x) << '\n')
#define errs(x) (cerr << (x) << ' ')

// clang-format off
template<class T>T jdz(const T&a){return a>0?a:-a;}
template<class T,class E>void up(T&a,const E&b){a<b&&(a=b);}
template<class T,class E>void down(T&a,const E&b){b<a&&(a=b);}
template<class T,size_t E>void fill(T(&a)[E],const int&x){memset(a,x,E*sizeof(*a));}
ll pow(ll a,ll b,const ll&m){ll res=1;a%=m;while(b>0){if(b&1)res=res*a%m;a=a*a%m,b>>=1;}return res;}
ll gcd(ll a,ll b){ll t;while(b!=0)t=a%b,a=b,b=t;return a;}
ll C(ll n,ll m){if(m>n)return 0;ll a=1;re(i,m)a*=(n-i+1),a/=i;return a;}
ll C(ll n,ll m,ll p){if(m>n)return 0;ll x=1;re(i,m){ll a=(n+i-m)%p,b=i%p;x=x*(a*pow(b,p-2,p)%p)%p;}return x;}
// clang-format on

signed main() {
	int a[10];
	re(i,3)cin>>a[i];
	sort(a+1,a+3+1);
	if(a[1]==a[2])cout<<a[3];
	else if(a[2]==a[3])cout<<a[1];
	else cout<<0;
	return 0;
}


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

struct UnionFind {
  vector<int> par;
  vector<map<int, int>> mp;
  UnionFind(int n=0): par(n,-1), mp(n) {}
  int find(int x) {
    if(par[x] < 0) return x;
    return par[x] = find(par[x]);
  }
  bool unite(int x, int y){
    x = find(x); y = find(y);
    if(x==y) return false;
    if(par[x] > par[y]) swap(x,y);
    // x > y
    for(auto p : mp[y]) {
      mp[x][p.first] += p.second;
    }
    mp[y] = map<int,int>();
    par[x] += par[y];
    par[y] = x;
    return true;
  }
  bool same(int x, int y) {return find(x) == find(y);}
  int size(int x) {return -par[find(x)];}
};

int main() {
  int n ,q;
  cin >> n >> q;
  UnionFind t(n);
  rep(i,n) {
    int c;
    cin >> c;
    t.mp[i][c] = 1;
  }

  rep(i,q){
    int type, a,b,x, y;
    cin >> type ;
    if(type==1){
      cin >> a >> b;
      --a; --b;
      t.unite(a,b);
    }else{
      cin >> x >> y;
      --x;
      x = t.find(x);
      int ans = t.mp[x][y];
      cout << ans << endl;
    }
  }
  return 0;
}

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

struct UnionFind{
  vector<int> r;
  vector<unordered_map<int,int>> mp;
  UnionFind(int n,vector<int> c){
    r=vector<int>(n,-1);
    mp.resize(n);
    for(int i=0; i<n; ++i) mp[i][c[i]]=1;
  }
  int root(int x){
    return (r[x]<0? x:r[x]=root(r[x]));
  }
  void unite(int x,int y){
    x=root(x);
    y=root(y);
    if(x==y) return;
    if(r[x]>r[y]) swap(x,y);
    r[x]+=r[y];
    for(auto [key,i]:mp[y]) mp[x][key]+=i;
    r[y]=x;
    return;
  }
  int size(int key,int y){
    return mp[root(key)][y];
  }
};

int main(void){
  int n,q; cin>>n>>q;
  vector<int> c(n);
  for(auto& i:c){ cin>>i; --i;}
  UnionFind UF(n,c);
  while(q--){
    int a,b,c; cin>>a>>b>>c; --b,--c;
    if(a==1) UF.unite(b,c);
    else cout<<UF.size(b,c)<<endl;
  }
  return 0;
}


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

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define fin(a) { cout << a << endl; return 0; }
#define debug(a) { cerr << #a << ": " << a << endl; }
#define endl '\n'
#define fi first
#define se second
using lint = long long;
using ld = long double;
using P = pair<int,int>;
using Pl = pair<lint,lint>;
template<class T> using V = vector<T>;
template<class T> using priq     = priority_queue<T>;
template<class T> using priq_inv = priority_queue<T, vector<T>, greater<T>>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
template<class T> T ceil(const T &a, const T &b) { return ((a)+(b)-1)/b; }
template<class T> bool chmin(T &a, T b) { if(a > b) { a = b; return 1; } return 0; }
template<class T> bool chmax(T &a, T b) { if(a < b) { a = b; return 1; } return 0; }
template<class T> void YesorNo(T x) { printf(x ? "Yes\n" : "No\n"); }
struct INF { template<class T> operator T() { return numeric_limits<T>::max() / 2; } } INF;

template<class T, class U> istream& operator>>(istream &in, pair<T,U> &p) {
    return in >> p.first >> p.second;
}
template<class T, class U> ostream& operator<<(ostream &out, const pair<T,U> &p) {
    return out << '{' << p.first << ',' << p.second << '}';
}
template<class T> istream& operator>>(istream &in, vector<T> &v) {
    for(auto &&e : v) in >> e;
    return in;
}
template<class T> ostream& operator<<(ostream &out, const vector<T> &v) {
    for(const auto &e : v) out << e << ' ';
    return out;
}

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

struct UnionFind { // UnionFindTree

    vector<int> d;
    int group;
    UnionFind(int n): d(n,-1), group(n) {}

    int find(int x) {
        if(d[x] < 0) return x;
        return d[x] = find(d[x]);
    }

    bool unite(int x, int y) {
        x = find(x);
        y = find(y);
        if(x == y) return false;
        if(-d[x] < -d[y]) swap(x,y);
        group--;
        d[x] += d[y];
        d[y] = x;
        return true;
    }

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

long long Modpow(long long a, int n, long long mod){
    if(n == 0) return 1;
    if(n%2 == 0){
      long long res = Modpow(a, n/2, mod);
      return res * res % mod;
    }
    return a * Modpow(a, n-1, mod) % mod;
}

int main(){
    int n;
    cin >> n;
    UnionFind uf(n);
    rep(i,n) {
        int a;
        cin >> a;
        a--;
        uf.unite(i,a);
    }
    cout << Modpow(2,uf.group,998244353)-1 << endl;
}

#include<bits/stdc++.h>
#define re register int
#define ll long long
#define dl long double
#define LL ll
#define V inline void
#define I inline int
#define FOR(i,a,b) for(re i=(a),i##i=(b);i<=i##i;++i)
#define ROF(i,a,b) for(re i=(a),i##i=(b);i>=i##i;--i)
#define gc getchar()
//#define gc (fs==ft&&(ft=(fs=buf)+fread(buf,1,1<<18,stdin),fs==ft))?0:*fs++
using namespace std;
char *fs,*ft,buf[1<<18];
const int N=3e5+10,mo=998244353,G=3;
LL read(){
	ll p=0; bool w=0; char ch=gc;
	while(!isdigit(ch)) w=ch=='-',ch=gc;
	while(isdigit(ch)) p=p*10+ch-'0',ch=gc;
	return w?-p:p;
}
int n,f[N],vis[N],as;
ll ans;
LL Pow(ll x,ll y){ ll as=1; for(;y;y>>=1,x=x*x%mo) if(y&1) as=as*x%mo; return as;}
V dfs(int u){
	if(vis[u]) return ;
	vis[u]=1;
	dfs(f[u]);
}
int low[N],dfn[N],now,cnt,id,s[N],bk[N],scc[N],siz[N];
V tarjan(int u){
	s[++cnt]=u;
	low[u]=dfn[u]=++now;
	bk[u]=1;
	int v=f[u];
	if(!low[v]) tarjan(v),low[u]=min(low[u],low[v]);
	else if(bk[v]) low[u]=min(low[u],dfn[v]);
	if(low[u]==dfn[u]){
		scc[u]=++id,siz[id]=1;
		bk[u]=0;
		while(s[cnt]!=u){
			v=s[cnt];
			scc[v]=id,++siz[id];
			bk[v]=0;
			--cnt;
		}--cnt;
	}

}
V sol(){
	FOR(i,1,n) if(!dfn[i]) tarjan(i);
	FOR(i,1,id) if(siz[i]>1) ++as;
	FOR(i,1,n) if(f[i]==i) ++as;
	ans=Pow(2,as)-1;
	cout<<ans;
	return ;
}
int main(){
	n=read();
	FOR(i,1,n) f[i]=read();
	sol();

	return 0;
}


#include <iostream>
using namespace std;

int main(){
	int N;
	cin >> N;
	cout << N-1;
}

#include<bits/stdc++.h>
using namespace std;
using P=pair<int,int>;
using ll=long long;
template<class T> using heapq = priority_queue<T,vector<T>,greater<T>>;
template<class T> bool chmax(T &a,const T b) {if (a<b) {a=b;return true;} else return false;}
template<class T> bool chmin(T &a,const T b) {if (a>b) {a=b;return true;} else return false;}
#define rep(i,n) for(int i=0; i<(n); i++)
#define srep(i,a,b) for(int i=(a); i<(b); i++)
#define rrep(i,n) for(int i=(n)-1;i>=0; i--)
#define srrep(i,a,b) for(int i=(b)-1; i>=(a); i--)
int main(){
    int n; cin >> n;
    cout << n-1 << endl;
}


#pragma GCC optimize ("Ofast,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")

#include <bits/stdc++.h>

using namespace std;

constexpr int M = 998244353;

#define fastio ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define int long long
#define pii pair<int, int>
#define fi first
#define se second
#define SZ(x) ((int)(x.size()))

#ifdef int
#define INF 0x3f3f3f3f3f3f3f3f
#define INF2 (int)(0xcfcfcfcfcfcfcfcf)
#else
#define INF 0x3f3f3f3f
#define INF2 0xcfcfcfcf
#endif

signed main() {
    fastio
    int n;
    cin >> n;
    map<int, int> cnt;
    int sum = 0;
    cnt[0]++;
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        if (i & 1) sum -= x;
        else sum += x;
        if (cnt.count(sum)) ans += cnt[sum];
        cnt[sum]++;
    }
    cout << ans << "\n";
    return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<(a)<<endl
#define dumparr(a,n) cerr<<#a<<"["<<(n)<<"]="<<(a[n])<<endl
#else
#define dump(a)
#define dumparr(a,n)
#endif
#define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

pll operator+(pll a,pll b){
  return pll(a.first+b.first,a.second+b.second);
}
pll operator-(pll a,pll b){
  return pll(a.first-b.first,a.second-b.second);
}
pll operator*(ll a,pll b){
  return pll(b.first*a,b.second*a);
}
const ll INF=(1LL<<60);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  a=abs(a);
  b=abs(b);
  if(a==0)return b;
  if(b==0)return a;
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif
template<class T>
bool chmax(T& a,const T& b){
  if(a<b){
    a=b;
    return true;
  }
  return false;
}
template<class T>
bool chmin(T& a,const T& b){
  if(a>b){
    a=b;
    return true;
  }
  return false;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< "]";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,set<T> a){
  os << "{ ";
  for(auto itr=a.begin();itr!=a.end();++itr){
    os<< *itr << " ";
  }
  os<< "}";
  return os;
}
template<class T>
void ans_array(T begin,T end){
  auto itr=begin;
  cout<<*itr;
  ++itr;
  for(;itr!=end;++itr){
    cout<<' '<<*itr;
  }
  cout<<endl;
}
template<class T>
void ans_array_newline(T begin,T end){
  for(auto itr=begin;itr!=end;++itr){
    cout<<*itr<<endl;
  }
}

void solve(long long N, std::vector<long long> A){
  REP(N){
    if(i%2){
      A[i]=-A[i];
    }
  }
  vector<ll> sumA(N+1);
  REP(N){
    sumA[i+1]=sumA[i]+A[i];
  }
  map<ll,ll> mp;
  REP(N+1){
    mp[sumA[i]]++;
  }
  ll ans=0;
  for (auto &&i : mp)
  {
    ans+=i.second*(i.second-1)/2;
  }
  cout<<ans<<endl;
}

int main(){
  cout<<setprecision(1000);
  long long N;
    scanf("%lld", &N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld", &A[i]);
    }
  solve(N, std::move(A));
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (ll i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using ld=long double;
using vin=vector<int>;
using vvin=vector<vin>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vst=vector<string>;
using P = pair<ll,ll>;
using vp=vector<P>;
using vvp=vector<vp>;
const int inf=1e9+7;
const ll INF=9e18/2;
const long double PI = acos(-1.0);
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

vvin g;
int cnt[1000000];
int ans=0;

int N=660000;

void dfs2(int);
void dfs(int);

void dfs2 (int now){
  for(auto v:g[now])cnt[v]--;
  for(auto v:g[now])if(cnt[v]==1)dfs(v);
}

void dfs(int now){
  for(auto v:g[now]){
    if(cnt[v])continue;
    cnt[v]=1;
    ans++;
    dfs2(v);
  }
}
int main(){//cout<<fixed<<setprecision(20);
  int n;
  cin>>n;
  g.resize(N);
  rep(i,0,n){
    int a,b;
    cin>>a>>b;
    g[i].pb(a+n);
    g[i].pb(b+n);
    g[a+n].pb(i);
    g[b+n].pb(i);
    cnt[a+n]++;
    cnt[b+n]++;
  }
  rep(i,n+1,N)if(cnt[i]==1)dfs(i);
  rep(i,n+1,N)if(cnt[i])ans++;
  cout<<ans<<endl;
}

#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#include<bitset>
#include<functional>
#include <fstream>
//#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i, x) for(ll i = 0; i < x; i++)
#define rep2(i, x) for(ll i = 1; i <= x; i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 10000000000000000;
const int intINF = 1000000000;
const ll mod = 1000000007;
const ll MOD = 998244353;
const ld pi = 3.141592653589793238;

bool isprime(int p) {
	if (p == 1) return false;
	for (int i = 2; i < p; i++) {
		if (p % i == 0) return false;
	}
	return true;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll keta(ll n) {
	ll res = 0;
	while (n >= 1) {
		res += n % 10; n /= 10;
	}
	return res;
}
ll modpow(ll x, ll y) {
	ll res = 1;
	while (y) {
		if (y % 2) { res *= x; res %= mod; }
		x = x * x % mod; y /= 2;
	}
	return res;
}
ll nCk(ll n, ll k) {
	ll a = 1, b = 1;
	for (int h = n - k + 1; h <= n; h++) { a *= h; a %= mod; }
	for (int h = 1; h <= k; h++) { b *= h; b %= mod; }
	return a * modpow(b, mod - 2) % mod;
}
//printf("%.10f\n", n);
typedef pair <ll, ll> P;
ll dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
struct edge { ll to, cost; };
struct status {
	ll y;
	ll high;
	ll cost;

	bool operator<(const status& rhs) const { return cost < rhs.cost; };
	bool operator>(const status& rhs) const { return cost > rhs.cost; };
};

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

	//input
	ll n;
	cin >> n;
	vector<ll> a(n), b(n), maa(n);
	rep(i, n) { cin >> a[i]; }
	rep(i, n) { cin >> b[i]; }
	rep(i, n) {
		if (i == 0) { maa[i] = a[i]; continue; }
		else { maa[i] = max(maa[i - 1], a[i]); }
	}
	ll ma = 0;
	rep(i, n) {
		ma = max(ma, maa[i] * b[i]);
		cout << ma << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define FI(n) FastIO::read(n)
#define FO(n) FastIO::write(n)
#define ull unsigned long long
#define mst(a,b) memset(a,b,sizeof(a))
#define foR(i,k,j) for(int i=(k);i>=(j);i--)
#define For(i,k,j) for(int i=(k);i<=(j);i++)
#define Foe(i,u) for(int i=lst[u],v=e[i].v;i;i=e[i].nxt,v=e[i].v)
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define Fin(s) freopen(s,"r",stdin)
#define Fout(s) freopen(s,"w",stdout)
#define file(s) Fin(s".in"),Fout(s".out")
#define INF ((1<<30)-1)
//#define int long long
const int P=3; //
using namespace std;
template<typename T>inline void ckmax(T &a,T b) {(a<b)&&(a=b);}
template<typename T>inline void ckmin(T &a,T b) {(a>b)&&(a=b);}
inline int mul(int a,int b) {return 1ull*a*b%P;}
inline int add(int a,int b) {return a+b>=P?a+b-P:a+b;}
inline int sub(int a,int b) {return a-b>=0?a-b:a-b+P;}
inline void mulmod(int &a,int b) {a=mul(a, b);}
inline void addmod(int &a,int b) {((a+=b)>=P)&&(a-=P);}
inline void submod(int &a,int b) {((a-=b)<0)&&(a+=P);}
inline int ksm(int a,int b) {int ans=1; for(;b;b>>=1) {if(b&1) ans=1ll*ans*a%P;a=1ll*a*a%P;}return ans;}
inline void fprint(const int &x,char c=' ') {fprintf(stderr,"%d%c",x,c);}
inline void fprint(const pii &x,char c='\n') {fprintf(stderr,"%d %d%c",x.first,x.second,c);}
inline void fprint(const int *f,const int &n,char c='\n') {for(int i=1;i<=n;i++) fprint(f[i]); fprintf(stderr,"%c",c);}
inline void fprint(const vector<int> &f,char c='\n') {for(int i=0;i<(int)f.size();i++) fprint(f[i]); fprintf(stderr,"%c",c);}
inline int inv(int a) {return ksm(a,P-2);}
namespace FastIO {
  const int SIZE=1<<16; char buf[SIZE],obuf[SIZE],str[64]; int bi=SIZE,bn=SIZE,opt;
  int read(char *s) {
    while (bn) {for (;bi<bn&&buf[bi]<=' ';bi++);if (bi<bn) break; bn=fread(buf,1,SIZE,stdin),bi=0;}
    int sn=0;while (bn) {for (;bi<bn&&buf[bi]>' ';bi++) s[sn++]=buf[bi];if (bi<bn) break; bn=fread(buf,1,SIZE,stdin),bi=0;}s[sn]=0;return sn;
  }
  bool read(int& x) {if(x)x=0;int bf=0,n=read(str); if(!n) return 0; int i=0; if (str[i]=='-') bf=1,i=1; for(x=0;i<n;i++) x=x*10+str[i]-'0'; if(bf) x=-x; return 1;}
  void write(int x) {
    if(!x) obuf[opt++]='0'; else {if(x<0) obuf[opt++]='-',x=-x;int sn=0; while(x)str[sn++]=x%10+'0',x/=10;for (int i=sn-1;i>=0;i--) obuf[opt++]=str[i];}
    if (opt>=(SIZE>>1)){fwrite(obuf,1,opt,stdout); opt=0;}
  }
  void write(char x) {obuf[opt++]=x;if (opt>=(SIZE>>1)){fwrite(obuf,1,opt,stdout); opt=0;}}
	void Fflush() {if (opt) fwrite(obuf,1,opt,stdout); opt=0;}
};
inline int read() {int x; FI(x); return x;}
const int MN=2e5+5;
int a[MN],n,dep[MN],rt,vrt,f[MN],ban[MN],X,Y;
vi e[MN];
void dfs1(int u,int fa) {
	dep[u]=dep[fa]+1,f[u]=fa;
	if(dep[u]>vrt) vrt=dep[u],rt=u;
	for(auto v:e[u]) {
		if(v==fa) continue;
		dfs1(v,u);
	}
}
int now=1,ans[MN];
void dfs2(int u,int fa) {
	int bv=0; ans[u]=now;
//	cerr<<u<<endl;
	for(auto v:e[u]) {
		if(v!=fa&&ban[v]) bv=v;
		if(v==fa||ban[v]) continue;
		now++; dfs2(v,u); now++;
	}
	if(bv) now++,dfs2(bv,u),now++;
}
signed main() {
	#ifndef ONLINE_JUDGE
		freopen("pro.in","r",stdin);
		freopen("pro.out","w",stdout);
	#endif
	n=read();
	For(i,1,n-1) {
		int u=read(),v=read();
		e[u].pb(v),e[v].pb(u);
	}
	dfs1(1,0); X=rt; rt=0,vrt=0; dfs1(X,0); Y=rt;
//	cerr<<X<<' '<<Y<<endl;
	int t=Y; do {
		ban[t]=1; t=f[t];
	} while(t);
	dfs2(X,0);
	For(i,1,n) {
		printf("%d ",ans[i]);
	}
	printf("\n");
	return FastIO::Fflush(),0;
}
/*

*/

#include <iostream>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <tuple>
using namespace std;

void yes(){ cout << "yes" << endl; }
void Yes(){ cout << "Yes" << endl; }
void YES(){ cout << "YES" << endl; }
void no(){ cout << "no" << endl; }
void No(){ cout << "No" << endl; }
void NO(){ cout << "NO" << endl; }
#define rep(i, n)for(int i=0; i<n; i++)
#define ll long long

ll inf = 1000000007;
ll INF = 1000000000000000007;

int main(){
  ll N; string S;
  cin >> N >> S;
  //

  // fofoxxfofox
  stack<char> s;
  rep(i, N){
    // xでなければスタックに突っ込む
    if(S[i] != 'x'){
      s.push(S[i]);
    }
    // xならばfoxを取り除けるかも
    else{
      if(s.empty()){
	s.push('x');
      }
      // oxを発見
      else if(s.top() == 'o'){
	s.pop();
	// foxを発見
	if(s.top() == 'f'){
	  s.pop();
	}
	// さっきpopしたoは間違いだった
	// xもpush
	else{
	  s.push('o');
	  s.push('x');
	}
      }
      // oxを含まないためxをpush
      else{
	s.push('x');
      }
    }
  }

  ll num = s.size();
  /* while(!s.empty()){
    cout << s.top();
    s.pop();
  }
  cout<<endl;*/

  // 解答
  cout << num << endl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef double dd;
#define tst int tttt;cin>>tttt;for(int TTTT=1;TTTT<=tttt;TTTT++)
#define nl cout<<"\n";
#define forn(a,b) for(int ii=a;ii<b;ii++)
const ll MOD1=1e9+7;
const ll MOD2=998244353;
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define vi vector<int>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define hhh cout<<"here"<<endl;

ll mod=MOD1;
ll po(ll x,ll y) {ll res=1;while(y>0){if(y&1)res=(res*x);x=(x*x);y>>=1;}return res;}
ll gcd(int a, int b){if(a<b) swap(a,b);if(b==0) return a;return gcd(a%b,b);}
int N=2e5+5;
void solve(){
    int n,w;cin>>n>>w;
    vector<ll> a(N);
    for(int i=0;i<n;i++){
        ll s,t,p;cin>>s>>t>>p;
        a[s]+=p;a[t]-=p;
    }ll s=0;
    for(int i=0;i<N;i++){
        s+=a[i];
        // cout<<s<<endl;
        if(s>w){
            cout<<"No";return;
        }
    }cout<<"Yes";
}
int main(){
    // fastio
    // ++*(int*)0;// crash
    // freopen("out.txt","r",stdin);freopen("outt.txt","w",stdout);
    // preprocess();
    // tst
    {
        solve();nl;
    }
}
/*

u & (v-u//2)

*/

//#include <tourist>
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
const int INF = 1e9;
const double eps = 1e-7;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
const long double pi = 4 * atan(1);
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//g++ yarudake.cpp -std=c++17 -I .
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,w;
    cin>>n>>w;
    vector<ll> sum(2*100000+2,0);
    ll s,t,p;
    rep(i,n){
        cin>>s>>t>>p;
        sum[s]+=p;
        sum[t]-=p;
    }
    rep(i,200001){
        sum[i+1]+=sum[i];
    }
    rep(i, 200000+2)
    {
        if(sum[i]>w){
            return no,0;
        }
    }
    yes;
}


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

using namespace std;

#define PB push_back
#define f first
#define s second
#define what_is(x) cerr << #x << " is " << x << endl;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

const int INF = 1000000007;
const ll MOD = 1000000007;

void solve_test()
{
    ll n;
    string t;
    cin >> n >> t;
    string s;
    char arr[] = {'1', '1', '0'};
    for(int i=0; i<=200005; i++)
    {
        s += arr[i%3];
    }
    const ll tot = 3*pow(10, 10);
    ll ans = 0;
    for(int i=0; i<3; i++)
    {
        if(s.substr(i, n) == t)
        {
            ans += 1 + (tot-i-n)/3;
        }
    }
    cout << ans;
}

signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int tests;
    tests = 1;
    //cin >> tests;
    while(tests--)
    {
        solve_test();
    }
    return 0;
}

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

int main(void){
    int N;
    string S;
    vector<string> V;
    ll ans, cnt;
    bool flg;

    cin >> N;
    cin >> S;
    ans = 10000000000;
    cnt = 0;
    flg = false;

    for (int i = 0; i < N; i++){
        if (S[i] == '0'){
            if (i >= 1 && S[i - 1] != '1'){
                flg = true;
                break;
            }
            else if (i >= 2 && S[i - 2] != '1'){
                flg = true;
                break;
            }
            cnt++;
        }

        if (N >= 3){
            if (S.substr(i, 3) == "111"){
                flg = true;
                break;
            }
        }
    }

    if (!flg){
        if (N == 1 && S[0] == '1'){
            ans *= 2;
        }
        else if (N == 2 && S[0] == '1' && S[1] == '1'){
            ans *= 1;
        }
        else{
            if (S[N - 1] == '0') ans = ans - cnt + 1;
            else ans = ans - cnt;
        }
    }
    else ans = 0;

    cout << ans << endl;

    return 0;
}


#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define int long long

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

    int n;
    cin >> n;
    vector<int> a(n);
    for (auto &t : a) {
        cin >> t;
    }
    int c = 0;
    int cmax = 0;
    int s = 0;
    for (int i = 0; i < n; i++) {
        c += s;
        s += a[i];
        cmax = max(cmax, a[i]);
        cout << (i + 1) * cmax + c + s << '\n';
    }
}

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
#define pb push_back
#define bp pop_back
#define int long long int
#define vt vector
#define pii pair<int,int>
#define pq priority_queue
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define lc lexicographical_compare
// #define endl '\n'

int inf = 1e18;
int mod = 1e9 + 7;
const int N = 2e5 + 5;
int spf[N];

void sieve() {
    for (int i = 1; i < N; i++) spf[i] = i;
    for (int i = 2; i * i < N; ++i) {
        if (spf[i] == i) {
            for (int j = i * i; j < N; j += i)
            {
                if (spf[j] == j)
                    spf[j] = i;
            }
        }
    }
}

int mpower(int x, unsigned int y) {
    int res = 1;
    x = x % mod;
    if (x == 0) return 0;
    while (y)
    {
        if (y & 1)
            res = (res * x) % mod;
        y = y >> 1;
        x = (x * x) % mod;
    }
    return res;
}
int gcdExtended(int a, int b, int *x, int *y);

int modInverse(int b, int m) {
    int x, y;
    int g = gcdExtended(b, m, &x, &y);
    if (g != 1)
        return -1;
    return (x % m + m) % m;
}

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

void solve();

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

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    // sieve();
    // int T;
    // cin >> T;
    // while (T--)
    solve();
    cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
    return 0;
}
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////

void solve() {
    int n;
    cin >> n;
    vt<int> a(n);
    map<int, int> m;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        m[a[i]] += 1;
    }
    vt<int> v;
    for (auto i : m)
        v.pb(i.ss);

    int sum = n, ans = 0;
    for (int i = 0; i < v.size(); i++) {
        // cout << v[i] << endl;
        sum -= v[i];
        ans += sum * v[i];
    }
    cout << ans << endl;

}


#include <cstdio>
#include <cctype>
#define rr register
using namespace std;
const int N=100011;
typedef long double ld;
int a[N],n;
inline signed iut(){
	rr int ans=0; rr char c=getchar();
	while (!isdigit(c)) c=getchar();
	while (isdigit(c)) ans=(ans<<3)+(ans<<1)+(c^48),c=getchar();
	return ans;
}
inline ld max(ld a,ld b){return a>b?a:b;}
inline ld calc(ld mid){
    rr ld sum=0;
	for (rr int i=1;i<=n;++i)
	    sum+=max(mid*2,a[i]);
	return sum-mid*n;
}
signed main(){
	n=iut();
	for (rr int i=1;i<=n;++i) a[i]=iut();
	rr ld l=0,r=1000000000;
	while (l+1e-8<r){
		rr ld k=(r-l)/3,lmid=l+k,rmid=r-k;
		if (calc(lmid)<calc(rmid)) r=rmid;
		    else l=lmid;
	}
	return !printf("%.8Lf",calc(l)/n);
}

/*
Author : Hocky Yudhiono
11/14/2020 11:34:48 PM

1. You can sort the query if offline!
2. Don't bring the dp remaining state when dfsing on DP on Tree.
3. Try to reverse (Think from the back) if you stuck.
4. Be careful when submitting Div. 2 D-F, dont waste it on stupid WAs.
5. Try to reduce a problem, think of it when you're making subtasks
   like when problemsetting.
*/

#include <algorithm>
#include <iostream>
#include <numeric>
#include <cstdlib>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <cstdio>
#include <limits>
#include <string>
#include <vector>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;

typedef long long LL;
typedef long long ll;
typedef long double LD;
typedef vector<int> vi;
typedef pair<LL,LL> PLL;
typedef pair<LL,int> PLI;
typedef pair<int,int> PII;
typedef pair<int,int> pii;
typedef vector<vector<LL>> VVL;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define popf pop_front
#define pf push_front
#define popb pop_back
#define mp make_pair
#define pb push_back
#define remove erase
#define fi first
#define se second

// If the time limit is strict, try not to use long double

// Remember to undefine if the problem is interactive
#define endl '\n'
#define DEBUG(X) cout << ">>> DEBUG(" << __LINE__ << ") " << #X << " = " << (X) << endl

const double EPS = 1e-9;
const int INFMEM = 63;
const int INF = 1061109567;
const LL LINF = 4557430888798830399LL;
const double DINF = numeric_limits<double>::infinity();
const LL MOD = 1000000007;
const int dx[8] = {0,0,1,-1,1,-1,1,-1};
const int dy[8] = {1,-1,0,0,1,-1,-1,1};
// Do dir^1 to get reverse direction
const char dch[4] = {'R','L','D','U'};
// const string ds[8] = {"E","W","S","N","SE","NW","SW","NE"};
const double PI = 3.141592653589793;

inline void open(string a){
    freopen((a+".in").c_str(),"r",stdin);
    freopen((a+".out").c_str(),"w",stdout);
}

inline void fasterios(){
    // Do not use if interactive
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // cout << fixed << setprecision(10);
}

LL n;
LL cnt[105];
bool isi[105][105];

int main(){
    cin >> n;
    for(int i = 1;i <= n;i++){
        for(int j = 1;j <= n;j++){
            char ch; cin >> ch;
            isi[i][j] = (ch == '1');
        }
    }
    for(int i = 1;i <= n;i++) isi[i][i] = 1;
    for(int k = 1;k <= n;k++){
        for(int i = 1;i <= n;i++){
            for(int j = 1;j <= n;j++){
                isi[i][j] |= (isi[i][k] && isi[k][j]);
            }
        }
    }
    LD ans = 0;
    for(int i = 1;i <= n;i++){
        for(int j = 1;j <= n;j++){
            if(isi[j][i]) cnt[i]++;
        }

        ans += ((LD)(1)/(LD)cnt[i]);
    }
    // for(int i = 1;i <= n;i++) cout << cnt[i] << endl;
    cout << fixed << setprecision(15) << ans << endl;
    return 0;
}