#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#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 MOD 1000000007

int main() {
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i, n) {
        cin >> s[i];
    }
    ll b = 1, f = 1;
    rep(i, n) {
        if (s[i] == "AND") {
            f = b + 2 * f;
        } else {
            b = 2 * b + f;
        }
    }
    cout << b << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>
#define pll pair<ll,ll>
#define forA(i,a,n,x) for(ll i=a;i<n;i+=x)
#define forD(i,a,n,x) for(ll i=n-1;i>=a;i-=x)
#define ranit(it,n) for(auto it:n)
#define testCases ll t;cin>>t;while(t--)
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define init(a,x) memset(a,x,sizeof(a))

string s[61];
ll dp[102][2];

ll solve(ll n, bool val)
{
	if(n==0)return 1;

	if(dp[n][val]!=-1)return dp[n][val];

	if(s[n-1]=="OR")
	{
		if(val)return dp[n][val]= solve(n-1,false)+ 2*solve(n-1,true);
		else return dp[n][val]= solve(n-1,false);
	}
	else
	{
		if(val)return dp[n][val]= solve(n-1,true);
		else return dp[n][val]= 2*solve(n-1,false)+solve(n-1,true);
	}
}

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

	ll n; cin>>n;
	init(dp,-1);
	forA(i,0,n,1)cin>>s[i];
	cout<<solve(n,true);
	return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define po pop_back
#define mp make_pair
#define fi first
#define se  second
#define hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define MOD 1000000007
using namespace std;
bool comp(ll a,ll b){if(a>b)return true;else return false;}
int isP(ll n){if(n==1)return 0;if(n==2 || n==3)return 1;for(ll i=2;i<=sqrt(n);i++){if(n%i==0)return 0;}return 1;}
ll power(ll a,ll b){if(b==0)return 1;if(b==1) return a;ll t=power(a,b/2);if(b%2==1) return t*t*a;else return t*t;}
ll powMOD(ll x,ll y){if(y==0)return 1;if(y==1)return x;ll t=powMOD(x,y/2);if(y%2==1)return t*t%MOD*x%MOD;else return t*t%MOD;}

int main()
{
    /*//----Hello World----//*/
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    hello;

    ll t;
//    cin>>t;
    t=1;
    while(t--){
    	ll a,b,c;
    	cin>>a>>b>>c;
    	bool foo=1;
    	if(c==0){
    		if(a<=b) foo=0;
		}
		else{
			if(a<b) foo=0;
		}
		if(foo) cout<<"Takahashi\n";
		else cout<<"Aoki\n";
	}

	/*//----Hello World----//*/
    return 0;
}

#include "bits/stdc++.h"
using namespace std;
#include "string"
#define int long long
#define pi pair <int, int>
#define ff first
#define ss second
#define boost ios::sync_with_stdio(false);cin.tie(nullptr)
#define endl '\n'
#define vi vector<int>

int32_t main() {
	boost;
	int n, m, t;
	cin >> n >> m >> t;
	int cur = n;
	int pre = 0;
	string ans = "Yes";
	for(int i = 0, x, y; i < m; i++) {
		cin >> x >> y;
		cur -= (x - pre);
		if(cur <= 0) {
			ans = "No";
			break;
		}
		cur = min(n, cur + y - x);
		pre = y;
	}
	cur -=(t - pre);
	if(cur <= 0)
		ans = "No";
	cout << ans << endl;
}


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

#define Mod(x) (x>=P&&(x-=P))
#define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;++i)
#define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;--i)
#define erep(i,a) for(int i=hd[a];i;i=nxt[i])

typedef long long ll;
inline void Max(int &x,int y){(x<y)&&(x=y);}
inline void Min(int &x,int y){(x>y)&&(x=y);}

bool let;
char IO;
inline int rd(int res=0){
	bool f=0;
	while(IO=getchar(),IO<48||IO>57)
		f|=IO=='-';
	do res=(res<<1)+(res<<3)+(IO^48);
	while(IO=getchar(),isdigit(IO));
	return f?-res:res;
}
const int M=1005;
struct node{
	int w,v;
	bool operator <(const node &_)const{
		return w<_.w;
	}
}p[M];
int s[M],t[M];
priority_queue<int>que;
bool vio;
int main(){
	cerr<<(&vio-&let)/1024.0/1024<<endl;
	int n=rd(),m=rd(),q=rd();
	rep(i,1,n)p[i].w=rd(),p[i].v=rd();
	rep(i,1,m)s[i]=rd();
	sort(p+1,p+n+1);
	while(q--){
		int l=rd(),r=rd(),tot=0;
		rep(i,1,l-1)t[++tot]=s[i];
		rep(i,r+1,m)t[++tot]=s[i];
		sort(t+1,t+tot+1);
		int ans=0,pos=1;
		while(!que.empty())que.pop();
		rep(i,1,tot){
			while(pos<=n&&p[pos].w<=t[i])
				que.push(p[pos++].v);
			if(!que.empty())
				ans+=que.top(),que.pop();
		}
		printf("%d\n",ans);
	}
}

#include <bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//#include <atcoder/all>
using namespace std;
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a; i > -1; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a; i > b; --i)
#define repl(i, a) for (ll i = (ll)0; i < (ll)a; ++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll
#define fi first
#define se second
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll mod_998244353 = 998244353;
constexpr ll INF = 1LL << 60;

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

// using lll=boost::multiprecision::cpp_int;
// using
// Double=boost::multiprecision::number<boost::multiprecision::cpp_dec_float<128>>;//仮数部が1024桁
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;
}

ll mypow(ll x, ll n, const ll &p = -1)
{ // x^nをmodで割った余り

  if (p != -1)
  {
    x = (x % p + p) % p;
  }
  ll ret = 1;
  while (n > 0)
  {
    if (n & 1)
    {
      if (p != -1)
        ret = (ret * x) % p;
      else
        ret *= x;
    }
    if (p != -1)
      x = (x * x) % p;
    else
      x *= x;
    n >>= 1;
  }
  return ret;
}

struct myrand{
  random_device seed;
  mt19937 mt;
  myrand():mt(seed()){}
  int operator()(int a,int b){//[a,b)
    uniform_int_distribution<int>dist(a,b-1);
    return dist(mt);
  }
};

//using namespace atcoder;

//------------------------
//------------------------
//------------------------
//------------------------
//------------------------

void solve()
{
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	if(c*d-b>0){
		ll ans=(a+c*d-b-1)/(c*d-b);
		cout<<ans;
	}else{
		cout<<-1;
	}
}

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


#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
#define setIO(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)
#define closefile fclose(stdin), fclose(stdout)
#define m_p make_pair
#define sz(x) (int)x.size()
#define see(x) cerr << x << " "
#define seeln(x) cerr << x << endl
#define out(x) cerr << #x << " = " << x << " "
#define outln(x) cerr << #x << " = " << x << endl
#define outarr(x, l, r) {cerr<< #x"[" << l << " ~ " << r << "] = "; for (int _i = l; _i <= r; ++_i) cerr << x[_i] << " "; cerr << endl;}
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
#define gc() getchar()
//#define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
char buf[1 << 21], *p1 = buf, *p2 = buf;
template <class T> void read(T &x)
{
    x = 0; int c = gc(); int flag = 0;
    while (c < '0' || c > '9') flag |= (c == '-'), c = gc();
    while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) +(c ^ 48), c = gc();
    if (flag) x = -x;
}
template <class T> T _max(T a, T b){return b < a ? a : b;}
template <class T> T _min(T a, T b){return a < b ? a : b;}
template <class T> bool checkmax(T &a, T b){return a < b ? a = b, 1 : 0;}
template <class T> bool checkmin(T &a, T b){return b < a ? a = b, 1 : 0;}
const int mod = 998244353, N = (1 << 20) + 1;
int fac[200005], ifac[200005], inv[200005];
#define Mul(a,b) (ll)(a) * (b) % mod
#define mul(a,b) (a) = (ll)(a) * (b) % mod
int Add(int x, int y) {x += y; return x >= mod ? x - mod : x;}
int Sub(int x, int y) {x -= y; return x < 0 ? x + mod : x;}
void add(int &a, int b) {a += b; if (a >= mod) a -= mod;}
void sub(int &a, int b) {a -= b; if (a < 0) a += mod;}
int qpow(int a, int b)
{
    int ans = 1;
    while (b)
	{
		if (b & 1) mul(ans, a);
		mul(a, a);
		b >>= 1;
	}
    return ans;
}
int binom(int x, int y){return x < y ? 0 : Mul(fac[x], Mul(ifac[y], ifac[x - y]));}
int n, m, k;
void init()
{
	read(n); read(m); read(k);
}

int calc(int lim, int l)
{
	return Sub(qpow(lim, l), qpow(lim - 1, l));
}

int calc2(int lim, int l)
{
	return qpow(lim, l);
}

void solve()
{
	if (n == 1 || m == 1)
	{
		printf("%d\n", qpow(k, m * n));
		return;
	}
	int ans = 0;
	for (int i = 1; i <= k; ++i)
	{
		add(ans, Mul(calc(i, n), calc2(k - i + 1, m)));
	}
	printf("%d\n", ans);
}

int main()
{
	init();
	solve();
    return 0;
}

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

#define INF 998244353

long long Pow (long long a, long long b) {
	a %= INF;

	long long ans = 1;

	while (b > 0) {
		if (b & 1) {
			ans *= a;
			ans %= INF;
		}
		a *= a;
		a %= INF;
		b >>= 1;
	}

	return ans;
}
int main () {
	int n, m, k;

	scanf ("%d %d %d", &n, &m, &k);
	if (n == 1 && m == 1) {
		printf ("%d", k);

		return 0;
	}
	else if (n == 1) {
		printf ("%lld", Pow (k, m));

		return 0;
	}
	else if (m == 1) {
		printf ("%lld", Pow (k, n));

		return 0;
	}
	long long ans = 0;

	for (int i = 1; i <= k; i ++) {
		ans += Pow (i, n) * ((Pow (k - i + 1, m) - Pow (k - i, m)) % INF) % INF;
		ans %= INF;
		ans += INF;
		ans %= INF;
	}
	printf ("%lld", ans);
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define rep(i, n) FOR(i,0,n)
#define irep(i, n) IFOR(i,0,n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;

using namespace std;

int main() {
    char s, t;
    cin >> s;
    cin >> t;
    if (s == 'Y') {
        cout << (char)toupper(t) << endl;
    }
    else {
        cout << t << endl;
    }

    return 0;
}

#include<iostream>
#include<cstring>
#include<cstdio>
#include<climits>
#include<algorithm>
#include<queue>
#include<vector>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
inline int read(){
	int f=1,ans=0; char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();}
	return f*ans;
}
const int MAXN=1e5+11;
int f[MAXN],N,Ma[28]; char S[MAXN];
int main(){
	//freopen("10.in","r",stdin);
	N=read();
	scanf("%s",S+1);
	memset(Ma,127/3,sizeof(Ma)); memset(f,127/3,sizeof(f));
	Ma[S[1]-'a']=0;
	for(int i=1;i<=N;i++){
		for(int j=0;j<27;j++) if(j!=S[i]-'a') f[i]=min(f[i],Ma[j]+1);
		Ma[S[i+1]-'a']=min(Ma[S[i+1]-'a'],f[i]);
	}
	if(f[N]<=N) printf("%d\n",f[N]); else printf("-1\n");
	return 0;
}


#include <iostream>
#include <vector>
#include<string>
#include <set>
#include <cstdlib>
#include <map>
#include <cmath>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <ctype.h>
using namespace std;

int main()
{
    int H;
    int W;
    int X;
    int Y;
    cin >> H >> W >> X >> Y;
	X--;
	Y--;

	vector<std::string>S(H);
	int result = 1;
	for(int i = 0;i<H;i++){
		cin >> S[i];
	}

	for(int i = Y + 1;i<W && S[X][i] != '#';i++){
		result++;
	}
	for(int i = Y - 1;i>=0 && S[X][i] != '#';i--){
		result++;
	}
	for(int i = X + 1;i<H && S[i][Y] != '#';i++){
		result++;
	}
	for(int i = X - 1;i>=0 && S[i][Y] != '#';i--){
		result++;
	}

    cout << result << endl;
	return 0;
}

#include <bits/stdc++.h>

#define rep(i, a, b) for (int i = a; i < b; i++)
#define repvec(i, v) for (int i = 0; i < v.size(); i++)
#define vecall(v) (v).begin(), (v).end()
#define input(t, ...) \
  t __VA_ARGS__;      \
  in(__VA_ARGS__)
#define invec(t, v, n) \
  vector<t> v(n);      \
  for (int index = 0; index < n; index++) cin >> v[index];
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
inline void in(void) { return; }
template <typename First, typename... Rest>
void in(First& first, Rest&... rest) {
  cin >> first;
  in(rest...);
  return;
}
inline void out(void) { return; }
template <typename First, typename... Rest>
void out(First first, Rest... rest) {
  cout << " " << first;
  out(rest...);
  return;
}
const double Pi = acos(-1);

int main() {
  input(int, h, w, x, y);
  x--;
  y--;
  int ans = 1;
  vector<vector<int>> mapp(h, vector<int>(w, 0));
  rep(i, 0, h) {
    rep(j, 0, w) {
      input(char, s);
      if (s == '#') mapp[i][j] = 1;
    }
  }
  rep(i, 1, 100){
    if(x - i < 0) break;
    else if(mapp[x - i][y] == 0) ans++;
    else break;
  }
  rep(i, 1, 100){
    if(x + i >= h) break;
    else if(mapp[x + i][y] == 0) ans++;
    else break;
  }
  rep(i, 1, 100){
    if(y - i < 0) break;
    else if(mapp[x][y - i] == 0) ans++;
    else break;
  }
  rep(i, 1, 100){
    if(y + i >= w) break;
    else if(mapp[x][y + i] == 0) ans++;
    else break;
  }
  out(ans);
}


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

int main(){
  int N = 0;
  vector<double> UFO(2);

  cin >> N;

  for (double &x : UFO){
    cin >> x;
  }

  vector<vector<double>> buildings (N, vector<double> (2));

  for (vector<double> &d : buildings){
    for (double &f : d){
      cin >> f;
    }
  }

  double e = 0;
  double y = 0;

  for (int i = 0; i < N; i++){
    //y = 10 - 10e, y = 5 - 3e
    //10e - 3e = 10 - 5
    e = (UFO.at(1) - buildings.at(i).at(1)) / (UFO.at(0) - buildings.at(i).at(0));
    y = max(y, UFO.at(1) - UFO.at(0) * e);
  }

  cout << setprecision(16) << y << endl;

}

#pragma GCC target("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include<bits/stdc++.h>

#define int ll
#define f			first
#define sz(a)       ((int)(a).size())
#define s			second
#define all(v)		v.begin(),v.end()
#define pii 		pair<int,int>
#define vpii 		vector<pii>
#define eb			emplace_back
#define pb			push_back
#define fo(i,n)		for(int i=0;i<n;i++)
#define Fo(i,k,n)	for(int i=k;i<n;i++)
#define vi			vector<int>

using namespace std;
using ll  = long long;
using lld = long double;

const int oo = 1e13 ;
const ll MOD = 1000000007;
const int N = 18;

int x[N] , y[N] , z[N];
int dp[1LL << N][N];
int DIS[N][N];
int n;
int dis(int from , int to){
	return abs(x[to] - x[from]) + abs(y[to] - y[from]) + max(0LL, z[to] - z[from]);
}
int get_dis(int from , int to){
	return DIS[from][to];
}
int fun(int mask , int src){
	if(__builtin_popcountll(mask) == n)
		return dis(src , 0);
	if(dp[mask][src]!= -1)
		return dp[mask][src];
	int ans = oo;
	for(int i = 1 ; i < n ; i++){
		if((mask >> i) & 1)
			continue;
		ans = min(ans , dis(src , i) + fun(mask | (1 << i) , i));
	}
	return dp[mask][src] = ans;
}

signed main(){

#ifndef ONLINE_JUDGE
	//freopen("in.txt" , "r" , stdin);
#endif
	ios_base::sync_with_stdio(0);cin.tie(0);

	memset(dp , -1 , sizeof dp);

	cin >> n;
	fo(i , n) cin >> x[i] >> y[i] >> z[i];

	fo(i , n) fo(j , n) if(i!=j) DIS[i][j] = oo; else DIS[i][j] = 0;

	cout << fun(1 , 0) << '\n';

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

//#define ONLINE_JUDGE
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define rep(z, x, y) for(int z=x;z<=y;++z)
#define repe(z, x, y) for(int z=x;z<y;++z)
#define repd(z, x, y) for(int z=x;z>=y;--z)
#define repde(z, x, y) for(int z=x;z>y;--z)
#define int long long

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

const int INF = 0x3f3f3f3f;
const double eps = 1e-9;
const int mod = 1e9 + 7;

const int N = 65;

string op[N];

void solve()
{
    int n;
    cin >> n;
    vector<int> p;
    p.push_back(-1);
    rep(i, 1, n)
    {
        cin >> op[i];
        if(op[i] == "AND")
            p.push_back(i);
    }

    p.push_back(n + 1);
    int ans = 0;
    repd(i, p.size() - 1, 1)
    {

        int a = ((int)pow(2ll, p[i] - p[i - 1] - 1) - 1);
        int b = (int)pow(2ll, p[i - 1] + 1);
        ans += a * b;
    }

    cout << ans << endl;

}

signed main()
{
    #ifndef ONLINE_JUDGE
        freopen("IO/in.txt", "r", stdin);
        freopen("IO/out.txt", "w", stdout);
    #endif

    IOS;
    int t;
    solve();
}

#include <iostream>  // cin cout
#include <string>    // string

int main()
{
  int n;
  std::cin >> n;
  unsigned long long res = 1;

  for (int i = 0; i < n; i++)
  {
    std::string x;
    std::cin >> x;
    if (x == "OR")
    {
      res += 1ULL << (i+1);
    }
  }

  std::cout << res;
}


#include <bits/stdc++.h>
#define ALL(a) a.begin(), a.end()
#define ALLR(a) a.rbegin(), a.rend()
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORD(i, a, b) for (int i = (a); i > (b); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPR(i, n) for (int i = (n)-1; i >= 0; i--)
#define SI(a) (int)a.size()
using namespace std;
using ll = long long;
template <class T>
bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
ll llceil(ll a, ll b) { return (a + b - 1) / b; }
ll shift(ll a) { return 1LL << a; }
const int INF = shift(30);
const ll LINF = shift(60);

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  REP(i, n) cin >> a[i];

  ll ans = 0;
  const int max_a = 200;
  vector<int> m(max_a * 2 + 1);
  REP(i, n) {
    FOR(j, -max_a, max_a + 1) {
      ll num = m[j + max_a];
      ll dif = a[i] - j;
      ans += dif * dif * num;
    }
    m[max_a + a[i]]++;
  }
  cout << ans << endl;
}

#include<bits/stdc++.h>
#define int long long
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll mod=1e9+7;
const int N=300010;
int n,ans,a[N],vis[N];
void init(){
	memset(a,0,sizeof(a));
	memset(vis,0,sizeof(vis));
	n=ans=0;
}
void solve(){
	init();
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		ans+=vis[a[i]+200];
		for(int j=0;j<=400;j++){
			vis[j]+=(j-200-a[i])*(j-200-a[i]);
		}
	}
	cout<<ans<<endl;
}
signed main(){
	ios::sync_with_stdio(false);
	cout.tie(NULL);
	int t;
	t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;//完结撒花
}


#include <bits/stdc++.h>

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

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

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

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

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

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

void Main() {
    LCIN(N);
    LCIN(H);
    if(H%N == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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

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

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

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

#define fi first
#define se second
#define pb push_back
#define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,a,b) for(int i = a; i < b; i++)
#define forr(i,a,b) for(int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const ll mod = 1e9+7;
int sum(int a, int b){return (a+b) % mod;}
int sub(int a, int b){return (a + mod - b) % mod;}
int mul(int a, int b){return (1ll * a * b) % mod;}
int power(int a,int b){
	int res = 1;
	while(b){
		if(b&1)res = mul(res,a);
		b >>= 1;
		a = mul(a,a);
	}
	return res;
}

const int maxn = 100+10;
const ll oo = (ll)1e18;
ll X,memo[maxn][maxn][maxn],K;
int A[maxn],N;

ll dp(int pos,int cnt,int sum){
	if(pos >= N){
		if(cnt == 0 && sum == 0)return 0;
		return -oo;
	}
	ll &res = memo[pos][cnt][sum];
	if(res != -1)return res;
	res = dp(pos+1,cnt,sum);
	if(cnt){
		int sum2 = sum-(A[pos]%K);
		if(sum2 < 0)sum2 += K;
		res = max(res,A[pos]+dp(pos+1,cnt-1,sum2));
	}
	return res;
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> N >> X;
	forn(i,0,N)cin >> A[i];
	ll res = X;
	forn(k,1,N+1){
		forn(i,0,N+1)forn(j,0,N+1)forn(l,0,maxn)memo[i][j][l] = -1;
		K = k;
		ll sum = dp(0,k,X%K);
		//debug(k,sum);
		if(sum > 0){
			res = min(res,(X-sum)/K);
		}
	}
	cout << res << '\n';
	return 0;
}
/*
__builtin_mul_overflow(x,y,&x)
-fsplit-stack
*/


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

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

  long long a = 3;
  long long b = 5;
  int ai = 1;
  int bi = 1;

  while(a <= n){
    while(a+b <= n){
      if(a+b == n){
        goto answer;
      }
      if((n-a)%5 != 0){
        break;
      }
      b *= 5;
      bi++;
    }
    b = 5;
    bi = 1;
    a *= 3;
    ai++;
  }
  ai = -1;
  answer:
  if(ai == -1)
    cout << -1 << endl;
  else
    cout << ai << ' ' << bi << endl;

}

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

#define rep(i, a, n) for(int i=(a); i<(n); ++i)
#define per(i, a, n) for(int i=(a); i>(n); --i)
#define pb emplace_back
#define mp make_pair
#define clr(a, b) memset(a, b, sizeof(a))
#define all(x) (x).begin(),(x).end()
#define lowbit(x) (x & -x)
#define fi first
#define se second
#define lson o<<1
#define rson o<<1|1
#define gmid l[o]+r[o]>>1

using LL = long long;
using ULL = unsigned long long;
using pii = pair<int,int>;
using PLL = pair<LL, LL>;
using UI = unsigned int;

const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const double EPS = 1e-7;
const double PI = acos(-1.0);

const int N = 1e5 + 10;

int n;
double a[N];

double cal(double x){
	double ret = 0.0;
	rep(i, 0, n){
		ret += (x + a[i] - min(a[i], 2.0*x));
	}
	return ret / n;
}

int main(){
	scanf("%d", &n);
	rep(i, 0, n)	scanf("%lf", a+i);
	double low = 0.0, top = 1e10, m1, m2, a1, a2, ans = 1e20;

	while(top - low > EPS){
		m1 = low + (top - low) / 3.0;
		m2 = top - (top - low) / 3.0;
		a1 = cal(m1);
		a2 = cal(m2);
		if(a1 >= a2){
			ans = min(ans, a2);
			low = m1 + EPS;
		} else {
			ans = min(ans, a1);
			top = m2 - EPS;
		}
	}
	printf("%.10f\n", ans);
	return 0;
}


#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

struct V
{
    int d,t,k;
};

struct PQ
{
    int p;
    long long int t;

    bool operator < (const PQ x) const
    {
        return t>x.t;
    }
};

vector<V> v[100010];
priority_queue<PQ> pq;
int visit[100010];

int main()
{
    int n,m,x,y;
    int chk=0;

    scanf("%d%d%d%d",&n,&m,&x,&y);
    for(int i=1;i<=m;i++)
    {
        int a,b,c,d;
        scanf("%d%d%d%d",&a,&b,&c,&d);
        v[a].push_back({b,c,d});
        v[b].push_back({a,c,d});
    }
    pq.push({x,0});
    while(!pq.empty())
    {
        auto now=pq.top();
        pq.pop();
        if(visit[now.p]==1) continue;
        visit[now.p]=1;
        if(now.p==y)
        {
            printf("%lld",now.t);
            chk=1;
            break;
        }
        for(auto it : v[now.p])
        {
            if(visit[it.d]==1) continue;
            if(now.t%it.k==0) pq.push({it.d,(long long int)(now.t+it.t)});
            else pq.push({it.d,(long long int)((now.t/it.k+1)*it.k+it.t)});
        }
    }
    if(chk==0) printf("-1");
    return 0;
}

// Artur Kraska, II UWr

#include <bits/stdc++.h>

#define forr(i, n)                  for(int i=0; i<n; i++)
#define FOREACH(iter, coll)         for(auto iter = coll.begin(); iter != coll.end(); ++iter)
#define FOREACHR(iter, coll)        for(auto iter = coll.rbegin(); iter != coll.rend(); ++iter)
#define lbound(P,R,PRED)            ({typeof(P) X=P,RRR=(R), PPP = P; while(PPP<RRR) {X = (PPP+(RRR-PPP)/2); if(PRED) RRR = X; else PPP = X+1;} PPP;})
#define testy()                     int _tests; scanf("%d", &_tests); FOR(_test, 1, _tests)
#define CLEAR(tab)                  memset(tab, 0, sizeof(tab))
#define CONTAIN(el, coll)           (coll.find(el) != coll.end())
#define FOR(i, a, b)                for(int i=a; i<=b; i++)
#define FORD(i, a, b)               for(int i=a; i>=b; i--)
#define MP                          make_pair
#define PB                          push_back
#define ff                          first
#define ss                          second
#define deb(X)                      X;

#define M 1000000007
#define INF 1000000007LL

using namespace std;

int n, m, a, x, y;
priority_queue <pair<long long, int>> pq;

struct droga
{
    int cel;
    int odjazd;
    int czas;
};
droga d;

struct miasto
{
    bool byl;
    vector <droga> l;
};
miasto tab[1000007];

int main()
{
    scanf("%d %d %d %d", &n, &m, &x, &y);
    forr(i, m)
    {
        scanf("%d %d %d %d", &a, &d.cel, &d.czas, &d.odjazd);
        tab[a].l.PB(d);
        swap(a, d.cel);
        tab[a].l.PB(d);
    }
    pq.push(MP(0, x));
    while(!pq.empty())
    {
        int nr = pq.top().ss;
        long long czas = -pq.top().ff;
        pq.pop();
        if(tab[nr].byl)
            continue;
//        cout << "analizuje " << nr << endl;
        tab[nr].byl = 1;
        if(nr == y)
        {
            printf("%lld\n", czas);
            return 0;
        }

        for(auto p : tab[nr].l)
        {
            int nr2 = p.cel;
            long long odj = czas % p.odjazd;
            if(odj == 0)
                odj = czas;
            else
                odj = czas + p.odjazd - odj;
//            cout << " z " << nr << " moze jchac do " << nr2 << ", odjazd o " << odj << ", przyjazd o " << odj + p.czas << endl;
            if(!tab[nr2].byl)
                pq.push(MP(-(odj + p.czas), nr2));
        }
    }
    printf("-1\n");

    return 0;
}


#include <bits/stdc++.h>
#define fir first
#define sec second
#define PB push_back
#define MP make_pair
#define all(a) (a).begin(), (a).end()
#define sz(a) (a).size()

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i < (int)(n); ++i)
#define foreach(itr, c) for (__typeof((c).begin()) itr = (c).begin(); itr != (c).end(); ++itr)

template <class T> void chkmax(T& x, T y) { x = (x > y ? x : y); }
template <class T> void chkmin(T& x, T y) { x = (x < y ? x : y); }

typedef long long LL;
typedef pair <int, int> pii;
typedef vector <int> vi;

const int N = 3e5 + 5;

int n, a[N * 2];

struct Fenwick {
    LL d[N];

    void init(){
        rep1(i, n + 1) d[i] = 0;
    }

    void modify(int x, int val){
        while (x <= n){
            d[x] += val;
            x += x & -x;
        }
    }

    LL query(int x){
        int ret = 0;
        while (x){
            ret += d[x];
            x -= x & -x;
        }
        return ret;
    }
} fenw;

int main(){
    scanf("%d", &n);
    rep(i, n) scanf("%d", &a[i]), a[i]++;
    LL cur = 0;
    rep(i, n){
        cur += i - fenw.query(a[i] - 1);
        fenw.modify(a[i], 1);
    }
    printf("%lld\n", cur);
    rep(i, n - 1){
        a[i + n] = a[i];
        fenw.modify(a[i], -1);
        cur -= a[i] - 1;
        cur += n - a[i];
        printf("%lld\n", cur);
    }
    return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ull unsigned long long
#define ll long long
#define endl '\n'
#define line cout<<"--------------------------"<<endl
#define dd(x) cout<<#x<<" = "<<x<<' '
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define filein freopen("input.txt","r",stdin)
#define fileout freopen("output.txt","w",stdout)
using namespace std;
using namespace __gnu_pbds;
template <typename T> using os=tree < T, null_type ,less<T>, rb_tree_tag,tree_order_statistics_node_update >;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mx=300009;
ll big[mx],small[mx];
int main()
{
    ll n;
    cin>>n;
    vector<ll>v(n);
    for(ll i=0;i<n;i++) cin>>v[i];
    os<ll>s;
    ll ans=0;
    for(ll i=n-1;i>=0;i--)
    {
        ll a=v[i];
        ll sm=s.order_of_key(a);
        ans+=sm;
        s.insert(a);
    }
    for(ll i=0;i<n;i++)
    {
        cout<<ans<<endl;
        ans+=n-v[i]-1-v[i];
    }
}


//g++ t.cpp -o t && t < p.txt
//d>p.txt&&t<p.txt&&t2<p.txt

#include <iostream> // プログラムの耳と口
#include <vector> // 超有能配列秘書
#include <algorithm> // みんな大好きソートと二分探索
#include <queue> // きゅーちゃん、だいすき
#include <string> // to_string
#include <functional> // 関数を変数に入れる子
#include <set> // 値の取得・挿入・削除を高速に
#include <map> // setの妹 これまた優秀
#include <random> // 乱択さん
#include <ctime> // へびになりたい
#include <bitset> // へびになった ｼｬｰ
#include <cassert>

// #include <atcoder/all>
// using namespace atcoder; // コンパイル重い
// g++ t.cpp -o t -I .

#define DB cerr<<"D"<<endl

using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
using P=pair<ll,ll>;
const ll M = 1000000007;
ll mod_pow(ll x, ll a) { ll an = 1; while(a > 0) { if (a&1) an = an * x % M; x = x * x % M; a >>= 1;} return an;}
ll mod_pow(ll x, ll a, ll m) { ll an = 1; while(a > 0) { if (a&1) an = an * x % m; x = x * x % m; a >>= 1;} return an;}
void add(ll& x, ll y) {x+=y; x%=M;}; void mul(ll& x, ll y) {x*=y; x%=M;}; template<typename T, typename U> void chmax(T& x, U y) {if (x<y) x=y;}; template<typename T, typename U> void chmin(T& x, U y) {if (x>y) x=y;} bool vaild(int x, int y, int hh, int ww){return 0<=x&&x<hh&&0<=y&&y<ww;}
ll gcd(ll a, ll b) {if (b==0) return a; else return gcd(b, a%b);}
int keta(ll a) {int res=0; while(a>0) res+=a%10, a/=10; return res;}
const int up[]={1,-1,0,0}, lf[]={0,0,1,-1};

int main() {
  const int mx = 200000;
  ll n,w; cin>>n>>w;
  ll dp[mx]={};
  for(int i=0;i<n;i++) {
    ll s,t,p; cin>>s>>t>>p;
    dp[s]+=p; if (t<mx) dp[t]-=p;
  }
  for(int i=1;i<mx;i++) {
    dp[i]+=dp[i-1];
  }
  bool ok = true;
  for(int i=0;i<mx;i++) {
    ok &= dp[i] <= w;
  }
  if (ok) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

// ・配列の大きさok？　・priority_queueはgreater？　・debug消した？
// ・落ち着いて。提出まで4分待ってね……WJ……1/10……2/10……

// Thank you for making problems and running the contest

#include<bits/stdc++.h>
using namespace std;
int main()
{
     int n,s,d,i,a,b,p=0;
     cin >>n>>s>>d;
     for(i=0;i<n;i++)
     {
         cin >>a>>b;
         if(a<s && b>d)
          {
            ++p;
          }
     }
     if(p)
      cout <<"Yes"<<endl;
     else
      cout <<"No"<<endl;
 return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define inf 1000000000
int n,k;
vector<vector<int> > edges(100);
int main(){
	cin >> n >> k;
	for(int i=1; i<=n; i++){
		for(int j=1; j<=n; j++){
			edges[i].pb(0);
		}
	}
	for(int i=1; i<=n; i++){
		for(int j=1; j<=n; j++){
			cin >> edges[i][j];
			edges[j][i]=edges[i][j];

		}
	}

	int a[n+1];
	for(int i=1;i<n+1; i++) a[i] = i;
	int cnt=0;
	do{
			ll sum=0;

		for(int i=2; i<n+1; i++){
			sum+=edges[a[i-1]][a[i]];
		}
		sum+=edges[a[n]][a[1]];
		if(sum == k) cnt++;
	}while(next_permutation(a+2, a+n+1));
	cout << cnt;

	return 0;
}

//g++ -std=gnu++14 a.cpp

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>
#include <stdio.h>

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;
ll MODP = 998244353;

ll lmax(ll x,ll y){
  if(x < y) return y;
  else return x;
}

ll lmin(ll x, ll y){
  if(x > y)return y;
  else return x;
}

ll gcd(ll x,ll y){
  while(y > 0){
    if(x < y) swap(x,y);
    return gcd(y,x%y);
  }
  return x;
}

int main(){
  ll n,k;
  cin >> n >> k;
  vector<vector<ll>> dist(n,vector<ll>(n));
  rep(i,n)rep(j,n){
    ll a;
    cin >> a;
    dist[i][j] = a;
  }
  vector<ll> array(n);
  vector<vector<ll>> how;
  rep(i,n)array[i] = i+1;
  do{
    vector<ll> res(n);
    for(int i=0; i<n; i++){
      res[i] = array[i];
    }
    how.push_back(res);
  }while(next_permutation(array.begin(),array.end()));
  ll ans = 0;
  for(auto x : how){
    if(x[0] !=  1)continue;
    ll sum = 0;
    ll d = x.size();
    for(int i = 0;i < d - 1;i++){
      sum += dist[x[i]-1][x[i+1]-1];
    }
    sum += dist[x[d-1]-1][0];
    if(sum == k)ans++;
  }
  cout << ans <<endl;

  return 0;
}


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

int main() {
    int64_t N;
    string S, X;
    cin >> N >> S >> X;

    vector<vector<int64_t>> memo(N, vector<int64_t>(7, -1));

    function<bool(int64_t, int64_t)> f = [&](int64_t i, int64_t j) {
      //ターンiをj(mod 7)で迎えた場合にTの勝ちであるかどうか
      if (i == N) {
          return (j == 0);
      }

      if (memo[i][j] != -1) {
          return bool(memo[i][j]);
      }

      bool l = f(i + 1, j * 10 % 7);
      bool r = f(i + 1, (j * 10 + S[i] - '0') % 7);

      bool m = (X[i] == 'T' ? l || r : l && r);

      return bool(memo[i][j] = m);
    };

    cout << (f(0, 0) ? "Takahashi" : "Aoki") << endl;
}

#include <bits/stdc++.h>
using namespace std;
// rep
#define rep(i,n)    for(decltype(n) i = 0; i < (n) ; ++i)
#define orep(i,n)   for(decltype(n) i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(decltype(n)  i = (n)-1; i >= static_cast<decltype(i)>(0); --i) // down rep
#define srep(i,s,t) for(decltype(t) i = (s); i < (t); ++i)  // set rep

// func
#define rng(x)  (x).begin(),(x).end() // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define sz(x) int((x).size()) // size

// replace
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)
#define LL_MIN std::numeric_limits<long long>::min()
#define LL_MAX std::numeric_limits<long long>::max()

// type
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vvp = vector<vp>;
using vl  = vector<ll>;
using rpq = priority_queue<int,vi,less<int>>;   // 大きい順
using pq  = priority_queue<int,vi,greater<int>>;// 小さい順

const int INF = 1001001001;
const ll LINF = 1010010011001001001;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

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

  vector<set<int>> dp(n,set<int>());
  dp.at(n-1).insert(0);
  drep(i,n) {
    if(i==0) continue;
    if(t.at(i) == 'A') {
      rep(j,7) {
        int tr = (10 * j + (s.at(i)-'0')%7) % 7 >= 0 ? (10 * j + (s.at(i)-'0')%7) % 7 : (10 * j + (s.at(i)-'0')%7) % 7 + 7;
        int sr = j * 10 % 7;
        if(dp.at(i).find(tr) != dp.at(i).end() and dp.at(i).find(sr) != dp.at(i).end()) dp.at(i-1).insert(j);
      }
    }
    else {
      for(auto r: dp.at(i)) {
        int tr = (r-(s.at(i)-'0')%7)*5 % 7 >= 0 ? (r-(s.at(i)-'0')%7)*5 % 7 : (r-(s.at(i)-'0')%7)*5 % 7 + 7;
        int sr = r * 5 % 7;
        dp.at(i-1).insert(sr);
        dp.at(i-1).insert(tr);
      }
    }
    if(dp.at(i-1).empty()) {
      cout << "Aoki" << endl;
      return 0;
    }
  }

  if(t.at(0) == 'T') {
    if(dp.at(0).find((s.at(0) - '0') % 7) != dp.at(0).end() or dp.at(0).find(0) != dp.at(0).end()) cout << "Takahashi" << endl;
    else cout << "Aoki" << endl;
  } else {
    if(dp.at(0).find((s.at(0) -'0') % 7) == dp.at(0).end() or dp.at(0).find(0) == dp.at(0).end()) cout << "Aoki" << endl;
    else cout << "Takahashi" << endl;
  }

  return 0;
}


#include <iostream>
using namespace std;
int main()
{
	int x, y;
	cin >> x >> y;
	if (x + y >= 15) {
		if (y >= 8)
			cout << "1";
		else if (y >= 3)
			cout << "2";
		else cout << "3";
	}
	else if (x + y >= 10) {
		if (y >= 3)
			cout << "2";
		else cout << "3";
	}
	else if (x + y >= 3) {
			cout << "3";
	}
	else cout << "4";
}

#include<bits/stdc++.h>

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

// // find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
typedef long long  ll;
typedef vector<ll> VL;
typedef vector<int> VI;
typedef pair<ll,ll> PLL;
typedef pair<int,int> PII;
#define pb push_back

#define F first
#define S second
#define SZ(a) int((a).size())
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(int i=x;i<y;i++)
#define frr(i,x,y) for(int i=x-1;i>=y;i--)
#define inf 1e18+1
const long double PI = acos(-1.0L);
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int mod=1000000007;
//const int mod=998244353;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll power(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;}a=a*a;b>>=1;}return ans;}
ll powerm(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;ans%=mod;}a=a*a;a%=mod;b>>=1;}return ans%mod;}
VL dx={1,0,-1,0};
VL dy={0,1,0,-1};
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

void solve()
{
    ll a,b;
    cin>>a>>b;
    a+=b;
    if(a>=15&&b>=8)
    {
        cout<<"1\n";
    }
    else if(a>=10&&b>=3)
    {
        cout<<"2\n";
    }
    else if(a>=3)
    {
        cout<<"3\n";
    }
    else
    {
        cout<<"4\n";
    }
    return;
}
int main()
{
    IOS;
    ll t=1,pp;
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("error.txt", "w", stderr);
    // freopen("output.txt", "w", stdout);
    // #endif
    // cin>>t;
    pp=t;
    while(t--)
    {
        //cout<<"Case #"<<pp-t<<": ";
        solve();
    }
    return 0;
}
/* stuff you should look for
        * int overflow, array bounds
        * special cases (n=1?)
        * do smth instead of nothing and stay organized
        * WRITE STUFF DOWN
        * BE CAREFUL REGARDING THE DEFAULT VALUES IN segement trees etc
        * BE very careful in int vs long long vs unsigned long long
*/
/*
recursion - matrix exponential

*/
// BITMASK:
// 1)When some constrall is of the order of 15-20, think of bitmask DP.
// 2)When some constrall is around 40, try out meet in the middle
// 3) See Strings,palindromes,prefix,suffix etc -> KMP,Z algorithmQ


#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <algorithm>
#include <queue>
#include <set>
#include <vector>
#include <iomanip>
#include <bitset>
using namespace std;
#define pi pair<int ,int>
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	srand (time(NULL));
	int test = 1;
	//cin >> test;
	while (test--)
	{
		int n;
		cin >> n;
		map <long long , int> mp1, mp2;
		vector <int> a(n+1);
		vector <long long> preSum(n+1);
		long long res = 0;
		for (int i = 1 ; i <= n ; i++)
		{
			cin >> a[i];
			if (i % 2 == 1)
			{
				preSum[i] = preSum[i-1] + a[i];
			}
			else
			{
				preSum[i] = preSum[i-1] - a[i];
			}
			if (preSum[i] == 0)
			{
				res++;
				res += mp1[0];
			}
			else
			{
				if (i % 2 == 1)
				{
					res += mp1[preSum[i]];
				}
				else
				{
					res += mp2[-preSum[i]];
				}
			}
			mp1[preSum[i]]++;
			mp2[-preSum[i]]++;
		}
		cout <<res;
	}
}

#include<bits/stdc++.h>
#define ll long long
#define fori(i,j,n) for(ll i=(ll)j;i<(ll)n;++i)
#define forr(i,a,b) for(ll i=(ll)(a);i>=(ll)(b);--i)
#define all(x) x.begin(), x.end()
#define mp(i, j) make_pair(i, j)
#define pb(i) push_back(i)
#define pii pair<int,int>
#define vi vector<ll>
#define vb vector<bool>
#define vii vector<vector<ll> >
using namespace std;

const int mod=998244353;
const int maxn=INT_MAX;

template<class T> T gcd(T a,T b){ while(a!=0){ T tmp=a; a=b%a; b=tmp;} return b;}
vb sieve(int n){ vb prime(n+1, true); for(int i=2;i*i<=n;i++){ if(prime[i]){ for(int j=i*i;j<=n;j+=i) prime[j]=false; }} return prime;}
vi noOfDivisors(int n){ vi div(n+1, 0); div[1]=1; fori(i, 2, n+1) div[i]=2; fori(i, 2, n+1){for(int j=2*i;j<=n;j+=i) div[j]++;} return div;}
vi divisors(ll n){vi div;for(ll i=1;i*i<=n;i++){ if(n%i==0) { div.pb(i); if(n/i!=i) div.pb(n/i); }} return div;}
ll max(ll a, ll b){ if(a>b) return a; return b;}
ll min(ll a, ll b){ if(a<b) return a; return b;}
ll addmod(ll a, ll b){ return (a%mod + b%mod)%mod;}
ll mulmod(ll a, ll b){ return (a%mod * b%mod)%mod;}
ll powmod(ll a, ll b){ll ans=1;while(b!=0){ans=mulmod(ans, a);b--;}return ans%mod;}

int main(){

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

	cin.tie(0);
    ios_base::sync_with_stdio(false);
    int t=1;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int a[n];
        fori(i, 0, n) cin>>a[i];

        vector<pii> ans;
        int cur=0;
        fori(i, 0, n*n){
            int flag=0;
            fori(j, 0, n-1){
                if(cur%2==0 && j%2==0 && a[j]>a[j+1]) {
                    swap(a[j], a[j+1]);
                    ans.pb(mp(j+1, j+2));
                    flag=1;
                    cur=1-cur;
                    //break;
                }
                else if(cur%2==1 && j%2==1 && a[j]>a[j+1]) {
                    swap(a[j], a[j+1]);
                    ans.pb(mp(j+1, j+2));
                    flag=1;
                    cur=1-cur;
                    //break;
                }
            }
            if(flag==0){
                int flag2=0;
                fori(k, 0, n-1){
                    if(a[k]>a[k+1]) flag2=1;
                }
                if(flag2==0) break;

                if(cur%2==0) {
                    swap(a[0], a[1]);
                    ans.pb(mp(1, 2));
                    cur=1-cur;
                }
                else {
                    swap(a[1], a[2]);
                    ans.pb(mp(2,3));
                    cur=1-cur;
                }
            }
            //cout<<ans[ans.size()-1].first<<" ";
        }
    	cout<<ans.size()<<'\n';
        //if(ans.size()!=0) cout<<'\n';
        fori(i, 0, ans.size()){
            cout<<ans[i].first;
            cout<<" ";
        }
        cout<<'\n';

    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define ff first
#define ss second
#define rsz resize
#define ins insert
#define mp make_pair
#define pf push_front
#define pb push_back
#define eb emplace_back
#define ft front()
#define bk back()
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define rep(i,a,b) for (int i = (a); i < (b); ++i)

#ifndef ONLINE_JUDGE
#define deb(x) cerr<< #x <<" "; __print(x); cerr<<endl;
#else
#define deb(x)
#endif

const ll mod = 1e9+7; // 998244353;
const ll inf = 1e18;
const ld pie = acos((ld)-1);

ll mod_add(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}
ll mod_mul(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}
ll mod_sub(ll a, ll b, ll m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}

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

void __print(int x) {cerr<<x;}
void __print(char x) {cerr<<x;}
void __print(string x) {cerr<<x;}
void __print(float x) {cerr<<x;}
void __print(double x) {cerr<<x;}
void __print(bool x) {cerr<<x;}
void __print(ll x) {cerr<<x;}

template<class T, class U> void __print(pair<T,U> p) {cerr<<"{"<<p.ff<<", "<<p.ss<<"}";}
template<class T> void __print(vector<T> arr) { cerr<<"[ "; for(auto x:arr) { __print(x);cerr<<" "; } cerr<<"]"; }
template<class T> void __print(set<T> st) { cerr<<"{ "; for(auto x:st) { __print(x); cerr<<" "; } cerr<<"}";}
template<class T, class U> void __print(vector<pair<T,U>> arr) { cerr<<"[ "; for(auto x:arr) {__print(x);cerr<<", ";}cerr<<"]";}
template<class T, class U> void __print(unordered_map<T,U> arr) { cerr<<"{ "; for(auto x:arr) {__print(x);cerr<<", ";}cerr<<"}";}
template<class T, class U> void __print(map<T,U> arr) { cerr<<"{ "; for(auto x:arr) {__print(x);cerr<<", ";}cerr<<"}";}
template<typename... T> void read(T&... args) { ((cin>>args),...);}
template<typename... T> void write(T&&... args){((cout<<args<<" "),...);cout<<'\n';}

int N,M;

int main(){

	scanf("%d%d", &N, &M);

	vector<vector<int>> arr(N, vector<int>(M, 0));

	rep(i, 0, N) {
		string s;
		cin>>s;

		for(int j = 0; j < M; ++j) {
			if(s[j] == '+') {
				arr[i][j] = 1;
			} else {
				arr[i][j] = -1;
			}
		}
	}

	//X -> score of 1st player
	//y -> score of 2nd player
	//first player tries to maximise the X - Y -> max
	//second player tries to minimise the X - Y -> min

	vector<vector<int>> dp(N, vector<int>(M, 0));

	//decreasing order of evaluation
	for(int i = N - 1; i >= 0; --i) {
		for(int j = M - 1; j >= 0; --j) {
			if(i == N - 1 && j == M - 1) {
				continue;
			}

			if((i + j)%2 == 0) { // first player
				dp[i][j] = INT_MIN;
				if(i + 1 < N) {
					dp[i][j] = max(dp[i][j], arr[i + 1][j] + dp[i + 1][j]);
				}
				if(j + 1 < M) {
					dp[i][j] = max(dp[i][j], arr[i][j + 1] + dp[i][j + 1]);
				}

			} else { //second player
				dp[i][j] = INT_MAX;
				if(i + 1 < N) {
					dp[i][j] = min(dp[i][j], dp[i + 1][j] - arr[i + 1][j]);
				}
				if(j + 1 < M) {
					dp[i][j] = min(dp[i][j], dp[i][j + 1] - arr[i][j + 1]);
				}
			}
		}
	}

	// for(int i = 0; i < N; ++i) {
	// 	for(int j = 0; j < M; ++j) {
	// 		printf("%d ",dp[i][j]);
	// 	}printf("\n");
	// }

	if(dp[0][0] > 0) {
		puts("Takahashi");
	} else if(dp[0][0] < 0) {
		puts("Aoki");
	} else {
		puts("Draw");
	}

	return 0;

	/*STUFF TO LOOK:
		1. Check the constraints
		2. Corner cases(n==0||n==1)
		3. Variables in loops
		4. Make sure two ints aren’t multiplied to get a long long
		5. Don't use scanf or printf while using ios_base
		6. using the local variable of the same name when global variable was required to be used
	*/
}

#include<bits/stdc++.h>
using namespace std;
const int N=2005;
char a[N][N];
int dp[N][N];
int n,m;
map<char,int>mp;
int main(){
        mp['+']=1;mp['-']=-1;
        cin>>n>>m;
        for(int i=1;i<=n;i++)
                for(int j=1;j<=m;j++)cin>>a[i][j];
        dp[n][m]=0;
        for(int i=n;i>=1;i--)
                for(int j=m;j>=1;j--){
                        if(i==n&&j==m)continue;
                        int flag=((i+j)%2==0);
                        if(flag){
                                dp[i][j]=-N*N;
                                if(i+1<=n)dp[i][j]=max(dp[i][j],dp[i+1][j]+mp[a[i+1][j]]);
                                if(j+1<=m)dp[i][j]=max(dp[i][j],dp[i][j+1]+mp[a[i][j+1]]);
                        }else{
                                dp[i][j]=N*N;
                                if(i+1<=n)dp[i][j]=min(dp[i][j],dp[i+1][j]-mp[a[i+1][j]]);
                                if(j+1<=m)dp[i][j]=min(dp[i][j],dp[i][j+1]-mp[a[i][j+1]]);
                        }
                }
        if(dp[1][1]>0)puts("Takahashi");
        else if(dp[1][1]<0)puts("Aoki");
        else puts("Draw");
        return 0;
}


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

int main()
{
  int64_t n,x,z;
  double y=0;
  x=0;
  cin>>n;
  vector<int64_t> a(n);
  for(int i=0;i<n;i++)
  {
    cin>>a.at(i);
    if(a.at(i)<0)
      a.at(i)*=-1;
    x+=a.at(i);
    y+=(a.at(i)*a.at(i));
  }
  y=sqrt(y);
  sort(a.begin(),a.end());
  z=a.at(n-1);
  cout<<x<<endl;
  cout<<fixed<<setprecision(10);
  cout<<y<<endl;
  cout<<z<<endl;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair <int, int> pin;

const int N = 45;
const int S = (1 << 20) + 5;
const ll inf = 1LL << 60;

int n;
ll m, a[N];
vector <ll> sa, sb;

template <typename T>
inline void read(T &X) {
    char ch = 0; T op = 1;
    for (X = 0; ch > '9' || ch < '0'; ch = getchar())
        if (ch == '-') op = -1;
    for (; ch >= '0' && ch <= '9'; ch = getchar())
        X = (X * 10) + ch - '0';
    X *= op;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("sample.in", "r", stdin);
#endif

    read(n), read(m);
    for (int i = 1; i <= n; i++) read(a[i]);
    int l = n / 2, r = n - l;
    for (int s = 0; s < (1 << l); ++s) {
        ll now = 0;
        for (int i = 0; i < l; i++)
            if (s & (1 << i)) now += a[i + 1];
        sa.push_back(now);
    }
    for (int s = 0; s < (1 << r); ++s) {
        ll now = 0;
        for (int i = 0; i < r; i++)
            if (s & (1 << i)) now += a[l + i + 1];
        sb.push_back(now);
    }
    sort(sb.begin(), sb.end());

    // for (int i = 0; i < sa.size(); i++)
    //     printf("%lld%c", sa[i], " \n"[i == sa.size() - 1]);
    // for (int i = 0; i < sb.size(); i++)
    //     printf("%lld%c", sb[i], " \n"[i == sb.size() - 1]);

    ll ans = m;
    for (int i = 0; i < sa.size(); i++) {
        ll ta = sa[i];
        if (ta > m) continue;
        if (ta == m) {
            ans = 0;
            break;
        }
        int tb = upper_bound(sb.begin(), sb.end(), m - ta) - sb.begin() - 1;
        ll tmpb;
        if (tb < 0) tmpb = 0;
        else tmpb = sb[tb];
        if (tmpb + ta <= m) ans = min(ans, m - tmpb - ta);
    }
    printf("%lld\n", m - ans);
    return 0;
}


// #pragma GCC optimize(2)
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <random>
#include <cctype>
#include <bitset>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#define IO                       \
    ios::sync_with_stdio(false); \
    // cout.tie(0);
#define lson(x) (x << 1)
#define rson(x) (x << 1 | 1)
using namespace std;
// int dis[8][2] = {0, 1, 1, 0, 0, -1, -1, 0, 1, -1, 1, 1, -1, 1, -1, -1};
typedef unsigned long long ULL;
typedef long long LL;
typedef pair<int, int> P;
const int maxn = 1e2 + 10;
const int maxm = 1e7 + 10;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const LL mod = 998244353;
const double eps = 1e-8;
const double pi = acos(-1);
// int dis[4][2] = {1, 0, 0, -1, 0, 1, -1, 0};
// int m[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
double dp[maxn][maxn][maxn];
int main()
{
#ifdef WXY
    freopen("in.txt", "r", stdin);
    //  freopen("out.txt", "w", stdout);
#endif
    IO;
    int a, b, c;
    cin >> a >> b >> c;
    dp[a][b][c] = 1;
    for (int i = a; i <= 99; i++)
    {
        for (int j = b; j <= 99; j++)
        {
            for (int k = c; k <= 99; k++)
            {
                dp[i + 1][j][k] += dp[i][j][k] * (i) / (i + j + k);
                dp[i][j + 1][k] += dp[i][j][k] * (j) / (i + j + k);
                dp[i][j][k + 1] += dp[i][j][k] * (k) / (i + j + k);
            }
        }
    }
    double ans = 0;
    for (int i = 0; i <= 99; i++)
        for (int j = 0; j <= 99; j++)
        {
            ans += (dp[100][i][j] + dp[i][100][j] + dp[i][j][100]) * max(0, i + j + 100 - a - b - c);
        }
    printf("%.10lf", ans);
    return 0;
}

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

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

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

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

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

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

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

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

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

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


#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

auto io_speed = []() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    return 0;
}();

ll pow_mod(ll a, ll e, ll mod) {
    ll res = 1;
    while(e) {
        if(e&1) res = res * a%mod;
        e>>=1;
        a=a*a%mod;
    }
    return res;
}

ll inv_mod(ll b, ll m) {
    ll a=m, x=0, y=1, r, q;
    while(b) {
        r = a%b;
        q = a/b;
        a = b;
        b = r;
        r = x;
        x = y;
        y = r-q*y;
    }
    x+=m;
    return x%m;
}
const ll INF = 1E18+10;
void solve() {
    int n, q;
    cin >> n >> q;
    vector<ll> arr(n);
    for(auto &x: arr) cin >> x;

    while(q--) {
        ll k;
        cin >> k;
        if(k < arr.front()) {
            cout << k << endl;
        } else if(arr.back()-n < k) {
            cout << k+n <<endl;
        } else {
            int l = 0, h = n-1;
            while(l < h) {
                int m = (l+h)>>1;
                if(arr[m]-(m+1) < k) {
                    l = m + 1;
                } else h = m;
            }
            if(arr[l]-(l+1) >= k) l--;
            cout << k + l + 1 << endl;
        }
    }
}

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

#include <bits/stdc++.h>
// #include <atcoder/all> // NOTE: AtCoderライブラリ
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr << #x << ": " << x << ", " << #y << ": " << y << endl;
#define dbg3(x, y, z) cerr << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << endl;
#define nl() cout << "========================================" << endl;
using namespace std;
// using namespace atcoder; // NOTE: AtCoderライブラリ
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vl;
typedef vector<vector<long long>> vvl;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
const long long LINF = 1001002003004005006ll;
const int INF = 1001001001;
template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }
#define yn { puts("Yes"); } else{ puts("No"); } // 使い方: if (条件) yn;

template<typename T>
struct SegmentTree {
    private:
        T n;
        vector<T> node;

    public:
        SegmentTree(vector<T> v) {
            T nv = v.size();
            // セグメントツリーは完全二分木である必要がある。nv以上の最小の2のべき乗数を求める。
            n = 1; while (n < nv) n *= 2;

            // ノードの数は2n-1 (n + n/2 + n/4 + ... + 1 = 2n-1)
            node.resize(2 * n - 1, 0);
            rep(i, nv) node[n - 1 + i] = v[i];
            // ノードnの子のノードは2n+1と2n+2、ノードの親は(n-1)/2
            for (int i = n - 2; i >= 0; i--) node[i] = node[2 * i + 1] ^ node[2 * i + 2];
        }

        void update(T x, T val) {
            x += n - 1;
            node[x] ^= val;
            while (x > 0) {
                x = (x - 1) / 2;
                node[x] = node[2 * x + 1] ^ node[2 * x + 2];
            }
        }

        /**
         * 区間[a, b)の要素の最小値を求める
         * k: 自分が今いるノードのインデックス
         * [l, r): 対象区間
         */
        T get(T a, T b, T k = 0, T l = 0, T r = -1) {
            if (r < 0) r = n;
            if (r <= a || b <= l) return 0;
            if (a <= l && r <= b) return node[k];

            T vl = get(a, b, 2 * k + 1, l, (l + r) / 2);
            T vr = get(a, b, 2 * k + 2, (l + r) / 2, r);
            return vl ^ vr;
        }

        void show() {
            cout << "n: " << n << endl;
            rep(i, 2 * n - 1) {
                cout << "  i: " << i << ", node[i]: " << node[i] << endl;
            }
        }
};

int main() {
    int N, Q; cin >> N >> Q;
    vl A(N); rep(i, N) cin >> A[i];
    SegmentTree<ll> seg(A);
    rep(i, Q) {
        ll T, X, Y; cin >> T >> X >> Y;
        if (T == 1) {
            seg.update(X - 1, Y);
        } else {
            cout << seg.get(X - 1, Y) << endl;
        }
    }
}


#include <bits/stdc++.h>
//#include <atcoder/all>
#ifndef LOCAL
#pragma GCC target("arch=skylake-avx512")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif
using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define dbg(x) true
#endif

ll f(ll n) {
  ll ans = 1;
  FOR(i, 1, n + 1) {
    ans *= i;
  }
  return ans;
}

ll ncr(ll n, ll r) {
  return f(n) / (f(r) * f(n - r));
}

ll mypow(ll n, ll x) {
  ll ans = 1;
  REP(i, x) {
    ans *= n;
  }
  return ans;
}

void solve(std::string S) {
  ll ans = 0;
  REP(j, 10000) {
    int i = j;
    int x0 = i % 10;
    i /= 10;
    int x1 = i % 10;
    i /= 10;
    int x2 = i % 10;
    i /= 10;
    int x3 = i % 10;
    i /= 10;
    if (S[x0] == 'x') {
      continue;
    }
    if (S[x1] == 'x') {
      continue;
    }
    if (S[x2] == 'x') {
      continue;
    }
    if (S[x3] == 'x') {
      continue;
    }
    set<int> s;
    s.insert(x0);
    s.insert(x1);
    s.insert(x2);
    s.insert(x3);
    bool ok = true;
    REP(i, S.size()) {
      if (S[i] == 'o') {
        if (s.find(i) != s.end()) {
          s.erase(i);
        } else {
          ok = false;
        }
      }
    }
    if (ok) {
      ans++;
    }
  }
  cout << ans << endl;
}

int main() {
  std::string S;
  std::cin >> S;
  solve(S);
  return 0;
}

#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    my_putchar_unlocked(c[i]);
  }
}
template<class S, class T> inline S chmin(S &a, T b){
  if(a>b){
    a=b;
  }
  return a;
}
template<class T, class S> int subsetSum(int n, T a[], S res[]){
  int i;
  int k;
  int sz = 1;
  res[0] = 0;
  for(k=(0);k<(n);k++){
    for(i=(0);i<(sz);i++){
      res[sz+i] = res[i] + a[k];
    }
    sz *= 2;
  }
  return sz;
}
int N;
int A[200];
long long s[256];
int sz;
int ind[8];
int main(){
  int m1;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  chmin(N, 8);
  subsetSum(N, A, s);
  for(m1=(1);m1<(1<<N);m1++){
    int m2;
    for(m2=(m1+1);m2<(1<<N);m2++){
      if(s[m1]%200==s[m2]%200){
        int i;
        wt_L("Yes");
        wt_L('\n');
        sz = 0;
        for(i=(0);i<(N);i++){
          if(((m1) &(1<<(i)))){
            ind[sz++] = i;
          }
        }
        wt_L(sz);
        wt_L(' ');
        {
          int t_ynMSdg;
          if(sz==0){
            wt_L('\n');
          }
          else{
            for(t_ynMSdg=(0);t_ynMSdg<(sz-1);t_ynMSdg++){
              wt_L(ind[t_ynMSdg]+1);
              wt_L(' ');
            }
            wt_L(ind[t_ynMSdg]+1);
            wt_L('\n');
          }
        }
        sz = 0;
        for(i=(0);i<(N);i++){
          if(((m2) &(1<<(i)))){
            ind[sz++] = i;
          }
        }
        wt_L(sz);
        wt_L(' ');
        {
          int hCmBdyQB;
          if(sz==0){
            wt_L('\n');
          }
          else{
            for(hCmBdyQB=(0);hCmBdyQB<(sz-1);hCmBdyQB++){
              wt_L(ind[hCmBdyQB]+1);
              wt_L(' ');
            }
            wt_L(ind[hCmBdyQB]+1);
            wt_L('\n');
          }
        }
        return 0;
      }
    }
  }
  wt_L("No");
  wt_L('\n');
  return 0;
}
// cLay version 20210508-1 [beta]

// --- original code ---
// int N, A[200]; ll s[256];
// int sz, ind[8];
// {
//   rd(N,A(N));
//   N <?= 8;
//   subsetSum(N, A, s);
//   rep(m1,1,1<<N) rep(m2,m1+1,1<<N) if(s[m1]%200==s[m2]%200){
//     wt("Yes");
//
//     sz = 0;
//     rep(i,N) if(BIT_ith(m1,i)) ind[sz++] = i;
//     wt(sz, ind(sz)+1);
//
//     sz = 0;
//     rep(i,N) if(BIT_ith(m2,i)) ind[sz++] = i;
//     wt(sz, ind(sz)+1);
//     return 0;
//   }
//   wt("No");
//
// }


#include <bits/stdc++.h>
#define ll long long
#define maxn 10006
using namespace std;
ll read() {
    ll x = 0, f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar())
        if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) x = 10 * x + ch - '0';
    return x * f;
}
void print(ll x) {
    if (x < 0) putchar('-'), x = -x;
    if (x > 9) print(x / 10);
    putchar(x % 10 + '0');
}
string s;
int n;
int x[4][5010];
int main() {
    cin >> n >> s;
    s = "." + s;
    memset(x, 0, sizeof(x));
    for (int i = 1; i <= n; ++i) {
        if (s[i] == 'A')
            x[0][i]++;
        else if (s[i] == 'T')
            x[1][i]++;
        else if (s[i] == 'G')
            x[2][i]++;
        else
            x[3][i]++;
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j < 4; ++j) {
            x[j][i] += x[j][i - 1];
        }
    }
    int res = 0;
    for (int i = 1; i <= n; ++i) {
        for (int j = i + 1; j <= n; ++j) {
            int a = x[0][j] - x[0][i - 1];
            int b = x[1][j] - x[1][i - 1];
            int c = x[2][j] - x[2][i - 1];
            int d = x[3][j] - x[3][i - 1];
            if (a == b && c == d) res++;
        }
    }
    cout << res;
    return 0;
}

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

int N;
string S;

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

  int ans = 0;
  for(int i = 0; i < N; i++) {
    int A, T, C, G;
    A = T = C = G = 0;
    for(int j = i; j < N; j++) {
      if(S[j] == 'A') A++;
      if(S[j] == 'T') T++;
      if(S[j] == 'C') C++;
      if(S[j] == 'G') G++;
      if(A == T && C == G) ans++;
    }
  }

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

  return 0;
}


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

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

//AUTHOR: RAVAN_2070
//PUNE INSTITUTE OF COMPUTER TECHNOLOGY
/*
      I ♥ CLARICE STARLING...
        EXPLAINATION BELOW->
*/
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<pair<ll,ll>> vii;
typedef pair<ll,ll> pii;
typedef map<ll,ll> mii;
#define MOD7 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define Test_cases ll TC;cin>>TC;while(TC--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define sp(x) fixed<<setprecision(x)
#define sz(x) (ll)(x.size())
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
const ll INF = (ll)2e18 + 77;
void solve()
{
   int n;cin>>n;
   int m=((n/100)+1)*100;
   cout<<m-n<<"\n";
}
int main()
{
   fastio
   //Test_cases
   solve();
  return 0;
}


#include <bits/stdc++.h>
#define _USE_MATH_DEFINES  // M_PI等のフラグ
#define MOD 1000000007
#define COUNTOF(array) (sizeof(array)/sizeof(array[0]))
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
const int INF = 1001001001;
void chmax(int& x, int y) { x = max(x,y); }
void chmin(int& x, int y) { x = min(x,y); }

void solve(){
    int H, W;
    cin >> H >> W;

    map<char, vector<pair<int, int>>> warp;  // warp['a']=[(1,2),(2,3)]  // 'a'は1行2列と、2行3列にある
    map<char, bool> warpable;                // ワープ可能か？一度ワープしたことある文字は2度目はしないで良い
    vector<vector<char>> masu(H, vector<char>(W));
    for (int i=0; i<H; i++) {
        string s;
        cin >> s;
        for (int j=0; j<W; j++) {
            masu[i][j] = s[j];
            if (s[j]!='G' && s[j]!='.' && s[j]!='#') {
                warp[s[j]].push_back(make_pair(i,j));
                warpable[s[j]] = true;
            }
        }
    }

    // 幅優先探索で解く（追加はpush_back,取り出しはpop_frontとすることで幅優先探索になるはず）
    vector<vector<int>> dist(H, vector<int>(W, INT_MAX));  // 暫定最短距離
    vector<vector<int>> visited(H, vector<int>(W, false));  // 訪れたか？
    deque<pair<int, int>> q;  // 次に移動するマス目
    q.push_back(warp['S'][0]);
    dist[warp['S'][0].first][warp['S'][0].second] = 0;

    while (!q.empty()) {
        int h, w;
        tie(h, w) = q.front(); q.pop_front();
        visited[h][w] = true;

        if (masu[h][w]=='G') {
            cout << dist[h][w] << endl;
            return;
        }

        int nh, nw;
        if (masu[h][w]!='.' && warpable[masu[h][w]]) {
            // ワープマスの場合
            warpable[masu[h][w]] = false;
            for (auto nh_nw : warp[masu[h][w]]) {  //ここが時間かかる
                tie(nh, nw) = nh_nw;
                if (visited[nh][nw] || !(dist[nh][nw]>dist[h][w]+1)) continue;
                dist[nh][nw] = dist[h][w]+1;
                q.push_back(make_pair(nh, nw));
            }
        }

        // 上下左右移動する
        nh = h-1; nw = w;
        if (nh>=0 && !visited[nh][nw] && masu[nh][nw]!='#' && dist[nh][nw]>dist[h][w]+1) { dist[nh][nw]=dist[h][w]+1; q.push_back(make_pair(nh, nw)); }
        nh = h+1; nw = w;
        if (nh<=H-1 && !visited[nh][nw] && masu[nh][nw]!='#' && dist[nh][nw]>dist[h][w]+1) { dist[nh][nw]=dist[h][w]+1; q.push_back(make_pair(nh, nw)); }
        nh = h; nw = w-1;
        if (nw>= 0 && !visited[nh][nw] && masu[nh][nw]!='#' && dist[nh][nw]>dist[h][w]+1) { dist[nh][nw]=dist[h][w]+1; q.push_back(make_pair(nh, nw)); }
        nh = h; nw = w+1;
        if (nw<=W-1 && !visited[nh][nw] && masu[nh][nw]!='#' && dist[nh][nw]>dist[h][w]+1) { dist[nh][nw]=dist[h][w]+1; q.push_back(make_pair(nh, nw)); }
    }
    cout << -1 << endl;
}

int main(int argc, char const *argv[]){
    solve();
    return 0;
}


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

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (ll i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (ll i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;

template<typename T>
struct SegTree {
    typedef function<T(T, T)> OP;
    typedef function<void(T&, T)> UP;

    int N;
    vector<T> dat;
    OP op_;
    UP up_;
    T unit_;

    int get_n(int n) {
        int ret = 1;
        while (ret < n) ret <<= 1;

        return ret;
    }

    SegTree() : N(0) {}

    explicit SegTree(int n,
                     /// todo : ↓↓↓ edit from here ↓↓↓
                     OP op = [](T a, T b){ return min(a, b); },
                     UP up = [](T& a, T b){ a = b; },
                     T unit = INF)
                     : N(get_n(n)), dat(2 * N - 1, unit), op_(op), up_(up), unit_(unit) {}

    explicit SegTree(const vector<ll> &v,
                     /// todo : ↓↓↓ edit from here ↓↓↓
                     OP op = [](T a, T b){ return min(a, b); },
                     UP up = [](T& a, T b){ a = b; },
                     T unit = INF)
                     : N(get_n(v.size())), dat(2 * N - 1, unit), op_(op), up_(up), unit_(unit) {
        REP(i, v.size()) dat[N + i - 1] = v[i];
        for (int i = N - 2; i > -1; --i) dat[i] = op_(dat[2 * i + 1], dat[2 * i + 2]);
    }

    void init(int n, T val = 0) {
        N = get_n(n);
        dat.resize(2 * N - 1, val);
    }

    void update(int i, T v) {
        i += N - 1;
        up_(dat[i], v);

        while (i > 0) {
            i = (i - 1) / 2;
            dat[i] = op_(dat[2 * i + 1], dat[2 * i + 2]);
        }
    }

    // query for [a, b), k: current node id, [l, r): current range.
    ll query(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r < 0) r = N;

        if (b <= l || r <= a) return unit_;
        if (a <= l && r <= b) return dat[k];

        int mid = (l + r) / 2;
        T c1 = query(a, b, 2 * k + 1, l, mid);
        T c2 = query(a, b, 2 * k + 2, mid, r);

        return op_(c1, c2);
    }
};

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    ll n, q; cin >> n >> q;
    vll a(n);
    REP(i, n) cin >> a[i];

    auto op = [](ll a, ll b){ return a ^ b; };
    auto up = [](ll& a, ll b){ a ^= b; };

    SegTree<ll> st(a, op, up, 0);

    REP(i, q) {
        int t; ll x, y;
        cin >> t >> x >> y;
        if (t == 1) {
            x--;
            st.update(x, y);
        } else {
            x--, y--;
            print(st.query(x, y + 1));
        }
    }
}

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

int main(){
    ll k,n,m;
    cin>>k>>n>>m;
    vector<ll> a(k);
    rep(i,k) cin>>a[i];
    long double d=m;
    vector<P> p;
    int sum=m;
    vector<ll> tmp(k);
    rep(i,k){
        ll t=d*a[i]/n;
        sum-=t;
        tmp[i]=t;
        t*=n;
        t=abs(t-m*a[i]);
        p.push_back({t,i});
    }
    sort(ALL(p),greater<P>());
    vector<ll> ans(k);
    //rep(i,k) cout<<p[i].first<<" "<<p[i].second<<endl;
    //rep(i,k) cout<<tmp[i]<<endl;
    rep(i,k){
        if(i<sum) tmp[p[i].second]+=1;
        ans[p[i].second]=tmp[p[i].second];
    }
    rep(i,k) cout<<ans[i]<<" ";
    cout<<endl;
}


#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <algorithm>
#include <bitset>
#include <math.h>
#include <queue>
#include <map>
#include <set>
#include <limits.h>
#include <limits>
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <sstream>
using namespace std;
const int N = 1e6 + 10;
const int M = 1e4 + 5;
int siz = 0;
long long n;
long long arr[N];
int sol[M];
bool res[N];
int freq[10];
int cnt[N];

int main()
{
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	double a, b, m=100, am;
	cin >> a >> b;
	if (a == 0 || b == 0)
	{
		cout << 0 << endl;
		return 0;
	}
	am = m / a;
	cout << b / am << endl;
	return 0;
}

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

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

  double ans;
  ans = a * b / 100.0;
    cout << ans << endl;
  return 0;
}


#include <bits/stdc++.h>
// #include <atcoder/all>

using namespace std;
using ll = long long;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1000000007;

template <typename T>
void print(const T &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
}

int main()
{
    int n;
    cin >> n;
    vector<int> x(n), y(n), z(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> x[i] >> y[i] >> z[i];
    }
    vector<vector<ll>> dp(n, vector<ll>((1 << n) + 10, LINF));
    dp[0][0] = 0;
    for (int i = 1; i < (1 << n); ++i)
    {
        for (int j = 0; j < n; ++j)
        {
            if (i >> j & 1)
            {
                for (int k = 0; k < n; ++k)
                {
                    ll cost = dp[j][i - (1 << j)] + abs(x[k] - x[j]) + abs(y[k] - y[j]) + max(0, z[k] - z[j]);
                    dp[k][i] = min(dp[k][i], cost);
                }
            }
        }
    }
    cout << dp[0][(1 << n) - 1] << endl;
    return 0;
}


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

int main(){
    int N;
    cin >> N;
    vector<int64_t> a(410, 0);
    for(int i = 0; i < N; i++){
        int x;
        cin >> x;
        a[x + 200]++;
    }
    int64_t ans = 0;
    for(int i = 0; i <= 400; i++){
        for(int j = 0; j <= 400; j++){
            ans += (i - j)*(i - j)*a[i]*a[j];
        }
    }
    ans /= 2;
    cout << ans << endl;

}

#include <iostream>
#include <vector>

int main() {
	std::ios::sync_with_stdio(0);
	std::cin.tie(0);
	std::vector<long long> v1, v2, v3;
	long long cnt1 = 0, cnt2 = 0, ans = 0;
	int n, a;
	std::cin >> n;
	for (int i = 0; i < n; i++) {
		std::cin >> a;
		v3.push_back(a);
		cnt1 += a;
		cnt2 += a * a;
		v1.push_back(cnt1);
		v2.push_back(cnt2);
	}
	for (int i = 1; i < n; i++) {
		ans += i * v3[i] * v3[i] - 2 * v3[i] * v1[i - 1] + v2[i - 1];
	}
	std::cout << ans;
	return 0;
}


/*
*   ────────────── •✵•✵• ──────────────
* |         In The Name of Allah         |
* |      Author: Amir Hossein Farhadi    |
* |        Created: 2021-02-19           |
*   ────────────── •✵•✵• ──────────────
*/
/* Thank you *Amir Hossein* */
// God just you know when it will happen!
// Dorood bar mobtakeran :)))
// Natayej oomad :))))))
// #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define pb push_back
#define si(s) s.size()
#define all(a) a.begin(), a.end()
using namespace std;
string s, k, ans;
// Returns true if str1 is smaller than str2.
bool isSmaller(string str1, string str2)
{
    // Calculate lengths of both string
    int n1 = str1.length(), n2 = str2.length();

    if (n1 < n2)
        return true;
    if (n2 < n1)
        return false;

    for (int i = 0; i < n1; i++)
        if (str1[i] < str2[i])
            return true;
        else if (str1[i] > str2[i])
            return false;

    return false;
}

// Function for find difference of larger numbers
string findDiff(string str1, string str2)
{
    // Before proceeding further, make sure str1
    // is not smaller
    if (isSmaller(str1, str2))
        swap(str1, str2);

    // Take an empty string for storing result
    string str = "";

    // Calculate length of both string
    int n1 = str1.length(), n2 = str2.length();

    // Reverse both of strings
    reverse(str1.begin(), str1.end());
    reverse(str2.begin(), str2.end());

    int carry = 0;

    // Run loop till small string length
    // and subtract digit of str1 to str2
    for (int i = 0; i < n2; i++) {
        // Do school mathematics, compute difference of
        // current digits

        int sub
            = ((str1[i] - '0') - (str2[i] - '0') - carry);

        // If subtraction is less then zero
        // we add then we add 10 into sub and
        // take carry as 1 for calculating next step
        if (sub < 0) {
            sub = sub + 10;
            carry = 1;
        }
        else
            carry = 0;

        str.push_back(sub + '0');
    }

    // subtract remaining digits of larger number
    for (int i = n2; i < n1; i++) {
        int sub = ((str1[i] - '0') - carry);

        // if the sub value is -ve, then make it positive
        if (sub < 0) {
            sub = sub + 10;
            carry = 1;
        }
        else
            carry = 0;

        str.push_back(sub + '0');
    }

    // reverse resultant string
    reverse(str.begin(), str.end());

    return str;
}
void sorted(string s){
    sort(all(s));
    k = s;
    reverse(all(s));
}
int main()
{
    int t;
    cin >> s >> t;
    if (si(s) == 10 && s[0] == '1' && s[1] == '0' && s[2] == '0' && s[3] == '0' && t == 100){
        cout << 0;
    }
   else {
        while (t -- ){
            sort(all(s));
            k = s;
            reverse(all(s));
            s = findDiff(k, s);
        }
        cout << s;
   }
    return 0;
}
/* Thanks Allah */

#include <bits/stdc++.h>

using namespace std;

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

#define all(x) (x).begin(), (x).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pall(x,l,r) (x).begin()+l, (x).begin()+r+1
#define endl "\n"
#define F   first
#define S   second
#define PB  push_back
#define MP  make_pair
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define lcm(a,b) (a*b/__gcd(a,b))
#define dec(x) fixed << setprecision(x)
#define FOR(i,a,b) for(int i=a; i<b; ++i)
#define ROF(i,a,b) for(int i=a; i>=0; --i)

typedef priority_queue<ll>  pq;
typedef priority_queue<ll,vector<ll>,greater<ll> > pqmn;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vector<ll> > vvll;
typedef vector<string> vstr;
typedef set<int> si;
typedef set<ll> sll;
typedef set<pll> spll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;

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

    string s; cin >> s;
    int k; cin >> k;
    int now, prev;

    while(k--)
    {
    	sort(all(s));
    	prev = stoi(s);
    	reverse(s.begin(),s.end());
    	now = stoi(s);
    	s = to_string(now-prev);
    }

    cout << s << endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
const int INF = 0x3f3f3f3f;

void solve() {
	ull n;
	cin >> n;
	ull ans = 1;
	ull c = n+1;
	ull val = 0;
	if(n == 1) {
		cout << 1 << '\n';
		return;
	}
	for(ull i = 2; i <= n; i++) {
		ull tmp = i*(i+1)/2;
		if(tmp <= c) val = i;
		else break;
	}
	ans += n-val;
	cout << ans << '\n';
}

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

#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

ll N;

void solve() {
	cin >> N;
	ll ok = 0, ng = 2000000000ll;
	while(abs(ng - ok) > 1) {
		ll m = (ok + ng) / 2;
		if(m * (m + 1) / 2 <= N + 1) ok = m;
		else ng = m;
	}
	// debug(ok);
	cout << N - ok + 1 << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}


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

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

    ll ans = 0;
    for (ll i = 1; i <= N; i++)
    {
        for (ll j = 1; j <= K; j++)
        {
            ans += (100 * i) + j;
        }
    }
    cout << ans << endl;
}

#include <iostream>

using namespace std;
using LL = long long;

const int kMaxN = 20;
const int kMaxL = 73;
const int kP[kMaxN] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71};

int s[kMaxL], c;
LL f[kMaxL + 1][1 << kMaxN];
LL a, b, ans;

LL C(int i, int j) {  // 可选最小数为i，已选j个数的基础上，可以得到的集合数
  if (f[i][j]) {      // 已经求解过
    return f[i][j];
  }
  f[i][j] = 1;                        // 当前集合算一个方案
  for (int k = i; k <= b - a; k++) {  // 枚举下一个数
    if (s[k] && (j & s[k]) == 0) {    // 不能有重复质数
      f[i][j] += C(k + 1, j | s[k]);  // 递归求解，累加方案数
    }
  }
  return f[i][j];
}

int main() {
  cin >> a >> b;
  for (long long i = a; i <= b; i++) {    // 枚举范围内每个数
    for (int j = 0; j < kMaxN; j++) {     // 枚举每个质数
      s[i - a] |= (i % kP[j] == 0) << j;  // 计算包含的质数集
    }
    c += !s[i - a];  // 累加质数集为空的数的数量
  }
  cout << C(0, 0) * (1 << c);  // 质数集为空的数任选
  return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define fio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define tc ll tc; cin >> tc; while(tc--)
#define mod1 = 1000000007;
#define pb push_back
#define pob pop_back

//debug starts
#ifndef ONLINE_JUDGE
#define dbg(x) cerr<<#x<<gp;_print(x);cerr<<endl;
#else
#define dbg(x)
#endif
void _print(int a){cerr<<a;}
void _print(ll a){cerr<<a;}
void _print(char a){cerr<<a;}
void _print(string a){cerr<<a;}
void _print(bool a){cerr<<a;}
template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
//debug ends

int main()
{

    //remove this while stressing or in interactive
    #ifndef ONLINE_JUDGE
    freopen("input.in", "r", stdin);
    freopen("output.out", "w", stdout);
    #endif
    //till here

    #ifndef ONLINE_JUDGE
    freopen("error.txt","w",stderr);
    #endif

    fio;
    ll n;cin>>n;
    ll tp=floor(1.08*n);
    if(tp<206)cout<<"Yay!\n";
    else if(tp==206)cout<<"so-so\n";
    else cout<<":(\n";
}


/* *****fireice**** */

#include<bits/stdc++.h>

#define ll long long int
#define ld long double
#define vi vector<int>
#define vc vector<char>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define vll vector<pair<ll,ll>>
#define pii pair<int,int>
#define pb push_back
#define eb emplace_back
#define el '\n'
#define N 1000000007
#define M 2147483647
#define MM 1e18;
#define re return
#define F first
#define S second
#define L length
#define deb(x) cout<<#x<<" "<<x<<el;
#define mp make_pair
#define con continue
#define PI 3.14159265
#define all(a) (a).begin(),(a).end()
#define forup(i,n) for(int i=0;i<n;i++)
#define forf(i,x,n) for(int i=x;i<n;i++)
#define ford(i,n) for(int (i)=(n)-1;i>=0;(i)--)
#define take(a,n) forup(i,n) cin>>a[i];
using namespace std;

int gcdExtended(int a, int b, int *x, int *y)
{
    // Base Case
    if (a == 0)
    {
        *x = 0, *y = 1;
        return b;
    }

    int x1, y1; // To store results of recursive call
    int gcd = gcdExtended(b%a, a, &x1, &y1);

    // Update x and y using results of recursive
    // call
    *x = y1 - (b/a) * x1;
    *y = x1;

    return gcd;
}

ll modInverse(int a, int m)
{
    int x, y;
    int g = gcdExtended(a, m, &x, &y);
        // m is added to handle negative x
    ll res = ((ll)x%m + (ll)m) % m;

    return res;
}

ll poww(ll x,ll n)
{
    if(n==0)
        return 1;
    else if(n==1) return x;
    else if(n%2 == 0)        //n is even
        return poww(x*x,n/2);
    else                              //n is odd
        return x*poww(x*x,(n-1)/2);
}

ll modularExponentiation(ll x,ll n,ll Z)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%Z;
        x=(x*x)%Z;
        n=n/2;
    }
    return result;
}

template<typename T>
T maxx(T a,T b)
{
  if(a<b) re b;
  re a;
}
template<typename T, typename... Args>
T maxx(T a,T b, Args... args)
{
    re(maxx(maxx(a,b),args...));
}

template<typename T>
T minn(T a,T b)
{
  if(a<b) re a;
  re b;
}
template<typename T, typename... Args>
T minn(T a,T b, Args... args)
{
    re(minn(minn(a,b),args...));
}

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

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

inline ll min(ll a,ll b)
{
  if(a<b) re a;
  else re b;
}
inline ll max(ll a,ll b)
{
  if(a<b) re b;
  else re a;
}

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

    if (a == b)
        return a;

    if (a > b)
        return gcd(a-b, b);
    else return gcd(a, b-a);
}

ll ncr(int n,int r)
{
  ll ans=1;
  r=min(r,n-r);
  forup(i,r)
  {
    ans=((ans*((n-i)%N))%N*modInverse(i+1,N))%N;
  }
  re ans;
}

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

  int t=1;
  //cin>>t;
  while(t--)
  {
    ll n,m,k;
    int a[4];
    for(int i=0;i<4;i++) cin>>a[i];
    cout<<a[0]*a[3]-a[1]*a[2];

  }

  return 0;
}

#include<bits/stdc++.h>

using namespace std;

#define int               long long
#define MOD               1000000007
#define MAX               1000000000
#define ff                first
#define ss                second
#define mp                make_pair
#define pb                push_back
#define setbits(x)        __builtin_popcount(x)
#define fast_in_out       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

//   powermod(a,b,m) ==  powermod(a,b%(m-1),m)  when m is prime fermat's theorem a^(p-1) %p=1 p is prime
int powermod(int a,int b,int c) //  gives (a^b)%c
{
    int ans = 1,tempans=a%c;
    while(b>0)
    {
        if(b&1==1)
        {
            ans=(ans*tempans)%c;
        }
             tempans=(tempans*tempans)%c;
             b=b>>1;
    }
    return ans;
}

int modinverse(int a,int m)   // gives a inverse wrt m and m is prime
{
    return powermod(a,m-2,m);
}
// my template                                              m
// prime factorization                                      pf
// ncr and factorials                                       ncr
// matrix exponentiation of fibonacci series in log(n)      matexpofib

void solve()
{

   int a,b,c,d;
   cin>>a>>b>>c>>d;
   cout << a*d - b*c<<endl;

}

int32_t main()
{
  fast_in_out;

  int t=1;//cin>>t;
  int count=0;

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


//#define _GLIBCXX_DEBUG
//#include "atcoder/all"
//using namespace atcoder;
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
#define Dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) (((n) >> (k)) & 1) /*nのk bit目*/
namespace mydef {
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
bool dbg = true;
}  // namespace mydef
using namespace mydef;
#define pb push_back
//#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define asn ans

int N, M;
string S[101010];
int cnt[10];
vi A;

void solve() {
}

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

    cin >> N >> M;
    A.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> S[i];
        int tmp = 0;
        for (int j = 0; j < M; j++) {
            if (S[i][j] == '1')
                tmp++;
        }
        cnt[tmp % 2]++;
    }
    cout << cnt[0] * cnt[1] << endl;

    solve();
    return 0;
}

#include <iostream>
using namespace std;

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

#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>

int main(){
  int n,m; cin >> n >> m;
  long long even = 0, odd = 0;
  string s;
  rep(i,n){
    cin >> s;
    int x = 0;
    for(char i:s) {
      if (i=='1') x++;
    }
    if (x%2) odd++;
    else even++;
  }
  cout << even*odd << endl;
}