#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pa pair<int,int>
const int Maxn=200010;
const int inf=2147483647;
const double pi=acos(-1.0);
LL read()
{
	LL x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=x*10ll+ch-'0',ch=getchar();
	return x*f;
}
int n,k,f[Maxn],g[Maxn],w;
vector<int>G[Maxn];
void dfs(int x,int fa)
{
	f[x]=0;
	int mx=0,mn=0;bool flag=false;
	for(int i=0;i<G[x].size();i++)
	{
		int y=G[x][i];
		if(y==fa)continue;flag=true;
		dfs(y,x);f[x]+=f[y];
		int t=g[y];
		if(t>0)mx=max(mx,t);
		else mn=min(mn,t);
	}
	if(!flag){g[x]=-1;return;}
	if(mx-1+mn>=0&&mx)g[x]=mx-1;
	else
	{
		if(mn==-w)
		{
//			printf("# %d\n",x);
			f[x]++;
			g[x]=w;
		}
		else g[x]=mn-1;
	}
//	printf("%d %d %d\n",x,f[x],g[x]);
}
bool check()
{
	dfs(1,0);
	return(f[1]+(g[1]<0)<=k);
}
int main()
{
	n=read(),k=read();
	for(int i=1;i<n;i++)
	{
		int x=read(),y=read();
		G[x].push_back(y),G[y].push_back(x);
	}
//	w=1;check();return 0;
	int l=1,r=n-1;
	while(l<=r)
	{
		int mid=l+r>>1;w=mid;
		if(check())r=mid-1;
		else l=mid+1;
	}
	printf("%d",r+1);
}

#include<bits/stdc++.h>
#define ln puts("")
using namespace std;
typedef long long ll;

inline ll read() {
	ll sum = 0, ff = 1;
	char ch = getchar();
	while(ch < '0' || ch > '9') {
		if(ch == '-')
			ff = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9')
		sum = sum * 10 + ch - '0', ch = getchar();
	return sum * ff;
}

const int N = 2007;
int n, m;
ll ans;
struct edge {
	int to, nxt;
}e[N];
int cnt, he[N];
bool vis[N];

void add(int u, int v) {
	e[++cnt].to = v;
	e[cnt].nxt = he[u];
	he[u] = cnt;
}

void dfs(int u) {
	ans++;
	vis[u] = true;
	for(int i = he[u]; i; i = e[i].nxt) {
		int v = e[i].to;
		if(vis[v])
			continue;
		dfs(v);
	}
}

int main() {
//	freopen("", "r", stdin);
//	freopen("", "w", stdout);
	n = read(), m = read();
	for(int i = 1; i <= m; i++) {
		int u = read(), v = read();
		add(u, v);
	}
	for(int i = 1; i <= n; i++) {
		memset(vis, false, sizeof(vis));
		dfs(i);
	}
	cout << ans;
	return 0;
}


#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a;
    cin>>a;
    cout<<a-1<<endl;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	char a;
	cin>>a;
	char b;
	cin>>b;
	if(a=='Y') printf("%c",b-32);
	else printf("%c",b);
	return 0;
}


//DUEL
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define x first
#define y second
#define pii pair<int,int>
#define pb push_back
#define eb emplace_back
#pragma GCC optimize("unroll-loops")
#define shandom_ruffle(a, b) shuffle(a, b, rng)
#define vi vector<int>
#define vl vector<ll>
#define popcnt __builtin_popcount
#define popcntll __builtin_popcountll
#define all(a) begin(a),end(a)

using namespace std;
using namespace __gnu_pbds;

using ll=long long;
using ull=unsigned long long;
using ld=long double;
int MOD=1000000007;
int MOD2=998244353;
vector<int> bases;
const ll LLINF=1ll<<60;
const char en='\n';

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void yes() {cout<<"YES"<<en; exit(0);}
void no() {cout<<"NO"<<en; exit(0);}
inline int rund() {int x576363482791fuweh=rng();return abs(x576363482791fuweh)%RAND_MAX;}
template<class T>
void prVec(vector<T> w,bool fl=false)
{
	cout<<w.size()<<en;
	for (int i=0;i<int(w.size())-1;++i) cout<<w[i]<<' ';
	if (w.size()) cout<<w[w.size()-1]<<en;
	if (fl) cout<<flush;
}

void M998()
{
	swap(MOD,MOD2);
}

ll raand()
{
	ll a=rund();
	a*=RAND_MAX;
	a+=rund();
    return a;
}

#define rand raand

ll raaand()
{
	return raand()*(MOD-7)+raand();
}

template<class T>
vi compress(vector<T>&v)
{
	set<T> s;
	for (auto a: v) s.insert(a);
	vector<T> o(all(s));
	vi nv;
	for (int i=0;i<(int)v.size();++i) nv.pb(lower_bound(all(o),v[i])-o.begin());
	return nv;
}

string to_upper(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
	return a;
}

string to_lower(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
	return a;
}

ll sti(string a,int base=10)
{
	ll k=0;
	for (int i=0;i<(int)a.size();++i)
	{
		k*=base;
		k+=a[i]-'0';
	}
	return k;
}

template<class T>
void eras(vector<T>& a,T b)
{
	a.erase(find(a.begin(),a.end(),b));
}

string its(ll k,int base=10)
{
	if (k==0) return "0";
	string a;
	while (k)
	{
		a.push_back((k%base)+'0');
		k/=base;
	}
	reverse(a.begin(),a.end());
	return a;
}

ll min(ll a,int b)
{
	if (a<b) return a;
	return b;
}

ll min(int a,ll b)
{
	if (a<b) return a;
	return b;
}

ll max(ll a,int b)
{
	if (a>b) return a;
	return b;
}

ll max(int a,ll b)
{
	if (a>b) return a;
	return b;
}

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

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

template<class T,class K>
pair<T,K> mp(T a,K b)
{
	return make_pair(a,b);
}

inline int mult(ll a,ll b)
{
	return (a*b)%MOD;
}

inline int pot(int n,int k)
{
	if (k==0) return 1;
	ll a=pot(n,k/2);
	a=mult(a,a);
	if (k%2) return mult(a,n);
	else return a;
}

int divide(int a,int b)
{
	return mult(a,pot(b,MOD-2));
}

inline int sub(int a,int b)
{
	if (a-b>=0) return a-b;
	return a-b+MOD;
}

inline int add(int a,int b)
{
	if (a+b>=MOD) return a+b-MOD;
	return a+b;
}

bool prime(ll a)
{
	if (a==1) return 0;
	for (int i=2;i<=round(sqrt(a));++i)
	{
		if (a%i==0) return 0;
	}
	return 1;
}

int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
const int N=300010;
int t;
ll n;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	for (int i=0;i<10;++i) bases.push_back(rand()%(MOD-13893829*2)+13893829);
	cin>>t;
	while (t--)
	{
		cin>>n;
		if (n%2) cout<<"Odd\n";
		else if (n%4) cout<<"Same\n";
		else cout<<"Even\n";
	}
}

#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()
ll read()
{
	ll 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=;
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()

ll n;

void solve(){
	n=read();
	if (n%4==0) puts("Even");
	else if (n%2==0) puts("Same");
	else puts("Odd");
}

int main()
{
	for (int T=read();T--;) solve();
	return 0;
}


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

int main(void)
{
    long long x,y;
    cin >> x >> y;
    long long a[3]={0};

    if(x==y) cout<<x<<endl;
    else
    {
        a[x]++;
        a[y]++;

        for(long long i=0;i<3;i++)
        {
            if(a[i]==0) cout<<i<<endl;
        }
    }

    return 0;
}

#include <iostream>
using namespace std;

int main(){
  int x,y;
  cin >> x >> y;
  if(x==y)
    cout << x;
  else
    cout << 3-(x+y);
  return 0;
}


//#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <functional>
#include <cstring>
#include <string>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <complex>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define itn int
#define nit int
#define ll long long
#define ms multiset
#define F(i,a,b) for(register int i=a,i##end=b;i<=i##end;++i)
#define UF(i,a,b) for(register int i=a,i##end=b;i>=i##end;--i)
#define re register
#define ri re int
#define il inline
#define pii pair<int,int>
#define cp complex<double>
//#pra gma G CC opti mize(3)
using namespace std;
using std::bitset;
//using namespace __gnu_pbds;
const double Pi=acos(-1);
namespace fastIO {
	template<class T>
	inline void read(T &x) {
		x=0;
		bool fu=0;
		char ch=0;
		while(ch>'9'||ch<'0') {
			ch=getchar();
			if(ch=='-')fu=1;
		}
		while(ch<='9'&&ch>='0') x=(x*10-48+ch),ch=getchar();
		if(fu)x=-x;
	}
	inline int read() {
		int x=0;
		bool fu=0;
		char ch=0;
		while(ch>'9'||ch<'0') {
			ch=getchar();
			if(ch=='-')fu=1;
		}
		while(ch<='9'&&ch>='0') x=(x*10-48+ch),ch=getchar();
		return fu?-x:x;
	}
	char _n_u_m_[40];
	template<class T>
	inline void write(T x ) {
		if(x==0){
			putchar('0');
			return;
		}
		T tmp = x > 0 ? x : -x ;
		if( x < 0 ) putchar('-') ;
		register int cnt = 0 ;
		while( tmp > 0 ) {
			_n_u_m_[ cnt ++ ] = tmp % 10 + '0' ;
			tmp /= 10 ;
		}
		while( cnt > 0 ) putchar(_n_u_m_[ -- cnt ]) ;
	}
	template<class T>
	inline void write(T x ,char ch) {
		write(x);
		putchar(ch);
	}
}
using namespace fastIO;
int n;
double x[1002],y[1002],mmin=-1.0000001,mmax=1.0000001;
int main() {int ans=0;
	cin>>n;
	F(i,1,n)cin>>x[i]>>y[i];
	F(i,1,n){
		F(j,i+1,n){
			if((y[i]-y[j])/(x[i]-x[j])>mmin&&(y[i]-y[j])/(x[i]-x[j])<mmax)ans++;
		}
	}cout<<ans;
	return 0;
}

#include<cstdio>//JZM YYDS!!!
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<ctime>
#define ll long long
#define MAXN 100005
#define uns unsigned
#define MOD 1000000007ll
#define INF 1e18
using namespace std;
inline ll read(){
	ll x=0;bool f=1;char s=getchar();
	while((s<'0'||s>'9')&&s>0){if(s=='-')f^=1;s=getchar();}
	while(s>='0'&&s<='9')x=(x<<1)+(x<<3)+s-'0',s=getchar();
	return f?x:-x;
}
inline ll ksm(ll a,ll b,ll mo){
	ll res=1;
	for(;b;b>>=1,a=a*a%mo)if(b&1)res=res*a%mo;
	return res;
}
int n;
double a[MAXN];
inline double check(double x){
	double res=0;
	for(int i=1;i<=n;i++)
		res=(res+(x+a[i]-min(a[i],x*2))/n);
	return res;
}
signed main()
{
	n=read();
	double mx=0;
	for(int i=1;i<=n;i++)a[i]=read(),mx=max(mx,a[i]);
	double ans=INF;
	long double l=0,r=mx,m1,m2;
	while(r-l>1e-10){
//		printf("%.5f %.5f\n",l,r);
		m1=(l+l+r)/3,m2=(l+r+r)/3;
		double c1=check(m1),c2=check(m2);
		ans=min(ans,min(c1,c2));
		if(c1<c2)r=m2;
		else l=m1;
	}
	printf("%.10f\n",ans);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
// #define int long long
#define Rep(x, a, b) for(int x = a; x <= b; ++ x)
#define Dep(x, a, b) for(int x = a; x >= b; -- x)
int read() {
    char c = getchar(); int f = 1, x = 0;
    while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); }
    while(c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); }
    return x * f;
}
int main() {
	int a = read(), b = read(), c = read(), d = read();
	printf("%d\n", a * d - b * c);
	return 0; int zmy = 123456;
}

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acosl(-1.0);

ll mod_pow(ll x, ll n, ll m = mod) {
	if (n < 0) {
		ll res = mod_pow(x, -n, m);
		return mod_pow(res, m - 2, m);
	}
	if (abs(x) >= m)x %= m;
	if (x < 0)x += m;
	ll res = 1;
	while (n) {
		if (n & 1)res = res * x % m;
		x = x * x % m; n >>= 1;
	}
	return res;
}
struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n % mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
	if (n == 0)return modint(1);
	modint res = (a * a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
modint operator/=(modint& a, modint b) { a = a / b; return a; }
const int max_n = 1 << 2;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
modint combP(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[a - b];
}

void solve() {
	int n, p; cin >> n >> p;
	if (p == 2) {
		if (n == 1)cout << 1 << "\n";
		else cout << 0 << "\n"; return;
	}
	modint ans = p - 1;
		ans *= mod_pow(p - 2, n - 1);
	cout << ans << "\n";
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init_f();
	//init();
	//expr();
	//int t; cin >> t;rep(i,t)
	solve();
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
// #define LOCAL // 提出時はコメントアウト
#define DEBUG_

typedef long long ll;
const double EPS = 1e-9;
const ll INF = ((1LL<<62)-(1LL<<31));
typedef vector<ll> vecl;
typedef pair<ll, ll> pairl;
template<typename T> using uset = unordered_set<T>;
template<typename T, typename U> using mapv = map<T,vector<U>>;
template<typename T, typename U> using umap = unordered_map<T,U>;

#define ALL(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define sz(x) (ll)x.size()
ll llceil(ll a,ll b) { return (a+b-1)/b; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> vector<vector<T>> genarr(ll n, ll m, T init) { return vector<vector<T>>(n,vector<T>(m,init)); }

///// DEBUG
#define DUMPOUT cerr
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
template<typename T>istream&operator>>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<typename T,typename U>ostream&operator<<(ostream&os,pair<T,U>&pair_var){os<<"("<<pair_var.first<<", "<<pair_var.second<<")";return os;}
template<typename T>ostream&operator<<(ostream&os,const vector<T>&vec){os<<"{";for(int i=0;i<vec.size();i++){os<<vec[i]<<(i+1==vec.size()?"":", ");}
os<<"}";return os;}
template<typename T,typename U>ostream&operator<<(ostream&os,map<T,U>&map_var){os<<"{";repi(itr,map_var){os<<*itr;itr++;if(itr!=map_var.end())os<<", ";itr--;}
os<<"}";return os;}
template<typename T>ostream&operator<<(ostream&os,set<T>&set_var){os<<"{";repi(itr,set_var){os<<*itr;itr++;if(itr!=set_var.end())os<<", ";itr--;}
os<<"}";return os;}
void dump_func(){DUMPOUT<<endl;}
template<class Head,class...Tail>void dump_func(Head&&head,Tail&&...tail){DUMPOUT<<head;if(sizeof...(Tail)>0){DUMPOUT<<", ";}
dump_func(std::move(tail)...);}
#ifndef LOCAL
#undef DEBUG_
#endif
#ifdef DEBUG_
#define DEB
#define dump(...)                                                          \
DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
        << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
        << endl                                                            \
        << "    ",                                                         \
    dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif

//////////

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

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

    ll N;
    cin>>N;

    vecl A(N);
    rep(i,N) cin>>A[i];

    ll ans = 0;
    rep(i,N) {
        ll x = A[i];
        ll l = i, r = i;

        bool ul = false, ur = false;
        rep(j,i) {
            ll k = i - j - 1;
            if (A[k] < x) {
                l = k + 1;
                ul = true;
                break;
            }
        }

        REP(j,i+1,N) {
            if (A[j] < x) {
                r = j - 1;
                ur = true;
                break;
            }
        }

        if (!ul) l = 0;
        if (!ur) r = N-1;

        dump(x,l,r, (r-l+1) * x);

        chmax(ans, (r-l+1) * x);
    }

    cout << ans << endl;

    return 0;
}

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

int main(void){
    int n, ans = 0;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int l = 0; l < n; l++){
        int x = a[l];
        for(int r = l; r < n; r++){
            x = min(x, a[r]);
            ans = max(ans, x*(r-l+1));
        }
    }
    cout << ans << endl;
    return 0;
}


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

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

const ll MOD = 1e9 + 7;

int main(){

    readFile();

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

	string s;
	cin >> s;
	deque<char> d;
	int n = (int)s.length();
	bool rev = false;
	for(int i = 0 ; i < n ; ++i){
		if(s[i] == 'R'){
			rev = !rev;
		}
		else{
			if(rev){
				d.push_front(s[i]);
			}
			else{
				d.push_back(s[i]);
			}
		}
	}
	vector<char> a;
	for(auto i : d){
		a.push_back(i);
	}
	vector<char> bb;
	for(int i = 0 ; i < (int)a.size() ; ++i){
		bool ok = false;
		while(!bb.empty() && bb.back() == a[i]){
			bb.pop_back();
			ok = true;
		}
		if(!ok) bb.push_back(a[i]);
	}
	if(rev){
		reverse(bb.begin(), bb.end());
	}
	for(auto i : bb) cout << i;
	cout << '\n';
	return 0;
}

#include <bits/stdc++.h>

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define log_2(a) (log((a)) / log(2))
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

template<typename T>
void printArray(vector<T> &printVec) {
    if(printVec.empty()) return;
    cout << printVec[0];
    for(int i = 1; i < printVec.size(); ++i) cout << " " << printVec[i];
    cout << endl;
}

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    string s;
    cin >> s;
    bool f = false;
    deque<char> d;
    for(char c : s) {
        if(c == 'R') {
            f = !f;
        } else {
            if(f) d.push_front(c);
            else d.pb(c);
        }
    }

    stack<char> st;
    if(f) {
        while(!d.empty()) {
            char c = d.back();
            d.pop_back();
            if(!st.empty() && st.top() == c) {
                st.pop();
            } else {
                st.push(c);
            }
        }
    } else {
        while(!d.empty()) {
            char c = d.front();
            d.pop_front();
            if(!st.empty() && st.top() == c) {
                st.pop();
            } else {
                st.push(c);
            }
        }
    }

    string t = "";
    while(!st.empty()) {
        t += st.top();
        st.pop();
    }
    reverse(all(t));
    cout << t << endl;
    return 0;
}


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

std::vector<std::vector<int>> children, list;
std::vector<int> in, out, depth;
int timer;

void dfs(const int u) {
    in[u] = timer++;
    list[depth[u]].push_back(in[u]);
    for (const int v : children[u]) {
        depth[v] = depth[u] + 1;
        dfs(v);
    }
    out[u] = timer++;
}

int main() {
    int N;
    std::cin >> N;
    children = list = std::vector<std::vector<int>>(N);
    in = out = depth = std::vector<int>(N);
    for (int i = 1; i < N; ++i) {
        int p;
        std::cin >> p;
        children[p - 1].push_back(i);
    }
    dfs(0);
    int Q;
    std::cin >> Q;
    while (Q--) {
        int u, d;
        std::cin >> u >> d;
        u -= 1;
        const auto& v = list[d];
        std::cout << std::lower_bound(v.cbegin(), v.cend(), out[u]) - std::lower_bound(v.cbegin(), v.cend(), in[u]) << '\n';
    }
    return 0;
}

//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization("unroll-loops")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
template<class T> using indexed_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
const int N=2e5+7;
const int mod=1e9+7;
const int INF=1e18+7;
const double EPS=1e-12;
const int dx[]={-1,1,0,0}; // UDLR
const int dy[]={0,0,-1,1}; // UDLR
inline int maximum(int a,int b) {int c=a>b?a:b; return c;}
inline int minimum(int a,int b) {int c=a>b?b:a; return c;}

int n; vector<vector<int>> adj(N); vector<int> dis(N),sub(N),ans(N); map<int, int> *cnt[N];
vector<vector<pair<int,int>>> query(N);
void dfs(int src){
  sub[src]=1;
  for(auto v:adj[src]){
   dis[v]+=dis[src]+1;
   dfs(v);
   sub[src]+=sub[v];
  }
}
void dfsz(int src){
  int mx=-1,big=-1;
  for(auto v:adj[src]){
   dfsz(v);
   if(sub[v]>mx) mx=sub[v],big=v;
  }
  if(big!=-1) cnt[src]=cnt[big];
  else cnt[src]=new map<int,int>();
  (*cnt[src])[dis[src]] ++;
  for(auto v:adj[src]){
    if(v==big) continue;
    for(auto x:*cnt[v]) (*cnt[src])[x.first]+=x.second;
  }
  for(auto p:query[src]){
   ans[p.first]=(*cnt[src])[p.second];
  }
}
int32_t main(){
    cin.tie(nullptr)->sync_with_stdio(false);

    cin>>n;
    for(int i=2;i<=n;i++){
     int x; cin>>x; adj[x].push_back(i);
    }
    dfs(1);
    int q; cin>>q;
    for(int i=0;i<q;i++){
     int u,d; cin>>u>>d;
     query[u].push_back({i,d});
    }
    dfsz(1);
    for(int i=0;i<q;i++) cout<<ans[i]<<'\n';

 return 0;
}


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

#ifndef godfather
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#endif

#define int long long
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef gp_hash_table<int, int> umap;
typedef tree<int, null_type, less<int>, rb_tree_tag,
        tree_order_statistics_node_update> oset;
typedef pair<pii, int> piii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<pii> vii;

#define INF 1000000000000000000
#define inf 1000000000
// #define MOD 67280421310721
#define MOD  1000000007
// #define MOD 998244353
#define PI 3.1415926535897932385

#define pb push_back
#define bitc __builtin_popcountll
#define mp make_pair
#define all(ar) ar.begin(), ar.end()

#define fr(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define rep(i, n) for (int i = 0, _n = (n); i < _n; i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)
#define frr(i, a, b) for (int i = (a), _b = (b); i >= _b; i--)
#define foreach(it, ar) for (auto it = ar.begin(); it != ar.end(); it++)
#define fil(ar, val) memset(ar, val, sizeof(ar))  // 0x3f for inf, 0x80 for -INF can also use with pairs

#ifdef godfather
template<typename T>
void __p(T a) { cout << a << " "; }
template<typename T>
void __p(std::vector<T> a) { cout << "{ "; for (auto p : a) __p(p); cout << "}"; }
template<typename T, typename F>
void __p(pair<T, F> a) { cout << "{ "; __p(a.first); __p(a.second); cout << "}"; }
template<typename T, typename ...Arg>
void __p(T a1, Arg ...a) { __p(a1); __p(a...); }
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
    cout<<name<<" : ";__p(arg1);cout<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
    int bracket=0,i=0;
    for(; ;i++)
        if(names[i]==','&&bracket==0)
            break;
        else if(names[i]=='(')
            bracket++;
        else if(names[i]==')')
            bracket--;
    const char *comma=names+i;
    cout.write(names,comma-names)<<" : ";
    __p(arg1);
    cout<<"| ";
    __f(comma+1,args...);
}
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define trace(...)
#define end_routine()
#endif

mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
inline bool equals(double a, double b) { return fabs(a - b) < 1e-9; }
ll modpow(ll b, ll e, ll mod=MOD) {
    ll ans=1; for(;e;b=b*b%mod,e/=2) if(e&1) ans=ans*b%mod; return ans; }

ld modp(ld b, ll e) {
    ld ans=1; for(;e;b=b*b,e/=2) if(e&1) ans=ans*b; return ans; }

void solve()
{
    // START
    ll a,b;
    cin >>a>>b;
    ld ans = (a*b);
    ans/=100;
    cout<<ans<<"\n";

    // END
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0), cout.precision(15);   cout<<fixed;
    #ifdef godfather
        cin.exceptions(cin.failbit);
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int t=1;
    // cin>>t;
    fr(i,1,t)
    {
        // cout<<"Case #"<<i<<": ";
        solve();
    }
    end_routine();
}

#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
ll B,C;
long a,b,c,d;

void fun1()//判断C的
{
    ll n=C/2;
    if(C%2==1)
    {
        a=-1*B-n;

        b=-1*B+n;
    }
    else
    {
        if(C==0)
        {
            a=B;
            b=B;
        }
        else
        {
            a=B - n;
            b=B + n - 1;
        }
    }
    // cout<<n<<endl;
    // cout<<a<<" "<<b<<"**"<<endl;
}
void fun2()//判断C-1的
{
    long long cc=C-1;
    ll n=(cc)/2;
    if(cc%2==1)
    {
        c=-1*B-n;
        d=-1*B+n;
    }
    else
    {
        if(cc==0)
        {
            c=B;
            d=B;
        }
        else
        {
            c=B - n;
            d=B + n - 1;
        }
    }
    // cout<<n<<endl;
    // cout<<c<<" "<<d<<"**"<<endl;
}
int main()
{
    while(cin>>B>>C)
    {
        fun1();
        fun2();
        cout << (b-a+1)+(d-c+1)-max(0l,min(b,d)-max(a,c)+1)<<endl;
    }
    // system("pause");
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define in inline
namespace fast_io
{
	char buf[1<<12],*p1=buf,*p2=buf,sr[1<<23],z[23],nc;int C=-1,Z=0,Bi=0,ny;
	in char gc() {return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<12,stdin),p1==p2)?EOF:*p1++;}
	in ll read()
	{
		ll x=0;ny=1;while(nc=gc(),(nc<48||nc>57)&&nc!=EOF)if(nc==45)ny=-1;Bi=1;if(nc<0)return nc;
		x=nc-48;while(nc=gc(),47<nc&&nc<58&&nc!=EOF)x=(x<<3)+(x<<1)+(nc^48),Bi++;return x*ny;
	}
	in db gf() {int a=read(),y=ny,b=(nc!='.')?0:read();return (b?a+(db)b/pow(10,Bi)*y:a);}
	in int gs(char *s) {char c,*t=s;while(c=gc(),c<=32);*s++=c;while(c=gc(),c>32)*s++=c;return s-t;}
	in void ot() {fwrite(sr,1,C+1,stdout);C=-1;}
	in void flush() {if(C>1<<22) ot();}
	template <typename T>
	in void write(T x,char t)
	{
		int y=0;if(x<0)y=1,x=-x;while(z[++Z]=x%10+48,x/=10);
		if(y)z[++Z]='-';while(sr[++C]=z[Z],--Z);sr[++C]=t;flush();
	}
	in void write(char *s) {int l=strlen(s);for(int i=0;i<l;i++)sr[++C]=*s++;sr[++C]='\n';flush();}
};
using namespace fast_io;
const int N=1e6+5;
int n,m,p[N],a[N],v[N];
int main()
{
	n=read();a[1]=1;
	for(int i=2;i<=n;i++)
	{
		if(!v[i]) p[++m]=i,a[i]=2;
		for(int j=1;i*p[j]<=n&&j<=m;j++)
		{
			v[i*p[j]]=1;a[i*p[j]]=a[i]+1;
			if(i%p[j]==0) break;
		}
	}
	for(int i=1;i<=n;i++) write(a[i]," \n"[i==n]);
	return ot(),0;
}
//Author: disangan233

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


#include<bits/stdc++.h>
#define MAX 1000000007
#define MOD 998244353
#define ll long long int
#define fo(i,a,n) for(int i=a;i<n;i++)
#define ull unsigned long long int
#define pb push_back
#define eb emplace_back
#define in insert
#define cl clear
#define ii pair<int,int>
#define ld long double
const ll INF  = 1e18;
using namespace std;

void print(int arr[], int n){
    fo(i,0,n){
        cout<<arr[i]<<" ";
    }
    cout<<endl;
}

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

    int n,x;
    cin>>n>>x;

    vector<pair<int, int>> v(n);

    fo(i,0,n){
        cin>>v[i].first>>v[i].second;
    }

    int intake = 0;
    fo(i,0,n){
        intake += (v[i].first * v[i].second);
        if( intake > x*100 ){
            cout<<i+1<<endl;
            return 0;
        }
    }

    cout<<-1<<endl;

    return 0;
}

#include<stdio.h>

int main(){
	int n,x;
	scanf("%d%d",&n,&x);
	int sum=0;
	for(int i=0;i<n;i++){
		int v,p;
		scanf("%d%d",&v,&p);
		sum+=v*p;
		if(sum>x*100){
			printf("%d\n",i+1);
			return 0;
		}
	}
	puts("-1");
}


#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(char &c){
  int i;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c = i;
}
inline int rd(char c[]){
  int i;
  int sz = 0;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = my_getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
template<class T> inline T popFirst(multiset<T> &a){
  T res = *(a.begin());
  a.erase(a.begin());
  return res;
}
template<class T> inline T getFirst(multiset<T> &a){
  return *(a.begin());
}
template<class T> inline T popFirst(set<T> &a){
  T res = *(a.begin());
  a.erase(a.begin());
  return res;
}
template<class T> inline T getFirst(set<T> &a){
  return *(a.begin());
}
int N;
char S[500000+2];
char T[500000+2];
int main(){
  int i;
  int x;
  int y;
  long long res = 0;
  set<int> ss;
  set<int> tt;
  rd(N);
  rd(S);
  rd(T);
  for(i=(0);i<(N);i++){
    if(S[i]=='1'){
      ss.insert(i);
    }
  }
  for(i=(0);i<(N);i++){
    if(T[i]=='1'){
      tt.insert(i);
    }
  }
  while(ss.size() || tt.size()){
    if(ss.size()==0){
      wt_L(-1);
      wt_L('\n');
      return 0;
    }
    if(tt.size()==0 || getFirst(ss) < getFirst(tt)){
      if(ss.size()==1){
        wt_L(-1);
        wt_L('\n');
        return 0;
      }
      x = popFirst(ss);
      y = popFirst(ss);
      res += y - x;
      continue;
    }
    else{
      x = popFirst(ss);
      y = popFirst(tt);
      res += x - y;
    }
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20201115-1

// --- original code ---
// int N;
// char S[5d5+2], T[5d5+2];
// {
//   int x, y;
//   ll res = 0;
//   set<int> ss, tt;
//   rd(N,S,T);
//   rep(i,N) if(S[i]=='1') ss.insert(i);
//   rep(i,N) if(T[i]=='1') tt.insert(i);
//   while(ss.size() || tt.size()){
//     if(ss.size()==0) wt(-1), return 0;
//     if(tt.size()==0 || getFirst(ss) < getFirst(tt)){
//       if(ss.size()==1) wt(-1), return 0;
//       x = popFirst(ss);
//       y = popFirst(ss);
//       res += y - x;
//       continue;
//     } else {
//       x = popFirst(ss);
//       y = popFirst(tt);
//       res += x - y;
//     }
//   }
//   wt(res);
// }

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

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

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

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

int main()
{
  FAST/**/

   ll n,m;
   cin>>n>>m;

   string arr[n];
   ll cnt = 0;
   rep(n)
        cin>>arr[i];
   rep(n-1)
   {
       repi(j,m)
            if(arr[i][j] == '.' && arr[i+1][j] == '.')
                cnt++;
   }

   repi(j,m-1)
        rep(n)
            if(arr[i][j] == '.' && arr[i][j+1] == '.')
                cnt++;

   cout<<cnt;

  return 0;

}


#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#define ll long long
#define rep(i,n) for(int i = 0;i < (int)n;i ++)
#define mod % 998244353
using namespace std;

int main(void){
  ll n;
  cin >> n;
  ll A[n+1];
  A[0] = 1;
  rep(i,n){
    A[i+1] = (A[i]*(i+1))mod;
  }
  vector<ll> w(n);
  ll S = 3;
  rep(i,n){
    cin >> w[i];
    S += w[i];
  }
  sort(w.begin(),w.end());
  ll Q = S;
  vector<vector<vector<ll>>> P(n+1,vector<vector<ll>>(Q,vector<ll>(n+1,0)));
  P[0][Q/2][0] = 1;
  rep(i,n){
    rep(j,Q){

      rep(k,n+1){
        P[i][j][k] = P[i][j][k] mod;
        if(P[i][j][k] > 0){
          if(j+w[i]<Q)P[i+1][j+w[i]][k+1] = (P[i+1][j+w[i]][k+1]+P[i][j][k]) mod;
          if(j-w[i]>=0)P[i+1][j-w[i]][k] = (P[i+1][j-w[i]][k]+P[i][j][k]) mod;
        }
      }
    }
  }
  vector<ll> ans = P[n][Q/2];
  ll sum = 0;
  rep(i,n){
    ll M = (A[i]*A[n-i]) mod;
    sum = (sum+ans[i]*M) mod;
  }
  cout << sum << endl;
  return 0;
}

#include<bits/stdc++.h>
#define cs const
#define pb push_back
using namespace std;
cs int mod = 998244353;
int add(int a, int b) {
	return a + b >= mod ? a + b - mod : a + b;
}
int mul(int a, int b) {
	return 1ll * a * b % mod;
}
int dec(int a, int b) {
	return a - b < 0 ? a - b + mod : a - b;
}
void Add(int &a, int b) {
	a = add(a, b);
}
void Dec(int &a, int b) {
	a = dec(a, b);
}
void Mul(int &a, int b) {
	a = mul(a, b);
}
int ksm(int a, int b) {
	int ans = 1; for(; b; b >>= 1, Mul(a, a))
	if(b & 1) Mul(ans, a);
}
cs int N = 105, M = N * N;
int n, a[N];
int dp[N][M], fc[N];
int main() {
	#ifdef FSYo
	freopen("1.in", "r", stdin);
	#endif
	cin >> n;
	dp[0][0] = 1;
	int S = 0;
	for(int i = 1, x; i <= n; i++) {
		scanf("%d", &x);
		for(int j = i - 1; ~j; j--)
		for(int k = 0, c; k <= S; k++)
		if(c = dp[j][k])
		Add(dp[j + 1][k + x], c);
		S += x;
	}
	if(S & 1) return puts("0"), 0;
	S >>= 1;
	fc[0] = 1;
	for(int i = 1; i <= n; i++)
		fc[i] = mul(fc[i - 1], i);
	int ans = 0;
	for(int i = 1; i < n; i++) {
		Add(ans, mul(dp[i][S], mul(fc[i], fc[n - i])));
	}
	cout << ans;
	return 0;
}


#include<bits/stdc++.h>
#define pb emplace_back
#define AI(i) begin(i), end(i)
using namespace std;
using ll = long long;
template<class T>
bool chmax(T &val, T nv) { return val < nv ? (val = nv, true) : false; }
template<class T>
bool chmin(T &val, T nv) { return nv < val ? (val = nv, true) : false; }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() {cerr << endl;}
template<class T1, class ...T2>
void kout (T1 v, T2 ...e) { cerr << v << ' ', kout(e...); }
template<class T>
void debug(T L, T R) { while (L != R) cerr << *L << " \n"[next(L)==R], ++L; }
#else
#define DE(...) 0
#define debug(...) 0
#endif
// What I should check
// 1. overflow
// 2. corner cases
// Enjoy the problem instead of hurrying to AC
// Good luck !
const int MAX_N = 300010;

ll dfs(ll v, ll k) {
	static map<ll,ll> dp[100];
	if (k == 0) return abs(v);

	if (dp[k].count(v)) return dp[k][v];

	ll ad = 1ll << k;

	if (abs(v) >= 2 * ad) return abs(v);

	ll &ret = dp[k][v] = abs(v);

	chmin(ret, 0 + dfs(v, k-1));
	DE(v, k, ret);
	chmin(ret, 1 + dfs(v-ad, k-1));
	DE(v, k, ret);
	chmin(ret, 1 + dfs(v+ad, k-1));
	DE(v, k, ret);

	assert(ret >= 0);

	return ret;
}

ll solve(ll v, ll k) {
	if (k == 0) return abs(v);

	ll ad = 1ll << k;

	ll d = v / ad;

	ll ret = abs(v);

	DE(v, k);

	chmin(ret, abs(d) + dfs(v - d * ad, k));

	cerr << "Sv ", DE(v, k, ret);
	chmin(ret, abs(d+1) + dfs(v - (d+1) * ad, k));
	cerr << "Sv ", DE(v, k, ret);
	if (d)
	chmin(ret, abs(d-1) + dfs(v - (d-1) * ad, k));
	cerr << "Sv ", DE(v, k, ret);

	return ret;
}
int32_t main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	ll x, y;
	cin >> x >> y;

	ll res = abs(x - y);

	for (int k = 1;; ++k) {
		x *= 2;

		ll sv = solve(y - x, k);
		DE(k, y - x, sv);
		chmin(res, sv + k);

		if (x > y) break;
	}

	cout << res << '\n';
}

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

int h, w;

bool is_in(int i, int j){
    return 0 <= i && i < h && 0 <= j && j < w;
}

int INF = 1<<30;
int a[2000][2000];
int point[2000][2000];

int ad(int i, int j){
    bool flag1 = false, flag2 = false;
    if(point[i][j] != INF) return point[i][j];
    int ans1, ans2;
    int c = (2*((i+j)%2 == 0)-1);
    if(is_in(i+1, j)){
        flag1 = true;
        ans1 = ad(i+1, j);
        ans1 += c * a[i+1][j];
    }
    if(is_in(i, j+1)){
        flag2 = true;
        ans2 = ad(i, j+1);
        ans2 += c * a[i][j+1];
    }
    int ans = 0;
    if((i+j)%2 == 1 && (flag1 || flag2)){
        ans = 1<<30;
        if(flag1) ans = min(ans, ans1);
        if(flag2) ans = min(ans, ans2);
    }
    else if(flag1 || flag2){
        ans = -(1<<30);
        if(flag1) ans = max(ans, ans1);
        if(flag2) ans = max(ans, ans2);
    }
    point[i][j] = ans;

    return ans;
}

signed main(){
    // cout << fixed << setprecision(10) << flush;

    cin >> h >> w;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            char c;
            cin >> c;
            if(c == '+') a[i][j] = 1;
            else a[i][j] = -1;
        }
    }

    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            point[i][j] = INF;
        }
    }

    int ans = ad(0, 0);
    // cout << ans << endl;
    if(ans > 0) cout << "Takahashi" << endl;
    else if(ans < 0) cout << "Aoki" << endl;
    else cout << "Draw" << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include <algorithm>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int,int>;
using T = tuple<int,int,int>;
using Graph = vector<vector<int>>;
const int INF = 1001001001;
void printVec(vector<int> &vec) {
  for (auto itr = vec.begin(); itr != vec.end(); itr++) cout << *itr << " ";
  cout << endl;
}

int main() {
  ll N;
  cin >> N;
  vector<ll> vec;
  for(ll i = 2; i <= 100001; i++) {
    for(ll j = 2; j <= 35; j++) {
      ll a = pow(i, j);
      if(a > N) break;
      vec.push_back(a);
    }
  }
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  cout << N - vec.size() << endl;
}

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

int main() {
  cin.tie(0)->sync_with_stdio(0);
  long long n; cin >> n;
  map<long long,bool> m;
  long long ans = n;
  for (long long i = 2; i * i <= n; i++) {
    if (m.count(i)) continue;
    long long t = i * i;
    while (t <= n) {
      ans--;
      m[t] = true;
      t *= i;
    }
  }
  cout << ans << '\n';
}


#include <bits/stdc++.h>
#include <unordered_set>
#include <cmath>
#include <algorithm>
// #include <atcoder/all>

// URL:

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vs = vector<string>;

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n)? "YES": "NO") << endl
#define Yes(n) cout << ((n)? "Yes": "No") << endl

#define rept(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define fore(x, a) for(auto& (x) : (a))

#define reptll(i, a, b) for(ll i = (ll)(a); i < (ll)(b); i++)
#define repll(i, n) for (ll i = 0; i < (ll)(n); i++)

#define ALL(a) (a).begin(), (a).end()

#define VECCIN(x) for(auto& youso_: (x)) cin >> youso_
#define VECCOUT(x) for(auto& youso_: (x)) cout << youso_ << " ";cout << endl

#define pb push_back
#define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)

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

const ll INFL = numeric_limits<ll>::max() / 4;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main(){
  optimize_cin();

  int N;
  cin >> N;

  cout << (N - 1)/100 + 1 << endl;

  return 0;
}

#include <stdio.h>
#include <string>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int, int>;
int main()
{
  int n, start = 0, end = 1005;
  int a, b;
  cin >> n;

  rep(i,n){
    cin >> a;
    start = max(start, a);
  }
  rep(i,n){
    cin >> b;
    end = min(end, b);
  }

  if(start > end) cout << 0 << endl;
  else cout << end - start + 1 << endl;
}


#include<ctime>
#include<cstdio>
#include<cctype>
#define ll long long
using namespace std;
const ll N=2e6+7;
const ll p=1e9+7;
ll read(){
	char c;
	ll x=0,f=1;
	while(!isdigit(c=getchar()))
		f-=2*(c=='-');
	while(isdigit(c)){
		x=x*10+f*(c-48);
		c=getchar();
	}
	return x;
}
ll n,m,k,jc[N],inv[N];
ll C(ll i,ll j){
	if(j>i)
		return 0;
	return jc[i]*inv[j]%p*inv[i-j]%p;
}
ll HgS(ll a,ll b){
	ll res=1;
	while(b){
		if(b&1)
			res=res*a%p;
		a=a*a%p;
		b>>=1;
	}
	return res;
}
int main(){
	#ifndef ONLINE_JUDGE
	freopen("E.in","r",stdin);
	freopen("E.out","w",stdout);
	#endif
	clock_t t1=clock();
	//--------
	n=read();
	m=read();
	k=read();
	jc[0]=1;
	for(ll i=1;i<=n+m;++i)
		jc[i]=jc[i-1]*i%p;
	inv[n+m]=HgS(jc[n+m],p-2);
	for(ll i=n+m-1;~i;--i)
		inv[i]=inv[i+1]*(i+1)%p;
	if(n>m+k)
		puts("0");
	else
		printf("%lld",(C(n+m,n)-C(n+m,m+k+1)+p)%p);
	//--------
	fprintf(stderr,"%0.3lfs",1.0*(clock()-t1)/CLOCKS_PER_SEC);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

void solve() {
    int N;
    cin >> N;
    vector<pair<double, double>> A(N);
    REP(i, N) {
        int t;
        double l, r;
        cin >> t >> l >> r;
        if (t == 2) {
            r -= 0.1;
        } else if (t == 3) {
            l += 0.1;
        } else if (t == 4) {
            r -= 0.1;
            l += 0.1;
        }
        A[i] = {l, r};
    }
    int ans = 0;
    REP(i, N) {
        FOR(j, i + 1, N) {
            // 共通区間（左端の最大値 <= 右端の最小値）
            ans +=
                (max(A[i].first, A[j].first) <= min(A[i].second, A[j].second));
        }
    }
    cout << ans << endl;
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}


/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

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

const bool ready = [](){
    ios_base::sync_with_stdio(false); cin.tie(0);
    cout << fixed << setprecision(12);
    return true;
}();

const double PI = acos(-1);
using ll= long long;
#define int ll
#define all(v) (v).begin(), (v).end()
#define fori(n) for(int i=0; i<int(n); i++)

#define cini(i) int i; cin>>i;
#define cins(s) string s; cin>>s;
#define cind(d) double d; cin>>d;
#define cinai(a,n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s,n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a,n) vd a(n); fori(n) { cin>>a[i]; }

using pii= pair<int, int>;
using pdd= pair<double, double>;
using vd= vector<double>;
using vb= vector<bool>;
using vi= vector<int>;
using vvi= vector<vi>;
using vs= vector<string>;

#define endl "\n"

/*
 * Both print min 1 and max N
 * Value of second cannot be bigger than first since
 * first is optimal.
 * So M<0 is not possible.
 *
 * if M==0 choose all non overlapping like
 * (1,2),(3,4),...,(n*2-1,n*2)
 *
 * if M==1 make first overlap the next two, like
 * (1,6),(2,3),(4,5),(7,8),...
 *
 * if M==N-1 ?
 * -> Not possible
 */
void solve() {
    cini(n);
    cini(m);

    if(n==1 && m==0) {
        cout<<"1 2"<<endl;
        return;
    }

    if(m<0 || m>=n-1) {
        cout<<-1<<endl;
        return;
    }

    set<int> s;
    for(int i=2; i<=n*2; i++)
        s.insert(i);

    vi l(n);
    vi r(n);
    l[0]=1;
    if(m>0) {
        r[0]=4+m*2;
        s.erase(4+m*2);
    } else {
        r[0]=2;
        s.erase(2);
    }
    for(int i=1; i<n; i++)  {
        auto it=s.begin();
        l[i]=*it;
        s.erase(it);
        it=s.begin();
        r[i]=*it;
        s.erase(it);
    }
    for(int i=0; i<n; i++)
        cout<<l[i]<<" "<<r[i]<<endl;

}

signed main() {
    solve();
}

// FIRST THINK, THEN CODE
// DO NOT JUMP BETWEEN PROBLEMS


#pragma GCC optimize(3)
#include <bits/stdc++.h>
#define debug(x) cout<<#x<<":"<<x<<endl;
#define dl(x) printf("%lld\n",x);
#define di(x) printf("%d\n",x);
#define _CRT_SECURE_NO_WARNINGS
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef vector<int> VI;
const int INF = 0x3f3f3f3f;
const int N = 5010;
const ll mod = 998244353;
const double eps = 1e-9;
const double PI = acos(-1);
template<typename T>inline void read(T &a) {
	char c = getchar(); T x = 0, f = 1; while (!isdigit(c)) {if (c == '-')f = -1; c = getchar();}
	while (isdigit(c)) {x = (x << 1) + (x << 3) + c - '0'; c = getchar();} a = f * x;
}
int gcd(int a, int b) {return (b > 0) ? gcd(b, a % b) : a;}
ll ksm (ll a , ll b){ ll ans = 1 , base = a;
while (b){if (b & 1) ans = ans * base % mod;b >>= 1;base = base * base % mod;}return ans;}
ll f[N],inv[N];
ll dp[N][N];
int n,m;

ll C (ll a,ll b){
    if (a < b) return 0;
    return f[a] * inv[a - b] % mod * inv[b] % mod;
}

int main() {
	f[0] = inv[0] = 1;
    for (int i = 1 ; i < N ; i++){
        f[i] = f[i - 1] * i % mod;
        inv[i] = ksm(f[i] , mod - 2);
    }
    read(n),read(m);
    dp[0][0] = 1;
    for(int i = 1;i <= 20;i++){
    	if((1 << (i - 1)) > m){
    		dl(dp[i - 1][m]);
    		return 0;
    	}
    	for(int k = 0;k <= n;k += 2){
    		ll t = k * (1 << (i - 1));
    		if(t > m) break;
    		for(int j = t;j <= m;j++) dp[i][j] = (dp[i][j] + dp[i - 1][j - t] * C(n,k)) % mod;
    	}
    }
    return 0;
}

/**
*　　┏┓　　　┏┓+ +
*　┏┛┻━━━┛┻┓ + +
*　┃　　　　　　　┃
*　┃　　　━　　　┃ ++ + + +
*  ████━████+
*  ◥██◤　◥██◤ +
*　┃　　　┻　　　┃
*　┃　　　　　　　┃ + +
*　┗━┓　　　┏━┛
*　　　┃　　　┃ + + + +Code is far away from
*　　　┃　　　┃ + bug with the animal protecting
*　　　┃　 　 ┗━━━┓ 神兽保佑,代码无bug
*　　　┃ 　　　　　　 ┣┓
*　　  ┃ 　　　　　 　┏┛
*　    ┗┓┓┏━┳┓┏┛ + + + +
*　　　　┃┫┫　┃┫┫
*　　　　┗┻┛　┗┻┛+ + + +
*/

#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
using ll=long long;
using namespace std;

//const int mod = 1000000007;
const int mod = 998244353;
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 { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= 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);}

  //supports not prime
  mint modinv(ll a) {
    long long b = mod, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= mod;
    if (u < 0) u += mod;
    mint res(u);
    return res;
}
  mint& operator/=(const mint a) { return *this *= modinv(a.x);}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

//combination
//under mint
vector<mint> fact;
vector<mint> finv;

void comb_init(int n){
    fact=vector<mint>(n+1);
    finv=vector<mint>(n+1);
    fact[0]=1;
    for(int i=1;i<=n;i++){
        fact[i]=fact[i-1]*i;
    }
    finv[0]=1;
    finv[n]=mint(1)/fact[n];
    for(int i=n;i>=2;i--){
        finv[i-1]=finv[i]*i;
    }
}

mint comb(int a,int b){
    return fact[a]*finv[b]*finv[a-b];
}

int main(){
    int N,M;
    cin>>N>>M;
    comb_init(N+1);
    //vector<vector<vector<mint>>> dp(13,vector<vector<mint>> (N+1,vector<mint>(M+1,0)));
    vector<vector<mint>> dp(14,vector<mint>(M+1,0));
    dp[0][0]=1;
    for(int i=1;i<=13;i++){
        for(int j=0;j<=M;j++){
            for(int k=0;k<=N;k+=2){
                int base=1<<(i-1);
                if(base*k > j){
                    continue;
                }
                dp[i][j]+=comb(N,k)*dp[i-1][j-base*k];

            }
        }
    }
    /*
    for(auto p:dp){
        for(auto q:p){
            cout<<q<<" ";
        }
        cout<<endl;
    }
    //*/
    cout<<dp[13][M]<<endl;

    return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 500500;
int t[maxn];
int n;
void upd(int p,int x) {
	for(; p < maxn; p |= (p + 1)) t[p] += x;
}
int get(int p) {
	int r = 0;
	for(; p >= 0; p = (p & (p + 1)) - 1) r += t[p];
	return r;
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n;
	vector<pair<int, int>> a(n), b(n);
	for(int i = 0; i < n; i++) {
		cin >> a[i].first;
		a[i].first += i;
		a[i].second = i;
	}
	for(int i = 0; i < n; i++) {
		cin >> b[i].first;
		b[i].first += i;
		b[i].second = i;
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	vector<int> p(n);
	for(int i = 0; i < n; i++) {
		if(a[i].first != b[i].first) {
			cout << -1;
			return 0;
		}
		p[a[i].second] = b[i].second;
	}
	ll ans = 0;
	for(int i = n - 1; i >= 0; i--) {
		ans += get(p[i]);
		upd(p[i], 1);
	}
	cout << ans;
}

#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <set>
#include <vector>
#include <queue>
#include <map>
#include <numeric>
#include <math.h>
#include <complex>

using namespace std;

#define rep(i, n) for (long long int i = 0; i < (long long int)(n); i++)
#define irep(i, n) for (long long int i = 1; i <= (long long int)(n); i++)
#define drep(i, n, diff) for (long long int i = 0; i < (long long int)(n); i += diff)
#define mod 1000000007
#define INF 1001001001001001011
#define ld(val) printf("%s : %lld\n", #val, val);
#define sd(val) printf("%s : %s\n", #val, val.c_str());

typedef long long int ll;
typedef pair<ll, ll> P;
typedef pair<P, P> PP;
typedef tuple<ll, ll, ll> TP;

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

  rep(i, n) {
    cin >> a[i];
  }
  rep(i, n) {
    cin >> b[i];
  }
  rep(i, n) {
    cin >> c[i];
    c[i]--;
  }
  map<ll, ll> mp;
  rep(i, n) {
    mp[b[c[i]]]++;
  }

  ll ans = 0;
  rep(i, n) {
    ans += mp[a[i]];
  }
  cout << ans << endl;
  return 0;
}


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

#define rep(i, a, b) for(int i=a; i<=b; i++)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int) x.size()
#define f first
#define s second
#define nl "\n"
#define pb push_back
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
const int MOD = 1e9+7;
template<class T> using pqg = priority_queue<T,vector<T>,greater<T>>;

int n, m;
vector<pii> edges[26];
bool e[1000][1000];
vi adj[1000*999+999];
int dist[1000*999+999];

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);

  cin >> n >> m;
  rep(i, 1, m){
    int u, v; char c;
    cin >> u >> v >> c;
    u--; v--;
    edges[c-'a'].pb({u, v});
    edges[c-'a'].pb({v, u});
    e[u][v]=e[v][u]=true;
  }

  rep(c, 0, 25){
    rep(i, 0, sz(edges[c])-1){
      rep(j, i+1, sz(edges[c])-1){
        int a=edges[c][i].f;
        int b=edges[c][i].s;
        int C=edges[c][j].f;
        int d=edges[c][j].s;
        adj[1000*min(a, C)+max(a, C)].pb(1000*min(b, d)+max(b, d));
      }
    }
  }

  //shortest dist from 1000*1+n to 1000a+a or 1000a+b (a-b)
  pqg<pii> pq;
  int ans=1e9;
  pq.push({0, n-1});
  while(!pq.empty()){
    pii p=pq.top(); pq.pop();
    int d=p.f;
    int u=p.s/1000;
    int v=p.s%1000;
    if(dist[p.s]) continue;
    dist[p.s]=d;
    if(u==v){
      ans=min(ans, 2*d);
    }
    if(e[u][v]){
      ans=min(ans, 2*d+1);
    }
    trav(k, adj[p.s]){
      if(dist[k]==0) pq.push({d+1, k});
    }
  }
  cout << (ans==1e9?-1:ans);
}

#include<bits/stdc++.h>
#define ll long long
#define N 2005
using namespace std;
struct node{
	int to,nxt;
}e[N*N*2];
int head[N],tot,d[N];
void build(int a,int b)
{
	++d[a],++d[b];
	e[++tot].to=b;
	e[tot].nxt=head[a];
	head[a]=tot;
	e[++tot].to=a;
	e[tot].nxt=head[b];
	head[b]=tot;
}
int n,m,vis[N];
char mp[N][N];
void dfs(int p)
{
	vis[p]=1;
	for(int i=head[p];i;i=e[i].nxt)
	{
		if(!vis[e[i].to])
		dfs(e[i].to);
	}
}
int main()
{
#ifdef lovelyG
Sfile(1);
#endif
	scanf("%d%d",&n,&m);
	build(1,1+n);
	build(1,m+n);
	build(n,1+n);
	build(n,m+n);
	for(int i=1;i<=n;++i)
	{
		scanf("%s",mp[i]+1);
		for(int j=1;j<=m;++j)
		{
			if(mp[i][j]=='#')
			build(i,j+n);
		}
	}
	int numr=0,numc=0;
	for(int i=1;i<=n;++i)
	{
		if(!vis[i])
		{
			++numr;
			if(d[i])++numc;
			dfs(i);
		}
	}
	for(int i=1;i<=m;++i)
	{
		if(!vis[i+n])
		{
			++numc;
		}
	}
	printf("%d",min(numr,numc)-1);
	return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
#include<cstring>
#include<map>
#include<set>
#include<cstdlib>
#include<bitset>
using namespace std;
#define FAST ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
typedef long long ll;
#define N 200005
ll p=1e9+7;
ll n,m,f[N][17][17]={0},v[22]={0},sm;
char a[N];
int main()
{
	ll i,j,k,a1,a2,an=0;
	scanf("%s",a+1);
	n=strlen(a+1);
	for(ll i=1;i<=n;i++)
		if(a[i]>='0'&&a[i]<='9')
			a[i]-='0';
		else
			a[i]-='A'-10;
	scanf("%lld",&m);
	for(ll i=0;i<=m;i++)
		f[0][i][i]=1;
	for(ll i=1;i<=n;i++)
		for(ll j=1;j<=m;j++)
			for(ll k=j;k<=m;k++)
				f[i][j][k]=((ll)f[i-1][j][k-1]*(17ll-k)+(ll)f[i-1][j][k]*k)%p;
	for(ll i=1;i<=n;i++)
		an=(an+15ll*f[i-1][1][m])%p;
	// for(ll i=1;i<=n;i++)
	// {
	// 	for(ll j=1;j<=m;j++)
	// 		for(ll k=j;k<=m;k++)printf("%lld\n",f[i][j][1]);
	// }
	for(ll i=1;i<=n;i++)
	{
		for(ll j=a[i]+1;j<=15;j++)
			an=(an-f[n-i][sm+(!v[j])][m]+p)%p;
		//printf("%lld\n",an);
		sm+=!v[a[i]];
		v[a[i]]=1;
	}
	printf("%lld",an);
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a)
#define dumparr(a,n)
#endif
#define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

pll operator+(pll a,pll b){
  return pll(a.first+b.first,a.second+b.second);
}
pll operator-(pll a,pll b){
  return pll(a.first-b.first,a.second-b.second);
}
pll operator*(ll a,pll b){
  return pll(b.first*a,b.second*a);
}
const ll INF=(1LL<<60);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  a=abs(a);
  b=abs(b);
  if(a==0)return b;
  if(b==0)return a;
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif
template<class T>
bool chmax(T& a,const T& b){
  if(a<b){
    a=b;
    return true;
  }
  return false;
}
template<class T>
bool chmin(T& a,const T& b){
  if(a>b){
    a=b;
    return true;
  }
  return false;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}

const long long MOD = 1000000007;
const long long max_cache=100;
long long cache_fact[max_cache],cache_inv_fact[max_cache];
long long combination_cached(long long n,long long r){
  ll m=MOD;
  static bool cached=false;
  if(cached==false){
    cached=true;
    cache_inv_fact[1]=1;
    for (long long i = 2; i < max_cache; i++) {
      cache_inv_fact[i]=(m-m/i)*cache_inv_fact[m%i]%m;
    }
    for (long long i = 2; i < max_cache; i++){
      cache_inv_fact[i]=cache_inv_fact[i]*cache_inv_fact[i-1]%m;
    }
    cache_fact[0]=1;
    for (long long i = 1; i < max_cache; i++) {
      cache_fact[i]=cache_fact[i-1]*i%m;
    }
  }
  if(r<0||r>n)return 0;
  if(r==0||r==n)return 1;
  if(n>m){
    std::cerr<<"Combination Error: n is greater than m"<<std::endl;
    exit(1);
  }
  r=min(r,n-r);
  return cache_fact[n]*cache_inv_fact[r]%m*cache_inv_fact[n-r]%m;
}
long long modpow(long long a,long long b){
  long long base=a,ans=(1LL);
  while(b){
    if(b&1){
      ans=ans*base%MOD;
    }
    base=base*base%MOD;
    b>>=1;
  }
  return ans;
}
long long invpow(long long a){
  return modpow(a,MOD-2);
}
ll solve_nk(ll n,ll k,ll len){
  ll ans=combination_cached(16-n,k);
  ll tmp=0;
  REP(k+1){
    tmp+=modpow(MOD-1,i)*combination_cached(k,i)%MOD*modpow(k-i+n,len)%MOD;
  }
  return ans*tmp%MOD;
}
void solve(std::string N, long long K){
  auto c2i=[](char x){
    if('0'<=x&&x<='9'){
      return (ll)(x-'0');
    }else{
      return (ll)(x-'A')+10;
    }
  };
  unordered_map<ll,ll> m;
  auto inc_m=[&m](ll x){
    if(m.count(x)){
      ++m[x];
    }else{
      m[x]=1;
    }
  };
  auto dec_m=[&m](ll x){
    assert(m.count(x));
    --m[x];
    if(m[x]==0){
      m.erase(x);
    }
  };
  ll ans=0;
  REP(N.size()-1){
    ans=(ans+15*solve_nk(1,K-1,i)%MOD)%MOD;
  }
  REP(N.size()){
    FOR(j,0,c2i(N[i])){
      if(i==0&&j==0)continue;
      inc_m(j);
      ans=(ans+solve_nk(m.size(),K-m.size(),N.size()-i-1))%MOD;
      dec_m(j);
    }
    inc_m(c2i(N[i]));
  }
  if(m.size()==K){
    ++ans;
  }
  cout<<ans<<endl;
}

int main(){
  cout<<setprecision(1000);
  std::string N;
    std::cin >> N;
    long long K;
    scanf("%lld",&K);
  solve(N, K);
  return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define mod 1000000007
#define ad(a,b) a=(a+b)%mod;
#define X 200010
ll po(ll x,ll y){
	ll res=1;
	for(;y;y>>=1){
		if(y&1)res=res*x%mod;
		x=x*x%mod;
	}
	return res;
}
ll gcd(ll a,ll b){
	return (b?gcd(b,a%b):a);
}
ll fac[X],ivf[X];
void initfac(){
	fac[0]=1;
	for(ll i=1;i<X;i++)fac[i]=fac[i-1]*i%mod;
	for(ll i=0;i<X;i++)ivf[i]=po(fac[i],mod-2);
}
ll C(ll n,ll k){
	return fac[n]*ivf[n-k]%mod*ivf[k]%mod;
}

ll n,a[210],b[210];
vector<ll> A[210],B[210];//A[p]:=(a[i]==p)=なるiのset
bool f[210][210];
bool solve(){
	cin>>n;
	rep(i,n){
		cin>>a[i]>>b[i];
		if(a[i]>=0)a[i]--;
		if(b[i]>=0)b[i]--;
		if(a[i]!=-1&&b[i]!=-1&&a[i]>=b[i])return 0;
		if(a[i]>=0)A[a[i]].push_back(i);
		if(b[i]>=0)B[b[i]].push_back(i);
	}
	rep(i,2*n){
		if(A[i].size()+B[i].size()>1)return 0;
	}//重複なし
	for(int i=0;i<=2*n;i++)for(int j=0;j<=2*n;j++)f[i][j]=0;
	for(int l=0;l<2*n;l+=2){
		for(int k=1;l+2*k<=2*n;k++){
			int r=l+2*k;
			bool ok=1;
			rep(i,n){
				bool va=(l<=a[i]&&a[i]<r);
				bool vb=(l<=b[i]&&b[i]<r);
				if(a[i]>=0&&b[i]>=0){
					if(va==0&&vb==0)continue;
					if(va==1&&vb==1){
						ok&=(a[i]+k==b[i]);
						continue;
					}
					ok=0;
				}
				else if(a[i]==-1&&b[i]==-1)continue;
				else if(a[i]>=0){
					if(va==0)continue;
					if(not(0<=a[i]+k&&a[i]+k<2*n))ok=0;
					else if(A[a[i]+k].size()+B[a[i]+k].size()>0)ok=0;
				}
				else if(b[i]>=0){
					if(vb==0)continue;
					if(not(0<=b[i]-k&&b[i]-k<2*n))ok=0;
					else if(A[b[i]-k].size()+B[b[i]-k].size()>0)ok=0;
				}
			}
			f[l][r]=ok;
			//cerr<<"f["<<l<<"]["<<r<<"]="<<f[l][r]<<endl;
		}
	}
	bool dp[210];
	for(int i=0;i<=2*n;i++)dp[i]=0;
	dp[0]=1;
	for(int i=0;i<2*n;i++){
		if(dp[i]==0)continue;
		for(int j=i+1;j<=2*n;j++){
			if(f[i][j]==1){
				dp[j]=1;
			}
		}
	}
	return dp[2*n];
}
int main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<(solve()?"Yes":"No")<<endl;

}

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

int main() {
    int n; cin >> n;
    vector<pair<string, int>> s(n);
    for (int i=0; i<n; i++) {
        cin >> s[i].first;
        if (s[i].first[0] == '!') {
            s[i].first.erase(0, 1);
            s[i].second = 1;
        } else {
            s[i].second = 0;
        }
    }
    sort(s.begin(), s.end());

    for (int i=0; i<n-1; i++) {
        if (s[i].first == s[i+1].first && s[i].second != s[i+1].second) {
            cout << s[i].first << endl;
            return 0;
        }
    }

    cout << "satisfiable" << endl;
    return 0;
}


/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <cstdio>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
#include <cassert>
#include <random>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

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

ll conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}

ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
ll modpow(ll a, ll b){
    ll res = 1;
    while(b > 0){
        if(b & 1){
            res *= a;
            res %= MOD;
        }
        a *= a;
        a %= MOD;
        b >>= 1;
    }
    return res;
}
int main(void){
    ll h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i, h) cin >> s[i];

    vector<vector<ll>> ve(h, vector<ll>(w, 0)), ho(h, vector<ll>(w, 0));
    ll k = 0;
    rep(i, h){
        ll cnt = 0;
        rep(j, w){
            if(s[i][j] == '.'){
                k++;
                cnt++;
            } else {
                cnt = 0;
            }
            ho[i][j] = cnt;
        }

        for(ll j = w - 2; j >= 0; j--){
            if(s[i][j] == '.'){
                ho[i][j] = max(ho[i][j], ho[i][j + 1]);
            }
        }
    }

    rep(i, w){
        ll cnt = 0;
        rep(j, h){
            if(s[j][i] == '.'){
                cnt++;
            } else {
                cnt = 0;
            }
            ve[j][i] = cnt;
        }

        for(ll j = h - 2; j >= 0; j--){
            if(s[j][i] == '.'){
                ve[j][i] = max(ve[j][i], ve[j + 1][i]);
            }
        }
    }
    ll ans = 0;
    rep(i, h){
        rep(j, w){
            if(s[i][j] == '.'){
                //cout << i << " " << j << "   " << ho[i][j] << " " << ve[i][j] << endl;
                ans += modpow(2LL,k) - modpow(2LL, k - (ho[i][j] + ve[i][j] - 1));
                ans %= MOD;
            }
        }
    }

    while(ans < 0) ans += MOD;

    cout << ans % MOD << endl;
}

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
static const ll mod=1000000007;
ll H,W;
char f[2005][2005];
ll modpow(ll x,ll y){
  if(y==0)
    return 1;
  else if(y%2==0){
  ll z=modpow(x,y/2);
    return (z*z)%mod;
  }else{
   ll z=modpow(x,y/2);
    return (x*((z*z)%mod))%mod;
  }
}
ll sum[2005][2005];
int main(){
cin>>H>>W;ll K=0;
  for(ll i=0;i<H;i++){
  string s;cin>>s;
    for(ll j=0;j<W;j++){
      f[i][j]=s[j];
    if(f[i][j]=='.')K++;
    }
  }
  for(ll i=0;i<H;i++){
  ll x=0;
    for(ll j=0;j<W;j++){
    if(f[i][j]=='#')
      x=0;
      else{
      x++;sum[i][j]+=x;
      }
     }
   } for(ll j=0;j<W;j++){
  ll x=0;
    for(ll i=H-1;0<=i;i--){
    if(f[i][j]=='#')
      x=0;
      else{
      x++;sum[i][j]+=x;
      }
     }
   } for(ll i=0;i<H;i++){
  ll x=0;
    for(ll j=W-1;0<=j;j--){
    if(f[i][j]=='#')
      x=0;
      else{
      x++;sum[i][j]+=x;
      }
     }
   } for(ll j=0;j<W;j++){
  ll x=0;
    for(ll i=0;i<H;i++){
    if(f[i][j]=='#')
      x=0;
      else{
      x++;sum[i][j]+=x;
      }
     }
   }ll ans=0;ll k=modpow(2,K);
  for(ll i=0;i<H;i++)
    for(ll j=0;j<W;j++)
      if(f[i][j]!='#'){
        ll y=sum[i][j]-3;
      ll x=(k-modpow(2,K-y)+mod)%mod;
      ans=(ans+x)%mod;
      }cout<<ans<<endl;
      return 0;
}


/*
	Auth: StardustSphere
	Time: 2021/01/10
	Prog: ARC111-C
	Lang: cpp
*/
#define F_C
#include <bits/extc++.h>
#define rep(i, l, r) for(int i = l; i < r; i++)
#define hrp(i, l, r) for(int i = l; i <= r; i++)
#define rev(i, r, l) for(int i = r; i >= l; i--)
#define ms(n, t) memset(n, t, sizeof(n))
#define pb emplace_back
#define int ll
#ifndef JOEON
#define D(...) 97
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
template<typename tn = int> inline tn next(void) { tn k; cin>>k; return k; }
const int U = 2e5+50;
int afford[U], weight[U], keep[U], keeper[U];
vector<pii> ans;
vector<int> v;
signed main(void)
{
	#ifdef JOEON
//		freopen("C:\\Users\\Joeon\\Desktop\\IN.txt", "r", stdin);
//		freopen("C:\\Users\\Joeon\\Desktop\\OUT.txt", "w", stdout);
	#endif

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

	int n = next();
	rep(i, 0, n) cin>>afford[i];
	rep(i, 0, n) cin>>weight[i];
	rep(i, 0, n)
	{
		keep[i] = next()-1;
		keeper[keep[i]] = i;
		if (afford[i] <= weight[keep[i]] && keep[i] != i) return cout<<-1<<endl, 0;
		if (keep[i] != i) v.pb(i);
	}

	sort(v.begin(), v.end(), [=](const int& a, const int& b)
	{
		return afford[a] < afford[b];
	});
	rep(i, 0, v.size()) // person
	{
		if (v[i] == keep[v[i]]) continue;
		int ot = keeper[v[i]];
		ans.pb(v[i], ot);
		swap(keep[v[i]], keep[ot]);
		keeper[keep[i]] = i;
		keeper[keep[ot]] = ot;
	}

	cout<<ans.size()<<endl;
	for(auto &[f, s] : ans) cout<<f+1<<' '<<s+1<<endl;

	return 0;
}

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

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

int main() {
	// your code goes here
	IOS;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll i, j, t, k, x, y, z,  N;
	cin >> n >> m >> k;
	map<ll, ll> fail;
	rep(i, k) {
		cin >> x;
		fail[x] = 1;
	}
	db dp_sum[n + m], dp_carry[n + m];
	rep(i, n + m) {
		dp_carry[i] = 0; dp_sum[i] = 0;
	}
	db sum = 0, car = 0;
	for (i = n - 1; i > 0; i--) {
		if (fail[i]) {
			dp_carry[i] = 1;
			dp_sum[i] = 0;

		}
		else {
			dp_carry[i] = car / db(m);
			dp_sum[i] = 1.0 + sum / db(m);
		}
		sum += dp_sum[i];
		car += dp_carry[i];
		sum -= dp_sum[i + m];
		car -= dp_carry[i + m];

	}
	sum = 1.0 + sum / db(m);
	car = car / db(m);
	// rep(i, n + m) {
	// 	cout << dp_sum[i] << ' ';
	// }
	db ans = sum / (1.0 - car);
	if (ans <= 0 || (1.0 - car) < 1e-6) cout << -1;
	else
		cout << fixed << setprecision(5) << ans;

	return 0;

}


#include <bits/stdc++.h>
/* #include <atcoder/all> */

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;
/* using namespace atcoder; */

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

const int MOD = 1'000'000'007;

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

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i, h) {
    cin >> s.at(i);
  }
  vector<vector<ll>> r(h, vector<ll>(w));
  vector<vector<ll>> d(h, vector<ll>(w));
  vector<vector<ll>> rd(h, vector<ll>(w));
  vector<vector<ll>> dp(h, vector<ll>(w, 0));
  dp.at(0).at(0) = 1;
  rep(i, h) {
    rep(j, w) {
      if (s.at(i).at(j) == '#') {
        r.at(i).at(j) = 0;
        d.at(i).at(j) = 0;
        rd.at(i).at(j) = 0;
        continue;
      }
      // r
      int oi = i - 1;
      int oj = j;
      if (oi < h && oj < w && oi >= 0 && oj >= 0) {
        r.at(i).at(j) += dp.at(oi).at(oj);
        r.at(i).at(j) += r.at(oi).at(oj);
      }
      // d
      oi = i;
      oj = j - 1;
      if (oi < h && oj < w && oi >= 0 && oj >= 0) {
        d.at(i).at(j) += dp.at(oi).at(oj);
        d.at(i).at(j) += d.at(oi).at(oj);
      }
      // rd
      oi = i - 1;
      oj = j - 1;
      if (oi < h && oj < w && oi >= 0 && oj >= 0) {
        rd.at(i).at(j) += dp.at(oi).at(oj);
        rd.at(i).at(j) += rd.at(oi).at(oj);
      }
      dp.at(i).at(j) += r.at(i).at(j);
      dp.at(i).at(j) %= MOD;
      dp.at(i).at(j) += d.at(i).at(j);
      dp.at(i).at(j) %= MOD;
      dp.at(i).at(j) += rd.at(i).at(j);
      dp.at(i).at(j) %= MOD;
    }
  }
  cout << dp.at(h - 1).at(w - 1) << endl;
  return 0;
}

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

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

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

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

int main()
{
  FAST/**/

   ll n,m;
   cin>>n>>m;

   if(n == 1)
   {
       if(m == 0)
       {
           cout<<1<<" "<<2<<"\n";
           return 0;
       }
       cout<<-1<<"\n";
       return 0;
   }

   if(m<0 || m >= n-1)
   {
       cout<<-1<<"\n";
       return 0;
   }

   if(m == 0)
   {
       rep(n)
            cout<<(2*i+1)<<" "<<(2*i+2)<<"\n";
       return 0;
   }

   if(m == n-1)
   {
       for(ll i=1;i<=n-1;i++)
           cout<<2*i<<" "<<2*i+1<<"\n";
       cout<<1<<" "<<2*n<<"\n";
       return 0;
   }

   ll sta = 2;
   for(ll i=0;i<m+1;i++)
   {
       cout<<sta<<" "<<sta+1<<"\n";
       sta+=2;
   }

   cout<<1<<" "<<sta<<"\n";
   sta++;
   rep(n-(m+2))
   {
       cout<<sta<<" "<<sta+1<<"\n";
       sta+=2;
   }

  return 0;

}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++)
#define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--)
#define all(v) v.begin(), v.end()
void chmax(ll &x, ll y) {x = max(x,y);}
void chmin(ll &x, ll y) {x = min(x,y);}
void Yes() {cout << "Yes" << endl; exit(0);}
void No() {cout << "No" << endl; exit(0);}
template<class in_Cout> void Cout(in_Cout x) {cout << x << endl; exit(0);}
template<class in_vec_cout>
void vec_cout(vector<in_vec_cout> vec) {
    for (in_vec_cout res : vec) {cout << res << " ";}
    cout << endl;
}

const ll inf = 1e18;
const ll mod = 1e9 + 7;

ll K, N, M;
vector<ll> A, B;

void init() {
    cin >> K >> N >> M;
    A.resize(K);
    B.resize(K);
    rep(i,K) cin >> A[i];
}

/*
|N*B[i]-M*A[i]| <= X; (0 <= X <= N*M)
M*A[i] - X <= N*B[i] <= M*A[i] + X;
ceil((M*A[i]-X)/N) <= B[i] <= floor((M*A[i]+X)/N)
*/

ll Ceil(ll x, ll y) {
    if (y==0) return inf;
    if (x<=0) return 0;
    ll res = x / y;
    if (x%y) res++;
    return res;
}

ll Floor(ll x, ll y) {
    if (y==0) return inf;
    return x / y;
}

bool ok(ll X) {
    vector<ll> l(K), r(K);
    ll L = 0, R = 0;
    rep(i,K) {
        l[i] = Ceil(M*A[i]-X,N);
        r[i] = Floor(M*A[i]+X,N);
        L += l[i];
        R += r[i];
    }

    if (M<L || R<M) return false;

    ll dif = M - L;
    rep(i,K) {
        B[i] = l[i];
        ll add = min(dif,r[i]-l[i]);
        B[i] += add;
        dif -= add;
    }
    return true;
}

void solve() {
    init();

    ll l = -1, r = N*M + 1;
    while (r-l>1) {
        ll m = (l+r)/2;
        if (ok(m)) r = m;
        else l = m;
    }

    vec_cout(B);
}

int main() {
    solve();
}

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

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

    vector<long double> a(k);
    vector<int> b(k);
    vector<pair<long double, int>> p(k);

    cin >> a;

    rep(i, k) b[i] = (a[i] * m) / n + 0.001;

    int r = m - accumulate(all(b), 0);

    rep(i, k)
    {
        p[i].first = b[i] - (a[i] * m) / n;
        p[i].second = i;
    }
    sort(all(p));

    rep(i, r)
    {
        b[p[i].second]++;
    }

    cout << b << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll _mergeSort(ll arr[], ll temp[],
				ll left, ll right);
ll merge(ll arr[], ll temp[], ll left,
				ll mid, ll right);

ll mergeSort(ll arr[], ll array_size)
{
	ll temp[array_size];
	return _mergeSort(arr, temp, 0, array_size - 1);
}

/* An auxiliary recursive function
that sorts the input array and
returns the number of inversions in the array. */
ll _mergeSort(ll arr[], ll temp[],
				ll left, ll right)
{
	ll mid, inv_count = 0;
	if (right > left) {
		/* Divide the array into two parts and
		call _mergeSortAndCountInv()
		for each of the parts */
		mid = (right + left) / 2;

		/* Inversion count will be sum of
		inversions in left-part, right-part
		and number of inversions in merging */
		inv_count += _mergeSort(arr, temp,
								left, mid);
		inv_count += _mergeSort(arr, temp,
							mid + 1, right);

		/*Merge the two parts*/
		inv_count += merge(arr, temp, left,
						mid + 1, right);
	}
	return inv_count;
}

/* This funt merges two sorted arrays
and returns inversion count in the arrays.*/
ll merge(ll arr[], ll temp[], ll left,
		ll mid, ll right)
{
	ll i, j, k;
	ll inv_count = 0;

	i = left; /* i is index for left subarray*/
	j = mid; /* j is index for right subarray*/
	k = left; /* k is index for resultant merged subarray*/
	while ((i <= mid - 1) && (j <= right)) {
		if (arr[i] <= arr[j]) {
			temp[k++] = arr[i++];
		}
		else {
			temp[k++] = arr[j++];

			/* this is tricky -- see above
			explanation/diagram for merge()*/
			inv_count = inv_count + (mid - i);
		}
	}

	/* Copy the remaining elements of left subarray
(if there are any) to temp*/
	while (i <= mid - 1)
		temp[k++] = arr[i++];

	/* Copy the remaining elements of right subarray
(if there are any) to temp*/
	while (j <= right)
		temp[k++] = arr[j++];

	/*Copy back the merged elements to original array*/
	for (i = left; i <= right; i++)
		arr[i] = temp[i];

	return inv_count;
}

int main()
{
	ll n;
	cin>>n;
	ll a[n],b[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		b[i]=a[i];
	}

	ll ans = mergeSort(b, n);
	cout<<ans<<endl;
	for(int i=0;i<n-1;i++)
	{
		cout<<ans-a[i]+(n-a[i]-1)<<endl;
		ans=ans-a[i]+(n-a[i]-1);
	}
	return 0;
}

/**
 *    author:  upsolver69
**/
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0); cin.tie(0);
#define f_in(file) freopen(file, "r", stdin)
#define f_out(file) freopen(file, "w", stdout)
#define sz(a) int((a).size())
#define pp pair
#define fi first
#define vt vector
#define se second
#define vt vector
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(c) c.begin(), c.end()
#define tr(i, c) for(auto& i : c)
#define present(c,x) (c.find(x) != c.end())  // Set and Maps
#define cpresent(c,x) (find(allc,x) != c.end()) // Vectors

using namespace std;

typedef long long ll;

const int mod = 1e9 + 7;
const int inf = (int) 1e9;

using pd = pair<double, double>;

void testcase() {
  int n, m, k;
  cin >> n >> m >> k;
  vt<bool> a(n + 1, 0);
  for (int i = 0; i < k; i++) {
    int x;
    cin >> x;
    a[x] = 1;
  }
  vector<pd> dp(n + m + 1, mp(0.0, 0.0));
  pd sum = {0, 0};
  for (int i = n - 1; i >= 0; i--) {
    sum.fi += dp[i + 1].fi;
    sum.se += dp[i + 1].se;
    sum.fi -= dp[i + m + 1].fi;
    sum.se -= dp[i + m + 1].se;
    if (a[i]) {
      dp[i] = mp(0, 1);
    } else {
      dp[i] = mp(1 + sum.fi / (double) m, sum.se / (double) m);
    }
  }
  double p = dp[0].fi;
  double q = 1 - dp[0].se;
  if (abs(q) < 1e-10) {
    cout << -1;
  } else {
    cout << fixed << setprecision(10) << p / q;
  }
}

int main(void) {
  fast
  int tt = 1;
  // cin >> tt;
  while (tt--) {
    testcase();
  }
  return 0;
}


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

template<typename T>
void compress(vector<T>& A) {
  vector<T> vals=A;
  vals.push_back(0);
  sort(vals.begin(),vals.end());
  vals.erase(unique(vals.begin(),vals.end()),vals.end());
  for(auto& e:A) e=distance(vals.begin(),lower_bound(vals.begin(),vals.end(),e));
}

int main() {
  ll N,M; cin>>N>>M;
  // 座標圧縮っぽい
  vector<ll> X,Y;
  ll size;
  ll ans=0;
  for(ll i=0; i<M; ++i) {
    ll x,y; cin>>x>>y;
    y=y-N+M;
    if(y<0 || y>2*M) continue;
    X.push_back(x); Y.push_back(y);
  }
  compress(X);
  size=X.size();
  map<ll,set<ll>> pawn;
  for(ll i=0; i<size; ++i) pawn[Y[i]].insert(X[i]);
  queue<pair<ll,ll>> que;
  map<pair<ll,ll>,bool> seen;
  que.push({0,M});
  seen[{0,M}]=true;
  while(!que.empty()) {
    auto p=que.front();
    que.pop();
    ll limit=LLONG_MAX;
    auto itr=pawn[p.second].upper_bound(p.first);
    if(itr==pawn[p.second].end()) ans++;
    else limit=*itr;
    // 前
    if(p.second-1>=0) {
      itr=pawn[p.second-1].upper_bound(p.first);
      for(;itr!=pawn[p.second-1].end();++itr) {
        if(*itr>limit) break;
        if(seen.count({*itr,p.second-1})==0) {
          que.push({*itr,p.second-1});
          seen[{*itr,p.second-1}]=true;
        }
      }
    }
    // 後
    if(p.second+1<=2*M) {
      itr=pawn[p.second+1].upper_bound(p.first);
      for(;itr!=pawn[p.second+1].end();++itr) {
        if(*itr>limit) break;
        if(seen.count({*itr,p.second+1})==0) {
          que.push({*itr,p.second+1});
          seen[{*itr,p.second+1}]=true;
        }
      }
    }
  }
  cout<<ans<<endl;
}

#include<bits/stdc++.h>

using namespace std;

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
    return '"' + s + '"';
}

string to_string(const char& s) {
    string res = "'";
    res += s;
    res += "'";
    return res;
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++) {
        if (i) res += ", ";
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v) {
    string res = "";
    for (size_t i = 0; i < N; i++) {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define int long long
#define fi first
#define se second
#define pii pair<int, int>
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(a) (int) (a).size()
#define eb emplace_back
#define ld long double
#define ve vector
#define forn(i, n) for (int i = 0; i < n; i++)

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    ve<pii> a(m);
    forn (i, m) cin >> a[i].fi >> a[i].se;
    sort(all(a));
    a.pb({1e18, 1e18});
    set<int> tmp;
    tmp.insert(n);
    int i = 0;
    while (true) {
        //debug(tmp);
        if (i == m) {
            cout << sz(tmp);
            return 0;
        }
        int j = i;
        while (a[j].fi == a[i].fi) j++;
        ve<int> ban;
        for (int v = i; v < j; v++) ban.pb(a[v].se);
        ve<int> add;
        for (auto x : ban) {
            if (tmp.find(x - 1) != tmp.end() || tmp.find(x + 1) != tmp.end()) add.pb(x);
        }
        //debug(ban, add);
        for (auto x : ban) {
            if (tmp.find(x) != tmp.end()) tmp.erase(x);
        }
        for (auto x : add) tmp.insert(x);
        i = j;
    }
}


#include <bits/stdc++.h>

#define Fast cin.tie(0), ios::sync_with_stdio(0)
#define All(x) x.begin(), x.end()
#define louisfghbvc int t; cin >> t; for(int tt = 0; tt < t; ++tt)
#define sz(x) (int)(x).size()
#define sort_unique(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()));
using namespace std;
typedef long long LL;
typedef pair<LL, LL> ii;
typedef vector<LL> vi;

template<typename T> istream& operator>>(istream &is, vector<T> &v) { for(auto &it : v) is >> it; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep = ""; for(const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cerr << " end.\n"; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

const int N = 5e2+5;
const int INF = 0x3f3f3f3f;
/**
Read problem statement carefully
**/
int dp[N][N];
LL A[N][N], B[N][N];

int r, c;
void solve(int x){
    memset(dp, 0x3f, sizeof dp);

    cin >> r >> c;
    for(int i = 1; i <= r; ++i)
        for(int j= 1; j < c; ++j)
            cin >> A[i][j];

    for(int i = 1; i < r; ++i)
        for(int j = 1; j <= c; ++j)
            cin >> B[i][j];

    dp[1][1] = 0;
    priority_queue<ii, vector<ii>, greater<ii>> pq;
    pq.push({0, 0});

    while(sz(pq)){
        auto [cost, idx] = pq.top(); pq.pop();
        int x = idx/c, y = idx%c;
        x++, y++;
        if(cost > dp[x][y]) continue;
        dp[x][y] = cost;
        if(y < c){
            if(dp[x][y+1] > dp[x][y] + A[x][y]){
                dp[x][y+1] = dp[x][y] + A[x][y];
                pq.push({dp[x][y+1], (x-1) * c + y});
            }
        }
        if(y > 1){
            if(dp[x][y-1] > dp[x][y] + A[x][y-1]){
                dp[x][y-1] = dp[x][y] + A[x][y-1];
                pq.push({dp[x][y-1], (x-1) * c + y - 2});
            }
        }
        if(x < r){
            if(dp[x+1][y] > dp[x][y] + B[x][y]){
                dp[x+1][y] = dp[x][y] + B[x][y];
                pq.push({dp[x+1][y], x * c + y - 1});
            }
        }
        for(int i = 1; i < r && x - i > 0; ++i){
            int ga = 1 + i;
            if(dp[x][y] + ga < dp[x-i][y]){
                dp[x-i][y] = dp[x][y] + ga;
                pq.push({dp[x-i][y], (x - i - 1) * c + y-1});
            }
        }
    }

    cout << dp[r][c] << "\n";
}

int main()
{
    // Fast;
    // louisfghbvc
        solve(1);
    return 0;
}

/**
Enjoy the problem.
**/

//#include <atcoder/all>
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
//using namespace atcoder;
using ll = long long;
#define all(A) A.begin(),A.end()
using vll = vector<ll>;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
using Graph = vector<vector<pair<ll, ll>>>;
int main(){
    ll R,C;
    cin>>R>>C;
    Graph G(2*R*C);
    rep(r,R){
        rep(c,C-1){
            ll A;
            cin>>A;
            G[r*C+c].push_back(make_pair(r*C+c+1,A));
            G[r*C+c+1].push_back(make_pair(r*C+c,A));
        }
    }
    rep(r,R-1){
        rep(c,C){
            ll A;
            cin>>A;
            G[r*C+c].push_back(make_pair((r+1)*C+c,A));
            G[R*C+(r+1)*C+c].push_back(make_pair(R*C+(r)*C+c,1));
        }
    }
    rep(r,R){
        rep(c,C){
            G[r*C+c].push_back(make_pair(R*C+r*C+c,1));
            G[R*C+r*C+c].push_back(make_pair(r*C+c,0));
        }
    }

    priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> Q;
    vll dist(2*R*C,1e17);
    dist[0]=0;
    Q.push(make_pair(0,0));
    while(!Q.empty()){
        auto p=Q.top();
        Q.pop();
        ll v=p.second;
        for(auto q:G[v]){
            ll nv=q.first;
            if(dist[nv]<=dist[v]+q.second)continue;

            dist[nv]=dist[v]+q.second;
            Q.push(make_pair(dist[nv],nv));
        }
    }
    cout<<dist[R*C-1]<<endl;
}


 /*
    Auther: ghoshashis545 Ashis Ghosh 😎
    College: Jalpaiguri Govt Enggineering College
*/
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
#include<algorithm>
#include<string>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template <class type1>
// using ordered_multiset = tree <type1, null_type, less_equal <type1>, rb_tree_tag, tree_order_statistics_node_update>;
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define ll int
#define int long long
#define ld long double
#define ff first
#define ss string
#define se second
#define sp(x) cout << fixed << setprecision(x)
#define endl "\n"
#define ub upper_bound
#define lb lower_bound
#define vi vector<int>
#define ipair pair<int,int>
#define vpi vector<ipair>
#define clr(a,x) memset(a,x,sizeof(a))
#define alt(v) v.begin(),v.end()
#define ralt(v) v.rbegin(),v.rend()
#define pb emplace_back
#define mp make_pair
#define cntb(x) __builtin_popcount(x)
#define fab(i,a,b) for(int i=(a);i<(b);i++)
#define fba(i,a,b) for(int i=(b);i>=(a);i--)
bool ispoweroftwo(int n){return n&(!(n&(n-1)));}
int mod=1000000007;
// int mod=998244353;
int dx[] = {1,0,-1,0};
int dy[] = {0,-1,0,1};

bool test  = 0;

const int inf = 1e9;
const int N = 2e5+5;

int k,n,q;
vector<int>adj[N],dep(N,0),val(N,0);

void dfs(int u,int p)
{
    for(auto it : adj[u]){
        if(it == p)
            continue;
        dep[it] = dep[u] + 1;
        dfs(it,u);
    }
}

void dfs1(int u,int p)
{
    for(auto it : adj[u]){
        if(it == p)
            continue;
        val[it] += val[u];
        dfs1(it,u);
    }
}

void solve(int tc = 0)
{
    cin >> n;
    vector<ipair>edge;
    for(int i = 1,x,y; i < n; ++i){
        cin >> x >> y;
        adj[x].pb(y);
        adj[y].pb(x);
        edge.pb(mp(x,y));
    }
    dfs(1,0);
    int s = 0;
    cin >> q;
    while(q--)
    {
        int t,e,v;
        cin >> t >>e >>v;
        s += v;
        int x = edge[e-1].ff;
        int y = edge[e-1].se;
        if(t == 2)
            swap(x,y);
        if(dep[x] > dep[y]){
            val[1] -= v;
            val[x] += v;
        }
        else{
            val[y] -= v;
        }
    }
    dfs1(1,-1);
    for(int i = 1; i<=n; ++i)
        cout<<(val[i]+s)<<"\n";

}

signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    int t=1;
    if(test)
    cin>>t;
    for(int i = 1; i <= t; ++i){
        solve(i);
    }
    return 0;
}

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0; i<(n); i++)
#define sz(x) int(x.size())

using namespace std;
using ll = long long;
using P = pair<int,int>;
using tp = tuple<int,int> ;

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

void dfs(int v, ll x, int from, const vector<vector<int>>& e, vector<ll>& dp){
    dp[v] += x;
    for(int next : e[v]){
        if(next == from) continue;
        dfs(next,dp[v], v, e,dp);
    }
    return ;
}

void deepDFS(int x, int d, vector<int>& deep, const vector<vector<int>>& e){

    deep[x] = d;
    for(int u : e[x]){
        if(deep[u] >= 0) continue;;
        deepDFS(u,d+1,deep,e);
    }
}

int main(){
    int n; cin >> n;
    vector<vector<int>> e(n);
    vector<int> A(n);
    vector<int> B(n);
    rep(i,n-1){
        int a,b; cin >> a >> b;
        a--; b--;
        e[a].push_back(b);
        e[b].push_back(a);
        A[i] = a; B[i] = b;
    }
    vector<int> deep(n,-1);
    deepDFS(0,0,deep,e);

    int q; cin >> q;
    vector<ll> dp(n);
    rep(i,q){
        int t,ei,x; cin >> t >> ei >> x;
        ei--;
        int a,b;
        if(t == 1) { a = A[ei]; b = B[ei]; }
        else { a = B[ei]; b = A[ei]; }

        if(deep[a] < deep[b]){
            dp[0] += x;
            dp[b] -= x;
        } else {
            dp[a] += x;
        }

    }

    dfs(0,0,-1,e,dp);
    rep(i,n) cout << dp[i] << endl;
    return 0;
}