#include <bits/stdc++.h>

long long int sum_arr(long long int start, long long int end) {
    if (start < 0 || end < 0) {
        return 0;
    }
    return (start + end) * (start - end + 1) / 2;
}

int main() {
    long long int N, K;
    std::cin >> N >> K;

    long long int res = K;
    for (long long int l = 3; l <= 3 * N; l++) {
        long long int c0 = (l - 1) * (l - 2) / 2;
        long long int c1 = sum_arr(l - 1 - (N + 1), 0) * 3;
        long long int c2 = sum_arr(l - 1 - N - (N + 1), 0) * 3;
        long long int c = c0 - c1 + c2;
        if (res - c <= 0) {
            // i + j + k == l
            // std::cout << l << " , " << res << std::endl;
            // std::cout << "l = " << l << std::endl;
            for (long long int i = std::max(1ll, l - 2 * N); i <= N; i++) {
                long long int jk = l - i;  // sum of j and k
                long long int cnt = std::min(N, jk - 1) - std::max(1ll, jk - N) + 1;
                // std::cout << i << " " << jk << " " << cnt << std::endl;
                // std::cout << i << " " << jk << " " << cnt << std::endl;
                if (res - cnt <= 0) {
                    long long int j = std::max(1ll, jk - N) + res - 1;
                    std::cout << i << " " << j << " " << l - i - j << std::endl;
                    return 0;
                }
                res -= cnt;
            }
            // std::cout << res << std::endl;
            // break;
        }
        res -= c;
    }
}


// Author :- Sarvesh Chaudhary
#include<bits/stdc++.h>
using namespace std;
#define w(x) int x; cin>>x; while(x--)
#define ll long long int
#define sidha(i,a,b) for(int i=a;i<b;i++)
#define set_built(x) __builtin_popcountll(x)
#define zero_built(x) __bultin_ctzll(x)
#define pairi pair<int,int>
#define vi vector<int>
#define mod 1000000007
#define MAX INT_MAX
#define MIN INT_MIN
#define pb push_back
#define po pop_back
#define all(c) c.begin(),c.end()
#define io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

//Global Variable
map<int,int> m;

//Functions

//Driver Function
int main(){
	io;
    double a,b,c,d;cin>>a>>b>>c>>d;
    double x=d/a;
    if(x>c or x<b){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
	return 0;
}

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

int main()
{
    lli a,b,c,d,t,n,x,y,z,i,j,k,s,v;
    cin>>v>>s>>t>>d;
    if(d>=v*s && d<=v*t)
    {
        cout<<"No"<<endl;
    }
    else
    {
        cout<<"Yes"<<endl;
    }
    return 0;
}


#include <stdio.h>

int main()
{
    int arr[3], remaining = 0;
    scanf("%d %d %d", &arr[0], &arr[1], &arr[2]);

    bool flag = false;
    for (int i = 0; i <= 1; i++)
    {
        for (int j = i + 1; j <= 2; j++)
        {
            if (arr[i] == arr[j])
            {
                flag = true;
                if (i == 1)
                {
                    remaining = arr[0];
                }
                else
                {
                    (j == 1) ? remaining = arr[2] : remaining = arr[1];
                }
                break;
            }
        }
        if (flag && remaining != 0)
        {
            break;
        }
    }

    printf("%d\n", remaining);

    return 0;
}

#pragma GCC optimize("Ofast")
/*#pragma GCC target("avx,avx2,fma")
#pragma GCC target ("sse4")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld double
#define rep(i,a,b) for(ll i=a; i<b; ++i)
#define BOOST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(v) v.begin(),v.end()
#define sl(a) a.size()
#define mod 1000000007
#define lcm(a,b) (a*b)/__gcd(a,b)
#define MAX1 100006
#define f first
#define s second
#define pi 2*acos(0.0)
bool isPowerOfTwo (ll x) {  return x && (!(x&(x-1)));  }
ll Modular_Exponentiation(ll x, ll n, ll M)
{
    if(n==0) return 1;
    if(n%2) return (x*Modular_Exponentiation((x*x)%M,n/2,M))%M;
    else return (Modular_Exponentiation((x*x)%M,n/2,M))%M;
}
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;
}
/********************************************************************************************/
void solve()
{
    char s,t; cin>>s>>t;
    if(s=='Y') cout<<char(toupper(t));
    else cout<<t;
}
int32_t main()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt","r",stdin);
    //for getting error from error.txt
    freopen("error.txt", "w", stderr);
    // for writing output to output.txt
    freopen("output.txt","w",stdout);
    #endif
    BOOST
    int T=1; //cin>>T;
    while(T--) solve();
    cerr<<"Time taken : "<<fixed<<setprecision(5)<<((float)clock()/CLOCKS_PER_SEC)*1000<<" ms"<<"\n";
    cerr<<"My CLOCKS_PER_SEC= "<<CLOCKS_PER_SEC<<"\n";
    return 0;
}


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

int main() {
  int n, L;
  cin >> n >> L;
  auto input = [&]() {
    vector<int> a(n);
    for (auto&& e : a) {
      cin >> e;
    }
    a.emplace_back(L + 1);
    for (auto i = 0; i <= n; i++) a[i] -= i + 1;
    for (auto i = n; i; i--) a[i] -= a[i - 1];
    return a;
  };
  auto a = input();
  auto b = input();
  int l = 0;
  long ans = 0;
  for (auto i = 0; i <= n; i++) {
    int w = b[i];
    if (!w) continue;
    while (l <= n && !a[l]) ++l;
    int r = l;
    int sum = 0;
    while (r <= n && sum < w) {
      sum += a[r];
      r++;
    }
    if (sum > w) {
      cout << "-1\n";
      return 0;
    }
    ans += max(0, i - l);
    ans += max(0, r - 1 - i);
    l = r;
  }
  cout << ans << endl;
}


#include <iostream>
#include <vector>
#include <queue>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i < n + 1; i++)
#define all(A) A.begin(), A.end()
typedef long long ll;
using P = pair<int, int>;

struct E
{
    int to, co;
    E(int a, int b)
    {
        to = a;
        co = b;
    }
};

struct node
{
    int dis, pos;
    node(int a, int b)
    {
        dis = a;
        pos = b;
    }
};

int n, m;
vector<vector<E>> g;
const int INF = (int)1e9;

void solve(int sv)
{
    vector<int> dist(n+1, INF);
    vector<bool> seen(n+1, 0);
    priority_queue<P, vector<P>, greater<P>> q;
    for (E next : g[sv])
    {
        if (next.co >= dist[next.to]){
            continue;
        }
        q.emplace(make_pair(next.co, next.to));
        dist[next.to] = next.co;
    }
    while (!q.empty())
    {
        node now = node(q.top().first, q.top().second);
        q.pop();
        for (E next : g[now.pos])
        {
            int this_route = now.dis + next.co;
            if (this_route >= dist[next.to])
            {
                continue;
            }
            q.emplace(make_pair(this_route, next.to));
            dist[next.to] = this_route;
        }
    }
    int ans = dist[sv];
    if (ans == INF)
    {
        ans = -1;
    }
    cout << ans << endl;
}

int main()
{
    cin >> n >> m;
    g.resize(n+1);
    rep(i, m)
    {
        int a, b, c;
        cin >> a >> b >> c;
        g[a].push_back(E(b, c));
    }
    rep1(sv, n)
    {
        solve(sv);
    }
    return 0;
}

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

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
// You should only debug a pair of simple data types. For example,
// the debug won't work if one of pair's elements is collection type
// (std::vector, std::map, std::set...).
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

// Shortcuts for "common" data types in contests
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<char,char> pcc;
typedef pair<char,int> pci;
typedef pair<int,char> pic;
typedef vector<pii> vpii;
typedef set<int> si;
typedef set<ll> sll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
#define ff first
#define ss second
#define endl '\n'
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define rep(i, a, b) for(int i = a; i < b; i++)
#define repv(c, it) \
for(auto it = (c).begin(); it != (c).end(); it++)
#define repm(c, it) \
for(mll::iterator it = (c).begin(); it != (c).end(); it++)
const long long inf = 9223372036854775807;
#define pb push_back
const long long mod = 1000000007;
const double pi = acos(-1);

int main() {
 //decreases the time taken by cin,cout.
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
//freopen("error.txt", "w", stderr);
freopen("output.txt", "w", stdout);
#endif

    int n;cin>>n;

mii m;
    rep(i,0,n)
    {
        int x;cin>>x;
        if(m.find(x)==m.end()){m[x]=1;}
        else{cout<<"No";return 0;}
    }
    cout<<"Yes";

    return 0;
}


#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read()
{
	int x=0;
	bool flag=1;
	char c=getchar();
	while(c<'0'||c>'9')
	{
		if(c=='-')
			flag=0;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return (flag?x:~(x-1));
}
int a,b,c,d;
signed main()
{
	a=read();
	b=read();
	c=read();
	d=read();
	int l=0,r=1e8;
	while(l<=r)
	{
		int mid=(l+r)>>1;
		int x=a+mid*b,y=mid*c;
		if(y*d>=x)
			r=mid-1;
		else
			l=mid+1;
	}
	if(l==1e8+1)
		puts("-1");
	else
		cout<<l<<endl;
	return 0;
}

#include<bits/stdc++.h>
#define vll vector<long long>
#define ll long long
#define dbg(x) cout << #x << " " << x <<endl;
#define forn(i,n) for(int i=0;i<(int)n;i++)
#define farn(i,x,n) for(int i=x;i<=(int)n;i++)
#define rforn(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,s,n) for(int i=s;i<n;i++)
#define sz(x) ((int)x.size())
#define clr(x) memset(x,0,sizeof(x))
#define sa(v) sort(v.begin(), v.end())
#define sd(v) sort(v.begin(),v.end(), greater<int>())
#define pb push_back
#define mp make_pair
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define ff first
#define ss second
#define cl(a,b) (a+b-1)/b
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)
const int mod = 1000000007;//1e9+7
const int INF = 2e9 + 2;
const int N = 2e5+5;

using namespace std;

ll a, b, c, d;
void sol ()
{
    cin >> a >> b>>c>>d;

    if(d*c - b <= 0)cout<<-1;
    else
        cout<<cl(a,(d*c - b));

    cout<<endl;

}

int main(){
    int TC;
    TC = 1;
    // cin >> TC;
    while (TC--)
    {
        sol();

    }
    return 0;
}


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

#ifdef LOCAL
#include <debugger.h>
#else
#define dbg(x...) {}
#define dbg_t()   {}
#endif

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

const ll INF = 1e18;

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

  vector<string> grid(n);
  for (ll i = 0; i < n; i++)
    cin >> grid[i];

  dbg(grid);

  auto in = [&](ll x, ll y)
  {
    return (x >= 0 && y >= 0 && x < n && y < m);
  };

  vector<vector<array<ll, 2>>> dp(n, vector<array<ll, 2>>(m, {INF, INF}));

  function<array<ll, 2>(ll, ll)> rec = [&](ll a, ll b)
  {
    dbg(a, b);

    array<ll, 2> r = {0ll, 0ll};

    if ((a == n - 1) && (b == m - 1))
      return r;

    if (!in(a, b))
      return r;

    array<ll, 2> d = {INF, INF};

    if (dp[a][b] != d)
      return dp[a][b];

    array<ll, 2> x1 = rec(a, b + 1), x2 = rec(a + 1, b);

    array<ll, 2> ans1 = {0, INF}, ans2 = {0, INF}, ans;

    if (in(a, b + 1))
    {
      if (grid[a][b + 1] == '+')
        ans1 = {x1[1] + 1, x1[0]};
      else
        ans1 = {x1[1] - 1, x1[0]};
    }

    if (in(a + 1, b))
    {
      if (grid[a + 1][b] == '+')
        ans2 = {x2[1] + 1, x2[0]};
      else
        ans2 = {x2[1] - 1, x2[0]};
    }

    if ((ans1[0] - ans1[1]) > (ans2[0] - ans2[1]))
      ans = ans1;
    else
      ans = ans2;

    return dp[a][b] = ans;
  };

  array<ll, 2> res = rec(0, 0);

  dbg(res);

  if (res[0] > res[1])
    cout << "Takahashi" << "\n";
  else if (res[1] > res[0])
    cout << "Aoki" << "\n";
  else
    cout << "Draw" << "\n";
}

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

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

  ll _t = 1;
  // cin >> _t;
  for (ll i = 1; i <= _t; i++)
  {
    // cout << "Case #" << i << ": ";
    solve();
  }

  dbg_t();

  return 0;
}

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

#define mp make_pair
#define pb push_back
#define ll long long int
#define sdll(x) scanf("%lld",&x)
#define sd(x) scanf("%d",&x)
#define inf (ll)(1e18+9)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define bits(x) __builtin_popcount(x)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define bitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define ld long double
#define test() ll test; cin>>test; while(test--)
#define fi first
#define se second

inline ll GCD(ll x, ll y) {
    if(x<y) swap(x,y);
    if(x==0) return y;
    if(y==0) return x;
    return GCD(x%y,y);
}

ll phi(ll n) {
    ll result = n;
    for (ll i = 2; i * i <= n; i++) {
        if(n % i == 0) {
            while(n % i == 0)
                n /= i;
            result -= result / i;
        }
    }
    if(n > 1)
        result -= result / n;
    return result;
}

ll power(ll x, ll n, ll mod) {
    ll res = 1;
    x %= mod;
    while(n) {
        if(n&1) {
            res = ((res*x)%mod+mod)%mod;
        }
        x = ((x*x)%mod+mod);
        n>>=1;
    }

    return res;
}

const int MAXN = 2005;
const ll INIT_VALUE = -inf;

int H,W;
ll dp[MAXN][MAXN];
char mat[MAXN][MAXN];

void clear() {
    for(int i=0;i<=H;i++) {
        for(int j=0;j<=W;j++) {
            dp[i][j] = INIT_VALUE;
        }
    }
}

inline bool check(int x ,int y) {
    return x>=1 && x<=H && y>=1 && y<=W;
}

inline ll getvalue(int x, int y) {
    return mat[x][y]=='+'?1:-1;
}

ll solve(int x, int y);

ll solving(int x, int y) {
    ll ans = -inf;
    if(mat[x][y]=='+') {
        if(check(x+1,y) && check(x,y+1)) {
            ans = max(ans,1+min(solve(x+1,y)-getvalue(x+1,y),solve(x,y+1)-getvalue(x,y+1)));
        } else if(check(x+1,y)) {
            ans = max(ans,1+solve(x+1,y)-getvalue(x+1,y));
        } else if(check(x,y+1)) {
            ans = max(ans,1+solve(x,y+1)-getvalue(x,y+1));
        } else {
            ans = 1;
        }
    } else {
        if(check(x+1,y) && check(x,y+1)) {
            ans = max(ans,-1+min(solve(x+1,y)-getvalue(x+1,y),solve(x,y+1)-getvalue(x,y+1)));
        } else if(check(x+1,y)) {
            ans = max(ans,-1+solve(x+1,y)-getvalue(x+1,y));
        } else if(check(x,y+1)) {
            ans = max(ans,-1+solve(x,y+1)-getvalue(x,y+1));
        } else {
            ans = -1;
        }
    }
    return ans;
}

ll solve(int x, int y) {
    if(!check(x,y)) {
        return -inf;
    }

    if(x==H && y==W) return 0;

    if(dp[x][y]!=INIT_VALUE) return dp[x][y];

    ll ans = -inf;

    if(check(x+1,y)) {
        ans = max(ans,solving(x+1,y));
    }

    if(check(x,y+1)) {
        ans = max(ans,solving(x,y+1));
    }

    // cout<<x<<" "<<y<<" "<<ans<<endl;

    return dp[x][y] = ans;
}

int main() {
    fastio;

    cin>>H>>W;

    for(int i=1;i<=H;i++) {
        for(int j=1;j<=W;j++) {
            cin>>mat[i][j];
        }
    }

    clear();

    ll ans = solve(1,1);
    if(ans>0) {
        cout<<"Takahashi"<<endl;
    } else if(ans<0) {
        cout<<"Aoki"<<endl;
    } else {
        cout<<"Draw"<<endl;
    }

}


#include <iostream>
#include <vector>
using namespace std;
int main(void){
    long long N,M,T;
    cin >> N >> M >> T;
    long long start, end, now, B;
    B = N;
    now = 0;
    for(int i=0;i<M;i++){
        cin >> start >> end;
        B -= start-now;
        if(B<=0){
            cout << "No";
            return 0;
        }
        // cout << B << endl;
        B = min(N, B+end-start);
        // cout << B << endl;
        now = end;
    }
    if(B-(T-now)<=0) cout << "No";
    else cout << "Yes";
    return 0;

}

		                         ///−In the name of God −///

//In mathematics, an unordered pair or pair set is a set of the form {a, b},
//i.e. a set having two elements a and b with no particular relation between them.
//In contrast, an ordered pair (a, b) has a as its first element and b as its second element.
//So, (a,b)!=(b,a) in ordered pair but it is in case of unordered pair.
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define   ll  long long int
#define   dl double
#define   llu unsigned long long int
#define   scll(x) scanf("%lld",&x)
#define   scld(x) scanf("%lf",&x)
#define   scull(x) scanf("%llu",&x)
#define   scch(x) scanf(" %c",&x)
#define   eb(x)   emplace_back(x)
#define   pb(x) push_back(x)
#define   pf(x) push_front(x)
#define   ppb() pop_back()
#define   ppf() pop_front()
#define   Pi acos(-1.0)
#define   inf 1000000000000000000
#define   mod 1000000007
#define   ff first
#define   ss second
#define   mpr make_pair
#define   debug(x) cout<<x<<'\n';
#define   MAX 1000000
#define   eps 1e-8
#define   nl  cout<<'\n'
#define   ump unordered_map
#define   mp  map
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_multiset;
//Taking input by EOF
//while(scanf("%lld",&x)!=-1){ }
// Creates a min heap
//priority_queue <int, vector<int>, greater<int> > pq;
//sin((x*pi)/180.0)[x in degree]
//sin(x)[x in radian]
//asin(x)[radian]
//(asin(x)*180)/pi[degree]
//or(|)//and(&)//xor(^)//not(~)
//S.order_of_key(x)[Give me the position of x]
//S.find_by_order(x)[Give me the x th element in set]
//pair can no te used as index in Unordered_map
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//Knight moves
ll dx[8]={-2,-2,2,2,-1,-1,1,1};
ll dy[8]={1,-1,1,-1,2,-2,2,-2};
ll lcm(ll a, ll b) {return (a * b) / __gcd(a, b);}
int main()
{
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ll a, b, c = 0, d, e, f = 0, g, h, i, j = 0, k, m, n, o, p, s, t, v, w, x = 0, y, z, l, res = 0;
  ll cnt = 0, l1 = 0, l2, l3, c1 = 0, c2 = 0, c3 = 0, mx = 0, mn = inf;
  ll prevsum = 0, ans1 = 0, ans2 = 0, odd = 0, even = 0, hh, mm;
  string str, str1, str2, str3 = "", str4 = "";
  ll ide = 0, idx = 0, Q;
  ll xa, xy;

      /*scll(t);
      while(t--)
      {

      }*/

 scll(n);
 scll(m);
 scll(t);
 ll ans=n;
 ll prev=0;
 f=0;
for(i=0;i<m;i++)
{
  scll(a);
  ans-=a-prev;
  if(ans<=0)
  	{
  		f=1;
  	}
  scll(b);
 ans+=b-a;
 if(ans>n)
 	ans=n;
 prev=b;
}

ans-=t-prev;
if(ans<=0)
f=1;
//cout<<ans;

if(f)
	cout<<"No";
else
	cout<<"Yes";

return 0;
}


#include <bits/stdc++.h>

using namespace std;

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

#define REP(i, a, b) for (ll i = a; i <= b; i++)
#define REP_REV(i, a, b) for (ll i = a; i >= b; i--)
#define debug(x) cerr << #x << " is " << x << endl;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define endl "\n"

#define pb push_back
#define rsz resize
#define f first
#define s second
#define mp make_pair

using ll = int64_t;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vc = vector<char>;
using ull = unsigned int64_t;
using pi = pair<int, int>;
using vl = vector<int64_t>;
using pl = pair<int64_t, int64_t>;
using vpl = vector<pair<int64_t, int64_t>>;
using msl = map<string, int64_t>;
using vvl = vector<vector<int64_t>>;

#define DBG1(x) cerr << (#x) << ": " << (x) << endl;
#define DBG2(x, y) cerr << (#x) << " " << (#y) << ": " << (x) << " " << y << endl;
#define DBG3(x, y, z) cerr << (#x) << " " << (#y) << " " << (#z) << ": " << (x) << " " << y << " " << z << endl;
#define DBG4(a, b, c, d) cerr << (#a) << " " << (#b) << " " << (#c) << " " << (#d) << ": " << a << " " << b << " " << c << " " << d << endl;
template <class T>
void DBGvec(vector<T> a) {
    for (T i : a) cerr << i << " ";
    cerr << endl;
}

const ll MOD = 1e9 + 7;
const int INF = int(1e9);

bool isPrime(ll n) {
    if (n == 1) return false;
    if (n == 2) return true;
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

unsigned long long factorial(int n) {
    const unsigned int M = MOD;
    unsigned long long f = 1;
    for (int i = 1; i <= n; i++)
        f = (f * i) % M;
    return f;
}

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

void solve() {
    ll n, q;
    string s;
    cin >> n >> s >> q;
    bool turn = 1;
    REP(i, 0, q - 1) {
        ll t, a, b;
        cin >> t >> a >> b;
        if (t == 1) {
            if (turn) {
                swap(s[a - 1], s[b - 1]);
            } else {
                if (a <= n && b <= n) {
                    swap(s[n + a - 1], s[n + b - 1]);
                } else if (a > n && b > n) {
                    swap(s[a - n - 1], s[b - n - 1]);
                } else if (a <= n && b > n) {
                    swap(s[n + a - 1], s[b - n - 1]);
                }
            }
        } else {
            turn = !turn;
        }
    }
    if (turn) {
        cout << s;
    } else {
        cout << s.substr(n, n) + s.substr(0, n);
    }
}

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

#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    int tt = clock();
#endif

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

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

#ifdef _DEBUG
    cerr << "\nTIME = " << clock() - tt << endl;
    tt = clock();
#endif
    return 0;
}

//ver 8.1
#include <bits/stdc++.h>
using namespace std;
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vd = vector<ld>;
using vs = vector<string>;
using vb = vector<bool>;
using vvl = vector<vector<ll>>;
using vvd = vector<vector<ld>>;
using vvs = vector<vector<string>>;
using vvb = vector<vector<bool>>;
using pll = pair<ll,ll>;
using mll = map<ll,ll>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
#define each(x,v) for(auto& x : (v))
#define reps(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define mp make_pair
const ll INF = 1LL << 60;
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) ((a)<=(x)&&(x)<=(b))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) //被り削除
#define debug cout << "line : " << __LINE__ << " debug" << endl;
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ind(...) long double __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define inc(...) char __VA_ARGS__; in(__VA_ARGS__)
void in(){}
template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
template <typename T> void in1(T &s) {rep(i,s.size()){in(s[i]);}}
template <typename T> void in2(T &s,T &t) {rep(i,s.size()){in(s[i],t[i]);}}
template <typename T> void in3(T &s,T &t,T &u) {rep(i,s.size()){in(s[i],t[i],u[i]);}}
template <typename T> void in4(T &s,T &t,T &u,T &v) {rep(i,s.size()){in(s[i],t[i],u[i],v[i]);}}
template <typename T> void in5(T &s,T &t,T &u,T &v,T &w) {rep(i,s.size()){in(s[i],t[i],u[i],v[i],w[i]);}}
void out(){cout << endl;}
template <typename T,class... U> void out(const T &t,const U &...u){cout << t; if(sizeof...(u)) cout << " "; out(u...);}
void die(){cout << endl;exit(0);}
template <typename T,class... U> void die(const T &t,const U &...u){cout << t; if(sizeof...(u)) cout << " "; die(u...);}
template <typename T> void outv(T s) {rep(i,s.size()){if(i!=0)cout<<" ";cout<<s[i];}cout<<endl;}
template <typename T> void out1(T s) {rep(i,s.size()){out(s[i]);}}
template <typename T> void out2(T s,T t) {rep(i,s.size()){out(s[i],t[i]);}}
template <typename T> void out3(T s,T t,T u) {rep(i,s.size()){out(s[i],t[i],u[i]);}}
template <typename T> void out4(T s,T t,T u,T v) {rep(i,s.size()){out(s[i],t[i],u[i],v[i]);}}
template <typename T> void out5(T s,T t,T u,T v,T w) {rep(i,s.size()){out(s[i],t[i],u[i],v[i],w[i]);}}
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
template <typename T> T allSum(vector<T> a){T ans=T();each(it,a)ans+=it;return ans;}
template<typename T> bool inside(T a,T b){auto it=a.begin()-1;each(x,b){it=find(it+1,a.end(),x);if(it==a.end())return false;}return true;}
ll ceilDiv(ll a,ll b) {return (a+b-1)/b;}
ld dist(pair<ld,ld> a, pair<ld,ld> b){return sqrt(abs(a.fi-b.fi)*abs(a.fi-b.fi)+abs(a.se-b.se)*abs(a.se-b.se));} // ２点間の距離
ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b;}
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
#define YES(n) ((n) ? "YES" : "NO"  )
#define Yes(n) ((n) ? "Yes" : "No"  )
#define yes(n) ((n) ? "yes" : "no"  )

int main(){
  init();
  inl(n,k);
  ll ans=0;
  rep(i,n)rep(j,k){
    ll a=(i+1)*100+j+1;
    ans+=a;
  }
  out(ans);
  return 0;
}


#include <bits/stdc++.h>
// #define x first
// #define y second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
const int N = 2e5 + 20;

int n, t;
bool vis[N];

int main()
{
	IOS; cin >> t >> n;
	// LL l = 1, r = 1e13, res = 1;
	// while(l <= r)
	// {
		// LL mid = l + r >> 1;
		// if(t * mid >= n * 100ll)
		// {
			// r = mid - 1;
			// res = mid;
		// }
		// else l = mid + 1;
	// }
	// cout << res + n - 1 << endl;
	cout << (100ll * n + t - 1) / t + n - 1 << endl;
	return 0;
}

#include<bits/stdc++.h>
#define int long long
#define ls (rt<<1)
#define rs (rt<<1|1)
#define pii pair<int,int>
#define fi first
#define se second
#define rd(u) u=read()
#define endl '\n'
using namespace std;

const int N=2e6+5;
const int M=1e7+5;
const int mod=1e9+7;
const int inf=3e18;
inline int read(){int u=0,f=1;char ch=getchar();while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){u=u*10+ch-'0';ch=getchar();}return u*f;}
int ksm(int u,int y=mod-2,int z=mod){int ret=1;while (y){if (y&1) ret=(ret*u);u=(u*u);y>>=1;}return ret;}
int t,n,m,ans;
int x[N],y[N];
signed main()
{
	rd(t);rd(n);
	for (int a=1;a<=100;a++)
	{
		int b=(100+t)*a/100;
		x[b]=1;
	}
	for (int i=1;i<=100+t;i++) if (!x[i]) y[++m]=i;
	//for (int i=1;i<=m;i++) cout<<y[i]<<" ";cout<<endl;
	n--;
	ans=(n/m)*(100+t);
	ans+=y[(n%m+1)];
	cout<<ans<<endl;
}


#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <numeric>
#include <algorithm>
#include <queue>
#include <bitset>
using namespace std;
#define rep(i,n)  for(int i=0 ; i<(n) ; ++i)
typedef long long ll;
typedef pair<int,int> p;
const int MOD = 1000000000+7;
const int INF = 1001000100;

int main(){
  ll n;
  cin >> n;
  ll a[n];
  rep(i,n) cin>>a[i];

  //dp。i番目までに作業をして、i番目を+で足したか-で足した時の和と、その場合の数を足していく。
  ll dp[n][2][2];//+で足した時の(和、場合の数）、-で足した時の（和、場合の数）
  dp[0][0][0] = a[0];
  dp[0][0][1] = 1;
  dp[0][1][0] = 0;
  dp[0][1][1] = 0;
  for(int i=1 ; i<n ; ++i){
    dp[i][0][0] = dp[i-1][0][0] + dp[i-1][1][0] + (dp[i-1][0][1]+dp[i-1][1][1])*a[i];
    dp[i][0][0] = dp[i][0][0] % MOD;
    dp[i][1][0] = dp[i-1][0][0] + dp[i-1][0][1]*(MOD - a[i]);
    dp[i][1][0] = dp[i][1][0] % MOD;
    dp[i][0][1] = (dp[i-1][0][1] + dp[i-1][1][1]) %MOD;
    dp[i][1][1] = dp[i-1][0][1] % MOD;
  }

  cout << (dp[n-1][0][0] + dp[n-1][1][0])%MOD;

  return 0;
}

#include <bits/stdc++.h>
#define N 567
typedef long long ll;
using namespace std;
const int P = 998244353;
inline void read(int &x) {
	scanf("%d", &x);
}
int n, m;
char s[N];
int bin[N + N];
inline void Set(int p, int v) {
	if (bin[p] == -1) {
		bin[p] = v;
	} else {
		if (bin[p] ^ v) {
			puts("0"); exit(0);
		}
	}
}
int main() {
	read(n), read(m);
	memset(bin, -1, sizeof(bin));
	for (int i = 1; i <= n; ++i) {
		scanf("%s", s + 1);
		for (int j = 1; j <= m; ++j) if (s[j] != '.')
			Set(i + j, s[j] == 'R' ? 0 : 1);
	}
	int ans = 1;
	for (int i = 2; i <= n + m; ++i) if (bin[i] == -1) ans = (ans + ans) % P;//bug
	printf("%d\n", (ans % P + P) % P);
	return 0;
}


#include <bits/stdc++.h>
#define ALL(x) (x).begin(),(x).end()
using namespace std;
using ll = long long int;
using ull = unsigned long long int;
const ll INF=LLONG_MAX;
const int inf=INT_MAX;
const ull md=1000000000;//10^9

void out(int ans){
  cout << ans << endl;
  exit(0);
}

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

  int N;
  cin >> N;
  for(int i=1; ; i++){
    if(1+(1+i)*i/2 > N){
      cout << i << endl;
      break;
    }
  }
  return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main() {
string a, saida = "";
cin >> a;

int i = 0;
while(a[i] != '.' && i < a.length()){
    saida += a[i];
    i++;
}
cout << saida << endl;

return 0;
}


#include <bits/stdc++.h>

using namespace std;

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

    cout << (1 << n) - 1 << '\n';
    for (int i = 1; i < 1 << n; ++i) {
        for (int j = 0; j < 1 << n; ++j) {
            if (__builtin_popcount(i & j) & 1) {
                cout << 'B';
            } else {
                cout << 'A';
            }
        }
        cout << '\n';
    }

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int in();
ll sol(ll i){
	if(i%200==0)	i/=200;
	else	i=i*1000+200;
	return i;
}
int main(){
	ll n,k;
	n=in();k=in();
	for(int i=1; i<=k; i++)	n=sol(n);
	cout<<n;
	return 0;
}
int in(){
	ll nn=0,ff=0;
	char cc;
	cc=cin.get();
	while((cc<'0' || cc>'9') && cc!='-')	cc=cin.get();
	if(cc=='-')	ff=1;
	else	nn=cc-'0';
	cc=cin.get();
	while(cc>='0' && cc<='9'){
		nn=nn*10+cc-'0';
		cc=cin.get();
	}
	if(ff==1)	return -nn;
	return nn;
}

#include <bits/stdc++.h>
using namespace std;
// #define LOCAL // 提出時はコメントアウト
#define DEBUG_

typedef long long ll;
const double EPS = 1e-9;
const ll INF = ((1LL<<62)-(1LL<<31));
typedef vector<ll> vecl;
typedef pair<ll, ll> pairl;
template<typename T> using uset = unordered_set<T>;
template<typename T, typename U> using mapv = map<T,vector<U>>;
template<typename T, typename U> using umap = unordered_map<T,U>;

#define ALL(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define sz(x) (ll)x.size()
ll llceil(ll a,ll b) { return (a+b-1)/b; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> vector<vector<T>> genarr(ll n, ll m, T init) { return vector<vector<T>>(n,vector<T>(m,init)); }

///// DEBUG
#define DUMPOUT cerr
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
template<typename T>istream&operator>>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<typename T,typename U>ostream&operator<<(ostream&os,pair<T,U>&pair_var){os<<"("<<pair_var.first<<", "<<pair_var.second<<")";return os;}
template<typename T>ostream&operator<<(ostream&os,const vector<T>&vec){os<<"{";for(int i=0;i<vec.size();i++){os<<vec[i]<<(i+1==vec.size()?"":", ");}
os<<"}";return os;}
template<typename T,typename U>ostream&operator<<(ostream&os,map<T,U>&map_var){os<<"{";repi(itr,map_var){os<<*itr;itr++;if(itr!=map_var.end())os<<", ";itr--;}
os<<"}";return os;}
template<typename T>ostream&operator<<(ostream&os,set<T>&set_var){os<<"{";repi(itr,set_var){os<<*itr;itr++;if(itr!=set_var.end())os<<", ";itr--;}
os<<"}";return os;}
void dump_func(){DUMPOUT<<endl;}
template<class Head,class...Tail>void dump_func(Head&&head,Tail&&...tail){DUMPOUT<<head;if(sizeof...(Tail)>0){DUMPOUT<<", ";}
dump_func(std::move(tail)...);}
#ifndef LOCAL
#undef DEBUG_
#endif
#ifdef DEBUG_
#define DEB
#define dump(...)                                                          \
DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
        << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
        << endl                                                            \
        << "    ",                                                         \
    dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif

//////////

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

int solve(ostringstream &cout) {
    #ifdef LOCAL
    ifstream in("../../Atcoder/input.txt");
    cin.rdbuf(in.rdbuf());
    #endif

    ll N,K;
    cin>>N>>K;

    rep(i,K) {
        if (N % 200 == 0) N /= 200;
        else {
            N *= 1000, N += 200;
        }
    }

    cout << N << endl;

    return 0;
}

int main() {
    ostringstream oss;
    int res = solve(oss);

    cout << oss.str();
    return res;
}


/*  *Which of the favors of your Lord will you deny ?*  */
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define vpnt(ans)                       \
    for (ll i = 0; i < ans.size(); i++) \
        cout << ans[i] << (i + 1 < ans.size() ? ' ' : '\n');
#define setbit(x, k) (x |= (1LL << k))
#define clearbit(x, k) (x &= ~(1LL << k)) //x er last theke k-1 tomo ghor
#define checkbit(x, k) (x & (1LL << k))
#define mp make_pair
#define scl(x) scanf("%lld", &x)
#define sci(x) scanf("%d", &x)
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ff first
#define ss second
#define pii pair<int, int>
#define YES printf("YES\n")
#define Yes printf("Yes\n")
#define yes printf("yes\n")
#define NO printf("NO\n")
#define No printf("No\n")
#define no printf("no\n")
#define nn cout << "\n";
#define INF (1 << 30)
#define LL_INF (1LL << 32)
#define pll pair<ll, ll>
#define pp(n, p) (ll)(pow(n, p) + 0.5)
#define ok ios::sync_with_stdio(false);
#define fine cin.tie(nullptr);
#define mod 1000000007
#define N 100005

int main()
{
    ll n;
    cin>>n;
    vector<int>a, b;
    for(int i=0; i<n; i++)
    {
        ll x;
        cin>>x;
        a.pb(x);
    }
    ll res = 0;
    for(int i=0; i<n; i++)
    {
        ll x;
        cin>>x;
        res += x*a[i];
    }
    if(res == 0) Yes;
    else No;

}

#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define int long long
typedef vector<int> vi;typedef vector<vi> vvi;

signed main(){
ios::sync_with_stdio(0);cin.tie(0);
#ifndef ONLINE_JUDGE
freopen("E:\\in.txt","r", stdin);
#endif
	int n; cin >> n;
	vi a(n), b(n);
	for(int i =0; i < n; i++){
		cin >> a[i];
	}
	for(int i =0; i < n; i++){
		cin >> b[i];
	}
	int x =0 ;
	for(int i =0; i < n; i++){
		x += a[i] * b[i];
	}
	cout << (x ? "No":"Yes") << '\n';
}


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

vector<vector<int64_t>> v_comb(100,vector<int64_t>(100));
int64_t comb(int64_t x, int64_t y){
    if(x < 0 || y < 0 || x < y) return 0;
    if(y == 0 || x == y) return 1;
    if(v_comb[x][y] != 0) return v_comb[x][y];
    int64_t rtn = comb(x-1,y-1)+comb(x-1,y);
    v_comb[x][y] = rtn;
    return rtn;
}

int main(){
    int a, b;
    int64_t k;
    cin >> a >> b >> k;

    int ai = a;
    int bi = b;
    int64_t mink = 1;
    int64_t maxk = comb(a+b,a)+1;
    string ans;
    for(int i = 0; i < a+b; i++){
        if(k < comb(ai+bi-1,ai-1)+mink){
            ans.push_back('a');
            maxk = comb(ai+bi-1,ai-1)+mink;
            ai--;
        }
        else{
            ans.push_back('b');
            mink = comb(ai+bi-1,ai-1)+mink;
            bi--;
        }
    }

    cout << ans << endl;
}

#include <bits/stdc++.h>

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

constexpr bool typetest = 0;
constexpr int N = 35 + 5;
int a, b;
ll k;

void Read()
{
    cin >> a >> b >> k;
}

ll Pow(ll a, ll b)
{
    ll ans(1);
    for (; b > 0; b >>= 1)
    {
        if ((b & 1))
            ans = ans * a;
        a = a * a;
    }
    return ans;
}

ll Cals(ll x, ll y)
{
    ll ans(0);
    while (y >= x)
        ans += (y /= x);

    return ans;
}

ll Cal(int x, int y)
{
    int n = x + y;
    ll ans(1);
    bitset<N> ck;
    for (int i = 2; i <= n; ++i)
        if (!ck[i])
        {
            ans *= Pow(i, Cals(i, n) - Cals(i, x) - Cals(i, y));
            for (int j = i; j <= n; j += i)
                ck[j] = 1;
        }
    return ans;
}

void Solve()
{
    int n = a + b;
    for (int i = 1; i <= n; ++i)
    {
        //cerr << i << "\n";
        if (a > 0 && Cal(a - 1, b) >= k)
            cout << 'a', --a;
        else
            cout << 'b', k -= Cal(a - 1, b), --b;
    }
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t(1);
    if (typetest)
        cin >> t;
    for (int _ = 1; _ <= t; ++_)
    {
        Read();
        Solve();
    }
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;

int main()
{
    int N;
    cin>>N;
    vector<string> S(N);
    for (string &s: S)
        cin>>s;

    int oo = 9999;
    vector<vector<int>> D(N, vector<int>(N, 9999));
    for (int i=0; i<N; i++)
        for (int j=0; j<N; j++)
            if (S[i][j]=='1')
                D[i][j] = 1;
    for (int i=0; i<N; i++)
        D[i][i] = 1;
    for (int i=0; i<N; i++)
        for (int j=0; j<N; j++)
            for (int k=0; k<N; k++)
                D[k][j] = min(D[k][j], D[k][i]+D[i][j]);

    double ans = 0;
    for (int i=0; i<N; i++)
    {
        int c = 0;
        for (int j=0; j<N; j++)
            if (D[j][i]<oo)
                c++;
        ans += 1./c;
    }

    printf("%.16f\n", ans);
}

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

#ifndef aa
#define trace(...)
#define endl '\n'
#endif
#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(1,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...);}
#ifndef ONLINE_JUDGE
//#define deb(x...) cerr << "[" << #x << "] = "; _print(x)
#define deb(x...)  _print(x)
#else
#define deb(x...)
#endif
// DEBUG FUNCTIONS END

const int N = 1e3+5;
vi g[N];

void solve(){

	int n;
	cin>>n;
	ld ans = 0;
	vs a(n);
	rep(i,0,n){
		cin>>a[i];
		rep(j,0,n){
			if(a[i][j]=='1')
				g[j].pb(i);
		}
	}

	rep(i,0,n){
		int cnt = 0;
		vi vis(n);
		qi q;
		q.push(i);
		vis[i] = 1;
		while(q.size()){
			int v = q.front();
			q.pop();
			cnt++;
			trav(to, g[v]){
				if(!vis[to]){
					vis[to] = 1;
					q.push(to);
				}
			}
		}
		ans += (ld)1/cnt;
	}

	cout << ans;

}

signed main() {
    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 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;
}

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

int norm(int a) {
    while (a >= mod) a -= mod;
    while (a < 0) a += mod;
    return a;
}


#include <bits/stdc++.h>
#define ll long long
#define INF 1000000007
using namespace std;
bool visited[2001];
ll dist[2001];
vector<pair<int,int>> adj[2001];
int edges[2001][2001];
int main()
{
	int N,M;
	cin>>N>>M;
	memset(edges,0,sizeof(edges));
	memset(dist,INF,sizeof(dist));
	for(int i=1; i<=M; i++)
	{
		int A,B;
		ll C;
		cin>>A>>B>>C;
		adj[A].push_back({C,B});
		if(edges[A][B]==0 || C<edges[A][B])
		{
			edges[A][B]=C;
		}
	}
	priority_queue<pair<int,int>> q;

	for(int i=1; i<=N; i++)
	{

		dist[i]=0;
		q.push({0,i});
		while(!q.empty())
		{
			long long a=q.top().second;
			q.pop();
			if(visited[a])
			{
				continue;
			}
			visited[a]=true;
			for(auto u: adj[a])
			{
				long long b=u.second;
				long long w=u.first;
				if(dist[a]+w<dist[b])
				{
					dist[b]=dist[a]+w;
					q.push({-dist[b],b});
				}
			}
		}
		ll minn=INF;
		for(int j=1; j<=N; j++)
		{
			if(dist[j]==INF)
			{
				continue;
			}
			if(edges[j][i]>0)
			{
				ll temp= dist[j]+edges[j][i];
				if(temp<minn)
				{
					minn=temp;
				}
			}
		}
		if(minn==INF)
		{
			cout<<"-1"<<endl;
		}
		else
		{
			cout<<minn<<endl;
		}
		memset(visited,false,sizeof(visited));
		for(int j=1; j<=N; j++)
		{
			dist[j]=INF;
		}

	}
    return 0;

}

#include<bits/stdc++.h>
#define ll                  long long
#define dl                 long double
#define pb                push_back
#define F                  first
#define S                  second
#define endl              "\n"
#define rep(i,a,b)       for(i=a;i<b;i++)
#define all(v)             v.begin(),v.end()
#define allr(v)            v.rbegin(),v.rend()
#define mod              1000000007LL
#define CIN(V,s,n)      for(int i=s;i<n;i++){cin >> V[i];}
#define COUT(V,s,n)   {for(int i=s;i<n;i++){cout <<  V[i] << " "  ;} cout << endl;}
#define fast               ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define CLEAR(V);      for(ll i=0;i<V.size();i++) V[i] = 0;
#define N                  200002LL
#define tmod             998244353LL
using namespace std;

bool sBs(const pair<int,int> &a,const pair<int,int> &b)
{   return (a.second < b.second);   }

ll Powb(ll b,ll n,ll m);
ll BS(vector<pair< ll ,ll > > &PS,ll s,ll e,ll ser);
ll MI(ll a, ll m);
ll P[N+1];
void Sieve(int n=N);

vector<vector<ll> > G(N), K(N), T(N);

int main()
{
fast;
ll q=1,t;
//cin >> q; t = q;
while(q--)
{
    ll i,j,n,m,k,l=0,r=0,a=0,b=0,c=0,d=0,e,g=1,p,u,v,w,x,y,z,flag=1;
    //n=m=k=i=j=l=r=a=b=c=d=u=v=w=p=x=y=0;
    cin >> n >> m >> x >> y;
    for (i=0;i<m;i++) {
        cin >> u >> v >> t >> k;
        G[u].pb(v); K[u].pb(k), T[u].pb(t);
        G[v].pb(u); K[v].pb(k), T[v].pb(t);
    }
    priority_queue<pair<ll,ll>, vector<pair<ll,ll>> , greater<pair<ll,ll>> > PQ;
    PQ.push({0,x});
    vector<ll> dist(n+1,-1);
    while(!PQ.empty()) {
        pair<ll,ll> U = PQ.top(); PQ.pop();
        u = U.S;
        w = U.F;
        for (i=0;i<G[u].size();i++) {
            v = G[u][i];
            k = K[u][i];
            t = T[u][i];
            ll nw = t + ((w+k-1)/k)*k;
            if (nw < dist[v] or dist[v] == -1) {
                dist[v] = nw;
                PQ.push({nw,v});
            }
        }
    }

        cout << dist[y];
}
    return 0;
}

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

ll Powb(ll b,ll n,ll m)
{
    if(n==0) return 1LL;
    if(n==1) return b;
    ll temp = Powb(b,n/2,m);
    if(n%2==0){return (temp*temp)%m;}
    else{return (b*((temp*temp)%m))%m;}
}

ll BS(vector<pair<ll,ll> > &PS,ll s,ll e,ll ser)
{
    if(s>e)
        return s;
    ll mid = (s+e)/2;
    if(PS[mid].F==ser)
    {
        return mid;
    }
    else if(PS[mid].F > ser)
    {
        return BS(PS,s,mid-1,ser);
    }
    else
        return BS(PS,mid+1,e,ser);
}
ll MI(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;
    if (m == 1)
      return 0;
    while (a > 1)
    {
        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;
    return x;
}

void Sieve(int n)
{
    //memset(P,1,sizeof(P));
    P[0] = 0;
    P[1]= 0;
    for(int i=2;i<=n;i++) P[i] = 1;
    for(ll i=2;i*i<=n;i++)
    {
        if(P[i]==1)
        {
            for(ll j=i*i;j<=n;j+=i)
            {
                P[j]=0;
            }
        }
    }

}


/*

  AUTHOR:    nit1n
  CREATED:   15.11.2020 18:02:29

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

const int N = 2e5 + 10 ;
int a[N] ;

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

	int n ,w  ;
	cin >> n >> w ;
	for(int i = 0; i < n ; ++i){
		int s , t , p ;
		cin >> s >> t>>p ;
		a[s] += p ;
		a[t] -= p ;
	}

	int cur = 0 ;
	for(int i = 0 ; i < N; ++i){
		cur += a[i] ;
		if(cur > w){
			cout << "No" ;
			return 0 ;
		}
	}
	cout << "Yes" ;
}

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using ll = long long int;
#define ss string
#define mod 1000000007
#define pi 3.14159265358979
#define rep(i,s,n) for(int i=(s);i<(int)(n);i++)
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
#define all(v) v.begin(),v.end()
#define co(x) cout << (x) << endl
#define ci(x) cin >> (x)

int main(){
  int maxn=200010,n,w;cin>>n>>w;
  vector<ll> time(maxn);
  vector<ll> s(maxn),t(maxn);
  rep(i,0,n){
    int ts,tt,p;cin>>ts>>tt>>p;
    s[ts]+=p;t[tt]+=p;
  }
  rep(i,0,maxn-1){
    time[i+1]=time[i]+s[i]-t[i];
    if(time[i]>w){co("No");return 0;}
  }
  co("Yes");
}


#include <bits/stdc++.h>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) a.begin(), a.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vv = vector<vi>;
using Graph = vector<vector<int>>;
template<class T> bool chmax(T& a, T b){ if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a, T b){ if (a > b) { a = b; return true; } return false; }

const ll mod = 1000000007;
const int INF = 100000000;
const double PI = acos(-1);

int main()
{
    int x;
    cin >> x;
    if (x < 0) cout << 0 << endl;
    else cout << x << endl;
}

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }
const double PI = 3.14159265358979323846;
int vector_finder(vector<int> vec, int number) {
  auto itr = find(vec.begin(), vec.end(), number);
  size_t index = distance(vec.begin(), itr);
  if (index != vec.size()) {  // 発見できたとき
    return 1;
  } else {  // 発見できなかったとき
    return 0;
  }
}
unsigned GetDigit(unsigned num) { return log10(num) + 1; }
int main() {
  int n = 0, cnt = 0;
  cin >> n;
  if (n % 2 == 0) {
    cout << "White";
  }
  if (n % 2 == 1) {
    cout << "Black";
  }
}
/*vector<int> a;
  int d;
  for (int i = 0; i < n; i++) {
    cin >> d;
    a.push_back(d);
  }*/

// g++ lo.cpp
// ./a.exe
// g++ -o つくりたいふぁいるめい　もとのふぁいる.cpp
/*
for (int i = 0; i < n - 2; i++) {
  for (int j = i + 1; j < n - 1; j++) {
    int k = 2 * j - i;*/
/* vector<int>a(n);
   cin>>a.at(n);*/
/* queue<long long> q;
for(i=0;i<n-1;i++){
        pop = q.front();
        if(pop%10!=0) q.push(pop*10 + pop%10 -1);
        q.push(pop*10+pop%10);
        if(pop%10 != 9) q.push(pop*10 + pop%10 + 1);
        q.pop();
    }*/
/*
int value = 4287;
int a[ 4 ];
a[0] = (value % 10); value /= 10;　// 1桁目を取り出す7
a[1] = (value % 10); value /= 10;　// 2桁目を取り出す8
a[2] = (value % 10); value /= 10;　// 3桁目を取り出す2
a[3] = (value % 10); value /= 10;　// 4桁目を取り出す4
*/
/*nCm
int n, m;
  cin >> n >> m;
  int N = 1, M = 1;
  for (int i = 0; i < m; i++) {
    N = N * (n - i);
  }
  for (int j = 0; j < m; j++) {
    M = m * (m - j);
  }
  cout << N / M;
*/


#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <queue>

#define CHECK_IMPL1(cond)                \
    if (!(cond)) {                       \
      DEBUG("expected cond: " << #cond); \
      assert(cond);                      \
    }

#define CHECK_IMPL2(cond, message)                                              \
    if (!(cond)) {                                                              \
      DEBUG("expected cond: " << #cond << " failed with message: " << message); \
      assert(cond);                                                             \
    }

#define CHECK_IMPL(_1, _2, NAME, ...) NAME
#define CHECK(...) CHECK_IMPL(__VA_ARGS__, CHECK_IMPL2, CHECK_IMPL1, CHECK_IMPL0)(__VA_ARGS__)

#ifdef __APPLE__
#define DEBUG(message) std::cerr << message << std::endl;
#else
#define DEBUG(message)
#endif

constexpr int kMod = 998244353;
constexpr int N = 100;

int mul(int64_t a, int64_t b) {
  return a * b % kMod;
}

int add(int64_t a, int64_t b) {
  int64_t c = a + b;
  if (c >= kMod) {
    c -= kMod;
  }
  if (c < 0) {
    c += kMod;
  }
  return c;
}

int pow(int a, int n) {
  int r = 1;
  while (n) {
    if (n & 1) {
      r = mul(r, a);
    }
    a = mul(a, a);
    n >>= 1;
  }
  return r;
}

int inv(int a) {
  return pow(a,  kMod - 2);
}

int fac[N];

int solve(std::vector<std::vector<int>> g) {
  std::vector<int> cmp(g.size(), -1);
  std::vector<int> sz;
  for (int i = 0; i < g.size(); ++i) {
    if (cmp[i] != -1) {
      continue;
    }

    cmp[i] = sz.size();
    sz.push_back(1);
    std::vector<int> q = {i};
    for (int j = 0; j < q.size(); ++j) {
      int v = q[j];

      for (auto to : g[v]) {
        if (cmp[to] == -1) {
          cmp[to] = cmp[v];
          q.push_back(to);
          ++sz.back();
        } else {
          CHECK(cmp[to] == cmp[v]);
        }
      }
    }
  }
  int ans = 1;
  for (auto x : sz) {
    ans = mul(ans, fac[x]);
  }
  return ans;
}

void solve() {
  int n, k;
  std::cin >> n >> k;

  fac[0] = 1;
  for (int i = 1; i < N; ++i) {
    fac[i] = mul(fac[i - 1], i);
  }

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

  std::vector<std::vector<int>> g_cols(n);
  std::vector<std::vector<int>> g_rows(n);
  for (int x = 0; x < n; ++x) {
    for (int y = 0; y < n; ++y) {
      if (x == y) {
        continue;
      }
      {
        bool bad = false;
        for (int i = 0; i < n; ++i) {
          if (a[i][x] + a[i][y] > k) {
            bad = true;
            break;
          }
        }
        if (!bad) {
          g_cols[x].push_back(y);
          g_cols[y].push_back(x);
        }
      }
      {
        bool bad = false;
        for (int i = 0; i < n; ++i) {
          if (a[x][i] + a[y][i] > k) {
            bad = true;
            break;
          }
        }
        if (!bad) {
          g_rows[x].push_back(y);
          g_rows[y].push_back(x);
        }
      }
    }
  }

  std::cout << mul(solve(g_cols), solve(g_rows)) << '\n';
}

int main() {
#ifdef __APPLE__
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
#endif
  int t = 1;
  //std::cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}

#include<cstdio>
#define fo(i,a,b) for(int i=a;i<=b;i++)
const int N=55,mo=998244353;
int n,K,fac[N],a[N][N],f[N][N],g[N][N],s,ans=1;
bool vf[N],vg[N];
void T(int&x,int y) {x=1ll*x*y%mo;}
void dg(int x,int f[N][N],bool vf[N])
{
	vf[x]=1; s++;
	fo(y,1,n) if(!vf[y]&&f[x][y]) dg(y,f,vf);
}
int main()
{
	scanf("%d%d",&n,&K);
	fac[0]=1;
	fo(i,1,n) fac[i]=1ll*fac[i-1]*i%mo;
	fo(i,1,n) fo(j,1,n) scanf("%d",&a[i][j]);
	fo(i,1,n-1) fo(j,i+1,n)
	{
		fo(k,1,n) if(a[i][k]+a[j][k]>K) goto RW;
		f[i][j]=f[j][i]=1;
		RW:fo(k,1,n) if(a[k][i]+a[k][j]>K) goto NE;
		g[i][j]=g[j][i]=1;
		NE:;
	}
	fo(i,1,n)
	{
		if(!vf[i]) s=0,dg(i,f,vf),T(ans,fac[s]);
		if(!vg[i]) s=0,dg(i,g,vg),T(ans,fac[s]);
	}
	printf("%d",ans);
}


#include<bits/stdc++.h>
#define SZ(x) ((int)x.size())
#define uni(x) sort(all(x)),x.resize(unique(all(x))-x.begin());
#define GETPOS(c,x) (lower_bound(all(c),x)-c.begin())
#define lown1(x,val) low(in(x),val)-x
#define lowm1(x,val) low(im(x),val)-x
#define low1(x,nums,val) low(x+1,x+nums+1,val)-x
#define mst(x,val) memset((x),val,sizeof((x)))
#define ls rt<<1
#define rs rt<<1|1
#define lson rt<<1,l,M
#define rson rt<<1|1,M+1,r
#define PI acos(-1)
#define MM int M=(l+r)>>1;
#define fu(i,r,t) for(int i=r;i<=t;i++)
#define fd(i,r,t) for(int i=r;i>=t;i--)
#define fh(i,be,e) for(int i=head[be];~i;i=e[i].next)
#define fa(i,V) for(auto i:V)
#define far(i,V) for(auto &i:V)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define lcm(a,b) ((a)*(b))/__gcd(a,b)
#define cp(i,ans) printf("%.if",ans);
#define cpp(i,ans) cout<<setprecision(i)<<fixed<<ans<<endl;
#define ppb pop_back
#define ppf pop_front
#define pb push_back
#define pf push_front
#define pq priority_queue
#define lowbit(x) ((x)&(-x))
#define all(V) V.begin(),V.end()
#define ms multiset
#define mod(x) (((x)<0)?(x)%mo_num+mo_num:(x)%mo_num)
#define vc vector
#define vct vector<int>
#define out(i) cout<<(i)<<endl;
#define fi first
#define se second
#define fun(i) fu(i,1,n)
#define fut(i) fu(i,1,t)
#define fum(i) fu(i,1,m)
#define ld long double
#define umap unordered_map
#define Umap unordered_map<int,int>
#define P pair<int,int>
#define SET set<int>
#define mk make_tuple
#define eps 1e-6
//Remember cancel"#define endl '\n'" in interactive questions or use "<<flush"
#define endl '\n'
#define low lower_bound
#define upp upper_bound
#define yn(key) out(key?"YES":"NO")
//#define yn(key) out(key?"Yes":"No")
#define in(i) i+1,i+1+n
#define im(i) i+1,i+1+m
#define ik(i,k) i+1,i+1+k
#define bffs(i) __builtin_ffs(i)
#define bcount(i) __builtin_popcount(i)
#define bone(i) ((1<<i)-1)
#define db double
#define ll long long
#define got(container,num) get<num-1>(container)
#define int long long
#define print(a,n) fun(i)cout<<a[i]<<(i!=n?' ':endl);
#define outcase(x) cout<<"Case #"<<(++case_of_T)<<": "<<(x)<<endl;
#define ptcase(x) printf("Case #%d: %d\n",++case_of_T,x);
#define plcase(x) printf("Case #%lld: %lld\n",++case_of_T,x);
using namespace std;
//Remember to cancel the line below and declare INT=INT_MAX/2; when you want to change long to int
const int INF=LLONG_MAX/4,SINF=0x3f3f3f3f,Lim=1<<20,MINF=LLONG_MAX;
//const int INF=INT_MAX/4,SINF=0x3f;
// use C:printf("%.16f", x);  ->  printf("%.10f", x); can accelerate the program
const int dx[]={0,0,-1,1},dy[]={-1,1,0,0};//down up left right
const int maxn=1e6+1e5;
int mo_num=1e9+7;
//const int mo_num=998244353;
int n,m,t,a[maxn],b[maxn],ans,case_of_T;

void solve()
{
    int A,B;
    cin>>n>>A>>B;
    if(n<A+B)out(0)
    else{
        m=n+2-A-B;
        int C=mod(m*(m-1)/2);
        ans=mod(4*mod(mod((n-A+1)*(n-B+1))*C));
        ans=mod(ans-mod(4*C*C));
        out(ans)
    }
    return ;
}
main()
{
    IOS

    int T=1;
    cin>>T;
    while(T--)solve();
    return 0;
}

//面倒くさがらずに実験したらすぐ分かった…
//all - NG * NGの形にして、1次元の問題でNGを数える。
//A, Bを置く位置x, y(0≦x, y≦N-1)を考えると
//0 ≦ x ≦ N - A
//0 ≦ y ≦ N - B
//y - A + 1 ≦ x ≦ y + B - 1
//なる(x, y)を数えたくなるので、そういう(x, y)を表示してみる。(実験)
//A + B > Nのときは、(N + 1 - A) * (N + 1 - B)個全てが埋まる.
//A + B <= Nのとき、
//1辺len = N + 1 - A - Bの二等辺三角形2つを引けばよい.
//ただし、二等辺三角形の面積は1 + … + lenなことに注意（離散的なので）
//(N + 1 - A) * (N + 1 - B) - (len + 1) * len個.

#include <iostream>
#define int long long
using namespace std;

int mod = 1000000007;

signed main() {
	int T;
	cin >> T;

	while (T--) {
		int n, a, b;
		cin >> n >> a >> b;

		int all = (n - a + 1) * (n - a + 1) % mod * (n - b + 1) % mod * (n - b + 1) % mod;
		int ng;
		if (a + b > n) ng = (n + 1 - a) * (n + 1 - b);
		else ng = (n + 1 - a) * (n + 1 - b) - (n + 2 - a - b) * (n + 1 - a - b);
		ng %= mod;

		int ans = (all - ng * ng % mod + mod) % mod;
		cout << ans << endl;
	}
	return 0;
}


#include <iostream>
#include <cmath>

using namespace std;

int n;
double x0, z0, xn, zn, rx, ry, dx, dy, theta, c, s;

int main(){
    cin >> n;
    cin >> x0 >> z0 >> xn >> zn;

    rx = (x0 + xn)/2.0;
    ry = (z0 + zn)/2.0;
    dx = x0 - rx;
    dy = z0 - ry;

    c = cos(M_PI*2.0/n);
    s = sin(M_PI*2.0/n);

    // cout << rx << " " << ry << endl;
    // cout << c << " " << s << endl;
    // cout << dx << " " << dy << endl;

    printf("%9lf %9lf", rx +c*dx - s*dy, ry +s*dx + c*dy);

    // cout << rx +c*dx - s*dy << " " << rx +c*dx - s*dy<<endl;

}

#include <bits/stdc++.h>

#pragma region my_template

struct Rep {
  struct I {
    int i;
    void operator++() { ++i; }
    int operator*() const { return i; }
    bool operator!=(I o) const { return i < *o; }
  };
  const int l_, r_;
  Rep(int l, int r) : l_(l), r_(r) {}
  Rep(int n) : Rep(0, n) {}
  I begin() const { return {l_}; }
  I end() const { return {r_}; }
};
struct Per {
  struct I {
    int i;
    void operator++() { --i; }
    int operator*() const { return i; }
    bool operator!=(I o) const { return i > *o; }
  };
  const int l_, r_;
  Per(int l, int r) : l_(l), r_(r) {}
  Per(int n) : Per(0, n) {}
  I begin() const { return {r_ - 1}; }
  I end() const { return {l_ - 1}; }
};

template <class F>
struct Fix : private F {
  Fix(F f) : F(f) {}
  template <class... Args>
  decltype(auto) operator()(Args&&... args) const {
    return F::operator()(*this, std::forward<Args>(args)...);
  }
};

template <class T = int>
T scan() {
  T res;
  std::cin >> res;
  return res;
}

template <class T, class U = T>
bool chmin(T& a, U&& b) {
  return b < a ? a = std::forward<U>(b), true : false;
}
template <class T, class U = T>
bool chmax(T& a, U&& b) {
  return a < b ? a = std::forward<U>(b), true : false;
}

#ifndef LOCAL
#define DUMP(...) void(0)
template <int OnlineJudge, int Local>
constexpr int OjLocal = OnlineJudge;
#endif

using namespace std;

#define ALL(c) begin(c), end(c)

#pragma endregion

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  cout << fixed << setprecision(20);
  int64_t ans = 0;
  for (int n = scan(); n--;) {
    int64_t a = scan();
    int64_t b = scan();
    ans += (a + b) * (b - a + 1) / 2;
  }
  cout << ans << '\n';
}


#include <bits/stdc++.h>

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(40)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

bool solve(vector<ll> &A) {
    ll N = A.size();
    vector<ll> ans;
    REP(i, N * N) {
        bool sorted = true;
        REP(j, N - 1) {
            if (A[j] > A[j + 1]) {
                sorted = false;
                break;
            }
        }
        if (sorted)
            break;
        bool update = false;
        REP(j, N) {
            if (i % 2 != j % 2)
                continue;
            if (j + 1 >= N)
                break;
            if (A[j] > A[j + 1]) {
                update = true;
                swap(A[j], A[j + 1]);
                ans.push_back(j);
                break;
            }
        }
        if (!update) {
            for (ll j = N - 2; j >= 0; --j) {
                if (j % 2 == i % 2) {
                    swap(A[j], A[j + 1]);
                    ans.push_back(j);
                    break;
                }
            }
        }
#if false
        REP(j, N) {
            cout << A[j] << " ";
        }
        cout << endl;
#endif
    }

    cout << ans.size() << endl;
    REP(i, ans.size()) {
        cout << ans[i] + 1 << " ";
    }
    cout << endl;
    {
        bool sorted = true;
        REP(j, N - 1) {

            if (A[j] > A[j + 1]) {
                sorted = false;
                break;
            }
        }
        return sorted;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
#if true
    ll Q;
    cin >> Q;
    REP(_, Q) {
        ll N;
        cin >> N;
        vector<ll> A(N);
        REP(i, N) {
            cin >> A[i];
        }
        if (!solve(A)) {
            assert(false);
        }
    }
#else
    vector<ll> A;
    ll N = 8;
    REP(i, N) {
        A.push_back(i + 1);
    }
    do {
        vector<ll> v;
        REP(i, N) {
            v.push_back(A[i]);
        }
        if (!solve(v)) {
            assert(false);
        }
    } while (next_permutation(A.begin(), A.end()));
#endif
    return 0;
}

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

int main(){
  ll n;
  cin >> n;
  while(n % 2 == 0){
    n /= 2;
  }
  ll sq = sqrt(n);
  ll ans = 0;
  for(ll i = 1;i <= sq;i++){
    if(n % i == 0){
      ans += 2;
    }
  }
  if(sq*sq == n) ans--;
  cout << ans*2 << endl;
}


#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
const int MAX_T = 200005;

int main() {
  int N, X;
  cin >> N >> X;
  string S;
  cin >> S;
  int score = X;
  for (char s : S) {
    score += (s == 'o' ? 1 : -1);
    maxs(score, 0);
  }

  cout << score << endl;
  return 0;
}

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
long long a[100010];
vector<pair<long long, int>> vec;
int main() {
	long long k, n, m, sum = 0;
	cin >> k >> n >> m;
	for (int i = 0; i < k; i++) {
		cin >> a[i];
		long long a1 = a[i] * m / n;
		sum += a1;
		vec.emplace_back(make_pair(a[i] * m - n * a1, i));
		a[i] = a1;
	}
	sort(vec.rbegin(), vec.rend());
	for (int i = 0; i < m - sum; i++) {
		a[vec[i].second]++;
	}
	for (int i = 0; i < k; i++) {
		cout << a[i] << " ";
	}
	cout << endl;
}


#include <bits/stdc++.h>
using namespace std;
const long long INF = 10000000000000007;
const long long mod = 1000000007;
typedef long long ll;
typedef pair<int, int> P;

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

vector<int> table(2500);
vector<vector<int>> tile(2500);
vector<vector<bool>> seen(50,vector<bool>(50,0));
vector<vector<int>>point(50,vector<int>(50));

int now_x, now_y;
int si, sj;
// ll sum = 0;
vector<int> dx = {1, 0, -1, 0};
vector<int> dy = {0, 1, 0, -1};
vector<int>ans;

void solve(int now_x, int now_y) {
  while (1) {
    int num = table[now_x+now_y*50];
    for (int j = 0; j < tile[num].size(); j++) {
      int k = tile[num][j];
      seen[k/50][k%50] = 1;
    }

    int nx,ny,index=-1;
    ll ma = -1;
    for (int i = 0; i < 4; i++) {
      nx = now_x + dx[i];
      ny = now_y + dy[i];
      if (nx<0||nx>=50||ny<0||ny>=50) continue;
      if (seen[ny][nx]==1) continue;
      ll score = 0;
      if (i==0) score += 50-now_x;
      else if (i==1) score += 50-now_y;
      else if (i==2) score += now_x;
      else if (i==3) score += now_y;
      score += point[ny][nx] / 10;
      if (chmax(ma, score)) {
        index = i;
      }
    }
    if (index==-1) break;
    now_x = now_x + dx[index];
    now_y = now_y + dy[index];
    ans.push_back(index);
  }
  return;
}

int main()
{
  cin >> sj >> si;
  now_x = si;
  now_y = sj;

  for (int i = 0; i < 2500; i++) {
    int num;
    cin >> num;
    table[i] = num;
    tile[num].push_back(i);
  }
  for (int i = 0; i < 2500; i++) {
    int x = i%50;
    int y = i/50;
    cin >> point[y][x];
  }

  solve(now_x, now_y);

  // 出力
  for (int i = 0; i < ans.size(); i++) {
    if (ans[i]==0) cout << 'R';
    else if (ans[i]==1) cout << 'D';
    else if (ans[i]==2) cout << 'L';
    else if (ans[i]==3) cout << 'U';
  }
  cout << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef DEBBY
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
      *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define ll long long
#define rep(i,a,b) for(int i=int(a); i<=int(b); i++)
#define print_mat(i,j,a,b,v) for(int i=0;i<a;i++){for(int j=0;j<b;j++)cerr<<v[i][j] << " "; cerr<<endl;}
#define sz(v)  (int)(v).size()
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pi pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define vpi vector<pi>
#define pq priority_queue<int>
#define pqg priority_queue<int, vi, greater<int> >
#define fs first
#define sd second
#define pb push_back
#define eb emplace_back

void solve(){
    string s;
    cin >> s;
    int j=sz(s)-1;
    while(j>=0 and s[j]=='0')
        j--;
    j++;
    for(int i=0; i<j/2; i++){
        if(s[i]!=s[j-i-1]){
            cout << "No"; return;
        }
    }
    cout << "Yes";

}

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

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

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

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

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

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

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

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

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

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

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


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

const int M = 1e5;
int main()
{
    int n;
    cin >> n;
    vector<int> t(n);
    rep(i, n) cin >> t[i];
    int sum = 0;
    rep(i, n) sum += t[i];

    //for文でMまで探索するので、M+1000でもはみ出さないようにする。
    vector<vector<int>> dp(n + 5, vector<int>(M+1005));

    dp[0][0] = 1;
    rep(i, n)
    {
        rep(j, M)
        {
            dp[i + 1][j] = dp[i][j] | dp[i + 1][j];
            dp[i + 1][j + t[i]] = dp[i][j] | dp[i + 1][j + t[i]];
        }
    }
    int ans = M;
    rep(i, M)
    {
        if (dp[n][i] == 1)
        {
            int a = i;
            int b = sum - i;
            ans = min(ans, max(a, b));
        }
    }
    cout << ans << endl;

    return 0;
}

/*
                    __
                   /\ \
 _ __   ___     ___\ \ \/'\     ___      __      ___     ___      __
/\`'__\/ __`\  /'___\ \ , <    / __`\  /'__`\  /' _ `\ /' _ `\  /'__`\
\ \ \//\ \L\ \/\ \__/\ \ \\`\ /\ \L\ \/\ \L\.\_/\ \/\ \/\ \/\ \/\ \L\.\_
 \ \_\\ \____/\ \____\\ \_\ \_\ \____/\ \__/.\_\ \_\ \_\ \_\ \_\ \__/.\_\
  \/_/ \/___/  \/____/ \/_/\/_/\/___/  \/__/\/_/\/_/\/_/\/_/\/_/\/__/\/_/

*/

#ifndef __AHA__HEADER
#define __AHA__HEADER

#include <bits/stdc++.h>
using namespace std;
#define g0 get<0>
#define g1 get<1>
#define g2 get<2>
#define ft first
#define sd second
#define sz(x) (i6) x.size()
#define psb(x) push_back(x)
#define ppb() pop_back()
#define bg(x) x.begin()
#define ed(x) x.end()
#define col(x) x.begin(), x.end()
#define srt(x) sort(x.begin(), x.end())
#define vec vector
#define deq deque
#define hmap unordered_map
#define pq priority_queue
#define fn function
#ifdef LOCAL
#define git stauDBG_MACRO_NO_WARNING
#include <dbg.h>
#define dbgt dbg(dbg::time())
#else
#define dbg(...)
#define dbgt
#endif
typedef string str;
typedef int32_t i3;
typedef int64_t i6;
typedef int64_t i64;
typedef uint32_t u3;
typedef uint64_t u6;
typedef long double d6;
typedef pair<i6, i6> p6;
typedef vec<i6> vi6;
typedef vec<p6> vp6;
typedef vec<bool> vb;
typedef vec<vi6> vv;
typedef deq<p6> dp6;
typedef deq<i6> di6;
typedef map<i6, i6> mi6;
typedef map<p6, i6> mp6;
typedef set<i6> si6;
typedef hmap<i6, i6> hi6;
typedef vv graph;
typedef vv matrix;

const i6 INF = INT64_MAX / 4;
const i6 NINF = -INF;
const i6 ZERO = 0;
const i6 ONE = 1;

#endif

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifdef LOCAL
  ifstream cin{"input.txt"};
  ofstream cout{"output.txt"};
#endif

  i64 h, w;
  cin >> h >> w;

  vv v(h, vi6(w));
  for (i64 i = 0; i < h; i++) {
    string s;
    cin >> s;
    for (i64 j = 0; j < w; j++) {
      if (s[j] == '.') {
        v[i][j] = 0;
      } else {
        v[i][j] = 1;
      }
    }
  }

  i64 res = 0;

  for (i64 i = 1; i < h; i++) {
    for (i64 j = 1; j < w; j++) {
      i64 x = 0;
      if (v[i][j - 1] == 0) {
        x += 1;
      }
      if (v[i - 1][j - 1] == 0) {
        x += 1;
      }
      if (v[i - 1][j] == 0) {
        x += 1;
      }
      if (v[i][j] == 0) {
        x += 1;
      }

      if (x % 2 == 1) {
        res += 1;
      }
    }
  }

  cout << res << endl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    int r = r2 - r1, c = c2 - c1;
    int ans = 3;
    if(!r && !c) ans = 0;
    else if(r == c || r == -c || abs(r) + abs(c) <= 3) ans = 1;
    else if((r ^ c ^ 1) & 1 || abs(r + c) <= 3 || abs(r - c) <= 3 || abs(r) + abs(c) <= 6) ans = 2;
    cout << ans << endl;
}

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

int main() {
  int A[3];
  for (int i = 0; i < 3; i++) cin >> A[i];

  int p[3] = {0, 1, 2};
  bool res = false;
  do {
    if (A[p[2]] - A[p[1]] == A[p[1]] - A[p[0] ]) res = true;
  } while (next_permutation(p, p + 3));

  if (res) cout << "Yes";
  else cout << "No";
}


#define _USE_MATH_DEFINES
#include <iomanip>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <tuple>
#include <climits>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<double> VD;
typedef vector<LL> VLL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef vector<vector<long long>> VVLL;
typedef vector<vector<bool>> VVB;
typedef vector<vector<double>> VVD;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(a) (a).begin(),(a).end()

const int MOD = 1000000007;

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

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

void debug(VI &arr){
	int n=arr.size();
	rep(i,n){
		cout<<arr.at(i)<<endl;
	}
}

void debug(VVI &board){
	int h = board.size();
	int w = board.at(0).size();
	rep(i,h){
		rep(j,w){
			cout << board.at(i).at(j) << " ";
		}
		cout<<endl;
	}
}

void debug(VVLL &board){
	int h = board.size();
	int w = board.at(0).size();
	rep(i,h){
		rep(j,w){
			cout<<board.at(i).at(j)<<" ";
		}
		cout<<endl;
	}
}

void debug(VS &board){
	int h = board.size();
	rep(i,h){
		cout<<board.at(i)<<endl;
	}
	return;
}

LL gcd(LL a,LL b){
	return b==0?a:gcd(b,a%b);
}

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

LL cnt(LL n){
	LL i=0;
	while(true){
		LL sum = (i + 1) * i / 2;
		if(sum>n+1){
			break;
		}
		i++;
	}
	return i-1;
}

int main(){
	//cout<<fixed;
	//cout<<setprecision(9)<<...
	LL n;
	cin>>n;
	cout<<n-cnt(n)+1<<endl;

	return 0;
}

// #include <bits/stdc++.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
// bits default for atcoder

// additional
// #include <array> // array
#include <numeric> // accumulate

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

using namespace std;

using ll = long long;

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

    vector<pair<int, string>> vec(N);
    for (int i = 0; i < N; ++i) {
        string s;
        int t;
        cin >> s >> t;
        vec[i] = make_pair(t, s);
    }

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

    cout << vec[N-2].second << endl;

    return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;

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

    vl ans(t);
    rep(j, t) {
        string s;
        cin >> s;
        ll n = s.size();
        // 0回の場合
        if("atcoder" < s) {
            continue;
        }
        // s[0] = 'a' が確定
        ll x = 0;  // sの先頭から連続する'a'の個数
        for(auto c : s) {
            if(c == 'a') {
                x++;
            }
            else {
                break;
            }
        }
        // 全ての文字が'a'のとき不可能
        if(x == n) {
            ans[j] = -1;
            continue;
        }
        if(s[x] > 't') {
            ans[j] = x-1;
        }
        else {
            ans[j] = x;
        }
    }

    rep(i, t) {
        out(ans[i]);
    }

    re0;
}

#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl '\n'
//#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define BIT(n) (1LL << (n))
#define TOUPPER(s) transform(s.begin(), s.end(), s.begin(), ::toupper)
#define TOLOWER(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define FILLZERO(s, n)                      \
    do {                                    \
        ostringstream os;                   \
        os << setw(n) << setfill('0') << s; \
        s = os.str();                       \
    } while (0);
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと

using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pi = pair<int, int>;
template <typename T>
using Pq = priority_queue<T>;
template <typename T>
using pQ = priority_queue<T, vector<T>, greater<T>>;

template <typename T>
vector<T> make_vec(size_t a, T n) { return vector<T>(a, n); }
template <typename T, typename... Ts>
auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); }
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
bool isProductOverflow(T a, T b) {
    return (a > numeric_limits<T>::max() / b);
}
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

__attribute__((constructor)) void ioInit() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << std::fixed << std::setprecision(10);
}

constexpr ll MOD = 1e9 + 7;
//constexpr ll MOD = 998244353;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

signed main() {
    cin >> N >> A >> B;
    REP(i, N) {
        cin >> X >> Y;
        if (X < A and Y > B) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define boostIO                   \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define rep(i, b) for (int i = 0; i < b; i++)
#define repn(i, n) for (int i = 1; i <= n; i++)
#define rrep(i, b, a) for (int i = b; i >= a; i--)
#define sz(v) (v.empty() ? 0 : v.size())
#define all(v) v.begin(), v.end()
#define mem(a, val) memset(a, val, sizeof(a))
#define trav(a, x) for (auto &a : x)
#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define int long long
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d) for (long blockTime = 0; (blockTime == 0 ? (blockTime = clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
#define maxn 100005
#define mod 998244353
const int INF = 1e10;
typedef pair<int, int> pii;

signed main() {
    boostIO;
    int n, k;
    cin >> n >> k;
    int ans = 0;
    for (int i = 2; i <= (2 * n); i++) {
        int K = k + i;
        if(K < 2 or K > 2 * n) continue;
        int ir = min(n, i - 1);
        int il = max(1LL, i - n);
        int kr = min(n, K - 1);
        int kl = max(1LL, K - n);
        int ni = (ir >= il ? ir - il + 1 : 0);
        int nk = (kr >= kl ? kr - kl + 1 : 0);
        ans += (ni * nk);
    }
    cout << ans << endl;
    return 0;
}
// XD

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

#define int long long
#define fi first
#define se second
#define pb push_back
//#define mp make_pair
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)

typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;

const int N = 2005;

const int oo = 1e18 + 7, mod = 1e9 + 7;

int n, a[N];

set<int> numbers;
map<int, int> mp;

void process(){
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		if(numbers.find(a[i]) != numbers.end()) continue;
		numbers.insert(a[i]);
		for(int j = 1; j <= sqrt(a[i]); j++){
			if(a[i] % j) continue;
			mp[a[i] / j] = __gcd(mp[a[i] / j], j);
			mp[j] = __gcd(mp[j], a[i] / j);
		}
	}
	int mini = (*numbers.begin());
	set<int> se;
	se.insert(mini);
	for(auto it : mp){
		if(it.fi > mini) break;
		if(it.se != 1) continue;
		se.insert(it.fi);
	}
	cout << se.size();
}

signed main(){
	ios_base::sync_with_stdio(0);
	process();
}


//#include <atcoder/all>
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
//using namespace atcoder;
using ll = long long;
#define all(A) A.begin(),A.end()
using vll = vector<ll>;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
using Graph = vector<vector<pair<ll,double>>>;

vector<pair<ll,ll>> Z;
double dist(ll A,ll B){
    ll dx=Z[A].first-Z[B].first;
    ll dy=Z[A].second-Z[B].second;
    return sqrt(dx*dx+dy*dy);
}
ll gcd(ll(a), ll(b)) {
	ll c = a;
	while (a % b != 0) {
		c = a % b;
		a = b;
		b = c;
	}
	return b;
}
ll mod=1e9+7;

int main() {

   ll N;
   cin>>N;
   vector<pair<ll,string>> P(N);
    rep(i,N){
        ll H;string S;
        cin>>S>>H;
        P[i]=make_pair(H,S);
    }
    sort(all(P));
    reverse(all(P));
    cout<<P[1].second<<endl;

}


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

int main()
{
    int H, W;
    cin >> H >> W;
    string S[100];

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

    int answer = 0;

    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            if (j != W - 1)
            {
                if (S[i][j] == '.' && S[i][j + 1] == '.')
                {
                    answer++;
                }
            }
            if (i != H - 1)
            {
                if (S[i][j] == '.' && S[i + 1][j] == '.')
                {
                    answer++;
                }
            }
        }
    }

    cout << answer << endl;

    return 0;
}

#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007LL
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define SHIFT(n) (1LL<<((ll)n))
#define ALL(a) (a).begin(),(a).end()
#define Max(a) (*max_element(ALL(a)))
#define Min(a) (*min_element(ALL(a)))
using namespace std;

bool exor(string s){
    ll ret = 0;
    for(int i = 0;i < s.size();i++){
        ret+=(s[i]-'0')%2;
    }
    return ret%2;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin >> n >> m;
    vector<string>vs(n);
    for(auto &s:vs)cin>>s;
    ll ans = 0;
    vi cnt(10);
    for(int i = 0;i < n;i++){
        cnt[exor(vs[i])]++;
    }
    cout << cnt[0] * cnt[1] << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define sz(v) (int)v.size()
#define all(v) v.begin(), v.end()
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template < typename T_container, typename T = typename enable_if < !is_same<T_container, string>::value, typename T_container::value_type >::type >
ostream & operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << "\b\b]\n"; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << H << ", "; dbg_out(T...);}
#define watch(...) cerr << "[" << #__VA_ARGS__ << "]: [", dbg_out(__VA_ARGS__)

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

    int a, b; cin >> a >> b;
    vector <ll> ans;
    if (a >= b) {
        for (int i = 1; i <= a; ++i)
            ans.push_back(i);
        for (int i = 1; i < b; ++i)
            ans.push_back(-i);
        ll sum = 0;
        for (int i = b; i <= a; ++i)
            sum += i;
        ans.push_back(-sum);
    }
    else {
        for (int i = 1; i <= b; ++i)
            ans.push_back(-i);
        for (int i = 1; i < a; ++i)
            ans.push_back(i);
        ll sum = 0;
        for (int i = a; i <= b; ++i)
            sum += i;
        ans.push_back(sum);
    }
    for (auto i : ans)
        cout << i << ' ';

    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;

double fc(vector<int> &a, double x) {
  double res = 0;
  int n = a.size();
  rep(i, n) {
    res += a.at(i);
    res -= min((double)a.at(i), 2*x);
  }
  res /= n;
  res += x;
  return res;
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);
  double l = 0, r = 1e10;
  rep(_i, 300) {
    double ml = (l*2+r)/3, mr = (l+r*2)/3;
    double mlp = fc(a, ml), mrp = fc(a, mr);
    if(mlp < mrp) r = mr;
    else l = ml;
  }
  double ans = fc(a, (l+r)/2);
  cout << fixed << setprecision(10) << ans << endl;
  return 0;
}


#include <iostream>
#include <map>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <utility>
#include <limits.h>
#include <cstring>
using namespace std;
const int N = 200005;
int n, s[N], e[N], tim = 1;
vector<int> adj[N];
vector<int> lvl[N];
int cnt(int idx, int l, int r)
{
    return upper_bound(lvl[idx].begin(), lvl[idx].end(), r) - lower_bound(lvl[idx].begin(), lvl[idx].end(), l);
}
void dfs(int u = 1, int l = 0)
{
    s[u] = tim;
    lvl[l].push_back(s[u]);
    for (int v: adj[u])
    {
        tim ++;
        dfs(v, l + 1);
    }
    e[u] = tim;
}
int main(int argc, char const *argv[])
{
	scanf("%d", &n);
    for (int i = 2; i <= n; ++i)
    {
        int p;
        scanf("%d", &p);
        adj[p].push_back(i);
    }
    dfs();
    int q;
    scanf("%d", &q);
    while (q --)
    {
        int u, v;
        scanf("%d", &u);
        scanf("%d", &v);
        printf("%d\n", cnt(v, s[u], e[u]));
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')';}
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) {os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
template<typename T> void dbg_a(const T *a,int l,int r){cerr<<" {";for(int i = l;i<r;i++) cerr<<a[i]<<", ";cerr<<a[r]<<"}"<<endl;}
typedef long long ll;
//#define int ll
inline int read(){
    int f(1),r(0);char c(getchar());
    while(c<'0'||c>'9'){if(c == '-') f = -1; c = getchar();}
    while(c>='0'&&c<='9'){ r = (r<<1) + (r<<3) + c - '0';c = getchar();}
    return f*r;
}
void read(int &x){ x = read();}
template<class Head, class... Tail> void read(Head &head, Tail &... tail) { read(head); read(tail...); }
typedef pair<int,int> PII;
#define fi first
#define se second
#define mst(a,b) memset(a,b,sizeof(a))
#define For(i,a,b) for(int i = a;i<=b;i++)
#define For_(i,a,b) for(int i = a;i>=b;i--)
#define rep(i,a) for(int i = 0;i<a;i++)
#define All(x) x.begin(),x.end()

//    For(i,1,n) For(j,1,m) printf("f[%lld][%lld] = %lld\n",i,j,f[i][j]);
//const ll INF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const int N = 2e5 + 6,M = 2020+ 6;
const int mod = 1e9 + 7;

int n;
vector<vector<int>> G,lis;
int timer;
int in[N],out[N],dep[N];
void dfs(int x,int pr){
    in[x] = ++timer;
    lis[dep[x]].emplace_back(in[x]);
    for(auto y:G[x]) if(y != pr){
        dep[y] = dep[x] + 1;
        dfs(y,x);
    }
    out[x] = ++timer;
}

void solve(){
    n = read();
    G.resize(n+1);
    lis.resize(n+1);
    For(i,2,n){
        int x = read();
        G[i].emplace_back(x);
        G[x].emplace_back(i);
    }
    dfs(1,0);
    int q = read();
    dbg_a(in,1,7);
    dbg_a(out,1,7);
    while(q--){
        int x,d;
        read(x,d);
        auto depth = lis[d];
        int res = lower_bound(All(depth),out[x]) - lower_bound(All(depth),in[x]);
        cout<<res<<"\n";
    }

}
signed main(){
    int T = 1;
    //T = read();
    while(T--) solve();
    return 0;
}


/**
*    author:
*    created: 15.11.2020 22:52:52
**/

#pragma region Macros
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
using P = pair<int,int>;
using ll = long long;
const int INF = 1001001001;
const int di[] = {-1,0,1,0}, dj[] = {0,-1,0,1};
typedef vector<int> vi;
typedef vector<vi> vvi;

#define rep(i,n) for(int i = 0; i < (n); i++)
#define repn(i,n) for(int i = 1; i <= (n); i++)
#define pb push_back
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

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

const double PI = acos(-1);
const int mod = 1000000007;
class mint {
  long long x;
  public:
  mint(long long x=0) : x((x%mod+mod)%mod) {}
  mint operator-() const {
    return mint(-x);
  }
  mint& operator+=(const mint& a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint& a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const  mint& a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint& a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint& a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint& a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    return a;
  }
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint& a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint& a) const {
    mint res(*this);
    return res/=a;
  }

  friend ostream& operator<<(ostream& os, const mint& m){
    os << m.x;
    return os;
  }
};
#pragma endregion

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n,w;
  cin >> n >> w;
  vector<ll>weight(200010,0);
  rep(i,n){
    int s,t,w;
    cin >> s >> t >> w;
    weight[s]+=w;
    weight[t]-=w;
  }
  rep(i,200005){
    weight[i+1]+=weight[i];
    if(weight[i]>w){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

#include <iostream>

#include <vector>
#include <string>

#include <algorithm>
#include<cmath>
#define ll long long

using namespace std;

int main(void){
  ll num,pro;
  cin >> num;
  cin >> pro;
  bool ans = true;
  vector<ll> start(num);
  vector<ll> end(num);
  vector<ll> use(num);
  for(int i = 0;i < num;i ++){
    cin >> start[i];
    cin >> end[i];
    cin >> use[i];
  }
  vector<ll> add(300000,0);
  for(int i = 0;i < num;i ++){
    add[start[i]] = add[start[i]] + use[i];
    add[end[i]] = add[end[i]] - use[i];
  }
  ll sum = 0;
  for(int i = 0;i < 300000;i ++){
    sum = sum + add[i];
    if(sum > pro){
      ans = false;
    }
  }
  if(ans == true){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;
}


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

int charToInt(char c){
    char zero_num = '0';
    return (int)c - (int)zero_num;
}

void cout_line(vector<int> &a){
    for(int i=0;i<a.size();i++){
        if(i<a.size()-1){
            cout<<a.at(i)<<" ";
        }else{
            cout<<a.at(i)<<endl;
        }
    }
}

signed main(){
    int N; cin>>N;
    vec_int A(N); rep(i,N)cin>>A.at(i);
    int MOD = pow(10, 9) + 7;

    vec_int cumul_A(N+1, 0);
    for(int i=1;i<=N;i++){
        cumul_A.at(i) = cumul_A.at(i-1)+A.at(i-1);
    }

    vector<vec_int> DP(N+1, vec_int(N+1, 0)); // DP.at(i).at(j): j番目の数値までをi個に区切ったときの数
    DP.at(0).at(0) = 1;

    for(int i=0;i<N;i++){

        vec_int cumul_A2(N+1);
        rep(k,N+1)cumul_A2.at(k) = cumul_A.at(k)%(i+1);
        vector<vec_int> inds(i+1);
        vector<vec_int> cumul(i+1);
        rep(k, i+1)cumul.at(k).push_back(0);
        vec_int start_vec(N+1, 0);
        rep(k,N+1){
            inds.at(cumul_A2.at(k)).push_back(k);
            int sz = inds.at(cumul_A2.at(k)).size();
            start_vec.at(k) = sz-1;
            int prev = cumul.at(cumul_A2.at(k)).at(sz-1);
            cumul.at(cumul_A2.at(k)).push_back(prev + DP.at(i).at(k));
        }

        for(int j=1;j<=N;j++){
            // if(DP.at(i).at(j)==0)continue;
            int from = cumul_A2.at(j);
            int start_ind = start_vec.at(j);
            // cout<<i<<" "<<j<<" "<<from<<" "<<start_ind<<" "<<cumul.at(from).at(start_ind)<<endl;
            DP.at(i+1).at(j) += cumul.at(from).at(start_ind);
            DP.at(i+1).at(j) %= MOD;
            /*
            for(int k=start_ind+1; k<inds.at(from).size();k++){
                DP.at(i+1).at(inds.at(from).at(k)) += DP.at(i).at(j);
                DP.at(i+1).at(inds.at(from).at(k)) %= MOD;
            }
            */
        }
    }
    int ans = 0;
    for(int i=1;i<=N;i++){
        ans += DP.at(i).at(N);
        ans %= MOD;
    }
    cout<<ans<<endl;

    return 0;
}

#include<stdio.h>
using ll=long long;
constexpr int mod=1000000007;

int N,M,K,inv[2000000]={1,1};
int main(){
  for(int i=2;i<2000000;++i)inv[i]=ll(inv[mod%i])*(mod-mod/i)%mod;
  for(int i=2;i<2000000;++i)inv[i]=ll(inv[i])*inv[i-1]%mod;

  scanf("%d %d %d",&N,&M,&K);
  ll p=1;
  for(int i=2;i<=N+M;++i)(p*=i)%=mod;
  int ans=p*inv[N]%mod*inv[M]%mod;
  if(N+M<=K||N==K){
    printf("%d\n",ans);
    return 0;
  }
  if(N>M+K){
    puts("0");
    return 0;
  }
  ++K;
  ans-=p*inv[N-K]%mod*inv[M+K]%mod;
  if(ans<0)ans+=mod;
  printf("%d\n",ans);
}


#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<sstream>
#include<cstring>
#include<cstdio>
#include<string>
#include<deque>
#include<cmath>
#include<queue>
#include<set>
#include<map>

using namespace std;

std::set<long long> numSet;

bool isPrime(long long num) {
	if (num == 2)
		return true;
	if (num % 2 == 0)
		return false;

	int d = 3;
	while ((d * d) <= num) {
		if (num % d == 0)
			return false;
		d = d + 2;
	}

	return true;
}

int main(void)
{
	long long n;
	long long left;

	scanf("%lld", &n);
	left = n;

	long long p;
	p = 2;
	while ((p * p) <= n) {
//		if (isPrime(p) == false) {
//			p++;
//			continue;
//		}
		if (numSet.find(p) != numSet.end()) {
			p++;
			continue;
		}

		long long curNum = p * p;

		while (curNum <= n) {
			numSet.insert(curNum);
			left--;
			curNum = curNum * p;
		}
		p++;
	}

	printf("%lld\n", left);

	return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <functional>
#include <cmath>
#include <unordered_set>
using namespace std;

int main()
{
    long N;
    cin >> N;
    unordered_set<long> s;
    for(long i = 2; i*i <= N; i++){
        long exp = i*i;
        while(exp <= N){
            s.insert(exp);
            exp *= i;
        }
    }

    cout << N - s.size() << endl;
}