#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cfenv>
#include <cmath>
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) a.begin(),a.end()
#define P pair<long,long>
#define INF 10000000000000000
#define EX 100000000000000000
using namespace std;

struct edge{long to,cost,k;};

int main() {
  int N;cin>>N;
  vector<long> a(N);
  vector<long> t(N);
  rep(i,N)cin>>a[i]>>t[i];
  int Q;cin>>Q;
  vector<long> x(Q);
  rep(i,Q)cin>>x[i];

  long U=INF;
  long M=0;
  long D=-INF;

  rep(i,N){
    long A=a[N-i-1],T=t[N-i-1];
    if(T==1){
      D-=A;U-=A;M+=A;
    }
    if(T==2){
      if(A>D)D=A;
      if(D>U)D=U;
    }
    if(T==3){
      if(A<U)U=A;
      if(D>U)U=D;
    }
  }
  rep(i,Q){
    if(x[i]<D)cout<<D+M<<endl;
    else if(x[i]>U)cout<<U+M<<endl;
    else cout<<x[i]+M<<endl;
  }
}

#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
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.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
#define SZ(x) (int)((x).size())
template <typename T> static constexpr T inf = numeric_limits<T>::max() / 2;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

int main() {
  int cas;
  cin >> cas;
  while (cas--) {
    int n;
    cin >> n;
    string A, B, C;
    cin >> A >> B >> C;
    cout << string(n, '1') + string(n, '0') + "1" << '\n';
  }

  return 0;
}


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

// 小数点以下桁数
// fixed << setprecision(i)

int64_t gcd(int64_t a,int64_t b){return (a%b==0?b:gcd(b, a%b));}
int64_t lcm(int a,int b){return (int64_t)a*b/gcd(a, b);}
int factorial(int a){int b=1;while(a){b*=a--;}return b;} //13以下対応
bool is_prime(int a){if(a<=1)return false;for(int i=2;(int64_t)i*i<=a;i++){if(a%i==0)return false;}return true;}
int get_adp(double x, int n){return (int)round((x-(int)x)*pow(10,n))%10;} // 小数点以下の指定桁の値を取得
int64_t sigma(int64_t s, int64_t n){return n*(2*s+n-1)/2;}

//順列の全列挙
// vector<int> v(N);
// iota(v.begin(), v.end(), 1);       // v に 1, 2, ... N を設定
// do {
//	for(auto x : v) cout << x << " "; cout << "\n";     // v の要素を表示
// } while( next_permutation(v.begin(), v.end()) );

//bit全探索
// for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
//	bitset<ビット数> s(tmp);
//	// (ビット列sに対する処理)
// }

int main()
{
	int n, ans;
	vector<int> a(100000);
	vector<int> b(100000);

	ans = 0;
	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	for (int i = 0; i < n; ++i)
		cin >> b[i];
	for (int i = 0; i < n; ++i)
		ans += a[i] * b[i];
	cout << (ans == 0 ? "Yes" : "No") << endl;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(ll i = (ll)a; i <= (ll)b; i++)
#define DEC(i, a, b) for(ll i = (ll)a; i >= (ll)b; i--)
typedef pair<ll, ll> pi;
typedef pair<pi, ll> pii;
typedef pair<ll, pi> ipi;
typedef pair<pi, pi> pipi;
#define mp make_pair
#define f first
#define s second
typedef vector<ll> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define size(v) (ll) v.size()
#define disc(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
#define INF (ll) (1e9 + 100)
#define LLINF (ll) 1e18
#define mod (const ll) (1e9 + 7)
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sandybridge __attribute__((optimize("Ofast"), target("arch=sandybridge")))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusive

ll n, a[100005], b, ans;

int main() {
	fastio; cin >> n;
  FOR(i, 1, n) cin >> a[i];
  FOR(i, 1, n) {
    cin >> b;
    ans += b * a[i];
  }
  cout << (ans == 0 ? "Yes" : "No");
}


#include<bits/stdc++.h>
using namespace std;
int N,M;
int P[51][51];
int main(void)
{
	register int i,j;
	cin>>N>>M;
	for(i=1;i<=50;i++)for(j=1;j<=50;j++)cin>>P[i][j];
	N++,M++;
	if(M>1&&P[N][M-1]!=P[N][M])cout<<"L"<<endl,exit(0);
	if(M<50&&P[N][M+1]!=P[N][M])cout<<"R"<<endl,exit(0);
	if(N>1&&P[N-1][M]!=P[N][M])cout<<"U"<<endl,exit(0);
	if(N<50&&P[N+1][M]!=P[N][M])cout<<"D"<<endl,exit(0);
	cout<<"D"<<endl;
	return 0;
}

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

using P = pair<int, int>;
using B = bitset<2500>;

struct dat {
  B b;
  int x, y;
  dat(int _x = 0, int _y = 0, B _b = B()) : b(_b), x(_x), y(_y) {}
  bool operator<(const dat r) const {
    if (x != r.x) return x < r.x;
    if (y != r.y) return y < r.y;
    for (int i = 0; i < 2500; ++i)
      if (b[i] != r.b[i]) return b[i];
    return 0;
  }
};

using node = pair<int, dat>;

const int n = 50;
int d[4] = {0, 1, 0, -1};
string dir = "RDLU";
vector<vector<int>> t, p;
P st;
map<dat, int> dp;
map<dat, string> memo;

string solve();
bool isvalid(int x, int y) { return x >= 0 && x < n && y >= 0 && y < n; }

int main() {
  cin >> st.first >> st.second;
  t.resize(n);
  for (auto& v : t) {
    v.resize(n);
    for (auto& x : v) cin >> x;
  }
  p.resize(n);
  for (auto& v : p) {
    v.resize(n);
    for (auto& x : v) cin >> x;
  }
  cout << solve() << endl;
  return 0;
}

string solve() {
  vector<node> v;
  string ress;
  int resp;
  {  // make start node
    B stb;
    stb[t[st.first][st.second]] = 1;
    dat stdat(st.first, st.second, stb);
    resp = dp[stdat] = p[st.first][st.second];
    memo[stdat] = "";
    v.push_back(node(dp[stdat], stdat));
  }
  auto start = chrono::system_clock::now();
  auto nowt = chrono::system_clock::now();
  auto dur = nowt - start;
  auto msec = chrono::duration_cast<chrono::milliseconds>(dur).count();
  int cnt = 0;
  vector<int> did = {0, 1, 2, 3};
  {
    vector<int> dists = {49 - st.second, 49 - st.first, st.second, st.first};
    sort(did.begin(), did.end(),
         [&](int l, int r) { return dists[l] > dists[r]; });
  }
  int bf = resp, nch = 0;
  while (v.size() && msec < LIMTIME) {
    {
      if (bf == resp) {
        if (++nch >= 300) {
          int len = max(1, (int)v.size() / 2);
          while (v.size() > len) v.pop_back();
          nch = -1e8;
        }
      } else
        nch = 0, bf = resp;
    }
    // cerr << cnt++ << " " << resp << " " << v.size() << " " << msec << endl;
    const auto [score, now] = v.back();
    v.pop_back();
    string s = memo[now];
    if (score != dp[now]) continue;
    for (int i : did) {
      int tx = now.x + d[i], ty = now.y + d[1 ^ i];
      if (!isvalid(tx, ty)) continue;
      int id = t[tx][ty], tscore = score + p[tx][ty];
      if (now.b[id]) continue;
      // pushed = 1;
      dat to(tx, ty, now.b);
      to.b[id] = 1;
      if (dp.count(to) && dp[to] >= tscore) continue;
      dp[to] = tscore;
      memo[to] = s + dir[i];
      v.push_back(node(tscore, to));
      if (resp < tscore) resp = tscore, ress = memo[to];
    }
    nowt = chrono::system_clock::now();
    dur = nowt - start;
    msec = chrono::duration_cast<chrono::milliseconds>(dur).count();
  }
  cerr << cnt << " " << v.size() << " " << resp << endl;
  return ress;
}


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

void solve(){

	int H, W; cin>>H>>W;
	//set<int> s;
	int a[H][W];
	int sum[10001] = {0};
	int chk = 1;
	for(int i = 0; i<H; i++){
		string S; cin>>S;
		for(int j = 0; j<W; j++){
			if(S[j]=='R'){
				if(sum[i+j]!=0&&sum[i+j]!=1) chk = 0;
				else sum[i+j] = 1;
			}
			else if(S[j]=='B'){
				if(sum[i+j]!=0&&sum[i+j]!=-1) chk = 0;
				else sum[i+j] = -1;
			}
		}
	}
	if(!chk){
		cout<<0;
		return;
	}
	int ans = 1;
	for(int i = 0; i<H+W-1; i++){
		if(sum[i]==0){
			ans*=2;
			ans%=mod;
		}
	}
	cout<<ans<<'\n';

}

int main(){

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 // ONLINE_JUDGE

 //int t; cin>>t;
 int t = 1;
 for(int i =0 ; i<t; i++)
	solve();
return 0;

}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<ll>>;
struct UnionFind{
  vector<ll> par,siz;
  UnionFind(int n):par(n,-1),siz(n,1){}

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

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

  bool unite(ll x,ll 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;
  }
  ll size(int x){
    return siz[root(x)];
  }
};

int main(){
  ll N;
  cin >> N;
  vector<ll>A(N);
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  UnionFind uf(201010);
  for(int i=0;i<N/2;i++){
    uf.unite(A[i],A[N-i-1]);
  }
  int ans=0;
  for(int i=0;i<201010;i++){
    if(uf.root(i)==i) ans+= uf.size(i)-1;
  }
  cout << ans;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

struct union_find {
    vector<int> par, siz;
    union_find(int n) {
        par.resize(n);
        siz.resize(n);
        for(int i = 0; i < n; i++){
            par[i] = i;
            siz[i] = 1;
        }
    }

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

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

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

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

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

    ll n; cin >> n;
    ll a[n]; zep(i, 0, n)cin >> a[i];

    union_find u(2e5 + 100);
    ll ans = 0;
    zep(i, 0, n / 2){
        if(!u.same(a[i], a[n - 1 - i])){
            ans++;
            u.unite(a[i], a[n - 1 - i]);
        }
    }
    print(ans)

    return 0;
}


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

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

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

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

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

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

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

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

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
using namespace std;
const long double eps = 1e-6;

int read(){
	int x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	return x*f;
}

int k,m,n;
struct node{
	int x,y;
	int zx,zd;
}a[110];
int fa[110];
int find(int x){if(x==fa[x])return x;return fa[x]=find(fa[x]);}
long double dis(int x,int y){return sqrt((a[x].x-a[y].x)*(a[x].x-a[y].x)+(a[x].y-a[y].y)*(a[x].y-a[y].y));}
bool check(long double mid){
	for(int i=1;i<=n;i++){
		fa[i]=i;
		a[i].zx=100;a[i].zd=-100;
	}
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			if(dis(i,j)<=mid)fa[find(i)]=fa[find(j)];
		}
	}
	for(int i=1;i<=n;i++){
		int x=find(i);
		a[x].zx=min(a[x].zx,a[i].y);
		a[x].zd=max(a[x].zd,a[i].y);
	}
	for(int i=1;i<=n;i++){
		if(i==find(i)){
			//cout<<i<<" "<<a[i].zx<<" "<<a[i].zd<<" "<<mid<<endl;
			if(a[i].zx+100<=mid && 100-a[i].zd<=mid)return false;
		}
	}
	return true;
}
int main(){
	n=read();
	for(int i=1;i<=n;i++){
		a[i].x=read();a[i].y=read();
	}
	long double l=0,r=200,ans=0;
	while(l+eps<=r){
		long double mid=(l+r)/2;
		if(check(mid)){ans=r;l=mid;}
		else r=mid;
	}
	printf("%.6Lf\n",ans/2);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int N,c,z;
vector<vector<int>> adj(105), tc(105, vector<int>(105));

void dfs(int u, int s) {
    tc[s][u] = true;
    //if (s == 1) cout << u << "\n";
    for (int v: adj[u]) {
    //    if (u == 1) cout << v << " ";
        if (!tc[s][v]) dfs(v,s);
    }
}

int main() {

    cin >> N;

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            char c;
            cin >> c;
            if (c=='1') {
                adj[i].push_back(j);
            }
        }
    }

    for (int i = 0; i < N; i++) {
        dfs(i, i);
    }

    double res = 0;

    for (int i = 0; i < N; i++) {
        int c = 0;
        for (int j = 0; j < N; j++) {
            if (tc[j][i]) {
              //  cout << j << " " << i << "\n";
                c++;
            }
        }
        res += 1.0/c;;
    }

    cout << setprecision(15) << res << "\n";

    return 0;
}

#include <bits/stdc++.h>

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define rep(i,n) repi(i,0,n)
#define repi(i,a,n) for(ll i = a;i < (ll)n;++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SHOW(str,val) cout<<(str)<<" : "<<(val)<<endl;

using namespace std;
using ll = long long;
using P = pair<ll, ll>;
// using P = pair<int, int>;
void YN(bool a) { cout << (a ? "Yes" : "No"); }
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;}

// 最大公約数 : 3,4 ->  1
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

void solve()
{
  ll n, a;
  cin >> n;
  ll ans = 0;
  for(int i = 0; i < n; ++i)
  {
    cin >> a;
    ans = gcd(ans, a);
  }

  cout << ans;
}

int main()
{
  fastio;
  solve();

  return 0;
}


#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <map>
#include <vector>
#include <queue>
#include <cmath>

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

int main()
{
    ll s,p;
    cin>>s>>p;

    for(ll i=1; i<=sqrt(p); i++)
    {
        if(p%i==0)
        {
            if(i+p/i==s){ cout<<"Yes"<<endl; return 0; }
        }
    }
    cout<<"No"<<endl;
    return 0;
}

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

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

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

int main2() {
  ll S = nextLong();
  ll P = nextLong();

  for (ll a = 1; a * a <= P; a++) {
    if (P % a == 0) {
      ll b = P / a;
      if (a + b == S) {
        return 1;
      }
    }
  }
  return 0;
}

int main() {

  bool ans = main2();
  cout << (ans ? "Yes":"No") << endl;

  return 0;
}


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

int main(){
  int n; cin >> n;
  vector<int> a;

  long long ans = 1;
  for(long long i = 1; i <= n; ++i){
    string s; cin >> s;
    if(s == "OR"){ans += (long long)pow(2, i);}
  }
  cout << ans << endl;
}

#include <cstring>
#include <iostream>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
int n;
ll dp[100][2] = { 0 };
int main()
{
    cin >> n;
    vector<string> s(n, "");
    for (int i = 0; i < n; ++i) {
        cin >> s[i];
    }
    dp[0][0] = dp[0][1] = 1;
    for (int i = 1; i <= n; ++i) {
        if (s[i - 1] == "AND") {
            dp[i][1] = dp[i - 1][1];
            dp[i][0] = dp[i - 1][1] + dp[i - 1][0] * 2;
        } else {
            dp[i][0] = dp[i - 1][0];
            dp[i][1] = dp[i - 1][1] * 2 + dp[i - 1][0];
        }
    }
    cout << dp[n][1] << endl;
    return 0;
}


#pragma GCC optimize(2)
#pragma GCC optimize(3,"Ofast","inline")
#include <bits/stdc++.h>
#define inf 0x7fffffff
//#define ll long long
#define int long long
//#define double long double
#define re register int
#define void inline void
#define eps 1e-8
//#define mod 1e9+7
#define ls(p) p<<1
#define rs(p) p<<1|1
#define pi acos(-1.0)
#define pb push_back
#define P pair < int , int >
using namespace std;
const int mod=998244353;
const int M=5e6;
const int N=2*1e5+5;//?????????? 4e8
int n,m;
char s[505][505];
int ans,flag;
int op,ret;
int power(int a,int b)
{
	int sum=1;
	while(b)
	{
		if(b&1)  sum=sum*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return sum;
}
void solve()
{
	cin>>n>>m;
	for(re i=1;i<=n;i++)  scanf("%s",s[i]+1);
//	for(re i=1;i<=n;i++)  for(re j=1;j<=m;j++)  if(s[i][j]=='.')  op=1;
//	if(!op)  ans++;
	for(re i=1;i<=n;i++)
	{
		int x=i,y=1;
		int red=0,blue=0,cnt=0;
		while(x>=1&&y<=m)
		{
			if(s[x][y]=='.')  cnt++;
			if(s[x][y]=='R')  red=1;
			if(s[x][y]=='B')  blue=1;
			x--,y++;
		}
		if(red==1&&blue==1)  flag=1;
		else if((red==1&&blue==0)||(red==0&&blue==1))
		{

//			if(cnt)  ans=(ans+1)%mod;
		}
		else
		{
			if(cnt)  ret++;
		}
	}
	for(re i=1;i<=m;i++)
	{
		if(i==1)  continue;
		int x=n,y=i;
		int red=0,blue=0,cnt=0;
		while(x>=1&&y<=m)
		{
			if(s[x][y]=='.')  cnt++;
			if(s[x][y]=='R')  red=1;
			if(s[x][y]=='B')  blue=1;
			x--,y++;
		}
		if(red==1&&blue==1)  flag=1;
		else if((red==1&&blue==0)||(red==0&&blue==1))
		{
//			if(cnt)  ans=(ans+1)%mod;
		}
		else
		{
			if(cnt)  ret++;
		}
	}
	ans=(ans+power(2,ret))%mod;
	if(flag)  ans=0;
	cout<<ans<<endl;
}
signed main()
{
    int T=1;
//    cin>>T;
    for(int index=1;index<=T;index++)
    {
        solve();
//        puts("");
    }
    return 0;
}
/*

#((((#

*/

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vc = vector<T>;
template<class T> using vvc = vc<vc<T>>;
template<class T> using vvvc = vc<vvc<T>>;
template<class T> using vvvvc = vvc<vvc<T>>;
template<class T> using PQ = priority_queue<T>;
template<class T> using invPQ = priority_queue<T, vector<T>, greater<T>>;
using IP = pair<int, int>;
using LP = pair<ll, ll>;
#define all(x) begin(x), end(x)
#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 = (n) - 1; (i) >= 0; i--)
#define rep3r(i, m, n) for (int i = (n) - 1; (i) >= (int)(m); 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; }
constexpr int INF = 1070000000;

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

    int R, C;
    cin >> R >> C;
    vvc<int> A(R, vc<int>(C-1)), B(R-1, vc<int>(C));
    rep (i, R) rep (j, C-1) cin >> A[i][j];
    rep (i, R-1) rep (j, C) cin >> B[i][j];

    invPQ<tuple<int, int, int, int>> que;
    que.push({0, 0, 0, 1});
    vvvc<int> dist(R, vvc<int>(C, vc<int>(2, INF)));
    dist[0][0][1] = 0;
    while (!que.empty()) {
        while (!que.empty()) {
            int d, r, c, t;
            tie(d, r, c, t) = que.top();
            que.pop();
            if (d > dist[r][c][t]) continue;
            if (c < C-1) if (chmin(dist[r][c+1][1], d + A[r][c])) que.push({ dist[r][c+1][1], r, c+1, 1 });
            if (c > 0) if (chmin(dist[r][c-1][1], d + A[r][c-1])) que.push({ dist[r][c-1][1], r, c-1, 1 });
            if (r < R-1) if (chmin(dist[r+1][c][1], d + B[r][c])) que.push({ dist[r+1][c][1], r+1, c, 1 });
            if (r > 0) if (chmin(dist[r-1][c][0], d + t + 1)) que.push({ dist[r-1][c][0], r-1, c , 0 });
        }
    }

    cout << dist[R-1][C-1][1] << endl;
}


using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define pai arccos(-1);
#define keta(n) cout << fixed << setprecision((n));
using ll = long long;
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define cYES cout << "YES" << endl
#define cNO cout << "NO" << endl
typedef long long int ll;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<vector<ll>> vvll;
typedef long double ld;
const int INF = 1 << 30;
const ll MOD = 1000000007;
int main()
{
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    Sort(a);
    bool jd=false;
    rep(i,n){
        if(a[i]==a[i+1]){
            jd=true;
            break;
        }
    }
    if(jd)cno;
    else cyes;
}

#include<bits/stdc++.h>
using namespace std;
int a[4],n,y,z,x[1001];
string s[1001],c;
int main(){
  cin>>n;
  for (int i=1;i<=n;i++){
    cin>>s[i]>>x[i];
    y=max(x[i],y);
  }
  for (int i=1;i<=n;i++)
    if (x[i]!=y&&x[i]>z) z=x[i],c=s[i];
  cout<<c;
}


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

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

ll N;

void solve() {
	int i,j,k,l,r,x,y; string s;

	cin>>N;
	double phi=(1+sqrt(5))/2;
	ll A=N/(1+phi),B=N-A;

	for(i=-3000;i<=3000;i++) {
		ll X=A+i;
		ll Y=B-i;
		if(X<0||Y<0) continue;
		vector<int> V;
		V.push_back(3);
		while(X && V.size()<=130) {
			if(X>=Y) {
				V.push_back(3);
				X-=Y;
			}
			else if(X<Y) {
				V.push_back(4);
				Y-=X;
			}
		}
		if(Y+V.size()>130) continue;
		FOR(i,Y) V.push_back(2);
		reverse(ALL(V));
		cout<<V.size()<<endl;
		FORR(v,V) cout<<v<<endl;
		return;
	}
	assert(0);
}

int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); 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 N;
vector<pair<int, int>> E[200001];
int A[200001], B[200001];
ll zentai = 0;
ll kari = 0;
ll q[200001];
ll kotae[200001];

void dfs(int a, int mae) {

	kotae[a] = kari;
	for (auto p : E[a]) {
		int to = p.first;
		int e = p.second;
		if (mae == to) continue;

		if (B[e] == a) {
			kari += q[e];
			dfs(to, a);
			kari -= q[e];
		}
		else {
			zentai += q[e];
			kari -= q[e];
			dfs(to, a);
			kari += q[e];
		}

	}

}

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

	cin >> N;
	rep1(i, N - 1) {
		int a, b;
		cin >> a >> b;
		A[i] = a;
		B[i] = b;
		E[a].pb(mp(b, i));
		E[b].pb(mp(a, i));
	}
	int Q;
	cin >> Q;
	rep(i, Q) {
		int t, e, x;
		cin >> t >> e >> x;
		if (t == 2) {
			zentai += x;
			q[e] += -x;
		}
		else q[e] += x;
	}

	dfs(1, 0);

	rep1(i, N) {
		co(zentai + kotae[i]);
	}

	Would you please return 0;
}


#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define bg begin()
#define en end()
#define endl "\n"
#define vvl(n,m) vector<vector<ll> > a( n , vector<ll> (m))
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mod 1000000007
using namespace std;
ll gcd(ll a,ll b){
    if(a==0)
        return b;
    else return gcd(b%a,a);
}
ll power(ll x, ll y, ll m)
{
    if (y == 0)
        return 1;
    ll p = power(x, y / 2, m) % m;
    p = (p * p) % m;

    return (y % 2 == 0) ? p : (x * p) % m;
}
ll modInverse(ll a, ll m)
{
    return power(a, m - 2, m);
}
ll ncr(ll n, ll k)
{
    ll res = 1;

    if (k > n - k)
        k = n - k;
    for (ll i = 0; i < k; ++i) {
        res *= (n - i);
        res /= (i + 1);
    }

    return res;
}
void permute(string str)
{
    set<string> s;
    sort(str.begin(), str.end());
    do {
        if(s.count(str)==0)
        cout << str << endl;
        s.insert(str);
    } while (next_permutation(str.begin(), str.end()));
}
void solve()
{
    ll n,i;
    cin>>n;
    ll r=power(2,n,10000000);
    ll a[r+1],l=1,b[r+1][2];
    for(i=1;i<=r;i++){
        cin>>a[i];
        b[i][1]=a[i];
        b[i][0]=i;
    }
    while(r!=2){
        for(l=1;l<=r/2;l++){
            if(b[2*l-1][1]>b[2*l][1]){
                b[l][0]=b[2*l-1][0];
                b[l][1]=b[2*l-1][1];
            }
            else{
                b[l][0]=b[2*l][0];
                b[l][1]=b[2*l][1];
            }
        }
        r/=2;
    }
    if(b[1][1]<b[2][1]){
        cout<<b[1][0];
    }
    else
        cout<<b[2][0];
}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast
    solve();
    #ifndef ONLINE_JUDGE
    cout << "\nTime Elapsed: " << 1.0 * clock()  / CLOCKS_PER_SEC << " sec\n";
    #endif
    return 0;
}

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

int main(){
  cout<<setprecision(15)<<fixed;
  int n;
  cin>>n;
  vector<ll> x(n);
  rep(i,n){
    ll a; cin>>a;
    x[i]=abs(a);
  }
  ll M=0, C=0;
  double E=0;
  rep(i,n) M+=x[i];
  rep(i,n) E+=x[i]*x[i];
  E=sqrt(E);
  rep(i,n) C=max(C,x[i]);
  cout<<M<<endl;
  cout<<E<<endl;
  cout<<C<<endl;
}


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

ll compute(ll a){
    ll ans =0;
    while(a != 0){
        ans += a-1;
        a--;
    }
    return ans;

}

int main(){

    ll N; cin >> N;
    vector<ll> A(N);
    rep(i,0,N){
        cin >> A.at(i);
    }
    sort(A.begin(),A.end());
    ll cnt =0;
    ll sub_cnt =0;
    rep(i,1,N){
        if(A.at(i)==A.at(i-1)){
            sub_cnt++;
        }
        else{
            cnt += compute(sub_cnt+1);
            sub_cnt=0;
        }
    }
    if(sub_cnt!=0){
        cnt += compute(sub_cnt+1);
    }
    cout << compute(N) - cnt << endl;

}

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include <cassert>
#include <numeric>
#include <unordered_map>
typedef long long ll;
#define FOR(i, a, b) for(int i=(a); i<(b);i++)
#define REP(i, n) for(int i=0; i<(n);i++)
#define ROF(i, a, b) for(int i=(b-1); i>=(a);i--)
#define PER(i, n) for(int i=n-1; i>=0;i--)
using namespace std;

int main() {
  unordered_map<string, int> map;
  ll n;
  cin >> n;
  vector<string> s;
  s.resize(n);

  REP(i, n) {
    cin >> s[i];
  }
  ll ans = 0;

  REP(i, n) {
    if (s[i][0] == '!') {
      map[s[i]] = 1;
    }
  }
  REP(i, n) {
    if (s[i][0] != '!') {
      string tmp = '!' + s[i];
      if (map[tmp] == 1) {
        cout << s[i];
        return 0;
      }
    }
  }

  cout << "satisfiable";

  return 0;
}


#include<bits/stdc++.h>
typedef int LL;
typedef double dl;
#define opt operator
#define pb push_back
#define pii std::pair<LL,LL>
const LL maxn=1e5+9,mod=998244353,inf=0x3f3f3f3f;
LL Read(){
	LL x(0),f(1); char c=getchar();
	while(c<'0' || c>'9'){
		if(c=='-') f=-1; c=getchar();
	}
	while(c>='0' && c<='9'){
		x=(x<<3ll)+(x<<1ll)+c-'0'; c=getchar();
	}return x*f;
}
void Chkmin(LL &x,LL y){
	if(y<x) x=y;
}
void Chkmax(LL &x,LL y){
	if(y>x) x=y;
}
LL add(LL x,LL y){
	return x+=y,x>=mod?x-mod:x;
}
LL dec(LL x,LL y){
	return x-=y,x<0?x+mod:x;
}
LL mul(LL x,LL y){
	return 1ll*x*y%mod;
}
LL Pow(LL base,LL b){
	LL ret(1); while(b){
		if(b&1) ret=mul(ret,base); base=mul(base,base); b>>=1;
	}return ret;
}
LL n;
LL size[maxn],f[maxn];
std::vector<LL> V[maxn];
void Dfs(LL u){
	size[u]=1;
	for(LL i=0;i<V[u].size();++i){
		LL v(V[u][i]);
		Dfs(v);
		size[u]^=size[v];
	}
	static LL p[maxn];
	LL tot(0);
	LL sum1(0),sum2(0);
	for(LL i=0;i<V[u].size();++i){
		LL v(V[u][i]);
		LL a(f[v]),b(size[v]);
		if(b){
			p[++tot]=a;
		}else if(a<=0){
			sum1+=a;
		}else{
			sum2+=a;
		}
	}
	std::sort(p+1,p+1+tot);
	f[u]=1; f[u]+=sum1;
	for(LL i=1;i<=tot;++i){
		if((i-1)&1){
			f[u]-=p[i];
		}else{
			f[u]+=p[i];
		}
	}
	if(tot&1){
		f[u]-=sum2;
	}else{
		f[u]+=sum2;
	}
}
int main(){
//	freopen("y1.txt","r",stdin);
	n=Read();
	for(LL i=2;i<=n;++i){
		LL x(Read());
		V[x].pb(i);
	}
	Dfs(1);
//	for(int i=1;i<=n;++i){
//  	    printf("%d ",f[i]);
//    }puts("");
	assert(!(n+f[1]&1));
	printf("%d\n",n+f[1]>>1);
	return 0;
}

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define fo(i,x,y) for(int i = x;i <= y;++i)
#define fd(i,x,y) for(int i = x;i >= y;--i)
using namespace std;
int n,e[200010][2],lst[100010],stk[100010],tot,c[100010],x,y;
bool bz[100010];
char ch[20];
int rd()
{
	int x=0,sig=1;
	char c;
	for (c=getchar();c<'0' || c>'9';c=getchar()) if (c=='-') sig=-1;
	for (;c>='0' && c<='9';c=getchar()) x=x*10+c-48;
	return x*sig;
}
void print(int x,char sp)
{
	int w = -1,sig = 0;
	if(x == 0) w = 0,ch[0] = 48;
	if(x < 0) sig = 1,x = -x;
	while(x > 0) ch[++w] = x % 10 + 48,x /= 10;
	if(sig == 1) putchar('-');
	fd(i,w,0) putchar(ch[i]),ch[i] = 0;putchar(sp);
}
void add(int x,int y)
{
	e[++tot][0] = y,e[tot][1] = lst[x],lst[x] = tot;
}
void dg(int x,int fa)
{
	stk[c[x]]++;
	if(stk[c[x]] <= 1) bz[x] = 1;
	for(int i = lst[x];i;i = e[i][1])
	{
		int v = e[i][0];
		if(v == fa) continue;
		dg(v,x);
	}
	stk[c[x]]--;
}
int main()
{
	//freopen("E.in","r",stdin);
//	freopen("E.out","w",stdout);
	n = rd();
	fo(i,1,n) c[i] = rd();
	fo(i,1,n - 1) x = rd(),y = rd(),add(x,y),add(y,x);
	dg(1,0);
	fo(i,1,n) if(bz[i]) print(i,'\n');
	return 0;
}


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

#define N 200000
unsigned long long dp[N][2];

using namespace std;
int main(void) {
    unsigned long long n;
    cin >> n;
    map<long long, std::vector<long long> > balls;
    for (long long i = 0; i < n; i++) {
        long long x, c;
        cin >> x >> c;
        if (balls.count(c) == 0) {
            balls[c] = std::vector<long long>();
        }
        balls[c].push_back(x);
    }
    for (const auto& b: balls) {
        sort(balls[b.first].begin(), balls[b.first].end());
    }
    long long current_pos_left = 0;
    long long current_pos_right = 0;
    auto it = balls.begin();
    long long i;
    for (it = balls.begin(), i = 0; it != balls.end(); it++, i++) {
        long long left = (*it).second.front();
        long long right = (*it).second.back();
        if (it == balls.begin()) {
            dp[i][0] = abs(right) + right - left;
            dp[i][1] = abs(left) + right - left;
            current_pos_left = left;
            current_pos_right = right;
            //cout << "i = " << i << ", left = " << dp[i][0] << ", right = " << dp[i][1]
            //     << ", pos_left = " << current_pos_left << ", pos_right = " << current_pos_right << endl;
        } else {
            dp[i][0] = min(dp[i-1][0] + abs(current_pos_left - right) + right - left,
                           dp[i-1][1] + abs(current_pos_right - right) + right - left);
            dp[i][1] = min(dp[i-1][0] + abs(current_pos_left - left) + right - left,
                           dp[i-1][1] + abs(current_pos_right - left) + right - left);
            current_pos_left = left;
            current_pos_right = right;
            //cout << "i = " << i << ", left = " << dp[i][0] << ", right = " << dp[i][1]
            //     << ", pos_left = " << current_pos_left << ", pos_right = " << current_pos_right << endl;
        }
    }
    cout << min(dp[balls.size() - 1][0] + abs(current_pos_left), dp[balls.size() - 1][1] + abs(current_pos_right)) << endl;
}

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

//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define pb push_back
#define fi first
#define se second
#define ll long long
#define tp top()
#define fr front()
#define vi vector<int>
#define sz size()
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define mem(a,  b) memset(a,  (b),  sizeof(a))
#define clr(a) memset(a,  0,  sizeof(a))
#define sqr(x) ( (x) * (x) )
#define all(v) v.begin(),  v.end()

typedef pair<int, int> pii;
typedef pair<int,pii> pip;
typedef pair<pii,int> ppi;
typedef pair<pii,pii> ppp;

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

#define N 200020

ll mins[N], maks[N];

ll memo[N][5];
int n;
ll dp(int id, int state, ll pos){
	if (id == n+1) return abs(pos);
	if (memo[id][state] != -1) return memo[id][state];
	if (maks[id] == -1e18) return memo[id][state] = dp(id+1,state,pos);

	ll ans = 1e18;

	ans = min(ans, dp(id+1, 0, mins[id]) + abs(pos-maks[id]) + abs(maks[id]-mins[id]));
	ans = min(ans, dp(id+1, 1, maks[id]) + abs(pos-mins[id]) + abs(maks[id]-mins[id]));
	return memo[id][state] = ans;
}
ll pos[N], c[N];

void solve(){
	mem(memo,-1);
	cin>>n;
	rep(i,1,n+1) {
		mins[i] = 1e18;
		maks[i] = -1e18;
	}
	rep(i,0,n){
		cin>>pos[i]>>c[i];
		maks[c[i]] = max(maks[c[i]], pos[i]);
		mins[c[i]] = min(mins[c[i]], pos[i]);
	}
	cout<<dp(1,0,0)<<"\n";
}

int main()
{
	base();
//  freopen("input.txt", "r", stdin);
//  freopen("output.txt", "w", stdout);
	int t=1;
//	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long int
const double pi = 3.14159265358979;
const int inf = 1e13;
const int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
#define pii pair<int,int>
#define endl "\n"
#define dtor(deg) (((deg)/360)*2*pi)
#define all(a) a.begin(),a.end()
#define overload(_1,_2,_3,_4,name,...) name
#define _rep1(n) for(int i = 0; i < (n); i++)
#define _rep2(i,n) for(int i = 0; i < (n); i++)
#define _rep3(i,a,b) for(int i = (a); i < (b); i++)
#define _rep4(i,a,b,c) for(int i = (a); i < (b); i += (c))
#define rep(...) overload(__VA_ARGS__,_rep4,_rep3,_rep2,_rep1)(__VA_ARGS__)
#define _rrep1(n) for(int i = (n) - 1; i >= 0; i--)
#define _rrep2(i,n) for(int i = (n) - 1; i >= 0; i--)
#define _rrep3(i,a,b) for(int i = (b) - 1; i >= (a); i--)
#define rrep(...) overload(__VA_ARGS__,_null,_rrep3,_rrep2,_rrep1)(__VA_ARGS__)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define vv(type,name,size,...) vector<vector<type>> name(size,vector<type>(__VA_ARGS__))
#define ForEach(a,b) for_each(a.begin(),a.end(),b)
struct Edge { int to, cost; Edge(int to, int cost) : to(to), cost(cost) {} };
using Graph = vector<vector<Edge>>;
template <class T> bool chmin(T& a, T b){ if(a > b){ a = b; return 1; } return 0; }
template <class T> bool chmax(T& a, T b){ if(a < b){ a = b; return 1; } return 0; }

void Main(){
    int b, c, ans;
    cin >> b >> c;
    if(b == 0){
        cout << c << endl;
    }else if(b > 0 && c >= b * 2){
        ans = b * 2 + 1 + (c - 2);
        cout << ans << endl;
    }else if(b < 0 && c >= abs(b) * 2 + 1){
        ans = abs(b) * 2 + c;
        cout << ans << endl;
    }else if(b > 0 && c == 3){
        cout << 5 << endl;
    }else if(b > 0 && c == 2){
        cout << 3 << endl;
    }else if(b > 0 && c == 1){
        cout << 2 << endl;
    }else if(b > 0){
        cout << 5 + (c - 3) * 2 << endl;
    }else if(b < 0 && c == 3){
        cout << 5 << endl;
    }else if(b < 0 && c == 2){
        cout << 3 << endl;
    }else if(b < 0 && c == 1){
        cout << 2 << endl;
    }else if(b < 0){
        cout << 5 + (c - 3) * 2 << endl;
    }
}

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

#include <bits/stdc++.h>

int nextInt() {
    int temp; scanf("%d", &temp);
    return temp;
}
long long nextLL() {
    long long temp; scanf("%lld", &temp);
    return temp;
}

void print(int x, char endc = '\n') {
    printf("%d%c", x, endc);
    return;
}
void print(long long x, char endc = '\n') {
    printf("%lld%c", x, endc);
    return;
}
void print(size_t x, char endc = '\n') {
    printf("%zu%c", x, endc);
    return;
}
void print(float x, char endc = '\n') {
    printf("%f%c", x, endc);
    return;
}
void print(double x, char endc = '\n') {
    printf("%lf%c", x, endc);
    return;
}

template<typename T1, typename T2>
void print(std::pair<T1, T2> &p, char sepc = ' ', char endc = '\n') {
    print(p.first, sepc);
    print(p.second, endc);
    return;
}

template<typename T>
void print(std::vector<T> &v, char sepc = ' ', char endc = '\n') {
    for(T e : v) print(e, sepc);
    printf("%c", endc);
    return;
}

template<typename T>
void print(const std::set<T> &v, char sepc = ' ', char endc = '\n') {
    for(T e : v) print(e, sepc);
    printf("%c", endc);
    return;
}

using namespace std;

void eachTC() {
    long long B = nextLL(), C = nextLL();
    long long res;

    if(B == 0)
        res = C;
    else if(C == 1) {
        res = 2;
    }
    else if((B > 0 && B <= C/2) || (B < 0 && -B <= (C-1)/2)) {
        long long B1, B2;
        if(B > 0 && B <= C/2) {
            B1 = -B - (C-1)/2;
            B2 = B + (C-2)/2;
        }
        else {
            B1 = B - C/2;
            B2 = -B + (C-1)/2;
        }
        res = B2 - B1 + 1;
    }
    else res = 2*C - 1; // 2 * (C/2 + (C-1)/2)

    print(res);
}

int main() {
    int T = 1;
    while(T--) eachTC();

    return 0;
}


#include <sys/time.h>

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <utility>
#include <cctype>
#include <cstdlib>
#include <typeinfo>

/*
#include <atcoder/all>
using namespace atcoder;
*/

/*
#include <boost/multiprecision/cpp_int.hpp>

namespace mp = boost::multiprecision;
using BigInt = mp::cpp_int;
*/

using namespace std;

using ll = long long;
using i_i = pair<int, int>;
using l_l = pair<ll, ll>;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)

const ll MOD = 1000000007LL;
const ll INF = 1e9 + 1;

//#define pos(x, y) (x) + (y) * w

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

	ll min_v = - 1e9;
	ll max_v = 1e9;
	ll total_a = 0;

	rep(i, n) {
		ll a, t;
		cin >> a >> t;
		if (t == 1) {
			total_a += a;
			max_v += a;
			min_v += a;
		} else if (t == 2) {
			min_v = max(a, min_v);
			max_v = max(a, max_v);
		} else if (t == 3) {

			min_v = min(a, min_v);
			max_v = min(a, max_v);
		}
	}
	//cout << "max_v:" << max_v << " min_v:" << min_v << " total_a:" << total_a << endl;
	int q;
	cin >> q;

	rep(i, q) {
		ll x;
		cin >> x;
		ll ans = x + total_a;
		ans = min(ans, max_v);
		ans = max(ans, min_v);
		cout << ans << endl;
	}

	return 0;
}

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <ctype.h>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#define INF 0x3f3f3f3f
#define eps 1e-8
// #define _
using namespace std;
typedef long long ll;
int main()
{
    #ifdef _
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif

    int n;
    ll ans=0;
    scanf("%d",&n);
    string s,t;
    while(s.size()<n+3) s+="110";
    cin>>t;
    for(int i=0;i<3;i++)
    {
        if(s.substr(i,n)==t)
        {
            ll l=i,r=3e10-n;
            ans+=ceil((r-l+1)/3.0);
        }
    }
    printf("%lld\n",ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mit map<int,int>::iterator
#define sit set<int>::iterator
#define itrm(g,x) for(mit g=x.begin();g!=x.end();g++)
#define itrs(g,x) for(sit g=x.begin();g!=x.end();g++)
#define ltype int
#define rep(i,j,k) for(ltype(i)=(j);(i)<=(k);(i)++)
#define rap(i,j,k) for(ltype(i)=(j);(i)<(k);(i)++)
#define per(i,j,k) for(ltype(i)=(j);(i)>=(k);(i)--)
#define pii pair<int,int>
#define fi first
#define se second
#define mpr make_pair
#define pb push_back
#define fastio ios::sync_with_stdio(false)
#define check(x) if(x>=mod) x-=mod
const int inf=0x3f3f3f3f,mod=998244353;
const double pi=3.1415926535897932,eps=1e-6;
void chmax(int &x,int y){if(x < y) x = y;}
void chmin(int &x,int y){if(x > y) x = y;}
int qpow(int x,int y){
    int ret = 1;
    while(y) {
        if(y & 1) ret = (ll)ret * x % mod;
        x = (ll)x * x % mod;
        y >>= 1;
    }
    return ret;
}
int n,C[305][305],k,ans[305],a[200005],ab[305][305],suma[305],inv2 = 499122177;
int pwa[200005][305];
int main()
{
    scanf("%d%d",&n,&k);
    C[0][0] = 1;
    rep(i,1,k) rep(j,0,k) {
        C[i][j] = C[i-1][j];
        if(j) {C[i][j] += C[i-1][j-1]; check(C[i][j]);}
    }
    rep(i,1,n) scanf("%d",a+i);
    rep(i,1,n) {
        pwa[i][0] = 1;suma[0] += pwa[i][0];
        rep(j,1,k) {
            pwa[i][j] = (ll)pwa[i][j-1] * a[i] % mod;
            suma[j] += pwa[i][j];
            check(suma[j]);
        }
    }
    rep(i,0,k) rep(j,0,k - i) {
        ab[i][j] = ((ll)suma[i] * suma[j] % mod - suma[i + j] + mod) % mod;
        ab[i][j] = (ll)ab[i][j] * inv2 % mod;
        ans[i + j] += (ll)C[i + j][j] * ab[i][j] % mod;
        check(ans[i + j]);
    }
    rep(i,1,k) printf("%d\n",ans[i]);
    return 0;
}

/*

    P_r_A_d_Y ☹

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

#define int     long long int
#define endl    "\n"
#define mod     1000000007
#define inf     1e18
#define pb      push_back
#define all(x)  x.begin(),x.end()
#define arr_max(x)  *max_element(x.begin(),x.end())
#define arr_min(x)  *min_element(x.begin(),x.end())
#define pii         pair<int,int>
#define ff          first
#define ss          second
#define vec         vector<int>

const int N = 300005;

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

bool cmp(vector<int>a , vector<int>b) {
    return a[0] < b[0];
}
int poww(int x, int n)
{
    if (n == 0 ) return 1 ;
    int u = poww(x, n / 2);
    u = (u * u) ;
    if (n % 2 == 1)u = (u * x) ;
    return u;
}

//(x**n)%m
int mod_pow(int x, int n, int m)
{
    if (n == 0 ) return 1 % m;
    int u = mod_pow(x, n / 2, m);
    u = (u * u) % m;
    if (n % 2 == 1)u = (u * x) % m;
    return u;
}
int query(int l, int r)
{
    int x;
    cout << "? " << l << " " << r << endl;
    cin >> x;

    return x;
}

// int xd[4] = {1, 0, -1, 0};
// int yd[4] = {0, -1, 0, 1};

int32_t main()
{
    fastIO;

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

    int t;
    t = 1;
    //cin >> t;
    int ert = 1;
    while (t--)
    {
        string s; cin >> s;
        map<char, int>mp;
        int n = s.length();

        int ans = 0;
        for (int i = n - 1; i >= 0; i--)
        {
            if (i + 1 < n && i - 1 >= 0 && s[i] == s[i - 1] && s[i] != s[i + 1])
            {
                int g = n - 1 - i;
                // cout << g << endl;
                if (mp.count(s[i]))
                    g -= mp[s[i]];

                ans += g;

                mp.clear();
                mp[s[i]] = n - 1 - i;
                s[i + 1] = s[i];
            }
            mp[s[i]]++;
        }

        cout << ans << endl;

    }

    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <array>
#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>

using namespace std;

using ll = long long;
using ull = unsigned long long;

template <class ...Args>
void Input(Args &...args)
{
	(cin >> ... >> args);
}

template <class T>
void InputArray(std::size_t size, T &t)
{
	t.resize(size);
	for (auto &e : t) {
		cin >> e;
	}
}

template <class ...Args>
void InputArray(std::size_t size, Args &...args)
{
	(InputArray(size, args), ...);
}

template <class ...Args>
void InputVerticalArray(std::size_t size, Args &...args)
{
	(args.resize(size), ...);
	for (int i = 0; i < size; i++) {
		((cin >> args[i]), ...);
	}
}

template <class ...Args>
void Output(const Args &...args)
{
	((cout << args << ' '), ...) << endl;
}

template <class ...Args>
void OutputVertical(const Args &...args)
{
	((cout << args << endl), ...);
}

template <class T>
void OutputArray(const T &t)
{
	for (const auto &e : t) {
		cout << e << ' ';
	}
	cout << endl;
}

template <class ...Args>
void OutputArray(const Args &...args)
{
	(OutputArray(args), ...);
}

template <class ...Args>
void OutputVerticalArray(const Args &...args)
{
	for (int i = 0; i < min({ args.size()... }); i++) {
		((cout << args[i] << ' '), ...) << endl;
	}
}

#define inp(type, ...) \
	type __VA_ARGS__; \
	Input(__VA_ARGS__)

#define inpa(type, size, ...) \
	type __VA_ARGS__; \
	InputArray((size), __VA_ARGS__)

#define inpva(type, size, ...) \
	type __VA_ARGS__; \
	InputVerticalArray((size), __VA_ARGS__)

#define otp(...) \
	Output(__VA_ARGS__)

#define otpv(...) \
	OutputVertical(__VA_ARGS__)

#define otpa(...) \
	OutputArray(__VA_ARGS__)

#define otpva(...) \
	OutputVerticalArray(__VA_ARGS__)

#define rep(counter, range) \
	for (int (counter) = 0; (counter) < (range); (counter)++)

#define repi(range) \
	rep(i, range)

#define rrep(counter, range) \
	for (int (counter) = (range) - 1; (counter) >= 0; (counter)--)

#define rrepi(range) \
	rrep(i, range)

#define repc(element, container) \
	for (auto &(element) : (container))

#define repe(container) \
	repc(e, container)

#define all(container) \
	(begin(container)), (end(container))

#ifdef __CCR__
#	define dlog(x) clog << #x " = " << x << endl
#else
#	define dlog(x)
#endif

constexpr ll mod = 998244353;

int main()
{
	inp(ll, a, b, c);

	ll sa = a * (a + 1) / 2 % mod;
	ll sb = b * (b + 1) / 2 % mod;
	ll sc = c * (c + 1) / 2 % mod;
	ll sbc = sb * sc % mod;
	ll sabc = sa * sbc % mod;

	otp(sabc);

	return 0;
}

#include<bits/stdc++.h>
#define int long long
//#define PI pair<int,int>
using namespace std;
const int maxm=2e6+5;
const int mod=998244353;

int cal(int x){
    return x*(x+1)/2%mod;
}
void solve(){
    int a,b,c;cin>>a>>b>>c;
    int C=cal(c);
    int B=cal(b)*C%mod;
    int A=cal(a)*B%mod;
    cout<<A<<endl;
}
signed main(){
    solve();
    return 0;
}
/*

*/


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

int main(){
    int n; cin >> n;
    string s,x; cin >> s >> x;
    vl b(n+1,0);
    b[n] = 1;
    ll now = 1;
    for(int i=n-1; i>=0; i--){
        int c = s[i] - '0';
        if(x[i] == 'T'){
            b[i] = b[i+1];
            rep(j,7){
                if(b[i+1]>>((j+c*now)%7) & 1) b[i] |= 1<<j;
            }
        }else{
            rep(j,7){
                if((b[i+1]>>j & 1) && (b[i+1]>>((j+c*now)%7) & 1)){
                    b[i] |= 1<<j;
                }
            }
        }
        now = now * 10 % 7;
    }
    if(b[0] & 1) cout << "Takahashi\n";
    else cout << "Aoki\n";
}

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

#define rng(x) x.begin(), x.end()
#define pb push_back
#define ff first
#define ss second

typedef double db;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<bool> vb;
typedef unsigned long long int lld;

/*-----------------------------Code begins----------------------------------*/
ll mod = 1e9 + 7;

void solve(){
    int n,m; cin>>n>>m;
    int a[n][m] ;
    int dp[n][m] ;
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            char c;  cin>>c;
            if(c=='-'){a[i][j]=-1;}
            else{a[i][j]=1;}
        }
    }
    dp[n-1][m-1]=0;
    for(int i=n-1; i>=0; i--){
        for(int j=m-1; j>=0; j--){
            if(i<(n-1) && j<(m-1)){
                dp[i][j] = max(a[i][j+1] - dp[i][j+1] , a[i+1][j] - dp[i+1][j]);
            }
            else if(i<(n-1)){
                dp[i][j] = a[i+1][j] - dp[i+1][j];
            }
            else if(j<(m-1)){
                dp[i][j] = a[i][j+1] - dp[i][j+1];
            }
        }
    }
    if(dp[0][0]==0){
        cout<<"Draw\n";
    }
    else if(dp[0][0]>0){
        cout<<"Takahashi\n";
    }
    else{
        cout<<"Aoki\n";
    }
}
int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T = 1;
  //cin >> T;
  while (T--){
    solve();
  }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,n) for(ll i=0;i<n;i++)
#define loopn(i,j,n) for(ll i=j;i<n;i++)
#define m_arr(arr, n) vector<ll>arr(n)
#define m_arre(arr) vector<ll>arr
#define m_set(sat) set<ll>sat
#define ppn(name) pair<ll,ll>name
#define pp pair<ll,ll>
#define ff first
#define ss second
#define sort_all(arr) sort(arr.begin(), arr.end())
#define pi 3.141592653589793238
#define mod 998244353

ll gcd(ll a, ll b){if(a==0)return b;if(b==0)return a;return gcd(b%a, a);}
ll power(ll a, ll b){ll res=1;while(b>0){if(b%2!=0)res=res*1ll*a;b/=2;a=a*1ll*a;}return res;}

#define inf (power(2, 63)-1)
#define ninf (power(2, 63)+1)

void solve()
{
    ll l ,r ;
    cin>>l>>r;

    ll ans = (r-l);
    if(ans<l)
    {
        cout<<0<<endl;
        return;
    }
    ans=ans-l+1;
    ans = ans*1ll*(ans+1)/2;
    cout<<ans<<endl;
    return;

}

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


#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;

#define REP(i,b,e) for(int i=b; i<e; i++)
#define PRINT(vec) {printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");}
#define fi first
#define se second

const int MOD = 1e9+7;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
	int n;
	scanf("%d", &n);
	char s[n+1];
	scanf("%s", s);

	std::vector<char> st;
	REP(i, 0, n){
		st.push_back(s[i]);
		int l = st.size();
		if(st[l-3]=='f' && st[l-2]=='o' && st[l-1]=='x'){
			st.pop_back();
			st.pop_back();
			st.pop_back();
		}
	}
	printf("%ld\n", st.size());
	return 0;
}

#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <deque>
using namespace std;

int main() {
    int n; cin >> n;
    map<int, int> mp;
    for(int i = 1;i < n ; i++){
        mp[i] = i - 1;
    }

    string s; cin >> s;
    reverse(s.begin(), s.end());
    long num = 0;
    if(n == 1 || n == 2) {
        cout << n << endl;
        return 0;
    }
    if(n == 3) {
        if(s == "xof"){
            cout << 0 << endl;
            return 0;
        }else{
            cout << 3 << endl;
            return 0;
        }
    }

      for(int i = 2 ;i < n; i++) {
          if(s.at(i) == 'f'){
              if(mp[mp[i]] < 0) break;
              if(s.at(mp[i]) == 'o' && s.at(mp[mp[i]]) == 'x'){
                  mp[i + 1] = mp[mp[mp[mp[i + 1]]]];
                  num++;
              }
          }
      }

    cout << n - 3*num << endl;

}


// #include <atcoder/all>
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
    return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
    return a > b && (a = b, true);
}
/*-------------------------------------------*/

int n;
ll a[200009], b[200009];

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

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

    ll sum = 0;
    rep(i, n) sum += a[i];

    vector<int> odd, even;
    rep(i, n)(i & 1 ? odd : even).push_back(b[i] - a[i]);

    sort(ALL(odd), greater<int>());
    sort(ALL(even), greater<int>());

    ll ans = sum;
    rep(i, n / 2) chmax(ans, sum += odd[i] + even[i]);

    cout << ans << endl;

    return 0;
}

#include <cstdio>
#include <cctype>
namespace io{
	#define cs const
	#define il inline
	#define tpl template
	#define tpn typename
	typedef cs int&ci;
	typedef unsigned size_t;
	typedef cs size_t&cst;
#ifndef ONLINE_JUDGE
	using std::getchar;
	using std::putchar;
	using std::isdigit;
#else
	const size_t _I_Buffer_Size = 1 << 23, _O_Buffer_Size = 1 << 23;
	char _I_Buffer[_I_Buffer_Size],*_I_pos=_I_Buffer-1;
    const char *_I_end=_I_Buffer + _I_Buffer_Size;
    char _O_Buffer[_O_Buffer_Size],*_O_pos=_O_Buffer-1;
    const char *_O_end=_O_Buffer + _O_Buffer_Size,*_O_preend=_O_end-1;
    struct io{
		~io(){
			fwrite(_O_Buffer,1,_O_pos-_O_Buffer+1,stdout);
		}
	}ios;
    il char getchar(){
        return *((++_I_pos==_I_end)?fread(_I_Buffer,1,_I_Buffer_Size,stdin),_I_pos=_I_Buffer:_I_pos);
    }
    il bool isdigit(ci ch){
		return '0'<=ch;
	}
    il void putchar(ci x){
        *((_O_pos==_O_preend)?fwrite(_O_Buffer,1,_O_end-_O_Buffer,stdout),_O_pos = _O_Buffer:++_O_pos)=x;
    }
#endif
	template<typename T1>il void readuint(T1&x){
		int ch;
		while(!isdigit(ch=getchar()));
		for(x=ch^'0'; isdigit(ch=getchar()); x=x*10+(ch^'0'));
	}
	template<typename T>void writeuint(cs T&x){
		if(x>9)
			writeuint(x/10);
		putchar((x%10)|'0');
	}
	template<typename T>il void writelnuint(cs T&x){
		writeuint(x);
		putchar('\n');
	}
	#undef cs
	#undef il
	#undef tpl
	#undef tpn
}
#include <algorithm>
#define max_n 100000
using io::readuint;
using io::writelnuint;
using namespace std;
typedef long long ll;
int a[max_n];
#define a0 a
int main(){
	int n,k;
	readuint(n);
	int*a1=a+(k=n>>1);
	for(int*i=a1; --i>=a0; ){
		readuint(*i);
		readuint(*(i+k));
	}
	ll ans=0;
	for(int*i=a1,x; --i>=a0; ){
		readuint(x);
		*i-=x,ans+=x;
		readuint(x);
		*(i+k)-=x,ans+=x;
	}
	stable_sort(a0,a1),stable_sort(a1,a1+k);
	for(int*i=a1,x; --i>=a0&&(x=*i+*(i+k))>0; ans+=x);
	writelnuint(ans);
	return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

template<class V, int ME> class BIT {
public:
	V bit[1<<ME],val[1<<ME];
	V operator()(int e) {if(e<0) return 0;V s=0;e++;while(e) s+=bit[e-1],e-=e&-e; return s;}
	void add(int e,V v) { val[e++]+=v; while(e<=1<<ME) bit[e-1]+=v,e+=e&-e;}
	void set(int e,V v) { add(e,v-val[e]);}
	int lower_bound(V val) {
		V tv=0; int i,ent=0;
		for(i=ME-1;i>=0;i--) if(tv+bit[ent+(1<<i)-1]<val) tv+=bit[ent+(1<<i)-1],ent+=(1<<i);
		return ent;
	}
};
BIT<int,20> TL,TR;;

int N,L;
int A[101010],B[101010];
int T[101010];
map<int,int> le,ri;
void solve() {
	int i,j,k,l,r,x,y; string s;

	cin>>N>>L;
	A[0]=B[0]=0;
	FOR(i,N) {
		cin>>A[i+1];
		A[i+1]-=i+1;
	}
	A[N+1]=B[N+1]=L-N;
	FOR(i,N) {
		cin>>B[i+1];
		B[i+1]-=i+1;
	}

	N+=2;

	FOR(i,N) if(ri.count(A[i])==0) ri[A[i]]=i;
	for(i=N-1;i>=0;i--) if(le.count(A[i])==0) le[A[i]]=i;

	FOR(i,N) {
		if(A[i]==B[i]) T[i]=i;
		if(A[i]<B[i]) {
			if(ri.count(B[i])==0) return _P("-1\n");
			T[i]=ri[B[i]];
			TR.set(T[i],1);
		}
		if(A[i]>B[i]) {
			if(le.count(B[i])==0) return _P("-1\n");
			T[i]=le[B[i]];
			TL.set(T[i],1);
		}
	}
	ll ret=0;
	FOR(i,N) {
		if(A[i]<B[i]) {
			ret++;
			ret+=TR(T[i]-1)-TR(i);
		}
		if(A[i]>B[i]) {
			ret++;
			ret+=TL(i-1)-TL(T[i]);
		}
	}

	cout<<ret<<endl;
}

int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stdlib.h>
#include <map>
#include <cmath>
#define MOD_P 1000000007
#define MOD_Q 998244353
#define PI 3.14159265358979
#define ll long long
using namespace std;

int main()
{
	int h, w;
	cin >> h >> w;
	int ans = 0;
	vector<vector<bool>> dp(h + 2, vector<bool>(w + 2, false));
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			char tmp;
			cin >> tmp;
			if (tmp == '.') {
				dp[i][j] = true;
			}
		}
	}
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			if (dp[i][j]) {
				if (dp[i - 1][j])ans++;
				if (dp[i + 1][j])ans++;
				if (dp[i][j - 1])ans++;
				if (dp[i][j + 1])ans++;
			}
		}
	}

	printf("%d", ans / 2);

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define cin(a,n) for(int i=0;i<n;i++) cin>>a[i]
#define cin2(a,b,n) for(int i=0;i<n;i++) cin>>a[i]>>b[i]
#define mod 998244353
#define pb push_back
#define pie 3.141592653589793238462643383279
vector<bool> prime;
vector<int> fact,inv,primes,factors;
void factorize(int a)
{
	fact.clear();
	for(int i=1;i*i<=a;i++)
	{
		if (i*i==a) factors.pb(i);
		else if (a%i==0)
		{
			factors.pb(i);
			factors.pb(a/i);
		}
	}
	sort(factors.begin(),factors.end());
}
int power(int a,int b)
{
	if(a==1||b==0)	return 1;
	int c=power(a,b/2);
	int res=1;
	res=c*c;
	if(res>=mod)	res%=mod;
	if(b%2)	res*=a;
	if(res>=mod)	res%=mod;
	return res;
}
int modInv(int a)
{
	return power(a,mod-2);
}
void factorial(int n)
{
	fact.resize(n+1);
	fact[0]=1;
	for(int i=1;i<=n;i++)
	{
		fact[i]=fact[i-1]*i;
		if(fact[i]>=mod)	fact[i]%=mod;
	}
}
void InvFactorial(int n)
{
	inv.resize(n+1);
	inv[0]=1;
	for(int i=1;i<=n;i++)	inv[i]=modInv(fact[i]);
}
int ncr(int n,int r)
{
	if(n<r||n<0||r<0)	return 0;
	int b=inv[n-r];
	int c=inv[r];
	int a=fact[n]*b;
	if(a>=mod)	a%=mod;
	a*=c;
	if(a>=mod)	a%=mod;
	return a;
}
void remove_duplicates(vector<pair<int,int>> &v)
{
	sort(v.begin(),v.end());
	int _size=unique(v.begin(),v.end())-v.begin();
	v.resize(_size);
}
unsigned int gcd(unsigned int u, unsigned int v)
{
    if(u==0||v==0) return max(u,v);
    unsigned int shift=__builtin_ctz(u|v);
	u>>=__builtin_ctz(u);
    do{
    	v>>=__builtin_ctz(v);
    	if(u>v)	swap(u,v);
    	v-=u;
    }while(v!=0);
    return u<<shift;
}
void sieve(int n)
{
    prime.assign(n+1,1);
	prime[1]=false;
    for(int p=2;p*p<=n;p++) if(prime[p])	for(int i=p*p;i<=n;i+=p)	prime[i]=false;
    for(int i=2;i<n+1;i++) if(prime[i]) primes.push_back(i);
}
//----------------------------------------------------------------------------------------------------------------------------------------------------
void solve()
{
	int n;
	cin>>n;
	int a[n];
	cin(a,n);
	sort(a,a+n);
	int sum=0,exp=a[0];
	for(int i=1;i<n;i++)
	{
		sum=(sum+a[i]*exp)%mod;
		exp=(2*exp+a[i])%mod;
	}
	for(int i=0;i<n;i++) sum=(sum+a[i]*a[i])%mod;
	cout<<sum;
}
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int T=1;
	//cin>>T;
	for(int i=1;i<=T;i++) solve();
}

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

using namespace std;

int main(){
    int N = 0;
    cin >> N;
    vector<long long> A(N, 0);
    for(int i = 0; i < A.size(); i++){
        cin >> A[i];
    }
    sort(A.begin(), A.end());

    long long MOD = 998244353;
    long long ans = 0;
    for(int i = 0; i < A.size(); i++){
        ans = (ans + (A[i] * A[i]) % MOD) % MOD;
    }
    if(N != 1){
        vector<long long> sub(N-1,0);
        sub[N-2] = A[N-1];
        for(int i = N-3;i >= 0;i--){
            sub[i] = (((sub[i+1] * 2) % MOD) + A[i+1]) % MOD;
        }

        for(int i = 0; i < sub.size(); i++){
            sub[i] = (sub[i] * A[i]) % MOD;
        }

        for(int i = 0; i < sub.size(); i++){
            ans = (ans + sub[i]) % MOD;
        }
    }

    cout << ans << endl;

    return 0;
}


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

//バイトで１５分ほど遅れて参加
int main() {
	ll N;
	cin>>N;
	ll A=1000;
	ll Z=0,X=N;
	while(X>=A){
		Z+=(X-A+1);
		A*=1000;
	}
	cout<<Z<<endl;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_multiset tree<long long , null_type,less_equal<long long >, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_set tree<long long , null_type,less<long long >, rb_tree_tag,tree_order_statistics_node_update>
#define fill(arr,c) memset(arr,c,sizeof(arr))
#define perm(r) next_permutation(all(r))
//it gives bool value ans permute the string lexoggraphically
#define sortdesc greater<int>()
#define ll long long int
//std::setfill('0') << std::setw(5) << 25; it adds leaing zeroes;
#define f(i,a) for(int i=0;i<a;i++)
#define fo(i,a) for(int i=1;i<=a;i++)
#define foo(i,x,n,c) for(ll i=x;i<n;i+=c)
#define foi(i,x,n,c) for(ll i=x;i>=n;i+=c)
#define fauto(i,m) for(auto i:m)
#define forall(a) for( auto itr=a.begin();itr!=a.end();itr++)
#define ld long double
#define in push_back
#define mll map<ll,ll>
#define mcl map<char,ll>
#define msl map<string,ll>
#define vi vector<int >
#define vl vector<ll >
#define vp vector< pair<int,int> >
#define vs vector <string>
#define vc vector <char>
#define o(a) cout<<a
#define os(a) cout<<a<<" "
#define en cout<<"\n";
#define testcase ll t ;cin>>t; while(t--)
#define ff first
#define ss second
#define pl pair<ll,ll>
#define pi pair<int,int>
#define all(a) (a).begin(), (a).end()

#define sz(a)  (a).size()
#define prec(n) fixed<<setprecision(n)
#define mp make_pair
#define bitcount  __builtin_popcountll
#define imin o("imin");en;
using namespace std;
bool comp(const pair<int,int> &a , const pair<int,int> &b){
    if(a.first == b.first)  return a.second < b.second;
     return a.first < b.first;
}
bool comps(const pair<int,int> &a , const pair<int,int> &b){
    if(a.second == b.second)  return a.first< b.first;
     return a.second < b.second;
}
//ll pi=acos(0.0)*2;
void fastio()
{
    	ios::sync_with_stdio(0);
cin.tie(0);

}
void inout()
{

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);

     freopen("output.txt", "w", stdout);
     #endif
}
ll gcd(ll bb,ll aa)
{

	if(bb==0)
	return aa;
	else
	return gcd(aa%bb,bb);
}
ll N=1e9+7;
int main()
{
fastio();
ll n,k;
cin>>n>>k;
ll x,y;
ll ans=0;
foo(i,2,2*n+1,1)
{
	if(i-k>=2 && i-k<=2*n)
	ans=ans+(min(i-1,2*n-i+1))*min(i-1-k,2*n-i+1+k);
}

o(ans);
en;

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 pii = pair<int, int>;

int main() {
	int n, k;
	cin >> n >> k;
	k = abs(k);
	vector<ll> v(2 * n + 1);
	for (int i = 2; i <= 2 * n; i++) {
		v[i] = min(i - 1, 2 * n - i + 1);
	}
	ll ans = 0;
	for (int i = k + 1; i <= 2 * n; i++) {
		ans += v[i] * v[i - k];
	}
	cout << ans << endl;
	return 0;
}


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

bool flg[100][100];
int main() {
	int n; cin >> n;
	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < n; ++j) {
			char c; cin >> c;
			flg[i][j] = (c == '1');
		}
		flg[i][i] = true;
	}
	for(int k = 0; k < n; ++k) {
		for(int i = 0; i < n; ++i) {
			for(int j = 0; j < n; ++j) {
				flg[i][j] |= (flg[i][k] & flg[k][j]);
			}
		}
	}
	double ans = 0;
	for(int i = 0; i < n; ++i) {
		int cnt = 0;
		for(int j = 0; j < n; ++j) {
			cnt += flg[j][i];
		}
		ans += 1.0 / (double)cnt;
	}
	printf("%.15f\n", ans);
	return 0;
}

/*
                    author         : TAPAN SAVANI
                    codeforces     : savanitapan2001
                    codechef       : savanitapan17
*/

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

░██╗░░░░░░░██╗░█████╗░██████╗░██╗░░██╗  ██╗░░██╗░█████╗░██████╗░██████╗░
░██║░░██╗░░██║██╔══██╗██╔══██╗██║░██╔╝  ██║░░██║██╔══██╗██╔══██╗██╔══██╗
░╚██╗████╗██╔╝██║░░██║██████╔╝█████═╝░  ███████║███████║██████╔╝██║░░██║
░░████╔═████║░██║░░██║██╔══██╗██╔═██╗░  ██╔══██║██╔══██║██╔══██╗██║░░██║
░░╚██╔╝░╚██╔╝░╚█████╔╝██║░░██║██║░╚██╗  ██║░░██║██║░░██║██║░░██║██████╔╝
░░░╚═╝░░░╚═╝░░░╚════╝░╚═╝░░╚═╝╚═╝░░╚═╝  ╚═╝░░╚═╝╚═╝░░╚═╝╚═╝░░╚═╝╚═════╝░

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

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

#define HAPPY_CODING              \
    ios_base::sync_with_stdio(0); \
    cin.tie(NULL);                \
    cout.tie(NULL);
#define pb push_back
#define mp make_pair
#define Debug(x) cout << #x " = " << (x) << endl
#define SORT(a) sort(a.begin(), a.end())
#define SORTR(a) sort(a.rbegin(), a.rend())
#define mod 1000000007
#define pi 3.141592653589793238
#define ll long long int
#define ull unsigned long long
#define be begin()
#define en end()
#define FOR(i, a, b) for (long long int i = a; i < b; i++)
#define FORI(i, a, b) for (int i = a; i >= b; i--)

typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
typedef pair<ll, ll> PL;
typedef vector<PI> VPI;

int main()
{
    HAPPY_CODING;

    int n;
    cin >> n;

    string s;
    cin >> s;

    int q, swapq = 0;
    cin >> q;

    while (q--)
    {
        int t, a, b;
        cin >> t >> a >> b;

        a--, b--;

        if (t == 1)
        {
            if (swapq % 2 == 0)
            {
                char x = s[a];
                s[a] = s[b];
                s[b] = x;
            }
            else
            {
                if (a >= n)
                    a -= n;
                else
                    a += n;

                if (b >= n)
                    b -= n;
                else
                    b += n;

                char x = s[a];
                s[a] = s[b];
                s[b] = x;
            }
        }
        else
        {
            swapq++;
        }
    }
    if (swapq % 2 == 1)
    {
        string s1 = s.substr(0, n);
        string s2 = s.substr(n);

        s = s2 + s1;
    }

    cout << s << "\n";

    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 VVL = vector<VL>;
using VP = vector<P>;
using VS = vector<string>;
using VC = vector<char>;
#define MOD 1000000007
const int INF = 1e9 + 10;

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

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);
    //////////////////////////////////////////
    double sx,sy,gx,gy;
    cin >> sx >> sy >> gx >> gy;
    print((sy*gx+gy*sx)/(gy+sy));

    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main() {
    int r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    int answer;

    int dr = r2 - r1;
    int dc = c2 - c1;

    if (dr == 0 && dc == 0) {
        answer = 0;
    } else if (dr == -dc || dr == dc || abs(dr) + abs(dc) <= 3 ) {
        answer = 1;
    } else if ((dr + dc) % 2 == 0 || abs(dr + dc) <= 3 || abs(dr - dc)<= 3 || abs(dr) + abs(dc) <= 6) {
        answer = 2;
    } else {
        answer = 3;
    }

    cout << answer << endl;

}


#include<bits/stdc++.h>
using namespace std;
typedef pair< int , int >PII;

vector< PII >deltas(vector< int >X) {
    vector< PII >vd;
    for (int i = 0; i+1 < X.size(); i++) {
        if (X[i]+1 < X[i+1]) {
            vd.emplace_back(X[i+1]-X[i]-1, i);
        }
    }
    return vd;
}

void impossible() {
    cout << -1 << "\n";
    exit(0);
}

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

    int n, l;
    cin >> n >> l;

    vector< int >A(n+2);
    A[0] = 0;
    A[n+1] = l+1;
    for (int i = 1; i <= n; i++) cin >> A[i];

    vector< int >B(n+2);
    B[0] = 0;
    B[n+1] = l+1;
    for (int i = 1; i <= n; i++) cin >> B[i];

    vector< PII >da = deltas(A);
    vector< PII >db = deltas(B);

    long long ans = 0;
    for (int i = db.size()-1; i >= 0; i--) {
        vector< PII >fromA;
        int sum = 0;
        while (sum < db[i].first) {
            assert(!da.empty());
//            if (da.empty()) impossible();
            sum += da.back().first;
            fromA.push_back(da.back());
            da.pop_back();
        }

        if (sum != db[i].first) impossible();

        int mn = fromA.back().second;
        int mx = fromA.front().second;
        mn = min(mn, db[i].second);
        mx = max(mx, db[i].second);

        ans += mx-mn;
    }

    if (!da.empty()) {
        impossible();
    }

    cout << ans << "\n";

    return 0;
}

#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define FI(n) FastIO::read(n)
#define FO(n) FastIO::write(n)
#define ull unsigned long long
#define mst(a,b) memset(a,b,sizeof(a))
#define foR(i,k,j) for(int i=(k);i>=(j);i--)
#define For(i,k,j) for(int i=(k);i<=(j);i++)
#define Foe(i,u) for(int i=lst[u],v=e[i].v;i;i=e[i].nxt,v=e[i].v)
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define Fin(s) freopen(s,"r",stdin)
#define Fout(s) freopen(s,"w",stdout)
#define file(s) Fin(s".in"),Fout(s".out")
#define INF ((1<<30)-1)
#define int long long
const int P=1e9+7; //
using namespace std;
template<typename T>inline void ckmax(T &a,T b) {(a<b)&&(a=b);}
template<typename T>inline void ckmin(T &a,T b) {(a>b)&&(a=b);}
inline int mul(int a,int b) {return 1ull*a*b%P;}
inline int add(int a,int b) {return a+b>=P?a+b-P:a+b;}
inline int sub(int a,int b) {return a-b>=0?a-b:a-b+P;}
inline void mulmod(int &a,int b) {a=mul(a, b);}
inline void addmod(int &a,int b) {((a+=b)>=P)&&(a-=P);}
inline void submod(int &a,int b) {((a-=b)<0)&&(a+=P);}
inline int ksm(int a,int b) {int ans=1; for(;b;b>>=1) {if(b&1) ans=1ll*ans*a%P;a=1ll*a*a%P;}return ans;}
inline void fprint(const int &x,char c=' ') {fprintf(stderr,"%d%c",x,c);}
inline void fprint(const pii &x,char c='\n') {fprintf(stderr,"%d %d%c",x.first,x.second,c);}
inline void fprint(const int *f,const int &n,char c='\n') {for(int i=1;i<=n;i++) fprint(f[i]); fprintf(stderr,"%c",c);}
inline void fprint(const vector<int> &f,char c='\n') {for(int i=0;i<(int)f.size();i++) fprint(f[i]); fprintf(stderr,"%c",c);}
inline int inv(int a) {return ksm(a,P-2);}
namespace FastIO {
  const int SIZE=1<<16; char buf[SIZE],obuf[SIZE],str[64]; int bi=SIZE,bn=SIZE,opt;
  int read(char *s) {
    while (bn) {for (;bi<bn&&buf[bi]<=' ';bi++);if (bi<bn) break; bn=fread(buf,1,SIZE,stdin),bi=0;}
    int sn=0;while (bn) {for (;bi<bn&&buf[bi]>' ';bi++) s[sn++]=buf[bi];if (bi<bn) break; bn=fread(buf,1,SIZE,stdin),bi=0;}s[sn]=0;return sn;
  }
  bool read(int& x) {if(x)x=0;int bf=0,n=read(str); if(!n) return 0; int i=0; if (str[i]=='-') bf=1,i=1; for(x=0;i<n;i++) x=x*10+str[i]-'0'; if(bf) x=-x; return 1;}
  void write(int x) {
    if(!x) obuf[opt++]='0'; else {if(x<0) obuf[opt++]='-',x=-x;int sn=0; while(x)str[sn++]=x%10+'0',x/=10;for (int i=sn-1;i>=0;i--) obuf[opt++]=str[i];}
    if (opt>=(SIZE>>1)){fwrite(obuf,1,opt,stdout); opt=0;}
  }
  void write(char x) {obuf[opt++]=x;if (opt>=(SIZE>>1)){fwrite(obuf,1,opt,stdout); opt=0;}}
	void Fflush() {if (opt) fwrite(obuf,1,opt,stdout); opt=0;}
};
inline int read() {int x; FI(x); return x;}
const int MN=1e5+5;
int n,f[MN],ned[MN];
vi ans; int now,X,Y;
void doit(int x) {
	if(x==0) X++;
	if(x==1) Y++;
	if(x==2) X+=Y;
	if(x==3) Y+=X;
	ans.pb(x+1);
//	cerr<<X<<' '<<Y<<endl;
}
signed main() {
	#ifndef ONLINE_JUDGE
		freopen("pro.in","r",stdin);
		freopen("pro.out","w",stdout);
	#endif
	f[0]=f[1]=1; For(i,2,87) f[i]=f[i-1]+f[i-2];
	int n=read(),mx=-1;
	foR(i,87,0) {
		while(n>=f[i]) {
			if(mx==-1) mx=i;
			n-=f[i];
//			cerr<<mx<<' '<<i<<endl;
			ned[mx-i]++;
		}
	}
//	cerr<<"?"<<endl;
//cerr<<mx<<endl;
	now=(mx&1);
	For(i,0,mx) {
		while(ned[i]) {
			doit(now);
			ned[i]--;
		}
		doit(now+2); now^=1;

	}
	cout<<ans.size()<<endl;
	for(auto it:ans) {
		printf("%d\n",it);
	}
	return FastIO::Fflush(),0;
}


#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define ll long long
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb push_back
#define pob pop_back()
#define Mod (ll)(1e9+7)
#define mod (ll)(998244353)
#define setp(x) setprecision((ll)(n))
#define INF (ll)(1000000000000000000)
using namespace std;
using vi=vector<int>;
using vc=vector<char>;
using vl=vector<long long>;
using vvi=vector<vi>;
using vvl=vector<vl>;
using vpl=vector<pair<ll,ll>>;
using vs=vector<string>;
using pii=pair<int, int>;
using pll=pair<ll,ll>;

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

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

int main() {
  int N,K;
  cin>>N>>K;
  cout<<50*K*N*(N+1)+N*(K*K+K)/2<<endl;
}


#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int a[4];
    cin>>a[0]>>a[1]>>a[2]>>a[3];
    sort(a,a+4);
    cout<<a[0];
}

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
constexpr int int_max = (1<<30)+((1<<30)-1);
constexpr int int_min = -(1<<30)-(1<<30);
constexpr ll ll_max = (1LL<<62)+((1LL<<62)-1LL);
constexpr ll ll_min = -(1LL<<62)-(1LL<<62);
int main(){

   int ans = INT32_MAX;
   for(int i = 0; i < 4; ++i){
       int a;
       cin >> a;
       ans = min(ans, a);
   }

   cout << ans << endl;
}


#include<bits/stdc++.h>

typedef long long ll;
using namespace std;

char maze[15][15];
struct node {
  int x, y;
};

bool cmp1(node a, node b) {
  return a.x != b.x ? a.x < b.x : a.y < b.y;
}

bool cmp2(node a, node b) {
  return a.y != b.y ? a.y < b.y : a.x < b.x;
}

void solve() {
  int n, m, ans = 0; scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%s", maze[i] + 1);
  }
  vector<node> vt;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (maze[i][j] == '#' and maze[i - 1][j] == '.') {
        vt.push_back(node{i, j});
      }
    }
  }
  double t1 = 0;
  for(int j = 0; j < 12; j++) t1++;
  double t2 = 0;
  t2--;
  for (int i = 0; i < 4; i++) t1 -= t2;
  sort(vt.begin(), vt.end(), cmp1);
  for (int i = 1; i < vt.size(); i++) {
    if (vt[i].x == vt[i - 1].x && vt[i].y == vt[i - 1].y + 1) {
      continue;
    }
    ans++;
  }
  t2++;
  t1++;
  ans += 1;
  vt.clear();
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (maze[i][j] == '#' && maze[i + 1][j] == '.') {
        vt.push_back(node{i, j});
      }
    }
  }
  for (int i = 0; i < 4; i++) t1 -= t2;

  sort(vt.begin(), vt.end(), cmp1);
  for (int i = 1; i < vt.size(); i++) {
    if (vt[i].x == vt[i - 1].x && vt[i].y == vt[i - 1].y + 1) {
      continue;
    }
    ans++;
  }
  t2++;
  t1++;
  ans++;
  vt.clear();
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (maze[i][j] == '#' && maze[i][j + 1] == '.') {
        vt.push_back(node{i, j});
      }
    }
  }
  for (int i = 0; i < 4; i++) t1 -= t2;

  sort(vt.begin(), vt.end(), cmp2);
  for (int i = 1; i < vt.size(); i++) {
    if (vt[i].y == vt[i - 1].y && vt[i].x == vt[i - 1].x + 1) {
      continue;
    }
    ans++;
  }
  for (int i = 0; i < 4; i++) t1 -= t2;

  t2++;
  t1++;
  ans += 1;
  vt.clear();
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (maze[i][j] == '#' && maze[i][j - 1] == '.') {
        vt.push_back(node{i, j});
      }
    }
  }
  for (int i = 0; i < 4; i++) t1 -= t2;

  sort(vt.begin(), vt.end(), cmp2);
  for (int i = 1; i < vt.size(); i++) {
    if (vt[i].y == vt[i - 1].y && vt[i].x == vt[i - 1].x + 1) {
      continue;
    }
    ans++;
  }
  for (int i = 0; i < 4; i++) t1 -= t2;
  t2++;
  t1++;
  printf("%d\n", ++ans);
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int T = 1; //cin >> T;
  while(T--) {
    solve();
  }
  return 0;
}

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

///--->>> CONTAINERS <<<---///
using i64 = int64_t;
using ll = long long;
using ld = long double;
using vi = vector<ll>;
using vvi = vector<vector< ll > >;
using vpi = vector<pair<ll,ll> >;
using pi = pair<ll,ll>;
using st = set<ll>;
using stk = stack<ll>;
using kiwi = queue<ll>;
using pkiwi = priority_queue<ll>;
using mp = map<ll,ll>;
using ump = unordered_map<ll,ll>;

///--->>> TEMPLATES <<<---///
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update >;

template<typename T>
T modpow(T a, T b){ll ans = 1; while(b>0) { if(b&1) ans*=a, b--; else a*=a, b>>=1;} return ans; }

///--->>> MACROS<<<---///
const ll mx = 3e6+123;
#define MOD 998244353
#define mod 1000000007
#define isb(z) __builtin_popcount(z)
#define lisb(z) __builtin_popcountll(z)
#define iclz(z) __builtin_clz(z)
#define lclz(z) __builtin_clzll(z)
#define ictz(z) __builtin_ctz(z)
#define lctz(z) __builtin_ctzll(z)
#define REP(i,n) for (ll i=1;i<=n;++i)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

///--->>>OPTIMIZE<<<---///
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

///--->>> DEBUGGER<<<---///
#define dbg(args...) do {cerr<<#args<<" : "; diraf(args); } while(0)
void diraf ()  {cerr << endl;}
template < typename T, typename ... hello>
void diraf( T arg, const hello &... rest) {cerr<<arg<< ' ';diraf(rest...);}

///--->>> RANDOMIZER<<<---///
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
/* usage - just do rng() */

int main(int argc, char* argv[]){
    fastio;
	///freopen("input.txt","r",stdin);
    ///freopen("output.txt","w",stdout);
    ///cout<<fixed<<setprecision(20);
    cin.exceptions(cin.failbit);
   	ll height, width; cin>>height>>width;
   	char ch;
   	vector<vector<bool> > grid(height+1, vector<bool>(width+1, 0));
   	for(ll i = 0 ; i<height; ++i){
   		for(ll j = 0 ; j<width; ++j){
   			cin>>ch;
   			grid[i][j] = (ch=='#'? 1 : 0);
   		}
   	}
   	ll sides = 0;
   	for(ll i = 0 ; i<height - 1; ++i){
   		for(ll j = 0 ; j <width - 1; ++j){
   		    ll borders = 0;
   		    borders ^= grid[i+1][j];
   		    borders ^= grid[i][j+1];
   		    borders ^= grid[i+1][j+1];
   		    borders ^= grid[i][j];
   		    sides += borders;
   		}
   	}
   	cout<<sides<<endl;

return 0;
}


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

typedef __int128 ll;
typedef pair<int,int> ii;

void solve(){
	int n; cin >> n;
	long long ci; cin >> ci;
	ll C = ci;
	vector<tuple<int,int,ll>> v; // point, ev, price
	for (int i=0; i<n; i++){
		int a,b,c; cin >> a >> b >> c;
		v.push_back(make_tuple(a,0,c));
		v.push_back(make_tuple(b+1,1,c));
	}
	sort(v.begin(), v.end());
	ll curr = 0;
	ll answer = 0;
	ll lastpoint = -1;
	for (int i=0; i<n*2; i++){
		int j;
		ll change = 0;
		for (j=i; j<n*2 && get<0>(v[j]) == get<0>(v[i]); j++){
			if (get<1>(v[j]) == 0) change += get<2>(v[j]);
			else change -= get<2>(v[j]);
		}
		if (lastpoint == -1) lastpoint = get<0>(v[i]);
		ll dist = get<0>(v[i]) - lastpoint;
		if (dist > 0){
			answer = answer + min(dist * curr, dist * C);
		}
		curr += change;
		lastpoint = get<0>(v[i]);
		i = j-1;
	}
	vector<int> ans;
	while(answer > 0){
		ans.push_back(answer%10);
		answer = answer / (ll)10;
	}
	reverse(ans.begin(), ans.end());
	for (int i=0; i<ans.size(); i++) cout << ans[i];
	cout << '\n';
}

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

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

	return 0;
}
// NK

#include<bits/stdc++.h>
#define int long long int
//Compute XOR of all numbers from 1 to n in O(1) complexity
#define xor1toN(n) (n&((n&1)-1)&~1 | ((n>>1)^n)&1)
using namespace std;
const int M = 998244353;
const int mod = 1e9+7;
const int inf = 1e18;
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);

int power(int x,int y,int p){
	int 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;
}

void solve(){
	int n;
    cin>>n;
    int a[n];
    int b[n];
    int sum=0;
    int ans=INT_MAX;
    for(int i=0;i<n;i++)
    {
        cin>>a[i]>>b[i];
        sum=a[i]+b[i];
        ans = min(sum,ans);
    }
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(i!=j)
            {
                int val =max(a[i],b[j]);
                ans = min(ans,val);
            }
        }
    }
    cout<<ans<<endl;
}

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


#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1e9
typedef long long ll;
typedef long double ld;

int main(){
  ll n;
  cin >> n;
  vector<pair<double,double>> v(n);
  REP(i,n){
    ll t;
    double l, r;
    cin >> t >> l >> r;
    if(t == 2)r-=0.1;
    else if(t==3)l+=0.1;
    else if(t==4){
      l+=0.1;
      r-=0.1;
    }
    v[i] = {l,r};
  }
  ll cnt = 0;
  REP(i,n-1){
    FOR(j,i+1,n){
      if(v[j].first <= v[i].second && v[i].first <= v[j].second)cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < (n); ++i)
const ll mod = 1000000007;
const ll inf = (1ll << 60);
vector<int> dy {0,1,0,-1};
vector<int> dx {-1,0,1,0};// ← ↓ → ↑

int main(){
    ll x, y; cin >> x >> y;
    ll a, b; cin >> a >> b;
    ll ans = 0;
    while(1){
        if(x > y/a) break;
        if(a*x >= y) break;
        if(a*x >= x + b) break;
        x *= a;
        ans++;
    }
    ans += (y-x-1)/b;
    cout << ans << endl;
}


//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word
//Incase of close mle change language to c++17 or c++14

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007ll //998244353ll
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const long long N=200005, INF=2000000000000000000;
lld pi=3.1415926535897932;
int lcm(int a, int b)
{
    int g=__gcd(a, b);
    return a/g*b;
}
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }
int l;
int dp[300][15];
int fun(int pos, int rem)
{
    if(rem<0)
    return 0;
    if(pos>=l)
    {
        if(rem==0)
        return 1;
        return 0;
    }
    if(dp[pos][rem]!=-1)
    return dp[pos][rem];
    return dp[pos][rem]=fun(pos+1, rem)+fun(pos+1, rem-1);
}
int32_t main()
{
    IOS;
    fill(dp, -1);
    cin>>l;
    cout<<fun(1, 11);
}

#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  FIFO ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
#define  inf 2e18
#define  mod 998244353
#define  bg begin()
#define  en end()
#define  ll long long int
#define  pb push_back
#define  mp make_pair
#define  pii pair<int,int>
#define  pll pair<ll,ll>
#define  vi vector<int>
#define  vll vector<long long int>
#define  vpll vector<pair<long long int,long long int> >
#define  vpii vector<pair<int,int> >
#define  vstr vector<string>
#define  mpii map<int ,int>
#define  mpll map<long long int,long long int >
#define  max3(arr,brr,ser) max(arr,max(brr,ser))
#define  min3(arr,brr,ser) min(arr,min(brr,ser))
#define  setbits(x) __builtin_popcountll(x)
#define  zerobits(x) __builtinctzll(x) //zeros after rightmost set bit
#define  w(t) ll t; cin>>t; while(t--)
#define  vin(v,G) for(int i=0;i<G;i++){ll x;cin>>x; v.pb(x);}
#define  for0(i,G) for(int i=0;i<G;i++)
#define  for1(i,G) for(int i=1;i<=G;i++)
#define  forn(i,arr,brr) for(int i=arr;i<=brr;i++)
#define  forv(it,v) for(auto it=v.begin();it!=v.end();it++)
#define  mem(arr,val) memset(arr,val,sizeof(arr))
#define  Sort(vec) sort(vec.begin(),vec.end())
#define  RSort(vec) sort(vec.rbegin(),vec.rend())
#define  eb emplace_back
#define  bs binary_search
#define  lb(v,arr) lower_bound(v.begin(),v.end(),arr)
#define  ub(v,arr) upper_bound(v.begin(),v.end(),arr)
#define  deb1(x) cerr<<#x<<": "<<x<<" "<<endl
#define  deb2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define  deb3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define  deb4(arr, brr, ser, d) cerr<<#arr<<": "<<arr<<" | "<<#brr<<": "<<brr<<" | "<<#ser<<": "<<ser<<" | "<<#d<<": "<<d<<endl
#define  FF first
#define  SS second
#define  yes "YES"
#define  no "NO"
#define  PI 3.141592653589793238462643383279502884L
#define printv(v) for(int i=0;i<v.size();i++) cout<<v[i]<<" "
// find_by_order(p)  returns iterator to kth element starting from 0;
// order_of_key(p) returns count of elements strictly smaller than p;
//order of key returns the index if the element was present.(If not present)
template <typename T>
using pbds = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

ll Ceil(ll arr, ll brr) {return arr / brr + (arr % brr != 0);}
ll Logn(ll G, ll right) {return (G > right - 1) ? 1 + Logn(G / right, right) : 0;}
ll fastModExp(ll arr, ll brr) { ll res = 1; while (brr > 0) { if (brr & 1)res = (res * arr) % mod; arr = (arr * arr) % mod; brr = brr >> 1; } return res;}
ll GCD(ll arr, ll brr) { if (brr == 0)return arr; else  return GCD(brr, arr % brr);}
//Chrnlgy: Binary Search,Greedy,dp,dfs and similar
int main()
{
	// w(t)
	// {
	ll n;
	cin >> n;
	string s;
	cin >> s;
	ll q;
	cin >> q;
	string s1, s2;
	s1 = s.substr(0, n);
	s2 = s.substr(n, n);
	while (q--) {
		ll t, a, b;
		cin >> t >> a >> b;
		if (t == 1)
		{
			a--;
			b--;
			if (a < s1.length() && b < s1.length())
			{
				swap(s1[a], s1[b]);
			}
			else if (a >= s1.length() && b >= s1.length())
				swap(s2[a - n], s2[b - n]);
			else
			{
				char ch = s1[a];
				s1[a] = s2[b - n];
				s2[b - n] = ch;
			}

		}
		if (t == 2)
		{
			swap(s1, s2);

		}
	}
	cout << s1 + s2 << endl;
	return 0;
}


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

int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output1.txt","w",stdout);
    #endif
    string s;
    cin >> s;
    if( (s[0]==s[1] && s[1]==s[2])){
    	cout << "Won";
    }
    else{
    	cout << "Lost";
    }
    return 0;
}

#include<bits/stdc++.h>

#define ll long long

using namespace std;

vector<int> primes;

ll isPrime(ll n){
	if(n==1){
		return 1;
	}
	for(int j=2; j*j<=n; j++){
		if(n%j==0){
			return 0;
		}
	}
	return 1;
}

void solve(){
	string in; cin >> in;
	set<char> s;
	for(int i=0; i<in.size(); i++){
		s.insert(in[i]);
	}
	if(s.size()==1){
		cout << "Won\n";
	}else{
		cout << "Lost\n";
	}
	return;
}

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


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD=1000000000+7;

//template<typename T>
vector<ll> findall(string target,string find_word){
    vector<ll> a;
    ll pos=target.find(find_word);
    while(pos!=std::string::npos){
        a.push_back(pos);
        pos=target.find(find_word,pos+find_word.length());
    }
    return a;
}

int main(){
    double n;cin>>n;
    if(floor(n*1.08)<206)cout << "Yay!";
    else if(floor(n*1.08)==206)cout << "so-so";
    else cout << ":(";
#ifdef _DEBUG //-D_DEBUG
#endif
}

#include<cstdio>
using namespace std;
int main(void)
{
	int n;
	scanf("%d",&n);
	if(n%2==0)	printf("White\n");
	else	printf("Black\n");
	return 0;
}