//@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_popcount(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); }
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 k;
  ll ans=0;
  cin>>k;
  rep(i,1,k+1){
    rep(j,1,k+1){
      if(i*j>k)break;
      ans+=k/(i*j);
    }
  }
  cout<<ans;
}

#include "bits/stdc++.h"
#include <chrono>
#include <random>
#define lli long long int
using namespace std;
#define mod 1000000007
#define mod1 998244353
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define INF 1000000000
#define common cout << "Case #" << w+1 << ": "
#define MAXN 200000

int main()
{
    int k;
    cin >> k;
    vector<int>v;
    for(int i=1;i<=k;i++)
    {
        for(int j=1;j<=k;j++)
        {
            if(i*j<=k)
                v.push_back(i*j);
            else
                break;
        }
    }
    sort(v.begin(),v.end());
    lli ans=0;
    for(int i=1;i<=k;i++)
    {
        for(int j=0;j<v.size();j++)
        {
            if(i*v[j]<=k)
                ++ans;
            else
                break;
        }
    }
    cout << ans << "\n";
}


#include <bits/stdc++.h>
using namespace std;
#define LL long long
//#define MOD 1000000007
#define MOD 998244353
#define INF 1000000000000000000
#define VE vector
#define VL vector<LL>
#define VVL VE<VL>
#define VVVL VE<VVL>
#define LD long double
#define PB push_back
#define POB pop_back
#define FOR(i,a,k) for(LL i=a;i<k;i++)
#define rep(i,k) FOR(i,0,k)
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define coutl cout<<fixed<<setprecision(15)//

#define MI modint<MOD>
template<int mod>struct modint{
	int x;
	modint():x(0){}
	modint(LL n):x(n>=0?n%mod:(mod-(-n)%mod)%mod){}
	modint &operator+=(const modint &n){if((x+=n.x)>=mod)x-=mod;return *this;}
	modint &operator-=(const modint &n){if((x+=mod-n.x)>=mod)x-=mod;return *this;}
	modint &operator++(){*this+=1;return *this;}
  modint &operator--(){*this-=1;return *this;}
	modint &operator*=(const modint &n){x=(int)((LL)x*n.x%mod);return *this;}
	modint &operator/=(const modint &n){*this*=n.inv();return *this;}
	modint operator-()const{return modint(-x);}
	modint operator+(const modint &n)const{return modint(*this)+=n;}
	modint operator-(const modint &n)const{return modint(*this)-=n;}
	modint operator++(int){modint ret(*this);*this+=1;return ret;}
  modint operator--(int){modint ret(*this);*this-=1;return ret;}
	modint operator*(const modint &n)const{return modint(*this)*=n;}
	modint operator/(const modint &n)const{return modint(*this)/=n;}
	bool operator<(const modint &n)const{return x<n.x;}
	bool operator>(const modint &n)const{return x>n.x;}
	bool operator<=(const modint &n)const{return x<=n.x;}
	bool operator>=(const modint &n)const{return x>=n.x;}
	bool operator!=(const modint &n)const{return x!=n.x;}
	bool operator==(const modint &n)const{return x==n.x;}
	friend istream &operator>>(istream &is,modint &n){LL l;is>>l;n=modint<mod>(l);return is;}
	friend ostream &operator<<(ostream &os,const modint &n){return os<<n.x;}
	int getmod(){return mod;}
	modint inv()const{int a=x,b=mod,c=1,d=0,n;while(b){n=a/b;swap(a-=n*b,b);swap(c-=n*d,d);}return modint(c);}
	modint pow(LL n)const{modint ret(1),m(x);while(n){if(n&1)ret*=m;m*=m;n>>=1;}return ret;}
};

LL nanjo(LL a,LL n){//N=nanjo(a,n)AのNjooo;
	LL ret=1;
	for(LL i=0;i<n;i++){
		ret*=a;
	}
	return ret;
}

void YesNo(bool f){
	if(f)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

LL kakuketa(LL n){//各桁の和を求める
	LL a=0;
	while(n>0){
		a=a+n%10;
		n=n/10;
	}
	return a;
}

VL yakusuu(LL N){
	LL M=0;
	VL ret;
	for(LL i=0; i<N; i++){
		M++;
		if(M>N/M){
			for(LL i=0; i<N; i++){
				M--;
				if(M==0){
					return ret;
				}
				if(M*M==N){
					continue;
				}
				if(N%M==0){
					ret.PB(N/M);
				}
			}
		}
	  if(N%M==0){
		  ret.PB(M);
		}
	}
	return ret;
}

int main(){
	LL N,M;
	cin>>N>>M;
	cout<<N/M<<endl;
}

#include<iostream>
main(){
  int x,y;
  scanf("%d%d",&x,&y);
  printf("%d",(6-x-y)%3);
}


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

int main(){
  int H, W, X, Y;
  cin >> H >> W >> X >> Y;
  vector<string> S(H);
  rep(i, H) cin >> S.at(i);

  int ans = 1;

  for(int i = 1; i < H; i++){
    if(X + i <= H && S.at(X + i -1).at(Y - 1) == '.'){
      ans++;
    }
    else break;
  }

  for(int i = 1; i < H; i++){
    if(X - i > 0 && S.at(X - i -1).at(Y - 1) == '.'){
      ans++;
    }
    else break;
  }

  for(int i = 1; i < W; i++){
    if(Y + i <= W && S.at(X -1).at(Y + i - 1) == '.'){
      ans++;
    }
    else break;
  }

 for(int i = 1; i < W; i++){
    if(Y - i > 0 && S.at(X -1).at(Y - i - 1) == '.'){
      ans++;
    }
    else break;
  }

  cout << ans << endl;
}

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

int main(){
    int h,w,x,y;
    cin>>h>>w>>x>>y;
    x--;y--;
    swap(x,y);
    vector<string> s(h);
    for(int i=0;i<h;i++){
        cin>>s[i];
    }
    int ans=1;
    for(int i=1; x+i<w && s[y][x+i]!='#' ;i++)ans++;
    for(int i=1; x-i>=0 && s[y][x-i]!='#' ;i++)ans++;
    for(int i=1; y+i<h && s[y+i][x]!='#' ;i++)ans++;
    for(int i=1; y-i>=0 && s[y-i][x]!='#' ;i++)ans++;
    cout<<ans<<endl;
    return 0;
}


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

int main() {
    int N, Q; cin >> N;
    vector<int> A(N), T(N);
    REP(i, 0, N) cin >> A[i] >> T[i];

    cin >> Q;
    vector<ll> X(Q);
    REP(i, 0, Q) cin >> X[i];

    set<ll> S;
    REP(i, 0, Q) S.insert(X[i]);

    ll offset = 0;
    REP(i, 0, N) {
        if (T[i] == 1) {
            offset += A[i];
        } else if (T[i] == 2) {
            auto itr = S.lower_bound(A[i] - offset);

            bool deleted = false;
            auto jtr = S.begin();
            while (jtr != itr) {
                jtr = S.erase(jtr);
                deleted = true;
            }
            if (deleted) {
                S.insert(A[i] - offset);
            }
        } else {
            auto itr = S.lower_bound(A[i] - offset);

            bool deleted = false;
            while (itr != S.end()) {
                itr = S.erase(itr);
                deleted = true;
            }
            if (deleted) {
                S.insert(A[i] - offset);
            }
        }
    }
    // for (auto x : S) cout << x << " ";
    // cout << endl;

    REP(i, 0, Q) {
        auto itr = S.lower_bound(X[i]);
        if (itr != S.begin() && (itr == S.end() || *itr > X[i])) itr = prev(itr);
        // cout << "# i : " << i << ", X[i] : " << X[i] << ", itr : " << *itr << endl;
        cout << *itr + offset << endl;
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
typedef pair<int,int> P;
typedef long long ll;
const int INF = 1001001001;
const ll INFL = 1e17;
const int MOD = 1e+9+7;

int main(){
    int n,k;
    ll ans = 0;
    cin >> n >> k;
    vector<vector<int>> t(n,vector<int>(n));
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            cin >> t[i][j];
        }
    }
    vector<int> perm(n-1);
    for(int i=0; i<n-1; i++){
        perm[i] = i;
    }
    do{
        int now = 0;
        int prev;
        ll sum = 0;
        for(int i=0; i<n-1; i++){
            prev = now;
            now = perm[i]+1;
            sum += t[prev][now];
        }
        sum += t[now][0];
        if(sum == k) ans++;
    }while(next_permutation(perm.begin(),perm.end()));
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
//#include <atcoder/all>
#ifndef LOCAL
#pragma GCC target("arch=skylake-avx512")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif
using namespace std;

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string &s) {
  return '"' + s + '"';
}

string to_string(const char *s) {
  return to_string((string)s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " +
         to_string(get<3>(p)) + ")";
}

void debug_out() {
  cerr << endl;
}

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define dbg(...) 42
#endif

const int MAX = 1'000'001;

bool is_prime[MAX + 1];
int min_factor[MAX + 1];
vector<int> primes;

ll f(ll y, ll R, ll i) {
  return R / y - i / y;
}

void solve(long long L, long long R) {
  fill_n(is_prime, MAX + 1, true);
  is_prime[0] = is_prime[1] = false;
  min_factor[0] = 0;
  min_factor[1] = 1;
  for (int i = 2; i <= MAX; ++i) {
    if (is_prime[i]) {
      min_factor[i] = i;
      for (long long j = static_cast<long long>(i) * i; j <= MAX; j += i) {
        is_prime[j] = false;
        if (min_factor[j] == 0)
          min_factor[j] = i;
      }
    }
  }
  ll ans = 0;
  FOR(i, max(2ll, L), R) {
    set<ll> s;
    auto j = i;
    while (j > 1) {
      auto k = min_factor[j];
      s.insert(k);
      j = j / k;
    }
    vector<ll> v(s.begin(), s.end());
    ll a = -f(i, R, i);
    FOR(k, 1, 1 << v.size()) {
      int count = __builtin_popcount(k);
      ll y = 1;
      REP(l, v.size()) {
        if ((k >> l) & 1) {
          y *= v[l];
        }
      }
      a += (count % 2 == 1 ? +1 : -1) * f(y, R, i);
    }
    ans += a;
  }
  cout << ans * 2 << endl;
}

int main() {
  long long L;
  std::scanf("%lld", &L);
  long long R;
  std::scanf("%lld", &R);
  solve(L, R);
  return 0;
}

#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define SHOW1d(v,n) {REP(W,n)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {REP(aaa,i){REP(bbb,j)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007LL

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

template<typename T>
void show_vector(vector<T> v) {
	for (auto ele: v)cout << ele << " " ;cout << endl;
}

template<typename T>
void show_vector(vector<vector<T>> v) {
	for (auto ele: v)show_vector(ele);
}

template<typename T>
void show_vector(vector<vector<vector<T>>> v) {
	for (auto ele: v) {
		show_vector(ele);
		cout << endl;
	}
}

vector<vector<P>> v(200200);
ll mp[2];
ll ans;

void dfs(int now, int pre, ll val, ll shift) {
	mp[val > 0]++;
	REP(i, v[now].size()) {
		if (v[now][i].FI == pre) continue;
		dfs(v[now][i].FI, now, val ^ (v[now][i].SE & (1LL << shift)), shift);
	}
}

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

	ll n;cin >> n;
	REP(i, n-1) {
		ll a, b, w;cin >> a >> b >> w;
		a--;b--;
		v[a].EB(b, w);
		v[b].EB(a, w);
	}

	REP(i, 60) {
		mp[0] = 0;
		mp[1] = 0;
		dfs(0, -1, 0, i);
		ans += ((1LL << i) % MOD) * (mp[0] * mp[1] % MOD) % MOD;
		ans %= MOD;
	}

	cout << ans << 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
#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
#define M 1000000007
#define N 100010
//#define endl '\n'

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

int findPow(int i,int p,int m){
	if(p==0){
		return(1);
	}
	int res=findPow(i,p/2,m);
	if(p%2==0){
		return((res*res)%m);
	}
	else{
		return((((res*res)%m)*i)%m);
	}
}

int modInverse(int val,int m){
	return(findPow(val,m-2,m));
}

void solve(){

	string s;
	cin >> s;
	int cnt=0,n=s.length();
	for(int i=0;i<=n-4;i++){
		string a="ZONe";
		int flag=0;
		for(int j=0;j<4;j++){
			if(s[i+j]!=a[j]){
				flag=1;
				break;
			}
		}
		if(flag==0){
			cnt++;
		}
	}
	cout << cnt << endl;
}

signed main(){

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

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

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

typedef long double ld;
const ll MOD=1000000007;
const ll MODA=998244353;
ll vx[4]={0,1,0,-1};
ll vy[4]={1,0,-1,0};
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
long long gcd(long long a,long long b){
    ll gcdmax=max(a,b);
    ll gcdmin=min(a,b);
    while(true){
        if(gcdmax%gcdmin==0)break;
        else gcdmax%=gcdmin;
        swap(gcdmin,gcdmax);
    }
    return gcdmin;
}
ll pow(ll N,ll P,ll M){
    if(P==0)return 1;
    else if(P%2==0){
        ll t=pow(N,P/2,M);
        return t*t%M;
    }
    else return N*pow(N,P-1,M)%M;
}
vector<ll> find_divisor(ll N){
  ll k=1;
  while(k*k<=N){
    k++;
  }
  vector<ll> A(1);
  rep(i,k){
    if(i==1)A.at(0)=1;
    else if(i>=2){
      if(N%i==0)A.push_back(i);
    }
  }
  ll t=0;
  t=A.size();
  rep(i,t){
    if(A.at(t-i-1)*A.at(t-i-1)!=N)A.push_back(N/A.at(t-1-i));
  }
  return A;
}
vector<ll> fac;
vector<ll> finv;
vector<ll> inv;
void COMinit(ll N,ll P){
    rep(i,N+1){
        if(i==0){
            fac.push_back(1);
            finv.push_back(1);
            inv.push_back(1);
        }
        else if(i==1){
            fac.push_back(1);
            finv.push_back(1);
            inv.push_back(1);
        }
        else{
            fac.push_back(fac.at(i-1)*i%P);
            inv.push_back(P-inv.at(P%i)*(P/i)%P);
            finv.push_back(finv.at(i-1)*inv.at(i)%P);
        }
    }
}

ll COM(ll n,ll k,ll P){
    if(n<k)return 0;
    if(n<0||k<0)return 0;
    return fac.at(n)*(finv.at(k)*finv.at(n-k)%P)%P;
}

struct UnionFind {
    vector<ll> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(ll N) : par(N) { //最初は全てが根であるとして初期化
        for(ll i = 0; i < N; i++) par[i] = i;
    }

    ll root(ll x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(ll x, ll y) { // xとyの木を併合
        ll rx = root(x); //xの根をrx
        ll ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }
};

int main(){
    ll N;
    cin>>N;
    vector<ll> A(N);
    rep(i,N){
        cin>>A.at(i);
    }
    ll ans=0;
    rep(i,N){
        ll sum=0;
        for(ll j=i;j>=0;j--){
            if(A.at(j)>=A.at(i))sum+=A.at(i);
            else break;
        }
        for(ll j=i+1;j<N;j++){
            if(A.at(j)>=A.at(i))sum+=A.at(i);
            else break;
        }
        ans=max(ans,sum);
    }
    cout<<ans<<endl;
}


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

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

  ll ans = 0;
  int commaCnt = 1;

  bool exist = false;
  if (n >= 1000){
    exist = true;
  }
  while(exist){
    ll maxNum = pow(1000, commaCnt + 1) - 1;
    if(n > maxNum){
      ans += commaCnt * (maxNum - pow(1000, commaCnt) + 1);
    } else {
      ans += commaCnt * (n - pow(1000, commaCnt) + 1);
      exist = false;
    }
    commaCnt++;
  }
  cout << ans << endl;
}

#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>
#include <random>

#define FOR_LT(i, beg, end) for (decltype(end) i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (decltype(end) i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (decltype(beg) i = beg; end <= i; i--)
#define REP(n)              for (decltype(n) repeat_index = 0; repeat_index < n; repeat_index++)

using namespace std;

template<typename T, size_t S>
T minval(const T(&vals)[S])
{
	T val = numeric_limits<T>::max();
	FOR_LT(i, 0, S) {
		val = min(val, vals[i]);
	}
	return val;
}

template<typename T, size_t S>
T maxval(const T(&vals)[S])
{
	T val = numeric_limits<T>::min();
	FOR_LT(i, 0, S) {
		val = max(val, vals[i]);
	}
	return val;
}

int64_t eval(array<int, 5>& assign, vector<array<int64_t, 32>>& vals)
{
	int64_t ans = INT64_MAX;

	FOR_LT(i, 0, 3) {
		int64_t s = 0;
		FOR_LT(j, 0, 5) {
			if (assign[j] == i) s += (1 << j);
		}
		if (s == 0) continue;

		int64_t ca = 0;
		FOR_LT(k, 0, vals.size()) {
			ca = max(ca, vals[k][s]);
		}
		ans = min(ans, ca);
	}
	return ans;
}

int64_t solve(int i, array<int, 5>& assign, vector<array<int64_t, 32>>& vals)
{
	if (i == 5) {
		return eval(assign, vals);
	}

	int64_t ans = 0;
	FOR_LT(j, 0, 3) {
		assign[i] = j;
		ans = max(ans, solve(i + 1, assign, vals));
	}
	return ans;
}

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

	int64_t n; cin >> n;
	vector<array<int64_t, 5>> as(n);
	FOR_LT(i, 0, n) {
		FOR_LT(j, 0, 5) {
			cin >> as[i][j];
		}
	}

	int64_t mv = 1;
	REP(5) mv *= 5;
	vector<array<int64_t, 32>> vals(n);
	FOR_LT(i, 0, n) {
		FOR_LT(j, 0, 32) {
			int64_t c = INT_MAX;
			FOR_LT(k, 0, 5) {
				if (j & (1 << k)) c = min(c, as[i][k]);
			}
			vals[i][j] = c;
		}
	}

	array<int, 5> assign;
	assign[0] = 0;
	cout << solve(1, assign, vals) << endl;

	return 0;
}


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

int main(){
	int a,b,x,y;
	cin>>a>>b>>x>>y;
	if(a==b){
		printf("%d",x);
	}
	else if(a>b){
		int ans1=(a-b+a-b-1)*x;
		int ans2=(a-b-1)*y+x;
		printf("%d",min(ans1,ans2));
	}
	else{
		int ans1=(b-a+1+b-a)*x;
		int ans2=(b-a)*y+x;
		printf("%d",min(ans1,ans2));
	}
}


#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"
#define N 55

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;

int prime[N];
vector<int> p;
int n;
int INF=1;

void eratosthenes(){
  rep(i,N) prime[i]=1;
  prime[0]=prime[1]=0;
  rep(i,N){
    if(prime[i]){
      for(int j=i+i;j<N;j+=i) prime[j]=0;
    }
  }
}

int solve(vector<int> x,int a,int num){
  //cout<<a<<endl;
  int ret=INF;
  if(a==p.size() ){

    rep(i,n){

      if(x[i]!=0) return ret;
    }
    return num;
  }
  ret=min(solve(x,a+1,num),ret);
  rep(i,n){
    if(x[i]%p[a]==0){
      x[i]=0;
    }
  }
  ret=min(solve(x,a+1,num*p[a]),ret);
  return ret;

}

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

  cin>>n;
  eratosthenes();
  rep(i,51){
    if(prime[i]==1) {INF*=i;p.push_back(i);}
  }
  vector<int> x(n);
  rep(i,n){
    cin>>x[i];
    //cout<<x[i]<<endl;
  }
  cout<<solve(x,0,1)<<endl;

  return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define ff first
#define ss second
#define INF (ll) (1e9)
#define mod (ll) (1e9 + 7)
#define endl "\n"
#define tt ll testcase; cin>>testcase; while(testcase--)

const int mxn = 1*(1e5) + 5;
ll n, m;

void solve(){
	char s, t;
	cin >> s >> t;
	if(s == 'Y') {
		if(t == 'A' || t == 'B' || t == 'C') {
			cout<<t;
		}
		else if(t == 'a') {
			cout << 'A';
		}else if(t == 'b') {
			cout << 'B';
		}else if(t == 'c') {
			cout << 'C';
		}
	} else {
		cout<<t;
	}
}

int main(){
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
     // tt
        solve();
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define MAXN 200005
#define lowbit(x) (x&-x)
#define reg register
#define mkpr make_pair
#define fir first
#define sec second
typedef long long LL;
typedef unsigned long long uLL;
const int INF=0x3f3f3f3f;
const int mo=998244353;
const LL jzm=2333;
const int iv2=499122177;
const double Pi=acos(-1.0);
typedef pair<int,int> pii;
const double PI=acos(-1.0);
template<typename _T>
_T Fabs(_T x){return x<0?-x:x;}
template<typename _T>
void read(_T &x){
	_T f=1;x=0;char s=getchar();
	while(s>'9'||s<'0'){if(s=='-')f=-1;s=getchar();}
	while('0'<=s&&s<='9'){x=(x<<3)+(x<<1)+(s^48);s=getchar();}
	x*=f;
}
template<typename _T>
void print(_T x){if(x<0){x=(~x)+1;putchar('-');}if(x>9)print(x/10);putchar(x%10+'0');}
int n,k,head[MAXN],tot,lim,hei[MAXN],sum;
struct edge{int to,nxt;}e[MAXN<<1];
void addEdge(int u,int v){e[++tot]=(edge){v,head[u]};head[u]=tot;}
void dosaka(int u,int fa){
	int mx1=0,mx2=0;if(!head[u]){hei[u]=0;return ;}
	for(int i=head[u];i;i=e[i].nxt){
		int v=e[i].to;if(v==fa)continue;dosaka(v,u);
		if(hei[v]>=0)mx1=max(mx1,hei[v]+1);
		else mx2=max(mx2,-hei[v]-1);
	}
	if(mx2>mx1)hei[u]=-mx2;else hei[u]=mx1;
	if(hei[u]>=lim||(u==1&&hei[u]>=0))hei[u]=-lim-1,sum++;
	//printf("dosaka%d:%d\n",u,hei[u]);
}
bool check(int mid){
	for(int i=1;i<=n;i++)hei[i]=0;
	lim=mid;sum=0;dosaka(1,0);return sum<=k;
}
signed main(){
	read(n);read(k);
	for(int i=1;i<n;i++){
		int u,v;read(u);read(v);
		addEdge(u,v);addEdge(v,u);
	}
	int l=1,r=n;if(k>=n){puts("0");return 0;}
	while(l<r){int mid=l+r>>1;if(check(mid))r=mid;else l=mid+1;}
	printf("%d\n",l);
	return 0;
}

/*
  /^--^\
  \____/
 /      \ _____  _ __  __ ____  _     ____   ____  _____
|        || ()_)| |\ \/ /| ===|| |__ / (__` / () \|_   _|
 \__  __/ |_|   |_|/_/\_\|____||____|\____)/__/\__\ |_|
|^|^\ \^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|
| | |\ \| | | | | | | | | | | | | | | | | | | | | | | | |
#####/ /#################################################
| | |\/ | | | | | | | | | | | | | | | | | | | | | | | | |
|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|*/
//#pragma GCC optimize("O4,unroll-loops,no-stack-protector")
#include <bits/stdc++.h>
#define int ll //__int128
#define double long double
using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define For(i,a,b)    for(int i=a;i<=b;i++)
#define Fors(i,a,b,s) for(int i=a;i<=b;i+=s)
#define Forr(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define L(id) (id*2+1)
#define R(id) (id*2+2)
#define LO(x) (x&(-x))

#define eb emplace_back
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define mkp make_pair

#define MOD (int)(1000000007)
#define INF (int)(1e12)
#define EPS (1e-7)

#ifdef NYAOWO
#define debug(...) do{\
	cerr << __LINE__ <<\
	" : ("#__VA_ARGS__ << ") = ";\
	_OUT(__VA_ARGS__);\
	cerr << flush;\
}while(0)
template<typename T> void _OUT(T x) { cerr << x << "\n"; }
template<typename T,typename...I>
void _OUT(T x,I ...tail) { cerr << x << ", "; _OUT(tail...); }
inline void USACO(const string &s) { cerr<<"USACO: "<<s<<"\n"; }
#else
#define debug(...)
inline void USACO(const string &s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}
#endif
inline void NYA(){ ios::sync_with_stdio(false); cin.tie(0); }

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
//int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
inline int gcd(int a,int b) { return __gcd(a,b); }
inline int lcm(int a,int b) { return a/gcd(a,b)*b; }
int fpow(int b,int p,const int &mod){
	int ans=1;
	while(p){
		if(p&1) ans=ans*b%mod;
		p/=2; b=b*b%mod;
	}
	return ans;
}
int fpow(int b,int p) { return fpow(b,p,MOD); }
template<typename T> inline void chmin(T &_a,const T &_b) { if(_b<_a) _a=_b; }
template<typename T> inline void chmax(T &_a,const T &_b) { if(_b>_a) _a=_b; }

int dis[1010][1010];
vector<int> adj[1010][26];

int32_t main(){
	NYA();
	//nachoneko so cute >/////<
	int n,m; cin>>n>>m;
	memset(dis,-1,sizeof(dis));
	priority_queue<pair<int,pii>,vector<pair<int,pii>>,greater<pair<int,pii>>> pq;
	//pair( dist , pair( s,t ) ) where s<=t
	For(i,1,n) pq.emplace(0,mkp(i,i));
	while(m--){
		int a,b; cin>>a>>b;
		char ch; cin>>ch;
		adj[a][ch-'a'].eb(b);
		adj[b][ch-'a'].eb(a);
		if(a>b) swap(a,b);
		pq.emplace(1,mkp(a,b));
	}
	while(!pq.empty()){
		int d=pq.top().F;
		int s=pq.top().S.F;
		int t=pq.top().S.S;
		pq.pop();
		if(dis[s][t]!=-1) continue;
		dis[s][t]=d;
		For(ch,0,25){
			for(auto &a:adj[s][ch]) for(auto &b:adj[t][ch]){
				int x=min(a,b),y=max(a,b);
				if(dis[x][y]==-1) pq.emplace(d+2,mkp(x,y));
			}
		}
	}
	cout<<dis[1][n]<<"\n";
	return 0;
}


  /*  Author :    */
#include <bits/stdc++.h>

using namespace std;

#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define pb push_back
#define ll long long
#define rep(i,n)  for(ll i=0;i<n;i++)
#define rep1(i,n)  for(ll i=n-1;i>=0;i--)

#define repi(i,n)  for(ll i=1;i<=n;i++)
#define mem(arr,x) memset(arr,x,sizeof(arr))

typedef vector<ll> vi;
typedef vector<char> vc;

#define mp make_pair
#define ss second

const int MAX=100005;
const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int min(int a,int b)
{
        if(a<b)
        return a;
        return b;
}
void solve()
{
 ll n;
 cin>>n;
 vector<pair<int,int>>v;
 ll a,q,ans=0;
 for(int i=0;i<n;i++)
 {
  cin>>a>>q;
  v.pb(mp(a,q));
 }
 for(int i=0;i<n;i++)
 {
  int a=v[i].first;
  int b=v[i].second;

  for(int j=i+1;j<n;j++)
  {
      int a1=v[j].first;
     int b1=v[j].second;
     if(a1==a)
      continue;
     float p=b1-b;
     float q=a1-a;
     float bb=(float)p/q;
     if(bb>=-1.0 && bb<=1.0)
      ++ans;

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

}

 int main()
{
  fast_io;
int T=1;
 //cin>>T;
while(T--)
{
  solve();

 }
}

#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>
#include <bitset>
#include <chrono>

using namespace std;

typedef long long ll;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  int n;
  cin >> n;
  vector <int> x(n), y(n);
  for (int i = 0; i < n; ++i) {
    cin >> x[i] >> y[i];
  }
  vector <int> ix(n), iy(n);
  iota(ix.begin(), ix.end(), 0);
  iota(iy.begin(), iy.end(), 0);
  sort(ix.begin(), ix.end(), [&] (int i, int j) {
    return x[i] < x[j];
  });
  sort(iy.begin(), iy.end(), [&] (int i, int j) {
    return y[i] < y[j];
  });
  vector <int> intr;
  for (int i = 0; i < min(n, 3); ++i) {
    intr.push_back(ix[i]);
    intr.push_back(iy[i]);
  }
  for (int i = 0; i < min(n, 3); ++i) {
    intr.push_back(ix[n - i - 1]);
    intr.push_back(iy[n - i - 1]);
  }
  sort(intr.begin(), intr.end());
  intr.resize(unique(intr.begin(), intr.end()) - intr.begin());
  vector <int> vals;
  for (int i : intr) {
    for (int j : intr) {
      if (i < j) {
        vals.push_back(max(abs(x[i] - x[j]), abs(y[i] - y[j])));
      }
    }
  }
  sort(vals.rbegin(), vals.rend());
  cout << vals[1] << '\n';
}


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

int n,m;
vector<int> adj[21];
int vis[21];

vector<int> nxt[21];
int par[21];
void dfs(int x) {
    vis[x]=1;
    for (int y : adj[x]) if (!vis[y]) {
        nxt[x].push_back(y);
        par[y]=x;
        dfs(y);
    }
}

int color[21];

int solve(int x) {
    int r = 0;
    for(int c = 0; c < 3; c++) {
        int ok=1;
        for (int z : adj[x]) if (color[z]==c) ok=0;
        if (!ok) continue;
        color[x]=c;
        int rc=1;
        for (int y : nxt[x]) {
            rc*=solve(y);
        }
        r+=rc;
    }
    color[x]=-1;
    return r;
}

int main() {
    cin >> n >> m;
    for(int i = 0; i < m; ++i){
        int a,b;
        cin >> a >> b;
        a--; b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    long long r=1;
    for(int i = 0; i < n; i++) {
        color[i]=-1;
        par[i]=-1;
    }
    for(int i = 0; i < n; i++)
        if (!vis[i]) {
            dfs(i);
            r*=solve(i);
    }
    cout << r << endl;
    return 0;
}

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
//#define puts sdf
using std::vector;
//using std::cout;
//using std::endl;
using std::sort;
using std::swap;
using std::min;
using std::max;

int read(){//int 无负数
	int h=0;char c=getchar();
	while(c<'0'||c>'9')c=getchar();
	while(c>='0'&&c<='9')h=(h<<1)+(h<<3)+c-'0',c=getchar();
	return h;
}

const int MAXN=200100;
int K,n;
struct Edge{
    int to;
    int nxt;
}edge[MAXN<<1];
int frm[MAXN];
int cnt_e;

void insert_e(int u,int v){
    cnt_e++;
    edge[cnt_e].to=v;
    edge[cnt_e].nxt=frm[u];
    frm[u]=cnt_e;
}
int Fa[MAXN];

int Rt,mns,S;
int siz[MAXN];
bool vis[MAXN];
void get_rt(int x,int ff){
    siz[x]=1;int mxs=0;
    for(int i=frm[x];i;i=edge[i].nxt){
        int v=edge[i].to;if(v==ff||vis[v])continue;
        get_rt(v,x);
        siz[x]+=siz[v];
        mxs=max(mxs,siz[v]);
    }
    mxs=max(mxs,S-siz[x]);
    if(mxs<mns)Rt=x,mns=mxs;
}

int Dt[MAXN];//点分树上的深度
int dis[MAXN][21]; //x到点分树上深度为D的那个祖先的距离
int mndis[MAXN];//距离他最近的点

void get_dis1(int U,int x,int ff,int dep,int D){
    dis[x][D]=dep;
    for(int i=frm[x];i;i=edge[i].nxt){
        int v=edge[i].to;if(v==ff||vis[v])continue;
        get_dis1(U,v,x,dep+1,D);
    }
}

void divide(int x,int D){//D是点分树上的深度
    vis[x]=true;
    Dt[x]=D;
    get_dis1(x,x,x,0,D);
    for(int i=frm[x];i;i=edge[i].nxt){
        int v=edge[i].to;if(vis[v])continue;

        S=siz[v],mns=siz[v],get_rt(v,v);
        Fa[Rt]=x;divide(Rt,D+1);
    }
}

void Modify(int x){
    int rt=x;
    for(;rt;rt=Fa[rt]){
        mndis[rt]=min(mndis[rt],dis[x][Dt[rt]]);
//        cout<<"MODIFY"<<x<<" "<<rt<<" "<<mndis[rt]<<endl;
    }
}

bool Query(int x,int mid){
    int rt=x;
    for(;rt;rt=Fa[rt]){
//    	cout<<"QUERY "<<x<<' '<<rt<<" "<<mndis[rt]<<' '<<dis[x][Dt[rt]]<<endl;
        if(mndis[rt]+dis[x][Dt[rt]]<=mid)return true;
    }
    return false;
}

int fa[MAXN][19];
int dep[MAXN];
int qwq[MAXN];//按深度排序
bool cmp(int x,int y){
	return dep[x]>dep[y];
}
void pre_dfs(int x,int ff){
	fa[x][0]=ff;dep[x]=dep[ff]+1;
	for(int i=1;i<=18;i++)fa[x][i]=fa[fa[x][i-1]][i-1];
	for(int i=frm[x];i;i=edge[i].nxt){
		int v=edge[i].to;if(v==ff)continue;
		pre_dfs(v,x);
	}
}

int get_fa(int x,int k){
	int nw=x;
	for(int i=0;i<=18;i++){
		if(k&(1<<i))nw=fa[nw][i];
	}
	return nw;
}

bool ch_ck(int mid){
//	cout<<"MID"<<':'<<mid<<endl;
	memset(mndis,0x3f,sizeof(mndis));
//	for(int i=1;i<=n;i++)mndis[i]=-0x3f3f3f3f;
	int cnt=0;
	for(int i=1;i<=n;i++){
		int x=qwq[i];
		if(Query(x,mid))continue;
		int fk=get_fa(x,mid);
		cnt++;Modify(fk);
//		cout<<"WORK"<<x<<" "<<fk<<endl;
		if(cnt>K)return false;
	}
	return true;
}

int get_ans(){
	int l=0,r=n;
	while(l+1<r){
		int mid=(l+r)>>1;
		if(ch_ck(mid)){
			r=mid;
		}
		else l=mid+1;
	}
	if(l==r)return r;
	if(ch_ck(l))return l;
	return r;
}

int main(){
	n=read(),K=read();
    for(int i=1;i<=n-1;i++){
        int u=read(),v=read();
        insert_e(u,v),insert_e(v,u);
    }
    S=n,mns=n,get_rt(1,1);
    divide(Rt,0);
    pre_dfs(1,1);
    for(int i=1;i<=n;i++)qwq[i]=i;sort(qwq+1,qwq+n+1,cmp);
//    for(int i=1;i<=n;i++)cout<<qwq[i]<<" ";puts("");
//    for(int i=1;i<=n;i++){
//    	for(int j=0;j<=18;j++)cout<<fa[i][j]<<" ";puts("");
//	}
    printf("%d\n",get_ans());
	return 0;
}


/*

weak        weak  we      ak   we  akwea        weak  we
  weak    weak    we      ak   weak    weak    we  ak we
    weakweak      we      ak   wea       ak   we    akwe
      wea         we      ak   we        ak   we    akwe
      wea         we      ak   we        ak   we    akwe
      wea          eak  weak   we        ak    we  ak we
      wea            wea  ak   we        ak     weak  we
                                                      we
we      ak     wea  ak       weak                     we
 we    ak    wea  weak     wea  eak                   we
  we  ak    we      ak   wea      wea         we      we
   weak     we      ak   we        we         we      we
    we      we      ak   we        we         we      we
   we        wea  weak    wea    wea          weak  weak
weak           wea  akw      weak                weak

*/
using namespace std;
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <utility>
#include <bitset>
#include <set>
#include <string>
#include <stack>
#include <iomanip>
#include <map>
#include <memory.h>
#include <deque>

#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define LL long long
#define mid (LB+RB)/2
#define vvl vector <vector<LL>>
#define vl vector <LL>
#define mkp make_pair

//iterators
#define iter(x) x.begin(),x.end()
#define aiter(a,n) a,a+n

//loops
#define REP(n) for (int ___=n;___--;)
#define REP0(i,n) for (int i=0;i<n;++i)
#define REP1(i,n) for (int i=1;i<=n;++i)
#define FOR(i,b,l,k) for (int i=b;i!=l;i+=k)
#define forEach(i,v) for (auto i:v)

/*
yungyao so weeeeeeeeeeeeeeeeeeeeeeeeeeak
8e7 so dian
FHVirus so dian
youou so dian
KYW so dian
hubert so dian
jass so dian
tingyu so dian
panda so dian
*/

//IO
#include <iostream>
#define theyRSOOOOOOOOODIAN ios_base::sync_with_stdio(false),cin.tie(0);
//testing some stuff, still under construction
//a lot more useful while debug
inline void print(vector <int> v){
    for (auto i:v)
        cout << i << ' ';
    cout << '\n';
}
inline void print(vector <int> v,char sep,char end){
    for (auto i:v)
        cout << i << sep;
    cout << end;
}

//constants
#include <climits>
const int maxn = 2020,mod = 0;

//workspace

inline void solve(){
    int n;
    pair<double,double> seg[maxn]{};

    cin >> n;
    REP1(i,n){
        int t;

        cin >> t >> seg[i].F >> seg[i].S;
        if (t == 2) seg[i].S -= 0.1;
        else if (t == 3) seg[i].F += 0.1;
        else if (t == 4) seg[i].S -= 0.1,seg[i].F += 0.1;
    }

    int cnt = 0;
    REP1(i,n){
        for (int j=i+1;j<=n;++j){
            auto [l1,r1] = seg[i]; auto [l2,r2] = seg[j];

            if (l1 <= r2 && l2 <= r1) ++cnt;
        }
    }
    cout << cnt;
}

signed main(){
    theyRSOOOOOOOOODIAN
    //for (int ;cin;)//use in multi-testcases and end in EOF problems
    //int t,i=1;for (cin >> t;i<=t;++i)//use in multi-testcases problems
    //cout << "Case #" << i << ": ",//use in Google, FB competitions
    solve();//always used
    return 0;
}

#include <bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//#include <atcoder/all>
using namespace std;
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a; i > -1; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a; i > b; --i)
#define repl(i, a) for (ll i = (ll)0; i < (ll)a; ++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll
#define fi first
#define se second
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll mod_998244353 = 998244353;
constexpr ll INF = 1LL << 60;

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

// using lll=boost::multiprecision::cpp_int;
// using
// Double=boost::multiprecision::number<boost::multiprecision::cpp_dec_float<128>>;//仮数部が1024桁
template <class T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}

ll mypow(ll x, ll n, const ll &p = -1)
{ // x^nをmodで割った余り

  if (p != -1)
  {
    x = (x % p + p) % p;
  }
  ll ret = 1;
  while (n > 0)
  {
    if (n & 1)
    {
      if (p != -1)
        ret = (ret * x) % p;
      else
        ret *= x;
    }
    if (p != -1)
      x = (x * x) % p;
    else
      x *= x;
    n >>= 1;
  }
  return ret;
}

struct myrand{
  random_device seed;
  mt19937 mt;
  myrand():mt(seed()){}
  int operator()(int a,int b){//[a,b)
    uniform_int_distribution<int>dist(a,b-1);
    return dist(mt);
  }
};

// using namespace atcoder;

//------------------------
//------------------------
//------------------------
//------------------------
//------------------------

template<typename T>
struct edge{
  int to;
  T c,d;
  edge(int to,T c,T d):to(to),c(c),d(d){}
};

template<typename T>
vector<T> dijkstra(vector<vector<edge<T>>> &g,int s){//sは始点
  const auto INFTY=numeric_limits<T>::max();//2回以上使うときはオーバーフローに気をつける(INFTYのときはif文で弾くなど)
  vector<T>dist(g.size(),INFTY);
  using P=pair<T,int>;//firstは最短距離,secondは頂点の番号
  priority_queue<P,vector<P>,greater<P>>pq;
  dist[s]=0;
  pq.emplace(dist[s],s);

  while(!pq.empty()){
    auto x=pq.top();pq.pop();
    int v=x.second;
    if(dist[v]<x.first)continue;//最短距離でなければ飛ばす

    for(auto e:g[v]){
      ll stop=max(0LL,ll(sqrt(e.d)-1));
      if(chmin(dist[e.to],dist[v]+e.c+e.d/(dist[v]+1))){
        pq.emplace(dist[e.to],e.to);
      }
      rep(i,2){
        if(dist[v]<stop&&chmin(dist[e.to],stop+e.c+e.d/(stop+1))){
          pq.emplace(dist[e.to],e.to);
        }
        stop++;
      }
    }
  }
  return dist;
}

void solve()
{
  int n,m;
  cin>>n>>m;
  vector<vector<edge<ll>>>g(n);
  rep(i,m){
    int a,b;
    ll c,d;
    cin>>a>>b>>c>>d;
    a--;b--;
    g[a].eb(b,c,d);
    g[b].eb(a,c,d);
  }
  auto d=dijkstra<ll>(g,0);
  if(d[n-1]==numeric_limits<ll>::max()){
    cout<<-1;
  }else{
    cout<<d[n-1]<<"\n";
  }
}

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


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

typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define ALL(obj) (obj).begin(), (obj).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

int main() {
    cout<<fixed<<setprecision(10);

    ll n; cin>>n;
    string s; cin>>s;

    vint a(n+1,0), t(n+1,0), c(n+1,0), g(n+1,0);
    rep(i,s.size()){
        a[i+1] = a[i];
        t[i+1] = t[i];
        c[i+1] = c[i];
        g[i+1] = g[i];
        if(s[i] == 'A') a[i+1]++;
        if(s[i] == 'T') t[i+1]++;
        if(s[i] == 'C') c[i+1]++;
        if(s[i] == 'G') g[i+1]++;
    }

    ll ans = 0;
    rep(l,n+1){
        rep(r,n+1){
            if(!(l < r)) continue;
            if(a[r] - a[l] == t[r] - t[l] and c[r] - c[l] == g[r] - g[l]) ans++;
        }
    }
    cout<<ans<<endl;

    return 0;

}

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(v) (v).begin() , (v).end()
#define sumof(v) accumulate(all(v), 0LL, plus<ll>())
#define maxof(v) max_element(all(v))
#define minof(v) min_element(all(v))
#define unique(a) a.resize(unique(a.begin(), a.end()) - a.begin())
#define inf INT_MAX
#define VI vector<ll>
#define VII vector<pair<ll, ll>>
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'

ll add(ll x, ll y){
    x+=y;
    while(x>=MOD) x-=MOD;
    while(x<0) x+=MOD;
    return x;
}

ll mul(ll x, ll y){
    return (x * 1ll * y) % MOD;
}

ll binpow(ll x, ll y){
    ll ans = 1;
    while(y>0){
        if(y%2==1){
            ans = mul(ans, x);
        }
        x = mul(x, x);
        y /= 2;
    }
    return ans;
}

ll divide(ll x, ll y){
    return mul(x, binpow(y, MOD-2));
}

int main(){
    FASTIO
    int testCases = 1, testCaseCount = 1;
    // cin>>testCases;
    while(testCases--){
        // cout<<"Case #"<<testCaseCount++<<":";
        ll N; cin>>N;
        string S; cin>>S;
        map<pair<int, int>, int> hMap;
        int C = 0, G = 0, A = 0, T = 0;
        ll ans = 0;
        for(int i=0; i<S.length(); ++i){
            if(S[i]=='C') C++;
            else if(S[i]=='G') G++;
            else if(S[i]=='A') A++;
            else T++;
            pair<int, int> temp = {C-G, A-T};
            if(hMap.find(temp)!=hMap.end()) ans += hMap[temp];
            if(hMap.find(temp)!=hMap.end()) hMap[temp]++;
            else hMap[temp] = 1;
            if(temp.first==0 && temp.second==0) ans++;
        }
        cout<<ans<<endl;
    }
}


#include <bits/stdc++.h>

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

using namespace std;

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

	int n; cin>>n;
	int cnt = 0;
	rep(i,n)
	{
		int tmp = i + 1;
		int f = 1;
		string o;
		while (tmp)
		{
			o.push_back((char)(tmp % 8 + '0'));
			tmp /= 8;
		}
		rep(i,o.size())
			if (o[i] == '7') {cnt++; f = 0; break;}
		tmp = i+1;
		string d = to_string(tmp);
		rep(i,d.size())
			if (d[i] == '7' && f) {cnt++; break;}
	}
	cout << n - cnt << "\n";
}

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

typedef long long ll;

ll mod=1e9+7;

vector<ll> p(3e5),r(3e5);

ll find(ll a){
    if(p[a]==a)
    return a;
    return p[a]=find(p[a]);
}

void join(ll a,ll b){
    a=find(a);
    b=find(b);

    if(r[a]==r[b]){
        r[a]++;
    }

    if(r[a]>r[b]){
        p[b]=a;
    }else{
        p[a]=b;
    }

}

int main() {

    ll n;
    cin>>n;

     ll a[n];

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

     for(int i=0;i<p.size();i++){
         p[i]=i;
     }

     int i=0,j=n-1;

     ll ans=0;

     while(i<j){
         if(a[i]!=a[j]){
             ll c=find(a[i]);
             ll d=find(a[j]);

             if(c==d){
                 i++;
                 j--;
                 continue;
             }else{
                 ans++;
                 join(a[i],a[j]);
             }
         }
         i++;
         j--;
     }

     cout<<ans;

 	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;
template <typename T> using vt = vector<T>;
template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb push_back
#define SZ(x) ((int)((x).size()))
#define EACH(x, a) for (auto& x: a)
#define FOR(i,s,n) for (ll i = (s); (i) < (n); ++i)
#define FORD(i,s,l) for (ll i = (s); (i) >= l; --i)
#define F first
#define S second
#define TC int __tc; cin >> __tc; FOR(case_num,1,__tc+1)
#define TEST(x,i) ((x)&(1ll<<(i)))
#define SET(x,i) ((x)|(1ll<<(i)))
#define FLIP(x,i) ((x)^(1ll<<(i)))
#define CLEAR(x,i) ((x)&~(1ll<<(i)))
const double pi = 4 * atan(1);
using ll = long long;
using pll = pair<ll, ll>;

mt19937 mt_rng(chrono::steady_clock::now().time_since_epoch().count());
ll randint(ll a, ll b) {
	return uniform_int_distribution<ll>(a, b)(mt_rng);
}

template<class T> bool umin(T& a, const T& b) {
	return b<a?a=b, 1:0;
}
template<class T> bool umax(T& a, const T& b) {
	return a<b?a=b, 1:0;
}

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

template<typename T1, typename T2>
std::ostream& operator<<(std::ostream &o, const pair<T1, T2> &p) {
	return o << p.F << " " << p.S;
}

template<typename T>
vector<int> argsort(const vector<T> &v, function<bool(T,T)> cmp) {
    vector<int> indices(v.size());
    iota(indices.begin(), indices.end(), 0);
    sort(indices.begin(), indices.end(),[&v,&cmp](int left, int right) -> bool {return cmp(v[left],v[right]);});
    return indices;
}

template<typename T>
vector<int> argsort(const vector<T> &v) {
    return argsort<T>(v, less<T>());
}

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

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

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

vector<vector<int>> adj;
vector<vector<pair<int,int>>> queries;
vector<int> counts;

void dfs(int u, vector<int> &ans, int p = 1, int d = 0) {
	vector<int> before;
	for (int i = 0; i < (int)queries[u].size(); i++) {
		before.pb(counts[queries[u][i].F]);
	}
	counts[d]++;
	for (auto &v : adj[u]) {
		if (v != p) {
			dfs(v, ans, u, d+1);
		}
	}
	vector<int> after;
	for (int i = 0; i < (int)queries[u].size(); i++) {
		after.pb(counts[queries[u][i].F]);
	}
	for (int i = 0; i < (int)queries[u].size(); i++) {
		ans[queries[u][i].S]=after[i]-before[i];
	}
}

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

	int n;
	cin >> n;
	adj.assign(n+1, {});
	queries.assign(n+1, {});
	counts.assign(n+1,0);

	for (int i = 2; i <= n; i++) {
		int p;
		cin >> p;
		adj[i].pb(p);
		adj[p].pb(i);
	}

	int q;
	cin >> q;
	vector<int> ans(q);
	for (int i = 0; i < q; i++) {
		int u, d;
		cin >> u >> d;
		queries[u].pb({d,i});
	}

	dfs(1, ans);

	print_vec(ans.begin(),ans.end(),"\n");

}

/**
 *    author:  FromDihPout
 *    created: 2021-06-05
**/

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

const int MAX_DEPTH = 2e5 + 5;
int t;
vector<vector<int>> adj;
vector<vector<int>> depth;
vector<int> tin, tout;

void dfs(int u, int d) {
    depth[d].push_back(t);
    tin[u] = t;
    t++;
    for (int v : adj[u]) {
        dfs(v, d + 1);
    }
    tout[u] = t;
}

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

    int n;
    cin >> n;
    adj.resize(n);
    for (int i = 1; i < n; i++) {
        int p;
        cin >> p;
        p--;
        adj[p].push_back(i);
    }

    t = 0;
    depth.resize(MAX_DEPTH);
    tin.resize(n);
    tout.resize(n);
    dfs(0, 0);

    int q;
    cin >> q;
    while (q--) {
        int u, d;
        cin >> u >> d;
        u--;

        vector<int> nodes = depth[d];
        int r = lower_bound(nodes.begin(), nodes.end(), tout[u]) - nodes.begin();
        int l = lower_bound(nodes.begin(), nodes.end(), tin[u]) - nodes.begin();
        cout << r - l << '\n';
    }
    return 0;
}


#include <bits/stdc++.h>
#include <bits/extc++.h>
#define double long double
#define rbtree __gnu_pbds::tree<int,__gnu_pbds::null_type,less<int>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>
#define int ll
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);
#define pb push_back
#define ALL(X) X.begin(),X.end()
#define F(i,n)  FF(i,0,n)
#define F1(i,n)  FF(i,1,n+1)
#define FF(i,n,m) for(int i=(int)n;i<(int)m;++i)
#ifndef LOCAL
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
#else
#endif // LOCOL
//#define mp make_pair
using namespace std;
//using namespace __gnu_pbds;
template<typename T> bool remax(T& a, const T& b) {return b>a?a=b,1:0;}
template<typename T> bool remin(T& a, const T& b) {return b<a?a=b,1:0;}
inline ostream& operator << (ostream& os,__int128_t a){if(a==0) {return (os<<'0');}bool flag=0;if(a<0) {a=-a,flag=1;}string s;while(a){s+=a%10+'0';a/=10;}s+=flag?"-":"";reverse(ALL(s));return os<<s;}
inline istream& operator >>(istream& is,__int128_t& a){string s;cin>>s;a=0;for(auto c:s) a=a*__int128_t(10)+__int128_t(c-'0');return is;}
template<typename T,typename P> inline ostream& operator << (ostream& os,pair<T,P> a){os<<a.first<<" "<<a.second; return os;}
template<typename T,typename P> inline istream& operator >> (istream& is,pair<T,P> &a){is>>a.first>>a.second; return is;}
using ll=long long;
using ull=unsigned long long;
using int128= __int128_t;
using uint128= __uint128_t;
using pii =pair<int,int>;
const double pi=acos(-1);
const int N=1E5+5;
const ll M=1000000000;
const ll INF_64=0x3f3f3f3f3f3f3f3f;
const int INF_32=0x3f3f3f3f;
const int16_t INF_16=0x3f3f;
const int klog=20;
const int mod=998244353;//1E9+7
const double eps=1E-8;
void gen(){
}

int d[N]{};
vector<pair<int,pii>> g[N];
int dis(int c,int d,int t){
    double l=0,r=1E14;
    F(_,100){
        double m1=l+(r-l)/3.0,m2=r-(r-l)/3.0;
        double mv1=t+m1+c+(d/(t+m1+1.0));
        double mv2=t+m2+c+(d/(t+m2+1.0));
        if(mv1==mv2) l=m1,r=m2;
        else if(mv1>mv2) l=m1;
        else r=m2;
    }
    int re=INF_64;
    int L=l,R=r;
    FF(j,L-3,R+3)
        if(j>=0)remin(re,t+j+c+(d/(t+j+1)));
    return re;
}
void sol(){
    int n,m;cin>>n>>m;
    priority_queue<pii,vector<pii>,greater<pii>> pq;
    memset(d,0x3f,sizeof(d));
    d[0]=0;pq.push({0,0});
    F(i,m){
        int a,b,C,D;cin>>a>>b>>C>>D;
        a--,b--;
        g[a].pb({b,{C,D}});
        g[b].pb({a,{C,D}});
    }
    while(pq.size()){
        auto [val,a]=pq.top();pq.pop();
        if(val!=d[a]) continue;
        for(auto &[b,tt]:g[a]){
            if(remin(d[b],dis(tt.first,tt.second,d[a])))
                pq.push({d[b],b});
        }
        assert(d[a]==val);
    }
    //F(i,n) cout<<d[i]<<" ";
    //cout<<"\n";
    assert(d[n-1]>=0);
    cout<<(d[n-1]>=INF_64?-1:d[n-1])<<"\n";
}
int32_t main(){
    #ifdef LOCAL
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    #endif // LOCAL
    IOS;
    int t=1;
    gen();
    //cin>>t;
    FF(i,1,t+1){
        //cout<<"Case #"<<i<<": ";
        sol();
    }
}


#include <bits/stdc++.h>
using namespace std;
vector<int> ar[2001];
set<pair<int,int>> s;
int visited[2001];
void dfs(int x,int source)
{
	visited[x]=1;
	for(auto it:ar[x])
	{
		if(!visited[it])
		{
			s.insert({source,it});
			dfs(it,source);

		}
	}
}
void solve()
{
int t=1;
//cin>>t;
while(t--)
{
int n,m,i;
cin>>n>>m;
int x,y;
for(i=1;i<=n;i++)
{
	s.insert({i,i});
}
for(i=0;i<m;i++)
{
	cin>>x>>y;
	ar[x].push_back(y);

}

for(i=1;i<=n;i++)
{
	memset(visited,0,sizeof(visited));
	dfs(i,i);
}
cout<<s.size()<<endl;

}

}
int main()
{
  ios::sync_with_stdio(0);
cin.tie(0);
solve();
cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
return 0;
}

#include "bits/stdc++.h"
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vll=vector<ll>;
using vvll=vector<vll>;
using pii=pair<int,int>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sor(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define pb push_back
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
//const int INF = 1123456789;
//const int mod = 1e9+7;
int n,m;
vvi g;
int ans=0;
vector<bool> checked;
void f(void){
    checked.clear();
    checked.resize(n);
}
void dfs(int now){
    checked[now]=true;
    for(auto a:g[now]) if(!checked[a]) dfs(a);
}
int main(){
    cin>>n>>m;
    g.resize(n);
    rep(i,m){
        int a,b; cin>>a>>b;
        a--; b--;
        g[a].pb(b);
    }
    rep(i,n){
        f();
        dfs(i);
        rep(j,n) if(checked[j]) ans++;

    }

    cout<<ans<<endl;
}


#include <bits/stdc++.h>
//#include <atcoder/all>
#define rep(i, n) for (int i=0; i < (n); i++)
using namespace std;
//using namespace atcoder;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int NIL = -1;
const int MAX = 10000;
const int MOD = 1000000007;
const double pi = 3.141592653589;

vector<map<char, int>> dict(5010);

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

    vector<string> ss(n+1, "");

    for (int i=0;i<n;i++){
        ss[i+1] = ss[i] + s[i];
    }
    for (int i=1;i<=n;i++){
        for (auto c : ss[i]){
            dict[i][c] += 1;
        }
    }

    int ans = 0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n+1;j++){

            if (dict[j]['T']-dict[i]['T'] == dict[j]['A']-dict[i]['A'] && dict[j]['C']-dict[i]['C'] == dict[j]['G']-dict[i]['G'])
                ans += 1;
        }
    }
    cout << ans << endl;

    return 0;
}

#include <vector>
#include <array>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);

    int n;
    cin >> n;

    vector<long long> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
    }
    vector<long long> sums(n + 1, 0);
    for (int i = 0; i < n; ++i) {
        sums[i + 1] = sums[i];
        if (i & 1) {
            sums[i + 1] += A[i];
        } else {
            sums[i + 1] -= A[i];
        }
    }

    map<long long,int> cnts;
    cnts[0] += 1;
    long long res = 0;
    for (int i = 0; i < n; ++i) {
        res += cnts[sums[i + 1]];
        cnts[sums[i + 1]] += 1;
    }

    cout << res << '\n';

    return 0;
}


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

int main(){
    string a;
    cin >> a;
    int p=0;
    int c = a.size();
    for(int i=0; i < c;i++){
        if(a[i]=='.') p = i;
    }
    if(p!=0) a = a.substr(0,p);
    // a.substr(0,(a.size()-p));
    cout << a << endl;
    return 0;
}

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

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

using ll = int64_t;
using ull = uint64_t;

int n[18];
/*
ある整数が3の倍数であるかどうかは、その数の各位の数を足した値が3の倍数であるかどうかで調べられます。
*/
int main() {
    string N;
    cin >> N;

    int index = 0;
    for (char c : N) {
        n[index++] = c - '0';
    }

    int S = N.size();
    int min_keta = 1000;
    for (ull i = 0; i < (1 << S); i++) {
        ull num = 0;
        int keta = 0;
        for (int j = 0; j < S; j++) {
            if (i & (1 << j)) {
                num += n[j];
                keta++;

                // cout << n[j] << ": " << num << endl;
                if ((num % 3) == 0) {
                    if ((S - keta) < min_keta) {
                        min_keta = (S - keta);
                    }
                }
            }
        }
    }
    if (min_keta == 1000) {
        cout << -1 << endl;
    } else {
        cout << min_keta << endl;
    }
}


#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

const int maxX = 2e5 + 1;
int divCount[maxX];

int main()
{
  int a, b;
  while (~scanf("%d %d", &a, &b))
  {
    memset(divCount, 0, sizeof(divCount));
    for (int i = a; i <= b; i++)
    {
      for (int j = 2, end = sqrt(i); j <= end; j++)
        if (i % j == 0)
        {
          divCount[j]++;
          if (i % (i / j) == 0 && j != i / j)
            divCount[i / j]++;
        }
      divCount[i]++;
    }

    int ans = 1;
    for (int i = 2; i < maxX; i++)
      if (divCount[i] > 1)
        ans = i;
    printf("%d\n", ans);
  }
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
int findMaxGCD(int arr[], int n)
{
    int high = 0;
    for (int i = 0; i < n; i++)
        high = max(high, arr[i]);

    int count[high + 1] = {0};
    for (int i = 0; i < n; i++)
        count[arr[i]]++;

    int counter = 0;

    for (int i = high; i >= 1; i--)
    {
        int j = i;
       counter = 0;

        while (j <= high)
        {
            // A multiple found

            if(count[j] >=2)
               return j;

           else if (count[j] == 1)
                counter++;

            // Incrementing potential
            // GCD by itself
            // To check i, 2i, 3i....
            j += i;

            // 2 multiples found,
            // max GCD found
            if (counter == 2)
                return i;
        }
    }
}
int main()
{
    int a,b;
    cin>>a>>b;
    int c[b-a+1];
    for(int i=0; i<b-a+1; i++)
    {
        c[i]=a+i;
    }
 /*   for(int i=0; i<b-a+1; i++)
    {
        cout<<c[i]<<" ";
    }
    cout<<endl;*/
    int n;
    n=b-a+1;
    cout << findMaxGCD(c, n);

    return 0;
}


#define _USE_MATH_DEFINES

#include <iostream>
#include <cstring>
#include <regex>
#include <cmath>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <unordered_set>
#include <queue>
#include <unordered_map>
#include <set>
#include <cassert>
#include <climits>

#pragma GCC optimize("O3")

using namespace std;
using ll = long long;
using ull = unsigned long long;

#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repd(i, n) for(ll i = (n) - 1ll; i >= 0; --i)
#define FOR(i, a, b) for(ll i = a; i < ll(b); ++i)
#define FORD(i, a, b) for(ll i = a; i > ll(b); --i)
#define foreach(i, itr) for(auto& i : (itr))
#define asort(arr, size) std::sort(arr, arr + size)
#define dsort(arr, size) std::sort(arr, arr + size, [](auto a, auto b) { return a > b; })
#define cauto const auto&
#define bit(n) (1LL << (n))

////////////////////////////////////
// ここから下に任意のコードを書く //
////////////////////////////////////

int main() {
    string S;
    cin >> S;
    deque<char> T;
    bool R = false;
    rep(i, S.size()) {
        if (S[i] == 'R') {
            R = !R;
        }
        else if (T.empty()) {
            T.push_back(S[i]);
        }
        else if (R) {
            if (T.front() == S[i]) {
                T.pop_front();
            }
            else {
                T.push_front(S[i]);
            }
        }
        else {
            if (T.back() == S[i]) {
                T.pop_back();
            }
            else {
                T.push_back(S[i]);
            }
        }
    }
    if (R) {
        for_each(T.rbegin(), T.rend(), [](char c) { cout << c; });
    }
    else {
        for (char c : T) {
            cout << c;
        }
    }
    cout << endl;
    return 0;
}

//ll abi[5000][5];
//ll dp[5000][3][5];
//
//ll getPower(int index) {
//    ll res = INT_MAX;
//    rep(i, 3) {
//        ll mx = 0;
//        rep(j, 5) {
//            mx = max(mx, dp[index][i][j]);
//        }
//        res = min(res, mx);
//    }
//    return res;
//}
//
//int main()
//{
//    int N;
//    cin >> N;
//    rep(i, N) cin >> abi[i][0] >> abi[i][1] >> abi[i][2] >> abi[i][3] >> abi[i][4];
//
//    dp[0][0][0] = abi[0][0];
//    dp[0][0][1] = abi[0][1];
//    dp[0][0][2] = abi[0][2];
//    dp[0][0][3] = abi[0][3];
//    dp[0][0][4] = abi[0][4];
//    FOR(i, 1, N) {
//        int index = -1;
//        rep(j, 3) {
//            rep(k, 5) {
//                dp[i][j][k] = dp[i - 1][j][k];
//            }
//        }
//        ll res = INT_MAX;
//        rep(j, 3) {
//            ll mx = 0;
//            rep(k, 5) {
//                mx = max(mx, dp[i][j][k]);
//            }
//            res = min(res, mx);
//        }
//    }
//
//    return 0;
//}

#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  deque<char> ans;
  cin >> s;
  int sw,i,size;
  sw=0;
  size=s.size();
  for(char c: s)
  {
  if(c=='R') sw++;
  else{
    if(ans.size()==0) ans.push_front(c);
    else if(sw%2==0) {if(c==ans.back()) ans.pop_back();
                 else ans.push_back(c);
                }
    else        {if(c==ans.front()) ans.pop_front();
                 else ans.push_front(c);
                }
   }
  }
  if(sw%2==1) reverse(ans.begin(),ans.end());
  string T;
    for(char c : ans){
      T.push_back(c);
    }
    cout << T << endl;

return 0;}


#include <bits/stdc++.h>

using namespace std;

int main(){
  int H, W;
  while(scanf("%d%d", &H, &W) > 0){
    int A[H][W], min_A = 110;

    for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
	scanf("%d", &A[i][j]);
	min_A = min(min_A, A[i][j]);
      }
    }

    int ans = 0;
    for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
	ans += A[i][j] - min_A;
      }
    }

    printf("%d\n", ans);
  }
}

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <array>
#include <cassert>
#include <optional>
#include <utility>
#include <vector>

template <class InputIterator>
std::ostream& range_output(std::ostream& os_arg, InputIterator first_arg, InputIterator last_arg){ if(first_arg != last_arg){ do{ os_arg << *(first_arg++); if(first_arg == last_arg) break; os_arg << ' '; } while(true); }  return os_arg; }
template <class Tp> std::ostream& operator << (std::ostream& os_arg, const std::vector<Tp>& arr_arg){ return range_output(os_arg, arr_arg.cbegin(), arr_arg.cend()); }
template <class Tp, std::size_t Size> std::ostream& operator << (std::ostream& os_arg, const std::array<Tp, Size>& arr_arg){ return range_output(os_arg, arr_arg.cbegin(), arr_arg.cend()); }
template <class S, class T> std::ostream& operator << (std::ostream& os_arg, const std::pair<S, T>& pair_arg){ return os_arg << '(' << pair_arg.first << ", " << pair_arg.second << ')'; }

#ifndef ONLINE_JUDGE
    template <typename Head> void dump_out(Head head_arg){ std::cerr << head_arg << '\n'; }
    template <typename Head, typename... Tail>
    void dump_out(Head head_arg, Tail... tail_args){ std::cerr << head_arg << ", "; dump_out(tail_args...); }
    #define dump(...) do { std::cerr << "[in line " << __LINE__ << "] " << #__VA_ARGS__ << " : "; dump_out(__VA_ARGS__); } while(false)
#else
    #define dump(...) (void(0))
#endif

int main(void){
    std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(16);
    int H, W; std::cin >> H >> W;
    int sum = 0;
    int m = std::numeric_limits<int>::max();
    for(int i = 0; i < H; ++i) for(int j = 0; j < W; ++j){
        int a; std::cin >> a;
        sum += a; if(m > a) m = a;
    }
    std::cout << (sum - (H * W * m)) << '\n';
    return 0;
}


#include <cstdio>
#include <algorithm>
using namespace std;
int n,a[31],f[31][31];long long ans=1e15;
void dfs(int las,int sum)
{
	if(las==n)
	{
		ans=min(ans,1ll*sum);
		return;
	}
	for(int i=las+1;i<=n;i++)
		dfs(i,sum^f[las+1][i]);
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
		for(int j=i;j<=n;j++)
			f[i][j]=f[i][j-1]|a[j];
	dfs(0,0);
	printf("%lld",ans);
}

        #include<bits/stdc++.h>

        using namespace std;

        #define FOR(i,a,b) for(int i = (a); i < (b); i++)
        #define RFOR(i,a,b) for(int i = (a) - 1; i>=(b);i--)
        #define rep(i,n) FOR(i,0,n)
        #define PB push_back
        #define SZ(a) (int)a.size()
        #define ALL(a) a.begin(), a.end()
        #define FILL(a, value) memset(a, value, sizeof(a))
        #define IOS ios_base::sync_with_stdio(0),cin.tie(0), cout.tie(0);

        typedef  long long LL ;
        typedef  vector<int > VI ;
        typedef vector<LL > VL;
        typedef pair<int,int > PII;
        typedef pair<LL,LL> PLL;

        const LL LINF = (LL)1e18 +47;
        const int INF =  (int)(1 << 30) + 100 ;
        const int MOD =(int)1e9 + 7 ;
        const int modulo = 998244353;
        const int nax =  3 * (int)1e5 + 10;
        const double EPS = 1e-7;
        const double PI = acos(-1.0);

        int a[nax];
        int main()
        {
           #ifndef ONLINE_JUDGE
          freopen("input.txt", "r", stdin);
          freopen("output.txt", "w", stdout);
          #endif
          IOS;
          int n;
          cin >> n ;
          rep(i,n)cin >> a[i];
          int ans = INF;
          for(int mask =1; mask < (1 << n); mask++)
          {
              vector<int > vec;
              int orr = 0;
              rep(i,n)
              {
                orr|=a[i];
                if(mask &(1 << i))
                {
                   vec.PB(orr);
                   orr = 0;
                }
              }
              if(orr!=0)vec.PB(orr);
              int xr = 0;
              for(auto x : vec)xr^=x;
              ans = min(ans,xr);
          }
          cout << ans << '\n';

        }


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

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef vector<bool> VB;
typedef priority_queue<LL> PQ_DESC;
typedef priority_queue<LL, VL, greater<LL>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef priority_queue<VL> PQ_DESC_VL;
typedef priority_queue<VL, vector<VL>, greater<VL>> PQ_ASC_VL;
typedef priority_queue<PLL> PQ_DESC_PLL;
typedef priority_queue<PLL, vector<PLL>, greater<PLL>> PQ_ASC_PLL;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) LL((a).size())

#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define ROF(i,a,b) for(LL i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL LARGE_INT = 1e9+100;
const LL INF = 2e9+100;
const LL INF_LL = (LL)INF*(LL)INF;
const LL MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void Main()
{
    LL n;cin>>n;

    LL result = INF_LL;
    VL a(n),b(n);
    REP(i,n){
        cin>>a[i]>>b[i];
        result = min(result,a[i]+b[i]);
    }

    REP(i,n){
        REP(j,n){
            if(i==j){
                continue;
            }
            result = min(result,max(a[i],b[j]));
        }
    }

    cout<<result<<endl;

	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cstdio>
#include <cmath>
#include <bitset>

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

const int INF = 100100100;

/*
ll gcd(ll a, ll b){
	//log max(a,b)
	if (a % b == 0){
		return(b);
	}
	else{
		return(gcd(b, a % b));
	}
}

ll lcm(ll a, ll b){
	return a * b / gcd(a, b);
}
*/
//gcd lcm

int main() {//////////いもす
	int n, k;
	cin >> n >> k;
	vector<vector<int>>a(n, vector<int>(n));
	rep(i, n)rep(j, n)cin >> a[i][j];
	int L = k * k / 2 + 1;
	int wa = -1, ac = 1001001001;
	while (wa + 1 < ac) {
		int wj = (wa + ac) / 2;
		bool ok = false;
		{
			vector<vector<int>> s(n + 1, vector<int>(n + 1));
			rep(i, n)rep(j, n) s[i + 1][j + 1] = a[i][j]>wj?1:0;
			rep(i, n+1)rep(j, n)s[i][j+1] += s[i][j];
			rep(i, n)rep(j, n+1)s[i + 1][j] += s[i][j];
			rep(i, n - k + 1)rep(j, n - k + 1) {
				int now = s[i+k][j+k];
				now -= s[i][j + k];
				now -= s[i + k][j];
				now += s[i][j];
				if (now < L)ok = true;
			}
		}
		if (ok)ac = wj; else wa = wj;
	}
	cout << ac << endl;
	return 0;
}


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

#define REP(i,n) for(ll i=0;i<(ll)n;i++)
#define dump(x)  cerr << "Line " << __LINE__ << ": " <<  #x << " = " << (x) << "\n";
#define spa << " " <<
#define fi first
#define se second
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()

using ld = long double;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;

template<typename T> using V = vector<T>;
template<typename T> using P = pair<T, T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){os << "(" << v.first << ", " << v.second << ")"; return os;}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<vector<T>> &v){ for(auto &e : v){os << e << "\n";} return os;}
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

template <class T> void UNIQUE(vector<T> &x) {sort(ALL(x));x.erase(unique(ALL(x)), x.end());}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
void fail() { cout << -1 << '\n'; exit(0); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
template<typename T> void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cerr<<v[i][0];for(ll j=1;j<w;j++)cerr spa v[i][j];cerr<<"\n";}};
template<typename T> void debug(vector<T>&v,ll n){if(n!=0)cerr<<v[0];
for(ll i=1;i<n;i++)cerr spa v[i];
cerr<<"\n";};

const ll INF = (1ll<<62);
// const ld EPS   = 1e-10;
// const ld PI    = acos(-1.0);
const ll mod = (int)1e9 + 7;
//const ll mod = 998244353;

int main(){

    ll N, M;
    cin >> N >> M;
    V<ll> X(M), Y(M);
    REP(i, M) cin >> X[i] >> Y[i];

    set<ll> st;
    st.insert(N);

    V<ll> ids(M, 0);
    iota(ALL(ids), 0);
    sort(ALL(ids), [&](ll x, ll y){
        return X[x] < X[y];
    });

    REP(i, M){
        ll j = i;
        while(j < M and X[ids[i]] == X[ids[j]]){
            j++;
        }
        ll len = j - i;
        V<ll> check(len, 0);
        V<ll> vals;
        for(ll k=i;k<j;k++){
            vals.push_back(Y[ids[k]]);
        }
        REP(k, len){
            if(st.find(vals[k]-1) != st.end() or st.find(vals[k]+1) != st.end()){
                check[k] = 1;
            }
        }
        REP(k, len){
            if(check[k]){
                st.insert(vals[k]);
            }else{
                auto itr = st.find(vals[k]);
                if(itr != st.end()) st.erase(itr);
            }
        }

        i = j - 1;

        // for(auto x: st) cerr << x << " ";
        // cerr << endl;
    }

    cout << st.size() << endl;

    return 0;
}

#include<bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifdef OJ
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    freopen("error.txt","w",stderr);
    #endif
    int n;
    cin>>n;
    string a;
    cin>>a;
    if(a[0]!=a[a.size()-1])cout<<1;
    else
    {
        char c1=a[0],c2=a[a.size()-1];
        for(int i=1;i<a.size();i++)
        {
            if(c1!=a[i] && c2!=a[i+1])
            {
                cout<<2;
                return 0;
            }
        }
        cout<<-1;
    }
    return 0;
}


#pragma GCC optimize("Ofast")
//#pragma GCC target ("sse4")

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acosl(-1.0);

ll mod_pow(ll x, ll n, ll m = mod) {
	if (n < 0) {
		ll res = mod_pow(x, -n, m);
		return mod_pow(res, m - 2, m);
	}
	if (abs(x) >= m)x %= m;
	if (x < 0)x += m;
	ll res = 1;
	while (n) {
		if (n & 1)res = res * x % m;
		x = x * x % m; n >>= 1;
	}
	return res;
}
struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n % mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
	if (n == 0)return modint(1);
	modint res = (a * a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
modint operator/=(modint& a, modint b) { a = a / b; return a; }
const int max_n = 1 << 2;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
modint combP(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[a - b];
}

void solve() {
	int n, m; cin >> n >> m;
	vector<int> a(m),b(m);
	rep(i, m) {
		cin >> a[i] >> b[i]; a[i]--; b[i]--;
	}
	int k; cin >> k;
	vector<int> c(k), d(k);
	rep(i, k) {
		cin >> c[i] >> d[i]; c[i]--; d[i]--;
	}
	int ans = 0;
	rep(i, (1 << k)) {
		vector<bool> exi(n);
		rep(j, k) {
			if (i & (1 << j)) {
				exi[c[j]] = true;
			}
			else {
				exi[d[j]] = true;
			}
		}
		int cnt = 0;
		rep(j, m)if (exi[a[j]] && exi[b[j]])cnt++;
		ans = max(ans,cnt);
	}
	cout << ans << "\n";
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	//init_f();
	//init();
	//expr();
	//int t; cin >> t; rep(i,t)
	//expr();
	solve();
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    int n,m;
  	int vdnhgbdrhg;
    cin>>n>>m;
    vector<pair<int,int>>a(m);
    for(int i=0;i<m;i++)
    {
        cin>>a[i].first>>a[i].second;
    }
    int k;
    cin>>k;
    vector<pair<int,int>>b(k);
    for(int j=0;j<k;j++)
    {
        cin>>b[j].first>>b[j].second;
    }
    ll l=0;
    ll tot=1<<k;
    for(ll mask=0;mask<tot;mask++)
    {
        vector<int>v(n+1);
        ll ans=0;
        for(int i=0;i<k;i++)
        {
            if(mask & (1<<i))
                v[b[i].second]=1;
            else
                v[b[i].first]=1;
        }
        for(int i=0;i<m;i++)
        {
            if(v[a[i].first] && v[a[i].second])
                ans++;
        }
        l=max(l,ans);
    }
    cout<<l<<endl;
    return 0;
}


#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N,A,B;
    cin >> N >> A >> B;
    cout << N-A+B << endl;
}

#include <bits/stdc++.h>
// 1. bs
#define int long long
#define cf(i, a, b)       for(int i=a;i<=b;i++)
#define cb(i, a, b)       for(int i=a;i<=b;i--)
#define gcd            __gcd
#define endl           "\n"
#define pb             emplace_back
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define deci(x, y)      fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define nitin          ios_base::sync_with_stdio(false); cin.tie(NULL)
#define PI             3.141592653589793238
using namespace std;

int32_t main() {
    nitin;
    int n,a,b;
    cin>>n>>a>>b;
    cout<<n-a+b<<endl;
    return 0;
}


// Created by Amal P Mathews

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,n) for(ll i=0;i<n;i++)
#define tc() ll t;cin>>t;while(t--)
#define rem 1e9+7
#define pb(v,i) v.push_back(i)
#define vll vector<ll>
#define Arin(a,n) loop(i,n)cin>>a[i];
#define Arout(a,n) loop(i,n)cout<<a[i]<<" ";cout<<endl;
#define ArSize(a) sizeof(a)/sizeof(a[0]);
void start()
{
   ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

   #ifndef ONLINE_JUDGE
   freopen("/home/amal/Desktop/programming/c++/practise/input_cpp.txt","r",stdin);
   freopen("/home/amal/Desktop/programming/c++/practise/error_cpp.txt", "w", stderr);
   freopen("/home/amal/Desktop/programming/c++/practise/output_cpp.txt", "w", stdout);
   #endif
}
void solve()
{
    ll n;
    cin>>n;
    for(ll i=1;;i++)
    {
        if(stoll(to_string(i)+to_string(i))>n)
        {
            cout<<i-1;
            break;
        }
    }
}
int main()
{
    start();

    int t = 1;
    /*is Single Test case?*/
 //   cin >> t;
    while (t--) {
        solve();

    }

    cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using comp           = complex<double>;
const long double PI = acosl(-1.0);

int main(void) {
	int n;
	cin >> n;
	double p, q, r, s;
	comp a, b, c, d, ans;
	cin >> p >> q;
	cin >> r >> s;
	a        = p + q * 1i;
	b        = r + s * 1i;
	c        = (a + b) / 2.0;
	double t = 2.0 * PI / n;
	d        = cos(t) + sin(t) * 1i;
	ans      = d * (a - c) + c;
	printf("%.9lf %.9lf\n", ans.real(), ans.imag());
	return 0;
}


#include <bits/stdc++.h>

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

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

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

int main()
{
    ll N;
    cin >> N;
    vec x(N), y(N);
    REP(i,0,N) cin >> x[i] >> y[i];

    ll cnt = 0;
    REP(i,0,N-1) {
        REP(j,i+1,N) cnt += (abs(y[i]-y[j]) <= abs(x[i]-x[j]));
    }
    PR(cnt);

    return 0;
}

/*

*/

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<queue>
#include<stack>
#include<deque>
#include<list>
#include<bitset>
#include<sstream>

using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define REP(i, n) for(int i = 0; i < n; i++)
#define endl "\n"
using Graph = vector<vector<int>>;

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

    if(c%2==0){
        if(abs(a)<abs(b))cout<<"<"<<endl;
        else if(abs(a)>abs(b))cout<<">"<<endl;
        else if(abs(a)==abs(b))cout<<"="<<endl;
    }
    else{
        if(a<b)cout<<"<"<<endl;
        else if(a>b)cout<<">"<<endl;
        else if(a==b)cout<<"="<<endl;
    }
}


#include <iostream>
#include <math.h>

using namespace std;

int main()
{
	long long N;
	cin >> N;
	int cont = 0;

	int i = 1;
	long long M = 11;
	while(M <= N)
	{
		cont++;
		i++;
		int dig = to_string(i).length();
		M = i * pow(10, dig) + i;
	}

	cout << cont << endl;

	return 0;
}

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

#define mod 998244353
#define int long long
#define INF 1e9
#define endl "\n"
#define pi 2*acos(0.0)//M_PI in cmath lib
#define sp(x) setprecision(x)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define L length()

const int32_t N=25;

int find(int a,vector<int>&link){
    int x=a;
    while(link[x]!=x){
        x = link[x];
    }
    return x;
}

void unite(int a,int b,vector<int>&link,vector<int>&size){
    a = find(a,link);
    b = find(b,link);
    if(size[a]<size[b])
        swap(a,b);
    size[a] += size[b];
    link[b]=a;
}

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

std::vector<int> seive(int n){
    std::vector<int> v(n+1,0);
    std::vector<int> p;
    for(int i=2;i*i<=n;i++){
        if(v[i]==0){
            p.pb(i);
            for(int j=i;j<=n;j+=i)v[i]=1;
        }
    }
    return p;
}

bool cmp(pair<pair<int,int>,int> a, pair<pair<int,int>,int> b){
    return a.F.F<b.F.F;
}

bool pal(string s){
    int i=0,j=s.length()-1;
    while(i<j){
        if(s[i]!=s[j])return false;
        i++,j--;
    }
    return true;
}

void solve(){
    int n;cin>>n;
    if(n==0){cout<<"Yes";return;}
    int z=0;
    int t=n;
    int r=t%10;
    while(r==0 && t>0){
        z++;
        t/=10;
        r=t%10;
    }
    string s="";
    while(z--)s+='0';
    s+=to_string(n);
    if(pal(s))cout<<"Yes";
    else cout<<"No";
}

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


#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;++i)
#define repn(i,n) for(int i=1;i<=n;++i)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

int n,cnt,ans=0;
vector <int> g[400010];
bool vis[400010],cyc;

void dfs(int pos,int par)
{
  vis[pos]=true;
  cnt++;
  bool bk=false;
  rep(i,g[pos].size())
  {
    if(g[pos][i]==par&& !bk)
    {
      bk=true;
      continue;
    }
    if(vis[g[pos][i]]) cyc=true;
    else dfs(g[pos][i],pos);
  }
}

int main()
{
  cin>>n;
  int x,y;
  rep(i,n)
  {
    scanf("%d%d",&x,&y);
    g[x].pb(y);g[y].pb(x);
  }
  repn(i,400000)
  {
    if(vis[i]) continue;
    cyc=false;cnt=0;
    dfs(i,0);
    ans+=cnt-1+(int)cyc;
  }
  cout<<ans<<endl;
	return 0;
}

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

int main(){
	ll n,m;cin>>n>>m;
	vector<string> s;
  	ll odd=0,even=0;
  	for(ll i=0;i<n;i++){
    	string str;cin>>str;
    	ll ct=0;
      	for(ll j=0;j<m;j++){
        	if(str[j]=='1'){
            	ct++;
            }
        }
      ct%2?odd++:even++;
    }
  cout<<odd*even<<endl;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define per(i,r,l) for(int i=(r);i>=(l);--i)
#define fi first
#define se second
using namespace std;
int T,n,x;
map<int,int> mp;
int main(){
	scanf("%d",&T);
	while(T--){
		scanf("%d",&n);mp.clear();
		rep(i,1,n) scanf("%d",&x),mp[x]++;
		if(n&1){puts("Second");continue;}
		bool fl=0;
		for(auto &x:mp) if(x.se&1){fl=1;break;}
		if(fl) puts("First");
		else puts("Second");
	}
	return 0;
}

#include <stdio.h>
#include <algorithm>
#include <vector>
#define MN 100000

int n;
std::vector<int> e[MN+5];

void add(int u,int v){
	e[u].push_back(v);
}

struct state{
	int c,f,s;
}s[MN+5];

void dfs(int u){
	s[u].c = 1;
	s[u].f = 1;
	s[u].s = 0;
	std::vector<int> ve[2];
	for(auto v:e[u]){
		dfs(v);
		s[u].c += s[v].c;
		if(s[v].c&1){
			ve[1].push_back(v);
		}else{
			if(s[v].s>=s[v].f){
				s[u].s += s[v].s;
				s[u].f += s[v].f;
			}else{
				ve[0].push_back(v);
			}
		}
	}
	std::sort(ve[1].begin(),ve[1].end(),[](int a,int b)->bool{
		return s[a].s-s[a].f>s[b].s-s[b].f;
	});
	for(int i=0;i<(int)ve[1].size();i++){
		int v = ve[1][i];
		if(i&1){
			s[u].f += s[v].s;
			s[u].s += s[v].f;
		}else{
			s[u].s += s[v].s;
			s[u].f += s[v].f;
		}
	}
	if(ve[1].size()&1){
		for(auto v:ve[0]){
			s[u].f += s[v].s;
			s[u].s += s[v].f;
		}
	}else{
		for(auto v:ve[0]){
			s[u].s += s[v].s;
			s[u].f += s[v].f;
		}
	}
}

int main(){
	scanf("%d",&n);
	for(int i=2,f;i<=n;i++){
		scanf("%d",&f);
		add(f,i);
	}
	dfs(1);
	printf("%d\n",s[1].f);
}


#include "bits/stdc++.h"
#define ll long long int
#define MOD 1000000007
#define oo 1000000000000000000
#define forr(i,n) for(ll i=0;i<n;i++)
#define fastio ios_base::sync_with_stdio(false); cin.tie(0) ; cout.tie(0);
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define mem(a,v) memset(a,v,sizeof(a))
#define pb push_back
#define popcount(x) __builtin_popcount(x)

using namespace std;

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

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

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

ll add(ll a, ll b,ll p=MOD) { a%=p; b%=p; return (a+b + p)%p;}
ll mul(ll a, ll b,ll p=MOD) { a%=p; b%=p; return (a*b + p)%p;} // __int128
ll power(ll x,ll n,ll p=MOD){ if(x==0) return 0; if(n==0 || x==1) return 1LL;
    ll r = (power(x,n/2,p))%p; if(n&1) return mul(mul(r,r,p) , x,p); else return mul(r,r,p);
}
ll inv(ll x){return power(x,MOD-2);}

pair<int,int> dx[4] = { { -1,0 } , {1,0} , {0,-1} , {0,1} };

// Now we can simply define our unordered_map or our gp_hash_table as follows:
// unordered_map<long long, int, custom_hash> safe_map;
// gp_hash_table<long long, int, custom_hash> safe_hash_table;

/* ------------------------------------------ Code ----------------------------------------------- */

ll dp[1010][1010];

ll ncr(ll n, ll r){
    if(r==0) return 1;
    if(n<r) return 0;
    if(n==r) return 1;
    if(dp[n][r]!=-1) return dp[n][r];
    return dp[n][r] = ncr(n-1,r-1) + ncr(n-1,r);
}

void __sol(){
    mem(dp,-1);
    int n; cin>> n;
    cout << ncr(n-1,11);
    return;
}

int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    fastio
    ll tc=1; // cin >> tc;
    while(tc--) __sol();
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long long int lli;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef unsigned long long int ulli;

void fast_io(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
}

int main(){

	fast_io();
	//code starts here

	double n;
	cin >> n;

	n *= double(1.08);
	int N = n;
	if(N<206){
		cout << "Yay!" << endl;
	} else if(N>206){
		cout << ":(" << endl;
	} else {
		cout << "so-so" << endl;
	}

	return 0;

}


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

// find_by_order(k) returns the iterator to the kth largest element (start from 0)
// order_of_key(k) returns the number of elements in the set which are strictly less than the value k

using namespace std;
using namespace __gnu_pbds;

#define ff              first
#define ss              second
#define all(v)          v.begin(), v.end()
#define int             long long
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mem(dp,x)       memset(dp,x,sizeof dp);
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define rightmostbit(x) __builtin_ffsll(x)
#define mod             1000000007
#define inf             1e18
#define pi              3.141592653589793238
#define mk(a,n)         int n;cin>>n;vi a(n);for(int i=0;i<n;i++) cin>>a[i]
#define w(x)            int x; cin>>x; while(x--)

#define deb(...) cerr << "[" << #__VA_ARGS__ << "]: "; cerr << to_string(__VA_ARGS__) << endl
template <typename T, size_t N> int SIZE(const T (&t)[N]) { return N; } template<typename T> int SIZE(const T &t) { return t.size(); } string to_string(const string s, int x1 = 0, int x2 = 1e9) { return '"' + ((x1 < s.size()) ? s.substr(x1, x2 - x1 + 1) : "") + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(const bool b) { return (b ? "true" : "false"); } string to_string(const char c) { return string({c}); } template<size_t N> string to_string(const bitset<N> &b, int x1 = 0, int x2 = 1e9) { string t = ""; for (int __iii__ = min(x1, SIZE(b)),  __jjj__ = min(x2, SIZE(b) - 1); __iii__ <= __jjj__; ++__iii__) { t += b[__iii__] + '0'; } return '"' + t + '"'; } template <typename A, typename... C> string to_string(const A (&v), int x1 = 0, int x2 = 1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(const pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(const A (&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if (l_v_l_v_l == 0) res += "\n"; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2 - x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if (e != l) { if (rnk > 1) { res += "\n"; t_a_b_s = l_v_l_v_l; }; } else { t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if (l_v_l_v_l == 0) res += "\n"; return res; } void dbgm() {;} template<typename Heads, typename... Tails> void dbgm(Heads H, Tails... T) { cerr << to_string(H) << " | "; dbgm(T...); }
#define debm(...) cerr << "[" << #__VA_ARGS__ << "]: "; dbgm(__VA_ARGS__); cerr << endl

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
void g_b()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("error.txt", "w", stderr);
#endif
}
int32_t main()
{

	g_b();
	int n, w; cin >> n >> w;
	cout << n / w;

	return 0;

}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<string> VS;
typedef vector<P> VP;
typedef vector<V> VV;
typedef map<ll, ll> MP;
typedef multimap<ll, ll> MMP;
typedef set<ll> SET;
typedef multiset<ll> MSET;

#define loop(i,n) for(ll i = 0; i < n; i++)
#define loopr(i,x,y) for(ll i = x; i < y; i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define deb(x) cout << #x << "=" << x << endl
#define endl '\n'
#define PI 3.1415926535897932384626
#define MOD 1000000007

const int N = 200005;

vector<int> edges[N];
vector<int> st(N), en(N), dist[N];
int tmp = 0;

void dfs(int v, int len) {

	st[v] = tmp++;
	dist[len].pb(st[v]);

	for (auto it : edges[v]) {
		dfs(it, len + 1);
	}
	en[v] = tmp;
}

int main() {

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

	int n;

	cin>>n;

	for (int i = 2; i <= n; i++) {
		int val;
		cin>>val;
		edges[val].pb(i);
	}

	dfs(1, 0);

	int q;

	cin>>q;

	while (q--) {

		int a, b;

		cin>>a>>b;

		int l = st[a];
		int r = en[a];

		vector<int> vect = dist[b];

		int res = lower_bound(all(vect), r) - lower_bound(all(vect), l);

		cout<<res<<endl;
	}
}