#include <iostream>
int a[100];
int b[100];
int used[200];
int main() {
    int n;
    std::cin >> n;
    for (int i = 0; i < n; ++i) {
        std::cin >> a[i] >> b[i];
        if (a[i] != -1) ++used[a[i] - 1];
        if (b[i] != -1) ++used[b[i] - 1];
        if (a[i] != -1 and b[i] != -1 and a[i] >= b[i]) {
            std::cout << "No\n";
            return 0;
        }

        if (a[i] != -1 and used[a[i] - 1] == 2) {
            std::cout << "No\n";
            return 0;
        }

        if (b[i] != -1 and used[b[i] - 1] == 2) {
            std::cout << "No\n";
            return 0;
        }
    }
    int ilen, jlen, idx;
    for (int i = 0; i < n; ++i) {
        for (int j = i - 4; j < n; ++j) {
            if (i == j) continue;
            if (j < 0) continue;
            if (a[i] == -1 or b[i] == -1) continue;
            if (a[i] <= a[j] and a[j] <= b[i] and a[i] <= b[j] and b[j] <= b[i]) {
                std::cout << "No\n";
                return 0;
            }

            if (b[j] != -1) {
                if (a[i] <= a[j] and a[j] <= b[i]) {
                    ilen = b[i] - a[i] + 1;
                    jlen = b[j] - a[j] + 1;
                    if (ilen != jlen) {
                        std::cout << "No\n";
                        return 0;
                    }
                }
            } else {
                if (a[i] <= a[j] and a[j] <= b[i]) {
                    ilen = b[i] - a[i];
                    idx = a[j] + ilen - 1;
                    if (idx < 0 or 2 * n <= idx or used[idx] == 1) {
                        std::cout << "No\n";
                        return 0;
                    }
                }
            }

            if (a[j] != -1) {
                if (a[i] <= b[j] and b[j] <= b[i]) {
                    ilen = b[i] - a[i] + 1;
                    jlen = b[j] - a[j] + 1;
                    if (ilen != jlen) {
                        std::cout << "No\n";
                        return 0;
                    }
                }
            } else {
                if (a[i] <= b[j] and b[j] <= b[i]) {
                    ilen = b[i] - a[i];
                    idx = b[j] - ilen - 1;
                    if (idx < 0 or 2 * n <= idx or used[idx] == 1) {
                        std::cout << "No\n";
                        return 0;
                    }
                }
            }
        }
    }
    std::cout << "Yes\n";
}

#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<functional>
#include<string>
#include<numeric>
#include<cstring>
#include<random>
#include<array>
#include<fstream>
#include<iomanip>
#include<list>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
#include<queue>

/*
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
*/

using namespace std;

using ll = long long;
using ull = unsigned long long;

#define REP(i,a,b) for(ll i = a; i < b; ++i)
#define PRI(s) std::cout << s << endl
#define PRIF(v, n) printf("%."#n"f\n", (double)v)

template<typename A, typename B>void mins(A& a, const B& b) { a = min(a, (A)b); };
template<typename A, typename B>void maxs(A& a, const B& b) { a = max(a, (A)b); };

int main() {
	ll N; cin >> N;
	vector<ll> A(N), B(N);
	REP(i, 0, N) cin >> A[i] >> B[i];

	vector<ll> T(2 * N + 1, 0);
	REP(i, 0, N) {
		if (A[i] != -1) {
			if (T[A[i]] != 0) {
				PRI("No");
				return 0;
			}

			T[A[i]] = i+1;
		}
		if (B[i] != -1) {
			if (T[B[i]] != 0) {
				PRI("No");
				return 0;
			}

			T[B[i]] = -(i+1);
		}
		if (A[i] != -1 && B[i] != -1 && B[i] <= A[i]) {
			PRI("No");
			return 0;
		}
	}

	vector<ll> dp(2 * N + 1, false);
	dp[0] = true;
	REP(i, 0, 2 * N) {
		if (!dp[i]) continue;

		for (int k = i + 2; k <= 2 * N; k += 2) {
			int d = (k - i) / 2;

			bool ok = true;
			for (int j = i + 1; j <= k; j++) {
				if (T[j] > 0 && (j + d > 2 * N || (T[j + d] != 0 && T[j] != -T[j + d]))) {
					ok = false;
					break;
				}
				if (T[j] < 0 && (j - d <= i || (T[j - d] != 0 && T[j - d] != -T[j]))) {
					ok = false;
					break;
				}
			}
			if (!ok) continue;

			dp[k] = true;
		}
	}

	if (dp[2 * N]) PRI("Yes");
	else PRI("No");

	return 0;
}


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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#define itrout(x) for(int i=0;i<x.size();i++) {cout << x[i] << (i==x.size()-1 ? "\n" : " ");}
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define debugbit(x, n) cerr << #x << " = " << bitset<n>(x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define debugbit(x, n)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long
//using mint = atcoder::modint;

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

ll merge_cnt(vector<ll> &a) {
    int n = a.size();
    if (n <= 1) { return 0; }

    ll cnt = 0;
    vector<ll> b(a.begin(), a.begin()+n/2);
    vector<ll> c(a.begin()+n/2, a.end());

    cnt += merge_cnt(b);
    cnt += merge_cnt(c);

    int ai = 0, bi = 0, ci = 0;
    // merge の処理
    while (ai < n) {
        if ( bi < b.size() && (ci == c.size() || b[bi] <= c[ci]) ) {
            a[ai++] = b[bi++];
        } else {
            cnt += n / 2 - bi;
            a[ai++] = c[ci++];
        }
    }
    return cnt;
}

void solve(long long N, std::vector<long long> a){
    auto A = a;
    ll current = merge_cnt(A);
    rep(i,0,N) {
        cout << current << endl;
        current -= a[i];
        current += N - a[i] - 1;
    }
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N-1-0+1);
    for(int i = 0 ; i < N-1-0+1 ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, std::move(a));
    return 0;
}

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

int main(){
  int N;  cin >> N;
  vector<int>A(N);
  vector<int>B(N);
  for(int i=0; i<N; i++){
    cin >> A[i];
  }
  for(int i=0; i<N; i++){
    cin >> B[i];
  }
  int ans = 100000000;
  ans = min(ans, B[0]- A[0] + 1);
  for(int i=1; i<N; i++){
    if(A[i-1] < A[i] && B[i-1] < B[i] ){
      B[i] = B[i-1];
      ans = min(ans, B[i]-A[i]+1);
    }else if(A[i-1] >= A[i] && B[i-1] < B[i]){
      A[i] = A[i-1];
      B[i] = B[i-1];
      ans = min(ans, B[i]-A[i]+1);
    }
    else if(A[i-1] >= A[i] && B[i-1] >= B[i]){
      A[i] = A[i-1];
      ans = min(ans, B[i]-A[i]+1);
    }else{
      ans = min(ans, B[i]-A[i]+1);
    }
  }
  if(ans>=1){
    cout << ans << endl;
  }
  else{
    cout << 0 << endl;
  }
}


/*
    __  ___        __
   /  |/  /____   / /_ ____   _____ ____ _ _____
  / /|_/ // __ \ / __// __ \ / ___// __ `// ___/
 / /  / // /_/ // /_ / /_/ // /   / /_/ /(__  )
/_/  /_/ \____/ \__/ \____//_/    \__,_//____/
*/

#ifndef __AHA__HEADER
#define __AHA__HEADER

#include <bits/stdc++.h>
using namespace std;
#define g0 get<0>
#define g1 get<1>
#define g2 get<2>
#define ft first
#define sd second
#define sz(x) (i6) x.size()
#define psb(x) push_back(x)
#define ppb() pop_back()
#define bg(x) x.begin()
#define ed(x) x.end()
#define col(x) x.begin(), x.end()
#define srt(x) sort(x.begin(), x.end())
#define vec vector
#define deq deque
#define hmap unordered_map
#define pq priority_queue
#define fn function
#ifdef LOCAL
#define git stauDBG_MACRO_NO_WARNING
#include <dbg.h>
#define dbgt dbg(dbg::time())
#else
#define dbg(...)
#define dbgt
#endif
typedef string str;
typedef int32_t i3;
typedef int64_t i6;
typedef int64_t i64;
typedef uint32_t u3;
typedef uint64_t u6;
typedef long double d6;
typedef pair<i6, i6> p6;
typedef vec<i6> vi6;
typedef vec<p6> vp6;
typedef vec<bool> vb;
typedef vec<vi6> vv;
typedef deq<p6> dp6;
typedef deq<i6> di6;
typedef map<i6, i6> mi6;
typedef map<p6, i6> mp6;
typedef set<i6> si6;
typedef hmap<i6, i6> hi6;
typedef vv graph;
typedef vv matrix;

const i6 INF = INT64_MAX / 4;
const i6 NINF = -INF;
const i6 ZERO = 0;
const i6 ONE = 1;

#endif

void build_prt(i6 p, i6 crt, vv& tree, vi6& prt) {
  for (auto& c : tree[crt]) {
    if (c != p) {
      prt[c] = crt;
      build_prt(crt, c, tree, prt);
    }
  }
}

void dfs(i6 p, i6 crt, i6 val, vv& tree, vi6& vals, vi6& ans) {
  ans[crt] = val + vals[crt];
  for (auto& c : tree[crt]) {
    if (c != p) {
      dfs(crt, c, ans[crt], tree, vals, ans);
    }
  }
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifdef LOCAL
  ifstream cin{"input.txt"};
  ofstream cout{"output.txt"};
#endif
  i6 n;
  cin >> n;
  vp6 edges(n);
  vv tree(n + 1, vi6());
  for (i6 i = 0; i < n - 1; i++) {
    i6 x, y;
    cin >> x >> y;
    edges[i] = {x, y};
    tree[x].push_back(y);
    tree[y].push_back(x);
  }
  vi6 prt(n + 1, -1);
  build_prt(-1, 1, tree, prt);
  prt[1] = 1;
  i6 q;
  cin >> q;
  vi6 vals(n + 1, 0);
  for (int i = 1; i <= q; i++) {
    i6 t, e, x;
    cin >> t >> e >> x;
    auto crtp = edges[e - 1];
    if (t == 1) {
      if (prt[crtp.ft] != crtp.sd) {
        vals[1] += x;
        vals[crtp.sd] -= x;
      } else {
        vals[crtp.ft] += x;
      }
    } else {
      if (prt[crtp.sd] != crtp.ft) {
        vals[1] += x;
        vals[crtp.ft] -= x;
      } else {
        vals[crtp.sd] += x;
      }
    }
  }
  vi6 ans(n + 1, 0);
  dfs(-1, 1, 0, tree, vals, ans);
  for (i6 i = 1; i <= n; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

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

using namespace std;
typedef long long ll;
const ll INF = 1e18;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n; cin >> n;
    vector<ll> x(n), c(n);
    vector<ll> l(n+2, INF), r(n+2, -INF);
    for(int i = 0; i < n; i++) {
        cin >> x[i] >> c[i];
        chmin(l[c[i]], x[i]);
        chmax(r[c[i]], x[i]);
    }
    l[0] = 0, r[0] = 0;
    l[n+1] = 0, r[n+1] = 0;
    vector<vector<ll>> dp(n+2, vector<ll>(2, INF));
    int pre = 0;
    dp[0][0] = 0;
    dp[0][1] = 0;
    for(int i = 1; i <= n+1; i++){
        if(l[i] == INF) continue;
        chmin(dp[i][0], dp[pre][0]+abs(r[i]-l[pre])+abs(l[i]-r[i]));
        chmin(dp[i][0], dp[pre][1]+abs(r[i]-r[pre])+abs(l[i]-r[i]));
        chmin(dp[i][1], dp[pre][0]+abs(l[i]-l[pre])+abs(l[i]-r[i]));
        chmin(dp[i][1], dp[pre][1]+abs(l[i]-r[pre])+abs(l[i]-r[i]));
        pre = i;
    }
    cout << dp[n+1][0] << endl;
}


#include<bits/stdc++.h>
#include<string>

using namespace std;

#define ll long long int
#define ld long double
#define pb push_back
#define all(v) v.begin(),v.end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define deb(x) cout<< #x << '=' << x <<endl
#define MOD 1000000007

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

    string s;
    cin>>s;
    int n = sz(s);
    for(int i = 104; i <= 1000; i += 8){
        string t = to_string(i);
        bool flag = 0;
        vector<int> vis(n , 0);
        for(int j = 0; j < sz(t); j++){
            bool ok = 0;
            for(int k = 0; k < n; k++){
                if(t[j] == s[k] && !vis[k]){
                    ok = 1;
                    vis[k] = 1;
                    break;
                }
            }
            if(!ok){
                flag = 1;
            }
        }
        if(!flag){
            cout<<"Yes\n";
            return 0;
        }
    }
    if(n == 2){
        for(int i = 16; i <= 100; i += 8){
            string t = to_string(i);
            bool flag = 0;
            vector<int> vis(n , 0);
            for(int j = 0; j < sz(t); j++){
                bool ok = 0;
                for(int k = 0; k < n; k++){
                    if(t[j] == s[k] && !vis[k]){
                        ok = 1;
                        vis[k] = 1;
                        break;
                    }
                }
                if(!ok){
                    flag = 1;
                }
            }
            if(!flag){
                cout<<"Yes\n";
                return 0;
            }
        }
    }
    if(n == 1){
        if(s[0] == '8'){
            cout<<"Yes\n";
            return 0;
        }
    }
    cout<<"No\n";
    return 0;
}

#include <iostream>
#include <math.h>
#include <algorithm>
#include <queue>
#include <map>
#include <list>
//#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
typedef long long ll;

bool solve(string s) {
    if(s.size() == 1) return s == "8";
    if(s.size() == 2){
        if(stoi(s) % 8 == 0) return 1;
        swap(s[0], s[1]);
        return stoi(s) % 8 == 0;
    }
    vector<int> cnt(10);
    FOR (i, 0, s.size()) {
        int si = s[i] - '0';
        cnt[si]++;
    }
    int lenofs = s.size();
    FOR (i, 13, 125) {
        vector<int> tmp = cnt;
        int a = 8 * i;
        string b = to_string(a);

        for (auto bi : b) {
            int bj = bi - '0';
            tmp[bj]--;
        }
        int cnt_less_than0 = 0;
        for (auto x : tmp) {
            if (x < 0) cnt_less_than0++;
        }
        if (cnt_less_than0 > 0)continue;
        else {
            return true;
        }
    }
    return false;
}

int main(){
    string s;
    cin >> s;
    string ans = solve(s) ? "Yes" : "No";
    cout << ans << endl;
    return 0;
}


/**
 *    Author:  Oak_limy
 *    Created: 2020-11-15 01:26:42
 *    Wish you and me a better future.
**/
#include <bits/stdc++.h>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define zy -2147382637
#define bql 2147483647
#define ll long long
#define ull unsigned long long
#define ld long double
#define il inline
#define sz(x) x.size()
#define maxn 100010
#define rp(i, l, r) for (int i = l; i <= r; i++)
#define rb(i, r, l) for (int i = r; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;
ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
ll lowbit(ll x){return x&(-x);}
ll prime(ll x){
   if(x<=1)return false;
   for(int i=2;i<=int(sqrt(x));i++){
	   if(x%i==0)return false;
   }return true;
}
bool cmp(ll a,ll b){return a>b;}
ll gcd(ll a,ll b){ll r;while(b>0){r=a%b;a=b;b=r;}return a;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
inline int readint() {
	int f=1,x=0; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
    while(ch<='9'&&ch>='0') x=x*10+ch-'0',ch=getchar();
    return f*x;
}
inline ll readll() {
	ll f=1,x=0; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
    while(ch<='9'&&ch>='0') x=x*10+ch-'0',ch=getchar();
    return f*x;
}
void fl(string name){
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
}
const int dx[8] = {-1, 1, 0, 0, -1, 1, -1, 1},
		  dy[8] = {0, 0, -1, 1, -1, -1, 1, 1};
#define MAXN 110
ll n,dp[MAXN][MAXN];
double ans;
char s[MAXN];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>(s+1);
		for(int j=1;j<=n;j++){
			dp[i][j]=(s[j]=='1');
		}
		dp[i][i]=1;
	}
	for(int k=1;k<=n;k++){
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				if(dp[i][k]&&dp[k][j]){
					dp[i][j]=1;
				}
			}
		}
	}
	for(int i=1;i<=n;i++){
		ll cnt=0;
		for(int j=1;j<=n;j++){
			if(dp[j][i])cnt++;
		}
		ans=ans+1.0/cnt*1.0;
	}
	printf("%.10lf\n",ans);
	return 0;
}
/* stuff to remember
	* int overflow, array bounds
	* special cases (n=1? n=0?)
	* do something instead of nothing and stay organized
	* USE STATIC ARRAYS
	* DEFINING ARRAYS BEFORE main()
	* DO NOT DEFINE ARRAYS IN main()
	* USE INT INSTEAD OF LL,NOTICE THE MLE
*/

#include <bits/stdc++.h>
using namespace std;
// clang-format off
// #include <atcoder/all>
// using namespace atcoder;
// using mint = modint1000000007;
// using mint = modint998244353

using ll = int64_t;
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
    for (auto& a : v) cin >> a;
    return is;
}
template <class T>
istream& operator>>(istream& is, vector<pair<T, T>>& v) {
    for (auto& a : v) cin >> a.first >> a.second;
    return is;
}
template <class T>
istream& operator>>(istream& is, vector<tuple<T, T, T>>& v) {
    for (auto& a : v) {
        T a1, a2, a3;
        cin >> a1 >> a2 >> a3;
        a = {a1, a2, a3};
    }
    return is;
}
template<typename T>
istream& operator>>(istream &is, complex<T>& c) {
    double x, y;
    is >> x >> y;
    c.real(x);
    c.imag(y);
    return is;
}
template <class T>
ostream& operator<<(ostream& os, vector<T>& v) {
    for (auto& a : v) os << a << " ";
    os << endl;
    return os;
}
template<class T>
bool chmin(T &a, T b) {
    if (a > b) { a = b; return true; }
    return false;
}
template<class T>
bool chmax(T &a, T b) {
    if (a < b) { a = b; return true; }
    return false;
}
#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)
#define TRC1(a) cout << #a ":" << a
#define TRC2(a, b) TRC1(a); cout << " "; TRC1(b)
#define TRC3(a, b, c) TRC2(a, b); cout << " "; TRC1(c)
#define TRC4(a, b, c, d) TRC3(a, b, c); cout << " "; TRC1(d)
#define GET_NAME(_1,_2,_3,_4,NAME,...) NAME
#define TRC(...) GET_NAME(__VA_ARGS__, TRC4, TRC3, TRC2, TRC1) (__VA_ARGS__) << endl
using veci = vector<int>;
using vecll = vector<ll>;
using Pi = pair<int, int>;
using Ti = tuple<int, int, int>;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
const int IINF = INT32_MAX;
const ll LINF = INT64_MAX;

// cout << fixed << setprecision(15);
void solve();
int main() {
    cin.tie(0); ios::sync_with_stdio(0);
    cout << fixed << setprecision(15); solve(); return 0; }
// clang-format on

void solve() {
    ll K;
    cin >> K;
    ll ans = 0;
    for (ll a = 1; a <= K; ++a) {
        for (ll b = 1; b <= K / a; ++b) {
            ll c = K / (a * b);
            ans += c;
        }
    }
    cout << ans << endl;
}


# include <cstdio>
# define ef else if

namespace Main {
    namespace Source {
        typedef short unsigned int hu;
        typedef unsigned int uint;
        static inline const void swap(hu& a, hu& b) { hu c(a); a = b, b = c; }
    }
    using namespace Source;
    namespace Testcase {
        enum { N = 500 };
        static hu n;
        static hu p[N + 1];
        static uint m, inv;
        static hu a[N * N + 1];
        static inline const void operate(const hu n)
        { p[n] < p[n + 1] ? ++inv : --inv, swap(p[n], p[n + 1]), a[++m] = n; }
        static inline const void main() {
            scanf("%hu", &n), m = 0, inv = 0;
            for (hu i(1); i <= n; ++i) scanf("%hu", &p[i]);
            for (hu i(1); i <= n; ++i) for (hu j(i + 1); j <= n; ++j) inv += p[j] < p[i];
            while (inv) {
                for (hu i(1); i <= n; ++i) {
                    hu c(0), a[2]{};
                    for (hu j(1); j < n; ++j) if (p[j + 1] < p[j]) ++c, a[j % 2] = j;
                    if (not a[(m + 1) % 2]) break;
                    else operate(a[(m + 1) % 2]);
                }
                if (not inv) break;
                operate(m % 2 + 1);
            }
            printf("%u\n", m);
            for (register uint i(1); i <= m; ++i) printf("%u ", a[i]);
            putchar('\n');
        }
    }
    static hu t;
    static inline const void main() {
        scanf("%hu", &t);
        for (hu i(0); i < t; ++i) Testcase::main();
    }
}

signed int main() { Main::main(); return 0; }

//Coded by Abhijay Mitra (AbJ)
#include "bits/stdc++.h"
#define double long double
#define int long long int
#define ibs ios_base::sync_with_stdio(false)
#define cti cin.tie(0)
#define mp make_pair
#define pb emplace_back
#define F first
#define S second
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using pii = std::pair<int, int>;
using vpii = std::vector<pii>;
using vvpii = std::vector<vpii>;
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, b, a) for (int i = b; i >= a; i--)
#define all(x) x.begin(), x.end()
using namespace std;
const int inf = 1e18 + 10;
const int N = 2e6 + 10;
int n, a[N];
void solve(){
	cin >> n;
	rep(i, 1LL, n){
		cin >> a[i];
	}
	vi v;
	if(n == 1LL){
	}
	else if(n == 2LL){
		if(a[1LL] == 2LL){
			v.pb(1LL);
			swap(a[1LL], a[2LL]);
		}
	}
	else{
		rep(i, 1LL, n - 3LL){
			rep(j, i + 1, n){
				if(a[j]==i){
					if((((int)v.size() ) & 1) != (j & 1)){
						if(((int)v.size() & 1) == (n & 1)){
							v.pb(n - 1LL);
							swap(a[n - 1LL], a[n]);
						}
						else{
							v.pb(n - 2LL);
							swap(a[n - 2LL], a[n - 1LL]);
						}
					}
					per(pos, j - 1, i){
						v.pb(pos);
						swap(a[pos], a[pos + 1LL]);
					}
				}
			}
		}
	}
	while(a[n] != n or a[n - 1LL] != n - 1LL or a[n - 2LL] != n - 2LL){
		if(((int)v.size() & 1LL) == (n & 1LL)){
			v.pb(n - 1LL);
			swap(a[n - 1LL], a[n]);
		}
		else{
			v.pb(n - 2LL);
			swap(a[n - 2LL], a[n - 1LL]);
		}
	}
	assert((int)v.size() <= n * n);
	assert(is_sorted(a + 1LL, a + 1LL + n));
	cout << v.size() << "\n";
	for(auto &i: v){
		cout << i << " ";
	}
}
int32_t main(){
	ibs;cti;
	// solve(); return 0;
	int t; cin >> t;
	while (t--){
		solve(); cout << "\n";
	}
	return 0;
}


#include<bits/stdc++.h>
typedef long long ll;
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define nep(i,r,l) for(int i=r;i>=l;i--)
void re(int &x){scanf("%d",&x);}
void re(int &x,int &y){scanf("%d %d",&x,&y);}
void re(ll &x){scanf("%lld",&x);}
void re(ll &x,ll &y){scanf("%lld %lld",&x,&y);}
void re(double &x){scanf("%lf",&x);}
void re(double &x,int &y){scanf("%lf %lf",&x,&y);}
using namespace std;
const int N=1e5+5;
const int mod=998244353;

string s[N];
char boom[N];
int main()
{
    int n,m;re(n,m);
    rep(i,0,n+m-2) boom[i]='.';
    rep(i,0,n-1) cin>>s[i];
    rep(i,0,n-1)
    {
        rep(j,0,m-1)
        {
            if(s[i][j]=='R'&&boom[i+j]!='B') boom[i+j]='R';
            else if(s[i][j]=='B'&&boom[i+j]!='R') boom[i+j]='B';
            else if(s[i][j]=='.') continue;
            else
            {
                cout<<0<<endl;
                return 0;
            }
        }
    }
    ll ans=1;
    rep(i,0,n+m-2)
    {
        if(boom[i]=='.') ans=(ans*2)%mod;
    }
    cout<<ans<<endl;
    return 0;
}

// editorial
#include<iostream>
#include<vector>
#include<numeric>
using namespace std;

typedef long long ll;
const ll mod = 998244353;

ll modpow(ll a, ll b, ll p = 1e9+7){
    if(b == 0)  return 1;

    if(b % 2 == 0){
        ll d = modpow(a, b/2, p);
        return (d*d) % p;
    }else{
        return (a%p * modpow(a, b-1, p)) % p;
    }
}

int main(){
    int n, k;
    cin >> n >> k;
    vector<ll> v(n);
    for(int i = 0; i < n; i++)  cin >> v[i];
    vector<ll> fact(k+1, 1);
    for(int i = 1; i <= k; i++) fact[i] = fact[i-1]*i%mod;
    vector<ll> invf(k+1, 1);
    for(int i = 1; i <= k; i++) invf[i] = modpow(fact[i], mod-2, mod);
    vector<ll> sum(k+1, 0);
    sum[0] = n;
    vector<ll> powers(n, 1);
    for(int i = 1; i <= k; i++){
        for(int j = 0; j < n; j++){
            powers[j] = powers[j]*v[j]%mod;
            (sum[i] += powers[j]*invf[i]%mod) %= mod;
        }
    }
    const ll invtwo = modpow(2, mod-2, mod);
    vector<ll> fpowers(n, 1);
    for(int i = 1; i <= k; i++){
        ll tmp = 0, sub = 0;
        for(int j = 0; j <= i; j++){
            (tmp += sum[j]*sum[i-j]%mod) %= mod;
        }
        (tmp *= fact[i]) %= mod;
        for(int j = 0; j < n; j++){
            fpowers[j] = fpowers[j]*2*v[j]%mod;
            (sub += fpowers[j]) %= mod;
        }
        cout << (tmp-sub+mod)*invtwo%mod << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vb = vector<bool>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<long long>;
using vvl = vector<vector<long long>>;
using vc = vector<char>;
using vvc = vector<vector<char>>;
const long long MOD2 = 998244353LL;
const long long MOD = 1000000007LL;
const long long INF = 1LL<<60;

int main(){
   double sx,sy,cx,cy;
   cin >> sx >> sy >> cx >> cy;
   cy *= -1;
   if(sx == cx)cout << sx << endl;
   else{
      double a = (cy-sy)/(cx - sx);
      double b = sy - a*sx;
      printf("%.15lf\n", -1.0*b/a);
   }
   return 0;
}

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


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
#define int long long
typedef unsigned long long lu;
typedef vector<ll> v;
typedef vector<vector<ll> > vv;
typedef vector<string>  vs;
typedef vector<pair<ll,ll>> vpr;
typedef vector<bool>vb;
typedef vector<double>vd;
typedef long double ld;
#define f(i,n) for(ll i = 0; i < n; i++)
#define ff(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define endl "\n"
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define amax(x,y) if(y>x) x=y;
#define amin(x,y) if(y<x)x=y;
#define bg(x) x.begin()
#define sz(x) (ll)x.size()
#define in(x,n) for(ll i=0;i<n;i++)cin>>x[i]
#define out(x,n) for(ll i=0;i<n;i++)cout<<x[i]<<" "
#define mxt(a) *(max_element(a.begin(),a.end()))
#define mnt(a) *(min_element(a.begin(),a.end())
#define tc ll t;cin>>t;while(t--)
typedef pair<ll,ll> pi;
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
#define yesno(f) if(f) yes else no
const v dx = {1, -1, 0, 0};
const v dy = {0, 0, 1, -1};
const ld PI = 2 * acos(0.0);
ll cel(ll x1,ll y1){if((x1%y1)==0)return x1/y1;else return x1/y1+1;}
ll power(ll a,ll b,ll m)
{
    if(b==0)
        return 1;
    ll d=power(a,b/2,m);
    d=(d*d)%m;
    if(b&1)
        d=(d*a)%m;
    return d;
}
const ll mod=1e9+7;
int MOD(int a)
{
    if(a<0)
        a+=mod;
    if(a>=mod)
        a%=mod;
    return a;
}
// set_name.find_by_order(k) It returns to an iterator to the kth element (counting from zero) in the set in O(logn) time
// set_name.order_of_key(k) It returns to the number of items that are strictly smaller than our item k in O(logn) time.
/*string operations :
str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
str.substr (x) : returns a substring str[x],... end of string
str.find(qtr) : returns the first occurenece of qtr in str */
int32_t main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int n;cin>>n;
    const int N=4e5;
    vector<unordered_set<int> > gr(N+1);
    vpr vec;
    for (int i = 0; i < n; ++i)
    {
        int a,b;cin>>a>>b;
        vec.pb({a,b});
        gr[a].insert(i);
        gr[b].insert(i);
    }
    queue<int>que;
    for (int i = 1; i <= N; ++i)
    {
        if(sz(gr[i])==1)
        {
            que.push(i);
        }
    }
    int ans=0;
    while(!que.empty())
    {
        int u=que.front();
        que.pop();
        if(sz(gr[u])!=1)
            continue;
        ans++;
        int i=*gr[u].begin();
        gr[u].erase(gr[u].begin());
        int u1=vec[i].first^vec[i].second^u;
        if(u1 !=u)
        {
            gr[u1].erase(i);
            if(sz(gr[u1]) == 1)
                que.push(u1);
        }
    }
    for (int i = 1; i <= N; ++i)
    {
        if(sz(gr[i]))
            ans++;
    }
    cout<<ans<<endl;
    return 0;
}

#include<iostream>
#include<stdio.h>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<bitset>
//#include<unordered_map>
#include<time.h>
#include<cstdlib>
typedef long long ll;
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#define mm(a) memset(a,0,sizeof(a))
#define lr rt<<1
#define rr rt<<1|1
#define sync std::ios::sync_with_stdio(false);std::cin.tie(0);
#define inf 0x3f3f3f3f
//#define eqs 1e-8
#define lb(x) (x&(-x))
#define ch(a) (int(a-'a')+1)
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
typedef pair<int,int> pii;
//const double pi=acos(-1);
const int maxn=1000010;
//const ll Mod=1000000007;
const ll Mod=998244353;

int c[maxn];
vector<int>g[maxn];

int head[maxn],d[maxn];
int tot,n,m;
struct node
{
    int v,nxt;
    ll w;
}e[maxn<<1];

void add(int u,int v,ll c)
{
    e[tot].v=v;
    e[tot].w=c;
    e[tot].nxt=head[u];
    head[u]=tot++;
    e[tot].v=u;
    e[tot].w=0ll;           //为0！！！
    e[tot].nxt=head[v];
    head[v]=tot++;
}

int bfs(int s,int t)
{
    queue<int>q;
    memset(d,-1,sizeof(d));
    d[s]=0;
    q.push(s);
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        if(u==t)
            return 1;
        for(int i=head[u];i!=-1;i=e[i].nxt)
        {
            int v=e[i].v;
            if(d[v]==-1&&e[i].w>0)
            {
                d[v]=d[u]+1;
                q.push(v);
            }
        }
    }
    return 0;
}

ll dfs(int u,ll flow,int t)
{
    if(u==t)
        return flow;
    ll sum=0;
    for(int i=head[u];i!=-1;i=e[i].nxt)
    {
        int v=e[i].v;
        ll w=e[i].w;
        if(w>0&&d[v]==d[u]+1)
        {
            ll tmp=dfs(v,min(1ll*flow-sum,e[i].w),t);
            e[i].w-=1ll*tmp;
            e[i^1].w+=1ll*tmp;
            sum+=1ll*tmp;
            if(sum==flow)
                return sum;
        }
    }
    if(sum==0)
        d[u]=0;
    return sum;
}

ll dinic(int s,int t)
{
    ll total=0;
    while(bfs(s,t))
        total+=1ll*dfs(s,2e14,t);
    return total;
}

bool vvs[maxn];

int main()
{
    sync;
    memset(head,-1,sizeof(head));
    int u,v;
    int st,ed;
    tot=0;
    st=0,ed=400001;
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>u>>v;
        vvs[u]=1;
        vvs[v]=1;
        add(st,i+ed,1);
        add(i+ed,u,1);
        add(i+ed,v,1);
    }
    for(int i=1;i<=400000;i++)
    {
        if(vvs[i])
        add(i,ed,1);
    }

    cout<<dinic(st,ed)<<endl;

    return 0;
}


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

using namespace std;

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

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007;

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

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

	int N, K;
    int ans = 0;
    vector<int> a;
    vector<int> con(400000);

    cin>>N>>K;

    a.resize(N);

    for(int i = 0; i < N; i++){
        cin>>a[i];
        con[a[i]]++;
        con[a[i]] = min(con[a[i]], K);
    }

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

    for(int i = 0; i + 1 < con.size(); i++){
        con[i+1] = min(con[i], con[i+1]);
        ans += (con[i] - con[i+1]) * (i+1);
    }

    cout<<ans<<endl;

	return 0;
}

#include<bits/stdc++.h>
#define maxn 10005
using namespace std;
int n,m; string s[805];
int son[800*13][8],tot=1;
vector<int> has[800*13];
struct mat{
	int v[20][20];
	int score;
	bool vis[800];
}arr[maxn];

int vis[800*13],col;
int dx[4]={0,1},dy[4]={1,0};
void getscore(mat &tt)
{
	memset(tt.vis,0,sizeof(tt.vis));
	tt.score=0;
	col++;
	for (int x=0;x<n;x++)
		for (int y=0;y<n;y++)
		for (int f=0;f<=1;f++)
		{
			int nx=x,ny=y,now=1,step=0;
			while (step<n)
			{
				if (!son[now][tt.v[nx][ny]]) break;
				now=son[now][tt.v[nx][ny]];
				step++; nx=(nx+dx[f]+n)%n; ny=(ny+dy[f]+n)%n;
				if (vis[now]!=col)
				{
					vis[now]=col;
					int siz=has[now].size();
					for (int j=0;j<siz;j++)
						tt.vis[has[now][j]]=1;
				}
			}
		}
	for (int i=0;i<m;i++)
	if (tt.vis[i])
		tt.score++;
	return;
}

void ins(int id,string s)
{
	int now=1;
	for (int i=0;i<s.size();i++)
	{
		int tt=s[i]-'A';
		if (!son[now][tt]) son[now][tt]=++tot;
		now=son[now][tt];
	}
	has[now].push_back(id);
	return;
}

void out(mat now)
{
	for (int i=0;i<n;i++)
	{
		for (int j=0;j<n;j++)
			cout<<(char)(now.v[i][j]+'A');
		cout<<endl;
	}
//	cout<<now.score<<endl;
	return;
}

int father=10,sson=5,dai=300000,fir=10000;
int cmp(mat x,mat y) {return x.score>y.score;}
void init()
{
	int tot=0;
	for (int i=1;i<=fir;i++)
	{
		tot++; arr[tot]=arr[i];
		for (int tt=1;tt<=100;tt++)
		{
			int j=rand()%(m-arr[tot].score)+1,x=rand()%n,y=rand()%n,now=0;
			while (true)
			{
				if (arr[tot].vis[now]==0) j--;
				if (j==0) break;
				now++;
			}
			//构造第now个字符串
			int f=rand()%2;
			for (j=0;j<s[now].size();j++)
			{
				arr[tot].v[x][y]=s[now][j]-'A';
				x=(x+dx[f]+n)%n; y=(y+dy[f]+n)%n;
			}
		}
		getscore(arr[tot]);
	}
	sort(arr+1,arr+tot+1,cmp);
}

int main()
{
//	freopen("0055.txt","r",stdin);
	int ti=clock();
	srand(time(0));
	cin>>n>>m;
	for (int i=0;i<m;i++) {cin>>s[i]; ins(i,s[i]);}
	int limit=CLOCKS_PER_SEC*2.9;
//	init();

	for (int tim=1;tim<=dai;tim++)
	{
		if (clock()-ti>=limit) break;
//		if (tim%50==0) cout<<tim<<" "<<arr[1].score<<endl;
//		cout<<tim<<" "<<arr[1].score<<endl;
		int tot=father;
		for (int i=1;i<=father;i++)
		{
			int q=sson;
			q=sson+(100-i*40>=0)?30-i*10:0;
			for (int tt=1;tt<=q;tt++)
			{
				tot++; arr[tot]=arr[i];
				int j=rand()%(m-arr[tot].score)+1,x=rand()%n,y=rand()%n,now=0;
				while (true)
				{
					if (arr[tot].vis[now]==0) j--;
					if (j==0) break;
					now++;
				}
				//构造第now个字符串
				int f=rand()%2;
				for (j=0;j<s[now].size();j++)
				{
					arr[tot].v[x][y]=s[now][j]-'A';
					x=(x+dx[f]+n)%n; y=(y+dy[f]+n)%n;
				}

				getscore(arr[tot]);
				if (arr[tot].score==m) {out(arr[tot]); return 0;}
			}
		}
		sort(arr+1,arr+tot+1,cmp);
	}
	sort(arr+1,arr+tot+1,cmp);
	out(arr[1]);
	return 0;
}


#include <bits/stdc++.h>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
const ul mod = 1000000007;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin >> n;
    string s, t;
    cin >> s >> t;

    ll num = 0;
    rep(i, n) {
        if (s[i] == '1') {
            num++;
        }
        if (t[i] == '1') {
            num--;
        }
    }
    if (num < 0) {
        cout << -1 << endl;
        return 0;
    }
    if (num % 2 == 1) {
        cout << -1 << endl;
        return 0;
    }

    ll ans = 0;
    int s_del_num = -1;
    queue<int> t_to_match;
    rep(i, n) {
        if (t[i] == '1') {
            t_to_match.push(i);
        }
        if (s[i] == '0') {
            continue;
        }
        if (s_del_num == -1) {
            if (t_to_match.empty()) {
                s_del_num = i;
            } else {
                int match = t_to_match.front();
                t_to_match.pop();
                ans += i - match;
                // cout << "match:" << i << " " << match << endl;
            }
        } else {
            ans += i - s_del_num;
            // cout << "delete:" << i << " " << s_del_num << endl;
            s_del_num = -1;
        }
    }
    if (t_to_match.empty()) {
        cout << ans << endl;
    } else {
        cout << -1 << endl;
    }
    return 0;
}

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

//to insert pair use eb or { }
#define int int64_t
typedef pair<int,int> pii;
const int X=1e9+7;
const int inf=1e18;

#define lld        int
#define pqu        priority_queue
#define eb         emplace_back
#define mp         make_pair
#define fi         first
#define se         second
#define pb         push_back
#define endl       "\n"
#define v          vector
#define Y          998244353
#define EPS        1e-6
#define N          500005
#define pi         3.1415926535897932384626

#define ones(x)     __builtin_popcount(x)
#define zero(a)    memset(a,0,sizeof(a))
#define minus(a)   memset(a,-1,sizeof(a))
#define all(a)     (a).begin(),(a).end()

#define rec(i,s,e)   for(int i=s ; (s<=e)?(i<e):(i>=e) ; (s<=e)?(i++):(i--) )
// rec(i,0,n)
// rec(i,n-1,0)
//for flush dont use endl (\n)

void google(int i)
{  cout<<"Case #"<<i<<": "; }

//use sort function even to sort a string of caharacters or numbers ...
//  sort(s.begin(),s.end());

//floating precision functions
//floor() for low
//ceil() for above
// trunc() removes decimal digits
//round() used to round off
void prec(double n,int d)
{
 cout<<fixed<<setprecision(d)<<n<<endl;
}

//prime[i]==1 if it is prime
int prime[1000001];
void sieve(int n)
{ rec(i,0,n+1)
    prime[i]=1;
   for(int i=2;i*i<=n;i++)
     { if(prime[i]!=1)
          continue;
         for(int j=i*i;j<=n;j=j+i)
          if(prime[j]==1)
           prime[j]=i;
      }
}

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

//fermat a^(m-2)%mod
int bin(int a,int n,int m)
{  int res=1;
 while(n)
  { if(n%2)
      { res=(res*a)%m;
         n--;
      }
     a=(a*a)%m;
     n/=2;
  }
  return res;
}

void dijktra(v<pii> g[], int n)
{
  pqu<pii, v<pii>, greater<pii>> pq;
  v<int> dist(n, inf);
  dist[0] = 0;
  int parent[n];
  minus(parent);
  pq.push({0, 0});

  while (!pq.empty())
  {
    pii x= pq.top();
    pq.pop();

    for(int i=0;i<(int)g[x.se].size();i++)
    {
      pii k = g[x.se][i];
      if (dist[x.se] + k.fi < dist[k.se])
      {
        dist[k.se] = dist[x.se] + k.fi;
        parent[k.se] = x.se;
        pq.push({dist[k.se], k.se});
      }
    }
  }
}

void bfs(int s,v<int> g[],int n)
{
   bool vis[n];
   rec(i,0,n)
    vis[i]=false;

   vis[s]=true;
   deque<int> q;
   q.pb(s);

   while(!q.empty())
   {
      s=q.front();
     q.pop_front();

     for(int i=0;i<g[s].size();i++)
      {
        if(!vis[g[s][i]])
         { vis[g[s][i]]=true;
            q.pb(g[s][i]);
         }
      }
   }
}

void dfs(int u,v<int> g[],bool *vis)
{

   vis[u]=true;
   for(int i=0;i<g[u].size();i++)
     if(!vis[g[u][i]])
          dfs(g[u][i],g,vis);

}
void create_w(v<pii> *g, int n, int m)
{
  rec(i,0, m)
  {
    int u,v,w;
    cin>>u>>v>>w;
    g[u-1].pb({w, v-1});
    g[v-1].pb({w, u-1});
  }
}
void create(v<int> *g,int n,int m)
{
   rec(i,0,m)
    {
       int u,v;
       cin>>u>>v;
       g[u-1].pb(v-1);
       g[v-1].pb(u-1);
    }
}

//always use int
void contest(int t)
{
        int s,p;
    cin>>s>>p;

    rec(i,1,sqrt(p)+1)
    {
        if(p%i!=0)
         continue;
        if((i + (p/i)) == s)
         {
             cout<<"Yes"<<endl;
             return;
         }

    }

    cout<<"No"<<endl;

}
//remember rec

int32_t main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(0); cout.tie(0);
     #ifdef PUNEET_GOEL
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #endif
    //sieve(1e6);
    int T=1;
    //cin>>T;
    rec(t,0,T)
    {
      contest(t);
    }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define pp pair<ll,ll>
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
constexpr int inf=1000001000;
constexpr ll INF=2e18;
constexpr ll mod=1000000007;
// ll MOD=998244353;
ll MOD=998244353;

void Add(int &a, int b) {
  a += b;
  while (a >= MOD) a -= MOD;
  while (a < 0) a += MOD;
}

void Mul(int &a, int b) {
  a = 1LL * a * b % MOD;
}

int Pow(int b, int e) {
  if (e < 0) e += MOD - 1;
  int ret = 1;
  while (e) {
    if (e & 1) ret = 1LL * ret * b % MOD;
    b = 1LL * b * b % MOD;
    e >>= 1;
  }
  return ret;
}

int main() {
    int n,k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    // vector<vector<ll>> b(n,vector<ll>(k+1,1));
    vector<ll> b(n,1);
    vector<ll> e(k+5,0);
    rep(i,k+1) e[i]=Pow(i,MOD-2);
    vector<ll> c(k+1,0);
    rep(i,n){
      rep(j,k+1){
        (c[j]+=b[i])%=MOD;
        b[i]=(b[i]*a[i]%MOD*e[j+1])%MOD;
      }
    }
    // rep(i,n){
    //   rep(j,k+1) (c[j]+=b[i][j])%=MOD;
    // }
    vector<ll> ans(k+1);
    ans[1]=1;
    rep(i,k){
      ans[i+2]=(ans[i+1]*(i+2))%MOD;
    }
    vector<ll> o(k,0);
    rep(i,k){
      rep(j,k+1){
        if (i+1-j<0) break;
        (o[i]+=c[j]*c[i+1-j]%MOD)%=MOD;
      }
    }
    vector<ll> p(k+2,0);
    ll cc;
    rep(i,n){
      cc=a[i]*2;
      rep(j,k) {
        (p[j]+=cc)%=MOD;
        (cc*=a[i]*2)%=MOD;
      }
    }
    rep(i,k) cout << ((ans[i+1]*o[i]%MOD+MOD-p[i])%MOD)*Pow(2,MOD-2)%MOD << endl;
}

#define wiwihorz
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma loop-opt(on)

#define rep(i, a, b) for(int i = a; i <= b; i++)
#define rrep(i, a, b) for(int i = b; i >= a; i --)
#define all(x) x.begin(), x.end()
#define ceil(a, b) ((a + b - 1) / (b))

#define MAXN 1000005
#define INF 1000000000000000000
#define MOD 998244353
#define eps (1e-9)

#define int long long int
#define lld long double
#define pii pair<int, int>
#define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count())

using namespace std;
#ifdef wiwihorz
#define print(a...) kout("[" + string(#a) + "] = ", a)
void vprint(auto L, auto R) {
	while(L < R) cerr << *L << " \n"[next(L) == R], ++L;
}
void kout() {cerr << endl;}
template<class T1, class ... T2> void kout(T1 a, T2 ... e) {
	cerr << a << " ", kout(e...);
}
#else
#define print(...) 0
#define vprint(...) 0
#endif
int n, m, k;
int pow_(int a, int times) {
	int ans = 1;
	for(;times > 0; times >>= 1, a = (a * a) % MOD) {
		if(times & 1) ans = (ans * a) % MOD;
	}
	return ans;
}
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> m >> k;
	if(m == 1 || n == 1) {
		if(n < m) swap(n, m);
		int ans = 0;
		ans = pow_(k, n);
		cout << (ans % MOD + MOD) % MOD << "\n";
	}
	else {
		int ans = 0;
		rep(i, 1, k) {
			ans += (pow_(i, n) - pow_(i - 1, n))
				* pow_(k - i + 1, m) % MOD;
			ans %= MOD;
		}
		cout << (ans % MOD + MOD) % MOD << "\n";
	}
	return 0;
}


#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
const int mod = 998244353;
int mult(int a, int b) {
    return (1LL * a * b) % mod;
}
int sum(int a, int b) {
    int s = a + b;
    if (s >= mod) s -= mod;
    return s;
}
int sub(int a, int b) {
    int s = a - b;
    if (s < 0) s += mod;
    return s;
}
const int maxN = 3005;
int dp[maxN][maxN];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    int n, k;
    cin >> n >> k;
    dp[0][0] = 1;
    for (int cnt = 1; cnt <= n; cnt++) {
        for (int s = cnt; s >= 1; s--) {
            dp[cnt][s] = dp[cnt - 1][s - 1];
            if (cnt >= 2 * s) {
                dp[cnt][s] = sum(dp[cnt][s], dp[cnt][2 * s]);
            }
        }
    }
    cout << dp[n][k];
    return 0;
}

#include<bits/stdc++.h>
#define it register int
#define ct const int
#define il inline
using namespace std;
typedef long long ll;
#define rll register ll
#define cll const ll
const int N=5005;
#define P 998244353
int fac[N],sz[N],k,n,cnt,ans,f[N][N];
il void mo(it&p,ct q){p+=q,p=(p>=P?p-P:p);}
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	scanf("%d%d",&n,&k);it i,j;
	if(k==n) return puts("1"),0;
	f[0][0]=1;
	for(j=1;j<=n;++j)
		for(i=1;i<=j;++i){
			f[i][j]=f[i-1][j-1];
			if((i<<1)<=j-i) mo(f[i][j],f[i<<1][j-i]);
			if((i-1<<1|1)<=j-i) mo(f[i][j],f[i-1<<1|1][j-i]);
		}
	for(i=1;i<=k;++i) mo(ans,f[i][n-k]);
	printf("%d",ans);
	return 0;
}


#include <cstdio>
#include <queue>
#include <algorithm>

using namespace std;

int d[101][2];

int main() {
    int a, b, x, y, i, j;
    priority_queue<pair<int, pair<int, int>>> q;

    scanf("%d %d %d %d", &a, &b, &x, &y);

    for (i = 1; i <= 100; i++) {
        for (j = 0; j < 2; j++) {
            d[i][j] = 1e9;
        }
    }

    d[a][0] = 0;
    q.push(make_pair(0, make_pair(a, 0)));

    while (!q.empty()) {
        int r = -q.top().first;
        int s = q.top().second.first;
        int t = q.top().second.second;

        q.pop();

        if (d[s][t] != r) continue;

        if (s == b && t == 1) {
            printf("%d\n", r);

            return 0;
        }

        if (d[s][1 - t] > r + x) {
            d[s][1 - t] = r + x;
            q.push(make_pair(-d[s][1 - t], make_pair(s, 1 - t)));
        }

        if (t == 0 && s - 1 >= 1 && d[s - 1][1 - t] > r + x) {
            d[s - 1][1 - t] = r + x;
            q.push(make_pair(-d[s - 1][1 - t], make_pair(s - 1, 1 - t)));
        }

        if (t == 1 && s + 1 <= 100 && d[s + 1][1 - t] > r + x) {
            d[s + 1][1 - t] = d[s][t] + x;
            q.push(make_pair(-d[s + 1][1 - t], make_pair(s + 1, 1 - t)));
        }

        if (s + 1 <= 100 && d[s + 1][t] > r + y) {
            d[s + 1][t] = d[s][t] + y;
            q.push(make_pair(-d[s + 1][t], make_pair(s + 1, t)));
        }

        if (s - 1 >= 1 && d[s - 1][t] > r + y) {
            d[s - 1][t] = d[s][t] + y;
            q.push(make_pair(-d[s - 1][t], make_pair(s - 1, t)));
        }
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

template <typename T>
vector<T> Dijkstra(int s, vector<vector<pair<int, T>>>& G,
                   /*vector<int> & prev,*/ const T INF = 1e9) {
    using P = pair<T, int>;
    int V = G.size();
    vector<T> dist(V, INF);
    priority_queue<P, vector<P>, greater<P>> que;
    dist[s] = 0;
    que.emplace(0, s);
    // prev.assign(V, -1);
    while (!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        if (dist[v] < p.first) continue;
        for (int i = 0; i < (int)G[v].size(); i++) {
            int to = G[v][i].first;
            T cost = G[v][i].second;
            if (dist[to] > dist[v] + cost) {
                dist[to] = dist[v] + cost;
                // prev[to] = v;
                que.emplace(dist[to], to);
            }
        }
    }
    return dist;
}

constexpr int n = 100;

signed main() {
    int a, b, x, y;
    cin >> a >> b >> x >> y;
    a--;
    b--;
    vector<vector<pair<int, int>>> G(2 * n);
    for (int i = 0; i < n; i++) {
        G[i].emplace_back(n + i, x);
        G[n + i].emplace_back(i, x);
    }
    for (int i = 0; i < n - 1; i++) {
        G[i + 1].emplace_back(n + i, x);
        G[n + i].emplace_back(i + 1, x);
        G[i].emplace_back(i + 1, y);
        G[i + 1].emplace_back(i, y);
        G[n + i].emplace_back(n + i + 1, y);
        G[n + i + 1].emplace_back(n + i, y);
    }
    auto dist = Dijkstra(a, G);
    cout << dist[b + n] << endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

void output(vector<int> &a){
  cout << a.size();
  for(auto &nx : a){
    cout << ' ' << nx;
  }
  cout << '\n';
}

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(auto &nx : a){cin >> nx;}
  vector<vector<int>> bk(200,vector<int>(0));
  int cnt=min(n,8);
  for(int i=1;i<(1<<cnt);i++){
    int sig=0;
    vector<int> s;
    for(int j=0;j<cnt;j++){
      if(i&(1<<j)){
        s.push_back(j+1);
        sig+=a[j];sig%=200;
      }
    }
    if(bk[sig].size()!=0){
      cout << "Yes\n";
      output(bk[sig]);
      output(s);
      return 0;
    }
    else{bk[sig]=s;}
  }
  cout << "No\n";
  return 0;
}

/*
    author:ujwalll
*/
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; 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 nx cout << "\n";
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
#define pp pair<ll, ll>
#define ppi pair<int, int>
typedef long long int ll;
#define pri(x) printf("%d ", x);
#define prl(x) printf("%lld ", x);
#define fi first;
#define se second;
#define pb push_back;
#define all(v) v.begin(), v.end()
#define minimum 1
#define maximum 1e5
#define random minimum + (rand() % static_cast<int>(maximum - minimum + 1))

bool isPowerOfTwo(ll x){
    return x && (!(x & (x - 1)));
}
void fastio(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}
long long binpow(long long a, long long b){
    long long res = 1;
    while (b > 0)
    {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
// int dfstimer(int node, int par){
//     st[node]=timer;
//     ft[timer]=node;
//     timer++;
//     for(auto i:adj[node]){
//         if(i!=par)dfs(i,node);
//     }
//     et[node]=timer;
//     ft[timer]=node;
//     timer++;
// }
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};
////////////////////////////////////////////////////////////////////
map<int,char> mp;
int main(){
    fastio();
    int tc = 1;
    // cin>>tc;
    while(tc--){
        int n;
        cin>>n;
        string s;
        cin>>s;
        int q;
        cin>>q;
        rep(i,2*n){
            mp[i]=s[i];
        }
        int bi = 0;
        while(q--){
            int t,a,b;
            cin>>t>>a>>b;
            if(t==2)bi^=1;
            else{
                a--;
                b--;
                if(bi){
                    if(a>=n)a-=n;
                    else a+=n;
                    if(b>=n)b-=n;
                    else b+=n;
                }
                    char c = mp[a];
                    mp[a]=mp[b];
                    mp[b]=c;
            }
        }
        for(auto i:mp){
            s[i.first]=i.second;
        }
        // cout<<bi;
        if(bi){
            string ans = "";
            for(int i=n;i<2*n;i++)ans+=s[i];
            rep(i,n)ans+=s[i];
            cout<<ans;
        }
        else cout<<s;
        done:;

    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int H, W, A, B, Ans;

void dfs(int p, int bitdp, int rec, int squ) {
  // 終端
  if (p == H * W) {
    Ans++;
    return;
  }
  // すでに利用済み
  if (bitdp & 1 << p) dfs(p + 1, bitdp, rec, squ);
  // 半畳を利用
  if (squ && ~bitdp & 1 << p) dfs(p + 1, bitdp | 1 << p, rec, squ - 1);
  // 畳を利用
  if (rec) {
    // 右へ遷移
    if (p % W != W - 1 && ~bitdp & 1 << (p + 1)) dfs(p + 1, bitdp | 3 << p, rec - 1, squ);
    // 下へ遷移
    if (p + W < H * W) dfs(p + 1, bitdp | 1 << p | 1 << (p + W), rec - 1, squ);
  }
}

int main() {
  cin >> H >> W >> A >> B;
  dfs(0, 0, A, B);
  cout << Ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
const long long mod1 = 1000000007;
using ll = long long;
using pq = priority_queue<ll>;
vector<int> dx = {0,1,0,-1};
vector<int> dy = {-1,0,1,0};

long long pow(long long x,long long n){
    long long ans = 1;
    while(n != 0){
        long long a = x;
        long long z = 1;
        while(z*2 <= n){
            a *=a;
            a=a%mod1;
            z*=2;
        }
        ans*=a;
        ans=ans%mod1;
        n-=z;
    }
    return ans;
}//累乗 x^n

template<typename T>
void input_vec(vector<T> &A,long long N){
    for(int i = 0; i < N; i++){
        cin >> A.at(i);
    }
    return;
}//入力を配列で受け取る

template<typename T>
void output_vec(vector<T> &A,long long N){
    for(int i = 0; i < N; i++){
        if(i != 0){
            cout << " ";
        }
        cout << A.at(i);
    }
    cout << endl;
    return;
}//配列を出力

template<typename T>
long long count_vec(vector<T> &A,T x){
    long long counter = 0;
    for(int i = 0; i < (int)A.size(); i++){
        if(A.at(i) == x){
            counter++;
        }
    }
    return counter;
}//配列内のxの個数をreturn

vector<char> change_vec(string s,int n){
    vector<char> ans(n);
    for(int i = 0; i < n; i++){
        ans.at(i) = s.at(i);
    }
    return ans;
}//文字列を配列に変換

void derete(vector<ll> &a){
    vector<ll> b = a;

    ll size = a.size();
    for(int i = 0; i < size; i++){
        b.at(i) = a.at(size-i-1);
    }
    b.pop_back();
    a.pop_back();
    for(int i = 0; i < size-1; i++){
        a.at(i) = b.at(size-i-2);
    }
    return;
}

int main(){
    ll a,b,c; cin >> a >> b >> c;
    if(a == b) cout << a << endl;
    if(a != b) cout << 3-a-b << endl;

}


#include <bits/stdc++.h>

int main(){
    std::string S;
    std::cin >> S;

    int st = 8, ed = 10;
    if(S.size() == 2){
        st = 16; ed = 100;
    }else if(S.size() >= 3){
        st = 104; ed = 1000;
    }
    std::vector< int > eight;
    for(int i=st; i<ed; i+=8){
        int tmp = i;
        bool zero = false;
        while(tmp != 0){
            int tmp2 = tmp % 10;
            if(tmp2 == 0){
                zero = true;
                break;
            }
            tmp /= 10;
        }
        if(!zero){
            eight.push_back(i);
        }
    }

    std::vector< int > cnt(10, 0);

    for(int i=0;i<S.size(); i++){
        cnt[S[i] - '0']++;
    }
    for(int i=0;i<eight.size(); i++){
        std::vector< int > cnt2(10, 0);
        int digit3 = (eight[i] % 1000) / 100;
        int digit2 = (eight[i] % 100) / 10;
        int digit1 = (eight[i] % 10) / 1;
        cnt2[digit3]++;
        cnt2[digit2]++;
        cnt2[digit1]++;
        bool ok = 1;
        for(int j=1; j<10; j++){
            if(cnt[j] < cnt2[j]){
                ok = 0;
            }
        }

        if(ok){
            std::cout << "Yes" << std::endl;
            return 0;
        }
    }

    std::cout << "No" << std::endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(long i=0; i<(long)(n);i++)
#define REP(i,s,t) for(long i=s; i<t; i++)
#define RNG(i,s,t,u) for(long i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(){
  string s;
  cin >> s;
  vl cnt(10,0);
  rep(i,s.size()){
    int p = s.at(i) - '0';
    cnt.at(p)++;
  }

  if(s.size() <= 3){
    sort(all(s));
    do{
      int p = atoi(s.c_str());
      if(p % 8 == 0){
        YES;

        return 0;
      }
    }while(next_permutation(all(s)));
    NO;
    return 0;
  }

  rep(i,1000){
    vl ref(10,0);
    bool flag = true;
    if(i % 8 != 0) continue;
    int p = i / 100;
    int q = i % 100 / 10;
    int r = i % 10;
    ref.at(p)++;
    ref.at(q)++;
    ref.at(r)++;
    rep(j,10){
      if(ref.at(j) <= cnt.at(j)) continue;
      flag = false;
    }
    if(flag){
      YES;
      return 0;
    }
  }

  NO;
}


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

string A, B, C;
long long x, y, z;

int func(vector<int> &V)
{
    x = y = z = 0;

    for (int i=0; i<A.size(); i++)
    {
        int dig = V[ A[i] - 'a' ];

        if (i == 0 && dig == 0)
            return 0;

        x = x * 10 + dig;
    }

    for (int i=0; i<B.size(); i++)
    {
        int dig = V[ B[i] - 'a' ];

        if (i == 0 && dig == 0)
            return 0;

        y = y * 10 + dig;
    }

    for (int i=0; i<C.size(); i++)
    {
        int dig = V[ C[i] - 'a' ];

        if (i == 0 && dig == 0)
            return 0;

        z = z * 10 + dig;
    }

    return (x + y == z);
}

int solve(int mask, int maxx, vector<int> &V)
{
    if (V.size() == maxx)
        return func(V);

    for (int i=0; i<10; i++)
    {
        if (mask & (1 << i))
            continue;

        V.push_back(i);

        if (solve((mask | (1 << i)), maxx, V))
            return 1;

        V.pop_back();
    }

    return 0;
}

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

    cin >> A >> B >> C;

    map<char, char> S;

    for (auto a : A)
        S[a];
    for (auto b : B)
        S[b];
    for (auto c : C)
        S[c];

    if (S.size() > 10)
    {
        cout << "UNSOLVABLE\n";
        return 0;
    }

    char ptr = 'a';

    for (auto &it: S)
        it.second = ptr++;

    for (auto &a : A)
        a = S[a];
    for (auto &b : B)
        b = S[b];
    for (auto &c : C)
        c = S[c];

    vector<int> V;

    if (!solve(0, S.size(), V))
        cout << "UNSOLVABLE\n";
    else
        cout << x << "\n" << y << "\n" << z << "\n";

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
char s1[15],s2[15],s3[15];
int a[15],b[15],c[15];
int n,m,k;

char dig[45];
int len;

void Discretize() {
	for(int i=1;i<=n;i++) {
		dig[++len]=s1[i];
	}
	for(int i=1;i<=m;i++) {
		dig[++len]=s2[i];
	}
	for(int i=1;i<=k;i++) {
		dig[++len]=s3[i];
	}
	sort(dig+1,dig+len+1);
	len=unique(dig+1,dig+len+1)-dig-1;
	for(int i=1;i<=n;i++) {
		a[i]=(lower_bound(dig+1,dig+len+1,s1[i])-dig);
	}
	for(int i=1;i<=m;i++) {
		b[i]=(lower_bound(dig+1,dig+len+1,s2[i])-dig);
	}
	for(int i=1;i<=k;i++) {
		c[i]=(lower_bound(dig+1,dig+len+1,s3[i])-dig);
	}
}

int match[11];//What i in the strings correspond to

bool vis[11];

bool hasLead[11];

bool check() {
	ll x=0,y=0,z=0;
	for(int i=1;i<=n;i++) {
		x=x*10+match[a[i]];
	}
	for(int i=1;i<=m;i++) {
		y=y*10+match[b[i]];
	}
	for(int i=1;i<=k;i++) {
		z=z*10+match[c[i]];
	}
	if(x+y==z) {
		printf("%lld\n%lld\n%lld",x,y,z);
		return 1;
	}
	return 0;
}

bool dfs(int step) {
	if(step==len+1) {
		if(check()) {
			return 1;
		}
		return 0;
	}
	for(int i=(hasLead[step]?1:0);i<=9;i++) {
		if(!vis[i]) {
			vis[i]=1;
			match[step]=i;
			if(dfs(step+1)) {
				return 1;
			}
			vis[i]=0;
		}
	}
	return 0;
}

int main() {
	scanf("%s %s %s",s1+1,s2+1,s3+1);
	n=strlen(s1+1),m=strlen(s2+1),k=strlen(s3+1);
	Discretize();
	if(len>10) {
		printf("UNSOLVABLE");
		return 0;
	}
	hasLead[a[1]]=hasLead[b[1]]=hasLead[c[1]]=1;
	if(!dfs(1)) {
		printf("UNSOLVABLE");
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0,endrep=(n); i<endrep; ++i)
#define rep1(i,n) for(ll i=1,endrep=(n); i<=endrep; ++i)
#define revrep(i,n) for(ll i=(n)-1; i>=0; --i)
inline constexpr ll Inf = (1ULL << 60) -123456789;
#define fastio cin.tie(0); ios_base::sync_with_stdio(false); cout<<fixed<<setprecision(10);
#define newl '\n'
#define YN(e) ((e)?"Yes":"No")
#define all(a) begin(a),end(a)
#define rall(a) rbegin(a),rend(a)
template <class T,class U> bool updmax(T& a, U b) { if(b>a){ a=b; return true;} return false;}
template <class T,class U> bool updmin(T& a, U b) { if(b<a){ a=b; return true;} return false;}
inline constexpr int Mod = 1000000007;
//inline constexpr int Mod = 998244353;
#define dbg(a) cout << #a << ": " << a << endl;
#define dbg1(a,n) cout<<#a<<": "; rep(i,n) cout<<a[i]<<" "; cout<<endl;
#define dbg2(m,h,w) cout<<#m<<":"<<endl; rep(i,h){ rep(j,w)cout<<m[i][j]<<" "; cout<<endl; }
int rng(int n) { return rand()/(RAND_MAX+1.0)*n; }

ll s(ll n) {
    if (n <= 0) return 0;
    return (n+1)*n/2;
}

template <ll Mod>
class modint {
    public:
    ll n=0;
    modint(){}
    modint(ll n):n(n){ clamp(); }
    modint& operator = (modint const& a) = default;
    modint& operator = (int a) { n = a; clamp(); return *this; }
    modint operator - () { modint t = *this; t.n = -t.n; t.clamp(); return t; }
    modint& operator *= (modint const& a) { n *= a.n; clamp(); return *this; }
    modint& operator *= (ll a) { n *= a; clamp(); return *this; }
    modint& operator /= (modint const& a) { *this *= a.inv(); return *this; }
    modint& operator += (modint const& a) { n += a.n; if (n >= Mod) n -= Mod; return *this; }
    modint& operator -= (modint const& a) { n -= a.n; if (n < 0) n += Mod; return *this; }
    modint& operator %= (modint const& a) { n %= a.n; clamp(); return *this; }
    friend modint operator * (modint a, modint b) { modint t(a); t.n *= b.n; t.clamp(); return t; }
    friend modint operator + (modint a, modint b) { modint t(a); t.n += b.n; t.clamp(); return t; }
    friend modint operator - (modint a, modint b) { modint t(a); t.n -= b.n; t.clamp(); return t; }
    friend ostream& operator << (ostream& os, modint const& a) { os << a.n; return os; }
    friend bool operator == (modint const& a, int b) { return a.n == b; }
    void clamp() { n %= Mod; if (n < 0) n += Mod; }
    modint inv() const { return this->pow(Mod-2); }
    ll get() { return n; }
    modint pow(ll p) const {
        ll a=1, e=n;
        while (p > 0) {
            if (p&1) { a *= e; a %= Mod; }
            e *= e; e %= Mod; p >>= 1;
        }
        return modint(a);
    }
};
using mint = modint<Mod>;

int main() {
    fastio;
    ll T;
    cin >> T;
    while(T-- > 0) {
        ll N,A,B;
        cin >> N >> A >> B;
        ll ad = N-A+1;
        ll bd = N-B+1;
        ll z = s(N-A)-s(B-1);
        if (z < 0) z = 0;
        mint xs = z;
        ll t = N-A-B+1;
        if (t < 0) t = 0;
        mint bm = t;
        mint p = xs+bm*(-B+1);
        mint dup = p*p;
        mint h = ad*bd * p;
        mint ans = h*4 - dup*4;
        cout << ans.get() << newl;
    }
}

/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kein Yukiyoshi
 */

// clang-format off
#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx")
#define int long long
using namespace std;
#define stoi stoll
#define fi first
#define se second
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; i++)
#define rep2(i, a, b) for (int i = (int)(a), i##_len=(b); i < i##_len; i++)
#define rep3(i, a, b) for (int i = (int)(a), i##_len=(b); i >= i##_len; i--)
#define FOR(i, a) for (auto &i: a)
#define ALL(obj) begin(obj), end(obj)
#define _max(x) *max_element(ALL(x))
#define _min(x) *min_element(ALL(x))
#define _sum(x) accumulate(ALL(x), 0LL)

const int MOD    = 998244353;
const int INF    = 10000000000007; // 1e13 + 7
const int INF2    = LLONG_MAX; // 9.2e18
const double EPS = 1e-8;
const double PI  = 3.14159265358979;
template <class T> using V = vector<T>;
template <class T> using VV = vector<vector<T>>;
template <class T> using VVV = vector<vector<vector<T>>>;
template <class T, class S>  using P = pair<T, S>;
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 (b < a) {a = b;return true;}return false;}
int _ceil(int a, int b) { return (a >= 0 ? (a + (b - 1)) / b : (a - (b - 1)) / b); }
template<class T> T chmod(T &a, T mod=MOD) {a =  a >= 0 ? a % mod : a - (mod * _ceil(a, mod)); return a;};
int _mod(int a, int mod=MOD) {return a >= 0 ? a % mod : a - (mod * _ceil(a, mod));}
int _pow(int a, int b) {int res = 1;for (a %= MOD; b; a = a * a % MOD, b >>= 1)if (b & 1) res = res * a % MOD;return res;}
struct mint {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; }mint operator+(const mint a) const { return mint(*this) += a; }mint operator-(const mint a) const { return mint(*this) -= a; } mint operator*(const mint a) const { return mint(*this) *= a; }mint pow(long long t) const {if (!t) return 1;mint a = pow(t >> 1);a *= a;if (t & 1) a *= *this;return a;}mint inv() const { return pow(MOD - 2); }mint &operator/=(const mint a) { return *this *= a.inv(); }mint operator/(const mint a) const { return mint(*this) /= a; }};istream &operator>>(istream &is, mint &a) { return is >> a.x; }ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
// clang-format on

struct UnionFind {
  vector<int> d;
  UnionFind(int n = 0) : d(n, -1) {} //0からn-1
  int find(int x) { return (d[x] < 0 ? x : d[x] = find(d[x])); }
  bool unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x, y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return -d[find(x)]; }
};

class BSpecialSubsets {
public:
  static void solve(istream &cin, ostream &cout) {
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    int N;
    cin >> N;
    V<int> f(N);
    rep(i, N) cin >> f[i];
    UnionFind uf(N + 1);
    rep(i, N) uf.unite(i + 1, f[i]);
    int ans = 1;
    V<bool> already(N + 1);
    rep(i, N) {
      if (!already[uf.find(i + 1)]) {
        ans *= 2;
        ans %= MOD;
        already[uf.find(i + 1)] = true;
      }
    }
    cout << _mod(ans - 1) << endl;
  }
};

signed main() {
  BSpecialSubsets solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int MAXN = 2e5 + 10;
double arr[105][105][105];
double f(int a, int b, int c) {
  if (arr[a][b][c]) return arr[a][b][c];
  if (a == 100 || b == 100 || c == 100) return 0.0;
  double ans = 0.0;
  ans += (f(a + 1, b, c) + 1) * a / (a + b + c);
  ans += (f(a, b + 1, c) + 1) * b / (a + b + c);
  ans += (f(a, b, c + 1) + 1) * c / (a + b + c);
  arr[a][b][c] = ans;
  return ans;
}
int main() {
  double a, b, c;
  cin >> a >> b >> c;
  double res = f(a, b, c);
  cout << fixed << setprecision(9) << res;
}

#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i = 0; 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;}
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;
const int MOD = 1000000007;
const double pi = acos(-1);
ll gcd(ll a, ll b) {if(b == 0) return a; else return gcd(b,a%b);}
ll lcm(ll a, ll b) {return a*b/gcd(a,b);}

int main() {
    int N; cin >> N;
    ll X; cin >> X;
    vecl A(N);
    REP(i,N) {
        ll v,p; cin >> v >> p;
        A[i] = v*p;
    }
    ll total = 0;
    REP(i,N) {
        total += A[i];
        if(total > X*100) {
            cout << i+1 << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long llu;
#define INF 0x3f3f3f3f
const int N=600010,mod=1e9+7,P=19260817;
ll n,m,T,k,x,cnt,y,b[N],c[N],vis[N],ans,t,a[N],x2,y2;
string s;
int main()
{
	scanf("%lld%lld",&n,&m);
	if (n==1)
	{
		if (m==0) printf("%lld %lld\n",(ll)1,(ll)2); else printf("%lld\n",(ll)-1);
		return 0;
	}
	if (m>n-2||m<0)
	{
		printf("%lld\n",(ll)-1);
		return 0;
	}
	if (m>=0)
	{
		printf("1 %lld\n",2*n-1);
		for (ll i=1;i<=m;i++) printf("%lld %lld\n",i*2,i*2+1);
		printf("%lld %lld\n",n*2-2,n*2);
		for (ll i=1;i<=n-m-2;i++) printf("%lld %lld\n",n*2+i*2-1,n*2+i*2);
	}
	else
	{
		//printf("%lld %lld\n",(ll)1,(ll)3);
		//for (ll i=1;i<=-m;i++) printf("%lld %lld\n",i*2+2,i*2+3);
		//printf("%lld %lld\n",(ll)2,n*2);
		//for (ll i=1;i<=n+m-2;i++) printf("%lld %lld\n",n*2+i*2-1,n*2+i*2);
	}
}

#include <bits/stdc++.h>
using namespace std;
long long qwq(long long a, long long b) {
	long long ans = 1;
	while (b) {
		if (b & 1) {
			ans = ans * a % 1000000007;
		}
		a *= a;
		a %= 1000000007;
		b >>= 1;
	}
	return ans;
}
int main() {
	int n, m;
	scanf("%d %d", &n, &m);
	printf("%lld\n", qwq(m - 2, n - 1) * (m - 1) % 1000000007);
	return 0;
}


#include<stdio.h>
int main(void){
	int n;
	scanf("%d",&n);
	printf("%d",n-1);
	return 0;
}

#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << a*d - b*c << "\n";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define fast ios::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

vector<int> dsu,sz,rnk;
vector<vector<pair<int,int>>> g;
vector<int> color;

void init(int n,int x){
	dsu = sz = rnk = vector<int> (n+x);
	iota(dsu.begin()+x,dsu.end(),x);
	fill(sz.begin(),sz.end(),1);
}

int find(int u){
	return u == dsu[u] ? u : dsu[u] = find(dsu[u]);
}

void merge(int u,int v){
	u = find(u);
	v = find(v);
	if(u == v)return;
	if(sz[u] < sz[v])swap(u,v); // enable for fast dsu
	// if(rnk[u] > rnk[v])swap(u,v);
	sz[u] += sz[v];
	rnk[v] = rnk[u] + 1;
	dsu[v] = u;
}

set<int> st;

void dfs(int u,int p,int t){
	if(t == -1){
		for(pair<int,int> c : g[u])st.erase(c.second);
		color[u] = *st.begin();
		for(pair<int,int> c : g[u])st.insert(c.second);
	}else{
		color[u] = t;
	}
	// cerr << u << ' ' << p << ' ' << t << '\n';

	for(pair<int,int> c : g[u]){
		int v = c.first;
		int w = c.second;
		if(v == p)continue;
		if(w == color[u])dfs(v,u,-1);
		else dfs(v,u,w);
	}

}

int main(){
	fast
	int n,m;
	cin>>n>>m;
	color.resize(n);
	for(int i=1;i<=n;i++)st.insert(i);
	g.resize(n);
	init(n,0);
	for(int i=0;i<m;i++){
		int u,v,w;
		cin>>u>>v>>w;
		u--;v--;
		if(find(u) != find(v)){
			g[u].push_back({v,w});
			g[v].push_back({u,w});
			// cerr << u << ' ' << v << '\n';
			merge(u,v);
		}
	}
	dfs(0,-1,-1);
	for(int c : color)
		cout << c << '\n';
}

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

const int N=2e5+5;
const int LOGN=log2(N+10)+1;

int depth[N+1], a[N], b[N], delta[N], ans[N];

int parent[LOGN][N];
vector<int>edges[N];
int n;

void init(int n){
    for(int bit=0;bit<LOGN;bit++){
        for(int i=0;i<n;i++){
            parent[bit][i]=-1;
        }
    }
}

void dfs(int s,int p,int dep){
    depth[s]=dep;
    parent[0][s]=p;
    for(int bit=1;bit<LOGN;bit++){
        if(parent[bit-1][s]!=-1){
            parent[bit][s]=parent[bit-1][parent[bit-1][s]];
        }
    }
    for(auto x:edges[s]){
        if(x==p)    continue;
        dfs(x,s,dep+1);
    }
}

int lca(int u,int v){
    if(depth[u]<depth[v]) swap(u,v);
    int diff=depth[u]-depth[v];
    for(int bit=0;bit<LOGN;bit++) if((diff>>bit)&1) u=parent[bit][u];
    if(u==v) return u;
    for(int bit=LOGN-1;bit>=0;bit--)
        if(parent[bit][u]!=parent[bit][v]) {
            u=parent[bit][u];
            v=parent[bit][v];
        }
    return parent[0][u];
}

int dist(int a,int b){
    int c=lca(a,b);
    return depth[a]+depth[b]-2*depth[c];
}

int getNode(int a,int dist){
    for(int bit=0;bit<LOGN;bit++){
        if(dist&(1ll<<bit)){
            a=parent[bit][a];
        }
    }
    return a;
}

void dfs2(int s,int p,int change){
	ans[s]=delta[s]+change;
	for(auto x:edges[s]){
		if(x==p)	continue;
		dfs2(x,s,change+delta[s]);
	}
}

void solve(){
	cin>>n;
	init(n);
	for(int i=0;i+1<n;i++){
		cin>>a[i]>>b[i];
		a[i]--;b[i]--;
		edges[a[i]].push_back(b[i]);
		edges[b[i]].push_back(a[i]);
	}
	dfs(0,-1,0);

	int q;cin>>q;
	while(q--){
		int t,e,x;cin>>t>>e>>x;
		e--;

		int A=a[e], B=b[e];
		// cout<<A<<" "<<B<<"\n";
		if(t==2)	swap(A,B);

		// cout<<A<<" "<<B<<"\n";

		// Spcl Care
		if(lca(A,B)==B){
			// cout<<A<<" "<<B<<"\n";
			// cout<<"Coming Here\n";
			// delta[B]-=x;
			int node=getNode(A, dist(A, B)-1);
			delta[node]+=x;
			continue;
		}

		delta[B]-=x;
		// cout<<"B="<<B<<"\n";
		delta[0]+=x;
	}
	// for(int i=0;i<n;i++)	cout<<delta[i]<<" ";cout<<"\n";

	dfs2(0,-1,0);
	for(int i=0;i<n;i++)	cout<<ans[i]<<"\n";
}

main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    solve();
}


#include<bits/stdc++.h>
using namespace std;
#define MAXN 200005
#define lowbit(x) (x&-x)
#define reg register
typedef long long LL;
typedef unsigned long long uLL;
typedef unsigned int uint;
const int INF=0x7f7f7f7f;
const int jzm=233;
const int mo=998244353;
const double Pi=acos(-1.0);
typedef pair<int,int> pii;
const double PI=acos(-1.0);
template<typename _T>
_T Fabs(_T x){return x<0?-x:x;}
template<typename _T>
void read(_T &x){
	_T f=1;x=0;char s=getchar();
	while(s>'9'||s<'0'){if(s=='-')f=-1;s=getchar();}
	while('0'<=s&&s<='9'){x=(x<<3)+(x<<1)+(s^48);s=getchar();}
	x*=f;
}
LL a,b,prime[100],cntp,val[100],tot,S[100],dp[(1<<20)+5],ans;
bool oula[100];
void init(){
	for(LL i=2;i<=72;i++){
		if(!oula[i])prime[++cntp]=i;
		for(LL j=1;j<=cntp&&1ll*prime[j]*i<=72;j++){
			oula[prime[j]*i]=1;
			if(i%prime[j]==0)break;
		}
	}
}
int main(){
	read(a);read(b);init();dp[0]=1;int lim=(1<<cntp)-1;
	for(LL i=a;i<=b;i++)val[++tot]=i;
	for(int i=1;i<=tot;i++){
		for(int j=1;j<=cntp;j++)
			if(val[i]%prime[j]==0)S[i]|=(1<<j-1);
	}
	for(int i=1;i<=tot;i++)
		for(int j=lim;j>=0;j--)
			if(!(j&S[i]))dp[j|S[i]]+=dp[j];
	for(int j=0;j<=lim;j++)ans+=dp[j];
	printf("%lld\n",ans);
	return 0;
}

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

int main() {
    ll A, B;
    cin >> A >> B;
    vector<int> primes = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71};
    int K = primes.size();
    vector<ll> from(1<<K, 0), to(1<<K, 0);
    from[0] = 1;
    for (ll i = A; i <= B; i++) {
        fill(to.begin(), to.end(), 0);
        ll mask = 0;
        for (int j = 0; j < K; j++) {
            if (i%primes[j] == 0) mask |= (1<<j);
        }
        for (int j = 0; j < (1<<K); j++) {
            to[j] += from[j];
            if ((j&mask) == 0) to[j|mask] += from[j];
        }
        swap(from, to);
    }
    ll ans = 0;
    for (ll n : from) ans += n;
    cout << ans << endl;
    return 0;
}


#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

typedef long long ll;
using std::swap;
using std::reverse;
using std::priority_queue;
using std::nth_element;
using std::next_permutation;
using std::upper_bound;
using std::lower_bound;
using std::unique;
using std::sort;
using std::max;
using std::min;
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::bitset;
using std::set;
using std::map;
using std::vector;
using std::queue;
using std::stack;
using std::pair;
using std::make_pair;
using std::complex;
using std::deque;
using std::list;

ll read() {
	register ll x = 0, f = 0, ch = getchar();
	for (; !isdigit(ch); f = (ch == 45), ch = getchar()) ;
	for (; isdigit(ch); x = x * 10 + ch - 48, ch = getchar()) ;
	return f ? -x : x;
}

void write(int x) {
	if (x < 0) putchar(45), x = -x;
	static int sta[35];
	int top = 0;
	do {
		sta[top++] = x % 10, x /= 10;
	} while (x);
	while (top) putchar(sta[--top] + 48);
}

const int maxn = 2e5 + 9, maxm = 2e5 + 9, inf = 0x3f3f3f3f;

ll t, n, m;
ll a[maxn], b[maxn], res;

std::pair<ll, int> c[maxn];

ll myabs(ll x) { return x > 0 ? x : -x; }

int main() {
	// freopen(".in", "r", stdin);
	// freopen(".out", "w", stdout);
	t = read(), n = read(), m = read();
	for (int i = 1; i <= t; ++i)
		a[i] = read(), b[i] = a[i] * m / n, res += b[i],
		c[i] = std::make_pair(myabs(a[i] * m - (b[i] + 1) * n) - myabs(a[i] * m - b[i] * n), i);
	res = m - res;
	std::sort(c + 1, c + t + 1);
	for (int i = 1; res && i <= n; ++i) b[c[i].second]++, res--;
	for (int i = 1; i <= t; ++i) printf("%lld ", b[i]);
	puts("");
	return 0;
}

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

//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define pb push_back
#define fi first
#define se second
#define ll long long
#define tp top()
#define fr front()
#define vi vector<int>
#define sz size()
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define mem(a,  b) memset(a,  (b),  sizeof(a))
#define clr(a) memset(a,  0,  sizeof(a))
#define sqr(x) ( (x) * (x) )
#define all(v) v.begin(),  v.end()

typedef pair<int, int> pii;
typedef pair<int,pii> pip;
typedef pair<pii,int> ppi;
typedef pair<pii,pii> ppp;

void base(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

#define N 100020
vector<int> adj[N];
int a[100020];
int par[100020];

vector<int> ans;

void dfs(int cur, int pa){
	if (par[a[cur]] == -1) {
		par[a[cur]] = cur;
		ans.pb(cur);
	}

	for(int to : adj[cur]){
		if (pa == to) continue;
		dfs(to,cur);
	}

	if (par[a[cur]] == cur) {
		par[a[cur]] = -1;
	}
}

void solve(){
	mem(par,-1);
	int n; cin>>n;
	rep(i,1,n+1) cin>>a[i];
	rep(i,0,n-1){
		int u,v; cin>>u>>v;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	dfs(1,1);
	sort(all(ans));
	for(int x : ans) cout<<x<<"\n";

}

int main()
{
	base();
//  freopen("input.txt", "r", stdin);
//  freopen("output.txt", "w", stdout);
	int t=1;
//	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a) for(int i = 0; i < (int) a; i++)
#define PB push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int grid[2007][2007];

int n;
vector<pair<int,int>> graph[2007];
int dist[2007];

void dijsktra(int s){
	for(int i = 0; i < n; i++) dist[i] = INT_MAX;
	priority_queue<pair<int,int>,
				   vector<pair<int,int>>,
				   ::greater<pair<int,int>> > q;
	q.push({0, s});
	bitset<2007> vis(0);
	while(!q.empty()){
		int now = q.top().second; q.pop();
		if(vis[now]) continue;

		vis[now] = 1;

		for(auto v : graph[now]){
			if(now == s){
				dist[v.second] = v.first;
				q.push({dist[v.second], v.second});
			}else if(dist[v.second] > dist[now] + v.first){
				dist[v.second] = dist[now] + v.first;
				q.push({dist[v.second], v.second});
			}
		}

	}
}

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

	int m; cin >> n >> m;
	FOR(i, n) FOR(j, n) grid[i][j] = 1e9;

	FOR(i, m){
		int a, b, c; cin >> a >> b >> c;
		a--; b--;
		grid[a][b] = min(grid[a][b], c);
	}

	FOR(i, n){
		FOR(j, n){
			if(grid[i][j] != 1e9){
				graph[i].PB({grid[i][j], j});
			}
		}
	}

	FOR(i, n){
		dijsktra(i);
		if(dist[i] == INT_MAX) cout << "-1\n";
		else cout << dist[i] << '\n';
	}

	return 0;
}

#include <bits/stdc++.h>

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;
using llpair = pair<llong, lpair>;

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

constexpr llong mod = 1e9+7;
constexpr llong inf = mod * mod;

struct union_find {
  std::vector<int> par;
  vector<unordered_map<int, int>> sum;

  union_find() {}
  union_find(int n) :
    par(n+1, -1)
  {}

  int root(int x) {
    if(par[x] < 0) return x;
    return par[x] = root(par[x]);
  }
  int size(int x) {
    return -par[root(x)];
  }
  bool same(int a, int b) {
    return root(a) == root(b);
  }
  bool marge(int a, int b) {
    a = root(a), b = root(b);
    if(a == b) return false;
    if(par[a] > par[b]) std::swap(a, b);
    par[a] += par[b];
    par[b] = a;
    for (auto it: sum[b]) {
      sum[a][it.first] += it.second;
    }
    return true;
  }
  int query(int x, int y) {
    return sum[root(x)][y];
  }
};

int main() {
  llong N, Q;
  vector<llong> C;
  vector<llpair> query;

  cin >> N >> Q;
  C.resize(N);
  for (auto &in: C) {
    cin >> in;
    in--;
  }
  query.resize(Q);
  for (auto &in: query) {
    cin >> in.first >> in.second.first >> in.second.second;
    in.second.first--;
    in.second.second--;
  }

  union_find uf(N);
  uf.sum.resize(N);
  for (int i = 0; i < N; i++) {
    uf.sum[i][C[i]] = 1;
  }
  for (auto q: query) {
    if (q.first == 1) {
      llong a = q.second.first;
      llong b = q.second.second;
      uf.marge(a, b);
    }
    else {
      llong x = q.second.first;
      llong y = q.second.second;
      cout << uf.query(x, y) << endl;
    }
  }

  return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <tuple>
#include <cmath>
using namespace std;
#define _GLIBCXX_DEBUG

int main(void){

        char S, T;
        cin >> S >> T;

        if(S == 'Y'){
            if(T == 'a'){
                cout << 'A' << endl;
            }

            else if(T == 'b'){
                cout << 'B' << endl;
            }

            else{
                cout << 'C' << endl;
            }

        }

        else{
            cout << T << endl;
        }

}

#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 105;
const int mod = 998244353;

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  string s, t;
  cin>>s>>t;
  if(s[0]=='N')cout<<t<<endl;
  else {
    cout<<char(t[0] - 'a' + 'A')<<endl;
  }
  return 0;
}


#include <bits/stdc++.h>
//#include <atcoder/all>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const long long INF = 1e18;
//const ll mod = 1000000007;
ll ans = 0;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    vector<ll> A[2];
    vector<ll> sum[2];
    cin >> N;
    ll T;
    cin >> T;
    for(int i = 0; i < N; i++) {
        ll a;
        cin >> a;
        A[i%2].push_back(a);
    }
    for(int i = 0; i < 2; i++) {
        for(int bits = 0; bits < (1 << A[i].size()); bits++) {
            ll tmp = 0;
            for(int j = 0; j < A[i].size(); j++) {
                if(bits & (1 << j)) tmp += A[i][j];
            }
            sum[i].push_back(tmp);
        }
        sort(sum[i].begin(), sum[i].end());
    }
    for(auto tmp : sum[0]) {
        auto itr = lower_bound(sum[1].begin(), sum[1].end(), T+1-tmp);
        if(itr == sum[1].begin()) continue;
        itr--;
        chmax(ans, tmp + *itr);
    }
    cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define fast_io cin.tie(0);ios_base::sync_with_stdio(0);
string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cout << endl; }
void show() { cout << endl; }
void pret() { cout << endl; exit(0);}
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cout << " " << to_string(H); debug_out(T...);}
template <typename Head, typename... Tail> void show(Head H, Tail... T) {cout <<H<<" "; show(T...);}
template <typename Head, typename... Tail> void pret(Head H, Tail... T) {cout <<H<<" "; pret(T...);}
#define pr(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
#define disp(x) cout<<x<<" ";
#define rep(i,a,b) for(int i=a;i<(int)b;i++)
#define fo(i,a,b) for(int i=a;i<=(int)b;i++)
#define rf(i,a,b) for(int i=a;i>=(int)b;i--)
#define mp make_pair
#define pb emplace_back
#define F first
#define S second
#define endl '\n'
//cout.setf(ios::fixed);cout.precision(18)
const int MOD = 1e9+7;
int maxn = 100+1;

int dp[101][101][101];
int newdp[101][101][101];

int32_t main(){
    fast_io;
    int n;
    ll x;
    cin >> n >> x;
    maxn = n + 1;
    int a[n + 1];
    for (int i = 0; i < n; ++i)
    {
    	cin >> a[i + 1];
    }
    for (int i = 0; i < maxn; ++i)
    {
    	for (int j = 0; j < maxn; ++j)
    	{
    		for (int k = 0; k < maxn; ++k)
    		{
    			dp[i][j][k] = -1;
    		}
    	}
    }
    for (int i = 1; i < maxn; ++i)
    {
    	dp[0][i][0] = 0;
    }
    fo(id, 1, n){
    	// pr(dp);
    	for (int i = 0; i < maxn; ++i)
    	{
    		for (int j = 0; j < maxn; ++j)
    		{
    			for (int k = 0; k < maxn; ++k)
    			{
    				newdp[i][j][k] = dp[i][j][k];
    			}

    		}
    	}
    	// show("----- ", id);
    	fo(i, 1, id){
    		fo(dividend, 1, maxn){
    			for (int rem = 0; rem < maxn; ++rem)
    			{
    				if(dp[i - 1][dividend][rem] == -1) continue;
    				int curr = (dp[i - 1][dividend][rem] + a[id]) % dividend;
    				newdp[i][dividend][curr] = max(newdp[i][dividend][curr], dp[i - 1][dividend][rem] + a[id]);
    			}
    		}
    		// for (int rem = 0; rem < maxn; ++rem)
    		// {
    		// 	if(dp[i - 1][rem] == -1) continue;
    		// 	int curr = (dp[i - 1][rem] + a[id]) % i;
    		// 	pr(i, rem);
    		// 	show(newdp[i][curr], dp[i - 1][rem] + a[id]);
    		// 	newdp[i][curr] = max(newdp[i][curr], dp[i - 1][rem] + a[id]);
    		// }
    	}
    	for (int i = 0; i < maxn; ++i)
    	{
    		for (int j = 0; j < maxn; ++j)
    		{
    			for (int k = 0; k < maxn; ++k)
    			{
    				dp[i][j][k] = newdp[i][j][k];
    			}
    			// dp[i][j] = newdp[i][j];
    		}
    	}
    }
    ll ans = x;
    for(ll i = 1; i <= n; i++){
    	int rem = x % i;
    	// show(i, rem, dp[i][i][rem]);
    	if(dp[i][i][rem] == -1) continue;
    	ll flag = dp[i][i][rem];
    	flag = x - flag;
    	// show(flag, flag / i);
    	ans = min(ans, flag / i);
    }
    show(ans);
    return 0;
}


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

ll dp[3005][3005], ways[3005][3005];

int main() {
	// your code goes here
	IOS;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll i, j, t, k, x, y, z, N;

	//dp[i][j] denotes ith index tak aur j groups

	//ways[i][j] sum%i==j

	mset(dp, 0);
	mset(ways, 0);

	dp[0][0] = 1;

	ll sum = 0;

	ways[1][0] = 1;
	cin >> n;
	ll a[n];
	rep(i, n) cin >> a[i];

	rep(i, n) {
		sum += a[i];
		repr(j, n) {
			ll rem = sum % (j + 1);
			(dp[i + 1][j + 1] += ways[j + 1][rem]) %= M;
			(ways[j + 2][sum % (j + 2)] += dp[i + 1][j + 1]) %= M;
		}
	}
	// rep(i, n + 1) {
	// 	rep(j, n + 1) {
	// 		debug(i, j, dp[i][j]);
	// 	}
	// }
	ll ans = 0;
	for (i = 1; i <= n; i++) (ans += dp[n][i]) %= M;
	cout << ans;

	return 0;

}

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

typedef long long ll;
typedef unsigned long long ull;

#define mp make_pair
#define fr first
#define sc second

template<class T> T T_INF(){ return 1000000000000000000; }
template<> int T_INF<int>(){ return 1000000000; }

template<int MOD> struct modint{
	ull val;
	modint(ull x){ val=x%MOD; }
	modint(){}
	friend modint modpow(modint x,ull k){
		modint ret(1ULL);
		while(k>0){
			if(k&1ULL)ret*=x;
			x*=x;
			k>>=1;
		}
		return ret;
	}
	modint& operator +=(const modint& rhs){
		this->val+=rhs.val;
		if(this->val>=MOD)this->val-=MOD;
		return *this;
	}
	friend modint operator+(modint lhs, const modint& rhs){
		lhs+=rhs;
		return lhs;
	}
	modint& operator -=(const modint& rhs){
		this->val+=MOD-rhs.val;
		if(this->val>=MOD)this->val-=MOD;
		return *this;
	}
	friend modint operator-(modint lhs, const modint& rhs){
		lhs-=rhs;
		return lhs;
	}
	modint& operator *=(const modint& rhs){
		this->val*=rhs.val;
		this->val%=MOD;
		return *this;
	}
	friend modint operator*(modint lhs, const modint& rhs){
		lhs*=rhs;
		return lhs;
	}
	static vector<modint> inv_;
	static void precalc_inv_(int k){
		int t=inv_.size();
		inv_.resize(k);
		for(int i=t;i<k;i++){
			inv_[i]=modpow(modint(i),MOD-2);
		}
	}
	modint& operator /=(const modint& rhs){
		//if(rhs.val<inv_.size()){
		//	(*this)*=inv_[rhs.val];
		//}
		//else {
			(*this)*=modpow(rhs,MOD-2);
		//}
		return *this;
	}
	friend modint operator/(modint lhs, const modint& rhs){
		lhs/=rhs;
		return lhs;
	}

	static vector<vector<modint>> C_;
	static vector<modint> fac,inv_fac;
	static void precalc_C_(int k){
		C_.resize(k,vector<modint>(k));
		for(int i=0;i<k;i++){
			C_[i][0]=C_[i][i]=1;
			for(int j=1;j<=i-1;j++){
				C_[i][j]=C_[i-1][j-1]+C_[i-1][j];
			}
		}
	}
	static void precalc_fac(int k){
		fac.resize(k);
		inv_fac.resize(k);
		fac[0]=inv_fac[0]=1;
		for(int i=1;i<k;i++){
			fac[i]=fac[i-1]*i;
			inv_fac[i]=modpow(fac[i],MOD-2);
		}
	}
	static modint C(ll n,ll k,int type=0){
		if(k<0||k>n)return 0;
		if(type==0){
			return C_[n][k];
		}
		else {
			return fac[n]*inv_fac[k]*inv_fac[n-k];
		}
	}
};
template<int MOD> vector<modint<MOD>> modint<MOD>::inv_;
template<int MOD> vector<vector<modint<MOD>>> modint<MOD>:: C_;
template<int MOD> vector<modint<MOD>> modint<MOD>::fac;
template<int MOD> vector<modint<MOD>> modint<MOD>::inv_fac;

const int MOD=1000000007;
typedef modint<MOD> mi;

int n;
ll a[3002];
ll s[3002];

mi dp[3002][3002];
mi temp[3002];

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%lld",&a[i]);

	s[0]=0;
	for(int i=1;i<=n;i++)s[i]=s[i-1]+a[i];

	mi ret=0;
	dp[0][0]=1;
	for(int i=1;i<=n;i++){
		fill_n(temp,3002,0);
		for(int j=0;j<=n;j++){
			dp[i][j]=temp[s[j]%i];
			temp[s[j]%i]+=dp[i-1][j];
		}
		ret+=dp[i][n];
	}
	cout<<ret.val<<endl;
}


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

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

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 };
ll MOD = 1000000007;

#define DEBUG fprintf(stderr, "====TESTING====\n")
#define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
#define OUT(x) cout << x << "\n"
#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

template<typename T_vector>
void output_vector(const T_vector &v, bool line_break = false, bool add_one = false, int start = -1, int end = -1) {
    if (start < 0) start = 0;
    if (end < 0) end = int(v.size());
    for (int i = start; i < end; i++) {
      cout << v[i] + (add_one ? 1 : 0) << (line_break ? '\n' : i < end - 1 ? ' ' : '\n');
    }
}

const int mxN = 60;
int p[mxN];

void solve() {
    int n; cin >> n;
    // let x be root, k be LCA
    // d(i, j) = d(k, i) ^ d(k, j)
    //         = d(k, i) ^ d(k, j) ^ d(x, k) ^ d(x, k)
    //         = (d(k, i) ^ d(x, k)) ^ (d(k, j) ^ d(x, k))
    //         = d(x, i) ^ d(x, j)
    vector<vector<pll>> g(n), weight(n);
    REP(i, n - 1) {
        ll u, v, w; cin >> u >> v >> w;
        --u, --v;
        g[u].pb({v, w});
        g[v].pb({u, w});
    }
    vl dist(n, -1);
    dist[0] = 0;
    queue<int> q;
    q.push(0);
    while(!q.empty()) {
        int now = q.front(); q.pop();
        EACH(x, g[now]) {
            int next = x.fi;
            ll sum = dist[now] ^ x.se;
            if(dist[next] == -1) {
                dist[next] = sum;
                q.push(next);
            }
        }
    }
    ll ans = 0;
    REP(i, mxN) {
        vi cnt(2);
        REP(j, n) cnt[dist[j] >> i & 1]++;
        ans += (1LL << i) % MOD * cnt[0] % MOD * cnt[1];
        ans %= MOD;
    }
    OUT(ans);
}

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();
    solve();
    return 0;
}

#include <iostream>
#include <vector>

using namespace std;
using LL = long long;

const int kMaxN = 2e5 + 1;
const int kMaxM = 101;
const int kM = 1e9 + 7;

LL n, ans, u, v, w;
LL c[kMaxN], d[kMaxM];

bool vis[kMaxN];

vector<LL> a[kMaxN], b[kMaxN];

void Dfs(LL x, LL y) {
  if (vis[x]) {
    return;
  }
  vis[x] = true;
  c[x] = y;
  for (LL i = 0; i < a[x].size(); i++) {
    Dfs(a[x][i], y ^ b[x][i]);
  }
}

int main() {
  cin >> n;
  for (LL i = 1; i < n; i++) {
    cin >> u >> v >> w;
    a[u].push_back(v), b[u].push_back(w);
    a[v].push_back(u), b[v].push_back(w);
  }
  Dfs(1, 0);
  for (LL i = 1; i <= n; i++) {
    for (LL j = 0; j <= 61; j++) {
      if (c[i] & (1ll << j)) {
        d[j]++;
      }
    }
  }
  for (LL i = 0; i <= 61; i++) {
    ans = (ans + 1ll * (n - d[i]) * d[i] % kM * ((1ll << i) % kM) % kM) % kM;
  }
  cout << ans;
  return 0;
}