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

using namespace std;

long powerm(long long a, long long n, long long m)
{
    if (n==1) return a%m;
    if (n==0) return 1;
    if (n%2) return (a*powerm((a*a)%m,n/2,m))%m;
    return powerm((a*a)%m,n/2,m);
}

void amain()
{
    long long n; cin >> n;
    long long m; cin >> m;
    long long x;
    x=powerm(10,n,m*m);
    //cout << x << endl;
    cout << x/m << endl;
    return;
}

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

// Artur Kraska, II UWr

#include <bits/stdc++.h>

#define forr(i, n)                  for(int i=0; i<n; i++)
#define FOREACH(iter, coll)         for(auto iter = coll.begin(); iter != coll.end(); ++iter)
#define FOREACHR(iter, coll)        for(auto iter = coll.rbegin(); iter != coll.rend(); ++iter)
#define lbound(P,R,PRED)            ({typeof(P) X=P,RRR=(R), PPP = P; while(PPP<RRR) {X = (PPP+(RRR-PPP)/2); if(PRED) RRR = X; else PPP = X+1;} PPP;})
#define testy()                     int _tests; scanf("%d", &_tests); FOR(_test, 1, _tests)
#define CLEAR(tab)                  memset(tab, 0, sizeof(tab))
#define CONTAIN(el, coll)           (coll.find(el) != coll.end())
#define FOR(i, a, b)                for(int i=a; i<=b; i++)
#define FORD(i, a, b)               for(int i=a; i>=b; i--)
#define MP                          make_pair
#define PB                          push_back
#define ff                          first
#define ss                          second
#define deb(X)                      X;

#define M 1000000007
#define INF 1000000007LL

using namespace std;

long long n, m, a;

long long pow(long long a, long long n, long long m)
{
    if(n == 0)
        return 1 % m;
    long long p = pow(a, n/2, m);
    p = p*p%m;
    if(n & 1)
        p = p*a%m;
    return p;
}

int main()
{
    scanf("%lld %lld", &n, &m);
    long long p = pow(10, n, m*m);
    p /= m;
    cout << p%m << endl;

    return 0;
}


#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline int rd_int(void){
  int x;
  rd(x);
  return x;
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    my_putchar_unlocked(c[i]);
  }
}
int main(){
  if(rd_int()%2){
    wt_L("Black");
    wt_L('\n');
  }
  else{
    wt_L("White");
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20201101-1

// --- original code ---
// {
//   wt(if[rd_int()%2, "Black", "White"]);
// }

#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define loop(i, a, n) for(int i = (a); i < (n); i++)
#define all(x) x.begin(), x.end()
#ifdef _DEBUG
#define disp(x) cout << #x << " : " << x << endl
#else
#define disp(x)
#endif
using namespace std;
using ll = int64_t;

int main(){
    int n; cin >> n;
    if(n%2) cout << "Black" << endl;
    else cout << "White" << endl;

    return 0;
}


#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>
#include <list>
#include <cassert>
#include <climits>
#include <bitset>
#include <chrono>
#include <random>
using namespace std;

#define PB push_back
#define MP make_pair
#define SZ(v) ((int)(v).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n) FORE(i,0,n)
#define FORSZ(i,a,v) FOR(i,a,SZ(v))
#define REPSZ(i,v) REP(i,SZ(v))
std::mt19937 rnd((int)std::chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

ll n;

ll calcsum(ll a, ll b) {
	ll x = a + b, y = b - a + 1;
	if (x % 2 == 0) x /= 2; else { assert(y % 2 == 0); y /= 2; }
	if (x > LLONG_MAX / y) return LLONG_MAX; else return x * y;
}

ll solve() {
	ll lo = 0, hi = n + 1;
	while (lo + 1 < hi) {
		ll mi = lo + (hi - lo) / 2;
		ll a = 1, b = n + 1 - mi, c = n + 1;
		ll d = calcsum(a, b);
		if (c >= d) hi = mi; else lo = mi;
	}
	return hi;
}

void run() {
	scanf("%lld", &n);
	printf("%lld\n", solve());
}

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

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

int main(){
  ll n,max=0,max2=0,t,idx=1,idx2=1;
  cin>>n;
  vector<ll> a(1<<n);
  for(ll i=0; i<(1<<(n-1)); i++){
    cin>>t;
    if(t>max){
      max=t;
      idx=i+1;
 //     cout << max << " "<< idx << endl;
    }
  }
  for(ll i=0; i<(1<<(n-1)); i++){
    cin>>t;
    if(t>max2){
      max2=t;
      idx2=i+1+(1<<(n-1));
    }
  }
  if(max<max2) cout << idx << endl;
  else cout << idx2 << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
const int maxn=(4e5)+10;
int n,fa[maxn],dis[maxn],dep[maxn];
vector<int> g[maxn];
int lg[maxn];
int mx,son[maxn];
void dfs(int u,int p) {
	dis[u]=dis[p]+1; fa[u]=p;
	for (int v : g[u]) if (v!=p) dfs(v,u);
	if (!mx||dis[u]>dis[mx]) mx=u;
}
int st[maxn][20];
int dfn[maxn],tot,idx,euler[maxn],pos[maxn],ans[maxn];
void dfs2(int u,int p) {
	dfn[++idx]=u;
	for (int v : g[u]) if (v!=p&&v!=son[u]) dfs2(v,u);
	if (son[u]) dfs2(son[u],u);
}
int MN(int x,int y) {
    if (dep[x]<dep[y]) return x;
    return y;
}
int lca(int x,int y) {
    x=pos[x],y=pos[y];
    if (x>y) swap(x,y);
    int j=lg[y-x+1];
    return MN(st[x][j],st[y-(1<<j)+1][j]);
}
int DIS(int x,int y) {
    return dep[x]+dep[y]-2*dep[lca(x,y)];
}
void pre(int u,int p) {
    dep[u]=dep[p]+1;
    euler[++tot]=u; pos[u]=tot;
    for (int v : g[u]) if (v!=p) {
        pre(v,u);
        euler[++tot]=u;
    }
}
int main() {
	//freopen("1.txt","r",stdin);
    for (int i=2;i<maxn;i++) lg[i]=lg[i>>1]+1;
	read(n); int x,y,z;
	for (int i=1;i<n;i++) {
		read(x),read(y);
		g[x].push_back(y);
		g[y].push_back(x);
	}
	pre(1,0);
	for (int i=1;i<=tot;i++) st[i][0]=euler[i];
    for (int j=1;j<=19;j++)
    for (int i=1;i+(1<<j)-1<=tot;i++)
        st[i][j]=MN(st[i][j-1],st[i+(1<<(j-1))][j-1]);
	mx=0; dfs(1,0); x=mx;
	mx=0; dfs(x,0); y=mx;
	z=y;
	while (fa[z]) son[fa[z]]=z,z=fa[z];
	dfs2(x,0);
	ans[x]=1;
	for (int i=2;i<=n;i++)
		ans[dfn[i]]=ans[dfn[i-1]]+DIS(dfn[i],dfn[i-1]);
	for (int i=1;i<=n;i++) printf("%d ",ans[i]); puts("");
	return 0;
}
/*
  REMEMBER:
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?

  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?

  3. Do not make STUPID MISTAKES!
  Array size? Integer overflow? Time complexity? Memory usage? Precision error?
*/

//#pragma GCC target("avx,avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
//#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll         long long int
#define co         cout
#define ci         cin
#define sf1(n)     scanf("%lld",&n)
#define sf2(n,m)   scanf("%lld %lld",&n,&m);
#define sf3(n,m,p) scanf("%lld %lld %lld",&n,&m,&p);
#define pf1(n)     printf("%lld\n",n);
#define mem(a,b)   memset(a,b,sizeof(a))
#define en         cout<<endl;
#define pb         push_back
#define gcd(n,m)   __gcd(n,m)
#define lcm(n,m)   ((n)/__gcd(n,m))*(m)
#define fi         first
#define se         second
#define coy        cout<< "YES"<<endl;
#define con        cout<< "NO"<<endl;
#define f(i,a,b)   for(ll i=a;i<b;i++)
#define r(i,a,b)   for(ll i=a;i>=b;i--)
#define all(x)     (x).begin(),(x).end()
#define allr(x)    (x).rbegin(),(x).rend()
#define pi         pair<ll,ll>
#define br         break;
#define i64        long long
#define PI         2*acos(0.0)
#define MAXN       3*100000
ll n,m,k,g,mx,mn,res,c,x,y,z,w,p,q,r,l,s,t;

void solve()
{
    ci>>n>>m>>x>>y;
    char a[n][m];
    f(i,0,n) f(j,0,m) ci>>a[i][j];
    x--;y--;
    ll i=y;
    c=0;
    while(a[x][i]=='.' and i>=0)
    {
        c++;
        i--;
    }
    i=y+1;
    while(a[x][i]=='.' and i<m)
    {
        c++;
        i++;
    }
    i=x-1;
    while(a[i][y]=='.' and i>=0)
    {
        c++;
        i--;
    }
    i=x+1;
    while(a[i][y]=='.' and i<n)
    {
        c++;
        i++;
    }
    co<<c<<endl;
}

int main()
{

//#ifdef LOCAL
        //freopen("input.txt","r",stdin);
        //freopen("output.txt","w",stdout);
//#endif
        auto start_time = clock();
        cerr << setprecision(3) << fixed;
        cout << setprecision(10) << fixed;
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        // ci>>t;
        t=1;
        for(ll ca=0;ca<t;ca++)
        {
            solve();
        }
//#ifdef LOCAL
        auto end_time = clock();
        cerr<< "Execution time: "<<(end_time-start_time)*(int)1e3/CLOCKS_PER_SEC<<" ms\n";
//#endif
}


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

int main() {
    int N;
    long K;
    cin >> N >> K;
    vector<vector<long long>> dp(4,vector<long long>(3*N+4));
    dp.at(0).at(0) = 1;
    rep(i,3) {
        rep(j,i*N+1) {
            dp.at(i+1).at(j+1) += dp.at(i).at(j);
            dp.at(i+1).at(j+N+1) -= dp.at(i).at(j);
        }
        rep(j,(i+1)*N) {
            dp.at(i+1).at(j+1) += dp.at(i+1).at(j);
        }
    }
    int sum;
    for(int i=3; i<=3*N; i++) {
        if(K<=dp.at(3).at(i)) {
            sum = i;
            break;
        }
        else {
            K -= dp.at(3).at(i);
        }
    }
    rep(i,N) {
        int ans_1 = i+1;
        int jmin=max(1,sum-ans_1-N);
        int jmax=min(N,sum-ans_1-1);
        if(jmin>jmax) continue;
        if(K>(jmax-jmin+1)) {
            K -= jmax-jmin+1;
            continue;
        }
        int ans_2=jmin+K-1;
        int ans_3=sum-ans_1-ans_2;
        cout << ans_1 << " " << ans_2 << " " << ans_3 << endl;
        break;
    }
}

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

#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl
#define pq priority_queue
#define inf 0x3f
#define rep(i,a,b) for (int i=a;i<(b);i++)
#define MP make_pair
#define SZ(x) (int(x.size()))
#define ll long long
#define mod 1000000007
#define ALL(x) x.begin(),x.end()
void inc(int &a,int b) {a=(a+b)%mod;}
void dec(int &a,int b) {a=(a-b+mod)%mod;}
int lowbit(int x) {return x&(-x);}
ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;}

const int maxn=3e6+10;

int N;
ll K;
ll f[maxn];

ll getf(int x) {
	if (x<2||x>N+N) return 0;
	ll a=max(1,x-N),b=min(N,x-1);
	return b-a+1;
}

int main() {
//	freopen("input.txt","r",stdin);
	std::ios::sync_with_stdio(false);cin.tie();
	cin>>N>>K;
	memset(f,0,sizeof(f));
	rep(i,3,3*N+1) {
		f[i]=f[i-1]+getf(i-1);
		if (i-N-1>=2) f[i]-=getf(i-N-1);
//		debug(f[i]);
	}

	int cur=2;
	while (1) {
		cur++;
		if (K<=f[cur]) break;
		else K-=f[cur];
	}
	debug(K);
	//sum is cur
	int b=0;
	while (1) {
		b++;
		if (K<=getf(cur-b)) break;
		else K-=getf(cur-b);
	}
	//first ele is b
	debug(cur);
	cout<<b<<" "<<max(0,cur-b-N-1)+K<<" "<<cur-b-max(0,cur-b-N-1)-K;
	return 0;
}


#include<bits/stdc++.h>

#define ll long long

using namespace std;

int read()
{
	int a=0,f=1,c=getchar();
	while(!isdigit(c))
	{
		if(c=='-')f=-1;
		c=getchar();
	}
	while(isdigit(c))
	{
		a=a*10+c-'0';
		c=getchar();
	}
	return a*f;
}

const int N=1e5+10;
const int P=1e9+7;
ll mod(ll x){return (x%P+P)%P;}

int n;
int a[N];
ll f[2][N],g[2][N];

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

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

	f[0][1]=1;
	g[0][1]=a[1];
	for(int i=2;i<=n;++i)
	{
		f[0][i]=mod(f[0][i-1]+f[1][i-1]);
		f[1][i]=f[0][i-1];
		g[0][i]=mod(g[0][i-1]+g[1][i-1]+a[i]*f[0][i]);
		g[1][i]=mod(g[0][i-1]-a[i]*f[1][i]);
	}
	printf("%lld\n",mod(g[0][n]+g[1][n]));

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define each(e, v) for(auto &e: v)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
//const int MOD = 1000000007;
const int MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

struct io_setup{
    io_setup(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout << fixed << setprecision(15);
    }
} io_setup;

template<int mod>
struct Mod_Int{
    int x;

    Mod_Int() : x(0) {}

    Mod_Int(ll y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

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

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

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

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

    Mod_Int &operator ++ () {return *this += Mod_Int(1);}

    Mod_Int operator ++ (int){
        Mod_Int tmp = *this;
        ++*this;
        return tmp;
    }

    Mod_Int &operator -- () {return *this -= Mod_Int(1);}

    Mod_Int operator -- (int){
        Mod_Int tmp = *this;
        --*this;
        return tmp;
    }

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

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

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

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

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

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

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

    Mod_Int inverse() const {
        assert(*this != Mod_Int(0));
        return pow(mod-2);
    }

    Mod_Int pow(ll k) const{
        Mod_Int now = *this, ret = 1;
        for(; k; k >>= 1, now *= now){
            if(k&1) ret *= now;
        }
        return ret;
    }

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

    friend istream &operator >> (istream &is, Mod_Int &p){
        ll a;
        is >> a;
        p = Mod_Int<mod>(a);
        return is;
    }
};

using mint = Mod_Int<MOD>;

int main(){
    int H, W, K;
    cin >> H >> W >> K;

    vector<vector<mint>> dp(H, vector<mint>(W, 0));
    vector<vector<char>> a(H, vector<char>(W, '0'));

    rep(i, K){
        int x, y;
        char c;
        cin >> x >> y >> c; x--, y--;
        a[x][y] = c;
    }

    dp[0][0] = 1;
    mint p = mint(2)/mint(3);

    rep(i, H){
        rep(j, W){
            if((i < H-1 || j < W-1) && a[i][j] == '0') dp[i][j] *= p;
            if(a[i][j] != 'R' && i+1 < H){
                dp[i+1][j] += dp[i][j];
            }
            if(a[i][j] != 'D' && j+1 < W){
                dp[i][j+1] += dp[i][j];
            }
        }
    }

    mint ans = dp[H-1][W-1];
    ans *= mint(3).pow(H*W-K);
    cout << ans << '\n';
}


#include<bits/stdc++.h>
using namespace std;
#define N (1000000000+7)
//#define N 998244353
#define INF 1e18
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
const int inf = (int)1e9;

using P = pair<int,int>;

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

template<typename T>
struct BIT{
    private:
    vector<T> array;
    int length;

    public:

    BIT(int _n=0) : array(_n+1),length(_n){}

    T sum(int i){
        T s=0;
        while(i>0){
            s+=array[i];
            i -= i&(-i);
        }
        return s;
    }

    T sum(int i,int j){
        T ret1 = sum(i-1);
        T ret2 = sum(j);
        return ret2-ret1;
    }

    void add(int i,T x){
        while(i<=length){
            array[i]+=x;
            i += i&(-i);
        }
    }
};

ll row[200010];
ll col[200010];

vector<ll> v[200010];

int main(void){
  ll h,w,m;
  cin>>h>>w>>m;
  for(int i=1;i<=h;i++)row[i] = w+1;
  for(int i=1;i<=w;i++)col[i] = h+1;
  ll ans = 0;
  for(int i=0;i<m;i++){
    ll x,y;
    cin>>x>>y;
    row[x] = min(row[x],y);
    col[y] = min(col[y],x);
  }
  ll Mw = row[1];
  ll Mh = col[1];
  for(ll i=1;i<Mh;i++){
    ans += row[i]-1;
    v[row[i]-1].push_back(i);
  }
  for(ll i=1;i<Mw;i++){
    ans += col[i]-1;
  }
  //cout<<ans<<endl;
  BIT<ll> bit = BIT<ll>(h+1);
  ll res = 0;
  for(ll i=1;i<=w;i++){
    if(i<Mw){
      bit.add(1,1LL);
      bit.add(col[i],-1LL);
    }
    //cout<<col[i]<<" ";
    for(int j=0;j<v[i].size();j++){
      ll t = bit.sum(v[i][j]);
      res += bit.sum(v[i][j]);
      //cout<<t<<" ";
    }
    ////cout<<endl;
  }
  cout<<ans-res<<endl;
  return 0;
}

/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author NikuKyabe
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define REV(i, a, b) for (int i = (b) - 1; i >= (a); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001l
#define MOD 1000000007
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;
template<class T>
using M =vector<vector<T>>;

class BHydrate {
public:
	void solve(std::istream& cin, std::ostream& cout) {
        int a,b,c,d;
        cin >> a >> b >> c >> d;

        if(c * d - b <= 0){
            cout << -1 << endl;
        }
        else{
            double t = (double)a / (c * d - b);
            cout << (int)ceil(t) << endl;
        }
	}
};

signed main() {
	BHydrate solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


// #pragma GCC optimize("Ofast,unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define forn(i, s, n)  for(ll i=(ll)s; i<(ll)(n); i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define pll pair<long long int, long long int>
#define pii pair<int, int>
#define lld long double
#define F first
#define S second
#define PI 3.141592653589793238
#define prec(n) fixed<<setprecision(n)
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define itsval(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); itval(_it, args); }
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

void itval(istream_iterator<string> it) {}
template<typename T, typename... Args>
void itval(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    itval(++it, args...);
}
const ll MOD = 1e9 + 7;
template <typename T>
inline void print(T x) {cout << x << "\n";}
template <typename T>
inline void printvec(T x) {for (auto a : x)cout << a << ' '; cout << '\n';}
// -----------------------------------------------------------------------

struct custom {
    bool operator()(const pair<int, pii> &p1, const pair<int, pii> &p2)const {
        if (p1.F == p2.F)
            return p1.S.F > p2.S.F;
        return p1.F > p2.F;
    }
};

// Calculate a^b % MOD -------------------------------------------------
ll get_pow(ll a, ll b, ll M = MOD) {
    ll res = 1;
    while (b) {
        if (b & 1) res = (res * a) % M;
        a = (a * a) % M;
        b >>= 1;
    }
    return res;
}
// ---------------------------------------------------------------------
const ll N = 3e5 + 5, inf = 2e9;
std::vector<pii> adj[N];
int a[502][502], b[502][502], ind[502][502], dist[N];
void solve()
{
    int R, C;
    cin >> R >> C;
    forn(i, 1, R + 1)
    {
        forn(j, 1, C)
        {
            cin >> a[i][j];
        }
    }
    forn(i, 1, R)
    {
        forn(j, 1, C + 1)
        cin >> b[i][j];
    }
    forn(i, 1, R + 1)
    {
        forn(j, 1, C + 1) {
            ind[i][j] = j + C * i;
            dist[ind[i][j]] = inf;
        }
    }

    forn(i, 1, R + 1)
    {
        forn(j, 1, C + 1)
        {
            if (j < C)
            {
                adj[ind[i][j]].pb({a[i][j], ind[i][j + 1]});
            }
            if (j > 1)
            {
                adj[ind[i][j]].pb({a[i][j - 1], ind[i][j - 1]});
            }
            if (i < R)
            {
                adj[ind[i][j]].pb({b[i][j], ind[i + 1][j]});
            }
            forn(k, 1, i)
            {
                adj[ind[i][j]].pb({1 + k, ind[i - k][j]});
            }
        }
    }
    dist[ind[1][1]] = 0;
    set<pii>s;
    s.insert({0, ind[1][1]});
    while (!s.empty())
    {
        pll t = *s.begin();
        s.erase(s.begin());
        for (auto x : adj[t.S])
        {
            if (dist[x.S] > x.F + t.F)
            {
                s.erase({dist[x.S], x.S});
                dist[x.S] = x.F + t.F;
                s.insert({dist[x.S], x.S});
            }
        }
    }

    cout << dist[ind[R][C]] << '\n';
}

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

    int test = 1;
    clock_t z = clock();
    //cin >> test;
    forn(tes, 0, test)
    {

        solve();
    }
    debug("Total Time:%.4f\n", (double)(clock() - z) / CLOCKS_PER_SEC);
    return 0;
}

#include<bits/stdc++.h>

using namespace std;

#define  GODSPEED       ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(15);
#define  f              first
#define  s              second
#define  newl           cout<<"\n";
#define  pb             push_back
#define  mset(a,x)      memset(a,x,sizeof(a))
#define  debv(a)        for(auto it: a)cout<<it<<" ";newl;
#define  deb1(a)        cout<<a<<"\n";
#define  deb2(a,b)      cout<<a<<" "<<b<<"\n";
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<"\n";
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define  uniq(a)        a.resize(unique(a.begin(), a.end()) - a.begin());
#define  all(a)         a.begin(),a.end()

typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;

const ll   N     =  1e5+5;
const ll   mod   =  998244353;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;

ll n, k;

void solve(){
	cin >> n >> k;
	ll ans = 0;
	for(int i = 2; i <= 2 * n; i++){
		ll sum = k + i;
		ll x = i;
		if(sum > 2 * n or sum < 2) continue;
		if(x > n) x -= 2 * (x - (n + 1));
		if(sum > n) sum -= 2 * (sum - (n + 1));
		ans += (x - 1) * (sum - 1);
	}
	deb1(ans)
}

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


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 5e5+5;
const int INF = 0x3f3f3f3f;

int a[N],b[N];

inline int check1(int n){
	int A0 = 0,B0 = 0;
	vector <int> s,t;
	for(int i = 1;i <= n;++i){
		if(a[i] == 0) A0++,s.push_back(i);
		if(b[i] == 0) B0++,t.push_back(i);
	}
	if(A0 != B0) return INF;

	int res = 0;
	for(int i = 0;i < s.size();++i){
		if(s[i] == t[i]) res++;
	}
	return A0-res;
}

inline int check2(int n){
	int A0 = 0,B0 = 0;
	vector <int> s,t;
	for(int i = n;i;--i){
		if(a[i] == 0) A0++,s.push_back(i);
		if(b[i] == 0) B0++,t.push_back(i);
	}
	if(A0 != B0) return INF;

	int res = 0;
	for(int i = 0;i < s.size();++i){
		if(s[i] == t[i]) res++;
	}
	return A0-res;
}

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

	int ans = INF;
	ans = min(ans,check1(n));
	ans = min(ans,check2(n));
	printf("%d\n",ans == INF ?-1 :ans);
    return 0;
}

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

#define pb push_back
#define mp make_pair
#define f1 first
#define s2 second

#define fastio ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(x) cerr << "[" << #x << "]: " << x << "\n";

using ll = long long;
using ld = long double;
using ii = pair<int, int>;
using pl = pair<ll, ll>;

ld const PI = 4*atan((ld)1);
const int MAX = 5e5 + 69;

int main()
{
	fastio;

	int n;
	char s[MAX], t[MAX];

	cin >> n;
	cin >> s;
	cin >> t;

	int a = 0, b = 0;
	for (int i = 0; i < n; ++i)
		a += s[i] == '0', b += t[i] == '0';

	if (a != b)
	{
		cout << -1 << '\n';
		return 0;
	}

	vector<int> A, B;
	for (int i = 0; i < n; ++i)
	{
		if (s[i] == '0') A.pb(i);
		if (t[i] == '0') B.pb(i);
	}

	int res = 0;
	for (int i = 0; i < (int)A.size(); ++i)
	{
		if (A[i] == B[i])
			continue;
		res++;
	}

	cout << res << '\n';

	return 0;
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
//#define mod 998244353
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline void out(T a){ cout << a << '\n'; }
void YN(bool ok){if(ok) cout << "Yes" << endl; else cout << "No" << endl;}
//void YN(bool ok){if(ok) cout << "YES" << endl; else cout << "NO" << endl;}

const ll INF=1e18;
const int mx=200005;
//arc110
int main(){
    //オーバーフローは大丈夫ですか？？
    cin.tie(0);ios::sync_with_stdio(false);
    ll ans=1;
    ll n;
    cin>>n;
    map<ll,ll> mp;
    for(ll i=2;i<=n;i++){
        ll tmp=i;
        map<ll,ll> mp2;
        for(ll j=2;j*j<=i;j++){
            while(tmp%j==0){
                tmp/=j;
                mp2[j]++;
            }
        }
        if(tmp!=1){
            mp2[tmp]++;
        }
        for(auto p:mp2){
            chmax(mp[p.ft],p.sc);
        }
    }
    for(auto p:mp){
        rep(i,p.sc) ans*=p.ft;
    }
    ans++;
    out(ans);
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
{
    ・全探索できるなら全探索しろ
    ・異常な制約ならそこに注目
}
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'¥n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え('='でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
doubleを扱うときには(abs)ではなく'fabs'!!!
dpするときは「配る」、「もらう」の両方を考えて最適な方を選べ
Segtreeで区間最大(max)を使うとき,単位元の設定をしっかり
(デフォルトは-INF,0の方が都合の良い場合は変更)
*/

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,N) for(ll i = 0; i < N; i++)
#define ld long double
int main(){
	int n;
	scanf("%d",&n);
	vector<pair<pair<int,int>,int>> v(n);
	rep(i,n) scanf("%d%d%d",&v.at(i).first.first,&v.at(i).first.second,&v.at(i).second);
	vector<bool> ans(10002);
	rep(i,n) {
		if(!ans.at(v.at(i).first.second) && !ans.at(v.at(i).first.second + 1)){
			ans.at(v.at(i).first.second) = true;
			ans.at(v.at(i).first.second + 1) = true;
		}
		else v.at(i).second = 0;
		if(v.at(i).first.second == 0 || v.at(i).first.second == 10000)
			v.at(i).second = 0;

	}
	vector<pair<int,int>> kot(n);
	rep(i,n){
		if(v.at(i).second == 0){
			kot.at(i).first = 0;
			kot.at(i).second = 0;
			continue;
		}
		else {
			kot.at(i).first = v.at(i).first.second;
			kot.at(i).second = v.at(i).first.second + 1;
		}

		while(v.at(i).second > (kot.at(i).second - kot.at(i).first) * 10000){
			if(ans.at(kot.at(i).first - 1) == false && kot.at(i).first > 1){
				kot.at(i).first--;
				ans.at(kot.at(i).first) = true;
			}
			else if(ans.at(kot.at(i).second + 1) == false && kot.at(i).second < 9999){
				kot.at(i).second++;
				ans.at(kot.at(i).second) = true;
			}
			else break;
		}
	}
	int index = 1;
	rep(i,n){
		if(v.at(i).second && kot.at(i).first > 0 && kot.at(i).second <= 9999) printf("%d %d %d %d\n",0,kot.at(i).first - 1,10000,kot.at(i).second);
		else {
		       	printf("%d %d %d %d\n",index,9999,index + 1,10000);
			index++;
		}
	}
	return 0;
}


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

const int N = 110;

int n;
ll X, dp[N][N][N], ans = 1e18, a[N];

int main(){
	cin >> n >> X;
	for(int i = 1; i <= n; ++ i)	cin >> a[i];
	for(int t = 1; t <= n; ++ t){	//一共选t个
		memset(dp, 0xcf, sizeof dp);
		dp[0][0][0] = 0;
		for(int i = 1; i <= n; ++ i){		//前i个物品中选
			dp[i][0][0] = 0;
			for(int k = 1; k <= min(i, t); ++ k){	//选k个
				for(int j = 0; j < t; ++ j)
					dp[i][k][j] = max(dp[i - 1][k][j], dp[i - 1][k - 1][((j - a[i]) % t + t) % t] + a[i]);
			}
		}
		if(dp[n][t][X % t] >= 0)	ans = min(ans, (X - dp[n][t][X % t]) / t);
	}
	cout << ans;
	return 0;
}

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef  long long  int ll;
typedef long double db;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pll pair<ll,ll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ub(v,val) upper_bound(v.begin(),v.end(),val)
#define np(str) next_permutation(str.begin(),str.end())
#define lb(v,val) lower_bound(v.begin(),v.end(),val)
#define sortv(vec) sort(vec.begin(),vec.end())
#define rev(p) reverse(p.begin(),p.end());
#define v vector
#define pi 3.14159265358979323846264338327950288419716939937510
#define len length()
#define repc(i,s,e) for(ll i=s;i<e;i++)
#define fi first
#define se second
#define mset(a,val) memset(a,val,sizeof(a));
#define mt make_tuple
#define repr(i,n) for(i=n-1;i>=0;i--)
#define rep(i,n) for(i=0;i<n;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define at(s,pos) *(s.find_by_order(pos))
#define set_ind(s,val) s.order_of_key(val)
long long int M = 1e9 + 7 ;
long long int inf = 9 * 1e18;
//CLOCK
ll begtime = clock();
#define time() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//CLOCK ENDED
ll n, m;
// modular exponentiation
ll binpow(ll val, ll deg)
{
	if (deg < 0)
		return 0;
	if (!deg)
		return 1 % M;
	if (deg & 1)
		return binpow(val, deg - 1) * val % M;
	ll res = binpow(val, deg >> 1);
	return (res * res) % M;
}
//binomial
ll modinv(ll n) {
	return binpow(n, M - 2);
}
//DEBUGGING
vector<string> vec_splitter(string s)
{
	s += ',';
	vector<string> res;
	while (!s.empty())
	{
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}
void debug_out(
    vector<string> __attribute__((unused)) args,
    __attribute__((unused)) int idx,
    __attribute__((unused)) int LINE_NUM) { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T)
{
	if (idx > 0)
		cout << " | ";
	else
		cout << "Line(" << LINE_NUM << ") ";
	stringstream ss;
	ss << H;
	cout << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifndef ONLINE_JUDGE
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
// DEBUGGING ENDED
int main() {
	// your code goes here
	IOS;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll i, j, t, k, x, y, z,  N;
	cin >> n >> x;
	ll a[n];
	rep(i, n) {
		cin >> a[i];
		// cout << a[i] << ' ';
	}
	ll mn = inf;
	for (ll C = 1; C <= n; C++) {
		ll dp[n + 5][n + 5][n + 5];
		mset(dp, -1);
		dp[0][0][0] = 0;
		for (i = 0; i < n; i++)
		{
			for (j = 0; j <= n; j++) {
				for (k = 0; k <= n; k++) {
					if (dp[i][j][k] != -1) {
						dp[i + 1][j][k] = max(dp[i + 1][j][k], dp[i][j][k]);
						if (j < n) {
							y = dp[i][j][k] + a[i];
							ll to = (x - y) % C;
							dp[i + 1][j + 1][to] = max(dp[i + 1][j + 1][to], y);
						}
					}
				}
			}
		}
		if (dp[n][C][0] != -1) {
			mn = min(mn, (x - dp[n][C][0]) / C);
		}
	}
	if (mn == inf) cout << -1;
	else cout << mn;

	return 0;

}


#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<stack>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll N;
ll dp[18][(1<<18)];
ll x[20],y[20],z[20];
ll d[20][20];
ll Cost(ll now,ll next){
    return abs(x[next]-x[now])+abs(y[next]-y[now])+max(0ll,z[next]-z[now]);
}
int main(){
    cin>>N;
    for(ll i=0;i<N;i++){
        cin>>x[i]>>y[i]>>z[i];
    }
    for(ll i=0;i<N;i++){
        for(ll j=0;j<N;j++){
            d[i][j] = Cost(i,j);
        }
    }
    for(ll i=0;i<N;i++){
        for(ll j=0;j<(1<<N);j++){
            dp[i][j]=INF;
        }
    }
    dp[0][1]=0;
    for(ll state=1;state<(1<<N);state+=2){
        for(ll now=0;now<N;now++){
            if(dp[now][state]==INF)continue;
            for(ll next=0;next<N;next++){
                if(next==now)continue;
                if((1<<next) & state)continue;
                dp[next][state | (1<<next)] = min(dp[next][state | (1<<next)], dp[now][state]+d[now][next]);
            }
        }
    }
    ll ans=INF;
    for(ll i=1;i<N;i++){
        ans=min(ans,dp[i][(1<<N)-1]+d[i][0]);
    }
    cout<<ans<<endl;

    return 0;
}

#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define eps (double)(1e-9)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

ll cost(ll a, ll b, ll c, ll p, ll q, ll r){
    return abs(a-p) + abs(b-q) + max(0LL, r-c);
}

int main() {
    int n;
    cin >> n;
    vector<ll> x(n), y(n), z(n);
    rep(i, n)cin >> x[i] >> y[i] >> z[i];
    vector<vector<ll>> dp(1<<n, vector<ll>(n, inf));
    dp[0][0] = 0;
    rep(i, (1<<n)-1){
        rep(j, n){
            if(i & (1<<j) == 0)continue;
            rep(k, n){
                chmin(dp[i|(1<<k)][k], dp[i][j] + cost(x[j],y[j],z[j],x[k],y[k],z[k]));
            }
        }
    }
    cout << dp[(1<<n)-1][0] << endl;
}


#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
struct FIO{FIO(){std::cin.tie(0);std::ios_base::sync_with_stdio(0);std::cout<<std::fixed<<std::setprecision(15);}}fIO;
template<typename T> using V = std::vector<T>;
template<typename T> void fill(V<T>&v) { for(T&e:v) std::cin >> e; }
/*-*/

int main() {
	int n,m;
	std::cin >> n >> m;
	V<lnt> w(n);
	fill(w);
	std::map<lnt,lnt> map;
	lnt minload=1e18;
	rep(i,m) {
		lnt a,b;
		std::cin >> a >> b;
		map[b]=std::max(map[b],a);
		minload=std::min(minload,b);
	}
	rep(i,n) {
		if(w[i]>minload) {
			print(-1);
			return 0;
		}
	}
	V<std::pair<lnt,lnt> > v;
	v.emplace_back(0,0);
	for(auto e:map) v.emplace_back(e);
	{
		lnt max=0;
		int k=v.size();
		rep(i,k) {
			max=std::max(max,v[i].second);
			v[i].second=max;
		}
	}
	V<int> p(n);
	std::iota(all(p),0);
	lnt min=1e18;
	std::sort(all(w));
	do {
		V<V<std::pair<lnt,lnt> > > g(n);
		V<lnt> a(n);
		rep(i,n) a[i]=w[p[i]];
		V<lnt> ac(n+1,0);
		rep(i,n) ac[i+1]=ac[i]+a[i];
		rep(i,n) {
			for(int j=i+1;j<n;j++) {
				lnt x=ac[j+1]-ac[i];
				int l=-1,r=v.size();
				while(r-l>1) {
					int o=(l+r)>>1;
					if(v[o].first<x) l=o;
					else r=o;
				}
				g[i].emplace_back(j,v[l].second);
			}
		}
		auto dfs=[&](auto f, int i) -> lnt {
			lnt max=0;
			for(auto to:g[i]) {
				max=std::max(max,f(f,to.first)+to.second);
			}
			return max;
		};
		lnt x=dfs(dfs,0);
		min=std::min(min,x);
	} while(std::next_permutation(all(p)));
	print(min);
}

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

#define ll long long int
#define endl '\n'
void testCase()
{
    //ll t; cin>>t; while(t--)
    {
       ll n,k;
       cin>>n>>k;
       ll s=101;
       ll e=n*100+k;
       ll ans=0;
       for(int i=e;i>=s;i--)
       {
       	if(i==(n*100))
       	{
       		i=(n-1)*100+k;
       		n--;
       	}
       ans+=i;
       }
       //ans+=i;
       cout<<ans;

    }
}

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


#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, j, n) for (int i = j; i < (n); ++i)
#define rrep(i, j, n) for (int i = (n)-1; j <= i; --i)

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T>& a) {
  os << "{";
  for (size_t i = 0; i < a.size(); ++i) os << (i > 0 ? "," : "") << a[i];
  return os << "}";
}

[[maybe_unused]] constexpr ll MOD = 1e9 + 7;
[[maybe_unused]] constexpr int INF = 0x3f3f3f3f;
[[maybe_unused]] constexpr ll INFL = 0x3f3f3f3f3f3f3f3fLL;

int main() {
  cin.tie(0)->sync_with_stdio(0);
  int n;
  cin >> n;
  vector<ll> a(n), b(n), p(n), q(n);
  vector<vector<int>> g(n);
  rep(i, 0, n) cin >> a[i];
  vector<pair<int, int>> ps;
  rep(i, 0, n) {
    cin >> b[i];
    ps.emplace_back(b[i], i);
  }
  sort(ps.rbegin(), ps.rend());

  rep(i, 0, n) {
    cin >> p[i], --p[i];
    q[p[i]] = i;
  }
  vector<pair<int, int>> ans;
  rep(i, 0, n) {
    // 重い荷物から完了させていく。
    // 重い荷物を渡しても、それがあってるならOK
    // 現在いるところと、
    auto [weight, bidx] = ps[i];
    if (p[bidx] != bidx) {
      int nowi = q[bidx]; // bidxを持っているa
      // bidx bを持たせたいa
      if (a[nowi] <= weight || a[bidx] <= b[p[bidx]]) {
        cout << -1 << '\n';
        return 0;
      }
      ans.emplace_back(nowi + 1, bidx + 1);
      swap(p[nowi], p[bidx]);
      q[p[nowi]] = nowi;
      q[p[bidx]] = bidx;
    }
  }
  cout << ans.size() << '\n';
  for (auto [x, y] : ans) cout << x << " " << y << '\n';

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define all(c) c.begin(),c.end()
#define sz(x) int(x.size())
#define ar array
typedef long long ll ;
typedef vector<int> vi;
#define mod 1000000007
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll exp(ll x,ll y){
  x%=mod;
  ll res=1;
  while(y){
    if(y&1)
    res=res*x%mod;
    x=x*x%mod;
    y>>=1;
  }
  return res;
}
ll fact(ll n){
  ll res=1;
  for(ll i=2;i<=n;++i)
  (res*=i)%=mod;
  return res;
}
bool isprime(ll n){
  if(n<=1) return 0;
  for(ll i=2;i*i<=n;++i)
  if(n%i==0) return 0;
  return 1;
}

int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n;
cin>>n;
set<int>s;
int mx=10000;
for(int i=2;i<=mx;++i){
  if(10*i<=mx)
  s.insert(10*i);
}
for(int i=2;i<=mx;++i){
  if(6*i<=mx)
  s.insert(6*i);
}
for(int i=2;i<=mx;++i){
  if(15*i<=mx)
  s.insert(15*i);
}
cout<<"10 6 15 ";
n-=3;
for(int i=1;i<=n;++i){
  cout<<*s.begin()<<" ";
  s.erase(s.begin());
}
return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define  w(t)                      int t;  cin>>t;  while(t--)
#define  mod1                      1000000007
#define  mod2                      998244353
#define  ll                        long long int
#define  ull                       unsigned long long int
#define  fastIO                    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define  vll                       vector<ll>
#define  vi                        vector<int>
#define  vch                       vector<char>
#define  pll                       pair<ll,ll>
#define  pii                       pair<int,int>
#define  makpii                    make_pair
#define  mpii                      unordered_map<int,int>
#define  sti                       unordered_set<int>
#define  mpci                      unordered_map<char,int>
template<typename T>
T myMax(T x, T y)
{
	return (x > y) ? x : y;
}
struct myComp1          //      sort pairs by second element (MAX)
{
	constexpr bool operator()
	(pair<ll, ll> const& a, pair<ll, ll> const& b)const noexcept
	{
		return a.second < b.second;
	}
};
struct myComp2          //      sort pairs by second element (MIN)
{
	constexpr bool operator()
	(pair<ll, ll> const& a, pair<ll, ll> const& b)const noexcept
	{
		return a.second > b.second;
	}
};
priority_queue<pll, vector<pll>, myComp1> p1; // priority queue with second element in MAX order
priority_queue<pll, vector<pll>, myComp2> p2; // priority queue with second element in MIN order
int32_t main()
{
	fastIO
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int x;
	cin >> x;
	if (x % 100 == 0)
	{
		cout << 100 << "\n";
	}
	else
	{
		int val = x;
		while (val % 100 != 0)
		{
			val++;
		}
		cout << val - x << "\n";
	}
	return 0;
}
/*bool prime[1000001];
int primebeh[1000001];
int primesnear[1000001];
void sieve()
{
	int n = 1000000;
	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;
		}
	}
	int last = 0;
	for (int i = 2; i <= n; i++)
	{
		if (prime[i])
		{
			primesnear[i] = i;
			last = i;
		}
		else
		{
			primesnear[i] = last;
		}
	}
	last = 0;
	for (int i = n; i >= 2; i--)
	{
		if (prime[i])
		{
			primebeh[i] = i;
			last = i;
		}
		else
		{
			primebeh[i] = last;
		}
	}
ll power(ll x, ll y, ll p)
{
	ll res = 1; x = x % p; while (y > 0) {if (y & 1) {res = (res * x) % p;} y = y >> 1; x = (x * x) % p;}
	return res;
}
ll modInverse(ll n, int p)
{
	return power(n, p - 2, p);
}
ll nCrModPFermat(ll n, ll r, ll p)
{
	if (n < r)
		return 0;
	if (r == 0)
		return 1;
	ll fac[n + 1];
	fac[0] = 1;
	for (int i = 1; i <= 1000; i++)
		fac[i] = (fac[i - 1] * i) % mod2;
	return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p;
}
}*/

/*
 *  Created on: 20 / 2 / 2021
 *  Author:     Eslam Waheed
 */

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

clock_t T;
#define ctime         cerr << "Time : " << double(clock() - T) / CLOCKS_PER_SEC << '\n'
#define Eslam__Waheed ios_base::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);

#define ll   long long
#define ull  unsigned ll
#define ld   long double

#define all(c)  c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define stp(n)  cout << fixed << setprecision(n);
#define iq(v)   v.resize(unique(v.begin(),v.end())-v.begin())
#define sz(s)   (ll)s.size()
#define endl    '\n'

/*
int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
*/
//const ld PI = acos(-1);
//ll gcd(ll a, ll b) { return !b ? abs(a) : gcd(b, a % b); }

// ( إن الله وملائكته يصلون على النبي يا أيها الذين آمنوا صلوا عليه وسلموا تسليما )

int main()
{
	//stp(0)
	Eslam__Waheed;
	ll n; cin >> n;
	ll x = n % 100;
	cout << 100 - x;
}


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

#define STRING(str) #str
#define ll long long

template <typename T >
void print_vec_1d(vector<T> x, string name) {
	cout << name << endl;
	cout << "[ ";
	for (int i=0;i<x.size();i++) {
		cout << x[i];
		if (i != x.size()-1) cout << ", ";
		else cout << " ]" << endl;
	}
}

template <typename T >
void print_vec_2d(vector<vector<T>> x, string name) {
	cout << name << endl;
	cout << "[ ";
	for (int i=0;i<x.size();i++) {
		cout << "[ ";
		for (int j=0;j<x[i].size();j++) {
			cout << x[i][j];
			if (j != x[i].size()-1) cout << ", ";
			else {
				cout << " ]";
				if (!((i == x.size()-1) && (j == x[i].size()-1))) {
					cout << "," << endl;
				}
			}
		}
	}
	cout << " ]" << endl;
}

int N;
vector<string> S;

int bfs(int i) {
	queue<int> q;
	q.push(i);
	vector<bool> visited(N, false);
	while (!q.empty()) {
		int ind = q.front();
		q.pop();
		visited[ind] = true;
		for (int j=0;j<N;j++) {
			if (visited[j]) continue;
			if (S[j][ind] == '1') {
				q.push(j);
			}
		}
	}
	int ret = 0;
	for (int j=0;j<N;j++) {
		if (visited[j]) ret++;
	}
	return ret;
}

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

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

	double ans = 0;
	for (int i=0;i<N;i++) {
		ans += (double)1/bfs(i);
	}
	// cout << ans << "\n";
	cout << fixed << setprecision(12) << ans << "\n";
}

/**
*    author:
*    created: 15.11.2020 00:24:55
**/

#pragma region Macros
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
using P = pair<int,int>;
using ll = long long;
const int INF = 1001001001;
const int di[] = {-1,0,1,0}, dj[] = {0,-1,0,1};
typedef vector<int> vi;
typedef vector<vi> vvi;

#define rep(i,n) for(int i = 0; i < (n); i++)
#define repn(i,n) for(int i = 1; i <= (n); i++)
#define pb push_back
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

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

const double PI = acos(-1);
const int mod = 1000000007;
class mint {
  long long x;
  public:
  mint(long long x=0) : x((x%mod+mod)%mod) {}
  mint operator-() const {
    return mint(-x);
  }
  mint& operator+=(const mint& a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint& a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const  mint& a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint& a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint& a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint& a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    return a;
  }
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint& a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint& a) const {
    mint res(*this);
    return res/=a;
  }

  friend ostream& operator<<(ostream& os, const mint& m){
    os << m.x;
    return os;
  }
};
#pragma endregion

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<vector<int>> a(n, vector<int> (n,0));
  rep(i,n){
    rep(j,n){
      char c;
      cin >> c;
      if(c == '1') a[i][j] = 1;
    }
  }
  rep(i,n) a[i][i] = 1;
  rep(k,n)rep(i,n)rep(j,n) a[i][j] |= a[i][k] & a[k][j];
  double ans = 0;
  rep(i,n){
    int cnt = 0;
    rep(j,n) cnt += a[j][i];
    ans += double(1)/double(cnt);
  }
  cout << fixed << setprecision(10);
  cout << ans << "\n";
  return 0;
}


#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
using ll =long long;
using vi = vector<ll>;
using vc = vector<char>;
using vs = vector<string>;
using P = pair<ll , ll>;
using vp = vector<P>;
#define rep(i, n) for (long long int i = 0; i < n; i++)
#define rep2(i, s, n) for (int i = (s); i < n; i++)
#define sort(A) sort(A.begin(),A.end());
#define reverse(A) reverse(A.begin(),A.end());
#define vecint2(A, n, m) vector<vector<long long int>> A(n, vector<long long int>(m));
#define vecchar2(A, n, m) vector<vector<char>> A(n, vector<char>(m));
#define k(s) cout << fixed << setprecision(s);
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
const long double pi=3.14159265358979323846;
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main() {
  ll MOD=998244353;
  int H,W,K;
  cin>>H>>W>>K;
  vecint2(A,H,W);
  vecint2(dp,H,W);
  rep(i,H)rep(j,W){
    A[i][j]=0;dp[i][j]=0;
  }
  rep(i,K){
    int h,w;
    char c;
    cin>>h>>w>>c;
    if(c=='R') A[h-1][w-1]=1;
    if(c=='D') A[h-1][w-1]=2;
    if(c=='X') A[h-1][w-1]=3;
  }
  dp[0][0]=modpow(3,H*W-K,MOD);
  rep(i,H)rep(j,W){
    if(i==0 && j==0){
      continue;
    }else if(i==0){
      if(A[i][j-1]==0) dp[i][j]+=2*dp[i][j-1]%MOD*modinv(3,MOD)%MOD;
      if(A[i][j-1]==1) dp[i][j]+=dp[i][j-1]%MOD;
      if(A[i][j-1]==3) dp[i][j]+=dp[i][j-1]%MOD;
    }else if(j==0){
      if(A[i-1][j]==0) dp[i][0]+=2*dp[i-1][j]%MOD*modinv(3,MOD)%MOD;
      if(A[i-1][j]==2) dp[i][0]+=dp[i-1][j]%MOD;
      if(A[i-1][j]==3) dp[i][0]+=dp[i-1][j]%MOD;
    }else{
      if(A[i][j-1]==0) dp[i][j]+=2*dp[i][j-1]%MOD*modinv(3,MOD)%MOD;
      if(A[i][j-1]==1) dp[i][j]+=dp[i][j-1]%MOD;
      if(A[i][j-1]==3) dp[i][j]+=dp[i][j-1]%MOD;
      if(A[i-1][j]==0) dp[i][j]+=2*dp[i-1][j]%MOD*modinv(3,MOD)%MOD;
      if(A[i-1][j]==2) dp[i][j]+=dp[i-1][j]%MOD;
      if(A[i-1][j]==3) dp[i][j]+=dp[i-1][j]%MOD;
    }
    dp[i][j]%=MOD;
  }
/*  rep(i,H){
    rep(j,W) cout<<dp[i][j]<<" ";
    cout<<endl;
  }
  */

  cout<<dp[H-1][W-1]<<endl;
}

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

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

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

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

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

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

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

inline int mul (int a, int b, int m = MOD) {
    return ((ll)a * b) % m;
}

inline int binpow (int a, int n, int m = MOD) {
    int ans = 1;
    for (; n; n >>= 1) {
        if (n & 1) ans = mul(ans, a, m);
        a = mul(a, a, m);
    }
    return ans;
}

inline void add (int &a, int x, int m = MOD) {
    a += x;
    if (a >= m) a -= m;
    if (a < 0) a += m;
}

inline int sum (int a, int b, int m = MOD) {
    a += b;
    if (a >= m) a -= m;
    if (a < 0) a += m;
    return a;
}

inline int inv (int x, int m = MOD) {
    return binpow(x, m - 2, m); /// only if m is prime
}

vector <int> f, fi;

inline void precalc_f (int n, int m = MOD) {
    f.resize(n);
    fi.resize(n);
    f[0] = 1;
    for (int i = 1; i < n; i++) {
        f[i] = mul(f[i - 1], i, m);
    }
    fi[n - 1] = inv(f[n - 1], m);
    for (int i = n - 2; i >= 0; i--) {
        fi[i] = mul(fi[i + 1], i + 1, m);
    }
}

inline int A (int n, int k, int m = MOD) {
    return mul(f[n], fi[n - k], m);
}

inline int C (int n, int k, int m = MOD) {
    return mul(A(n, k), fi[k], m);
}

const int N = 101;
int dp[N][N * N * (N + 1) / 2] = {};
main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k >> MOD;
    dp[0][0] = 1;
    for (int x = 1; x <= n; x++) {
        vector <int> S(x);
        for (int s = 0, y = 0; s <= k * n * (n + 1) / 2; s++) {
            add(S[y], dp[x - 1][s]);
            if ((k + 1) * x <= s) {
                add(S[y], -dp[x - 1][s - (k + 1) * x]);
            }
            dp[x][s] = S[y];
            add(y, 1, x);
        }
    }
//    for (int i = 1; i <= n; i++) {
//        for (int j = 0; j <= k * n * (n + 1) / 2; j++) {
//            cout << dp[i][j] << ' ';
//        }
//        cout << '\n';
//    }
    for (int x = 1; x <= n; x++) {
        int ans = 0;
        for (int s = 1; s <= k * n * (n + 1) / 2; s++) {
            add(ans, mul(dp[x - 1][s], dp[n - x][s]));
        }
        ans = mul(ans, k + 1);
        add(ans, k);
        cout << ans << '\n';
    }
}


#include <stdio.h>
#include <iostream>
#include <vector>
// #include <bits/stdc++.h>
#include <queue>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cmath>

using namespace std;
typedef long long ll;

#define rep(i,k,n) for(ll i=k; i<(ll)(n); i++)

int main() {
    ll n; cin >> n;
    vector<ll> a(n);
    ll ans = 0;
    rep(i,0,n) {
        cin >> a[i];
        if(a[i]-10 > 0) ans += a[i]-10;
    }

    cout << ans << endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define N 100005
#define MOD 1000000007
#define dd double
#define vi vector<int>
#define vll vector<ll>
#define forr(i,n) for(ll i=0;i<n;i++)
#define revf(i,n) for(ll i=n-1;i>=0;i--)
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep1(i,b) for(ll i=1;i<=b;i++)
#define inp(a,n) for(ll i=0;i<n;i++)cin>>a[i]
#define outp(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" "
#define outp1(a,n) for(ll i=1;i<n;i++)cout<<a[i]<<" "
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) (((a)*(b))/gcd((a),(b)))
#define pb push_back
#define mp make_pair
#define BINSC binary_search
#define BITOUT __builtin_popcount
#define mem(x,n) memset(x,n,sizeof(x))
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define test ll t; cin>>t; while(t--)
#define cn cout<<"\n";
int main()
{
     fast
	 ll k;
	 cin>>k;
	 ll ans=0;
	 REP(i,1,k+1)
	 {
		 REP(j,1,k+1)
		 {
			if(i*j>k)
			break;
			REP(q,1,k+1)
			{
				if(i*j*q>k)
				break;
				ans++;
			}
		 }
	 }
	 cout<<ans;
}


/// HuDzG - NHDanDz "Elderwood" (DangCuto Dep Trai vcl)
#include <bits/stdc++.h>
#define reset(a) memset(a,0,sizeof(a))
#define ll long long
#define ld long double
#define endl '\n'
#define AutoAC int main()
#define OO 1000000000000000000
#define F first
#define S second
#define pii pair <ll, ll>
#define pb push_back
#define nmax 200005
#define HUNGIT "C"
#define MOD 998244353

using namespace std;

const ll M = 1000000;

ll n, Begin[nmax], End[nmax], res[nmax], q, ST[4 * nmax], cnt = 0;
struct pp
{
    ll u, d, id;
} Q[nmax];
vector <ll> g[nmax], node[2];

bool cmp(pp a, pp b)
{
    return a.d < b.d;
}

ll dfs(ll u)
{
    ll Max = 0;
    Begin[u] = ++Begin[0];
    for(auto v : g[u])
        Max = max(Max, dfs(v) + 1);
    End[u] = Begin[0];
    return Max;
}

void Update(ll id, ll l, ll r, ll i, ll v)
{
    if(r < i || i < l) return;
    if(l == r)
    {
        ST[id] = v;
        return;
    }
    ll mid = (l + r) / 2;
    Update(id * 2, l, mid, i, v);
    Update(id * 2 + 1, mid + 1, r, i, v);
    ST[id] = ST[id * 2] + ST[id * 2 + 1];
}

ll Get(ll id, ll l, ll r, ll x, ll y)
{
    if(r < x || y < l) return 0;
    if(x <= l && r <= y) return ST[id];
    ll mid = (l + r) / 2;
    return Get(id * 2, l, mid, x, y) + Get(id * 2 + 1, mid + 1, r, x, y);
}

void bfs()
{
    ll now = cnt % 2, Next = (cnt + 1) % 2;
    cnt++;
    while(!node[now].empty())
    {
        ll u = node[now].back();
        Update(1, 1, n, Begin[u], 0);
        for(auto v : g[u])
        {
            node[Next].pb(v);
            Update(1, 1, n, Begin[v], 1);
        }
        node[now].pop_back();
    }
}

void solve()
{
    cin >> n;
    for (int i = 2; i <= n; i++)
    {
        ll p;
        cin >> p;
        g[p].pb(i);
    }
    cin >> q;
    for(int i = 1; i <= q; i++)
    {
        cin >> Q[i].u >> Q[i].d;
        Q[i].id = i;
    }
    sort(Q + 1, Q + 1 + q, cmp);
    ll Max = dfs(1);
    node[0].pb(1);
    Update(1, 1, n, Begin[1], 1);
    for(int i = 1; i <= q; i++)
    {
        ll u = Q[i].u, d = Q[i].d, id = Q[i].id;
        if(d > Max) break;
        while(cnt < d) bfs();
        res[id] = Get(1, 1, n, Begin[u], End[u]);
    }
    for(int i = 1; i <= q; i++)
        cout << res[i] << endl;
}

AutoAC
{
    // clock_t START, FINISH;
    // START = clock();
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // freopen (HUNGIT".inp", "r", stdin);
    // freopen (HUNGIT".out", "w", stdout);
    ll T = 1;

    // cin >> T;

    for (int i = 1; i <= T; i++)
    {
        solve();
    }

    // FINISH = clock();
    // cout << fixed << setprecision(4);
    // cout << endl << "TIME: " << (ld)((ld)(FINISH - START) / CLOCKS_PER_SEC);
    return 0;
}

#include <bits/stdc++.h>
// #include <atcoder/all>
// using namespace atcoder;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const long long INF = 1e18;
const long long MOD = 1e9+7;
using Graph = vector<vector<ll>>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}
ll ceilll(ll a, ll b) {return (a + b-1) / b;} // if(a%b != 0) (a/b) + 1
ll get_digit(ll a) {ll digit = 0; while(a != 0){a /= 10; digit++;} return digit;} // a != 0
template<typename T> void vecdbg(vector<T>& v){ rep(i, v.size()){cerr << v[i] << " ";} br;}
template<typename T> void vecvecdbg(vector<vector<T>>& v){ rep(i, v.size()){rep(j, v[i].size()){cerr << v[i][j] << " ";} br;}}
ll POW(ll a, ll n){ ll res = 1; while(n > 0){ if(n & 1){ res = res * a; } a *= a; n >>= 1; } return res; }
using P = pair<ll, ll>;

// 0 false, 1 true
// string number to int : -48 or - '0'
// a to A : -32
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp
// global vector -> 0 initialization
// DONT FORGET TO INTIALIZE
// The type of GRID is CHAR. DONT USE STRING
// If the result in local and judge is different, USE CODETEST!!
// (a * b)over flow?   if(a > INF / b){ /* overflow */}

ll n;
ll cnt = 0;
vector<pair<ll, ll>> inout(n);
vector<ll> depth(n);
vector<ll> seen(n);
void dfs(vector<vector<ll>> &g, ll v, ll d){
    //in
    inout[v].first = cnt;
    depth[v] = d;
    seen[v] = 1;
    cnt++;
    for(ll next : g[v]){
        if(seen[next] == 0){
            dfs(g, next, d+1);
            cnt++;
        }
    }
    //out
    inout[v].second = cnt;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    cin >> n;
    vector<vector<ll>> g(n);
    depth.assign(n, 0);
    inout.assign(n, {-1, -1});
    seen.assign(n, 0);
    rep(i, n-1){
        ll p; cin >> p; p--;
        g[i+1].push_back(p); g[p].push_back(i+1);
    }

    dfs(g, 0, 0);
    vector<vector<ll>> hukasa(n);
    rep(i, n){
        ll x = depth[i];
        hukasa[x].push_back(inout[i].first);
    }
    rep(i, n){
        sort(all(hukasa[i]));
    }

    ll q; cin >> q;
    rep(i, q){
        ll u, d; cin >> u >> d; u--;
        ll r = lower_bound(all(hukasa[d]), inout[u].second) - hukasa[d].begin();
        ll l = lower_bound(all(hukasa[d]), inout[u].first) - hukasa[d].begin();
        cout << r - l << endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
const double pi = 3.14159265358979;
const ll inf = 1e17;
const int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
#define pii pair<int,int>
#define pll pair<ll,ll>
#define endl "\n"
#define dtor(deg) (((deg)/360)*2*pi)
#define all(a) a.begin(),a.end()
#define overload(_1,_2,_3,_4,name,...) name
#define _rep1(n) for(int i = 0; i < (n); i++)
#define _rep2(i,n) for(int i = 0; i < (n); i++)
#define _rep3(i,a,b) for(int i = (a); i < (b); i++)
#define _rep4(i,a,b,c) for(int i = (a); i < (b); i += (c))
#define rep(...) overload(__VA_ARGS__,_rep4,_rep3,_rep2,_rep1)(__VA_ARGS__)
#define _rrep1(n) for(int i = (n) - 1; i >= 0; i--)
#define _rrep2(i,n) for(int i = (n) - 1; i >= 0; i--)
#define _rrep3(i,a,b) for(int i = (b) - 1; i >= (a); i--)
#define _rrep4(i,a,b,c) for(int i = (b) - 1; i >= (a); i -= (c))
#define rrep(...) overload(__VA_ARGS__,_rrep4,_rrep3,_rrep2,_rrep1)(__VA_ARGS__)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define vv(type,name,size,...) vector<vector<type>> name(size,vector<type>(__VA_ARGS__))
#define ForEach(a,b) for_each(a.begin(),a.end(),b)
template <class T> bool chmin(T& a, T b){ if(a > b){ a = b; return 1; } return 0; }
template <class T> bool chmax(T& a, T b){ if(a < b){ a = b; return 1; } return 0; }

struct WeightedGraph{
    struct Edge { int to; ll cost; Edge(int to, ll cost) : to(to), cost(cost) {} };
    vector<vector<Edge>> g;
    WeightedGraph(int n) : g(n) {}
    vector<Edge> operator[](int a){ return g[a]; }
    operator vector<vector<Edge>>(){ return g; }
    auto begin(){ return g.begin(); }
    auto end(){ return g.end(); }
    int size(int x){ return g.size(); }
    void resize(int x){ g.resize(x); }
    void DirectConnect(int f, int t, ll c){ g[f].push_back({t, c}); }
    void Connect(int a, int b, ll c){ g[a].push_back({b, c}); g[b].push_back({a, c}); }
    vector<ll> dijkstra(int s){
        int n = g.size();
        vector<ll> dist(n, inf);
        priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> task;
        dist[s] = 0;
        task.push({dist[s], s});
        while(task.size()){
            pii p = task.top();
            task.pop();
            int v = p.second;
            if(dist[v] < p.first) continue;
            for(auto e : g[v]) if(chmin(dist[e.to], dist[v] + e.cost)) task.push({dist[e.to], e.to});
        }
        return dist;
    }
    vector<int> topo_sort(){
        int n = g.size();
        WeightedGraph copy(n);
        vector<int> deg(n);
        vector<int> order;
        queue<int> task;
        rep(n) for(auto v : g[i]){
            copy.DirectConnect(v.to, i, v.cost);
            deg[i]++;
        }
        rep(n) if(!deg[i]) task.push(i);
        while(task.size()){
            int fv = task.front();
            task.pop();
            order.push_back(fv);
            for(auto nv : copy[fv]){
                deg[nv.to]--;
                if(!deg[nv.to]) task.push(nv.to);
            }
        }
        reverse(all(order));
        return order;
    }
};

void Main(){
    int n, m;
    cin >> n >> m;
    WeightedGraph g(n), r(n);
    vector<vector<ll>> cycle(n);
    rep(m){
        int a, b;
        ll c;
        cin >> a >> b >> c;
        a--; b--;
        if(a == b) cycle[a].push_back(c);
        else{ g.DirectConnect(a, b, c); r.DirectConnect(b, a, c); }
    }
    rep(n){
        ll ans = inf;
        vector<ll> t = g.dijkstra(i), tr = r.dijkstra(i);
        for(auto x : cycle[i]) chmin(ans, x);
        rep(j,n) if(i != j) chmin(ans, t[j] + tr[j]);
        if(ans == inf) cout << -1 << endl;
        else cout << ans << endl;
    }
}

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


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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()

typedef pair<int,int> P;

signed main(){
  int n,m,q;cin>>n>>m>>q;
  vector<P> v(n);
  REP(i,n)cin>>v[i].first>>v[i].second;
  sort(ALL(v));
  vector<int> x(m);
  REP(i,m)cin>>x[i];
  auto solve=[&](vector<int> &k){
    sort(ALL(k));
    priority_queue<int> que;
    int res=0,now=0;
    for(int p:k){
      while(now<n&&v[now].first<=p)que.push(v[now++].second);
      if(que.size()){
        res+=que.top();
        que.pop();
      }
    }
    return res;
  };
  while(q--){
    int l,r;cin>>l>>r;l--;
    vector<int> k;
    REP(i,m)if(i<l||r<=i)k.push_back(x[i]);
    cout<<solve(k)<<endl;
  }
}

/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;
#define fst first
#define snd second

void solve(istream &cin, ostream &cout) {
  int n, m, q;
  cin >> n >> m >> q;
  vector<PII> bags(n);
  for (auto &[v, w] : bags)
    cin >> w >> v;
  sort(bags.rbegin(), bags.rend());
  VI boxes(m);
  for (int &box : boxes)
    cin >> box;
  while (q--) {
    int l, r;
    cin >> l >> r;
    l--, r--;
    VI use;
    for (int i = 0; i < m; i++) {
      if (l <= i && i <= r) continue;
      use.push_back(boxes[i]);
    }
    sort(use.begin(), use.end());
    auto heap = bags;
    int tot = 0;
    for (int box : use) {
      for (auto &[v, w] : heap) {
        if (v != 0 && w <= box) {
          tot += v;
          v = 0;
          break;
        }
      }
    }
    cout << tot << '\n';
  }
}

struct DShippingCenter {
  void solve(std::istream &in, std::ostream &out) {
    ::solve(in, out);
  }
};

int main() {
  DShippingCenter solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


#include "bits/stdc++.h"
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,mmx,avx,avx2")
using namespace std;
using ll = long long;

void A()
{
    string s; cin >> s;
    if (s[0] == s[1] && s[1] == s[2]) cout << "Won\n";
    else cout << "Lost\n";
}

void B()
{
    int n, limit; cin >> n >> limit;
    limit *= 100;
    for (int i = 1; i <= n; ++i) {
        int vol, percent; cin >> vol >> percent;
        limit -= vol*percent;
        if (limit < 0) {cout << i; return;}
    }
    cout << -1;
}

void C()
{
    int n; cin >> n;
    int a[n];
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        int mn = a[i];
        for (int j = i; j >= 0; --j) {
            if (a[j] < mn) mn = a[j];
            ans = max(ans, 1LL*mn*(i-j+1));
        }
    }
    cout << ans;
}

void D()
{
    int n; cin >> n;
    vector<string> v(n);
    vector<array<ll, 2>> dp(n+1);
    dp[0][0] = dp[0][1] = 1;
    for (int i = 1; i <= n; ++i) {
        cin >> v[i-1];
        if (v[i-1] == "OR") {
            dp[i][1] = dp[i-1][0] + 2*dp[i-1][1];
            dp[i][0] = dp[i-1][0];
        }
        else {
            dp[i][1] = dp[i-1][1];
            dp[i][0] = dp[i-1][1] + 2*dp[i-1][0];
        }
    }
    cout << dp[n][1];
}

void E()
{
    int n; cin >> n;
    vector<array<ll, 2>> pts(n);
    for (auto &[x, y] : pts)
        cin >> x >> y;
    int m; cin >> m;
    using row = array<ll, 3>;
    using matrix = array<row, 3>;
    vector<matrix> mat(m+1);
    mat[0][0][0] = mat[0][1][1] = mat[0][2][2] = 1;
    auto matmul = [&] (auto &a, auto &b) {
        array<array<ll, 3>, 3> res = array<array<ll, 3>, 3>();
        for (int i = 0; i < 3; ++i)
            for (int j = 0; j < 3; ++j)
                for (int k = 0; k < 3; ++k)
                    res[i][j] += a[i][k] * b[k][j];
        return res;
    };
    for (int i = 1; i <= m; ++i) {
        int type; cin >> type;
        if (type == 1) {
            mat[i] = matrix{row{0, 1, 0}, row{-1, 0, 0}, row{0, 0, 1}};
        }
        else if (type == 2) {
            mat[i] = matrix{row{0, -1, 0}, row{1, 0, 0}, row{0, 0, 1}};
        }
        else {
            int p; cin >> p;
            if (type == 3) {
                mat[i] = matrix{row{-1, 0, 2*p}, row{0, 1, 0}, row{0, 0, 1}};
            }
            else {
                mat[i] = matrix{row{1, 0, 0}, row{0, -1, 2*p}, row{0, 0, 1}};
            }
        }
        mat[i] = matmul(mat[i], mat[i-1]);
    }

    int q; cin >> q;
    while (q--) {
        int a, b; cin >> a >> b;
        auto [x, y] = pts[b-1];
        auto transform = mat[a];
        cout << x*transform[0][0] + y*transform[0][1] + transform[0][2] << ' ' << x*transform[1][0] + y*transform[1][1] + transform[1][2] << '\n';
    }
}

int main()
{
    ios::sync_with_stdio(0); cin.tie(0);
    mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
    E();
}

#include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
using namespace std;
#define int long long
int safe_mod(int x, int m) {
    x %= m;
    if (x < 0) x += m;
    return x;
}
pair<int,int> inv_gcd(int a, int b) {
    a = safe_mod(a, b);
    if (a == 0) return {b, 0};
    int s = b, t = a;
    int m0 = 0, m1 = 1;
    while (t) {
        int u = s / t;
        s -= t * u;
        m0 -= m1 * u;
        auto tmp = s;
        s = t;
        t = tmp;
        tmp = m0;
        m0 = m1;
        m1 = tmp;
    }
    if (m0 < 0) m0 += b / s;
    return {s, m0};
}
pair<int,int> crt(const vector<int>& r, const vector<int>& m) {//if p.second == 0 then there is no answer
    assert(r.size() == m.size());
    int n = (int)(r.size());
    int r0 = 0, m0 = 1;
    for (int i = 0; i < n; i++) {
        assert(1 <= m[i]);
        int r1 = safe_mod(r[i], m[i]), m1 = m[i];
        if (m0 < m1) {
            swap(r0, r1);
            swap(m0, m1);
        }
        if (m0 % m1 == 0) {
            if (r0 % m1 != r1) return {0, 0};
            continue;
        }
        int g, im;
        tie(g, im) = inv_gcd(m0, m1);
        int u1 = (m1 / g);
        if ((r1 - r0) % g) return {0, 0};
        int x = (r1 - r0) / g % u1 * im % u1;
        r0 += x * m0;
        m0 *= u1;
        if (r0 < 0) r0 += m0;
    }
    return {r0, m0};
}
signed main(){
	cin.tie(nullptr)->sync_with_stdio(false);
	int t;
	cin >> t;
	while(t--){
		int x,y,p,q;
		cin >> x >> y >> p >> q;
		int ans = (int)9e18;
		for(int i = x; i<x+y; i++){
			for(int j = p; j<p+q; j++){
				pair<int,int> a = crt({i,j},{x+y+x+y,p+q});
				if(a.second==0)continue;
				ans = min(ans,a.first);
			}
		}
		if(ans==(int)9e18){
			cout << "infinity\n";
		}
		else{
			cout << ans << "\n";
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long template_array_size = 1e6+100;
long long a[template_array_size];
long long b[template_array_size];
ll ans = 21;
void solve(){
	ll a,b,c;
	cin>>a>>b>>c;
	ans = ans - (a+b+c);

	cout<<ans<<"\n";
}
int main(){
	solve();
	return 0;
}

#include <iostream>
using namespace std;

int main()
{
    int X, Y, Z;
    cin >> X >> Y >> Z;

    double a = (double)Z * Y / X;
    int b = (int)a;
    if(a == b) {
        cout << b-1 << endl;
    } else {
        cout << b << endl;
    }

    return 0;
}


#line 1 "/home/siro53/kyo-pro/compro_library/template/template.cpp"
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    for(int i = 0; i < (int)v.size(); i++) {
        if(i) { os << ','; }
        os << v[i];
    }
    os << '}';
    return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
    cerr << " " << x;
    debugg(args...);
}
#define debug(...)                                                             \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

struct Setup {
    Setup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __Setup;

using ll = long long;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define FOR(i, a, b) for(int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------
#line 2 "e.cpp"

int N, Q;
ll a, b, c; // F(x) = min(c, max(b, x+a));

int main() {
    cin >> N;
    a = 0, b = -LLINF, c = LLINF;
    REP(i, N) {
        ll x; int t; cin >> x >> t;
        if(t == 1) {
            a += x, b += x, c += x;
        }else if(t == 2) {
            chmax(b, x); chmax(c, x);
        }else{
            chmin(b, x); chmin(c, x);
        }
    }

    cin >> Q;
    while(Q--) {
        ll x; cin >> x;
        cout << min(c, max(b, x+a)) << endl;
    }
}

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
#include<array>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acosl(-1.0);

ll mod_pow(ll x, ll n, ll m = mod) {
	if (n < 0) {
		ll res = mod_pow(x, -n, m);
		return mod_pow(res, m - 2, m);
	}
	if (abs(x) >= m)x %= m;
	if (x < 0)x += m;
	ll res = 1;
	while (n) {
		if (n & 1)res = res * x % m;
		x = x * x % m; n >>= 1;
	}
	return res;
}
struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n % mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
	if (n == 0)return modint(1);
	modint res = (a * a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
modint operator/=(modint& a, modint b) { a = a / b; return a; }
const int max_n = 1 << 2;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
modint combP(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[a - b];
}

void solve() {
	int n; cin >> n;
	ll c[3] = { 0,-INF,INF };
	rep(i, n) {
		ll a;int t; cin >> a >> t;
		if (t == 1) {
			c[0] += a;
			c[1] += a;
			c[2] += a;
		}
		else if (t == 2) {
			c[1] = max(c[1], a);
			c[2] = max(c[2], a);
		}
		else {
			c[2] = min(c[2], a);
		}
	}
	int q; cin >> q;
	rep(i, q) {
		ll x; cin >> x;
		ll ans = min(max(x + c[0], c[1]), c[2]);
		cout << ans << "\n";
	}
}

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


#include <bits/stdc++.h>

#define REP(i, n) for(i64 i = 0; i < n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for(auto i = a; i != b; ++i)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

using i64 = int_fast64_t;
using u64 = uint_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

const string ln = "\n";
const i64 dx[4] = {1, 0, -1, 0};
const i64 dy[4] = {0, 1, 0, -1};
const i64 inf = 1e18;

i64 Sx, Sy, Gx, Gy;

int main() {
    cin >> Sx >> Sy >> Gx >> Gy;
    f64 ans = Gx - (f64)Gy * (Gx - Sx) / (Gy + Sy);
    cout << fixed << setprecision(10) << ans << ln;
}

#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
    double a,b,c,d;
    double x,k;
    double s,e;
    scanf("%lf%lf%lf%lf",&a,&b,&c,&d);

    x=-d*(c-a)/(d+b)+c;
    printf("%lf",x);

}


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

int main() {
    ll N; cin >> N;
    vector<vector<ll>> C(N, vector<ll>(N));
    vector<ll> A(N), B(N);
    // (最小値, 最小値が含まれる行数) を表す Pair
    P min_val(INF, 0);
    rep(i, N) rep(j, N) {
        ll val;
        cin >> val;
        if (min_val.first > val) {
            min_val = make_pair(val, i);
        }
        C[i][j] = val;
    }
    bool ok = true;
    A[min_val.second] = min_val.first;
    for (ll i = 0; i < N; i++) {
        B[i] = C[min_val.second][i] - A[min_val.second];
    }
    for (ll i = 0; i < N; i++) {
        A[i] = C[i][0] - B[0];
    }
    rep(i, N) rep(j, N) {
        if (C[i][j] != A[i] + B[j]) ok = false;
        if (A[i] < 0 || B[j] < 0) ok = false;
    }
    if (ok) {
        cout << "Yes" << endl;
        rep(i, N) cout << A[i] << endl;
        rep(i, N) cout << B[i] << endl;
    }
    else cout << "No" << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

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

int main()
{
    int N, X; cin >> N >> X;
    int A;
    string ans = "";
    for (int i = 0; i < N; ++i) {
        cin >> A;
        if (A != X) {
            if (ans == "") {
                ans += to_string(A);
            } else {
                ans += " " + to_string(A);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define MOD 	1000000007
#define INF64 	(long long)1e18
#define INF 	(int)1e9
#define ll      long long int
#define ld		long double
const int dx8[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy8[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dx4[4] = {1,0,-1,0};
const int dy4[4] = {0,1,0,-1};

//debug.....................................
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
//............................................
void fastio(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

void solveTest(){
    int n,x;
    cin>>n>>x;
    vector<int> a;
    for(int i=0;i<n;i++){
        int y;
        cin>>y;
        if(y!=x){
            a.push_back(y);
        }
    }
    for(int i:a){
        cout<<i<<" ";
    }

    return;

}

int main(){
	fastio();

	int t=1;
	//cin>>t;
	while(t--){
		solveTest();

	}
	return 0;
}


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

int main(){
    int N;
    cin >> N;
    vector<long long> b(N),M(N);

    long long A;
    cin >> A;
    b.at(0) = A;
    for(int i=1; i<N; i++){
        long long a;
        cin >> a;
        b.at(i) = b.at(i-1) + a;
    }
	M.at(0) = A;
    for(int i=1; i<N; i++){
    	M.at(i) = max(M.at(i-1), b.at(i));
    }

    long long ans = 0;
    long long x = 0;
    for(int i=0; i<N; i++){
       ans = max(ans, x + M.at(i));
       x = x + b.at(i);
    }

    cout << ans;

}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define VI vector<ll>
#define PB push_back
#define MM multimap
#define M map
#define MOD 100000007
#define PRII pair<ll,ll>
#define REP(i,n) for(ll i = 0;i<n;++i)
#define RES(i,n) for(ll i = n-1;i>=0;--i)
const int MAXN = 1e6+10;
const ull inf = 0x3f3f3f3f;
const double eps = 1e-8;
const double pi  = acos(-1);
const double e = exp(1);
int sign(double a) {
	     if (a < -eps) return -1;
	else if (a >  eps) return  1;
	else               return  0;
}
struct Vector{
    double x,y;
};
double dis(Vector a,Vector b){
    return sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y));
}
ll POW(ll a,ll b,ll m){
    if(!b)return 1;
    ll ans = POW(a*a%m,b/2,m);
    return (b%2?ans*a%m:ans);
}
bool is_prime(ll n){
    if(n<=1)
        return 0;
    for(int i = 2;i*i<=n;++i)
        if(n%i==0)
            return 0;
    return 1;
}
ll t;
struct job{
    double c,w;
}a[50];
bool cmp(job a,job b){
    return a.c/a.w < b.c/b.w;
}
ull Stoi(string s){
    reverse(s.begin(),s.end());
    stringstream ss(s);
    ull num = 0;
    ss>>num;
    return num;
}
vector<pair<ll,ll>>v;
int main() {
    ll n;
    cin>>n;
    n = pow(2,n);
    REP(i,n){
        ll t;
        cin>>t;
        v.PB({t,i+1});
    }
    while(v.size()>2){
        n/=2;
        for(int i = 0;i<n;i++){
            if(v[i].first>v[i+1].first)
                v.erase(v.begin()+i+1);
            else
                v.erase(v.begin()+i);
        }
    }
    cout<<(ll)(v[0].first>v[1].first?v[1].second:v[0].second);
}


#include<iostream>
#include<vector>
#include<string>
#include<queue>

using ll = long long;
ll n;
std::vector<ll> p;
std::queue<std::pair<ll, ll>> que; // end index, size

// return inversion number
ll merge_sort(std::vector<ll> &a, ll pos = 0){
    ll size = a.size();
    if(size <= 1) return 0LL;

    ll cnt = 0LL;
    std::vector<ll> b(a.begin(), a.begin() + size / 2);
    std::vector<ll> c(a.begin() + size / 2, a.end());
    cnt += merge_sort(b, pos);
    cnt += merge_sort(c, pos + size / 2);

    int bi = 0, ci = 0;
    // merge array
    for(int ai = 0; ai < size; ai++){
        if(bi < b.size() && (ci == c.size() || b[bi] <= c[ci])){
            a[ai] = b[bi];
            bi++;
        }else{
            cnt += size / 2 - bi;
            que.emplace(pos + b.size() + ci, size / 2 - bi);
            a[ai] = c[ci];
            ci++;
        }
    }

    return cnt;
}

int main(){
    std::cin >> n;
    p.resize(n);
    for(int i = 0; i < n; i++){
        std::cin >> p[i];
    }

    // calculate inversion number
    ll invNum = merge_sort(p);
    if(invNum == n - 1){
        std::vector<bool> flag(n + 1, false);
        std::queue<ll> ans;
        while(!que.empty()){
            auto p = que.front();
            que.pop();
            for(int i = 0; i < p.second; i++){
                if(!flag[p.first - i]){
                    ans.push(p.first - i);
                    flag[p.first - i] = true;
                }else{
                    std::cout << -1 << std::endl;
                    return 0;
                }
            }
        }

        while(!ans.empty()){
            std::cout << ans.front() << std::endl;
            ans.pop();
        }
    }else{
        std::cout << -1 << std::endl;
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int long long
#pragma GCC optimize("O2")
#define CLR(s) memset(&s, 0, sizeof(s))
#define sz(x) ((long long)(x).size())
#define all(x)  x.begin(),x.end()
#define rall(x) (x).rbegin(), (x).rend()
#define trav(a,x) for (auto& a : x)
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define leastsigbit(x)     __builtin_ffs(x)
const int MOD = 1e9 + 7;
#define hmap        unordered_map
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define pii pair<ll,ll>
#define vpii vector<pii>
#define tt ll tt;cin >> tt;while(tt--)
#define  fio ios::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define D1(x) { cerr << " [" << #x << ": " << x << "]\n"; }
#define D2(x) { cerr << " [" << #x << ": "; for(auto it:x) cerr << it << " "; cerr << "]\n";}
const double PI = acos(-1);
ll add(ll x, ll y) {ll res=x+y; return(res>=MOD?res-MOD:res);}
ll mul(ll x, ll y) {ll res=x*y; return(res>=MOD?res%MOD:res);}
ll sub(ll x, ll y) {ll res=x-y; return(res<0?res+MOD:res);}
ll power(ll a,ll b,ll m=MOD){ ll ans=1; a=a%m;  while(b>0) {  if(b&1)  ans=(1ll*a*ans)%m; b>>=1;a=(1ll*a*a)%m;}return ans;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll lcm( ll x, ll y) { return (x*y)/gcd(x,y);}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}
bool isPowerOfTwo(int x)
{
    /* First x in the below expression is for the case when x is 0 */
    return x && (!(x&(x-1)));
}
double distform(int x, int y, int z, int w) {//(x1,y1,x2,y2)
    return sqrt(1. * pow(x-z,2) + 1. * pow(y-w,2));
}
int dx[] = {-1,1,0,0,-1,1,1,-1};
int dy[] = {0,0,1,-1,1,1,-1,-1};
const int MAXN = 2e5+ 10;
const ll inf = 1e18;
template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;}

int intlog(double base, double x) {
    return (int)(log(x) / log(base));
}
void read(vi & a) { for (int i = 0; i < sz(a); ++i) cin >> a[i];}
void solve() {
    int n;
    cin >> n;
    vi a(n); read(a);
    sort(all(a));
    vi suff(n,0);
    for (int i = n - 1; i >= 0; --i) {
        if(i < n - 1) {
            suff[i] = suff[i + 1] + a[i];
        }
        else suff[i] = a[i];
    }
    int ans = 0;

    for (int j = 0; j < n - 1; ++j) {
        ans += abs(suff[j + 1] - a[j] * (n - 1 - j));
    }
    cout << ans << endl;
}
int32_t main() {
    fio

    solve();
}


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define speedX ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
template<typename T>
void __p(T a) { cout << a << " "; }
template<typename T, typename F>
void __p(pair<T, F> a) { cout << "{ "; __p(a.first); __p(a.second); cout << "}"; }
template<typename T>
void __f(const char* s, T t) { cout << s << " : "; __p(t); }
template<typename T>
void __t(const char* s, const T &x) { cout << s << " : { "; for (auto it : x) __p(it); cout << "} ";}
template<typename T, typename ... F>
void __f(const char* s, T t, F ... f) {
	int i = 0; for (;; ++i) if (s[i] == ',') break;
	cout.write(s, i) << " : "; __p(t); cout << " | "; __f(s + i + 1, f...);
}
#define trace(...) { cout<<"LINE: "<<__LINE__<<" || "; __f(#__VA_ARGS__,__VA_ARGS__); cout<<"\n\n"; }
#define debug(...) { cout<<"LINE: "<<__LINE__<<" || "; __t(#__VA_ARGS__,__VA_ARGS__); cout<<"\n\n"; }
int begtime = clock();
#define end_time() cout << "\n\nTime of execution: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define trace(...)
#define debug(...)
#define end_time()
#endif

#define int long long
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef vector<int> vi;
typedef vector<pii> vii;

inline bool equals(ld a, ld b) {return fabs(a - b) < 1e-9;}
inline int gcd(int a, int b) { a=abs(a); b=abs(b); while(a>0 && b>0) (a>b?a%=b:b%=a); return (a==0?b:a); }
inline int power(int x, int n, int m = LLONG_MAX)
    {  int res=1; x = (x%m + m)%m;
       while(n) { if(n&1) res=(res*x)%m;  x=(x*x)%m;  n >>= 1; }  return res;
    }
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define uset unordered_set
#define umap unordered_map
#define all(x) x.begin(), x.end()
#define mod 1000000007

void solve(){
	int n,a,b;
	cin>>n>>a>>b;
	cout<<(n-a+b)<<"\n";
}
signed main(){
	speedX;
	#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
	int t=1;
	//cin>>t;
	for(int i=1;i<=t;++i) {
		//cout<<"Case #"<<i<<": ";
		solve();
	}
	end_time();
	return 0;
}

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

int n, a, b;
int main()
{
	cin >> n >> a >> b;
    cout << n - a + b << endl;
    return 0;
}


#include <bits/stdc++.h>

#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define reset(a,v) memset((a), v, sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

int n;

bool checkDecimal(int x) {
	while (x) {
		int mods = x%10;
		if (mods == 7) return true;
		x /= 10;
	}
	return false;
}

bool checkOctal(int x) {
	while (x) {
		int mods = x%8;
		if (mods == 7) return true;
		x /= 8;
	}
	return false;
}

int main() {
	scanf("%d", &n);
	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		if (!checkDecimal(i) && !checkOctal(i)) {
			++ans;
		}
	}
	printf("%d\n", ans);
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
typedef long long int ll;
int main()
{
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif

	ll n; cin >> n;
	ll k = 0;
	set<ll> s;
	for (int i = 1; i <= n; i++) {
		ll t = i;
		while (t) {
			if (t % 10 == 7) {
				s.insert(i);
				break;
			}
			t = t / 10;
		}
		t=i;
		while (t) {
			if (t % 8 == 7) {
				s.insert(i);
				break;
			}
			// t = t - ((t / 8) * 8);
			t = t / 8;
		}
	}
// 	for (auto i : s) {
// 		cout << i << " ";
// 	}
	cout << n - s.size();
}


#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define repi(i, n) for(int i=0;i<(int)(n);i++)
#define rep2i(i, s, n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define chmax(s, t) s=max(s,t);
#define chmin(s, t) s=min(s,t);

#define deg2rad(deg) (((deg)/360)*2*M_PI)
#define rad2deg(rad) (((rad)/2/M_PI)*360)

using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const ll INF = (1LL<<60);
const int INFi = (1<<29);

/*素数判定*/
bool is_prime(ll n){
    if(n==1) return false;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0) return false;
    }
    return true;
}

/*約数列挙*/
vll enum_divisors(ll n){
    vll l;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            l.push_back(i);
            if(n/i != i) l.push_back(n/i);
        }
    }
   sort(all(l));
   return l;
}

/*素因数分解*/
vector<P> prime_factorize(ll n){
    vector<P> l;
    for(ll i=2;i*i<=n;i++){
        if(n%i!=0) continue;
        ll e = 0;
        while(n%i==0){
            e++;
            n /= i;
        }
        l.push_back({i, e});
    }
    if(n!=1) l.push_back({n, 1});
    return l;
}

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

/*最大公約数*/
ll gcd(ll a, ll b){
    return __gcd(a,b);
}

/*組み合わせ(Combination)*/
const ll CMAX = 1010000;
const ll CMOD = 1e9+7;
ll fac[CMAX], finv[CMAX], inv[CMAX];
// テーブルを作る前処理
void combinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll i = 2; i < CMAX; i++) {
		fac[i] = fac[i - 1] * i % CMOD;
		inv[i] = CMOD - inv[CMOD%i] * (CMOD / i) % CMOD;
		finv[i] = finv[i - 1] * inv[i] % CMOD;
	}
}
// 二項係数計算
ll comb(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % CMOD) % CMOD;
}

/*階乗*/
ll factorial(ll n){
    const ll FMOD = 1e9+7;
    ll ret = n;
    for(ll i=n-1;i>0;i--){
        ret*=i;
        ret%=FMOD;
    }
    return (ret?ret:1);
}

int main(){

    ll n, s, d; cin >> n >> s >> d;
    string ans = "No";
    rep(i, n){
        ll x, y;
        cin >> x >> y;
        if(x<s && y>d){
            ans = "Yes";
        }
    }

    cout << ans << endl;

    return 0;
}

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

bool check(const int64_t x, vector<vector<int64_t>>& a) {
    set<int> s;
    for (auto i = 0; i < (int)a[0].size(); i++) {
        auto t = 0;
        for (auto j = 0; j < 5; j++)
            t |= ((a[j][i] >= x) << j);
        s.insert(t);
    }
    for (auto& i : s)
        for (auto& j : s)
            for (auto& k : s)
                if ((i | j | k) == (1 << 5) - 1)
                    return true;
    return false;
}

int64_t bin_search(const int64_t ng, const int64_t ok,
                   vector<vector<int64_t>>& a) {
    int64_t left = ng, right = ok;
    while (abs(right - left) > 1) {
        int64_t mid = (left + right) / 2;
        if (check(mid, a)) right = mid;
        else
            left = mid;
    }
    return right;
};

int main() {
    int64_t n;
    cin >> n;
    vector<vector<int64_t>> a(5, vector<int64_t>(n));
    for (auto i = 0; i < n; i++)
        for (auto j = 0; j < 5; j++) cin >> a[j][i];
    cout << bin_search(1e9 + 1, 0, a) << endl;
    return 0;
}