// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

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

#define int long long

unordered_map <int, int> dp, seen;
int x;

int go(int y) {
  if(x >= y) return abs(x-y);
  if(seen[y]) return dp[y];
  seen[y] = 1;
  int a = abs(x-y);
  if(y%2) {
    a = min(a, 2+go(y/2));
    a = min(a, 2+go((y+1)/2));
  } else {
    a = min(a, 1+go(y/2));
  }
  dp[y] = a;
  return dp[y];
}

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

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

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

   int t = 1; //cin >> t;
   for(int i = 1; i <= t; i++) {
     solve();
  }
}

/*

*/

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

using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
typedef vector<vector<bool> > vvb;

#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define rrep(i, n) for (int i = 1; i <= int(n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = int(n)-1; i >= 0; --i)

#define MES(a) MES2 a
#define MES2(a0,a1,a2,a3,a4,x,...) x
#define mes_1(x1) cout<<x1<<endl
#define mes_2(x1,x2) cout<<x1<<" "<<x2<<endl
#define mes_3(x1,x2,x3) cout<<x1<<" "<<x2<<" "<<x3<<endl
#define mes_4(x1,x2,x3,x4) cout<<x1<<" "<<x2<<" "<<x3<<" "<<x4<<endl
#define mes_5(x1,x2,x3,x4,x5) cout<<x1<<" "<<x2<<" "<<x3<<" "<<x4<<" "<<x5<<endl
#define mes(...) CHOOSE((__VA_ARGS__,mes_5,mes_4,mes_3,mes_2,mes_1,~))(__VA_ARGS__)

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)

#define ynmes(a) (a) ? mes("Yes") : mes("No")
#define YNmes(a) (a) ? mes("YES") : mes("NO")
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define Rev(a) reverse(a.begin(), a.end())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
struct io { io() { ios::sync_with_stdio(false); cin.tie(0); } };
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

ll modpow(ll x, ll y) {
    if(y == 1) {
        return x;
    }
    ll ans;
    if(y % 2 == 1) {
        ll r = modpow(x,(y-1)/2);
        ans = r * r % MOD;
        ans = ans * x % MOD;
    }
    else {
        ll r = modpow(x,y/2);
        ans = r * r % MOD;
    }
    return ans;
}

ll modncr(ll N, ll K) {
    ll res = 1;
    ll p=1;
    for (ll n = 0; n < K; ++n) {
      res = (res*(N - n))%MOD;
      p = (p*(n + 1))%MOD;
    }
    return (res*modpow(p,MOD-2))%MOD;
}

ll x, y;
map <ll, ll> memo;

ll rec(ll y) {
  	if (y == 1) return abs(x-y);
  	if (memo.find(y) != memo.end()) return memo[y];
  	if (y%2 == 0) {
    	memo[y] = min(rec(y/2)+1, abs(y-x));
  	} else {
    	memo[y] = min({rec(y+1)+1, rec(y-1)+1, abs(y-x)});
  	}
	return memo[y];
}

signed main() {
  	ll y;
  	cin >> x >> y;
  	mes(rec(y));

}


#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX
#define INFL LLONG_MAX
typedef long long ll;
using namespace std;

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

  string s;
  cin >> s;

  char dna;
  ll a=0,t=0,c=0,g=0,count=0;
  for(ll i=0;i<n-1;i++){

      a=0;
      t=0;
      c=0;
      g=0;

        for(ll k=i;k<n;k++){
          dna=s.at(k);
          if(dna=='A') a++;
          else if(dna=='T') t++;
          else if(dna=='C') c++;
          else if(dna=='G') g++;

          if(a==t && a!=0 && t!=0 && c==g) count++;
          else if(c==g && c!=0 && g!=0 && a==t) count++;
        }

  }

  cout << count << endl;
  return 0;

}

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

string a, b, c, p;
set<char> st;
char mp[26];

ll str_to_num(string s) {
	ll res = 0;
	for (char x : s) res = 10*res + mp[x-'a'];
	return res;
}

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

	cin>>a>>b>>c;

	for (char x : a) st.insert(x);
	for (char x : b) st.insert(x);
	for (char x : c) st.insert(x);

	if (st.size() > 10) {
		cout<<"UNSOLVABLE"<<endl;
		return 0;
	}

	int n = 0;
	for (char x : st) mp[x-'a'] = 'a' + n++;

	for (char &x : a) x = mp[x-'a'];
	for (char &x : b) x = mp[x-'a'];
	for (char &x : c) x = mp[x-'a'];

	p = "abcdefghij";
	do {
		if (p[0] == a[0] || p[0] == b[0] || p[0] == c[0]) {
			continue; // no leading zeros
		}

		n = 0;
		for (char x : p) mp[x-'a'] = n++;

		ll aa = str_to_num(a);
		ll bb = str_to_num(b);
		ll cc = str_to_num(c);

		if (aa + bb == cc) {
			cout<<aa<<endl<<bb<<endl<<cc<<endl;
			return 0;
		}
	} while (next_permutation(p.begin(), p.end()));

	cout<<"UNSOLVABLE"<<endl;
}


#include<iostream>
#include<vector>
#include<string>
#include<sstream>
#include<functional>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<vector<long long>> a(n, vector<long long>(n)),coma(n,vector<long long>(n)), comb(n, vector<long long>(n));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) cin >> a[i][j];
	}
	for (int i = 1; i < n; i++) {
		for (int j = 1; j < n; j++) {
			coma[i][j] = a[i][j] - a[i][j - 1] - (a[i - 1][j] - a[i - 1][j - 1]);
		}
	}
	for (int i = 1; i < n; i++) {
		for (int j = 1; j < n; j++) {
			comb[i][j] = a[i][j] - a[i - 1][j] - (a[i][j - 1] - a[i - 1][j - 1]);
		}
	}
	bool ans = true;
	for (int i = 1; i < n; i++) {
		for (int j = 1; j < n; j++) {
			if (comb[i][j] != 0 || coma[i][j] != 0) ans = false;
		}
	}
	if (!ans) cout << "No" << endl;
	else {
		vector<int> ansa(n), ansb(n), an(n), bn(n);;
		for (int i = 0; i < n; i++) ansa[i] = a[0][i];
		for (int i = 0; i < n; i++) ansb[i] = a[i][0];
		for (int i = 0; i < n; i++) an[i] = ansa[i];
		for (int i = 0; i < n; i++) bn[i] = ansb[i];
		sort(an.begin(), an.end());
		sort(bn.begin(), bn.end());
		int af = ansa[0] - an[0], bf = ansb[0] - bn[0];
		if (af + bf > ansa[0]) cout << "No" << endl;
		else {
			cout << "Yes" << endl;
			for (int i = 0; i < n; i++) {
				ansb[i] -= af;
				cout << ansb[i];
				if (i < n - 1) cout << " ";
				else cout << endl;
			}
            int k = ansa[0];
			for (int i = 0; i < n; i++) {
				ansa[i] -= k - af;
				cout << ansa[i];
				if (i < n - 1) cout << " ";
				else cout << endl;
			}
		}
	}
}

// template
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

struct Input
{
	int id;
    int x;
    int y;
    int r;
	int sx,sy,gx,gy;
};

bool compare_pos(Input a, Input b)
{
	if (a.x == b.x)
	{
		return a.y < b.y;
	}
	else
	{
		return a.x < b.x;
	}
}

bool compare_id(Input a, Input b)
{
	return a.id < b.id;
}

int main(void)
{
	int N;
	cin >> N;
    vector<Input> input(N);
	for (size_t i = 0; i < N; i++)
	{
		input[i].id = i;
		cin >> input[i].x >> input[i].y >> input[i].r;
	}

	// input[0]が一番左上
	sort(input.begin(), input.end(), compare_pos);

	int idx = 0;
	int left = 0;
	int top = 0;

	for (int i = 0; i < N; i++)
	{
		if (i < N-1 && input[i + 1].x == input[i].x)
		{
			input[i].sx = left;
			input[i].sy = top;
			input[i].gx = input[i].x + 1;
			input[i].gy = input[i].y + 1;

			top = input[i].y + 1;
		}
		else
		{
			input[i].sx = left;
			input[i].sy = top;
			input[i].gx = input[i].x + 1;
			input[i].gy = 10000;

			left = input[i].x + 1;
			top = 0;
		}
	}

	sort(input.begin(), input.end(), compare_id);
	for (int i = 0; i < N; i++)
	{
		printf("%d %d %d %d\n", input[i].sx,
								input[i].sy,
								input[i].gx,
								input[i].gy);
	}

}


#include <bits/stdc++.h>
#define f(a, n) for (int a = 0; a < n; a++)
#define F(a, n) for (int a = 1; a <= n; a++)
using namespace std;

struct Student{
	map<int, int> mp;
	int sz = 1;
	Student* par = this;
};

Student* find(Student* a){
	if (a->par == a) return a;
	return a->par = find(a->par);
}

void join(Student* a, Student* b){ // b joins a
	a->sz += b->sz;
	b->par = a;
	for (auto p: b->mp){
		int x = p.first, y = p.second;
		a->mp[x] += y;
	}
}

int main(){
	int n, q;
	cin >> n >> q;
	Student A[200005];
	F(i, n) {
		int x;
		cin>>x;
		A[i].mp[x]++;
	}
	F(asdf, q){
		int a, b, c;
		cin >> a >> b >> c;
		if (a == 1){
			auto d = find(&A[b]);
			auto e = find(&A[c]);
			if (d != e){
				if (d->sz >= e->sz){
					join(d, e);
				} else{
					join(e, d);
				}
			}
		} else{
			cout<<find(&A[b])->mp[c]<<endl;
		}
	}
}

//#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Общий файл.
//#include <ext/pb_ds/tree_policy.hpp> // Содержит класс tree_order_statistics_node_updat
//#include <ext/pb_ds/detail/standard_policies.hpp>
//#define int long long
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define repb(i, r, l) for (int i = r; i >= l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define ret(a) {cout << a; exit(0);}

using namespace std;

mt19937 mrand(random_device{}());
const int mod = 998244353;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod;if(a==1)return 1; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
typedef pair < int , int > pii ;
typedef pair < long long  , long long > pll ;
const int N = 5000;

using namespace std;
int n, m;
int u[N],v[N];
int c[N];
char ans[N];
int id[200][200];
vector <int> gr[N];
bool was[N];
void dfs(int u, int col){
	was[u] = 1;
	for(int to : gr[u]){
		if(c[to] != col)continue;
		if(ans[id[u][to]] != 0)continue;
		int i = id[u][to];
		if(v[i] == u)
			ans[i] = '<';
		else ans[i] = '>';
		if(!was[to])
			dfs(to,col);
	}
}
main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >> n >> m;
	rep(i,1,m){
		cin >> u[i] >> v[i];
		id[u[i]][v[i]] = id[v[i]][u[i]] = i;
		gr[u[i]].pb(v[i]);
		gr[v[i]].pb(u[i]);
	}
	rep(i,1,n)
		cin >> c[i];

	for(int i = 1; i <= n; i++){
		if(!was[i])
			dfs(i,c[i]);
	}
	for(int i = 1; i <= m;i++){
		if(c[u[i]] > c[v[i]])
			ans[i] = '>';
		else if(c[u[i]] < c[v[i]])
			ans[i] = '<';
	}
	for(int i = 1; i <= m; i++){
		if(ans[i] == '<')
			cout << "<-\n";
		else cout << "->\n";
	}
}


#include <bits/stdc++.h>
#define endl '\n'
#define modulo 1000000007
#define int long long
#define PI acos(-1)
#pragma GCC optimize("-Ofast")
#pragma GCC optimize("trapv")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-funroll-all-loops,-fpeel-loops,-funswitch-loops")
#define sinDegrees(x) sin((x) * PI / 180.0)
#define cosDegrees(x) cos((x) * PI / 180.0)
#define tanDegrees(x) tan((x) * PI / 180.0)
#define atanDegrees(x) atan(x)* 180.0 / PI
#define asinDegrees(x) asin(x)* 180.0 / PI
#define EPS 0.000000001
using namespace std;
int power(int x,int y,int m)
{
int temp;
if(y == 0)
return 1;
temp = (power(x, y/2,m))%m;
if (y%2 == 0)
return ((temp%m)*temp);
else
return ((x*temp%m)*temp%m)%m;
}
int inv(int x,int m=modulo)
{
return (power(x,m-2,m))%m;
}
///IOI 2021 isA
int32_t main()
{
//freopen("output.txt","w",stdout);
//freopen("colors.in","r",stdin);
cin.tie(0),iostream::sync_with_stdio(0);
string a,b;
cin>>a>>b;
int S=0,S2=0;
for(int i=0;i<a.size();i++)
S+=a[i]-'0',S2+=b[i]-'0';
cout<<max(S,S2);
return 0;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef pair<long long, long long> pl;

#define rep(i, a, b) for (int i = a; i < b; i++)

void solve()
{
    ll a, b;
    cin >>a >> b;

    ll sa = 0;
    while(a > 0){
        sa += a%10;
        a/=10;
    }

    ll sb = 0;
    while(b > 0){
        sb += b%10;
        b/=10;
    }

    cout << max(sa, sb) << endl;
}

int main(int argc, char const *argv[])
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    // int t;
    // cin >> t;
    // while(t--)
        solve();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    long long x, y, a, b;
    long long s;

    cin >> x >> y >> a >> b;
    s = 0;

    while ( x*a <= x+b && x*a < y && x < x*a) {
        x *= a;
        s++;
    }

    s += ( (y-x-1) / b < 0 ? 0 : (y-x-1) / b );
    cout << s << endl;

    return (0);
}

#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;i--)
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define coy cout<<"Yes"<<endl
#define con cout<<"No"<<endl
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7
#define LINF 1e18+10
using ll = long long;

using P = pair<int, int>;
using lP = pair<ll, ll>;
using fP = pair<double, double>;
using PPI = pair<P, int>;
using PIP = pair<int, P>;
using Ps = pair<int, string>;

using vi = vector<int>;
using vl = vector<ll>;
using vc = vector<char>;
using vd = vector<double>;
using vs = vector<string>;
using vp = vector<P>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvd = vector<vector<double>>;
using vvc = vector<vector<char>>;
using vvp = vector<vector<P>>;
using vvb = vector<vector<bool>>;
template <typename T>
bool chmax(T& a, const T b) { if (a < b) { a = b; return true; } return false; }
template <typename T>
bool chmin(T& a, const T b) { if (a > b) { a = b; return true; } return false; }

//const ll mod=998244353;
const ll mod = 1e9 + 7;
const ll MAX = 300000;
template <typename T>
T abs(T a) { if (a < 0)return -a; else return a; }//2020/09/30 stdlib has abs(long) abs(long long) error

//////////////////////////////////////
ll x,y,a,b;

int main(){

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


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

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,m,q;
  cin >> n >> m >> q;
  vector<int> w(n);
  vector<int> v(n);
  for (int i=0;i<n;i++) cin >> w[i] >> v[i];
  vector<int> x(m);
  for (int i=0;i<m;i++) cin >> x[i];
  for (int i=0;i<q;i++) {
    int l,r;
    cin >> l >> r;
    l--;
    r--;
    vector<int> ok;
    for (int j=0;j<m;j++) {
      if (j >= l && j <= r) continue;
      ok.emplace_back(x[j]);
    }
    sort(ok.begin(),ok.end());
    int sz = ok.size();
    vector<int> left = v;
    int ans = 0;
    for (int j=0;j<sz;j++) {
      int maxv = -1;
      int mind = -1;
      for (int k=0;k<n;k++) {
        if (w[k] <= ok[j]) {
          if (left[k] > maxv) {
            maxv = left[k];
            mind = k;
          }
        }
      }
      if (mind == -1) continue;
      ans += maxv;
      left[mind] = 0;
    }
    cout << ans << endl;
  }
}

//@formatter:off
#include<bits/stdc++.h>
#define overload4(_1,_2,_3,_4,name,...) name
#define rep1(i,n) for (ll i = 0; i < ll(n); ++i)
#define rep2(i,s,n) for (ll i = ll(s); i < ll(n); ++i)
#define rep3(i,s,n,d) for(ll i = ll(s); i < ll(n); i+=d)
#define rep(...) overload4(__VA_ARGS__,rep3,rep2,rep1)(__VA_ARGS__)
#define rrep1(i,n) for (ll i = ll(n)-1; i >= 0; i--)
#define rrep2(i,n,t) for (ll i = ll(n)-1; i >= (ll)t; i--)
#define rrep3(i,n,t,d) for (ll i = ll(n)-1; i >= (ll)t; i-=d)
#define rrep(...) overload4(__VA_ARGS__,rrep3,rrep2,rrep1)(__VA_ARGS__)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define popcount(x) __builtin_popcountll(x)
#define pb push_back
#define eb emplace_back
#ifdef __LOCAL
#define debug(...) { cout << #__VA_ARGS__; cout << ": "; print(__VA_ARGS__); cout << flush; }
#else
#define debug(...) void(0)
#endif
#define INT(...) int __VA_ARGS__;scan(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;scan(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;scan(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;scan(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;scan(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;scan(__VA_ARGS__)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int,int>;
using LP = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vs = vector<string>;
using vc = vector<char>;
using vvc = vector<vector<char>>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vp = vector<P>;
using vvp = vector<vector<P>>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?"":","); return os<<']'; }
template<class T> void vecout(const vector<T> &v,char div='\n') { rep(i,v.size()) cout<<v[i]<<(i==int(v.size()-1)?'\n':div);}
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;}
void scan(){}
template <class Head, class... Tail> void scan(Head& head, Tail&... tail){ cin >> head; scan(tail...); }
template<class T> void print(const T& t){ cout << t << '\n'; }
template <class Head, class... Tail> void print(const Head& head, const Tail&... tail){ cout<<head<<' '; print(tail...); }
template<class... T> void fin(const T&... a) { print(a...); exit(0); }
struct Init_io {
    Init_io() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        cout.tie(nullptr);
        cout << boolalpha << fixed << setprecision(15);
    }
} init_io;
const string yes[] = {"no","yes"};
const string Yes[] = {"No","Yes"};
const string YES[] = {"NO","YES"};
const int inf = 1001001001;
const ll linf = 1001001001001001001;
//@formatter:on

int main() {
    INT(x, y, z);
    rrep(i, 1000000) {
        if (y * z > i * x) fin(i);
    }
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;const int mod = 1000000007;
//const int mod = 998244353;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main(){

    int N;
    cin>>N;
    vector<ll> A(N+1);

    ll a;

    for(int i=1;i<=N;i++){
        cin>>a;
        A[i]=a+A[i-1];
    }

    vector<vector<ll> >dp(N+1,vector<ll>(N+1,0));

    for(int i=1;i<=N;i++){
        for(int j=0;j<=N;j++){
            dp[i][j]=A[j]%i;
        }
    }

    vector<vector<mint> > g(N+1,vector<mint>(N+1,0));
    for(int i=1;i<=N;i++){
        g[1][i]=1;
    }

    for(int i=2;i<=N;i++){
        map<ll,ll> mp1;
        map<ll,mint> mp2;
        for(int j=i-1;j<=N;j++){
            mp1[dp[i][j]]++;
            if(mp1[dp[i][j]]>1){

                g[i][j]=mp2[dp[i][j]];

            };
            mp2[dp[i][j]]+=g[i-1][j];
        }
        /*
        cout<<"i: "<<i<<" ";
        for(auto a:mp1){
            cout<<a.first<<" "<<a.second<<endl;
        }
         */
    }

    mint ans=0;

    for(int i=0;i<=N;i++){
        ans+=g[i][N];
    }

    cout<<ans<<endl;
    /*
    for(int i=0;i<=N;i++){
        for(int j=0;j<=N;j++){
            cout<<g[i][j]<<" ";
        }
        cout<<endl;
    }
    cout<<" A "<<endl;
    for(int i=0;i<=N;i++){

            cout<<A[i]<<" ";

    }
    cout<<endl;

    cout<<" dp "<<endl;
    for(int i=0;i<=N;i++){
        for(int j=0;j<=N;j++){
            cout<<dp[i][j]<<" ";
        }
        cout<<endl;
    }
     */
}

#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>

using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;

#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()

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

int main(){
    ll N;
    cin>>N;
    v A(N),sA(N,0);
    rep(i,0,N)cin>>A[i];
    sA[0]=A[0];
    rep(i,1,N){
        sA[i]=sA[i-1]+A[i];
    }
    vv dp(N,v(N,0));
    rep(i,0,N)dp[0][i]=1;

    rep(i,1,N){
        ll NM = i+1;
        v mods(NM,0);
        mods[sA[i-1]%NM]+=dp[i-1][i-1];
        mods[sA[i-1]%NM]%=MOD;
        rep(j,i,N){
            dp[i][j] += mods[sA[j]%NM];
            dp[i][j] %=MOD;
            mods[sA[j]%NM]+=dp[i-1][j];
            mods[sA[j]%NM] %=MOD;
        }
    }

    ll ans = 0;
    rep(i,0,N){
        ans+=dp[i][N-1];
        ans%=MOD;
    }
    cout<<ans;
    return 0;
}


#define _USE_MATH_DEFINES

#include <bits/stdc++.h>

using namespace std;

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

constexpr ll MOD = 998244353;

#ifndef ONLINE_JUDGE
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " (" << x.first << " : " << x.second << ")" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "["; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "]"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "(" << obj.first << ", " << obj.second << ")"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print_sim_py(void) {cout << endl;}
template <class Head> void print_sim_py(Head&& head) {cout << head;print_sim_py();}
template <class Head, class... Tail> void print_sim_py(Head&& head, Tail&&... tail) {cout << head << " ";print_sim_py(forward<Tail>(tail)...);}

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

#define print(...) print_sim_py(__VA_ARGS__);
#else
#define print(...);
#endif

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

    string s;

    cin >> s;
    vector<ll> nc(10,0);
    for(int i=0; i<s.length(); i++){
        ll x=s[i]-'0';
        nc[x]++;
    }

    auto tmp = nc;
    ll ie=10,je=10;

    switch(s.length()){
    case 1:
        je = 1;
        nc[0]++;
    case 2:
        ie = 1;
        nc[0]++;
    }

    auto f = [&](){
        string ans = "No";
        for(ll i=0; i<ie; i++){
            for(ll j=0; j<je; j++){
                for(ll k=0; k<10; k++){
                    tmp[i]--;
                    tmp[j]--;
                    tmp[k]--;

                    if(tmp[i]>=0 && tmp[j]>=0 && tmp[k]>=0){
                        ll v = i*100+j*10+k;
                        if(v%8==0){
                            ans = "Yes";
                            return ans;
                        }
                    }
                    tmp = nc;
                }
            }
        }
        return ans;
    };

	auto ans = f();

    cout << ans << endl;

    return 0;
}

#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<set>
#include<iterator>
#include <map>
#include<cmath>
#include <list>
#include<string>
#include <stdlib.h>
#include<ctime>
#include<cstring>
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define line cout<<'\n'
typedef long long ll;
using namespace std;
vector<long double>roots1;
void printVec(vector<long double>&v)
{
	int sz = v.size();
	for (long double x : v)
	{
		cout << x << " ";
	}
	line;
}
void printVec(vector<double>&v)
{
	int sz = v.size();
	for (double x : v)
	{
		cout << x << " ";
	}
	line;
}
void printVec(vector<vector<long double>>&vec)
{
	for (int i = 0; i < vec.size(); i++)
	{
		for (int j = 0; j < vec[i].size(); j++)
		{
			cout << vec[i][j] << " ";
		}
		line;
	}
	line;
}
void print(vector<pair<double, double>>&vec)
{
	int sz = vec.size();
	for (int i = 1; i < sz; i++)
	{
		cout << vec[i].first << " " << vec[i].second << endl;
	}
	line;
}
int main()
{
	fastIO
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	string s;
	ll n;
	cin >> s;
	int sz=s.size();
	if(sz<=2)
	{
		string s1=s;
		reverse(s1.begin(), s1.end());
		if(stoi(s)%8==0 or stoi(s1)%8==0)
		{
			cout<<"Yes\n";
		}
		else
		{
			cout<<"No\n";
		}
	}
	else
	{
		bool flag=false;
		vector<int>freq(10,0);
		for(int i=0;i<sz;i++)
		{
			freq[s[i]-'0']++;
		}
		for(int i=104;i<1000;i+=8)
		{
			int temp=i;
			flag=false;
			vector<int> freq1(10,0);
			while(temp!=0)
			{
				freq1[temp%10]++;
				temp/=10;
			}
			for(int j=0;j<10;j++)
			{
				if(freq[j]<freq1[j])
				{
					flag=true;
					break;
				}
			}
			if(!flag)
			{
				cout<<"Yes\n";
				break;
			}
		}
		if(flag)
		{
			cout<<"No\n";
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=5e5+100;
int read()
{
	int ans=0;bool f=0;char ch=getchar();
	while(ch<'0' or ch>'9'){if(ch=='-')f=1;ch=getchar();}
	while(ch>='0' and ch<='9'){ans=(ans<<1)+(ans<<3)+(ch^48);ch=getchar();}
	return f?~ans+1:ans;
}
int n,ans,nx[maxn],per[maxn];
char s1[maxn],s2[maxn];
vector<int>g1,g2;
int abx(int x)
{
	return x>0?x:-x;
}
int main()
{
	n=read();
	scanf("%s%s",s1+1,s2+1);
	int now=1;
	for(int i=1;i<=n;++i)
	{
		if(s1[i]=='0')
		g1.push_back(i);
		if(s2[i]=='0')
		g2.push_back(i);
	}
	nx[now]=n+1;
	if(g1.size()!=g2.size())
	{
		puts("-1");
		return 0;
	}
	for(int i=0;i<g1.size();++i)
	{
		ans+=abx(g1[i]-g2[i])!=0;
	}
	cout<<ans;
	return 0;
}

#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline")
#pragma GCC optimize(3 , "Ofast" , "inline")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <unordered_map>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <stack>
#include <set>
#include <bitset>
#include <deque>
using namespace std ;
#define ios ios::sync_with_stdio(false) , cin.tie(0)
#define x first
#define y second
#define pb push_back
#define ls rt << 1
#define rs rt << 1 | 1
typedef long long ll ;
const double esp = 1e-6 , pi = acos(-1) ;
typedef pair<int , int> PII ;
const int N = 1e6 + 10 , INF = 0x3f3f3f3f , mod = 1e9 + 7;
int n ;
string a , b ;
vector<int> va , vb ;
int work()
{
  cin >> n >> a >> b ;
  for(int i = 0 ;i < a.size() ;i ++ )
  	 if(a[i] == '0') va.pb(i) ;
  for(int i = 0 ;i < b.size() ;i ++ )
  	 if(b[i] == '0') vb.pb(i) ;
  if(va.size() != vb.size()) return puts("-1") , 0 ;
  int ans = 0 ;
  for(int i = 0 ;i < va.size() ;i ++ )
  	if(va[i] != vb[i]) ans ++ ;
  cout << ans << "\n" ;
  return 0 ;
}
int main()
{
  //   freopen("C://Users//spnooyseed//Desktop//in.txt" , "r" , stdin) ;
  //   freopen("C://Users//spnooyseed//Desktop//out.txt" , "w" , stdout) ;

  work() ;
  return 0 ;
}
/*

*/


#pragma GCC optimize "trapv"
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define ld long double
//#define mp make_pair
#define pii pair<int,int>
#define mod 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define repp(i,a,n) for(int i=a;i<n;i++)
#define all(v) v.begin(),v.end()
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
vector<string> split(const string& s, char c) {
    vector<string> v; stringstream ss(s); string x;
    while (getline(ss, x, c)) v.push_back(x); return move(v);
}
template<typename T, typename... Args>
inline string arrStr(T arr, int n) {
    stringstream s; s << "[";
    for(int i = 0; i < n - 1; i++) s << arr[i] << ",";
    s << arr[n - 1] << "]";
    return s.str();
}
#define EVARS(args...) {__evars_begin(__LINE__); __evars(split(#args, ',').begin(), args);}
inline void __evars_begin(int line) { cerr << "#" << line << ": "; }
template<typename T> inline void __evars_out_var(vector<T> val) { cerr << arrStr(val, val.size()); }
template<typename T> inline void __evars_out_var(T* val) { cerr << arrStr(val, 10); }
template<typename T> inline void __evars_out_var(T val) { cerr << val; }
inline void __evars(vector<string>::iterator it) { cerr << endl; }
template<typename T, typename... Args>
inline void __evars(vector<string>::iterator it, T a, Args... args) {
    cerr << it->substr((*it)[0] == ' ', it->length()) << "=";
    __evars_out_var(a);
    cerr << "; ";
    __evars(++it, args...);
}
template<typename T_vector>
void output_vector(const T_vector &v, bool add_one = false, int start = -1, int end = -1) {
    if (start < 0) start = 0;
    if (end < 0) end = int(v.size());

    for (int i = start; i < end; i++)
        cout << v[i] + (add_one ? 1 : 0) << (i < end - 1 ? ' ' : '\n');
}
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    fio;
    clock_t clk = clock();
    int t = 1;
    // cin >> t;
    while(t--)
    {
        string s;
        cin >> s;
        ll n = (ll)s.size();
        bool ok = true;
        for(int i = 0; i < n; i++)
        {
            if(i % 2 == 0)
            ok &= (s[i] >= 'a' && s[i] <= 'z');
            else
            ok &= (s[i] >= 'A' && s[i] <= 'Z');
        }
        cout << (ok ? "Yes" : "No") << endl;
    }
    cerr << '\n'<<"Time (in s): " << double(clock() - clk) * 1.0 / CLOCKS_PER_SEC << '\n';
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=2e5+5;
int mod=1e9+7;
int gcd(int x,int y)
{
    if(y==0)
    {
        return x;
    }
    return gcd(y,x%y);
}
int power(int a,int n)
{
    int res=1;
    while(n)
    {
        if(n%2)
        {
            res=(res*a)%mod;
        }
        n=n/2;
        a=(a*a)%mod;
    }
    return res;
}
void solve()
{
    int i,j,n,total=0,ans=1e8;
    cin>>n;
    vector<int> arr;
    arr.assign(n,0);
    for(i=0;i<n;i++)
    {
        cin>>arr[i];
        total=total+arr[i];
    }
    int dp[n+1][total+1];
    for(i=0;i<=n;i++)
    {
        for(j=0;j<=total;j++)
        {
            dp[i][j]=0;
        }
    }
    dp[0][0]=1;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=total;j++)
        {
            if(j<arr[i-1])
            {
                dp[i][j]=dp[i-1][j];
            }
            else
            {
                dp[i][j]=dp[i-1][j]+dp[i-1][j-arr[i-1]];
            }
        }
    }
    for(j=1;j<total;j++)
    {
        if(dp[n][j])
        {
            ans=min(ans,max(j,total-j));
        }
    }
    if(n==1)
    {
        cout<<arr[0];
        return;
    }
    cout<<ans;
}
int32_t main()
{
    int t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double d;
typedef long double ld;
inline int read()
{
	register int s=0,f=0;
	register char ch=getchar();
	while(!isdigit(ch)) f|=(ch=='-'),ch=getchar();
	while(isdigit(ch)) s=(s<<1)+(s<<3)+(ch^48),ch=getchar();
	return f?-s:s;
}
inline void write(int x)
{
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}
int a[5005][305];
char ch[5] = {' ', 'A', 'T', 'G', 'C'};
signed main()
{
	int n;
	string s;
	cin >> n >> s;
	int ans = 0;
	s = ' ' + s;
	for (int i = 1; i <= n; i ++)
	{
		for (int j = 1; j <= 4; j ++)
		{
			a[i][ch[j]] = a[i - 1][ch[j]] + (s[i] == ch[j]);
		}
	}
	for (int i = 1; i <= n; i ++)
	{
		for (int j = 2; j <= (n - i) + 1; j += 2)
		{
			string t = s.substr (i, j);
			int sa;
			int st;
			int sg;
			int sc;
			sa = a[i + j - 1]['A'] - a[i - 1]['A'];
			st = a[i + j - 1]['T'] - a[i - 1]['T'];
			sg = a[i + j - 1]['G'] - a[i - 1]['G'];
			sc = a[i + j - 1]['C'] - a[i - 1]['C'];
			if (sa == st && sg == sc) ans ++;
		}
	}
	cout << ans << endl;
	return 0;
}

#include <iostream>
#include <iomanip>
#include <vector>
#include <array>
#include <stack>
#include <queue>
#include <tuple>
#include <algorithm>
#include <unordered_set>
#include <cmath>

using ull = unsigned long long;
using ll = long long;

#define REP(i, n) for(ll i=0;i<(ll)n;i++)
#define REPab(i,a,b)for(ll i=(ll)a;i<(ll)b;i++)
constexpr bool bitp(ull bits, ull pos) { return bits & (1ULL << pos); }

int main() {
    ll N;
    std::cin >> N;
    std::vector<ull> A(N);
    REP(i, N) std::cin >> A[i];
    ull max = 1ULL << (N - 1);
    ull score = std::numeric_limits<ull>::max();
    for (ull b = 0; b < max; b++) {
        ull bOR = A[0];
        ull bXOR = 0;
        for (ull t = 0; t < N - 1; t++) {
            if (bitp(b, t)) {
                bXOR ^= bOR;
                bOR = 0;
            }
            bOR |= A[t + 1];
        }
        bXOR ^= bOR;
        score = std::min(score, bXOR);
    }
    std::cout << score << "\n";
}


#include <bits/stdc++.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <list>
#define eps 10e-14
//cout<<fixed<<setprecision(15)<<
//s=to_string(100);
//vector<vector<char>>c(h,vector<char>(w));
//next_permutation(orig.begin(),orig.end());
using namespace std;
int gcd(int x,int y){
  while(y>0){
    int r=x%y;
      x=y;
      y=r;
  }
  return x;
}
int lcm(int a,int b){
  int r=gcd(a,b);
  return a*b/r;
}
template<typename T, typename U>
void primeFactorization(map<T, U> &primes, T N) {
  T n=N;
  U num=0;
  while(n%2==0){
    num++;
    n/=2;
  }
  if(num!=0){
    primes.emplace(2,num);
  }
  for(T i=3;i*i<=N;i+=2) {
    num=0;
    while(n%i==0){
      num++;
      n/=i;
    }
    if(num!=0){
      primes.emplace(i, num);
    }
  }
  if(n!=1){
    primes.emplace(n,1);
  }
}
template<typename TypeInt>
string Itoa(const TypeInt v, int base){
    static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    string ret;
    static numeric_limits<TypeInt> t;
    TypeInt n = v;
    if (t.is_signed) {
        if (v < 0) n *= -1;
    }
    while (n >= base) {
        ret += table[n%base];
        n /= base;
    }
    ret += table[n];
    if (t.is_signed) {
        if (v < 0 && base == 10) ret += '-';
    }
    // 文字列の順番を逆にする
    std::reverse(ret.begin(), ret.end());
    return ret;
}
int hanoi(int n){
  return pow(2,n)-1;
}

int main() {
  long long n,k,count=0;
  cin>>n;
  vector<long long>a(n),b(n);
  map<long long,long long>m;
  for(int i=0;i<n;i++){
    cin>>a.at(i);
    m[a.at(i)%200]++;
  }
  for(auto t:m){
    if(t.second>=2){
      for(int i=1;i<t.second;i++)count+=i;
    }
  }
  cout<<count<<endl;
}

#include <iostream>
#include <vector>
#include <set>

using namespace std;

typedef long long ll;

const ll INF = 1e18 + 2000;

ll mdist (const set<pair<ll, int>> &A, const set<pair<ll, int>> &B) {
  ll ans = INF;
  for (auto it = A.begin(); it != A.end(); it++) {
    auto oth = B.lower_bound(*it);
    if (oth != B.end()) {
      ans = min(ans, oth->first - it->first);
    }

    if (oth != B.begin()) {
      ans = min(ans, it->first - prev(oth)->first);
    }
  }
  return ans;
}

int main () {
  int n;
  cin >> n;
  n *= 2;

  set<pair<ll, int>> rs, gs, bs;
  for (int i = 0; i < n; i++) {
    ll a;
    char c;
    cin >> a >> c;

    auto pr = make_pair(a, i);

    switch(c) {
    case 'R':
      rs.insert(pr);
      break;
    case 'G':
      gs.insert(pr);
      break;
    case 'B':
      bs.insert(pr);
      break;
    }
  }

  if ((int) rs.size() % 2 == 0 && (int) gs.size() % 2 == 0 && (int) bs.size() % 2 == 0) {
    cout << 0 << endl;
    return 0;
  }

  if (bs.size() % 2 == 0) {
    swap(bs, gs);
  }

  if (rs.size() % 2 == 0) {
    swap(rs, gs);
  }

  cout << min(mdist(rs, bs), mdist(rs, gs) + mdist(bs, gs)) << endl;
}


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

void check(long long &a, vector<int> &v, vector<int> &c, int i, int &lc){
  if(c.at(i) == lc){
    a++;
    return;
  }
  if(c.at(i) != -1){
    return;
  }
  c.at(i) = lc;
  check(a, v, c, v.at(i), lc);
}

int main(){
  int N;
  long long a = 0;
  cin >> N;
  vector<int> v(N);
  rep(i, N){
    cin >> v.at(i);
    v.at(i)--;
  }
  vector<int> c(N, -1);
  for(int i = 0; i < N; i++){
    if(c.at(i) == -1){
      check(a, v, c, i, i);
    }
  }
  long long ans = 1;
  rep(i, a){
    ans *= 2;
    ans %= 998244353;
  }
  cout << ans - 1 << endl;
}

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

#define ll long long
#define forin(in ,n) for(ll i=0; i<n; i++) cin>>in[i]
#define forout(out) for(ll i=0; i<(ll)out.size(); i++) cout<<out[i]<<endl
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep_up(i, a, n) for (ll i = a; i < n; ++i)
#define rep_down(i, a, n) for (ll i = a; i >= n; --i)
#define P pair<ll, ll>

#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define vvvll vector<vector<vector<ll>>>
#define vvll vector<vector<ll>>
#define vll vector<ll>
#define pqll priority_queue<ll>
#define pqllg priority_queue<ll, vector<ll>, greater<ll>>

constexpr ll INF = (1ll << 60);
// constexpr ll mod = 1000000007;
constexpr ll mod = 998244353;
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
void pt(T val) {
    cout << val << "\n";
}
template <typename T>
void pt_vll(vector<T> &v) {
    ll vs = v.size();
    rep(i, vs) {
        cout << v[i];

        if (i == vs - 1)
            cout << "\n";
        else
            cout << " ";
    }
}
ll mypow(ll a, ll n) {
    ll ret = 1;
    if(n==0) return 1;
    if(a==0) return 0;
    rep(i, n) {
        if (ret > (ll)(1e18 + 10) / a) return -1;
        ret *= a;
    }
    return ret;
}
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll dig(ll n) {//桁数
    ll res = 0;
    while(n > 0) {
        res ++;
        n /= 10;
    }
    return res;
}
vector<bool> seen;
void dfs(vvll &G, ll v){
    seen[v]=true;
    for(auto next:G[v]){
        if(seen[next]) continue;
        dfs(G,next);
    }
}

int main() {
    ll n,x,ans=1;
    cin>>n;
    vvll G(n);
    vll a(n);
    rep(i,n){
        cin>>x;
        x--;
        G[i].push_back(x);
        G[x].push_back(i);
    }
    seen.assign(n,false);
    rep(i,n){
        if(seen[i]) continue;
        dfs(G,i);
        ans*=2;
        ans%=mod;
    }
    cout<<(mod+ans-1)%mod<<endl;
}


#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <complex>

using namespace std;

//#pragma GCC optimize("Ofast")
//#pragma GCC optimization("unroll-loops, no-stack-protector")
//#pragma GCC target("avx,avx2,fma")

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

	long long k, i, j, ans, x, s;
	cin >> k;
	vector<long long> v(k + 10, 0);		// # of ways to get AB <= x

	for (i = 1; i <= k; i++) {
		for (j = 1; (i * j) <= k; j++) v[i * j]++;
	}
	for (i = 1; i <= k; i++) v[i] += v[i - 1];

	ans = 0;
	for (i = 1; i <= k; i++) ans += v[k / i];
	cout << ans << "\n";

	return 0;
}

#include<bits/stdc++.h>
#define int long long
#define ll long long
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define fs first
#define sd second
#define rept(x,n) for(int i=x;i<n;i++)
#define rrept(n,x) for(int i=n-1;i>=x;i--)
#define all(v) v.begin(),v.end()
#define mpit map<int,int>::iterator
#define stit set<int,int>::iterator
#define quit queue<int,int>::iterator
#define maxt(a,b,c) max(a,max(b,c))
#define mint(a,b,c) min(a,min(b,c))
#define rsort(v) sort(v.rbegin(),v.rend())
#define pb push_back
#define prnt(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" ";
using namespace std;
void solve()
{
    ll m;
    cin>>m;
    ll cnt = 0;
     for(ll i = 1;;i++)
     {
         if(i>m)
            break;
         for(ll j = 1;;j++)
         {
             if(i*j>m)
                break;
             for(ll k = 1;;k++)
             {
                 if(i*j*k>m)
              {
                 break ;
              }
                 else
                    cnt++;

             }
         }
     }
    cout<<cnt<<"\n";

}
signed main()
{
    speed;
    int t=1;
    //cin>>t;
    while(t--)
    {
         solve();
    }
    return 0;
}


#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
#define double long double
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define PRINT(a) printf("%.15Lf\n",a);
#define YESNO(a) cout << (a ? "YES" : "NO") << endl
#define YesNo(a) cout << (a ? "Yes" : "No") << endl
#define yesno(a) cout << (a ? "yes" : "no") << endl
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
#define eps 1e-12
//priority_queue<int,vector<int>, greater<int> > q2;

int dp[200010][7];
int ten[200010];
int N;
string S, X;

int solve(int now, int m) {
	//cout << now << " " << m << endl;
	if (dp[now][m] != 0)return dp[now][m];
	if (now == N) {
		if (m == 0)return 1;
		else return 2;
	}
	else {
		int ans1 = solve(now + 1, m);
		int ans2 = solve(now + 1, (m + (S[now] - '0')*ten[N - now - 1]) % 7);
		//cout << now << " " << m << " " << ans1 << " " << ans2  <<" "<< S[now]<< endl;
		if (ans1 == 1 && ans2 == 1) {
			dp[now][m] = 1;
			return 1;
		}
		else if (ans1 == 2 && ans2 == 2) {
			dp[now][m] = 2;
			return 2;
		}
		else if (X[now] == 'T'){
			dp[now][m] = 1;
			return 1;
		}
		else{
			dp[now][m] = 2;
			return 2;
		}
	}
}

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

	cin >> N;
	REP(i, N) {
		if (i == 0)ten[i] = 1;
		else {
			ten[i] = (ten[i - 1] * 10) % 7;
		}
	}
	cin >> S >> X;
	int ans = solve(0, 0);
	if (ans == 1) {
		cout << "Takahashi" << endl;
	}
	else {
		cout << "Aoki" << endl;
	}

	return 0;
}

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <cmath>
using namespace std;

const int INF = 2000000000;
int N,M,Q;

int main() {
    // Step #1. Input
    cin >> N;
    vector<int> xa(N+1);
    vector<int> ya(N+1);
    for (int i = 1; i <= N; i++){
        cin >> xa[i] >> ya[i];
    }
    cin >> M;
    vector<vector<int64_t> > X(M+1,vector<int64_t>(4));
    vector<vector<int64_t> > Y(M+1,vector<int64_t>(4));
    /*
    for (int i = 1; i <= N; i++){
        X[0][i]=xa[i];
        Y[0][i]=ya[i];
    }
    */
   X[0][1]=0;
   Y[0][1]=0;
   X[0][2]=1;
   Y[0][2]=0;
   X[0][3]=0;
   Y[0][3]=1;

    for(int i=1;i<=M;i++){
        int a;
        int64_t b;
        cin >> a;
        if(a>2){
            cin >> b;
        }
        for(int j=1;j<=3;j++){
            int64_t x=X[i-1][j];
            int64_t y=Y[i-1][j];
            if(a==1){
                X[i][j]=y;
                Y[i][j]=0-x;
            }else if(a==2){
                X[i][j]=0-y;
                Y[i][j]=x;
            }else if(a==3){
                X[i][j]=2*b-x;
                Y[i][j]=y;
            }else{
                X[i][j]=x;
                Y[i][j]=2*b-y;
            }
        }
    }

    cin >> Q;
    for(int i=1;i<=Q;i++){
        int a,b;
        cin >> a >> b;
        int64_t x_x=X[a][2]-X[a][1];
        int64_t x_y=Y[a][2]-Y[a][1];
        int64_t y_x=X[a][3]-X[a][1];
        int64_t y_y=Y[a][3]-Y[a][1];
        cout << X[a][1]+x_x*xa[b]+y_x*ya[b] << " " << Y[a][1]+x_y*xa[b]+y_y*ya[b] << endl;

        //cout << X[a][b] << " " << Y[a][b] << endl;
    }
    /*
    for(int i=1;i<=3;i++){
        cout << X[M][i] << " " << Y[M][i] << endl;
    }
    */

    //cout << sum << endl;

}


#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<stack>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

struct Edge {
  int to;
  long long weight;
  Edge() : to(0), weight(0) {}
  Edge(int to, long long weight) : to(to), weight(weight) {}
  Edge(const Edge& e) {
    to = e.to;
    weight = e.weight;
  }
};

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
using weightedGraph = vector<vector<Edge>>;
using heap = priority_queue<int, vector<int>, greater<int>>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)
#define inf (1<<29)

int main(int argc,char* argv[]){
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
  int n;
  cin >> n;
  vector<int> ans(n+1, 2);
  ans[1] = 1;
  for(int i=2;i<n+1;i++) {
    for(int j=2;i*j<n+1;j++) {
      if(ans[i*j] != ans[i]) continue;
      ans[i*j]++;
    }
  }
  for(int i=1;i<n+1;i++) {
    cout << ans[i];
    if(i != n) cout << " ";
  }
  cout << endl;
  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;

//#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")

#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first

typedef pair < long long, long long > pll;
typedef pair < int, int > pii;
typedef unsigned long long ull;
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb;
typedef long long ll;
typedef double db;

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

const int inf = 1e9, maxn = 2e5 + 48, mod = 1e9 + 7, N = 1e5 + 512;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 300;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const db eps = 1e-12, pi = acos(-1);
const ll INF = 1e18;

int n;

main () {
	cin >> n;
	cout << setprecision(8) << fixed;
	db ans = 0;
	for (int i = 1; i < n; ++i)
		ans += (n + 0.0) / i;

	cout << ans << endl;
}


#include<bits/stdc++.h>

using namespace std;

const int N=2e5+5;
int a[N],b[N];
bool visited[N];
vector<int>adj[N];
long long add,sub;

void DFS(int cur)
{
    if(visited[cur])return;
    visited[cur]=1;
    if(a[cur] > b[cur])sub+=a[cur]-b[cur];
    else add+=b[cur]-a[cur];
    for(int it : adj[cur])DFS(it);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int i,m,n,x,y;
    cin >> n >> m;
    for(i=1;i<=n;i++)cin >> a[i];
    for(i=1;i<=n;i++)cin >> b[i];
    while(m--)
    {
        cin >> x >> y;
        adj[x].emplace_back(y);
        adj[y].emplace_back(x);
    }
    for(i=1;i<=n;i++)
    {
        if(!visited[i])
        {
            add=sub=0;
            DFS(i);
            if(add != sub)
            {
                cout << "No";
                return 0;
            }
        }
    }
    cout << "Yes";
    return 0;
}

//#undef DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll llinf = (1ll<<61)-1;
const char lf = '\n', splf[] = " \n";
#define sz(a) int(a.size())
#define all(x) begin(x), end(x)
#define TCC template<class C
#define OSO ostream &operator<<(ostream &os, const
#ifdef DEBUG
const int DEBUG_END = 26;
#define DOS cout
#include <debug.h>
#else
#define bug(args...) void()
#define cbug(a, args...)
#endif
#define ASSERT(a, o, b, args...) if (!((a)o(b))) bug(a, b, ##args), assert((a)o(b));
#define fi first
#define se second
#define Pair make_pair

class DSU//{
{
    vector<int> dsupar;
public:
    int cntDSU;
    vector<int> siz;

    void reset(int nd) {
        for (int i = 0; i <= nd; i++) dsupar[i] = i, siz[i] = 1;
        cntDSU = nd;
    }

    DSU(int N, int noOfSets = -1) {
        dsupar.resize(N+5), siz.resize(N+5);
        reset(N+4);
        cntDSU = noOfSets==-1 ? N : noOfSets;
    }

    int find(int x) {
        return dsupar[x]==x ? x : dsupar[x] = find(dsupar[x]);
    }

    void union_(int u, int v) {
        if ((u = find(u))==(v = find(v))) return;
        if (siz[u]<siz[v]) swap(u, v);
        dsupar[v] = u, siz[u] += siz[v], siz[v] = 0;
        cntDSU--;
    }

    bool same(int u, int v) { return find(u)==find(v); }

    int size(int u) { return siz[find(u)]; }

    vector<vector<int>> groups(int mnNode, int mxNode) {
        vector<vector<int>> ret(mxNode+1);
        for (int i = mnNode; i <= mxNode; ++i) {
            ret[find(i)].push_back(i);
        }
        ret.erase(
            remove_if(ret.begin(), ret.end(), [](const vector<int> &v) { return v.empty(); }),
            ret.end());
        return ret;
    }
};//}
#define yes cout << "Yes\n"
#define no cout << "No\n"

const int inf = 1000000007,N=200005;
int TC=1, CN,n,m,a[N],b[N];
ll sa[N],sb[N];

signed main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); cout.precision(11), cout.setf(ios::fixed);
    //cin >> TC;// inputAll + resetAll -> solution
    auto kase = [&]()->void {
        cin>>n>>m;
        DSU dsu(n);
        for(int i=1;i<=n;++i)cin>>a[i];
        for(int i=1;i<=n;++i)cin>>b[i];
        for(int i=0;i<m;++i){
            int u,v;
            cin>>u>>v;
            dsu.union_(u,v);
        }
        for(int i=1;i<=n;++i){
            int p=dsu.find(i);
            sa[p]+=a[i],sb[p]+=b[i];
        }
        for(int i=1;i<=n;++i){
            if(sa[i]!=sb[i]){no;return;}
        }
        yes;
    };
    while (CN++!=TC) kase();
}


#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define double long double
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#ifndef LOCAL
#define dbg(...) ;
#define endl '\n'
#endif

const int inf = 1e15;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;

signed main(){
    IOS;
    int a, b;
    cin >> a >> b;
    if (b >= a) {
        int s = 0;
        vector<int> v;
        for (int i = 1; i <= b; i++) {
            v.push_back(-i);
            s -= i;
        }
        for (int i = 1; i < a; i++) {
            v.push_back(i);
            s += i;
        }
        s = -s;
        for (auto i : v)
            cout << i << " ";
        cout << s << endl;
    } else {
        int s = 0;
        vector<int> v;
        for (int i = 1; i <= a; i++) {
            v.push_back(i);
            s += i;
        }
        for (int i = 1; i < b; i++) {
            v.push_back(-i);
            s -= i;
        }
        s = -s;
        for (auto i : v)
            cout << i << " ";
        cout << s << endl;
    }
    return 0;
}

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

struct Lucas {
    vector<vector<long long>> table;
    long long p;
    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 > 0) {
            ret *= table[n % p][k % p];
            ret %= p;
            n /= p;
            k /= p;
        }
        return ret;
    }
};

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

    Lucas lu(3);
    int n,B=0,W=1,R=2; string s; cin >> n >> s;
    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;
    }

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


#include<bits/stdc++.h>
using namespace std;
//#include <atcoder/scc>
//using namespace atcoder;
//using mint = modint998244353;
//using mint = modint1000000007;
#pragma region template
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define overload4(_1,_2,_3,_4,name,...) name
#define overload3(_1,_2,_3,name,...) name
#define rep1(n) for(ll i=0;i<n;++i)
#define rep2(i,n) for(ll i=0;i<n;++i)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
#define rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define rrep1(n) for(ll i=n;i--;)
#define rrep2(i,n) for(ll i=n;i--;)
#define rrep3(i,a,b) for(ll i=b;i-->(a);)
#define rrep(...) overload3(__VA_ARGS__,rrep3,rrep2,rrep1)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define debug(var)  do{std::cerr << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cerr << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cerr << e << " "; } std::cerr << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){cerr << endl;int cnt = 0;for(const auto& v : vv){cerr << cnt << "th : "; view(v); cnt++;} cerr << endl;}
std::ostream &operator<<(std::ostream &dest, __int128_t value) {
  std::ostream::sentry s(dest);
  if (s) {
    __uint128_t tmp = value < 0 ? -value : value;
    char buffer[128];
    char *d = std::end(buffer);
    do {
      --d;
      *d = "0123456789"[tmp % 10];
      tmp /= 10;
    } while (tmp != 0);
    if (value < 0) {
      --d;
      *d = '-';
    }
    int len = std::end(buffer) - d;
    if (dest.rdbuf()->sputn(d, len) != len) {
      dest.setstate(std::ios_base::badbit);
    }
  }
  return dest;
}
template<class T, class K>bool chmax(T &a, const K b) { if (a<b) { a=b; return 1; } return 0; }
template<class T, class K>bool chmin(T &a, const K b) { if (b<a) { a=b; return 1; } return 0; }
const int inf = 1001001001;
const ll INF = 1001001001001001001ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll rddiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // -20 / 3 == -7
ll power(ll a, ll p){ll ret = 1; while(p){if(p & 1){ret = ret * a;} a = a * a; p >>= 1;} return ret;}
ll modpow(ll a, ll p, ll mod){ll ret = 1; while(p){if(p & 1){ret = ret * a % mod;} a = a * a % mod; p >>= 1;} return ret;}
ll rudiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); } //  20 / 3 == 7
#pragma endregion
// const double pi = acos(-1);
//const ll mod = 998244353;
const ll mod = 1000000007;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(20);
    int n, m; cin >> n >> m;
    int ans = 0;
    VV<int> G(n);
    rep(i,m){
        int a, b; cin >> a >> b;
        --a, --b;
        G[a].pb(b);
    }
    rep(i,n){
        queue<int> que;
        V<bool> seen(n);
        que.push(i);
        while(que.size()){
            int v = que.front(); que.pop();
            if(seen[v]) continue;
            seen[v] = true;
            ans++;
            for(int nv : G[v]){
                if(!seen[nv]) que.push(nv);
            }
        }
    }
    cout << ans << endl;
}

#include<iostream>
using namespace std;
#include<bits/stdc++.h>
typedef long long int ll;
void dfs(int i,vector<vector<int>>&adj,int vis[]){
  vis[i]=1;
  for(int child:adj[i]){
    if(vis[child]==0)
      dfs(child,adj,vis);
  }
}
int main(){
  int n,m;
  cin>>n>>m;
  vector<vector<int>>adj(n+1);
  int u,v;
  for(int i=1;i<=m;i++){
    cin>>u>>v;
    adj[u].push_back(v);
  }
  ll cnt=0;
  for(int i=1;i<=n;i++){
    int vis[n+1];
    for(int j=1;j<=n;j++)
      vis[j]=0;
    dfs(i,adj,vis);
    for(int j=1;j<=n;j++){
      if(vis[j]==1)
        cnt++;
    }
  }
  cout<<cnt<<endl;
}


//BY: YASH JAIN, CF: BitSane
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#define May_the_fork_be_with_you ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define rall(v) v.rbegin(),v.rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define deb(x) cout<<#x<<": "<<x<<endl;
#define debn(x) cout<<#x<<": "<<x<<"  ";
#define MOD 1000000007
#define mod 998244353
#define INF 1e18
#define ll long long
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define endl "\n"
#define int long long
#define N 100005
#define sq(x) ((x)*(x))
typedef vector<int> vi;
ll gcd(ll a, ll b) {if (!b)return a; return gcd(b, a % b);}
ll power(ll x, ll y, ll p = INF) {ll res = 1; x %= p; while (y > 0) {if (y & 1)res = (res * x) % p; y = y >> 1; x = (x * x) % p;} return res;}
// Do Not use power when calculating powers of 2 (its inefficient)

void solve() {
    int n, k; cin >> n >> k;
    int res = 0;
    res += n * (k * (k + 1)) / 2;
    res += 100 * k * (n * (n + 1)) / 2;
    cout << res;
}

int32_t main() {

#ifndef ONLINE_JUDGE
    // for geting input form input.txt
    freopen("input.txt", "r", stdin);
    // for wrting output to output.txt
    freopen("output.txt", "w", stdout);
#endif

    May_the_fork_be_with_you
    int t = 1;
    int x = 1;
    // cin >> t;
    cout << fixed << setprecision(12);
    while (t--) {
        // cout << "Case #" << x << ": ";
        solve();
        x++;
    }

#ifndef ONLINE_JUDGE
    cerr << "Time Taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
#endif
}

#include <iostream>

using namespace std;

int main()
{
    int n,k;
    long long res=0;
    cin>>n>>k;
    for (int i=1;i<=n;i++)
        for (int j=1;j<=k;j++)
    {
        res+=100*i+j;
    }
    cout<<res;
    return 0;
}


#include<iostream>
using namespace std;

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

#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cerr << #x << " = " << (x) << endl
#define show2(x,y) cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cerr << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second)
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) (find(all(v),x)!=v.end())
#define incls(s,c) (s.find(c)!=string::npos)
#define lb(a,x) distance((a).begin(),lower_bound(all(a),(x)))
#define ub(a,x) distance((a).begin(),upper_bound(all(a),(x)))
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(all(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
//const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define YN {puts("YES");}else{puts("NO");}
inline int in() { int x; cin >> x; return x;}
inline ll lin() { ll x; cin >> x; return x;}
inline char chin() { char x; cin >> x; return x;}
inline string stin() { string x; cin >> x; return x;}
inline double din() { double x; cin >> x; return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const vector<T>& a) { ll res(0); for (auto&& x : a) res += x; return res;}
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; }
char itoa(int n) { return n + '0';}
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;}
const int dy[4] = {1, 0, -1,  0};
const int dx[4] = {0, 1,  0, -1};

int main () {
	ll x, y, a, b;
	cin >> x >> y >> a >> b;

	ll t = b/(a-1);
	ll now = x;
	ll ans = 0;
	while (now < y) {
		if (now <= t) {
			now *= a;
			ans++;
		}
		else {
			ans += (y-1-now)/b;
			break;
		}
	}
	if (now >= y) ans--;

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


// 解き直し.
// https://atcoder.jp/contests/abc191/editorial/610
// C++(GCC 9.2.1)
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define pb push_back
const LL INF = 202020202020202020;

struct edge{
    int n; // 次の頂点.
    LL c;  // 移動時間.
    bool operator < (const edge &E) const{ return c > E.c; }
};

LL d[2020][2020]; // i -> j の 移動時間.
LL ds[2020];      // i -> i の 移動時間.
LL ans[2020];     // 出力用.
vector<edge> G[2020];

int main(){

    // 1. 入力情報.
    int N, M;
    scanf("%d %d", &N, &M);
    rep(i, N) rep(j, N) d[i][j] = INF;
    rep(i, N) ds[i] = INF;
    rep(i, M){
        int a, b;
        LL c;
        scanf("%d %d %lld", &a, &b, &c);
        a--, b--;
        edge e;
        e.n = b;
        e.c = c;
        G[a].pb(e);                       // a -> b.
        if(a == b) ds[a] = min(ds[a], c); // a -> a.  (random_10.txt の WA回避？)
    }

    // 2. ダイクストラ法.
    // https://ja.wikipedia.org/wiki/ダイクストラ法
    auto dijkstra = [&](int s){
        // 1. 初期化.
        priority_queue<edge> pq;

        // 2. 始点設定.
        d[s][s] = 0;
        pq.push({s, 0LL});

        // 3. キュー pq が 空になるまで, 探索.
        while(!pq.empty()){
            // 4. 探索を継続するために, 頂点を取得.
            edge e = pq.top();
            pq.pop();
            int cn = e.n;
            LL cc = e.c;

            // 4. 各隣接する頂点について, 距離を確認し, 移動時間を更新.
            for(auto &g : G[cn]){
                int nn = g.n;
                LL nc = cc + g.c;

                // 5. 移動時間更新.
                if(d[s][nn] > nc) d[s][nn] = nc, pq.push({nn, nc});
            }
        }
        return;
    };

    // 3. 各頂点に対して, 最短経路を求める.
    rep(i, N) dijkstra(i);

    // 4. 出力用の情報を作成.
    rep(i, N){
        ans[i] = ds[i];
        rep(j, N) if(i != j) ans[i] = min(ans[i], d[i][j] + d[j][i]);
    }
    rep(i, N) if(ans[i] >= INF) ans[i] = -1;

    // 5. 出力.
    rep(i, N) printf("%lld\n", ans[i]);
    return 0;

}

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

#define endline         '\n'
#define vll             vector<ll>
#define vi              vector<int>
#define pll             pair<ll,ll>
#define pi              pair<int,int>
#define pb              push_back
#define fr(i,a,b)       for(int i=a;i<(int)b;i++)
#define rfr(i,a,b)      for(int i=a;i>=(int)b;i--)
#define ff              first
#define ss              second
#define all(x)          (x).begin(), (x).end()
#define INF             0x3f3f3f3f
#define debug(x)        cerr<<x<<endline
#define PI              3.14159265358979323846

typedef long long int ll;
const int N = 4e5+10;
const ll mod=1e9+7;

clock_t startTime;
double getCurrenttime() {
    return (double) (clock() - startTime) / CLOCKS_PER_SEC;
}
bool comp(pi a,pi b)
{
    if(a.first==b.first)return a.second<b.second;
    return a.first<b.first;
}

void solve()
{
    vector<pair<ll,pll>> v;
    int n;cin>>n;
    fr(i,0,n)
    {
        ll x,y,z; cin>>x>>y>>z;
        v.pb({x,{y,z}});
    }
    int c=0;
    sort(all(v));

    fr(i,0,n)
    {
        fr(j,i+1,n)
        {
            double a[]={0,0,0.00001,0.00001};
            double b[]={0,-0.00001,0,-0.00001};
            int f1=v[i].first;int f2=v[j].first;
            long double x1=0,y1=0,x2=0,y2=0;
            fr(k,0,4)
            {
                if(f1==k+1)
                {
                    x1=v[i].second.first+a[k],y1=v[i].second.second+b[k];
                }
            }
            fr(k,0,4)
            {
                if(f2==k+1)
                {
                    x2=v[j].second.first+a[k],y2=v[j].second.second+b[k];
                }
            }
            if(x1<=x2 and x2<=y1)c++;
            else if(x2<=x1 and x1<=y2)c++;
            else if(x1<=y2 and y2<=y1)c++;
            else if(x2<=y1 and y1<=y2)c++;
        }
    }
    cout<<c<<endline;
}

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

    #ifndef ONLINE_JUDGE
    startTime=clock();
    freopen("input.txt","r",stdin);
    freopen("output1.txt","w",stdout);
    // freopen("debug.txt", "w", stderr);
    #endif

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

    #ifndef ONLINE_JUDGE
    cout << "Time: " << getCurrenttime() * 1000 << " ms" << endline;
    #endif
}


#include <bits/stdc++.h>
#define rep(i,n)    for(int i=0;i<(n);++i)
#define repA(i,k,n) for(int i=k;i<=(n);++i)
#define repD(i,k,n)	for(int i=k;i>=(n);--i)
#define endl '\n'
#define print(b)	for(auto a:b) cout<<a<<' ';
#define printN(b)   for(auto a:b) cout<<a<<endl;
#define fin    		freopen("C:\\Users\\Nazmul Rahul\\Desktop\\in.txt", "r++", stdin)
#define fout   		freopen("C:\\Users\\Nazmul Rahul\\Desktop\\out.txt", "w++", stdout)
#define fastio    	ios::sync_with_stdio(false)
#define max(a,b)	((a)>(b)?(a):(b))
#define min(a,b)	((a)<(b)?(a):(b))
#define pb    		push_back
#define pob   		pop_back
#define ll 			long long int
#define MAX         2*100001
std::vector<ll> total(MAX);
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
	fin;
	fout;
#endif
	ll n, w;
	ll s, t, p;
	cin >> n >> w;

	for (ll i = 0; i < n; i++) {
		cin >> s >> t >> p;
		total[s] += p;
		total[t] -= p;
	}
	for (ll i = 1; i < MAX; i++) {
		total[i] += total[i - 1];
	}
	// cout << total[2] << endl;
	for (int i = 0; i < MAX; i++) {
		if (total[i] > w) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes";

	return 0;
}

//FEARLESS
//Fear is the path to the dark side.
//Fear leads to anger. Anger leads to hate.
//Hate leads to suffering. - Master Yoda

// Templates
// 1. tempgeo.cpp
// 2. tempunion.cpp
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#define pb push_back
#define pii pair <int, int>
#define pll pair <long long, long long>
#define endl '\n'
#define PI (2.0 * acos(0.0))
#define testcase ll T; cin >> T; for (ll tc = 1; tc <= T; tc++)
#define info pair<int, pii>
#define mkp make_pair
#define MAXN   1000002
const long long M = 1e5 + 10, M2 = 1e6 + 10, oo = 1e9 + 7;
const long long MC = (1<<20) + 5;
void precomp () {
	// precomputation here
}
void solve () {
	int n, s, d;
	cin >> n >> s >> d;
	for (int i = 0; i < n; i++) {
		int x, y;
		cin >> x >> y;
		if (x < s && y > d) {
			cout << "Yes" << endl;
			return;
		}
	}
	cout << "No" << endl;
}
int main () {
    //freopen("E:/newts/in.txt", "r", stdin);
    //freopen("E:/newts/out.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	precomp();
    //testcase {
        solve ();
    //}
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fast {ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
typedef long long int ll;
typedef string S;
#define M 1e18
#define AS 250005
#define sp cout<<' '
#define nw cout<<endl
#define rt return
#define __ template<typename T, typename... Types>
void in() {rt;} __ void in(T &a, Types&... b){cin>>(a); in(b...);}
void o() {rt;}  __ void o(T a, Types... b){cout<<(a);sp; o(b...);}
#define fr(Hi,a,n) for(ll Hi=a;Hi<=n;Hi++)
#define frm(Hi,a,n) for(ll Hi=n;Hi>=a;Hi--)
#define P pair<ll,ll>
#define vc vector<ll>
#define pb push_back
#define MP map<ll,ll>
bool sortin(const pair<ll,ll> &e,const pair<ll,ll> &f){return (e.first<f.first);}
bool POT(ll x){return x && (!(x&(x-1)));}
ll i,j,k,l,m,n,p,q,r,a,b,c,x,y,z,ts,mn=1e18,mod=1e9+7;
ll ar[AS],br[AS],xr[AS],tem[AS];

int main()
{
    fast;
    in(n,a,b);
    fr(i,0,n-1)
    {
        in(x,y);
        if(x<a and y>b)c=1;
    }
    if(c)o("Yes");
    else o("No");
}

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

int main() {
  int n,k,m,sum,z;
  sum=0;
  cin >> n >> k >> m;
  vector<int> A(n-1);
  for (int i=0;i<n-1;i++)cin >> A.at(i);

  for (int j=0;j<n-1;j++)sum+=A.at(j);

  if(sum+k<n*m)cout << "-1" <<endl;
  else{
    z=n*m-sum;
    if(z<=0)cout << 0 <<endl;
    else cout << z <<endl;
  }
}


#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int a,b,c;
	cin>>a>>b>>c;
	if(a==b)
	    cout<<c;
	else if(a==c)
	    cout<<b;
	else if(b==c)
	    cout<<a;
	else
	    cout<<"0";
	return 0;
}

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

int main() {
  int A,B,C;
  cin >> A >> B >>C;
  if(A*A+B*B<C*C) printf("Yes");
  else printf("No");
}


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

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  sort(a.rbegin(), a.rend());
  ll ans = 0;
  ll b = n - 1;
  rep(i, n) {
    ans += a[i] * b;
    b -= 2;
  }
  cout << ans << endl;
  return 0;
}

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

int main(void) {
  int n; cin >> n;
  long long a[n];
  long long b[n] = {};
  for (int i = 0; i < n; ++i) cin >> a[i];
  sort(a, a + sizeof(a)/sizeof(a[0]));
  for(int i = 0; i < n-1; ++i) {
    if(i == 0){
      b[n-1] = a[n-1]-a[n-2];
    } else {
      b[n-1-i] = b[n-i] + (i + 1)*(a[n-1-i] - a[n-2-i]);
    }
  }
  long long ans = 0;
  for(int i = 1; i < n; ++i) {
    ans += b[i];
  }
  cout << ans << "\n";
  return 0;
}


#include<bits/stdc++.h>

#define pl(a) " [" << #a << ": " << (a) << "] "
#define pts(a) " [" << #a << ": { first: " << (a.first) << ", second: " << (a.second) << "}] "

#define all(vi) vi.begin(), vi.end()
#define endl "\n"
#define ll long long

using namespace std;

pair<int, int> n4[4] { {1, 0}, {-1, 0}, {0, 1}, {0, -1} };
pair<int, int> n8[8] { {1, 0}, {-1, 0}, {0, 1}, {0, -1}, {1, 1}, {-1, -1}, {-1, 1}, {1, -1} };

ll int h(ll int x1, ll int y1, ll int x2, ll int y2) { return abs(x2 - x1) + abs(y2 - y1); }
ll int pow(ll int x, ll int y) { if (y == 0) return 1; if (y % 2 == 0) { ll int a = pow(x, y / 2); return a * a; } else { int a = pow(x, y / 2); return a * a * x; } return 0;}

template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v);
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "[" << p.first << ", " << p.second << "]"; }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) { cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";}
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) { cin >> p.first; return cin >> p.second; }

void set_in(string s) {
    if (s.length() > 0) {
        freopen ((s+".in").c_str(), "r", stdin);
        freopen ((s+".out").c_str(), "w", stdout);
    }
}

void solve() {
    ll int s; cin >> s;
    // s *= 2;
    set<ll int> fact;

    // find factors of 2 * n
    s *= 2;
    for (ll int i = 1; i * i <= s; i++) {
        if (s % i == 0) {
            fact.insert(i);
            fact.insert(s/i);
            // cerr << i << endl;
        }
    }
    s /= 2;

    ll int ans = 0;

    for (ll int n : fact) {
        ll int t = 2 * s / n;
        t -= (n - 1);
        if (t % 2 == 0) {
            ans++;
            // cout << pl(t / 2) << endl;
        }
    }

    cout << ans << endl;
}

int main() {
#ifndef DEBUG
    set_in("");
#endif
#ifdef DEBUG
    auto clock_start = chrono::high_resolution_clock::now();
    cout << endl;
#endif

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    solve();
    // int T; cin >> T;

    // for (int t = 1; t <= T; t++) {
    //     cout << "Case #" << t << ": ";
    //     solve();
    // }

    // Clock
#ifdef DEBUG
    auto clock_end = chrono::high_resolution_clock::now();
    cout << endl;
    chrono::duration<double> elapsed = clock_end - clock_start;
    cout << "Execution time: " << elapsed.count() << "s" << endl;
#endif
    return 0;
}

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

vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0;
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
        res.push_back({a, ex});
    }
    if (N != 1) res.push_back({N, 1});
    return res;
}

int main(){
  ll n;
  cin >> n;
  vector<pair<ll, ll> > res = prime_factorize(n);
  ll kis = 1;
  ll gus = 0;
  for(int i=0;i<res.size();i++){
    if(res[i].first%2==0) gus+=res[i].second;
    else kis*=(res[i].second+1);
  }
  cout << kis*2 << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, q;
    cin >> n >>q;
    vector<long long> a(n), c(n);
    long long x;
    for (int i=0; i <n; i++){
        cin >> x;
        if (i == 0){
            a.at(i) = x;
            c.at(i) = x-1;
        }
        else{
            a.at(i) = x;
            c.at(i) = c.at(i-1) + x - a.at(i-1) -1;
        }
    }
    vector<long long> k(q);

    for (auto& num : k){
        cin >> num;
    }

    for (auto num : k){
        if (c.at(n-1) <num){
            cout << a.at(n-1) + (num-c.at(n-1)) << endl;

        }
        else{
            auto index = lower_bound(c.begin(), c.end(),num) - c.begin();
            cout << a.at(index)-1-c.at(index) + num <<endl;
        }

    }
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
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;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, q; cin >> n >> q;
  vector<ll> A(n); rep(i, n) cin >> A[i];
  sort(all(A));
  vector<ll> K(q);
  rep(i, q) cin >> K[i];
  auto bsearch = [&](ll k) {
    auto test = [&](ll m) {
      return upper_bound(all(A), m) - begin(A) + k <= m;
    };
    ll ok = longinf, ng = 0;
    while(abs(ok-ng) > 1) {
      ll mid = (ok+ng)/2;
      (test(mid) ? ok : ng) = mid;
    }
    return ok;
  };
  rep(i, q) {
    cout << bsearch(K[i]) << endk;
  }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>
// using namespace __gnu_pbds;

#pragma GCC optimize("O3")
#ifdef LOCAL
#include "/Users/lbjlc/Desktop/coding/debug_utils.h"
#else
#define print(...) ;
#define printn(...) ;
#define printg(...) ;
#define fprint(...) ;
#define fprintn(...) ;
#endif

#define rep(i, a, b) for(auto i = (a); i < (b); i++)
#define rrep(i, a, b) for(auto i = (a); i > (b); i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back
// #define mp make_pair
#define fi first
#define se second
#define maxi(x, y) x = max(x, y)
#define mini(x, y) x = min(x, y)
// long long fact(long long n) { if(!n) return 1; return n*fact(n-1); }
// #define endl '\n'
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int get_random() {
    static uniform_int_distribution<int> dist(0, 1e9 + 6);
    return dist(rng);
}
#define solve_testcase int T;cin>>T;for(int t=1;t<=T;t++){solve(t);}

typedef unsigned long long ull;
typedef long long ll;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pdd> vpdd;
typedef vector<long long> vll;
#define bd(type,op,val) bind(op<type>(), std::placeholders::_1, val)

template<class T>
void make_unique(T & v) {
    sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());
}
int geti() { int x; cin >> x; return x; }
long long getll() { long long x; cin >> x; return x; }
double getd() { double x; cin >> x; return x; }
// pair<int, int> a(geti(), geti()) does not work
// pair<int, int> a({geti(), geti()}) works, since it uses initializer.

const int MAXN = 3e5 + 100;

void solve(int tt) {
    // cout<<"Case #"<<tt<<": ";
}

int main(int argc, char * argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    // solve_testcase;

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

    return 0;
}

/*
after dusk passed,
there is a starry sky.
*/
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define m_k make_pair
using namespace std;
const int N=2*1e5+100;
int n,a[N],b[N],p[N],vi[N],wh[N];
vector <pair<int,int> > ans;
priority_queue <pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > q;
inline int read()
{
	int f=1,x=0;char s=getchar();
	while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
	while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}
	return x*f;
}
signed main()
{
	n=read();
	for (int i=1;i<=n;i++) a[i]=read();
	for (int i=1;i<=n;i++) b[i]=read();
	for (int i=1;i<=n;i++) p[i]=read();
	for (int i=1;i<=n;i++)
	{
		if (p[i]==i){vi[i]=1;continue;}
		if (a[i]<=b[p[i]])
		{
			printf("-1\n");
			return 0;
		}
		q.push(m_k(a[i],i));wh[p[i]]=i;
	}
	while (!q.empty())
	{
		int x=q.top().second,y;q.pop();
		if (vi[x]) continue;
		vi[x]=1;y=wh[x];
		ans.push_back(m_k(x,y));
		wh[p[x]]=y;
		swap(p[x],p[y]);
		if (y==p[y]) vi[y]=1;
	}
	printf("%d\n",(int)ans.size());
	for (int i=0;i<(int)ans.size();i++) printf("%d %d\n",ans[i].first,ans[i].second);
}


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

int n,m,a[maxn],q,t;
char s[maxn];
char AB[2],AA[2],BA[2],BB[2];

LL ksm(LL a, LL b) {
    LL res = 1;
    while(b){
        if(b&1){
            res = res*a%mod;
        }
        a=a*a%mod;
        b>>=1;
    }
    return res;
}
LL dp[maxn];
void solve(){
    if(BB[0]=='B'){
        puts("1");return ;
    }
    if(BA[0]=='A') {
        cout<<ksm(2,n-3)<<endl;
    }
    else {
        dp[1]=dp[0]=1;
        fo(i,2,n-2){
            dp[i]=(dp[i-1]+dp[i-2])%mod;
        }
        printf("%lld\n",dp[n-2]);
    }
}
void solve2(){
    if(AA[0]=='A'){
        puts("1");return ;
    }
    if(BA[0]=='B'){
        cout<<ksm(2,n-3)<<endl;
    }
    else {
        dp[1]=dp[0]=1;
        fo(i,2,n-2){
            dp[i]=(dp[i-1]+dp[i-2])%mod;
        }
        printf("%lld\n",dp[n-2]);
    }

}

int main(){
//    op;
    read(n);
    cin>>AA>>AB>>BA>>BB;
    if(n<=3){
        puts("1");return 0;
    }
    if(AB[0]=='B'){
        solve();
    }
    else solve2();

    Please AC;
}

#include <bits/stdc++.h>

#define fi first
#define se second
#define ll long long
#define dl double long

using namespace std;

const int N = 1e4 + 7;
const long long mod = 1e9 + 7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n;
string s = "AB";
map < char , map < char , char > > c;

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

    cin >> n;
    cin >> c['A']['A'];
    cin >> c['A']['B'];
    cin >> c['B']['A'];
    cin >> c['B']['B'];
    vector < int > d(N , 1) , f( N , 0 ) , ff( N , 0 );
    ff[2] = ff[3] = 1;
    f[2] = f[3] = 1;
    for( int i = 4; i <= n; i++ ){
        ff[i] = ff[i - 1] + ff[i - 2];
        f[i] = f[i - 1] * 2;
        ff[i] %= mod;
        f[i] %= mod;
    }
    for( int nn = 2; nn <= 10; nn++ ){
        set < string > t;
        t.insert(s);
        for( int it = 3; it <= nn; it++ ){
            set < string > f;
            for( auto x : t ){
                for( int i = 0; i + 1 < (int)x.size(); i++ ){
                    string res = "";
                    for( int j = 0; j <= i; j++ ){
                        res += x[j];
                    }
                    res += c[x[i]][x[i + 1]];
                    for( int j = i + 1; j < (int)x.size(); j++ ){
                        res += x[j];
                    }
                    f.insert(res);
                }
            }
            t = f;
        }
        d[nn] = (int)t.size();
    }
    if( n <= 10 || d[10] == 1 )cout << d[n];
    else if( d[10] == d[9] + d[8] ){
        cout << ff[n];
    }else cout << f[n];
}


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

int main() {
  int h,w,n,m;
  cin >> h >> w >> n >> m;
  vector<int> a(n), b(n);
  vector<vector<int>> done(h, vector<int>(w,0));
  rep(i,n){
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
  }

  rep(i,m){
    int c, d;
    cin >> c >> d;
    c--; d--;
    done[c][d]--;
  }

  rep(i,n){
    if(!done[a[i]][b[i]]){
      int x = a[i];
      while(x >= 0 && done[x][b[i]] != -1) { done[x][b[i]] = 1; x--; }
      x = a[i];
      while(x < h && done[x][b[i]] != -1) { done[x][b[i]] = 1; x++; }
    }
  }

  rep(i,n){
    if(done[a[i]][b[i]] != 2){
      int y = b[i];
      while(y >= 0 && done[a[i]][y] != -1) { done[a[i]][y] = 2; y--; }
      y = b[i];
      while(y < w && done[a[i]][y] != -1) { done[a[i]][y] = 2; y++; }
    }
  }

  int ans = 0;
  rep(i,h){
    rep(j,w){
      if(done[i][j] > 0) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
typedef int64_t lint;
#define rep(i, n) for(int i=0; i<n; i++)
#define repx(i, l, n) for(int i=l; i<n; i++)
#define all(v) v.begin(), v.end()
#define show(x) cout << #x << ": " << x << endl;
#define list(x) cout << #x << ": " << x << "  ";
#define pb push_back
using vi = vector<lint>;
using vvi = vector<vector<lint>>;
template<class T> inline void vin(vector<T>& v) { rep(i, v.size()) cin >> v.at(i); }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline void drop(T x) { cout << x << endl; exit(0); }
template<class T> void vout(vector<T> v) { rep(i, v.size()) { cout << v.at(i) << ' '; } cout << endl; }
constexpr lint LINF = LLONG_MAX/2;

int N, M, TIME=clock();
vector<pair<int, string>> V;
vi C(8);
int sum = 0;
vector<string> S(20);

int total() {
	string s;
	int p = 0;
	set<string> t, u;
	rep(i, M) t.insert(V[i].second);
	vector<string> v(20);
	rep(i, N) v[i] = S[i];
	rep(q, 2) {
		rep(i, N) {
			s = v[i] + v[i];
			for (auto a : t) {
				bool f = false;
				rep(j, N) {
					if (a == s.substr(j, a.size())) {
						f = true;
						break;
					}
				}
				if (f) p += a.size();
				else u.insert(a);
			}
			t.clear();
			swap(t, u);
		}
		rep(i, N) { v[i].clear(); rep(j, N) v[i] += S[j][i]; }
	}
	return p;
}

int delta(int a, int b, int x, int y) {
	string s;
	int p = 0;
	set<string> t, u;
	rep(i, M) t.insert(V[i].second);
	rep(q, 2) {
		s = S[a] + S[a];
		for (auto r : t) {
			bool f = false;
			int c = (b+N-r.size()+1)%N;
			rep(j, r.size()) {
				if (r == s.substr(c+j, r.size())) {
					f = true;
					break;
				}
			}
			if (f) p += r.size();
			else u.insert(r);
		}
		t.clear();
		swap(t, u);
		swap(a, x);
	}
	rep(q, 2) {
		s = "";
		rep(i, N) s += S[i][b];
		rep(i, N) s += S[i][b];
		for (auto r : t) {
			bool f = false;
			int c = (a+N-r.size()+1)%N;
			rep(j, r.size()) {
				if (r == s.substr(c+j, r.size())) {
					f = true;
					break;
				}
			}
			if (f) p += r.size();
			else u.insert(r);
		}
		t.clear();
		swap(t, u);
		swap(b, y);
	}
	return p;
}

int delta_1(int a, int b) {
	string s;
	int p = 0;
	set<string> t, u;
	rep(i, M) t.insert(V[i].second);
	s = S[a] + S[a];
	for (auto r : t) {
		bool f = false;
		int c = (b+N-r.size()+1)%N;
		rep(j, r.size()) {
			if (r == s.substr(c+j, r.size())) {
				f = true;
				break;
			}
		}
		if (f) p += r.size();
		else u.insert(r);
	}
	t.clear();
	swap(t, u);

	s = "";
	rep(i, N) s += S[i][b];
	rep(i, N) s += S[i][b];
	for (auto r : t) {
		bool f = false;
		int c = (a+N-r.size()+1)%N;
		rep(j, r.size()) {
			if (r == s.substr(c+j, r.size())) {
				f = true;
				break;
			}
		}
		if (f) p += r.size();
		else u.insert(r);
	}
	t.clear();
	swap(t, u);
	return p;
}

int main() {
	cin >> N >> M;
	string s;
	rep(i, M) {
		cin >> s;
		V.pb({s.size(), s});
		rep(j, s.size()) C[s[j]-'A']++;
	}
	rep(i, 8) sum += C[i];
	rep(i, 7) C[i+1] += C[i];
	sort(all(V));

	int a=0, b=0, c=0, x, y, z;
	rep(i, N) {
		rep(j, N) {
			x = rand()%sum;
			rep(k, 8) {
				if (x < C[k]) {
					S[i] += 'A'+k;
					break;
				}
			}
		}
	}
	// show(total())
	int count = 0;
	while (true) {
		count++;
		a = rand()%N;
		b = rand()%N;
		if (count%5 == 0) {
			y = S[a][b]-'A';
			x = y;
			while (x == y) x = rand()%8;
			c = delta_1(a, b);
			S[a][b] = 'A'+x;
			z = delta_1(a, b);
			if (c > z) S[a][b] = 'A'+y;
		} else {
			x = rand()%N;
			y = rand()%N;
			c = delta(a, b, x, y);
			swap(S[a][b], S[x][y]);
			z = delta(a, b, x, y);
			if (c > z) swap(S[a][b], S[x][y]);
		}
		// list(c)list(z) show(total())
		if (clock()-TIME > 2.95 * CLOCKS_PER_SEC) break;
	}
	// show(count)
	rep(i, N) std::cout << S[i] << '\n';
}


#include <bits/stdc++.h>
using namespace std;
int n,m;
int dist[2010][2010];
int dp[2010][2010];
vector<int> v[2010];
int main()
{
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int x,y,z;
		cin>>x>>y>>z;
		if(!dist[x][y]||dist[x][y]>z)
		dist[x][y]=z;
	}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			if(dist[i][j])
				v[i].push_back(j);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			dp[i][j]=1e9;
	for(int i=1;i<=n;i++)
	{
		dp[i][i]=0;
		queue<int> q;
		q.push(i);
		while(!q.empty())
		{
			int x=q.front();
			q.pop();
			for(int j=0;j<v[x].size();j++)
				if(dp[i][v[x][j]]>dp[i][x]+dist[x][v[x][j]])
				{
					dp[i][v[x][j]]=dp[i][x]+dist[x][v[x][j]];
					q.push(v[x][j]);
				}
		}
	}
	for(int i=1;i<=n;i++)
	{
		int ans=1e9;
		for(int j=1;j<=n;j++)if(dist[j][i])ans=min(ans,dist[j][i]+dp[i][j]);
		if(ans==1e9)cout<<-1<<endl;
		else cout<<ans<<endl;
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    const int INF = 1e9;
    int n, m;
    cin >> n >> m;
    vector<vector<pii>> v(n);
    vector<int> self(n,INF);
    REP(i,m) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        if (a == b) self[a] = min(self[a],c);
        else v[a].emplace_back(c,b);
    }

    auto dijkstraToAll = [&](const int from) {
        priority_queue<pii,vector<pii>,greater<pii>> pq;
        vector<bool> visit(n);
        vector<int> ret(n,INF);
        for (auto p : v[from]) pq.push(p);
        visit[from] = true;
        while(!pq.empty()) {
            pii p = pq.top();
            pq.pop();
            if (visit[p.second]) continue;
            visit[p.second] = true;
            ret[p.second] = p.first;
            for(auto [c,b]:v[p.second]) {
                if (!visit[b]) pq.push({p.first+c,b});
            }
        }
        return ret;
    };

    vector<vector<int>> len;
    REP(i,n) len.push_back(dijkstraToAll(i));
    REP(i,n) {
        int ans = self[i];
        REP(j,n) ans = min(ans,len[i][j]+len[j][i]);
        if (ans <INF) OUT(ans)
        else OUT(-1)
    }

    return 0;
}


//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <array>
#include <unordered_map>
#include<unordered_set>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<complex>
#include<fstream>
#include<assert.h>

#include<stdio.h>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, double> pid;
typedef pair<double, int> pdi;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;

const double EPS = 1e-9;

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

	int N;
	cin >> N;

	int ans = 0;

	vector<pii> P(N);
	rep(i, 0, N)
	{
		cin >> P[i].first >> P[i].second;
	}

	rep(i, 0, N)rep(j, i + 1, N)
	{
		int dx = P[j].first - P[i].first;
		int dy = P[j].second - P[i].second;

		if (dx < 0)
		{
			dx *= -1;
			dy *= -1;
		}

		if (-dx <= dy && dy <= dx)
		{
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}

#include<bits/stdc++.h>

using namespace std;

#define int long long int
int fun(int a)
{
	int ret=0;
	while(a>0)
	{
		ret+=a%10;
		a=a/10;
	}
	return ret
;}

main()
{

int n;
cin>>n;
float x[n],y[n];
for(int i=0;i<n;i++)
{
	cin>>x[i]>>y[i];
}
int cou=0;
for(int i=0;i<n;i++)
{
	for(int j=i+1;j<n;j++)
	{
		float num=(y[i]-y[j])/(x[i]-x[j]);
		if(num<=1&&num>=-1)
		{
			cou++;
		}
	}
}
cout<<cou<<endl;
}