#include <bits/stdc++.h>

using namespace std;

//#pragma GCC optimize("O3")

#define DIM 200009
#define INF ((long long)1e18+9ll)
#define pairll pair<long long,long long>
#define fi first
#define se second
#define ld long double
#define amen exit(0)
#define endl '\n'
#define MODULO 998244353
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)

long long i,j,k,l,n,m;

string a,b;

int main()
{
    fast;

    int nt;
    cin>>nt;
    while(nt--){
        a="atcoder";
        cin>>b;
        if(a<b)cout<<0<<endl;
        else{
            long long res=INF;
            long long pos=-1;
            for(int i=0;i<b.size();i++){
                if(b[i]!='a'){
                    pos=i+1;
                    break;
                }
            }

            if(pos==-1)cout<<-1<<endl;
            else{
                if(b[pos-1]>'t')cout<<pos-2<<endl;
                else cout<<pos-1<<endl;
            }
        }
    }

    amen;
}

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF ((1<<30)-1)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()

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

	int T;
	cin >> T;
	rep(_, T) {
		string s;
		cin >> s;

		string t = s;
		sort(all(t));
		reverse(all(t));
		if (t <= "atcoder") {
			cout << -1 << endl;
			continue;
		}

		int ans = INF;
		int cur = 0;
		rep(i, 7) {
			int idx = -1;
			for (int j = i; j <= s.size(); j++) {
				if ("atcoder"[i] < s[j]) {
					ans = min(ans, cur + j - i);
				}
				else if ("atcoder"[i] == s[j] && idx == -1) {
					idx = j;
				}
			}
			if (idx == -1)break;
			cur += idx - i;
			for (int j = idx - 1; j >= i; j--) {
				s[j + 1] = s[j];
			}
			s[i] = "atcoder"[i];
		}
		if (s.size() > 7 && s.substr(0, 7) == "atcoder")ans = min(ans, cur);
		cout << ans << endl;
	}

	return 0;
}


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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define int long long

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

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1e9;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

signed main() {
    double a,b;
    cin >> a >> b;

    if(a==b){
        cout << a << endl;
    }else {
        cout << 3-a-b << endl;
    }

    return 0;
}

#include <bits/stdc++.h>

#define x first
#define y second

using namespace std;

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

int main()
{
    int a, b;
    cin >> a >> b;
    cout << 1.0 * (a - b) / a * 100 << endl;
    return 0;
}


#include "bits/stdc++.h"

#define REP(i,num) for(ll i=0;i<(num);++i)
#define FOR(i,c,num) for(ll (i)=(c);(i)<(num);++(i))
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){ T x; cin >> x; return (x); }
template<typename T=ll,typename C=vector<T>>
C vecin(int N){ C x(N);REP(i,N){ x[i]=in<T>(); }return x; }

void vout(){ cout << endl; }
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){ cout << ' ' << h;vout(forward<Tail>(t)...); }
void out(){ cout << endl; }
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){ cout << h;vout(forward<Tail>(t)...); }

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

class Data{
public:
	ll X,Y,Z;
};

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

	auto N=in();
	vector<Data> D(N);
	REP(i,N){
		D[i].X=in();
		D[i].Y=in();
		D[i].Z=in();
	}
	ll L = 1ll<<N;
	vvll dp(L,vll(N,1ll<<60));
	dp[0][0] = 0;
	REP(i,L){
		REP(j,N){
			REP(k,N){
				ll to = i | (1ll<<k);
				ll C = abs(D[j].X-D[k].X)+abs(D[j].Y-D[k].Y)+max(0ll,D[k].Z-D[j].Z);
				chmin(dp[to][k],dp[i][j]+C);
			}
		}
	}
	out(dp[L-1][0]);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define M_PI 3.14159265358979323846
#define MOD 1000000007
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> ipair;
typedef pair<ll, ll> llpair;

/*
    Author: Koushik Sahu
    Created: 03 April 2021 Sat 22:14:58
*/

const int nxM = 105;
int h, w, x, y;
string s[nxM];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    cin>>h>>w>>x>>y;
    for(int i=0; i<h; i++) cin>>s[i];
    x--, y--;
    int ans = 1;
    for(int i=x+1; i<h; i++){
        if(s[i][y]=='.') ans++;
        else break;
    }
    for(int i=x-1; i>=0; i--){
        if(s[i][y]=='.') ans++;
        else break;
    }
    for(int i=y+1; i<w; i++){
        if(s[x][i]=='.') ans++;
        else break;
    }
    for(int i=y-1; i>=0; i--){
        if(s[x][i]=='.') ans++;
        else break;
    }
    cout<<ans<<"\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k,m;
  cin>>n>>k>>m;
  vector<int> v(n-1);
  int l=0;
  for(int i=0;i<n-1;i++){
    cin>>v[i];
    l+=v[i]-m;
  }
  l-=m;
  if(l>=0) cout<<0<<endl;
  else if(-1*l<=k) cout<<-1*l<<endl;
  else cout<<-1<<endl;
}

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

int main() {
	int n, k, m; scanf("%d%d%d", &n, &k, &m);
	int sum = 0;
	for (int i = 0; i < n-1; i++) {
		int x; scanf("%d", &x);
		sum += x;
	}

	for (int i = 0; i <= k; i++) {
		if ((sum + i) / n >= m) {
			return !printf("%d\n", i);
		}
	}

	printf("-1\n");
}


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

int main(){

    int x;
    cin>>x;
    for(int i= 1; i<=1001; i++){
    	if(i*100  > x){
    		cout<<i*100-x;
    		break;
		}
	}

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
# define ll long long
# define read read1<ll>()
# define Type template<typename T>
Type T read1(){
	T t=0;
	char k;
	bool vis=0;
	do (k=getchar())=='-'&&(vis=1);while('0'>k||k>'9');
	while('0'<=k&&k<='9')t=(t<<3)+(t<<1)+(k^'0'),k=getchar();
	return vis?-t:t;
}
# define fre(k) freopen(k".in","r",stdin);freopen(k".out","w",stdout)
ll n;
int main(){
	n=read;ll v=9e18,x=0;
	for(ll i=0;i<62;++i)
		if((n>>i)+i+(n&(1ll<<i)-1)<v)
			v=(n>>i)+i+(n&(1ll<<i)-1),x=i;
	cout<<v;
	return 0;
}


#include <bits/stdc++.h>
long long c[61][61];
using namespace std;
int main(){
	c[0][0]=1;
	for(int i=1;i<=60;i++){
		c[i][0]=1;
		for(int j=1;j<=i;j++){
			c[i][j]=c[i-1][j-1]+c[i-1][j];
		}
	}
	int a,b;
	long long k;
	cin>>a>>b>>k;
	int n=a+b;
	for(int i=1;i<=n;i++){
		if(c[n-i][b]>=k){
			cout<<'a';
			a--;
		}
		else{
			cout<<'b';
			k-=c[n-i][b];
			b--;
		}
	}
	return 0;
}

#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; debug_print(__VA_ARGS__); } while(false)
template<typename T, typename... Ts> void debug_print(const T &t, const Ts &...ts) { cerr << t; ((cerr << ", " << ts), ...); cerr << endl; }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, const T& b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, const T& b) { if (a < b) {a = b; return true; } return false; }
template<typename T, typename... Ts> void print(const T& t, const Ts&... ts) { cout << t; ((cout << ' ' << ts), ...); cout << '\n'; }
template<typename... Ts> void input(Ts&... ts) { (cin >> ... >> ts); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int a, b;
    ll k;
    input(a, b, k);
    auto comb = make_v(100, 100, 0LL);
    auto nCr = [&](auto &f, int n, int r) -> ll {
        if (r == 0 || n == r) {
            return 1;
        }
        if (comb[n][r] > 0) return comb[n][r];
        return comb[n][r] = f(f, n - 1, r) + f(f, n - 1, r - 1);
    };
    string ans = "";
    int n = a + b;
    rep(i, 0, n) {
        if (a > 0) {
            ll cnt = nCr(nCr, a + b - 1, b);
            dump(k, cnt, a, b);
            if (k > cnt) {
                k -= cnt;
                ans += 'b';
                b--;
            } else {
                ans += 'a';
                a--;
            }
        } else {
            ans += 'b';
            k--;
            b--;
        }
    }
    print(ans);

    return 0;
}


#include <iostream>
#include <map>
#include <vector>
#include <set>
#include <stack>
#include <bitset>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cassert>
#include <random>

using namespace std;

void solve();

int main() {
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif
    srand(time(0));
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

#define int long long

const int N = 101, A = 2e5 + 100, INF = 1e18;

int n, ans;
string f, s;

void solve() {
    cin >> n >> f >> s;
    vector < int > a, b;
    for (int i = s.size() - 1; i >= 0; i--) {
        if (s[i] == '1') a.push_back(i);
    }
    for (int i = 0; i < f.size(); i++) {
        if (f[i] == '0') continue;
        if (a.empty() || a.back() > i) b.push_back(i);
        else {
            ans += i - a.back();
            a.pop_back();
        }
    }
    if (b.size() % 2 == 1 || !a.empty()) {
        cout << -1;
        return;
    }
    for (int i = 0; i < b.size(); i += 2) {
        ans += b[i + 1] - b[i];
    }
    cout << ans;
}

#include <bits/stdc++.h>
#ifndef ONLINE_JUDGE
#define _GLIBCXX_DEBUG
#endif
using namespace std;
#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 all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define vec vector
#define rip return 0
typedef long long ll;
typedef pair<ll,ll> P;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
if(x<y)return x;
else return y;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout<<fixed<<setprecision(12);
  /*-------------------------------------------*/
  ll r,x,y;
  cin>>r>>x>>y;
  double eu=sqrt(x*x+y*y);
  ll ans=eu/r;
  if(r*ans==eu)cout<<ans<<endl;
  else if(eu>2*r) cout<<ans+1<<endl;
  else cout<<2<<endl;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
using namespace std;

// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")

using ll = long long;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

int sx, sy, gx, gy;
ll score;

inline void query(){
    cin >> sx >> sy >> gx >> gy;
}

string get_str(){
    string res = "";
    while(sx < gx) { res += 'D'; ++sx; }
    while(sx > gx) { res += 'U'; --sx; }
    while(sy < gy) { res += 'R'; ++sy; }
    while(sy > gy) { res += 'L'; --sy; }
    return res;
}

inline void output(string s){
    cout << s << endl;
}

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

    for(int i = 0; i < 1000; ++i){
        query();
        output(get_str());
        cin >> score;
    }

    return 0;
}

//#include <atcoder/all>
//using namespace atcoder;
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPR(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)
#define ALL(v) v.begin(), v.end()
#define bit(n) (1LL<<(n))
#define FIX(d) fixed << setprecision(d)
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const ll LINF = (1LL<<60);

int di[] = {-1, 1, 0, 0};
int dj[] = {0, 0, -1, 1};
const int H = 30, W = 30;

struct edge
{
  int to;
  int cost;

  edge(int _to, int _cost){
    to = _to;
    cost = _cost;
  }
};
using Graph = vector<vector<edge>>;

// 経路復元用
vector<ll> dijkstra(int s, const Graph &G, vector<int> &prev)
{
  int n = G.size();
  priority_queue<P, vector<P>, greater<P>> que;
  vector<ll> d(n, INF);
  prev.resize(n, -1);
  d[s] = 0;
  que.emplace(0, s);

  while (!que.empty()){
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first) continue;

    for(auto nv: G[v]){
      if (d[nv.to] > d[v] + nv.cost){
        d[nv.to] = d[v] + nv.cost;
        prev[nv.to] = v;
        que.emplace(d[nv.to], nv.to);
      }
    }
  }
  return d;
}

string get_path(const vector<int> &prev, int t) {
  vector<int> path;
  for (int cur = t; cur != -1; cur = prev[cur]) {
    path.push_back(cur);
  }
  reverse(path.begin(), path.end());

  string pathString = "";
  REP(i,path.size()-1){
    if(path[i]-path[i+1]==1) pathString.push_back('L');
    else if(path[i]-path[i+1]==-1) pathString.push_back('R');
    else if(path[i]-path[i+1]==W) pathString.push_back('U');
    else pathString.push_back('D');
  }

  return pathString;
}

void init(Graph &G){
  REP(i,H) REP(j,W){
    int cur = i*W+j;
    REP(k,4){
      int ni = i+di[k];
      int nj = j+dj[k];
      if(ni<0 || ni>=H || nj<0 || nj>=H) continue;
      int next = ni*W+nj;
      G[cur].push_back(edge(next, 1000));
      G[next].push_back(edge(cur, 1000));
    }
  }
}

int main() {
  Graph G(H*W);
  init(G);

  REP(q,1000){
    int si, sj, ti, tj;
    cin >> si >> sj >> ti >> tj;
    int sp = si*W+sj;
    int tp = ti*W+tj;
    vector<int> prev;
    auto dist = dijkstra(sp, G, prev);
    string path = get_path(prev, tp);
    cout << path << endl;

    int score;
    cin >> score;
    int score_per = score / path.size();
    int cur = tp;
    while(cur!=sp){
      int next = prev[cur];
      for(auto &eg: G[cur]){
        if(eg.to!=next) continue;
        //chmax(eg.cost, score_per);
        eg.cost = score_per;
      }
      for(auto &eg: G[next]){
        if(eg.to!=cur) continue;
        //chmax(eg.cost, score_per);
        eg.cost = score_per;
      }
      cur = next;
    }
  }

  return 0;
}


#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define P 998244353
#define rep(i,n) for(i=0;i<n;++i)
#define re(i,a,n) for(i=a;i<=n;++i)
#define repr(i,a,n) for(i=a;i>=n;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

ll binpow(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
   while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
ll modInverse(ll n, ll p)
{
    return binpow(n, p-2, p);
}

/*const ll MAXN=4e6+1;
ll spf[MAXN];
void sieve()
{
    spf[1] = 1;
    ll i,j;
    for (i=2; i<MAXN; i++)
          spf[i] = i;

    for (i=4; i<MAXN; i+=2)
        spf[i] = 2;

    for (i=3; i*i<MAXN; i++)
    {

        if (spf[i] == i)
        {

            for (j=i*i; j<MAXN; j+=i)

                if (spf[j]==j)
                    spf[j] = i;
        }
    }
} */

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll m,n,i,f=0,j,ans=0,k,x,r,l,t,y,h,w;
    cin >> h >> w >> n >> m ;
    set<ll> s;
    ll a[h][w];

    ll used[h][w];
    rep(i,h)
    {
      rep(j,w){ a[i][j]=0; used[i][j]=0;}
    }
    vector<vector<ll>> row(h),col(w),rowb(h),colb(w);
    rep(i,n)
    {
        cin >> x >> y ;
        x--;
        y--;
        a[x][y]=1;
    }
    rep(i,m)
    {
      cin >> x>> y ;
      x--;
      y--;
      a[x][y]=-1;
    }

    rep(i,h)
    {
      f=0;
      rep(j,w)
      {
          if(a[i][j]==1)
          {
              f=1;
          }
          else if(a[i][j]==-1) f=-1;
          if(f==1) used[i][j]=1;
      }

    }
    rep(i,h)
    {
      f=0;
      rep(j,w)
      {
          if(a[i][w-j-1]==1)
          {
              f=1;
          }
          else if(a[i][w-j-1]==-1) f=-1;
          if(f==1) used[i][w-j-1]=1;
      }

    }
    rep(j,w)
    {
      f=0;
      rep(i,h)
      {
          if(a[h-i-1][j]==1)
          {
              f=1;
          }
          else if(a[h-i-1][j]==-1) f=-1;
          if(f==1) used[h-i-1][j]=1;
      }

    }
rep(j,w)
    {
      f=0;
      rep(i,h)
      {
          if(a[i][j]==1)
          {
              f=1;
          }
          else if(a[i][j]==-1) f=-1;
          if(f==1) used[i][j]=1;
      }

    }
    rep(i,h)
    {
      rep(j,w)
      {
        if(used[i][j]==1)
        {
          //cout << i << " " << j << endl ;
          ans++;
        }
      }
    }
    cout << ans ;

    return 0;
}

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

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define IN(x,c) (find(c.begin(),c.end(),x) != (c).end())
#define REP(i,n) for (int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for (int i=(a);i<=(b);i++)
#define INIT(a,v) memset(a,v,sizeof(a))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
template<class A, class B> A cvt(B x) { stringstream ss; ss<<x; A y; ss>>y; return y; }

#define SPC << " " <<
#define DEBUG(x) cerr << #x << " = "; cerr << x << endl;
#define DEBUG_ITER(x) cerr << #x << " = "; for (auto _ : x) cerr << _ << ' '; cerr << endl;

typedef pair<int,int> PII;
typedef long long int64;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef vector<double> VD;

#define MOD 1000000007

/* Matrix operations */

typedef int64 Element;
typedef vector<Element> Row;
typedef vector<Row> Matrix;

Matrix zeros(int h, int w) {
    return Matrix(h, Row(w));
}

Matrix identity(int n) {
    Matrix c = zeros(n,n);
    REP (i,n) c[i][i]=1;
    return c;
}

Matrix transpose(const Matrix &a) {
    int h=a[0].size(), w=a.size();
    Matrix t = zeros(h, w);
    REP (i,h) REP (j,w) t[i][j]=a[j][i];
    return t;
}

Matrix operator+(const Matrix &a, const Matrix &b) {
    int h=a.size(), w=a[0].size();
    assert(a.size()==b.size() && a[0].size()==b[0].size());
    Matrix c = zeros(h,w);
    REP (i,h) REP (j,w) {
        c[i][j]=a[i][j]+b[i][j];
        c[i][j]%=MOD;
    }
    return c;
}

Matrix operator+(const Matrix &a, Element k) {
    int h=a.size(), w=a[0].size();
    Matrix c = a;
    REP (i,h) REP (j,w) {
        c[i][j]+=k;
        c[i][j]%=MOD;
    }
    return c;
}

Matrix operator*(Element k, const Matrix &a) {
    int h=a.size(), w=a[0].size();
    Matrix c = a;
    REP (i,h) REP (j,w) {
        c[i][j]*=k;
        c[i][j]%=MOD;
    }
    return c;
}

Matrix operator*(const Matrix &a, const Matrix &b) {
    int h=a.size(), w=b[0].size();
    assert(a[0].size()==b.size());
    Matrix c = zeros(h,w);
    REP (i,h) REP (j,w) {
        REP (k,a[0].size()) {
            c[i][j]+=a[i][k]*b[k][j];
            c[i][j]%=MOD;
        }
    }
    return c;
}

Matrix operator+(Element k, const Matrix &a) {
    return a+k;
}

Matrix operator*(const Matrix &a, Element k) {
    return k*a;
}

Matrix operator-(const Matrix &a, const Matrix &b) {
    return a+(-1)*b;
}

Matrix mat_pow(const Matrix &a, int k) {
    assert(a.size()==a[0].size());
    if (k==0) return identity(a.size());
    if (k%2==0) {
        Matrix c=mat_pow(a,k/2);
        return c*c;
    } else {
        Matrix c=mat_pow(a,k-1);
        return c*a;
    }
}

void mat_print(const Matrix &a) {
    REP (i,a.size()) {
        REP (j,a[i].size()) {
            if (j!=0) cout << " ";
            cout << a[i][j];
        }
        cout << endl;
    }
}

int modPow(int a, int k, int m) {
	if (k==0) return 1;
	else if (k%2==0) {
		int64 b=modPow(a,k/2,m);
		return (b*b)%m;
	} else {
		int64 b=modPow(a,k-1,m);
		return (a*b)%m;
	}
}

int n,m,k;
int a[100];
int deg[100];
vector<int> adj[100];

int main() {
    //freopen("test.in","r",stdin);
    cin >> n >> m >> k;
    REP (i,n) cin >> a[i];
    Matrix A = zeros(n,n);
    REP (i,m) {
        int x,y;
        cin >> x >> y;
        x--; y--;
        adj[x].PB(y); adj[y].PB(x);
        deg[x]++; deg[y]++;
    }
    int64 inv_2m=modPow(2*m,MOD-2,MOD);
    int64 inv_m=modPow(m,MOD-2,MOD);
    REP (i,n) {
        for (int j : adj[i]) {
            A[i][j]=inv_2m; //1.0/(2*m);
            A[i][i]=(A[i][i]+inv_2m)%MOD; //+=1.0/(2*m);
        }
        A[i][i]=(A[i][i]+(m-deg[i])*inv_m)%MOD;
    }
    Matrix v = zeros(n,1);
    REP (i,n) v[i][0]=a[i];
    Matrix Ak = mat_pow(A,k);
    Matrix vk = Ak*v;
    REP (i,n) {
        cout << vk[i][0] << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define _GLIBCXX_DEBUG //gccで配列[]を使った時にバグを検出してくれる
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; }

int main(void){
  int n;
  cin >> n;
  vector<int> a(n);
  int64_t cnt = 0;
  for(int i = 0; i < n; i++){
    cin >> a.at(i);
  }
  for(int i = 0; i < n; i++){
    int x = 0;
    if(a.at(i) > 10){
      x = a.at(i) - 10;
    }
    cnt += x;
  }
  cout << cnt << endl;
}

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

#define pb push_back
#define eb emplace_back
#define mk make_pair
#define fi first
#define se second
#define mset(a, b) memset(a, b, sizeof(a))
using ll = long long;
using pii = pair<int, int>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class Ty> Ty randint(Ty a, Ty b) { return uniform_int_distribution<Ty>(a, b)(rng); }

template<class T> void DBG(T&& x) { cerr << x << " "; }
template<class T, class...Args> void DBG(T&& x, Args&&... args) { DBG(x); DBG(args...); }
#define DBG(...) { cerr << "[" << #__VA_ARGS__ << "]: "; DBG(__VA_ARGS__); cerr << endl; }
template<class num> inline void rd(num& x) { cin >> x; }
template <class Ty, class... Args> inline void rd(Ty& x, Args&... args) { rd(x); rd(args...); }
template<class num> inline void print(num&& x) { cout << x; }
template <class Ty, class... Args> inline void print(Ty&& x, Args&&... args) { print(x); print(' '); print(args...); }
#define print(...) print(__VA_ARGS__), print('\n')

inline void run_test(int test_number) {
	int n, x; rd(n, x);
	for (int i = 0; i < n; i++) {
		int y; rd(y);
		if (y != x) cout << y << " ";
	}
	cout << "\n";
}

int main() {

//#ifndef LOCAL_PC
//	freopen("FILE.in", "r", stdin);
//#endif

	ios::sync_with_stdio(false); cin.tie(nullptr);
	int n_tests = 1;
	for (int i = 1; i <= n_tests; i++) run_test(i);
}


#include <iostream>
using namespace std;
int main() {

    long long n;
    cin >> n;
    long long ans[n];

    ans[0] = 1;

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

        ans[i] = ans[i-1] * (n-i) / i;
    }

    /*for(int i=0;i<n;i++) {

        cout << ans[i] << " ";
    }
    cout << endl;*/

  	cout << ans[11] << endl;
}

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

std::vector<std::vector<long long>> comb(int n, int r) {
  std::vector<std::vector<long long>> v(n + 1,std::vector<long long>(n + 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++) {
    for (int k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
    }
  }
  return v;
}

int main(){
	ll l;
	cin>>l;
	vector<vector<ll>> ans=comb(l,12);
	cout<<ans[l-1][11]<<endl;
	return 0;
}


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

#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++)
#define revrep(i, n) for(ll i = (n)-1; i >=0; i--)
#define P pair<ll,ll>
#define pb push_back
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;
ll MODP = 998244353;
//const ll M = MOD;

template<typename __T__>
int len(vector<__T__> x){
  return int(x.size());
}

template<typename __T__>
void vecout(vector<__T__> x){
  rep(i, len(x)) cout << x[i] << " ";
  cout << endl;
}

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 gen(ll x,ll y){
  if(y == 0)return 1;
  if(y == 1)return x%MOD;
  if(y%2 == 1){
    return ((x%MOD)*gen(x,y-1)%MOD)%MOD;
  }else{
    ll res = gen(x,y/2)%MOD;
    return ((res%MOD)*(res%MOD))%MOD;
  }
}

ll Factorial(ll x,ll y){ //xのy乗
  if(y == 1) return x;
  if(y == 0) return 1;
  if(y%2 == 0){
    ll res = Factorial(x,y/2);
    return res*res;
  }else{
    return x*Factorial(x,y-1);
  }

}

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

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

ll maxn = 1005;
vector<vector<ll>> to(maxn*(maxn-1)/2);
vector<vector<ll>> id(maxn,vector<ll>(maxn,0));
ll toid (ll i,ll j){ //iとjの試合に対応する頂点番号を返す関数
  if(i > j)swap(i,j);
  return id[i][j];
}

int len(string s, string t){
  int dp[s.size()][t.size()];
  rep(i,s.size()) rep(j,t.size()) dp[i][j] = 0;
  ll res = 0;
  rep(i,s.size()){
    rep(j,t.size()) {
      if(s[i] == t[j]){
        if(i < 1 || j < 1){
          dp[i][j] = 1;
        }else{
          dp[i][j] = dp[i-1][j-1] + 1;
        }
      }
      res = lmax(res,dp[i][j]);
    }
  }
  return res;
}

int main(){
  string s;
  cin >> s;
  string ans = "";
  ans += s[1];
  ans += s[2];
  ans += s[0];
  cout << ans << endl;

  return 0;
}

#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <stdlib.h>
#include <vector>
#include <set>
#include <cassert>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;
#define ALL(a)  (a).begin(),(a).end()

int main() {
    ll N,n,ans=0,sum;
    string s;
    vector<ll> L;

    cin >> s;

    n = s.size();

    s = s + s[0];

    s.erase(0,1);

    cout << s;

}


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

long long n;
vector<long long> v(2, 1);

vector<int> solve();

int main() {
  for (int i = 2;; ++i) {
    if (v[i - 2] + v[i - 1] >= 1e18) break;
    v.push_back(v[i - 2] + v[i - 1]);
  }
  cin >> n;
  auto res = solve();
  cout << res.size() << endl;
  for (auto p : res) cout << p << endl;
  return 0;
}

vector<int> solve() {
  vector<int> res;
  long long rem = n;
  for (int i = 86; i; --i) {
    long long now = rem / v[i];
    while (now--) res.push_back(1 + (i & 1));
    rem %= v[i];
    res.push_back(4 - (i & 1));
  }
  long long x = 0, y = 0;
  for (auto p : res) {
    if (p == 1)
      ++x;
    else if (p == 2)
      ++y;
    else if (p == 3)
      x += y;
    else
      y += x;
  }
  assert(x == n);
  assert(res.size() <= 130);
  return res;
}

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

long long X;
vector<long long> fibo = {0,1};
vector<int> ans = {1};
bitset<100> bs;

int main() {
    scanf("%lld", &X);
    while (fibo[fibo.size()-2] + fibo[fibo.size()-1] <= X) fibo.push_back(fibo[fibo.size()-2] + fibo[fibo.size()-1]);
    int K = fibo.size();
    X -= fibo.back();
    while (X) {
        while (fibo.back() > X) fibo.pop_back();
        bs[fibo.size()] = true;
        X -= fibo.back();
    }
    for (int i = 1; i < K-1; ++i) {
        ans.push_back(3+i%2);
        if (bs[K-i]) ans.push_back(1+i%2);
    }
    printf("%d\n", ans.size());
    if (K % 2 == 0) {
        for (int x: ans) printf("%d\n", x);
    }
    else {
        for (int x: ans) {
            if (x <= 2) printf("%d\n", 3-x);
            else printf("%d\n", 7-x);
        }
    }

    return 0;
}


#include <bits/stdc++.h>

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif

    vi a(4);
    forn(i, 4) cin >> a[i];
    bool ok = false;
    forn(mask, 1 << 4) {
        int s = 0;
        forn(i, 4) (s += a[i] * ((mask >> i) & 1 ? 1 : -1));
        ok |= s == 0;
    }
    cout << (ok ? "Yes" : "No") << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}

#include <iostream>
#include <vector>

using namespace std;

int main(){
    vector<int> v(4);
    int sum = 0;
    for(int i=0;i<4;i++){
        cin >> v[i];
        sum += v[i];
    }

    for(int i=1;i<16;i++){
        int tsum = 0;
        for(int j=0;j<4;j++){
            if(i & (1<<j)){
                tsum += v[j];
            }
        }

        if(tsum == sum - tsum){
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
    return 0;
}


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

using ll = long long;
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define POPCOUNT(x) __builtin_popcount(x)
template <typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template <typename T> void chmax(T &a, const T &b) { a = max(a, b); }

const ll INF = 1LL << 60;

struct FastIO {
    FastIO() {
        cin.tie(0);
        ios::sync_with_stdio(0);
    }
} fastiofastio;

const ll MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    REP(i, N) { cout << (i * 2) % N + 1 << " " << (i * 2 + 1) % N + 1 << endl; }
}

#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
#include<cstring>
#include<map>
#include<set>
#include<cstdlib>
#include<bitset>
using namespace std;
#define FAST ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
typedef long long ll;
ll siz[200005],par[200005];
ll mod=998244353;
ll find(ll x)
{
	if(x==par[x]) return x;
	else return par[x]=find(par[x]);
}
void unite(ll x,ll y)
{
	x=find(x);y=find(y);
	if(x==y) return;
	if(siz[x]<=siz[y])
	{
		siz[y]+=siz[x];
		par[x]=y;
	}
	else
	{
		siz[x]+=siz[y];
		par[y]=x;
	}
}
ll go[200005]={0};
int main(void)
{
	ll n;
	scanf("%lld",&n);
	for(ll i=1;i<=n;i++) siz[i]=1,par[i]=i;
	for(ll i=1;i<=n;i++)
	{
		ll u;
		scanf("%lld",&u);
		unite(i,u);
	}
	for(ll i=1;i<=n;i++)
	{
		go[find(i)]=1;
	//	printf("%lld %lld\n",i,find(i));
	}
	ll ans=0;
	for(ll i=1;i<=n;i++) ans+=go[i];
	ll an=1;
	for(ll i=0;i<ans;i++)
	{
		an=an*2%998244353;
	}
	an=an-1;
	an=an%mod+mod;
	an=an%mod;
	cout<<an;
}


#include <bits/stdc++.h>

int main(){

  int N;
  std::cin >> N;
  long A[N];
  long ans;
  long hoge;
  ans =0;
  hoge=0;
  //std::cout <<"A: ";
  for (int i=0;i<N;i++){
    std::cin >> A[i];
   // std::cout <<A[i] <<" ";

  }
  //std::cout <<std::endl;
  std::sort(A,A+N);
  //std::cout << ans << std::endl;

  for (int i=N-1;i>=0;i--){
  	//std::cout << i << " "<< A[i] <<" "<<hoge ;

    if (i==N-1){

      hoge =0;
      }
    else{hoge = 2*hoge+A[i+1];}
	hoge = hoge%998244353;
    ans +=(A[i]*(A[i]+(int)hoge));
    ans = ans%998244353;
  	//std::cout << " "<<hoge<<" "<<ans<<std::endl;

    }
  std::cout << ans%998244353 << std::endl;

}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

/*
    実行時MODint :
    template <int& MOD = 1000000007>
    static int MOD;
    cin >> MOD;
*/
template <int MOD = 1000000007>
struct Mint {
    int x;

    constexpr Mint() : x(0) {}
    constexpr Mint(long long t)
        : x(t >= 0 ? (t % MOD) : (MOD - (-t) % MOD) % MOD) {}

    Mint pow(int n) {
        Mint res(1), t(x);
        while (n > 0) {
            if (n & 1) res *= t;
            t *= t;
            n >>= 1;
        }
        return res;
    }

    Mint inv() const {
        int a = x, b = MOD, u = 1, v = 0, t;
        while (b > 0) {
            t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return Mint(u);
    }

    Mint &operator+=(Mint a) {
        x += a.x;
        if (x >= MOD) x -= MOD;
        return *this;
    }

    Mint &operator-=(Mint a) {
        x += MOD - a.x;
        if (x >= MOD) x -= MOD;
        return *this;
    }

    Mint &operator*=(Mint a) {
        x = int(1LL * x * a.x % MOD);
        return *this;
    }

    Mint &operator/=(Mint a) {
        return (*this) *= a.inv();
    }

    Mint operator+(Mint a) const {
        return Mint(x) += a;
    }
    Mint operator-(Mint a) const {
        return Mint(x) -= a;
    }
    Mint operator*(Mint a) const {
        return Mint(x) *= a;
    }
    Mint operator/(Mint a) const {
        return Mint(x) /= a;
    }

    Mint operator-() const {
        return Mint(-x);
    }

    bool operator==(const Mint a) {
        return x == a.x;
    }
    bool operator!=(const Mint a) {
        return x != a.x;
    }
    bool operator<(const Mint a) {
        return x < a.x;
    }

    friend ostream &operator<<(ostream &os, const Mint &a) {
        return os << a.x;
    }

    friend istream &operator>>(istream &is, Mint &a) {
        int t;
        is >> t;
        a = Mint<MOD>(t);
        return (is);
    }
};

signed main() {
    int n;
    cin >> n;
    char caa, cab, cba, cbb;
    cin >> caa >> cab >> cba >> cbb;
    if (n <= 3) {
        cout << 1 << endl;
        return 0;
    }
    if ((cab == 'A' && caa == 'A') || (cab == 'B' && cbb == 'B')) {
        cout << 1 << endl;
        return 0;
    }
    if ((cab == 'A' && caa == 'B' && cba == 'A') ||
        (cab == 'B' && cbb == 'A' && cba == 'B')) {
        Mint<> dp[n][2];
        dp[0][0] = 1;
        rep(i, n - 1) {
            dp[i + 1][0] += dp[i][1];
            dp[i + 1][1] += (dp[i][0] + dp[i][1]);
        }
        cout << dp[n - 1][1] << endl;
        return 0;
    }
    cout << Mint<>(2).pow(n - 3) << endl;
    return 0;
}


#include<cstdio>
#include<cctype>
#include<algorithm>
#include<cstring>
#include<cmath>
// Standard iostream objects -*- C++ -*-

// Copyright (C) 1997-2014 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.

// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
// <http://www.gnu.org/licenses/>.

/** @file include/iostream
 *  This is a Standard C++ Library header.
 */

//
// ISO C++ 14882: 27.3  Standard iostream objects
//

#ifndef _GLIBCXX_IOSTREAM
#define _GLIBCXX_IOSTREAM 1

#pragma GCC system_header

#include <bits/c++config.h>
#include <ostream>
#include <istream>

namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION

  /**
   *  @name Standard Stream Objects
   *
   *  The <iostream> header declares the eight standard stream
   *  objects.  For other declarations, see
   *  http://gcc.gnu.org/onlinedocs/libstdc++/manual/io.html
   *  and the @link iosfwd I/O forward declarations @endlink
   *
   *  They are required by default to cooperate with the global C
   *  library's @c FILE streams, and to be available during program
   *  startup and termination. For more information, see the section of the
   *  manual linked to above.
  */
  //@{
  extern istream cin;		/// Linked to standard input
  extern ostream cout;		/// Linked to standard output
  extern ostream cerr;		/// Linked to standard error (unbuffered)
  extern ostream clog;		/// Linked to standard error (buffered)

#ifdef _GLIBCXX_USE_WCHAR_T
  extern wistream wcin;		/// Linked to standard input
  extern wostream wcout;	/// Linked to standard output
  extern wostream wcerr;	/// Linked to standard error (unbuffered)
  extern wostream wclog;	/// Linked to standard error (buffered)
#endif
  //@}

  // For construction of filebuffers for cout, cin, cerr, clog et. al.
  static ios_base::Init __ioinit;

_GLIBCXX_END_NAMESPACE_VERSION
} // namespace

#endif /* _GLIBCXX_IOSTREAM */
#define R register

using namespace std;

using namespace std;

typedef long long ll;

const int N =111111;
int n, a[N],p[]={0, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 0, 0};

ll ans;

void dfs(int k,ll b)
{
    if(!p[k])
    {
        int i=1;
        for(i=1;i<=n;i++)
        	if(__gcd(b,(ll)a[i])==1)
        		break;
        if(i==n+1)
        {
            if(!ans)
            	ans=b;
            else ans=min(ans,b);
        }
    }
    else
        dfs(k+1,b),dfs(k+1,b*p[k]);
}

int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    	cin>>a[i];
    dfs(1,1);
    cout<<ans;
    return 0;
}

//Bismillahir Rahmanir Raheem
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>pii;
#define sf(x) scanf("%d",&x)
#define sfl(x) scanf("%lld",&x)
#define lli long long int
#define ll64 int64_t
#define pb push_back
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define frr(i,a) for(int i=0;i<a;i++)
#define frl(i,a) for(lli i=0;i<a;i++)
#define fr1(i,a) for(int i=1;i<=a;i++)
#define iter(x)  x.begin(),x.end()
#define Memset(a,x,n) for(int i=0;i<n;i++)a[i]=x;
#define fi first
#define si second
//lower_bound returns an iterator pointing to the first element in the range [first,last) which has a value not less than ‘val’.
//upper_bound returns an iterator pointing to the first element in the range [first,last) which has a value greater than ‘val’.
typedef pair<lli,lli>pll;
bool isp[102];
const lli mx=50ll;
vector<lli>prime;

void sieve()
{
    memset(isp,1,sizeof(isp));
    isp[0]=isp[1]=0;
    for(int i=4;i<=mx;i+=2)
    {
        isp[i]=0;
    }
    for(int i=3;i*i<=mx;i+=2)
    {
        if(isp[i])
        {
            for(int j=i*i;j<=mx;j+=i)
            {
                isp[j]=0;
            }
        }
    }
    for(lli i=2;i<=mx;i++)
    {
        if(isp[i])
        {
            prime.pb(i);
            //cout<<i<<" ";
        }
    }
    //cout<<endl;
}
void solve()
{
    sieve();
    lli n;
    lli ans=-1;
    //cout<<"ans = "<<ans<<endl;
    cin>>n;
    lli a[n];
    frr(i,n)
    {
        cin>>a[i];

    }
    for(int i=0;i<(1<<15);i++)
    {
        lli res=1ll;
        bool ok=true;
        //cout<<"i = "<<i<<endl;
        for(int j=0;j<15;j++)
        {
            if((i&(1<<j)))
            {
                //cout<<prime[j]<<" ";
                res*=prime[j];
            }
        }
        //cout<<endl;
        for(int j=0;j<n;j++)
        {
            if(__gcd(a[j],res)==1)
            {
                ok=false;
            }
        }

        if(ok)
        {
            //cout<<"res = "<<res<<endl;
            if(ans==-1)
            {
                ans=res;
            }
            else
            ans=min(ans,res);
        }
    }
    cout<<ans<<endl;
}
int main()
{
    int t;
    t=1;
    while(t--)
    {
        solve();
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define sz(x) (ll)x.size()
#define m1(x) memset(x, 1, sizeof(x))
#define m0(x) memset(x, 0, sizeof(x))
#define inf(x) memset(x, 0x3f, sizeof(x))
#define flout cout << fixed << setprecision(12)
#define MOD 1000000007
int main() {
    int n, m;
    cin >> n >> m;
    int a[m], b[m];
    for (int i = 0; i < m; i ++) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }
    int k;
    cin >> k;
    int c[k], d[k];
    for (int i = 0; i < k; i ++) {
        cin >> c[i] >> d[i];
        c[i]--;
        d[i]--;
    }
    bool cur[n];
    int ans = 0;
    for (int i = 0; i < (1 << k); i ++) {
        m0(cur);
        for (int j = 0; j < k; j ++) {
            if ((1 << j) & i) {
                cur[d[j]] = true;
            }
            else {
                cur[c[j]] = true;
            }
        }
        int counter = 0;
        for (int i = 0; i < m; i ++) {
            if (cur[a[i]] && cur[b[i]]) {
                counter ++;
            }
        }
        ans = max(ans, counter);
    }
    cout << ans << endl;
}

#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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;
}
#define int long long
signed main(){
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(all(a));
    vector<int>c(n+1);
    c[0] = k;
    rep(i,n){
        if(c[a[i]]>0){
            c[a[i]]--;
            c[a[i]+1]++;
        }
    }
    ll sm = 0;
    rep(i,n+1){
        sm += c[i]*(ll)i;
    }
    cout << sm << endl;
    return 0;
}


#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define mp make_pair
#define pb push_back
#define pll pair<LL,LL>
#define pii pair<int,int>
#define y second
#define x first
#define LL long long
#define ULL unsigned long long
#define sqr(x) ((x)*(x))
#define pi acos(-1)
#define pdd pair<double,double>
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
using namespace std;
int dp[2][3005][3005];
int mod=998244353;
int DP(int op,int x,int y){
    if(y>x)return 0;
    if(op==0&&y==x)return 1;
    if(x==0&&y==0)return 1;
    if(y<=0)return 0;
    if(x<0)return 0;
    if(dp[op][x][y]!=-1)return dp[op][x][y];
    if(op==0){
        if(y==0)return 0;
        dp[0][x][y]=DP(1,x,y);
    }
    if(op==1){
        dp[1][x][y]=(DP(0,x,y*2)+DP(1,x-1,y-1))%mod;
    }
  //  printf("%d %d %d %d\n",op,x,y,dp[op][x][y]);
    return dp[op][x][y];
}
void solve(){
    int n,k;
    scanf("%d %d",&n,&k);
    MEMS(dp);
    printf("%lld\n",DP(0,n,k));
}
int main(){
    int t=1;
    while(t--){
        solve();
    }
}
/*
11 4 12
1 1 1 1
AABB
.AB.
CCDD
.CD.
EEFF
.EF.
GGHH
.GH.
IIJJ
.IJ.
KKLL

12
0 0
0 -13
3 -13
3 -10
10 -10
10 10
-1 10
-1 13
-4 13
-4 10
-10 10
-10 0

*/

#include <cstdio>
#include <string>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <tuple>

#define max(l,r) ((l)>(r)?(l):(r))
#define min(l,r) ((l)<(r)?(l):(r))
#define rep(i,s,l) for(int i=(int)s;i<(int)l;++i)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;

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

const long long INF = 1LL<<60;
const long long MOD = 1000000007;

int main() {
  int n,k;
  cin >> n >> k;
  ll ans = 0LL;
  rep(i,1,n+1) {
    rep(j,1,k+1) {
      ans += i*100+j;
    }
  }
  cout << ans << endl;
}


#include <bits/stdc++.h>
//#define DEBUG
#define REP(i, nn ) for(int i = 0 ; i < (int) nn; i++)
#define deb(x) std::cout << #x << " " << x << endl;
#define debl(x) std::cout << #x << " " << x << " ";
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
template<typename... T>
void read(T& ... a){
    ((cin >> a),...);
}
template<typename... T>
void write(T... a){
    ((cout << a << "\n"),...);
}

template<typename... T>
void write_space(T... a){
    ((cout << a << " "),...);
}
const string s = "110";
const int sz = s.size();
constexpr ll L = 3e10;

void solve(){
    ll n ;
    cin >>n;
    string t;
    cin >> t;
    if( n == 1){
        if(t[0] == '1'){
            cout << 2 * L / 3 << endl;
        }else{
            cout << L / 3 << endl;
        }
        return;
    }
    bool match;
    int start = -1;
    for(start = 0 ; start < sz; start++){
        match = true;
        for(int i = 0 ; i < (int) t.size(); i++){
            int j = (i + start) % sz;
            if( t[i] != s[j]){
                match = false;
                break;
            }
        }
        if(match) break;
    }
    if(match == false){
        cout << 0 << endl;
    }else{
        assert(start >= 0);
        ll end = L - n;
        // debl(start) deb(end)
        ll ans = end / 3;
        if(end % 3 >= start){
            ans++;
        }
        cout << ans << endl;
    }
}

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/
    solve();
    return 0;
}

#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>
#include <functional>
#include <iomanip>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);
constexpr int INF = (1 << 30);
//constexpr ll INF = (1LL << 60);

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

	ll ans = 0LL;

	if( n == 1 ) {
		if( t == "1" ) {
			ans = 2LL * 1e10;
		} else {
			ans = 1e10;
		}
	} else if( n == 2 && t == "11" ) {
		ans = 1e10;
	} else {
		bool f = true;
		int num_zero = 0;

		for(int i = 0; i < n; ++i) {
			if( i < n - 1 ) {
				string tmp = t.substr(i, 2);

				if( tmp == "00" ) {
					f = false;
					break;
				}
			}

			if( t[i] == '0' ) num_zero++;
		}

		for(int i = 0; i < n - 2; ++i) {
			string tmp = t.substr(i, 3);

			if( tmp == "111" || tmp == "010" ) {
				f = false;
				break;
			}
		}

		if( f ) {
			if( t.back() == '0' ) {
				ans = 1e10 - num_zero + 1;
			} else {
				ans = 1e10 - num_zero;
			}
		}
	}

	cout << ans << endl;

	return 0;
}


/*
Author: QAQAutoMaton
Lang: C++
Code: B.cpp
Mail: lk@qaq-am.com
Blog: https://www.qaq-am.com/
*/
#include<bits/stdc++.h>
#define debug(qaq...) fprintf(stderr,qaq)
#define DEBUG printf("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define Debug debug("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define all(x) x.begin(),x.end()
#define x first
#define y second
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())
using namespace std;
typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef complex<double> cp;
typedef pair<int,int> pii;
int inf;
const double eps=1e-8;
const double pi=acos(-1.0);
template<class T,class T2>int chkmin(T &a,T2 b){return a>b?a=b,1:0;}
template<class T,class T2>int chkmax(T &a,T2 b){return a<b?a=b,1:0;}
template<class T>T sqr(T a){return a*a;}
template<class T,class T2>T mmin(T a,T2 b){return a<b?a:b;}
template<class T,class T2>T mmax(T a,T2 b){return a>b?a:b;}
template<class T>T aabs(T a){return a<0?-a:a;}
template<class T>int dcmp(T a,T b){return a>b;}
template<int *a>int cmp_a(int x,int y){return a[x]<a[y];}
template<class T>bool sort2(T &a,T &b){return a>b?swap(a,b),1:0;}
#define min mmin
#define max mmax
#define abs aabs
struct __INIT__{
	__INIT__(){
		fill((unsigned char*)&inf,(unsigned char*)&inf+sizeof(inf),0x3f);
	}
}__INIT___;
namespace io {
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	// getchar
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	// print the remaining part
	inline void flush () {
		fwrite (obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	// putchar
	inline void putc (char x) {
		*oS ++ = x;
		if (oS == oT) flush ();
	}
	template<typename A>
	inline bool read (A &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;else if(c==EOF)return 0;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = x * 10 + (c & 15); x *= f;
		return 1;
	}
	inline bool read (char &x) {
		while((x=gc())==' '||x=='\n' || x=='\r');
		return x!=EOF;
	}
	inline bool read(char *x){
		while((*x=gc())=='\n' || *x==' '||*x=='\r');
		if(*x==EOF)return 0;
		while(!(*x=='\n'||*x==' '||*x=='\r'||*x==EOF))*(++x)=gc();
		*x=0;
		return 1;
	}
	template<typename A,typename ...B>
	inline bool read(A &x,B &...y){
		return read(x)&&read(y...);
	}
	template<typename A>
	inline bool write (A x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
		return 0;
	}
	inline bool write (char x) {
		putc(x);
		return 0;
	}
	inline bool write(const char *x){
		while(*x){putc(*x);++x;}
		return 0;
	}
	inline bool write(char *x){
		while(*x){putc(*x);++x;}
		return 0;
	}
	template<typename A,typename ...B>
	inline bool write(A x,B ...y){
		return write(x)||write(y...);
	}
	//no need to call flush at the end manually!
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io :: read;
using io :: putc;
using io :: write;
int fpm(int a,int b,int p){
	a%=p;
	int c=1;
	for(;b;b>>=1,a=a*a%p)if(b&1)c=c*a%p;
	return c;
}
int xfpm(int a,int b){
	if(a==1||(a<4 && b==1))return fpm(a,b,4);
	else return fpm(a,b,4)+4;
}
signed main(){
#ifdef QAQAutoMaton
	freopen("B.in","r",stdin);
	freopen("B.out","w",stdout);
#endif
	int a,b,c;
	read(a,b,c);
	a%=10;
	/*for(int i=1;i<10;++i){
		write(i,i*i%10,i*i*i%10,i*i*i*i%10,i*i*i*i*i%10,'\n');
	}*/
	write(fpm(a,xfpm(b,c),10),'\n');
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define mp(a,b) make_pair(a,b)
#define vi vector<int>
#define mii map<int,int>
#define mpi map<pair<int,int>,int>
#define vp vector<pair<int,int> >
#define pb(a) push_back(a)
#define fr(i,n) for(i=0;i<n;i++)
#define rep(i,a,n) for(i=a;i<n;i++)
#define F first
#define S second
#define endl "\n"
#define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define dom 998244353
#define pi 3.14159265
#define sl(a) (int)a.length()
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define mini 2000000000000000000
#define time_taken 1.0 * clock() / CLOCKS_PER_SEC
//mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
//primes for hashing 937, 1013
template<typename T, typename U> static inline void amin(T &x, U y)
{
    if (y < x)
        x = y;
}
template<typename T, typename U> static inline void amax(T &x, U y)
{
    if (x < y)
        x = y;
}
void shikhar7s(int cas)
{
    int x,y;
    cin>>x>>y;
    if(!x)
        cout<<y<<endl;
    else if(x>0)
    {
        if(y<3)
            cout<<y+1<<endl;
        else
            cout<<y+min(2*x,y)-1<<endl;
    }
    else
    {
        if(y<3)
            cout<<y+1<<endl;
        else
            cout<<y+min(1-2*x,y)-1<<endl;
    }
}
signed main()
{
    fast;
    //freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
    int t=1;
    //cin>>t;
    int cas=1;
    while(cas<=t)
    {
    shikhar7s(cas);
    cas++;
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int _ = (cout << fixed << setprecision(9), cin.tie(0), ios::sync_with_stdio(0));
using Int = long long;
int main() {
    Int B, C; cin >> B >> C;
    vector<pair<Int, Int>> sec;
    sec.emplace_back(B - C/2, B);
    sec.emplace_back(-B - (C-1)/2, -B);
    sec.emplace_back(-B, -B + (C-1)/2);
    sec.emplace_back(B, B + (C-2)/2);
    Int ans = 0, rmax = LLONG_MIN;
    sort(begin(sec), end(sec));
    for (auto [l, r] : sec) {
        l = max(l, rmax + 1);
        ans += r - l + 1;
        rmax = max(rmax, r);
    }
    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define ALL(x) (x).begin(),(x).end()
template<class T>bool umax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;}
template<class T>bool umin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;}
#ifdef LOCAL
void _debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void _debug_out(Head H, Tail... T) { cerr << " " << to_string(H); _debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", _debug_out(__VA_ARGS__)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...) 42
#define eprintf(...) 42
#endif

int main() {
  int a,b,c,d; cin >> a >> b >> c >> d;
  cout << a*d-b*c<<endl;
}


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

#define int long long int
#define endl "\n"
#define aashish_999 ios_base::sync_with_stdio(false);cin.tie(NULL)

void solve()
{
	//read the question properly
	string s;
	cin >> s;
	string f, r;
	f = r = "";

	bool flag = false;
	int cnt = 0;

	for (auto i : s) {
		if (i == 'R')
			flag = !flag, ++cnt;
		else if (flag)
			r += i;
		else
			f += i;
	}

	string final;
	if (cnt % 2 == 0)
		reverse(r.begin(), r.end()), final = r + f;
	else reverse(f.begin(), f.end()), final = f + r;
	string ans = "";
	for (int i = 0; i < final.length(); i++) {
		if (ans.empty()) {
			ans += final[i];
			continue;
		}
		if (ans.back() == final[i]) {
			ans.pop_back();
		}
		else ans.push_back(final[i]);
	}

	cout << ans;
}

int32_t main()
{
	aashish_999;

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

#define _USE_MATH_DEFINES

#include <iostream>
#include <cstring>
#include <regex>
#include <cmath>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <unordered_set>
#include <queue>
#include <unordered_map>
#include <set>
#include <cassert>
#include <climits>

#pragma GCC optimize("O3")

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

#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repd(i, n) for(ll i = (n) - 1ll; i >= 0; --i)
#define FOR(i, a, b) for(ll i = a; i < ll(b); ++i)
#define FORD(i, a, b) for(ll i = a; i > ll(b); --i)
#define foreach(i, itr) for(auto& i : (itr))
#define asort(arr, size) std::sort(arr, arr + size)
#define dsort(arr, size) std::sort(arr, arr + size, [](auto a, auto b) { return a > b; })
#define cauto const auto&
#define bit(n) (1LL << (n))

////////////////////////////////////
// ここから下に任意のコードを書く //
////////////////////////////////////

int main() {
    string S;
    cin >> S;
    deque<char> T;
    bool R = false;
    rep(i, S.size()) {
        if (S[i] == 'R') {
            R = !R;
        }
        else if (T.empty()) {
            T.push_back(S[i]);
        }
        else if (R) {
            if (T.front() == S[i]) {
                T.pop_front();
            }
            else {
                T.push_front(S[i]);
            }
        }
        else {
            if (T.back() == S[i]) {
                T.pop_back();
            }
            else {
                T.push_back(S[i]);
            }
        }
    }
    if (R) {
        for_each(T.rbegin(), T.rend(), [](char c) { cout << c; });
    }
    else {
        for (char c : T) {
            cout << c;
        }
    }
    cout << endl;
    return 0;
}

//ll abi[5000][5];
//ll dp[5000][3][5];
//
//ll getPower(int index) {
//    ll res = INT_MAX;
//    rep(i, 3) {
//        ll mx = 0;
//        rep(j, 5) {
//            mx = max(mx, dp[index][i][j]);
//        }
//        res = min(res, mx);
//    }
//    return res;
//}
//
//int main()
//{
//    int N;
//    cin >> N;
//    rep(i, N) cin >> abi[i][0] >> abi[i][1] >> abi[i][2] >> abi[i][3] >> abi[i][4];
//
//    dp[0][0][0] = abi[0][0];
//    dp[0][0][1] = abi[0][1];
//    dp[0][0][2] = abi[0][2];
//    dp[0][0][3] = abi[0][3];
//    dp[0][0][4] = abi[0][4];
//    FOR(i, 1, N) {
//        int index = -1;
//        rep(j, 3) {
//            rep(k, 5) {
//                dp[i][j][k] = dp[i - 1][j][k];
//            }
//        }
//        ll res = INT_MAX;
//        rep(j, 3) {
//            ll mx = 0;
//            rep(k, 5) {
//                mx = max(mx, dp[i][j][k]);
//            }
//            res = min(res, mx);
//        }
//    }
//
//    return 0;
//}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll,ll>;
using pld = pair<ld,ld>;
using vll = vector<ll>;
using vld = vector<ld>;
using vstr = vector<string>;
#define _GLIBCXX_DEBUG
#define rep(j, m) for (ll j = 0; j < (ll)(m); j++)
#define rep2(i, l, n) for (ll i = l; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
const ld PI = 3.1415926535897932;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
vll dx = {-1,0,1,0};
vll dy = {0,-1,0,1};
vll Dx = {-1,-1,-1,0,0,1,1,1};
vll Dy = {-1,0,1,-1,1,-1,0,1};
const ll INF = 1000000000000000;

int main() {
   ll N;
   cin >> N;
   vector<pll> X(N);
   vector<pll> Y(N);
   rep(i,N) {
      cin >> X[i].first >> Y[i].first;
      X[i].second = i;
      Y[i].second = i;
   }
   sort(all(X));
   sort(all(Y));
   ll x1 = X[N - 1].first - X[0].first;
   ll y1 = Y[N - 1].first - Y[0].first;
   ll x21 = X[N - 2].first - X[0].first;
   ll y21 = Y[N - 2].first - Y[0].first;
   ll x22 = X[N - 1].first - X[1].first;
   ll y22 = Y[N - 1].first - Y[1].first;
   if (x1 > y1) {
      if ((X[N - 1].second == Y[N - 1].second && X[0].second == Y[0].second)||
      (X[N - 1].second == Y[0].second && X[0].second == Y[N - 1].second)) {
         cout << max(max(x21,x22),max(y21,y22)) << endl;
      }
      else {
         cout << max(x21,max(x22,y1)) << endl;
      }
   }
   else {
      if ((X[N - 1].second == Y[N - 1].second && X[0].second == Y[0].second)||
      (X[N - 1].second == Y[0].second && X[0].second == Y[N - 1].second)) {
         cout << max(max(x21,x22),max(y21,y22)) << endl;
      }
      else {
         cout << max(x1,max(y21,y22)) << endl;
      }
   }
}

#include <bits/stdc++.h>

using namespace std;

#define il inline
#define re register
#define rep(i, s, e) for (re int i = s; i <= e; ++i)
#define drep(i, s, e) for (re int i = s; i >= e; --i)
#define file(a) freopen(#a".in", "r", stdin), freopen(#a".out", "w", stdout)

const int mod = 998244353;
const int inv2 = (mod + 1) >> 1;

const int N = 200010;

il int read() {
    int x = 0; bool f = true; char c = getchar();
    while (!isdigit(c)) {if (c == '-') f = false; c = getchar();}
    while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
    return f ? x : -x;
}

il int inc(int a, int b) { return (a += b) >= mod ? a - mod : a; }
il int dec(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
il int mul(int a, int b) { return 1ll * a * b % mod; }

int inv[N];
il void init(int w) {
    inv[1] = 1;
    rep(i, 2, w) inv[i] = mod - mul(mod / i, inv[mod % i]);
}

int n, m, f[N];
int tot, p[N], minv[N];
bool isnp[N];

il void filt() {
    f[1] = 1;
    rep(i, 2, m) {
        if (!isnp[i]) p[++tot] = i, f[i] = n, minv[i] = 1;
        for (re int j = 1; j <= tot && i * p[j] <= m; ++j) {
            isnp[i * p[j]] = true;
            if (i % p[j]) f[i * p[j]] = mul(f[i], n), minv[i * p[j]] = 1;
            else { f[i * p[j]] = mul(f[i], mul(n + minv[i], inv[minv[i] + 1])), minv[i * p[j]] = minv[i] + 1; break; }
        }
    }
}

int main() {
    n = read(), m = read(), init(200000);
    filt();
    int ans = 0;
    rep(i, 1, m) ans = inc(ans, f[i]);
    printf("%d\n", ans);
    return 0;
}


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

ll mod = 1000000007;

int main() {
    ll N; cin >> N;
    vector<char> col = {'R','G','B'};
    vector<vector<ll>> cute(3);
    rep(i,2*N){
        ll a; char c; cin >> a >> c;
        rep(j,3){
            if(c==col[j]) cute[j].push_back(a);
        }
    }
    bool even[3];
    rep(i,3){
        cute[i].push_back(2e18);
        cute[i].push_back(-2e18);
        sort(cute[i].begin(),cute[i].end());
        if(cute[i].size()%2==0) even[i] = true;
        else even[i] = false;
    }
    if(even[0]&&even[1]&&even[2]){
        cout << 0 << endl; return 0;
    }
    ll md[3];
    rep(i,3) md[i] = 2e18;
    rep(i,3){
        rep(j,3){
            if(i<=j) continue;
            int k = 3-i-j;
            int M = cute[i].size()-2;
            for(int l=1;l<=M;l++){
                ll c = cute[i][l];
                int s = lower_bound(cute[j].begin(),cute[j].end(),c)-cute[j].begin();
                md[k] = min({md[k],abs(c-cute[j][s]),abs(c-cute[j][s-1])});
            }
        }
    }
    ll ans = 2e18;
    rep(i,3){
        if(even[i]) ans = min(ans,md[i]);
        //cout << md[i] << endl;
        rep(j,3){
            if(i<=j) continue;
            if(!even[i]&&!even[j]) ans = min(ans,md[i]+md[j]);
        }
    }
    cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define deb(...)
#endif
#define endl "\n"
#define pb push_back
#define int long long
#define ll long long
#define pii pair<int,int>
#define F first
#define S second
#define all(c) c.begin(),c.end()
#define read(v) for(auto &it:v) cin>>it;
const int inf = 1e18;
const int N   = 2e5 + 5;
const int mod = 1000000007;
vector <int> adj[4];
int solve(vector <int> &B, vector <int> &C) {
    int ans = inf;
    if (B.empty() || C.empty()) {
        return ans;
    }
    for (auto it : B) {
        // find best match for this in C?
        auto x = lower_bound(all(C), it);
        if (x == C.end()) {
            ans = min(ans, abs(it - *C.rbegin()));
        }
        else {
            if (x == C.begin()) {
                ans = min(ans, abs(it - *C.begin()));
            }
            else {
                ans = min(ans, abs(it - *x));
                x--;
                ans = min(ans, abs(it - *x));
            }
        }
    }
    for (auto it : C) {
        // find best match for this in C?
        auto x = lower_bound(all(B), it);
        if (x == B.end()) {
            ans = min(ans, abs(it - *B.rbegin()));
        }
        else {
            if (x == B.begin()) {
                ans = min(ans, abs(it - *B.begin()));
            }
            else {
                ans = min(ans, abs(it - *x));
                x--;
                ans = min(ans, abs(it - *x));
            }
        }
    }
    return ans;

}
void test_case() {
    int n;
    cin >> n;
    for (int i = 0; i < 2 * n; i++) {
        int a;
        char b;
        cin >> a >> b;
        if (b == 'R') {
            adj[1].pb(a);

        } else if (b == 'G') {
            adj[2].pb(a);

        } else {
            adj[3].pb(a);
        }
    }
    sort(all(adj[1]));
    sort(all(adj[2]));
    sort(all(adj[3]));

    int r = adj[1].size(), g = adj[2].size(), b = adj[3].size();
    int cnt = 0, who = -1;
    for ( int val : {r, g, b}) {
        if (val % 2 == 1) {

            cnt++;
        }
        else {
            if (val == r) {
                who = 1;
            }
            else if (val == g) {
                who = 2;
            }
            else {
                who = 3;
            }
        }
    }
    if (cnt == 0) {
        cout << 0 << endl;
        return;
    }
    if (cnt == 1 || cnt == 3) {
        assert(false);
    }
    vector <int> A = adj[who];
    set <int> st = {1, 2, 3};
    st.erase(who);
    vector <int> B = adj[*st.begin()];
    vector <int> C = adj[*st.rbegin()];
    cout << min(solve(B, C), solve(A, C) + solve(A, B)) << endl;

}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int  t = 1;
    // cin >> t;
    while (t--)test_case();
    return 0;
}


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

int main () {
    ll n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> b(n);
    vector<ll> c(n);
    rep(i,n) cin >> a.at(i);
    rep(i,n) cin >> b.at(i);
    ll maxv = a.at(0);
    c.at(0) = a.at(0) * b.at(0);
    for (int i = 1; i < n; i++) {
        maxv = max(maxv, a.at(i));
        c.at(i) = max(c[i - 1], maxv * b.at(i));
    }
    for (auto i : c) {
        cout << i << endl;
    }
}

#include <iostream>
#include <fstream>
#include <string>

using namespace std;
int main()
{
	int N;
	cin>>N;
	int a[N];
	int b[N];
	for(int i=0;i<N;i++){
		cin>>a[i];
		if(i>0){
			if (a[i]<a[i-1]){
				a[i]=a[i-1];
			}
		}
	}
	for(int i=0;i<N;i++){
		cin>>b[i];
	}
	long long int before=0;
	for(int i=0;i<N;i++){
		long long int out=a[i]*b[i];
		if(out<before){
			out=before;
		}else{
			before=out;
		}
		cout<<out<<endl;
	}
return 0;
}


/**

   * Made by:    Diego Briaares
   * At:   07.03.2021 18:28:23
**/

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

void optimize() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
}

void test_case() {
	int n;
	cin >> n;
	string s1, s2, s3;
	cin >> s1 >> s2 >> s3;
	s1 += s1;
	s2 += s2;
	s3 += s3;
	vector<string> cand;
	string a, b;
	for (int i = 0; i < n; i++) a.push_back('0');
	for (int i = 0; i < n; i++) b.push_back('1');
	string c = a + b + "0";
	cout << c << "\n";
}

	int main () {
		optimize();
		int t;
		cin >> t;
		while (t--) {
			test_case();

		}
	}

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
const int N = 1e6 + 5;
using namespace std;

int cas, n;
char s[3][N], T[N];

template < typename T >
inline T read()
{
	 T x = 0, w = 1; char c = getchar();
	 while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
	 while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	 return x * w;
}

bool check()
{
	 bool flag = 1; int pos = 1;
	 for(int op = 0; op < 3; op++)
	 {
		  pos = 1;
		  for(int i = 1; i <= 4 * n; i++)
				if(pos <= 2 * n + 1 && T[pos] == s[op][i > 2 * n ? i - 2 * n : i]) pos++;
		  flag &= pos > 2 * n;
	 }
	 return flag;
}

int main()
{
#ifndef ONLINE_JUDGE
	 freopen("cpp.in", "r", stdin);
#endif
	 cas = read <int> ();
	 while(cas--)
	 {
		  n = read <int> (), scanf("%s", s[0] + 1), scanf("%s", s[1] + 1), scanf("%s", s[2] + 1);
		  for(int i = 1; i <= n; i++) T[i] = '1', T[n + i] = '0'; T[2 * n + 1] = '1';
		  if(check()) { for(int i = 1; i <= 2 * n + 1; i++) printf("%c", T[i]); puts(""); continue; }
		  for(int i = 1; i <= n; i++) T[i] = '1', T[n + i] = '0'; T[2 * n + 1] = '0';
		  if(check()) { for(int i = 1; i <= 2 * n + 1; i++) printf("%c", T[i]); puts(""); continue; }
		  for(int i = 1; i <= n; i++) T[i] = '0', T[n + i] = '1'; T[2 * n + 1] = '0';
		  if(check()) { for(int i = 1; i <= 2 * n + 1; i++) printf("%c", T[i]); puts(""); continue; }
		  for(int i = 1; i <= n; i++) T[i] = '0', T[n + i] = 1; T[2 * n + 1] = '1';
		  if(check()) { for(int i = 1; i <= 2 * n + 1; i++) printf("%c", T[i]); puts(""); continue; }
		  T[1] = '0'; for(int i = 1; i <= n; i++) T[i + 1] = '1', T[n + i + 1] = '0';
		  if(check()) { for(int i = 1; i <= 2 * n + 1; i++) printf("%c", T[i]); puts(""); continue; }
		  T[1] = '1'; for(int i = 1; i <= n; i++) T[i + 1] = '1', T[n + i + 1] = '0';
		  if(check()) { for(int i = 1; i <= 2 * n + 1; i++) printf("%c", T[i]); puts(""); continue; }
		  T[1] = '1'; for(int i = 1; i <= n; i++) T[i + 1] = '0', T[n + i + 1] = '1';
		  if(check()) { for(int i = 1; i <= 2 * n + 1; i++) printf("%c", T[i]); puts(""); continue; }
		  T[1] = '0'; for(int i = 1; i <= n; i++) T[i + 1] = '0', T[n + i + 1] = '1';
		  if(check()) { for(int i = 1; i <= 2 * n + 1; i++) printf("%c", T[i]); puts(""); continue; }
	 }
	 return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N=205;
int n,ma[N],tmp[N];
bool ok=1,can[N][N],f,dp[N];

int main()
{
	scanf("%d",&n);
	for(int i=1,ai,bi;i<=n;i++){
		scanf("%d%d",&ai,&bi);
		if(ai>0 && ma[ai]) ok=0;
		if(bi>0 && ma[bi]) ok=0;
		if(ai>0 && bi>0)
			ma[ai]=bi,ma[bi]=ai;
		else if(ai>0) ma[ai]=-1;
		else if(bi>0) ma[bi]=-2;
//		cout<<i<<" "<<ok<<endl;
	}
	if(!ok){
		printf("No\n");
		return 0;
	}
	n<<=1;
//	for(int l=1;l<=n;l++)
//		cout<<ma[l]<<" ";
//	cout<<endl;
	for(int l=1;l<=n;l++)
		for(int r=l;r<=n;r++){
			if((r-l+1)%2) continue;f=1;
			int k=(r-l+1)/2;
			for(int i=l;i+k<=r;i++){
				if(ma[i]>0 && ma[i]!=i+k) f=0;
				if(ma[i+k]>0 && ma[i+k]!=i) f=0;
				if(ma[i] && ma[i+k] && ma[i]!=i+k) f=0;
				if(ma[i]==-2 || ma[i+k]==-1) f=0;
			}
			can[l][r]=f;
		}
//	cout<<can[1][2]<<endl;
	dp[0]=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<i;j++)
			if(dp[j] && can[j+1][i])
				dp[i]=1;
//		cout<<dp[i]<<" ";
	}
//	cout<<endl;
	if(dp[n]) printf("Yes\n");
	else printf("No\n");
	return 0;
}

// author: xay5421
// created: Sat May 29 20:25:20 2021
#ifdef xay5421
#define D(...) fprintf(stderr,__VA_ARGS__)
#else
#define D(...) ((void)0)
//#define NDEBUG
#endif
#include<bits/stdc++.h>
#define SZ(x) ((int)(x).size())
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
using namespace std;
const int N=505;
int T,n,a[N];
bool ok(){
	rep(i,1,n)if(a[i]!=i)return 0;
	return 1;
}
int main(){
#ifdef xay5421
	freopen("a.in","r",stdin);
#endif
	scanf("%d",&T);
	rep(_,1,T){
		D("_=%d\n",_);
		scanf("%d",&n);
		rep(i,1,n)scanf("%d",&a[i]);
		vector<int>ans;
		while(1){
			if(ok())break;
			bool flg=0;
			for(int i=(n-1)&1?n-1:n-2;i>=1;i-=2){
				if(a[i]>a[i+1]){
					swap(a[i],a[i+1]),ans.push_back(i);
					flg=1;
					break;
				}
			}
			if(flg==0){
				swap(a[1],a[2]),ans.push_back(1);
			}
			if(ok())break;
			flg=0;
			for(int i=2;i<n;i+=2){
				if(a[i]>a[i+1]){
					swap(a[i],a[i+1]),ans.push_back(i);
					flg=1;
					break;
				}
			}
			if(flg==0){
				swap(a[2],a[3]),ans.push_back(2);
			}
		}
		printf("%d\n",SZ(ans));
		for(int x:ans)printf("%d ",x);
		puts("");
	}
	return 0;
}


/* Piyush Sharma*/

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

int main()
{
    ll testcase = 1;
    // ll testcase;
    // cin >> testcase;

    while (testcase > 0)
    {
        double n, D, H;
        cin >> n >> D >> H;

        double maxVal = INT_MIN;
        double backup = 0 * 1.0000;

        while ( n > 0 ) {
            double d, h;
            cin >> d >> h;

            double res = double((h*1.0) - ((d*1.0)*(((H-h)*1.0)/(D-d))));
            if ( res >= maxVal ) {
                maxVal = res;
            }
            n--;
        }

        if ( maxVal <= 0 ) {
            cout << setprecision(16) << backup;
        }
        else {
            cout << setprecision(16) << maxVal;
        }

        testcase--;
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,t,n) for(int64_t i=t;i<n;i++)
#define Sort(a) sort(a.begin(),a.end())
#define rSort(a,n,m) sort(a.begin()+n-1,a.begin()+m)
#define Reverse(a) reverse(a.begin(),a.end())
#define rReverse(a,n,m) reverse(a.begin()+n-1,a.begin()+m)
#define MOD 1000000007
#define sign(i) -1*pow(-1,i)
#define vi(A,N,i)  vector<int64_t> A(N,i)
#define vs(A,N,i)  vector<string> A(N,i)
#define vb(A,N,i)  vector<bool> A(N,i)
#define INF ((1LL<<62)-(1LL<<31))
//((a+b+c)-max(a,max(b,c))-min(a,min(b,c)))

/*template <class T>

}*/

//cout << fixed << setprecision(桁数);

int64_t def_str(string x,string y){
  int64_t def=0;
  rep(i,0,(int64_t)x.size()){
    if(x[i]!=y[i]){
      def++;
    }
  }
  return def;
}

int main() {
  //int64_t a,b,c,d,e,f,g,h,hi,ans=0,now_ans=0,mlt_ans=1;
  double a,b,c,d,e,f,ans=0,now_ans=0,mlt_ans=1;
  string x,y,z;
  char s,t,u;
  bool frag=false,frag1=false,frag2=false;
  vector<int64_t> A{},B{},C{},D{};
  vector<string> Cg{},Dg{};
  vector<char> E{},F{};
  vector<bool> G(26,false);
  cin>>a>>b>>c;
  //cin>>x;
  //cin>>s>>t;////////////////////////
  rep(i,0,a){
    cin>>d>>e;
    f=-(b*(c-e)/(b-d))+c;
    ans=max(ans,f);
  }
  cout << fixed << setprecision(20);
  cout<<ans;
}


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

using ll=long long ;

#define rep(i,n)  for(int i=0;i<(n);i++)
#define f first
#define sc second
const int mod=1'000'000'007;

// UnionFind
// coding: https://youtu.be/TdR816rqc3s?t=726
// comment: https://youtu.be/TdR816rqc3s?t=6822
struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};

int fact(int n){
if(n==0){
     return 1;
 }else{
     return n*fact(n-1);
 }
}

bool is_prime(int x){
if(x<=1) return false;
for(int i=2;i*i<x;i++){
    if(x%i==0) return false;}
return true;}

template<class T>void chmin(T& a,T b){
    if(a>b){
        a=b;
    }
}

template<class T>void chmax(T& a,T b){
    if(a<b){
        a=b;
    }
}
int gcd(int x, int y) {
     if(x % y == 0) {
        return y;
     } else {
        return gcd(y, x % y);
     }
}

ll f(ll x,ll c,ll d){
    return x-x/c-x/d+x/(c/(gcd(c,d))*d);
}

string to_oct(int n){
    string s;
    while(n){
     s = std::to_string(n%8) + s;
     n /= 8;
    }
return s;
}

using namespace std;
int main(){
   int a,b,c;
   cin>>a>>b>>c;

   if(a*a+b*b<c*c){
       cout << "Yes" << endl;
   }else{
       cout << "No" << endl;
   }

}

#include <bits/stdc++.h>
#define int long long
#define INT_MAX INT64_MAX
#define INT_MIN INT64_MIN
#define PI 3.14159265358979323846
#define CLK clock_t clk = clock();//Start of main
#define OCLK cerr << "Time (in ms): " << (double)(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n';//End of main
#define MOD 1000000007
/* DEFINE cout */
#define pln cout << "===============================\n"
#define on cout<<"\n"
#define os cout<<" "
#define o2(a,b) cout<<a<<" "<<b
#define o(a) cout << a
#define bitcount __builtin_popcountll
/* DEFINE cout */
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);//fastio
using namespace std;
struct hash_pair { // use pair as key in unordered_map<pair<int,int>,int,hash_pair>;
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
bool prime[10000001];
int P=MOD-2;
int factorial[10000001]={0};
int powerFunction(int x,int y){
    int res = 1;
    int p = MOD;
    x = x % p;
    while (y > 0){
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
void sieveFunction(int maxLimit){
    memset(prime, true, sizeof(prime));
    prime[0] = prime[1]=false;
    for(int i=2; maxLimit >= i ; i++){
        if(prime[i]){
            for(int j=2*i ; maxLimit >= j ; j+=i)
            prime[j]=false;
        }
    }
}
void factorialFunction(int maxLimit){
    factorial[0]=1;
    for(int i=1 ; i <= maxLimit ; i++)
    factorial[i]=(factorial[i-1]*i)%MOD;
    return;
}
int gcd(int a, int b){
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
signed main(){
    int n, m, t;
    cin >> n >> m >> t;
    int a[m], b[m];
    int batt = n;
    int tm = 0;
    bool fg = true;
    for(int i=0; m>i; i++){
        cin >> a[i] >> b[i];
        int reach = a[i] - tm;
//        cout << batt << endl;
        if(batt > reach){
            batt -= reach;
        }else{
            fg = false;
        }
        int stay = b[i]-a[i];
        batt += stay;
        batt = min(n, batt);
        tm = b[i];
    }
//    cout << batt << endl;
    int rem = t - b[m-1];
    if(batt <= rem){
        fg = false;
    }
    if(fg){
        cout << "Yes\n";
    }else{
        cout << "No\n";
    }

}


#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, j, k, n, a, b, c = 2, s, t, now;
  bool ans = true;
  scanf("%lld%lld", &n, &k);
  if(k > n * n * n / 2) ans = false, k = n * n * n - k + 1;
  s = n + n + 1;
  while(s - c > 1) {
    t = (s + c) / 2;
    now = t * (t - 1) * (t - 2) / 6;
    if(t > n + 2) now -= (t - n) * (t - n - 1) * (t - n - 2) * 3 / 6;
    if(now < k) c = t;
    else s = t;
  }
  t = c;
  k -= t * (t - 1) * (t - 2) / 6;
  if(t > n + 2) k += (t - n) * (t - n - 1) * (t - n - 2) * 3 / 6;
  c++;
  now = 0;
  for(i = 1; ; ++i) {
    if(c - i > n) t = 2 * n - c + i + 1;
    else t = c - i - 1;
    if(now + t >= k) {
      a = i, k -= now;
      break;
    }
    now += t;
  }
  for(i = 1; k; ++i) if(a + i + n >= c) --k;
  b = i - 1;
  if(ans) printf("%lld %lld %lld", a, b, c - a - b);
  else printf("%lld %lld %lld", n - a + 1, n - b + 1, n - c + a + b + 1);
  return 0;
}

//ABC 200 E - Patisserie ABC 2
//https://atcoder.jp/contests/abc200/tasks/abc200_e

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

long long dp[4][3000005] = {};

int main() {
	int n;
	long long k;
	cin >> n >> k;
	//已选了几个数，其数字和是多少

	dp[0][0] = 1;
	for(int i = 0; i < 3; i++) {    // 推送给、贡献给父问题
		for(int j = 0; j <= i * n; j++) {
			dp[i + 1][j + 1] += dp[i][j];      //区间统一修：差分
			dp[i + 1][j + n + 1] -= dp[i][j];
		}
		for(int j = 1; j <= (i + 1) * n; j++) //差分+前缀和
			dp[i + 1][j] += dp[i + 1][j - 1];    //才是最后的值
	}

	int x;
	for(int i = 3; i <= 3 * n; i++)
		if(k <= dp[3][i]) {
			x = i;
			break;
		} else k -= dp[3][i];   //为何要减去？

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


#include<bits/stdc++.h>
using namespace std;
const int M  = 100005;
#define ll long long int
ll N = 1e9 + 7;
ll Z = 998244353;
#define all(x) (x).begin(), (x).end()
#define deb(x) cerr << #x << " = " << x <<"\n";
#define rep(i, begin, end) for (__typeof(end) i = (begin) — ((begin) > (end)); i != (end) — ((begin) > (end)); i += 1 — 2 * ((begin) > (end)))

ll power(ll x, unsigned int y, int p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
ll modinv(ll x, int p){
    return (power(x, p-2, p));
}

bool compare(const pair<int, int> &p1, const pair<int, int> &p2){
    return (p1.first < p2.first); // Ascending Order
    // return (p1.first > p2.first); // Descending Order
}
// min({args}), max({args})
void precompute(){

}
int main(){
    #ifdef SARTHAK
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    auto start = chrono::high_resolution_clock::now();
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t=1;
    //cin>>t;
    precompute();
    while(t--){
        int n;
        cin>>n;
        cout<<(n-1)/100 + 1<<"\n";
    }
    #ifdef SARTHAK
    auto end = chrono::high_resolution_clock::now();
    double time_taken =  chrono::duration_cast<chrono::nanoseconds>(end - start).count(); time_taken *= 1e-9;
    cout << "\nTime taken by program is : " << fixed << time_taken << setprecision(9); cout << " sec" << endl;
    #endif
    return 0;
}

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

void  century(int year)
{
  if(year<=0)
    return;
  else if(year % 100 == 0)
  {
    cout<<(year/100);
  }
  else
    cout<<(year /100) +1;

}
int main()
{
  int N;
  cin>>N; // year//
  century(N);
 return 0;
}


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

using ll = long long;

const int MAX_H = 2e5;
const int MAX_W = 2e5;

// From https://cp-algorithms.com/data_structures/fenwick.html
struct FenwickTree {
   vector<int> bit;  // binary indexed tree
   int n;

   FenwickTree(int n) {
      this->n = n;
      bit.assign(n, 0);
   }

   FenwickTree(vector<int> a) : FenwickTree(a.size()) {
      for (size_t i = 0; i < a.size(); i++)
         add(i, a[i]);
   }

   int sum(int r) {
      int ret = 0;
      for (; r >= 0; r = (r & (r + 1)) - 1)
         ret += bit[r];
      return ret;
   }

   int sum(int l, int r) {
      return sum(r) - sum(l - 1);
   }

   void add(int idx, int delta) {
      for (; idx < n; idx = idx | (idx + 1))
         bit[idx] += delta;
   }

   void set(int idx, int val) {
      int curr = sum(idx, idx);
      if (curr == 1) add(idx, -1);
      add(idx, val);
   }
};

vector<int> byRow[MAX_H + 1], byCol[MAX_W + 1];

int main() {

   int h, w, m;
   scanf("%d %d %d", &h, &w, &m);
   for (int i = 0; i < m; i++) {
      int x, y;
      scanf("%d %d", &x, &y);
      byRow[x].push_back(y);
      byCol[y].push_back(x);
   }
   for (int i = 1; i <= h; i++) {
      byRow[i].push_back(w + 1);
      sort(byRow[i].begin(), byRow[i].end());
   }
   for (int i = 1; i <= w; i++) {
      byCol[i].push_back(h + 1);
      sort(byCol[i].begin(), byCol[i].end());
   }

   ll ans = 0;
   // Go right, then down
   for (int i = 1; i < byRow[1].front(); i++) {
      assert(byCol[i].front() > 1);
      ans += byCol[i].front() - 1;
   }

   FenwickTree blockedColumns(w + 1);
   // Go down, then right
   for (int i = 1; i < byCol[1].front(); i++) {
      assert(!byRow[i].empty());
      assert(byRow[i].front() > 1);

      // Add cells that in columns you can't reach by going right first
      ans += max(0, byRow[i].front() - byRow[1].front());

      // Add cells that are blocked from above
      ans += blockedColumns.sum(1, byRow[i].front() - 1);

      for (int blockedColumn : byRow[i]) {
         if (blockedColumn < byRow[1].front()) blockedColumns.set(blockedColumn, 1);
      }
   }
   printf("%lld\n", ans);

   return 0;
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0; i<ll(n); i++)
#define FOR(i,m,n) for(ll i=ll(m); i<ll(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VP vector<pair<ll,ll>>
#define VPP vector<pair<int,pair<int,int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }

const ll  INF = (1 << 30) - 1;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;

VLL tate[200005];
VLL yoko[200005];
VLL cnt[200005];
struct Segment_tree {
	using T = ll;

	ll n;
	vector<T> data;
	const T out = 0LL;

	inline T vmerge(T l, T r) { return l + r; }

	Segment_tree(ll n) :n(n) { data.assign(2 * n, out); }

	void update(ll p, T x) {  // set value at position p
		for (data[p += n] = x; p > 1; p >>= 1) {
			data[p >> 1] = vmerge(data[p], data[p ^ 1]);
		}
	}

	T query(ll l, ll r) {  // sum on interval [l, r)
		T resl = out, resr = out;
		for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
			if (l & 1) resl = vmerge(data[l++], resl);
			if (r & 1) resr = vmerge(resr, data[--r]);
		}
		return vmerge(resl, resr);
	}
};

int main() {

	ll h, w, m;
	cin >> h >> w >> m;

	vector<pair<ll, ll>> v(m);
	REP(i, m) {
		cin >> v[i].first >> v[i].second;
		v[i].first--;
		v[i].second--;
		tate[v[i].first].push_back(v[i].second);
		yoko[v[i].second].push_back(v[i].first);
	}

	REP(i, 200005) {
		sort(ALL(tate[i]));
		sort(ALL(yoko[i]));
	}

	ll x;
	if (tate[0].size() == 0)x = w;
	else x = tate[0][0];

	ll ans = 0;

	REP(i, x) {
		if (yoko[i].size() == 0) {
			ans += h;
			cnt[h].push_back(i);
		}
		else {
			ans += yoko[i][0];
			cnt[yoko[i][0]].push_back(i);
		}
		//cerr << "   "<<ans << endl;
	}
	FOR(i, x, w) {
		cnt[0].push_back(i);
	}
	Segment_tree rsq(200005);

	cerr << ans << endl;

	ll y;
	if (yoko[0].size() == 0)y = h;
	else y = yoko[0][0];

	cerr << y << endl;

	FOR(i, 0, y) {
		if (tate[i].size() == 0) {
			ans += rsq.query(0, w);
		}
		else {
			ans += rsq.query(0, tate[i][0]);
		}
		for (ll j : cnt[i]) {
			//cerr << i << ' ' << j << endl;
			rsq.update(j, 1);
		}
	}
	cout << ans << endl;

}


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

void abcd(){
    int n,k;
    string s;
    cin >> s;
    n=0;
    rep(i,0,9){
        if(s[i]=='Z' && s[i+1]=='O' && s[i+2]=='N' && s[i+3]=='e'){
            n++;
        }
    }
    cout << n;
}

int32_t main(){
    int t=1;
    // scanf("%lld",&t);
    while(t--){
        abcd();
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{string s;
 cin>>s;
 int ans=0;
 string a="ZONe";
 for(int i=0;i<9;i++)
 {string x=s.substr(i,4);
 if(x==a) {ans++;}}
 cout<<ans;
return 0;}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,x,n) for(int i=x;i<(int)n;++i)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define ceiling(a,b) ((a+b-1)/b)
#define out(a) cout<<a<<endl;
#define vout(v) rep(i,0,v.size())cout<<v[i]<<(i==v.size()-1?"\n":" ");
#define vvout(vv) rep(j,0,vv.size()){vout(vv[j])}
#define mout(m) for(auto&e:m)cout<<e.first<<": "<<e.second<<endl;
#define _CHK_ 1
#define chk(a) if(_CHK_){cout<<#a<<": ";out(a)}
#define vchk(v) if(_CHK_){cout<<#v<<": ";vout(v)}
#define vvchk(vv) if(_CHK_){cout<<#vv<<": "<<endl;vvout(vv)}
#define mchk(m) if(_CHK_){cout<<#m<<": "<<endl;mout(m)}

template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    // friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
    //     if (n == 0) return 1;
    //     auto t = modpow(a, n / 2);
    //     t = t * t;
    //     if (n & 1) t = t * a;
    //     return t;
    // }
};
const long long MOD = 1000000007;
using mint = Fp<MOD>;

mint modpow(const mint &a, int64_t n){
    if(n==0)return 1;
    mint t=modpow(a,n/2);
    t=t*t;
    if(n&1)t=t*a;
    return t;
}

int main(){
    int64_t H,W;
    cin>>H>>W;
    vector<vector<char>> S(H, vector<char>(W));
    for (int64_t i = 0; i < H; i++) {
        for (int64_t j = 0; j < W; j++) {
            cin>>S[i][j];
        }
    }
    // vvchk(S)

    vector<vector<int64_t>> dp(H, vector<int64_t>(W, 0));
    vector<vector<int64_t>> x(H, vector<int64_t>(W, 0));
    vector<vector<int64_t>> y(H, vector<int64_t>(W, 0));
    vector<vector<int64_t>> z(H, vector<int64_t>(W, 0));
    dp[0][0]=1;
    for (int64_t i = 0; i < H; i++) {
        for (int64_t j = 0; j < W; j++) {
            if(i==0&&j==0)continue;
            if(j-1>=0&&S[i][j-1]=='.'&&S[i][j]=='.') x[i][j]=x[i][j-1]+dp[i][j-1];
            if(i-1>=0&&S[i-1][j]=='.'&&S[i][j]=='.') y[i][j]=y[i-1][j]+dp[i-1][j];
            if(j-1>=0&&i-1>=0&&S[i-1][j-1]=='.'&&S[i][j]=='.') z[i][j]=z[i-1][j-1]+dp[i-1][j-1];
            dp[i][j]=x[i][j]+y[i][j]+z[i][j];
            dp[i][j]%=MOD;
        }
    }
    // vvchk(x)
    // vvchk(y)
    // vvchk(z)
    // vvchk(dp)
    out(dp[H-1][W-1])

    return 0;
}

#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
string i_t_s(int x){
	string t="";
	while(x){
		t+=x%10+'0';
		x/=10;
	}
	reverse(all(t));
	re t;
}
int s_t_i(string t){
	int x=0;
	rep(i,sz(t)){
		x=x*10+(t[i]-'0');
	}
	re x;
}
bool vis[8];
int n;
ll t[8][8];
ll k;
int ans;
void dfs(int x,int cnt,ll sum){
	if(cnt==n&&x==0&&sum==k){
		ans++;
		re;
	}
	if(vis[x])
	re;
	vis[x]=true;
	rep(i,n){
		if(sum+t[x][i]>k)
		continue;
		dfs(i,cnt+1,sum+t[x][i]);
	}
	vis[x]=false;
}
int main(){
	ios::sync_with_stdio(0);
	cin>>n>>k;
	rep(i,n)
	rep(j,n)
	cin>>t[i][j];
	dfs(0,0,0);
	cout<<ans;
	re 0;
}


// clang-format off
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using G = vector<vector<ll>>;
#define G(i, j) i, vector<ll>(j)
#define Gv(i, j, k) i, vector<ll>(j, k)
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i,n) for(ll i=n-1; i>=0; --i)
#define rrep1(i,n) for(ll i=n; i>0; --i)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define SORT_DESC(x) sort((x).rbegin(),(x).rend())
#define pb push_back
#define mp make_pair
#define coutl cout<<fixed<<setprecision(10)
#define ANS(ans) cout<<ans<<endl
#define END(ans) ANS(ans); return
const ll LINF = (1LL << 62) - 1;
const int INF = (1 << 30) - 1;
template<class T>inline bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if (b<a){a=b;return 1;}return 0;}
// clang-format on

void solve(std::string S) {
  ll count = 0;
  ll len = S.length();
  for (ll i = 0; i < len; ++count) {
    ll ret = S.find("ZONe", i);
    if (ret == string::npos)
      break;
    i = ret + 1;
  }
  ANS(count);
}

// clang-format off
int main() {
  std::string S;
  std::cin >> S;
  solve(S);
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define rep(i,n) for (int i = 0;i < n;i++)
typedef long long ll;

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	string s;
	int p1 = 0;
	int p2 = 1;
	int p3 = 2;
	int p4 = 3;
	int count = 0;
	cin >> s;
	while (p4 < s.size()) {
		if (s[p1] == 'Z' && s[p2] == 'O' && s[p3] == 'N' && s[p4] == 'e') {
			count++;
		}
		p1++;
		p2++;
		p3++;
		p4++;
	}
	cout << count;

	return 0;
}


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

#define ll long long
#define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i)
#define rep(i, n) drep(i, 0, n - 1)
#define P pair<ll, ll>
#define all(a) (a).begin(), (a).end()

int main(){
    ll H, W;
    cin >> H >> W;

    vector<string> S(H);
    rep(i, H) cin >> S.at(i);

    ll ans = 0;
    ll dh[4] = {0, 1, 0, 1};
    ll dw[4] = {0, 0, 1, 1};
    rep(h, H-1){
        rep(w, W-1){
            ll count = 0;
            rep(i, 4){
                ll nh = h + dh[i];
                ll nw = w + dw[i];
                if(S[nh][nw] == '#') count++;
            }
            if(count == 1 || count == 3) ans++;
        }
    }

    cout << ans << endl;
}


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

int main(){
    long long n;
    cin >> n;
    long long tsum = 0;
    while(n--){
        long long a, b;
        cin >> a >> b;

        long long  sum1 = ((a-1) * a) / 2;
        long long  sum2 = ( b * (b+1)) / 2;
        long long sum = sum2 - sum1;
        tsum = tsum + sum;
    }
    cout << tsum << endl;
    return 0;
}

#include <iostream>
#include <fstream>
#include <cstdio>
#include <string>
#include <stack>
#include <queue>
#include <random>
#include <deque>
#include <cassert>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <list>
#include <forward_list>
#include <array>
#include <cstring>
#include <cmath>
#include <tuple>
#include <complex>
#include <bitset>
#include <climits>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
using pld = pair<ld, ld>;

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

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

    ll res = 0;
    for (ll cur_sum = 2 - min(0ll, K); cur_sum <= 2 * N - max(0ll, K); ++cur_sum)
    {
        res += (abs(cur_sum - 2 * max(1ll, cur_sum - N)) + 1) * (abs(cur_sum + K - 2 * max(1ll, cur_sum + K - N)) + 1);
    }

    cout << res;
}