#include "bits/stdc++.h"
using namespace std;
#ifndef LOCAL
#define endl '\n'
#endif

#define fr(i, a, b) for(int i = a; i <= b; i++)
#define rf(i, a, b) for(int i = a; i >= b; i--)
#define pf push_front
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
#define lb lower_bound
#define ub upper_bound

typedef long long ll;
typedef long double f80;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int pct(int x) { return __builtin_popcount(x); }
int pct(ll x) { return __builtin_popcountll(x); }
int bt(int x) { return 31 - __builtin_clz(x); } // floor(log2(x))
int bt(ll x) { return 63 - __builtin_clzll(x); } // floor(log2(x))
int cdiv(int a, int b) { return a / b + !(a < 0 || a % b == 0); }
ll cdiv(ll a, ll b) { return a / b + !(a < 0 || a % b == 0); }
int nxt_C(int x) { int c = x & -x, r = x + c; return (((r ^ x) >> 2) / c) | r; }
ll nxt_C(ll x) { ll c = x & -x, r = x + c; return (((r ^ x) >> 2) / c) | r; }

vector<int> get_bits(int mask) {
	vector<int> bb;
	while(mask) { int b = bt(mask); bb.pb(b); mask ^= (1 << b); }
	reverse(all(bb));
	return bb;
}

int get_mask(vector<int> v) {
	int mask = 0;
	for(int x : v) { mask ^= (1 << x); }
	return mask;
}

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

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

ll rand(ll l, ll r){
	uniform_int_distribution<ll> uid(l, r);
	return uid(rng);
}

void sc() {}

template <typename Head, typename... Tail>
void sc(Head &H, Tail &... T) { cin >> H; sc(T...); }

#ifdef LOCAL
#define debug(...) cerr << "[L:" << __LINE__ << "][" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

// #ifndef LOCAL
// string to_string(__int128 x) {
// 	string s = "";
// 	bool neg = 0;
// 	if(x < 0) { s += "-"; neg = 1; x = -x; }
// 	if(!x) s += '0';
// 	while(x) {
// 		int rem = x % 10;
// 		s += to_string(rem);
// 		x /= 10;
// 	}
// 	reverse(s.begin() + neg, s.end());
// 	return s;
// }
// #endif

const int mod = 1e9 + 7; // 998244353;

int pwr(int a,ll b) {
	int ans = 1;
	while(b) {
		if(b & 1) ans = (ans * 1LL * a) % mod;
		a = (a * 1LL * a) % mod;
		b >>= 1;
	}
	return ans;
}

/*
	Lookout for overflows!!
	Check array sizes!!
	Clear before test cases!!
	Use the correct modulo!!
	Check for corner cases!!
	Are you forgetting something?!
	Read problem statement carefully!!!
*/

const int N = 1e5 + 5;
int dsu[N], sz[N];
bool odd[N], par[N];

int root(int u) {
    while(u != dsu[u]) u = dsu[u];
    return u;
}

int get_par(int u) {
    int p = 0;
    while(u != dsu[u]) {
        p ^= par[u];
        u = dsu[u];
    }
    return p;
}

void uni(int u,int v) {
    int uu = root(u), vv = root(v);
    if(uu == vv) {
        if(get_par(u) == get_par(v))
            odd[uu] = 1;
        return;
    }
    if(sz[uu] > sz[vv]) {
        swap(uu, vv), swap(u, v);
    }
    dsu[uu] = vv;
    sz[vv] += sz[uu];
    odd[vv] |= odd[uu];
    par[uu] = get_par(u) ^ get_par(v) ^ 1;
}

void solve() {
	int n, m;
    sc(n, m);
    fr(i, 1, n) {
        sz[i] = 1;
        dsu[i] = i;
        odd[i] = 0;
        par[i] = 0;
    }
    fr(i, 1, m) {
        int u, v;
        sc(u, v);
        uni(u, v);
    }
    int c1 = 0, c2 = 0, c3 = 0;
    fr(i, 1, n) {
        if(i == dsu[i]) {
            if(sz[i] == 1) {
                c1++;
            }
            else if(odd[i]) {
                c2++;
            }
            else {
                c3++;
            }
        }
    }
    ll ans = 0;
    while(c1) {
        ans += 2 * n - 1;
        n--;
        c1--;
    }
    while(c2) {
        ans += 2 * (c2 + c3) - 1;
        c2--;
    }
    ans += (c3 * 1LL * (c3 - 1)) * 2 + 2LL * c3;
    cout << ans;
}

int main() {
	ios :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	// cin >> t;
	for(int tt = 1; tt <= t; tt++) {
		solve();
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

struct UnionFind{
  int num;
  vector<int> rs,ps;
  UnionFind(){}
  UnionFind(int n):num(n),rs(n,1),ps(n,0){iota(ps.begin(),ps.end(),0);}
  int find(int x){
    return (x==ps[x]?x:ps[x]=find(ps[x]));
  }
  bool same(int x,int y){
    return find(x)==find(y);
  }
  void unite(int x,int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(rs[x]<rs[y]) swap(x,y);
    rs[x]+=rs[y];
    ps[y]=x;
    num--;
  }
  int size(int x){
    return rs[find(x)];
  }
  int count() const{
    return num;
  }
};

//INSERT ABOVE HERE
signed main(){
  int n,m;
  cin>>n>>m;
  UnionFind uf(n),bp(n*2);
  for(int i=0;i<m;i++){
    int u,v;
    cin>>u>>v;
    u--;v--;
    uf.unite(u,v);
    bp.unite(u+0,v+n);
    bp.unite(u+n,v+0);
  }
  using ll = long long;
  ll odd=0,eve=0,iso=0;
  for(int i=0;i<n;i++){
    if(uf.find(i)!=i) continue;
    if(uf.size(i)==1){
      iso++;
      continue;
    }
    if(bp.same(i,i+n)) odd++;
    else eve++;
  }
  ll ans=(ll)n*n-(n-iso)*(n-iso);
  ans+=(odd+eve)*(odd+eve);
  ans+=eve*eve;
  cout<<ans<<endl;
  return 0;
}


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

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

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

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

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

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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

void solve() {
    double n, m, d; cin >> n >> m >> d;
    double k = d==0 ? 1 : 2;
    cout << k*(n-d)*(m-1)/n/n << endl;
}

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

#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

    // cout << 1.0 / 2 << endl;

    int n, m, d; cin >> n >> m >> d;

    // 隣り合う二項はm-1個ある
    // (a, b)並んでいた場合の期待値を求めて、それをm-1倍する

    double ans = 0.0;

    double e = 0.0;

    if (d == 0) {
        e = double(1.0) / n;
    } else {
        e = double(2.0);
        ll n2 = ll(n) * n;
        e *= (n-d);
        e /= n2;
    }
    cout << e * (m-1) << endl;
    return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll A[2], B[2];

int main()
{
  rep( i, 2 )
    std::cin >> A[i];
  rep( i, 2 )
    std::cin >> B[i];

  std::cout << std::min(A[0], A[1])+std::min(B[0], B[1]) << std::endl;

  return 0;
}

#include <iostream>
using namespace std;

int main (void){
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    if(a <= b) {
        if(c < d){
            cout << a + c << endl;
        }else{
            cout << a + d << endl;
        }
    }else{
        if(c < d){
            cout << b + c << endl;
        }else{
            cout << b + d << endl;
        }
    }

    return 0;
}


#include <cstdio>
#include <iostream>
#define debug(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
inline char nc() {
    return getchar();
    static char buf[100000], *l = buf, *r = buf;
    return l==r&&(r=(l=buf)+fread(buf,1,100000,stdin),l==r)?EOF:*l++;
}
template<class T> void read(T &x) {
    x = 0; int f = 1, ch = nc();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=nc();}
    while(ch>='0'&&ch<='9'){x=x*10-'0'+ch;ch=nc();}
    x *= f;
}
typedef long long LL;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 50;
int n;
char s[maxn];
int a[maxn];
int solve() {
    n <<= 1;
    for(int i = 1; i <= n; ++i) {
        a[i] = s[i] == 'B';
    }
    for(int i = n; i >= 1; --i) {
        a[i] ^= a[i - 1];
    }
    a[0] = 1;
    for(int i = 1; i <= n; ++i) {
        a[i] ^= a[i - 1] ^ 1;
    }
    int an = 1, cnt = 0;
    for(int i = 1; i <= n; ++i) {
        if(a[i]) ++cnt;
        else {
            if(cnt == 0) return 0;
            an = (LL)an * cnt % mod;
            --cnt;
        }
    }
    if(cnt) return 0;
    n >>= 1;
    for(int i = 1; i <= n; ++i) {
        an = (LL)an * i % mod;
    }
    return an;
}
int main() {
    read(n);
    scanf("%s", s + 1);
    printf("%d\n", solve());
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(),(v).end()
#define vc vector
#define sz(v) (int)(v).size()
#define pb push_back
#define FF first
#define SS second
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define pll pair<ll,ll>
#define fi first
#define se second
#define pii pair<int,int>
typedef long long ll;
typedef long double f80;
#define endl '\n'

const int mod = 1e9 + 7;
const int N = 2e5 + 5;
char s[N];
bool x[N];

int main(){

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin >> n;
	fr(i, 1, 2 * n) {
		cin >> s[i];
	}
	int ans = 1;
	fr(i, 1, n) {
		ans = (ans * 1LL * i) % mod;
	}
	s[0] = 'W';
	s[2 * n + 1] = 'W';
	fr(i, 0, 2 * n) {
		if(s[i] != s[i + 1])
			x[i] = 1;
	}
	int cl = 0, cr = 0, val = 0;
	bool pos = 1;
	fr(i, 1, 2 * n) {
		if(x[i - 1]) {
			cl++;
			val++;
		}
		else {
			x[i] ^= 1;
			cr++;
			if(!val) pos = 0;
			ans = (ans * 1LL * val) % mod;
			val--;
		}
	}
	if(!pos || (cl != cr && cl != n)) {
		cout << 0;
		return 0;
	}
	cout << ans;
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
//#define N 131072 //100000
#define MAXVAL 2147483647 //((long int) ((unsigned long) (1 << 31) - 1))  //*2
int min(int a, int b){return a>b?b:a;}
int max(int a, int b){return a>b?a:b;}
int data[2*131072+100];      //the size of array, for present the tree

//range update and single query

/*
always binary [node_left,node_right]
from top to bottom
*/
void update(int update_left, int update_right, int x, int current_node,int node_left,int node_right){
	//not in the range
	if(update_right<node_left||update_left>node_right){
		return;
	}else if(update_left<=node_left&&update_right>=node_right){
		data[current_node] = x;
	}else{
		//how to check if the
		//unfold the node, the amxValue->-1
		if(data[current_node]!=-1){ //-1: unfold
			//update(node_left, node_right,data[current_node],current_node*2+1,node_left,(node_left+node_right)/2);
			//update(node_left, node_right,data[current_node],current_node*2+2,(node_left+node_right)/2+1, node_right);
			data[2*current_node+1] = data[current_node];
            data[2*current_node+2] = data[current_node];
			data[current_node]=-1;
		}
		//update
		update(update_left, update_right, x, current_node*2+1,node_left,(node_left+node_right)/2);
		update(update_left, update_right, x, current_node*2+2,(node_left+node_right)/2+1, node_right);
	}
}
//segment of thr last layer
//I did notdeal with 0
//backtrack the tree from the bottom,
//just update one time
void update2(int x, int node_id,int node_left, int node_right){//x begin from data[0], node_id from 1
	if(x!=-1){
		data[node_id] = x;
	}
	//printf("%d %d %d\n",node_left,node_right,node_id);
	if(node_left==node_right) {
		return;
	}
	if(data[node_id]!=-1){
		//printf("%d\n",data[node_id]);
		update2(data[node_id], node_id*2+1,node_left, (node_left+node_right)/2);
		update2(data[node_id], node_id*2+2,(node_left+node_right)/2+1, node_right);
		data[node_id]=-1;
	}
	else {
		update2(-1, node_id*2+1,node_left, (node_left+node_right)/2);
		update2(-1, node_id*2+2,(node_left+node_right)/2+1, node_right);
	}

}
//search from top to bottom
int search(int search_left,int search_right, int current_node, int node_left, int node_right){
	if(search_right < node_left || search_left > node_right){
        return -1;//not in the range
	}
	else if(search_left >= node_left && search_right <= node_right&&data[current_node]>=0){//??
		return data[current_node];//for the folded node which parent present the minimal of their children
	}else {
		int left = search(search_left, search_right,current_node*2+1, node_left,(node_left+node_right)/2);
		int right = search(search_left, search_right,current_node*2+2, (node_left+node_right)/2+1, node_right);
		return max(left,right);
	}

}
int main(){
	int n, q;
	FILE *fp = fopen("in.txt","r");
	scanf("%d %d",&n,&q);
	int N = 1;
	while(N<n) N = N<<1;
	if(n==1) N=2;
	for(int i = 0; i<=2*N-2; i++){
		data[i] = MAXVAL;
	}
	//printf("%d",(-1/2));
	for(int i = 0; i<q; i++){
		int temp = 0;
		scanf("%d", &temp);
		int a,b,c;

		if(temp == 0) {  //update
			scanf("%d %d %d",&a,&b,&c);
			update(a,b,c,0,0,N-1);

		} else if(temp == 1){ //search
			scanf("%d",&a);
			printf("%d\n",search(a,a,0,0,N-1));
		}
	}

	return 0;
}


#include<iostream>
#include<string>

using namespace std;

void sort(int card[5])
{
	for(int i=0;i<5;i++)
	{
		int max=i;
		for(int j=i+1;j<5;j++)
		{
			if(card[max]<card[j])
			{
				max=j;
			}
		}
		int tmp=card[i];
		card[i]=card[max];
		card[max]=tmp;
	}
}

bool fourcard(int card[5])
{
	if((card[0]==card[1]&&card[1]==card[2]&&card[2]==card[3])||
		(card[1]==card[2]&&card[2]==card[3]&&card[3]==card[4]))
	{
		return true;
	}
	else
	{
		return false;
	}
}

bool fullhouse(int card[5])
{
	if((card[0]==card[1]&&card[2]==card[3]&&card[3]==card[4])||
		(card[0]==card[1]&&card[1]==card[2]&&card[3]==card[4]))
	{
		return true;
	}
	else
	{
		return false;
	}
}

bool straight(int card[5])
{
	if((card[0]-1==card[1]&&card[1]-1==card[2]&&card[2]-1==card[3]&&card[3]-1==card[4])||
		(card[0]==13&&card[1]==12&&card[2]==11&&card[3]==10&&card[4]==1))
	{
		return true;
	}
	else
	{
		return false;
	}
}

bool threecard(int card[5])
{
	if((card[0]==card[1]&&card[1]==card[2])||
		(card[1]==card[2]&&card[2]==card[3])||
		(card[2]==card[3]&&card[3]==card[4]))
	{
		return true;
	}
	else{
		return false;
	}
}

bool twopair(int card[5])
{
	if((card[0]==card[1]&&card[2]==card[3])||
		(card[0]==card[1]&&card[3]==card[4])||
		(card[1]==card[2]&&card[3]==card[4]))
	{
		return true;
	}
	else return false;
}

bool onepair(int card[5])
{
	if(card[0]==card[1]||
		card[1]==card[2]||
		card[2]==card[3]||
		card[3]==card[4])
	{
		return true;
	}
	else return false;
}

char *solve(int card[5])
{
	sort(card);
	if(fourcard(card))
	{
		return "four card";
	}
	else if(fullhouse(card))
	{
		return "full house";
	}
	else if(straight(card))
	{
		return "straight";
	}
	else if(threecard(card))
	{
		return "three card";
	}
	else if(twopair(card))
	{
		return "two pair";
	}
	else if(onepair(card))
	{
		return "one pair";
	}
	else
	{
		return "null";
	}
}

int main(void)
{
	int card[5];
	char c;
	while(cin>>card[0])
	{
		for(int i=1;i<5;i++)
		{
			cin>>c>>card[i];
		}
		cout<<solve(card)<<endl;
	}
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
constexpr int INF = 2e9 + 1;
int main() {
  int n, l, q;
  cin >> n;
  vector<int> x(n);
  rep(i,n) cin >> x[i];
  cin >> l >> q;
  vector<vector<int>> to(32, vector<int>(n, 0));
  x.emplace_back(INF);
  rep(i, n) {
    auto itr = lower_bound(x.begin(), x.end(), x[i] + l);
    if (*itr > x[i] + l) itr--;
    to[0][i] = itr - x.begin();
  }
  for (int i = 0; i < 31; i++) {
    for (int j = 0; j < n; j++) to[i + 1][j] = to[i][to[i][j]];
  }

  while (q--) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    if (a > b) swap(a, b);
    int res = 0;
    for (int i = 31; i >= 0; i--) {
      if (to[i][a] < b) {
        res += 1 << i;
        a = to[i][a];
      }
    }
    cout << res + 1 << endl;
  }
  return 0;
}


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

typedef unsigned long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)
#define MOD 998244353
#define int ll

int N,K;

int fac[5001];

int exp(int a,int b){
	int res = 1;

	while (b > 0){
		if (b&1){
			res *= a;
			res %= MOD;
		}

		b >>= 1;
		a *= a;
		a %= MOD;
	}
	return res;
}

int modinv(int A,int B){
	A %= MOD;
	B = exp(B,MOD-2);
	A *= B;
	A %= MOD;
	return A;
}

int nchoosek(int n,int k){
	if (n < k) return 0;
	return modinv(fac[n],(fac[k] * fac[n-k]) % MOD);
}

int32_t main(){
	fast;

	cin>>K>>N;

	fac[0] = 1;
	FOR(i,1,4999){
		fac[i] = (fac[i-1] * i) % MOD;
	}
	int num = nchoosek(N + K - 1,N);

	//cout<<num<<'\n';
	FOR(k,2,2*K){
		int pairs = 0;
		FOR(i,1,K){
			if (1 <= k - i && k-i <= K) pairs++;
		}
		if (k % 2 == 0) pairs++;
		pairs /= 2;

		//cout<<pairs<<'\n';

		int ans = num;
		FOR(i,1,pairs){
			int val = (nchoosek(N - i * 2 + K - 1,N - i * 2) * nchoosek(pairs,i)) % MOD;
			if (i % 2 == 0) ans = (ans + val) % MOD;
			else ans = (ans - val + MOD)%MOD;
		}

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

}

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

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    long long int res = 0;
    for (int i = 0; i < (1 << n); i++) {
        string s1, s2;
        for (int j = 0; j < n; j++) {
            if ((i >> j) % 2 == 1) {
                s1.push_back(s[j]);
            } else {
                s2.push_back(s[j]);
            }
        }
        // reverse(s2.begin(), s2.end());

        int n1 = s1.size(), n2 = s2.size();
        vector<vector<int>> v(n1 + 1, vector<int>(n2 + 1, 0));
        v[0][0] = 1;
        for (int a = 0; a <= n1; a++) {
            for (int b = 0; b <= n2; b++) {
                if (v[a][b] == 0) continue;
                if (a < n1) {
                    if (s[2 * n - 1 - a - b] == s1[a]) {
                        v[a + 1][b] += v[a][b];
                    }
                }
                if (b < n2) {
                    if (s[2 * n - 1 - a - b] == s2[b]) {
                        v[a][b + 1] += v[a][b];
                    }
                }
            }
        }
        res += v[n1][n2];
    }
    cout << res << endl;
}


#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
using namespace std; const int N=200010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
int n,Y;
signed main()
{
    n=read(), Y=read();
    for(ri int i=0;i<=Y/10000;i++)
    for(ri int j=0;j<=Y/5000&&i+j<=n;j++)
    if(i*10000+j*5000+(n-i-j)*1000==Y)
    {
        printf("%lld %lld %lld\n",i,j,n-i-j);
        return 0;
    }
    puts("-1 -1 -1");
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{ string s;
long long d,sum=0,num;
cin>>s;
long long n=s.size();
for(int i=0 ; i<n ; i++){
     d = s[i] - '0';
    num = num * 10 + d;
sum+=d;
}
if(num%(sum)==0) cout<< "Yes"<<  endl;
if(num%(sum)!=0) cout<< "No"<<  endl;

return 0;

}


#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
using namespace std;
int main(){
	int n,m;
	cin>>n>>m;
	vi in(n);
	rep(i,n)cin>>in[i];
	vi out(n,0);
	rep(i,m){
		int a;
		cin>>a;
		rep(j,n)if(a>=in[j]){
			out[j]++;
			break;
		}
	}
	int ma=-1;
	rep(i,n)ma=max(ma,out[i]);
	rep(i,n)if(ma==out[i])cout<<i+1<<endl;

	}

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

int main() {
  ll n, x;
  cin >> n >> x;
  V<ll> a(n);
  rep(i, n) cin >> a[i];

  ll ans = 0;
  for (int i = 1; i < n; i++) {
    if (a[i - 1] + a[i] <= x) continue;
    ll diff = a[i - 1] + a[i] - x;
    ll eat = min(a[i], diff);
    ans += eat;
    a[i] -= eat;
  }
  if (a[0] > x) ans += a[0] - x;
  cout << ans << endl;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
  int n; cin >> n;
  while(n)
  {
    if(n%10 == 7)
    {
      cout << "Yes" << endl;
      return 0;
    }
    n/=10;
  }
  cout << "No" << endl;
  return 0;
}

#include <bits/stdc++.h>

const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;

typedef long long ll;

#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FORD(i, a, b) for (int i = b - 1; i >= int(a); i--)
#define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)

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

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

int main()
{
    string s;
    cin >> s;
    string ans = "No";
    REP(i, 3)
    if (s[i] == '7')
        ans = "Yes";
    cout << ans << endl;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> P;

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

ll mod = 1000000007;
int main(){
  int n; cin >> n;
  vector <ll> a(n);
  rep(i, n){
    cin >> a[i];
    a[i]++;
  }
  vector <ll> num(n+1);
  num[0] = 3;
  ll ans = 1;
  rep(i, n){
    if (num[a[i]-1] < 0){
      cout << 0 << endl;
      return 0;
    }
    ans *= num[a[i]-1];
    ans %= mod;
    num[a[i]-1]--;
    num[a[i]]++;
  }
  cout << ans <<endl;
}

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

typedef long long ll;
static const int MAX = 510000;
static const ll MOD = 1000000007;

int main(){
    int N;
    cin>>N;
    vector<ll> A(N);
    for(int i=0; i<N; i++) cin>>A[i];
    vector<ll> color(3,0);

    ll ans = 1;

    for(int i=0; i<N; i++){
        ll kake = 0;
        for(int j=0; j<3; j++){
            if(color[j] == A[i]) kake++;
        }

        ans *= kake;
        ans %= MOD;

        for(int j=0; j<3; j++){
            if(color[j] == A[i]){
                color[j]++;
                break;
            }
        }
    }

    cout<<ans<<endl;
}


#include <iostream>
#include<algorithm>
#include<utility>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
#define srep(i,s,t) for (int i = s; i < t; i++)
#define rng(a) a.begin(),a.end()
typedef long long ll;

using namespace std;

int main() {
    int l, r;
    cin>>l>>r;
    int mx = min(2018,r-l);
    int ans = 9999;
    for(int i = l+mx; i > l; i--){
        for(int j = l; j < i; j++){
            ans = min(ans,((i%2019)*(j%2019))%2019);
        }
    }
    cout<<ans<<endl;

    return 0;
}

#include <iostream>
#include <string>
#include <math.h>
#include <stdio.h>
#include <ctype.h>

using namespace std;

int main() {
    int M[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};
    string W[7]={"Monday",
        "Tuesday",
        "Wednesday",
        "Thursday",
        "Friday",
        "Saturday",
        "Sunday"};

    int x,y;
    while(scanf("%d%d",&x,&y)!=EOF){
        if(x==0||y==0){
            break;
        }
        int day=0;
        for(int i=1; i<x; i++){
            day+=M[i];
        }
        day+=y+2;
        int week = day % 7;
        cout<<W[week]<<endl;

    }
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll max(ll a, ll b){
	if(a>b)return a;
	else return b;
}

int main(){
    int d,t,s;
    cin>>d>>t>>s;
    if(t*s>=d){
    	cout<<"Yes"<<endl;
	}else
	cout<<"No"<<endl;
}

//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
using namespace std;
typedef long long ll;
#define free  freopen ("input.txt", "r", stdin);freopen ("output.txt", "w", stdout);
#define Fast  ios::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second

bool vowel(char che)
{
    if (che == 'A' || che == 'E' || che == 'I' || che == 'O' || che == 'U' || che == 'Y')
        return true;
    else
        return false;
}

const int N = 1e6+5;
const int mod = 1e9+7;
ll a[N], b[N], c[N], d, dp[N], dis;
//pair <ll, ll> p[N], p1[N];
char o;
bool mark[N], h;
string s;
//stack <int> st;
//set <ll> st1, st2;
//deque <int> dq;
//vector <ll> vm, vp, vt[N];
//int a1[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int main()
{
    Fast
    ll t, n, m, k = 0, f = 0, sum = 0, ans = 0;
    cin >> n >> m >> k;
    f = (n+k-1)/k;
    if (m >= f)
        cout << "Yes\n";
    else
        cout << "No\n";
}


#include <iostream>
#include <cstdio>

using namespace std;

double l[10];
double v1, v2;

int main()
{
  while (scanf("%lf", &l[0]) == 1) {
    int sum = l[0];
    for (int i = 1; i < 10; i++) {
      scanf(",%lf", &l[i]);
      sum += l[i];
    }
    scanf(",%lf,%lf", &v1, &v2);

    double x = (sum * v1) / (v1 + v2);

    int c;
    for (c = 0; x > 0; c++) {
      x -= l[c];
    }

    printf("%d\n", c);
  }
  return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
#include <deque>
#include <functional>
using namespace std;
typedef long long ll;

#define fi first
#define se second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define debugA cerr << "AAAAA" << endl
#define debug_ cerr << "-------------" << endl
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                   \
    cout << #v << endl;                \
    for (int i = 0; i < v.size(); i++) \
    {                                  \
        cout << v[i] << " ";           \
    }                                  \
    cout << endl;
#define debug_vec2(v)                         \
    cout << #v << endl;                       \
    for (int i = 0; i < v.size(); i++)        \
    {                                         \
        for (int j = 0; j < v[i].size(); j++) \
        {                                     \
            cout << v[i][j] << " ";           \
        }                                     \
        cout << endl;                         \
    }

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

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

template <typename T>
void quit(T a)
{
    cout << a << endl;
    exit(0);
}

using Graph = vector<vector<int>>;
using P = pair<int, int>;
using P1 = pair<int, pair<int, int>>; // クラスカル法とかで、{cost, {from, to}}的に使う。
const ll LINF = 10010020030040056ll;
const int INF = 1001001001;
const double pi = acos(-1);

void MergeSort(vector<int> &a, int left, int right)
{
    if (right - left == 1)
        return;

    int mid = (right + left) / 2;
    MergeSort(a, left, mid);
    MergeSort(a, mid, right);
    int i = left;
    int j = mid;
    vector<int> tmp;
    while (true)
    {
        if (i == mid && j == right)
        {
            break;
        }
        else if (i == mid)
        {
            tmp.push_back(a.at(j));
            j++;
            continue;
        }
        else if (j == right)
        {
            tmp.push_back(a.at(i));
            i++;
            continue;
        }
        if (a[i] <= a[j])
        {
            tmp.push_back(a.at(i));
            i++;
        }
        else
        {
            tmp.push_back(a.at(j));
            j++;
        }
    }
    for (int i1 = left; i1 < right; i1++)
    {
        a.at(i1) = tmp.at(i1 - left);
    }
}

int main()
{
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> vec(n);
    for (int i = 0; i < n; i++)
    {
        vec[i] = {0, 0};
    }
    for (int i = 0; i < m; i++)
    {
        int a;
        string s;
        cin >> a >> s;
        a--;
        if (s == "WA" && vec[a].fi == 0)
        {
            vec[a].se++;
        }
        else if (s == "WA")
        {
            continue;
        }
        else
        {
            vec[a].fi++;
        }
    }
    int ac = 0;
    int wa = 0;
    for (int i = 0; i < n; i++)
    {
        if (vec[i].fi != 0)
        {
            ac++;
            wa += vec[i].se;
        }
    }
    cout << ac << " " << wa << endl;

    return 0;
}

#include <bits/stdc++.h>
#include <string>
//#define local
#ifdef local
#include "dbg-macro/dbg.h"
#endif
#define ll long long
#define pi (acos(-1))
#define rep(i, n) for (unsigned long long i = 0; i < (unsigned long long)(n); ++i)
using namespace std;
std::vector<unsigned ll> genprimevec(const unsigned ll N);

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> wavec(n, 0);
    vector<bool> aced(n, false);
    ll ac = 0;
    ll wa = 0;
    while (m--)
    {
        int p;
        string s;
        cin >> p >> s;
        if (aced[p]) { continue; }
        if (s == "AC")
        {
            aced[p] = true;
            ++ac;
            wa += wavec[p];
        }
        else
        {
            wavec[p]++; // WA
        }
    }

    cout << ac << ' ' << wa << endl;
    return 0;
}

ll extgcd(ll a, ll b, ll &x, ll &y)
{
    if (b == 0)
    {
        x = 1, y = 0;
        return a;
    }
    ll d = extgcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
}

std::vector<unsigned ll> genprimevec(const unsigned ll N)
{
    std::vector<bool> is_prime(N + 1);
    for (unsigned ll i = 0; i <= N; i++) { is_prime[i] = true; }
    std::vector<unsigned ll> P;
    for (unsigned ll i = 2; i <= N; i++)
    {
        if (is_prime[i])
        {
            for (unsigned ll j = 2 * i; j <= N; j += i) { is_prime[j] = false; }
            P.emplace_back(i);
        }
    }
    return P;
}


#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std; using ll = long long;
using ull = unsigned long long; using P = pair<int, int>;
const int INF = 1e9; const int MOD = 1000000007;
const int dx[] = {-1,0,1,0}; const int dy[] = {0,-1,0,1};
//const int dx[] = {-1,-1,-1, 0, 0, 1, 1, 1}; const int dy[] = {-1, 0, 1,-1, 1,-1, 0, 1};
#define PI 3.14159265358979323846264338327950L //setprecision(15)
#define MAX_N 100000
int main() {
	string s; cin >> s;
	int ans = INF;
	for (int i = 0; i < s.length() - 2; i++) {
		int tmp = (s[i] - '0') * 100;
		tmp += (s[i+1] - '0') * 10;
		tmp += (s[i+2] - '0');
		ans = min(ans, max(tmp-753, 753-tmp));
	}
	cout << ans << endl;
}

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

typedef long long ll;

main()
{
    string s, sub;
    int a;
    vector<int> v;
    cin >> s;
    for(int i = 0; i < s.size()-2; i++){
        sub = s.substr(i, 3);
        a = stoi(sub);
        v.push_back(abs(753-a));
    }
    sort(v.begin(), v.end());
    cout << v.front();
}

///promy_pompom
//hello world


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

#define MAX_N 10000
int prime[MAX_N];
bool is_prime[MAX_N+1];
int sieve(int n){
	int p=0;
	memset(is_prime,true,sizeof(is_prime));
	is_prime[0]=is_prime[1]=false;
	for(int i=2;i<=n;i++){
		if(is_prime[i]){
			prime[p++]=i;
			for(int j=2*i;j<=n;j+=i)is_prime[j]=false;
		}
	}
	return p;
}

int main(){
	sieve(MAX_N);
	vector<int> p;
	for(int i=2;i<=MAX_N-2;i++)
		if(is_prime[i]&&is_prime[i+2])p.push_back(i+2);
	int n;
	while(cin>>n&&n){
		int a=upper_bound(p.begin(),p.end(),n)-p.begin();
		cout<<p[a-1]-2<<' '<<p[a-1]<<endl;
	}
	return 0;
}

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

int main(){
  int m, nmin, nmax;
  while(cin >> m >> nmin >> nmax, m || nmin || nmax){
    nmin--;
    nmax--;
    vector<int> v(m);

    for(int i = 0; i < m; i++){
      cin >> v[i];
    }

    pair<int, int> ans = make_pair(0, 0);

    for(int i = nmin; i <= nmax; i++){
      if(v[i] - v[i + 1] >= ans.second){
        ans = make_pair(i + 1, v[i] - v[i + 1]);
      }
    }
    cout << ans.first << endl;
  }
}


#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>
#include <random>
#include <vector>
#include <unordered_map>
#include <bitset>

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

LL mod = 998244353;

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

  LL N;
  cin >> N;
  vector<LL> a(N);

  LL sum = 0;

  REP(i,N){
    cin >> a[i];
    sum += a[i];
  }
  //bound
  sum = (sum - 1) / 2 + 1;

  vector<vector<LL>> v(a.size()+1, vector<LL>(100001, 0));
  v[0][0] = 1;

  REP(i,a.size()){
    REP(j,90001){
      v[i + 1][j] += v[i][j]*2;
      v[i + 1][j+a[i]] += v[i][j];
      v[i + 1][j] %= mod;
      v[i + 1][j + a[i]] %= mod;
    }
  }

  LL ans = 1;

  REP(i,a.size()){
    ans *= 3;
    ans %= mod;
  }

  FOR(i,sum,90001){
    ans -= v[a.size()][i] * 3;
    ans %= mod;
    ans += mod;
    ans %= mod;
  }

  vector<vector<LL>> vv(a.size()+1, vector<LL>(100001, 0));
  vv[0][0] = 1;

  REP(i,a.size()){
    REP(j,90001){
      vv[i + 1][j] += vv[i][j];
      vv[i + 1][j+a[i]] += vv[i][j];
      vv[i + 1][j] %= mod;
      vv[i + 1][j + a[i]] %= mod;
    }
  }

  FOR(i,sum,90001){
    ans += vv[a.size()][i] * 3 *2;
    ans %= mod;
    ans += mod;
    ans %= mod;
  }

  LL cnt = 3;

  REP(i,a.size()){
    cnt *= 2;
    cnt %= mod;
  }

  ans -= cnt;
  ans %= mod;
  ans += mod;
  ans %= mod;

  cout << ans << endl;
}

#include<bits/stdc++.h>
#define inv(x) power(x,Mod-2)
#define upd(a,b) a=add(a,b)
using namespace std;
typedef long long ll;
const int Mod=1e9+7;
int add(int a,const int b){a+=b;if(a>=Mod)a-=Mod;return a;}
int sub(int a,const int b){a-=b;if(a<0)a+=Mod;return a;}
int mul(const int a,const int b){return (ll)a*b%Mod;}
int power(int x,int cs)
{
	int ras=1;
	while(cs)
	{
		if(cs&1) ras=mul(ras,x);
		x=mul(x,x);cs>>=1;
	}
	return ras;
}
const int N=2020;
int n,K,tot,ans=0;
int dp[N][N],sum[N],zp[N*N],fp[N*N];
int C(int a,int b)
{
	if(a<0||b<0||a<b) return 0;
	return mul(zp[a],mul(fp[b],fp[a-b]));
}
int main()
{
	int i,j;
	scanf("%d%d",&n,&K);
	if(K==1)
	{
		puts("1");
		return 0;
	}
	tot=n*K;
	zp[0]=fp[0]=1;
	for(i=1;i<=tot;i++) zp[i]=mul(zp[i-1],i);
	fp[tot]=inv(zp[tot]);
	for(i=tot-1;i>=1;i--) fp[i]=mul(fp[i+1],i+1);
	dp[1][0]=1;
	for(i=2;i<=n;i++)
	{
		memset(sum,0,sizeof(sum));
		for(j=0;j<=i;j++)
		{
			if(j>0) sum[j]=sum[j-1];
			upd(sum[j],dp[i-1][j]);
		}
		for(j=0;j<i;j++)
		{
			upd(dp[i][j],mul(sum[j],C(i*(K-1)+j-1,K-2)));
		}
	}
	for(i=0;i<=n;i++) upd(ans,dp[n][i]);
	ans=mul(ans,zp[n]);
	printf("%d",ans);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ll long long
long long min(long long x,long long y){return (x<y ? x:y);}
long long max(long long x,long long y){return (x>y ? x:y);}
#define ld long double
int stoi(string s) {return atoi(s.c_str());}
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
#define LINEY "YES\n"
#define Liney "Yes\n"
#define LINEN "NO\n"
#define Linen "No\n"

void func(ll* x,ll* y){
  *x -= (*x%2);
  *x /= 2;
  *y += *x;
}

int main(){
  ll A,B;
  int K;
  cin >> A>>B>>K;
  bool turn_A = true;
  REP(i,K){
    if(turn_A){func(&A,&B);}
    else{func(&B,&A);}
    turn_A = !turn_A;
  }
  printf("%d %d\n",A,B);
}

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

int main(){
    ll a, b, k;
    cin >> a >> b >> k;
    rep(i, k) {
        if ( i & 1 ) {
            if ( b & 1 ) {
                --b;
            }
            a += b / 2;
            b /= 2;
        }
        else {
            if ( a & 1 ) {
                --a;
            }
            b += a / 2;
            a /= 2;
        }
    }

    cout << a << " " << b << endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<int>>;
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
struct edge{ll to, cost;};
typedef pair<ll,ll> P;
struct graph{
  ll V;
  vector<vector<edge> > G;
  vector<ll> d;

  graph(ll n){
    init(n);
  }

  void init(ll n){
    V = n;
    G.resize(V);
    d.resize(V);
    rep(i,V){
      d[i] = INF;
    }
  }

  void add_edge(ll s, ll t, ll cost){
    edge e;
    e.to = t, e.cost = cost;
    G[s].push_back(e);
  }

  void dijkstra(ll s){
    rep(i,V){
      d[i] = INF;
    }
    d[s] = 0;
    priority_queue<P,vector<P>, greater<P> > que;
    que.push(P(0,s));
    while(!que.empty()){
      P p = que.top(); que.pop();
      ll v = p.second;
      if(d[v]<p.first) continue;
      for(auto e : G[v]){
        if(d[e.to]>d[v]+e.cost){
          d[e.to] = d[v]+e.cost;
          que.push(P(d[e.to],e.to));
        }
      }
    }
  }
};
int main(){
  ll n; cin>>n;
  ll a[n]={};
  ll b[65]={};
  rep(i,n){
    cin>>a[i];}
  ll ans = 0;
  rep(i,n){
    bitset<61> s(a[i]);
    rep(j,61){
      if(s.test(j))b[j]++;}
  }
  ll k = 1;
  rep(i,61){
    ll m = b[i]*(n-b[i]);
    m%=MOD;
    ans += m*k;
    k*=2;
    k%=MOD;
  ans%=MOD;}
  cout << ans << endl;}

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

using namespace std;

template<typename T>
long long modpow(const T n,const T p,const T mod);
template<typename T>
long long modinv(const T n,const T mod);
template<typename T>
bool chmax(T &a,const T &b);
template<typename T>
bool chmin(T &a,const T &b);

long long inf=1000000007;

int main(){
	long long n;
	cin>>n;
	vector<long long> zero(62,0),one=zero;

	for(long long i=0;i<n;i++){
		long long hoge;
		cin>>hoge;
		bitset<62> bit=hoge;

		for(long long i=0;i<62;i++){
			if(bit.test(i)) one.at(i)++;
			else zero.at(i)++;
		}
	}

	long long ans=0;
	long long two=1;

	for(long long i=0;i<62;i++){
		ans+=(two*zero.at(i))%inf*one.at(i);
		ans%=inf;
		two*=2;
		two%=inf;
	}

	cout<<ans<<endl;

	return 0;
}

template<typename T>
long long modpow(const T n,const T p,const T mod){
	if(p==0) return 1;
	if(p%2==0){
		long long a=modpow(n,p/2,mod);
		return a*a%mod;
	}
	if(p%2==1) return (modpow(n,p-1,mod)*n)%mod;
	cerr<<"ERROR"<<endl;
	return 1;
}

template<typename T>
long long modinv(const T n,const T mod){
	return modpow(n,mod-2,mod);
}

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

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


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp>
//#include <functional> // for less
#define PI acos(-1.0)
#define eps 1e-9
#define ll long long
#define ull unsigned long long
#define nl printf("\n")
#define sf scanf
#define pf printf
#define INF (ll)1e15
#define mod 1000000007

///#define isValid(n,m,nx,ny)nx>=0&&nx<n&&ny>=0&&ny<m
///int kx[]={1, 1, -1, -1, 2, 2, -2, -2}; //knight moves
///int ky[]={2,-2,  2, -2, 1,-1,  1, -1}; //knight moves
///int dx[]={1,-1,0,0,1,-1,1,-1};//eight direction
///int dy[]={0,0,1,-1,1,-1,-1,1};//eight direction

///using namespace __gnu_pbds;
using namespace std;

///inline double toRad(double deg){return deg*PI/180;}
///inline double toDeg(double rad){return rad*180/PI;}
///typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;

const int S=123456;
int main()
{
    #ifndef ONLINE_JUDGE
    //freopen("input.txt","r",stdin);
    #endif
    ll n,a,b;
    while(sf("%lld %lld %lld",&n,&a,&b)==3)
    {
        ll ara[n+5];
        for(int i=0;i<n;i++)sf("%lld",&ara[i]);

        ll ans=0;
        for(int i=0;i<n-1;i++)
        {
            ll dis=ara[i+1]-ara[i];
            if(dis*a<=b)ans+=(dis*a);
            else ans+=b;
        }
        pf("%lld\n",ans);
    }
    return 0;
}

#include <bits/stdc++.h>
//#include <atcoder/all>
#define ll long long int
#define MOD 1000000007
#define P pair<ll,ll>
#define INF 1000000000000000000

//using namespace atcoder;
using namespace std;

int main(void){
  ll n, a, b;
  cin >> n >> a >> b;

  vector<ll> x(n);
  for (int i = 0; i < n; i++){
    cin >> x[i];
  }
  ll ans = 0;
  for (int i = 0; i < n-1; i++){
    ans += min(a*(x[i+1]-x[i]), b);
  }
  cout << ans << endl;

  return 0;
}


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

#define MAX_N 3700000

int prime[MAX_N], twin[MAX_N];

void isprime(int c) {
	prime[2] = 1;
	for (int i = 3; i < c; i += 2) {
		for (int j = 3; j <= sqrt(i); j += 2) {
			if (i%j == 0) {
				goto E;
			}
		}
		prime[i] = 1;
	E:;
	}
}

void istwin(int d) {
	for (int i = 5; i < d; i++) {
		if (prime[i - 2] + prime[i] == 2) {
			twin[i] = i;
		}
		else {
			twin[i] = twin[i - 1];
		}
	}
}

int n;

int main() {
	isprime(MAX_N);
	istwin(MAX_N);
	while (true) {
		cin >> n;
		if (n == 0) {
			break;
		}
		cout << twin[n] - 2 << ' ' << twin[n] << endl;
	}
}

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

int main() {
    string a;
    cin >> a;
    vector<int> X(4);
    for (int i = 0; i < 4; ++i) {
        X[i] = a[i]-'0';
    }

    for (int i = 0; i < (1 << 3); ++i) {
        bitset<3> bit(i);
        int sum = X[0];
        vector<string> ans(7);
        ans.push_back(to_string(X[0]));
        for (int j = 0; j < 3; ++j) {
            if (bit.test(j)) {
                sum += X[j+1];
                ans.push_back("+");
            }
            else
            {
                sum -= X[j+1];
                ans.push_back("-");
            }
            ans.push_back(to_string(X[j+1]));
        }
        if (sum == 7) {
            string answer = "";
            for (auto s : ans) {
                answer += s;
            }
            cout << answer << "=7" << endl;
            return 0;
        }
    }
}


#include<bits/stdc++.h>
//cervello|Phoenix
using namespace std;
#define ll long long int
#define eb emplace_back
#define mk make_pair
#define all(x) x.begin(),x.end()
#define mod 1000000007

vector<bool> prime(1000001,1);

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  for(int i=2;i*i<=1000000;i++)
    if(prime[i])
      for(int j=i*2;j<=1000000;j+=i)
        prime[j]=0;

  int n; cin>>n;
  vector<int> ans; int p=11;
  while(ans.size()<n){
    if(prime[p]&&(p%5==1))
      ans.eb(p);
    p++;
  }

  for(auto i:ans)
    cout<<i<<" ";
  cout<<"\n";
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const long long INF = 1LL << 60;
using ping = pair<ll, ll>;

int main(){
    ll X;
    cin >> X;
    ll cnt500 = 0;
    for (int i = 1;; i++) {
      if (i * 500 > X) break;
      else
        cnt500++;
    }
    X = X - cnt500 * 500;
    ll cnt5 = 0;
    for (int i = 1;; i++) {
      if (i * 5 > X) break;
      else
        cnt5++;
    }
    cout <<cnt500 * 1000 + cnt5 * 5 << endl;
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

struct murmur_hash {
    const unsigned int random = random_device{}();
    unsigned int operator()(const string& s) const {
        const unsigned int m = 0x5bd1e995;
        const int r = 24;
        unsigned int len = s.size(), h = (random ^ len);
        const unsigned int *z = (const unsigned int*)s.c_str();
        while(len >= 4){
            unsigned int k = *z;
            k *= m, k = (k^(k>>r))*m, h = (h*m)^k;
            z += 1, len -= 4;
        }
        const char *c = (const char *)z;
        switch(len)
        {
        case 3u: h ^= (c[2] << 16);
        case 2u: h ^= (c[1] << 8);
        case 1u: h ^= c[0];
                 h *= m;
        }
        h = (h^(h>>13))*m;
        return (h^(h>>15));
    }
};

unordered_map<string, unordered_map<string, int, murmur_hash>, murmur_hash> mp[2];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    n *= 2;
    string s;
    cin >> s;
    rep(i,(1 << (n-n/2))){
        string red,blue;
        rep(j,n-n/2){
            if((i >> j) & 1){
                red.pb(s[j+n/2]);
            }else{
                blue.pb(s[j+n/2]);
            }
        }
        reverse(all(blue));
        if(len(red) <= len(blue)){
            mp[0][blue][red]++;
        }else{
            mp[1][red][blue]++;
        }
    }
    ll ans = 0;
    rep(i,(1 << n/2)){
        string red, blue;
        rep(j,n/2){
            if((i >> j) & 1){
                red.pb(s[j]);
            }else{
                blue.pb(s[j]);
            }
        }
        reverse(all(blue));
        if(len(red) >= len(blue)){
            ans += mp[0][red][blue];
        }else{
            ans += mp[1][blue][red];
        }
    }
    cout << ans << "\n";
    return 0;
}

#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<std::string, std::string>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N;
std::string S;
std::map<P, ll> mp;
ll ans;

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

  std::reverse( S.begin()+N, S.end() );

  rep( i, 1<<N )
  {
    std::string t[2];

    rep( j, N )
      t[i>>j&1] += S[j];

    ++mp[P( t[0], t[1] )];
  }

  rep( i, 1<<N )
  {
    std::string t[2];

    rep( j, N )
      t[i>>j&1] += S[N+j];

    ans += mp[P( t[0], t[1] )];
  }

  std::cout << ans << std::endl;

  return 0;
}


#include <iostream>
using namespace std;

int main() {
	int a,b,n,i,x,y;
	while(1){
	a = 0;
	b = 0;
	cin >> n;
	if(n == 0)break;
	for(i=0;i<n;i++){
		cin >> x >> y;
		if(x < y){
			b += x + y;
		}
		else if(x == y){
			a += x;
			b += y;
		}
		else {
			a += x + y;
		}
	}
	cout << a << " " << b << endl;
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,int> pdi;
typedef pair<double,double> pdd;
typedef pair<double,ll> pdl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<pdd> vdd;
typedef vector<pdi> vdi;
typedef vector<pdl> vdl;
typedef vector<string> vs;
#define fi first
#define se second
const ll INFLL=LLONG_MAX;
const int INF=INT_MAX;
const ll MAXLL=0x3f3f3f3f3f3f3f3f;
const int MAX=0x3f3f3f3f;
const ll MOD=1000000007;
const ll mod=998244353;
#define eb emplace_back
#define emp emplace
#define mp(a,b) make_pair(a,b)
template<class T> using min_heap=priority_queue<T,vector<T>,greater<T> >;
template<class T>
void sort(vector<T>& v){
	sort(v.begin(),v.end());
}
template <class T, class U>
void sort(vector<T>& v,U func){
	sort(v.begin(),v.end(),func);
}
template<class T>
void rsort(vector<T>& v){
	sort(v.rbegin(),v.rend());
}
template <class T>
int lb_index(vector<T>& v,T k){
	return lower_bound(v.begin(),v.end(),k)-v.begin();
}
template <class T>
int ub_index(vector<T>& v,T k){
	return upper_bound(v.begin(),v.end(),k)-v.begin();
}
template<class T>
bool is_sorted(vector<T>& v){
	return is_sorted(v.begin(),v.end());
}
template<class T>
bool sorted(vector<T>& v){
	return is_sorted(v);
}
void precompute(){

	return;
}
void solve(){
	int n;
	cin>>n;
	if(n==1){
		cout<<"Hello World";
	}
	else{
		int a,b;
		cin>>a>>b;
		cout<<a+b;
	}
}

int main(){
	ios::sync_with_stdio(0);
	int numberofsubtestcases=1;
//	cin>>numberofsubtestcases;
	precompute();
	for(int looping=1;looping<=numberofsubtestcases;looping++){
//		cout<<"Case #"<<looping<<": ";
		solve();
	}
	return 0;
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define pdi pair<db,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define eps 1e-8
#define mo 974711
#define MAXN 200005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 + c - '0';
 	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
int N;
int64 a[55],K;
void Solve() {
    read(K);
    N = 50;
    a[1] = K / N;
    for(int i = 2 ; i <= N ; ++i) {
	a[i] = a[i - 1] + 1;
    }
    int t = K % N;
    for(int i = 1 ; i <= t ; ++i) {
	a[i] += N;
	for(int j = 1 ; j <= N ; ++j) {
	    if(i != j) a[j]--;
	}
    }
    out(N);enter;
    for(int i = 1 ; i <= N ; ++i) {
	out(a[i]);space;
    }
    enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}

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

int main() {
  int A,B,ans=1; cin >> A >> B;
  if(B==1) cout << 0 << endl;
  else if(A>=B) cout << 1 << endl;
  else{
    int sum = A*ans;
    while(sum < B) {
      ans++;
      sum += (A-1);
    }
    cout << ans << endl;
  }
}


#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
typedef unsigned long long ull;
#define vvi std::vector<std::vector<int> >
#define vvs std::vector<std::vector<string> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;
int main(int argc, char const *argv[]) {
  int N;
  ll ans = 0;
  string s, S, t, T="";
  std::cin >> N;
  std::cin >> s;
  S = s.substr(0, N);
  t = s.substr(N);
  for(int i=0;i<N;i++) T+=t[N-1-i];
  std::vector<int> num(26, 0);
  for(int i=0;i<N;i++) num[S[i]-'a']++, num[T[i]-'a']--;
  bool flag = true;
  for(int i=0;i<26;i++) if(num[i]!=0) flag = false;
  vvs str = vv(0, 2, "", string);
  for(int i=0;i<(1<<N);i++){
    int n = i+(1<<20), count=0;
    string ah = "", bh = "";
    while(count<N){
      if(n%2==1) ah += T[count];
      if(n%2==0) bh += T[count];
      count++;
      n/=2;
    }
    str.push_back(std::vector<string> {ah, bh});
  }
  sort(str.begin(), str.end());
  for(int i=0;i<(1<<N);i++){
    int n = i + (1<<20), count=0;
    string ah="", bh="";
    while(count<N){
      if(n%2==1) ah += S[count];
      if(n%2==0) bh += S[count];
      count++;
      n/=2;
    }
    int k = upper_bound(str.begin(), str.end(), std::vector<string> {ah,bh}) - lower_bound(str.begin(), str.end(), std::vector<string> {ah, bh});
    ans += k;
  }
  std::cout << (!flag?0:ans) << '\n';
  return 0;
}

#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

long long int DP[110000] = {}, DP2[110000] = {};

long long int pow_m1(long long int num){
	long long int pow_num = MOD - 2;
	long long int mod_num = MOD;
	long long int pow_cur = num;
	long long int ret = 1;
	while(pow_num > 0){
		if(pow_num % 2 == 1){
			ret *= pow_cur;
			ret %= mod_num;
		}
		pow_cur *= pow_cur;
		pow_cur %= mod_num;
		pow_num /= 2;
	}
	return ret;
}

int main(){
	long long int N, X;
	cin >> N >> X;
    long long int S[300];
	for(int i = 0; i < N; i++){
		cin >> S[i];
	}
    sort(S, S + N);
    long long int num = 1;
    for(int i = 1; i <= N; i++){
        num *= i;
        num %= MOD;
    }
    DP[X] = num;
    for(int i = N - 1; i >= 0; i--){
        num = pow_m1(i + 1);
        for(int j = 0; j <= X; j++){
            DP2[j] = 0;
        }
        for(int j = 0; j <= X; j++){
            DP2[j % S[i]] += DP[j] * num;
            DP2[j % S[i]] %= MOD;
            DP2[j] += DP[j] * (num * i % MOD);
            DP2[j] %= MOD;
        }
        for(int j = 0; j <= X; j++){
            DP[j] = DP2[j];
        }
    }
    long long int ans = 0;
    for(int i = 1; i <= X; i++){
        ans += i * DP[i];
        ans %= MOD;
    }
    cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
#define fir first
#define sec second
#define mod 998244353
#define int long long
#define INF (int)(1e18)
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
typedef pair<int,int> pii;
int add(int x,int y){return x+y>=mod?x+y-mod:x+y;}
int sub(int x,int y){return x-y<0?x-y+mod:x-y;}
int mul(int x,int y){return 1LL*x*y%mod;}
#define N 5005
int f[N][N];
struct Node
{
	int x,y;
};
Node a[N];
bool cmp(Node x,Node y)
{
	return x.x+x.y<y.x+y.y;
}
signed main()
{
#ifdef __LOCAL__
	freopen("in.txt","r",stdin);
#endif
	int n=read();
	for(int i=1;i<=n;i++) a[i].x=read(),a[i].y=read();
	sort(a+1,a+n+1,cmp);
	for(int i=0;i<=n;i++)
	{
		for(int j=1;j<=n;j++) f[i][j]=INF;
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=i;j++)
		{
			f[i][j]=f[i-1][j];
			if(f[i-1][j-1]<=a[i].x)
			{
				f[i][j]=min(f[i][j],f[i-1][j-1]+a[i].y);
			}
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		if(f[n][i]<INF) ans=i;
	}
	cout<<ans<<endl;
#ifdef __LOCAL__
	cout<<"Time Used : "<<clock()<<endl;
#endif
	return 0;
}

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

#define INF 10000000000000000

LL zab[11000];

int main(){
    LL n;
    cin >> n;
    vector<pair<LL,LL> > g;
    for(LL i = 0; i < n; i++){
        LL a, b;
        cin >> a >> b;
        a += b;
        g.push_back(make_pair(a,b));
    }
    sort(g.begin(), g.end());

    for(LL i = 0; i <= n; i++){
        zab[i] = INF;
    }
    zab[0] = 0;

    for(LL i = 0; i < n; i++){
        g[i].first -= g[i].second;
        for(LL j = n-1; j >= 0; j--){
            if(zab[j] <= g[i].first){
                zab[j+1] = min(zab[j+1], zab[j] + g[i].second);
            }
        }
    }

    LL best = 0;
    for(LL i = 0; i <= n; i++){
        if(zab[i] < INF){
            best = i;
        }
    }
    cout << best << endl;
}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(int argc,char** argv) {
	int n,t;
	vector<int> a;
	cin >> n;
	for(int i = 0;i < n;i++) {
		cin >> t;
		a.push_back(t);
	}
	bool flag = true;
	int count = 0;
	while(flag) {
		flag = false;
		for(auto itr = a.begin() + 1;itr != a.end();itr++) {
			if(*itr < *(itr - 1)) {
				iter_swap(itr,itr-1);
				flag = true;
				count++;
			}
		}
	}
	for(int i = 0;i < a.size()-1;i++) cout << a[i] << " ";
	cout << a[a.size()-1] << endl << count << endl;
}

#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<map>
#include<set>
using namespace std;
int n,a[105];
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	    cin>>a[i];
	int cnt=0;
	for(int i=0;i<n;i++)
        for(int j=0;j<n-1;j++)
            if(a[j]>a[j+1])
            {
            	cnt++;
            	swap(a[j],a[j+1]);
			}
	for(int i=0;i<n;i++)
	{
		cout<<a[i];
		if(i!=n-1)
		    cout<<' ';
		else
		    cout<<endl<<cnt<<endl;
	}
	return 0;
}


#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

const ll INF = 1LL << 50;

struct UnionFind {
  vll par;
  vll wcnt;
  vll bcnt;
  ll cnt;
  UnionFind(ll N, vector<string>& mp) : par(N), wcnt(N, 0), bcnt(N, 0), cnt(N) {
    for (ll i = 0; i < N; i++) {
      par[i] = i;
      ll w = (ll)mp[0].size();
      if (mp[i / w][i % w] == '.')
        wcnt[i] = 1;
      else
        bcnt[i] = 1;
    }
  }

  ll find(ll x) { return par[x] == x ? x : par[x] = find(par[x]); }

  bool same(ll x, ll y) { return find(x) == find(y); }

  ll get_wcnt(ll x) { return wcnt[find(x)]; }
  ll get_bcnt(ll x) { return bcnt[find(x)]; }

  void unite(ll x, ll y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    ll sizex = wcnt[x] + bcnt[x];
    ll sizey = wcnt[y] + bcnt[y];
    if (sizex < sizey) swap(x, y);
    par[y] = x;
    wcnt[x] += wcnt[y];
    bcnt[x] += bcnt[y];
    cnt--;
  }

  ll count() const { return cnt; }
};

int main() {
  ll x, y;
  cin >> x >> y;
  ll ans = 0;
  if (x == 1)
    ans += 300000;
  else if (x == 2)
    ans += 200000;
  else if (x == 3)
    ans += 100000;

  if (y == 1)
    ans += 300000;
  else if (y == 2)
    ans += 200000;
  else if (y == 3)
    ans += 100000;

  if (x == 1 && y == 1) ans += 400000;

  cout << ans << endl;

  return 0;
}

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

using namespace std;

int main()
{
	int X, Y;
	cin >> X >> Y;

	int total = 0;
	if (X == 1 && Y == 1) {
		total = 300000 * 2 + 400000;
		cout << total << endl;
		return 0;
	}

	if (X == 1) {
		total += 300000;
	}
	else if (X == 2) {
		total += 200000;
	}
	else if (X == 3) {
		total += 100000;
	}

	if (Y == 1) {
		total += 300000;
	}
	else if (Y == 2) {
		total += 200000;
	}
	else if (Y == 3) {
		total += 100000;
	}

	cout << total << endl;

}


#include<algorithm>
#include<functional>
#include<cstdio>
using namespace std;

int main(void){
	int sci[4], soc[2];
	scanf("%d%d%d%d%d%d", sci+0, sci+1, sci+2, sci+3, soc+0, soc+1);
	sort(sci, sci+4, greater<int>());
	printf("%d\n", sci[0]+sci[1]+sci[2]+max(soc[0], soc[1]));
	return(0);
}

#include <stdio.h>

int main(){

int angka,ratusan,puluhan,satuan;

scanf("%d", &angka);

ratusan = angka % 100;
puluhan = ratusan % 10;
satuan = puluhan;
puluhan = ratusan / 10;
ratusan = angka / 100;

if (ratusan == 7){
	printf("Yes\n");
}

else if(puluhan == 7){
	printf("Yes\n");
}

else if(satuan == 7){
	printf("Yes\n");
}
else{
	printf("No\n");
}

return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
	int n=2;
	vector<int> p[2];
	int ans[2];
	for(int i=0;i<n;++i){
		for(int j=0,point;j<10;++j){
			cin>>point;
			p[i].push_back(point);
		}
		sort(p[i].begin(),p[i].end(),greater<int>());
		ans[i]=p[i][0]+p[i][1]+p[i][2];
	}
	for(int i=0;i<n;++i)cout<<ans[i]<<((i==n-1)?"\n":" ");
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b,c,d,e,k; cin >> a >> b >> c >> d >> e >> k;

  if(e-a>k) cout << ":(" << endl;
  else cout << "Yay!" << endl;
}


#include <iostream>
#include <vector>

using namespace std;

const long long INF = 1e18;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<long long>> g(n, vector<long long>(n, INF));
  for (int i = 0; i < n; i++) {
    g[i][i] = 0ll;
  }
  for (int i = 0; i < m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    g[u][v] = (long long) w;
  }
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (g[i][i] < 0) {
      return cout << "NEGATIVE CYCLE" << '\n', 0;
    }
  }
  for (auto& v : g) {
    for (int i = 0; i < (int) v.size(); i++) {
      if (i > 0) {
        cout << ' ';
      }
      if (v[i] > 1e10) {
        cout << "INF";
      } else {
        cout << v[i];
      }
    }
    cout << '\n';
  }
  return 0;
}

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

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

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

template<class T>struct dijkstra{//T=int or ll
  struct Node{
    vector<T> edges_to;
    vector<T> edges_cost;
    bool done;
    T cost=-1;
  };
  vector<Node> graph;
  void init(T N){
    graph.resize(N);
  }
  void add(T from, T to, T cost){
    graph[from].edges_to.push_back(to);
    graph[from].edges_cost.push_back(cost);
  }
  void shortest(T start){
    priority_queue<pair<T,T>,vector<pair<T,T>>,greater<pair<T,T>>> d;
    d.push(make_pair(0,start));
    while(!d.empty()){
      pair<T,T> p = d.top();
      d.pop();
      Node &point = graph[p.second];
      if(point.done) continue;
      point.done = true;
      point.cost = p.first;
      for(T i = 0; i < (T)point.edges_to.size(); i++){
        if(graph[point.edges_to[i]].done)continue;
        d.push(make_pair(point.cost+point.edges_cost[i],point.edges_to[i]));
      }
    }
  }
};

int main() {
  ll N;
  cin>>N;
  dijkstra<ll> D;
  D.init(N);
  for(ll i = 0; i < N-1; i++) {
    ll x,y,z;
    cin>>x>>y>>z;
    D.add(x-1,y-1,z);
    D.add(y-1,x-1,z);
  }
  ll Q,K;
  cin>>Q>>K;
  D.shortest(K-1);
  for(ll i = 0; i < Q; i++){
    ll x,y;
    cin>>x>>y;
    cout<<D.graph[x-1].cost+D.graph[y-1].cost<<endl;
  }
}


#include <iostream>
using namespace std;

int main() {
  int n, q, t, cnt = 0;
  cin >> n;
  int s[n];

  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }

  cin >> q;

  for (int i = 0; i < q; i++) {
    cin >> t;
    for (int j = 0; j < n; j++) {
      if (t == s[j]) {
        cnt += 1;
        break;
      }
    }
  }

  cout << cnt << endl;
  return 0;
}

#include <iostream>
#include <set>
#include <algorithm>
using namespace std;

#define V(a) a.begin(), a.end()
typedef set<int> s;

int main()
{
	s a[2], C;

	for (auto &i : a) {
		int n, x;
		cin >> n;
		while (n--) {
			cin >> x;
			i.insert(x);
		}
	}

	set_intersection(V(a[0]), V(a[1]), inserter(C, C.end()));

	cout << C.size() << endl;
}


#include <iostream>
#include <vector>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<int> a(N + 1);
    for(int i = 1; i < N + 1; i++) cin >> a[i];
    vector<int> ko(N + 1, 0);
    int cnt = 0;
    for(int i = N; i > 0; i--){
        int t = 0;
        for(int j = i; j <= N; j += i){
            t += ko[j];
        }
        if(t % 2 != a[i]) {
            ko[i]++;
            cnt++;
        }
    }
    cout << cnt << endl;
    for(int i = 1; i <= N; i++){
        if(ko[i] == 1){
            cout << i << endl;
        }
    }
}

#pragma GCC optimize ("O3")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
#define all(a) a.begin(),a.end()
#define endl '\n'
#define ull unsigned long long
#define y1 ljhadglkjsadf
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define iter multiset<int>::iterator
#define iter1 set<int>::iterator
#define int long long
using namespace std;
using namespace __gnu_pbds;

template<class T>
using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

template<class T>
using ordered_multiset=tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rnd1(chrono::steady_clock::now().time_since_epoch().count());

//find_by_order
//order_of_key

const int N=2e5+7;
const int inf=1e18+1e9;
const int mod=1e9+7;
const ld eps=1e-9;

//const int MAX_MEM=4e8;
//int mpos=0;
//char mem[MAX_MEM];
//
//inline void * operator new(size_t n){
//    char *res=mem+mpos;
//    mpos+=n;
//    if (mpos>=MAX_MEM){
//        cout<<"BAD"<<endl;
//        exit(0);
//    }
//    return (void*)res;
//}
//
//inline void operator delete(void *) {}

int st[50];

main ()
{
    st[0]=1;
    for (int i=1;i<35;++i){
        st[i]=st[i-1]*2;
    }
    ios;
    int n;
    multiset<int>setik;
    cin>>n;
    for (int i=1;i<=n;++i){
        int x;
        cin>>x;
        setik.insert(x);
    }
    int ans=0;
    while(setik.size()>0){
        iter it=setik.end();
        --it;
        int x=(*it);
        setik.erase(it);
        int k=0;
        while(st[k]<=x)++k;
        int l=st[k]-x;
        iter it1=setik.find(l);
        if (it1!=setik.end()){
            ++ans;
            setik.erase(it1);
        }
    }
    cout<<ans<<endl;
}
//1
//3 15
//1 4
//3 5


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-10;

int main(){
    ll N, X;
    cin >> N >> X;
    ll b[N], l[N], u[N];
    rep(i, N) cin >> b[i] >> l[i] >> u[i];
    ll S = 0;
    rep(i, N) S += b[i]*l[i];
    pli p[N];
    rep(i, N) p[i] = pli(b[i]*l[i]+(X-b[i])*u[i], i);
    sort(p, p+N, greater<pli>());
    ll ans = INF;
    ll sum[N+1];
    sum[0] = 0;
    rep(i, N) sum[i+1] = sum[i] + p[i].first;
    rep(i, N){
        ll s = p[i].first;
        int j = p[i].second;
        if(sum[i] < S){
            ll k = lower_bound(sum, sum+N+1, S)-sum;
            ll rem = S-(sum[k]-s);
            ll n;
            if(rem <= b[j]*l[j]) n = (rem+l[j]-1)/l[j];
            else n = b[j]+(rem-b[j]*l[j]+u[j]-1)/u[j];
            ans = min(ans, (k-1)*X+n);
        }
        else{
            ll k = lower_bound(sum, sum+N+1, S-s)-sum;
            ll rem = S-sum[k];
            ll n;
            if(rem < 0) n = 0;
            elif(rem <= b[j]*l[j]) n = (rem+l[j]-1)/l[j];
            else n = b[j]+(rem-b[j]*l[j]+u[j]-1)/u[j];
            ans = min(ans, k*X+n);
        }
    }
    cout << ans << endl;
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

// ----------------------------------------------------------------------
// ----------------------------------------------------------------------

struct edge {
  ll to; ll d;
  bool operator< (const edge &x) const { return to<x.to; }
};
map<ll, set<edge>> adj;

map<ll, ll> dijkstra(int n=0) {
  auto c = [](const p_ll &x, const p_ll &y){return x.second>y.second;};
  priority_queue<p_ll, vector<p_ll>, decltype(c)> q(c);
  map<ll, ll> result; result[n] = 0; q.push(make_pair(n,0));
  while(q.size()) {
    p_ll now = q.top(); q.pop();
    ll np = now.first, nd = now.second;
    if (nd>result[np]) continue;
    for (auto x: adj[np]) {
      if (result.count(x.to)&&result[x.to]<=result[np]+x.d) continue;
      q.push(make_pair(x.to, result[np]+x.d));
      result[x.to] = result[np]+x.d;
    }
  }
  return result;
}

// ----------------------------------------------------------------------
// ----------------------------------------------------------------------

ll C = pow(10,6)+10;

int main() {
  int N, M; cin >> N >> M;
  rep(i,M) {
    ll p, q, c; cin >> p >> q >> c; p--; q--;
    adj[p*C].insert({p*C+c,1}); adj[p*C+c].insert({p*C,0});
    adj[q*C].insert({q*C+c,1}); adj[q*C+c].insert({q*C,0});
    adj[p*C+c].insert({q*C+c,0}); adj[q*C+c].insert({p*C+c,0});
  }
  map<ll, ll> d = dijkstra();
  // for (auto x: d) cout << x.first << "->" << x.second << " "; cout << endl;
  ll result = d.count((N-1)*C) ? d[(N-1)*C] : -1;
  cout << result << endl;
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
    int a, b, k;
    cin >> a >> b >> k;
    for(int i = 0; i < k; i++) {
        if(i % 2 == 0) {
            if(a % 2 != 0) {
                a--;
            }
            int h = a / 2;
            a = h;
            b += h;
        } else {
            if(b % 2 != 0) {
                b--;
            }
            int h = b / 2;
            b = h;
            a += h;
        }
    }
    cout << a << " " << b << "\n";
    return 0;
}

#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int a = 0, b = 0, a_sum[11] = { 0 }, b_sum[11] = { 0 };
	for (int i = 0; i < 10; i++) {
		cin >> a;
		a_sum[i] = a;
	}
	for (int j = 0; j < 10; j++) {
		cin >> a;
		b_sum[j] = a;
	}
	a = 0;
	sort(a_sum, a_sum + 10);
	sort(b_sum, b_sum + 10);
	/*for (int i = 0; i < 10; i++) {
		cout << a_sum[i] << "," << b_sum[i] << endl;
	}*/
	for (int i = 9; i >6; i--) {
		a += a_sum[i];
		b += b_sum[i];
	}
	cout << a << " " << b << endl;
}


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

int main(){

  int n;
  cin>>n;

  vector<int> data(n+2);

  data.at(0)=0;
  data.at(n+1)=0;

  for (int i=1;i<=n;i++){
    int tmp;
    cin>>tmp;
    data.at(i)=tmp;
  }

  long long sum=0;

  for (int i=0;i<n+1;i++){
    sum+=abs(data.at(i+1)-data.at(i));
  }

  for (int i=1;i<=n;i++){
    cout<<sum-abs(data.at(i)-data.at(i-1))-abs(data.at(i+1)-data.at(i))+abs(data.at(i+1)-data.at(i-1))<<endl;
  }

}

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

int main(){
  int n;
  cin>>n;
  int vec[n+2];
  vec[0]=0,vec[n+1]=0;
  for(int i=1;i<=n;i++){
    cin>>vec[i];
  }
  int sum=0;
  for(int i=0;i<n+1;i++){
    sum+=abs(vec[i]-vec[i+1]);
  }
  for(int i=1;i<=n;i++){
    if(vec[i-1]<=vec[i]&&vec[i]<=vec[i+1]){
      cout<<sum<<endl;
      continue;
    }
    if(vec[i-1]>=vec[i]&&vec[i]>=vec[i+1]){
      cout<<sum<<endl;
      continue;
    }
    if(vec[i-1]==vec[i]||vec[i]==vec[i+1]){
      cout<<sum<<endl;
      continue;
    }
    cout<<sum-abs(vec[i-1]-vec[i])-abs(vec[i]-vec[i+1])+abs(vec[i-1]-vec[i+1])<<endl;
  }
}


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

void solve(long long A, long long B, long long C, long long D){
    if ((A + B) > (C + D)) cout << "Left" << endl;
    else if ((A + B) < (C + D)) cout << "Right" << endl;
    else cout << "Balanced" << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    long long D;
    scanf("%lld",&D);
    solve(A, B, C, D);
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    long long i,j,k,l,m,n,o,p,q;
    while(cin>>m>>n>>o>>p)
    {
        if(m+n>o+p)
            cout<<"Left"<<endl;
        else if(m+n<o+p)
            cout<<"Right"<<endl;
        else
            cout<<"Balanced"<<endl;
    }
    return 0;
}


#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

int main() {
  string s;
  while(cin >> s) {
    int state = 0;
    int J, O, I;
    int ans = 0;
    REP(i, s.size()) {
      if (s[i] == 'J') {
        if (state == 1) {
          J++;
        } else {
          state = 1;
          J = 1;
        }
      } else if (s[i] == 'O') {
        if (state == 1) {
          state = 2;
          O = 1;
        } else if (state == 2) {
          O++;
        } else state = 0;
      } else {
        if (state == 2) {
          state = 3;
          I = 1;
          if (J>=O&&I>=O)
            ans = max(ans, O);
        } else if (state == 3) {
          I++;
          if (J>=O&&I>=O)
            ans = max(ans, O);
        } else {
          state = 0;
        }
      }
      //cout << J << " " << O << " " << I << "  : " << state << endl;
    }
    cout << ans << endl;
  }
}

#include <iostream>
#include <string>

int main(){

	const std::string correct_word = "Hoshina";
	const std::string find_word = "Hoshino";

	int N;

	std::cin >> N;
	std::cin.ignore();

	for(int i = 0; i < N; ++i){

		std::string str;
		std::getline(std::cin,str);

		std::string::size_type pos = str.find(find_word);

		while(pos != std::string::npos){

			 str.replace(pos, find_word.length(), correct_word);

			 pos = str.find(find_word, pos + find_word.length());
		}

		std::cout << str << std::endl;

	}
	return 0;
}


#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cassert>
#include <numeric>

using namespace std;
#define ll long long

vector<int> prime(ll f){
  vector<int> ans(1,2);
  for(int i = 3;i <= sqrt(f);i ++){
    int p = 0;
    bool jud = true;
    while(ans[p]<=sqrt(i)){
      if(i % ans[p] == 0){
        jud = false;
        break;
      }
      p++;
    }
    if(jud == true){
      ans.insert(ans.end(),i);
    }
  }
  return ans;
}

int main(void){
  ll a,b;
  cin >> a >> b;
  while(a !=  b){
    if(a > b){
      if(a % b == 0){
        a = b;
      }else{
        a = a % b;
      }
    }else{
      if(b % a == 0){
        b = a;
      }else{
        b = b % a;
      }
    }
  }
  vector<int> pri = prime(a);
  vector<int> prnum(pri.size()+1,0);
  int s = pri.size();
  for(int i = 0;i < s;i ++){
    while(a % pri[i] == 0){
      a = a / pri[i];
      prnum[i] ++;
    }
    if(a == 1){
      break;
    }
  }
  if(a != 1){
    prnum[pri.size()]++;
  }
  int ans = 1;
  s = prnum.size();
  for(int i = 0;i < s;i ++){
    if(prnum[i]>0){
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}

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

int main() {
  long n,ans=0,p=0;
  cin >> n;
  vector<vector<long>> a(n,vector<long>(n-1));
  vector<vector<bool>> b(n,vector<bool>(n));
  vector<long> c(n);
  queue<long> x;
  queue<long> y;
  for(long i=0;i<n;i++) for(long j=0;j<n-1;j++) cin >> a[i][j];

  for(long i=0;i<n;i++) {
    b[i][a[i][0]-1]=true;
    if(b[a[i][0]-1][i]) {
      x.push(i);
      y.push(a[i][0]-1);
    }
  }

  while(p<n*(n-1)/2) {
    ans++;
    long z=x.size();
    if(z==0) break;
    for(long i=0;i<z;i++) {
      c[x.front()]++;
      c[y.front()]++;
      if(c[x.front()]!=n-1) {
        b[x.front()][a[x.front()][c[x.front()]]-1]=true;
        if(b[a[x.front()][c[x.front()]]-1][x.front()]) {
          x.push(x.front());
          y.push(a[x.front()][c[x.front()]]-1);
        }
      }
      if(c[y.front()]!=n-1) {
        b[y.front()][a[y.front()][c[y.front()]]-1]=true;
        if(b[a[y.front()][c[y.front()]]-1][y.front()]) {
          x.push(y.front());
          y.push(a[y.front()][c[y.front()]]-1);
        }
      }
      x.pop();
      y.pop();
    }
    p+=z;
  }

  if(p==n*(n-1)/2) cout << ans << endl;
  else cout << -1 << endl;
}


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

int64_t mod = 1000000007;
int64_t large = 9223372036854775807;
double PI = 3.141592653589793;

int main()
{
    vector<int> list(3);
    int K;
    for (int i = 0; i < 3; i++)
        cin >> list[i];
    cin >> K;
    sort(list.begin(), list.end());
    cout << list[2] * pow(2, K) + list[1] + list[0];
}

/* In the name of Allah */
#include<bits/stdc++.h>
using namespace std;

const int N = 2e3 + 5;
int n, m, q, a[N][N], dp[N][N][3];

int get(int b, int xl, int xr, int yl, int yr) {
	return dp[xr][yr][b] - dp[xl][yr][b] - dp[xr][yl][b] + dp[xl][yl][b];
}

void read_input() {
	cin >> n >> m >> q;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++) {
			char c;
			cin >> c;
			a[i][j] = c - '0';
		}
}

void solve() {
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++) {
			dp[i][j][0] = (a[i][j] && a[i][j + 1]) + dp[i - 1][j][0] + dp[i][j - 1][0] - dp[i - 1][j - 1][0];
			dp[i][j][1] = (a[i][j] && a[i + 1][j]) + dp[i - 1][j][1] + dp[i][j - 1][1] - dp[i - 1][j - 1][1];
			dp[i][j][2] = a[i][j] + dp[i - 1][j][2] + dp[i][j - 1][2] - dp[i - 1][j - 1][2];
		}
}

void write_output() {
	while (q--) {
		int xl, xr, yl, yr;
		cin >> xl >> yl >> xr >> yr;
		cout << get(2, xl - 1, xr, yl - 1, yr) - get(1, xl - 1, xr - 1, yl - 1, yr) - get(0, xl - 1, xr, yl - 1, yr - 1) << endl;
	}
}

int main() {
	ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	read_input(), solve(), write_output();
	return 0;
}


///usr/bin/g++ -O2 $0 -o ${0%.cpp} && echo "----------" && ./${0%.cpp}; exit;
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

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

typedef long long ll;
typedef pair<int, int> ii;

const int N = 1005;
const int mod = 1e9 + 7;

#define mul(a, b) ((ll) (a) * (b) % mod)

int f[N][N], n, a, b, c, d, fact[N], inv[N][N];

inline int Pow(int a, int p) {
    int ret = 1; while(p) {
        if(p & 1) ret = mul(ret, a);
        a = mul(a, a);
        p >>= 1;
    } return ret;
}

void precalc() {
    fact[0] = 1;
    for(int i = 1; i < N; ++i)
        fact[i] = mul(fact[i - 1], i);
    inv[N - 1][1] = Pow(fact[N - 1], mod - 2);
    for(int i = N - 2; i >= 0; --i)
        inv[i][1] = mul(inv[i + 1][1], i + 1);
    for(int i = 0; i < N; ++i) {
        inv[i][0] = 1;
        for(int j = 2; j < N; ++j) {
            inv[i][j] = mul(inv[i][j - 1], inv[i][1]);
        }
    }
}

int main(int argc, char const *argv[]) {
    precalc();
    scanf("%d %d %d %d %d", &n, &a, &b, &c, &d);

    for(int i = 0; i <= n; ++i) f[0][i] = 1;
    for(int i = 1; i <= n; ++i) {
        for(int j = a; j <= b; ++j) {
            f[i][j] = f[i][j - 1];
            for(int k = c; k <= d && j * k <= i; ++k) {
                f[i][j] += mul(fact[i], mul(f[i-j*k][j-1], mul(inv[i-j*k][1], mul(inv[j][k], inv[k][1]))));
                if(f[i][j] >= mod) f[i][j] -= mod;
            }
        }
    }
    printf("%d\n", f[n][b]);
}

//Heaplax
//别让自己后悔
#include<bits/stdc++.h>
#define N 2005
#define LL long long
#define LOG(x) cerr<<#x<<" = "<<x<<endl
#define add_edge(u,v) nxt[++cnt]=head[u],head[u]=cnt,to[cnt]=v
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
char ch;bool fs;void re(int& x)
{
	while(ch=getchar(),ch<33);
	if(ch=='-')fs=1,x=0;else fs=0,x=ch-48;
	while(ch=getchar(),ch>33)x=x*10+ch-48;
	if(fs)x=-x;
}
using namespace std;
int n,m,q,v[N][N],xe[N][N],ye[N][N];
char s[N][N];
int main()
{
	re(n),re(m),re(q);
	for(int i=1;i<=n;++i)
		scanf("%s",s[i]+1);
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
		{
			v[i][j]=s[i][j]-'0'+v[i-1][j];
			xe[i][j]=(s[i][j]=='1'&&s[i-1][j]=='1')+xe[i-1][j];
			ye[i][j]=(s[i][j]=='1'&&s[i][j-1]=='1')+ye[i][j-1];
		}
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
		{
			v[i][j]+=v[i][j-1];
			xe[i][j]+=xe[i][j-1];
			ye[i][j]+=ye[i-1][j];
		}
	for(int a,b,c,d;q--;)
	{
		re(a),re(b),re(c),re(d);
		int ans=v[c][d]+v[a-1][b-1]-v[a-1][d]-v[c][b-1];
		ans-=xe[c][d]-xe[a][d]-xe[c][b-1]+xe[a][b-1];
		ans-=ye[c][d]-ye[a-1][d]-ye[c][b]+ye[a-1][b];
		printf("%d\n",ans);
	}
}


#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <math.h> // sqrt
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <iomanip> // setprecision
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<long long>;
using pii = pair<int, int>;
using psi = pair<string, int>;

int main() {
    int N;
    string S;
    cin >> N >> S;
    ll r = 0, g = 0, b = 0;
    for (int i = 0; i < N; i++) {
        if (S[i] == 'R') {
            r++;
        }
        else if (S[i] == 'G') {
            g++;
        }
        else {
            b++;
        }
    }
    ll ans = r * g * b;
    for (int i = 0; i < N - 2; i++) {
        for (int j = i + 2; j < N; j += 2) {
            int k = (i + j) / 2;
            if (S[i] != S[j] && S[j] != S[k] && S[k] != S[i]) {
                ans--;
            }
        }
    }
    cout << ans << endl;
}

#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define IN inline
#define RE register
using namespace std;
const int maxn=2e3+5;
int n,m,q;
int l,u,r,d;
int sum[maxn][maxn][3];
char s[maxn];
bool mp[maxn][maxn];
IN int read(){
	int ret=0,f=1;char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=-f;ch=getchar();}
	while(ch>='0'&&ch<='9') ret=ret*10+ch-'0',ch=getchar();
	return ret*f;
}
IN void work(){
	u=read(),l=read(),d=read(),r=read();
	int v=sum[d][r][0]-sum[d][l-1][0]-sum[u-1][r][0]+sum[u-1][l-1][0];
	int e1=sum[d][r][1]-sum[d][l-1][1]-sum[u][r][1]+sum[u][l-1][1];
	int e2=sum[d][r][2]-sum[d][l][2]-sum[u-1][r][2]+sum[u-1][l][2];
	printf("%d\n",v-e1-e2);
	return;
}
int main(){
// 	freopen("wang.in","r",stdin);
// 	freopen("wang.out","w",stdout);
	n=read(),m=read(),q=read();
	for(RE int i=1;i<=n;i++){
		scanf("%s",s+1);
		for(int j=1;j<=m;j++) mp[i][j]=s[j]-'0';
	}
	for(RE int i=1;i<=n;i++)
	for(RE int j=1;j<=m;j++){
		sum[i][j][0]=sum[i][j-1][0]+sum[i-1][j][0]-sum[i-1][j-1][0]+mp[i][j];
		if(i>1) sum[i][j][1]=sum[i][j-1][1]+sum[i-1][j][1]-sum[i-1][j-1][1]+(mp[i][j]&mp[i-1][j]);
		if(j>1) sum[i][j][2]=sum[i][j-1][2]+sum[i-1][j][2]-sum[i-1][j-1][2]+(mp[i][j]&mp[i][j-1]);
	}
	for(RE int i=1;i<=q;i++) work();
	return 0;
}


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

void solve()
{
    int n;cin>>n;
    int a[n],b[n],c[n+1],d[n+1];
    REP(i,n)cin>>a[i];REP(i,n)cin>>b[i];
    REP(i,n+1)c[i]=d[i]=0;
    REP(i,n)c[a[i]]++,d[b[i]]++;
    REP(i,n+1)if(c[i]+d[i]>n){cout<<"No"<<endl;return;}
    cout<<"Yes"<<endl;
    rep(i,1,n+1)c[i]+=c[i-1],d[i]+=d[i-1];
    int x=0;rep(i,1,n+1)x=max(x,c[i]-d[i-1]);
    REP(i,n)cout<<(i?" ":"")<<b[(i+n-x)%n];cout<<endl;
}

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

#include <bits/stdc++.h>
#include<cmath>
#include<string>
#define pb push_back
//#define x first
//#define y second
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define all(x) x.begin(),x.end()
#define int long long
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
//void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

// look for  all edge cases
//search for a pattern

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

	int n;
	cin >> n;
	vector<int> v(n);

	for(int i =0 ; i < n ; i++)cin >> v[i];

	set<int> s;
	map<int,int> m;

	for(int i =0 ; i < n; i++){
		int temp;
		cin >> temp;
		m[temp] += 1;
		s.insert(temp);
	}

	int l = 0;
	bool ok = true;
	vector<int> ans(n);

	for(int i= 0 ; i < n; i++){
		int val = v[i];
		auto beg = *s.begin();
		auto en = *s.rbegin();
		if(beg != en){
			if(val == beg){
				m[en] -= 1;
				if(m[en] == 0){
					s.erase(en);
				}
				ans[i] = en;
			}
			else{
				m[beg] -= 1;
				if(m[beg] == 0){
					s.erase(beg);
				}
				ans[i] = beg;
			}
		}
		else if(beg == en && en != val){
			m[beg] -= 1;
			ans[i] = beg;
			if(m[beg] == 0){
				s.erase(beg);
			}

		}
		else{
			m[beg] -= 1;
			bool found = false;
			while(l != i){

				if(v[l] != beg && ans[l] != beg){
					int temp = ans[l];
					ans[l] = beg;
					ans[i] = temp;
					l++;
					found = true;
					break;
				}
				l++;
			}

			if(found){
				if(m[beg] == 0){
					s.erase(beg);
				}
			}
			else{
				ok = false;
			}

		}
	}

	if(!ok)
		cout<<"No";
	else{
		cout<<"Yes\n";
		for(auto it : ans){
			cout<< it << " ";
		}
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> a(n+1,0);
  for(int i=1;i<=n;i++)
    cin>>a.at(i);
  vector<int> d(n+1);
  int s=0;
  for(int i=0;i<n;i++){
    d.at(i)=abs(a.at(i+1)-a.at(i));
    s+=d.at(i);
  }
  d.at(n)=abs(a.at(n));
  s+=d.at(n);
  for(int i=1;i<=n;i++){
    if(min({a.at(i-1),a.at(i),a.at((i+1)%(n+1))})==a.at(i)||max({a.at(i-1),a.at(i),a.at((i+1)%(n+1))})==a.at(i))
      cout<<s-2*min(d.at(i-1),d.at(i))<<endl;
    else
      cout<<s<<endl;
  }
}

// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
int getDigit(long long n);      // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      ((a)/GCD((a),(b))*(b))
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;

// code
// ------------------------------------------------
int main() {

  ll n;
  cin >> n;
  vector<ll> a(n+2,0),r(n+2,0);
  rep(i,n) cin >> a[i+1];

  rep(i,n+1)
  {
    r[i+1] = r[i] + abs(a[i+1] - a[i]);
  }

  rep(i,n)
  {
    ll no = i + 1;
    cout << r[no - 1] + r[n+1] - r[no + 1] + abs(a[no+1] - a[no-1]) << endl;
  }

  return 0;
}
// funcの実体
// ------------------------------------------------
int getDigit(ll n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 0)
      break;
    i++;
  }
  return i;
}
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


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

vector<int> A;
vector<int> g;

int n, m;
int cnt;

auto prn=[=](){
    for(auto a : A)
        cout<<a<<"\n";
};

void _insSort(int g){
    for(int i=g-1;i<n;i++){
        int maxi=i;
        for(int j=i+g;j<n;j+=g){
            if(A[j] < A[maxi]){
                maxi=j;
            }
        }
        if(i!=maxi){
            swap(A[i],A[maxi]);
            cnt++;
        }
    }
 //   cout<<"----"<<g<<"-----\n";
 //   prn();
}

void insSort(int g){
    for(int i=g;i<n;i++){
        int v = A[i];
        int j = i - g;
        while(j>=0 && A[j] > v){
            A[j+g] = A[j];
            j -= g;
            cnt++;
        }
        A[j+g] = v;
    }
}

void  ShellSort(){
    int i;
    cnt=0;
    m = n;
    if(m>100)
	m=100;
    g.push_back(1);
    for(i=1;pow(4,i)+3*pow(2,i-1)+1<n&&i<=m;i++){
        g.push_back(pow(4,i)+3*pow(2,i-1)+1);
    }
    if(i!=m)
	m=i;
    for(i=g.size()-1;i>=0;i--)
        insSort(g[i]);
}

int main(){
    ios::sync_with_stdio(false);
    int  t;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>t;
        A.push_back(t);
    }
    ShellSort();
    cout<<m<<"\n";
    for(int i=g.size()-1;i>0;i--)
        cout<<g[i]<<" ";
    cout<<g[0]<<"\n";
    cout<<cnt<<endl;
    prn();
    return 0;
}

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

int insertionSort(int a[], int n, int g){
	int cnt = 0;
	for(int i=g;i<n;++i){
		int v = a[i];
		int j = i - g;
		while(j>=0 && a[j]>v){
			a[j+g] = a[j];
			j = j - g;
			++cnt;
		}
		a[j+g] = v;
	}
	return cnt;
}

int* interleavedlist(int n, int *m){
	int i = 1, j = 0;
	*m = log10(2*n+1) / log10(3);
	int *g = new int[*m];
	while(i<=n){
		g[j] = i;
		++j;
		i = 3 * i + 1;
	}
	return g;
}

void shellSort(int a[], int n){
	int cnt = 0;
	int m;
	int *g = interleavedlist(n,&m);

	cout<<m<<endl;
	for(int i=m-1;i>=0;--i)cout<<g[i]<<(i?" ":"");
	cout<<endl;

	for(int i=m-1;i>=0;--i){
		cnt += insertionSort(a,n,g[i]);
	}
	cout<<cnt<<endl;
}

int main() {
	int n, *data;

	cin>>n;
	data = new int[n];
	for(int i=0;i<n;++i){
		cin>>data[i];
	}

	shellSort(data,n);

	for(int i=0;i<n;++i){
		cout<<data[i]<<endl;
	}
	return 0;
}