                   /**Bismillahir Rahmanir Rahim.**/
/*
         Md.Fagun Molla
         18ICTCSE006
         BSMRSTU(SHIICT)
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
using ll=long long;
using db=double;
///***************************************************** CONSTANTS ******************************************************///

int const N=1e6+3;
ll MOD=1e9+7,fact[N];
const long long inf=(long long)1e18;
const long double PI=3.14159265358979;

///************************************************ CONTAINER DEFINITIONS ***********************************************///

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

///************************************************ SHORT FORM KEYWORDS *************************************************///

#define PB push_back

#define F first
#define S second
#define MP make_pair
#define I insert
#define lb lower_bound
#define ub upper_bound
#define endl '\n'

///************************************************ SHORT FORM FUNCTIONS ************************************************///

#define loop(a,b) for(ll i=a;i<b;i++)
#define loopr(a,b) for(ll i=a-1;i>=b;i--)
#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sa(v) sort(v.begin(),v.end())
#define sd(v) sort(v.begin(),v.end(),greater<>())
#define rev(s) reverse(s.begin(),s.end())
#define stll(x) stoll(x, nullptr, 10);
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
#define mx(a) *max_element(all(a))
#define mn(a) *min_element(all(a))
#define all(a) a.begin(),a.end()
#define mxa(a,N) *max_element(a,a+N)
#define mna(a,N) *min_element(a,a+N)
#define print(a) {for(auto x:a)cout<<x<<" ";cout<<endl;}
#define io() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

///************************************************ SOLUTION STARTS HERE ************************************************///
///======================================================================================================================///

void solve(){
	int a,b,c;
	cin>>a>>b>>c;
	if(c==0){
		if(a>b) cout<<"Takahashi"<<endl;
		else cout<<"Aoki"<<endl;
	}
	else {
		if(a<b) cout<<"Aoki"<<endl;
		else cout<<"Takahashi"<<endl;
	}
}
int main()
{
   	io();
    int T=1;//cin>>T;
    while(T--) solve();
    return 0;
}

/****************ALHAMDULILLAH******************/

#include <bits/stdc++.h>
#include<math.h>
#include<queue>
#include<cstdio>
#include<set>
#include<map>
using namespace std;
using ll = long long;

int main(){
    int A,B,C;
    cin >> A >> B >> C;
    if(C==1){
        if(A>B) cout << "Takahashi" << endl;
        if(A<B) cout << "Aoki" << endl;
        if(A==B) cout << "Takahashi" << endl;
    }else{
        if(A>B) cout << "Takahashi" << endl;
        if(A<B) cout << "Aoki" << endl;
        if(A==B) cout << "Aoki" << endl;
    }
    return 0;
}


// Problem : E - Queen on Grid
// Contest : AtCoder - AtCoder Beginner Contest 183
// URL : https://atcoder.jp/contests/abc183/tasks/abc183_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// God & me
// Fly ...
//#pragma GCC optimize "trapv"//  WA to RE int!!
#include <bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORR(i,n) for(int i=n;i>=0;i--)
#define pb push_back
#define vint vector<int>
#define sint set<int>
#define mint map<int,int>
#define pint pair< int,int >
#define int long long int
#define test int tt1234; cin>>tt1234;while(tt1234--)
#define endl "\n"
#define input(a,n) int n;cin>>n;vint a(n);for(int&v:a)rd(v);
#define all(zz) zz.begin(),zz.end()
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define error(x) cerr << #x <<" is " << x << endl;
#define Error(a,b) cerr<<"( "<<#a<<" , "<<#b<<" ) = ( "<<(a)<<" , "<<(b)<<" )\n";
#define precision(x) cout<<fixed<<setprecision(x);
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define present(container, element) (container.find(element)!=container.end())
#define fint fast;test
#define set(a,x) memset(a,x,sizeof(a))
#define L(x)	((x)<<1)
#define R(x)	(((x)<<1)+1)
#define ft first
#define se second
#define MOD 1000000007
using namespace std;
template<typename... T> void rd(T&... args) { ((cin >> args), ...); }
template<typename... T> void pp(T... args) { ((cout << args << " "), ...); cout<<"\n"; }

int n,m;
int arr[3001][3001];
int dp[2005][2005];

int go(int x,int y)
{
	if(x==n-1 && y==m-1) return 1;
	if(x>=n || y>=m) return 0;
	int ans=0;

	if(dp[x][y]!=-1) return dp[x][y]%MOD;
	for(int i=x+1;i<n;i++)
	{
		if(arr[i][y]==1)break;
		ans=(ans%MOD+go(i,y)%MOD)%MOD;
	}

	for(int j=y+1;j<m;j++)
	{
		if(arr[x][j]==1)break;
		ans=(ans%MOD+go(x,j)%MOD)%MOD;
	}

	for(int i=1;;i++)
	{
		int X=x+i,Y=y+i;
		if(X>=n || Y>=m || arr[X][Y]==1)break;
		ans=(ans%MOD+go(X,Y)%MOD)%MOD;
	}

	return dp[x][y]=ans%MOD;
}

void solve(){
	rd(n,m);
	rep(i,1,n+1){
		rep(j,1,m+1){
			char c;
			rd(c);
			arr[i][j]=(c=='.')?0:1;
		}
	}
	int U[n+1][m+1]={0},D[n+1][m+1]={0},DG[n+1][m+1]={0};
	dp[1][1]=1;
	U[1][1]=1;
	D[1][1]=1;
	DG[1][1]=1;
	int con=1;
	rep(j,2,m+1)
	{
		if(arr[1][j]==1)break;
		else dp[1][j]=con%MOD,con+=dp[1][j]%MOD;
		U[1][j]=dp[1][j]%MOD;
		D[1][j]=dp[1][j]%MOD;
		DG[1][j]=dp[1][j]%MOD;
	}
	con=1;
	rep(i,2,n+1)
	{
		if(arr[i][1]==1)break;
		else
		{
			dp[i][1]=con%MOD,con+=dp[i][1]%MOD;
			U[i][1]=dp[i][1]%MOD;
			D[i][1]=dp[i][1]%MOD;
			DG[i][1]=dp[i][1]%MOD;
		}
	}

	for(int i=2;i<=n;i++)
	{
		for(int j=2;j<=m;j++)
		{
			if(arr[i][j]==1)dp[i][j]=0;
			else
			{
				dp[i][j]=(U[i-1][j]%MOD+D[i][j-1]%MOD+DG[i-1][j-1]%MOD)%MOD;
				U[i][j]=(U[i-1][j]%MOD+dp[i][j]%MOD)%MOD;
				D[i][j]=(D[i][j-1]%MOD+dp[i][j]%MOD)%MOD;
				DG[i][j]=(DG[i-1][j-1]%MOD+dp[i][j]%MOD)%MOD;
			}
		}
	}

	// rep(i,1,n+1){
		// rep(j,1,m+1){
			// cout<<dp[i][j]<<" ";
		// }
		// cout<<endl;
	// }
	pp(dp[n][m]%MOD);
	return;
}

int32_t main() {
    fast;
    // memset(dp,-1,sizeof(dp));
    solve();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const int mod=998244353;
int n,m,k,ans;
void update(int &x,int y) {
	x+=y; if (x>=mod) x-=mod;
}

int ksm(int x,int y) {
	int res=1;
	while (y) {
		if (y&1) res=(ll)res*x%mod;
		x=(ll)x*x%mod; y>>=1;
	} return res;
}

int main() {
	//freopen("1.txt","r",stdin);
	read(n),read(m),read(k);
	if (n==1) { printf("%d\n",ksm(k,m)); return 0; }
	if (m==1) { printf("%d\n",ksm(k,n)); return 0; }
	for (int i=1;i<=k;i++) {
		update(ans,(ll)ksm(k-i+1,m)*(ksm(i,n)-ksm(i-1,n)+mod)%mod);
	}
	printf("%d\n",ans);
	return 0;
}
/*
  0. Enough array size? Enough array size? Enough array size? Integer overflow?

  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?

  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?

  3. Do not make STUPID MISTAKES!
  Time complexity? Memory usage? Precision error?
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=2e3+5;
ll dp[maxn][maxn],sum[3][maxn*2],belong[maxn][maxn];
char buff[maxn][maxn];
const int mod=1e9+7;
int main() {
    int n,m;cin>>n>>m;
    for(int i=1;i<=n;i++) cin>>(buff[i]+1);
    for(int i=1;i<=m;i++) belong[1][i]=i;
    for(int i=2;i<=n;i++) belong[i][1]=m+i-1;
    for(int i=1;i<=n;i++) {
        for(int j=1;j<=m;j++) {
            if(belong[i][j]) continue;
            belong[i][j]=belong[i-1][j-1];
        }
    }
    dp[1][1]=1;
    for(int i=1;i<=n;i++) {
        for(int j=1;j<=m;j++) {
            if(buff[i][j]=='#') {
                sum[0][belong[i][j]]=sum[1][i]=sum[2][j]=0;
            }else {
                if(i!=1||j!=1) dp[i][j]=(sum[0][belong[i][j]]+sum[1][i]+sum[2][j])%mod;
                (sum[0][belong[i][j]]+=dp[i][j])%=mod;
                (sum[1][i]+=dp[i][j])%=mod;
                (sum[2][j]+=dp[i][j])%=mod;
            }
        }
    }
    cout<<dp[n][m]%mod<<endl;
    return 0;
}


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

#define ll long long
#define print(a)        for (auto x : a) cout << x << " "; cout << endl
#define print_upto(a,n)        for(ll i=1;i<=n;i++)    cout<<a[i]<<" "; cout<<endl
#define take(a,n)           for(ll i=1;i<=n;i++)  cin>>a[i];

#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"
#define watch3(x,y,z) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<"\n"

#define ff first
#define ss second
#define null NULL
#define all(c) (c).begin(),(c).end()
#define nl "\n"

#define ld long double
#define eb emplace_back
#define pb push_back
#define pf push_front
#define MOD 1000000007
#define inf INT_MAX
// cout << fixed << setprecision(9) << ans << nl;

typedef vector<ll> vl;
typedef vector< vl > vvl;
typedef pair< ll, ll> pll;
typedef map< ll, ll> mll;

const ll N = 200009;

void solve() {
	ld x, y, r;
	cin>>x>>y>>r;

	double ep = 1e-14;
	r = r + ep;

	ld lx = x-r;
	ld rx = x+r;

	ld llx = ceil(lx);
	ld rrx  = floor(rx);

	ll ans=0;
	for(ld i=llx;i<=rrx;i++){
		ld res = (r*r) - (i-x)*(i-x);
		if(res<0)
			continue;
		res = sqrt(res);

		ld ly = res + y;
		ld ry = -res + y;

		ld lly = ceil(ry);
		ld rry = floor(ly);

		ans += (ll)(rry-lly+1);
	}

	cout<<ans<<nl;
}

int main() {

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

	ll t = 1;
	// cin >> t;

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

	return 0;
}

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

typedef long double ld;
typedef long long ll;

const ld eps = 1e-10l;

ld X, Y, R;
ll res;

int main()
{
	cin >> X >> Y >> R;
	for (int i = X - R - 5; i <= X + R + 5; i++) {
		int intY = Y;
		int lef = Y - R - 5, rig = intY;
		while (lef <= rig) {
			int m = (lef + rig) / 2;
			if (ld(i - X) * ld(i - X) + ld(Y - m) * (Y - m) <= R * R + eps)
				rig = m - 1;
			else lef = m + 1;
		}
		if (lef <= intY) res += intY - lef + 1;
		lef = intY + 1, rig = Y + R + 5;
		while (lef <= rig) {
			int m = (lef + rig) / 2;
			if (ld(i - X) * ld(i - X) + ld(Y - m) * (Y - m) <= R * R + eps)
				lef = m + 1;
			else rig = m - 1;
		}
		if (rig > intY) res += rig - intY;
	}
	cout << res << endl;
    return 0;
}


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

const ll mod = 1e9 + 7;
const int maxn = 2002;
char saveori[maxn][maxn];

ll ff[4100005];
void init(){
    ff[0] = 1;
    for(int i =1;i<=4000005;i++){
        ff[i] = ff[i - 1] * 2;
        ff[i] %= mod;
    }
}

int tor[maxn][maxn];
int tol[maxn][maxn];
int tou[maxn][maxn];
int tod[maxn][maxn];

void solve(){
    int n ,m;
    cin>>n>>m;
    for(int i =1;i<=n;i++){
        scanf("%s", saveori[i] + 1);
    }

    int tot = 0;
    for(int i =1;i<=n;i++){
        for(int j = 1;j<=m;j++){
            tot += (saveori[i][j] == '.');
        }
    }

    for(int i =1;i<=n;i++){
        tol[i][0] = 0;
        for(int j = 1;j<=m;j++){
            if(saveori[i][j] == '.'){
                tol[i][j] = tol[i][j-1] + 1;
            }
            else{
                tol[i][j] = 0;
            }
        }
    }

    for(int i =1;i<=n;i++){
        tor[i][m+1] = 0;
        for(int j =m;j>=1;j--){
            if(saveori[i][j] == '.'){
                tor[i][j] = tor[i][j+1] + 1;
            }
            else{
                tor[i][j] = 0;
            }
        }
    }

    for(int j = 1;j<=m;j++){
        tou[int(0)][j] = 0;
        for(int i = 1;i<=n;i++){
            if(saveori[i][j] == '.'){
                tou[i][j] = tou[i-1][j] + 1;
            }
            else{
                tou[i][j] = 0;
            }
        }
    }

    for(int j = 1;j<=m;j++){
        tod[n+1][j] = 0;
        for(int i = n;i>=1;i--){
            if(saveori[i][j] == '.'){
                tod[i][j] = tod[i + 1][j] + 1;
            }
        }
    }

    int ans = 0;
    for(int i =1;i<=n;i++){
        for(int j = 1;j<=m;j++){
            if(saveori[i][j] != '.')
                continue;
            ll nowcnt = tol[i][j] + tod[i][j] + tor[i][j] + tou[i][j];
            nowcnt-=3;
            ll nowans = (ff[nowcnt] - 1)* ff[tot - nowcnt];
            nowans %= mod;
            ans += nowans;
            ans %= mod;
        }
    }
    cout<<ans<<endl;
}

signed main() {
    //freopen("in.txt", "r", stdin);
    init();
    solve();
}

#include <bits/stdc++.h>

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

using namespace std;
using ll = long long;

template<typename T>
T pown(T b, ll e) {
    if(e == 0) return 1;
    T p = pown(b, e / 2);
    if(e % 2 == 0) return p * p;
    return p * p * b;
}

template<const int mod>
struct Intmod {
    ll a;
    Intmod(ll a = 0): a(((a % mod) + mod) % mod) {}

    Intmod operator-() const {return Intmod(-a);}

    Intmod& operator+=(const Intmod b) {
        if((a += b.a) >= mod) a -= mod;
        return *this;
    }
    Intmod& operator+=(const ll b) {
        if((a += b) >= Intmod(mod).a) a -= mod;
        return *this;
    }
    Intmod& operator-=(const Intmod b) {
        if((a -= b.a) < 0) a += mod;
        return *this;
    }
    Intmod& operator-=(const ll b) {
        if((a -= Intmod(b).a) < 0) a += mod;
        return *this;
    }
    Intmod& operator*=(const Intmod b) {
        (a *= b.a) %= mod;
        return *this;
    }
    Intmod& operator*=(const ll b) {
        (a *= Intmod(b).a) %= mod;
        return *this;
    }

    template<typename T> Intmod operator+(const T b) const {return Intmod(*this) += b;}
    template<typename T> Intmod operator-(const T b) const {return Intmod(*this) -= b;}
    template<typename T> Intmod operator*(const T b) const {return Intmod(*this) *= b;}

    // Valid for prime mod. pown() needs to be included.
    int i = 0;
    Intmod inv() {
        if(a == 0) throw "Inverse of zero does not exist.";
        if(!i) i = pown(*this, mod - 2).a;
        return Intmod(i);
    }
    Intmod& operator/=(const Intmod b) {return *this *= b.inv();}
    Intmod& operator/=(const ll b) {return *this *= Intmod(b).inv();}
    template<typename T> Intmod operator/(const T b) const {return Intmod(*this) /= b;}
};
template<const int mod> Intmod<mod> operator+(const ll b, Intmod<mod> a) {return a += b;}
template<const int mod> Intmod<mod> operator-(const ll b, Intmod<mod> a) {return a -= b;}
template<const int mod> Intmod<mod> operator*(const ll b, Intmod<mod> a) {return a *= b;}
template<const int mod> Intmod<mod> operator/(const ll b, Intmod<mod> a) {return a /= b;} //Valid for prime mod.

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

    const int MOD = 1000000007;

    int h, w, k = 0;
    cin >> h >> w;
    vector<string> s(h);
    rep(i, h) {
        cin >> s.at(i);
        rep(j, w) if(s.at(i).at(j) == '.') k++;
    }

    vector<vector<int>> eh(h, vector<int>(w)), ew(h, vector<int>(w));
    int temp = 0;
    rep(i, h) {
        temp = 0;
        rep(j, w + 1) {
            if(j == w || s.at(i).at(j) == '#') {
                for(int jt = temp; jt < j; ++jt) ew.at(i).at(jt) = j - temp;
                temp = j + 1;
            }
        }
    }
    rep(i, w) {
        temp = 0;
        rep(j, h + 1) {
            if(j == h || s.at(j).at(i) == '#') {
                for(int jt = temp; jt < j; ++jt) eh.at(jt).at(i) = j - temp;
                temp = j + 1;
            }
        }
    }

    Intmod<MOD> bi = 2;
    Intmod<MOD> ans = pown(bi, k);
    ans *= k;

    rep(i, h) {
        rep(j, w) {
            if(s.at(i).at(j) == '.') ans -= pown(bi, k + 1 - eh.at(i).at(j) - ew.at(i).at(j));
        }
    }

    printf("%lld\n", ans.a);

    return 0;
}


#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define pb push_back
#define mp make_pair

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

int A[1 << 16];

int main() {
  int n;
  S(n);
  int idx = 0;
  rep(i,0,1<<n) {
    S(A[i]);
    if(A[i] > A[idx]) {
      idx = i;
    }
  }
  int ans = -1;
  int y = (1 << (n - 1));
  rep(i,0,1<<n) {
    if((idx < y && i >= y) || (idx >= y && i < y)) {
      if(ans == -1 || A[i] > A[ans]) {
        ans = i;
      }
    }
  }
  P(ans + 1);
  return 0;
}

#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#define print(a) for(auto i : a) { cout << i << " "; } cout << endl;
#endif
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define all(v) v.begin(), v.end()
#define rep(i, begin, end) for(int i = begin; i < (int)(end); i++)
#define contains(v, x) (find(all(v), x) != v.end())
template<class T> bool chmin(T& a, T b){ if (a > b){ a = b; return true; } return false; }
template<class T> bool chmax(T& a, T b){ if (a < b){ a = b; return true; } return false; }
template<class T> T roundup(T a, T b){ return (a + b - 1) / b; }
const double PI = 3.14159265359;
const vector<int> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
const vector<int> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};
using ll = long long;
struct Edge{ int to; ll cost; Edge(int to, ll cost) : to(to), cost(cost) {} };
const ll MOD = (ll)1e9 + 7;
const ll INF = (ll)1e9;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
/*#include <atcoder/all>
using namespace atcoder;
using mint = modint;*/

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    //mint::set_mod(MOD);

    int n;
    cin >> n;
    int p1 = -1, p2 = -1;
    int ans1 = -1, ans2 = -1;
    rep(i, 0, pow(2, n - 1)){
        int a;
        cin >> a;
        if(chmax(ans1, a)) p1 = i;
    }
    rep(i, 0, pow(2, n - 1)){
        int a;
        cin >> a;
        if(chmax(ans2, a)) p2 = pow(2, n - 1) + i;
    }
    cout << (ans1 < ans2 ? p1 : p2) + 1 << endl;
}


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tiii;

//#define x first
//#define y second
#define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define fopen freopen("input.txt", "r", stdin)
#define eb emplace_back
#define em emplace
#define prec(a) cout << fixed;cout.precision(a);
#define all(a) (a).begin(), (a).end()

const ll INF = 2e18;
const int inf = 2e9;
template<class T>
void pr(T t) {cerr << t << " ";}
template<class T, class ...Args>
void pr(T a, Args ...args) {cerr << a << " ";pr(args...);}
template<class ...Args>
void prl(Args ...args) {pr(args...);cerr << endl;}

const ll mxN  = 1e6 + 10;
const ll mod = 998244353;
const double eps = 1e-14;

struct Point {
    double x, y;
    Point(double a = 0, double b = 0){
        x = a, y = b;
    }
    Point operator - (const Point &a) const {
        return Point(x - a.x , y - a.y);
    }
    Point operator + (const Point &a) const {
        return Point(x + a.x, y + a.y);
    }
    Point operator / (const double &a) const{
        return Point(x / a, y / a);
    }
    Point operator * (const double &a) const{
        return Point(x * a, y * a);
    }
    double operator * (const Point &a) const{
        return x * a.y - y * a.x;
    }
    double operator ^ (const Point &a) const{
        return x * a.x + y * a.y;
    }
};

typedef Point Vector;

struct Line {
    Point x, y;
    Line () {}
    Line(Point a, Point b){
        x = a, y = b;
    }
};

int main()
{
   fastio;
   ll n;
   cin >> n;
   ll ans = 1e18;
   for(int i=0;i<n;i++)
   {
       ll a, p, x;
       cin >> a >> p >> x;
       if(a < x)
       {
           ans = min(ans, p);
       }
   }
   cout << (ans == (ll) 1e18 ? -1 : ans) << endl;

}

#include<bits/stdc++.h>
using namespace std;
# define ll long long
# define read read1<ll>()
# define Type template<typename T>
Type T read1(){
	T t=0;
	char k;
	bool vis=0;
	do (k=getchar())=='-'&&(vis=1);while('0'>k||k>'9');
	while('0'<=k&&k<='9')t=(t<<3)+(t<<1)+(k^'0'),k=getchar();
	return vis?-t:t;
}
# define fre(k) freopen(k".in","r",stdin);freopen(k".out","w",stdout)
void exgcd(ll u,ll v,ll &x,ll &y){
	if(!v){x=1,y=0;return;}
	if(u<v){
		exgcd(v,u,y,x);x=-x;y=-y;
		return;
	}ll i=u/v;
	exgcd(u%v,v,x,y);
	y+=x*i;
}
int main(){
	for(int T=read;T--;){
		int x=read,y=read,p=read,q=read;
		ll a=x+y<<1,b=p+q,d=__gcd(a,b);ll ans=-1;
		for(int i=x;i<x+y;++i)
			for(int j=p;j<p+q;++j){
				ll c=j-i;//ax-by=c
				if(c/d*d!=c)continue;
				ll l=a/d,r=b/d,u=0,v=0;c/=d;//lu-rv=c
				exgcd(l,r,u,v);//lu-rv=1
				u*=c;v*=c;//lu-rv=c
				ll m=max(max((r-u-1)/r,(l-v-1)/l),0ll);
				u+=r*m,v+=l*m;
				m=max(min(u/r,v/l),0ll);
				u-=r*m;v-=l*m;
				//cout<<u*a+i<<' '<<v*b+j<<endl;
				if(!~ans||ans>v*b+j)ans=v*b+j;
			}if(~ans)cout<<ans<<endl;
			else puts("infinity");
	}
	return 0;
}


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

const long long MOD = 1e9+7;
const long long N = 25e4+10;

#define ll int
// typedef long long ll;
typedef long double ld;

ll r, c, n;

ll get(ll i, ll j) {
    return (i * c + j);
}

vector<array<int, 2>> g[N];
int d[N];

void dijkstra(int s) {
    fill(d, d+n+1, MOD);
   d[s] = 0;
   using pii = pair<int, int>;
   priority_queue<pii, vector<pii>, greater<pii>> q;
   q.push({0, s});
   while (!q.empty()) {
      int v = q.top().second;
      int d_v = q.top().first;
      q.pop();
      if (d_v != d[v])
         continue;
      for (auto [to, len] : g[v]) {
         if (d[v] + len < d[to]) {
            d[to] = d[v] + len;
            q.push({d[to], to});
         }
      }
   }
}

void test_case() {
    cin >> r >> c;
    n = r * c;
    vector<vector<ll>> a(r, vector<ll>(c)), b(r, vector<ll>(c));
    for(int i = 0; i < r; i++) {
        for(int j = 0; j < c-1; j++) {
            cin >> a[i][j];
        }
    }
    for(int i = 0; i < r-1; i++) {
        for(int j = 0; j < c; j++) {
            cin >> b[i][j];
        }
    }

    for(int i = 0; i < r; i++) {
        for(int j = 0; j < c-1; j++) {
            ll x = get(i, j);
            ll y = get(i, j+1);
            g[x].push_back({y, a[i][j]});
            g[y].push_back({x, a[i][j]});
        }
    }
    for(int i = 0; i < r-1; i++) {
        for(int j = 0; j < c; j++) {
            ll x = get(i, j);
            ll y = get(i+1, j);
            g[x].push_back({y, b[i][j]});
        }
    }
    for(int i = 0; i < r; i++) {
        for(int j = 0; j < c; j++) {
            for(int k = 1; k <= i; k++) {
                ll x = get(i, j);
                ll y = get(i-k, j);
                g[x].push_back({y, 1+k});
            }
        }
    }
    ll st = get(0, 0);
    ll ed = get(r-1, c-1);
    dijkstra(st);
    cout << d[ed] << '\n';

}

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

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

int charToInt(char c){
    char zero_num = '0';
    return (int)c - (int)zero_num;
}

signed main(){

    int R, C; cin>>R>>C;
    vector<vec_int> A(R, vec_int(C-1));
    rep(i,R)rep(j,C-1)cin>>A.at(i).at(j);

    vector<vec_int> B(R-1, vec_int (C));
    rep(i,R-1)rep(j,C)cin>>B.at(i).at(j);

    vector<vec_int> visited(R, vec_int(C, 0));

    priority_queue<T2, vector<T2>, greater<T2>> pq;
    pq.emplace(0, 0, 0, 0);

    while(!pq.empty()){
        int cost, r, c, type; tie(cost, r, c, type)=pq.top(); pq.pop();
        if(visited.at(r).at(c)==1)continue;
        if(r==R-1&&c==C-1){
            cout<<cost<<endl;
            return 0;
        }
        visited.at(r).at(c) = 1;
        if(c<C-1){
            if(visited.at(r).at(c+1)==0){
                pq.emplace(cost+A.at(r).at(c), r, c+1, 1);
            }
        }
        if(c>0){
            if(visited.at(r).at(c-1)==0){
                pq.emplace(cost+A.at(r).at(c-1), r, c-1, 1);
            }
        }
        if(r<R-1){
            if(visited.at(r+1).at(c)==0){
                pq.emplace(cost+B.at(r).at(c), r+1, c, 0);
            }
        }
        if(type==1){
            for(int i=0;i<r;i++){
                if(visited.at(i).at(c)==0){
                    pq.emplace(cost+(r-i+1), i, c, 0);
                }
            }
        }
    }

    return 0;
}


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

vector<int> ans;

int calc(int n, vector<int> num)
{
  //int ans;
  //int min;
  vector<int> div;

  for(int a = 1; a <= (int)sqrt(n); a++)
  {
    if(n % a == 0)
    {
      if(a * a == n) div.push_back(num.at(a - 1));
      else
      {
        div.push_back(num.at(a - 1));
        if(a != 1) div.push_back(num.at(n / a - 1));
      }
    }
  }

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

  return div.at(div.size() - 1) + 1;
}

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

  int next;
  if(N == 1) cout << 1 << endl;
  else
  {
    ans.push_back(1);
    for(int i = 2; i <= N; i++)
    {
      next = calc(i, ans);
      ans.push_back(next);
    }
    for(int i = 0; i < N; i++)
    {
      cout << ans.at(i) << ' ';
    }
    cout << endl;
  }
}

#include <stdio.h>
#include <iostream>
#include <cmath>

using namespace std;

int get_num_digits(long long x){
    int c = 0;
    do {
        x = x / 10;
        c++;
    }
    while (x > 0);
    return c;
}

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

    int x_half = 1;
    int count = 0;

    while (true){
        int n_digits = get_num_digits(x_half);
        long long x = pow(10, n_digits) * x_half + x_half;

        if (x > N){
            break;
        }
        x_half++;
        count++;
    }

    cout << count << endl;
}


#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc
#define next          sdNNNmNNNNNNNmds
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot
#define read               tyhyt
#define rank              ytmNmo
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

struct Ed {
    int u, v, d;
};

bool comp(const Ed& a, const Ed& b) {
    return a.d < b.d;
}

const int N = 111;
int x[N], y[N], dsu[N], rank[N];
vector<Ed> ev;
int n;

int find(int u) {
    if(dsu[u] == u) return u;
    dsu[u] = find(dsu[u]);
    return dsu[u];
}

bool merge(int u, int v) {
    u = find(u), v = find(v);
    if(u == v) return false;
    if(rank[u] > rank[v]) {
        dsu[v] = u;
    } else {
        dsu[u] = v;
        if(rank[u] == rank[v]) {
            rank[v]++;
        }
    }
    return true;
}

int solve() {
    cin >> n;
    rep(i, 1, n) {
        cin >> x[i] >> y[i];
    }
    rep(i, 1, n + 2) {
        dsu[i] = i;
    }
    rep(i, 1, n) {
        rep(j, 1, i - 1) {
            int dx = x[i] - x[j], dy = y[i] - y[j];
            ev.pb({i, j, dx * dx + dy * dy});
        }
        int dy1 = y[i] + 100, dy2 = 100 - y[i];
        ev.pb({i, n + 1, dy1 * dy1});
        ev.pb({i, n + 2, dy2 * dy2});
    }
    sort(rng(ev), comp);
    int ans = 0;
    rall(e, ev) {
        ans = max(ans, e.d);
        merge(e.u, e.v);
        int u = find(n + 1), v = find(n + 2);
        if(u == v) {
            break;
        }
    }
    double anss = sqrt(ans) * .5;
    cout << fixed << setprecision(13) << anss << endl;
    return 0;
}

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

/*
link:
tags:
*/
#include<bits/stdc++.h>
#define to_l(a) ((a)<<1)
#define to_r(a) ((a)<<1|1)
#define lowbit(a) ((a)&(-a))
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
const int int_inf=0x3f3f3f3f;
const ll ll_inf=0x3f3f3f3f3f3f3f3f;
const int max_n=1e2+5;
#define eps 1e-8
int x[max_n],y[max_n];
double dis[max_n][max_n];
int pa[max_n];
inline int find(int a){
	return pa[a]?pa[a]=find(pa[a]):a;
}
void merge(int a,int b){
	a=find(a),b=find(b);
	if(a==b) return ;
	pa[a]=b;
	return ;
}
bool judge(int n,double mid)
{
	mid=mid*2.0;
	pa[101]=pa[102]=0;
	for(int i=1;i<=n;i++){
		pa[i]=0;
	}
	for(int i=1;i<=n;i++){
		if(mid-(100-y[i])>eps){
			merge(i,101);
		}
		if(mid-(y[i]-(-100))>eps){
			merge(i,102);
		}
		for(int j=i+1;j<=n;j++){
			if(mid-dis[i][j]>eps){
				merge(i,j);
			}
		}
	}
	return find(101)!=find(102);
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>x[i]>>y[i];
	}
	auto get_dis = [](int a,int b) -> double{
		return sqrt((x[a]-x[b])*(x[a]-x[b])+(y[a]-y[b])*(y[a]-y[b]));
	};
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			dis[i][j]=get_dis(i,j);
		}
	}
	double l=0.0,r=100.0,res=0.0;
	while(r-l>=eps){
		double mid=(l+r)/2.0;
		if(judge(n,mid)){
			l=mid;
			res=mid;
		}else{
			r=mid;
		}
	}
	cout<<res<<endl;
	return 0;
}


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

void solve() {
  int t; cin >> t;
  auto query = []() {
    int n; cin >> n;
    unordered_map<int, bool> mp;
    for(int i=0; i<n; ++i) {
      int a; cin >> a;
      mp[a] ^= true;
    }
    if(!(n & 1)) {
      for(auto &[v, b] : mp) {
        if(b) {
          return true;
        }
      }
    }
    return false;
  };
  while(t--) {
    cout << (query() ? "First" : "Second") << '\n';
  }
}

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

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  set<int> nums;
  vector<int> a;
  for (int i = 0; i < n; i++) {
    int d;
    cin >> d;
    nums.insert(d);
    a.push_back(d);
  }
  int res = 0;
  for (int d : nums) {
    int count = 1;
    int cur = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] >= d) {
        cur++;
      }
      else {
        cur = 0;
      }
      count = max(count, cur);
    }
    res = max(res, count * d);
  }
  cout << res << "\n";
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
int main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	int n, q; cin >> n >> q;
	vector<map<int, int>> mp(n);
	vector<int> p(n,-1);
	auto find = [&](auto &&self, int x) -> int{return (p[x] < 0 ? x : p[x] = self(self,p[x]));};
	auto uni = [&](int x, int y){
		x = find(find,x);
		y = find(find,y);
		if(x != y){
			if(p[x] > p[y]) swap(x,y);
			p[x] += p[y];
			p[y] = x;
			for(auto [i,v]: mp[y]) mp[x][i] += v;
		}
	};
	rep(i,n){
		int c; cin >> c;
		mp[i][c-1] = 1;
	}
	rep(i,q){
		int t, a, b; cin >> t >> a >> b; a--; b--;
		if(t == 1) uni(a,b);
		else cout << mp[find(find,a)][b] << "\n";
	}
}

#include <bits/stdc++.h>
using namespace std;
#define mp(a,b) make_pair(a,b)
#define ff first
#define setp(a) setprecision(a)<<fixed
#define ss second
#define fori(v) for(ll i=0; i<v; i++)
#define forj(v) for(ll j=0; j<v; j++)
#define fork(v) for(ll k=0; k<v; k++)
#define forl(v) for(ll l=0; l<v; l++)
#define fort(v) for(ll t=0; t<v; t++)
#define forz(v) for(ll z=0; z<v; z++)
#define forx(v) for(ll x=0; x<v; x++)
#define fory(v) for(ll y=0; y<v; y++)
#define ll long long
#define ld long double
#define pb(a) push_back(a)
#define MAX (int)(pow(10,6) + 10)
const ll INF = 0x3f3f3f3f;
const ll inf = pow(10,18);
ll modulo = pow(10,9)+7;

vector<ll> g[MAX];
ll dp[MAX][2];
ll num[MAX][2];

void dfs(ll hd, ll pr){
	dp[hd][0] = 0;
	num[hd][0] = hd;

	dp[hd][1] = -inf;
	num[hd][1] = -1;

	for(auto& hr : g[hd]){
		if(hr == pr){
			continue;
		}
		dfs(hr, hd);

		if(dp[hr][0] + 1 > dp[hd][0]){
			dp[hd][1] = dp[hd][0];
			num[hd][1] = num[hd][0];
			dp[hd][0] = dp[hr][0] + 1;
			num[hd][0] = num[hr][0];
		}
		else if(dp[hr][0] + 1 > dp[hd][1]){
			dp[hd][1] = dp[hr][0] + 1;
			num[hd][1] = num[hr][0];
		}

	}
}

ll tin[MAX];
ll tout[MAX];

void dfsForT(ll hd, ll pr,ll& tim){
	tin[hd] = tim;
	for(auto& hr: g[hd]){
		if(hr == pr){
			continue;
		}
		++tim;
		dfsForT(hr, hd, tim);
	}
	tout[hd] = tim;
}

ll val[MAX];

void dfsFinal(ll hd, ll pr, ll& tar, ll& tim){
	val[hd] = tim;

	ll lz = -1;

	for(auto& hr: g[hd]){
		if(hr == pr){
			continue;
		}
		if(tin[hr]  <= tin[tar] && tout[hr] >= tin[tar] ){
			lz = hr;
		}
		else{
			++tim;
			dfsFinal(hr, hd, tar, tim);
		}
	}

	if(lz!=-1){
		++tim;
		dfsFinal(lz, hd, tar, tim);
	}

	++tim;
}

void deal(){
	ll n;
	cin>>n;
	fori(n-1){
		ll ai, bi;
		cin>>ai>>bi;
		--ai, --bi;
		g[ai].pb(bi);
		g[bi].pb(ai);
	}

	dfs(0, -1);

	ll lz = 0;
	fori(n){
		if(dp[i][0] + dp[i][1] > dp[lz][0] + dp[lz][1]){
			lz = i;
		}
	}

	ll root = num[lz][0];
	ll tar = num[lz][1];

//	cout<<"root is "<<root+1<<" target is "<<tar+1<<" sum is "<<dp[lz][0]+dp[lz][1]<<" lz is "<<lz+1<<endl;

	ll tim = 0;

	dfsForT(root, -1, tim);

	tim = 1;

	dfsFinal(root, -1, tar, tim);

	fori(n){
		cout<<val[i]<<' ';
	}

}

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


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define REP(i, n) for (int i=1; i<=(int)(n); i++)
#define FOR(i, n, m) for (int i=(n); i<=(int)(m); i++)
#define ll long long
const ll INF=1LL<<60;
const double pi=3.1415926535;

int main() {
    vector<vector<int>> dp(900, vector<int>(900));
    vector<int> vec_output;
    //通った道
    vector<vector<int>> usei(1000), usej(1000);
    vector<int> usedoutput(1000);

    rep(i, 1000) {

        //入力
        vector<int> input(4);
        rep(j, 4) cin >> input.at(j);

        usei.at(i).push_back(input.at(0));
        usej.at(i).push_back(input.at(1));

        int x = input.at(1);
        int y = input.at(0);
        int xplus = 0;
        int yplus = 0;
        if (x < input.at(3)) xplus = 1;
        if (x > input.at(3)) xplus = -1;
        if (y < input.at(2)) yplus = 1;
        if (y > input.at(2)) yplus = -1;
        bool X = false;

        //経路探索
        while (x != input.at(3)) {
            //ｘの残りをうめる
            if (y == input.at(2)) {
                while (x != input.at(3)) {
                    x += xplus;
                    usei.at(i).push_back(y);
                    usej.at(i).push_back(x);
                    cout << (xplus == 1 ? "R" : "L") << flush;
                }
                break;
            }

            //探索済みか近いかを調べる
            if (dp.at(y*30 + x).at(y*30 + x+xplus) == 0 && dp.at(y*30 + x).at((y+yplus)*30 + x) == 0) {
                X = !X;
            } else if (dp.at(y*30 + x).at(y*30 + x+xplus) == 0) {
                X = true;
            } else if (dp.at(y*30 + x).at((y+yplus)*30 + x) == 0) {
                X = false;
            } else if (dp.at(y*30 + x).at(y*30 + x+xplus) < dp.at(y*30 + x).at((y+yplus)*30 + x)) {
                X = true;
            } else if (dp.at(y*30 + x).at(y*30 + x+xplus) > dp.at(y*30 + x).at((y+yplus)*30 + x)) {
                X = false;
            }

            if (X) {
                x += xplus;
                usei.at(i).push_back(y);
                usej.at(i).push_back(x);
                cout << (xplus == 1 ? "R" : "L") << flush;
            } else {
                y += yplus;
                usei.at(i).push_back(y);
                usej.at(i).push_back(x);
                cout << (yplus == 1 ? "D" : "U") << flush;
            }
        }

        //yの残りをうめる
        while (y != input.at(2)) {
            y += yplus;
            usei.at(i).push_back(y);
            usej.at(i).push_back(x);
            cout << (yplus == 1 ? "D" : "U") << flush;
        }
        cout << endl;

        //入力
        ll output;
        cin >> output;

        //点数の平均を計算
        int size = usei.at(i).size();
        output *= 60;
        output /= size;
        vec_output.push_back(output);
        ll sum = 0;
        for (ll a : vec_output) {
            sum += a;
        }
        ll ave = sum / vec_output.size();
        vector<ll> put_output;
        for (ll a : vec_output) {
            put_output.push_back(a-ave);
        }

        rep(j, put_output.size()) {
            put_output.at(j) -= usedoutput.at(j);
            usedoutput.at(j) = put_output.at(j);
            rep(k, usei.at(j).size()-1) {
                int a = usei.at(j).at(k);
                int b = usej.at(j).at(k);
                int c = usei.at(j).at(k+1);
                int d = usej.at(j).at(k+1);
                //cout << a*30+b << " " << c*30+d << endl;
                dp.at(a*30+b).at(c*30+d) += put_output.at(j);
                dp.at(c*30+d).at(a*30+b) += put_output.at(j);
            }
        }

        /*rep(j, 29) {
            rep(k, 29) {
                cout << " " << dp.at(j*30+k).at(j*30+k+1);
            }
            cout << endl;
            rep(k, 30) {
                cout << dp.at(j*30+k).at((j+1)*30+k) << " ";
            }
            cout << endl;
        }*/
    }
}

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

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

struct edge
{
  int to;
  int cost;

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

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

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

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

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

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

  return pathString;
}

unsigned int xor128(){
  static unsigned int x=123456789,y=362436069,z=521288629,w=88675123;
  unsigned int t = (x^(x<<11));
  x=y; y=z; z=w;
  return( w=(w^(w>>19))^(t^(t>>8)) );
}

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

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

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

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

  return 0;
}


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

int main()
{
   int t;
   cin>>t;
   ll sum3 = 0;
   while(t--)
   {
       ll a,b;
       cin>>a>>b;
       a--;
       ll sum1 = (a*(a+1))/2;
       ll sum2 = (b*(b+1))/2;
        sum3 +=  sum2-sum1;

   }
   cout<<sum3<<endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    cin.tie(0);
    cout.tie(0);
    int n,i,s=0;
    cin>>n;
    int A[n];
    for(i=0;i<n;i++)
    {
        cin>>A[i];
        if(A[i]<=10)
        {
            A[i]=0;
        }
        else
        {
            A[i]=A[i]-10;
        }
        s+=A[i];
    }
    cout<<s<<endl;
    return 0;
}


/*
	Author:Frozencode
*/
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> pii;
const ll maxn = 100010;
const ll INF = 2147483647;
ll n, c[maxn], cnt, res[maxn], x, y;
bool vis[maxn];
ll col[maxn];
vector <ll> e[maxn];
void dfs(ll tem){
	vis[tem] = 1;
	if(!col[c[tem]])res[++cnt] = tem;
	col[c[tem]]++;
	for(int i = 0; i < e[tem].size(); i++){
		if(!vis[e[tem][i]])dfs(e[tem][i]);
	}
	col[c[tem]]--;
}
int main()
{
	ios::sync_with_stdio(false);
	cin >> n;
	for(int i = 1; i <= n; i++)cin >> c[i];
	for(int i = 1; i < n; i++){
		cin >> x >> y;
		e[x].pb(y);
		e[y].pb(x);
	}
	dfs(1);
	sort(res + 1, res + cnt + 1);
	for(int i = 1; i <= cnt; i++)cout << res[i] << endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
ll I=1167167167167167167;
ll Q=1e9+7;
#define rep(i,a) for (ll i=0;i<a;i++)
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end());reverse(v.begin(),v.end());}
template<class T> void print_tate(vector<T> &v) {rep(i,v.size()) cout<<v[i]<<"\n";}
void yneos(bool a){if(a) cout<<"Yes"<<"\n"; else cout<<"No"<<"\n";}

ll N;
vector<ll> p;
vector<ll> c(1e5);
vector<ll> ans,seen;
vector<vector<ll>> G;

void DFS(int a){
	seen[a]=1;
	if(c[p[a]]==-1){
		ans.push_back(a);
		c[p[a]]=a;
	}
	for(auto x:G[a]){
		if(seen[x]==0) DFS(x);
	}
	if(c[p[a]]==a) c[p[a]]=-1;
}

//Cとかで出てみたい
int main() {
	cin>>N;
	rep(i,N){
		ll a;
		cin>>a;
		a--;
		p.push_back(a);
	}
	G.resize(N);
	rep(i,N-1){
		ll a,b;
		cin>>a>>b;
		a--,b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	seen.resize(N);
	rep(i,1e5) c[i]=-1;
	DFS(0);
	rep(i,ans.size()) ans[i]++;
	So(ans);
	print_tate(ans);
}


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

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define for_(i, a, b) for(int i = (a);i < (b);++i)
#define ford_(i, a, b) for(int i = (b)-1;i >= (a);--i)
#define rep(i, n) for_(i, 0, n)
#define repd(i, n) rfor_(i, 0, n)

int main(){
  int a,b;

  cin >> a >> b;

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

  return 0;
}


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

#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define pf(a) push_front(a)
#define ef(a) emplace_front(a)
#define pob pop_back()
#define pof pop_front()
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define mt make_tuple
#define gt(t, i) get<i>(t)
#define iceil(a, b) (((a) + (b) - 1) / (b))
#define tomax(a, b) ((a) = max((a), (b)))
#define tomin(a, b) ((a) = min((a), (b)))
#define topos(a) ((a) = (((a) % MOD + MOD) % MOD))
#define uni(a) a.resize(unique(iter(a)) - a.begin())
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
    if(pvaspace) b << " "; pvaspace=true;\
    b << pva;\
}\
b << "\n";}

using namespace std;
using namespace __gnu_pbds;

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

using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using tiii = tuple<int, int, int>;

const ll MOD = 1000000007;
const ll MAX = 2147483647;

template<typename A, typename B>
ostream& operator<<(ostream& o, pair<A, B> p){
    return o << '(' << p.F << ',' << p.S << ')';
}

vector<int> prime, lpf;

void sieve(int n){
    lpf.resize(n + 1, 1);
    for(int i = 2; i <= n; i++){
        if(lpf[i] == 1){
            lpf[i] = i;
            prime.eb(i);
        }
        for(int j : prime){
            if((ll)j * i > n) break;
            lpf[i * j] = j;
            if(j == lpf[i]) break;
        }
    }
}

int main(){
    StarBurstStream

//    sieve(40000);

    int n;
    cin >> n;
    map<int, int> tmp;
    int mn = MAX;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        mn = min(mn, a);
        for(int j = 1; (ll)j * j <= a; j++){
            if(a % j) continue;
            tmp[j] = __gcd(tmp[j], a);
            tmp[a / j] = __gcd(tmp[a / j], a);
        }
    }

    int ans = 0;
    for(pii i : tmp){
        if(i.F == i.S && i.F <= mn) ans++;
    }
    cout << ans << "\n";

    return 0;
}

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int l;
#define M 1000000007
#define loop(i,n)           for(int i=0;i<n;i++)
const l inf = 9e17;
struct triplet
{
    l src;
    l dest;
    l weigh;
};
l sum;
l pa(int n)
{
    l cnt=0;
    for(int i=1;i*i<=n;i++)
    {
        if(i*i==n)
            sum+=i;
        else if(n%i==0)
            {
               sum+=i;
               sum+=(n/i);
            }

    }
    return sum%M;
}

l vis[10001];
map<l,vector<l>>mp;
int dfs(l st)
{
    if(vis[st])
        return 0;
    vis[st]=1;
    l ans=0;
    for(auto x:mp[st])
    {
        if(!vis[x])
        {
            ans+=dfs(x);
        }
    }
    return ans+1;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output1.txt","w",stdout);
    #endif

    l t;
    t=1;
    while(t--)
    {

            l n,m;
            cin>>n>>m;

            l a,b;
            loop(i,m)
            {
                cin>>a>>b;
                mp[a].push_back(b);
            }
            //vis.resize(n+1);
            l ams=0;
            loop(i,n){
               memset(vis,0,sizeof(vis));
               l z = dfs(i+1);
               //cout<<z<<endl;
               ams+=z;

            }
            cout<<ams;

    }

    return 0;

}


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

int main() {
    mt19937 rng(48);
    cout.tie(nullptr)->sync_with_stdio(false);
    int N, M; cin >> N >> M;

    array<array<bool, 20>, 20> graph{};
    for (int i = 0; i < M; ++i) {
        int a, b; cin >> a >> b;
        --a, --b;
        graph[a][b] = graph[b][a] = true;
    }

    int mi = N;
    vector<int> S(N), cc(N);
    iota(S.begin(), S.end(), 0);
    for (int it = 0; it <= 25; ++it) {
        shuffle(S.begin(), S.end(), rng);
        int color = 1;
        for (int i = 1; i < N; ++i) {
            int Q = 0;
            for (int j = 0; j < i; ++j) {
                if (!graph[S[j]][S[i]]) Q |= (1 << cc[j]);
            }
            Q ^= (1 << color) - 1;
            if (Q == 0) {
                cc[i] = color++;
            } else {
                while (true) {
                    cc[i] = uniform_int_distribution<int>(0, color + 1)(rng);
                    if (Q & (1 << cc[i])) break;
                }
            }
        }
        mi = min(mi, color);
    }

    cout << mi << '\n';
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#ifndef aa
#define trace(...)
#define endl '\n'
#endif
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef long double ld;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define frev(a,b,c) for(int a=c; a>=b; a--)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
#define done(x) {cout << x << endl;return;}
#define mini(x,y) x=min(x,y)
#define maxi(x,y) x=max(x,y)
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
//const int mod = 998244353;
const int mod = 1e9 + 7;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vpii;
typedef map<int, int> mii;
typedef set<int> si;
typedef set<pair<int,int>> spii;
typedef queue<int> qi;
uniform_int_distribution<int> rng(29,1e9);

//DEBUG FUNCTIONS START
#define cerr cout
void __print(int x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
//#define deb(x...) cerr << "[" << #x << "] = "; _print(x)
#define deb(x...)  _print(x)
#else
#define deb(x...)
#endif
// DEBUG FUNCTIONS END

const int N = 2e5+5;

void solve(){

	int n, m;
	cin >> n >> m;

	vvi g(n, vi(n));
	rep(_, 0, m){
		int u, v;
		cin >> u >> v;
		u--, v--;
		g[u][v] = 1;
		g[v][u] = 1;
	}

	vi dp(1<<n);

	rep(msk,0,1<<n){
		bool ok = 1;
		rep(i,0,n){
			rep(j,i+1,n){
				if((msk >> i & 1) && (msk >> j & 1))
					ok &= (bool)g[i][j];
			}
		}

		if(ok){
			dp[msk] = 1;
		}else{
			dp[msk] = infl;
			for(int s = msk; s; s = (s-1) & msk){
				mini(dp[msk], dp[s] + dp[s ^ msk]);
			}
		}
	}

	cout << dp[(1<<n)-1] << endl;

}

signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(10);
    int t = 1;
    //cin >> t;
    while (t--)
        solve();
    return 0;
}

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

int divide(int a, int b) {
    return (a % mod) * powm(b % mod, mod - 2) % mod;
}

int norm(int a) {
    while (a >= mod) a -= mod;
    while (a < 0) a += mod;
    return a;
}


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

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

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int N, M, p = 0;
	cin >> N >> M;
	vector<int> width, blue(M);
	int mw = N;
	FOR(i,0,M){
		cin >> blue.at(i);
	}
	sort(range(blue));
	FOR(i,0,M){
		int a = blue.at(i);
		if(a-p!=1){
			width.push_back(a - p - 1);
			mw = min(mw, a - p - 1);
		}
		p = a;
	}
	if(N!=p){
		width.push_back(N - p);
		mw = min(mw, N - p);
	}

	/*
	FOR(i,0,width.size()){
		cout << width.at(i) << " ";
	}
	cout << endl;
	cout << mw << endl;
	*/

	int sum = 0;
	FOR(i,0,width.size()){
		sum += ceil((ld)width.at(i) / mw);
	}

	cout << sum << endl;

	return 0;
}

#include <bits/stdc++.h>
#define REP(i, nn ) for(int i = 0 ; i < (int) nn; i++)
#define REPS(i, ss, nn ) for(int i = ss ; i < (int) nn; i++)
#define REV(i, ss, nn ) for(int i = ss ; i >= nn; i--)
#define deb(x) std::cout << #x << " " << x << endl;
#define debl(x) std::cout << #x << " " << x << " ";
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
namespace std{
    template<class Fun>
    class y_combinator_result{
        Fun fun_;
        public:
            template<class T>
            explicit y_combinator_result(T &&fun) : fun_(std::forward<T>(fun)){}
            template<class ...Args>
            decltype(auto) operator()(Args&&...args){
                return fun_(std::ref(*this), std::forward<Args>(args)...);
            }
    };
    template<class Fun>
    decltype(auto) y_combinator(Fun && fun){
        return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));
    }
};
template<typename T>
bool u_max(T& a, T b){
    if( a < b){
        a = b;
        return true;
    }
    return false;
}
template<typename T>
bool u_min(T& a, T b){
    if( a > b){
        a = b;
        return true;
    }
    return false;
}
// struct edge{
//     int to, from;
//     ll cost;
//     edge(){ edge(0,0);}
//     edge(int to_, ll cost_){ edge(0, -1, 0);}
//     edge(int to_, int from_, ll cost_) : to(to_), from(from_), cost(cost_){}
// };

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

void solve(){
    int n;
    read(n);
    ll subscription;
    read(subscription);
    map<ll, ll> mp;
    REP(i, n){
        ll a, b, c;
        read(a, b, c);
        mp[a] += c;
        mp[b+1] -= c;
    }
    ll pay = 0;
    ll cost = 0;
    ll last = 0;
    for(auto& [day, price] : mp){
        if(cost < subscription){
            pay += cost * (day - last);
        }else{
            pay += subscription * (day - last);
        }
        cost += price;
        // debl(day) debl(cost) deb(pay)
        last = day;
    }
    cout << pay << endl;
}

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


#include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
// #include <ext/rope>
// using namespace __gnu_cxx;
typedef long long int ll;
typedef long double ld;
#define FAST                 \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define mxe(v) *max_element(v.begin(), v.end())
#define mne(v) *min_element(v.begin(), v.end())
#define ve vector
#define lb lower_bound
#define ub upper_bound
#define bb break
#define cc continue
#define rem 1000000007
#define PI 3.141592653589793238462643383279502
ll power(ll x, ll y, ll p)
{
    ll res = 1; // Initialize result
    x = x % p;  // Update x if it is more than or
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1; // y = y/2
        x = (x * x) % p;
    }
    return res;
}
ll modInverse(ll n, ll p)
{
    return power(n, p - 2, p);
}
struct point
{
    ll x, y;
};

// ve<ve<ll>> tree;
ve <ll> ans;
ve <bool> done;
map<pair<ll, ll>, ll> val;

void dfs(ll node, ve<ll> adj[], ve<bool> &visited)
{
    visited[node] = true;

    for (int i = 0; i < (int)adj[node].size(); i += 1)
    {
        if (!visited[adj[node][i]])
        {
            // tree[node].pb(adj[node][i]);
            // tree[adj[node][i]].pb(node);
            ll x=node,y=adj[node][i];
            done[val[{x,y}]]=true;
            if (val[{x,y}]==ans[x]||val[{x,y}]==ans[y])
            {
                //nothing
            }
            else
            {
                ans[y]=val[{x,y}];
            }
            dfs(adj[node][i], adj, visited);
        }
    }
}
int main()
{
    FAST
        // freopen("input1.txt", "r", stdin);
        // freopen("output.txt", "w", stdout);
        /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
        ll n,
        m;
    cin >> n >> m;
    ans.assign(n+1,0);
    done.assign(n+1,false);
    ve<ll> adj[n + 1];
    rep(i, 0, m)
    {
        ll u, v, c;
        cin >> u >> v >> c;
        adj[u].pb(v);
        adj[v].pb(u);
        val[{u, v}] = c;
        val[{v, u}] = c;
    }
    ve<bool> visit(n + 1, false);
    dfs(1,adj,visit);
    rep (i,1,n+1)
    {
        if (done[i]==false)
        {
            rep (j,1,n+1)
            {
                if (ans[j]==0)
                {
                    ans[j]=i;
                }
            }
            break;
        }
    }
    rep (i,1,n+1)
    {
        if (ans[i]==0||visit[i]==false)
        {
            cout<<"No\n";
            return 0;
        }
    }
    rep (i,1,n+1)
    {
        cout<<ans[i]<<"\n";
    }
}

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

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

    vector<int> F(N + 1, 0), G(N + 1, 1);
    REP(i, 1, N + 1) {
        int cnt = 0, tmp = i;
        while (tmp % 3 == 0) {
            cnt++;
            tmp /= 3;
        }
        F[i] = F[i - 1] + cnt;
        G[i] = (G[i - 1] * (tmp % 3)) % 3;
    }

    auto ncr = [&](int r) {
        if (F[N - 1] - F[r] - F[N - 1 - r]) return 0;
        if (G[N - 1] == 1) {
            return (G[r] * G[N - 1 - r]) % 3;
        } else {
            return (6 - G[r] * G[N - 1 - r]) % 3;
        }
    };

    int ans = 0;
    REP(i, 0, N) {
        if (S[i] == 'B') {
            ans += ncr(i);
        } else if (S[i] == 'R') {
            ans += 2 * ncr(i);
        }
    }
    if (N % 2 == 0) ans *= -1;

    ans = (3 + ans % 3) % 3;
    if (ans == 0) {
        cout << "W" << endl;
    } else if (ans == 1) {
        cout << "B" << endl;
    } else {
        cout << "R" << endl;
    }
    return 0;
}


//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;

#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

//https://github.com/atcoder-live/library/blob/master/mint.cpp
struct mint {
  LL x;
  mint(LL x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(LL t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

struct combination {
  vector<mint> fact, ifact;//factに階乗を計算、ifactはその各々に対する逆元
  combination(LL n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (LL i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (LL i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(LL n,LL k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

LL N;
char CAA,CAB,CBA,CBB;

mint ans = 1;

mint dp(){
    //dp[i][c]:
    //i文字目までカウント、最後に使った文字がc
    vector<map<char,mint>> dp((N-3)+1);
    dp[0]['A'] = 1;
    dp[0]['B'] = 1;//Bは2文字以上連続しない
    for(int i=0;i<N-3;i++){
        dp[i+1]['A'] = (dp[i]['A'] + dp[i]['B']);
        dp[i+1]['B'] = dp[i]['A'];
    }
    return dp[N-3]['A'];
}
void solve(){
    if(N<=3) return;
    if(CAB=='A'){
        if(CAA=='A') return;
        if(CAA=='B'){
            if(CBA=='A'){
                ans = dp();
                return;
            }
            if(CBA=='B'){
                ans = mint(2).pow(N-3);
                return;
            }
        }
    }
    if(CAB=='B'){
        if(CBB=='B') return;
        if(CBB=='A'){
            if(CBA=='B'){
                ans = dp();
                return;
            }
            if(CBA=='A'){
                ans = mint(2).pow(N-3);
                return;
            }
        }
    }
}

int main(){
    cin >> N;
    cin >> CAA >> CAB >> CBA >> CBB;

    solve();

    cout << ans.x << endl;
    return 0;
}

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

const int64_t MOD = 1e9 + 7;
const int64_t MOD2 = 998244353;
const int INF = 2e9;
const long long inf = 1LL<<62;

template<int MOD> struct ModInt {
    static const int Mod = MOD; unsigned x; ModInt() : x(0) { }
    ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    int get() const { return (int)x; }
    ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
    ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
    ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
    ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
    ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
    ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
    ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0;
        while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); }
        return ModInt(u); }
    bool operator==(ModInt that) const { return x == that.x; }
    bool operator!=(ModInt that) const { return x != that.x; }
    ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
template<int MOD> ostream& operator<<(ostream& st, const ModInt<MOD> a) { st << a.get(); return st; };
template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
    ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; }
typedef ModInt<998244353> mint;

int64_t po(int64_t a, int64_t b) {
  int64_t ans = 1;
  while (b > 0) {
    if (b%2) {
      ans = (ans*a)%MOD2;
    }
    a = a*a%MOD2;
    b /= 2;
  }
  return ans;
}

int main() {
  int n, m;
  cin >> n >> m;
  mint ans = (mint(m)^n)*(mint(n));
  for (int l=2; l<=n; l++) {
    for (int x = 1; x<=m; x++) {
      ans -= (mint(m-x)^(l-2))*(mint(m)^(n-l))*mint(n-l+1);
    }
  }
  cout << ans << endl;
}


#include<iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	cout<<n-1;
	return 0;
 }


//12252024832524
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

typedef long long LL;
const int MAXN = 100005;
const int MOD = 1e9 + 7;
int n;

int Read()
{
	int x = 0,f = 1;char c = getchar();
	while(c > '9' || c < '0'){if(c == '-')f = -1;c = getchar();}
	while(c >= '0' && c <= '9'){x = (x*10) + (c^48);c = getchar();}
	return x * f;
}
void Put1(int x)
{
	if(x > 9) Put1(x/10);
	putchar(x%10^48);
}
void Put(int x,char c = -1)
{
	if(x < 0) putchar('-'),x = -x;
	Put1(x);
	if(c >= 0) putchar(c);
}
template <typename T>T Max(T x,T y){return x > y ? x : y;}
template <typename T>T Min(T x,T y){return x < y ? x : y;}
template <typename T>T Abs(T x){return x < 0 ? -x : x;}

int qpow(int x,int y)
{
	int ret = 1;
	while(y){if(y & 1) ret = 1ll * ret * x % MOD;x = 1ll * x * x % MOD;y >>= 1;}
	return ret;
}
char gc()
{
	char c = getchar();
	while(c != 'A' && c != 'B') c = getchar();
	return c;
}
int f[MAXN];
int getf(int x)
{
	f[1] = 2;f[2] = 3;
	for(int i = 3;i <= x;++ i) f[i] = (f[i-1] + f[i-2]) % MOD;
	return f[x];
}

int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	n = Read();
	if(n <= 3) {Put(1);return 0;}
	char aa = gc(),ab = gc(),ba = gc(),bb = gc();
	if(ab == 'B')
	{
		if(bb == 'B') Put(1);
		else
		{
			if(ba == 'A') Put(qpow(2,n-3));
			else Put(getf(n-3));
		}
	}
	else
	{
		if(aa == 'A') Put(1);
		else
		{
			if(ab == 'B' || ba == 'B') Put(qpow(2,n-3));
			else Put(getf(n-3));
		}
	}
	return 0;
}

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

using namespace std;

#define endl '\n'
#define all(v) v.begin(), v.end()
#define front(v) *v.begin()
#define back(v) *(--v.end())
#define len(v) v.size()
#define int long long

using longl = long long;
using longd = long double;

const longl INF = 1e9;
const longl LINF = 1e18;
const longl mod = 1e9 + 7;
const double PI = acos(-1);
//------------------------------------------------------------------------------------------------

longl divup(longl a, longl b){
    return (a + b - 1) / b;
}

longl bin_pow(longl a, longl b){
    longl res = 1;

    while (b > 0){
        if (b % 2)
            res = res * a % mod;

        a = a * a % mod;
        b /= 2;
    }
    return res;
}

//------------------------------------------------------------------------------------------------
int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int n;
    cin >> n;

    vector<int> v(n);

    for (int i = 0; i < n; i++){
        cin >> v[i];
    }

    sort(all(v));
    v.resize(unique(all(v)) - v.begin());
    reverse(all(v));

    int ans = 1;

    for (int i = 1; i < v.size(); i++){
        ans = (ans * (v[i - 1] - v[i] + 1)) % mod;
    }
    ans = ans * (v[v.size() - 1] + 1) % mod;
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

typedef vector<int> vi;
typedef vector<ll> vll;

typedef vector<vi> vvi;
typedef vector<vll> vvll;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef vector<pii> vpii;
typedef vector<pll> vpll;

typedef vector<vpii> vvpii;
typedef vector<vpll> vvpll;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define fi first
#define se second

template<class T> bool ckmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<class T> bool ckmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}

void __print(int x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for(auto z : x) cerr << (f++ ? "," : ""), __print(z); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if(sizeof...(v)) cerr << ", "; _print(v...);}

#ifdef ljuba
#define dbg(x...) cerr << "LINE(" << __LINE__ << ") -> " << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif

const char nl = '\n';

const int mxN = 3e5 + 12;
ll ft[mxN];

void update(int i, ll x) {
    for(; i < mxN; i += i&-i) {
        ft[i] += x;
    }
}

ll query(int i) {
    ll r = 0;
    for(; i; i -= i&-i) {
        r += ft[i];
    }
    return r;
}

void solve() {
    int n;
    cin >> n;
    vll v(n);
    for(auto &z : v) {
        cin >> z;
        ++z;
    }

    ll ans = 0;
    for(int i = 0; i < n; ++i) {
        ans += query(n) - query(v[i]-1);
        update(v[i], 1);
    }

    cout << ans << nl;

    for(int i = 0; i < n-1; ++i) {
        ans -= v[i]-1;
        ans += (n-v[i]);
        cout << ans << nl;
    }
}

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

    int testCases = 1;
    //cin >> testCases;
    while(testCases--)
        solve();

}

#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include<cstdio>
#include<functional>
#include <bitset>
#include <iomanip>
#include <cctype>
#include <list>
#include <cassert>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define ll long long
#define repi(i,a,b) for(ll i=a;i<b;++i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

using namespace std;
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
using vvv = vector<vector<vector<ll>>>;
using vv = vector<vector<ll>>;
using vec = vector<ll>;
using P = pair<ll, ll>;

int ceil_pow2(int n) {
	int x = 0;
	while ((1U << x) < (unsigned int)(n)) x++;
	return x;
}

template <class S, S(*op)(S, S), S(*e)()> struct segtree {
public:
	segtree() : segtree(0) {}
	segtree(int n) : segtree(std::vector<S>(n, e())) {}
	segtree(const std::vector<S>& v) : _n(int(v.size())) {
		log = ceil_pow2(_n);
		size = 1 << log;
		d = std::vector<S>(2 * size, e());
		for (int i = 0; i < _n; i++) d[size + i] = v[i];
		for (int i = size - 1; i >= 1; i--) {
			update(i);
		}
	}

	void set(int p, S x) {
		assert(0 <= p && p < _n);
		p += size;
		d[p] = x;
		for (int i = 1; i <= log; i++) update(p >> i);
	}

	S get(int p) {
		assert(0 <= p && p < _n);
		return d[p + size];
	}

	S prod(int l, int r) {
		assert(0 <= l && l <= r && r <= _n);
		S sml = e(), smr = e();
		l += size;
		r += size;

		while (l < r) {
			if (l & 1) sml = op(sml, d[l++]);
			if (r & 1) smr = op(d[--r], smr);
			l >>= 1;
			r >>= 1;
		}
		return op(sml, smr);
	}

	S all_prod() { return d[1]; }

	template <bool(*f)(S)> int max_right(int l) {
		return max_right(l, [](S x) { return f(x); });
	}
	template <class F> int max_right(int l, F f) {
		assert(0 <= l && l <= _n);
		assert(f(e()));
		if (l == _n) return _n;
		l += size;
		S sm = e();
		do {
			while (l % 2 == 0) l >>= 1;
			if (!f(op(sm, d[l]))) {
				while (l < size) {
					l = (2 * l);
					if (f(op(sm, d[l]))) {
						sm = op(sm, d[l]);
						l++;
					}
				}
				return l - size;
			}
			sm = op(sm, d[l]);
			l++;
		} while ((l & -l) != l);
		return _n;
	}

	template <bool(*f)(S)> int min_left(int r) {
		return min_left(r, [](S x) { return f(x); });
	}
	template <class F> int min_left(int r, F f) {
		assert(0 <= r && r <= _n);
		assert(f(e()));
		if (r == 0) return 0;
		r += size;
		S sm = e();
		do {
			r--;
			while (r > 1 && (r % 2)) r >>= 1;
			if (!f(op(d[r], sm))) {
				while (r < size) {
					r = (2 * r + 1);
					if (f(op(d[r], sm))) {
						sm = op(d[r], sm);
						r--;
					}
				}
				return r + 1 - size;
			}
			sm = op(d[r], sm);
		} while ((r & -r) != r);
		return 0;
	}

private:
	int _n, size, log;
	std::vector<S> d;

	void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); }
};

ll op(ll a, ll b) {
	return a + b;
}

ll e() {
	return 0;
}

int main(void) {
	ll n; cin >> n;
	vec al(n);
	rep(i, n) cin >> al[i];
	auto sg = new segtree<ll, op, e>(n);
	ll ans = 0;
	rep(i, n) {
		ans += sg->prod(al[i], n);
		sg->set(al[i], 1);
	}
	rep(i, n) {
		cout << ans << endl;
		ans -= al[i];
		ans += n - 1 - al[i];
	}
	system("pause");
}


#include "bits/stdc++.h"
//#include "atcoder/all"
using namespace std;
//using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N, M;
	cin >> N >> M;
	vector<int>A(M);
	vector<int>B(M);
	rep(i, M) {
		cin >> A[i] >> B[i];
		A[i]--;
		B[i]--;
	}
	int K;
	cin >> K;
	vector<int>C(K);
	vector<int>D(K);
	rep(i, K) {
		cin >> C[i] >> D[i];
		C[i]--;
		D[i]--;
	}
	int ans = 0;
	rep(i, (1 << K)) {
		vector < bool >Tama(N);
		rep(j, K) {
			if (1&(i >> j)) {
				Tama[C[j]] = true;
			}
			else {
				Tama[D[j]] = true;
			}
		}
		int anssub = 0;
		//rep(j, N) {
		//	cout << Tama[j] << "_";
		//}
		//cout << endl;
		rep(j, M) {
			if ((Tama[A[j]]) && (Tama[B[j]])) {
				anssub++;
			}
		}
		ans = max(ans, anssub);
	}
	cout << ans << endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    string a,b;
    cin >> a >> b;
    ll as = 0;
    ll bs = 0;
    for(int i = 0;i < (int)a.size();i++)as += a[i] - '0';
    for(int i  =0;i < (int)b.size();i++)bs += b[i] - '0';
    cout << max(as,bs) << endl;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

string rev(string s) {
  REP(i, s.size()) {
    s[i] = 'A'+(1-(s[i]-'A'));
  }
  return s;
}
int main2() {
  int N = nextLong();
  int M = 1 << N;

  vector<string> ans;
  ans.push_back("AB");

  for (int m = 1; m <= N-1; m++) {
    vector<string> n_ans;
    n_ans.push_back(string(1<<m, 'A') + string(1<<m, 'B'));
    for (string s : ans) {
      n_ans.push_back(s + s);
    }
    for (string s : ans) {
      n_ans.push_back(s + rev(s));
    }
    ans = n_ans;
  }

  cout << (M - 1) << endl;
  for (string s : ans)
    cout << s << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

#include "bits/stdc++.h"
using namespace std;
using ll = long long;
int n;
vector<ll> with[3];
int cnt[3];

int getID(char c) {
    switch (c) {
        case 'R': return 0;
        case 'G': return 1;
        case 'B': return 2;
    }
    return -1;
}

signed main() {
    cin >> n;
    for (int i = 0; i < n * 2; i++) {
        ll a;
        char c;
        cin >> a >> c;
        int id = getID(c);
        with[id].push_back(a);
        cnt[id]++;
    }
    bool allEven = all_of(cnt, cnt + 3, [](int elem)->bool {
        return elem % 2 == 0;
    });
    if (allEven) {
        return cout << 0 << endl, 0;
    }
    if (cnt[0] % 2 == 0) {
        swap(cnt[2], cnt[0]);
        swap(with[2], with[0]);
    }
    else if (cnt[1] % 2 == 0) {
        swap(cnt[2], cnt[1]);
        swap(with[2], with[1]);
    }
    assert(cnt[2] % 2 == 0);
    ll pos1 = 1e18;//posibilities
    ll pos2[2] = {pos1, pos1};
    vector<pair<ll, int>> only01;
    for (int i = 0; i < 2; i++) {
        for (ll c : with[i]) {
            only01.emplace_back(c, i);
        }
    }
    sort(only01.begin(), only01.end());
    for (int i = 1; i < (int)only01.size(); i++) {
        auto [preFi, preSe] = only01[i - 1];
        auto [currFi, currSe] = only01[i];
        if (currSe != preSe) {
            pos1 = min(pos1, currFi - preFi);
        }
    }
    vector<pair<ll, int>> all;
    for (int i = 0; i < 3; i++) {
        for (ll c : with[i]) {
            all.emplace_back(c, i);
        }
    }
    sort(all.begin(), all.end());
    for (int i = 1; i < n * 2; i++) {
        auto [preFi, preSe] = all[i - 1];
        auto [currFi, currSe] = all[i];
        if (preSe == 0 && currSe == 2 || preSe == 2 && currSe == 0) {
            pos2[0] = min(pos2[0], currFi - preFi);
        }
        else if (preSe == 1 && currSe == 2 || preSe == 2 && currSe == 1) {
            pos2[1] = min(pos2[1], currFi - preFi);
        }
    }
    cout << min(pos2[0] + pos2[1], pos1) << endl;
    return 0;
}


#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast")
/*#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
/*#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma")*/
using namespace std;
using ll = long long int;
using ld = long double;
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define lc v<<1
#define rc v<<1|1
#define fast_io ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
const int N=5e5+10,LN=18,M=1.1e7+10,SQ=350,BS=737,inf=1e9+10;
const ll INF=1e15;
const int MH=1000696969,MOD=1000000007 /*998244353*/;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using pll=pair<ll,ll>;
using pii=pair<int,int>;
#define ordered_set tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>
ll pow(ll x, ll y, ll mod){
    ll ans=1;
    while (y != 0) {
        if (y & 1) ans = ans * x % mod;
        y >>= 1;
        x = x * x % mod;
    }
    return ans;
}
ll n,cnt[3],ls[3],mn[3],ans;
pll a[N];
int main(){
    fast_io;
    cin >> n;
    n*=2;
    mn[0]=mn[1]=mn[2]=INF;
    for(ll i=1; i<=n; i++){
        cin >> a[i].F;
        char C;
        cin >> C;
        if(C=='G') a[i].S=1;
        if(C=='B') a[i].S=2;
        cnt[a[i].S]++;
    }
    sort(a+1,a+n+1);
    for(ll i=1; i<=n; i++){
        ls[a[i].S]=i;
        for(ll j=0; j<3; j++){
            if(j!=a[i].S && ls[j]){
                ll k=3-a[i].S-j;
                mn[k]=min(mn[k],a[i].F-a[ls[j]].F);
            }
        }
    }
    if(cnt[0]%2==1 && cnt[1]%2==1) ans=min(mn[2],mn[1]+mn[0]);
    if(cnt[0]%2==1 && cnt[2]%2==1) ans=min(mn[1],mn[2]+mn[0]);
    if(cnt[2]%2==1 && cnt[1]%2==1) ans=min(mn[0],mn[1]+mn[2]);
    cout << ans << '\n';
    return 0;
}

/*Be patient && calm!
All our dreams can come true, if we have the courage to pursue them.
I fear not the man who has practiced 10,000 kicks once, but I fear the man who has practiced one kick 10,000 times.
Do not pray for an easy life, pray for the strength to endure a difficult one.
When something is important enough, you do it even if the odds are not in your favor.
First, solve the problem. Then, write the code.
Fix the cause, not the symptom.
Simplicity is the soul of efficiency.
Make it work, make it right, make it fast.
No matter how hard it gets, NEVER GIVE UP*/
// set<int>::iterator it;
// set<int>::reverse_iterator it;
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define Max 10000000000000000
int fact(int n)
{
    int res = 1;
    for (int i = 2; i <= n; i++)
        res = res * i;
    return res;
}
ll f1(vector<ll> &v1,vector<ll> &v2){
	int sz=v1.size();
	ll ans=1e18;
	for(int i=0;i<sz;i++){
		auto ind=lower_bound(v2.begin(),v2.end(),v1[i])-v2.begin();
		if(ind<(int)v2.size()&&abs(v2[ind]-v1[i])<ans)
			ans=abs(v2[ind]-v1[i]);
		if(ind>0&&abs(v2[ind-1]-v1[i])<ans)
			ans=abs(v2[ind-1]-v1[i]);
	}
	return ans;
}

ll f(vector<ll> v1,vector<ll> v2,vector<ll> v3){
	return min(f1(v2,v3),f1(v1,v2)+f1(v1,v3));
}
void solve(){
	int n;
	cin>>n;
	vector<ll> v[3];
	for(int i=0;i<2*n;i++){
		ll a;
		cin>>a;
		char c;
		cin>>c;
		if(c=='R')
			v[0].push_back(a);
		if(c=='G')
			v[1].push_back(a);
		if(c=='B')
			v[2].push_back(a);
	}
	sort(v[0].begin(),v[0].end());
	sort(v[1].begin(),v[1].end());
	sort(v[2].begin(),v[2].end());
	int l0=v[0].size(),l1=v[1].size(),l2=v[2].size();
	if(l1%2==0&&l2%2==0&&l0%2==0){
		cout<<"0\n";
		return;
	}
	if(l0%2==0){
		cout<<f(v[0],v[1],v[2]);
	}
	else if(l1%2==0){
		cout<<f(v[1],v[0],v[2]);
	}
	else if(l2%2==0){
		cout<<f(v[2],v[0],v[1]);
	}
}
int main(){
// 	ios::sync_with_stdio(false);
// 	cout.tie(0);
// 	cin.tie(NULL);
	int t;
	// cin>>t;
	t=1;
    while(t--) {
    	// int n;
    	// cin>>n;
    	solve();
	}
}


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

int main()
{
    ll n;
    cin >> n;
    vector<ll> x(n);
    rep(i,n) cin >> x[i];
    vector<ll> ps = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47};
    ll ans = LONG_LONG_MAX;
    for(int i = 0; i < 1 << ps.size(); i++){
        bitset<20> bs(i);
        bool ok = true;
        rep(j,n){
            bool sub = false;
            rep(k,(int)ps.size()){
                if(bs[k]){
                    if(x[j] % ps[k] == 0) {
                        sub = true;
                        break;
                    }
                }
            }
            if(sub==false) ok = false;
            if(!ok) break;
        }
        if(ok){
            ll sum = 1;
            rep(k,(int)ps.size()){
                if(bs[k]){
                    sum *= ps[k];
                }
            }
            ans = min(ans, sum);
        }
    }
    cout << ans << endl;

    return 0;
}

# include <bits/stdc++.h>
# define sz(x) (int)x.size()
# define f first
# define s second

using namespace std;
using ll = long long;

int cnt[55], a[55], n;
ll ans;
set<int> f[55];

void calc(int in) {
  int x = a[in];
  for (int i = 2; i <= x; ++i) {
    while (x % i == 0) {
      x /= i;
      //cout << "HERE";
      f[in].insert(i);
    }
  }
  for (auto i : f[in]) cnt[i]++;
}

void solve() {
  cin >> n;
  ans = 1;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    calc(i);
  }
  vector<int> used(55);
  // for (int i = 0; i < 55; ++i) cout << cnt[i] << ' ';
  // cout << '\n';
  for (int i = 0; i < n; ++i) {
    bool ok = 0;
    for (auto j : f[i]) {
      if (ans % j == 0) ok = 1;
    }
    if (ok) {
      for (auto j : f[i]) cnt[j]--;
      continue;
    }
    int res = 0, x = 1;
    for (auto j : f[i]) {
      if (cnt[j] > res) {
        res = cnt[j];
        x = j;
      }
    }
    ans *= x;
    for (auto j : f[i]) cnt[j]--;
  }
  cout << ans;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  //int t; cin >> t; while (t--)
  solve();
}


//#define _GLIBCXX_DEBUG
//#include <atcoder/all>
#include <bits/stdc++.h>
#include <chrono>
#include <random>

using namespace std;
//using namespace atcoder;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
//const ll MOD=1000000007;
const ll MOD=998244353;
//using mint = modint998244353;
//using mint = modint1000000007;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);
int dx[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
int dy[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; }

//https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a

ll mod_pow(long long x, long long n) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * x % MOD;  // n の最下位bitが 1 ならば x^(2^i) をかける
        x = x * x % MOD;
        n >>= 1;  // n を1bit 左にずらす
    }
    return ret;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // cout << fixed << setprecision(15);

  ll N,K; cin>>N>>K;
  vector<ll> A(N); rep(i,N) cin>>A[i];

  vector<vector<ll>> pascal(1,{1});
  for(int i=1;i<=K;i++){
    vector<ll> vec={};
    rep(j,i+1){
      if(j==0||j==i) {vec.push_back(1); continue;}
      vec.push_back((pascal[i-1][j-1]+pascal[i-1][j])%MOD);
    }
    pascal.push_back(vec);
  }
  /*
  for(auto v:pascal){
    rep(i,v.size()){
      if(i!=0) cout<<' ';
      cout<<v[i];
    }
    cout<<'\n';
  }
  */
  vector<ll> run(K+1,0);
  rep(i,N){
    ll a=1;
    rep(_,K+1){
      run[_]=(run[_]+a)%MOD;
      a=a*A[i]%MOD;
    }
  }
  for(int X=1;X<=K;X++){
    auto l=pascal[X];
    ll ans=0;
    rep(i,X+1){
      ll sans=0;
      ll AA=run[X-i];
      ll B=run[i];
      ll C=run[X];
      sans=l[i]*(AA*B%MOD-C)%MOD;
      if(X%2==0&&i==X/2) sans=sans*mod_pow(2,MOD-2)%MOD;
      if(i>X/2) break;
      if(sans<0) sans+=MOD;
      ans=(ans+sans)%MOD;
    }
    cout<<ans<<'\n';
  }
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T,class U>
inline bool chmax(T &a,U b){
    if(a<b){
        a=b;
        return true;
    }
    return false;
}
template<class T,class U>
inline bool chmin(T &a,U b){
    if(a>b){
        a=b;
        return true;
    }
    return false;
}
constexpr int INF=1000000000;
constexpr ll llINF=3000000000000000000;
constexpr int mod=998244353;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
/*
vector<vector<ll>>C,sC;
void init_comb(int n,int m){
    C.resize(n+1,vector<ll>(m+1,0));
    sC.resize(n+1,vector<ll>(m+1,0));
    C[0][0]=1;
    for(int i=1;i<=n;i++){
        C[i][0]=1;
        for(int j=1;j<=m;j++){
            C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
        }
    }
    rep(i,n+1){
        rep(j,m){
            sC[i][j+1]=(sC[i][j]+C[i][j])%mod;
        }
    }
}*/
ll gcd(ll a,ll b){
    while(a%b){
        a%=b;
        swap(a,b);
    }
    return b;
}
ll lcm(ll a,ll b){
    return a/gcd(a,b)*b;
}
bool isprime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
vector<int>primes;
void init_prime(int n){
	primes.push_back(2);
    for(int i=3;i<=n;i+=2){
        bool f=true;
        for(int j:primes){
            if(j*j>i)break;
            if(i%j==0){
                f=false;
                break;
            }
        }
        if(f)primes.push_back(i);
    }
}
ll modpow(ll a,ll b){
    ll res=1;
    while(b){
        if(b&1){
            res*=a;
            res%=mod;
        }
        a*=a;
        a%=mod;
        b>>=1;
    }
    return res;
}
vector<ll>inv,fact,factinv;
void init_fact(int n){
    inv.resize(n+1);
    fact.resize(n+1);
    factinv.resize(n+1);
    inv[0]=0;
    inv[1]=1;
    fact[0]=1;
    factinv[0]=1;
    for(ll i=1;i<=n;i++){
        if(i>=2)inv[i]=mod-((mod/i)*inv[mod%i]%mod);
        fact[i]=(fact[i-1]*i)%mod;
        factinv[i]=factinv[i-1]*inv[i]%mod;
    }
}
ll _inv(ll a,ll m=mod){
    //gcd(a,m) must be 1
    ll b=m,u=1,v=0;
    while(b){
        ll t=a/b;
        a-=t*b;swap(a,b);
        u-=t*v;swap(u,v);
    }
    u%=m;
    if(u<0)u+=m;
    return u;
}
ll comb(int a,int b){
    if(a<b)return 0;
    if(a<0)return 0;
    return fact[a]*factinv[a-b]%mod*factinv[b]%mod;
}
ll multicomb(int a,int b){
    return comb(a+b-1,b);
}
int n,k,dp[200010],res,dmax;
vector<int>g[200010];
void dfs(int x,int p){
    dp[x]=0;
    for(int i:g[x]){
        if(i!=p){
            dfs(i,x);
            if(dp[i]+1>dmax)res++;
            else if(dp[i]+1+dp[x]<=dmax)chmax(dp[x],dp[i]+1);
            else{
                res++;
                chmin(dp[x],dp[i]+1);
            }
        }
    }
}
bool check(int x){
    res=0,dmax=x*2;
    dfs(0,-1);
    return res<k;
}
void solve(){
    cin>>n>>k;
    rep(i,n-1){
        int a,b;
        cin>>a>>b;
        a--,b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    int ok=n,ng=0;
    while(ok-ng>1){
        int m=(ok+ng)>>1;
        if(check(m))ok=m;
        else ng=m;
    }
    cout<<ok<<endl;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    //int t;cin>>t;while(t--)
    solve();
    return 0;
}


#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using pint = pair<int,int>;

// __int128の入出力

using LL = __int128;
istream& operator>>(istream& is, LL& v)
{
    string s;
    is >> s;
    v = 0;
    for (int i = 0; i < (int)s.size(); i++) {
        if (isdigit(s[i])) { v = v * 10 + s[i] - '0'; }
    }
    if (s[0] == '-') { v *= -1; }
    return is;
}

ostream& operator<<(ostream& os, const LL& v)
{
    if (v == 0) { return (os << "0"); }
    LL num = v;
    if (v < 0) {
        os << '-';
        num = -num;
    }
    string s;
    for (; num > 0; num /= 10) { s.push_back((char)(num % 10) + '0'); }
    reverse(s.begin(), s.end());
    return (os << s);
}
using Int = __int128_t;

int main()
{
    ll N; cin >> N;
    ll ans = 1e18;
    for(int b = 0; b <= 62; b++) {
        ll num = (1LL<<b);
        if(num > N)continue;
        ll a = N / num;
        ll c = N % num;
        ans = min(ans, a + b + c);
    }
    cout << ans << endl;
}

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

int main() {
  long long int A,count=0,B,C,D,E;
  long long int ans[1000]={0};
  cin >> A;
  B=A;
  C=1;
  while(1){
    D=A/C;
    E=A%C;
    ans[count]=count+D+E;
    if(B<2)break;
    B=B/2;
    C=C*2;
    count++;
 }
  long long int min=ans[0];
  for(int i=1;i<count;i++){
    if(min>ans[i])min=ans[i];
  }
  cout<<min;
}


#include <bits/stdc++.h>

using namespace std;

#define int long long

int n, k;

int dp [105][105]; // pos, 2^x players
int win [105];

int pows [105];
int winz (int a, int b){
    if (a==b) return a;
    if (a>b) swap(a, b);
    if(a==0 && b==1) return 1;
    if(a==0 && b==2) return 0;
    if(a==1 && b==2) return 2;
}
main(){
    ios_base::sync_with_stdio(0);

    pows[0]=1;
    cin >> n >> k;

    for (int i=1;i<105; i++) pows[i] = (2*pows[i-1])%n;

    string s; cin >> s;//leng n

    for (int i=0; i<n; i++){
        if (s[i] == 'R') win[i]=0;
        else if (s[i] == 'P') win[i]=1;
        else win[i]=2;
    }

    for (int i=0; i<n; i++) dp[i][0] = win[i];

    for (int i=1; i<=100; i++){
        for (int j=0; j<n; j++){
            int fi = dp[j][i-1];
            int si = (j + pows[i-1]) % n;

            si = dp[si][i-1];

            dp[j][i] = winz(fi, si);
        }
    }
    if (dp[0][k]==0)cout<<'R';
    else if (dp[0][k]==1) cout << 'P';
    else cout << 'S';

    return 0;
}

#include <bits/stdc++.h>
//#include <atcoder/all>
#define int long long
#define rep(i,a) for (int i = 0; i < (a); i++ )
#define Rep(i,start,a) for (int i = start; i < (a); i++ )
#define ALL(vec) (vec).begin(), (vec).end()
#define Sort(vec) sort((vec).begin(), (vec).end()) // 小さい順
#define SORT(vec) sort((vec).begin(), (vec).end(), [](int a, int b){return a>b;}) // 大きい順
#define SORTll(vec) sort((vec).begin(), (vec).end(), [](long long a, long long b){return a>b;}) // 大きい順
#define debug(x) cerr << #x << " = " << (x) << endl
#define VI vector<int>
#define VLL vector<long long>
#define PII pair<int,int>
#define VPII vector<PII>
#define VB vector<bool>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define Graph vector<vector<int>>
#define PB emplace_back
#define USI unordered_set<int>
#define Maze vector<string>
#define Pqueue priority_queue
#define MP make_pair
#define WeightedGraph vector<vector<pair<int,ll>>> // parent, (to, cost)
#define mat vector<vector<long long>>

#define vecdebug(vec) {cerr << #vec << " = [" ; for(auto x : (vec)){cerr << (x) << ", ";} cerr << "]" << endl; }
#define vdebug(vec,i) cerr << #vec << "[" << (i) << "] = " << (vec)[(i)] << endl
#define vvdebug(vec,i,j) cerr << #vec << "[" << (i) << "][" << (j) << "] = " << (vec)[(i)][(j)] << endl
#define vvvdebug(vec,i,j,k) cerr << #vec << "[" << (i) << "][" << (j) << "][" << (k) <<"] = " << (vec)[(i)][(j)][(k)] << endl
#define pdebug(p) cerr << #p << " = [" << (p).first << ", " << (p).second << "]" << endl

typedef long long ll;
typedef long double ld;

const ll mod = 998244353;
const ll MOD = 1000000007;
const ll INFLL = (1LL << 62) -1;
const int INF = (1 << 30) -1;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const long double pi = 2*asin(1);
// cout << fixed << setprecision(16);

using namespace std;
//using namespace atcoder;

//using mint = modint1000000007;
//using mint = modint998244353;
//using mint = modint998244353;
//using mint = static_modint<7>;

inline void chmin(ll &x, ll y){
  if(x>y) x=y;
}

inline void chmax(ll &x, ll y){
  if(x<y) x=y;
}

inline int tonum(char X){
  return (int)(X-'a');
}

inline int ctoi(char x){
  return (int)(x-'0');
}

int Max(int x, int y){
  if(x>y) return x;
  return y;
}

int Min(int x, int y){
  if(x<y) return x;
  return y;
}

inline int tochar(int n){
  return (char)('a' + n);
}

inline int ABS(int n){
  if(n<0) return -n;
  return n;
}

int n,k;
string S;
VI twomod(200);

void init(){
  cin >> n >> k;
  cin >> S;
  twomod[0] = 1 % n;
  rep(j,190) twomod[j+1] = (2 * twomod[j]) % n;
}

char winhand(char h1, char h2){
  if(h1 == h2) return h1;
  if(h1 == 'R' && h2 == 'S') return 'R';
  if(h1 == 'R' && h2 == 'P') return 'P';
  if(h1 == 'P' && h2 == 'R') return 'P';
  if(h1 == 'P' && h2 == 'S') return 'S';
  if(h1 == 'S' && h2 == 'R') return 'R';
  if(h1 == 'S' && h2 == 'P') return 'S';
  return '?';
}

void solve(){
  init();
  vector<vector<char>> win(n, vector<char>(110));
  rep(i,n) win[i][0] = S[i];
  rep(j,105) rep(i,n){
    win[i][j+1] = winhand(win[i][j], win[ (twomod[j] + i) %n ][j]);
  }
  cout << win[0][k] << endl;
}

signed main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(16);

  solve();
}