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

int main() {
  string s;
  int alp[27];
  for (int i = 0; i < 26; i++) {
    alp[i] = 0;
  }
  alp[26] = 1;

  cin >> s;
  if (s == "zyxwvutsrqponmlkjihgfedcba") {
    puts("-1");
  } else {
    string ans = "";
    for (int i = 0; i < (int)s.size(); i++) {
      alp[s[i] - 'a']++;
    }

    if (s.size() < 26) {
      for (int i = 0; i < 26; i++) {
        if (alp[i] == 0) {
          ans = s + (char)('a' + i);
          break;
        }
      }
    } else {
      string s_next = s;
      next_permutation(s_next.begin(), s_next.end());
      for (int i = 0; i < (int)s.size(); i++) {
        ans += s_next[i];
        if (s[i] != s_next[i]) break;
      }
    }
    cout << ans << endl;
  }

  return 0;
}

#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  string S, ans;
  cin >> S;
  if (S.size() == 26) {
    ans = S;
    if (!next_permutation(begin(ans), end(ans)))
      ans = "-1";
    else
      for (int i = 0; i != 26; ++i) {
        if (S[i] != ans[i]) {
          ans.resize(i + 1);
          break;
        }
      }
  } else {
    int d[26]{};
    for (char c : S) ++d[c - 'a'];
    ans = S + char('a' + find(d, d + 26, 0) - d);
  }
  cout << ans << endl;
}


#include <iostream>
#include <cmath>
#include <cstdio>

using namespace std;

int main()
{
	int d;
	double area;
	int x;
	//int y;
	while(cin >> d)
	{
		x = 0;
		//d = 0;
		area = 0;
		while(x <= 600 - d)
		{
			area += pow(x,2.0) * d;
			x += d;
			//cout << x << endl;
		}
		printf("%ld\n",(long int)area );
		//cout << area << endl;
	}
	//cout << area << endl;
}

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

int main(){
	int d, ans, n;
	while(cin >> d){
		ans = pow(d, 3);
		n = 600 / d - 1;
		ans *= n*(n+1)*(2*n+1) / 6;
		cout << ans << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
//#include <unistd.h>
//#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll inf = 2147483647;
const ll INF = 1LL << 60;
const ld pi = 3.14159265358;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
//素数判定O(sqrt(N))
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}

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

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < 510000; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
ll nCk(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//nのm乗をMODで割ったあまりO(logN)
ll modpow(ll n,ll m,ll MOD){
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}

//printf("%.10f\n", N);
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/

//    cout << fixed << setprecision(15);

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll S;
    cin >> S;
    if(S % 111 == 0)
    cout << S / 111 * 111 << endl;
    else cout << (S / 111 + 1) * 111 << endl;
}

//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao Twitter/QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 10e16
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}

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

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    string s;cin>>s;
    if(s.length()==2)
        cout<<s<<Endl;
    else{
        reverse(all(s));
        cout<<s<<Endl;
    }
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace __gnu_pbds;
using namespace __gnu_cxx;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the iterator to kth largest element.(0-based)
typedef long long int lli;
#define pb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pair<int,int>>
#define vc vector<char>
#define vs vector<string>
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define fastio	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
/*-------CONSTANTS------- */
const int MAXN = 1000005;
const int SQRTN = 1003;
const int LOGN = 22;
const double PI=acos(-1);
const int INF = 1000000000;
const int MOD = 1000000007;
const int FMOD = 998244353;
const double eps = 1e-9;
/*-----------------------------MATH STUFF----------------------------- */
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
int mod_neg(int a, int b, int c){int res;if(abs(a-b)<c)res=a-b;else res=(a-b)%c;return(res<0?res+c:res);}
int mulmod(int a, int b, int c){lli res=(lli)a*b;return(res>=c?res%c:res);}
template<typename T>T power_mod(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mulmod(x,p,m);p=mulmod(p,p,m);n>>=1;}return x;}
template<typename T>T extended_euclid(T a, T b, T &x, T &y){T xx=0,yy=1;y=0;x=1;while(b){T q=a/b,t=b;b=a%b;a=t;\
t=xx;xx=x-q*xx;x=t;t=yy;yy=y-q*yy;y=t;}return a;}
template<typename T>T mod_inverse(T a, T n){T x,y,z=0;T d=extended_euclid(a,n,x,y);return(d>1?-1:mod_neg(x,z,n));}
//Factorials upto 1e5%MOD,nCr%MOD,nPr%MOD
lli fact[100000+5],fact_modinv[100000+5];
void fact_init(){
    fact[0] = 1ll;
    fact_modinv[0] = mod_inverse(fact[0],1ll*MOD);
    for(int i = 1;i<=100000;i++){
        fact[i] = mulmod(fact[i-1],i,1ll*MOD);
        fact_modinv[i] = mod_inverse(fact[i],1ll*MOD);
    }
}
lli choose(int n,int r){
    return mulmod(fact_modinv[n-r],mulmod(fact[n],fact_modinv[r],MOD),MOD);
}
lli P(int n,int r){
    return mulmod(fact[n],fact_modinv[n-r],1ll*MOD);
}
/*-----------------------------START----------------------------- */

int n,m;
vector<int> g[10000+5],gr[10000+5];
vector<int> topo;
bool visited1[10000+5],visited2[10000+5];
vector<int> scc[10000+5];
int par[10000+5];
void dfs(int u){
    visited1[u] = true;
    for(auto x : g[u])
        if(!visited1[x])
            dfs(x);

    topo.push_back(u);
}

void dfs2(int u,int p){
    visited2[u] = true;
    par[u] = p;

    for(auto x : gr[u])
        if(!visited2[x])
            dfs2(x,p);
}
int main(){
    fastio;
    cin>>n>>m;
    for(int i = 0;i<m;i++){
        int u,v;
        cin>>u>>v;
        g[u].pb(v);
        gr[v].pb(u);
    }
    for(int i = 0;i<n;i++)
        if(!visited1[i])
            dfs(i);

    reverse(topo.begin(),topo.end());

    for(auto x : topo)
        if(!visited2[x])
            dfs2(x,x);

    int q;cin>>q;
    while(q--){
        int u,v;
        cin>>u>>v;
        cout<<(par[u] == par[v])<<endl;
    }

    return 0;
}

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

// 強連結成分分解
//   計算量: O(V + E)
//   operator[]: 頂点kが属する強連結成分の番号を返す

class StronglyConnectedComponents {
    int V;
    vector<vector<int>> G, rG;
    vector <int> comp; // 強連結成分の番号（トポロジカル順）
    vector <int> order; // DFSで辿った順
    vector <int> used;

    void dfs(int cur) {
        if (used[cur]) return;
        used[cur] = true;
        for (int to : G[cur]) dfs(to);
        order.push_back(cur);
    }

    void rdfs(int cur, int cnt) {
        if (comp[cur] != -1) return;
        comp[cur] = cnt;
        for (int to : rG[cur]) rdfs(to, cnt);
    }

public:
    StronglyConnectedComponents(vector<vector<int>> &edge) {
        V = edge.size();
        G.resize(V);
        rG.resize(V);
        comp.assign(V, -1);
        used.assign(V, false);
        for (int i = 0; i < V; i++) {
            for (int e : edge[i]) {
                G[i].push_back(e);
                rG[e].push_back(i);
            }
        }
    }

    int operator[](int k) { return comp[k]; }

    void build(vector<vector<int>> &buff) {
        for (int i = 0; i < V; i++) dfs(i);
        reverse(order.begin(), order.end());
        int cnt = 0;
        for (int i : order) if (comp[i] == -1) rdfs(i, cnt++);
        buff.resize(cnt);
        for (int i = 0; i < V; i++) {
            for (int to : G[i]) {
                int x = comp[i], y = comp[to];
                if (x == y) continue;
                buff[x].push_back(y);
            }
        }
    }
};

// verified
//   https://onlinejudge.u-aizu.ac.jp/courses/library/5/GRL/3/GRL_3_C
void AOJ_GRL_3_C() {
    int V, E;
    cin >> V >> E;

    vector<vector<int>> edge(V), buff;
    for (int i = 0; i < E; i++) {
        int s, t;
        cin >> s >> t;
        edge[s].push_back(t);
    }

    StronglyConnectedComponents scc(edge);
    scc.build(buff);

    int Q;
    cin >> Q;
    while (Q--) {
        int u, v;
        cin >> u >> v;
        cout << (scc[u] == scc[v] ? 1 : 0) << "\n";
    }
}

int main() {
    AOJ_GRL_3_C();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 1000000007;
static const int INF = 1 << 25;
static const LL LL_INF = 1152921504606846976;

int n, m, a, b, c;
LL d;
int main() {
	while ( ~scanf( "%d %d", &n, &m ) && n && m ) {
		LL mp[ 100 ][ 100 ];
		for ( int i = 0; i < n; i++ ) {
			for ( int j = 0; j < n; j++ ) {
				mp[ i ][ j ] = LL_INF;
			}
		}
		for ( int i = 0; i < n; i++ ) {
			mp[ i ][ i ] = 0;
		}
		for ( int i = 0; i < m; i++ ) {
			scanf( "%d", &a );
			switch ( a ) {
				case 0:
					scanf( "%d %d", &b, &c );
					if ( mp[ b - 1 ][ c - 1 ] == LL_INF ) {
						printf( "-1\n" );
					}
					else {
						printf( "%lld\n", mp[ b - 1 ][ c - 1 ] );
					}
					break;
				case 1:
					scanf( "%d %d %lld", &b, &c, &d );
					if ( mp[ b - 1 ][ c - 1 ] > d ) {
						mp[ b - 1 ][ c - 1 ] = mp[ c - 1 ][ b - 1 ] = min( d, mp[ b - 1 ][ c - 1 ] );
						for ( int j = 0; j < n; j++ ) {
							for ( int k = 0; k < n; k++ ) {
								for ( int l = 0; l < n; l++ ) {
									mp[ k ][ l ] = mp[ l ][ k ] = min( mp[ k ][ l ], mp[ k ][ j ] + mp[ j ][ l ] );
								}
							}
						}
					}
					break;
			}
		}
	}
	return 0;
}

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int h[10] = { 6,2,5,5,4,5,6,3,7,6 };
bool b[10] = { false };
int dp[10100][10];
int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int a;
		cin >> a;
		b[a] = true;
	}
	for (int i = 0; i < n + 10; i++) {
		for (int j = 0; j < 10; j++) {
			dp[i][j] = -1;
		}
	}
	for (int i = 0; i < 10; i++) {
		dp[0][i] = 0;
	}
	for (int i = 0; i <= n; i++) {
		if (dp[i][0] == -1) {
			continue;
		}
		for (int j = 1; j < 10; j++) {
			if (!b[j]) {
				continue;
			}
			if (dp[i + h[j]][0] == -1) {
				for (int k = 0; k < 10; k++) {
					dp[i + h[j]][k] = dp[i][k];
					if (j == k) {
						dp[i + h[j]][k]++;
					}
				}
			}
			else {
				int kari[10];
				int sl = 0, sr = 0;
				for (int k = 0; k < 10; k++) {
					kari[k] = dp[i][k];
					if (j == k) {
						kari[k]++;
					}
					sl += dp[i + h[j]][k];
					sr += kari[k];
				}
				bool bo = true;
				if (sl != sr) {
					if (sl > sr) {
						bo = false;
					}
				}
				else {
					int l = 9, r = 9;
					while (1) {
						if (l == 0 && r == 0) {
							bo = false;
							break;
						}
						if (dp[i + h[j]][l] == 0) {
							l--;
							continue;
						}
						if (kari[r] == 0) {
							r--;
							continue;
						}
						if (l == r && dp[i + h[j]][l] == kari[r]) {
							l--;
							r--;
							continue;
						}
						else if (l < r) {
							break;
						}
						else if (l > r) {
							bo = false;
							break;
						}
						else if (dp[i + h[j]][l] < kari[r]) {
							break;
						}
						else if (dp[i + h[j]][l] > kari[r]) {
							bo = false;
							break;
						}
					}
				}
				if (bo) {
					for (int k = 0; k < 10; k++) {
						dp[i + h[j]][k] = kari[k];
					}
				}
			}
		}
	}
	for (int i = 9; i > 0; i--) {
		for (int j = 0; j < dp[n][i]; j++) {
			cout << i;
		}
	}
	cout << endl;
	return 0;
}


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

void input(int& rnTrgSu, int& rnTrgKin)
{
  cin >> rnTrgSu >> rnTrgKin;
}

int dfs(int nPos, int nTrgSu, int nTrgKin, vector<int>& rvnMoneyCnt)
{
  const vector<int> cnvnMoney{10000, 5000, 1000};

  if (nTrgSu == 0 && nTrgKin == 0) return  1;
  if (nTrgKin <  0)                return -1;
  if (nPos == rvnMoneyCnt.size())  return  0;

  if (nPos == rvnMoneyCnt.size() - 1)
  {
    rvnMoneyCnt[nPos] = nTrgSu;
    return dfs(nPos + 1, 0, nTrgKin - cnvnMoney[nPos] * nTrgSu, rvnMoneyCnt);
  }
  else
    for (int i = 0; i <= nTrgSu; i++)
    {
      rvnMoneyCnt[nPos] = i;
      for (int i = nPos + 1; i < rvnMoneyCnt.size(); i++)
        rvnMoneyCnt[i] = 0;

      int nReslt = dfs(nPos + 1, nTrgSu - i, nTrgKin - cnvnMoney[nPos] * i, rvnMoneyCnt);
      if      (nReslt ==  1)  return 1;
      else if (nReslt == -1)  break;
    }

  return 0;
}

void searchCntl(int nTrgSu, int nTrgKin)
{
  vector<int> vnMoneyCnt(3);

  if ( dfs(0, nTrgSu, nTrgKin, vnMoneyCnt) )
  {
    for (int i = 0; i < vnMoneyCnt.size(); i++)
    {
      if ( i )  cout << " ";
      cout << vnMoneyCnt[i];
    }
    cout << endl;
  }
  else
    cout << -1 << " " << -1 << " " << -1 << endl;
}

int main()
{
  int nTrgSu, nTrgKin;

  input(nTrgSu, nTrgKin);
  searchCntl(nTrgSu, nTrgKin);

  return 0;
}

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

int main(){
	int k,x;
	cin >> k >> x;
	int mn = x - k + 1;
	int mx = x + k - 1;
	vector<int> ans;
	for(int i = mn; i < mx; i++) cout << i << " ";
		cout << mx << endl;
}

// cout << fixed << setprecision(15) <<  << endl;


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

typedef long long ll;
using namespace std;

int gcd(int a, int b) { //最大公約数
  if (b==0) return a;
  else return gcd(b, a%b);
}

int lcm(int a, int b) { //最小公倍数
  return a * b / gcd(a, b);
}

int main()
{
  ll n,a[100010];
  cin>>n;
  rep(i,n)cin>>a[i];
  sort(a,a+n,greater<ll>());

  ll tate=0,yoko=0,cnt=0;

  rep(i,n-1){
    if(cnt==0&&a[i]==a[i+1]){
      tate=a[i];
      cnt=1;
      i++;
    }else if(cnt==1&&a[i]==a[i+1]){
      yoko=a[i];
      cnt=2;
    }
  }

  if(tate==0||yoko==0){
    cout<<0<<endl;
  }else{
    cout<<tate*yoko<<endl;
  }

  return 0;
}

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

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

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

const int N = 2e5+23;

int a[N];
map<int, int> m;

void solve() {
  int n; scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a+i);
    ++m[a[i]];
  }
  sort(a, a+n, greater<int>());
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    if (!m[a[i]]) continue;
    for (int j = 1<<30; j >= a[i]; j >>= 1) {
      int t = 1;
      if (j-a[i] == a[i]) {
	t = 2;
      }
      if (m.count(j-a[i]) && m[j-a[i]] >= t) {
	++ans;
	--m[a[i]];
	--m[j-a[i]];
	break;
      }
    }
  }
  printf("%d", ans);
}

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


#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    int N, M; cin >> N >> M;
    vector<int> A(N), B(M); unordered_map<int, int> a, b; bool ok = true;
    REP(i, 0, N) {
        cin >> A[i];
        if(a[A[i]]) ok = false;
        a[A[i]] = i + 1;
    }
    REP(i, 0, M) {
        cin >> B[i];
        if(b[B[i]]) ok = false;
        b[B[i]] = i + 1;
    }
    if (!ok) {
        cout << 0 << endl;
        return 0;
    }

    int count[N * M + 1] = {};
    REP(i, 0, N) {
        REP(j, 0, M) {
            count[min(A[i], B[j])]++;
        }
    }

    vector<int> acnt(N, 0), bcnt(M, 0);
    REP(i, 0, N) {
        REP(j, 0, M) {
            if (A[i] <= B[j]) acnt[i]++;
        }
    }
    REP(j, 0, M) {
        REP(i, 0, N) {
            if (A[i] >= B[j]) bcnt[j]++;
        }
    }

    ll ans = 1; int cnt = 0;
    for (int i = N * M; i > 0; i--) {
        cnt += count[i];
        if (a[i] && b[i]) {
            continue;
        } else if (a[i]) {
            ans = (ans * acnt[a[i] - 1]) % MOD;
        } else if (b[i]) {
            ans = (ans * bcnt[b[i] - 1]) % MOD;
        } else {
            ans = (ans * (cnt - (N * M - i))) % MOD;
        }
    }
    cout << ans << endl;

    return 0;
}

#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  ll N,M;
  cin >> N >> M;
  int A[N],B[M];
  int Acnt[1100000];
  int Bcnt[1100000];
  ll a = 0;
  ll b = 0;
  ll ans = 1;
  for (int i = 0; i < 1100000; i++) {
    Acnt[i] = 0; Bcnt[i] = 0;
  }
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    Acnt[A[i]]++;
  }
  for (int i = 0; i < M; i++) {
    cin >> B[i];
    Bcnt[B[i]]++;
  }
  for (int i = N*M; i >= 1; i--) {
    int s = Acnt[i] + Bcnt[i];
    if (s > 2) {
      ans = 0;
    } else if (s == 2) {
      ans *= 1;
      a++; b++;
    } else if (s == 1) {
      if (Acnt[i] == 1) {
        ans *= b;
        a++;
      } else {
        ans *= a;
        b++;
      }
    } else {
      ll c = a*b;
      c -= ((N*M) - i);
      ans *= c;
    }
    ans %= Mod;
  }
  if (a == N && b == M) {
    cout << ans << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;
}


#include <bits/stdc++.h>

#define loop(v, f, l) for(int v = (f), v##_ = (l); v < v##_; ++v)

using namespace std;

typedef long long int lint;
static inline int in(){ int x; scanf("%d", &x); return (x); }
static inline lint inl(){ lint x; scanf("%lld", &x); return (x); }

int main()
{
	int n;

	scanf("%d\n", &n);
	loop(i, 0, n)
	{
		string line;
		std::getline(cin, line);
		int pos = 0;

		while( (pos = line.find("Hoshino", pos)) != string::npos )
		{
			line.replace(pos, 7, "Hoshina");
		}
		cout << line << endl;
	}
	return (0);
}

#include <bits/stdc++.h>
using namespace std;
#define ld double
#define ll long long
#define pb emplace_back
#define mk make_pair
#define mod 1000000007
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) x.begin(),x.end()
ll power(ll a, ll b) {ll res = 1; a = a % mod; while (b) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b /= 2;} return res;}
ll invmod(ll a) {return power(a, mod - 2);}
int main(void)
{
	FIO
	int t = 1;
	// cin >> t;
	while (t--)
	{
		int a, b;
		cin >> a >> b;
		cout << a*b << '\n';
	}
	return 0;
}


#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<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 1e+5+5;

int n;
int a[3][N];
int id[N],inv[N];
bool vis[N];

int main(){
	n=get();
	fo(i,0,2)fo(j,1,n)a[i][j]=get();
	fo(i,1,n){
		int x=(a[0][i]-1)/3+1;
		if (a[0][i]==x*3-2&&a[1][i]==x*3-1&&a[2][i]==x*3)id[i]=x,inv[i]=0;
		if (a[2][i]==x*3-2&&a[1][i]==x*3-1&&a[0][i]==x*3)id[i]=x,inv[i]=1;
		if (!id[i])return printf("No\n"),0;
		if (i%2!=id[i]%2)return printf("No\n"),0;
	}
	int inv0=0,inv1=0;
	fo(i,1,n)
	if (i&1)inv1^=inv[i];else inv0^=inv[i];
	int flip0=(n/2)&1,flip1=(n&1)^((n/2)&1);
	fo(i,1,n)
	if (!vis[i]){
		if (i&1)flip1^=1;else flip0^=1;
		vis[i]=1;
		for(int x=id[i];x!=i;x=id[x])vis[x]=1;
	}
	if (flip1!=inv0||inv1!=flip0)printf("No\n");
	else printf("Yes\n");
	return 0;
}


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

int main()
{
    string s;
    cin>>s;
    int d=INT_MAX;
    for(int i=0;i<=s.size()-3;i++)
    {
        int k=i+2;
        int k1=0;
        for(int j=i;j<=k;j++)
        {
            k1=k1*10+(s[j]-'0');
        }
        int c=k1>753?(k1-753):753-k1;
        d=(c<d)?c:d;

    }
    cout<<d<<endl;
    return 0;
}

/*https://atcoder.jp/contests/abc114/tasks/abc114_b*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	string s;
	int min_dif = 1e5 + 1;
	cin >> s;
	for (int i = 0; i < s.length() - 2; i++)
	{
		char a, b, c;
		a = s[i], b = s[i + 1], c = s[i + 2];
		string n;
		n += s[i];
		n += s[i + 1];
		n += s[i + 2];

		// cout << a << " " << b << " " << c << endl;
		// int x = stoi(n) + atoi(b) + atoi(c);
		// cout << n << endl;

		int x = stoi(n);
		// cout << x <<< " ->" abs(x - 753)
		min_dif = min(min_dif, abs(x - 753));
	}
	cout << min_dif;
}


#include"bits/stdc++.h"

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

typedef long long ll;

const int mod = 1e9 + 7;

using namespace std;

int main(void) {
	int N, Q; cin >> N >> Q;
	string S; cin >> S;
	vector<int> l(Q), r(Q);
	rep(i, Q) {
		cin >> l[i] >> r[i];
		l[i]--;
		r[i]--;
	}

	rep(i, S.size()-1) {
		if (S[i] == 'A' && S[i + 1] == 'C') {
			S[i] = '@';
		}
	}

	vector<int> sum(S.size(), 0);
	sum[0] = (int)(S[0] == '@');
	for(int i = 1;i < S.size();i++) {
		sum[i] = sum[i - 1];
		sum[i] += (int)(S[i] == '@');
	}

	rep(q, Q) {
		int ans = sum[r[q]-1] - sum[l[q]];
		ans += (int)(S[l[q]] == '@');
		cout << ans << endl;
	}

	return 0;
}

#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int maxn = 1007, maxm = 2007;
const int inf = 1e9 + 7;
int cnt = 1;
int head[maxn], vis[maxn], dfn[maxn], vis2[maxn];
//head[x]:点x连接的最后一条边号
//vis[x]:标记每次dfs访问过的点，以免重复搜索耗时
//dfn[x]:x的时间戳
//vis[x]2:dfs中标记访问过的次数，找环
int b[maxn];
struct edge
{
int u, v, next;
}e[maxm];
void addedge(int u, int v)//前向星
{
e[cnt].u = u;
e[cnt].v = v;
e[cnt].next = head[u];
head[u] = cnt;
cnt++;
}
vector<int> v;
int ans = inf;
void dfs(int x, int num)
{
vis[x] = 1;//标记x访问过
dfn[x] = num;
for (int i = head[x]; i ; i = e[i].next)//遍历x点连接的所有边
{
int y = e[i].v;
if (vis2[y] == 1)//y第二次被访问，说明形成环
{
if (dfn[x] - dfn[y] + 1 < ans)//ans记录最小环的大小
{
ans = dfn[x] - dfn[y] + 1;
int sz = v.size();
for (int i = 1; i <= ans; i++)
b[i] = v[sz - i];//b[i]存最小环的点
}
}
if (vis[y] == 0)//y没有访问过
{
vis2[y] = 1;
v.push_back(y);
dfs(y, num + 1);
}
}
v.pop_back();
vis2[x] = 0;
}
int main()
{
int n, m;
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++)
{
int x, y;
scanf("%d%d", &x, &y);
addedge(x, y);
}
for (int i = 1; i <= n; i++)
{
if (vis[i] == 0)
{
v.clear();
v.push_back(i);
vis2[i] = 1;
dfs(i, 1);
}
}
if (ans == inf)
printf("-1\n");
else
{
printf("%d\n", ans);
for (int i = ans; i >= 1; i--)
printf("%d\n", b[i]);
}
return 0;
}


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

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

typedef long long ll;

int main() {

  int N;
  while(cin >> N && N) {
    vector<int> v(N);
    rep(i, N) cin >> v[i];

    ll mx = -1<<29;
    rep(i, N) {
      ll sum = 0;
      REP(j, i, N) {
	sum += v[j];
	mx = max(mx, sum);
      }
    }
    cout << mx << endl;
  }

  return 0;
}

#include <stdio.h>

int
main(void)
{
	char line[80];
	int a[5000];
	int n;

	while (fgets(line, sizeof line, stdin)) {
		if (sscanf(line, "%d", &n) == 1) {
			if (n == 0) {
				break;
			}

			for (int i = 0; i < n; i++) {
				if (fgets(line, sizeof line, stdin) == NULL) {
					return 1;
				}
				if (sscanf(line, "%d", &(a[i])) != 1) {
					return 1;
				}
			}

			int m1 = -100001;
			for (int i = 0; i < n; i++) {
				int s = 0;
				int m0 = -100001;
				for (int j = i; j < n; j++) {
					s += a[j];
					if (m0 < s) {
						m0 = s;
					}
				}
				if (m1 < m0) {
					m1 = m0;
				}
			}
			printf("%d\n", m1);
		}
	}

	return 0;
}


#include <bits/stdc++.h>

#define ll long long int
#define ull unsigned long long int
#define IO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;

const int INF = 1e9 + 7;
const int N = 1e5+5;

int main() {

	IO;

	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;

	string ans, ur, ld, mdf="L", mof = "R";

	while (ty > sy) {
		ur += 'U';
		ld += 'D';
		sy++;
	}
	mdf += ur + 'U';
	mof += ld + 'D';
	while (tx > sx) {
		ur += 'R';
		ld += 'L';
		mdf += 'R';
		mof += 'L';
		sx++;
	}

	mdf += "RD";
	mof += "LU";
	ans += ur + ld + mdf + mof;

	cout << ans << endl;

}

#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
constexpr int MAX = 2e6;
vll L(MAX / 2 + 2), R(MAX / 2 + 2);
ll cnt = 0;
inline void merge(vll &a, ll left, ll mid, ll right) {
	ll n1 = mid - left;
	ll n2 = right - mid;
	rep(i, 0, n1) L[i] = a[left + i];
	rep(i, 0, n2) R[i] = a[mid + i];
	L[n1] = R[n2] = 1e9;
	ll i = 0, j = 0;
	rep(k, left, right) {
		if(L[i] <= R[j]) {
			a[k] = L[i];
			++i;
		} else {
			a[k] = R[j];
			++j;
			cnt = cnt + n1 - i;
		}
	}
}
inline void mergeSort(vll &a, ll left, ll right) {
	if(left + 1 < right) {
		ll mid = (left + right) / 2;
		mergeSort(a, left, mid);
		mergeSort(a, mid, right);
		merge(a, left, mid, right);
	}
}
int main() {
	int n; cin >> n;
	vll a(n); rep(i, 0, n) cin >> a[i];
	mergeSort(a, 0, n);
	P(cnt);
	return 0;
}


// J'aime
// Chemise Blanche

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  string s, t;
  cin >> s >> t;
  cout << t << s << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}

// https://atcoder.jp/contests/abc149/tasks/abc149_a
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(size_t i = 0; i < (n); ++i)

int main()
{
    string S, T;
    cin >> S >> T;
    T.insert(T.end(), S.begin(), S.end());
    cout << T << endl;
    return 0;
}


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

int main(){
 double x1,x2,y1,y2,d;

 cin >> x1 >> y1 >> x2 >> y2;

 d = sqrt(pow(x1-x2, 2) + pow(y1-y2, 2));

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

 return 0;
}

#include <iostream>
using namespace std;

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


#include <iostream>
using namespace std;

const int DEPTH = 17;
const int INTMAX = (1LL << 31) - 1;

struct RUQ {
	int d[1 << (DEPTH + 1)];
	int t[1 << (DEPTH + 1)];

	RUQ() {
		int i;
		for (i = 0; i < (1 << (DEPTH + 1)); i++) {
			d[i] = INTMAX;
			t[i] = -1;
		}
	}

	//[l, r)
	void update(int l, int r, int x, int Time, int a = 0, int b = (1 << DEPTH), int id = 0) {
		if (a >= r || b <= l) return;
		if (l <= a && b <= r) {
			d[id] = x;
			t[id] = Time;
			return;
		}
		update(l, r, x, Time, a, (a + b) / 2, id * 2 + 1);
		update(l, r, x, Time, (a + b) / 2, b, id * 2 + 2);
	}

	int getValue(int pos) {
		pos += (1 << DEPTH) - 1;
		int retD = d[pos];
		int retT = t[pos];

		while (pos > 0) {
			pos = (pos - 1) / 2;
			if (retT < t[pos]) {
				retT = t[pos];
				retD = d[pos];
			}
		}
		return retD;
	}
};

RUQ ruq;

int main() {
	int n, q;

	cin >> n >> q;
	for (int i = 0; i < q; i++) {
		int type;
		cin >> type;
		if (type == 0) {
			int s, t, x;
			cin >> s >> t >> x;
			ruq.update(s, t + 1, x, i);
		}
		else {
			int pos;
			cin >> pos;
			cout << ruq.getValue(pos) << endl;
		}
	}
	return 0;
}

#include <cmath>
#include <cstdio>
#include <vector>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
int N, Q;
int main() {
	scanf("%d%d", &N, &Q);
	vector<int> tp(Q), s(Q), t(Q), x(Q);
	for (int i = 0; i < Q; i++) {
		scanf("%d%d", &tp[i], &s[i]);
		if (tp[i] == 0) scanf("%d%d", &t[i], &x[i]), t[i]++;
	}
	vector<int> d(N, 2147483647);
	int B = sqrt(Q);
	for (int i = 0; i < B; i++) {
		int l = 1LL * i * Q / B, r = 1LL * (i + 1) * Q / B;
		for (int j = l; j < r; j++) {
			if (tp[j] == 1) {
				bool flag = false;
				for (int k = j - 1; k >= l; k--) {
					if (tp[k] == 0 && s[k] <= s[j] && s[j] < t[k]) {
						printf("%d\n", x[k]); flag = true;
						break;
					}
				}
				if (!flag) printf("%d\n", d[s[j]]);
			}
		}
		vector<int> cp = { 0, N };
		for (int j = l; j < r; j++) {
			if (tp[j] == 0) {
				cp.push_back(s[j]);
				cp.push_back(t[j]);
			}
		}
		sort(cp.begin(), cp.end());
		cp.erase(unique(cp.begin(), cp.end()), cp.end());
		vector<int> f(cp.size() - 1, -1);
		for (int j = l; j < r; j++) {
			if (tp[j] == 0) {
				int pl = lower_bound(cp.begin(), cp.end(), s[j]) - cp.begin();
				int pr = lower_bound(cp.begin(), cp.end(), t[j]) - cp.begin();
				for (int k = pl; k < pr; k++) f[k] = x[j];
			}
		}
		for (int j = 0; j < cp.size() - 1; j++) {
			if (f[j] != -1) {
				for (int k = cp[j]; k < cp[j + 1]; k++) d[k] = f[j];
			}
		}
	}
	return 0;
}


//Badwaper gg
#include<bits/stdc++.h>
#define inf 1e9
#define eps 1e-6
#define mp make_pair
#define pb push_back
#define re register ll
#define fr first
#define sd second
#define FOR(i,a,b) for(re i=a;i<=b;i++)
#define REP(i,a,b) for(re i=a;i>=b;i--)
#define lowbit(x) (x&(-x))
#define Z(x) (x>=mod?x-mod:x)
#define N 41
#define M 200010
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline ll read()
{
	char ch=getchar();
	ll s=0,w=1;
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
	return s*w;
}
const int mod=1e9+7;
int f[N][M],to[M][N];
int n,x,y,z;
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	n=read(),x=read(),y=read(),z=read();y+=x;z+=y;
	FOR(S,1,1<<z)FOR(i,1,10)
	{
		to[S][i]=1;
		FOR(k,0,z-i)if((S>>k)&1)if(!(k<x&&k+i>x)&&!(k<y&&k+i>y))to[S][i]|=(1<<(i+k));
		if((S==(1<<z))||(to[S][i]>=(1<<z)))to[S][i]=1<<z;
	}
	f[0][1]=1;
	FOR(i,0,n-1)FOR(S,1,(1<<z))FOR(j,1,10)f[i+1][to[S][j]]=Z(f[i+1][to[S][j]]+f[i][S]);
	printf("%d\n",f[n][1<<z]);
	return 0;
}

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
const int N = 45;
const int mod = 1e9 + 7;
using namespace std;

int n, x, y, z, now, lim, f[N][(1 << 17) + 5], ans;

template < typename T >
inline T read()
{
	T x = 0, w = 1; char c = getchar();
	while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * w;
}

int fpow(int x, int y)
{
	int res = 1;
	for( ; y; y >>= 1, x = 1ll * x * x % mod)
		if(y & 1) res = 1ll * res * x % mod;
	return res;
}

void output(int x)
{
	int a[100], cnt = 0;
	while(x) a[cnt++] = x & 1, x >>= 1;
	if(!cnt) return (void) (puts("0"));
	for(int i = cnt - 1; i >= 0; i--) printf("%d", a[i]);
	puts("");
}

int main()
{
	n = read <int> (), x = read <int> (), y = read <int> (), z = read <int> ();
	now = (1 << (x - 1 + y + z)) | (1 << (y - 1 + z)) | (1 << (z - 1)), lim = (1 << (x + y + z)) - 1;
	f[0][0] = 1;
	for(int tmp, i = 0; i < n; i++)
		for(int j = 0; j <= lim; j++)
			if(f[i][j])
			{
				for(int k = 1; k <= 10; k++)
				{
					tmp = ((j << k) | (1 << (k - 1))) & lim;
					if((tmp & now) != now) f[i + 1][tmp] = (f[i + 1][tmp] + f[i][j]) % mod;
				}
			}
	for(int j = 0; j <= lim; j++) if((j & now) != now) ans = (ans + f[n][j]) % mod;
	printf("%d\n", (fpow(10, n) - ans + mod) % mod);
	return 0;
}


///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;
const int M=100005;
int n;
string s;
char ses[M];
char fnd(int pos,char cur,char dan)
{
    if(cur=='S')
    {
        if(s[pos]=='o')return dan;
        else
        {
            if(dan=='S')return 'W';
            else return 'S';
        }
    }
    else if(cur=='W')
    {
        if(s[pos]=='x')return dan;
        else
        {
            if(dan=='S')return 'W';
            else return 'S';
        }
    }
}
void chk(char x,char y)
{

    ses[0]=x;
    ses[1]=y;
    ses[n-1]=fnd(0,x,y);
    for(int i=2;i<=n;i++)
    {
        char yo=fnd(i-1,ses[i-1],ses[i-2]);
        if(i==n-1)
        {
            if(yo!=ses[n-1])
            {
                return ;
            }
        }
        else if(i==n)
        {
            if(yo!=ses[0])return ;
            continue;
        }
        ses[i]=yo;
    }
    ses[n]='\0';
    cout<<ses<<endl;
    exit(0);
}
 main()

{
    fast
    cin>>n;
    cin>>s;
    chk('S','W');
    chk('S','S');
    chk('W','S');
    chk('W','W');
    cout<<"-1"<<endl;
    return 0;

}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string s;
    cin >> n >> s;
    vector<int> ans;
    for(int i = 0; i < 4; i++){
    	ans.resize(n);
    	ans[0] = i%2;
    	ans[1] = i/2;
    	for(int j = 1; j < n-1; j++){
    		if(s[j] == 'o'){
    			if(ans[j] == 0) ans[j+1] = ans[j-1];
    			else ans[j+1] = !ans[j-1];
    		}
    		else{
    			if(ans[j] == 0) ans[j+1] = !ans[j-1];
    			else ans[j+1] = ans[j-1];
    		}
    	}
    	if(s[0] == 'o'){
    		if((ans[0] == 0) ^ (ans[1] == ans.back())) continue;
    	}
    	else{
    		if((ans[0] == 0) ^ (ans[1] != ans.back())) continue;
    	}
    	if(s.back() == 'o'){
    		if((ans.back() == 0) ^ (ans[0] == ans[n-2])) continue;
    	}
    	else{
    		if((ans.back() == 0) ^ (ans[0] != ans[n-2])) continue;
    	}
    	for(int j = 0; j < n; j++){
    		cout << "SW"[ans[j]];
    	}
    	cout << endl;
    	return 0;
    }
    cout << -1 << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    ll a[n+2];
    for(int i=0;i<n;i++)cin>>a[i];
    ll cnt[n+2]={0};
    cnt[0]=a[0];
    for(int i=1;i<n;i++)cnt[i]=cnt[i-1]+a[i];
    ll sum=0;
    ll res=cnt[n-1];
    for(int i=0;i<n-1;i++){
        if(i==0)sum+=(cnt[i]*((res-cnt[i])%mod))%mod;
        else sum+=(((cnt[i]-cnt[i-1])%mod)*((res-cnt[i])%mod))%mod;
    }
    cout<<sum%mod<<endl;
}

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

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

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

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

	int n;
	cin >> n;
	int a[n], b[n], c[n];
	set<int>s;
	zip(i, 0, n)cin >> a[i], s.insert(a[i]);
	zip(i, 0, n)cin >> b[i];
	zip(i, 0, n)cin >> c[i];
	sort(a, a + n);
	sort(b, b + n);
	sort(c, c + n);
	vi b1(n, 0);

	zip(i, 0, n)
	{
		// first element-> b[i]
		// c mai baaki saare elements bade hone chahiye..
		int pos = upper_bound(c, c + n, b[i]) - c;
		debug(pos);
		b1[i] = n - pos;
	}
	rzip(i, n - 2, 0)
	{
		b1[i] += b1[i + 1];
	}
	debug(b1);
	int ans = 0;
	zip(i, 0, n)
	{
		int x = a[i];
		// upper bound nikalna hoga array b mai.
		int pos = upper_bound(b, b + n, x) - b;
		if (pos < n)
		{
			ans += b1[pos];
		}
	}
	cout << ans << en;

	return 0;
}


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

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

const int MAXN = 1e5;
const int MAXM = 100;

int N, M;
vector<int> V1, V2, A, B;

int main()
{
    int i, j;

    scanf("%d%d", &N, &M);
    int cnt=0;
    for(i=1; i<=M; i++)
    {
        int X; scanf("%d", &X);
        if(X%2) V2.push_back(X), cnt++;
        else V1.push_back(X);
    }
    if(cnt>2) return !printf("Impossible");

    if(cnt>0) A.push_back(V2[0]);
    for(i=0; i<V1.size(); i++) A.push_back(V1[i]);
    if(cnt>1) A.push_back(V2[1]);

    if(A.size()==1)
    {
        if(A[0]>1) B.push_back(A[0]-1);
        B.push_back(1);
    }
    else
    {
        B.push_back(A[0]+1);
        for(i=1; i+1<A.size(); i++) B.push_back(A[i]);
        if(A.back()>1) B.push_back(A.back()-1);
    }

    for(i=0; i<A.size(); i++) printf("%d ", A[i]);
    printf("\n%d\n", B.size());
    for(i=0; i<B.size(); i++) printf("%d ", B[i]);
}

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

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

int N, M, A[100005], cnt = 0;

int main(){
	getint(N), getint(M);
	for(register int i = 1; i <= M; i++) getint(A[i]);
	for(register int i = 1; i <= M; i++) if(A[i] & 1){
		if(++cnt == 1) swap(A[i], A[1]);
		else if(cnt == 2) swap(A[i], A[2]);
		else return puts("Impossible"), 0;
	}
	if(cnt) swap(A[cnt], A[M]);
	for(register int i = 1; i <= M; i++) printf("%d ", A[i]); puts("");
	if(cnt <= 1){
		printf("%d\n1 ", A[M] == 1 ? M : M + 1);
		for(register int i = 1; i < M; i++) printf("%d ", A[i]);
		if(A[M] > 1) printf("%d\n", A[M] - 1);
	}
	else{
		printf("%d\n%d ", A[M] == 1 ? M - 1 : M, A[1] + 1);
		for(register int i = 2; i < M; i++) printf("%d ", A[i]);
		if(A[M] > 1) printf("%d\n", A[M] - 1);
	}
	return 0;
}


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

int main() {
  int c[6] = {0},same[5] = {0};

  while(scanf("%d,%d,%d,%d,%d\n",&c[0],&c[1],&c[2],&c[3],&c[4]) == 5) {
    int same[5] = {0};
    int straight = 0;
    for(int i=0;i<5;i++) {
      for(int j=0;j<5;j++) {
	if(c[i] == c[j]) {
	  same[i]++;
	}
      }
    }
    sort(c,c+5);
    sort(same,same+5);
    if(same[4] == 4) {
      cout << "four card" << endl;
    }
    else if(same[4] == 3) {
      if(same[1] == 2) {
	cout << "full house" << endl;
      }
      else {
	cout << "three card" << endl;
      }
    }
    else if(same[4] == 2) {
      if((same[3] == 2) &&(same[2] == 2)) {
	cout << "two pair" << endl;
      }
      else {
	cout << "one pair" << endl;
      }
    }
    else if(same[4] == 1) {
      for(int i=0;i<4;i++) {
	if(c[i] == c[i+1]-1) {
	  straight = 1;
	}
	else {
	  straight = 0;
	  break;
	}
      }
      if((c[0] == 1) && (c[1] == 10)) {
	straight = 1;
      }
      if(straight) {
	cout << "straight" << endl;
      }
      else {
	cout << "null" << endl;
      }
    }

  }
}

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

int main()
{
	int n; char c; string s;
	while(cin >> n)
	{
		int cd[13]={0},pr[5]={0};

		cd[n-1]++;
		for(int i=0; i<4; i++)
		{
			cin >> c >> n;
			cd[n-1]++;
		}

		for(int i=0; i<13; i++)
		{
			pr[cd[i]]++;
		}

		bool st=false;
		for(int i=0; i<10; i++)
		{
			int sm=0;
			for(int j=0; j<5; j++) sm+=(cd[(i+j)%13]?1:0);
			if(sm==5) st=true;
		}

		                      s="null";
		     if(pr[4])        s="four card";
		else if(pr[3]&&pr[2]) s="full house";
		else if(st)           s="straight";
		else if(pr[3])        s="three card";
		else if(pr[2]==2)     s="two pair";
		else if(pr[2])        s="one pair";

		cout << s << endl;
	}
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define cans cout << ans << endl
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
typedef long long ll;

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> l(n+1),r(n+1);
    for(int i=1; i<=n-1; i++){
        if(s[i-1]=='W') l[i] = l[i-1]+1;
        else l[i] = l[i-1];
    }
    for(int i=n; i>=1; --i){
        if(s[i-1]=='E') r[n-i+1] = r[n-i]+1;
        else r[n-i+1] = r[n-i];
    }
    int ans = 1e9;
    for(int i=0; i<=n-1; i++){
        ans = min(ans,l[i]+r[n-i-1]);
    }
    cout << ans << endl;

    return 0;
}

#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
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<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

int main(){
  string S;
  cin >> S;
  if(S.size()==3){
    reverse(ALL(S));
  }
  cout << S << endl;
}


#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)
const ll INF=1e17;
using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
ll ans1=0;
void recur(vector<pair<char,int>> str,int val,ll sum,int idx){
  if(val<0) return;
  else if(val==0){
    ans1=max(ans1,sum);
    return;
  }
  if(idx>=str.size()) return;
  rep(j,idx,str.size()){
    recur(str,val-str[j].s,sum*10+str[j].f-'0',idx+1);
    recur(str,val-str[j].s,sum*10+str[j].f-'0',idx);
  }
}
void  solve(){
  int n,m2;
  cin>>n>>m2;
  int a[m2];
  rep(i,0,m2) cin>>a[i];
  sort(a,a+m2);
  map<int,int> m,m1;
  m[1]=2;
  m[2]=5;
  m[3]=5;
  m[4]=4;
  m[5]=5;
  m[6]=6;
  m[7]=3;
  m[8]=7;
  m[9]=6;
  rep(i,0,m2){
    m1[m[a[i]]]=a[i];
  }
  int sma= (*m1.begin()).s;
  int rep = max(n/m[sma]-7,0);
  int rem=n%m[sma]+min(n/m[sma],7)*m[sma];

  string ans="";
  ans+=repeat(getString('0'+sma),rep);
  vector<pair<char,int>> str;
  for(auto i:m1){
    str.pb({i.s+'0',i.f});
  }
  ans1=0;
  recur(str,rem,0,0);
  vector<char> res;
  rep(i,0,ans.length()) res.pb(ans[i]);
  // cout<<ans1<<endl;
  while(ans1){
    res.pb(ans1%10+'0');
    ans1/=10;
  }
  sort(all(res),greater<char>());
  rep(i,0,res.size()) cout<<res[i];
  cout<<endl;
  // if(rem==0) cout<<ans<<endl;
  // else{
  //   int mx=-1;
  //   for(auto i:m1){
  //     if(i.f<=rem) mx=max(mx,i.s);
  //   }
  //   cout<<rem<<endl;
  //   if(mx!=-1 && sma>mx) ans+= getString(mx+'0');
  //   else if(mx!=-1 && sma<=mx) ans=getString(mx+'0')+ans;
  //   cout<<ans<<endl;
  // }
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}

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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < (n); i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define REP(i, vec) for(auto i = vec.begin(); i != vec.end(); ++i)

const int mod = 1000000007;
const int inf = (1 << 21);
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, 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; }
template<class T> inline T GCD(T a, T b) { return b ? GCD(b, a % b) : a; }
template<class T> inline T LCM(T a, T b) { return (a + (b - 1)) / b; }

int round_int(int a, int b) { return (a + (b - 1)) / b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

constexpr array<int, 10> cost = { -1,2,5,5,4,5,6,3,7,6 };

int calc_cost(deque<int> d) {
	int res = 0;
	while (!d.empty()) {
		int v = d.front(); d.pop_front();
		res += cost[v];
	}
	return res;
}

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

	vi a(m);
	rep(i, m) cin >> a[i];

	vector<vector<deque<int>>> dp(n + 1, vector<deque<int>>(m));

	for (int i = 0; i <= n; ++i) {
		for (int j = 0; j < m; ++j) {
			int c = cost[a[j]];
			//cout << i << " " << j << endl;
			if (i - c >= 0 && calc_cost(dp[i - c][j]) + c == i) {
				deque<int> pre = dp[i - c][j];
				if (pre.size() == 0) pre.push_back(a[j]);
				else if (pre.front() > a[j]) pre.push_back(a[j]);
				else pre.push_front(a[j]);
				dp[i][j] = pre;
			}

			if (j != 0) {
				deque<int> pre = dp[i][j - 1];

				if (pre.size() < dp[i][j].size()) continue;
				else if (pre.size() > dp[i][j].size()) dp[i][j] = pre;
				else if (pre.size() == dp[i][j].size()) {
					if (pre.size() == 0) continue;

					deque<int> tmp1 = pre, tmp2 = dp[i][j];
					for (int k = 0; k < pre.size(); ++k) {
						int l = tmp1.front(), r = tmp2.front();
						tmp1.pop_front(), tmp2.pop_front();

						if (l > r) {
							dp[i][j] = pre;
							break;
						}
						else if (l < r) {
							break;
						}
					}
				}
			}
		}
	}

	int mx = dp[n][m - 1].size();
	rep(i, mx) {
		int v = dp[n][m - 1].front(); dp[n][m - 1].pop_front();
		cout << v;
	}
}


#include <iostream>
#include <vector>
#include <stack>
#include <bitset>
#include <utility>
#include <algorithm>

using namespace std;

const int kNil = -1;
const int kMaxV = 100010;

enum class Color {
  kWhite,
  kGrey,
  kBlack,
};

template <class T>
struct Edge {
  using w_type = T;
  Edge(int u, int v, w_type w): u(u), v(v), w(w) { }
  int u, v;
  w_type w;
  bool operator<(const Edge<T> & rhs) const {
    if (w != rhs.w) { return w < rhs.w; }
    if (u != rhs.u) { return u < rhs.u; }
    return v < rhs.v;
  }
};

template <class Edge>
void ArticulationPointsVisit(
    const typename vector<Edge>::size_type node_now,
    typename vector<Edge>::size_type & time,
    const vector<vector<Edge>> & adjacency_list,
    vector<int> & d,
    vector<int> & low,
    vector<Color> & color,
    vector<int> & parent,
    bitset<kMaxV> & bs_aps) {
  color[node_now] = Color::kGrey;
  d[node_now] = time;
  low[node_now] = time++;
  unsigned child_num = 0;
  for (const auto & e: adjacency_list[node_now]) {
    if (color[e.v] == Color::kWhite) {
      ++child_num;
      parent[e.v] = e.u;
      ArticulationPointsVisit(e.v, time, adjacency_list, d, low, color, parent, bs_aps);
      low[e.u] = min(low[e.u], low[e.v]);

      if (parent[e.u] == kNil && child_num >= 2) {
        bs_aps.set(e.u);
      }
      if (parent[e.u] != kNil && d[e.u] <= low[e.v]) {
        bs_aps.set(e.u);
      }
    } else if (parent[e.u] != e.v) {
      low[e.u] = min(low[e.u], d[e.v]);
    }
  }
  color[node_now] = Color::kBlack;
}

template <class Edge>
bitset<kMaxV> ArticulationPoints(const vector<Edge> & edges,
                 typename vector<Edge>::size_type node_num) {
  using size_type = typename vector<Edge>::size_type;

  vector<vector<Edge>> adjacency_list(node_num, vector<Edge>());
  for (const auto & e: edges) {
    adjacency_list[e.u].push_back(e);
    adjacency_list[e.v].emplace_back(e.v, e.u, e.w);
  }

  size_type time = 0;
  vector<int> d(node_num);
  vector<int> low(node_num);
  vector<Color> color(node_num, Color::kWhite);
  vector<int> parent(node_num, kNil);
  bitset<kMaxV> bs_aps;

  for (unsigned i = 0; i < node_num; ++i) {
    if (color[i] == Color::kWhite) {
      ArticulationPointsVisit(i, time, adjacency_list, d, low, color, parent, bs_aps);
    }
  }

  return bs_aps;
}

int main(int argc, char const *argv[]) {
  using w_type = unsigned;

  vector<Edge<w_type>> edges;
  unsigned V, E;
  cin >> V >> E;
  for (unsigned i = 0; i < E; ++i) {
    unsigned u, v;
    w_type w;
    cin >> u >> v;
    edges.emplace_back(u, v, 1);
  }

  auto bs_aps = ArticulationPoints(edges, V);
  for (unsigned i = 0; i < V; ++i) {
    if (bs_aps.test(i)) {
      cout << i << endl;
    }
  }

  return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) int((a).size())
#define out(a) cout<<(a)<<endl;
const int INF=INT_MAX;
const int MAX = 510000;
const ll MOD = 10000;
ll fac[MAX], finv[MAX], inv[MAX];

int main (){
  ll n,m,q;cin>>n>>m>>q;
  vvll a(509,vll(509,0));
  rep(i,0,m){
    ll l,r;cin>>l>>r;
    a[l][r]++;
  }
  rep(i,1,n+1){
    rep(j,1,n+1){
      a[i][j]+=a[i][j-1];
    }
  }
  rep(i,1,n+1){
    rep(j,1,n+1){
      a[i][j]+=a[i-1][j];
    }
  }
  rep(i,0,q){
    ll p,q;cin>>p>>q;
    cout<<a[q][q]+a[p-1][p-1]-a[p-1][q]-a[q][p-1]<<endl;
  }

}


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

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    string s; cin >> s;
    if (s == "zyxwvutsrqponmlkjihgfedcba") {
        cout << "-1\n";
        return 0;
    }
    int n = (int) s.size();
    if (n == 26) {
        int ind = -1;
        for (int i = n-2; i >= 0; i--) {
            if (s[i] < s[i+1]) {
                ind = i;
                break;
            }
        }
        char now;
        for (int i = n-1; i > ind; i--) {
            if (s[i] > s[ind]) {
                now = s[i];
                break;
            }
        }
        cout << s.substr(0, ind) << now << endl;
    } else {
        vector<int> oc(27);
        for (int i = 0; i < n; i++) {
            oc[s[i]-'a']=1;
        }
        int mex = 0;
        while (oc[mex]) mex++;
        cout << s << char('a' + mex) << endl;
    }

    return 0;
}

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

using namespace std;
int a;
char test[21];
char temp;

int main()
{
	scanf("%s",test);
	for(a=strlen(test)-1;a>=0;a--)
	{
	printf("%c",test[a]);
	}
	printf("\n");
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<char,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
ll INF=1LL<<60;
ll MOD=1000000007;

int main(){
    string N;
    cin >> N;
    ll n=N.size();
    ll ans=0;
    vector<ll> keta(n,0);
    for(ll i=0;i<n;i++){
        keta[i]=N[i]-'0'
    ;}
    for(ll i=n-1;i>=0;i--){
        if(keta[i]==10){
            if(i>0){
                keta[i-1]++;
                keta[i]=0;
            }
            else ans+=1;
        }
        else if(keta[i]<=4){
            ans+=keta[i];
        }
        else if(keta[i]>=6&&keta[i]<=9){
            ans+=10-keta[i];
            if(i>0){
                keta[i-1]++;
            }
            else ans+=1;
        }
        else if(keta[i]=5){
            if(i==0){
                ans+=5;
            }
            else if(keta[i-1]<=4){
                ans+=5;
            }
            else if(keta[i-1]>=5){
                ans+=5;
                keta[i-1]+=1;
            }
        }
    ;}
    cout<<ans<<endl;

    return 0;
}

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

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

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

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

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

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

  string s;
  cin >> s;

  set<ll> mi;
  rep(i, 26) mi.insert(i);

  ll n = s.size();
  string ans = "";
  rep(i, n) {
    ll idx = s[i] - 'a';
    if (mi.find(idx) != mi.end()) {
      mi.erase(idx);
      ans += s[i];
    } else {
      auto citr = mi.begin();
      ans += *citr + 'a';
      mi.erase(citr);
    }
  }  // i

  if (s == ans) {
    if (!mi.empty()) {
      rep(i, 26) {}
      ans += *mi.begin() + 'a';
    } else {
      vector<char> tst;
      rep(i, 26) tst.push_back(s[i]);
      next_permutation(tst.begin(), tst.end());
      string cmp = "";
      for (char c : tst) cmp += c;
      if (cmp < s) {
        puts("-1");
        return 0;
      } else {
        rep(i,26) if(ans[i] != cmp[i]){
          ans = cmp.substr(0, i+1);
          break;
        }
      }
    }
  }

  cout << ans << endl;

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

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

int main(){
    int n,x;
    cin>>n>>x;
    int s[n+1];
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    s[n]=INF;
    sort(s,s+n);
    int crt=0;
    ll dp[x+1]={};
    for(int i=0;i<=x;i++){
        while(s[crt]<=i)crt++;
        if(crt==0){
            dp[i]=i;
            continue;
        }
        ll inv=modpow(crt,MOD-2);
        for(int j=0;j<crt;j++){
            dp[i]=(dp[i]+dp[i%s[j]])%MOD;
        }
        dp[i]=(dp[i]*inv)%MOD;
    }
    ll ans=dp[x];
    for(int i=2;i<=n;i++){
        ans=(ans*i)%MOD;
    }
    cout<<ans<<endl;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main(){
  const ll mod=998244353;
  int n,d[100010];
  cin >> n;
  int i,ma=0;
  for(i=0;i<n;i++){
    cin >> d[i];
    ma=max(ma,d[i]);
  }
  if(d[0]!=0){
    cout << 0 << endl;
    return 0;
  }
  vector<int> x(100010,0);
  for(i=0;i<n;i++){
    x[d[i]]++;
  }
  if(x[0]!=1){
    cout << 0 << endl;
    return 0;
  }
  for(i=0;i<=ma;i++){
    if(x[i]==0){
      cout << 0 << endl;
      return 0;
    }
  }
  ll ans=1;
  for(i=1;i<=ma-1;i++){
    ans*=modpow(x[i],x[i+1],998244353);
    ans=ans%mod;
  }
  cout << ans << endl;
}


/*
  Contest 096
  B - Maximum Sum
  Rakesh Kumar --> 23/09/2020
 */

#include <bits/stdc++.h>

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

    int a = 0, b = 0, c = 0;
    std::cin >> a >> b >> c;
    int k = 0;
    std::cin >> k;
    int v = std::max(std::max(a, b), c);
    int total = a + b + c - v;
    while (k--) {
        v <<= 1;
    }
    total += v;
    std::cout << total << std::endl;

    return 0;
}

/*Author- Soumak Poddar*/

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

#define ll long long int
#define sll signed long long int
#define ull unsigned long long int
#define um unordered_map
#define us unordered_set
#define mm multimap
#define mp make_pair
#define pb push_back
#define M 1000000007

bool comp(pair<int,int> a,pair<int,int> b)
{
   return a.second<b.second;
}

template<typename T>
T gcd(T a,T b)
{
   if(a==0)
      return b;
   return gcd(b%a,a);
}
template<typename T>
T lcm(T a,T b)
{
   T g=gcd<T>(a,b);
   return (a*b)/g;
}
template<typename T>
bool isprime(T n)
{
   if(n<=1)
      return false;
   for(int i=2;i<sqrt(n);i++)
      if(n%i==0)
         return false;
   return true;
}

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

   #ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("error.txt", "w", stderr);
      freopen("output.txt", "w", stdout);
   #endif

   int t=1;
   // cin>>t;
   while(t--)
   {
      solve();
      cout<<"\n";
   }
   cerr<<"Time Taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
   return 0;
}
void solve()
{
   int d,t,s;
   cin>>d>>t>>s;
   double at=(double)d/s;
   if(at<=t)
      cout<<"Yes";
   else
      cout<<"No";
}


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

void show(int arr[], int N){
	for(int i=0; i<N; i++)
		if(i<N-1)
			cout<<arr[i]<<' '<<flush;
		else
			cout<<arr[i]<<flush;
	cout<<endl;
}

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

int ShellSort(int* arr, int N);
int InsertionSort_r(int* arr, int N, int r);

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

	int* arr= new int[N];

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

	int count=ShellSort(arr, N);

	cout<<count<<endl;

	for( int i=0; i<N; i++)
		cout<<arr[i]<<endl;

	delete[] arr;
}

int ShellSort(int* arr, int N)
{
	int counter=0;

	vector<int> range;

	for( int i=1; i<=N; i= i*3 +1 )
		range.push_back(i);

	cout<<range.size()<<endl;

	for( int i=range.size() -1; i >=0; i-- )
		cout<<range[ i ]<<' '<<flush;
	cout<<endl;

	for( int i=range.size() -1; i>=0; i-- )
		counter=InsertionSort_r(arr, N, range[ i ]);

	return counter;

}

int InsertionSort_r(int arr[], int N, int r)
{

	static int counter=0;
	int compindex;
	int comp;
	int j;

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

		for( int compindex=N- r -1 -i ; compindex> -1; compindex-=r ){

			comp=arr[compindex];
			j=r;
			for( ; compindex+j<N; j+=r ){

				if(comp > arr[compindex+j]){
					arr[compindex + j -r] = arr[compindex + j];
					counter++;
				}
				else
					break;

			}
			arr[compindex + j - r] = comp;

		}
	}
	return counter;
}
/* ?§£??????????????????????????????
	  o x x o x x x *
	  o x x o x x o *
	  x o x x o x x
	  x x o x x o x
  ??¨???????????????????????????????????????????????§???
  	  o x x o x x x *
	  x o x x o x x
	  x x o x x o x
	  o x x o x x o *
?????¨?????????????§£?????????
????????????????????¨????????????????????????(0.2?§????????§£?????????????????????????)

int InsertionSort_r(int arr[], int N, int r)
{
	static int cnt=0;
	bool changed=false;
	for( int compindex=r; compindex<N; compindex++) {

		int comp= arr[compindex];

		int j=compindex - r;

		for( ; j>=0; j-=r ) {
			if(arr[j] > comp){
				arr[ j+r ]=arr[j];
				cnt++;
				changed=true;
			}
			else
				break;
		}

		arr[ j+r ] =comp;

		changed=false;
	}
	return cnt;
}
*/

#include <iostream>
#include <algorithm>
#include <vector>
typedef int TInt;
typedef std::vector<TInt> TList;

TList Input()
{
    int Count;
    std::cin >> Count;
    TList List(Count);
    for(int i = 0; i < Count; ++i){
        std::cin >> List[i];
    }
    return List;
}
int insertionSort(TList& A, int g)
{
    int cnt = 0;
    for(int i = g; i < A.size(); ++i){
        TInt v = A[i];
        int j = i - g;
        while(j >= 0 && A[j] > v){
            A[j+g] = A[j];
            j = j - g;
            cnt++;
        }
        A[j+g] = v;
    }
    return cnt;
}
void Reverse(TList& List)
{
    TList R;
    for(TList::reverse_iterator It = List.rbegin();
        It != List.rend();
        ++It)
    {
        R.push_back(*It);
    }
    std::swap(R, List);
}
TList GetG(int Max)
{
    TList G;
    int h = 1;
    while(h <= Max){
        G.push_back(h);
        h = 3 * h + 1;
    }
    // Reverse(G);
    std::reverse(G.begin(), G.end());
    return G;
}
int shellSort(TList& A, const TList& G)
{
    int cnt = 0;
    for(TList::const_iterator It = G.begin();
        It != G.end();
        ++It){
        cnt += insertionSort(A, *It);
    }
    return cnt;
}
void OutputLine(const TList& List)
{
    TList::const_iterator It = List.begin();
    std::cout << *(It++);
    for(; It != List.end(); ++It){
        std::cout << " " << *It;
    }
    std::cout << std::endl;
}
void Output(const TList& List)
{
    TList::const_iterator It = List.begin();
    // std::cout << *(It++);
    for(; It != List.end(); ++It){
        std::cout << *It << std::endl;
    }
}
int main()
{
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    TList A = Input();
    TList G = GetG(A.size());
    int cnt = shellSort(A, G);
    std::cout << G.size() << std::endl;
    OutputLine(G);
    std::cout << cnt << std::endl;
    Output(A);
    return 0;
}


#include<iostream>
using namespace std;
int a;
int main() {
	while (cin >> a) {
		cout << (900 - a)*(900 - a) * 100 - 9000000 << endl;
	}
}

#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

int f(int n) {
    return n * n;
}

int main(void) {
    int n;
    while (cin >> n) {
        int ans = 0;
        for (int i = 0; i * n < 600; i++) {
            ans += f(i*n) * n;
        }
        cout << ans << endl;
    }
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<queue>
#include<algorithm>
#include<functional>
#include<cstdlib>
#include<cmath>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define CI cin >>
#define CO cout <<
#define E << endl;

using namespace std;

typedef pair<int, int> P;
typedef pair<long, long> LP;
typedef pair<int, P> PP;
typedef pair<long, LP> LPP;

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

string C;
void input(void) {
	CI C;
	return;
}

int main(void) {
	input();
	reverse(C.begin(), C.end());

	CO C E

	return 0;
}

  #include <iostream>
#include <string>
using namespace std;
int main(){
	string str;
	int i,j;
	cin >> str;
	string st="";
	for( i=str.size()-1; i>=0 ; i-- )
		st+=str[i] ;
	cout << st << endl;
}


#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    ll n,y;
    cin>>n>>y;
    ll noguchi=0,higuchi=0;
    rep(i,n+1){
        rep(j,n+1-i){
            if((y-(1000*i+5000*j))%10000==0&&(y-(1000*i+5000*j))/10000==n-i-j){
                printf("%d %d %d",n-i-j,j,i);
                return 0;
            }
        }
    }
    printf("-1 -1 -1");
}

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#define PI 3.14159265359
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pai;
typedef pair<ll, ll> pal;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

int main(){
	int n, y;
	cin >> n >> y;
	for (int i = 0; i <= 2000; i++){
		for (int j = 0; i+j <= 2000; j++){
			for (int k = 0; i+j+k <= 2000; k++){
				if (i+j+k == n && i*1000 + j*5000 + k*10000 == y){
					cout << k << " " << j << " " << i << endl;
					return 0;
				}
			}
		}
	}
	cout << -1 << " " << -1 << " " << -1 << endl;
	return 0;
}


/// However long the night,
///     The dawn will break
/// ICPC next year

#include<bits/stdc++.h>
using namespace std ;
const int N = 1e6+5 ;

int n ,a[N] ,b[N] ;
vector<int> xorA ,xorB ;

int nn ,mm ,pat[N], str[N];

int F[N];

int getNextLen(int len, int c){
  while(len && c != pat[len])
    len = F[len-1];
  if(c == pat[len]) ++len;
  return len;
}

void computeF(){
  for(int i = 1 ; i<nn ; ++i)
    F[i] = getNextLen(F[i-1], pat[i]);
}

vector<int> search(){
  int len = 0;
  vector<int> res;
  for(int i = 0 ; i<mm ; ++i){
    len = getNextLen(len, str[i]);
    if(len==nn){
        res.push_back(i-len+1);
    }
  }
  return res;
}

int main(){
    memset(pat,-1,sizeof pat);
    memset(str,-1,sizeof str);
    scanf("%d",&n);
    for(int i=0;i<n;++i) scanf("%d",a+i);
    for(int i=0;i<n;++i) scanf("%d",b+i);
    for(int i=0;i<n;++i){
        xorA.push_back(a[i]^a[(i+1)%n]);
        xorB.push_back(b[i]^b[(i+1)%n]);
    }
    for(int i=n;i<n+n+n;++i) xorA.push_back(xorA[i-n]);

    for(int i=0;i<xorA.size();++i) str[i] = xorA[i] ;
    for(int i=0;i<xorB.size();++i) pat[i] = xorB[i] ;
    mm = xorA.size() ;
    nn = xorB.size() ;
    computeF() ;
    auto v = search() ;

    for(auto go:v){
        if(go>=n) break ;
        int x = a[go]^b[0] ;
        printf("%d %d\n",go,x);
    }
    return 0;
}

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

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

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

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

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

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

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

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

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


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

//ライブラリ始まり

//定数

//円周率
const double PI = 3.1415926535897932384;

//天井
const int INF = 1000000000; // = 10^9
const ll LINF = 1000000000000000; // = 10^15

//ABC文字列
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZABC";
const string abc = "abcdefghijklmnopqrstuvwxyzabc";

//よくあるmodくん
const ll MOD = 1000000007; // = 10^9 + 7

//データ構造

//Union_Find木
struct UnionFind {
  vector<int> UF; // UF.at(i) : iの親の番号
  vector<int> SIZE; // SIZE.at(root(i)) : iと連結されてる要素の数
  UnionFind(int N) : UF(N), SIZE(N, 1) { // 最初は全てが根であるとして初期化
    for(int i = 0; i < N; i++) {
      UF.at(i) = i;
    }
  }
  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (UF.at(x) == x) {
      return x;
    }
    return UF.at(x) = root(UF.at(x));
  }
  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); // xの根をrx
    int ry = root(y); // yの根をry
    if (rx == ry) {
      return; // xとyの根が同じ(=同じ木にある)時はそのまま
    }
    // xとyの根が同じでない(=同じ木にない)時：小さい方の根を大きい方の根につける
    if (SIZE.at(rx) < SIZE.at(ry)) {
      UF.at(rx) = ry;
      SIZE.at(ry) += SIZE.at(rx);
      SIZE.at(rx) = 0;
    }
    else {
      UF.at(ry) = rx;
      SIZE.at(rx) += SIZE.at(ry);
      SIZE.at(ry) = 0;
    }
  }
  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
  int size(int x) { // xと連結されてる要素の数を返す
    return SIZE.at(root(x));
  }
};

//関数

//ctoi
int ctoi(char c){
  if (c == '0') {
    return 0;
  }
  if (c == '1') {
    return 1;
  }
  if (c == '2') {
    return 2;
  }
  if (c == '3') {
    return 3;
  }
  if (c == '4') {
    return 4;
  }
  if (c == '5') {
    return 5;
  }
  if (c == '6') {
    return 6;
  }
  if (c == '7') {
    return 7;
  }
  if (c == '8') {
    return 8;
  }
  if (c == '9') {
    return 9;
  }
  return -1;
}

//素数判定
bool PN(int x) {
  if (x <= 1) {
    return false; // 1や0,-1は素数ではない
  }
  if (x == 2) {
    return true; // √2 + 1 > 2 なので下でやると 2 ％ 2 = 0 となり判定できない
  }
  for (int i = 2; i < sqrt(x) + 1; i++) {
    if (x % i == 0) {
      return false; // 割れたら素数じゃない
    }
  }
  return true;
}

//ライブラリ終わり

int main() {
  ll N, A, B;
  cin >> N >> A >> B;
  vector<ll> M(N, 0);
  vector<ll> X(N);
  for (int i = 0; i < N; i++) {
    cin >> X.at(i);
  }
  for (int i = 1; i < N; i++) {
    M.at(i) = min(M.at(i - 1) + B,
                  M.at(i - 1) + A * (X.at(i) - X.at(i - 1)));
  }
  cout << M.at(N - 1) << endl;
}

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

using namespace std;

const long MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;

int main(){
    int N, A, B;
    cin >> N >> A >> B;

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

    sort(X, X+N);

    int now = X[0];
    ll ans = 0;
    for(int i=0; i<N; i++){
        ll w = (ll)A*(X[i] - now);
        ll t = B;
        ans = ans + min(w, t);
        now = X[i];
    }

    cout << ans << endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define co(a) cout<<a<<endl
#define sz size()
#define bgn begin()
#define en end()
#define pb(a) push_back(a)
#define pop pop_back
#define V vector
#define P pair
#define V2(a,b,c) V<V<int>> a(b,V<int>(c))
#define V2a(a,b,c,d) V<V<int>> a(b,V<int>(c,d))
#define incin(a) int a; cin>>a
#define yuko(a) setprecision(a)
//#define min min<int>
//#define max max<int>
template<class T>
 void cou(vector<vector<T>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}
/*template<>
 void cou(vector<vector<char>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}*/
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 int lcm(int a,int b){
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }
 bool prime(int a){
   if(a<2)
     return false;
   else if(a==2)
     return true;
   else if(a%2==0)
     return false;
   double b=sqrt(a);
    for(int i=3;i<=b;i+=2){
      if(a%i==0){
        return false;
      }
    }
   return true;
 }
struct Union{
  vector<int> par;
  Union(int n){
	par= vector<int>(n, -1);
  }
  int find(int x){
    if(par[x]<0)
      return x;
    else
      return par[x]=find(par[x]);
  }
  bool same(int a,int b){
    return find(a)==find(b);
  }
  int Size(int a){
    return -par[find(a)];
  }
  void unite(int a,int b){
    a=find(a);
    b=find(b);
    if(a==b)
      return;
    if(Size(b)>Size(a))
      swap<int>(a,b);
    par[a]+=par[b];
    par[b]=a;
  }
};
int ketas(int a){
  string b=to_string(a);
  int c=0;
  fo(i,keta(a)){
    c+=b[i]-'0';
  }
  return c;
}
/*struct aa{
	vector<int> gt;
  aa(int n){
	gt= vector<int>(n, 1);
  }
	void c(V<int> d,int b){
	if(d[b]==0){
		gt[d[b]-1]++;
		gt[gt.sz-1]++;
	}
	else{
		gt[d[b]-1]++;
		c(d,d[d[b]]-1);
	}
}
void cok(int a){
	cout<<gt[a-1]<<endl;
	fo(i,a-1)
	cout<<gt[i]<<endl;
}
};
*/
signed main(){
	int a;
	cin>>a;
	cout<<180*(a-2)<<endl;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll inf = 1e9+7;

int main(){

    ll a,b;
    cin>>a>>b;
    cout << a*b;

}


#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}
int Madd(int x,int y) {return (x+y)%M;}
int Msub(int x,int y) {return (x-y+M)%M;}
int Mmul(int x,int y) {return (x*y)%M;}

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WG = vector< Edges< T > >;
using UG = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

template< typename T >
struct LowLink {
  const WG<T> &g;
  vector< int > used, ord, low;
  vector< int > articulation;
  vector< pair< int, int > > bridge;

  LowLink(const WG<T> &g) : g(g) {}

  int dfs(int idx, int k, int par) {
    used[idx] = true;
    ord[idx] = k++;
    low[idx] = ord[idx];
    bool is_articulation = false;
    int cnt = 0;
    for(auto &e : g[idx]) {
      if(!used[e.to]) {
        ++cnt;
        k = dfs(e.to, k, idx);
        low[idx] = min(low[idx], low[e.to]);
        is_articulation |= ~par && low[e.to] >= ord[idx];
        if(ord[idx] < low[e.to]) bridge.emplace_back(minmax(idx, (int) e.to));
      } else if(e.to != par) {
        low[idx] = min(low[idx], ord[e.to]);
      }
    }
    is_articulation |= par == -1 && cnt > 1;
    if(is_articulation) articulation.push_back(idx);
    return k;
  }

  virtual void build() {
    used.assign(g.size(), 0);
    ord.assign(g.size(), 0);
    low.assign(g.size(), 0);
    int k = 0;
    for(int i = 0; i < g.size(); i++) {
      if(!used[i]) k = dfs(i, k, -1);
    }
  }
};

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

  int n,m;
  cin>>n>>m;
  WG<int> es(n);
  rep(i,m){
    int x,y;
    cin>>x>>y;
    es[x].PB(edge<int>(y,1));
    es[y].PB(edge<int>(x,1));
  }

  LowLink<int> lowlink(es);
  lowlink.build();
  sort(all(lowlink.articulation));
  for(int x:lowlink.articulation){
    cout<<x<<endl;
  }

}

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

int timer = 0;

struct needed {

	needed(int verNum) {
		for (int i = 0; i < verNum; i++) {
			visited.push_back(false);
			preNum.push_back(1 << 30);
			lowest.push_back(1 << 30);
			parent.push_back(-1);
		}
	}

	vector<bool> visited;
	vector<int> preNum; //?¨?????????????
	vector<int> lowest;
	vector<int> parent;

};

void DFS(int current, int previous, vector<int> verVal[], needed &need) {

	need.preNum[current] = timer;
	need.lowest[current] = timer;
	timer++;

	need.visited[current] = true;

	for (int i = 0; i < verVal[current].size(); i++) {
		int next = verVal[current][i];
		if (!need.visited[next]) {
			need.parent[next] = current;
			DFS(next, current, verVal, need);
			need.lowest[current] = min(need.lowest[current], need.lowest[next]);
		}
		else if (next != previous) {
			need.lowest[current] = min(need.lowest[current], need.preNum[next]);
		}
	}
}

void ArticulationPoint(vector<int> verVal[], int verNum) {

	needed need(verNum);
	DFS(0, -1, verVal, need);

	set<int> artPoints;
	int childNumOfRoot = 0;
	//root??????????????¨??¨
	for (int i = 1; i < verNum; i++) {
		int nowP = need.parent[i];
		if (nowP == 0) childNumOfRoot++;
		else if (need.preNum[nowP] <= need.lowest[i])
			artPoints.insert(nowP);
	}
	//root?????¢?????????????????????????????????????????£??????????????§?????????
	if (childNumOfRoot > 1) artPoints.insert(0);

	for (set<int>::iterator it = artPoints.begin(); it != artPoints.end(); it++)
		cout << *it << endl;
}

int main() {

	int verNum, edgeNum;
	cin >> verNum >> edgeNum;
	vector<int> verVal[100000];

	for (int i = 0; i < edgeNum; i++) {
		int firVal, secVal;
		cin >> firVal >> secVal;
		verVal[firVal].push_back(secVal);
		verVal[secVal].push_back(firVal);
	}

	ArticulationPoint(verVal, verNum);

	return 0;
}


/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>

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

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

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

ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}

//-----------------------ここから-----------
int main(void){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int q;
    cin >> q;
    vector<int> K(q);
    for(int i = 0; i < q; i++) cin >> K[i];
    for(int i = 0; i < q; i++){
        int k = K[i];
        int r = 0;
        ll dcnt = 0;
        ll dmcnt = 0;
        ll dmccnt = 0;
        ll mcnt = 0;
        for(int l = 0; l < n; l++){
            while(r < n && r - l < k){
                if(s[r] == 'D'){
                    dcnt++;
                } else if(s[r] == 'M'){
                    dmcnt += dcnt;
                    mcnt++;
                } else if(s[r] == 'C') {
                    dmccnt += dmcnt;
                }
                r++;
            }

            //cout << l <<" " << r << " " << dcnt << " " << dmcnt << " " << dmccnt << endl;

            //if(r == l) r++;

            if(s[l] == 'D'){
                dmcnt -= mcnt;
                dcnt--;
            }

            if(s[l] == 'M') mcnt--;
        }
        cout << max(0LL,dmccnt) << endl;
    }
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int N;
string S;
int Q;
int k[100];
ll D[1000010];
ll M[1000010];
ll C[1000010];
ll sum[1000010];
ll ans[100];

void input(){
    cin >> N >> S >> Q;
    for(int i = 0; i < Q; i++){
        cin >> k[i];
    }
}

void solve(){
    for(int i = 0; i < N; i++){
        if(S[i] == 'M') M[i]++;
        M[i + 1] = M[i];
        if(S[i] == 'C') C[i]++;
        C[i + 1] = C[i];
    }

    for(int i = 1; i < N; i++){
        sum[i] = sum[i - 1];
        if(S[i] == 'C') sum[i] += M[i];
    }

    for(int i = 0; i < Q; i++){
        for(int j = 0; j < N; j++){
            if(S[j] != 'D') continue;
            int nd = min(j + k[i] - 1, N - 1);
            ll res = sum[nd] - sum[j] - M[j] * (C[nd] - C[j]);
            ans[i] += res;
        }
    }
}

void output(){
    for(int i = 0; i < Q; i++){
        cout << ans[i] << endl;
    }
}

int main(){
    input();
    solve();
    output();
    return 0;
}


#include <bits/stdc++.h>
#define dbug(x) cout<<#x<<"="<<x<<endl
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const int maxn=(1e5)+10;
int n,x; ll s[maxn],S;
struct node {
	int l,r,a; ll t;
	void init() {
		read(a); read(l); read(r);
		t=(ll)a*l+(ll)(x-a)*r;
		S-=(ll)l*a;
	}
} d[maxn];
bool cmp(node A,node B) {
	return A.t>B.t;
}
bool solve(ll mid) {
	ll q=mid/x,r=mid-q*x,tmp;
	if (q==n) return 1;
	for (int i=1;i<=n;i++) {
		tmp=S;
		if (i<=q) tmp+=s[q+1]-d[i].t;
		else tmp+=s[q];
		if (r>=d[i].a) tmp+=(ll)d[i].l*d[i].a+(r-d[i].a)*d[i].r;
		else tmp+=r*d[i].l;
		if (tmp>=0) return 1;
	} return 0;
}
int main() {
	//freopen("1.txt","r",stdin);
	read(n); read(x);
	for (int i=1;i<=n;i++) d[i].init();
	sort(d+1,d+n+1,cmp);
	for (int i=1;i<=n;i++) s[i]=s[i-1]+d[i].t;
	ll l=0,r=(ll)x*n,mid,res;
	while (l<=r) {
		mid=(l+r)/2;
		if (solve(mid)) r=mid-1,res=mid;
		else l=mid+1;
	}
	printf("%lld\n",res);
	return 0;
}

#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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);
}
using Graph = vector<vector<int>>;
Graph G;

int main(){
    int d; cin >> d;
    ll g; cin >> g;
    vector<ll> p(d);
    vector<ll> c(d);
    rep(i, d) cin >> p[d - 1 - i] >> c[d - 1 - i];

    int min_count = 100000000;
    int count, sum;
    bool flag;
    for(int bit = 0; bit < (1 << d); bit++){
        flag = false;
        count = 0;
        sum = 0;
        for(int i = 0; i < d; i++){
            if(bit & (1 << i)){
                int num;
                if((g - sum) > (d - i) * 100 * p[i] + c[i]){
                    sum += (d - i) * 100 * p[i] + c[i];
                    count += p[i];
                }else{
                    num = min(((g - sum) + ((d - i) * 100) - 1) / ((d - i) * 100), p[i]);
                    count += num;
                    flag = true;
                }
            }
            if(flag) break;
        }
        //cout << count << endl;
        if(flag) min_count = min(count, min_count);
    }
    cout << min_count << endl;
}