//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("O2")
//#pragma GCC optimize("O3")
////#pragma GCC optimize("unroll-loops")
////
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#include <bits/stdc++.h>

#define all(x) (x).begin(), (x).end()
#define allp(x) (x)->begin(), (x)->end()

#define pb push_back

using namespace std;
void dout() { cerr << endl; }
//typedef long long ll;
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

using ll = long long;
//#ifdef __int128
//using hll = __int128;
//#endif
using pii = pair<ll, ll>;
using ld = long double;
using pll = pair<long long, long long>;

template <typename T>
void do_uniq(vector<T> &vec){
    sort(all(vec));
    vec.resize(unique(all(vec)) - vec.begin());
}

#ifndef ONLINE_JUDGE

clock_t timestamp_start = clock();
void time_calc()
{
    cerr << (ld)(clock() - timestamp_start) / CLOCKS_PER_SEC << "\n";
}
#endif

#ifdef _getchar_nolock
#else
#define _getchar_nolock getchar_unlocked
#endif

#define integer int

integer mod = 1e9 + 7;

integer ml(integer a, integer b) {
    return (a * 1ll * b) % mod;
}

integer add(integer a, integer b) {
    return (a + b) % mod;
}

integer sub(integer a, integer b) {
    return add(a, mod - b);
}

integer sq(integer a) {
    return ml(a, a);
}

integer b_p(integer b, integer p) {
    if (p == 0) return 1;
    if (p & 1) return ml(b, b_p(b, p - 1));
    return sq(b_p(b, p >> 1));
}

#define solvsh
//#define multi

#ifdef solvsh

const int MAXN = 2e5 + 31;

void precalc() {
}

struct edge {
    int from;
    int to;
    int ci;

    int other(int i) {
        return i == from ? to : from;
    }

};

edge edgs[MAXN];

vector<int> g[MAXN];
set<int> forb[MAXN];

int assgn[MAXN];
bool usd[MAXN];

void dfs(int ver, int l =- 1) {
    if (usd[ver]) return;;
    usd[ver] = true;

    if (l == -1) {
        l = 1;
        while (forb[ver].count(l)) ++l;
    }

    assgn[ver] = l;
    for (auto e : g[ver]) {
        forb[edgs[e].other(ver)].insert(l);
    }

    for (auto e : g[ver]) {
        int to = edgs[e].other(ver);
        if (assgn[ver] == edgs[e].ci) dfs(to, -1);
        else dfs(to, edgs[e].ci);
    }
}

void solve() {

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

    int last = 0;

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

        int f, t, c;
        cin >> f >> t >> c;
        --f;
        --t;
        edgs[last] = {f, t, c};
        g[f].push_back(last);
        g[t].push_back(last);
        ++last;
    }

    dfs(0);

    for (int i = 0; i < n; ++i) {
        if (!usd[i]) {
            cout << "No\n";
            return;
        }
    }

    for (int i = 0; i < n; ++i) {
        cout << assgn[i] << "\n";
    }
}

#else
#endif

void multisolve() {
    precalc();
    int t;

    cin >> t;

    int i = 1;
    while (t--) {
        solve();
        i++;
    }
}

#ifndef ONLINE_JUDGE

void gen() {

    int n = 2000;
    cout << n << "\n";
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            cout << (i != j ? 1 : 0) << " ";
        }
        cout << "\n";
    }
}

#endif

#define int int
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    cout << fixed << setprecision(20);

#ifdef multi
    //            gen();
        multisolve();
#else

    solve();
//    gen();
#endif
    // time_calc();
}

#include<bits/stdc++.h>
using namespace std;
#define N 100005
struct ji{
	int nex,to,len;
}edge[N<<2];
int E,n,m,x,y,z,head[N],vis[N],pd[N],ans[N];
void add(int x,int y,int z){
	edge[E].nex=head[x];
	edge[E].to=y;
	edge[E].len=z;
	head[x]=E++;
}
void dfs(int k){
	vis[k]=1;
	for(int i=head[k];i!=-1;i=edge[i].nex)
		if (!vis[edge[i].to]){
			if (edge[i].len==ans[k])ans[edge[i].to]=n+1;
			else ans[edge[i].to]=edge[i].len;
			dfs(edge[i].to);
		}
}
int main(){
	scanf("%d%d",&n,&m);
	memset(head,-1,sizeof(head));
	for(int i=1;i<=m;i++){
		scanf("%d%d%d",&x,&y,&z);
		add(x,y,z);
		add(y,x,z);
	}
	dfs(1);
	for(int i=1;i<=n;i++)
		if (!vis[i]){
			printf("No");
			return 0;
		}
	ans[1]=n+1;
	for(int i=1;i<=n;i++)
		if (ans[i]>n){
			for(int j=head[i];j!=-1;j=edge[j].nex)pd[ans[edge[j].to]]=1;
			ans[i]=1;
			while (pd[ans[i]])ans[i]++;
			for(int j=head[i];j!=-1;j=edge[j].nex)pd[ans[edge[j].to]]=0;
		}
	for(int i=1;i<=n;i++)printf("%d\n",ans[i]);
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define F first
#define S second
#define Tsetso ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pr pair < int , int >
const int N = 2e5+10,NN = 1005, length = 25 , mod = 1e9+7, inf = 1e9;
vector < int > g[N];
int color[N] , ans, n;
multiset< pair < int , int  > > *mst[N];
void dfs ( int node , int par )
{
    int mx = -1 ;
    for ( auto i : g[node])
    {
        if ( i == par)
            continue;
        dfs(i,node);
        if ( mx == -1)
                mx = i ;
        else if ( mst[i]->size() > mst[mx]->size())
            mx = i;
    }
    if ( mx == -1)
    {
        mst[node] = new multiset< pair < int , int > > ;
        mst[node]->insert({color[node],node});
        return ;
    }
    for ( auto i : g[node])
    {
        if ( i == par || i == mx)
            continue;
        for ( auto j : *mst[i])
                mst[mx]->insert(j);
    }
    auto it = mst[mx]->lower_bound({color[node],-1});
    while (it != mst[mx]->end() && it->first == color[node])
    {
        mst[mx]->erase(it);
        it =  mst[mx]->lower_bound({color[node],-1});
    }
    mst[node] = mst[mx];
    mst[node]->insert({color[node],node});
}
int main() {
    Tsetso
    cin >> n ;
    ans = n;
    for ( int i = 1 ; i <= n; i++)
        cin >> color[i];
    for ( int i = 1 ; i < n ; i++)
    {
        int u , v ;
        cin >> u >> v ;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs(1,0);
    set < int > s ;
    for ( auto j : *mst[1])
            s.insert(j.second);
    for ( auto j : s)
            cout << j << '\n';
}

//================code===================//

//#define TLE

#ifdef TLE
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#endif

#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <ctime>

#define ci(t) cin>>t
#define co(t) cout<<t
#define LL long long
#define ld long double
#define fa(i,a,b) for(LL i=(a);i<(LL)(b);++i)
#define fd(i,a,b) for(LL i=(a);i>(LL)(b);--i)
#define setp pair<pair<int,int>,int>
#define setl pair<LL,LL>
#define micro 0.000001

using namespace std;

LL gcd(LL a, LL b) { return a % b ? gcd(b, a % b) : b; }
LL lcm(LL a, LL b) { return (a * b) / gcd(a, b); }
#ifdef OHSOLUTION
#define ce(t) cerr<<t
#define AT cerr << "\n=================ANS=================\n"
#define AE cerr << "\n=====================================\n"
#else
#define AT
#define AE
#define ce(t)
#define __popcnt __builtin_popcountll
#endif

pair <int, int> vu[9] = { {0,1},{1,0},{0,-1} ,{-1,0},{0,0},{1,0}, {-1,1} , {1,-1},{-1,-1} }; //RDLU EWSN

template<typename T, typename U> void ckmax(T& a, U b) { a = a < b ? b : a; }
template<typename T, typename U> void ckmin(T& a, U b) { a = a > b ? b : a; }
struct gcmp { bool operator()(LL a, LL b) { return a < b; } bool operator()(setl a, setl b) { return a.second < b.second; } };
struct lcmp { bool operator()(LL a, LL b) { return a > b; } bool operator()(setl a, setl b) { return a.second > b.second; } };

const int max_v = 2e5 + 7;
const int INF = 1e9 + 7;
const LL LNF = (LL)5e18 + 7ll;
const LL mod = 1e9+7;

setl arr[max_v];
map<int, vector<int>> xh;
vector <int> vi[max_v];
map<setl, LL> dp;

LL dnq(int pos, int id)
{
	if (id == 0) return abs(pos);

	LL& ret = dp[{pos,id}];

	if (ret) return ret;

	if (vi[id - 1].size() == 1) return ret = dnq(vi[id - 1][0], id - 1)+ abs(pos-vi[id-1][0]);
	ret = LNF;
	LL dif = abs(vi[id - 1][0] - vi[id - 1][1]);
	ckmin(ret, dnq(vi[id - 1][1], id - 1) + dif + abs(pos - vi[id - 1][0]));
	ckmin(ret, dnq(vi[id - 1][0], id - 1) + dif + abs(pos - vi[id - 1][1]));
	return ret;
}

int main()
{
#ifdef OHSOLUTION
	freopen("input.txt", "r", stdin);
#endif
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n; ci(n);
	fa(i, 0, n) ci(arr[i].first >> arr[i].second);

	vector <int> cod(n);

	fa(i, 0, n) cod[i] = arr[i].second;

	sort(cod.begin(), cod.end());
	cod.erase(unique(cod.begin(), cod.end()), cod.end());

	fa(i, 0, n) arr[i].second = lower_bound(cod.begin(), cod.end(), arr[i].second) - cod.begin();

	fa(i, 0, n) xh[arr[i].second].push_back(arr[i].first);

	for (auto& x : xh)
	{
		sort(x.second.begin(), x.second.end());
		vi[x.first].push_back(x.second[0]);
		if (x.second.size() > 1) vi[x.first].push_back(x.second.back());
	}

	co(dnq(0, cod.size()));
	return 0;
}


#include<iostream>
#include<algorithm>
#include <cmath>
#include <string>
using namespace std;
int main()
{
	int n, x;
	string s;
	cin >> n >> x;
	cin >> s;
	for (int i = 0; i < n; i++)
	{
		if (s[i] == 'o')
		{
			x++;
		}
		if (s[i] == 'x')
		{
			if (x == 0)
			{
				continue;
			}
			else
			{
				x--;
			}
		}
	}
	cout << x << endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll long long
#define int long long int
#define pb push_back
#define mp make_pair
#define pll pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>
#define setbits(x) __builtin_popcountll(x)
#define md (ll)1e9 + 7
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define f(i, j, n) for (ll i = j; i < n; i++)
#define r(i, j, n) for (ll i = n - 1; i >= j; i--)
void solve()
{
    ll n,x;
    cin>>n>>x;
    string s;
    cin>>s;
    for(auto i : s){
        i=='o'?x++:x--,x=max(0ll,x);
    }
    cout<<x;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("inpput.txt", "r", stdin); //freopen("op.txt", "w", stdout);
#endif
    ll test_cases = 1;
    //cin >> test_cases;
    for (ll t = 1; t <= test_cases; t++)
        solve(),cout<<"\n";
    //cerr<<"Time : "<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms\n";
    return 0;
}


#include <bits/stdc++.h>

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

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

const ll MOD = 1e9 + 7;
const int INF = 1001001001;
const double PI = 3.14159265358979323846;

int V;
int G[20][20];
int dp[200000][20];

struct pos {
    int x, y, z;
    pos(int x, int y, int z) : x{x}, y{y}, z{z} {}
};

int rec(int state, int v) {
    if (state == 0) {
        if (v == 0) {
            return 0;
        } else {
            return INF;
        }
    }
    if ((state & (1 << v)) == 0) {
        return INF;
    }

    int &ret = dp[state][v];
    if (ret != 0) return ret;

    ret = INF;
    rep(u, V) {
        ret = min(ret, rec(state ^ (1 << v), u) + G[u][v]);
    }
    return ret;
}

void solve() {
    cin >> V;

    rep(i, 20) rep(j, 20) G[i][j] = INF;

    vector<pos> vec;
    int x, y, z;
    vector<int> zs;
    rep(i, V) {
        cin >> x >> y >> z;
        x--; y--; z--;
        vec.push_back(pos(x, y, z));
        zs.push_back(z);
    }

    rep(i, V) {
        auto a = vec[i];
        rep(j, V) {
            auto b = vec[j];
            int dist = abs(a.x - b.x) + abs(a.y - b.y);
            G[i][j] = dist + max(0, b.z - a.z);
            G[j][i] = dist + max(0, a.z - b.z);
        }
    }

    int state = (1 << V) - 1;
    int ans = rec(state, 0);

    if (ans == INF) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }
}

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

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

typedef long long ll;
const int maxn = 500;
const int inf  = 1 << 29;

const int N = 17;
int n;
int dp[N][1<<N];
int dis[N][N];
int pos[N][3];

int dfs(int city, int state) {
	if(state == (1 << n) - 1) {
		return dis[city][0];
	}
	if(dp[city][state] != -1) return dp[city][state];
	dp[city][state] = inf;
	for(int i = 0; i < n; i++) {
		if(state & (1 << i)) continue;
		dp[city][state] = min(dp[city][state], dis[city][i] + dfs(i, state | (1 << i)));
	}
	return dp[city][state];
}

int main() {
#ifdef LOCAL
    freopen("data.in", "r", stdin);
	freopen("data.out", "w", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

	scanf("%d", &n);
	for(int i = 0; i < n; i++) {
		scanf("%d%d%d", &pos[i][0], &pos[i][1], &pos[i][2]);
	}
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			dis[i][j] = abs(pos[i][0] - pos[j][0]) + abs(pos[i][1] - pos[j][1]) + max(0, pos[j][2] - pos[i][2]);
		}
	}
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			for(int k = 0; k < n; k++) {
				dis[j][k] = min(dis[j][k], dis[j][i] + dis[i][k]);
			}
		}
	}
	memset(dp, 255, sizeof(dp));
	dfs(0, 1<<0);
	printf("%d", dp[0][1<<0]);
    return 0;
}


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

void solve(vector<int> &a, vector<int> &b, vector<int> &c) {
    sort(a.begin(), a.end());
    int64_t ans = 0;
    for (auto &&i : c) {
        int value = b[i - 1];
        ans += upper_bound(a.begin(), a.end(), value) - lower_bound(a.begin(), a.end(), value);
    }
    cout << ans << endl;
}

int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    for (auto &&i : a) cin >> i;
    for (auto &&i : b) cin >> i;
    for (auto &&i : c) cin >> i;
    solve(a, b, c);
}

#include<algorithm>
#include<iostream>
#include<cstring>
#include<bitset>
#include<cstdio>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
#define int long long
#define uint unsigned int
#define reg register
#define db double
#define il inline
#define gc getchar
#define pc putchar
#define len 200000
il int umax(int a,int b){return a>b?a:b;}
il int umin(int a,int b){return a<b?a:b;}
il int rd()
{
	reg int res=0;
	reg char ch=getchar();
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9')
		res=(res<<3)+(res<<1)+(ch&15),ch=getchar();
	return res;
}
il void prt(int x,char t)
{
	if(x<0)putchar('-'),x=-x;
	if(x>9)prt(x/10,0),x%=10;
	putchar(x|48);
	if(t)putchar(t);
}
int n,a[len+5],b[len+5],mxa[len+5],mxb[len+5],ans;
signed main()
{
	n=rd();
	for(int i=1;i<=n;++i)
		a[i]=rd(),mxa[i]=umax(mxa[i-1],a[i]);
	for(int i=1;i<=n;++i)
		b[i]=rd(),mxb[i]=umax(mxb[i-1],b[i]);
	for(int i=1;i<=n;++i)
		prt((ans=umax(ans,mxa[i]*b[i])),'\n');
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=998244353;
ll dp[3005][3050],cnt;

ll dfs(int n,int k){
//	cout<<n<<" "<<k<<endl;
	if(n<k) return 0;
	if(dp[n][k]>0) return dp[n][k];
	if(n==0) return dp[n][k]=1;
	if(k==0) return dp[n][k]=0;
	ll ret=(dfs(n-1,k-1)+dfs(n,k<<1))%mod;
	return dp[n][k]=ret;
}

int main(){
	int n,k;cin>>n>>k;
	cout<<dfs(n,k)<<endl;
	return 0;
}

#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ub              upper_bound
#define lb              lower_bound
#define isrt            insert
#define clr             clear
#define rsz             resize
#define ff              first
#define ss              second
#define lli             long long int
#define pb              push_back
#define pf              push_front
#define mkp              make_pair
#define pii             pair<lli,lli>
#define vi              vector<int>
#define mii             map<lli,lli>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             998244353
#define INF             1e9
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define all(v)          v.begin(),v.end()
#define endl            "\n"
const double PI = acos(-1);

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

lli maxm(lli a, lli b)
{
  return (a >= b ? a : b);
}

lli minm(lli a, lli b)
{
  return (a <= b ? a : b);
}

lli power(lli x, lli y, lli p)
{
  lli res = 1;

  x = x % p;
  if (x == 0)
    return 0;

  while (y > 0)
  {

    if (y & 1)
      res = (res * x) % p;

    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}

lli nCrmodp(lli n, lli r, lli p)
{
  if (r == 0)
    return 1;
  if (r == 1)
    return n;

  lli pro = 1, k = n;
  while (k > r)
  {
    pro *= k;
    pro %= p;
    --k;
  }

  k = 2;
  while (k <= (n - r))
  {
    pro *= power(k, (p - 2), p);
    pro %= p;
    ++k;
  }

  return pro;
}

lli first_big(lli n, lli k, vector<lli> arr)
{
  lli l, r, ans = n;
  l = 0;
  r = n - 1;

  while (l <= r) {
    lli m = l + (r - l) / 2;

    if (arr[m] > k) {
      ans = m;
      r = m - 1;
    }

    else
      l = m + 1;
  }

  return ans;
}

lli last_small(lli n, lli k, vector<lli> arr)
{
  lli l, r, ans = -1;
  l = 0;
  r = n - 1;

  while (l <= r)
  {
    lli mid = (l + r) / 2;

    if (arr[mid] <= k)
    {
      ans = mid;
      l = mid + 1;
    }
    else
      r = mid - 1;
  }

  return ans;
}

void c_p_c()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}
lli dp[3001][6001];
lli n, k;

lli dfs(lli i, lli j)
{
  if (dp[i][j] == -1)
  {
    if (i < j)
      dp[i][j] = 0;
    else
    {
      if (j == 0 || i == 0)
      {
        if (i == 0 && j == 0)
          dp[i][j] = 1;
        else
          dp[i][j] = 0;
      }

      else
        dp[i][j] = (dfs(i - 1, j - 1) + dfs(i, 2 * j)) % mod;
    }
  }
  return dp[i][j];
}

int main()
{
  c_p_c();
  cin >> n >> k;
  memset(dp, -1, sizeof(dp));
  cout << dfs(n, k) << endl;

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int a[11], k, cnt;

int main() {

	int aa = 0;

	char c;
	while((c = getchar()) != ' ') a[++cnt] = c - 48;
	for(int i = 1; i <= cnt; i ++) aa = aa * 10 + a[i];

	cin >> k;

	int ne = aa;

	for(int i = 1; i <= k; i ++) {
		sort(a + 1, a + cnt + 1);
		int b = 0, e = 0;
		for(int i = 1; i <= cnt; i ++) b = b * 10 + a[i];
		reverse(a + 1, a + cnt + 1);
		for(int i = 1; i <= cnt; i ++) e = e * 10 + a[i];

		ne = abs(b - e);

		cnt = 0;

		if(i < k) while(ne > 0) a[++cnt] = ne % 10, ne /= 10;

	}

	cout << ne << endl;

	return 0;

}

#include<bits/stdc++.h>
#define fp(x,a,b) for(ll x=a; x<b; x++)
#define fn(x,a,b) for(int x=a; x>b; x--)
#define f(x, m) for(auto x : m)
#define cpu() ios::sync_with_stdio(false); cin.tie(nullptr)
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pair<int ,int>>
#define vll vector<pair<ll ,ll>>
#define all(v) v.begin(),v.end()
#define sor(a) sort( a.begin(), a.end() )
#define ros(a) sort( a.rbegin(), a.rend())
#define prec(n) fixed<<setprecision(n)
#define ff first
#define ss second
// #define tt third
#define print(x) for(auto it:x) cout<<it<<" ";
#define debug(x) cerr << #x << " is " << x << endl;
#define w(x) while(x--)
#define r(x) scanf("%d", &x)
#define rl(x) scanf("%ld", &x)
#define rll(x) scanf("%lld", &x)

typedef long long ll;
using namespace std;
template <typename TYPE> void readint(TYPE &x){
x=0; int f=1; char c;
for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-1;
for(;isdigit(c);c=getchar())x=x*10+c-'0';
x*=f;
}
#define dbg(args...){ string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
err(++it, args...);
}
template<typename... T>
void rd(T& ... args){
  ((cin >> args), ...);
}
template<typename... T>
void ps(T ... args){
  ((cout << args << ' '), ...);
  cout<<'\n';
}
const ll MOD = 1e9 + 7, MOD1 = 998244353LL, MAX = 2e5 + 5;
const char nl = '\n';
const int INF = 2e9;
int n, q;
char x[MAX];
//queue front back push pop
//stack top push pop
// __builtin_popcount() : Cuenta todos los bits 1 de un número
// __builtin_parity() : Revisa la paridad de un número
// __builtin_clz() : Cuenta todos los bits 0 a la izquierda del primer bit 1 de un número.
// __builtin_ctz() : Cuenta todos los bits 0 a la derecha del último bit 1 de un número.

void solve(){
  // be careful with typos and overflows, but also with the sizes of the arrays :::
	int a[3] = {1, 1, 0};
	rd(n);
	ll ans = 10000000000LL, ga = -1, gb = -1;
	fp(i, 0, n) rd(x[i]);
	if(n == 1){
		ps(ans * (x[0] - '/'));
		return;
	}
	bool gd = false;
	fp(i, 0, 3){
		bool f = true;
		fp(j, 0, n){
			if(x[j] - '0' != a[(j + i) % 3]){
				f = false;
				break;
			}
		}
		if(f) gd = f, ga = i, gb = (i + n - 1) % 3;
	}
	// dbg(n, ga, gb);
	if(gd) ps(ans - (n + (2 - gb) + ga) / 3 + 1);
	else ps(0);

}
int main(){
cpu();
// int __;
//  cin>>__;
//  while(__--){
//   solve();
//   // cout << nl;
//  }
   solve();
// cout<<nl;

return 0;
}


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

int N;
int A[MAX_N], B[MAX_N], P[MAX_N];
int idx[MAX_N];

void solve() {
	cin >> N;
	rep(i, 0, N) cin >> A[i];
	rep(i, 0, N) cin >> B[i];
	rep(i, 0, N) {
		cin >> P[i]; P[i]--;
		idx[P[i]] = i;
	}
	rep(i, 0, N) {
		if(A[i] <= B[P[i]] && i != P[i]) {
			cout << -1 << "\n"; return;
		}
	}
	vi ord(N);
	vector<pi> ans;
	rep(i, 0, N) ord[i] = i;
	sort(all(ord), [&](int a, int b) { return A[a] < A[b]; });
	rep(q, 0, N) {
		int i = ord[q];
		if(i == P[i]) continue;
		int j = idx[i];
		idx[P[i]] = j;
		idx[P[j]] = i;
		swap(P[i], P[j]);
		ans.pb(pi(i + 1, j + 1));
	}
	cout << sz(ans) << "\n";
	rep(i, 0, sz(ans)) {
		cout << ans[i].fst << " " << ans[i].sec << "\n";
	}
}

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

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

#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <string>
using namespace std;

#define debug(x) std::cerr << #x << '=' << x << '\n'

#define rep(a, b, c) for (int a = b; a <= c; a++)

typedef long long LL;
typedef unsigned long long ULL;

const int N = 212345;

int n, m;

void work_before(void) {
    for (int i = 1; i <= m + 1; i++) {
        printf("%d %d\n", i << 1, (i << 1) + 1);
    }
}

void work_after(void) {
    for (int i = 1; i <= n - m - 2; i++) {
        printf("%d %d\n", 1000000 + i * 2, 1000001 + i * 2);
    }
}

int main() {
    cin >> n >> m;
    if (n == 1 || n == 2) {
        if (!m) {
            puts("1 2");
        } else {
            puts("-1");
        }
        return 0;
    }

    if (m < 0 || n - m - 1 < 1) {
        puts("-1");
        return 0;
    }
    puts("1 1000001");
    work_before();
    work_after();
    return 0;
}


#include <bits/stdc++.h>
//#include <chrono>
//#pragma GCC optimize("O3")
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()

using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

ll N,M,H,W,Q,K,A,B;
string S;
using P = pair<ll, ll>;
const ll INF = (1LL<<60);

template<class T> bool chmin(T &a, const T b){
    if(a > b) {a = b; return true;}
    else return false;
}
template<class T> bool chmax(T &a, const T b){
    if(a < b) {a = b; return true;}
    else return false;
}
template<class T> void my_printv(std::vector<T> v,bool endline = true){
    if(!v.empty()){
        for(std::size_t i{}; i<v.size()-1; ++i) std::cout<<v[i]<<" ";
        std::cout<<v.back();
    }
    if(endline) std::cout<<std::endl;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin>>S;
    N = S.size();
    rep(i, N){
        if(S[i] == '.') break;
        cout<<S[i];
    }
    cout<<endl;
}

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

using ll = long long;

#define rep(i, n) for (int i=0; i<(int)(n); ++(i))
#define rep3(i, m, n) for (int i=(m); (i)<(int)(n); ++(i))
#define repr(i, n) for (int i=(int)(n)-1; (i)>=0; --(i))
#define rep3r(i, m, n) for (int i=(int)(n)-1; (i)>=(int)(m); --(i))
#define all(x) (x).begin(), (x).end()

int main() {
    ll n;
    cin >> n;
    map<ll, int> fib;
    ll val = 1, pre = 0;
    int cnt = 0;
    while (val <= n) {
        fib[val] = cnt;
        ll tmp = val + pre;
        pre = val;
        val = tmp;
        ++cnt;
    }
    int mc = fib.rbegin()->second;
    n -= fib.rbegin()->first;
    vector<int> add;
    for (auto itr=fib.rbegin(); itr!=fib.rend(); ++itr) {
        if (itr->second == mc) continue;
        if (n == 0) break;
        if (n >= itr->first) {
            n -= itr->first;
            add.push_back(itr->second);
        }
    }
    vector<int> res;
    int bi = mc % 2, ai = 0, adlen = add.size();
    rep(i, mc+1) {
        if (i%2 == 0) {
            if (i == 0) res.push_back(bi+1);
            else res.push_back(bi+3);
        }
        else res.push_back(4-bi);
        if (ai<adlen && add[ai]==mc-i) {
            res.push_back(((i%2)+bi)%2+1);
            ++ai;
        }
    }
    int k = res.size();
    cout << k << endl;
    rep(i, k) cout << res[i] << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,e,i,j,ii,jj,zx,xc,f[1500009],pas;
multiset <int> s,h;
multiset <int>::iterator it,tt;
void ins(int q){
	it=h.lower_bound(q);
	if(it!=h.end()&&(*it)==q){
		h.erase(it);
	}
	s.insert(q);
}
void er(int q){
	it=s.lower_bound(q);
	s.erase(it);
	it=s.lower_bound(q);
	if(it!=s.end()&&(*it)==q){

	}else{
		h.insert(q);
	}
}
void chk(){
	tt=h.begin();
	if(pas>(*tt)) pas=(*tt);
}
int main(){
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>a>>b;
	pas=a+2;
	for(i=1; i<=a; i++){
		cin>>f[i];
	}
	for(i=0; i<=a+2; i++){
		h.insert(i);
	}
	for(i=1; i<=b; i++){
		//s.insert(f[i]);
		ins(f[i]);
	}
	chk();
	for(i=b+1; i<=a; i++){
		c=f[i-b];
		/*it=s.lower_bound(c);
		s.erase(it);*/
		er(c);
		//s.insert(f[i]);
		ins(f[i]);
		chk();
	}
	cout<<pas;
	return 0;
}

#include <bits/stdc++.h>
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define Unique(v) sort(all(v));v.erase(unique(all(v)),v.end());
#define sz(v) ((int)v.size())
#define int long long
using namespace std;
typedef vector<int> vi;
#define y1 abacaba
//#define left oooooopss
#define db(x) cerr << #x <<" == "<<x << endl;
#define db2(x,y) cerr<<#x <<" == "<<x<<", "<<#y<<" == "<<y<<endl;
#define db3(x,y,z) cerr << #x<<" == "<<x<<", "<<#y<<" == "<<y<<", "<<#z<<" == "<<z<<endl;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());
inline ll mod(ll n, ll m ){ ll ret = n%m; if(ret < 0) ret += m; return ret; }
ll gcd(ll a, ll b){return (b == 0LL ? a : gcd(b, a%b));}
ll exp(ll b,ll e,ll m){
  b%=m;
  ll ans = 1;
  for (; e; b = b * b % m, e /= 2)
      if (e & 1) ans = ans * b % m;
  return ans;
}

const int N = 1511111 + 100;
int tree[N*4];
int qtd[N*4];
void upd(int no,int i,int j,int p,int v){
  if(i==j){
    qtd[no]+=v;
    tree[no] = (qtd[no] ? 1 : 0);
    return;
  }
  int mid = (i+j)>>1;
  int l=no<<1,r=no<<1|1;
  if(p<=mid)upd(l,i,mid,p,v);
  else upd(r,mid+1,j,p,v);
  tree[no] = tree[l] + tree[r];
}

int query(int no,int i,int j){
  if(i==j)return i;
  int mid = (i+j)>>1;
  int l=no<<1,r=no<<1|1;
  if(tree[l]!=(mid - i + 1)){
    return query(l,i,mid);
  }
  return query(r,mid+1,j);
}
int a[N];

int32_t main(){
  fastio;
  int n,m;
  cin >> n >> m;
  for(int i=1;i<=n;i++){
    cin >> a[i];
  }

  for(int i=1;i<=m;i++){
    upd(1,0,n,a[i],1);
  }
  int res = 1e9;
  for(int i=m;i<=n;i++){
    if(i!=m){
      upd(1,0,n,a[i-m],-1);
      upd(1,0,n,a[i],1);
    }
    res = min(res,query(1,0,n));
  }

  cout << res << endl;

  // math -> gcd it all
  // Did u check N=1? Did you switch N,M?
}


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

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

const int Nmax=509, INF=1e9+10;
int N,C[Nmax][Nmax],B[Nmax],A[Nmax],chk,Bm=INF,Am=INF,Delta;

int main() {
    ios_base::sync_with_stdio(0);    cin.tie(0);
    cin>>N;
    REP(i,1,N) {
        REP(j,1,N) {
            cin>>C[i][j];
        }
    }
    REP(j,1,N) {
        B[j]=C[1][j];       Bm=min(Bm,B[j]);
    }
    REP(j,1,N) B[j]-=Bm;
    REP(i,1,N) {
        A[i]=C[i][1];       Am=min(Am,A[i]);
    }
    REP(i,1,N) A[i]-=Am;
    Delta=C[1][1]-A[1]-B[1];
    REP(i,1,N) A[i]+=Delta;
    REP(i,1,N) {
        REP(j,1,N) {
            if (C[i][j]==A[i]+B[j]) continue;
            chk=-1;     break;
        }
    }
    if (chk) cout<<"No";
    else {
        cout<<"Yes\n";
        REP(i,1,N) cout<<A[i]<<" ";
        cout<<"\n";
        REP(i,1,N) cout<<B[i]<<" ";
    }
    return 0;
}

/*
  Krishnakant Tiwari
  Problem Link:

 */
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
using namespace std;
typedef long long ll;
#define _cin      ios_base::sync_with_stdio(0);  cin.tie(0);
#define endl "\n"
#define pb push_back
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define repd(i,a,b) for(ll i=a;i>=b;--i)
#define mp make_pair
#define hell 1000000007
#define vvll vector<vector<ll> >
#define vll vector<ll>
#define mll map<ll,ll>
#define sz(x) (ll)x.size()
#define sll set<ll>
#define pll pair<ll,ll>
#define F first
#define S second
#define eb	emplace_back
#define ppb	pop_back
#define pf	push_front
#define ppf	pop_front
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define precise(x)	cout<<fixed<<setprecision(x)
const ll MAX = 1000004;
const ll INF = 1e18L + 5;
template <class T, class U>
void chmin(T &t, const U &u)
{
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T &t, const U &u)
{
    if (t < u) t = u;
}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
    cerr << " " << H;
    debug_out(T...);
}
template <typename Arg1>
void pn(Arg1 &&arg1)
{
    cout << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void pn(Arg1 &&arg1, Args &&... args)
{
    cout << arg1 << "\n";
    pn(args...);
}
template <typename Arg1>
void ps(Arg1 &&arg1)
{
    cout << arg1 << " ";
}
template <typename Arg1, typename... Args>
void ps(Arg1 &&arg1, Args &&... args)
{
    cout << arg1 << " ";
    ps(args...);
}
template <typename Arg1>
void read(Arg1 &&arg1)
{
    cin >> arg1;
}
template <typename Arg1, typename... Args>
void read(Arg1 &&arg1, Args &&... args)
{
    cin >> arg1;
    read(args...);
}

ll g[MAX];
ll a[MAX];

void solve()
{
    ll n, a, b;
    read(n, a, b);
    pn(n - min(a, n) + b);

}

int main()
{

    _cin
    ll tc = 1;
    // cin>>tc;
    while(tc--)
    {
        solve();
    }

}


#include <bits/stdc++.h>
using namespace std;
#define LL long long
//#define MOD 1000000007
#define MOD 998244353
#define INF 1000000000000000000
#define VE vector
#define VL vector<LL>
#define VVL VE<VL>
#define VVVL VE<VVL>
#define LD long double
#define PB push_back
#define POB pop_back
#define FOR(i,a,k) for(LL i=a;i<k;i++)
#define rep(i,k) FOR(i,0,k)
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define coutl cout<<fixed<<setprecision(15)//

#define MI modint<MOD>
template<int mod>struct modint{
	int x;
	modint():x(0){}
	modint(LL n):x(n>=0?n%mod:(mod-(-n)%mod)%mod){}
	modint &operator+=(const modint &n){if((x+=n.x)>=mod)x-=mod;return *this;}
	modint &operator-=(const modint &n){if((x+=mod-n.x)>=mod)x-=mod;return *this;}
	modint &operator++(){*this+=1;return *this;}
  modint &operator--(){*this-=1;return *this;}
	modint &operator*=(const modint &n){x=(int)((LL)x*n.x%mod);return *this;}
	modint &operator/=(const modint &n){*this*=n.inv();return *this;}
	modint operator-()const{return modint(-x);}
	modint operator+(const modint &n)const{return modint(*this)+=n;}
	modint operator-(const modint &n)const{return modint(*this)-=n;}
	modint operator++(int){modint ret(*this);*this+=1;return ret;}
  modint operator--(int){modint ret(*this);*this-=1;return ret;}
	modint operator*(const modint &n)const{return modint(*this)*=n;}
	modint operator/(const modint &n)const{return modint(*this)/=n;}
	bool operator<(const modint &n)const{return x<n.x;}
	bool operator>(const modint &n)const{return x>n.x;}
	bool operator<=(const modint &n)const{return x<=n.x;}
	bool operator>=(const modint &n)const{return x>=n.x;}
	bool operator!=(const modint &n)const{return x!=n.x;}
	bool operator==(const modint &n)const{return x==n.x;}
	friend istream &operator>>(istream &is,modint &n){LL l;is>>l;n=modint<mod>(l);return is;}
	friend ostream &operator<<(ostream &os,const modint &n){return os<<n.x;}
	int getmod(){return mod;}
	modint inv()const{int a=x,b=mod,c=1,d=0,n;while(b){n=a/b;swap(a-=n*b,b);swap(c-=n*d,d);}return modint(c);}
	modint pow(LL n)const{modint ret(1),m(x);while(n){if(n&1)ret*=m;m*=m;n>>=1;}return ret;}
};

VL yakusuu(LL N){
	LL M=0;
	VL ret;
	for(LL i=0; i<N; i++){
		M++;
		if(M>N/M){
			for(LL i=0; i<N; i++){
				M--;
				if(M==0){
					return ret;
				}
				if(M*M==N){
					continue;
				}
				if(N%M==0){
					ret.PB(N/M);
				}
			}
		}
	  if(N%M==0){
		  ret.PB(M);
		}
	}
	return ret;
}

LL nanjo(LL a,LL n){//aのn乗  N=nanjo(a,n)A
	LL ret=1;
	for(LL i=0;i<n;i++){
		ret*=a;
	}
	return ret;
}

void YesNo(bool f){
	if(f)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

LL kakuketa(LL n){//各桁の和を求める
	LL a=0;
	while(n>0){
		a=a+n%10;
		n=n/10;
	}
	return a;
}

int main(){
	LL N,ans=1000000001;
	cin>>N;
	VL A(N),P(N),X(N);
	rep(i,N){
		cin>>A[i]>>P[i]>>X[i];
	}
	rep(i,N){
		if(X[i]-A[i]>0){
			if(ans>=P[i]){
				ans=P[i];
			}
		}
	}
	if(ans==1000000001){
		cout<<-1<<endl;
	}
	else{
		cout<<ans<<endl;
	}
	/*LL K,ans=0;
	cin>>K;
	ans=K-2;//全部同じ数だった場合
	if(K>=4){
		ans+=(1+(K-2)/2)*K/2*3;//２つ同じ数があった場合
	}
	if(K>=6){
		ans+=(1+(K/2+1)*K/6)**6;
	}
	cout<<ans<<endl;
	LL N,M,T,ans=0;
	cin>>N>>M>>T;
	ans=N;
	VL A(M),B(M);
	rep(i,M){
		cin>>A[i]>>B[i];
	}
	rep(i,M){
		ans=ans-A[i]+A[i-1];
		if(ans<=0){
			cout<<"No"<<endl;
			break;
		}
		ans=ans+(B[i]-A[i]);
		if(ans>=M){
			ans=N;
		}
	}
	cout<<"Yes"<<endl;*/
}

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

int main(){
  int N, A, P, X, x = 1000000000;
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> A >> P >> X;
    if(X - A > 0){
      x = min(P, x);
    }
  }
  if(x == 1000000000) cout << -1 <<endl;
  else cout << x << endl;
  return 0;
}


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

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

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

	ll N;
	cin >> N;

	ll tmp = 2 * N + 2;

	ll are = sqrt(tmp);

	ll kotae = 0;

	if (are * (are + 1) <= tmp) chmax(kotae, are);
	if (are * (are - 1) <= tmp) chmax(kotae, are - 1);
	if ((are + 2) * (are + 1) <= tmp) chmax(kotae, are + 1);

	co(N - kotae + 1);

	Would you please return 0;
}

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

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

    ll l, r;
    l = 0, r = 2e9;
    while (r - l > 1) {
        ll m = (l + r) / 2;
        if (m * m + m > 2 * n + 2) r = m;
        else l = m;
    }
    cout << n - (l - 1) << endl;
    // long double s = sqrtl(8.0 * n + 9.0);
    // cout << setprecision(15) << (- 1.0 + s ) / 2.0 << endl;
    // ll m = (- 1.0 + s ) / 2.0;
    // cout << m << endl;
    // cout << n - (m - 1) << endl;
}


#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define ep emplace
#define epb emplace_back
#define scll static_cast<long long>
#define sz(x) static_cast<int>((x).size())
#define pfll(x) printf("%lld\n", x)
#define ci(x) cin >> x
#define ci2(x, y) cin >> x >> y
#define ci3(x, y, z) cin >> x >> y >> z
#define co(x) cout << x << endl
#define co2(x, y) cout << x << y << endl
#define co3(x, y, z) cout << x << y << z << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> PQ;
typedef priority_queue<int, vector<int>, greater<int>> PQG;
typedef priority_queue<P> PQP;
typedef priority_queue<P, vector<P>, greater<P>> PQPG;

const int MAX_N = 2e5, MOD = 1e9 + 7, INF = 1e9;
int n, x[100], y[100];

int par[MAX_N + 2], r[MAX_N + 2];

void init(int x) {
    for (int i = 0; i < x; i++) par[i] = i;
}

int find(int x) {
    if (par[x] == x) return x;
    else return par[x] = find(par[x]);
}

void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (r[x] < r[y]) par[x] = y;
    else {
        if (r[x] == r[y]) r[x]++;
        par[y] = x;
    }
}

bool same(int x, int y) {
    return find(x) == find(y);
}

int main() {
    ci(n);
    rep(i, n) ci2(x[i], y[i]);
    double l = 0.0, r = 100.0;
    rep(cnt, 200) {
        double mid = (l + r) / 2;
        init(n + 2);
        rep(i, n) {
            if (2 * mid >= 100 - y[i]) unite(i, n);
            if (2 * mid >= y[i] + 100) unite(i, n + 1);
            rep(j, i) {
                if (4 * mid * mid >= (x[i] - x[j]) * (x[i] - x[j])
                                  +  (y[i] - y[j]) * (y[i] - y[j])) {
                    unite(i, j);
                }
            }
        }
        if (same(n, n + 1)) r = mid;
        else l = mid;
    }
    printf("%5.15lf\n", l);
    return 0;
}

/**
 * Written by : Ujjawal Pabreja [cuber_coder]
 * Email : ujjawalpabreja99@gmail.com
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
#define endl "\n"
const int mod = 1e9 + 7;
const int MAX = 2e5 + 1;

int n;
vector <pair <ld, ld>> a;
vector <int> Parent, Rank;

void init() {
    Parent.resize(n + 2);
    Rank.resize(n + 2);
    iota(Parent.begin(), Parent.end(), 0);
}

int Find(int v) {
    while (v != Parent[v]) {
        v = Parent[v];
    }
    return v;
}

void Union(int u, int v) {
    u = Find(u);
    v = Find(v);
    if (Rank[u] < Rank[v]) {
        Parent[u] = v;
    } else {
        Parent[v] = u;
        if (Rank[u] == Rank[v]) {
            Rank[u]++;
        }
    }
}

ld distance(pair <ld, ld> a, pair <ld, ld> b) {
    return (a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second);
}

bool possible(ld r) {
    init();
    for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            if (distance(a[i], a[j]) <= 4.0 * r * r) {
                Union(i, j);
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        if (abs(a[i].second - 100) <= 2.0 * r) {
            Union(n + 1, i);
        }
        if (abs(a[i].second + 100) <= 2.0 * r) {
            Union(0, i);
        }
    }
    return Find(0) != Find(n + 1);
}

void Solve() {
    cin >> n;
    a.resize(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i].first >> a[i].second;
    }
    sort(a.begin() + 1, a.end());
    ld hi = 100, lo = 0, ans;
    ll itr = 100;
    while (itr--) {
        ld mid = lo + (hi - lo) / 2;
        if (possible(mid)) {
            lo = mid + 1;
            ans = mid;
        } else {
            hi = mid - 1;
        }
    }
    cout << fixed << setprecision(20) << ans << endl;
}

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

    int testcases = 1;
    // cin >> testcases;

    while (testcases--) {
        Solve();
    }
}


#include<bits/stdc++.h>
using namespace std;
int a[3050][6], n;
bool check(int x){
    int vis[35] = {0};
    for(int i = 1; i <= n; i ++){
        int tmp = 0;
        for(int j = 0; j < 5; j ++){
            if(a[i][j] >= x) tmp |= (1 << j);
        }
        vis[tmp] = 1;
    }
    int t = 1 << 5;
    for(int i = 0; i < t; i ++)
        for(int j = i; j < t; j ++)
            for(int k = j; k < t; k ++)
                if(vis[i] && vis[j] && vis[k] && (i|j|k) == t - 1) return true;
    return false;
}
int main(){
    cin >> n;
    for(int i = 1; i <= n; i ++) for(int j = 0; j < 5; j ++) cin >> a[i][j];
    int l = 1, r = 1e9, ans = 1;
    while(l <= r){
        int mid = l + r >> 1;
        if(check(mid)) l = mid + 1, ans = mid;
        else r = mid - 1;
    }
    cout << ans << endl;
    return 0;
}

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

#define ll     long long
#define test   int tt; cin>>tt; while(tt--)
#define ff     first
#define ss     second
#define pb     push_back
#define ppb    pop_back
#define pf     push_front
#define ppf    pop_front

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

    int n;
    cin>>n;

    int arr[n][5];

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

    int ans=0;

    for(int k=0; k<5; k++)
    {
        vector<pair<int, int>> v;

        for(int i=0;i<n;i++)
            v.pb({arr[i][k], i});

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

        int sel=v[n-1].ss;
        int done[5];

        for(int j=0; j<5; j++)
            done[j]=arr[sel][j];

        for(int i=0;i<n;i++)
        {
            for(int j=i+1;j<n;j++)
            {
                int aa=max({done[0], arr[i][0], arr[j][0]});
                int bb=max({done[1], arr[i][1], arr[j][1]});
                int cc=max({done[2], arr[i][2], arr[j][2]});
                int dd=max({done[3], arr[i][3], arr[j][3]});
                int ee=max({done[4], arr[i][4], arr[j][4]});

                ans=max(ans, min({aa, bb, cc, dd, ee}));
            }
        }
    }

    cout<<ans<<endl;
}


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

int32_t main()
{
    int t;
    //cin>>t;
    t=1;
    while(t--)
    {
        int n;cin>>n;
        map<string,int> one;
        map<string,int> two;
        while(n--){
            string s;
            cin>>s;
            if(s[0]=='!'){
                int size=s.size();
                s=s.substr(1,size-1);
                two[s]++;
            }
            else{
                one[s]++;
            }
        }
        bool found=false;
        string ans="satisfiable";
        for(auto c:one){
            if(two.find(c.first)!=two.end()){
                found=true;
                ans=c.first;
            }
        }
        if(!found)
        cout<<"satisfiable"<<endl;
        else
        cout<<ans<<endl;
    }
}

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

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

int T;

int extGCD(int a, int b, int &x, int &y)
{
    if(b == 0)
    {
        x = 1;
        y = 0;
        return a;
    }

    int ret = extGCD(b, a % b, y, x);
    y -= a / b * x;
    return ret;
}

int unit(int a, int b)
{
    if(a < 0)return 0;
    return (a + b - 1) / b;
}

signed main()
{
    cin >> T;
    rep(_, T)
    {
        int X, Y, P, Q;
        cin >> X >> Y >> P >> Q;

        int T1 = 2 * (X + Y), T2 = P + Q;
        int ans = -1;
        rep(i, Y)rep(j, Q)
        {
            int x, y;
            int c = P + j - X - i;
            int d = extGCD(T1, -T2, x, y);
            if(d < 0)
            {
                d = -d;
                x = -x;
                y = -y;
            }
            if(c % d != 0)continue;
            // cout << T1 << "*" << x << "+" << -T2 << "*" << y << "=" << d << endl;
            x *= c / d, y *= c / d;

            // cout << T1 << "*" << x << "+" << -T2 << "*" << y << "=" << c << endl;

            int t1 = T1 / d, t2 = T2 / d;

            if(x < 0 || y < 0)
            {
                int MAX = max(unit(-x, t2), unit(-y, t1));
                // cout << "((" << -x << ", " << t2 << ")" << unit(-x, t2) << ", " << "(" << -y << ", " << t2 << ")" << unit(-y, t1) << ")" << endl;
                // cout << "MAX : " << MAX << endl;
                x += MAX * t2, y += MAX * t1;
                if(ans == -1)ans = x * T1 + i + X;
                else ans = min(ans, x * T1 + i + X);
                // assert(x * T1 + i + X == y * T2 + P + j);
            }
            else
            {
                int MIN = min(x / t2, y / t1);
                // cout << "MIN : " << MIN << endl;
                x -= MIN * t2, y -= MIN * t1;
                if(ans == -1)ans = x * T1 + i + X;
                else ans = min(ans, x * T1 + i + X);
                // assert(x * T1 + i + X == y * T2 + P + j);
            }
        }

        if(ans == -1)cout << "infinity " << endl;
        else cout << ans << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pb push_back
#define ve vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vp vector<pair<ll, ll>>
#define all(v) (v).begin(), (v).end()
#define sortve(v) sort(all(v))
#define rsrt(v) sort(v.rbegin(), v.rend())
#define rev(i, n) for (ll i = n - 1; i >= 0; i--)
#define f(i, n) for (ll i = 0; i < n; i++)
#define f1(i, n) for (ll i = 1; i < n + 1; i++)
#define f2(i, a, b) for (ll i = a; i < b; i++)
#define precision(x) cout << fixed << setprecision(x);
#define testcase \
    ll t;        \
    cin >> t;    \
    while (t--)
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(nullptr);             \
    cout.tie(nullptr)
#define bas cout << "\n";
const ll PI = 3.1415926535897932384626;
const ll mod = 1000000007;
const ll FMOD = 998244353;
const ll N = 100005;
const double eps = 1e-9;

// Let's Go 😇

int main()
{
    double a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a > c)
    {
        swap(a, c);
        swap(b, d);
    }
    //cout << a << b << c << d;
    double tan = (b + d) / (c - a);
    // cout << tan;
    double ans = a + (b / tan);
    precision(6);
    cout << ans;
}

/* SERIOUSLY, It ⬇ ain't a JOKE ⬇ */

/* The problem  is either
   in conditional statements
   or the increments or %mod or
   endl or you are printing
   something else*/

// ABC196C
// 幾何
// 各色ごとの最終位置は二択.

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

const int INF = 1e18;

signed main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int N;
  cin >> N;
  map<int, vector<int>> m;
  for (int i = 0; i < N; i++) {
    int x, c;
    cin >> x >> c;
    m[c].push_back(x);
  }
  vector<vector<int>> pos(N + 1, vector<int>(2, 0));
  vector<vector<int>> sec(N + 1, vector<int>(2, INF));
  sec[0] = {0, 0};
  int i = 0;
  for (auto& [_, v] : m ) {
    auto max = *max_element(v.begin(), v.end());
    auto min = *min_element(v.begin(), v.end());
    for (int j = 0; j < 2; j++) {
      // max first
      int tmp = abs(max - pos[i][j]) + max - min + sec[i][j];
      if (tmp < sec[i + 1][0]) {
        sec[i + 1][0] = tmp;
        pos[i + 1][0] = min;
      }
      int tmp2 = abs(pos[i][j] - min) + max - min + sec[i][j];
      if (tmp2 < sec[i + 1][1]) {
        sec[i + 1][1] = tmp2;
        pos[i + 1][1] = max;
      }
    }
    ++i;
  }
  cout << min(sec[i][0] + abs(pos[i][0]), sec[i][1] + abs(pos[i][1])) << endl;

  return 0;
}


#include<bits/stdc++.h>

int main(){
    using namespace std;
    const auto scan{[]{unsigned long r; cin >> r; return r;}};
    const auto N{scan()}, M{scan()};
    const auto [h, dif]{[&N]{
        vector<unsigned long> h(N);
        for(auto&& i : h)cin >> i;
        sort(begin(h), end(h));
        vector<unsigned long> rp{0}, ra;
        for(unsigned long i{0}; i + 1 < N; i += 2)rp.push_back(h[i + 1] - h[i]);
        for(unsigned long i{1}; i + 1 < N; i += 2)ra.push_back(h[i + 1] - h[i]);
        ra.push_back(0);
        partial_sum(begin(rp), end(rp), begin(rp));
        partial_sum(rbegin(ra), rend(ra), rbegin(ra));
        transform(begin(rp), end(rp), begin(ra), begin(rp), plus<>{});
        return make_pair(h, rp);
    }()};
    const auto w{[&M]{
        vector<unsigned long> w(M);
        for(auto&& i : w)cin >> i;
        sort(begin(w), end(w));
        return w;
    }()};
    auto it{begin(h)};
    unsigned long ans{numeric_limits<unsigned long>::max()};
    for(const auto& i : w){
        while(it != end(h) && i > *it)++it;
        const unsigned long idx{(it - begin(h)) / 2UL};
        ans = min(dif[idx] + max(h[2 * idx], i) - min(h[2 * idx], i), ans);
    }
    cout << ans << endl;
    return 0;
}

#pragma region Region_1

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
using ll = long long;
using P = pair<int, int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VP = vector<P>;
#define MOD 1000000007
const int INF = 1e9 + 10;

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

template <class T>
T sum(const vector<T>& v) {
    T res = 0;
    for (size_t i = 0; i < v.size(); ++i) res += v[i];
    return res;
}

/////////////////////////////////////////////////////////
// print like python
// https://qiita.com/Lily0727K/items/06cb1d6da8a436369eed
/////////////////////////////////////////////////////////
void print() { cout << endl; }

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << " ";
    print(forward<Tail>(tail)...);
}

template <class T>
void print(vector<T>& vec) {
    for (auto& a : vec) {
        cout << a;
        if (&a != &vec.back()) cout << " ";
    }
    cout << endl;
}

template <class T>
void print(vector<vector<T>>& df) {
    for (auto& vec : df) {
        print(vec);
    }
}

#pragma endregion Region_1
/////////////////////////////////////////////////////////

int main() {
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    std::cout << std::setprecision(15);
    //////////////////////////////////////////

    int n, m;
    cin >> n >> m;
    VL H(n);
    VL W(m);

    rep(i, n) cin >> H[i];
    rep(i, m) cin >> W[i];

    sort(rng(H));

    VL sum1(n + 1, 0);
    for (int i = 0; i < n - 1; i += 2) {
        sum1[i / 2 + 1] = sum1[i / 2] + H[i + 1] - H[i];
    }

    VL sum2(n + 1, 0);
    for (int i = n - 2; i > 0; i -= 2) {
        sum2[i / 2] = sum2[i / 2 + 1] + H[i + 1] - H[i];
    }

    ll ans = 2 * INF;
    rep(i, m) {
        ll w = W[i];
        ll idx = [&] {
            int l = -1, r = n;
            while (l + 1 < r) {
                int m = (l + r) / 2;
                if (H[m] < w) {
                    l = m;
                } else {
                    r = m;
                }
            }
            return r;
        }();
        // print("t1:",w, idx);
        // print("t2:",sum1[idx / 2], sum2[idx / 2]);
        if (idx % 2 == 0) {  // 奇数番目に挿入
            chmin(ans, sum1[idx / 2] + sum2[idx / 2] + abs(H[idx] - w));
        } else {  // 偶数番目に挿入
            chmin(ans, sum1[idx / 2] + sum2[idx / 2] + abs(H[idx - 1] - w));
        }
    }
    print(ans);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int t[200005];
long long a[200005];
long long sum[200005];

pair<long long, long long> tree[1000000];
void update(int n, int s, int e, int i, int t, long long v){
    if(s == e){
        if(t == 2) tree[n].first = v;
        else tree[n].second = v;
    }
    else{
        int mid = (s+e)/2;
        if(i <= mid) update(n+n, s, mid, i, t, v);
        else update(n+n+1, mid+1, e, i, t, v);
        tree[n].first = max(tree[n+n].first, tree[n+n+1].first);
        tree[n].second = min(tree[n+n].second, tree[n+n+1].second);
    }
}
pair<long long, long long> query(int n, int s, int e, int l, int r){
    if(s > r || l > e) return make_pair(-1e18, 1e18);
    if(l <= s && e <= r) return tree[n];
    int mid = (s+e)/2;

    pair<long long, long long> x = query(n+n, s, mid, l, r);
    pair<long long, long long> y = query(n+n+1, mid+1, e, l, r);
    return make_pair(max(x.first, y.first), min(x.second, y.second));
}

int n, q;
int find_max(long long sum, int i){
    int lo = i+1, hi = n, ans = -1;
    while(lo <= hi){
        int mid = (lo+hi)/2;
        if(query(1, 1, n, i+1, mid).first >= sum) ans = mid, hi = mid-1;
        else lo = mid+1;
    }
    return ans;
}
int find_min(long long sum, int i){
    int lo = i+1, hi = n, ans = -1;
    while(lo <= hi){
        int mid = (lo+hi)/2;
        if(query(1, 1, n, i+1, mid).second <= sum) ans = mid, hi = mid-1;
        else lo = mid+1;
    }
    return ans;
}

long long tmp[200005];
int main(){
    scanf("%d", &n);
    for(int i=1;i<=4*n;i++) tree[i] = make_pair(-1e18, 1e18);
    for(int i=1;i<=n;i++){
        scanf("%lld%d", &a[i], &t[i]);
        if(t[i] == 1) sum[i] = sum[i-1] + a[i];
        else sum[i] = sum[i-1];
        a[i] -= sum[i];
    }
    for(int i=n;i>=1;i--){
        if(t[i] == 2 || t[i] == 3){
            int mx = find_max(a[i], i);
            int mn = find_min(a[i], i);

            if(mx == -1 && mn == -1){
                tmp[i] = a[i] + sum[i] + (sum[n] - sum[i]);
            }
            else if(mx != -1 && mn == -1){
                tmp[i] = tmp[mx];
            }
            else if(mn != -1 && mx == -1){
                tmp[i] = tmp[mn];
            }
            else{
                tmp[i] = tmp[min(mn, mx)];
            }

            if(t[i] == 2){
                update(1, 1, n, i, 2, a[i]);
            }
            else{
                update(1, 1, n, i, 3, a[i]);
            }
        }
    }

    scanf("%d", &q);
    for(int i=1;i<=q;i++){
        int x;
        scanf("%d", &x);
        int mx = find_max(x, 0);
        int mn = find_min(x, 0);

        long long ans = 0;
        if(mx == -1 && mn == -1){
            ans = x + sum[n];
        }
        else if(mx != -1 && mn == -1){
            ans = tmp[mx];
        }
        else if(mn != -1 && mx == -1){
            ans = tmp[mn];
        }
        else{
            ans = tmp[min(mn, mx)];
        }
        printf("%lld\n", ans);
    }
}

#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cerr << #x << " = " << (x) << endl
#define show2(x,y) cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cerr << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second)
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) (find(all(v),x)!=v.end())
#define incls(s,c) (s.find(c)!=string::npos)
#define lb(a,x) distance((a).begin(),lower_bound(all(a),(x)))
#define ub(a,x) distance((a).begin(),upper_bound(all(a),(x)))
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(all(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
//const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define YN {puts("YES");}else{puts("NO");}
inline int in() { int x; cin >> x; return x;}
inline ll lin() { ll x; cin >> x; return x;}
inline char chin() { char x; cin >> x; return x;}
inline string stin() { string x; cin >> x; return x;}
inline double din() { double x; cin >> x; return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const vector<T>& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
char itoa(int n) { return n + '0';}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
const int dy[4] = {1, 0, -1,  0};
const int dx[4] = {0, 1,  0, -1};

int d[20][20];
int dp[1<<17][17];

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

	rep(i,n)rep(j,n) {
		if (i == j) continue;
		d[i][j] = INF;
	}
	rep(s,n)rep(t,n) {
		// s -> t
		int a = x[s];
		int b = y[s];
		int c = z[s];
		int p = x[t];
		int q = y[t];
		int r = z[t];

		int cost = abs(p-a) + abs(q-b) + max(0,r-c);
		d[s][t] = cost;
	}

	rep(i,1<<n)rep(j,n) dp[i][j] = INF;
	dp[(1<<n)-1][0] = 0;
	for (int S = (1<<n)-2; S >= 0; S--) {
		rep(v,n)rep(u,n) {
			if (!(S>>u&1)) {
				dp[S][v] = min(dp[S][v], dp[S|1<<u][u] + d[v][u]);
			}
		}
	}

	cout << dp[0][0] << endl;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <utility>
#define pb push_back
#define mk make_pair
#define endl "\n"
#define mod 998244353
#define mod1 1610612741
#define mul 31
#define PI 3.14159265358979323846264
//#include bits/stdc++.h
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
typedef long long int lli;
typedef long double ld;
typedef pair<lli,lli> ii;
priority_queue <lli, vector<lli>, greater<lli> > ti;
//priority_queue<pair<lli,pair<lli,lli>>>e;
vector <lli> p[300005],q[300005],f(5000005,0),d(5000005);
//vector<set<lli>>s(200005);
//set<pair<lli,lli>>s;
//lli dp[1000005][3][3];
//lli b[1000005],l[1000005];
//vector<vector<lli>> d(300005,vector<lli>(18,0));
//vector<pair<lli,ii>>p[300005];
map<pair<lli,lli>,lli>mp;
//vector<pair<pair<lli, lli>,lli> > st;
//queue<lli> qy;
lli gcd(lli a, lli b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
lli bpow(lli a, lli b) {
    lli res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a)%mod;
        a = (a * a)%mod;
        b >>= 1;
    }
    return res%mod;
}
void fact(lli i)
{
    f[0]=1;
    for(lli k=1;k<=i;k++)
    {
        (f[k]=f[k-1]*k)%=mod;
    }
}
lli isprime(lli n)
{
    if(n==1)
        return 0;
    for(lli i=2;i<=sqrt(n);i++)
        if(n%i==0)
            return 0;
    return 1;
}
lli find(lli x)
{
    if(f[x]==x)
        return x;
    else
        return f[x]=find(f[x]);
}
bool cmp(lli x,lli y)
{
    return x<y;
}
void check()
{
    cout<<"HI"<<endl;
}
lli comb(lli i,lli j)
{
    if(j>i)return 0;
    lli k=f[i];
    lli g=(f[j]*(f[i-j]))%mod;
    lli h=bpow(g,mod-2);
    return (k*h)%mod;
}
/*void sieve()
{
    for(lli i=2;i<=sqrt(10000000);i++)
    {
        if(b[i]==0)
        {
            k.pb(i);
        for(lli j=2;i*j<=sqrt(10000000);j++)
        {
            b[i*j]=1;
        }
        }
    }
}*/
void dfs(lli i,lli pr)
{
    for(auto u:p[i])
    {
        if(f[u]==0)
        {
            f[u]=f[i]+1;
            dfs(u,i);
        }
    }
}
int main ()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli n;cin>>n;
    lli x;
    for(lli i=1;i<=n;i++)
    {
        cin>>x;
        if(i!=x)
        {
            p[i].pb(x);
            p[x].pb(i);
        }
    }
    lli c=0;
    for(lli i=1;i<=n;i++)
    {
        if(f[i]==0)
        {
            f[i]=1;
            dfs(i,0);
            c++;
        }
        //cout<<i<<" "<<c<<endl;
    }
    lli j=bpow(2,c);
    j=(j-1+mod)%mod;
    cout<<j<<endl;
}

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

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

using namespace std;

long long pow_mod(long long x, long long y, long long MOD) {
  long long ret = 1;
  while (y) {
    if (y & 1)
      ret = ret * x % MOD;
    x = x * x % MOD;
    y >>= 1;
  }
  return ret;
}

struct UnionFind {
  vector<int> par, siz;

  // initialize
  UnionFind(int n): par(n, -1), siz(n, 1) {}

  int root(int x){
    if (par[x] == -1) return x;
    else return par[x] = root(par[x]);
  }

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

  bool unite(int x, int y){
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (siz[x] < siz[y]) swap(x, y);
    par[y] = x;
    siz[x] += siz[y];
    return true;
  }

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

signed main() {
  long long MOD = 998244353;
  int N;
  cin >> N;
  int f[N];
  set<int> result_set;
  int result;
  UnionFind uf(N+1);
  rep(i, N){
    cin >> f[i];
    uf.unite(i+1, f[i]);
  }
  rep(i, N){
    result_set.insert(uf.root(i+1));
  }
  result = pow_mod(2, result_set.size(), MOD);
  cout << result - 1 << endl;

  return 0;
}


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

using namespace std;
using namespace __gnu_pbds;

#define endl '\n'
#define f first
#define s second
#define ub  upper_bound
#define lb  lower_bound
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define fbo find_by_order
#define ook order_of_key
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << "[" << name << " : " << arg1 << "]" << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cerr << "[";
cerr.write(names, comma - names) << " : " << arg1<<"] | ";__f(comma+1, args...);
}

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

struct UnionFind{
  vi parent;
  vi set_size;
  int n;
  UnionFind(int n):n(n){
    parent.resize(n+1);
    iota(all(parent),0);
    set_size.assign(n+1,1);
  }
  int find(int x){
    if(x == parent[x])
      return x;
    return parent[x] = find(parent[x]);
  }
  void join(int x,int y){
    x = find(x);
    y = find(y);
    if(x == y)
      return;
    if(set_size[x] > set_size[y])
      swap(x,y);
    parent[x] = y;
    set_size[y] += set_size[x];
  }
};

struct Point{ //Represents a 2D Point
  ld x,y;
  Point(ld x=0,ld y=0):x(x),y(y){}
};

const ld EPS = 1e-9;
int n;

vector <Point> points;

bool lte(ld x,ld y){ //x <= y
  return x < y + EPS;
}

bool lt(ld x,ld y){ // x < y
  return x + EPS < y;
}

ld squared(ld x){
  return x*x;
}

ld euc_dist(Point p1,Point p2){
  return sqrt(squared(p1.x - p2.x) + squared(p1.y - p2.y));
}

bool can(ld m){
  UnionFind dsu(n+2);
  for(int i=0;i<n;i++)
    for(int j=i+1;j<n;j++)
      if(lt(euc_dist(points[i],points[j]), 2*m)) dsu.join(i,j);

  for(int i=0;i<n;i++){
    if(lt(points[i].y + 100, 2*m)) dsu.join(i, n);
    if(lt(100 - points[i].y, 2*m)) dsu.join(i, n+1);
  }

  return dsu.find(n) != dsu.find(n+1);
}

int main(){
  fastio;

  cin >> n;
  points.resize(n);
  for(int i=0;i<n;i++)
    cin >> points[i].x >> points[i].y;

  ld l = 0;
  ld r = 100;

  ld ans = 0;

  for(int i=0;i<100;i++){
    ld m = (l + r)/2;
    if(can(m)) ans = m, l = m;
    else r = m;
  }

  cout << fixed << setprecision(10) << ans << endl;

  return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int>A(2*N);
    vector<pair<int,int>>B(2*N);
    vector<int>C(2*N);
    for(int i = 0; i < 2*N; i++) {
        cin >> A[i];
        B[i] = {A[i],i};
    }
    sort(B.rbegin(),B.rend());
    for(int i = 0; i < N; i++) {
        C[B[i].second]++;
    }
    string ans = "";
    int sum1 = 0,sum2 = 0;
    for(int i = 0; i < 2*N; i++) {
        if(C[i] == 0) {
            if(sum2) {
                sum2--;
                ans += ')';
            }
            else {
                sum1++;
                ans += '(';
            }
        }
        else {
            if(sum1) {
                sum1--;
                ans += ')';
            }
            else {
                sum2++;
                ans += '(';
            }
        }
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
# define Z 1000000007
# define el "\n"
# define vt vector
# define pb push_back
# define all(v) (v).begin(),(v).end()
# define ll long long int

int main()
{
	ll l;
	cin>>l;
	vt<ll>v(1<<l);
	for(ll i=0;i<(1<<l);i++){
		cin>>v[i];
	}
	auto k1 = max_element(v.begin(),v.begin()+(1<<(l-1)));
	auto k2 = max_element(v.begin()+(1<<(l-1)),v.end());
	if(*k1>*k2){cout<<k2-v.begin()+1<<el;}else{cout<<k1-v.begin()+1<<el;}

return 0;
}

#include <iostream>
#include <vector>
#include <numeric>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector <long long> a(1 << n);
  for (auto &x : a) {
    cin >> x;
  }

  vector <int> id(1 << n);
  iota(id.begin(), id.end(), 0);
  for (int i = 0; i < n - 1; ++i) {
    int f = 1 << (i + 1);
    for (int r = f; r <= (1 << n); r += f) {
      int l = r - f;
      int x = (l + r) / 2 - 1;
      int winner = a[id[x]] > a[id[x + 1]] ? id[x] : id[x + 1];
      for (int k = l; k < r; ++k) {
        id[k] = winner;
      }
    }
  }

  int x = (1 << (n - 1)) - 1;
  if (a[id[x]] > a[id[x + 1]]) {
    cout << id[x + 1] + 1 << endl;
  } else {
    cout << id[x] + 1 << endl;
  }
  return 0;
}


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

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

int main(){
    ll R, X, Y; cin >> R >> X >> Y;
    ll D = X*X+Y*Y;

    if(D < R*R) {cout << "2\n"; return 0;}

    ll A = (D+R*R-1)/(R*R);
    int ans = 0;

    rep2(i, 0, 1000000){
        if(A > i*i) ans++;
        else break;
    }

    cout << ans << '\n';
}

//雪花飄飄北風嘯嘯
//天地一片蒼茫

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl

#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define lb lower_bound
#define up upper_bound

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

const int MOD=998244353;

int n;
int arr[200005];
bool vis[200005];
bool onstack[200005];

bool dfs(int i){
	if (vis[i]){
		return onstack[i];
	}
	vis[i]=true;
	onstack[i]=true;

	bool res=dfs(arr[i]);

	onstack[i]=false;
	return res;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin.exceptions(ios::badbit | ios::failbit);

	cin>>n;
	rep(x,1,n+1) cin>>arr[x];

	int cnt=0;
	rep(x,1,n+1) if (!vis[x]){
		cnt+=dfs(x);
	}

	ll ans=1;
	rep(x,0,cnt){
		ans=(ans*2)%MOD;
	}

	cout<<ans-1<<endl;
}


// D - Base n
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

string X;
ll M;

string f(ll n){
	ll m = M;
	string res = "";
	while(m){
		ll r = m % n; m = m / n;
		res += r <= 9? to_string(r): "a";
	}
	reverse(res.begin(), res.end());
	return res;
}

bool check(ll n){
	string m = f(n);
	if(X.size() > m.size()) return false;
	else if(X.size() < m.size()) return true;
	for(int i=0; i<(int)X.size(); ++i)
		if(X[i] < m[i]) return true;
		else if(X[i] > m[i]) return false;
	return true;
}

int main(){
	cin>>X>>M;
	if(X.size() == 1){ cout<< (stoi(X) <= M) <<endl; return 0; }
	int d = 0;
	for(auto c:X) d = max(d, c-'0');
	ll ok = d, ng = M + 1;
	while(ng - ok > 1){
		ll n = (ng + ok) / 2;
		(check(n)? ok:ng) = n;
	}
	cout<< ok - d <<endl;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define endl "\n"
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

void solve(){
  int a,b;
  cin>>a>>b;
  int sum1 =0;
  int sum2 =0;
  while(a){
      int r1 = a%10;

    sum1+=r1;
    a/=10;

  }

    while(b){
     int r2 = b%10;

    sum2 +=r2;
    b/=10;}
	if (sum1>sum2)
  cout<<sum1<<endl;
  else cout<<sum2<<endl;
}

signed main(){
  IOS
  solve();
  return 0;
}


#include<bits/stdc++.h>
#define N 505
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
bool mmp1;
int n,m,K;
namespace P100 {
	int C[N][N];
	int A[N],B[N];
	int D[N][N];
	void solve() {
		scanf("%d",&n);
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++)
				scanf("%d",&C[i][j]);
		for(int i=1;i<=n;i++)
			B[i]=C[1][i];
		for(int i=1;i<=n;i++)
			A[i]=C[i][1]-B[1];
		int ma=A[1],mb=B[1];
		for(int i=2;i<=n;i++)ma=min(ma,A[i]);
		for(int i=2;i<=n;i++)mb=min(mb,B[i]);
		if(ma+mb<0){
			puts("No");
			return;
		}else if(ma<0)for(int i=1;i<=n;i++)A[i]-=ma,B[i]+=ma;
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++){
				// printf("D[%d][%d]=%d\n",i,j,A[i]+B[j]);
				if(C[i][j]!=A[i]+B[j]){
					puts("No");
					return;
				}
			}
		puts("Yes");
		for(int i=1;i<=n;i++)
			printf("%d ",A[i]);
		puts("");
		for(int i=1;i<=n;i++)
			printf("%d ",B[i]);
	}
}
bool mmp2;
int main() {
//	srand(time(0));
//	printf("%.6fMB\n",(&mmp2-&mmp1)/1024.0/1024);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	P100::solve();
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define length size()
#define int long long
#define ll long long
#include <cstdint>
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    if(n==0) return 0;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
const int MOD = 1000000007;
const int mod = 998244353;
const int MAX = 510000;
const int inf = 400000000000000;
template<typename T> string join(vector<T> &vec ,const string &sp){
    int si = vec.length;
    if(si==0){
        return "";
    }else{
        stringstream ss;
        rep(i,si-1){
            ss << vec[i] << sp;
        }
        ss << vec[si - 1];
        return ss.str();
    }
}
vector<vector<int>> ruiseki2d(vector<vector<int>> vec){
    rep(i,vec.size()-1){
        rep(j,vec[0].size()-1){
            vec[i+1][j+1] = vec[i][j+1]+vec[i+1][j]-vec[i][j]+vec[i+1][j+1];
        }
    }
    return vec;
}
class CompareDist
{
public:
    bool operator()(pair<int,int> p,pair<int,int>q){
    return p.second > q.second;
}
};
int ctoi(const char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return -1;
  }
}
vector<int> dijkstra(vector<vector<pair<int,int>>> vec,int s){
    priority_queue<pair<int,int>,vector<pair<int,int>>,CompareDist> que;
    pair<int,int> f = make_pair(s,0);//point,cost;
    que.push(f);
    bool y = false;
    vector<int> cost(vec.size(),inf);
    while(!que.empty()){
        pair<int,int> tmp = que.top();
        que.pop();
        int p = tmp.first;
        int c = tmp.second;
        if(cost[p]>c){
        cost[p] = c;
        rep(i,vec[p].size()){
            if(cost[vec[p][i].first]<=inf){
            tmp = make_pair(vec[p][i].first,vec[p][i].second+c);
            que.push(tmp);
            }
        }
        }
        if(!y) cost[p] = inf;
        y = true;
    }
    return cost;
}
signed main(void){
    int n;
    cin >> n;
    vector<vector<int>> vec(n,vector<int>(n));
    rep(i,n){
        rep(j,n){
            cin >> vec[i][j];
        }
    }
    vector<int> vx(n,0);
    vector<int> vy(n,0);
    bool flag = false;
    rep(i,n-1){
        int t = vec[0][i+1]-vec[0][i];
        rep(j,n-1){
            if(vec[j+1][i+1]-vec[j+1][i]!=t)  flag = true;
        }
        vx[i+1] = t;

    }
    rep(i,n-1){
        int t = vec[i+1][0]-vec[i][0];
      //  cout << t << " ";
        rep(j,n-1){
            if(vec[i+1][j+1]-vec[i][j+1]!=t)  flag = true;
        }
        vy[i+1] = t;
    }
    rep(i,n-1){
        vx[i+1] += vx[i];
        vy[i+1] += vy[i];
    }
   // cout << join(vx," ") << endl;
   // cout << join(vy," ") << endl;

    if(flag) cout << "No" << endl;
    else{
        //cout << "Yes" << endl;
        int xm = *min_element(vx.begin(),vx.end());
        int ym = *min_element(vy.begin(),vy.end());
        xm *= -1;
        ym *= -1;
       // cout << xm << " " << ym << endl;
        rep(i,n){
            vx[i] += xm;
            vy[i] += ym;
        }
         //   cout << join(vx," ") << endl;
          //  cout << join(vy," ") << endl;
        if(vx[0]+vy[0]>vec[0][0]){cout << "No" << endl;}
        else{
            int k = (vec[0][0]-(vx[0]+vy[0]));
            rep(i,n){
                vx[i] += k;
            }
            cout << "Yes" << endl;
            cout << join(vy," ") << endl;
            cout << join(vx," ") << endl;
        }
    }

}


    #include<bits/stdc++.h>
    using namespace std ;
    #define ll long long int
    #define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
    #define DISPLAY(V)  for(auto it : V)  {   cout<<it<<" " ;} cout<<endl;
    #define DISPLAY2(V)  for(auto it : V) { for (auto val : it) { cout<<val<<" ";} cout<<endl;}
    #define MOD 1000000007
    #define see(x) cout<<#x<< " = "<<x<<endl;
    #define seep(x) cout<<#x<<" = "<<"["<<x.first<<","<<x.second<<"]"<<endl;

    inline int add(int a,int b){a+=b;if(a>=MOD)a-=MOD;return a;}
    inline int mul(int a,int b){return (a*1ll*b)%MOD;}
    inline int power(int a,int b){int rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}

    void solve()
    {
        ll n ;
        cin>>n ;
        if(n%4==2)
        {
            cout<<"Same\n" ;
        }
        else if(n%2==0) cout<<"Even\n";
        else cout<<"Odd\n" ;

    }

    int main()
    {
        fast ;
        ll t = 1;
        cin>>t;

        for(ll i = 1 ;i<=t; ++i)
        {
            solve();
        }
        return 0 ;
    }

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

int main(){

  long long int t;
  cin>>t;
  while(t--)
  {
    long long int n;
    cin>>n;
    if(n%2!=0)
      cout<<"Odd"<<"\n";
    else if(n%4==0)
    {
      cout<<"Even"<<"\n";
    }
    else
      cout<<"Same"<<"\n";

  }
return 0;
}


//a.9
#include<bits/stdc++.h>
#define ll long long
#define all(x) x.begin(),x.end()
#define CASE(t) cout<<"Case #"<<(t)<<": ";
#define endll endl
#define endl '\n'
#define mod 1000000007
#define INF 1e18
#define maxN 500005
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;
ll ceill(ll a,ll b){return a/b+bool(a%b);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b, a % b);}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
ll power(ll x,ll y){ll res=1;while(y>0){if(y&1)res=(res*x)%mod;x=(x*x)%mod;y>>=1;}return res;}
bool isPrime(ll n)
{
    if(n<=1)return false;if(n<=3)return true;if(n%2==0 || n%3==0)return false;
    for(ll i=5;i*i<=n;i=i+6)if(n%i==0 || n%(i+2)==0) return false; return true;
}
void primeFactors(ll n, vector<ll> &vec)
{
    while(n%2==0)vec.push_back(2),n/=2;
    for(ll i=3;i<=sqrt(n);i+=2)while(n%i==0)vec.push_back(i),n/=i;
    if(n>2)vec.push_back(n);
}
//vector<ll>fact(maxN);
//void factpre(){fact[0]=1;for(ll i=1;i<maxN;i++)fact[i]=(fact[i-1]*1LL*i);}
//ll mul(ll a,ll b){return (a*1LL*b)%mod;}
//ll nCr(ll n,ll k){return mul(fact[n],power(mul(fact[k],fact[n-k]),mod-2));}
void solve()
{
    char a,b,c;cin>>a>>b>>c;
    cout<<b<<c<<a<<endl;
}
signed main()
{
    ios;
    ll tc=1; //cin>>tc;
    for(ll TTT=1;TTT<=tc;TTT++)
    {
        //CASE(TTT);
        solve();
    }
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define FOR(i, a, b) for(ll i=(a); i < (ll)(b); ++i)
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;}

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

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define vll vector<long long>
#define mll map<long long,long long>
#define pll pair<long long,long long>
#define pb push_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define FAST  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 998244353
typedef  long long ll;
typedef long double ld;
long double pi=3.14159265358979323846;

vll al[300005];
ll I[101][101];

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

bool isPrime(int n)
{
    if (n<=1) return false;
    if (n<=3) return true;
    if (n%2==0||n%3==0) return false;
    for (int i=5;i*i<=n;i=i+6) if (n%i==0||n%(i+2)==0) return false;
    return true;
}

ll bpow(ll n, ll po)
{
	ll res=1;
	while(po>0)
	{
		if(po%2)
		{
			res=(res*n)%mod;
			po--;
		}
		else
		{
			n=(n*n)%mod;
			po/=2;
		}
	}
	return res;
}

void swap(ll *a, ll *b)
{
	ll temp=*a;
	*a=*b;
	*b=temp;
}

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

ll modInverse(ll n,ll p)
{
	return bpow(n,p-2);
}

ll fac[300001];

ll nCr(ll n,ll r)
{
    if (r == 0) return 1;
    return (fac[n] * modInverse(fac[r], mod) % mod * modInverse(fac[n - r], mod) % mod) % mod;
}

//bool bipartite_dfs(ll node, ll flag)
//{
//	vis[node]=1;
//	ll cflag=flag;
//	color[node]=cflag;
//	for(ll child : al[node])
//	{
//		if(!vis[child])
//		{
//			bool n=bipartite_dfs(child,1-cflag);
//			if(n==false) return false;
//		}
//		else if(color[child]==color[node]) return false;
//	}
//	return true;
//}

void mmul(ll A[][101], ll B[][101], ll dim)
{
	ll res[dim][dim];
	for(ll i=0;i<dim;i++) for(ll j=0;j<dim;j++)
	{
		res[i][j]=0;
		for(ll k=0;k<dim;k++) res[i][j]=(res[i][j]+A[i][k]*B[k][j])%1000000007;
	}
	for(ll i=0;i<dim;i++) for(ll j=0;j<dim;j++) A[i][j]=res[i][j];
}

void mpow(ll A[][101],ll dim, ll po)
{
	for(ll i=0;i<dim;i++) for(ll j=0;j<dim;j++)
	{
		if(i==j) I[i][j]=1;
		else I[i][j]=0;
	}
	while(po>0)
	{
		if(po%2==1)
		{
			mmul(I,A,dim);
			po--;
		}
		else
		{
			mmul(A,A,dim);
			po/=2;
		}
	}
	for(ll i=0;i<dim;i++) for(ll j=0;j<dim;j++) A[i][j]=I[i][j];
}

ll b[200001],vis[200001];

ll dfs(ll node){
	vis[node]=1;
	ll ret=1;
	for(ll i=0;i<al[node].size();i++){
		ll child=al[node][i];
		if(!vis[child]){
			ret+=dfs(child);
		}
	}
	return ret;
}

int main()
{
	FAST
//	freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
	ll testcases=1;
//	cin>>testcases;
//	fac[0]=1;
//	for(ll i=1;i<300001;i++) fac[i]=(fac[i-1]*i)%mod;
	while(testcases--)
	{
		ll n;
		cin>>n;
		ll a[n];
		for(ll i=0;i<n;i++) cin>>a[i];
		for(ll i=0;i<n;i++){
			ll x=a[i],y=a[n-1-i];
			if(x!=y) al[x].pb(y);
		}
		for(ll i=0;i<n;i++) b[a[i]]++;
		ll ans=0;
		for(ll i=1;i<=200000;i++) if(!vis[i]) ans+=dfs(i)-1;
		cout<<ans;
	}
}

// Problem : D - KAIBUNsyo
// Contest : AtCoder - AtCoder Beginner Contest 206（Sponsored by Panasonic）
// URL : https://atcoder.jp/contests/abc206/tasks/abc206_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
using namespace std;
/* DEBUGGING */
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
/* MACROS */
typedef long long int ll;

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

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

typedef map<int,int> mii;
typedef tuple<int,int,int> tup;

#define  ff          first
#define  ss          second
#define  pb          push_back
#define  IOS         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define  lb          lower_bound
#define  ub          upper_bound
#define  all(x)      (x).begin(), (x).end()
#define  sz(x)       (x).size()
#define  lcm(x, y)   ((x) * (y) / __gcd(x, y))
#define  ps(x,y)     fixed<<setprecision(y)<<x
#define  setbit(x)   __builtin_popcountll(x)
#define  rep(i,a,b)  for(int i=a ; i<b ; ++i)
#define  repr(i,a,b) for(int i=a ; i>=b ; --i)

/* CONSTANTS */
#define PI 3.141592653589793
const ll MOD = 1e9 + 7;
const ll INF = 1000000000;
const ll MAX_N = 2e5 + 2;

vi adj[MAX_N],vis(MAX_N);
int sz;

void dfs(int node){
    vis[node] = 1;
    sz++;

    for(auto x:adj[node]){
        if(!vis[x]){
            dfs(x);
        }
    }
}

void solve(){
    int n; cin >> n;
    set<int>s;
    fill(all(vis) , 0);

    vi v(n);
    rep(i,0,n) cin >> v[i], s.insert(v[i]);

    int ans = 0;

    rep(i,0,n){
        if(v[i]!=v[n-i-1]){
            adj[v[i]].pb(v[n-i-1]);
            adj[v[n-i-1]].pb(v[i]);
        }
    }

    rep(i,1,MAX_N){
        if(!vis[i]){
            sz = 0;
            dfs(i);
            ans+=(sz-1);
        }
    }

    cout << min(ans , (int)s.size());
}

int main(){
    IOS;
    solve();
}


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

typedef long long ll;

typedef   vector<ll>  vi;
typedef   vector<pair<ll, ll> > vii;
typedef   pair<ll,ll> pii;
typedef   multiset<pair<ll, ll> > msii;
typedef   multiset<ll> msi;
typedef   set<pair<ll, ll> > sii;
typedef   set<ll> si;
typedef   map<ll, ll> mii;

#define boost 	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define for1(x, a, b)  for(x=a; x<b; x++)
#define for2(x, a, b)  for(x=a, x>=b; x--)
//#define endl 	"\n"
#define all(x)  x.begin(), x.end()
#define p       pair
#define mp      make_pair
#define read    freopen("input.txt","r",stdin)
#define write   freopen("output.txt","w",stdout)
#define pb      push_back
#define ff      first
#define ss      second
#define bb      begin
#define arr_ub(arr, n, x) upper_bound(arr, arr+n, x)-arr
#define arr_lb(arr, n, x) lower_bound(arr, arr+n, x)-arr
#define u_p(v, x) upper_bound(v.begin(), v.end(), x)-v.begin()
#define l_b(v, x) lower_bound(v.begin(), v.end(), x)-v.begin()

const ll sz=1e6+123;
#define INF 1000000000000000007
#define MOD 1000000007
#define stringLen 18446744073709551620
#define pi 3.1415926536

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll n;

int main(){

    cin >> n;
    vector<vector<ll>> T(n, vector<ll>(3)); //l, r, t
    for(int i=0; i<n; ++i){
        vector<ll> tmp(3);
        cin >> tmp[2] >> tmp[0] >> tmp[1];
        T[i] = tmp;
    }

    sort(all(T), [](const vector<ll>& a, const vector<ll>& b){
        return a[0] < b[0];
    });

    ll ans = 0;
    for(int i=0; i<n-1; ++i){
        int j= i+1;
        while(( T[i][1] >= T[j][0]  || T[i][0] == T[j][0] )&& j<n){
            // if (T[i][0] == T[j][0]){
            //     if(T[i][2]==3 || T[i][2]==4 || T[j][2] == 3 || T[j][2] == 4) {
            //         j++;
            //         continue;
            //     }
            // }
            if (T[i][1] == T[j][0]){
                if(T[i][2]==2 || T[i][2]==4 || T[j][2] == 3 || T[j][2] == 4) {
                    j++;
                    if(j >= n){
                        break;
                    }
                    continue;
                }
            }
            ans++;
            j++;
            if(j>=n){
                break;
            }
        }
    }
    cout << ans;

    return 0;
}

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

int main()
{
    int N; cin >> N;
    double l[N], r[N];

    for (int i = 0; i < N; i++)
    {
        int t; cin >> t >> l[i] >> r[i];
        t--;
        if (t & 1) r[i] -= 0.5;
        if (t & 2) l[i] += 0.5;
    }
    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        for (int j = i + 1; j < N; j++)
        {
            ans += (max(l[i], l[j]) <= min(r[i], r[j]));
        }
    }

    cout << ans << '\n';
    return 0;
}


#include <iostream>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;

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

	int n; cin >> n;
	vector<ll> r, g, b;
	for (int i = 0; i < 2 * n; i++) {
		ll a; char c; cin >> a >> c;
		if (c == 'R') { r.push_back(a); }
		else if (c == 'G') { g.push_back(a); }
		else { b.push_back(a); }
	}

	vector<ll> v1, v2, v3;
	if (r.size() % 2 && g.size() % 2) { v1 = r; v2 = g; v3 = b; }
	else if (r.size() % 2 && b.size() % 2) { v1 = r; v2 = b; v3 = g; }
	else if (g.size() % 2 && b.size() % 2) { v1 = g; v2 = b; v3 = r; }
	else { cout << 0 << '\n'; return 0; }

	sort(v1.begin(), v1.end());
	sort(v2.begin(), v2.end());
	sort(v3.begin(), v3.end());

	ll ans = 1e16;
	ll min12 = 1e16, min13 = 1e16, min23 = 1e16;

	for (int i = 0; i < v1.size(); i++) {
		int cur = lower_bound(v2.begin(), v2.end(), v1[i]) - v2.begin();
		if (cur < v2.size()) { min12 = min(min12, v2[cur] - v1[i]); }
		if (cur > 0) { min12 = min(min12, v1[i] - v2[cur - 1]); }
	}
	for (int i = 0; i < v1.size(); i++) {
		int cur = lower_bound(v3.begin(), v3.end(), v1[i]) - v3.begin();
		if (cur < v3.size()) { min13 = min(min13, v3[cur] - v1[i]); }
		if (cur > 0) { min13 = min(min13, v1[i] - v3[cur - 1]); }
	}
	for (int i = 0; i < v2.size(); i++) {
		int cur = lower_bound(v3.begin(), v3.end(), v2[i]) - v3.begin();
		if (cur < v3.size()) { min23 = min(min23, v3[cur] - v2[i]); }
		if (cur > 0) { min23 = min(min23, v2[i] - v3[cur - 1]); }
	}

	ans = min(min12, min13 + min23);
	cout << ans << '\n';
}

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

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

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

template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <typename T> void coutall(T v) { if(v.empty()){cout << endl; return;} for(auto i = v.begin(); i != --v.end(); i++){cout << *i << " ";} cout << *--v.end() << endl; }
template <typename T> void DEBUGall(T v) { if(v.empty()){cerr << endl; return;} for(auto i = v.begin(); i != --v.end(); i++){cerr << *i << " ";} cerr << *--v.end() << endl; }
inline void IN(void){ return; }
template <typename First, typename... Rest> void IN(First& first, Rest&... rest){ cin >> first; IN(rest...); return; }
inline void OUT(void){ cout << "\n"; return; }
template <typename First, typename... Rest> void OUT(First first, Rest... rest){ cout << first << " "; OUT(rest...); return; }
inline void DEBUG(void){ cerr << "\n"; return; }
template <typename First, typename... Rest> void DEBUG(First first, Rest... rest){ cerr << first << " "; DEBUG(rest...); return; }

void yes(bool ok = true){ cout << (ok ? "yes" : "no") << endl; }
void Yes(bool ok = true){ cout << (ok ? "Yes" : "No") << endl; }
void YES(bool ok = true){ cout << (ok ? "YES" : "NO") << endl; }
ll myceil(ll a, ll b) { return a >= 0 ? (a+b-1)/b : -((-a)/b); }
ll myfloor(ll a, ll b) { return a >= 0 ? a/b : -myceil(-a, b); }

const ll INF = 1002003004005006001;
void Main(){
    int n; IN(n);
    vector<vll> v(3);
    rep(i, n*2) {
        ll a; char c;
        IN(a, c);
        if(c == 'R') v[0].pb(a);
        if(c == 'G') v[1].pb(a);
        if(c == 'B') v[2].pb(a);
    }

    if(v[0].size() % 2 == 0 && v[1].size() % 2 == 0 & v[2].size() % 2 == 0){
        OUT(0);
        return;
    }

    if(v[1].size() % 2 == 0) swap(v[0], v[1]);
    else if(v[2].size() % 2 == 0) swap(v[0], v[2]);
    rep(i, 3) sort(all(v[i]));
    /*
    DEBUGall(v[0]);
    DEBUGall(v[1]);
    DEBUGall(v[2]);
    */

    // v[0]: even, v[1], v[2]: odd

    auto f = [&](vll a, vll b){
        ll res = INF, ans = INF;
        for(auto x : a){
            auto it = upper_bound(all(b), x);
            if(it != b.end()){
                if(chmin(res, abs(x-*it))) ans = x;
            }
            if(it != b.begin()){
                it--;
                if(chmin(res, abs(x-*it))) ans = x;
            }
        }
        return Pll{res, ans};
    };

    auto [r1, a1] = f(v[1], v[2]);
    auto [r2, a2] = f(v[0], v[1]);
    auto [r3, a3] = f(v[0], v[2]);

    /*
    DEBUG(r1, a1);
    DEBUG(r2, a2);
    DEBUG(r3, a3);
    */

    if(a2 != a3 || a2 == INF){
        OUT(min(r1, r2 + r3));
        return;
    }

    vll w = v[0];
    w.erase(find(all(w), a2));
    auto [r4, a4] = f(w, v[1]);
    auto [r5, a5] = f(w, v[2]);

    ll ANS = min(r3 + r4, r2 + r5);
    OUT(min(r1, ANS));
    return;
}

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