#include <bits/stdc++.h>
#include <cassert>
#define rep(i, N) for (int i = 0; i < (N); ++i)
#define rep2(i, a, b) for (ll i = a; i <= b; ++i)
#define rep3(i, a, b) for (ll i = a; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define nl '\n'
#define endl '\n'
#define all(c) begin(c), end(c)
#define ok() puts(ok ? "Yes" : "No");
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;
}
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvll = vector<vll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using vs = vector<string>;
using P = pair<ll, ll>;
using gt = greater<P>;
using minq = priority_queue<P, vector<P>, gt>;
using vP = vector<P>;
template <class T> void takeUnique(vector<T> &v) {
  auto last = std::unique(v.begin(), v.end());
  v.erase(last, v.end());
}
template <class T> void print(const initializer_list<T> &il) {
  for (auto x : il) {
    cout << x << " ";
  }
  cout << "\n";
}
inline void priv(vi a) {
  rep(i, (int)a.size())
      printf("%d%c", a[i], i == (int)a.size() - 1 ? '\n' : ' ');
}
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int dxx[] = {0, 1, 1, 1, 0, -1, -1, -1};
int dyy[] = {1, 1, 0, -1, -1, -1, 0, 1};
// clang++ -std=c++11 -stdlib=libc++

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int N, M, Q;
  cin >> N >> M >> Q;
  vi W(N);
  vi V(N);
  vii I(N);
  vi X(M);
  rep(i, N) cin >> I[i].fi >> I[i].se;
  rep(i, M) cin >> X[i];
  sort(all(I));
  while (Q--) {
    int L, R;
    cin >> L >> R;
    // dp[i][j][k]:=max value s.t., seen i items, j th box has k space
    L--, R--;
    vi B;
    rep(i, M) {
      if (i <= R and i >= L)
        continue;
      B.pb(X[i]);
    }
    sort(all(B));
    int p = 0;
    priority_queue<int> valq;
    ll ans = 0;
    rep(i, B.size()) {
      while (p < N and I[p].fi <= B[i]) {
        valq.push(I[p].se);
        p++;
      }
      if (valq.empty())
        continue;
      int v = valq.top();
      valq.pop();
      ans += v;
    }
    cout << ans << endl;
  }
  return 0;
}

// テスト
#include<ctime>
#include<cmath>
#include<queue>
#include<cstdio>
#include<cctype>
#include<algorithm>
#define ll long long
using namespace std;
const ll N=2e5+7;
const ll INF=1ll<<55;
ll read() {
	char c;
	ll x=0,f=1;
	while(!isdigit(c=getchar()))
		f-=2*(c=='-');
	while (isdigit(c)){
		x=x*10+(c-48)*f;
		c=getchar();
	}
	return x;
}
struct edge{
	ll to,c,d,nxt;
	edge(ll to=0,ll c=0,ll d=0,ll nxt=0):to(to),c(c),d(d),nxt(nxt){}
}e[N];
ll n,m,a,b,c,d,tot,head[N],dis[N],vis[N];
void add(ll u,ll v,ll c,ll d){
	e[++tot]=edge(v,c,d,head[u]);
	head[u]=tot;
}
struct node{
	ll i,d;
	node(ll i=0,ll d=0):i(i),d(d){}
	friend bool operator <(node a,node b){
		return a.d>b.d;
	}
};
ll dijkstra(){
	priority_queue<node>q;
	for(ll i=1;i<=n;++i)
		dis[i]=INF;
	dis[1]=0;
	q.push(node(1,0));
	while(!q.empty()){
		node u=q.top();
		q.pop();
		ll x=u.i;
		if(vis[x])
			continue;
		vis[x]=1;
		for(ll i=head[x];i;i=e[i].nxt){
			ll y=e[i].to;
			ll c=e[i].c;
			ll d=e[i].d;
			ll t=sqrt(d);
			if(dis[x]<=t-1){
				for(ll j=-3;j<=3;++j){
					if(t+j<=0)
						continue;
					dis[y]=min(dis[y],(t+j)+d/(t+j)+c-1);
				}
				q.push(node(y,dis[y]));
			}
			if(dis[y]>dis[x]+c+d/(dis[x]+1)){
				dis[y]=dis[x]+c+d/(dis[x]+1);
				q.push(node(y,dis[y]));
			}
		}
	}
	if(dis[n]==INF)
		return -1;
	return dis[n];
}
int main() {
	#ifndef ONLINE_JUDGE
	freopen("E.in","r",stdin);
	freopen("E.out","w",stdout);
	#endif
	clock_t t1=clock();
	//--------
	n=read();
	m=read();
	for(int i=1;i<=m;++i){
		a=read();
		b=read();
		c=read();
		d=read();
		add(a,b,c,d);
		add(b,a,c,d);
	}
	printf("%lld",dijkstra());
	//--------
	clock_t t2=clock();
	fprintf(stderr,"time:%0.3lfs",1.0*(t2-t1)/CLOCKS_PER_SEC);
	return 0;
}


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

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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

// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

void solve()
{
  ll N, M; cin >> N >> M;

  if(M < 0 || (M > N - 2 && N != 1)) {
    cout << -1 << endl;
    return;
  }

  rep(i, N - 1) {
    cout << (i +  1) * 10 << " " << (i + 1) * 10 + 5 << "\n";
  }
  if(M > 0) {
    cout << "7 " << (M + 1) * 10 + 8 << "\n";
  } else {
    cout << "7 8\n";
  }
}

int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}

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

int main(void){
    long long int n,q,i,ng,ok,mid;

    cin >> n >> q;

    vector<long long int> a(n+1),k(q),c(n+1);
    a.at(0) = 0;
    c.at(0) = 0;

    for(i=1; i<=n; i++){
        cin >> a.at(i);
        c.at(i) = a.at(i) - i;
    }

    for(i=0; i<q; i++){
        cin >> k.at(i);
    }

    for(i=0; i<q; i++){
        if(c.at(n) < k.at(i)){
            cout << a.at(n) + k.at(i) - c.at(n) << endl;
        }else{
            ok = 0;
            ng = n;
            while(abs(ok - ng) > 1){
                mid = (ok + ng) / 2;
                if(k.at(i) > c.at(mid)){
                    ok = mid;
                }else{
                    ng = mid;
                }
            }
            cout << a[ok] + k[i] - c[ok] << endl;
        }
    }
    return 0;
}


#include "bits/stdc++.h"
using namespace std;
#define for_(i, s, e) for (int i = s; i < (int) e; i++)
#define for__(i, s, e) for (ll i = s; i < e; i++)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
#define endl '\n'

// if two adjacent nodes have same reachability, then they are in SCC
// now we have a DAG to solve with
// if two adjacent nodes have different reachability, then their direction is easily found
// reduced to making graph SCC by directing edges
// read CF blog post for details on how to do that (is-this-fft)

int n, m;
vector<vector<ii>> adj;
vector<ii> ans;
vi vis;

int dfs(int p, int parent) {
	if (vis[p]) return 1;
	vis[p] = 1;

	for (auto i: adj[p]) if (i.first != parent and ans[i.second].first == -1) {
		int v = dfs(i.first, p);
		// cout << "going edge " << p << " - " << i.first << " ... " << v << endl;
		ans[i.second] = {i.first, p};
		// if (v) ans[i.second] = {p, i.first};
	}

	vis[p] = 2;
	return 0;
}

int main() {
	#ifdef mlocal
	freopen("test.in", "r", stdin);
	#endif

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

	cin >> n >> m;
	vector<ii> edges(m);
	adj.resize(n); ans.resize(m, {-1, -1}); vis.resize(n);

	for_(i, 0, m) {
		int a, b; cin >> a >> b;
		a -= 1; b -= 1;
		adj[a].push_back({b, i}); adj[b].push_back({a, i});
		edges[i] = {a, b};
	}

	vi reach(n);
	for_(i, 0, n) cin >> reach[i];
	for_(i, 0, m) if (reach[edges[i].first] != reach[edges[i].second]) {
		ans[i] = {edges[i].first, edges[i].second};
		if (reach[edges[i].first] < reach[edges[i].second]) ans[i] = {edges[i].second, edges[i].first};
	}

	for_(i, 0, n) if (!vis[i]) dfs(i, i);

	for_(i, 0, m) {
		if (edges[i] == ans[i]) cout << "->";
		else cout << "<-";
		cout << endl;
	}

	return 0;
}

#include <bits/stdc++.h>
typedef long long int ll;
#define INF 1e18
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    ll x;
    cin >>  n >> x;
    vector<int> arr(n);
    for(int i=0;i<n;i++){
        cin >> arr[i];
    }
    ll res=INF;
    for(int k=1;k<=n;k++){

        vector<vector<int>> dp(k+1,vector<int> (k,-1));
        dp[0][0]=0;
        for(int i=1;i<=n;i++){
            for(int j=k;j>=1;j--){
                for(int r=0;r<k;r++){
                    if(dp[j-1][r]==-1){
                        continue;
                    }
                    int next=dp[j-1][r]+arr[i-1];
                    dp[j][next%k]=max(dp[j][next%k],next);
                }
            }
        }
        // cout << "k= " << k << " " << dp[k][x%k] <<  "\n";

        if(dp[k][x%k]!=-1){
            res=min(res,(x-dp[k][x%k])/k);
        }
    }
    cout << res << "\n";
    return 0;
}


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

int main() {
    int A, B, C;
    string win;
    cin >> A >> B >> C;

    if( C == 0) {
        while(1) {
            A--;
            if( A < 0 ) {
                win = "Aoki";
                break;
            }
            B--;
            if( B < 0 ) {
                win = "Takahashi";
                break;
            }
        }
    } else if(C == 1) {
        while(1) {
            B--;
            if( B < 0 ) {
                win = "Takahashi";
                break;
            }
            A--;
            if( A < 0 ) {
                win = "Aoki";
                break;
            }
        }
    }
    cout << win << endl;
    return 0;
}

#include <iostream>
#include <cstdio>
#include<bits/stdc++.h>
using namespace std;
int solve(int a,int b,int c)
{
        if(a==b)
            return c;
        else if(a==c)
            return b;
        else if(b==c)
            return a;
        return 0;
}
int main(){

    int a,b,c;
    cin>>a>>b>>c;
    cout<<solve(a,b,c);

}


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

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

    string s;
    cin >> s;

    int a = count(ALL(s), 'o');
    int b = count(ALL(s), 'x');
    int c = count(ALL(s), '?');

    ll cnt = 0;
    const int ar[5] = {0, 1, 14, 36, 24};

    rep(i, 1 << c) {
        int t = __builtin_popcount(i);
        if(a + t <= 4) cnt += ar[a + t];
    }

    cout << cnt << endl;

    return 0;
}

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

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

int main(){
  string S; cin >> S;
  int ans = 0;
  rep(i,10000){
    int K[4] = {i/1000,i/100%10,i/10%10,i%10};
    int C[10] = {}; rep(t,4) C[K[t]] = 1;
    bool ok = true;
    rep(d,10) if(C[d] == 0 && S[d] == 'o') ok = false;
    rep(d,10) if(C[d] == 1 && S[d] == 'x') ok = false;
    if(ok) ans++;
  }
  cout << ans << "\n";
  return 0;
}

struct ios_do_not_sync{
  ios_do_not_sync(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
  }
} ios_do_not_sync_instance;


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

int main(){
  long long n;
  cin >> n;
  set<long long> ans;
  long long lpn = min(n, 10000000ll);

  for(int i = 1; i <= lpn; i++){
    if(n%i == 0){
      ans.insert(i);
      ans.insert(n/i);
    }
  }

  while(!ans.empty()){
    cout << *begin(ans) << endl;
    ans.erase(*begin(ans));
  }
}

#include<iostream>
using namespace std;

int main(){
    int n;
    cin >> n;
    cout << n - 1 << endl;
}


#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <complex>

using namespace std;

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

int gcd(int a, int b)
{
	while (b != 0) {
		int t = b;
		b = a % b;
		a = t;
	}
	return a;
}

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

	int n, i, j, k, MAXX = 10000, gg;
	set<int> a;
	vector<int> ans, aa;
	for (i = 1; 2 * 3 * i < MAXX; i++) a.insert(2 * 3 * i);
	for (i = 1; 5 * 3 * i < MAXX; i++) a.insert(5 * 3 * i);
	for (i = 1; 2 * 5 * i < MAXX; i++) a.insert(2 * 5 * i);
	a.erase(11 * 2 * 5);
	a.erase(13 * 3 * 5);
	for (auto p : a) aa.push_back(p);

	cin >> n;
	for (i = 0; i < n - 2; i++) ans.push_back(aa[i]);
	ans.push_back(11 * 2 * 5);
	ans.push_back(13 * 3 * 5);

	for (auto p : ans) cout << p << " ";
	cout << "\n";

	gg = ans[0];
	for (i = 0; i < n; i++) {
		gg = gcd(gg, ans[i]);
		for (j = i + 1; j < n; j++) {
			int g = gcd(ans[i], ans[j]);
			if ((ans[i] == ans[j]) || (g == 1))
				break;
		}
	}

	return 0;
}

#include "bits/stdc++.h"
using namespace std;
using li = long long;
const char newl = '\n';
template <class T> vector<vector<T>> vv(const unsigned int n, const unsigned int m, const T x) { return vector<vector<T>>(n, vector<T>(m, x)); }
template <class T> vector<vector<vector<T>>> vvv(const unsigned int n, const unsigned int m, const unsigned int k, const T x) { return vector<vector<vector<T>>>(n, vv(m, k, x)); }
template <class T> bool contains(const set<T>& s, const T& v) { return s.find(v) != s.end(); }
template <class T> bool contains(const unordered_set<T>& s, const T& v) { return s.find(v) != s.end(); }
template <class K, class V> bool contains_key(const map<K, V>& m, const K& v) { return m.find(v) != m.end(); }

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

    li n;
    cin >> n;
    vector<li> as(n), bs(n), ps(n);
    for (int i = 0; i < n; ++i) {
        cin >> as[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> bs[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> ps[i];
        ps[i]--;
    }
    vector<li> wants(n);
    for (int i = 0; i < n; ++i) {
        wants[ps[i]] = i;
    }
    vector<bool> vis(n);
    vector<li> is, js;
    for (int i = 0; i < n; ++i) {
        if (vis[i]) {
            continue;
        }
        vector<li> cycle;
        li pos = i;
        while (!vis[pos]) {
            vis[pos] = true;
            cycle.emplace_back(pos);
            pos = wants[pos];
        }
        if (cycle.size() <= 1) {
            continue;
        }
        li light = bs[ps[pos]];
        li light_arg = 0;
        for (int j = 0; j < cycle.size(); ++j) {
            li c = cycle[j];
            if (light > bs[ps[c]]) {
                light = bs[ps[c]];
                light_arg = j;
            }
        }
        for (auto c : cycle) {
            if (as[c] <= bs[ps[c]]) {
                cout << -1 << endl;
                return 0;
            }
        }
        for (int j = 0; j < cycle.size() - 1; ++j) {
            is.emplace_back(cycle[(light_arg + j) % cycle.size()]);
            js.emplace_back(cycle[(light_arg + j + 1) % cycle.size()]);
        }
    }

    vector<li> qs = ps;
    cout << is.size() << newl;
    for (int i = 0; i < is.size(); ++i) {
        cout << is[i] + 1 << " " << js[i] + 1 << newl;
        swap(qs[is[i]], qs[js[i]]);
    }
//    for (int i = 0; i < n; ++i) {
//        cout << qs[i] << " ";
//    }
    return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
using vii = vector<vector<int>>;
using vi = vector<int>;

int main()
{
    int n, k, m;
    cin >> n >> k >> m;
    vi a(n-1);
    int sum = 0;
    rep(i, n - 1) {
        cin >> a.at(i);
        sum += a.at(i);
    }
    int ans = n * m - sum;
    if (ans > k) {
        ans = -1;
    }
    else if (ans < 0) {
        ans = 0;
    }

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

#include<bits/stdc++.h>
using namespace std;
const int N=100010;

int main(){
   int a,b,w;
   cin>>a>>b>>w;
   int m=1e9,M=0;
   for(int n=1;n<=1e6;n++){
      if(a*n<=1000*w&&1000*w<=b*n){
         m=min(m,n);
         M=max(M,n);

      }
   }
   if(M==0)cout<<"UNSATISFIABLE";
   else cout<<m<<' '<<M;
}


#include <iostream>
using namespace std;
void chmax(double& a, double b){ if(a < b) a = b; }
int main(){
    int N;
    double D, H, ans = 0;
    cin >> N >> D >> H;
    while(N--){
        double d, h;
        cin >> d >> h;
        chmax(ans, h - d * (H - h) / (D - d));
    }
    cout << ans << endl;
}

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

int main(void) {
    int N;
    double D, H;
    cin >> N >> D >> H;
    vector<double> d(N);
    vector<double> h(N);
    rep(i, N) cin >> d[i] >> h[i];

    double ans = 0.0;
    rep(i, N) {
        // 切片を計算する
        double temp = H - (H - h[i]) / (D - d[i]) * D;
        ans = max(ans, temp);
    }

    cout << fixed << setprecision(15) << ans << endl;

    return 0;
}


#include<cstdio>
#define ll long long
ll n;
int main(){
	scanf("%lld",&n);
	for(ll i=3,a=1;i<=n;i*=3,a++)
		for(ll j=5,b=1;j<=n;j*=5,b++)
			if(i+j==n){printf("%d %d",a,b);return 0;}
	printf("-1");
	return 0;
}

#include<bits/stdc++.h>
#define ll          long long
#define ld          long double
#define mod         998244353
#define INF         998244353
#define ull         unsigned long long
#define pb          push_back
#define	endl		'\n'
#define pi          acos(-1)
#define pii         pair<ll int,ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define SIZE(X)     ((int)((X).size()))
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define fo(i,s,n)  for(int i=s;i<n;i++)
#define FORE(i,s,n) for(int i=s;i<=n;i++)
#define rep(i,n) for(int i=0;i<(n);++i)
#define repf(i,a,b) for(int i=(a);i<=(b);++i)
#define ERASE(x)    x.erase(unique(x.begin(),x.end()),x.end()) //removes repeated element;
#define Fast        ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);

using namespace std;
const int N = 2*100010;
vector <ll> is_prime(N+1 , true);
bool sortinrev(const pair<int,int> &a,const pair<int,int> &b){return (a.first > b.first);}
bool sortbysecdesc(const pair<int,int> &a,const pair<int,int> &b){return a.second>b.second;}
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b) {return (a.second < b.second);}
ll powerm(ll a, ll k) { if (!k) {return 1;}ll b = powerm(a, k / 2);b = b * b % INF;if (k % 2) {return a * b % INF;} else {return b;}}
ll int power(ll int a , ll int b) { if(b == 1) return a; if(b == 0) return 1; ll int m1 = power(a,b/2); if(b%2) return m1*m1*a; return m1*m1; }
void seive_of_eras(ll n) { is_prime[0] = 0; is_prime[1] = 0; for(ll i=2;i*i<=n;i++) { if(is_prime[i]) { for(ll j=i*i;j<=n;j+=i) { is_prime[j] = false; } } } }
bool isprime (ll a) { if(a<=1) return false; if(a==2||a==3) return true; if(a%2==0||a%3==0) return false; for(ll i=5;i*i<=a;i=i+6) { if(a%i==0||a%(i+2)==0) return false; } return true;}

void codeit()
{
    //cout<<power(3 , 40)<<endl;
    ll n; cin>>n;
    for(ll i=1;i<=30;i++)
    {
        if(power(5 , i)>1e18)
        {
            break;
        }
        for(ll j=1;j<=39;j++)
        {
            ll k = power(5 , i) + power(3 , j);
            if(k>1e18)
            {
                break;
            }
            if(k==n)
            {
                cout<<j<<" "<<i<<endl;
                return;
            }
        }
    }
    cout<<-1<<endl;
    return;
}

int main()
{
    //Fast
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ll tt; tt = 1;
    //cin>>tt;
    for(ll i=0;i<tt;i++)
        codeit();
}


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

char S[500005];
char T[500005];

priority_queue<int, vector<int>, greater<int> > A;
vector<int> B;

int main(){
    int N;
    scanf("%d", &N);

    scanf(" %s %s", S, T);

    int sizeA = 0;
    for(int i = 0; i < N; i ++){
        if(S[i] == '1'){
            A.push(i);
            sizeA ++;
        }
        if(T[i] == '1'){
            B.push_back(i);
        }
    }

    if(sizeA < (int)B.size()){
        printf("-1");
        return 0;
    }else if( (sizeA-(int)B.size())&1 ){
        printf("-1");
        return 0;
    }

    //long long ans = (sizeA-(int)B.size())>>1;
    long long ans = 0;
    bool boleh = true;
    for(int i = 0; i < (int)B.size(); i ++){
        bool found = false;
        while(!A.empty()){
            int x = A.top();
            if(x >= B[i]){
                ans += x-B[i];
                A.pop();
                //printf("found x=%d B[i]=%d\n", x, B[i]);
                found = true;
                break;
            }else{
                A.pop();
                if(A.empty()){
                    printf("-1");
                    return 0;
                }
                int y = A.top();
                A.pop();
                //printf("found x=%d y=%d\n", x, y);
                ans += y-x;
            }
        }

        if(!found){
            boleh = false;
            break;
        }
    }

    while(!A.empty()){
        int x = A.top();
        A.pop();
        if(A.empty()){
            printf("-1");
            return 0;
        }
        int y = A.top();
        A.pop();
        //printf("lastly, found x=%d y=%d\n", x, y);
        ans += y-x;
    }

    if(!boleh){
        printf("-1");
        return 0;
    }
    printf("%lld", ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<pair<ll,ll> > vpl;//追加はmake_pairを使う
typedef long double ld;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqg; //昇順のPriority queue
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define all(v) v.begin(), v.end()
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;}
#define dbl(i) fixed << setprecision(15) << i << endl;
#define GET_VARIABLE_NAME(Variable) (#Variable)
#define dbc(a) cout << GET_VARIABLE_NAME(a) << "=" << a << endl;
#define vsum(v) accumulate(all(v), 0);
#define rsort(v) sort(v.begin(),v.end(),greater<ll>());
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }
    // 素数である
    return true;
}
vector<ll> enum_divisors(ll N) {//約数列挙
    vector<ll> res;
    for (ll i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            // 重複しないならば i の相方である N/i も push
            if (N/i != i) res.push_back(N/i);
        }
    }
    // 小さい順に並び替える
    sort(res.begin(), res.end());
    return res;
}
vector<pair<long long, long long> > prime_factorize(long long N) {//因数分解
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        pair <ll,ll> push;
        push.first=a;
        push.second=ex;
        res.push_back(push);
    }

    // 最後に残った数について
    if (N != 1){
        pair <ll,ll> push;
        push.first=N;
        push.second=1;
        res.push_back(push);
    }
    return res;
}
ll gcd(ll a, ll b){//最大公約数
        if (a%b == 0){
            return(b);
        }else{
            return(gcd(b, a%b));
        }
    }
ll lcm(ll a, ll b){//最小公倍数
   return a / gcd(a, b) * b;
}
ll comb(ll n, ll r) {
if(n<r) return 0;
  if ( r * 2 > n ) r = n - r;
  ll dividend = 1;
  ll divisor  = 1;
  for ( ll i = 1; i <= r; ++i ) {
    dividend *= (n-i+1);
    divisor  *= i;
  }
  return dividend / divisor;
}
void exgcd(ll a,ll b,ll &x,ll &y)
{
	if(b==0){ x=1;y=0; }
	else{ exgcd(b,a%b,y,x);y-=a/b*x; }
}
ll inv(ll a,ll Mod){//modにおけるaの逆元
	ll x,y;
	exgcd(a,Mod,x,y);
	return (x%Mod+Mod)%Mod;
}
ll RepeatSquaring(ll N, ll P, ll M){
    if(P==0) return 1;
    if(P%2==0){
        ll t = RepeatSquaring(N, P/2, M);
        return t*t % M;
    }
    return N * RepeatSquaring(N, P-1, M);
}
ll rui(ll a,ll n){
    ll x=1;
    while(n>0){
        if(n&1){
            x=x*a;
        }
        a=a*a;
        n>>=1;
    }
    return x;
}
ll f(ll n, vector <string>s){
    if(s[n]=="OR"){
        if(n==0)return 3;
        return rui(2,n+1)+f(n-1,s);
    }else{
        if(n==0)return 1;
        return f(n-1,s);
    }
}
string toBinary(int n)
{
    string r;
    while (n != 0){
        r += ( n % 2 == 0 ? "0" : "1" );
        n /= 2;
    }
    return r;
}

int main(){
    ll n,x;
    cin>>n>>x;
    rep(i,n){
        ll t;
        cin>>t;
        if(t!=x)cout<<t<<" ";
    }
    cout<<endl;
}

#include <bits/stdc++.h>

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

typedef long long          num;

using namespace std;

const int nsz = 2e5;
int n, dfn[nsz + 5];
vector<int> g[nsz + 5];

void bfs(int s, int *d) {
	static int q[nsz + 5];
	int ql = 0, qr = 0;
	cont (u, n) d[u] = -1;
	for (q[qr++] = s, d[s] = 0; ql != qr;) {
		int u = q[ql++];
		for (int v : g[u]) if (d[v] == -1) q[qr++] = v, d[v] = d[u] + 1;
	}
}

void inline find_diameter(vector<int> &nd) {
	static int d[nsz + 5];
	int u = 1, v = 1;
	bfs(1, d);
	cont (v, n) if (d[v] > d[u]) u = v;
	bfs(u, d);
	cont (u, n) if (d[u] > d[v]) v = u;
	for (int w = v; w != u;) {
		nd.push_back(w);
		for (int v : g[w]) if (d[v] == d[w] - 1) {
			w = v;
			break;
		}
	}
	nd.push_back(u);
}

void dfs(int u, int &t, int p1 = -1, int p2 = -1) {
	t += 1;
	dfn[u] = t;
	for (int v : g[u]) if (v != p1 && v != p2) dfs(v, t, u);
	t += 1;
}

void inline solve() {
	vector<int> nd;
	find_diameter(nd);
	int t = 0;
	loop (i, nd.size()) {
		int p1 = i - 1 >= 0 ? nd[i - 1] : -1;
		int p2 = i + 1 < nd.size() ? nd[i + 1] : -1;
		dfs(nd[i], t, p1, p2);
		t -= 1;
	}
}

int main() {
	scanf("%d", &n);
	cont (i, n - 1) {
		int u, v;
		scanf("%d%d", &u, &v);
		g[u].push_back(v), g[v].push_back(u);
	}
	solve();
	cont (u, n) printf("%d%c", dfn[u], "\n "[u < n]);
}


#include<bits/stdc++.h>
#define ll int
#define ld long double
using namespace std;
int main()
{
    #ifndef ONLINE_JUDGE
        freopen ("input.txt" , "r" , stdin);
        // freopen ("OUTPUT.txt" , "w" , stdout);
    #endif
    ll tc=1;
    //cin>>tc;
    while(tc--)
    {
        ll n,w;
        cin>>n>>w;
        cout<<n/w<<endl;
    }
}

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

int main()
{
    int x, y, a, b, temp1, temp2;

    cin >> a >> b;

    x = (a + b) / 2;
    y = a - x;

    cout << x << " " << y << "\n";

    return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<vl> vvl;

double EPS=1e-9;
int INF=1000000005;
long long INFF=1000000000000000005ll;
double PI=acos(-1);
int dirx[8]={ -1, 0, 0, 1, -1, -1, 1, 1 };
int diry[8]={ 0, 1, -1, 0, -1, 1, -1, 1 };
const ll MOD = 1000000007;

ll sum() { return 0; }
template<typename T, typename... Args>
T sum(T a, Args... args) { return a + sum(args...); }

#define DEBUG fprintf(stderr, "====TESTING====\n")
#define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
#define OUT(x) cout << x << endl
#define OUTH(x) cout << x << " "
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define READ(x) for(auto &(z):x) cin >> z;
#define FOR(a, b, c) for (int(a)=(b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a)=(b); (a) <= (c); ++(a))
#define FORD(a, b, c) for (int(a)=(b); (a) >= (c); --(a))
#define FORSQ(a, b, c) for (int(a)=(b); (a) * (a) <= (c); ++(a))
#define FORC(a, b, c) for (char(a)=(b); (a) <= (c); ++(a))
#define EACH(a, b) for (auto&(a) : (b))
#define REP(i, n) FOR(i, 0, n)
#define REPN(i, n) FORN(i, 1, n)
#define MAX(a, b) a=max(a, b)
#define MIN(a, b) a=min(a, b)
#define SQR(x) ((ll)(x) * (x))
#define RESET(a, b) memset(a, b, sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define PERMUTE next_permutation
#define TC(t) while (t--)
#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define what_is(x) cerr << #x << " is " << x << endl;

void solve() {

}

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

//    int tc; cin >> tc;
//    TC(tc) solve();
	int n, a; cin >> n;
	set<int> taken;
	int smallest = 0;
	REP(i,n) {
		cin >> a;
		while(a==smallest||taken.find(smallest)!=taken.end()) smallest++;
		OUT(smallest);
		if(a>=0) taken.insert(a);
	}
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep1(i, n) for(int i=1; i<=(int)(n); i++)
#define rep2(i, n, m) for(int i=(int)n; i<=(int)m; i++)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> wi;
typedef vector<ll> vl;
const ll inf=1LL<<60;
const int MOD=1000000007;
const int mod=998244353;

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

  int n;
  cin >> n;
  vi p(n);
  rep(i, n)cin >> p[i];

  set<int> q;
  rep(i, 200001)q.insert(i);
  int ans=0;
  rep(i, n){
    q.erase(p[i]);
    cout << *q.begin() << endl;
  }

  return 0;
}


#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> //Policy Based Data Structure
// using namespace __gnu_pbds;              //Policy Based Data Structure
using namespace std;
// typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> pbds; //Policy Based Data Structure
// #define gc              getchar_unlocked
// #define pqb             priority_queue<int>
// #define pqs             priority_queue<int, vi, greater<int> >
// #define mk(arr,n,type)  type *arr = new type[n]
#define fo(i,n)         for(i=0;i<n;i++)
#define Fo(i,k,n)       for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define int             long long
#define endl            '\n'
#define w(t)            int t; cin>>t; while(t--)
#define deb(x)          cout << #x << "=" << x << endl
#define deb2(x,y)       cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb              push_back
#define mp              make_pair
#define F               first
#define S               second
#define all(x)          x.begin(), x.end()
#define clr(x)          memset(x, 0, sizeof(x))
#define sortall(x)      sort(all(x))
#define tr(it,a)        for(auto it = a.begin(); it != a.end(); it++)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define PI              3.1415926535897932384626
#define inf             1e18
// mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());  //Random Shuffler
typedef pair<int, int>   pii;
typedef vector<int>     vi;
typedef vector<pii>     vpii;
typedef vector<vi>      vvi;
typedef map<int, int>    mii;
int mpow(int base, int exp);
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
// const int N = 3e5, M = N;
// vi g[N];
//=======================

void sol()
{
    int n;
    cin >> n;
    int  i, a[n], j;
    fo(i, n)cin >> a[i];
    int ans = a[0];
    for ( i = 0; i < n; ++i)
    {   int mi_n = a[i];
        for ( j = i; j < n; j++)
        {
            mi_n = min(mi_n, a[j]);
            ans = max(ans, (j - i + 1) * mi_n);
        }

    }
    cout << ans;
}

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    sol();

    return 0;
}

int mpow(int base, int exp) {
    base %= mod;
    int result = 1;
    while (exp > 0) {
        if (exp & 1) result = (result * base) % mod;
        base = (base * base) % mod;
        exp >>= 1;
    }
    return result;
}

// void ipgraph(int n, int m){
//     int i, u, v;
//     while(m--){
//         cin>>u>>v;
//         g[u-1].pb(v-1);
//         g[v-1].pb(u-1);
//     }
// }
//
// void dfs(int u, int par){
//     for(int v:g[u]){
//         if (v == par) continue;
//         dfs(v, u);
//     }
// }

#include"bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i,m,n) for(ll i=m;i<n;i++)
const ll mod = 1000000007;
const long double pai = 3.14159265358979;
int main() {
	ll n;
	cin >> n;
	vector<long double>a(n);
	rep(i, 0, n)cin >> a[i];
	sort(a.begin(), a.end());
	long double sum = 0;
	rep(i, 0, n)sum += a[i];
	long double ans = sum;
	long double sumcopy = sum;
	long double minus = 0;
	rep(i, 0, n) {
		long double x = a[i] / 2;
		long double sub = 0;
		sub += n * x;
		sub += sum;
		sub -= (2 * x) * (n - i);
		sub -= minus;
		//cout << sub << endl;
		minus += a[i];
		ans = min(ans, sub);
	}
	cout << setprecision(15) << fixed << ans / n << endl;
	return 0;
}


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

const int INF = 1e9;
const long long inf = 1LL<<60;
using ll = long long;
template<int MOD> struct ModInt {
    static const int Mod = MOD; unsigned x; ModInt() : x(0) { }
    ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    int get() const { return (int)x; }
    ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
    ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
    ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
    ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
    ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
    ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
    ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0;
        while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); }
        return ModInt(u); }
    bool operator==(ModInt that) const { return x == that.x; }
    bool operator!=(ModInt that) const { return x != that.x; }
    ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
template<int MOD> ostream& operator<<(ostream& st, const ModInt<MOD> a) { st << a.get(); return st; };
template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
    ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; }
typedef ModInt<1000000007> mint;

mint dp[3000][3001];
ll a[3000];

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int n;
  cin >> n;
  for (int i=0; i<n; i++) {
    cin >> a[i];
  }
  for (int i=0; i<n; i++) {
    dp[i][1] = mint(1);
  }
  for (int i=2; i<=n; i++) {
    ll val = 0;
    unordered_map<int, mint> v;
    for (int j=0; j<n; j++) {
      if (j < i-1) {
        val += a[j];
        v[val%i] += dp[j][i-1];
        continue;
      }
      val += a[j];
      dp[j][i] += v[val%i];
      v[val%i] += dp[j][i-1];
    }
  }
  mint ans = mint(0);
  for (int i=1; i<=n; i++) ans += dp[n-1][i];
  cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;
#define fst first
#define snd second

const int N = 105;
string adj[N];
int n;

bool vis[N];
void dfs(int u) {
  if (vis[u]) return;
  vis[u] = true;
  for (int v = 0; v < n; v++) {
    if (adj[v][u] == '1') dfs(v);
  }
}

int main() {
#ifdef LOCAL_EXEC
//  freopen("sample.in", "r", stdin);
//  freopen("sample.out", "w", stdout);
#else
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#endif
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> adj[i];
  }

  double ans = 0;
  for (int u = 0; u < n; u++) {
    memset(vis, 0, sizeof vis);
    dfs(u);
    int d = 0;
    for (int v = 0; v < n; v++) {
      if (vis[v]) d++;
    }
    ans += 1.0 / d;
  }
  cout << setprecision(10) << fixed << ans << endl;

  return 0;
}

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

#define ll long long
#define tej ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);

#define ve vector<int>
#define vl vector<long long int>
#define vp vector<pair<long long int,long long int>>
#define pb push_back
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define bp pop_back
#define fp pop_front
#define mp make_pair

#define fo(i,n) for(i=0;i<n;i++)
#define unq(v)      unique(v.begin(), v.end())-v.begin()
#define fnd(v,a)    find(v.begin(), v.end(), a)
#define uprb(v,a)   upper_bound(v.begin(), v.end(), a)
#define upra(v,n,a) upper_bound(v, v+n, a)
#define lowb(v,a)   lower_bound(v.begin(), v.end(), a)
#define lowa(v,n,a) lower_bound(v, v+n, a)
#define newuv(v)    v.erase(unique(v.begin(),v.end()),v.end())
#define rev(v)      reverse(v.begin(),v.end())
#define rndshf(v)   random_shuffle(v.begin(),v.end())
#define all(v)      v.begin(),v.end()

// ll po(ll a,ll b,ll m)
// {
// ll t=1;
// while(b>0)
// {
//     if(b%2!=0)
//     {
//         t=(t*a)%m;
//     }
//     a=(a*a)%m;
//     b=b/2;
// }
// return t;
// }
// ll po(ll a,ll b)
// {
// ll t=1;
// while(b>0)
// {
//     if(b%2!=0)
//     {
//         t=(t*a);
//     }
//     a=(a*a);
//     b=b/2;
// }
// return t;
// }
// ll inv(ll a,ll m)
// {
//   return po(a,m-2,m);
// }

// ll vis[100002]={0},x=0;
// vl v[100002];
// ll dfs(ll s)
// {
//   ll c=1,i;
//   if(v[s].size()>2)
//   {

//   }
//   for(i=0;i<v[s].size();i++)
//   {
//     if(vis[v[s][i]]==0)
//     {
//       vis[v[s][i]]=1;
//       c+=dfs(v[s][i]);
//     }
//   }
//   x+=c-1;
//   //cout<<x<<endl;
//   return c;
// }

void solve()
{
  ll n,i,si;
  cin>>n;
  string s;
  vector<char>v;
  cin>>s;
  for(i=0;i<n;i++)
  {
    v.pb(s[i]);
    if(v.size()>=3)
    {
      si=v.size();
      if(v[si-1]=='x'&&v[si-2]=='o'&&v[si-3]=='f')
      {
        v.pop_back();
        v.pop_back();
        v.pop_back();
      }
    }
  }
  cout<<v.size();
}
int main()
{
    tej
    ll t=1;
    //cin>>t;
    while(t--)
    solve();
return 0;
}


//Let's join Kaede Takagaki Fan Club !!
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//#define int long long
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define a first
#define b second
#define fi first
#define sc second
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define all(x) x.begin(),x.end()
#define si(x) int(x.size())

#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif

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

template<class t> using vc=vector<t>;

template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
	return os<<"{"<<p.fi<<","<<p.sc<<"}";
}

template<class t> ostream& operator<<(ostream& os,const vc<t>& v){
	os<<"{";
	for(auto e:v)os<<e<<",";
	return os<<"}";
}

template<class T>
void g(T &a){
	cin >> a;
}
template<class T>
void o(const T &a,bool space=false){
	cout << a << (space?' ':'\n');
}
//ios::sync_with_stdio(false);
const ll mod = 1000000007;//998244353
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
template<class T>
void add(T&a,T b){
	a+=b;
	if(a >= mod) a-=mod;
}
ll modpow(ll x,ll n){
	ll res=1;
	while(n>0){
		if(n&1) res=res*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return res;
}
template<class T> using mat = vc<vc<T>>;

template<class T>
mat<T> operator*(mat<T> a, mat<T> b){
	if(a.empty() || b.empty()) return mat<T>();
	int n = a.size();
	int m = b[0].size();
	int len = a[0].size();
	assert(len == b.size());
	mat<T>ret(n);
	rep(i, n) ret[i] = vc<T>(m);

	rep(i, n) rep(j, len) rep(k, m){
		ll add = (ll)(a[i][j]) * b[j][k];
		add %= mod;
		ret[i][k] += add;
		if(ret[i][k] >= mod) ret[i][k] -= mod;
	}
	return ret;
}

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

	mat<ll>M(n, vc<ll>(n));
	rep(i, n) M[i][i] = 1;

	vc<ll>num(n);
	rep(i, n) cin>>num[i];
	ll rv = modpow(2*m, mod-2);
	rep(i, m){
		int a, b; cin >> a >> b;
		a--; b--;
		M[a][a] -= rv;
		M[b][b] -= rv;
		M[a][b] += rv;
		M[b][a] += rv;
	}
	rep(i, n) rep(j, n) M[i][j] = (M[i][j]%mod+mod)%mod;

	mat<ll>ret(n, vc<ll>(n));
	rep(i, n) ret[i][i] = 1;
	while(k){
		if(k&1) ret = ret*M;
		k >>= 1;
		M = M*M;
	}
	mat<ll>ans(n, vc<ll>(1));
	rep(i, n) ans[i][0] = num[i];
	auto result = ret*ans;
	rep(i, n) o(result[i][0]);
}
signed main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);
	int t; t = 1; //cin >> t;
	while(t--) solve();
}

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define repa(i,a,n) for (long long i = (a); i < (long long)(n); i++)
#define Rrep(i,n) for (long long i = (long long)(n)-1; i >= 0; i--)
#define Rrepa(i,a,n) for (long long i = (long long)(n)-1; i >= a; i--)
using ll = long long;
class Prints {
    class __Prints {
    public:
        __Prints(const char* sep, const char* term) : sep(sep), term(term) {}
        template <class... Args>
        void operator()(const Args&... args) const { print(args...); }
        template <typename T>
        void pvec(const T& vec, size_t sz) const {
            for (size_t i = 0; i < sz; i++)
                std::cout << vec[i] << (i == sz - 1 ? term : sep);
        }
        template <typename T>
        void pmat(const T& mat, size_t h, size_t w) {
            for (size_t i = 0; i < h; i++)
                for (size_t j = 0; j < w; j++)
                    std::cout << mat[i][j] << (j == w - 1 ? term : sep);
        }

    private:
        const char *sep, *term;
        void print() const { std::cout << term; }
        void print_rest() const { std::cout << term; }
        template <class T, class... Tail>
        void print(const T& head, const Tail&... tail) const { std::cout << head, print_rest(tail...); }
        template <class T, class... Tail>
        void print_rest(const T& head, const Tail&... tail) const { std::cout << sep << head, print_rest(tail...); }
    };

public:
    Prints() {}
    __Prints operator()(const char* sep = " ", const char* term = "\n") const { return __Prints(sep, term); }
};
Prints print;
//一次元配列はprint().pvec(vec,要素数);
//二次元配列はprint().pmat(vec,要素数1,要素数2);
using P = pair<ll,ll>;
const ll INF = 2e18;
ll func(ll N,ll K){
    if (N % K == 0) return 0;
    else return K - (N%K);
}
void dijkstra(vector<vector<tuple<ll,ll,ll>>> &road,ll N,ll M,ll X,ll Y){
    vector<ll> dist(N,INF);
    priority_queue<P, vector<P>, greater<P>> que;
    dist[X] = 0;
    que.push(P(0,X));

    while (!que.empty()){
        P p = que.top();que.pop();
        ll v = p.second;
        if (dist[v] < p.first) continue;
        rep(i,road[v].size()){
            ll val = dist[v] + get<1>(road[v][i]) + func(p.first,get<2>(road[v][i]));
            if (dist[get<0>(road[v][i])] > val){
                dist[get<0>(road[v][i])] = val;
                que.push(P(dist[get<0>(road[v][i])],get<0>(road[v][i])));
            }
        }
    }
    cout << (dist[Y]==INF? -1 : dist[Y]) << endl;
}
int main() {
    ll N,M,X,Y;
    cin >> N >> M >> X >> Y;
    X--;
    Y--;
    vector<vector<tuple<ll,ll,ll>>> d(N);
    rep(i,M){
        ll A,B,T,K;
        cin >> A >> B >> T >> K;
        d[A-1].push_back(make_tuple(B-1,T,K));
        d[B-1].push_back(make_tuple(A-1,T,K));
    }
    dijkstra(d,N,M,X,Y);
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <iomanip>
using namespace std;
using ll = long long int;

vector<string> myspliter(const string &s, const char delimiter){
    vector<string> res;
    string part = "";
    for(auto &p: s){
        if(p == delimiter){
            if(part.length() > 0) res.push_back(part);
            part = "";
        }else{
            part += p;
        }
    }
    if(part.length() > 0) res.push_back(part);
    return res;
}

ll transToInt(vector<string> str){
    ll ans = 0;
    ans += stoi(str[0])*10000;
    if(str.size() == 2){
        while(str[1].length() < 4) str[1] += '0';
        ans += stoi(str[1]);
    }
    return ans;
}

ll solve(ll x, ll y, ll r){
    ll ans = 0;
    for(ll i = -2'000'000'000; i <= 2'000'000'000; i += 10000){
        if(r*r-(i-y)*(i-y) < 0) continue;

        ll inner = x;
        ll outer = 4'000'000'000;
        ll border = r*r-(i-y)*(i-y);
        while(outer-inner > 1){
            ll mid = (outer+inner)/2;
            if((mid-x)*(mid-x) <= border) inner = mid;
            else outer = mid;
        }
        ll left = x*2-inner;
        ll right = inner;
        if(left <= 0){
            left = left/10000 - 1;
        }else{
            left = (left-1)/10000;
        }
        if(right < 0){
            right = (right+1)/10000;
        }else{
            right = right/10000 + 1;
        }
        ans += max(right - left - 1, 0LL);
        // if(right > 1 && left < -1) ans++;
        // if(i == 00000) cerr << left << " " << right << " " << inner << endl;
    }
    return ans;
}

int main(){
    string x0, y0, r0;
    cin >> x0 >> y0 >> r0;
    ll x = transToInt(myspliter(x0, '.'));
    ll y = transToInt(myspliter(y0, '.'));
    ll r = transToInt(myspliter(r0, '.'));

    cout << solve(x, y, r) << endl;
    return 0;
}

#ifdef Rahul
#include "RAHUL.h"
#else
#include <bits/stdc++.h>
using namespace std;
#define error(...) 42;
#endif
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
const int MOD = (int) 1e9 + 7;
const i64 INF = (i64) 1e18 + 42;

const long double eps = 1e-9;

int main() {
  cin.tie(nullptr) -> sync_with_stdio(false);
  long double X, Y, r; cin >> X >> Y >> r;
  long double r2 = r * r;
  i64 ans = 0;
  for (int x = int(X - r - 2); x <= int(X + r + 2); ++x) {
    int uy, dy;
    long double dx = (X - x) * (X - x);
    {
      int lo = Y - r - 2, hi = Y;
      while (lo < hi) {
        int md = (lo + hi) >> 1;
        if (dx + (Y - md) * (Y - md) <= r2 + eps) hi = md;
        else lo = md + 1;
      }
      dy = lo;
    }
    {
      int lo = ceil(Y) + eps, hi = Y + r + 2;
      while (lo < hi) {
        int md = (lo + hi + 1) >> 1;
        if (dx + (Y - md) * (Y - md) <= r2 + eps) lo = md;
        else hi = md - 1;
      }
      uy = lo;
    }
    if (dx + (Y - dy) * (Y - dy) > r2 + eps) {
      ++dy;
    }
    if (dx + (Y - uy) * (Y - uy) > r2 + eps) {
      --uy;
    }
    if (uy >= dy) ans += uy - dy + 1;
  }
  kek(ans);
}


#include "bits/stdc++.h"
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, m = 0, n = 0, p = 0, q = 0, mod = 1000000007, pi = 3.1415926535;
    string s1, s2;
    char moji;

    cin >> a;
    cout << (a-1)/100+1 << endl;
    return 0;
}

#include <iostream>
using namespace std;

#include <math.h>

bool IsPrime(int num) {
  if (num < 2)
    return false;
  else if (num == 2)
    return true;
  else if (num % 2 == 0)
    return false; // 偶数はあらかじめ除く

  double sqrtNum = sqrt(num);
  for (int i = 3; i <= sqrtNum; i += 2) {
    if (num % i == 0) {
      // 素数ではない
      return false;
    }
  }

  // 素数である
  return true;
}

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

  long long val = 1;
  for (int i = 2; i <= N; i++) {
    if (IsPrime(i))
      val *= i;
  }

  if (2 * 2 <= N) {
    val *= 2;
  }
  if (2 * 2 * 2 <= N) {
    val *= 2;
  }
  if (2 * 2 * 2 * 2 <= N) {
    val *= 2;
  }
  if (3 * 3 <= N) {
    val *= 3;
  }
  if (3 * 3 * 3 <= N) {
    val *= 3;
  }
  if (5 * 5 <= N) {
    val *= 5;
  }

  cout << val + 1 << endl;
  return 0;
}


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

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

#define speed                       ios_base::sync_with_stdio(0); cin.tie(0);
#define FL(i,a,n)                   for(ll i=a;i<n;i++)
#define even(x)                     (((x)%(2)) == (0))
#define odd(x)                      (((x)%(2)) == (1))
#define meme(x)                     memset(x, 0, sizeof(x))
#define mod                         1000000007
#define onebit(x)                   __builtin_popcountll(x)
#define endl                        "\n"

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

typedef long double                 ld;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<double,double>         pdd;
typedef pair<ld,ld>                 pld;
typedef pair<string , string>       pss;

int main()
{
	int t;
    t=1;
    //cin>>t;
	while(t--)
    {
        ll a,b,k;
        cin>>a>>b>>k;

        while(a>0 && b>0)
        {
            a--;
            b--;
        }

        if(a==0 && b!=0)
        cout<<"Aoki"<<endl;
        else if(b==0 && a!=0)
        cout<<"Takahashi"<<endl;
        else
        {
            if(a==0 && b==0)
            {
                if(k==1)
                cout<<"Takahashi"<<endl;
                else
                {
                    cout<<"Aoki"<<endl;
                }

            }
        }

	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
void __print(int x){cout<<x;}void __print(long x){cout<<x;}
void __print(long long x){cout<<x;}void __print(unsigned x){cout<<x;}
void __print(unsigned long x){cout<<x;}void __print(unsigned long long x){cout<<x;}
void __print(float x){cout<<x;}void __print(double x){cout<<x;}
void __print(long double x){cout<<x;}void __print(char x){cout<<'\''<<x<<'\'';}
void __print(const char *x){cout<<'\"'<<x<<'\"';}void __print(const string &x){cout<<'\"'<<x<<'\"';}
void __print(bool x) {cout<<(x?"true":"false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define lp(i,a,b)       for (ll i=a;i<=b;i++)
#define rp(i,a,b)       for (ll i=a;i>=b;i--)
#define ms(a,x)         memset(a,x,sizeof a)
#define ll              long long
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define rall(a)         a.rbegin(),a.rend()
#define pb              push_back
#define nl              cout<<"\n"
#define gcd(a,b)        __gcd((a),(b))
#define lcm(a,b)        ((a)*(b))/(gcd(a,b))
#define sq(a)           ((a)*(a)*(a))
#define sz(a)           (int) a.size()
#define mod             1000000007
#define PI              (2*acos(0.0))
const ll N=2e5+5;
vector<array<ll,2>> g[N];
ll A[N];
void dfs(ll node,ll p,ll x)
{
  A[node]=x;
  for(auto [adj,cost]:g[node])
  {
    if(adj!=p) dfs(adj,node,x^cost);
  }
}
void solve()
{
  ll n;
  cin>>n;
  lp(i,1,n-1)
  {
    ll a,b,c;
    cin>>a>>b>>c;
    g[a].pb({b,c});
    g[b].pb({a,c});
  }
  dfs(1,-1,0);
  ll res=0;
  lp(i,0,60)
  {
    ll one=0,zero=0;
    lp(j,1,n)
    {
          if(A[j] & 1ll<<i) one++;
          else zero++;
    }
    res=((res)+(1ll<<i)%mod*one%mod*zero%mod)%mod;
  }
  cout<<res;
}

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


#include <bits/stdc++.h>
using namespace std;
#define forr(i,m,n) for (int i=(m); i<=(n); i++)
#define forv(i,m,n) for (int i=(m); i>=(n); i--)
#define forall(it,p) for (auto it = p.begin(); it != p.end(); ++it)
#define R 998244353
#define DBG 1
typedef pair<int,int> pii;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> pl3;

#define MAXN 100000
int a[MAXN];

unordered_map<ll,ll> h;
unordered_map<ll,ll> g;

ll f(int n, int k) {
  if (n==k) return 1;
  if (n<k || k==0) return 0;
  auto p = h.find((n<<16)|k);
  if (p!=h.end()) return p->second;
  ll sm = 0;
  int stt = max(0,2*k-n);
  vector<pl3> q;
  forr(i,stt,k) {
    int nn = n-i;
    int kk = 2*(k-i);
    auto p = g.find((nn<<16)|kk);
    if (p!=g.end()) {
      sm = p->second;
      break;
    } else {
      ll v = f(nn,kk);
      q.push_back(pl3(nn,pll(kk,v)));
    }
  }
  while (q.size()>0) {
      int nn = q.back().first;
      int kk = q.back().second.first;
      ll v = q.back().second.second;
      q.pop_back();
      sm = (sm+v)%R;
      g[(nn<<16)|kk] = sm;
  }
  h[(n<<16)|k] = sm;
  return sm;
}

int main() {
  int n,k;
  cin >> n >> k;
  cout << f(n,k) << endl;
}

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=998244353;
int dp[3005][3005];
signed main(){
	int n,k;
	cin>>n>>k;
	dp[0][0]=1;
	for(int i=1;i<=n;i++){
		for(int j=i;j>=1;j--){
			dp[i][j]=(dp[i-1][j-1]+dp[i][j*2])%mod;
		}
	}
	cout<<dp[n][k];
	return 0;
}


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

const int N = 200005;
const int MOD = 998244353;
int n, sz[N], rt[N], comp;

int get(int u) {
    if (rt[u] == u) {
        return u;
    }
    rt[u] = get(rt[u]);
    return rt[u];
}

void mrg(int u, int v) {
    u = get(u);
    v = get(v);
    if (u == v) {
        return;
    }
    if (sz[v] > sz[u]) {
        swap(u, v);
    }
    comp --;
    rt[v] = rt[u];
    sz[u] += sz[v];
}

int main(int argc, char const *argv[]) {
    cin >> n;
    comp = n;
    for (int i = 1; i <= n; ++i) {
        sz[i] = 1;
        rt[i] = i;
    }
    for (int i = 1; i <= n; ++i) {
        int x;
        cin >> x;
        mrg(i, x);
    }
    int ans = 1;
    for (int i = 0; i < comp; ++i) {
        ans = (2LL * ans) % MOD;
    }
    ans = (1LL * ans + MOD - 1) % MOD;
    cout << ans;
    return 0;
}

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main(void){
    int N, xbuf;
    cin >> N;
    long long D1buf = 0;
    long long D2buf = 0;
    long long D3buf = 0;
    for(int i=0; i<N; i++){
        cin >> xbuf;
        D1buf += abs(xbuf);
        D2buf += (long long)xbuf * xbuf;
        D3buf = max(D3buf, (long long)abs(xbuf));
    }
    cout << D1buf << endl;
    cout << setprecision(10) << sqrtl(D2buf) << endl;
    cout << D3buf << endl;
    return 0;
}


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

#define all(x) (x).begin(), (x).end()
#define dbl(k, x) fixed << setprecision(k) << (x)

template <typename _T>
inline void _DBG(const char *s, _T x) {
  cerr << s << " = " << x << "\n";
}
template <typename _T, typename... args>
void _DBG(const char *s, _T x, args... a) {
  while (*s != ',') cerr << *s++;
  cerr << " = " << x << ',';
  _DBG(s + 1, a...);
}

#define _upgrade                \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)

// ********************** CODE ********************** //

long long f(long long n, long long s) {
  long long x = min(n, s - 1);
  return x - (s - x) + 1;
}

int main() {
  _upgrade;
  long long N, K;
  cin >> N >> K;

  long long res = 0;
  for (long long s = max(K + 2, 2LL); s <= 2 * N; s++) {
    if (s - K >= 2 && s - K <= 2 * N) {
      res += f(N, s) * f(N, s - K);
    }
  }

  cout << res << "\n";
  return 0;
}

#include <bits/stdc++.h>
#define F first
#define S second
#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define bck(i, a, b) if ((i) >= (a) && (i) < (b))
#define trav(x, a) for (auto &x : (a))
#define sz(a) (int)(a).size()
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef string str;
template<typename T> using vec = vector<T>;
template<typename T> using pq = priority_queue<T, vector<T>, std::greater<T>>;
template<typename T> using mxpq = priority_queue<T>;
typedef pair<int,int> pii;
typedef vec<int> vi;
typedef vec<pii> vii;
typedef vec<vi> vvi;
typedef pair<ll,ll> pll;
typedef vec<ll> vl;
typedef vec<pll> vll;
typedef vec<vl> vvl;
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<typename A, typename B>
istream& operator>>(istream& s, pair<A,B>& p) { return s>>p.first>>p.second; }
template<typename T>
istream& operator>>(istream& s, vec<T>& p) {
    for (T& t : p) s >> t;
    return s;
}

#define MOD 1000000007ll

vl mmul(const vl& a, const vl& b, int n) {
    vl r(sz(b));
    rep(i, 0, n) rep(k, 0, n) rep(j, 0, n)
        (r[i*n+j] += a[i*n+k] * b[k*n+j] % MOD) %= MOD;
    return r;
}
vl vmul(const vl& a, const vl& b, int n) {
    vl r(sz(b));
    rep(i, 0, n) rep(j, 0, n)
        (r[i] += a[i*n+j] * b[j] % MOD) %= MOD;
    return r;
}

ll modpow(ll b, ll e, ll mod=MOD) {
    if (e < 0) return modpow(modpow(b, mod-2, mod), -e, mod);
    ll r = 1;
    while (e) {
        if (e & 1) r = r*b % mod;
        b = b*b % mod;
        e /= 2;
    }
    return r;
}

ll modinv(ll n, ll mod=MOD) { return modpow(n, mod-2, mod); }

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll n, m, k; cin >> n >> m >> k;
    vl a(n), mat(n*n); cin >> a;
    rep(i, 0, n) mat[i*n+i] = 1;
    rep(i, 0, m) {
        int x, y; cin >> x >> y; x--, y--;
        (mat[x*n+x] -= modinv(m)*modinv(2) % MOD) %= MOD;
        (mat[y*n+y] -= modinv(m)*modinv(2) % MOD) %= MOD;
        (mat[x*n+y] += modinv(m)*modinv(2) % MOD) %= MOD;
        (mat[y*n+x] += modinv(m)*modinv(2) % MOD) %= MOD;
    }
    trav(v, mat) (v += MOD) %= MOD;
    while (k) {
        if (k & 1) a = vmul(mat, a, n);
        mat = mmul(mat, mat, n);
        k >>= 1;
    }
    trav(v, a) cout << v << endl;
}


#include <bits/stdc++.h>

#define numm ch-48
#define pd putchar(' ')
#define pn putchar('\n')
#define int long long int
using namespace std;

template<typename T>
void read(T &res) {
    bool flag = false;
    char ch;
    while (!isdigit(ch = getchar())) (ch == '-') && (flag = true);
    for (res = numm; isdigit(ch = getchar()); res = (res << 1) + (res << 3) + numm);
    flag && (res = -res);
}

template<typename T>
void write(T x) {
    if (x < 0) putchar('-'), x = -x;
    if (x > 9) write(x / 10);
    putchar(x % 10 + '0');
}

/// #pragma GCC optimize(3,"Ofast","inline")
//////////////////////////////////////////////////////////////////////////////////////////////

int h, w, x, y;
string mp[105];

signed main() {
    cin >> h >> w >> x >> y;
    for (int i = 1; i <= h; i++) {
        cin >> mp[i];
        mp[i] = ' ' + mp[i];
    }
    int ans = 1;
    if (mp[x][y] != '.') {
        write(0), pn;
    }
    int i = 1;
    while (x + i <= h and mp[x + i][y] == '.') ans++, i++;
    i = 1;
    while (x - i > 0 and mp[x - i][y] == '.') ans++, i++;
    i = 1;
    while (y + i <= w and mp[x][y + i] == '.') ans++, i++;
    i = 1;
    while (y - i > 0 and mp[x][y - i] == '.') ans++, i++;
    write(ans);
    return 0;
}

#include <bits/stdc++.h>
#include <iostream>
#include<stdio.h>
#include<math.h>
#include<string.h>
using namespace std;
double mina(double a,double b)
{
    if(a<=b)
    return a;
    return b;
}
double maxa(double a,double b)
{
    if(a<=b)
    return b;
    return a;
}

int main() {
   long long int t,n,i,j,k,l,flag,flag1,count,count1,count2,count3,count4,sum,max1,max2,m,c1,c2,temp,suma,sumb;
  long long int d,e,a,b,c;

  double a2[300001],b1[2002][3],a1[300001];

        //vector< long long int> v1,v2,v;
        //  vector< pair <long long int,long long int> > v3;
  //  string s1,s2,s;
//  char s[300001],s1[300001];
  //  long long int f[100001];
  //   for(i=0;i<100001;i++)
  //    f[i]=0;
    count=0,flag=0,flag1=0,sum=0,max1=0,max2=0,c1=0,c2=0,temp=0,suma=0,sumb=0,count1=0,count2=0,count3=0,count4=0;
  // long long int max3=0,max4=0,ans=0,mina=999999999999999999,c0=0,c3,c4;
   cin>>n;
   for(i=0;i<n;i++)
   {
       for(j=0;j<3;j++)
       cin>>b1[i][j];
   }
   for(i=0;i<n;i++)
   {
       if(b1[i][0]==2)
       b1[i][2]=b1[i][2]-0.1;
      else  if(b1[i][0]==3)
       b1[i][1]=b1[i][1]+0.1;
        if(b1[i][0]==4)
        {
       b1[i][2]=b1[i][2]-0.1;
       b1[i][1]=b1[i][1]+0.1;
        }

   }

   for(i=0;i<n;i++)
   {
       if(b1[i][1]>b1[i][2])
       swap(b1[i][1],b1[i][2]);
   }
   for(i=0;i<n;i++)
   {
       for(j=i+1;j<n;j++)
       {
           if(mina(b1[i][2],b1[j][2]) >=maxa( b1[i][1],b1[j][1]) )
           count++;

       }
   }
   //for(i=0;i<n;i++)
  // for(j=0;j<3;j++)
  // cout<<b1[i][j];
   cout<<count;
	return 0;
}


#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 1e9;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep2(i, x, n) for(int i = x; i < (n); i++)
#define all(n) begin(n), end(n)

void Main() {
    int n;
    cin >> n;
    vector<vector<int>> c(n, vector<int>(n));
    rep(i, n) rep(j, n) cin >> c[i][j];
    vector<int> a(n), b(n);
    a[0] = 0;
    rep(i, n) {
        if(i == 0) {
            rep(j, n) { b[j] = c[i][j] - a[0]; }
        } else {
            int ai = c[i][0] - b[0];
            rep(j, n) {
                if(c[i][j] - b[j] != ai) {
                    cout << "No" << endl;
                    return;
                }
            }
            a[i] = ai;
        }
    }

    int mini = INF;
    rep(i, n) if(a[i] < mini) mini = a[i];
    // cout << mini << endl;
    if(mini < 0) {
        rep(i, n) a[i] -= mini;
        rep(i, n) b[i] += mini;
    }

    mini = INF;
    rep(i, n) if(b[i] < mini) mini = b[i];
    // cout << mini << endl;
    if(mini < 0) {
        rep(i, n) b[i] -= mini;
        rep(i, n) a[i] += mini;
    }

    rep(i, n) if(a[i] < 0 || b[i] < 0) {
        cout << "No" << endl;
        return;
    }

    cout << "Yes" << endl;
    rep(i, n) {
        if(i == n - 1)
            cout << a[i] << endl;
        else
            cout << a[i] << " ";
    }
    rep(i, n) {
        if(i == n - 1)
            cout << b[i] << endl;
        else
            cout << b[i] << " ";
    }
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<stack>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

struct Edge {
  int to;
  long long weight;
  Edge() : to(0), weight(0) {}
  Edge(int to, long long weight) : to(to), weight(weight) {}
  Edge(const Edge& e) {
    to = e.to;
    weight = e.weight;
  }
};

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
using weightedGraph = vector<vector<Edge>>;
using heap = priority_queue<int, vector<int>, greater<int>>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)
#define inf (1<<29)

int main(int argc,char* argv[]){
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
  int n;
  cin >> n;
  vector<vector<ll>> c(n, vector<ll>(n, 0));
  for(int i=0;i<n;i++) {
    for(int j=0;j<n;j++) {
      cin >> c[i][j];
    }
  }
  ll v = INF;
  for(int i=0;i<n;i++) {
    v = min(v, c[i][0]);
  }
  vector<ll> a(n);
  for(int i=0;i<n;i++) {
    a[i] = c[i][0] - v;
  }
  vector<ll> b(n);
  for(int i=0;i<n;i++) {
    ll k = 0;
    for(int j=0;j<n;j++) {
      if(j == 0) {
        k = c[j][i] - a[j];
        continue;
      }
      ll m = c[j][i] - a[j];
      if(k != m) {
        cout << "No" << endl;
        return 0;
      }
    }
    if(k < 0) {
      cout << "No" << endl;
      return 0;
    }
    b[i] = k;
  }
  cout << "Yes" << endl;
  for(int i=0;i<n;i++) {
    cout << a[i];
    if(i != n-1) cout << " ";
  }
  cout << endl;
  for(int i=0;i<n;i++) {
    cout << b[i];
    if(i != n-1) cout << " ";
  }
  cout << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll  long long
#define int ll
#define vi vector<int>
#define pii pair<int,int>
#define piii pair<int, pii>
#define pb push_back
#define fs first
#define sc second
//#define ONLINE_JUDGE
#define endl "\n"
#define pow2(i) (1<<(i))
#define d0(x) cout<<x<<" "
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl
#define d4(x,y,z,w) cout<<x<<" "<<y<<" "<<z<<" "<<w<<endl
#define d5(x,y,z,w,s) cout<<x<<" "<<y<<" "<<z<<" "<<w<<" "<<s<<endl
#define fifo ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define precise(x) cout<<fixed<<setprecision(x)
#define all(v) (v).begin(),(v).end()
const int mod = 1e9+7;

int dig(int x)
{
	int ret = 0;
	while(x)
	{
		x/=10;
		ret++;
	}
	return ret;
}

int po(int x)
{
	if(x==0)return 1;
	return 10*po(x-1);
}
int bin(int l,int r,int n)
{
	if(l==r)return l;
	int m=(l+r+1)/2;

	if(m+m*po(dig(m))<=n)
		return bin(m,r,n);
	else
		return bin(l,m-1,n);

}
void solve()
{
	int n;
	cin>>n;

	if(n<=10)
	{
		cout<<0<<endl;return;
	}
	cout<<bin(1,1000000,n)<<endl;
}

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

    fifo
    int t=1;

    //cin>>t;

    for(ll tc=1;tc<=t;++tc)
    {
        solve();
    }
}

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


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

#define vi vector<int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define vl vector<ll>
#define pii pair<int, int>

void allprime(int n, bool prime[])
{
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
}

void bfs(vi adj[], int src, bool vis[], int level[])
{
	queue<pii> q;
	q.push(mp(src,0));
	vis[src]=true;
	level[src]=0;

	while(!q.empty())
	{
		pii vpair=q.front();
		q.pop();
		int v=vpair.ff;
		int lvl=vpair.ss;

		for(int i=0;i<adj[v].size();i++)
		{
			int next=adj[v][i];
			if(!vis[next])
			{
				q.push(mp(next,lvl+1));
				vis[next]=true;
				level[next]=lvl+1;
			}
		}
	}
}

void dfs(vi adj[], int src, bool vis[])
{
	vis[src]=true;
	for(int i=0;i<adj[src].size();i++)
	{
		int next=adj[src][i];
		if(!vis[next])
		{
			dfs(adj,next,vis);
		}
	}
}

void solve()
{
	// bool vis[6]={false};
	// int level[6];
	// dfs(adj,0,vis);
	// bfs(adj,0,vis,level);
	ll n,k;
	cin>>n>>k;
	if(k<0)
		k*=-1;
	ll ansup, ansdown, ans=0;
	for(int j=2;j<=2*n-k;j++)
	{
		ll up = j+k;
		if(j>n+1)
			ansdown=2*n-j+1;
		else
			ansdown=j-1;
		if(up>n+1)
			ansup=2*n-up+1;
		else
			ansup=up-1;
		// cout<<ansup<<" "<<ansdown<<endl;
		ans+=ansup*ansdown;

	}
	cout<<ans<<endl;
}

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

/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("[DEBUG] ");W(__VA_ARGS__);}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1<<20;
LL N,K;
void solve() {
    LL an=0;
    FOR(i,2,2*N){
        LL need = i-K;
        if(need<2 || need > 2*N)continue;
        an+=min(i-1LL,2*N+1-i)*min(need-1LL,2*N+1-need);
    }
    W(an);
}
void input() {
    R(N,K);
}
int main(){
    input();
    solve();
    return 0;
}


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

using namespace std;
//using namespace atcoder;

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using ld = long double;
using vld = vector<ld>;
using vb = vector<bool>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define dbg(x) true
#endif

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

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

template <class T> ostream& operator<<(ostream& s, const vector<T>& a) {
    for(auto i : a) s << i << ' ';
    return s;
}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

struct mint {
    static const long long mod = 998244353;
    long long x;
    mint(long long 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;}

    friend const mint operator+(const mint& a, const mint& b) { mint ret = a; return ret += b; }
    friend const mint operator-(const mint& a, const mint& b) { mint ret = a; return ret -= b; }
    friend const mint operator*(const mint& a, const mint& b) { mint ret = a; return ret *= b; }
    friend ostream& operator<<(ostream& s, const mint& a) { return s << a.x; }

    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2);}
    mint& operator/=(const mint a) { return (*this) *= a.inv();}
    friend const mint operator/(const mint& a, const mint& b) { mint ret = a; return ret /= b; }
};

void solve() {
    ll n, m, k;
    cin >> n >> m >> k;
    mint ans = 0;
    for(int i = 1; i <= k; ++i) {
        mint a = mint(i).pow(n) - mint(i-1).pow(n); // 1〜iでiを含む
        mint b = mint(k-i+1).pow(m);    // i〜kでiは含まなくて良い
        if(n == 1 || m == 1) b -= mint(k-i).pow(m); // nかmが1だとiを含む
//        cout << i << ' ' << a << ' ' << b << endl;
        ans += a * b;
    }
    cout << ans << endl;
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

// clang-format off
typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define FOREACH(i,c) for(__typeof((c).begin())i = (c).begin();i!=(c).end(); ++i)

//v5
int cond = 1;string to_string(char c){return'\''+string(1,c)+'\'';}string to_string(const string&s){return'"'+s+'"';}string to_string(const char*s){return to_string((string)s);}string to_string(bool b){return(b?"true":"false");}string to_string(std::vector<bool>::reference&r){return to_string((bool)r);}template<typename A,typename B>string to_string(const pair<A,B>&p){return"("+to_string(p.first)+", "+to_string(p.second)+")";}template<typename A>string to_string(A v){int f=1;string r="{";for(auto x:v){if(!f){r+=", ";}f=0;r+=to_string(x);}r+="}";return r;}template<typename A,typename B>string to_string(map<A,B>v){int f=1;string r="{";for(auto x:v){if(!f){r+=", ";}f=0;r+=to_string(x.first)+" -> "+to_string(x.second);}r+="}";return r;}void __db(int i,const vector<string>&s){cerr<<endl;}template<typename T,typename... A>void __db(int i,const vector<string>&s,T t,A... a){if(i)cerr<<", ";cerr<<s[i]<<" = "<<to_string(t);__db(i+1,s,a...);}string __cl(string s){while(!s.empty()&&s[0]==' ')s.erase(0,1);while(!s.empty()&&s.back()==' ')s.pop_back();return s;}vector<string>__vars(string s){vector<string>r;s+=",";string n="";int d=0;for(auto x:s)if(x==','&&d==0){if(!n.empty())r.push_back(__cl(n));n="";}else{n+=x;if(x=='('||x=='[')d++;else if(x==')'||x==']')d--;}return r;}
#define DB(...){if(cond){cerr<<"Line:"<<__LINE__<<" ";__db(0,__vars(#__VA_ARGS__),__VA_ARGS__);}}
// clang-format on

int main() {
  set<LL> s;
  LL n;
  scanf("%lld", &n);
  FOR(i, 1, sqrt(n)) {
    if (n % i == 0) {
      s.insert(i);
      s.insert(n/i);
    }
  }
  for (auto x : s) {
    printf("%lld\n", x);
  }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define SZ(v) ((int)(v).size())
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
typedef long long ll;
typedef unsigned uint;
const int INF=0x3f3f3f3f;
const double EPS=1e-10;
typedef pair<int,int> pii;
int inline in(){int x=0,c;for(;(uint)((c=getchar())-'0')>=10;)
{if(c=='-')return -in();if(!~c)throw ~0;}do{x=(x<<3)+(x<<1)+(c-'0');}
while((uint)((c=getchar())-'0')<10);return x;}

int x;
int main(){
	scanf("%d",&x);
	printf("%d\n",x<0?0:x);
	return 0;
}

#include <iostream>

int main() {
	int x;
  	std::cin >> x;
  	if(x >= 0) std::cout << x;
  	else std::cout << 0;
}


#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define endl "\n"
#define loop(n) for(int i = 0; i<n; ++i)
const int N = 1e3+5;
int n, freq[N], x;
bool permutation = true;
int main()
{
    IOS;
    cin >> n;
    loop(n)
    {
        cin >> x;
        freq[x]++;
    }
    for(int i = 1; i<=n; ++i)
    {
        if(freq[i] != 1)
        {
            permutation = false;
            break;
        }
    }
    if(!permutation) return cout << "No" << endl, 0;
    cout << "Yes" << endl;
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    set<int> S;
    for(int i = 0;i<N;i++){
        int a;
        cin >> a;
        S.insert(a);
    }

    if(N == S.size()) cout << "Yes" <<endl;
    else cout << "No" <<endl;
}


#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

void solve(string s){
    //if(s.size() < 7){cout << -1 << endl; return ;}
    if(s[0] != 'a'){cout << 0 << endl;return;}
    string tar = "atcoder";
    if(s.size() > 7)if(s.substr(0,7) == tar){cout << 0 << endl; return;}
    rep(i,7){
        if(i < s.size()){
            if(s[i] > tar[i]){cout << 0 << endl; return;}
            if(s[i] == tar[i])continue;
            else break;
        }
    }
    rep(i,s.size()){
        if(s[i] != 'a'){
            if(s[i] > 't')cout << i - 1 << endl;
            else cout << i << endl;
            return ;
        }
    }
    cout << -1 << endl;
    //vector<char> can;
    //int ans = inf;
    //rep(i,s.size()){
    //    if(i < tar.size())can.push_back(tar[i]);
    //    int k = inf;
    //    rep(j,can.size()){
    //        if(s[i] > can[j])k = j;
    //    }
    //    if(k != inf){ans = min(ans, i-k);}
    //}
    //if(ans == inf)ans = -1;
    //cout << ans << endl;
    return ;
}

int main(){
    int T;
    cin >> T;
    vector<string> ss(T);
    rep(i,T)cin >> ss[i];
    rep(i,T)solve(ss[i]);
    return 0;
}

#include <iostream>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <bitset>
#include <functional>
#include <random>
#include <cassert>

typedef long long ll;
using namespace std;

const ll mod = 1000000007;
const ll mod998 = 998244353;

int T;

int main() {
	cin >> T;
	while (T--) {
		bool B[4];
		for (int i = 0; i < 4; i++) {
			B[i] = false;
		}
		int N;
		cin >> N;
		string S;
		for (int i = 0; i < 3; i++) {
			cin >> S;
			if (S.front() == '0' && S.back() == '0') {
				B[0] = true;
			}
			if (S.front() == '0' && S.back() == '1') {
				B[1] = true;
			}
			if (S.front() == '1' && S.back() == '0') {
				B[2] = true;
			}
			if (S.front() == '1' && S.back() == '1') {
				B[3] = true;
			}
		}
		if (!B[0]) {
			for (int i = 0; i < N; i++) {
				cout << '0';
			}
			cout << '1';
			for (int i = 0; i < N; i++) {
				cout << '0';
			}
			cout << '\n';
		}
		else if (!B[1]) {
			for (int i = 0; i < N; i++) {
				cout << '0';
			}
			for (int i = 0; i < N; i++) {
				cout << '1';
			}
			cout << '0';
			cout << '\n';
		}
		else if (!B[2]) {
			for (int i = 0; i < N; i++) {
				cout << '1';
			}
			for (int i = 0; i < N; i++) {
				cout << '0';
			}
			cout << '1';
			cout << '\n';
		}
		else {
			for (int i = 0; i < N; i++) {
				cout << '1';
			}
			cout << '0';
			for (int i = 0; i < N; i++) {
				cout << '1';
			}
			cout << '\n';
		}
	}
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll one = 1;
const ll INF = 9223372036854775807; //10^18
const int inINF = 2147483647; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
    int N;
    cin >> N;
    string S, T;
    cin >> S >> T;
    int c = 0, d = 0;
    for (int i = 0; i < N; i++) {
        if(S[i] == '0') c++;
        if(T[i] == '0') d++;
    }
    if(c != d){
        cout << -1 << endl;
        return 0;
    }
    vector<int> A(c), B(c);
    c = 0; d = 0;
    for (int i = 0; i < N; i++) {
        if(S[i] == '0'){
            A[c] = i;
            c++;
        }
        if(T[i] == '0'){
            B[d] = i;
            d++;
        }
    }
    int ans = A.size();
    for (int i = 0; i < A.size(); i++) {
        if(A[i] == B[i]) ans--;
    }
    cout << ans << endl;

}

#include <bits/stdc++.h>
using namespace std;
#define REPP(i,a,b,d) for(int i=(a);i<=(int)(b);i+=(d))
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,d) for(int i=(a);i>=(int)(b);i-=(d))
#define REV(i,a,b) REVV(i,a,b,1)
#define FOR(i,a) for(int i=0; i<(int)(a); i++)
#define FORD(i,a) for(int i=(int)(a)-1; i>=0; i--)
#define pb push_back
typedef long long ll;

const int N = 1e5+5, K = 15;
int n, m, k;
bool trap[N];
pair<long double, long double> E[2*N];

void no() {
	cout << -1 << '\n';
	exit(0);
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n >> m >> k;
	FOR(i, k) {
		int x; cin >> x;
		trap[x] = 1;
	}
	int cnt = 0;
	REP(i, 1, m) cnt += trap[i];
	if(cnt == m) no();
	REP(i, m+1, n) {
		cnt += trap[i] - trap[i-m];
		if(cnt == m) no();
	}

	REP(i, n, n+m-1) E[i] = {0, 0};

	pair<long double, long double> acc = {0, 0};
	REV(i, n-1, 0) {
		if(trap[i]) E[i] = {1, 0};
		else {
			E[i].first += acc.first / (long double)m;
			E[i].second += acc.second / (long double)m;
			E[i].second++;
		}
		acc.first += E[i].first, acc.second += E[i].second;
		acc.first -= E[i+m].first, acc.second -= E[i+m].second;
	}

	cout << fixed << setprecision(4) << -E[0].second / (E[0].first-1) << '\n';

	return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f3f3f3fLL
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll quickpower(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string int_to_string(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int string_to_int(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
int n;
int main()
{
	ios::sync_with_stdio(0);
	cin>>n;
	cout<<(1<<n)-1<<endl;
	forn(i,1,(1<<n)-1)
	{
		rep(j,1<<n)
		{
			if(__builtin_popcount(i&j)%2) cout<<'B';
			else cout<<'A';
		}
		cout<<endl;
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vc = vector<T>;
template<class T> using vvc = vc<vc<T>>;
template<class T> using vvvc = vc<vvc<T>>;
template<class T> using vvvvc = vvc<vvc<T>>;
template<class T> using PQ = priority_queue<T>;
template<class T> using invPQ = priority_queue<T, vector<T>, greater<T>>;
using IP = pair<int, int>;
using LP = pair<ll, ll>;
#define all(x) begin(x), end(x)
#define rep(i, n) for (int i = 0; (i) < (int)(n); i++)
#define rep3(i, m, n) for (int i = (m); (i) < (int)(n); i++)
#define repr(i, n) for (int i = (n) - 1; (i) >= 0; i--)
#define rep3r(i, m, n) for (int i = (n) - 1; (i) >= (int)(m); i--)
template<class T> inline bool chmax(T & a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T & a, T b) { if (a > b) { a = b; return 1; } return 0; }
constexpr long long LINF = 4611686015206162431;

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

    int N;
    cin >> N;
    ll a[2*N];
    vc<int> c(2*N);
    vvc<ll> dogs(3);
    rep (i, N*2) {
        cin >> a[i];
        char col;
        cin >> col;
        if (col == 'G') c[i] = 1;
        else if (col == 'B') c[i] = 2;
        dogs[c[i]].emplace_back(a[i]);
    }
    rep (i, 3) {
        sort(all(dogs[i]));
    }

    int oddcnt = dogs[0].size() % 2 + dogs[1].size() % 2 + dogs[2].size() % 2;
    ll ans = LINF;
    if (oddcnt == 0) ans = 0;
    else {
        int even = 0;
        rep (i, 3) if (dogs[i].size() % 2 == 0) even = i;
        int odd1 = (even + 1) % 3, odd2 = (even + 2) % 3;

        rep (i, dogs[odd1].size()) {
            int pos = lower_bound(all(dogs[odd2]), dogs[odd1][i]) - dogs[odd2].begin();
            if (pos < dogs[odd2].size()) chmin(ans, abs(dogs[odd2][pos] - dogs[odd1][i]));
            if (pos > 0) {
                chmin(ans, abs(dogs[odd2][pos-1] - dogs[odd1][i]));
            }
        }

        ll tmp1 = LINF, tmp2 = LINF;
        rep (i, dogs[odd1].size()) {
            int pos1 = lower_bound(all(dogs[even]), dogs[odd1][i]) - dogs[even].begin();
            if (pos1 < dogs[even].size()) chmin(tmp1, abs(dogs[even][pos1] - dogs[odd1][i]));
            if (pos1 > 0) chmin(tmp1, abs(dogs[even][pos1-1] - dogs[odd1][i]));
        }
        rep (i, dogs[odd2].size()) {
            int pos2 = lower_bound(all(dogs[even]), dogs[odd2][i]) - dogs[even].begin();
            if (pos2 < dogs[even].size()) chmin(tmp2, abs(dogs[even][pos2] - dogs[odd2][i]));
            if (pos2 > 0) chmin(tmp2, abs(dogs[even][pos2-1] - dogs[odd2][i]));
        }
        chmin(ans, tmp1 + tmp2);
    }

    cout << ans << endl;
}


#include <bits/stdc++.h>
// #include <atcoder/all>
// #include "icld.cpp"
using namespace std;
using ll = long long int;
using pii = pair<int,int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using ss = string;
using db = double;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
#define V vector
#define pi 3.14159265358979
#define rep(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define ci(x) cin >> x
#define cii(x) int x;cin >> x
#define cci(x,y) int x,y;cin >> x >> y
#define co(x) cout << x << endl
void chmax(int &x,int y){x=max(x,y);}
void chmin(int &x,int y){x=min(x,y);}

int main(){
  cci(n,m);
  int n2=n/2;

  vi mi(n2),ma(n2),v(n);
  rep(i,0,n)ci(v[i]);
  sort(all(v));

  vi tc(m);
  rep(i,0,m)ci(tc[i]);
  sort(all(tc));

  rep(i,0,n-1)(i%2?ma:mi)[i/2]=v[i+1]-v[i];

  vi smi(n2+1,0),sma(n2+1,0);
  rep(i,0,n2)smi[i+1]=smi[i]+mi[i];
  rep(i,0,n2)sma[n2-i-1]=sma[n2-i]+ma[n2-i-1];

  int ans=1001001001;
  rep(i,0,m){
    int nx=(lower_bound(all(v),tc[i])-v.begin())/2;
    chmin(ans,smi[nx]+abs(v[nx*2]-tc[i])+sma[nx]);
  }
  co(ans);
}

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define ull unsigned long long
#define mp make_pair

void solve()
{
   ll n,m;
   cin>>n>>m;

   vector<ll>v(n);
   ll i,j;
   for(i=0;i<n;i++)cin>>v[i];

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

   vector<ll>form(m);

   for(i=0;i<m;i++)cin>>form[i];
   sort(form.begin(),form.end());

   vector<ll>dp_left(n+1,0);
   ll prev = 0;
   for(i=1;i<n;i=i+2)
   {
      dp_left[i] = prev+ (v[i] - v[i-1]);
      prev = dp_left[i];
   }
   prev = 0;
   vector<ll>dp_right(n+1,0);

   for(i=n-2;i>=0;i=i-2)
   {
       dp_right[i] = prev + (v[i+1]-v[i]);
       prev = dp_right[i];
   }

   ll val = LLONG_MAX;

   for(i=0;i<=n;i++)
   {
       ll low_index,high_index;
       ll left_index, right_index;
       ll diff_index;
       ll low,high;

       if(i%2==0)
       {
           low_index = i-1;
           high_index = i;
           left_index = i-1;
           right_index = i+1;
           diff_index = i;
       }
       else
       {
           low_index = i-1;
           high_index = i;
           left_index = i-2;
           right_index = i;
           diff_index = i-1;
       }

       ll left_max,right_max;
       if(left_index <0)
       {
           left_max = 0;
       }
       else
       {
           left_max = dp_left[left_index];
       }
       if(right_index>=n)
       {
           right_max = 0;
       }
       else
       {
           right_max = dp_right[right_index];
       }

       if(low_index<0)
       {
           low = INT_MIN;
       }
       else
       {
           low = v[low_index];
       }
       if(high_index>=n)
       {
           high = INT_MAX;
       }
       else
       {
           high = v[high_index];
       }

       ll ans = INT_MAX;

       //cout<<low<<" "<<high<<endl;
       //cout<<diff_index<<endl;

       if(i%2==0)
       {
           ll ub = upper_bound(form.begin(),form.end(),high)-form.begin();
           ub--;
           if(ub<form.size() && ub>=0)
           {
               ans = min(ans, abs(v[diff_index] - form[ub]));
           }
       }
       else
       {
           ll lb = lower_bound(form.begin(),form.end(),low)-form.begin();
           if(lb<form.size() && lb>=0)
           {
               ans = min(ans, abs(v[diff_index] - form[lb]));
           }
       }
       //cout<<ans<<endl;
       ans +=left_max;
       ans += right_max;
       //cout<<ans<<endl;
       val = min(ans, val);
   }
   cout<<val<<endl;

}

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

    int t =1;

    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
#define PI 3.141592653589793
#define MOD 1000000007
//#define MOD 998244353
#define ALL(obj) (obj).begin(),(obj).end()
const ll INF = 1LL << 60;
//四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};

struct edge{//グラフに使うヤツ
    ll from,to,cost;
};

typedef vector<vector<edge> > G;

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

ll myPow(ll x,ll n,ll m){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(){
    ll h,w;
    cin >> h >> w;
    string s[h];
    for (ll i=0;i<h;i++)cin >> s[i];
    ll tate[h][w],yoko[h][w];
    memset(tate,-1,sizeof(tate));
    memset(yoko,-1,sizeof(yoko));
    ll lc=0;
    for (ll i=0;i<h;i++){
        for (ll j=0;j<w;j++){
            ll c=0,f=j;
            for (ll k=j;s[i][k]=='.' and k<w;k++){
                c++;
                f=k;
                lc++;
            }
            for (ll k=j;k<=f;k++){
                yoko[i][k]=c;
            }
            j=f;
        }
    }
    for (ll i=0;i<w;i++){
        for (ll j=0;j<h;j++){
            ll c=0,f=j;
            for (ll k=j;s[k][i]=='.' and k<h;k++){
                c++;
                f=k;
            }
            for (ll k=j;k<=f;k++){
                tate[k][i]=c;
            }
            j=f;
        }
    }
    ll ans=0;
    ll lcm=myPow(2,lc,MOD),inv=modinv(2,MOD);
    int ni[h+w+10];
    ll a=1;
    for (ll i=0;i<h+w+5;i++){
        ni[i]=a;
        a*=2;
        a%=MOD;
    }
    for (ll i=0;i<h;i++){
        for (ll j=0;j<w;j++){
            if (s[i][j]=='.'){
                ll c=tate[i][j]+yoko[i][j]-1;
                c=ni[c];
                ll x=(c-1)*lcm%MOD;
                x*=modinv(c,MOD);
                x%=MOD;
                ans+=x;
                ans%=MOD;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;
const int M = 300005;
int read()
{
	int x=0,f=1;char c;
	while((c=getchar())<'0' || c>'9') {if(c=='-') f=-1;}
	while(c>='0' && c<='9') {x=(x<<3)+(x<<1)+(c^48);c=getchar();}
	return x*f;
}
int n,m,tot,f[M],dis[M];
struct edge
{
    int v,c,next;
}e[10*M];
struct node
{
    int u,c;
    bool operator < (const node &R) const
    {
        return c>R.c;
    }
};
int id(int x,int y)
{
    return (x-1)*m+y;
}
void add(int u,int v,int c)
{
    e[++tot]=edge{v,c,f[u]},f[u]=tot;
}
void dijk()
{
    priority_queue<node> q;
    memset(dis,0x3f,sizeof dis);
    q.push(node{1,0});dis[1]=0;
    while(!q.empty())
    {
        int u=q.top().u,t=q.top().c;q.pop();
        if(t>dis[u]) continue;
        for(int i=f[u];i;i=e[i].next)
        {
            int v=e[i].v,c=e[i].c;
            if(dis[v]>dis[u]+c)
            {
                dis[v]=dis[u]+c;
                q.push(node{v,dis[v]});
            }
        }
        int x=(u-1)/m+1,y=(u-1)%m+1;
        for(int i=1;i<x;i++)
        {
            int v=id(x-i,y),c=i+1;
            if(dis[v]>dis[u]+c)
            {
                dis[v]=dis[u]+c;
                q.push(node{v,dis[v]});
            }
        }
    }
}
signed main()
{
    n=read();m=read();
    for(int i=1;i<=n;i++)
        for(int j=1;j<m;j++)
        {
            int x=read();
            add(id(i,j),id(i,j+1),x);
            add(id(i,j+1),id(i,j),x);
        }
    for(int i=1;i<n;i++)
        for(int j=1;j<=m;j++)
        {
            int x=read();
            add(id(i,j),id(i+1,j),x);
        }
    dijk();
    printf("%d\n",dis[id(n,m)]);
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,a,b) for(int i=a;i<=b;i++)
inline ll r() {
	ll x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c))x=x*10+c-'0',c=getchar();
	return x*f;
}
#define d r()
ll a,b,c;
int main(){
	a=d,b=d,c=d;
	printf("%lld",((a*(a+1)/2)%998244353)*((b*(b+1)/2)%998244353)%998244353*((c*(c+1)/2)%998244353)%998244353);
	return 0;
}


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

int main(){
  int h, w;
  cin >> h >> w;
  int v = 1000;
  int a[h][w];
  rep(i,h) {
    rep(j,w) {
      cin >> a[i][j];
      v = min(v,a[i][j]);
    }
  }
  int ans = 0;
  rep(i,h) {
    rep(j,w) {
      ans += a[i][j] - v;
    }
  }
  cout << ans << endl;
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
int h,w,ans,a[10001],minm=101;
int main(){
	scanf("%d%d",&h,&w);
	for(int i=1;i<=h*w;i++){
		scanf("%d",&a[i]);
		minm=min(minm,a[i]);
	}
	sort(a+1,a+h*w+1);
	int x=min(minm,a[(h*w+1)>>1]);
	for(int i=1;i<=h*w;i++)ans+=a[i]-x;
	printf("%d\n",ans);
}


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

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll a,b,c;
	cin>>a>>b>>c;
	if(a==b)
		cout<<c;
	else if(b==c)
		cout<<a;
	else if(a==c)
		cout<<b;
	else
		cout<<0;
	return 0;
}

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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    set<int> set;
    set.insert(a);
    set.insert(b);
    set.insert(c);
    if (set.size() == 3)
        cout << 0 << endl;
    else {
        if (a == b)
            cout << c << endl;
        else if (a == c)
            cout << b << endl;
        else
            cout << a << endl;
    }
}