#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = long long;
using PAIR = pair<int, int>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 1e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<"\n";
#define debug(x) cerr << #x << ":" << (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

signed main() {
  INIT;
	VAR(int, k);
	int n = 50, p = k / n, q = k % n;
	vector< int > a(n, n + p - q - 1);
	REP(i, q) {
		a[i] += 51;
	}

	OUT(n)BR;
	REP(i, n) {
		OUT(a[i]);
		if (i < n - 1) SP;
	}
	BR;

  return 0;
}

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

template<typename T_char>
T_char ToUpper(T_char cX){return toupper(cX);}

int main(){
  int n;
  cin >> n;
  while(1){
    if(n%111 == 0) break;
    n++;
  }
  cout << n;
}


#include <bits/stdc++.h>

using namespace std;

#define FOR(i,s,e) for(int (i)=(s);(i)<(int)(e);(i)++)
#define REP(i,e) FOR(i,0,e)
#define RFOR(i,e,s) for(int (i)=(e)-1;(i)>=(int)(s);(i)--)
#define RREP(i,e) RFOR(i,e,0)

#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

typedef long long ll;
typedef pair<int, int> PII;
typedef priority_queue<int> PQI;
typedef priority_queue<PII> PQII;

const double EPS = 1e-10;
const int INF = 1e9;
const int N = 100;
int n;
int r[N], c[N];
int dp[N+1][N];

int main() {
  scanf("%d ", &n);
  REP(i,n) scanf("%d%d ", r+i, c+i);

  REP(i,n+1) REP(j,n) dp[i][j] = INF;
  REP(j,n) dp[1][j] = 0;
  FOR(i,2,n+1) REP(j,n-i+1) FOR(k,1,i)
    dp[i][j] = min(dp[i][j], dp[k][j] + r[j]*c[j+k-1]*c[i+j-1] + dp[i-k][j+k]);

  printf("%d\n", dp[n][0]);

  return 0;
}

#include <stdio.h>

int main(){
 int n;
 scanf("%d",&n);
 while(n){
  int a=0,b=0,aa,bb;
  for(int i=n;i>0;i--){
   scanf("%d %d",&aa,&bb);
   if(aa>bb){
    a+=aa+bb;
   }else if(aa<bb){
    b+=aa+bb;
   }else{
    a+=aa;
    b+=bb;
   }
  }
  printf("%d %d\n",a,b);
  scanf("%d",&n);
 }
}


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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;

int POWINT(int x, int n) {
  int ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

ll POWLL(int x, int n) {
  ll ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

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

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

struct Q {
  int l, r, id;
};

bool lessL(const Q &q1, const Q &q2) {
  return q1.l < q2.l;
};

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

  int N;
  cin >> N;
  vector<Q> q(N);

  int max_l = 0;
  int min_r = 1e9+7;
  int max_len = 0;
  rep(i, 0, N) {
    cin >> q[i].l >> q[i].r;
    q[i].r++;
    q[i].id = i;

    if (q[i].l > max_l) {
      max_l = q[i].l;
    }

    if (q[i].r < min_r) {
      min_r = q[i].r;
    }

    max_len = max(q[i].r - q[i].l, max_len);
  }

  int ans = max_len + max(0, min_r - max_l);

  int ans_min_r = 2e9+7;
  int ans_max_l = 2e9+7;

  vector<PI> a(N);
  rep(i, 0, N) {
    a[i].first = max(q[i].r - max_l, 0);
    a[i].second = max(min_r - q[i].l, 0);
  }

  sort(All(a));

  int mn = a[0].second;
  rep(i, 1, N) {
    ans = max(ans, mn + a[i].first);
    mn = min(mn, a[i].second);
  }

  cout << ans << endl;

  return 0;
};

#include<iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
using P = pair<int,int>;
const ll INF = 1000100100100100100;

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

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

    ll dp[n][2];
    rep(i,n) rep(j,2) dp[i][j] = 0;
    dp[0][1] = -INF;

    rep(i,n){
        if(i == n-1){
            dp[i+1][0] = max(dp[i][0]+a[i], dp[i][1]-a[i]);
            dp[i+1][1] = -INF;
        }
        else{
            dp[i+1][0] = max(dp[i][0]+a[i], dp[i][1]-a[i]);
            dp[i+1][1] = max(dp[i][0]-a[i], dp[i][1]+a[i]);
        }
    }

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


#include <algorithm>
#include <cstdio>

static const size_t n_max = 200000;
static int S[n_max], L[n_max], R[n_max];
static long long c = 0;

void merge_sort(size_t i, size_t j) {
  switch (j - i) {
    case 0:
    case 1:
      break;
    case 2:
      if (S[i+1] < S[i]) {
        c++;
        std::swap(S[i], S[i+1]);
      }
      break;
    default:
      size_t k = (i + j) / 2;
      merge_sort(i, k);
      merge_sort(k, j);
      std::copy(S + i, S + k, L);
      std::copy(S + k, S + j, R);
      for (size_t l = i, p = 0, q = 0;; l++) {
        if (p < k - i && q < j - k) {
          if (L[p] <= R[q])
            S[l] = L[p++];
          else {
            c += k - i - p;
            S[l] = R[q++];
          }
        } else if (p < k - i)
          S[l]= L[p++];
        else if (q < j - k)
          S[l] = R[q++];
        else
          break;
      }
      break;
  }
}

int main() {
  size_t n;
  scanf("%zu", &n);
  for (size_t i = 0; i < n; i++)
    scanf("%d", S + i);
  merge_sort(0, n);
  printf("%lld\n", c);
  return 0;
}

/*************************************
 * @contest:      AGC041.
 * @user_name:    hkxadpall.
 * @time:         2019-12-28.
 * @language:     C++.
 * @upload_place: AtCoder.
*************************************/

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

typedef signed char          int8;
typedef unsigned char       uint8;
typedef short                int16;
typedef unsigned short      uint16;
typedef int                  int32;
typedef unsigned            uint32;
typedef long long            int64;
typedef unsigned long long  uint64;

template <typename Int>
inline Int read()
{
    Int flag = 1;
    char c = getchar();
    while ((!isdigit(c)) && c != '-') c = getchar();
    if (c == '-') flag = -1, c = getchar();
    Int init = c & 15;
    while (isdigit(c = getchar())) init = (init << 3) + (init << 1) + (c & 15);
	return init * flag;
}

template <typename Int>
inline Int read(char &c)
{
    Int flag = 1;
    c = getchar();
    while ((!isdigit(c)) && c != '-') c = getchar();
    if (c == '-') flag = -1, c = getchar();
    Int init = c & 15;
    while (isdigit(c = getchar())) init = (init << 3) + (init << 1) + (c & 15);
	return init * flag;
}

template <typename Int>
inline void write(Int x)
{
    if (x < 0) putchar('-'), x = ~x + 1;
    if (x > 9) write(x / 10);
    putchar((x % 10) | 48);
}

template <typename Int>
inline void write(Int x, char nextch)
{
    write(x);
    putchar(nextch);
}

int n;
char a[1007][1007];
// bool col[1007];
int now = 0;

void set3(int i, int j) // sum = 1
{
    a[i][j] = a[i][j + 1] = 'o';
    a[i + 1][j + 2] = a[i + 2][j + 2] = 'p';
}

void set4(int i, int j) // sum = 3
{
    a[i + 0][j + 0] = 'a'; a[i + 0][j + 1] = 'a'; a[i + 0][j + 2] = 'c'; a[i + 0][j + 3] = 'd';
    a[i + 1][j + 0] = 'b'; a[i + 1][j + 1] = 'b'; a[i + 1][j + 2] = 'c'; a[i + 1][j + 3] = 'd';
    a[i + 2][j + 0] = 'e'; a[i + 2][j + 1] = 'f'; a[i + 2][j + 2] = 'g'; a[i + 2][j + 3] = 'g';
    a[i + 3][j + 0] = 'e'; a[i + 3][j + 1] = 'f'; a[i + 3][j + 2] = 'h'; a[i + 3][j + 3] = 'h';
}

void set5(int i, int j)
{
    a[i + 0][j + 0] = 'a'; a[i + 0][j + 1] = 'a'; a[i + 0][j + 2] = 'b'; a[i + 0][j + 3] = 'b'; a[i + 0][j + 4] = 'c';
    a[i + 1][j + 0] = 'd'; a[i + 1][j + 1] = 'e'; a[i + 1][j + 2] = 'e'; a[i + 1][j + 3] = '.'; a[i + 1][j + 4] = 'c';
    a[i + 2][j + 0] = 'd'; a[i + 2][j + 1] = '.'; a[i + 2][j + 2] = '.'; a[i + 2][j + 3] = 'e'; a[i + 2][j + 4] = 'a';
    a[i + 3][j + 0] = 'a'; a[i + 3][j + 1] = '.'; a[i + 3][j + 2] = '.'; a[i + 3][j + 3] = 'e'; a[i + 3][j + 4] = 'a';
    a[i + 4][j + 0] = 'a'; a[i + 4][j + 1] = 'b'; a[i + 4][j + 2] = 'b'; a[i + 4][j + 3] = 'c'; a[i + 4][j + 4] = 'c';
}

void set7(int x, int y)
{
    static const char tpr[7 + 3][7 + 3] = {
        "aa..bba",
        "b.cc..a",
        "bc.dd..",
        ".cd.cc.",
        "..dc..b",
        "a..c..b",
        "abb..aa",
    };
    for (int i = 0; i < 7; i++) {
        strncpy(a[x + i] + y, tpr[i], 7);
    }
}

void outputMat()
{
    for (register int i = 0; i < n; i++) {
        for (register int j = 0; j < n; j++) {
            if (a[i][j]) putchar(a[i][j]);
            else putchar('.');
        }
        putchar('\n');
    }
}

int main()
{
    n = read<int>();
    if (n % 4 == 0) {
        for (register int i = 0; i < n; i += 4) set4(i, i);
        outputMat();
    } else if (n % 3 == 0) {
        for (register int i = 0; i < n; i += 3) set3(i, i);
        outputMat();
    } else if (n % 4 == 1 && n >= 5) {
        for (int i = 0; i < n - 5; i += 4) set4(i, i);
        set5(n - 5, n - 5);
        outputMat();
    } else if (n % 4 == 2 && n >= 10) {
        for (int i = 0; i < n - 10; i += 4) set4(i, i);
        set5(n - 10, n - 10);
        set5(n - 5, n - 5);
        outputMat();
    } else if (n % 4 == 3 && n >= 7) {
        for (int i = 0; i < n - 7; i += 4) set4(i, i);
        set7(n - 7, n - 7);
        outputMat();
    } else puts("-1");
    return 0;
}


#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

int main() {
  int N, K; cin >> N >> K;
  if (N % K == 0) cout << 0 << endl;
  else            cout << 1 << endl;
}

/*
 * Project: AtCoder Beginners Contest 105 A - AtCoder Crackers
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/06/16
 * Copyright (c) 2020 toms74209200
 *
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
using namespace std;

int n, k;

void solve() {

    int rem = n % k;
    if (rem == 0)
        printf("0\n");
    else
        printf("1\n");

}

int main() {

    scanf("%d", &n);
    scanf("%d", &k);

    solve();

}


#include<stdio.h>
#include<string.h>

int main(){
	int l[10],v1,v2,i;
	double sure;

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

		sure=(double)v1/(double)(v1+v2)*(double)(l[9]);

		for(i=0;i<10;i++){
			if(sure<=l[i]){
				printf("%d\n",i+1);
				break;
			}
		}
	}
	return 0;
}

#include<iostream>
using namespace std;

int main(void)
{
	int L[10];
	int V[2];
	char C[11];

	while(cin >> L[0] >> C[0])
	{
		for(int i=1; i<10; i++)
			cin >> L[i] >> C[i];
		cin >> V[0] >> C[10] >> V[1];

		int sum = 0;
		for(int i=0; i<10; i++)
			sum += L[i];

		double col_point = 0;
		col_point = ((double)sum)/((double)V[0]+V[1])*V[0];

		int ruikei = 0;
		for(int i=0; i<10; i++)
		{
			ruikei += L[i];
			if(col_point <= ruikei)
			{
				cout << (i+1) << endl;
				break;
			}
		}
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#define int long long
using namespace std;
signed main() {
    string S;
    int w;

    cin>>S>>w;

    for(int i=0;i<S.size();i+=w){
        cout<<S[i];
    }
}

#include <iostream>
#include <string>
#include <stack>
#include <math.h>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <vector>

using namespace std;

int main()
{
	string s,t;
	cin >> s;
	t = s;
	for (int i = 0; i < s.size(); i++) {
		t[i] = s[s.size() - i-1];
	}
	cout << t << endl;

}


#include<bits/stdc++.h>
#define ll long long int
#define endl '\n'
#define M 1000000007
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define f first
#define s second
#define b begin
#define e end
#define pb push_back
#define mp make_pair
#define FOR(i,a,b) for(i=a;i<b;i++)
#define RFOR(i,a,b) for(i=a;i>=b;i--)
#define all(x) x.begin(),x.end()
#define itfr(it,x) for(it=x.begin();it!=x.end();it++)
#define flash ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;

int main()
{
    flash;
    //sieve();
    ll T=1,n,m,k,x,y,z;
    // cin>>T;
    while(T--)
    {
        string a,b,c;
        cin>>a>>b>>c;
        n = a.length();
        m = b.length();
        k = c.length();
        x = 0; y = 0; z = 0;
        char cur = 'a';
        while(x<=n&&y<=m&&z<=k)
        {
            if(cur=='a')
            {
                cur = a[x];
                x++;
            }
            else if(cur=='b')
            {
                cur = b[y];
                y++;
            }
            else
            {
                cur = c[z];
                z++;
            }
        }
        if(x>n)
            cout<<'A';
        else if(y>m)
            cout<<'B';
        else
            cout<<'C';
        cout<<endl;
    }
}

#include <algorithm>
#include <climits>
#include <iostream>
#include <vector>
#define MAX_V 100
#define INF LONG_MAX / 4
using namespace std;

typedef struct {
  int to, cost;
} edge;

vector<edge> G[MAX_V];
long long d[MAX_V][MAX_V];

bool find_negative_cycle(int v) {
  for (int i = 0; i < v; i++) {
    if (d[i][i] < 0) return true;
  }
  return false;
}

void warshall_floyd(int v) {
  for (int k = 0; k < v; k++) {
    for (int i = 0; i < v; i++) {
      if (d[i][k] == INF) continue;
      for (int j = 0; j < v; j++) {
	if (d[k][j] == INF) continue;
	d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}

void init(int v) {
  for (int i = 0; i < v; i++) {
    for (int j = 0; j < v; j++) {
      if (i == j) d[i][j] = 0;
      else d[i][j] = INF;
    }
  }

  for (int i = 0; i < v; i++) {
    for (int j = 0; j < G[i].size(); j++) {
      d[i][G[i][j].to] = G[i][j].cost;
    }
  }
}

int main() {
  int v, e;
  cin >> v >> e;
  for (int i = 0; i < e; i++) {
    edge temp;
    int s, t, d;
    cin >> s >> t >> d;
    temp.to = t;
    temp.cost = d;
    G[s].push_back(temp);
  }

  init(v);
  warshall_floyd(v);

  if (find_negative_cycle(v) == true) {
    cout << "NEGATIVE CYCLE" << endl;
    return 0;
  }

  for (int i = 0; i < v; i++) {
    for (int j = 0; j < v; j++) {
      if (INF - 20000000 <= d[i][j] && d[i][j] <= INF) {
	cout << "INF";
      } else {
	cout << d[i][j];
      }
      if (j < v - 1) {
	cout << ' ';
      } else {
	cout << endl;
      }
    }
  }

  return 0;
}


#include<algorithm>
#include<cstdio>

using namespace std ;

int sports[ 1000 + 1 ] ;

int cnt[ 1000 + 1 ] ;
int CNT[ 1000 + 1 ] ;

int cmp ;

int N ,M ;

int ans()
{
	sort( cnt + 1 ,cnt + N + 1 ) ;

	return ( find_if( CNT ,CNT + N + 1 ,[]( int cmpair ){ return cmpair == cnt[ N ] ; } ) - CNT ) ;
}

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

	int i ;
	for( i = 1 ; i <= N ; ++i )
	{
		scanf( "%d" ,&cmp ) ;

		sports[ i ] = cmp ;
	}

	for( i = 0 ; i < M ; ++i )
	{
		scanf( "%d" ,&cmp ) ;

		++cnt[ ( find_if( sports + 1 ,sports + N + 1 ,[]( int cmpair){ return cmp >= cmpair ; } ) - sports ) ] ;
	}

	copy( cnt ,cnt + N + 1 ,CNT ) ;

	printf( "%d\n" ,ans() ) ;

	return 0 ;
}

#include<iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cmath>
#include <set>
#include <string.h>
#include <functional>

using namespace std;

int a[1010];
int b[1010];
int c[1010];
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<m;i++){
        cin>>b[i];
    }
    for(int i=0;i<m;i++){
        for(int j=0;j<n;j++){
            if(b[i]>=a[j]){
                c[j]++;
                break;
            }
        }
    }
    int max=0;int ans=-1;;
    for(int i=0;i<n;i++){
        if(c[i]>max){
            max=c[i];
            ans=i+1;
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <time.h>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) (min(a,b) <= (x) && (x) <= max(a,b)) //hei
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007LL
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589

#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
	std::fill((T*)array, (T*)(array + N), val);
}
pll Dir[4] = {
	{ -1 ,0 },{ 0 , 1 },{ 1 ,0 },{ 0 ,-1 }
};

//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define INF 10000000000000000LL
#define chmax(a,b) a = max(a,b)
#define chmin(a,b) a = min(a,b)

struct Edge {
	int from, to;
	ll w;
	bool operator<(const Edge& rhs) const {
		return MP(w, MP(from, to)) < MP(rhs.w, MP(rhs.from, rhs.to));
	}
};

typedef vector<set<Edge>> Graph;

struct Segtree {

};

signed main(void) {

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

	vector<ll> a(n), b(m), upc(n * m + 1);
	multiset<ll> aa, ba;
	REP(i, n) {
		cin >> a[i];
		aa.insert(a[i]);
	}

	REP(i, m) {
		cin >> b[i];
		ba.insert(b[i]);
	}

	REP(i, n) {
		REP(j, m) {
			upc[min(a[i], b[j])]++;
		}
	}

	for (int i = n * m; 1 <= i; i--)
		upc[i - 1] += upc[i];

	ll used = 0;
	ll ans = 1;
	for (int i = n * m; 1 <= i; i--) {
		if (aa.count(i) > 1 || ba.count(i) > 1) {
			cout << 0 << endl;
			return 0;
		}
		if (aa.count(i)) {
			if (!ba.count(i)) {
				int cc = 0;
				REP(j, m) {
					cc += b[j] > i;
				}

				ans *= cc;
			}
		}

		else if (ba.count(i)) {
			if (!aa.count(i)) {
				int cc = 0;
				REP(j, n) {
					cc += a[j] > i;
				}

				ans *= cc;
			}
		}
		else {

			ans *= upc[i] - used;

		}
		ans %= MODU;
		used++;
	}

	cout << ans << endl;

	return 0;
}

#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

int N, M;
int A[1010], B[1010];
int C[1010101];

int belongs_a(int n)
{
    auto lb = lower_bound(A, A + N, n);
    int i = lb - begin(A);
    if (A[i] == n)
    {
        return i;
    }
    else
    {
        return -1;
    }
}

int greater_num_a(int n)
{
    auto lb = upper_bound(A, A + N, n);
    int i = lb - begin(A);
    return N - i;
}

int belongs_b(int m)
{
    auto lb = lower_bound(B, B + M, m);
    int i = lb - begin(B);
    if (B[i] == m)
    {
        return i;
    }
    else
    {
        return -1;
    }
}

int greater_num_b(int m)
{
    auto lb = upper_bound(B, B + M, m);
    int i = lb - begin(B);
    return M - i;
}

int main()
{
    cin >> N >> M;
    rep(i, 0, N)
    {
        cin >> A[i];
    }
    rep(i, 0, M)
    {
        cin >> B[i];
    }
    sort(A, A + N);
    sort(B, B + M);
    rep(i, 1, N)
    {
        if (A[i - 1] == A[i])
        {
            cout << 0 << endl;
            return 0;
        }
    }
    rep(i, 1, M)
    {
        if (B[i - 1] == B[i])
        {
            cout << 0 << endl;
            return 0;
        }
    }

    ll ans = 1;
    for (int i = N * M; i >= 1; i--)
    {
        int ba = belongs_a(i);
        int bb = belongs_b(i);
        if (ba >= 0 && bb >= 0)
        {
            continue;
        }
        else if (ba >= 0)
        {
            ans *= greater_num_b(i);
            ans %= MOD;
        }
        else if (bb >= 0)
        {
            ans *= greater_num_a(i);
            ans %= MOD;
        }
        else
        {
            ll p = greater_num_a(i) * greater_num_b(i) % MOD;
            p = (p - (M * N - i) + MOD) % MOD;
            ans *= p;
            ans %= MOD;
        }
    }
    cout << ans << endl;
}


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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.141592653589793238462643383279;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

ll dp[1<<16], score[1<<16];
ll a[16][16];

ll rec(int S){
    if(dp[S] != -1) return dp[S];
    if(S == 0) return dp[S] = 0;

    ll ret = score[S];
    for(int T=S; T>0; T=T-1&S){
        if(S==T) continue;
        chmax(ret, rec(T) + rec(S^T));
    }

    return dp[S] = ret;
}

int main(void){
    int N; cin >> N; REP(i,1<<N) dp[i] = -1;
    REP(i,N)REP(j,N) cin >> a[i][j];

    REP(S,1<<N){
        REP(i,N)FOR(j,i+1,N) if(S>>i & S>>j & 1) score[S] += a[i][j];
    }

    ll ans = rec((1<<N)-1);
    cout << ans << en;
    return 0;
}

#include<bits/stdc++.h>

#ifdef _PRINTDEBUG
  #include "lib/printdebug.hpp"
#else
  #define printdebug(...) 1
#endif
#define MOD_1_000_000_007 (1000000007)
#define IINF (1<<28)
#define LINF (1LL<<60)
#define rep(i, n)      REP(i, 0, (n))
#define repc(i, n)     REPC(i, 0, (n))
#define REP(i, n, m)   for (int i = (int)(n); i <  (int)(m); i++)
#define REPC(i, n, m)  for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
#define yesno(cond)       YESNO((cond), "Yes", "No")
#define YESNO(cond, a, b) cout << ((cond) ? (a) : (b)) << "\n"

namespace solver {
  using namespace std;
  typedef long long ll;

  int N, as[16][16];
  ll sum[1<<16], dp[1<<16];

  void init() {
    cin >> N;
    rep(i, N) rep(j, N) {
      cin >> as[i][j];
    }
  }

  void build_sum() {
    rep(i, 1<<N) {
      sum[i] = 0;
      if(__builtin_popcount(i) <= 1) continue;
      int j = i & -i;
      int k = i & ~j;
      sum[i] = sum[k];
      rep(l, N) if((k >> l) & 1) {
        sum[i] += as[l][__builtin_ffs(j)-1];
      }
    }
  }

  void solve() {
    build_sum();
    rep(i, 1<<N) {
      dp[i] = sum[i];
      if(__builtin_popcount(i) <= 2) continue;
      int j = i;
      do {
        int k = i & ~j;
        if(j != 0 || k != 0) {
          dp[i] = max(dp[i], dp[j] + dp[k]);
          j = (j - 1) & i;
        }
      } while(j != i);
    }
    cout << max(0LL, dp[(1<<N)-1]) << "\n";
  }
}

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


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

int	main()
{
	int	N, M, Q;
	cin >> N >> M >> Q;
	vector<vector<int>>	cnt_vec(N + 1, vector<int>(N + 1, 0));
	int	L, R;
	for (int i = 0; i < M; ++i) {
		cin >> L >> R;
		cnt_vec.at(L).at(R) += 1;
	}
	vector<vector<int>>	cumsum(N + 1, vector<int>(N + 1, 0));
	for (int i = N; i > 0; --i) {
		for (int j = 1; j <= N; ++j) {
			cumsum.at(i).at(j) = cnt_vec.at(i).at(j);
			cumsum.at(i).at(j) += cumsum.at(i).at(j - 1);
			if (i < N) {
				cumsum.at(i).at(j) += cumsum.at(i + 1).at(j);
				cumsum.at(i).at(j) -= cumsum.at(i + 1).at(j - 1);
			}
		}
	}
	int	p, q;
	for (int i = 0; i < Q; ++i) {
		cin >> p >> q;
		cout << cumsum.at(p).at(q)  << endl;
	}
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
const int M = 1e6+6;
ll seg[4*M],lazy[4*M],ct[4*M];
ll ans[100];
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;
	cin>>n;
	string s;
	cin>>s;
	s = "$"+s;
	int q;
	cin>>q;
	while(q--)
	{
		int k;
		cin>>k;
		ll ans = 0;
		ll m = 0;
		ll d = 0;
		ll cur = 0;
		for(int i=1;i<=n;i++)
		{
			if(i>k)
			{
				// delete i-k
				if(s[i-k] == 'D')
				{
					cur -= m;
					d--;
				}
				if(s[i-k] == 'M')
				{
					m--;
				}
			}
			if(s[i] == 'D')
				d++;
			if(s[i] == 'M')
			{
				m++;
				cur += d;
			}
			if(s[i] == 'C')
				ans += cur;
		}
		cout<<ans<<"\n";
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<long long> > vvll;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
#define INF 1000000000
#define MOD 1000000007
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define p_q priority_queue

#define FOR(i, a, b) for (ll i=(a); i<=(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)

#define MN 500005
#define MX 1048600
int n;
ll a[MN];
ll ps[MN];

ll lst[MX]; //last time we saw 0
ll cnt[MX];
pll dp[MX]; //cnt for k, cnt for 0

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

    cin >> n;
    FOR(i, 1, n){
        cin >> a[i];
        ps[i] = ps[i-1] ^ a[i];
    }
    ll ov = ps[n];
    //cout << ov << "\n";

    if(ov != 0){
        ll isn = 0;
        ll isz = 1;

        FOR(i, 1, n-1){
            if(ps[i] == 0){
                isz = (isn+isz)%MOD;
            } else if(ps[i] == ov){
                isn = (isn+isz)%MOD;
            }
        }

        cout << isz << "\n";
    } else{
        int tm = 0;

        dp[0].f = 1;
        FOR(i, 1, MX-1){
            dp[i].s = 1;
        }

        FOR(i, 1, n-1){
            //cout << ps[i] << " ";
            if(ps[i] == 0){
                tm++;
                dp[0].f = (dp[0].f*2)%MOD;
            } else{
                int j = ps[i];
                int dif = tm-lst[j];
                dp[j].s = (dp[j].s + dp[j].f*dif) % MOD;
                dp[j].f = (dp[j].f + dp[j].s) % MOD;
                lst[j] = tm;
            }
        }
        //cout << "\n";
        ll sm = 0;
        F0R(i, MX){
            /*if(dp[i].f != 0){
                cout << i << " adds " << dp[i].f << "\n";
            }*/
            sm += dp[i].f;
            sm %= MOD;
        }

        //cout << "\n";
        cout << sm << "\n";
    }

    return 0;
}

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

#define pb push_back
#define ff first
#define ss second

const int MAXN = 2e5 + 21, LG = 61;

int n, m;
long long k;
long long a[MAXN], d[MAXN], p[MAXN][LG];
vector <long long> res;

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

    for (int i = 1; i <= n; i++)
        cin >> a[i];
    res.pb(a[1]);

    cin >> m >> k;

    for (int i = 1; i < n; i++) {
        d[i] = a[i + 1] - a[i];
        p[i][0] = i;
    }

    for (int i = 1; i <= m; i++) {
        int x;
        cin >> x;
        swap(p[x - 1][0], p[x][0]);
    }

    for (int i = 1; i < LG; i++)
        for (int j = 1; j < n; j++) {
            p[j][i] = p[p[j][i - 1]][i - 1];
        }

    for (int i = 1; i < n; i++) {
        int cur = i;

        for (int i = LG - 1; ~i; i--)
            if (k & (1LL << i))
                cur = p[cur][i];
        res.pb(res.back() + d[cur]);
    }

    for (auto y: res)
        cout << y << '\n';
    return 0;
}


#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
double pi = 3.1415926535897932384646433;
typedef long long ll;
typedef pair<ll, ll>pii;
ll ccw(pii a, pii b, pii c)
{
  return (b.first - a.first)*(c.second - b.second) - (b.second - a.second)*(c.first - b.first);
}
double dist(pii a, pii b)
{
  return sqrt(double((b.first - a.first)*(b.first - a.first) + (b.second - a.second)*(b.second - a.second)));
}
double dot(pii a, pii b)
{
  return double(a.first*b.first + a.second*b.second);
}
double ans[111];
int main()
{
  fill(ans, ans + 111, 0);
  int num;
  scanf("%d", &num);
  vector<pii>v;
  map<pii, int>ma;
  for (int i = 0; i < num; i++)
  {
    ll a, b;
    scanf("%lld%lld", &a, &b);
    v.push_back(make_pair(a, b));
    ma[make_pair(a, b)] = i;
  }
  sort(v.begin(), v.end());
  vector<pii>v1, v2;
  for (int i = 0; i < num; i++)
  {
    for (;;)
    {
      if (v1.size() <= 1)break;
      pii a = v1[v1.size() - 2], b = v1[v1.size() - 1];
      if (ccw(a, b, v[i])<0)v1.pop_back();
      else break;
    }
    v1.push_back(v[i]);
  }
  for (int i = 0; i < num; i++)
  {
    for (;;)
    {
      if (v2.size() <= 1)break;
      pii a = v2[v2.size() - 2], b = v2[v2.size() - 1];
      if (ccw(a, b, v[i])>0)v2.pop_back();
      else break;
    }
    v2.push_back(v[i]);
  }
  for (int i = int(v2.size()) - 2; i >= 1; i--)v1.push_back(v2[i]);
  for (int i = 0; i < v1.size(); i++)
  {
    pii s = v1[(i + v1.size() - 1) % v1.size()];
    pii t = v1[i];
    pii u = v1[(i + 1) % v1.size()];
    //printf("%lld %lld  %lld %lld  %lld %lld\n", s.first, s.second, t.first, t.second, u.first, u.second);
    double x = acos(dot(make_pair(u.first - t.first, u.second - t.second), make_pair(s.first - t.first, s.second - t.second)) / dist(s, t) / dist(t, u));
    ans[ma[v1[i]]] = (pi - x) / (2 * pi);
  }
  for (int i = 0; i < num; i++)printf("%.6lf\n", ans[i]);
}

#include <bits/stdc++.h>
using namespace std;
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) _overload(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
double res, PI = acos(-1);
int n;
main(){
	cin >> n;
    int x[n], y[n];
	rep(i, n) cin>>x[i]>>y[i];
	rep(i, n){
        vector<double> d;
        rep(j, n) if(i != j) d.push_back(atan2(y[j] - y[i], x[j] - x[i]));
		sort(begin(d),end(d));
		res = d[0] - d[d.size() - 1] + PI;
		rep(j, 1, d.size()) res=max(res,d[j] - d[j - 1] - PI);
        cout<<max(0.0, res / 2.0 / PI)<<'\n';
	}
}


#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string& s) {
  return '"' + s + '"';
}
string to_string(const char* s) {
  return to_string((string) s);
}
string to_string(bool b) {
  return (b ? "true" : "false");
}
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
const long long mod = 1e9+7; // CHECK
long long power(long long a, long long b, long long m = mod) {
    if(b < 0) {
        return power(power(a, -b), mod-2);
    }
    long long x = 1;
    while(b) {
        if(b & 1) {
            x = 1ll * x * a % m;
        }
        a = 1ll * a * a % m;
        b /= 2;
    }
    return x;
}
#define ll long long
const int INT_INF = 1e9+9;
const ll LL_INF = 2e18;
const int N = 3e5+9;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n; cin >> n;
    int latest_start = 0, earliest_finish = 0;
    vector<pair<int, int>> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i].first >> a[i].second;
        if (a[latest_start].first < a[i].first) {
            latest_start = i;
        }
        if (a[earliest_finish].second > a[i].second) {
            earliest_finish = i;
        }
    }
    int ans = 0;
    // both in same
    {
        int longest = -INT_INF;
        for (int i = 0; i < n; i++) {
            if (i == earliest_finish || i == latest_start) continue;
            longest = max(longest, a[i].second - a[i].first + 1);
        }
        ans = max(ans, longest + max(a[earliest_finish].second - a[latest_start].first + 1, 0));
    }
    // earliest_finish in left
    {
        vector<pair<int, int>> b;
        for (int i = 0; i < n; i++) {
            if (i == earliest_finish || i == latest_start) continue;
            b.push_back({max(0, a[earliest_finish].second - a[i].first + 1),
                -max(0, a[i].second - a[latest_start].first + 1)});
        }
        sort(b.begin(), b.end());
        int mn_right = a[latest_start].second - a[latest_start].first + 1;
        for (int i = 0; i < n-2; i++) {
            ans = max(ans, b[i].first + mn_right);
            mn_right = min(mn_right, -b[i].second);
        }
        ans = max(ans, mn_right + a[earliest_finish].second - a[earliest_finish].first + 1);
    }
    cout << ans << '\n';

    return 0;
}

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

//***********************************************************************

// hash struct for unordered_map
struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};

int MAXNUM = 5e3+5;
vector <int>vis(MAXNUM);
vector<int> pr;
void sieve() {
	pr.push_back(2);
	for(ll i=3;i<MAXNUM;i+=2) if(!vis[i]) {
		pr.push_back(i);
		for(ll j=i*i;j<MAXNUM;j+=2*i) vis[j]=true;
	}
}
//************************************************************************

ll cnt[1<<16];
ll dp[1<<16];
// ll finddpvalue(ll mask,ll pos)
// {
//     if(pos==-1)
//     {
//         return cnt[mask];
//     }
//     if(dp[mask][pos]!=-1)
//     {
//         return dp[mask][pos];
//     }
//     ll ans=0;
//     ans+=finddpvalue(mask,pos-1);
//     if(mask&(1<<pos))
//     ans+=finddpvalue(mask^(1<<pos),pos-1);
//     return dp[mask][pos]=ans;

// }

ll finddpvalue2(int mask)
{
    if(mask==0)
    return 0;
    if(dp[mask]!=-1)
    return dp[mask];
    ll ans=cnt[mask];
    for(int i = (mask-1)&mask; i > 0; i = (i-1) & mask)
    {
        int group=mask^i;
        //cout << "mask : " << mask << " i : " << i << " grp :" << group << endl;
        ans=max(ans,cnt[group]+finddpvalue2(i));
    }
    return dp[mask]=ans;
}

void solve()
{
    ll n;
    cin >> n;
    vector<vector<ll>> v(n,vector<ll>(n));
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            cin >> v[i][j];
        }
    }
    memset(cnt,0,sizeof cnt);
    for(ll mask=0;mask<(1<<n);mask++)
    {
        for(ll i=0;i<n;i++)
        {
            if(mask&(1<<i))
            {
                for(ll j=i+1;j<n;j++)
                {
                    if(mask&(1<<j))
                    cnt[mask]+=v[i][j];
                }
            }
        }
    }
    memset(dp,-1,sizeof dp);
    //cout << "c0"  << endl;
    ll ans=finddpvalue2((1<<n)-1);
    //cout << "c0"  << endl;
    cout << ans << endl;
}

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

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define ll long long

int cntD(ll i){
	int cnt = 0;
	if( i == 0) return 1;
	while(i>0){
		i /= 10;
		++cnt;
	}
	return cnt;
}

ll f (ll i, ll j){
	return max(cntD(i), cntD(j));
}

int main(){
	ll n;
	cin >> n;
	ll d = cntD(n);
	for(ll a = 1; a*a<=n; ++a){
		if(n%a != 0) continue;
		ll b = n/a;
		d = min(d, f(a,b));
	}
	cout << d;
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

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

bool IsPrime(ll num)
{
  if (num < 2)
    return false;
  else if (num == 2)
    return true;
  else if (num % 2 == 0)
    return false;
  ld sqrtNum = sqrt(num);
  for (ll i = 3; i <= sqrtNum; i += 2)
  {
    if (num % i == 0)
      return false;
  }
  return true;
}

//実行部
void Main()
{
  str s; ll w; cin >> s >> w;
  rep(i, s.size())
  {
    if(i % w == 0) cout << s[i];
  }
  cout << endl;
}
//前処理
int main()
{
  ifstream in("text.txt");
  cin.rdbuf(in.rdbuf());
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}

/*
//test時
  g++ test.cpp -o test;./test
*/


#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mk make_pair
#define MAX 1000001
ll prime[MAX];
#define FAST           ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define gcd __gcd
// ll rec(vector<vector<ll> >& dp,vector<ll>& arr,int n,int i,int k,int w)
// {
//   ll ans=0;
//   if(i>=n)
//     return 0;

//   if(dp[i][k]!=-1)
//     return dp[i][k];

//   if(k!=0)
//   ans=max(rec(dp,arr,n,i+1,w,w),arr[i]+rec(dp,arr,n,i+1,k-1,w));
//   else
//   ans=max(rec(dp,arr,n,i+1,k,w),rec(dp,arr,n,i+1,w,w));

//   return dp[i][k]=ans;

// }

//ll t[400008];
// void build(vector<ll>& a, int v, int tl, int tr) {
//     if (tl == tr) {
//         t[v] = a[tl];
//     } else {
//         int tm = (tl + tr) / 2;
//         build(a, v*2, tl, tm);
//         build(a, v*2+1, tm+1, tr);
//         t[v] = max(t[v*2] ,t[v*2+1]);
//     }
// }

// ll maxi(int v, int tl, int tr, int l, int r) {
//     if (l > r)
//         return 0;
//     if (l == tl && r == tr) {
//         return t[v];
//     }
//     int tm = (tl + tr) / 2;
//     return max(maxi(v*2, tl, tm, l, min(r, tm)) ,maxi(v*2+1, tm+1, tr, max(l, tm+1), r));
// }

// void update(int v, int tl, int tr, int pos, ll new_val) {
//     if (tl == tr) {
//         t[v] = new_val;
//     } else {
//         int tm = (tl + tr) / 2;
//         if (pos <= tm)
//             update(v*2, tl, tm, pos, new_val);
//         else
//             update(v*2+1, tm+1, tr, pos, new_val);
//         t[v] = max(t[v*2] ,t[v*2+1]);
//     }
// }

struct hash_pair {
   template <class T1, class T2>
   size_t operator()(const pair<T1, T2>& p) const{
      auto hash1 = hash<T1>{}(p.first);
      auto hash2 = hash<T2>{}(p.second);
      return hash1 ^ hash2;
   }
};

int temp[1000002]={0};

void sieve()
{
  temp[1]=1;
  for(int i=2;i<1000002;i++)
  {
    if(temp[i]==0)
    { temp[i]=i;
      for(int j=i*2;j<1000002;j+=i)
      {
        if(temp[j]==0)
        temp[j]=i;
      }
    }
  }

}

int dfs(int i,vector<vector<int> > &g,vector<int>& p,vector<int>& c)
{
  int sub=1;
  for(auto x:g[i])
  {
    if(p[i]!=x)
    {
      p[x]=i;
      sub+=dfs(x,g,p,c);
    }
  }

  return c[i]=sub;
}

int main() {

int n;
cin>>n;
int a[n],fa[n+1]={0};
int b[n],fb[n+1]={0};

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

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

for(int i=1;i<=n;i++)
{
  if(fa[i]+fb[i]>n)
  {
    flag=1;
    break;
  }
}
if(flag)
{
  cout<<"No"<<"\n";
  return 0;
}

 cout<<"Yes"<<"\n";

reverse(b,b+n);

int i=0;
int j=0;

while(i<n)
{
  if(a[i]!=b[i])
    { i++;
      continue;}

  swap(b[i],b[j]);
  j++;

}

i=n-1;
j=n-1;

while(i>=0)
{
  if(a[i]!=b[i])
    { i--;
      continue;}

  swap(b[i],b[j]);
  j--;

}

 for(int i=0;i<n;i++)
  cout<<b[i]<<" ";
cout<<"\n";

return 0;
}
/*
1
4
1 2
2 3
3 4
*/

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

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

	int a[n],b[n];

	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=0;i<n;i++)
	{
		cin>>b[n-i-1];
	}

	int val=-1;

	for(int i=0;i<n;i++)
	{
		if(a[i]==b[i])
		{
			val=a[i];
			break;
		}
	}

	if(val==-1)
	{
		cout<<"Yes"<<endl;

		for(int i=0;i<n;i++)
		{
			cout<<b[i]<<' ';
		}
		cout<<endl;
	}
	else
	{
		vector<int> t_change,available;

		for(int i=0;i<n;i++)
		{
			if(a[i]!=val && b[i]!=val)
			{
				available.push_back(i);
			}
			if(a[i]==val && b[i]==val)
			{
				t_change.push_back(i);
			}
		}

		if(t_change.size()>available.size())
		{
			cout<<"No"<<endl;
		}
		else
		{

			for(auto i:t_change)
			{
				int ind=*(available.end()-1);

				swap(b[i],b[ind]);
				available.pop_back();
			}

			cout<<"Yes"<<endl;

			for(int i=0;i<n;i++)
			{
				cout<<b[i]<<' ';
			}
			cout<<endl;
		}
	}
	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

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

    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) { cin >> A[i]; }

    ll sum = 0;
    vector<bool> B(N, false);
    if (A[0] != 0) {
        cout << -1 << endl;
        return 0;
    }

    rep(i, N - 1) {
        if (A[i + 1] > A[i] + 1) {
            cout << -1 << endl;
            return 0;
        }
        if (A[i + 1] - A[i] == 1)
            B[i + 1] = true, sum++;
    }

    rep(i, N) {
        if (!B[i])
            sum += A[i];
    }

    cout << sum << endl;
}

#include <bits/stdc++.h>

using namespace std;

int A[100050];
int n,l,q;
int dp[100050][20];
int main(){
	//freopen("input.in","r",stdin);
	cin >> n;
	for(int i=1; i<=n; ++i) cin >> A[i];
	cin >> l;
	for(int i=1; i<=n; ++i) dp[i][0] = upper_bound(A+1,A+n+1,A[i]+l)-A-1;
	for(int k=1; k<=18; ++k){
		for(int i=1; i<=n; ++i){
			dp[i][k] = dp[dp[i][k-1]][k-1];
		}
	}
//	for(int k=0; k<=3; ++k){ for(int i=1; i<=n; ++i) printf("%d ", dp[i][k]); printf("\n"); }
	cin >> q;
	while(q--){
		int a, b; cin >> a >> b;
		if(a > b) swap(a,b);
		int ans = 0;
		while(a < b){
			int s=0,e=19,m;
			for(int k=0; k<=18; ++k) if(dp[a][k] < b) s=k;
			ans += (1<<s);
			a = dp[a][s];
		}
		cout << ans << "\n";
	}
}


#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=998244353;
const LL LINF=1LL<<60;
const int INF=1<<30;

vector<LL> fact;
vector<LL> inver(3000001);

LL combi(int n,int r){
    if(n<r||n<0||r<0) return 0;
    return fact[n]%mod*inver[n-r]%mod*inver[r]%mod;
}

LL fpow(LL a, LL n){
    LL x = 1;
    while(n > 0){
        if(n&1){
            x=x*a%mod;
        }
        a=a*a%mod;
        n >>= 1;
    }
    return x;
}

void set_combi(){
    LL s=1;
    fact.push_back(1);
    for(int i=1;i<=3000000;i++){
        s*=i;
        s%=mod;
        fact.push_back(s);
    }
    inver[3000000]=fpow(fact[3000000],mod-2);
    for(int i=2999999;i>=0;i--){
        inver[i]=inver[i+1]*(i+1)%mod;
    }
}

LL hcombi(int n,int r){
    return combi(n+r-1,r);
}

int main(){
    set_combi();
    LL n,m;cin >> n >> m;
    LL ans = 0;
    for (int i = m; i >= 0; i-=2) {
        ans = (ans + hcombi(n,m+(m-i)/2) * combi(n,i))%mod;
    }
    for (int i = 2*m+1; i <= 3*m; i++) {
        ans = (ans - (n * hcombi(n-1,3*m-i))%mod + mod)%mod;
    }
    cout << ans << 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>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
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');}
const int mod=998244353;
const int MAXN=3000005;
int pre[MAXN],inv[MAXN];
int C(int n,int m)
{
	if(n<m)return 0;
	return 1LL*pre[n]*inv[m]%mod*inv[n-m]%mod;
}
int n,m;
void ad(int &x,int y){x+=y;if(x>=mod)x-=mod;}
void dl(int &x,int y){x-=y;if(x<0)x+=mod;}
int pow_mod(int a,int b)
{
	int ret=1;
	while(b)
	{
		if(b&1)ret=1LL*ret*a%mod;
		a=1LL*a*a%mod;b>>=1;
	}
	return ret;
}
int main()
{
	pre[0]=1;for(int i=1;i<MAXN;i++)pre[i]=1LL*pre[i-1]*i%mod;
	inv[MAXN-1]=pow_mod(pre[MAXN-1],mod-2);
	for(int i=MAXN-2;i>=0;i--)inv[i]=1LL*inv[i+1]*(i+1)%mod;
	n=read();m=read();
	int ans=0;
	for(int i=0;i<=m;i++)
		if(!((3*m-i)&1))
			ad(ans,1LL*C(n,i)*C(((3*m-i)>>1)+n-1,n-1)%mod);
//	dl(ans,1LL*n*C(m-2+n-1,n-1)%mod);
	dl(ans,1LL*n*C(m-1+n-1,n-1)%mod);
	pr2(ans);
	return 0;
}


//終局から考える。
//S[i] = '1'なるiについて、A[i]が{A[j], i+1≦j≦N-1, S[j] = '0'}と独立ならx≠0.
//全て従属とする。iが大きい方から考えると、最終的にx=0(従属)にできる。
//独立性の判定:
//・各数を2進数ベクトルと考えて {A[j], i+1≦j≦N-1, S[j] = '0'}について掃き出し法をおこない、
//  表現できるベクトル集合が同一のより単純な表現に直す
//・その表現では'1'の立つ最上位ビットの場所がdistinctだから、A[i]を作れるかを貪欲に判定できる
//計算量はO(TN^3). 厳しい？ -> 定数倍が軽いので大丈夫そう.
//0ベクトルを取り除かない上に、S[i] = '1'なるiについてもA[i]を追加してしまったバージョン
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

void sweep(vector<int> &vs) {
	int n = vs.size();
	int row = 0;

	for (int i = 59; i >= 0; i--) {
		int pipot = -1;
		for (int j = row; j < n; j++) {
			if ((vs[j] >> i) & 1) {
				pipot = j;
				break;
			}
		}
		if (pipot == -1) continue;
		swap(vs[row], vs[pipot]);

		for (int j = row + 1; j < n; j++) {
			if ((vs[j] >> i) & 1) {
				vs[j] ^= vs[row];
			}
		}
		row++;
	}
}

int solve(vector<int> a, string s) {
	int n = a.size();

	vector<int> vs;
	for (int i = n - 1; i >= 0; i--) {
		if (s[i] == '0') {
			vs.push_back(a[i]);
		}
		else {
			sweep(vs);
			int val = a[i];
			for (int j = 0; j < vs.size(); j++) {
				if ((val ^ vs[j]) < val) {
					val ^= vs[j];
				}
			}
			if (val != 0) return 1;
            vs.push_back(a[i]);
		}
	}
	return 0;
}

signed main() {
	int T;
	cin >> T;
	while (T--) {
		int i, n; cin >> n;
		vector<int> a(n);
		rep(i, n) cin >> a[i];
		string s; cin >> s;
		cout << solve(a, s) << endl;
	}
	return 0;
}

#include <iostream>
#include<bits/stdc++.h>
#define base 950527
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
vector<P> res;
ll lh,ns,nt,LH,tmp=1,n,s[200005],t[200005],K[200005],S[200005],T[200005];
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>S[i];
    }
    for(int i=0;i<n;i++){
        cin>>T[i];
    }
    for(int i=0;i<n;i++){
        K[i]=S[i]^T[0];
    }
    for(int i=0;i<n;i++){
        s[i]=S[i]^S[(i+1)%n];
        t[i]=T[i]^T[(i+1)%n];
        //cout<<s[i]<<endl;
    }
    //cin>>s>>t;
    ns=n;
    nt=n;
    for(int i=0;i<nt;i++){
        lh=lh*base+s[i];
        LH=LH*base+t[i];
        tmp*=base;
    }
    if(lh==LH)res.push_back({0,K[0]});
    for(int i=0;i<ns-1;i++){
        lh=lh*base-tmp*s[i];
        lh+=s[i];
        //cout<<LH<<" "<<lh<<" "<<i<<endl;
        if(LH==lh)res.push_back({i+1,K[i+1]});
    }
    sort(res.begin(),res.end());
    for(auto x:res){
        cout<<x.first<<" "<<x.second<<endl;
    }
}


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

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

  int n, k;
  cin >> n >> k;

  vector<int> v(n);
  rep(i, 0, n) cin >> v[i];

  ll ans = 0;
  rep(l, 0, k + 1) {
    rep(r, 0, k - l + 1) {
      if (l + r > n)
        continue;
      int d = k - l - r;
      ll now = 0;
      vector<int> s;
      rep(i, 0, l) {
        now += v[i];
        s.push_back(v[i]);
      }
      rep(i, n - r, n) {
        now += v[i];
        s.push_back(v[i]);
      }

      sort(s.begin(), s.end());
      rep(i, 0, d) {
        if (i >= s.size() || s[i] > 0)
          break;
        now -= s[i];
      }

      ans = max(ans, now);
    }
  }

  cout << ans << endl;
}

#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N,x;
  cin>>N>>x;
  vector<int> A(N);
  for(int &i:A)cin>>i;
  sort(A.begin(),A.end());
  int ans=0;
  for(int i=0;i<N;i++){
    x-=A[i];
    if(x<0)break;
    ans++;
  }
  if(ans==N && x!=0)cout<<N-1<<endl;
  else cout<<ans<<endl;
}


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

template<typename T, typename E> struct LazySegmentTree {
  using F = function<T(T, T)>;
  using G = function<T(T, E)>;
  using H = function<E(E, E)>;
  using P = function<E(E, int)>;

  int n;
  T ti;
  E ei;
  F f;
  G g;
  H h;
  P p;
  vector<T> data;
  vector<E> lazy;

  LazySegmentTree(int n_, F f, G g, H h, T ti = INT_MAX, E ei = INT_MAX,
                  P p = [](E a, int b) { return a; })
      : f(f), g(g), h(h), ti(ti), ei(ei), p(p) {
    init(n_);
  }
  void init(int n_) {
    n = 1;
    while (n < n_) n *= 2;
    data.assign(n * 2 - 1, ti);
    lazy.assign(n * 2 - 1, ei);
  }
  void build(vector<T> v) {
    for (int i = 0; i < v.size(); ++i) data[i + n - 1] = v[i];
    for (int i = n - 2; i >= 0; --i) {
      data[i] = f(data[i * 2 + 1], data[i * 2 + 2]);
    }
  }
  inline void eval(int len, int k) {
    if (lazy[k] == ei) return;
    if (k * 2 + 1 < n * 2 - 1) {
      lazy[k * 2 + 1] = h(lazy[k * 2 + 1], lazy[k]);
      lazy[k * 2 + 2] = h(lazy[k * 2 + 2], lazy[k]);
    }
    data[k] = g(data[k], p(lazy[k], len));
    lazy[k] = ei;
  }
  T update(int a, int b, E x, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    eval(r - l, k);
    if (b <= l || r <= a) return data[k];
    if (a <= l && r <= b) {
      lazy[k] = h(lazy[k], x);
      return g(data[k], p(lazy[k], r - l));
    }
    T vl = update(a, b, x, k * 2 + 1, l, (l + r) / 2);
    T vr = update(a, b, x, k * 2 + 2, (l + r) / 2, r);
    return data[k] = f(vl, vr);
  }
  T query(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    eval(r - l, k);
    if (b <= l || r <= a) return ti;
    if (a <= l && r <= b) return data[k];
    T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
    T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
    return f(vl, vr);
  }
};

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

  int n, q; cin >> n >> q;
  const int INF = INT_MAX;
  LazySegmentTree<int, int>::F f = [&](int a, int b) { return min(a, b); };
  LazySegmentTree<int, int>::G g = [&](int a, int b) { return (b == INF) ? a : b; };
  LazySegmentTree<int, int>::H h = [&](int a, int b) { return (b == INF) ? a : b; };
  LazySegmentTree<int, int>::P p = [&](int a, int b) { return (a == INF) ? a : a * b; };

  LazySegmentTree<int, int> seg(n, f, g, h);
  for (int i = 0; i < q; ++i) {
    int com; cin >> com;
    if (com) {
      int i; cin >> i;
      cout << seg.query(i, i + 1) << endl;
    } else {
      int s, t, x; cin >> s >> t >> x;
      seg.update(s, t + 1, x);
    }
  }
  return 0;
}


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

int main() {

	int n; cin >> n;
	vector<int> a(n + 2, 0);
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	int sum = 0;
	for (int i = 1; i <= n + 1; i++) {
		sum +=abs(a[i] - a[i - 1]);
	}
	for (int i = 1; i <= n; i++) {
		int tmp = sum;
		tmp -= abs(a[i] - a[i - 1]);
		tmp -= abs(a[i + 1] - a[i]);
		tmp += abs(a[i + 1] - a[i - 1]);
		cout << tmp << 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 N;
  cin >> N;
  vll A(N);

  ll sum = 0;
  rep(i, N) {
    ll a;
    cin >> a;
    A[i] = a;
    if (i == 0) {
      sum += abs(a);
    } else {
      sum += abs(a - A[i - 1]);
    }
  }
  sum += abs(A[N - 1]);

  rep(i, N) {
    if (i == 0) {
      ll ans = sum - abs(A[0]) - abs(A[0] - A[1]) + abs(A[1]);
      COUT(ans);
      continue;
    }
    if (i == N - 1) {
      ll ans = sum - abs(A[N - 1]) - abs(A[N - 2] - A[N - 1]) + abs(A[N - 2]);
      COUT(ans);
      continue;
    }
    ll a = abs(A[i - 1] - A[i]);
    ll b = abs(A[i] - A[i + 1]);
    ll c = abs(A[i - 1] - A[i + 1]);
    ll ans = sum - a - b + c;
    COUT(ans);
  }

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define reg register
#define ll long long
#define maxn 100005
inline ll read()
{
	ll x=0,w=0;char ch=getchar();
	while(!isdigit(ch))w|=ch=='-',ch=getchar();
	while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return w?-x:x;
}
int n,m;ll k;
int b[maxn],to[70][maxn],c[maxn];
double a[maxn],d[maxn];
int main()
{
    n=read();reg int i,j;
    for(i=1;i<=n;++i)a[i]=read();
    for(i=2;i<=n;++i)d[i]=a[i]-a[i-1];
    m=read(),k=read();
    for(i=1;i<=m;++i)b[i]=read();
    for(i=1;i<=n;++i)to[0][i]=i,c[i]=i;
    for(i=1;i<=m;++i)swap(to[0][b[i]],to[0][b[i]+1]);
    for(j=1;j<=62;++j)for(i=2;i<=n;++i)
        to[j][i]=to[j-1][to[j-1][i]];
    for(j=62;j>=0;--j)if(k>=(1ll<<j))
    {
        for(i=2;i<=n;++i)c[i]=to[j][c[i]];
        k^=(1ll<<j);
    }
    for(i=2;i<=n;++i)a[i]=d[c[i]]+a[i-1];
    for(i=1;i<=n;++i)printf("%.9lf\n",a[i]);
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define inf (int)(3e18)
#define P pair<int,int>
#define mod (int)(1e9+7)
#define mod2 998244353

template<class T> inline void chmin(T &a, T b) {
	a = min(a, b);
}
template<class T> inline void chmax(T &a, T b) {
	a = max(a, b);
}
int mod_pow(int x, int y, int m = mod) {
	int res = 1;
	x %= m;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int perm[1000005];
void init_perm(){
	perm[0]=1;
	REP(i,1000005)perm[i]=perm[i-1]*i%mod;
}
int nCk(int x,int y){
	if(x<y)return 0;
	return perm[x]*mod_pow(perm[x-y],mod-2)%mod*mod_pow(perm[y],mod-2)%mod;
}
int N,A,B,C,D;
int dp[1005][1005];
signed main(){
    init_perm();
    cin>>N>>A>>B>>C>>D;
    dp[0][1]=1;
    rep(i,N){
        REP(j,N){
            dp[i][j]%=mod;
            dp[i][j+1]+=dp[i][j];
        }
        for(int j=A;j<=B;j++){
            int ans=1,rem=N-i;
            REP(k,D+1){
                if(i+j*k>N)break;
                ans*=nCk(rem,j);
                ans%=mod;
                rem-=j;
                if(k>=C){
                    dp[i+j*k][j+1]+=dp[i][j]*ans%mod*mod_pow(perm[k],mod-2)%mod;
                    dp[i+j*k][j+1]%=mod;
                }
            }
        }
    }
    int ans=0;
    rep(i,N+2){
        //cout<<dp[N][i]<<endl;
        ans+=dp[N][i]%mod;
    }
    cout<<ans%mod<<endl;
}


#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) {
    ll H, W, N;
    cin >> H >> W >> N;
    cout << N / max(H, W) + !!(N % max(H, W)) << endl;
    return 0;
}

#include <stdio.h>

int main() {
	int h,w,n;
	scanf("%d", &h);
	scanf("%d", &w);
	scanf("%d", &n);
	int ctr = 0;
	int total = 0;
	while (n > total){
		if(w >= h){
			total += w;
			ctr++;
		}else if(h > w){
			total += h;
			ctr++;
		}
	}
	printf("%d\n",ctr);

	return 0;
}


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

int main(void) {
	int n,a[100];
	cin >> n;
	for(int i = 0;i < n;i++) cin >> a[i];
	bool flag = true;
	int cnt = 0;
	while(flag) {
		flag = false;
		for(int j = n-1;j > 0;j--) {
			if(a[j]<a[j-1]) {
				swap(a[j],a[j-1]);
				flag = true;
				cnt++;
			}
		}
	}
	for(int i = 0;i < n-1;i++) cout << a[i] << " ";
	cout << a[n-1] << endl << cnt << endl;
}


#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

ll mod=1e9+7;
ll fac[210];

void modfac(ll n){
    fac[0]=1;
    for(ll i=1;i<n;i++){
        fac[i]=(fac[i-1]*i)%mod;
    }
}

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

ll dp[210][100010];

int main(){
  ll n,x;
  cin >> n >> x;
  ll a[n];
  for(ll i=0;i<n;i++) cin >> a[i];
  sort(a,a+n);
  reverse(a,a+n);
  ll inv[n+1];
  for(ll i=1;i<=n;i++) inv[i]=modinv(i);
  for(ll i=0;i<=x;i++) dp[n][i]=i;
  for(ll i=n-1;i>=0;i--){
    for(ll j=0;j<=x;j++){
      ll p=n-i;
      dp[i][j]=inv[p]*(dp[i+1][j%a[i]]+(p-1)*dp[i+1][j]%mod)%mod;
    }
  }
  modfac(210);
  cout << dp[0][x]*fac[n]%mod << endl;
}

#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <numeric>
#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 bool 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 = "";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+" ";
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e17;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 200005;
ll fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    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 COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m,k;
    cin >> n >> m >> k;
    ll ans = 0;
    COMinit();
    rep(i,n){
        rep(j,m-1){
            ans += (j+1)*n*(m-j-1)%MOD;
            ans %= MOD;
        }
    }
    rep(i,n-1){
        rep(j,m){
            ans += (i+1)*m*(n-i-1)%MOD;
            ans %= MOD;
        }
    }
    PRINT(ans*COM(n*m-2,k-2)%MOD);
}


#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

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

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int 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;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
vector<long long int >meguru;
bool isOK(int index, int key) {
	if (meguru[index] >= key) return true;
	else return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = (int)meguru.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key)) right = mid;
		else left = mid;
	}
	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

int main() {
	string s;
	cin >> s;
	if (s == "RSR") {
		cout << "1";
	}
	else {
		int a = 0;
		for (int i = 0; i < 3; i++) {
			if (s[i] == 'R') {
				a++;
			}
		}
		cout << a;
	}
}

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

int main(){

    vector<int> t1,t2;
    int input = 0;

    for(int i = 0;i < 6;i++){
        if(i < 4){
            cin >> input;
            t1.push_back(input);
        }else{
            cin >> input;
            t2.push_back(input);
        }
    }

    sort(t1.begin(), t1.end());
    sort(t2.begin(), t2.end());

    int result = t1[3] + t1[2] + t1[1] + t2[1];
    cout << result << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define rep1(i, n) for (int i = 1; i < int(n); ++i)
#define repx(i, x, n) for (int i = int(x); i < int(n); ++i)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; --i)
#define ALL(n) begin(n), end(n)
#define IN(a, x, b) ((a) <= (x) && (x) < (b))
#define OUT(a, x, b) ((x) < (a) || (x) < (b))
typedef long long ll;
typedef long double ld;
const ll INF = 1e18;
const ll MOD = 1000000007;

const ll MAX = 1e9 + 10;

int main()
{
    ll N, A, B, thr, pre, now;
    cin >> N >> A >> B;
    thr = ll(B / A);
    ll ans = 0;

    cin >> pre;
    rep1(i, N)
    {
        cin >> now;
        if (now - pre > thr)
        {
            ans += B;
            // cout << "+B" << endl;
        }
        else
        {
            ans += A * (now - pre);
            // cout << "+" << A * (now - pre) << endl;
        }
        pre = now;
    }

    cout << ans << endl;

    return 0;
}

#include <iostream>
#include <vector>
#include <string.h>
#include <algorithm>
#include <cstring>
#include <queue>
#include <assert.h>
#include <cmath>
#include <stack>
#include <deque>
#include <set>
#include <unordered_map>
#include <complex>
#include <fstream>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
const int mxn = 1e6+10;
int l[mxn];

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

	int n; cin>>n;
	for(int i=1; i<=2*n; i++) cin>>l[i];
	sort(l+1, l+2*n+1);

	int sum = 0;
	for(int i=1; i<=2*n; i+=2) {
		sum+=min(l[i], l[i+1]);
	}

	cout << sum <<'\n';

	return 0;
}
//comparator function in sorting
//swapping arguments
//missing cases in dp
//dividing in modulo
//Beware of overflow and modulo
//Be mindful of overflow
//s is a matrix but forget
//length of ranges
//working with bit using ull


// https://atcoder.jp/contests/aising2019/tasks/aising2019_c
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

struct UnionFind {
  struct Node {
    ll parent;
    ll size;
  };
  vector<Node> tree;

  UnionFind(ll size) : tree(size) {
    for (ll i = 0; i < size; i++) {
      tree[i].parent = i;
      tree[i].size = 1;
    }
  }

  ll find(ll x) {
    while (tree[x].parent != x) {
      ll p = tree[x].parent;
      tree[x].parent = tree[p].parent;
      x = p;
    }
    return x;
  }

  void unite(ll x, ll y) {
    x = find(x);
    y = find(y);
    if (x == y) return;

    if (tree[x].size < tree[y].size) swap(x, y);
    tree[y].parent = x;
    tree[x].size += tree[y].size;
  }

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

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

  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i, h) cin >> s[i];

  vi dx = {0, 0, 1, -1};
  vi dy = {1, -1, 0, 0};
  UnionFind uf(h*w);
  rep(i, h) rep(j, w) rep(k, 4) {
    int ni = i+dx[k];
    int nj = j+dy[k];
    if (0 <= ni && ni < h && 0 <= nj && nj < w && s[i][j] != s[ni][nj]) {
      uf.unite(i*w + j, ni*w + nj);
    }
  }

  vector<ll> black(h*w, 0), white(h*w, 0);
  rep(i, h) rep(j, w) {
    if (s[i][j] == '#') black[uf.find(i*w + j)]++;
    else white[uf.find(i*w + j)]++;
  }

  ll ans = 0;
  rep(i, h*w) {
    ans += black[i] * white[i];
  }
  cout << ans << endl;
}

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

ll dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
ll counterb=0,counterw=0;
void dfs(ll x,ll y,ll H, ll W,vector<vector<bool>> &field,vector<vector<bool>> &check){
    check[x][y]=1;
    if(field[x][y]==1){counterb++;}
    if(field[x][y]==0){counterw++;}
    bool meter=(x+y+field[x][y])%2;
    for(int i=0;i<4;i++){if(x+dx[i]>=0&&x+dx[i]<H&&y+dy[i]>=0&&y+dy[i]<W){
        if(check[x+dx[i]][y+dy[i]]==0&&(x+y+dx[i]+dy[i]+field[x+dx[i]][y+dy[i]])%2==meter){
            dfs(x+dx[i],y+dy[i],H,W,field,check);
        };}
    ;}

}

int main(){
ll H;
cin >> H;
ll W;
cin >> W;
vector<vector<bool>> field(H, vector<bool>(W, 0));
vector<vector<bool>> check(H, vector<bool>(W, 0));
for(int i=0;i<H;i++){
 for(int j=0;j<W;j++){
     char k;
     cin>>k;
     if(k=='#'){field[i][j]=1;}
 ;}
;}
    ll ans=0;
for(ll i=0;i<H;i++){
 for(ll j=0;j<W;j++){

     if(check[i][j]==0){
         dfs(i,j,H,W,field,check);ans+=counterb*counterw;
         counterb=0;counterw=0;
     }

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

}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define Return(expr) { Cout(expr); return 0; }
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

constexpr int MOD = 998244353;

ll modpow(ll n, ll p){
    if(p == 0) return 1;
    if(p % 2 == 1) return n * modpow(n, p-1) % MOD;
    ll t = modpow(n, p/2);
    return t*t % MOD;
}

constexpr int COMB_MAX = 210000;
ll fac[COMB_MAX], finv[COMB_MAX], inv[COMB_MAX];

void initComb(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < COMB_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 comb(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(void){
    Cin(int, n, m, k);
    initComb();

    ll ans = 0;
    For(i, k+1){
        ll tmp = m * modpow(m-1, n-i-1) % MOD * comb(n-i-1 + i, i) % MOD;
        // Cout(tmp);
        ans = (ans + tmp) % MOD;
    }
    Cout(ans);
}

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1000000007;
signed main(){
  int n,m,x1,y1;
  cin>>n>>m>>x1;
  int ans1=0,ans2=0;
  for(int i=0;i<n-1;i++){
    int x2;
    cin>>x2;
    ans1=(ans1+(x2-x1)*(i+1)%mod*(n-1-i)%mod)%mod;
    x1=x2;
  }
  cin>>y1;
  for(int i=0;i<m-1;i++){
    int y2;
    cin>>y2;
    ans2=(ans2+(y2-y1)*(i+1)%mod*(m-1-i)%mod)%mod;
    y1=y2;
  }
  cout<<ans1*ans2%mod;
}


#include<bits/stdc++.h>
/* #define int long long */
/* #define double long double */
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repa(i, s, n) for(int i = s; i < (int)n; i++)
#define MOD 1000000007
using namespace std;
using ll = long long;
typedef vector<int> vi;
typedef pair<int, int> P;
#define rrep(i,a,b) for(int i=a;i>=b;i--)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main(){
    int n, r;
    cin >> n >> r;
    if(n >= 10){
        cout << r << endl;
    }else{
        // r = ans - 100 * (10 - k)
        cout << r + 100 * (10 - n) << endl;
    }
}

#include <iostream>
#include <vector>

using namespace std;

void abc_150a();

void abc_151a();

void abc_152a();

void abc_154a();

void abc_156a();

int main()
{
  //abc_150a();
  //abc_151a();
  //abc_152a();
  //abc_154a();
  abc_156a();

}

void abc_150a()
{
  int K, X;
  cin >> K >> X;

  if (500 * K >= X) cout << "Yes\n";
  else cout << "No\n";
}

void abc_151a()
{
  char C;
  cin >> C;

  cout << (char)((int)C + 1) << "\n";
}

void abc_152a()
{
  int N, M;
  cin >> N >> M;
  if (N == M) cout << "Yes\n";
  else cout << "No\n";
}

void abc_154a()
{
  string S, T;
  cin >> S >> T;
  int a, b;
  cin >> a >> b;
  string U;
  cin >> U;

  if (S == U) cout << a - 1 << " " << b << "\n";
  else cout << a << " " << b - 1 << "\n";

}

void abc_156a()
{
  int N, R;
  cin >> N >> R;

  if (N >= 10) cout << R << "\n";
  else cout << R + 100 * (10 - N) << "\n";
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int N=1000100,P=1e9+7;
inline int read(){
	int x=0,f=0,c=getchar();
	for(;c>'9'||c<'0';f=c=='-',c=getchar());
	for(;c>='0'&&c<='9';c=getchar())
	x=(x<<1)+(x<<3)+c-'0';return f?-x:x;
}
inline void write(ll x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);putchar(x%10+'0');
}
int n,a[N];
int dfs(int x){
	int sm=0,i;
	for(i=1;i<=n;i++)
		sm^=a[i]&1;
	if(sm!=(n&1))return x;
	for(i=1;i<=n;i++)
	if(a[i]&1&&a[i]>1)break;
	a[i]--;
	sm=a[1];
	for(i=2;i<=n;i++)sm=__gcd(a[i],sm);
	if(sm&1)return !x;
	for(i=1;i<=n;i++)a[i]/=sm;
	return dfs(!x);
}
int main(){
	//freopen("1.out","w",stdout);
	int i;
	n=read();
	for(i=1;i<=n;i++)a[i]=read();
	puts(dfs(1)?"First":"Second");
	return 0;
}

#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define MAX 510000
#define Rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)

using namespace std;
typedef long long int  ll;
typedef pair<int, int> P;

//cout << fixed << setprecision(10);//
//最小公倍数//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//べき//
ll squ(ll n, ll p, ll m){
	if(p==0) return 1;
	if(p%2==0){
		ll t=squ(n, p/2, m);
		return t*t%m;
	}
	return n*squ(n,p-1,m);

}

//逆元mod(mを法とするaの逆元)//
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

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

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int 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 COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//nが大

ll com(ll n,ll m){
    if(n<m || n<=0 ||m<0){
		return 0;
	}
	if( m==0 || n==m){
		return 1;
	}

	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1);
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}

	return k;
}

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

ll a[100005];

int judge(int n){
	ll y;
ll b[100005];
ll ch=0;

for(int i=1;i<=n;i++){
	if(i==1){y=a[1];
	if(y%2){y--;
	ch=1;
	}
	}
else{
	if(a[i]%2){
		ch++;
		y=gcd(y,a[i]-1);
	}
	else{
		y=gcd(y,a[i]);
	}

}

if(a[i]==1){return 0;}
if(ch>=2){return 0;}

}

if(ch==0){return 0;}
if(y==1||y%2==1){return 0;}
ll sum=0;
for(int i=1;i<=n;i++){
	if(a[i]%2==0){
	b[i]=a[i]/y;}
	else{
		b[i]=(a[i]-1)/y;
	}
if((a[i]-b[i])%2)sum++;
}
if(sum%2){return 0;}
for(int i=1;i<=n;i++){
	a[i]=b[i];
}

return 1;

}

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

ll sum=0;
rep(i, n){
	cin>>a[i];
	sum+=a[i];
}

if(n%2==0){
	if(sum%2==0){
		cout<<"Second"<<endl;
	}
	else{
		cout<<"First"<<endl;
	}
	return 0;
}

if(sum%2==0){cout<<"First"<<endl;
return 0;}

ll inv=0;
for(int u=1;u<=50;u++){
if(judge(n)==1){
	inv++;
}
else{
	break;
}
}

if(inv%2){cout<<"First"<<endl;}
else{cout<<"Second"<<endl;}
return 0;

}


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

int n,m,vis[maxn];

ll ans[maxn],a[maxn],k,cnt,q[maxn],pos[maxn];

template <class T>
void read(T &x){
	char s=getchar();int f=0;x=0;
	while(s<'0'||s>'9'){if(s=='-') f=1;s=getchar();}
	while(s>='0'&&s<='9') x=(x<<3)+(x<<1)+s-'0',s=getchar();
	x=f?-x:x;
}

int main(){
	read(n);
	for(int i=1;i<=n;i++){
		read(a[i]);
		pos[i]=1ll*i;
	}
	read(m);read(k);
	for(int i=n;i>=1;i--) a[i]=a[i]-a[i-1];
	for(int i=1,x;i<=m;i++){
		read(x);
		swap(pos[x],pos[x+1]);
	}
	for(int i=1;i<=n;i++){
		ll p=i;cnt=0;
		if(vis[i]) continue;
		q[++cnt]=p;
		vis[p]=1;
		p=pos[p];
		while(p!=i){
			q[++cnt]=p;
			vis[p]=1;
			p=pos[p];
		}
		for(int j=1;j<=cnt;j++) ans[q[j]]=a[q[(j+k-1)%cnt+1]];
	}
	for(int i=1;i<=n;i++){
		ans[i]+=ans[i-1];
		printf("%lld.0\n",ans[i]);
	}
	return 0;
}

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

int main () {
  int d, g;
  cin >> d >> g;
  vector<pair<int,int>> p(d);
  for (int i = 0; i < d; i++)
    cin >> p[i].first >> p[i].second;

  vector<int> v(d);
  iota (v.begin(), v.end(), 0);
  int ans = 1000;
  do {
    int sum = 0, c = 0;
    for (int i = 0; i < d; i++) {
      int x = v[i];
      int i100 = 100 * (x+1);
      int pi100 = p[x].first * i100;
      if (g > sum + pi100 + p[x].second) {
        sum += pi100 + p[x].second;
        c += p[x].first;
      }
      else if (sum + pi100 <= g &&
               g <= sum + pi100 + p[x].second) {
        c += p[x].first;
        break;
      }
      else {
        c += (g - sum + i100-1) / i100;
        break;
      }
    }
    ans = min(ans, c);
  }
  while (next_permutation(v.begin(), v.end()));

  cout << ans << endl;
}


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

const int N=1001000;
int fa[N],n,m,q[N],d[N],a[N],bl[N];
vector<int>g[N];
vector<pair<int,int> >vec[N];
int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
void add(int x,int y){g[x].push_back(y);g[y].push_back(x);}

int bfs(int S,int T){
	for(int i=1;i<=n;++i)d[i]=-2;
	d[S]=0;int t=-1,w=0;q[0]=S;
	for(;t<w;){
		int x=q[++t];
		for(int i:g[x])if(d[i]==-2)d[i]=d[x]+1,q[++w]=i;
	}
	return d[T];
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>m;int S=1,T=n,mx=0;
	for(int i=1;i<=m;++i){
		int x,y,z;cin>>x>>y>>z;mx=max(mx,z);
		vec[z].emplace_back(x,y);
	}
	for(int i=1;i<=mx;++i)if(!vec[i].empty()){
		int cnt=0;
		for(auto j:vec[i])a[++cnt]=j.first,a[++cnt]=j.second;
		sort(a+1,a+cnt+1);cnt=unique(a+1,a+cnt+1)-a-1;
		for(int j=1;j<=cnt;++j)fa[a[j]]=a[j];
		for(auto j:vec[i])fa[find(j.first)]=find(j.second);
		for(int j=1;j<=cnt;++j)if(fa[a[j]]==a[j])bl[a[j]]=++n;
		for(int j=1;j<=cnt;++j)add(a[j],bl[find(a[j])]);
	}
	cout<<(bfs(S,T)/2)<<'\n';
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 233;
typedef long long ll;
int a[maxn],l[maxn],r[maxn],ord[maxn];
ll val[maxn],sum[maxn],tot = 0;
int n,x;
bool cmp(int i,int j){
	return val[i]>val[j];
}
inline ll cal(int i,int v){
	if(v<=a[i])return 1LL*v*l[i];
	return 1LL*a[i]*l[i]+1LL*(v-a[i])*r[i];
}
bool check(ll m){
	int t = (m-1)/x,v = m-t*x;
	ll maxi = 0;
	for(int i=1;i<=t;i++){
		int x = ord[i];
		ll tmp = sum[t+1] - val[x] + cal(x,v);
		maxi = max(maxi,tmp);
	}
	for(int i=t+1;i<=n;i++){
		ll tmp = sum[t] + cal(ord[i],v);
		maxi = max(maxi,tmp);
	}
	if(maxi>=tot)return 1;
	return 0;
}
int main()
{
	cin>>n>>x;
	for(int i=1;i<=n;i++)
		scanf("%d%d%d",&a[i],&l[i],&r[i]),
		val[i] = cal(i,x),
		ord[i] = i,
		tot += cal(i,a[i]);
//	cout<<tot<<endl;
	sort(ord+1,ord+n+1,cmp);
	for(int i=1;i<=n;i++)
		sum[i] = sum[i-1]+val[ord[i]];
	ll l = 0,r = 1LL*n*x;
	while(l!=r){
		ll m = (l+r)>>1;
		if(check(m))r = m;
		else l = m+1;
	}
	cout << l << endl;
	return 0;
}


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

int main(){
	ll n,x,t;
	cin>>n>>x>>t;

	ll k=n/x,r=n%x;

	if(r>0)r=1;

    cout<<k*t+r*t;

}

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

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    ll a,b,c; cin>>a>>b>>c;
    if(a<c && c<b || b<c && c<a) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = (int)(j);i <= (int)(k);i ++)
#define debug(x) cerr<<#x<<":"<<x<<endl
#define fix cout<<fixed<<setprecision(20);
const int maxn=(int)2e6+5;
vector<int> E[maxn];
int vis[maxn],ind[maxn],dis[maxn];
int reach[maxn];//longest can reach
inline int id(int x,int y){
    if(x>y)swap(x,y);
    //x--,y--;
    return x+1000*y;
}
int ans=-1;

int dfs(int x){
    //debug(x);
    if(vis[x]==2)return dis[x];
    vis[x]=1;
    for(auto v:E[x]){
        if(vis[v]==1)return -1;

        //dis[v]=dis[x]+1;ans=max(ans,dis[v]);
        int ret=dfs(v);
        if(ret==-1)return -1;
        dis[x]=max(dis[x],ret+1);//每个节点存最大值。

    }

    //debug(dis[x]);debug(x);

    vis[x]=2;
    return dis[x];
}
int main(){
    //ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;cin>>n;
    rep(i,1,n){
        int last=0;
        rep(j,1,n)if(i!=j){
            int x;scanf("%d",&x);
            if(last==0){last=id(i,x);continue;}
            E[last].push_back(id(i,x));ind[id(i,x)]++;
            last=id(i,x);
        }
    }

    rep(i,1,n)rep(j,1,i-1)if(ind[id(i,j)]==0){
       // memset(vis,0,sizeof(vis));
        E[0].push_back(id(i,j));
        /* dis[id(i,j)]=1;
        if(dfs(id(i,j))==0){cout<<-1<<endl;return 0;};
        //debug("--"); */
    }
    dis[0]=-1;
    int ans=dfs(0);

    cout<<ans<<endl;

}
/*
建DAG，判环
topo 可判环（无法进入队列的点），但无法找最长路径
两种环
一种是链环，用
一种是纯环，
3
2 3
1 3
1 2

12-13
12-23
13-23

4
2 3 4
1 3 4
4 1 2
3 1 2

12-13
13-14
12-23
23-24
34-13
13-23
34-14
14-24

 queue<int> Q;
    rep(i,1,n)rep(j,1,i-1)if(ind[id(i,j)]==0)Q.push(id(i,j)),vis[id(i,j)]=1;
    while(!Q.empty()){

        int cur=Q.front();Q.pop();
        debug(cur);debug(vis[cur]);
        for(auto v:E[cur]){
            if(vis[v]){continue;}
            //if(vis[v]==1){cout<<-1<<endl;return 0;}
            ind[v]--;
            if(ind[v]==0)Q.push(v),vis[v]=vis[cur]+1,ans=max(ans,vis[v]);
        }
    }
   // rep(i,1,n)rep(j,1,n)if(i!=j)debug(vis[id(i,j)]),debug(i),debug(j);
 */

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Edge=pair<int,int>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
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;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int N;
deque<int> A[1010];
int step[1010];
int M;
int main(){
  cin>>N;
  REP(i,N){
    REP(j,N-1){
      int x;
	  cin>>x;
	  A[i].push_back(x-1);
    }
  }
  M=N*(N-1)/2;

  queue<int> Q;
  REP(i,N) Q.push(i);

  int num=0;
  while(Q.size()){
    queue<int> Q2;

    while(Q.size()){
      int i=Q.front();
      Q.pop();
      if(step[i]<=num && A[i].size() && A[A[i].front()].front()==i && step[A[i].front()]<=num) {
        step[i]=step[A[i].front()]=num+1;
        Q2.push(i);
        Q2.push(A[i].front());
        A[A[i].front()].pop_front();
        A[i].pop_front();
        M--;
      }
    }
    num++;
    if(M==0) break;
    swap(Q,Q2);
  }

  if(M) cout<<-1<<endl;
  else cout<<num<<endl;
}


#include<bits/stdc++.h>
using namespace std;
long long int Min(long long int x,long long int y)
{
    if(x<y)
        return x;
    return y;
}
int main()
{
    long long int n,k,i,j,x;
    long long int ans;
    cin>>n>>k;
    long long int ara[n];
    for(i=0; i<n; i++)
        cin>>ara[i];

    if(ara[0]<0&&ara[n-1]<=0)
        ans=(-1)*ara[0];
    else if(ara[0]>=0 && ara[n-1]>0)
        ans=ara[n-1];
    else
        ans=(ara[n-1]-ara[0]-ara[0]);

    if(ara[0]>=0)
        cout<<ara[k-1]<<endl;
    else if(k==0)
        cout<<0<<endl;
    else
    {
        for(i=0; i<n; i++)
        {
            j=i+k-1;
            if(j>n-1)
                break;
            if(ara[i]<0 && ara[j]>0){
                    x=Min(ara[j]-ara[i]-ara[i],-ara[i]+ara[j]+ara[j]);
                ans=Min(ans,x);
            }
            else if(ara[i]<0 && ara[j]<=0)
                ans=Min(ans,(-1)*ara[i]);
            else
                ans=Min(ans,ara[j]);
        }
        cout<<ans<<endl;
    }

    return 0;
}

#include<iostream>
#include<queue>
#include<cmath>
#include<algorithm>
using namespace std;
int n,m,ans=0x3f3f3f3f;
int a[100000+5];
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=1;i<=n-m+1;i++){
		int j=m+i-1;
		ans=min(ans,min(abs(a[i])+abs(a[j]-a[i]),abs(a[j])+abs(a[j]-a[i])));
	}
	if(ans==0x3f3f3f3f) cout<<0<<endl;
	cout<<ans<<endl;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
# define ll int64_t
# define str string
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;

#define INF 2000000000
#define MAX_V 10

bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<ll,ll> a,pair<ll,ll> b){
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll modpow(ll a,ll n,ll mod1) {
    ll res=1;
    while(n>0){
        if(n&1) res=res*a%mod1;
        a = a*a%mod1;
        n >>= 1;
    }
    return res;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

ll gcd(ll a,ll b) { return b ? gcd(b, a%b) : a; }

ll lcm(ll a,ll b){
   return a/gcd(a,b)*b;
}
const ll MAX = 5100000;
const ll MOD = 1000000007;

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

// テーブルを作る前処理
void COMinit() {
    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 COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

using graph = vector<vector<ll>>;
pair<pair<ll,ll>,ll> p[100010];

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

    ll n,k;
    cin>>n>>k;
    vec<ll> a(n);
    rep(i,n) {
        cin>>a[i];
    }

    sort(ALL(a));
    if(a[n-1]<k){
        cout<<"IMPOSSIBLE"<<endl;
        return 0;
    }
    ll sum=gcd(a[0],a[1]);
    for(ll i=2;i<n;i++) sum=gcd(sum,a[i]);

    if(k%sum==0) cout<<"POSSIBLE"<<endl;
    else cout<<"IMPOSSIBLE"<<endl;
    return 0;
}

#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline T intceil(T a, T b) { return (a + (b - 1)) / b; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const long long MOD = 1e9+7;
#define precout() cout << std::fixed << std::setprecision(20);
const string alphabet = "abcdefghijklmnopqrstuvwxyz";
const int dy[4] = { 0, 1, 0, -1 };
const int dx[4] = { 1, 0, -1, 0 };
typedef complex<double> cd;
static const double pi = 3.141592653589793;

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

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

  int n,k; cin >> n >> k;
  int curGcd; cin >> curGcd;
  int maxA = curGcd;
  rep(i, n - 1) {
    int tmp; cin >> tmp;
    chmax(maxA, tmp);
    curGcd = gcd(curGcd, tmp);
  }

  if(k <= maxA && k % curGcd == 0) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
}


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

int main() {
  vector<int> time(3);
  vector<int> subsc = {0, 1, 2};
  rep(i, 3) cin >> time[i];
  int cmp = 100000000;
  do {
    int sum = 0;
    rep(i, 2) sum += time[subsc[i]];
    cmp = min(sum, cmp);
  }while(next_permutation(subsc.begin(), subsc.end()));

  cout << cmp << endl;
  return 0;
}

#include<iostream>
using namespace std;
int main(){
    int d,a,b,s,sum;
    while(cin>>d){
        sum=0;
        a=600/d;
        for(int i=0;i<a;i++){
            b=d*d*i*i;
            s=b*d;
            sum+=s;
        }
        cout << sum << endl;
    }
    return 0;
}


#include <stdio.h>

int main() {
    int H;
    int W;
    int N;
    scanf("%d", &H);
    scanf("%d", &W);
    scanf("%d", &N);
    int ctr = 0;
    int total = 0;
    while (N > total){
        if(W >= H){
            total += W;
            ctr++;
        }else if(H > W){
            total += H;
            ctr++;
        }
    }
    printf("%d\n",ctr);

    return 0;
}

#include <stdio.h>

int main() {
  int rows, columns, n, tempR = 1, tempC = 1;
  scanf("%d %d %d", &rows, &columns, &n);

  int i = 1, j = 1;
  while(tempR < n && i <= rows) {
    tempR = i * columns;
    i++;
  }
  while(tempC < n && j <= columns) {
    tempC = j * rows;
    j++;
  }

  if(i == 1 && j == 1) printf ("1");
  else if(i < j) printf("%d", i - 1);
  else printf("%d", j - 1);
  return 0;
}