#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=(r)-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={1,0,-1,0,1,1,-1,-1,0};
const ll dx[9]={0,-1,0,1,1,-1,1,-1,0};
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;
}

template <class T>
class SegTree {
    int n;// 葉の数
    vector<T> data;// データを格納するvector
    T def; // 初期値かつ単位元
    function<T(T, T)> operation; // 区間クエリで使う処理
    function<T(T, T)> update;// 点更新で使う処理

    T find(int a, int b) {
        T val_left = def, val_right = def;
        for (a += (n - 1), b += (n - 1); a < b; a >>= 1, b >>= 1)
        {
            if ((a & 1) == 0){
                val_left = operation(val_left, data[a]);
            }
            if ((b & 1) == 0){
                val_right = operation(data[--b],val_right);
            }
        }
        return operation(val_left, val_right);
    }
    public:
    // _n:必要サイズ, _def:初期値かつ単位元, _operation:クエリ関数,
    // _update:更新関数
    SegTree(size_t _n, T _def, function<T(T, T)> _operation,
        function<T(T, T)> _update=[](T a,T b){return b;})
        : def(_def), operation(_operation), update(_update) {
        n = 1;
        while (n < _n) {
            n *= 2;
        }
        data = vector<T>(2 * n - 1, def);
    }
    void set(int i, T x) { data[i + n - 1] = x; }
    void build() {
        for (int k=n-2;k>=0;k--) data[k] = operation(data[2*k+1],data[2*k+2]);
    }
    // 場所i(0-indexed)の値をxで更新
    void change(int i, T x) {
        i += n - 1;
        data[i] = update(data[i], x);
        while (i > 0) {
            i = (i - 1) / 2;
            data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]);
        }
    }

    // [a, b)の区間クエリを実行
    T query(int a, int b) {
        //return _query(a, b, 0, 0, n);
        return find(a,b);
    }

    // 添字でアクセス
    T operator[](int i) {
        return data[i + n - 1];
    }
};

int main(){
    ll h,w,n;cin >> h >> w >> n;
    vvl g(h);rep(i,n){
        ll p;cin >> p;p--;
        ll q;cin >> q;q--;
        g[p].pb(q);
    }
    /*rep(i,h){
        for(auto p:x[i])cout << p <<" ";cout << endl;
    }*/
    SegTree<ll> st(w,0LL,[](ll a,ll b){return a+b;});
    rep(i,w)st.set(i,1);st.build();
    bool flag=true;
    ll ans=0;
    rep(i,h){
        ll left=INF;
        for(auto p:g[i]){
            if(p==0)flag=false;
            st.change(p,0);
            chmin(left,p);
        }
        if(i==0&&left!=INF){
            for(int j=left;j<w;j++)st.change(j,0);
        }
        if(!flag)ans+=st.query(0,w);
        else{
            if(left==INF)ans+=w;
            else ans+=left+st.query(left,w);
        }
        //cout << ans <<endl;
    }
    cout << ans <<endl;
}

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

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

  int n; LL k; cin >> n >> k;

  LL dp[4][3000005] = {0};

  dp[0][0] = 1;

  #if 0
  // A slower way of calculating dp[i][j] is:
  // Will give TLE: https://atcoder.jp/contests/abc200/submissions/22497898

  for (int i = 0; i < 3; i ++) {
    // O(N^2)
    for (int j = 0; j <= 3 * n; j ++) {
      for (int k = 1; k <= n; k ++) {
        dp[i + 1][j + k] += dp[i][j];
      }
    }
  }

  // first of all, we know dp[i][j] > 0 if j <= i * n;
  // next, dp[i][j] will be added to dp[i+1][j+1:j+n+1)
  // so we can basically use dp[i+1][j] as a prefix to dp[i+1][j+1]
  #else

  for (int i = 0; i < 3; i ++) {
    // O(N)
    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]; // remove from accumulation.
    }
    // accumulate / prefix sum
    for (int j = 1; j <= (i + 1) * n; j ++)
      dp[i+1][j] += dp[i+1][j-1];
  }

  #endif
  // we accumulate the counts of sums until we reach k.
  // sum_{i=3}^{x} dp[3][i] <= k. we want to find x.
  int x;
  for (int i = 3; i <= 3 * n; i ++) {
    if (k <= dp[3][i]) { x = i; break; }
    else { k -= dp[3][i]; }
  }

  // finally, we can iterate the beauty of the cake
  for (int i = 1; i <= n; i ++) {
    // i is the beauty.
    // the maximum of the taste we can get is
    // x (the sum) - i (beauty) - n (pop).
    // the minimum is
    // x - i - 1.
    // we should constrain them between [1, n].
    int jmi = max(1, x - i - n), jma = min(n, x - i - 1);

    if (jmi > jma) continue; // in this case i is too small.
    if (k > (jma - jmi + 1)) {
      k -= (jma - jmi + 1); // these are the choices available for taste.
      continue;
    }

    int y = jmi + k - 1;
    int z = x - i - y;
    cout << i << ' ' << y << ' ' << z << '\n';
    return 0;
  }
}


#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = false;
//---------------------------------//

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

	vector<string> ans;

	// auto func = [&]() {
	// 	int as = -1, an = -1;
	// 	REP(i, 1 << N) FOR(j, i + 1, 1 << N) {
	// 		int s = 0, n = 0;
	// 		for (auto & str : ans) {
	// 			s += str[i] == str[j];
	// 			n += str[i] != str[j];
	// 		}
	// 		if (as == -1) {
	// 			as = s;
	// 			an = n;
	// 		}
	// 		else {
	// 			if (as != s || an != n) return false;
	// 			//cout << i << ", " << j << ": as = " << s << ", s = " << s << ": an = " << an << ", n = " << n << endl;
	// 			// assert(as == s);
	// 			// assert(an == n);
	// 		}
	// 	}
	// 	return true;
	// };

	// vector<string> op;
	// REP(i, 1 << ((1 << N) - 1)) {
	// 	int pcnt = 0;
	// 	REP(j, (1 << N) - 1) pcnt += i >> j & 1;
	// 	if (pcnt != (1 << (N - 1)) - 1) continue;
	// 	string s(1 << N, 'B');
	// 	s[0] = 'A';
	// 	REP(j, (1 << N) - 1) if (i >> j & 1) s[j + 1] = 'A';
	// 	op.emplace_back(s);
	// }

	// vector<int> cnt(1 << N);

	// auto dfs = [&](auto self, int d, int p) {
	// 	if (d == (1 << N) - 1) {
	// 		if (func()) {
	// 			puts("answer! : ");
	// 			sort(ALL(ans));
	// 			for (auto s : ans) cout << s << endl;
	// 			return;
	// 		}
	// 		return;
	// 	}
	// 	FOR(i, p, op.size()) {
	// 		bool ok = true;
	// 		FOR(j, 1, op[i].size()) {
	// 			if (op[i][j] == 'A') ++cnt[j];
	// 			ok &= cnt[j] <= (1 << (N - 1)) - 1;
	// 		}
	// 		if (ok) {
	// 			ans.emplace_back(op[i]);
	// 			self(self, d + 1, i + 1);
	// 			ans.pop_back();
	// 		}

	// 		FOR(j, 1, op[i].size()) if (op[i][j] == 'A') --cnt[j];
	// 	}
	// };
	// dfs(dfs, 0, 0);

	REP(i, N) {
		vector<string> nex;
		nex.emplace_back(string(1 << i, 'A') + string(1 << i, 'B'));
		for (auto & s : ans) {
			nex.emplace_back(s + s);
			string rev = s;
			for (char & c : rev) c = c == 'A' ? 'B' : 'A';
			nex.emplace_back(s + rev);
		}
		swap(ans, nex);
	}

	cout << ans.size() << endl;
	for (auto & s : ans) cout << s << '\n';
}

#pragma GCC optimize("O3")

#include "bits/stdc++.h"

#define sz(x) (int)(x).size()
using namespace std;

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

    int n;
    cin >> n;
    cout << (1<<n)-1 << "\n";
    for(int i=1; i<=(1<<n)-1; i++) {
        for(int j=0; j<(1<<n); j++)
            cout << (__builtin_popcount(i & (j+1)) % 2 ? 'A' : 'B');
        cout << "\n";
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
  //int arr[] = {1, 2, 90, 10, 110};
  //int n = sizeof(arr) / sizeof(arr[0]);

  // Function calling
  //cout << "Maximum difference is " << maxDiff(arr, n);
  int a,b,c,d;
  cin>> a;
  cin>>b;
  cin>> c;
  cin>>d;
  cout<< b-c;

  return 0;
}

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

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

//using lll=boost::multiprecision::cpp_int;
//using Double=boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1024>>;//仮数部が1024桁
template <class T>
inline bool chmin(T &a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}

template <typename T>
T mypow(T x, T n, const T &p = -1)
{ //x^nをmodで割った余り

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

using namespace std;
//using namespace atcoder;

void solve()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<b-c;
}

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


#include<algorithm>
#include<iostream>
#include<cstring>
#include<bitset>
#include<cstdio>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
#define neinf 0xc0c0c0c0c0c0c0c0ll
#define inf 0x3f3f3f3f3f3f3f3fll
#define uint unsigned int
#define ull unsigned ll
#define ll long long
#define reg register
#define db double
#define il inline
#define gc getchar
#define pc putchar
#define HgS 998244353
il ll rd()
{
	reg ll res=0,lab=1;
	reg char ch=gc();
	while((ch<'0'||ch>'9')&&ch!=EOF)
	{if(ch=='-')lab=-lab;ch=gc();}
	while(ch>='0'&&ch<='9')
		res=(res<<3)+(res<<1)+(ch&15),ch=gc();
	return res*lab;
}
il void prt(ll x,char t=' ')
{
	reg char ch[70];reg int tp=0;
	if(x<0)pc('-'),x=-x;
	while(x)ch[++tp]=(x%10)^48,x/=10;
	if(!tp)ch[++tp]=48;
	while(tp)pc(ch[tp--]);
	if(t)pc(t);
}
ll n,f[200005],v[200005],ans;
il void dfs(int cur)
{
	if(v[cur]==2)return;
	if(v[cur]==1){++ans;return;}
	++v[cur];dfs(f[cur]);++v[cur];
}
il ll qpow(ll n,ll e,ll p=HgS)
{
	reg ll res=1;
	while(e){if(e&1)res=res*n%p;n=n*n%p;e>>=1;}
	return res;
}
int main()
{
	n=rd();for(int i=1;i<=n;++i)f[i]=rd();
	for(int i=1;i<=n;++i)if(!v[i])dfs(i);
	prt(qpow(2,ans)-1);
	return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<vl> vvl;

double EPS=1e-9;
int INF=1000000005;
long long INFF=1000000000000000005ll;
double PI=acos(-1);
int dirx[8]={ -1, 0, 0, 1, -1, -1, 1, 1 };
int diry[8]={ 0, 1, -1, 0, -1, 1, -1, 1 };
const ll MOD = 1000000007;

ll sum() { return 0; }
template<typename T, typename... Args>
T sum(T a, Args... args) { return a + sum(args...); }

#define DEBUG fprintf(stderr, "====TESTING====\n")
#define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
#define OUT(x) cout << x << endl
#define OUTH(x) cout << x << " "
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define READ(x) for(auto &(z):x) cin >> z;
#define FOR(a, b, c) for (int(a)=(b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a)=(b); (a) <= (c); ++(a))
#define FORD(a, b, c) for (int(a)=(b); (a) >= (c); --(a))
#define FORSQ(a, b, c) for (int(a)=(b); (a) * (a) <= (c); ++(a))
#define FORC(a, b, c) for (char(a)=(b); (a) <= (c); ++(a))
#define EACH(a, b) for (auto&(a) : (b))
#define REP(i, n) FOR(i, 0, n)
#define REPN(i, n) FORN(i, 1, n)
#define MAX(a, b) a=max(a, b)
#define MIN(a, b) a=min(a, b)
#define SQR(x) ((ll)(x) * (x))
#define RESET(a, b) memset(a, b, sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define PERMUTE next_permutation
#define TC(t) while (t--)
#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define what_is(x) cerr << #x << " is " << x << endl;

void solve() {

}

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

//    int tc; cin >> tc;
//    TC(tc) solve();
	char s, n;
	cin >> s >> n;
	if(s=='Y') OUT((char)toupper(n));
	else OUT(n);
    return 0;
}


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

int main() {

	int N,X;
	cin>>N>>X;

	vector<int> V;
	for(int i=0;i<N;i++)
	{
		int x;
		cin>>x;

		if(x != X)
		{
			V.push_back(x);
		}
	}

	for(int i=0;i<V.size();i++)
	{
		if(i == (V.size()-1))
		{
			cout<<V[i]<<endl;
		}
		else
		{
			cout<<V[i]<<" ";
		}
	}

	return 0;
}


#include <bits/stdc++.h>
#define endl '\n';

typedef long long ll;

using namespace std;

const int maxn = 1e5 + 10;

int main()
{
	ios::sync_with_stdio(false);
	int n,x;
	char aws;
	cin >> n >> x;
	for (int i = 0; i < n; i++) {
		cin >> aws;
		if (aws == 'o')x++;
		else if (x != 0) x--;
	}
	cout << x << endl;
	return 0;
}

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

int main(){
	int n, x; string s; cin>>n>>x>>s;
	for(auto c:s) x = c=='o'? x+1:max(0, x-1);
	cout<< x <<endl;
}


#include <bits/stdc++.h>
// clang-format off
using namespace std; using ll=long long; using ull=unsigned long long; using pll=pair<ll,ll>; const ll INF=4e18;
void print0() {}
template<typename H,typename... T> void print0(H h,T... t){cout<<fixed<<setprecision(15)<<h;print0(t...);}
void print() { print0("\n"); }
template<typename H,typename... T>void print(H h,T... t){print0(h);if(sizeof...(T)>0)print0(" ");print(t...);}
void ioinit() { cout << fixed << setprecision(15); ios_base::sync_with_stdio(0); cin.tie(0); }
// clang-format on
const ll MODULO = 3;
const ll COMBMAX = 400005;
ll fac[COMBMAX];
ll fthree[COMBMAX];
void combination_init() {
    fac[0] = fac[1] = 1;
    fthree[0] = fthree[1] = 0;
    for (int i = 2; i < COMBMAX; i++) {
        fthree[i] = fthree[i - 1];
        ll j = i;
        while (j % 3 == 0) {
            j = j / 3;
            fthree[i]++;
        }
        fac[i] = fac[i - 1] * j % MODULO;
    }
}
ll inv(ll v) {
    if (v == 1) return 1;
    if (v == 2) return 2;
    return 0;
}
ll combination(ll n, ll k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    if (fthree[n] - fthree[k] - fthree[n - k] > 0) {
        return 0;
    }
    return fac[n] * inv(fac[n - k]) * inv(fac[k]) % MODULO;
}

int main() {
    ioinit();
    ll n;
    cin >> n;
    string s;
    cin >> s;
    vector<ll> t(n);
    for (ll i = 0; i < n; i++) {
        if (s[i] == 'B') {
            t[i] = 0;
        }
        if (s[i] == 'W') {
            t[i] = 1;
        }
        if (s[i] == 'R') {
            t[i] = 2;
        }
    }

    combination_init();
    ll sign = (n % 2 == 0) ? -1 : 1;
    ll ans = 0;
    for (ll i = 0; i < n; i++) {
        ans += t[i] * combination(n - 1, i);
    }
    ans = ans * sign;
    ans = ans % 3;
    if (ans < 0) ans += 3;
    if (ans == 0) {
        print("B");
    }
    if (ans == 1) {
        print("W");
    }
    if (ans == 2) {
        print("R");
    }
}

#include <bits/stdc++.h>
using namespace std;
long long MOD;
int main(){
  int N, K;
  cin >> N >> K >> MOD;
  vector<vector<long long>> f(N);
  f[0].push_back(1);
  for (int i = 1; i < N; i++){
    int sz = f[i - 1].size();
    f[i] = vector<long long>(sz + i * K, 0);
    for (int j = 0; j < sz; j++){
      f[i][j] = f[i - 1][j];
    }
    for (int j = i; j < sz + i * K; j++){
      f[i][j] += f[i][j - i];
      if (f[i][j] >= MOD){
        f[i][j] -= MOD;
      }
    }
    for (int j = sz + i * K - 1; j >= i * (K + 1); j--){
      f[i][j] -= f[i][j - i * (K + 1)];
      if (f[i][j] < 0){
        f[i][j] += MOD;
      }
    }
  }
  for (int i = 0; i < N; i++){
    long long ans = 0;
    int d = min(f[i].size(), f[N - 1 - i].size());
    for (int j = 0; j < d; j++){
      ans += f[i][j] * f[N - 1 - i][j] % MOD;
      ans %= MOD;
    }
    ans *= (K + 1);
    ans %= MOD;
    ans--;
    if (ans == -1){
      ans += MOD;
    }
    cout << ans << endl;
  }
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define each(e, v) for(auto &e: v)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
//const int MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

struct io_setup{
    io_setup(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout << fixed << setprecision(15);
    }
} io_setup;

bool judge(string S){
    int N = sz(S);

    rep(i, N){
        if(S[i] != S[N-1-i]) return false;
    }

    return true;
}

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

    reverse(all(S));

    bool ans = false;

    rep2(i, 0, 100){
        if(judge(S)) ans = true;
        S += '0';
    }

    cout << (ans? "Yes\n" : "No\n");
}

#include <bits/stdc++.h>

#define speedup ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr),cout.precision(12)
using namespace std;

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

using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_map;
#define sbc __builtin_popcount
#define pb push_back
#define pbk pop_back
#define em emplace
#define emb emplace_back
#define ff first
#define ss second
#define ll long long
const ll mod = 1e9 + 7;

template<typename T> void smax(T& a, T b) { if(a<b) a=b; }
template<typename T> void smin(T& a, T b) { if(a>b) a=b; }
template<typename T> T pw(T a,T b) { T p=1,one=1; while(b) { if(b&one) p=p*a; a=a*a; b >>=1; } return p; }
template<typename T> T pwm(T a,T b,T md=mod) { T p=1,one=1; while(b) { if(b&one) p=p*a%md; a=a*a%md; b >>=1; } return p; }

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

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &it) {
    os << it.first << ' ' << it.second;
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const array<T, 2> &v) {
    for (auto &it : v) os << it << ' ';
    return os;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    for (auto &it : v)
        os << it << ' ';
    return os;
}

#ifndef ONLINE_JUDGE
class Timer { chrono::high_resolution_clock::time_point start_t, end_t; public: Timer() { start_t=chrono::high_resolution_clock::now(); } ~Timer() { end_t = chrono::high_resolution_clock::now(); auto duration = chrono::duration_cast<chrono::milliseconds>(end_t-start_t); cerr<<"\nRunTime: "<<duration.count()<<"ms"<<'\n'; } };
void debug() { cerr << '\n'; }

template<typename T, typename... Args>
void debug(T print, Args... args) {
    cerr << ' ' << print;
    debug(args...);
}

#define deb(...) cerr << "[" << #__VA_ARGS__ << "]" << " --> ", debug(__VA_ARGS__)
#else
#define deb(...) void(0)
#endif

void solve() {
	int n;
	cin>>n;
	for(int i=0;i<n;++i)
		cout<<2*i%n+1<<' '<<(2*i+1)%n+1<<'\n';
}
int main() {
    speedup;
    //int t; cin >> t; while (t--)
	solve();
}
/**Vim
 *
 *
 *
 *
 *
 *
 *
 *
 */


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

#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
#define P pair<int,ll>
#define MOD 1000000007

using namespace std;

ll n, a,b,c, m;

int main(){
    cin >> n;
    m = n+1;
    rep(i, 60){
        a = (n >> i);
        b = i;
        c = n - (a << b);
        m = min(m, a+b+c);
    }
    cout << m<<endl;
}

#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <cassert>
#include <stack>
#include <numeric>

typedef int64_t ll;
typedef std::pair<int, int> Pii;
typedef std::pair<ll, ll> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, _s) for (int i = (_s);i < (int)( n ); i++)
#define all(_l) _l.begin(), _l.end()
#define rall(_l) _l.rbegin(), _l.rend()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

# ifdef LOCAL_DEBUG
template<typename T>
void vdeb(const std::vector<T> &bb) {
    for (unsigned int i = 0;i < bb.size();i++) {
        if (i == bb.size() - 1) std::cout << bb[i];
        else std::cout << bb[i] << ' ';
    }
    std::cout << '\n';
}
template<typename T>
void vdeb(const std::vector<std::vector<T>> &bb) {
    for (unsigned int i = 0;i < bb.size();i++) {
        std::cout << i << ' ';
        vdeb(bb[i]);
    }
    std::cout << '\n';
}
# endif

using namespace std;

int main() {
    int n; cin >> n;
    cout << (1<<n)-1  << endl;
    rip(i,1<<n,1) {
        rip(j,1<<n,0) {
            if(__builtin_popcount(j&i)&1) cout << 'A';
            else cout << 'B';
        }
        cout << '\n';
    }
}


#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <numeric>
#include <chrono>
#include <random>
#include <bitset>
#include <tuple>
#include <queue>
#include <map>
#include <unordered_map>
#include <cstring>
#include <cassert>
#include <climits>
#include <math.h>
using namespace std;

const int N = 2e5 + 10, mod = 1e9 + 7;
int n, q, a[N], t[N];
long long pref[N];
map<long long, int> mxid, mnid;
set<long long> mns, mxs;

struct tr {
    int tree[N << 1];
    void build() {
        for(int i = 0; i < n; i++) tree[i + n] = 1e9;
        for(int i = n - 1; i > 0; i--) tree[i] = min(tree[i << 1], tree[i << 1 | 1]);
    }

    void upd(int i, int va) {
        tree[i += n] = va;
        for(i >>= 1; i > 0; i >>= 1) tree[i] = min(tree[i << 1], tree[i << 1 | 1]);
    }

    int query(int l, int r) {
        int resl = 1e9, resr = 1e9;
        for(l += n, r += n + 1; l < r; l >>= 1, r >>= 1) {
            if(l & 1) resl = min(resl, tree[l++]);
            if(r & 1) resr = min(resr, tree[--r]);
        }
        return min(resl, resr);
    }
} mntr, mxtr;

int main() {
    // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int tc = 1;
    //scanf("%d", &tc);
    for(int cn = 1; cn <= tc; cn++) {
        scanf("%d", &n);
        for(int i = 0; i < n; i++) scanf("%d%d", &a[i], &t[i]);
        for(int i = 0; i < n; i++) {
            if(i) pref[i] = pref[i - 1];

            if(t[i] == 1) pref[i] += a[i];
            else if(t[i] == 2) mxid[a[i] - pref[i]];
            else mnid[a[i] - pref[i]];
        }
        mntr.build();
        mxtr.build();
        int c = 0;
        for(auto &x : mxid) {
            x.second = c++;
            mxs.insert(x.first);
        }
        c = 0;
        for(auto &x : mnid) {
            x.second = c++;
            mns.insert(x.first);
        }

        vector<long long> ans(n);
        for(int i = n - 1; i >= 0; i--) {
            if(t[i] == 1) continue;

            auto it = mxs.lower_bound(a[i] - pref[i]);
            int j = 1e9;
            if(it != mxs.end()) {
                j = mxtr.query(mxid[*it], n - 1);
            }

            it = mns.upper_bound(a[i] - pref[i]);
            int k = 1e9;
            if(it != mns.begin()) {
                it--;
                k = mntr.query(0, mnid[*it]);
            }

            if(min(j, k) < n) ans[i] = ans[min(j, k)];
            else ans[i] = 1ll * a[i] + pref[n - 1] - pref[i];

            if(t[i] == 2) mxtr.upd(mxid[a[i] - pref[i]], i);
            else mntr.upd(mnid[a[i] - pref[i]], i);
        }

        scanf("%d", &q);
        while(q--) {
            long long x; scanf("%lld", &x);

            auto it = mxs.lower_bound(x);
            int j = 1e9;
            if(it != mxs.end()) {
                j = mxtr.query(mxid[*it], n - 1);
            }

            it = mns.upper_bound(x);
            int k = 1e9;
            if(it != mns.begin()) {
                it--;
                k = mntr.query(0, mnid[*it]);
            }

            if(min(j, k) < n) printf("%lld\n", ans[min(j, k)]);
            else printf("%lld\n", x + pref[n - 1]);
        }
    }
    return 0;
}

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

const int N = 17;
int n,m,k;
vector<vector<int>> G;
int d[N][N], c[N];
int dp[1 << N][N];

void bfs(int s) {
  vector<int> dist(n, INT_MAX);
  queue<int> que;
  que.push(c[s]);
  dist[c[s]] = 0;
  while(!que.empty()) {
    int v = que.front();
    que.pop();
    for (auto next : G[v]) {
      if (dist[next] != INT_MAX) continue;
      dist[next] = dist[v] + 1;
      que.push(next);
    }
  }
  for (int i = 0; i < k; i++) {
    d[s][i] = min(d[s][i], dist[c[i]]);
    d[i][s] = min(d[i][s], dist[c[i]]);
  }
}

signed main() {
  cin >> n >> m;

  G.resize(n);
  for (int i = 0; i < m; i++) {
    int a, b; cin >> a >> b;
    a--, b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      d[i][j] = INT_MAX;
    }
  }

  cin >> k;
  for (int i = 0; i < k; i++) {
    cin >> c[i], c[i]--;
  }
  for (int i = 0; i < k; i++) {
    bfs(i);
  }

  for (int i = 0; i < (1 << N); i++) {
    for (int j = 0; j < N; j++) {
      dp[i][j] = INT_MAX;
    }
  }

  for (int i = 0; i < k; i++) {
    dp[(1 << k) - 1][i] = 0;
  }

  // d[N][N]はidxで管理 (idx < k)
  for (int s = (1 << k) - 2; s >= 0; s--) {
    for (int v = 0; v < k; v++) {
      for (int u = 0; u < k; u++) {
        if (!(s >> u & 1)) {
          dp[s][v] = min(dp[s][v], dp[s | 1 << u][u] + d[v][u]);
        }
      }
    }
  }

  int res = INT_MAX;
  for (int i = 0; i < k; i++) {
    res = min(res, dp[0][i]);
  }

  if (res == INT_MAX) res = -1;
  else res += 1;
  cout << res << '\n';
}


#include <bits/stdc++.h>
using namespace std;
// TYPEDEF ------------------------------
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> Pair;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<vector<ll>> Graph;
typedef vector<string> vs;
typedef vector<pair<ll, ll>> Pll;
typedef queue<ll> qll;
typedef map<ll, ll> mll;
// REPEAT ------------------------------
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;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--)
// UTIL ------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end() // 注意；https://kimiyuki.net/blog/2015/09/25/competitive-programming-coding/
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())
#define REVERSE(x) reverse(ALL(x))
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define SUM(x) accumulate(ALL(x), (ll)0)
#define COUNT(x, y) count(ALL(x), y);
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
// PRINT ------------------------------
#define COUT(a) cout << (a) << endl;
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
// DEBUG ------------------------------
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(...) {debug_all(#__VA_ARGS__, __VA_ARGS__);}
template < typename T >
void _debug_print(T const& a) {cerr << a << ", ";}
template < typename... Args >
void debug_all(string s, Args... args) {
  cerr << "[debug] " << s << " = ";
  using swallow = std::initializer_list<int>;
  (void)swallow{ (void( _debug_print(args) ), 0)... };
  cerr << endl;
}
#define debugV(v) cerr << "[debugV] " << #v << ":"; REP(z, v.size()) cerr << " " << v[z]; cerr << "\n";
// CONST ------------------------------
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279; // or M_PI

//######################################################################
//#                         ここから下に書いていく                         #
//######################################################################

void Main() {
  ll n, k;
  cin >> n >> k;

  ll ans = 0;
  REP(i, n) {
    REP(j, k) {
      ans += (i+1) * 100;
      ans += (j+1);
    }
  }
  COUT(ans);
}

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

/*

3 2
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
ll gcd(ll x, ll y) {return (x%y) ? gcd(y, x%y) : y; }
const int inf = 1000000000;
const int dx[]={1,0,-1,0};
const int dy[]={0,1,0,-1};
const ll mod = 1e9+7;

int main(){
    string a, b;
    cin >> a >> b;
    int suma = 0;
    int sumb = 0;
    rep(i,3){
        suma += (a.at(i)-'0');
    }
    rep(i,3){
        sumb += (b.at(i)-'0');
    }
    cout << max(suma, sumb) << endl;
}


#include <bits/stdc++.h>

using namespace std;

#define FASTIO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define FASTIO1 srand(chrono::high_resolution_clock::now().time_since_epoch().count())
#define gc getchar_unlocked
#define ll long long
#define PI 3.1415926535897932384626
#define br cout << endl
#define sp cout << " "
#define foin(i, s, e) for (i = s; i < e; i++)
#define Fo(i, k, n) for (i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
#define printarr(i, s, e, a, str) fin(i, s, e) cout << a[i] << str;
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define clr(x) memset(x, 0, sizeof(x))
#define tr(it, x) for (auto it = x.begin(); it != x.end(); it++)
#define trr(it, x) for (auto it = x.rbegin(); it != x.rend(); it +)
#define sortv(vec) sort(vec.begin(), vec.end());

typedef pair<int, int> pii;
typedef map<int, int> mapii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;

const int mod = 1'000'000'007;
const int N = 3e5;
int i = 0;

mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim)
{
    uniform_int_distribution<int> uid(0, lim - 1);
    return uid(rang);
}

/* ========== Solution ========= */

int main()
{
    FASTIO;
    FASTIO1;

    int n = 1;
    cin >> n;

    int a[n], b[n];

    foin(i, 0, n)
            cin >>
        a[i];
    foin(i, 0, n)
            cin >>
        b[i];

    int s = a[0], e = b[0];

    foin(i, 1, n)
    {
        if (a[i] > s)
            s = a[i];
        if (b[i] < e)
            e = b[i];
    }
    if (s > e)
        cout << "0";
    else
        cout << (e - s + 1);

    return 0;
}

#include <bits/stdc++.h>
#define arr array
#define pb push_back
#define fs first
#define sc second
#define eb emplace_back
#define vt vector
#define all(x) (x).begin(), (x).end()
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

using namespace std;
typedef long long ll;
const int maxn=1e5;
const ll MAXLL=9223372036854775807;

void solve(){
	int n;
	cin >> n;
	vt<int> a(n);
	rep(i, 0, n) cin >> a[i], a[i]%=200;
	int li=min(8, n);
	map<int, vt<vt<int>>> mp;
	for (int mask=1; mask<(1<<li); mask++){
		vt<int> v;
		int s=0;
		rep(i, 0, li)
			if (mask>>i&1) s+=a[i], v.pb(i+1);
		if (!mp[s%200].empty()){
			vt<int> v1=mp[s%200][0];
			cout << "Yes" << endl;
			cout << (int)v.size() << " "; for (auto i:v) cout << i << " "; cout << endl;
			cout << (int)v1.size() << " "; for (auto i:v1) cout << i << " "; cout << endl;
			return;
		} else mp[s%200].pb(v);
	}
	cout << "No";
}

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


#include <algorithm>
#include <iostream>
#include <vector>
#include <set>

typedef long long ll;
using namespace std;
int n;
vector<vector<int>> a;
set<int> ids;
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main() {
    cin >> n;
    rep(i, n) {
        int x, y;
        cin >> x >> y;
        a.emplace_back(vector<int>{x, y, i});
    }
    rep(k, 2) {
        sort(a.begin(), a.end());
        rep(i, 2) {
            ids.emplace(a[i][2]);
            ids.emplace(a[n - 1 - i][2]);
        }
        for (auto& v : a)swap(v[0], v[1]);
    }
    vector<pair<int, int>> b;
    for (auto v : a) {
        if (ids.count(v[2]) > 0)b.emplace_back(v[0], v[1]);
    }
    vector<ll> d;
    for (int i = 0; i < (int)b.size(); i++) {
        for (int j = i + 1; j < (int)b.size(); j++) {
            d.emplace_back(max(abs(b[i].first - b[j].first), abs(b[i].second - b[j].second)));
        }
    }
    sort(d.begin(), d.end());
    cout << d[d.size() - 2] << endl;
    return 0;
}

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

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

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H,W;
    int ans = 0;
    string S[100];
    cin >> H >> W;
    REP(i, H)
    cin >> S[i];

    REP(h, H){
        REP(w, W){
            if (S[h][w]=='.'){
                if ( w+1<W && S[h][w+1]=='.' )
                    ans++;
                if (h+1<H && S[h+1][w]=='.')
                    ans++;
            }
        }
    }
    cout << ans << endl;
}


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

using ll = long long;

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

int main() {
	double A, B;
	cin >> A >> B;
	co(100 * (1 - B / A));
}

#include <bits/stdc++.h>
using namespace std;
int main(){
  int A, B;
  cin >> A >> B;
  cout << 2 * A + 100 - B;

 }


//   https://atcoder.jp/contests/arc108/tasks/arc108_b
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N;
	char a[200010];
	memset(a,0,200010);
	cin>>N>>a;
	for(int i=0;i<N;i++){
		if(a[i]=='f'&&a[i+1]=='o'&&a[i+2]=='x'){
			for(int j=i;j<N;j++) a[j]=a[j+3];
		i=i-3;
		N=N-3;
		}
	}
	cout<<N;
	return 0;
}

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

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

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

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

	int n;
	cin>>n;
	string s;
	cin>>s;

	vector<char>v;

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

		v.pb(s[i]);

		int sz=v.size();

		if(sz>=3 && v[sz-3]=='f' && v[sz-2]=='o' && v[sz-1]=='x'){

			for(int i=0;i<3;i++)
			v.pop_back();
		}
	}

	cout<<v.size()<<endl;

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


#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
    #include <atcoder/all>
    using namespace atcoder;
#endif

using namespace std;
using Graph = vector<vector<int>>;
using vst= vector<string>;
using vin= vector<int>;
using ll=long long;
using ull=unsigned long long;
using vll= vector<ll>;
using P=pair<int ,int>;
using pqi=priority_queue<int, vector<int>, greater<int>>;
using pqp=priority_queue<P, vector<P>, greater<P>>;

//const long double pi=acos(-1);
#define ft first
#define sd second
#define fn front
#define pb push_back
#define eb emplace_back
#define it insert
#define vvi vector<vector<int>>
#define si(v) int((v).size())
#define pq priority_queue
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rell(i,n) for (ll i=0; i< (ll)(n); i++)
#define sot(x) sort(x.begin(), x.end())
#define rese(x) reverse(x.begin(), x.end())
#define gsot(x) sort(x.begin(), x.end(), greater<ll>());
#define vnn(x,y,s,name) vector<vector<int>> name(x, vector<int>(y,s))
#define mse(x) memset(x, 0, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define mii(x,y,z) min(x,min(y,z))
#define maa(x,y,z) max(x,max(y,z))
#define cps CLOCKS_PER_SEC
#define yes cout<<"Yes"<<"\n"
#define no cout<<"No"<<"\n"
#define cset(x) cout<<fixed<<setprecision(x)

//const int INF=1001001001;
//const ll INF=1e18;
//998244353  1000000007
void output(int a,int b,int c,int d){
    cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<pair<int,P>> a(n);

    rep(i,n){
        int x,y,r;
        cin>>x>>y>>r;
        /*int s=ceil(sqrt((double)(r)));
        int t=s/2;*/
        output(x,y,x+1,y+1);
        a[i].ft=r;
        a[i].sd.ft=x;
        a[i].sd.sd=y;
    }
    sot(a);

}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<bool> vbl;
typedef vector<vector<bool>> vvbl;
typedef vector<ld> vld;

void INX(){}
template<typename Head, typename... Tail>
void INX(Head&& head, Tail&&... tail)
{
    cin >> head;
    INX(forward<Tail>(tail)...);
}
void OUTX(){}
template<typename Head, typename... Tail>
void OUTX(Head&& head, Tail&&... tail)
{
    cout << head << endl;
    OUTX(forward<Tail>(tail)...);
}
void OUTX2(){cout << endl;}
template<typename Head, typename... Tail>
void OUTX2(Head&& head, Tail&&... tail)
{
    cout << head << ' ';
    OUTX2(forward<Tail>(tail)...);
}

#define ADD emplace_back
#define MP make_pair
#define __LONG_LONG_MIN__ (-__LONG_LONG_MAX__ - 1)

//#define MOD 1000000007 // 10^9 + 7
//setprecision(10)

struct dat
{
    ll index;
    ld x;
    ld y;
    ld r;
    ld sqrtr2;
};
typedef vector<dat> vdat;

struct square
{
    ld a;
    ld b;
    ld c;
    ld d;
};
typedef vector<square> vsquare;

int main()
{
    ll n;
    INX(n);

    vdat data(n);
    vdat dataxsort(n);
    vdat dataysort(n);
    vsquare result(n);
    for (ll i = 0; i < n; i++)
    {
        dat &di = data[i];
        INX(di.x, di.y, di.r);
        di.index = i;
        di.sqrtr2 = (ld)sqrt(di.r) / 2.0;
        dataxsort[i] = di;
        dataysort[i] = di;

        square &sqi = result[i];
        sqi.a = di.x;
        sqi.b = di.y;
        sqi.c = di.x + 1.0;
        sqi.d = di.y + 1.0;

    }

    sort(dataxsort.begin(), dataxsort.end(), [](dat d1, dat d2){return d1.x < d2.x;});
    sort(dataysort.begin(), dataysort.end(), [](dat d1, dat d2){return d1.y < d2.y;});

    for (ll i = 0; i < n; i++)
    {
        dat &dx = dataxsort[i];
        square &sqi1 = result[dx.index];
        ll j = i - 1;
        if(i == 0 || dataxsort[i].x == dataxsort[0].x)
        {
            sqi1.a = max((ld)0, sqi1.a - dx.sqrtr2);
        }
        else if(dataxsort[i].x == dataxsort[j].x)
        {
            while(dataxsort[i].x == dataxsort[--j].x);
            square &sqj = result[dataxsort[j].index];
            sqi1.a = max(sqj.c, sqi1.a - dx.sqrtr2);
        }
        else
        {
            square &sqj = result[dataxsort[j].index];
            sqi1.a = max(sqj.c, sqi1.a - dx.sqrtr2);
        }
        sqi1.a = ceil(sqi1.a);

        dat &dy = dataysort[i];
        square &sqi2 = result[dy.index];
        j = i - 1;
        if(i == 0 || dataysort[i].y == dataysort[0].y)
        {
            sqi2.b = max((ld)0, sqi2.b - dy.sqrtr2);
        }
        else if(dataysort[i].y == dataysort[j].y)
        {
            while(dataysort[i].y == dataysort[--j].y);
            square &sqj = result[dataysort[j].index];
            sqi2.b = max(sqj.d, sqi2.b - dy.sqrtr2);
        }
        else
        {
            square &sqj = result[dataysort[j].index];
            sqi2.b = max(sqj.d, sqi2.b - dy.sqrtr2);
        }
        sqi2.b = ceil(sqi2.b);
    }

    for (ll i = 0; i < n; i++)
    {
        square &sqi = result[i];
        OUTX2(sqi.a, sqi.b, sqi.c, sqi.d);
    }

    return 0;
}


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

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

/*
x*K = N - S (mod N)
*/

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

// 拡張ユークリッドの互除法 O(log(lcm(a,b)))
// a*x + b*y = gcd(a,b) となる (x,y) を返す
// b*s + (a%b)*t = gcd(a,b)
// a = (a/b)*b + a%b, d = gcd(a,b) = gcd(b,a%b)
// ((a/b)*b + a%b)*x + b*y = d
// b*((a/b)*x + y) + (a%b)*x = d
// {s = (a/b)*x + y, t = x} <=> {x = t, y = s - (a/b)*t}
pair<ll,ll> ext_gcd(ll a, ll b) {
    if (b==0) return {1,0};
    pair<ll,ll> P = ext_gcd(b, a%b);
    ll s = P.first, t = P.second;
    return {t, s-(a/b)*t};
}

ll solve() {
    ll N, S, K;
    cin >> N >> S >> K;

    ll d = gcd(N,gcd(N-S,K));
    ll A = K / d, B = (N-S) / d;
    N /= d;

    if (gcd(A,N)!=1) return -1;

    ll invA = (ext_gcd(A,N).first + N) % N;

    return B * invA % N;
}

int main() {
    ll T; cin >> T;
    vector<ll> res(T);
    rep(i,T) res[i] = solve();
    for (ll ans : res) cout << ans << endl;
}

#include<bits/stdc++.h>
using namespace std;
int gcd_extend(int a, int b,
               long long& x,long long& y)
{
    // Base Case
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }

    // Recursively find the gcd
    else {
        int g = gcd_extend(b,
                           a % b, x, y);
        int x1 = x, y1 = y;
        x = y1;
        y = x1 - (a / b) * y1;
        return g;
    }
}

// Function to print the solutions of
// the given equations ax + by = c
void print_solution(long long a,long long b,long long c,long long *x1,long long *y1)
{
    long long x, y;
    if (a == 0 && b == 0) {

        // Condition for infinite solutions
        if (c == 0) {
            cout
                << "Infinite Solutions Exist"
                << endl;
        }

        // Condition for no solutions exist
        else {
            cout
                << "No Solution exists"
                << endl;
        }
    }
    int gcd = gcd_extend(a, b, x, y);

    // Condition for no solutions exist
    if (c % gcd != 0) {
        cout
            << "No Solution exists"
            << endl;
    }
    else {

        // Print the solution
        /*cout << "x = " << x * (c / gcd)
             << ", y = " << y * (c / gcd)
             << endl; */
    	*x1=x*(c/gcd);
    	*y1=y*(c/gcd);
    }
}
int main(){
    // write your code
    #ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	int T;
	cin>>T;
	while(T--)
	{
		long long n,s,k,x,y;
		cin>>n>>s>>k;
		if(s%__gcd(n,k))	{cout<<"-1\n";continue;}
		int d=__gcd(n,__gcd(k,s));
		n=n/d;
		k=k/d;
		s=s/d;
		print_solution(k,n,-s,&x,&y);
		cout<<((x%n)+n)%n<<endl;
	}
}


#include <stdio.h>
#include <math.h>

int main() {
    long long R, X, Y;
    scanf("%lld %lld %lld", &R, &X, &Y);
    int ans;
    if (X * X + Y * Y < R * R) {
        ans = 2;
    }
    else {
        double dis = sqrt((1.0 * X * X + 1.0 * Y * Y) / (1.0 * R * R));
        ans = ceil(dis);
    }
    printf("%d\n", ans);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define endl "\n"
ll mod=1000000007;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    IOS;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    //ll t;cin>>t;while(t--)
    {
        ll a,b,c,d,i,j,k,l,m,n,sum=0,temp=0,f=0,cnt=0;
        double x1,y1,x2,y2;
        cin>>x1>>y1>>x2>>y2;
        double ans=((x2*y1)+(x1*y2))/(y1+y2);
        cout<<fixed<<setprecision(7)<<ans<<endl;

    }
}


#include <iostream>
#include <vector>
#include <queue>
#include <tuple>
#include <cmath>
#include <algorithm>
using namespace std;

int K, N, M;
int A[100005];
typedef tuple<long long, int, int> P;// (error, original-index, scaled-value)
P Q[100005], R[100005];

int main() {
  scanf("%d%d%d", &K, &N, &M);
  for (int i = 0; i < K; i++) { scanf("%d", A+i); }

  double r = (double) M / (double) N;
  for (int i = 0; i < K; i++) {
    int scaled = (int)ceil(A[i] * r);
    Q[i] = make_tuple(abs((long long)N*scaled - (long long)M*A[i]), i, scaled);
  }

  int rest = 0; // to decrease
  for (int i = 0; i < K; i++) { rest += get<2>(Q[i]); }
  rest -= M;

  sort(Q, Q+K, [](P &a, P &b) {
    return get<0>(a) > get<0>(b);
  });
  for (int i = 0; i < rest; i++) {
    Q[i] = make_tuple(get<0>(Q[i]), get<1>(Q[i]), get<2>(Q[i])-1);
  }

  sort(Q, Q+K, [](P &a, P &b) {
    return get<1>(a) < get<1>(b);
  });
  for (int i = 0; i < K; i++) { printf("%d ", get<2>(Q[i])); }
  puts("");
}

#include <bits/stdc++.h>

#define int ll

typedef long long ll;

const int K = 100000;

int k, n, m;

ll a[K + 5]; int l[K + 5], r[K + 5];
bool check(ll x) {
	ll sl = 0, sr = 0;
	for (int i = 1; i <= k; i++) {
		if (a[i] - x > 0) l[i] = (a[i] - x + n - 1) / n;
		else l[i] = 0;
		r[i] = (a[i] + x) / n;

		sl += l[i], sr += r[i];
	}
	return sl <= m && m <= sr;
}

ll sl[K + 5], sr[K + 5]; int ans[K + 5];
void print(ll x) {
	// printf("! %lld\n", x);
	for (int i = 1; i <= k; i++) {
		if (a[i] - x > 0) l[i] = (a[i] - x + n - 1) / n;
		else l[i] = 0;
		r[i] = (a[i] + x) / n;

		sl[i] = sl[i - 1] + l[i], sr[i] = sr[i - 1] + r[i];
	}
	for (int i = k; i >= 1; i--) {
		if (m - l[i] <= sr[i - 1]) {
			ans[i] = l[i], m -= l[i];
		} else {
			ans[i] = m - sr[i - 1];
			for (int j = i - 1; j >= 1; j--)
				ans[j] = r[j];
			break;
		}
	}
	for (int i = 1; i <= k; i++)
		printf("%lld ", ans[i]);
	puts("");
}

signed main() {
	scanf("%lld%lld%lld", &k, &n, &m);
	for (int i = 1; i <= k; i++)
		scanf("%lld", &a[i]), a[i] *= m;

	ll le = 0, ri = (ll)n * m;
	while (le < ri) {
		ll mid = (le + ri) >> 1;
		if (check(mid)) ri = mid;
		else le = mid + 1;
	}
	print(ri);
}


#include <bits/stdc++.h>
#define endl "\n"
#define ff first
#define ss second
#define PB push_back
#define MP make_pair
#define ll long long
#define llu unsigned long long
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define ABS(X) ((X) < 0 ? -(X) : (X))
#define LCM(X, Y) (((X) / (GCD((X), (Y)))) * (Y))
#define MEM(A, B) memset((A), (B), sizeof(A))
#define MEM_VEC(V, FILL) fill(V.begin(), V.end(), FILL)
#define FOR_EACH(IT, V) for (auto IT = V.begin(); IT != V.end(); IT++)
#define DEBUG_ARRAY_PRINT(A, I) cout << "at pos " << I << "  value is: " << A[I]
#define TURBO                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0)
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;
using namespace std;
inline ll GCD(ll A, ll B)
{
    if (B == 0)
        return A;
    return GCD((B), (A % B));
}
inline ll POW(ll BASE, ll EXP)
{
    ll RES = 1;
    for (ll I = 0; I < EXP; I++)
        RES *= BASE;
    return RES;
}
inline ll BIGMOD(ll a, ll p, ll m)
{
    ll res = 1 % m;
    ll x = a % m;
    while (p > 0)
    {
        if ((p & 1) > 0)
            res = (res * x) % m;
        x = (x * x) % m;
        p >>= 1;
    }
    return res;
}
inline void FILE_HANDLE()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
int main()
{
    TURBO;
    //FILE_HANDLE() ;
    int n, a, b;
    cin >> n >> a >> b;
    cout << n - a + b << endl;
}

// Coder: @SumitRaut
#include <bits/stdc++.h>
#define speedup ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr),cout.precision(16)
using namespace std;

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

using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_map;
#define sbc __builtin_popcount
#define pb push_back
#define em emplace
#define emb emplace_back
#define ff first
#define ss second
#define ll long long
const ll mod = 1e9+7;

template<typename T> void smax(T& a, T b) { if(a<b) a=b; }
template<typename T> void smin(T& a, T b) { if(a>b) a=b; }
template<typename T> T pw(T a,T b) { T p=1,one=1; while(b) { if(b&one) p=p*a; a=a*a; b >>=1; } return p; }
template<typename T> T pwm(T a,T b,T md=mod) { T p=1,one=1; while(b) { if(b&one) p=p*a%md; a=a*a%md; b >>=1; } return p; }

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

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
	for (auto &it : v)
		os << it << ' ';
	return os;
}

#ifndef ONLINE_JUDGE
class Timer { chrono::high_resolution_clock::time_point start_t, end_t; public: Timer() { start_t=chrono::high_resolution_clock::now(); } ~Timer() { end_t = chrono::high_resolution_clock::now(); auto duration = chrono::duration_cast<chrono::milliseconds>(end_t-start_t); cerr<<"\nRunTime: "<<duration.count()<<"ms"<<'\n'; } };
void debug() { cerr << '\n'; }
template <typename T, typename... Args>
void debug(T print, Args... args) { cerr << ' ' << print; debug(args...); }
#define deb(...) cerr << "[" << #__VA_ARGS__ << "]" << " --> ", debug(__VA_ARGS__)
#else
#define deb(...) void(0)
#endif

void solve() {
	int n;
	string s,t;
	cin>>n>>s>>t;
	int j=0;
	ll res=0;
	for(int i=0;i<n;++i) {
		if(s[i]!=t[i]) {
			smax(j,i+1);
			while(j<n&&s[j]!='1') ++j;
			if(j==n) {
				cout<<"-1\n";
				return;
			}
			res+=j-i;
			s[j]='0';
		}
	}
	cout<<res<<'\n';
}

int main() {
	#ifndef ONLINE_JUDGE
	Timer timer;
	#endif
	speedup;
	//int t; cin>>t; while(t--)
	solve();
}


#include<iostream>
using namespace std;
int N;
string S,X;
int dp[2<<17][7];
bool dfs(int t,int k)
{
	if(dp[t][k]!=0)
	{
		return dp[t][k]>0;
	}
	bool win=false;
	if(t==N)
	{
		if(k==0)win=true;
	}
	else if(X[t]=='T')
	{
		if(dfs(t+1,k*10%7))win=true;
		else if(dfs(t+1,(k*10+S[t]-'0')%7))win=true;
	}
	else
	{
		if(!dfs(t+1,k*10%7))win=true;
		else if(!dfs(t+1,(k*10+S[t]-'0')%7))win=true;
		win=!win;
	}
	dp[t][k]=win?1:-1;
	return win;
}
main()
{
	cin>>N>>S>>X;
	cout<<(dfs(0,0)?"Takahashi":"Aoki")<<endl;
}

#include <iostream>

using namespace std;

const int kMaxN = 2e5;

int n, s[kMaxN], x[kMaxN];
int f[kMaxN][7];
string tmp;

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

  cin >> n >> tmp;
  f[n][0] = 1;
  for (int i = 0; i < n; i++) {
    s[i] = tmp[i] - '0';
  }
  cin >> tmp;
  for (int j = 0; j < n; j++) {
    x[j] = tmp[j] == 'T';
  }
  for (int i = n - 1; i >= 0; i--) {
    for (int j = 0; j < 7; j++) {
      f[i][j] = x[i] ^ (f[i + 1][j * 10 % 7] != x[i] && f[i + 1][(j * 10 + s[i]) % 7] != x[i]);
    }
  }
  cout << (f[0][0] ? "Takahashi" : "Aoki") << endl;
  return 0;
}


#include<bits/stdc++.h>
#define int long long
constexpr long long mod = 1000000007;
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define mp make_pair
#define all(x) x.begin(),x.end()
#define puts(x) cout << x << "\n"
using namespace std;
int dp_a[1234], dp_b[1234];
signed main() {
	int n; char cab, cba, caa, cbb;
	cin >> n >> caa >> cab >> cba >> cbb;
	if (cab == 'B') {
		if (cbb == 'B') { puts(1); return 0; }
		if (cba == 'A') {
			int ans = 1; for1(i, n - 3) { ans *= 2; ans %= mod; }
			puts(ans);
		}
		else {
			dp_b[2] = 1;
			for (int i = 3; i <= n; i++) {
				dp_a[i] = dp_b[i - 1]; dp_b[i] = dp_a[i - 1] + dp_b[i - 1];
				dp_a[i] %= mod; dp_b[i] %= mod;
			}
			puts(dp_b[n]);
		}
	}
	else {
		if (caa == 'A') { puts(1); return 0; }
		if (cba == 'B') {
			int ans = 1; for1(i, n - 3) { ans *= 2; ans %= mod; }
			puts(ans);
		}
		else {
			dp_a[2] = 1;
			for (int i = 3; i <= n; i++) {
				dp_b[i] = dp_a[i - 1]; dp_a[i] = dp_a[i - 1] + dp_b[i - 1];
				dp_a[i] %= mod; dp_b[i] %= mod;
			}
			puts(dp_a[n]);
		}
	}
}

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

using Int = long long;
const char newl = '\n';

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
template<typename T=int>
vector<T> read(size_t n){
  vector<T> ts(n);
  for(size_t i=0;i<n;i++) cin>>ts[i];
  return ts;
}

template<typename T, T MOD = 1000000007>
struct Mint{
  static constexpr T mod = MOD;
  T v;
  Mint():v(0){}
  Mint(signed v):v(v){}
  Mint(long long t){v=t%MOD;if(v<0) v+=MOD;}

  Mint pow(long long k){
    Mint res(1),tmp(v);
    while(k){
      if(k&1) res*=tmp;
      tmp*=tmp;
      k>>=1;
    }
    return res;
  }

  static Mint add_identity(){return Mint(0);}
  static Mint mul_identity(){return Mint(1);}

  Mint inv(){return pow(MOD-2);}

  Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;}
  Mint& operator/=(Mint a){return (*this)*=a.inv();}

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

  Mint operator-() const{return v?Mint(MOD-v):Mint(v);}

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

  static Mint comb(long long n,int k){
    Mint num(1),dom(1);
    for(int i=0;i<k;i++){
      num*=Mint(n-i);
      dom*=Mint(i+1);
    }
    return num/dom;
  }
};
template<typename T, T MOD> constexpr T Mint<T, MOD>::mod;
template<typename T, T MOD>
ostream& operator<<(ostream &os,Mint<T, MOD> m){os<<m.v;return os;}

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  int n;
  cin>>n;

  string s="XXXX";
  for(int i=0;i<4;i++) cin>>s[i];

  map<string, int> ans;
  ans["AAAA"]=1;
  ans["AAAB"]=1;
  ans["AABA"]=1;
  ans["AABB"]=1;
  ans["ABAA"]=128;
  ans["ABAB"]=1;
  ans["ABBA"]=34;
  ans["ABBB"]=1;
  ans["BAAA"]=34;
  ans["BAAB"]=34;
  ans["BABA"]=128;
  ans["BABB"]=128;
  ans["BBAA"]=128;
  ans["BBAB"]=1;
  ans["BBBA"]=34;
  ans["BBBB"]=1;

  if(n<=3) drop(1);

  using M = Mint<int>;
  if(ans[s]==1) drop(1);
  if(ans[s]==128) drop(M(2).pow(n-3));

  M x(1),y(1);
  for(int i=0;i<n-3;i++){
    M z=x+y;
    x=y;
    y=z;
  }
  cout<<y<<endl;
  return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define repl(i,n) for(ll i=0;i<n;i++)
#define repl1(i,n) for(ll i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define revl(i,n) for(ll i=n-1;i>=0;i--)
#define repn(i,n) for(int i=0;i<=n;i++)
#define repln(i,n) for(ll i=0;i<=n;i++)
#define lb lower_bound
#define up upper_bound
#define pb push_back
#define Mod 1000000007

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);

void solve(){

	ll n;
	cin>>n;
	vector<ll> v(n),inp(n);
	ll mx=INT_MIN;
	repl(i,n){
		cin>>v[i];
		inp[i]=v[i];
	}
	ll ans=0;

	repl(i,n-1){
		v[i+1]+=v[i];
	}
	repl(i,n-1){
		v[i+1]+=v[i];
	}
	repl(i,n){
		mx=max(mx,inp[i]);
		cout<<(ll) mx*(i+1)+v[i]<<endl;
	}

	// cout<<ans;

	return ;
}
int main(){
    fastio;
    int tc;
    tc=1;
    // cin>>tc;
    while(tc--){

    	solve();

    	if(tc) cout<<"\n";
    }

    return 0;
}

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

long long A[200005];

int main(){
    int N;
    scanf("%d", &N);

    for(int i = 0; i < N; i ++){
        scanf("%lld", &A[i]);
    }

    long long max1 = 0;
    long long tempSum = 0;
    long long prefixSum = 0;
    for(int i = 0; i < N; i ++){
        prefixSum += A[i];
        tempSum += prefixSum;
        max1 = max(max1, A[i]);
        printf("%lld\n", tempSum + max1*(i+1));
    }

    return 0;
}


//#define _GLIBCXX_DEB // Iterator safety; out-of-bounds access for Containers, etc.
//#pragma GCC optimize "trapv" // abort() on (signed) integer overflow.
#include <bits/stdc++.h>

using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

#define ll long long int
#define mod 1000000007
#define deb(x) cout << #x << "=" << x << "\n"
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << "\n"
#define prec(n) fixed << setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int>>
#define PI 3.1415926535897932384626
#define INF 1000000000
#define no_of_digits(n) floor(log10(n)) + 1
#define bits(n) __builtin_popcount(n)

void solve()
{
    char s;
    cin>>s;
    char t;
    cin>>t;
    if(s=='Y')
    {
        cout<<(char)toupper(t);
    }
    else
    cout<<(char)tolower(t);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input1.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output1.txt", "w", stdout);
#endif

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

#include <bits/stdc++.h>

using namespace std;

string s;

char get (char c) {
  if (c == '0') return '0';
  if (c == '1') return '1';
  if (c == '6') return '9';
  if (c == '9') return '6';
  if (c == '8') return '8';
  return 0;
}

int main() {
  cin >> s;
  reverse(s.begin(), s.end());
  for (char &c : s) c = get(c);
  cout << s << '\n';
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
template<typename T> bool chmax(T &x, const T &y) {return (x<y)?(x=y,true):false;};
template<typename T> bool chmin(T &x, const T &y) {return (x>y)?(x=y,true):false;};
constexpr ll MOD=1000000007;
constexpr ll INF=2e18;

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

/*
    author : aryan57
    created : 13-June-2021 17:30:46 IST
*/
#include <bits/stdc++.h>
using namespace std;

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#ifndef ONLINE_JUDGE
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

#define int long long
#define X first
#define Y second
#define pb push_back
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(), (a).end()
#define F(i, a, b) for (int i = a; i <= b; i++)
#define RF(i, a, b) for (int i = a; i >= b; i--)

const int mxn = 1e5;
const long long INF = 2e18;
const int32_t M = 1000000007;
// const int32_t M = 998244353;
const long double pie = acos(-1);

void solve_LOG()
{
    int a,b;
    cin>>a>>b;

    long double ans=a*b;
    ans/=100;

    cout<<ans;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
#ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
#endif
#ifdef ARYAN_SIEVE
    sieve();
#endif
#ifdef ARYAN_SEG_SIEVE
    segmented_sieve();
#endif
#ifdef ARYAN_FACT
    fact_init();
#endif
    // cout<<fixed<<setprecision(10);
    int _t=1;
    // cin>>_t;
    for (int i=1;i<=_t;i++)
    {
        // cout<<"Case #"<<i<<": ";
        solve_LOG();
    }
    return 0;
}
//	parsed : 13-June-2021 17:30:42 IST


//#pragma GCC optimize ("O2")
//#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;

#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

//おそそう

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	if ((tmp & ma0) ^ ma0) {
		int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
		tmp = tmp << dig & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += (72 - dig >> 3);
	}
	else {
		tmp = tmp & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += 8;
		if (*ci++ == '0') {
			tmp = tmp * 10;
			ci++;
		}
	}
	return tmp;
}
void pakuri_sort(int N, ll A[]) {
	const int b = 8;
	ll tmp[100001];
	rep(k, 4) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
	}
}
ll li[300];
int li2[300];

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

	int N = getint(), M = getint();
	int w[8];
	rep(i, N) w[i] = getint();

	ll lv[100001];
	rep(i, M) {
		ll l = getint();
		int v = getint();
		lv[i] = l << 32 | v;
	}
	pakuri_sort(M, lv);
	lv[M] = 1000000001ll;

	rep(i, 1 << N) {
		rep(j, N) if (i >> j & 1) li[i] += w[j];
		li[i] = li[i] << 30 | i;
	}
	sort(li, li + (1 << N));
	int saidai = 0;
	int k = 0;
	rep(i, 1 << N) {
		while ((lv[k] & (1 << 30) - 1) < li[i] >> 30) {
			if (saidai < lv[k] >> 32) saidai = lv[k] >> 32;
			k++;
		}
		li[i] = ll(saidai) << 30 | (li[i] & (1 << 30) - 1);
	}
	rep(i, 1 << N) li2[li[i] & (1 << 30) - 1] = li[i] >> 30;

	rep(i, N) {
		if (w[i] > (lv[0] & (1 << 30) - 1)) {
			printf("-1");
			return 0;
		}
	}
	int P[8];
	rep(i, N) P[i] = i;

	int kotae = 1e9;
	do {
		int tmp[8] = {};
		rep(p, N - 1) {
			int omosa = 1 << P[p];
			for (int q = p + 1; q < N; q++) {
				omosa |= 1 << P[q];
				int kari = tmp[p] + li2[omosa];
				if (tmp[q] < kari) tmp[q] = kari;
			}
		}
		if (kotae > tmp[N - 1]) kotae = tmp[N - 1];

	} while (next_permutation(P, P + N));

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

	Would you please return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define time_taken_start int begtime = clock();
#define time_taken_end int endtime = clock(); \
cerr << "\n\n" << "Time elapsed: " << \
(endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
return 0;
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define inf 100000000000000007
#define eps 0.000000000001
#define pi acosl(-1)
#define pdd pair<ld,ld>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define vpl vector<pll>
#define vll vector<ll>
#define mseti multiset <ll>
#define msetd multiset <ll,greater<ll>>
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define stp fixed<<setprecision(20)
#define endl '\n'
vll v;
pll p[100009];
ll n,m;
ll md;
ll dis(ll x)
{
    ll l=0,u=m-1,mid;
    ll ans=md;
    while(l<=u)
    {
        mid=(l+u)/2;
        if(p[mid].ff>=x)
        {
            u=mid-1;
        }
        else
        {
            l=mid+1;
            ans=p[mid].ss;
        }
    }
    if(u==-1)
        ans=0;
    return ans;
}
ll check()
{
    ll a[n+1];
    a[n]=0;
    ll pre[n+1];
    pre[0]=0;
    for(ll i=0;i<n;i++)
    {
        a[i]=0;
        pre[i+1]=v[i]+pre[i];
    }
    ll sum;
    for(ll i=2;i<=n;i++)
    {
        sum=0;
        for(ll j=i-1;j>0;j--)
        {
            ll x=pre[i]-pre[j-1];
            a[i]=max(a[i],dis(x)-sum);
            //cout<<i<<' '<<j<<' '<<x<<' '<<dis(x)<<' '<<a[j]<<' '<<sum<<endl;
            sum+=a[j];
        }
    }
    sum=0;
    for(ll i=0;i<=n;i++)
        sum+=a[i];
    return sum;
}
void solve()
{
    cin>>n>>m;
    ll x,y;
    ll cm=0,bm=inf;
    for(ll i=0;i<n;i++)
    {
        cin>>x;
        v.pb(x);
        cm=max(cm,x);
    }
    for(ll i=0;i<m;i++)
    {
        cin>>p[i].ss>>p[i].ff;
        bm=min(bm,p[i].ff);
        md=max(md,p[i].ss);
    }
    if(cm>bm)
    {
        cout<<-1;
        return;
    }
    sort(p,p+m);
    for(ll i=1;i<m;i++)
    {
        p[i].ss=max(p[i].ss,p[i-1].ss);
    }
    ll ans=inf;
    sort(v.begin(),v.end());
    do{
        ans=min(check(),ans);
    }while(next_permutation(v.begin(),v.end()));
    cout<<ans;
}
int main()
{
    FAST
    #ifdef ayk_16
    freopen("input.txt","rt",stdin);
    freopen("output.txt","wt",stdout);
    #endif
    time_taken_start
    ll t=1;
    //cin>>t;
    for(ll i=0;i<t;i++)
    {
        //cout<<"Case #"<<i+1<<": ";
        solve();
    }
    time_taken_end
}


#include<bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(int i=a; i<b; i++)
#define fr(i,a,b) for(int i=a; i>=b; i--)
typedef vector<int> vi;
typedef long long int ll;
typedef vector<ll> vll;
#define fastio std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PI 3.1415926535
// ll Mod = 1e9+7;
// ll N = 1e5;

ll Mod = 998244353;

ll mult(ll a, ll b) {
    ll ret = 1;
    ret = ((a%Mod) * (b%Mod))%Mod;
    return ret;
}

ll power(ll a, ll b = Mod-2) {
    if(b == 0) return 1;
    ll ret = 1;
    while(b) {
        if(b&1) {
            ret = mult(ret,a);
        }
        a = mult(a,a);
        b>>=1;
    }
    return ret;
}

// ll sub(ll a, ll b) {
//     ll ret = (a%Mod - b%Mod + Mod)%Mod;
//     return ret;
// }

// void seive(vector<bool> &status) {
//      for(ll i = 2; i<=1e6; i++) {
//          if(status[i]) {
//                 for(ll j =i*i; j<=1e6; j+=i) status[j] = 0;
//          }
//      }
//  }

// int getmex(vi& occr, int n, int mex) {
//     for(int i = mex; i<n; i++) {
//         if(occr[i] == 0) return i;
//     }
//     return n;
// }

// void swap(int &a, int &b) {
//     a = a + b;
//     b = a - b;
//     a = a - b;
// }

void test_case() {
    ll h,w,k,x,y;
    cin>>h>>w>>k;
    char a,grid[h][w];
    ll moves[h+1][w+1];
    memset(moves,0,sizeof moves);

    f(i,0,h) {
        f(j,0,w) {
            grid[i][j] = '.';
        }
    }

    f(i,0,k) {
        cin>>x>>y;
        x--; y--;
        cin>>a;
        grid[x][y] = a;
    }

    moves[0][0] = 1;
    ll d = power(3,Mod-2);
    f(i,0,h) {
        f(j,0,w) {
            if(grid[i][j] == '.') {
                int add =  mult(mult(2,moves[i][j]),d);
                moves[i+1][j] = (moves[i+1][j] + add)%Mod;
                moves[i][j+1] = (moves[i][j+1] + add)%Mod;
            } else {
                if(grid[i][j] == 'X') {
                    moves[i][j+1] = (moves[i][j+1] + moves[i][j])%Mod;
                    moves[i+1][j] = (moves[i+1][j] + moves[i][j])%Mod;
                }
                else if(grid[i][j] == 'R') {
                    moves[i][j+1] = (moves[i][j+1] + moves[i][j])%Mod;
                }
                else {
                    moves[i+1][j] = (moves[i][j] + moves[i+1][j])%Mod;
                }
            }
        }
    }

    cout<<mult(moves[h-1][w-1],power(3,h*w-k))<<'\n';
}

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

	fastio;
    // vector<bool> status(1e6+1,1);
    int t = 1;
    // vll primes;
    // seive(status);
    // f(i,2, 1e6+1) {
    //     if(status[i]) primes.push_back(i);
    // }
    // cin>>t;
    while(t--) {
        test_case();
    }
}


#include <bits/stdc++.h>
using namespace std;
template<typename T = int> vector<T> create(size_t n){ return vector<T>(n); }
template<typename T, typename... Args> auto create(size_t n, Args... args){ return vector<decltype(create<T>(args...))>(n, create<T>(args...)); }
template <typename T>
struct fenwick {
    int n, lgn;
    vector<T> fenw;
    fenwick(int n): n(n) {
        for(lgn = 0; (1<<lgn) <= n; lgn++);
        fenw.resize(n);
    }
    T get(int p){
        T r = T();
        for(; p; p -= p & -p)
            r = r + fenw[p];
        return r;
    }
    T get(int l, int r){
        return get(r) - get(l - 1);
    }
    void add(int p, T v){
        for(; p < n; p += p & -p)
            fenw[p] = fenw[p] + v;
    }
    int lower_bound(T v){
        int p = 0;
        T sum = 0;
        for(int i = lgn - 1; i >= 0; i--){
            int np = p + (1<<i);
            if(np < n && sum + fenw[np] < v){
                p = np;
                sum = sum + fenw[p];
            }
        }
        return p + 1;
    }
};
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n), b(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int i = 0; i < n; i++) cin >> b[i];
	using ll = long long;
	ll d = 0;
	for(int i = 0; i < n; i++) d += a[i] - b[i];
	if(d != 0) return cout << -1 << '\n', 0;
	for(int i = 0; i < n; i++) a[i] += i, b[i] += i;
	map<int, vector<int>> pos;
	for(int i = n - 1; i >= 0; i--){
		pos[b[i]].push_back(i);
	}
	for(int i = 0; i < n; i++){
		if(pos[a[i]].empty()){
			return cout << -1 << '\n', 0;
		}
		int x = pos[a[i]].back();
		pos[a[i]].pop_back();
		a[i] = x + 1;
	}
	fenwick<int> fenw(n + 1);
	long long ans = 0;
	for(int i = 0; i < n; i++){
		ans += i - fenw.get(a[i]);
		fenw.add(a[i], 1);
	}
	cout << ans << '\n';
	return 0;
}

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

int n;
long long t, arr[45];
vector<int> v[2];
vector<long long> p[2];
int id;
long long ans = 0;

void solve(int idx, long long sum) {
    if (sum > t) return;

    if (idx == v[id].size()) {
        // cout << "SUM " << sum << endl;
        p[id].push_back(sum);
        return;
    }
    solve(idx + 1, sum);
    solve(idx + 1, sum + v[id][idx]);
}

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

    cin >> n >> t;
    for (int i = 1; i <= n; i++) cin >> arr[i];
    sort(arr + 1, arr + n + 1);
    reverse(arr + 1, arr + n + 1);

    for (int i = 1; i <= n / 2; i++) v[0].push_back(arr[i]);
    for (int i = n / 2 + 1; i <= n; i++) v[1].push_back(arr[i]);
    id = 0;
    solve(0, 0);
    id = 1;
    solve(0, 0);
    for (int i = 0; i < 2; i++) sort(p[i].begin(), p[i].end());

    // for (long long x : p[0]) cout << "0 x " << x << "\n";
    // for (long long x : p[1]) cout << "1 x " << x << "\n";
    for (long long x : p[0]) {

        int pos = (int)(lower_bound(p[1].begin(), p[1].end(), t + 1 - x) - p[1].begin());
        if (pos == 0) continue;
        if (p[1][pos - 1] + x > t) continue;
        ans = max(ans, x + p[1][pos - 1]);
    }
    cout << ans << "\n";

    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()
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); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
const ll INF = 1LL<<60;

int main() {
	ll v, t, s, d;
	cin >> v >> t >> s >> d;

	if(v*t <= d && d <= s*v) {
		cout << "No" << endl;
	} else {
		cout << "Yes" << endl;
	}

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define DEBUG
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    for(int i = 0; i < (int)v.size(); i++) {
        if(i) { os << ','; }
        os << v[i];
    }
    os << '}';
    return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
    cerr << " " << x;
    debugg(args...);
}
#define debug(...)                                                             \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,-1,0,1,1,-1,-1,1};
ll dx[8] = {-1,0,1,0,1,-1,1,-1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    int sz = a.size();
    for(auto itr = a.begin(); itr != a.end(); itr++){
		cout << *itr;
        sz--;
        if(sz) cout << " ";
	}
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){
	cout << a << " " << b << "\n";
}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
void mark() {cout << "#" << "\n";}
ll pcount(ll x) {return __builtin_popcountll(x);}
const int mod = 1e9 + 7;
//const int mod = 998244353;

ll a[202020];

int main(){
	int n,w; cin >> n >> w;
	rep(i,n){
		ll s,t,p; cin >> s >> t >> p;
		a[s] += p;
		a[t] -= p;
	}
	rep(i,201010) a[i+1] += a[i];
	rep(i,201010){
		if(a[i] > w){
			cout << "No" << "\n";
			return 0;
		}
	}
	cout << "Yes" << "\n";
}


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

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) for(auto x:obj)cout<<x<<' ';cout<<endl;
typedef vector<vector<int>> state;

bool is_spread(int id);
void fill(double dur, int width);
void init();
void adinit(int id);
void output();
void update(int id, int asp, int width);
int score();

struct d1{
    int x, y, r;
};

const int EDGE = 10000;
const double tlimit = 4700;
const double ideal_rate = 0.98;
double ntime;
double Stime;
int n;
int weightsum = 0;
vector<d1> req(200);
state ans(200, vector<int>(4));
vector<int> area(200);
vector<int> ideal(200);
vector<int> weight(EDGE*EDGE);
vector<bool> expandable(200, true);

random_device seed;
mt19937_64 gen(seed());

int main(){
    Stime = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
    ntime = Stime;
    init();

    fill(tlimit, 2);

    output();
    return 0;
}

void fill(double dur, int width){
    double endtime = Stime + dur;
    while(ntime < endtime){
        ntime = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
        int id = gen() % n;
        if(area[id] > ideal[id] || !expandable[id])continue;
        int asp = gen() % 4;
        update(id, asp, width);
    }
}

void update(int id, int asp, int width = 1){
    bool ok = false;
    rep(i,4){
        int dir = (asp+i) % 4;
        int ramda = 1;
        if(dir <= 1){
            if(ans[id][dir] - width < 0)continue;
        }else{
            if(ans[id][dir] + width > EDGE)continue;
            ramda = -1;
        }
        ans[id][dir] -= width*ramda;
        if(is_spread(id)){
            int height = 0;
            if(dir % 2 == 0)height = ans[id][3] - ans[id][1];
            else height = ans[id][2] - ans[id][0];
            area[id] += width * height;
            ok = true;
        }else{
            ans[id][dir] += width*ramda;
        }
    }

    if(!ok)expandable[id] = false;

}

bool is_spread(int id){
    bool res = true;
    rep(i,n){
        if(i == id)continue;
        if(! (ans[id][2] <= ans[i][0] || ans[i][2] <= ans[id][0] ||
                    ans[id][3] <= ans[i][1] || ans[i][3] <= ans[id][1]) )res = false;
    }
    return res;
}

int score(){
    double sat = 0;
    rep(i,n){
        if(ans[i][0] <= req[i].x && req[i].x < ans[i][2] &&
                ans[i][1] <= req[i].y && req[i].y < ans[i][3]){
            int s = (ans[i][2] - ans[i][0]) * (ans[i][3] - ans[i][1]);
            double t = 1 - (double)min(req[i].r, s)/(double)max(req[i].r, s);
            sat += 1 - t*t;
        }
    }
    sat /= n;
    return (int)1e9 * sat;
}

void init(){
    cin >> n;
    rep(i,n){
        cin >> req[i].x >> req[i].y >> req[i].r;
        adinit(i);
        ideal[i] = req[i].r * ideal_rate;
    }
}

void adinit(int id){
    ans[id][0] = req[id].x;
    ans[id][1] = req[id].y;
    ans[id][2] = req[id].x + 1;
    ans[id][3] = req[id].y + 1;
    area[id] = 1;
}

void output(){
    rep(i,n){
        rep(j,4){
            if(j != 0)cout << ' ';
            cout << ans[i][j];
        }
        cout << "\n";
    }
}

#include<bits/stdc++.h>
#define int long long
#define ll long long
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define fs first
#define sd second
#define rept(x,n) for(int i=x;i<n;i++)
#define rrept(n,x) for(int i=n-1;i>=x;i--)
#define all(v) v.begin(),v.end()
#define mpit map<int,int>::iterator
#define stit set<int,int>::iterator
#define quit queue<int,int>::iterator
#define maxt(a,b,c) max(a,max(b,c))
#define mint(a,b,c) min(a,min(b,c))
#define rsort(v) sort(v.rbegin(),v.rend())
#define pb push_back
#define printarr(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" ";cout<<"\n";
#define printvec(v) for(int i = 0;i<v.size();i++)cout<<v[i]<<" ";cout<<"\n";
using namespace std;
using namespace std::chrono;
ll power(ll a,ll b){ll res = 1;while(b){if(b&1)res*=a;a*=a;b/=2;}return res;}
ll powerwithmod(ll a,ll b,ll mod){ll res = 1;while(b){if(b&1)res*=a;res%=mod;a*=a;a%=mod;b/=2;}return res;}
void sieve(vector<ll>&prime,ll n){ll contestant[n+1]={0};contestant[0]=1;contestant[1]=1;contestant[2]=0;
for(ll i = 4;i<=n;i+=2)contestant[i]=1;for(ll i = 3;i*i<=n;i+=2){if(contestant[i]==0){
for(ll j = i*i;j<=n;j+=i){contestant[j] = 1;}}}for(ll i = 2;i<=n;i++){if(contestant[i]==0)prime.pb(i);}}

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

void solve()
{
	ll n;
	cin>>n;
	string s;
	cin>>s;
	ll q;
	cin>>q;
	ll cnt2=0;
	while(q--)
	{
		ll t,a,b;
		cin>>t>>a>>b;
		if(t==2)
		{
			cnt2^=1;
		}
		else
		{
			if(cnt2==0)
				swap(s[a-1],s[b-1]);
			else
			{
				if(a<=n&&b<=n)
				{
					swap(s[n+a-1],s[n+b-1]);
				}
				else if(a>n&&b>n)
				{
					swap(s[a-1-n],s[b-1-n]);
				}
				else
				{
					swap(s[n+a-1],s[b-1-n]);
				}
			}
		}
	}
	if(cnt2==1)
	{
		for(ll i = n;i<2*n;i++)
			cout<<s[i];
		for(ll i = 0;i<n;i++)
			cout<<s[i];
	}
	else
		cout<<s<<"\n";
}
signed main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("error.txt", "w", stderr);
	freopen("output.txt", "w", stdout);
	#endif
    speed;
    int t=1;
    //cin>>t;
	auto start = high_resolution_clock::now();
    while(t--)
    {
         solve();
    }
	auto stop = high_resolution_clock::now();
	auto duration = duration_cast<microseconds>(stop - start);
#ifndef ONLINE_JUDGE
	cerr << "Time: " << duration.count()/1000.0 << endl;
#endif
	return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<double, int> P;
#define rep(i, x) for (int i = 0; i < x; i++)

auto start = std::chrono::system_clock::now();
int cnt = 0;

double gettime() {
    auto end = std::chrono::system_clock::now();
    double ms = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
    return ms;
}

bool finish() {
    if (cnt % 100 == 0 && gettime() > 1980)
        return true;
    else
        return false;
}

bool LOCAL_TEST = false;
vvi h(30, vi(29)), v(29, vi(30));
int si, sj, ti, tj, a, prev_result;
double e, score;

string query() {
    string res;
    int di = ti - si;
    if (di >= 0) {
        rep(l, di) { res += "D"; }
    } else {
        rep(l, -di) { res += "U"; }
    }
    int dj = tj - sj;
    if (dj >= 0) {
        rep(l, dj) { res += "R"; }
    } else {
        rep(l, -dj) { res += "L"; }
    }
    return res;
}

int main() {
    start = std::chrono::system_clock::now();
    if (LOCAL_TEST) {
        rep(i, 30) rep(j, 29) cin >> h[i][j];
        rep(i, 29) rep(j, 30) cin >> v[i][j];
    }
    prev_result = 0;
    score = 0.0;
    for (int k = 0; k < 1000; k++) {
        if (LOCAL_TEST) {
            cin >> si >> sj >> ti >> tj >> a >> e;
        } else {
            cin >> si >> sj >> ti >> tj;
        }
        string path = query();
        cout << path << endl;
        if (LOCAL_TEST) {
            int b = path.length();
            score = score * 0.998 + a / b;
            prev_result = round(b * e);
        } else {
            cin >> prev_result;
        }
    }
    if (LOCAL_TEST) {
        cout << round(2312311 * score) << endl;
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using pii = pair<int, int>;

ll solve(){
    int si, sj, ti, tj;
    cin >> si >> sj >> ti >> tj;
    int v = ti - si;
    int h = tj - sj;
    string rou;
    if(v>0) rou += string(v,'D');
    else rou+= string(-v, 'U');
    if(h>0) rou += string(h, 'R');
    else rou += string(-h, 'L');
    cout << rou << endl;
    ll score;
    cin >> score;
    return score;
}

int main(){
    rep(q, 1000){
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,s,n) for (int i = (s); i < (n); ++i)
#define rrep(i,n,g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define len(x) (int)(x).size()
#define dup(x,y) (((x)+(y)-1)/(y))
#define pb push_back
#define eb emplace_back
#define Field(T) vector<vector<T>>
#define pq(T) priority_queue<T,vector<T>,greater<T>>
using namespace std;
using ll = long long;
using P = pair<int,int>;

struct ArbitraryModInt {
  int x;
  ArbitraryModInt() : x(0) {}
  ArbitraryModInt(int64_t y) : x(y >= 0 ? y % get_mod() : (get_mod() - (-y) % get_mod()) % get_mod()) {}

  static int &get_mod() {
    static int mod = 0;
    return mod;
  }
  static void set_mod(int md) {
    get_mod() = md;
  }

  ArbitraryModInt &operator+=(const ArbitraryModInt &p) {
    if((x += p.x) >= get_mod()) x -= get_mod();
    return *this;
  }
  ArbitraryModInt &operator-=(const ArbitraryModInt &p) {
    if((x += get_mod() - p.x) >= get_mod()) x -= get_mod();
    return *this;
  }
  ArbitraryModInt &operator*=(const ArbitraryModInt &p) {
    unsigned long long a = (unsigned long long) x * p.x;
    unsigned xh = (unsigned) (a >> 32), xl = (unsigned) a, d, m;
    asm("divl %4; \n\t" : "=a" (d), "=d" (m) : "d" (xh), "a" (xl), "r" (get_mod()));
    x = m;
    return *this;
  }
  ArbitraryModInt &operator/=(const ArbitraryModInt &p) {
    *this *= p.inv();
    return *this;
  }
  ArbitraryModInt operator-() const { return ArbitraryModInt(-x); }
  ArbitraryModInt operator+(const ArbitraryModInt &p) const { return ArbitraryModInt(*this) += p; }
  ArbitraryModInt operator-(const ArbitraryModInt &p) const { return ArbitraryModInt(*this) -= p; }
  ArbitraryModInt operator*(const ArbitraryModInt &p) const { return ArbitraryModInt(*this) *= p; }
  ArbitraryModInt operator/(const ArbitraryModInt &p) const { return ArbitraryModInt(*this) /= p; }
  bool operator==(const ArbitraryModInt &p) const { return x == p.x; }
  bool operator!=(const ArbitraryModInt &p) const { return x != p.x; }

  ArbitraryModInt inv() const {
    int a = x, b = get_mod(), u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ArbitraryModInt(u);
  }
  ArbitraryModInt pow(int64_t n) const {
    ArbitraryModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }
  friend ostream &operator<<(ostream &os, const ArbitraryModInt &p) {
    return os << p.x;
  }
  friend istream &operator>>(istream &is, ArbitraryModInt &a) {
    int64_t t;
    is >> t;
    a = ArbitraryModInt(t);
    return (is);
  }
};

using mint = ArbitraryModInt;

void mul(vector<mint> &dp, int d) {
  int MAX = len(dp)-1;
  rrep(i,MAX+1,d) {
    dp[i] -= dp[i - d];
  }
}

void div(vector<mint> &dp, int d) {
  int MAX = len(dp);
  rep(i,d,MAX+1) {
    dp[i] += dp[i - d];
  }
}

int main() {
  int n, k, m;
  cin >> n >> k >> m;
  mint::set_mod(m);
  vector<mint> dp(n*n*k+1, 0);
  vector<vector<mint>> vals(n+1, vector<mint>(n*n*k+1));
  dp[0] = mint(1);
  vals[0][0] = dp[0];
  rep(i,1,n) {
    div(dp, i);
    mul(dp, i*(k+1));
    rep(j,0,n*n*k) {
      vals[i][j] = dp[j];
    }
  }
  rep(i,0,n) {
    mint ans = 0;
    rep(j,0,n*n*k+1) {
      ans += vals[i][j] * vals[n-i-1][j];
    }
    cout << ans*(k+1)-1 << endl;
  }
  return 0;
}

/* May the force be with you */
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define FASTANDFURIOUS ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define For(i,n) for(ll i=0;i<n;i++)
#define MOD 1000000007
#define MAX 1000001
#define pll pair <ll,ll>
#define pii pair <int,int>
#define dbg(x)    cout << #x << ": " << x << endl;
#define read(n,v) For(i,n)cin>>v[i]
#define mxh priority_queue<int>
#define mnh priority_queue<int,vector<int>,greater<int>>
#define mkp make_pair
#define YES cout<<"YES\n";
#define NO cout<<"NO\n";
#define fi first
#define se second
#define No cout<<"No\n";
#define Yes cout<<"Yes\n";
#define endl '\n'
#define INF 1e18

vl fact(1001,1);

ll pow(ll x, unsigned ll y, ll p){
    ll res=1LL;
    x=x%p;
    if (x==0) return 0;
    while (y > 0){
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
ll _pow(int a, int b){
    if(!b)
        return 1;
    ll temp = _pow(a, b / 2);
    temp = (temp * temp);
    if(b % 2)
        return (a * temp);
    return temp;
}
ll invmod(int a,int m){
    return pow(a,m-2,m);
}
ll ncr(int n,int r){
    if(n<r)
        return 0;
    ll ans=fact[n];
    ans*=invmod(fact[n-r],MOD);
    ans%=MOD;
    ans*=invmod(fact[r],MOD);
    ans%=MOD;
    return ans;
}
ll ncr_2(ll n, ll k ){
    if (k > n) return 0;
    if (k * 2 > n) k = n-k;
    if (k == 0) return 1;

    ll result = n;
    for(ll i = 2; i <= k; ++i ) {
        result = result * (n-i+1);
        result /= i;
    }
    return result;
}
bool ok(int x){
    int l = sqrt(x);
    if(l*l == x){
        return true;
    }
    else{
        return false;
    }
}
signed main(){
   FASTANDFURIOUS;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    int tc=1;
    // cin>>tc;
    For(t,tc){
        int n;
        cin>>n;
        if(n%100){
            cout<<n/100+1<<endl;
        }
        else{
            cout<<n/100<<endl;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define f(i,n) for(int i=0; i<n; ++i)
#define fi(i,st,n) for(int i=st; i<=n; ++i)
#define veci vector<int>
#define vecp vector<pair<int,int> >
#define vecl vector<ll>
int prime[100000+10];

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

ll power(ll a, ll n, ll mod) {
	ll res = 1;
	while(n > 0) {
		if(n&1) {
			res = (res*a)%mod;
		}
		a = (a*a)%mod;
		n = n/2;
	}
	return res;
}

ll sum(int arr[], int n) {
	ll res = 0;
	f(i,n) {
		res += arr[i];
	}
	return res;
}

void seive() {
	prime[1] = 0;
	for(int i=2; i<=100000; i++) {
		prime[i] = 1;
	}
	for(ll i=2; i<=100000; i++) {
		if(prime[i]) {
			for(ll j=i*i; j<=100000; j+=i) {
				prime[j] = 0;
			}
		}
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t = 1;
//	cin>>t;
	while(t--){
		ll a,b,c;
		cin>>a>>b>>c;
		if(a == b) {
			if(c == 0) cout<<"Aoki";
			else cout<<"Takahashi";
		}
		else {
			if(a > b) {
				cout<<"Takahashi";
			} else {
				cout<<"Aoki";
			}
		}
	}
 	return 0;
}

/**
 *  author: sourav rakshit
 *  created: 13.12.2020 17:30:15
**/
/*
#pragma GCC optimize("O3")
#pragma GCC target ("avx2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/

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

using namespace std;

namespace std
{
#define ar array
#define len(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define str(s) to_string(s)

    //@y_combinator
    template <class F>
    struct y_combinator
    {
        F f;
        template <class... Args>
        decltype(auto) operator()(Args &&... args) const
        {
            // the lambda should take the first argument as `auto&& recurse` or similar.
            return f(*this, std::forward<Args>(args)...);
        }
    };
    template <class F>
    y_combinator<std::decay_t<F>> make_y_combinator(F &&f)
    {
        return {std::forward<F>(f)};
    }

//@Debugger
#ifdef LOCAL
    template <typename T>
    ostream &operator<<(ostream &os, const vector<T> &v)
    {
        os << '{';
        string sep;
        for (const auto &x : v)
            os << sep << x, sep = ", ";
        return os << '}';
    }
    template <typename T, size_t size>
    ostream &operator<<(ostream &os, const array<T, size> &arr)
    {
        os << '{';
        string sep;
        for (const auto &x : arr)
            os << sep << x, sep = ", ";
        return os << '}';
    }
    template <typename A, typename B>
    ostream &operator<<(ostream &os, const pair<A, B> &p)
    {
        return os << '(' << p.first << "," << p.second << ')';
    }

    void flush_out() { cerr << endl; }
    template <typename H, typename... T>
    void flush_out(H h, T... t)
    {
        cerr << ' ' << h << " | ";
        flush_out(t...);
    }
#define log(...) cerr << "[ " << #__VA_ARGS__ << " ] :", flush_out(__VA_ARGS__)
#else
#define log(...) (void)0x30
#endif

    template <typename T>
    inline void mini(T &a, T b)
    {
        a = min(a, b);
    }
    template <typename T>
    inline void maxi(T &a, T b) { a = max(a, b); }
    template <class T>
    class Random
    {
        static T range(T &a, T &b) { return a + rand() % (b - a + 1); }
    };
    template <class K, class V>
    using table = __gnu_pbds::gp_hash_table<K, V>;
    template <typename K, typename V, typename Comp = std::less<K>>
    using ordered_map = __gnu_pbds::tree<
        K, V, Comp,
        __gnu_pbds::rb_tree_tag,
        __gnu_pbds::tree_order_statistics_node_update>;
    template <typename K, typename Comp = std::less<K>>
    using ordered_set = ordered_map<K, __gnu_pbds::null_type, Comp>;
}; // namespace std

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;

const int mod = 1e9 + 7;
const ll INF = 1e18;
const ld PI = 4 * atan((ld)1);

void test_case(const int &tc) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << min({a, b, c, d}) << '\n';
}

int main(int argc, char *argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int _t = 1;
    for (int _ = _t - 1; ~_; --_)
    {
        test_case(_);
    }

#ifdef LOCAL
    cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
#endif
}
// overflows? index_of_of_bound? integer_overflows?