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

int main()
{
    ll n, a, b, c, d, e;
    cin >> n >> a >> b >> c >> d >> e;

    ld res = n / ld(min({a, b, c, d, e}));

    cout << (ll (ceil(res) + 4)) << "\n";

    return 0;
}

#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <cstring>
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <numeric>
#include <float.h>
#include <math.h>
#include <sstream>
#include <iterator>
using namespace std;
// repマクロの定義
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// allマクロの定義
#define all(v) v.begin(), v.end()
// 大きい順
#define rall(v) v.rbegin(), v.rend()
#define vi vector<int>
#define vl vector<ll>
const  long long INF = 1LL << 60;
typedef  long long ll;
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;
}

int ctoi(char c) {
 	switch (c) {
		case '0': return 0;
		case '1': return 1;
		case '2': return 2;
		case '3': return 3;
		case '4': return 4;
		case '5': return 5;
		case '6': return 6;
		case '7': return 7;
		case '8': return 8;
		case '9': return 9;
		default: return 0;
	}
}

bool is_prime(const unsigned n){
    switch(n){
        case 0: // fall-through
        case 1: return false;
        case 2: // fall-through
        case 3: return true;
    } // n > 3 が保証された

    if(n % 2 == 0 || n % 3 == 0) return false;
    // n は 2 と 3 のいずれの倍数でもないことが保証された
    // これより n は (6の倍数)-1 か (6の倍数)+1 である

    // 6の倍数前後の数を使って試し割りをする
    for(unsigned i = 5; i * i <= n; i += 6) {
        if(n % i     == 0) return false; // (6の倍数)-1
        if(n % (i+2) == 0) return false; // (6の倍数)+1
    }

    return true;
}

map<ll,ll> mp;

auto findFactors(ll num){

    ll i;
    while (num % 2 == 0){ // 偶数の素数は2のみ
        if(mp.count(2)){
			mp[2] = mp[2] + 1;
		}
		else{
			mp[2] = 1;
		}
        num /= 2;
    }
    for (i = 3; i <= num; i++){ // 他の素数で割っていく
        while (num % i == 0){
			if(mp.count(i)){
			mp[i] = mp[i] + 1;
		}
		else{
			mp[i] = 1;
		}
            num /= i;
        }
    }
    return 0;
}
ll kaizyou(ll n){
    if(n == 1){
        return 1;
    }
    else{
        return (n * kaizyou(n-1)) % 1000000007;
    }
}

int main(){
int N; cin >> N;
map<ll,ll> A;
rep(i,N) {
    ll a; cin >> a;
    if(!A.count(a)){
        A[a] = 1;
    }
    else{
        A[a] += 1;
    }
}
vl x;
for(auto u:A){
    if(u.second >= 2){
        x.push_back(u.first);
    }
    if(u.second >= 4){
        x.push_back(u.first);
    }
}
if(x.size() >= 2){
sort(rall(x));
cout << x[0] * x[1] << endl;
}
else{
    cout << 0 << endl;
}
}


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

typedef long long ll;

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

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

int main(){
  vector<int> A(3);
  cin >> A[0] >> A[1] >> A[2];
  int mid = A[2];
  sort(A.begin(), A.end());
  cout << (A[1]==mid?"Yes":"No") << endl;
  return 0;
}


#include<iostream>
using namespace std;
int main(void){
    long long n,a[10000],min=1000000,max=-1000000,sum=0;

    cin>>n;
    for(int i=0;i<n;i++){
    cin>>a[i];
    if(a[i]<min){min=a[i];}
    if(a[i]>max){max=a[i];}
    sum=a[i]+sum;
    }
    cout<<min<<" "<<max<<" "<<sum<<endl;

}

#define _CRT_SECURE_NO_WARNINGS

#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 <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define mkt make_tuple
#define no {cout << -1; return;}

void solve() {
    int p, q, r;
    cin >> p >> q >> r;
    cout << min({ p + q, q + r, p + r });
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}


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

int main(){
    ll N, M, Q; cin >> N >> M >> Q;
    vector<vector<ll>> D(N+1, vector<ll>(N+1));
    for(int i = 0; i < M; i++){
        ll l, r; cin >> l >> r; D[l][r]++;
    }
    for(int i = 0; i < N+1; i++){
        for(int j = 0; j < N; j++) D[i][j+1] += D[i][j];
    }

    while(Q--){
        ll p, q; cin >> p >> q;
        ll cnt = 0;
        for(;p <= q; p++){
            cnt += D[p][q];
        }
        cout << cnt << endl;
    }

}

///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;

struct BIT
{
	int N;
	vector<int> bit;

	void init(int n)
	{
		N = n;
		bit.assign(n + 1, 0);
	}

	void update(int idx, int val)
	{
		while(idx <= N)
		{
			bit[idx] += val;
			idx += idx & -idx;
		}
	}

	void updateMax(int idx, int val)
	{
		while(idx <= N)
		{
			bit[idx] = max(bit[idx], val);
			idx += idx & -idx;
		}
	}

	int pref(int idx)
	{
		int ans = 0;
		while(idx > 0)
		{
			ans += bit[idx];
			idx -= idx & -idx;
		}
		return ans;
	}

	int rsum(int l, int r)
	{
		return pref(r) - pref(l - 1);
	}

	int prefMax(int idx)
	{
		int ans = -2e9;
		while(idx > 0)
		{
			ans = max(ans, bit[idx]);
			idx -= idx & -idx;
		}
		return ans;
	}
};

const int M=502;
vector<int>vec[M];
int ses[100009];
vector<pi>yo[M];
vector<pi>abr_yo[M];
BIT Magic;
 main()

{
    fast
    int n,m,q;
    cin>>n>>m>>q;
    Magic.init(503);
    f(i,1,m)
    {
        int l,r;
        cin>>l>>r;
        vec[l].pb(r);
    }
    f(i,1,q)
    {
        int l,r;
        cin>>l>>r;
        yo[l].pb(mp(r,i));
        abr_yo[r].pb(mp(l,i));
    }
    f(i,1,500)
    {
       for(auto x:yo[i])
       {
           int idx=x.si;
           int rgt=x.fi;
           int lft=i;
           ses[idx]=-Magic.rsum(lft,rgt);
       }
       for(auto x:vec[i])
       {
           Magic.update(x,1);
       }
    }
    Magic.init(503);
    f(i,1,500)
    {
        for(auto x:vec[i])
       {
           Magic.update(x,1);
       }
       for(auto x:abr_yo[i])
       {
           int idx=x.si;
           int lft=x.fi;
           int rgt=i;
           ses[idx]+=Magic.rsum(lft,rgt);
       }

    }
    f(i,1,q)
    {
        cout<<ses[i]<<endl;
    }
     cout<<endl;
    return 0;

}


// clang-format off
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
// clang-format on

const ll INF = LLONG_MAX / 3;

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

    const int L = 2 + n % 2;
    vector<vector<ll>> dp(n, vector<ll>(L, -INF));
    rep(i, L) dp[i][L - 1 - i] = a[i];
    rep(i, n - 1) rep(j, L) {
        if (dp[i][j] == -INF) continue;
        if (i + 2 < n) dp[i + 2][j] = max(dp[i + 2][j], dp[i][j] + a[i + 2]);
        if (j > 0) dp[i + 1][j - 1] = max(dp[i + 1][j - 1], dp[i][j]);
    }
    cout << dp[n - 1][0] << "\n";
    return 0;
}

#include <stdio.h>

const int bias = 10;
long long dp[bias*2+1][2],nxt[bias*2+1][2];

void mx(long long &a, long long b)
{
	if (a < b) a = b;
}

int main()
{
  for (int i=0;i<=bias*2;i++) dp[i][0] = dp[i][1] = -1e18; dp[bias][0] = 0;

  int n; scanf ("%d",&n);
  for (int k=0;k<n;k++){
	int x; scanf ("%d",&x);
  for (int i=0;i<=bias*2;i++) nxt[i][0] = nxt[i][1] = -1e18;
    for (int i=0;i<=bias*2;i++){
mx(nxt[i][0],dp[i][0]);
mx(nxt[i][0],dp[i][1]);
mx(nxt[i+2][1],dp[i][0]+x);
    }
  for (int i=1;i<=bias*2;i++){
    dp[i-1][0] = nxt[i][0];
    dp[i-1][1] = nxt[i][1];
  }
    dp[bias*2][0] = dp[bias*2][1] = -1e18;
  }

  int last = (n / 2) * 2 - n + bias;
  long long ans = -1e18;
  mx(ans,dp[last][0]);
  mx(ans,dp[last][1]);
  printf ("%lld\n",ans);
return 0;
}


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

class Dice {
private:
	int surface [6];
	void next(int a, int b, int c, int d);

public:
	Dice(int surface[6]);
	Dice();
	void role(char dir);
	void set(int pos, int num);
	int get(int pos);
};

int main(void) {
	Dice dice;

	for (int i = 0; 6 > i; i++) {
		int buf;
		scanf("%d", &buf);
		dice.set(i, buf);
	}
	char order;
	while (scanf(" %c", &order) != EOF) {
		dice.role(order);
	}
	printf("%d\n", dice.get(0));
	return 0;
}

void Dice::next(int a, int b, int c, int d)
{
	swap(surface[c], surface[d]);
	swap(surface[b], surface[c]);
	swap(surface[a], surface[b]);
}

Dice::Dice(int surface[6])
{
	for (int i = 0; 6 > i; i++)
		Dice::surface[i] = surface[i];
}

Dice::Dice()
{
	for (int i = 0; 6 > i; i++) surface[i] = 0;
}

void Dice::role(char dir)
{
	switch (dir) {
	case 'W': next(0,3,5,2);  break;
	case 'E': next(0,2,5,3);  break;
	case 'N': next(0,4,5,1);  break;
	case 'S': next(0,1,5,4);  break;
	}
}

void Dice::set(int pos, int num)
{
	surface[pos] = num;
}

int Dice::get(int pos)
{
	return surface[pos];
}

#include<bits/stdc++.h>

using namespace std;

struct Dice
{
  int x, y;
  int l, r, f, b, d, u;

  void RollF()
  {
    --y;
    int buff = d;
    d = f;
    f = u;
    u = b;
    b = buff;
  }

  void RollB()
  {
    ++y;
    int buff = d;
    d = b;
    b = u;
    u = f;
    f = buff;
  }

  void RollL()
  {
    --x;
    int buff = d;
    d = l;
    l = u;
    u = r;
    r = buff;
  }

  void RollR()
  {
    ++x;
    int buff = d;
    d = r;
    r = u;
    u = l;
    l = buff;
  }
};

int main()
{
  Dice dice;
  cin >> dice.u;
  cin >> dice.f;
  cin >> dice.l;
  cin >> dice.r;
  cin >> dice.b;
  cin >> dice.d;

  string S;
  cin >> S;
  for(char &c : S) {
    if(c == 'S') dice.RollF();
    else if(c == 'N') dice.RollB();
    else if(c == 'W') dice.RollR();
    else dice.RollL();
  }

  cout << dice.u << endl;
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
    int N;
    cin >> N;
    int M = 0;
    cin >> M;
    vector<int> s(M,0);
    vector<int> c(M,0);
    if(M == 0) {
        cout << (int)pow(10, N - 1)*(N != 1) << endl;
        return 0;
    }
    for(int i = 0; i < M; i++) {
        cin >> s.at(i);
        cin >> c.at(i);
    }
    for(int i = pow(10, N - 1)*(N != 1); i < pow(10, N); i++) {
        int check = 1;
        for(int j = 0; j < M; j++) {
            if((i/(int)pow(10, N - s.at(j)))%10 == c.at(j)) {
                continue;
            }
            check = 0;
        }
        if(check) {
            cout << i << endl;
            return 0;
        }
    }

    cout << -1 << endl;

    return 0;
}

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

int main() {
  int n,m;cin>>n>>m;
  vector<pair<int,int>> pr(m);
  rep(i,m){
    int s,c;cin>>s>>c;
    s--;
    pr[i]=make_pair(s,c);
  }
  rep(i,1000){
    bool ans=true;
    string a=to_string(i);
    int keta=a.size();
    if(n!=keta)continue;
    rep(j,m){
      if(a[pr[j].first]!=(char)('0'+pr[j].second))ans=false;
    }
    if(ans){
      cout<<i<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;
}


#include <iostream>
using namespace std;
#include <vector>
#include <functional>
template<class T, class Lazy> struct LazySegTree {
  private:
  public:
    int size;
    vector<T> v; vector<Lazy> lazy;
    vector<int> seg_size;
    using F = function<T(T,T)>;
    using G = function<Lazy(Lazy,Lazy)>;
    using H = function<T(T,Lazy,int)>;
    F f; G g; H h;
    T default_value; Lazy default_lazy;
  public:
    LazySegTree(int n, T default_value, Lazy default_lazy, F f, G g, H h)
      : default_value(default_value), default_lazy(default_lazy), f(f), g(g), h(h) {
      size = 1;
      while (size < n) size *= 2;

      v.resize(2 * size - 1, default_value);
      lazy.resize(4 * size - 1, default_lazy);
      seg_size.resize(2 * size - 1, 1);

      for (int i = 0; i < size - 1; ++i) {
        int j = size - 2 - i;
        seg_size[j] = seg_size[2 * j + 1] + seg_size[2 * j + 2];
      }
    }
    void update(int index, T val) {
      update(index, index+1, default_lazy);
      index = index + size - 1;
      v[index] = val;
      while (index > 0) {
        index = (index - 1) / 2;
        v[index] = f(v[2 * index + 1], v[2 * index + 2]);
      }
    }
    void eval(int index) {
      v[index] = h(v[index], lazy[index], seg_size[index]);

      lazy[2 * index + 1] = g(lazy[index], lazy[2 * index + 1]);
      lazy[2 * index + 2] = g(lazy[index], lazy[2 * index + 2]);

      lazy[index] = default_lazy;
    }
    T query(int l, int r) { return query(l, r, 0, size, 0); }
    T query(int l, int r, int cur_l, int cur_r, int index) {
      // [l, r)に対するクエリ
      eval(index);
      if (cur_r <= l || r <= cur_l) return default_value;
      if (l <= cur_l && cur_r <= r) return v[index];

      // 左右を見ていく
      int mid = (cur_l + cur_r) / 2;
      return f(
          query(l, r, cur_l, mid, 2 * index + 1),
          query(l, r, mid, cur_r, 2 * index + 2));
    }
    void update(int l, int r, Lazy x) { update(l, r, x, 0, size, 0); }
    void update(int l, int r, Lazy x, int cur_l, int cur_r, int index) {
      // [l, r)に対して操作する

      eval(index);
      if (cur_r <= l || r <= cur_l) return;
      if (l <= cur_l && cur_r <= r) {
        lazy[index] = x;
        eval(index);
        return;
      }
      // 左右を見ていく
      int mid = (cur_l + cur_r) / 2;
      update(l, r, x, cur_l, mid, 2 * index + 1);
      update(l, r, x, mid, cur_r, 2 * index + 2);
      v[index] = f(v[2 * index + 1], v[2 * index + 2]);
    }
};

// // 範囲和
// LazySegTree<long long, int> T(N, 0, 0,
//     [](long long a, long long b) {return a + b;},
//     [](int a, int b) {return a + b;},
//     [](long long a, int b, int size) {return a + b * size;});
// // chmin
// LazySegTree<ll, ll> T(N, INF, -1,
//     [](ll a, ll b) {return min(a, b);},
//     [](ll a, ll b) { return a == -1 ? b : a;},
//     [](ll a, ll lz, int size) {return lz == -1 ? a : lz;});

#define in(v) v; cin >> v;
void ins() {}
template<class T,class... Rest>void ins(T& v,Rest&... rest){cin>>v;ins(rest...);}
#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)

int main() {
  int in(N); int in(Q);

  // 範囲和
  LazySegTree<int, int> T(N, 2147483647, -1,
      [](int a, int b) {return min(a, b);},
      [](int par_lz, int lz) {return par_lz == -1 ? lz : par_lz;},
      [](int a, int lz, int size) {return lz == -1 ? a : lz;});

  rep(i, Q) {
    int com;
    ins(com);

    if (com == 0) {
      int s, t, x;
      ins(s, t, x);
      ++t;
      T.update(s, t, x);
    } else {
      int in(idx);
      cout << T.query(idx, idx+1) << endl;
    }
  }

  return 0;
}

#include<bits/stdc++.h>
//#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define bug1( x ) {cerr << (#x) <<"="<< x << endl;}
#define bug2( x , y ) {cerr << (#x) <<"="<< (x) << "    " << (#y) << "="<< (y) << endl;}
#define bug3( x , y , z ) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << endl;}
#define bug4( x , y , z , w) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << endl;}
#define bug5( x , y , z , w ,p) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << endl;}
#define bug6( x , y , z , w ,p , q) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << "    " << (#q) <<"="<< q << endl;}
#define bugn( x , n ) {cerr << (#x) <<":";for(int i=0;i<n;i++)cerr << x[i] <<"  "; cerr << endl;}
#define bugnm( x , n , m ) {cerr << (#x)<<endl;for(int i=0;i<n;i++){cerr << "Row #" << i<< ":";for(int j=0;j<m;j++)cerr << x[i][j] << "   ";cerr << endl;}}
typedef long long ll;
typedef long double ld;
using namespace std;

const int maxn = 1e6+10;
int dp[maxn][10];
string s;
int n;
int solve(int i,int carry){
	//bug2(i,carry);
	if( i >= n )return carry;
	int & ans = dp[i][carry%10];
	if( ans != -1 )return carry/10 + ans;
	ans = 1e8;
	carry += ( i < n ? s[i]-'0' : 0 );
	ans = min( ans , carry % 10 + solve(i+1,carry/10) );
	if( carry%10 ){
		ans = min( ans , 10-(carry%10) + solve(i+1,carry/10 + 1));
	}
	return ans;
}
int32_t main(){
	IOS
	memset(dp,-1,sizeof(dp));
	cin >> s; reverse(s.begin(),s.end());
	n = s.length();
	cout << solve(0,0) ;

}
/*
 * long long or int?
 * index out of bound?
 * Tested on own test case?corner?
 * Make more general solution.
 * Read Read Read Read ....
 */


#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>
#include <math.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--)
#define repv(x, arr) for (auto &x : arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 2147483600;
const ll infl = 1e17;

int n,m;

int main()
{
    cin >> n >> m;
    vii a(n), b(m);
    rep(i, n) cin >> a[i];
    rep(i, m) cin >> b[i];
    sort(all(a));
    sort(all(b));
    rep(i, n - 1)
    {
        if (a[i] == a[i + 1])
        {
            cout << 0 << endl;
            return 0;
        }
    }
    rep(i, m - 1)
    {
        if (b[i] == b[i + 1])
        {
            cout << 0 << endl;
            return 0;
        }
    }
    ll ans = 1;
    repr(now,n*m,0){
        int aidx = lower_bound(all(a), now) - a.begin();
        int bidx = lower_bound(all(b), now) - b.begin();
        ll atar = n - aidx, btar = m - bidx;
        ll kimeta = n * m  - now;
        if (a[aidx]==now && b[bidx]==now){
            continue;
        }
        else if(a[aidx]==now){
            ans = (ans * btar) % mod;
        }
        else if(b[bidx]==now){
            ans = (ans * atar) % mod;
        }
        else {
            ans = (ans * ((atar * btar) % mod + mod - kimeta) % mod) % mod;
        }
    }
    cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) ((v).begin(), (v).end())
using ll = long long;
using P = pair<int, int>;
/* ------------------------------------------------ */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ------------------------------------------------ */
int main() {
    int h,w;
    cin >> h >> w;
    char s[55][55];
    rep(i, h) {
        rep(j, w) cin >> s[i][j];
    }
    int dist[55][55];
    rep(i, h) {
        rep(j, w) dist[i][j] = -1;
    }
    dist[0][0] = 1;
    int f[]={0,1,0,-1};
    int g[]={1,0,-1,0};
    queue<P> que;
    que.push({0,0});
    while(!que.empty()) {
        P p = que.front();
        que.pop();
        rep(i, 4) {
            int x = p.first + f[i],y = p.second + g[i];
            if(x > h-1 || x < 0 || y > w-1 || y < 0) continue;
            if(dist[x][y] == -1 && s[x][y] == '.'){
                dist[x][y] = dist[p.first][p.second]+1;
                que.push({x,y});
            }
        }
    }
    if(dist[h-1][w-1]==-1) {
        cout << -1 << endl;
        return 0;
    }
    int ans = h*w - dist[h - 1][w - 1];
    rep(i, h) {
        rep(j, w) if(s[i][j] == '#') ans--;
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define ld long double
#define pb push_back
#define all(x) (x).begin(), (x).end()
template <typename T> using ord_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 2e5 + 123;
int n, a[N];
array <ll, 2> p[N], s[N];

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif

	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i];
	int j = 1;
	ll pref = a[1], cur = a[1];
	for (int i = 2; i <= n; i++) {
		pref += a[i];
		while (abs(cur + a[j + 1] - (pref - cur - a[j + 1])) < abs(cur - (pref - cur)))
			cur += a[++j];
		p[i] = {cur, pref - cur};
		if (p[i][0] > p[i][1]) swap(p[i][0], p[i][1]);
	}
	ll suf = a[n];
	cur = a[n], j = n;
	for (int i = n - 1; i >= 1; i--) {
		suf += a[i];
		while (abs(cur + a[j - 1] - (suf - cur - a[j - 1])) < abs(cur - (suf - cur)))
			cur += a[--j];
		s[i] = {cur, suf - cur};
		if (s[i][0] > s[i][1]) swap(s[i][0], s[i][1]);
	}
	ll ans = 1e9 + 123;
	for (int i = 2; i <= n - 2; i++)
		ans = min(ans, max(p[i][1], s[i + 1][1]) - min(p[i][0], s[i + 1][0]));
	cout << ans;
}

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <list>
#include <limits>
#include <set>
#include <map>
#include <functional>

#include <inttypes.h>
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

using namespace std;
typedef long long ll;

#ifndef PRId64
#define PRId64 "lld"
#endif
#ifndef SCNd64
#define SCNd64 "lld"
#endif
#define SC sc()
#define PT pr()
#define FORi(i,b,e) for (int i = (b), _ = (e); i < _; ++i)
#define FORe(i,b,e) for (int i = (b), _ = (e); i <= _; ++i)
#define FORre(i,b,e) for (int i = (b), _ = (e); i >= _; --i)

static int sc_ret = 0;
struct sc
{
    sc& operator()(char& v) { v = sc_ret = getchar(); return *this; }
    sc& operator()(int& v) { sc_ret = scanf("%d", &v); return *this; }
    sc& operator()(unsigned& v) { sc_ret = scanf("%u", &v); return *this; }
    sc& operator()(double& v) { sc_ret = scanf("%lf", &v); return *this; }
    sc& operator()(char* v) { sc_ret = scanf("%s", v); return *this; }
    sc& operator()(string& v) { sc_ret = (bool)(cin >> v); return *this; }
    sc& operator()(ll& v) { sc_ret = scanf("%" SCNd64, &v); return *this; }
    sc& ch(char& v) { sc_ret = scanf(" %c", &v); return *this; }
    sc& gets(char* v) { sc_ret = fgets(v, INT_MAX, stdin) != 0; v[strlen(v) - 1] = 0; return *this; }
    operator bool() const { return sc_ret > 0; }
    void read(int& v)
    {
        int x = 0, k = 1;
        char c = getchar();
        while (c < '0' || c > '9')
        {
            if (c == '-') k = -1;
            c = getchar();
        }
        while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + (c - 48), c = getchar();
        v = x * k;
    }
};
struct pr
{
    pr& ln() { putchar('\n'); return *this; }
    pr& operator()(char v) { putchar(v); return *this; }
    pr& operator()(int v) { printf("%d", v); return *this; }
    pr& operator()(double v) { printf("%.2f", v); return *this; }
    pr& operator()(const char* fmt, double v) { printf(fmt, v); return *this; }
    pr& operator()(const char* v) { printf("%s", v);return *this; }
    pr& operator()(string v) { printf("%s", v.c_str());return *this; }
    pr& operator()(ll v) { printf("%" PRId64, v);return *this; }

    void write(int v)
    {
        int cnt = 0; char c[15];
        if (v == 0)
        {
            putchar('0');
            return;
        }
        if (v < 0) putchar('-'), v = -v;
        while (v) c[++cnt] = (v % 10) + 48, v /= 10;
        while (cnt > 0) putchar(c[cnt--]);
    }
    template <typename T>
    void ln(T* arr, int size)
    {
        if (size > 0)
        {
            (*this)(arr[0]);
            for (int i = 1; i < size; ++i)
            {
                putchar(' ');
                (*this)(arr[i]);
            }
            putchar('\n');
        }
    }

    template <typename T>
    void muln(T* arr, int size)
    {
        for (int i = 0; i < size; ++i)
        {
            (*this)(arr[i]);
            putchar('\n');
        }
    }
};

const int inf = 0x3f3f3f3f;
const int mod = 1000000007;
const int maxn = 200000 + 10;
const int maxm = 100000 + 10;

ll a[maxn];

int main()
{
    int n, t, k;
    SC(n);
    FORe(i, 1, n)
    {
        int v;
        SC.read(v);
        a[i] = v + a[i - 1];
    }
    int l = 1, r = 3; ll ret = a[n];
    FORi(i, 2, n - 1)
    {
        for (; l < i - 1; ++l)
        {
            if (min(a[l], a[i] - a[l]) >= min(a[l + 1], a[i] - a[l + 1]))
                break;
        }
        for (; r < n - 1; ++r)
        {
            if (min(a[r] - a[i], a[n] - a[r]) >= min(a[r + 1] - a[i], a[n] - a[r + 1]))
                break;
        }
        ret = min(ret, max(max(a[r] - a[i], a[n] - a[r]), max(a[l], a[i] - a[l]))
            - min(min(a[l], a[i] - a[l]), min(a[r] - a[i], a[n] - a[r])));
    }
    PT(ret);
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
using lint = int64_t;

int main() {
    const int INF = 1000000000;
    int N, T;
    cin >> N >> T;
    vector<int> A(N), B(N);
    rep(i, N) cin >> A[i] >> B[i];
    vector<vector<int>> dp0(N + 1, vector<int>(T + 1, -INF)), dp1(N + 1, vector<int>(T + 1, -INF));
    dp0[0][0] = 0;
    dp1[N][0] = 0;
    rep(i, N) rep(j, T + 1) {
        dp0[i + 1][j] = max(dp0[i + 1][j], dp0[i][j]);
        if (j + A[i] <= T) dp0[i + 1][j + A[i]] = max(dp0[i + 1][j + A[i]], dp0[i][j] + B[i]);
    }
    for (int i = N; i > 0; --i) rep(j, T + 1) {
        dp1[i - 1][j] = max(dp1[i - 1][j], dp1[i][j]);
        if (j + A[i - 1] <= T) dp1[i - 1][j + A[i - 1]] = max(dp1[i - 1][j + A[i - 1]], dp1[i][j] + B[i - 1]);
    }
    rep(i, N + 1) rep(j, T) {
        dp0[i][j + 1] = max(dp0[i][j], dp0[i][j + 1]);
        dp1[i][j + 1] = max(dp1[i][j], dp1[i][j + 1]);
    }
    int ans = 0;
    rep(i, N) {
        int res = 0;
        rep(j, T) res = max(res, dp0[i][j] + dp1[i + 1][T - 1 - j]);
        ans = max(ans, res + B[i]);
    }
    cout << ans << "\n";
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i <= (b); ++ i)
#define rrp(i,a,b) for (int i = (a); i >= (b); -- i)
#define gc() getchar()
#define fir first
#define sec second
typedef pair<int,int> pii;
typedef long double db;
typedef long long ll;
template <typename tp>
inline void read(tp& x) {
  x = 0; char tmp; bool key = 0;
  for (tmp = gc(); !isdigit(tmp); tmp = gc())
    key = (tmp == '-');
  for (; isdigit(tmp); tmp = gc())
    x = (x << 3) + (x << 1) + (tmp ^ '0');
  if (key) x = -x;
}
template <typename tp>
inline void ckmn(tp& x,tp y) {
  x = x < y ? x : y;
}
template <typename tp>
inline void ckmx(tp& x,tp y) {
  x = x < y ? y : x;
}

const int N = 510, MAX = 10000;
int isp[MAX + 10], pri[MAX], pcnt;
void prework() {
  rep (i, 2, MAX) {
    if (!isp[i]) pri[++pcnt] = i;
    for (int j = 1; pri[j] * i <= MAX; ++ j) {
      isp[pri[j] * i] = 1;
      if (i % pri[j] == 0) break;
    }
  }
}
ll mat[N][N];
int n, arr[2][N];
set<ll> st;
ll lcm(ll x,ll y) {
  return x / __gcd(x, y) * y;
}
int main() {
  prework();
  read(n);
  if (n == 2) {
    puts("4 7");
    puts("23 10");
    return 0;
  }
  int p = 0;
  rep (i, 1, n) arr[0][i] = pri[++ p];
  rrp (i, n, 1) arr[1][i] = pri[++ p];
  int tmp = (n+1) / 2;
  rep (i, 1, n) rep (j, 1, n) if ((i+j) % 2 == 0) {
    int vx = i + j, vy = i - j;
    vx /= 2;
    vy /= 2;
    vy += tmp;
    mat[i][j] = 1ll * arr[0][vx] * arr[1][vy];
  }
  rep (i, 1, n) rep (j, 1, n) if ((i+j)&1) {
    mat[i][j] = 1;
    if (i > 1) mat[i][j] = lcm(mat[i][j], mat[i-1][j]);
    if (i < n) mat[i][j] = lcm(mat[i][j], mat[i+1][j]);
    if (j > 1) mat[i][j] = lcm(mat[i][j], mat[i][j-1]);
    if (j < n) mat[i][j] = lcm(mat[i][j], mat[i][j+1]);
    mat[i][j] ++;
  }
  // (i-j, i+j)
  // rep (i, 1, n) rep (j, 1, n) {
  //   assert(!st.count(mat[i][j]));
  //   assert(mat[i][j] <= (ll)1e15);
  //   st.insert(mat[i][j]);
  // }
  rep (i, 1, n) {
    rep (j, 1, n) printf("%lld ", mat[i][j]);
    puts("");
  }
  return 0;
}


#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using pll = pair<ll, ll>;
template<class T> void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T> void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U> bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U> bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T> bool even(T n) { return ! (n & 1); }
template<class T> bool odd(T n) { return n & 1; }
template<class T> ll rup(T a, T b) { return a % b ? a / b + 1 : a / b; }
template<class T> ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T> ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;
ll intpow(ll a, ll n, ll _mod=numeric_limits<ll>::max()) { ll p=1; while (n) { if (n&1) p=p*a%_mod; a=a*a%_mod; n>>=1; } return p; }
ll modc(ll a, char op, ll b, ll _mod=mod) { a %= _mod; b %= _mod; ll res = 1; switch(op) {
        case '+': res = (a + b) % _mod; break;
        case '-': res = (a - b) % _mod; break;
        case '*': res = a * b % _mod; break;
        case '/': res = modc(a, '*', modc(b, '^', _mod-2, _mod), _mod); break;
        case '^': res = intpow(a, b, _mod); break;
        case 'P': rep(i, a-b+1, a+1) res = modc(res, '*', i, _mod); break;
        case 'C': res = modc(modc(a, 'P', b, _mod), '/', modc(b, 'P', b, _mod)); break; } if (res < 0) res += _mod; return res; }

int main()
{
        ll H, W, N;
        cin >> H >> W >> N;
        ll bigger = max(H, W);
        cout << rup(N, bigger) << endl;
}

#include<stdio.h>

int main(){

	int h, w, n, ans;

	scanf("%d", &h);
	scanf("%d", &w);
	scanf("%d", &n);

	if(w>=h){
		if(n%w == 0){
			ans = n/w;
		}else if(n%w != 0){
			ans = n/w+1;
		}

	}else if(w<=h){
		if(n%h == 0){
			ans = n/h;
		}else if(n%h != 0){
			ans = n/h+1;
		}
	}
	printf("%d", ans);
}


#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  string S;
  cin>>S;
  map<char, int> amap;
  for(int i=0;i<S.size();++i) {
    amap[S[i]]++;
  }
  char ans = 'A';
  for(char a='a';a<='z';++a) {
    if(amap[a]==0) {
      ans = a;
      break;
    }
  }
  if(ans=='A') cout<<"None"<<endl;
  else cout<<ans<<endl;
}

#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include <iostream>
#include <algorithm>
#define INF 100000000000000
using namespace std;
typedef long long llong;

//int isalpha(char ch): ch がアルファベットなら true を返す
//int isdigit(char ch): ch が数字なら true を返す
//int islower(char ch): ch が小文字なら true を返す
//int isupper(char ch): ch が大文字なら true を返す
//int tolower(char ch): ch の小文字を返す
//int toupper(char ch): ch の大文字を返す

//string型
//size()	文字数を返す
//insert()	（指定した場所に）文字・文字列を挿入する
//erase()	（指定した場所の）文字・文字列を削除する
//clear()	すべての文字を削除する
//substr()	文字列の（指定した）部分文字列を返す
//replace()	（指定した）部分文字列を新しい文字列に置換する
//文字列の比較は、<=や==などを使え
//replace関数を使い、簡単に文字列を置換
//リバース関数：reverse(str.begin(), str.end());

int main(){
    string S;
    vector<char> Table(26, 0);
    cin >> S;

    for(int i=0; i<S.size(); i++){
        Table[S[i]-'a'] = 1;
    }
    for(int i=0; i<Table.size(); i++){
        if(Table[i]==0){
            printf("%c\n", 'a'+i);
            exit(0);
        }
    }
    cout << "None\n";
    return 0;
}


#include<iostream>
using namespace std;
int main () {
  int H, W, A, B;
  cin >> H >> W >> A >> B;
  int zo[] = {0, 1};
  for (int i = 0; i < B; i ++) {
    for (int j = 0; j < A; j ++) {
      cout << zo[0];
    }
    for (int j = A; j < W; j ++) {
      cout << zo[1];
    }
    cout << endl;
  }
  for (int i = B; i < H; i ++) {
    for (int j = 0; j < A; j ++) {
      cout << zo[1];
    }
    for (int j = A; j < W; j ++) {
      cout << zo[0];
    }
    cout << endl;
  }
}

#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch 01Matrix | diff 01Matrix.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address 01Matrix.cpp && ./a.out

/*

 8/3/2020

 21:24-

 */

int H,W,A,B;

void solve() {
  REP(_,B) {
    REP(j,W) cout<<char('0'+(j<A));
    cout<<endl;
  }
  REP(_,H-B) {
    REP(j,W) cout<<char('0'+(j>=A));
    cout<<endl;
  }
}

bool ith(int mask, int i) { return (mask>>i)&1; }
void test() {
  set<II> ps;
  REP(mask, 1<<25) {
    VV<int> G(5,VI(5,0));
    REP(i,25) if(ith(mask,i)) {
      G[i/5][i%5]=1;
    }

    set<int> r,c;
    REP(i,5) {
      int cnt[2]={};
      REP(j,5) cnt[G[i][j]]++;
      r.emplace(min(cnt[0],cnt[1]));
    }
    REP(j,5) {
      int cnt[2]={};
      REP(i,5) cnt[G[i][j]]++;
      c.emplace(min(cnt[0],cnt[1]));
    }
    if(SZ(r)==1&&SZ(c)==1) {
      if(*r.begin()==2&&*c.begin()==1) {
        REP(i,5) dumpc(G[i]);
      }
      ps.emplace(*r.begin(), *c.begin());
    }
  }
  dumpc(ps);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;

  cin>>H>>W>>A>>B;
  solve();

  return 0;
}


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

int main() {
  ll n;cin>>n;
  int ans=1e9;
  for(int i=1;i<=sqrt(n);i++){
    if(n%i!=0)continue;
    ll j=n/i;
    string I=to_string(i),J=to_string(j);
    int a=I.size(),b=J.size();
    int f=max(a,b);
    ans=min(ans,f);
  }
  cout<<ans<<endl;
}

#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)
#define rrep(i, j, n) for (int i = (int)n - 1; j <= i; --i)

int main() {
  ll n;
  cin >> n;
  ll m = (ll)sqrt((double)n);

  auto d = [](ll x) {
    ll res = 0;
    while (x) {
      x /= 10;
      res++;
    }
    return res;
  };

  rrep(i, 1, m + 1) {
    if (n % i == 0) {
      cout << max(d(i), d(n / i)) << '\n';
      return 0;
    }
  }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back
#define Cout(s) cout << s << endl
string Yes(bool b) {if(b){return "Yes";} else {return "No";}}
string YES(bool b) {if(b){return "YES";} else {return "NO";}}

int main(){
	string S;
	cin >> S;
	if(S.size() == 3) reverse(all(S));
	Cout(S);
}

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

    if(S.size()==2){
        cout<<S<<endl;
    }
    else{
        cout<<S[2]<<S[1]<<S[0]<<endl;
    }
}


#include <iostream>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <cstring>

#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repn(i,n,m) for(int i=n;i<m;i++)
#define repn1(i,n,m) for(int i=n;i<=m;i++)
using namespace std;

int main(){

	int dp[100] = {0};
	int n;

	dp[1] = 1;
	dp[2] = 2;
	dp[3] = 4;

	repn1(i, 4, 30) dp[i] = dp[i-1] + dp[i-2] + dp[i-3];

	while(cin >> n, n){

		cout << dp[n] / 3650 + (dp[n]%3650==0 ? 0 : 1) << endl;
	}

	return 0;
}

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

int main() {
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }
        int table[11][11] = {};
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                cin >> table[i][j];
            }
        }
        for (int i = 0; i < n; i++) {
            int sum = 0;
            for (int j = 0; j < n; j++) {
                sum += table[i][j];
            }
            table[i][n] = sum;
        }
        for (int i = 0; i <= n; i++) {
            int sum = 0;
            for (int j = 0; j < n; j++) {
                sum += table[j][i];
            }
            table[n][i] = sum;
        }
        for (int i = 0; i <= n; i++) {
            for (int j = 0; j <= n; j++) {
                printf("%5d",table[i][j]);
            }
            printf("\n");
        }
    }
}


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

int main()
{
	int n, m;
	int p[1000];

	cin >> n >> m;

	while (n != 0 || m != 0) {
		for (int i = 0; i < n; i++)
			cin >> p[i];

		sort(p, p + n, greater<int>());

		int s = 0;
		for (int i = 0; i < n; i++) {
			if (i % m != m - 1)
				s += p[i];
		}
		cout << s << endl;

		cin >> n >> m;
	}

	return 0;
}

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

using ll = long long;
#define pq priority_queue
#define debug(x) cerr << #x << ": " << x << endl;
#define line() cerr << "---------------" << endl;

int main() {
   int n, m;
   while (cin >> n >> m) {
      if (n == 0 && m == 0) break;
      vector<int> v(n);
      int sum = 0;
      for (int &x : v) {
         cin >> x;
         sum += x;
      }
      sort(v.begin(), v.end(), greater<int>());
      for (int i = m-1; i < v.size(); i+=m) {
         sum -= v[i];
      }
      cout << sum << endl;
   }

   return 0;
}


//15
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  double l[12];
  double ls[13]={};
  for(;;){
    for(int i=0;i<12;i++){
      (cin>>l[i]).ignore();
      if(!cin)return 0;
      ls[i+1]=ls[i]+l[i];
    }
    cout<<lower_bound(ls,ls+11,l[10]*ls[10]/(l[10]+l[11]))-ls<<endl;
  }
  return 0;
}

#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
#define rep2(x,from,to) for(int x = (from); x < (to); ++(x))
#define rep(x,to) rep2(x,0,to)
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};
int b[14][14];
void dfs(int y, int x) {
	if(!b[y][x]) return;
	b[y][x] = 0;
	rep(i,4) {
		dfs(y+dy[i], x+dx[i]);
	}
}
int main() {
	string s;
	while(cin >> s) {
		rep(i,14) {
			b[0][i] = b[i][0] = 0;
			b[13][i] = b[i][13] = 0;
		}
		rep(i,12) {
			b[1][i+1] = s[i] - '0';
		}
		rep2(i,2,13) {
			cin >> s;
			rep(j,12) {
				b[i][j+1] = s[j] - '0';
			}
		}
		int cnt = 0;
		rep(i,14) {
			rep(j,14) {
				if(b[i][j]) {
					dfs(i,j);
					cnt++;
				}
			}
		}
		cout << cnt << endl;
	}
	return 0;
}


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

using namespace std;
 int main(){

  long long  x,y;
  cin>>x>>y;

  if(x*y < 0) cout<<abs(abs(x) - abs(y))+1<<endl;
  else if(x*y == 0){

   if(x<y) cout<<y-x<<endl;
   else cout<<x-y+1<<endl;
  }
  else {
     if(x<y) cout<<y-x<<endl;
     else
        cout<<x-y+2<<endl;

  }

 return 0;
 }

#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    int n;
    ll y;
    cin >> n >> y;

    for(ll i=0;10000*i<=y;i++){
        ll x=y-10000*i;
        for(ll j=0;5000*j<=x;j++){
            ll k=(x-5000*j)/1000;
            if(i+j+k==n){
                cout << i << " " << j << " " << k << endl;
                return 0;
            }
        }
    }

    cout << -1 << " " << -1 << " " << -1 << endl;

    return 0;
}


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

typedef long long ll;
typedef long double ld;
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    int N; cin >> N;
    int x, ans;
    for (int i = 9; i >= 1; i--) {
        x = i * 111;
        if (N <= x) ans = x;
    }
    cout << ans << endl;
    return 0;
}

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

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

constexpr ll INF = 1ll<<60;

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

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

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

ll N;

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

  std::cout << N/3 << std::endl;

  return 0;
}


#include <iostream>
#include <stdio.h>
#include <vector>
#include <math.h>
using namespace std;
int main(void){
    int N; cin >> N;
    int i = 0;
    int answer = 0;
    if (N / 100 > (N - N / 100 * 100) / 10) answer = N / 100;
    else if (N / 100 < (N - N / 100 * 100) / 10) answer = N / 100 + 1;
    else if ((N - N / 100 * 100) / 10 >= N % 10) answer = N / 100;
    else answer = N / 100 + 1;
    cout << answer << answer << answer << endl;
}

/*
ID: anonymo14
TASK: wormhole
LANG: C++
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {//227
	int i;
	cin>>i;
	for(;i<=999;i++) {
		if(i%10==(i%100)/10&&i%10==i/100){
			cout<<i;
			return;
		}
	}
}

int main() {

	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////

	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}


#include<stdio.h>
main(){
  int i,d,s;
  while(scanf("%d",&d)!=EOF){
    s=0;
    for(i=0;i<600/d;i++){
      s+=(d*((d*i)*(d*i)));
    }
    printf("%d\n",s);
  }
  return 0;
}

#include<bits/stdc++.h>

using namespace std;
int main()
{
	double r;
	cin>>r;
	cout<<2*r*M_PI;
}


#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
const int N = 500005;
int n,m;
map<ii, int> id;
vector<ii> G[N];
int ct = 1;
priority_queue<ii, vector<ii>, greater<ii> > pq;
int dist[N];
int main(){
    scanf("%d%d",&n,&m);
    ct = n+1;
    for (int i = 0; i < m; i++){
        int p,q,c;
        scanf("%d%d%d",&p,&q,&c);
        int a,b;
        if (id.count({p,c})) a = id[ii(p,c)];
        else{
            a = id[ii(p,c)] = ct++;
            G[a].push_back({p,1});
            G[p].push_back({a,1});
        }
        if (id.count({q,c})) b = id[ii(q,c)];
        else{
            b = id[ii(q,c)] = ct++;
            G[b].push_back({q,1});
            G[q].push_back({b,1});
        }
        G[a].push_back({b,0});
        G[b].push_back({a,0});
    }
    memset(dist,-1,sizeof(dist));
    dist[1] = 0;
    pq.push({0,1});
    while (pq.size()){
        int d, u;
        tie(d,u) = pq.top(); pq.pop();
        if (d > dist[u]) continue;
        for (auto v : G[u]){
            int nd = d + v.second;
            if (dist[v.first] == -1 || dist[v.first] > nd){
                dist[v.first] = nd;
                pq.push({nd,v.first});
            }
        }
    }
    if (dist[n] == -1) printf("-1\n");
    else printf("%d",dist[n]/2);

}

// #pragma GCC optimize("O3")
// #pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
// #define int ll
// #define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sz(a)((int)(a).size())
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);iostream::sync_with_stdio(0);cout<<fixed<<setprecision(10);cerr<<fixed<<setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...)
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());const int D=4,dx[]={+1,0,-1,0},dy[]={0,+1,0,-1};

const int N=1e5+5,OO=1e9;
vector<pii> gg[N];
vector<int> v[N];
vector<int> num[N];
int xx[N*4],zz[N*4],dist[N*4];
vector<vector<int>> g[N];
int u[N];
int q[N*8];
int32_t main(){
    int n,m;
    cin>>n>>m;
    forn(i,m){
        int x,y,z;
        cin>>x>>y>>z;
        gg[x].pb(y,z);
        gg[y].pb(x,z);
        v[x].pb(z);
        v[y].pb(z);
    }
    int cnt=0;
    for(int i=1;i<=n;++i){
        sort(v[i].begin(), v[i].end());
        v[i].resize(unique(v[i].begin(), v[i].end())-v[i].begin());
        g[i].resize(sz(v[i]));
        num[i].resize(sz(v[i]));
        forn(j,sz(v[i])){
            xx[cnt]=i;zz[cnt]=j;
            dist[cnt]=OO;
            num[i][j]=cnt++;
        }
        for(pii p:gg[i]){
            int to=p.f,z=p.s;
            z=lower_bound(v[i].begin(), v[i].end(),z)-v[i].begin();
            g[i][z].pb(to);
        }
    }
    int l=N*3,r=N*3;
    forn(i,sz(v[1])){
        dist[num[1][i]]=1;
        q[r++]=num[1][i];
    }
    u[1]=1;
    while(l<r){
        int nu=q[l++];
        int x=xx[nu],pz=zz[nu];
        int z=v[x][pz];
        if(!u[x]){
            u[x]=1;
            forn(i,sz(v[x])){
                int nt=num[x][i];
                if(dist[nt]>dist[nu]+1){
                    dist[nt]=dist[nu]+1;
                    q[r++]=nt;
                }
            }
        }
        for(int to:g[x][pz]){
            int pzt=lower_bound(v[to].begin(), v[to].end(),z)-v[to].begin();
            int nt=num[to][pzt];
            if(dist[nt]>dist[nu]){
                dist[nt]=dist[nu];
                q[--l]=nt;
            }
        }
    }
    int ans=OO;
    forn(i,sz(v[n]))upn(ans,dist[num[n][i]]);
    if(ans==OO)ans=-1;
    cout<<ans<<'\n';
    return 0;
}


#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define int long long
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int INF = 1e9, MOD = 1e9 + 7; /// think
const ll LINF = 1e18;

const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
    return 0 <= x && 0 <= y && x < n && y < m;
}

template<class T> bool umin (T &a, T b) {return a > b ? (a = b, true) : false; }
template<class T> bool umax (T &a, T b) {return a < b ? (a = b, true) : false; }

main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector <int> a(n);
    vector <vector<pii> > b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        b[i].resize(a[i]);
        for (auto &j : b[i]) {
            cin >> j.y >> j.x;
            --j.y;
        }
    }
    int ans = 0;
    for (int i = 1; i < (1 << n); i++) {
        int res = 0;
        vector <int> used(n);
        for (int j = 0; j < n; j++) {
            if (i & (1 << j)) {
                ++res;
                used[j] = 1;
            }
        }
        if (ans >= res) continue;
        bool ok = true;
        for (int j = 0; j < n; j++) {
            if (!used[j]) continue;
            for (auto &k : b[j]) {
                if (k.x) {
                    if (!used[k.y]) {
                        ok = false;
                    }
                }
                else {
                    if (used[k.y]) {
                        ok = false;
                    }
                }
            }
        }
        if (ok) ans = res;
    }
    cout << ans << '\n';
}

#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647 -> 10桁
// MAX ll 9,223,372,036,854,775,807 -> 19桁
// MAX O(n) 10^8 -> 8回
// double pi = M_PI or acos(-1)
// printf("%.10f\n", ans);

int g[15][15];

int main() {
    int n;
    cin >> n;
    rep(i, n) rep(j, n) g[i][j] = -1;
    rep(i, n) {
        int m;
        cin >> m;
        rep(j, m) {
            int a, x;
            cin >> a >> x;
            --a;
            g[i][a] = x;
        }
    }
    int ans = 0;
    rep(i, 1 << n) {
        vector<int> d(n);
        rep(j, n) if(i >> j & 1) {
            d[j] = 1;
        }
        bool ok = true;
        rep(j, n) {
            if(d[j]) {
                rep(k, n) {
                    if (g[j][k] == -1) continue;
                    if (g[j][k] != d[k]) ok = false;
                }
            }
        }
        if (ok) ans = max(ans, __builtin_popcount(i));
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  int n,q; string s;
  cin >> n >> q >> s;
  vector<int> a(n+1,0);
  rep(i,1,n+1) {
    if (s.substr(i-1,2) == "AC") {
      a[i]++;
    }
    a[i] += a[i-1];
  }
  rep(i,0,q) {
    int l,r;
    cin >> l >> r;
    int ans = a[r] - a[l];
    if (a[l] != a[l-1]) ans++;
    if (a[r] != a[r-1]) ans--;
    cout << ans << endl;
  }
  return 0;
}

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

int main() {
  int N, doubt=0, M=0;
  cin >> N;
  vector<vector<pp>> V(N, vector<pp>(0));

  int A, p, q;

  for (int i=0; i<N; i++) {
    cin >> A;
    for (int j=0; j<A; j++) {
      cin >> p >> q;
      V[i].push_back(pp(p,q));
    }
  }

  for (int b=0; b<(1<<N); b++) {
    bitset<15> s(b);
    vector<int> W(N);
    doubt=0;

    for (int i=0; i<N; i++) {
      W[i]=s.test(i);
      //cout << W[i] << endl;
    }

    for (int i=0; i<N; i++) {
      if (s.test(i)) {
        for (int j=0; j<(int)V[i].size(); j++) {
          int x=V[i][j].first, y=V[i][j].second;
          if (W[x-1]!=y) {
            doubt=1;
            break;
          }
        }
        if (doubt==1) {break;}
      }
    }
    if (doubt==0) {
      int rr=0;
      for (int i=0; i<N; i++) {
        rr+=s.test(i);
      }
      M=max(M, rr);
      //cout << M << endl;
    }
  }
  cout << M << endl;
}


#include<bits/stdc++.h>
typedef long long ll;
typedef std::pair<ll,ll> P;

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

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 (b < a) { a = b; return 1; } return 0; }

constexpr ll mod = 1e9 + 7;

struct UnionFind {
public:
	vector <ll> par; //
	vector <ll> siz; //

	UnionFind() {}

	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}

	ll root(ll x) {
		while (par[x] != x) {
			x = par[x] = par[par[x]];
		}
		return x;
	}

	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}

	bool issame(ll x, ll y) {
		return root(x) == root(y);
	}

	ll size(ll x) {
		return siz[root(x)];
	}
};

int main() {
	ll n;
	cin >> n;
	vector<int> ans;
	for (int i = 0; i < 60; i++) {
		ll m = n % (1LL << (i+1));
		if (m) {
			ans.push_back(1);
			ll sub = 1LL << i;
			if (i % 2 == 1) {
				sub *= -1;
			}
			n -= sub;
		}
		else ans.push_back(0);
		if (n == 0) break;
	}
	reverse(ans.begin(), ans.end());
	for (auto a : ans) {
		cout << a;
	}
	cout << endl;
	return 0;
}

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

int main(){
  int n;
  cin >> n;
  string s = "";
  while(n != 0){
    int r = n%2;
    if (r < 0) r +=2;
    n = (n-r)/(-2);
    s += (char)('0' + r);
  }
  reverse(s.begin(),s.end());
  if (s == "") s = "0";
  cout << s << endl;

}


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

int main()
{
    ll a,b,i,cnt=0;
    scanf("%lld %lld", &a, &b);
    while(a<=b){
        string s;
        s = to_string(a);
        if(s[0]==s[4] && s[1]==s[3]){
            cnt++;
        }
        a++;
    }
    printf("%lld\n", cnt);
    return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;

  int a12 = a/1000;
  int a21 = a12/10 + a12%10*10;
  int b12 = b/1000;
  int b21 = b12/10 + b12%10*10;

  // 上２ケタがa12でaより小さいのを弾く
  int count_less_than_a = 0;
  for (int i = 0; i <= 9; i++) {
    if (a12*1000 + i*100 + a21 < a){
      count_less_than_a++;
    }
    else {
      break;
    }
  }

  // 上２ケタがb12でbより大きいのを弾く
  int count_more_than_b = 0;
  for (int i = 9; i >= 0; i--) {
    if (b12*1000 + i*100 + b21 > b){
      count_more_than_b++;
    }
    else {
      break;
    }
  }

  int result = (b12 - a12 +1) * 10
    - count_less_than_a - count_more_than_b;

  cout << result << endl;

}


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

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

int main(void)
{
    ll n; cin>>n;
    ll ans=1;
    for(ll i=1;i<=n;i++){
        if(i*i<=n) ans=max(ans,i*i);
    }
    cout<<ans<<endl;
    return 0;
}

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

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

  cout << ll(sqrt(n)) * ll(sqrt(n)) << endl;

  return 0;
}


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

bool furui[10010];
vector<int> prime;
vector<int> twin;

void mkprime() {
	for(int i = 0; i < 10010; i++) furui[i] = true;
	furui[0] = furui[1] = false;
	for(int i = 0; i < 10010; i++) {
		if(furui[i]) {
			prime.push_back(i);
			for(int j = i * 2; j < 10010; j += i) {
				furui[j] = false;
			}
		}
	}
	for(int i = 0; i < prime.size() - 1; i++) {
		if(prime[i + 1] - prime[i] == 2)
			twin.push_back(prime[i + 1]);
	}
	sort(twin.begin(), twin.end());
}

int main() {
	int n;
	mkprime();
	while(cin >> n, n) {
		vector<int>::iterator iter;
		iter = upper_bound(twin.begin(), twin.end(), n);
		cout << *(iter-1) - 2 << " " << *(iter-1) << endl;
	}
}

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

bool isprime(int n);

int main(void){
  int n;
  while(1){
    cin>>n;
    if(n==0)break;

    for(int j=n;j>0;j--){
      if(isprime(j) && isprime(j-2)){
        cout<<j-2<<" "<<j<<endl;
        break;
      }
    }
  }
  return 0;
}

bool isprime(int n){
  for(int i=2;i<min((int)sqrt(n)+1,n);i++){
    if(n%i==0){
      return false;
    }
  }
  return true;
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i=0; i<n; ++i) {
        cin >> a.at(i);
    }

    ll sumO = 0, sumE = 0;
    for (int i=0; i<n; ++i) {
        if (i % 2 == 0) sumO += a.at(i);
        else sumE += a.at(i);
    }
    if (n % 2 == 0) {
        ll res = sumE;
        ll curO = 0, curE = 0;
        for (int i=0; i<n; ++i) {
            if (i % 2 == 0) {
                curO += a.at(i);
            } else {
                curE += a.at(i);
                chmax(res, sumE + curO - curE);
            }
        }
        cout << res << '\n';
    } else {
        ll res = sumE;
        ll curO = 0, curE = 0;
        vector<ll> diff(n);
        for (int i=0; i<n; ++i) {
            if (i % 2 == 0) {
                curO += a.at(i);
            } else {
                curE += a.at(i);
                chmax(diff.at(i), curO - curE);
                if (i > 1) chmax(diff.at(i), diff.at(i-2));
            }
        }
        chmax(res, sumE + diff.at(n-1));
        curO = curE = 0;
        ll maxi = 0;
        for (int i=n-1; i>=0; --i) {
            if (i % 2 == 0) {
                curO += a.at(i);
            } else {
                curE += a.at(i);
                chmax(maxi, curO - curE);
                if (i == 1) chmax(res, sumE + maxi);
                else chmax(res, sumE + diff.at(i-2) + maxi);
            }
        }
        cout << res << '\n';
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

ll sol_even(int n, const vector<ll> &a) {
    ll dp[200200][2];
    rep(i,200200) rep(j,2) dp[i][j] = -LINF;
    dp[0][0] = a[0];
    dp[1][1] = a[1];
    rep(i,n) {
        if (i+2 < n) chmax(dp[i+2][0], dp[i][0]+a[i+2]);
        if (i+3 < n) chmax(dp[i+3][1], dp[i][0]+a[i+3]);
        if (i+2 < n) chmax(dp[i+2][1], dp[i][1]+a[i+2]);
    }

    return max(dp[n-2][0], dp[n-1][1]);
}

ll dp[200200][3][2];
ll sol_odd(int n, const vector<ll> &a) {
    rep(i,200200) rep(j,3) rep(k,2) dp[i][j][k] = -LINF;
    dp[0][0][0] = a[0];
    dp[1][1][0] = a[1];
    dp[2][2][0] = a[2];
    rep(i,n) {
        if (i+2 < n && i+2 != n-1) chmax(dp[i+2][0][0], dp[i][0][0]+a[i+2]);
        if (i+3 < n) chmax(dp[i+3][1][0], dp[i][0][0]+a[i+3]);
        if (i+4 < n) chmax(dp[i+4][0][1], dp[i][0][0]+a[i+4]);
        if (i+3 < n) chmax(dp[i+3][2][0], dp[i][1][0]+a[i+3]);
        if (i+2 < n) chmax(dp[i+2][1][0], dp[i][1][0]+a[i+2]);
        if (i+2 < n) chmax(dp[i+2][2][0], dp[i][2][0]+a[i+2]);
        if (i+2 < n) chmax(dp[i+2][0][1], dp[i][0][1]+a[i+2]);
    }
    return max({dp[n-3][0][0], dp[n-2][1][0], dp[n-1][2][0], dp[n-1][0][1]});
}

int main(int argc, char const *argv[]) {
    int n; cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    if (n%2) cout << sol_odd(n,a) << '\n';
    else cout << sol_even(n,a) << '\n';

    return 0;
}


#include <iostream>
#include <vector>

using namespace std;

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

	typedef vector<int> IntVector;
	IntVector a(n, 0);

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

	IntVector::const_reverse_iterator ritEnd = a.rend();
	for (IntVector::const_reverse_iterator rit = a.rbegin(); rit != ritEnd; ++rit)
	{
		cout << *rit;
		if (rit == ritEnd - 1)
			cout << endl;
		else
			cout << " ";
	}

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main(){

    int n;
    int a[100];

    cin>>n;

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

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

    for( int i=0; i<n; i++){
        if(i) cout<<" ";
        cout<<a[i];
    }

    cout<<endl;

    return 0;
}


/**
 *    author:  otera
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

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

#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
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);
}

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

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

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


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

using namespace std;

void swap(int &a, int &b) {
	int t = a;
	a = b;
	b = t;
}

int partition(vector<int> &A, int p, int r) {
	int x = A[r];
	int i = p;
	for (int j = p; j < r; j++) {
		if (A[j] <= x) {
			swap(A[i], A[j]);
			i++;
		}
	}
	swap(A[i], A[r]);
	return i;
}

int main() {
	int n = 0;
	cin >> n;
	vector<int> v;
	v.resize(n);

	{
		vector<int>::iterator i = v.begin();
		copy(istream_iterator<int>(cin), istream_iterator<int>(), i++);
	}
	int p = partition(v, 0, n-1);

	for (int i = 0; i < n; i++) {
		if (i == p) {
			cout << "[" << v[i] << "] ";
		}
		else if (i == n - 1) {
			cout << v[i] << "\n";
		}
		else {
			cout << v[i] << " ";
		}
	}
	return 0;
}

#include <stdio.h>

#define N 1000000
int n;
int S[N];

int partition(int n){
	int x = S[n];
	int i,p=0;
	int tmp;
	int j;
	for(i = 0;i < n;i++){
		//printf("%d\n",i);
		if(S[i] <= x){
			tmp  = S[i];
			S[i] = S[p];
			S[p] = tmp;
			p++;
		}
		/*
		for(j=0;j<n+1;j++){
			printf("%d ",S[j]);
		}
		printf("\n");
		printf("p = %d\n",p);*/
	}
	tmp = S[p] ;
	S[p] = S[n];
	S[n] = tmp;
	return p;
}

int main(){
	scanf("%d",&n);
	int i;
	for(i=0;i<n;i++){
		scanf("%d",&S[i]);
	}
	int m = partition(n-1);
	for(i = 0;i< n;i++){
		if(m == i){
			printf("[%d] ",S[i]);
		}
		else if(i == n-1)printf("%d\n",S[i]);
		else printf("%d ",S[i]);
	}
	return 0;
}


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

int main()
{
        ll N; cin >> N;
        vector<ll> A(N, 0);
        map<ll, ll, greater<ll>> m;
        for (int i = 0; i < N; ++i) {
                cin >> A[i];
                m[A[i]]++;
        }
        int cnt = 0;
        ll a = 0;
        ll b = 0;
        for (auto i : m) {
                if (i.second > 1) {
                        if (cnt == 0) {
                                a = i.first;
                                if (i.second > 3) {
                                        b = i.first;
                                        break;
                                }
                                cnt++;
                        }
                        else {
                                b = i.first;
                                break;
                        }
                }
        }
        cout << a * b << 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 <iostream>
#include <vector>
#include <stack>

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

using namespace std;

void makeStackRecur(vector<vector<int> > &g, int u, stack<int> &out, vector<bool> &seen) {
    seen[u] = true;
    for(int v: g[u])
        if (! seen[v])
            makeStackRecur(g, v, out, seen);
    out.push(u);
}

void makeStack(vector<vector<int> > &g, int u, vector<bool> &seen, stack<int> &vStack) {
    makeStackRecur(g, u, vStack, seen);
}
void getConnectedCompRecur(vector<int> &rootGroup, vector<vector<int> > &invGraph, int u, int root) {
    if (rootGroup[u] == -1) {
        rootGroup[u] = root;
        for(int v: invGraph[u])
            getConnectedCompRecur(rootGroup, invGraph, v, root);
    }
}

void getConnectedComp(vector<int> &rootGroup, vector<vector<int> > &invGraph, stack<int> &vStack) {
    while (! vStack.empty()) {
        int u = vStack.top();
        vStack.pop();
        getConnectedCompRecur(rootGroup, invGraph, u, u);
    }
}
int main () {
    int V, E;
    cin >> V >> E;

    vector<vector<int> > graph(V);
    vector<vector<int> > invGraph(V);
    vector<bool> seen(V, false);
    vector<int> rootGroup(V, -1);

    FOR(i,E) {
        int s, t;
        cin >> s >> t;

        graph[s].push_back(t);
        invGraph[t].push_back(s);
    }

    stack<int> vStack;
    FOR(i, V)
        if (! seen[i]) makeStack(graph, i, seen, vStack);

    FOR(i, V)
        if (rootGroup[i] == -1) getConnectedComp(rootGroup, invGraph, vStack);

    int Q;
    cin >> Q;
    FOR(i,Q) {
        int f, t;
        cin >> f >> t;
        cout << (rootGroup[f] == rootGroup[t]) << endl;
    }
}

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

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

long long MOD = 10000000000 + 7;

int main(){
  cout << setprecision(10);
  int N, u, v; cin >> N >> u >> v;
  u--; v--;

  vector<vector<int>> e(N);
  for(int i = 0; i < N-1; i++){
    int x,y; cin >> x >> y;
    x--; y--;
    e[x].push_back(y);
    e[y].push_back(x);
  }

  vector<int> a(N,-1);
  vector<int> t(N,-1);
  t[u] = 0;
  a[v] = 0;

  queue<int> qt,qa;

  qt.push(u);
  while(!qt.empty()){
    int now = qt.front();
    qt.pop();
    for(int next: e[now]){
      if(t[next] == -1){
        t[next] = t[now] + 1;
        qt.push(next);
      }
    }
  }

  int dist = t[v];

  qa.push(v);
  while(!qa.empty()){
    int now = qa.front();
    qa.pop();
    for(int next: e[now]){
      if(a[next] == -1){
        a[next] = a[now] + 1;
        qa.push(next);
      }
    }
  }
  t[u] = 2;

  int ans = 0;
  for(int i = 0; i < N; i++){
    if(a[i] >= t[i]){
      ans = max(ans, a[i]);
    }
  }
  cout << max(ans-1,0) << endl;
  // cerr << "dist: " << dist;

}


#include <bits/stdc++.h>

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

using namespace std;

typedef long long ll;

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

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

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

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

#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  string S;
  cin >> S;

  int len = S.size();

  int ans = 1000;
  for (int i = 0; i < len - 2; i++){
    int x = (S[i] - '0') * 100 + (S[i + 1] - '0') * 10 + (S[i + 2] - '0');
    ans = min(abs(x - 753), ans);
  }
  cout << ans << endl;
}


#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

typedef long long ll;

const ll M = 4e18;

ll n, m, mn = M;
vector<ll> ve[1005];
vector<ll> ans;
vector<ll> now;
ll vv[1005];

void dfs(ll p)
{
    if(now.size() != 0 && p == now[0])
    {
        if(mn > now.size())
        {
            mn = now.size();
            ans = now;
        }
        return;
    }
    else if(vv[p]) return;
    if(now.size() > mn) return;
    vv[p] = true;
    now.push_back(p);
    for(ll i = 0; i < ve[p].size(); i++)
    {
        dfs(ve[p][i]);
    }
//    vv[p] = false;
    now.pop_back();
}

int main()
{
    scanf("%lld%lld", &n, &m);
    for(ll i = 0; i < m; i++)
    {
        ll u, v;
        scanf("%lld%lld", &u, &v);
        ve[u].push_back(v);
    }
    for(ll i = 1; i <= n; i++)
    {
        for(ll i = 1; i <= n; i++) vv[i] = false;
        dfs(i);
    }
    if(mn == M) printf("-1\n");
    else
    {
        printf("%lld\n", mn);
        for(ll i = 0; i < ans.size(); i++)
        {
            printf("%lld\n", ans[i]);
        }
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    ll n, m;
    cin >> n >> m;
    vector<vector<ll>> g(n), r(n);
    rep(i, m) {
        ll a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        r[b].push_back(a);
    }
    vector<ll> ans(n + 1);
    rep(i, n) {
        queue<ll> q;
        vector<ll> dist(n, LONG_LONG_MAX);
        vector<ll> prev(n, LONG_LONG_MAX);
        q.push(i);
        dist[i] = 0;
        while(!q.empty()) {
            ll now = q.front(); q.pop();
            rep(ii, sz(g[now])) {
                ll next = g[now][ii];
                if (dist[next] <= (dist[now] + 1)) continue;
                dist[next] = dist[now] + 1;
                prev[next] = now;
                q.push(next);
            }
        }
        vector<ll> tmp;
        q.push(i);
        tmp.push_back(i);
        while(!q.empty()) {
            ll now = q.front(); q.pop();
            ll mi = -1, mv = LONG_LONG_MAX;
            rep(ii, sz(r[now])) {
                ll next = r[now][ii];
                if (mv <= dist[next]) continue;
                mv = dist[next];
                mi = next;
            }
            if ((mv == LONG_LONG_MAX) || (mi == i)) break;
            tmp.push_back(mi);
            q.push(mi);
        }
        if ((sz(tmp) == 1) || (sz(tmp) >= sz(ans))) continue;
        reverse(tmp.begin() + 1, tmp.end());
        ans = tmp;
    }
    if (sz(ans) == (n + 1)) {
        cout << -1 << endl;
    }
    else {
        cout << sz(ans) << endl;
        rep(i, sz(ans)) cout << (ans[i] + 1) << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

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

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

  bool digits[10] = {false};

  for (int i = 0; i < k; ++i) {
    int x; cin >> x;
    digits[x] = true;
  }

  while (n <= INT_MAX) {
    int tmp = n;

    while (tmp) {
      int d = tmp % 10;
      if (digits[d]) break;
      else tmp /= 10;
    }

    if (tmp == 0) break;
    else n++;
  }

  cout << n << "\n";
}

#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

int h, w;
vector< string > field;
vector< vector< bool > > reached;

using P = pair<s64, s64>;

P dfs(int y, int x, char c)
{
    P ret{0, 0};
    if (c == '#') ret.first = 1;
    else ret.second = 1;

    reached[y][x] = true;
    int dy[] = {-1, 0, 1, 0};
    int dx[] = {0, -1, 0, 1};
    rep (i, 4)
    {
        int ny = y + dy[i];
        int nx = x + dx[i];
        if (IN(0, h, ny) && IN(0, w, nx) && !reached[ny][nx] && field[ny][nx] != c)
        {
            P temp = dfs(ny, nx, field[ny][nx]);
            ret.first += temp.first;
            ret.second += temp.second;
        }
    }

    return ret;
}

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

    cin >> h >> w;
    field.resize(h);
    reached.resize(h, vector<bool>(w, false));
    rep (i, h) cin >> field[i];

    s64 ans = 0;
    rep (i, h)
    {
        rep (j, w)
        {
            if (!reached[i][j] && field[i][j] == '#')
            {
                P p = dfs(i, j, '#');
                ans += p.first * p.second;
            }
        }
    }

    cout << ans << "\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll=long;
#define V v[i]

int main(){
  ll t;cin>>t;
  while(t--){
    ll n,Q=0;cin>>n;
    vector<ll>v(n),N;
    for(ll &p:v)cin>>p;
    string s;cin>>s;
    for(ll i=n-1;i>=0;i--){
      for(ll p:N)V=min(V,V^p);
      N.push_back(V);
      Q|=s[i]=='1'&&V;
    }
    cout<<Q<<endl;
  }
}


#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
template<typename T> auto compare = [](T x, T y) -> bool{return (x < y);};
const int MOD = 1000000007;

int N;
ll A[200010];

signed main(){
    cin >> N;
    REP(i, N) cin >> A[i];
    REP(i, N){
        if(i < A[i] || A[i] + 1 < A[i + 1]){
            PRINT("-1");
            return 0;
        }
    }
    ll ans = 0;
    for(int i = N - 1; i > 0; i--){
        if(A[i - 1] < A[i]){
            ans++;
        }else{
            ans += A[i];
        }
    }
    PRINT(ans);
    return 0;
}

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

int main() {
    int A;
    int B;
    int C;
    int D;
    int L;
    int R;
    cin >> A >> B >> C >> D;
    L = A + B;
    R = C + D;

    if (L > R){
        cout << "Left" << endl;
    }

    else if (L == R) {
        cout << "Balanced" << endl;
    }

    else if (L < R){
        cout << "Right" <<endl;
    }

}


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

int main(){
  int N,Q;
  cin >> N >> Q;

  vector<int> data(N);
  for(int i=0; i<N; i++){
    cin >> data.at(i);
  }

  vector<int> cumsumL(N+1);
  vector<int> cumsumR(N+1);
  for(int i=1; i <= N; i++){
    cumsumL.at(i)= cumsumL.at(i-1)+ data.at(i-1);
    cumsumR.at(i)= cumsumR.at(i-1)+ data.at(N-i);
  }

  int QpopMAX= min(N, Q);
  int ans= 0;
  for(int Qpop=0; Qpop <= QpopMAX; Qpop++){
    for(int QpopL=0; QpopL <= Qpop; QpopL++){
      int QpopR= Qpop- QpopL;
      priority_queue<int, vector<int>, greater<int>> items;
      for(int i=0; i<QpopL; i++){
        items.push(data.at(i));
      }
      for(int i=1; i<=QpopR; i++){
        items.push(data.at(N-i));
      }

      int cand= cumsumL.at(QpopL)+ cumsumR.at(QpopR);
      ans= max(ans, cand);

      int Qpush= min(Q- Qpop, Qpop);
      for(int q=0; q<Qpush; q++){
        int cut_cand= items.top();
        if(cut_cand < 0){
          items.pop();
          cand-= cut_cand;
          ans= max(ans, cand);
        }
        else{
          break;
        }
      }
    }
  }

  cout << ans << endl;
}

#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

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

ll gcd(ll a, ll b) {return (!b ? a : gcd(b, a % b));}
ll lcm(ll a, ll b) {return ((a*b)/gcd(a,b));}
bool cmp(int a,int b){return a>b;}

const ll mod = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
const ld pi = 3.141592653589793;
const int N = 1e6 + 10;

long long modpow(long long n, long long k, long long mod)
{
if (k == 0) return 1;
long long r = modpow(n * n % mod, k >> 1, mod);
if (k & 1) r = r * n % mod;
return r;
}

void solve(){
     int n,k;cin >> n >> k;
     vector<int>a(n);
     int cnt = 0;
     int sum = 0;
     for(int i = 0;i<n;i++){
        cin >> a[i];
        if(a[i]>0) sum += a[i];
        if(a[i]<0) cnt++;
     }
    if(k>=n+cnt){
        cout << sum;
        return;
    }
    vector<int>l(220,0);
    multiset<int>ms;
    l[0] = 0;int now = 0;
    for(int i = 0;i<k;i++){
        int cnt = 0;sum = 0;
        now += a[i];
        ms.insert(a[i]);
        l[i+1] = max(l[i+1],max(l[i],now));
        for(auto it : ms){
            if(it<0) {cnt++;sum += it;l[i+cnt+1] = max(now-sum,l[i+cnt+1]);}
            else break;
        }
       // cout << l[i+1] <<endl;
    }
    ms.clear();
    vector<int>r(220,0);
    r[0] = 0;
    reverse(a.begin(),a.end());
    now = 0;
    for(int i = 0;i<k;i++){
        int cnt = 0;sum = 0;
        now += a[i];
        ms.insert(a[i]);
        r[i+1] = max(r[i+1],max(r[i],now));
        for(auto it : ms){
            if(it<0) {cnt++;sum += it;r[i+cnt+1] = max(r[i+cnt+1],now-sum);}
            else break;
        }
    }
    int ans = 0;
    for(int i = 0;i<=k;i++){
        ans = max(ans,r[i]+l[k-i]);
    }
    cout << ans;
}

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


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

const int64_t MOD = 1000000007;
typedef int64_t ll;
typedef uint64_t ull;

#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;

	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

/*
  //エラトステネスのふるい
  int maxNum = 100000;
  char isNotPrime[maxNum+1] = {};
  isNotPrime[0]=isNotPrime[1]=1;
  for(int i=2;i<maxNum;i++){
    if(isNotPrime[i]==1) continue;
    int num = i+i;
    while(num<=maxNum){
      isNotPrime[num]=1;
      num += i;
    }
  }
*/
// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

// 降順ソート vector<int> v;
// sort(v.begin(),v.end(),greater<int>());

signed main() {
  ll n,t;
  cin >> n >> t;

  ll total = 0;
  int a = 0;
  int prevA = -t-1;
  for(int i=0;i<n;i++){
    cin >> a;
    total += t;

    if(a-prevA<=t){
      total -= t-(a-prevA);
    }
    prevA = a;
  }

  cout << total << endl;

  return 0;
}

#include<iostream>
using namespace std;

int main(){
    int n,t;
    cin>>n>>t;
    int a[n];
    long long ans=0;
    cin>>a[0];
    for(int i=1;i<n;i++){
        cin>>a[i];
        if(a[i]-a[i-1]>t){
            ans+=t;
        }else{
            ans+=a[i]-a[i-1];
        }
    }
    ans+=t;
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

using ll = long long;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

#define input(...) __VA_ARGS__; in(__VA_ARGS__)

template<class T>
void print(vector<T> a) {
  cout << "[ ";
  REP(i, a.size()) cout << a[i] << " ";
  cout << "]" << endl;
}

void print() {
  std::cout << std::endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cout << head << " ";
  print(std::forward<Tail>(tail)...);
}

void in() { }

template <class Head, class... Tail>
void in(Head&& head, Tail&&... tail) {
  cin >> head;
  in(std::forward<Tail>(tail)...);
}

ll n, x;
vector<ll> s;
vector<vector<ll>> table;
ll MOD = 1000000000 + 7;
ll powmod(ll v, ll x) {
  if (x == 0) return 1;
  if (x % 2 == 0) {
    ll tmp = powmod(v, x / 2);
    return (tmp * tmp) % MOD;
  } else {
    return (powmod(v, x - 1) * v) % MOD;
  }
}

#define DP table[i][a]
ll dfs(ll i, ll a) {
  if (DP != -1) return DP;
  if (i == n) return DP = a;

  // double p = 1. / (n - i);
  ll p = powmod(n - i, MOD - 2);
  return DP = ((dfs(i + 1, a % s[i]) * p) % MOD + (dfs(i + 1, a) * ((1 - p + MOD) % MOD)) % MOD) % MOD;

  /* if (i == n - 1) return DP = a % s[n - 1]; */
  /* return DP = (dfs(i + 1, a % s[i]) + dfs(i + 1, a)) % MOD; */
}

int main() {
  cin >> n >> x;
  s = vector<ll>(n);
  REP(i, n) cin >> s[i];
  sort(s.begin(), s.end(), greater<ll>());
  table = vector<vector<ll>>(n + 1, vector<ll>(x + 1, -1));
  ll fact = 1;
  FOR(i, 1, n) {
    (fact *= i) %= MOD;
  }
  cout << dfs(0, x) * fact % MOD << endl;
}


#include<iostream>
#include<cstdio>
using namespace std;
int main() {
	int siz[6], damy;
	char mozi[2];
	for (int abc = 0; abc < 6; abc++) {
		cin >> siz[abc];
	}
	fgets(mozi,2,stdin);
	while(true){
		fgets(mozi,2,stdin);
		if (mozi[0] == '\n') {
			cout << siz[0] << endl;
			break;
		}
		switch (mozi[0]) {
		case 'S':
			damy = siz[0];
			siz[0] = siz[4];
			siz[4] = siz[5];
			siz[5] = siz[1];
			siz[1] = damy;
			break;
		case 'E':
			damy = siz[0];
			siz[0] = siz[3];
			siz[3] = siz[5];
			siz[5] = siz[2];
			siz[2] = damy;
			break;
		case 'N':
			damy = siz[0];
			siz[0] = siz[1];
			siz[1] = siz[5];
			siz[5] = siz[4];
			siz[4] = damy;
			break;
		case 'W':
			damy = siz[0];
			siz[0] = siz[2];
			siz[2] = siz[5];
			siz[5] = siz[3];
			siz[3] = damy;
			break;
		}
	}
	return 0;
}

 #include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 #include<functional>
 #include<utility>

 using namespace std;

 int main()
 {
   int up,down,front,back,left,right;
   cin>>up>>front>>right>>left>>back>>down;
   string com;
   cin>>com;
   for(int i=0;i<com.length();i++)
   {
     if(com[i]=='S')
     {
       int temp=down;
       down=front;
       front=up;
       up=back;
       back=temp;
     }
     else if(com[i]=='W')
     {
       int temp=left;
       left=up;
       up=right;
       right=down;
       down=temp;
     }
     else if(com[i]=='N')
     {
       int temp=front;
       front=down;
       down=back;
       back=up;
       up=temp;
     }
     else
     {
       int temp=up;
       up=left;
       left=down;
       down=right;
       right=temp;
     }
   }
   cout<<up<<endl;
   //while(1);
   return 0;
 }


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

int main() {

  long long n;
  cin >> n;

  long long ans = 0;

  for(int i = 1; i <= n; i++){
    if(i % 3 == 0 && i % 5 == 0) {
      //FizzBuzz
    } else if(i % 3 == 0) {
      //Fizz
    } else if(i % 5 == 0) {
      //Buzz
    } else {
      ans = ans + i;
    }
  }

  cout << ans;

}


#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int k,t;
  cin >> k >> t;
  vi a(t);
  int maxnum = 0, pos;
  rep(i, t){
    cin >> a[i];
    if(a[i] > maxnum){
      maxnum = a[i];
      pos = t;
    }
  }
  int ans = maxnum - 1;
  ans = max(ans - k + maxnum, 0);
  cout << ans << endl;
}

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(int (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
const double PI = 3.1415926535897932384626433832795;
const int mod = 1000000007;
const int INF = 1001001001;

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

int h, w;
vector<vector<bool>> used(400, vector<bool>(400));
ll black = 0, white = 0;

void dfs(int x, int y, vector<string> &s) {
  if (used[x][y]) return;
  used[x][y] = true;
  if (s[x][y] == '.') white++;
  else black++;

  char cur = s[x][y];
  rep(i, 4) {
    int nx = dx[i] + x;
    int ny = dy[i] + y;
    if (0 <= nx && nx < h && 0 <= ny && ny < w) {
      char next = s[nx][ny];
      if (next != cur) {
        dfs(nx, ny, s);
      }
    }
  }
}

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

  ll ans = 0;
  rep(i, h) rep(j, w) {
    black = white = 0;
    dfs(i, j, s);
    ans += black * white;
  }

  cout << ans << endl;
}