#include <bits/stdc++.h>
using namespace std;
const int mxn=3e5+5;
vector<int>a(mxn);
template<typename T>
struct segtree {
	const int n;
    vector<T> stree;
    segtree(int n) : n(n), stree(4*n) {}
    void build(int id,int l,int r){//build segment tree
		if(r-l<2){
			stree[id]=a[l];
			return;
		}
		int mid=(l+r)/2;
		build(2*id,l,mid);
		build(2*id+1,mid,r);
		stree[id]=stree[2*id]^stree[2*id+1];
	}
	void modify(int p,T x,int id,int l,int r){//here we change pth position to x(0-based)
		stree[id]^=x;
		if(r-l<2){
			a[p]=x;
			return;
		}
		int mid=(l+r)/2;
		if(mid>p)
		return modify(p,x,2*id,l,mid);
		else
		return modify(p,x,2*id+1,mid,r);
	}
	T query(int x,int y,int id,int l,int r){//sum from x to y
		if(x >= r or l >= y)	return 0;
		if(x <= l && r <= y)	return stree[id];
		int mid = (l+r)/2;
		return query(x, y, id * 2, l, mid)^query(x, y, id * 2 + 1, mid, r);
	}
};
int main() {
	int i,n,q;
	cin>>n>>q;
	for(i=0;i<n;i++)
	cin>>a[i];
    segtree<int>st(n+1);
    st.build(1,0,n+1);
    for (i=0;i<q;i++) {
		int c,x,y;
		cin>>c;
		if(c==1){
			cin>>x>>y;
			st.modify(x-1,y,1,0,n+1);
		}
		else{
			cin>>x>>y;
			cout<<st.query(x-1,y,1,0,n+1)<<'\n';
		}

    }
}

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

using namespace std;

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

    int n;
    cin >> n;
    int m;
    cin >> m;
    vector<int> A(m);
    vector<int> B(m);
    vector<int> C(m);

    for (int i = 0; i < m; ++i) {
        cin >> A[i] >> B[i] >> C[i];
        --A[i], --B[i];
    }

    vector<vector<int>> graph(n);
    vector<vector<int>> rgraph(n);
    for (int i = 0; i < m; ++i) {
        int u = A[i];
        int v = B[i];
        graph[u].push_back(i);
        rgraph[v].push_back(i);
    }

    const long long INF = 1LL << 40;
    vector<long long> dis(n, INF);
    using PII = pair<long long,int>;
    priority_queue<PII, vector<PII>, greater<PII>> pq;
    auto dijkstra = [&](int s) -> long long {
        fill(dis.begin(), dis.end(), INF);
        dis[s] = 0;
        pq.emplace(0, s);
        while (!pq.empty()) {
            int u = pq.top().second;
            auto d = pq.top().first;
            pq.pop();
            if (d != dis[u]) {
                continue;
            }
            for (auto e : graph[u]) {
                int v = B[e];
                long long w = C[e];
                if (dis[v] > d + w) {
                    dis[v] = d + w;
                    pq.emplace(dis[v], v);
                }
            }
        }

        long long res = INF;

        for (auto e : rgraph[s]) {
            int v = A[e];
            long long w = C[e];
            res = min(res, dis[v] + w);
        }

        if (res >= INF) {
            return -1;
        }
        return res;
    };

    for (int i = 0; i < n; ++i) {
        cout << dijkstra(i) << '\n';
    }

    return 0;
}


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

#include <bits/stdc++.h>

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

using namespace std;
using namespace __gnu_pbds;

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

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

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

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

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

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

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

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

void solve(int tc) {
    long double r, x, y;
    read(r, x, y);
    long double num = sqrt((x * x) + (y * y));
    if (num < r) {
        write(2, "\n");
        return;
    } else if (num == r) {
        write(1, "\n");
        return;
    }
    int ans = ceil(num / r);
    write(ans, "\n");
}

signed main() {
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int tc = 1;
    // read(tc);
    for (int curr = 1; curr <= tc; ++curr) {
        solve(curr);
    }
    return 0;
}

// C - Compass Walking
#include <bits/stdc++.h>
using namespace std;

int main(){
	int64_t d2, ok, ng, m, r, x, y; cin>>r>>x>>y;
	d2 = x*x + y*y;
	ok = 0, ng = 1e6;
	while(ng - ok > 1){
		m = (ok + ng) / 2;
		__int128_t rm2 = (__int128_t)r*r*m*m;
		(rm2 < d2? ok:ng) = m;
	}
	cout<< ok + 1 + (d2 < r*r) <<endl;
}


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

typedef long long ll;

int main()
{
    ll a, b;
    cin >> a >> b;
    if(abs(a - b) < 3)
    	puts("Yes");
    else puts("No");
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define ub upper_bound
#define lb lower_bound
#define all(v) ((v).begin()),((v).end())
#define allr(v) ((v).rbegin()),((v).rend())
#define ff first
#define ss second
#define mp make_pair
#define pll pair<ll,ll>
#define fo(i,n) for(ll i=0;i<n;i++)
#define foa(i,s,e) for(ll i=(s);i<=e;i++)
#define fod(i,s,e) for(ll i= (s);i>=(e);i--)
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
#define sz(x) (ll)(x.size())
#define ANS cout<<ans<<'\n'
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define Yes cout<<"Yes\n"
#define No cout<<"No\n"
const ld pi = 3.14159265358979323846;
//ll MOD = 1e9 + 7;
ll MOD = 998244353;
const char nl = '\n';
const ll inf = 1e15;
#define fill(a,b) memset(a, b, sizeof(a))
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) fo(i, n){fo(j, m)cout<<dp[i][j]<<" ";cout<<"\n";}
ll nxt(){ll x; cin >> x; return x;}
ll mul(ll x,ll y){
    return (1ll* (x%MOD)*(y%MOD));
}
ll modpow(ll x,ll y){ll z=1;while(y>0){if(y%2)z=mul(z,x);x =mul(x,x) ;y/=2;}return z;}
ll power(ll x,ll y){ll z=1;while(y>0){if(y%2)z=z*x;x =x*x ;y/=2;}return z;}
ll gcd(ll a,ll b){if(a<b) return gcd(b,a);if(b==0) return a;return gcd(b,a%b);}
ll min(ll a,ll b){if(a<b)return a;return b;}
ll max(ll a,ll b){if(a>b)return a;return b;}
ll sq(ll a){
    ll ans = (1ll*a*a);
    return ans;
}
void solve(){
    ll x,y;
    cin >> x >> y;
    if(abs(x - y) < 3){
        Yes;
    }
    else No;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("inputf.txt" , "r" , stdin) ;
    freopen("outputf.txt" , "w" , stdout) ;
    freopen("error.txt" , "w" , stderr) ;
    #endif
    ll TC = 1;
    //cin>>TC;
    fo(TT, TC){
        // Google,FB cout << "Case #"<< TT + 1 << ": ";
        solve();
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD =  998244353;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
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; }
const long double PI = acos(-1.0);
// cout << fixed << setprecision(14);

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

	int A, B, C;
	cin >> A >> B >> C;
	A = (A+1)*A/2;
	B = (B+1)*B/2;
	C = (C+1)*C/2;
	A %= MOD;
	B %= MOD;
	C %= MOD;
	B = A*B % MOD;
	C = B*C % MOD;
	cout << C << endl;
}

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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define rb              pop_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define un_mii          unordered_map<int,int>
#define pqb             priority_stack<int>
#define pqs             priority_stack<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define all(x)          (x).begin(),(x).end()
#define double          long double
#define pi              3.14159265358979323846

int moduloExp(int a, int b, int n) {
    int result = 1;
    while (b > 0) {
        if ((b & 1) == 1) {
            result = ((result % n) * (a % n)) % n;
        }
        a = ((a % n) * (a % n)) % n;
        b = b >> 1;
    }
    return result % n;
}

int inverseModulo(int a, int m){
    return moduloExp(a,m-2,m);
}

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

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

    return gcd(b, a % b);
}

// GRAPH

// class Graph{
// public:
//     vector<int> g[100005];
//     int V;
//     Graph(int v){
//       V=v;
//     }
//     void addEdge(int x, int y){
//         g[x].pb(y);
//         g[y].pb(x);
//     }

//     int bfs(){
//       map<int,int> dist;
//       for(int i=0;i<V;i++){
//         dist[i]=INT_MAX;
//       }
//       dist[0]=0;
//       queue<int> pendingNodes;
//       pendingNodes.push(0);

//       while(!pendingNodes.empty()){
//         int current_node=pendingNodes.front();
//         pendingNodes.pop();
//         for(auto i:g[current_node]){
//           if(dist[i]==INT_MAX){
//             pendingNodes.push(i);
//             dist[i]=dist[current_node]+1;
//           }
//         }
//       }
//       return dist[V-1];
//     }

// };

// PRIME SEIVE

// const int N=1000001;

// int arr[N];
// vi primes;
// void seive(){
//   for(int i=0;i<N;i++){
//     arr[i]=i;
//   }
//   for(int i=2;i<N;i++){
//     if(arr[i]==i){
//       primes.pb(i);
//       for(int j=i*i;j<N;j+=i){
//         arr[j]=i;
//       }
//     }
//   }
// }

// NCR

// int fact[1005]={0};
// int invfact[1005]={0};
// void preCompute(){
//   fact[0]=1;
//   fact[1]=1;
//   for(int i=2;i<1005;i++){
//     fact[i]=((fact[i-1]%mod)*(i%mod))%mod;
//   }
//   for(int i=0;i<1005;i++){
//     invfact[i]=inverseModulo(fact[i],mod);
//   }
// }
// int ncr(int n, int r){
//   int ans=((fact[n]%mod)*((invfact[n-r]*invfact[r])%mod))%mod;
//   return ans;
// }

void solve() {
  int a,b,c;cin>>a>>b>>c;
  if(c==0){
    if(a>b){
      cout<<"Takahashi";
    }
    else{
      cout<<"Aoki";
    }
  }
  else{
    if(a<b){
      cout<<"Aoki";
    }
    else{
      cout<<"Takahashi";
    }
  }
}
int32_t main() {

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

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

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

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

struct union_find{
    vector<int> rnk, par;

    union_find(int n){
        rnk.resize(n);
        par.resize(n);
        for(int i = 0; i < n; i++){
            par[i] = i;
            rnk[i] = 0;
        }
    }

    int find(int x){
        if (par[x] == x) return x;
        return par[x] = find(par[x]);
    }

    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if (x == y)return;
        if (rnk[x] < rnk[y]){
            par[x] = y;
        }
        else{
            par[y] = x;
            if (rnk[x] == rnk[y])rnk[x]++;
        }
    }

    bool same(int x, int y){
        return find(x) == find(y);
    }
};

vector<vector<P>> g;

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

    ll n, m; cin >> n >> m;
    g.resize(n);
    ll u[m], v[m], c[m];
    zep(j, 0, m){
        cin >> u[j] >> v[j] >> c[j];
        u[j]--;
        v[j]--;
        c[j]--;
        g[u[j]].push_back(P(v[j], c[j]));
        g[v[j]].push_back(P(u[j], c[j]));
    }

    ll ans[n];
    ans[0] = 0;
    queue<ll> q;
    q.push(0);
    bool use[n]; memset(use, 0, sizeof(use));

    while(!q.empty()){
        ll at = q.front(); q.pop();
        use[at] = true;

        zep(j, 0, g[at].size()){
            ll nx = g[at][j].first;
            ll la = g[at][j].second;

            if(!use[nx]){
                q.push(nx);
                if(ans[at] != la){
                    ans[nx] = la;
                }else{
                    ans[nx] = (la + 1) % n;
                }
            }
        }
    }

    zep(i, 0, n){
        print(ans[i] + 1)
    }

    return 0;
}

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define sz(a) ((int)a.size())
#define re return
#define all(a) a.begin(),a.end()
#define int long long
#define Type int
#define rept(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,a) rept(i,0,a)
using namespace std;
const int mod=998244353;
const int mul=332748118;
const int D[4]={mul*2,0,1,1};
const int R[4]={mul*2,1,0,1};
int fac;
int n,m,k;
int f[5005][5005];
int dp[5005][5005];
int num(){
	char c;cin>>c;
	if (c=='R') re 1;
	if (c=='D') re 2;
	re 3;
}
void o(int l){
	fac=1;
	rep(i,l) fac=fac*3%mod;
}
signed main()
{
	cin>>n>>m>>k;
	o(n*m-k);
	rep(i,k){
		int a,b;
		cin>>a>>b;
		f[a-1][b-1]=num();
	}
	for (int i=n-1;i>=0;i--)
		for (int j=m-1;j>=0;j--){
			if (i==n-1&&j==m-1){
				dp[i][j]=fac;
				continue;
			}
			dp[i][j]+=D[f[i][j]]*dp[i+1][j];
			dp[i][j]%=mod;
			dp[i][j]+=R[f[i][j]]*dp[i][j+1];
			dp[i][j]%=mod;
		}
	cout<<dp[0][0];
	re 0;
}


/***"In the name of Allah(swt), the most gracious, most merciful. Allah(swt) blesses with knowledge whom he wants."***/
/*** "ALHAMDULILLAH for Everything..." ***/
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
*/

#include<bits/stdc++.h>
using namespace std;
#define  fastt       ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define  ll         long long
#define  debug      printf("Come here!")
#define  inf        1000000000000000000
#define  pb         push_back
#define  mp         make_pair
#define  sz(a)      a.size()
#define  mem(a,b)   memset(a,b,sizeof(a))
#define  clr(x)     x.clear()
#define  ff         first
#define  ss         second
#define  case(x)    cout << "Case " << x <<": "

#define  md         1000000007
#define  pi         acos(-1.0)
#define  cos(a)     cos(a*pi/180)
#define  sin(a)     sin(a*pi/180)
#define  tan(a)     tan(a*pi/180)
#define  cosi(a)    acos(a)/(pi/180)
#define  sini(a)    asin(a)/(pi/180)
#define  tani(a)    atan(a)/(pi/180)

#define  vl         vector <ll>
#define  vs         vector <string>
#define  vc         vector <char>
#define  vpll       vector < pair <ll, ll> >
#define  vpsl       vector < pair <string, ll> >
#define  vpls       vector < pair <ll, string> >
#define  pql        priority_queue<ll>
#define  minpql     priority_queue<ll,vector<ll>,greater<ll> >

#define  setbits(x)     __builtin_popcountll(x)
#define  zerobits(x)    __builtin_ctzll(x)

#define toll(a) atoll(a.c_str())
string tostr(ll a) {stringstream rr;rr<<a;return rr.str();}
ll pow(ll c,ll d){return d==0?:c*pow(c,d-1);}
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));}
int dx[]={-1, 0, 0, 1};
int dy[]={0, -1, 1, 0};
int dx1[]={-1, -1, -1, 0, 0, 0, 1, 1, 1};
int dy1[]={-1, 0, 1, -1, 0, 1, -1, 0, 1};

/* mpp.max_load_factor(0.25); mpp.reserve(1024); */
/* cout << fixed << setprecision(12);*/
ll n, m;
ll power(ll a, ll b){
    if(b==0)return 1;
    if(b%2==1){
        return ((a%m)*(power(a, b-1)%m))%m;
    }
    else{
        ll x = power(a, b/2);
        return ((x%m) * (x%m))%m;
    }
}
int main()
{
    ll k, i, j;
    ll x, y, p=0, s=10, h, f=0;
    cin>>n>>m;
    p = m;
    m*=m;
    x = power(s, n);
    cout<<x/p<<endl;
    return 0;
}

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0; i<(n); ++i)
#define fixed_setprecision(n) fixed << setprecision((n))
#define execution_time(ti) printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - ti) / CLOCKS_PER_SEC);
#define pai 3.1415926535897932384
#define NUM_MAX 2e18
#define NUM_MIN -1e9

using namespace std;
using ll = long long;
using P = pair<int,int>;
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; }

int H, W, ans;

void dfs(int n, int bit, int A, int B){
    if(n==H*W){
        ans++;
        return;
    }
    if(bit & 1 << n) return dfs(n + 1, bit, A, B);
    if(B) dfs(n+1, bit | 1<<n, A, B-1);
    if(A){
        if(n%W < W-1 && ~bit << n && ~bit << (n+1)) dfs(n+1, bit | 1<<n | 1<<(n+1), A-1, B);
        if(n+W < H*W) dfs(n+1, bit | 1<<n | 1<<(n+W), A-1, B);
    }
}

int main() {
    int A, B;
    cin >> H >> W >> A >> B;

    dfs(0, 0, A, B);

    cout << ans << endl;

    return 0;
}


#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
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<int Mod> class ModInt {
  int v;
public:
  constexpr ModInt(const long long x = 0) noexcept : v((x % Mod + Mod) % Mod) {}
  constexpr ModInt &operator+=(const ModInt rhs) noexcept {
    v += rhs.v;
    if (v >= Mod)
      v -= Mod;
    return *this;
  }
  constexpr ModInt &operator-=(const ModInt rhs) noexcept {
    if (v < rhs.v)
      v += Mod;
    v -= rhs.v;
    return *this;
  }
  constexpr ModInt &operator*=(const ModInt rhs) noexcept {
    v = int(1LL * v * rhs.v % Mod);
    return *this;
  }
  constexpr ModInt &operator/=(ModInt rhs) noexcept {
    long long exp = Mod - 2;
    while (exp) {
      if (exp & 1)
        *this *= rhs;
      rhs *= rhs;
      exp >>= 1;
    }
    return *this;
  }
  constexpr ModInt operator-() const noexcept { return ModInt(-v); }
  constexpr ModInt operator+(const ModInt rhs) const noexcept {
    return ModInt(*this) += rhs;
  }
  constexpr ModInt operator-(const ModInt rhs) const noexcept {
    return ModInt(*this) -= rhs;
  }
  constexpr ModInt operator*(const ModInt rhs) const noexcept {
    return ModInt(*this) *= rhs;
  }
  constexpr ModInt operator/(const ModInt rhs) const noexcept {
    return ModInt(*this) /= rhs;
  }
  constexpr bool operator==(const ModInt rhs) const noexcept {
    return v == rhs.v;
  }
  constexpr bool operator!=(const ModInt rhs) const noexcept {
    return v != rhs.v;
  }
  constexpr ModInt pow(long long exp) const noexcept {
    ModInt res(1), mul(v);
    while (exp) {
      if (exp & 1)
        res *= mul;
      mul *= mul;
      exp >>= 1;
    }
    return res;
  }
  friend ostream &operator<<(ostream &os, const ModInt obj) noexcept {
    return os << obj.v;
  }
  friend istream &operator>>(istream &is, ModInt &obj) noexcept {
    long long tmp;
    is >> tmp;
    obj = ModInt<Mod>(tmp);
    return is;
  }
};
constexpr int MOD = 1000000007;
using mint = ModInt<MOD>;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  rep(_, t) {
    ll n, a, b;
    cin >> n >> a >> b;
    if (a < b)
      swap(a, b);
    mint ans = mint(n-a+1)*(n-a+1)*(n-b+1)*(n-b+1);
    mint sum;
    if (a < n && b > 1) {
      ll mn = a+1, mx = min(a+b-1, n);
      mint l = n-mx+1, r = n-mn+1;
      sum += (l+r)*(r-l+1);
    }
    sum += mint(n-a+1)*(a-b+1);
    ans -= sum*sum;
    cout << ans << '\n';
  }
  return 0;
}

/*pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; i++)
#define RFOR(i, a, n) for (ll i = (ll)n - 1; i >= (ll)a; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define bra(firstsecond) '(' << first< ',' << second< ')'
//constexpr ll MOD = 1000000007;
constexpr ll MOD = 998244353;
ll INF = 1001001001001001001;
long double EPS = 1e-8;
long double PI = 3.141592653589793238;
template <typename T>
void remove(std::vector<T> &vector, unsigned int index)
{
   vector.erase(vector.begin() + index);
}

using Graph = vector<vector<pair<ll,ll>>>;

// MOD確認

ll N,M,Q;
pair<ll,ll> P[60];
ll X[60],L[60],R[60];
ll w[60];
ll done[60];

int main(){
   cin >> N >> M >> Q;
   rep(i,N) cin >> P[i].second >> P[i].first;
   rep(i,M) cin >> X[i];
   rep(i,Q) cin >> L[i] >> R[i];
   sort(P,P+N);
   rep(i,Q){
      ll cnt = 0,res = 0;
      rep(j,M){
         if(j < L[i]-1 || R[i] <= j){
            w[cnt] = X[j];
            cnt++;
         }
      }
      sort(w,w+cnt);
      rep(j,60) done[j] = 0;
      rrep(j,N){
         rep(k,cnt){
            if(!done[k] && w[k] >= P[j].second){
               done[k] = 1;
               res += P[j].first;
               break;
            }
         }
      }
      cout << res << endl;
   }
}


#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <limits>
#include <list>
#include <numeric>
#include <queue>
#include <stack>
#include <utility>
#include <array>
#include <random>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <assert.h>
using namespace std;
typedef long long ll;
#define dump(x) // // cerr << #x << " = " << (x) << " [" << __LINE__ << ":" << __FUNCTION__ << "] " << endl;
// vector出力
template < typename T >
ostream& operator<<(ostream& os, vector< T >& v) {
    os << "{";
    for (int i = 0; i < (int)v.size(); i++) {
        os << v[i] << (i < v.size() - 1 ? ", " : "");
    }
    os << "}";
    return os;
}
// pair出力
template < typename T, typename U >
ostream& operator<<(ostream& os, const pair< T, U >& p) {
    return os << "(" << p.first << ", " << p.second << ")";
}
// map出力
template < typename T, typename U >
ostream& operator<<(ostream& os, const map< T, U >& map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set 出力
template < typename T >
ostream& operator<<(ostream& os, const set< T >& set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// multiset 出力
template < typename T >
ostream& operator<<(ostream& os, const multiset< T >& set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#pragma endregion

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

int main() {
    ll n;cin >> n;
    ll ans = n;
    set<ll> st;
    for (ll i = 2; i*i <= n; i++) {
        for (ll j = i*i; j <= n; j*=i) {
            if (st.find(j) != st.end()) continue;
            // cout << i << " " << j << endl;
            ans--;
            st.insert(j);
        }
    }
    cout << ans << endl;
    return 0;
}

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

#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <complex>
#include <regex>

#define Debug cout << "line: " << __LINE__ << "Debug" << endl;
#define Yes cout << "Yes" << endl;
#define YES cout << "YES" << endl;
#define No cout << "No" << endl;
#define NO cout << "NO" << endl;
#define ALL(a) (a).begin(), (a).end()
#define MP make_pair
#define MOD 1000000007
#define PI 3.14159265358979323846

using namespace std;

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vd = vector<double>;
using vl = vector<long long>;

void set_FPD(int n){
    cout << fixed << setprecision(n);
    return;
}

ll Pow(ll a,ll b){
    ll ans=1;
    for(int i=0;i<b;i++) ans*=a;
    return ans;
}

ll apc(ll n,ll b){
    ll ans=0,tmp=pow(2,b);
    ans+=n%tmp;
    ans+=n/tmp;
    return ans;
}

void Main(){
    ll n;
    cin>>n;
    ll m=1e18;
    for(ll b=0;b<64;b++){
        ll tmp=apc(n,b);
        m=min(m,tmp+b);
    }
    cout<<m<<endl;
    return;
}

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


#include<bits/stdc++.h>
using namespace std;
template <typename T> inline void read(T& A){T x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();A=x*f;}
template <typename T> inline void read(T& A,T& B){read(A),read(B);}
template <typename T> inline void read(T& A,T& B,T& C){read(A),read(B),read(C);}
template <typename T> inline void write(T a){if(a<0)putchar('-'),a=-a;if(a>9)write(a/10);putchar(a%10+'0');}
int n,m,a,b;
int A[1510][1510];
int x[500010];
int y[500010];
int main(){
	read(a,b);
	read(n,m);
	for(int i=1;i<=n;i++){
		read(x[i],y[i]);
		A[x[i]][y[i]]=2;
	}
	for(int i=1;i<=m;i++){
		int u,v;
		read(u,v);
		A[u][v]=1;
	}
	for(int i=1;i<=n;i++){
		int lef=x[i]-1;
		while(lef>=1&&A[lef][y[i]]!=1&&A[lef][y[i]]!=2){
			A[lef][y[i]]=3;
			lef--;
		}
		int rig=x[i]+1;
		while(rig<=a&&A[rig][y[i]]!=1&&A[rig][y[i]]!=2){
			A[rig][y[i]]=3;
			rig++;
		}
		lef=y[i]-1;
		while(lef>=1&&A[x[i]][lef]!=1&&A[x[i]][lef]!=2){
			A[x[i]][lef]=3;
			lef--;
		}
		rig=y[i]+1;
		while(rig<=b&&A[x[i]][rig]!=1&&A[x[i]][rig]!=2){
			A[x[i]][rig]=3;
			rig++;
		}
	}
	int ans=0;
	for(int i=1;i<=a;i++){
		for(int j=1;j<=b;j++){
			ans+=(A[i][j]==2||A[i][j]==3);
		}
	}
	cout<<ans;
	return 0;
}

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

#include <bits/stdc++.h>

// #include <atcoder/all>

using namespace std;
// using namespace atcoder;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define int ll

#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
void YES(bool t=true) {cout<<(t?"YES":"NO")<<endl;}
void Yes(bool t=true) {cout<<(t?"Yes":"No")<<endl;}
void yes(bool t=true) {cout<<(t?"yes":"no")<<endl;}
void NO(bool t=true) {cout<<(t?"NO":"YES")<<endl;}
void No(bool t=true) {cout<<(t?"No":"Yes")<<endl;}
void no(bool t=true) {cout<<(t?"no":"yes")<<endl;}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
int popcount(ll t) { return __builtin_popcountll(t); }
// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {0, 1, 0, -1}, dy = {-1, 0, 1, 0};
// vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
struct Setup_io {
    Setup_io() {
        ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
        cout << fixed << setprecision(25);
    }
} setup_io;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'

ll gcd(ll a, ll b) {
  if (b > a) {
    swap(a, b);
  }
  if (b == 0) return a;
  ll r = a%b;
  while (r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}

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

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

    vi primes;
    REP (i, 2, 51) {
        int x = i;
        bool flag = true;
        for (int j = 2; j < x; j++) {
            if (x % j == 0) {
                flag = false;
            }
        }
        if (flag) primes.push_back(i);
    }

    int m = primes.size();
    ll ans = INF;
    rep (i, 1 << m) {
        ll g = 1;
        rep (j, m) {
            if (i & (1 << j)) g *= primes[j];
        }

        bool flag = true;
        rep (i, n) {
            if (gcd(g, a[i]) == 1) flag = false;
        }
        if (flag) {
            chmin(ans, g);
        }
    }
    cout << ans << endl;
}


#include <iostream>
#include <algorithm>

using namespace std;

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

#include <bits/stdc++.h>
#define M 1000000007
#define ll long long
#define ld long double
#define P pair<int, int>
#define PL pair<ll, ll>
#define F first
#define S second
#define vc vector<int>
#define vcl vector<ll>
#define vcb vector<bool>
#define vt vector
#define pb push_back
#define ha cout << "YES";
#define na cout << "NO";
#define el endl
#define filler(arr, n)          \
    for (int i = 0; i < n; i++) \
        cin >> arr[i];

/*
    generated by
    jaindipankar284
*/
using namespace std;
void solve();

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // int T;
    // cin >> T;
    // while (T--)
    solve();
    return 0;
}
class Helper
{
public:
    ll s;
    ll idx;
    Helper(ll s, ll idx)
    {
        this->s = s;
        this->idx = idx;
    }
};
void solve()
{
    int x;
    cin >> x;
    cout << (x >= 0 ? x : 0);
}


#pragma region templates
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
template<typename T> using PQ = priority_queue<T>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007; // 998244353;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const ld PI = acos((ld)-1);
constexpr ll dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
inline void Yes() { cout << "Yes" << ENDL; }
inline void No() { cout << "No" << ENDL; }
inline void YES() { cout << "YES" << ENDL; }
inline void NO() { cout << "NO" << ENDL; }

template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template <typename T>
vector<T> finddivisor(T x) {  //整数xの約数(xを含む)
  vector<T> divisor;
  for(T i = 1; (i * i) <= x; i++) {
    if(x % i == 0) {
      divisor.push_back(i);
      if(i * i != x) { divisor.push_back(x / i);}
    }
  }
  sort(divisor.begin(), divisor.end());
  return divisor;
}

template <typename T> V<T> prefix_sum(const V<T>& v) {
  int n = v.size();
  V<T> ret(n + 1);
  rep(i, 0, n) ret[i + 1] = ret[i] + v[i];
  return ret;
}

template<typename T>
T rand(T l,T r){
  static random_device rd;
  static mt19937 g(rd());
  return uniform_int_distribution<T>(l,r)(g);
}

template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(auto&& x: vec) is >> x;
  return is;
}

template<typename T,typename Y>
ostream& operator<<(ostream& os,const pair<T,Y>& p){
  return os<<"{"<<p.fs<<","<<p.sc<<"}";
}

template<typename T> ostream& operator<<(ostream& os,const V<T>& v){
  os<<"{";
  for(auto e:v)os<<e<<",";
  return os<<"}";
}

template<typename ...Args>
void debug(Args&... args){
  for(auto const& x:{args...}){
    cerr<<x<<' ';
  }
  cerr<<ENDL;
}
#pragma endregion templates

signed main(){
  cin.tie(0);cerr.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  V<string> s(3);cin>>s;
  V<char> cs(0);

  rep(i,0,3)for(auto&& c:s[i])cs.eb(c);

  sort(all(cs));
  cs.erase(unique(all(cs)),cs.end());

  ll bit=0,step=0;
  V<ll> v(3);
  unordered_map<char,int> ma;
  auto dfs=[&](auto self)->void{
    if(step==siz(cs)){
      v.assign(3,0);
      rep(i,0,3)rep(j,0,siz(s[i])){
        v[i]*=10;
        v[i]+=ma[s[i][j]];
        if(!j && ma[s[i][j]]==0)return;
      }

      if(v[0]+v[1]==v[2]){
        cout<<v[0]<<ENDL<<v[1]<<ENDL<<v[2]<<ENDL;
        exit(0);
      }
    }else{
      rep(i,0,10)if(!(bit & (1<<i))){
        bit|=(1<<i);
        ma[cs[step]]=i;
        step++;
        self(self);
        step--;
        bit^=(1<<i);
      }
    }
    return;
  };

  dfs(dfs);
  cout<<"UNSOLVABLE"<<ENDL;
}
//(・_・)(・_・)(・_・)(・_・)
//CHECK overflow,what to output?
//any other simpler approach?

#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
#define f0(n) for(int i=0;i<n;i++)
#define f1(n) for(int i=1;i<=n;i++)
#define mii map<int,int>
#define mci map<char,int>
#define V vector<int>
#define vp vector<pair<int,int>>
#define pb push_back
#define pp pair<int,int>
#define ff first
#define ss second
#define S set<int>
#define show2(a, b) cout<<a<<' '<<b<<endl;
#define show3(a, b, c) cout<<a<<' '<<b<<' '<<c<<endl;
#define mod 1000000007
int f(string s){
	int n=0;
	for(int i=0;i<s.length();i++){
		n*=10;
		n+=(s[i]-'0');
	}
	return n;
}
int32_t main(){
    int t=1;
    //cin>>t;
	while(t--){
	string s1,s2,s3;
	cin>>s1>>s2>>s3;
	map<char,vector<pp>> m;
	f0(s1.length()) m[s1[i]].pb({1,i});
	f0(s2.length()) m[s2[i]].pb({2,i});
	f0(s3.length()) m[s3[i]].pb({3,i});
	vector<vector<pp>> a;
	for(auto i=m.begin();i!=m.end();i++) a.pb(i->ss);
	if(a.size()>10){
		cout<<"UNSOLVABLE\n";
		return 0;
	}
		V v={0,1,2,3,4,5,6,7,8,9};
			string t1=s1,t2=s2,t3=s3;
	do{
		for(int i=0;i<a.size();i++){
			for(int j=0;j<a[i].size();j++){
				if(a[i][j].ff==1) t1[a[i][j].ss]=v[i]+'0';
				if(a[i][j].ff==2) t2[a[i][j].ss]=v[i]+'0';
				if(a[i][j].ff==3) t3[a[i][j].ss]=v[i]+'0';
			}
		}
		if(t1[0]=='0'||t2[0]=='0'||t3[0]=='0') continue;
		int n1=f(t1),n2=f(t2),n3=f(t3);
		if(n1+n2==n3){
			cout<<n1<<endl;
			cout<<n2<<endl;
			cout<<n3<<endl;
			return 0;
		}

	}
	while(next_permutation(v.begin(),v.end()));
	cout<<"UNSOLVABLE\n";
	}

	return 0;
	}


//2*10^9   -- int
//9*10^18  -- long long int
//10^38    -- __int128_t

//we also have long double
/*A better way to compare ﬂoating point numbers is to assume that
two numbers are equal if the difference between them is less than ε, where ε is a small number.(ε=10−9) */

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

typedef unsigned long long int ull;
typedef long long int ll;
#define endl "\n"
#define sp " "
#define PI 3.14159265358979323846264338327950L

const ll dif=1e-9;
const ll M=1e9+7;

//to handle when remainder is -neg we add + M
//but when rem is +pos that time also we add so use %M
//so it will work for both
ll mod(ll n){
    return (n%M + M)%M;
}
ll modAdd(ll a, ll b){
    return mod(mod(a)+mod(b));
}
ll modMul(ll a, ll b){
    return mod(mod(a)*mod(b));
}
ll modMinus(ll a, ll b){
    return mod(mod(a)-mod(b));
}
ll modpow(ll x, ll n)
{
    if (n == 0)
        return 1%M;
    if (n == 1)
        return x%M;
    ll u = modpow(x,n/2);
    u = modMul(u,u);
    if (n%2)
        u = modMul(u,x);
    return u;
}
ll gcd(ll a,ll b){
    if(b==0)
        return a;
    return gcd(b,a%b);
}
bool isPrime(ll n){
    int end = sqrt(n);
    for(int i=2;i<=end;i++)
        if(n%i==0)
            return false;
    return true;
}

int getParent(vector<int>&parent,int s){
    if(parent[s]==s)
        return s;
    return getParent(parent,parent[s]);
}

void solve(){
    int h,w;
    cin>>h>>w;

    vector<vector<int>> data(h,vector<int>(w,0));
    char c;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>c;
            data[i][j]=(c=='#'?1:0);
        }
    }
    int ans=0;
    //row-wise

    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(data[i][j]==1 && data[i-1][j]==0){
                int k=j;
                ans+=1;
                while(k<w && data[i][k]==1 && data[i-1][k]==0)
                    k++;
                j=k;
            }
        }
    }
     for(int i=h-1;i>=0;i--){
        for(int j=0;j<w;j++){
            if(data[i][j]==1 && data[i+1][j]==0){
                int k=j;
                ans+=1;
                while(k<w && data[i][k]==1 && data[i+1][k]==0)
                    k++;
                j=k;
            }
        }
    }

     for(int i=0;i<w;i++){
        for(int j=0;j<h;j++){
            if(data[j][i]==1 && data[j][i-1]==0){
                int k=j;
                ans+=1;
                while(k<h && data[k][i]==1 && data[k][i-1]==0)
                    k++;
                j=k;
            }
        }
    }

     for(int i=w-1;i>=0;i--){
        for(int j=0;j<h;j++){
            if(data[j][i]==1 && data[j][i+1]==0){
                int k=j;
                ans+=1;
                while(k<h && data[k][i]==1 && data[k][i+1]==0)
                    k++;
                j=k;
            }
        }
    }
    cout<<ans<<endl;
}

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

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

#include <bits/stdc++.h>
#define LL_MAX 1e18
using ll = long long;
using namespace std;
int main(){
    int dx[4]={0,0,-1,-1};
    int dy[4]={-1,0,-1,0};
    int h,w;
    cin>>h>>w;
    vector<string> s(h);
    for(int i=0; i<h; i++) cin>>s[i];
    int ans=0;
    for(int i=1; i<h; i++){
        for(int j=1; j<w; j++){
            int white=0,black=0;
            for(int k=0; k<4; k++){
                if(s[i+dy[k]][j+dx[k]]=='.') white++;
                else black++;
            }
            if(black%2) ans++;
        }
    }
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a)  (a).begin(),(a).end()

int main() {

ll N,M;
cin >> N >> M;

vector<ll> aa((1+N)/2);
vector<ll> bb((1+N)/2);

vector<ll> hh(N);
vector<ll> ww(M);

for(ll i=0;i<N;i++) cin >> hh[i];

for(ll i=0;i<M;i++) cin >> ww[i];

sort(ALL(hh));
ll ans=INF;

aa[0]=0;
for(ll i=1;i<(N+1)/2;i++){
aa[i]=aa[i-1]+hh[2*i-1]-hh[2*i-2];
}

for(ll i=(N-2)/2;i>=0;i--){
bb[i]=bb[i+1]+hh[2*i+2]-hh[2*i+1];
}

for(auto gg : ww){
ll x=lower_bound(ALL(hh),gg)-hh.begin();
 if(x & 1) x^=1;
 chmin(ans,aa[x/2]+bb[x/2]+abs(gg-hh[x]));

}

cout << ans << endl;

}

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

//head

ll cc(ll x) {
  ll res = 1;
  while(x--) res *= 10;
  return res;
}
ll dd(ll x) {return x*x;}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll x = INT_MAX, xt = 0, y = INT_MAX, yt = 0, r = INT_MAX, rt = 0;
  string s;
  cin >> s;
  rep(i, s.size()) {
    if(s[i] != '.') continue;
    if(s[0] != '-') x = 1;
    else x = -1;
    s = s.substr(i+1);
    x *= stoi(s);
    xt = s.size();
    break;
  }
  if(x == INT_MAX) x = 0;
  cin >> s;
  rep(i, s.size()) {
    if(s[i] != '.') continue;
    if(s[0] != '-') y = 1;
    else y = -1;
    s = s.substr(i+1);
    y *= stoi(s);
    yt = s.size();
    break;
  }
  if(y == INT_MAX) y = 0;
  cin >> s;
  rep(i, s.size()) {
    if(s[i] != '.') continue;
    s = s.substr(0, i) + s.substr(i+1);
    r = stoi(s);
    rt = s.size()-i;
    break;
  }
  if(r == INT_MAX) r = stoi(s);
  int t = max({xt, yt, rt});
  x *= cc(t-xt);
  y *= cc(t-yt);
  r *= cc(t-rt);
  ll ans = 0;
  ll u = cc(t);
  //cout << P(x, y) << ' ' << P(r, t) << endl;
  for(ll z = -100010; z < 100010; z++) {
    ll now = z*u;
    //if(abs(y-now) > r) continue;
    //cout << z << endl;
    ll lb = -100010, ub = 1;
    while(ub-lb != 1) {
      ll mid = (lb+ub)>>1;
      if(dd(x-mid*u)+dd(y-now) <= r*r) ub = mid;
      else lb = mid;
    }
    int lef = ub;
    ub = 100010;
    lb = 0;
    while(ub-lb != 1) {
      ll mid = (lb+ub)>>1;
      if(dd(x-mid*u)+dd(y-now) <= r*r) lb = mid;
      else ub = mid;
    }
    ans += lb-lef+1;
  }
  cout << ans << endl;
}


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

template<typename T>
struct BIT {
    int n;
    vector<T> dat;

    BIT(int n=0){
        initialize(n);
    }

    void initialize(int nin){
        n = nin;
        dat.assign(n, 0);
    }

    T sum(int i){
        T s = 0;
        while(i >= 0){
            s += dat[i];
            i = (i & (i+1)) - 1;
        }
        return s;
    }

    T sum_between(int i, int j){
        return sum(j) - sum(i-1);
    }

    void plus(int i, T x){
        while(i < n){
            dat[i] += x;
            i |= i+1;
        }
    }

    // a[0]+...+a[ret] >= x
    int lower_bound(T x){
        if(x < 0) return -1;
        int ret = -1;
        int k = 1;
        while(2*k <= n) k <<= 1;
        for( ;k>0; k>>=1){
            if(ret+k < n && dat[ret+k] < x){
                x -= dat[ret+k];
                ret += k;
            }
        }
        return ret + 1;
    }
};

void fail(){
    cout << -1 << endl;
    exit(0);
}

int main(){
    int N;
    cin >> N;
    map<int, vector<int>> V[2];
    for(int k=0; k<2; k++) for(int i=0; i<N; i++){
        int a;
        cin >> a;
        V[k][a+i].push_back(i);
    }
    vector<int> T(N);
    for(auto& [k, v] : V[0]){
        int sz = v.size();
        if(V[1][k].size() != sz) fail();
        for(int i=0; i<sz; i++) T[v[i]] = V[1][k][i];
    }

    BIT<int> bit(N);
    int64_t ans = 0;
    for(int a : T){
        ans += bit.sum_between(a, N-1);
        bit.plus(a, 1);
    }
    cout << ans << endl;
}

#include<bits/stdc++.h>
#define int long long
const int N=1000050;
using namespace std;

int n,ans,to[N];
struct node{
	int w,p;
	bool operator <(node b)const{return w==b.w?p<b.p:w<b.w;}
}a[N],b[N];

int s[N];
void add(int k){
	while(k<=n)s[k]++,k+=k&-k;
}
int sum(int k){
	int ans=0;while(k)
		ans+=s[k],k-=k&-k;
	return ans;
}

main(){
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)scanf("%lld",&a[i].w),a[i].w+=i,a[i].p=i;
	for(int i=1;i<=n;i++)scanf("%lld",&b[i].w),b[i].w+=i,b[i].p=i;
	sort(a+1,a+1+n);
	sort(b+1,b+1+n);
	for(int i=1;i<=n;i++){
		if(a[i].w!=b[i].w)printf("-1"),exit(0);
		to[a[i].p]=b[i].p;
	}
	for(int i=1;i<=n;i++)
		ans+=sum(to[i]-1),add(to[i]);
	printf("%lld",n*(n-1)/2-ans);
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1;} return 0;}
struct init{init(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}}init_;

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    ll N;
    cin >> N;
    vl E(2 * N, -1), id(2 * N, -1), used(2 * N), se(N), A(N), B(N);
    rep(i, N) {
        cin >> A[i] >> B[i];
        if (A[i] > 0) A[i]--, id[A[i]] = i, used[A[i]]++;
        if (B[i] > 0) B[i]--, id[B[i]] = i, used[B[i]]++;
        if (A[i] >= 0 and B[i] >= 0) se[i] = 1; // 始点終点が決まっている

        if((A[i] >= 0 and B[i] >= 0) and A[i] > B[i]){
            cout << "No" << endl;
            return 0;
        }
    }

    rep(i, 2 * N){
        if(used[i] > 1){
            cout << "No" << endl;
            return 0;
        }
    }

    rep(i, N) {
        if (A[i] == -1 or B[i] == -1) continue;
        ll d = B[i] - A[i];
        repe(j, A[i], B[i] + 1) {
            if(!(E[j] == -1 or E[j] == d)){
                cout << "No" << endl;
                return 0;
            }
            E[j] = d;
        }
    }

    vl pass(2 * N + 1);
    pass[0] = 1;
    rep(i, 2 * N - 1){
        if (!pass[i]) continue;
        // 選ぶ人数
        repe(n, 1, N + 1){
            if (i + 2 * n > 2 * N) break;
            bool isok = true;
            rep(j, n){
                if(id[i + j] == -1 and id[i + j + n] == -1){
                    continue;
                }else if(id[i + j] == -1){
                    if (se[id[i + j + n]]) isok = false;
                }else if(id[i + j + n] == -1){
                    if (se[id[i + j]]) isok = false;
                }else{
                    if (id[i + j] != id[i + j + n]) isok = false;
                }
                if (!isok) break;
            }
            if (isok) pass[i + 2 * n] = 1;
        }
    }

    cout << (pass[2 * N] ? "Yes" : "No") << endl;
}

/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
**/

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

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

#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define     F           first
#define     S           second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     vi          vector<int>
#define     all(x)      x.begin(),x.end()
#define     fix         fixed<<setprecision(10)
#define     rep(i,a,b)  for(int i=int(a);i<=int(b);i++)
#define     repb(i,b,a) for(int i=int(b);i>=int(a);i--)
#define     FastIO      ios_base::sync_with_stdio(0),cin.tie(0)

typedef double db;
typedef long long ll;

const int N=205;
const int mod=1e9+7;

int n,a[N],dp[N][N][N][2][2];

int rec(int i,int s1,int s2,int f1,int f2){
    if(f1 and f2 and s1==s2) return 1;
    if(i>n) return 0;
    int &cache=dp[i][s1][s2][f1][f2];
    if(cache!=-1) return cache;
    return cache=(rec(i+1,(s1+a[i])%200,s2,1,f2)|rec(i+1,s1,(s2+a[i])%200,f1,1)|rec(i+1,s1,s2,f1,f2));
}

void path(int i,int s1,int s2,int f1,int f2,vi &v,vi &u){
    if(i>n) return;
    if(rec(i+1,(s1+a[i])%200,s2,1,f2)){
        v.pb(i);
        return path(i+1,(s1+a[i])%200,s2,1,f2,v,u);
    }
    if(rec(i+1,s1,(s2+a[i])%200,f1,1)){
        u.pb(i);
        return path(i+1,s1,(s2+a[i])%200,f1,1,v,u);
    }
    path(i+1,s1,s2,f1,f2,v,u);
}

signed main(){
    FastIO;
    cin>>n;
    rep(i,1,n) cin>>a[i];
    memset(dp,-1,sizeof dp);
    if(!rec(1,0,0,0,0)){
        return cout<<"NO",0;
    }
    cout<<"YES\n";
    vi v,u;
    path(1,0,0,0,0,v,u);
    cout<<v.size()<<' ';
    for(int i:v) cout<<i<<' ';
    cout<<'\n';
    cout<<u.size()<<' ';
    for(int i:u) cout<<i<<' ';
    return 0;
}


#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define LL long long
template <typename T>
void read (T &x) {
	x = 0; T f = 1;
	char ch = getchar ();
	while (ch < '0' || ch > '9') {
		if (ch == '-') f = -1;
		ch = getchar ();
	}
	while (ch >= '0' && ch <= '9') {
		x = (x << 3) + (x << 1) + ch - '0';
		ch = getchar ();
	}
	x *= f;
}
template <typename T>
void write (T x) {
	if (x < 0) {
		x = -x;
		putchar ('-');
	}
	if (x < 10) {
		putchar (x + '0');
		return;
	}
	write (x / 10);
	putchar (x % 10 + '0');
}
template <typename T>
void print (T x, char ch) {
	write (x); putchar (ch);
}
template <typename T> T Max (T x, T y) { return x > y ? x : y; }
template <typename T> T Min (T x, T y) { return x < y ? x : y; }
template <typename T> T Abs (T x) { return x > 0 ? x : -x; }

const int Maxn = 2 * 1e5;

int n;
int a[Maxn + 5];

int fa[Maxn + 5];
void MakeSet () {
    for (int i = 1; i <= Maxn; i++) {
        fa[i] = i;
    }
}
int FindSet (int x) {
    if (fa[x] != x) {
        fa[x] = FindSet (fa[x]);
    }
    return fa[x];
}
void UnionSet (int x, int y) {
    int u = FindSet (x), v = FindSet (y);
    if (u == v) return;
    fa[u] = v;
}

signed main () {
    MakeSet ();
    read (n);
    for (int i = 1; i <= n; i++) {
        read (a[i]);
    }
    int ans = 0;
    for (int i = 1, j = n; i < j; i++, j--) {
        if (FindSet (a[i]) != FindSet (a[j])) {
            UnionSet (a[i], a[j]);
            ans++;
        }
    }
    write (ans);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define tcase int _; cin >> _; while(_--)
#define ll long long
#define endl '\n'
const int INF = 2e9;
const int MAX = 2e5+100;

void solve() {
    ll n;
    cin >> n;
    vector<int> arr(n);
    for(int &x : arr) cin >> x;

    vector<int> uf(MAX), w(MAX);
    for(int i=0; i<MAX; ++i) uf[i] = i, w[i] = 1;

    auto find = [&](auto &&self, int i) -> int {
        return i == uf[i] ? i : uf[i] = self(self, uf[i]);
    };

    auto join = [&](int i, int j) -> void {
        i = find(find, i);
        j = find(find, j);
        if(i == j) return;
        if(w[i] > w[j]) {
            uf[j] = i;
            w[i] += w[j];
        } else {
            uf[i] = j;
            w[j] += w[i];
        }
    };

    int answer = 0;
    for(int i=0; i<n/2; ++i) {
        if(find(find, arr[i]) != find(find, arr[n-i-1])) {
            answer++;
            join(arr[i], arr[n-i-1]);
        }
    }

    cout << answer << endl;
}

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

    solve();

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <cstring>
#include <bitset>
#include <array>

using namespace std;
typedef long long ll;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll n;
	cin >> n;
	ll pot=3;
	int br1=1, br2=1;
	ll y;
	ll x;
	while(pot<n){
		y=n-pot;
		x=5;
		br2=1;
		while(y>x){
			br2++;
			x*=5;
		}
		if(pot+x==n){
			cout << br1 << ' ' << br2 << '\n';
			return 0;
		}
		br1++;
		pot*=3;
	}
	cout << -1 << '\n';
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
bool _DD = false;
#define _D(a)if(_DD)cout<<#a<<':'<<a<<" | ";
#define DBG(a){_D(a);if(_DD)cout<<'\n';}
#define DBG2(a,b){_D(a);_D(b);if(_DD)cout<<'\n';}
#define DBG3(a,b,c){_D(a);_D(b);_D(c);if(_DD)cout<<'\n';}
#define DBG4(a,b,c,d){_D(a);_D(b);_D(c);_D(d);if(_DD)cout<<'\n';}
#define DBG5(a,b,c,d,e){_D(a);_D(b);_D(c);_D(d);_D(e);if(_DD)cout<<'\n';}
#define DBG6(a,b,c,d,e,f){_D(a);_D(b);_D(c);_D(d);_D(e);_D(f);if(_DD)cout<<'\n';}
#define PB push_back
#define EB emplace_back
#define btoe(v) (v).begin(),(v).end()
#define etob(v) (v).rbegin(),(v).rend()
#define F first
#define S second
#define SZ size()

typedef unsigned long long int ulli;
typedef long long int lli;
typedef long double ldbl;
#define f(i,a,b) for(int i=(a); i<(b); ++i)
#define fr(i,a,b) for(int i=(a); i>(b); --i)
#define fl(i,a,b) for(lli i=(a); i<(b); ++i)
#define flr(i,a,b) for(lli i=(a); i>(b); --i)
#define w(x) lli x; cin>>x; while(x--)
#define inpn(n,v,T) T n; cin>>n; vector<T> v(n); fl(i,0,n) cin>>v[i];
#define inp(n,v,T) vector<T> v(n); fl(i,0,n) cin>>v[i];

typedef pair<int,int> pii;typedef vector<int> vi;typedef vector<vi> vvi;typedef vector<pii> vpii;typedef vector<vector<pii>> vvpii;typedef pair<lli,lli> plli;typedef vector<lli> vlli;typedef vector<vlli> vvlli;typedef vector<plli> vplli;typedef vector<vector<plli>> vvplli;typedef vector<bool> vb;typedef vector<vb> vvb;typedef vector<string> vs;typedef vector<vector<string>> vvs; typedef vector<char> vc; typedef vector<vc> vvc;
#define unmp unordered_map

const lli PRIME = 1000000007ll;
const lli PRIME2 = 998244353ll;

inline void debugORfast(bool a=0,bool b=1){
    if(a) _DD=1;
    if(b){ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}
}

//Question Link

int main(int argc,char* argv[])
{
    if(argc>1 and strcmp(argv[1],"1")==0) debugORfast(1,1);
    else debugORfast(0,1);

	lli n; cin>>n;
	f(t,1,38){
		f(fv,1,26){
			lli val = powl(3,t)+powl(5,fv);
			if(val==n){
				cout<<t<<' '<<fv<<endl;
				return 0;
			}
		}
	}
	cout<<-1<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long li;
typedef long double ld;
typedef pair<int,int> pt;
typedef pair<ld, ld> ptd;
typedef unsigned long long uli;

#define SORT(vec) sort(vec.begin(), vec.end())
#define loop(i,a,n) for(int i=a;i<n;i++)
#define pb push_back
#define mp make_pair
#define mset(a, val) memset(a, val, sizeof (a))
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define ft first
#define sc second
#define sz(a) int((a).size())
#define x first
#define y second

const int INF = int(1e9);
const li INF64 = li(INF) * li(INF);
const ld EPS = 1e-9;
const ld PI = ld(3.1415926535897932384626433832795);
int main(){
li x,y,a,b;
cin>>x>>y>>a>>b;
li ans=1;
li res=0;
for(int i=0;i<=60;i++){
	if(i!=0){
		ans*=a;

	}
	li num=ans*x;
	if(y<=num)break;
	if(num<(ans/a)*x)break;
	res=max(res,(i+(y-num-1)/b));

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

#include<bits/stdc++.h>

using namespace std;

#define debug(x) cout << '[' << #x << " is: " << x << "] " << endl;
#define imod(a , n) (a % n + n ) % n

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
#define inF freopen("file.txt","r",stdin );
#define outF freopen("perimeter.out" , "w" , stdout ) ;
#define sor(v) sort(v.begin() , v.end());
#define print(v) for(auto f : v ) cout << f << " " ;
#define rsor(v) sort(v.rbegin() , v.rend());
#define rev(v) reverse(v.begin() , v.end());
#define lp(i , n) for(int x = i ; x < n ; x ++)
#define ll long long
#define read(arr , x , n) for(int i = x ; i < n ; i ++ )cin >> arr[i];
#define vector deque

const int N = 2e4 + 6, M = N * 4 ;
const ll MOD = 1e9 + 7 ;

int32_t main()
{
    // inF;outF;
    fastio;
    // Dont Forget memset
    //inF;
    ll ans = 0 , a , b , c , d;
    cin >> a >> b >> c >> d ;

    while(b / c > a && a * c < a + d )ans ++ , a *= c ;

    b -= a ;
    b -- ;

    ans += b / d ;

    cout << ans ;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define debug(a) { cerr << #a << ':' << a << endl; }
#define endl '\n'
#define fi first
#define se second
using lint = long long;
using P = pair<int,int>;
template<class T> using V = vector<T>;
template<class T> using priq     = priority_queue<T>;
template<class T> using priq_inv = priority_queue<T, vector<T>, greater<T>>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
template<class T> T ceil(const T &a, const T &b) { return (a+b-1)/b; }
template<class T> bool chmin(T &a, T b) { if(a > b) { a = b; return 1; } return 0; }
template<class T> bool chmax(T &a, T b) { if(a < b) { a = b; return 1; } return 0; }
struct INF { template<class T> operator T() { return numeric_limits<T>::max() / 2; } } INF;

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

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

bool f(int x, V<V<int>> &as) {
    set<V<bool>> st;
    int n = sz(as);
    rep(i,n) {
        V<bool> v(5);
        rep(j,5) v[j] = (as[i][j] >= x);
        st.insert(v);
    }

    bool res = false;
    for(auto i: st) for(auto j: st) for(auto k: st) {
        bool ok = true;
        rep(l,5) {
            ok &= (i[l] || j[l] || k[l]);
        }
        res |= ok;
    }
    return res;
}

int main() {
    int n;
    cin >> n;
    V<V<int>> as(n,V<int>(5));
    cin >> as;

    int l = 0, r = INF;
    while(r-l > 1) {
        int mid = (l+r)/2;
        if(f(mid,as)) l = mid;
        else r = mid;
    }
    cout << l << endl;
}

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

const int N=55;
int n,a[N],X[N],x;
int dp[N][2];

int calc(int i,int carry)
{
    if(i==n+1) return carry^1;
    int &res=dp[i][carry];
    if(res!=-1) return res;
    int lim=a[i+1]/a[i];
    int cur=X[i]+carry;
    if(cur==lim) res=calc(i+1,1);
    else if(cur==0) res=calc(i+1,0);
    else res=calc(i+1,0)+calc(i+1,1);
    return res;
}

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    memset(dp,-1,sizeof dp);
    cin>>n>>x;
    for(int i=1;i<=n;i++) cin>>a[i];
    a[n+1]=1e18;
    for(int i=n;i>=1;i--)
    {
        X[i]=x/a[i];
        x%=a[i];
    }
    cout<<calc(1,0);
}


#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
int mod = 1000000007;
int add(int x, int y) { return (x += y) >= mod ? x - mod : x; }
template<class... T> int add(int x, T... y) { return add(x, add(y...)); }
int mul(int x, int y) { return 1LL * x * y % mod; }
template<class... T> int mul(int x, T... y) { return mul(x, mul(y...)); }
int sub(int x, int y) { return add(x, mod - y); }
int modpow(int a, long long b) {
	int ret = 1; while (b > 0) {
		if (b & 1) ret = 1LL * ret * a % mod; a = 1LL * a * a % mod; b >>= 1;
	} return ret;
}
int modinv(int a) { return modpow(a, mod - 2); }
void chadd(int& x, int y) { x = add(x, y); }
void chsub(int& x, int y) { x = sub(x, y); }
void chmul(int& x, int y) { x = mul(x, y); }
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/

int N, K, M;
const int MA = 251010;
int dp[101][MA];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> K >> mod;

	dp[0][0] = 1;
	rep(i, 0, 100) rep(sm, 0, MA) rep(use, 0, K + 1) if (sm + use * (i + 1) < MA) {
		chadd(dp[i + 1][sm + use * (i + 1)], dp[i][sm]);
	}

	rep(x, 1, N + 1) {
		int lft = x - 1, rht = N - x;
		int ans = 0;
		rep(sm, 0, MA) chadd(ans, mul(dp[lft][sm], dp[rht][sm], K + 1));
		chsub(ans, 1);
		printf("%d\n", ans);
	}
}


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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N; cin >> N;
  ll p = 1;
  ll a = 0;
  while (true) {
    if (p >= N / 3) break;
    a++;
    p *= 3;
    ll q = 1;
    ll b = 0;
    while (true) {
      if (q > (N - p) / 5) break;
      b++;
      q *= 5;
      if (p + q == N) {
	cout << a << " " << b << endl;
	return 0;
      }
    }
  }
  cout << -1 << endl;

  return 0;
}

#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {
    return a < b && (a = b, true);
}
template <typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {
    return a > b && (a = b, true);
}
/*-------------------------------------------*/

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

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

    int ans = 0;
    rep(i, n) ans += max(0, a[i] - 10);
    cout << ans << endl;

    return 0;
}


/*input
3 3 5
2 3 D
1 3 D
2 1 D
1 2 X
3 1 R

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

const ll mod = 998244353,N = 5005;
ll H,W,K;
vector<vector<char>> mat(N,vector<char> (N,'.'));
vector<vector<ll>>  dp(N,vector<ll> (N,-1)),row(N,vector<ll> (N,0)),col(N,vector<ll> (N,0));
vector<ll> power3(N,0);

int main()
{
	cin>>H>>W>>K;
	for(int i=0;i<K;i++){
		ll x,y;cin>>x>>y;
		x--,y--;
		char c;cin>>c;
		mat[x][y] = c;
	}

	for(ll x=0;x<H;x++){
		for(ll y=W-1;y>=0;y--){
			row[x][y] = (mat[x][y]=='.') + (y!=W-1?row[x][y+1]:0);
		}
	}

	for(ll y=0;y<W;y++){
		for(ll x=H-1;x>=0;x--){
			col[x][y] = (mat[x][y]=='.') + (x!=H-1?col[x+1][y]:0);
		}
	}

	power3[0]=1;
	for(ll i =1;i<N;i++){
		power3[i] = (power3[i-1]*3)%mod;
	}

	for(ll x=H-1;x>=0;x--)
	{
		for(ll y=W-1;y>=0;y--)
		{

			if(x==H-1 && y==W-1) { dp[x][y] = ((mat[x][y]=='.')?3:1); continue; }

			ll ans = 0;
			if(mat[x][y]=='R'){
				if(y+1<W){
					ans = (ans + (dp[x][y+1] * power3[col[x][y]])%mod);
				}
			}
			else if(mat[x][y]=='D'){
				if(x+1<H){
					ans = (ans + (dp[x+1][y] * power3[row[x][y]])%mod);
				}
			}
			else if(mat[x][y]=='X'){
				if(y+1<W){
					ans = (ans + (dp[x][y+1] * power3[col[x][y]])%mod);
				}
				if(x+1<H){
					ans = (ans + (dp[x+1][y] * power3[row[x][y]])%mod);
					if(ans>=mod) ans-=mod;
				}
			}
			else{
				if(y+1<W){
					ll val = (dp[x][y+1] * power3[col[x+1][y]])%mod;
					val*=2;
					if(val>=mod) val-=mod;
					ans +=val;
				}
				if(x+1<H){
					ll val = 2*(dp[x+1][y] * power3[row[x][y+1]])%mod;
					if(val>=mod) val-=mod;
					ans+=val;
					if(ans>=mod) ans-=mod;
				}
			}
			dp[x][y]=ans;
		}
	}
	cout<<dp[0][0]<<"\n";

	return 0;
}

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

using ll = long long;

#define fi first
#define se second

const int N = 2e5 + 5;
const int INF = 2e9;
const ll LINF = 9e18;

struct query {
  int T, X, Y;
};

int n, m, q;
int a[N], b[N];
ll tree[4][N << 2];

// 0 = Sum_A, 1 = Sum_B, 2 = Freq_A, 3 = Freq_B

void update(int idx, int l, int r, int pos, ll val, int d) {
  if(l > pos || r < pos) return;
  if(l == r) {
    tree[d][idx] += val;
    return;
  }
  int mid = l + r >> 1;
  update(idx << 1, l, mid, pos, val, d);
  update(idx << 1 | 1, mid + 1, r, pos, val, d);
  tree[d][idx] = tree[d][idx << 1] + tree[d][idx << 1 | 1];
}

ll rangeSum(int idx, int l, int r, int from, int to, int d) {
  if(l > to || r < from) return 0;
  if(from <= l && r <= to) return tree[d][idx];
  int mid = l + r >> 1;
  return (
    rangeSum(idx << 1, l, mid, from, to, d) +
    rangeSum(idx << 1 | 1, mid + 1, r, from, to, d)
  );
}

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

  cin >> n >> m >> q;
  vector<query> Q;
  set<int> distinct;
  distinct.insert(0);
  while(q--) {
    int t, x, y; cin >> t >> x >> y;
    Q.push_back({t, x, y});
    distinct.insert(y);
  }
  int cnt = 0;
  map<int, int> idx;
  for(int u : distinct) {
    idx[u] = ++cnt;
  }
  int s = distinct.size();

  update(1, 1, s, idx[0], n, 2);
  update(1, 1, s, idx[0], m, 3);

  ll ans = 0;
  for(query u : Q) {
    if(u.T == 1) {
      int prv = idx[a[u.X]];
      int nxt = idx[u.Y];

      ans -= rangeSum(1, 1, s, 1, prv, 3) * a[u.X];
      ans += rangeSum(1, 1, s, 1, prv, 1);
      ans -= rangeSum(1, 1, s, 1, nxt, 1);
      ans += rangeSum(1, 1, s, 1, nxt, 3) * u.Y;

      update(1, 1, s, prv, -a[u.X], 0);
      update(1, 1, s, nxt, u.Y, 0);
      update(1, 1, s, prv, -1, 2);
      update(1, 1, s, nxt, 1, 2);

      a[u.X] = u.Y;
    } else {
      int prv = idx[b[u.X]];
      int nxt = idx[u.Y];

      ans -= rangeSum(1, 1, s, 1, prv, 2) * b[u.X];
      ans += rangeSum(1, 1, s, 1, prv, 0);
      ans -= rangeSum(1, 1, s, 1, nxt, 0);
      ans += rangeSum(1, 1, s, 1, nxt, 2) * u.Y;

      update(1, 1, s, prv, -b[u.X], 1);
      update(1, 1, s, nxt, u.Y, 1);
      update(1, 1, s, prv, -1, 3);
      update(1, 1, s, nxt, 1, 3);

      b[u.X] = u.Y;
    }
    cout << ans << "\n";
  }
}


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

typedef complex<double> P;
#define X real()
#define Y imag()

// 内積 |a||b|cos(theta)
double dot(P a, P b) { return a.X * b.X + a.Y * b.Y; }

// 外積 |a||b|sin(theta)
double cross(P a, P b) { return a.X * b.Y - a.Y * b.X; }

int main() {
    int N;
    cin >> N;
    vector<P> A(N), B(N);
    for (auto &x : A) {
        int a, b;
        cin >> a >> b;
        x = P(a, b);
    }
    for (auto &x : B) {
        int a, b;
        cin >> a >> b;
        x = P(a, b);
    }
    map<tuple<int, int, int>, int> s, t;
    auto add = [](auto &s, auto a1, auto a2, auto a3) {
        // 2点間のベクトル
        auto v1 = a2 - a1;
        auto v2 = a3 - a1;
        // 外積
        int cr = cross(v1, v2);
        // 2点間の距離(整数にするため２乗)
        int r1 = abs(v1) * abs(v1);
        int r2 = abs(v2) * abs(v2);
        s[{cr, r1, r2}]++;
    };
    for (auto a : A)
        for (auto b : A)
            for (auto c : A)
                add(s, a, b, c);
    for (auto a : B)
        for (auto b : B)
            for (auto c : B)
                add(t, a, b, c);
    puts(s == t ? "Yes" : "No");
}


#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>
#include <iomanip>

using namespace std;

#define FOR(i, a, b) for(int (i)=(a);(i)<(b);(i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)
#define REP(i, n) FOR((i), 0, (n))

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int main() {
    int h, w, n, m;
    cin >> h >> w >> n >> m;
    vector<int> a(n), b(n), c(m), d(m);
    vector<vector<int>> masu(h, vector<int>(w, 0));
    REP(i, n){
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
        masu[a[i]][b[i]] = 1;
    }
    REP(i, m){
        cin >> c[i] >> d[i];
        c[i]--, d[i]--;
        masu[c[i]][d[i]] = -1;
    }

    vector<vector<vector<bool>>> hikari(h, vector<vector<bool>>(w, vector<bool>(4, false)));
    REP(i, h){
        bool nowl = false;
        bool nowr = false;
        REP(j, w){
            // from left
            if(masu[i][j] == 1) nowl = true;
            else if(masu[i][j] == -1) nowl = false;
            hikari[i][j][0] = nowl;
            // from right
            if(masu[i][w-j-1] == 1) nowr = true;
            else if(masu[i][w-j-1] == -1) nowr = false;
            hikari[i][w-j-1][1] = nowr;
        }
    }
    REP(j, w){
        bool nowt = false;
        bool nowb = false;
        REP(i, h){
            // from top
            if(masu[i][j] == 1) nowt = true;
            else if(masu[i][j] == -1) nowt = false;
            hikari[i][j][2] = nowt;
            // from bottom
            if(masu[h-i-1][j] == 1) nowb = true;
            else if(masu[h-i-1][j] == -1) nowb = false;
            hikari[h-i-1][j][3] = nowb;
        }
    }

    int cnt = 0;
    REP(i, h)
        REP(j, w){
            if(hikari[i][j][0] || hikari[i][j][1] || hikari[i][j][2] || hikari[i][j][3])
                cnt++;
        }

    cout << cnt << endl;
    return 0;
}

#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
using namespace std;
long double  n ,  m , cnt, ans , sum;
ll x , y , z;
ll a , b , c;
string s , s1;
char ch;
map<char , int>mp;
int main(){
    cin >> n >> a >> b >> m;
    if( m / n >= a and m / n <= b )
        cout << "No";
    else
        cout << "Yes";
}


//I still luve you Kashish <3
#include<bits/stdc++.h>
using namespace std ;
#define int                long long
#define pb                 push_back
#define F                  first
#define S                  second
#define P                  push
#define nl                 "\n"
#define vvi                vector<vector<int>>
#define vi                 vector<int>
#define vc                 vector<char>
#define pii                vector<pair<int, int>>
#define sz(a)              (int)a.size()
#define all(a)             a.begin(),a.end()
#define sort(v)            sort(all(v))
#define sortr(v)           sort(v); reverse(all(v));
#define yes                cout << "YES"
#define no                 cout << "NO"
#define PeeleMera          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
const int N = 1e9 + 7 , N1 = 1e7 + 5 , N2 = 1e6 + 3, N3 = 1e5 + 3;
#define IM -1e18
#define IX 1e18

void solve()
{
    string s;
    cin>>s;

    int n=sz(s);
    vi v(26,0),v1(26,0);
    int ans=0;

    for(int i=n-1;i>0;i--)
    {
        if(s[i]==s[i-1])
        {
            ans+=n-i-1-v[s[i]-97];
            // v.clear();
            v=v1;
            v[s[i]-97]+=n-i+1;
            i--;
            continue;
        }
        v[s[i]-97]++;
    }
    cout<<ans;
}

signed main(){
    PeeleMera;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    int t=1;
    // cin>>t;
    // cout<<fixed<<setprecision(9);
    while(t--)
    {
        solve();
        cout<<endl;
    }
}

//Hoang Vu - CVA-BD High School for Gifted Student
#include <bits/stdc++.h>
using namespace std;
//ifstream f1("test.inp");
//ofstream f2("test.out");
//#define cin f1
//#define cout f2
#define fu(i,a,b) for(ll i=a;i<=b;++i)
#define fd(i,a,b) for(ll i=a;i>=b;i--)
#define FastIO ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL);
#define fa(i,s) for(auto i:s)
#define ll long long
#define ld long double
#define pb push_back
//#define mp make_pair
#define ii pair<ll,ll>
#define fi first
#define se second
#define MOD 1000000007
#define inf 10000000000000000
#define MAXN 3000005
ll n,a[MAXN],res=1,su=0;
map<ll,ll> mp;
set<ll> s;
void solve()
{
    cin>>n;
    fu(i,1,n)
    {
        cin>>a[i];
        mp[a[i]]++;
        s.insert(a[i]);
    }
    vector<int> save;
    fa(i,s) save.pb(mp[i]);
    //res=save[0];
    su=save[0];
    fu(i,1,save.size()-1)
    {
        res+=save[i]*su;
        su+=save[i];
    }
    cout<<res-1;
}
int main()
{
    FastIO
    int t=1;
    //cin>>t;
    solve();
}


#include <bits/stdc++.h>
#define ll long long
#define ls id << 1
#define rs id << 1 | 1
#define mem(array, value, size, type) memset(array, value, ((size) + 5) * sizeof(type))
#define memarray(array, value) memset(array, value, sizeof(array))
#define fillarray(array, value, begin, end) fill((array) + (begin), (array) + (end) + 1, value)
#define fillvector(v, value) fill((v).begin(), (v).end(), value)
#define pb(x) push_back(x)
#define st(x) (1LL << (x))
#define pii pair<int, int>
#define mp(a, b) make_pair((a), (b))
#define Flush fflush(stdout)
#define vecfirst (*vec.begin())
#define veclast (*vec.rbegin())
#define vecall(v) (v).begin(), (v).end()
#define vecupsort(v) (sort((v).begin(), (v).end()))
#define vecdownsort(v, type) (sort(vecall(v), greater<type>()))
#define veccmpsort(v, cmp) (sort(vecall(v), cmp))
using namespace std;
const int N = 500050;
const int inf = 0x3f3f3f3f;
const ll llinf = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
clock_t TIME__START, TIME__END;
void program_end()
{
#ifdef ONLINE
    printf("\n\nTime used: %.6lf(s)\n", ((double)TIME__END - TIME__START) / 1000);
    system("pause");
#endif
}
ll r1, c1, r2, c2;

inline void solve()
{
    cin >> r1 >> c1 >> r2 >> c2;
    if (r1 == r2 && c1 == c2)
        return puts("0"), void();
    if ((r1 + c1 == r2 + c2) || (r1 - c1 == r2 - c2) || (abs(r1 - r2) + abs(c1 - c2) <= 3))
        return puts("1"), void();
    if (((r1 + c1) % 2 == (r2 + c2) % 2) || (abs(r1 - r2) + abs(c1 - c2) <= 6))
        return puts("2"), void();
    if (abs(r1 - r2) <= abs(c1 - c2))
    {
        int ans = min(abs(c1 - abs(r1 - r2) - c2), abs(c1 + abs(r1 - r2) - c2));
        if (ans <= 3)
            return puts("2"), void();
    }
    else
    {
        int ans = min(abs(r1 - abs(c1 - c2) - r2), abs(r1 + abs(c1 - c2) - r2));
        if (ans <= 3)
            return puts("2"), void();
    }

    puts("3");
}

int main()
{
    TIME__START = clock();
    int Test = 1;
    // scanf("%d", &Test);
    while (Test--)
    {
        solve();
        // if (Test)
        //     putchar('\n');
    }
    TIME__END = clock();
    program_end();
    return 0;
}

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi >;
using vl = vector<ll>;
using vvl = vector<vl >;
using pairi = pair<int, int>;
using pairl = pair<ll, ll>;

#define TR ","
#define TS " "
#define rep(i,N) for(ll i=0;i<(ll)N;++i)
#define rpt(i,a,b) for(ll i=a;i<(ll)b;++i)
#define all(v) v.begin(), v.end()
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

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

ll lcm(ll x, ll y) {
    return x / gcd(x, y) * y;
}

void printVector(const vector<ll>& vec) {
    for (ll value : vec) {
        cout << value << " ";
    }
    cout << endl;
}

vector<int> IntegerToVector(int bit, int N) {
    vector<int> S;
    for (int i = 0; i < N; ++i) {
        if (bit & (1 << i)) {
            S.push_back(i);
        }
    }
    return S;
}

const int MAXN = 510000;
const int MOD = 1000000007;

long long fac[MAXN], finv[MAXN], inv[MAXN];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAXN; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM(ll n, ll k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {

    ll N, M, T;
    cin >> N >> M >> T;
    vi a(M), b(M);

    ll y = N;

    rep(i, M) cin >> a[i] >> b[i];
    if (N <= a[0]) { cout << "No" << endl; return 0; }
    y -= a[0];

    rep(i, M-1) {
        y = min(N, y + b[i] - a[i]);
        if(y<=a[i+1]-b[i]) { cout << "No" << endl; return 0; }
        y -= a[i + 1] - b[i];
    }

    y = min(N, y + b[M-1] - a[M-1]);
    if (y <= T - b[M-1]) { cout << "No" << endl; return 0; }

    cout << "Yes" << endl; return 0;

}


//  RAKSHIT KADAM
// rax_coder
 #include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 3
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree< int ,  null_type ,  less<int> ,  rb_tree_tag ,  tree_order_statistics_node_update>
#warning check the size of arrays!!!
// NUMERIC DEFINITIONS :
    #define INF 1000000000000000005
    #define inf 1000000004
    #define MOD  1000000007
    #define mod 998244353
    #define MAX 300006
    #define pi 3.1415926535897932384626433832795
#define ld long double
 #define ll long long
 #define int long long
 #define P(gg) for(auto rax:gg){cout<<rax<<" ";}cout<<endl;
 #define Need_for_speed(activated) ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
 #define satisfy ll ter; cin>> ter; while(ter--)
 #define inp(n) int n;cin >> n
 #define mp make_pair
 #define pb push_back
 #define endl "\n"
 #define x first
 #define y second
 #define fore(i,a,b) for(ll i=a;i<b;i++)
 #define forci(i,n) for(ll i=0;i<n;i++)
 #define vi vector<ll>
 #define Endl endl
 #define lb lower_bound
 #define ub upper_bound
#define pii pair<ll,ll>

 #define input freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout)
 #define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;

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

int power(int x, unsigned int y, unsigned int m){ if (y == 0) return 1;int p = power(x, y/2, m) % m;  p = (p * p) % m;return (y%2 == 0)? p : (x * p) % m;}
ll modInverse(int a, int m){{ return power(a, m-2, m);}}
const int maxn = 500003;
//ll fact[300009];
//ll modIN[100009];
//void facto()
//{
//    ll lim =300005;fact[0]=1;
//    for(ll i=1;i<lim;i++)
//    {
//        fact[i]=(fact[i-1]*i)%mod;
//    }
//
//}
//ll ncr(ll a,ll b)
//{
//    ll ret = 0;
//    ret = fact[a]*(modInverse(fact[b],mod));
//
//    ret%=mod;
//    ret*=modInverse(fact[a-b],mod);
//    ret%=mod;
//
//    return ret;
//}
//  """""   1LL << x    """""

void solve()
{
    ll n;cin>>n;
    string s;cin>>s;
    ll ans = 0 ;

    map<char,ll>m;
    for(ll i=0;i<n;i++)
    {
        for(ll j=i;j<n;j++)
        {
            m[s[j]]++;
            if(m['A']==m['T'] && m['C']==m['G'])ans++;
        }
        m.clear();
    }
    cout<<ans<<endl;
}

signed main(){
   Need_for_speed(activated);

//    satisfy
//    {
// solve();
//    }
//
    solve();
    return 0;
}


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

signed main(){
    int t = 1; //cin >> t;
    while(t--){
        int n,k; cin >> n >> k;
        int time[n+1][n+1];
        for(int i = 1; i <= n; i++)
            for(int j = 1; j <= n; j++)
                cin >> time[i][j];
        vector<int> p;
        for(int i = 2; i <= n; i++)
            p.push_back(i);
        int ans = 0;
        do
        {
            int res = 0;
            int city = 1;
            for(int x:p)
            {
                res += time[city][x];
                city = x;
            }
            res += time[city][1];
            if(res == k)
                ans++;
        } while(next_permutation(p.begin(),p.end()));
        cout << ans;
    }
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef std::vector<long long> vll;
typedef std::vector<std::vector<long long>> vvll;
typedef std::vector<bool> vb;
typedef std::vector<std::vector<bool>> vvb;
#define INF 1999999999
#define MODA 1000000007
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define rep1(i,n) for (long long i = 1; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define errvn1(x) cerr << #x <<" "<< x << endl;
#define errvn2(x, y) cerr << #x <<" "<< x <<" "<< #y <<" "<< y << endl;
#define errvn3(x, y, z) cerr << #x <<":"<< x <<" "<< #y <<":"<< y <<" "<< #z <<":"<< z << endl;
#define errvn4(x, y, z, a) cerr << #x <<":"<< x <<" "<< #y <<":"<< y <<" "<< #z <<":"<< z <<" "<< #a <<":"<< a << endl;
#define errop2(x, y) cerr << x <<" "<< y << endl;
#define errop3(x, y, z) cerr << x <<" "<< y <<" "<< z << endl;
#define errop4(x, y, z, a) cerr << x <<" "<< y <<" "<< z <<" "<< a << endl;

ll N, K;
vvll T;
ll ans = 0;

// usage:
// foreach_permutation<long long, long long>(n, [&](vector<long long> ind) {
//   operations here;
// });
template<typename T1 = long long, typename T2 = long long>
void foreach_permutation(T1 n, std::function<void(vector<T2>)> func) {
  vector<T2> indexes(n);
  for (T2 i = 0; i < n; ++i) indexes[i] = i;
  do {
    func(indexes);
  } while (std::next_permutation(indexes.begin(), indexes.end()));
}

int main() {
  cin >> N >> K;
  T.resize(N, vll(N));
  rep(i,N) {
    rep(j,N) {
      cin >> T[i][j];
    }
  }

  ans = 0;
  foreach_permutation<long long, long long>(N, [&](vector<long long> ind) {
    ll dist = 0;
    if (ind[0] != 0) return;
    for(ll i=0; i<N-1; ++i) {
      dist += T[ind[i]][ind[i+1]];
      cerr << ind[i];
    }
    cerr << endl;
    dist += T[ind[N-1]][ind[0]];
    if(dist == K) ans++;
  });

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


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

struct E {
    int to, co;
    E(int to=0, int co=0):
    to(to), co(co) {}
};

int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<E>> g(n);
    rep(i, m){
        int a, b, c;
        cin >> a >> b >> c;
        --a, --b;
        g[a].emplace_back(b, c);
    }
    const int INF = 1001001001;
    rep(sv, n){
        vector<int> dist(n, INF);
        priority_queue<P, vector<P>, greater<P>> q;
        auto push = [&](int v, int d){
            if(dist[v] <= d) return;
            dist[v] = d;
            q.emplace(d, v);
        };
        for (auto&&  e: g[sv]) push(e.to, e.co);
        while(!q.empty()){
            int d = q.top().first;
            int v = q.top().second;
            q.pop();
            if(dist[v] != d) continue;
            for (auto&& e : g[v]){
                push(e.to, d+e.co);
            }
        }
        int ans = dist[sv];
        if (ans == INF) ans = -1;
        cout << ans << endl;
    }
}

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

#define ll long long
#define ull unsigned long long
#define INF LONG_LONG_MAX
#define gcd __gcd

const long mxN=2001;
const ll ax=1e12;

ll n,m;

vector<pair<ll,ll> > adj[mxN];
vector<ll> vst(mxN),dst(mxN);

ll bfs(ll x){
	priority_queue<pair<ll,ll>,vector<pair<ll,ll> > ,greater<pair<ll,ll> > > pq;
	pq.push({0,x});
	int u,v;
	while(pq.size()){
//		cout<<pq.size()<<"\n";
		u=pq.top().second;
		v=pq.top().first;
		pq.pop();
		for(int i=0;i<adj[u].size();i++){
//			cout<<v+adj[u][i].second<<" "<<dst[adj[u][i].first]<<"\n";
			if((v+adj[u][i].second)<dst[adj[u][i].first]){
				dst[adj[u][i].first]=v+adj[u][i].second;
				pq.push({v+adj[u][i].second,adj[u][i].first});
			}
		}
	}
	return dst[x];
}

void solve(){
	cin>>n>>m;
	ll u,v,w;
	for(int i=0;i<m;i++){
		cin>>u>>v>>w;
		adj[u].push_back({v,w});
	}
	vector<ll> ans(n+1);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			dst[j]=ax;
		}
		ll y=bfs(i);
		if(y>=ax){
			ans[i]=-1;
		}else{
			ans[i]=y;
		}
	}
	for(int i=1;i<=n;i++){
		cout<<ans[i]<<"\n";
	}
}

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


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

using namespace std;
using ll = long long;

int n,m,k;
vector<pair<int,int>> v;
vector<pair<int,int>> item;
int dish[105];
int ans = 0;

void chk(){
    int result = 0;
    for(int i=0;i<m;i++){
        if(dish[v[i].first]>0&&dish[v[i].second]>0) result++;
    }
    ans = max(ans,result);
}

void dfs(int idx){
    if(idx==k){
        chk();
        return;
    }
    dish[item[idx].first]++;
    dfs(idx+1);
    dish[item[idx].first]--;
    dish[item[idx].second]++;
    dfs(idx+1);
    dish[item[idx].second]--;
}

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

    cin >> n >> m;
    for(int i=0;i<m;i++){
        int a,b;
        cin >> a >> b;
        v.push_back({a,b});
    }
    cin >> k;
    for(int i=0;i<k;i++){
        int c,d;
        cin >> c >> d;
        item.push_back({c,d});
    }
    dfs(0);
    cout << ans;

    return 0;
}

#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
// #include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define pb push_back
#define INF 1000000000
#define LL_MAX 1000000000000000000
#define LL_MIN -1000000000000000000
#define mod 1000000007
#define mod2 998244353
#define PI 3.14159265358979323846264338327950288419716939937510
#define ll long long
#define ld long double
#define vi vector <int>
#define vb vector<bool>
#define vvi vector <vector<int>>
#define vvb vector <vector<bool>>
#define vvvi vector <vector<vector<int>>>
#define vll vector<ll>
#define vvl vector <vector<ll>>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpii vector<pair<int,int>>
#define pld pair<ld,ld>
#define vpll vector<pair<ll,ll>>
#define vpld vector<pair<ld,ld>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define sz(a) (int)a.size()
#define FIO   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fs(x) fixed<<setprecision(x)
#define print(a) {for(auto x:a){cout << x << " ";}}
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// template <typename T>
// using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

bool chmin(ll& a, const ll& b) {
	return b < a ? a = b, 1 : 0;
}
bool chmax(ll& a, const ll& b) {
	return a < b ? a = b, 1 : 0;
}
constexpr int pct(int x) { return __builtin_popcount(x); }
constexpr int bits(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))

const int N = 3e5 + 5;

void run_case() {
	int n;
	ld D, H;
	cin >> n >> D >> H;
	ld ans = 0;
	for (int i = 0; i < n; i++) {
		int d, h;
		cin >> d >> h;
		ld x = (ld)H - ((ld)(H - h) / (D - d)) * D ;
		if (x > ans )ans = x;
	}
	cout << fs(20) << ans << endl;
}
auto clk = clock();
int main()
{

	FIO
#ifndef ONLINE_JUDGE
	//for getting input from input.txt
	freopen("input.txt", "r", stdin);
	//for writting output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	int t;
	//cin >> t;
	t = 1;
	for (int i = 1; i <= t; i++) {
		//cout << "case #" << i << ": " ;
		run_case();
	}
#ifndef ONLINE_JUDGE
	cout << endl
	     << "Time elapsed: " << fs(10) << (double)(clock() - clk) / CLOCKS_PER_SEC << endl
	     << endl;
#endif
	return 0;
}
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * in case of segmentation fault check for ex- a variable declared more than once , or index becoming negative
    * check TLE due to not clearing adjacency list for each test
    * do smth instead of nothing and stay organized
    * BELIEVE in yourself
*/


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
ll mod = 1000000007;
double eps = 1e-12;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 2e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())

int f(int n)
{
    if(n == 1) return 1;
    return n*f(n-1);
}
int C(int n,int r)
{
    return (f(n)/(f(n-r)*f(r)));
}
void solve()
{
    int x,a=0,b=0;
    string s;
    cin>>s;
    for(int i=0;i<10;i++)
    {
        if(s[i] == 'o')
        {
            a++;
        }
        if(s[i] == '?')
        {
            b++;
        }
    }
    if(a<=4)
    {
        if(a == 0)
        {
            cout<<pow(b,4);
        }
        else if(a == 1)
        {
            cout<<pow(b+1,4)-pow(b,4);
        }
        else if(a == 2)
        {
            cout<<C(b,2)*24+b*12+(f(4)*b)+14;
        }
        else if(a == 3)
        {
            cout<<(f(4)*b)+3*12;
        }
        else
        {
            cout<<f(4);
        }
    }
    else
    {
        cout<<0;
    }
}
int main()
{
    fast_cin();
    solve();
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vs vector <string>
#define vpii vector <pair <int, int> >
#define vpll vector <pair <long long, long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define vb vector <bool>
#define vvb vector <vb>
#define mp make_pair
#define vvll vector <vll>
#define vsi vector <si>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MANX MAXN
#define itn int
#define dbg(x); {cout<<#x<<"="<<x<<", ";}
#define in(x); { for (auto &to : x) cin>>to;}
#define out(x); { for (auto &to : x) cout<<to<<" ";cout<<'\n'; }

const ll INFLL = 1e18;
const int MAXN = 1e6+100;
const ll INF = 1e9;
const int mod1 = 1e9+7;
const int mod2 = 1e9+21;
ll lcm(ll a,ll b)
{
    return a*b/__gcd(a,b);
}
void solve()
{
//    for (int i=2;i<=30;i++) {
        int n;
        cin >> n;
//        n=i;
        ll x = 1;
        for (int i = 2; i <= n; i++)
            x = lcm(x, i);
        assert(x+1<=1e13);
        cout << x + 1 << '\n';
//    }
}

int main() {
    #ifdef Mip182
    #else
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #endif
    #ifdef Mip182
    freopen("a.in", "r", stdin);
    #endif
    int _t;
    _t=1;
//    cin>>_t;
    while (_t--)
        solve();
    #ifdef Mip182
    cout<<'\n'<<"Time : "<<(double)(clock())/CLOCKS_PER_SEC<<'\n';
    #endif
}


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

using namespace std;

int main()
{

    int a, b;
    cin >> a >> b;

    if (a + b >= 15 && b >= 8)
    {
        cout << 1 << endl;
    }
    else if (a + b >= 10 && b >= 3)
    {
        cout << 2 << endl;
    }
    else if (a + b >= 3)
    {
        cout << 3 << endl;
    }
    else
    {
        cout << 4 << endl;
    }

    return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i,n) for(int i = 0; i < (n); i++)

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

int main() {
    int a, b;
    cin >> a >> b;
    int ans = max(s(a), s(b));
    cout << ans << endl;
    return 0;
}


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

#define PI double(2 * asin(1.0))
#define ll long long
#define MOD 1000000007
#define INF 1e15

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

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

	unordered_map<int, int> umap;
	int64_t cnt = 0;
	for (int i = 0; i < n; ++i)
		umap[a[i] - 200]++;

	for (auto x : umap)
	{
		cnt += ((long long)x.second * (x.second - 1)) / 2;
	}
	cout << cnt << endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)//iをaからn
#define per(i,n,a) for (int i=a-1;i>=n;i--)//iをnからa
#define db(x) cout << #x << " = " << x << endl//デバッグ用
#define db2(x, y) cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"; //デバッグ用
#define all(x) (x).begin(), (x).end()
#define INF32 2147483647 //2.147483647×10^{9}:32bit整数のinf
#define INF64 9223372036854775807 //9.223372036854775807×10^{18}:64bit整数のinf
#define MOD 1000000007 //10^9+7:合同式の法
#define pb push_back
#define F first
#define S second
typedef long long ll;

//sort(all(a)); ソート
//sort(all(a),greater<int>()); 逆順ソート
//a.erase(unique(all(a)), a.end()); ソート後に重複を削除
//cout<< std::fixed << std::setprecision(15)<<0.000001<<endl; 小数点以下を表示させる
//vector<vector<int>> data(3, vector<int>(4)); int型の2次元配列(3×4要素の)の宣言

int main() {
    ll n;
    cin>>n;
    vector<ll> amari(200);
    ll aaa;
    rep(i,0,n){
    cin>>aaa;
    amari.at(aaa%200)++;
    }
    ll ans=0;
    rep(i,0,200){
        //cout<<amari.at(i)<<" ";
    ans+=((amari.at(i)-1)*amari.at(i))/2;
    }
    cout<<ans;
}