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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }

	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);

	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) {
		pr(t); pr(ts...);
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) {
		pr("{",x.f,", ",x.s,"}");
	}
	template<class T> void pr(const T& x) {
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0;
		pr("}");
	}

	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) {
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...);
	}
}

using namespace output;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N, M; cin >> N >> M;
	if (N&1) {
		FOR(i, 1, M+1) print(i, N-i+1);
	} else {
		int even_pos = 1;
		int odd_pos = N/2+1;
		for (int s = M; s >= 1; --s) {
			if (s&1) {
				print(odd_pos, odd_pos + s); ++odd_pos;
			} else {
				print(even_pos, even_pos + s); ++even_pos;
			}
		}
	}

}

#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <limits>
#include <numeric>
#include <type_traits>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define MOD 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define REVERSE(s) reverse(s.begin(), s.end());
#define SUM(s) accumulate(s.begin(), s.end(), 0LL);
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
//#define int ll
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int ndx[8] = { 0,1,0,-1, 1,1,-1,-1 };
int ndy[8] = { 1,0,-1,0, 1,-1,-1,1 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> v(n+1);

	int u1 = 1+m;
	int d1 = 1;
	int u2=  n;
	int d2 = n - m + 1;

	int c = 0;

	while (u1 > d1 && c < m) {
		cout << d1 << " " << u1 << endl;
		d1++; u1--;
		c++;
	}
	while (u2 > d2 && c < m) {
		cout << d2 << " " << u2 << endl;
		d2++; u2--;
		c++;
	}
}


#include<bits/stdc++.h>
using namespace std;
int main(){
  long long a,b,k;
  cin>>a>>b>>k;
  while(k){
    if(a%2==1)a--;
    a/=2;
    b+=a;
    k--;
    if(k==0)break;
    if(b%2==1)b--;
    b/=2;
    a+=b;
    k--;
    if(k==0)break;
  }
  cout<<a<<" "<<b<<endl;
  return 0;
}

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

typedef long long  ll;

ll MOD = 1000000007;
ll INF = 100000000;
double PI = 3.1415926535;

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<pair<ll,ll>>>;

int main(){
  int N,H,W;
  cin >> N >> H >> W;
  cout << max(0,(N-H+1)*(N-W+1)) << endl;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <set>
#include <map>
#include <vector>
#include <queue>
#define LL long long
#define N 55555
#define maxn 10005
#define INF 0x3f3f3f3f
#define mase(a,b) memset(a,b,sizeof(a))
#define MIN(a,b) (a<b?a:b)
#define MAX(a,b) (a>b?a:b)
#define DS DisputeSegement
using namespace std;
bool isPrime(int fig)
{
    int limit=(int)sqrt(fig)+1;
    for(int i=2;i<limit;i++)
    {
        if(fig%i==0)
        {
            return false;
        }

    }
    return true;
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=11;i<=N;i+=10)
    {
        if(isPrime(i))
        {
            printf("%d",i);
            n--;
            printf("%c",n?' ':'\n');
            if(!n)
            {
                break;
            }
        }
    }
    return 0;
}

//Five,Five Everywhere,原创者CSDN@

#define scanf_s scanf
#include <stdio.h>
#include <string>
#include <iostream>
using namespace std;
#define MAX 20
int main(void)
{
	int i;
	char str[MAX + 1];
	scanf_s("%s", str, MAX);
	for (i = 0; str[i + 1] != '\0'; ++i);
	for (; i >= 0;--i){
		printf("%c", str[i]);
	}
	printf("\n");
}


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

int main() {
  ll n; cin >> n;
  if (n-1) {
    ll a, b; cin >> a >> b;
    cout << a + b << endl;
  } else {
    cout << "Hello World" << endl;
  }
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
    string S;
    cin>>S;
    int w;
    cin>>w;
    int a=S.size();
  	if(w!=1){
    for(int i=1; i<a+1; i++){
        if(i%w==1){
            cout<<S[i-1];
        }
    }
    }
  else{
rep(i,S.size()){
  cout<<S[i];
}
  }
    cout<<""<<endl;
}


#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e9;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef pair<double,double> point;
const ll MAX = 200005;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin >> n >> m;
    if (n%2){
        ll l = 1,r = n;
        rep(i,m){
            printf("%lld %lld\n",l,r);
            l++;
            r--;
        }
    }
    else{
        ll k = n/2;
        ll l = 1,r = n;
        rep(i,min(k/2,m)){
            printf("%lld %lld\n",l,r);
            l++;
            r--;
        }
        r--;
        rep(i,m-k/2){
            printf("%lld %lld\n",l,r);
            l++;
            r--;
        }
    }
}

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

int main(){
  int n,rank[100];
  pair<int,int> point[100];
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    point[i].first = 0;
    point[i].second = i;
  }
  for(int i=0;i<n*(n-1)/2;i++){
    int a,b,c,d;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    if(c<d){
      point[b-1].first += 3;
    }else if(c>d){
      point[a-1].first += 3;
    }else{
      point[a-1].first += 1;
      point[b-1].first += 1;
    }
  }
  sort(point,point+n);
  reverse(point,point+n);
  int r;
  for(int i=0;i<n;i++){
    int team = point[i].second;
    if(i>0&&point[i].first==point[i-1].first){
      rank[team] = r;
    }else{
      r = i+1;
      rank[team] = r;
    }
  }
  for(int i=0;i<n;i++) printf("%d\n",rank[i]);
  return 0;
}


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

string s;

void dfs(string op,int now,int i)
{
	if(i==4)
	{
		if(now==7)
		{
		for(int i =0 ;i<3;i++)cout<<s[i]<<op[i+1];
		cout<<s.back();
		cout<<"=7"<<endl;
		exit(0);
		}
		return;
	}
	dfs(op+'+',now+s[i]-'0',i+1);
	if(i)dfs(op+'-',now-s[i]+'0',i+1);
}

int main()
{
	cin >> s;
	dfs("",0,0);
}

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

int main()
{
	int n;
	cin >> n;
	int a[4], ans, k;
	for (int i = 3; i >= 0; i--)
	{
		a[i] = n % 10;
		n = n / 10;
	}
	string op;
	for (int i = 0; i < 8; i++)
	{
		ans = a[0];
		k = 1;
		for (int j = 2; j >= 0; j--)
		{
			if (i & (1 << j))
			{
				op += "-";
				ans -= a[k++];
			}
			else
			{
				op += "+";
				ans += a[k++];
			}
		}
		if (ans == 7)
		{
			break;
		}
		else
		{
			op = "";
		}
	}
	string r = to_string(a[0]);
	k = 1;
	for (int i = 0; i < 3; i++)
		r += op[i] + to_string(a[k++]);
	r += "=7";
	cout << r << endl;
}


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

int main() {
    cin.tie(0)->sync_with_stdio(false);

    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;

    int index = -1;
    REP(i, n) {
        if (s.substr(i, n - i) == t.substr(0, n - i)) {
            index = i;
            break ;
        }
    }

    if (index == -1) cout << s.size() + t.size() << '\n';
    else cout << n + index << '\n';
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pii pair<int,int>
const long long MOD=1000000007;

int main(){
    int n,m,x,y;
    cin>>n>>m>>x>>y;
    int xmax=x,ymin=y;
    rep(i,n){
        int x0;
        cin>>x0;
        xmax=max(xmax,x0);
    }
    rep(i,m){
        int y0;
        cin>>y0;
        ymin=min(ymin,y0);
    }
    if(xmax<ymin) cout<<"No War"<<endl;
    else cout<<"War"<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//using ll = long long;
using P = pair<int,int>;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

const int INF=1e+9;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int n,q;
	string s;
	cin >> n >> s >> q;
	for(int i = 0;i < q;i++){
		int k,ans = 0,d = 0,m = 0,c = 0,dm = 0,mc = 0;
		cin >> k;
		for(int j = 0;j < n;j++){
			if(j >= k){
				if(s[j - k] == 'D'){
					d--;
					dm -= m;
				}
				else if(s[j - k] == 'M'){
					m--;
					mc -= c;
				}
				else if(s[j - k] == 'C'){
					c--;
				}
			}
			if(s[j] == 'D'){
				d++;
			}
			else if(s[j] == 'M'){
				m++;
				dm += d;
			}
			else if(s[j] == 'C'){
				c++;
				mc += m;
				ans += dm;
			}
		}
		cout << ans << endl;
	}

}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define fi first
#define se second
const ll mod = 1e9+7;
const int N = 2e5+6;
int bit[55][55];
void add(int x, int y){
	for(int i=x;i>0;i-=(i&-i)){
		for(int j=y;j>0;j-=(j&-j)){
			bit[i][j]++;
		}
	}
}
ll get(int x, int y){
	ll ret =0;
	for(int i=x;i<55;i+=(i&-i)){
		for(int j=y;j<55;j+=(j&-j)){
			ret+=bit[i][j];
		}
	}
	return ret;
}
ll get2(ll x){
	ll ret = 1;
	while(x%2==0){
		ret++;
		x/=2;
	}
	return ret;
}
ll get5(ll x){
	ll ret = 1;
	while(x%5==0){
		ret++;
		x/=5;
	}
	return ret;
}
void solve(){
	int n;
	cin>>n;
	ll ans = 0;
	for(int i=1;i<=n;i++){
		ld inp;
		cin>>inp;
		ll trt = llround(inp*1e9);
		ll x = get2(trt);
		ll y = get5(trt);
		ll xp = max(1ll,20-x);
		ll yp = max(1ll,20-y);
		ans+=get(xp,yp);
		add(x,y);
	}
	cout<<ans<<endl;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1;
//	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

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

ll mp[555][555];
int dx[] = {1,0,-1,0};
int dy[] = {0,-1,0,1};
vector<ll> v;

ll gcd(ll a,ll b){
	if(a < b)swap(a,b);
	return b == 0 ? a : gcd(b,a%b);
}

void prime(){
	vector<bool> pri(100000);
	vector<ll> tmp;
	int cou = 0;
	for(int i = 2;;i++){
		if(!pri[i]){
			tmp.PB(i);
			for(int j = i;j < 100000;j+=i)pri[j] = true;
			cou++;
		}
		if(cou == 1010)break;
	}
	for(int i = 0,j = tmp.size() - 1;i < j;i++,j--){
		v.PB(tmp[i]);
		v.PB(tmp[j]);
	}
}

void seica(){
	REP(i,555)REP(j,555)mp[i][j] = 1;
	REP(i,500){
		REP(j,500){
			if((i+j) % 2 == 0){
				mp[i][j] *= v[(i+j)/2];
			}
			if((i+499-j) % 2 == 1){
				mp[i][j] *= v[501+(i+499-j)/2];
			}
		}
	}

	REP(i,500){
		REP(j,500){
			if((i + j) % 2){
				ll now = 1;
				REP(k,4){
					if(i+dy[k] >= 0 && i+dy[k] < 500 && j+dx[k] >= 0 && j+dx[k] < 500){
						ll hoge = gcd(now, mp[i+dy[k]][j+dx[k]]);
						now *= mp[i+dy[k]][j+dx[k]] / hoge;
					}
				}
				mp[i][j] = now + 1;
			}
		}
	}
}

int main(){

	int n;cin >> n;

	prime();
	//cout << v.size() << endl;
	seica();

	REP(i,n){
		REP(j,n){
			cout << mp[i][j] << " ";
		}
		cout << endl;
	}

	return 0;
}

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(ll i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <ll,ll> P;
typedef long double ld;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    if (n <= 2) {
        cout << "-1\n";
    } else if (n % 3 == 0) {
        rep (i, n) {
            rep (j, n) {
                if (i / 3 == j / 3 && ((i % 3 == 0) ^ (j % 3 == 0))) cout << 'a';
                else cout << '.';
            }
            cout << "\n";
        }
    } else if (n == 7) {
        cout << "abb...a\n"
             << "a.a...a\n"
             << "bba...c\n"
             << "...abbc\n"
             << "...a.ab\n"
             << "...bbab\n"
             << "bbaacc.\n";
    } else if (n == 11) {
        cout << "bccaabbccaa\n"
             << "babb...abbc\n"
             << "ca.a...a.ac\n"
             << "cbba...bbab\n"
             << "baccbcc...b\n"
             << "ba.ab.b...a\n"
             << "accaccb...a\n"
             << "a...baacaab\n"
             << "b...b.bc.cb\n"
             << "b...aabaaca\n"
             << "ccaabbccbba\n";
    } else {
        int a, b;
        for (int i = n / 5; i >= 0; i--) {
            if ((n - 5 * i) % 4 == 0) {
                a = i;
                b = (n - 5 * i) / 4;
                break;
            }
        }
        // eprintf("a=%d, b=%d\n", a, b);
        vector<string> s4 = {"aaca", "bbca", "acbb", "acaa"},
                       s5 = {"aacca", "c.bba", "cb..c", "ab..c", "accaa"};
        rep (i, n) {
            rep (j, n) {
                if (i / 5 == j / 5 && i / 5 < a) {
                    // cout << 1;
                    cout << s5[i % 5][j % 5];
                } else if ((i - 5 * a) / 4 == (j - 5 * a) / 4 && i - 5 * a >= 0 && j - 5 * a >= 0) {
                    // cout << 2;
                    cout << s4[(i - 5 * a) % 4][(j - 5 * a) % 4];
                } else {
                    // cout << 3;
                    cout << '.';
                }
            }
            cout << "\n";
        }
    }
    return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    vector<ll> A(3);
    cin >> A[0] >> A[1] >> A[2];
    sort(A.begin(), A.end());
    ll K;
    cin >> K;
    rep(i, K) A.back() *= 2;
    cout << accumulate(A.begin(), A.end(), 0LL) << endl;
    return 0;
}

#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

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

signed main() {
  init();
  ll A, B, C;
  cin >> A >> B >> C;
  ll K;
  cin >> K;
  ll m1 = max(max(A, B), C);
  ll m2 = max(max(A, B), C);
  rep(i, K) {
    m1 *= 2;
  }

  ll ans = A + B + C - m2 + m1;
  COUT(ans);

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b

signed main(){
	vi v(3);
	rep(i,0,3)cin>>v[i];
	sort(all(v));
	cout<<(v[0]+v[1])<<endl;

	return 0;
}

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

signed main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  int ans = 0;
  for (int i = 1; i < N; i++) {
    int d = A[i - 1] - A[i];
    if (d > 0) {
      ans += d;
      A[i] = A[i - 1];
    }
  }

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


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

int main() {
int n;
int r;
int x;
cin >> n;
cin >> r;
x = 100*(10-n)+r;
if (n >= 10) {
  cout << r;
} else {
 cout << x;
}
	return 0;
}

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int N, R;
  cin >> N >> R;
  if (N < 10) {
    R += 100 * (10 - N);
  }
  cout << R << '\n';
  return 0;
}


#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <assert.h>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <math.h>
#include <string>
#include <string.h>
#include <queue>
#include <complex>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
ll mod=1e9+7;
double eps=1e-7;
ll exp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=(x*x)%mod){if(y&1)ret=(ret*x)%mod;}return ret;}
ull pexp(ull x,ull y){if(y<0) return 0; ull ret=1; for(;y;y>>=1,x=(x*x)){if(y&1)ret=(ret*x);}return ret;}
ll gcd(ll x,ll y){if(!x||!y) return x+y; return x%y==0?y:gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll bsum(ll u,ll b){ll ret=0;if(u<b)return u;while(u){ret+=u%b;u/=b;}return ret;}
ll prival(ll u,ll p){ll cn=0;while(u%p==0){cn++;u=u/p;}return cn;}
ll minv(ll a,ll b){return 1<a?b-minv(b%a,a)*b/a:1;}
ll extm(ll a,ll b){ll ret=0;while(a!=0){if(a%2==1){ret+=b;ret%=mod;}a>>=1;b=(2*b)%mod;}return ret;}
ll eaphi(ll x){ll t=x,ret=x,i;for(i=2;i*i<=x;i++){if(t%i==0){ret-=ret/i;while(t%i==0) t/=i;}}if(t!=1) ret-=ret/t;return ret;}
ll eadivc(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=2;if(x%i==0 && i*i==x) ret+=1;}return ret;}
ll eadivs(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=i+x/i;if(x%i==0 && i*i==x) ret+=i;}return ret;}
ll ndig(ll x, ll b){ll ret=0;while(x){x/=b; ret++;}return ret;}
ll rev(ll n, ll b){ll ret=0;while(n){ret=b*ret+n%b; n/=b;}return ret;}
ll sq(ll x){ll t=(ll)sqrt(x); for(ll i=t-2 ; i<=t+2 ; i++) if(i*i==x) return abs(i); return -1;}
ll extexp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=extm(x,x)){if(y&1)ret=extm(ret,x);}return ret;}
bool isprime(ll x){if(x<=1) return false; for(ll i=2;i*i<=x;i++){if(x%i==0){return false;}}return true;}
ll n, k, T, x, y, cnt;
ll vv[55];

int main(void)
{
	cin>>k; n=50; T=k/n; ll i;
	x=T+2*n-k%n; y=x-n-1;
	for(i=1 ; i<=k%n ; i++) vv[i]=x;
	for(i=k%n+1 ; i<=n ; i++) vv[i]=y;
	cout<<n<<"\n";
	for(i=1 ; i<=n ; i++) cout<<vv[i]<<" ";
	return 0;
}

// 제출하기 전에 생각햇나요?
// it may be easier/harder than you think
// ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

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

int main()
{
    string S, target = "FESTIVAL";
    cin >> S;

    S.replace(S.length()-target.length(),S.length(),"");

    cout << S << endl;

    return 0;
}


#include <iostream>
using namespace std;

int main() {
	int month, day; cin >> month >> day;
	while (month != 0 && day != 0) {
		if (month >= 1) day = day;
		if (month >= 2) day = day + 31;
		if (month >= 3) day = day + 29;
		if (month >= 4) day = day + 31;
		if (month >= 5) day = day + 30;
		if (month >= 6) day = day + 31;
		if (month >= 7) day = day + 30;
		if (month >= 8) day = day + 31;
		if (month >= 9) day = day + 31;
		if (month >= 10) day = day + 30;
		if (month >= 11) day = day + 31;
		if (month >= 12) day = day + 30;
		if (day % 7 == 0) cout << "Wednesday" << endl;
		if (day % 7 == 1) cout << "Thursday" << endl;
		if (day % 7 == 2) cout << "Friday" << endl;
		if (day % 7 == 3) cout << "Saturday" << endl;
		if (day % 7 == 4) cout << "Sunday" << endl;
		if (day % 7 == 5) cout << "Monday" << endl;
		if (day % 7 == 6) cout << "Tuesday" << endl;
		cin >> month >> day;
	}
	return 0;
}

#include<bits/stdc++.h>

using namespace std;

#define debug(x) cout << (#x) << " is " << x << endl;
#define Q int t; scanf("%d", &t); for(int q=1; q<=t; q++)
typedef long long int lli;
typedef pair<int, int> pi;

int main()
{
    int has = 1, a, b, ans=0;
    cin >> a >> b;
	while(has < b){
		has--;
		has += a;
		ans++;
	}
	cout << ans << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

using i64 = int64_t;

const i64 MOD = 1e9 + 7;

struct LowLink{
    vector<vector<int>>& edges;
    // 関節点
    vector<int> art;
    vector<pair<int,int>> bridge;

    vector<int> used, ord, low;
    int k;

    void dfs(int idx, int par){
        ord[idx] = k++;
        low[idx] = ord[idx];
        bool is_art = false;
        int cnt = 0;
        for(auto& to : edges[idx]){
            if(ord[to] == -1){
                ++cnt;
                dfs(to, idx);
                low[idx] = min(low[idx], low[to]);
                is_art |= par != -1 && low[to] >= ord[idx];
                if(ord[idx] < low[to])
                    bridge.emplace_back(idx, to);
            }else if(to != par)
                low[idx] = min(low[idx], ord[to]);
        }
        is_art |= (par == -1 && cnt > 1);
        if(is_art)
            art.emplace_back(idx);
    }

    LowLink(vector<vector<int>>& edges) :
        edges(edges),
        ord(edges.size(), -1),
        low(edges.size(), 0),
        k(0)
    {
        for(int i = 0; i < edges.size(); ++i)
            if(ord[i] == -1)
                dfs(i, -1);
        for(auto& b : bridge)
            b = make_pair(min(b.first, b.second), max(b.first, b.second));
        sort(art.begin(), art.end());
        sort(bridge.begin(), bridge.end());
    }
};

signed main(){
    int n, m;
    cin >> n >> m;
    vector<pair<int,int>> v(m);
    vector<vector<int>> edges(n);
    for(int i = 0; i < m; ++i){
        vector<int> l(2);
        for(auto& x : l)
            cin >> x;
        sort(l.begin(), l.end());
        v[i] = make_pair(l.front(), l.back());
        edges[l[0]].emplace_back(l[1]);
        edges[l[1]].emplace_back(l[0]);
    }
    LowLink ll(edges);
    for(auto& x : ll.art)
        cout << x << endl;
}

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

using namespace std;
#define MAX 10000

vector<int> G[MAX];
int n;
bool visited[MAX];
int treeIdx[MAX], parent[MAX], lowest[MAX], treeNodeCounter;

void dfs(int curIdx, int prev)
{
	treeIdx[curIdx] = lowest[curIdx] = treeNodeCounter;
	treeNodeCounter++;

	visited[curIdx] = true;
	int next;

	for (int i = 0; i < G[curIdx].size(); ++i)
	{
		next = G[curIdx][i];
		if (!visited[next])
		{
			parent[next] = curIdx;
			dfs(next, curIdx);
			lowest[curIdx] = min(lowest[curIdx], lowest[next]);
		}
		else if (next != prev)
		{
			lowest[curIdx] = min(lowest[curIdx], treeIdx[next]);
		}
	}
}

void criticalPoints()
{
	for (int i = 0; i < n; ++i)
		visited[i] = false;
	treeNodeCounter = 1;

	dfs(0, -1);

	set<int> s;
	int np = 0;
	for (int i = 1; i < n; ++i)
	{
		int p = parent[i];
		if (0 == p) np++;
		else if (treeIdx[p] <= lowest[i])
			s.insert(p);
	}
	if (np > 1) cout << 0 << endl;
	for (auto v : s) cout << v << endl;
}

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

	for (int i = 0; i < m; ++i)
	{
		int s, t;
		cin >> s >> t;
		G[s].push_back(t);
		G[t].push_back(s);
	}
	criticalPoints();

	return 0;
}


#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    string s;
    cin >> s;
    if(s.size() == 2)
    {
        cout << s << "\n";
    }
    else
    {
        for(int i = s.size() - 1;i >= 0;i--)
        {
            cout << s[i];
        }
        cout << "\n";
    }

    return 0;
}

#include <bits/stdc++.h>

using namespace std;

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

	string s;

	cin >> s;

	if(s.length()==3)
	{
		reverse(s.begin(),s.end());
	}

	cout << s << '\n';

	return 0;
}


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

const ll Mod = 1000000007;
bool exists(vector<ll>& vec,ll x)
{
    auto pos = lower_bound(vec.begin(),vec.end(),x);
    if(pos == vec.end())return false;
    return *pos == x;
}
void solve(ll N, ll M, vector<ll> A, vector<ll> B)
{
    ll ans = 1;
    sort(A.begin(),A.end());
    sort(B.begin(),B.end());
    ll empty = 0;
    ll numrow=0,numcol=0;
    for(ll x = M*N;x>=1;--x)
    {
        if(exists(A,x))
        {
            if(exists(B,x))
            {
                empty += numcol + numrow;
                numcol++;
                numrow++;
            }else
            {
                empty += numcol - 1;
                ans *= numcol;
                ans %= Mod;
                numrow++;
            }
        }else
        {
            if(exists(B,x))
            {
                empty += numrow - 1;
                ans *= numrow;
                ans %= Mod;
                numcol++;
            }else
            {
                if(empty <= 0)
                {
                    cout<<0<<endl;
                    return;
                }
                ans *= empty;
                empty--;
                ans %= Mod;
            }
        }
    }
    cout<<ans<<endl;
}

int main()
{
    ll N;
    cin >> N;
    ll M;
    cin >> M;
    vector<ll> A(N);
    for(int i = 0 ; i < N ; i++)
    {
        cin >> A[i];
    }
    vector<ll> B(M);
    for(int i = 0 ; i < M ; i++)
    {
        cin >> B[i];
    }
    solve(N, M, move(A), move(B));
    return 0;
}

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#define inf 0x3f3f3f3f
#define MOD 1000000007
using namespace std;
typedef long long ll;

template <typename Tp> inline void getint(Tp &num){
	register int ch, neg = 0;
	while(!isdigit(ch = getchar())) if(ch == '-') neg = 1;
	num = ch & 15;
	while(isdigit(ch = getchar())) num = num * 10 + (ch & 15);
	if(neg) num = -num;
}

int N, M, A[1005], B[1005];
ll ans = 1;

int main(){
	getint(N), getint(M);
	for(register int i = 1; i <= N; i++) getint(A[i]);
	for(register int i = 1; i <= M; i++) getint(B[i]);
	sort(A + 1, A + N + 1), sort(B + 1, B + M + 1), A[N + 1] = B[M + 1] = inf;
	for(register int i = 1; i < N; i++) if(A[i] == A[i + 1]) return puts("0"), 0;
	for(register int i = 1; i < M; i++) if(B[i] == B[i + 1]) return puts("0"), 0;
	for(register int i = 1, j = 1, k = 1; i <= N * M; i++){
		while(j <= N && A[j] < i) j++;
		while(k <= M && B[k] < i) k++;
		if(A[j] == i && B[k] != i) ans = ans * (M - k + 1) % MOD;
		else if(A[j] != i && B[k] == i) ans = ans * (N - j + 1) % MOD;
		else if(A[j] != i && B[k] != i) ans = ans * ((M - k + 1) * (N - j + 1) - (N * M - i)) % MOD;
	}
	return printf("%lld\n", ans), 0;
}


#include <bits/stdc++.h>
using namespace std;
int main() {
  int A;
  int B;
  cin>>A>>B;
  int i=0;
  int j=B-A;
  int sum=0;
  int C=A;
  while(i<=j){
    A=C;
    int a=A%10;//A=12345の時5
    A/=10;//A=1234
    int b=A%10;
    A/=10;//A=123
    A/=10;//A=12
    int d=A%10;
    A/=10;//A=1
    int e=A;
    if(a==e&&b==d){
      sum+=1;
    }
    C++;
    i++;
  }
  cout<<sum<<endl;

}

#include<iostream>
using namespace std;

int main() {
    string sa, sb, sc;
    cin >> sa >> sb >> sc;
    int na = sa.length() + 1;
    int nb = sb.length() + 1;
    int nc = sc.length() + 1;

    int a = 0, b = 0, c = 0;
    char next = 'a', ans = 'A';
    while(a < na && b < nb && c < nc) {
        if (next == 'a') {
            next = sa[a];
            a++;
            ans = 'A';
        } else if (next == 'b') {
            next = sb[b];
            b++;
            ans = 'B';
        } else {
            next = sc[c];
            c++;
            ans = 'C';
        }
    }

    cout << ans << endl;

}


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

int main() {
  int a;
  int ma = 0, mi = 999;
  for (int i=0; i<5; i++) {
    cin >> a;
    ma = max(ma, a);
    mi = min(mi, a);
  }
  int dist = ma - mi;
  int k;
  cin >> k;
  if (dist <= k) cout << "Yay!" << endl;
  else cout << ":(" << endl;
}

#include <iostream>
using namespace std;

void call(int n){
	bool end_check_num=false;
	int i=1,x;
	while(1){//check_num
		while(1){//end_check_num
			x=i;
			if(x%3==0){
				cout<<" "<<i;
				break;//goto end_check_num
			}
			while(1){//include3
				if(x%10==3){
					cout<<" "<<i;
					end_check_num=true;
					break;//goto end_check_num
				}
				if(end_check_num) break;
				x/=10;
				if(x==0) break;//goto include3
			}
			break;
		}
		//end_check_num
		end_check_num=false;
		if(++i>n) break;
	}
	cout<<endl;
}

int main(){
	int n=0;
	cin>>n;
	call(n);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,K;
  cin>>N>>K;
  if(N<K){
    cout<<1<<endl;
  }
  else if(N%K==0){
    cout<<0<<endl;
  }
  else{
    cout<<1<<endl;
  }
}

#include <iostream>
#include <climits>      // to use INT_MIN and INT_MAX
using namespace std;
typedef long long ll;

ll arr[100005];

ll gcd(ll a, ll b) {    // Euclidean algorithm
	if (b == 0) return a;
      return gcd(b, (a%b));
      // doing a%b will also help swap both numbers in the case b>a
}

bool multiples(ll N, ll K, ll min, ll max) {
      ll gcdRes = 0;

      // (1) CHECK FOR GCD IN ARRAY
      for(ll i=0; i<N; i++) {
            gcdRes = gcd(gcdRes, arr[i]);
      }

      // (2) CHECK IF TARGET K IS DIVISIBLE BY GCD
      bool flag = false;
      if(K % gcdRes != 0) {
            flag = true;
      }
      return flag;
}

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

      ll N, K, min = INT_MAX, max = INT_MIN;
      cin >> N >> K;

      for(int i=0; i<N; i++) {
            cin >> arr[i];

            if(arr[i] == K) { // box already contains target K
                  cout << "POSSIBLE" << endl;
                  exit(0);
            }
            if(arr[i] < min) min = arr[i];
            if(arr[i] > max) max = arr[i];
	}
      // If max (eg. 5) is less than target (eg. 10),
      // Even if min=1 (smallest possible from constraints), abs diff will never reach target:
      if(max < K) {
            cout << "IMPOSSIBLE" << endl;
            exit(0);
      }
      if(multiples(N , K, min, max) == true){
		cout << "IMPOSSIBLE" << endl;
	}
	else cout << "POSSIBLE" << endl;
}


#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}
const int dm = 1400000;
char dn[dm], * di = dn;
const int MAX = 20000;
class unko {
public:
	char C[MAX * 7 + 10], *K[MAX + 10];
	constexpr unko() : C(), K() {
		auto di = C + 3;
		C[0] = '0';
		C[0] = ' ';
		C[0] = '\n';
		K[0] = C;
		K[1] = di;
		rep1(i, MAX) {
			int X = i;
			int keta = 0;
			char c[10] = {};
			while (X) {
				*(c + keta) = '0' + X % 10;
				X /= 10;
				keta++;
			}
			for (int j = keta - 1; j >= 0; j--)* di++ = (*(c + j));
			*di++ = ' ';
			*di++ = '\n';
			K[i + 1] = di;
		}
	}
};
constexpr unko f;
inline void putint(int X) {
	if (X > 20000) {
		int ue = X / 10;
		for (auto i = f.K[ue]; *i != ' '; i++) *di++ = *i;
		*di++ = '0' + X % 10;
		*di++ = ' ';
	}
	else for (auto i = f.K[X]; *i != '\n'; i++)* di++ = *i;
}

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

	int N = getint(), K = getint();

	int A[200001];
	rep(i, N) A[i] = getint();
	ll owa = ll(N) * N;

	rep(p, K) {
		int B[200001] = {};
		rep(i, N) {
			B[max(0, i - A[i])]++;
			B[min(N, i + A[i] + 1)]--;
		}
		ll kei = B[0];
		A[0] = B[0];
		rep1(i, N - 1) {
			kei += (A[i] = A[i - 1] + B[i]);
		}
		if (kei == owa) break;
	}

	rep(i, N) putint(A[i]);
	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}

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

int main(){
	int n;
	cin>>n;
	long long ret = 0;
	int neg = 0;
	vector<long long>arr(n);
	for(int i=0; i<n; i++){
		cin>>arr[i];
		if(arr[i]<0) neg++;
		ret+=abs(arr[i]);
		arr[i] = abs(arr[i]);
	}
	if(neg%2) ret-=2*(*min_element(arr.begin(),arr.end()));
	cout<<ret;
}


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

int main(){
  int n;
  cin >> n;
  set <int> s;
  for(int i = 0;i < n;++i){
    int num;
    cin >> num;
    auto itr = s.find(num);
    if(itr == s.end()) s.insert(num);
    else s.erase(num);
  }
  cout << (int)s.size() << endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main()
{
long long a,b,i,c=0,d=0,n,m,t,j;
cin>>n;
long long A[n];
for(i=0;i<n;i++)
cin>>A[i];
sort(A,A+n);
for(i=0;i<n-1;i++)
{
  if(A[i]==A[i+1])
  {
    c+=2;
    i++;
  }
}
std::cout <<n-c<< '\n';
return 0;
}


#include <cstdio>
#include <utility>
#include <cmath>
#include <algorithm>
using namespace std;

#define gcu getchar_unlocked
int in(int c){int n=0;bool m=false;if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;}
int in() {return in(gcu());}
bool scan(int &n){int c=gcu();return c==EOF?false:(n=in(c),true);}
bool scan(char &c){c=gcu();gcu();return c!=EOF;}
//bool scan(string &s){int c;s="";
//	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#define pcu putchar_unlocked
#define vo inline void out
template <typename T>
vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
vo(const char *s){while(*s)pcu(*s++);}
vo(char c){pcu(c);}
//vo(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail> vo(head&& h, tail&&... t){out(h);out(move(t)...);}
//template <typename T> vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
#undef vo

int main() {
	for (int e, m; (e = m = in());) {
		for (int z = cbrt(e) + 0.00001; z >= 0; z--) {
			int te = e - z * z * z;
			int y = (int)sqrt(te);
			int tm = z + y + te - y * y;
			if (y > m)
				break;
			m = min(m, tm);
		}
		out(m, '\n');
	}
}

#include <stdio.h>
#include <iostream>
#include <queue>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#define PB push_back
#define in scanf
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
using	namespace std;
void solve(){
	int e;
	while(cin >> e ,e!=0) {
	int m =1000000000;
	int x;
	for(int z=0;z*z*z<=e;z++){
		for(int y=0;y*y+z*z*z<=e;y++){
			x = e-y*y-z*z*z;
			m = min(x + y + z,m);

		}
	}
	cout << m  << endl;

}
}

int main(){
	solve();

}


#include<iostream>
#include<math.h>
using namespace std;

int main(){
    long long a,b,c,d=0,e=0;
    cin>>a>>b>>c;
    if(a==b && b==c || a!=b && b!=c && a!=c){cout<<"No";return 0;}
    else{cout<<"Yes";}
    return 0;
}

//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;
typedef struct pair<int,int> P;
int A,B,C,D,E,F;
int main() {
	cin>>A>>B>>C>>D>>E>>F;

	int M=A;
	if(B<M)M=B;
	if(C<M)M=C;
	if(D<M)M=D;
	int R=A+B+C+D-M;
	int L=0;
	if(E<F){
		L=F;
	}else{
		L=E;
	}

	cout<<R+L<<endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	string s;
	cin >> s;
	int n = int(s.size());
	if(n == 2 && s[0] == s[1]) return cout << 1 << ' ' << 2 << '\n', 0;
	for(int i = 0; i < n - 2; ++i){
		string ac = s.substr(i, 3);
		if(ac[0] == ac[1] || ac[0] == ac[2] || ac[1] == ac[2]){
			return cout << i + 1 << ' ' << i + 3 << '\n', 0;
		}
	}
	cout << -1 << ' ' << -1 << '\n';
	return 0;
}

#include <bits/stdc++.h>
#define s second
#define f first
#define pb push_back
#define endl '\n'
using namespace std;

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

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;

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

	string S;
	cin >> S;

	vector<vector<int>> Oc(27);

	for(int i = 0; i < S.size(); i++){
		Oc[S[i] - 'a'].pb(i);
	}

	bool can = 0;

	for(int i = 0; i < 27; i++){
		for(int l = 0; l < Oc[i].size(); l++){
			for(int r = l + 1; r < Oc[i].size(); r++){
				if(r - l + 1 > (Oc[i][r] - Oc[i][l] + 1)/2){
					can = 1;
					cout << Oc[i][l] + 1 << " " << Oc[i][r] + 1 << endl;
				}
				if(can) break;
			}
			if(can) break;
		}
		if(can) break;
	}

	if(!can){
		cout << -1 << " " << -1 << endl;
	}

	return 0;
}


#include <iostream>
using namespace std;

int bubbleSort(int A[], int N)
{
  int s = 0;
  for(int i = 0; i < N - 1; i++)
    for(int j = N - 1; j > i; j--)
      if(A[j] < A[j - 1]){
	int tmp = A[j - 1];
	A[j - 1] = A[j];
	A[j] = tmp;
	s++;
      }
  return s;
}

int main()
{
  int N;
  cin >> N;
  int A[N];
  for(int i = 0; i < N; i++)
    cin >> A[i];
  int n = bubbleSort(A, N);
  for(int i = 0; i < N; i++)
    if(i)
      cout << " " << A[i];
    else
      cout << A[i];
  cout << endl << n << endl;
}

#include <iostream>
#include <cmath>
#include <vector>
#include <climits>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> v;
    for(int i = 0;i < n;i++)
    {
        int t;
        cin >> t;
        v.push_back(t);
    }
    bool f = true;
    int c = 0;
    while(f)
    {
        f = false;
        for(int i = 1;i < v.size();i++)
        {
            if(v.at(i) < v.at(i - 1))
            {
                int t = v.at(i - 1);
                v.at(i -1) = v.at(i);
                v.at(i) = t;
                f = true;
                c++;
            }
        }
    }
    for(int i = 0;i < v.size();i++)
    {
        cout << v.at(i);
        if(i + 1 != v.size())
        {
            cout << " ";
        }
        else
        {
            cout << endl;
        }
    }
    cout << c << endl;
}


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

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
        #define eprintf(...) 42
#endif

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define all(x) (x).begin(),(x).end()
#define foreach(u,v) for(auto (u) : (v))
#define pb push_back
#define mp make_pair
#define mt make_tuple

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

const int inf = 1e9;
const ll linf = 1LL<<60;
const ll mod = 1e9 + 7;
const double eps = 1e-9;

/*
*/

typedef tuple<int, int, int> triple;

int n, m;
map<pii, vector<triple>> g;
map<pii, ll> dist;

int main()
{
  cin >> n >> m;
  rep(i, m){
    int p, q, c;
    cin >> p >> q >> c;
    p--; q--;

    g[mp(p, c)].pb(mt(q, c, 0));
    g[mp(q, c)].pb(mt(p, c, 0));
    g[mp(p, c)].pb(mt(q, -1, 0));
    g[mp(q, c)].pb(mt(p, -1, 0));
    g[mp(p, -1)].pb(mt(q, c, 1));
    g[mp(q, -1)].pb(mt(p, c, 1));

    dist[mp(p, c)] = linf;
    dist[mp(q, c)] = linf;
    dist[mp(p, -1)] = linf;
    dist[mp(q, -1)] = linf;
  }

  rep(i, n) dist[mp(i, -1)] = linf;

  priority_queue<triple, vector<triple>, greater<triple>> que;
  que.push(mt(0, 0, -1));
  dist[mp(0, -1)] = 0;

  while(!que.empty()){
    int d, v, c;
    tie(d, v, c) = que.top();
    que.pop();

    if(dist[mp(v, c)] < d) continue;
    for(auto e : g[mp(v, c)]){
      int to, cc, dd;
      tie(to, cc, dd) = e;
      if(dist[mp(to, cc)] > dist[mp(v, c)] + dd){
        dist[mp(to, cc)] = dist[mp(v, c)] + dd;
        que.push(mt(dist[mp(to, cc)], to, cc));
      }
    }
  }

  ll ans = dist[mp(n-1, -1)];
  if(ans == linf) cout << -1 << endl;
  else cout << ans << endl;

  return 0;
}

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#define MN 301000
#define MM 1601000

typedef std::pair<int, int> P;
int h[MN], nxt[MM], to[MM], cost[MM], K = 0;
std::vector<P> v[101000];
int d[MN], n, m;
std::deque<int> q;

void ins(int u, int v, int c) {nxt[++K] = h[u]; h[u] = K; to[K] = v; cost[K] = c;}

int bfs()
{
	q.push_back(1);
	memset(d, 0x3f, sizeof(d)); d[1] = 0;
	while(!q.empty())
	{
		int u = q.front(); q.pop_front();
		for(int i = h[u]; i; i = nxt[i])
		{
			if(d[to[i]] > d[u] + cost[i])
			{
				d[to[i]] = d[u] + cost[i];
				if(cost[i]) q.push_back(to[i]);
				else q.push_front(to[i]);
			}
		}
	}
	if(d[n] > 1e9) return -1;
	return d[n];
}

int main()
{
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= m; i++)
	{
		int p, q, c; scanf("%d%d%d", &p, &q, &c);
		v[p].push_back(P(c, i));
		v[q].push_back(P(c, i));
		ins(p, n + i, 1); ins(n + i, p, 0);
		ins(q, n + i, 1); ins(n + i, q, 0);
	}
	for(int i = 1; i <= n; i++)
	{
		std::sort(v[i].begin(), v[i].end());
		int S = v[i].size();
		for(int j = 1; j < S; j++)
		{
			if(v[i][j].first == v[i][j - 1].first)
			{
				ins(v[i][j].second + n, v[i][j - 1].second + n, 0);
				ins(v[i][j - 1].second + n, v[i][j].second + n, 0);
			}
		}
	}
	printf("%d\n", bfs());
}


#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <chrono>
#include <vector>
#include <map>
#include <random>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
using namespace std;

#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define emb emplace_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>

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

template <typename T> inline T range(T l, T r) {
    return uniform_int_distribution<T>(l, r)(rng);
}

inline void setin(string s) {
    freopen(s.c_str(), "r", stdin);
}

inline void setout(string s) {
    freopen(s.c_str(), "w", stdout);
}

template <typename T> void Min(T &a, T b) {
    a = min(a, b);
}

template <typename T> void Max(T &a, T b) {
    a = max(a, b);
}

const int inf = 0x3f3f3f3f;
const int mod = 998244353;
const int N = 3e2 + 15;
int n, k;
string s;
int dp[2][N][N]; // dp[i][operation_applied][free_ones]
int a[N];

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

inline void add_t(int &a, int b) {
    a = add(a, b);
}

inline int mt(int a, int b) {
    return 1ll * a * b % mod;
}

inline void construct() {
    int sz = 1;
    for(int i = 1; i <= n && s[i] == '1'; ++i)
        a[1] = i;
    for(int i = a[1] + 1; i <= n; ++i) {
        if(s[i] == '0') {
            if(i + 1 <= n && s[i + 1] == '0')
                a[++sz] = 0;
        }
        else {
            int j = i;
            while(j + 1 <= n && s[j + 1] == '1')
                ++j;
            a[++sz] = j - i + 1;
            i = j;
        }
    }
    n = sz;
}

inline void solve() {
    // dp[i][operation_applied][free_ones]
    dp[(n + 1) & 1][0][0] = 1;
    int sum = 0;
    for(int i = n; i >= 1; --i) {
        int bit = i & 1;
        memset(dp[bit], 0, sizeof(dp[bit]));
        for(int k = 0; k <= sum; ++k) {
            int val = 0;
            for(int t = sum; t >= 0; --t) {
                add_t(dp[bit][k][t], val);
                for(int j = 0; j <= a[i] && k + j < N; ++j)
                    add_t(dp[bit][k + j][t + j], dp[bit ^ 1][k][t]);
                add_t(val, dp[bit ^ 1][k][t]);
            }
        }
        sum += a[i];
    }
}

inline void output() {
    int ans = 0;
    for(int i = 0; i < min(N, k + 1); ++i)
        add_t(ans, dp[1][i][0]);
    cout << ans << endl;
}

main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // setin("input.txt");
    cin >> s >> k;
    n = s.size();
    s = '#' + s;
    construct();
    solve();
    output();
    return 0;
}

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

#define endl '\n'
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << ends << H; debug_out(T...); }
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll MOD = 998244353;

////////////////////////////////////////////////////////////////////

const int N = 3e2 + 5;

int A[N], DP[N][N][N];

void Add(int &x, int y) {
	x += y;
	if (x >= MOD) x -= MOD;
}

int main() {

	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	mt19937 Rnd(time(0));

	string S; cin >> S;
	int m = 1, o = 0;
	for (char c : S) if (c == '0') m++; else A[m - 1]++, o++;
	reverse(A, A + m);
	DP[0][0][0] = 1;
	for (int i = 0; i < m; i++) for (int j = 0; j <= o; j++) for (int k = 0; k <= o; k++) {
		if (!DP[i][j][k]) continue;
		for (int l = 0; l <= A[i] + k; l++) Add(DP[i + 1][j + max(A[i] - l, 0)][k + A[i] - l], DP[i][j][k]);
	}
	int k; cin >> k;
	k = min(k, o);
	int ans = 0;
	for (int i = 0; i <= k; i++) Add(ans, DP[m][i][0]);
	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

// For modular arithmetic when a modular is specified per input case.
// Verified: ABC129F
struct ModInt {
 private:
  static int64 M;
  int64 x;
 public:
  static void SetMod(int64 mod) {
    M = mod;
  }
  ModInt(int64 input_x) : x(input_x % M) {}
  ModInt() : x(0) {}
  int64 Value() { return x; }
  inline ModInt operator+(ModInt o) {
    ModInt r(*this); r += o; return r;
  }
  inline ModInt operator-(ModInt o) {
    ModInt r(*this); r -= o; return r;
  }
  inline ModInt operator* (ModInt o) {
    ModInt r(*this); r *= o; return r;
  }
  inline void operator+= (ModInt o) { x = (x + o.x) % M; }
  inline void operator-= (ModInt o) { x = (x + M - o.x) % M; }
  inline void operator*= (ModInt o) { x = (x * o.x) % M; }
};
int64 ModInt::M = 1;  // Do not forget to add this line.

template<typename T>
vector<vector<T>> MakeVector2D(int d1, int d2, T default_value) {
  return vector<vector<T>>(d1, vector<T>(d2, default_value));
}

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

  int n;
  cin >> n;
  int m;
  cin >> m;
  ModInt::SetMod(m);

  const int BASE = n;
  auto dp = MakeVector2D<ModInt>(3 * n + 1, 2 * n + 1, ModInt(0));
  dp[0][BASE] = 1;
  for (int i = 0; i < 3 * n; i++) {
    for (int k = 0; k <= 2 * n; k++) {
      if (dp[i][k].Value() == 0) continue;
      // Size 1
      dp[i + 1][min(k + 1, 2 * n)] += dp[i][k];

      // Size 2
      if (k > 0 && i + 2 <= 3 * n) {
        dp[i + 2][k - 1] += dp[i][k] * (i + 1);
      }

      // Size 3
      if (i + 3 <= 3 * n) {
        dp[i + 3][k] += dp[i][k] * (i + 1) * (i + 2);
      }
    }
  }

  ModInt ans = 0;
  for (int k = BASE; k <= 2 * n; k++) {
    // cout << dp[3 * n][k].Value() << endl;
    ans += dp[3 * n][k];
  }
  cout << ans.Value() << endl;
}

#include <bits/stdc++.h>

using namespace std;
#define  ll long long
#define ld long double
#define f first
#define s second

int n , g , p[11] , c[11] , mn=1e9;
bool vis[11];

void solve(int i , int sum , int cnt)
{
    if (i > n)
    {
        int rem = g-sum;
        if (rem <= 0) mn = min(mn , cnt);
        else
        {
            for(int j=n; j>0; j--)
            {
                if (vis[j]) continue;
                for(int k=1; k<=p[j]; k++)
                {
                    rem -= j*100 , cnt++;
                    if (rem <= 0)
                    {
                        mn = min(mn , cnt);
                        return;
                    }
                }
            }
        }
        return;
    }

    vis[i] = 1;
    solve(i+1 , sum+p[i]*i*100+c[i] , cnt+p[i]);
    vis[i] = 0;
    solve(i+1 , sum , cnt);
}

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

    cin >> n >> g;
    for(int i=1; i<=n; i++)
    {
        cin >> p[i] >> c[i];
    }

    solve(1,0,0);
    cout << mn << '\n';

    return 0;
}


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

int main(void) {
    string str, cmd, rep;
    int q, s, e;

    cin >> str >> q;
    for (int i = 0; i < q; i++) {
        cin >> cmd >> s >> e;
        int interval = e - s + 1;

        if (cmd == "print") {
            cout << str.substr(s, interval) << endl;
        } else if (cmd == "reverse") {
            string original = str.substr(s, interval);
            int size = original.size();
            for (int i = 0; i < size; i++) {
                str[s + i] = original[size - i - 1];
            }
        } else if (cmd == "replace") {
            cin >> rep;
            str.replace(s, interval , rep);
        }
    }

    return 0;
}

#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;

int main() {
    int H, W;
    cin >> H >> W;
    int cnt = 0;
    vector<vector<char>> G(H, vector<char>(W));
    vector<pint> flip;
    rep(i, H) {
        rep(j, W) {
            cin >> G[i][j];
            if (G[i][j] == '.')
                cnt++;
            else
                flip.push_back({i, j});
        }
    }

    ll ans = 0;
    int dx[4] = {1, 0, 0, -1};
    int dy[4] = {0, 1, -1, 0};
    while (cnt != 0) {
        vector<pint> A;
        rep(i, flip.size()) {
            for (int j = 0; j < 4; j++) {
                pint p = flip[i];
                int ny = p.first + dy[j];
                int nx = p.second + dx[j];
                if (ny < 0 || nx < 0 || ny >= H || nx >= W)
                    continue;
                if (G[ny][nx] == '#')
                    continue;
                G[ny][nx] = '#', cnt--, A.push_back({ny, nx});
            }
        }
        ans++;
        flip = A;
    }

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


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

// Inserted snippets: io, root
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }
// End snippets

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

  int sx, sy, tx, ty;
  read(sx, sy, tx, ty);
  int dx = tx - sx, dy = ty - sy;
  write(
      "L" +
      string(dy + 1, 'U') +
      string(dx + 1, 'R') +
      "D" +
      "R" +
      string(dy + 1, 'D') +
      string(dx + 1, 'L') +
      "U" +
      string(dy, 'U') +
      string(dx, 'R') +
      string(dy, 'D') +
      string(dx, 'L')
      );
}

#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

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

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;

  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;

    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }

    res.push_back({i,ex});
  }

  if(n != 1) res.push_back({n,1});

  return res;

}

int main(){
  ll sx,sy,tx,ty; cin >> sx >> sy >> tx >> ty;
  ll dx = tx - sx; ll dy = ty - sy;

  cout << string(dx,'R') << string(dy,'U') << string(dx,'L') <<
    string(dy,'D') << 'D' << string(dx+1,'R') <<
    string(dy+1,'U') << 'L' << 'U' << string(dx+1,'L') <<
    string(dy+1,'D') << 'R' << endl;

}


// luogu-judger-enable-o2
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cctype>
typedef long long int64;
using namespace std;
inline int64 read(int f = 1, int64 x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 1e5+5;
int n, m, a[N], f[N], s[N], top, vis[N];
int64 ans[N], k;
int main()
{
    n = read();
    for(int i = 1; i <= n; ++i) a[i] = read();
    for(int i = n; i; --i) a[i] -= a[i-1], f[i] = i;
    m = read(), k = read();
    for(int i = 1, p; i <= m; ++i) p = read(), swap(f[p], f[p+1]);
    for(int i = 1; i <= n; ++i, top = 0)
        if(!vis[i])
        {
            for(int j = i; !vis[j]; j = f[j]) vis[j] = 1, s[++top] = j;
            for(int j = 1; j <= top; ++j) ans[s[j]] = a[s[(j+k-1)%top+1]];
        }
    for(int i = 1; i <= n; ++i) printf("%lld\n", ans[i] += ans[i-1]);
    return 0;
}

//Optional FAST

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

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);
const long double PI=3.14159265358979;

// Required random number generators

// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());

//Required Functions

ll power(ll x,ll y)
{
    if (y == 0)
        return 1;
    ll p = power(x, y/2) % MOD;
    p = (p * p) % MOD;

    return (y%2 == 0)? p : (x * p) % MOD;
}
ll modInverse(ll a)
{
   return power(a,MOD-2);

}

//Work

int main()
{
    #ifndef ONLINE_JUDGE
    if (fopen("INPUT.txt", "r"))
    {
        freopen ("INPUT.txt" , "r" , stdin);
        //freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    clock_t clk;
    clk = clock();
//-----------------------------------------------------------------------------------------------------------//

    READV(N);
    READAR(A,N);
    ll P[N]={0};
    ll ans[N];
    FORI(i,0,N)
    {
        P[i]=i;
        ans[i]=i;
    }
    READV(M);
    READV(K);
    FORI(i,0,M)
    {
        READV(x);
        swap(P[x-1],P[x]);
    }
    while (K>0)
    {
        ll V[N]={0};
        if(K%2==1)
        {
            FORI(i,1,N)
            {
                ans[i]=P[ans[i]];
            }
        }
        FORI(i,1,N)
        {
            V[i]=P[P[i]];
        }
        FORI(i,1,N)
        {
            P[i]=V[i];
        }
        K=K/2;
    }
    ll diff[N]={0};
    FORI(i,1,N)
    {
        diff[i]=A[i]-A[i-1];
    }
    FORI(i,1,N)
    {
        ans[i]=diff[ans[i]];
    }
    cout<<A[0]<<endl;
    ll prev=A[0];
    FORI(i,1,N)
    {
        cout<<prev+ans[i]<<endl;
        prev=prev+ans[i];
    }
    cout<<endl;

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

    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;

    return 0;
}


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#include<assert.h>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
#define SZ(x) ((int)x.size())
using namespace std;
inline LL read()
{
	LL f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
template<typename T>inline void chkmin(T &x,T y){x=x<y?x:y;}
template<typename T>inline void chkmax(T &x,T y){x=x>y?x:y;}
const int MAXN=100005;
int X[MAXN],n,S;LL P[MAXN];
int main()
{
	n=read();S=read();
	for(int i=1;i<=n;i++)X[i]=read(),P[i]=read();LL ans=0;
	int l=1,r=n,preo=-1;
	while(l<=r&&X[l]<S&&X[r]>S)
	{
		if(P[l]>=P[r])
		{
			P[l]+=P[r];
			if(preo!=2)preo=2,ans+=X[r]-X[l];
			--r;
		}
		else
		{
			P[r]+=P[l];
			if(preo!=1)preo=1,ans+=X[r]-X[l];
			++l;
		}
	}
	if(l<=r)
	{
		if(X[l]>=S)ans+=X[r]-S;
		else ans+=S-X[l];
	}pr2(ans);
	return 0;
}

/*
 * Since g++10 is released, some characters is not valid inside #if 0 :(
 * So, why not using clang++? :D

 * Date:
  echo -n '  ' && date +%Y.%m.%d # Just Run this (Type !!sh in Vim).

 * Solution:
 * 考虑边界，推导结论，子问题递归求解

  如果 S <= p[1] 或者 S >= p[n] ，显然所有人投票都是一个方向，不妨假设 p[1] < S < p[n] 。

  考虑处在最边上的 1 号点和 n 号点，如果 a[1] >= a[n] ，那么一定先到 1 ，否则先到 n 。归
纳证明，如果 n = 2 显然成立，对于 n >= 3 ，若 S >= a[n - 1] 显然成立，否则 S < a[n - 1] ，
此时考虑 1 和 n - 1 ，如果先到 n - 1 就会回到 S >= a[n - 1] 的情况。

  不妨假设 a[1] >= a[n] ，那么到 n 的时间就一定是到 1 的时间加上 1 到 n 的距离，那么 n 想
要最小化到达 n 的时间其实就是等价于最小化到达 1 的时间，可以赋值 a[1] = a[1] + a[n] 并赋
值 n = n - 1 转换为子问题，递归求解，可以求出每个点的到达时间。

 * Digression:

 * CopyRight:
          ▁▃▄▄▄▃▃▃▃▄▶
        ▗▇▀▔    ▔▔▔▔
       ▄▛   ▃▅━━■▄▂
      ▟▊   ▐▘     ▀▙
     ▟▜▌   ▐▖   ▋  ▐▍
    ▟▘ ▜   ▝▀▇▆●▘  ▐▌
  ▗▟▘   ▜▃       ▁▅▛
  ▔▀▼▅▄▃▃██▅▄▄▄▅■▀▔
        ▔▔▔▔▔▔
 */

#include <cstdio>
#include <algorithm>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long ll;

struct {
	inline operator int () { int x; return scanf("%d", &x), x; }
	inline operator ll () { ll x; return scanf("%lld", &x), x; }
	template<class T> inline void operator () (T &x) { x = *this; }
	template<class T, class ...A> inline void operator () (T &x, A &...a)
	{ x = *this; this -> operator () (a...); }
} read;

const int maxn = 1000005;
int p[maxn];
ll a[maxn];
ll t[maxn];

void solve (int l, int r, int S) {
	if (S <= p[l]) {
		for (int i = l; i <= r; i ++)
			t[i] = p[i] - S;
		return;
	}
	if (S >= p[r]) {
		for (int i = l; i <= r; i ++)
			t[i] = S - p[i];
		return;
	}
	if (a[l] >= a[r]) {
		a[l] += a[r];
		solve(l, r - 1, S);
		t[r] = t[l] + p[r] - p[l];
	} else {
		a[r] += a[l];
		solve(l + 1, r, S);
		t[l] = t[r] + p[r] - p[l];
	}
}

int main () {
	int n = read, S = read;
	for (int i = 1; i <= n; i ++) read(p[i], a[i]);
	solve(1, n, S);
	ll ans = 0;
	for (int i = 1; i <= n; i ++) ans = std::max(ans, t[i]);
	printf("%lld\n", ans);
}


#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<iomanip>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define sz(a) (int)a.size()
using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    long double n, m, d;
    cin >> n >> m >> d;
    if (d == 0) {
        cout << fixed<<setprecision(12)<<(m-1)*(1/n)  << endl;
    }
    else {
        cout << fixed<<setprecision(12)<<(m-1)*(2*(n-d)/(n*n)) << endl;
    }
}

#include <iostream>

using namespace std;

int main()
{
  int D,T,S;
  cin>>D>>T>>S;
double  t=(double)D/S;
  if(t<=T){
    cout<<"Yes"<<endl;
  }
  else {
    cout<<"No"<<endl;
  }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
string s;
int main(){
	cin >> s;
	if(s.size()<26){
		for(char c='a';c<='z';c++)
			if(s.find(c)==string::npos){
				cout << s << c;
				return 0;
			}
	}
	for(int i=s.size()-2;i>=0;i--){
		if(s[i]<s[i+1]){
			char t=s[i+1];
				for(int j=i+1;j<s.size();j++)
					if(s[j]>s[i])t=min(t,s[j]);
			s[i]=t;
			s=s.substr(0,i+1);
			cout << s;
			return 0;
		}
	}
	puts("-1");
	return 0;
}

#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <assert.h>
#include <numeric>
#include <time.h>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < n; i++)
#define all(c) (c).begin(), (c).end()
#define P pair<int, int>
#define chmin(x, y) x = min(x, y)

int main()
{
  string s;
  cin >> s;
  reverse(all(s));
  s += '0';

  int n = s.size();

  const int INF = 100100100;
  vector<vector<int>> dp(n + 1, vector<int>(2, INF));
  dp[0][0] = 0;

  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < 2; j++)
    {
      int x = s[i] - '0';
      x += j;
      if (x < 10)
        chmin(dp[i + 1][0], dp[i][j] + x);
      if (x > 0)
        chmin(dp[i + 1][1], dp[i][j] + (10 - x));
    }
  }

  cout << dp[n][0] << endl;
}


#pragma GCC optimize ("O3")

#include <bits/stdc++.h>
#define DEBUG true
#ifdef ONLINE_JUDGE
#undef DEBUG
#define DEBUG false
#endif

using namespace std;

#define TRACE(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cerr << endl;}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << "[" << *it << " = " << a << "]";
	err(++it, args...);
}

#define MAXN ((ll)2e5+5)
#define MOD ((ll)998244353)
#define INF ((ll)1e9 + 9)
#define ll long long
#define _ << " " <<
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define LOG(x) if(DEBUG) cerr << x << endl;
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl "\n"
#define pii pair<int,int>
#define mid ((l+r)/2)

ll n, m, k;
ll A = 0;
ll ans;

void mulself(ll& a, ll b)
{
	a *= b;
	a %= MOD;
}

ll fast(ll a,ll b)
{
	ll res=1;
	while(b)
	{
		if(b&1LL)
		{
			res*=a;
			res%=MOD;
		}
		b>>=1LL;
		a*=a;
		a%=MOD;
	}
	return res;
}

ll inv(ll x)
{
	return fast(x, MOD-2);
}

ll C(ll a, ll b)
{
	ll ret = 1;
	for (int i = 0; i < b; ++i)
 		mulself(ret, a-i);

 	for (int i = 2; i <= b; ++i)
 		mulself(ret, inv(i));

 	return ret;
}

signed main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin >> n >> m >> k;

	A = m * fast(m-1, n-k-1);
	A %= MOD;

	mulself(A, C(n-1, k));

	ans = (ans + A) % MOD;

	ll B = A;

	for (int i = k-1; i >= 0; --i)
	{
		mulself(B, m-1);
		mulself(B, i+1);
		mulself(B, inv(n-(i+1)));

		ans = (ans + B) % MOD;
	}

	cout << ans << endl;
}

/* stuff you should look for
	* ll overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
*/

#include<bits/stdc++.h>
#define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long int
#define mod 998244353
using namespace std;
int fact[200005];
int power(int a, int b)
{
    if(b==0)
        return 1;
    int t = power(a,b/2);
    t*=t;
    t%=mod;
    if(b&1)
        t*=a;
    return t%mod;
}

int ncr(int n, int r)
{
    if(r==0)
        return 1;
    int ans=1;
    ans*=fact[n];
    ans%=mod;
    ans*=power(fact[r],mod-2);
    ans%=mod;
     ans*=power(fact[n-r],mod-2);
    ans%=mod;

    return ans;
}

void solve()
{
    fact[1]=1;
    fact[0]=1;
    for(int i=2;i<200005;i++)
        fact[i]=fact[i-1]*i%mod;
    int n,m,k;
    cin>>n>>m>>k;
    if(m==1)
    {
        if(k==n-1)
            cout<<1<<endl;
        else
            cout<<0<<endl;
        return;
    }
    int ans=0;
    for(int i=0;i<=k;i++)
    {
        int g = ncr(n-1,i);
        // cout<<g<<endl;
        int t = (g*m%mod)*power(m-1,n-1-i)%mod;
        ans+=t;
        ans%=mod;

    }

    cout<<ans<<endl;

}
signed main()

{
    FAST_IO;
    int t = 1;

    // cin>>t;

    while(t--)
    {
        solve();
    }

    return 0;
}


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

int main() {
  int N,L;cin>>N>>L;
  int left=L;
  int right=L+N-1;
  int all=0;
  for(int i=1;i<=N;i++) all+=L+i-1;
  if(left>=0) cout<<all-L<<endl;
  else if(right<=0) cout<<all-L-N+1<<endl;
  else cout<<all<<endl;
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll=long long;
using Graph=vector<vector<ll>>;
int main(){
  ll n,t;cin>>n>>t;
  vector<ll> ti(n);
  rep(i,n)cin>>ti[i];
  ll c=t;
  for(int i=n-1;i>0;--i){
    c+=min(t,ti[i]-ti[i-1]);
  }
  cout<<c;
}


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

const int maxn = 4e5 + 10;

int s[maxn], t[maxn];
int a[maxn], b[maxn];
int fail[maxn];

int n, m;
void getfail()
{
    memset(fail, 0, sizeof(fail));
    int len = n;
    int j = 0, k = fail[0] = -1;
    while (j < len)
    {
        while (k != -1 && t[j] != t[k])
            k = fail[k];
        fail[++j] = ++k;
    }
}

int kmp()
{
    int i = 0, j = 0;
    int ret = 0;
    while (i < n * 2)
    {
        while (j != -1 && s[i] != t[j])
            j = fail[j];
        i++, j++;
        if (j == m)
        {
            //printf("debug: i: %d j: %d\n", i, j);
            if (i < 2 * n)
                printf("%d %d\n", i - j, a[(i - j)] ^ b[0]);
            ret++, j = fail[j];
        }
    }
    return ret;
}

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

    for (int i = 0; i < n; i++)
        s[i] = a[i] ^ a[(i + 1) % n], t[i] = b[i] ^ b[(i + 1) % n];
    for (int i = n; i < 2 * n; i++)
        s[i] = s[i - n];
    /*     for (int i = 0; i < 2 * n; i++)
        cout << s[i] << " ";
    cout << endl;
    for (int i = 0; i < n; i++)
        cout << t[i] << " ";
    cout << endl; */
    getfail();
    kmp();
}

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

template <typename T>
struct Compress {
    vector<T> xs;

    Compress(const vector<T>& vs) : xs(vs) {
        sort(xs.begin(), xs.end());
        xs.erase(unique(xs.begin(), xs.end()), xs.end());
    }

    int compress(const T& x) {
        return lower_bound(xs.begin(), xs.end(), x) - xs.begin();
    }

    T decompress(int i) {
        return xs[i];
    }
};

vector<int> suffix_array(vector<int>& s) {
    int n = s.size();
    Compress<int> comp(s);
    vector<int> t(n);
    for (int i = 0; i < n; i++) t[i] = comp.compress(s[i]);
    vector<int> p(n), c(n), cnt(n);
    for (int i = 0; i < n; i++) cnt[t[i]]++;
    for (int i = 1; i < n; i++) cnt[i] += cnt[i-1];
    for (int i = 0; i < n; i++) p[--cnt[t[i]]] = i;
    int cl = 0;
    for (int i = 1; i < n; i++) {
        if (s[p[i]] != s[p[i-1]]) cl++;
        c[p[i]] = cl;
    }
    vector<int> pn(n), cn(n);
    for (int h = 0; (1 << h) < n; h++) {
        for (int i = 0; i < n; i++) {
            pn[i] = p[i] - (1 << h);
            if (pn[i] < 0) pn[i] += n;
        }
        fill(cnt.begin(), cnt.end(), 0);
        for (int i = 0; i < n; i++) cnt[c[pn[i]]]++;
        for (int i = 1; i < n; i++) cnt[i] += cnt[i-1];
        for (int i = n - 1; i >= 0; i--) {
            cnt[c[pn[i]]]--;
            p[cnt[c[pn[i]]]] = pn[i];
        }
        cn[p[0]] = 0;
        cl = 0;
        for (int i = 1; i < n; i++) {
            pair<int, int> cur(c[p[i]], c[(p[i] + (1 << h)) % n]);
            pair<int, int> prev(c[p[i-1]], c[(p[i-1] + (1 << h)) % n]);
            if (cur != prev) cl++;
            cn[p[i]] = cl;
        }
        swap(c, cn);
    }
    return p;
}

int bin_search(vector<int>& a, vector<int>& b, vector<int>& sa, bool lower) {
    int n = a.size();
    int lb = -1, ub = n;
    while (ub - lb > 1) {
        int m = (lb + ub) / 2;
        bool flag = false;
        for (int i = 0; i < n; i++) {
            int j = (sa[m] + i) % n;
            if (a[i] < b[j]) {
                ub = m;
                flag = true;
                break;
            }
            if (a[i] > b[j]) {
                lb = m;
                flag = true;
                break;
            }
        }
        if (!flag) {
            if (lower) ub = m;
            else lb = m;
        }
    }
    return ub;
}

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

    int N;
    cin >> N;
    vector<int> a(N), b(N);
    for (int i = 0; i < N; i++) cin >> a[i];
    for (int i = 0; i < N; i++) cin >> b[i];
    vector<int> c(N), d(N);
    for (int i = 0; i < N; i++) {
        c[i] = a[i] ^ a[(i+1) % N];
        d[i] = b[i] ^ b[(i+1) % N];
    }
    auto sa = suffix_array(d);
    int lb = bin_search(c, d, sa, true);
    int ub = bin_search(c, d, sa, false);
    vector<pair<int, int>> ans;
    for (int i = lb; i < ub; i++) {
        int k = (N - sa[i]) % N;
        int x = a[k] ^ b[0];
        ans.push_back({k, x});
    }
    sort(ans.begin(), ans.end());
    for (auto& p : ans) cout << p.first << " " << p.second << "\n";
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include<random>
#include <bitset>
using namespace std;
#define N (1000000000+7)
//#define N 998244353
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> Q;

const int inf = (int)1e9;

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

ll dp[110][10];
ll fib[1010];

int main(void){
	int H,W,K;
	cin>>H>>W>>K;
	dp[0][1]=1;
	fib[0]=1;
	fib[1]=1;
	for(int i=2;i<1010;i++){
		fib[i] = (fib[i-1]+fib[i-2])%N;
	}
	for(int i=1;i<=H;i++){
		for(int j=1;j<=W;j++){
			if(j==1){
				dp[i][j] = (dp[i-1][j]*fib[W-1])%N;
				if(W-j>=0){
					ll t = (dp[i-1][j+1]*fib[W-j-1])%N;
					dp[i][j] = (dp[i][j]+t)%N;
				}
			}
			else{
				if(j==W){
					dp[i][j] = (dp[i-1][j]*fib[j-1])%N;
					if(j-2>=0){
						ll t = (dp[i-1][j-1]*fib[j-2])%N;
						dp[i][j] = (dp[i][j]+t)%N;
					}
				}
				else{
					ll t1 = (fib[j-2]*fib[W-j])%N;
					ll t2 = (fib[j-1]*fib[W-j-1])%N;
					ll t3 = (fib[j-1]*fib[W-j])%N;
					t1 = (dp[i-1][j-1]*t1)%N;
					t2 = (dp[i-1][j+1]*t2)%N;
					t3 = (dp[i-1][j]*t3)%N;
					dp[i][j] = ((t1+t2)%N+t3)%N;
				}
			}
		}
	}
	/*for(int i=1;i<=H;i++){
		for(int j=1;j<=W;j++){
			cout<<dp[i][j]<<" ";
		}
		cout<<endl;
	}*/
	cout<<dp[H][K]<<endl;
	return 0;

}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define per(i,r,l) for(int i=(r);i>=(l);--i)
using namespace std;
const int N=1e6+10;
int n,q[N],ans;char s[N],t[N];
int main(){
    scanf("%d%s%s",&n,s+1,t+1);
    int flag=0;
    rep(i,1,n) if(s[i]^t[i]){flag=1;break;}
    if(!flag) return puts("0"),0;
    int i=n,j=n,l=1,r=0;
    while(i){
        while(i>1&&t[i]==t[i-1]) --i;
        //printf("%d %d\n",i,j);
        while(j&&(s[j]!=t[i]||j>i)) --j;
        if(!j) return puts("-1"),0;
        while(l<=r&&q[l]-(r-l+1)>=i) ++l;
        if(i!=j) q[++r]=j;
        ans=max(ans,r-l+2);--i;
    }
    printf("%d\n",ans);
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(),v.end()

const int maxn = 1e6 + 100, maxc = 256;
const ll inf = 2e18, mod = 1e9 + 7;

int n, pos[maxc], R[maxn], dest[maxn], par[maxn], fen[maxn * 2];
char s[maxn], t[maxn];
vector<int> vec[maxc];

void update(int x, int val)
{
	for (int ind = x + 1; ind < maxn * 2; ind += (ind & -ind))
		fen[ind] += val;
}

int query(int x)
{
	int res = 0;
	for (int ind = x + 1; ind; ind -= (ind & -ind))
		res += fen[ind];
	return res;
}

bool check(int H)
{
	memset(fen, 0, sizeof(fen));
	update(n, -H);
	update(0, H);

	int cut = 0;
	for (int i = n - 1; i >= 0; i--)
	{
		if (query(cut + i) == 0)
			return false;
		if (!i || t[i] != t[i - 1])
		{
			if (query(cut + i) < H)
				cut++;
			else
			{
				update(cut + i, -H);
				update(cut + i + 1, H);
			}
			update(par[i] + cut, -1);
			update(i + cut, 1);
		}
	}
	return true;
}

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

	for (int i = 0; i < maxc; i++)
		pos[i] = -mod;

	cin >> n >> s >> t;

	if (strcmp(s, t) == 0)
	{
		cout << 0 << endl;
		return 0;
	}

	int ind = 0;
	for (int i = 0; i < n; i++)
		if (t[i] != t[i - 1])
		{
			for (int j = ind; j < i; j++)
				R[j] = i - 1;
			ind = i;
		}
	for (int i = ind; i < n; i++)
		R[i] = n - 1;

	for (int i = 0; i < n; i++)
		vec[s[i]].pb(i);
	ind = n;
	for (int i = n - 1; i >= 0; i--)
	{
		while (ind - 1 > i)
		{
			ind--;
			//cerr << "ERASE " << t[ind] << endl;
			vec[s[ind]].popb();
		}
		if (!i || t[i] != t[i - 1])
		{
			if (vec[t[i]].empty())
			{
				//cerr << '#' << i << ' ' << t[i] << ' ' << ind << endl;
				cout << -1 << endl;
				return 0;
			}
			par[i] = vec[t[i]].back();
			for (int j = vec[t[i]].back(); j < ind; j++)
				vec[s[j]].popb();
			ind = par[i];
		}
	}
	for (int i = 0; i < n; i++)
		if (!i || t[i] != t[i - 1])
			for (int j = i; j <= R[i]; j++)
				par[j] = par[i];
	//for (int i = 0; i < n; i++)
	//	cerr << '_' << par[i];
	//cerr << endl;
	for (int i = 0; i < n; i++)
		if ((i && par[i] < par[i - 1]) || par[i] > i)
		{
			//cerr << "QUIT " << i << ' ' << par[i] << endl;
			cout << -1 << endl;
			return 0;
		}

	/*while (true)
	{
		int x;
		cin >> x;
		cerr << '#' << check(x) << endl;
	}*/
	int l = 0, r = n + 100, mid;
	while (r - l > 1)
	{
		mid = (l + r) / 2;
		if (check(mid))
			r = mid;
		else
			l = mid;
	}

	cout << r << endl;
}


#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#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 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>>;
const ll mod=1000000007;
const int MAX_N = 1000;         // n の最大値

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

int main() {
ll a,b,n;
cin>>a>>b>>n;
for(ll i=0; i<n; i++){
if(i%2==0){
a/=2;
b+=a;}
else{
b/=2;
a+=b;}}
cout << a << " " << b << endl;}

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
signed main(){
  ll n,m,d;cin>>n>>m>>d;if(d)d=2*(n-d);else d=n;
  printf("%.20f",(double)(m-1)*d/(double)(n*n));cout<<endl;
  return 0;
}


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

using namespace std;
using ll = long long;

double expected_value(int n) {
  return (double)((1 + n) * n / 2) / (double)n;
}

int main() {
  int n, k;
  cin >> n >> k;
  vector<double> ps(n + 1);
  vector<double> comsum(n + 1, 0);
  int p;
  rep(i, n) {
    cin >> p;
    ps[i + 1] = expected_value(p);
    comsum[i + 1] = comsum[i] + ps[i + 1];
  }
  double mm = 0;
  for (int i = k; i <= n; i++) {
    mm = max(comsum[i] - comsum[i - k], mm);
  }
  printf("%.6f\n", mm);
  return 0;
}

/**
 *    author        : Sudipta Banik Trisha
 *    created       : September 10, 2020 5:11 PM
 *    Problem Name  : D - Dice in Line
 *    Problem Limit : 2000 ms , 1024 MB
 *    Problem Url   : https://atcoder.jp/contests/abc154/tasks/abc154_d
 *    @genarated by : ai-virtual-assistant
**/

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

int main(){
    ios_base::sync_with_stdio(false);

    ll n,k;
    cin >> n >> k;

    vector<ll>v(n);
    for(ll i=0; i<n; i++){
        cin >> v[i];
        v[i] = 1 + v[i];
    }
    for(ll i=1; i<n; i++){
        v[i] = v[i-1] + v[i];
    }

    long double mxprob = (long double)v[k-1];
    for(int i=k; i<n; i++) {
        mxprob = max(mxprob , (long double)(v[i] - v[i-k]));
    }

    mxprob = mxprob / (long double)2.0;
    cout << fixed << setprecision(12) << mxprob << endl;

    return 0 ;
}


#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#define MAXN 1000010
using namespace std;

int n;
char s1[MAXN],s2[MAXN];
vector<int> S[30];
int p[MAXN];

struct Queue{
	deque<int> Q;
	int d;

	void push_back(int x){ Q.push_back(x-d); }
	void push_front(int x){ Q.push_front(x-d); }
	int back(){ return Q.back()+d; }
	void pop_back(){ Q.pop_back(); }
	void pop_front(){ Q.pop_front(); }
	bool empty(){ return Q.empty(); }
	int size(){ return Q.size(); }
}Q;

int main(){
#ifdef DEBUG
	freopen("F.in","r",stdin);
#endif
	scanf("%d",&n);
	scanf("%s%s",s1+1,s2+1);
	n=strlen(s1+1);
	for(int i=1;i<=n;i++) S[s1[i]-'a'].push_back(i);
	int ans=0;
	p[n+1]=n+1;
	for(int i=n;i>=1;i--){
		if(s2[i]==s2[i+1] && i>=p[i+1]){
			p[i]=p[i+1];
		}else{
			while(!S[s2[i]-'a'].empty() && S[s2[i]-'a'].back()>=p[i+1])
				S[s2[i]-'a'].pop_back();
			if(S[s2[i]-'a'].empty()){
				puts("-1");
				return 0;
			}
			p[i]=S[s2[i]-'a'].back();
			if(i>=p[i+1]){
				Q.d--;
				Q.push_front(p[i+1]-1);
				while(Q.back()>=i) Q.pop_back();
				Q.push_back(i);
			}else{
				while(!Q.empty()) Q.pop_back();
				if(p[i]<i) Q.push_back(i);
			}
			ans=max(ans,(int)Q.size());
		}
	}
	printf("%d\n",ans);
}

#include <cstdio>
#include <algorithm>

#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

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

int n, m;
Q g[100000];
int p[10000];
int r[10000];

void init(){
	rep(i, n){
		p[i] = i;
		r[i] = 0;
	}
}

int find(int i){
	return p[i] == i ? i : p[i] = find(p[i]);
}

bool same(int i, int j){
	return find(i) == find(j);
}

void unite(int i, int j){
	int a = find(i);
	int b = find(j);

	if(a == b){
		return;
	}

	if(r[a] > r[b]){
		p[b] = a;
	}
	else{
		p[a] = b;
		if(r[a] == r[b]){
			++r[b];
		}
	}
}

int main(){
	scanf("%d%d", &n, &m);
	rep(i, m){
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		g[i] = Q(c, P(a, b));
	}

	sort(g, g + m);

	init();

	int ans = 0;
	rep(i, m){
		int a = g[i].second.first;
		int b = g[i].second.second;
		int c = g[i].first;

		if(!same(a, b)){
			unite(a, b);
			ans += c;
		}
	}
	printf("%d\n", ans);
	return 0;
}


#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

template <typename T>
struct RollingHash
{
	int size;
	int n;
	ll factor = 1;
	ll b = 0;
	ll mod = 0;
	ll hash = 0;
	vector<T> list;
	int num = 0;
	int head = 0;

	void init(int _n, ll _b = (ll)1e8 + 7, ll _mod = (ll)1e9 + 7)
	{
		n = _n;
		b = _b;
		list.reserve(n);
		mod = _mod;
		auto temp = 1ll;
		for (auto i = 0; i < n; ++i)
		{
			factor = temp;
			temp = temp * b % mod;
		}
	}

	void add(ll val)
	{
		if ((int)list.size() >= n)
		{
			hash = (((hash - list[head] * factor) % mod) + mod) % mod;
			list[head] = val;
			head = (head + 1) % n;
		}
		else
		{
			list.push_back(val);
		}
		hash = hash * b % mod;
		hash = (hash + val) % mod;
	}

	ll getHash() { return hash; }
};

ll calcHash(vector<ll>& list, ll factor, ll mod)
{
	auto hash = 0ll;
	for (auto i = 0; i < (int)list.size(); ++i)
	{
		hash = hash * factor % mod;
		hash = (hash + list[i]) % mod;
	}

	return hash;
}

int main()
{
	int N;
	cin >> N;
	vector<ll> a(N);
	vector<ll> b(N);
	for (auto i = 0; i < N; ++i)
	{
		ll temp;
		cin >> temp;
		a[i] = temp;
		a.push_back(temp);
	}
	for (auto& temp : b)
	{
		cin >> temp;
	}

	vector<ll> x;
	for (auto i = 0; i < N; ++i)
	{
		x.push_back(b[0] ^ a[i]);
	}

	auto bitNum = 31;
	auto mod = (ll)1e9 + 7;
	vector<ll> rollingHashFactor = { (ll)1e8 + 7 };
	vector<vector<vector<RollingHash<ll>>>> hashA
		(bitNum, vector<vector<RollingHash<ll>>>(2, vector<RollingHash<ll>>((int)rollingHashFactor.size())));
	vector<vector<RollingHash<ll>>> hashB
		(bitNum, vector<RollingHash<ll>>((int)rollingHashFactor.size()));

	for (auto i = 0; i < bitNum; ++i)
	{
		for (auto k = 0; k < N; ++k)
		{
			auto val = (b[k] >> i) & 1;
			for (auto l = 0; l < (int)rollingHashFactor.size(); ++l)
			{
				if (k == 0)
				{
					hashB[i][l].init(N, rollingHashFactor[l], mod);
				}
				hashB[i][l].add(val);
			}
		}
	}

	vector<ll> factor;
	for (auto i = 0; i < (int)rollingHashFactor.size(); ++i)
	{
		auto temp = 1ll;
		for (auto j = 0; j < bitNum; ++j)
		{
			temp = temp * rollingHashFactor[i] % mod;
		}
		factor.push_back(temp);
	}

	vector<ll> correct;
	for (auto i = 0; i < (int)rollingHashFactor.size(); ++i)
	{
		vector<ll> list;
		for (auto j = 0; j < bitNum; ++j)
		{
			list.push_back(hashB[j][i].getHash());
		}
		correct.push_back(calcHash(list, factor[i], mod));
	}

	for (auto i = 0; i < bitNum; ++i)
	{
		for (auto j = 0; j < 2; ++j)
		{
			for (auto k = 0; k < N; ++k)
			{
				auto val = ((a[k] >> i) ^ j) & 1;
				for (auto l = 0; l < (int)rollingHashFactor.size(); ++l)
				{
					if (k == 0)
					{
						hashA[i][j][l].init(N, rollingHashFactor[l]);
					}
					hashA[i][j][l].add(val);
				}
			}
		}
	}

	vector<pair<int, ll>> ans;
	for (auto k = 0; k < N; ++k)
	{
		vector<vector<ll>> list((int)rollingHashFactor.size());
		for (auto i = 0; i < bitNum; ++i)
		{
			int j = (x[k] >> i) & 1;
			for (auto l = 0; l < (int)rollingHashFactor.size(); ++l)
			{
				list[l].push_back(hashA[i][j][l].getHash());
			}
		}

		auto match = true;
		for (auto i = 0; i < (int)rollingHashFactor.size(); ++i)
		{
			auto hash = calcHash(list[i], factor[i], mod);
			if (hash != correct[i])
			{
				match = false;
			}
		}

		if (match != false)
		{
			ans.push_back({ k, x[k] });
		}

		for (auto i = 0; i < bitNum; ++i)
		{
			for (auto j = 0; j < 2; ++j)
			{
				auto val = ((a[k + N] >> i) ^ j) & 1;
				for (auto l = 0; l < (int)rollingHashFactor.size(); ++l)
				{
					hashA[i][j][l].add(val);
				}
			}
		}
	}

	for (auto& pair : ans)
	{
		cout << pair.first << " " << pair.second << endl;
	}

	return 0;
}

#include<cstdio>
#include<vector>
#include<algorithm>
#include<map>

using namespace std;

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

int main(void)
{
	int h, w;
	int d_max=80*80;
	while(scanf("%d%d", &h, &w)==2)
	{
		vvi a(h), b(h), c(h);
		for(int y=0;y<h;y++)
		{
			a[y].resize(w);
			for(int x=0;x<w;x++) scanf("%d", &a[y][x]);
		}
		for(int y=0;y<h;y++)
		{
			b[y].resize(w);
			for(int x=0;x<w;x++) scanf("%d", &b[y][x]);
		}

		for(int y=0;y<h;y++)
		{
			c[y].resize(w);
			for(int x=0;x<w;x++) c[y][x]=abs(a[y][x]-b[y][x]);
		}

		vector<vector<vector<bool> > > dp(h);
		for(int y=0;y<h;y++)
		{
			dp[y].resize(w);
			for(int x=0;x<w;x++)
			{
				dp[y][x].assign(d_max+1, false);
			}
		}

		dp[0][0][c[0][0]]=true;
		for(int y=0;y<h;y++)
		{
			for(int x=0;x<w;x++)
			{
				for(int i=0;i<=d_max;i++)
				{
					if(dp[y][x][i]==false) continue;

					if(y+1<h)
					{
						int nbp=i+c[y+1][x];
						int nbn=abs(i-c[y+1][x]);
						dp[y+1][x][nbn]=true;
						if(nbp<=d_max) dp[y+1][x][nbp]=true;
					}
					if(x+1<w)
					{
						int nbp=i+c[y][x+1];
						int nbn=abs(i-c[y][x+1]);
						dp[y][x+1][nbn]=true;
						if(nbp<=d_max) dp[y][x+1][nbp]=true;
					}
				}
			}
		}
		int ans=0;
		for(ans=0;ans<=d_max && dp[h-1][w-1][ans]==false;ans++)
		{

		}
if(0)
{
		for(int y=0;y<h;y++)
		{
			for(int x=0;x<w;x++)
			{
				printf("%d ", c[y][x]);
			}
			printf("\n");
		}
		for(int y=0;y<h;y++)
		{
			for(int x=0;x<w;x++)
			{
				printf(" [");
				for(int i=0;i<=d_max;i++) if(dp[y][x][i]) printf(" %d", i);
				printf(" ]");
			}
			printf("\n");
		}
}
		printf("%d\n", ans);
	}
	return 0;
}


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

using namespace std;

int main(){
    long long N, M, V, P; cin >> N >> M >> V >> P;
    vector<long long> A(N);
    for(auto& t : A) cin >> t;
    sort(A.begin(), A.end());
    int L = -1, R = N-1;
    while(R-L > 1){
        int mid = (L+R)/2;
        long long thr = A[mid] + M;
        int gr = 0;
        long long add = M;
        for(int j=N-1;j>=0;j--){
            if(j == mid) continue;
            if(A[j] > thr){
                gr++;
                add += M;
            } else {
                if(gr+1 < P && A[j]+M > thr){
                    gr++;
                    add += M;
                } else {
                    add += min(M, thr-A[j]);
                }
            }
        }
        if(gr < P && add >= M*V) R = mid;
        else L = mid;
    }
    cout << N-R << endl;
}

//Author:xht37
#include <bits/stdc++.h>

#define ui unsigned int
#define ll long long
#define ul unsigned ll
#define ld long double

#define pi pair <int, int>
#define fi first
#define se second
#define mp make_pair

#define ls (p << 1)
#define rs (ls | 1)
#define md ((t[p].l + t[p].r) >> 1)

#define vi vector <int>
#define pb push_back
#define pq priority_queue

#define dbg(x) cerr << #x" = " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)

#define fl(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)

using namespace std;

namespace io {
	const int SI = 1 << 21 | 1;
	char IB[SI], *IS, *IT, OB[SI], *OS = OB, *OT = OS + SI - 1, c, ch[100];
	int f, t;
	#define gc() (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin), IS == IT ? EOF : *IS++) : *IS++)
	inline void flush() {
		fwrite(OB, 1, OS - OB, stdout), OS = OB;
	}
	inline void pc(char x) {
		*OS++ = x;
		if (OS == OT) flush();
	}

	template <class I>
	inline void rd(I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + (c & 15), c = gc());
		x *= f;
	}
	template <class I>
	inline void rd(I &x, I &y) {
		rd(x), rd(y);
	}
	template <class I>
	inline void rd(I &x, I &y, I &z) {
		rd(x), rd(y), rd(z);
	}
	template <class I>
	inline void rda(I *a, int n) {
		for (int i = 1; i <= n; i++) rd(a[i]);
	}
	inline void rdc(char &c) {
		for (c = gc(); c < 33 || c > 126; c = gc());
	}
	inline void rds(char *s, int &n) {
		for (c = gc(); c < 33 || c > 126; c = gc());
		for (n = 0; c >= 33 && c <= 126; s[++n] = c, c = gc());
		s[n+1] = '\0';
	}
	inline void rds(string &s) {
		for (c = gc(); c < 33 || c > 126; c = gc());
		for (s.clear(); c >= 33 && c <= 126; s.pb(c), c = gc());
	}

	template <class I>
	inline void print(I x, char k = '\n') {
		if (!x) pc('0');
		if (x < 0) pc('-'), x = -x;
		while (x) ch[++t] = x % 10 + '0', x /= 10;
		while (t) pc(ch[t--]);
		pc(k);
	}
	template <class I>
	inline void print(I x, I y) {
		print(x, ' '), print(y);
	}
	template <class I>
	inline void print(I x, I y, I z) {
		print(x, ' '), print(y, ' '), print(z);
	}
	template <class I>
	inline void printa(I *a, int n) {
		for (int i = 1; i <= n; i++) print(a[i], " \n"[i==n]);
	}
	inline void printc(char c) {
		pc(c);
	}
	inline void prints(char *s, int n) {
		for (int i = 1; i <= n; i++) pc(s[i]);
		pc('\n');
	}
	inline void prints(string s) {
		int n = s.length();
		while (t < n) pc(s[t++]);
		pc('\n'), t = 0;
	}
	struct Flush {
		~Flush() {
			flush();
		}
	} flusher;
}
using io::rd;
using io::rda;
using io::rdc;
using io::rds;
using io::print;
using io::printa;
using io::printc;
using io::prints;

namespace shai {
	const int n = 1e6 + 7;
	int p[n], v[n], phi[n], miu[n];

	inline void init(int n) {
		v[1] = phi[1] = miu[1] = 1;
		for (int i = 2; i <= n; i++) {
			if (!v[i]) p[++p[0]] = v[i] = i, phi[i] = i - 1, miu[i] = -1;
			for (int j = 1; j <= p[0] && i * p[j] <= n && p[j] <= v[i]; j++)
				v[i*p[j]] = p[j],
				phi[i*p[j]] = phi[i] * (p[j] - 1 + (p[j] == v[i])),
				miu[i*p[j]] = p[j] == v[i] ? 0 : -miu[i];
		}
	}
}
using shai::p;

const int N = 507;
int n, a[N], b[N];

int main() {
	shai::init(1e4);
	rd(n);
	for (int i = 1; i <= n; i++) a[i] = p[i&1?i/2+1:n*2-i/2+1];
	for (int i = 1; i <= n; i++) b[i] = p[(i&1?n-i/2:n+i/2)+(n&1)];
	a[0] = a[n+1] = b[0] = b[n+1] = 1;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			print((i ^ j) & 1 ? 1ll * a[(i+j)/2] * a[(i+j)/2+1] * b[(n+i-j+(n&1))/2] * b[(n+i-j+(n&1))/2+1] + 1 : 1ll * a[(i+j)/2] * b[(n+i-j+(n&1))/2], " \n"[j==n]);
	return 0;
}