#include <algorithm>
#include <iostream>
using namespace std;
static const int MAX = 200000;

static const int sentinel = 1000000000;
long int ninvention = 0;

int merge(int A[], int left, int mid, int right) {
  int n1 = mid - left;
  int n2 = right - mid;
  int L[n1 + 1], R[n2 + 1];
  for (int i = 0; i < n1; i++)
    L[i] = A[left + i];
  for (int i = 0; i < n2; i++)
    R[i] = A[mid + i];
  L[n1] = sentinel;
  R[n2] = sentinel;

  int i = 0, j = 0;
  for (int k = left; k < right; k++) {
    if (L[i] <= R[j]) {
      A[k] = L[i];
      i++;
    } else {
      ninvention += max(0, n1 - i);
      A[k] = R[j];
      j++;
    }
  }
}

int mergeSort(int A[], int left, int right) {
  if (left + 1 < right) {
    int mid = (left + right) / 2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}

int main() {
  int data[MAX];
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> data[i];
  }
  mergeSort(data, 0, n);

  cout << ninvention << endl;
}

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

using namespace std;

using i64=long long;

template <typename T>
struct BinaryIndexedTree {
    size_t n;
    vector<T> tree;
    BinaryIndexedTree(size_t n, T e=0): n(n) {
        tree = vector<T>(n+1, e);
    }
    void add(size_t i, T w) {
        // v[i] += w;
        // i in [1, n]
        for (size_t j=i; j<=n; j+=j&-j)
            tree[j] += w;
    }
    T sum(T m) {
        // returns sum of v[i] for i in [1, m]
        T sum_=0;
        for (size_t i=m; i>0; i-=i&-i)
            sum_ += tree[i];

        return sum_;
    }
};

int main() {
    size_t n;
    scanf("%zu", &n);

    vector<int> a(n);
    for (size_t i=0; i<n; ++i)
        scanf("%d", &a[i]);

    map<int, size_t> m;
    for (size_t i=0; i<n; ++i)
        m[a[i]] = i;

    vector<int> b(n);
    int rank_=1;
    for (pair<const int, size_t> p: m)
        b[p.second] = rank_++;

    BinaryIndexedTree<i64> tree(n+1);
    i64 res=0;
    for (size_t i=0; i<n; ++i) {
        res += i-tree.sum(b[i]);
        tree.add(b[i], 1);
    }

    printf("%lld\n", res);
    return 0;
}


#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int flood(char map[][14], int i, int j){
    if(map[i][j] == '1')
        map[i][j] = '0';
    if(map[i+1][j] == '1')
        flood(map,i+1,j);
    if(map[i][j+1] == '1')
        flood(map,i,j+1);
    if(map[i-1][j] == '1')
        flood(map,i-1,j);
    if(map[i][j-1] == '1')
        flood(map,i,j-1);
    return 1;
}

int main(){
    bool loop = true;
    char map[14][14] = {{'0'}}, s[14];
    while(loop){
        range(i,1,13){
            if(!(cin >> s)) loop = false;
            rep(j,12){
                map[i][j+1] = s[j];
            }
        }
        int ans = 0;
        range(i,1,13){
            range(j,1,13){
                if(map[i][j] == '1')
                    ans += flood(map,i,j);
            }
        }
        if(loop)
            cout << ans << endl;
    }
}

#include <bits/stdc++.h>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;

int main(){
	int n,p;
	int have[50];
	while(true){
		cin >> n >> p;
		if(n==0 && p==0) break;
		for(int i=0;i<n;i++) have[i]=0;
		int turn=0;
	    int cnt=p;
		while(true){
			if(cnt>0){
				cnt--;
				have[turn%n]++;
				if(have[turn%n]==p){
					cout << turn%n << endl;
					break;
				}

			}
			else{
					cnt =have[turn%n];
					have[turn%n]=0;
				}
			turn++;

		}

	}
}


#include<iostream>
int rounds;
int Ascore, Bscore;
int Acard,Bcard;
int main(){
	while (true){
		std::cin >> rounds;
		if (rounds == 0)break;
		for (int i = 0; i < rounds; i++){
			std::cin >> Acard>> Bcard;
			if (Acard > Bcard){
				Ascore += (Acard + Bcard);
			}
			else if (Acard < Bcard){
				Bscore += (Acard + Bcard);
			}
			else{
				Ascore += Acard;
				Bscore += Bcard;
			}
		}
		std::cout << Ascore << " " << Bscore << "\n";
		Ascore = 0, Bscore = 0;
	}
	return 0;
}

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
using namespace std;

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

  int m, d;
  while( cin >> m >> d ){
    if( m == 0 || d == 0 ) break;

    int tmp = d;
    for(int i=0; i<m; i++) tmp += M[i];

    cout << w[tmp%7] << endl;
  }

  return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<ll,ll>
#define PP pair<P,P>
using namespace std;

int dp[80][80][16000];

int main(){
    int h,w; cin >> h >> w;
    int a[h][w];
    int b[h][w];
    rep(i,h)rep(j,w) cin >> a[i][j];
    rep(i,h)rep(j,w) cin >> b[i][j];
    rep(i,h)rep(j,w) a[i][j]=abs(a[i][j]-b[i][j]);
    rep(i,h)rep(j,w)rep(k,16000) dp[i][j][k]=0;
    dp[0][0][a[0][0]]=1;
    rep(i,h)rep(j,w)rep(k,16000){
        if(i>0){
            if(dp[i-1][j][k]){
                dp[i][j][k+a[i][j]]=1;
                dp[i][j][abs(k-a[i][j])]=1;
            }
        }
        if(j>0){
            if(dp[i][j-1][k]){
                dp[i][j][k+a[i][j]]=1;
                dp[i][j][abs(k-a[i][j])]=1;
            }
        }
    }
    int now=0;
    for(;;){
        if(dp[h-1][w-1][now]){
            cout << now << endl;
            return 0;
        }
        now++;
    }
return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	vector<long long>v(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	vector<vector<long long>>dp(n, vector<long long>(2, 0));
	dp[0][0] = v[0];
	dp[0][1] = -v[0];
	for (int i = 1; i < n - 1; i++) {
		dp[i][0] = max(dp[i - 1][0] + v[i], dp[i - 1][1] - v[i]);
		dp[i][1] = max(dp[i - 1][0] - v[i], dp[i - 1][1] + v[i]);
	}
	cout << (max(dp[n - 2][0] + v[n - 1], dp[n - 2][1] - v[n - 1])) << endl;
}


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

int sign(int x){
  return (x>0)-(x<0);
}
int main(){
  int x,y;
  int count = 0;
  cin >> x >> y;

  if( sign(x)*sign(y)==1 ){
    if( x<y ) cout << y-x << endl;
    if( x>y ) cout << x-y+2 << endl;
  }
  if( sign(x)*sign(y)==-1 ){
    if( sign(x)*x<=sign(y)*y ) cout << sign(y)*y-sign(x)*x+1 << endl;
    if( sign(x)*x>sign(y)*y ) cout << sign(x)*x-sign(y)*y+1 << endl;
  }
  if( x*y==0 ){
    if( x<y ) cout << y-x << endl;
    if( x>y ) cout << x-y+1 << endl;
  }
}

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

lli x, y;

int main(void){
	cin >> x >> y;
	lli ans = 1e18;
	rep(i, 2){
		rep(j, 2){
			lli xc, yc;
			xc = x;
			yc = y;
			lli c = 0;
			if(i == 1) xc*=-1, c++;
			if(j == 1) yc*=-1, c++;
			if(xc <= yc) c+=yc-xc;
			else c+=1e18;
			ans = min(ans, c);
		}
	}
	cout << ans << endl;
	return 0;
}


#include<iostream>

using namespace std;

class Dice{
  private:
    int d_1,d_2,d_3,d_4,d_5,d_6;
  public:
    void setDice(int a,int b,int c,int d,int e,int f){
      d_1 = a;
      d_2 = b;
      d_3 = c;
      d_4 = d;
      d_5 = e;
      d_6 = f;
    }
    void roll_w(){
      int tmp = d_1;
      d_1 = d_3;
      d_3 = d_6;
      d_6 = d_4;
      d_4 = tmp;
    }
    void roll_e(){
      int tmp = d_1;
      d_1 = d_4;
      d_4 = d_6;
      d_6 = d_3;
      d_3 = tmp;
    }
    void roll_n(){
      int tmp = d_1;
      d_1 = d_2;
      d_2 = d_6;
      d_6 = d_5;
      d_5 = tmp;
    }
    void roll_s(){
      int tmp = d_5;
      d_5 = d_6;
      d_6 = d_2;
      d_2 = d_1;
      d_1 = tmp;
    }

    void spin(){
      int tmp = d_2;
      d_2 = d_3;
      d_3 = d_5;
      d_5 = d_4;
      d_4 = tmp;
    }

    int findRight(int top,int front){
      for(int i=0;i < 6;i++){
        for(int j=0;j < 4;j++){
          if((*this).d_1 == top && (*this).d_2 == front) return (*this).d_3;
          (*this).spin();
        }
        if(i % 2 == 0)
        (*this).roll_n();
        else
        (*this).roll_w();
      }
      return -1;
    }

    bool cmpDice(Dice d2){
      for(int i=0;i < 6;i++){
        for(int j=0;j < 4;j++){
          if((*this).d_1 == d2.d_1 && (*this).d_2 == d2.d_2 && (*this).d_3 == d2.d_3
          && (*this).d_4 == d2.d_4 && (*this).d_5 == d2.d_5 && (*this).d_6 == d2.d_6){
            return true;
          }
          d2.spin();
        }
        if(i % 2 == 0) d2.roll_n();
        else d2.roll_w();
      }
      return false;
    }

    int getDice(){
      return d_1;
    }

};

int main(){
  int n;
  int a,b,c,d,e,f;
  bool ok = true;
  Dice D[100];
  cin >> n;
  for(int i=0;i < n;i++){
    cin >> a >> b >> c >> d >> e >> f;
    D[i].setDice(a,b,c,d,e,f);
  }
  for(int i=0;i < n;i++){
    for(int j=0;j < n;j++){
      if(i==j) continue;
      if(D[i].cmpDice(D[j])){
        ok = false;
        break;
      }
    }
    if(!ok) break;
  }
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

#include <iostream>
#include <stdlib.h>

using namespace std;

int main() {

    int count,box,random,a=0,b=0,i,j,k,n,dice[100][6];

    cin >> n;

    for(i=0;i<n;i++){
        for(j=0;j<6;j++){
            cin >> dice[i][j];
        }
    }

    for(k=1;k<n;k++){
        if(b==1){
            break;
        }
         for(i=0;i<10000;i++){
             count=0;
             if(a==1){
                 b=1;
                 break;
             }
             for(int j=0;j<6;j++){
                 if(dice[0][j] == dice[k][j]){
                     count++;
                 }
             }
             if(count==6){
                 cout << "No" << endl;
                 a=1;
                 break;
             }

             random = rand() % 4 + 1;

             if(random == 1){
                 box=dice[k][0];
                 dice[k][0]=dice[k][4];
                 dice[k][4]=dice[k][5];
                 dice[k][5]=dice[k][1];
                 dice[k][1]=box;
             }
             else if(random == 2){
                 box=dice[k][0];
                 dice[k][0]=dice[k][1];
                 dice[k][1]=dice[k][5];
                 dice[k][5]=dice[k][4];
                 dice[k][4]=box;
             }
             else if(random == 3){
                 box=dice[k][0];
                 dice[k][0]=dice[k][2];
                 dice[k][2]=dice[k][5];
                 dice[k][5]=dice[k][3];
                 dice[k][3]=box;
             }
             else if(random == 4){
                 box=dice[k][0];
                 dice[k][0]=dice[k][3];
                 dice[k][3]=dice[k][5];
                 dice[k][5]=dice[k][2];
                 dice[k][2]=box;
             }
         }
    }

         if(a!=1){
             cout << "Yes" << endl;
         }

    return 0;
}


//#include "debug.h"
#include <string.h>
#include <limits.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

const long long M=1000000007;
//typedef long T;
//#include "math/mod.h"

//#include "math/modulo.h"

template<class T, long long M>
struct modulo {
	T n;
	T gcd_ext(T a, T b, T *x, T *y) {
		if (a == 0) {
			*x = 0;
			*y = 1;
			return b;
		}
		T x1, y1;
		T gcd = gcd_ext(b%a, a, &x1, &y1);
		*x = y1 - (b/a) * x1;
		*y = x1;
		return gcd;
	}
	modulo(T n): n(n<0? n%M+M: n%M) {}
	operator T() const { return n; }
	modulo operator-() {
		return modulo(-n);
	}
	modulo operator+(const modulo &o) {
		return modulo(n+o.n);
	}
	modulo operator-(const modulo &o) {
		return modulo(n-o.n);
	}
	modulo operator*(const modulo &o) {
		return modulo(n*o.n);
	}
	modulo operator/(const modulo &o) {
		T x, y;
		T g = gcd_ext(o.n, M, &x, &y);
		if (g != 1) return 0;
		else return modulo(n * (x % M));
	}
	bool operator<(const modulo &o) const {
		return n<o.n;
	}
	bool operator<=(const modulo &o) const {
		return n<=o.n;
	}
	bool operator>(const modulo &o) const {
		return n>o.n;
	}
	bool operator>=(const modulo &o) const {
		return n>=o.n;
	}
	bool operator==(const modulo &o) const {
		return n==o.n;
	}
	bool operator!=(const modulo &o) const {
		return n!=o.n;
	}
};

typedef modulo<long long, M> T;
//#include "math/comb.h"

void comb_inc_k(T &r, int n, int &k) {
        //C(n,k+1) = C(n,k) * (n-k) / (k+1)
	r = r * T(n-k) / T(k+1);
	k++;
}

void comb_dec_k(T &r, int n, int &k) {
        //C(n,k-1) = C(n,k) * k / (n-k+1)
	r = r * T(k) / T(n-k+1);
	k--;
}

void comb_inc_n(T &r, int &n, int k) {
        //C(n+1,k) = C(n,k) * (n+1) / (n+1-k)
	r = r * T(n+1) / T(n+1-k);
	n++;
}

void comb_dec_n(T &r, int &n, int k) {
        //C(n-1,k) = C(n,k) * (n-k) / n
	r = r * T(n-k) / T(n);
	n--;
}

T comb(int n, int k) {
    if (k*2 > n) k = n-k;
    if (n==0) return 0;
    T r = 1; //C(n,0)
    for (int i=0; i<k; ) comb_inc_k(r, n, i);
    return r;
}

int h,w,a,b;

int input() {
	if (scanf("%d %d %d %d", &h, &w, &a, &b) < 0) return 0;
	return 1;
}

void init() {
}

int solve() {
	T r = comb(h+w-2, h-1);

	int xn = h-a+b-1, xk = b-1;
	T x = comb(xn, xk);

	int yn = a-1+w-b-1, yk = w-b-1;
	T y = comb(yn, yk);

	for (int i=0; i<a; i++) {
		//T x = mod_combinations(h-a+i+b-1, b-1, M);
		//T y = mod_combinations(a-1-i+w-b-1, w-b-1, M);
		if (i) {
			comb_inc_n(x, xn, xk);
			comb_dec_n(y, yn, yk);
		}
		r = r-x*y;
	}
	/*
	T r = mod_combinations(h+w-2, h-1, M);
	T x = mod_combinations(h-a+b-1, b-1, M);
	T y = mod_combinations(a-1+w-b-1, w-b-1, M);
	for (int i=0; i<a; i++) {
		//T x = mod_combinations(h-a+i+b-1, b-1, M);
		//T y = mod_combinations(a-1-i+w-b-1, w-b-1, M);
		if (i) {
			T n = h-a+i+b-1, m = b-1;
			x = mod_div(x*n, n-m, M);

			n = a-1-i+w-b-1, m = w-b-1;
			y = mod_div(y*(n+1-m), n+1, M);
		}
		T z = mod_mul(x, y, M);
		//printf("%d: r=%ld %ld %ld %ld\n", i, r, x, y, z);
		r = mod_sub(r, z, M);

	}
	*/
	return r;
}

void output(int ans) {
	printf("%d\n", ans);
}

void cleanup() {
}

int main() {
	//precalc();
	//int ca; scanf("%d", &ca);
	while (input()) {
		init();
		output(solve());
		cleanup();
		//break;
	}
}

#include<cstring>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#define ll long long
using namespace std;//往左走w-1,往下走h-1
const ll mod=1000000007;
ll f[1000000];
ll quick(ll a,ll b)
{
//	cout<<"a"<<a<<"b"<<b<<endl;
	ll ans=1;
	while(b)
	{
		if(b&1)
		{
			ans=(ans*a)%mod;
		}
		b>>=1;
		a=(a*a)%mod;
	}
//	cout<<"("<<ans<<endl;
	return ans;
}
ll ni(ll a)
{
//	cout<<"ni"<<endl;
	return quick(a,mod-2);
}
ll c(int n,int m)
{
	ll a=f[n];
//	cout<<"a"<<f[n]<<endl;
	ll b=(f[m]*f[n-m])%mod;
//	cout<<"b"<<b<<endl;
	return (a*ni(b))%mod;
}
int main()
{
	int h,w,a,b;
	f[0]=1;
	for(int i=1;i<=200005;i++)
	{
		f[i]=(f[i-1]*i)%mod;
	}
	cin>>h>>w>>a>>b;
	ll ans=0;
	ll t;
	for(int i=b+1;i<=w;i++)
	{
	//	cout<<"-----"<<endl;
	//	cout<<"!"<<c(h-a-1+i-1,h-a-1)<<endl;
	//	cout<<"!"<<c(w-i+a-1,a-1)<<endl;
		t=(c(h-a-1+i-1,h-a-1)*c(w-i+a-1,a-1))%mod;
		ans=(ans+t)%mod;
	}
	cout<<ans<<endl;
}


//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

const int MAX_ROW = 100010; // to be set appropriately
const int MAX_COL = 70; // to be set appropriately

struct BitMatrix {
	int H, W;
	bitset<MAX_COL> val[MAX_ROW];
	BitMatrix(int m = 1, int n = 1) : H(m), W(n) {}
	inline bitset<MAX_COL>& operator [] (int i) { return val[i]; }
};

int GaussJordan(BitMatrix &A, bool is_extended = false) {
	int rank = 0;
	for (int col = 0; col < A.W; ++col) {
		if (is_extended && col == A.W - 1) break;
		int pivot = -1;
		for (int row = rank; row < A.H; ++row) {
			if (A[row][col]) {
				pivot = row;
				break;
			}
		}
		if (pivot == -1) continue;
		swap(A[pivot], A[rank]);
		for (int row = 0; row < A.H; ++row) {
			if (row != rank && A[row][col]) A[row] ^= A[rank];
		}
		++rank;
	}
	return rank;
}

int linear_equation(BitMatrix A, vector<int> b, vector<int> &res) {
	int m = A.H, n = A.W;
	BitMatrix M(m, n + 1);
	for (int i = 0; i < m; ++i) {
		for (int j = 0; j < n; ++j) M[i][j] = A[i][j];
		M[i][n] = b[i];
	}
	int rank = GaussJordan(M, true);

	// check if it has no solution
	for (int row = rank; row < m; ++row) if (M[row][n]) return -1;

	// answer
	res.assign(n, 0);
	for (int i = 0; i < rank; ++i) res[i] = M[i][n];
	return rank;
}

BitMatrix encodeBM(vector<int> v, int col)
{
	BitMatrix M(v.size(), col);
	rep(i, 0, (int)v.size())
	{
		rep(j, 0, col)
		{
			M[i][col - (j + 1)] = (v[i] >> j) & 1;
		}
	}
	return M;
}

vector<int> decodeBM(BitMatrix M)
{
	vector<int> v(M.H);
	rep(i, 0, M.H)
	{
		int n = 0;
		rep(j, 0, M.W)
		{
			if (M[i][j])
			{
				n |= 1LL << (M.W - (j + 1));
			}
		}
		v[i] = n;
	}
	return v;
}

int N;
int A[100010];

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

	cin >> N;
	int ans = 0;
	rep(i, 0, N)
	{
		cin >> A[i];
		ans ^= A[i];
	}

	vector<int> v;
	rep(i, 0, N)
	{
		v.push_back(A[i] & (~ans));
	}

	BitMatrix M = encodeBM(v, 60);
	GaussJordan(M, false);

	v = decodeBM(M);

	int res = 0;
	for (auto n : v)
	{
		res ^= n;
	}

	ans += res * 2;
	cout << ans << endl;

	return 0;
}

#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>

typedef uint64_t ull;
typedef  int64_t sll;

static const ull MOD = 1000000007LL;

int n;
int k;
int q;

ull a[200019];

ull umin (ull a, ull b) {
	return (a < b) ? a : b;
}
ull umax (ull a, ull b) {
	return (a > b) ? a : b;
}

ull solve () {
	sll i, j, ki;
	ull res = 0;

	ull allxor = 0;
	for (i = 0; i < n; i++) {
		allxor ^= a[i];
	}
	for (i = 0; i < n; i++) {
		a[i] &= ~allxor;
	}

	ull rank = 0;
	for (i = 59; i >= 0; i--) {
		for (j = rank; j < n; j++) {
			if (a[j] & (1LL << i)) break;
		}
		if (j == n) {
			continue;
		}

		if (j > rank) a[rank] ^= a[j];
		for (j = rank + 1; j < n; j++) {
			a[j] = umin(a[j], a[j] ^ a[rank]);
		}

		rank++;
	}
	ull x = 0;
	for (i = 0; i < n; i++) {
		x = umax(x, x ^ a[i]);
	}

	res = (x * 2) + allxor;

	return res;
}

int main(void){

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

	printf("%lld\n", solve());

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(void){
int x[5];
for(int i=0;i<5;i++)
    cin>>x[i];
int k;cin>>k;
sort(x,x+5);
cout<<((x[4]-x[0])>k?":(":"Yay!")<<endl;
return 0;}

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

using namespace std;
using namespace atcoder;
using ll = long long;

int main() {
	int n, q;
	cin >> n >>q;
	fenwick_tree<ll> ft(n);
	rep(i, n) {
		ll s;
		cin >> s;
		ft.add(i, s);
	}
	rep(i, q) {
		bool t;
		cin >> t;
		if (!t) {
			int p;
			ll x;
			cin >> p >> x;
			ft.add(p, x);
		}
		else {
			int p, x;
			cin >> p >> x;
			cout << ft.sum(p, x) << endl;;
		}
	}
	return 0;
}


//
//  main.cpp
//  ITP1_6-A
//
//  Created by Saicj on 2015/07/14.
//  Copyright (c) 2015??´ saicj. All rights reserved.
//

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

int main(int argc, const char * argv[])
{

    int n;
    int index = 0;
    cin >> n;

    int numList[n];

    while (true) {
        int temp;

        cin >> temp;
        numList[index] = temp;
        index++;

        if (index >= n){
            break;
        }
    }

    for (int i = index-1; i >= 0; i--) {

        if (i == 0){
            printf("%d",numList[0]);
            break;
        }

        printf("%d ",numList[i]);
    }

    printf("\n");

    return 0;
}

#include<stdio.h>

int main(void){
int a,i;
scanf("%d",&a);
int x[a];
for(i=0;i<a;i++){
	scanf("%d",&x[i]);
}
for(i=0;i<a;i++){
	printf("%d",x[a-i-1]);
	if(i!=a-1){
	printf(" ");
	}else{
	printf("\n");
	}
}
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main(){
	ll n, t;
	cin >> n >> t;
	ll ans = n*t;
	ll last;
	cin >> last;
	for(int i = 1; i < n; ++i){
		int cur;
		cin >> cur;
		if(cur<(last+t)){
			ans += (cur-(last+t));
		}
		last = cur;
	}
	cout << ans;
	return 0;
}

#include<iostream>
#include<vector>
using namespace std;
int main(){
    int n,t;
    cin>>n>>t;
    vector<int>v(n);
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
    }
    int current_time=0;
    int result=0;
    for(int i=0;i<n;i++)
    {
        int start_time=v[i];
        current_time=v[i]+t;
        bool inside=false;
        while(i<n&&v[i]<current_time){
            current_time=v[i]+t;
            i++;
            inside=true;
        }
        if(inside)i--;
        result+=current_time-start_time;
    }
    cout<<result<<endl;
}


#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int k, t;
    cin >> k >> t;
    vector<int> a(t);
    for(int i=0; i<t; i++)cin >> a[i];
    sort(a.begin(), a.end(), greater<int>());

    cout << max(a[0] - 1 - (k - a[0]), 0) << endl;
}

#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
using ll = long long;
#define rep(i,n) for (ll i=0;i<n;i++)
using namespace std;

void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n,m;
    set<string> uni;
    cin >> n;
    vector<string> s(n);
    rep(i,n) {
        cin >> s[i];
        uni.insert(s[i]);
    }
    cin >> m;
    vector<string> t(m);
    rep(i,m) {
        cin >> t[i];
        uni.insert(t[i]);
    }

    ll ans = 0;

    for(string ss:uni){
        ll tmp = 0;
        rep(i,n){
            if(s[i]==ss) tmp++;
        }
        rep(i,m){
            if(t[i]==ss) tmp--;
        }

        ans = max(ans,tmp);
    }

    cout << ans << endl;

    return 0;
}


#include <iostream>
#include <vector>

std::vector<long long> common_divisors(long long a, long long b) {
	if (a > b) std::swap(a, b);
	std::vector<long long> ret(0), st(0);
	for (int i = 1; i <= a / i; i++) {
		if (a % i == 0) {
			if (b % i == 0) ret.push_back(i);
			if (b % (a / i) == 0 && i < a / i) st.push_back(a / i);
		}
	}
	while (st.size()) {
		ret.push_back(st.back());
		st.pop_back();
	}
	return ret;
}

bool is_prime(long long n) {
	if (n < 2) return false;
	if (n == 2) return true;
	if (n % 2 == 0) return false;
	for (int i = 3; i <= n / i; i += 2) {
		if (n % i == 0) return false;
	}
	return true;
}

int main() {
	long long a, b;
	std::cin >> a >> b;
	std::vector<long long> v = common_divisors(a, b);
	long long ans = 1;
	for (auto i : v) {
		if (is_prime(i)) ans++;
	}
	std::cout << ans << '\n';

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t a,b;
  cin >> a >> b;
  vector<pair<int64_t,int64_t>> res;
  int64_t n=gcd(a,b);
  for(int64_t i=2;i*i<=n;i++){
    if(n%i!=0)continue;
    int64_t s=0;
    while(n%i==0){
      s++;
      n/=i;
    }
    res.push_back({a,s});
  }
  if(n!=1)res.push_back({n,1});
  cout << res.size()+1 << endl;
}


#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
template <typename X, typename Y> istream& operator>>(istream& is, pair<X, Y>& p) { return is >> p.first >> p.second; }
enum class event_t { start, end, query };
struct event {
    event_t type;
    int pos, val;
};
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    vector<event> events;
    for(int i = 0; i < n; i++) {
        int s, t, x;
        cin >> s >> t >> x;
        events.push_back({event_t::start, s - x, x});
        events.push_back({event_t::end, t - x, x});
    }
    for(int i = 0; i < q; i++) {
        int d;
        cin >> d;
        events.push_back({event_t::query, d, i});
    }
    vector<int> ans(q);
    sort(events.begin(), events.end(), [](auto& e1, auto& e2) {
        return pair{e1.pos, e1.type} < pair{e2.pos, e2.type};
    });
    multiset<int> s;
    for(auto& e : events) {
        if(e.type == event_t::start) {
            s.insert(e.val);
        } else if(e.type == event_t::end) {
            s.erase(s.find(e.val));
        } else {
            ans[e.val] = s.empty() ? -1 : *s.begin();
        }
    }
    for(int i = 0; i < q; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}

#include <bits/stdc++.h>
#define mset(a, b) memset(a, b, sizeof(a))
#define mcpy(a, b) memcpy(a, b, sizeof(a))
using namespace std;
typedef long long LL;
const int N = 15;
const int MAXS = (1 << N) + 5;

template <typename T> inline void read(T &AKNOI) {
    T x = 0, flag = 1;
    char ch = getchar();
    while (!isdigit(ch)) {
        if (ch == '-') flag = -1;
        ch = getchar();
    }
    while (isdigit(ch)) {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    AKNOI = flag * x;
}

template <typename T> inline void cmax(T &x, T y) {
	if (x < y) x = y;
}

int n, m, S, g[N][N], bin[N], id[MAXS];
int sum[MAXS], dp[MAXS][N];

void init() {
	read(n); read(m);
	S = (1 << n);
	for (int i = 0; i < n; ++i) {
		bin[i] = (1 << i);
		id[bin[i]] = i;
	}
	for (int i = 1; i <= m; ++i) {
		int a, b, c;
		read(a); read(b); read(c);
		g[a - 1][b - 1] = g[b - 1][a - 1] = c;
	}
	for (int s = 1; s < S; ++s) {
		int u = id[s & (-s)];
		sum[s] = sum[s ^ bin[u]];
		for (int i = u + 1; i < n; ++i) {
			if ((s >> i) & 1) {
				sum[s] += g[u][i];
			}
		}
	}
}

void solve() {
	mset(dp, 0x80);
	int ans = dp[0][0];
	dp[1][0] = 0;
	for (int s = 1; s < S; ++s) {
		for (int i = 0; i < n; ++i) {
			for (int t = s; t; t = (t - 1) & s) {
				if (t & bin[i]) {
					cmax(dp[s][i], dp[s ^ t ^ bin[i]][i] + sum[t]);
				}
			}
			for (int j = 0; j < n; ++j) {
				if ((s >> j) & 1) continue;
				if (!g[i][j]) continue;
				cmax(dp[s | bin[j]][j], dp[s][i] + g[i][j]);
			}
		}
		if (s & bin[n - 1]) {
			cmax(ans, dp[s][n - 1]);
		}
	}
	printf("%d\n", sum[S - 1] - ans);
}

int main() {
	init();
	solve();
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
typedef vector<int>         vi;
const int mod = 1000000007;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,time,ans=0,flag=0;
    cin>>n>>time;
    int s,e;
    cin>>s;
    e=s+time;
    for(int i =1;i <n;i++){
        int inter;
        cin>>inter;

        if(inter <=e){
            e = inter + time;
           // cout<<"in between "<<e<<endl;
            flag=0;
        }
        else{
            ans = ans + (e-s);
            //cout<<"broken"<<" "<<ans<<endl;
            flag=1;
            s = inter;
            e = inter  + time;
        }

    }
    ans = ans + e-s ;
    cout<<ans<<endl;

}

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

#define rep(i,l,r) for(int i=(l);i<(r);i++)
#define pb push_back
#define fi first
#define se second

using ll = long long;
using G = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll MOD = 1000000007;

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

int main() {
	ll n, m; cin >> n >> m;
	ll t[200005];
	rep(i, 0, n) cin >> t[i];
	ll ans = 0;
	rep(i, 1, n){
		if((t[i]-t[i-1])>m) ans += m;
		else ans += t[i]-t[i-1];
	}
	ans += m;
	cout << ans << endl;
	return 0;
}


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

  int main() {
  double R = 0;
  cin >> R;//現在のレーティング
  double G = 0;
  cin >> G;//したいレーティング
  //(R + ans) / 2 = G
  //R + ans = 2*G
  double ans  = 0;
  ans = 2*G - R;
    cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい
// https://github.com/atcoder/live_library
// cppdbg: test.exeのterminalに標準入力を打てる

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
#define ub(a,x) (upper_bound(ALL(a),x)-a.begin())
#define lb(a,x) (lower_bound(ALL(a),x)-a.begin())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<ll, vector<ll>, greater<ll> > gpq; //逆順priority_queue
typedef priority_queue<ll> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
   int R,G;cin>>R>>G;
   cout<<G+G-R<<endl;
}


#include <bits/stdc++.h>
#define MAXN 100010
#define pii pair<int,int>
#define ff first
#define ss second
#define ll long long
#define in_range(x, y, n) (x >= 0 and x<n and y >=0 and y<n)
using namespace std;
const int mod = 1e9 + 7;

int main (){
    string s;

    cin >> s;

    int n = s.size();

    for (int i=0; i<n-2; i++){
        if (s[i+1] == s[i] || s[i+2] == s[i]){
            cout << i+1 << " " << i+3 << endl;
            return 0;
        }
    }

    if (s[n-1] == s[n-2]){
        cout << n-1 << " " << n << endl;
    }
    else cout << "-1 -1" << endl;

    return 0;
}

#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#define ll long long
#define maxn 1010
inline ll read()
{
	ll x=0; char c=getchar(),f=1;
	for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
	for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
	return x*f;
}
inline void write(ll x)
{
	static int buf[20],len; len=0;
	if(x<0)x=-x,putchar('-');
	for(;x;x/=10)buf[len++]=x%10;
	if(!len)putchar('0');
	else while(len)putchar(buf[--len]+'0');
}
inline void writeln(ll x){write(x); putchar('\n');}
inline void writesp(ll x){write(x); putchar(' ');}
const char mat4[4][5]={"aacd","bbcd","cdaa","cdbb"};
const char mat5[5][6]={"aabba","bcc.a","b..cb","a..cb","abbaa"};
const char mat6[6][7]={"aabcc.","b.b..c","baa..c","cc.aab","..cb.b","..cbaa"};
const char mat7[7][8]={"aa.bb.a",".cc..ca","b.dd.c.","b...d.b",".c..d.b","ac..cc.","a.bb.aa"};
char mat[maxn][maxn];
int n;
int main()
{
	n=read();
	if(n<=2){
		puts("-1"); return 0;
	}
	if(n==3){
		puts("aab\nb.b\nbaa");
		return 0;
	}
	memset(mat,'.',sizeof(mat));
	for(int i=0;i<=n-8;i+=4){
		for(int j=0;j<4;j++)
			for(int k=0;k<4;k++)
				mat[i+j][i+k]=mat4[j][k];
	}
	switch(n%4)
	{
		case 0:{
			for(int i=0;i<4;i++)
				for(int j=0;j<4;j++)
					mat[n-4+i][n-4+j]=mat4[i][j];
			break;
		}
		case 1:{
			for(int i=0;i<5;i++)
				for(int j=0;j<5;j++)
					mat[n-5+i][n-5+j]=mat5[i][j];
			break;
		}
		case 2:{
			for(int i=0;i<6;i++)
				for(int j=0;j<6;j++)
					mat[n-6+i][n-6+j]=mat6[i][j];
			break;
		}
		case 3:{
			for(int i=0;i<7;i++)
				for(int j=0;j<7;j++)
					mat[n-7+i][n-7+j]=mat7[i][j];
			break;
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++)
			putchar(mat[i][j]);
		putchar('\n');
	}
	return 0;
}


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

void solve(int delta_x){
	int number_of_rectangle, height_of_rectangle;
	int integer = 0;
	number_of_rectangle = 600 / delta_x;
	for(int i = 1;i < number_of_rectangle;i++){
		height_of_rectangle = (delta_x * i) * (delta_x * i);
		integer += height_of_rectangle * delta_x;
	}
	cout << integer << endl;
}

int main(){
	int number_of_rectangle, delta_x;
	while(cin >> delta_x){
		solve(delta_x);
	}
	return 0;
}

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

#define MAX 256
#define S(x) (x*x)

int f(int z){
	if (z < 10)return 1;
	return 1 + f(z / 10);
}

int main(void){

	int ans[MAX];
	for (int i = 0; i < MAX; i++){
		ans[i] = 0;
	}

	int d;
	int i = 0;

	while (scanf("%d", &d) != EOF){
		for (int j = d; j <= 600 - d; j += d){
			ans[i] += S(j)*d;
		}
		i++;
	}

	for (int j = 0; j < i; j++){
		printf("%d\n", ans[j]);
	}

	return 0;
}


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

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

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

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

  void dijkstra(ll s){
    rep(i,V){
      d[i] = INF;
    }
    d[s] = 0;
    priority_queue<P,vector<P>, greater<P> > que;
    que.push(P(0,s));
    while(!que.empty()){
      P p = que.top(); que.pop();
      ll v = p.second;
      if(d[v]<p.first) continue;
      for(auto e : G[v]){
        if(d[e.to]>d[v]+e.cost){
          d[e.to] = d[v]+e.cost;
          que.push(P(d[e.to],e.to));
        }
      }
    }
  }
};
class UnionFind
{
public:
  int par[100005];
  int depth[100005];
  int nGroup[100005];

  UnionFind(int n) {
    init(n);
  }

  void init(int n) {
    for(int i=0; i<n; i++) {
      par[i] = i;
      depth[i] = 0;
      nGroup[i] = 1;
    }
  }

  int root(int x) {
    if(par[x] == x) {
      return x;
    } else {
      return par[x] = root(par[x]);
    }
  }

  bool same(int x, int y) {
    return root(x) == root(y);
  }

  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if(x == y) return;

    if(depth[x] < depth[y]) {
      par[x] = y;
      nGroup[y] += nGroup[x];
      nGroup[x] = 0;
    } else {
      par[y] = x;
      nGroup[x] += nGroup[y];
      nGroup[y] = 0;
      if(depth[x] == depth[y])
        depth[x]++;
    }
  }
};
const ll MAX = 510000;
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;
}

vector<ll> depth;
vector<ll> f;
vector<ll> g;
void dfs(const Graph &G, ll v, ll p, ll d) {
    depth[v] = d;
    for (auto nv : G[v]) {
        if (nv == p) continue; // nv が親 p だったらダメ
        dfs(G, nv, v, d+1);
    }

    // 帰りがけ時に、部分木サイズを求める
    f[v] = 1;
    g[v] = 1;// 自分自身
    for (auto c : G[v]) {
        if (c == p) continue;
        f[v]*=g[c];
        f[v]%=MOD;
        g[v]*=f[c];
        g[v]%=MOD;
        }
    f[v]+=g[v];
    f[v]%=MOD;
}

int main() {
ll n,m,k; cin>>n>>m>>k;
ll ca = 0;
ll q = 1;
COMinit();
for(ll i=0; i<n-k-1; i++){
q*=m-1;
q%=MOD;}
q*=m;
q%=MOD;
for(ll i=k; i>0; i--){
ll c = 1;
c*=(COM(n-1,i))%MOD;
//c*=m;
//c%=MOD;
c*=q;
c%=MOD;
q*=(m-1);
q%=MOD;
ca+=c;
ca%=MOD;}
//cout << q << endl;
//q*=m;
//q%=MOD;
//cout << q << endl;
ca+=q;
ca%=MOD;
//ll p = 1;
//for(ll i =1; i<100; i++){
//p*=99;
//p%=MOD;
//}
//cout << p << endl;
//p*=100;
//p%=MOD;
cout << ca << endl;}

#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>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int N, T;
    cin >> N >> T;

    vector<P> AB(N);
    rep(i, N) {
        int A, B;
        cin >> A >> B;
        AB[i] = {A, B};
    }

    sort(all(AB));

    vector<vector<int>> dp(N + 1, vector<int>(7000, -1));
    dp[0][0] = 0;

    rep(i, N) {
        rep(j, 7000) {
            if (dp[i][j] != -1) {
                if (j < T) chmax(dp[i + 1][j + AB[i].first], dp[i][j] + AB[i].second);
                chmax(dp[i + 1][j], dp[i][j]);
            }
        }
    }

    int ans = 0;
    rep(i, dp[N].size()) {
        chmax(ans, dp[N][i]);
    }

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

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

int32_t main()
{
    int d,g;
    cin>>d>>g;

    vector<array<int,2>> s(d);
    for(int i=0;i<d;i++)
    cin>>s[i][0]>>s[i][1];
     int ans=INT_MAX;
    for(int i=0;i<(1<<d);i++)
    {
        int left=-1,sum=0,count=0;
        for(int j=0;j<d;j++)
        {
            if((i>>j)&1)
                sum+=100*(j+1)*s[j][0]+s[j][1],count+=s[j][0];
            else
            left=j;
        }
        if(sum<g)
        {
            int c=100*(left+1);
            int need=(g-sum+c-1)/c;
            if(need>=s[left][0])
            continue;
            count+=need;
        }
        ans=min(ans,count);
    }
    cout<<ans<<endl;

}


#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef pair<int,int> pr;
int main() {
	// your code goes here
	int w,h;
	while(cin >> w >> h && w!=0){
	int xs,ys,xg,yg,n,m,s,sum,c,d,x,y;
	int dx[]={0,1,-1,0},dy[]={1,0,0,-1};
	cin >> xs>>ys>>xg>>yg >> n;
	bool map[102][102]={};
	int color[102][102]={};
	queue<pr> q;
		color[xs][ys]=10;
		for(int i=0;i<n;i++){
			cin >> c >> d >>x >> y;
			for(int j=0;j<2+d*2;j++)
				for(int k=0;k<4-d*2;k++)
					color[x+k][y+j]=c;
		}
		map[xs][ys]=true;
		q.push(pr(xs,ys));
		while(!q.empty()){
			int f=q.front().first,s=q.front().second;
			q.pop();
			for(int i=0;i<4;i++){
					if(color[f][s]==color[f+dx[i]][s+dy[i]] && !map[f+dx[i]][s+dy[i]]){
						q.push(pr(f+dx[i],s+dy[i]));
						map[f+dx[i]][s+dy[i]]=true;
					}
			}
		}
		if(map[xg][yg])
		cout << "OK" << endl;
		else
		cout << "NG" << endl;
	}
	return 0;
}

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

int main()
{
  int n, m;
  int x[20];
  int y[20];
  char d[30];                   // ??????
  int s[30];                    // ?§???????

  bool grid[21][21];

  while (1)
  {
    cin >> n;
    if (n == 0) return 0;
    for (int i=0;i<n;i++) cin >> x[i] >> y[i];
    cin >> m;
    for (int i=0;i<m;i++) cin >> d[i] >> s[i];

    for (int i=0;i<21;i++)
      for (int j=0;j<21;j++) grid[i][j]=false;

    int posx = 10, posy = 10;
    grid[posx][posy]=true;

    for (int i=0;i<m;i++)
    {
      for (int k=0;k<s[i];k++)
      {
        switch (d[i])
        {
        case 'E': posx = min(posx+1, 20); break;
        case 'W': posx = max(posx-1, 0); break;
        case 'N': posy = min(posy+1, 20); break;
        case 'S': posy = max(posy-1, 0); break;
        }
        grid[posx][posy]=true;
      }
    }

    int r=n;
    for (int i=0;i<n;i++)
      if (grid[x[i]][y[i]]) r--;
    if (r==0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}


#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <bitset>
#include <stack>
//#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)

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;
    }
}
int main(void)
{
    int x;
    string s;
    cin >> x;
    s = to_string(x);
    int sum = 0;
    for (int i = 0; i < s.length(); i++)
    {
        sum += s[i] - '0';
    }
    if (x % sum == 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

#include<iostream>
#include<cstdlib>
#include<cstring>
#include<string>

using namespace std;

typedef long long ll;

int main() {
	string s;
	cin >> s;
	int len = s.size();
	int cnts = 0, cntst = 0;
	for (int i = 0; i < len; ++i) {
		if (s[i] == 'S')
			cnts++;
		else if (s[i] == 'T' && cnts != 0) {
			cnts--;
			cntst += 2;
		}
	}
	cout << len - cntst << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned int
#define test int t;cin>>t; while(t--)
#define en '\n'
typedef pair<int, int>     pii;
typedef pair<char, int>    pci;
typedef pair<char, char>   pcc;
typedef vector<pii>       vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define sz(x) (int)x.size()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007

void __print(int x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
// You should only debug a pair of simple data types. For example,
// the debug won't work if one of pair's elements is collection type
// (std::vector, std::map, std::set...).
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

// bool check_prime(int n)  return whether a number is prime or not O(sqrt(N));
// int BE(int x,int n,int m)  return x^n%m; O(logN);
// void sieve()  from number 1-1000001 saare prime store kar lega  in bool is_prime[1000001] array
// vector<int> z_array(string s)  return vector which is Z-array of string s;
// vector<int> lps(string s)      return vector which is lps array of string s;
// int power(int x,int n) return x^n; O(logN);
// using_ordered_set (template for using ordered set , replace first 2 lines of this page with this code..);
const int gf = 1e6 + 9;

bool check_prime(long long n)
{
	int flag = 0;
	for (long long i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			flag = 1;
			break;
		}
	}
	if (n == 1)
		return false;
	else if (flag == 0 || n == 2 || n == 3)
	{
		return true;
	}
	else
	{
		return false;
	}

}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________

	int n;
	cin >> n;
	vi v;
	rep(i, 1, 55555)
	{
		if (check_prime(i) && i % 5 == 1)
		{
			v.pb(i);
		}
	}
	debug(sz(v));
	zip(i, 0, n)
	cout << v[i] << " ";

	return 0;
}

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

int main(){
	int k;
  cin>>k;
  string palabra;
  cin>>palabra;
  int tamano;
  tamano=palabra.size();
    if (tamano>k){
          for(int i=0;i<k;i++){
          cout<<palabra[i];
          }
          cout<<"...";
      }
      else{
        cout<<palabra<<endl;
    }

}


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

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int  MOD=1000000007;
const int  INF= int(1e9);
const int  MAX =1007;
string a,b;
int n,m;
int dp[MAX][MAX];

int solve ( int n,int m) {
    if(dp[n][m] != -1) {
        return dp[n][m];
    }
    else if(m == 0) {
        return dp[n][m]=n;
    }
    else if(n == 0) {
        return dp[n][m]=m;
    }
    if (a[n-1] == b[m-1] ) {
        return dp[n][m]=solve(n-1,m-1);
    }
    dp[n][m] = 1 + min(  solve(n-1,m-1) , min ( solve(n-1,m) ,solve(n,m-1) ) );
    return dp[n][m];
}

int main()
{
    ios_base::sync_with_stdio(false);
    for(int i=0;i<MAX;i++) {
        for(int j=0;j<MAX;j++) {
            dp[i][j]=-1;
        }
    }
    cin>>a;
    cin>>b;
    n=a.size(),m=b.size();
    solve(n,m);
    cout<<dp[n][m]<<"\n";

    return 0;

}

//Edit distance

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

#define MAX 1000

string s,t;
int dp[MAX+1][MAX+1];

int d(int i,int j){
	if(s[i]==t[j]) return 0;
	else return 1;
}

int main(){
	cin>>s>>t;
	for(int i=0;i<=s.size();++i) for(int j=0;j<=t.size();++j){
		if(i==0||j==0){
			dp[i][j]=max(i,j);
			continue;
		}
		dp[i][j]=min(min(dp[i-1][j],dp[i][j-1])+1,dp[i-1][j-1]+d(i-1,j-1));
	}
	cout<<dp[s.size()][t.size()]<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define ld long double
#define fi first
#define se second
#define all(uiet) uiet.begin(),uiet.end()
#define read(UIET) for(int i = 0; i < n; ++i) cin >> UIET[i]
#define out(UIET) for(int i = 0; i < n; ++i) cout << UIET[i] << " "
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vpp vector<pair< int, int > >
#define pll pair<int , int >
#define ppll pair < pll , pll >
#define debug(n1) cout << n1 << endl
#define len(a) ((int) (a).size())
#define endl "\n"
#define mod 1000000007
const int INF=(1LL<<60)-1;
bool isPerfectSquare(long double x) {
    long double sr = sqrt(x);
    return ((sr - floor(sr)) == 0);
}
bool isPrime(int x){
    for(int i = 2; i * i <= x; ++i){
        if(x % i == 0) return 0;
    }
    return 1;
}
int fun(int n){
    if(n & 1) return 3 * n + 1;
    else return n/2;
}
int32_t main(){
    SPEED;
    string s;
    cin >> s;
    int ans = INF;
    for(int i = 0; i < (len(s) - 2); ++i){
        string temp = "";
        temp += s[i];
        temp += s[i + 1];
        temp += s[i + 2];
        int res = stoi(temp);
        ans = min(ans, abs(res - 753));
    }
    cout << ans ;
}

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

typedef long long ll;

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

///promy_pompom
//hello world


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef pair<l_l,ll> lll;
typedef vector<string> vs;
const ll dx[4]={1,-1,0,0};
const ll dy[4]={0,0,1,-1};
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
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;
}
//グリッド：（典型）dp,dfs,bfs,最短経路,その他
ll n;
bool ok(vector<l_l> ls){
    ll h=0;
    rep(i,sz(ls)){
        ll b=ls[i].fi;
        if(h+b<0)return false;
        h+=ls[i].se;
    }
    return true;
}
int main(){
    cin>>n;
    vector<l_l> ls,rs;
    ll tot=0;
    rep(i,n){
        string s;cin>>s;
        ll h=0,b=0;
        rep(j,sz(s)){
            if(s[j]=='(')h++;
            else h--;
            b=min(b,h);
        }
        tot+=h;
        if(h>=0)ls.pb({b,h});
        else rs.pb({b-h,-h});
    }
    sort(ls.rbegin(),ls.rend());
    sort(rs.rbegin(),rs.rend());
    if(ok(ls)&&ok(rs)&&tot==0){
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
    return 0;
}

#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 main(){
  int N;
  cin>>N;
  int A[N];
  REP(i,N){
    cin>>A[N-1-i];
  }

  vector<int> L(N+1,MOD);
  L[0]=-1;

  REP(i,N){
    if(A[i]<L[0]){
      L[0]=A[i];
      continue;
    }
    auto it=upper_bound(ALL(L),A[i]);
    int index=it-L.begin();

    if(L[index-1]==A[i]) L[index]=A[i];
    else L[index--]=A[i];
  }

  RREP(i,N){
    if(L[i]==MOD){
      co(i-1);
      return 0;
    }
  }
  co(N);
  return 0;
}


// Written by newbiechd
#include <cstring>
#include <iostream>
#include <string>

const int maxN = 13;
int n;

const std::string ans[][7] = {
  {
    "aabc",
    "ddbc",
    "efgg",
    "efhh"
  },
  {
    "aabbd",
    "ccf.d",
    "eefgg",
    "..hij",
    "..hij"
  },
  {
    "aabbcc",
    "ddeeff",
    "ghi...",
    "ghi...",
    "...jkl",
    "...jkl"
  },
  {
    "aabbcc.",
    "ddee..h",
    "ffgg..h",
    "....ijk",
    "....ijk",
    "....lmn",
    "....lmn"
  }
};

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

  if (n < 3) {
    printf("-1\n");
    return 0;
  }
  if (n == 3) {
    std::cout << "aa.\n..a\n..a\n";
    return 0;
  }

  int k = (n & 3) + 4;
  for (int i = 0; i < n - k; ++i) {
    std::string str(n, '.');
    str.replace(i / 4 * 4, 4, ans[0][i % 4]);
    std::cout << str << '\n';
  }
  for (int i = n - k; i < n; ++i) {
    std::string str(n, '.');
    str.replace(n - k, k, ans[k - 4][i + k - n]);
    std::cout << str << '\n';
  }
  return 0;
}

#include<iostream>
using namespace std;
int main(){
	long long int dp[31];
	dp[0]=1;
	dp[1]=1;
	dp[2]=2;
	for(int i=3;i<=30;i++)dp[i]=dp[i-1]+dp[i-2]+dp[i-3];
	int n;
	while(cin>>n,n){
		long long int ans=dp[n];
		ans=(ans-1)/10+1;
		ans=(ans-1)/365+1;
		cout<<ans<<endl;
	}
}


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

using namespace std;

const int N = 1e6 + 1;
const int MOD = 1e9 + 7;

int mul(int a, int b) {
	return 1LL * a * b % MOD;
}

int sub(int a, int b) {
	return (a - b + MOD) % MOD;
}

int p_col[N];
int p_row[N];

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

	fill(p_col, p_col + N, -1);
	fill(p_row, p_row + N, -1);

	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		x--;
		p_row[x] = i;
	}
	for (int i = 0; i < m; i++) {
		int x;
		cin >> x;
		x--;
		p_col[x] = i;
	}
	int ans = 1;
	int cnt = 0;
	int free_col = 0;
	int free_row = 0;
	for (int i = n * m - 1; i >= 0; i--) {
		if (p_row[i] != -1 && p_col[i] != -1) {
			free_row++;
			free_col++;
		} else if (p_row[i] != -1) {
			ans = mul(ans, free_col);
			free_row++;
		} else if (p_col[i] != -1) {
			ans = mul(ans, free_row);
			free_col++;
		} else {
			ans = mul(ans, sub(mul(free_col, free_row), cnt));
		}
		cnt++;
	}
	cout << ans << '\n';
}

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

void ins() {}
template<class T,class... Rest>void ins(T& v,Rest&... rest){cin>>v;ins(rest...);}
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(int i=0,_i=(n);i<_i;++i)
#define _rep3(i,a,b) for(int i=(a),_i=(b),_ii=(b)>(a)?1:-1;abs(_i-i)>0;i+=_ii)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))

signed main() {
  ll N, M, V, P;
  ins(N, M, V, P);

  vector<ll> A(N);
  rep(i, N)
    cin >> A[i];
  all(sort, A); all(reverse, A);

  int ok = -1, ng = N;
  auto f = [&](int mid) {
    if (mid < P) return true;
    if (A[P-1] > A[mid]+M) return false;

    ll tmp = 1LL * ((N-mid)+P-1) * M;
    rep(i, P-1, mid)
      tmp += min(1LL*M, max(0LL, A[mid]+M-A[i]));
    return tmp >= M*V;
  };
  while (abs(ok - ng) > 1) {
    int mid = ok + (ng-ok) / 2;
    (f(mid) ? ok : ng) = mid;
  }
  cout << ok+1 << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rep3(i, n) for (int i = 1; i < (int)(n+1); i++)
#define rep4(i, s, n) for (int i = (s); i < (int)(n+1); i++)
#define repr(i,n) for (int i = (n-1); i>=0;i--)
#define repr3(i,n) for(int i = (n);i>0;i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
#define INF const ll INF = 1001001001;
#define PI const ld PI = 3.14159265358979323846;

const int MAX = 510000;
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;
}

vector<vector<long long>> comb(int n, int r) {
  vector<vector<long long>> v(n + 1,vector<long long>(n + 1, 0));
  ll div=(ll)powl(10,9)+7;
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++) {
    for (int k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k])%div;
    }
  }
  return v;
}
vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

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

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}

int main() {
    ll N,M;
    cin >> N>>M;
    //pairの書き換えが煩雑であるので、素数リストと指数連想配列に分ける
   map<ll,ll> prime_count;
   vector<ll> prime_list;

    //resに素数のペア(素数、その素数の指数）の配列が入る
    const auto  &res = prime_factorize(M);

   rep(i,res.size()){
       if(prime_count[res[i].first]==0){
           prime_list.push_back(res[i].first);
       }
       prime_count[res[i].first]+=res[i].second;
   }
   // 前処理
    COMinit();

    ll ans=1;
    rep(i,prime_list.size()){
        ans*=COM(N+prime_count[prime_list[i]]-1,N-1);
        ans%=MOD;
    }
    cout<<ans<<endl;
    return 0;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  return res;

}

int main(){

  nCrprep();

  ll n,m; cin >> n >> m;

  auto vec = prime_factorize(m);

  ll ans = 1;

  for(auto p : vec){
    ll x = p.second;

    ans *= nCr(n-1+x,x);
    ans = mod(ans);
  }

  cout << ans << endl;

}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair<pair<int, int>, int> p;

#define MOD 1000000007

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() {
	cin.tie(0);
    ios::sync_with_stdio(false);

    ll mod = pow(10, 9) + 7;

    ll N, M;
    cin >> N >> M;

    map<ll, ll> a;

    for(ll i = 2LL; i * i <= M; i++) {
        while(M % i == 0) {
            a[i]++;
            M /= i;
        }
    }

    if(M != 1) a[M]++;

    ll ans = 1LL;

    for(auto i = begin(a); i != a.end(); i++) {
        ll c = 1LL;
        for(ll j = 0LL; j < i -> second; j++) {
            c *= (N + j) % mod;
            c %= mod;
            c *= modpow(j + 1LL, mod - 2LL, mod) % mod;
            c %= mod;
        }
        ans *= c;
        ans %= mod;
    }

    cout << ans % mod << endl;
}

#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1000000000000000000

using namespace std;
ll power(ll n, ll k){
  ll res = 1;
  while(k > 0){
    if (k & 1)
      res = res * n % MOD;
    n = n * n % MOD;
    k >>= 1;
  }
  return res;
}

ll genfact(ll n, ll k){

  ll res = 1;
  k--;
  while (k >= 0){
    res = (res * (n - k)) % MOD;
    k--;
  }

  return res;
}

ll inv(ll n){
  return power(n, MOD - 2);
}

ll fact(ll n){
  return genfact(n, n - 1);
}

ll nck(ll n, ll k){
  if (k == 0)
    return 1;
  if (n <= 0)
    return 0;

  return ((genfact(n, k) % MOD) * inv(fact(k))) % MOD;
}

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

  ll ans = 0;

  ll t = nck(n*m-2,k-2);
  for (ll j = 1; j < m; j++){
    ans += j*(m-j) % MOD * n % MOD *n % MOD * t % MOD;
    ans = (ans % MOD);
  }
  for (ll i = 1; i < n; i++){
    ans += i*(n-i) % MOD * m % MOD *m % MOD * t % MOD;
    ans = (ans % MOD);
  }
  cout << ans << endl;

  return 0;
}


#define _USE_MATH_DEFINES

#include <iostream>	//cin, cout
#include <vector>	//vector
#include <algorithm> //sort,min,max,count
#include <string>	//string,getline
#include <ios>		//fixed
#include <iomanip>	//setprecision
#include <utility> //swap
#include <cstdlib>	//abs(int)
#include <cmath>	//sqrt
#include <sstream>	//stringstream,getline
#include <cmath>	//ceil,M_PI
#include <numeric>	//gcd

using namespace std;

int main() {

	string S;
	cin >> S;

	switch (S[2]) {
	case 'N': if (S[0] == 'S') {
		cout << 7 << endl;
	}
			else {
		cout << 6 << endl;
	}
			break;
	case 'E': cout << 5 << endl; break;
	case 'D': cout << 4 << endl; break;
	case 'U': cout << 3 << endl; break;
	case 'I': cout << 2 << endl; break;
	case 'T': cout << 1 << endl; break;
	}

	return 0;

}

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

int main() {
  string S;
  cin >> S;
  vector<string> V { "SUN","MON","TUE","WED","THU","FRI","SAT" };
  int tmp = 0;
  for (int i = 0; i < V.size(); i++) {
    if (V.at(i) == S) tmp = i;
  }
  cout << 7 - tmp << "\n";
}


#include<bits/stdc++.h>
using namespace std;
//#include<ext/rope>
//using namespace __gnu_cxx
//#include<ext/pb_ds/priority_queue.hpp>
//using namespace __gnu_pbds;
#define lowbit(x) (x&-x)
#define pb push_back
#define empb emplace_back
#define all(x) (x).begin(),(x).end()
#define clr(a,b) memset(a,b,sizeof(a))
#define caze(T) for(cin>>T;T;T--)
#define inf (1<<29)
#define Endl ('\n')
#define fi first
#define se second
#define db double
#define ldb long double
#define ll long long
#define pii pair<int,int>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pll pair<ll,ll>
#define ull unsigned long long
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
inline char nc() {
	#define SZ 1000000
	static char buf[SZ], *p1, *p2;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,SZ,stdin),p1==p2)?EOF:*p1++;
}
template<typename T>
inline int scan(T &x) {
	char c, sign=1;
	while(!isdigit(c=nc())&&c!=EOF)if(c=='-')sign*=-1;
	if(c==EOF) return EOF;
	for(x = 0; isdigit(c); c = nc())
		x = (x<<1) + (x<<3) + (c&15);
	return x *= sign, 1;
}
template<typename T, typename...Args>
inline int scan(T &x, Args&...args) {
	return scan(x), scan(args...);
}
const int N=1<<18;
const int mod=1000000007;
int f[N],ivf[N];
int qp(int a,int b)
{
	int ret=1;
	for(;b;b>>=1,a=1LL*a*a%mod)
		if(b&1) ret=1LL*ret*a%mod;
	return ret;
}
int C(int n,int m){int ret=1LL*f[n]*ivf[n-m]%mod;return 1LL*ret*ivf[m]%mod;}
int go(int n,int m){return C(n+m-2,m-1);}
int main()
{
	f[0]=1;
	for(int i=1;i<N;++i)
		f[i]=1LL*f[i-1]*i%mod;
	ivf[N-1]=qp(f[N-1],mod-2);
	for(int i=N-2;~i;--i)
		ivf[i]=1LL*ivf[i+1]*(i+1)%mod;
	int n,m,a,b;
	while(cin>>n>>m>>a>>b)
	{
		int ans=0;
		for(int i=1;i<=n-a;++i)
		{
			int tp=1LL*go(i,b)*go(n-i+1,m-b)%mod;
			(ans+=tp)%=mod;
		}
		cout<<ans<<Endl;
	}
}

#include <iostream>
using namespace std;
const long long MOD = 1e9+7;
//aのMODbでの逆元
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;
}
long long combi(int n,int k){
    k = min(k,n-k);
    long long p = 1;
    for(int i = n;i>=n-k+1;i--){
        p*=i;
        p%=MOD;
    }
    for(int i = 0;i<k;i++){
        p*=modinv(i+1,MOD);
        p%=MOD;
    }
    return p;
}
int main(){
    long long h,w,a,b;
    cin >> h >> w >> a >> b;
    long long comb1 = 1;
    long long comb2 = combi(w+h-b-2,w-b-1);
    long long ans = 0;
    for(int i = 0;i<h-a;i++){
        ans+=((comb1*comb2)%MOD);
        ans%=MOD;
        comb1*=(b+i);
        comb2*=(h-1-i);
        comb1%=MOD;
        comb2%=MOD;
        comb1*=modinv(i+1,MOD);
        comb2*=modinv(w+h-b-2-i,MOD);
        comb1%=MOD;
        comb2%=MOD;
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>

using namespace std;

template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }

#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
#define sp(x) fixed << setprecision(x)
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

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

const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
}

void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}

}

void solve()
{
	int n;
	cin >> n;
	ll a[n];
	vector<ll> p;
	rep(i, n) cin >> a[i];
	sort(a, a + n);
	rep(i, n){
		if(i && a[i] == a[i - 1]) p.pb(a[i++]);
	}
	sort(p.rbegin(), p.rend());
	if(sz(p) <= 1) cout << 0;
	else cout << p[0] * p[1];
}

int main()
{
	// freopen("crosses.in", "r", stdin);
	// freopen("crosses.out", "w", stdout);
    Red;
  	int T = 1;
  	// cin >> T;
  	for(int i = 1; i <= T; ++i){
  		solve();
  	}
  	return 0;

}

#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

vector<ll> & T(vector<ll> &ret,vector<ll> A,vector<ll> B){
    for(int i=0;i<B.size();i++){
        ret[i]=A[B[i]];
    }
    return ret;
}

int main(){
    ll n;
    cin>>n;
    vector<ll> x(n);
    for(auto &i:x){cin>>i;}
    ll m,k;
    cin>>m>>k;
    vector<ll> A(m);
    for(auto &i:A){cin>>i;}
    vector<ll> a(n-1);
    vector<ll> ans(n-1);
    for(int i=0;i+1<n;i++){ans[i]=a[i]=i;}
    for(int i=0;i<m;i++){
        A[i]--;
        swap(a[A[i]-1],a[A[i]]);
    }
    while(k>0){
        if(k&1){T(ans,ans,a);}
        T(a,a,a);
        k>>=1;
    }
    vector<ll> dp(n,x[0]);
    for(int i=0;i<n-1;i++){
        dp[i+1]=dp[i]+x[ans[i]+1]-x[ans[i]];
    }
    for(int i=0;i<n;i++){
        cout<<dp[i]<<endl;
    }

    return 0;
}


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

int main(){
  long long N;
  cin >> N; // 1 <= N <= 1+10^15 1000000000000001
  string abc = "abcdefghijklmnopqrstuvwxyz";
  string name = "";
  for(int i = 0; i < 11; i++){
    name = abc[(N-1)%26]+name;
    N = (N-1)/26;
    if(N == 0) break;
  }
  cout << name << endl;
}

#include <stdio.h>

#define LL long long
#define ULL unsigned long long
#define UI unsigned int
#define UC unsigned char
#define UL unsigned long

int main() {
	LL llMax = 1000000000000001, llN;
	scanf("%lld", &llN);
	//a = 97
	int iChar[20], iCnt = 0;
	llN--;
	while (iCnt < 20) {
		iChar[iCnt++] = llN % 26;
		if (llN < 26)
			break;
		llN -= (iChar[iCnt - 1] + 1);
		llN /= 26;
		//printf("%lld\n", llN);
	}
	while (iCnt-- > 0) {
		printf("%c", (char)(iChar[iCnt] + 97));
	}

	return 0;
}


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

int H, W;
int a[510][510];
vector<T> ans;

signed main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> H >> W;
    rep(i, H) rep(j, W) cin >> a[i][j];
    rep(i, H) {
        if (i%2==0) {
            rep(j, W) {
                if (i==H-1 && j==W-1) continue;
                int ni, nj;
                if (j==W-1) ni = i+1, nj = W-1;
                else ni = i, nj = j+1;
                if (a[i][j]%2==1) {
                    ans.pb(make_tuple(i+1, j+1, ni+1, nj+1));
                    a[ni][nj]++;
                }
            }
        }
        else {
            for (int j=W-1; j>=0; j--) {
                if (i==H-1 && j==0) continue;
                int ni, nj;
                if (j==0) ni = i+1, nj = 0;
                else ni = i, nj = j-1;
                if (a[i][j]%2==1) {
                    ans.pb(make_tuple(i+1, j+1, ni+1, nj+1));
                    a[ni][nj]++;
                }
            }
        }
    }
    cout << ans.size() << endl;
    rep(i, ans.size()) cout << get<0>(ans[i]) << " " << get<1>(ans[i]) << " " << get<2>(ans[i]) << " " << get<3>(ans[i]) << endl;
}

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

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

const int N = 501;

int a[N][N];

struct Move {
  int x1, y1, x2, y2;
};

            // up, left, down, right
int dx[4] = {0, -1, 0, 1}, dy[4] = {-1, 0, 1, 0};

void solve() {
  int h, w; scanf("%d%d", &h, &w);
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      scanf("%d", a[i]+j);
    }
  }
  vector<Move> v;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (a[i][j]%2 == 0) continue;
      for (int k = 0; k < 4; ++k) {
	if (i+dy[k] < 0 || i+dy[k] >= h || j+dx[k] < 0 || j+dx[k] >= w) continue;
	if (a[i+dy[k]][j+dx[k]]%2==0) continue;
	v.push_back({i+1, j+1, i+dy[k]+1, j+dx[k]+1});
	--a[i][j];
	++a[i+dy[k]][j+dx[k]];
	break;
      }
      if (a[i][j]%2 == 0) continue;
      for (int k = 2; k < 4; ++k) {
	if (i+dy[k] < 0 || i+dy[k] >= h || j+dx[k] < 0 || j+dx[k] >= w) continue;
	v.push_back({i+1, j+1, i+dy[k]+1, j+dx[k]+1});
	--a[i][j];
	++a[i+dy[k]][j+dx[k]];
	break;
      }
    }
  }
  printf("%d\n", v.size());
  for (const auto &e: v) {
    printf("%d %d %d %d\n", e.x1, e.y1, e.x2, e.y2);
  }
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


#include <iostream>
using namespace std;

void bubble(int *pbuff, int n){
	int v;
	int j;
	int flag=1;
	int i=0;
	int count=0;
	while(flag){
		flag=0;
		for(int i=n-1;j<i;i--){
			if(pbuff[i]<pbuff[i-1]){
				v=pbuff[i];
				pbuff[i]=pbuff[i-1];
				pbuff[i-1]=v;
				count++;
			}
			flag=1;
		}
		j++;
	}
		for(int j=0;j<n-1;j++) cout << pbuff[j]<<" ";
		cout << pbuff[n-1]<<endl;
		cout << count<<endl;
	return ;
}

int main()
{
	int n;
	cin>> n;
	int buff[100];
	for(int j=0;j<n;j++) cin >> buff[j];
	bubble(buff,n);
	return 0;
}

//FIRST THINK THEN CODE.

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

//#define MOD 998244353
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define FOR(i,n)  for(ll i=0;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define rev(p) reverse(p.begin(),p.end());
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define popcount(x) __builtin_popcountll(x)
#define sz(x) ((ll)x.size())
const ll M=1000000007;
const ll MM=998244353;
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";

ll newmod(ll a,ll b)
 {
  return ((a%b)+b)%b;
}

ll powM(ll a,ll b,ll m )
{
  if(a<=0)return 0;
  a%=m;
  if(!b)return 1;
  ll ans=1LL;
  while(b)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }

return ans;
}

ll poww(ll a,ll b)
{

  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }

return ans;

}

template<typename T,typename F>
void chmax( T &a,F b){
  if(b>a)a=b;
}

template<typename T,typename F>
void chmin( T &a,F b){
  if(b<a)a=b;
}

const ll N=1e5+5;

int main()
{

IOS;

ll n;cin>>n;

vl f(N);

ll ans=1;

for(int i=1;i<=n;i++){
  ll x;cin>>x;
  ll temp;
  if(!x){
    temp=3-f[0];
  }
  else {
    temp=f[x-1]-f[x];
  }
  if(temp<=0){
    cout<<0;
    return 0;
  }
  ans=ans*temp%M;
  f[x]++;
}

cout<<ans;

//end_routine();

return 0;

}


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

int main(){
  int k, t;  cin >> k >> t;
  vector<int> a(t);
  for(int i=0; i<t; i++)  cin >> a[i];
  sort(a.begin(), a.end());

  int sum = 0, ans = 1e9;
  for(int i=0; i<t; i++){
    sum += a[i];
    ans = min(ans, abs(k-sum-sum));
  }

  cout << max(0, ans - 1) << endl;

  return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main(){
  int k, t, a[109];
  cin >> k >> t;
  for(int i=0;i<t;i++)cin >> a[i];
  int ans=0;
  for(int i=0;i<t;i++){
    int rest=max(a[i]-(k+1)/2, 0);
    if(rest==1)ans++;
    else if(rest>1){
      ans += 1+2*(rest-1);
    }
  }
  cout << ans << endl;
}


#include<bits//stdc++.h>
using namespace std;
int main(){
	int n,p;
	while(cin>>n>>p&&n!=0&&p!=0){
		int a[50];
		fill(a,a+n,0);
		int m=0,p2=p;
		while(true){
			if(p==0){
				p+=a[m];
				a[m]=0;
			}
			else{
				p--;
				a[m]++;
			}
			if(p==0&&a[m]==p2) break;
			m++;
			if(m==n) m=0;
		}
		cout<<m<<endl;
	}
}

#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>

using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)

int main(){
    int n, p;
    cin >> n >> p;
    while(n || p){
        ll m = p, idx = 0;
        vector<ll> stone(n);
        for(;;){
            if(m > 0){
                m--;
                stone[idx]++;
            }
            else if(stone[idx] < p){
                m = stone[idx];
                stone[idx] = 0;
            }
            else{
                cout << idx << endl;
                break;
            }
            idx++;
            idx %= n;
        }

        cin >> n >> p;
    }
}


#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>

using namespace std;
using ll = long long;

#pragma region Macros
#define FOR(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define rep(i, n) FOR(i, 0, n)

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

template <class T> string join(const T &v, const string delim = ",")
{
    if (v.empty())
        return "";

    ostringstream res;
    res << v[0];
    for (int i = 1; i < v.size(); i++)
    {
        res << delim << v[i];
    }
    return res.str();
}

#pragma endregion Macros

// 解説AC
int main()
{
    int H, W;
    cin >> H  >> W;

    vector<vector<int>> a(H, vector<int>(W));
    rep(i, H) rep(j, W) cin >> a[i][j];

    int ph=-1, pw=-1;
    bool c=false;

    vector<vector<int>> ans;

    for (int h = 0; h < H; h++) {
        if (h % 2 == 0) {
            for (int w = 0; w < W;w++){
                if (c) ans.push_back(vector<int>{ph + 1, pw + 1, h + 1, w + 1});
                if(c){
                    if(a[h][w]%2==1){
                        c = false;
                    }
                }else{
                    if(a[h][w]%2==1){
                        c = true;
                    }
                }
                ph = h;
                pw = w;
            }
        } else {
            for (int w = W - 1;w>=0;w--){
                if (c) ans.push_back(vector<int>{ph + 1, pw + 1, h + 1, w + 1});
                if (c) {
                    if (a[h][w] % 2 == 1) {
                        c = false;
                    }
                } else {
                    if (a[h][w] % 2 == 1) {
                        c = true;
                    }
                }
                ph = h;
                pw = w;
            }
        }
    }

    cout << ans.size() << endl;
    for(auto a:ans){
        cout << join(a, " ") << endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define endl "\n"
#define rep(i, a, n) for (int i = a; i < n; ++i)
#define all(x) (x).begin(), (x).end()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    string a, b, c;
    cin >> n >> a >> b >> c;

    int ans = 0;
    rep(i, 0, n) {
        if (a[i] != b[i] && b[i] != c[i] && c[i] != a[i]) ans += 2;
        else if (a[i] == b[i] && b[i] == c[i]) continue;
        else ans++;
    }

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

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <stack>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 28)
template<typename T>
void remove(vector<T>& vector, unsigned int index){
vector.erase(vector.begin() + index);
}
vector<string> split(const string &s, char c);
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int n, q, cnt = 0;
void search(int num, int memo[10001]){
	rep(i,n){
		if(memo[i]==num){
			cnt++;
			break;
		}
	}
}

int main(void){
	int memo[10001];
	fill_n(memo, 10001, 0);
	cin >> n;
	rep(i,n)cin >> memo[i];
	cin >> q;
	rep(i,q){
		int a;
		cin >> a;
		search(a,memo);
	}
	cout << cnt << endl;
	return 0;
}

int StrToInt(string s){
	stringstream ss;
	ss << s;
	int val;
	ss >> val;
	return val;
}
string IntToStr(int i){
	stringstream ss;
	ss << i;
	return ss.str();
}

vector<string> split(const string &s, char delim) {
    vector<string> elems;
    string item;
    for (int i = 0; i < s.size(); i++) {
    	char ch = s[i];
        if (ch == delim) {
            if (!item.empty())
                elems.push_back(item);
            item.clear();
        }
        else {
            item += ch;
        }
    }
    if (!item.empty())
        elems.push_back(item);
    return elems;
}


#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <functional>
#include <random>

using namespace std;

const int N = 1000;

int ind[N][N];

vector<pair<int, int>> apply(vector<pair<int, int>> v, int x) {
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            ind[i][j] = -1;
        }
    }
    vector<pair<int, int>> vecs;
    for (int i = 0; i * i <= x; i++) {
        for (int j = 0; j * j <= x; j++) {
            if (i * i + j * j == x) {
                vecs.push_back({-i, j});
                vecs.push_back({i, -j});
                vecs.push_back({i, j});
                vecs.push_back({-i, -j});
            }
        }
    }
    int n = (int)v.size();
    for (int i = 0; i < n; i++) {
        ind[v[i].first][v[i].second] = i;
    }
    vector<vector<int>> g(n);
    for (int i = 0; i < n; i++) {
        int f, s;
        tie(f, s) = v[i];
        for (auto t : vecs) {
            int dx, dy;
            tie(dx, dy) = t;
            if (f + dx > N || f + dx < 0) continue;
            if (s + dy > N || s + dy < 0) continue;
            if (ind[f + dx][s + dy] != -1) {
                g[i].push_back(ind[f + dx][s + dy]);
            }
        }
    }
    vector<int> used(n);
    vector<int> cl(n);
    vector<int> lol(2);
    function<void(int, int)> dfs = [&](int cur, int c) {
        used[cur] = 1;
        cl[cur] = c;
        lol[c]++;
        for (auto t : g[cur]) {
            if (!used[t]) {
                dfs(t, c ^ 1);
            }
        }
    };
    for (int i = 0; i < n; i++) {
        if (!used[i]) {
            dfs(i, 0);
        }
    }
    int mx = 0;
    if (lol[1] > lol[0]) mx = 1;
    vector<pair<int, int>> tk;
    for (int i = 0; i < n; i++) {
        if (cl[i] == mx) {
            tk.push_back(v[i]);
        }
    }
    return tk;
}

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

    int n;
    cin >> n;
    n *= 2;
    int d1, d2;
    cin >> d1 >> d2;
    if (d1 % 2 < d2 % 2) {
        swap(d1, d2);
    }
    if (d2 % 2 == 1) {
        for (int i = 0; i < n; i += 2) {
            for (int j = 0; j < n; j += 2) {
                cout << i << ' ' << j << endl;
            }
        }
        exit(0);
    }
    vector<pair<int, int>> v;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (d1 % 2) {
                if ((i + j) % 2 == 0) {
                    v.push_back({i, j});
                }
            } else {
                v.push_back({i, j});
            }
        }
    }
    if (d1 % 2 == 0) {
        v = apply(v, d1);
    }
    v = apply(v, d2);
    for (int i = 0; i < n * n / 4; i++) {
        cout << v[i].first << ' ' << v[i].second << '\n';
    }
}

//============================================================================
// Name        : hoba.cpp :)
// Author      : (O_O Diab) (Why_not) (el 3AQ)
// Version     :
// Copyright   : please, Don't touch me :(
// Description : problem (I) in C++
// MAIN IDEA   : max sum of S(X) + S(S(X)) => 100 so brute force
//============================================================================
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define rw freopen("input.txt","r",stdin),freopen("output.txt","w",stdout);
#define pb push_back
#define F first
#define S second
#define pf push_front
#define lp(i,a,b) for (int i=a;i<=(int)b;++i)
#define lp2(i,a,b) for (int i=a;i>=b;--i)
#define f(x) return cout<<x<<"\n",0
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define p(x) cout<<#x<<" = { "<<x<<" } \n"
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define EPS 1e-6
// to convert string to number use int a = stoi(string);
// to convert number to string use string s = to_string(int);
#define FAST ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define clr(c,x) memset(c,x,sizeof(c));
using namespace __gnu_pbds;
using namespace std;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const int dx[] = { 0, 1, 0, -1, 1, -1, 1, -1 };
const int dy[] = { 1, 0, -1, 0, 1, -1, -1, 1 };
const int N = 2e5 + 5, mod = (int) 1e9 + 7, INF = 0x3f3f3f3f;
vi vv;
vector<vi> v, vec;
set<int> st;
int ans[N] = { }, comp[N] = { };
bool vis[N] = { };
void dfs(int node) {
	vis[node] = true;
	for (auto u : v[node])
		if (!vis[u])
			dfs(u);
	vv.pb(node);
}
int main() {
#ifdef ONLINE_JUDGE
	FAST
#endif
	int n, k, l;
	cin >> n >> k >> l;
	v.resize(n + 1);
	lp(i,1,k)
	{
		int x, y;
		cin >> x >> y;
		v[x].pb(y);
		v[y].pb(x);
	}
	int cnt = 0;
	lp(i,1,n)
	{
		if (vis[i])
			continue;
		vv.clear();
		dfs(i);
		cnt++;
		for (auto u : vv)
			comp[u] = cnt;
	}
	clr(vis, 0);
	v.clear();
	v.resize(n + 1);
	vec.resize(n + 1);
	lp(i,1,l)
	{
		int x, y;
		cin >> x >> y;
		v[x].pb(y);
		v[y].pb(x);
	}
	lp(i,1,n)
	{
		if (vis[i])
			continue;
		vv.clear();
		dfs(i);
		st.clear();
		for (auto u : vv) {
			vec[comp[u]].pb(u);
			st.insert(comp[u]);
		}
		for (auto u : st) {
			for (auto k : vec[u])
				ans[k] = vec[u].size();
			vec[u].clear();
		}
	}
	lp(i,1,n)
		cout << ans[i] << " ";
	return 0;
}


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

#define ll long long
int main() {
  ll N, T;
  cin >> N >> T;

  vector<ll> time(N);

  ll ans = 0;
  for (int i = 0; i < N; i++) {
    cin >> time[i];
  }

  for (int i = 0; i < N-1; i++) {
    if (time[i+1] - time[i] < T) {
      ans += time[i+1]- time[i];
    } else {
      ans += T;
    }
  }

  ans += T;

  cout << ans << endl;

}

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

int main(){
  int n;
  char str[1002],cmp[8]="Hoshino";
  scanf("%d%c",&n,&str[0]);
  for(int i=0;i<n;i++){
    gets(str);
    int cnt=0;
    int j=0;
    while(str[j]!='\0'){
      if(str[j]==cmp[cnt])cnt++;
      else cnt=0;
      if(str[j]==cmp[cnt])cnt++;
      if(cnt==7){str[j]='a';cnt=0;}
      j++;
    }
    puts(str);
  }
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1000000007;
int k[1000000];
int p(int A,int B){
  if(!B)return 1;
  if(B%2)return p(A,B-1)*A%mod;
  int C=p(A,B/2);
  return C*C%mod;
}
int c(int A,int B){
  if(A<B)return 0;
  return k[A]*p(k[A-B]*k[B]%mod,mod-2)%mod;
}
signed main(){
  k[0]=1;
  for(int i=1;i<=1000000;i++)k[i]=k[i-1]*i%mod;
  int N,M;
  cin>>N>>M;
  map<int,int> A;
  for(int i=2;i<=M/i;i++)
    for(;M%i==0;M/=i)A[i]++;
  if(M!=1)A[M]++;
  int ans=1;
  for(pair<int,int> p:A)ans=ans*c(N+p.second-1,N-1)%mod;
  cout<<ans<<endl;
}

#include <iostream>
#include <vector>

using namespace std;

const int MOD = 998244353;

int main(){
    const int maxSize = 2000001;
	vector<long long> inv(maxSize);
	vector<long long> fact(maxSize);
	vector<long long> factInv(maxSize);
	for(int i=0;i<2;i++) inv[i] = fact[i] = factInv[i] = 1;
	for(int i=2;i<maxSize;i++){
		inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
		fact[i] = fact[i-1] * i % MOD;
		factInv[i] = factInv[i-1] * inv[i] % MOD;
	}
	auto comb = [&](int n, int r){
		if(n < r || r < 0) return 0LL;
		return fact[n] * factInv[n-r] % MOD * factInv[r] % MOD;
	};
    auto perm = [&](int n, int r){
        if(n < r || r < 0) return 0LL;
        return fact[n] * factInv[n-r] % MOD;
    };
    int N, M;
    while(cin >> N >> M){
        long long res = (N * comb(M+N-2, N-2)) % MOD;
        long long sum = 0;
        for(int i=0;i<=M/2;i++){
            int m2 = M+i;
            long long cur = comb(m2+N-1, N-1);
            sum += N * comb(m2-M+N-2, N-2);
            sum %= MOD;
            cur = (cur + MOD - sum) % MOD;
            res += cur * comb(N, M-2*i);
            res %= MOD;
        }
        cout << res << endl;
    }
}


#include <bits/stdc++.h>

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
   string s;cin >>s;
   int n=s.size();
   vector<int>cnt(26,0);
    for (int i = 0; i < n; ++i) {
        cnt[s[i]-'a']++;
    }
    string ans;
    char nx;
    for (int i = 0; i < 26; ++i) {
        if(cnt[i]==0){
            nx=(char)('a'+i);
            break;
        }
    }
    if(s.size()!=26){
        ans=s+nx;
        cout <<ans <<endl;
    }
    else {
        ll mx=-1;
        reverse(all(s));
        int k=-1;
        vector<char>f;
        for (int i = 0; i < n; ++i) {
            if(mx>s[i]-'a'){
//                for (int i = 0; i < f.size(); ++i) {
//                    cout <<f[i]<<" ";
//                }
                int key=lower_bound(all(f),s[i])-f.begin();
                s[i]=f[key];
                k=n-i;
                break;
            }
            else {
                mx=s[i]-'a';
                f.push_back(s[i]);
            }
        }
        reverse(all(s));
        if(k>0){
            cout <<s.substr(0,k)<<endl;
        }
        else cout <<-1<<endl;
    }
}

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

int main() {
    string s;
    cin >> s;

    int mini = 10000;
    for (int i = 0; i < s.length()-2; i++) {
        int x = atoi(s.substr(i, 3).c_str());
        mini = min(abs(x - 753), mini);
    }

    cout << mini << endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e3+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a,b) memset(a,b,sizeof a)
#define lx x<<1
#define rx x<<1|1
#define reg register
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
#define il inline
int main(){
	ll x;cin>>x;
	if(x<=6) puts("1");
	else if(x<=11) puts("2");
	else {
		ll y=x/11,z=x%11;
		y<<=1;
		if(z>0&&z<=6) y++;
		else if(z>0&&z>6) y+=2;
		cout<<y;
	}
	return 0;
}

#include <iostream>

using namespace std;

int main()	{
  long long x;
  cin >> x;
  long long moves = 2 * (x / 11);
  if (x % 11 > 0)	moves++;
  if (x % 11 > 6)	moves++;
  cout << moves << endl;
  return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int n;
ll t[500005];

void inc(int x, ll v) {
    for (; x <= n; x += x & -x) t[x] += v;
}

ll que(int x) {
    ll z = 0;
    for (; x; x -= x & -x) z += t[x];
    return z;
}

int main() {
    ios::sync_with_stdio(false);
    int q, o, u, v;
    cin >> n >> q;
    for (int i = 1; i <= n; i++) cin >> u, inc(i, u);
    while (q--) {
        cin >> o >> u >> v;
        if (o == 0) inc(u + 1, v);
        else cout << que(v) - que(u) << '\n';
    }
}

#include <bits/stdc++.h>
#include <atcoder/all>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
using namespace atcoder;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, Q; cin >> N >> Q;
  fenwick_tree<ll> ft(N);
  REP(i, N){
    ll a; cin >> a;
    ft.add(i, a);
  }
  REP(i, Q){
    int q; cin >> q;
    if(q == 0){
      int p; ll x; cin >> p >> x;
      ft.add(p, x);
    }else{
      int l, r; cin >> l >> r;
      ll ans = ft.sum(l, r);
      cout << ans << endl;
    }
  }
}