#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define drep(i,j,n) for(int i=0;i<(int)(n-1);i++)for(int j=i+1;j<(int)(n);j++)
#define trep(i,j,k,n) for(int i=0;i<(int)(n-2);i++)for(int j=i+1;j<(int)(n-1);j++)for(int k=j+1;k<(int)(n);k++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yes(ans) if(ans)printf("yes\n");else printf("no\n")
#define Yes(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YES(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector1d(type,name,...) vector<type>name(__VA_ARGS__)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define vector3d(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
const int MOD2=998244353;
const int INF=1<<30;
const ll INF2=(ll)1<<60;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T,class L>void scan(pair<T, L>& p){scan(p.first);scan(p.second);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T,class L>void print(const pair<T, L>& p){print(p.first);putchar(' ');print(p.second);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}
template<class T> void chmax(T &a,const T b){if(b>a)a=b;}
template<class T> void chmin(T &a,const T b){if(b<a)a=b;}

int main(){
    LL(n,m);
    if(n==m){
        out(0);
        return 0;
    }
    if(m==0){
        out(1);
        return 0;
    }
    vector<ll> vec(m);
    in(vec);
    sort(all(vec));
    ll l=1,r=n,mid,ans=INF2,pre,d;
    bool h=false;
    while(l<r){
        mid=(l+r)/2;
        h=true;
        pre=0;
        d=0;
        for(int i=0;i<m;i++){
            if(vec[i]-pre-1>=mid){
                d+=updivide(vec[i]-pre-1,mid);
            }else{
                if(vec[i]-pre!=1){
                    h=false;
                }
            }
            pre=vec[i];
        }
        if(n-vec[m-1]>=mid){
            d+=updivide(n-vec[m-1],mid);
        }else{
            if(n+1-vec[m-1]!=1){
                h=false;
            }
        }
        if(h){
            l=mid+1;
            chmin(ans,d);
        }else{
            r=mid;
        }
    }
    out(ans);
}

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

constexpr int N = 1005;

int n, m;
std::string s;
int f[N << 1];
std::vector<int> a, b;

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

inline void merge(int x, int y) { f[find(x)] = find(y); }

int main() {
    std::ios::sync_with_stdio(false), std::cin.tie(nullptr);
    std::cin >> n >> m;
    for (int i = 1; i <= n + m; ++i) f[i] = i;
    for (int i = 1; i <= n; ++i) {
        std::cin >> s;
        for (int j = 1; j <= m; ++j)
            if (s[j - 1] == '#')
                merge(i, j + n);
    }
    merge(1, n + 1);
    merge(1, n + m);
    merge(n, n + 1);
    merge(n, n + m);
    for (int i = 1; i <= n; ++i) a.push_back(find(i));
    for (int i = 1; i <= m; ++i) b.push_back(find(i + n));
    std::sort(a.begin(), a.end());
    std::sort(b.begin(), b.end());
    std::cout << std::min(std::unique(a.begin(), a.end()) - a.begin(), std::unique(b.begin(), b.end()) - b.begin()) - 1 << '\n';
    return 0;
}


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

double A, B;

int main() {
    cin >> A >> B;
    cout << fixed << setprecision(9) << (A-B) / A * 100.0 << endl;
}

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
//using Graph = vector<vector<pair<ll,ll>>>;
const int mod =1e+9+7;

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

const ll INF=1e18;

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


/*
{
######################
#       Author       #
#        Gary        #
#        2021        #
######################
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define check_min(a,b) a=min(a,b)
#define check_max(a,b) a=max(a,b)
using namespace std;
//inline int read(){
//    int x=0;
//    char ch=getchar();
//    while(ch<'0'||ch>'9'){
//        ch=getchar();
//    }
//    while(ch>='0'&&ch<='9'){
//        x=(x<<1)+(x<<3)+(ch^48);
//        ch=getchar();
//    }
//    return x;
//}
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
/*}
*/

int main(){
	int T;
	scanf("%d",&T);
	while(T--){
		int l,r;
		scanf("%d%d",&l,&r);
		int t=r-(2*l)+1;
		if(t<=0){
			cout<<0<<endl;
		}
		else{
			cout<<1ll*t*(t+1)/2<<endl;
		}
	}
	return 0;
}

#include <iostream>
#include <unordered_set>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll maxn = 1e9 + 7;
const double eps = 1e-6;
const ll N = 9e5 + 999;

struct node {
	ll x, y;
}a[N];
ll cas;
ll dis(ll i, ll j) {
	return (a[i].x - a[j].x) * (a[i].x - a[j].x) + (a[i].y - a[j].y ) * (a[i].y - a[j].y);
}
ll sum(ll x) {
	if (x == 1)return 1;
	return (1 + (2 *x - 1)) * x / 2;
}
ll d[N];
bool check(string num, ll n) {
	ll ret = 0;
	for (int i = 0; i < num.size(); i++) {
		ret *= 10;
		ret += num[i];
		ret %= n;
	}
	if (ret == 0)return 1;
	return 0;
}
ll n;
ll c;
ll f(ll x) {
	return -x * x * n + x * c;
}
void solve() {
	ll l, r;cin >> l >> r;
	ll dis = r-l + 1;
	ll ans = 0;
	if (dis == 0) {
		if (l == r && r == 0) {
			cout << 1 ;
		} else cout << 0;
		cout << endl;
		return;
	}
	if (l == 0) {
		ans += dis;
		l = 1;
	}
	 l = max((ll)0,dis - l);
	 r = max((ll)0, dis - r);
	ans += (l + r) * (l-r + 1) / 2;
	cout << ans << endl;

}
signed main() {
	ios::sync_with_stdio(0);
	ll t = 1;cin >> t;
	while (t--)
	solve();
}


#include<bits/stdc++.h>
using namespace std;
const int MAX = 2010;
const int INF = 1e9;
bool seen[MAX][MAX];
int dp[MAX][MAX];
int H, W;

int add(char x){
  if(x == '+'){
    return 1;
  }
  else{
    return -1;
  }
}

int dfs(int h, int w, vector<vector<char>> &vec){
  if(seen[h][w]){
    return dp[h][w];
  }
  int a = -INF;
  int b = -INF;
  if(h < H-1){
    a = dfs(h+1,w,vec);
    if((h+1+w)%2 == 0){
      a -= add(vec[h+1][w]);
    }
    else{
      a += add(vec[h+1][w]);
    }
  }
  if(w < W-1){
    b = dfs(h,w+1,vec);
    if((h+1+w)%2 == 0){
      b -= add(vec[h][w+1]);
    }
    else{
      b += add(vec[h][w+1]);
    }
  }
  seen[h][w] = true;
  if((h+w)%2 == 0){
    dp[h][w] = max(a,b);
  }
  else{
    if(a == -INF){
      a = b;
    }
    else if(b == -INF){
      b = a;
    }
    dp[h][w] = min(a,b);
  }
  return dp[h][w];
}

int main(){
  cin >> H >> W;
  vector<vector<char>> vec(H,vector<char>(W));
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      cin >> vec[i][j];
    }
  }
  seen[H-1][W-1] = true;
  dfs(0,0,vec);
  if(dp[0][0] > 0){
    cout << "Takahashi" << endl;
  }
  else if(dp[0][0] < 0){
    cout << "Aoki" << endl;
  }
  else{
    cout << "Draw" << endl;
  }
  //cout << dp[0][0] << endl;
}

#include <bits/stdc++.h>
//#include <atcoder/all>
#ifndef LOCAL
#pragma GCC target("arch=skylake-avx512")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif
using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define dbg(x) true
#endif

ll dp[2010][2010];

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<int>> a(h, vector<int>(w));
  REP(y, h) {
    string s;
    cin >> s;
    REP(x, w) {
      if (s[x] == '+') {
        a[y][x] = 1;
      } else {
        a[y][x] = -1;
      }
    }
  }
  dp[h - 1][w - 1] = a[h - 1][w - 1] * (((h - 1) + (w - 1)) % 2 == 0 ? -1 : +1);
  dbg(a[h - 1][w - 1]);
  dbg(dp[h - 1][w - 1]);
  for (int y = h - 1; y > 0; y--) {
    int s = ((w - 1 + y) % 2 == 0) ? 1 : -1;
    dp[y - 1][w - 1] = dp[y][w - 1] + s * a[y - 1][w - 1];
  }
  for (int x = w - 1; x > 0; x--) {
    int s = ((h - 1 + x) % 2 == 0) ? 1 : -1;
    dp[h - 1][x - 1] = dp[h - 1][x] + s * a[h - 1][x - 1];
  }

  for (int y = h - 1; y > 0; y--) {
    for (int x = w - 1; x > 0; x--) {
      bool odd = (y + x) % 2 == 0;
      int s = odd ? -1 : 1;
      if (odd) {
        dp[y - 1][x - 1] = max(dp[y - 1][x], dp[y][x - 1]);
      } else {
        dp[y - 1][x - 1] = min(dp[y - 1][x], dp[y][x - 1]);
      }
      dp[y - 1][x - 1] += s * a[y - 1][x - 1];
    }
  }
  dp[0][0] += a[0][0];
  // REP(y, h) {
  //   REP(x, w) {
  //     cout << dp[y][x] << " ";
  //   }
  //   cout << endl;
  // }
  if (dp[0][0] > 0) {
    cout << "Takahashi" << endl;
  } else if (dp[0][0] == 0) {
    cout << "Draw" << endl;
  } else {
    cout << "Aoki" << endl;
  }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define MOD 1000000007
#define int long long int
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;cin>>n;
    int l = 1, r = 1e9;
    while(l<r)
    {
        int mid = (l+r-1)/2;
        if((mid*(mid+1)/2) < n)
        l = mid+1;
        else
        r = mid;
    }
    cout<<l<<"\n";
}

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
double eps = 1e-12;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 2e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define int long long

void solve(){
    int n,i,s=0;
    cin>>n;
    for(i=1;;i++)
    {
        s=s+i;
        if(s>=n)
        break;
    }
    cout<<i;
}
signed main()
{
    fast_cin();
    // ll t;
    // cin >> t;
    // while(t--) {
         solve();
    // }
    return 0;
}


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

#define rep(i, a, b) for(int i=a; i<=b; i++)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int) x.size()
#define pb push_back
#define f first
#define s second
#define nl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MOD = 1e9+7;
// const int MOD = 998244353;
template<class T> using pqg = priority_queue<T,vector<T>,greater<T>>;

int n, m;
vector<pii> adj[101];
bool vis[101];
pii edge[10001];
int dir[10001];
int c[10001];

void dfs(int x){
  vis[x]=true;
  trav(p, adj[x]){
    if(c[p.f]==c[x]){
      dir[p.s]=x;
      if(!vis[p.f]) dfs(p.f);
    }
  }
}

bool comp(int a, int b){
  return (c[a]<c[b]);
}

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

  cin >> n >> m;
  rep(i, 1, m){
    cin >> edge[i].f >> edge[i].s;
    adj[edge[i].f].pb({edge[i].s, i});
    adj[edge[i].s].pb({edge[i].f, i});
  }
  rep(i, 1, n) cin >> c[i];

  rep(i, 1, n){
    if(vis[i]) continue;
    dfs(i);
  }

  vi vec;
  rep(i, 1, n) vec.pb(i);
  sort(all(vec), comp);
  rep(i, 0, n-1){
    int x=vec[i];
    trav(p, adj[x]){
      if(dir[p.s]!=0) continue;
      dir[p.s]=p.f;
    }
  }
  rep(i, 1,m){
    if(dir[i]==edge[i].f) cout << "->" << nl;
    else cout << "<-" << nl;
  }
}

#include<iostream>

using namespace std;

int main() {
  int a, b, c, d;
  cin>>a>>b;
  cin>>c>>d;
  cout<<(b-c);
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
     int a,b,c,d;
     cin >> a >> b >> c >> d;
     if( b-c*d==0)
     {
         cout << -1 << endl;
     }
     else
     {
         int k=(c*d-b);
         if(k<0)
         {
             cout << -1 << endl;
         }
         else if(a%k==0)
         {
             cout << a/k << endl;
         }
         else
         {
             cout << a/k +1 << endl;
         }
     }
}

#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;

int main()
{
	boost;
	ll x, y, a, b;
	cin >> x >> y >> a >> b;

	ll curr = x;
	ll ans = 0;
	while(curr < y) {
		if(y / a <= curr) break;
		if(curr * a < curr + b) {
			++ans;
			curr *= a;
		}
		else break;
	}
	ans += ((y - 1) - curr) / b;
	cout << ans;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define for0(i,n) for(ll i=0;i<n;i++)
#define for1(i,n) for(ll i=1;i<=n;i++)
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define maxpq priority_queue<int>
#define minpq priority_queue<int ,vector<int>,greater<int>>
#define fio ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define bits(n) __builtin_popcount(n)
#define prec(n) fixed<<setprecision(n)
#define rr return 0
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;

void solve(){

map<int,int> m;
ll n;
cin>>n;
ll a[n];
for0(i,n) cin>>a[i];
ll ans=0;
for(ll i=n-1;i>=0;i--){
ans+=(n-1-i-m[a[i]]);
m[a[i]]++;
}
cout<<ans<<endl;

}

int main()
{
fio;
ll t=1;
//cin>>t;
while(t--)
solve();
rr ;
}

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

using Int = long long;
const char newl = '\n';

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
template<typename T=int>
vector<T> read(size_t n){
  vector<T> ts(n);
  for(size_t i=0;i<n;i++) cin>>ts[i];
  return ts;
}

template<typename T, T MOD = 1000000007>
struct Mint{
  static constexpr T mod = MOD;
  T v;
  Mint():v(0){}
  Mint(signed v):v(v){}
  Mint(long long t){v=t%MOD;if(v<0) v+=MOD;}

  Mint pow(long long k){
    Mint res(1),tmp(v);
    while(k){
      if(k&1) res*=tmp;
      tmp*=tmp;
      k>>=1;
    }
    return res;
  }

  static Mint add_identity(){return Mint(0);}
  static Mint mul_identity(){return Mint(1);}

  Mint inv(){return pow(MOD-2);}

  Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;}
  Mint& operator/=(Mint a){return (*this)*=a.inv();}

  Mint operator+(Mint a) const{return Mint(v)+=a;}
  Mint operator-(Mint a) const{return Mint(v)-=a;}
  Mint operator*(Mint a) const{return Mint(v)*=a;}
  Mint operator/(Mint a) const{return Mint(v)/=a;}

  Mint operator-() const{return v?Mint(MOD-v):Mint(v);}

  bool operator==(const Mint a)const{return v==a.v;}
  bool operator!=(const Mint a)const{return v!=a.v;}
  bool operator <(const Mint a)const{return v <a.v;}

  static Mint comb(long long n,int k){
    Mint num(1),dom(1);
    for(int i=0;i<k;i++){
      num*=Mint(n-i);
      dom*=Mint(i+1);
    }
    return num/dom;
  }
};
template<typename T, T MOD> constexpr T Mint<T, MOD>::mod;
template<typename T, T MOD>
ostream& operator<<(ostream &os,Mint<T, MOD> m){os<<m.v;return os;}

// [0, n]
template<typename T>
vector<T> powers(int n,T x){
  vector<T> po(n+1,T(1));
  for(int i=0;i<n;i++) po[i+1]=po[i]*x;
  return po;
}

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

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

  using M = Mint<int, 998244353>;
  vector<M> way(n,0);
  for(int h=1;h<=m;h++){
    M res{1};
    for(int i=0;i<n;i++){
      way[i]+=res;
      res*=M(m-h);
    }
  }

  auto po=powers(n,M(m));

  M ans=M(n)*po[n];
  for(int w=0;w+2<=n;w++)
    ans-=M(n-(w+2)+1)*po[n-(w+2)]*way[w];
  //cout<<way[0]<<endl;
  cout<<ans<<newl;
  return 0;
}


#include <bits/stdc++.h>

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

using namespace std;

typedef long long ll;

#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FORD(i, a, b) for (int i = b - 1; i >= int(a); i--)
#define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)

#define ALL(x) (x).begin(), (x).end()

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

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
ll n,b,c,a[100009];
ll dp[1000005];

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


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

const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
const int MOD=1000000007;

int x[2000],y[2000];
int main(){
	int n;cin>>n;
	rep(i,n){
		scanf("%d%d",&x[i],&y[i]);
	}
	int cnt=0;
	rep(i,n)for(int j=i+1;j<n;j++){
		int A=abs(x[j]-x[i]),B=abs(y[j]-y[i]);
		if(B<=A){
			cnt++;
		}
	}
	cout<<cnt<<endl;
}

#include<bits/stdc++.h>
typedef long long ll;
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define nep(i,r,l) for(int i=r;i>=l;i--)
void re(int &x){scanf("%d",&x);}
void re(int &x,int &y){scanf("%d %d",&x,&y);}
void re(ll &x){scanf("%lld",&x);}
void re(ll &x,ll &y){scanf("%lld %lld",&x,&y);}
void re(double &x){scanf("%lf",&x);}
void re(double &x,int &y){scanf("%lf %lf",&x,&y);}
using namespace std;
const int N=1e5+5;

int boom[N];
int a[N];
int main()
{
    ll n;re(n);
	ll t;
	ll ans=0;
	rep(i,1,n)
	{
		cin>>t;
		boom[t]++;
	}
	rep(i,1,n)
	{
		cin>>a[i];
	}
	rep(i,1,n)
	{
		cin>>t;
		ans+=boom[a[t]];
	}
	cout<<ans;
    return 0;
}


# include <bits/stdc++.h>
# define ull unsigned long long
# define ll long long
# define double long double
# define pll pair<ll,ll>
# define pb push_back
# define fi first
# define se second
# define mp make_pair
# define max3(a,b,c) max(a,max(b,c))
# define min3(a,b,c) min(a,min(b,c))
# define all(x) x.begin(),x.end()
# define fill(a,b) memset(a,b,sizeof(a))
# define gcd(m,n)  __gcd(m, n)
# define pr_double(x) cout << fixed << setprecision(15) << x
# define endl "\n"

using namespace std;
const ll INF = 9223372036854775807;
const ll N = 300005;
const ll mod = 998244353;
const ll M = 30;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll a,b,c,d; cin>>a>>b>>c>>d; ll ans = -19999999;
  for(ll x=a;x<=b;x++)
  {
      for(ll y=c;y<=d;y++) ans = max(ans,x-y);
  }
  cout<<ans<<endl;
}

#include <iostream>

using namespace std;

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << b - c << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FAST ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define pb push_back
#define MOD 1000000007
#define sz5 100005
#define sz6 1000005
#define UP upper_bound
#define LB lower_bound
#define F first
#define S second
#define PI pair<int,int>
#define PL pair<ll,ll>
#define VI vector<int>
#define VL vector<ll>
#define pr pair<int, pair<int,int>>

const ll inf = 1e9;

int r,c;
int A[505][505], B[505][505];

int main() {
    FAST

    int la,lb;
    cin>>r>>c;
    for(la=1;la<=r;la++){
        for(lb=1;lb<c;lb++)
            cin>>A[la][lb];
    }
    for(la=1;la<r;la++){
        for(lb=1;lb<=c;lb++)
            cin>>B[la][lb];
    }

    priority_queue<pr, vector<pr>, greater<pr>> q;
    bool mk[505][505]={0};

    q.push({0, {1, 1}});
    vector<vector<int>> dis(505, vector<int>(505, inf));
    dis[1][1]=0;

    while(!q.empty()){
        int d=q.top().first, x=q.top().second.first, y=q.top().second.second;
        q.pop();

        if(dis[x][y] != d)
            continue;

        if(x==r && y==c){
            cout<<d<<endl;
            return 0;
        }

        if(y<c && dis[x][y+1] > dis[x][y]+A[x][y]){
            dis[x][y+1] = dis[x][y]+A[x][y];
            q.push({dis[x][y+1], {x, y+1}});
        }
        if(y>1 && dis[x][y-1] > dis[x][y]+A[x][y-1]){
            dis[x][y-1] = dis[x][y]+A[x][y-1];
            q.push({dis[x][y-1], {x, y-1}});
        }
        if(x<r && dis[x+1][y] > dis[x][y]+B[x][y]){
            dis[x+1][y] = dis[x][y]+B[x][y];
            q.push({dis[x+1][y], {x+1, y}});
        }

        for(la=x-1, lb=1;la>=1;la--,lb++){
            if(dis[la][y] > dis[x][y]+1+lb){
                dis[la][y] = dis[x][y]+1+lb;
                q.push({dis[la][y], {la, y}});
            }
        }
    }

    return 0;
}

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

#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>
#define all(x) x.begin(),x.end()

const int N = 505;
const int inf = 1e9;

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

vector<pii> g[2*N*N];
vector<bool> vis(2*N*N,0);
vector<int> dis(2*N*N,inf);

inline int encode(int i,int j)
{
    return (i*m) + j;
}

void solve()
{
   cin >> n >> m;

   f(i,n) f(j,m-1) cin >> a[i][j];
   f(i,n-1) f(j,m) cin >> b[i][j];

   f(i,n) f(j,m)
   {
       if(j > 0) g[encode(i,j)].push_back({encode(i,j-1),a[i][j-1]});
       if(j < m-1) g[encode(i,j)].push_back({encode(i,j+1),a[i][j]});
       if(i < n-1) g[encode(i,j)].push_back({encode(i+1,j),b[i][j]});
       if(i > 0) g[encode(i,j) + (n*m)].push_back({encode(i-1,j) + (n*m),1});

       g[encode(i,j)].push_back({encode(i,j) + (n*m),1});
       g[encode(i,j) + (n*m)].push_back({encode(i,j),0});
   }

   dis[0] = 0;
   priority_queue<pii,vector<pii>,greater<pii> > PQ;
   PQ.push({0,0});

   while(!PQ.empty())
   {
       auto x = PQ.top();  PQ.pop();
       if(vis[x.S] == 1) continue;
       vis[x.S] = 1;

       for(auto z : g[x.S])
       {
           if(dis[z.F] > dis[x.S] + z.S)
           {
               dis[z.F] = dis[x.S] + z.S;
               PQ.push({dis[z.F],z.F});
           }
       }
   }

   cout << dis[n*m - 1];
}

signed main()
{
    fast;
    solve();
}


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

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

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

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

const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy

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

    int N; cin >> N;
    ll A[N], B[N]; F0R(i, N) cin >> A[i] >> B[i];
    vl ops; ll sum = 0;
    F0R(i, N) {
        sum += A[i]; ops.pb(2*A[i] + B[i]);
    }
    sort(all(ops)); reverse(all(ops));
    int ans = 0;
    F0R(i, N) {
        ans++; sum -= ops[i];
        if (sum < 0) break;
    }
    cout << ans << nl;

	return 0;
}

// read the question correctly (ll vs int)
// template by bqi343

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define MAX 128
#define pb push_back
#define mp make_pair
#define ALL(x) (x).begin(), (x).end()
#define bit(n) (1LL << (n))
const double PI = 3.141593;
const int MOD = (int)1e9 + 7;
const int INF = 100100100;
const double EPS = 1e-9;
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;}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }     //最小公倍数
ll combination(ll n, ll r){if (r * 2 > n)r = n - r;ll dividend = 1;ll divisor = 1;for (ll i = 1; i <= r; ++i){dividend *= (n - i + 1);divisor *= i;}return dividend / divisor;}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int h, w, x, y;
    cin >> h >> w >> x >> y;
    x--;
    y--;
    string s[h];
    rep(i, h)
    {
        cin >> s[i];
    }
    int ans =0;
    for (int i = y; i < w;i++){
        if(s[x][i]=='.'){
            ans++;

        }
        else
            break;
    }
    for (int i = y; 0 <= i; i--)
    {
        if(s[x][i]=='.'){
            ans++;
        }
        else
            break;
    }
    for (int i = x; i < h; i++)
    {
        if(s[i][y]=='.'){
            ans++;
        }
        else
            break;
    }
    for (int i = x; 0 <= i; i--)
    {
        if(s[i][y]=='.'){
            ans++;
        }
        else
            break;
    }
    cout << ans - 3 << endl;
    return 0;
}


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

ll MX=100000000000000000LL;

ll ck(vector<ll> a, vector<ll> b)
{
    ll mn=MX;
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    for(int i=0;i<a.size();i++)
    {
        auto it=upper_bound(b.begin(), b.end(), a[i]);
        if(it!=b.end())
        {
            mn=min(mn, abs(*it-a[i]));
        }
        if(it!=b.begin())
        {
            it=prev(it);
            mn=min(mn, abs(*it-a[i]));
        }
    }
    return mn;

}

ll ck1(vector<ll> a, vector<ll> b, vector<ll> c)
{
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    vector<ll> dl(a.size()), dr(a.size());
    for(int i=0;i<a.size();i++)
    {
        ll x=MX;
        auto it=upper_bound(b.begin(), b.end(), a[i]);
        if(it!=b.end())
        {
            x=min(x, abs(*it-a[i]));
        }
        if(it!=b.begin())
        {
            it=prev(it);
            x=min(x, abs(*it-a[i]));
        }
        if(i>0) dl[i]=min(x, dl[i-1]);
        else dl[i]=x;
    }
    for(int i=a.size()-1;i>=0;i--)
    {
        ll x=MX;
        auto it=upper_bound(b.begin(), b.end(), a[i]);
        if(it!=b.end())
        {
            x=min(x, abs(*it-a[i]));
        }
        if(it!=b.begin())
        {
            it=prev(it);
            x=min(x, abs(*it-a[i]));
        }
        if(i!=a.size()-1) dr[i]=min(x, dr[i+1]);
        else dr[i]=x;
    }

    ll mn=MX;
    for(int i=0;i<a.size();i++)
    {
        ll x=MX;
        auto it=upper_bound(c.begin(), c.end(), a[i]);
        if(it!=c.end())
        {
            x=min(x, abs(*it-a[i]));
        }
        if(it!=c.begin())
        {
            it=prev(it);
            x=min(x, abs(*it-a[i]));
        }
        ll y=MX;
        if(i>0) y=min(y, dl[i-1]);
        if(i+1<a.size()) y=min(y, dr[i+1]);
        mn=min(mn, x+y);
    }
    return mn;
}

int main()
{
    ll n;
    cin>>n;
    map<char, vector<ll> > mp;
    for(int i=1;i<=2*n;i++)
    {
        ll x;
        char c;
        cin>>x>>c;
        mp[c].push_back(x);
    }
    if(mp['B'].size()%2==0 and mp['R'].size()%2==0 and mp['G'].size()%2==0)
    {
        cout<<0<<endl;
        return 0;
    }
    if(mp['B'].size()%2==0)
    {
        ll x=ck(mp['R'], mp['G']);
        if(mp['B'].size()>=2)
            x=min(x, ck1(mp['B'], mp['R'], mp['G']));
        cout<<x<<endl;
        return 0;
    }

    if(mp['R'].size()%2==0)
    {
        ll x=ck(mp['B'], mp['G']);
        if(mp['R'].size()>=2)
        {
            x=min(x, ck1( mp['R'], mp['B'], mp['G'] ));
        }
        cout<<x<<endl;
        return 0;
    }

    if(mp['G'].size()%2==0)
    {
        ll x=ck(mp['R'], mp['B']);
        if(mp['G'].size()>=2)
        {
            x=min(x, ck1(mp['G'], mp['R'], mp['B']));
        }
        cout<<x<<endl;
        return 0;
    }

    return 0;
}

#include <stdio.h>

typedef long long ll;
int num[105][105], max = -1, vis[20], k, n, m;
struct node {
	int x1, x2;
} a[20], b[105];

void dfs(int now) {
	if (now >= k) {
		int sum = 0;
		//for (int i = 0; i < 17; i ++) printf("%d ", vis[i]);printf("\n");
		for (int i = 0; i < m; i ++)
			if (vis[b[i].x1] && vis[b[i].x2])
				//printf("sum : %d + num[%d][%d] (%d)\n", sum, b[i].x1, b[i].x2, num[b[i].x1][b[i].x2]);
				sum ++;

		if (sum > max) max = sum;
		//printf("%d..sum : %d\n", now, sum);
		return;
	}
	int px1 = a[now].x1, px2 = a[now].x2;

	vis[px1] ++;
	//printf("%d pick : %d\n", now, px1);
	dfs(now + 1);
	vis[px1] --;

	vis[px2] ++;
	//printf("%d pick : %d\n", now, px2);
	dfs(now + 1);
	vis[px2] --;

}
int main() {
	int cnt = 0;
	scanf("%d %d", &n, &m);
	while (cnt < m) {
		scanf("%d %d", &b[cnt].x1, &b[cnt].x2);
		//num[b[cnt].x1][b[cnt].x2] ++;
		cnt ++;
	}
	int ind = 0;
	scanf("%d", &k);
	while (ind < k) {
		scanf("%d %d", &a[ind].x1, &a[ind].x2);
		ind ++;
	}
	dfs(0);
	//dfs(1);
	printf("%d\n", max);
	return 0;
}


#include <bits/stdc++.h>

#define vi vector<int>
#define tests int t; cin>>t; while(t--)
#define ll long long
#define vll vector<long long>
#define srt(v) sort(v.begin(), v.end())
#define srtg(v) sort(v.begin(), v.end(), greater<int> ())
#define FOR(k, n) for(int k=0; k<n; k++)
#define pb push_back
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define printarr(v) for(auto& x : v) cout<<x<<" "; cout<<endl

using namespace std;

char nums[10] = { '0','1','2','3','4','5','6','7','8','9' };
char alphsl[26] = { 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' };
const int MOD = 1000000007;
char alphs[26] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };

void solve() {

   int n, w;
   cin>>n>>w;

   vi start(n), end(n), litre(n);
   for(int i=0; i<n; i++){
       cin>>start[i]>>end[i]>>litre[i];
   }

   vi open[200005], close[200005];

   for(int i=0; i<n; i++){
       int currop=start[i];
       open[currop].pb(i);
       currop=end[i];
       close[currop].pb(i);
   }
   ll curr=0;
   for(int i=0; i<=200000; i++){
       for(auto x : open[i]) curr+=litre[x];
       for(auto y : close[i]) curr-=litre[y];

       if(curr>w){
           cout<<"No"<<endl;
           return;
       }

   }
   cout<<"Yes"<<endl;

}

int main() {

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

        solve();

    return 0;
}

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

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    int N,S,T;long W,P;
    int maxx = 0;
    long long a[200010]={0},sum=0,sum1=0;

    cin >> N >> W;
    for(int i=1;i<=N;i++){
        cin >> S >> T >> P;
        maxx = max(maxx,T);
        a[S] += P;
        a[T] -= P;
    }
    for(int i=0;i<maxx;i++){
        sum1 = max(sum,sum + a[i]);
        sum += a[i];
        if(sum>W){
            cout << "No" << endl;
            //cout << sum1<<endl;
            //cout << a[0]<<endl;
            //cout << a[200000]<<endl;
            return 0;
        }
    }
    cout << "Yes";
    //cout << sum1;
    return 0;
}


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

int main() {
  int a, b;
  cin >> a >> b;
  int a1 = a / 100, b1 = b / 100;
  int a2 = (a -= a1*100) / 10, b2 = (b -= b1*100) / 10;
  int a3 = a - a2*10, b3 = b - b2*10;
  a = a1 + a2 + a3, b = b1 + b2 + b3;
  if(a >= b) cout << a << endl;
  else cout << b << endl;
  return 0;
}

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
#include <climits>
#include <iomanip>
#include <queue>
#include <stack>

using namespace std;

typedef long long ll;

const int INF = (1<<30)-1;
const ll LINF = 1e18;

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

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

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

int main() {
    ll n, m, t; cin >> n >> m >> t;
    ll tmp = n;
    vector<ll> a(m+1), b(m+1, 0);
    rep(i, m) {
        cin >> a[i+1] >> b[i+1];
        tmp -= a[i+1] - b[i];
        if (tmp <= 0) {
            cout << "No" << endl;
            return 0;
        }
        tmp = min(n, tmp+b[i+1]-a[i+1]);
    }

    tmp -= t - b[m];
    if (tmp <= 0) {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    return 0;
}

//小数点精度
//cout << fixed << std::setprecision(15) << y << endl;


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

#define PI acos(-1)

typedef long long int T;    /// basic type
typedef double Tf;      /// floating point type

Tf eps = 1e-6;

//int sgn(Tf x){
//    if(fabs(x) < eps) return 0;
//    if(x > 0) return 1;
//    else return -1;
//}

int sgn(T x){
    if(x == 0) return 0;
    if(x > 0) return 1;
    else return -1;
}

struct point{
    T x, y;
    point(T x = 0, T y = 0){
        this->x = x;
        this->y = y;
    }

    point operator+(point p){ return point(x+p.x, y+p.y); }

    point operator-(point p){ return point(x-p.x, y-p.y); }

    point operator*(T a){ return point(x*a, y*a); }

    point operator/(T a){ return point(x/a, y/a); }

    Tf len(){ return sqrt(x*x+y*y); }

    T norm(){ return x*x + y*y; }

//    bool operator==(point p){       /// for integers
//        return x == p.x && y == p.y;
//    }

    bool operator==(point p){       /// for floating point
       return sgn(x-p.x) == 0 && sgn(y-p.y) == 0;
    }

//    bool operator<(point p){        /// for integers
//        if(x == p.x) return y < p.y;
//        else return x < p.x;
//    }
//
    bool operator<(point p){        /// for floating points
        if(sgn(x-p.x) == 0) return sgn(y-p.y) == -1;
        else return sgn(x-p.x) == -1;
    }

};

T dot(point p, point q){
    return p.x * q.x + p.y * q.y;
}

T cross(point p, point q){
    return p.x * q.y - p.y * q.x;
}

/// a->b->c which direction we rotate, +ve ccw, -ve cw, 0 collinear
T orient(point a, point b, point c){
    return cross(b-a, c-a);
}

ostream& operator<<(ostream &os, point p){
    return os<<"("<<p.x<<","<<p.y<<")";
}

T triangleArea(point a, point b, point c){
    return abs(orient(a, b, c));
}

struct segment{
    point a, b;

    bool onSegment(point p){ // check if a point is on the segment.
        if(sgn(orient(a, b, p)) != 0) return false;
        return sgn(dot(p-a, p-b)) <= 0;
    }

    bool intersection(segment s){
        if(onSegment(s.a)) return true;
        if(onSegment(s.b)) return true;
        if(s.onSegment(a)) return true;
        if(s.onSegment(b)) return true;

        int s1 = sgn(orient(a, b, s.a));
        int s2 = sgn(orient(a, b, s.b));
        int s3 = sgn(orient(s.a, s.b, a));
        int s4 = sgn(orient(s.a, s.b, b));

        if(s1*s2 < 0 && s3 * s4 < 0) return true;

        return false;
    }
};

//8 -6 8 6
//0 0 7
void solve(){
     int n; cin>>n;
     double arr1[n], arr2[n];
     for(int  x=0;x<n;x++){
        cin>>arr1[x]>>arr2[x];
     }
     bool ok = false;
     for(int x=0;x<n;x++){
        for(int y=x+1;y<n;y++){
            for(int z=y+1;z<n;z++){
                point a(arr1[x], arr2[x]);
                point b(arr1[y], arr2[y]);
                point c(arr1[z], arr2[z]);
                if(orient(a, b, c) == 0) ok = true;
            }
        }
     }
     if(ok) cout<<"Yes\n";
     else cout<<"No\n";
}
int main(){
    solve();
//    double x1, y1, x2, y2, c1, c2, l;
//    cin>>x1>>y1>>x2>>y2>>c1>>c2>>l;
//
//    point a(x1, y1);
//    point b(x2, y2);
//    point c(c1, c2);
//
//    point d = (a + b) / 2;
//
//
//    segment seg;
//    seg.a = a;
//    seg.b = b;
//
//    double ans1;
//    if((orient(b, d, c) * orient(d, a, c))>=0 || (orient(d, b, c) * orient(a, d, c)) >= 0){
//        double ar = triangleArea(a, b, c);
//        ans1 = ar / (a-b).len();
//    }else{
//        ans1 = min((c-a).len(), (c-b).len());
//    }
//    printf("%.2lf\n", max((double) 0,  ans1 - l));
//
//
//    double ans2 = max((double)0, max((a-c).len(), (b-c).len()) - l);
//    printf("%.2lf\n",  ans2);

}

/// x > y => x-y > 0
/// sgn(x-y) == 1
/// sgn(y-x) == -1

#include<iostream>
using namespace std;

#define progend  {delete [] x;delete [] y; return 0;}

int* makevector(int* a, int p, int len) {
    int* temp = new int[len];
    for (int i = 0; i < len; i++) {
        temp[i] = a[i] - p;
    }
    return temp;
}

int main() {
    int n, a, b;
    cin >> n;
    int* x = new int[n];
    int* y = new int[n];
    int k = n;
    while (n--) {
        cin >> a >> b;
        x[n] = a;
        y[n] = b;
    }
    int* xV, * yV;
    while (k>2) {
        xV = makevector(x, x[k - 1], k-1);
        yV = makevector(y, y[k - 1], k-1);
        for (int i = 0; i < k - 2; i++)
            for (int j = i + 1; j < k - 1; j++)
                if (xV[j] * yV[i] == xV[i] * yV[j]) {
                    cout << "Yes\n";
                    progend
                }
        k -= 1;
    }
    cout << "No\n";
    progend
}


#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f3f3f3fLL
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll quickpower(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string int_to_string(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int string_to_int(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
int n;
int x[1010],y[1010];
int main()
{
	ios::sync_with_stdio(0);
	cin>>n;
	rep(i,n)cin>>x[i]>>y[i];
	int ans=0;
	rep(i,n)
	{
		rep(j,i)
		{
			if(abs(y[j]-y[i])<=abs(x[j]-x[i]))ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

void fastio() {
	cin.tie(nullptr);
	cin.sync_with_stdio(false);
}

using LL = long long;
using LD = long double;

const LL MOD = 1e9+7;
const LL INF = LLONG_MAX;
const LL N = 101;

#define F first
#define S second
#define vt vector

LL gcd(LL a, LL b, LL& x, LL& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	LL x1, y1;
	LL d = gcd(b, a % b, x1, y1);
	x = y1;
	y = x1 - y1 * (a / b);
	return d;
}

int main() {
	fastio();

	LL T;
	cin >> T;

	while (T--) {
		LL n, s, k;
		cin >> n >> s >> k;

		if (s % __gcd(k, n) != 0) {
			cout << "-1\n";
			continue;
		}
		LL xg, yg;

		LL gc = __gcd(k, n);
		LL k1 = k/gc, n1 = n/gc, s1 = s/gc;

		gcd(k, n, xg, yg);

		LL x0 = -xg * s1;
		LL y0 = yg * s1;

		//cerr << x0 << " " << y0 << "??\n";

		if (x0 < 0) {
			// adjust y and x
			LL mx = max(-x0/n1, -y0/k1);
			x0 += mx*n1;
			y0 += mx*k1;

			if (x0 < 0 || y0 < 0) {
				x0 += n1;
				y0 += k1;
			}
		}
		else {
			x0 %= n1;
		}

		cout << x0 << "\n";
	}
}


#include <bits/stdc++.h>

using namespace std;

int modPow(int x, int n, int mod) {
    if (n == 0) return 1;
    int z = modPow(x, n / 2, mod);
    z *= z;
    z %= mod;
    if (n & 1) z *= x, z %= mod;
    return z;
}

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    a %= 10;
    vector<int> p;
    p.push_back(a);
    int t = a;
    while ((t * a) % 10 != a) {
        t *= a;
        t %= 10;
        p.push_back(t);
    }
    int cycleLength = p.size();
    int remPow =  modPow(b, c, cycleLength);
    int ans = remPow == 0? p.back(): p[remPow - 1];
    cout << ans << "\n";
    return 0;
}

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

int main() {
    long double X, Y, R;
  cin >> X >> Y >> R;

  long ans = 0;
  int high = floor(Y + R);
  int low = ceil(Y - R);
  R += 1e-14;
  long double RR = R*R;

  for(long double h = high; h >= low; h--) {
    long double YYhh = (Y-h)*(Y-h);
    if(RR > YYhh ){
    long double halfLen = sqrt(RR - YYhh);
    int right = floor(X + halfLen);
    int left = ceil(X - halfLen);

    ans += right - left + 1;
    }
  }

  cout << ans;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
const int INF = 1000000007;
int A[MAXN], max_reachable[MAXN];
vector <int> G[MAXN];
int main(int argc, char const *argv[])
{
	int n, m;
	cin>>n>>m;
	for (int i = 1; i <= n; ++i)
	{
		cin>>A[i];
	}
	for (int i = 0; i < m; ++i)
	{
		int u, v;
		cin>>u>>v;
		G[u].push_back(v);
	}

	int ans = -INF;
	for (int i = n; i >= 1; --i)
	{
		max_reachable[i] = -INF;
		for (int j = 0; j < (int)G[i].size(); ++j)
		{
			int v = G[i][j];
			max_reachable[i] = max(max_reachable[i], max_reachable[v]);
		}

		ans = max(ans, max_reachable[i] - A[i]);

		max_reachable[i] = max(max_reachable[i], A[i]);
	}

	cout<<ans<<"\n";
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define fst ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endk cout<<"\n";
typedef long long int ll;
typedef long int l;
#define l(i,a,b) for(i=a;i<b;i++)
#define lo(i,a,b) for(i=a;i>=b;i--)
#define s(v) sort(v.begin(),v.end());
#define pb push_back;
#define vll vector<ll>
#define vint vector<int>
#define test() ll t;cin>>t;while(t--){solve();};
#define test1() int t=1;while(t--){solve();};
bool isprime(ll x)
{
    if(x==1) return false;
    if(x==2 || x==3) return true;
    if(x%2==0 || x%3==0) return false;
    for(ll i=5;i*i<=x;i+=6)
    {
        if(x%i==0 || x%(i+2)==0) return false;
    }
    return true;
}
ll power(ll x,ll y)
{
	ll ans=1;
	while(y>0)
	{
		if(y&1) ans=ans*x;
		x=x*x;
		y=y>>1;
	}
	return ans;
}
bool comp(pair<ll,ll> a,pair<ll,ll> b)
{
    return (a.first<b.first);
}
int solve()
{
    ll n,k,ans=0,i,curr=0;
    cin>>n>>k;
    vector<pair<ll,ll>> v(n);
    for(i=0;i<n;i++)
    {
        cin>>v[i].first>>v[i].second;
    }
    sort(v.begin(),v.end(),comp);
    for(i=0;i<n;i++)
    {
        if(v[i].first-curr<=k)
        {
            k-=(v[i].first-curr);
            curr=v[i].first;
            k+=v[i].second;
        }
        else
        {
            curr+=k;
            break;
        }
    }
    if(i==n)
    {
        curr+=k;
    }
    cout<<curr;
    return 0;
}
int main()
{
    fst;
    test1();
    return 0;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#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=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;}

#define MAX_N 1000010
ll inv[MAX_N+10],fac[MAX_N+10],ifac[MAX_N+10];

void setComb(){
  inv[0]=1;inv[1]=1;fac[1]=1;ifac[1]=1;fac[0]=1;ifac[0]=1;
  for(int i=2;i<MAX_N;i++){
    inv[i]=(-MOD/i)*inv[MOD%i]%MOD;
    fac[i]=fac[i-1]*i%MOD;
    ifac[i]=ifac[i-1]*inv[i]%MOD;

    inv[i]=(inv[i]+MOD)%MOD;
    fac[i]=(fac[i]+MOD)%MOD;
    ifac[i]=(ifac[i]+MOD)%MOD;
  }
  return;
}

ll comb(ll n,ll k){
  if(n<k||n<0||k<0) return 0;
  else return ((fac[n]*ifac[k]%MOD*ifac[n-k]%MOD+MOD)%MOD);
}

ll hcomb(ll n,ll r){// this size is really ok??
  if(n==0&&r==0) return 1;
  else if(n<0||r<0) return 0;
  else return comb(n+r-1,r);
}

ll binom(ll n,ll k){
  if(n<k||n<0||k<0) return 0;
  ll res=1;
  for(ll i=0;i<k;i++) res=res*(n-i)%MOD;
  res=res*ifac[k]%MOD;
  return res;
}

ll mod_pow(ll x,ll n){
  x%=MOD;
  ll res=1;
  while(n>0){
    if(n&1) res=res*x%MOD;
    x=x*x%MOD;
    n>>=1;
  }
  return res;
}

ll mod_inverse(ll x){
  return mod_pow(x,MOD-2);
}

void add(ll &a,ll b){
  a=(a+b)%MOD;
}

void mul(ll &a,ll b){
  a%=MOD;b%=MOD;
  a=a*b%MOD;
}

string P="RDX";

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

  setComb();

  ll H,W,K;
  cin>>H>>W>>K;
  vector<int> X(K),Y(K);
  vector<char> C(K);
  rep(i,K) cin>>X[i]>>Y[i]>>C[i];

  rep(i,K){
    X[i]--;Y[i]--;
  }
  vector<int> ord(K,0);
  rep(i,K) ord[i]=i;
  sort(all(ord),[&](int a,int b){
    if(X[a]!=X[b]) return X[a]<X[b];
    if(Y[a]!=Y[b]) return Y[a]<Y[b];
    return a<b;
  });

  vector<ll> dp(W,0);
  dp[0]=mod_pow(3,H*W-K);
  int now=0;
  for(int i=0;i<H;i++){
    vector<ll> ndp(W,0);
    for(int j=0;j<W;j++){
      bool exi=false;
      char c='#';
      if(now<K&&X[ord[now]]==i&&Y[ord[now]]==j){
        c=C[ord[now]];
        exi=true;
        now++;
      }
      ll coef=1;
      if(exi==false) coef=inv[3];
      for(int k=0;k<3;k++){
        //if(mp.count(mkp(i,j))&&mp[mkp(i,j)]!=P[k]) continue;
        if(exi&&c!=P[k]) continue;
        if(k==0||k==2){
          if(j+1<W){
            dp[j+1]+=(dp[j]*coef%MOD);
            dp[j+1]%=MOD;
          }
        }
        if(k==1||k==2){
          if(i+1<H){
            ndp[j]+=(dp[j]*coef%MOD);
            ndp[j]%=MOD;
          }
        }
      }
    }

    if(i+1==H) break;
    swap(dp,ndp);
  }

  ll ans=dp[W-1];
  cout<<ans<<endl;

  return 0;
}

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define priority_queue std::priority_queue
#define F first
#define S second

ll MOD=998244353;
int h, w, k;
char g[5005][5005];
ll dp[5005][5005], emp[5005][5005], po3[200005], inv;

ll modpow(ll x, ll e){
	if(x==0) return 0;
	if(e==0) return 1;
	ll y=modpow(x, e/2);
	if(e%2==0) return (y*y)%MOD;
	return ((y*y)%MOD*x)%MOD;
}

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>h>>w>>k;
	po3[0]=1;
	for(int i=1;i<200005;i++){
		po3[i]=(po3[i-1]*3)%MOD;
	}
	for(int i=0;i<=h;i++){
		for(int j=0;j<=w;j++){
			g[i][j]='.';
		}
	}
	for(int i=0;i<k;i++){
		int x, y;
		char c;
		cin>>x>>y>>c;
		g[x][y]=c;
	}
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			emp[i][j]=emp[i-1][j]+emp[i][j-1]-emp[i-1][j-1]+(g[i][j]=='.');
		}
	}
	if(g[1][1]=='.') dp[1][1]=3;
	else dp[1][1]=1;
	inv=modpow(3, MOD-2);
	for(int x=1;x<=h;x++){
		for(int y=1;y<=w;y++){
			if(x+y==2) continue;
			ll c=po3[emp[x][y]-emp[x][y-1]], r=po3[emp[x][y]-emp[x-1][y]];
			if(g[x][y-1]=='R' || g[x][y-1]=='X'){
				dp[x][y]=(dp[x][y]+dp[x][y-1]*c)%MOD;
			}
			if(g[x-1][y]=='D' || g[x-1][y]=='X'){
				dp[x][y]=(dp[x][y]+dp[x-1][y]*r)%MOD;
			}
			if(g[x][y-1]=='.'){
				dp[x][y]+=(((2*inv*dp[x][y-1])%MOD)*c)%MOD;
				dp[x][y]%=MOD;
			}
			if(g[x-1][y]=='.'){
				dp[x][y]+=(((2*inv*dp[x-1][y])%MOD)*r)%MOD;
				dp[x][y]%=MOD;
			}
		}
	}
	cout<<dp[h][w]<<endl;
}


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

signed main(void)
{
	int x, y, tmp; cin >> x >> y;
	if (x > y) {tmp = x; x = y; y = tmp;}
	x += 3;
	if (x > y) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

signed main(){
	int x, y;
	cin >> x >> y;
	if(abs(x - y) < 3)
		cout << "Yes\n";
	else
		cout << "No\n";
}


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

int main(){
  int N;
  cin>>N;
  string A,B;
  cin>>A>>B;
  int cnt1=0;
  for(int i=0;i<N;i++){
    if(A[i]=='1')cnt1++;
    if(B[i]=='1')cnt1--;
  }
  if(cnt1!=0){
    cout<<"-1\n";
    return 0;
  }

  long long ans=0;
  for(int i=0,cnt1move=0,cntA1=0,cntA0=0,lastA1=-1;i<N;i++){
    if(B[i]=='1'&&A[i]=='0'){
      if(lastA1<i-1){
        lastA1=i-1;
      }
      if(cntA1<i){
        cntA1=i;
      }

      while(A[cntA1]=='0')cntA1++;
      ans+=cntA1-lastA1-1;
      lastA1=cntA1;
      swap(A[i],A[cntA1]);
      cntA1++;
    }else if(B[i]=='0'&&A[i]=='1'){
      if(cntA0<i){
        cntA0=i;
      }
      ans++;
      while(A[cntA0]=='1')cntA0++;
      swap(A[i],A[cntA0]);
      cntA0++;

    }

  }

  cout<<ans<<'\n';
}

#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
#include <iomanip>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
  int N;

  vector<int> V(2510);
  int count=0;
  for(int i=1;i<10000;i++){
    if(i%6==0 || i%10==0 || i%15==0){
      V[count]=i;
      count++;
    }
  }
  cin>>N;
  for(int i=1;i<N+1;i++) cout<<V[i]<<" ";

return 0;}


#include <bits/stdc++.h>

using namespace std;
const int c=5002;
long long n, m, sum, mod=998244353;
long long po[c][c];
int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n >> m;
    for (int i=0; i<=m; i++) {
        po[i][0]=1;
    }
    for (int i=0; i<=m; i++) {
        for (int j=1; j<=n; j++) {
            po[i][j]=po[i][j-1]*i%mod;
        }
    }
    sum=po[m][n]*n%mod;
    for (int i=1; i<n; i++) {
        for (int j=1; j<=m; j++) {
            sum-=(n-i)*po[m][n-i-1]%mod*po[m-j][i-1]%mod;
        }
    }
    sum%=mod;
    if (sum<0) {
        sum+=mod;
    }
    cout << sum << "\n";
    return 0;
}

#include <bits/stdc++.h>

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

const int MAXN = 5000+5;
const int ha = 998244353;
int n,m;

inline void add(int &x,int y){
    x += y-ha;x += x>>31&ha;
}

int pw[MAXN],pw1[MAXN];

int main(){
    scanf("%d%d",&n,&m);
    if(m == 1){
        puts("1");
        return 0;
    }
    pw[0] = 1;FOR(i,1,MAXN-1) pw[i] = 1ll*pw[i-1]*m%ha;
    pw1[0] = 1;FOR(i,1,MAXN-1) pw1[i] = 1ll*pw1[i-1]*(m-1)%ha;
    int ans = 0;
    FOR(x,2,m){
        int c = 1;
        FOR(k,2,n-1){
            c = 1ll*c*(m-x)%ha;
            int d = (pw1[k-1]+ha-c)%ha;
            add(ans,1ll*d*(n-k)%ha*pw[n-(k+1)]%ha);
        }
    }
    FOR(i,1,n) add(ans,1ll*pw1[i-1]*pw[n-i+1]%ha);
    printf("%d\n",ans);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr int maxn = 200000 + 1;
void no(){
    cout << -1;
    exit(0);
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int N, M;
    cin >> N >> M;
    if(M < 0) no();
    if(M == 0){
        for(int i = 1; i <= N; i += 1) cout << i * 10 << " " << i * 10 + 1 << "\n";
        return 0;
    }
    if(M > N - 2) no();
    for(int i = 1; i < N; i += 1) cout << i * 10 << " " << i * 10 + 1 << "\n";
    cout << "1 " << (M + 1) * 10 + 2 << "\n";
    return 0;
}

#include<bits/stdc++.h>
#define pb emplace_back
#define AI(i) begin(i), end(i)
using namespace std;
using ll = long long;
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() {cerr << endl;}
template<class T1, class ...T2>
void kout (T1 v, T2 ...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
const int MAX_N = 300010;
int n, m;
int l[MAX_N], r[MAX_N];
int tak() {
	vector<pair<int,int>> a;
	for (int i = 1;i <= n;++i)
		a.pb(l[i], r[i]);
	sort(AI(a), [&](auto x, auto y) {
			return x.second < y.second;
			});
	int len = 0;
	int cur = -1;
	for (auto [l, r] : a)
		if (l > cur) ++len, cur = r;
	return len;
}
int aok() {
	vector<pair<int,int>> a;
	for (int i = 1;i <= n;++i)
		a.pb(l[i], r[i]);
	sort(AI(a));
	int len = 0;
	int cur = -1;
	for (auto [l, r] : a)
		if (l > cur) ++len, cur = r;
	return len;
}
void construct(int n, int m) {
	for (int i = 1;i <= n;++i)
		l[i] = 4 * i+1, r[i] = l[i] + 2;
	r[1] = r[m+2]+1;
	for (int i = 1;i <= n;++i) {
		cout << l[i] << ' ' << r[i] << '\n';
		assert(l[i] < r[i]);
		assert(l[i] >= 1 && r[i] <= 1000000000);
	}
	set<int> v;
	for (int i = 1;i <= n;++i)
		v.insert(l[i]), v.insert(r[i]);
	assert(v.size() == n*2);
	assert(tak() - aok() == m);
}
signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n >> m;
	if (n == 1 && m == 0) {
		cout << 1 << ' ' << 2 << '\n';
		return 0;
	}
	if (m < 0 || m > n-2)
		return puts("-1"), 0;
	construct(n, m);
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define length size()
#define int long long
#define ll long long
const int MOD = 1000000007;
const int MAX = 510000;
template<typename T> string join(vector<T> &vec ,const string &sp){
    int si = vec.length;
    if(si==0){
        return "";
    }else{
        stringstream ss;
        rep(i,si-1){
            ss << vec[i] << sp;
        }
        ss << vec[si - 1];
        return ss.str();
    }
}
signed main(void){
    int h,w;
    cin >> h >> w;
    vector<vector<char>> vec(h+1,vector<char>(w+1,'#'));
    int sum = 0;
    rep(i,h){
        rep(j,w){
            cin >> vec[i][j];
        }
    }
    rep(i,h){
        rep(j,w){
            if(vec[i][j]=='.'){
                if(vec[i][j+1]=='.') sum++;
                if(vec[i+1][j]=='.') sum++;
            }
        }
    }
    cout << sum << endl;
}

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

#define endl "\n"
#define int long long int
#define mod 1000000007
#define vi vector<int>
#define pint pair<int,int>
#define vint vector<vector<int>>
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

const int N = 1e6+5;
int A[N], B[N], P[N], Q[N][3], D[N][3];
string S[105];

int mat[5005][5005];
pint edges[N];
unordered_map<int, set<int>> m;

bool compare(vi a, vi b)
{
    return a[0] < b[0];
}

int lcm(int a, int b)
{
    return (a*b)/(__gcd(a,b));
}

int mypow(int a, int x)
{
    if(a<=1 || x==1) return a;
    if(x==0) return 1;

    int temp = mypow(a,x/2);
    if(x%2==0) return ((temp%mod) * (temp%mod))%mod;
    else return (a%mod * ((temp%mod) * (temp%mod))%mod)%mod;
}

int count_bits(int n)
{
    int cnt = 0;
    while(n)
    {
        n = n & (n-1);
        cnt++;
    }return cnt;
}

void bfs(int src, int n)
{
    unordered_map<int, bool> visited;
    for(int i=0;i<n;i++) visited[i] = false;
    queue<int> q;
    q.push(src);
    visited[src] = true;

    while(!q.empty())
    {
        int curr = q.front();
        q.pop();
        B[curr] -= min(B[curr], A[src]);
        //cout<<curr<<" "<<endl;

        for(auto neigh: m[curr])
        {
            if(visited[neigh] == false)
            {
                //cout<<neigh<<endl;
                q.push(neigh);
                visited[neigh] = true;
                m[src].erase(neigh);
                m[neigh].erase(src);
            }
        }
    }
}

int length_of_lis(int n)
{
    if(n<=1) return n;
    vector<int> res;

    res.push_back(A[0]);
    int i;

    for(i=1;i<n;i++)
    {
        if(A[i] > res.back()) res.push_back(A[i]);
        else
        {
            int index = lower_bound(res.begin(), res.end(), A[i]) - res.begin();
            res[index] = A[i];
        }
    }return res.size();
}

int solve(int h, int w)
{
    int i,j,k;
    int ans = 0;

    for(i=0;i<h;i++)
    {
        for(j=0;j<w-1;j++)
        {
            if(S[i][j] == '.' && S[i][j+1] == '.')
                ans++;
        }
    }

    for(i=0;i<w;i++)
    {
        for(j=0;j<h-1;j++)
        {
            if(S[j][i] == '.' && S[j+1][i] == '.')
                ans++;
        }
    }
    return ans;
}

int32_t main()
{
    //code
	IOS;

    int t,n,m,a,b,x,y,i,j,z;
    //cin>>t;
    t = 1;
    while(t--)
    {
        int h,w;
        cin>>h>>w;
        for(i=0;i<h;i++)
            cin>>S[i];
        cout<<solve(h,w)<<endl;
    }

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
//#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch GameInMomotetsuWorld | diff GameInMomotetsuWorld.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address GameInMomotetsuWorld.cpp && ./a.out

/*

 5/16/2021

 11:16-12:13

 */

const int MAX_N=2000+10;
string A[MAX_N];
int N,M;

const int Inf=1e8;
II memo[MAX_N][MAX_N];

II f(int i, int j) {
  //if(i>=N) return (j<M-1?make_pair(-Inf,-Inf):make_pair(0,0));
  //if(j>=M) return (i<N-1?make_pair(-Inf,-Inf):make_pair(0,0));
  //if(i>=N||j>=M) return {-Inf,-Inf};
  //if(i==N-1&&j==M-1) return {0,0};
  if(memo[i][j].first!=-Inf) return memo[i][j];
  II &res=memo[i][j];

  vector<II> xs;

  REP(di,2)REP(dj,2)if(di+dj==1) {
    int ii=i+di,jj=j+dj;
    if(ii>=N||jj>=M) continue;
    auto x=f(ii,jj);
    swap(x.first,x.second);
    int d=(A[ii][jj]=='+')?1:-1;
    x.first+=d;
    xs.push_back(x);
  }

  if(SZ(xs)==0) {
    assert(i==N-1&&j==M-1);
    return {0,0};
  }
  if(SZ(xs)==1) return res=xs[0];

  if(xs[0].first-xs[0].second>xs[1].first-xs[1].second) {
    res=xs[0];
  } else {
    res=xs[1];
  }

/*
  if(xs[0].first!=xs[1].first) {
    res=xs[0].first>xs[1].first?xs[0]:xs[1];
  } else {
    res=xs[0].second<xs[1].second?xs[0]:xs[1];
  }*/
  dump(i,j,res.first,res.second);
  return res;
}

void solve() {
  REP(i,N)REP(j,M) memo[i][j]={-Inf,-Inf};
  II res=f(0,0);
  dump(res.first, res.second);
  string ans="Draw";
  if(res.first>res.second) ans="Takahashi";
  else if(res.first<res.second) ans="Aoki";
  cout<<ans<<endl;
}

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

  cin>>N>>M;
  REP(i,N) cin>>A[i];
  solve();

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define d(x) cout<<x<<" "
#define nl cout<<endl
#define rep(var,init_val,final_val) for(int var = init_val; var < final_val; ++var)
#define tt ll t;cin>>t;while(t--)
#define show(a,b) rep(i,0,b) d(a[i]);nl;
#define vi std::vector<int>
#define pi pair<int,int>
#define mod 1000000007
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
	ll n , y;
	cin>>n>>y;
	ll maxp,minp,maxn,minn;
	ll ans = 0;
	if(n>0){
		maxp=(n+(y-2)/2);
		minp=(n-y/2);
		maxn=-(n-(y-1)/2);
		minn=-(n+(y-1)/2);

		if(maxn>=minp) ans = maxp-minn+1;
		else ans = maxp-minp+maxn-minn+2;

	}
	else if(n<0){
		maxp=-(n-(y-1)/2);
		minp=-(n+(y-1)/2);
		minn=(n-y/2);
		maxn=(n+(y-2)/2);

		if(maxn>=minp) ans = maxp-minn+1;
		else ans = maxp-minp+maxn-minn+2;
	}
	else{
		maxp=(y-1)/2;
		minp=-y/2;

		ans=maxp-minp+1;
	}
	cout<<ans<<endl;
    return 0;
}


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

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

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

int h, w;
int bcj[2][1010];
vector<int> row[1001], col[1001];

int fd(cint x, bool st) {
    return bcj[st][x] == x ? x : bcj[st][x] = fd(bcj[st][x], st);
}

int main() {
    int s = -1, ss = -1;
    cin >> h >> w;
    char a;
    for(int i=1; i<=h; i++) bcj[0][i] = i;
    for(int i=1; i<=w; i++) bcj[1][i] = i;
    bcj[1][w] = 1; bcj[0][h] = 1;
    for(int i=1; i<=h; i++)
        for(int j=1; j<=w; j++) {
            cin >> a;
            if(a == '#') {
                row[i].push_back(j);
                col[j].push_back(i);
                if(i == 1 || i == h) bcj[1][fd(bcj[1][j], 1)] = fd(bcj[1][1], 1);
                if(j == 1 || j == w) bcj[0][fd(bcj[0][i], 0)] = fd(bcj[0][1], 0);
            }
        }
    int a1, a2;
    for(int i=1; i<=h; i++) {
        for(int j=0; j<(int)row[i].size()-1; j++) {
            a1 = row[i][j], a2 = row[i][j+1];
            bcj[1][fd(bcj[1][a1], 1)] = fd(bcj[1][a2], 1);
        }
    }
    for(int i=1; i<=w; i++) {
        for(int j=0; j<(int)col[i].size()-1; j++) {
            // cout << j << '-' << (int)col[i].size() << ' ' << i << endl;
            a1 = col[i][j], a2 = col[i][j+1];
            bcj[0][fd(bcj[0][a1], 0)] = fd(bcj[0][a2], 0);
        }
    }
    int tmp = 0;
    for(int i=1; i<=w; i++)
        if(bcj[1][i] == i) ++tmp;
    int tmp1 = 0;
    for(int i=1; i<=h; i++)
        if(bcj[0][i] == i) ++tmp1;
    // cout << tmp << ' ' << tmp1 << endl;
    cout << min(tmp1, tmp) - 1 << endl;
    return 0;
}
/*
5 9
.........
.#######.
.........
.........
.........
*/

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

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

const int SZ = 2010;
class UF {
public:
	int P[SZ + 1];
	UF() : P() {
		rep1(i, SZ) P[i] = -1;
	}
	int find(int A) {
		if (P[A] < 0) return A;
		return P[A] = find(P[A]);
	}
	bool unite(int A, int B) {
		int a = find(A);
		int b = find(B);
		if (a == b) return false;
		if (P[a] > P[b]) swap(a, b);
		P[a] += P[b];
		P[b] = a;
		return true;
	}

} uf;

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

	int H, W;
	cin >> H >> W;

	uf.unite(1, 1001);
	uf.unite(1, W + 1000);
	uf.unite(H, 1001);
	uf.unite(H, W + 1000);

	rep1(i, H) {
		string S;
		cin >> S;
		rep(j, W) {
			if (S[j] == '#') {
				uf.unite(i, j + 1001);
			}
		}
	}

	int kotae = 1000;

	unordered_set<int> ST;
	rep1(i, H) {
		ST.insert(uf.find(i));
	}
	kotae = ST.size() - 1;
	ST.clear();
	rep1(j, W) {
		ST.insert(uf.find(j + 1000));
	}
	chmin(kotae, int(ST.size()) - 1);

	co(kotae);

	Would you please return 0;
}


#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
const vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T>void debag(const vector<T> &a){cerr<<"debag :";for(auto v:a)cerr<<v<<" ";cerr<<"\n";}
template<class T>void print(const vector<T> &a){for(auto v:a)cout<<v<<" ";cout<<"\n";}
struct mint{
using ull=unsigned long long int;
ull v;
mint(ll vv=0){s(vv%mod+mod);}
mint& s(ull vv){
v=vv<mod?vv:vv-mod;
return *this;
}
//オーバーロード
mint operator-()const{return mint()-*this;}//mint型にキャスト
mint&operator+=(const mint&val){return s(v+val.v);}
mint&operator-=(const mint&val){return s(v+mod-val.v);}
mint&operator*=(const mint&val){
v=ull(v)*val.v%mod;
return *this;
}
mint&operator/=(const mint&val){return *this*=val.inv();}
mint operator+(const mint&val){return mint(*this)+=val;}
mint operator-(const mint&val){return mint(*this)-=val;}
mint operator*(const mint&val){return mint(*this)*=val;}
mint operator/(const mint&val){return mint(*this)/=val;}
mint pow(ll n)const{
mint res(1),x(*this);
while(n){
if(n&1)res*=x;
x*=x;
n>>=1ll;
}
return res;
}
mint inv()const{return pow(mod-2);}
//拡張ユークリッドの互除法
/* mint inv()const{
int x,y;
int g=extgcd(v,mod,x,y);
assert(g==1);
if(x<0)x+=mod;
return mint(x);
}*/
friend ostream& operator<<(ostream&os,const mint&val){
return os<<val.v;
}//出力
bool operator<(const mint&val)const{return v<val.v;}
bool operator==(const mint&val)const{return v==val.v;}
bool operator>(const mint&val)const{return v>val.v;}
};
const ll MAX = 2000010;//設定
mint fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void init(){
fac[0] = fac[1] = 1;
for(int i=1;i<MAX;i++)fac[i]=fac[i-1]*i;
finv[MAX-1]=fac[MAX-1].inv();
for(int i=MAX-2;i>=0;i--)finv[i]=finv[i+1]*(i+1);
for(int i=MAX-2;i>=1;i--)inv[i]=finv[i]+fac[i-1];
}
//階乗
mint factor(ll n,ll k){
if (n<k) return 0;
if (n<0 || k<0) return 0;
return fac[n]*finv[k];
}
// 二項係数計算
mint 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];
}
mint dp[200005][17][17]={};
int main(){
  init();
  string s;
  cin>>s;
  int k;
  cin>>k;
  int n=s.size();
  V<int> a(n);
  map<char,int> mp;
  for(char c='0';c<='9';c++){
        mp[c]=int(c-'0');
  }
  for(char c='A';c<='F';c++){
        mp[c]=int(c-'A')+10;
  }
  for(int i=0;i<n;i++){
        a[i]=mp[s[i]];
  }
  for(int i=1;i<=k;i++)dp[0][i][0]=mint(1); //すでにi個決まっている
  for(int i=0;i<n;i++){
        for(int j=0;j<=k;j++){
            for(int r=0;r<=k;r++){
                    dp[i+1][j][r+1]+=dp[i][j][r]*mint(16-j-r);
                    dp[i+1][j][r]+=dp[i][j][r]*mint(j+r);
            }
        }
  }
  ll v=0;
  mint ans=mint(0);
  for(int i=0;i<n;i++){
         if(__builtin_popcount(v)<=k){
            for(int j=(i==0?1:0);j<a[i];j++){
                  ll c=(v|(1ll<<j));
                  int num=__builtin_popcount(c);
                  if(num>k)continue;
                  ans+=dp[n-i-1][num][k-num];
            }
         }
        if(i!=0){
          ans+=dp[n-i-1][1][k-1]*mint(15);
        }
        v|=(1ll<<a[i]);
  }
  set<int> st;
  for(int i=0;i<n;i++)st.insert(a[i]);
  if(int(st.size())==k)ans+=mint(1);
  cout<<ans<<"\n";
}

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

int main(){
    int N,M;
    cin >> N >> M;
    int A[N];
    vector<int> candidate,cnt(N+1);
    for(int i = 0;i < N;i++){
        cin >> A[i];
    }
    set<int> x;
    for(int i = 0;i <= N;i++){
        x.insert(i);
    }
    for(int i = 0;i < M;i++){
        x.erase(A[i]);
        cnt.at(A[i])++;
    }
    for(int i = 0;i < N - M;i++){
        candidate.push_back(*x.begin());
        cnt.at(A[i])--;
        cnt.at(A[i+M])++;
        if(cnt.at(A[i]) == 0) x.insert(A[i]);
        x.erase(A[i+M]);
    }
    candidate.push_back(*x.begin());
    sort(candidate.begin(),candidate.end());
    cout << candidate.at(0) << endl;
}


#include <bits/stdc++.h>
#define arr array
#define pb push_back
#define fs first
#define sc second
#define eb emplace_back
#define vt vector
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

using namespace std;
typedef long long ll;
const int maxn=2e5;
const int MAXINT=1e9;
const ll MAXLL=1e18;

void solve(){
    int n;
    cin >> n;
    n*=2;
    vt<arr<int, 3>> a(n);
    rep(i, 0, n) cin >> a[i][0], a[i][1]=i;
    sort(a.begin(), a.end(), [&](arr<int, 3> x, arr<int, 3> y){
        return x[0]<y[0];
    });
    rep(i, 0, n/2) a[i][2]=1;
    rep(i, n/2, n) a[i][2]=0;
    sort(a.begin(), a.end(), [&](arr<int, 3> x, arr<int, 3> y){
        return x[1]<y[1];
    });

    //rep(i, 0, n) cout << a[i][2] << " "; cout << endl;
    vt<int> st;
    vt<char> ans(n);
    rep(i, 0, n){
        if (!st.empty()&&a[i][2]!=a[st.back()][2]) ans[st.back()]='(', ans[i]=')', st.pop_back();
        else st.pb(i);
    }
    rep(i, 0, n) cout << ans[i]; cout << endl;
}

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

#include<bits/stdc++.h>
#define For(i,a,b) for(register int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(register int i=(a);i>=(b);--i)
#define int long long
using namespace std;
inline int read()
{
    char c=getchar();int x=0;bool f=0;
    for(;!isdigit(c);c=getchar())f^=!(c^45);
    for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
    if(f)x=-x;return x;
}

#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;

#define mod 998244353
struct modint{
    int x;
    modint(int o=0){x=o;}
    modint &operator = (int o){return x=o,*this;}
    modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
    modint &operator -=(modint o){return x=x-o.x<0?x-o.x+mod:x-o.x,*this;}
    modint &operator *=(modint o){return x=1ll*x*o.x%mod,*this;}
    modint &operator ^=(int b){
        modint a=*this,c=1;
        for(;b;b>>=1,a*=a)if(b&1)c*=a;
        return x=c.x,*this;
    }
    modint &operator /=(modint o){return *this *=o^=mod-2;}
    modint &operator +=(int o){return x=x+o>=mod?x+o-mod:x+o,*this;}
    modint &operator -=(int o){return x=x-o<0?x-o+mod:x-o,*this;}
    modint &operator *=(int o){return x=1ll*x*o%mod,*this;}
    modint &operator /=(int o){return *this *= ((modint(o))^=mod-2);}
    template<class I>friend modint operator +(modint a,I b){return a+=b;}
    template<class I>friend modint operator -(modint a,I b){return a-=b;}
    template<class I>friend modint operator *(modint a,I b){return a*=b;}
    template<class I>friend modint operator /(modint a,I b){return a/=b;}
    friend modint operator ^(modint a,int b){return a^=b;}
    friend bool operator ==(modint a,int b){return a.x==b;}
    friend bool operator !=(modint a,int b){return a.x!=b;}
    bool operator ! () {return !x;}
    modint operator - () {return x?mod-x:0;}
};

#define maxn 500005
int n,a[maxn],id[maxn],col[maxn];
bool cmp(int x,int y){
	return a[x]<a[y];
}
queue< pii >q;
bool vis[maxn];
int pre[maxn],nxt[maxn];
char s[maxn];
void print(){
	For(i,1,n)if(!vis[i])cout<<a[i]<<' ';
}
signed main()
{
	n=read()*2;
	For(i,1,n)a[i]=read(),id[i]=i;
	For(i,1,n-1)nxt[i]=i+1;
	For(i,2,n)pre[i]=i-1;
	sort(id+1,id+n+1,cmp);
	For(i,n/2+1,n)col[id[i]]=1;
	For(i,1,n-1)
		if(col[i]!=col[i+1])q.push(mkp(i,i+1));
	int orz=0;
	while(!q.empty()){
		pii t=q.front();q.pop();
		int u=t.fi,v=t.se;
		if(vis[u]||vis[v])continue;
		vis[u]=vis[v]=1;
	//	++orz,cout<<orz<<" "<<u<<' '<<v<<endl;
	//	print();
		s[u]='(',s[v]=')';
		int uu=pre[u],vv=nxt[v];
		if(uu&&vv&&col[uu]!=col[vv]) q.push(mkp(uu,vv));
		nxt[pre[u]]=nxt[v];
		pre[nxt[v]]=pre[u];
		pre[u]=pre[v]=nxt[u]=nxt[v]=0;
	}
	For(i,1,n)if(!s[i])return -1;
	cout<<s+1;
	return 0;
}


#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;   typedef pair<int,int>pint;  typedef long double ld;
using vll=vector<ll>;   using vs=vector<string>;
#define b2e(v)v.begin(),v.end()
#define p2a(v, p) v[p.first][p.second]

class var { public: ll min,max,ct,sum,dif,result; };
int main() {
    ll n;
    cin>>n;
    vector<pint> v;

    const int INF=0x3f3f3f3f;
    const ll INFL=0x3f3f3f3f3f3f3f3f;
    pint lmax={INF,INF},idx={0,0};
    rep(i,n) {
        ll a,b;
        cin >> a >> b;
        if (lmax.first > a) { lmax.first=a; idx.first=i; }
        if (lmax.second > b) { lmax.second=b; idx.second=i; }
        v.push_back({a,b});
    }

    pint lmax2={INF,INF};
    rep(i,n) {
        ll a=v[i].first,b=v[i].second;
        if (idx.first!=i && lmax2.first > a) { lmax2.first=a; }
        if (idx.second!=i && lmax2.second > b) { lmax2.second=b; }
    }
    ll result = min(max(lmax.first,lmax2.second),max(lmax2.first,lmax.second));
    if (idx.first!=idx.second) {
        result = max(lmax.first, lmax.second);
    } else {
        result = min(lmax.first+lmax.second, min(max(lmax.first,lmax2.second), max(lmax2.first,lmax.second)));
    }
    cout << result << endl;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

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

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

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

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

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

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

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

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

    template<typename T, typename V>
    void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
    template<typename T>
    void __print(const T &x) {int f = 0; cerr << '{'; for(auto z : x) cerr << (f++ ? "," : ""), __print(z); cerr << "}";}
    void _print() {cerr << "]\n";}
    template <typename T, typename... V>
    void _print(T t, V... v) {__print(t); if(sizeof...(v)) cerr << ", "; _print(v...);}

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

using namespace debug;

const char nl = '\n';

void solve() {
    int n;
    cin >> n;
    vpii v(n);
    for(auto &[a, b] : v)
        cin >> a >> b;

    int ans = 1e9;
    for(auto [a, b] : v) {
        ckmin(ans, a + b);
    }

    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < n; ++j) {
            if(i == j)
                continue;
            ckmin(ans, max(v[i].fi, v[j].se));
        }
    }

    cout << ans << nl;
}

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

#ifdef ljuba
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif

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

}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define ln cout<<'\n'
void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<' ';pr(b...);}
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;}

bool temp[2010];
vector<vector<int>> to;

void dfs(int a) {
	if (temp[a]) return;
	temp[a] = true;
	for (auto v:to[a]) dfs(v);
}

void solve() {
	int n , m; cin >> n >> m;
	to.resize(n);
	rep(i, m) {
		int a, b; cin >> a >> b;
		to[a-1].push_back(b-1);
	}
	int ans = 0;
	rep(i, n) {
		rep(i, n) temp[i] = false;
		dfs(i);
		rep(i, n) if (temp[i]) ++ans;
	}
	cout << ans << endl;
}

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

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    int n,m;
  	int vdnsddglkdk;
    cin>>n>>m;
    vector<pair<int,int>>a(m);
    for(int i=0;i<m;i++)
    {
        cin>>a[i].first>>a[i].second;
    }
    int k;
    cin>>k;
    vector<pair<int,int>>b(k);
    for(int j=0;j<k;j++)
    {
        cin>>b[j].first>>b[j].second;
    }
    ll l=0;
    ll tot=1<<k;
    for(ll mask=0;mask<tot;mask++)
    {
        vector<int>v(n+1);
        ll ans=0;
        for(int i=0;i<k;i++)
        {
            if(mask & (1<<i))
                v[b[i].second]=1;
            else
                v[b[i].first]=1;
        }
        for(int i=0;i<m;i++)
        {
            if(v[a[i].first] && v[a[i].second])
                ans++;
        }
        l=max(l,ans);
    }
    cout<<l<<endl;
    return 0;
}


/*
  AUTHOR:SOURABH
  CREATED:10:10:20
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ordered_set tree<ll , null_type, less< ll >, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define W while
#define fn(i,x) for(i=0;i<x;i++)
#define fs(i,s,x) for(i=s;i<x;i++)
#define fr(i,x) for(i=x;i>=0;i--)
#define fit(it,s) for(it=s.begin();it!=s.end();it++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define mod 998244353
#define MAXN 10000001
#define M 32

using namespace std;
using namespace __gnu_pbds;

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

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

    ll t;
    char s,tt;
    t=1;
    //cin>>t;
    W(t--)
    {
        cin>>s>>tt;
        if(s=='Y')
            cout<<char(tt-32);
        else
            cout<<tt;
    }
    return 0;
}

#pragma GCC optimize("Ofast")
#pragma GCC optimization("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define deb(x) cout << #x << " " << x << endl;
#define mod 1000000007
#define fast std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define rall(v) v.rbegin(), v.rend()
const ll INF = 1e18;
//const ll NEGINF = -1 * INF;

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

ll my_pow(ll a, ll n, ll m = INF)
{
    ll res = 1;
    while (n)
    {
        if (n % 2)
        {
            res = (res * a) % m;
            n--;
        }
        a = (a * a) % m;
        n /= 2;
    }
    return res;
}

#define double long double

const int N = 2e5 + 5;

//g(i) = a*x+b;

double a[N];
double b[N];
bool bad[N];

void solve()
{
    ll n, m, k;
    cin >> n >> m >> k;

    ll pt;
    for (int i = 0; i < k; i++)
    {
        cin >> pt;
        bad[pt] = true;
    }
    double c = 0;
    double v = 0;
    double sum = 0;

    for (int i = n - 1; i >= 0; i--)
    {
        if (bad[i])
        {
            a[i] = 1.0;
            b[i] = 0;
        }
        else
        {
            a[i] = (double)c / m;
            b[i] = (double)v / m + 1;
        }
        sum += bad[i] - bad[i + m];
        if (sum == m)
        {
            cout << -1 << endl;
            return;
        }
        c += a[i] - a[i + m];
        v += b[i] - b[i + m];
    }

    cout << fixed << setprecision(10) << b[0] / (1 - a[0]) << endl;
}

int main()
{
    fast;
#ifndef ONLINE_JUDGE
    freopen("/home/kalit/Desktop/Data Structures-Algo-Competitive/src/codeforces/input.txt", "r", stdin);
    freopen("/home/kalit/Desktop/Data Structures-Algo-Competitive/src/codeforces/output.txt", "w", stdout);
#endif
    int T = 1;
    while (T--)
    {
        solve();
    }
    //cout<< "Done in " << clock() / CLOCKS_PER_SEC <<"sec"<< endl;
    return 0;
}


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

const int inf = 1e8;
const ll llinf = 1e18;
const double PI = acos(-1);
#define yes "Yes"
#define no "No"
#define all(n) n.begin(), n.end()

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

struct UnionFind {
  vector<int> par, siz;
  UnionFind(int n) : par(n, -1), siz(n, 1) {}
  int root(int x) {
    if (par[x] == -1) return x;
    return par[x] = root(par[x]);
  }
  bool isSame(int x, int y) { return root(x) == root(y); }
  bool unite(int x, int y) {
    x = root(x), y = root(y);
    if (x == y) return false;
    if (siz[x] < siz[y]) swap(x, y);
    par[y] = x;
    siz[x] += siz[y];
    return true;
  }
  int size(int x) { return siz[root(x)]; }
};

using Graph = vector<vector<int>>;
vector<int> visited(false);

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

void dfs(const Graph &G, int v) {
  visited[v] = true;
  for (auto next : G[v]) {
    if (visited[next]) continue;
    dfs(G, next);
  }
}

bool isPrime(ll n) {
  if (n < 2) return false;
  for (ll i = 2; i * i <= n; ++i)
    if (n % i == 0) return false;
  return true;
}

// 最大公約数
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

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

ll gcd2(const vector<ll> &v) {
  ll val = v[0];
  for (ll i = 1; i < v.size(); ++i) val = gcd(val, v[i]);
  return val;
}

ll lcm2(const vector<ll> &v) {
  ll val = v[0];
  for (ll i = 1; i < v.size(); ++i) val = lcm(val, v[i]);
  return val;
}

vector<ll> divisors(ll n) {
  vector<ll> a;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      a.push_back(i);
      if (n / i != i) a.push_back(n / i);
    }
  }
  sort(a.begin(), a.end());
  return a;
}

// pairを要素に持つvectorをsecondを基準にソートする比較関数
bool comp(pair<ll, ll> a, pair<ll, ll> b) { return a.second < b.second; }

vector<int> eratosthenes(int n) {
  vector<bool> is_prime(n + 1, true);
  vector<int> p;
  for (int i = 2; i <= n; ++i) {
    if (is_prime[i]) {
      for (int j = i * 2; j <= n; j += i) {
        is_prime[j] = false;
      }
      p.push_back(i);
    }
  }
  return p;
}

int main() {
  double n, d, h;
  cin >> n >> d >> h;
  double ans = 0;

  rep(i, n) {
    double dn, hn;
    cin >> dn >> hn;
    double a = (h - hn) / (d - dn);
    double b = h - a * d;
    ans = max(ans, b);
  }

    cout << fixed << setprecision(9) << ans << endl;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
using ll = long long int;
using iPair = pair<int,int>;
using lPair = pair<ll, ll>;
using ivector = vector<int>;
using lvector = vector<ll>;
using istack = stack<int>;
using iqueue = queue<int>;
using ivv = vector<vector<int>>;
using lvv = vector<vector<ll>>;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
vector<iPair> dir = {{1,0}, {-1,0}, {0,1}, {0,-1}};
#define dump(x) cout << #x << " = " << (x) << endl
#define ALL(x) begin(x),end(x)
#define rep(i,s,e) for(ll i=(s); i<(ll)(e); ++i)
#define repRev(i,s,e) for(ll i=(e-1); i>=(ll)(s); --i)
#define range(i,s,n) for(ll i=(s), i_stop=(s)+(n); i<i_stop; ++i)
#define rangeRev(i,s,n) for(ll i=(s), i_stop=(s)-(n); i>i_stop; --i)
#define foreach(x,container) for(auto &&x:container)
bool chmax(ll& a, ll b) {if(a<b) {a=b;return true;} return false;}
bool chmin(ll& a, ll b) {if(a>b) {a=b;return true;} return false;}
template<typename T> void printArr(vector<T> &arr){
    for(auto &&x:arr) {cout << x << " ";} cout << endl;
}

/*

## 關鍵詞：
二分，二維前綴和，中值

## 題意：
給定長寬爲N的正方形，求所有K*K的正方形區域中中值的最小值。
1 <= K <= N <= 800。
中值定義: K*K方塊中，第 (K*K/2)+1 大的數值。

## 思路：
題解：https://atcoder.jp/contests/abc203/editorial/1955
將問題轉化爲求「對於任意X，判斷是否存在一個K*K區域使得該區域的中值小於等於X」。
然後二分去尋找滿足條件的最小X。
「存在一個K*K區域使得該區域的中值小於等於X」
等價於
「存在一個K*K區域，其中大於X的方塊數量小於(K*K/2)+1」，證明很簡單。
判斷某個X是否滿足條件時，花費O(N^2)生成前綴和，然後可以在O(1)判斷K*K中大於X的方塊數量。
總的復雜度是O(max(A_i)N^2)

## 雜多：

*/

ll n,k;
ll A[810][810];
ll s[810][810];

bool check(ll x) {
    range(i, 0, n) range(j, 0, n) {
        s[i+1][j+1] = s[i+1][j] + s[i][j+1] - s[i][j];
        if(A[i][j] > x) ++s[i+1][j+1];
    }

    ll thres = k*k/2+1;
    for(int i=0; i+k<=n; ++i) for(int j=0; j+k<=n; ++j) {
        ll cnt = s[i+k][j+k];
        cnt -= s[i+k][j] + s[i][j+k];
        cnt += s[i][j];
        if(cnt < thres) return true;
    }
    return false;
}

void solve(){
    cin>>n>>k;
    range(i, 0, n) range(j, 0, n) cin>>A[i][j];
    range(i, 0, k) {
        s[i][0] = 0;
        s[0][i] = 0;
    }

    ll l = 0, r = 1000000001;
    while(l<r) {
        ll mid = l + (r-l) / 2;
        if(!check(mid)) l = mid+1;
        else r = mid;
    }
    cout << l << endl;
}

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


#include <bits/stdc++.h>
using namespace std;
#define ll long long
void solve(){
	ll n;
	cin>>n;
	if(n==2) {
		cout<<1;
		return;
	}
	ll i=1LL;
	while(((i*(i+1))/2)<=(n+1))
	i++;
	ll res=  n-(i-1)+1;
	cout<<res;

}
int main() {
	solve();
	// your code goes here
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  int mx = 1, th = 2;

  rep(i,n){
    if(i+1 == th){
      mx++;
      th *= 2;
    }
    cout << mx << " ";
  }
  cout << endl;
  return 0;
}


#include<cstdio>
#include<algorithm>
typedef long long ll;
ll ans[2000005];
inline ll read() {
	register ll x=0,f=1;register char s=getchar();
	while(s>'9'||s<'0') {if(s=='-') f=-1;s=getchar();}
	while(s>='0'&&s<='9') {x=x*10+s-'0';s=getchar();}
	return x*f;
}
int main() {
	ll n=read(); int cnt=0;
	for(register ll i=1;i*i<=n;++i) {
		if(n%i==0) {
			ans[++cnt]=i;
			if(i!=n/i) ans[++cnt]=n/i;
		}
	}
	std::sort(ans+1,ans+1+cnt);
	for(register int i=1;i<=cnt;++i) printf("%lld\n",ans[i]);
	return 0;
}

#include <bits/stdc++.h>
#define M 1000000007
#define fio                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
#define d(x) cout << #x << " " << x << "\n";
#define ll long long int
#define ul unsigned long long int
#define p pair<int, int>
#define ld long double
#define inf INT_MAX
using namespace std;

int main()
{
    ld n;
    cin >> n;
    ld ans = 0.0;
    for (ld i = n - 1; i >= 1; --i)
    {
        ans += (n / i);
    }
    cout << setprecision(9)<<ans;
    return 0;
}


#include <iostream>
using namespace std;

typedef long long ll;

int main () {
	int x;
	cin >> x;
	cout << ((x>0)?x:0) << endl;
	return 0;
}

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
#include <set>

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

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

    if(x >= 0)cout << x << "\n";
    else cout << 0 << "\n";
}


// Keep it simple
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define Br cout<<endl
#define int long long
#define fe first
#define se second
#define double long double
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define PT(x) cout << (x) << endl
#define last(x)  prev(x.end())
#define PP(x) cout << (x) << " "
#define PS(x) for(auto it: x)cout << it <<" "; cout << endl;
#define PTT(x) cout << (#x) << " is " << (x) << endl
#define lets_go ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
void PV(vi v) { for (int i = 0 ; i < (int)v.size() ; i++) cout << v[i] << " " ; cout << endl;}
void PVV(vii v) {for (int i = 0 ; i < (int)v.size() ; i++) cout << v[i].first << " " << v[i].second << endl;}
void PA(int v[], int n, int x = 0) { for (int i = x ; i < n + x; i++)cout << v[i] << ' ' ; cout << endl;}
void IN(int a[], int n, int x = 0) {for (int i = x; i < n + x; i++)cin >> a[i];}
inline void op() {
#ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
#endif
}

// <=================================================================================================================================
// <=================================================================================================================================
const int M = 1e9 + 7;
const int IM = 1e18 + 37;
const int N = 2e5 + 10;

signed  main() {
   lets_go
   op();

   int n;
   cin >> n;
   set<int> s = {10, 6, 15};

   for (int i = 10; i <= 10000; i += 10) {
      if (s.size() == n)
         break ;
      s.insert(i);
   }
   for (int i = 6; i <= 10000; i += 6) {
      if (s.size() == n)
         break ;
      s.insert(i);
   }
   for (int i = 15; i <= 10000; i += 15) {
      if (s.size() == n)
         break ;
      s.insert(i);
   }
   PS(s);

   return 0;
}

#include <bits/stdc++.h>

using namespace std;

void solve() {
    string s;
    cin >> s;
    int ans = 0;
    for (int i = 0; i <= 9999; ++i) {
        set<char> have;
        int t = i;
        for (int j = 0; j < 4; ++j) {
            have.insert(t % 10);
            t /= 10;
        }
        int res = 1;
        for (int j = 0; j < s.size(); ++j) {
            if ((s[j] == 'o' && !have.count(j)) || (s[j] == 'x' && have.count(j))) {
                res = 0;
                break;
            }
        }
        ans += res;
    }
    cout << ans << "\n";
}

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


#include <bits/stdc++.h>
using namespace std;
#define END '\n'
#define int long long
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define bug(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, b, a) for(int i = (b); i > (a); --i)
const int inf = 1e18;
const int mod = 1e9+7;
const int mod1 = 998244353;
const int nax = 200005;
struct road
 {
  int v, t, k;
 };
int n, m, a, b, x, y, t, k;
vector<road> adj[nax];
int dp[nax];
void calc()
 {
  priority_queue<pii> q;
  q.push({0, x});
  while(!q.empty())
   {
    int time = -q.top().ff;
    int node = q.top().ss;
    q.pop();
    for(auto x : adj[node])
       {
        int div = (time + x.k - 1)/x.k;
        int tot = div*x.k + x.t;
        if(dp[x.v] > tot)
           {
            dp[x.v] = tot;
            q.push({-dp[x.v], x.v});
           }
       }
   }
 }
void solve()
 {
  cin>>n>>m>>x>>y;
  for(int i = 1; i <= n; i++)
     dp[i] = inf;
  dp[x] = 0;
  for(int i = 1; i <= m; i++)
     {
      cin>>a>>b>>t>>k;
      road A;
      A.v = b;
      A.t = t;
      A.k = k;
      adj[a].pb(A);
      A.v = a;
      adj[b].pb(A);
     }
  calc();
  if(dp[y] == inf)
     dp[y] = -1;
  cout<<dp[y];
 }
int32_t main()
 {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
   int t = 1;
   //cin>>t;
   while(t--)
     solve();
 // cerr<<END<<1.0*clock()/CLOCKS_PER_SEC;
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
const ll mod = 10e8 + 7;
const ll inf = (1LL << 60);

vector<ll> x(20), y(20), z(20);

ll c(int i, int j) {
    return abs(x[i] - x[j]) + abs(y[i] - y[j]) + max(0LL,z[j] - z[i]);
}

int main(){
    int n; cin >> n;
    rep(i,n) cin >> x[i] >> y[i] >> z[i];
    vector<vector<pair<ll,int>>> dp((1<<n),vector<pair<ll,int>>(n,make_pair(inf,-1)));
    rep(i,n) dp[(1<<i)][i] = make_pair(c(i,0),i);
    rep(i,(1<<n)){
        bitset<20> s(i);
        rep(j,n){
            if(s.test(j)) continue;
            rep(k,n){
                if(!s.test(k)) continue;
                ll x, y, z, w;
                tie(x,y) = dp[i|(1<<j)][j];
                tie(z,w) = dp[i][k];
                if(x > z + c(j,k)){
                    dp[i|(1<<j)][j] = make_pair(z + c(j,k),w);
                }
            }
        }
    }
    cout << dp[(1<<n)-1][0].first << endl;
}