#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;
  }
}
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);
}
int WRITER_DOUBLE_DIGIT = 15;
inline int writerDigit_double(){
  return WRITER_DOUBLE_DIGIT;
}
inline void writerDigit_double(int d){
  WRITER_DOUBLE_DIGIT = d;
}
inline void wt_L(double x){
  const int d = WRITER_DOUBLE_DIGIT;
  int k;
  int r;
  double v;
  if(x!=x || (x==x+1 && x==2*x)){
    my_putchar_unlocked('E');
    my_putchar_unlocked('r');
    my_putchar_unlocked('r');
    return;
  }
  if(x < 0){
    my_putchar_unlocked('-');
    x = -x;
  }
  x += 0.5 * pow(0.1, d);
  r = 0;
  v = 1;
  while(x >= 10*v){
    v *= 10;
    r++;
  }
  while(r >= 0){
    r--;
    k = floor(x / v);
    if(k >= 10){
      k = 9;
    }
    if(k <= -1){
      k = 0;
    }
    x -= k * v;
    v *= 0.1;
    my_putchar_unlocked(k + '0');
  }
  if(d > 0){
    my_putchar_unlocked('.');
    v = 1;
    for(r=(0);r<(d);r++){
      v *= 0.1;
      k = floor(x / v);
      if(k >= 10){
        k = 9;
      }
      if(k <= -1){
        k = 0;
      }
      x -= k * v;
      my_putchar_unlocked(k + '0');
    }
  }
}
double dp[101][101][101];
int main(){
  int i;
  int A;
  rd(A);
  int B;
  rd(B);
  int C;
  rd(C);
  for(i=(100)-1;i>=(A);i--){
    int j;
    for(j=(100)-1;j>=(B);j--){
      int k;
      for(k=(100)-1;k>=(C);k--){
        if(i+j+k > 0){
          dp[i][j][k] = 1 + (dp[i+1][j][k] * i + dp[i][j+1][k] * j + dp[i][j][k+1] * k) / (i+j+k);
        }
      }
    }
  }
  wt_L(dp[A][B][C]);
  wt_L('\n');
  return 0;
}
// cLay version 20201123-1

// --- original code ---
// double dp[101][101][101];
// {
//   int @A, @B, @C;
//   rrep(i,A,100) rrep(j,B,100) rrep(k,C,100) if(i+j+k > 0){
//     dp[i][j][k] = 1 + (dp[i+1][j][k] * i + dp[i][j+1][k] * j + dp[i][j][k+1] * k) / (i+j+k);
//   }
//   wt(dp[A][B][C]);
// }

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

long double dp[100][100][100];

long double solve(int a, int b, int c, int cnt) {
	// basis
	if (a == 100 || b == 100 || c == 100)
	{
		return cnt;
	}

	if (dp[a][b][c] != 0)
	{
		return dp[a][b][c];
	}

	long double ret = 0;

	// a + 1
	ret += solve(a + 1, b, c, cnt + 1) * a / (a + b + c);

	// b + 1
	ret += solve(a, b + 1, c, cnt + 1) * b / (a + b + c);

	// c + 1
	ret += solve(a, b, c + 1, cnt + 1) * c / (a + b + c);

	return  dp[a][b][c] = ret;
}

int main() {
	int a, b, c;
	cin >> a >> b >> c;

	cout << setprecision(12) << solve(a, b, c, 0) << endl;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// --------------------------------------------------------
template<class T> bool chmax(T& a, const T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T b) { if (b < a) { a = b; return 1; } return 0; }
#define FOR(i,l,r) for (int i = (l); i < (r); ++i)
#define RFOR(i,l,r) for (int i = (r)-1; (l) <= i; --i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define MIN(c) *min_element(ALL(c))
#define MAX(c) *max_element(ALL(c))
#define SUM(c) accumulate(ALL(c), 0)
#define SUMLL(c) accumulate(ALL(c), 0LL)
#define SZ(c) ((int)(c).size())
#define CIN(c) cin >> (c)
#define COUT(c) cout << (c) << '\n'
#define debug(x) cerr << #x << " = " << (x) << '\n';
using P = pair<int,int>;
using VP = vector<P>;
using VVP = vector<VP>;
using VS = vector<string>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<ll>;
using VVLL = vector<VLL>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
static const double EPS = 1e-10;
static const double PI  = acos(-1.0);
static const ll MOD = 1000000007;
// static const ll MOD = 998244353;
static const int INF = (1 << 30) - 1;  // 1073741824 - 1
// static const ll INF = (1LL << 62) - 1;  // 4611686018427387904 - 1
// --------------------------------------------------------
// #include <atcoder/all>
// using namespace atcoder;

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

    ll r1, c1; cin >> r1 >> c1;
    ll r2, c2; cin >> r2 >> c2;

    ll dr = llabs(r1 - r2);
    ll dc = llabs(c1 - c2);
    if (r1 == r2 && c1 == c2) { COUT(0); return 0; }
    if (dr + dc <= 3) { COUT(1); return 0; }
    if (dr == dc) { COUT(1); return 0; }
    if (dr + dc <= 6) { COUT(2); return 0; }
    if (llabs(dr - dc) % 2 == 0) { COUT(2); return 0; }
    if (llabs(dr - dc) <= 3) { COUT(2); return 0; }
    COUT(3); return 0;

    return 0;
}

#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;
vector<ll> ans_vec(500,0);
ll H,W,A,B;

void dfs(ll a,ll k,ll board[]){
    if(k == A){
        ans_vec[a]++;
    }
    for(ll h=0;h<H;h++){
        for(ll w=0;w<W;w++){
            if(k < a){
                if(w == W-1)
                    continue;
                if(board[h*H+w] == 1 || board[h*H+w+1] == 1)
                    continue;
                ll copy_board[500];
                rep(i,500)
                    copy_board[i] = board[i];
                copy_board[h*H+w] = 1;
                copy_board[h*H+w+1] = 1;
                dfs(a,k+1,copy_board);
            }
            else{
                if(h == H-1)
                    continue;
                if(board[h*H+w] == 1 || board[h*H+w+H] == 1)
                    continue;
                ll copy_board[500];
                rep(i,500)
                    copy_board[i] = board[i];
                copy_board[h*H+w] = 1;
                copy_board[h*H+w+H] = 1;
                dfs(a,k+1,copy_board);
            }
        }
    }
}

ll frac(ll a){
    if(a == 0)
        return 1;
    else
        return a*frac(a-1);
}

int main(){
    ll ans = 0;
    cin >> H >> W >> A >> B;
    if(H < W){
        ll tmp = W;
        W = H;
        H = tmp;
    }

    //0...縦 1...横

    for(ll a = 0; a <= A; a++){
        ll board[500];
        memset(board,0,sizeof(board));
        dfs(a,0,board);
    }
    for(ll a = 0; a <= A;a++){
        ans += ans_vec[a]/(frac(a)*frac(A-a));
    }
    cout << ans << endl;
}


#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <bitset>
#include <vector>
#include <cstdio>
#include <string>
#include <cassert>
#include <climits>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define PB push_back
#define MP make_pair
#define SZ(v) ((int)(v).size())
#define abs(x) ((x) > 0 ? (x) : -(x))
#define FOREACH(e,x) for(__typeof(x.begin()) e=x.begin();e!=x.end();++e)
typedef long long LL;

const int maxn = 105;
int n;
int x[maxn], y[maxn];
double d[maxn][maxn];

struct DisJointSet{
	int rank[maxn], parent[maxn];

	void init(int n) {
		for (int i = 0; i < n; i++) {
			rank[i] = 0;
			parent[i] = i;
		}
	}

	int Find(int x) {
		if (parent[x] == x) return x;
		return parent[x] = Find(parent[x]);
	}

	void Union(int x, int y) {
		x = Find(x);
		y = Find(y);

		if (x == y) return;

		if (rank[x] >= rank[y]) {
			parent[y] = x;
			if (rank[x] == rank[y])
				rank[x]++;
		}
		else {
			parent[x] = y;
		}
	}

	int count(int n) {
		int ret = 0;
		for (int i = 0; i < n; i++)
			ret += Find(i) == i;
		return ret;
	}
}uf;

double distance(int x1, int y1, int x2, int y2) {
    return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

bool check(double r) {
    int s = n, t = n + 1;
    uf.init(n + 2);
    for (int i = 0; i < n; i++) {
        if (100 - y[i] <= 2 * r) {
            uf.Union(s, i);
        }
        if (y[i] - (-100) <= 2 * r) {
            uf.Union(i, t);
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (d[i][j] <= 2 * r) {
                uf.Union(i, j);
            }
        }
    }
    return uf.Find(s) == uf.Find(t);
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
    }
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            d[i][j] = d[j][i] = distance(x[i], y[i], x[j], y[j]);
        }
    }

    double lo = 0, hi = 200, res;
    while (hi - lo > 1e-5) {
        double mid = (lo + hi) / 2;
        if (check(mid)) {
            res = mid;
            hi = mid;
        } else {
            lo = mid;
        }
    }
    printf("%.4f\n", res);
    return 0;
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (ll i=(ll)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const ll INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(ll x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { ll d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll modpow(ll x, ll p) { ll result = 1, now = 1, pm = x; while (now<=p) { if (p&now) { result = result * pm % MOD; } now*=2; pm = pm*pm % MOD; } return result; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

struct coord {
  double x, y; ll i;
  bool operator< (const coord &c) const { return x<c.x||(x==c.x&&y<c.y); };
};

struct dist {
  ll x, y; double d;
  bool operator< (const dist &c) const { return d<c.d; };
};

dist calc_d(coord x, coord y) {
  double d = sqrt(pow(x.x-y.x,2)+pow(x.y-y.y,2));
  return {x.i, y.i, d};
}

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

struct UnionFind {
  vector<int> par, s;
  UnionFind(int N) : par(N), s(N) { rep(i,N) { par[i] = i; s[i] = 1; } }
  int root(int x) { return par[x]==x ? x : par[x] = root(par[x]); }
  int size(int x) { return par[x]==x ? s[x] : s[x] = size(root(x)); }
  void unite(int x, int y) { int rx=root(x), ry=root(y); if (rx!=ry) { s[rx] += s[ry]; par[ry] = rx; } }
  bool same(int x, int y) {  int rx=root(x), ry=root(y); return rx==ry; }
};

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

int main() {
  ll N; cin >> N;
  coord c[N]; rep(i,N) { cin >> c[i].x >> c[i].y; c[i].i = i+1; }
  vector<dist> d;
  rep(i,N) repr(j,i+1,N) d.push_back(calc_d(c[i], c[j]));
  rep(i,N) {
    d.push_back({0  ,c[i].i,c[i].y+100.0});
    d.push_back({N+1,c[i].i,100.0-c[i].y});
  }
  sort(all(d));

  // for (auto x: d) cout << x.x << "-" << x.y << ": " << x.d << endl;
  UnionFind uf(N+2);
  double result;
  for (auto x: d) {
    uf.unite(x.x, x.y);
    if (uf.same(0,N+1)) {
      result = x.d/2;
      break;
    }
  }
  cout << setprecision(10) << result << endl;
  return 0;
}


/*	_____________________
	|Author : canhnam357|
	|___________________|
*/
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <string> vs;
typedef vector <vector <int>> vvi;
typedef vector <vll> vvll;
typedef map<int, int> mi;
typedef map<string, int> ms;
typedef map<char, int> mc;
typedef map <int, bool> mb;
typedef map<ll, ll> mll;
typedef unordered_map<int, int> umi;
typedef unordered_map<string, int> ums;
typedef unordered_map<char, int> umc;
typedef unordered_map <int, bool> umb;
typedef unordered_map<ll, ll> umll;
typedef vector <ld> vld;
typedef vector <bool> vb;
typedef pair <int, int> pii;
typedef pair<ll, ll> pll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
int CASE = 1;
const int mxn = 4e3 + 1;
const ll INF = 1e10;
#define FOR(i,N) for(ll i = 0 ; i < N;i++)
#define eFOR(i,a,b) for(ll i = a; i <=b;i++)
#define dFOR(i,N) for(ll i = N - 1; i>=0;i--)
#define edFOR(i,b,a) for(ll i = b ; i >=a;i--)
#define all(x) x.begin(),x.end()
#define SORT(x) sort(all(x))
#define RSORT(x) sort(x.rbegin(),x.rend())
#define UNQ(x)  unique(all(x))
#define mine(x) min_element(all(x))
#define maxe(x) max_element(all(x))
#define lb(v, x) lower_bound(all(v) , x)
#define ub(v , x) upper_bound(all(v) , x)
#define pb push_back
#define PI 3.141592653589793
#define FIX cout << fixed << setprecision(15)
#define g(i , a) get<i>(a)
const ll mod = 2e5;
int a[1000000];
bool prime(ll n)
{
	if (n <= 1)
		return false;
	eFOR(i, 2, sqrt(n))
		if (!(n % i))
			return false;
	return true;
}
ll __gcd(ll a, ll b)
{
	return !b ? a : __gcd(b, a % b);
}
bool cpx(pair<pii, pii> a, pair<pii, pii> b)
{
	return a.first.first < b.first.first;
}
bool cpy(pair<pii, pii> a, pair<pii, pii> b)
{
	return a.second.first < b.second.first;
}
void solve()
{
	int n;
	cin >> n;
	vector <pair<pii, pii>> v;
	vi vx, vy;
	vb ok(n, false);
	FOR(i, n)
	{
		int x, y;
		cin >> x >> y;
		v.push_back(make_pair(make_pair(x, i), make_pair(y, i)));
	}
	sort(all(v), cpx);
	set <pair <pii, pii>> s;
	s.insert(v[0]);
	s.insert(v[1]);
	s.insert(v[n - 2]);
	s.insert(v[n - 1]);
	sort(all(v), cpy);
	s.insert(v[0]);
	s.insert(v[1]);
	s.insert(v[n - 2]);
	s.insert(v[n - 1]);
	vector <pair<pii, pii>> vec(all(s));
	vi ans;
	for (int i = 0; i < vec.size() - 1; i++)
	{
		for (int j = i + 1; j < vec.size(); j++)
		{
			ans.push_back(max(abs(vec[i].first.first - vec[j].first.first), abs(vec[i].second.first - vec[j].second.first)));
		}
	}
	RSORT(ans);
	cout << ans[1];
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int T = 1;
	while (T--)
	{
		solve();
	}
	return 0;
}

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

typedef long long int lld;
#define all(m) m.begin(),m.end()
#define sz(m) lld(m.size())
#define pb push_back
#define mod 1000000007
#define st first
#define nd second
#define endl "\n"

#ifdef LOCAL
	#define debug(...) debug_out(#__VA_ARGS__, __VA_ARGS__)
	#define debug2(v,a,b) debug2_out(#v,v,a,b)
#else
	#define debug(...)
	#define debug2(v,a,b)
#endif

const int N=1e6+100;
void swagWaalaFunction()
{
	lld l,r,ans=0;
	cin>>l>>r;

	vector<lld> nfac(N);
	// Counts number of factors
	// stores -ve value if it is of form a1^x1 * a2^x2 ...., where a1,a2 are primes and some xi%2==0
	// Used to calculate mobius

	for(lld i=2;i<=r;i++)
	{
		if(nfac[i])
			continue;
		for(lld j=i;j<=r;j+=i)
			nfac[j]++;
		for(lld j=i*i;j<=r;j+=i*i)
			nfac[j]=-1e18;
	}

	// MOBIOUS MAGICCCC !!!
	for(lld i=2;i<=r;i++)
	{
		if(nfac[i]<0)
			continue;

		lld cnt=r/i-(l-1)/i;
		lld pairs=cnt*(cnt-1)/2;
		if(nfac[i]%2)
			ans+=pairs;
		else
			ans-=pairs;
	}

	// Remove multiples
	for(lld i=max(2LL,l);i<=r;i++)
		ans-=(r/i-1);

	ans*=2; // x,y and y,x are different
	cout<<ans<<endl;
}

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

	lld tc=1;
	//cin>>tc;

	for(int i=0;i<tc;i++)
	{
		// cout<<"Case #"<<i+1<<": ";
		swagWaalaFunction();
	}
	return 0;
}


#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define mp make_pair
#define pb push_back
#define pll pair<LL,LL>
#define pii pair<int,int>
#define y second
#define x first
#define LL long long
#define ULL unsigned long long
#define sqr(x) ((x)*(x))
#define pi acos(-1)
#define pdd pair<double,double>
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
using namespace std;
void solve(){
    LL n;
    scanf("%lld",&n);
    LL tmp=n+1;
    LL Max=2e9+10,Min=0;
    while(Max>Min+1){
        LL mid=(Max+Min)/2;
        if(mid*(mid+1)/2<=n+1)Min=mid;
        else Max=mid;
    }
    printf("%lld\n",n+1-Min);
}
int main(){
    int t=1;
   // scanf("%d",&t);
    while(t--){
        solve();
    }
}

#include <bits/stdc++.h>
using namespace std;
int main() {
  long N;
  cin >> N;
  long count = 0;
  long tasu = 0;
  for(long i = 1; i <= N+1; i++) {
    tasu += i;
    if(tasu > N+1) break;
    count++;
  }
  cout << N + 1 - count << endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
const ll mod=998244353;
const int N=2e6+1;
int n,k;
char c[101];
ll md[101];
char dp[101][101];//
char win(char x,char y){
	if(x==y) return x;
	if(x+y=='P'+'S') return 'S';
	if(x+y=='P'+'R') return 'P';
	return 'R';
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);
	cin >> n >> k;
	md[0]=1;
	for(int i=0; i<n ;i++){
		cin >> c[i];
		dp[0][i]=c[i];
	}
	md[0]=1;
	for(int j=1; j<=k ;j++){
		md[j]=md[j-1]*2%n;
	}
	for(int i=1; i<=k ;i++){
		for(int j=0; j<n ;j++){
			dp[i][j]=win(dp[i-1][j],dp[i-1][(j+md[i-1])%n]);
		}
	}
	cout << dp[k][0] << '\n';
}

#include <bits/stdc++.h>
using namespace std;
//const long nPrime = 1000000007;
//const long nPrime = 998244353;
int main() {
    long n,k;
    cin >> n >> k;
    vector<vector<long>> vviGrid(n,vector<long>(n));
    for(long i = 0; i < n; i++){
        for(long j = 0; j < n; j++){
            cin >> vviGrid[i][j];
        }
    }

    long iOK = 2e9, iNG = -1;
    while(iOK - iNG > 1){
        long iTmp = (iOK+iNG)/2;
        vector<vector<long>> vviGridThis(n,vector<long>(n));
        for(long i = 0; i < n; i++){
            for(long j = 0; j < n; j++){
                vviGridThis[i][j] = (iTmp<vviGrid[i][j]) ? 1 : 0;
            }
        }
        vector<vector<long>> vviSum(n+1,vector<long>(n+1,0));
        for(long i = 1; i <= n; i++){
            for(long j = 1; j <= n; j++){
                vviSum[i][j] = vviSum[i-1][j]+vviSum[i][j-1]-vviSum[i-1][j-1]+vviGridThis[i-1][j-1];
            }
        }

        long iMin = 1e9;
        for(long i = k; i <= n; i++){
            for(long j = k; j <= n; j++){
                long iThis = vviSum[i][j]-vviSum[i][j-k]-vviSum[i-k][j]+vviSum[i-k][j-k];
                iMin = min(iMin, iThis);
            }
        }
        if(iMin >= (k*k)/2+1){
            iNG = iTmp;
        } else {
            iOK = iTmp;
        }
    }

    cout << iOK << endl;
    return 0;
}


        // Rakib (CSE'19)

        #include<bits/stdc++.h>
        #include<iostream>
        #include<queue>
        #include<stack>
        #include<set>
        #include<iomanip>
        #include<iterator>
        #include<sstream>
        #include<algorithm>
        #include<vector>
        #include<string>
        #include<cstdlib>
        #include<cmath>
        #include<map>

        #define               boost_                 ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
        #define               pb                     push_back
        #define               read(i,n,a)            for(i=0;i<n;++i) cin>>a[i]
        #define               print(i,a)             for(auto i:a) cout<<i<< " " ; cout<<endl ;
        #define               dpoint(n)              cout<<showpoint<<fixed<<setprecision(n)
        #define               MOD                    1000000007
        #define               llmax                  LONG_LONG_MAX
        #define               llmin                  LONG_LONG_MIN
        #define               read_grid(i,j,n,m,a)   for(i=0;i<n;++i) for(j=0;j<m;++j) cin >> a[i][j];
        #define               all(a)                 a.begin(),a.end()
        #define               vl                     vector<ll>
        #define               MP                     make_pair

        typedef               long long              ll;
        typedef               unsigned long long     ull;

        using namespace std;

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

        /*ll MX=100001;
        //vector<ll>check(MX,1), divisor(MX,2);
        //vector<ll>primes,divisor;

        void prime(){

                ll i,j;
                //check[1]=0;
                //check[2]=1;
                //primes.pb(2);
                for(i=3;i<MX;i+=2){
                        if(check[i]){
                                //primes.pb(i);
                                divisor[i]=i;
                                for(j=i*i;j<MX;j+=2*i) divisor[j]=i, check[j]=0;
                        }
                }
        } */

        ll power_mod(ll b,ll p){

                ll ans=1;
                b%=MOD; //if b>MOD;
                if(!b) return 0 ;
                while(p){
                        if(p%2) ans=(ans*b)%MOD;
                        p>>=1; // top to bottom
                        b=(b*b)%MOD; // bottom to top
                }

                return ans;
        }

        bool cmp(const pair<ll,ll> &a, const pair<ll,ll> &b){ return 2*a.first+a.second>2*b.first+b.second; }

        void task(ll case_no){

                ll n;
                cin >> n;
                vector<pair<ll,ll>>a;

                ll sum=0,cnt=n;
                while(n--){
                        ll x,y;
                        cin >> x >> y;
                        a.pb({x,y});
                        sum+=x;
                }

                sort(all(a),cmp);

                ll sum1=0,i;

                for(i=0;i<a.size();++i){

                      sum1+=a[i].first +a[i].second;
                      sum-=a[i].first;
                      if(sum1>sum) break;

                }

                cout << i+1  << "\n";

        }

        int main(){

                boost_;

                //prime();
                ll t=1,i=0;
                //cin >> t;

                while(t--){

                        task(++i);

                }

                return 0;
        }

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

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

struct edge {int to, cost; };

int main(){
  int n;
  cin >> n;
  ll sa = 0;
  ll delta[n];
  for(int i=0; i<n; i++){
    ll a, b;
    cin >> a >> b;
    sa += a;
    delta[i] = 2*a+b;
  }
  sort(delta, delta+n, greater<ll>());
  int ans = 0;
  for(int i=0; i<n; i++){
    if(sa<0) break;
    sa -=  delta[i];
    ans++;
  }
  cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
const int N=5e6+5;
const int M=1e5+5;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
const double eps=1e-8;
const long double pi=acos(-1.0L);
#define ls (i<<1)
#define rs (i<<1|1)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mem(a,b) memset(a,b,sizeof(a))
LL read()
{
    LL x=0,t=1;
    char ch;
    while((ch=getchar())<'0'||ch>'9') if(ch=='-') t=-1;
    while(ch>='0'&&ch<='9'){ x=(x<<3)+(x<<1)+ch-'0'; ch=getchar(); }
    return x*t;
}
int a[N],ans[N];
int main()
{
    int T=read();
    while(T--)
    {
        //并不需要考虑去将每一个数字归位，而是可以直接考虑减少逆序对(交换相邻的逆序数字)
        int n=read(),tot=0;
        for(int i=1;i<=n;i++) a[i]=read();
        for(int k=0;;k^=1){
            int flag=0;
            for(int i=1;i<n;i++)
                if(a[i]>a[i+1]) flag=1;
            if(!flag) break;
            int i;
            for(i=k+1;i<n&&a[i]<a[i+1];i+=2);
            if(i>=n) i-=2;
            ans[++tot]=i;
            swap(a[i],a[i+1]);
        }
        printf("%d\n",tot);
        for(int i=1;i<=tot;i++) printf("%d%c",ans[i],i==tot?'\n':' ');
    }

    return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

void testcase(){
  int N; cin >> N;
  vector<int> A(N); rep(i,N) cin >> A[i];
  vector<int> ans;
  int turn = 0;
  auto op = [&ans,&A,&turn](int p)->void{
    swap(A[p],A[p+1]);
    ans.push_back(p+1);
    turn ^= 1;
  };

  while(A.size() >= 4){
    int p = -1;
    rep(i,A.size()) if(A[i] == A.size()) p = i;
    if(p%2 != turn){
      int x = -1;
      if(p == 0) op(1);
      if(p == 1) op(2);
      if(p == 2){ op(1); op(2); p=1; }
      if(p >= 3 && p%2 == 1) op(0);
      if(p >= 4 && p%2 == 0) op(1);
    }
    while(p != A.size()-1){
      op(p++);
    }
    A.pop_back();
  }

  vector<int> tg(A.size());
  rep(i,tg.size()) tg[i] = i+1;
  while(tg != A) op(turn);

  cout << ans.size() << "\n";
  rep(i,ans.size()){
    if(i) cout << " ";
    cout << ans[i];
  }
  cout << "\n";
}

int main(){
  int T; cin >> T;
  while(T--) testcase();
  return 0;
}

struct ios_do_not_sync{
  ios_do_not_sync(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
  }
} ios_do_not_sync_instance;


#include<bits/stdc++.h>

using namespace::std;

class Advertisement{
    public:
        void set_val(int x,int y,int inr);
        long get_height();
        long get_width();
        long a;
        long b;
        long c;
        long d;
        long s;
        long r;
};

void Advertisement::set_val(int x,int y,int inr){
    a = x;
    b = y;
    c = x+1;
    d = y+1;
    r = inr;
    s = 1;
}

long Advertisement::get_width(){
    return d-b;
}

long Advertisement::get_height(){
    return c-a;
}

int main(){
    long n;
    cin >> n;
    long x,y,r;
    Advertisement *ad = new Advertisement[n];
    for(int i=0;i<n;i++){
        cin >> x >> y >> r;
        ad[i].set_val(x,y,r);
    }
    for(int i=0;i<n;i++){
        cout << ad[i].a << ' ' << ad[i].b << ' ' << ad[i].c << ' ' << ad[i].d << ' ' << endl;
    }
}

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include <cassert>
#include <numeric>
#include <unordered_map>
//#include <atcoder/all>
#include <queue>
#include <math.h>
#include <climits>
#include <set>
#include <map>
//using namespace atcoder;

typedef long long ll;
#define FOR(i, a, b) for(ll i=(a); i<(b);i++)
#define REP(i, n) for(ll i=0; i<(n);i++)
#define ROF(i, a, b) for(ll i=(b-1); i>=(a);i--)
#define PER(i, n) for(ll i=n-1; i>=0;i--)
#define REPREP(i,j,a,b) for(ll i=0;i<a;i++)for(ll j=0;j<b;j++)
#define VV(type) vector<vector<type>>
#define VV2(type,n,m,val) vector<vector<type>> val;val.resize(n);for(ll i;i<n;i++)val[i].resize(m)
#define vec(type) vector<type>
#define VEC(type,n,val) vector<type> val;val.resize(n)
#define VL vector<ll>
#define SZ size()
#define all(i) begin(i),end(i)
#define SORT(i) sort(all(i))
#define max(a,b) a>b?a:b
using namespace std;

int main() {
  ll n;
  cin >> n;
  VL x(n),y(n),r(n);
  ll mi = n;
  ll mx = 0;
  REP(i, n) {
    cin >> x[i] >> y[i] >> r[i];
    if (mx < r[i]) {
      mx = r[i];
      mi = i;
    }
  }
  if (1.25*1e9 < mx * n) {
    REP(i, n) {
      if (i == mi) {
        cout << x[(i + 0) % n] <<" "<< y[(i + 0) % n] << " " << x[(i + 0) % n] + 1 << " " << y[(i + 0) % n] + 1<<endl;
      }
      else if ((i + 1) % n == mi) {
        cout << x[(i + 2) % n] << " " << y[(i + 2) % n] << " " << x[(i + 2) % n] + 1 << " " << y[(i + 2) % n] + 1 << endl;
      }
      else {
        cout << x[(i + 1) % n] << " " << y[(i + 1) % n] << " " << x[(i + 1) % n] + 1 << " " << y[(i + 1) % n] + 1 << endl;
      }
    }
  }
  else {
    REP(i, n) {
      cout << x[(i + 1) % n] << " " << y[(i + 1) % n] << " " << x[(i + 1) % n] + 1 << " " << y[(i + 1) % n] + 1 << endl;
    }
  }

  return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

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

template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <typename T> void coutall(T v) { if(v.empty()){cout << endl; return;} for(auto i = v.begin(); i != --v.end(); i++){cout << *i << " ";} cout << *--v.end() << endl; }
template <typename T> void DEBUGall(T v) { if(v.empty()){cerr << endl; return;} for(auto i = v.begin(); i != --v.end(); i++){cerr << *i << " ";} cerr << *--v.end() << endl; }
inline void IN(void){ return; }
template <typename First, typename... Rest> void IN(First& first, Rest&... rest){ cin >> first; IN(rest...); return; }
inline void OUT(void){ cout << "\n"; return; }
template <typename First, typename... Rest> void OUT(First first, Rest... rest){ cout << first << " "; OUT(rest...); return; }
inline void DEBUG(void){ cerr << "\n"; return; }
template <typename First, typename... Rest> void DEBUG(First first, Rest... rest){ cerr << first << " "; DEBUG(rest...); return; }

void yes(bool ok = true){ cout << (ok ? "yes" : "no") << endl; }
void Yes(bool ok = true){ cout << (ok ? "Yes" : "No") << endl; }
void YES(bool ok = true){ cout << (ok ? "YES" : "NO") << endl; }
ll myceil(ll a, ll b) { return a >= 0 ? (a+b-1)/b : -((-a)/b); }
ll myfloor(ll a, ll b) { return a >= 0 ? a/b : -myceil(-a, b); }

void Main(){
    int h, w, x, y; IN(h, w, x, y);
    x--; y--;
    vector<string> s(h);
    rep(i, h) cin >> s[i];
    int ans = 1;
    rep3(i, x, x){
        rep3(j, y+1, w-1){
            if(s[i][j] == '.') ans++;
            else break;
        }
        rep3rev(j, y-1, 0){
            if(s[i][j] == '.') ans++;
            else break;
        }
    }
    rep3(j, y, y){
        rep3(i, x+1, h-1){
            if(s[i][j] == '.') ans++;
            else break;
        }
        rep3rev(i, x-1, 0){
            if(s[i][j] == '.') ans++;
            else break;
        }
    }
    OUT(ans);
    return;
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

#include<bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define ii pair<ll,ll>
#define vi vector<ll>
#define vii vector<ii>
#define INF 1000000000
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_multiset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
 ll nni[2000005],fni[2000005],fact[2000005];
 const ll md=1e9+7;
 void ion()
{
  nni[0]=nni[1]=1;
  for(int i=2;i<2000005;i++)
  {
    nni[i]=nni[md%i]*(md-md/i)%md;
  }
}
void iof()
{
   fni[0]=fni[1]=1;
   for(int i=2;i<2000005;i++)
   {
     fni[i]=(nni[i]*fni[i-1])%md;
   }
}
void fac()
{
  fact[0]=1;
  for(int i=1;i<2000005;i++)
  {
    fact[i]=(fact[i-1]*i)%md;
  }
}
int main(){
	IOS
	ll t;
	t=1;
	ion();
  iof();
  fac();
	while(t--)
	{
      ll w,b,k;
	  cin>>w>>b>>k;
	  if(w>b+k){cout<<"0"<<"\n";return 0;}
	  ll to=(((fact[w+b]*fni[w-(k+1)])%md)*fni[b+k+1])%md;
	  ll ans=(((((fact[w+b]*fni[w])%md)*fni[b])%md)-to+md)%md;
	  cout<<ans<<"\n";

	}

return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5+5;
int readint(){
	int x=0,f=1;char s=getchar();
	#define sc (s=getchar())
	while(s<'0'||s>'9'){
		if(s=='-')
			f=-1;
		sc;
	}
	while(s>='0'&&s<='9'){
		x=(x<<3)+(x<<1)+(s^48);
		sc;
	}
	#undef sc
	return x*f;
}
struct zz{
	int u,v,w;
}s[maxn];
struct edge{
	int v,w,nxt;
	edge(){};
	edge(int V,int W,int N){
		v=V;
		w=W;
		nxt=N;
	}
}e[maxn<<1];
int head[maxn],edge_cnt=-1;
void addedge(int u,int v,int w){
	e[++edge_cnt]=edge(v,w,head[u]);
	head[u]=edge_cnt;
	e[++edge_cnt]=edge(u,w,head[v]);
	head[v]=edge_cnt;
}
int fa[maxn];
int findset(int x){
	if(fa[x]!=x)
		fa[x]=findset(fa[x]);
	return fa[x];
}
int ans[maxn];
void dfs(int u,int pre){
	for(int i=head[u];~i;i=e[i].nxt){
		int v=e[i].v;
		if(v==pre)
			continue;
		if(ans[u]==e[i].w)
			ans[v]=(e[i].w-1>0?e[i].w-1:e[i].w+1);
		else
			ans[v]=e[i].w;
		dfs(v,u);
	}
}
bool cmp(const zz &x,const zz &y){
	return x.w<y.w;
}
int main (){
	memset(head,-1,sizeof(head));
	int n=readint(),m=readint();
	for(int i=1;i<=m;i++){
		s[i].u=readint(),s[i].v=readint(),s[i].w=readint();
	}
	for(int i=1;i<=n;i++){
		fa[i]=i;
	}
	int cnt=0;
	for(int i=1;i<=m;i++){
		int u=s[i].u,v=s[i].v;
		int fu=findset(u),fv=findset(v);
		if(fu==fv)
			continue;
		addedge(u,v,s[i].w);
		fa[fu]=fv;
		cnt++;
		if(cnt==n-1)
			break;
	}
	int sum=0;
	for(int i=1;i<=n;i++){
		if(fa[i]==i)
			sum++;
	}
	if(sum!=1)
		return !printf("No");
	ans[1]=1;
	dfs(1,0);
	for(int i=1;i<=n;i++){
		printf("%d\n",ans[i]);
	}
	return 0;
}

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

int N, M;
int X[101], Y[101], Z[101];
int cnt[101];
ll memo[2 << 19];

ll dfs(int bit, int nbit){
    if(bit == (1 << N) - 1){
        return 1;
    }
    if(memo[bit] != -1) return memo[bit];
    ll ret = 0;
    for(int i=0;i<N;i++){
        if ((bit>>i)&1) continue;
        for(int j=0;j<M;j++){
            if(nbit + 1 <= X[j] && (i + 1) <= Y[j]){
                cnt[j]++;
            }
        }
        bool ok = true;
        for(int j=0;j<M;j++){
            if(cnt[j] > Z[j]){
                ok = false;
                break;
            }
        }
        if(ok){
            ret += dfs(bit | (1 << i), nbit + 1);
        }
        for(int j=0;j<M;j++){
            if(nbit + 1 <= X[j] && (i + 1) <= Y[j]){
                cnt[j]--;
            }
        }
    }
    memo[bit] = ret;
    return ret;
}

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

    for(int i=0;i<M;i++){
        cin >> X[i] >> Y[i] >> Z[i];
    }

    memset(cnt, 0, sizeof(cnt));
    memset(memo, -1, sizeof(memo));
    cout << dfs(0, 0) << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int A[105],B[105];
int main(){
    int n,a,b,ans;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>A[i];
    }
    for(int i=0;i<n;i++){
        cin>>B[i];
    }
    sort(A,A+n);
    a=A[n-1];
    sort(B,B+n);
    b=B[0];
    ans=b-a+1;
    if(ans>=0)cout<<ans;
    else cout<<0;
}

#include<bits/stdc++.h>
#define pb emplace_back
#define AI(i) begin(i), end(i)
using namespace std;
using ll = long long;
template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() {cerr << endl;}
template<class T, class ...U> void kout (T v, U ...e) { cerr << v << ' ', kout(e...); }
template<class T> void debug(T L, T R) { while (L != R) cerr << *L << " \n"[next(L)==R], ++L; }
#else
#define DE(...) 0
#define debug(...) 0
#endif
// What I should check
// 1. overflow
// 2. corner cases
// Enjoy the problem instead of hurrying to AC
// Good luck !
const int MAX_N = 300010;

const int in_t = 1, out_t = 2, no_t = 0, p = 998244353;

int vis[MAX_N], nxt[MAX_N], n;

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

	cin >> n;
	for (int i = 1;i <= n;++i)
		cin >> nxt[i];

	ll res = 1;

	for (int i = 1;i <= n;++i) {
		vector<int> stk;
		bool bad = false;
		for (int x = i;;x = nxt[x]) {
			if (vis[x] == out_t) {
				bad = true;
				break;
			}
			if (vis[x] == in_t) break;
			stk.pb(x);
			vis[x] = in_t;
		}
		if (!bad) {
			res = res * 2 % p;
		}
		for (int u : stk)
			vis[u] = out_t;
	}

	--res;
	if (res < 0) res += p;

	cout << res << '\n';
}


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

typedef long long ll;
typedef unsigned long long ull;

const int INF = INT_MAX;
const ll LINF = LLONG_MAX;
const int MOD = 1e9+7;
const int N = 1e5+7;

void test_cases(){
	int  n,m;
	cin >> n >> m;
	set<int> mp;
	mp.insert(n);
	mp.insert(m);
	if(mp.size()==1){
		cout << m;
	}else{
		if((n==1&&m==2)||(n==2&&m==1))cout << "0";
		else if((n==1&&m==0)||(n==0&&m==1))cout << "2";
		else cout << "1";
	}
}

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

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

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

	return 0;
}

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<functional>
#include<numeric>
using namespace std;

#define vi vector<int>
#define pii pair<int,int>
#define x first
#define y second
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
typedef long long ll;
const int MAXN = 2e5+5, INF = 0x3f3f3f3f, MOD = 998244353;
const ll INFL = 0x3f3f3f3f3f3f3f3f;

const int M = 30;
void run(){
    int a,b; cin>>a>>b;
    if(a==b)cout<<a<<'\n';
    else cout<<3-a-b<<'\n';
}

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

    int t=1;
    //cin>>t;
    while(t--)run();
    return 0;
}


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

int X, Y, Z;
int main() {
	scanf("%d %d %d", &X, &Y, &Z);
	for (int i = 1; i < 1e8; i++) {
		if (i * X >= Y * Z) {
			printf("%d\n", i - 1);
			return 0;
		}
	}
}

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int long long
#define fi first
#define se second
#define debug(x) cerr << #x << ": " << x << '\n'
#define yn {puts("Yes");}else{puts("No");} // if(a == b) yn;

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

constexpr int INF = 1001001001;
constexpr long long LINF = 1001001001001001001;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int x,y,z;
    cin >> x >> y >> z;
    cout << (y * z - 1) / x << endl;
}

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

    solve();

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int sz = 2e3 + 9;
const ll mod =  1e9 + 7;
const ll inf = 1e9;
const double eps = 1e-6;
void test()
{
    int n,t;scanf("%d%d", &n, &t);
    ll x[n];
    for(int i=0;i<n;i++)
        scanf("%lld", &x[i]);
    int m = n - (n / 2),temp = n;
    vector<int> a(temp),b(temp);
    n/=2;
    for(int i=0;i < n;i++)
        a[i] = x[i];
    for(int i = n,p = 0;i < temp;i++,p++)
        b[p] = x[i];
    vector<ll> s(1<<n),s2(1<<m);
    for(int i = 0;i < (1<<n);i++)
    {
        ll sum=0;
        for(int j=0;j<n;j++)
        {
            if(i & (1<<j))
                sum+=a[j];
        }
        s[i] = sum;
    }
    for(int i=0;i<(1<<m);i++)
    {
        ll sum = 0;
        for(int j=0;j<m;j++)
        {
            if(i & (1<<j))
                sum+=b[j];
        }
        s2[i] = sum;
    }
    ll ans = 0;
    sort(s2.begin(),s2.end());
    for(ll i : s)
    {
        if(i<=t)
        {
            int it = (int)(upper_bound(s2.begin(),s2.end(),t - i) - s2.begin());
            if(it)
                ans = max(ans,i + s2[it - 1]);
        }
    }
    printf("%lld", ans);
}
int main()
{
    int cases = 1;
//    cin>>cases;
    while(cases--)
        test();
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vc = vector<T>;
template<class T> using vvc = vc<vc<T>>;
template<class T> using vvvc = vc<vvc<T>>;
template<class T> using vvvvc = vvc<vvc<T>>;
template<class T> using PQ = priority_queue<T>;
template<class T> using invPQ = priority_queue<T, vector<T>, greater<T>>;
using IP = pair<int, int>;
using LP = pair<ll, ll>;
#define mp make_pair
#define pb push_back
#define all(x) begin(x), end(x)
#define rep(i, n) for (int i = 0; (i) < (int)(n); i++)
#define rep3(i, m, n) for (int i = (m); (i) < (int)(n); i++)
#define repr(i, n) for (int i = n; (i) >= 0; i--)
#define rep3r(i, m, n) for (int i = (n); (i) >= (int)(m); i--)
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; }
constexpr int INF = 1070000000;
constexpr long long LINF = 4611686015206162431;

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

    int N, M, Q;
    cin >> N >> M >> Q;
    vc<IP> bag(N);
    rep (i, N) cin >> bag[i].first >> bag[i].second;
    vc<int> X(M);
    rep (i, M) cin >> X[i];

    sort(all(bag));

    rep (l, Q) {

        int L, R;
        cin >> L >> R;
        L--; R--;

        vc<int> box;
        rep (i, M) {
            if (i == L) {
                i = R;
                continue;
            }
            box.push_back(X[i]);
        }
        sort(all(box));

        int ans = 0;

        PQ<int> vals;
        int j = 0;
        rep (i, box.size()) {

            while (j < N && bag[j].first <= box[i]) {
                vals.push(bag[j].second);
                j++;
            }

            if (!vals.empty()) {
                ans += vals.top();
                vals.pop();
            }
        }

        cout << ans << endl;
    }
}

#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
ll rand_int(ll l, ll r) //[l, r]
{
    static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
    return uniform_int_distribution<ll>(l, r)(gen);
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
const int maxn=105;
int w[maxn],v[maxn];
int x[maxn];
namespace KM{
const int maxn = 50 + 7;
const int INF = 0x3f3f3f3f;
int n; //点数
int cost[maxn][maxn];
int lx[maxn], ly[maxn], match[maxn], slack[maxn];
int pprev[maxn];
bool vy[maxn];
void augment(int root)
{
    memset(vy, 0, sizeof(vy));
    memset(slack, 0x3f, sizeof(slack));
    int py;
    match[py = 0] = root;
    do
    {
        vy[py] = true;
        int x = match[py], yy;
        int delta = INF;
        for (int y = 1; y <= n; y++)
        {
            if (!vy[y])
            {
                if (lx[x] + ly[y] - cost[x][y] < slack[y])
                    slack[y] = lx[x] + ly[y] - cost[x][y], pprev[y] = py;
                if (slack[y] < delta)
                    delta = slack[y], yy = y;
            }
        }
        for (int y = 0; y <= n; y++)
        {
            if (vy[y])
                lx[match[y]] -= delta, ly[y] += delta;
            else
                slack[y] -= delta;
        }
        py = yy;
    } while (match[py] != -1);
    do
    {
        int pre = pprev[py];
        match[py] = match[pre], py = pre;
    } while (py);
}
int KM()
{
    for (int i = 1; i <= n; i++)
    {
        lx[i] = ly[i] = 0;
        match[i] = -1;
        for (int j = 1; j <= n; j++)
            lx[i] = max(lx[i], cost[i][j]);
    }
    int ans = 0;
    for (int root = 1; root <= n; root++)
        augment(root);
    for (int i = 1; i <= n; i++)
        ans += lx[i], ans += ly[i];
    return ans;
}
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,m,q;
    cin>>n>>m>>q;
    for(int i=0;i<n;i++) cin>>w[i]>>v[i];
    for(int i=0;i<m;i++) cin>>x[i];
    while(q--)
    {
        int l,r;
        cin>>l>>r;
        l--,r--;
        KM::n=50;
        memset(KM::cost,0,sizeof(KM::cost));
        for(int i=0;i<m;i++)
        {
            if(i>=l&&i<=r) continue;
            for(int j=0;j<n;j++)
            {
                if(x[i]>=w[j])
                    KM::cost[i+1][j+1]=v[j];
            }
        }
        print(KM::KM());
    }
}


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

using namespace std;

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

int main() {
  int N,A,B;cin>>N>>A>>B;
  cout<<N-A+B<<endl;
}

#include <stdio.h>

constexpr unsigned char H[16] = {0, 1, 0, 3, 1, 1, 1, 1, 0, 1, 2, 2, 3, 1, 2, 3};

int main() {
  unsigned char n, k;
  scanf("%hhd %hhd", &n, &k);
  getchar_unlocked();
  unsigned char h[101], h2[101];
  for (unsigned char i = 0; i < n; i++) h[i] = getchar_unlocked() - 80;
  for (unsigned char i = 0; i < k; i++) {
    unsigned char *cur = (i & 1) ? h2 : h, *nxt = (i & 1) ? h : h2;
    for (unsigned char j = 0; j < n; j++) {
      nxt[j] = H[(cur[(j * 2) % n] * 4) + cur[((j * 2) + 1) % n]];
    }
  }
  putchar_unlocked(((k & 1) ? (*h2) : (*h)) + 80);
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;

#define LETS_GET_SCHWIFTY ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ff              first
#define ss              second
#define int             long long
#define ll              long long
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define vpii            vector<pair<int,int> >
#define all(x)          x.begin(),x.end()
#define matrixprint(arr,a,b,c,d) for(int i=a;i<=c;i++){for(int j=b;j<=d;j++){cout<<arr[i][j]<<" ";}cout<<"\n";}
#define show(arr,x,y)   for(int i=x;i<=y;i++){cout<<arr[i]<<" ";}cout<<"\n"
#define sz(x)           (int)x.size()
#define db(x)           cout<<x<<"\n";

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

//insert,find_by_order,order_of_key,lower_bound,upper_bound;

#define TRACE
#ifdef TRACE
#define deb(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#else
#define deb(...)
#endif

//////////////////////////////code//////////////////////////////

const int N = 200;

int power(int a, int b = mod - 2) {

  int x = 1 % mod;
  a %= mod;
  b %= mod - 1;
  while (b) {

    if (b & 1) x = (x * a)%mod;
    a = (a * a)%mod;
    b >>= 1;

  //  deb(x);
  }

  return x;

}

void solve()
{

      int n , p;
      cin >> n >> p;

      if(n == 1)
      {
            db(p - 1)
            return;
      }

      if(p == 0)
      {
          db(0)
          return;
      }

          int ans = (p - 1) % mod;
          ans *= power(p - 2,n - 1);
          ans %= mod;

          db(ans)

}

int32_t main()
{

    LETS_GET_SCHWIFTY;

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

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

    while (t--)
        solve();

}

// check out for following mistakes-
// if using pb operation on vector and then trying to access index..check if sizeof that vec could remain 0 only
// is using prime sieve make sure it fits
// when using factorial template or combinatorics make sure that you edit fillfac fun values and array values

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

const int mod = 1e9 + 7;
long long Pow(long long a, long long b) {
	long long res = 1;
	while (b) {
		if (b & 1) {
			res = res * a % mod;
		}
		a = a * a % mod;
		b >>= 1;
	}
	return res;
}
int main() {
	int n, p;
	cin >> n >> p;
	long long res = 1;
	res = 1ll * (p - 1) * Pow(p - 2, n - 1) % mod;
	cout << res << "\n";
}


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

int main(){
  vector<int> v(4);
  for(int i=0;i<4;i++)
    cin >> v[i];

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

  if(v[0]+v[3]==v[1]+v[2])
    cout << "Yes" << endl;

  else if(v[0]+v[1]+v[2]==v[3])
    cout << "Yes" << endl;

  else
    cout << "No" << endl;
}

#include <bits/stdc++.h>
using namespace std;
int main() {
  int A,B,N;
  cin >> N >> A >> B;

  cout << N - A + B << endl;

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define F            first
#define S            second
#define pb(x)        push_back(x)
#define mp(a,b)      make_pair(a,b)
#define mt(a,b,c)    make_tuple(a,b,c)
#define sz           size()
#define all(A)       A.begin(), A.end()
#define mem(a, b)    memset(a, b, sizeof(a))   // all elements of A are b=0 or b=-1 else don't work
#define f0(i,b)      for(ll i=0;i<(b);i++)
#define f1(i,b)      for(ll i=1;i<=(b);i++)
#define f2(i,a,b)    for(ll i=(a);i<=(b);i++)
#define f3(i,b,a)    for(ll i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(ll i=(a);i!=(b);i+=(c))

#define MOD          1000000007 //10^9 + 7
#define PI           acos(-1.0)
#define MAX3(a,b,c)  max(a,max(b,c))
#define MIN3(a,b,c)  min(a,min(b,c))

/*------------------------Bitmask-------------------------------*/
#define bitOn(N,pos)      (N | (1LL<<(pos)))
#define bitOff(N,pos)     (N & (~(1LL<<(pos))))
#define bitCheck(N,pos)   ((bool)(N & (1LL<<(pos)))) //check whether the (pos)th bit is On or Off in N(number)
#define bitFlip(a,k)      (a^(1LL<<(k)))

#define whilee(i,t)  while(i!=t)
#define  sl(a)       scanf("%lld",&a)
#define  pl(a)       printf("%lld\n",a)

//x = 1e18 means 10^18
//for(auto it =A.begin(); it!=A.end(); it++)
//sort(A.begin(),A.end()); //sort(A, +n, greater<int>());
//binary_search(A.begin(),A.end(),x);
//reverse(A.begin(), A.end());
//cout << *max_element(A.begin(), A.end()); //will have index if A.begin() is minus from it
//cout << *min_element(A.begin(), A.end());
//count(A.begin(), A.end(), X); //counts the occurrences of X
//distance(A.begin(),A.end());  //distance between first to last element
//accumulate(A.begin(), A.end(), 0); //add
//next_permutation(A.begin(), A.end());
//prev_permutation(A.begin(), A.end());
//swap(S[0], T[0]);

//scanf("%lld",&x);
//printf("%lld\n",x);
//printf("%I64d\n", a);
//while (scanf("%lld %lld", &a, &b) == 2)
//printf("Case %lld: %lld\n", t++, a);

/*----------------------- Graph Moves---------------------------*/
// int dx[] = {1,-1,0,0} , dy[] = {0,0,1,-1};  // 4 Direction
// int dx[] = {0,0,1,-1,-1,1,-1,1} , dy[] = {-1,1,0,0,1,1,-1,-1};  // 8 Direction // Kings Move
// int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1};  // Knight Direction
// int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1};  // Hexagonal Direction

//vector <ll> A;
//deque <ll> A;
//queue <ll> A;
//stack <ll> A;
//list <int> A;
//set <ll> A;
//map <ll,ll> A;
//unordered_map <ll, ll> A;
//pair <ll,ll> A ;
//tuple <ll, ll, ll> A;
//vector <pair <ll,ll>> A;
//bitset<32> bset1;
//bool ok = true;
//char ch;
//string S, T, U;

bool decToOctal(int n)
{

    // array to store octal number
    int octalNum[100];

    // counter for octal number array
    int i = 0;
    while (n != 0)
    {

        // storing remainder in octal array
        octalNum[i] = n % 8;
        if(octalNum[i]==7)
        {
            return true;
        }
        n = n / 8;
        i++;
    }
    return false;
}

ll i=0, j=0, k=0, a, b, c, d, e, f, g, h, l, m, n, o, p, q, r, s, t=1, u, v, w, x, y, z, maxx=INT_MIN, minn=INT_MAX, ans=0, sum=0, flag=0, cnt=0;

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

    //cin>>t; while(t--){ }
    cin>>n;
    j=7;
    for(i=7; i<=n; i++)
    {
        if(decToOctal(i))
        {
            cnt++;
        }
        else
        {
            x=i;
            while(x>0)
            {
                if(x%10==7)
                {
                    cnt++;
                    break;
                }
                x/=10;
            }
        }
    }

    cout<<n-cnt<<endl;
    return 0;
}

#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
const int INF = 0x3f3f3f3f;

#define FOR(i, b, e) for(int i = (b); i < (e); i++)
#define TRAV(x, a) for(auto &x: (a))
#define SZ(x) ((int)(x).size())
#define PB push_back
#define PR pair
#define X first
#define Y second

bool digs(int x, int base){
	while(x){
		if(x%base == 7) return 0;
		x /= base;
	}
	return 1;
}

void solve(){
	int n, ans = 0;
	cin >> n;
	FOR(i, 1, n+1) ans += digs(i, 10) & digs(i, 8);
	cout << ans << '\n';
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	// int tt; cin >> tt;
	// FOR(te, 0, tt){
	// 	// cout << "Case #" << te+1 << ": ";
	// 	solve();
	// }
	solve();
	return 0;
}


#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const int mod = 1000000007;
//const int mod = 998244353;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    rep(i, 0, n) cin >> a[i];
    rep(i, 0, n) cin >> b[i];
    vector<bool> c(10005, true);
    rep(i, 0, n){
        rep(j, 0, a[i]) c[j] = false;
        rep(j, b[i] + 1, 10005) c[j] = false;
    }
    int ans = 0;
    rep(i, 0, 10005) if(c[i]) ans++;
    cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define ll long long int
#define llu unsigned long long int
#define ld long double
#define mod 998244353
#define big 1e18 + 10000000
#define small -big
#define pb push_back
#define endl "\n"

template <typename T>

void prarr(T a)
{
     cerr << "[ ";

     for(auto i : a){
         cerr << i << " ";
     }

     cerr << "]" << endl;
}

#define trace(...) _er(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>

void _er(const char* name, Arg1&& arg1){
	cerr << "[" << name << " : " << arg1 << "]" << endl;
}

template <typename Arg1, typename... Args>

void _er(const char* names, Arg1&& arg1, Args&&... args){

	const char* comma = strchr(names + 1, ',');
	cerr << "[" ; cerr.write(names, comma - names) << " : " << arg1 << "] ";
	_er(comma+2, args...);
}

ll n;
vector<ll> A[102];
ll cou[102] = {0};
bool visited[102];

void dfs(ll v) {
        if(visited[v]) {
                return;
        }

        visited[v] = true;

        for(auto it : A[v]) {
                if(!visited[it]) {
                        dfs(it);
                }
        }

}

void solve() {

                cin >> n;

                for(ll i = 1;  i <= n; i++) {
                        string s;
                        cin >> s;
                        for(ll j = 0; j < n; j++) {
                                if(s[j] - 48) {
                                    A[i].pb(j + 1);
                                }
                        }
                }

                for(ll i = 1; i <= n; i++) {
                        memset(visited, false, sizeof(visited));

                        dfs(i);

                        for(ll j = 1; j <= n; j++) {
                                if(visited[j]) {
                                        cou[j]++;
                                }
                        }
                }

                ld ans = 0.0;

                for(ll i = 1; i <= n; i++) {
                        ld curr = cou[i];
                        ans += (1.0 / curr * 1.0);
                }

                cout << fixed << setprecision(11) << ans << endl;

}

int main() {

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

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

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

        return 0;

}


#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using namespace std;
using ll = long long;
struct Edge
{
    ll to;
    ll cost;
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, ll>;
#define mp make_pair
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), v.end()
ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = LLONG_MAX;
const int MAX = 510000;
bool graph[nmax][nmax];
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;

    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

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

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

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}
ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

void solve(long long A, long long B, long long C)
{
    if (A % 10 == 0)
    {
        cout << 0 << endl;
        return;
    }
    else if (A % 10 == 1)
    {
        cout << 1 << endl;
        return;
    }
    else if (A % 10 == 2)
    {
        ll ans[4] = {6, 2, 4, 8};
        MOD = 4;

        ll ind = powMod(B, C);
        cout << ans[ind] << endl;
    }
    else if (A % 10 == 3)
    {
        ll ans[4] = {1, 3, 9, 7};
        MOD = 4;

        ll ind = powMod(B, C);
        cout << ans[ind] << endl;
    }
    else if (A % 10 == 4)
    {
        ll ans[2] = {6, 4};
        // 4,6,4,6,4,6....
        MOD = 2;

        ll ind = powMod(B, C);
        cout << ans[ind] << endl;
    }
    else if (A % 10 == 5)
    {
        cout << 5 << endl;
        return;
    }
    else if (A % 10 == 6)
    {
        cout << 6 << endl;
        return;
    }
    else if (A % 10 == 7)
    {
        ll ans[4] = {1, 7, 9, 3};
        MOD = 4;

        ll ind = powMod(B, C);
        cout << ans[ind] << endl;
    }
    else if (A % 10 == 8)
    {
        ll ans[4] = {6, 8, 4, 2};
        MOD = 4;

        ll ind = powMod(B, C);
        cout << ans[ind] << endl;
        // 8,4,2,6,8....
    }
    else if (A % 10 == 9)
    {
        ll ans[2] = {1, 9};
        MOD = 2;

        ll ind = powMod(B, C);
        cout << ans[ind] << endl;
        // 9,1,9,1...
    }
}

int main()
{

    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    long long C;
    scanf("%lld", &C);
    solve(A, B, C);
    return 0;
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MOD 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
	ll a, b, c;
    cin >> a >> b >> c;

    a %= 10;
    b %= 4;

    ll x;
    if(b==0) x=4;
    else if(b==1) x=1;
    else if(b==2){
        if(c>1) x=4;
        else x=2;
    }else{
        if(c%2==0) x=1;
        else x=3;
    }

    ll ans=powl(a, x);
    cout << ans%10 << endl;

	return 0;
}


#include <bits/stdc++.h>

using ll =long long;
using namespace std;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll 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 { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    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 { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main(){

    int N;
    cin>>N;

    set<ll> st;

    ll a;

    for(int i=0;i<N;i++){
        cin>>a;
        st.insert(a);

    }

    mint pre(0);
    mint ans(1);
    for(auto s:st){
        ans=ans*(mint(s)-pre+1);
        pre=s;

    }

    cout<<ans<<endl;
}

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

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

  vector<ll> A(N);
  for (ll i = 0; i < N; i++){
    cin >> A[i];
  }
  sort(A.begin(), A.end());

  ll ans = 0, prevsum = 0;
  for (ll i = N - 2; i >= 0; i--){
    prevsum += A[N - 1] - A[i];
  }
  ans = prevsum;

  for (ll i = N - 2; i >= 0; i--){
    prevsum = prevsum - (i + 1) * (A[i + 1] - A[i]);
    ans += prevsum;
  }

  cout << ans << endl;
}


#include<bits/stdc++.h>

using namespace std;

#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define pb push_back
#define input(a,n) for(ll i=0;i<n;i++){ll y;cin>>y;a.pb(y);}
#define print(x) for(auto it:x)cout<<it<<" ";cout<<"\n";
#define all(x) (x).begin(),(x).end()
#define clr(x) memset(x,0,sizeof(x))
#define fn(a,n) for(ll i = a; i < n; ++i)
#define f(n) for(ll i = 0; i < n; i++)
#define endl '\n'
#define test ll t;cin>>t;while(t--)
#define INF 1000000000
#define MAX 100001
#define pyes cout<<"YES"<<endl;
#define pno cout<<"NO"<<endl;
#define sz(x) (x).size()

const ll mod=1000000007;

int main()
{
    io;
    //test
    {
        int a,b;
        cin>>a>>b;
        int x,y;
        x=(a+b)/2;
        y=(a-b)/2;
        cout<<x<<" "<<y<<endl;
    }
    return 0;
}

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v){
    if(v.empty()){
        os<<"{ }";
        return os;
    }
    os<<"{"<<v.front();
    for(auto itr=++v.begin();itr!=v.end();itr++){
        os<<", "<<*itr;
    }
    os<<"}";
    return os;
}

template<typename T_first,typename T_second>
ostream& operator<<(ostream& os,const pair<T_first,T_second>& P){
    os<<"("<<P.first;
    os<<", "<<P.second;
    os<<")";
    return os;
}

int main(){
    int a,b; cin>>a>>b;
    cout<<(a+b)/2<<" "<<(a-b)/2<<endl;
}


#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  constexpr int T = 200000;
  int n, w; cin >> n >> w;
  vector<ll> water(T + 1, 0);
  while (n--) {
    int s, t, p; cin >> s >> t >> p;
    water[s] += p;
    water[t] -= p;
  }
  REP(i, T) water[i + 1] += water[i];
  cout << (*max_element(ALL(water)) <= w ? "Yes\n" : "No\n");
  return 0;
}

#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reps(i,a,b) for(int i= a; i < b; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

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

  int find(int x) {
    if(d.at(x) < 0) return x;
    return d.at(x) = find(d.at(x));
  }

  bool unite(int a, int b) {
    a = find(a); b = find(b);
    if (a == b) return false;
    if (d.at(a) > d.at(b)) swap(a, b);
    d.at(a) += d.at(b); d.at(b) = a;
    return true;
  }

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

  int size(int x) {
    return -d.at(find(x));
  }
};

int main()
{
  int n, m;
  cin >> n >> m;
  vector<ll> a(n), b(n);
  UnionFind uf(n);
  rep(i, n) cin >> a.at(i);
  rep(i, n) cin >> b.at(i);
  rep(i, m) {
    int x, y;
    cin >> x >> y;
    --x; --y;
    uf.unite(x, y);
  }
  map<ll, ll> am, bm;
  rep(i, n) {
    am[uf.find(i)] += a.at(i);
    bm[uf.find(i)] += b.at(i);
  }
  for (auto it = am.begin(); it != am.end(); it++) {
    if (it->second != bm[it->first]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ull=unsigned long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=((ll)n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=((ll)a);i<((ll)n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S,class T>auto&operator<<(ostream&os,map<S,T>mp){bool a=1;for(auto p:mp){os<<(a?"":", ")<<p;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/
map<int,int> zip;
int unzip[500000];

int compress(vector<int> &x) {
    sort(x.begin(), x.end());
    x.erase(unique(x.begin(),x.end()),x.end());
    for(int i = 0; i < x.size(); i++){
        zip[x[i]] = i;
        unzip[i] = x[i];
    }
    return x.size();
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,c;
    cin>>n>>c;
    vl a(n),b(n),v(n);
    vi tmp;
    rep(i,n){
        cin>>a[i]>>b[i]>>v[i];
        tmp.push_back(a[i]);
        tmp.push_back(b[i]+1);
    }
    compress(tmp);

    vl imos(n*2+1, 0);
    rep(i,n){
        imos[zip[a[i]]]+=v[i];
        imos[zip[b[i]+1]]-=v[i];
    }
    partial_sum(all(imos), imos.begin());

    ll ans=0;
    rep(i,n*2+1){
        ll d=unzip[i+1]-unzip[i];
        if(d<=0)continue;
        ans+=min(c, imos[i]) * d;;
    }
    puta(ans);
    return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef	long long ll;
typedef long double ld;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef set<int> si;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef vector<pii> vii;
typedef vector<pll> vll;
#define fi first
#define se second
#define pi 3.141592653589793
#define mod 998244353
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define pqmax priority_queue<int>
#define pqmin priority_queue<int,vi,greater<int>>
#define fio ios_base::sync_with_stdio(0), cin.tie(NULL)
#define tc int tt;cin>>tt;for(int ti=1;ti<=tt;ti++)
#define case_g "Case #"<<ti<<": "
#define RED "\033[31m"
#define GREEN "\033[32m"
#define RESET "\033[0m"
#define sleep for (int i = 1, a;i < 100000000;i++, a = a * a)
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> ranked_pairset;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ranked_set;
typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ranked_map;

int main() {
	fio;
	ll n, p;
	cin >> n >> p;
	mll m;
	for (int i = 0;i < n;i++) {
		int a, b, c;
		cin >> a >> b >> c;
		m[a] += c;
		m[b + 1] -= c;
	}
	ll cur = 0, ans = 0;
	for (auto itr = m.begin();next(itr) != m.end();itr++) {
		ll d = next(itr)->fi - itr->fi;
		cur += itr->se;
		ll c = min(cur, p);
		ans += d * c;
	}
	cout << ans << '\n';
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int M=1005;
inline int read(){
	char c=getchar();int x=0,f=1;
	for(;c<'0'||c>'9';c=getchar())if(c=='-')f=0;
	for(;c<='9'&&c>='0';c=getchar())x=(x<<1)+(x<<3)+(c^48);
	return f?x:-x;
}
struct node{
	char s[20];int x;
	bool operator <(const node &t)const{
		return x>t.x;
	}
}a[M];
int main(){
	int n=read();
	for(int i=1;i<=n;i++){
		scanf("%s",a[i].s);a[i].x=read();
	}
	sort(a+1,a+1+n);
	printf("%s",a[2].s);
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  for(int i=0;i<n;i++)
    cout<<(2*i)%n+1<<' '<<(2*i+1)%n+1<<'\n';
  return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <iomanip>
#include <functional>
using namespace std;
typedef long long ll;
int n,m;
string s[100010];
int k[100010];
int main(){
    cin >> n >> m;
    for(int i=0;i<n;i++)cin >> s[i];
    ll a=0,b=0;
    for(int i=0;i<n;i++){
        int cnt=0;
        for(int j=0;j<m;j++){
            if(s[i][j]!=s[0][j]){
                cnt++;
            }
        }
        if(cnt%2==0)a++;
        else b++;
    }
    cout << a*b << endl;
    return 0;
}

#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define st first
#define nd second
#define pii pair<int,int>
#define mp make_pair
#define pll pair<long long,long long>

using namespace std;

ll xd[2];

void solve(){
    int n,m; cin>>n>>m;
    while(n--){
        string s; cin>>s;
        int x = 0;
        for(char y : s){
            if(y == '1') x++;
        }
        xd[x % 2]++;
    }
    cout<<xd[0] * xd[1];
}

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


//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
#include <bits/stdc++.h>
#include<set>
#include <array>
using namespace std;
#define ll long long
#define endl '\n'
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define con continue
#define ub upper_bound
#define lb lower_bound

#define si(x) int(x.size())
#define sum_all(a)     ( accumulate ((a).begin(), (a).end(), 0ll))
#define mine(a)    (*min_element((a).begin(), (a).end()))
#define maxe(a)    (*max_element((a).begin(), (a).end()))
#define mini(a)    ( min_element((a).begin(), (a).end()) - (a).begin())
#define maxi(a)    ( max_element((a).begin(), (a).end()) - (a).begin())
#define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())
const double pi = 2 * acos(0.0);
const int dx[] = { -1, 0, 1, 0 };
const int dy[] = { 0, -1, 0, 1 };

const int dx8[] = { -1, 0, 1, 0,1,1,-1,-1 };
const int dy8[] = { 0, -1, 0, 1,1,-1,1,-1 };

ll min(ll a,ll b)
{
    if(a<b)return a;
    return b;
}
ll max(ll a,ll b)
{
    if(a>b)return a;
    return b;
}
ll ceil1(ll a,ll b)
{
    return(a+b-1)/b;
}
void read(vector<ll> & arr)
{
  for(ll i=0;i<si(arr);i++)
    cin >> arr[i];

}

void read_graph(vector<vector<ll>>& g, ll m)
{
  while(m--)
  {
    ll x,y; cin >> x>> y ;
    x--,y--;
    g[x].pb(y);
    g[y].pb(x);
  }
}
void solve()
{

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

  vector<vector<pair<char,int>>> g(n);
  for(int i=0;i<m;i++)
  {
     int x,y;
     char ch;
     cin >> x >> y >> ch ;
     x--,y--;
     g[x].push_back({ch,y});
     g[y].push_back({ch,x});

  }
   using node= pair<int,pair<int,int>>;
   vector<vector<bool>> vis(n,vector<bool>(n));

   queue<node> q ;
   q.push({0,{0,n-1}});
   int ans=INT_MAX;
   while(!q.empty())
   {
     auto a1=q.front();
     q.pop();

     auto a=a1.ss.ff,b=a1.ss.ss;
     auto dis= a1.ff;
     if(a==b)
     {
        ans=min(ans,dis*2);
        continue;
     }
     if(vis[a][b]) continue;
      vis[a][b]=true;
      vis[b][a]=true;
      bool f=false;
     for(auto info :g[a])
     {
         auto v=info.ss;
         if(v==b)
         {
           f=true;
           break;
         }
     }
  if(f)
  {
     ans=min(ans,dis*2+1);
     continue;
  }
     for(auto info :g[a])
        for(auto info2 : g[b])
        {
            if(info.ff!=info2.ff) continue;
            if(vis[info.ss][info2.ss]) continue;
            q.push({dis+1,{info.ss,info2.ss}});
        }

   }
  if(ans==INT_MAX) ans=-1;
  cout << ans << endl;
  return ;
}

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

}

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

ll n, p[2 * 101 * 1001], db[20][2 * 101 * 1001], iv[2 * 101 * 1001], dep[2 * 101 * 1001], Q;
vector<ll> v, ans;

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

    cin >> n;
    zep(i, 1, n){cin >> p[i]; p[i]--;}

    vector<vector<ll>> g(n);
    zep(i, 1, n)g[p[i]].push_back(i);
    //zep(i, 0, n){zep(j, 0, g[i].size())cout << g[i][j] << " "; cout << endl;}
    queue<ll> q;
    iv[0] = v.size();
    q.push(0);
    v.push_back(0);

    while(!q.empty()){
        ll at = q.front(); q.pop();

        db[0][iv[at]] = v.size();
        zep(i, 0, g[at].size()){
            iv[g[at][i]] = v.size();
            v.push_back(g[at][i]);
            q.push(g[at][i]);
            dep[g[at][i]] = dep[at] + 1;
        }
    }
    db[0][n] = v.size();

    zep(j, 1, 20){
        rep(i, 0, n){
            db[j][i] = db[j - 1][db[j - 1][i]];
        }
    }

    cin >> Q;
    while(Q--){
        ll u, d; cin >> u >> d; u--;
        d -= dep[u];

        if(d < 0){
            ans.push_back(0); continue;
        }

        ll l = iv[u], r = iv[u] + 1;
        rrep(j, 19, 0){
            if(d & (1LL << j)){
                l = db[j][l];
                r = db[j][r];
            }
        }
        ans.push_back(r - l);
    }

    zep(i, 0, ans.size())print(ans[i])

    return 0;
}


#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

#define mkp make_pair
#define mkt make_tuple
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
template <class T> void chmin(T &a, const T &b) {
    if (a > b) a = b;
}
template <class T> void chmax(T &a, const T &b) {
    if (a < b) a = b;
}

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

    int N;
    ll K;
    cin >> N >> K;
    vector<ll> A(N + 1, 0), B(N + 1, 0);
    rep(i, N) cin >> A[i + 1] >> B[i + 1];

    A[0] = 0;
    B[0] = K;

    vector<int> ord(N + 1);
    rep(i, N + 1) ord[i] = i;
    sort(all(ord), [&](int a, int b) {
        if (A[a] == A[b])
            return a < b;
        else
            return A[a] < A[b];
    });

    ll money = 0;
    int now = 0;
    while (now <= N) {
        int nex = now;
        while (nex <= N && A[ord[now]] == A[ord[nex]]) {
            money += B[ord[nex]];
            nex++;
        }

        if (nex > N) {
            cout << A[ord[N]] + money << endl;
            return 0;
        }

        if (money >= A[ord[nex]] - A[ord[now]]) {
            money -= A[ord[nex]] - A[ord[now]];
        } else {
            cout << A[ord[now]] + money << endl;
            return 0;
        }
        now = nex;
    }

    return 0;
}

//Classic
// //g++ -std=c++17 -O2 -Wall a.cpp -o test
// _()_
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define vll vector<ll>
#define vi vector<int>
#define vb vector<bool>
#define pi pair<int,int>
#define pll pair<ll,ll>
#define vp vector<pi>
#define vpll vector<pll>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define For(i,a,b) for(ll i=a;i<b;i++)
//#define endl "\n"
#define debug2(x,y) cout<<"This side ----> "<<#x<<" -> "<<x<<" | "<<#y<<" -> "<<y<<endl;
#define debug(x) cout<<"This side    ----> "<<#x<<" -> "<<x<<endl
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define mint map<int,int>
#define mall map<ll,ll>
#define ciN cin
#define gu(a,s) get<a>(s)
#define tin tuple<ll,ll,ll>
#define ter(x,y,z) ((x)?y:z)
#define ul ll
/////////////

const ll maxn = 2e5 + 5;
const ll max_val = 2e5 + 10;
ll mod = 1e9 + 7;
const ll bits = 20;
ll caseNumber = 1;
////////////////////////////////////////////////////////////////

void jabru() {
	ll n, k; cin >> n >> k;
	vpll v(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i].F >> v[i].S;
	}
	ll curr = 0;
	sort(all(v));
	for (int i = 0; i < n; i++) {
		ll req = v[i].F - curr;
		if (k < req) {
			break;
		}
		else {
			k -= req;
			k += v[i].S;
			curr += req;
		}
	}
	curr += k;
	cout << curr << endl;
}

bool TestCase = 0;
bool isGoogles = 0;

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

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

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

	ll t;
	t = 1;
	if (TestCase) {
		cin >> t;
	}
	while (t--) {
		if (isGoogles) {cout << "Case #" << caseNumber << ": ";} caseNumber++;
		jabru();

	}
	return 0;
}


#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif

#include <algorithm>
#include <cmath>
#include <cstring>
#include <cctype>
#include <iostream>
#include <sstream>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <vector>

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> II;
typedef pair<LL, II> III;
typedef priority_queue<III, vector<III>, greater<>> Queue;
static const LL INF = 1LL << 60;

LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }
LL lcm(LL a, LL b) { return (a / gcd(a, b)) * b; }

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

void dfs(int y, int x) {
	for (int dir = 0; dir < 4; ++dir) {
		int ny = y + dy[dir], nx = x + dx[dir];
		if (ny >= 0 && ny < H && nx >= 0 && nx < W && !vis[ny][nx] && B[ny][nx] != '#') {
			vis[ny][nx] = 1;
			dfs(ny, nx);
		}
	}
}

LL binary_search(vector<LL> a, LL x) {

	vector<int> vi(N);
	iota(vi.begin(), vi.end(), 0);
	sort(vi.begin(), vi.end(), [&](int lhs, int rhs) {
		return make_pair(x[lhs], y[lhs]) < make_pair(x[rhs], y[rhs]);
	});

	auto possible = [&](LL t) {

		return t <= x;

	};
	LL left = -1, right = a.size();
	while (right - left > 1) {
		LL mid = (left + right) / 2;
		if (possible(a[mid])) {
			left = mid;
		} else {
			right = mid;
		}
	}
	return left;
}
#endif

void solve(long long N, std::vector<long long> &x) {
	LL ans = 0;
	for (int i = 0; i < N; i++) {
		ans += abs(x[i]);
	}
	cout << ans << endl;
	LD sum = 0;
	for (int i = 0; i < N; i++) {
		sum += x[i] * x[i];
	}
	cout << sqrt(sum) << endl;
	ans = 0;
	for (int i = 0; i < N; i++) {
		ans = max(ans, abs(x[i]));
	}
	cout << ans << endl;
}

int main() {
	cout.precision(20);
    long long N;
	std::cin >> N;
	std::vector<long long> x(N);
	for (int i = 0; i < N; i++) {
		std::cin >> x[i]; // x[i]--;
	}
	solve(N, x);
	return 0;
}

/* @author: saran
 * Git: https://github.com/abhisheksaran
 * LinkedIn: https://www.linkedin.com/in/abhishek-saran-2900b/
 */

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

typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<LL> vl;
typedef vector<vl> vvl;

double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };
int diry[8] = { 0, 1, -1, 0, -1, 1, -1, 1 };

#ifdef TESTING
#define DEBUG fprintf(stderr, "====TESTING====\n")
#define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define DEBUG
#define VALUE(x)
#define debug(...)
#endif

#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a))
#define FORN(a, b, c) for (int(a) = (b); (a) <= (c); ++(a))
#define FORD(a, b, c) for (int(a) = (b); (a) >= (c); --(a))
#define FORSQ(a, b, c) for (int(a) = (b); (a) * (a) <= (c); ++(a))
#define FORC(a, b, c) for (char(a) = (b); (a) <= (c); ++(a))
#define FOREACH(a, b) for (auto&(a) : (b))
#define REP(i, n) FOR(i, 0, n)
#define REPN(i, n) FORN(i, 1, n)
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define SQR(x) ((LL)(x) * (x))
#define RESET(a, b) memset(a, b, sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define ALLA(arr, sz) arr, arr + sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define PERMUTE next_permutation
#define TC(t) while (t--)

inline string IntToString(LL a)
{
    char x[100];
    sprintf(x, "%lld", a);
    string s = x;
    return s;
}

inline LL StringToInt(string a)
{
    char x[100];
    LL res;
    strcpy(x, a.c_str());
    sscanf(x, "%lld", &res);
    return res;
}

inline string GetString(void)
{
    char x[1000005];
    scanf("%s", x);
    string s = x;
    return s;
}

inline string uppercase(string s)
{
    int n = SIZE(s);
    REP(i, n)
    if (s[i] >= 'a' && s[i] <= 'z')
        s[i] = s[i] - 'a' + 'A';
    return s;
}

inline string lowercase(string s)
{
    int n = SIZE(s);
    REP(i, n)
    if (s[i] >= 'A' && s[i] <= 'Z')
        s[i] = s[i] - 'A' + 'a';
    return s;
}

inline void OPEN(string s)
{
#ifndef TESTING
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
#endif
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin>>s;
  REVERSE(s);
  int n = s.size();
  int i;
  REP(i,n){
    if(s[i] == '6') s[i] = '9';
    else if(s[i] == '9') s[i] = '6';
  }
  cout<<s<<endl;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <iomanip>
#include <cmath>
#include <set>
#include <unordered_set>
#include <functional>
#include <map>
#include <unordered_map>
#include <string>
#include <tuple>
using namespace std;
using ll = long long;
const int MOD=1e9+7;
const int MAX=100009;
ll fac[100009],finv[100009],inv[100009];

#define pi 3.14159265358979323846
#define ee 2.71828182845904523536
#define INF 1e18+1

ll gcd(ll x, ll y) { // 最大公約数
    if (y == 0)return x;
    else return gcd(y, x % y);
}

bool prime(ll x) { //素数判定
    if(x==1)return false;
    if (x!=2&&x % 2 == 0)return false;
    for (ll i = 3; i <= sqrt(x); i+=2) {
        if (x % i == 0)return false;
    }
    return true;
}

ll modinv(ll a, ll 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;
}

ll modpow(ll a, ll n, ll mod) { //二分累乗法
    ll res = 1;
    while (n) {
        if (n % 2)res = res * a % mod;
        a = a * a % mod;
        n /= 2;
    }
    return res;
}

void COMinit() { //二項係数計算の前処理
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM(int n, int k){ //二項係数計算
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

struct UnionFind {   // UnionFind
    vector<int> par;
    vector<int> siz;

    UnionFind(int N) : par(N), siz(N, 1) {
        for (int i = 0; i < N; i++) par[i] = i;
    }

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

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        if (par[rx] > par[ry])swap(rx, ry);
        siz[rx] += siz[ry];
        par[ry] = rx;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
    int size(int x) {
        return siz[root(x)];
    }
};

int main() {
    int n,p;
    cin>>n>>p;
    ll ans=p-1;
    cout<<ans*modpow(p-2,n-1,MOD)%MOD<<endl;
}

#pragma region Region_1

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
using ll = long long;
using P = pair<ll, ll>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VP = vector<P>;
using VS = vector<string>;
using VC = vector<char>;
using VVC = vector<vector<char>>;
#define MOD 1000000007
const int INF = (int)1e9 + 10; // int max > 2*10^9
const long long INFL = (ll)2e18 + 10; // ll max > 9*10^18

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

template <class T> T sum(const vector<T>& v) {
    T res = 0;
    for (size_t i = 0; i < v.size(); ++i) res += v[i];
    return res;
}

/////////////////////////////////////////////////////////
// print like python
// https://qiita.com/Lily0727K/items/06cb1d6da8a436369eed
/////////////////////////////////////////////////////////
void print() { cout << endl; }

template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << " ";
    print(forward<Tail>(tail)...);
}

template <class T> void print(vector<T>& vec) {
    for (auto& a : vec) {
        cout << a;
        if (&a != &vec.back()) cout << " ";
    }
    cout << endl;
}

template <class T> void print(vector<vector<T>>& df) {
    for (auto& vec : df) {
        print(vec);
    }
}

#pragma endregion Region_1
/////////////////////////////////////////////////////////
struct mint {
    ll x;  // typedef long long ll;
    int mod;
    mint(ll x = 0, int mod = MOD) : x((x % mod + mod) % 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;
    }
    // x^t
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;// 桁ずらし
        if (t & 1) a *= *this;
        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;
    }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

int main() {
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    std::cout << std::setprecision(15);
    //////////////////////////////////////////
    ll n ,p;
    cin >> n >> p;

    mint x = p-2;
    x = x.pow(n-1) * (p-1);
    print(x.x);

    return 0;
}


#include <bits/stdc++.h>

#define int long long
#define ll long long
#define ld long double

#define mod 1000000007
#define mod2 998244353
#define ff first
#define ss second
#define pb push_back
#define endl "\n"

#define vi vector<int>
#define si set<int>
#define pii pair<int,int>
#define mii map<int,int>
#define umii unordered_map<int,int>
#define vii vector<pii>
#define sii set<pii>
#define vvi vector<vi>
#define vvii vector<vii>
#define vsi vector<si>

#define in(arr,n) for(int i=0;i<n;i++)cin>>arr[i];
#define out(arr,n) for(int i=0;i<n;i++)cout<<arr[i]<<" ";cout<<endl;
#define inn(arr,m,n) for(int i=m;i<n;i++)cin>>arr[i];
#define outt(arr,m,n) for(int i=m;i<n;i++)cout<<arr[i]<<" ";cout<<endl;

#define narr int arr[n];in(arr,n)
#define nbrr int brr[n];in(brr,n)
#define intt(n,m) int n,m;cin>>n>>m;

using namespace std;
void solve1();

int power(int x, int y, int p){
    //if(x==0&&y==0)return 1;
    int res = 1;x = x % p;if (x == 0) return 0;
    while (y > 0){if (y & 1)res = (res*x) % p;y = y>>1;x = (x*x) % p;}
    return res;
}
int power(int x, int y){
    //if(x==0&&y==0)return 1;
    int res = 1;if (x == 0) return 0;
    while (y > 0){if (y & 1)res = (res*x);y = y>>1;x = (x*x);}
    return res;
}
int fib(int s1) {
    int s2, s4, s5, s3;
    s2 = s3 = 1;
    s4 = s5 = 0;
    while (s1 > 0) {
        if (s1 % 2 == 0) {
            int s6 = s3*s3;
            s3 = 2*s5*s3 + s6;
            s5 = s5*s5 + s6;
            s1 /= 2;
        } else {
            int s6 = s2*s3;
            s2 = s4*s3 + s6 + s2*s5;
            s4 = s4*s5 + s6;
            s1 -= 1;
        }
    }
    return s4;
}
int sum(int arr[],int a,int n)
{
    int zz=0;
    for(int i=a;i<n;i++)
    {
        zz+=arr[i];
    }
    return zz;
}
void solve(){
    int t;cin>>t;
    while(t--){solve1();}
}
signed main()
{
    //std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    solve1();
    return 0;
}

void solve1()
{
    int n,m,a,b;cin>>n>>m;
    if(n==1&&m==0)
    {
        cout<<1<< " "<<3<<endl;return;
    }
    if(((m<0)||(m>=n-1)))
    {
        cout<<-1<<endl;return;
    }
    int arr[n][2];
    arr[0][0]=2;arr[0][1]=4;
    for(int i=1;i<n;i++)
    {
        arr[i][0]=arr[i-1][0]+4;
        arr[i][1]=arr[i-1][1]+4;
    }
    if(m>0)
    {
        arr[0][1]+=(m)*4+3;
    }
    else if(m<0)
    {
        arr[n-1][0]-=3+(abs(m))*4;
    }
    for(int i=0;i<n;i++)
    {
        cout<<arr[i][0]<<" "<<arr[i][1]<<endl;
    }
}

#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

int N, M;

signed main(){
	cin >> N >> M;
	if(N == 1){
		if(M == 0) cout << 1 << " " << 2 << endl;
		else cout << -1 << endl;
		return 0;
	}
	if(N == 2){
		if(M == 0){
			cout << 1 << " " << 2 << endl;
			cout << 3 << " " << 4 << endl;
		}
		else{
			cout << -1 << endl;
		}
		return 0;
	}
	if(M < 0 || M > N-2){
		cout << -1 << endl;
		return 0;
	}

	if(M == 0){
		rep(i, N){
			cout << 2*i+1 << " " << 2*i+2 << endl;
		}
	}
	else{
		cout << 1 << " " << 100000000 << endl;
		rep(i, M+1){
			cout << 2*i+2 << " " << 2*i+3 << endl;
		}
		rep(i, N-1-(M+1)){
			cout << 100000000 + 2*i+1 << " " << 100000000 + 2*i+2 << endl;
		}
	}
}