#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef   long long int ll;
typedef long double db;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pll pair<ll,ll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ub(v,val) upper_bound(v.begin(),v.end(),val)
#define np(str) next_permutation(str.begin(),str.end())
#define lb(v,val) lower_bound(v.begin(),v.end(),val)
#define sortv(vec) sort(vec.begin(),vec.end())
#define rev(p) reverse(p.begin(),p.end());
#define v vector
#define pi 3.14159265358979323846264338327950288419716939937510
#define len length()
#define repc(i,s,e) for(ll i=s;i<e;i++)
#define fi first
#define se second
#define mset(a,val) memset(a,val,sizeof(a));
#define mt make_tuple
#define repr(i,n) for(i=n-1;i>=0;i--)
#define rep(i,n) for(i=0;i<n;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define at(s,pos) *(s.find_by_order(pos))
#define set_ind(s,val) s.order_of_key(val)
long long int M = 1e9 + 7 ;
long long int inf = 9 * 1e18;
//CLOCK
ll begtime = clock();
#define time() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//CLOCK ENDED
ll n, m;
// modular exponentiation
ll binpow(ll val, ll deg)
{
	if (deg < 0)
		return 0;
	if (!deg)
		return 1 % M;
	if (deg & 1)
		return binpow(val, deg - 1) * val % M;
	ll res = binpow(val, deg >> 1);
	return (res * res) % M;
}
//binomial
ll modinv(ll n) {
	return binpow(n, M - 2);
}

v<v<ll>> adj;
int main() {
	// your code goes here
	IOS;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll i, j, t, k, x, y, z,  N;
	cin >> n >> m;
	adj.resize(n);
	rep(i, m) {
		cin >> x >> y;
		x--; y--;
		adj[x].pb(y);
		adj[y].pb(x);
	}
	cin >> k;
	ll c[k];
	rep(i, k) {cin >> c[i]; c[i]--;}
	ll dis[k][n];
	rep(i, k) {
		rep(j, n) {
			dis[i][j] = inf;
		}
	}
	rep(i, k) {
		dis[i][c[i]] = 0;
		queue<ll> q;
		v<ll> used(n, 0);
		ll s = c[i];
		q.push(s);
		used[s] = 1;
		while (!q.empty())
		{
			ll V = q.front();
			q.pop();
			for (ll u : adj[V])
			{
				if (!used[u])
				{
					used[u] = 1;
					dis[i][u] = dis[i][V] + 1;
					q.push(u);
				}
			}
		}

	}
	ll cost[1LL << k][k];
	// cout << k;
	rep(i, 1LL << k) {
		rep(j, k) {
			cost[i][j] = inf;
		}
	}
	rep(i, k) {
		cost[1LL << i][i] = 0;
	}
	for (i = 1LL; i < (1LL << k); i++) {
		v<ll> vec;
		rep(j, k) {
			if ((1LL << j)&i)vec.pb(j);
		}
		rep(j, k) {
			if (!((1 << j)&i)) {
				for (auto u : vec) {
					if (dis[u][c[j]] != inf && cost[i][u] != inf)
						cost[i | (1LL << j)][j] = min(cost[i | (1LL << j)][j], dis[u][c[j]] - 1LL + cost[i][u]);
				}
			}
		}
	}
	ll mn = inf;
	rep(i, k) {
		mn = min(mn, cost[(1LL << k) - 1LL][i]);
	}
	if (mn == inf)cout << -1LL;
	else {
		cout << mn + k;

	}

	return 0;

}

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <sstream>
#include <iomanip>
using namespace std;

using VI = vector <int>;
using VVI = vector <VI>;
using VVVI = vector <VVI>;
using VLL = vector <long long>;
using VVLL = vector <VLL>;
using VVVLL = vector <VVLL>;
using UMI = unordered_map<int, int>;
using UMLL = unordered_map<long long, long long>;

struct Que {
    int now;
    long long dist;

    Que (int pn, long long pd) : now(pn), dist(pd) {}

    bool operator<(const Que& q) const {
        return dist > q.dist;
    }
};

long long lowVal(long long val, long long target) {
    if (target == 0) {
        return val+1;
    }

    long long low = 1;
    long long up = val;
    long long ret = val;

    while (low <= up) {
        long long mid = (low+up) / 2;
        long long d = val / mid;

        if (d >= target) {
            low = mid+1;
            ret = mid;
        } else {
            up = mid-1;
        }
    }

    return ret;
}

int main() {
    int N;
    int M;

    cin >> N >> M;
    VVVLL adja(N);

    for (int i = 0; i < M; ++i) {
        int a;
        int b;
        int c;
        int d;
        cin >> a >> b >> c >> d;
        --a;
        --b;

        adja[a].push_back({b, c, d});
        adja[b].push_back({a, c, d});
    }

    const long long INF = 1000000000LL * 100000000LL;
    VLL dp(N, INF);
    VI used(N);
    priority_queue <Que> pq;
    dp[0] = 0;
    pq.push(Que(0, 0));

    while (!pq.empty()) {
        Que tq = pq.top();
        int now = tq.now;
        pq.pop();

        // cout << "DEBUG " << now << " " << dp[now] << endl;

        if (used[now]) {
            continue;
        }

        used[now] = 1;
        long long nt = dp[now];

        for (int i = 0; i < adja[now].size(); ++i) {
            int nextv = adja[now][i][0];
            long long C = adja[now][i][1];
            long long D = adja[now][i][2];

            // cost = dt + (C + (D/(nt+1+dt)))
            long long low = 0;
            long long up = nt ? D/nt : D;
            auto costCal = [&nt, &C, &D](long long dt) { return nt+dt+(C+D/(nt+1+dt)); };
            long long best = costCal(0);

            // 0 = 1 - D/(nt+1+dt)^2
            // D = (nt+1+dt)^2
            // sqrt(D)-nt-1

            long long base = sqrt(D)-nt-1;
            for (long long vdt = max(0LL, base-10); vdt <= base+10; ++vdt) {
                best = min(best, costCal(vdt));
            }

            // cerr << now << " " << nextv << " BEST " << best << endl;
            if (best < dp[nextv]) {
                dp[nextv] = best;
                pq.push(Que(nextv, best));
            }
        }
    }

    cout << (dp[N-1] == INF ? -1 : dp[N-1]) << endl;

    return 0;
}


//Awwawa! Dis cold yis ratten buy tEMMIE!
#include <bits/stdc++.h>
#define ll long long
#define maxn 200005 /*rem*/
#define mod 998244353
#define db double
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define fi first
#define se second

template <typename T> bool chkmax(T &x,T y){return x<y?x=y,true:false;}
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,true:false;}

using namespace std;
ll ksm(ll a, ll b) {
   if (!b) return 1;
   ll ns = ksm(a, b >> 1);
   ns = ns * ns % mod;
   if (b & 1) ns = ns * a % mod;
   return ns;
}
int a[maxn], b[maxn];
map<int, int> s[2];
vi tot;
int ask(int l) {
	int pl = lower_bound(tot.begin(), tot.end(), l + 1) - tot.begin();
	return pl;
}
int ask(int l, int r) {
//	cout << l << ' ' << r << ' ' << ask(r) << ' ' << ask(l - 1) << endl;
	return ask(r) - ask(l - 1);
}
int main() {
	int n, l;
	cin >> n >> l;
	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	a[0] = 0, a[n + 1] = l + 1;
	for (int i = 1; i <= n; i++)
		scanf("%d", &b[i]);
	b[0] = 0, b[n + 1] = l + 1;
	vi tr;
	for (int i = 0; i <= n + 1; i++)
		b[i] -= i, a[i] -= i,
		s[0][a[i]]++, s[1][b[i]]++,
		tr.pb(a[i]), tr.pb(b[i]);
	sort(tr.begin(), tr.end());
	tr.erase(unique(tr.begin(), tr.end()), tr.end());
	for (auto v : tr) {
		if (s[1][v] && !s[0][v]) {
			cout << -1 << endl;
			return 0;
		}
		if (s[0][v] && s[1][v])
			tot.pb(v);
	}
	ll ans = 0;
	for (int i = 0; i <= n + 1; i++) {
//		cout << a[i] << ' ' << b[i] << ' ' << ans << endl;
		if (a[i] > b[i])
			ans += ask(b[i], a[i] - 1);
		else ans += ask(a[i] + 1, b[i]);
	}

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

/** これを翻訳している間、あなたはあなたの人生のいくつかの貴重な瞬間を無駄にしました **/
#include<bits/stdc++.h>
using namespace std;

#ifdef Zoro
  #include "headers/debug.h"
#else
  #define debug(x...)
  #define deb(x...)
#endif

#define rep(i,x,y) for(int i=x;i<y;i++)
#define repr(i,x,y) for(int i=x;i>=y;i--)
#define int long long
#define pb push_back
#define ff first
#define ss second
#define sz(x) ((int)x.size())
#define all(x) begin(x), end(x)
#define memo(x,y) memset((x),(y),sizeof((x)))
#define line cout<<"[At "<<__LINE__<<"]"<<endl;

using pii = pair<int, int>;
using vi = vector<int>;
using vii = vector<pair<int, int>>;

constexpr int mod = 1e9 + 7, N = 2e5 + 5;
constexpr long long inf = 1e18;
constexpr long double eps = 1e-6;

void Onigiri() {
  int n,m;
  cin>>n>>m;

  deque<pii> v(m);
  rep(i,0,m){
    cin>>v[i].ff>>v[i].ss;
  }
  sort(all(v));
  unordered_set<int> cols;
  cols.insert(n);
  while(sz(v)){
    int cx = v.front().ff;
    vi cy;
    while(sz(v) && v.front().ff == cx) {
      cy.pb(v.front().ss);
      v.pop_front();
    }

    vi addList,removeList;
    for(auto &x:cy){
      if(cols.find(x-1)!=cols.end()){
        addList.push_back(x);
      }else if(cols.find(x+1)!= cols.end()){
        addList.push_back(x);
      }else{
        removeList.push_back(x);
      }
    }

    deb(cx,addList,removeList);
    for(auto &x:removeList){
      if(cols.find(x)!=cols.end()) cols.erase(x);
    }

    for(auto &x:addList){
      if(cols.find(x)==cols.end()) cols.insert(x);
    }

  }

  cout<<sz(cols);

}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  //cout.precision(10);cout<<fixed;
#ifdef Zoro
  freopen("/home/pritish/Competitive/io/in", "r", stdin);
  freopen("/home/pritish/Competitive/io/out", "w", stdout);
#endif

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

  while(t--) {
    Onigiri();
    cout << "\n";
  }

  cerr << "\n" << (float)clock() / CLOCKS_PER_SEC * 1000 << " ms" << endl;
  return 0;
}


#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;
#define int long long
#define all(arr) arr.begin(),arr.end()
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define vi vector<int>
#define vstr vector<string>
#define vbool vector<bool>
#define vvi vector<vector<int> >
#define mii map<int,int>
#define pb push_back
#define pii pair<int,int>
#define vpair vector<pii >
#define mkp make_pair
#define scan(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) {cout<<a[i]<<' ';}cout<<'\n'
#define mem(a,v) memset(a,v,sizeof(a))
#define loop(i,a,b) for (int i = a; i < b; i++)
#define loope(i,a,b) for (int i = a; i <= b; i++)
#define FastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PRECISION std::cout.unsetf ( std::ios::fixed );std::cout.precision(9)
#define PI 3.14159265
#define S second
#define F first
#define CHECK cout<<"CHEDEDWB"<<endl
#define br '\n'
int mod = 1e9+7;
/*int inf = 1e18;
int m_inf = INT_MIN;
int MOD = 100001;*/

void solve()
{
	string X;
    cin>>X;
    for(char c:X)
    {
        if(c=='.')
            break;
        cout<<c;
    }
    cout<<endl;
}

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

/*
    I love the sound you make when you shut up.
*/
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
/*-------typedefs------*/
template<class T> using ordered_set = tree<T, null_type , less<T> , rb_tree_tag , tree_order_statistics_node_update> ;
using ll = long long;
using pi = pair<int, int>;
/*-----in and out--------*/
#define pf(a) cout << a << endl
#define forIn(arr, num) for(int i = 0; i < num; i++) cin >> arr[i];
#define vpnt(ans) for(int i = 0; i < int(ans.size()); i++) cout << ans[i] << (i + 1 < int(ans.size()) ? ' ' : '\n');
/*---useful defines------*/
#define sz(x) (int)(x).size()
#define pb push_back
#define mem(a, b) memset(a,(b), sizeof(a))
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
/*----- the binary answer of life-----*/
#define no cout << "NO" << endl
#define yes cout << "YES" << endl
/*---checking and pushing-----*/
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; }
/*---- FAST I/O and file read ---*/
void go() {
    ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#endif
}
/*-------- test-case stuff--------------*/
#define ssolve solve();
#define msolve int T;cin >> T;while(T--) {solve();}
#define mcsolve int T;cin >> T;for(int tt = 1;tt <= T;tt++) {cout << "Case #" << tt << ": ";solve();}
/*-------- movement in a 2D array ------*/
const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};
/*----------------------------------------------------------------*/
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;
/*-------------- Push your limits here ---------------------------*/
void solve() {
    string s;
    cin >> s;

    string res = "";
    for(int i = 0;i < sz(s);i++) {
        if(s[i] == '.') break;
        res += s[i];
    }

    pf(res);
}

int main() {
    go();
    ssolve
    return 0;
}


#line 2 "/Users/kaage/Desktop/ProgrammingWorkspace/library/other/template.hpp"
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx2")
#pragma optimize("O3")
#pragma optimize("unroll-loops")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define all(V) V.begin(),V.end()
typedef unsigned int uint;
typedef long long lint;
typedef unsigned long long ulint;
typedef std::pair<int, int> P;
typedef std::pair<lint, lint> LP;
constexpr int INF = INT_MAX/2;
constexpr lint LINF = LLONG_MAX/2;
constexpr double eps = DBL_EPSILON;
constexpr double PI=3.141592653589793238462643383279;
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
inline lint gcd(lint a, lint b) {
	while (b) {
		lint c = a;
		a = b; b = c % b;
	}
	return a;
}
inline lint lcm(lint a, lint b) {
	return a / gcd(a, b) * b;
}
bool isprime(lint n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
template<typename T>
T mypow(T a, lint b) {
	T res(1);
	while(b){
		if(b&1)res*=a;
		a*=a;
		b>>=1;
	}
	return res;
}
lint modpow(lint a, lint b, lint m) {
	lint res(1);
	while(b){
		if(b&1){
			res*=a;res%=m;
		}
		a*=a;a%=m;
		b>>=1;
	}
	return res;
}
template<typename T>
void printArray(std::vector<T>& vec) {
	rep(i, vec.size()){
		std::cout << vec[i];
		std::cout<<(i==(int)vec.size()-1?"\n":" ");
	}
}
template<typename T>
void printArray(T l, T r) {
	T rprev = std::prev(r);
	for (T i = l; i != rprev; i++) {
		std::cout << *i << " ";
	}
	std::cout << *rprev << std::endl;
}
LP extGcd(lint a,lint b) {
	if(b==0)return {1,0};
	LP s=extGcd(b,a%b);
	std::swap(s.first,s.second);
	s.second-=a/b*s.first;
	return s;
}
LP ChineseRem(const lint& b1,const lint& m1,const lint& b2,const lint& m2) {
	lint p=extGcd(m1,m2).first;
	lint tmp=(b2-b1)*p%m2;
	lint r=(b1+m1*tmp+m1*m2)%(m1*m2);
	return std::make_pair(r,m1*m2);
}
template<typename F>
inline constexpr decltype(auto) lambda_fix(F&& f){
	return [f=std::forward<F>(f)](auto&&... args){
		return f(f,std::forward<decltype(args)>(args)...);
	};
}
#line 3 "/Users/kaage/Desktop/ProgrammingWorkspace/library/graph/UnionFind.hpp"
class UnionFind {
protected:
	std::vector<int> par, size;
public:
	UnionFind(){}
	UnionFind(int size) {init(size);}
	void init(int size){
		par.resize(size); this->size.resize(size, 1);
		rep(i, size) {
			par[i] = i;
		}
	}
	int find(int n) {
		if (par[n] == n)return n;
		return par[n] = find(par[n]);
	}
	void unite(int n, int m) {
		n = find(n);
		m = find(m);
		if (n == m)return;
		int a=n,b=m;
		if(size[a]>size[b])std::swap(a,b);
		par[a] = b;
		size[b] += size[a];
	}
	bool same(int n, int m) {
		return find(n) == find(m);
	}
	int getsize(int n) {
		return size[find(n)];
	}
};
#line 3 "main.cpp"
int N,M,a[200010],b[200010];
lint s[200010][2];
int main(){
	std::cin>>N>>M;
	REP(i,N)std::cin>>a[i];
	REP(i,N)std::cin>>b[i];
	UnionFind uf(N+1);
	rep(i,M){
		int c,d;
		std::cin>>c>>d;
		uf.unite(c,d);
	}
	REP(i,N){
		s[uf.find(i)][0]+=a[i];
		s[uf.find(i)][1]+=b[i];
	}
	REP(i,N){
		if(s[i][0]!=s[i][1]){
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	return 0;
}

#include <bits/stdc++.h> //Header Files

#define ll long long int
#define endl "\n"

using namespace std;

ll dfs(vector<vector<int>> &gr, int v, ll a[], ll b[], vector<bool> &vis, ll past)
{
    vis[v] = true;
    a[v] += past;
    ll val = a[v] - b[v];
    a[v] = b[v];

    for (int adj : gr[v])
    {
        if (!vis[adj])
        {
            ll temp = dfs(gr, adj, a, b, vis, val);
            a[v] += temp;
            val = a[v] - b[v];
            a[v] = b[v];
        }
    }

    return val;
}

void runTest()
{
    int n, m;
    cin >> n >> m;

    ll a[n + 1], b[n + 1];
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 1; i <= n; i++)
        cin >> b[i];

    vector<vector<int>> gr(n + 1);

    for (int i = 1; i <= m; i++)
    {
        int u, v;
        cin >> u >> v;
        gr[u].push_back(v);
        gr[v].push_back(u);
    }

    vector<bool> vis(n + 1, false);

    for (int i = 1; i <= n; i++)
    {
        if (vis[i])
            continue;

        ll valu = dfs(gr, i, a, b, vis, 0);
        if (valu != 0)
        {
            cout << "No" << endl;
            return;
        }
    }

    cout << "Yes" << endl;
}

int main()
{

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

    runTest();

    return 0;
}


#include <bits/stdc++.h>
#ifdef LILY
#include "Debug.h"
#else
#define var(...) (0)
#define dbg(...) (0)
#endif
using int32 = int;
using int64 = long long;
using namespace std;

class Solution
{
#define int int64
#define sfor(i, n) for (int i = 1; i <= (n); ++i)
#define tfor(i, n) for (int i = 0; i < (n); ++i)
#define INF 0x3f3f3f3f
#define EPS 1e-5
#define M 1000000007

    int n;
    int p;

    int pow(int base, int ex)
    {
        int ret = 1;
        while (ex)
        {
            if (ex & 1) ret = ret * base % M;
            ex >>= 1;
            base = base * base % M;
        }
        return ret;
    }

    void reals()
    {
    }

public:
    Solution()
    {
        cin >> n >> p;
        int t = pow(p - 2, n - 1);
        cout << t * (p - 1) % M << endl;
    }
#undef int
#undef tfor
#undef sfor
};

int32 main()
{
#ifdef LILY
    while (1)
#endif
        Solution();
    return 0;
}

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

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

using namespace std;

int main(){

    int a,b;
    cin >> a >> b;
    cout << a/100.0*b << endl;

}


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

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
/*
 execution in cmd for windows: g++ p1.cpp -op1

  p1

  execution in terminal for linux: g++ p1.cpp

  ./a.out

*/
typedef long double dd;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define nl <<"\n"
#define con continue
#define br break
#define vll vector<ll>
#define vpll vector<pair<ll,ll> >
ll mx=INT_MAX;
ll mi=INT_MIN;
#define mem0(a)         memset(a,0,sizeof(a))
#define mem1(a)         memset(a,-1,sizeof(a))
#define all(v) v.begin(), v.end()
#define fsort(v) sort(all(v))
#define rsort(v) sort(v.rbegin(),v.rend())
#define rev(v) reverse(all(v))
#define maxc(v) *max_element(all(v))
#define minc(v) *min_element(all(v))
#define sumv(v,x) accumulate(v.begin(),v.end(),x);
const ll mod = 998244353;
const ll inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3fLL;
const ll MOD = 1000000007;
#define pi 3.14159265
#define io { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define cer cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
#define cs ll t;cin>>t;while(t--)
#define cs1 ll t;t=1;while(t--)
#define input(v) for(i=0;i<v.size();i++) cin>>v[i];
#define output(v) for(i=0;i<v.size();i++) cout<<v[i]<<" ";
#define dbg(n) cout<<"[ "<<n<<" ]" nl;

int main()
{

    #ifndef ONLINE_JUDGE
        ifstream cin("in.in");
        ofstream cout("out.out");
    #endif

        io;
        //////////////////////////////////

        cs1{
             ll i, j, s = 0, c, k = 0, q = 0, o=0,  m = 0, e = -1, x, y, f=-1, ans = INF, p = 0, r=0, a, b, d=0, len, ct = 0, id, n;
             cin>>n;
             vll v(n);
             vll vv(1000,0);
             for(i=0;i<n;i++) {
              cin>>v[i];
              v[i]+=200;
              for(j=0;j<=400;j++){
                s=s+vv[j]*(v[i]-j)*(v[i]-j);
              }
              vv[v[i]]++;
            }
            cerr<<s nl;
            cout<<s nl;

      }
        //////////////////////////////////
        cer;

}

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

typedef long long LL;
LL ans, sum;
int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		LL a;
		cin >> a;
		ans += a * a * (n - 1);
		ans -= 2 * a * sum;
		sum += a;
	}
	cout << ans;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,m;
int sum[30];
char a[30];
int main()
{
	cin>>n>>m;
	long long ans=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%s",a+1);
		int t=0;
		for(int j=1;j<=m;j++)
		{
			if(a[j]=='1') t++;
		}
		if(t%2==1) ans+=sum[2],sum[1]++;
		else ans+=sum[1],sum[2]++;
	}
//	puts("");
//	for(int i=1;i<=m;i++) cout<<b[i]<<' ';
	cout<<ans<<endl;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define rng(v) v.begin(),v.end()
#define rngr(v) v.rbegin(),v.rend()
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using P3 = tuple<int, int, int>;
#define vi vector<int>
#define vvi vector<vi>
#define vll vector<ll>
#define vs vector<string>
using vp = vector<P>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using CP = complex<double>;
double dot( const CP &z, const CP &w ){ return (z.real()*w.real() + z.imag()*w.imag()); }
double cross( const CP &z, const CP &w ){ return (z.real()*w.imag() - z.imag()*w.real()); }
int main()
{
    int n, m;
    cin >> n >> m;
    ll a = 0;
    ll b = 0;
    rep(i, n) {
        string s;
        cin >> s;
        int c = 0;
        for(auto j : s) if(j-'0' == 1) c++;
        (c%2 == 0 ? a : b)++;
    }
    cout << a*b << 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;

long long int power(long long int x, long long int n, long long int M) {
	long long int ret = 1;
	long long int by = x;
	while (n) {
		if (n & 1) {
			ret *= by;
			ret %= M;
		}
		by *= by;
		by %= M;
		n >>= 1;
	}
	return ret;
}

long long by[2222222];
long long inv[2222222];

long long ncr(long long n, long long r) {
	if (r<0 || r>n)return 0;
	return by[n] * inv[n - r] % MOD * inv[r] % MOD;
}

void Solve(int a, int b, int c) {
	long long ans = ncr(a + b, a);
	ans += MOD - ncr(a + b, a - (c + 1));
	ans %= MOD;
	cout << ans << endl;
}

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

	by[0] = by[1] = inv[0] = inv[1] = 1;
	for (int i = 2; i < 2222222; i++) {
		by[i] = by[i - 1] * i % MOD;
	}
	inv[2222221] = power(by[2222221], MOD - 2, MOD);
	for (int i = 2222220; i > 0; i--) {
		inv[i] = inv[i + 1] * (i + 1) % MOD;
	}
	cin >> N >> M >> K;
	if (N - M > K) {
		cout << 0 << endl;
		return 0;
	}
	Solve(N, M, K);
}

// Problem: E - White and Black Balls
// Contest: AtCoder - AtCoder Beginner Contest 205
// URL: https://atcoder.jp/contests/abc205/tasks/abc205_e
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)

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

#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define endl '\n'
#define vi vector<int>
#define pii pair<int, int>
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define fill(a,b) memset(a, b, sizeof(a))
#define setbits(x) __builtin_popcountll(x) //count number of 1
#define zrobits(x) __builitin_ctzll(x)     //count number of zero before 1st 1 ex- (110000)2 ->4

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

// <--------------------Code Begins Here-------------------->
const int N = 2e6 + 1;
int a[N];
int power(int a, int b, int p){
	int res = 1;
	while(b != 0) {
		if(b & 1)
		  res = (res % p * a % p) % p;
		a = (a%p * a%p)%p;
		b /= 2;
	}
	return res%p;
}
int fact[N],inv[N];
void pre(int p) {
    fact[0]=1;
    inv[0]=1;
    for(int i=1;i<N;i++)
        fact[i]=(i*fact[i-1])%p;
    for(int i=1;i<N;i++)
        inv[i]=power(fact[i], p - 2, p);
}
int nCr(int n, int r, int p) {
    if(r>n)
       return 0;
    if(n==r)
       return 1;
    if(r==0)
       return 1;
    return (((fact[n]*inv[r]) % p )*inv[n-r])%p;
}
int32_t main() {
	SPEED;
	int t = 1;
	// cin>>t;
	pre(mod);
	while(t--) {
		int n, m, k;
		cin>>n>>m>>k;
		if(n > (m + k)) {
			cout<<0;
			return 0;
		}
		int ans = nCr(n + m, n, mod);
		ans -= nCr(n + m, m + k + 1, mod);
		ans %= mod;
		if(ans < 0)ans += mod;
		cout<<ans;
	}
	return 0;
}


#include <iostream>

int main() {
    int a, b, c;
    std::cin >> a >> b >> c;

    int result = 0;
    if (a == b) {
        result = c;
    } else if (b == c) {
        result = a;
    } else if (c == a) {
        result = b;
    }

    std::cout << result << std::endl;
    return 0;
}

#pragma GCC optimize("Ofast", "unroll-loops")
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define double long double
using pii = pair<int, int>;
template<typename T>
using Prior = std::priority_queue<T>;
template<typename T>
using prior = std::priority_queue<T, vector<T>, greater<T>>;

#define X first
#define Y second
#define eb emplace_back
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)
#define fastIO() ios_base::sync_with_stdio(0), cin.tie(0)

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

inline int getRand(int L, int R) {
    if (L > R) swap(L, R);
    return (int)(rng() % ((uint64_t)R - L + 1) + L);
}

template<typename T1, typename T2>
ostream& operator << (ostream &os, pair<T1, T2> &p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template<typename T>
ostream& operator << (ostream &os, vector<T> &vec) {
    for (int i = 0; i < vec.size(); ++i) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}

void solve() {
    int a, b, c; cin >> a >> b >> c;
    cout << (set<int>{a, b, c}.size() == 3 ? (int)0 : (a^b^c)) << "\n";
}

int32_t main() {
    fastIO();

    int t = 1; // cin >> t;
    for (int _ = 1; _ <= t; ++_) {
        // cout << "Case #" << _ << ": ";
        solve();
    }

    return 0;
}


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

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

#define int long long int

#define vi vector<int>

#define ff first
#define ss second

#define pb push_back
#define MOD 1000000007
//const int nax = 1e6+5;
#define inf 4e18
#define Graph vector<vi>
#define Graphw vector<vector<pair<int,int>>>
#define sz(x) (int)x.size()
#define pr pair<int,int>

#define display(v) for(int i =0;i<(int)v.size();++i)cout << v[i] << " "
#define all(v) v.begin(),v.end()
#define read(a) for(int i = 0;i<(int)a.size();++i)cin>>a[i]
#define show(x) cout << #x << " is " << x << "\n";
// typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>   ind_si;
// typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>   ind_msi;
#define show_arr(a) cout << #a << "\n"; display(a) ; cout << "\n";
inline int add(int a, int b){ int c = (a%MOD) + (b%MOD); if(c >= MOD) c -= MOD; return c; }
inline int mul(int a, int b){ return ((a%MOD) * 1ll * (b%MOD)) % MOD; }
inline int sub(int a, int b){ int c = (a%MOD) - (b%MOD); if(c < 0) c += MOD; return c; }
const int nax = 200*1000 + 10;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

//#define ook order_of_key
//#define fbo find_by_order
//   order_of_key(x) -> number of elements less than x.
// * find_by_order(x) -> gives the element at index x (0 - indexing)

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

int n;
string s ,x;
int dp[nax][8];
int vis[nax][8];

bool f(int id , int cur){
    if(id >= n){
        return (cur == 0);
    }
    if(vis[id][cur]){
        return dp[id][cur];
    }
    vis[id][cur] = 1;
    int cur1 = (cur * 3)%7 + (s[id] - '0')%7;
    bool f1 = f(id + 1, cur1%7);
    int cur2 = cur * (3);
    bool f2 = f(id + 1 , cur2%7);
    //cout << cur1 << " " << cur2 << '\n';
    //cout << id << " " <<f1 << ' ' << f2 << '\n';
    if(x[id] == 'T'){
        if(f1 || f2){
            dp[id][cur] = 1;
        }
        else{
            dp[id][cur] = 0;
        }
    }
    else{
        if(f1 && f2){
            dp[id][cur] = 1;
        }
        else{
            dp[id][cur] = 0;
        }
    }
    return dp[id][cur];
}

void test_case(){

    cin>>n;

    cin>>s>>x;
    if(f(0 , 0)){
        cout << "Takahashi";
    }
    else{
        cout << "Aoki";
    }

}

// Химаншу
// check overflow
// special case n == 1
// 🍪🍪🍪

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0xccccccc;
const ll LINF = 0xcccccccccccccccLL;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

//head

vector<bitset<256>> pre, now;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int u = 1<<n, v = u/2;
  cout << u-1 << endl;
  for(int i = 1; i <= n; i++) {
    now.clear();
    now.emplace_back(bitset<256>(0));
    rep(j, 1<<i-1) now[0].set(j);
    rep(j, pre.size()) {
      now.emplace_back(bitset<256>(0));
      now.back() |= pre[j];
      now.back() |= (pre[j]<<(1<<i-1));
    }
    rep(j, pre.size()) {
      now.emplace_back(bitset<256>(0));
      now.back() |= pre[j];
      now.back() |= ((pre[j]^now[0])<<(1<<i-1));
    }
    now.swap(pre);
  }
  for(auto bi:pre) {
    rep(i, u) {
      if(bi.test(i)) cout << 'A';
      else cout << 'B';
    }
    cout << '\n';
  }
}


#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
const long long MOD1 = 1000000007;
const long long MOD2 = 998244353;
#define logn long
#define lnog long
#define lgon long
#define itn int
typedef long long ll;
typedef pair<long double, long double> P;
const long long INF = 1e18;
int main(){
    long long N; cin >> N;
    string S; cin >> S;
    if (N == 2) {
        if (S[0] == S[1]) cout << -1 << endl;
        else cout << 1 << endl;
        return 0;
    }
    if (N == 3) {
        if (S[0] != S.back()) cout << 1 << endl;
        else cout << -1 << endl;
        return 0;
    }
    if (S[0] != S.back()) {
        cout << 1 << endl;
        return 0;
    }
    char ch = S[0];
    long long ans = 0;
    long long pos = 0;
    for (long long i = 1; i < N - 1; i++) {
        if (S[i] != ch && S[i+1] != ch) {
            cout << 2 << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

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

int main () {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    //cin >> t;
    while (t--) {
        int n, inf = 1e9 + 7;
        string s;
        cin >> n >> s;
        vector<int> dp(26, inf);
        dp[s[n - 1] - 'a'] = 0;
        int ans = inf;
        for (int i = n - 2; i >= 0; i--) {
            vector<int> dp1 = dp;
            for (int j = 0; j < 26; j++) {
                if (s[i] - 'a' != j && dp1[j] != inf) {
                    if (i == 0) ans = min(ans, dp1[j] + 1);
                    else {
                        dp[s[i - 1] - 'a'] = min(dp[s[i - 1] - 'a'], dp1[j] + 1);
                    }
                }
            }
        }
        if (ans == inf) ans = -1;
        cout << ans << '\n';
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 4e2+5;

char s[N],t[N];

inline char get(char a,char b){
	if(a == b) return a;
	if(a == 'P' && b == 'R') return 'P';
	if(a == 'R' && b == 'P') return 'P';
	if(a == 'S' && b == 'P') return 'S';
	if(a == 'P' && b == 'S') return 'S';
	if(a == 'R' && b == 'S') return 'R';
	if(a == 'S' && b == 'R') return 'R';
}

inline void change(int n){
	for(int i = 0;i < n;++i) t[i] = s[i];
	for(int i = n;i < n*2;++i) t[i] = s[i-n];

	for(int i = 0;i < n;++i)
		s[i] = get(t[i*2],t[i*2+1]);
	return ;
}

int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	scanf("%s",s);

	while(k){
		change(n);
		k--;
	}
	printf("%c",s[0]);
	return 0;
}

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9 + 7;
const double PI = 3.14159265358979;
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()

ll modpow(ll base, ll pow){
    ll ret = 1;
    while(pow>0){
        if(pow & 1) ret = ret * base % MOD;
        base = base*base % MOD;
        pow >>= 1;
    }
    return ret;
}

int main(){
    ll n, p; cin >> n >> p;
    ll ans = modpow(p-2, n-1);
    ans = ans * (p-1) % MOD;
    cout << ans << endl;
}


#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i = (begin); i < (end); i++)
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define SZ(x) ((int)((x).size()))
#define LE(vec) vec[vec.size()-1]
#define TSTS int t; cin >> t; while(t--)solve()

const int INF = 1e9;
const long long LINF = 1e18;
const long double PI = asin(1)/2;
const int MOD = 1e9+7;

using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef map<int, int> mii;
typedef long long ll;
typedef long double ld;

void setIO()
{
    FAST_IO;
}

void setIO (string s) {
    setIO();
 	freopen((s+".in").c_str(),"r",stdin);
 	freopen((s+".out").c_str(),"w",stdout);
}

const int N = 50;

int n, m, q;
vector<pii> inf;
int x[N];

int fnd(int l, int r)
{
    int tot = 0;
    set<int> used;
    vector<pii> a;
    FOR(i, 0, l-1)
    {
        a.PB(MP(x[i], i));
    }

    FOR(i, r, m)
    {
        a.PB(MP(x[i], i));
    }

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

    for(auto it : a)
    {
        int mx = -1, mxin = 0;
        FOR(j, 0, SZ(inf))
        {
            if(!used.count(j))
            {
                if(inf[j].F<=it.F)
                {
                    if(mx<inf[j].S)
                    {
                        mx = inf[j].S;
                        mxin = j;
                    }
                }
            }
        }
        if(mx!=-1)
        {
            used.insert(mxin);
            tot += mx;
        }
    }

    return tot;
}

int main()
{
    setIO();
    cin >> n >> m >> q;
    FOR(i, 0, n)
    {
        int a, b;
        cin >> a >> b;
        inf.PB(MP(a, b));
    }

    FOR(i, 0, m)
    {
        cin >> x[i];
    }

    FOR(i, 0, q)
    {
        int l, r;
        cin >> l >> r;
        cout << fnd(l, r) << '\n';
    }
}

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

ll getmax(vector<int> box, vector<pair<int, int>> &bag, int n){
    sort(box.begin(), box.end());
    ll result=0;
    vector<bool> visit (n, 0);
    for(int i=0; i<box.size();i++){
        for(int j=0; j<n; j++){
            //cout<<bag[j].second<<"   "<<box[i];
            if(!visit[j]&&bag[j].second<=box[i]){
                //cout<<"Hello";
                visit[j]=1;
                result+=bag[j].first;
                break;
            }
        }
    }
    return result;
}

int main(){
    int N, M, Q;
    cin>>N>>M>>Q;
    vector<pair<int,int>> bag;
    for(int i=0; i<N; i++){
        int first, second;
        cin>>first>>second;
        bag.push_back({second, first});
    }
    vector<int> box;
    for(int i=0; i<M; i++){
        int a; cin>>a; box.push_back(a);
    }
    sort(bag.rbegin(), bag.rend());
    for (int i=0; i<Q; i++){
        int L, R;
        cin>>L>>R; --L; --R;
        //cout<<"---------------------";
        vector<int> validbox;
        for(int j=0; j<M; j++){
            if(j<L||j>R) validbox.push_back(box[j]);
        }
        cout<<getmax(validbox, bag, N)<<endl;
        }

}


#include <bits/stdc++.h>

using namespace std ;

#define i64 int64_t // typecast using i64(x)
#define int int64_t
#define ld long double
#define endl "\n"
#define f(i,a,b) for(int i=int(a);i<int(b);++i)

#define pr pair
#define ar array
#define fr first
#define sc second
#define vt vector
#define pb push_back
#define LB lower_bound
#define UB upper_bound
#define PQ priority_queue

#define sz(x) ((int)(x).size())
#define all(a) (a).begin(),(a).end()
#define allr(a) (a).rbegin(),(a).rend()
#define mem0(a) memset(a, 0, sizeof(a))
#define mem1(a) memset(a, -1, sizeof(a))

template<class A> void rd(vt<A>& v);
template<class T> void rd(T& x){ cin >> x; }
template<class H, class... T> void rd(H& h, T&... t) { rd(h) ; rd(t...) ;}
template<class A> void rd(vt<A>& x) { for(auto& a : x) rd(a) ;}

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; }

template<typename T>
void __p(T a) {
  cout<<a;
}
template<typename T, typename F>
void __p(pair<T, F> a) {
  cout<<"{";
  __p(a.first);
  cout<<",";
  __p(a.second);
  cout<<"}\n";
}
template<typename T>
void __p(std::vector<T> a) {
  cout<<"{";
  for(auto it=a.begin(); it<a.end(); it++)
    __p(*it),cout<<",}\n"[it+1==a.end()];
}
template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) {
  __p(a1);
  __p(a...);
}
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
  cout<<name<<" : ";
  __p(arg1);
  cout<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
  int bracket=0,i=0;
  for(;; i++)
    if(names[i]==','&&bracket==0)
      break;
    else if(names[i]=='(')
      bracket++;
    else if(names[i]==')')
      bracket--;
  const char *comma=names+i;
  cout.write(names,comma-names)<<" : ";
  __p(arg1);
  cout<<" | ";
  __f(comma+1,args...);
}

void setIO(string s = "") {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cin.exceptions(cin.failbit);
  if(sz(s)){
    freopen((s+".in").c_str(),"r",stdin);
    freopen((s+".out").c_str(),"w",stdout);
  }
}
template<int MOD> struct mint {
  static const int mod = MOD ;
  int v; explicit operator int() const { return v; }
  mint() { v = 0; }
  mint(long long _v) { v = int((-MOD < _v && _v < MOD) ? _v : _v % MOD);
    if (v < 0) v += MOD; }
  friend bool operator==(const mint& a, const mint& b) {
    return a.v == b.v; }
  friend bool operator!=(const mint& a, const mint& b) {
    return !(a == b); }
  friend bool operator<(const mint& a, const mint& b) {
    return a.v < b.v; }

  mint& operator+=(const mint& m) {
    if ((v += m.v) >= MOD) v -= MOD;
    return *this; }
  mint& operator-=(const mint& m) {
    if ((v -= m.v) < 0) v += MOD;
    return *this; }
  mint& operator*=(const mint& m) {
    v = int((long long)v*m.v%MOD); return *this; }
  mint& operator/=(const mint& m) { return (*this) *= inv(m); }
  friend mint power(mint a, long long p) {
    mint ans = 1; assert(p >= 0);
    for (; p; p /= 2, a *= a) if (p&1) ans *= a;
    return ans; }
  friend mint inv(const mint& a) { assert(a.v != 0);
    return power(a,MOD-2); }

  mint operator-() const { return mint(-v); }
  mint& operator++() { return *this += 1; }
  mint& operator--() { return *this -= 1; }
  friend mint operator+(mint a, const mint& b) { return a += b; }
  friend mint operator-(mint a, const mint& b) { return a -= b; }
  friend mint operator*(mint a, const mint& b) { return a *= b; }
  friend mint operator/(mint a, const mint& b) { return a /= b; }
};
const int MOD = 998244353 ;
typedef mint<MOD> mi;
signed main(){
  setIO() ;
  int N, M, K;
  rd(N,M,K);
  mi ans ;
  if(N == 1){
  	ans = power(mi(K),M);
  }else if(M == 1){
  	ans = power(mi(K),N);
  }else{
  	for(int x=1; x<=K; x++){
  		mi countB =  power(mi(K-x+1),M);
  		mi countA =  power(mi(x),N) - power(mi(x-1),N) ;
  		ans += countA * countB;
  	}
  }
  cout << ans.v ;
}

#include<bits/stdc++.h>
#define int long long
#define mod 998244353
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<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    return x*f;
}

int n,m,k,ans;

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

signed main() {
	cin>>n>>m>>k;
	if(n==1) {
		//Ã¶¾Ùa È»ºóÓÐÒ»¸öbºÍËûÒ»Ñù
		for(int i=1;i<=k;i++) ans=(ans+ksm(k-i+1,m)-ksm(k-i,m))%mod;
		cout<<(ans+mod)%mod<<endl;
	}
	else if(m==1) {		//Ã¶¾Ù×î´óÖµ
		for(int i=1;i<=k;i++) ans=(ans+ksm(i,n)-ksm(i-1,n))%mod;
		cout<<(ans+mod)%mod<<endl;
	}
	else {
		for(int i=1;i<=k;i++) {		//Ã¶¾ÙaµÄ×î´óÖµ
			ans=(ans+ksm(k-i+1,m)*(ksm(i,n)-ksm(i-1,n))%mod)%mod;
		}
		cout<<(ans+mod)%mod<<endl;
	}

}


#include <bits/stdc++.h>

#define yy cout<<"YES"<<endl;
#define nn cout<<"NO"<<endl;
#define for0(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define forc(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i)
#define forr0(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define forr1(i, n) for (int i = (int)(n); i >= 1; --i)
#define rep(i, a, n) for (int i = a; i < n; i++)
#define mod 1000000007

#define fi first
#define se second
#define int             long long
#define w(x)            int x; cin>>x; while(x--)
#define endl            ("\n")
#define f(i, a, n)      for(int i=a; i<n; i++)
#define pb              push_back
#define mi(a,b,c)       min(a,min(b,c))
#define cc(r)           cout<<r<<" "
#define ce(r)           cout<<r<<endl

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin, (x).rend()

#define tr(c,i) for(__typeof__((c)).begin() i = (c).begin(); i != (c).end(); i++)

#define present(c,x) ((c).find(x) != (c).end())

#define cpresent(c,x) (find(all(c),x) != (c).end())

#define sz(a) int((a).size())

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef double ld;

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(14);
    cout << fixed;
    int t =1 ;
    //cin >> t ;
    while (t--)
    {
        int a, b ,c ;
        cin >> a >>b >> c ;
        cout << 21- a - b - c ;
    }
    return 0;
}

#include <bits/stdc++.h>
#include <bits/extc++.h>
#define double long double
#define rbtree __gnu_pbds::tree<int,__gnu_pbds::null_type,less<int>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>
#define int ll
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);
#define pb push_back
#define ALL(X) X.begin(),X.end()
#define F(i,n)  FF(i,0,n)
#define F1(i,n)  FF(i,1,n+1)
#define FF(i,n,m) for(int i=(int)n;i<(int)m;++i)
#ifndef LOCAL
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
#else
#endif // LOCOL
//#define mp make_pair
using namespace std;
//using namespace __gnu_pbds;
template<typename T> bool remax(T& a, const T& b) {return b>a?a=b,1:0;}
template<typename T> bool remin(T& a, const T& b) {return b<a?a=b,1:0;}
inline ostream& operator << (ostream& os,__int128_t a){if(a==0) {return (os<<'0');}bool flag=0;if(a<0) {a=-a,flag=1;}string s;while(a){s+=a%10+'0';a/=10;}s+=flag?"-":"";reverse(ALL(s));return os<<s;}
inline istream& operator >>(istream& is,__int128_t& a){string s;cin>>s;a=0;for(auto c:s) a=a*__int128_t(10)+__int128_t(c-'0');return is;}
template<typename T,typename P> inline ostream& operator << (ostream& os,pair<T,P> a){os<<a.first<<" "<<a.second; return os;}
template<typename T,typename P> inline istream& operator >> (istream& is,pair<T,P> &a){is>>a.first>>a.second; return is;}
using ll=long long;
using ull=unsigned long long;
using int128= __int128_t;
using uint128= __uint128_t;
using pii =pair<int,int>;
const double pi=acos(-1);
const int N=1E5+5;
const ll M=1000000000;
const ll INF_64=0x3f3f3f3f3f3f3f3f;
const int INF_32=0x3f3f3f3f;
const int16_t INF_16=0x3f3f;
const int klog=20;
const int mod=1E9+7;//998244353
const double eps=1E-8;
void gen(){
}
vector<int> an;
bool DD(int x,int y){
    if(x==0||y==0){
        if(an.size()+x+y>130) return false;
        while(x--) an.pb(1);
        while(y--) an.pb(2);
        return true;
    }
    if(x>=y)
        x-=y,an.pb(3);
    else y-=x,an.pb(4);
    return DD(x,y);
}
int re(){
    int x=0,y=0;
    F(i,an.size()){
        if(an[i]==1) x++;
        else if(an[i]==2) y++;
        else if(an[i]==3) x+=y;
        else if(an[i]==4) y+=x;
    }

    return x;
}
void sol(){
    int n;
    cin>>n;
    std::random_device rd;
    std::default_random_engine gen = std::default_random_engine(rd());
    std::uniform_int_distribution<int> dis(n/4,3*n/4);
    int tt;

    if(n<=130){
        cout<<n<<"\n";
        F(i,n) cout<<1<<"\n";
        return;
    }
    while(tt=dis(gen)){
        an.clear();
        an.pb(3);
        if(!DD(tt,n-tt)) continue;
        //cerr<<tt<<"\n";
        cout<<an.size()<<"\n";
        reverse(ALL(an));
        assert(re()==n);
        F(i,an.size()) cout<<an[i]<<"\n";
        return;
    }

}
int32_t main(){
    #ifdef LOCAL
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    #endif // LOCAL
    IOS;
    int t=1;
    gen();
    //cin>>t;
    FF(i,1,t+1){
        //cout<<"Case #"<<i<<": ";
        sol();
    }
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define RFOR(i,a,b) for(int i=(b-1); i>=(a); i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
using ll = long long;
using D = double;
using LD = long double;
using P = pair<int, int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<int mod> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % mod) {
        if (val < 0) val += mod;
    }
    constexpr int getmod() { return mod; }
    constexpr Fp operator - () const noexcept {
        return val ? mod - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= mod) val -= mod;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += mod;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % mod;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = mod, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % mod;
        if (val < 0) val += mod;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr istream& operator >> (istream &is, const Fp<mod>& x) noexcept {
        int val; is >> val;
        x = Fp<mod>(val);
        return is;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<mod>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<mod> modpow(const Fp<mod> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};

const int mod = 1e9+7;
using mint = Fp<mod>;

int main(){
    int n; cin  >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    if(n == 1){
        cout << a[0] << endl;
        return 0;
    }

    vector<mint> v(n), w(n);
    v[0] = 1; v[1] = 2;
    w[0] = 1; w[1] = 1;
    rep(i,n-2) {
        v[i+2] = v[i+1] + v[i];
        w[i+2] = w[i+1] + w[i];
    }

    mint ans = 0;
    rep(i,n) {
        mint p = v[n-1-i]*w[i];
        mint m = v[n-1]-p;
        ans += (mint)a[i]*(p-m);
    }
    cout << ans << endl;
}

    /**   Created by: Humberto Yusta
          Codeforces User: humbertoyusta
          Country: Cuba
          Copyright��                    */
#include<bits/stdc++.h>
using namespace std;
/// Pragmas:
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
//#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
//#pragma GCC target("avx2") //Enable AVX
/// Recently stolen pragmas:
//#pragma comment(linker, "/STACK:1024000000,1024000000")
//#pragma GCC optimize ("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
/// Macros:
#define int long long
#define f first
#define s second
#define db(x) cerr << #x << ": " << (x) << '\n';
#define pb push_back
#define lb lower_bound
#define up upper_bound
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
typedef pair<int,int> ii;
typedef long double ld;
typedef unsigned long long ull;
typedef long long ll;
/// Constraints:
const int maxn = 100010;
const int mod = 1000000007;
const int mod2 = 998244353;
const ld eps = 1e-9;
const int inf = ((1ll<<31ll)-1ll);
const int INF = 1ll * mod * mod;
const ld pi = acos(-1);
/// Prime Numbers:
// 2, 173, 179, 181, 197, 311, 331, 737, 1009, 2011, 2027, 3079, 4001, 10037, 10079, 20011, 20089;
// 100003, 100019, 100043, 200003, 200017, 1000003, 1000033, 1000037, 1000081;
// 2000003, 2000029, 2000039, 1000000007, 1000000021, 2000000099;
/// rng
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
/// Functions:
#define lg2(x) 63 - __builtin_clzll(x)
#define lgx(x,b) ( log(x) / log(b) )
/// Red-Black Tree Template ---------------------------------
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree < long long ,  null_type ,  less<long long> ,  rb_tree_tag ,  tree_order_statistics_node_update > ordered_set;
/// Quick Pow and Primality Check------------------------------------------------
int qpow(int b,int e){
    if( !e ) return 1;
    if( e & 1 ) return qpow(b,e-1) * b % mod;
    int pwur = qpow(b,e>>1);
    return pwur * pwur % mod;
}
int modinv(int x){
    return qpow(x,mod-2);
}
bool isprime(int x){
    for(int i=2; i*i<=x; i++)
        if( x % i == 0 ) return false;
    return true;
}
/// My Code -------------------------------------------------

int n, dp[maxn], subt[maxn], cnt[maxn];
vector<int> g[maxn];

void dfs(int u){

    for( auto v : g[u] )
        dfs(v);
    subt[u] = 1;
    for( auto v : g[u] ){
        subt[u] += subt[v];
        cnt[u] += subt[v] % 2;
    }

    if( subt[u] == 1 ){
        dp[u] = 0;
        return;
    }

    if( g[u].size() == 1 ){
        dp[u] = dp[g[u][0]];
        return;
    }

    vector<int> vx;
    for( auto v : g[u] ){
        if( subt[v] & 1 ){
            dp[u] += dp[v];
            vx.pb(-dp[v]+subt[v]-dp[v]);
        }
        else{
            if( dp[v] >= subt[v] - dp[v] ){
                dp[u] += dp[v];
            }
            else{
                if( cnt[u] % 2 ){
                    dp[u] += subt[v] - dp[v];
                }
                else{
                    dp[u] += dp[v];
                }
            }
        }
    }
    sort(all(vx));
    //reverse(all(vx));
    for(int i=1; i<vx.size(); i+=2){
         dp[u] += vx[i];
    }
}

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout.setf(ios::fixed); cout.precision(0);
    srand(time(NULL));

    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);

    cin >> n;

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

    for(int i=2; i<=n; i++){
        int u;
        cin >> u;
        g[u].pb(i);
    }

    dfs(1);

    for(int i=1; i<=n; i++){
        ;//db(dp[i])
    }

    cout << n - dp[1] << '\n';

    return 0;
}


#include <bits/stdc++.h>

#define ll          long long int
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pair<int,int>>
#define mi          map<int,int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define rep(i,a,b)  for(i=a;i<b;i++)
#define inf         INT_MAX
#define llinf       LLONG_MAX

template<typename T, typename U> static inline void amin(T &x, U y){ if(y<x) x=y; }
template<typename T, typename U> static inline void amax(T &x, U y){ if(x<y) x=y; }

using namespace std;
void solve()
{
    int a[4],i;
    rep(i,0,4)cin>>a[i];
    sort(a,a+4);
    if(a[3]==a[0]+a[1]+a[2] || a[0]+a[2]==a[1]+a[3] || a[0]+a[3]==a[1]+a[2])cout<<"Yes";
    else cout<<"No";
}
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

#ifdef BOI
#include "debug.h"
#else
#define debug(args...)
#endif

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
using pii = pair <int, int>;
using pli = pair <ll, int>;
using pll = pair <ll, ll>;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

const ll INF = (ll)2e9 + 69;

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

    vector <ll> a(4); cin >> a[0] >> a[1] >> a[2] >> a[3];

    bool ok = false;
    for (int i = 0; i < 16; ++i) {
        ll sum = accumulate(all(a), 0);
        ll sum1 = 0;
        for (int j = 0; j < 4; ++j) {
            if (i & (1 << j)) sum1 += a[j];
        }
        sum -= sum1;
        if (sum == sum1) {
            ok = true;
            break;
        }
    }

    cout << (ok ? "Yes" : "No");
}


#include <bits/stdc++.h>

using namespace std;
const int N = 505;
int T, n, cnt, a[N], op[N * N];
int s[10][4] = {
	{},
	{0, 1, 2, 3},
	{0, 1, 3, 2},
	{0, 3, 1, 2},
	{0, 3, 2, 1},
	{0, 2, 3, 1},
	{0, 2, 1, 3},
	{0, 1, 2, 3}
};
int to[10] = {0, 2, 1, 2, 1, 2, 1};

void out() {
	cout << cnt << '\n';
	for(int i = 1; i <= cnt; i++) {
		cout << op[i] << ' ';
	}
	cout << '\n';
}

void move(int x) {
	int pos = 0;
	for(int i = 1; i <= n; i++) {
		if(a[i] == x) {
			pos = i;
			break;
		}
	}
	while(pos != x) {
//		cout << pos << ' ' << cnt << '\n';
		if(pos % 2 == (cnt + 1) % 2) {
			swap(a[pos], a[pos + 1]);
			op[++cnt] = pos;
			++pos;
		} else {
			if(pos >= x - 2) {
				op[++cnt] = pos - 1;
				op[++cnt] = pos;
				op[++cnt] = pos - 1;
				op[++cnt] = pos;
				op[++cnt] = pos - 1;
				swap(a[pos], a[pos + 1]);
				++pos;
			} else {
				op[++cnt] = pos + 1;
				swap(a[pos + 2], a[pos + 1]);
			}
		}
	}
}

bool eq(int x) {
	for(int i = 1; i <= 3; i++) {
		if(a[i] != s[x][i]) return false;
	}
	return true;
}

void work() {
	if(n == 2) {
		if(a[1] == 2) op[cnt = 1] = 1;
		out();
	} else {
		for(int i = n; i >= 4; i--) {
			move(i);
		}
		for(int i = 1; i <= 7; i++) {
			if(eq(i)) {
				if(i == 1 || i == 7) break;
				if((cnt + 1) % 2 == to[i] % 2)
					for(int j = i; j < 7; j++) op[++cnt] = to[j];
				else
					for(int j = i - 1; j >= 1; j--) op[++cnt] = to[j];
				break;
			}
		}
		out();
	}
}

int main() {
//	freopen("test.in", "r", stdin);
//	freopen("test.out", "w", stdout);
	#ifdef ONLINE_JUDGE
	ios::sync_with_stdio(false); cin.tie(0);
	#endif
	cin >> T;
	while(T--) {
		cnt = 0;
		cin >> n;
		for(int i = 1; i <= n; i++) {
			cin >> a[i];
		}
		work();
	}

	return 0;
}

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

using namespace std;

#define ll long long
#define reps(i, a, b) for(int i = a; i < b; i++)
#define rreps(i, a, b) for(int i = a-1; i >= b; i--)
#define rep(i, n) reps(i, 0, n)
#define rrep(i, n) rreps(i, n, 0)
#define P pair<int, int>
#define vec vector<int>
#define mat vector<vector<int> >

const ll mod = 1000000007;
const int INF = 1001001001;

struct mint {
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};
istream& operator>>(istream& is, const mint& a){ return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a){ return os << a.x; }

int main(){
    int n;
    cin >> n;
    vec a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());
    mint ans;
    ans = a[0] + 1;
    rep(i, n-1){
        ans *= a[i+1] - a[i] + 1;
    }
    cout << ans << endl;
}


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

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

#define pb push_back

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

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

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

#ifndef ONLINE_JUDGE

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

#ifdef _getchar_nolock
#else
#    define _getchar_nolock getchar_unlocked
#endif

#define integer int

integer mod = 1e9 + 7;

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

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

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

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

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

#define solvsh
//#define multi

#ifdef solvsh

void precalc() {
}

const int MAXN = 112;

int getbg(int k) {
    if (k > 30) return 1e9;
    return 1 << k;
}

char getwin(char l, char r) {
    if (l == 'R') {
        if (r == 'S') return l;
        return r;
    } else if (l == 'P') {
        if (r == 'R') return l;
        return r;
    } else {
        if (r == 'P') return l;
        return r;
    }
}

void solve() {

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

    string s;
    cin >> s;
    while (k) {

        string news = "";

        if (s.size() % 2 == 1) {
            s = s + s;
        }

        for (int i = 0; i < s.size(); i += 2) {
            news += getwin(s[i], s[i + 1]);
        }

        --k;
        int lenn = getbg(k);

        while (news.size() > lenn) news.pop_back();

        s = news;
    }

    cout << s << "\n";

}

#else

#endif

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

    cin >> t;

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

#ifndef ONLINE_JUDGE

void gen() {

    int n = 2000;
    cout << n << "\n";
    for (int i = 0; i < n; ++i) {

        for (int j = 0; j < n; ++j) {
            if (i == 0 && j == 0) {
                cout << "S";
                continue;
            }
            if (i == n - 1 && j == n  - 1) {
                cout << "G";
                continue;
            }

            cout << char('a' + (rand() % 26)) << "";
        }
        cout << "\n";
    }
}

#endif

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

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

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

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

char win(char a,char b){
    if (a == 'R' && b == 'P') return b;
    if (a == 'P' && b == 'S') return b;
    if (a == 'S' && b == 'R') return b;
    else return a;
}
int main(){
    int n,k;
    cin >> n >> k;
    string s;
    cin >> s;
    while(k--){
        s += s;
        string t;
        for(int i = 0;i<2*n;i+= 2){
            t += win(s[i],s[i+1]);
        }
        s = t;
    }
    cout << s[0] << endl;

    }


#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<cmath>
#include<vector>

#define rep(i,a,b) for(ll i=a;i<=b;++i)
#define per(i,a,b) for(ll i=a;i>=b;--i)
#define fi first
#define se second
#define mp make_pair
#define all(x) x.begin(),x.end()
#define debug(x) cout<<# x <<" is "<<x<<endl;

using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const ll maxn=2e2+10,inf=0x3f3f3f3f3f3f3f3f,mod=1e9+7;

vector<int> ans[maxn];
bool vis[maxn];
int a[maxn];
int main()
{
	int N;cin>>N;
	rep(i,1,N) {cin>>a[i];	a[i]%=200;}

	//sort(a+1,a+1+N);
	vis[0]=1;
	vector<int> flag1,flag2;
	rep(i,1,N){
		vector<int> t;
		rep(j,0,199){
			if(vis[j]){
				int tar=(j+a[i])%200;
				if((tar!=0&&vis[tar])||(tar==0&&!ans[0].empty())){
					flag1=ans[tar];
					flag2=ans[j];
					flag2.push_back(i);
					break;
				}
				else{
					ans[tar]=ans[j];
					ans[tar].push_back(i);
					t.push_back(tar);
				}
			}
		}
		if(!t.empty()) rep(i,0,t.size()-1)	vis[t[i]]=true;
	}

	if(flag1.empty()) cout<<"No"<<endl;
	else {
		cout<<"Yes\n";
		cout<<flag1.size()<<' ';
		rep(i,0,flag1.size()-1)
			cout<<flag1[i]<<' ';
		putchar('\n');

		cout<<flag2.size()<<' ';
		rep(i,0,flag2.size()-1)
			cout<<flag2[i]<<' ';
		putchar('\n');
	}

	return 0;
}

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

int main(){
    ll n,a;
    cin>>n;
    vector<ll> A(n),bit200(200,0);
    vector<set<ll>> bit200s(200);

    for(ll i=0;i<n;i++) {
        cin>>a;
        A.at(i)=(a%200);
    }

    ll N8=n>8?8:n;
    set<ll> s1,s2;
    bool boo=false;

    for(ll i=1;i<(1<<N8);i++){
        set<ll> s;
        ll sum=0;
        for(ll j=0;j<N8;j++) if((1<<j)&i) {
            //cout<<j<<endl;
            sum+=A.at(j);
            //cout<<j<<endl;
            s.insert(j);
        }
        if(bit200.at(sum%200)==1){
            s1=s;
            s2=bit200s.at(sum%200);
            boo=true;
            break;

        }
        else {
            bit200.at(sum%200)=1;
            bit200s.at(sum%200)=s;
        }

    }

    if(!boo){
        cout<<"No"<<endl;
    }

    else{
        cout<<"Yes"<<endl;

        cout<<s1.size();

        for(auto si:s1){
            cout<<" "<<si+1;

        }

        cout<<endl;

        cout<<s2.size();

        for(auto si:s2){
            cout<<" "<<si+1;
        }
        cout<<endl;
    }
}


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

int main(){
    int n, k, m;

    int total=0,ans=0;
    cin >> n >> k >> m;
    int ar[n];
    int sum = 0;
    for(int i = 0; i < n - 1; i++)
    {
        cin >> ar[i];
        sum = sum+ar[i];
    }
    total = (n * m - sum);

    if (total <= 0) ans = 0;
    else if(total <= k) ans = total;
    else ans = -1;
    cout << ans << endl;
}

#include <bits/stdc++.h>

using namespace std;

#define fastio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define t_times int t; cin >> t; while(t--)
#define _parr(a, n) for(int __i = 0; __i < (int )n; __i++) cout << a[__i] << ' '; cout << '\n'
#define fr(i, p, n) for(int i = (int )p; i < (int )n; i++)
#define frn(i, p, n) for(int i = (int )p; i <= (int )n; i++)
#define rev(i, n, p) for(int i = (int )n; i >= (int )p; i--)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).begin(), (c).end()
#define sci(n) scanf("%d", &n)
#define scl(n) scanf("%lld", &n)
#define prin(n) printf("%d\n", n)
#define prln(n) printf("%lld\n", n)
#define mp make_pair
#define F first
#define S second
#define pb push_back

typedef long long int LL;
typedef unsigned long long ULL;
typedef unsigned int uint;
typedef pair< int, int> ii;
typedef vector< int> vi;

const int mod = 1e9 + 7;
const LL INF = 9e18 + 2e17;
const int inf = 2e9;
const int N = 2e5 + 22;
const double eps = 1e-10;

int n, m, k;

void _solve() {
	cin >> n >> k >> m;
	int x, sum = 0;
	fr(i, 1, n) cin >> x, sum += x;
	int z = m * n;
	if(z > sum && (z - sum) > k) cout << -1;
	else if(z > sum) cout << z - sum;
	else cout << 0;
}

int main() {
    fastio;
    //t_times
    _solve();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s;
    cin >> s;
    vector<int> cnt(10);
    for (char c : s) ++cnt[c - '0'];
    bool ok = false;
    for (int i = 8; i < 1000; i += 8) {
        vector<int> cnt2(cnt);
        for (char c : to_string(i)) --cnt2[c - '0'];
        if (s.size() <= 3) ok or_eq all_of(cnt2.begin(), cnt2.end(), [](int x) { return x == 0; });
        else ok or_eq to_string(i).size() == 3 and to_string(i).find('0') == string::npos and all_of(cnt2.begin(), cnt2.end(), [](int x) { return x >= 0; });
    }
    cout << (ok ? "Yes" : "No") << "\n";
    return 0;
}

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

#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)

#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法

signed main(){
    string S;
    cin >> S;
    vector<ll> bucket(10, 0);

    if(S.length() == 1) {
        if(S == "8") {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
        return 0;
    }

    if(S.length() == 2) {
        ll num1 = (S.at(0) - '0') * 10 + (S.at(1) - '0');
        if(num1 % 8 == 0) {
            cout << "Yes" << endl;
            return 0;
        } else {
            ll num2 = (S.at(1) - '0') * 10 + (S.at(0) - '0');
            if(num2 % 8 == 0) {
                cout << "Yes" << endl;
                return 0;
            }
        }
        cout << "No" << endl;
        return 0;
    }

    REP(i, S.length()) {
        ll index = (S.at(i) - '0');
        bucket.at(index)++;
    }

    for(ll i = 104; i <= 992; i += 8) {
        ll x = i;
        vector<ll> bucket2(10, 0);
        while(x != 0) {
            bucket2.at(x % 10)++;
            x /= 10;
        }
        bool flag = true;
        REP(j, 10) {
            if(bucket.at(j) < bucket2.at(j)) {
                flag = false;
                break;
            }
        }
        if(flag) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
}


#include <bits/stdc++.h>

#define ll long long
#define map unordered_map
#define set unordered_set
#define l_l pair<ll, ll>
#define P pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>
#define mp make_pair
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rev(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define revs(i, n) for (int i = ((int)(n)); i > 0; --i)
// template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
// template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);
ll H, W;

// template <class T> void plus_mod(T &a, const T &b) {a = (a + b) % MOD;}

ll grid[2005][2005];

ll dp[2005][2005];

ll TE;

ll calc(ll y, ll x) {
  if (dp[y][x] != INF) return dp[y][x];

  ll te = y + x;
  bool is_taka = (te % 2 == 0);

  ll plus = is_taka ? grid[y][x] : -grid[y][x];

  if (y == H - 1 && x == W - 1) {
    dp[y][x] = -plus;
    return -plus;
  }

  ll v;
  if (x < W - 1 && y < H - 1) {
    //
    ll v1 = calc(y, x + 1);
    ll v2 = calc(y + 1, x);

    if (is_taka) {
      v = max(v1, v2);
    } else {
      v = min(v1, v2);
    }

  } else if (x < W - 1) {
    v = calc(y, x + 1);
  } else if (y < H - 1) {
    v = calc(y + 1, x);
  }
  v -= plus;

  dp[y][x] = v;

  return v;
}

template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}

void show_table(ll I, ll J) {
  rep(i, I) {
    rep(j, J) { cout << dp[i][j] << " "; }
    cout << "" << endl;
  }
  cout << "" << endl;
}
int main() {
  // std::cout << std::fixed << std::setprecision(10);

  Fill(dp, INF);

  // + 青
  // - 赤
  scanf("%lld %lld", &H, &W);

  rep(y, H) {
    string line;
    cin >> line;

    rep(x, W) {
      char ch = line[x];
      if (ch == '-') grid[y][x] = -1;
      if (ch == '+') grid[y][x] = 1;
    }
  }

  // cout << (calc(1, 0)) << endl;

  if (H == 1 && W == 1) {
    cout << ("Draw") << endl;
    return 0;
  }

  ll TE = H + W - 2;

  ll c = calc(0, 0);

  ll v;

  if (W >= 2 && H >= 2) {
    ll v1 = dp[0][1];
    ll v2 = dp[1][0];
    v = max(v1, v2);
  } else if (W >= 2) {
    v = dp[0][1];
  } else {
    v = dp[1][0];
  }

  // cout << "v:" << (v) << endl;

  if (v == 0) {
    cout << ("Draw") << endl;
  } else if (v >= 1) {
    cout << ("Takahashi") << endl;
  } else {
    cout << ("Aoki") << endl;
  }

  // show_table(H, W);
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vll = vector<long long>;
using vb = vector<bool>;
using vd = vector<double>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long>>;
using vvc = vector<vector<char>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using graph = vector<vector<pair<T, int>>>;// pair of weight and vertex
template<typename T> inline bool chmax(T& a, const T b){ if(a < b){ a = b; return true; } return false; }
template<typename T> inline bool chmin(T& a, const T b){ if(a > b){ a = b; return true; } return false; }
void my_answer(){
    // 本質的にはミニマックス法と同じだが、dpの定義が通常とは違ってしまっているっぽい
    // dp[i][j] := if (i+j) % 2 == 0: Score(Takahashi) - Score(Aoki)の最大値
    //             elif: Score(Aoki) - Score(Takahashi)の最大値
   int h, w;
   cin >> h >> w;

   vvc fi(h, vc(w));
   for(auto& y: fi) for(auto& x: y) cin >> x;

   vvi dp(h, vi(w, INT32_MIN));
   dp[h-1][w-1] = 0;
   for(int y = h-1; y >= 0; --y){
       for(int x = w-1; x >= 0; --x){
           if(y+1 <= h-1) chmax(dp[y][x], -dp[y+1][x] + (fi[y+1][x] == '+' ? 1 : -1));
           if(x+1 <= w-1) chmax(dp[y][x], -dp[y][x+1] + (fi[y][x+1] == '+' ? 1 : -1));
           }
       }

   if(dp[0][0] == 0){
       cout << "Draw" << endl;
   }else if(dp[0][0] > 0){
       cout << "Takahashi" << endl;
   }else{
       cout << "Aoki" << endl;
   }
}
void best_answer(){
    // ミニマックス法（模範解答）
    // dp[i][j] := Score(Takahashi) - Score(Aoki)
    // if (i+j) % 2 == 0: Takahashiスタート。dp[i][j]を最大化しようとする。入る得点はTakahashiのものとして考えるので、+で計算。
    // elif: Aokiスタート。dp[i][j]を最小化しようとする。入る得点はAokiのものとして考えるので、-で計算。

   int h, w;
   cin >> h >> w;

   vvc fi(h, vc(w));
   for(auto& y: fi) for(auto& x: y) cin >> x;

   vvi dp(h, vi(w, 0));
   for(int y = h-1; y >= 0; --y){
       for(int x = w-1; x >= 0; --x){
           if((y + x) % 2 == 0){
               // Takahashi start
               if(y+1 <= h-1 || x+1 <= w-1) dp[y][x] = INT32_MIN;
               if(y+1 <= h-1) chmax(dp[y][x], dp[y+1][x] + (fi[y+1][x] == '+' ? 1 : -1));
               if(x+1 <= w-1) chmax(dp[y][x], dp[y][x+1] + (fi[y][x+1] == '+' ? 1 : -1));
           }else{
               // Aoki start
               if(y+1 <= h-1 || x+1 <= w-1) dp[y][x] = INT32_MAX;
               if(y+1 <= h-1) chmin(dp[y][x], dp[y+1][x] - (fi[y+1][x] == '+' ? 1 : -1));
               if(x+1 <= w-1) chmin(dp[y][x], dp[y][x+1] - (fi[y][x+1] == '+' ? 1 : -1));
           }
       }
   }

   if(dp[0][0] == 0){
       cout << "Draw" << endl;
   }else if(dp[0][0] > 0){
       cout << "Takahashi" << endl;
   }else{
       cout << "Aoki" << endl;
   }
}
int main(){

    // my_answer();
    best_answer();
}


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

int32_t main()
{

string s;
cin>>s;

bool ok=true;

for(int i=0;i<s.length();i++)
{
	if(i%2==1)
	{
		if(islower(s[i]))
			ok=false;
	}
	else if(i%2==0)
	{
		if(isupper(s[i]))
			ok=false;
	}

}

if(ok)
	cout<<"Yes"<<"\n";
else
	cout<<"No"<<"\n";

}

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

void DBG() { cerr << endl; }
template<class Head, class... Tail>
void DBG(Head H, Tail... T) { cerr << ' ' << H; DBG(T...); }
#define dbg(...) cerr << "(" << (#__VA_ARGS__) << "):", DBG(__VA_ARGS__)

using ll = long long;
using ld = long double;

#define sqr(a) ll(a) * (a)
#define siz(a) int(a.size())
#define ints(a...) int a; read(a)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define trav(i, v) for (const auto i : v)
#define fill(a, b) memset(a, b, sizeof(a))
#define rep(i, b, n) for (auto i = b; i < n; i++)
#define per(i, b, n) for (auto i = b; i >= n; i--)
#define unify(a) sort(all(a)); a.resize(unique(all(a)) - a.begin())

template <class T> using vec = vector<T>;
template <class... Args> inline void read(Args&... args) { ((cin >> args), ...); }
template <class... Args> inline void show(Args... args) { ((cout << args << " "), ...); }
template <class T1, class T2> inline bool ckmin(T1 &a, T2 b) { return a > b ? a = b, 1 : 0; }
template <class T1, class T2> inline bool ckmax(T1 &a, T2 b) { return a < b ? a = b, 1 : 0;  }
template <class T> inline void operator>> (istream& in, vector<T>& v) { rep(i, 0, siz(v)) in >> v[i]; }
template <class T> inline void operator<< (ostream& out, const vector<T>& v) { rep(i, 0, siz(v)) out << v[i] << " \n"[i + 1 == siz(v)]; }

const int MOD = 998244353;

struct Mod {
    template<typename T>
    T add(int64_t a, T b) { a += b; if (a >= MOD) a -= MOD; return a; }

    template<typename T>
    T sub(T a, T b) { a = a - b; if (a < 0) a += MOD; return a; }

    template<typename T>
    T mul(T a, T b) { return 1ll * a * b % MOD; }

    int64_t pow_n(int64_t a, int64_t p, const int mod = MOD) {
        int64_t ans = 1;
        a %= mod;
        while (p > 0) {
            if (p & 1) ans = ans * a % mod;
            a = a * a % mod;
            p >>= 1;
        }
        return ans;
    }

    template<typename T>
    T inv(T a) { return pow_n(a, MOD - 2); }

    template<typename T>
    T div(T a, T b) { return mul(a, inv(b)); }
} M;

void solve() {
    vec<ll> v(3);
    cin >> v;
    ll res = 1;
    rep(i, 0, 3) {
        ll a = v[i];
        ll b = v[i] + 1;
        if (a % 2 == 0)
            a /= 2;
        else
            b /= 2;
        res = M.mul(res, M.mul(a, b));
    }
    cout << res << '\n';
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
    int _ = 1;
    // cin >> _;
    rep(i, 1, _ + 1) {
        // printf("Case %d: ", i);
        solve();
    }
    return 0;
}


//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")

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

typedef long long  ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
#define pb push_back
#define MAXN 500005
const ll N=60;
#define INF (ll)1e18
#define mod 1000000007
//#define mod 998244353
#define fi first
#define se second
#define mkp make_pair
#define sze(x) ((ll)x.size())
#define all(v) v.begin(),v.end()
#define endl '\n'
#define level 20
ll timer,cc,cc1;

void boost()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

ll dp[MAXN],b[N];
vl V[MAXN];
map<pll,ll> mp;

void dfs(ll cur,ll prev)
{
    ll j;
    j=mp[mkp(cur,prev)];
    dp[cur]=dp[prev]^j;

    for(auto x : V[cur])
    {
        if(x!=prev)
        {
            dfs(x,cur);
        }
    }
}

int main()
{
    boost();

    ll i,t,n,q,l,r,ans,mid,c=0,j,k,z,tc;
    ll h,m,u,mm,w,mx,x,y,l1,r1,d=0,mask;
    ld f,f1;

    cin>>n;

    for(i=0;i<(n-1);i++)
    {
        cin>>x>>y>>z;
        V[x].pb(y);
        V[y].pb(x);
        mp[mkp(x,y)]=z;
        mp[mkp(y,x)]=z;
    }

    dfs(1,0);
    ans=0;

    for(i=0;i<60;i++)
    {
        c=0;
        d=0;
        for(j=1;j<=n;j++)
        {
            if((1LL<<i)&dp[j])
            {
                c++;
            }

            else
            d++;
        }

        z=c*d;
        l=(1LL<<i);
        l%=mod;
        z=z%mod;
        z=z*l;
        z%=mod;

        ans+=z;
        ans%=mod;
    }

    cout<<ans<<endl;

return 0;
}

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

#define INF (int)2e9
#define mod 1000000007
#define PI 3.141592653589793238
#define all(a) (a).begin(),(a).end()
#define rep(i,a,b) for(int i=a; i<b; ++i)
#define repd(i,a,b) for(int i=a; i>=b; --i)
#define repz(i,b) for(int i=0; i<b; ++i)
#define repdz(i,b) for(int i=b; i>=0; --i)
#define trav(i,a) for(auto &i: a)
#define pb push_back
#define pf push_front
#define nl '\n'
#define sp ' '
#define sz(a) a.size()
#define read(p) repz(i,sz(p)) cin>>p[i]

typedef long long ll;
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>>  vvl;
typedef pair<int, int> pii;
typedef vector<vector<pair<ll ,ll>>> vvp;
typedef vector<pair<ll, ll>> vpl;
typedef pair<ll, ll> pll;

int n;
vvp adj;

ll paths;

pll dfs(ll v, ll prev, int b){
	vpl paritypaths;
	ll tx=0, ty=0;
	trav(p, adj[v]){
		if(p.first==prev) continue;
		pii np=dfs(p.first, v, b);
		if(p.second&((ll)1<<b)) swap(np.first, np.second);
		tx+=np.first; ty+=np.second;
		tx%=mod; ty%=mod;
		if(p.second&((ll)1<<b)) {
			ty++; np.second++;
		}else {
			tx++; np.first++;
		}
		paritypaths.pb({np.first, np.second});
	}

	paths+=ty;
	paths%=mod;

	trav(p,paritypaths){
		paths+=p.first*(ty-p.second);
		paths%=mod;
	}

	return {tx,ty};
}

ll ppow(ll n, ll m){
	if(m==0) return 1;
	ll tmp=ppow(n,m/2);
	tmp = tmp * tmp % mod;
	return m%2 ? tmp*n % mod : tmp;
}

void solve(){

	cin>>n;
	adj.assign(n, vpl());

	repz(i, n-1){
		ll u, v, w; cin>>u>>v>>w; u--; v--;
		adj[u].pb({v,w}); adj[v].pb({u,w});
	}

	ll ans=0;
	repz(b,60){
		paths=0;
		dfs(0,0,b);
		ans+=paths*ppow(2,b);
		ans%=mod;
		// cout<<paths<<sp<<ans<<nl;
	}

	cout<<ans;

}

int main(){

	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.precision(10);
	int ts=1;
	//cin>>ts;
	while(ts--){
		solve();
	}
	return 0;

}


#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
#define rprintf(fmt, begin, end) do { const auto end_rp = (end); auto it_rp = (begin); for (bool sp_rp=0; it_rp!=end_rp; ++it_rp) { if (sp_rp) putchar(' '); else sp_rp = true; printf(fmt, *it_rp); } putchar('\n'); } while(0)

int N;

void MAIN() {
    scanf("%d", &N);
    int ans =0 ;
    for (int i=1; i<=N; i++) {
	bool ok = true;
	{
	    int m = i;
	    while (m) {
		if (m % 10 == 7) {
		    ok = false;
		    break;
		}
		m /= 10;
	    }
	}
	if (ok) {
	    int m = i;
	    while (m) {
		if (m % 8 == 7) {
		    ok = false;
		    break;
		}
		m /= 8;
	    }
	}

	if (ok) ans++;
    }

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

}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n,arr[1006];
    cin>>n;
    for(int i=0; i<n; i++)
    {
        cin>>arr[i];
    }
    sort(arr,arr+n);
    int x=0,c,max_c=0,flag=0;
    for(int i=2;i<=1000;i++)
    {
        c=0;
        for(int j=0;j<n;j++)
        {
            if(arr[j]%i==0)
            {
                c++;
            }
        }
        if(c>max_c)
        {
            max_c=c;
            x=i;
            flag=1;
        }
    }
    if(flag==1)
    {
        cout<<x<<endl;
    }
    else
    {
        cout<<"0"<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define vll vector<ll>
#define mp make_pair
#define pb push_back
#define pll pair<ll,ll>
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define F(i,a,n) for(ll i=a;i<n;i++)
#define fil(ar, val) memset(ar, val, sizeof(ar))
using namespace std;

const int mod = 1000000007;

ll gcd(ll a, ll b) {return (b == 0) ? a : gcd(b, a % b);}
ll lcm(ll a, ll b) {return ((a * b) / (gcd(a, b)));}
ll binpow(ll a, ll b)
{
    a %= mod;
    ll res = 1;
    while (b > 0)
    {
        if (b & 1)
        {
            res = (res * a) % mod;
        }
        a = (a * a) % mod;
        b >>= 1;
    }
    res %= mod;
    return res;
}

ll counter(ll n)
{
    ll ct = 0;
    while (n)
    {
        n /= 10;
        ct++;
    }
    return ct;
}

bool prime[10000005];
vector<ll>v;
unordered_map<ll, bool>cp;
void sieve()
{
    memset(prime, 1, sizeof(prime));
    for (ll i = 2; i * i <= 10000001; i++)
    {
        if (prime[i] == 1)
        {
            for (ll j = i * i; j <= 10000001 ; j += i)
            {
                prime[j] = 0;
            }
        }
    }
    prime[1] = 0;
    F(i, 3, 2000005)  // n prime : 1000003
    {
        if (prime[i])
        {
            v.pb(i);
            cp[i] = true;
        }
    }
}

vll vis(2005, 0);
vector<ll>adj[2005];
vector<ll>dis(2005, 0);

ll ct = 0;
void dfs(ll node)
{
    ct++;
    vis[node] = 1;
    for (auto i : adj[node])
    {
        if (!vis[i])
        {
            dfs(i);
        }
    }
}
void bfs(ll node)
{
    vis[node] = 1;
    queue<ll>q;
    q.push(node);
    while (!q.empty())
    {
        ll src = q.front();
        q.pop();
        for (auto i : adj[src])
        {
            if (!vis[i])
            {
                dis[i] = dis[src] + 1;
                vis[i] = 1;
                q.push(i);
            }
        }
    }
}

void i_p()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("op.txt", "w", stdout);
#endif
}

// luba luba dub dub

int main() {

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

    i_p();

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

        // easy way:
        ll n, m;
        cin >> n >> m;
        F(i, 1, n + 1)
        {
            vis[i] = 0;
        }
        ll x, y;
        F(i, 0, m)
        {
            cin >> x >> y;
            adj[x].pb(y);
        }
        ll ans = 0;
        F(i, 1, n + 1)
        {
            ct = 0;
            dfs(i);
            ans += ct;
            // cout << ct << "\n";
            F(i, 1, n + 1)
            {
                vis[i] = 0;
            }
        }
        cout << ans << "\n";

    }

    return 0;
}

#include<bits/stdc++.h>

using namespace std;

#define oo 1000000000

typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<char,int> pci;

int n;
string st,str;

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

	int cnt =0;

	for(int tam = 2;tam<=n;tam++){
		//cout << "\n" << tam << "\n";
		int at=0,cg=0;
		for(int i=0;i<n;i++){

			//cout << ini << " "
			if(str[i]=='A'){
				at++;
			}

			if(str[i]=='T'){
				at--;
			}

			if(str[i]=='C'){
				cg++;
			}

			if(str[i]=='G'){
				cg--;
			}

			if(i>=tam){
				if(str[i-tam]=='A'){
					at--;
				}

				if(str[i-tam]=='T'){
					at++;
				}

				if(str[i-tam]=='C'){
					cg--;
				}

				if(str[i-tam]=='G'){
					cg++;
				}
			}

			//cout << at << " " << cg << "\n";
			if((i>=tam-1) && (at == 0 && cg == 0)){
				cnt++;
			}
		}
	}

	cout << cnt << "\n";
}


#include <iostream>
#include <algorithm>
#include <string>
#include <complex>
#include <vector>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision

#include <chrono>
#include <random>
#include <cassert>

//#include <atcoder/all>

using namespace std;
//using namespace atcoder;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define rrep1(i,n) for(int i = (n); i >= 1; --i)
#define REP(i,n,m) for(int i = (n); i < (m); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(a) { cerr << #a << " = " << a << endl;}
#define debugV(vec) { cerr << #vec << " : "; for(auto v : vec) cerr << v << " "; cerr << endl; }
#define debug2D(vec2D, w) { cerr << #vec2D << endl;  for(auto vec : vec2D) { for (auto v : vec) cerr << setw(w) << v << " "; cerr << endl; } }
#define debugVP(vec) { cerr << #vec << " : ";  for(auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl;}
#define debug2DP(vec2D) { cerr << #vec2D << endl;  for(auto vec : vec2D) { for (auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl; } }

typedef long long ll;

constexpr ll INF = 1001001001; //32 ~2*10^10 //64 ~9*10^19
//constexpr ll MOD = 998244353;
constexpr ll MOD = 1000000007;
const double EPS = round(1e-6);
const char en = '\n';

/*
struct Edge {
	Edge(int _s, int _t, ll _cost = 1) : from(_s), to(_t), cost(_cost) {};
	int from, to;
	ll cost;
	//ll fee;
};
*/
typedef ll Edge;
/*
struct Edge {
	int id;
	int from, to;

	Edge() { id = from = to = -1; };
	Edge(int a, int b, int c) : id(a), from(b), to(c) {};
};
*/
typedef vector<vector<Edge>> Graph;
/*
void add_edge(Graph& g, int from, int to, ll cost = 1) {
	g[from].push_back(Edge(from, to, cost));
}
*/
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } else return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } else return false; }

void solve() {
  ll b, c; cin >> b >> c;
	ll l1 = (b - c / 2), l2 = (-b - (c - 1) / 2), r1 = (b + (c - 2) / 2), r2 = (-b + (c - 1) / 2);
	if (c == 1) {
	  if (b == 0) cout << 1 << endl;
		else cout << 2 << endl;
	}
	else if (c == 2) {
		if (b == 0) cout << 2 << endl;
		else cout << 3 << endl;
	}
	else if (b == 0) {
	  cout << r1 - l1 + 1 << endl;
	}
	else if (b < 0) {
		if (r1 >= l2) {
			cout << r2 - l1 + 1 << endl;
 		}
		else {
		  cout << r1 - l1 + r2 - l2 + 2 << endl;
		}
	}
	else {
		if (r2 >= l1) {
			cout << r1 - l2 + 1 << endl;
		}
		else {
			cout << r1 - l1 + r2 - l2 + 2 << endl;
		}
	}

}

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

	//rep(i,3)
	solve();

}

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

const int maxn = 2005;
const long long inf = 1e18+10;
int n, m;
vector<pair<long long,int> > g[maxn];
void dijkstra(int v) {
    long long d[n+1];
    for(int i=0; i<=n; i++) d[i] = inf;

    long long ans = inf;
    d[v] = 0;
    priority_queue<pair<long long,int> > pq;
    pq.push({0, v});
    bool p[n+1];
    memset(p, 0, sizeof p);
    while(!pq.empty()) {
        int cur = pq.top().second;
        pq.pop();
        if(p[cur]) continue;
        p[cur] = 1;
        for(int u=0; u<g[cur].size(); ++u) {
            long long b = g[cur][u].first, w = g[cur][u].second;
            //cout << b << " " << w << endl;
            if(b==v) {
                ans = min(ans, d[cur]+w);

            }
            else if(d[cur]+w<d[b]) {

                d[b] = d[cur]+w;
                pq.push({-d[b], b});
            }
        }
    }
    if(ans==inf) ans = -1;
    cout << ans << " ";
}
void Run_Case() {
    cin >> n >> m;
    for(int i=1; i<=m; i++) {
        int u, v, w; cin >> u >> v >> w;
        g[u].push_back({v, w});
    }
    for(int i=1; i<=n; i++) {
        dijkstra(i);
    }
}
int main() {
    Run_Case();
    return 0;
}


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

const int maxn = 200010;
int n, a[maxn], b[maxn], perm[maxn], c[maxn];
long long ans;
map<int, vector<int>> mp;
map<int, int> id;

void add(int p, int v) {
    for (; p <= n; p += p & -p) c[p] += v;
}

int query(int p) {
    int s = 0;
    for (; p; p -= p & -p) s += c[p];
    return s;
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]), a[i] += i;
        mp[a[i]].push_back(i);
    }
    for (int i = 1; i <= n; i++) {
        scanf("%d", &b[i]), b[i] += i;
    }
    for (int i = 1; i <= n; i++) {
        if (mp[b[i]].size() == id[b[i]]) puts("-1"), exit(0);
        perm[i] = mp[b[i]][id[b[i]]++];
        ans += i - 1 - query(perm[i]), add(perm[i], 1);
    }
    printf("%lld\n", ans);
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<vector<int>> to(N);
  vector<int> a(N-1), b(N-1);
  rep(i,N-1) {
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
    to[a[i]].push_back(b[i]); to[b[i]].push_back(a[i]);
  }
//  for(auto&x:to[0])cout<<x;cout<<endl;
  vector<ll> c(N,0);
  vector<pii> dag;
  vector<int> depth(N,-1);
  queue<int> q;
  q.push(0); depth[0]=0;
  while (!q.empty()) {
    int x=q.front(); q.pop();
    for (auto& y:to[x]) {
      if (depth[y] != -1) continue;
      depth[y] = depth[x] + 1;
      dag.push_back(pii(x,y));
      q.push(y);
    }
  }
//  for (auto&[x,y]:dag)cout<<"["<<x<<","<<y<<"],";
  int Q;
  cin >> Q;
  rep(i,Q) {
    int t,e,x;
    cin >> t >> e >> x;
    e--;
    int va=a[e], vb=b[e];
    if (t==2) swap(va, vb);
    if (depth[va]>depth[vb]) c[va] += x;
    else {c[0] += x; c[vb] -= x;}
  }
  for (auto& [x,y]:dag) {
    c[y] += c[x];
  }
  for (auto& x:c) printf("%ld\n",x);
}


#include <bits/stdc++.h>

#define ln                 '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (__typeof(to) i = 0; i < to; ++i)
#define cont(i, to)        for (__typeof(to) i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (__typeof(to) i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

const int nsz = 74;
const int hsz = int(1e7) + 39, esz = 2e6;
bitset<nsz> g[nsz + 5];
int vis[nsz + 5], pw[nsz + 5];
num n, fm, to, ans = 1, a[nsz + 5];

struct hash_table {
	int sz, hd[hsz + 5];

	struct node {
		int nxt;
		bitset<nsz> w;

		node() {}
		node(int nxt, bitset<nsz> w): nxt(nxt), w(w) {}
	} e[esz + 5];

	int inline to_key(const bitset<nsz> &w) {
		int u = 0;
		cont (i, n) u = (u * 2 + w[i]) % hsz;
		return u;
	}

	void inline ins(const bitset<nsz> &w, int u) {
		e[++sz] = node(hd[u], w), hd[u] = sz;
	}

	bool inline qry(const bitset<nsz> &w, int u) {
		for (int i = hd[u]; i; i = e[i].nxt) {
			if (e[i].w == w) return 1;
		}
		return 0;
	}
};
hash_table dat;

num gcd(num a, num b) {
	return !b ? a : gcd(b, a % b);
}

void bfs(int s, int &sz, int *nd) {
	static int q[nsz + 5];
	int ql = 0, qr = 0;
	for (q[qr++] = s, vis[s] = s; ql != qr;) {
		int u = q[ql++];
		nd[sz++] = u;
		cont (v, n) if (g[u][v] && !vis[v]) q[qr++] = v, vis[v] = s;
	}
}

num inline calc(int s) {
	static int nd[nsz + 5], d[esz + 5];
	static bitset<nsz> q[esz + 5], p[esz + 5];
	int sz = 0, ql = 0, qr = 1, cnt = 0;
	bfs(s, sz, nd);
	if (sz == 1) return 2;
	for (; ql != qr; ++cnt) {
		bitset<nsz> cur = q[ql], ban = p[ql], nban;
		int key = d[ql]; ++ql;
		loop (i, sz) if (!ban[nd[i]]) {
			int v = nd[i], nkey = (key + pw[v]) % hsz;
			cur[v] = 1, nban = ban | g[v];
			if (!dat.qry(cur, nkey)) {
				q[qr] = cur, p[qr] = nban, d[qr] = nkey; ++qr;
				dat.ins(cur, nkey);
			}
			cur[v] = 0;
		}
	}
	return cnt;
}

void inline init() {
	pw[0] = 1;
	cont (i, n) pw[i] = pw[i - 1] * 2 % hsz;
}

int main() {
	scanf("%lld%lld", &fm, &to);
	n = to - fm + 1;
	circ (i, fm, to) a[num(i) - fm + 1] = i;
	cont (u, n) cont (v, u) g[u][v] = g[v][u] = gcd(a[u], a[v]) > 1;
	init();
	cont (u, n) if (!vis[u]) ans *= calc(u);
	printf("%lld\n", ans);
}

// Problem: A - Health M Death
// Contest: AtCoder - Panasonic Programming Contest (AtCoder Beginner Contest 195)
// URL: https://atcoder.jp/contests/abc195/tasks/abc195_a
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/* Author : Atahar Islam Shihab
   ICT'16th Batch,MBSTU
*/
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define ll long long
#define maxele(v) *max_element(v.begin(),v.end())
#define minele(v) *min_element(v.begin(),v.end())
#define deb(x) cout << #x << " -> " << x << endl
#define deb2(x, y) cout << #x << " -> " << x << " || " << #y << " -> " << y << endl
#define fast  (ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0))
#define all(v) v.begin(),v.end()
#define sz(x) x.size();
#define clr(x) memset(x, 0, sizeof(x))
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
const int mxn = 100005;

int main()
{
  fast;
  int tc ;
  int n,m;
  cin >> n >> m;
  cout << (m%n==0?"Yes\n":"No\n");

  return 0;
}