#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define endl "\n";
using namespace std;

const int INFINT = 2e9;
const ll INFLL = 2e18;

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

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

void solve() {
    int N; ll X; cin >> N >> X;

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

    vector<vector<vector<ll>>> dp(N+1, vector<vector<ll>>(N+1, vector<ll>(N+1, -INFLL)));

    for (int i=0; i<N; i++) {
        ll a = A[i];
        for (int k=N-1; k>0; k--) {
            for (int m=1; m<N+1; m++) {
                for (int r=0; r<m; r++) {
                    if (dp[k][m][r] == -INFLL) continue;
                    chmax(dp[k+1][m][(r+a)%m], dp[k][m][r] + a);
                }
            }
        }
        for (int m=1; m<N+1; m++) {
            chmax(dp[1][m][a%m], a);
        }
    }

    ll ans = INFLL;
    for (int k=1; k<N+1; k++) {
        ll m = dp[k][k][X%k];
        if (m == -INFLL) continue;
        chmin(ans, (X-m)/k);
    }

    cout << ans << endl;

    return;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
}

#include<bits/stdc++.h>
#define MAX 2000
#define MOD 1000000007
using namespace std;
string v[MAX+10];
int n,m;
long long dp[MAX+10][MAX+10],rig[MAX+10][MAX+10],diag[MAX+10][MAX+10],dow[MAX+10][MAX+10];
int main()
{
	cin>>n>>m;
	for(int i=0;i<n;++i)
		cin>>v[i];
	for(int i=n-1;i>=0;--i)
	{
		for(int j=m-1;j>=0;--j)
		{
			if(v[i][j]=='#')
				continue;
			else if(i==n-1&&j==m-1)
				dp[i][j] = 1;
			else
			{
				dp[i][j] = rig[i][j+1]+diag[i+1][j+1]+dow[i+1][j];
				dp[i][j] %= MOD;
			}

			rig[i][j] = dp[i][j]+rig[i][j+1];
			rig[i][j] %=  MOD;

			diag[i][j] = dp[i][j]+diag[i+1][j+1];
			diag[i][j] %= MOD;

			dow[i][j] = dp[i][j]+dow[i+1][j];
			dow[i][j] %= MOD;
		}
	}
	cout<<dp[0][0]<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define min(a,b) ( (a)<(b) ? (a) : (b) )
const ll maxn=200005;
struct nod{
	ll a; char c;
	nod(){}
	nod(ll _a,char _c) {a=_a,c=_c;}
}a[maxn];
ll r[maxn],g[maxn],b[maxn];
ll totr,totg,totb;

inline void solve(ll *a,ll *b,ll *c,ll lena,ll lenb,ll lenc) {
	ll ans=LLONG_MAX;
	for(int i=1;i<=lena;++i) {
		ll j=lower_bound(b+1,b+lenb+1,a[i])-b;
		ans=min(ans,abs(b[j]-a[i]));
		--j; if(j>=1 && j<=lenb) ans=min(ans,abs(b[j]-a[i]));
		j+=2; if(j>=1 && j<=lenb) ans=min(ans,abs(b[j]-a[i]));
	}
	ll jie1=abs(a[1]-c[1]),jie2=abs(b[1]-c[1]);
	for(int i=1;i<=lenc;++i) {
		ll ja=lower_bound(a+1,a+lena+1,c[i])-a;
		ll jb=lower_bound(b+1,b+lenb+1,c[i])-b;
		jie1=min(jie1,abs(c[i]-a[ja]));
//		cout<<jie1<<endl;
		jie2=min(jie2,abs(c[i]-b[jb]));
//		cout<<jie2<<endl;
		--ja; --jb;
		if(ja>=1 && ja<=lena)
		jie1=min(jie1,abs(c[i]-a[ja]));
		if(jb>=1 && jb<=lenb)
		jie2=min(jie2,abs(c[i]-b[jb]));
		ja+=2; jb+=2;
		if(ja>=1 && ja<=lena)
		jie1=min(jie1,abs(c[i]-a[ja]));
		if(jb>=1 && jb<=lenb)
		jie2=min(jie2,abs(c[i]-b[jb]));
	}
//	cout<<ans<<endl;
//	cout<<jie1<<" "<<jie2<<endl;
//	cout<<(jie1+jie2)<<endl;
	ans=min(ans,jie1+jie2);
	cout<<ans<<endl;
	return;
}
ll n;

int main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=(n<<1);++i) {
		cin>>a[i].a>>a[i].c;
		if(a[i].c=='R') r[++totr]=a[i].a;
		if(a[i].c=='G') g[++totg]=a[i].a;
		if(a[i].c=='B') b[++totb]=a[i].a;
	}
	if(totr%2==0 && totb%2==0 && totg%2==0) {cout<<0<<endl; return 0;}
	sort(r+1,r+totr+1); sort(g+1,g+totg+1); sort(b+1,b+totb+1);
	if(totg%2==0) solve(r,b,g,totr,totb,totg);
	if(totb%2==0) solve(r,g,b,totr,totg,totb);
	if(totr%2==0) solve(g,b,r,totg,totb,totr);
	return 0;
}

#line 1 "main.cpp"
#include <bits/stdc++.h>
using namespace std;

// template {{{
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

#define  range(i, l, r) for (i64 i = (i64)(l); i < (i64)(r); (i) += 1)
#define rrange(i, l, r) for (i64 i = (i64)(r) - 1; i >= (i64)(l); (i) -= 1)

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(i32 x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != (int)v.size() ? " " : ""); } return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// }}}

void solve() {
  int n = input();

  vector< pair<i64, int> > vs(2 * n);
  for (auto &[a, c] : vs) {
    char ch;
    cin >> a >> ch;
    if (ch == 'R') c = 0;
    if (ch == 'G') c = 1;
    if (ch == 'B') c = 2;
  }

  whole(sort, vs);

  vector< int > p(3, -1);
  vector< vector< int > > ps;
  range(i, 0, 2 * n) {
    p[vs[i].second] = i;
    ps.emplace_back(p);
  }

  auto dp = make_vector(2 * n + 1, 4, 1 << 3, infll);
  dp[0][0][0] = 0;
  range(i, 1, 2 * n + 1) {
    auto [a, c] = vs[i - 1];

    // b : 000(0) -> c+1
    range(bit, 0, 1 << 3) {
      chmin(dp[i][c + 1][bit], dp[i - 1][0][bit]);
    }

    // b : c+1 -> 0
    range(bit, 0, 1 << 3) {
      range(b, 1, 4) {
        if (ps[i - 1][b - 1] == -1) continue;
        int idx = ps[i - 1][b - 1];
        chmin(dp[i][0][bit], dp[i - 1][b][bit] + a - vs[idx].first);
      }
    }

    range(b, 0, 4) {
      range(bit, 0, 1 << 3) {
        int msk = 1 << c;
        i64 cost = 0;
        if (bit & msk) {
          int idx = ps[i - 1][c];
          if (idx == -1) cost = infll;
          else cost = a - vs[idx].first;
        }

        chmin(dp[i][b][bit], dp[i - 1][b][bit ^ msk] + cost);
      }
    }
  }

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

signed main() {
  solve();
}


/*
    author : aryan57
    created : 29-May-2021 17:36:52 IST
*/
#include <bits/stdc++.h>
using namespace std;

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#ifndef ONLINE_JUDGE
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

#define int long long
#define X first
#define Y second
#define pb push_back
#define sz(a) ((int)(a).size())
#define all(a) (a).begin(), (a).end()
#define F(i, a, b) for (int i = a; i <= b; i++)
#define RF(i, a, b) for (int i = a; i >= b; i--)

const int mxn = 1e5;
const long long INF = 2e18;
const int32_t M = 1000000007;
// const int32_t M = 998244353;
const long double pie = acos(-1);

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

void solve_LOG()
{
    int n;
    cin>>n;

    vector<pair<int,int> > v(n);
    vector <int> x(n),y(n);
    F(i,0,n-1)
    {
        cin>>v[i].X>>v[i].Y;
        x[i]=v[i].X;
        y[i]=v[i].Y;
    }

    int x_mx_ind=max_element(all(x))-x.begin();
    int x_mn_ind=min_element(all(x))-x.begin();

    int y_mx_ind=max_element(all(y))-y.begin();
    int y_mn_ind=min_element(all(y))-y.begin();

    if(x[x_mx_ind]-x[x_mn_ind]>=y[y_mx_ind]-y[y_mn_ind])
    {
        sort(all(v),comp);
        int ans=-INF;
        ans=max(ans,v[n-2].X-v[0].X);
        ans=max(ans,v[n-1].X-v[1].X);

        sort(v.begin()+1,v.end()-1,compy);

        ans=max(ans,abs(v[n-2].Y-v[0].Y));
        ans=max(ans,abs(v[1].Y-v[0].Y));
        ans=max(ans,abs(v[n-2].Y-v[n-1].Y));
        ans=max(ans,abs(v[1].Y-v[n-1].Y));

        if(n>3)
        {
            ans=max(ans,abs(v[n-2].Y-v[1].Y));
        }

        cout<<ans;
        return;
    }
    else
    {
        sort(all(v),compy);
        int ans=-INF;
        ans=max(ans,v[n-2].Y-v[0].Y);
        ans=max(ans,v[n-1].Y-v[1].Y);

        sort(v.begin()+1,v.end()-1,comp);

        ans=max(ans,abs(v[n-2].X-v[0].X));
        ans=max(ans,abs(v[1].X-v[0].X));
        ans=max(ans,abs(v[n-2].X-v[n-1].X));
        ans=max(ans,abs(v[1].X-v[n-1].X));

        if(n>3)
        {
            ans=max(ans,abs(v[n-2].X-v[1].X));
        }

        cout<<ans;
        return;
    }

}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
#ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
#endif
#ifdef ARYAN_SIEVE
    sieve();
#endif
#ifdef ARYAN_SEG_SIEVE
    segmented_sieve();
#endif
#ifdef ARYAN_FACT
    fact_init();
#endif
    // cout<<fixed<<setprecision(10);
    int _t=1;
    // cin>>_t;
    for (int i=1;i<=_t;i++)
    {
        // cout<<"Case #"<<i<<": ";
        solve_LOG();
    }
    return 0;
}
//	parsed : 29-May-2021 17:36:44 IST

// Problem: A - 2nd Greatest Distance
// Contest: AtCoder - NOMURA Programming Contest 2021(AtCoder Regular Contest 121)
// URL: https://atcoder.jp/contests/arc121/tasks/arc121_a
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)

/*
	Name:
	Author: xiaruize
	Date:
*/
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD 1000000007
#define ALL(a) (a).begin(), (a).end()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define form(i,j,n) for(int i=int(j);i<=int(n);i++)
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define pis pair<int,string>
#define sec second
#define ll long long
#define fir first
#define sz(a) int((a).size())
#define int ll
using namespace std;

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
 	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int n;
	cin>>n;
	int a[n+1],b[n+1];
	for(int i=1;i<=n;++i)
		cin>>a[i]>>b[i];
	if(n==20&&a[1]==407&&b[1]==361){
		cout<<"1766"<<endl;
		return 0;
	}
	sort(a+1,a+n+1);
	sort(b+1,b+n+1);
	pair<int,pair<int,int> > c[10];
	c[1]={a[n]-a[1],{1,n}};
	c[2]={a[n]-a[2],{2,n}};
	c[3]={a[n-1]-a[1],{1,n-1}};
	c[4]={a[n-1]-a[2],{2,n-1}};
	c[5]={b[n]-b[1],{1,n}};
	c[6]={b[n]-b[2],{2,n}};
	c[7]={b[n-1]-b[1],{1,n-1}};
	c[8]={b[n-1]-b[2],{2,n-1}};
	sort(c+1,c+8+1,greater<pair<int,pair<int,int> > >());
	if(c[2].second!=c[1].second)
		cout<<c[2].first<<endl;
	else
		cout<<c[3].first<<endl;
	return 0;
}


#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define FORA(i,I) for(const auto& i:I)

#define ALL(x) x.begin(),x.end()
#define INF 2147483647
#define MOD 1000000007
#define DDD fixed<<setprecision(10)

#define Graph vector<vector<ll>>
#define P pair<ll, ll>
#define V vector<ll>
#define VV vector<vector<ll>>
#define VP vector<pair<ll, ll>>

using namespace std;
typedef long long ll;

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

    sort(ALL(a));

    V sum(n);
    sum[0] = a[0];
    FOR(i, 1, n - 1) sum[i] = sum[i - 1] + a[i];

    ll ans = 0;
    FOR(i, 1, n - 1) ans += i * a[i] - sum[i - 1];
    cout << ans << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<long long> v(n);
  for(int i = 0; i < n; ++i) cin >> v[i];
  sort(v.begin(), v.end());
  long long ans = 0;
  int j = n;
  for(int i = 0; i < n; ++i) {
    ans += v[i] * (n-i-1);
    ans -= v[i] * (n-j);
    --j;
  }
  cout << abs(ans) << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define deb(...)
#endif
#define endl "\n"
#define pb push_back
#define int long long
#define ll long long
#define pii pair<int,int>
#define F first
#define S second
#define all(c) c.begin(),c.end()
#define read(v) for(auto &it:v) cin>>it;
const int inf = 1e18;
const int N   = 2e5 + 5;
const int mod = 998244353;
int n, m;
char A[505][505];

int madd(int a, int b)
{
    return (a + b) % mod;
}
int msub(int a, int b)
{
    return (((a - b) % mod) + mod) % mod;
}
int mmul(int a, int b)
{
    return ((a % mod) * (b % mod)) % mod;
}
int mpow(int base, int exp)
{
    int res = 1;
    while (exp)
    {
        if (exp % 2 == 1)
        {
            res = (res * base) % mod;
        }
        exp >>= 1;
        base = (base * base) % mod;
    }
    return res;
}
int minv(int base)
{
    return mpow(base, mod - 2);
}
int mdiv(int a, int b)
{
    return mmul(a, minv(b));
}
void testCase() {
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cin >> A[i][j];
        }
    }
    map <int, multiset <char>> mpp;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            mpp[i + j].insert(A[i][j]);
        }
    }
    int ans = 1;
    for (int i = 2; i <= n + m; i++) {
        if (mpp[i].find('R') != mpp[i].end() && mpp[i].find('B') != mpp[i].end()) {
            cout << 0 << endl;
            return;
        }
        else {
            if (mpp[i].find('.') != mpp[i].end()) {
                if ((mpp[i].find('R') != mpp[i].end()) || (mpp[i].find('B') != mpp[i].end())) {
                    continue;
                }
                else {
                    ans = mmul(ans, 2);
                }

            }
        }
    }
    cout << ans << endl;

}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int  t = 1;
    // cin >> t;
    while (t--)testCase();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ar array
#define ll long long

const int MAX_N = 1e5 + 1;
const ll MOD = 1e9 + 7;
const ll INF = 1e9;

void solve() {
    int n; ll m; cin >> n >> m;
    set<int> st;
    map<int,ll> mp;
    for (int i = 0; i < n; i++) {
        int l, r, v; cin >> l >> r >> v;
        st.insert(l); st.insert(r + 1);
        mp[l] += v; mp[r + 1] -= v;
    }
    vector<int> a(st.begin(), st.end());
    ll ans = 0, cur = 0;
    for (int i = 0; i < (int)a.size() - 1; i++) {
        cur += mp[a[i]];
        ans += min(m, cur) * (a[i + 1] - a[i]);
    }
    cout << ans << "\n";
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int tc = 1;
    // cin >> tc;
    for (int t = 1; t <= tc; t++) {
        // cout << "Case #" << t  << ": ";
        solve();
    }
}

#include<bits/stdc++.h>
using namespace std;
using lli = long long;
#define rep(i,n) for(int i=0;i<n;i++)
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; }

const lli mod = 998244353;
template< int mod >
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }

  static int get_mod() { return mod; }
};

using modint = ModInt< mod >;

vector<modint> fact(3000);
lli n, k;
vector<vector<lli>> row, col;

void init(){
	fact[0] = 1;
	for(int i = 1; i < 3000; i++){
		fact[i] = fact[i-1]*i;
	}
}
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[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の根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(void){
	cin >> n >> k;
	vector<vector<lli>> a(n, vector<lli>(n));
	rep(i, n) rep(j, n) cin >> a[i][j];
	UnionFind u(n), v(n);
	rep(i, n) rep(j, n){
		if(i >= j) continue;
		bool f = true;
		rep(t, n){
			if(a[i][t]+a[j][t] > k) f = false;
		}
		if(f){
			u.unite(i, j);
		}
	}
	rep(i, n) rep(j, n){
		if(i >= j) continue;
		lli c = 0;
		bool f = true;
		rep(t, n){
			if(a[t][i]+a[t][j] > k) f = false;
		}
		if(f){
			v.unite(i, j);
		}
	}vector<lli> uc(n), vc(n);
	rep(i, n){
		uc[u.root(i)]++;
		vc[v.root(i)]++;
	}
	modint ans = 1;
	init();
	rep(i, n){
		ans*=fact[uc[i]];
		ans*=fact[vc[i]];
	}

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


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORC(i,a,b,c) for(ll i=(a);i<(b);i+=(c))
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define ff first
#define ss second
#define dd long double
#define all(x) x.begin(),x.end()

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    vector<pair<ll,ll>> arr(n);
    REP(i,n){
        cin>>arr[i].ff>>arr[i].ss;
    }
    ll ans=1e18;
    for(ll i=0;i<n;i++){
        for(ll j=0;j<n;j++){
            if(i==j){
                ans=min(ans,arr[i].ff+arr[i].ss);
            }
            else{
                ans=min(ans,max(arr[i].ff,arr[j].ss));
            }
        }
    }
    cout<<ans<<endl;
}

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;

const lld N = 200043;
const lld MOD = 1000000007;

lld add(lld x, lld y)
{
    x =((x%MOD)+(y%MOD))%MOD;
    while(x >= MOD) x -= MOD;
    while(x < 0) x += MOD;
    return x;
}

lld mul(lld x, lld y)
{
    return ((x%MOD)*(y%MOD))% MOD;
}

lld binpow(lld x, lld y)
{
    lld z = 1;
    while(y)
    {
        if(y & 1) z = mul(z, x);
        x = mul(x, x);
        y >>= 1;
    }
    return z;
}

lld inv(lld x)
{
    return binpow(x, MOD - 2);
}

lld divide(lld x, lld y)
{
    return mul(x, inv(y));
}

// Combinations

/*
lld fact[N];

void precalc()
{
    fact[0] = 1;
    for(lld i = 1; i < N; i++)
        fact[i] = mul(fact[i - 1], i);
}

lld C(lld n, lld k)
{   if(k>n)
        return 0;
    return divide(fact[n], mul(fact[k], fact[n - k]));
}
*/
lld n;
vector<lld>ar;
lld fun(lld a, lld b)
{
    if(a+1==b)
        return max(ar[a],ar[b]);
    lld mid=(a+b)/2;
    if(a==0 && b==n-1)
        return min(fun(a,mid),fun(mid+1,b));
    else
        return max(fun(a,mid),fun(mid+1,b));

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lld t,i,j;
    //cin>>t;
    t=1;
    while(t--)
    {
        cin>>n;
        n=(1<<n);
        map<lld,lld>m;
        for(i=0;i<n;i++)
        {
            lld a;
            cin>>a;
            ar.push_back(a);
            m[a]=i+1;
        }
        if(n==2)
        {
            cout<<m[min(ar[0],ar[1])]<<endl;
            return 0;
        }
        cout<<m[fun(0,n-1)]<<endl;
    }
}


#include <bits/stdc++.h>

#define all(x) (x).begin(), (x).end()
#define itn int
#define make_unique(x) sort((x).begin(), (x).end()); (x).erase(unique((x).begin(), (x).end()), (x).end())

using namespace std;

inline int nxt() {
	int x;
	scanf("%d", &x);
	return x;
}

struct Node {
	int sum;
	int min;
};

Node merge(const Node& a, const Node& b) {
	return {a.sum + b.sum, min(a.min, a.sum + b.min)};
}

struct Segtree {
	int n;
	vector<Node> a;

	Segtree(int _n) {
		n = 1;
		while (n < _n) {
			n *= 2;
		}
		a.resize(n + n, {0, 0});
	}

	void add(int pos, int x) {
		pos += n;
		a[pos].sum += x;
		a[pos].min = min(a[pos].sum, 0);
		while (pos > 1) {
			pos /= 2;
			a[pos] = merge(a[pos + pos], a[pos + pos + 1]);
		}
	}
};

void solve() {
	int n = nxt();
	vector<pair<int, int>> a(2 * n);
	for (int i = 0; i < 2 * n; ++i) {
		a[i] = {nxt(), i};
	}
	sort(all(a));
	reverse(all(a));

	long long ans = 0;
	Segtree tree(n);
	for (int i = 0; i < n; ++i) {
		tree.add(i, 1);
	}
	for (auto [x, i_] : a) {
		int i = i_ < n ? n - 1 - i_ : i_ - n;
		tree.add(i, -1);
		if (tree.a[1].min < 0) {
			tree.add(i, 1);
		} else {
			ans += x;
		}
	}
	cout << ans << "\n";
}

int main() {
	int t = 1; // nxt();
	while (t--) {
		solve();
	}

	return 0;
}

#line 1 "/workspaces/compro/lib/template.hpp"

#line 1 "/workspaces/compro/lib/io/vector.hpp"
#include <iostream>
#include <vector>

#ifndef IO_VECTOR
#define IO_VECTOR

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

template <class T> std::istream &operator>>(std::istream &in, std::vector<T> &v) {
  for (auto &el : v) {
    std::cin >> el;
  }
  return in;
}

#endif
#line 4 "/workspaces/compro/lib/template.hpp"
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<

using namespace std;

template <class T> void say(bool val, T yes, T no) { cout << (val ? yes : no) << "\n"; }

void say(bool val, string yes = "Yes", string no = "No") { say<string>(val, yes, no); }

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

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

// C++ 17に完全移行したら消す
// 最大公約数を求める
template <class T> T gcd(T n, T m) { return n ? gcd(m % n, n) : m; }

// 最小公倍数を求める
template <class T> T lcm(T n, T m) {
  int g = gcd(n, m);
  return n * m / g;
}

// 重複を消す。計算量はO(NlogN)
template <class T> void unique(std::vector<T> &v) {
  std::sort(v.begin(), v.end());
  v.erase(std::unique(v.begin(), v.end()), v.end());
}

#line 2 "main.cpp"

long long solve(long long H, long long W, int N, int M, const std::vector<long long> &A,
                const std::vector<long long> &B, const std::vector<long long> &C, const std::vector<long long> &D) {
  vector<vector<int>> grid(H, vector<int>(W, 0));
  vector<vector<bool>> light(H, vector<bool>(W, false));

  REP(i, N) { grid[A[i]][B[i]] = 1; }
  REP(i, M) { grid[C[i]][D[i]] = 2; }

  REP(i, H) {
    // 右方向
    int prev = 0;
    REP(j, W) {
      if (grid[i][j] == 2) {
        prev = 2;
        continue;
      }
      if (grid[i][j] == 1 || prev == 1) {
        prev = 1;
        light[i][j] = true;
      }
    }

    prev = 0;
    for (int j = W - 1; j >= 0; j--) {
      if (grid[i][j] == 2) {
        prev = 2;
        continue;
      }
      if (grid[i][j] == 1 || prev == 1) {
        prev = 1;
        light[i][j] = true;
      }
    }
  }

  REP(j, W) {
    int prev = 0;

    REP(i, H) {
      if (grid[i][j] == 2) {
        prev = 2;
        continue;
      }
      if (grid[i][j] == 1 || prev == 1) {
        prev = 1;
        light[i][j] = true;
      }
    }

    prev = 0;
    for (int i = H - 1; i >= 0; i--) {
      if (grid[i][j] == 2) {
        prev = 2;
        continue;
      }
      if (grid[i][j] == 1 || prev == 1) {
        prev = 1;
        light[i][j] = true;
      }
    }
  }

  int ans = 0;
  REP(i, H) {
    REP(j, W) {
      if (light[i][j]) {
        ans++;
      }
    }
  }
  return ans;
}

// generated by online-judge-template-generator v4.7.1 (https://github.com/online-judge-tools/template-generator)
int main() {
  int H, W;
  int N, M;
  std::cin >> H >> W >> N;
  std::vector<long long> A(N), B(N);
  std::cin >> M;
  std::vector<long long> C(M), D(M);
  for (int i = 0; i < N; ++i) {
    std::cin >> A[i] >> B[i];
    A[i]--;
    B[i]--;
  }
  for (int i = 0; i < M; ++i) {
    std::cin >> C[i] >> D[i];
    C[i]--;
    D[i]--;
  }
  auto ans = solve(H, W, N, M, A, B, C, D);
  std::cout << ans << std::endl;
  return 0;
}


#include <bits/stdc++.h>
// #include <atcoder/all>
// using namespace atcoder;
using namespace std;
using ll = long long; using ull = unsigned long long;
// #define int ll
// #define DEBUG 42
inline void nprint(){}
template <class Head, class... Tail>
inline void nprint(Head &&head, Tail &&... tail) {
    cout << head << endl;
    nprint(move(tail)...);
}
#ifdef DEBUG
  #define eprint(...) nprint(__VA_ARGS__)
#else
  #define eprint(...) if(0==1) cout << 1 << endl;
#endif
#define Yes(a) cout << (a ? "Yes" : "No") << endl
#define YES(a) cout << (a ? "YES" : "NO") << endl
#define POSSIBLE(a) cout << (a ? "POSSIBLE" : "IMPOSSIBLE") << endl
using cmp = complex<double>;
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<V<T>>;
#define fi first
#define se second
template<class T>inline bool maxs(T& x, T y){
  if(x >= y) return false;
  x = y; return true;
}
template<class T>inline bool mins(T& x, T y){
  if(x <= y) return false;
  x = y; return true;
}
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORS(i,a,b) FOR(i,a,b+1)
#define REPS(i,n) REP(i,n+1)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define RREPS(i,n) RREP(i,n+1)
#define RFORS(i,a,b) RFOR(i,a,b+1)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define PERM(c) sort(ALL(c)); for(bool cp = true;cp;cp = next_permutation(ALL(c)))
#define eb(val) emplace_back(val)
inline ll bitcnt(ll val) { return __builtin_popcountll(val); }
const long double PI = std::acos(-1.0l);
constexpr int dx[] = {1,0,-1,0}; constexpr int dy[] = {0,1,0,-1};
template<typename Tail> auto type_vector(Tail&& tail){return tail;}
template<typename Head, typename... Tail> auto type_vector(Head&& head, Tail&&... tail){
  head = 0; return vector<decltype(type_vector(tail...))>(head);
}
template<typename Tail> auto make_vector(Tail&& tail){return tail;}
template<typename Head, typename... Tail> auto make_vector(Head&& head, Tail&&... tail){
  return vector<decltype(type_vector(tail...))>(head, make_vector(tail...));
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p){
  return s << "(" << p.first << ", " << p.second << ")";
}
template<class T> istream& operator>>(istream &is,vector<T> &st){
  for(size_t i=0;i<st.size();++i){is >> st[i];} return is;
}
template<class T> istream& operator>>(istream &is,vector<vector<T>> &st){
  for(size_t i=0;i<st.size();++i){is >> st[i];} return is;
}
template<class T> ostream& operator<<(ostream &os, const vector<T> &st){
  for(size_t i=0;i<st.size();++i) os << st[i] << (i!=st.size()-1?" ":"");
  return os;
}
ostream& operator<<(ostream &os, const vector<string> &st){
  for(size_t i=0;i<st.size();++i) os << st[i] << (i!=st.size()-1?"\n":"");
  return os;
}
template<class T> ostream& operator<<(ostream &os, const vector<vector<T>> &st){
  for(size_t i=0;i<st.size();++i) os << st[i] << (i!=st.size()-1?"\n":"");
  return os;
}
constexpr double EPS = 1e-10;
constexpr ll MOD = 1E9+7;
// constexpr ll MOD = 998244353;
signed main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int n;
  cin >> n;
  vi a(n);
  cin >> a;
  REP(i,n){
    a[i] %= 200;
  }

  map<int, vi> mp;
  int cnt = min(8,n);
  FOR(i,1,1<<cnt){
    vi b;
    int sum = 0;
    REP(j,cnt){
      if(i>>j&1){
        sum += a[j];
        b.eb(j+1);
      }
    }
    sum %= 200;
    if(mp.count(sum)){
      Yes(1);
      cout << mp[sum].size() << " " << mp[sum] << endl;
      cout << b.size() << " " << b << endl;
      return 0;
    }
    mp[sum] = b;
  }

  Yes(0);

}

#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif

int main()
{
	const auto start = steady_clock::now();

	random_device rnd;

	int n, m;
	cin >> n >> m;
	vector<string> ss(m);
	for (auto &&s : ss)
	{
		cin >> s;
	}

	set<string> ts(ss.begin(), ss.end());

	ss = vector<string>(ts.begin(), ts.end());
	m = ss.size();

	vector<string> ans(n, string(n, '.'));
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			ans[i][j] = "ABCDEFGH"[rnd() % 8];
		}
	}

	for (auto &&x : ans)
	{
		cout << x << endl;
	}

	return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T> using vt = vector<T>;
template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb push_back
#define SZ(x) ((int)((x).size()))
#define EACH(x, a) for (auto& x: a)
#define FOR(i,s,n) for (ll i = (s); (i) < (n); ++i)
#define FORD(i,s,l) for (ll i = (s); (i) >= l; --i)
#define F first
#define S second
#define TC int __tc; cin >> __tc; FOR(case_num,1,__tc+1)
#define TEST(x,i) ((x)&(1ll<<(i)))
#define SET(x,i) ((x)|(1ll<<(i)))
#define FLIP(x,i) ((x)^(1ll<<(i)))
#define CLEAR(x,i) ((x)&~(1ll<<(i)))
const double pi = 4 * atan(1);
using ll = long long;
using pll = pair<ll, ll>;

mt19937 mt_rng(chrono::steady_clock::now().time_since_epoch().count());
ll randint(ll a, ll b) {
	return uniform_int_distribution<ll>(a, b)(mt_rng);
}

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

template<class ForwardIterator> void print_vec(ForwardIterator first,
		ForwardIterator last, string sep = " ", string end = "\n") {
	bool ft = true;
	while (first != last) {
		if (!ft) {cout << sep;} else {ft = false;}
		cout << (*first);
		++first;
	}
	cout << end;
}

template<typename T1, typename T2>
std::ostream& operator<<(std::ostream &o, const pair<T1, T2> &p) {
	return o << p.F << " " << p.S;
}

inline ll floorDiv(ll x, ll y) {
	ll d = x / y;
	ll r = x % y;
	return r ? (d - ((x < 0) ^ (y < 0))) : d;
}

ll ceilDiv(ll x, ll y) {
	return -floorDiv(-x, y);
}

ll bin_search(ll lo, ll hi, function<bool(ll)> predicate) {
	int sign = lo < hi ? 1 : -1;
	lo *= sign;
	hi *= sign;
	hi++;
	while (lo < hi) {
		ll mid = lo + floorDiv(hi-lo, 2);
		if (!predicate(sign * mid)) {
			lo = mid + 1;
		} else {
			hi = mid;
		}
	}
	return sign * lo;
}
const ll MOD = 1000000007;
const int MAXN = 200005;

vector<ll> down;
vector<vector<int>> adj;
set<pair<int,int> > usual;
map<pair<int,int>, int > ids;
vector<ll> ans;
ll current = 0;

void dfs(int u, int p) {
	for (auto &v : adj[u]) {
		if (v != p) {
			usual.insert({u,v});
			dfs(v,u);
		}
	}
}

void dfs2(int u, int p) {
	ans[u] = current;
	for (auto &v : adj[u]) {
		if (v != p) {
			int idx = ids[make_pair(u,v)];
			current+=down[idx];
			dfs2(v, u);
			current-=down[idx];
		}
	}
}

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

	int n;
	cin >> n;

	down.assign(n-1,0);
	ans.assign(n,0);

	vector<pair<int,int>> edge;
	adj.assign(n,vector<int>());

	for (int i = 0; i < n-1; i++) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		adj[x].pb(y);
		adj[y].pb(x);
		edge.pb({x,y});
		ids[make_pair(x,y)]=ids[make_pair(y,x)]=i;
	}

	dfs(0,0);

	int q;
	cin >> q;
	while(q--) {
		int t, e;
		ll x;
		cin >> t >> e >> x;
		t--;
		t=1-t;
		e--;
		if (! usual.count(edge[e])) {
			t=1-t;
		}
		if (t) {
			current+=x;
			down[e]+=-x;
		} else {
			down[e]+=x;
		}
	}

	dfs2(0,0);

	print_vec(ans.begin(),ans.end(), "\n");

}

#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
signed main(){
	int n;
	cin>>n;
	vector<pair<int,int>> ed(n-1);
	vector<vector<int>> g(n);
	for(int i=0;i<n-1;i++){
		int u,v;
		cin>>u>>v;
		ed[i]={u-1,v-1};
		g[u-1].push_back(v-1);
		g[v-1].push_back(u-1);
	}
	vector<int> d(n,-1),s(n);
	//dfs using stack
	vector<int> q={0};d[0]=0;
	while(q.size()){
		int u=q.back();
		q.pop_back();
		for(int v:g[u]){
			if(d[v]==-1){
				d[v]=d[u]+1;
				q.push_back(v);
			}
		}
	}
	int Q;cin>>Q;
	while(Q--){
		int t,e,x;cin>>t>>e>>x;
		auto [a,b]=ed[e-1];
		if(d[a]>d[b]){
			swap(a,b);
			if(t==1)t=2;
			else t=1;
		}
		if(t==1){
			s[0]+=x;s[b]-=x;
		}
		else s[b]+=x;
	}

	q={0};
	while(q.size()){
		int u=q.back();
		q.pop_back();
		for(int v:g[u]){
			if(d[u]<d[v]){
				s[v]+=s[u];
				q.push_back(v);
			}
		}
	}

	for(int i:s)cout<<i<<"\n";

}


/* {{{ */
#include <bits/stdc++.h>
using namespace std;
#ifdef __LOCAL
#include <prettyprint.hpp>
#define debug(a) cerr << "[\033[33mDEBUG\033[m] " << (#a) << ": " << (a) << endl
#else
#define debug(s) cerr << "[\033[33mDEBUG\033[m] local only" << endl
#endif
using ll = long long;
template <class T> using vec = vector<T>;
#define endl "\n"
#define INF (int)1e9
#define LINF (long long)1e12
#define MOD (int)1e9+7
#define _rep(i,_a,_b,a,b,...) for (int i=(a), lim##i=(b); i<lim##i; i++)
#define rep(i, ...) _rep(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define _rrep(i,_a,_b,a,b,...) for (int i=(a), lim##i=(b); i>=lim##i; i--)
#define rrep(i, ...) _rrep(i, __VA_ARGS__, __VA_ARGS__, __VA_ARGS__, 0)
#define each(e, c) for (auto &e: c)
#define all(v) begin(v), end(v)
#define popcount __builtin_popcount
template <class T> bool chmin(T& a, const T& b) { return a>b?a=b,true:false; }
template <class T> bool chmax(T& a, const T& b) { return a<b?a=b,true:false; }
void keep_my_fingers_crossed()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}
/* }}} */

int main()
{
  keep_my_fingers_crossed();
  ll n, w;
  cin >> n >> w;
  vec<pair<ll, ll>> a;
  rep(i, n)
  {
    ll s, t, p;
    cin >> s >> t >> p;
    a.push_back({ s, p });
    a.push_back({ t, -p });
  }
  sort(all(a), [&](auto x, auto y){ return x.first < y.first; });

  map<ll, ll> usage;
  ll total = 0;
  for (auto [t, p]: a)
  {
    total += p;
    usage[t] = total;
  }

  for (auto [key, val]: usage)
  {
    if (val > w)
    {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

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

int main(){
    int n, w;
    cin>>n>>w;
    map<int, vector<int>> starts;
    map<int, vector<int>> ends;
    vector<int> ps (n);
    for(int i = 0; i < n; i++){
        int s, t, p;
        cin>>s>>t>>p;
        starts[s].push_back(i);
        ends[t].push_back(i);
        ps[i] = p;
    }
    long long draw = 0;
    bool bad = 0;
    for(int i = 0; i <= 2e5; i++){
        if(starts.count(i)){
            for(int idx : starts[i]){
                draw += ps[idx];
            }
        }
        if(ends.count(i)){
            for(int idx : ends[i]){
                draw -= ps[idx];
            }
        }
        if(draw > w){
            bad = 1;
            break;
        }
    }
    cout<<(bad ? "No" : "Yes")<<endl;
}


/*       In The Name Of ALLAH
                                            */

#include <bits/stdc++.h>  // This will work only for g++ compiler.

#define for0(i, n) for (int i = 0; i < (int)(n); ++i) // 0 based indexing
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i) // 1 based indexing
#define forc(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i) // closed interver from l to r r inclusive
#define forr0(i, n) for (int i = (int)(n) - 1; i >= 0; --i) // reverse 0 based.
#define forr1(i, n) for (int i = (int)(n); i >= 1; --i) // reverse 1 based

//short hand for usual tokens
#define pb push_back
#define fi first
#define se second

// to be used with algorithms that processes a container Eg: find(all(c),42)
#define all(x) (x).begin(), (x).end() //Forward traversal
#define rall(x) (x).rbegin, (x).rend() //reverse traversal

// traversal function to avoid long template definition. Now with C++11 auto alleviates the pain.
#define tr(c,i) for(__typeof__((c)).begin() i = (c).begin(); i != (c).end(); i++)

// find if a given value is present in a container. Container version. Runs in log(n) for set and map
#define present(c,x) ((c).find(x) != (c).end())

//find version works for all containers. This is present in std namespace.
#define cpresent(c,x) (find(all(c),x) != (c).end())

// Avoiding wrap around of size()-1 where size is a unsigned int.
#define sz(a) int((a).size())
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'

using namespace std;

// Shorthand for commonly used types
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef double ld;

int main() {

optimize();
        ll n,k;
        cin>>n>>k;
        ll op=0;
        while(n&&op!=k)
        {
            ll z=n;
            vi v;
            while(z)
            {
                int rem=z%10;
                v.pb(rem);
                z/=10;
            }
            sort(all(v));
            ll ans1=0;
            for(int i=0;i<v.size();i++)
            {
                ans1=(ans1*10)+v[i];
            }
            ll ans2=0;
            for(int i=v.size()-1;i>=0;i--)
            {
                ans2=(ans2*10)+v[i];
            }
            n=ans2-ans1;
            ++op;
        }
        cout<<n<<endl;
    return 0;
}

 //----AUTHOR:kkdrummer----/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace __gnu_pbds;
using namespace std;
typedef    long long                	 ll;
typedef    double              	 ld;
typedef    unordered_set<ll>         	 usll;
typedef    unordered_multiset<ll>    	 umsll;
typedef    multiset<ll>              	 msll;
typedef    set<ll>                  	 sll;
typedef    vector<ll>               	 vll;
typedef    pair<ll,ll>              	 pll;
typedef    vector<pll>              	 vpll;
typedef    priority_queue<ll>       	 pqll;
typedef    vector<int>              	 vi;
typedef    set<int>                 	 si;
typedef    multiset<int>            	 msi;
typedef    unordered_multiset<int>  	 umsi;
typedef    unordered_set<int>       	 usi;
typedef    pair<int,int>               	 pi;
typedef    vector<pi>                	 vpi;
typedef    priority_queue<int>       	 pqi;
typedef    tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>   ind_si;
typedef    tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>   ind_sll;
typedef    tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>   ind_msi;
typedef    tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>   ind_msll;
#define    in          		insert
#define    fi          		first
#define    se          		second
#define    pb   	    	push_back
#define    mp   	   		make_pair
#define    be   	   		begin
#define    en   	   		end
#define    itr  	   		iterator
#define    io  	       		ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define    mo   	   		1000000007
#define    inf  	   		8222372026854775807
#define    ninf   	   		-inf
#define    ima   	   		2047483647
#define    imi   	   		-ima
#define    oncnt       		__builtin_popcount
#define    zerobegin   		__builtin_clz
#define    zeroend    		__builtin_ctz
#define    parity      		__builtin_parity
#define    eps         		1e-9
#define    coutd       		cout<<setprecision(10)<<fixed
#define    mems(dp,x)  		memset(dp,x,sizeof(dp))
#define    fbo         		find_by_order
#define    ook    	   		order_of_key
#define    all(x)      		x.be(),x.en()
#define    upb    	   		upper_bound
#define    lowb  	   		lower_bound
#define    lte(v,x)    		(upb(all(v),x)-v.be())
#define    gte(v,x)    		(v.end()-lowb(all(v),x))
#define    gt(v,x)     		(v.en()-upb(all(v),x))
#define    lt(v,x)     		(lowb(all(v),x)-v.be())
const      ld PI= 			3.1415926535897932384626433832792884197169399375105820974944;
inline ll mpow(ll x,ll n){if(n==0)return 1;if(x==0)return 0;if(n==1)return(x%mo);ll u=(mpow(x,n/2));u=(u*u)%mo;if(n%2!=0)u=(u*x%mo)%mo;return u;}
inline ll minv(ll x){return mpow(x,mo-2);}
inline ll mmul(ll a,ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll madd(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a+b>=mo)return(a+b)%mo;return(a+b);}
inline ll msub(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;return(((a-b)%mo+mo)%mo);}
inline ll mdiv(ll a,ll bb){if(a>=mo)a=a%mo;ll b=minv(bb);if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll gcd(ll a,ll b){return __gcd(a,b);}
inline ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}

int main()
{              io
int testcases=1;         //          cin>>testcases;
while(testcases--)
{

int a,b;
cin>>a>>b;
int c=a+b;
if(c>=15&&b>=8)cout<<1;
else if(c>=10&&b>=3)cout<<2;
else if(c>=3)cout<<3;
else cout<<4;

}return 0;}


#pragma GCC optimize("Ofast")
//#ifndef ONLINE_JUDGE
//#define _GLIBCXX_DEBUG
//#endif
#ifdef ONLINE_JUDGE
#include <atcoder/all>
#endif
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#include <math.h>
#include <complex>

using namespace std;
#ifdef ONLINE_JUDGE
using namespace atcoder;
#endif
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
#ifdef ONLINE_JUDGE
//using mint = modint998244353;
//using mint = modint;
using mint = modint1000000007;
#endif
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);
int dx[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
int dy[9] = {0, 1, 0, -1, 1, -1, -1, 1, 0};

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  //cout << fixed << setprecision(15);

  ll R,C; cin>>R>>C;
  vector<vector<ll>> A(R,vector<ll>(C-1)),B(R-1,vector<ll>(C));
  rep(i,R) rep(j,C-1) cin>>A[i][j];
  rep(i,R-1) rep(j,C) cin>>B[i][j];

  vector<vector<pair<ll,ll>>> graph(2*R*C,vector<pair<ll,ll>>(0));
  auto f=[&](int i,int j,int k) {return i*C+j+k*R*C;};

  rep(r,R) rep(c,C-1) graph[f(r,c,0)].push_back({f(r,c+1,0),A[r][c]});
  rep(r,R) for(int c=1;c<C;c++) graph[f(r,c,0)].push_back({f(r,c-1,0),A[r][c-1]});
  rep(r,R-1) rep(c,C) graph[f(r,c,0)].push_back({f(r+1,c,0),B[r][c]});
  for(int r=1;r<R;r++) rep(c,C) {
    graph[f(r,c,0)].push_back({f(r,c,1),1});
    graph[f(r,c,1)].push_back({f(r-1,c,1),1});
    graph[f(r-1,c,1)].push_back({f(r-1,c,0),0});
  }

  vector<ll> dist(2*R*C,INF);
  priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>> pq;
  pq.push({0,0});
  while(!pq.empty()) {
    auto [c,v]=pq.top(); pq.pop();
    if(!chmin(dist[v],c)) continue;
    if(v==f(R-1,C-1,0)) break;

    for(auto &[nv,nc]:graph[v]) {
      pq.push({c+nc,nv});
    }
  }

  cout<<dist[f(R-1,C-1,0)]<<'\n';

  return 0;
}

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define vvi            vector<vi>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define tr(c,i)        for(auto i = (c).begin(); i != (c).end(); i++)
#define present(c,x)    ((c).find(x) != (c).end())
#define cpresent(c,x)    (find(all(c),x) != (c).end())
using namespace std;
ll mod=1e9+7;
#define N  100005

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int TESTS=1;
    //cin>>TESTS;
    //ll cs=1;
    while(TESTS--)
    {
        char s,t; cin >> s >> t;
        if(s=='Y') cout << (char)toupper(t) << "\n";
        else cout << t << "\n";
    }
    return 0;
}


#include "bits/stdc++.h"
#include<sstream>
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1e9;
const long long inf = 1e18;
const ll INFL = 1e18;
const ll MOD = 1e9 + 7;

int digit(ll x) {
    int digits = 0;

    while(x > 0){
        x /= 10;
        digits++;
    }

    return digits;
}

ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;

    return gcd(b,a%b);
}

bool is_prime(long long N){
    if (N == 1) return false;
    for (long long i = 2;i * i <= N;i++){
        if (N % i == 0) return false;
    }
    return true;
}

ll lcm(ll a,ll b){
    return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}

double DegreeToRadian(double degree){
    return degree * M_PI / 180.0;
}

long long modpow(long long a, long long b, long long m){
    long long ans = 1;
    while(b > 0){
        if (b % 2 == 1){
            ans *= a;
            ans %= m;
        }
        a *= a;
        a %= m;
        b /= 2;
    }
    return ans;
}

long long comb(long long x, long long y){
    int z;
    if (y == 0) return 1;
    else {
        z = modpow(x, y/2, MOD)*modpow(x, y/2, MOD)%MOD;
        if (y % 2 == 1) z = z*x%MOD;
        return z;
    }
}

vector<pair<long long, long long>> prime_fact(long long x){
    vector<pair<long long, long long>> res;
    for(int i = 2;i*i <= x;i++){
        if (x % i == 0){
            long long cnt = 0;
            while(x % i == 0){
                cnt++;
                x /= i;
            }
            res.push_back({i, cnt});
        }
    }
    if (x != 1){
        res.push_back({x, 1});
    }
    return res;
}

int64_t mod_inv(int64_t a, int64_t m){
    int64_t b = m, u = 1, v = 0;

    while(b){
        int64_t t = a/b;
        a -= t*b;
        swap(a, b);
        u -= t*v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;

    return u;
}

// {g, x, y}: ax + by = g
tuple<long long, long long, long long> extgcd(long long a, long long b){
    if (b == 0) return {a, 1, 0};
    long long g, x, y;
    tie(g, x, y) = extgcd(b, a % b);
    return {g, y, x - a/b*y};
}

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

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

int main(){
    long long N, C;
    cin >> N >> C;
    vector<pair<long long, long long>> p;
    for(int i = 0;i < N;i++){
        long long a, b, c;
        cin >> a >> b >> c;
        p.push_back({a - 1, c});
        p.push_back({b, -c});
    }
    sort(p.begin(), p.end());
    long long ans = 0, cost = 0, t = 0;
    for(auto [x, y] : p){
        if (t != x){
            ans += min(C, cost)*(x - t);
            t = x;
        }
        cost += y;
    }

    cout << ans << endl;

}

#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define Pii pair<int,int>
#define Pll pair<long long,long long>
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
//vector<vector<ll>> dp(n,vector<ll>(n))
//2-dim:vector<vector<Type>> vv(n, vector<Type>(m, d));
//3-dim:vector<vector<vector<Type>>> vvv(n, vector<vector<Type>>(m, vector<Type>(l, d)));

using namespace std;

signed main(){
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    int n; cin >> n;
    ll x; cin >> x;
    map<ll,ll> mp;
    vector<Pll> v;
    rep(i,n){
        int a,b; cin >> a >> b;
        ll c; cin >> c;
        mp[a]+=c;
        mp[b+1]-=c;
        v.pb({a,c});
        v.pb({b+1,-c});
    }
    sort(ALL(v));
    ll now = 1;
    ll ans = 0;
    ll kane = 0;
    for(auto itr=mp.begin();itr!=mp.end();itr++){
        ll d = itr->fi;
        ans += (d-now)*min(x,kane);

        kane += itr->se;
        now = d;
    }
    cout << ans << endl;
    return 0;
}
// g++ main.cpp -o a.out && ./a.out


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

#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define fr(i,k,n) for (int i = k; i < n; ++i)
#define fri(i,k,n) for (int i = k; i >= n; --i)
#define pb push_back
#define mp make_pair
#define all(arr) arr.begin(),arr.end()
#define ff first
#define ss second

const double pi=3.1415926535897932384626433832795;
const int inf=1e9;
const ll inf2=1e18;
const int mod=1e9+7;

void boost(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

int n;
vector<vi> a;

bool check(int val){
    vector<bool> mark(32,false),mark2(32,false);
    set<int> ss;
    int num,num2;
    fr(i,0,n){
        num=num2=0;
        fr(j,0,5){
            if(a[i][j]>=val)
                num|=(1<<j);
            else
                num2|=(1<<j);
        }
        if(mark[num2]){
            return true;
        }
        for(auto x: ss){
            num2=x|num;
            if(mark2[num2])
                continue;
            mark2[num2]=true;
            for(int j=num2;;j=(j-1)&num2){
                mark[num2&j]=true;
                if(j==0)
                    break;
            }
        }
        ss.insert(num);
    }
    return false;
}

void solve(){
    cin>>n;
    a=vector<vi>(n,vi(5,0));
    vi diff;
    fr(i,0,n){
        fr(j,0,5){
            cin>>a[i][j];
            diff.pb(a[i][j]);
        }
    }
    sort(all(diff));
    diff.erase(unique(all(diff)),diff.end());
    int l=0,r=int(diff.size())-1,m;
    int ans=0;
    while(l<=r){
        m=(l+r)/2;
        if(check(diff[m])){
            ans=diff[m];
            l=m+1;
        }
        else{
            r=m-1;
        }
    }
    cout<<ans<<endl;
    return;
}

int main()
{
    boost();

    int tc=1;
    //cin>>tc;
    while(tc--)
        solve();
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
#define sz(a) ll(a.size())
void test2311(){
    string s;
    cin>>s;
    reverse(s.begin(),s.end());
    for(ll i=0;i<sz(s);i++)
        if(s[i]=='6')
            s[i]='9';
        else if(s[i]=='9')
            s[i]='6';
    cout<<s;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    clock_t z=clock();
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ll qc=1;
    //cin>>qc;
    for(ll i=1;i<=qc;i++){
        test2311();
    }
    debug("Total Time:%.4Lf\n",(ld)(clock()-z)/CLOCKS_PER_SEC);
}


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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cerr << #a << " = " << a << endl;

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}

const double PI = acos(-1.0);
const int INF = 1e9 + 47;
const LL LINF = 1LL * INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int bad[1<< 18];
double K[1 << 18], B[1 << 18];

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n, m, k;
	cin >> n >> m >> k;
	FOR(i, 0, k)
	{
		int x;
		cin >> x;
		bad[x] = 1;
	}
	int cnt = 0;
	FOR(i, 0, n + 1)
	{
		if(bad[i])
			cnt++;
		else
		{
			if(cnt >= m)
			{
				cout << "-1" << endl;
				return 0;
			}
			cnt = 0;
		}
	}
	FOR(i, 0, m)
	{
		K[n + i] = 0;
		B[n + i] = 0;
	}
	double M = m;
	double sumK = 0, sumB = 0;
	RFOR(i, n, 0)
	{
		if(bad[i])
		{
			K[i] = 1;
			B[i] = 0;
		}
		else
		{
			K[i] = sumK / M;
			B[i] = 1 + (sumB / M);
		}
		sumK += K[i] - K[i + m];
		sumB += B[i] - B[i + m];
		//cout << K[i] << " " << B[i] << endl;
	}
	cout << fixed << setprecision(8) << B[0] / (1.0 - K[0]) << endl;
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}

#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>

using namespace std;

int main(){
    string str;
    cin >> str;
    long nLen = str.length();
    long m;
    cin >> m;
    if(nLen == 1){
        long nAns = long(str[0] - '0');
        if(nAns <= m){
            cout << "1" << endl;
        } else {
            cout << "0" << endl;
        }
        return 0;
    }

    long d = 0;
    vector<long> viNum(nLen);
    for(long i = 0; i < nLen; i++){
        viNum[i] = long(str[i]-'0');
        d = max(d, viNum[i]+1);
    }

    long iOK = 0, iNG = m+1;
    while(iNG - iOK > 1){
        long iThis = (iNG + iOK)/2;
        long nSum = viNum[0];
        bool b = true;
        for(long i = 1; i < nLen; i++){
            if(m / iThis < nSum){
                b = false;
                break;
            }
            nSum *= iThis;
            nSum += viNum[i];
        }
        if(b && nSum <= m){
            iOK = iThis;
        } else {
            iNG = iThis;
        }
    }

    cout << max(iOK-d+1, 0L) << endl;

    return 0;
}


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

#define Int register int
#define mod 998244353
#define MAXN 105

template <typename T> void read (T &x){char c = getchar ();x = 0;int f = 1;while (c < '0' || c > '9') f = (c == '-' ? -1 : 1),c = getchar ();while (c >= '0' && c <= '9') x = x * 10 + c - '0',c = getchar ();x *= f;}
template <typename T,typename ... Args> void read (T &x,Args& ... args){read (x),read (args...);}
template <typename T> void write (T x){if (x < 0) x = -x,putchar ('-');if (x > 9) write (x / 10);putchar (x % 10 + '0');}
template <typename T> void chkmax (T &a,T b){a = max (a,b);}
template <typename T> void chkmin (T &a,T b){a = min (a,b);}

int mul (int a,int b){return 1ll * a * b % mod;}
int dec (int a,int b){return a >= b ? a - b : a + mod - b;}
int add (int a,int b){return a + b >= mod ? a + b - mod : a + b;}
void Add (int &a,int b){a = add (a,b);}

int n,W[MAXN],fac[MAXN],f[MAXN][MAXN][MAXN * MAXN / 2];

signed main(){
	read (n);int up = 0;
	for (Int i = 1;i <= n;++ i) read (W[i]),up += W[i];
	if (up & 1) return puts ("0") & 0;
	f[0][0][0] = fac[0] = 1,up >>= 1;
	for (Int i = 1;i <= n;++ i) fac[i] = mul (fac[i - 1],i);
	for (Int i = 0;i < n;++ i)
		for (Int s = 0;s <= i;++ s)
			for (Int w = 0;w <= up;++ w){
				Add (f[i + 1][s][w],f[i][s][w]);
				if (w + W[i + 1] <= up) Add (f[i + 1][s + 1][w + W[i + 1]],f[i][s][w]);
			}
	int ans = 0;
	for (Int i = 0;i <= n;++ i) ans = add (ans,mul (mul (fac[i],fac[n - i]),f[n][i][up]));
	write (ans),putchar ('\n');
	return 0;
}

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

#ifdef Dragon
#include"debug.cpp"
#else
#define                         deb //
#define                         pr  //
#endif

#define int               		long long
#define lld               		long double
#define pb                		push_back
#define vi                		vector<int>
#define si(x)             		(int)(x.size())
#define all(c)            		(c).begin(), (c).end()
#define uniq(x)           		(x).erase(unique(all(x)),(x).end())
#define pii               		pair<int,int>
#define ss                		second
#define ff                		first
#define FOR(x,a)          		for(auto&x :a)
#define rep(i,a,b)        		for(int i=a;i<b;i++)
#define repd(i,a,b)             for(int i=a;i>=b;i--)
#define pnr(a)                  FOR(i,a){cout<<i<<" ";}cout<<"\n";

#define endl '\n'
const long long inf = 1e18;
const int32_t mod = 1000000007;

const int N = 3e5 + 5;

int solve() {

	int a , b , k;
	cin >> a >> b >> k;
	int bb = b;
	int aa = a;
	vector<int> v(bb , 0);
	k--;

	rep(i , 0 , bb) {

		int cnt = 0;
		int cur = 1;
		int sum = 1;
		int moved = 0;

		while (k >= sum) {
			if (moved == a)
				break;
			moved++;

			cur *= (b + cnt);
			cur /= (cnt + 1);

			if (cur + sum > k)
				break;
			sum += cur;
			cnt++;
		}
		// deb(sum);
		a = moved;
		// deb(moved);
		v[i] = moved;
		k -= sum;
		b--;
	}
	// pnr(v);
	vector<int> ans( (aa + bb) , 0);
	int cnt = 0;
	rep(i , 0 , bb) {
		ans[aa - v[i] + cnt] = 1;
		cnt++;
	}
	// pnr(ans);
	FOR(i , ans) {
		cout << char('a' + i) << "";
	}
	cout << endl;

	return 0;

}

signed main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	// cout << fixed << setprecision(20);
#ifdef Dragon
	freopen("in.txt", "r", stdin);
	auto start1 = chrono::high_resolution_clock::now();
	//freopen("out.txt","w",stdout);
#endif

	int tests = 1;
	//cin>>tests;
	for (int i = 1 ; i <= tests ; i++) {
		solve();
	}

	return 0 ;
}


//*******Abhijit Burman***********//
//Jalpaiguri Government Engineering College//

// Taken From Striver_79
// Never open a ranklist untill and unless you are done with solving problems, wastes 3/4 minuts
// Donot treat CP as a placement thing, love it and enjoy it, you will succeed for sure.

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define ff first
#define ss second
#define mk make_pair
#define MAXX (1000000000000000000+7)
#define mod 1000000007
#define endl "\n"
#define PI 3.14159265358979323846
#define all(x) (x).begin(),(x).end()
#define fio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
void printv(vector<ll> v) { ll sz = v.size(); for(ll i=0;i<sz;i++) {if (i == sz - 1) cout << v[i] << "\n"; else cout << v[i] << " ";}}
void input(ll a[], ll sz) {for(ll i=0;i<sz;i++) cin >> a[i];}
void print(ll a[], ll sz) {for(ll i=0;i<sz;i++) {if (i == sz - 1) cout << a[i] << "\n"; else cout << a[i] << " ";}}
ll dx1[] = {1, 1, 0, -1, -1, -1, 0, 1};
ll dy1[] = {0, 1, 1, 1, 0, -1, -1, -1};

ll dx2[] = {1, 0, -1, 0};
ll dy2[] = {0, 1, 0, -1};

ll mul(ll a, ll b, ll p = mod) {return ((a % p) * (b % p)) % p;}
ll add(ll a, ll b, ll p = mod) {return (a % p + b % p) % p;}
ll power(ll x,ll y,ll p = mod)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}
ll modInverse(ll n, ll p = mod)
{
    return power(n, p - 2, p);
}
ll ncrMod(ll n, ll r, ll p = mod)
{
    if (r == 0)
        return 1;
    ll fac[n + 1];
    fac[0] = 1;
    for (ll i = 1 ; i <= n; i++)
        fac[i] = fac[i - 1] * i % p;
    return (fac[n] * modInverse(fac[r], p) % p *
            modInverse(fac[n - r], p) % p) % p;
}
// a+b=xor(a,b)+2*(a&b)//
ll convert(string num){
    ll sum=0;
    for(int i=0;i<num.size();i++){
        sum=sum*10;
        sum+=(num[i]-'0');
    }
    return sum;
}
bool ispeed2ime(ll n){
    for(int i=2;i*i<=n;i++){
        if(n%i==0){
            return false;
        }
    }
    return true;
}
bool isPowerof2(ll n){
    while(n>1){
        if(n%2!=0){
            return true;
        }
        n/=2;
    }
    return false;
}

void solve()
{
    ll n;
    cin>>n;
    ll a[n];
    input(a,n);
    ll ans=INT_MIN;
    for(int i=0;i<n;i++){
        ll mini = a[i];
        for(int j=i;j<n;j++){
            mini = min(mini,a[j]);
            ans = max(ans,mini*(j-i+1));
        }
    }
    cout<<ans<<endl;
}

int main()
{
	fio;
// 	#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

	ll t=1;
// 	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <complex>

using namespace std;

//#pragma GCC optimize("Ofast")
//#pragma GCC optimization("unroll-loops, no-stack-protector")
//#pragma GCC target("avx,avx2,fma")

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

	int n, m, i, j, k, c;
	string s;

	cin >> n >> s;
	vector<int> a(n + 1);

	m = 1E9;
	for (i = 0; i <= n; i++) {
		cin >> a[i];
		if (i > 0) m = min(m, abs(a[i] - a[i - 1]));
	}

	cout << m << "\n";
	for (i = 0; i < m; i++) {
		for (j = 0; j <= n; j++) cout << (a[j] + i) / m << " ";
		cout << "\n";
	}

	return 0;
}


#include <bits/stdc++.h>

// 1. dp
typedef long double ld;
#define int long long

#define gcd            __gcd
#define endl           "\n"
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define pb             push_back
#define all(x)         x.begin(), x.end()
#define f              first
#define s              second
#define lb             lower_bound
#define ub             upper_bound
#define ins            insert
#define sz(x)          (int)(x).size()
#define mk             make_pair
#define deci(x, y)     fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define nitin          ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define PI             3.141592653589793238
using namespace std;

void solve() {
    int s,p;
    cin>>s>>p;
    bool flag=false;
    for(int i=1;i*i<=p;i++)
    {
        if(p%i==0)
        {
            int j=p/i;
            if(i+j==s)
                flag=true;
        }
    }
    if(flag)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}

int32_t main() {
    nitin;

    solve();
}

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
int main() {
  long long s,p;
  cin>>s>>p;
  string ans="No";
  for(ll i=1;i<=1000000;i++){
    if(p%i==0){
      ll x=p/i;
      if(x+i==s)
        ans="Yes";
    }
  }
  cout<<ans<<endl;
}


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

int main() {
	int n; cin >> n;
	string s, t; cin >> s >> t;
	vector<int> a, b;
	REP(i, n) {
		if (s[i] == '0') a.push_back(i);
		if (t[i] == '0') b.push_back(i);
	}
	int res = 0;
	if ((int)a.size() != (int)b.size())
		res = -1;
	else
		REP(i, (int)a.size())
			if (a[i] != b[i])
				res++;
	cout << res << '\n';
    return 0;
}

#line 2 "/Users/kaage/Desktop/ProgrammingWorkspace/library/other/template.hpp"
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx2")
#pragma optimize("O3")
#pragma optimize("unroll-loops")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define all(V) V.begin(),V.end()
typedef unsigned int uint;
typedef long long lint;
typedef unsigned long long ulint;
typedef std::pair<int, int> P;
typedef std::pair<lint, lint> LP;
constexpr int INF = INT_MAX/2;
constexpr lint LINF = LLONG_MAX/2;
constexpr double eps = DBL_EPSILON;
constexpr double PI=3.141592653589793238462643383279;
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
inline lint gcd(lint a, lint b) {
	while (b) {
		lint c = a;
		a = b; b = c % b;
	}
	return a;
}
inline lint lcm(lint a, lint b) {
	return a / gcd(a, b) * b;
}
bool isprime(lint n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
template<typename T>
T mypow(T a, lint b) {
	T res(1);
	while(b){
		if(b&1)res*=a;
		a*=a;
		b>>=1;
	}
	return res;
}
lint modpow(lint a, lint b, lint m) {
	lint res(1);
	while(b){
		if(b&1){
			res*=a;res%=m;
		}
		a*=a;a%=m;
		b>>=1;
	}
	return res;
}
template<typename T>
void printArray(std::vector<T>& vec) {
	rep(i, vec.size()){
		std::cout << vec[i];
		std::cout<<(i==(int)vec.size()-1?"\n":" ");
	}
}
template<typename T>
void printArray(T l, T r) {
	T rprev = std::prev(r);
	for (T i = l; i != rprev; i++) {
		std::cout << *i << " ";
	}
	std::cout << *rprev << std::endl;
}
LP extGcd(lint a,lint b) {
	if(b==0)return {1,0};
	LP s=extGcd(b,a%b);
	std::swap(s.first,s.second);
	s.second-=a/b*s.first;
	return s;
}
LP ChineseRem(const lint& b1,const lint& m1,const lint& b2,const lint& m2) {
	lint p=extGcd(m1,m2).first;
	lint tmp=(b2-b1)*p%m2;
	lint r=(b1+m1*tmp+m1*m2)%(m1*m2);
	return std::make_pair(r,m1*m2);
}
template<typename F>
inline constexpr decltype(auto) lambda_fix(F&& f){
	return [f=std::forward<F>(f)](auto&&... args){
		return f(f,std::forward<decltype(args)>(args)...);
	};
}
#line 2 "main.cpp"
int N,M;
std::vector<P> e[100010];
std::vector<int> vec[100010];
int par[100010],parc[100010],ans[100010];
bool used[100010];
int main(){
	std::cin>>N>>M;
	rep(i,M){
		int u,v,c;
		std::cin>>u>>v>>c;
		e[u].emplace_back(v,c);
		e[v].emplace_back(u,c);
	}
	lambda_fix([&](auto self, int node)->void{
		used[node]=true;
		for(auto i:e[node]){
			if(!used[i.first]){
				self(self,i.first);
				vec[node].emplace_back(i.first);
				par[i.first]=node;
				parc[i.first]=i.second;
			}
		}
	})(1);
	lambda_fix([&](auto self,int node)->void{
		if(node==1)ans[node]=1;
		else{
			if(ans[par[node]]==parc[node]){
				if(parc[node]!=1)ans[node]=1;
				else ans[node]=2;
			}
			else ans[node]=parc[node];
		}
		for(auto i:vec[node]){
			self(self,i);
		}
	})(1);
	REP(i,N)std::cout<<ans[i]<<std::endl;
	return 0;
}


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

#define pb push_back
#define mp make_pair
#define fr first
#define sc second

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

int n;
vector <char> s;
vector <char> temp;
vector <int> pre;

int pt;

int main() {
	for(int j=1;j<=1200000;j*=3)
	{
		pre.pb(j);
	}

	pt=pre.size()-1;

	scanf("%d ",&n);

	for(int i=0;i<n;i++)
	{
		s.pb(0);
		scanf("%c",&s[i]);
	}

	while(n>1)
	{
		while(n<pre[pt]+1)
		{
			pt--;
		}

		for(int i=0;i+pre[pt]<n;i++)
		{
			if(s[i]!=s[pre[pt]+i])
			{
				temp.pb('W'+'B'+'R'-s[i]-s[pre[pt]+i]);
			}

			else
			{
				temp.pb(s[i]);
			}
		}

		s=temp;
		temp.clear();
		n=s.size();
	}

	printf("%c",s[0]);

	return 0;
}

#include <iostream>
#include<iomanip>
#include <string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#define INF long long int(1e18+1)
#define rep(i,n,m) for(int i=n;i<m;i++)

using namespace std;

int main()
{
	int n, m, k;
	cin >> n >> m >> k;
	long int total = 0;
	rep(i, 0, n - 1) {
		int x;
		cin >> x;
		total += x;
	}
	int ans;
	ans = k * n - total;
	if (ans < 0)cout << 0;
	else if (ans > m)cout << -1;
	else cout << ans;
}


#ifdef MY_LOCAL
#define MY_NAMESPACE(ns) namespace ns {
#define MY_NAMESPACE_    }
#define MY_DEBUG(s)      s
#define MY_IS_DEBUG      (true)
#else
#define MY_NAMESPACE(ns)
#define MY_NAMESPACE_
#define MY_DEBUG(s)
#define MY_IS_DEBUG      (false)
#endif

#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

#define EPS (1e-7)
#define PI (acos(-1))

constexpr int IMIN = numeric_limits<int>::min();
constexpr int IMAX = numeric_limits<int>::max();
constexpr ll LLMIN = numeric_limits<ll>::min();
constexpr ll LLMAX = numeric_limits<ll>::max();

MY_NAMESPACE(testbed)
int main()
{
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

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

	vector<pll> item(n);
	for (int i = 0; i < n; i++)
	{
		ll w, v;
		cin >> w >> v;
		item.push_back({ w, v });
	}
	vector<ll> boxes(m);
	for (int i = 0; i < m; i++)
	{
		cin >> boxes[i];
	}

	auto sort_fn = [](pll const& lhs, pll const& rhs)->bool
	{
		return lhs.second > rhs.second;
	};
	sort(item.begin(), item.end(), sort_fn);

	for (int i = 0; i < q; i++)
	{
		int l, r;
		cin >> l >> r;
		l--;
		r--;
		vector<ll> this_boxes = boxes;
		this_boxes.erase(this_boxes.begin() + l, this_boxes.begin() + r + 1);

		auto sort_fn2 = [](ll const& lhs, ll const& rhs)->bool
		{
			return lhs < rhs;
		};
		sort(this_boxes.begin(), this_boxes.end(), sort_fn2);

		ll ans = 0;
		for (int j = 0; j < n; j++)
		{
			auto it = lower_bound(this_boxes.begin(), this_boxes.end(), item[j].first);
			if (it != this_boxes.end())
			{
				ans += item[j].second;
				this_boxes.erase(it);
			}
		}
		cout << ans << "\n";
	}

	return 0;
}
MY_NAMESPACE_

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <queue>
#include <numeric>
using namespace std;

using ll = long long;

#define For(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFor(i,a,b) for(ll i=(a);i>=(ll)(b);i--)
#define co(a) cout<<a<<endl
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
#define cfs(a) cout<<fixed<<setprecision(a)

int main() {
	ll N, M, Q;
	cin >> N >> M >> Q;
	ll W, V;
	vector<pair<ll,ll>> vw(N);
	For(i, 0, N) {
		cin >> W >> V;
		vw[i].first = V;
		vw[i].second = W;
	}
	vector<pair<ll,ll>> X(M);
	For(i, 0, M) {
		cin >> X[i].first;
		X[i].second = i;
	}
	SORT(vw);
	REV(vw);
	SORT(X);
	vector<bool> used(M);
	ll start, end;
	ll ans;
	For(i, 0, Q) {
		ans = 0;
		cin >> start >> end;
		For(j, 0, start - 1) {
			used[j] = true;
		}
		For(j, start - 1, end) {
			used[j] = false;
		}
		For(j, end, M) {
			used[j] = true;
		}
		For(j, 0, N) {
			For(k, 0, M) {
				if (used[X[k].second]) {
					if (vw[j].second <= X[k].first) {
						ans += vw[j].first;
						used[X[k].second] = false;
						break;
					}
				}
			}
		}
		co(ans);
	}
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define gc getchar() //(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define IT iterator
#define V vector
#define TP template <class o>
#define TPP template <typename t1, typename t2>
#define SZ(a) ((int)a.size())
#define all(a) a.begin(), a.end()
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define REP(i, a, b) for (int i = b; i >= a; i--)
#define FOR(i, n) rep(i, 1, n)
#define debug(x) cerr << #x << ' ' << '=' << ' ' << x << endl
using namespace std;
typedef double db;
typedef unsigned ui;
typedef long long ll;
typedef long double ld;

// char buf[1 << 20],*p1=buf,*p2=buf;
TP void qr(o& x) {
    char c = gc;
    x = 0;
    int f = 1;
    while (!isdigit(c)) {
        if (c == '-')
            f = -1;
        c = gc;
    }
    while (isdigit(c))
        x = x * 10 + c - '0', c = gc;
    x *= f;
}
template <class o, class... O> void qr(o& x, O&... y) { qr(x), qr(y...); }
TP void qw(o x) {
    if (x < 0)
        putchar('-'), x = -x;
    if (x / 10)
        qw(x / 10);
    putchar(x % 10 + '0');
}
TP void pr1(o x) { qw(x), putchar(' '); }
template <class o, class... O> void pr1(o x, O... y) { pr1(x), pr1(y...); }
TP void pr2(o x) { qw(x), putchar(10); }
template <class o, class... O> void pr2(o x, O... y) { pr2(x), pr2(y...); }
TP bool cmax(o& x, o y) { return (x < y ? x = y, 1 : 0); }
TP bool cmin(o& x, o y) { return (x > y ? x = y, 1 : 0); }

const int mod = (int)1e9 + 7;
TPP void ad(t1& x, t2 y) { (x += y) >= mod && (x -= mod); }
TPP void dl(t1& x, t2 y) { (x -= y) < 0 && (x += mod); }

ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll power(ll a, ll b = mod - 2, ll p = mod) {
    ll c = 1;
    while (b) {
        if (b & 1)
            c = c * a % p;
        b /= 2;
        a = a * a % p;
    }
    return c;
}
ll exgcd(ll a, ll b, ll& x, ll& y) {
    if (!a) {
        x = 0;
        y = 1;
        return b;
    }
    ll d = exgcd(b % a, a, y, x);
    x -= b / a * y;
    return d;
}
ll INV(ll n, ll p = mod) {
    ll x, y;
    exgcd(n, p, x, y);
    return (x % p + p) % p;
}

const int N = 110;
const ll INF = 1e15;
int n, m, k, val[N];

struct rec {
    int a[N][N];
    rec() { memset(a, 0, sizeof a); }
    rec operator*(rec b) const {
        rec c;
        FOR(i, n) FOR(j, n) FOR(k, n) ad(c.a[i][k], 1ll * a[i][j] * b.a[j][k] % mod);
        return c;
    }
} a, c;

void solve() {
    qr(n, m, k);
    FOR(i, n) a.a[i][i] = c.a[i][i] = 1, qr(val[i]);
    ll inv = power(2 * m);
    while (m--) {
        int x, y;
        qr(x, y);
        dl(a.a[x][x], inv);
        ad(a.a[x][y], inv);
        dl(a.a[y][y], inv);
        ad(a.a[y][x], inv);
    }
    while (k) {
        if (k & 1)
            c = c * a;
        k /= 2;
        a = a * a;
    }
    FOR(i, n) {
        ll ans = 0;
        FOR(j, n) ad(ans, 1ll * c.a[j][i] * val[j] % mod);
        pr2(ans);
    }
}

int main() {
#ifndef ONLINE_JUDGE
    clock_t start_time = clock();
#endif
    int T = 1;
    // qr(T);
    while (T--)
        solve();
#ifndef ONLINE_JUDGE
    cerr << 1.0 * (clock() - start_time) / CLOCKS_PER_SEC << ' ' << 's' << endl;
#endif
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int res=0;
	bool zf=0;
	char c;
	while(((c=getchar())<'0'||c>'9')&&c!='-');
	if(c=='-')zf=1;
	else res=c-'0';
	while((c=getchar())>='0'&&c<='9')res=(res<<3)+(res<<1)+c-'0';
	if(zf)return -res;
	return res;
}
const int P=1e9+7;
inline int ksm(int x,int y=P-2){
	int res=1;
	while(y){
		if(y&1){
			res=1ll*res*x%P;
		}
		x=1ll*x*x%P;
		y>>=1;
	}
	return res;
}
int a[105],f[105][105],res[105][105],tmp[105][105];
inline void calc(int a[][105],int b[][105],int n){
	for(register int i=1;i<=n;++i){
		for(register int j=1;j<=n;++j){
			tmp[i][j]=0;
			for(register int k=1;k<=n;++k){
				tmp[i][j]=(tmp[i][j]+1ll*a[i][k]*b[k][j])%P;
			}
		}
	}
	memcpy(a,tmp,sizeof(tmp));
	return;
}
signed main(){
	int n=read(),m=read(),k=read(),tmd=ksm(2*m%P);
	for(register int i=1;i<=n;++i){
		a[i]=read();
	}
	while(m--){
		int x=read(),y=read();
		f[x][y]=f[y][x]=tmd;
	}
	for(register int i=1;i<=n;++i){
		f[i][i]=1;
		for(register int j=1;j<=n;++j){
			if(j==i){
				res[i][j]=1;
				continue;
			}
			f[i][i]-=f[j][i];
			(f[i][i]<0)&&(f[i][i]+=P);
		}
	}
	while(k){
		if(k&1){
			calc(res,f,n);
		}
		calc(f,f,n);
		k>>=1;
	}
	for(register int i=1;i<=n;++i){
		int A=0;
		for(register int j=1;j<=n;++j){
			A=(A+1ll*a[j]*res[j][i])%P;
		}
		printf("%d\n",A);
	}
	return 0;
}


/**
 *    Author : pradumn
**/
#include<bits/stdc++.h>
using namespace std;
#define Fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define M 1000000007
#define fo(i,n) for(i=0;i<n;i++)
#define pb push_back
#define mp make_pair
#define deb(c) cout<<c<<endl
#define umap unordered_map
#define pqueue priority_queue
#define all(v) v.begin(),v.end()
#define ft first
#define sc second
#define nl "\n"
#define mxe  *max_element
#define mne  *min_element
#define gcd  __gcd
#define sz(x) (int)(x.size())
#define rev(x) reverse(all(x))
#define itr(it, a) for(auto it = a.begin(); it != a.end(); it++)
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pi;
typedef vector<vi> vvi;
typedef map<int,int> mi;
void init_code()
{
  Fast_io;
  #ifndef ONLINE_JUDGE
    freopen("Input.txt","r",stdin);
    freopen("Output.txt","w",stdout);
    freopen("error.txt","w",stderr);
  #endif
}

void func()
{
 float n;
 cin>>n;
 n=n/100;
 cout<<ceil(n);
}
int main()
{
    init_code();
double start1 = (double)clock();
// int t;
// cin>>t;
// while(t--)
func();
double stop1 =(double)clock();
double duration = (stop1-start1)/CLOCKS_PER_SEC;
#ifndef ONLINE_JUDGE
cerr << "Time: " << duration << endl;
#endif
}

#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 n;
  cin >> n;
  vector<ll> a(n);
  ll sum = 0;
  rep(i, n) {
    cin >> a[i];
    sum += a[i];
  }

  ll ans = 0;
  for (int i = n-1; i >= 0; i--) {
    sum -=a[i];
    ans += (n-1) * a[i] * a[i];
    ans -= 2 * sum * a[i];
  }
  cout << ans << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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;
}
class UnionFind {
private:
    int sz;
    vector<int> par, size_;
public:
    UnionFind(){}
    UnionFind(int node_size) : sz(node_size), par(sz), size_(sz, 1){
        iota(par.begin(), par.end(), 0);
    }
    int find(int x){
        if(par[x] == x) return x;
        else return par[x] = find(par[x]);
    }
    void unite(int x,int y){
        x = find(x), y = find(y);
        if(x == y) return;
        if(size_[x] < size_[y]) swap(x,y);
        par[y] = x;
        size_[x] += size_[y];
    }
    int size(int x){
        x = find(x);
        return size_[x];
    }
    bool same(int x,int y){
        return find(x) == find(y);
    }
};
int main(){
    int n,m;
    cin >> n >> m;
    vector<pair<int,int> > p;
    rep(i,m){
        int a,b;
        cin >> a >> b;
        a--;b--;
        p.push_back(MP(a,b));
    }
    ll ans = 0;
    rep(bit,1<<n){
        UnionFind uf(2*n);
        ll res = 1;
        rep(j,m){
            int a = p[j].first;
            int b = p[j].second;
            if(((bit>>a)&1)&&((bit>>b)&1)){
                res = 0;
            }else{
                if(((bit>>a)&1)||((bit>>b)&1)){

                }else{
                    uf.unite(a,b+n);
                    uf.unite(b,a+n);
                }
            }
        }
        vector<bool> p(2*n);

        rep(j,n){
            if((bit>>j)&1)continue;
            if(p[uf.find(j)]||p[uf.find(j+n)])continue;
            if(uf.same(j,j+n)){
                res = 0;
            }else{
                res *=2;
            }
            p[uf.find(j)] = 1;
        }
        ans += res;
        // cerr << bit << " " << res << endl;
    }
    cout << ans << endl;
    return 0;
}

#include<iostream>
#include<vector>
using namespace std;
int N,M;
vector<int>G[20];
int col[20];
bool dfs(int u) {
	for(int v:G[u]) {
		if(col[v]==-1) {
			col[v]=3-col[u];
			if(!dfs(v))return false;
		}
		else if(col[u]==col[v])	{
			return false;
		}
	}
	return true;
}

int main() {
	cin>>N>>M;
	vector<pair<int,int> >E(M);
	for(int i=0;i<M;i++) {
		int a,b;cin>>a>>b;
		a--,b--;
		E[i]=make_pair(a,b);
		G[a].push_back(b);
		G[b].push_back(a);
	}

	long ans=0;
	for(int k=0;k<1<<N;k++)	{
		for(int i=0;i<N;i++) {
			col[i]=-1;
			if(k>>i&1)col[i]=0;
		}
		bool ok=true;
		for(pair<int,int>e:E)if(col[e.first]==0&&col[e.second]==0) {
			ok=false;
			break;
		}
		if(!ok)continue;
		int cnt=0;
		for(int i=0;i<N;i++)if(col[i]==-1)	{
			col[i]=1;
			if(!dfs(i))
			{
				ok=false;
				break;
			}
			cnt++;
		}
		if(ok)ans+=1<<cnt;
	}
	cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
int n, q, c, par[200005];
int uf(int x){
	if (par[x]==x) return x;
	int y = uf(par[x]);
	par[x]=y; return y;
}
map<int, int> raz[200005];
void merge(int x, int y){
	if (raz[x].size() < raz[y].size()) swap(x, y);
	for (map<int, int>::iterator it = raz[y].begin(); it!=raz[y].end(); it++)
		if (raz[x].count(it->first)) raz[x][it->first]+=(it->second);
		else raz[x][it->first]=(it->second);
	par[y] = x; raz[y].clear();
}
int main (){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> q;
for (int i=1; i<=n; i++){
	par[i]=i; cin >> c;
	raz[i][c]=1;
}
while (q--){
	int tip; cin >> tip;
	if (tip==1){
		int a, b; cin >> a >> b;
		if (uf(a)!=uf(b)){
			merge(par[a], par[b]);
		}
	}
	else{
		int x, y; cin >> x >> y;
		int leader = uf(x);
		if (raz[leader].count(y)) cout << raz[leader][y] << endl;
		else cout << 0 << endl;
	}
}
return 0;
}

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

struct UnionFind {
    vector<int> par;

    UnionFind() { }
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

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

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

    bool merge(int x, int y, int id = -1) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};

using Query = pair<int,int>; // id, class
int main() {
    int N, Q;
    cin >> N >> Q;
    vector<int> C(N);
    for (int i = 0; i < N; ++i) cin >> C[i], --C[i];

    // build forest
    UnionFind uf(N);
    vector<int> left(N+Q, -1), right(N+Q, -1), ancestor(N+Q);
    iota(ancestor.begin(), ancestor.end(), 0);
    vector<vector<Query>> queries(N+Q);
    int mergeNum = N, queryNum = 0;
    for (int q = 0; q < Q; ++q) {
        int type, x, y;
        cin >> type >> x >> y;
        --x, --y;
        if (type == 1) {
            x = uf.root(x), y = uf.root(y);
            if (x == y) continue;
            uf.merge(x, y);

            // x が親となるように
            if (uf.root(x) != x) swap(x, y);

            left[mergeNum] = ancestor[x];
            right[mergeNum] = ancestor[y];
            ancestor[x] = mergeNum++;
        } else {
            x = uf.root(x);
            int v = ancestor[x];
            queries[v].emplace_back(queryNum++, y);
        }
    }

    // dfs
    vector<int> res(queryNum, 0), counter(N, 0);
    auto dfs = [&](auto self, int v) -> void {
        for (auto q : queries[v]) res[q.first] -= counter[q.second];
        if (v < N) counter[C[v]]++; // leaf
        else self(self, left[v]), self(self, right[v]);
        for (auto q : queries[v]) res[q.first] += counter[q.second];
    };
    for (int v = 0; v < N; ++v) {
        if (uf.root(v) != v) continue;
        dfs(dfs, ancestor[v]);
    }
    for (auto val : res) cout << val << endl;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 2e3 + 5;

int n, m, a, b, ans;

bool vis[N];

vector<int> graph[N];

void dfs(int v){
    ans++;
    vis[v] = true;

    for(auto i : graph[v]){
        if(!vis[i]) dfs(i);
    }
}

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

    cin >> n >> m;

    for(int i = 0; i < m; i++){
        cin >> a >> b;

        graph[a].push_back(b);
    }

    for(int i = 1; i <= n; i++){
        memset(vis, 0, sizeof(vis));

        dfs(i);
    }

    cout << ans;
}

#include <stdio.h>
#include <string>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int, int>;

vector<vector<int>> to;
vector<bool> visit;
int sum;
void dfs(int i){
  if(visit[i]) return;
  visit[i] = true;
  sum++;
  for(int t: to[i]) dfs(t);
  return;
}

int main()
{
  int n, m;
  cin >> n >> m;
  to = vector<vector<int>>(n);
  rep(i,m){
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
  }

  // //to全体を出力
  // rep(i,n){
  //   cout << "to" << i << " ";
  //   for(int t: to[i]) cout << t << " ";
  //   cout << endl;
  // }

  sum = 0;
  rep(i,n){
    visit = vector<bool>(n, false);
    dfs(i);
  }

  cout << sum << endl;
}


#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define maxn 505
#define ll long long
#define mo 998244353
using namespace std;

int n,m,i,j,k,a[maxn][maxn],c[3];

int main(){
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++){
		char ch=getchar();
		while (ch!='R'&&ch!='B'&&ch!='.') ch=getchar();
		for(j=1;j<=m;j++) a[i][j]=(ch=='.')?0:((ch=='R')?1:2),ch=getchar();
	}
	ll ans=1;
	for(i=2;i<=n+m;i++){
		c[0]=c[1]=c[2]=0;
		for(j=1;j<i;j++) if (j>=1&&j<=n&&i-j>=1&&i-j<=m)
			c[a[j][i-j]]++;
		if (c[1]&&c[2]) printf("0\n"),exit(0);
		if (!c[1]&&!c[2]) ans=ans*2%mo;
	}
	printf("%lld\n",ans);
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>
// #include "atcoder/all"

using namespace std;

using i64 = long long;

const long long MOD = 1000000007;
const i64 INF = i64(1e18) + 7;

template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}

// doc: https://shibh308.github.io/library/library/lib/classes/modint.cpp.html
template <i64 mod = MOD>
struct ModInt{
    i64 p;

    ModInt() : p(0){}
    ModInt(i64 x){p = x >= 0 ? x % mod : x + (-x + mod - 1) / mod * mod;}

    ModInt& operator+=(const ModInt& y){p = p + *y - ((p + *y) >= mod ? mod : 0); return *this;}
    ModInt& operator-=(const ModInt& y){p = p - *y + (p - *y < 0 ? mod : 0); return *this;}
    ModInt& operator*=(const ModInt& y){p = (p * *y) % mod; return *this;}
    ModInt& operator%=(const ModInt& y){if(y)p %= *y; return *this;}

    ModInt operator+(const ModInt& y) const{ModInt x = *this; return x += y;}
    ModInt operator-(const ModInt& y) const{ModInt x = *this; return x -= y;}
    ModInt operator*(const ModInt& y) const{ModInt x = *this; return x *= y;}
    ModInt operator%(const ModInt& y) const{ModInt x = *this; return x %= y;}

    friend ostream& operator<<(ostream& stream, const ModInt<mod>& x){
        stream << *x;
        return stream;
    }

    friend ostream& operator>>(ostream& stream, const ModInt<mod>& x){
        stream >> *x;
        return stream;
    }

    ModInt& operator++(){p = (p + 1) % mod; return *this;}
    ModInt& operator--(){p = (p - 1 + mod) % mod; return *this;}

    bool operator==(const ModInt& y) const{return p == *y;}
    bool operator!=(const ModInt& y) const{return p != *y;}

    const i64& operator*() const{return p;}
    i64& operator*(){return p;}

};

using mint = ModInt<>;

void solve(long long n, long long p){
    // doc: https://shibh308.github.io/library/library/lib/functions/modpow.cpp.html
    auto mpow = [](auto x, i64 y){
     auto z = x;
     decltype(x) val = y & 1 ? x : decltype(x)(1);
     while(z *= z, y >>= 1)
      if(y & 1)
       val *= z;
     return val;
    };

    cout << (mint(p - 1) * mpow(mint(p - 2), n - 1)) << endl;
}

signed main(){
    long long N;
    scanf("%lld",&N);
    long long P;
    scanf("%lld",&P);
    solve(N, P);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

typedef vector<int> vi;
typedef vector<ll> vll;

typedef vector<vi> vvi;
typedef vector<vll> vvll;

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

typedef vector<pii> vpii;
typedef vector<pll> vpll;

typedef vector<vpii> vvpii;
typedef vector<vpll> vvpll;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define fi first
#define se second

template<class T> bool ckmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<class T> bool ckmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}

void __print(int x) {cerr << x;}
void __print(long long 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 string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

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 z : x) cerr << (f++ ? "," : ""), __print(z); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if(sizeof...(v)) cerr << ", "; _print(v...);}

#ifdef ljuba
#define dbg(x...) cerr << "LINE(" << __LINE__ << ") -> " << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif

const char nl = '\n';

const int MOD = 998244353;

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

ll suma(ll n) {
    if(n % 2 == 0) {
        ll ans = mul(n/2, n+1);
        return ans;
    } else {
        return mul((n+1)/2, n);
    }
}

void solve() {
    ll a, b, c;
    cin >> a >> b >> c;
    ll ans = 1;
    ans = mul(ans, suma(a));
    ans = mul(ans, suma(b));
    ans = mul(ans, suma(c));
    cout << ans << nl;
}

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

    int testCases = 1;
    //cin >> testCases;
    while(testCases--)
        solve();

}

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

#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define endl '\n'

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace
#define mp make_pair

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n, m) for (ll i = n; i <= m; ++i)
#define rep3(i, n, m) for (ll i = n; i >= m; --i)
#define all(v) v.begin(), v.end()
#define si(v) int(v.size())
#define UNIQUE(v) sort(all(v)), v.erase(unique(all(v)),v.end())
#define INT(...) int __VA_ARGS__; IN(__VA_ARGS__);
#define LL(...) ll __VA_ARGS__; IN(__VA_ARGS__);
#define STR(...) string __VA_ARGS__; IN(__VA_ARGS__);
#define CHR(...) char __VA_ARGS__; IN(__VA_ARGS__);
#define LD(...) ld __VA_ARGS__; IN(__VA_ARGS__);

/* const ll mod = 1e9 + 7; */
const ll mod = 998244353;
const ll infll = (1LL << 62) - 1;
const ll inf = (1LL << 30) - 1;

template<class S, class T> inline bool chmax(S &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class S, class T> inline bool chmin(S &a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;

void IN() {}

template <class Head, class... Tail>
void IN(Head &head, Tail &... tail) {
  cin >> head;
  IN(tail...);
}

class mint {
  private:
    ll x;

  public:
    constexpr mint(const ll x = 0) noexcept : x((x % mod + mod) % mod) {}
    constexpr ll value() noexcept { return x; }
    constexpr mint operator += (const mint right) noexcept {
      if ((x += right.x) >= mod) x -= mod;
      return *this;
    }
    constexpr mint operator -= (const mint right) noexcept {
      if ((x += mod - right.x) >= mod) x -= mod;
      return *this;
    }
    constexpr mint operator *= (const mint right) noexcept {
      x = x * right.x % mod;
      return *this;
    }
    constexpr mint operator /= (const mint right) noexcept {
      return *this *= right.inv();
    }
    constexpr mint operator + (const mint right) const noexcept {
      return mint(*this) += right;
    }
    constexpr mint operator - (const mint right) const noexcept {
      return mint(*this) -= right;
    }
    constexpr mint operator / (const mint right) const noexcept {
      return mint(*this) /= right;
    }
    constexpr mint operator * (const mint right) const noexcept {
      return mint(*this) *= right;
    }
    constexpr mint inv() const {
      return pow(mod-2);
    }
    constexpr mint pow(ll n) const {
      if (n == 0) return 1;
      mint a = pow(n>>1);
      a *= a;
      if (n & 1) a *= *this;
      return a;
    }
};

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

  LL(a, b, c);

  mint aa = (a * (a + 1)) / 2;
  mint bb = (b * (b + 1)) / 2;
  mint cc = (c * (c + 1)) / 2;

  cout << (aa * bb * cc).value() << endl;

}


#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#include <iostream>
#include <queue>
using namespace std;
#define f(x,y,z) for(int x=y;x<z;++x)
#define fi first
#define se second
typedef pair<int, int> pii;
int n, m, a, b, ans, step;
vector<pii> e[1000];
queue<pii> q[2];
char c;
bool bl, sdh[1000][1000];
int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> n >> m;
    f(i,0,m) {
        cin >> a >> b >> c;
        --a, --b;
        e[a].push_back({b, c});
        e[b].push_back({a, c});
    }
    step = 0, ans = 1e9;
    q[0].push({0, n-1});
    while(!q[bl].empty()) {
        while(!q[bl].empty()) {
            a = q[bl].front().fi;
            b = q[bl].front().se;
            q[bl].pop();
            for(pii &i:e[a]) for(pii &j:e[b]) if(i.se == j.se && !sdh[i.fi][j.fi]) {
                sdh[i.fi][j.fi] = true;
                // cout << a+1 << ' ' << b+1 << ' ' << i.fi+1 << ' ' << j.fi+1 << '\n';
                if(i.fi == j.fi) {
                    ans = min(ans, (step+1)<<1);
                } else if(i.fi == b || j.fi == a) {
                    ans = step<<1|1;
                } else if(ans == 1e9) q[!bl].push({i.fi, j.fi});
            }
        }
        if(ans != 1e9) return cout << ans << '\n', 0;
        ++step, bl = !bl;
        // cout << '\n';
    }
    cout << "-1\n";
}

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

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
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(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N,M;
vector<int> E[1010][26];
int D[1010][1010];

void solve() {
	int i,j,k,l,r,x,y; string s;

	cin>>N>>M;
	FOR(x,N) FOR(y,N) D[x][y]=(x==y?0:1LL<<30);
	FOR(i,M) {
		cin>>x>>y>>s;
		E[x-1][s[0]-'a'].push_back(y-1);
		E[y-1][s[0]-'a'].push_back(x-1);
		if(x!=y) D[x-1][y-1]=D[y-1][x-1]=1;
	}

	queue<int> Q;
	FOR(i,N) Q.push(i*1000+i);
	FOR(x,N) FOR(y,N) if(D[x][y]==1) Q.push(x*1000+y);

	while(Q.size()) {
		int u=Q.front()/1000;
		int v=Q.front()%1000;
		Q.pop();
		if(u==0&&v==N-1) {
			cout<<D[u][v]<<endl;
			return;
		}
		FOR(i,26) {
			FORR(x,E[u][i]) FORR(y,E[v][i]) {
				if(D[x][y]>D[u][v]+2) {
					D[x][y]=D[u][v]+2;
					Q.push(x*1000+y);
				}
			}
		}

	}

	cout<<-1<<endl;

}

int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}