#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);}
ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*b);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}
#define num_l(a,v) POSL(a,v) //v未満の要素数
#define num_eql(a,v) POSU(a,v) //v以下の要素数
#define num_h(a,v) (a.size() - POSU(a,v)) //vより大きい要素数
#define num_eqh(a,v) (a.size() - POSL(a,v)) //v以上の要素数
// static_cast< long long ll >

//chrono::system_clock::time_point start, end;
clock_t start;

bool did[50*52];
int tile[51][51];
int point[51][51];
int N = 50;
int si,sj;

string now = "";
int len = 0;
string ans="";

int score = 0;
int best_s = 0;

string D = "DURL";
int di[] = {1,-1,0,0};
int dj[] = {0,0,1,-1};

string DD = "AAAA";
int di_[] = {1,-1,0,0};
int dj_[] = {0,0,1,-1};

double t = 82.0;

void calc(int i,int j,char &x){
  if(i<0 || j<0 || i>=50 || j>=50)return;
  if(did[ tile[i][j] ])return;
  clock_t end = clock();
  double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
  if(time >= t)return;
  now[len] = x;
  len++;
  did[ tile[i][j] ] = true;
  score += point[i][j];
  if(score > best_s){
    best_s = score;
    ans = now.substr(0,len);
  }
  FOR(k,0,4){
    calc(i+di_[k],j+dj_[k],DD[k]);
  }
  len--;
  did[ tile[i][j] ] = false;
  score -= point[i][j];
}

int main(){
  FOR(i,0,N*N) now += 'D';

  mt19937_64 mt(1);
  uniform_real_distribution<double> rnd(0.00,1.00);

  cin >> si >> sj;
  FOR(i,0,N)FOR(j,0,N){
    cin >> tile[i][j];
  }
  FOR(i,0,N)FOR(j,0,N){
    cin >> point[i][j];
  }

  start = clock();

  char a = 'U';
  vector<int> ind(4);
  ind[0] = 0;
  ind[1] = 1;
  ind[2] = 2;
  ind[3] = 3;
  do{
    for(int i=0;i<4;i++){
      DD[i] = D[ind[i]];
      di_[i] = di[ind[i]];
      dj_[i] = dj[ind[i]];
    }
    calc(si,sj,a);
    t += 82.0;
  }while(NEXTP(ind));

  if(ans.size() == 0) ans = "U";
  cout << ans.substr(1,ans.size()-1) << endl;

}

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int si, sj, ti, tj, t[50][50], p[50][50],
    dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
bool done[2500] = {};
char c[4] = {'R', 'D', 'L', 'U'};
string ans = "";

pair<int, int> next(int d){
    pair<int, int> res = {ti + dx[d % 4], tj + dy[d % 4]};
    return res;
}

bool check(int i, int j, int d){
    int ni = i + dx[d % 4], nj = j + dy[d % 4];
    bool res = (ni >= 0) && (ni < 50) && (nj >= 0) && (nj < 50);
    if(res) res = !done[t[ni][nj]];
    return res;
}

void change(int d){
    ti = ti + dx[d % 4], tj = tj + dy[d % 4];
    done[t[ti][tj]] = true;
    ans.push_back(c[d % 4]);
    return;
}

int nextok(int d){
	if(!check(ti, tj, d)) return -1;
  	auto [ni, nj] = next(d);
  	int res = 0;
  	for(int i = 0; i < 4; i++){
      	int nni = ni + dx[i], nnj = nj + dy[i];
      	if((nni >= 0) && (nni < 50) && (nnj >= 0) && (nnj < 50)){
			if(!done[t[nni][nnj]] && (t[ni][nj] != t[nni][nnj])) res++;
        }
    }
  	return res;
}

int main(){
    scanf("%d %d", &si, &sj);
    ti = si, tj = sj;
    for(int i = 0; i < 50; i++)
        for(int j = 0; j < 50; j++)
            scanf("%d", &t[i][j]);
    for(int i = 0; i < 50; i++)
        for(int j = 0; j < 50; j++)
            scanf("%d", &p[i][j]);
    done[t[si][sj]] = true;
    int foo[4] = {49 - sj, 49 - si, sj, si};
    int D = (min_element(foo, foo + 4) - foo) + (1<<20);
  	while(true){
		if(!(check(ti, tj, D) || check(ti, tj, D + 1) || check(ti, tj, D + 2) || check(ti, tj, D + 3))) break;
      	int nd = rand() % 4, md = -1;
      	for(int i = nd; i < nd + 4; i++){
			if(md < nextok(i)){
				D = i;
              	md = nextok(i);
            }
        }
      	change(D);
    }
    /*while(true){
        if(!(check(ti, tj, D - 1) || check(ti, tj, D) || check(ti, tj, D + 1))) break;
        if(check(ti, tj, D))change(D);
        else{
            int td = D - 1 + 2 * (rand() & 1);
            if(check(ti, tj, td)) change(td);
            else change(td + 2);
        }
    }
    D++;
    while(true){
        if(!(check(ti, tj, D) || check(ti, tj, D + 1) || check(ti, tj, D + 2) || check(ti, tj, D + 3))) break;
        for(int d = D - 1; d < D + 3; d++){
            if(check(ti, tj, d)){
                change(d);
                D = d;
                break;
            }
        }
    }*/
    cout << ans << endl;
    return 0;
}


#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, init, end) for(ll i = init; i < end; i++)
#define REP(i, init, end) for(ll i = init; i < end + 1; i++)
#define rev(i, end, init) for(ll i = init - 1; i >= end; i--)
#define REV(i, end, init) for(ll i = init; i >= end; i--)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 998244353
//cout << std::fixed << std::setprecision(15) << y << endl;

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

    if(N == 3){
        cout << "6 10 15" << endl;
        return 0;
    }

    ll count = 0;
    ll i = 6;
    vector<ll> ans;
    while(count < N){
        if((i % 6 == 0 && i % 5 != 0) || (i % 10 == 0 && i % 3 != 0) || (i % 15 == 0 && i % 2 != 0) || (i % 30 == 0)){
            count++;
            ans.push_back(i);
        }
        i++;
    }

    rep(i, 0, ans.size()){
        if(i != 0){
            cout << " ";
        }
        cout << ans[i];
    }
    cout << endl;
    // cout << "size: " << ans.size() << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define SZ(x) ((int)(x).size())
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) \
  SORT(var);       \
  REVERSE(var)
#define OPTIMIZE_STDIO         \
  ios::sync_with_stdio(false); \
  cin.tie(0);                  \
  cout.precision(10);          \
  cout << fixed
#define endl '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

void solve(istream& cin, ostream& cout) {
  int n;
  cin >> n;
  vector<ll> a(n);
  REP(i, n) cin >> a[i];
  vector<ll> c(n + 1);
  c[0] = 0;
  REP(i, n) {
    if (i % 2 == 0) c[i + 1] = c[i] + a[i];
    else
      c[i + 1] = c[i] - a[i];
  }
  map<ll, ll> mp;
  FOR(i, 0, n) mp[c[i]]++;
  ll ans = 0;
  EACH(e, mp) {
    ans += e.second * (e.second - 1) / 2;
  }
  cout << ans << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
  return 0;
}
#endif

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

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

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

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

int main(){
    v fib(88,0);
    fib[0]=1;fib[1]=1;
    rep(i,2,88)fib[i]=fib[i-1]+fib[i-2];

    ll N;
    cin>>N;
    v fbit(88,0);
    ll sbit;
    bool ok = false;
    for(ll i = 87;i>=0;i--){
        if(N>=fib[i]){
            fbit[i]=1;
            N-=fib[i];
            if(!ok){
                sbit = i;
                ok = true;
            }
        }
    }
    ll nowxy = sbit%2;
    ll x=0,y=0;
    ll sb=0;
    rep(i,0,sbit+1){
        if(fbit[i]==1)sb++;
    }

    cout<<sb+sbit<<endl;
    for(ll i = sbit; i>=1;i--){
        if(fbit[i]){
            cout<<nowxy+1<<endl;
            if(nowxy==0)x++;
            else y++;
        }
        nowxy++;nowxy%=2;
        cout<<nowxy+3<<endl;
        if(nowxy==0)x=x+y;
        else y=x+y;
    }
    //cout<<x<<" "<<y;
    return 0;
}


#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#include <algorithm>
#include <iostream>
#include <bitset>
#include <vector>
#include <array>
using namespace std;
#define f(x,y,z) for(int x=y;x<=z;++x)
vector<int> v[200001];
int n, a, b, it;
array<int, 200001> jr, dlm, nmr;
bitset<200001> sdh;
void jrk(int x) {
    for(int &i:v[x]) if(!jr[i]) {
        jr[i] = jr[x]+1, jrk(i);
    }
}
void trn(int x) {
    sdh[x] = true;
    for(int &i:v[x]) if(!sdh[i]) {
        trn(i), dlm[x] = max(dlm[x], dlm[i]+1);
    }
}
void isi(int x) {
    sdh[x] = true, nmr[x] = a;
    vector<pair<int, int>> mn;
    for(int &i:v[x]) if(!sdh[i]) mn.push_back({dlm[i], i});
    sort(mn.begin(), mn.end());
    for(auto &i:mn) ++a, isi(i.second), ++a;
}
int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    cin >> n;
    f(i,2,n) {
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    jr[1] = a = 1, jrk(1);
    it = max_element(jr.begin()+1, jr.begin()+n+1)-jr.begin();
    trn(it), sdh.reset(), isi(it);
    f(i,1,n) cout << nmr[i] << ' ';
}

//全力以赴
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define PI 3.141592653L
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll INF = (ll)1e18;
const int N = 2e5 + 5;
const ll MOD = 1e9+7;

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

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

ll extGcd(ll a, ll b, ll &x, ll &y) { // solves for x and y where ax+by=gcd(a,b)
    if(b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
}

ll modInv(ll a, ll p) { // solve for x=a^-1 where ax + py = 1 % p
    if(gcd(a, p) != 1) return -1; // modInv only exists if a and p are coprime (gcd(a, p) = 1)
    ll x, y;
    extGcd(a, p, x, y);
    x = (x % p + p) % p;
    return x;
}

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

/*
a^b:
if b is even -> a^b = a^(b/2) * a^(b/2)
if b is odd -> a^b  = a * a^(b-1/2) * a^(b-1/2)
*/
ll modPow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = (res * a) % mod;
        a = (a * a) % mod;
        n >>= 1;
    }
    return res;
}

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

void Union(int x, int y) {
    int xPar = find(x), yPar = find(y);
    if(xPar != yPar) parent[xPar] = yPar;
}

ll nCr(ll n, ll r) {
    ll res = 1;
    for(ll i=1;i<=r;i++) {
        res = res * (n - r + i) / i;
    }
    return res;
}

int ask(int i, int j) {
    cout << "? " << i + 1 << ' ' << j + 1 << endl;
    int v;
    cin >> v;
    return v;
}

int msbPos(int n) {
    if(n == 0) return 0;
    int msbPos = 0;
    n /= 2;
    while(n != 0) {
        n /= 2;
        msbPos++;
    }
    return msbPos;
}

void solve() {
    int n, m;
    cin >> n >> m;
    set<int> st;
    for(int i=0;i<n;i++) {
        int x;
        cin >> x;
        st.insert(x);
    }
    for(int i=0;i<m;i++) {
        int x;
        cin >> x;
        if(st.count(x)) {
            st.erase(x);
        }
        else {
            st.insert(x);
        }
    }
    for(auto x : st) cout << x << ' ';
    cout << endl;
}

int main()
{
    IOS
    //int t;
    //cin >> t;
    //while(t--) solve();
    solve();
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

#include <string>
#include <cmath>

using namespace std;

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

	if (A == B)
	{
		cout << C;
	}
	else if (B == C)
	{
		cout << A;
	}
	else if (A == C)
	{
		cout << B;
	}
	else
	{
		cout << 0;
	}
}

#include<bits/stdc++.h>
using namespace std;
#define int long long
int a,b,k;
int gcd(int x,int y)
{
    if(y==0) return x;
    else return gcd(y,x%y);
}
void dfs(int n,int m,int x)
{
	if(n==0){while(m--)cout<<'b';return;}
	if(m==0){while(n--)cout<<'a';return;}
	int q=1,w,ci=n+m-1,hh=1,yue=max(n-1,m),shao=min(m,n-1);
	for(int i=yue+1,j=1;i<=ci;i++,j++)
	{
		if(j<=shao)hh*=j;
		q*=i;w=gcd(q,hh);
		q/=w;hh/=w;
	}
	if(q<x){cout<<'b';dfs(n,m-1,x-q);}
	else {cout<<'a';dfs(n-1,m,x);}
}
signed main()
{
	scanf("%lld%lld%lld",&a,&b,&k);
	dfs(a,b,k);
	return 0;
}


//@formatter:off
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < int(n); ++i)
#define rrep(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = int(s); i < int(n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<P>
#define vvp vector<vector<P>>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
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<<']'; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << '\n'; }
void YES(bool b) { cout << (b ? "YES" : "NO") << '\n'; }
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;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;
//@formatter:on

ll dp[60][2];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    ll X;
    cin >> n >> X;
    vl a(n);
    cin >> a;
    vl x(n);
    rrep(i, n) {
        x[i] = X / a[i];
        X %= a[i];
    }
    rrep(i, n - 1) {
        a[i + 1] /= a[i];
    }
    rep(i, n - 1) {
        a[i] = a[i + 1];
    }
    dp[0][0] = 1;
    rep(i, n - 1) rep(j, 2) {
            if (dp[i][j] == 0) continue;
            if (j + x[i] < a[i]) {
                dp[i + 1][0] += dp[i][j];
                if (j + x[i] > 0)dp[i + 1][1] += dp[i][j];
            } else {
                dp[i + 1][1] += dp[i][j];
            }
        }
    cout << dp[n - 1][0] + dp[n - 1][1] << endl;
}

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <numeric>
#include <map>
#include <vector>

using namespace std;

typedef long long LL;
map<pair<LL, LL>, LL> memo;

LL solve(LL x, LL i, const vector<LL> &a) {
	if (i >= a.size()) return 1;
	pair<LL, LL> key(x, i);
	if (memo.find(key) != memo.end()) return memo[key];
	LL w = 0;
	LL y = a[i];
	if (i == a.size() - 1) {
		return (x % y) == 0;
	}
	LL r = x % a[i + 1];
	if (r == 0) {
		w = solve(x, i + 1, a);
	} else {
		w = solve(x - r, i + 1, a) + solve(x - r + a[i + 1], i + 1, a);
	}
	memo[key] = w;
	return w;
}

int main() {
	LL N, X;
	cin >> N >> X;
	vector<LL> a(N);
	for (LL i = 0; i < N; ++i) {
		cin >> a[i];
	}
	LL ans = solve(X, 0, a);
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define Rep(i,j,n) for (ll i=(ll)(j);i<=(ll)(n);++i)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const int mod = 998244353;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

/*
ll ti=clock();
cout<<("Execution Time: %.4lf sec", 1.0 * (clock() - ti) / CLOCKS_PER_SEC)<<endl;
*/

int main(){
  ll n,m,q;
  cin>>n>>m>>q;
  vl w(n),v(n);
  vector<Pll> bag;
  rep(i,n){
      cin>>w[i]>>v[i];
      bag.emplace_back(v[i],w[i]);
  }
  sort(all(bag),greater<Pll>());
  vl x(m);
  rep(i,m){
      cin>>x[i];
  }
  rep(i,q){
      ll l,r;
      cin>>l>>r;
      vl tmp;
      rep(i,m){
          if(i==l-1){
              i=r;
              if(r==m){
                  break;
              }
          }
          tmp.eb(x[i]);
      }
      sort(all(tmp));
      vector<bool> empty(sz(tmp),true);
      ll sum=0;
      rep(i,n){
          rep(j,sz(tmp)){
              if(bag[i].S<=tmp[j]&&empty[j]){
                  sum+=bag[i].F;
                  empty[j]=false;
                  break;
              }
          }
      }
      print(sum);
  }
}

#include<bits/stdc++.h>
using namespace std;
int n,m,q;
struct node{
	int w,v;
}a[55];
struct node1{
	int x,num;
}b[55];
int cmp(node x,node y){
	if(x.v==y.v)return x.w<y.w;
	return x.v>y.v;
}
int cmp2(node1 x,node1 y){
	return x.x<y.x;
}
typedef long long ll;
int x[55];
bool v[55];
ll ans=0ll;
int main(){
	cin>>n>>m>>q;
	for(int i=1;i<=n;i++)cin>>a[i].w>>a[i].v;
	for(int i=1;i<=m;i++)cin>>b[i].x,b[i].num=i;
	sort(b+1,b+m+1,cmp2);
	sort(a+1,a+n+1,cmp);
	while(q--){
		ans=0ll;
		memset(v,0,sizeof(v));
		int l,r;
		cin>>l>>r;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				if(b[j].num>=l&&b[j].num<=r)continue;
				if(b[j].x>=a[i].w&&!v[b[j].num]){
					ans+=a[i].v;v[b[j].num]=1;break;
				}
			}
		}
		cout<<ans<<endl;
	}
}


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

#define ll long long
#define vt vector
#define ar array
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define pb push_back

template<class A> void read(vt<A>& v);
template<class A, size_t S> void read(ar<A, S>& a);
template<class T> void read(T& x) {
	cin >> x;
}
void read(double& d) {
	string t;
	read(t);
	d=stod(t);
}
void read(long double& d) {
	string t;
	read(t);
	d=stold(t);
}
template<class H, class... T> void read(H& h, T&... t) {
	read(h);
	read(t...);
}
template<class A> void read(vt<A>& x) {
	for (A & it : x) read(it);
}
template<class A, size_t S> void read(array<A, S>& x) {
    for (A & it : x) read(it);
}
template<class A> void read(vt<vt<A>> & x) {
    for (vt<A> & it : x) for (A & itt : it) read(itt);
}
template<class A> void read(vt<pair<A, A>> & x) {
    for (pair<A, A> & it : x) {
        read(it.first);
        read(it.second);
    }
}

string to_string(char c) {
	return string(1, c);
}
string to_string(bool b) {
	return b?"true":"false";
}
string to_string(const char* s) {
	return string(s);
}
string to_string(string s) {
	return s;
}
string to_string(vt<bool> v) {
	string res;
	for (int i = 0; i < sz(v); i++)
		res+=char('0'+v[i]);
	return res;
}

template<size_t S> string to_string(bitset<S> b) {
	string res;
	for (int i = 0; i < S; i++)
		res+=char('0'+b[i]);
	return res;
}
template<class T> string to_string(T v) {
    bool f=1;
    string res;
    for (T & x : v) {
		if(!f)
			res+=' ';
		f=0;
		res+=to_string(x);
	}
    return res;
}

template<class A> void print(A x) {
	cout << to_string(x);
}
template<class H, class... T> void print(const H& h, const T&... t) {
	print(h);
	print(t...);
}
void println() {
	cout << endl;
}
template<class A> void println(A x) {
	print(x);
    println();
}
template<class H, class... T> void println(const H& h, const T&... t) {
	print(h);
	print(t...);
    println();
}

template<class A> bool umin(A & x, A a) {
    if (a < x) {
        x = a;
        return 1;
    }
    return 0;
}
template<class A> bool umax(A & x, A a) {
    if (a > x) {
        x = a;
        return 1;
    }
    return 0;
}

int readInt () {
	bool minus = false;
	int result = 0;
	char ch;
	ch = getchar();
	while (true) {
		if (ch == '-') break;
		if (ch >= '0' && ch <= '9') break;
		ch = getchar();
	}
	if (ch == '-') minus = true; else result = ch-'0';
	while (true) {
		ch = getchar();
		if (ch < '0' || ch > '9') break;
		result = result*10 + (ch - '0');
	}
	if (minus)
		return -result;
	else
		return result;
}

//----------------------------------Solution starts here-------------------------------//

void solve() {
	ll n;
	read(n);

	set<ll> s;
	for (ll i = 2; i <= sqrt(n); i++) {
		ll j = i * i;
		while (j <= n) {
			s.insert(j);
			j *= i;
		}
	}
	println(n - sz(s));
}

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

    /*
    freopen("in.txt", "r", stdin);
    freopen ("out.txt", "w", stdout);
    */

    int t = 1;
    //read(t);
    for (int i = 1; i <= t; i++) {
        //print("Case #", i, ": ");
        solve();
    }
}

//Δke_D
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
typedef double DB;
const int N = 333;
int n,m,a[N][N];
int main()
{
	int i,j,k;
	cin>>n;
	for(i=1;i<=n;i=i+1){
		m=1<<(i-1);
		for(j=m;j<m*2;j=j+1)
			for(k=0;k<m;k=k+1)
				a[j][k]=a[j-m][k];
		for(j=0;j<m;j=j+1)
			for(k=m;k<m*2;k=k+1)
				a[j][k]=a[j][k-m];
		for(j=m;j<m*2;j=j+1)
			for(k=m;k<m*2;k=k+1)
				a[j][k]=a[j-m][k-m]^1;
	}
	m=1<<n;
	cout<<m-1<<endl;
	for(i=1;i<m;i=i+1){
		for(j=0;j<m;j=j+1)
			cout<<(char)(a[i][j]+'A');
		cout<<endl;
	}
	return 0;
}


//x<<y=x*2^y,x>>y=x/2^y
//1e5+3 is prime
// in a matrix, all elements of a primary diagonal have constant diff of coordinates
// and a secondary diagonal has constant sum of coordinates
//use ll() for using an integer in self-built fn
//(x&-x) bitwise and of (x and its 2's complement) returns (last set bit)
//eg if x=1010 then it will return 0010
// careful dont print empty container(run time error)
//v.erase O(n)
//use ("\n") instead of endl as endl flushes the output buffer
//every time so takes more time than \n (TLE)
//stoll() and to_string((less than 1e19))
//INT_MAX is approx 3e10
//For sets use set_name.lower_bound(x)(strictly O(logn))
//NOT lb(all(s),x)(O(logn) for random access (eg vector) but for sets it is O(n));
#include<bits/stdc++.h>
typedef long long int ll;
#define ull unsigned long long int
#define lld long double
#define endl "\n"
#define fi first
#define sec second
#define sp setprecision
#define lb lower_bound
#define ub upper_bound
#define For(i, a, b) for(long long int i = (a); i <= (b); i++)
#define Forr(i, a, b) for(long long int i = (a); i >= (b); i--)
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define vll vector<ll>
#define pll pair<ll,ll>
#define vlld vector<lld>
#define vi vector<int>
#define vch vector<char>
#define sll set<ll>
#define sch set<ch>
#define vpll vector< pair<ll,ll> >
#define vpii vector< pair<int,int> >
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mll map<ll, ll>
#define mcll map<char,ll>
#define sz(container) ll((container).size())
#define fill(a,b) memset(a, b, sizeof(a))
#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;
lld pi=3.1415926535897932;
const ll mod=998244353;
const ll dx[4]={-1, 0, 1, 0} , dy[4]={0, 1, 0, -1};
const ll dxx[8]={-1, -1, 0, 1, 1, 1, 0, -1} , dyy[8]={0, 1, 1, 1, 0, -1, -1, -1};
string ds="RLDU";
/***************************************
struct cmp
{
    bool operator() (const pll &a, const pll &b)  const
    {
        ll lena = a.sec - a.fi + 1;
        ll lenb = b.sec - b.fi + 1;
        if (lena == lenb) return a.fi < b.fi;
        return lena > lenb;
    }
};
********************************/

ll lcm(ll a, ll b)
{
    ll g=__gcd(a, b);
    return a/g*b;
}

ll binpow(ll a, ll b,ll m)
{
    a %= m;
    ll res = 1;
    while (b > 0)
    {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
ll modinv(ll n)
{
    return binpow(n, mod - 2,mod);
}

/**************coding*********************/
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    fast_io;
    ll T=1;//cin>>T;
    For(i,1,T)
    {
        ll n;cin>>n;
        vll a(n);
        For(j,0,n-1) cin>>a[j];
        ll g=a[0];
        For(j,1,n-1) g=__gcd(g,a[j]);
        cout<<g;
    }
}

#include<bits/stdc++.h>

using namespace std;

using ll = long long;
const int MOD = 1e9 + 7;
int main() {

    ios_base::sync_with_stdio(false); cin.tie(0);
    int n; cin >> n;
    vector<int> a(n);
    for (auto &i : a) cin >> i;

    a.emplace_back(0);
    sort(a.begin(), a.end());
    ll ans = 1;
    for (int i = 0; i < n; i++)
        ans = ans * (a[i + 1] - a[i] + 1) % MOD;

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


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

using namespace std;

signed main(){
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> p(n);
    vector<int> idx(n);
    vector<bool> use(n,false);
    rep(i,n){
        cin >> p[i];
        p[i]--;
        idx[p[i]]=i;
    }
    vector<int> ans;
    rep(i,n){
        int x = idx[i];
        //cout << x << endl;
        for(int j=x;j>i;j--){
            if(use[j]){
                cout << -1 << endl;
                return 0;
            }
            ans.pb(j);
            idx[p[j]]=j-1;
            idx[p[j-1]]=j;
            swap(p[j],p[j-1]);
            use[j] = true;
        }
    }
    if(ans.size()!=n-1) cout << -1 << endl;
    else{
        for(int u:ans) cout << u << endl;
    }
    return 0;
}
// g++ main.cpp -o a.out && ./a.out

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cctype>
#include <fstream>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <stdio.h>
#include <string>
#include <sstream>
#include <stack>
#include <set>
#include <vector>

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

const int AAA = 1000000007;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pairII;
typedef vector<int> vecI;

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll powD(ll a, ll b) {
	ll ans = 1;
	a %= AAA;
	for (int i = 0; i < b; i++)
	{
		ans *= a;
		ans %= AAA;
	}
	return ans;
}

int main(int argc, char* argv[]) {
	int i, j;
	string N;
	cin >> N;
	if (N.size() == 1) {
		cout << 0;
		return 0;
	}
	if (N.size() % 2 == 1) {
		string S;
		rep(i, 0, N.size() - 1) {
			S.push_back('9');
		}
		N = S;
	}
	ll shift_len = N.size() / 2;
	ll shift = pow(10, shift_len);

	ll X = stoll(N);
	ll n1 = stoll(N) / shift;
	ll n2 = stoll(N) % shift;

	ll n = pow(10, shift_len-1);
	ll ans = pow(10, shift_len - 1) - 1;
	while (n * shift + n <= X) {
		ans++;
		n++;
	}
	cout << ans;
	return 0;
}


//Utkarsh.25dec
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// ordered_set s ; s.order_of_key(val)  no. of elements strictly less than val
// s.find_by_order(i)  itertor to ith element (0 indexed)
typedef vector<vector<ll>> matrix;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=500023;
bool vis[N];
vector <int> adj[N];
void solve()
{
    ll n;
    cin>>n;
    set <ll> s;
    map <ll,ll> cnt;
    for(int i=0;i<n;i++)
    {
        ll c;
        cin>>c;
        s.insert(c);
        cnt[c]^=1;
    }
    if(n%2==1)
    {
        cout<<"Second\n";
    }
    else
    {
        ll odd=0;
        for(auto it:s)
        {
            if(cnt[it]==1)
                odd=1;
        }
        if(odd==1)
            cout<<"First\n";
        else
            cout<<"Second\n";
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T=1;
    cin>>T;
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

#include<bits/stdc++.h>
using namespace std;
#define res register int
#define ll long long
//#define cccgift
#define lowbit(x) ((x)&-(x))
#define rep(i,l,r) for(res i=l,_r=r;i<=_r;++i)
#define per(i,r,l) for(res i=r,_l=l;i>=_l;--i)
#define mkp make_pair
#define pb push_back
#define mem0(a) memset(a,0,sizeof(a))
#define mem0n(a,n) memset(a,0,(n)*sizeof(a[0]))
#define iter(x,v) for(res v,_p=head[x];v=ver[_p],_p;_p=nxt[_p])
#ifdef cccgift //by lqh
#define SHOW(x) cerr<<#x"="<<(x)<<endl
#else
#define SHOW(x) 0
#endif
//#define getchar()(ip1==ip2&&(ip2=(ip1=ibuf)+fread(ibuf,1,1<<21,stdin),ip1==ip2)?EOF:*ip1++)
//char ibuf[1<<21],*ip1=ibuf,*ip2=ibuf;
template<typename T>
inline void read(T &x)
{
    static char ch;bool f=1;
    for(x=0,ch=getchar();!isdigit(ch);ch=getchar()) if(ch=='-') f=0;
    for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=getchar());x=f?x:-x;
}
template<typename T>
void print(T x)
{
    if (x<0) x=-x,putchar('-');
    if (x>9) print(x/10);
    putchar(x%10+48);
}
template<typename T>
inline void print(T x,char ap) {print(x);if (ap) putchar(ap);}
template<typename T>
inline void chkmax(T &x,const T &y) {x=x<y?y:x;}
template<typename T>
inline void chkmin(T &x,const T &y) {x=x<y?x:y;}
unordered_map<int,bool> mp;
int t,n,x;
int main()
{
	read(t);
	while(t--) {
		read(n),mp.clear();
		rep(i,1,n) read(x),mp[x]^=1;
		if(n&1) {puts("Second");continue;}
		bool flag=false;
		for(auto &p:mp) if(p.second) flag=true;
		puts(flag?"First":"Second");
	}
	return 0;
}
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do something instead of nothing and stay organized
*/


#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
const vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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; }
template<class T>void debag(const vector<T> &a){cerr<<"debag :";for(auto v:a)cerr<<v<<" ";cerr<<"\n";}
template<class T>void print(const vector<T> &a){for(auto v:a)cout<<v<<" ";cout<<"\n";}
int main(){
     ll n;
     cin>>n;
     V<V<ll>> g(n+1);
     for(ll i=1;i<=n;i++){
            for(ll j=i;j<=n;j+=i){
                  g[j].emplace_back(i);
            }
     }
     int ma=0;
     for(int i=1;i<=n;i++){
           chmax(ma,int(g[i].size()));
     }
     V<int> ans(n,0);
     for(int i=0;i<n;i++){
            V<bool> ok(ma+1,true);
            for(int v:g[i+1]){
                    ok[ans[v-1]]=false;
            }
            for(int j=1;j<=ma;j++){
                  if(ok[j]){
                         ans[i]=j;
                         break;
                  }
            }
     }
    print(ans);
}

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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define per(i, b) per2(i, 0, b)
#define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define ALL(c) (c).begin(), (c).end()
#define SZ(x) ((int)(x).size())

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

int main() {
    #ifdef LOCAL
    freopen("A.INP", "r", stdin);
    freopen("A.OUT", "w", stdout);
  #endif // LOCAL
    int N;
    cin >> N;
    V<int> A(N), B(N);
    int sz = N * 2;
    V<int> have(sz), go(sz, -1);

    bool ng = true;

    rep(i, N) {
        cin >> A[i] >> B[i];
        if (A[i] != -1) {
            --A[i];
            if (have[A[i]]) ng = false;
            have[A[i]] = i + 1;
        }
        if (B[i] != -1) {
            --B[i];
            if (have[B[i]]) ng = false;
            have[B[i]] = -(i + 1);
        }

        if (A[i] != -1 && B[i] != -1) {
            go[A[i]] = B[i];
            go[B[i]] = A[i];
        }
    }
    if (!ng) {
        puts("No");
        return 0;
    }

    V<bool> dp(sz + 1);
    dp[0] = true;

    rep(i, sz) {
        if (!dp[i]) continue;
        for (int j = i + 1; j < sz; ++j) {
            int w = j - i + 1;
            if (w & 1) continue;
            w /= 2;
            bool ok = true;
            V<bool> exist(N);

            rep(k, w) {
                int l = i + k, r = i + k + w;
                if (go[l] != -1 && go[l] != r) {
                    ok = false;
                }
                if (go[r] != -1 && go[r] != l) {
                    ok = false;
                }

                if (have[l] && have[r]) {
                    if (have[l] + have[r]) {
                        ok = false;
                    }
                }
                if (have[l] < 0 || have[r] > 0) {
                    ok = false;
                }
            }
            if (ok) {
                dp[j + 1] = true;
            }
        }
    }
    puts(dp[sz] ? "Yes" : "No");

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) {sort(all(a));a.erase(unique(all(a)),a.end());}
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vvvvi=vector<vvvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const ll INF=1001001001;
const ll mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}

int main(){
    ll n,k,m;cin>>n>>k>>m;
    vvi dp(n,vi(n*(n+1)/2*k+1));
    rep(i,k+1)dp[0][i]=1;
    REP(i,1,n){
        ll sum=0;
        rep(j,i+1){
            for(ll t=j;t<dp[0].size();t+=i+1){
                sum+=dp[i-1][t];sum%=m;
                if(t-(i+1)*(k+1)>=0)sum=(sum-dp[i-1][t-(i+1)*(k+1)]+m)%m;
                dp[i][t]=sum;
            }
        }
    }
    vi ans(n);ans[0]=1;
    REP(i,1,n){
        if(n-i-1<i)ans[i]=ans[n-i-1];
        else{
            rep(j,dp[i-1].size())ans[i]=(ans[i]+dp[i-1][j]*dp[n-i-2][j])%m;
        }
    }
    rep(i,n)ans[i]=(ans[i]*(k+1)+m-1)%m;
    for(ll x:ans)out(x);
}


#include<bits/stdc++.h>
#define pb push_back
using namespace std;
typedef unsigned long long ull;
typedef unsigned uint;
typedef long long ll;
#define G getchar()
int read()
{
	int x=0; bool flg=false; char ch=G;
	for (;!isdigit(ch);ch=G) if (ch=='-') flg=true;
	for (;isdigit(ch);ch=G) x=(x<<3)+(x<<1)+(ch^48);
	return flg?-x:x;
}
#undef G
#define fi first
#define se second
/*
const int mod=;
inline int upd(const int &x){return x+(x>>31&mod);}
inline void add(int &x,const int &y){x=upd(x+y-mod);}
inline void iadd(int &x,const int &y){x=upd(x-y);}
int qpow(int x,int y){
	int res=1;
	for (;y;y>>=1,x=1LL*x*x%mod)
		if (y&1) res=1LL*res*x%mod;
	return res;
}
*/
typedef pair<ll,int> P;
#define rep(i,l,r) for (int i(l),_##i(r);i<=_##i;i++)
#define per(i,l,r) for (int i(r),_##i(l);i>=_##i;i--)
#define all(x) (x).begin(),(x).end()
#define forall(x,y) for (const int &y: e[x])

int n,a[300010];
P b[300010];

void solve(){
	n=read();
	rep(i,1,n) a[i]=read()*(i&1?-1:1);
	ll S=0; b[0]=P(0,0);
	rep(i,1,n) S+=a[i],b[i]=P(S,i);
	sort(b,b+n+1);
	ll z=0; S=0;
	rep(i,1,n){
		S+=a[i];
		auto l=lower_bound(b,b+n+1,P(S,0));
		auto r=lower_bound(b,b+n+1,P(S,i));
//		printf("test %lld,%d: ",S,i);
//		rep(j,l-b,r-b-1) printf("%lld,%d  ",b[j].fi,b[j].se);
//		puts("");
		z+=r-l;
	}
	printf("%lld\n",z);
}

int main()
{
	for (int T=1;T--;) solve();
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
	cin.tie(nullptr)->sync_with_stdio(false);
	int h,w,a,b;
	cin >> h >> w >> a >> b;
	int ans = 0;

	for(int i = 0; i<(1<<((h-1)*w)); i++){
		for(int j = 0; j<(1<<((w-1)*h)); j++){
			if(__builtin_popcount(i)+__builtin_popcount(j)!=a)continue;
			vector<vector<int>>arr(h+1,vector<int>(w+1));
			int cur = 1;
			for(int a = 0; a<h-1; a++){
				for(int b = 0; b<w; b++){
					if((1<<(a*w+b))&i){
						arr[a][b] = cur; arr[a+1][b] = cur;
						cur++;
					}
				}
			}
			for(int b = 0; b<w-1; b++){
				for(int a = 0; a<h; a++){
					if((1<<(b*h+a))&j){
						arr[a][b] = cur; arr[a][b+1] = cur;
						cur++;
					}
				}
			}
			bool f = true;
			for(int a = 0; a<h-1; a++){
				for(int b = 0; b<w; b++){
					if((1<<(a*w+b))&i){
						if(arr[a][b]==arr[a+1][b]&&arr[a][b]>0){
							continue;
						}
						f = false;
					}
					else{
						if(arr[a][b]==0||arr[a+1][b]==0||arr[a][b]!=arr[a+1][b]){
							continue;
						}
						f = false;
					}
				}
			}
			for(int b = 0; b<w-1; b++){
				for(int a = 0; a<h; a++){
					if((1<<(b*h+a))&j){
						if(arr[a][b]==arr[a][b+1]&&arr[a][b]>0){
							continue;
						}
						f= false;
					}
					else{
						if(arr[a][b]==0||arr[a][b+1]==0||arr[a][b]!=arr[a][b+1]){
							continue;
						}
						f = false;
					}
				}
			}
			ans+=f;
		}
	}
	cout << ans << "\n";
	return 0;
}


#include <bits/stdc++.h>
#define inf 0x7fffffff
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;
const double pi = acos(-1);

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

ll ans;
char ch[2005][2005];
int pre[2005][2005][4], sum;
int n, m, bit[4000005];
int main(){
	int i, j;
	n = read(), m = read();
	bit[0] = 1;
	for(i = 1;i <= n * m;i++) bit[i] = bit[i - 1] * 2 % mod;
	for(i = 1;i <= n;i++) scanf("%s", ch[i] + 1);
	for(i = 1;i <= n;i++){
		int now = 0;
		for(j = 1;j <= m;j++){
			if(ch[i][j] == '#') now = 0;
			else now++, sum++;
			pre[i][j][0] = now;
		}
		now = 0;
		for(j = m;j >= 1;j--){
			if(ch[i][j] == '#') now = 0;
			else now++, sum++;
			pre[i][j][1] = now;
		}
	}
	for(i = 1;i <= m;i++){
		int now = 0;
		for(j = 1;j <= n;j++){
			if(ch[j][i] == '#') now = 0;
			else now++, sum++;
			pre[j][i][2] = now;
		}
		now = 0;
		for(j = n;j >= 1;j--){
			if(ch[j][i] == '#') now = 0;
			else now++, sum++;
			pre[j][i][3] = now;
		}
	}
	sum/=4;
	int ans = 0;
	for(i = 1;i <= n;i++){
		for(j = 1;j <= m;j++){
			if(ch[i][j] == '#') continue;
			int now = 0;
			for(int k = 0;k <= 3;k++) now += pre[i][j][k];
			now -= 3;
			ans = (ans + 1ll * (bit[now] - 1) * (bit[sum - now]) % mod) % mod;
		}
	}
	printf("%d\n", ans);
}

#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> T(N);
  for (int i = 0; i < N; i++){
    cin >> T[i];
  }
  int S = 0;
  for (int i = 0; i < N; i++){
    S += T[i];
  }
  vector<vector<bool>> dp(N + 1, vector<bool>(S + 1, false));
  dp[0][0] = true;
  for (int i = 0; i < N; i++){
    for (int j = 0; j <= S; j++){
      if (dp[i][j]){
        dp[i + 1][j] = true;
        dp[i + 1][j + T[i]] = true;
      }
    }
  }
  int ans = S;
  for (int i = 0; i <= S; i++){
    if (dp[N][i]){
      ans = min(ans, max(i, S - i));
    }
  }
  cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define ll                  long long
#define pb                  push_back
#define ppb                 pop_back
#define um                  unordered_map
#define MOD                 1000000007
#define rep(i,s,e)          for(int i=s; i<e; i++)
#define rrep(i,s,e)         for(int i=e-1; i>=s; i--)
#define all(x)              (x).begin(),(x).end()
#define uniq(v)             (v).erase(unique(all(v)),(v).end())
#define sz(x)               (int)((x).size())
#define ff                  first
#define ss                  second
#define mp                  make_pair
#define vi                  vector<int>
#define vpii                vector<pair<int,int>>
#define pii                 pair<int,int>
#define mem1(a)             memset(a,-1,sizeof(a))
#define mem0(a)             memset(a,0,sizeof(a))
#define google(test_no)     cout<<"Case #"<<test_no<<": ";
#define DEBUG true
#define deb(x) \
    if (DEBUG) \
        cerr << #x << " " << x << endl;
#define debarr(arrayName, s, n)          \
    if (DEBUG)                           \
    {                                    \
        cout << #arrayName << endl;      \
        for (ll i = s; i < n; i++)       \
            cout << arrayName[i] << " "; \
        cout << endl;                    \
    }
#define debarr2d(arrayName,s, n, m)             \
    if (DEBUG)                                  \
    {                                           \
        cout << #arrayName << endl;             \
        for (ll i = s; i < n; i++){             \
            for(ll j = s; j < m; j++){          \
                cout << arrayName[i][j] << " "; \
            }                                   \
         cout << endl;                          \
        }                                       \
    }
#define debv(vec)             \
    if (DEBUG)                \
    {                         \
        cout << #vec << " ";  \
        for (auto x : vec)    \
            cout << x << " "; \
        cout << endl;         \
    }
#define tc            \
    ll test_case;     \
    cin >> test_case; \
    while (test_case--)

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

void solve(int test){

    ll n;
    cin>>n;

    int i=1;
    while((ll)(i*(i+1))/2 < n){
        i++;
    }

    cout << i;
}

int main(){

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

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

 return 0;
}

#include<bits/stdc++.h>
typedef long long ll;
#define V(a) vector
#define P(a,b) pair
#define A(a) set
#define M(a,b) map
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define in insert
#define bp __builtin_popcount
#define ppb pop_back
#define FOR(a,b,c) for(ll(a) = b; a < c; a++)
#define FORN(a,b,c) for(ll(a) = b; a <= c; a++)
#define FOREV(a,b,c) for(ll(a)=b; a > c; a--)
#define FOREVN(a,b,c) for(ll(a)=b; a >= c; a--)
#define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
using namespace std;

bool cprime(int x)
{
    if (x == 1)
        return false;
    if (x <= 3)
        return true;
    if (x % 2 == 0 || x % 3 == 0)
        return false;
    for (int i = 5; i <= sqrt(x); i += 6)
        if (x % i == 0 || x % (i + 2) == 0)
            return false;
    return true;
}

bool cpalin(string s)
{
    int n = s.length(), l;
    if (n == 1)
        return true;
    if (n % 2 == 0)
        l = n / 2 - 1;
    else
        l = (n - 1) / 2 - 1;
    for (int i = 0; i <= l; i++)
        if (s[i] != s[n - i - 1])
            return false;
    return true;
}
void sieveOfEratosthenes(int n)
{
    bool arr[n + 1];
    FOR(i, 0, n + 1)
    arr[i] = true;
    for (int i = 2; i * i <= n; i++)
    {
        if (arr[i] == true)
        {
            for (int j = i * i ; j <= n; j += i)
            {
                if (arr[j] == true)
                    arr[j] = false;
            }
        }
    }
}

ll ndivs(ll n)
{
    int N = 1000;
    bool arr[N];
    FOR(i, 0, N)
    arr[i] = true;
    for (int i = 2; i * i <= N; i++)
    {
        if (arr[i] == true)
        {
            for (int j = i * i ; j <= N; j += i)
            {
                if (arr[j] == true)
                    arr[j] = false;
            }
        }
    }

    ll p = 1;
    FOR(i, 2, N)
    {
        if (arr[i] == true && n % i == 0)
        {
            ll m = 0; ll cp = n;
            while (cp % i == 0)
            {
                cp /= i;
                m++;
            }
            p *= (m + 1);
        }
    }
    return p;
}
bool compare( ll a,  ll b) // false return swap
{
    return a > b;
}

ll power( ll a, ll b)
{
    ll p = 1;
    ll N = 1e9+7;
    while (b > 0)
    {
        if (b & 1)
            p = (p%N * a%N)%N;
        a = (a%N*a%N)%N;
        b >>= 1;
    }
    return p;
}

string dtobin(ll n)
{
    string s;
    while (n)
    {
        s = to_string((n % 2)) + s;
        n /= 2;
    }
    return s;
}

ll bintod(string s)
{
    ll n = 0;
    FOR(i, 0, s.length())
    if (s[i] == '0')
        continue;
    else
        n += pow(2, (s.length() - 1 - i));
    return n;
}

ll sdigs(ll n)
{
    int s = 0;
    while (n)
    {
        s += n % 10;
        n /= 10;
    }
    return s;
}

ll fact(ll p)
{
    int x = 1;
    FORN(i, 1, p)
    x *= i;

    return x;
}
ll ncr(ll n , ll r)
{
    ll ans = (fact(n) ) / (fact(r) * fact(n - r));
    return ans;
}

ll __lcm(ll a, ll b)
{
    ll g = __gcd(a,b);
    return (a*b)/g;
}
int main() {

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

   ll n;
   cin >> n;
   ll c = 0;
   while(c*(c+1)/2<n)
    c++;
cout << c;
    return 0;
}


 #include <bits/stdc++.h>
        using namespace std;
        #define tani_nachi_ke  ios_base::sync_with_stdio(false); cin.tie(NULL);
        #define M_PI 3.14159265358979323846
        #define data data_
        #define ff first
        #define ss second
        #define pb push_back
        #define ld long double
        #define int long long
        #define print(t) cout << "Case #" << t << ": ";
        int32_t main()
        {
            tani_nachi_ke

            int n,m;
            cin >> n >> m;
            int a[n+1]={0},b[m+1]={0};
            for(int i = 1; i <= n; i++)
                cin >> a[i];
            for(int i = 1; i <= m; i++)
                cin >> b[i];
            sort(a+1, a+n+1);
            int suff[n+10] = {0}, pref[n+10] = {0};
            for(int i = n-1; i >= 1; i-=2)
            {
                suff[i] = a[i+1] - a[i];
                suff[i] += suff[i+2];
            }
            for(int i = 2; i <= n; i+=2)
            {
                pref[i] = a[i] - a[i-1];
                pref[i] += pref[i-2];
            }

            int ans = 1e18;
            // for(int i = 1; i <= n; i++)
            //     cout << a[i] << " ";
            // cout << endl;
            for(int i = 1; i <= m; i++)
            {
                int j = lower_bound(a+1, a+n+1, b[i]) - (a+1);
                // cout << j << endl;
                if(j%2)
                {
                    ans = min(ans, pref[j-1] + abs(b[i] - a[j]) + suff[j+1]);
                }
                else
                {
                    ans = min(ans, pref[j] + abs(b[i] - a[j+1]) + suff[j+2]);

                }
            }

            cout << ans << endl;

           return 0;
        }

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;
typedef vector<int> vi;

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

	int H, W;
	cin >> H >> W;
	vector<string> A(H);
	for(int i = 0; i < H; ++i) cin >> A[i];

	vector<vi> dp(H, vi(W));
	for(int i = H-1; i >= 0; --i) {
		for(int j = W-1; j >= 0; --j) {
			if(i == H-1 && j == W-1) {
				dp[i][j] = 0;
			} else if((i+j)&1) {
				dp[i][j] = H+W;
				if(i+1 < H) dp[i][j] = min(dp[i][j], dp[i+1][j] + (A[i+1][j] == '-' ? 1 : -1));
				if(j+1 < W) dp[i][j] = min(dp[i][j], dp[i][j+1] + (A[i][j+1] == '-' ? 1 : -1));
			} else {
				dp[i][j] = - (H+W);
				if(i+1 < H) dp[i][j] = max(dp[i][j], dp[i+1][j] + (A[i+1][j] == '+' ? 1 : -1));
				if(j+1 < W) dp[i][j] = max(dp[i][j], dp[i][j+1] + (A[i][j+1] == '+' ? 1 : -1));
			}
		}
	}

	if(dp[0][0] > 0) cout << "Takahashi\n";
	else if(dp[0][0] == 0) cout << "Draw\n";
	else cout << "Aoki\n";

	return 0;
}


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

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define pvec(v) for(auto e: v) cout << e << " ";
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define rep(i, a, b) for(int i = (a); i<(b); ++i)
#define pb push_back
#define INF 1000000005
#define MOD (1e18 + 5)
#define all(v) v.begin(), v.end()

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

ll power(ll x, ll y){
    ll res = 1LL;
    if (x == 0) return 0;
    while (y > 0){
        if (y & 1LL)
            res = (res*x);
        y = y>>1LL;
        x = (x*x);
    }
    return res;
}

long double log3(long double d) {
	return log(d*1.0)*1.0/log(3.0);
}

vi *adj;
vi vis, a, b;

void dfs(int u, ll &sum) {
	vis[u] = 1;
	sum += (a[u] - b[u])*1LL;
	for(int v: adj[u]) {
		if(!vis[v]) {
			dfs(v, sum);
		}
	}
}

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

	if(m < 0 || (m > 0 && m + 2 > n)) {
		cout << -1 << '\n';
		return 0;
	}
	if( m == 0) {
		int l = 1, r = 5;
		for(int i = 0; i < n; ++i) {
			cout << l << " " << r << '\n';
			l+=5;
			r+=5;
		}
		return 0;
	}
	else {
		ll l = 2, r = 5;
		for(int i = 0; i <= m; ++i) {
			cout << l << " " << r << '\n';
			l+=5;
			r+=5;
			--n;
		}
		cout << 1 << " " << r << '\n';
		--n;
		l+=5;
		r+=5;
		while(n) {
			cout << l << " " << r << '\n';
			l += 5;
			r += 5;
			--n;
		}
	}
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vi = vector<int>;
using vb = vector<bool>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vpll = vector<pll>;
const ll LINF = 1ll << 55;
const ll INF = 0x3f3f3f3f;
const ll MOD = 1e9 + 7;
const int MAXN = 1e5 + 10;
const ll dx[] = {1, 0, -1, 0};
const ll dy[] = {0, 1, 0, -1};

/// cin/cout overloading
template <typename T>
ostream &operator<<(ostream &out, const vector<T> &vec) {
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    out << *it << " ";
  }
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const pair<T, T> &P) {
  out << P.first << " " << P.second;
  return out;
}

template <typename T>
istream &operator>>(istream &in, vector<T> &vec) {
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    in >> *it;
  }
  return in;
}

template <typename T>
istream &operator>>(istream &in, pair<T, T> &P) {
  in >> P.first >> P.second;
  return in;
}

#define error(args...)                       \
  {                                          \
    string _s = #args;                       \
    replace(_s.begin(), _s.end(), ',', ' '); \
    stringstream _ss(_s);                    \
    istream_iterator<string> _it(_ss);       \
    err(_it, args);                          \
    cerr << endl;                            \
  }

void err(istream_iterator<string>) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << ", ";
  err(++it, args...);
}

#define rep(i, begin, end) \
  for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define all(x) (x).begin(), (x).end()
#define coutp(x, y) cout << (x) << " " << (y) << endl
#define coutn(x) cout << (x) << endl
#define coutd(x) cout << setprecision(10) << (x) << endl

ll calc(const string &S) {
  ll res = 0;
  for (int i = 1; i <= 9; ++i) {
    ll base = 1;
    for (auto c : S) {
      if (c - '0' == i) {
        base *= 10;
      }
    }
    res += i * base;
  }
  return res;
}

/// main函数
int main() {
  ll A, B;
  cin >> A >> B;
  double ans = (double(A) - B) / A * 100;
  coutd(ans);
  return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

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

  int A,B,C;
  cin>>A>>B>>C;

  if(A*A+B*B<C*C) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}

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

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

    if(b < c*d)
    {

        ll cy = a;
        ll r = 0;
        for(ll i = 0; ; i++)
        {
            //cout<<"r = "<<r<<" cy = "<<cy<<endl;
            if(r*d >= cy)
            {
                cout<<i<<endl;
                break;
            }
            cy += b;
            r += c;
        }
    }

    else
    {
        cout<<-1<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int N, Q;
const int maxn = 2e5 + 5;
typedef long long ll;
inline ll read()
{
    ll x = 0;
    int s = 1;
    char c = getchar();
    while (c < 48 || c > 57)
    {
        if (c == '-')
            s = -1;
        c = getchar();
    }
    while (c >= 48 && c <= 57)
    {
        x = (x << 3) + (x << 1) + c - '0';
        c = getchar();
    }
    return x * s;
}
int main()
{
    int N, Q;
    N = read();
    ll a, t;
    ll l = -1e9, r = 1e9, b = 0;
    for (int i = 0; i < N; i++)
    {
        a = read();
        t = read();
        if (t == 1)
        {
            l += a;
            r += a;
            b += a;
        }
        else if (t == 2)
        {
            l = max(l, a);
            r = max(r, a);
        }
        else
        {
            l = min(l, a);
            r = min(r, a);
        }
    }
    Q = read();
    while (Q--)
    {
        ll x = read() + b;
        if (x < l)
            cout << l;
        else if (x > r)
            cout << r;
        else
            cout << x;
        cout << ' ';
    }
}

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()

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


//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word
//ctrl+end - to break infinite loop in sublime text

#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
using namespace std;
#define Fio                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(nullptr);                 \
    cout.tie(nullptr)
#define ll long long int
#define fo(i, a, b) for (long long int i = a; i <= b; i++)
#define w(t)  \
    int t;    \
    cin >> t; \
    while (t--)
#define all(v) v.begin(),v.end()
#define vi vector<int>
#define vl vector<long long int>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long int>>
#define mii map<int, int>
#define umii unordered_map<int, int>
#define mll map<ll,ll>
#define umll unordered_map<ll,ll>
#define newl cout<<"\n"
#define pb push_back
#define mp make_pair
#define fi first
#define se second
const ll inf = 1e9+7;
const ll mod = 998244353 ;
#define MAX 200005

void call_priyanshu(){
    Fio;
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt", "w", stdout);
    #endif
}

ll mini(ll a,ll b){
    if(a>=b)return b;
    return a;
}

ll maxi(ll a,ll b){
    if(a>=b)return a;
    return b;
}

void run(ll n,ll d1,ll d2,ll d3,ll d4,ll d5,ll d6,vector<pair<ll,ll>> &A,vector<pair<ll,ll>> &B){
    if(d1>=d2){
        if((B[0]==A[0] && B[n-1]==A[n-1]) || (B[n-1]==A[0] && B[0]==A[n-1])){
            cout<<max(max(d3,d4),max(d5,d6));
            return;
        }else{
            cout<<max(d2,max(d3,d4));
            return;
        }
    }else{
        if((B[0]==A[0] && B[n-1]==A[n-1]) || (B[n-1]==A[0] && B[0]==A[n-1])){
            cout<<max(max(d3,d4),max(d5,d6));
            return;
        }else{
            cout<<max(d1,max(d5,d6));
            return;
        }
    }
}

void calc(vector<pair<ll,ll>> &A,vector<pair<ll,ll>> &B,ll n){
    ll v1 = abs(A[0].first - A[n-1].first);
    ll v2 = abs(B[0].first - B[n-1].first);
    ll v3 = abs(A[0].first - A[n-2].first);
    ll v4 = abs(A[1].first - A[n-1].first);
    ll v5 = abs(B[0].first - B[n-2].first);
    ll v6 = abs(B[1].first - B[n-1].first);
    run(n,v1,v2,v3,v4,v5,v6,A,B);
}

void solve(){
    //write your code here
    ll n;
    cin>>n;
    vector<pair<ll,ll>> A,B;
    for(ll i = 0;i<n;i++){
        ll x,y;
        cin>>x>>y;
        A.pb(mp(x,y));
        B.pb(mp(y,x));
    }
    sort(all(A)),sort(all(B));
    calc(A,B,n);

}

int main(){
    call_priyanshu();
    // w(T){
        solve();
    // }
    return 0;
}

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

const int MAXN = 101, MAXM = MAXN*MAXN;
int n, m, c[MAXN], a[MAXM], b[MAXM], dep[MAXN];
bool direc[MAXN][MAXN];
bool vis[MAXN];
vector<int> g[MAXN];
void dfs(int x, int prv) {
	vis[x] = 1;
	dep[x] = dep[prv]+1;
	for(int i: g[x]) {
		if(!vis[i]) {
			direc[x][i] = 1;
			dfs(i, x);
		}
	}
	for(int i: g[x]) {
		if(i!=prv && dep[i]<dep[x]) {
			direc[x][i] = 1;
		}
	}
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin>>n>>m;
	for(int i=0; i<m; ++i) {
		cin>>a[i]>>b[i];

	}
	for(int i=1; i<=n; ++i) {
		cin>>c[i];
	}
	for(int i=0; i<m; ++i) {
		if(c[a[i]] > c[b[i]]) {
			direc[a[i]][b[i]] = 1;
		}
		if(c[b[i]] > c[a[i]]) {
			direc[b[i]][a[i]] = 1;
		}
		if(c[a[i]]==c[b[i]]) {
			g[a[i]].push_back(b[i]);
			g[b[i]].push_back(a[i]);
		}
	}
	for(int i=1; i<=n; ++i) {
		if(!vis[i]) {
			dfs(i, i);
		}
	}
	for(int i=0; i<m; ++i) {
		if(direc[a[i]][b[i]]) cout<<"->\n";
		else cout<<"<-\n";
	}
}


// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int ll
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define ll long long
#define pi pair<int,int>
#define pii pair<pi,int>
#define vi vector<int>
#define pb push_back
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
ll fastexp(ll x,ll a){
    ll res = 1;
    while(a>0){
        if(a&1){
            res = (res*x)%mod;
        }
        a=a>>1;
        x=(x*x)%mod;
    }
    return res;
}
ll inverse(ll n){
    return fastexp(n,mod-2);
}
template <typename T>
void add(T &a, T b){
	a += b;
	if(a >= mod)a -= mod;
}
template <typename T>
void sub(T &a, T b){
	a -= b;
	if(a < 0)a += mod;
}
template <typename T>
void mul(T &a, T b){
	a *= b;
	if(a >= mod)a %= mod;
}
int n,k;
int a[10][10];
int ans;
void find(vi v,int cost,int cur){
	// cout<<cur<<" ";
	if(s(v) == 0){
		// cout<<cost<<"\n";
		if(cost + a[cur][0] == k){
			ans++;
		}
		return;
	}
	rep(i,s(v)){
		vi new_v;
		rep(j,s(v)){
			if(j == i)continue;
			new_v.pb(v[j]);
		}
		find(new_v,cost+a[cur][v[i]],v[i]);
	}
}
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>k;
	rep(i,n){
		rep(j,n){
			cin>>a[i][j];
		}
	}
	vi v;
	repa(i,1,n)v.pb(i);
	find(v,0,0);
	cout<<ans;
	return 0;
}


#include <vector>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
#define lo(i,a,b) for(int i=a; i<b; i++) // loop

int main(){
	int A, B;
	cin >> A >> B;
	int res = 2 * A + 100 - B;
	cout << res << endl;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
 ios_base::sync_with_stdio(0);
 cin.tie(0);
 int a, b;
 cin >> a >> b;
 cout << max (2 * a + 100 - b, 0) << '\n';
 return 0;
}


#include<bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
using namespace std;
inline int read(){
	int res=0;
	bool zf=0;
	char c;
	while(((c=getchar())<'0'||c>'9')&&c!='-');
	if(c=='-')zf=1;
	else res=c-'0';
	while((c=getchar())>='0'&&c<='9')res=(res<<3)+(res<<1)+c-'0';
	if(zf)return -res;
	return res;
}
const int maxn=2e5+5,P=998244353;
int f[maxn],g[maxn];
int p[maxn],r;
int v[maxn],inv[25];
signed main(){
	int n=read(),m=read(),ans=1;
	inv[1]=1;
	for(register int i=2;i<=20;++i){
		inv[i]=1ll*inv[P%i]*(P-P/i)%P;
	}
	for(register int i=2,t;i<=m;++i){
		if(!v[i]){
			f[i]=n,g[i]=1,p[++r]=i;
		}
		for(register int j=1;j<=r&&(t=i*p[j])<=m;++j){
			v[t]=1;
			if(i%p[j]){
				f[t]=1ll*f[i]*n%P,g[t]=1;
			}
			else{
				f[t]=1ll*f[i]*(n+g[i])%P*inv[g[i]+1]%P,g[t]=g[i]+1;
				break;
			}
		}
		ans+=f[i];
		(ans>=P)&&(ans-=P);
	}
	printf("%d\n",ans);
	return 0;
}

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

#define For(i,a,b)  for(int i=a;i<=b;i++)
#define Forr(i,a,b) for(int i=a;i>=b;i--)
#define F first
#define S second
#define L(id) (id<<1)
#define R(id) (id<<1|1)
#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 (ll)(1e9+7)
#define INF (ll)(1e15)
#define EPS (1e-6)

#ifdef LOCALMEOW
#define debug(...) do{\
	cerr << __PRETTY_FUNCTION__ << " - " << __LINE__ <<\
	" : ("#__VA_ARGS__ << ") = ";\
	_OUT(__VA_ARGS__);\
}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...); }
#else
#define debug(...)
#endif
inline void IOS(){ 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); }
int lcm(int a,int b) { return a/gcd(a,b)*b; }
int fpow(int b,int p){
	int ans=1,now=b;
	while(p){
		if(p&1) ans=ans*now%MOD;
		p/=2; now=now*now%MOD;
	}
	return ans;
}
void minify(int &a,int b) { if(b<a) a=b; }
void maxify(int &a,int b) { if(b>a) a=b; }

int32_t main(){
	IOS();
	//code...
	string s; cin>>s;
	int n=sz(s);
	int cnt[26];
	For(i,0,25) cnt[i]=0;
	int ans=0;
	Forr(i,n-1,1){
		if(s[i]==s[i-1]){
			ans+=n-i-1-cnt[s[i]-'a'];
			memset(cnt,0,sizeof(cnt));
			cnt[s[i]-'a']=n-i-1;
		}
		cnt[s[i]-'a']++;
	}
	cout<<ans<<"\n";
	return 0;
}


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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()

struct UnionFind{
  int num;//連結成分の数
  vector<int> r,p;//そのグループのサイズ,自分の親っぽいやつ
  vector<map<int,int>> mp;
  UnionFind(){}
  UnionFind(int n):num(n),r(n,1),mp(n),p(n,0){iota(p.begin(),p.end(),0);}

  int find(int x){//どのグループに所属するか
    return (x==p[x]?x:p[x]=find(p[x]));//xがグループの名前と一致するまでxを親にする
  }

  bool same(int x,int y){//同じグループかどうか
    return find(x)==find(y);
  }

  void unite(int x,int y){//xとyを同じグループにする
    x=find(x);y=find(y);//xとyのグループの名前をどっちかが変える
    if(x==y) return;
    if(mp[x].size()<mp[y].size()) swap(x,y);//サイズが大きい方をxとする
    for(auto p:mp[y])mp[x][p.first]+=p.second;
    p[y]=x;
    num--;
  }

  int size(int x){//グループの大きさ
    return r[find(x)];
  }

  int count() const{//グループの数
    return num;
  }
};

signed main(){
  int n,q;cin>>n>>q;
  UnionFind uf(n);
  REP(i,n){
    int c;cin>>c;c--;uf.mp[i][c]++;
  }
  REP(_,q){
    int c,a,b;cin>>c>>a>>b;a--;b--;
    if(c==1)uf.unite(a,b);
    else cout<<uf.mp[uf.find(a)][b]<<endl;
  }
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using iPair = pair<int,int>;
using lPair = pair<ll, ll>;
using ivector = vector<int>;
using lvector = vector<ll>;
using istack = stack<int>;
using iqueue = queue<int>;
using ivv = vector<vector<int>>;
using lvv = vector<vector<ll>>;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
vector<iPair> dir = {{1,0}, {-1,0}, {0,1}, {0,-1}};
#define dump(x) cout << #x << " = " << (x) << endl
#define ALL(x) begin(x),end(x)
#define rep(i,s,e) for(ll i=(s), i_stop=(e); i<i_stop; ++i)
#define repRev(i,s,e) for(ll i=(e)-1, i_stop=(s); i>=i_stop; --i)
#define range(i,s,n) for(ll i=(s), i_stop=(s)+(n); i<i_stop; ++i)
#define rangeRev(i,s,n) for(ll i=(s), i_stop=(s)-(n); i>i_stop; --i)
#define foreach(x,container) for(auto &&x:container)
bool chmax(ll& a, ll b) {if(a<b) {a=b;return true;} return false;}
bool chmin(ll& a, ll b) {if(a>b) {a=b;return true;} return false;}
template<typename T> void printArr(vector<T> &arr){
    for(auto &&x:arr) {cout << x << " ";} cout << endl;
}

/*

## 關鍵詞：

## 題意：

## 思路：

## 雜多：

*/

#define maxn 200000
int r[maxn+10];
int father[maxn+10];
map<int,int> group[maxn+10];

int find_top(int x) {
    if(father[x] == x) return x;
    else return (father[x] = find_top(father[x]));
}

void merge(int x, int y) {
    int fax = find_top(x);
    int fay = find_top(y);
    if(fax == fay) return;
    if(r[fax] < r[fay]) {
        father[fax] = fay;
        r[fay] += r[fax];
        for(auto&& [k,v]: group[fax]) {
            group[fay][k] += v;
        }
    }else{
        father[fay] = fax;
        r[fax] += r[fay];
        for(auto&& [k,v]: group[fay]) {
            group[fax][k] += v;
        }
    }
}

void solve() {
    // 預處理
    range(i, 1, maxn) {father[i] = i; r[i] = 1;}

    int n,q; cin>>n>>q;
    range(i, 1, n) {
        int c; cin>>c;
        group[i][c] = 1;
    }

    while(q--) {
        int op, x, y; cin>>op>>x>>y;
        if(op == 1) {
            merge(x, y);
        }else{
            cout << group[find_top(x)][y] << endl;
        }
    }
}

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


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

#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
//#define ld long double
#define mod 1000000007
//define inf 100000000000010
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf
//#define INF LONG_MAX
#define PI 3.1415926535897932384626
//#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(int x=j;x<n;x++)
#define repr(x,n,j)for(ll x=n;x>j;x--)
#define all(x) (x).begin(), (x).end()

typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> pi;
typedef long double ld;

mt19937 myrand(time(0));

bool isprime(ll n)
{
    if(n<=1)return false;
    if(n<=3)return true;
    if(n%2==0||n%3==0)return false;
    for(ll i=5;i*i<=n;i+=6)
    {
        if(n%i==0||n%(i+2)==0)return false;
    }
    return true;
}

ll modexp(ll a,ll b,ll m)
{
    ll r=1;
    a=a%m;
    while(b>0)
    {
        if(b&1)r=(r*a)%m;
        b = b>>1;
        a=(a*a)%m;
    }
    return r%m;
}

ll builtin_popcount(ll x)
{
    ll cnt = 0;
    for(ll i=60;i>=0;i--)
    {
        if((1LL<<i)&x)cnt++;
    }
    return cnt;
}

ll addmod(ll a,ll b)
{
    a%=mod;
    b%=mod;
    return (a+b)%mod;
}
ll mulmod(ll a,ll b)
{
    a%=mod;
    b%=mod;
    return (a*b)%mod;
}
ll submod(ll a,ll b)
{
    a%=mod;
    b%=mod;
    a-=b;
    if(a<0)a+=mod;
    return a%mod;
}

struct CustomCompare
{
    bool operator()(pi a,pi b)
    {
        return a.fi<b.fi;
    }
};
/*
const int mxn = 5*(1e6) +10;
vi spf(mxn);
void sieve()
{
    for(ll i =0;i<mxn;i++)spf[i]  = i;
    for(ll i=2;i<mxn;i+=2)spf[i] = 2;
    for(ll i = 3;i*i<mxn;i++)
    {
        if(spf[i]==i)
        {
            for(ll j = i*i;j<mxn;j+=i)
            {
                if(spf[j]==j)spf[j] = i;
            }
        }
    }
}
*/

const int mxn = 18;

ll adj[mxn][mxn];

bool check[(1LL<<mxn)];
ll dp[(1LL<<mxn)];

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

ll n,m; cin>>n>>m;

rep(i,0,m)
{
    ll x,y; cin>>x>>y;
    --x,--y;
    adj[x][y] = adj[y][x] = 1;
}

//cout<<"ok"<<endl;
rep(i,1LL,1LL<<n)
{
    vi arr;
    rep(j,0,n)if((1LL<<j)&i)arr.pb(j);

    check[i] = true;
    ll sz = arr.size();
    rep(j,0,sz)
    {
        rep(k,j+1,sz)
        {
            ll x = arr[j] ,y = arr[k];
            if(!adj[x][y]&&!adj[y][x])check[i] = false;
        }
    }
}
//cout<<"ok"<<endl;
rep(i,1LL,1LL<<n)dp[i] = 1e10;
dp[0] = 0;

rep(i,1LL,1LL<<n)
{
    if(check[i])dp[i] = 1;
    for(ll j=i;j;j=(j-1LL)&i)dp[i] = min(dp[i],dp[j]+dp[i^j]);
}
cout<<dp[(1LL<<n)-1];
return 0;

}
/*
1
4 7
...*...
..***..
.****..
*******

*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define endl '\n'
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef long double ld;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define frev(a,b,c) for(int a=c; a>=b; a--)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
#define done(x) {cout << x << endl;return;}
#define mini(x,y) x=min(x,y)
#define maxi(x,y) x=max(x,y)
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
//const int mod = 998244353;
const int mod = 1e9 + 7;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vpii;
typedef map<int, int> mii;
typedef set<int> si;
typedef set<pair<int,int>> spii;
typedef queue<int> qi;
uniform_int_distribution<int> rng(0, 1e9);

//DEBUG FUNCTIONS START
#define cerr cout
void __print(int 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...);}
#ifdef LOCAL
#define deb(x...)  _print(x)
#else
#define deb(x...)
#endif
// DEBUG FUNCTIONS END

const int N = 2e5 + 5;
vpii g[N];
int f[60][2];

void dfs(int v, int p, int msk){

    rep(i,0,60){
        f[i][msk >> i & 1]++;
    }

    for(auto [to, w] : g[v]){
        if(to != p){
            dfs(to, v, msk ^ w);
        }
    }

}

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

void solve(){

    int n;
    cin >> n;

    fr(i,2,n){
        int u, v, w;
        cin >> u >> v >> w;
        g[u].pb({v, w});
        g[v].pb({u, w});
    }

    dfs(1, 1, 0);

    int ans = 0;

    rep(i,0,60){
            ans += (1ll << i) % mod * f[i][0] % mod * f[i][1] % mod;
            ans %= mod;
    }

    cout << ans << endl;

}

signed main() {

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

    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(15);
    int t = 1;
    //cin >> t;

    while (t--)
        solve();
    return 0;
}

int divide(int a, int b) {
    return (a % mod) * powm(b % mod, mod - 2) % mod;
}


#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri();
	int a[n];
	for (auto &i : a) i = ri();

	int res = 2000000000;
	for (int i = 0; i < 1 << (n - 1); i++) {
		int xored = 0;
		int ored = 0;
		for (int j = 0; j <= n; j++) {
			if (j < n) ored |= a[j];
			if (j == n || (i >> j & 1)) xored ^= ored, ored = 0;
		}
		res = std::min(res, xored);
	}

	printf("%d\n", res);
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    long long int count=0;
    cin>>n;
    int ar[n]={};
    int arr[200]={};
    for (int i = 0; i < n; i++)
    {
        cin>>ar[i];
    }
    for (int i = 0; i < n; i++)
    {
        arr[ar[i]%200]++;
    }
    for (int i = 0; i <n; i++)
    {
       if ((arr[ar[i]%200])>1)
       {
           count=count+arr[ar[i]%200]-1;

       }
       arr[ar[i]%200]--;

    }
    cout<<count;
return 0;
}


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

int main()
{
    int t;
    t=1;
    while(t--)
    {
        string s;
        cin>>s;
        for(int i=s.size()-1;i>=0;i--)
        {
            if(s[i]=='9')
                cout<<6;
            else if(s[i]=='6')
                cout<<9;
            else
                cout<<s[i];
        }
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
#define all(x) (x).begin(),(x).end()
#define fr first
#define sc second
#define nl '\n'

void solve(){

    ll n;cin>>n;
    ll ans=0;
    ll a[5]={999,999999,999999999,999999999999,999999999999999};
    int i=0;
    while(n-a[i]>0 && i<5){
        ans+=n-a[i];
        i++;
    }
    cout<<ans;

}

int main(){

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

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

return 0;
}


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

int n,ans;
string a;

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

	for(int i=0;i<n;i++)
	{
		map <char,int> m;
		for(int j=i;j<n;j++)
		{
			m[a[j]]++;
			if(m['A']==m['T'] and m['C']==m['G']) ans++;
		}
	}
	cout<<ans;
}

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

#include<bits/stdc++.h>

using namespace std;

#define fast                     ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ll                       long long
#define ld                       long double
#define endl                     '\n'
#define all(A)                   (A).begin(),(A).end()
#define traceA(A,x)              cerr<<#A<<": ";for(int i = 0; i < (x) ; ++i) cerr<<A[i]<<' ';cerr<<endl
#define traceV(A)                cerr<<#A<<": ";for(auto i:A)cerr<<i<<' ';cerr<<endl
#define traceM(A,n,m)            cerr<<#A<<": "<<endl;for(int i = 0; i < (n) ; ++i){for(int j = 0; j < (m) ; ++j) cerr << A[i][j] << ' ';cerr << endl;}

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

const int N = 2e5 + 77;
int A[N], C[N], G[N], T[N];
int a , c, g, t;

void sol(){
    int n ;  cin >> n ;
    string s ; cin >> s;
    for(int i = 0 ; i < n ; ++i){
        if(s[i] == 'A') A[i+1]++;
        if(s[i] == 'C') C[i+1]++;
        if(s[i] == 'G') G[i+1]++;
        if(s[i] == 'T') T[i+1]++;
    }
    {
        for(int i = 1; i <= n ; ++i){
            a += A[i];
            A[i] = a;
        }
        for(int i = 1; i <= n ; ++i){
            c += C[i];
            C[i] = c;
        }
        for(int i = 1; i <= n ; ++i){
            g += G[i];
            G[i] = g;
        }
        for(int i = 1; i <= n ; ++i){
            t += T[i];
            T[i] = t;
        }
    }

    // traceA(A,n+1);
    // traceA(C,n+1);
    // traceA(G,n+1);
    // traceA(T,n+1);
    int ans = 0;

    for(int l = 1 ; l <= n ; ++l){
        for(int r= l+1; r <= n ; ++r){
            a = A[r]-A[l-1];
            c = C[r]-C[l-1];
            g = G[r]-G[l-1];
            t = T[r]-T[l-1];
            if(a == t && c == g) ans++;
        }
    }
    cout << ans << endl;
}

int32_t main(){
    fast;
    int t  = 1;
    // cin >> t;
    // while(t--)
    sol();
    return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> at(n);
  ll pinf = 4e18, minf = -4e18, bias = 0;
  rep(i, n) {
    ll a, t;
    cin >> a >> t;
    if(t == 1) {
      bias += a;
      pinf += a;
      minf += a;
    }
    if(t == 2) {
      pinf = max(pinf, a);
      minf = max(minf, a);
    }
    if(t == 3) {
      pinf = min(pinf, a);
      minf = min(minf, a);
    }
  }
  int q;
  cin >> q;
  while(q--) {
    ll x;
    cin >> x;
    ll ans = min(pinf, max(minf, x+bias));
    cout << ans << endl;
  }
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
#define pb push_back
#define mp make_pair
const ll INF = 1e16;
const int MOD = 1e9+7;
const int MAX_N = 2e5+12;
int N, Q;
ll a[MAX_N],t[MAX_N];
ll x[MAX_N];

void solve()
{
	ll lo = -INF, hi = INF, add = 0;
	for(int i=0;i<N;++i){
		if(t[i]==1){
			add += a[i];
			lo += a[i];
			hi += a[i];
		}else if(t[i]==2){
			lo = max(lo, a[i]);
			hi = max(hi, a[i]);
		}else{
			lo = min(lo, a[i]);
			hi = min(hi, a[i]);
		}
	}
	for(int i=0;i<Q;++i){
		cout<<min(hi,max(lo, x[i]+add))<<'\n';
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	cin >> N;
	for(int i=0;i<N;++i)cin>>a[i]>>t[i];
	cin >> Q;
	for(int i=0;i<Q;++i)cin>>x[i];
	solve();
	return 0;
}


#include<bits/stdc++.h>
#define mod 998244353
using namespace std;
struct DSU{
    int n;
    int parent[55];
    int size[55];
    void init(int _n){
        n = _n;
        for(int i=1;i<=n;i++){
            parent[i]=i;
            size[i]=1;
        }
    }
    int findSet(int i){
        if(parent[i]==i)return i;
        return parent[i]=findSet(parent[i]);
    }
    void unionSet(int u, int v){
        u = findSet(u), v = findSet(v);
        if(u!=v){
            if(size[u]<size[v]){
                parent[u]=v;
                size[v]+=size[u];
            }else{
                parent[v]=u;
                size[u]+=size[v];
            }
        }
    }
    vector<int>sz(){
        vector<int>res;
        for(int i=1;i<=n;i++){
            if(parent[i]==i)res.push_back(size[i]);
        }
        return res;
    }
};
long long fact(int n){
    if(n==1)return 1;
    else return (n%mod*fact(n-1)%mod)%mod;
}
int main(){
    int n,K;cin>>n>>K;
    int a[n+5][n+5];
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            cin>>a[i][j];

    DSU dsu;
    dsu.init(n);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            bool valid = true;
            for(int k=1;k<=n;k++){
                if(a[k][i] + a[k][j] > K){
                    valid=false;
                    break;
                }
            }if(valid)dsu.unionSet(i,j);
        }
    }
    long long ans = 1;
    for(int x : dsu.sz()){
        // cout<<x<<endl;
        ans = (1LL * fact(x) * ans )%mod;
    }

    dsu.init(n);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            bool valid = true;
            for(int k=1;k<=n;k++){
                if(a[i][k] + a[j][k] > K){
                    valid=false;
                }

            }if(valid){
                    dsu.unionSet(i,j);
                }
        }
    }
    for(int x : dsu.sz()){
       ans = (ans * 1LL * fact(x))%mod;
    }
    cout<<ans<<endl;
}

#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#include<cstdio>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	if ((tmp & ma0) ^ ma0) {
		int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
		tmp = tmp << dig & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += (72 - dig >> 3);
	}
	else {
		tmp = tmp & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += 8;
		if ((ct = *ci++) >= '0') {
			tmp = tmp * 10 + ct - '0';
			if (*ci++ == '0') {
				tmp = tmp * 10;
				ci++;
			}
		}
	}
	return tmp;
}

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

	int N = getint();
	int kotae = 2e9;

	rep(i, N) {
		int a = getint();
		int p = getint();
		int x = getint();
		if (a < x && p < kotae) kotae = p;
	}

	if (kotae > 1e9) printf("-1");
	else printf("%d", kotae);

	Would you please return 0;
}


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

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

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

    s64 s, p;
    cin >> s >> p;

    string ans = "No";
    for (s64 n = 1; n * n <= p; ++n)
    {
        if (p % n == 0)
        {
            s64 m = p / n;
            if (n + m == s) ans = "Yes";
        }
    }

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define nline "\n"
const ll M1=1e9+7;
const ll M=998244353;
const ll N=100005;
const ll INF_ADD=1e18;
const ll INF_MUL=1e13;
#define f first
#define s second
#define pll pair<ll,ll>
#ifndef ONLINE_JUDGE
#define debug(x) cerr<<#x<<" "; _print(x); cerr<<nline;
#else
#define debug(x);
#endif
void _print(ll x){cerr<<x;}
template<class T,class V> void _print(pair<T,V> p) {cerr<<"{"; _print(p.first);cerr<<","; _print(p.second);cerr<<"}";}
template<class T>void _print(vector<T> v) {cerr<<" [ "; for (T i:v){_print(i);cerr<<" ";}cerr<<"]";}
template<class T>void _print(set<T> v) {cerr<<" [ "; for (T i:v){_print(i); cerr<<" ";}cerr<<"]";}
template<class T>void _print(multiset<T> v) {cerr<< " [ "; for (T i:v){_print(i);cerr<<" ";}cerr<<"]";}
template<class T,class V>void _print(map<T, V> v) {cerr<<" [ "; for(auto i:v) {_print(i);cerr<<" ";} cerr<<"]";}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ll optimal(ll x,ll t){
    ll sq=sqrt(x);
    set<ll> comp;
    comp.insert(t+x/(t+1));
    if(sq>t)
        comp.insert(sq+x/(sq+1));
    sq++;
    if(sq>t)
        comp.insert(sq+x/(sq+1));
    sq++;
    if(sq>t)
        comp.insert(sq+x/(sq+1));
    sq=sqrt(x);
    sq--;
    if(sq>t)
        comp.insert(sq+x/(sq+1));
    sq--;
    if(sq>t)
        comp.insert(sq+x/(sq+1));
    ll best=*(comp.begin());
    return best;
}
void solve(){
    ll n,m; cin>>n>>m;
    vector<vector<pll>> adj(n+2);
    vector<ll> ans(n+5,INF_ADD);
    priority_queue<pll> prefer;
    prefer.push({0,1});
    vector<vector<ll>> a(m+4,vector<ll>(5,0));
    ans[1]=0;
    for(ll i=1;i<=m;i++){
        for(ll j=1;j<=4;j++)
            cin>>a[i][j];
        adj[a[i][1]].pb({a[i][2],i});
        adj[a[i][2]].pb({a[i][1],i});
    }
    while(prefer.size()){
        auto it=prefer.top();
        prefer.pop();
        if(ans[it.s]!=-it.f)
            continue;
        ll node=it.s,instant=-it.f;
        for(auto chld:adj[node]){
            ll compare=(a[chld.s][3]+optimal(a[chld.s][4],instant));
            if(compare<ans[chld.f]){
                prefer.push({-compare,chld.f});
                ans[chld.f]=compare;
            }
        }
    }
    if(ans[n]!=INF_ADD)
        cout<<ans[n];
    else
        cout<<"-1";

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif
    ll t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    /*
    Correct data type?
    Infinity?
    Base case?
    */
    cerr<<"Time:"<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms\n";
}


#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define vec(s) vector<s>
#define vvec(s) vector<vector<s>>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli, lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes(x) cout << (x ? "Yes" : "No") << endl;
#define YES(x) cout << (x ? "YES" : "NO") << endl;
#define out(s) cout << s << endl;
#define Reverse(x) reverse(all(x));
#define Sort(x) sort(all(x));
#define pb(s) push_back(s);
#define sp " "
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(), s.end()
void vout(vi v)
{
    for (lli i = 0; i < v.size(); i++)
        cout << v.at(i) << endl;
}
vvi dp(1 << 17, vi(17,-1));
lli n;
vvi place(17, vi(3));
lli rec(lli s, lli v)
{
    if (dp[s][v] >= 0)
    {
        return dp[s][v];
    }
    if (s == (1 << n) - 1 && v == 0)
    {
        return dp[s][v] == 0;
    }
    lli tmp = INF;
    rep(i, n)
    {
        if (!(s >> i & 1))
        {
            lli p = (abs(place[v][0] - place[i][0]) + abs(place[v][1] - place[i][1]) + max((lli)0, place[i][2] - place[v][2]));
            //out("P" << p);
            if (p==0)
            {
                p = INF;
            }
            //out("P" << p <<"S" << s << "G" << v);
            tmp = min(tmp, rec(s | 1 << i, i) +p);
            //out(rec(s | 1 << i, i) + p << "S" << s << "G" << v);
        }
    }
    return dp[s][v]=tmp;
}
int main()
{
    cout << std::fixed << std::setprecision(10);

    cin >> n;
    rep(i, n)
    {
        lli a, b, c;
        cin >> a >> b >> c;
        place[i][0] = a;
        place[i][1] = b;
        place[i][2] = c;
    }
    out(rec(0, 0));
}

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

#define endl '\n'
typedef long long int ll;

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

	int n;cin >> n;
	vector<vector<int>> dist(n, vector<int>(n));
	vector<tuple<int, int, int>> pos;
	vector<vector<int>> dp(n, vector<int>(1 << n, 2e9));
	dp[0][0] = 0;
	for(int i = 0;i < n;i++){
		int x, y, z;cin >> x >> y >> z;
		pos.emplace_back(x, y, z);
	}
	for(int i = 0;i < n;i++){
		for(int j = 0;j < n;j++){
			if(i == j)continue;
			dist[i][j] = abs(get<0>(pos[i]) - get<0>(pos[j])) +
									abs(get<1>(pos[i]) - get<1>(pos[j])) +
									max(0, get<2>(pos[j]) - get<2>(pos[i]));
		}
	}
	for(int i = 0;i < (1 << n);i++){
		for(int j = 0;j < n;j++){
			for(int k = 0;k < n;k++){
				if(j != k && dp[j][i] != INT_MAX){
					dp[k][i | (1 << k)] = min(dp[k][i | (1 << k)], dp[j][i] + dist[j][k]);
				}
			}
		}
	}
	cout << dp[0][(1 << n) - 1] << endl;
}


//#include <atcoder/maxflow.hpp>
#include <memory>
#include <iostream>
#include <map>
#include <list>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>
#include <complex>
#include <thread>

#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s

typedef long long ll;

using namespace std;
//using namespace atcoder;

ll modd = (1000LL * 1000LL * 1000LL + 7LL);
//ll modd = 998244353;

int main()   {

    ios_base::sync_with_stdio(false);

    cout.precision(17);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int> rand_gen(0, modd);   // rand_gen(rng) gets the rand no

    auto start = chrono::steady_clock::now();

//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readint(n);
        int ct = 0;
        forr(i,1,n) {
            bool has7 = false;
            int nn = i;
            while (nn>0) {
                if (nn%10==7) {has7=true;}
                nn/=10;
            }
            nn = i;
            while (nn>0) {
                if (nn%8==7) {has7=true;}
                nn/=8;
            }
            if (!has7) {
                ++ct;
            }
        }
        cout << ct << endl;
    }
//        auto stop = chrono::steady_clock::now();
//        auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start);
//        cout << "Duration: " << duration.count() << endl;
    return 0;
}

#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
//#include <atcoder/all>
//using namespace atcoder;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<vector<vector<int>>> v3int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef vector<vector<vector<ll>>> v3ll;
typedef list<int> liint;
typedef pair<int, int> pint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, int>> vpll_int;
typedef vector<pair<int, ll>> vpint_ll;
typedef set<pair<int, int>> spint;
typedef set<pair<ll, int>> spll;
typedef unordered_map<int, unordered_set<int>> Graph;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }

bool is_seven10(int x) {
    string s = to_string(x);
    rep(i, s.size()) {
        if (s[i] == '7') return true;
    }
    return false;
}

bool is_seven8(int x) {
    while (1) {
        if (x < 8) {
            break;
        }
        int t = x % 8;
        if (t == 7) return true;
        x /= 8;
    }
    if (x == 7) return true;
    return false;
}

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

    ll ans = 0;
    REP(x, 1, N + 1) {
        if (is_seven8(x) == true) continue;
        if (is_seven10(x) == true) continue;
        ans++;
    }
    cout << ans << endl;
    return 0;
}