#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<tuple>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

using state = tuple<ll, int, int>;

const ll INF = 1LL << 50;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int R, C;
    cin >> R >> C;
    vector<vector<int>> A(R, vector<int>(C - 1));
    vector<vector<int>> B(R - 1, vector<int>(C));
    rep(i, 0, R) rep(j, 0, C - 1) {
        cin >> A[i][j];
    }
    rep(i, 0, R - 1) rep(j, 0, C) {
        cin >> B[i][j];
    }
    priority_queue<state, vector<state>, greater<state>> que;
    vector<vector<ll>> dp(R, vector<ll>(C, INF));
    dp[0][0] = 0;
    que.emplace(0, 0, 0);
    while (!que.empty()) {
        state now = que.top();
        que.pop();
        ll cost = get<0>(now);
        int r = get<1>(now);
        int c = get<2>(now);
        if (dp[r][c] < cost) {
            continue;
        }
        if (c + 1 < C && chmin(dp[r][c + 1], cost + A[r][c])) {
            que.emplace(dp[r][c + 1], r, c + 1);
        }
        if (c - 1 >= 0 && chmin(dp[r][c - 1], cost + A[r][c - 1])) {
            que.emplace(dp[r][c - 1], r, c - 1);
        }
        if (r + 1 < R && chmin(dp[r + 1][c], cost + B[r][c])) {
            que.emplace(dp[r + 1][c], r + 1, c);
        }
        rep(i, 0, r) {
            if (chmin(dp[r - i - 1][c], cost + 1 + i + 1)) {
                que.emplace(dp[r - i - 1][c], r - i - 1, c);
            }
        }
    }
    cout << dp[R - 1][C - 1] << endl;
    return 0;
}

#include<bits/stdc++.h>
#define ll long long
#define N 400005
using namespace std;
int read() {
	int x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while('0'<=c&&c<='9'){x=x*10+c-'0';c=getchar();}
	return x*f;
}
int n,m,K,cnt,h[N],c[N],fp[N];
struct Edge {
	int to,next;
}a[N*2];
void Add(int x,int y) {
	cnt++;a[cnt].to = y;a[cnt].next = h[x];h[x] = cnt;
}
int ind;
ll ans = 0;
#define inf 0x7fffffff/2
queue<int>q;
int d[20][N],inq[N];
void bfs(int id) {

	for(int i=1; i<=n; ++i)d[id][i] = inf;

	q.push(c[id]);d[id][c[id]] = 0;

	inq[c[id]] = 1;

	while(!q.empty()) {

		int x = q.front();q.pop();
		for(int i=h[x]; i; i=a[i].next) {
			int y = a[i].to;
			if(!inq[y])d[id][y] = d[id][x]+1,q.push(y),inq[y] = 1;
		}
	}
	memset(inq,0,sizeof(inq));
}
ll f[1<<17][18];
int sta;
int fl;
void deal() {
//	fl++;
//	if(fl>=20)
//	{
//		vector<int>v;
//		cout<<v[2313132]<<endl;
//		exit(0);
//	}
	for(int i=1; i<=K; ++i)bfs(i);
//	for(int i=1; i<=K; ++i){
//
//		for(int j=1; j<=n; ++j)
//		cout << d[i][j] << ' ';
//		cout << '\n';
//	}
	memset(f,0x3f,sizeof(f));
	for(int i=1; i<=K; ++i)f[1<<i-1][i] = 0;
	for(int i=0;i<(1<<K);i++)
	{
		for(int j=1;j<=K;j++)
		{
			if(f[i][j]>1e9)continue;
			for(int t=1;t<=K;t++)
			{
				if(i&(1<<t-1))continue;
				f[i+(1<<t-1)][t]=min(f[i+(1<<t-1)][t],f[i][j]+d[j][c[t]]);
			}
		}
	}
	for(int j=1;j<=K;j++)
	{
		ans=min(ans,f[(1<<K)-1][j]);
	}

}
bool vst[N];
void dfs(int x) {
	vst[x] = 1;
	if(fp[x])ind |= 1 << fp[x]-1;
	for(int i=h[x]; i; i=a[i].next) {
		int y = a[i].to;
		if(!vst[y])dfs(y);
	}
}
int main() {
	n = read();m = read();
	for(int i=1; i<=m; ++i) {
		int x = read(),y = read();
		Add(x,y);Add(y,x);
	}
	K = read();sta = 0;
	for(int i=1; i<=K; ++i) {
		sta |= 1<<i-1;
	}
	ans = 1LL<<40;
	for(int i=1; i<=K; ++i)c[i] = read(),fp[c[i]] = i;
	for(int i=1; i<=n; ++i)if(!vst[i]) {
		ind = 0;
		dfs(i);
		if(ind == sta)
		{
			deal();
			for(int j=1;j<=K;j++)if(!vst[c[j]])exit(0);
		}
	}
	if(ans >= 1e9)puts("-1");
	else cout << ans+1;
}


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

typedef long long              ll;
typedef long double            ld;
typedef pair<int, int>         pi;
typedef vector<int>            vi;
typedef vector<long long>      vll;
typedef vector<pair<int, int>> vpi;

#define pb            push_back
#define pf            push_front
#define all(x)        begin(x), end(x)
#define sz(x)         (int)(x).size()
#define ff            first
#define ss            second
#define mp            make_pair
#define lb            lower_bound
#define ub            upper_bound
#define Tcase()       int tcc; cin >> tcc; while(tcc--)
#define FOR(i, a, b)  for(int i = (a); i < (b); i++)
#define F0R(i, a)     FOR(i, 0, a)

const ll  MOD   = 998244353;
const ll  INF   = 9e18;
const int MX    = 2e5 + 5;
const ld  PI    = acos((ld) -1);
const int dx[8] = {0, 1, 0, -1, 1, -1, 1, -1};
const int dy[8] = {1, 0, -1, 0, 1, -1, -1, 1};

void setIO(string name = "") {
    ios_base::sync_with_stdio(0); cin.tie(0);
    if(sz(name)){
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }
}

int Dp[5005][5005];

int main(){

    setIO();

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

    int a[n], b[m];
    F0R(i, n) cin >> a[i];
    F0R(i, m) cin >> b[i];

    F0R(i, n + 1){
        F0R(j, m + 1){
            Dp[i][j] = MOD;
            if(!i) Dp[i][j] = j;
            if(!j) Dp[i][j] = i;
        }
    }

    FOR(i, 1, n + 1){
        FOR(j, 1, m + 1){

            if(a[i - 1] == b[j - 1]) Dp[i][j] = Dp[i - 1][j - 1];
            else Dp[i][j] = min({Dp[i - 1][j], Dp[i][j - 1], Dp[i - 1][j - 1]}) + 1;
        }
    }

    cout << Dp[n][m];
}

//OM TAT SAT
#include<bits/stdc++.h>
#define N 100010
using namespace std;
int a[N],b[N];
int main()
{
    int n;
    cin>>n;

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

    }//cout<<aa<<bb<<endl;
    int ans=10000000,p;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            //ans=min(ans,i==j? a[i]+b[j] :max(a[i],b[j]));
            if(i==j)
            p=a[i]+b[j];
           else
            p=max(a[i],b[j]);

           ans=min(ans,p);

        }
    }
    cout<<ans<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
const int N = 3010;
int f[N][N];
int main(){
#ifndef ONLINE_JUDGE
	freopen("E:\\in.txt","r", stdin);
#endif
	int n, k;
	cin >> n >> k;
	f[0][0] = 1;
	for(int i = 1; i <= n; i++){
		for(int j = n; j >= 1; j--){
			f[i][j] = f[i-1][j-1];
			if(i >= 2 * j)
				f[i][j] = (f[i][j] + f[i][2*j]) % mod;
		}
	}
	cout << f[n][k] << endl;
}

#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>;
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>;

const ll MOD = 1000000007;

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

int main() {
    ll N, P;
    cin>>N>>P;

    ll ans = (P-1) * modpow(P-2, N-1) % MOD;
    cout << ans;
}


//Somos insignificantes. Por mais que você programe sua vida, a qualquer momento tudo pode mudar.
// If you have God on your side,everything becomes clear

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

typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int MAX_N = 1e5 + 5;
const int MAX_L = 20; // ~ Log N
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 7;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
#define fi first
#define popcount(x) __builtin_popcountll(x)
#define se second
#define LSOne(S) (S & (-S))
#define isBitSet(S, i) ((S >> i) & 1)
/*void Sieve(int n)
{

    //bool prime[n+1];
    //memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }

} */
/* struct cmp{
    bool operator()(const pair<int,int>& v1,const pair<int,int>& v2) const{

    }};*/

bool comp(pair<string,int>a,pair<string,int>b)
{
    if(a.second>b.second)
        return true;
    else
        return false;
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
   int n;
   cin>>n;
   vector<pair<string,int>>city;
   for(int i=0;i<n;i++)
   {
       string s;
       int h;
       cin>>s>>h;
       city.push_back({s,h});
   }
   sort(city.begin(),city.end(),comp);
   cout<<city[1].first<<endl;
}

#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
typedef long long ll;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);

int gcd(int x, int y)
{
    if (x == 0)
        return y;
    return gcd(y % x, x);
}

void solv()
{
    int n;
    scanf("%d", &n);
    int ans = 0;
    while (n--)
    {
        int x;
        scanf("%d", &x);
        ans = gcd(ans, x);
    }
    printf("%d\n", ans);
}

int main()
{
    #ifdef SOMETHING
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #endif // SOMETHING
    //ios_base::sync_with_stdio(false), cin.tie(0);
    solv();
    return 0;
}

//while ((double)clock() / CLOCKS_PER_SEC <= 0.9){}


#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
#include <cstdint>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int INF=1001001001;
const int mod = 1000000007;

int main() {
  int N;
  cin>>N;
  vector<int>type(2*N);//iが誰かの　始点-1 終点1 なんでもいい 0　になっているか
  vector<vector<int>>p(2*N,vector<int>(2*N));//i,jを ペアにしていい 1,0 ダメ -1
  vector<int>xs,ps;
  for(int i=0;i<N;i++){
    int a,b;
    cin>>a>>b;
    if(a!=-1){
       a--;
       if(type[a]!=0){cout<<"No"<<endl;return 0;}
       type[a]=1;
       xs.push_back(a);
    }
    if(b!=-1){
       b--;
       if(type[b]!=0){cout<<"No"<<endl;return 0;}
       type[b]=-1;
       xs.push_back(b);
    }
    if(a!=-1&&b!=-1){p[a][b]=1;ps.push_back(a);ps.push_back(b);}
  }
  for(int a:xs){//xs:-1ではない物->それ同士は(元からペアになっているものを除いて）ペアにならない。
    for(int b:xs){
        if(p[a][b]!=1){p[a][b]=-1;}
    }
  }
  for(int a:ps){//ps:元からペアになっているものの片方。!p[a][i]:1ではないもの。元からペアのものがある場合は、その相手以外はペアにできないようにする。
    for(int i=0;i<2*N;i++){
       if(!p[a][i]){p[a][i]=-1;}
       if(!p[i][a]){p[i][a]=-1;}
    }
  }
  vector<bool>dp(2*N+1,false);
  dp[0]=true;
  for(int i=0;i<2*N;i+=2){
    if(!dp[i]){continue;}
    for(int j=1;j<=N;j++){
      int ni=i+j*2;
      if(ni>2*N){break;}
      bool ok=true;
      for(int l=i;l<i+j;l++){
        int r=l+j;
        if(type[l]==-1){ok=false;}
        if(type[r]==1){ok=false;}
        if(p[l][r]==-1){ok=false;}
      }
      if(ok){dp[ni]=1;}
    }
  }
  if(dp[2*N]){cout<<"Yes"<<endl;}
  else{cout<<"No"<<endl;}
  return 0;
}//お試し

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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define per(i, b) per2(i, 0, b)
#define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define ALL(c) (c).begin(), (c).end()
#define SZ(x) ((int)(x).size())

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

int main() {
    int N;
    cin >> N;
    V<int> A(N), B(N);
    int sz = N * 2;
    V<int> tp(sz), com(sz, -1);

    bool ng = false;

    rep(i, N) {
        cin >> A[i] >> B[i];
        if (A[i] != -1) {
            --A[i];
            if (tp[A[i]]) ng = true;
            tp[A[i]] = i + 1;
        }
        if (B[i] != -1) {
            --B[i];
            if (tp[B[i]]) ng = true;
            tp[B[i]] = -(i + 1);
        }

        if (A[i] != -1 && B[i] != -1) {
            com[A[i]] = B[i];
            com[B[i]] = A[i];
        }
    }
    if (ng) {
        puts("No");
        return 0;
    }

    V<bool> dp(sz + 1);
    dp[0] = true;

    rep(i, sz) {
        if (!dp[i]) continue;
        for (int j = i + 1; j < sz; ++j) {
            int w = j - i + 1;
            if (w & 1) continue;
            w /= 2;
            bool ok = true;
            V<bool> exist(N);

            rep(k, w) {
                int p = i + k, q = i + k + w;
                if (com[p] != -1 && !(i <= com[p] && com[p] <= j)) {
                    ok = false;
                }
                if (com[q] != -1 && !(i <= com[q] && com[q] <= j)) {
                    ok = false;
                }

                bool same = true;
                if (tp[p] != 0 && tp[q] != 0) {
                    if (tp[p] < 0 || tp[p] + tp[q] != 0) {
                        ok = false;
                    } else
                        same = true;
                }
                if (tp[p] < 0 || tp[q] > 0) {
                    ok = false;
                } else {
                    if (tp[p] != 0) {
                        int v = tp[p] - 1;
                        if (exist[v]) {
                            ok = false;
                        }
                        exist[v] = true;
                    }
                    if (!same && tp[q] != 0) {
                        int v = -tp[q] - 1;
                        if (exist[v]) {
                            ok = false;
                        }
                        exist[v] = true;
                    }
                }
            }
            if (ok) {
                dp[j + 1] = true;
            }
        }
    }
    puts(dp[sz] ? "Yes" : "No");

    return 0;
}


#include <iostream>

constexpr int N = 200005;
constexpr int p = 998244353;

int add(int x, int y) { return (x += y) >= p ? x - p : x; }
int mul(int x, int y) { return (long long)x * y % p; }
int power(int x, int y) { int ans = 1; for (; y; y >>= 1) { if (y & 1) ans = mul(ans, x); x = mul(x, x); } return ans; }

int n, m;
int f[N], primes[N], powcnt[N], inv[N], cnt;
bool vis[N];

int main() {
    std::ios::sync_with_stdio(false), std::cin.tie(nullptr);
    std::cin >> n >> m;
    inv[1] = 1;
    for (int i = 2; i <= m; ++i) inv[i] = mul(inv[p % i], p - p / i);
    f[1] = 1;
    vis[1] = true;
    for (int i = 2; i <= m; ++i) {
        if (!vis[i]) primes[++cnt] = i, f[i] = n, powcnt[i] = 1;
        for (int j = 1; j <= cnt && i * primes[j] <= m; ++j) {
            vis[i * primes[j]] = true;
            if (!(i % primes[j])) {
                powcnt[i * primes[j]] = powcnt[i] + 1;
                f[i * primes[j]] = mul(f[i], mul(n + powcnt[i * primes[j]] - 1, inv[powcnt[i * primes[j]]]));
                break;
            } else {
                powcnt[i * primes[j]] = 1;
                f[i * primes[j]] = mul(f[i], f[primes[j]]);
            }
        }
    }
    int ans = 0;
    for (int i = 1; i <= m; ++i) ans = add(ans, f[i]);
    std::cout << ans << '\n';
    return 0;
}


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

int main() {

  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  if (b/c >= d) {
    cout << -1 << '\n';
  } else {
    ll y = (d*c)-b;
    ll x = (a/y);
    if (((b*x)+a) <= (d * x * c)) {
      cout << x << '\n';
    } else {
      cout << x + 1 << '\n';
    }
  }

  return 0;
}

#include<bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x)
{
	T f = 1; x = 0;
	char ch = getchar();
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
	for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
	x *= f;
}
template <typename T>
void write(T x)
{
	if (x < 0)
	{
		putchar('-');
		x = -x;
	}
	if (x > 9) write(x / 10);
	putchar(char(x % 10 + 48));
}
template <typename T>
void writeln(T x, char ch = '\n')
{
	write(x);
	putchar(ch);
}
int n, m, k;
int main()
{
	read(n); read(m); read(k);
	cout << (n - m + k) << endl;
	return 0;
}


#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
#include<chrono>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define vint(a,n) vint a(n); rep(i, n) cin >> a[i];
#define vll(a,n) vll a(n); rep(i, n) cin >> a[i];
#define ALL(n) begin(n),end(n)
#define RALL(n) rbegin(n),rend(n)
#define MOD (1000000007)
// #define MOD (998244353)
#define INF (1e9+7)
#define INFL (2e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
using vint=vector<int>;
using vll=vector<ll>;
using vbool=vector<bool>;
using P=pair<ll,ll>;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pl(T x){cout << x << " ";}
template<class T>void pr(T x){cout << x << endl;}
template <class T, class... Ts> inline void pr(T Tar, Ts... ts) { std::cout << Tar << " "; pr(ts...); return; }
template<class T>void prvec(vector<T>& a){if(a.size()>0){rep(i, (int)a.size()-1){pl(a[i]);} pr(a.back());}else{pr("");}}
template<class T>void prarr(arr<T>& a){rep(i, (int)a.size()) if(a[i].empty()) pr(""); else prvec(a[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; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}

int main()
{
    ll n; cin >> n;
    vll(a, n);

    ll ans = INF;

    if(n==1){
        pr(a[0]);
        return 0;
    }

    rep(bit, 1<<(n-1)){
        // if(bit==0) continue;
        ll res = 0;
        ll t = 0;
        rep(i, n){
            t |= a[i];
            if(i==n-1) break;
            if((bit>>i)&1){
                res ^= t;
                t = 0;
            }
        }
        res ^= t;
        chmin(ans, res);
    }
    pr(ans);
    return 0;}

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
int mod = 1000000007;
int add(int x, int y) { return (x += y) >= mod ? x - mod : x; }
template<class... T> int add(int x, T... y) { return add(x, add(y...)); }
int mul(int x, int y) { return 1LL * x * y % mod; }
template<class... T> int mul(int x, T... y) { return mul(x, mul(y...)); }
int sub(int x, int y) { return add(x, mod - y); }
int modpow(int a, long long b) {
    int ret = 1; while (b > 0) {
        if (b & 1) ret = 1LL * ret * a % mod; a = 1LL * a * a % mod; b >>= 1;
    } return ret;
}
int modinv(int a) { return modpow(a, mod - 2); }
typedef vector<int> Vec;
typedef vector<Vec> Mat;
Vec mulMatVec(Mat a, Vec b)
{
    int n = b.size(); Vec ret(n, 0);
    rep(i, 0, n) rep(j, 0, n) ret[i] = add(ret[i], mul(a[i][j], b[j]));
    return ret;
}
Mat mulMatMat(Mat a, Mat b)
{
    int n = a.size(); Mat ret(n, Vec(n, 0));
    rep(i, 0, n) rep(j, 0, n) rep(k, 0, n) ret[i][j] = add(ret[i][j], mul(a[i][k], b[k][j]));
    return ret;
}
Mat fastpow(Mat x, ll n)
{
    Mat ret(x.size(), Vec(x.size(), 0));
    rep(i, 0, x.size()) ret[i][i] = 1;
    while (0 < n) { if ((n % 2) == 0) { x = mulMatMat(x, x); n >>= 1; } else { ret = mulMatMat(ret, x); --n; } }
    return ret;
}
void printVec(Vec a) { cout << "[\t"; rep(i, 0, a.size()) cout << a[i] << "\t"; cout << "]" << endl; }
void printMat(Mat a) { rep(i, 0, a.size()) printVec(a[i]); }
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/

int N, M, K, A[101];
int X[10101], Y[10101];
int cnt[101];
bool E[101][101];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> M >> K;
	rep(i, 0, N) cin >> A[i];
    rep(i, 0, M) cin >> X[i] >> Y[i], X[i]--, Y[i]--;

    Mat Ma(N, Vec(N));
	rep(i, 0, M) {
        cnt[X[i]]--;
        cnt[Y[i]]--;
        E[X[i]][Y[i]] = E[Y[i]][X[i]] = true;
	}

    rep(to, 0, N) {
        int cnt = M;
        rep(from, 0, N) if (to != from) {
            if (E[to][from]) {
                Ma[to][to] = add(Ma[to][to], mul(modinv(M), modinv(2)));
                Ma[to][from] = add(Ma[to][from], mul(modinv(M), modinv(2)));
                cnt--;
            }
        }
        Ma[to][to] = add(Ma[to][to], mul(cnt, modinv(M)));
    }

    Vec v(N, 0);
    rep(i, 0, N) v[i] = A[i];

    Ma = fastpow(Ma, K);
    v = mulMatVec(Ma, v);
    rep(i, 0, N) cout << v[i] << endl;
}


#include <iostream>
#include<bits/stdc++.h>

using namespace std;
#define int long long
#define iso ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int32_t main() {

        int n;
        cin >> n;
   cout<<n/100+(n%100==0?0:1)<<endl ;

}

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

// additional
// #include <array> // array
#include <numeric> // accumulate

// macro
#define rep(i, n) for (int (i)=0;(i)<(n);(i)++)

using namespace std;

using ll = long long;

int main() {
    int N;
    cin >> N;
    cout << ((N-1) / 100) + 1 << endl;
    return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define pb push_back
#define nl cout<<"\n"
#define F first
#define S second
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

const ll MOD = 1000000007;
ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; }

const int MAXN = 1e5+5;
const int LOGN = 21;
const ll INF = 1e14;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

template<class T1, class T2> void add( T1 &x, T2 y, ll m = MOD )
{
	x += y;
	if( x >= m )
		x -= m;
}

template<class T1, class T2> void sub( T1 &x, T2 y, ll m = MOD )
{
	x -= y;
	if( x < 0 )
		x += m;
}

int dp[1002][1002];

int main()
{
	#ifdef gupta_samarth
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	fastio();

	int a,b,w;
	cin>>a>>b>>w;

	w *= 1000;
	int mn = MOD, mx = 0;
	for(int i=w/b;i<=(w+a-1)/a;i++)
	{
		if( a*i <= w && w <= b*i )
		{
			mn = min(mn, i);
			mx = max(mx, i);
		}
	}
	if( mn == MOD )
	{
		cout<<"UNSATISFIABLE",nl;
		return 0;
	}
	cout<<mn<<" "<<mx,nl;

	cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
	return 0;
}

#include <iostream>
using namespace std;

int A, B;
double W;

int isin(double N) {
    if(N >= A and N <= B) {
        return true;
    } else {
        return false;
    }
}

int main() {
    cin >> A >> B >> W;
    int max = 0;
    int min = 0;
    for (int i = 1; i <= W * 1000; i++) {
        double pre = W * 1000 / i;

        if(isin(pre)) {
            min = i;
            break;
        }
    }

    for (int i = W * 1000; i > 0; i--) {
        double pre = W * 1000 / i;

        if(isin(pre)) {
            max = i;
            break;
        }
    }

    if (min == 0) {
        min = max;
    }
    if (max == 0) {
        max = min;
    }

    if (min == 0 and max == 0) {
        cout << "UNSATISFIABLE" << endl;
    } else {
        cout << min << " " << max << endl;
    }
}


#include <bits/stdc++.h>
#define ll long long
#define ls id << 1
#define rs id << 1 | 1
#define mem(array, value, size, type) memset(array, value, ((size) + 5) * sizeof(type))
#define memarray(array, value) memset(array, value, sizeof(array))
#define fillarray(array, value, begin, end) fill((array) + (begin), (array) + (end) + 1, value)
#define fillvector(v, value) fill((v).begin(), (v).end(), value)
#define pb(x) push_back(x)
#define st(x) (1LL << (x))
#define pii pair<int, int>
#define mp(a, b) make_pair((a), (b))
#define Flush fflush(stdout)
#define vecfirst (*vec.begin())
#define veclast (*vec.rbegin())
#define vecall(v) (v).begin(), (v).end()
#define vecupsort(v) (sort((v).begin(), (v).end()))
#define vecdownsort(v, type) (sort(vecall(v), greater<type>()))
#define veccmpsort(v, cmp) (sort(vecall(v), cmp))
using namespace std;
const int N = 500050;
const int inf = 0x3f3f3f3f;
const ll llinf = 0x3f3f3f3f3f3f3f3f;
const int mod = 998244353;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
clock_t TIME__START, TIME__END;
void program_end()
{
#ifdef ONLINE
    printf("\n\nTime used: %.6lf(s)\n", ((double)TIME__END - TIME__START) / 1000);
    system("pause");
#endif
}
ll n;
vector<ll> ans;

inline void solve()
{
    cin >> n;
    for (ll i = 1; i * i < n; ++i)
    {
        if (n % i == 0)
        {
            // cout << i << endl;
            // cout << n / i << endl;
            ans.push_back(i), ans.push_back(n / i);
        }
    }
    if ((ll)sqrt(n) * (ll)sqrt(n) == n)
    {
        // cout << (ll)sqrt(n) << endl;
        ans.push_back((ll)sqrt(n));
    }
    vecupsort(ans);
    for(auto i :ans)
        cout << i << '\n';
}

int main()
{
    TIME__START = clock();
    int Test = 1;
    // scanf("%d", &Test);
    while (Test--)
    {
        solve();
        // if (Test)
        //     putchar('\n');
    }
    TIME__END = clock();
    program_end();
    return 0;
}

#include <bits/stdc++.h>

#define fi first
#define se second
#define DB double
#define U unsigned
#define P std::pair
#define LL long long
#define LD long double
#define pb push_back
#define MP std::make_pair
#define SZ(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define FOR(i,a,b) for(int i = a;i <= b;++i)
#define ROF(i,a,b) for(int i = a;i >= b;--i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl

int c[(1<<8)+5][(1<<8)+5];
bool ok[(1<<8)+5];

int main(){
    int n;scanf("%d",&n);
    if(n == 1){
        printf("1\nAB\n");
        return 0;
    }
    printf("%d\n",(1<<n)-1);
    FOR(i,1,(1<<n)-1){
        FOR(j,0,(1<<n)-1) ok[j] = __builtin_popcount(i&j)&1;
        FOR(i,0,(1<<n)-1) printf("%c","AB"[ok[i]]);puts("");
        FOR(i,0,(1<<n)-1) FOR(j,i+1,(1<<n)-1) if(ok[i] != ok[j]) ++c[i][j];
    }
    int tt = c[0][1];
    FOR(i,0,(1<<n)-1) FOR(j,i+1,(1<<n)-1) assert(c[i][j] == tt);
    return 0;
}


/* Author : Mychecksdead */
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define PI 3.1415926535
#define pb push_back
#define for0(i, n) for(ll i = 0; i < n; i++)
#define for1(i, n) for(ll i = 1; i <= n; i++)
#define test int T; cin >> T;
#define mid (l+r)/2
const int N = 1e5;

int n, q;
ll arr[N], el, k;
set<pair<ll,ll>> s;
void solve(){
    cin >> n >> q;
    for0(i, n) cin >> arr[i];
    for(int i = 0; i < n; i++){
        s.insert({arr[i] - i - 1, arr[i]});
    }
    while(q--){
        cin >> k;
        auto it = s.upper_bound({k, -1e9});
        if(it == s.begin()){
            cout << k << '\n';
        }else{
            it--;
            pair<ll, ll> p = (*it);
            cout << p.second + k - p.first << '\n';
        }

    }
}

int main(){
    cin.tie(0); ios::sync_with_stdio(0);
    // test;
    int T = 1;
    while(T--){
        solve();
    }
    return 0;
}

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

int main() {
    ll N,M,T; cin>>N>>M>>T;
    ll n = N, l=0;
    rep(i, M){
        ll A,B; cin>>A>>B;
        n = max(n-(A - l), (ll)0);
        if(n <= 0){
            cout << "No" << endl;
            return 0;
        }
        n = min(n+(B-A), N);
        l = B;
    }

    cout << (n-(T-l) <= 0 ? "No" : "Yes") << endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
//constexpr ll MOD = 1e9 + 7;
constexpr ll MOD = 998244353;
//constexpr ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
constexpr ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)

ll loopcnt = 0;
vector<vector<ll>> G;
vector<ll> visited;
void dfs(ll sv, ll V)
{
  if (visited.at(V) != -1)
  {
    if (visited.at(V) == sv)
    {
      //cerr << sv << " " << V << endl;
      loopcnt++;
    }

    return;
  }
  visited.at(V) = sv;

  for (auto nv : G.at(V))
  {
    dfs(sv, nv);
  }
}

int main()
{
  ll N;
  cin >> N;
  G.resize(N);
  for (ll u = 0; u < N; u++)
  {
    ll v;
    cin >> v;
    v--;
    G.at(u).push_back(v);
  }

  visited.resize(N);
  fill(visited.begin(), visited.end(), -1);
  for (ll v = 0; v < N; v++)
  {
    if (visited.at(v) == -1)
      dfs(v, v);
  }

  ll ans = 1;
  for (ll i = 0; i < loopcnt; i++)
  {
    ans *= 2, ans %= MOD;
  }
  ans = mod(ans - 1, MOD);
  cout << ans << endl;
  //cerr << loopcnt << endl;
}

// We can calculate the number of inversions in the original array in a number of ways, such as with a Fenwick tree or with merge sort.
// Now, notice that each of the resulting sequences essentially remove the first element of the previous sequence and insert it at the end of it.
// This changes the number of inversions in the new sequence by n−1−2ai for each i from 0 to N−2.

// Time complexity: O(NlogN for calculating inversions  )
#include <bits/stdc++.h>
#define ll long long
using namespace std;

const int maxn = (int)3e5+5;
int n,a[maxn],b[maxn],c[maxn];

ll find_inversions(int l, int r) {
    if (l == r)
        return 0;
    int m = l+ ((r-l)>>1), x = l, y = m+1;
    ll ans = find_inversions(l, m) + find_inversions(m+1, r);
    for (int i = l; i <= r; i++) {
        if (x > m)
            c[i] = b[y++];
        else if (y>r)
            c[i] = b[x++];
        else if (b[x]>b[y]) {
            c[i] = b[y++];
            ans += m-x+1;
        }
        else
            c[i] = b[x++];
    }
    for (int i = l; i <= r; i++)
        b[i] = c[i];
    return ans;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin>>n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        b[i] = a[i];
    }
    ll cur = find_inversions(0,n-1);
    cout << cur << "\n";
    for (int i = 0; i+1 < n; i++) {
        cur += n-1 - 2*a[i];
        cout << cur << "\n";
    }
    return 0;
}


/*
　　　　　／＞　 フ
　　　　　| 　_　 _|
　 　　　／`ミ _x 彡
　　 　 /　　　 　 |
　　　 /　  ヽ　　 ?
　／￣|　　 |　|　|
　| (￣ヽ＿_ヽ_)_)
　＼二つ
 */

#include <queue>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MP make_pair
#define ll long long
#define fi first
#define se second
using namespace std;

template <typename T>
void read(T &x) {
    x = 0; bool f = 0;
    char c = getchar();
    for (;!isdigit(c);c=getchar()) if (c=='-') f=1;
    for (;isdigit(c);c=getchar()) x=x*10+(c^48);
    if (f) x=-x;
}

template<typename F>
inline void write(F x, char ed = '\n') {
	static short st[30];short tp=0;
	if(x<0) putchar('-'),x=-x;
	do st[++tp]=x%10,x/=10; while(x);
	while(tp) putchar('0'|st[tp--]);
	putchar(ed);
}

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

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

const int N = 5005;
char s[N]; int n, T;
char t[] = "aatcoder";
int main() {
	for (read(T); T; T--) {
		scanf ("%s", s + 1), n = strlen(s + 1);
		bool fl = 0; int tp = 8;
		for (int i = 1;i <= min(n, 7); i++)
			if (s[i] > t[i]) { write(0); fl = 1; break; }
			else if (s[i] < t[i]) { tp = i; break; }
		if (fl) continue;
		fl = 0;
		for (int i = 1;i <= n; i++) if (s[i] != 'a') fl = 1;
		if (!fl) { write(-1); continue; }
		if (tp == 8 && n > 7) { write(0); continue; }
		if (tp > 2) { write(1); continue; }
		for (int i = 1;i <= n; i++) if (s[i] != 'a') {
			write(s[i] > 't' ? i - 2 : i - 1); break;
		}
	}
	return 0;
}

/*

atcodera

*/

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < n; ++i)
ll gcd(ll a, ll b){
  if(a%b == 0) return b;
  else return gcd(b,a%b);
}

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

int main(){
  int h,w,x,y;
  cin >> h >> w >> x >> y;
  x--;
  y--;
  vector<string> s(h);
  rep(i,h) cin >> s[i];
  int cnt = 0;
  for(int i=x;i<h;i++){
    if(s[i][y] == '#') break;
    if(s[i][y] == '.') cnt++;
  }
  for(int i=x;i>=0;i--){
    if(s[i][y] == '#') break;
    if(s[i][y] == '.') cnt++;
  }
  for(int j=y;j<w;j++){
    if(s[x][j] == '#') break;
    if(s[x][j] == '.') cnt++;
  }
  for(int j=y;j>=0;j--){
    if(s[x][j] == '#') break;
    if(s[x][j] == '.') cnt++;
  }
  cout << cnt - 3 << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll> pql;
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, k, n) for(ll i = ll(k); i <= ll(n); i++)
#define rep3(i, n, k) for(ll i = ll(n); i >= ll(k); i--)
#define all(v) (v).begin(), (v).end()
ll mod(ll a, ll b) {if(b == 0) return 0; return (a % b + b) % b;}
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e3;
const ld eps = 1e-9;
const char newl = '\n';

vl parent(MAX), depth(MAX);

ll find(ll x) {if(parent[x]==x) return x; return parent[x] = find(parent[x]);}

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

  if(depth[x] < depth[y]) {
    parent[x] = y;
  }else {
    parent[y] = x;
    if(depth[x] == depth[y]) depth[x]++;
  }
}

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

  cout << fixed << setprecision(15);

  ll n;
  cin >> n;
  vl x(n), y(n);
  rep(i, n) cin >> x[i] >> y[i];

  ll ok=0, ng=40001;
  while(ng-ok>1) {
    ll RR = (ok+ng)/2;

    rep(i, n) {parent[i] = i; depth[i] = 0;}
    rep2(i, 200-99, 200+99) {parent[i] = 200; depth[i] = 0;}
    rep2(i, 400-99, 400+99) {parent[i] = 400; depth[i] = 0;}

    rep(i, n) {
      if((100+y[i])*(100+y[i]) < RR) unite(i, x[i]+200);
      if((100-y[i])*(100-y[i]) < RR) unite(i, x[i]+400);
    }

    rep(i, n-1) rep2(j, i+1, n-1) {
      ll dx = x[j]-x[i], dy = y[j]-y[i];
      if(dx*dx+dy*dy < RR) unite(i, j);
    }

    if(find(200)==find(400)) ng = (ok+ng)/2;
    else ok = (ok+ng)/2;
  }
  cout << sqrt(ok)/2 << newl;
  return 0;
}

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

vector<bool> seen;
vector<int> color;
vector<int> ans;
vector<int> c;
Graph G;

void dfs(const Graph &G, int v) {
    // cout << "v = " << v  << " " << color[c[v]] << endl;
    seen[v] = true;
    if (color[c[v]] == 0) ans.push_back(v+1);
    color[c[v]]++;
    // cout << "v = " << v  << " " << " c[v] = " << c[v] << " " << " color[v] = "  <<  color[c[v]] << endl;

    for (auto next_v : G[v]) {
        if (seen[next_v]) continue;
        dfs(G, next_v); // 再帰的に探索
    }
    color[c[v]]--;
}
int main(void) {
    int n;
    cin >> n;
    c.resize(n);
    rep(i, n) cin >> c[i];
    G.resize(n);
    rep(i, n-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    seen.assign(n, false);
    color.assign(100010, 0);
    dfs(G, 0);

    sort(ans.begin(), ans.end());
    rep(i, (int)ans.size()) {
        cout << ans[i] << endl;
    }
    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) {
  T g = gcd(n, m);
  return (n / g) * m;
}

// 重複を消す。計算量は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"

// generated by online-judge-template-generator v4.7.1 (https://github.com/online-judge-tools/template-generator)
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << min(a, min(b, min(c, d))) << endl;
}

#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int t,i,arr[4];
    for(i=0;i<4;i++)
    cin>>arr[i];

    sort(arr,arr+i);
    cout<<arr[0]<<"\n";
    return 0;
}


// Parasparopagraho Jīvānām

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

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

typedef long long ll ;
typedef long double ldb ;

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

typedef vector<int> vi ;
typedef vector<ll> vll ;
typedef vector<pii> vpi ;
typedef vector<pll> vpl ;
typedef vector<int,pil> edges ;
typedef vector<vi> matrix ;
typedef priority_queue<int> pqu ;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update> ;

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

#define mp make_pair
#define eb emplace_back
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define ins insert
#define bk back
#define con continue
#define lbd lower_bound
#define ubd upper_bound

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)

#define pr cout << // I don't like this but my laptop's 'O' key is not functioning well

/* Careful when using long long
__builtin_clz(int x) {} //: the number of zeros at the beginning of the number
__builtin_ctz(int x) {} //: the number of zeros at the end of the number
__builtin_popcount(int x) {} //: the number of ones in the number
__builtin_parity(int x) {} //: the parity (even or odd) of the number of ones */

const int mod1 = 1000000007 ;
const int mod2 = 998244353 ;
const ll  infl = 4e18 ;
const int infi = 2e9 ;
const int maxn = 2e5 + 5 ;
const int block = 500 ;
const int logn = 31 ;
const int alpha = 27 ;
const ldb pi = acos(-1) ;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) ;
int rng_lr(int a, int b)
{
    int ret ;
    ret = uniform_int_distribution<int>(a, b)(rng) ;
    return ret ;
    // For shuffling use shuffle(all, rng) ;
}

ll modpow(ll a, ll b, int MOD) { ll res = 1 ; while(b) { if(b&1) { res = res*a ; res %= MOD ; } a *= a ; a %= MOD ; b >>= 1 ; } return res%MOD ; }
void upmin(int &a, int b) { if(a < b) { a = b ; } }
void relax(int &a, int b) { if(a > b) { a = b ; } }
ll add(ll a, ll b, int MOD) { a += b ; if(a >= MOD) { a -= MOD ; } return  a ; }
ll sub(ll a, ll b, int MOD) { a -= b ; if(a < 0) { a += MOD ; } return a ; }
ll mul(ll a, ll b, int MOD) { b %= MOD ; a *= b ; a %= MOD ; return a ; }
ll inverse(ll a, ll MOD) { a = modpow(a, MOD - 2, MOD) ; return a ; }
ll lcm(ll a, ll b) { ll ret ; ll g = __gcd(a, b) ; ret = a/g ; ret = ret*b ; return ret ; }
int icast(char ch) { return int(ch-'a') ; }
void hyn(int a, int b) { if(a == b) cout << "YES\n" ; else cout << "NO\n" ; }
void pyd(int a, int b) { if(a == b) cout << "First\n" ; else cout << "Second\n" ; }

// Check constraints + overflows + types in typedef
int n ;
char g[102][102] ;
int main()
{
    ios::sync_with_stdio(false) ;
    cin.tie(NULL) ;
    cin >> n ;
    rep(i,0,n-1) {
      rep(j,0,n-1) {
        cin >> g[i][j] ;
      }
    }
    int dist[n + 1][n + 1] ;
    rep(i,1,n) {
      rep(j,1,n) {
        dist[i][j] = infi ;
      }
    }
    rep(i,1,n) {
      dist[i][i] = 0 ;
    }
    rep(i,1,n) {
      rep(j,1,n) {
        if(g[i - 1][j - 1] == '1') {
          dist[i][j] = 1 ;
        }
      }
    }
    rep(p,1,n) {
      rep(i,1,n) {
        rep(j,1,n) {
          if(dist[i][p] < infi && dist[p][j] < infi) {
            dist[i][j] = min(dist[i][j], dist[i][p] + dist[p][j]) ;
          }
        }
      }
    }
    int ances[n + 1] ;
    rep(i,1,n) {
      ances[i] = 0 ;
      rep(j,1,n) {
        if(dist[j][i] < infi) {
          ances[i]++ ;
        }
      }
    }
    ldb ev = (ldb)0 ;
    rep(i,1,n) {
      ldb prob = ((ldb)1)/((ldb)ances[i]) ;
      ev = ev + prob ;
    }
    cout << fixed << setprecision(10) ;
    pr ev << "\n" ;
    return 0 ;
}

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

bool flg[100][100];
int main() {
	int n; cin >> n;
	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < n; ++j) {
			char c; cin >> c;
			flg[i][j] = (c == '1');
		}
		flg[i][i] = true;
	}
	for(int k = 0; k < n; ++k) {
		for(int i = 0; i < n; ++i) {
			for(int j = 0; j < n; ++j) {
				flg[i][j] |= (flg[i][k] & flg[k][j]);
			}
		}
	}
	double ans = 0;
	for(int i = 0; i < n; ++i) {
		int cnt = 0;
		for(int j = 0; j < n; ++j) {
			cnt += flg[j][i];
		}
		ans += 1.0 / (double)cnt;
	}
	printf("%.15f\n", ans);
	return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,mmx,avx")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
#define PB push_back
#define MP make_pair
#define endl "\n"
#define fst first
#define snd second
const int UNDEF = -1;
const int INF=1<<30;
template<typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; }
template<typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ? aa = bb, true : false; }
typedef pair<ll,ll> pll;typedef vector<ll> vll;typedef pair<int,int> pii;typedef vector<int> vi;typedef vector<vi> vvi;typedef vector<pii> vpii;typedef vector<pll> vpll;
template<typename T> void makeunique(vector<T> &vx) {sort(vx.begin(),vx.end());auto it=unique(vx.begin(),vx.end());vx.resize(std::distance(vx.begin(),it));}
const int mn=200000+4;

ll dfs(vvi const & tree, int u, int p, int depth) {
  ll res = ((ll) depth << 32) + u;
  for (int v : tree[u]) {
          if (v != p) {
            res = max(res, dfs(tree, v, u, depth + 1));
          }
  }
  return res;
}

pii diameter(vvi const & tree) {
  int furthestVertex = (int) dfs(tree, 1, -1, 0);
  return MP((int) (dfs(tree, furthestVertex, -1, 0)), furthestVertex);
}

vi order;
vvi g;
bitset<mn> special;
int id=1;
void go(int x, int p) {
  order[x]=id;
  ++id;
  for (auto &y:g[x]) {
    if (y==p) continue;
    go(y,x);
  }
  if (!special[x]) {
    ++id;
  }
}

vi vpar;
void makepar(int x, int p) {
  vpar[x]=p;
  for (auto &y:g[x]) {
    if (y==p) continue;
    makepar(y,x);
  }
}

int getdist(int x, int p, int dest) {
  if (x==dest) return 0;
  for (auto &y:g[x]) {
    if (y==p) continue;
    int got=getdist(y,x,dest);
    if (got!=-1) return got+1;
  }
  return -1;
}

void solve(long long n, std::vector<long long> A, std::vector<long long> B){
  g.resize(n+1); vpar.resize(n+1); order.resize(n+1);
  for (int i=0;i<A.size();i++) {
    int x=A[i],y=B[i];
    g[x].PB(y);
    g[y].PB(x);
  }
  pii diam=diameter(g);
  int src=diam.fst,dest=diam.snd;
  makepar(src,-1);
  //printf("src:%d dest:%d\n",src,dest);
  {
    int x=dest;
    while(x!=-1) {
      //printf("x:%d\n",x);
      special[x]=true;
      x=vpar[x];
    }
  }
  for (int x=1;x<=n;x++) sort(g[x].begin(),g[x].end(),[&](int x,int y) {return MP(special[x],x) < MP(special[y],y);} );
  go(src,-1);
  for (int x=1;x<=n;x++) printf("%d ",order[x]);
  printf("\n");
  //for (int x=1;x<=n;x++) for (int y=1;y<=n;y++) {
  //  if (abs(order[x]-order[y]) < getdist(x,-1,y)) {
  //    printf("x:%d y:%d order:%d %d dist:%d\n",x,y,order[x],order[y],getdist(x,-1,y));fflush(stdout);
  //    assert(0);
  //  }
  //}
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N-1);
    std::vector<long long> B(N-1);
    for(int i = 0 ; i < N-1 ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
    }
    solve(N, std::move(A), std::move(B));
    return 0;
}

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<random>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
typedef vector<vt>vvt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const long double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

int n,c;
vi d,out;
vvi G;
void dfs(int a,int p,int t){
	d[a]=t;
	for(auto i:G[a]){
		if(i==p)continue;
		dfs(i,a,t+1);
	}
}
void dfs2(int a,int p){
	out[a]=c;
	for(auto i:G[a]){
		if(d[i]<d[a])continue;
		if(i==p)continue;
		c++;
		dfs2(i,a);
		c++;
	}
	for(auto i:G[a]){
		if(d[i]>d[a])continue;
		if(i==p)continue;
		c++;
		dfs2(i,a);
		c++;
	}
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin>>n;
	G=vvi(n);
	rep(i,n-1){
		int a,b;
		cin>>a>>b;
		a--;b--;
		G[a].pb(b);
		G[b].pb(a);
	}
	out=d=vi(n,-1);
	dfs(0,-1,0);
	int r,ma=0;
	rep(i,n)cmax(ma,d[i]);
	rep(i,n)if(ma==d[i]){
		r=i;
	}
	d=vi(n,-1);
	c=1;
	dfs(r,-1,0);
	ma=0;
	rep(i,n)cmax(ma,d[i]);
	rep(i,n)if(ma==d[i]){
		r=i;
	}

	dfs2(r,-1);
	show1d(out);
}


#pragma region templates
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
template<typename T> using PQ = priority_queue<T>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007; // 998244353;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const ld PI = acos((ld)-1);
constexpr ll dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
inline void Yes() { cout << "Yes" << ENDL; }
inline void No() { cout << "No" << ENDL; }
inline void YES() { cout << "YES" << ENDL; }
inline void NO() { cout << "NO" << ENDL; }

template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template <typename T>
vector<T> finddivisor(T x) {  //整数xの約数(xを含む)
  vector<T> divisor;
  for(T i = 1; (i * i) <= x; i++) {
    if(x % i == 0) {
      divisor.push_back(i);
      if(i * i != x) { divisor.push_back(x / i);}
    }
  }
  sort(divisor.begin(), divisor.end());
  return divisor;
}

template <typename T> V<T> prefix_sum(const V<T>& v) {
  int n = v.size();
  V<T> ret(n + 1);
  rep(i, 0, n) ret[i + 1] = ret[i] + v[i];
  return ret;
}

template<typename T>
T rand(T l,T r){
  static random_device rd;
  static mt19937 g(rd());
  return uniform_int_distribution<T>(l,r)(g);
}

template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(auto&& x: vec) is >> x;
  return is;
}

template<typename T,typename Y>
ostream& operator<<(ostream& os,const pair<T,Y>& p){
  return os<<"{"<<p.fs<<","<<p.sc<<"}";
}

template<typename T> ostream& operator<<(ostream& os,const V<T>& v){
  os<<"{";
  for(auto e:v)os<<e<<",";
  return os<<"}";
}

template<typename ...Args>
void debug(Args&... args){
  for(auto const& x:{args...}){
    cerr<<x<<' ';
  }
  cerr<<ENDL;
}
#pragma endregion templates

signed main(){
  cin.tie(0);cerr.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  V<int> a(1002,0),b=a;
  ll n,m;cin>>n>>m;
  rep(i,0,n){
    ll x;cin>>x;
    a[x]=1;
  }
  rep(i,0,m){
    ll x;cin>>x;
    b[x]=1;
  }

  rep(i,1,1001)if(a[i]^b[i])cout<<i<<" ";
  cout<<ENDL;

}
//(・_・)(・_・)(・_・)(・_・)
//CHECK overflow,what to output?
//any other simpler approach?

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

int main() {
    int n,m;
    cin >> n >> m;
    vector<int> vec (n);
    for(int i=0; i<n; i++){
        int x;
        cin >> x;
        vec.at(i) = x;
    }
    for(int i=0; i<m; i++){
        int x;
        cin >> x;
        vec.push_back(x);
    }
    sort(vec.begin(),vec.end());
    reverse(vec.begin(),vec.end());
    stack<int> ans;
    for(int i=0; i<vec.size(); i++){
        if(ans.empty()){
            ans.push(vec.at(i));
        }
        else if(vec.at(i) == ans.top()){
            ans.pop();
        }
        else{
            ans.push(vec.at(i));
        }
    }
    while(!ans.empty()){
        cout << ans.top() << " ";
        ans.pop();
    }
}


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

#define  all(x)        (x).begin(),(x).end()
#define  pb            push_back
#define  lb            lower_bound
#define  ub            upper_bound
#define  fi            first
#define  se            second
#define  pii           pair<int,int>
#define  fastIO        ios_base::sync_with_stdio(false); cin.tie(NULL);
#define  mp            make_pair
#define endl '\n'
#define int long long

typedef double db;
typedef long long ll;

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

int ncr(int n, int r) {
	r = min(r, n - r);
	int ans = 1;

	for (int i = 1; i <= r; i++) {
		ans *= (n - r + i);
		ans /= i;
	}
	return ans;
}

void solve() {

	int a, b, k; cin >> a >> b >> k;

	int n = (a + b);
	string ans = "";
	--k;

	while (a && b) {

		//number of remaining string if we put 'a' here
		int rem = ncr(a + b - 1, b);

		if (k >= rem) {
			k -= rem;
			ans += "b";
			--b;
		}
		else {
			ans += "a";
			--a;
		}
	}

	ans += string(a, 'a') + string(b, 'b');
	cout << ans;
}

signed main() {

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

	fastIO

	int t = 1;
	// cin >> t;

	for (int tt = 1; tt <= t; tt++) {
		solve();
	}
}

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

ll c[32][32];

signed main(){
  rep(i,31){
    c[0][i]=1;
  }
  rep(i,31){
    c[i][0]=1;
  }
  rep(i,31) rep(j,31){
    if(i==0||j==0) continue;
    c[i][j]=c[i-1][j]+c[i][j-1];
  }
  ll a,b,k;
  cin>>a>>b>>k;

  ll len=a+b;
  rep(i,len){
    //cout<<a<<" "<<b<<" "<<k<<endl;
    if(b==0){
      cout<<"a";
      continue;
    }
    if(a==0){
      cout<<"b";
      continue;
    }
    if(k>c[a-1][b]){
      cout<<"b";
      k-=c[a-1][b];
      b--;

    }
    else{
      cout<<"a";
      a--;
    }
  }
  cout<<endl;
  return 0;
}


#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
typedef long long ll;
using namespace std;

	#define sim template < class c
	#define ris return * this
	#define dor > debug & operator <<
	#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
	sim > struct rge { c b, e; };
	sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
	sim > auto dud(c* x) -> decltype(cerr << *x, 0);
	sim > char dud(...);
	struct debug {
			// #ifdef LOCAL
		~debug() { cerr << endl; }
		eni(!=) cerr << boolalpha << i; ris; }
		eni(==) ris << range(begin(i), end(i)); }
		sim, class b dor(pair < b, c > d) {
			ris << "(" << d.first << ", " << d.second << ")";
		}
		sim dor(rge<c> d) {
			*this << "[";
			for (auto it = d.b; it != d.e; ++it)
				*this << ", " + 2 * (it == d.b) << *it;
			ris << "]";
		}

			// sim dor(const c&) { ris; }
	};
	#ifdef ASJKD
}
	#endif
	#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
	#define read(x) for(auto &i : (x)){cin>>i;}
	#define all(x) begin(x), end(x)
	#define pb push_back
#define maxn 1500
ll mod = 998244353;
int INF = 1e9;
ll INF64 = 1e18;

long long binpow(long long a, long long b, long long m) {
	a %= m;
	long long res = 1;
	while (b > 0) {
		if (b & 1){
			res = res * a % m;
		}
		a = a * a % m;
		b >>= 1;
	}
	return res;
}

bool check(vector<pair<int, int>> &a, long double pos, int d, int h){
	// myx = 0
	// myy = pos
	int n =a.size();
	long double coef = (long double)(h-pos) / ((long double)d);
	long double c = pos;
	// debug() << imie(coef) imie(c);
	bool ok = 1;
	for(int i=0;i<n;i++){

		ok &= ((coef * a[i].first) + c) > (double)a[i].second;
		if(!ok) break;
	}
	return ok;
}
double eps = 1e-6;
void test_case(int tnum){
	int n, d, h;
	cin>>n>>d>>h;
	vector<pair<int, int>> a(n);
	for(int i=0;i<n;i++){
		cin>>a[i].first>>a[i].second;
	}
	double hi = 1000;
	double lo = 0;
	while(hi-eps > lo){
		double mid = (hi + lo) / 2;
		if(check(a, mid, d, h)){
			hi = mid;
		} else{
			lo = mid;
		}
	}
	// debug() << imie(check(a, 2, d, h));
	cout <<setprecision(14) << fixed<< hi << '\n';
}
int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(false);
	int t=1;
	// cin>>t;
	for(int test=1;test<=t;test++){
		test_case(test);
	}
	return 0;
}

#include <iostream>
#include <string>
#include <vector>
//#include <math.h>       /* tan */
#include <cmath>
#include <algorithm>    // std::max

using namespace std;

int main(){
  int N;
  long D;
  long H;
  cin >> N >> D >> H;

  vector<vector<long>> q(N,vector<long>(2));
  for(int i = 0; i < N; i++){
    cin >> q[i][0] >> q[i][1];
  }

  double max = 0;
  for(auto h : q){
    double angle = atan2((H - h[1]), (D - h[0]));

    double t = D * tan(angle);
    double tmp = H - t;
    if(max < tmp){
      max = tmp;
    }
  }

  cout << max << endl;

  return 0;
}


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

void solve(){

	int r,c ;
	cin>>r>>c ;

	char arr[r][c] ;

	rep(i,r){
		rep(j,c){
			cin>>arr[i][j] ;
		}
	}

	ll count=0 ;

	rep(i,r){
		rep(j,c-1){
			if(arr[i][j]=='.' && arr[i][j+1]=='.'){
				count++ ;
			}
		}
	}

	rep(i,r-1){
		rep(j,c){
			if(arr[i][j]=='.' && arr[i+1][j]=='.'){
				count++ ;
			}
		}
	}

	cout<<count ;
}

int main(){

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

	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(false);

	int y ;

	y=1 ;
	//cin>>y ;

	while(y--)
	{
		solve() ;
	}

}


#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

const ll INF = INT_MAX / 2;

// {a, t}
vector<pair<ll, int>> fs;

ll calc(ll x, const int N) {
    ll ans = x;
    for (int i = 0; i < N; i++) {
        const ll a = fs[i].first;
        const int t = fs[i].second;
        if (t == 1) {
            ans += a;
        } else if (t == 2) {
            ans = max(ans, a);
        } else {
            ans = min(ans, a);
        }
    }
    return ans;
}

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

    fs.resize(N);
    for (int i = 0; i < N; i++) {
        int a, t;
        cin >> a >> t;
        fs[i] = make_pair(a, t);
    }

    int Q;
    cin >> Q;

    const ll v_min = calc(-INF, N);
    const ll v_max = calc(INF, N);
#ifdef DEBUG
    printf("v_min: %lld, v_max: %lld\n", v_min, v_max);
#endif

    ll acc = 0;
    for (int i = 0; i < N; i++) {
        const ll a = fs[i].first;
        const int t = fs[i].second;
        if (t == 1) {
            acc += a;
        }
    }

    for (int i = 0; i < Q; i++) {
        ll x;
        cin >> x;
        if (x < v_min - acc) {
            printf("%lld\n", v_min);
        } else if (v_max - acc < x) {
            printf("%lld\n", v_max);
        } else {
            printf("%lld\n", x + acc);
        }
    }

    return 0;
}

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

constexpr int N = 100005;

int n;
std::vector<long long> a[3];
std::string s;

int main() {
    std::ios::sync_with_stdio(false), std::cin.tie(nullptr);
    std::cin >> n;
    for (int i = 1; i <= n << 1; ++i) {
        long long x;
        std::cin >> x >> s;
        if (s[0] == 'R') a[0].push_back(x);
        else if (s[0] == 'G') a[1].push_back(x);
        else a[2].push_back(x);
    }
    int x = -1, y = -1;
    for (int i = 0; i < 3; ++i) {
        if (a[i].size() & 1) {
            if (x != -1) y = i;
            else x = i;
        }
        std::sort(a[i].begin(), a[i].end());
    }
    if (x == -1) return std::cout << "0\n", 0;
    auto f = [](int x, int y) -> long long {
        long long ans = 1e18;
        for (long long i : a[x]) {
            long long t = std::lower_bound(a[y].begin(), a[y].end(), i) - a[y].begin();
            if (t != a[y].size()) ans = std::min(ans, std::abs(a[y][t] - i));
            if (t) ans = std::min(ans, std::abs(i - a[y][t - 1]));
        }
        return ans;
    };
    int z = 3 - x - y;
    long long ans = f(x, y);
    long long t1 = f(x, z), t2 = f(y, z);
    if (t1 < 1e18) ans = std::min(ans, t1 + t2);
    std::cout << ans << '\n';
    return 0;
}


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

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

#define sz(x) (int)(x).size()

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

#ifdef XVENOM
  #define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: " << dbg_str(__VA_ARGS__)
#else
  #define dbg(...) ;
#endif
template <typename U, typename V> string to_string (pair<U, V>);
string to_string (const char* e) { return "\"" + string(e) + "\""; }
string to_string (string& e) { return "\"" + e + "\""; }
string to_string (char e) { return "\'" + string(1, e) + "\'"; }
string to_string (bool e) { return e ? "true" : "false"; }
template <typename T> string to_string (T e) {
  string s = "[ "; for (auto& x : e) s += to_string(x) + " "; return s + "]";
}
template <typename U, typename V> string to_string (pair<U, V> e) {
  return "(" + to_string(e.first) + ", " + to_string(e.second) + ")";
}
string dbg_str () { return " \n"; }
template <typename U, typename... V> string dbg_str (U u, V... v) {
  return " " + to_string(u) + dbg_str(v...);
}
/* *** */
const ll Mod = 1000000007;
/* --- */
using MT = decay<decltype(Mod)>::type;

MT inverse (MT a, MT n) {
  MT u = 0, v = 1;
  while (a != 0) {
    MT q = n / a;
    swap(u, v); v -= q * u;
    swap(n, a); a -= q * n;
  }
  assert(n == 1);
  return u;
}

class mint {
private: MT x;
public:
  void normalize() {
    if (x >= Mod || x < 0) x = (x % Mod) + Mod;
    if (x >= Mod) x -= Mod;
  }
  mint(): x(0) {}
  mint(MT z): x(z) { normalize(); }
  const MT& operator() () const { return x; }

  mint operator+ (const mint& z) { MT r = x + z(); if (r >= Mod) r -= Mod; return mint(r); }
  mint operator- (const mint& z) { MT r = x - z(); if (r < 0) r += Mod; return mint(r); }
  mint operator* (const mint& z) { MT r = x * z(); if (r >= Mod) r %= Mod; return mint(r); }
  mint operator/ (const mint& z) { return (*this) * mint(inverse(z(), Mod)); }

  mint operator+= (const mint& z) { (*this) = (*this) + z; return (*this); }
  mint operator-= (const mint& z) { (*this) = (*this) - z; return (*this); }
  mint operator*= (const mint& z) { (*this) = (*this) * z; return (*this); }
  mint operator/= (const mint& z) { (*this) = (*this) / z; return (*this); }

  friend std::istream& operator>> (std::istream&, mint&);
};

std::istream& operator>> (std::istream& stream, mint& p) {
  MT v; stream >> v; p.x = v; p.normalize(); return stream;
}
std::ostream& operator<< (std::ostream& stream, const mint& p) { return stream << p(); }
mint operator+ (const MT& p, const mint& q) { return mint(p) + q; }
mint operator- (const MT& p, const mint& q) { return mint(p) - q; }
mint operator* (const MT& p, const mint& q) { return mint(p) * q; }
mint operator/ (const MT& p, const mint& q) { return mint(p) / q; }
string to_string (const mint& p) { return to_string(p()); }

mint powMod (mint a, MT b) {
  mint res = 1, x = a;
  while (b > 0) {
    if (b & 1) res *= x;
    x *= x;
    b >>= 1;
  }
  return res;
}
/* --- */
const int N = 2000 + 66;
mint f[N][N], g[N][N], h[N][N], ans[N][N];
string grid[N];
int n, m;

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

  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    string t; cin >> t;
    grid[i] = " " + t;
  }

  f[1][1] = g[1][1] = h[1][1] = ans[1][1] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (i == 1 && j == 1) continue;
      if (grid[i][j] == '#') continue;
      ans[i][j] = f[i - 1][j] + g[i][j - 1] + h[i - 1][j - 1];
      f[i][j] = f[i - 1][j] + ans[i][j];
      g[i][j] = g[i][j - 1] + ans[i][j];
      h[i][j] = h[i - 1][j - 1] + ans[i][j];
    }
  }
  cout << ans[n][m] << '\n';
}

#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
typedef long long ll;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);
const int N = 100005;

int n, d;
int a[N], b[N];

int minu[N];

vector<int> v[N];

void solv()
{
    scanf("%d%d", &n, &d);
    for (int i = 1; i <= n; ++i)
        scanf("%d", &a[i]);
    for (int i = 1; i <= n; ++i)
        scanf("%d", &b[i]);

    a[n + 1] = b[n + 1] = d + 1;

    for (int i = 1; i <= n; ++i)
        minu[i] = N;

    map<int, int> mp;
    for (int i = 0; i <= n + 1; ++i)
    {
        mp[a[i] - i] = i;
        if (mp.find(b[i] - i) != mp.end())
        {
            if (mp[b[i] - i] != i)
                v[mp[b[i] - i]].push_back(i);
            minu[i] = min(minu[i], i - mp[b[i] - i]);
        }
    }

    mp.clear();
    for (int i = n + 1; i >= 0; --i)
    {
        mp[a[i] - i] = i;
        if (mp.find(b[i] - i) != mp.end())
        {
            if (mp[b[i] - i] != i)
                v[mp[b[i] - i]].push_back(i);
            minu[i] = min(minu[i], mp[b[i] - i] - i);
        }
    }

    for (int i = 0; i <= n + 1; ++i)
    {
        if (minu[i] == N)
        {
            printf("-1\n");
            return;
        }
    }

    ll ans = 0;
    for (int i = 0; i <= n + 1; ++i)
    {
        if (v[i].empty())
            continue;
        sort(all(v[i]));
        if (v[i][0] < i)
            ans += (i - v[i][0]);
        if (v[i].back() > i)
            ans += (v[i].back() - i);
    }

    printf("%lld\n", ans);
}

int main()
{
    #ifdef SOMETHING
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #endif // SOMETHING
    //ios_base::sync_with_stdio(false), cin.tie(0);
    solv();
    return 0;
}


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

int main(void) {
    int N;
    cin >> N;
    vector<int> C(N);
    for (int i = 0; i < N; i++) {
        char c;
        cin >> c;
        if (c == 'B') C[i] = 0;
        else if (c == 'W') C[i] = 1;
        else C[i] = 2;
    }
    vector<vector<int>> ncr = {
        {1, 0, 0},
        {1, 1, 0},
        {1, 2, 1}
    };
    int ans = 0;
    for (int i = 0; i < N; i++) {
        int r = i;
        int n = N - 1;
        int tmp = 1;
        while (n != 0) {
            int j = n % 3;
            int k = r % 3;
            n /= 3;
            r /= 3;
            tmp *= ncr[j][k];
            tmp %= 3;
        }
        ans += tmp * C[i];
        ans %= 3;
    }
    if (N % 2 == 0) ans = ans * -1;
    if (ans < 0) ans += 3;
    if (ans == 0) cout << "B" << endl;
    else if (ans == 1) cout << "W" << endl;
    else cout << "R" << endl;
}

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define vi vector<int>
#define mk make_pair
#define vll vector<long long >
#define loop(i,a,b) for(int i=a;i<=b;i++)
#define loopr(i,a,b) for(int i=b;i>=a;i--)
#define vii vector<vector<int>>
#define ll long long
void io()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int main()
{

	ll n;
	cin >> n;
	ll i = 1;
	ll ans = 0;
	while (i * i <= (2 * n)) {

		if ((2ll * n) % i == 0) {
			ll  no = ((2ll * n) / i ) + 1 - n;
			if (no % 2 == 0)
				ans += 2;
			no = i + 1 - n;
			if (no % 2 == 0)
				ans += 2;
			// cout << i << endl;
		}
		i++;
	}

	cout << ans << endl;

	return 0;
}


#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define m_k make_pair
using namespace std;
const int N=1e5+100;
int T,n,a[N],b[N],w,t[N];
signed main()
{
	scanf("%d",&T);
	while (T--)
	{
		scanf("%d",&n);
		for (int i=1;i<=n;i++) scanf("%d",&a[i]),b[i]=a[i];
		if (n==1)
		{
			printf("Second\n");
			continue;
		}
		sort(b+1,b+1+n);
		w=unique(b+1,b+1+n)-b-1;
		for (int i=1;i<=n;i++) a[i]=lower_bound(b+1,b+1+w,a[i])-b;
		for (int i=1;i<=n;i++) t[i]=0;
		for (int i=1;i<=n;i++) t[a[i]]++;
		int cnt=0;
		for (int i=1;i<=n;i++) cnt+=(t[i]&1);
		if (n%2==0)
		{
			if (!cnt) printf("Second\n");
			else printf("First\n");
		}
		else
		{
			if (cnt==1) printf("First\n");
			else printf("Second\n");
		}
	}
}

#include<bits/stdc++.h>

using namespace std;

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

#define F first
#define S second

const int MOD = 1e9 + 7;//XXX
const int C = 26;//XXX

void add(int &x, int y){
	x += y;
	while (x >= MOD) x -= MOD;
	while (x < 0) x += MOD;
}

int fix(int x){
	while (x >= MOD) x -= MOD;
	while (x < 0) x += MOD;
	return x;
}

int pw(int a, int b){
	int ret = 1;
	while (b){
		if (b & 1)
			ret = 1ll*ret*a%MOD;
		b >>= 1;
		a = 1ll*a*a%MOD;
	}
	return ret;
}

const int MAXN = 1e6 + 10;

int n, a[MAXN];
set<int> st;

vector<int> factor(int X) {
	vector<int> vec;
	for(int i = 1; i*i <= X; i++) {
		if(X % i == 0) {
			for(int x : {i, X/i})
				if(x <= a[0])
					vec.push_back(x);
		}
	}
	return vec;
}

bool check(int x) {
	int cur = -1;
	for(int j = 0; j < n; j++) {
		if(a[j] % x == 0) {
			if(~cur) {
				cur = __gcd(cur, a[j]);
			} else cur = a[j];
		}
	}
	return cur == x;
}

void solve() {
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a+n);
	vector<int> vec;
	for(int i = 0; i < n; i++) {
		vector<int> sec = factor(a[i]);
		for(int x : sec)
			vec.push_back(x);
	}
	sort(vec.begin(), vec.end());
	vec.resize(unique(vec.begin(), vec.end())-vec.begin());
	int ans = 0;
	for(int x : vec) if(check(x)) ++ans;
	cout << ans << endl;
}

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

	int te = 1;
	//cin >> te;
	for (int w = 1; w <= te; w++){
		//cout << "Case #" << w << ": ";
		solve();
	}
	return 0;
}


//雪花飄飄北風嘯嘯
//天地一片蒼茫

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

int n,m;
string grid[105];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin.exceptions(ios::badbit | ios::failbit);

	cin>>n>>m;
	rep(x,0,n) cin>>grid[x];

	int ans=0;

	rep(x,0,n-1){
		rep(y,0,m) if (grid[x][y]=='.' && grid[x+1][y]=='.') ans++;
	}

	rep(x,0,n){
		rep(y,0,m-1) if (grid[x][y]=='.' && grid[x][y+1]=='.') ans++;
	}

	cout<<ans<<endl;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
int main(void){
    int h,w,ans=0;
    cin >> h >> w;
    char m[h][w];
    rep(i,h)rep(j,w) cin >> m[i][j];
    rep(i,h)rep(j,w){
        if(m[i][j]=='#') continue;
        rep(k,4){
            int nowx = i+dx[k],nowy = j+dy[k];
            if(nowx<0||h<=nowx||nowy<0||w<=nowy) continue;
            if(m[nowx][nowy]=='.') ans++;
        }
    }
    cout << ans/2 << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

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

    ll n; cin >> n;
    ll a[n]; zep(i, 0, n)cin >> a[i];
    ll b[n]; zep(i, 0, n)cin >> b[i];

    ll mx = INF, mn = 0;
    zep(i, 0, n){
        mx = min(mx, b[i]);
        mn = max(mn, a[i]);
    }

    print(max(mx - mn + 1, 0LL))

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
void init(void)
{
    cin.tie(0) ;
    cin.sync_with_stdio(0) ;
}
int main()
{
    init() ;
    int n , temp ;
    bool flag = true ;
cin >> n;
int a[n] , b [n] ;
for(int i = 0 ; i< n ;i++) cin >> a[i] ;
for(int i = 0 ; i< n ;i++) cin >> b[i] ;
pair<int,int> minmax ;
minmax.first = 0 ;
minmax.second = 10001 ;
for(int i = 0 ;i<n;i++)
{
    if(b[i] >= minmax.first)
    {
        if(a[i]>minmax.first) minmax.first = a[i] ;
        if(b[i]<minmax.second) minmax.second = b[i] ;
    }else
    {
        flag = false ;
        cout<<0 ;
        break;
    }

}
if(flag == true ) cout << minmax.second - minmax.first +1 ;
    return 0;
}


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

int n,t,a[45];
vector<int> c[2];

void dfs(int now,int r,int s,int k)
{
	if(s>t) return;
	if(now==r+1)
	{
		c[k].push_back(s);
		return;
	}
	dfs(now+1,r,s+a[now],k);
	dfs(now+1,r,s,k);
}

signed main()
{
	ios::sync_with_stdio(0);
	cin>>n>>t;
	for(int i=1;i<=n;i++) cin>>a[i];
	dfs(1,n/2,0,0);
	if(n/2+1<=n) dfs(n/2+1,n,0,1);
	c[0].push_back(0);
	c[1].push_back(0);
	sort(c[1].begin(),c[1].end());
	int ans=0;
	for(int i=0;i<c[0].size();i++)
	{
		int it=upper_bound(c[1].begin(),c[1].end(),t-c[0][i])-c[1].begin()-1;
//		cout<<it<<' '<<c[1][it]<<endl;
		ans=max(c[0][i]+c[1][it],ans);
	}
	cout<<ans<<endl;

}

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

int main(){
    int n, T;
    cin >> n >> T;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<ll> s, t;
    s = t = {0};
    rep(i,n){
        for (int j = s.size()-1; j >= 0; --j){
            s.push_back(s[j]+a[i]);
        }
        swap(s,t);
    }
    sort(s.begin(), s.end());
    ll ans = 0;
    for(ll x : t){
        if (x > T) continue;
        int si = upper_bound(s.begin(), s.end(), T-x) - s.begin();
        ans = max(ans, x+s[si-1]);
    }
    cout << ans << endl;
}


#include "bits/stdc++.h"
using namespace std;
#define int long long int
int N=1e9+7;
int32_t main()
{
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }

    sort(a.begin(),a.end());

    int ans=1;

    int prev=0;

    for(int i=0;i<n;i++)
    {
        int mine=a[i]-prev+1;

        ans=(ans*mine)%N;

        prev=a[i];
    }

    cout<<ans<<endl;

    return 0;
}

#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#include<iostream>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	if ((tmp & ma0) ^ ma0) {
		int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
		tmp = tmp << dig & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += (72 - dig >> 3);
	}
	else {
		tmp = tmp & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += 8;
		if ((ct = *ci++) >= '0') {
			tmp = tmp * 10 + ct - '0';
			if (*ci++ == '0') {
				tmp = tmp * 10;
				ci++;
			}
		}
	}
	return tmp;
}
int A[100001];
int tmp[100001];
void pakuri_sort(int N, int A[]) {
	const int b = 8;
	rep(k, 4) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
	}
}
const int mod = 1e9 + 7;

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

	int N = getint();
	rep1(i, N) A[i] = getint();
	pakuri_sort(N, A + 1);

	int kotae = 1;
	rep(i, N) {
		kotae = kotae * ll(A[i + 1] - A[i] + 1) % mod;
	}

	co(kotae);

	Would you please return 0;
}


// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#define int long long int
#define ll long long int
#define ld long double
#define getFaster ios_base::sync_with_stdio(false), cin.tie(nullptr)
#define rep(i, init, n) for (int i = init; i < (int)n; i++)
#define rev(i, n, init) for (int i = (int)n; i >= init; i--)
#define MOD1 1e9 + 7
#define MOD2 998244353
#define f first
#define s second
#define endl '\n'
#define pii pair<int, int>
#define tii tuple<int, int>
#define all(v) v.begin(), v.end()
#define mt make_tuple
#define precise(i) cout << fixed << setprecision(i)
#define codejam cout << "Case #" << ii + 1 << ": ";
#define impossible cout << "IMPOSSIBLE" << endl;
#define error(s) throw runtime_error(s)
#define hash hash1
#define prev prev1
std::mt19937_64 gen(std::chrono::steady_clock::now().time_since_epoch().count());
std::mt19937 gen1(std::chrono::steady_clock::now().time_since_epoch().count());

//change according to int or long long int
int rng(int l, int r)
{
     return std::uniform_int_distribution<int>(l, r)(gen);
}

const long double PI = atan(1.0) * 4;
const int32_t INF32 = 2e9 + 7;
const int64_t INF64 = 3e18;
const int32_t LOG = 21;
int32_t MOD = MOD1;

using namespace std;

//-------------------DEBUGGING-------------------------
void my_debugger(string s, int LINE_NUM) { cerr << endl; }
template <typename start, typename... end>
void my_debugger(string s, int LINE_NUM, start x, end... y)
{
     if (s.back() != ',')
     {
          s += ',';
          cerr << "LINE(" << LINE_NUM << "): ";
     }
     int i = s.find(',');
     cerr << s.substr(0, i) << " = " << x;
     s = s.substr(i + 1);
     if (!s.empty())
          cerr << ", ";
     my_debugger(s, LINE_NUM, y...);
}

#ifdef AJIT
#define debug(...) my_debugger(#__VA_ARGS__, __LINE__, __VA_ARGS__);
#else
#define debug(...) ;
#endif

void setMod(int mod_val)
{
     MOD = mod_val;
}

void files_init()
{
     freopen("file.in", "r", stdin);
     freopen("file.out", "w", stdout);
}

const int N = 1e6 + 5;
const int LOGN = 20;

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

bool intersect(int l1,int r1,int l2,int r2,int fl1,int fr1,int fl2,int fr2)
{
     debug(l1,r1,l2,r2);
     if(l1>r2 || l2>r1 || l1>r1 || l2>r2)
     return false;

     if(l1==r2)
     {
          if(fl1 && fr2)
          return true;
          return false;
     }
     else if(l2==r1)
     {
          if(fl2 && fr1)
          return true;
          return false;
     }

     return true;
}

int32_t main()
{
     getFaster;
     //files_init();
     int tests = 1;
     //cin >> tests;
     rep(ii, 0, tests)
     {
          int n;
          cin>>n;
          vector<pii> vals(n);
          vector<pii> flag(n);
          rep(i,0,n)
          {
               int type,l,r;
               cin>>type>>l>>r;
               vals[i]={l,r};
               if(type==1)
               flag[i]={1,1};
               else if(type==2)
               flag[i]={1,0};
               else if(type==3)
               flag[i]={0,1};
               else
               flag[i]={0,0};
          }

          int ans=0;

          rep(i,0,n)
          {
               rep(j,i+1,n)
               {
                    if(intersect(vals[i].f,vals[i].s,vals[j].f,vals[j].s,flag[i].f,flag[i].s,flag[j].f,flag[j].s))
                    ans++;
               }
          }

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

#include <iostream>

using namespace std;

struct Interval {
  int tip;
  int left;
  int right;
};

int const NMAX = 2000;
Interval v[1 + NMAX];

bool isIntersect(Interval a, Interval b) {
  if(a.right == b.left){
    if((a.tip == 1 || a.tip == 3) && (b.tip == 1 || b.tip == 2)){// ] and [
      return true;
    }
    return false;
  }else if(a.right < b.left){
    return false;
  }
  if(b.right == a.left){
    if((b.tip == 1 || b.tip == 3) && (a.tip == 1 || a.tip == 2)){// ] and [
      return true;
    }
    return false;
  }else if(b.right < a.left){
    return false;
  }
  return true;
}

int main() {

  int n, ans = 0;
  cin >> n;
  for(int i = 1;i <= n;i++){
    cin >> v[i].tip >> v[i].left >> v[i].right;
  }
  for(int i = 1;i <= n;i++) {
    for(int j = i + 1;j <= n;j++){
      if(isIntersect(v[i], v[j])){
        ans++;
      }
    }
  }
  cout << ans;
  return 0;
}


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

typedef long long ll;
typedef long double ld;
const int N = (int)2e5 + 77;
const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e18;

int main()
{
  ll n, ans = 1, sp[33] = {0}, cnt[33] = {0};
  cin >> n;
  for (int i = 2; i <= n; i++)
  {
    for (int j = i; j <= n; j += i)
    {
      if (sp[j] == 0)
        sp[j] = i;
    }
  }
  for (int i = 2; i <= n; i++)
  {
    ll c[33] = {0}, k = i;
    while (k > 1)
    {
      c[sp[k]]++;
      k /= sp[k];
    }
    for (int j = 2; j <= n; j++)
      cnt[j] = max(cnt[j], c[j]);
  }
  for (int i = 2; i <= n; i++)
  {
    int k = cnt[i];
    while (k--)
      ans = ans * i;
  }
  cout << ans + 1 << endl;
  return 0;
}

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

#define faster      ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pi          acos(-1.0)
#define nl          '\n'

/**-------Library-------*/
#define mem(a,b)       memset(a,b,sizeof(a))
#define all(a)         a.begin(),a.end()
#define Sort(x)        sort(x.begin(),x.end())
#define SortR(x)       sort(x.begin(),x.end(),greater<int>())
#define Reverse(x)     reverse(x.begin(),x.end())

#define Sum(A,n)       accumulate(A,A+n,0)
#define SortA(ar,s)    sort(ar,ar+s)
#define SortD(ar,s)    sort(ar,ar+s,greater<int>())
#define maxa(A,n)      *max_element(A,A+n)
#define mina(A,n)      *min_element(A,A+n)
#define gcd(a,b)       __gcd(a,b)
#define lcm(a,b)       (a*(b/gcd(a,b)))
#define sq(x)          (x)*(x)
#define mid(l,r)       (l+(r-l)/2)

#define trzero(x)       __builtin_ctz(x)
#define parity(x)       __builtin_parity(x)
#define countone(x)     __builtin_popcount(x)
#define left(p)         (p<<1)
#define right(p)        (p>>1)

#define min3(a,b,c)       min(a,min(b,c))
#define min4(a,b,c,d)     min(a,min(b,min(c,d)))
#define max3(a,b,c)       max(a,max(b,c))
#define max4(a,b,c,d)     max(a,max(b,max(c,d)))
#define pb(x)             push_back(x)
#define mod               1000000007
#define precision(x)      cout<<fixed<<setprecision(x)
#define nel               cout<<nl
#define yes               cout<<"YES"<<nl
#define no                cout<<"NO"<<nl

/**----------Graph Moves----------*/
const int fx[] = {+1,-1,+0,+0};                         // 4 X directions
const int fy[] = {+0,+0,+1,-1};                         // 4 Y directions
const int fx8[] = {+0,+0,+1,-1,-1,+1,-1,+1};            // King X Moves
const int fy8[] = {-1,+1,+0,+0,+1,+1,-1,-1};            // King Y Moves
const int kx[] = {-2, -2, -1, -1,  1,  1,  2,  2};      // Knight X Moves
const int ky[] = {-1,  1, -2,  2, -2,  2, -1,  1};      // Knight Y Moves

/**----data type----*/
typedef long long int ll;
typedef unsigned long long int  llu;

int main()
{
    int n;
    cin>>n;
    n-=3;

    cout<<6<<" "<<10<<" "<<15<<" ";

    for(int i=16; ; i++)
    {
        if(n==0)
            return 0;

        if(i%6==0 || i%15==0 || i%10==0)
        {
            cout<<i<<" ";
            i++;
            n--;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
#define fi first
#define se second

//#define ivorysi
#define enter putchar('\n')
#define space putchar(' ')
#define pii pair<int,int>

typedef long long int64;
using namespace std;

template<class T>
void read(T &res) {
	res = 0;T f = 1;char c = getchar();
	while(c < '0' || c > '9') {
		if(c == '-') f = -1;
		c = getchar();
	}
	while(c >= '0' && c <= '9') {
		res = res * 10 + c - '0';
		c = getchar();
	}
	res *= f;
}
template<class T>
void out(T x) {
	if(x < 0) {x = -x;putchar('-');}
	if(x >= 10) out(x / 10);
	putchar('0' + x % 10);
}
int N;
int64 res = 1;
int64 gcd(int64 a,int64 b) {
	return b == 0 ? a : gcd(b,a % b);
}
int main() {
#ifdef ivorysi
	freopen("f1.in","r",stdin);
#endif
	read(N);
	for(int i = 2 ; i <= N ; ++i) {
		res = res * i / gcd(i,res);
	}
	out(res + 1);enter;
}

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

#define ll long long
#define vi vector<ll>
#define rep(i,a,b) for(ll i=a; i<b; ++i)
#define pb push_back
#define endl '\n'
#define sa(x) sort((x).begin(), (x).end());
#define int long long
#define test cout<<"hello\n";
#define disp(a) 	trav(a) cout<<x<<" "; cout<<endl;

template<typename T, typename U> static inline void amin(T &x, U y){ if(y<x) x=y; }
template<typename T, typename U> static inline void amax(T &x, U y){ if(x<y) x=y; }
template<typename T,typename U> std::ostream& operator<<(std::ostream& out, std::pair<T,U> a) {out<<" ("<<a.fr<<" "<<a.sc<<") "; return out;}
template<typename T,typename U> std::istream& operator>>(std::istream& in, std::pair<T,U> &a) {in>>a.fr>>a.sc; return in;}
template<typename T> static inline void sd(vector<T> &x) {sort(all(x), greater<T>()) ; }

vi a;
int solve(){
	int n;
	cin>>n;
	a.resize(1<<n);
	int mx=0, id=-1;
	rep(i,0,(1<<n)){
		cin>>a[i];
		if(a[i] > mx){
			mx=a[i];
			id=i;
		}
	}
	int st=0;
	if(id<(1<<(n-1))){
		st += (1<<(n-1));
	}
	int mm=0, ans=-1;
	// cout<<st<<endl;
	rep(i,0,(1<<(n-1))){
		if(a[st+i] > mm){
			mm = a[i+st];
			ans=i+st;
		}
	}
	cout<<ans+1<<endl;

	return 0;
}

signed main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int testcases=1;
	//cin>>testcases;
	while(testcases--){
		solve();
	}
	return 0;
}


#include <bits/stdc++.h>

#define isNum(a) (a >= '0' && a <= '9')
#define SP putchar(' ')
#define EL putchar('\n')
#define File(a) freopen(a ".in", "r", stdin), freopen(a ".out", "w", stdout)

template <typename T>
void read(T &);
template <typename T>
void write(const T &);

typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> pii;
const int iinf = 2147483647;
const ll llinf = 9223372036854775807ll;

const int N = 200005;

char ch[N];

int main() {
  int T;
  read(T);
  while (T--) {
    int n;
    read(n);
    scanf("%s", ch + 1);
    scanf("%s", ch + 1);
    scanf("%s", ch + 1);
    for (int i = 1; i <= n; ++i) {
      putchar('0');
    }
    for (int i = 1; i <= n; ++i) {
      putchar('1');
    }
    putchar('0');
    EL;
  }
  return 0;
}

template <typename T>
void read(T &Re) {
  T k = 0;
  char ch = getchar();
  int flag = 1;
  while (!isNum(ch)) {
    if (ch == '-') flag = -1;
    ch = getchar();
  }
  while (isNum(ch)) {
    k = (k << 1) + (k << 3) + ch - '0';
    ch = getchar();
  }
  Re = flag * k;
}
template <typename T>
void write(const T &Wr) {
  if (Wr < 0) {
    putchar('-');
    write(-Wr);
  } else {
    if (Wr < 10) {
      putchar(Wr + '0');
    } else {
      write(Wr / 10);
      putchar((Wr % 10) + '0');
    }
  }
}

#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb emplace_back
#define mp make_pair
#define sqr(n) ((n)*(n))
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)
#define precision(a) setiosflags(ios::fixed) << setprecision(a)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<long long> VL;
typedef double db;

template <typename T> inline char read(T &x) {
    x = 0; T fg = 1; char ch = getchar();
    while (!isdigit(ch)) {if (ch == '-') fg = -1;ch = getchar();}
    while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ '0'), ch = getchar();
    x = fg * x; return ch;
}
template <typename T, typename... Args> inline void read(T &x, Args &... args) { read(x), read(args...); }
template <typename T> inline void write(T x) {
    int len = 0; char c[21]; if (x < 0) putchar('-'), x = -x;
    do{++len; c[len] = x % 10 + '0';} while (x /= 10);
    for (int i = len; i >= 1; i--) putchar(c[i]);
}
template <typename T, typename... Args> inline void write(T& x, Args &... args) { write(x), write(args...); }

template<class T1, class T2> bool umin(T1& a, T2 b) { return a > b ? (a = b, true) : false; }
template<class T1, class T2> bool umax(T1& a, T2 b) { return a < b ? (a = b, true) : false; }
template<class T> void clear(T& a) { T().swap(a); }

const int N = 3e5 + 5;

int n, m, _, k, cas;
ll a[N], s[N], ans;

int main() {
    IOS; cin >> n;
    rep (i, 1, n) {
        cin >> a[i]; s[i] = s[i - 1] + a[i];
        ans += a[i] * a[i] * (n - 1);
        ans -= 2 * a[i] * s[i - 1];
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T,class U>
inline bool chmax(T &a,U b){
    if(a<b){
        a=b;
        return true;
    }
    return false;
}
template<class T,class U>
inline bool chmin(T &a,U b){
    if(a>b){
        a=b;
        return true;
    }
    return false;
}
constexpr int INF=1000000000;
constexpr ll llINF=3000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
/*
vector<vector<ll>>C,sC;
void init_comb(int n,int m){
    C.resize(n+1,vector<ll>(m+1,0));
    sC.resize(n+1,vector<ll>(m+1,0));
    C[0][0]=1;
    for(int i=1;i<=n;i++){
        C[i][0]=1;
        for(int j=1;j<=m;j++){
            C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
        }
    }
    rep(i,n+1){
        rep(j,m){
            sC[i][j+1]=(sC[i][j]+C[i][j])%mod;
        }
    }
}*/
ll gcd(ll a,ll b){
    while(a%b){
        a%=b;
        swap(a,b);
    }
    return b;
}
ll lcm(ll a,ll b){
    return a/gcd(a,b)*b;
}
bool isprime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
set<int>primes;
void init_prime(int n){
	primes.insert(2);
    for(int i=3;i<=n;i+=2){
        bool f=true;
        for(int j:primes){
            if(j*j>i)break;
            if(i%j==0){
                f=false;
                break;
            }
        }
        if(f)primes.insert(i);
    }
}
ll modpow(ll a,ll b){
    ll res=1;
    while(b){
        if(b&1){
            res*=a;
            res%=mod;
        }
        a*=a;
        a%=mod;
        b>>=1;
    }
    return res;
}
vector<ll>inv,fact,factinv;
void init_fact(int n){
    inv.resize(n+1);
    fact.resize(n+1);
    factinv.resize(n+1);
    inv[0]=0;
    inv[1]=1;
    fact[0]=1;
    factinv[0]=1;
    for(ll i=1;i<=n;i++){
        if(i>=2)inv[i]=mod-((mod/i)*inv[mod%i]%mod);
        fact[i]=(fact[i-1]*i)%mod;
        factinv[i]=factinv[i-1]*inv[i]%mod;
    }
}
ll _inv(ll a,ll m=mod){
    //gcd(a,m) must be 1
    ll b=m,u=1,v=0;
    while(b){
        ll t=a/b;
        a-=t*b;swap(a,b);
        u-=t*v;swap(u,v);
    }
    u%=m;
    if(u<0)u+=m;
    return u;
}
ll comb(int a,int b){
    if(a<b)return 0;
    if(a<0)return 0;
    return fact[a]*factinv[a-b]%mod*factinv[b]%mod;
}
ll multicomb(int a,int b){
    return comb(a+b-1,b);
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n,m,a[2000000],last[2000000];
    cin>>n>>m;
    int ans=n;
    fill(last,last+n,-1);
    rep(i,n){
        cin>>a[i];
        if(last[a[i]]+m<i){
            chmin(ans,a[i]);
        }
        last[a[i]]=i;
    }
    int i=n;
    rep(k,n){
        if(last[k]+m<i){
            chmin(ans,k);
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(void)
{
    ll ans = 0;
    int n, m;
    cin >> n >> m;
    ll even = 0, odd = 0;
    rep (i, n){
        string s;
        cin >> s;
        ll score = 0;
        rep (j, m){
            if (s[j] == '1') score++;
        }
        if (score % 2 == 0) even++;
        else odd++;
    }
    ans = even * odd;
    cout << ans << endl;
    return 0;
}


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

#ifdef Dhiraj
    #include "D:/dhiraj/Programming/debug.h"
#else
    #define d(...) 11
    #define cerr if(0) cerr
#endif

#define ll long long int
#define endl '\n'

template <typename T, typename U>
inline istream& operator >> (istream& in, pair<T, U>& a) {
    in >> a.first >> a.second;
    return in;
}
template <typename T>
inline istream& operator >> (istream& in, vector<T>& a) {
    for(auto& x : a) in >> x;
    return in;
}

void solve(int &T)
{
    ll n, m;
    cin >> n >> m;

    vector<ll> b(m + 2);
    for(ll i = 0; i < m; i++) {
        cin >> b[i + 1];
    }
    b[0] = 0;
    b[m + 1] = n + 1;

    if(m == 0) {
        cout << 1 << endl;
        return;
    }
    if(m == n) {
        cout << 0 << endl;
        return;
    }
    sort(b.begin(), b.end());

    ll mn = 1e10;
    for(ll i = 1; i < m + 2; i++)
    {
        if(b[i] != b[i - 1] + 1) {
            mn = min(mn, b[i] - b[i - 1] - 1);
        }
    }
    d(mn);

    if(mn == 1e10) {
        cout << 0 << endl;
        return;
    }

    ll ans = 0;
    for(ll i = 1; i < m + 2; i++)
    {
        if(b[i] != b[i - 1] + 1) {
            ans += (b[i] - b[i - 1] - 1 + mn - 1) / mn;
        }
    }
    cout << ans << endl;
}

int main()
{
    #ifdef Dhiraj
        freopen("D:/dhiraj/Programming/i1.txt", "r", stdin);
        freopen("D:/dhiraj/Programming/o1.txt", "w", stdout);
        // freopen("D:/dhiraj/Programming/e1.txt", "w", stderr);
    #endif

    ios::sync_with_stdio(false);
    cin.tie(0);

    int tc = 1;
    for(int i = 1; i <= tc; i++) {
        cerr << "Case #" << i << "\n";
        solve(i);
    }
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define closeSync ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef pair<int,ll> pil;
const int MAXN = 100005;
const ll MOD = 1e9+7;
const ll INF = 1e18;

vector<pil> mp[MAXN];
ll dis[MAXN];
int vis[MAXN];
ll ans[MAXN];
struct Edge{
	int u,v;
	ll w;
};
struct E{
	int v;
	ll w;
	bool operator<(const E& x)const
	{
		return w > x.w;
	}
};
int n,m;

ll dij(int st,int ed)
{
	for (int i=1;i<=n+1;i++)
		vis[i] = 0,dis[i] = INF;
	priority_queue<E> q;
	q.push({st,0});
	dis[st] = 0;
	while (!q.empty())
	{
		E u = q.top();
		q.pop();
		if (vis[u.v])
			continue;
		vis[u.v] = 1;
		for (auto c : mp[u.v])
		{
			if (dis[u.v] + c.second < dis[c.first])
			{
				dis[c.first] = dis[u.v] + c.second;
				q.push({c.first,dis[c.first]});
			}
		}
	}
	return dis[ed];
}

inline void solve()
{

	cin >> n >> m;
	vector<Edge> ve;
	for (int i=1;i<=m;i++)
	{
		int u,v;ll w;
		cin >> u >> v >> w;
		ve.push_back({u,v,w});
	}
	for (int i=1;i<=n;i++)
	{
		for (int j=1;j<=n;j++)
			mp[j].clear(),mp[j].resize(0);
		for (auto c : ve)
		{
			if (c.v == i)
				mp[c.u].push_back({n+1,c.w});
			else
				mp[c.u].push_back({c.v,c.w});
		}
		ll tmp = dij(i,n+1);
		ans[i] = (tmp == INF ? -1 : tmp);
	}
	for (int i=1;i<=n;i++)
		cout << ans[i] << endl;

}

int main()
{closeSync;
	// int T;
	// cin >> T;
	// while (T--)
		solve();
	return 0;
}