// abc180_a
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF (ll)(1e9)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int idx=0;idx<(n-1);idx++) cout << (vec)[idx] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << "\n";}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N, A, B;
    cin >> N >> A >> B;
    int ans = N - A + B;

    print(ans);

    return 0;
}

#ifdef _LOCAL
    #include "local_include.hpp"
#else
    #include <bits/stdc++.h>
    using namespace std;
#endif
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;

#define fto(i, s, e) for (int i = (s); i <= (e); ++i)
#define fto1(i, s, e) for (int i = (s); i < (e); ++i)
#define fdto(i, s, e) for (int i = (s); i >= (e); --i)
#define fit(it, a) for (auto it = (a).begin(); it != (a).end(); ++it)
#define fat(i, a) for (auto i : (a))

#define ll long long
#define ii pair<int, int>
#define pll pair<ll, ll>
template<class T, class Cmp = less<T>> using oss = tree<T, null_type, Cmp, rb_tree_tag, tree_order_statistics_node_update>;

#define bc __builtin_popcountll
#define y1 ansdj
#define endl '\n'
#define ff first
#define ss second
#define sz(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define bug(...) _bug(cout, __VA_ARGS__)
#define buga(a, s, e) cout << '{'; if (e < s) cout << '}'; else fto (__i, s, e) cout << a[__i] << " }"[__i == e]; cout << endl

template<class T1, class T2> ostream& operator<<(ostream &os, pair<T1, T2> const &v) {
    return os << '(' << v.ff << ", " << v.ss << ')';
}

template<typename T>
void _bug(ostream &os, T const &var) { os << var << endl; }

template<typename T, typename... Args>
void _bug(ostream &os, T const &var, Args const &... args) {
    os << var << ' ';
    _bug(os, args...);
}

double const pi = acos(-1);
#define oo 1000000007
#define OO 1000000000000000003LL
int const maxn = 1e5+3;

ii a[maxn];

#define multi_test 0
void _main() {
    int cap, m, T;
    cin >> cap >> m >> T;

    ll n = cap;
    fto (i, 1, m) {
        cin >> a[i].ff >> a[i].ss;
        n -= a[i].ff - a[i-1].ss;
        if (n <= 0) {
            bug("No");
            return;
        }
        n = min(1LL*cap, n + (a[i].ss - a[i].ff));
    }

    n -= T - a[m].ss;
    bug(n > 0 ? "Yes" : "No");
}

int main() {
    #ifdef _LOCAL
        freopen("main.inp", "r", stdin);
        freopen("main.out", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    int t = 1;
    if (multi_test) cin >> t;
    while (t--) {
        _main();
    }

    #ifdef _LOCAL
        cerr << 0.001*clock() << endl;
    #endif
    return 0;
}


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

#define pb push_back
#define S second
#define F first
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vll vector<long long int>
#define pll pair<long long int,long long int>
#define mod 1000000007
#define mod2 998244353
#define ll long long int
#define ld long double
#define pi 3.141592653589793238
#define Endl endl
#define endl "\n"
const int N = 5e5 + 5;
const ll infP = 1e18;

void solve()
{
        ll n , x;
        cin >> n >> x;
        for(ll i=0;i<n;i++)
        {
                ll y;
                cin >> y;
                if(y != x)
                        cout << y << " ";
        }
}

void debug(ll tt) {}

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


#define NOMINMAX
#define TEST_MODE true

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep2(i,a,b) for(int i=(a);i<(int)(b);++i)
#define rrep(i,n) for(int i=(n)-1;i>=0;--i)
#define rrep2(i,a,b) for(int i=(a)-1;i>=(int)b;--i)
#define range(i,a,b,c) for(int i=a;c>0?i<b:i>b;i+=c)

#define chmax(a,b) (a=(a)<(b)?(b):(a))
#define chmin(a,b) (a=(a)>(b)?(b):(a))

#define i1(a) cin>>a;
#define i2(a,b) cin>>a>>b;
#define i3(a,b,c) cin>>a;i2(b,c);

#define p1(a) cout<<a<<endl;
#define p2(a,b) cout<<a<<" ";p1(b);
#define p3(a,b,c) cout<<a<<" ";p2(b, c);

#define abp(o,a,b) p1(((o)?a:b))
#define YEP(x) abp(x,"YES","NO")
#define Yep(x) abp(x,"Yes","No")

#define all(a) begin(a),end(a)
#define ifnot(a) if(!(a))
#define int long long

#ifdef LOCAL_ENV

#if TEST_MODE==true
const bool test=true;
#define dump(x) cerr<<#x<<" : "<<(x)<< " "
#define dumpl(x) dump(x)<<endl
#else
const bool test=false;
#define dump(x)
#define dumpl(x)
#endif

#else
const bool test=false;
#define dump(x)
#define dumpl(x)
#endif

using ll = int;
using ull = unsigned int;
using ld = long double;

ll dx[]={1,0,-1,0};
ll dy[]={0,1,0,-1};
const ll inf=(ll)1<<60;
const ll undefined=inf;
const ll INFL=(ll)1<<60;
ll mod_n=(ll)1e9+7;
const double eps=1e-10;
typedef long double Real;
// return -1, 0, 1
ll sgn(const Real&r){return(r>eps)-(r<-eps);}
ll sgn(const Real&a,const Real&b) {return sgn(a-b);}

const ll MAX = (ll)2e5 + 5;

vector<string> split(const string&str,char sep){vector<string> v;stringstream ss(str);string buffer;while (getline(ss, buffer, sep)) v.push_back(buffer);return v;}

string join(const vector<string>& v, const string delim = 0){string s;if(!v.empty()){s+=v[0];for(decltype(v.size()) i=1,c=v.size();i<c;++i){if(delim!="")s+=delim;s+=v[i];}}return s;}

string operator*(const string&s,const ll&n){string res="";rep(i,n)res+=s;return res;}

#define sum(a) accumulate(all(a),0ll)

template<typename T>T gcd(T a,T b){T c;while(a!=0){c=a;a=b%a;b=c;};return b;}
#define bit_cnt(n) [](int n){int c=0;while(N){if(N&1)c++;N>>=1;}return c;};

template<typename T>void prll_vec(ostream& o,vector<T> a){rep(i,a.size()-1)o<<a[i]<<" ";o<<a.back()<<endl;}

ll pow_n(ll x,ll n){ll r=1;while(n>0){if(n&1)r=r*x;x=x*x;n>>=1;}return r;}

ll H,W;

#define grid_ng(y,x) (y<0||y>=H||x<0||x>=W)

ll div_ceil(ll a,ll b){ll r=a/b;if(a%b!=0)r++;return r;}

struct Point{ll x,y;bool operator<(const Point&r)const{if(x!=r.x)return x<r.x;return y<r.y;}};

int n, k;
int t[10][10];
bool visited[10];
int visited_n = 0;
int cost = 0;

class Solver {
public:
	int dfs(int curId) {
		if (visited_n == n - 1) {
			return cost + t[curId][0] == k;
		}

		int cnt = 0;
		rep(i, n) {
			if (visited[i] == false) {
				visited[i] = true;
				cost += t[curId][i];
				visited_n++;

				cnt += dfs(i);

				visited[i] = false;
				cost -= t[curId][i];
				visited_n--;
			}
		}

		return cnt;
	}

	void solve() {
		cin >> n >> k;
		rep(i, n) {
			rep(j, n) {
				cin >> t[i][j];
			}
		}
		visited[0] = true;

		cout << dfs(0) << endl;
	}
};

signed main(){srand((unsigned int)time(NULL));cout<<fixed<<setprecision(20);auto ptr=new Solver();ptr->solve();delete ptr;return 0;}

#include <bits/stdc++.h>
#define pb push_back
#define SZ(x) ((int)(x.size()))
#define FOR(i,s,n) for (ll i = (s); (i) < (n); ++i)
#define FORD(i,s,l) for (ll i = (s); (i) >= l; --i)
#define F first
#define S second
#define TC int __tc; cin >> __tc; FOR(case_num,1,__tc+1)
#define TEST(x,i) ((x)&(1ll<<(i)))
#define SET(x,i) ((x)|(1ll<<(i)))
#define FLIP(x,i) ((x)^(1ll<<(i)))
#define CLEAR(x,i) ((x)&~(1ll<<(i)))
const double pi = 4 * atan(1);
using namespace std;
typedef long long ll;

map<int,int> m;
int op[205];
int a[205];
int b[205];

bool dp[205][205];
bool dp2[205][205];

bool solve(int start, int end) {
	bool &ret = dp[start][end];
	if (dp2[start][end]){
		return ret;
	}
	dp2[start][end]=true;

	int d = (end-start)/2;

	bool good = true;

	for (int i = start; i+d < end && good; i++){
		if (op[i] || op[i+d]) {
			if (op[i] != i+d) {
				good = false;
			}
		}
		if (m.count(i)){
			if (a[m[i]] != i) {
				good = false;
			}
		}
		if (m.count(i+d)) {
			if (b[m[i+d]] != i+d) {
				good = false;
			}
		}
		if (m.count(i)&&m.count(i+d)){
			if (m[i]!=m[i+d]) {
				good = false;
			}
		}
	}

	if (good) {
		return ret = true;
	}

	for (int i = start+2; i < end; i+=2){
		if (solve(start,i) && solve(i,end)) {
			return ret = true;
		}
	}

	return ret = false;
}

bool answer() {
	int n;
	cin >> n;
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
		if (a[i]!=-1) {
			m[a[i]]=i;
			cnt++;
		}
		if (b[i]!=-1) {
			m[b[i]]=i;
			cnt++;
		}
		if (a[i]!=-1 && b[i]!=-1){
			op[a[i]]=b[i];
			op[b[i]]=a[i];
		}
	}

	if(cnt!=(int)m.size()) return false;

	for (int i = 0; i < n; i++) {
		if (a[i] != -1 && b[i] != -1 && a[i] >= b[i])
			return false;
	}

	return solve(1,2*n+1);

}

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

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


#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#include<bitset>
#include<functional>
#include <fstream>
//#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i, x) for(ll i = 0; i < x; i++)
#define rep2(i, x) for(ll i = 1; i <= x; i++)
#define rep3(i, x, y) for(ll i = x; i < y; i++)
#define rep4(i, x) for(ll i = x; i >= 0; i--)
#define all(a) (a).begin(),(a).end()
#define puts(x) cout << (x) << "\n"
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const int intINF = 1000000000;
const ll mod = 1000000007;
const ll MOD = 998244353;
const ld pi = 3.141592653589793238;
//const ld EPS = 1e-9;

bool isprime(int p) {
	if (p == 1) return false;
	for (int i = 2; i < p; i++) {
		if (p % i == 0) return false;
	}
	return true;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
//main関数内に extGCD(a, b, x, y); でx, yに解が格納
ll extGCD(ll a, ll b, ll& x, ll& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	ll d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll keta(ll n) {
	ll res = 0;
	while (n >= 1) {
		res += n % 10; n /= 10;
	}
	return res;
}
ll modpow(ll x, ll y) {
	ll res = 1;
	while (y) {
		if (y % 2) { res *= x; res %= mod; }
		x = x * x % mod; y /= 2;
	}
	return res;
}
ll nCk(ll n, ll k) {
	ll a = 1, b = 1;
	for (int h = n - k + 1; h <= n; h++) { a *= h; a %= mod; }
	for (int h = 1; h <= k; h++) { b *= h; b %= mod; }
	return a * modpow(b, mod - 2) % mod;
}
//printf("%.10f\n", n);
typedef pair <ll, ll> P;
typedef pair <ld, ll> pp;
ll dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
struct edge { ll to, cost; };
struct status {
	ll ima;
	ll cost;

	bool operator<(const status& rhs) const { return cost < rhs.cost; };
	bool operator>(const status& rhs) const { return cost > rhs.cost; };
};

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

	//input
	ll n; string s; cin >> n >> s;
	vector<ll>a(n + 1); ll mi = INF;
	rep(i, n + 1) {
		cin >> a[i]; //mi = min(mi, a[i]);
	}
	rep(i, n) {
		if (s[i] == '<') {
			mi = min(mi, a[i + 1] - a[i]);
		}
		else {
			mi = min(mi, a[i] - a[i + 1]);
		}
	}
	vector<vector<ll>> ans(n + 2, vector<ll>(10002));
	rep(i, n + 1) {
		ll cnt = a[i];
		rep(j, mi) {
			ans[i][j] = cnt / (mi - j); cnt -= ans[i][j];
		}
	}
	cout << mi << endl;
	rep(j, mi) {
		rep(i, n + 1) {
			if (i != 0) { cout << ' '; }
			cout << ans[i][j];
		}
		cout << endl;
	}
	return 0;
}

#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<sstream>
#include<cstring>
#include<cstdio>
#include<string>
#include<deque>
#include<cmath>
#include<queue>
#include<set>
#include<map>

using namespace std;

struct Diff {
	int thePos;
	long long rPos;
	long long rNeg;
	long long max;

	long long a;
	long long b;

	int d;
};

Diff diffs[100010];

int k;
long long n, m;
//long long a[100010];
//long long rPos[100010];
//long long rNeg[100010];
//
//long long b[100010];

bool compare(const Diff &a, const Diff &b) {
	if (a.max == b.max) {
		return a.thePos < b.thePos;
	} else {
		return a.max > b.max;
	}
}

bool comparePos(const Diff &a, const Diff &b) {
	return a.thePos < b.thePos;
}

int main(void)
{
	scanf("%lld%lld%lld", &k, &n, &m);
	for (int i = 0 ; i < k ; i++) {
		scanf("%lld", &(diffs[i].a));
		diffs[i].rPos = diffs[i].a * m % n;
		diffs[i].rNeg = n - diffs[i].rPos;
		diffs[i].thePos = i;

		//似乎不会有相等额情况
		if (diffs[i].rPos > diffs[i].rNeg) {
			diffs[i].max = diffs[i].rPos;
		} else {
			diffs[i].max = diffs[i].rNeg;
		}
	}

	sort(diffs, diffs + k, compare);
	long long balance = 0;
	//balance的值是固定的！
	for (int i = 0 ; i < k ; i++) {
		//似乎不会有相等额情况
		if (diffs[i].rPos < diffs[i].rNeg) {
			diffs[i].d = 1;	//正向
			balance = balance + diffs[i].rPos;
		} else {	//负向
			diffs[i].d = -1;
			balance = balance - diffs[i].rNeg;
		}
	}

	int pPos = k - 1;
	if (balance > 0) {
		while (balance > 0) {
			if (diffs[pPos].d == 1) {
				diffs[pPos].d = -1;
				balance = balance - n;
			}
			pPos--;
		}
	} else if (balance < 0) {
		while (balance < 0) {
			if (diffs[pPos].d == -1) {
				diffs[pPos].d = 1;
				balance = balance + n;
			}
			pPos--;
		}
	}

	sort(diffs, diffs + k, comparePos);
	for (int i = 0 ; i < k ; i++)  {
		diffs[i].b = diffs[i].a * m / n;

		if (diffs[i].d < 0) {
			diffs[i].b++;
		}
	}

	for (int i = 0 ; i < k ; i++)  {
		printf("%d ", diffs[i].b);
	}
	printf("\n");

	return 0;
}


#include"bits/stdc++.h"
using namespace std;
#define ll long long
#define ul unsigned long long
#define ui unsigned int
#define ri register int
#define pb push_back
#define mp make_pair
char p[30]={'0','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
inline ll rd(){
	ll x=0,flag=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') flag=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+(ch^48);ch=getchar();}
	return x*flag;
}
ll n;
inline int lowbit(int x){return x & ( - x ) ;}
int main()
{
	n=rd();int ok=0;
    for(ll i=1;i*i<=n;++i){
        if(n%i==0){
            if(i&1||((n/i)&1)){
                ok+=2;
                if(i*i==n) continue;
                if((i&1)&&((n/i)&1)) ok+=2;
            }
        }
    }
    cout<<ok;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;

#define rep(i, n) for (int i=0; i<(n); ++i)
#define each(v, i) for (auto i : v)
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define maxs(x, y) x = max(x, y)
#define mins(x, y) x = min(x, y)
#define pcnt __builtin_popcount
#define rng(a) a.begin(), a.end()
#define out(v) cout << v << endl

template<typename T> using vc = vector<T>;
template<typename T> using vv = vector<vector<T>>;
using vi = vc<int>;

int main() {
    int N; cin >> N;
    N = N * 108/100;
    int limit = 206;
    if (N < limit) out("Yay!");
    else if (N == limit) out("so-so");
    else out(":(");
    return 0;
}


#include <bits/stdc++.h>
//#include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using namespace std;
//using namespace atcoder;
const int mod = 998244353;
const int INF =1e9+1;
int ans=INF;

int main(){
    int h,w,n,m;cin>>h>>w>>n>>m;
    vector<vector<int>> math(h,vector<int> (w,0));
    vector<pair<int,int>> light(n);
    rep(i,n){
        int a,b;cin>>a>>b;
        math[a-1][b-1]=1;
        light[i]=make_pair(a-1,b-1);
    }
    rep(i,m){
        int a,b;cin>>a>>b;
        math[a-1][b-1]=2;
    }
    rep(i,n){
        int H=light[i].first,W=light[i].second;
        int W1=W;
        if(math[H][W]==3)continue;
        while(++W<w&&math[H][W]!=2){
            math[H][W]=3;
        }
        while(--W1>=0&&math[H][W1]!=2){
            math[H][W1]=3;
        }
    }
    rep(i,n){
        int H=light[i].first,W=light[i].second;
        int H1=H;
        if(math[H][W]==4)continue;
        while(++H<h&&math[H][W]!=2){
            math[H][W]=4;
        }
        while(--H1>=0&&math[H1][W]!=2){
            math[H1][W]=4;
        }
    }
    int ans=0;
    rep(i,h)rep(j,w){
        if(math[i][j]==3||math[i][j]==4||math[i][j]==1)ans++;
    }
    cout<<ans<<endl;
}

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define pb push_back

int32_t  main(){
    int n,m,a,b;
    cin>>n>>m>>a>>b;
    int grid[n][m];
    memset(grid,-1,sizeof(grid));
    //for bulbs
    for(int i=0;i<a;i++){
        int r,c;
        cin>>r>>c;
        r--;c--;
        grid[r][c]=1;
    }
    //for blocks
    for(int i=0;i<b;i++){
        int r,c;
        cin>>r>>c;
        r--;c--;
        grid[r][c]=2;
    }
    /*for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cout<<grid[i][j]<<" ";
        }
        cout<<endl;
    }*/
    int ans[n][m];
    memset(ans,0,sizeof(ans));
    //now solve for individual rows first
    //yaar ab batao aage kya kare ya phir mtlb kya karna chahiye more precisely
    for(int i=0;i<n;i++){
        int s=0;
        int lit=0;
        for(int j=0;j<m;j++){
            //block aa gya
            if(grid[i][j]==2){

                s=j+1;
                lit=0;
            }
            //bulb aa gya
            else if(grid[i][j]==1){
                while(s<=j){
                    ans[i][s]=1;
                    s++;
                }
                lit=1;
                s=j+1;

            }
            else {
                if(lit) ans[i][j]=1;
            }
        }
    }

    //now solve for columns

    for(int j=0;j<m;j++){
        int s=0;
        int lit=0;
        for(int i=0;i<n;i++){
            //block aa gya
            if(grid[i][j]==2){

                s=i+1;
                lit=0;
            }
            //bulb aa gya
            else if(grid[i][j]==1){
                while(s<=i){
                    ans[s][j]=1;
                    s++;
                }
                lit=1;
                s=i+1;

            }
            else {
                if(lit) ans[i][j]=1;
            }
        }
    }

    int cnt=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cnt+=ans[i][j];
        }
        //cout<<endl;
    }
    cout<<cnt<<endl;

}


# include <bits/stdc++.h>
using namespace std;
# define rep(i,a,n) for (int i=a; i<=n; ++i)
# define per(i,a,n) for (int i=a; i>=n; --i)
# define bug puts("H");
# define pb push_back
# define mp make_pair
# define all(x) (x).begin(), (x).end()
# define SZ(x) (int)x.size()
# define fi first
# define se second
# define lch p<<1,l,mid
# define rch p<<1|1,mid+1,r
# define mem(a,b) memset(a,b,sizeof(a))
# define INF 1000000001
# define MOD 1000000007
typedef vector<int> Vi;
typedef long long i64;
typedef pair<int, int> Pi;
mt19937 mrand(random_device{}());
int rnd(int x) {return mrand()%x;}
i64 powmod(i64 a, i64 b){i64 res=1;a%=MOD;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
i64 Inv(i64 b){return powmod(b,(i64)MOD-2);}
typedef long long ll;

const int N = 100005;
const double eps = 1e-9;
const double inf = 1e18;

char s[1005];

int main ()
{
    int T;
    cin >> T;
    string str = "atcoder", tmp;
    while (T--) {
        cin >> tmp;
        int ans = INF;
        if (str < tmp) ans = 0;
        else {
            int sz = SZ(tmp);
            rep(i,1,sz-1) {
                rep(j,0,min(i-1,6)) {
                    string t;
                    if (j) t += tmp.substr(0,j);
                    t += tmp[i];
                    t += tmp.substr(j,i-j);
                    t += tmp.substr(i+1,sz-1-i);
                    if (str < t) ans = min(ans, i-j);
                    //cout << i << " " << j << " " << t << endl;
                }
            }
        }
        if (ans == INF) cout << -1 << endl;
        else cout << ans << endl;
    }
    return 0;
}

#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

int N, M, K, T, H, W, L, R;
//long long int N, M, K, T, H, W, L, R;

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

	cin >> T;
	string t = "atcoder";
	while (T--) {
		string s;
		cin >> s;
		if (t < s) {
			cout << 0 << endl;
			continue;
		}
		int ans = MOD;
		for (int i = 0; i < s.size() && i < t.size(); i++) {
			for (int j = i + 1; j < s.size(); j++) {
				if (t[i] < s[j]) {
					ans = min(ans, j - i);
				}
			}
			if (s[i] != t[i])break;
		}
		if (ans == MOD)ans = -1;
		cout << ans << endl;
	}
}


#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
long long a[45],b[45],d=0,t,n;

void DFS(int c,long long r);
int main()
{
	cin>>n>>t;
	for(int i = 1;i <= n;i++)
	{
		scanf("%d",&a[i]);
	}
	sort(a+1,a+n+1);
	reverse(a+1,a+n+1);
	for(int i=n;i>=1;i--)
	{
		b[i]=b[i+1]+a[i];
	}
	DFS(0,t);
	cout << d;
	return 0;
}
void DFS(int c,long long r)
{
	if(c>n)
	{
		return;
	}
	d=max(d,t-r);
	if(r==0)
	{
		cout<<t;
		exit(0);
	}
	if(t-r+b[c+1]<=d)
	{
		return;
	}
	if(r-a[c+1]>=0)
	{
		DFS(c+1,r-a[c+1]);
	}
	DFS(c+1,r);
}

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const ll inf=1e9+7;
const ll INF=1e18;
const ll mod=99824453;
vin dx={-1,0,1,0};
vin dy={0,1,0,-1};

int main(){
    int n;ll t;cin>>n>>t;
    vll a(n);rep(i,n)cin>>a[i];
    int k=n/2,h=n-k;
    vll x,y;
    ll sum;
    rep(i,(1<<k)){
        bitset<22> tmp(i);
        sum=0;
        rep(j,k)if(tmp[j])sum+=a[j];
        x.push_back(sum);
    }
    rep(i,(1<<h)){
        bitset<22> tmp(i);
        sum=0;
        rep(j,h)if(tmp[j])sum+=a[k+j];
        y.push_back(sum);
    }
    sort(all(y));
    ll ans=0;
    int l,r,m;
    rep(i,x.size()){
        l=-1;r=y.size();
        while(r-l>1){
            m=(l+r)/2;
            if(y[m]+x[i]>t)r=m;
            else l=m;
        }
        if(l>-1)ans=max(ans,y[l]+x[i]);
    }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
long long INF = 1000000000000000000;
int main(){
    long long A, B;
    cin >> A >> B;
    vector<long long> d;
    for(int i = 2; i <= 72; i++){
        if(i == 2) d.push_back(i);
        if(i % 2 == 0) continue;
        bool flag = true;
        for(int j = 2; j * j <= i; j++){
            if(i % j == 0) flag = false;
        }
        if(flag) d.push_back(i);
    }
    int L = d.size();
    vector<vector<long long>> dp((B - A + 2), vector<long long>(1 << L));
    int ind = 0;
    dp[0][0] = 1;
    for(long long i = A; i <= B; i++){
        long long bit = 0;
        for(int k = 0; k < L; k++){
            if(i % d[k] == 0) bit |= (1 << k);
        }
        for(int j = 0; j < (1 << 20); j++){
            if((j & bit) == 0) dp[ind + 1][j | bit] += dp[ind][j];
            dp[ind + 1][j] += dp[ind][j];
        }
        ind++;
    }
    long long ans = 0;
    for(int i = 0; i < (1 << L); i++) ans += dp[B - A + 1][i];
    cout << ans << endl;
}

#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define pii pair<ll,ll>
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define autoitr(x,it) for(auto it = x.rbegin(); it != x.rend(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

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

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

using namespace std;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

vector<vector<ll>> g;

ll powa[64];

ll get(vector<ll> &v)
{
    ll n = v.size();
    if(n<2)
        return n;
    ll fst = (n+1)/2, sec = n/2;
    vector<ll> v1,v2;
    rep(n)
        if(i<fst)
            v1.pb(v[i]);
        else v2.pb(v[i]);
    ll self1[fst], self2[sec], cross[fst];
    rep(fst)
        self1[i] = powa[fst] - 1;
    rep(sec)
        self2[i] = powa[sec] - 1;
    rep(fst)
        cross[i] = powa[sec] - 1;
    for(ll i=0;i<fst;i++)
        for(ll j=0;j<fst;j++)
        {
            if(i != j && __gcd(v1[i],v1[j]) > 1)
                self1[i]-=powa[j];
        }
     for(ll i=0;i<sec;i++)
        for(ll j=0;j<sec;j++)
        {
            if(i != j && __gcd(v2[i],v2[j]) > 1)
                self2[i]-=powa[j];
        }
    for(ll i=0;i<fst;i++)
        for(ll j=0;j<sec;j++)
        {
            if(__gcd(v1[i],v2[j]) > 1)
                cross[i]-=powa[j];
        }
    vector<ll> s1, s2;
    for(ll mask=1;mask<powa[fst];mask++)
    {
        ll allowed = powa[fst] - 1;
        for(ll j=0;j<fst;j++)
            if(powa[j]&mask)
                allowed&=self1[j];
        if((mask&allowed) != mask)
            continue;
        s1.pb(mask);
    }

    for(ll mask=1;mask<powa[sec];mask++)
    {
        ll allowed = powa[sec] - 1;
        for(ll j=0;j<sec;j++)
            if(powa[j]&mask)
                allowed&=self2[j];
        if((mask&allowed) != mask)
            continue;
        s2.pb(mask);
    }

    ll dp[sec+1][powa[sec]];
    memset(dp,0,sizeof(dp));
    for(auto &x : s2)
        dp[sec][x] = 1;
    for(ll bit=sec-1;bit>-1;bit--)
    {
        for(ll mask=0;mask<powa[sec];mask++)
        {
            if(powa[bit]&mask)
                dp[bit][mask]+=(dp[bit+1][mask] + dp[bit+1][mask^powa[bit]]);
            else dp[bit][mask]+=(dp[bit+1][mask]);
        }
    }

    ll ans = 0;
    for(auto &x : s1)
    {
        ll allowed = powa[sec] - 1;
        for(ll j=0;j<fst;j++)
            if(powa[j]&x)
                allowed&=cross[j];
        ans+=dp[0][allowed];
    }

    ans+=((ll)s1.size());
    ans+=((ll)s2.size());
    return ans;
}

int main()
{
  FAST/**/

  powa[0] = 1;
  for(ll i=1;i<64;i++)
      powa[i] = powa[i-1]*2;

  ll a,b;
  cin>>a>>b;

  vector<ll> even;
  vector<ll> nums;
  for(ll i=a;i<=b;i++)
        if(i%2 == 0)
            even.pb(i);
        else nums.pb(i);

  ll ans = 1;
  ans+=get(nums);

  for(ll i=0;i<even.size();i++)
  {
      vector<ll> v1;
      for(ll j=0;j<nums.size();j++)
      {
          if(__gcd(nums[j], even[i]) == 1)
                v1.pb(nums[j]);
      }
      ans+=(1ll + get(v1));
  }

  cout<<ans<<'\n';

  return 0;
}


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

#define int         long long

#define read(a)		for(auto &z : a) cin >> z;
#define	write(a)	{for(auto &z : a) cout << z << ' ';cout << '\n';}
#define print(a)	cout << a << "\n";
#define all(a) 		a.begin(), a.end()

int32_t main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
    int _ = 1, n, m;
    // cin >> _;

    outer : while(_--) {
        // int a, b;
        // cin >> a >> b;
        // double ans = ((a*1.0)/100.0) * b;
        // cout << fixed << setprecision(9) << ans << "\n";
        cin >> n;
        vector<int> a(n);
        read(a);
        sort(all(a));
        int flag = 1;
        for(int i = 0 ; i < n ; i++) {
            flag &= (a[i] == i+1);
        }
        cout << (flag ? "Yes\n" : "No\n");
    }
    return 0;
}

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

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

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

const ll INF = 1001001001001001001;
void solve(long long N, std::vector<long long> a, std::vector<long long> t, long long Q, std::vector<long long> x){
    ll mn = -INF;
    ll mx = INF;
    ll bias = 0;
    rep(i, N) {
        if (t[i] == 1) {
            bias += a[i];
            mn += a[i];
            mx += a[i];
        } else if (t[i] == 2) {
            mn = max(mn, a[i]);
            mx = max(mx, a[i]);
        } else {
            mn = min(mn, a[i]);
            mx = min(mx, a[i]);
        }
    }
    rep(i, Q) {
        ll n = x[i] + bias;
        if (mn <= n && n <= mx) {
            cout << n << endl;
        } else if (n < mn) {
            cout << mn << endl;
        } else {
            cout << mx << endl;
        }
    }
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    std::vector<long long> t(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
        scanf("%lld",&t[i]);
    }
    long long Q;
    scanf("%lld",&Q);
    std::vector<long long> x(Q);
    for(int i = 0 ; i < Q ; i++){
        scanf("%lld",&x[i]);
    }
    solve(N, std::move(a), std::move(t), Q, std::move(x));
    return 0;
}


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

#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << '\n'
typedef long long ll;
using P = pair<int,int>;
using pll = pair<ll,ll>;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
//const ll MOD = 998244353;

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

void solve(){
    int n;  cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    vector<ll> c(n + 1, 0LL), d(n + 1, 0LL);
    for (ll i = 0; i < n; i++) {
        if(i % 2 == 0){
            c[i + 1] = c[i] + a[i];
            d[i + 1] = d[i];
        }
        else{
            c[i + 1] = c[i];
            d[i + 1] = d[i] + a[i];
        }
    }

    map<ll,ll> mp;
    for (ll i = 0; i < n + 1; i++) mp[c[i] - d[i]]++;

    ll ans = 0;
    for (auto p : mp) {
        ll w = p.second;
        ans += w * (w-1) / 2;
    }
    print(ans);
    return;
}

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

    int t;
    //cin >> t;
    t = 1;

    while(t--) solve();
    return 0;
}

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

vector<string> split(const string & s, char c=' ') {
   vector<string> v; stringstream ss(s); string x;
   while (getline(ss, x, c)) v.emplace_back(x); return move(v);
}
template<typename T, typename... Args>
inline string arrStr(T arr, int n) {
   stringstream s; s << "[";
   for(int i = 0; i < n - 1; i++) s << arr[i] << ",";
   s << arr[n - 1] << "]";
   return s.str();
}
#define EVARS(args...) {__evars_begin(__LINE__); __evars(split(#args, ',').begin(), args);}
inline void __evars_begin(int line) { cerr << "#" << line << ": "; }
template<typename T> inline void __evars_out_var(vector<T> val) { cerr << arrStr(val, val.size()); }
template<typename T> inline void __evars_out_var(T* val) { cerr << arrStr(val, 10); }
template<typename T> inline void __evars_out_var(T val) { cerr << val; }
inline void __evars(vector<string>::iterator it) { cerr << endl; }
template<typename T, typename... Args>
inline void __evars(vector<string>::iterator it, T a, Args... args) {
   cerr << it->substr((*it)[0] == ' ', it->length()) << "=";
   __evars_out_var(a);
   cerr << "; ";
   __evars(++it, args...);
}
template<typename T>
void maxa(T &a,T b){
  if(a<b) a=b;
}
template<typename T>
void mina(T &a,T b){
  if(a>b) a=b;
}

#define int long long
#define ll int
// const int inf=1e18;
#define F first
#define S second
#define Z(c) (int)(c).size()
#define pii pair<int,int>
const int mod=1e9+7;
const int N=2e5+10;

 vector<int> adj[N];
 int ct,vt[N];

 void dfs(int x){
     if(vt[x]) return;
     vt[x]=1;
     ct++;
     for(int i:adj[x]) dfs(i);
 }

void boomer(){
  int n; cin>>n;
  vector<int> v(n);
  for(int &x:v) cin>>x;

  int lt=0,rt=n-1;

  while(lt<rt){
      if(v[lt]!=v[rt]){
         adj[v[lt]].push_back(v[rt]);
         adj[v[rt]].push_back(v[lt]);
      }
      lt++;
      rt--;
  }

  int ans=0;

  for(int x:v){
      ct=0;
      dfs(x);
      ans+=max(0LL,ct-1);
  }

  cout<<ans;

}

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

  int tc=1;

  // cin>>tc;
  for(int i=1;i<=tc;++i)
  {
  // cout<<"Case #"<<i<<": ";
  boomer();
  if(i<tc)
  cout<<"\n";
  }

  return 0;
  }


    #include <bits/stdc++.h>

    using namespace std;
    void solve(){
       int N,M;
       cin>>N>>M;
       vector<pair<int,int>> cond(M);
       for(int i=0; i<M; i++){
            int t1,t2;
            cin>>t1>>t2;
            cond[i]=make_pair(t1,t2);
       }
       int K;
       cin>>K;
       vector<pair<int,int>> person(K);
        for(int i=0; i<K; i++){
            int t1,t2;
            cin>>t1>>t2;
            person[i]=make_pair(t1,t2);
       }
       int last=0;
        vector<int> dishes(N,0);
        for(int i=0; i<(1<<K); i++){
            int temp=0;
            bitset<17> b(i);
            dishes.assign(N,0);
            for(int j=0; j<K; j++){
                if(b[j]==0){
                    dishes[person[j].first-1]++;
                }
                else{
                    dishes[person[j].second-1]++;
                }
            }
            for(auto x: cond){
                if(dishes[x.first-1]>=1 && dishes[x.second-1]>=1){
                    temp++;
                }
            }
            last=max(last,temp);
        }
        cout<<last<<endl;

    }

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

      return 0;
    }

#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define lli                               long long int
#define ll                                long long
#define FOR(i,a,b)                        for(int i=a;i<b;i++)
#define vi                                vector<int>
#define all(a)                            a.begin(),a.end()
#define sz(a)                             a.size()
using namespace std;
// bitset<8>set1(p);
// __builtin_popcountll(x);
// bitset<100> b("1010");
ll int MM = 998244353;
const int mod = 1e9 + 7;
const int INF = 1e9 + 5;

void solve()
{
	int n,m;
	cin >> n >> m;
	vector<pair<int,int>> dish1(m);
	FOR(i,0,m) {
		cin >> dish1[i].first >> dish1[i].second;
	}
	int k;
	cin >> k;
	vector<pair<int,int>> dish2(k);
	FOR(i,0,k) {
		cin >> dish2[i].first >> dish2[i].second;
	}
	int mxans = 0;

	for(int i=0;i<(1<<k);i++)
	{
		int ans = 0;
		map<int,int>mpp;
		for(int j=0;j<k;j++)
		{
			if((1<<j)&i)
			{
				mpp[dish2[j].first]++;
			}
			else
			{
				mpp[dish2[j].second]++;
			}
		}
		FOR(i,0,m)
		{
			if(mpp[dish1[i].first] and mpp[dish1[i].second])
				ans++;
		}
		mxans = max(mxans,ans);
	}
	cout << mxans << "\n";

}

int main()
{
    ios;
    #ifndef ONLINE_JUDGE
    freopen("input2.txt","r",stdin);
    freopen("output2.txt","w",stdout);
    #endif

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


#include <bits/stdc++.h>
using namespace std;
int n;
vector <string> s;
vector <unsigned long long> t,f;
int main(){
    cin >> n;
    s = vector<string>(n);
    for(int i = 0; i < n; i++){
        cin >> s[i];
    }
    t = vector<unsigned long long>(n+1,0);
    f = vector<unsigned long long>(n+1,0);
    t[0]=1;
    f[0]=1;
    for(long long i = 1; i <= n; i++){
        if(s[i-1].compare("AND")==0){
            t[i]=t[i-1];
            f[i]=t[i-1]+2*f[i-1];
        }else{
            t[i]=f[i-1]+2*t[i-1];
            f[i]=f[i-1];
        }
    }
    #if 0
    for(long i = 0; i <= n; i++){
        cout << t[i] << " ";
    }
    cout << endl;
    for(long i = 0; i <= n; i++){
        cout << f[i] << " ";
    }
    cout << endl;
    #endif
    cout << t.back() << endl;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

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

#define sz(a) int((a).size())
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ini(a, i) memset(a, i, sizeof(a))
#define inin(a, n, i) memset(a, i, sizeof(a[0])*(n))
#define contains(c, i) ((c).find(i) != (c).end())
#define present(i, c) (find(all(c), i) != (c).end())

#define trav(x, c) for(auto& x : c)
#define rep(i, n) for(int i = 0; i < n; i++)
#define repa(i, b, e) for(int i = (b)-((b)>(e)); i != (e)-((b)>(e)); i += 1-2*((b)>(e)))

template<class T> bool chkmax(T &x, T y) { return x < y ? x = y, true : false; }
template<class T> bool chkmin(T &x, T y) { return x > y ? x = y, true : false; }
template<class A, class B> A cvt(B x) { stringstream s; s << x; A r; s >> r; return r; }

void read() {}
void print() {}
template<class T, class... Args> void read(T& a, Args&... args) { cin >> a; read(args...); }
template<class T, class... Args> void print(T a, Args... args) { cout << a << ' '; print(args...); }
template<class... Args> void println(Args... args) { print(args...); cout << '\n'; }

#define debug(args...) { string s_(#args); replace(all(s_), ',', ' '); stringstream ss_(s_); istream_iterator<string> it_(ss_); cerr_(it_, args); }
void cerr_(istream_iterator<string> it) { (void) it; }
template<class T, class... Args> void cerr_(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; cerr_(++it, args...); }

template<class T, class S>  ostream& operator<<(ostream& os, const pair<T, S>& p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<class T> ostream& operator<<(ostream &os, const set<T> &s) { os << '{'; string sep; for (const auto &x : s) os << sep << x, sep = ", "; return os << '}'; }
template<class T, class S> ostream& operator<<(ostream &os, const map<T, S> &m) { os << '{'; string sep; for (const auto &x : m) os << sep << x, sep = ", "; return os << '}'; }
template<class T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }

const int INF = 0x3F3F3F3F;
const int MAXN = (int) 1e6;
const int MOD = (int) 1e9+7;

//=========================

void run_test() {
    int n; read(n);
    vi v(n+1);
    rep(i, n) {
        string s; read(s);
        if(s == "AND") v[i+1] = 0;
        else v[i+1] = 1;
    }

    vector<vll> dp(2, vll(n+1));
    dp[1][0] = 1;
    dp[0][0] = 1;

    for(int i = 1; i <= n; i++) {
        if(!v[i]) {
            dp[1][i] += dp[1][i-1];
            dp[0][i] += dp[0][i-1] + dp[1][i-1];    // current is false
            dp[0][i] += dp[0][i-1];                 // current is true
        } else {
            dp[1][i] += dp[1][i-1] + dp[0][i-1];    // current is true
            dp[1][i] += dp[1][i-1];                 // current is false
            dp[0][i] += dp[0][i-1];
        }
    }

    ll ans = dp[1][n];
    println(ans);
}

//=========================

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//int t_ = 1, t__; cin >> t__; while(t_ <= t__) { cout << "Case #" << t_++ << ": "; run_test(); }
	// int t_; cin >> t_; while(t_--) run_test();
	run_test();
	return 0;
}


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

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

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

using Pair = std::pair<int, int>;

char winner(const char& l, const char& r) {
  if (l == r) return l;
  if (l == 'R' && r == 'P' || l == 'P' && r == 'R') return 'P';
  if (l == 'S' && r == 'P' || l == 'P' && r == 'S') return 'S';
  if (l == 'R' && r == 'S' || l == 'S' && r == 'R') return 'R';
  return '.';
}

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

  int n, k;
  cin >> n >> k;
  std::string s;
  cin >> s;
  s += s;

  std::string target_s {s};

  for (auto i = 0;i < k;++i) {
    int new_s_size {static_cast<int>(target_s.size())};
    std::string new_s{};
    for (auto j = 0;j < new_s_size;++j) {
      new_s += winner(target_s[2*j%n], target_s[(2*j + 1)%n]);
    }
    target_s = new_s;
    //std::cout << target_s << '\n';
  }
  cout << target_s[0] << '\n';
}

#include<bits/stdc++.h>
#define int ll
#define sz(x) int((x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using pi = pair<int,int>;
const int inf = 0x3f3f3f3f3f3f3f3f;
const int minf = 0xc0c0c0c0c0c0c0c0;

const int N = 2002002;
const int mod = int(1e9) + 7;

struct Modular {
    int fact[N+5], inv[N+5], fact_inv[N+5];
    Modular() {
        fact[0] = fact[1] = inv[1] = fact_inv[0] = fact_inv[1] = 1;
        for (int i=2; i<=N; i++) {
            fact[i] = ll(fact[i-1])*i%mod;
        }
        for (int i=2; i<=N; i++) {
            inv[i] = -mod/i*ll(inv[mod%i])%mod+mod;
        }
        for (int i=2; i<=N; i++) {
            fact_inv[i] = ll(fact_inv[i-1])*inv[i]%mod;
        }
    }
    int comb(int n, int r) {
        return n>=r && r>=0 ? ll(fact[n])*fact_inv[n-r]%mod*fact_inv[r]%mod : 0;
    }
    int perm(int n, int r) {
        return n>=r && r>=0 ? ll(fact[n])*fact_inv[n-r]%mod : 0;
    }
} modular;

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

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

    if (n > m+k) {
        cout<<0<<'\n';
        return 0;
    }

    int res = modular.comb(n+m, n);

    res -= modular.comb(m+n, k+1+m);

    if (res < 0) res += mod;

    cout<<res<<'\n';

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,a,b) for(int i=a;i<=b;i++)
inline ll r() {
	ll x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c))x=x*10+c-'0',c=getchar();
	return x*f;
}
#define d r()
ll n,cmp;
ll a[200010];
ll b[200010];
vector<ll> e[200010];
ll in[200010];
bool vis[200010];
ll viss[200010];
void dfs(ll u){
	//vis[u]=1;
	if(in[u]==0)cout<<u<<"\n",vis[u]=1;
	for(int i=0;i<e[u].size();i++){
		ll v=e[u][i];
		if(vis[v]||in[v]==0)continue;
		in[v]--;
		dfs(v);
	}
}
int main(){
	n=d;
	f(i,1,n)a[i]=d,b[i]=i-a[i],cmp+=abs(b[i]);
	if(cmp/2>=n){
		cout<<-1;
		return 0;
	}
	f(i,1,n){
		if(b[i]>0){
			ll now=i-1;
			viss[now]++;
			for(int j=i-2;j>=a[i];j--)e[now].push_back(j),in[j]++,viss[j]++,now=j;
		}
		if(b[i]<0){
			ll now=i;
			viss[now]++;
			f(j,i+1,a[i]-1)e[now].push_back(j),viss[j]++,in[j]++,now=j;
		}
	}
//	f(i,1,n-1){
//		for(int j=0;j<e[i].size();j++)cout<<e[i][j]<<" ";
//		cout<<endl;
//	}
	f(i,1,n-1){
		//cout<<in[i]<<" ";
		if(viss[i]!=2||b[i]==0){
			cout<<-1;
			return 0;
		}
	}
	f(i,1,n-1)if(in[i]==0&&!vis[i])dfs(i);
	return 0;
}

#include<cmath>
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#include<vector>
#include<bitset>
using namespace std;
const int maxn=105;
int n,k,m,a[maxn],sum;
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
		if(ch=='-')
			f=-1;
		ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
    }
    return x*f;
}
inline void write(int a)
{
    if(a<0)
    {
		char a='-',b='1';
		putchar(a);
		putchar(b);
    }
    else
    {
		if(a>=10)
			write(a/10);
		putchar(a%10+'0');
    }
}

int main()
{
    n=read(),k=read(),m=read();
	for(int i=1;i<n;++i)
		a[i]=read(),sum+=a[i];
	int shu=n*m-sum;
	if(shu>k)
		puts("-1");
	else
		write(max(0,shu));
    return 0;
}


#include <bits/stdc++.h>
#define INF 1e18
#define mod 998244353
#define rep(i,n,m) for(int i = (n); i < (m); i++)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define tii tuple<int,int,int>
#define mt make_tuple
#define pb push_back
#define pq priority_queue

using namespace std;
typedef long long int ll;
typedef long double ld;

ld MAX(ld x, ld y)
{
    if(x < y) return y;
    return x;
}

ld MIN(ld x, ld y)
{
    if(x < y) return x;
    return y;
}

ll pmod(ll x, ll y)
{
    return ((x*y)%mod + mod)%mod;
}

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

/*
 * @Author: AsilenceBTF
 * @LastEditTime: 2020-12-11 20:02:17
 */
#include<bits/stdc++.h>
using namespace std;

#define ALL(x) x.begin(), x.end()
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int N = 2e5 + 105;

ll pre[N] = {0};
int main(){
    int n;
    ll w;
    cin >> n >> w;
    for(int i = 1; i <= n; ++i){
        int l, r, p;
        cin >> l >> r >> p;
        pre[r] += p;
        if(l) pre[l] -= p;
    }
    for(int i = N - 2; i >= 0; --i) pre[i] += pre[i + 1];
    for(int i = 0; i < N; ++i){
        if(pre[i] > w) {
            cout << "No" << endl;
            return 0;
        }
    }cout << "Yes" << endl;
    // system("pause");
}


#include<bits/stdc++.h>
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+(ch^48);ch=getchar();}
	return x*f;
}
int a,b,c;
int main()
{
	a=read(),b=read(),c=read();
	if(c%2==0)
		a=abs(a),b=abs(b);
	if(a>b)
		puts(">"),exit(0);
	if(a==b)
		puts("="),exit(0);
	if(a<b)
		puts("<"),exit(0);
	return 0;
}

#include<iostream>
#include <bits/stdc++.h>
#include<stdio.h>
#include <string.h>
using namespace std;
#define ll long long
#define INF 1000007
#define MAX 500007
#define EPS 1e-9
#define PI acos(-1.0)
#define nl "\n"
#define F first
#define S second
typedef vector<ll> vi;
typedef priority_queue<ll , vector<ll> , greater<ll> > pqmx;
typedef priority_queue<ll> pqmn;
typedef pair<ll , ll> pi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector< pair<int , int> > vpi;
#define fr(i,n) for(i=0;i<n;i++)
#define rep(i,a,n) for(i=a;i<n;i++)
#define yeS(GOOD)      GOOD ? cout<<"YES\n" : cout<<"NO\n"
#define all(a) a.begin() , a.end()
#define pb push_back
#define ar array
ll mod = LLONG_MAX;
ll binpow(ll a, ll b){ll res=1;a%=mod;while(b>0){if(b&1)res=(res*a)%mod;a=(a*a)%mod;b>>=1;}return res;}
ll binmul(ll a, ll b){ll res=0;a%=mod;while(b>0){if(b&1)res=(res + a)%mod;a=(a + a)%mod;b>>=1;}return res;}
ll area(pi a, pi b,pi c){return abs(a.F * b.S + b.F * c.S + c.F*a.S - a.S * b.F - b.S * c.F - c.S * a.F);}
ll gcd (ll a,ll b){if(b==0)return a;else return gcd (b, a % b);}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
ll min(ll a,ll b){if(a < b){return a;}return b;}
ll max(ll a,ll b){if(a > b){return a;}return b;}
double intlog(ll n ,ll base){return (double)log(n)/log(base);}
double DEG_to_RAD(double d) { return d * PI / 180.0; }
double RAD_to_DEG(double r) { return r * 180.0 / PI; }

ll n , t , m , temp , temp2, root , p ,q , k , i , j , r , u , v , w;

int main(){
#ifndef ONLINE_JUDGE
    freopen("input.txt" , "r" , stdin);
    freopen("output.txt" , "w" , stdout);
#endif
    int n;
    cin>>n;
    int i = 0;
    while(n > 0){
        n -= ++i;
    }
    cout<<i<<nl;
#ifndef ONLINE_JUDGE
    cout << "Running Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s .\n";
#endif
}


#include<bits/stdc++.h>
#define	ll	long long
#define	pb	push_back
#define	sz(v)	(int)v.size()
#define	nl	"\n"
using namespace std;
//this fuction sorts vector pair according to first element in descending order.
bool sortinrev(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;
}
int decimalToOctal(ll n) {
    int remainder;
    int octal = 0, i = 1;

    while(n != 0) {
        remainder = n%8;
        if(remainder == 7) return false;
        n = n/8;
        octal = octal + (remainder*i);
        i = i*10;
    }
    return true;
}
int digit(int n)
{
	while(n != 0)
	{
		int re = n % 10;
		if(re == 7) return false;
		n/=10;
	}
	return true;
}
void solve()
{
	int n, m;
	cin>>n;
	int ans = 0;
	for(int i = 1; i<=n; i++)
	{
		if(decimalToOctal(i) && digit(i)) ans++;
	}
	cout<<ans<<nl;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(NULL);

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

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  if(s.length()==3 && s[0]==s[1] && s[1]==s[2]&& s[2]==s[0]){
    cout << "Won" << endl;
  }
  else{
    cout << "Lost" << endl;
  }
  return 0;
}


#include<bits/stdc++.h>
#define x first
#define y second
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mem(x,val) memset(x,val,sizeof x)
#define pii pair<int,int>
#define pb emplace_back
#define ar array
#define int long long
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define M 1000000007
#define wopen(x) freopen((x),"w",stdout)
#define ropen(x) freopen((x),"r",stdin)
using namespace std;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
const int N = 2e5 + 5;

int n, m, top, chose, dp[(1<<18)], group[(1<<18)], st[20];
bitset<20> mat[20];

void init(){
    for(int i = 0; i < (1<<n); i++){
        top = 0;
        for(int j = 0; j < n; j++)
            if((i>>j)&1) st[top++] = j;
        for(int j = 0; j < top; j++)
            for(int k = 0; k < j; k++)
                if(mat[st[j]][st[k]] == 0)
                    goto next;
        group[i] = 1;
        next:;
    }
}

void dfs(int now, int bit){
    if(group[bit] == 0 && bit) return;
    if(now == top){
        if(group[bit]) dp[chose|bit] = min(dp[chose|bit], dp[chose] + 1);
        return;
    }
    dfs(now + 1, bit | (1<<st[now]));
    dfs(now + 1, bit);
}

signed main(void){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        a--, b--;
        mat[a][b] = mat[b][a] = 1;
    }
    init();
    mem(dp, 0x3f);
    dp[0] = 0;
    for(int i = 0; i < (1<<n); i++){
        top = 0;
        if(group[i] && i) {
            dp[i] = 1;
        }
        for(int j = 0; j < n; j++)
            if(((i>>j)&1) == 0) st[top++] = j;
        chose = i;
        dfs(0, 0);
    }
    cout << dp[(1<<n)-1];
}

#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++)
#define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yes(ans) if(ans)printf("yes\n");else printf("no\n")
#define Yes(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YES(ans) if(ans)printf("YES\n");else printf("NO\n")
#define popcount(v) __builtin_popcount(v)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
const int MOD2=998244353;
const int INF=1<<30;
const ll INF2=1LL<<60;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);}
template<class T,class U,class V>void scan(tuple<T,U,V>& p){scan(get<0>(p));scan(get<1>(p));scan(get<2>(p));}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll modinv(ll a, ll m) {ll b = m, u = 1, v = 0;while (b) {ll t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}
template<class T> void chmax(T &a,const T b){if(b>a)a=b;}
template<class T> void chmin(T &a,const T b){if(b<a)a=b;}

int main(){
    INT(n,m);
    vector2d(bool,A,n,n,false);
    int u,v;
    rep(i,m){
        in(u,v);
        A[--u][--v]=true;
        A[v][u]=true;
    }
    vector<int> dp(1<<n,0);
    bool h=false;
    rep(S,1<<n){
        dp[S]=popcount(S);
        h=true;
        for(int i=0;i<n;i++){
            if(~S>>i&1)continue;
            for(int j=i+1;j<n;j++){
                if(~S>>j&1)continue;
                if(!A[i][j]){
                    h=false;
                    break;
                }
            }
        }
        if(h){
            dp[S]=1;
            continue;
        }
        for(int T=(S-1)&S;T>0;T=(T-1)&S){
            chmin(dp[S],dp[S^T]+dp[T]);
        }
    }
    out(dp.back());
}


#include <bits/stdc++.h>
#define ll long long int
#define db double
#define pb push_back
#define mpr make_pair
#define andl "\n"
#define f first
#define s second
#define mset(x,y) memset(x,y,sizeof(x))
#define fr(i,n) for(long long int i=0;i<n;i++)
#define trace(it,x) for(auto it = (x).begin(); it != (x).end(); it++)
#define mod 1000000007
#define fastio ios::sync_with_stdio (false); cin.tie (0); cout.tie (0);
#define runtime cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;
using namespace std;

// convert number to string to_string(x);
// convert string to number stoi();

// ll mulmod(ll x,ll y)
// {
//     return ((x%mod)*(y%mod))%mod;
// }

// ll binpow(ll x, ll y)
// {
//     ll z = 1;
//     while(y > 0)
//     {
//         if(y % 2 == 1)
//             z = mulmod(z, x);
//         x = mulmod(x, x);
//         y /= 2;
//     }
//     return z;
// }

// ll ncr(ll n,ll r)
// {
//     return mulmod(fact[n],binpow(mulmod(fact[n-r],fact[r]),mod-2));
// }

// ll pwr(ll n,ll m)
// {
//   if(n==1 || m==0)
//     return 1;

//   ll x=pwr(n,m/2);
//   if(m%2==0)
//     return x*x;
//   else
//     return n*x*x;
// }

// ll pwr(ll n,ll m,ll b)
// {
//   if(n==1 || m==0)
//     return 1;

//   ll x=pwr(n,m/2,b);
//   if(m%2==0)
//     return ((x%b)*(x%b))%b;
//   else
//     return ((n%b)*(((x%b)*(x%b))%b))%b;
// }

void solve()
{
	ll n,c,ans=0,a,b,ci;
	cin >> n >> c;
	map<ll,ll>m;
	fr(i,n)
	{
		cin >> a >> b >> ci;
			m[a]+=ci;
			m[b+1]-=ci;
	}
	ll d=1,t=0;
	for(auto it=m.begin();it!=m.end();it++)
	{
		ans+=(min(t,c)*(it->first-d));
		t+=it->second;
		d=it->first;
	}
	cout << ans;
  return ;
}

int main()
{
  fastio

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

  while(t--)
    solve();

  runtime
}

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned int
#define test int t;cin>>t; while(t--)
#define en '\n'
typedef pair<int, int>     pii;
typedef pair<char, int>    pci;
typedef pair<char, char>   pcc;
typedef vector<pii>       vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define sz(x) (int)x.size()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007

void __print(int x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
// You should only debug a pair of simple data types. For example,
// the debug won't work if one of pair's elements is collection type
// (std::vector, std::map, std::set...).
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

// bool check_prime(int n)  return whether a number is prime or not O(sqrt(N));
// int BE(int x,int n,int m)  return x^n%m; O(logN);
// void sieve()  from number 1-1000001 saare prime store kar lega  in bool is_prime[1000001] array
// vector<int> z_array(string s)  return vector which is Z-array of string s;
// vector<int> lps(string s)      return vector which is lps array of string s;
// int power(int x,int n) return x^n; O(logN);
// using_ordered_set (template for using ordered set , replace first 2 lines of this page with this code..);
const int gf = 1e6 + 9;

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________

	int a, b;
	cin >> a >> b;
	cout << (a + b) / 2 << " " << (a - b) / 2 << en;

	return 0;
}


#include <bits/stdc++.h>
#define LL long long
#define ULL unsigned long long
#define pb push_back
#define st first
#define nd second
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
template <class T> T read(T &a) {
    a=0;char x=getchar();bool f=0;
    for(;x<'0'||x>'9';x=getchar())f|=x=='-';
	for(;x>='0'&&x<='9';x=getchar())a=(a<<3)+(a<<1)+x-'0';
    if(f)a=-a;
    return a;
}
using namespace std;

const int N = 1e6 + 5;
int id[1005][1005];
typedef pair<int, int> tp;
vector<int> mp[1005][30];
int dis[N];
bool vis[N];
queue<int> q;
int f[N], nnext[N << 3], v[N << 3], cnt, cnt1;
int n, m;

void add(int a, int b) {
    nnext[++cnt] = f[a];
    f[a] = cnt;
    v[cnt] = b;
}

int main() {
    read(n), read(m);
    for (int i = 1; i <= m; ++i) {
        int a, b;
        char s[3];
        read(a), read(b);
        scanf("%s", s);
        mp[a][s[0] - 'a'].pb(b);
        mp[b][s[0] - 'a'].pb(a);
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            id[i][j] = ++cnt1;
        }
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            for (int k = 0; k < 26; ++k) {
                for (int I = 0; I < mp[i][k].size(); ++I) {
                    for (int J = 0; J < mp[j][k].size(); ++J) {
                        int x = mp[i][k][I], y = mp[j][k][J];
                        add(id[i][j], id[x][y]);
                    }
                }
            }
        }
    }
    int ans = INF;
    memset(dis, INF, sizeof dis);
    q.push(id[1][n]);
    dis[id[1][n]] = 0;
    vis[id[1][n]] = 1;
    while (!q.empty()) {
        int k = q.front();
        q.pop();
        vis[k] = 0;
        for (int i = f[k]; i; i = nnext[i]) {
            int to = v[i];
            if (dis[to] > dis[k] + 1) {
                dis[to] = dis[k] + 1;
                if (vis[to] == 0) {
                    vis[to] = 1;
                    q.push(to);
                }
            }
        }
    }
    for (int i = 1; i <= n; ++i) {
        if (dis[id[i][i]] != INF) ans = min(dis[id[i][i]] * 2, ans);
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j < 26; ++j) {
            for (int k = 0; k < mp[i][j].size(); ++k) {
                int to = mp[i][j][k];
                if (dis[id[i][to]] != INF) {
                    ans = min(dis[id[i][to]] * 2 + 1, ans);
                }
            }
        }
    }
    if (ans == INF) puts("-1"); else cout << ans << endl;
	return 0;
}

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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> A(M), B(M);
    vector<char> C(M);
    for (int i = 0; i < M; i++) {
        cin >> A[i] >> B[i] >> C[i];
        A[i]--;
        B[i]--;
    }
    vector<int> dist(N*N, 1e9);
    vector<int> visited(N*N, false);
    queue<int> q;
    for (int i = 0; i < N; i++) {
        dist[i*N+i] = 0;
        q.push(i*N+i);
        visited[i*N+i] = true;
    }
    vector<vector<int>> edge(N*N);
    for (int i = 0; i < M; i++) {
        if (dist[A[i]*N+B[i]] > 1) {
            dist[A[i]*N+B[i]] = 1;
            q.push(A[i]*N+B[i]);
        }
        if (dist[B[i]*N+A[i]] > 1) {
            dist[B[i]*N+A[i]] = 1;
            q.push(B[i]*N+A[i]);
        }
        visited[A[i]*N+B[i]] = true;
        visited[B[i]*N+A[i]] = true;
        for (int j = i+1; j < M; j++) {
            if (C[i] != C[j]) continue;
            edge[A[i]*N+A[j]].push_back(B[i]*N+B[j]);
            edge[A[j]*N+A[i]].push_back(B[j]*N+B[i]);
            edge[B[i]*N+B[j]].push_back(A[i]*N+A[j]);
            edge[B[j]*N+B[i]].push_back(A[j]*N+A[i]);

            edge[A[i]*N+B[j]].push_back(B[i]*N+A[j]);
            edge[A[j]*N+B[i]].push_back(B[j]*N+A[i]);
            edge[B[i]*N+A[j]].push_back(A[i]*N+B[j]);
            edge[B[j]*N+A[i]].push_back(A[j]*N+B[i]);
        }
    }
    while (!q.empty()) {
        int now = q.front();
        q.pop();
        for (int nxt : edge[now]) {
            if (dist[nxt] <= dist[now]+2) continue;
            dist[nxt] = dist[now]+2;
            visited[nxt] = true;
            q.push(nxt);
        }
    }
    if (dist[N-1] >= 1e8) cout << -1 << endl;
    else cout << dist[N-1] << endl;
    return 0;
}


#include <iostream>
#include <string.h>
using namespace std;

int main()
{
   char s[3];
   char a;
   int j=0;
   for(int i=0;i<3;i++)
   {

   cin>>s[i];
   }

   char x=s[0];
   int flag=1;
   for(int i=1; i<3;i++)
   {
      if(x!=s[i])
       {
           flag=0;
           cout<<"Lost";
           break;
       }
   }
   if(flag==1)
   {

       cout<<"Won";
   }
    return 0;
}

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


#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);

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

    vector<bool> bad(n + 1, false);
    vector<int> A(K);
    for (int i = 0; i < K; ++i) {
        cin >> A[i];
        bad[A[i]] = true;
        A[i] -= i;
    }

    for (int i = 0; i < K; ++i) {
        int len = 1;
        while (i + 1 < K && A[i] == A[i + 1]) {
            ++i;
            ++len;
        }
        if (len >= m) {
            cout << -1 << '\n';
            return 0;
        }
    }

    vector<long double> dp(n + 1, 0);
    auto calc = [&](long double x) {
        fill(dp.begin(), dp.end(), 0);
        long double sum = 0;
        for (int i = n - 1; i >= 0; --i) {
            if (bad[i]) {
                dp[i] = x;
            } else {
                dp[i] = sum / m  + 1.0;
            }
            sum += dp[i];
            if (i + m <= n) {
                sum -= dp[i + m];
            }
        }

        return dp[0];
    };
    long double lo = 0, hi = 1e20;

    int rnd = 128;
    while (rnd-- > 0) {
        long double mi = (lo + hi) / 2;

        auto ans = calc(mi);
        if (ans < mi) {
            hi = mi;
        } else {
            lo = mi;
        }
    }

    cout << lo << '\n';

    return 0;
}

// abc189_f
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<long double, long double> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF (ll)(1e9)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int idx=0;idx<(n-1);idx++) cout << (vec)[idx] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << "\n";}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N, M, K;
    cin >> N >> M >> K;
    vector<bool> A(N);
    REP(i, K) {
        int a; cin >> a; a;
        A[a] = true;
    }

    vector<P> V(N+M);
    P cumsum = {0, 0};
    REP_REV(i, N){
        if (A[i]){
            V[i] = {1, 0};
        } else {
            V[i] = {cumsum.first / M, cumsum.second / M + 1};
        }
        cumsum.first = {cumsum.first - V[i+M].first + V[i].first};
        cumsum.second = {cumsum.second - V[i+M].second + V[i].second};

//        print(i, cumsum);
    }

//    REP(i, N+M) print(V[i]);

    if (abs(V[0].first - 1) < 1e-6){
        print(-1);
    } else {
        long double ans = V[0].second / (1 - V[0].first);
        print(ans);
    }

    return 0;
}


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

#define M1 1000000007
#define M2 998244353
#define INF 1e18
#define ll long long
#define pll pair<ll,ll>
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define REPR(i,a,b) for(ll i=b-1;i>=a;i--)
#define forr(i,n) for(ll i=0;i<n;i++)
#define F first
#define S second
#define pb push_back
#define DB pop_back
#define mp make_pair
#define MT make_tuple
#define V(a) vector<a>
#define vi vector<int>
#define vlli vector <long long>
#define endl '\n'
#define ce(ele) cout<<ele<<' '
#define cs(ele) cout<<ele<<'\n'
#define CASE(t) ll t; cin>>t; while(t--)

/********************************************************************/
const double pi = 3.1415926535;
/********************************************************************/
//FAST IO//
void FAST() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

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

}

#include <bits/stdc++.h>
#include<sstream>
#include<string>
#include<vector>
#include <set>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define mp make_pair
#define ll long long
#define ff first
#define ss second
long long M=1000000007;
using namespace std;
ll fact[10000];
ll power(ll x, unsigned ll y, unsigned 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;
}
unsigned long long modInverse(unsigned long long n,
                                            int p)
{
    return power(n, p - 2, p);
}
unsigned long long nCrModPFermat(unsigned long long n,
                                 int r, int p)
{
    // If n<r, then nCr should return 0
    if (n < r)
        return 0;
    // Base case
    if (r == 0)
        return 1;
    return (fact[n] * modInverse(fact[r], p) % p
            * modInverse(fact[n - r], p) % p)
           % p;
}
int32_t main()
{
  IOS
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  cout<<(b-(c))<<endl;
  return 0;
}


#include <iostream>
#include <vector>
#include <queue>
#include <tuple>

#define MAX (int)(1e8)

using namespace std;

int main() {
	int R, C;

	cin >> R >> C;

	vector<vector<int>> A(R, vector<int>(C - 1)), B(R - 1, vector<int>(C));
	vector<vector<vector<int>>> costs(2, vector<vector<int>>(R, vector<int>(C, 0)));
	vector<vector<vector<bool>>> visited(2, vector<vector<bool>>(R, vector<bool>(C, false)));

	for (int i = 0; i < R; i++) for (int j = 0; j < C - 1; j++)
		cin >> A[i][j];

	for (int i = 0; i < R - 1; i++) for (int j = 0; j < C; j++)
		cin >> B[i][j];

	//優先順位付きキューを使ってダイクストラ法を行う
	priority_queue<tuple<int, int, int, int>, vector<tuple<int, int, int, int>>, greater<tuple<int, int, int, int>>> que;

	//始点を追加
	que.push(make_tuple(0, 0, 0, 0));

	while (!que.empty()) {
		auto pos = que.top();
		int cost = get<0>(pos), f = get<1>(pos), r = get<2>(pos), c = get<3>(pos);
		que.pop();

		if (visited[f][r][c]) continue; //確定なら終了

		//コストを確定
		costs[f][r][c] = cost;
		visited[f][r][c] = true;

		//自分が下っている最中かどうかで分岐
		if (f == 0) {//下っていない
			//上下左右に移動を考える
			if (r + 1 < R)  //上
				que.push(make_tuple(cost + B[r][c], f, r + 1, c));
			if (c - 1 >= 0)	//左
				que.push(make_tuple(cost + A[r][c - 1], f, r, c - 1));
			if (c + 1 < C)	//右
				que.push(make_tuple(cost + A[r][c], f, r, c + 1));
			if (r - 1 >= 0) //下
				que.push(make_tuple(cost + 1, 1, r, c));
		}
		else {	//下っている
			//一つ下に移動するver or　下るのをやめる
			if (r - 1 >= 0)//下る
				que.push(make_tuple(cost + 1, f, r - 1, c));

			que.push(make_tuple(cost, 0, r, c)); //戻る

		}
	}

	cout << costs[0][R - 1][C - 1] << endl;

	return 0;
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second

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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;

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

map<int, int> rev;
const int N = 102;
const int M = 102102;
vi vis(N), ans(M), ok(M);
vii ed(M);

void dfs(vector<vii> &gr, int u, int p) {
  vis[u] = 1;
  for (auto [v, e]: gr[u]) if (p != v) {
    if (vis[v]) {
      ok[rev[e]] = 1;
      ans[rev[e]] = ed[rev[e]].fst == v;
    }
    else {
      ans[rev[e]] = ed[rev[e]].snd == v;
      ok[rev[e]] = 1;
      dfs(gr, v, u);
    }
  }
}

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

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

  vi c(n+1), done(m), vis(n+1);

  vector<vii> g(n+1);
  rep(i,0,m) {
    cin >> ed[i].first >> ed[i].second;
    g[ed[i].fst].eb(ed[i].snd, i);
    g[ed[i].snd].eb(ed[i].fst, i);
  }

  rep(i,1,n+1) cin >> c[i];

  rep(i,1,n+1) {
    if (vis[i]) continue;
    queue<int> q;
    q.push(i);
    vis[i] = 1;
    vi comp;
    while (!q.empty()) {
      int u = q.front(); q.pop();
      comp.pb(u);
      for (auto [v, j]: g[u]) if (!vis[v] && c[v] == c[u]) {
        vis[v] = 1;
        q.push(v);
      }
    }

    vector<vii> gr(n+1);
    int nedges = 0;
    for (auto u: comp) {
      for (auto [v, j]: g[u]) {
        if (c[u] == c[v] && !done[j]) {
          rev[nedges] = j;
          gr[u].eb(v, nedges);
          gr[v].eb(u, nedges);
          ++nedges;
          done[j] = 1;
        }
      }
    }

    dfs(gr, i, i);
  }

  rep(i,0,m) {
    if (!ok[i]) {
      assert(c[ed[i].fst] != c[ed[i].snd]);
      ans[i] = c[ed[i].fst] > c[ed[i].snd];
    }
    if (ans[i]) cout << "->";
    else cout << "<-";
    cout << '\n';
  }

}


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

using namespace std;

typedef long long ll;

ll N;

int main() {
	cin >> N;
	N *= 2;
	vector<ll> yakusu;
	for (ll i = 1; i * i <= N; i++) {
		if (N % i == 0) {
			yakusu.push_back(i);
			yakusu.push_back(N / i);
		}
	}
	sort(yakusu.begin(), yakusu.end());

	//初項x, 項数bの等差数列の和はxb + b * (b - 1) / 2 == N
	int ans = 0;
	for (int i = 0; i < yakusu.size(); i++) {
		ll b = yakusu[i];
		ll x2 = (N / b + 1 - b);
		if (x2 % 2 == 0)ans++;
	}

	cout << ans << endl;

	return 0;
}

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

#define ff              first
#define ss              second
#define int             long long
#define double          long double
#define pb              push_back
#define mp              make_pair
#define pi              pair<int,int>
#define vtiii           vector<tuple<int,int,int>>
#define vi              vector<int>
#define vpii            vector<pair<int,int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int>>
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define inf             1e18
// #define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define all(x) (x).begin(), (x).end()
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

// typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif

void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(double t) {cerr << t;}

template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}

const int mxN = 1e7;
const int mod = 1e9 + 7;

void solve(){
    int n;cin>>n;
    int x = 0;
    cout<<n-1<<endl;

}

int32_t main(){
    // auto start = high_resolution_clock::now()
    FIO;
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        freopen("Error.txt", "w", stderr);
    #endif
    // precalc();
    //int x; cin>>x; while(x--)
    solve();
    // auto stop = high_resolution_clock::now();
    // auto duration = duration_cast<microseconds>(stop - start);
    // cout << duration.count() << endl;
}


// abc199_d
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>
#ifdef LOCAL
#include "../../debug_util/cxx-prettyprint/prettyprint.hpp"
#include "../../debug_util/rng.hpp"
#include "../../debug_util/timer.hpp"
#endif
using namespace std;

using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

#define REP(i, n) for (int i = 0 ; i < (int)(n) ; ++i)
#define REPN(i, m, n) for (int i = m ; i < (int)(n) ; ++i)
#define REP_REV(i, n) for (int i = (int)(n) - 1 ; i >= 0 ; --i)
#define REPN_REV(i, m, n) for (int i = (int)(n) - 1 ; i >= m ; --i)
#define ALL(x) x.begin(), x.end()

#define INF (ll)(1e15)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int idx=0;idx<(n-1);idx++) cout << (vec)[idx] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << "\n";}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
//struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

struct Graph {

    int n;
    vector<vector<int>> edges;

    vector<int> con_graph;
    vector<int> vals;

    vector<vector<int>> con_graph_list;
    ll tmp_ans = 0;

    Graph(int n_) : n(n_), edges(n_), con_graph(n_, -1), vals(n_, -1) {}

    void add_edge(int u, int v) {
        edges[u].emplace_back(v);
        edges[v].emplace_back(u);
    }

    void dfs0(int u, int p, int k){

        con_graph[u] = k;

        for (auto v: edges[u]){
            if (v == p) continue;
            if (con_graph[v] != -1) continue;
            dfs0(v, u, k);
        }
    }

    void dfs(int idx, int k){

        if (idx == con_graph_list[k].size()){
            tmp_ans++;
        } else {

            int u = con_graph_list[k][idx];

            vector<bool> tmp(3);
            for (auto v: edges[u]){
                if (vals[v] == -1) continue;
                tmp[vals[v]] = true;
            }

            REP(i, 3){
                if (tmp[i]) continue;
                vals[u] = i;
                dfs(idx+1, k);
                vals[u] = -1;
            }
        }
    }

    void func(){

        int k = 0;
        REP(i, n){
            if (con_graph[i] != -1) continue;
            dfs0(i, -1, k++);
        }

//        print(k);
        con_graph_list.resize(k);
        REP(u, n){
            con_graph_list[con_graph[u]].emplace_back(u);
        }

//        print(con_graph_list);

        ll ans = 1;

        REP(i, k){
            tmp_ans = 0;
            if (con_graph_list[i].size() == 1){
                ans *= 3;
            } else {
                vals[con_graph_list[i][0]] = 0;
                dfs(1, i);
                ans *= 3 * tmp_ans;
            }
        }

        print(ans);
    }
};

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N, M;
    cin >> N >> M;
    Graph g(N);
    REP(i, M){
        int a,b;
        cin >> a >> b;
        a--; b--;
        g.add_edge(a, b);
    }

    g.func();

    return 0;
}

#include<bits/stdc++.h>
#define N 25
using namespace std;
int n,m,no[N][3],id[N],p[N];
long long ans=1,cnt;
bitset<N> f[N];
inline int find(register int x){return x==id[x]?x:id[x]=find(id[x]);}
inline void dfs(register int x,register int y){
	register bool flag=0;
	for(register int i=x+1;i<=n;++i)if(find(i)==y){
		flag=1;
		for(register int j=0;j<3;++j)
			if(!no[i][j]){
				for(register int k=1;k<=n;++k)if(f[i][k])++no[k][j];
				dfs(i,y);
				for(register int k=1;k<=n;++k)if(f[i][k])--no[k][j];
			}
		return;
	}
	cnt++;
}
int main(){
	cin>>n>>m;
	srand(114514);
	for(register int i=1;i<=n;++i)p[i]=i;
	random_shuffle(p+1,p+1+n);
	for(register int i=1;i<=n;++i)id[i]=i;
	for(register int i=1,a,b;i<=m;++i)scanf("%d %d",&a,&b),a=p[a],b=p[b],id[find(a)]=find(b),f[a][b]=f[b][a]=1;
	for(register int i=1;i<=n;++i)if(id[i]==i)cnt=0,dfs(0,id[i]),ans*=cnt;
	cout<<ans<<endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

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

    set<char> s;
    for(int i =0; i < 3; ++i){
	char c;cin >>c;
	s.insert(c);
    }
    cout <<(s.size() == 1 ? "Won" : "Lost");

}

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

int main() {
  int N, X;
  cin >> N >> X;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }

  for (int i = 0; i < N; i++) {
    if (A.at(i)!=X) cout << A.at(i) << ' ';
  }
  cout << endl;
}


#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
#define f(i,a,b) for( int i=a;i<=b;++i)
#define ff(i,a,b) for( int i=a;i>=b;--i)
#define debug(x) cerr << #x << " : " << x << " " << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<int, int> pll;
typedef pair<string, string> pss;
const ll mod = 1e9 + 7;
const ll mod2 = 998244353;
const ll inf = 2e18;
const double tiaohe = 0.57721566490153286060651209;
ll oula(ll x) { ll res = x;f(i, 2, x / i) { if (x % i == 0) { res = res / i * (i - 1);while (x % i == 0) x /= i; } }if (x > 1) res = res / x * (x - 1);return res; }
ll quickmod(ll a, ll n, ll m) { ll s = 1;while (n) { if (n & 1) { s = s * a % m; }a = (a*a) % m;n = n / 2; }return s; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
void ex_gcd(ll a, ll b, ll &x, ll &y, ll &d) { if (!b) { d = a, x = 1, y = 0; } else { ex_gcd(b, a % b, y, x, d);y -= x * (a / b); } }
ll inv(ll t, ll p) { ll d, x, y;ex_gcd(t, p, x, y, d);return d == 1 ? (x % p + p) % p : -1; }
bool isPrime(ll x) { if (x == 2)return true;if (x % 2 == 0)return false;for (ll i = 2;i*i <= x;i++) if (x % i == 0)return false; return true; }
inline int in() { char ch = getchar();int x = 0, f = 1;while (ch<'0' || ch>'9') { if (ch == '-')f = -1;ch = getchar(); }while (ch >= '0'&&ch <= '9') { x = x * 10 + ch - '0';ch = getchar(); }return x * f; }
//double a = log(n) +tiaohe + 1.0 / (2 * n);
double eqa = (1 + sqrt(5.0)) / 2.0;
const double eps = 1e-6;
const int N = 6e5 + 5;

int main()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
#endif

	int n;cin >> n;
	map<string, int> mp;
	while (n--)
	{
		string s;cin >> s;
		mp[s]++;
	}
	int good = 0;
	string ans = "sdsa";
	for (auto i : mp)
	{
		string nx = '!' + i.first;
		if (mp.count(nx)) {
			ans = i.first;
			good++;
			break;
		}
	}
	if (good)cout << ans << endl;
	else puts("satisfiable");
	return 0;
}

#include<bits/stdc++.h>
#define ll long long
using namespace std;
#define gc getchar
inline ll read(){
    register ll x=0,f=1;char ch=gc();
    while (!isdigit(ch)){if (ch=='-') f=-1;ch=gc();}
    while (isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=gc();}
    return (f==1)?x:-x;
}
int n;
ll A[1010101],B[1010101],sumB[1010101];
ll f[1010101][2],g[2][2];
priority_queue<ll> q[2];
signed main(){
	n=read();
	for (int i=1;i<=n;i++){
		A[i]=read();
	}
	ll _=0,ans=0;
	for (int i=1;i<=n;i++){
		B[i]=read();
		q[i%2].push(B[i]-A[i]);
		_+=A[i];
	}
	ans=_;
	for (int i=1;i<=n/2;i++){
		_+=q[0].top(),_+=q[1].top();
		ans=max(ans,_);
		q[0].pop(),q[1].pop();
	}
	cout<<ans;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define testcase  \
    ll tc, t = 1; \
    cin >> tc;
#define iloop(i, n) for (i = 0; i < n; i++)
#define dloop(i, n) for (i = n; i >= 0; i--)

#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);

#define vll vector<ll>

#define ipop                          \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);

//#define MAX 1000000
vector<ll> Seiveprime(ll n)
{
    vector<bool> isPrime(n, true);
    for (int i = 2; i * i < n; i++)
    {
        if (isPrime[i])
        {
            for (int j = i * i; j < n; j += i)
                isPrime[j] = false;
        }
    }
    vector<ll> prime;
    prime.push_back(2);
    for (int i = 3; i < n; i += 2)
        if (isPrime[i])
            prime.push_back(i);
    return prime;
}
ll binpow(ll a, ll b)
{
    ll res = 1;
    while (b > 0)
    {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
bool isPrime(int n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
}
ll lcm(ll a, ll b)
{
    ll x = __gcd(a, b);
    return (a * b) / x;
}
int binarySearch(int arr[], int l, int r, int x)
{
    if (r >= l)
    {
        int mid = l + (r - l) / 2;

        if (arr[mid] == x)
            return mid;

        if (arr[mid] > x)
            return binarySearch(arr, l, mid - 1, x);

        return binarySearch(arr, mid + 1, r, x);
    }
    return -1;
}
long long ncr(long long n, long long r)
{
    if (n < r)
    {
        return 0;
    }
    if (n == r || r == 0)
    {
        return 1;
    }
    ll ans = 1;
    for (ll i = n; i > n - r; i--)
        ans *= i;
    for (ll i = 1; i <= r; i++)
        ans /= i;
    return ans;
}
int main()
{
    fast;

        ll n = 0,s,d, m = 0, i = 0, j = 0, k = 0, l = 0;
        cin >> n>>s>>d;
        ll x[n],y[n];
        bool f=0;
        for(i=0;i<n;i++)
        {
            cin>>x[i]>>y[i];
            if(s>x[i]&&y[i]>d)
             f=1;
        }
        if(f)
         cout<<"Yes";
        else
        {
            cout<<"No";
        }

    return 0;
}

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <cstring>
#include <queue>
#include <map>
#define LL long long
#define LD long double
#define MAXN 100005
#define MAXM
#define P
#define INF 0x3f3f3f3f
using namespace std;

int t, n, a[MAXN];

int main()
{
    scanf("%d", &t);
    while(t--)
    {
        scanf("%d", &n);
        for(int i=1; i<=n; ++i) scanf("%d", &a[i]);
        if(n%2) printf("Second\n");
        else
        {
            int tag=0;
            sort(a+1, a+n+1);
            for(int i=1, cnt=0; i<=n; ++i)
            {
                if(a[i]!=a[i-1] && cnt%2) tag=1;
                cnt++;
            }
            if(tag) printf("First\n");
            else printf("Second\n");
        }
    }
    return 0;
}


/*The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

//PRABHJOT SINGH A.K.A. PRABHI
//~~~~~conquizztador~~~~~

#include<bits/stdc++.h>
using namespace std;
using lli = long long int;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
const int MOD = 1000000007;
const int MOD1 = 998244353;
const int maxn = 100010;
const int lim = (int)1e9;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n = 0; cin >> n; cout << ((n & 1) ? "Black" : "White") << endl;
}

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

#define __AceOfSpades__ ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define rep (i, n) for(int i=0; i<(n); i++)

typedef long long ll;
using namespace std;

int findSumOfDigits(int n){
  int digit = 0;
  while(n > 0){
    digit += n % 10;
    n /= 10;
  }
  return digit;
}

int main() {
  __AceOfSpades__

  int a;
  cin >> a;
  string ans;

  if (a%2==0) ans = "White";
  else ans = "Black";
  cout << ans << endl;

  return 0;

}


#include<bits/stdc++.h>
using namespace std;
#define DONTSYNC ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL) //dont use stdio with iostream functions //input and output are out of order now!
#define TEST unsigned long long T; cin>>T; while(T--)  //loop over each testcase
#define endl "\n"
#define fori(a,start,end) for(int a=start;a<end;a++)
#define forl(a,start,end) for(long long a=start;a<end;a++)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
typedef long long     ll;
typedef long double   ld;
typedef pair<int,int> pii;
typedef pair<ll,ll>   pll;
typedef vector<int>   vi;
typedef vector<ll>    vl;
typedef vector<pii>   vii;
typedef vector<pll>   vll;
typedef vector<vi>    vvi;
typedef vector<vl>    vvl;
const double PI = acos(-1);
ll calc_end_t(ll start,ll c,ll d){
    ll tmin=(ll)sqrt(d)-1;
    if(tmin<start) tmin=start;
    ll end=LLONG_MAX;
    for(ll i=tmin-2;i<tmin+3;i++){
        if(i==-1 || i<start) continue;
        end=min(end,i+c+d/(i+1));
    }
    return end;
}
void solve(){
    /* code */
    int n,m; cin>>n>>m;
    vector<vii> graph(n); vll edge(m);
    fori(i,0,m){
        int a,b,c,d; cin>>a>>b>>c>>d; a--;b--;
        graph[a].push_back({b,i});
        graph[b].push_back({a,i});
        edge[i]={c,d};
    }
    vl res(n,LLONG_MAX); res[0]=0;
    // priority_queue<pll,vector<pll>,greater<pll>> pq; pq.push({0,0});
    set<pll> pq; pq.insert({0,0});
    while(pq.size()){
        // auto [start_t,u]=pq.top(); pq.pop();
        auto [start_t,u]=*pq.begin(); pq.erase(pq.begin());
        if(start_t>res[u]) continue;
        for(auto [v,e]:graph[u]){
            ll end_t=calc_end_t(start_t,edge[e].fi,edge[e].se);
            if(end_t<res[v]){
                res[v]=end_t;
                // pq.push({end_t,v});
                pq.insert({end_t,v});
            }
        }
    }
    if(res[n-1]==LLONG_MAX) cout<<-1<<endl;
    else cout<<res[n-1]<<endl;
}

int main()
{
    DONTSYNC;
    // TEST
    solve();
    return 0;
}

/*
   Author   : MatsuTaku
   Date     : 01/09/21
*/

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)         for (size_t i = 0, i##_len = (n); i < i##_len; i++)
using lint = long long int;
template<typename T>
using vvec = vector<vector<T>>;
template<typename T>
vvec<T> make_vvec(int n, int m, T v) { return vvec<T>(n, vector<T>(m, v)); }
template<typename T>
void chmax(T& dst, T x) { dst = max(dst, x); }
template<typename T>
void chmin(T& dst, T x) { dst = min(dst, x); }

class Solver {
 public:
  void solve();
};

constexpr int INF = 1e9;
void Solver::solve() {
  int n,m; cin>>n>>m;
  vector<tuple<int, int, int>> E(m);
  rep(i, m) {
    int a,b; cin>>a>>b; a--; b--;
    E[i] = {a, b, 0};
  }
  vector<int> C(n); for (auto& c:C) cin>>c;
  vector<int> Ci(n);
  iota(Ci.begin(), Ci.end(), 0);
  sort(Ci.begin(), Ci.end(), [&](auto l, auto r) {
    return C[l] > C[r];
  });
  vector<tuple<int, int, int>> H[n];
  rep(i, m) {
    auto& [a, b, id] = E[i];
    if (C[a] == C[b]) {
      H[a].emplace_back(b, i, H[b].size());
      H[b].emplace_back(a, i, H[a].size()-1);
    } else {
      id = C[a] > C[b] ? 1 : -1;
    }
  }
  vector<int> v(n);
  auto make_cycle = [&H, &E, &v](auto f, int s) -> void {
    if (v[s]) {
      return;
    }
    v[s] = true;
    for (auto& [t, ei, it] : H[s]) {
      auto& [es, et, eid] = E[ei];
      if (eid != 0) {
        continue;
      }
      eid = es == s ? 1 : -1;
      f(f, t);
    }
  };
  rep(i, n) {
    make_cycle(make_cycle, i);
  }
  for (auto [s, t, id] : E) {
    cout << (id == 1 ? "->" : "<-") << endl;
  }
}

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


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <limits>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
using namespace std;
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; }
template<class T> inline int  sz(T &a) { return a.size(); }
using ll = long long; using ld = long double;
using pi = pair<int,int>; using pl = pair<ll,ll>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
const int inf = numeric_limits<int>::max();
const ll infll = numeric_limits<ll>::max();
// ユークリッドの互除法で最大公約数を求める
int gcd(int a,int b){
  if(b==0) return a;
  return gcd(b,a%b);
}
// 最小公倍数
int lcm(int a,int b){
  return a/gcd(a,b)*b;
}
int main()
{
  int n; cin >> n;
  vi a(n);
  rep(i,n) cin >> a[i];

  int mn = inf;
  rep(i,n) {
    chmin(mn, a[i]);
  }

  map<int,int> mp;
  rep(tmp,n) {
    for(int i = 1; i*i <= a[tmp]; ++i) {
      if(a[tmp] % i == 0) {
        if(mp[i] == 0) mp[i] = a[tmp];
        else mp[i] = gcd(mp[i], a[tmp]);
        if(a[tmp]/i!=i) {
          int j = a[tmp]/i;
          if(mp[j] == 0) mp[j] = a[tmp];
          else mp[j] = gcd(mp[j], a[tmp]);
        }
      }
    }
  }

  int res = 0;
  for(auto tmp: mp) {
    auto [key, val] = tmp;
    if(mn >= key && key == val) res++;
  }
  cout << res << "\n";

  return 0;
}

/*
	JAI JAGANNATH!
*/
//@Author : zanj0

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

#define int 			long long int

#define ff              first
#define ss              second
#define pb              push_back
#define MOD             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
#define endl       		"\n"

void zanj0()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
const int N = 1e3 + 5;
int a[N], b[N];
int n, m;
int dp[N][N];
int dfs(int i, int j) {
	if (i > n) {
		return m - j + 1;
	} else if (j > m) {
		return  n - i + 1;
	}
	if (dp[i][j] != -1) return dp[i][j];
	int ret = inf;
	if (a[i] == b[j]) {
		ret = min(ret, dfs(i + 1, j + 1));
	}
	int op = 1 + min({dfs(i + 1, j), dfs(i, j + 1), dfs(i + 1, j + 1)});
	ret = min(ret, op);
	return dp[i][j] = ret;
}
void solve() {
	memset(dp, -1, sizeof dp);
	cin >> n >> m;
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int j = 1; j <= m; j++) cin >> b[j];
	cout << dfs(0, 0) << endl;
}
int32_t main()
{
	zanj0();
	solve();
	return 0;
}


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

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int a[3];
    for (int i = 0; i < 3; i++)
    {
      cin>>a[i];
    }
    sort(a,a+3);
    cout<<a[2]+a[1];

    return 0;
}

  #include<bits/stdc++.h>
  using namespace std;
  using ll = long long;
  #define rep(i,f,n) for(ll i=(f); (i) < (n); i++)
  #define repe(i,f,n) for(ll i=(f); (i) <= (n); i++)
  #define repc(i,f,n) for(char i=(f); (i) <= (n); i++)
  //#define PI 3.14159265358979323846264338327950L
  #define debug(x) cout<<#x<<" :: "<<x<<"\n";
  #define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
  #define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
  #define Pl pair<ll, ll>
  #define OUT(x) cout << x << endl; return 0;
  #define ALL(x) (x).begin(),(x).end()
  #define UNIQUE(x) (x).erase(unique(ALL(x)),(x).end()) //x must be sorted
  //printf("%.10f\n")
  //cout << fixed << setprecision(10);
  template<class T> inline bool chmax(T& a, T b){if (a < b) { a = b; return true; } return false;}
  template<class T> inline bool chmaxe(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;}
  const ll MOD = 1000000007ll;
  const ll INF = 1e+18;
  const int iINF = 1e9;
  const double EPS = 1e-8;
  //const double PI = acos(-1.0);

int
main()
{
  vector<ll> arr(3);
  rep(i, 0, 3) cin >> arr[i];
  ll sum =0 ;
  sort(ALL(arr));
  rep(i, 1, 3) sum += arr[i];

  cout << sum << endl;
}


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

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int& it : a) cin >> it;
    if (n & 1) {
        cout << "Second\n";
    } else {
        sort(a.begin(), a.end());
        bool win = false;
        for (int i = 0; i < n; i += 2) {
            win |= a[i] != a[i + 1];
        }
        cout << (win ? "First\n" : "Second\n");
    }
}

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int tt = 1;
    cin >> tt;
    while (tt--)
        solve();
    return 0;
}

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

#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << '\n'
typedef long long ll;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
//const ll MOD = 998244353;

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

void solve() {
    ll n;   cin >> n;
    string ans;
    if(n == 1){
        ans = "Odd";
    }else if(n % 2 == 0){
        if(n / 2 % 2) ans = "Same";
        else ans = "Even";
    }else{
        ans = "Odd";
    }
    print(ans);
}

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

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