#include "bits/stdc++.h"
//#include "atcoder/all"
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N;
	cin >> N;
	vector<long long>A(N);
	vector<long long>T(N);
	rep(i, N) {
		cin >> A[i] >> T[i];
	}
	long long y0 = -INF - 1;
	long long y1 = INF + 1;
	rep(i, N) {
		if (T[i] == 2) {
			y0 = max(y0, A[i]);
			y1 = max(y1, A[i]);
		}
		else if (T[i] == 1) {
			y0 += A[i];
			y1 += A[i];
		}
		else {
			y0 = min(y0, A[i]);
			y1 = min(y1, A[i]);
		}
	}

	//cout << y0 << endl;
	//cout << y1 << endl;
	long long l = -INF - 1;
	long long r = INF + 1;
	long long tx = 0;
	long long ty = 0;
	if (y0 != y1) {
		while (true) {
			long long c = (l + r) / 2;
			long long copyc = c;
			rep(i, N) {
				if (T[i] == 2) {
					c = max(c, A[i]);
				}
				else if (T[i] == 1) {
					c += A[i];
				}
				else {
					c = min(c, A[i]);
				}
			}
			//cout << copyc << "_" << c << endl;
			if (c == y0) { l = copyc; }
			else if (c == y1) { r = copyc; }
			else {
				tx = copyc;
				ty = c;
				break;
			}
		}
	}
	//cout << tx << "?" << ty << endl;
	long long cl = tx - (ty - y0);
	long long cr = tx + (y1 - ty);
	long long cy = ty - (tx - cl);
	//cout << cl << "_" << cr << "_"<<endl;
	int Q;
	cin >> Q;
	while (Q--) {
		int  x;
		cin >> x;
		if (y0 == y1) {
			cout << y0 << endl;
		}
		else {
			if ((cl <= x) && (x <= cr)) {
				cout << cy + (x - cl) << endl;
			}
			else if (x <= cl) {
				cout << y0 << endl;
			}
			else {
				cout << y1 << endl;
			}
		}
	}
	return 0;
}

#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;

int n,q;
ll a[200005];
int t[200005];
P p[200005];
ll ans[200005];

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%lld%d",&a[i],&t[i]);
	}
	scanf("%d",&q);
	for(int i=0;i<q;i++){
		ll x;
		scanf("%lld",&x);
		p[i]=P(x,i);
	}
	sort(p,p+q);
	int l=0,r=q;
	ll lv=p[0].first,rv=p[q-1].first;
	ll dif=0;
	for(int i=0;i<n;i++){
		if(t[i]==1){
			dif+=a[i];
			lv+=a[i];
			rv+=a[i];
		}
		if(t[i]==2){
			rv=max(a[i],rv);
			lv=max(a[i],lv);
			while(l<r && p[l].first+dif<a[i]){
				l++;
			}
		}
		if(t[i]==3){
			rv=min(a[i],rv);
			lv=min(a[i],lv);
			while(l<r && p[r-1].first+dif>a[i]){
				r--;
			}
		}
	}
	//printf("%d %d\n",l,r);
	for(int i=0;i<q;i++){
		if(i<l){
			ans[p[i].second]=lv;
		}else if(l<=i && i<r){
			ans[p[i].second]=p[i].first+dif;
		}else if(r<=i){
			ans[p[i].second]=rv;
		}
	}
	for(int i=0;i<q;i++){
		printf("%lld\n",ans[i]);
	}
	return 0;
}


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

long long int BIT[300001],N;

long long int sum(int i){
  long long int s = 0;
  while(i > 0){
    s += BIT[i];
    i -= i & -i;
  }
  return s;
}

void add(int i,long long int x){
  while(i <= N){
    BIT[i] += x;
    i += i & -i;
  }
}

int main(){
  cin >> N;
  long long int ans = 0;
  vector<long long int> A(N);
  for(int i=0;i<N;i++){
    cin >> A[i];
    ans += i-sum(A[i]+1);
    add(A[i]+1,1);
  }
  cout << ans << endl;
  for(int i=0;i<N-1;i++){
    ans -= A[i];
    ans += N-1-A[i];
    cout << ans << endl;
  }
}

//In the Name of Allah Most Gracious, Most Merciful//
/*If you want something you've never had, you have  to do something you never did.*/

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

using namespace std;
using namespace __gnu_pbds;

#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MaxN 201007
#define INF 1e9
#define INFL 1e18
#define PI acos(-1)
#define mp make_pair
//
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

//const int fx[]= {+1,-1,+0,+0};
//const int fy[]= {+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move

int gcd(int a, int b)
{
 return b ? gcd(b, a%b) : a;
}

ll bigmod(ll b,ll p,ll m)
{
    ll res=1LL%m;
    ll x=b%m;
    while(p)
    {
        if( p & 1LL )res=(res*x) % m;
        x=(x*x)%m;
        p >>=1LL;
    }
    return res;
}

struct data
{
    long long l,r,val;

};

ll myfunc(ll x)
{
    ll cnt=0;
    while(x!=0)
    {
        cnt++;
        x=x/10;
    }
    return cnt-1;
}

int main()
{

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

    ll n;
    cin>>n;

    map<ll,ll>cmma;
    for(int i=0;i<=15;i++)
    {
        cmma[i]=i/3;
    }
    ll x=1000;
    ll y=9999;
    ll cnt=0;
    for(int i=0;i<=15;i++)
    {
        if(n<x)
        {
            break;
        }
        ll val=(y-x+1);
        //cout<<x<<" "<<myfunc(x)<<endl;
        if(n>=y)
        {
            cnt+=(val)*cmma[myfunc(x)];
        }
        else
        {
            cnt+=(n-x+1)*cmma[myfunc(x)];
            break;
        }
        x=x*10;
        y=y*10+9;
    }
    cout<<cnt<<endl;

//#ifdef LOCAL_DEFINE
  //  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
// #endif
///Before submit=>
///    *check for integer overflow,array bounds
///    *check for n=1
}


// C - Bowls and Dishes
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
template<class T> inline bool chmax(T& a, T& b) { if (a < b) { int tmp=a; a=b; b=tmp; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T& b) { if (a > b) { int tmp=a; a=b; b=tmp; return 1; } return 0; }
const ll mod=1000000000+7;

int main(){
    int n,m;
    cin>>n>>m;
    vector<int>a(m),b(m);
    rep(i,m){
        cin>>a[i]>>b[i];
    }
    int k;
    cin>>k;
    vector<int>c(k),d(k);
    rep(i,k){
        cin>>c[i]>>d[i];
    }

    int ans=0;
    for(int bit=0;bit<(1<<k);bit++){ // 0:put d, 1:put c
        vector<int>dishes(n);
        int cnt=0;
        for(int i=0;i<k;i++){ // k people
            if(bit&(1<<i)){
                dishes[c[i]-1]++;
            }else{
                dishes[d[i]-1]++;
            }
        }

        for(int i=0;i<m;i++){
            if(dishes[a[i]-1]>=1&&dishes[b[i]-1]>=1){
                cnt++;
            }
        }
        ans=max(ans,cnt);
    }
    cout<<ans<<endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(all(x)),x.end())
typedef long long ll;
typedef pair<int,int> P;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll fpow(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

unordered_map<int,int> M;
int n,m,k;
int ans = 0,res = 0;
void dfs(int s, vector<P> &a,vector<P> &b){
    if(s > k) {
        for(int i = 1;i<=m;i++){
            int fi = a[i].first;
            int se = a[i].second;
            if(M[fi] > 0 && M[se] > 0) {
                ans++;
            }
        }
        res = max(ans,res);
        ans = 0;
        //cout << M[1] << " " << M[2] << " " << M[3] << " " << M[4] << endl;
        return ;
    }

    M[b[s].first]++;
    dfs(s + 1,a,b);
    M[b[s].first]--;
    M[b[s].second]++;
    dfs(s + 1,a,b);
    M[b[s].second]--;

}
int main(){
    ios::sync_with_stdio(false);
    cout.tie(nullptr);
    cin >> n >> m;
    vector<P> a(m+1);
    for(int i = 1;i<=m;i++){
        cin >> a[i].first >> a[i].second;
    }
    cin >> k;
    vector<P> b(k+1);
    for(int i = 1;i<=k;i++){
        cin >> b[i].first >> b[i].second;
    }
    dfs(1,a,b);
    cout << res << endl;
    return 0;
}


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

int main(){
  ll a, b, k;
  cin >> a >> b >> k;
  vector<vector<ll>> comb(MAX,vector<ll>(MAX));
  rep(i,MAX) comb[i][0] = 1;
  for(int i = 1; i < MAX; i++) {
    for(int j = 1; j <= i; j++) comb[i][j] = comb[i-1][j-1] + comb[i-1][j];
  }
  string ans;
  int len = a + b;
  rep(x,len) {
    if(b == 0) {
      ans += 'a';
      a--;
      continue;
    }
    if(a == 0) {
      ans += 'b';
      b--;
      continue;
    }
    ll na = comb[a+b-1][b];
    if(k > na) {
      ans += 'b';
      b--;
      k -= na;
    } else {
      ans += 'a';
      a--;
    }
  }
  cout << ans << endl;
  return 0;
}

#include<bits/stdc++.h>

using namespace std;

#define gc c=getchar()
#define r(x) read(x)
#define ll long long
#define db double

template<typename T>
inline void read(T&x){
    x=0;T k=1;char gc;
    while(!isdigit(c)){if(c=='-')k=-1;gc;}
    while(isdigit(c)){x=x*10+c-'0';gc;}x*=k;
}

const int p=998244353;
const int N=3001;

inline void add(int &a,const int &b){
     if((a+=b)>=p)a-=p;
}

int f[N][N];

int main(){
    // freopen(".in","r",stdin);
    // freopen(".out","w",stdout);
    int n,k;r(n),r(k);
    f[0][0]=1;
    for(int i=1;i<=n;++i){
        for(int j=i;j;--j){
            f[i][j]=f[i-1][j-1];
            if(j*2<=i)add(f[i][j],f[i][j<<1]);
        }
    }
    printf("%d\n",f[n][k]);
}


//To debug :  g++ -g file.cpp -o code
//to flush output : fflush(stdout) or cout.flush()
//cout<<setprecision(p)<<fixed<<var
//use 1LL<<i to for 64 bit shifting , (ll)2 because by default 2 is ll
//take care of precedence rule of operators
//do not forget to change the sizes of arrays and value of contants and other things after debugging

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,n) for(i=a;i<n;++i)
#define irep(i,n,a) for(i=n;i>a;--i)
#define mod 1000000007
#define pb push_back
#define big 9223372036854775807
#define big1 LONG_MAX
#define big2 ll_MAX
#define big3 1000000000
#define sma1 LONG_MIN
#define sma2 ll_MIN
#define sma3 -1000000000
#define mp make_pair
#define dub double
#define ivec vector<ll>
#define lvec vector<long long>
#define cvec vector<char>
#define svec vector<string>
#define mt make_tuple
#define MOD 998244353
#define ld long double
#define pi acos(-1.0)

#define SZ(x)  (ll)(x.size())

//comment the below if not required

/*

#define ss second.second
#define ff first.first
#define f first
#define s second
#define sf second.first
#define fs first.second
*/

#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

//cout<<"Case #"<<c<<": "<<ans<<"\n" ;

ll n,c,t,i,sum,j,val,ans;

int main()
{
	IOS;

	cin>>n;

	t = n;

	while(t!=0)
	{
		++c;
		t=t/10;
	}

	for(i=1;i<=c;++i)
	{
		val = 9;

		for(j=1;j<i;++j)
			val = 10*val;

		if(i<c)
		{
			sum += val;

			ans += ((i-1)/3)*val;
		}
		else
		{
			ans += ((i-1)/3)*(n-sum);
		}
	}

	cout<<ans<<"\n";

	return 0;
}


#pragma GCC optimize ("O3")
#pragma GCC target("avx512f")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++)
#define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yes(ans) if(ans)printf("yes\n");else printf("no\n")
#define Yes(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YES(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector1d(type,name,...) vector<type>name(__VA_ARGS__)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
const int MOD2=998244353;
const int INF=1<<30;
const ll INF2=(ll)1<<60;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll modinv(ll a, ll m) {ll b = m, u = 1, v = 0;while (b) {ll t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}
template<class T> void chmax(T &a,const T b){if(b>a)a=b;}
template<class T> void chmin(T &a,const T b){if(b<a)a=b;}

int main(){
    INT(n);
    vector<int> a(n);
    in(a);
    ll ans=0;
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            ans+=abs(a[i]-a[j]);
        }
    }
    out(ans);
}

#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
ll a[200010],sum[200010];
int main(){
    ll i,n; cin >> n;
    for(i=0;i<n;i++) cin >> a[i];
    sort(a,a + n);
    sum[0] = 0;
    for(i=1;i<=n;i++) sum[i] = sum[i - 1] + a[i - 1];
    ll ans = 0;
    for(i=0;i<n;i++){
        ans -= (n - 1 - 2*i)*a[i];
    }
    cout << ans << endl;
}


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

 int main ()
 {
     int t, n, i, j, x, y ;
     char c ;
     string s, s1, s2 ;
     cin>>x>>y>>n ;
     if( ((x*x) + (y*y)) < (n*n) ) cout<<"Yes" ;
     else cout<<"No" ;
     return 0 ;
 }

#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<list>
#include<bitset>
#include<sstream>
#include<regex>
#include<utility>
#include<queue>
#include<map>
using namespace std;

int main() {

	int N;
	cin >> N;

	long long ans = 0;
	vector<long long> A(N, 0);
	vector<long long> B(N, 0);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> B[i];
	}
	for (int i = 0; i < N; i++) {
		ans += A[i] * B[i];
	}

	if (ans == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}


//GIVE ME AC!!!!!!!!!!!!!!!!!
//#pragma GCC target("avx")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define floatset() fixed<<setprecision(15)
#define all(n) n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
#define rep(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define pb push_back
#define eb emplace_back
#define INT(...) int __VA_ARGS__;scan(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;scan(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;scan(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;scan(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;scan(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;scan(__VA_ARGS__)
using namespace std;
using vl=vector<ll>;
using vi=vector<int>;
using vs=vector<string>;
using vc=vector<char>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using vvc=vector<vc>;
using vd=vector<double>;
using vp=vector<P>;
using vb=vector<bool>;
using P=pair<ll,ll>;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const ll inf =1e18;
const ll MOD=1000000007;
const ll mod=998244353;
const double pi=acos(-1);
template<typename T1,typename T2 >
ostream &operator<<(ostream&os,const pair<T1,T2>&p) {
  os<<p.first<<" "<<p.second;
  return os;
}
template<typename T1,typename T2>
istream &operator>>(istream&is,pair<T1,T2>&p) {
  is>>p.first>>p.second;
  return is;
}
template<typename T>
ostream &operator<<(ostream&os,const vector<T>&v) {
  for(int i=0;i<(int)v.size();i++) {
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  return os;
}
template<typename T>
istream &operator>>(istream&is,vector<T>&v) {
  for(T &in:v)is>>in;
  return is;
}
void scan(){}
template<class Head,class... Tail>
void scan(Head&head,Tail&... tail) {
  cin>>head;
  scan(tail...);
}
template<class T>
void print(const T &t) { cout << t << '\n'; }
template<class Head, class... Tail>
void print(const Head &head, const Tail &... tail) {
  cout << head << ' ';
  print(tail...);
}
template<class... T>
void fin(const T &... a) {
  print(a...);
  exit(0);
}
template<typename T1,typename T2>
inline bool chmax(T1&a,T2 b){return a<b&&(a=b,true);}
template<typename T1,typename T2>
inline bool chmin(T1&a,T2 b){return a>b&&(a=b,true);}
int main(){
  LL(a,b,c,d);
  if(c*d-b<=0){
    fin(-1);
  }
  else{
    fin((a+c*d-b-1)/(c*d-b));
  }
}

#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
using namespace std;
const int INF = 1001001001;
const int MOD = 1e9+7;
template<class T> inline bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  double a,b,c,d; cin >> a >> b >> c >> d;
  if(c*d-b <= 0){
    cout << -1 << endl;
    return 0;
  }
  if(c*d-b == a){
    cout << 1 << endl;
    return 0;
  }
  ll ans = ceil((a)/(c*d-b));
  cout << ans << endl;
  return 0;
}


//做题头
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define _PI acos(-1.0)
#define INF 0x3f3f3f3f
#define esp 1e-9
#define IOS std::ios::sync_with_stdio(0);cin.tie(0);
#define FRE freopen("abc.in", "r", stdin)
#define MEM(X,Y) memset(X,Y,sizeof(X))
#define rep(i,a,b) for(int  i=a;i<b;++i)
#define rep1(i,a,b) for(int  i=a;i<=b;++i)
#define rrep(i,a,b) for(int i=b-1;i>=a;--i)
#define rrep1(i,a,b) for(int i=b;i>=a;--i)
typedef long long LL;
using namespace std;
/*===========================================*/

const int maxn = 2e5 + 5;
char str[maxn];

int main() {
	scanf("%s", str);
	int len = strlen(str);
	char last = 1;
	int lpos = -1;
	LL ret = 0;
	for (int i = 0; i <= len; ++i) {
		if (str[i] == str[i + 1] && str[i] != last)
		{
			if (~lpos)
				ret += 1LL * len - lpos;
			lpos = i;
			last = str[i];
		}
		if (str[i] == last)
			--ret;
	}
	printf("%lld", ret + 1);
}

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1<<30;
const ll inf_l = 1LL<<61;
const int MAX = 2*1e5+10;

int a[MAX], b[MAX], p[MAX], q[MAX];
vector<P> ans;
int n;

bool solve() {
    rep(i,n) {
        if (p[i] == i) continue;
        int now = i, start = i, mn = b[p[i]];
        while (q[now] != i) {
            if (chmin(mn, b[p[q[now]]])) start = q[now];
            now = q[now];
        }
        auto f = [&](int now) {
            if (a[now] <= b[p[now]]) return false;
            if (a[q[now]] <= b[p[q[now]]]) return false;
            ans.push_back(P(now + 1, q[now] + 1));
            swap(p[now], p[q[now]]);
            return true;
        };
        while (p[start] != start) {
            if (!f(start)) return false;
            start = q[start];
        }
    }
    return true;
}

int main() {
    cin >> n;
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n) {
        cin >> p[i];
        p[i]--;
    }
    rep(i,n) q[p[i]] = i;
    if (!solve()) cout << -1 << endl;
    else {
        cout << (int)ans.size() << endl;
        rep(i,ans.size()) {
            cout << ans[i].first << " " << ans[i].second << endl;
        }
    }
}


#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
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf=0x3f,INF=0x3f3f3f3f; const ll LLINF=0x3f3f3f3f3f3f3f3f;
#define sz(x) (int)x.size()
#define af(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x);
#define fil(x, y) fill(af(x), y);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second
#define lc i << 1
#define rc i << 1 | 1
const int mod = 1e9 + 7;
ll fpow(ll a, ll b){ll ret=1;while(b){if(b&1)ret=ret*a%mod;a=a*a%mod,b>>=1;}return ret;}
ll inv(ll x){return x ? fpow(x, mod - 2) : 1;}
void madd(int &a, int b){a+=b;if(a>=mod)a-=mod;}
void msub(int &a, int b){a+=mod-b;if(a>=mod)a-=mod;}
const int MM = 2e5 + 5;

void solve(){
	int n, w;
	cin >> n >> w;
	cout << n / w << '\n';
}

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

#include <bits/stdc++.h>
using namespace std;
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define int long long
#define double long double
#define PI 3.14159265
//=======================
//created by shail
const int mod = 1000000007;
const int inf = 0x3f3f3f3f;
void solve()
{
    int n,w;
    cin >> n >> w;
    cout << n/w;
}
signed main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    int t;
    t=1;
    while(t--)
    {
      solve();
    }
}


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

int main(void) {
  int t;
  ll n;
  cin >> t >> n;
  ll a;
  if(n*100%t!=0) a=(n*100)/t+1;
  else a=n*100/t;
  cout << a+(a*t/100)-1 << endl;
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
int n;
int x[105];
int y[105];

bool ok(double r){
    vector<vector<int>> dist(n+2);
    int s = n;
    int t = n + 1;
    rep(i,n)rep(j,i){
        if( (x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]) < 4*r*r ){
            dist[i].push_back(j);
            dist[j].push_back(i);
        }
    }
    rep(i,n){
        if(abs(y[i] - 100) < 2*r){ dist[s].push_back(i); dist[i].push_back(s);}
        if(abs(y[i] + 100) < 2*r){ dist[t].push_back(i); dist[i].push_back(t);}
    }
    vector<int> seen(n+2,-1);
    queue<int> q;
    q.push(s);
    while(!q.empty()){
        int now = q.front();
        q.pop();
        if(seen[now] >= 0) continue;
        seen[now] = 1;
        for(int j:dist[now]){
            if(seen[j] >= 0) continue;
            q.push(j);
        }
    }
    //rep(i,n+2) cout << seen[i] << " ";
    //cout << endl;
    if(seen[t] == -1) return true;
    else return false;
}

int main(){
    cin >> n;
    rep(i,n) cin >> x[i] >> y[i];

    double l = 0,r = 100;
    rep(i,100){
        double m = (l + r)/2;
        if(ok(m)) l = m;
        else r = m;
    }

    cout << setprecision(20) << l << endl;
    return 0;
}


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

#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define fr(i,k,n) for (int i = k; i < n; ++i)
#define fri(i,k,n) for (int i = k; i >= n; --i)
#define pb push_back
#define mp make_pair
#define all(arr) arr.begin(),arr.end()
#define ff first
#define ss second

const double pi=3.1415926535897932384626433832795;
const int inf=1e9;
const ll inf2=1e18;
const int mod=1e9+7;

void boost(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

void solve(){
    vll d;
    int n;
    cin>>n;
    vpll arr(n);
    vpll x(n),y(n);
    fr(i,0,n){
        cin>>arr[i].ff>>arr[i].ss;
        x[i]={arr[i].ff,i};
        y[i]={arr[i].ss,i};
    }
    sort(all(x));
    sort(all(y));
    int a=n-1,b=n-2;
    for(int i=0;i<n-1;i++){
        if(abs(x[i].ff-x[a].ff)>=abs(arr[x[i].ss].ss-arr[x[a].ss].ss)){
            d.pb(abs((x[i].ff-x[a].ff)));
        }
        if(i!=b && abs(x[i].ff-x[b].ff)>=abs(arr[x[i].ss].ss-arr[x[b].ss].ss)){
            d.pb(abs((x[i].ff-x[b].ff)));
        }
        if(abs(y[i].ff-y[a].ff)>abs(arr[y[i].ss].ff-arr[y[a].ss].ff)){
            d.pb(abs((y[i].ff-y[a].ff)));
        }
        if(i!=b && abs(y[i].ff-y[b].ff)>abs(arr[y[i].ss].ff-arr[y[b].ss].ff)){
            d.pb(abs((y[i].ff-y[b].ff)));
        }
    }
    sort(all(d),greater<ll>());
    cout<<d[1]<<endl;
    return;
}

int main()
{
    boost();

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

#include<bits/stdc++.h>

template<class T>
using pq_inv = std::priority_queue<T, std::vector<T>, std::greater<>>;

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    vector<pair<unsigned long, unsigned long>> house(N);
    for(auto&& [x, y] : house){
        cin >> x >> y;
        x += 1000000000;
        y += 1000000000;
    }
    const auto dist{[&house](const auto& i){
        return max(max(house[i.first].first, house[i.second].first) - min(house[i.first].first, house[i.second].first), max(house[i.first].second, house[i.second].second) - min(house[i.first].second, house[i.second].second));
    }};
    const auto cmp{[&dist](const auto& i, const auto& j){
        return dist(i) == dist(j) ? i > j : dist(i) > dist(j);
    }};
    set<pair<unsigned long, unsigned long>, decltype(cmp)> pq(cmp);
    vector<unsigned long> idx(N);
    iota(begin(idx), end(idx), 0UL);
    sort(begin(idx), end(idx), [&house](auto i, auto j){return house[i] < house[j];});
    pq.emplace(idx[0], idx[N - 1]);
    pq.emplace(idx[1], idx[N - 1]);
    pq.emplace(idx[0], idx[N - 2]);
    sort(begin(idx), end(idx), [&house](auto i, auto j){return house[i].second == house[j].second ? house[i].first < house[j].first : house[i].second < house[j].second;});
    pq.emplace(idx[0], idx[N - 1]);
    pq.emplace(idx[1], idx[N - 1]);
    pq.emplace(idx[0], idx[N - 2]);
    cout << dist(*next(pq.begin())) << endl;
    return 0;
}


#include <bits/stdc++.h>
const int maxn=100000;
using namespace std;
int a[1000000]={0,1,2,2,3};
int isprime[maxn+100];
int prime[maxn+100];
int num=0;
void init(){
    for(int i=0;i<=maxn;i++)isprime[i]=1;
    isprime[1]=0;
    for(int i=2;i<=maxn;i++){
        if(isprime[i]==1){
            prime[num++]=i;
            a[i]=2;
        }
        for(int j=0;j<num&&i*prime[j]<=maxn;j++){
            isprime[i*prime[j]]=0;
            a[i*prime[j]]=max(a[i],a[prime[j]])+1;
            if(i%prime[j]==0)break;
        }
    }
}
int main()
{
    //cout << "Hello world!" << endl;
    init();
    int N;
    cin>>N;

    for(int i=1;i<=N;i++){
        printf("%d ",a[i]);
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define PI 3.1415926535
#define INF INT_MAX
#define SPEED                       \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0);

// Aakash

void solve(){
  int n;
  cin>>n;

  int sum=0;
  if(n<1000)
  sum=0;
  else if(n<1e6)
  sum =  (1*(n - 1e3 +1 ));
  else if(n<1e9)
  sum =  (1*(1e6-1e3) + 2*(n- 1e6 +1));
  else if(n<1e12)
  sum =  (1*(1e6-1e3) + 2*(1e9 - 1e6 ) + 3*(n- 1e9 +1));
  else if(n<1e15)
  sum =  (1*(1e6-1e3) + 2*(1e9 - 1e6 ) + 3*(1e12 - 1e9 ) + 4*(n- 1e12 +1));
  else if(n==1e15)
  sum =  (1*(1e6-1e3) + 2*(1e9 - 1e6 ) + 3*(1e12 - 1e9 ) + 4*(1e15- 1e12 ) + 5);

  cout<<sum<<endl;

}

int32_t main() {

  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);

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


#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    int a, x;
    cin>>a;
    if(a%100)
    {
      x=a/100 + 1;
    }
  else
  {
    x=a/100;
  }
    cout<< x << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define int          	long long int
#define pb           	push_back
#define mp           	make_pair
#define all(x)       	x.begin(),x.end()
#define rep(i,a,b)   	for(int i=a;i<b;i++)
#define mem1(a)      	memset (a,-1,sizeof(a))
#define mem0(a)      	memset (a,0,sizeof(a))
#define sz(x)        	(int)((x).size())
#define rr           	return 0
#define f            	first
#define s            	second
#define pii          	pair<int,int>
#define endl         	"\n"
#define bigprime     	1000000007
#define MOD             1000000007
#define gcd(a,b)        __gcd((a),(b))
#define lcm(a,b)        (a/gcd(a,b))*b
#define scanvec(a,n)      rep(i,0,n){cin>>a[i];}
#define printvec(a,n)     rep(i,0,n){cout<<a[i]<<" ";}
/*********************************************************************************************************************************************************/

//bool ispalindrome(string s){string str = s;reverse(str.begin(),str.end());return(s==str);}
//bool isPrime(int N){for(int i=2;i*i<=N;++i){if(N%i==0) return false;}return true;}
//bool isvowel(char x){ ret//longest common subsequence using memoization over recursion
//int expo(int a, int b, int mod) {int res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;}
int mod(int x){return (x%MOD + MOD)%MOD;}
//int modmul(int a, int b) {return ((a%MOD) * (b%MOD)) % MOD;}
//int modadd(int a, int b){return mod(mod(a) + mod(b));}
//int modsub(int a, int b){return((a%MOD) - (b%MOD) + MOD)%MOD;}
//vector<int> sieve(int n) {int*a = new int[n + 1](); vector<int> v; for (int i = 2; i <= n; i++)if (a[i] == 0) {v.pb(i); for (int j = 2 * i; j <= n; j += i)a[j] = 1;} return v;}

/*********************************************************************************************************************************************************/
void mahol(){
	int n;cin>>n;
	int cnt =0;
	while(n>0){
		n = n-100;
		cnt++;
		//cout<<cnt<<" ";
	}
	cout<<cnt<<endl;
}
signed main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //int t;cin>>t;while(t--){mahol();}
    mahol();
	rr;
}


#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma comment(linker, "/stack:200000000")
using namespace std;
#define F first
#define S second
#define EB emplace_back
#define MP make_pair
#define all(o) (o).begin(), (o).end()
#define mset(m,v) memset(m,v,sizeof(m))
#define rep(i,n) for(ll i=0;i<(n);++i)
#define repe(i,a,b) for(ll i=a;i<=b;++i)
#define revlp(i,a,b) for(ll i=a;i>=b;i--)
#define remin(a,b) (a=min((a),(b)))
#define remax(a,b) (a=max((a),(b)))
#define sz(x) (ll)(x).size()
#define endl '\n'
typedef long long ll;        typedef long double ld;
typedef pair<ll,ll> pi;     typedef vector<ll> vi;
typedef vector<pi> vpi;       typedef vector<vi> graph;
long long mod=1000000007;     long double EPS=1e-9;
#ifndef ONLINE_JUDGE
#define debarr(a,n)cerr<<#a<<":";for(int i=0;i<n;i++)cerr<<a[i]<<" ";cerr<<endl;
#define debmat(mat,row,col)cerr<<#mat<<":\n";for(int i=0;i<row;i++){for(int j=0;j<col;j++)cerr<<mat[i][j]<<" ";cerr<<endl;}
#define pr(...)dbs(#__VA_ARGS__,__VA_ARGS__)
template<class S,class T>ostream &operator<<(ostream &os,const pair<S,T> &p){return os<<"("<<p.first<<","<<p.second<<")";}
template<class T>ostream &operator<<(ostream &os,const vector<T> &p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class T>ostream &operator<<(ostream &os,const set<T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class T>ostream &operator<<(ostream &os,const multiset<T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class S,class T>ostream &operator<<(ostream &os,const map<S,T>&p){os<<"[";for(auto&it:p)os<<it<<" ";return os<<"]";}
template<class T>void dbs(string str,T t){cerr<<str<<":"<<t<<"\n";}
template<class T,class...S>void dbs(string str,T t,S... s){int idx=str.find(',');cerr<<str.substr(0,idx)<<":"<<t<<",";dbs(str.substr(idx+1),s...);}
#else
#define pr(...){}
#define debarr(a,n){}
#define debmat(mat,row,col){}
#endif

void solve(){
    ll n;
    cin>>n;
    vector<ll> a(n),b(n);
    rep(i,n)    cin>>a[i];
    rep(i,n)    cin>>b[i];
    vector<ll> preMaxA(n);
    preMaxA[0]=a[0];
    repe(i,1,n-1)   preMaxA[i]=max(preMaxA[i-1],a[i]);
    vector<ll> temp(n);
    rep(i,n)    temp[i]=b[i]*preMaxA[i];
    vector<ll> preMaxB(n);
    preMaxB[0]=temp[0];
    repe(i,1,n-1)   preMaxB[i]=max(preMaxB[i-1],temp[i]);
    rep(i,n)    cout<<preMaxB[i]<<endl;
}

signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    //cout<<fixed<<setprecision(15);
    //clock_t begin = clock();
    ll tc=1;//cin>>tc;
    for(ll i=1;i<=tc;i++){
        //cout<<"Case #"<<i<<": ";
        solve();
    }
    // clock_t end = clock();double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC;cerr << elapsed_secs;
}

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

typedef long long ll;
const int N=2e5+5;
int a[N],b[N],n;

int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for(int i=1;i<=n;++i){
    cin >> a[i];
    a[i]=max(a[i],a[i-1]);
  }
  for(int i=1,j=0;i<=n;++i){
    cin >> b[i];
    if(1LL*b[i]*a[i]>1LL*b[j]*a[j])j=i;
    cout << 1LL * a[j]*b[j]<<'\n';
  }
}


#include <iostream>
#define a1 int('A')
#define a2 int('a')
#define z1 int('Z')
#define z2 int('z')
using namespace std;
int main(){
string str;
bool b = true;
cin >> str;
for (int i = 0;i < str.size();i++){ if (i % 2 == 0 && int(str[i]) >= a2 && int(str[i]) <= z2){} else if (i % 2 == 1 && int(str[i]) >= a1 && int(str[i]) <= z1){}
else b = false;
}
if (b) cout << "Yes";
else cout << "No";
}

#include <bits/stdc++.h>

#define rep(i, x, n) for (int i = (x); i < (n); i++)
#define reps(i, x, n) for (int i = (x); i <= (n); i++)
#define lol long long
#define SUM(n) ((n) + 1) * (n) / 2  // 1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed << setprecision(x + 1)  //小数点桁数を指定する
#define abs(x, y) max(x, y) - min(x, y)
#define all(v) v.begin(), v.end()
#define UPDigit(a, b) (a + b - 1) / b  //小数点切り上げ
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD = int(1e9) + 7;
using namespace std;
using pii = pair<int, int>;
typedef vector<int> vit;
//八方向を見るのに使うと便利(楽)
const int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};

signed main(void) {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  string s;
  cin >> s;
  for(int i = 0;i < s.size();i += 2){
    if(!('a' <= s[i] && s[i] <= 'z')){
      cout << "No\n";
      return 0;
    }
  }
  for(int i = 1;i < s.size();i += 2){
    if(!('A' <= s[i] && s[i] <= 'Z')){
      cout << "No\n";
      return 0;
    }
  }
  cout << "Yes\n";
  return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

/*** mod int ***/

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

/*** mod int ここまで ***/

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} comb(1000005);

void Solve(){
    int n, a, b; cin >> n >> a >> b;
    if(a+b>n) {
        cout << 0 << endl;
        return;
    }
    mint x = (mint)(n-(a+b)+2) * (mint)(n-(a+b)+1)/2;
    mint y = (mint)(n-a+1) * (mint)(n-b+1) - (mint)x * 2;
    mint ans = (mint)(n-a+1) * (mint)(n-a+1) * (mint)(n-b+1) * (mint)(n-b+1) - y * y;
    cout << ans << endl;
}

void Main(){
    int t; cin >> t;
    while(t--) Solve();
    return;
}

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

//#include<math.h>
#include<algorithm>
#include<stdlib.h>
#include<time.h>
#include<stdio.h>
#include<string.h>
#define un unsigned
#define srd srand(time(0))
#define ll long long
#define con continue
#define gtc getchar()
#define ptc putchar
#define dou double
#define eps 0.00000000001
#define opr operator
#define cl(x,a) memset(x,a,sizeof(x))
#define fo0(i,k) for(i=fr[k];i;i=nx[i])
#define fo1(i,l,r) for(i=l;i<=r;i++)
#define fo2(i,l,r) for(i=l;i>=r;i--)
#define fo(i,n) for(i=1;i<=n;i++)
#define ret return
#define x first
#define cint const int
#define y second
#define opi(x) freopen(x,"r",stdin)
#define opo(x) freopen(x,"w",stdout)
#define tpl template<class T>
#define priq priority_queue
#define mp make_pair
#define use using namespace
#define WT while(T--)
use std;
typedef pair<int,int> pii;typedef pair<int,ll> pil;typedef pair<ll,int> pli;typedef pair<ll,ll> pll;
namespace io
{
	void _(int &k){char c;int e=1;k=0;while((c=gtc)>'9'||c<'0')if(c=='-')e=-1;k=c-'0';while((c=gtc)<='9'&&c>='0'){k*=10;k+=c-'0';}k*=e;}
	void _(ll &k){char c;int e=1;k=0;while((c=gtc)>'9'||c<'0')if(c=='-')e=-1;k=c-'0';while((c=gtc)<='9'&&c>='0'){k*=10;k+=c-'0';}k*=e;}
	void _(char &c){while((c=gtc)==' '||c=='\n');}void _(dou &c){scanf("%lf",&c);}void _(char *s){char c;while((c=gtc)!=EOF&&c!=' '&&c!=10)*s++=c;}
	template<class t1,class t2>void _(t1 &a,t2 &b){_(a);_(b);}template<class t1,class t2,class t3>void _(t1 &a,t2 &b,t3 &c){_(a);_(b);_(c);}
	template<class t1,class t2,class t3,class t4>void _(t1 &a,t2 &b,t3 &c,t4 &d){_(a);_(b);_(c);_(d);}
	template<class t1,class t2,class t3,class t4,class t5>void _(t1 &a,t2 &b,t3 &c,t4 &d,t5 &e){_(a);_(b);_(c);_(d);_(e);}
	void _p(dou k){printf("%.6lf",k);}void _p(char *c){for(;*c;ptc(*c++));}void _p(const char *c){for(;*c;ptc(*c++));}void _p(char c){ptc(c);}
	tpl void _p0(T k){if(k>=10)_p0(k/10);ptc(k%10+'0');}tpl void _p(T k){if(k<0){ptc('-');_p0(-k);}else _p0(k);}tpl void __p(T k){_p(k);ptc(' ');}
	tpl void _pn(T k){_p(k);ptc('\n');}template<class t1,class t2>void _p(t1 a,t2 b){__p(a);_pn(b);}
	template<class t1,class t2,class t3>void _p(t1 a,t2 b,t3 c){__p(a);__p(b);_pn(c);}
	template<class t1,class t2,class t3,class t4>void _p(t1 a,t2 b,t3 c,t4 d){__p(a);__p(b);__p(c);_pn(d);}
	tpl void op(T *a,int n){int i;n--;fo(i,n)__p(a[i]);_pn(a[n+1]);}int gi(){int x;_(x);ret x;}ll gll(){ll x;_(x);ret x;}
}
int gcd(int a,int b){ret b?gcd(b,a%b):a;}void fcl(){fclose(stdin);fclose(stdout);}
void fop(const char *s){char c[256],d[256];cl(c,0);cl(d,0);strcpy(c,s);strcpy(d,s);opi(strcat(c,".in"));opo(strcat(d,".out"));}
int eq(dou a,dou b){return a+eps>=b&&b+eps>=a;}tpl void _ma(T &a,T b){if(a<b)a=b;}tpl void _mi(T &a,T b){if(a>b)a=b;}
cint N=2222,EE=100000000,GG=1000000000,ima=2147483647;
use io;
char a[1111][1111];
int fa[N],n,m,c[N],d[N],f[N],T;
int fi(int k){return fa[k]=fa[k]==k?k:fi(fa[k]);}
void hb(int x,int y)
{
	x=fi(x);
	y=fi(y);
	fa[x]=y;
}
int main()
{
	int i,j,a1,a2;
	_(n,m);
	fo(i,n)
		scanf(" %s",a[i]+1);
	fo(i,2111)
		fa[i]=i;
	a[1][1]=a[1][m]=a[n][1]=a[n][m]='#';
	fo(i,n)
		fo(j,m)
			if(a[i][j]=='#')
				hb(i*2,j*2+1);
	fo(i,n)
		c[i]=fi(i*2);
	sort(c+1,c+n+1);
	fo(i,m)
		d[i]=fi(i*2+1);
	sort(d+1,d+m+1);
	_pn(min(unique(d+1,d+m+1)-d,unique(c+1,c+n+1)-c)-2);
}


#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <deque>
#include <set>
#include <limits>
#include <string>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <numeric>

using namespace std;

using ll = long long;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)

/* input & output */
#define IN(a) cin >> a
#define OUT(a) cout << a << endl
#define OUT_PREC(a, n) cout << fixed << setprecision(n) << a << endl

/* vector */
#define VEC(t, v, n, ini) vector<t> v(n, ini)
#define VEC2(t, v, m, n, ini) vector<vector<t>> v(m, vector<t>(n, ini))
#define VEC3(t, v, k, m, n, ini) vector<vector<vector<t>>> v(k, vector<vector<t>>(m, vector<t>(n, ini)))

/* bit */
#define IS_TRUE(bit, i) (bit & (1 << i))    // bitのi成分
#define FLAG_ON(bit, i) (bit｜(1 << i))     // bitのi成分をtrueに
#define FLAG_OFF(bit, i) (bit & ~(1 << i))  // bitのi成分をfalseに
#define ALL_TRUE(n) (1 << n)                // 2^n
#define CMPSET(bit, s) (bit ^ s)              // sのbitに対する補集合
#define INCLUDES(a, b) ((a & b) == b)       // aはbを含むか

void solve()
{
    double a, b, w;
    cin >> a >> b >> w;
    w *= 1000;

    int min = (int)ceil(w / b);
    int max = (int)floor(w / a);
    if (max < min){
        cout << "UNSATISFIABLE" << endl;
        return;
    }

    cout << min << " " << max << endl;
    return;

}

int main()
{
    /* solve */
    solve();
    system("pause");
}

#include <iostream>
#include <map>
#include <list>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>

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

typedef long long ll;

using namespace std;

ll modd = 1000 * 1000 * 1000 + 7;

int main()   {

      ios_base::sync_with_stdio(false);

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

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

//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readint(n); readstring(s);
        map<char,int> dict{{'A', 0}, {'T', 1}, {'C', 2}, {'G', 3}};
        vector<vector<int>> freq(4, vector<int>(1, 0));
        for(char c : s) {
            for(auto x : dict) {
                freq[x.second].push_back(freq[x.second].back() + (x.first==c));
            }
        }

        int ret = 0;
        forr(i,0,n) {
            for(int j = i + 1; j <= n; ++j) {
                map<char,int> cand;
                for(auto x : dict) {
                    cand[x.first] = freq[x.second][j] - freq[x.second][i];
                }
                ret += ((cand['A']==cand['T']) && (cand['C']==cand['G']));
            }
        }

        cout << ret << endl;

    }
    return 0;
}

//        auto stop = chrono::steady_clock::now();
//        auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start);
//        cout << "Duration: " << duration.count() << endl;


#include<bits/stdc++.h>
#define rep(i,a,...) for(long long i = (a)*(strlen(#__VA_ARGS__)!=0);i<(long long)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(long long i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(long long)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
#define lambda(RES_TYPE, ...) (function<RES_TYPE(__VA_ARGS__)>)[&](__VA_ARGS__) -> RES_TYPE
#define method(FUNC_NAME, RES_TYPE, ...) function<RES_TYPE(__VA_ARGS__)> FUNC_NAME = lambda(RES_TYPE, __VA_ARGS__)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

namespace templates{
    ll modpow(ll x, ll b,ll mod=MOD){
        ll res = 1;
        while(b){
            if(b&1)res = res * x % mod;
            x = x * x % mod;
            b>>=1;
        }
        return res;
    }

    ll modinv(ll x){
        return modpow(x, MOD-2);
    }

    bool was_output = false;
    template<class t>
    void output(t a){
        if(was_output)cout << " ";
        cout << a;
        was_output = true;
    }
    void outendl(){
        was_output = false;
        cout << endl;
    }

    template<class t>
    istream& operator>>(istream&is, vector<t>&x){
        for(auto &i:x)is >> i;
        return is;
    }

    template<class t, class u>
    istream& operator>>(istream&is, pair<t, u>&x){
        is >> x.first >> x.second;
        return is;
    }

    template<class t>
    ostream& operator<<(ostream&os, vector<t> &v){
        os << "{";
        for(t &i:v){
            os << i << ", ";
        }
        os << "}";
        return os;
    }

    template<class t = long long>
    t in(){
        t res; cin >> res; return res;
    }

    template<class t>
    void out(t x){
        cout << x;
    }

    template<class t>
    vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){
        sort(line.begin(),line.end(),comp);
        return line;
    }

    template<class t>
    vector<t> reversed(vector<t> line){
        reverse(line.begin(),line.end());
        return line;
    }
    string reversed(string str){
        reverse(str.begin(),str.end());
        return str;
    }

    long long gcd(long long a,long long b){
        while(b){
            a %= b;
            swap(a,b);
        }
        return a;
    }

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

using namespace templates;

template <class T>
vector<T> make_vector(int n,T init){
    return vector<T>(n,init);
}

template <class... tail>
auto make_vector(int n, tail... args){
    return vector<decltype(make_vector(args...))>(n,make_vector(args...));
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int a = in();
    int b = in();
    int ans = 0;
    rep(i,1,b){
        int l = (a+i-1)/i*i;
        int r = b/i*i;
        if(l<r){
            chmax(ans,i);
        }
    }
    cout << ans << endl;
    return 0;
}

#include <iostream>
#include <string>
#include <fstream>
#include <random>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>
#include <typeinfo>
#include <iterator>

//#define PRINT

using ll = long long;
using ull = unsigned long long;
constexpr ll mop = 1000000007;
constexpr ll mop2 = 998244353;

using namespace std;

constexpr ll NOT_SPECIFIED_VALUE_MIN = INT64_MIN;
constexpr ll NOT_SPECIFIED_VALUE_MAX = INT64_MAX;

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

	ll h, w;
	cin >> h >> w;
	ll sum = 0;
	ll minValue = NOT_SPECIFIED_VALUE_MAX;
	for(ll i=0;i<h;++i){
		for(ll j=0;j<w;++j){
			ll a;
			cin >> a;
			sum += a;
			if( a < minValue )
			{
				minValue = a;
			}
		}
	}

	cout << sum - ( minValue ) * ( h * w ) << '\n';
}


// Problem: B - Visibility
// Contest: AtCoder - AtCoder Beginner Contest 197（Sponsored by Panasonic）
// URL: https://atcoder.jp/contests/abc197/tasks/abc197_b
// Memory Limit: 1024 MB
// Time Limit: 2000 ms

// Disclaimer: Don't copy my template, it may lead to plagiarism.
/* Author: Soumy Jain
   Handle: soumy_jain || soumyjain
   "Beautiful flowers too, eventually wither and fall. That's the fate of all living beings."
   "I hate perfection. To be perfect is to be unable to improve any furthur." - Mayuri Kurotsuchi | Bleach
   "I smile to show the pressure of heroes and to trick the fear inside of me."
   "Gravel may be gravel, but me? I'm the gravel that shatters diamonds."
   "If you were to write a story with me in the lead role, it would certainly be...a TRAGEDY." - Kaneki Ken | Tokyo
   Ghoul
*/
/******************************************************************************/
// clang-format off
#include <bits/stdc++.h>
#define ll        long long
#define ull       unsigned long long
#define SPEEDHACK ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ff        first
#define ss        second
#define sz(v)     (ll)(v).size()
#define file      freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define MOD       1000000007      // 998244353
using namespace std;
/******************************************************************************/
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(ll x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(ull x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

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

/***********************************MAIN***************************************/
// Are you ready to face the wrath of test cases? Good luck noob Soumy!

void work()
{
    ll h, w, x, y;
    cin >> h >> w >> x >> y;
    vector<string> v(h);
    for (auto &i : v)
        cin >> i;
    ll ans = 0;
    for (ll i = x - 1; i >= 0; i--)
    {
        if (v[i][y - 1] == '#')
            break;
        ans++;
    }
    for (ll i = x; i < h; i++)
    {
        if (v[i][y - 1] == '#')
            break;
        ans++;
    }
    for (ll i = y - 1; i >= 0; i--)
    {
        if (v[x - 1][i] == '#')
            break;
        ans++;
    }
    for (ll i = y; i < w; i++)
    {
        if (v[x - 1][i] == '#')
            break;
        ans++;
    }
    cout << ans - 1 << '\n';
}

int main()
{
    SPEEDHACK
    // file
    ll t = 1;
    // cin >> t;
    while (t--)
    {
        work();
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int N, M;
int board[105][105];
bool vis[105][105];
int dy[4] = {-1, 1, 0, 0};
int dx[4] = {0, 0, -1, 1};
int X, Y;
bool valid(int y, int x) {
    return 1<=y && y<=N && 1<=x && x<=M;
}

int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    cin >> N >> M >> Y >> X;
    for(int i=1;i<=N;++i) {
        string s; cin >> s;
        for(int j=1;j<=M;++j) {
            board[i][j] = s[j-1] == '#';
        }
    }
    int ans = 0;
    for(int i=0;i<4;++i) {
        int y = Y;
        int x = X;
        while(valid(y, x) && board[y][x] == 0) {
            if(!vis[y][x]) {
                vis[y][x] = true;
                ++ans;
            }
            y += dy[i];
            x += dx[i];
        }
    }
    cout << ans << '\n';
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long int lli;
#define pb push_back
#define nline "\n"
#define gcd(a,b) (__gcd(a,b))
#define lcm(a,b) ((a*b)/gcd(a,b))
vector<ll> soe(ll n) {ll *arr = new ll[n + 1]; vector<ll>ans; for (ll i = 0; i <= n; i++) {arr[i] = 1;} arr[0] = 0; arr[1] = 0; for (ll i = 2; i <= sqrt(n); i++) {if (arr[i] == 1) {for (ll j = 2; i * j <= n; j++) {arr[i * j] = 0;}}} for (ll i = 0; i <= n; i++) {if (arr[i] == 1)ans.push_back(i);} return ans;}

const ll mod = 1e9 + 7;
/* ncr = n-1cr-1+ n-1cr  */

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

ll fpow(ll a, ll g) {
	ll ag = 1;
	while (g) {
		if (g & 1) ag = (ag * a) % mod;
		a = (a * a) % mod;
		g >>= 1;
	}
	return ag;
}

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

	for (int i = s.length() - 1; i >= 0; i--) {
		if ((s[i] - '0') == 6) {
			cout << '9';
		}
		else if ((s[i] - '0') == 9) {
			cout << '6';
		}
		else {
			cout << s[i];
		}
	}
	cout << nline;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("inputf.in", "r", stdin);
	freopen("outputf.in", "w", stdout);
#endif
	// int test;
	// cin >> test;
	// while(test--){
	solve();
	// }
}

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

int main() {
  string S;
  cin >> S;
  int num = S.size();
  for(int i = 0 ;i < num ;i++){
    if(S.at(i) == '6'){
      S.at(i) = '9';
    }
     else if(S.at(i) == '9'){
      S.at(i) = '6';
    }
  }
   string S_reverse (S.rbegin(), S.rend());
    cout << S_reverse << endl;
}


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

vector<string> v{
  "8",
  "16",
  "61",
  "24",
  "42",
  "32",
  "23",
  "48",
  "84",
  "56",
  "65",
  "64",
  "46",
  "72",
  "27",
  "88",
  "96",
  "69"
};

bool Solve(string s)
{
  if (find(v.begin(), v.end(), s) != v.end())
    return true;

  sort(s.begin(), s.end());
  rep(i,13,124)
  {
    string t = to_string(i * 8);
    sort(t.begin(), t.end());
    if (s.find(t) != string::npos)
      return true;
  }

  return false;
}

int main() {
  string s;
  cin >> s;
  if (Solve(s)) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define INF 0x7fffffff
typedef long long ll;
typedef long double ld;

typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<ld> vld;

#define fastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define beg(x) x.begin()
#define en(x) x.end()

int main()
{
	fastIO;
	set<vi> S, S2, S3;
	for(int i = 16; i < 100; i += 8)
	{
		int a, b;
		vi v(10,0);
		a = i % 10; v[a]++;
		b = i / 10; v[b]++;
		S2.insert(v);
	}
	for(int i = 0; i < 1000; i += 8)
	{
		int a, b, c;
		vi v(10,0);
		a = i % 10; v[a]++;
		b = i / 10 % 10; v[b]++;
		c = i / 100; v[c]++;
		// for(int j = 0; j < 10; j++) printf("v[%d] = %d\n", j, v[j]);
		// cout << endl;
		S.insert(v);
	}
	// for(auto x : S)
	// {
	// 	for(int i = 0; i < 10; i++)
	// 		cout << x[i] << ' ';
	// 	cout << endl;
	// }

	string s; cin >> s;
	int cnt[10] = {0};
	for(int i = 0; i < s.length(); i++) cnt[s[i] - '0']++;
	if(s.length() == 1) printf("%s\n", cnt[8] == 1 ? "Yes" : "No");
	else if(s.length() == 2)
	{
		if(cnt[1] & cnt[6] | cnt[2] & cnt[4] | cnt[3] & cnt[2] | cnt[4] & cnt[0] | cnt[4] & cnt[8] | cnt[5] & cnt[6] | cnt[6] & cnt[4] | cnt[7] & cnt[2] | cnt[8] & cnt[0] | cnt[8] == 2 | cnt[9] & cnt[6])
			cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	else
	{
		for(auto x : S)
		{
			int k = 1;
			for(int i = 0; i < 10; i++)
				if(cnt[i] < x[i])
					k = 0;
			if(k)
			{
				cout << "Yes" << endl;
				return 0;
			}
		}
		cout << "No" << endl;
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
const ll MAX = 1001001;
const ll MOD = 1000000007;
const double pi = 2.0 * asin(1.0);
ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, 1, 0, -1};
int main()
{
    ll h, w, a, b;
    cin >> h >> w >> a >> b;
    if (h < w)
    {
        swap(h, w);
    }
    ll ans = 0;
    for (int tmp = 0; tmp < (1 << (h * w)); tmp++)
    {
        bitset<16> s(tmp);
        ll co = 0;
        vector<vector<bool>> c(h, vector<bool>(w));
        rep(i, h * w)
        {
            if (s.test(i))
            {
                co++;
                c[i / w][i % w] = true;
            }
        }
        if (co != b)
        {
            continue;
        }
        vector<ll> crt((1 << w));
        vector<ll> next((1 << w));
        crt[0] = 1;
        for (ll i = h - 1; i >= 0; i--)
        {
            for (ll j = w - 1; j >= 0; j--)
            {
                rep(u, (1 << w))
                {
                    if ((u >> j & 1) || (c[i][j]))
                    {
                        next[u] = crt[u & ~(1 << j)];
                    }
                    else
                    {
                        ll res = 0;
                        if (j + 1 < w && !(u >> (j + 1) & 1) && !c[i][j + 1])
                        {
                            res += crt[u | 1 << (j + 1)];
                        }
                        if (i + 1 < h && !c[i + 1][j])
                        {
                            res += crt[u | 1 << j];
                        }
                        next[u] = res;
                    }
                }
                swap(crt, next);
            }
        }
        ans += crt[0];
    }
    cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = (n-1); i >= 0; i--)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++)

template <class S>S sum(vector<S>& a) {return accumulate(all(a), S());}
template <class S>S max(vector<S>& a) {return *max_element(all(a));}
template <class S>S min(vector<S>& a) {return *min_element(all(a));}
ll max(int a, ll b) { return max((ll)a, b); } ll max(ll a, int b) { return max(a, (ll)b); }
ll min(int a, ll b) { return min((ll)a, b); } ll min(ll a, int b) { return min(a, (ll)b); }

#define VM 10
void eprint() { cerr << endl; }
template <class First, class... Rest>
void eprint(First f, Rest... r) {
  cerr << f << ' ';
  eprint(r...);
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  size_t output_num = v.size();
  bool is_omitted = false;
#ifdef VM
  if (VM < output_num) {
    output_num = VM;
    is_omitted = true;
  }
#endif
  os << "[";
  for (size_t i = 0; i < output_num - 1; i++) os << v[i] << ", ";
  os << v[output_num - 1];
  if (is_omitted) os << ", ...";
  return os << "]";
}
template <class S, class T>
ostream& operator<<(ostream& os, const map<S,T>& m) {
  os << "{\n";
  for(auto [k,v]: m){
    os << k << ": " << v << ",\n";
  }
  return os << '}';
}

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

using Heya = vector<vector<bool>>;

vector<pair<Heya,int>> patterns;
int h, w, a;

void dfs(Heya heya, int row, int used){
  if(used > a) return;
  if(row == h){
    patterns.push_back(make_pair(heya, used));
    return;
  }
  if(w == 2){
    auto h1 = heya;
    h1[row][0] = true;
    h1[row][1] = true;
    dfs(heya, row+1, used);
    dfs(h1, row+1, used+1);
  }else if(w == 3){
    auto h1 = heya;
    auto h2 = heya;
    h1[row][0] = true;
    h1[row][1] = true;
    h2[row][1] = true;
    h2[row][2] = true;
    dfs(heya, row+1, used);
    dfs(h1, row+1, used+1);
    dfs(h2, row+1, used+1);
  }else{
    auto h1 = heya;
    auto h2 = heya;
    auto h3 = heya;
    auto h4 = heya;
    dfs(heya, row+1, used);
    h1[row][0] = true;
    h1[row][1] = true;
    h1[row][2] = true;
    h1[row][3] = true;
    dfs(h1, row+1, used+2);
    h2[row][0] = true;
    h2[row][1] = true;
    dfs(h2, row+1, used+1);
    h3[row][1] = true;
    h3[row][2] = true;
    dfs(h3, row+1, used+1);
    h4[row][2] = true;
    h4[row][3] = true;
    dfs(h4, row+1, used+1);
  }
}
ll ans;

void dfs_col(Heya heya, int row, int col, int used){
  if(used > a) return;
  if(col == w){
    if(used == a){
      ans++;
    }
    return;
  }
  for(int i = row; i < h-1; i++){
    if(!heya[i][col] && !heya[i+1][col]){
      auto h1 = heya;
      h1[i][col] = true;
      h1[i+1][col] = true;
      dfs_col(h1, i+2, col, used+1);
    }
  }
    dfs_col(heya, 0, col+1, used);
}

void Main(){
  cin >> h >> w >> a;
  ans = 0;
  if(h < w) swap(h, w); // h > w
  if(w > 1){
    dfs(vector<vector<bool>>(h, vector<bool>(w, false)), 0,  0);
  }else{
    patterns.push_back(make_pair(vector<vector<bool>>(h, vector<bool>(w, false)), 0));
  }
  for(auto [p, u]: patterns){
    dfs_col(p, 0, 0, u);
  }
  cout << ans << endl;
}


#include <iostream>
#include <iomanip>
#include <algorithm>
#include <assert.h>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#include <chrono>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=a;i<b;++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,a) rrepi(i,a,0)
#define rrepi(i,a,b) for(int i=a-1;i>=b;--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}

const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ll MOD3 = 1e6;
const ll EPS = 1e-10;
int sgn(const double a){
    return (a < -EPS ? -1 : (a > EPS ? +1 : 0));
}
typedef pair<int,int> pi;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> tri;
typedef pair<double,double> point;
typedef complex<double> Point;
typedef string::const_iterator State;
const ll MAX = 105;
constexpr ll nx[4] = {-1,0,1,0};
constexpr ll ny[4] = {0,1,0,-1};

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    cins(all(a));
    map<int,int> t;
    int mi = 1e9;
    rep(i,n){
        chmin(mi,a[i]);
        rep(j,1,sqrt(a[i])+1){
            if (a[i]%j != 0) continue;
            if (t[j] == 0){
                t[j] = a[i];
            }
            else{
                t[j] = gcd(t[j],a[i]);
            }
            int m = j;
            j = a[i]/m;
            if (t[j] == 0){
                t[j] = a[i];
            }
            else{
                t[j] = gcd(t[j],a[i]);
            }
            j = m;
        }
    }
    int ans = 0;
    //PRINT(mi);
    for (auto [c,d]:t){
        if (c > mi) break;
        if (c == d) ans++;
        //PRINT(c << " " << d);
    }
    PRINT(ans);
}

#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
    vector<char> a(12);
    for(int i=0;i<12;i++){
        cin >> a.at(i);
    }
    int c=0;
    for(int i=0;i<12;i++){
        if(a.at(i)=='Z' && a.at(i+1)=='O' && a.at(i+2)=='N' && a.at(i+3)== 'e'){
            c++;
        }
    }
    cout << c;
}


#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,a,b) for(int i=int(a);i<(int)b;++i)
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vp vector<pair<ll,ll>>
#define pb push_back
#define all(v) v.begin(),v.end()

using namespace std;
using ll = long long;
const ll INF = 1e18;
const double PI = acos(-1);

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(void){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vi p(n),dif(n);
    ll num = 0;
    vi ans(n),ta(200000);
    set<int> se;

    rep(i,n){
        cin >> p[i];
        se.insert(p[i]);
        ta[p[i]]++;

    }
    int i = 0;
    while(true){
        if(se.count(i) == 0){
            ans[n-1] = i;
            break;
        }
        ++i;
    }

    for(int j = n-2;j >= 0; --j){
        ta[p[j+1]]--;
        if(p[j+1] < ans[j+1] && !ta[p[j+1]]){
            ans[j] = p[j+1];
        }else{
            ans[j] = ans[j+1];
        }
    }
    rep(i,n){
        cout << ans[i] << endl;
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll> pql;
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, k, n) for(ll i = ll(k); i <= ll(n); i++)
#define rep3(i, n, k) for(ll i = ll(n); i >= ll(k); i--)
#define all(v) (v).begin(), (v).end()
ll mod(ll a, ll b) {return (a % b + b) % b;}
ll quo(ll a, ll b) {return (a - mod(a, b)) / b;}
template <typename T, typename U> bool chmin(T &a, const U b) {if(a > b) {a = b; return 1;} return 0;}
template <typename T, typename U> bool chmax(T &a, const U b) {if(a < b) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 2e5;
const ld eps = 1e-9;
const char newl = '\n';

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

  ll n, x, c;
  cin >> n;
  vl l(n, INF), r(n, -INF);
  rep(_, n) {
    cin >> x >> c;
    c--;
    chmin(l[c], x);
    chmax(r[c], x);
  }
  pl tmpl = pl(0, 0), tmpr = pl(0, 0);
  rep(i, n) {
    if(l[i] > r[i]) continue;
    pl L = pl(l[i], 0), R = pl(r[i], 0);
    L.second = min(tmpl.second + abs(tmpl.first - r[i]), tmpr.second + abs(tmpr.first - r[i])) + abs(r[i] - l[i]);
    R.second = min(tmpl.second + abs(tmpl.first - l[i]), tmpr.second + abs(tmpr.first - l[i])) + abs(l[i] - r[i]);
    tmpl = L;
    tmpr = R;
  }
  cout << min(abs(tmpl.first) + tmpl.second, abs(tmpr.first) + tmpr.second) << newl;
  return 0;
}


#include <bits/stdc++.h>

#define ll             long long
#define sf             scanf
#define pf             printf
#define nl             printf("\n")
#define pb             push_back
#define TEST           int Test;cin>>Test;for(int _t=1;_t<=Test;_t++)

using namespace std;

int main()
{
	int a,b;
	sf("%d %d",&a,&b);
	int ans = (2*a)+100 - b;
	pf("%d\n",ans);
	return 0;
}

// JG GAP GG

#include <iostream>
#include <cstring>
#include<vector>
#include <algorithm>
#include<cstdlib>
#include<set>
#include<math.h>
#include<map>
#include<unordered_map>
#include<iomanip>
#include<queue>
#include<bitset>

using namespace std;
using ll = long long;
using ull = unsigned long long;
const ll MOD = 1000000007;
#define rep(n,x) for(ll i=0;i<n;i++) cin>>x[i];
#define forr(a,b) for(ll i=a;i<b;i++);
#define vecsort(myVec,x,y) sort(myVec.begin(),myVec.end(),[](const vector<y> &alpha,const vector<y> &beta){return alpha[x] < beta[x];});
#define vsort(v) sort(v.begin(),v.end());
#define vdownsort(v) sort(v.begin(),v.end(),greater<ll>());
ll modpow(ll a, ll n, ll mod)
{
	ll res = 1;
	while (0 < n)
	{
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

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

	int a, b;
	cin >> a >> b;
	cout << 2 * a + 100 - b << endl;

	return 0;
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
	int n;
	cin>>n;
	int a[n+1];
	int sum=0,tot=0;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	for(int i=1;i<=n;i++){
		tot+=(n-1)*a[i]*a[i];
		tot-=a[i]*(sum-a[i]);
	}
	cout<<tot;

	return 0;
}

#include <bits/stdc++.h>

#define x first
#define y second

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;

const int N = 210;

map<int, int> cnt;

int main()
{
	int n;
	cin >> n;
	for (int i = 1; i <= n; i ++ )
	{
		int x;
		cin >> x;
		cnt[x] ++;
	}

	LL ans = 0;
	for (int i = -200; i <= 200; i ++ )
		for (int j = i + 1; j <= 200; j ++ )
			ans += (LL)cnt[i] * cnt[j] * (j - i) * (j - i);
	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define run ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0);
#define LL_MAX LLONG_MAX

#define ub(v,x) upper_bound(v.begin(),v.end(),x)
#define lb(v,x) lower_bound(v.begin(),v.end(),x)

#define mod 1000000007
int exp(int x,int y){int res=1;x=x%mod;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
int modinv(int x){return exp(x,mod-2);}
int add(int a,int b){a%=mod,b%=mod;a=((a+b)%mod+mod)%mod;return a;}
int sub(int a,int b){a%=mod,b%=mod;a=((a-b)%mod+mod)%mod;return a;}
int mul(int a,int b){a%=mod,b%=mod;a=((a*b)%mod+mod)%mod;return a;}
int fac[1000009];int ncr_mod(int n,int k){int ans=fac[n];ans*=modinv(fac[k]);ans%=mod;ans*=modinv(fac[n-k]);ans%=mod;return ans;}

vector<int>v_prime;void Sieve(int n){bool prime[n + 1];memset(prime,true,sizeof(prime));for (int p = 2; p*p <=n;p++){if(prime[p] ==true) {for(int i = p*p; i<= n; i += p)prime[i]=false;}}for(int p = 2;p<= n;p++)if (prime[p])v_prime.pb(p);}
vector<int>v_factor;void factor(int n){ for (int i=1; i<=sqrt(n); i++) {if (n%i == 0) {if (n/i == i) v_factor.pb(i);else { v_factor.pb(i),v_factor.pb(n/i);};} } sort(all(v_factor)); }

int power(int x, int y){int temp;if( y == 0)return 1; temp = power(x, y / 2);if (y % 2 == 0) return temp * temp;else return x * temp * temp;}
int gcd(int a, int b){if (b == 0)return a; return gcd(b, a % b);}
int log2n( int n){ return (n > 1) ? 1 + log2n(n / 2) : 0;}

void out(vector<int>&a){for(int i=0;i<a.size();i++) cout<<a[i]<<" ";  cout<<endl;}
void sout(set<int>s){for(auto it=s.begin();it!=s.end();++it)cout<<*it<<" ";  cout<<endl;}
void mout(map<int,int>mm){for(auto it=mm.begin();it!=mm.end();++it) cout<<it->fi<<" "<<it->se<<endl;}

#define ms(a,x)  memset(a, x, sizeof(a));

#define decimal(n,k) cout<<fixed<<setprecision(k)<<n<<endl
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl

// In binary search always report l-1

signed main()
{

      run;

/*
open for mod factorial

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

      }
*/

/*
  for sieve open this and use v_prime

          int pp=pow(10,6)+100000;
               Sieve(pp);
*/

 // factor(n)  &&   USE v_factor For calculating factors && don't forget v_factor.clear();

int  t=1;
//cin>>t;
while(t--)
{
             //  map<int,int>mm; // it->second-->frequency

             int  n,i,x,y,ok=0,sum=0,ans=0,j,k,cnt=0,m,c=0;
             int  h[100009]={0};

                  cin>>n;

                 string s1,s2;cin>>s1>>s2;
                 vector<int>v1,v2;
                 for(i=0;i<n;i++)
                 {
                     if(s1[i]=='0')
                     {
                         v1.pb(i);
                     }
                     if(s2[i]=='0')
                     {
                         v2.pb(i);
                     }
                 }

                 if(v1.size()!=v2.size())
                 {
                     ans=-1;

                 }
                 else
                 {
                     for(i=0;i<v1.size();i++)
                     {
                         if(v1[i]!=v2[i])
                           ans++;
                     }
                 }

                 cout<<ans<<endl;

}
}

#include <bits/stdc++.h>
using namespace  std;
#define f(i,n) 		for(i=0;i<n;i++)
#define fr(i,n,a) 	for(i=n;i>=a;i--)
#define fa(i,a,n) 	for(i=a;i<n;i++)
#define deb(x)		cout<<#x<<" "<<x<<endl;
#define deb2(x,y)	cout<<#x<<","<<#y<<" "<<x<<","<<y<<endl;
#define buf(x)		cout<<"Check"<<x<<endl;
#define ll			long long int
#define ft			first
#define s			second
#define pb			push_back
#define mp			make_pair
#define do			double
#define all(v)		v.begin(),v.end()
#define et(v)		for(auto itr:v)
#define mod			1000000007
inline void p(vector<ll> x,int n)	{	int i;f(i,n)cout<<x[i]<<" ";cout<<endl; }

void solve()
{
	ll N,M,i,j,sum=1,pos,neg=0,z=0;
	ll x,y,k;
	cin>>N;
	string s;
	cin>>s;
	vector<ll> arr(N);
	f(i,N)
	{
		if(s[i]=='A')
			arr[i]=1;
		else if(s[i]=='T')
			arr[i]=-1;
		else if(s[i]=='G')
			arr[i]=10000;
		else
		{
			arr[i]=-10000;
		}

	}

	map<ll,ll> p;
    ll res = 0;
    ll curr = 0;

    f(i,N)
	{

        curr += arr[i];

        if (curr == 0)
            res++;

        if (p.find(curr) != p.end())
            res += (p[curr]);

        p[curr]++;
    }

	cout<<res;
}

int main()
{	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
	ll t=1,c=1;
	//cin>>t;
	while(t--)
	{

		//cout<<"Case #"<<c++<<": "<<endl;
		solve();
		cout<<"\n";

	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct Node {
    int v;
    ll T, K;
    ll t = LLONG_MAX;
    Node(int v, ll T, ll K) : v(v), T(T), K(K) {}
};
struct Data {
    int v;
    ll t = LLONG_MAX;
    Data(int v, ll t) : v(v), t(t) {}
    bool operator < (const Data &d) const {
        return d.t < t;
    }
};
int main() {
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;
    X--;
    Y--;
    int A[M], B[M];
    ll T[M], K[M];
    vector<Node> adj[N];
    for (int i = 0; i < M; i++) {
        cin >> A[i] >> B[i] >> T[i] >> K[i];
        A[i]--;
        B[i]--;
        adj[A[i]].push_back(Node(B[i], T[i], K[i]));
        adj[B[i]].push_back(Node(A[i], T[i], K[i]));
    }
    ll d[N];
    fill(d, d + N, LLONG_MAX);
    d[X] = 0;
    priority_queue<Data> pq;
    pq.push(Data(X, 0));
    bool vis[N] = {};
    while (!pq.empty()) {
        int v = pq.top().v;
        pq.pop();
        if (vis[v]) continue;
        vis[v] = true;
        for (Node i : adj[v]) {
            ll t = i.K * ((d[v] + i.K - 1) / i.K) + i.T;
            if (t < d[i.v]) {
                d[i.v] = t;
                pq.push(Data(i.v, t));
            }
        }
    }
    if (d[Y] == LLONG_MAX) {
        cout << "-1\n";
    } else {
        cout << d[Y] << "\n";
    }
    return 0;
}

#include "bits/stdc++.h"
#define ll long long
#define chl_jldi ios_base::sync_with_stdio(false); cin.tie(0)
#define mnpqll priority_queue<long long, vector<long long>, greater<long long> >
#define mxpqll priority_queue<long long>
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define ff first
#define ss second
#define uset unordered_set
#define pnl cout<<"\n"
#define isodd(xz2) (xz2&1)
#define umap unordered_map
using namespace std;
ll add_mod(ll a,ll b,ll m){return ((((a%m)+(b%m))%m + m)%m);}
ll subs_mod(ll a,ll b,ll m){return ((((a%m)-(b%m))%m + m)%m);}
ll mult_mod(ll a,ll b,ll m){return ((((a%m)*(b%m))%m + m)%m);}
ll power(ll x, ll y){ ll res = 1; while (y > 0) { if (y & 1)res = res * x; y = y >> 1; x = x * x;}return res;}
ll power_mod(ll x, ll y,ll mod){ ll res = 1; while (y > 0) { if (y & 1) res = mult_mod(res, x,mod); y = y >> 1; x = mult_mod(x,x,mod);}return res;}
ll test=1;
const ll mod=1000000007;
void test_case(){             //  cin>>test;
}
//================================================================================================================================================================//

void solve(){
//cout<<"error";

ll a,b,c,d;
cin>>a>>b>>c>>d;

ll red=0;
ll blue=a;
ll ans=0;
while(ans<=(a)){

    if(d*red>=blue) {cout<<ans<<"\n"; return;}
     blue+=b;
    red+=c;
    ans++;
}

cout<<"-1\n";

//cout<<"error";
return;}

int main(){
    chl_jldi;

#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    freopen("error.txt","w",stderr);
#endif
test_case();
ll koko=1;
while(koko<=test){
                    //    cout<<"Case #"<<koko<<": ";
solve();
                    // pnl;

koko++;
}return 0;}


#include <bits/stdc++.h>
using namespace std;
// #include <atcoder/all>
// using namespace atcoder
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<long long>;
using vvl = vector<vector<long long>>;
#define rep(i, s, n) for (int i = (int)s; i < (int)n; i++)
#define repr(i, n, s) for (int i = (int)n; (int)s < i; i--)
#define len(a) (int)a.size()
#define all(a) a.begin(), a.end()
/* 1次元ベクトルをスペースでつなぎ、改行をつけて出力 vi, vl, list<int>, list<ll>に対応  */
template<class T> void print_elements(T a) {string str = ""; for (auto itr = a.begin(); itr != a.end(); ++itr) \
        {str += to_string(*itr) + ' ';} str.pop_back(); cout << str << endl;}

const int INF32 = 1 << 29;
const long long INF64 = 1LL << 60;
const long long MOD = 1000000009;
const double PI = acos(-1);

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

    double ans = 0.0;

    rep(k, 1, N) {
        ans += 1.0 * N / (N - k);
    }
    cout <<fixed << setprecision(11) <<  ans << endl;
}

#include<bits/stdc++.h>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;
typedef long long int lli;
typedef vector<int> vi;
typedef vector<long long int> vlli;
typedef pair<int,int> pii;
typedef pair<long long int,long long int> plli;
typedef vector< vi > vvi ;
typedef vector< vlli > vvlli  ;
#define fi(i,a,b) for(int i=a;i<=b;i++)
#define flli(i,a,b) for(long long int i=a;i<=b;i++)
#define bi(i,a,b) for(int i=a;i>=b;i--)
#define blli(i,a,b) for(long long int i=a;i>=b;i--)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define pi 2*acos(0.0)
#define pb push_back
#define tr(v,it) for(decltype(v.begin()) it=v.begin();it!=v.end();it++)
#define present(v,num) (v.find(num)!=v.end())
#define cpresent(v,num) (find(v.begin(),v.end(),num)!=v.end())
#define pq priority_queue
#define mp make_pair
const int inf=INT_MAX;
const lli INF =LLONG_MAX;
const lli mod = 1e9+7;
int main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    fast;
    string s;cin>>s;
    deque<char> a;
    bool flag=true;
    lli n=sz(s);
    flli(i,0,n-1)
    {
    	if(s[i]=='R')
    	{
    		flag=flag^true;
    	}
    	else
    	{
    		if(flag)
    		{
    			if(a.empty())
    			{
    				a.push_back(s[i]);
    				continue;
    			}
    			auto vari=a.rbegin();
    			if(*vari!=s[i])
    				a.push_back(s[i]);
    			else a.pop_back();
    		}
    		else
    		{
    			if(a.empty())
    			{
    				a.push_front(s[i]);
    				continue;
    			}
    			auto vari=a.begin();
    			if(*vari!=s[i])
    				a.push_front(s[i]);
    			else a.pop_front();
    		}
    	}
    }
    string t;
    while(!a.empty())
    {
    	auto vari=a.begin();
    	t.pb(*vari);
    	a.pop_front();
    }
    if(!flag)reverse(all(t));
    tr(t,it)cout<<*it;
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}


#include <bits/stdc++.h>

#define clr(x) memset((x), 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define For(i, st, en) for(int i=(st); i<=(int)(en); i++)
#define Ford(i, st, en) for(int i=(st); i>=(int)(en); i--)
#define forn(i,m,n) for(int i=m; i<(int)(n); i++)
#define forn2(i, n) for(int i=0; i<=(int)(n); i++)
#define ford(i, n) for(int i=(n)-1; i>=0; i--)
#define fori(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define in(x) int (x); input((x));
#define x first
#define y second
#define less(a,b) ((a) < (b) - EPS)
#define more(a,b) ((a) > (b) + EPS)
#define eq(a,b) (fabs((a) - (b)) < EPS)
#define remax(a, b) ((a) = (b) > (a) ? (b) : (a))
#define remin(a, b) ((a) = (b) < (a) ? (b) : (a))
#define salfinal(x) cout<<x<<endl;
using namespace std;
const int MAX =1e5+1;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    /*
	freopen("s.txt","r",stdin);
	freopen("sa.txt","w",stdout);
    */
    int ent,remover;
    cin>>ent>>remover;
    vector<int>v(ent);
    for(int &i:v)cin>>i;
    if(v[0]!=remover)cout<<v[0];
    forn(i,1,ent)if(v[i]!=remover)cout<<" "<<v[i];
    cout<<"\n";
    return 0;
}

#include<bits/stdc++.h>
#define ll long long int
#define pragi(a,b) for(ll i = a;i<b;i++)
#define pragj(a,b) for(ll j = a;j<b;j++)
#define pragk(a,b) for(ll k = a;k>=b;k--)
#define all(v) (v.begin(),v.end())
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define MP make_pair
#define MT make_tuple
#define F first
#define S second
#define KAKA ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int mod = 1e9 + 9;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef long double ld;
typedef pair<int, int> pii;
//typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef pair<ll, ll> pll;

int main()
{
  KAKA
  ll n;
  cin>>n;
  vector<ll> a(n),b(n);
  pragi(0,n)
  {
    cin>>a[i];
  }
  pragi(0,n)
  {
    cin>>b[i];
  }
  ll sum = 0;
  pragi(0,n)
  {
    sum += (a[i] * b[i]);
  }
  if(sum == 0) cout<<"Yes"<<"\n";
  else cout<<"No"<<"\n";
}


//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <map>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <queue>

using namespace std;

#define rep(i,n) for (int i = 0; i < (n); i++)
#define vi vector<int>
#define vll vector<long long>
#define vb vector<bool>
#define vs vector<string>
#define all(x) x.begin() , x.end()
#define pb push_back
#define eb emplace_back
#define chmax(x,y) (x) = max((x) , (y))
#define chmin(x,y) (x) = min((x) , (y))
#define fi first
#define se second

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

//const int MOD = int(1e9) + 7;
//const int MOD = 998244353;
//const ll MOD = ll(1e9) + 7;
const ll MOD = 998244353;
const ld PI = 3.1415926535897932384626;
const int INF = 1001001001;
const ll LINF = 1001001001001001001;
const int MX = 220000;

ll modpow (ll x , ll p) {
    ll ret = 1;
    while (p) {
        if (p % 2 == 1) {
            ret *= x;
            ret %= MOD;
        }
        x *= x;
        x %= MOD;
        p /= 2;
    }
    return ret;
}

vll fact(MX);
vll factinv(MX);
void init_fact () {
    fact[0] = 1;
    for (int i = 1; i < MX; i++) {
        fact[i] = 1LL * i * fact[i - 1] % MOD;
    }
    for (int i = 0; i < MX; i++) {
        factinv[i] = modpow(fact[i] , MOD - 2);
    }
}

bool is_prime (int x) {
    if (x == 2 || x == 3 || x == 5 || x == 7) {
        return true;
    }
    for (ll i = 2; i*i <= x; i++) {
        if (x % i == 0) {
            return false;
        }
    }
    return true;
}

vb prime_table(MX , true);
void init_prime() {
    for (int i = 2; i < MX; i++) {
        for (int j = i + i; j < MX; j += i) {
            prime_table[j] = false;
        }
    }
    return;
}

vector<int> factrization(ll x) {
    vector<int> ret;
    for (int i = 2; i*i <= x; i++) {
        while (x % i == 0) {
            ret.pb(i);
            x /= i;
        }
    }
    if (x > 1) ret.pb(x);
    sort(all(ret));
    return ret;
}

ll moddiv (ll a , ll b) { return a * modpow(b , MOD - 2) % MOD; }
ll modsub (ll a , ll b) { if (a >= b) return (a - b) % MOD; else return (MOD - a + b); }
ll nCk (ll n , ll k) { return ((fact[n] * factinv[k] % MOD) * factinv[n - k] % MOD); }
ll nHk (ll n , ll k) { return nCk(n - 1 + k , k); } // 仕切り- 1 + boll を並べる組み合わせ
ll gcd (ll a , ll b) { if (a < b) swap(a , b); if (a % b == 0) return b; else return gcd(b , a % b); }
ll lcm (ll a , ll b) { return a / gcd(a , b) * b; }
ll lin() { ll x; scanf("%lld" , &x); return x; }
int in() { int x; scanf("%d" , &x); return x; }
bool is_palindrome (string s) { string t = s; reverse(all(t)); return (s == t); }
void io_setup() { cout << fixed << setprecision(20); }

void solve () {
    ll a , b;
    cin >> a >> b;
    ll ans = 1;
    for (int i = 1; i <= b; i++) {
        ll x = (a + i - 1) / i;
        if (a <= i * x && i * (x + 1) <= b) {
            chmax(ans , (ll)i);
        }
    }
    cout << ans << endl;
    return;
}

int main() {
    io_setup();
    //init_fact();
    //init_prime();
    solve();
    return 0;
}

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

int main(){
    int A,B;
    cin >> A >> B;
    if(A*2<=B){
        cout << B/2 << endl;
    }else{
        int res = B-A;
        for(int i=res;i>=1;i--){
            if(B%i==0&&A%i==0){
                res = i;
                break;
            }
            else if(A%i==0&&B/i==A/i+1){
                res = i;
                break;
            }
            else{
                if(B/i-2==A/i){
                    res = i;
                    break;
                }
            }
        }
        cout << res << endl;
    }
}


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

#define arrsize 100001
#define dpsize 1001
#define vpp vector<PP>
#define vll vector<ll>
#define vcc vector<char>
#define endl "\n"
#define vbb vector<bool>
#define w(t) while(t--)
#define PP pair<ll,ll>
#define test(x) ll t; cin>>t; w(t) x()
#define __lb lower_bound
#define __ub upper_bound
#define szs(x) x.length()
#define szv(x) x.size()
#define INF 1999999996000000010
#define takeINP(arr,n) for(long long i=0;i<n;i++) cin>>arr[i];
#define f(i,s,e) for(long long i=s;i<e;i++)
#define ef(i,s,e) for(long long i=s;i<=e;i++)
#define rf(i,e,s) for(long long i=e-1;i>=s;i--)
#define mem(arr) memset(arr,-1,sizeof(arr));
#define rsz(x,n) x.resize(n)
#define rsr(x,n) x.reserve(n)
#define float long long double
#define pb push_back
#define print(arr,s,e) f(i,s,e) cout<<arr[i]<<" "; cout<<endl;
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define vll vector<ll>
#define triplet pair<ll,pair<ll,ll> >
#define MITR(a,b) map<a,b>::reverse_iterator

lli M=1000000007;
lli mod(lli a) { return ((a%M+M)%M);}
lli add(lli a,lli b) { return mod(mod(a)+mod(b));}
lli multiply(lli a,lli b) { return mod(mod(a)*mod(b));}
lli min(lli a,lli b) { if(a<b) return a; return b;}
lli max(lli a,lli b) { return (a>b)?a:b;}
lli modexpo(lli a,lli b){
    lli res = 1;
    while(b>0){
    	if(b&1) res = (res*a)%M;
    	a = (a*a)%M;
    	b/=2;
    }
    return res;
}
lli mulmod(lli a, lli b, lli mod)
{
    lli res = 0; // Initialize result
    a = a % mod;
    while (b > 0)
    {
        // If b is odd, add 'a' to result
        if (b % 2 == 1)
            res = (res + a) % mod;

        // Multiply 'a' with 2
        a = (a * 2) % mod;

        // Divide b by 2
        b /= 2;
    }

    // Return result
    return res % mod;
}

lli binPower(lli a , lli n , lli mod)
{
	lli res = 1;

	while(n)
	{
		if(n & 1)
		res = mulmod(res , a , mod);

		n >>= 1;
		a = mulmod(a , a , mod);
	}

	return res % mod;
}
class Line{
  public:
  double slope;
  double c;
  Line(double slope=0,double c=0){
    this->slope=slope;
    this->c=c;
  }
};
int divisor[1000005];

void solve(){
    ll n,k;
    cin>>n>>k;
    vll arr(n);
    map<ll,ll> map;
    ll maxe=0;
    f(i,0,n) cin>>arr[i],map[arr[i]]++,maxe=max(maxe,arr[i]);
    sort(all(arr));
    ll ans=0;
    ll ls=0;
    for(ll i=0;i<maxe+1;i++){
        // cout<<i<<":"<<map[i]<<" ";
        if(map[i]<k){
            ans+=(k-map[i])*i;
            // cout<<e.first<<" ";
            k=map[i];
        }
        ls=i+1;
    }
    if(k>0){
        ans+=k*ls;
    }
    cout<<ans<<"\n";

}
int main(){
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    solve();
    // sieve();
    // int t;
    // cin>>t;
    // while(t--) solve();
    return 0;
}

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

#include <queue>

using namespace std;

typedef pair<int,int> ii;

int fr[300010];

int main(){

	cin.tie(0); ios_base::sync_with_stdio(0);
	int n,k;

	cin>>n>>k;

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

	int it=0;
	while(k){
		k = min(k,fr[it]);
		it++;
		res+=k;
	}
	cout<<res<<endl;

	return 0;
}


#include <bits/stdc++.h>
namespace IO{
    char buf[1000000],*p1,*p2;
    inline char getc(){
        if(p1==p2) p2=(p1=buf)+fread(buf,1,10,stdin);
        return p1==p2?EOF:*(p1++);
    }
    template<typename tp>inline void r(tp &n){
        n=0;char c=getc();int f=1;
        while(!isdigit(c)&&c!='-') c=getc();
        if(c=='-') f=-1,c=getc();
        while( isdigit(c)) n=n*10+c-48,c=getc();
        n*=f;
    }
    template<typename tp>inline void w(tp  n){
        if(n/10) w(n/10);
        putchar(n%10+48);
    }
};
using namespace IO;
const int N=2e5+5,M=2e5+5;
using namespace std;
int n,m,num;
int vis[N],head[N],nt[M<<1],to[M<<1];
long long a[N],b[N],tota,totb;
void Add(int x,int y){
    ++num;nt[num]=head[x];head[x]=num;to[num]=y;
    ++num;nt[num]=head[y];head[y]=num;to[num]=x;
}
void DFS(int p){
    vis[p]=1;tota+=a[p],totb+=b[p];
    for(int i=head[p];i;i=nt[i])
        if(!vis[to[i]]) DFS(to[i]);
}
int main(){

    //freopen("1.in","r",stdin);

    r(n),r(m);
    for(int i=1;i<=n;++i) r(a[i]);
    for(int i=1;i<=n;++i) r(b[i]);
    for(int i=1,x,y;i<=m;++i)
        r(x),r(y),Add(x,y);
    for(int i=1;i<=n;++i){
        if(vis[i]) continue;
        tota=0;totb=0;DFS(i);
        if(tota!=totb)
            puts("No"),exit(0);
    }
    puts("Yes");
    return 0;
}

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

ll sum[200005];

struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) {}
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0)
            return x;
        else
            return par[x] = root(par[x]);
    }

    bool issame(int x, int y) { return root(x) == root(y); }

    bool merge(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);  // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) { return -par[root(x)]; }
};

int main() {
    long long N, M;
    cin >> N >> M;
    vector<ll> A(N), B(N);
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];
    vector<int> C(M), D(M);
    for (int i = 0; i < M; ++i) {
        cin >> C[i];
        cin >> D[i];
        --C[i], --D[i];
    }

    rep(i, N) sum[i] = 0;

    UnionFind uf(N);
    rep(i, M) { uf.merge(C[i], D[i]); }

    rep(i, N) {
        int root_i = uf.root(i);
        if (root_i < 0)
            sum[i] += B[i] - A[i];
        else
            sum[root_i] += B[i] - A[i];
    }

    rep(i, N) {
        if (sum[i] != 0) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
//#include <random>
#include <map>
//#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <time.h>
//#include <chrono>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <limits>
#include <numeric>
//#include <type_traits>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define MOD 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define REVERSE(s) reverse(s.begin(), s.end());
#define SUM(s) accumulate(s.begin(), s.end(), 0LL);
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
//#define int ll
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int ndx[8] = { 0,1,0,-1, 1,1,-1,-1 };
int ndy[8] = { 1,0,-1,0, 1,-1,-1,1 };
double pi = 3.141592653589793;
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }

int main() {
	ll n;
	cin >> n;
	int sq = sqrt(n);
	vector<ll> ans;
	FOR(i, 1, sq + 1) {
		if (n % i == 0) {
			ll x = n / i;
			if (x == i) {
				ans.push_back(i);
			}
			else if (x < i) {

			}
			else {
				ans.push_back(i);
				ans.push_back(x);
			}
		}
	}
	SORT(ans);
	rep(i, ans.size()) {
		cout << ans[i] << endl;
	}
}

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

    typedef long long ll;
    const char nl = '\n';

    template <class T>
    ostream &operator <<(ostream &os, const vector<T>&v)
    {
        for(auto& x:v)os << x << " ";
        return os;
    }

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

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

    int main()
    {
        ll n,i;
        vector<ll>v;
        cin >> n;
        for(i=1 ; i*i<=n ; i++)
        {
            if(n%i==0)
            {
                if(i*i==n)v.pb(i);
                else
                {
                    v.pb(i);
                    v.pb(n/i);
                }
            }
        }
        sort(all(v));
        for(auto x:v)
            cout << x << nl;
        return 0;
    }