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

int main() {
  int n, k;
  cin >> n >> k;
  vector<vector<int>> t(n, vector<int>(n));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> t.at(i).at(j);
    }
  }

  int ans = 0;
  vector<int> order(n);
  for (int i = 0; i < n; i++) order.at(i) = i;
  do {
    if (order.at(0) != 0) continue;
    int keep = 0;
    for (int i = 0; i < n; i++) keep += t.at(order.at(i)).at(order.at((i + 1) % n));
    if (keep == k) ans++;
  } while (next_permutation(order.begin(), order.end()));

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

//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <complex>
#include <iomanip>
#include <iostream>
#include <limits>
#include <inttypes.h>
#include <map>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// #include <atcoder/dsu>
// using namespace atcoder;
// using mint = modint1000000007;
// using mint = modint998244353;
// using mint = modint;

using namespace std;

using ll = int64_t;
using ull = uint64_t;

[[maybe_unused]] constexpr ll LL_MAX = numeric_limits<ll>::max();
[[maybe_unused]] constexpr ll LL_MIN = numeric_limits<ll>::min();
[[maybe_unused]] constexpr ull ULL_MAX = numeric_limits<ull>::max();

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrep(i, a, b) for (ll i = (a)-1; i >= (b); i--)

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

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

ll csum(ll x, ll y) {
	if (x > 0 && y > 0 && x > LL_MAX - y) {
		return LL_MAX;
	}
	if (x < 0 && y < 0 && x < LL_MIN - y) {
		return LL_MIN;
	}
	return x + y;
}

ll readi() {
	ll ret;
	scanf("%" PRId64 "", &ret);
	return ret;
}

vector<ll> readvi(ll n) {
	vector<ll> ret(n);
	rep(i, 0, n) { ret[i] = readi(); }
	return ret;
}

double readf() {
	double ret;
	scanf("%lf", &ret);
	return ret;
}

string reads() {
	string s;
	cin >> s;
	return s;
}

void writei(ll x) {
	printf("%" PRId64 "\n", x);
}

void writevi(const vector<ll>& xs) {
    rep(i,0,xs.size()) {
        if (i < xs.size() - 1) {
            printf("%" PRId64 " ", xs[i]);
        } else {
            printf("%" PRId64 "\n", xs[i]);
        }
    }
}

void writes(const string& s) {
	cout << s.c_str() << endl;
}

template<typename T>
vector<T> make_vec_nd(T init, ll size) {
	return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, ll size, Args... rest) {
	auto inner = make_vec_nd(init, rest...);
	return vector<decltype(inner)>(size, inner);
}

struct P {
	ll x;
	ll y;
};

int main() {
	ll N = readi();
	ll M = readi();
	vector<ll> hs = readvi(N);
	vector<ll> ws = readvi(M);
	sort(hs.begin(), hs.end());
	sort(ws.begin(), ws.end());
	struct HW {
		bool isH;
		ll idx;
		ll height;
		bool operator<(const HW& rhs) const {
			return height < rhs.height || (height == rhs.height && isH < rhs.isH);
		}
	};
	vector<HW> hws;
	rep(i,0,N) {
		hws.push_back({true, i, hs[i]});
	}
	rep(i,0,M) {
		hws.push_back({false, i, ws[i]});
	}
	sort(hws.begin(), hws.end());
	vector<ll> leftCnt(M);
	ll cnt = 0;
	for (HW& hw : hws) {
		if (hw.isH) {
			cnt++;
		} else {
			leftCnt[hw.idx] = cnt;
		}
	}
	auto makePairs = [N, &hs]() {
		vector<ll> leftPairs(N+1);
		rep(n,1,N+1) {
			if (n%2 == 0) {
				leftPairs[n] = leftPairs[n-1] + abs(hs[n-1] - hs[n-2]);
			} else {
				leftPairs[n] = leftPairs[n-1];
			}
		}
		return leftPairs;
	};
	vector<ll> leftPairs = makePairs();
	reverse(hs.begin(), hs.end());
	vector<ll> rightPairs = makePairs();
	reverse(hs.begin(), hs.end());
	// writevi(leftPairs);
	// writevi(rightPairs);
	ll ans = LL_MAX;
	rep(i,0,M) {
		ll ansLoc = 0;
		if (leftCnt[i] % 2 == 1) {
			ansLoc += leftPairs[leftCnt[i]];
			ansLoc += ws[i] - hs[leftCnt[i]-1];
			ansLoc += rightPairs[N-leftCnt[i]];
		} else {
			ansLoc += leftPairs[leftCnt[i]];
			ansLoc += hs[leftCnt[i]] - ws[i];
			ansLoc += rightPairs[N-leftCnt[i]-1];
		}
		chmin(ans, ansLoc);
	}
	writei(ans);
}


#include<bits/stdc++.h>
#define pb push_back
using namespace std;
typedef unsigned long long ull;
typedef unsigned uint;
typedef long long ll;
#define G getchar()
int read()
{
	int x=0; bool flg=false; char ch=G;
	for (;!isdigit(ch);ch=G) if (ch=='-') flg=true;
	for (;isdigit(ch);ch=G) x=(x<<3)+(x<<1)+(ch^48);
	return flg?-x:x;
}
#undef G
#define fi first
#define se second

const int mod=998244353;
inline int upd(const int &x){return x+(x>>31&mod);}
inline void add(int &x,const int &y){x=upd(x+y-mod);}
inline void iadd(int &x,const int &y){x=upd(x-y);}
int qpow(int x,int y){
	int res=1;
	for (;y;y>>=1,x=1LL*x*x%mod)
		if (y&1) res=1LL*res*x%mod;
	return res;
}

//typedef pair<int,int> P;
#define rep(i,l,r) for (int i(l);i<=int(r);i++)
#define per(i,l,r) for (int i(r);i>=int(l);i--)
#define all(x) (x).begin(),(x).end()

int n,p[200010];
int f[200010];
int find(int x){
	return f[x]?f[x]=find(f[x]):x;
}
void merge(int x,int y){
	x=find(x),y=find(y);
	if (x^y) f[y]=x;
}
void solve(){
	n=read();
	rep(i,1,n) p[i]=read(),merge(i,p[i]);
	int tot=0;
	rep(i,1,n) tot+=find(i)==i;
	printf("%d\n",qpow(2,tot)-1);
}
int main()
{
	for (int T=1;T--;) solve();
	return 0;
}

#include<iostream>
#include<cstdio>
#include<queue>
#define ll long long

struct P{
	ll to,next;
}e[400005];

int s = 0,t;

int out[200005],in[200005];

int cnt,head[200005];

int vis[200005];

void add(int a,int b){
	e[++cnt].to = b;
	e[cnt].next = head[a];
	head[a] = cnt;
}

ll n,ans = 1;

bool last[200005];

ll dcnt;

void dfs(ll now){
	if(!vis[now])
	vis[now] = 1;
	else{
		dcnt ++ ;
		return ;
	}
	for(int i = head[now];i;i = e[i].next){
		if(!last[e[i].to] || (e[i].to == now))
		dfs(e[i].to);
		last[now] = 1;
	}
}

ll mod = 998244353;

ll pow(ll now){
	ll ans = 1;
	ll a = 2;
	while(now){
		if(now & 1) ans = ans * a % mod;
		a = a * a % mod;
		now >>= 1;
	}
	return ans;
}

int main(){
	scanf("%lld",&n);
	t = n + 1;
	for(int i = 1;i <= n;++i){
		ll a;
		scanf("%lld",&a);
		add(i,a);
	}
	for(int i = 1;i <= n;++i)
	if(!vis[i])
	dfs(i);
	std::cout<<pow(dcnt) - 1<<std::endl;
}


#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << (x) << '\n'
#define debugArray(x, n)                                      \
  cerr << __LINE__ << ": " << #x << " = {";                   \
  for (long long hoge = 0; (hoge) < (long long)(n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];                   \
  cerr << "}" << '\n'
#define debugMatrix(x, h, w)                                         \
  cerr << __LINE__ << ": " << #x << " =\n";                          \
  for (long long hoge = 0; (hoge) < (long long)(h); ++(hoge)) {      \
    cerr << ((hoge ? " {" : "{{"));                                  \
    for (long long fuga = 0; (fuga) < (long long)(w); ++(fuga))      \
      cerr << ((fuga ? ", " : "")) << x[hoge][fuga];                 \
    cerr << "}" << (hoge + 1 == (long long)(h) ? "}" : ",") << '\n'; \
  }
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#define debugMatrix(x, h, w) (void(0))
#endif

template <typename T>
struct BinaryIndexedTree {
  std::vector<T> dat;
  BinaryIndexedTree(int n) : dat(n + 1, T(0)) {}
  BinaryIndexedTree(int n, T a) : BinaryIndexedTree(std::vector<T>(n, a)) {}
  BinaryIndexedTree(std::vector<T> y) : dat(y.size() + 1, 0) {
    for (size_t i = 0; i < y.size(); ++i) dat[i + 1] = y[i];
    for (int i = 1; i < (int)dat.size(); ++i)
      if (i + (i & -i) < (int)dat.size()) dat[i + (i & -i)] += dat[i];
  }
  void add(int i, T a = 1) {
    for (++i; i < (int)dat.size(); i += i & -i) dat[i] += a;
  }
  T sum(int i) {  // sum [0,i)
    T s = 0;
    for (; i > 0; i &= i - 1) s += dat[i];
    return s;
  }
  // sum [l,r)
  T sum(int l, int r) { return sum(r) - sum(l); }
  T operator[](size_t k) { return sum(k + 1) - sum(k); }
  // min { i : sum(i+1) > k } -> kth element(0-indexed)
  int find(T k) const {
    int i = 0;
    for (int p = 1 << (std::__lg(dat.size() - 1) + 1); p > 0; p >>= 1)
      if (i + p < (int)dat.size() && dat[i + p] <= k) k -= dat[i += p];
    return i + 1 == (int)dat.size() ? -1 : i;  // -1 -> no solutions
  }
};

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  int N, M, Q;
  cin >> N >> M >> Q;
  const int MAX_Y = 1e6;
  BinaryIndexedTree<long long> bita1(MAX_Y), bita2(MAX_Y), bitb1(MAX_Y),
      bitb2(MAX_Y);
  for (int i = 0; i < N; i++) bita1.add(0);
  for (int i = 0; i < M; i++) bitb1.add(0);
  long long ans = 0;
  long long a[N] = {}, b[M] = {};
  int T[Q], X[Q], Y[Q];
  for (int i = 0; i < Q; i++) cin >> T[i] >> X[i] >> Y[i];
  vector<int> v(Y, Y + Q);
  v.emplace_back(0);
  sort(begin(v), end(v));
  v.erase(unique(begin(v), end(v)), end(v));
  auto zip = [&](int hoge) {
    return lower_bound(begin(v), end(v), hoge) - begin(v);
  };
  for (int i = 0; i < Q; i++) {
    int t = T[i], x = X[i] - 1;
    if (t == 1) {
      ans -= a[x] * bitb1.sum(zip(a[x]));
      ans -= bitb2.sum(zip(a[x]), MAX_Y);
      ans += Y[i] * bitb1.sum(zip(Y[i]));
      ans += bitb2.sum(zip(Y[i]), MAX_Y);
      bita1.add(zip(a[x]), -1);
      bita2.add(zip(a[x]), -a[x]);
      bita1.add(zip(Y[i]), 1);
      bita2.add(zip(Y[i]), Y[i]);
      a[x] = Y[i];
    } else {
      ans -= b[x] * bita1.sum(zip(b[x]));
      ans -= bita2.sum(zip(b[x]), MAX_Y);
      ans += Y[i] * bita1.sum(zip(Y[i]));
      ans += bita2.sum(zip(Y[i]), MAX_Y);
      bitb1.add(zip(b[x]), -1);
      bitb2.add(zip(b[x]), -b[x]);
      bitb1.add(zip(Y[i]), 1);
      bitb2.add(zip(Y[i]), Y[i]);
      b[x] = Y[i];
    }
    cout << ans << '\n';
  }
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int sz = 105, mod = 1e9+7;

struct matrix {
   int n, v[sz][sz];

   matrix(int n) : n(n) {
      memset(v, 0, sizeof(v));
   }

   matrix operator *(const matrix &b) {
      matrix ans = matrix(n);
      for(int k=0; k<n; k++) {
         for(int i=0; i<n; i++) {
            for(int j=0; j<n; j++) {
               int &w = ans.v[i][j];
               w += (ll) v[i][k] * b.v[k][j] % mod;
               w >= mod ? w -= mod : 1;
            }
         }
      }
      return ans;
   }

   matrix operator ^(ll p) {
      matrix ans = matrix(n), b = *this;
      for(int i=0; i<n; i++) ans.v[i][i] = 1;

      while(p) {
         if(p & 1) ans = ans * b;
         p >>= 1;
         b = b * b;
      }
      return ans;
   }
};

ll bigmod(ll b, ll n) {
   if(n == -1) n = mod - 2;
   ll ans = 1;
   while(n) {
      if(n & 1) ans = ans * b % mod;
      n >>= 1;
      b = b * b % mod;
   }
   return ans;
}

ll a[sz];
bool g[sz][sz];

int main() {
   int n, m, k;
   cin >> n >> m >> k;
   for(int i=0; i<n; i++) cin >> a[i];
   matrix mat(n);
   ll two = bigmod(2, -1), minv = bigmod(m, -1);
   for(int i=0; i<m; i++) {
      int u, v;
      scanf("%d %d", &u, &v);
      u--, v--;
      g[u][v] = g[v][u] = 1;
   }
   for(int i=0; i<n; i++) {
      int c = 0;
      for(int j=0; j<n; j++) c += g[i][j];
      mat.v[i][i] = ((m - c) * minv + c * minv % mod * two) % mod;
      for(int j=0; j<n; j++) {
         if(g[i][j]) mat.v[i][j] = minv * two % mod;
      }
   }
   mat = mat ^ k;
   for(int i=0; i<n; i++) {
      ll ans = 0;
      for(int j=0; j<n; j++) ans += mat.v[i][j] * a[j] % mod;
      printf("%lld\n", ans % mod);
   }
}


#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string(string(s)); }
string to_string(bool b) { return to_string(int(b)); }
string to_string(vector<bool>::reference b) { return to_string(int(b)); }
string to_string(char b) { return "'" + string(1, b) + "'"; }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A>
string to_string(A v) {
	string res = "{";
	for (const auto& x : v) res += (res == "{" ? "" : ", ") + to_string(x);
	return res + "}";
}
void debug() { cerr << endl; }
template <typename Head, typename... Tail>
void debug(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug(T...);
}
#define db(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define db(...) 42
#endif
typedef long long ll;
typedef long double ld;
const int MOD = 1000000007;
struct Mint {
	int val;
	Mint() { val = 0; }
	Mint(ll x) {
		val = (-MOD <= x && x < MOD) ? x : x % MOD;
		if (val < 0) val += MOD;
	}
	template <typename U>
	explicit operator U() const { return (U)val; }
	friend bool operator==(const Mint& a, const Mint& b) { return a.val == b.val; }
	friend bool operator!=(const Mint& a, const Mint& b) { return !(a == b); }
	friend bool operator<(const Mint& a, const Mint& b) { return a.val < b.val; }
	Mint& operator+=(const Mint& m) { if ((val += m.val) >= MOD) val -= MOD; return *this; }
	Mint& operator-=(const Mint& m) { if ((val -= m.val) < 0) val += MOD; return *this; }
	Mint& operator*=(const Mint& m) { val = (ll)val * m.val % MOD; return *this; }
	friend Mint modex(Mint a, ll p) {
		assert(p >= 0);
		Mint ans = 1;
		for (; p; p >>= 1, a *= a) if (p & 1) ans *= a;
		return ans;
	}
	Mint& operator/=(const Mint& m) { return *this *= modex(m, MOD - 2); }
	Mint& operator++() { return *this += 1; }
	Mint& operator--() { return *this -= 1; }
	Mint operator++(int) { Mint result(*this); *this += 1; return result; }
	Mint operator--(int) { Mint result(*this); *this -= 1; return result; }
	Mint operator-() const { return Mint(-val); }
	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; }
	friend ostream& operator<<(ostream& os, const Mint& x) { return os << x.val; }
	friend string to_string(const Mint& b) { return to_string(b.val); }
};
vector<Mint> fac(1, 1), invfac(1, 1);
Mint binom(int n, int k) {
	if (k < 0 || k > n) return 0;
	while (fac.size() <= n) {
		fac.push_back(fac.back() * fac.size());
		invfac.push_back(1 / fac.back());
	}
	return fac[n] * invfac[k] * invfac[n - k];
}
char n[200005];
int main() {
	binom(16, 0);
	int k;
	scanf("%s%d", n, &k);
	// [alr][...l ?...], want exactly k distinct.
	// each non-alr has to appear at least once.
	auto calc = [&](int l, int alr) -> Mint {
		if (alr > k) return 0;
		Mint ret = 0;
		for (int i = 0; i <= k - alr; ++i) {
			Mint v = modex(Mint(k - i), l) * binom(k - alr, i);
			if (i & 1) ret -= v;
			else ret += v;
		}
		return ret;
	};
	int m = strlen(n);
	vector<bool> has(16);
	int dis = 0;
	Mint ans = 0;
	for (int i = 1; i < m; ++i) {
		ans += calc(i, 0) * binom(16, k);
		ans -= calc(i - 1, 1) * binom(15, k - 1);
	}
	for (int i = 0; i < m; ++i) {
		int val = n[i] >= '0' && n[i] <= '9' ? n[i] - '0' : n[i] - 'A' + 10;
		for (int j = (i == 0 ? 1 : 0); j < val; ++j) {
			int ndis = dis;
			if (!has[j]) ndis++;
			ans += calc(m - i - 1, ndis) * binom(16 - ndis, k - ndis);
		}
		if (!has[val]) {
			dis++;
			has[val] = true;
		}
	}
	if (dis == k) ans++;
	printf("%d\n", ans.val);
}

#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 5;
typedef long long LL;
string s;
LL dp[N][20], v[N];
LL const mod = 1e9 + 7;
int k;
int main() {
    cin >> s >> k;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] >= '0' && s[i] <= '9')
            v[i] = s[i] - '0';
        else
            v[i] = 10+s[i] - 'A';
    }
    LL state = 0;
    for (LL i = 0; i < s.size(); i++) {
        for (LL j = 1; j <= 16; ++j) {
            dp[i + 1][j] = (dp[i + 1][j] + (LL)dp[i][j] * j % mod) % mod;
            dp[i + 1][j + 1] =
                (dp[i + 1][j + 1] + (LL)dp[i][j] * (16 - j) % mod) % mod;
        }
        dp[i + 1][1] = (dp[i + 1][1] + (LL)dp[i][0] * 15 % mod) % mod;
        dp[i + 1][0] = (dp[i + 1][0] + dp[i][0]) % mod;
        for (LL j = 0; j < v[i]; ++j) {
            LL nstate = state;
            if (i || j) nstate |= (1 << j);
            dp[i + 1][__builtin_popcount(nstate)] += 1;
        }
        state |= (1 << v[i]);
    }
    cout << dp[s.size()][k] + (__builtin_popcount(state) == k) << endl;
    return 0;
}


#include<iostream>
#include<vector>
#include<queue>
using namespace std;

int func(int v,vector<vector<int>>& T,vector<bool>& F) {
  priority_queue<int> q1,q2,q3;
  int i;
  F[v] = true;
  for(i=0;i<T[v].size();i++) {
    int temp = func(T[v][i],T,F);
    if(F[T[v][i]])q2.push(temp);
    else if(temp > 0)q1.push(temp);
    else q3.push(temp);
    if(F[T[v][i]])F[v] = !F[v];
  }
  int ans = -1;
  while(!q1.empty()) {
    ans += q1.top();
    q1.pop();
  }
  for(i=0;!q2.empty();i++) {
    ans += (i%2>0?-1:1)*q2.top();
    q2.pop();
  }
  while(!q3.empty()) {
    ans += (i%2>0?-1:1)*q3.top();
    q3.pop();
  }
  return ans;
}

int main() {
  int N;
  cin >> N;
  vector<vector<int>> T(N);
  vector<bool> F(N);
  int i,p;
  for(i=1;i<N;i++) {
    cin >> p;
    T[p-1].push_back(i);
  }
  cout << ((N-func(0,T,F))/2) << endl;
}

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

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

signed main(){
    int N; cin>>N;
    int M; cin>>M;
    vec_int a(M);
    vec_int b(M);
    rep(i,M)cin>>a.at(i)>>b.at(i);
    vec_int c(N); rep(i,N)cin>>c.at(i);
    vector<vec_int> G(N+1);
    rep(i,M){
        G.at(a.at(i)).push_back(b.at(i));
        G.at(b.at(i)).push_back(a.at(i));
    }
    map<P, int> path_map;
    rep(i, M){
        path_map[make_pair(a.at(i), b.at(i))] = i;
        path_map[make_pair(b.at(i), a.at(i))] = i;
    }
    vector<string> ans(M,"");
    rep(i,M){
        if(c.at(a.at(i)-1)>c.at(b.at(i)-1)){
            ans.at(i) = "->";
        }else if(c.at(a.at(i)-1)<c.at(b.at(i)-1)){
            ans.at(i) = "<-";
        }
    }

    rep(i,M){
        if(ans.at(i)==""){
            vec_int visited(N+1, 0);
            visited.at(a.at(i)) =1;
            stack<P> st;
            st.push(make_pair(b.at(i), a.at(i))); // node, parent
            int node_val = c.at(a.at(i)-1);
            while(!st.empty()){
                int node = st.top().first;
                int parent = st.top().second;
                st.pop();
                int ind = path_map[make_pair(parent, node)];
                if(ans.at(ind)!="")continue;
                if(a.at(ind)==parent && b.at(ind)==node){
                    ans.at(ind) = "->";
                }else{
                    ans.at(ind) = "<-";
                }
                for(auto next_node: G.at(node)){
                    if(next_node==parent)continue;
                    if(c.at(next_node-1)!=node_val)continue;
                    st.push(make_pair(next_node, node));
                }
            }
        }
    }
    rep(i,M){
        cout<<ans.at(i)<<endl;
    }

    return 0;
}


#include <stdio.h>
#include <utility>
#include <vector>
#include <numeric>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri();
	std::vector<int> a(1 << n);
	for (auto &i : a) i = ri();

	std::vector<int> remaining(1 << n);
	std::iota(remaining.begin(), remaining.end(), 0);

	for (int i = 1; i <= n; i++) {
		std::vector<int> next_remaining;
		for (int j = 0; j < 1 << (n - i); j++) {
			if (a[remaining[j * 2]] > a[remaining[j * 2 + 1]]) next_remaining.push_back(remaining[j * 2]);
			else next_remaining.push_back(remaining[j * 2 + 1]);
		}
		if (i == n) {
			printf("%d\n", 1 + (remaining[0] == next_remaining[0] ? remaining[1] : remaining[0]));
			return 0;
		}
		remaining = next_remaining;
	}

	return 0;
}

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

int main(){
    int N;
    cin >> N;
    int64_t num = 1 << N;
    vector<int> A(num), B(num);
    for(int i=0; i<num; i++){
        cin >> A[i];
        B[i] = i;
    }
    for(int i=1; i<N; i++){
        int split = 1 << (i-1);
        for(int j=(1<<i); j<=num; j+=(1<<i)){
            if(A[j-1] < A[j-split-1]){
                A[j-1] = A[j-split-1];
                B[j-1] = B[j-split-1];
            }
        }
    }

    if(A[num/2-1] > A[num-1]){
        cout << B[num-1]+1 << endl;
    } else {
        cout << B[num/2-1]+1 << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const long double EPS = 1e-8;

long double eq(long double a, long double b){
  return fabs(a - b) < EPS;
}

struct point {
  long double x, y;

  point(long double _x=0, long double _y=0) :
    x(_x), y(_y) {}

  bool operator == (point &o) const {
    return eq(x, o.x) and eq(y, o.y);
  }

  bool operator < (point &o) const {
    if(!eq(x, o.x)) return x < o.x;
    if(!eq(y, o.y)) return y < o.y;
    return false;
  }

  bool operator <= (point &o) const {
    if(*this == o) return true;
    return *this < o;
  }
};

void rotate_set(vector<point> &P, long double angle){
  long double sin_angle = sin(angle);
  long double cos_angle = cos(angle);

  for(point &p : P){
    p = point(p.x * cos_angle - p.y * sin_angle,
	      p.x * sin_angle + p.y * cos_angle);
  }
}

vector<point> normalize(int a[], int b[], int N, int i1, int i2){
  vector<point> P(N);

  for(int i = 0; i < N; i++){
    P[i] = point(a[i], b[i]);
  }

  double pivot_x = P[i1].x;
  double pivot_y = P[i1].y;

  for(point &p : P){
    p.x -= pivot_x;
    p.y -= pivot_y;
  }

  long double angle = atan2(P[i2].y, P[i2].x);
  rotate_set(P, -angle);

  return P;
}

bool are_the_same(vector<point> &S, vector<point> &T){
  sort(S.begin(), S.end());
  sort(T.begin(), T.end());

  for(int i = 0; i < S.size(); i++){
    if(!(S[i] == T[i])) return false;
  }

  return true;
}

int main(){
  int N;
  while(scanf("%d", &N) > 0){
    int a[N], b[N], c[N], d[N];

    for(int i = 0; i < N; i++){
      scanf("%d%d", &a[i], &b[i]);
    }

    for(int i = 0; i < N; i++){
      scanf("%d%d", &c[i], &d[i]);
    }

    if(N == 1){
      printf("Yes\n");
      continue;
    }

    vector<point> T = normalize(c, d, N, 0, 1);
    bool test = false;

    for(int i = 0; i < N and !test; i++){
      for(int j = 0; j < N and !test; j++){
	if(i == j) continue;
	vector<point> S = normalize(a, b, N, i, j);

	if(are_the_same(S, T)){
	  test = true;
	}
      }
    }

    printf("%s\n", test ? "Yes" : "No");
  }
}

#include <bits/stdc++.h>

#define fi first
#define se second
#define DB double
#define U unsigned
#define LL long long
#define LD long double
#define pb emplace_back
#define MP std::make_pair
#define SZ(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define FOR(i,a,b) for(int i = a;i <= b;++i)
#define ROF(i,a,b) for(int i = a;i >= b;--i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl

const int MAXN = 100 + 5;
const DB EPS = 1e-9;

inline int sgn(DB x){
	if(std::fabs(x) <= EPS) return 0;
	return x > 0 ? 1 : -1;
}

struct P{
	DB x,y;
	P(DB x=0,DB y=0) : x(x),y(y) {}
	P operator + (const P &t) const {return P(x+t.x,y+t.y);}
	P operator - (const P &t) const {return P(x-t.x,y-t.y);}
	DB dot(const P &t){return x*t.x+y*t.y;}
	DB det(const P &t){return x*t.y-y*t.x;}
	DB len2(){return x*x+y*y;}
	DB len(){return std::sqrt(len2());}

	inline bool operator < (const P &t) const {
		if(sgn(x-t.x)) return sgn(x-t.x) < 0;
		return sgn(y-t.y) < 0;
	}

	inline bool operator == (const P &t) const {
		return !sgn(x-t.x) && !sgn(y-t.y);
	}
}a[MAXN],b[MAXN],c[MAXN],t[MAXN];
int n;

inline P rotate(P v,DB sin,DB cos){
	return P(v.x*cos-v.y*sin,v.x*sin+v.y*cos);
}

int main(){
//	freopen("A.in","r",stdin);
	scanf("%d",&n);
	if(n <= 2){
		puts("Yes");
		return 0;
	}
	FOR(i,1,n) scanf("%lf%lf",&a[i].x,&a[i].y);
	FOR(i,1,n) scanf("%lf%lf",&b[i].x,&b[i].y);
	std::sort(b+1,b+n+1);
	// a[i]*A-b[i] = a[j]*A-b[j]
	// (a[i]-a[j])*A = b[i]-b[j]
	FOR(i,1,n) FOR(j,1,n){
		if(i == j) continue;
		P u = a[1]-a[2],v = b[i]-b[j];
//		if(!sgn(u.len()) || !sgn(v.len())) continue;
		DB Cos = u.dot(v)/u.len()/v.len(),Sin = u.det(v)/u.len()/v.len();

		FOR(k,1,n) c[k] = rotate(a[k],Sin,Cos);

		FOR(k,1,n){
			P vec = b[k]-c[1];
			FOR(l,1,n) t[l] = c[l]+vec;
			std::sort(t+1,t+n+1);
			bool flag = 1;
			FOR(l,1,n) flag &= t[l]==b[l];
			if(flag){
				puts("Yes");
				return 0;
			}
		}
	}
	puts("No");
	return 0;
}


#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <tuple>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <functional>
#include <numeric>
#include <iomanip>
#include <stdio.h>
//eolibraries
#define lnf 3999999999999999999
#define inf 999999999
#define PI 3.14159265359
#define endl "\n"
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define ll long long
#define all(c) (c).begin(),(c).end()
#define sz(c) (int)(c).size()
#define mkp(a,b) make_pair(a,b)
#define make_unique(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define rsz(a,n) a.resize(n)
#define pii pair <int,int>
#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define drep(i,n) for(int i = n-1 ; i >= 0 ; i--)
#define crep(i,x,n) for(int i = x ; i < n ; i++)
#define vi vector <int>
#define vec(...) vector<__VA_ARGS__>
#define rsz(a,n) a.resize(n)
#define rszv(a,n,v) a.resize(n,v)
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
//eodefine

const int max_n = 500000;

using namespace std;
int n;
vi adj[max_n];

vec(pii) qry[max_n];
int ans[max_n];

int depth[max_n],siz[max_n],ep[max_n];

void dfsfsiz(int x,int par=-1) {
	siz[x]=1;
	for(auto y : adj[x]) {
		if(y==par)continue;
		depth[y]=depth[x]+1;
		dfsfsiz(y,x);
		siz[x]+=siz[y];
	}
}

map <int,int> mp[max_n];

void dfs(int x,int par=-1) {

	int mx=0,vtk=x;

	for(auto y : adj[x]) {
		if(y == par)continue;
		dfs(y,x);
		if(siz[y]>mx) {
			mx=siz[y];
			vtk=ep[y];
		}
	}

	mp[vtk][depth[x]]++;

	for(auto y : adj[x]) {
		if(ep[y]==vtk)continue;
		for(auto p : mp[ep[y]]) {
			mp[vtk][p.fi]+=p.se;
		}
	}

	for(auto p : qry[x]) {
		ans[p.se]=mp[vtk][p.fi];
	}

	ep[x]=vtk;
}

int main(){
fcin;
	cin>>n;
	rep(i,n-1) {
		int x;cin>>x;x--;
		adj[x].pb(i+1);
		adj[i+1].pb(x);
	}

	dfsfsiz(0);

	int q;
	cin>>q;
	rep(_,q) {
		int x,d;
		cin>>x>>d;
		x--;
		qry[x].pb({d,_});
	}

	dfs(0);

	rep(i,q)cout<<ans[i]<<"\n";

/*
*/

    return 0;
}

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

void solve(){
	int n;
	cin>>n;
	vector<int> a(n);
	for(int i=0;i<n;i++)cin>>a[i];
	vector<int> ans;
	for(int t=0;;t++){
		bool up=true;
		for(int i=0;i+1<n;i++) if(a[i]>a[i+1]) up=false;
		if(up) break;
		int s=t%2;
		while(s+1<n && a[s]<a[s+1]) s+=2;
		if(s+1>=n){
			ans.push_back(s-2);
			swap(a[s-2],a[s-1]);
		} else{
			ans.push_back(s);
			swap(a[s],a[s+1]);
		}
	}
	cout << ans.size() << "\n";
	for(int i=0;i<ans.size();i++) cout << ans[i]+1 << " ";
    cout << "\n";
}

int main(){
	int t;
	cin>>t;
	while(t--) solve();
}


#include <bits/stdc++.h>
#define FOR(i, j, k) for(int i = j; i < k; i ++)
#define FORE(i, j, k) for(int i = j; i <= k; i ++)
#define FORD(i, j, k) for(int i = j; i >= k; i --)
#define mp make_pair
#define ll long long
//#define f first
//#define s second
#define int long long
using namespace std;

const int MOD=1e9+7;
const int N = 200005;

int k, n, m;
int a[N], b[N];

#undef int
int main()
{
    cin >> k >> n >> m;
    vector< pair < int, int > > lst(k);
    int cnt = m;
    FOR(i, 0, k)
    {
        cin >> a[i];
        b[i] = (m * a[i]) / n;
        cnt -= b[i];
        lst[i] = mp(b[i] * n - a[i] * m, i);
    }

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

    FOR(i, 0, k)
    {
        if(cnt != 0)
        {
            -- cnt;
            b[lst[i].second] ++;
        }
    }

    FOR(i, 0, k)
    {
        cout << b[i] << " ";
    }
    return 0;
}

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

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

//そんな貪欲みたいなことができるんですか？
int A[100000];
ll are[100000];

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	if ((tmp & ma0) ^ ma0) {
		int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
		tmp = tmp << dig & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += (72 - dig >> 3);
	}
	else {
		tmp = tmp & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += 8;
		if ((ct = *ci++) >= '0') {
			tmp = tmp * 10 + ct - '0';
			if (*ci++ == '0') {
				tmp = tmp * 10;
				ci++;
			}
		}
	}
	return tmp;
}
const int MAX = 100000;
class shuturyoku_unko {
public:
	char C[MAX * 5];
	constexpr shuturyoku_unko() : C() {
		rep(i, MAX) {
			int X = i;
			rep(j, 5) {
				C[i * 5 + 4 - j] = '0' + X % 10;
				X /= 10;
			}
		}
	}
};
constexpr shuturyoku_unko f;
const int dm = 1 << 17;
char *dn = cn, * di = dn, * owad = dn + dm - 20;
void putint(ll A) {
	if (owad < di) {
		fwrite(dn, 1, di - dn, stdout);
		di = dn;
	}
	int dig = 1;
	if (A >= 100000) {
		if (A >= 1000000000) dig = 5;
		else if (A >= 100000000) dig = 4;
		else if (A >= 10000000) dig = 3;
		else if (A >= 1000000) dig = 2;
		memcpy(di + dig, f.C + A % 100000 * 5, 5);
		A /= 100000;
		memcpy(di, f.C + A * 5 + 5 - dig, dig);
		di += 5 + dig;
	}
	else {
		if (A >= 10000) dig = 5;
		else if (A >= 1000) dig = 4;
		else if (A >= 100) dig = 3;
		else if (A >= 10) dig = 2;
		memcpy(di, f.C + A * 5 + 5 - dig, dig);
		di += dig;
	}
	*di++ = ' ';
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int K = getint(), N = getint(), M = getint();
	int kazu = 0;
	rep(i, K) {
		ll a2 = ll(getint()) * M;
		A[i] = a2 / N;
		are[i] = a2 - ll(A[i]) * N << 32 | i;
		kazu += A[i];
	}
	nth_element(are, are + K - M + kazu, are + K);

	for(int i = K - 1; i >= K - M + kazu; i--) A[are[i] & (1 << 20) - 1]++;
	rep(i, K) putint(A[i]);
	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}


#include<bits/stdc++.h>
#include <iostream>
#include <ctype.h>
#include <math.h>
#include <set>
#include<string.h>
#include<stdio.h>

using namespace std;
#define boost std::ios::sync_with_stdio(false);

typedef long long ll;

int t;
const int mod = 1000000007;
const int N = 1e3 + 6;
const int MOD = 2019;

int GCD(int a, int b)
{
    if(b == 0)
    return a;
    else
     return GCD(b,a%b);
}

int pow(int a, int b, int m)
{
	int ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}

int modinv(int k)
{
	return pow(k, MOD-2, MOD);
}

int pl[1000003];

void sieve(ll n) {
	bool prime[n+1];
	memset(prime, 1, sizeof prime);
	for(ll p = 2; p*p <= n; p++) {
		if(prime[p]) {
			for(ll i = p*p; i <= n; i+= p) {
				prime[i] = false;
			}
		}
	}
	pl[0] = 0;
	for(ll i = 3; i <= n; i++) {
		pl[i] = pl[i-1];
		if(prime[i]) pl[i]++;
	}
}

int primeDivisorCount(int x)
{
    int count = 0;
    for(ll i = 1;i*i<=x;i++)
    {
        if(x%i == 0)
        {
            if(x/i != i)
            {
                count+=2;
            }
            else
            {
                count++;
            }
        }
    }
    return count;
}

int findGCD(vector<int> &arr, int n)
{
	int result = arr[0];
	for (int i = 1; i < n; i++)
	{
		result = __gcd(arr[i], result)%mod;

		if(result == 1)
		{
		return 1%mod;
		}
	}
	result %= mod;
	return result;
}

int main()
{

    boost;

    string s;
    cin>>s;

    int x = s.rfind(".");
    string r = s.substr(0,x);

    cout<<r<<endl;

    return 0;
}

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

int main() {
    string x, ans;
    cin >> x;

    for (int i = 0; i < x.length(); i++) {
        if (x[i] == '.') {
            break;
        }
        else {
            ans += x[i];
        }
    }

    cout << ans << endl;

    return 0;
}


#include <bits/stdc++.h>

#define ff first
#define ss second
#define mp make_pair

using namespace std;

typedef long long ll;

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

    ll x1, y1;
    ll g = gcd(b, a%b, x1, y1);
    x = y1;
    y = x1 - (a/b)*y1;
    return g;
}

ll crt(const vector<pair<ll, ll>> &vet){
    ll ans = 0, lcm = 1;
    ll a, b, g, x, y;
    for(const auto &p : vet) {
        tie(a, b) = p;
        ll x, y;
        ll g = gcd(lcm, b, x, y);
        if((a - ans) % g != 0) return -1; // no solution
        ans = ans + x * ((a - ans) / g) % (b / g) * lcm;
        lcm = lcm * (b / g);
        ans = (ans % lcm + lcm) % lcm;
    }
    return ans;
}

int main(){
    int T,x,y,p,q;

    scanf("%d", &T);

    while(T--) {
        scanf("%d%d%d%d", &x, &y, &p, &q);

        ll best = -1;
        for(int a = x; a < x+y; a++) {
            for(int b = p; b < p+q; b++) {
                vector<pair<ll,ll>> aux;
                aux.emplace_back(a, 2LL*x + 2LL*y);
                aux.emplace_back(b, p+q);
                ll cand = crt(aux);
                if(cand == -1) continue;
                if(best == -1 or cand < best) best = cand;
            }
        }
        if(best == -1) printf("infinity\n");
        else printf("%lld\n", best);
    }

    return 0;
}

#include<iostream>
#include<vector>
#include<algorithm>
#include<random>
#include<map>
long long int realOdometer = 0;
long long int manhattanOdometer = 0;
long long int generalAverage = 0;
using namespace std;
int main(){
  pair<int, int>s, t;
  map<pair<pair<int, int>, pair<int, int>>, pair<int, int>>distance;
  int loopCount = 0;
  while(cin >> s.first >> s.second >> t.first >> t.second){
    string str = "";
    for(int i=0; i<abs(t.first-s.first); i++){
      str = str + (t.first-s.first>0? "D": "U");
    }
    for(int i=0; i<abs(t.second-s.second); i++){
      str = str + (t.second-s.second>0? "R": "L");
    }
    mt19937 g(loopCount);
    shuffle(str.begin(), str.end(), g);
    if(loopCount<2){
      cout << str << endl;
    }else{
      str.clear();
      pair<int, int>currentPos = s;
      while(currentPos!=t){
        if(currentPos.first==t.first||currentPos.second==t.second){
          if(currentPos.first==t.first){
            str.push_back(currentPos.second<t.second? 'R': 'L');
          }else{
            str.push_back(currentPos.first<t.first? 'D': 'U');
          }
        }else{
          pair<int, int>component0 = make_pair(currentPos.first, currentPos.second + (currentPos.second<t.second? +1: -1));
          pair<int, int>component1 = make_pair(currentPos.first + (currentPos.first<t.first? +1: -1), currentPos.second);
          pair<pair<int, int>, pair<int, int>>candidate0 = make_pair(currentPos, component0);
          pair<pair<int, int>, pair<int, int>>candidate1 = make_pair(currentPos, component1);
          if(candidate0.first>candidate0.second){
            swap(candidate0.first, candidate0.second);
          }
          if(candidate1.first>candidate1.second){
            swap(candidate1.first, candidate1.second);
          }
          int d0 = distance[candidate0].first!=0? distance[candidate0].first: generalAverage;
          int d1 = distance[candidate1].first!=0? distance[candidate1].first: generalAverage;
          if(d0<d1){
            str.push_back(currentPos.second<t.second? 'R': 'L');
          }else{
            str.push_back(currentPos.first<t.first? 'D': 'U');
          }
        }
        currentPos.first+= (str.back()=='D') - (str.back()=='U');
        currentPos.second+= (str.back()=='R') - (str.back()=='L');
      }
      cout << str << endl;
    }
    long long int D;
    cin >> D;
    realOdometer+= D;
    manhattanOdometer+= str.length();
    generalAverage = realOdometer/manhattanOdometer;
    int manhattan_d = str.length();
    vector<pair<pair<int, int>, pair<int, int>>>toDoList;
    for(int i=0; i<manhattan_d; i++){
      pair<int, int>temp1, temp2;
      if(i!=0){
        temp1 = toDoList.back().second;
      }else{
        temp1 = s;
      }
      auto convert = [&](char c){
        pair<int, int> val = temp1;
        if(c=='R'||c=='L'){
          val = make_pair(val.first, val.second + (c=='R'? +1: -1));
        }else{
          val = make_pair(val.first + (c=='D'? +1: -1), val.second);
        }
        return val;
      };
      temp2 = convert(str.at(i));
      toDoList.push_back(make_pair(temp1, temp2));
    }
    while(toDoList.size()!=0){
      if(toDoList.back().first>toDoList.back().second){
        swap(toDoList.back().first, toDoList.back().second);
      }
      distance[toDoList.back()].second++;
      distance[toDoList.back()].first =
        (distance[toDoList.back()].first * (distance[toDoList.back()].second-1)
        + D/manhattan_d)/distance[toDoList.back()].second;
      toDoList.pop_back();
    }
    loopCount++;
  }
  return 0;
}


/*_____________________
	|Author : canhnam357|
	|___________________|
*/
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <string> vS;
typedef vector <vector <int>> vvi;
typedef vector <vll> vvll;
typedef map<int, int> mi;
typedef map<string, int> ms;
typedef map<char, int> mc;
typedef map <int, bool> mb;
typedef map<ll, ll> mll;
typedef unordered_map<int, int> umi;
typedef unordered_map<string, int> ums;
typedef unordered_map<char, int> umc;
typedef unordered_map <int, bool> umb;
typedef unordered_map<ll, ll> umll;
typedef string S;
typedef vector <ld> vld;
typedef vector <bool> vb;
typedef pair <int, int> pii;
typedef pair<ll, ll> pll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
#define FOR(i,N) for(ll i = 0 ; i < N;i++)
#define eFOR(i,a,b) for(ll i = a; i <=b;i++)
#define dFOR(i,N) for(ll i = N - 1; i>=0;i--)
#define edFOR(i,b,a) for(ll i = b ; i >=a;i--)
#define all(x) x.begin(),x.end()
#define SORT(x) sort(all(x))
#define RSORT(x) sort(x.rbegin(),x.rend())
#define UNQ(x)  unique(all(x))
#define mine(x) min_element(all(x))
#define maxe(x) max_element(all(x))
#define pb push_back
#define PI 3.141592653589793
#define FIX cout << fixed << setprecision(15);
const ll mod = 998244353;
int CASE = 1;
const int mxn = 2e4 + 1;
const ll INF = 1e18;
int __gcd(int a, int b)
{
	return !b ? a : __gcd(b, a % b);
}
ll sum(ll n)
{
	return (n * (n + 1) / 2) % mod;
}
void solve()
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	string t = "";
	for (char c : s)
	{
		t.push_back(c);
		if (t.length() > 2 && t.substr(t.length() - 3) == "fox")
		{
			t.pop_back();
			t.pop_back();
			t.pop_back();
		}
	}
	cout << t.length();
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int T = 1;
	while (T--)
	{
		solve();
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
//const int mod=998244353;
using P = pair<int,int>;
using Pl= pair<ll,ll>;
using ld=long double;
using V=vector<int>;
using Vl=vector<ll>;
using VV=vector<vector<int>>;
using VVl=vector<vector<ll>>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;cin >>n;
    string s;cin >>s;
    vector<string>tmp;
    ll ans=0;
    for (int i = 0; i < n;) {
        if(s[i]!='f' and s[i]!='o' and s[i]!='x'){
            tmp.clear();
            i++;
        }
        else if(s.substr(i,3)=="fox"){
            ans+=3;
            i+=3;
        }
        else if(s.substr(i,2)=="fo"){
            tmp.push_back("fo");
            i+=2;
        }
        else if(s[i]=='f'){
            tmp.push_back("f");
            i++;
        }
        else if(s.substr(i,2)=="ox"){
            if(tmp.empty()){
                i+=2;
            }
            else{
                if(tmp.back()=="f"){
                    ans+=3;
                    i+=2;
                    tmp.pop_back();
                }
                else{
                    tmp.clear();
                    i+=2;
                }
            }
        }
        else if(s[i]=='x'){
            if(tmp.empty()){
                i++;
            }
            else{
                if(tmp.back()=="fo") {
                    ans += 3;
                    i++;
                    tmp.pop_back();
                }
                else{
                    tmp.clear();
                    i++;
                }
            }
        }
        else if(s[i]=='o'){
            if(tmp.empty()) {
                i++;
            }
            else if(tmp.back()=="f"){
                tmp.pop_back();
                tmp.push_back("fo");
                i++;
            }
            else {
                tmp.clear();
                i++;
            }
        }
        else {
            tmp.clear();
            i++;
        }
    }
    cout <<n-ans<<"\n";
    return 0;
}


#include <algorithm>
#include <iomanip>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <numeric>
#include <vector>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i, n) _rep2(i, 0, n)
#define _rep2(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using i64 = long long;
template<class T, class U>
bool chmin(T& a, const U& b) { return (b < a) ? (a = b, true) : false; }
template<class T, class U>
bool chmax(T& a, const U& b) { return (b > a) ? (a = b, true) : false; }

template<typename T>istream& operator>>(istream&i,vector<T>&v){rep(j,v.size())i>>v[j];return i;}
template<typename T>string join(vector<T>&v){stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v){if(v.size())o<<join(v);return o;}
template<typename T>string join(vector<vector<T>>&vv){string s="\n";rep(i,vv.size())s+=join(vv[i])+"\n";return s;}
template<typename T>ostream& operator<<(ostream&o,vector<vector<T>>&vv){if(vv.size())o<<join(vv);return o;}
template<class T> using pq = priority_queue<T, vector<T>, greater<T>>;

struct C
{
    int x, y;
    C(int x = 0, int y = 0) : x(x), y(y) {}
    C operator*(const C& a) const {
        return C(x * a.x - y * a.y, x * a.y + y * a.x);
    }
    C operator-(const C& a) const {
        return C(x - a.x, y - a.y);
    }
    bool operator<(const C& a) const {
        if (x == a.x) return y < a.y;
        return x < a.x;
    };
    bool operator==(const C& a) const {
        return x == a.x && y == a.y;
    };
    int norm() const { return x*x + y*y;}
};

int main()
{
    int n;
    cin >> n;
    vector<C> a(n), b(n);
    rep(i, n) {
        int x,y;
        cin >> x >> y;
        a[i] = C(x, y);
    }
    rep(i, n) {
        int x, y;
        cin >> x >> y;
        b[i] = C(x, y);
    }

    if(n == 1) {
        cout << "Yes" << endl;
        return 0;
    }

    rep(i, n) {
        rep(j, n) {
            // a[0] -> b[i]
            // a[1] -> b[j]
            if(i == j) continue;
            if((a[1] - a[0]).norm() != (b[j] - b[i]).norm()) continue; // 長さが違えばアウト

            auto f = [&](vector<C> p, C o, C r) {
                rep(i, n) p[i] = p[i] - o; // 平衡移動
                rep(i, n) p[i] = p[i] * r; // 回転
                sort(p.begin(), p.end());
                return p;
            };
            vector<C> na = f(a, a[0], b[j] - b[i]); // a[0] を原点にして，回転
            vector<C> nb = f(b, b[i], a[1] - a[0]); // a[0] を原点にして，回転
            if(na == nb) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;

    return 0;
}

#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 1e9+7;
const int MAXN = (int) 3e5+5;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n;

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

    #ifdef Local
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/int.txt","r",stdin);
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/out.txt","w",stdout);
    #endif

    ll b, c;

    cin>>b>>c;

    pll ara[4];

    if(b > 0){
        ara[0] = {-b - (c - 1) / 2,  -b};
        ara[1] = {b,  max(b, - (- b - c / 2)  - 1)};
        ara[2] = {b - c / 2, b};
        ara[3] = {-b, -(b - (c - 1) / 2)};
    }else if(b < 0){
        ara[0] = {b - c / 2, b};
        ara[1] = {-b, -b + (c - 1) / 2};
        ara[2] = {-b - (c - 1) / 2, -b};
        ara[3] = {b, - (-b - c / 2 + 1)};
    }else if(b == 0){
        ara[0] = {-c / 2, 0};
        ara[1] = {0, (c - 1) / 2};
        ara[2] = {0, 0};
        ara[3] = {0, 0};
    }
    sort(ara, ara + 4);

    ll cur = -3e18;

    ll ans = 0;

    for(pll u: ara){
        //cerr<<u.ff<<" "<<u.ss<<endl;
        if(u.ff > cur){
            ans += u.ss - u.ff + 1;
            cur = u.ss;
        }else{
            ans += max(0LL, u.ss - cur);
            cur = max(cur, u.ss);
        }
    }

    cout<<ans<<endl;

    #ifdef Local
        cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
using graph = vector<VI>;
template<class T = ll> using w_graph = vector<vector<pair<int, T>>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define SORT(a) sort(a.begin(),a.end())
#define rSORT(a) sort(a.rbegin(),a.rend())
#define fSORT(a,f) sort(a.begin(),a.end(),f)
#define all(a) a.begin(),a.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define tp(a,i) get<i>(a)
#ifdef _DEBUG
#define line cout << "-----------------------------\n"
#define stop system("pause")
#endif
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }
template<class T>inline T sum(const vector<T>& a, int l, int r) { return a[r] - (l == 0 ? 0 : a[l - 1]); }
template<class T>inline void END(T s) { print(s); exit(0); }
void END() { exit(0); }

int main() {
    init();

    VI p;
    const int lim = 72;
    FOR(i, 2, lim) {
        bool isP = true;
        for (int j = 2; j * j <= i; ++j) {
            if (i % j == 0)isP = false;
        }
        if (isP)p.push_back(i);
    }
    int s = p.size();

    ll a, b; cin >> a >> b;
    int n = b - a + 1;
    auto dp = vec<ll>(n + 1, 1 << s);
    dp[0][0] = 1;
    FOR(i, 0, n) {
        ll x = a + i;
        int nxtbit = 0;
        FOR(j, 0, s) {
            if (x % p[j] == 0)nxtbit |= (1 << j);
        }
        FOR(bit, 0, 1 << s) {
            dp[i + 1][bit] += dp[i][bit];
            if(!(bit&nxtbit))dp[i + 1][bit|nxtbit] += dp[i][bit];
        }
    }
    ll ans = 0;
    FOR(bit, 0, 1 << s)ans += dp[n][bit];
    print(ans);

    return 0;
}

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

int main() {
	string n;
	cin >> n;
	int k;
	cin >> k;
	int nn = n.size();
	vector<vector<long long int>> v(nn + 1, vector<long long int>(k + 1, 0));
	unordered_set<int> us;
	long long int res = 0;
	const int mod = 1e9 + 7;
	for (int i = 1; i <= nn; i++) {
		// v[already checked][how many used]
		if (i > 1) {
			v[i][1] += 15;
		}
		for (int j = 0; j <= k; j++) {
			// v[i - 1][j] -> v[i][j or j + 1];
			v[i][j] += v[i - 1][j] * j;
			if (j > 0) v[i][j] += v[i - 1][j - 1] * (16 - j + 1);
			v[i][j] %= mod;
		}

		char c = n[i - 1];
		int nc = (c <= '9' and c >= '0' ? c - '0' : c - 'A' + 10);
		for (int j = (i == 1 ? 1 : 0); j < nc; j++) {
			int e = 0;
			if (us.count(j) == 0) e = 1;
			if (us.size() + e <= k) {
				v[i][us.size() + e]++;
			}
		}
		us.insert(nc);
	}
	if (us.size() == k) res++;
	for (int i = k; i <= k; i++) {
		res += v[nn][i];
	}
	res %= mod;
	cout << res << endl;
}


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

#define         ld                  long double
#define         lli                 long long int
#define         vi                  vector<int>
#define         vlli                vector<lli>
#define         vvi                 vector<vi >
#define         vvl                 vector<vlli >
#define         str                 string
#define         vs                  vector<str>
#define         vb                  vector<bool>
#define         mp                  make_pair
#define         pii                 pair<int, int>
#define         pll                 pair<lli, lli>
#define         vpii                vector<pii>
#define         vpll                vector<pll>
#define         pb                  push_back
#define         all(a)              a.begin(),a.end()
#define         rev(a)              reverse(all(a))
#define         min3(a, b, c)       min(a, min(b, c))
#define         max3(a, b, c)       max(a, max(b, c))
#define         ft                  first
#define         sd                  second

#define         loop(i, s, l, j)    for(int i = s; i < l; i += j)
#define         rloop(i, s, l, j)   for(int i = s; i >= l; i -= j)
#define         rep(i, n)           loop(i,0,n,1)
#define         rrep(i, n)          rloop(i,n-1,0,1)
#define			inp(a,n)			rep(i,n)cin >> a[i]

#define fastio() ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)

#define mod 1000000007
#define inf 10000000
#define limit 1000005

void solve()
{
	int n;
	str s;
	cin >> n >> s;

	int ans = 0;
	rep(i,n)
	{
		int fa = 0, ft = 0, fc = 0, fg = 0;
		loop(j,i,n,1)
		{
			if(s[j] == 'A')fa++;
			if(s[j] == 'T')ft++;
			if(s[j] == 'C')fc++;
			if(s[j] == 'G')fg++;

			if(fa == ft && fc == fg)
				ans++;
		}

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

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

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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)

typedef long long ll;
const ll INF = (1LL << 62) - (1LL << 31); /*オーバーフローしない程度に大きい数*/
const ll MOD = 1000000007;
using namespace std;

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

template <class T>
void chmin(T& a, T b) {  // choose minimum.
    if (a > b) {
        a = b;
    }
}
template <class T>
void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

const int mod = 1e9 + 7;
struct mint {
    ll x;  // typedef long long ll;
    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;
    }
};

// MODのときの計算に使うのでmintになっている.
mint choose(int n, int a) {
    mint x = 1, y = 1;
    rep(i, a) {
        x *= n - i;
        y *= i + 1;
    }
    return x / y;
}

struct UnionFind {
    vector<int> par, siz;

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

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

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

    bool unite(int x, int y) {
        // x,yを根まで移動する
        x = root(x);
        y = root(y);
        // すでに同じグループのときは何もしない
        if (x == y) return false;
        /// union by size (y側のサイズが小さくなるようにする)
        if (siz[x] < siz[y]) swap(x, y);
        // yをxの子とする
        par[y] = x;
        siz[x] += siz[y];
        return true;
    }

    // xを含むグループのサイズ
    int size(int x) {
        int ret = siz[root(x)];
        return ret;
    }
};

// 辺を表す型，ここでは重みを表す型を long long 型とする
struct Edge {
    int to;       // 隣接頂点番号
    long long w;  // 重み
    Edge(int to, long long w) : to(to), w(w) {}
};

// 重み付きグラフを表す型
using Graph = vector<vector<Edge>>;

// 緩和を実施する関数
template <class T>
bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    } else
        return false;
}

int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};

int ctoi(char c) {
    if (c >= '0' && c <= '9') {
        return c - '0';
    }
    return 0;
}

int main() {
#ifdef LOCAL
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    int n;
    cin >> n;

    vector<int> x(n), y(n);
    rep(i, n) cin >> x[i] >> y[i];

    int ans = 0;
    rep(i, n - 1) repi(j, i + 1, n) {
        int dx = x[j] - x[i];
        int dy = y[j] - y[i];

        if (abs(dy) <= abs(dx)) ans++;

    }

    cout << ans;

    return 0;
}


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

	cout<<ans<<endl;
	return FastIO::Fflush(),0;
}
/*

*/

//Author : RISHABH (still under construction)
//Don't give up if you can't solve problem !

//TIPS : //copied from Benq
/*
	--> check out for integer overflows
	--> special cases like n==1
	--> do something instead of just sitting and fooling around
	--> write everything before you forget
	--> think of various approaches
	--> think if all the cases are similar by taking one case
	--> "NEVER USE FLOAT OR DOUBLE IF YOU HAVE NOT BEEN GIVEN THE ANS AS FLOAT OR DOUBLE"
*/

//includes all headder files :
#include <bits/stdc++.h>

//standard namespace :
using namespace std ;

//defining macros :
#define ll long long
#define fo(i , k , n) for(int i = k ; i < n ; i++)
#define pb push_back
#define eb embrace_back
#define rtn return
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin() , x.end() //forward traversal
#define rall(x) (x).rbegin, (x).rend() //reverse traversal
#define sz(a) int((a).size()) // Avoiding wrap around of size()-1 where size is a unsigned int.
#define sortall(x) sort(all(x))
#define rep(it , v) for(auto it = v.begin() ; it != v.end() ; it++)
#define each(a,x) for(auto& a : x)
#define ft front
#define bk back
#define print(x) cout << (x) ;
#define printarr(x) cout << (x) << " " ; //Credit - Harsh (cf handle : silvermirror)
#define nline endl ;
#define max(a,b,c) fmax(fmax(a,b) , c)
#define min(a,b,c) fmin(fmin(a,b) , c)
#define square(x) x*x
#define cube(x) x*x*x
#define cin(x) cin >> x ;
#define cin2(a,b) cin >> a >> b ;
#define cin3(a,b,c) cin >> a >> b >> c ;
#define cin4(a,b,c,d) cin >> a >> b >> c >> d ;
#define gline(s) getline(cin , a) ;
#define sortarr(a,n) sort(a , a+n) ;
#define Ignore cin.ignore() ;
#define mem(n,i) memset(n , i , sizeof(n)) ;
#define deci(n) cout << fixed << setprecision(n) ;
#define clr clear()
#define yes cout << "YES"
#define no cout << "NO"

//inevilability is the unavailability of vernability - Credit - Harsh (cf handle : silvermirror)

//constants : 1'000'000'007 (can be used this type too)
const long long int mod = 1e9 + 7 ;
const double PI = 3.1415926535897932384626 ;
const long long int max = INT_MAX ;
const long long int INF = 1e18 ;

//using typedef
typedef string str ;
typedef vector<ll , ll> vi ;
typedef vector<str> vs ;
typedef pair<ll , ll> pii ;
typedef vector<pii> vpii ;
typedef map<ll , ll> mii ;
typedef map<str , ll> msi ;
typedef pair<ll , ll> pii ;
typedef set<ll> si ;
typedef set<str> ss ;

//No that's not me ! Credit - Harsh (cf handle : silvermirror)

//I don't know what the hell this is
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std::chrono ;
using namespace __gnu_pbds ;

//solution starts here :
void solve(){
	ll n ;
	ll D , H;
	cin >> n >> D >> H ;
	long double x , d[n] , h[n] , max = 0 ;
	fo(i , 0 , n){
		cin2(d[i] , h[i]) ;
		x = h[i] - (d[i]*(H-h[i]))/(D-d[i]) ;
		(x > max)?max = x : max ;
	}cout << fixed << setprecision(9) << max ;
}

//main function :
int main(){
	//fast IO and clock :
	ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;
	srand(chrono::high_resolution_clock::now().time_since_epoch().count()) ;

	//t is no. of testcase :
	int t = 1 , tc = 1;
	// cin >> t ;
	while(t--){
		solve() ;
		cout << nline ;
		// for Google competition and single ans use this :
		// cout << "Case #" << tc << ": " << ans << endl ;
	}
}


#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define sz(x) (int)(x).size()

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<char> vc;
typedef vector<bool> vb;

const int N = 17;
int n,e;
vector<pii> a;

void escribir (vector<pii> a) {
    for (auto e: a) {
        cout << e.F << " ";
    }
    cout << endl;
}

int main () {
    cin >> n;
    FOR(i,1,1<<n) {
        cin >> e;
        a.PB({e,i});
    }

    while (a.size()>2) {
        // cout << "a:";
        // escribir(a);
        vector<pii> b;
        // b.clear();
        for (int i=0;i<a.size();i+=2) {
            if (a[i].F>a[i+1].F) {
                b.PB(a[i]);
            }
            else {
                b.PB(a[i+1]);
            }

        }
        // cout << "b:";
        // escribir(b);
        a = b;
    }
    // cout << "a:";
    //     escribir(a);
    if (a[0].F<a[1].F) {
        cout << a[0].S;
    }
    else {
        cout << a[1].S;
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
#define ll long long
#define pi (3.141592653589)
#define mod 1000000007
#define float double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define min3(a, b, c) min(c, min(a, b))
#define min4(a, b, c, d) min(d, min(c, min(a, b)))
#define rfo(i, a, b) for (int i = (int)a; i >= (int)b; i--)
#define fo(i, a, b) for (int i = (int)a; i <= (int)b; i++)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define see(x) cout << (x) << endl
#define hh cout << endl
#define INF 1e18
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

template <typename C,
          typename T = std::decay_t<decltype(*begin(std::declval<C>()))>,
          typename std::enable_if<!std::is_same<C, std::string>::value>::type * = nullptr>
std::ostream &operator<<(std::ostream &os, const C &container)
{
    bool first = true;
    std::stringstream ss;
    ss << '[';
    for (const auto &x : container)
    {
        if (!first)
        {
            ss << ", ";
        }
        first = false;
        ss << x;
    }
    ss << ']';
    return os << ss.str();
}
template <class T1, class T2>
std::ostream &operator<<(std::ostream &os, const std::pair<T1, T2> &p)
{
    os << '{' << p.first << ", " << p.second << '}';
    return os;
}

ll mod_pow(ll a, ll b)
{
    if (b < 0)
        return 0;
    a %= mod;
    if (b == 0)
        return 1;
    if (b == 1)
        return a % mod;
    if (b == 2)
        return ((a % mod) * (a % mod)) % mod;
    return (mod_pow(mod_pow(a, b / 2), 2) * mod_pow(a, b % 2)) % mod;
}

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

// Keep calm and Keep coding //

void solve()
{
    int n, m;
    cin >> n;
    cin >> m;
    int t;
    cin >> t;

    cout << max(n + m, max(m + t, t + n));
    return;
}

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


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(v) begin(v),end(v)
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
#define TO_STRING(VariableName) # VariableName
#define debug(x) cerr<<TO_STRING(x)<<" : "<<x<<" "<<endl;
void debugs() { cerr << endl; }
template <class T, class... Args>
void debugs(const T& x, const Args &... args) {
		cerr << x << " ";
		debugs(args...);
}
template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>& p) {
		ost << "{ " << p.first << ", " << p.second << " }";
	return ost;
}
template<class T>
ostream& operator<<(ostream& ost, const vector<T>& v) {
	ost << "{ ";
	for (int i = 0; i < v.size(); i++) {
		if (i)ost << ", ";
		ost << v[i];
	}
	ost << " }";
	return ost;
}
template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>& v) {
	ost << "{ ";
	for (auto p : v) {
		ost << "{ " << p.first << ", " << p.second << " }";
	}
	ost << " }";
	return ost;
}
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

std::vector<ll> find_divisor(ll n) {
	std::vector<ll> divisor;

	ll i = 1;
	for (; i * i <= n; i++) if (n % i == 0) divisor.push_back(i);
	i--;
	if (i * i == n) i--;
	for (; i >= 1; i--) if (n % i == 0) divisor.push_back(n / i);

	return divisor;
}

int main() {
	ll n;
	cin >> n;
	vector<ll> a(n+1);
	cout << "1";
	a[1] = 1;
	for(ll i = 2; i <= n; i++){
		a[i] = 0;
		vector<ll> d = find_divisor(i);
		rep(j, d.size()-1){
			a[i] = max(a[i], a[d[j]]);
		}
		a[i]++;
		cout << " " << a[i];
	}
	cout << endl;
	return 0;
}

// Problem: F - Silver Woods
// Contest: AtCoder - AtCoder Beginner Contest 181
// URL: https://atcoder.jp/contests/abc181/tasks/abc181_f
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forn(i,x,n) for(int i = x;i <= n;++i)
typedef pair<int,int> pii;
#define x first
#define y second

const int N = 215;
const double eps = 1e-6;
int fa[N],n;
pii pts[N];
int find(int x)
{
	if(fa[x] == x)	return x;
	return fa[x] = find(fa[x]);
}
double dist(int a,int b)
{
	int dx = pts[a].x - pts[b].x,dy = pts[a].y - pts[b].y;
	return sqrt(dx * dx + dy * dy);
}
bool check(double r)
{
	forn(i,1,N - 1)	fa[i] = i;
	forn(i,1,n)
	{
		if(abs(pts[i].y - 100) < 2 * r)
		{
			int fax = find(N - 1),fay = find(i);
			fa[fax] = fay;
		}
		if(abs(pts[i].y + 100) < 2 * r)
		{
			int fax = find(N - 2),fay = find(i);
			fa[fax] = fay;
		}
		forn(j,1,n)
		{
			if(dist(i,j) < 2 * r)
			{
				int fax = find(i),fay = find(j);
				fa[fax] = fay;
			}
		}
	}
	return find(N - 1) != find(N - 2);
}
int main()
{
	scanf("%d",&n);
    forn(i,1,n)	scanf("%d%d",&pts[i].x,&pts[i].y);
    double l = 0,r = 205;
    while(r - l > eps)
    {
    	double mid = (l + r) / 2;
    	if(check(mid))	l = mid;
    	else			r = mid;
    }
    printf("%.18lf",l);
    return 0;
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int MOD = 1000000007;
int N, M;

ll expo(ll a, ll b)
{
    if (b == 0)
        return 1;
    if (b == 1)
        return a % MOD;
    if (b % 2 == 0)
        return expo(a*a % MOD, b/2);
    return a*expo(a*a % MOD, (b-1)/2) % MOD;
}

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

    cin >> N >> M;
    int sum = 0;
    for (int i = 0, a; i < N; i++)
    {
        cin >> a;
        sum += a;
    }

    ll num = 1, dem = 1;
    for (int i = 0; i < sum + N; i++)
    {
        num = num*(M + N - i) % MOD;
        dem = dem*(i + 1) % MOD;
    }

    cout << num*expo(dem, MOD - 2) % MOD << "\n";

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
  int n;
  cin >> n;
  vector<ll> a(n);
  for (ll &i : a)
    cin >> i;
  sort(a.begin(), a.end());
  ll ans = 0;
  for (int i = 0; i != n; i++)
    ans += i * a[i] - (n - (i + 1)) * a[i];
  cout << ans << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define pi pair<lli,lli>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define FOR(i,a,b) for(lli i=a;i<b;i++)
#define all(x) x.begin(), x.end()
const lli inf=10000000000000000;
lli mod = 1e9+7;
//const long double pi = 3.14159265358979323846264338;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
        // #ifndef ONLINE_JUDGE
        // freopen("input.txt", "r", stdin);
        // freopen("output.txt", "w", stdout);
        // #endif
        int t=1;
       // cin>>t;
while(t--) {
	lli n;
	cin>>n;
	vector <pi> a(n),b(n);

	FOR(i,0,n){
		cin>>a[i].fi>>a[i].se;
		b[i].fi = a[i].se;
		b[i].se = a[i].fi;
	}
	sort(all(a));sort(all(b));
	lli m = inf;
	if(a[0].se==b[0].fi){
		m = min(m,a[0].fi+a[0].se);
		m = min(m,max(a[0].fi,b[1].fi));
		m = min(m,max(a[1].fi,b[0].fi));
	}
	else{
		m = min(m,max(a[0].fi,b[0].fi));
	}
	cout<<m<<endl;

}
}

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

int main() {
  int n;
  cin >> n;
  vector<int> veca(n);
  vector<int> vecb(n);
  int cost = 1000000;
  int costt = 1000000;
  for (int i = 0; i < n; i++) {
    cin >> veca.at(i) >> vecb.at(i);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i != j) cost = min(cost, max(veca.at(i), vecb.at(j)));
      if (i == j) costt = min(costt, veca.at(i) + vecb.at(j));
      }
    }
  int ans = min(cost, costt);
  cout << ans;
}


#include <bits/stdc++.h>

using namespace std;

const int max_n = 100000;
const long long inf = 2e18;

#define ll long long
#define PLI pair<ll, int>

int n, m;
ll dis[max_n + 15];
struct E {
  int v;
  ll c, d;
  E () {}
  E (int v, ll c, ll d) : v(v), c(c), d(d) {}
};
vector<E> edges[max_n + 15];
priority_queue<PLI, vector<PLI>, greater<PLI> > que;
inline ll f(ll x, ll d) { return x + d / (x + 1); }
ll cal(ll start_t, ll d) {
  ll s = start_t, e = 1e9, ans;
  while (s <= e - 1000) {
    ll ml = (2 * s + e) / 3;
    ll mr = (s + 2 * e) / 3;
       ll fl = f(ml, d), fr = f(mr, d);
    if (fl < fr) e = mr;
    else s = ml;
    //cout << s << ' ' << e << endl;
  }
  ans = f(s, d);
  for (ll i = s + 1; i <= e; ++i) {
    ll res = f(i, d);
    if (res < ans) ans = res;
  }
  return ans - start_t;
}
ll Dij() {
  for (int i = 2; i <= n; ++i) dis[i] = inf;
  que.push(PLI(dis[1] = 0, 1));
  while (que.size()) {
    PLI pp = que.top(); que.pop();
    ll t = pp.first; int u = pp.second;
    if (dis[u] < t) continue;
    for (auto e : edges[u]) {
      int v = e.v; ll c = e.c, d = e.d;
      ll delta = c + cal(t, d);
      if (dis[u] + delta < dis[v]) {
        que.push(PLI(dis[v] = dis[u] + delta, v));
      }
    }
  }
  return inf == dis[n] ? -1 : dis[n];
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    int u, v, c, d;
    scanf("%d%d%d%d", &u, &v, &c, &d);
    edges[u].push_back(E(v, c, d));
    edges[v].push_back(E(u, c, d));
  }
  printf("%lld\n", Dij());
  return 0;
 }

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  ll x, y; cin >> x >> y;
  if (x >= y) {
    cout << x - y << '\n';
    return 0;
  }
  map<ll, int> dp{{y, 0}};
  using P = pair<int, ll>;
  priority_queue<P, vector<P>, greater<P>> que;
  que.emplace(0, y);
  ll ans = y - x;
  while (!que.empty()) {
    auto [cost, z] = que.top(); que.pop();
    if (cost > dp[z] || cost >= ans) continue;
    if (z % 2 == 0) {
      if (dp.count(z / 2) == 0 || dp[z / 2] > dp[z] + 1) {
        dp[z / 2] = dp[z] + 1;
        chmin(ans, dp[z / 2] + abs(z / 2 - x));
        if (z / 2 > x) que.emplace(dp[z / 2], z / 2);
      }
    } else {
      if (dp.count((z + 1) / 2) == 0 || dp[(z + 1) / 2] > dp[z] + 2) {
        dp[(z + 1) / 2] = dp[z] + 2;
        chmin(ans, dp[(z + 1) / 2] + abs((z + 1) / 2 - x));
        if ((z + 1) / 2 > x) que.emplace(dp[(z + 1) / 2], (z + 1) / 2);
      }
      if (dp.count((z - 1) / 2) == 0 || dp[(z - 1) / 2] > dp[z] + 2) {
        dp[(z - 1) / 2] = dp[z] + 2;
        chmin(ans, dp[(z - 1) / 2] + abs((z - 1) / 2 - x));
        if ((z - 1) / 2 > x) que.emplace(dp[(z - 1) / 2], (z - 1) / 2);
      }
    }
  }
  cout << ans << '\n';
  return 0;
}


/*
 * A.cpp
 *
 *  Created on: Feb 6, 2021
 *      Author: jrantor
 */

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

int main(){

double v,t,s,d;

cin >> v >> t >> s >> d;

double x = d/v;

if(x >= t && x <= s){
 cout << "No";
}

else cout << "Yes";

 return 0;
}

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

using ll  = long long;
using ull = unsigned ll;
using ld  = long double;
using pi  = pair<int, int>;
using pii = pair<ll, ll>;
using vi  = vector<int>;
using vii = vector<ll>;
using vip = vector<pair<int, int>>;

const int MAX_N = 1e5 + 1;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define PI           3.141592653589793238
#define fir          first
#define sec          second
#define all(x)       (x).begin(),(x).end()
#define rall(x)      (x).rbegin(),(x).rend()
#define pb           push_back
#define mp           make_pair
#define loop(i,n,x)  for(int i=n;i<x;i++)
#define sz(a)        ((int) (a).size())
#define For(n,x)     for(int i=1;i<=x;i++)
#define ite          iterator it
#define fast         ios_base::sync_with_stdio(false);cin.tie(NULL);
#define test         ll t;cin>>t; while(t--){solve();}

void oj()
{

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

}

bool isPowerOfTwo(ll n)
{
	if (n == 0)
		return false;

	return (ceil(log2(n)) == floor(log2(n)));
}

void solve()
{
	float v, t, s, d;
	cin >> v >> t >> s >> d;
	float result = d / v;
	if (result >= t && result <= s)
		cout << "No" << endl;
	else
		cout << "Yes" << endl;

}

int main()
{

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

	oj();

	//test;
	solve();

}


#include<cstdio>
#define ll long long
using namespace std;
int main(){
	ll a,b,c,d;
	scanf("%lld %lld\n%lld %lld",&a,&b,&c,&d);
	ll ans = 0;
	ans = b-c;
	printf("%lld\n",ans);
	return 0;
}

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a,b;
	cin>>a>>b;
	cout<<(2*a+100)-b<<endl;
}


#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  string S[3];
  REP(i,3)cin>>S[i];
  char SF[3];
  REP(i,3)SF[i]=S[i][0];
  REP(i,3)reverse(ALL(S[i]));
  set<char> s;
  REP(i,3)for(auto c:S[i])s.insert(c);
  if(s.size()>10){
    cout<<"UNSOLVABLE"<<endl;
    return 0;
  }
  map<char,int> c;
  int i=0;
  for(auto e:s){
    c[e]=i;
    i++;
  }
  vector<int> v(10);
  REP(i,10)v[i]=i;
  do {
    bool f=false;
    REP(i,3)if(v[c[SF[i]]]==0)f=true;
    if(f)continue;
    lint N[3]={0};
    REP(i,3){
      lint base=1;
      for(auto e:S[i]){
        N[i]+=v[c[e]]*base;
        base*=10;
      }
    }
    if(N[0]+N[1]==N[2]){
      REP(i,3)cout<<N[i]<<endl;
      // for(auto e:c){
      //   cerr<<e.first<<":"<<v[e.second]<<endl;
      // }
      // cerr<<endl;
      return 0;
    }
  } while( next_permutation(v.begin(), v.end()) );     // 次の順列を生成
  cout<<"UNSOLVABLE"<<endl;
  return 0;
}

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

int main()
{
  int a, b, c, ans = 0;
  cin >> a >> b >> c;
  if (a != b && b != c && c != a)
  {
    cout << 0 << endl;
  }
  else if (a == b)
  {
    cout << c << endl;
  }
  else if (b == c)
  {
    cout << a << endl;
  }
  else
  {
    cout << b << endl;
  }
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <functional>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <unordered_map>
#include <cstdio>
#include <climits>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long ll;

ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}
ll kai(ll x, ll y, ll m) {
	ll res = 1;
	for (ll i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
ll mod_pow(ll x, ll y, ll m) {
	ll res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

ll comb(ll x, ll y, ll m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

const ll INF = 1000000000000000000;

int n, m, a[200010], x[200010], y[200010];
vector<int> vec[200010];
ll d[200010];
ll ans = -INF;

signed main() {
	std::random_device rnd;
	std::mt19937_64 mt(rnd());
	cin >> n >> m;
	for (int i = 1; i <= n; i++)cin >> a[i];
	fill(d, d + n + 1, INF);
	for (int i = 0; i < m; i++) {
		cin >> x[i] >> y[i];
		vec[y[i]].push_back(x[i]);
	}
	d[1] = a[1];
	for (int i = 2; i <= n; i++) {
		ll mi = INF;
		for (int j = 0; j < (int)vec[i].size(); j++)mi = min(mi, d[vec[i][j]]);
		ans = max(ans, (ll)a[i] - mi);
		d[i] = min(mi, (ll)a[i]);
	}
	cout << ans << endl;
}

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

typedef long long int ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<ll, ll> Pair;
typedef vector<Pair> VP;
typedef vector<string> VS;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n); i >= 0; i--)
#define RREP(i, n, e) for(int i = (int)(n); i>= e; i--)
#define all(a) (a).begin(), (a).end()
#define VEC(n, x) VI n(x); rep(i, x) cin >> n[i];
#define MAT(m, x, y) VVI m(x, VI(y)); rep(i, x) rep(j, y) cin >> m[i][j];
#define FIX cout << fixed << setprecision(10);
#define out(x) cout << (x) << endl;
#define fin(x) { out(x); return 0; }
#define IN(x, l, r) ((l) <= (x) && (x) < (r))

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

void solve(VVI &G, VI &A, int v, int m, VI &res) {
  if (chmax(res[v], A[v] - m)) {
    for(auto nv: G[v]) solve(G, A, nv, min(m, A[v]), res);
  }
}

int main () {
  int N, M; cin >> N >> M;
  VEC(A, N);
  VI X(M), Y(M); rep(i, M) cin >> X[i] >> Y[i], X[i]--, Y[i]--;

  VVI G(N); rep(i, M) G[X[i]].push_back(Y[i]);
  vector<bool> start(N, true); rep(i, M) start[Y[i]] = false;

  VI res(N, INT_MIN);
  rep(i, N) if(start[i]) solve(G, A, i, INT_MAX, res);

  int ans = INT_MIN; rep(i, N) chmax(ans, res[i]);
  out(ans);

  return 0;
}


#include <bits/stdc++.h>

using namespace std ;

const int MAX = 1000 + 10 ;

char arr[MAX][MAX] ;
int n , m ;

int par[MAX] , sz[MAX] ;

void init()
{
	for(int i = 0 ; i < max(n , m) ; ++i)
		par[i] = i , sz[i] = 1 ;
}

int root(int node)
{
	if(par[node] == node)
		return node ;
	return (par[node] = root(par[node])) ;
}

void Union(int x , int y)
{
	int a = root(x) ;
	int b = root(y) ;
	if(sz[a] < sz[b])
		swap(a , b) ;
	par[b] = a ;
	sz[a] += sz[b] ;
}

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	cin>>n>>m ;
	for(int i = 0 ; i < n ; ++i)
	{
		for(int j = 0 ; j < m ; ++j)
			cin>>arr[i][j] ;
	}
	init() ;
	arr[0][0] = arr[0][m-1] = arr[n-1][0] = arr[n-1][m-1] = '#' ;
	for(int i = 0 ; i < n ; ++i)
	{
		int last = -1 ;
		for(int j = 0 ; j < m ; ++j)
		{
			if(arr[i][j] != '#')
				continue ;
			if(last != -1)
				Union(j , last) ;
			last = j ;
		}
	}
	set<int>s ;
	for(int j = 0 ; j < m ; ++j)
		s.insert(root(j)) ;
	int ans = s.size() - 1 ;
	init() ;
	s.clear() ;
	for(int j = 0 ; j < m ; ++j)
	{
		int last = -1 ;
		for(int i = 0 ; i < n ; ++i)
		{
			if(arr[i][j] != '#')
				continue ;
			if(last != -1)
				Union(i , last) ;
			last = i ;
		}
	}
	for(int i = 0 ; i < n ; ++i)
		s.insert(root(i)) ;
	ans = min(ans , (int)(s.size())-1) ;
	return cout<<ans<<"\n" , 0 ;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
int h, w, p[2005];
char c;
int find(int x){return (p[x] < 0 ? x : p[x] = find(p[x]));}
set<int> hh, ww;
void uni(int x, int y){
	x = find(x); y = find(y);
	if(x != y){
		if(p[x] > p[y]) swap(x, y);
		p[x] += p[y];
		p[y] = x;
	}
}
int main(){
	scanf("%d%d", &h, &w);
	fill(p, p+h+w, -1);
	uni(0,h); uni(0,h+w-1); uni(h-1,h);
	rep(i,h) rep(j,w+1){
		c = getchar();
		if(c == '#') uni(i,h+j-1);
	}
	rep(i,h) hh.insert(find(i));
	rep(i,w) ww.insert(find(i+h));
	printf("%d\n", min((int)hh.size(),(int)ww.size())-1);
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define INF 2147483647
#define INFLL 1000000000000
#define MOD 998244353
#define PI 3.14159265359
#define dij priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>
#define cout_all(v) for(auto e:v)cout<<e<<" ";cout<<endl
#define smart(v) v.erase(unique(all(v)),v.end())
typedef vector<vector<int>> graph;
typedef long long ll;
typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef pair<ll,ll> pll;
//

int main(){
  int v,t,s,d;cin>>v>>t>>s>>d;
  int a=v*t,b=v*s;
  a<=d&&d<=b? cout<<"No"<<endl:cout<<"Yes"<<endl;
}

#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for (int i = k; i < (int)(n); i++)
#define repd(i, n) for (int i = n-1; i >= 0; i--)
#define rrepd(i, k, n) for (int i = n-1; i >= (int)(k); i--)
#define all(x) (x).begin(),(x).end()
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
//V,Pは大文字i,l,bは小文字
using ll = long long;
using Vi = vector<int>;
using VVi = vector<Vi>;
using Vl = vector<ll>;
using VVl = vector<Vl>;
using Vb = vector<bool>;
using VVb = vector<Vb>;
using P = pair<int,int>;
using Pl = pair<ll, ll>;
using Vs = vector<string>;
const ll mod = 1000000007;
const ll inf = 1000000000000;//10の12乗

int main() {
    int t;
    cin >> t;
    string at="atcoder";
    rep(i,t){
        string s;
        cin >> s;
        if(s>at){
            cout << 0 << endl;
            continue;
        }
        int len=min(2,(int)s.length());
        int len2=s.length();
        ll ans=inf;
        rep(j,len){
            rep(k,len2-j){
                if(at[j]<s[j+k]){
                    chmin(ans,(ll)k);
                }
            }
            if(at[j]>s[j]) break;
        }
       if(ans==inf) cout << -1 << endl;
       else cout << ans << endl;
    }
}


///////////////////////Loading Payloads.......////////////////////////////
#include<bits/stdc++.h>
#define f(i,a,b) for(int i = a; i < b; i++)
#define fd(i,a,b) for(int i = a; i > b;i--)
#define fld(i,a,b) for(ll i = a ; i > b;i--)
#define ll long long
#define fl(i,a,b) for(ll i = a; i < b; i++)
#define VI vector<int>
#define VP vector<pair<int,int>>
#define VPL vector<pair<ll,ll>>
#define VS vector<string>
#define VL vector<long long>
#define VC vector<char>
#define VF vector<float>
#define VD vector<double>
#define VB vector<bool>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define fa(i,skill) for(auto i : skill)
#define fr(i,skill) for(VI :: reverse_iterator i = skill.rbegin(); i != skill.rend(); i++)
#define PI pair<int,int>
#define mi map<int,int>
#define ml map<ll,ll>
#define mci map<char,int>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define MAX 1000000007
#define INF 1000000000
#define debug(x) cout<<"This side    ----> "<<#x<<" -> "<<x<<endl
using namespace std;

///////////////////////Engine Check.......////////////////////////////
void edit(VI &skill,int n)
{
    f(i,0,n)
        {
            int x;
            cin >> x;
            skill.PB(x);
        }
}

bool cmp(pair<ll,ll>p1,pair<ll,ll>p2)
{
    if(p1.S > p2.S)
        return true;
    if(p1.S < p2.S)
        return false;
    if(p1.F > p2.F)
        return true;
    else
        return false;
}
void editl(VL &skill,ll n)
{
    fl(i,0,n)
        {
            ll x;
            cin >> x;
            skill.PB(x);
        }
}
void editpl(VPL &skill,ll n)
{
    fl(i,0,n)
        {
            ll x,y;
            cin >> x >> y;
            skill.PB({x,y});
        }
}
ll nextPowerOf2(ll n)
{
    n--;
    n |= n >> 1;
    n |= n >> 2;
    n |= n >> 4;
    n |= n >> 8;
    n |= n >> 16;
    n++;
    return n;
}

bool isGoogles = 0;
bool testcase = 0;

void achilles()
{

    ll n;cin >> n;
    VPL arr,arr2;

    fl(i,0,n)
    {
        ll x,y;cin >>x >> y;
        arr.PB({x,y});
        arr2.PB({y,x});
    }

    sort(all(arr));
    sort(all(arr2));

    ll mxx1 = abs(arr[n-2].F - arr[0].F);
    ll mxx2 = abs(arr[n-1].F - arr[1].F);

    ll mxy1 = abs(arr2[n-2].F - arr2[0].F);
    ll mxy2 = abs(arr2[n-1].F - arr2[1].F);

    ll maxx = abs(arr[n-1].F - arr[0].F);
    ll maxy = abs(arr2[n-1].F - arr2[0].F);

    // if(maxx > maxy)

    // debug(arr2[n-1].F);debug(arr2[0].F);
    // debug(maxx);
    // debug(maxy);
    // debug(mxx1);
    // debug(mxx2);
    // debug(mxy1);
    // debug(mxy2);
    // cout << max(max(mxx1,mxx2),max(mxy1,mxy2)) << "\n";

    if(arr[n-1] == arr2[n-1])
    {
        // cout << arr[n].F << ' ' << arr[n].S << "\n";
        // cout << arr2[n].F << ' ' << arr2[n].S << "\n";
        cout << max(max(mxx1,mxx2),max(mxy1,mxy2)) << "\n";
    }
    else
    {
        VL ex;
        ex.PB(maxx);
        ex.PB(maxy);
        ex.PB(mxx1);
        ex.PB(mxx2);
        ex.PB(mxy1);
        ex.PB(mxy2);

        sort(rall(ex));

        cout << ex[1] << "\n";
    }

}

///////////////////////3....2....1...Ignition////////////////////////////

int main()
{

    ios :: sync_with_stdio(0);
    cin.tie(0);

    ll t=1,w=1;
    if(testcase)
    cin >>t;

    while(t--)
    {   if (isGoogles) {cout << "Case #" << w << ": ";}
        achilles();
        w++;
    }
    return 0;
}

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vll> vvll;
typedef pair<int, int> P;
typedef map<int, int> mii;
typedef set<int> si;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define fi first
#define se second
// #include <atcoder/all>
// using namespace atcoder;
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T, class U>
inline bool chmax(T& a, U b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T, class U>
inline bool chmin(T& a, U b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T, class U>
ostream& operator<<(ostream& os, pair<T, U>& p) {
    cout << "(" << p.first << ", " << p.second << ")";
    return os;
}
template <class T>
inline void dump(T& v) {
    if (v.size() > 100) {
        cout << "ARRAY IS TOO LARGE!!!" << endl;
    } else {
        irep(i, v) { cout << (*i) << ((i == --v.end()) ? '\n' : ' '); }
    }
}
template <class T, class U>
inline void dump(map<T, U>& v) {
    if (v.size() > 100) {
        cout << "ARRAY IS TOO LARGE!!!" << endl;
    } else {
        irep(i, v) { cout << i->first << " " << i->second << '\n'; }
    }
}
template <class T, class U>
inline void dump(pair<T, U>& p) {
    cout << p.first << " " << p.second << '\n';
}
inline void yn(const bool b) { b ? fin("yes") : fin("no"); }
inline void Yn(const bool b) { b ? fin("Yes") : fin("No"); }
inline void YN(const bool b) { b ? fin("YES") : fin("NO"); }
const int INF = INT_MAX;
constexpr ll LLINF = 1LL << 61;
constexpr ll MOD = 1000000007;  // 998244353; //
constexpr ld EPS = 1e-11;
void Case(int i) { printf("Case #%d: ", i); }
/* --------------------   ここまでテンプレ   -------------------- */

int main() {
    int n;
    cin >> n;
    // vi v(n);
    // rep(i, n) cin >> v[i];
    cout<<n-1<<endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
const ll mod = 1000000007;

int main() {
    int H, W; cin >> H >> W;
    int minA = INF;
    vvi As(H, vi(W));
    rep(i, H)rep(j, W){
        cin >> As[i][j];
        minA = min(minA, As[i][j]);
    }
    int ans = 0;
    rep(i, H)rep(j, W){
        ans += As[i][j] - minA;
    }
    cout << ans << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define int long long
template<typename T> void read(T &x) {
	x=0;int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar())if(c=='-') f=-1;
	for(;isdigit(c);c=getchar())x=x*10+c-'0';
	x=x*f;
}
const int mod=1e9+7;
int n,p;
/*
(p-1)(p-2)^(n-1)

*/
int qpow(int a,int b){
	int res=1;
	while(b){
		if(b&1) res=res*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return res%mod;
}
signed main(){
	cin>>n>>p;
	cout<<qpow(p-2,n-1)%mod*(p-1)%mod<<endl;

	return 0;
}


#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstring>
#include<vector>
#include<queue>
#define ll long long
const int N=2e5+10;
const ll mod=1e9+7;
ll read(){
    ll s = 0, f = 1; char ch = getchar();
    while(!isdigit(ch)){
        if(ch == '-') f = -1;
        ch = getchar();
    }
    while(isdigit(ch)) s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
    return s * f;
}
using namespace std;
struct edge{
	int u,v;
	ll time,K;
	edge(int u,int v,ll time, ll K){
		this->u=u;
		this->v=v;
		this->time=time;
		this->K=K;
	}
};
struct node{
	int u;
	ll time;
	bool operator <(const node &a) const{
		return time>a.time;
	}
	node(int u,ll time){
		this->u=u;
		this->time=time;
	}
};
vector<edge> e[N];
bool vis[N];
ll arr[N];
ll dj(int n,int x,int y){
	//³õÊ¼»¯
	for(int i=1;i<=n;i++){
		arr[i]=-1;
		vis[i]=false;
	}
	arr[x]=0;
	priority_queue<node> q;
	node t(x,0);
	q.push(t);
	while(!q.empty()){
		t=q.top();
		q.pop();
		int u=t.u;
		if(vis[u]) continue;
		vis[u]=true;
		for(int i=0;i<e[u].size();i++){
			int v=e[u][i].v;
			if(vis[v]) continue;
			ll ans=(arr[u]+e[u][i].K-1)/e[u][i].K*e[u][i].K+e[u][i].time;
			if(ans<arr[v]||arr[v]==-1){
				arr[v]=ans;
				q.push(node(v,ans));
			}
		}
	}
	return arr[y];
}
int main (){
    int n,m,x,y;
    n=read();
    m=read(); x=read(); y=read();
    int u,v,time,k;
    for(int i=1;i<=m;i++){
    	u=read();v=read();
    	time=read();
    	k=read();
    	e[u].push_back(edge(u,v,time,k));
    	e[v].push_back(edge(v,u,time,k));
	}
	cout<<dj(n,x,y)<<endl;
	return 0;
}

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <set>
#include <queue>
#include <stack>
using namespace std;
typedef long long int ll;
typedef pair<int,int> Pai;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

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

const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

struct to {
  int b;
  ll t;
  ll k;
};

struct queIn {
  int now;
  ll time;
};

int main() {
  int n, m, x, y;
  cin >> n >> m >> x >> y;
  x--; y--;
  vector< vector<struct to> > v(n);
  rep (i, m) {
    int a, b, t, k;
    cin >> a >> b >> t >> k;
    a--; b--;
    struct to tmp;
    tmp.b = b;
    tmp.t = t;
    tmp.k = k;
    v[a].push_back(tmp);
    tmp.b = a;
    v[b].push_back(tmp);
  }

  // rep (i, n) {
  //   rep (j, v[i].size()) {
  //     cout << i << " => " << "b: " << v[i][j].b << ", t: " << v[i][j].t << ", k: " << v[i][j].k << endl;
  //   }
  // }

  ll fast[n];
  rep (i, n) fast[i] = LINF;
  fast[x] = 0;
  struct queIn que;
  que.now = x;
  que.time = 0;
  // queue<struct queIn> q;
  auto compare = [](struct queIn a, struct queIn b) {
    return a.time > b.time;
  };

  priority_queue<
    struct queIn,
    vector<struct queIn>,
    decltype(compare) // 比較関数オブジェクトを指定
  > q {compare};
  q.push(que);
  while (!q.empty()) {
    que = q.top(); q.pop();
    // cout << "now: " << que.now << endl;
    rep (i, v[que.now].size()) {
      ll bai = que.time / v[que.now][i].k;
      if (que.time % v[que.now][i].k != 0) {
        bai++;
      }

      // cout << que.now << " => " << "b: " << v[que.now][i].b << ", t: " << v[que.now][i].t << ", k: " << v[que.now][i].k << endl;

      if (fast[v[que.now][i].b] > bai * v[que.now][i].k + v[que.now][i].t) {
        fast[v[que.now][i].b] = bai * v[que.now][i].k + v[que.now][i].t;
        struct queIn qTmp;
        qTmp.now = v[que.now][i].b;
        qTmp.time = bai * v[que.now][i].k + v[que.now][i].t;
        q.push(qTmp);
      }
    }
  }

  // rep (i, n) {
  //   cout << i << ": " << fast[i] << endl;
  // }

  if (fast[y] == LINF) {
    P(-1);
  } else {
    P(fast[y]);
  }

  return 0;
}