#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cassert>
#include <string>
#include <set>
#include <map>
#include <random>
#include <bitset>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using ul = unsigned long long;
using ld = long double;

ll md(ll i, vector<ll> &a) {
  auto it = lower_bound(all(a), i);
  ll ans = 1e18;
  if (it != a.end())
    ans = min(ans, *it - i);
  if (it != a.begin())
    ans = min(ans, i - *prev(it));
  return ans;
}

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);
  ll n;
  cin >> n;
  vector<vector<ll>> a(3);
  ll x;
  char c;
  string cc = "RGB";
  rep(i, 2 * n) {
    cin >> x >> c;
    a[cc.find(c)].push_back(x);
  }
  for (auto &p : a)
    sort(all(p));
  sort(all(a), [](const auto &p1, const auto &p2) { return p1.size() % 2 > p2.size() % 2; });
  if (a[0].size() % 2 == 0) {
    cout << 0;
    return 0;
  }
  ll ans = 1e18;
  for (ll i : a[0])
    ans = min(ans, md(i, a[1]));
  rep(t, 2) {
    ll cm = 1e18;
    for (ll i : a[2]) {
      ans = min(ans, cm + md(i, a[1]));
      cm = min(cm, md(i, a[0]));
    }
    swap(a[0], a[1]);
  }
  cout << ans;
}

#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pci pair <char, int>
#define pld pair <ld, ld>
#define ppld pair <pld, pld>
#define ppll pair <pll, pll>
#define pldl pair <ld, ll>
#define vll vector <ll>
#define vvll vector <vll>
#define vpll vector <pll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define mll map <ll, ll>
#define fastmap gp_hash_table
#define cd complex <double>
#define vcd vector <cd>
#define PI 3.14159265358979
#pragma 03
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll INF = 1e18;
char col[] = {'R', 'G', 'B'};
ll suff_min[200005][3], pref_min[200005][3];
pair <ll, char> dogs[200005];
ll mn[3], mx[3], cnt[3];
ll get_id(char c){
	for (ll i = 0; i < 3; i++){
		if (c == col[i]) return i;
	}
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	ll n; cin >> n;
	for (ll i = 0; i < 3; i++) mn[i] = INF;
	for (ll i = 1; i <= 2 * n; i++){
		cin >> dogs[i].fi >> dogs[i].se;
		cnt[get_id(dogs[i].se)]++;
	}
	if ((cnt[0] % 2 == 0) && (cnt[1] % 2 == 0) && (cnt[2] % 2 == 0)){
		cout << 0 << "\n"; return 0;
	}
	sort(dogs + 1, dogs + 2 * n + 1);
	ll ans = INF;
	pref_min[0][0] = pref_min[0][1] = pref_min[0][2] = INF;
	suff_min[2 * n + 1][0] = suff_min[2 * n + 1][1] = suff_min[2 * n + 1][2] = INF;
	for (ll i = 1; i <= 2 * n; i++){
		for (ll c = 0; c < 3; c++) pref_min[i][c] = pref_min[i - 1][c];
		ll id = get_id(dogs[i].se);
		if (cnt[id] & 1){
			for (ll c = 0; c < 3; c++){
				if (c == id) continue;
				if (mx[c] == 0) continue;
				if (cnt[c] & 1) ans = min(ans, dogs[i].fi - mx[c]);
				else pref_min[i][id] = min(pref_min[i][id], dogs[i].fi - mx[c]);
			}
		}
		else{
			for (ll c = 0; c < 3; c++){
				if (c == id) continue;
				if (mx[c] == 0) continue;
				pref_min[i][c] = min(pref_min[i][c], dogs[i].fi - mx[c]);
			}
		}
		mx[id] = max(mx[id], dogs[i].fi);
	}
	for (ll i = 2 * n; i >= 1; i--){
		for (ll c = 0; c < 3; c++) suff_min[i][c] = suff_min[i + 1][c];
		ll id = get_id(dogs[i].se);
		if (cnt[id] & 1){
			for (ll c = 0; c < 3; c++){
				if (c == id) continue;
				if (mn[c] == INF) continue;
				if (cnt[c] % 2 == 0) suff_min[i][id] = min(suff_min[i][id], mn[c] - dogs[i].fi);
			}
		}
		else{
			for (ll c = 0; c < 3; c++){
				if (c == id) continue;
				if (mn[c] == INF) continue;
				suff_min[i][c] = min(suff_min[i][c], mn[c] - dogs[i].fi);
			}
		}
		mn[id] = min(mn[id], dogs[i].fi);
	}
	for (ll s = 1; s < 2 * n; s++){
		for (ll c1 = 0; c1 < 3; c1++){
			for (ll c2 = 0; c2 < 3; c2++){
				if (c1 == c2) continue;
				ans = min(ans, pref_min[s][c1] + suff_min[s + 1][c2]);
			}
		}
	}
	cout << ans << "\n";
}


#line 2 "header.hpp"

//%snippet.set('header')%
//%snippet.fold()%
#ifndef HEADER_H
#define HEADER_H

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

// varibable settings
template <class T> constexpr T inf = numeric_limits<T>::max() / 2.1;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _rrep(i, n) rrepi(i, 0, n)
#define rrepi(i, a, b) for (ll i = (ll)((b)-1); i >= (ll)(a); --i)
#define r_rep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(i, a) for (auto &&i : a)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(...) make_tuple(__VA_ARGS__)
#define ub upper_bound
#define lb lower_bound
#define lpos(A, x) (lower_bound(all(A), x) - A.begin())
#define upos(A, x) (upper_bound(all(A), x) - A.begin())
template <class T, class U> inline void chmax(T &a, const U &b) { if ((a) < (b)) (a) = (b); }
template <class T, class U> inline void chmin(T &a, const U &b) { if ((a) > (b)) (a) = (b); }
template <typename X, typename T> auto make_table(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto make_table(X x, Y y, Z z, Zs... zs) { auto cont = make_table(y, z, zs...); return vector<decltype(cont)>(x, cont); }

template <class T> T cdiv(T a, T b){ assert(a >= 0 && b > 0); return (a+b-1)/b; }

#define is_in(x, a, b) ((a) <= (x) && (x) < (b))
#define uni(x) sort(all(x)); x.erase(unique(all(x)), x.end())
#define slice(l, r) substr(l, r - l)

typedef long long ll;
typedef long double ld;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;

template <typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;
void check_input() { assert(cin.eof() == 0); int tmp; cin >> tmp; assert(cin.eof() == 1); }

#if defined(PCM) || defined(LOCAL)
#else
#define dump(...) ;
#define dump_1d(...) ;
#define dump_2d(...) ;
#define cerrendl ;
#endif

#endif /* HEADER_H */
//%snippet.end()%
#line 2 "solve.cpp"
template<class T=ll> using vec = vector<T>;
struct Fast { Fast() { std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

int solve() {
    int n;cin>>n;
    ll x;cin>>x;
    dump(n, x);
    vector<ll> a(n+1);
    rep(i, 1, n+1) { cin>>a[i]; }
    dump(a);

    vec<ll> d(n+1);
    rep(i, 1, n){
        d[i] = a[i+1] / a[i];
    }
    dump(d);

    vec<ll> xb(n+1);
    r_rep(i, 1, n+1){
        xb[i] = x / a[i];
        x %= a[i];
    }
    dump(xb);
    dump(x);

    vec<ll> dp0(n+1);
    vec<ll> dp1(n+1);
    dp0[0] = 1;
    rep(i, 0, n){ // kubaru
        // o[i+1]は[0, d[i+1])をとる

        // from dp0
        dp0[i+1] += dp0[i]; // take 0;
        if (xb[i+1]>=1){
            dp1[i+1] += dp0[i]; // take [d-xb, d)
        }

        // from dp1
        if (xb[i+1]+1 == d[i+1]){
            dp1[i+1] += dp1[i]; // take 0;
        }
        else{
            dp0[i+1] += dp1[i]; // take 0;
            dp1[i+1] += dp1[i]; // take [d-xb, d)
        }
    }
    dump(dp0);
    dump(dp1);
    cout << dp0[n] << endl;

    return 0;
}

int main(){/*{{{*/
    solve();

    #if defined(PCM) || defined(LOCAL)
    check_input();
    #endif

    return 0;
}/*}}}*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll one = 1;
const ll INF = 9223372036854775807; //10^18
const int inINF = 2147483647; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

ll N, X;
map<pair<ll, ll>, ll> memo;
vector<ll> A;

ll solve(ll Y, ll ind){
    if(memo.count({Y, ind})){
        return memo[{Y, ind}];
    }
    if(ind == N - 1){
        if(Y % A[ind] == 0){
            return 1;
        }
        else{
            return 0;
        }
    }
    ll low = Y / A[ind+1] * A[ind+1];
    ll up = Y / A[ind+1] * A[ind+1] + A[ind+1];
    ll ret = 0;
    ret += solve(low, ind+1);
    if(Y % A[ind+1] != 0){
        ret += solve(up, ind + 1);
    }
    return memo[{Y, ind}] = ret;
}

int main(){
    cin >> N >> X;
    A.resize(N);
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
    }
    printf("%lld\n", solve(X, 0));

}


#include <bits/stdc++.h>
constexpr int DEBUG = 0;
using namespace std;
using int64 = long long;
#define REPEAT(i, l, r) for (int i = (int)(l); i < (int)(r); i++)

constexpr int64 P = 998244353;

class FF {
 private:
  int64 x_;
  void Normalize() {
    if (0 <= x_ && x_ < P) { return; } x_ %= P; if (x_ < 0) { x_ += P; }
  }
 public:
  FF(int64 x) : x_(x) { Normalize(); }
  FF() : x_(0) {}
  int64 Value() const { return x_; }
  FF operator+(FF o) const { FF r(*this); r += o; return r; }
  FF operator-(FF o) const { FF r(*this); r -= o; return r; }
  FF operator* (FF o) const { FF r(*this); r *= o; return r; }
  FF operator/ (FF o) const { return (*this) * o.Power(P - 2); }
  void operator+= (FF o) { x_ += o.x_; if (x_ >= P) x_ -= P; }
  void operator-= (FF o) { x_ -= o.x_; if (x_ < 0) x_ += P; }
  void operator*= (FF o) { x_ = (x_ * o.x_) % P; }
  FF Power(int64 p) const {
    if (p < 0) { return Power(-p); } FF x(*this), r(1);
    while (p) { if (p % 2) { r *= x; } x *= x; p /= 2; } return r;
  }
};
ostream& operator<<(ostream& s, const FF& x) { s << x.Value(); return s; }

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

  int n; cin >> n;
  vector<int> fs(n);
  REPEAT(i, 0, n) {
    cin >> fs[i];
    fs[i]--;
  }

  vector<int> ts(n, -1);
  int t = 0;
  vector<int> cs;
  REPEAT(s, 0, n) {
    if (ts[s] >= 0) continue;
    ts[s] = t;
    t++;
    int v = fs[s];
    while (true) {
      if (ts[v] >= 0) {
        if (ts[v] >= ts[s]) {
          cs.push_back(t - ts[v]);
        }
        break;
      } else {
        ts[v] = t;
        t++;
        v = fs[v];
      }
    }
  }
  FF ans = FF(2).Power(cs.size()) - 1;
  cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define deb(x) cout<< #x << " " << x << "\n";
#define MAX 9223372036854775807
#define MIN -9223372036854775807
#define setbits(n) __builtin_popcountll(n)
#define mkunique(a) a.resize(unique(a.begin(),a.end())-a.begin());
const ll mod=998244353;

const int N=2e5+10;
vector<ll> a[N];
vector<bool> vis(N);

ll dfs(ll v){
    vis[v]=true;
    ll s=1;
    for(ll u: a[v]){
        if(!vis[u])
            s+=dfs(u);
    }
    return s;
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll T=clock();

    ll n;
    cin>>n;
    for(ll i=0;i<n;i++){
        ll r;
        cin>>r; r--;
        a[r].pb(i);
        a[i].pb(r);
    }
    ll ans=1;
    for(ll i=0;i<n;i++){
        if(!vis[i]){
            ll num=dfs(i);
            ans=ans*2%mod;
        }
    }
    ans=(ans-1+mod)%mod;
    cout<<ans;

    cerr<<"\n\nTIME: "<<(double)(clock()-T)/CLOCKS_PER_SEC<<" sec\n";
    T = clock();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define int unsigned long long

#define PB    push_back
#define ALL(x)    (x).begin(), (x).end()
#define ALLR(x)    (x).rbegin(), (x).rend()
#define MP    make_pair

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef KILLBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define FAST_IO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<bool> vb;

const int INF = LONG_LONG_MAX/10;
const double PI = 3.141592653589793238;
const int MOD = 998244353;

bool many = false;
struct Solve {
    string endl = "\n";

    Solve() {
		int x, y, a, b;
		cin >> x >> y >> a >> b;

		int str = x;
		int exp = 0;

		for (int i = 0; str < b/(a-1) && str*a < y; i++) {
			str *= a;
			exp++;
		}
		debug(str, exp);
		if (str < y) {
			exp += (y-str-1)/b;
		}

		cout << exp << endl;
	}
};

signed main() {
    FAST_IO;
    int CASES=1;
    if (many)
        cin >> CASES;
    for (int i = 1; i <= CASES; i++) {
        Solve me;
    }
}
// g++ -Wall -Wextra -pedantic -std=c++17 -O2 -Wshadow -Wformat=2 -Wfloat-equal -Wconversion -Wlogical-op -Wshift-overflow=2 -Wduplicated-cond -Wcast-qual -Wcast-align -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -D_FORTIFY_SOURCE=2 -fsanitize=address -fsanitize=undefined -fno-sanitize-recover -fstack-protector

#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define db double
#define rep(x,a,b) for(int x=(a);x<=(b);x++)
#define per(x,a,b) for(int x=(a);x>=(b);x--)
#define reP(x,a,b) for(int x=(a);x<(b);x++)
#define Per(x,a,b) for(int x=(a);x>(b);x--)
#define scf(a) scanf("%d",&a)
#define scfll(a) scanf("%lld",&a)
#define scfdb(a) scanf("%lf",&a)
#define ptf(a) printf("%d",a)
#define ptfll(a) printf("%lld",a)
#define ptfsp(a) printf("%d ",a)
#define ptfllsp(a) printf("%lld ",a)
#define pli(a,b) make_pair(a,b)
#define pb push_back
#define el puts("")
#define FS first
#define SE second
#define PI acos(-1)
#define ls (pos<<1)
#define rs (pos<<1|1)
/*ios::sync_with_stdio(false);
freopen("in.txt","r",stdin);
freopen("1.out","w",stdout);*/
using namespace std;
const ll mod=1e9+7;
const int maxn=1e6+5;
int main(){
    ull x,y,a,b;
    scfll(x);scfll(y);scfll(a);scfll(b);
    ull res=0,ans=0;
    for(ll i=x;i<y;i=i*a){
        ans=max(ans,(y-i-1)/b+res);
        if((double)i*a>(double)y) break;
        res++;
    }
    cout<<ans;
}


#include<bits/stdc++.h>
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define pii pair<int,int>
#define fi first
#define se second
#define PB push_back
#define ll long long
#define ull unsigned long long
#define y1 orzkcz
using namespace std;
const int N=3005;
const int mo=998244353;
int n,k,f[N][N];
int main(){
	scanf("%d%d",&n,&k);
	f[0][0]=1;
	For(i,0,n) Rep(j,i,0){
		f[i+1][j+1]=(f[i+1][j+1]+f[i][j])%mo;
		if (j%2==0) f[i][j/2]=(f[i][j/2]+f[i][j])%mo;
	}
	cout<<f[n][k]<<endl;
}

#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <deque>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <functional>
#include <iomanip>
#include <cstdint>
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define mt make_tuple
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector
#define vi vec<int>
#define vl vec<ll>
#define vivi vec<vi>
#define vlvl vec<vl>
#define vpii vec<pii>
#define vpll vec<pll>
#define vbl vec<bool>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
#define D(x) cout << (#x) << " is " << x << endl;
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
string stin(){string s;cin>>s;return s;}
void drop(string s){cout<<s<<endl; exit(0);}
void drop(int x){cout<<x<<endl; exit(0);}
void drop(ll x){cout<<x<<endl; exit(0);}
int main(){
    int n = in();
    ll w = lin();
    vl plus(200010);
    rep(i,n){
        int s=in(),t=in(),p=in();
        plus[s] += p;
        plus[t] -= p;
    }
    ll tmp = 0;
    rep(i,200010){
        tmp += plus[i];
        if(tmp > w)drop("No");
    }
    drop("Yes");
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define sz(v) (int)v.size()
#define all(v) v.begin(), v.end()
void dbg_out() { cerr << "\b\b]\n"; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T){ cerr << H << ", "; dbg_out(T...);}
#define watch(...) cerr << "[" << #__VA_ARGS__ << "]: [", dbg_out(__VA_ARGS__)

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

    int n, m; cin >> n >> m;
    vector <pair <int, int>> A(m);
    for (auto &i: A) cin >> i.first >> i.second;
    int k; cin >> k;
    vector <int> dishes(n+1, 0);
    vector <pair <int, int>> person(k);
    for (int i = 0; i < k; ++i) {
        int a, b; cin >> a >> b;
        person[i] = {a, b};
    }
    int ans = 0;
    function <void(int)> go = [&](int pos) {
        if (pos >= k) {
            int res = 0;
            for (auto i: A) {
                if (dishes[i.first] and dishes[i.second]) res++;
            }
            ans = max(ans, res);
            return;
        }
        dishes[person[pos].first]++;
        go(pos+1);
        dishes[person[pos].first]--;
        dishes[person[pos].second]++;
        go(pos+1);
        dishes[person[pos].second]--;
    };

    go(0);
    cout << ans;
}

/*

*/

#include <bits/stdc++.h>

using namespace std;

struct p{
    long long int w;
    long long int c;
};

p tab[200007];
vector <long long int> edges[200007];

int main()
{
    long long int m, x, y, n, j, i, z=-1000000000000000007, a, b=1, m1=0, m2=0;
    cin >> n >> m;
    for(i=0; i<n; i++){
        cin >> a;
        tab[i].w=a;
        tab[i].c=-1000000000000000007;
    }
    for(i=0; i<m; i++){
        cin >> a >> b;
        edges[a-1].push_back(b-1);
    }
    for(i=0; i<n; i++){
        for(j=0; j<edges[i].size(); j++){
            tab[edges[i][j]].c=max(tab[edges[i][j]].c, max(tab[edges[i][j]].w-tab[i].w+tab[i].c, tab[edges[i][j]].w-tab[i].w));
            z=max(z, tab[edges[i][j]].c);
        }
    }
    cout << z << '\n';
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define x first
#define y second
#define FOR(i, m, n) for (ll i(m); i < n; i++)
#define DWN(i, m, n) for (ll i(m); i >= n; i--)
#define REP(i, n) FOR(i, 0, n)
#define DW(i, n) DWN(i, n, 0)
#define F(n) REP(i, n)
#define FF(n) REP(j, n)
#define D(n) DW(i, n)
#define DD(n) DW(j, n)
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using tll = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vpll = vector<pll>;
using vtll = vector<tll>;
using gr = vector<vll>;
using wgr = vector<vpll>;
void add_edge(gr&g,ll x, ll y){ g[x].pb(y);g[y].pb(x); }
void add_edge(wgr&g,ll x, ll y, ll z){ g[x].eb(y,z);g[y].eb(x,z); }
template<typename T,typename U>
ostream& operator<<(ostream& os, const pair<T,U>& p) {
    cerr << ' ' <<  p.x << ',' << p.y; return os; }
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    for(auto x: v) os << ' ' <<  x; return os; }
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
    for(auto x: v) os << ' ' <<  x; return os; }
template<typename T,typename U>
ostream& operator<<(ostream& os, const map<T,U>& v) {
    for(auto x: v) os << ' ' <<  x; return os; }
struct d_ {
    template<typename T> d_& operator,(const T& x) {
        cerr << ' ' <<  x; return *this;}
} d_t;
#define dbg(args ...) { d_t,"|",__LINE__,"|",":",args,"\n"; }
#define deb(X ...) dbg(#X, "=", X);
#define EPS (1e-10)
#define INF (1LL<<61)
#define YES(x) cout << (x ? "YES" : "NO") << endl;
#define CL(A,I) (memset(A,I,sizeof(A)))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

const ll MOD = 998244353;
ll mod(ll a, ll b=MOD) {
  return ((a%b)+b)%b;
}
ll extended_euclid(ll a,ll b,ll &x,ll &y) {
    if (a == 0) { x = 0; y = 1; return b;}
    ll x1, y1; ll d = extended_euclid(b%a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}
ll mod_inverse(ll a, ll n=MOD) {
  ll x, y;
  ll d = extended_euclid(a, n, x, y);
  if (d > 1) return -1;
  return mod(x,n);
}
struct Mt {
    ll x = 0;
    Mt(){}
    Mt(ll y):x(mod(y)){}
    bool operator==(Mt &y){return x==y.x;}
    Mt operator+(Mt y){return mod(x+y.x);}
    Mt operator-(){return mod(-x);}
    Mt operator-(Mt y){return mod(x-y.x);}
    Mt operator*(Mt y){return mod(x*y.x);}
    Mt operator/(Mt y){return mod(x*mod_inverse(y.x));}
    Mt operator+=(Mt y){return x=(*this+y).x;}
    Mt operator-=(Mt y){return x=(*this-y).x;}
    Mt operator*=(Mt y){return x=(*this*y).x;}
    Mt operator/=(Mt y){return x=(*this/y).x;}
    Mt pow(ll p) {
        Mt ret=1, z=x;
        while(p) {
            if (p&1) ret*=z;
            z*=z; p/=2;
        }
        return ret;
    }
    Mt operator^(Mt y){return this->pow(y.x);}
};
ostream& operator<<(ostream& os, const Mt&m){
    os << m.x; return os;
}

const ll N = 5e3+7;
Mt pw[N][N];

int main(void) {
    ios_base::sync_with_stdio(false);
    ll n,m; cin >> n >> m;
    F(m+1) pw[i][0] = 1;
    FOR(i,1,m+1) FOR(j,1,n+1) {
        pw[i][j] = pw[i][j-1] * i;
    }
    Mt ret = Mt(n) * pw[m][n];
    FOR(x,1,m+1) FOR(d,1,n+1) {
        Mt cur = pw[m-x][d-1] * pw[m][n-d-1];
        ret -= cur * (n-d);
    }
    cout << ret << endl;
    return 0;
}

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

#define sync std::ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define int long long
#define loop(i,n)           for(int i=0;i<n;i++)
#define FOR(i,a,b,c)        for(int i=a;i<=b;i=i+c)
#define RFOR(i,a,b,c)       for(int i=a;i>=b;i=i-c)

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

#define     deb(x)          cout<<#x<<" = "<<x<<endl
#define     all(x)          (x).begin(),(x).end()
#define     reset(a)        memset(a,0,sizeof(a))
#define     pb              push_back
#define     pf              push_front
#define     pob	            pop_back
#define     pof             pop_front
#define     ins             insert
#define     F               first
#define     S               second
#define     mkp             make_pair
#define     mkt             make_tuple
#define     bitcount(x)     __builtin_popcountll(x)
#define     gcd(a,b)        (__gcd(a,b))
#define     lcm(a,b)        ((a*b)/gcd(a,b))

#define PI 3.1415926535897932384626

const int mod = 998244353  ;//1e9+7;
const int N=2e5+5;

//============

void solve()
{
	int n,ans=0;
	string s,t;
	cin>>n>>s;
	char a,b,c;

	stack<char> stk;

	for(auto et: s)
	{
		stk.push(et);
		if(et=='x' && stk.size()>2)
		{
			a=stk.top();	stk.pop();
			b=stk.top();	stk.pop();
			c=stk.top();	stk.pop();
			if(a=='x' && b=='o' && c=='f')
				ans++;
			else
			{
				stk.push(c);
				stk.push(b);
				stk.push(a);
			}
		}
	}
	cout<<n-3*ans;

}

int32_t main()
{
	sync;

//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout);

	int t=1;
	//cin>>t;
	FOR(i,1,t,1)
	{
		//cout<<"Case #"<<i<<": "<<;
		solve();
		cout<<endl;
	}
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf=0x3f,INF=0x3f3f3f3f; const ll LLINF=0x3f3f3f3f3f3f3f3f;
#define sz(x) (int)x.size()
#define af(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x);
#define fil(x, y) fill(af(x), y);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second
#define lc i << 1
#define rc i << 1 | 1
const int mod = 1e9 + 7;
ll fpow(ll a, ll b){ll ret=1;while(b){if(b&1)ret=ret*a%mod;a=a*a%mod,b>>=1;}return ret;}
ll inv(ll x){return x ? fpow(x, mod - 2) : 1;}
void madd(int &a, int b){a+=b;if(a>=mod)a-=mod;}
void msub(int &a, int b){a+=mod-b;if(a>=mod)a-=mod;}
const int MM = 2e5 + 5;
void solve(){
	int a, b, c;
	cin >> a >> b >> c;
	vector<vector<vector<double>>> dp(101, vector<vector<double>>(101, vector<double>(101)));
	function<double(int,int,int)> rec = [&](int x, int y, int z){
		if (x == 100 || y == 100 || z == 100) return 0.0;
		if (dp[x][y][z] != 0.0) return dp[x][y][z];
		int t = x + y + z;
		return dp[x][y][z] = 1.0*x/t*(1.0+rec(x+1,y,z)) + 1.0*y/t*(1.0+rec(x,y+1,z)) + 1.0*z/t*(1.0+rec(x,y,z+1));
	};
	cout << fixed << setprecision(10) << rec(a, b, c) << '\n';
}

int main(){
	cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int t = 1;
	//cin >> t;
	while(t--) solve();
}

#include<functional>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<utility>
#include<string>
#include<cstdio>
#include<vector>
#include<bitset>
#include<cmath>
#include<ctime>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};// 上 左 下 右
const int N=100005,M=1000005,K=200005,mod=1000000007;
const long long llinf=9223372036854775807ll;
//int & long long
double dp[105][105][105],ans;
int a,b,c;
int main()
{
	cin>>a>>b>>c;
	dp[a][b][c]=1;
	for(int i=a;i<100;i++)
		for(int j=b;j<100;j++)
			for(int k=c;k<100;k++)
				dp[i+1][j][k]+=dp[i][j][k]*i/(i+j+k),dp[i][j+1][k]+=dp[i][j][k]*j/(i+j+k),dp[i][j][k+1]+=dp[i][j][k]*k/(i+j+k);
	for(int i=0;i<100;i++)
		for(int j=0;j<100;j++)
			ans+=dp[100][i][j]*(i+j+100-a-b-c),ans+=dp[i][100][j]*(i+j+100-a-b-c),ans+=dp[i][j][100]*(i+j+100-a-b-c);
	cout<<fixed<<setprecision(9)<<ans<<endl;
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<bits/stdc++.h>
//Do DEBUG OR NOT
//#define DEBUG

#ifdef DEBUG
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
#else
#define debug(...) true
#endif
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;

//prototype declaration
ll pow_mod(ll n, ll k, ll m);//繰り返し二乗法 return val:(n^k)%m
ll gcd(ll a, ll b);//最大公約数 2引数
ll ngcd(vector<ll> a);
ll lcm(ll a, ll b);//最小公倍数 2引数
ll nlcm(vector<ll> numbers);
bool isPrime(ll x);//素数判定
ll digsum(ll n);//桁和
vector<ll> enum_div(ll n);//約数全列挙
ll stringcount(string s, char c);//特定文字カウント

//__________________________main__________________________

int main(){
    string N;
    cin>>N;
    if(N.size()%2==1){
        ll temp=1;
        rep(i,N.size()-1){
            temp*=10;
        }
        temp--;
        N=to_string(temp);
    }
    debug(N);
    string fowardN;
    string backN;
    fowardN=N.substr(0,N.size()/2);
    backN=N.substr(N.size()/2,N.size());
    debug(fowardN);
    debug(backN);
    ll plus=9;
    ll start=1;
    ll goal=9;
    ll ans=0;
    rep(i,N.size()/2){
        debug(start);
        debug(goal);
        ll end=goal;
        //if((N.size()/2>1)&&(i==N.size()/2-1)&&(stoi(fowardN)<10||stoi(backN)<10)) break;
        if(i==N.size()/2-1){
            for(int i=start;i<=stoll(fowardN);i++){
                debug(i);
                if(stoll(N)<stoll(to_string(i)+to_string(i))) continue;
                ans++;
            }
            end=min(end,stoll(fowardN));
            end=min(end,stoll(backN));
        }else{
            ans+=end-start+1;
        }

        debug(ans);
        goal=goal*10+9;
        start*=10;
    }
    cout<<ans<<endl;

    return 0;
}

//__________________________functions_____________Ctrl+K,Ctrl+0
//繰り返し二乗法関数
ll pow_mod(ll n, ll k, ll m){//r:(n^k)%m
    ll r=1;
    for(;k>0;k=k>>1){
        if(k&1) r=(r*n)%m;
        n = (n*n) % m;
    }
    return r;
}
//最大公約数 2引数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}
//最大公約数 n引数
ll ngcd(vector<ll> a){
    ll res;
    res = a[0];
    for(int i = 1; i < a.size() && res != 1; i++) {
        res = gcd(a[i], res);
    }
    return res;
}
//最小公倍数 2引数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}
//最小公倍数 n引数
ll nlcm(vector<ll> numbers) {
    ll res;
    res = numbers[0];
    for (int i = 1; i < numbers.size(); i++) {
        res = lcm(res, numbers[i]);
    }
    return res;
}
//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}
//桁和
ll digsum(ll n) {
    ll res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}
//約数全列挙
vector<ll> enum_div(ll n){
    vector<ll> ret;
    for(int i = 1 ; i*i <= n ; ++i){
        if(n%i == 0){
            ret.push_back(i);
            if(i != 1 && i*i != n){
                ret.push_back(n/i);
            }
        }
    }
    return ret;
}
//特定文字カウント
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}

#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define ll long long
#define ull unsigned long long
#define cint const int&
#define Pi acos(-1)

const int mod = 1e9+7;
const int inf_int = 0x7fffffff;
const ll inf_ll = 0x7fffffffffffffff;
const double ept = 1e-9;

int n;
int h[100100], nx[200200], to[200200], ct;
int siz[100100];
int q[100100], cnt;

void add(cint f, cint t) {
    nx[++ct] = h[f];
    h[f] = ct;
    to[ct] = t;
}

int dfs(cint loc, cint fa) {
    int r= -111;
    int ans = -1, oth = 0;
    vector<int > d;
    for(int i=h[loc]; i; i = nx[i])
        if(to[i] != fa) {
            r = dfs(to[i], loc);
            siz[loc] += siz[to[i]];
            if(!(siz[to[i]] & 1) && r > 0) ans += r;
            else if(!(siz[to[i]] & 1) && r < 0) oth += r;
            else if((siz[to[i]] & 1)) d.push_back(r);
        }
    int nt = d.size();
    for(int i=0; i<nt; i++) q[i+1] = d[i];
    sort(q+1, q+1+nt);
    for(int i=nt; i>=1; i--)
        if(!((nt-i) & 1)) ans += q[i];
        else ans -= q[i];
    if(nt & 1) ans -= oth;
    else ans += oth;
    return ans;
}

int main() {
    cin >> n;
    int r;
    for(int i=2; i<=n; i++) {
        cin >> r;
        add(r, i);
        add(i, r);
        siz[i] = 1;
    }
    cout << (n-dfs(1, 1))/2 << endl;
    return 0;
}
/*
3
1 2
*/


#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define fi first
#define se second
#define pub push_back
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for(int i=(int)(l);i<(int)(r);i++)
#define repd(i, l, r) for (int i=(int)(l);i>=(int)(r);i--)
#define clrg(i, l, r) for(int i=(int)(l);i<(int)(r);i++)vis[i]=0,v[i].clear();
int power(int x, unsigned int y){int res = 1;while (y > 0){ if (y & 1){res = res*x;} y = y>>1;x = x*x;}return res;}
int powermod(int x, unsigned int y, int p){int res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}
#define print2d(mat,n,m){for(int i=0;i<(int)(n);i++){for(int j=0;j<(m);j++){cout<<mat[i][j]<<" ";}cout<< endl;}}
#define clr(a,x) memset(a,x,sizeof(a))
#define rr(v) for(auto &val:v)
#define print(v) for (const auto itr : v){cout<<itr<<' ';}cout<<"\n";
#define ln length()
#define sz size()
#define mod 1000000007
#define elif else if
int32_t main(){
   fastIO
   string st; cin>>st;
   int ans=0;
    rep(i,0,10){
        rep(j,0,10){
            rep(k,0,10){
                rep(p,0,10){
                    string s="";
                    s+=char('0'+i);
                    s+=char('0'+j);
                    s+=char('0'+k);
                    s+=char('0'+ p);
                    bool okk=1;
                    rep(c,0,10){
                        if(st[c]=='o'){
                            bool ok=0;
                            rep(c1,0,4){
                                if((s[c1])-'0'==c)ok=1;
                            }
                            if(!ok)okk=0;
                        }
                        elif(st[c]=='x'){
                            bool ok=1;
                            rep(c1,0,4){
                                 if((s[c1])-'0'==c)ok=0;
                            }
                            if(!ok)okk=0;
                        }
                    }
                    if(okk)ans++;
                }
            }
        }
    }
    cout<<ans<<"\n";
   return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define reps(i, a, n) for (int i = (a); i < (n); ++i)
#define rep(i, n) reps(i, 0, n)
#define deps(i, a, n) for (int i = (a); i >= (n); --i)
#define dep(i, n) deps(i, n, 0)
#define inf LLONG_MAX
#define int long long
#define mod 998244353

int h, w;
string s[500];
int ans = 1;

signed main(void)
{
	cin >> h >> w;
	rep (i, h) cin >> s[i];

	rep (k, inf)
	{
		int i, j;
		j = min(w-1, k);
		i = k-j;
		if (i >= h) break;
		int r = 0, b = 0, d = 0;
		while (1)
		{
			if (s[i][j] == 'R') r++;
			if (s[i][j] == 'B') b++;
			if (s[i][j] == '.') d++;
			if (r > 0 && b > 0) {ans *= 0; break;}

			j--;
			i++;
			if (j < 0) break;
			if (i >= h) break;
		}
		if (ans == 0) break;
		if (r == 0 && b == 0) {ans *= 2; ans %= mod;}
	}

	cout << ans << endl;
}

/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("[DEBUG] ");W(__VA_ARGS__);}
#else
 #define DEBUG(...)
#endif
/*}}}*/
int MOD = 998244353;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
const int SIZE = 1<<20;
string s[SIZE];
int n,m;
int cnt[SIZE][3];
void solve() {
    REP(i,n){
        REP(j,m){
            if(s[i][j]=='B')cnt[i+j][0]++;
            else if(s[i][j]=='R')cnt[i+j][1]++;
            else cnt[i+j][2]++;
        }
    }
    LL an=1;
    REP(i,n+m-1){
        if(cnt[i][0]&&cnt[i][1]){
            W(0);
            return;
        }
        if(!cnt[i][0]&&!cnt[i][1]){
            an=an*2%MOD;
        }
    }
    W(an);
}
void input() {
    R(n,m);
    REP(i,n)R(s[i]);
}
int main(){
    input();
    solve();
    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define nl "\n"
#define vec vector<ll>
#define pb push_back
#define MOD 1000000007
#define test ll testc;cin>>testc;while(testc--)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
ll bpow(ll a,ll b) {ll ans=1;while (b>0){if (b&1) ans=(ans*a)%MOD;b/=2;a=(a*a)%MOD;}return ans;}
int main()
{
	#ifndef ONLINE_JUDGE
    	freopen("input.txt", "r", stdin);
    	freopen("output.txt", "w", stdout);
    	#endif
    	fast
    	{
    		ll n; cin>>n;
    		ll a[n];
    		ll t=0;
    		for(int i=0;i<n;i++)
    		{
    			cin>>a[i];
    			t+=a[i];
    		}
    		ll x[100000+1]={0};
    		x[0]=1;
    		for (int i=0;i<n;i++)
    		{
    			for (int j=100000;j>=0;j--)
    			{
    				if (x[j]>0) x[j+a[i]]=1;
    			}
    		}
    		for (int i=0;i<=100000;i++)
    		{
    			if (i>=(t+1)/2 and x[i]>0)
    			{
    				cout<<i<<nl;
    				break;
    			}
    		}
    	}

}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INCANT cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(12)
const int INF = 1e9 + 7;
const ll LINF = 1e18 + 7;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
void debug_out();
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T);
#ifdef MY_DEBUG
#define dbg(...) debug_out(__VA_ARGS__)
#define dbgs(x) cout << "\033[33m" << x << "\033[m"　<< " "
#define dbge cout << endl
#else
#define dbg(...)
#define dbgs(x)
#define dbge
#endif
template <class T> bool chmax(T &, const T &);
template <class T> bool chmin(T &, const T &);
template <class T> T pwr(T, ll);
template <class T> T squ(T);
ll fact(ll);
ll comb(ll, ll);

int main() {
    INCANT;
    int n;
    cin >> n;
    vector<int> t(n);
    for (int i = 0; i < n; i++) cin >> t[i];

    vector<vector<bool>> dp(n, vector<bool>(110000, false));
    dp[0][0] = true, dp[0][t[0]] = true;
    for (int i = 1; i < n; i++) {
        for (int j = 0; j < 110000; j++) {
            if (dp[i - 1][j] == true) {
                dp[i][j + t[i]] = true;
                dp[i][j] = true;
            }
        }
    }

    int ans = INF;
    int sum = accumulate(t.begin(), t.end(), 0);
    for (int i = 0; i < 110000; i++) {
        if (dp[n-1][i] == true) chmin(ans, max(i, sum-i));
    }

    cout << ans << endl;
}

/*

-----------------------------------MY_FUNCTION------------------------------------ */

void debug_out() {
    cout << endl;
}

template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
    cout << "\033[33m" << H << "\033[m"
         << " ";
    debug_out(T...);
}

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

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

template <class T> T pwr(T x, ll n) {
    T ans = 1;
    for (int i = 0; i < n; i++) {
        ans *= x;
    }
    return ans;
}

template <class T> T squ(T x) {
    return x * x;
}

ll fact(ll n) {
    ll res = 1;
    for (ll i = 1; i <= n; i++) res *= i;
    return res;
}

ll comb(ll n, ll r) {  // comb(60, 30)までオーバーフローなし
    ll res = 1;
    for (int i = 1; i <= r; i++) {
        res *= n--;
        res /= i;
    }
    return res;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define ld long double
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define pii pair<int,int>
#define pll pair<ll,ll>
#define INF 1e9
#define INFL 1e18
#define mod 1000000007
//#define mod 998244353
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> os;
typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> os_pair;

ll power(ll x,ll n){ll res =1;while(n>0){if(n%2==1){res=res*x;}x=x*x;n=n/2;}return res;}
ll powm(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

//cout<< fixed << setprecision(10)
//__builtin_popcountll()

int main(){

    fast;
    int n,i,j;
    cin>>n;
    int a[n+1];
    for(i=1;i<=n;i++)
    cin>>a[i];
    set<int>s;
    for(i=1;i<n;i++)
    s.insert(i);
    vector<int>ans;
    for(i=1;i<=n;i++)
    {
    	if(a[i]==i)
    	{
    		cout<<-1;
    		return 0;
		}
    	if(a[i]>i)
    	continue;
    	else
    	{
    		for(j=i-1;j>=a[i];j--)
    		{
    			if(s.find(j)==s.end())
    			{
    				cout<<-1;
    				return 0;
				}
				else
				{
					s.erase(j);
					ans.pb(j);
				}
			}
		}
	}
	if(s.size()==0)
	{
		for(i=0;i<ans.size();i++)
		cout<<ans[i]<<" ";
	}
	else
	{
		cout<<-1;
	}

}

#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, init, end) for(ll i = init; i < end; i++)
#define REP(i, init, end) for(ll i = init; i < end + 1; i++)
#define rev(i, end, init) for(ll i = init - 1; i >= end; i--)
#define REV(i, end, init) for(ll i = init; i >= end; i--)
#define PI 3.14159265359
// #define EPS 0.0000000001
// #define MOD 1000000007
#define INF 100000000000000000
// #define MAX 100000000000
//cout << std::fixed << std::setprecision(15) << y << endl;

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

    string S, X;
    cin >> S >> X;

    ll dp[N][7]; // 0: Takahashi wins, 1: Aoki wins
    rep(i, 0, N){
        rep(j, 0, 7){
            dp[i][j] = -1;
        }
    }

    rep(j, 0, 7){
        if(X[N - 1] == 'A'){
            if(j == 0 && (S[N - 1] == '0' || S[N - 1] == '7')){
                dp[N - 1][j] = 0;
            }else{
                dp[N - 1][j] = 1;
            }
        }else{
            if(j == 0){
                dp[N - 1][j] = 0;
            }else{
                if(((j * 10) + (S[N - 1] - '0')) % 7 == 0){
                    dp[N - 1][j] = 0;
                }else{
                    dp[N - 1][j] = 1;
                }
            }
        }
    }

    rev(i, 0, N - 1){
        rep(j, 0, 7){
            if(X[i] == 'A'){
                dp[i][j] = max(dp[i + 1][(j * 10) % 7], dp[i + 1][((j * 10) + (S[i] - '0')) % 7]);
            }else{
                dp[i][j] = min(dp[i + 1][(j * 10) % 7], dp[i + 1][((j * 10) + (S[i] - '0')) % 7]);
            }
        }
    }

    if(dp[0][0] == 0){
        cout << "Takahashi" << endl;
    }else{
        cout << "Aoki" << endl;
    }

    return 0;
}


/*
 * author: cyclexit
 * start from: 2021-01-05 10:21
 */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

inline double slope(pair<double, double> x, pair<double, double> y) {
  return fabs(y.second - x.second) / fabs(y.first - x.first);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<pair<double, double>> point(n);
  for (int i = 0; i < n; ++i) {
    cin >> point[i].first >> point[i].second;
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      if (point[i].first != point[j].first) {
        if (-1.0 <= slope(point[i], point[j]) && slope(point[i], point[j]) <= 1.0) {
          ++ans;
        }
      }
    }
  }
  cout << ans << '\n';
  return 0;
}

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

using namespace std;
using namespace __gnu_pbds;

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

template <typename T>
using ordered_set = __gnu_pbds::tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

ll gcd(ll a, ll b){
  if (b==0) return a;
  return gcd(b, a%b);
}
const int N = 2000;
ll a[N];
unordered_map<int, int> gcds;
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n; cin >> n;
  ll lo = 1e18;
  for (int i = 0; i < n; i++){
    cin >> a[i];
    lo = min(a[i], lo);
  }

  for (int i = 0; i < n; i++){
    for (int d = 1; d*d <= a[i]; d++){
      if (a[i]%d != 0) continue;
      gcds[d] = gcd(gcds[d], a[i]);
      gcds[a[i]/d] = gcd(gcds[a[i]/d], a[i]);
    }
  }

  int ans = 1;
  for (auto g : gcds){
    if (g.first == g.second && g.first < lo) ans++;
  }
  cout << ans << endl;
  return 0;
}


#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = (1LL << 61);
#define int long long

signed main() {
	int H, W; cin >> H >> W;
	vector<vector<int>>A(H, vector<int>(W));
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++)cin >> A[i][j];
	}
	int ans = INF;
	for (int k = 0; k <= 100; k++) {
		int now = 0;
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				if (A[i][j] < k) {
					now = INF;
					break;
				}
				now += A[i][j] - k;
			}
		}
		ans = min(ans, now);
	}
	cout << ans << endl;
}

//00:04
#include <bits/stdc++.h>
using namespace std;
long long inf = 1000000007;
typedef long long ll;

int main(){
    int h, w, small = 101, cnt = 0;
    cin >> h >> w;
    vector<vector<int>> a(h, vector<int>(w, 0));
    for(vector<int>& a1:a){
        for(int& v: a1) cin >> v;
    }
    for(int i=0; i<h; ++i){
        for(int& v: a[i]){
            if(v < small) small = v;
        }
    }
    for(int i=0; i<h; ++i){
        for(int& v: a[i]){
            cnt += v - small;
        }
    }
    cout << cnt << endl;
    return 0;
}


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

//Template Begin
#define ll long long
#define int long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define be begin()
#define en end()
#define le length()
#define endl '\n'

using VI=vector<int>;
using VLL=vector<ll>;
using PII=pair<int, int>;
using PLL=pair<ll, ll>;
using VPII = vector< PII >;

#define TC(t) while (t--)
#define REP(i,from,to)      for(auto i=(from); i<=(to); ++i)
#define PER(i,from,to)      for(auto i=(from); i>=(to); --i)
#define REPITER(it, a)		for(__typeof(a.begin()) it = a.begin();it != a.end(); ++it)

#define FOR(i,less_than)    for (auto i=0; i<(less_than); ++i)
#define FORI(i, container)  for (auto i=0; i<(container).size(); ++i)
#define ROFI(i, container)  for (auto i=SZ(container)-1; i>=0; --i)

#define FOREACH(elem, container)  for (auto &elem : (container))
#define MEMSET(container, value)  memset(container, value, sizeof(container))
#define MEMSET0(container)        memset(container, 0, sizeof(container))
#define FILL(container, value)    fill(container.begin(), container.end(), value)
#define FILL0(container)    	  fill(container.begin(), container.end(), 0)
#define ALL(container)            (container).begin(), (container).end()
#define SZ(container)             (int)((container).size())
#define POP(var, container) auto var=(container.front()); container.pop();

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

template<typename T> T abs(T a) { return a < 0 ? -a : a; }
//Template End

int a[32]={0};
void calc() {
	a[0]=1;
	REP(i, 1, 32) a[i] = (a[i-1]*i)/__gcd((long long)i, a[i-1]);
}
void solve() {
	int n;
	cin>>n;
	cout<<a[n]+1<<endl;
}

signed main() {
	#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output1.txt", "w", stdout);
    #endif

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	// your code goes here
	int t=1;
	// cin>>t;
	calc();
	TC(t) solve();
	return 0;
}

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

typedef long long ll;
ll mod = 1000000007;
const double PI = 3.141592653589793238460;
const int INF = 1e9+5;
const ll lINF = 1e16+1;

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;

    vector<ll> isprime = {2,3,5,7,11,13,17,19,23,29};

    ll ans = 1;
    ans*=16;
    ans*=27;
    ans*=25;
    ans*=7;
    ans*=11;
    ans*=29;
    ans*=23;
    ans*=19;
    ans*=13;
    ans*=17;
    ans++;
    // for(int i=2; i<=n; i++){
    //     cout<<(ans)%i<<' ';
    // }
    // cout<<endl;
    cout<<ans;

    return 0;
}


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

const int max_l = 1000;

char mp[max_l][max_l+1];
int dsu[max_l<<1];

inline int my_min(int a, int b) { return (a < b)? a:b; }

int find(int x)
{
	if (dsu[x] != x) dsu[x] = find(dsu[x]);
	return dsu[x];
}

bool sam(int a, int b) { return find(a) == find(b); }

void unite(int a, int b)
{
	if (!sam(a, b))
		dsu[find(a)] = find(b);
}

int main()
{
	int h, w;
	set<int> rw, cl;

	scanf("%d%d", &h, &w);
	for (int i = 0; i < h; i++)
		scanf("%s", mp[i]);

	for (int i = 0; i < h + w; i++)
		dsu[i] = i;

	mp[0][0] = mp[0][w-1] = mp[h-1][0] = mp[h-1][w-1] = '#';
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++)
			if (mp[i][j] == '#')
				unite(i, j + h);

	for (int i = 0; i < h; i++)
		rw.insert(find(i));
	for (int i = 0; i < w; i++)
		cl.insert(find(i+h));

	printf("%d\n", my_min(rw.size(), cl.size()) - 1);

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define int long long
vector<set<int>> v;
vector<char> colour;
bool isValid(int i, char c){
    if(colour[i]!='.' && colour[i]!=c){
        return false;
    }
    for(auto z:v[i]){
        if(colour[z]==c){
            return false;
        }
    }
    return true;
}
int ways=0,n;
void f(int i,char c){
    if(i>=n || i<0 || !isValid(i,c)){
        return;
    }
    char x=colour[i];
    colour[i]=c;
    if(i==n-1){
        ways++;
        colour[i]=x;
        return;
    }
    f(i+1,'R');
    f(i+1,'G');
    f(i+1,'B');
    colour[i]=x;
}
vector<int> vis;
void dfs(int i,vector<int>&ps){
    if(vis[i]==0){
        vis[i]=1;
        ps.push_back(i);
        for(auto z:v[i])dfs(z,ps);
    }
}
void solve(){
    cin>>n; int m; cin>>m;
    v.resize(n);
    vis.resize(n,0);
    colour.resize(n,'.');
    while(m--){
        int a,b; cin>>a>>b; a--; b--;
        v[a].insert(b);
        v[b].insert(a);
    }
    int ans=1;
    for(int i=0;i<n;i++){
        vector<int> vvv;
        dfs(i,vvv);
        map<int,int> mv;
        int nn=vvv.size();
        set<int> sv;
        if(nn>0){
            for(int j=0;j<nn;j++){
              // cout<<vvv[j]<<" ";
                mv[vvv[j]]=j;
                sv.insert(vvv[j]);
            }
            vector<set<int>> temp(nn),temp1;
            temp1=v;
            for(int j=0;j<n;j++){
                if(sv.find(j)!=sv.end()){
                    for(auto z:v[j]){
                        if(sv.find(z)!=sv.end()){
                            temp[mv[j]].insert(mv[z]);
                        }
                    }
                }
            }
            int xxxx=n;
            v=temp;
            n=nn;
            colour.clear();
            colour.resize(n,'.');
            f(0,'R');
            ways*=3;
            ans*=ways;
            // cout<<ans<<"\n";
            ways=0;
            n=xxxx;
            v=temp1;
        }
    }
    cout<<ans;
}
signed main(){
    // time_t start, end;
    // time(&start);
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int tt=1,t=1; //cin>>tt;
    while(t<=tt){
        //cout<<"Case #"<<t<<": ";
        solve();
        cout<<"\n";
        t++;
    }
    // time(&end);
    // double time_taken = double(end - start);
    // cout << "Time taken by program is : " << fixed << time_taken << setprecision(5);
    // cout << " sec " << endl;
    return 0;
}


#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<vector>
#include<cstdio>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>

using namespace std;
#define SZ(v) ((int)(v).size())
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef pair<int,int> PII;

template<class T>
inline void relax(T& a,const T& b) { a=((a>b) ? a : b); }
template<class T>
inline void tense(T& a,const T& b) { a=((a<b) ? a : b); }

template<class T>
inline void read(T& x)
{
	x=0;
	register bool sign=false;
	register char c;
	for(c=getchar();c<'0' || c>'9';c=getchar())
		if(c=='-') sign=true;
	for(;c>='0' && c<='9';c=getchar())
		x=(x<<1)+(x<<3)+(c&15);
	if(sign) x=~x+1;
}

const int N=4e5+5;
const LL P=998244353;

int n;
LL a[N];

LL power(LL x,LL k,LL MOD)
{
	LL res=1; x%=MOD;
	while(k) {
		if(k&1) res=res*x%MOD;
		x=x*x%MOD; k>>=1;
	}
	return res%MOD;
}

int main()
{
//	freopen("1.in","r",stdin);
	int i;

	read(n);
	for(i=1;i<=n;i++) read(a[i]);
	sort(a+1,a+n+1);

	LL val=0;
	for(i=1;i<=n;i++)
		val=(val+a[i]*power(2,i-1,P))%P;

	LL ans=0;
	for(i=1;i<=n;i++) {
		val=(val-a[i]+P)*power(2,P-2,P)%P;
		ans=(ans+val*a[i])%P;
		ans=(ans+a[i]*a[i])%P;
	}
	printf("%lld\n",ans);
	return 0;
}

#include <bits/stdc++.h>
#define fo(i, k, n) for (ll i = k; i < n; i++)
#define rfo(i, k, n) for (ll i = k; i >= n  ; i--)
#define ll long long
#define ld long double
#define que queue
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vl vector<ll>
#define gcd(m,n) __gcd( m,  n)
#define sq(x)   (x*x)
#define rev(v)  reverse(v.begin(),v.end())
#define srt(v)  sort(v.begin(),v.end())
#define grtsrt(v) sort(v.begin(),v.end(),greater<int>())
#define mnv(v)     *min_element(v.begin(),v.end())
#define mxv(v)    *max_element(v.begin(),v.end())
#define all(v)    v.begin(),v.end()
#define toInteger(s) stoll(s)
#define toString(num) to_string(num)

using namespace std;
ll MOD = 1e9 + 7;
//--------------------------------------------functions-------------------------------------------------//

ll power(ll a,ll b){ll result=1;while(b>0){if(b%2 == 1){result *= a;} a *= a;b /= 2;}return result;}
ll countSetBits(ll x){ll Count=0;while(x>0){if(x&1) Count++;x=x>>1;}return Count;}
bool isPerfectSquare(ll n){ll sr = sqrt(n);if (sr * sr == n)return true;else return false;}
ll mod(ll x,ll M){return ((x%M + M)%M);}
ll mul(ll a, ll b,ll M){return mod(mod(a,M)*mod(b,M),M);}
ll powerM(ll a,ll b,ll M){
    ll res=1ll;
    while(b){
        if(b%2ll==1ll){
            res=mul(a,res,M);
        }
        a=mul(a,a,M);b/=2ll;
    }
    return res;
}
int log22(long long x)
{
    return 64 - __builtin_clzll(x) - 1;
}

//--------------------------------------------SieveOfEratosthenes-------------------------------------------------//
//mem will have true if its prime.
void SieveOfEratosthenes( vector<bool>&mem)
{ ll n = 1e6 +1;

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

     fo(i,2,n)
     if(prime[i])mem[i]=true;

}

//--------------------------------------------solve-------------------------------------------------//

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
 // freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);

  int n;
  cin>>n;

  vector<int>v(n);
  fo(i,0,n)
  cin>>v[i];
 ll ans = 0;
  fo(i,0,n)
  {
    if(v[i]>10)
        ans += v[i]-10;
  }
 cout<<ans;

  return 0;
}


/*  -*- coding: utf-8 -*-
 *
 * d.cc: D - Cooking
 */

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

using namespace std;

/* constant */

const int MAX_N = 100;
const int MAX_T = 1000;
const int MAX_S = MAX_N * MAX_T;

/* typedef */

/* global variables */

int ts[MAX_N];
bool dp[MAX_S + 1];

/* subroutines */

/* main */

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

  for (int i = 0; i < n; i++) scanf("%d", ts + i);

  dp[0] = true;
  int s = 0;
  for (int i = 0; i < n; i++) {
    for (int j = s; j >= 0; j--)
      if (dp[j]) dp[j + ts[i]] = true;
    s += ts[i];
  }

  int mint = s;
  for (int i = 0; i <= s; i++)
    if (dp[i]) mint = min(mint, max(i, s - i));

  printf("%d\n", mint);
  return 0;
}

//Code by Anshuman Das Gupta

#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define MOD 1000000007
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define loop(I,N) for(int i=I;i<N;i++)
#define sortvec(V) sort(V.begin(),V.end())
#define vec vector<int>
#define endl "\n"
using namespace std;
#define PI 3.14159265359
int fast_power(int base, int power) {
    int result = 1;
    while (power > 0) {

        if (power & 1) {
            result = (result * base) % MOD;
        }
        base = (base * base) % MOD;
        power = power >> 1;
    }
    return result % MOD;
}

bool isPrime(int x) {
    for (int i = 2; i <= sqrt(x); i++) {
        if (x % i == 0)
            return false;
    }
    if (x == 1)
        return false;
    return true;
}

int binsearch(int a[], int f, int r, int x) {
    while (f <= r) {
        int mid = (f + r) / 2;
        if (a[mid] == x)
            return mid;
        else if (a[mid] > x) {
            r = mid - 1;
        }
        else {
            f = mid + 1;
        }
    }
    return -1;
}
void sieve(int a[], int n) {
    a[0] = 0;
    a[1] = 0;
    for (int i = 2; i <= n; i++) {
        if (a[i] == 1) {
            for (int j = i + i; j <= n; j += i) {
                a[j] = 0;
            }
        }
    }
}

int32_t main() {
    int t = 1;
    //cin >> t;
    while (t--) {
        int n;
        cin >> n;
        cout << n - 1 << endl;

    }
}


/* Hardwork allways pays off */
//You never know how close to the solution you are ,so keep practicing
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define endl '\n'
#define REP(i,n) for(int i=1;i<=n;i++)
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower)
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define mod1 998244353
#define mod 1000000007
#define pie 3.141592653589793238
#define printv(x) for(i=0;i<x.size();i++) cout<<x[i]<<" ";
#define printA(x,n) for(i=0;i<n;i++) cout<<x[i]<<" ";
void make_unique(vector<int> vec)
{
sort(all(vec));
vec.resize(unique(all(vec)) - vec.begin());
}

bool isPowerOfTwo(int n)
{
   if(n==0)
   return false;

   return (ceil(log2(n)) == floor(log2(n)));
}
int cceil(int x, int y){
    return (x+y-1)/y;
}
bool cmp(const pair<int,int> &a,
                   const pair<int,int> &b)
{
       return (a.second+a.first)>(b.second+b.first);
}
int x,y;
int ans=1e18;
// int dp[]
map<int,int> dp,vis;
// int count=0;
int repeat(int y)   //return min steps to reach x from y by -1,+1,/2
{
    // cout<<y<<endl;
    // ans=abs(y-x);
    if(vis[y])
        return dp[y];
    vis[y]=1;
    dp[y]=1e18;
    int &ans=dp[y];
    ans=min(ans,abs(y-x));
    if(y==1)
        return ans;
    else if(y<x)
        return x-y;
    else
    {
        if(y%2==0)
            ans= min(ans,(1+repeat(y/2)));
        else
        {
            ans= min(ans,1+min(repeat(y-1),repeat(y+1)));
        }
    }
    return ans;

}
signed main()
 {   ios;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    // cout.precision(1);
    // cout<<fixed;
    int t=1;
     // cin>>t;
    while(t--)
    {int n,k,i,m,j,flag=1,moves=0,count=0;
       // cin>>n;
        // int x,y;
        cin>>x>>y;
        if(x>=y)
            cout<<x-y<<endl;
        else
        {
            int ans=repeat(y);
            cout<<ans<<endl;
        }

    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> pi;
#define f first
#define s second
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);
#define all(x) x.begin(),x.end()
typedef pair<int, pi> pii;

const int maxn = 500010;
const int INF = LLONG_MAX/2;

int x, Y;

map <int, int> dp;
int dpf(int y) {
	if (y <= x) return x - y;
	if (dp.find(y) != dp.end()) return dp[y];

	if (y % 2 == 0) {
		if (y/2 >= x) dp[y] = dpf(y/2) + 1;
		else dp[y] = min(x - y/2 + 1, y - x);
	} else {
		dp[y] = 1 + min(dpf(y+1), dpf(y-1));
	}
	return dp[y];
}

int32_t main() {
	FAST
	cin >> x >> Y;

	cout << dpf(Y);
}


#include<iostream>

using namespace std;
typedef long long ll;
int main() {
    ll n;
    cin>>n;
    ll ans=0;
    for (ll i=1; ; i++) {
        string s=to_string(i)+to_string(i);
        ll t=stoll(s);
        if (t>n) {
            cout<<i-1<<"\n";
            return 0;
        }
    }
    return 0;
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int MAX_N = 300000 + 5;
const int INF32 = 0x3f3f3f3f;
int n;
double ans;

int main() {
    scanf("%d", &n);
    for (int i = 1; i < n; i ++) ans += (double)n / i;
    printf("%.10lf\n", ans);
    return 0;
}


#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
#define rprintf(fmt, begin, end) do { const auto end_rp = (end); auto it_rp = (begin); for (bool sp_rp=0; it_rp!=end_rp; ++it_rp) { if (sp_rp) putchar(' '); else sp_rp = true; printf(fmt, *it_rp); } putchar('\n'); } while(0)

template<unsigned MOD_> struct ModInt {
    static constexpr unsigned MOD = MOD_;
    unsigned x;
    void undef() { x = (unsigned)-1; }
    bool isnan() const { return x == (unsigned)-1; }
    inline int geti() const { return (int)x; }
    ModInt() { x = 0; }
    ModInt(int y) { if (y<0 || (int)MOD<=y) y %= (int)MOD; if (y<0) y += MOD; x=y; }
    ModInt(unsigned y) { if (MOD<=y) x = y % MOD; else x = y; }
    ModInt(long long y) { if (y<0 || MOD<=y) y %= MOD; if (y<0) y += MOD; x=y; }
    ModInt(unsigned long long y) { if (MOD<=y) x = y % MOD; else x = y; }
    ModInt &operator+=(const ModInt y) { if ((x += y.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(const ModInt y) { if ((x -= y.x) & (1u<<31)) x += MOD; return *this; }
    ModInt &operator*=(const ModInt y) { x = (unsigned long long)x * y.x % MOD; return *this; }
    ModInt &operator/=(const ModInt y) { x = (unsigned long long)x * y.inv().x % MOD; return *this; }
    ModInt operator-() const { return (x ? MOD-x: 0); }

    ModInt inv() const { return pow(MOD-2); }
    ModInt pow(long long y) const {
	ModInt b = *this, r = 1;
	if (y < 0) { b = b.inv(); y = -y; }
	for (; y; y>>=1) {
	    if (y&1) r *= b;
	    b *= b;
	}
	return r;
    }

    friend ModInt operator+(ModInt x, const ModInt y) { return x += y; }
    friend ModInt operator-(ModInt x, const ModInt y) { return x -= y; }
    friend ModInt operator*(ModInt x, const ModInt y) { return x *= y; }
    friend ModInt operator/(ModInt x, const ModInt y) { return x *= y.inv(); }
    friend bool operator<(const ModInt x, const ModInt y) { return x.x < y.x; }
    friend bool operator==(const ModInt x, const ModInt y) { return x.x == y.x; }
    friend bool operator!=(const ModInt x, const ModInt y) { return x.x != y.x; }
};

constexpr LL MOD = 1000000007;
using Mint = ModInt<MOD>;

int N;
LL M;
LL A[2011];

void MAIN() {
    scanf("%d%lld", &N, &M);
    REP (i, N) scanf("%lld", A+i);

    LL sum = 0;
    REP (i, N) sum += A[i];
    if (sum > M) {
	puts("0");
	return;
    }

    Mint nu = 1;
    Mint de = 1;
    REP (a, sum+N) {
	de *= a+1;
	nu *= M+N-a;
    }

    Mint ans = nu / de;

    printf("%d\n", ans.geti());
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}

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

template<int MAX>
struct Combination {
    vector<long long> _inv, _fac, _ifac;
    const long long MOD;
    Combination(long long mod) : _inv(MAX+1), _fac(MAX+1), _ifac(MAX+1), MOD(mod) { init(); }
    void init() { init_inv(), init_fac(); }

    void init_inv() {
        _inv[0] = 0;
        for (int i = 1; i <= MAX; i++) {
            if (i == 1) _inv[i] = 1;
            else {
                _inv[i] = (MOD - (MOD / i) * _inv[MOD % i]) % MOD;
                if (_inv[i] < 0) _inv[i] += MOD;
            }
        }
    }
    void init_fac() {
        _fac[0] = _ifac[0] = 1;
        for (int i = 1; i <= MAX; i++) {
            _fac[i] = _fac[i-1] * i % MOD;
            _ifac[i] = _ifac[i-1] * _inv[i] % MOD;
        }
    }

    long long modpow(long long n, long long r) {
        n %= MOD, r %= (MOD-1);
        if (!n) return 0;
        long long ret = 1; long long tmp = n;
        while (r != 0) {
            if (r % 2) ret *= tmp;
            tmp *= tmp; tmp %= MOD; ret %= MOD;
            r /= 2;
        }
        return ret;
    }
    long long invb(int i) { return (i <= MAX) ? _inv[i] : this->modpow(i, MOD-2); }
    long long inv(int i) const { return _inv[i]; }
    long long fac(int i) const { return _fac[i]; }
    long long ifac(int i) const { return _ifac[i]; }

    long long operator()(int n, int r) const {
        if (n < r) return 0;
        return fac(n) * ifac(r) % MOD * ifac(n-r) % MOD;
    }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N, M; cin >> N >> M;
    constexpr long long mod = 1000000007;
    Combination<5000000> C(mod);
    long long Ans = 1;
    vector<int> A(N);
    int S = 0;
    for (auto &x: A) {
        cin >> x; S += x;
    }
    for (int i = 1; i <= N + S; i++) {
        Ans = Ans * C.invb(i) % mod;
        Ans = Ans * (M + N + 1 - i) % mod;
    }
    cout << Ans << "\n";
    return 0;
}


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

#define mnto(x, y) x = min(x, (__typeof__(x)) y)
#define mxto(x, y) y = max(x, (__typeof__(x)) y)
#define REP(i, s, e) for (int i = s; i < e; i++)
#define RREP(i, s, e) for (int i = s - 1; i >= e; i--)
typedef long long ll;
#define ALL(_a) _a.begin(), _a.end()
#define pb emplace_back
typedef vector<int> vi;
#define MP make_pair
#define FI first
#define SE second
typedef pair<int, int> ii;
#define MT make_tuple
typedef tuple<int, int, int> iii;

#define INF 1000000005
#define LINF 100000000000000005
#define MOD 1000000007
#define MAXN 200005
#define MAXA 400005

int n;
int in[MAXA];
vector<int> adjList[MAXA];
set<ii> st;
bool erased[MAXA];

int main() {
	scanf("%d", &n);
	REP (i, 0, n) {
		int a, b; scanf("%d%d", &a, &b);
		in[a]++;
		adjList[a].pb(b);
		if (a != b) {
			in[b]++;
			adjList[b].pb(a);
		}
	}
	REP (i, 1, MAXA) {
		if (in[i] == 0) continue;
		st.emplace(in[i], i);
	}
	int ans = 0;
	while (!st.empty()) {
		ii cur = *st.begin(); st.erase(st.begin());
		if (erased[cur.SE]) continue;
		for (int v : adjList[cur.SE]) {
			if (erased[v]) continue;
			st.erase(MP(in[v], v));
			in[v]--;
			if (in[v] > 0) st.emplace(MP(in[v], v));
			break;
		}
		erased[cur.SE] = true;
		ans++;
	}
	printf("%d\n", ans);
	return 0;
}

#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn=2e5,maxm=4e5;
int n;
int f[maxm+5];
int szp[maxm+5],sze[maxm+5];
int ans;
int find(int x){
	return x==f[x]?x:f[x]=find(f[x]);
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=maxm;i++) f[i]=i,szp[i]=1;
	for(int i=1,a,b;i<=n;i++){
		scanf("%d %d",&a,&b);
		int fa=find(a),fb=find(b);
		if(fa==fb) sze[fa]++;
		else{
			f[fb]=fa; szp[fa]+=szp[fb]; sze[fa]+=sze[fb]+1;
		}
	}
	ans=maxm;
	for(int i=1;i<=maxm;i++)
		if(i==find(i))
			if(sze[i]==szp[i]-1) ans--;
	printf("%d\n",ans);
	return 0;
}


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

using namespace std;

#define ll long long int
#define f(i,l,n) for(int i=l;i<n;i++)
#define E "\n"
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
#define vi(typ) vector<typ>
#define Ee cout<<"\n";

ll n,m;
vector<ll> graph[2005],visited(2005,0),dis(2005,0);
bool isvalid=0;
ll org,adj[2002][2002],val;
void dfs(ll node)
{
 // cout<<node<<E;
  for(auto x:graph[node])
  {

    if(x==org )
    {
      val=min(val,dis[node]+adj[node][x]);

    }
   // if(node==3) cout<<x<<" "<<val<<" "<<dis[node]<<" "<<adj[node][x]<<E;
    if(dis[node]+adj[node][x]<dis[x])
    {
      visited[x]=1;
      dis[x]=min(dis[x],adj[node][x]+dis[node]);
      dfs(x);
    }

  }
}

ll solve()
{

  cin >> n >> m;
  f(i,0,m)
  {
    ll x,y,c;
    cin >> x >> y >> c;

    if(adj[x][y]==0)
    {
      adj[x][y]=c;
      graph[x].push_back(y);
    //  graph[y].push_back(x);
    }
    else adj[x][y]=min(adj[x][y],c);

  }

  f(i,1,n+1)
  {
    f(j,1,n+1) visited[j]=0,dis[j]=1e15;
    org=i,val=1e15;
    visited[i]=1;
    dis[i]=0;
    dfs(i);
    if(val==1e15) cout<<"-1\n";
    else cout<<val<<E;

  }

  return 0;
}

int main()
{

   #ifndef ONLINE_JUDGE
      freopen("input.txt","r",stdin);
      freopen("output.txt","w",stdout);
      #endif
     ll t = 1;
     fast;
   //  cin >> t;
     while(t--)
     {
          int l=solve();
         // cout<<"hii\n";
     }

     return 0;
}


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

#define BOOST ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rept(it,v) for(auto it=v.begin();it!=v.end();it++)
#define pre(i,a,b) for(int i=a;i>=b;i--)
#define mp make_pair
#define pb push_back
#define endl "\n"
#define mod 1000000007
#define ll long long
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define all(x) x.begin(),x.end()
#define sp(x) setprecision(x)
#define lb lower_bound
#define ub upper_bound
#define ll long long
#define pb push_back
#define pob pop_back
#define mt make_tuple
#define F first
#define S second
#define endl "\n"
#define ct continue
#define fill(a,b) memset(a,b,sizeof(a))
#define bs binary_search
#define gcd __gcd
#define sz(x) (int)((x).size())
#define test cin>>t; while(t--)
ll n,q,i,j,cnt,cnt2,a[1000000],d,b[1000000],x1,x2,sum,c[1000000],t,x,p,y,m,z,l,k,inv,ans,mi,ma,flag,check;
vector <ll> v1,v2;
string s;

map <ll,ll> mp1,mp2;
int main()
{
  BOOST
  //test
  {
    cin>>x>>y>>z;
    if(x>y)
      cout<<"Takahashi"<<'\n';
    else if(x<y)
      cout<<"Aoki"<<'\n';
    else
    {
      if(z == 0)
        cout<<"Aoki"<<'\n';
      else
        cout<<"Takahashi"<<'\n';
    }

  }
}

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

struct UnionFind {
  vector<int> p;
  UnionFind(int n) : p(n, -1) {}

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

    if (-p[x] < -p[y])
      swap(x, y);
    p[x] += p[y];
    p[y] = x;
    return true;
  }

  int root(int x) {
    if (p[x] < 0)
      return x;
    return root(p[x]);
  }

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

int main() {
  int n, m;
  cin >> n >> m;
  int a[n], b[n];
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];

  UnionFind uf(n);
  rep(i, m) {
    int c, d;
    cin >> c >> d;
    uf.unite(--c, --d);
  }

  vector<ll> s(n);
  rep(i, n) s[uf.root(i)] += b[i] - a[i];
  bool ans = true;
  rep(i, n) if (s[i] != 0) ans = false;
  cout << (ans ? "Yes" : "No") << endl;
  return 0;
}


#pragma region Macros
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define REP2(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; ++i)
#define REP3(i, l, r) for (int i = (l), i##_len = (int)(r); i < i##_len; ++i)
#define GET_MACRO_REP(_1, _2, _3, NAME, ...) NAME
#define REP(...) GET_MACRO_REP(__VA_ARGS__, REP3, REP2) (__VA_ARGS__)
#define RREP2(i, n) for (int i = (n - 1); i >= 0; --i)
#define RREP3(i, l, r) for (int i = (r - 1), i##_len = (l); i >= i##_len; --i)
#define GET_MACRO_RREP(_1, _2, _3, NAME, ...) NAME
#define RREP(...) GET_MACRO_REP(__VA_ARGS__, RREP3, RREP2) (__VA_ARGS__)
#define IN(type, n) type n; cin >> n
#define INALL(type, v, s) vector<type> v(s); for (auto &e : v) { cin >> e; }
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

#ifdef _DEBUG
#define DEBUG(x) cout << #x << ": " << x << endl
#else
#define DEBUG(x)
#endif

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; }
void yes() { cout << "Yes" << endl; }
void no() { cout << "No" << endl; }
#pragma endregion

ll calc_time(ll now, ll c, ll d) {
  ll ans = now + c + d / (now + 1);
  ll sqr = (ll)sqrtl(d);
  for(ll i = max(0LL, sqr - 10); i <= min(d, sqr + 10); ++i) {
    if (i < now) continue;
    ll tmp = i + c + d / (i + 1);
    chmin(ans, tmp);
  }
  return ans;
}

int main() {
  IN(int, N);
  IN(int, M);
  vector<vector<tuple<int, ll, ll> > > edge(N, vector<tuple<int, ll, ll> >());
  REP(i, M) {
    IN(int, A);
    IN(int, B);
    A--; B--;
    IN(ll, C);
    IN(ll, D);
    if (A == B) continue;
    edge.at(A).emplace_back(make_tuple(B, C, D));
    edge.at(B).emplace_back(make_tuple(A, C, D));
  }

  vector<ll> time(N, LLONG_MAX);
  time.at(0) = 0LL;
  priority_queue<pair<ll, int>, vector<pair<ll, int> >, greater<pair<ll, int> > > que;
  que.push(make_pair(0LL, 0));
  while (!que.empty()) {
    auto [now, node] = que.top();
    que.pop();
    if (time.at(node) < now) continue;
    for (auto const &[to, c, d] : edge.at(node)) {
      ll arrive = calc_time(now, c, d);
      if (chmin(time.at(to), arrive)) {
        que.push(make_pair(arrive, to));
      }
    }
  }

  if (time.at(N - 1) == LLONG_MAX) cout << -1 << endl;
  else cout << time.at(N - 1) << endl;

  return 0;
}

#include <bits/stdc++.h>
#define int long long

using namespace std;

inline void max_self(int &a, int b) {
    a = max(a, b);
}

int N, T, ans;
vector < int > a, suf;

void Back(int index, int sum) {
    if(sum <= T)
        max_self(ans, sum);
    for(int k = index + 1; k <= N && ans < T && sum < T; ++k) {
        if(sum + a[k] <= T && sum + suf[k] > ans)
            Back(k, sum + a[k]);
        if(suf[k + 1] + sum > ans && suf[k + 1] + sum <= T)
            Back(k, sum);
    }
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> N >> T;
    a.resize(N + 1), suf.resize(N + 1);
    for(int i = 1; i <= N; ++i)
        cin >> a[i];
    suf[N] = a[N];
    for(int i = N - 1; i > 0; --i)
        suf[i] = suf[i + 1] + a[i];
    if(N <= 40) {
        if(a[1] <= T)
            Back(1, a[1]);
        Back(1, 0);
    }
    else {
        sort(a.begin() + 1, a.end());
        int p = 1, sum = 0;
        for(int i = 1; i <= N; ++i) {
            while(p <= N && sum + a[p] <= T)
                sum += a[p++];
            max_self(ans, sum);
            sum -= a[i];
        }
    }
    cout << ans;
}


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

struct Union{
  vector<ll> par;
  Union(ll a){
  par=vector<ll>(a,-1);
  }
  ll find(ll a){
    if(par[a]<0){
      return a;
    }
    else{
      return par[a]=find(par[a]);
    }
  }
  bool same(ll a,ll b){
    return (find(a)==find(b));
  }
  ll size(ll a){
    return -par[find(a)];
  }
  void unite(ll a,ll b){
    ll c=find(a),d=find(b);
    if(c==d)
      return;
    if(size(c)<size(d)){
      swap(c,d);
    }
    par[c]+=par[d];
    par[d]=c;
  }
};
ll euclidean_gcd(ll a, ll b) {
  if(a < b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
ll euclidean_lcm(ll a, ll b) {
  return a/euclidean_gcd(a,b)*b;
}
int main(void){
  ll n;
  cin >> n;
  ll a[n],b[n],c[n],d[n],v=0;
  rep(i,n){
    cin >> a[i] >> b[i];
    v+=a[i];
    c[i]=a[i]+b[i];
    d[i]=c[i]+a[i];
  }
  sort(d,d+n);
  rep(i,n){
    v-=d[n-i-1];
    if(v<0){
      cout << i+1 << endl;
      return 0;
    }
  }
}


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

const int MAXN = 102;
const int MAXC = 122505;

ll k, mod, table[MAXN][MAXC], ret[MAXN];
int n, now;

void calc() {
    memset(table, 0, sizeof(table));
    table[0][0] = 1;

    for (int i = 1; i <= n; ++i) {
        int c = (k * (i + 1) * i) >> 1;
        c = min(c, MAXC - 1);
        for (int j = 0; j <= c; ++j) {
            for (int v = 0; v <= k; ++v) {
                int tmp = j + v * i;
                if (tmp > c) break;
                table[i][tmp] += table[i-1][j];
                if (table[i][tmp] >= mod) table[i][tmp] -= mod;
            }
        }
    }
}

int main(){
    ios::sync_with_stdio(0), cin.tie(0);
    while (cin >> n >> k >> mod) {
        calc();
        for (now = 1; now * 2 <= n + 1; now++) {
            ll ans = 0;
            int l = now - 1, r = n - now;

            ans += k * table[l][0] * table[r][0];
            ans %= mod;

            for (int j = 1; j < MAXC; ++j) {
                ans += (k + 1LL) * ((table[l][j] * table[r][j]) % mod);
                ans %= mod;
            }

            ret[now] = ans;
            ret[n - now + 1] = ans;
        }

        for (now = 1; now <= n; ++now) cout << ret[now] << '\n';
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
long long MOD;
int main(){
  int N, K;
  cin >> N >> K >> MOD;
  vector<vector<long long>> f(N);
  f[0].push_back(1);
  for (int i = 1; i < N; i++){
    int sz = f[i - 1].size();
    f[i] = vector<long long>(sz + i * K, 0);
    for (int j = 0; j < sz; j++){
      f[i][j] = f[i - 1][j];
    }
    for (int j = i; j < sz + i * K; j++){
      f[i][j] += f[i][j - i];
      f[i][j] %= MOD;
    }
    for (int j = sz + i * K - 1; j >= i * (K + 1); j--){
      f[i][j] += MOD - f[i][j - i * (K + 1)];
      f[i][j] %= MOD;
    }
  }
  for (int i = 0; i < N; i++){
    long long ans = 0;
    int d = min(f[i].size(), f[N - 1 - i].size());
    for (int j = 0; j < d; j++){
      ans += f[i][j] * f[N - 1 - i][j] % MOD;
      ans %= MOD;
    }
    ans *= (K + 1);
    ans %= MOD;
    ans += MOD - 1;
    ans %= MOD;
    cout << ans << endl;
  }
}


#include<iostream>
using namespace std;
int main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << a * d - b * c << endl;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define debug printf("%d %s\n",__LINE__,__FUNCTION__);fflush(stdout)
using ll=long long;using i64=long long;using db=double;
using u32=unsigned int;using u64=unsigned long long;using db=double;
using pii=pair<int,int>;using vi=vector<int>;
using qi=queue<int>;using pqi=priority_queue<int>;using si=set<int>;
#define pb push_back
#define mk make_pair
#define ins insert
#define era erase
#define fi first
#define se second
#define lowbit(x) x&-x
#define ALL(a) a.begin(),a.end()
const int INF=0x3f3f3f3f;
const ll INFLL=0x3f3f3f3f3f3f3f3f;
const double PI=acos(-1.0);
template<class T>inline bool chkmin(T&a,T b){return b<a?a=b,true:false;}
template<class T>inline bool chkmax(T&a,T b){return a<b?a=b,true:false;}
int _w,_t;FILE* _f;

int a,b,c,d;

void solve(){
    scanf("%d%d%d%d",&a,&b,&c,&d);
    printf("%d\n",a*d-b*c);
}

int main(){
    #ifdef MULTI_CASES
    _w=scanf("%d",&_t);while(_t--)
    #endif
    solve();
    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
using namespace std;
const int N = 2e5 + 5;
int mod = 998244353;
int pre[N]{};
void add(int pos){
    pos = N - pos - 1;
    for (int i = pos; i < N; i += i & -i) pre[i]++;
}
int query(int pos){
    pos = N - pos - 1;
    int ans = 0;
    for (int i = pos; i; i -= i & -i) ans += pre[i];
    return ans;
}
int main(){
    ios::sync_with_stdio(0), cin.tie(0);
    int n;
    cin >> n;
    int a[n], b[n], tar[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    map<int, queue<int>> v;
    for (int i = 0; i < n; i++){
        cin >> b[i];
        v[b[i] + i].push(i);
    }
    for (int i = 0; i < n; i++){
        if (v[a[i] + i].empty()){
            cout << -1 << '\n';
            return 0;
        }
        tar[i] = v[a[i] + i].front();
        v[a[i] + i].pop();
    }
    ll ans = 0;
    for (int i = 0; i < n; i++){
        //cout << tar[i] - i<< ' ';
        ans += tar[i] + query(tar[i]) - i;
        add(tar[i]);
    }
    cout << ans << '\n';
}

#include <bits/stdc++.h>

using namespace std;
#define int long long
const int MOD = 1000000007;

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> A(N);
	int res = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	map<int, int> mp;
	mp[0] = 1;
	int sum = 0;
	int c = 1;
	for (int i = 0; i < N; i++) {
		sum += A[i] * c;
		c *= -1;
		res += mp[sum];
		mp[sum]++;
	}
	cout << res << endl;
}


//Let's join Kaede Takagaki Fan Club !!
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//#define int long long
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define a first
#define b second
#define fi first
#define sc second
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define all(x) x.begin(),x.end()
#define si(x) int(x.size())

#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif

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

template<class t> using vc=vector<t>;

template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
	return os<<"{"<<p.fi<<","<<p.sc<<"}";
}

template<class t> ostream& operator<<(ostream& os,const vc<t>& v){
	os<<"{";
	for(auto e:v)os<<e<<",";
	return os<<"}";
}

template<class T>
void g(T &a){
	cin >> a;
}
template<class T>
void o(const T &a,bool space=false){
	cout << a << (space?' ':'\n');
}
//ios::sync_with_stdio(false);
const ll mod = 1000000007;//998244353
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
template<class T>
void add(T&a,T b){
	a+=b;
}

ll modpow(ll x,ll n){
	ll res=1;
	while(n>0){
		if(n&1) res=res*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return res;
}
ll F[2000005],R[2000005];
void make(){
	F[0] = 1;
	for(int i=1;i<2000005;i++) F[i] = F[i-1]*i%mod;
	for(int i=0;i<2000005;i++) R[i] = modpow(F[i],mod-2);
}
ll C(int a,int b){
	return F[a]*R[b]%mod*R[a-b]%mod;
}
ll a, b;
int pr[20]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71};
ll dp[2][(1<<20)];
void solve(){
	cin >> a >> b;
		int cur = 0, nxt = 1;
		dp[cur][0] = 1;
	for(ll i=a;i<=b;i++){
		memset(dp[nxt], 0, sizeof(dp[nxt]));
		int cur_m = 0;
		rep(x, 20){
			if(i % pr[x] == 0) cur_m |= (1<<x);
		}
		rep(j, (1<<20)){
			if(dp[cur][j] == 0) continue;
			add(dp[nxt][j], dp[cur][j]);
			if( (j & cur_m) == 0) add(dp[nxt][j+cur_m], dp[cur][j]);
		}
		swap(cur,nxt);
	}
	ll ans = 0;
	rep(i,(1<<20)) ans += dp[cur][i];o(ans);
}
signed main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);
	int t; t = 1; //cin >> t;
	while(t--) solve();
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

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

	int a[n], b[n];
	vector <ll> v;
	ll sum = 0;

	for(int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
		v.push_back(2LL * a[i] + b[i]);
		sum += a[i];
	}

	sort(v.begin(), v.end(), greater<ll> ());
	for(int i = 0; i < n; i++) {
		if(v[i] > sum) {
			cout << i + 1;
			return 0;
		}
		sum -= v[i];
	}
	assert(0);
}

#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rl register long long
ll n,x,cur,ta,tb;
int main(){
    scanf("%lld %lld",&n,&x);x*=100;
    for(rl i=1;i<=n;++i){
        scanf("%lld %lld",&ta,&tb);
        cur+=ta*tb;
        if(cur>x) return printf("%lld\n",i),0;
    }
    printf("-1\n");
    return 0;
}


#pragma GCC diagnostic warning "-Wextra"
#pragma GCC diagnostic warning "-Wshadow"
#include <bits/stdc++.h>
using namespace std;

template <class A, class B> bool cmin(A& a, B b) { return a > b && (a = b, true); }
template <class A, class B> bool cmax(A& a, B b) { return a < b && (a = b, true); }
template <class A, class B> ostream& operator<<(ostream& os, pair<A, B>& p) { return os << '(' << p.first << ", " << p.second << ')'; }
static bool debug = false;
void dump() {}
template <class A, class... B> void dump(A&& a, B&&... b) { if (debug) cout << a << (sizeof...(b) ? ' ' : '\n'), dump(b...); }
template <class A> void dump1D(A& a) { if (debug) for (auto i = a.begin(); i != a.end(); i++) cout << *i << (next(i) != a.end() ? ' ' : '\n'); }
template <class A> void dump2D(A& a) { if (debug) for (auto i = a.begin(); i != a.end(); i++) dump1D(*i), cout << (next(i) != a.end() ? '\0' : '\n'); }

signed main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  debug = true;

  long H, W;
  cin >> H >> W;
  vector<vector<char>> S(H, vector<char>(W));
  for (long i = 0; i < H; i++) {
    for (long j = 0; j < W; j++) {
      cin >> S.at(i).at(j);
    }
  }

  long ans = 0;
  for (long h = 0; h < H; h++) {
    for (long w = 0; w < W; w++) {
      long cnt = 0;
      for (long i = 0; i < 2; i++) {
        for (long j = 0; j < 2; j++) {
          if (h + i >= H) goto NG;
          if (w + j >= W) goto NG;
          cnt += S.at(h + i).at(w + j) == '#';
        }
      }
      if (cnt == 1 || cnt == 3) ans++;
      NG:;
    }
  }
  cout << ans << '\n';
}

#define taskname "test"

#include <bits/stdc++.h>

using namespace std;

#define sz(x) (int)x.size()
#define fi first
#define se second

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

const int mod = 1e9 + 7;

int n, m;
int total = 0;

void read_input()
{
    cin >> n >> m;
    for(int i = 1; i <= n; ++i)
    {
        int a;
        cin >> a;
        total += a;
    }
}

int powmod(int x, int k)
{
    if(k == 0) return 1;
    int t = powmod(x, k / 2);
    if(k % 2 == 0) return t * 1LL * t % mod;
    else return t * 1LL * t % mod * x % mod;
}

int inv(int x)
{
    return powmod(x, mod - 2);
}

int C(int k, int n)
{
    if(k > n) return 0;
    int res = 1;
    for(int i = n - k + 1; i <= n; ++i)
        res = res * 1LL * i % mod;
    for(int i = 1; i <= k; ++i)
        res = res * 1LL * inv(i) % mod;
    return res;
}

int calc(int k, int n)
{
    return C(k, n + k);
}

void solve()
{
    cout << calc(n + total, m - total) << '\n';
}

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


#include <bits/stdc++.h>
#define endl "\n"
#define ff first
#define ss second
#define PB push_back
#define MP make_pair
#define ll long long
#define llu unsigned long long
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define ABS(X) ((X) < 0 ? -(X) : (X))
#define LCM(X, Y) (((X) / (GCD((X), (Y)))) * (Y))
#define MEM(A, B) memset((A), (B), sizeof(A))
#define MEM_VEC(V, FILL) fill(V.begin(), V.end(), FILL)
#define FOR_EACH(IT, V) for (auto IT = V.begin(); IT != V.end(); IT++)
#define DEBUG_ARRAY_PRINT(A, I) cout << "at pos " << I << "  value is: " << A[I]
#define TURBO                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0)
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;
using namespace std;
inline ll GCD(ll A, ll B)
{
    if (B == 0)
        return A;
    return GCD((B), (A % B));
}
inline ll POW(ll BASE, ll EXP)
{
    ll RES = 1;
    for (ll I = 0; I < EXP; I++)
        RES *= BASE;
    return RES;
}
inline ll BIGMOD(ll a, ll p, ll m)
{
    ll res = 1 % m;
    ll x = a % m;
    while (p > 0)
    {
        if ((p & 1) > 0)
            res = (res * x) % m;
        x = (x * x) % m;
        p >>= 1;
    }
    return res;
}
inline void FILE_HANDLE()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
int main()
{
    TURBO;
    //FILE_HANDLE() ;
    ll n;
    scanf("%lld", &n);
    vector<ll> v;
    for (ll i = 1; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            if (n / i == i)
                v.PB(i);

            else
            {
                v.PB(i);
                v.PB(n / i);
            }
        }
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < v.size(); i++)
        printf("%lld\n", v[i]);
}

#include <bits/stdc++.h>
#define fo(a,b,c) for (a=b; a<=c; a++)
#define fd(a,b,c) for (a=b; a>=c; a--)
#define ll long long
//#define file
using namespace std;

int T,n,i,j,k,l;
int a[501];
int d[250001],tot;
bool bz;

void add(int x)
{
	swap(a[x],a[x+1]);
	d[++tot]=x;
	bz^=1;
}

void Checker()
{
	int i;
	fo(i,1,n) if (a[i]!=i) exit(1);
	if (tot>n*n) exit(2);
	fo(i,1,tot) if ((d[i]&1)!=(i&1)) exit(3);
}

int main()
{
	#ifdef file
	freopen("c.in","r",stdin);
	freopen("c.out","w",stdout);
	#endif

	scanf("%d",&T);
	for (;T;--T)
	{
		scanf("%d",&n);tot=0;bz=1;
		fo(i,1,n) scanf("%d",&a[i]);

		if (n==2)
		{
			if (a[1]>a[2])
			add(1);
		}
		else
		{
			fd(i,n,4)
			if (a[i]>a[i+1])
			{
				if ((i&1)!=bz)
				{
					if (bz) add(1);
					else add(2);
				}
				fo(j,i,n-1) if (a[j]>a[j+1]) add(j); else break;
			}
			if (bz==1)
			{
				fo(j,3,n-1)
				if (a[j]>a[j+1]) add(j); else break;
			}
			else
			{
				add(2);
				fo(j,3,n-1)
				if (a[j]>a[j+1]) add(j); else break;
			}

			if (bz)
			{
				fo(j,1,n-1)
				if (a[j]>a[j+1]) add(j); else break;
			}
			else
			{
				fo(j,2,n-1)
				if (a[j]>a[j+1]) add(j); else break;
			}
			if (a[1]!=1 || a[2]!=2)
			{
				if (bz==1)
				{
					add(1);
					fo(j,2,n-1)
					if (a[j]>a[j+1]) add(j); else break;
				}
				else
				{
					fo(j,2,n-1)
					if (a[j]>a[j+1]) add(j); else break;
				}

				if (a[1]!=1)
				{
					if (a[1]!=2)
					{
						if (bz==1)
						{
							fo(j,1,n-1)
							if (a[j]>a[j+1]) add(j); else break;
						}
						else
						{
							add(2);
							fo(j,1,n-1)
							if (a[j]>a[j+1]) add(j); else break;
						}
					}

					if (a[1]>a[2])
					{
						if (bz) add(1);
						else add(2),add(1),add(2),add(1),add(2);
					}
				}
			}
		}

		Checker();
		printf("%d\n",tot);
		fo(i,1,tot) printf("%d ",d[i]);
		printf("\n");
	}

	fclose(stdin);
	fclose(stdout);
	return 0;
}


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

#define N  200005
#define INF 1e17
#define MP make_pair
const int mod = 998244353;
typedef long long LL;

unordered_map<int, int> F;

int f(int n, int k)
{
	if (n < k) return 0;
	if (n == k) return 1;
	if (k == 0) return 0;
	if (F.count(n*3005+k)) return F[n*3005+k];
	LL ans = f(n, 2*k) + f(n-1, k-1);
	ans %= mod;
	F[n*3005+k] = ans;
	return ans;
}

int main()
{
	int n, k;
 	cin >> n >> k;
    cout <<f(n,k) << endl;
	return 0;
}

#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <string.h>
#include <algorithm>
#include <cmath>
#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) < (b) ? (a) : (b))
#define pb push_back
#define cl clear
#define MAXN 100005

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const int INF = 1e9;

inline int read(){
	int x = 0, f = 1;
	char ch = getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-')
			f = -1;
		ch = getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=(x<<1)+(x<<3)+(ch^48);
		ch = getchar();
	}
	return x*f;
}

int n, k, cnt;
char s[105][105];

void solve(){
	n = read();
	k = read();
	cin>>(s[0]+1);
	if(n==1){
		printf("%c\n",s[0][1]);
		return ;
	}
	for(cnt = 1 ; cnt <= k ; ++cnt){
		for(int i = 1, idx = 0 ; i <= n ; ++i, idx += 2){
			// printf("%d\n",i);
			if(s[cnt-1][idx%n+1]==s[cnt-1][(idx+1)%n+1]) s[cnt][i] = s[cnt-1][idx%n+1];
			if(s[cnt-1][idx%n+1]=='S'&&s[cnt-1][(idx+1)%n+1]=='R') s[cnt][i] = 'R';
			if(s[cnt-1][idx%n+1]=='R'&&s[cnt-1][(idx+1)%n+1]=='S') s[cnt][i] = 'R';
			if(s[cnt-1][idx%n+1]=='S'&&s[cnt-1][(idx+1)%n+1]=='P') s[cnt][i] = 'S';
			if(s[cnt-1][idx%n+1]=='P'&&s[cnt-1][(idx+1)%n+1]=='S') s[cnt][i] = 'S';
			if(s[cnt-1][idx%n+1]=='R'&&s[cnt-1][(idx+1)%n+1]=='P') s[cnt][i] = 'P';
			if(s[cnt-1][idx%n+1]=='P'&&s[cnt-1][(idx+1)%n+1]=='R') s[cnt][i] = 'P';
		}
	}
	printf("%c\n",s[k][1]);
}

int main(){
    int t = 1;
    // t = read();
    while(t--) solve();
    return 0;
}


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

int main() {
	int n;
	cin >> n;
	map<string, int> m1, m2;
	string ans = "satisfiable";
	for(int i=0; i<n; i++){
	    string s;
	    cin >> s;
	    if(s[0] == '!'){
	        s = s.substr(1, s.size() - 1);
	        if(m2.count(s))
	            ans = s;
	        m1[s]++;
	    }else{
	        if(m1.count(s))
	            ans = s;
	        m2[s]++;
	    }
	}
	cout << ans;
	return 0;
}

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

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

  unordered_map<string, int> mp;

  rep(i, N) {
    string S;
    cin >> S;

    if (S[0] == '!') {
      if (mp.find(S.substr(1, S.size() - 1)) != mp.end()) {
        cout << S.substr(1, S.size() - 1) << endl;
        return 0;
      } else {
        mp[S] = i;
      }
    } else {
      if (mp.find("!" + S) != mp.end()) {
        cout << S << endl;
        return 0;
      } else {
        mp[S] = i;
      }
    }
  }
  cout << "satisfiable" << endl;
}