#include <assert.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <map>

using namespace std;

#define all(x) x.begin(), x.end()

const long long mod = (long long) (1e9 + 7);

long long powerf(long long a, long long b, long long c = mod) {
	long long res = 1;
	while (b > 0) {
		if (b%2 != 0)
			res = (res * a) % c;
		b/=2;
		a = (a * a) % c;
	}
	return res;
}

template<class T>
T gcd(T a, T b) {
	return (a == 0 ? b : gcd(b%a, a));
}

const int N = (int)(1e6 + 6);
vector<long long> mul(N, 0);
vector<long long> tmp1(N, 0);
long long nonCoPrimes = 0;
long long L, R;

auto nc2 = [](long long x) {
	return (x * (x - 1)) / 2;
};

void init() {
	for (long long x = 2; x < N; x++) {
		for (long long y = x; y < N; y+=x) {
			if (y >= L && y <= R)
				mul[x]++;
		}
	}

	for (long long x = N-1; x >= 2; x--) {
		long long cur = 0;
		cur = nc2(mul[x]);
		for (long long y = 2*x; y < N; y+=x) {
			cur -= tmp1[y];
		}
		tmp1[x] = cur;
		nonCoPrimes += tmp1[x];
	}
}

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

	cin >> L >> R;
	init();
	long long completelyDivPairs = 0;

	for (long long x = max(L, 2LL); x <= R; x++) {
		completelyDivPairs += mul[x] - 1;
	}

	cout << 2 * (nonCoPrimes - completelyDivPairs) << "\n";
	return 0;
}

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

using namespace std;
using ll = long long;

ll x,y;
unordered_map<ll,ll> um;

ll solve(ll num){
    if(num==1) return abs(x-num);
    if(um.find(num)!=um.end()) return um.find(num)->second;
    ll result;
    if(num%2) result = min(abs(x-num),min(solve((num+1)/2)+2,solve((num-1)/2)+2));
    else result = min(abs(x-num),solve(num/2)+1);
    um.insert({num,result});
    return result;
}
int main(void){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    cin >> x >> y;
    cout << solve(y);
    return 0;
}


#include <iostream>
#define ll long long
#define f first
#define s second
#define inf 2000000000

using namespace std;

int n, m, nod[20][20], dp[(1<<18)+10], isOK[(1<<18)+10];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    for(int i=1; i<=m; i++)
        {   int nod1, nod2;
            cin >> nod1 >> nod2;
            nod[nod1][nod2] = nod[nod2][nod1] = 1;
        }
    for(int mask=1; mask<(1<<n); mask++)
        {   int cnt = 0, nrbiti = 0;
            for(int bit1=0; bit1<n; bit1++)
                if(mask & (1 << bit1))
                    {   nrbiti++;
                        for(int bit2=bit1+1; bit2<n; bit2++)
                            if(mask & (1 << bit2) && nod[bit1+1][bit2+1]) cnt++;
                    }
            if(cnt == nrbiti * (nrbiti - 1) / 2) isOK[mask] = 1;
        }
    for(int mask=1; mask<(1<<n); mask++)
        {   dp[mask] = inf;
            if(isOK[mask])
                {   dp[mask] = 1;
                    continue;
                }
            int m = mask;
            while(m)
                {   m = (m - 1) & (mask);
                    dp[mask] = min(dp[mask], dp[m] + dp[mask^m]);
                }
        }
    cout << dp[(1<<n)-1] << '\n';
    return 0;
}

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

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

ll read(){
	ll a=0,b=1;char c=getchar();
	while(c>'9'||c<'0'){if(c=='-')b=-1;c=getchar();}
	while(c>='0'&&c<='9')a=a*10+c-48,c=getchar();
	return a*b;
}

const ll mod=1000000007;

ll n,ans;
struct edge{
	int v;
	ull w;
	int nx;
}e[400005];
int hd[200005],cnt;
ull xr[200005],x[200005];

void dfs(int u,int rt,ull v){
	xr[u]=v;
	for(int i=hd[u];i;i=e[i].nx){
		if(e[i].v!=rt){
			dfs(e[i].v,u,v^e[i].w);
		}
	}
}
ll r[200005][64];

int main(){
	n=read();
	for(int i=1;i<n;i++){
		int u=read(),v=read();
		ull w=read();
		e[++cnt]=edge{v,w,hd[u]},hd[u]=cnt;
		e[++cnt]=edge{u,w,hd[v]},hd[v]=cnt;
	}
	dfs(1,0,0);
	ll ans=0;
	for(int i=1;i<=n;i++){
		for(int j=0;j<64;j++)r[i][j]=r[i-1][j];
		ull k=xr[i];
		int ct=0;
		while(k){
			r[i][ct]+=(k&1);
			k>>=1;ct++;
		}
	}
	for(int i=1;i<=n;i++){
		//cout<<i<<" :\n";
		for(int j=0;j<64;j++){
			if(xr[i]&(1ull<<j)){
				ans+=(i-1-r[i-1][j])*((1ull<<j)%mod)%mod;
				ans%=mod;
				//if(i-1-r[i-1][j])cout<<j<<' '<<ans<<'\n';
			}else{
				ans+=(r[i-1][j])*((1ull<<j)%mod)%mod;
				ans%=mod;
				//if(r[i-1][j])cout<<r[i-1][j]<<' '<<j<<' '<<ans<<'\n';
			}
		}
		//cout<<xr[i]<<' '<<ans<<'\n';
	}
	cout<<ans<<'\n';
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define MO 1000000007
#define mem(a,s) memset(a,s,sizeof(a))
#define IOS ios_base::sync_with_stdio(0); cin.tie(NULL);
#define lop(i,s,e) for(int i=s;i<e;i++)
#define lopi(i,s,e) for(int i=s;i>=e;i--)
#define prina(a,n) for(int i=0;i<=n;i++)cout<<a[i]<<" ";cout<<endl;
#define prin2da(a,n,m) lop(i,1,n){lop(j,1,m)cout<<a[i][j]<<" ";cout<<endl;}
#define atout(v) for(auto x:v) cout<<x<<" ";cout<<endl;
#define atin(v) for(auto &x:v) cin>>x;
#define vl vector<ll >
#define vi vector<int >
#define lb lower_bound
#define ub upper_bound
#define sort(a) sort(a.begin(),a.end())
#define mp make_pair
#define all(v) v.begin(),v.end()
#define pll pair<ll,ll>
using namespace std;

bool check(ll l,ll r,vector<vector<ll>> &p,vector<ll> &b) {
	ll n=p.size();
	lop(i,l,r+1) b[i]=0;
	lop(i,0,n) {
		ll x=p[i][0],y=p[i][1];
		if(x!=-1 and y!=-1) {
			if(y<l or x>r) continue;
			if(y-x!=(r-l+1)/2 or b[x]) return false;
			b[x]=1;
		}
		else if(x!=-1 and y==-1) {
			if(x>r or x<l) continue;
			if(x>=(r+l+1)/2 or b[x]) return false;
			b[x]=1;
		}
		else if(x==-1 and y!=-1) {
			if(y<l or y>r) continue;
			x=y-((r-l+1)/2);
			if(y<(r+l+1)/2 or b[x]) return false;
			b[x]=1;
		}
	}
	return true;
}

void solve() {
	ll n;
	cin>>n;
	vector<vector<ll>> p(n,vector<ll>(2,0));
	vector<bool> dp(2*n+1,false);
	vector<ll> b(2*n+1);
	lop(i,0,n) cin>>p[i][0]>>p[i][1];
	dp[0]=true;
	for(int i=0 ; i<(2*n)+1 ; i+=2) {
		for(int j=i+2 ; j<=(2*n)+1 ; j+=2) {
			//cout<<check(i+1,j,p,b)<<endl;
			dp[j]=dp[j]or(dp[i] and check(i+1,j,p,b));
		}
	}
	//atout(dp);
	cout<<((dp[2*n])?"Yes":"No")<<endl;
	return;
}

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

	ll t=1;
	while(t--) {
		solve();
	}

	return 0;
}

#include <bits/stdc++.h>

using namespace std;

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

	int n;
	cin >> n;
	vector<bool> ju(2*n+1);
	vector<int> a(n),b(n);
	bool res=true;
	for(int i=0;i<n;i++){
		cin >> a[i] >> b[i];
		a[i]--,b[i]--;
		if(a[i]>=0 && ju[a[i]]) res=false;
		if(b[i]>=0 && ju[b[i]]) res=false;
		if(a[i]>=0) ju[a[i]]=true;
		if(b[i]>=0) ju[b[i]]=true;

		if(a[i]>=0 && b[i]>=0 && a[i]>=b[i]) res=false;
	}
	if(!res){
		cout << "No" << "\n";
		return 0;
	}

	vector<bool> dp(2*n+1);
	dp[2*n]=true;

	for(int i=2*n-1;i>=0;i--){
		for(int j=1;j<2*n;j++){
			if((i+2*j)>2*n) continue;
			if(!dp[i+2*j]) continue;
			if(dp[i]) continue;

			//i .. i+2*j-1
			vector<bool> ta(2*n);
			bool bo=true;
			int up=i+2*j-1;
			int down=i;
			for(int k=0;k<n;k++){
				if(a[k]<0 && b[k]<0) continue;
				if(b[k]>=0 && b[k]<down) continue;
				if(a[k]>=0 && a[k]>up) continue;
				if(b[k]>=0 && a[k]<0 && b[k]>up) continue;
				if(a[k]>=0 && b[k]<0 && a[k]<down) continue;
				if(a[k]>=0 && b[k]>=0 && a[k]<down && b[k]>up){
					bo=false;
					break;
				}

				if(a[k]>=0 && b[k]>=0){
					if((b[k]-a[k])!=j || ta[b[k]] || ta[a[k]] || a[k]<down || b[k]>up){
						bo=false;
						break;
					}
					ta[a[k]]=true;
					ta[b[k]]=true;
				}else if(a[k]>=0){
					int bb=a[k]+j;
					if(bb>up || ta[a[k]] || ta[bb] || a[k]<down){
						bo=false;
						break;
					}
					ta[a[k]]=true;
					ta[bb]=true;
				}else{
					int aa=b[k]-j;
					if(aa<down || ta[aa] || ta[b[k]] || b[k]>up){
						bo=false;
						break;
					}
					ta[aa]=true;
					ta[b[k]]=true;
				}
			}
			for(int k=down;k<=up;k++){
				if(ta[k]) continue;
				if((k+j)>up) bo=false;
				if(ta[k+j]) bo=false;
				ta[k]=true;
				ta[k+j]=true;
			}
			if(!bo) continue;

			dp[i]=true;
			//cout << i << " " << j << "\n";
		}
		//cout << dp[i] << "\n";
	}
	if(dp[0]) cout << "Yes" << "\n";
	else cout << "No" << "\n";
	return 0;
}


#include<bits/stdc++.h>
#define LL long long
using namespace std;
LL Pow(LL x,LL y,int mod)
{
	if(y==0) return 1ll;
	if(y==1) return x;
	LL a=Pow(x,y>>1,mod);
	if(y&1) return (((a*a)%mod)*x)%mod;
	return (a*a)%mod;
}
int main()
{
	LL a,b,c;
	cin>>a>>b>>c;
	LL x=Pow(b%4,c,4)+4;
	cout<<Pow(a%10,x,10);

}

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

using ll = long long;
const ll INF = __LONG_LONG_MAX__;

using namespace std;

int main() {
    long double x, y, r;
    cin >> x >> y >> r;

    long double e = 1e-9;
    //cout << e << endl;

    ll ans = 0ll;
    for(ll i = (ll)(floor(y+r)); i >= (ll)(ceil(y-r)); i--) {
        long double val = sqrt(r * r - (i-y)*(i-y) + e);
        ll l = ceil(x - val);
        ll r = floor(x + val);
        /*cout << i << " " << val << endl;
        cout << l << " " << r << endl;*/
        ans += r - l + 1;
    }

    cout << ans << endl;

    return 0;
}


#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
#define rprintf(fmt, begin, end) do { const auto end_rp = (end); auto it_rp = (begin); for (bool sp_rp=0; it_rp!=end_rp; ++it_rp) { if (sp_rp) putchar(' '); else sp_rp = true; printf(fmt, *it_rp); } putchar('\n'); } while(0)

int N;
LL A[101];
LL X;

LL dp[101][101];

void MAIN() {
    scanf("%d%lld", &N, &X);
    REP (i, N) scanf("%lld", A+i);
    LL ans = 1LL<<60;
    REP (i, N) {
	amin(ans, X - A[i]);
    }

    for (int B=2; B<=N; B++) {
	memset(dp, 0xc0, sizeof dp);

	dp[0][0] = 0;
	REP (i, N) {
	    int v = A[i] % B;
	    for (int c=i; c>=0; c--) {
		REP (j, B) {
		    amax(dp[c+1][(j+v) % B], dp[c][j] + A[i]);
		}
	    }
	}

	REP (j, B) if (dp[B][j] >= 0 && (X-j) % B == 0) {
	    assert((X-dp[B][j]) % B == 0);
	    LL tmp = (X-dp[B][j]) / B;
	    amin(ans, tmp);
	}
    }

    if (ans == (1LL<<60)) {
	puts("-1");
    } else {
	printf("%lld\n", ans);
    }
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}

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

using namespace std;

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

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

	long long n, x, i, j, k, kk, ans, INF = 1LL << 60, kv;
	cin >> n >> x;
	vector<long long> a(n);
	for (i = 0; i < n; i++) cin >> a[i];

	ans = INF;
	for (kk = 1; kk <= n; kk++) {
		// step, count, mod kk
		vector<vector<vector<long long>>> dp(n + 1, vector<vector<long long>>(kk + 1, vector<long long>(kk, -INF)));

		dp[0][0][0] = 0;
		for (i = 0; i < n; i++) {
			for (j = 0; j <= kk; j++) {
				for (k = 0; k < kk; k++) {
					dp[i + 1][j][k] = max(dp[i + 1][j][k], dp[i][j][k]);
					kv = (k + a[i]) % kk;
					if (j < kk) dp[i + 1][j + 1][kv] = max(dp[i + 1][j + 1][kv], dp[i][j][k] + a[i]);
				}
			}
		}

		if (dp[n][kk][x % kk] > 0) {
			ans = min(ans, (x - dp[n][kk][x % kk]) / kk);
		}
	}

	cout << ans << "\n";

	return 0;
}


#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define fp(x, a, b) for(int x = a; x < b; x++)
#define fn(x, a, b) for(int x = a; x > b; x--)
#define f(x, m) for(auto x : m)
#define cpu() ios::sync_with_stdio(false); cin.tie(nullptr)
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pair<int ,int>>
#define vll vector<pair<ll ,ll>>
#define all(v) v.begin(),v.end()
#define sor(a) sort( a.begin(), a.end() )
#define ros(a) sort( a.rbegin(), a.rend())
#define prec(n) fixed << setprecision(n)
#define ff first
#define ss second
// #define tt third
#define print(x) for(auto it : x) cout << it << " ";
#define debug(x) cerr << #x << " is " << x << endl;
// #define ordered_multiset tree<int, null_type, less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>

typedef long long ll;
using namespace std;
// using namespace __gnu_pbds;
#define dbg(args...){ string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << "NEXT\n"; }
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << ", ";
err(++it, args...);
}
template<typename... T>
void rd(T& ... args){
  ((cin >> args), ...);
}
template<typename... T>
void ps(T ... args){
  ((cout << args << ' '), ...);
  cout<<'\n';
}
const ll MOD = 1e9 + 7, MOD1 = 998244353LL, MAX = 1e2 + 5;
const char nl = '\n';
const int INF = 1e9 + 5;
int n, s, d, x, y;
void solve(){
  cin >> n >> s >> d;
  for(int i = 0; i < n; i++){
    cin >> x >> y;
    if(!(x >= s || y <= d)){
      cout << "Yes\n";
      return;
    }
  }
  cout << "No\n";
}
int main(){
  cpu();
  // int __;
  // cin >> __;
  // while(__--){
  //   solve();
  // }
  solve();
  // cout << nl;

  return 0;
}


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

int main(){
    int N, K;
    cin >> N >> K;
    cout << 50*N*(N+1)*K + K*(K+1)*N/2 << endl;

    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main(void) {
	int n, k;
	long long int sum = 0;
	cin >> n >> k;

	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= k; j++) {
		sum += i*100+j;
        }
	}
	cout << sum << endl;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define endl "\n"
#define deb(x) cout<<#x<<" "<<x<<endl;
#define sc(ar,n) for(int pen=0;pen<n;pen++){ cin>>ar[pen];}
#define pr(ar,n) for(int pen=0;pen<n;pen++){ cout<<ar[pen]<<" ";} cout<<endl;
#define fr(i,x,n) for(int i=x;i<n;i++)
#define frt(it,vb) for(auto it=vb.begin();it!=vb.end();it++)
#define mem(ar,x) memset(ar,x,sizeof(ar));
#define pb push_back
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define rt return 0;
#define ct continue;
#define MAX 1000000000000000000
#define MAX1 1000000000
#define CLK clock_t clk = clock();//Start of main
#define OCLK cerr << "Time (in ms): " << (double)(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n';//End of main
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

inline int solve()
{
    int n;
    cin>>n;
    int ar[n];
    sc(ar,n);
    int mn = MAX;
    fr(i,0,n) mn = min(mn , ar[i]);
    map <int,vector<int> > mp;
    fr(i,0,n){
        int x = ar[i];
        for(int j=1;j<=sqrt(x);j++){
            if(x%j == 0){
                mp[j].push_back(i);
                if(j != x/j)
                mp[x/j].push_back(i);
            }
        }
    }
    int ans = 0;
    frt(it,mp){
        if(it->first > mn) break;
        int g = 0;
        frt(ut,it->second){
            g = __gcd(g , ar[*ut]);
        }
        if(g == it->first){
            ans++;
        }
    }
    cout << ans << endl;
  rt;
}
signed main()
{
    // fastio;
    int t;
    int test_cases=1;
    if(test_cases==0)
    cin>>t;
    else
    t=1;
    while(t--){
        solve();
    }
}

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

#define stp(var, init, end) for (auto var = init; var < end; ++var)
#define stpe(var, init, end) for (auto var = init; var <= end; ++var)
#define ll long long

int main(void)
{
    int n, rnum = 0, gnum = 0, bnum = 0;
    cin >> n;

    vector<ll> rdogs;
    vector<ll> gdogs;
    vector<ll> bdogs;
    ll ina;
    char inc;
    stp(i, 0, 2 * n)
    {
        cin >> ina >> inc;
        if (inc == 'R')
        {
            rdogs.emplace_back(ina);
            ++rnum;
        }
        else if (inc == 'G')
        {
            gdogs.emplace_back(ina);
            ++gnum;
        }
        else if (inc == 'B')
        {
            bdogs.emplace_back(ina);
            ++bnum;
        }
    }
    sort(rdogs.begin(), rdogs.end());
    sort(gdogs.begin(), gdogs.end());
    sort(bdogs.begin(), bdogs.end());
    /*
    cout << "R: ";
    stp(i, 0, rnum)
    {
        cout << rdogs[i] << " ";
    }
    cout << "\n";
    cout << "G: ";
    stp(i, 0, gnum)
    {
        cout << gdogs[i] << " ";
    }
    cout << "\n";
    cout << "B: ";
    stp(i, 0, bnum)
    {
        cout << bdogs[i] << " ";
    }
    cout << "\n\n";
    */

    if (rnum % 2 == 0 && gnum % 2 == 0 && bnum % 2 == 0)
    {
        //cout << "even\n";
        cout << 0;
    }
    else
    {
        ll rgmin = 10000000000000000ll, gbmin = 10000000000000000ll, brmin = 10000000000000000ll;
        if (gnum > 0)
        {
            stp(i, 0, rnum)
            {
                auto iter = lower_bound(gdogs.begin(), gdogs.end(), rdogs[i]);
                if (iter == gdogs.begin())
                    rgmin = min(rgmin, abs(rdogs[i] - *iter));
                else if (iter == gdogs.end())
                    rgmin = min(rgmin, abs(rdogs[i] - *(iter - 1)));
                else
                    rgmin = min(rgmin, min(abs(rdogs[i] - *iter), abs(rdogs[i] - *(iter - 1))));
            }
        }
        if (bnum > 0)
        {
            stp(i, 0, gnum)
            {
                auto iter = lower_bound(bdogs.begin(), bdogs.end(), gdogs[i]);
                if (iter == bdogs.begin())
                    gbmin = min(gbmin, abs(gdogs[i] - *iter));
                else if (iter == bdogs.end())
                    gbmin = min(gbmin, abs(gdogs[i] - *(iter - 1)));
                else
                    gbmin = min(gbmin, min(abs(gdogs[i] - *iter), abs(gdogs[i] - *(iter - 1))));
            }
        }
        if (rnum > 0)
        {
            stp(i, 0, bnum)
            {
                auto iter = lower_bound(rdogs.begin(), rdogs.end(), bdogs[i]);
                if (iter == rdogs.begin())
                    brmin = min(brmin, abs(bdogs[i] - *iter));
                else if (iter == rdogs.end())
                    brmin = min(brmin, abs(bdogs[i] - *(iter - 1)));
                else
                    brmin = min(brmin, min(abs(bdogs[i] - *iter), abs(bdogs[i] - *(iter - 1))));
            }
        }

        if (rnum % 2 == 1 && gnum % 2 == 1)
        {
            if (bnum > 0)
                cout << min(rgmin, gbmin + brmin);
            else
                cout << rgmin;
        }
        else if (gnum % 2 == 1 && bnum % 2 == 1)
        {
            if (rnum > 0)
                cout << min(gbmin, brmin + rgmin);
            else
                cout << gbmin;
        }
        else if (bnum % 2 == 1 && rnum % 2 == 1)
        {
            if (gnum > 0)
                cout << min(brmin, rgmin + gbmin);
            else
                cout << brmin;
        }
    }
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  rep(i,N) cin >> a.at(i);

  int ans=1<<30;
  rep(s,1<<(N-1)){
    int o=0;
    int now=0;
    rep(i,N){
      o |= a.at(i);
      if(s>>i&1){
        now ^= o;
        o = 0;
      }
    }
    now ^= o;
    ans = min(ans,now);
  }
  cout << ans << endl;
}

#include <bits/stdc++.h>
#define endl '\n'
#define umap unordered_map
#define all(var) var.begin(), var.end()
#define input freopen("input", "r", stdin)
#define output freopen("output", "w", stdout)
#define Fast ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL)
#define dbg(x) cerr << #x << " => " << x << endl
using Long = long long;
using namespace std;

signed main () {
    Fast;
    int n; cin >> n;
    int arr[n]; for (int &i: arr) cin >> i;

    vector<int> sets;

    auto calc = [&] (vector<int>& v) {
        int i = 0, idx = 0, Xor = 0;
        while (idx < (int)v.size()) {
            int Or = 0;
            while (i < v[idx]) Or |= arr[i++];
            Xor ^= Or;
            idx++;
        }
        return Xor;
    };
    int ans = INT_MAX;
    for (int i = 1; i <= (1 << (n - 1)); i++) {
        for (int j = 0; j < n - 1; j++) {
            if (i & (1 << j)) {
                sets.push_back(j + 1);
            }
        }
        sets.push_back(n);
        ans = min(ans, calc(sets));
        sets.clear();
    }
    cout << ans << endl;
}


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

#define FASTIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using ll = long long;

const int MOD = 1e9+7;
const ll INF = 1e18;
const int MAXN = 1e6+5;

int main() {
    FASTIO

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

    vector<pair<ll,ll>> v(m);
    for(auto& p : v) cin >> p.first >> p.second;

    ll curr = 0, N = n;
    for(auto p : v) {
        N -= (p.first-curr);
        if(N <= 0) break;
        N = (N+(p.second-p.first) > n) ? n : N+(p.second-p.first);
        curr = p.second;
    }
    N -= (t-curr);
    if(N <= 0) cout << "No\n";
    else cout << "Yes\n";

    return 0;
}

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

///******************************** C o n t a i n e r ********************************///

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

///*********************************** C o n s t ***********************************///

const int       N=1e6+123;
const double    PI = acos(-1);
const ll        MOD=1000000007;                 ///1e9+7

ll dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};       ///first 4 for adjacent
ll dy[] = {0, +1, 0, -1, +1, -1, +1, -1};
ll dx8[]= {+1, +1, -1, -1, +2, +2, -2, -2};    ///knights move
ll dy8[]= {+2, -2, +2, -2, +1, -1, +1, -1};

///********************************** M a r c o ***********************************///

#define pb push_back
#define MP make_pair
#define F first
#define S second
#define test ll tc; cin>>tc; while(tc--)
#define forn(i,n) for(i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) x.size()
#define el <<'\n'
#define sp <<' '
#define print(a) {for(auto x:a)cout<<x<<" ";cout<<endl;}
#define mem(a,b) memset(a, b, sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) (a)*(a)

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

///*********************************** F u n c t i o n ***********************************///

ll powmod(ll a,ll b,ll MOD){ a%=MOD;if(!a) return 0;ll pr=1;while(b>0){if(b&1){pr*=a;pr%=MOD;--b;}a*=a;a%=MOD;b/=2;}return pr;}
ll modinverse(ll a){return powmod(a,MOD-2,MOD);}
bool isPrime(ll n){ if(n<=1)return false;if(n<=3)return true;if(n%2==0 or n%3==0)return false;for(ll i=5;i*i<=n;i+=6){if(n%i==0 or n%(i+2)==0)return false;}return true;}
void seive(bool a[]){vl v; ll mx=sqrt(N),ii,jj;for(ii=3;ii<=mx;ii+=2)if(!a[ii])for(jj=ii*ii;jj<N;jj+=2*ii)a[jj]=true; v.pb(2);for(ii=3;ii<N;ii+=2)if(!a[ii])v.pb(ii);}
void numofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<N;jj+=ii){if(jj==ii*ii) a[jj]++; else a[jj]+=2;}}}
void sumofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<N;jj+=ii){if(jj==ii*ii) a[jj]+=ii; else a[jj]+=ii+jj/ii;}}}

///**************************************************** C o d e ****************************************************///
///-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=///

void _case()
{
    ll n,m,t,ans,i;
    cin>>n>>m>>t;
    ans=n;
    i=0;
    bool ok=false;
    while(m--){
        ll x,y;
        cin>>x>>y;
        ans-=(x-i);
        if(ans<=0) ok=true,ans=0;
        ans+=(y-x);
        if(ans>=n) ans=n;
        i=y;
    }
    ans-=(t-i);
    if(ans<=0) ok=true,ans=0;

    if(ok) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}

main()
{
    fastio();
    _case();

}

///See you soon


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

int main(){
    ll n,m;cin>>n>>m;
    ll a=modpow(10,n,m*m);
    out(a/m);
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

#define amax(a, b) a = std::max(a, b)
#define amin(a, b) a = std::min(a, b)

using ll = long long;

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

    std::vector<ll> sum2cnt(2*N-1);
    for (ll i = 0; i < 2*N-1; i++) {
        sum2cnt[i] = std::min(i + 1, 2*N - i - 1);
    }
    // i, j, kをとりあえず0-indexedで出す
    K--;
    ll begin = 0, end = 1, ijk = 0, dif = 1;
    while (K >= end) {
        ijk++;
        begin = end;
        if (ijk < 2*N-1) {
            dif += sum2cnt[ijk];
        }
        if (ijk - N >= 0) {
            dif -= sum2cnt[ijk - N];
        }
        end += dif;
        // std::cerr << begin << ' ' << end << ' ' << ijk << std::endl;
    }

    ll jk = ijk;
    end = begin + (jk < 2*N - 1 ? sum2cnt[jk] : 0);
    // std::cerr << jk << ' ' << sum2cnt[jk] << ' ' << begin << ' ' << end << std::endl;
    for (; K >= end; jk--, begin = end, end += (jk < 2*N - 1 ? sum2cnt[jk] : 0)); //std::cerr << begin << ' ' << end << ' ' << jk << std::endl;;

    // std::cerr << begin << ' ' << end << ' ' << jk << std::endl;
    // std::cerr << ijk << ' ' << jk << std::endl;
    ll i = ijk - jk;
    ll j = jk - std::min(jk, N-1) + K - begin;
    ll k = jk - j;
    std::cout << i + 1 << ' ' << j + 1 << ' ' << k + 1 << '\n';

    return 0;
}


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

int main() {
	char op1[2], op2[2];
	cin >> op1 >> op2;
	if (op1[0] == 'Y') op2[0] -= 32;
	cout << op2[0] << endl;
	return 0;
}

//#include <bits/stdc++.h>
#include<iostream>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>

#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define rrep2(i,n,a) for(int i = (int)(n); i >= (int)(a); i--)

#define fi first
#define se second

using namespace std;

using ll = long long;
using v_int = vector<int>;
using v2_int = vector<v_int>;
using v_ll = vector<ll>;
using v2_ll = vector<v_ll>;
using v_string = vector<string>;
using v_bool = vector<bool>;
using v2_bool = vector<v_bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

const double PI = 3.1415926535897932;
const int INF = (int)2e9;
const ll LINF = (ll)2e18;
const ll MOD = 998244353;//1000000007;
const int dc[8] = {1, -1, 0,  0, 1, -1,  1, -1};
const int dr[8] = {0,  0, 1, -1, 1,  1, -1, -1};

template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p) {
    return o << "{" << p.first << "," << p.second << "}";
}
template<typename T> inline
istream& operator>>(istream &is, vector<T> &vec) {
    for(auto &v : vec) { is >> v; }
    return is;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<T> &vec) {
    //for(auto &v : vec) { os << v << ",";}
    for(auto &v : vec) { os << v << endl;}
    return os;
}
template<typename T> inline
ostream& operator<<(ostream &os, vector<vector<T> > &mat) {
    for(auto &row : mat) { os << row << endl; }
    return os;
}

template<typename T> inline
void chmin(T &a, T b) { a = min(a, b); }
template<typename T> inline
void chmax(T &a, T b) { a = max(a, b); }

int main(void)
{
    string s, t;
    cin >> s >> t;

    if(s == "Y") {
        int n = t.size();
        rep(i,n) {
            t[i] = toupper(t[i]);
        }
    }
    cout << t << endl;
    return 0;
} /*atcoder*/


#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/trie_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define ll 				long long int
#define ld				long double
#define mod             1000000007
#define inf             1e18
#define endl			"\n"
#define pb 				push_back
#define vi              vector<int>
#define vl              vector<ll>
#define vs				vector<string>
#define pii             pair<ll,ll>
#define ump				unordered_map
#define mp 				make_pair
#define pq_max          priority_queue<ll>
#define pq_min          priority_queue<ll,vi,greater<ll> >
#define all(n) 			n.begin(),n.end()
#define ff 				first
#define ss 				second
#define mid(l,r)        (l+(r-l)/2)
#define bitc(n) 		__builtin_popcount(n)
#define loop(i,a,b) 	for(int i=(a);i<=(b);i++)
#define looprev(i,a,b) 	for(int i=(a);i>=(b);i--)
#define iter(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define log(args...) 	{ string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define logarr(arr,a,b)	for(int z=(a);z<=(b);z++) cout<<(arr[z])<<" ";cout<<endl;
#define M 		1000000007
#define w(x)            int x; cin>>x; while(x--)
template <typename T> T gcd(T a, T b) {if (a % b) return gcd(b, a % b); return b;}
template <typename T> T lcm(T a, T b) {return (a * (b / gcd(a, b)));}
vs tokenizer(string str, char ch) {std::istringstream var((str)); vs v; string t; while (getline((var), t, (ch))) {v.pb(t);} return v;}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cout << *it << " = " << a << endl;
	err(++it, args...);
}
//typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
//typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update> pbtrie;

void file_i_o()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int main(int argc, char const *argv[]) {
	clock_t begin = clock();
	file_i_o();
	// Write your code here....

	double sx, sy, gx, gy;
	cin >> sx >> sy >> gx >> gy;

	double ans = double(((sy * (gx - sx)) / (gy + sy)) + sx);

	cout << fixed << setprecision(10) << ans << endl;

#ifndef ONLINE_JUDGE
	clock_t end = clock();
	cout << "\n\nExecuted In: " << double(end - begin) / CLOCKS_PER_SEC * 1000 << " ms";
#endif
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(i = 0; i < n; i++)
bool dfs(vector<int> &p, int swapFlag, int dep, vector<int> &ans) {
	int n = min(4, (int)p.size());
	int i;

	rep(i, n) if (p[i] != i) break;
	if (i == n) return true;
	if (dep >= n * n) return false;

	rep(i, n - 1) {
		if (i % 2 != swapFlag % 2) { continue; }
		swap(p[i], p[i + 1]);
		ans.push_back(i);
		bool res = dfs(p, !swapFlag, dep + 1, ans);
		if (res) return true;
		swap(p[i], p[i + 1]);
		ans.pop_back();
	}
	return false;
}

vector<int> solve(vector<int> p) {
	int n = p.size();
	int i, j;
	int cnt = 0;
	vector<int> ret;

	for (i = n; i >= 5; i--) {
		rep(j, i) if (p[j] == i - 1) break;
		int pos = j;
		if (pos == i - 1) continue;
		if (pos % 2 != cnt % 2) {
			rep(j, i - 1) {
				if (j != pos && j + 1 != pos && j % 2 == cnt % 2) {
					break;
				}
			}
			swap(p[j], p[j + 1]);
			cnt++;
			ret.push_back(j);
		}
		for (j = pos; j + 1 < i; j++) {
			swap(p[j], p[j + 1]);
			cnt++;
			ret.push_back(j);
		}
	}
	dfs(p, cnt % 2, 0, ret);
	return ret;
}

int main() {
	int T, i;

	cin >> T;
	while (T--) {
		int n;
		cin >> n;
		vector<int> p(n);
		rep(i, n) { cin >> p[i]; p[i]--; }

		vector<int> ans = solve(p);

		cout << ans.size() << endl;
		rep(i, ans.size()) {
			cout << ans[i] + 1;
			if (i + 1 < ans.size()) cout << " ";
		}
		cout << endl;
	}
	return 0;
}


#include <iostream>
using namespace std;
typedef long long ll;
const int maxn = 1e6+10,mod = 1e9+7;
int a,b,x,y,f[maxn][2];
int main() {
	cin >> a >> b >> x >> y;
	f[a<b?a:b][a<b?0:1] = 0;
	f[a<b?a:b][a<b?1:0] = x;
	for(int i = min(a,b)+1; i <= max(a,b); i++){
		f[i][0] = min(f[i-1][0]+y,f[i-1][1]+x);
		f[i][1] = min(f[i][0]+x,f[i-1][1]+y);
	}
	cout << f[a<b?b:a][a<b?1:0] << endl;
	return 0;
}

#include<bits/stdc++.h>

using namespace std;
using ll = int64_t;

int main(){

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

    int a,b,x,y;
    scanf("%d",&a);
    scanf("%d",&b);
    scanf("%d",&x);
    scanf("%d",&y);

    int ans;
    if(y > 2*x){
        if(a == b){
           ans = x;
        }
        else if(a < b){
            ans = x + (b-a)*2*x;
        }
        else{
            ans = x + (a-b-1)*2*x;
        }
    }
    else{
        if(a == b){
            ans = x;
        }
        else if(a < b){
            ans = x + (b-a)*y;
        }
        else{
            ans = x + (a-b-1)*y;
        }
    }
    printf("%d\n",ans);

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=10009;
struct node {
    set<int>q;
} d[N];
int n,ins[N],c[N],dfn[N],low[N],num,cnt=0;
double ans=0;
vector<int>w[N],w1[N],scc[N];
stack<int>st;
set<int>q;
void Tarjan(int x) {
    dfn[x]=low[x]=++num;
    st.push(x),ins[x]=1;
    for(int i=0; i<w[x].size(); i++) {
        int y=w[x][i];
        if(!dfn[y]) {
            Tarjan(y);
            low[x]=min(low[x],low[y]);
        } else if(ins[y])
            low[x]=min(low[x],dfn[y]);
    }
    if(dfn[x]==low[x]) {
        cnt++;
        int y;
        do {
            y=st.top();
            st.pop();
            ins[y]=0;
            c[y]=cnt;
            w1[cnt].push_back(y);
        } while(x!=y);
    }
}
void dfs(int x) {
    d[x].q.insert(x);
    int si=scc[x].size();
    for(int i=0; i<si; i++) {
        int y=scc[x][i];
        if(d[y].q.empty())
            dfs(y);
        for(set<int>::iterator it=d[y].q.begin(); it!=d[y].q.end(); it++)
            d[x].q.insert(*it);
    }
}
int main() {
    scanf("%d",&n);
    for(int i=1; i<=n; i++) {
        char a[N];
        scanf("%s",a+1);
        for(int j=1; a[j]!='\0'; j++)
            if(a[j]=='1')
                w[i].push_back(j);
    }
    for(int i=1; i<=n; i++)
        if(!dfn[i])
            num=0,Tarjan(i);
    for(int i=1; i<=n; i++)
        for(int j=0; j<w[i].size(); j++) {
            int x=w[i][j];
            if(c[i]==c[x])
                continue;
            scc[c[x]].push_back(c[i]);
        }
    for(int i=1; i<=cnt; i++) {
        if(d[i].q.empty())
            dfs(i);
    }
    for(int i=1;i<=cnt;i++){
        int res=0;
        for(set<int>::iterator it=d[i].q.begin(); it!=d[i].q.end(); it++)
            res+=w1[(*it)].size();
        ans+=(double)w1[i].size()/res;
    }
    printf("%.13lf",ans);
    return 0;
}
/*
4
0110
1001
0001
0010
*/

#include<bits/stdc++.h>
#define mp make_pair
#define pb emplace_back
#define fi first
#define se second
#define ick cout << "ickbmi32.9\n"
using namespace std;
struct edge{
    double w = 1;
    int t = 0;
};

edge r[30][30], d[30][30];
int dx[]{0, 0, 1, -1};
int dy[]{1, -1, 0, 0};
char mv[]{'R', 'L', 'D', 'U'};

int getDist(int x, int y, int dir) {
    if(min(x + dx[dir], y + dy[dir]) < 0) return -1;
    if(max(x + dx[dir], y + dy[dir]) >= 30) return -1;
    if(dir == 0) return d[x][y].w;
    if(dir == 1) return d[x][y - 1].w;
    if(dir == 2) return r[x][y].w;
    if(dir == 3) return r[x - 1][y].w;
    return -1;
}

pair<string, vector<pair<int, int>>> path(int x1, int y1, int x2, int y2) {
    double dist[30][30];
    for(int i = 0; i < 30; i++) for(int j = 0; j < 30; j++) dist[i][j] = -1;
    priority_queue<pair<double, pair<int, int>>, vector<pair<double, pair<int, int>>>, greater<>>dij;
    dij.push(mp(0, mp(x1, y1)));
    while(!dij.empty()) {
        pair<double, pair<int, int>> now = dij.top();
        dij.pop();
        if(abs(dist[now.se.fi][now.se.se] + 1) > 1e-5) continue;
        dist[now.se.fi][now.se.se] = now.fi;
        for(int i = 0; i < 4; i++) {
            int di = getDist(now.se.fi, now.se.se, i);
            if(di == -1) continue;
            dij.push(mp(now.fi + di, mp(now.se.fi + dx[i], now.se.se + dy[i])));
        }
    }
    pair<int, int> now = mp(x2, y2);
    vector<pair<int, int>> pa;
    string pam;
    while(now != mp(x1, y1)) {
        //cout << now.fi << ' ' << now.se << endl;
        for(int i = 0; i < 4; i++) {
            int di = getDist(now.fi, now.se, i);
            if(di == -1) continue;
            if(abs(dist[now.fi][now.se] - di - dist[now.fi + dx[i]][now.se + dy[i]]) < 1e-5) {
                pam += mv[i ^ 1];
                now.fi += dx[i];
                now.se += dy[i];
                break;
            }
        }
        pa.pb(now);
    }
    reverse(pa.begin(), pa.end());
    reverse(pam.begin(), pam.end());
    return mp(pam, pa);
}

void upd(string ah, vector<pair<int, int>> ps, double avg) {
    for(int i = 0; i < ah.length(); i++) {
        if(ah[i] == 'D') {
            d[ps[i].fi][ps[i].se].w = (d[ps[i].fi][ps[i].se].w * d[ps[i].fi][ps[i].se].t + avg) / (d[ps[i].fi][ps[i].se].t + 1);
            d[ps[i].fi][ps[i].se].t++;
        }
        if(ah[i] == 'U') {
            d[ps[i].fi][ps[i].se - 1].w = (d[ps[i].fi][ps[i].se - 1].w * d[ps[i].fi][ps[i].se - 1].t + avg) / (d[ps[i].fi][ps[i].se - 1].t + 1);
            d[ps[i].fi][ps[i].se - 1].t++;
        }
        if(ah[i] == 'R') {
            r[ps[i].fi][ps[i].se].w = (r[ps[i].fi][ps[i].se].w * r[ps[i].fi][ps[i].se].t + avg) / (r[ps[i].fi][ps[i].se].t + 1);
            r[ps[i].fi][ps[i].se].t++;
        }
        if(ah[i] == 'L') {
            r[ps[i].fi - 1][ps[i].se].w = (r[ps[i].fi - 1][ps[i].se].w * r[ps[i].fi - 1][ps[i].se].t + avg) / (r[ps[i].fi - 1][ps[i].se].t + 1);
            r[ps[i].fi - 1][ps[i].se].t++;
        }
    }
}
void solve() {
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    pair<string, vector<pair<int, int>>> go = path(x1, y1, x2, y2);
    double in;
    cout << go.fi << '\n';
    fflush(stdout);
    cin >> in;
    upd(go.fi, go.se, in / go.fi.length());
}
int main() {
    for(int _ = 0; _ < 1000; _++) solve();
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
#define ll long long
#define ld long double

using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

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

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

signed main()
{

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

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
        freopen("INPUT.txt","r",stdin);
        freopen("OUTPUT.txt","w",stdout);
    }
#endif

    int v,s,d,t;
    cin>>v>>t>>s>>d;
    int x=t*v;
    int y=v*s;
    if(x<=d && y>=d)
    {
        cout<<"No";
    }
    else
        cout<<"Yes";

}

#include <algorithm>
#include <iostream>
#include <queue>
#include <bitset>
using namespace std;

#define all(x) (x).begin(), (x).end()

using ll = long long;
const int MOD = 1e9 + 7;

void solve() {
    int a, b, w;
    cin >> a >> b >> w;
    w *= 1000;
    int x = 1e9, y = -1;
    for(int i = 1; i <= w; i++) {
        if(a * i <= w && w <= b * i) {
            x = min(x, i);
            y = max(y, i);
        }
    }
    if(y == -1) {
        cout << "UNSATISFIABLE";
    } else {
        cout << x << ' ' << y;
    }
}

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


#include <iostream>

using namespace std;

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

#include <bits/stdc++.h>

const long long INF = 1e9;
const long long MOD = 1e9 + 7;
//const long long MOD = 998244353;
const long long LINF = 1e18;
using namespace std;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define dump(x)  cout << #x << " = " << (x) << endl
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define COUT(x) cout<<(x)<<endl
#define SCOUT(x) cout<<(x)<<" "
#define VECCOUT(x) for(auto&youso_: (x) )cout<<right<<setw(10)<<youso_<<" ";cout<<endl
#define ENDL cout<<endl
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) long long __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define mp make_pair
#define PQ priority_queue<long long>
#define PQG priority_queue<long long,V,greater<long long>>

typedef long long ll;
typedef vector<long long> vl;
typedef vector<long long> vi;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vc> vvc;
typedef pair<long long, long long> pll;

#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
template<class T>
void mod(T &x) {
    x %= MOD;
    x += MOD;
    x %= MOD;
}

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

struct COMB{
    vl fact, fact_inv, inv;
    void init_nCk(long long SIZE) {
        fact.resize(SIZE + 5);
        fact_inv.resize(SIZE + 5);
        inv.resize(SIZE + 5);
        fact.at(0) = fact.at(1) = fact_inv.at(0) = fact_inv.at(1) = inv.at(1) = 1;
        for(long long i = 2; i < SIZE + 5; i++) {
            fact.at(i) = fact.at(i - 1)*i%MOD;
            inv.at(i) = MOD - inv.at(MOD%i)*(MOD/i)%MOD;
            fact_inv.at(i) = fact_inv.at(i - 1)*inv.at(i)%MOD;
        }
    }
    long long nCk (long long n, long long k) {
        assert(!(n < k));
        assert(!(n < 0 || k < 0));
        return fact.at(n)*(fact_inv.at(k)*fact_inv.at(n - k)%MOD)%MOD;
    }
};
ll extGCD(ll a, ll b, ll &x, ll &y) {
    if(b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a/b*x;
    return d;
}

void Main() {
    LCIN(A, B, C);
    if(A*A + B*B < C*C) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

int main() {
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


//IQ134高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF INT_MAX
#define LLINF LLONG_MAX
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007
#define MODB  998244353

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

int main() {
	ll ans = 0;
	ll tmp = 0;
	int n; cin >> n;
	vector<ll> a(n);
    cin >> a;
    map<ll, ll> m;
    m[0]++;
    REP(i, n){
        if(i%2==0)tmp += a[i];
        else tmp -= a[i];
        m[tmp]++;
    }
    for(auto it = m.begin(); it != m.end(); it++){
        ans += (it->second) * (it->second - 1LL) / 2;
    }
	cout << ans << endl;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define Pll pair<long,long>
#define mp make_pair
#define INF 1000000001
#define INFl 1000000000000000001
#define ll long long
using namespace std;

struct edge{long to,cost,k;};

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

int main() {
    int N;cin>>N;
    vector<long>A(N);
    vector<long>B(N);
    rep(i,N)cin>>A[i];
    map<long,int> mp;
    B[0]=A[0];
    rep(i,N-1){
        B[i+1]=A[i+1]-B[i];
    }
    B[0]=0;
    mp[0]=1;
    long cnt=0;
    rep(i,N-1){
        //cout<<B[i+1]<<endl;
        long j=B[i+1];
        if(i%2==0){
            if(mp.count(-j))cnt+=mp[-j];
        }else{
            if(mp.count(j))cnt+=mp[j];
        }

        if(i%2==0){
            long k=A[i+1]-B[i+1];
            if(mp.count(k))mp[k]++;
            else mp.emplace(k,1);
        }else{
            long k=A[i+1]-B[i+1];
            if(mp.count(-k))mp[-k]++;
            else mp.emplace(-k,1);
        }
    }
    cout<<cnt<<endl;
}


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

#define rep(i,n) for(int (i)=0; (i)<(int)(n); (i)++)
#define all(x) (x).begin(), (x).end()
#define sqr(x) (x)*(x)
#define CEIL(a,b) ((a)+(b)-1) /(b)

typedef long long ll;
const int INF = 1001001001;

void sort_second(vector<pair<ll, ll>> &A, int N); //A:array of pair, N:size of array
ll a_n(ll a, ll n); // a^n

int main() {
    int n, k, m, sum = 0;
    cin >> n >> k >> m;
    rep(i, n-1) {
        int a;
        cin >> a;
        sum += a;
    }
    if(n*m - sum < 0) cout << 0 << endl;
    else if(n*m - sum <= k) cout << n*m -sum << endl;
    else cout << -1 << endl;

    return 0;
}

void sort_second(vector<pair<ll, ll>> &A, int N) {
    rep(i, N) swap(A.at(i).first, A.at(i).second);
    sort(all(A));
    rep(i, N) swap(A.at(i).first, A.at(i).second);
}
ll a_n(ll a, ll n) {
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        count *= 2;
    }
    if(count == n) return ret;
    else return ret * a_n(a, n-count) ;
}

#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<set>
//#include<bits/stdc++.h>
#define int long long
constexpr long long mod = 1000000007;
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define mp make_pair
#define all(x) x.begin(),x.end()
#define puts(x) cout << (x) << "\n"
using namespace std;
int input() {
	int r; cin >> r; //scanf("%lld", &r);
	return r;
}
char map[2020][2020];
int px[2020][2020], h, w, gi, gj;
queue<pair<int, pair<int, int>>>q1;
vector<pair<int, int>>v[150]; bool b[150];
signed main() {
	cin >> h >> w;
	for0(i, h + 2)for0(j, w + 2) {
		if (i * j == 0)map[i][j] = '#';
		else if (i > h || j > w)map[i][j] = '#';
		else {
			cin >> map[i][j];
			px[i][j] = mod;
			if (map[i][j] == 'S') {
				q1.push(mp(0, mp(i, j)));
			}
			else if (map[i][j] == 'G') {
				gi = i; gj = j;
			}
			else if (map[i][j] != '.' && map[i][j] != '#')v[map[i][j]].push_back(mp(i, j));
		}
	}
	while (q1.size()) {
		int c = q1.front().first, i = q1.front().second.first, j = q1.front().second.second;
		q1.pop();
		if (px[i][j] < c)continue;
		px[i][j] = c;
		if (c > px[gi][gj] || (i == gi && j == gj)) {
			puts(px[gi][gj]); return 0;
		}
		if (map[i - 1][j] != '#' && px[i - 1][j] == mod) { px[i - 1][j] = c + 100; q1.push(mp(c + 1, mp(i - 1, j))); }
		if (map[i + 1][j] != '#' && px[i + 1][j] == mod) { px[i + 1][j] = c + 100; q1.push(mp(c + 1, mp(i + 1, j))); }
		if (map[i][j - 1] != '#' && px[i][j - 1] == mod) { px[i][j - 1] = c + 100; q1.push(mp(c + 1, mp(i, j - 1))); }
		if (map[i][j + 1] != '#' && px[i][j + 1] == mod) { px[i][j + 1] = c + 100; q1.push(mp(c + 1, mp(i, j + 1))); }
		if ('a' <= map[i][j] && map[i][j] <= 'z' && !b[map[i][j]]) {
			b[map[i][j]] = 1;
			for (pair<int, int>p1 : v[map[i][j]])
				if (px[p1.first][p1.second] == mod) { px[p1.first][p1.second] = c + 100; q1.push(mp(c + 1, mp(p1.first, p1.second))); }
		}
	}
	puts(-1); return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll>   vl;
#define f(i,n)  for(i=0;i<n;i++)
#define f1(i,n)  for(i=1;i<n;i++)
#define fr(i,n) for(i=n-1;i>=0;i--)
#define em emplace_back
#define mp make_pair
#define in insert
#define fi first
#define sc second
#define b begin
#define e end
#define er erase
#define l length
#define c clear
#define si size
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
const double pi=3.141592653;
const ll infi=1000000001;
const ll MOD=1000000007;
const ll mod=998244353;
const string no="NO\n",yes="YES\n";

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

// void dfs(vl v[],ll node,ll hai[]){
//     hai[node]=1;
//     for(auto i:v[node]){
//         if(hai[i]==0){
//             dfs(v,i,hai);
//         }
//     }
// }

// ll con(vl v[],ll hai[],ll sz){
//     ll count=0;
//     for(int i=1;i<sz;i++){
//         if(hai[i]==0){
//             count++;
//             dfs(v,i,hai);
//         }
//     }
    // return count;
// }

// void gcde(int a,int b,int *x,int *y){
//     if(a==0){
//         *x=0;
//         *y=1;
//         return;
//     }
//     int x1,y1;
//     gcde(b%a,a,&x1,&y1);

//     *x=y1-(b/a)*x1;
//     *y=x1;
// }

// ll recur(vl v,ll in,ll m,ll n){
//     if(in==-1)  return 1000000000001;
//     ll d,e,c;
//     d=max(m/v[in],n*v[in]);
//     c=recur(v,in-1,m/v[in],n*v[in]);
//     e=recur(v,in-1,m,n);
//     return min(c,min(e,d));
// }

// ll bexpo(ll a,ll p){
//     ll x=1;
//     while(p){
//     if(p&1){
//         x=(x*a)%mod;
//     }
//     a=(a*a)%mod;
//     p>>=1;
//     }
//     return x;
// }
// int dx[8]{-1,0,0,1,-1,-1,1,1};
// int dy[8]{0,-1,1,0,-1,1,-1,1};

int main() {
    fastio
    int t=1;
    // cin>>t;
    ll n,m,i,l,d,bank,k,j,x,y,ans,q;

    while(t--){ans=x=y=0;
        cin>>n;
        string s;
        cin>>s;
        f(i,n){
            x=y=0;
            for(int j=i;j<n;j++){
                if(s[j]=='A')    x++;
                else if(s[j]=='T') x--;
                else if(s[j]=='C')  y++;
                else y--;
                if(x==0 && y==0)    ans++;
            }
        }

        cout<<ans;
    }

	return 0;
}

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

using namespace std;

#define R (long long)(1e9 + 7)
#define M 998244353
#define INF 1e18L

struct dsu
{
	vector<int> rank, parent, c;
	vector<map<int, int>> f;
	int n;
	dsu(int n, vector<int>& c)
	{
		this -> n = n;
		this -> c = c;
		rank.assign(n, 0);
		parent.resize(n);
		f.resize(n);
		for(int i = 0; i < n; i++)
			parent[i] = i;
		for(int i = 0; i < n; i++)
			f[i][c[i]]++;
	}
	int find_set(int i)
	{
		if(i == parent[i])
			return i;
		return parent[i] = find_set(parent[i]);
	}
	bool is_same_set(int i, int j)
	{
		return (find_set(i) == find_set(j));
	}
	void union_set(int i, int j)
	{
		if(!is_same_set(i, j))
		{
			int u = find_set(i), v = find_set(j);
			if(rank[u] == rank[v])
			{
				rank[u]++;
				parent[v] = u;
				for(auto x : f[v])
				{
					f[u][x.first] += x.second;
				}
			}
			else if(rank[u] > rank[v])
			{
				parent[v] = u;
				for(auto x : f[v])
				{
					f[u][x.first] += x.second;
				}
			}
			else
			{
				parent[u] = v;
				for(auto x : f[u])
				{
					f[v][x.first] += x.second;
				}
			}
		}
	}

};
int main()
{
	int n, q;
	cin >> n >> q;
	vector<int> c(n);
	for(int& x : c)
		cin >> x;
	dsu d(n, c);
	while(q--)
	{
		int type;
		cin >> type;
		if(type == 1)
		{
			int a, b;
			cin >> a >> b;
			a--, b--;
			d.union_set(a, b);
		}
		else
		{
			int x, y;
			cin >> x >> y;
			x--;
			cout << d.f[d.find_set(x)][y] << '\n';

		}
	}
}


#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<limits.h>
#include<utility>
#include<vector>
#include<tuple>
#include <map>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for(ll i=0;i<n;i++)
#define ALL(A) A.begin(),A.end()

int main() {
    string s;
    vector<ll> a(26);
    cin>>s;
    ll ans=0;
    ll n=s.size();
    for(ll i=s.size()-3;i>=0;i--){
        ll c=s[i]-'a';
        ll C=s[i+2]-'a';
        a[C]++;
        if(s[i]==s[i+1]&&s[i]!=s[i+2]){
            ans+=n-2-i-a[c];
            rep(i,26){
                //cout<<a[i]<<"  ";
                a[i]=0;
            }
            //cout<<endl;
            a[c]=n-2-i;
            //cout<<i<<" "<<ans<<endl;
        }
    }
    cout<<ans<<endl;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++)
#define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--)
#define all(v) v.begin(), v.end()
void chmax(ll &x, ll y) {x = max(x,y);}
void chmin(ll &x, ll y) {x = min(x,y);}
void Yes() {cout << "Yes" << endl; exit(0);}
void No() {cout << "No" << endl; exit(0);}
template<class in_Cout> void Cout(in_Cout x) {cout << x << endl; exit(0);}
template<class in_vec_cout>
void vec_cout(vector<in_vec_cout> vec) {
    for (in_vec_cout res : vec) {cout << res << " ";}
    cout << endl;
}

const ll inf = 1e18;
const ll mod = 1e9 + 7;

// segment tree struct
template<class in_seg>
struct segtree {
    in_seg op(in_seg x, in_seg y) {return min(x,y);} // モノイド演算
    in_seg e = inf;       // 元(+→0, *→1, xor→0, max→-inf, min→inf, gcd→0 : e●a==a●e==a)
    ll len = 1LL;     // セグメントの長さ
    ll N;
    vector<in_seg> dat;

    segtree(ll n) {init_seg(n);}
    segtree(vector<in_seg> vec) {init_seg(vec);}

    void init_seg(ll n) {
        N = n;
        while (len<N) {len *= 2;}
        dat.resize(2*len,e);
    }
    void init_seg(vector<in_seg> vec) {
        N = vec.size();
        init_seg(N);
        rep(i,N) dat[i+len] = vec[i];
        for (ll i=len-1; i>=1; i--) dat[i] = op(dat[2*i],dat[2*i+1]);
    }

    // dat[id]に x を代入
    void set(ll id, in_seg x) {
        id += len;
        dat[id] = x;
        while (id>0) {
            id /= 2;
            dat[id] = op(dat[2*id],dat[2*id+1]);
        }
    }

    // dat[id]を返す O(1)
    in_seg get(ll id) {id += len; return dat[id];}

    // op(a[l],...,a[r-1])を計算して返す。l==rの時は e を返す O(logN)
    in_seg prod(ll l, ll r) {
        l += len; r += len;
        in_seg res = e;
        while (l<r) {
            if (l%2) {res = op(res,dat[l]); l++;}
            l /= 2;
            if (r%2) {res = op(res,dat[r-1]); r--;}
            r /= 2;
        }
        return res;
    }

    in_seg all_prod() {return dat[1];}
};

int main() {
    ll N, M; cin >> N >> M;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];

    vector<ll> cnt(N);
    segtree<ll> seg(N+1);
    rep(i,seg.len) seg.set(i,i);
    rep(i,M) {
        ll a = A[i];
        cnt[a]++;
        seg.set(a,inf);
    }

    ll ans = inf;
    for (ll i=M-1; i<N; i++) {
        chmin(ans,seg.all_prod());
        if (i==N-1) break;
        ll l = A[i-M+1], r = A[i+1];
        cnt[l]--;
        cnt[r]++;
        if (cnt[l]==0) seg.set(l,l);
        seg.set(r,inf);
    }

    Cout(ans);
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
const int MOD = 1000000007;
#define fi first
#define se second
#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define repe(i,n) for(int i = 0 ; i <= n ; i++)
#define repb(i,a,b) for(int i = a ; i < b ; i++)
#define repeb(i,a,b) for(int i = a ; i <= b ; i++)
#define rfor(i,n,a) for(ll i = n ; i >= a ; i--)
#define pb push_back
#define endl "\n"
#define vi vector<int>
#define vvi vector<vi>
#define pii pair <ll,ll>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a,b) cout << a << " " << b << endl
#define p3(a,b,c) cout << a << " " << b << " " << c << endl
#define watch(x) cout << (#x) << " is " << (x) << endl
#define w(x) ll x; cin>>x; while(x--)

    template <typename T1, typename T2>
    inline std::ostream& operator << (std::ostream& os, const std::pair<T1, T2>& p)
    {
        return os << "(" << p.first << ", " << p.second << ")";
    }

    template<typename T>
    inline std::ostream &operator << (std::ostream & os,const std::vector<T>& v)
    {
        bool first = true;
        for(unsigned int i = 0; i < v.size(); i++)
        {
            if(!first)
                os << " ";
            os << v[i];
            first = false;
        }
        return os;
    }

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

// read once, read again, think, code

const int MAXM = 2e5+1;
int timestamp = 0;
int in[MAXM];
int out[MAXM];

void dfs(int root, vi *adj, vi *depth, int d) {

	in[root] = timestamp;
	depth[d].pb(in[root]);
	timestamp++;

	for(int &child : adj[root]) {
		dfs(child,adj,depth,d+1);
	}

	out[root] = timestamp;
}

void solve() {

    int n;
    cin >> n;

    vi adj[n+1], depth[n+1];

    repeb(child,2,n) {
    	int parent; cin >> parent;
    	adj[parent].pb(child);
    }

    dfs(1,adj,depth,0);

    int q; cin >> q;

    while(q--) {
    	int u, d; cin >> u >> d;
    	int ans = lower_bound(depth[d].begin(), depth[d].end(), out[u]) - lower_bound(depth[d].begin(), depth[d].end(), in[u]);
    	p1(ans);
    }
}

int main()
{
	fastio;

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

    //w(tc)
    	solve();

	return 0;
}

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

#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define rreps(i, n, s) for (int i = s; i >= n; i--)

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    vector<vector<ll>> node(n);

    rep(i, m) {
        ll x, y;
        cin >> x >> y;
        x--, y--;
        node[x].push_back(y);
    }

    vector<bool> visit(n, false);

    vector<ll> dp(n, INF);
    rep(now, n) {
        if (visit[now]) continue;
        visit[now] = true;

        for (auto next : node[now]) { dp[next] = min(dp[next], min(dp[now], a[now])); }
    }

    ll res = -INF;
    rep(i, n) {
        if (dp[i] == INF) continue;
        res = max(a[i] - dp[i], res);
    }
    cout << res << endl;
    return 0;
}


#include<bits/stdc++.h>
#define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define all(x) (x).begin(), (x).end()
#define Unique(a)       a.erase(unique(all(a)), a.end())
#define ld long double
#define pb push_back
#define fi first
#define se second
#define inf 1e9
using namespace std;
typedef long long int ll;

const int mxn=2e5+5,mod=1e9+7;
int a[mxn],dis[mxn];
vector<int>g[mxn];
bool vis[mxn];

int timer;
vector<int> tin(mxn), tout(mxn);
vector<vector<int>> up;

vector<int>lev[mxn];

void dfs(int v, int p)
{
    tin[v] = ++timer;
    lev[dis[v]].pb(timer);

    for (int u : g[v]) {
        if (u != p){
        	dis[u]=dis[v]+1;
            dfs(u, v);
        }
    }
    tout[v] = ++timer;
}

int ask(int d,int x){
	int res=-1;
	for(int i=17;i>=0;--i){
		int sum=res+(1<<i);
		if(sum>=lev[d].size()) continue;
		if(lev[d][sum]<=x)res=sum;
	}
	return res;
}

int main(void){
	fast;
	int n,i,q,x;
	cin>>n;
	for(i=2;i<=n;i++){

		cin>>x;
		g[x].pb(i);
		g[i].pb(x);

	}
	dis[1]=0;

	dfs(1,0);

	cin>>q;

	while(q--){

		int x,y,l1=0,l2=0;
		cin>>x>>y;
		int l=tin[x];
		int r=tout[x];
		cout<<ask(y,r)-ask(y,l-1)<<'\n';
	}
}

#include <bits/stdc++.h>
using namespace std;
const int N=2e5+2;
int n,q,f[N];
int cnt,hd[N],to[N],nxt[N];
int hd1[N],d[N],nxt1[N],ans[N];
void adde(int x,int y)
{
	nxt[++cnt]=hd[x];
	to[hd[x]=cnt]=y;
}
void dfs(int x,int dep)
{
	for(int i=hd1[x];i;i=nxt1[i])
		ans[i]=-f[d[i]];
	++f[dep];
	for(int i=hd[x];i;i=nxt[i])
		dfs(to[i],dep+1);
	for(int i=hd1[x];i;i=nxt1[i])
		ans[i]+=f[d[i]];
}
int main()
{
	scanf("%d",&n);
	for(int i=2,x;i<=n;++i)
	{
		scanf("%d",&x);
		adde(x,i);
	}
	scanf("%d",&q);
	for(int i=1,x,y;i<=q;++i)
	{
		scanf("%d%d",&x,&y);
		nxt1[i]=hd1[x];
		d[hd1[x]=i]=y;
	}
	dfs(1,0);
	for(int i=1;i<=q;++i)
		printf("%d\n",ans[i]);
}


#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  long long k;
  cin >> n >> k;
  long long dp[4][3000005]={0};
  dp[0][0]=1;
  for(int i=0;i<3;i++){
    for(int j=0;j<=i*n;j++){
      dp[i+1][j+1]+=dp[i][j];
      dp[i+1][j+n+1]-=dp[i][j];
    }
    for(int j=1;j<=(i+1)*n;j++){
      dp[i+1][j]+=dp[i+1][j-1];
    }
  }

  int x;
  for(int i=3;i<=3*n;i++){
    if(k<=dp[3][i]){x=i;break;}
    else{k-=dp[3][i];}
  }
  for(int i=1;i<=n;i++){
    int jmi=max(1,x-i-n);
    int jma=min(n,x-i-1);
    if(jmi>jma){continue;}
    if(k>(jma-jmi+1)){k-=(jma-jmi+1);continue;}
    int y=jmi+k-1;
    int z=x-i-y;
    cout << i << ' ' << y << ' ' << z << '\n';
    return 0;
  }
}

#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c> {i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
    ~debug() { cerr << endl; }
    eni( != ) cerr << boolalpha << i; ris;
}
eni( == ) ris << range(begin(i), end(i));
}
sim, class b dor(pair < b, c > d) {
    ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
        *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
}
#else
    sim dor(const c&) { ris; }
#endif
};
#define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
#define int long long
int32_t main() {
 ios::sync_with_stdio(false);
 cin.tie(0);
 int l, r;
 cin >> l >> r;
 vector<int> dp(r + 1);
 int ans = 0;
 for(int i = r; i >= 2; i--){
     int mults = (r / i) - (l - 1) / i;
     mults = (mults * (mults - 1)) / 2;
     //debug() << imie(mults);
     for(int j = i + i; j <= r; j += i){
         mults -= dp[j];
     }
     dp[i] = mults;
     //debug() << imie(dp[i]) imie(i);
 }
 for(int i = 2; i <= r; i++){
     ans += dp[i];
 }
 debug() << imie(ans);
 for(int i = max(2LL, l); i <= r; i++){
     ans -= ((r / i) - 1);
 }
 cout << ans * 2 << endl;

}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	#ifndef ONLINE_JUDGE
		freopen("tpl.txt","r",stdin);
	#endif

	vector<int> vc;
	int n,m;
	cin >> n >>m;
	for(int i = 0 ; i < n; i ++){
		int t; cin >> t;
		if(t != m)
			vc.push_back(t);
	}
	for(int i = 0 ; i < vc.size() ; i++)
		cout << vc[i] << " ";
	return 0;
}

 //----AUTHOR:kkdrummer----/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace __gnu_pbds;
using namespace std;
typedef    long long                	 ll;
typedef    long double              	 ld;
typedef    unordered_set<ll>         	 usll;
typedef    unordered_multiset<ll>    	 umsll;
typedef    multiset<ll>              	 msll;
typedef    set<ll>                  	 sll;
typedef    vector<ll>               	 vll;
typedef    pair<ll,ll>              	 pll;
typedef    vector<pll>              	 vpll;
typedef    priority_queue<ll>       	 pqll;
typedef    vector<int>              	 vi;
typedef    set<int>                 	 si;
typedef    multiset<int>            	 msi;
typedef    unordered_multiset<int>  	 umsi;
typedef    unordered_set<int>       	 usi;
typedef    pair<int,int>               	 pi;
typedef    vector<pi>                	 vpi;
typedef    priority_queue<int>       	 pqi;
typedef    tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>   ind_si;
typedef    tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>   ind_sll;
typedef    tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>   ind_msi;
typedef    tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>   ind_msll;
#define    in          		insert
#define    fi          		first
#define    se          		second
#define    pb   	    	push_back
#define    mp   	   		make_pair
#define    be   	   		begin
#define    en   	   		end
#define    itr  	   		iterator
#define    io  	       		ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define    mo   	   		998244353
#define    inf  	   		8222372026854775807
#define    ninf   	   		-inf
#define    ima   	   		2047483647
#define    imi   	   		-ima
#define    oncnt       		__builtin_popcount
#define    zerobegin   		__builtin_clz
#define    zeroend    		__builtin_ctz
#define    parity      		__builtin_parity
#define    eps         		1e-9
#define    coutd       		cout<<setprecision(10)<<fixed
#define    mems(dp,x)  		memset(dp,x,sizeof(dp))
#define    fbo         		find_by_order
#define    ook    	   		order_of_key
#define    all(x)      		x.be(),x.en()
#define    upb    	   		upper_bound
#define    lowb  	   		lower_bound
#define    lte(v,x)    		(upb(all(v),x)-v.be())
#define    gte(v,x)    		(v.end()-lowb(all(v),x))
#define    gt(v,x)     		(v.en()-upb(all(v),x))
#define    lt(v,x)     		(lowb(all(v),x)-v.be())
const      ld PI= 			3.1415926535897932384626433832792884197169399375105820974944;
inline ll mpow(ll x,ll n){if(n==0)return 1;if(x==0)return 0;if(n==1)return(x%mo);ll u=(mpow(x,n/2));u=(u*u)%mo;if(n%2!=0)u=(u*x%mo)%mo;return u;}
inline ll minv(ll x){return mpow(x,mo-2);}
inline ll mmul(ll a,ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll madd(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a+b>=mo)return(a+b)%mo;return(a+b);}
inline ll msub(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;return(((a-b)%mo+mo)%mo);}
inline ll mdiv(ll a,ll bb){if(a>=mo)a=a%mo;ll b=minv(bb);if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll gcd(ll a,ll b){return __gcd(a,b);}
inline ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}

ll inta(vll v)
{
	ll c=0;
	for(auto x:v)c=c*10+x;
	return c;
}

ll g1(ll n)
{
	vll v;
	while(n)
	{
		v.pb(n%10);
		n/=10;
	}
	sort(all(v));
	reverse(all(v));
	return inta(v);
}

ll g2(ll n)
{
	vll v;
	while(n)
	{
		v.pb(n%10);
		n/=10;
	}
	sort(all(v));
	//reverse(all(v));
	return inta(v);
}

ll f(ll n)
{
	return g1(n)-g2(n);
}

int main()
{              io
int testcases=1;           //        cin>>testcases;
while(testcases--)
{

ll n,k;
cin>>n>>k;

for(int i=0;i<k;i++)
	n=f(n);

cout<<n;

}return 0;}


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

int main(){
    int n;
    long long X;
    scanf("%d %lld", &n, &X);

    vector <int> a(n);
    for(int i = 0; i < n; i++)scanf("%d", &a[i]);

    long long res = X;
    for(int k = 1; k <= n; k++){
        vector < vector <long long> > dp(k + 1, vector <long long> (k, -1));
        dp[0][0] = 0;

        for(int i = 0; i < n; i++){
            for(int j = k; j >= 1; j--)
            for(int r = 0; r < k; r++){
                long long c = dp[j - 1][(r - (a[i] % k) + k) % k];
                if(c != -1 && (dp[j][r] == -1 || dp[j][r] < c + a[i]))
                    dp[j][r] = c + a[i];
            }
        }

        if(dp[k][X % k] != -1)res = min(res, (X - dp[k][X % k]) / k);
    }
    printf("%lld\n", res);

    return 0;
}

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

#define ll long long
const int N = 5005;
int mod = 998244353;

int n , m;
ll pw[N];
ll a[N][N];

int main()
{
    // freopen(".inp","r",stdin);
    // freopen(".out","w",stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> m;

    pw[0] = 1;
    for (int i = 1 ; i < N ; ++i) pw[i] = pw[i - 1] * (ll) m % mod;

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

    for (int i = 0 ; i < N ; ++i)
    {
        for (int j = 1 ; j < N ; ++j)
        {
            a[i][j] = (a[i][j] + a[i][j - 1]) % mod;
        }
    }

    ll ans = pw[n] * n;

    for (int i = 1 ; i <= n ; ++i)
    {
        for (int j = i + 1 ; j <= n ; ++j)
        {
            ans = (ans - a[j - i - 1][m - 1] * pw[n - (j - i + 1)] + (ll) mod * (ll) mod) % mod;
        }
    }

    cout << ans;

}


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

int n, q;
const int N = 2e5+10;
int p[N], s[N], c[N];
map<int, int>res[N];

int f(int x) {
    return (p[x] == x ? x : p[x] = f(p[x]));
}
void merge(int u, int v) {
    u = f(u), v = f(v);
    if(u == v)
        return;
    if(s[u] < s[v])
        swap(u, v);
    p[v] = u, s[u] += s[v];
    for(auto i:res[v])
        res[u][i.first]+=i.second;
    res[v].clear();
}

void solve(){
    cin >> n >> q;
    for(int i=1;i<=n;++i) {
        cin >> c[i]; p[i] = i, s[i] = 1, res[i][c[i]] = 1;
    }
    while(q--) {
        int t, x, y;
        cin >> t >> x >> y;
        if(t == 1) {
            merge(x, y);
        } else {
            cout << res[f(x)][y] << "\n";
        }
    }
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t =1;
    while(t--)
        solve();
    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
#define MP make_pair
const unsigned long long mod = 1e9 + 7;
const long long INF = 1LL<<60;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }

// UnionFind  ex.)UnionFind uf(N);  という風に定義する
// coding: https://youtu.be/TdR816rqc3s?t=726
// comment: https://youtu.be/TdR816rqc3s?t=6822
struct UnionFind {
  vector<int> d;
  vector<map<int, int>> mp;
  UnionFind(int n = 0) : d(n, -1), mp(n) {} //コンストラクタ(n:頂点数)
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
	for (auto itr = mp[y].begin(); itr != mp[y].end(); ++itr){
		int cnt = itr->second;
		while(cnt--){
			mp[x][itr->first]++;
		}
	}
		return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
  void cnt(int x, int y){
	  cout << mp[find(x)][y] << endl;
  }
  void check(int c){
	  cout << c << ":";
	  for (auto itr = mp[c].begin(); itr != mp[c].end(); ++itr){
		  cout << "(" << itr->first << "->" << itr->second << "), ";
	  }
	  cout << endl;
  }
};

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int N, Q;
	cin >> N >> Q;
	UnionFind uf(N);
	FOR(i,0,N){
		int c;
		cin >> c;
		--c;
		uf.mp[i][c]++;
	}
	while(Q--){
		int t, a, b;
		cin >> t >> a >> b;
		--a;
		--b;
		if(t==1){
			uf.unite(a, b);
			//uf.check(uf.find(a));
		}else{
			uf.cnt(a, b);
		}
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fo(a,b) for(int64_t a=0;a<b;a++)
#define sor(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define ll int64_t
#define mod 1000000007
#define vl vector<int64_t>
#define vc vector<char>
#define vs vector<string>
#define np(vec) next_permutation(vec.begin(),vec.end())==true
#define en endl
#define vvl vector<vector<int64_t>>
#define stl stack<int64_t>
#define qul que<int64_t>
#define ms(a,b) memset(a,b,sizeof(a))
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pq priority_queue
#define pql priority_queue<int64_t>
#define pu push
#define pop pop()
#define top top()
#define pqr priority_queue<ll,vector<ll>,greater<ll>>
#define co cout
#define ci cin
#define wh while
#define size size()
#define front front()

int main() {
 ll n;
  cin>>n;
  vl v(n);
  vl v1(n);
  ll a;
  fo(i,n){
    cin>>v.at(i);
  }
  v1.at(0)=v.at(0);
  fo(i,n-1){
    v1.at(i+1)=v1.at(i)+v.at(i+1);
  }
  vector<vector<ll>> vec(n, vector<ll>(n));
 for (ll i = 0; i < n; i++) {
    for (ll j = 0; j < n; j++) {
      vec.at(i).at(j)=(v1.at(j))%(i+1);
    }
  }
   vector<vector<ll>> ans(n, vector<ll>(n));
  fo(i,n){
    ans.at(0).at(i)=1;
  }
  fo(i,n-1){
    vl kari(i+2);
    fo(j,n){
      ans.at(i+1).at(j)=kari.at(vec.at(i+1).at(j));
      kari.at(vec.at(i+1).at(j))=(kari.at(vec.at(i+1).at(j))+ans.at(i).at(j))%mod;
    }
  }
  ll f=0;
  fo(i,n){
  f=(f+ans.at(i).at(n-1))%mod;

  }
 cout<<f<<en;
}

#include<bits/stdc++.h>
#define ll long long int
#define mk make_pair
#define pb push_back
#define INF (ll)6e18
#define pii pair<ll,ll>
#define mod 1000000007 // 998244353
#define ff first
#define ss second
#define srt(v)  if(!v.empty())sort(v.begin(),v.end())
#define rev(v)  if(!v.empty())reverse(v.begin(),v.end())
#define PI 3.141592653589793238
#define pqr priority_queue<ll,vector<ll>,greater<ll>()>
using namespace std;
ll pow_mod(ll a,ll b)
{
	ll res=1;
	while(b!=0)
	{
		if(b&1)
		{
			res=(res*a)%mod;
		}
		a=(a*a)%mod;
		b/=2;
	}
	return res;
}

ll inv_mod(ll x){
    return pow_mod(x,mod-2);
}

const ll N=(ll)3e5;
ll inv[N];
ll fac[N];

void init(){
  fac[0]=1;

  for(ll i=1;i<N;i++)
  fac[i]=(i*fac[i-1])%mod;

  for(ll i=0;i<N;i++)
  inv[i]=inv_mod(fac[i]);
}

ll ncr(ll n,ll r){
    if(n<r)
    return 0;

    if(n==r||r==0)
    return 1LL;

    ll x=fac[n];
    ll y=inv[n-r];
    ll z=inv[r];

    return ((x*y)%mod*z)%mod;
}
bool test_cases=0;
void solve()
{
  ll n;
  cin>>n;

  ll a[n+1];
  for(ll i=1;i<=n;i++)
  cin>>a[i];

  ll dp[n+1][n+1];

  memset(dp,0,sizeof(dp));

  ll ans=0;

  ll p[n+1]={0};

  for(ll i=1;i<=n;i++)
  p[i]=p[i-1]+a[i];

  for(ll k=1;k<=n;k++){
     ll rem[n+1]={0};

     for(ll i=0;i<=n;i++)
     rem[i]=p[i]%k;

     ll sum[k]={0};

      if(k==1)
      sum[0]=1;

      for(ll i=1;i<=n;i++){
         ll x=rem[i];

         dp[i][k]+=sum[x];

         dp[i][k]%=mod;

         sum[x]+=dp[i][k-1];

         sum[x]%=mod;

         //cout<<"i "<<i<<" "<<"k "<<k<<" "<<dp[i][k]<<endl;

      }

      ans+=dp[n][k];

      ans%=mod;
  }

  cout<<ans<<endl;

}
int main()
{
     mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);

   // init();   //factorial calculations

   //Start from Here.

  ll t;
  t=1;

  if(test_cases)
  cin>>t;

  while(t--)
  solve();
//Good Bye!
    return 0;
}


#include <iostream>
using namespace std;

int main() {
    int X,Y,Z,sunuke;

    cin >> X >> Y >> Z;
    sunuke = (Y * Z - 1)/ X;

    cout << sunuke << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;
ll MOD=1000000007;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  cout<<21-a-b-c;
return 0;
}


#include<bits/stdc++.h>
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int&
#define I inline
#define W while
#define N 500000
#define LL long long
using namespace std;
int n,nxt1[N+5],nxt2[N+5];char s1[N+5],s2[N+5];
int main()
{
	RI i,j;LL t=0;scanf("%d%s%s",&n,s1+1,s2+1);
	for(j=0,i=1;i<=n;++i) s1[i]&1&&(nxt1[j]=i,j=i);nxt1[j]=n+1;
	for(j=0,i=1;i<=n;++i) s2[i]&1&&(nxt2[j]=i,j=i);nxt2[j]=n+1;
	#define NA() return puts("-1"),0;
	i=0,j=0;W(i<=n) if(i>=j) t+=i-j,i=nxt1[i],j=nxt2[j];
		else if(nxt1[i]<=n) t+=nxt1[i]-i,i=nxt1[nxt1[i]];else NA();
	return j>n?printf("%lld\n",t):puts("-1"),0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<pll,pll> ppp;
typedef vector<ll> vll;
typedef vector<pll> vp;
typedef priority_queue<pll,vp,greater<pll> > pqpll;
typedef priority_queue<ll, vll, greater<ll> > pqll;

#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n-1; i >= a;i--)
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second
#define EPS 1e-10
#define ALL(a) (a.begin(), a.end())

template<typename T>
ll sz(vector<T> &vec){ return (ll)vec.size(); }
template<typename T>
ll sz(priority_queue<T, vector<T> > &pq) {return (ll)pq.size(); }
template<typename T>
ll sz(priority_queue<T, vector<T>, greater<T> > &pq) {return (ll)pq.size(); }
ll sz(string &s) {return (ll)s.size(); }
ll gcd(ll a,ll b){ return ((!b) ?a :gcd(b, a%b)); }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b; }
bool checkindex(ll i,ll n){ return (i < n && i >= 0); }
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

int main(){
    ll n;
    cin >> n;
    string s,t;
    cin >> s >> t;

    vll sum(n+1,0),sum2(n+1,0);
    ll lsb = 0;

    rep(i,0,n){
        if(s[i] == '1') sum[i+1] = 1;
        else sum[i+1] = 0;

        if(t[i] == '1') {
            sum2[i+1] = 1;
            if(lsb == 0) lsb = i+1;
        }
        else sum2[i+1] = 0;

        if(i != 0){
            sum[i+1] += sum[i];
            sum2[i+1] += sum2[i];
        }
    }

    if(sum[n] - sum[max(lsb-1,0ll)] < sum2[n]){
        cout << -1 << endl;
        return 0;
    }
    if((sum[max(lsb-1,0ll)] + (sum[n] - sum[max(lsb-1,0ll)] - sum2[n])) % 2 == 1){
        cout << -1 << endl;
        return 0;
    }

    stack<ll> sta1,sta2;
    ll ans = 0;

    rep(i,0,n){
        if(t[i] == '1'){
            sta2.push(i);
        }

        if(s[i] == '1'){
            if(sta1.size() > 0){
                ans += i - sta1.top();
                sta1.pop();
            }
            else if(i+1 < lsb){
                sta1.push(i);
            }
            else if(sta2.size() > 0){
                ans += i - sta2.top();
                sta2.pop();
            }
            else{
                sta1.push(i);
            }
        }
    }

    if(sta1.size() + sta2.size() == 0) cout << ans << endl;
    else cout << -1 << endl;
}


#include <bits/stdc++.h>
#define mod 1000000007
#define MOD 1000000007
#define ll long long int
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define MAXN 100009
#define pi 3.1415926535897932384626

using namespace std;

ll power(ll x, ll y) { ll ans = 1; x %= MOD; while (y) {if (y & 1)ans = (x * ans) % MOD; x = (x * x) % MOD; y >>= 1;} return ans;}
ll modInv(ll n) { return power(n, MOD - 2);}

void solve()
{
    ll n, k, i, ans=0;
    cin>>n>>k;
    ll a[n+9], b[n+9];
    vector<pair<ll, ll>> v;
    for(i=0; i<n; i++)
    {
        cin>>a[i]>>b[i];
        v.push_back({a[i], b[i]});
    }

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

    for(i=0; i<n; i++)
    {
        if(k>=v[i].first)
        {
            k+=v[i].second;
        }
        else
        {
            break;
        }
    }
    cout<<k;
}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    fastio
    ll t=1;
    // cin>>t;

    while(t--)
    {
        solve();
    }
}

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <queue>

#define int long long

using namespace std;

const int N = 1e6 + 10, M = 2e6 + 10, inf = 0x3f3f3f3f;

const long long Linf = 0x3f3f3f3f3f3f3f3f;

inline int read() {
	bool sym = 0; int res = 0; char ch = getchar();
	while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar();
	while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();
	return sym ? -res : res;
}

int n, m, cnt, now, vis[N], dat[N], l[N], r[N], t[N];

signed main() {
	n = read(); int k = read();
	for (int i = 1; i <= n; i++) {
		l[i] = read(); r[i] = read(); t[i] = read();
	}
	for (int i = 1; i <= n; i++) {
		vis[l[i]] += t[i]; vis[r[i]] -= t[i]; m = max(m, r[i]);
	}
	for (int i = 0; i <= m; i++) {
		now += vis[i]; if (now > k) {printf("No"); return 0;}
	}
	printf("Yes");
	return 0;
}


#include<bits/stdc++.h>
#define int long long
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define endl "\n"
using namespace std;

const int max_n = 5e3+10;
const int inf = 1e18;
const int Mod = 998244353;

int n,m;
int dp[22][max_n];
int fact[max_n];
int NCR[max_n][max_n];

int f(int j,int M){
    if(j==-1 && M==0){
        return 1;
    }
    if(j==-1) return 0;
    if(dp[j][M]!=-1) return dp[j][M];

    int ans=0;
    for(int k=0;k<=n;k+=2){
        if((k*(1LL<<j))>M) break;

        int c = (NCR[n][k]*f(j-1,M-(k*(1LL<<j))))%Mod;
        ans = (ans+c)%Mod;
    }

    dp[j][M]=ans;
    return ans;
}

void fill(){
    for(int n=0;n<max_n;n++){
        for(int r=0;r<max_n;r++){
            if(r>n){
                NCR[n][r]=0;
            }else if(r==0){
                NCR[n][r]=1;
            }else if(n==0){
                NCR[n][r]=0;
            }else{
                NCR[n][r]=(NCR[n-1][r-1]+NCR[n-1][r])%Mod;
            }
        }
    }
}

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

    memset(dp,-1,sizeof(dp));

    cin>>n>>m;

    cout<<f(15,m)<<endl;

}

#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <tuple>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <functional>
#include <numeric>
#include <iomanip>
#include <stdio.h>
//end of libraries
#define lnf 3999999999999999999
#define inf 999999999
#define PI 3.14159265359
#define endl "\n"
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(c) (c).begin(),(c).end()
#define sz(c) (int)(c).size()
#define mkp(a,b) make_pair(a,b)
#define make_unique(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define rsz(a,n) a.resize(n)
#define pii pair <int,int>
#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define drep(i,n) for(int i = n-1 ; i >= 0 ; i--)
#define crep(i,x,n) for(int i = x ; i < n ; i++)
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);

const int max_n = 5500;

using namespace std;
ll mod = 998244353 , fact[max_n];
ll binpow(ll a, ll b) {
  a %= mod; ll res = 1;
  while (b) { if (b%2) res = res * a % mod; a = a * a % mod; b /= 2; }
  return res % mod;
}
void dofact() {
  fact[0]=fact[1]=1;
  rep(i,max_n-3){
    if(i>1)fact[i] = fact[i-1]*i; fact[i] %= mod;
  }
}

ll cnk(ll k , ll n){
  if(k>n) return 0;
  return (fact[n] * binpow(fact[k]*fact[n-k]%mod,mod-2)) % mod;
}
ll sub(ll a , ll b){
  a%=mod; b%=mod;
  return (((a-b)%mod)+mod)%mod;
}
ll prod(ll a , ll b){
  a%=mod; b%=mod;
  return ((a*b)%mod);
}

ll add(ll a , ll b){
  a%=mod; b%=mod;
  return (a+b)%mod;
}

ll dp[max_n] , nedp[max_n];

vector <ll> a;

int n,m;

void read() {
	cin >> n >> m;
	int x = 1;
	while(x<=m) {
		a.pb(x);
		x*=2;
	}
}

int main(){
fcin;
dofact();

	read();

	dp[0] = 1;

	rep(idx,sz(a)){
		int i = a[idx];
		rep(j,m+1) nedp[j]=dp[j];
		for(int j = 0 ; j <= m ; j++) {
			if(dp[j]==0) continue;
			int x = 2;
			while(j+x*i <= m) {
				int nxt = j+x*i;
				nedp[nxt] = add(nedp[nxt],prod(dp[j],cnk(x,n)));
				x+=2;
			}
		}
		rep(j,m+1) dp[j] = nedp[j];
		// rep(j,m+1) {
		// 	cout << dp[j] << " ";
		// }cout << "\n";
	}

	cout << dp[m] << "\n";
/*
*/

    return 0;
}


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

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

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

    int res = 2000000000;
    for (int i = 0; i < (1 << (n - 1)); i++)
    {
        int xored = 0;
        int ored = 0;
        for (int j = 0; j <= n; j++)
        {

            if (j < n)
                ored |= a[j];
            if (j == n || (i >> j & 1))
                xored ^= ored, ored = 0;
        }
        res = min(res, xored);
    }

    cout << res;
    return 0;
}

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <queue>
#include <numeric>
using namespace std;

using ll = long long;

#define For(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFor(i,a,b) for(ll i=(a);i>=(ll)(b);i--)
#define co(a) cout<<a<<endl
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
#define cfs(a) cout<<fixed<<setprecision(a)

int main() {
	ll N;
	cin >> N;
	vector<ll> A(N);
	ll sum = 0;
	For(i, 0, N) {
		cin >> A[i];
	}
	if (N == 1) {
		co(A[0]);
		return 0;
	}
	vector<ll> temps(N);
	ll sep, temp;
	ll Min = 100000000000;
	For(i, 0, 1 << (N - 1)) {
		sep = 0;
		temp = 0;
		For(j, 0, (N - 1)) {
			if ((i >> j) & 1) {
				temps[j] = 0;
				For(k, sep, j + 1) {
					temps[j] |= A[k];
				}
				sep = j + 1;
				temp ^= temps[j];
				//co(i << " " << j << " " << temp << " " << temps[j]);
			}
			if (j == N - 2) {
				temps[j + 1] = 0;
				For(k, sep, N) {
					temps[j + 1] |= A[k];
				}
				temp ^= temps[j + 1];
				//co(i << " " << j << " " << temp << " " << temps[j]);
			}
		}
		Min = min(Min, temp);
	}
	co(Min);
}


#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <list>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <fstream>
#include <sstream>
#include <unordered_map>
#include <ctime>
#include <assert.h>
using namespace std;

//#define ATCODER

#ifdef ATCODER
#include <atcoder/all>
#endif

const unsigned long long MOD = (unsigned long long)(1e9 + 7);

#define FROM_0(i, n) for(int i = 0; i < (n); i++)
#define FROM_S(i, s, e) for(int i = (s); i < (e); i++)
#define ITER_BEGIN_END(iter, vec) for(auto iter = vec.begin(); iter != vec.end(); iter++)

string s[200];

int main()
{
    int h, w;
    cin >> h >> w;
    FROM_0(i, h)
        cin >> s[i];
    int count = 0;
    FROM_0(i, h)
    {
        FROM_0(j, w)
        {
            if (s[i][j] == '#')
                continue;
            if (i < h - 1 && s[i + 1][j] == '.')
                count++;
            if (j < w - 1 && s[i][j + 1] == '.')
                count++;
        }
    }
    cout << count << endl;
    return 0;
}

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

#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);//cout.precision(dbl::max_digits10);
#define pb(x) push_back(x)
#define mod 1000000007ll //998244353ll
#define vi vector<int>
#define v(x) vector< x >
#define lld long double
#define pii pair<int, int>
#define ff first
#define ss second
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define repe(i,x,y) for(int i=x; i<=y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}

typedef std::numeric_limits< double > dbl;
using namespace __gnu_pbds;
using namespace std;
lld pi=3.1415926535897932;

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

int solve(){
	int n,k,x;
	cin>>n>>k>>x;
	return max(n+k,max(k+x,x+n));
}

int32_t main(){
	IOS

	int t=1;
	// cin>>t;
	// while(t--)
	// if(!solve())
	// cout<<"NO"<<endl;

	while(t--)
	// solve();
	cout<<solve()<<endl;

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+10;
bool p[maxn];
int prime[maxn],mu[maxn],cnt;
long long sum[maxn];
int main()
{
	int l,r;
	scanf("%d %d",&l,&r);
    mu[1]=1;
	for(int i=2;i<=r;i++){
		if(!p[i]){prime[++cnt]=i,mu[i]=-1;}
		for(int j=1;i*prime[j]<=r&&j<=cnt;j++){
			p[i*prime[j]]=1;
			if(i%prime[j]==0){mu[i*prime[j]]=0;break;}
			mu[i*prime[j]]=-mu[i];
		}
	}
	long long ans=0;
	for(int d=2;d<=r;d++){
		for(int k=1;k<=r/d;k++){
			int L=ceil((double)l/(k*d)),R=r/(k*d);
			ans+=(long long)(R-L+1)*(R-L+1)*mu[k];
		}
	}
    if(l==1)l++;
	for(int i=l;i<=r;i++){
		for(int j=i*2;j<=r;j+=i)ans-=2;
	}
	ans-=r-l+1;
	printf("%lld\n",ans);
	return 0;
}

// #pragma GCC target ("avx,avx2")
// #include <bits/extc++.h>
#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

#define f first
#define s second

using namespace std;
// using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
// typedef tree<int, null_type, less_equal<int>,
// rb_tree_tag, tree_order_statistics_node_update> oset;
//========================================================
const int N = 2e5+5, K = 21, M = 5e4+5, mod = 1e9+7, len = 30, inf = 0x3f3f3f3f;

ll l, r;

ll cnt(ll d)
{
    ll c = r / d - (l - 1) / d;
    return c;
}

void run_case()
{
    cin >> l >> r;
    ll a[r + 1];
    ll ans = 0;
    for(int i=r; i>1; i--)
    {
        a[i] = cnt(i) * (cnt(i) - 1);
        for(int j=i + i; j<=r; j += i)
            a[i] -= a[j];

    }

    for(int i=2; i<=r; i++)
    {
        if(i < l) continue;
        a[i] -= (cnt(i) - 1) * 2;
    }
    for(int i=2; i<=r; i++) ans += a[i];
    cout << ans << endl;
}

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    // freopen("input.txt", "rt", stdin);
    // freopen("output.txt", "wt", stdout);
    int T = 1;
    // cin >> T;
    while(T--)
        run_case();
}

/*
    1000000000
*/


#include<bits/stdc++.h>
#define int long long
#define N 100010
#define re register
using namespace std;
int n,m,p[N],q[N],mi,tmp;
vector<int> a[N],b[N];
char s[N];
template <class T> inline void read(T &x)
{
	x=0;int g=1;char s=getchar();
	for (;s<'0'||s>'9';s=getchar()) if (s=='-') g=-1;
	for (;s>='0'&&s<='9';s=getchar()) x=(x<<1)+(x<<3)+(s^48);
	x*=g;
}
signed main()
{
	re int i,j,x,z,op;
	read(n);
	scanf("%s",s+1);
	if (s[1]==s[n])
	{
		if (n<=3) {printf("-1");return 0;}
		for (i=2;i<n-1;i++)
		if (s[i]!=s[1]&&s[i+1]!=s[1])
		{
			printf("2");
			return 0;
		}
		printf("-1");
	}
	else
		printf("1");
	return 0;
}

#include<bits/stdc++.h>
#define pb push_back
#define eb emplace_back
using namespace std;

//#define DEBUG
#ifdef DEBUG
template<typename ...Args>
int debug(const Args &...args){
	return fprintf(stderr,args...);
}
#else
#define debug(...) void()
#endif

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

int n; char s[100010];
int dp[26];
void chk(int &x,int y){
	if (y<x) x=y;
}
int solve(){
	scanf("%d%s",&n,s+1);
	memset(dp,0x3f,sizeof dp);
	dp[s[n]-'a']=0;
	per(i,1,n){
		int t=1e9;
		rep(j,0,25) if (j+'a'!=s[i]) t=min(t,dp[j]);
		if (t==1e9) continue;
		if (i==1) return t+1;
		chk(dp[s[i-1]-'a'],t+1);
	}
	return -1;
}

int main()
{
	for (int T=1;T--;) printf("%d\n",solve());
	return 0;
}