#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define MV 200001
#define LMV 21
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define emp emplace
#define mp make_pair
#define ins insert
#define sz(x) (int)x.size()
#define whoami(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); whi(_it, args); }

void whi(istream_iterator<string> it) { cerr<<"\n"; }

template<typename T, typename... Args>
void whi(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<" "<<a<<" "; whi(++it, args...); }

void FLASH() {ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}
void SETF() {cout.ios_base::setf(ios_base::fixed); cerr.ios_base::setf(ios_base::fixed);}
void UNSETF() {cout.ios_base::unsetf(ios_base::fixed); cerr.ios_base::unsetf(ios_base::fixed);}

typedef long long ll;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<PII, int> PPII;
typedef pair<PLL, ll> PPLL;
typedef map<int, int> MII;

const int MOD = 1000000007;
const ll INF = 4e18;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct h_llint {
  static uint64_t splitmix64(uint64_t x) {    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};

struct h_pair{
  size_t operator()(const PLL&x)const{
    return hash<ll>()(((ll)x.ff)^(((ll)x.ss)<<32));
  }
};

typedef map<ll, ll> MLL;
typedef map<PII, int> MPII;
typedef map<PLL, ll> MPLL;
typedef set<int> SI;
typedef set<ll> SL;
//ordered_set = order_of_key(.)
//ordered_set = find_by_order(.)
typedef ordered_set<int> OSI;
typedef ordered_set<ll> OSL;
typedef ordered_multiset<int> MOSI;
typedef ordered_multiset<ll> MOSL;
typedef unordered_map<ll, int, h_llint> UMLI;
typedef unordered_map<ll, ll, h_llint> UMLL;
typedef unordered_map<PLL, int, h_pair> UMPI;
typedef unordered_map<PLL, ll, h_pair> UMPL;

int ar[MV];
ll arr[MV];

void solve(int T)
{
	int n;
	cin>>n;
	ll zx = 1;
	for(ll i=2;i<=n;i++)
	zx = (zx * (i/__gcd(zx, i)));
	cout<<zx+1<<"\n";
	return;
}

int main(void)
{
	FLASH();
	//freopen("cowjog.in", "r", stdin);
	//freopen("cowjog.out", "w", stdout);
	int T;
	T = 1;

#ifndef ONLINE_JUDGE
	time_t time_t1, time_t2;
	time_t1 = clock();
#endif

	//cin>>T;
	while(T--)
	solve(T);

#ifndef ONLINE_JUDGE
	time_t2 = clock();
	SETF();
	cerr<<"Time taken: "<<setprecision(7)<<(time_t2 - time_t1)/(double)CLOCKS_PER_SEC<<"\n";
	UNSETF();
#endif

	return 0;
}

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = ll(1e18) + 5;
ll dp[int(1e5) * 2 + 5][2];

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main() {
    ll N;
    cin >> N;
    vector<ll> maxV(N + 2, -INF);
    vector<ll> minV(N + 2, INF);
    rep(i, N) {
        ll X, C;
        cin >> X >> C;
        if (maxV[C] < X) {
            maxV[C] = X;
        }
        if (minV[C] > X) {
            minV[C] = X;
        }
    }

    maxV[N + 1] = 0;
    minV[N + 1] = 0;

    rep(i, N + 5) rep(j, 2) {
        dp[i][j] = INF;
    }
    dp[0][0] = 0;

    ll preMin = 0;
    ll preMax = 0;

    rep(i, N + 1) {
        if (maxV[i + 1] == -INF) {
            dp[i + 1][0] = dp[i][0];
            dp[i + 1][1] = dp[i][1];
            // cerr << "i= " << i << " dp[i+1][0]=" << dp[i + 1][0] << " dp[i+1][1]=" << dp[i + 1][1] << endl;
            continue;
        }
        ll cost = maxV[i + 1] - minV[i + 1];
        dp[i + 1][0] = min(dp[i][0] + abs(maxV[i + 1] - preMin) + cost, dp[i][1] + abs(maxV[i + 1] - preMax) + cost);
        dp[i + 1][1] = min(dp[i][0] + abs(minV[i + 1] - preMin) + cost, dp[i][1] + abs(minV[i + 1] - preMax) + cost);
        preMin = minV[i + 1];
        preMax = maxV[i + 1];
        // cerr << "i+1 =" << i + 1 << " dp[i+1][0]=" << dp[i + 1][0] << " dp[i+1][1]=" << dp[i + 1][1] << " cost=" << cost << endl;
    }

    cout << dp[N + 1][0] << endl;

    // Failed to predict input format
    return 0;
}


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

int main() {
  string s;
  cin >> s;
  int size=s.size();
  rep(i,size) {
    if(i%2==0) {
      if('a'<=s[i] && s[i]<='z') continue;
      else {
        cout << "No" << endl;
        return 0;
      }
    }
    if(i%2==1) {
      if('A'<=s[i] && s[i]<='Z') continue;
      else {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}

#include <bits/stdc++.h>
#include <cassert>
#define rep(i, N) for (int i = 0; i < (N); ++i)
#define rep2(i, a, b) for (ll i = a; i <= b; ++i)
#define rep3(i, a, b) for (ll i = a; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(c) begin(c), end(c)
#define ok() puts(ok ? "Yes" : "No");
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll, ll>;
template <class T> void takeUnique(vector<T> &v) {
  auto last = std::unique(v.begin(), v.end());
  v.erase(last, v.end());
}
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int dxx[] = {0, 1, 1, 1, 0, -1, -1, -1};
int dyy[] = {1, 1, 0, -1, -1, -1, 0, 1};
// clang++ -std=c++11 -stdlib=libc++

string s;
int main() {
  cin >> s;
  bool hard = true;
  rep(i, s.size()) {
    if (i & 1) {
      if (s[i] <= 'Z' and s[i] >= 'A')
        hard &= true;
      else
        hard &= false;
    } else {
      if (s[i] <= 'z' and s[i] >= 'a')
        hard &= true;
      else
        hard &= false;
    }
  }
  if (hard)
    puts("Yes");
  else
    puts("No");
  return 0;
}


//#include <atcoder/maxflow.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#include <iostream>
#include <map>
#include <list>
#include <set>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <iterator>
#include <random>
#include <chrono>
#include <complex>
#include <bitset>
#include <fstream>

#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s

typedef long long ll;

//using namespace __gnu_pbds;
//using namespace atcoder;
using namespace std;

const ll modd = (1000LL * 1000LL * 1000LL + 7LL);
//const ll modd = 998244353;

int main(int argc, char *argv[])   {

    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int> rand_gen(0, modd);   // rand_gen(rng) gets the rand no

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

    cout.precision(12);

//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readstring(s);
        bool reverse = false;
        deque<char> out;
        for(char c : s) {
            if (c=='R') {
                reverse = !reverse;
            } else {
                if (reverse) {
                    out.push_front(c);
                    if ((out.size()>=2) && (out[0]==out[1])) {
                        out.pop_front(); out.pop_front();
                    }
                } else {
                    out.push_back(c);
                    if ((out.size()>=2) && (out.back()==*prev(out.end(), 2))) {
                        out.pop_back(); out.pop_back();
                    }
                }
            }
        }

        forr(i,0,out.size()) {
            if (reverse) {
                cout << out[out.size()-1-i];
            } else {
                cout << out[i];
            }
        }
        cout << endl;
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, l, n) for (int i = (int)(l); i < (int)(n); i++)
#define drep(i, n, l) for (int i = (int)(n); i > (int)(l); i--)
#define INF INT_MAX
#define INFF (pow(2,64))
#define def (200007)
#define MOD (1000000007)
typedef int64_t intt;
typedef vector<int> veci;
typedef vector<vector<int>> Veci;
typedef vector<int64_t> vecit;
typedef vector<vector<int64_t>> Vecit;
typedef vector<vector<double>> Vecd;
typedef vector<double> vecd;
typedef pair<intt, intt> P;
typedef unordered_set<int> uset;
typedef unordered_set<intt> usett;

int main(){
  int N;cin>>N;
  Vecit g(N,vecit(3));
  int ans=0;
  rep(i,0,N){
    intt t,l,r;cin>>t>>l>>r;
    g[i]={l,r,t};
  }
  sort(g.begin(),g.end());

  rep(i,0,N){
    rep(j,i+1,N){
      if(g[i][2]==1 || g[i][2]==3){
        if(g[j][2]==1 || g[j][2]==2){
          if(g[i][1]<g[j][0]){
            continue;
          }
        }else{
          if(g[i][1]<=g[j][0]){
            continue;
          }
        }
      }else{
        if(g[i][1]<=g[j][0])continue;
      }
      ans++;
    }
  }
  cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ll;
#define fast ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL)
#define endl "\n"
#define ii pair<ll,ll>
#define ic pair<char,ll>
#define pb push_back
#define vi vector<ll>
#define popb pop_back
#define pf push_front
#define popf pop_front
#define all(v) (v).begin(), (v).end()
#define F first
#define S second
//#define size(x) (int)(x.size())
ll M = 1000000007;
ll i,j;
ll fac(ll x);
ll inv_fac(ll x);
ll binexp(ll a,ll b);

ll fac(ll x)
{
    ll fcto=1;
    for(ll i=2;i<=x;i++)
    {
        fcto*=i;
        fcto%=M;
    }
    return fcto;
}
ll inv_fac(ll x)
{
    return binexp(fac(x),M-2);
}
ll binexp(ll a,ll b)
{
    if(a==0||a==1) return a;
    if(b==0)  return 1;
    ll ret= binexp(a,b/2);
    if(b%2) return (((ret*ret)%M)*a)%M;
    else return (ret*ret)%M;
}

bool sortbysecdesc(const pair<int,int> &a,
                   const pair<int,int> &b)
{
       return a.second>b.second;
}
ll isPrime(ll n)
{   if (n <= 3)  return (1);
    if (n%2 == 0 || n%3 == 0) return (0);
    for ( i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return (0);

    return (1);
}
ll smallestDivisor(ll n)
{
    // if divisible by 2
    if (n % 2 == 0)
        return 2;

    // iterate from 3 to sqrt(n)
    for ( i = 3; i * i <= n; i += 2) {
        if (n % i == 0)
            return i;
    }

    return n;
}
long long maxPrimeFactors(long long n)
{
    long long maxPrime = -1;
    while (n % 2 == 0) {
        maxPrime = 2;
        n >>= 1;
    }
    for ( i = 3; i <= sqrt(n); i += 2) {
        while (n % i == 0) {
            maxPrime = i;
            n = n / i;
        }
    }
    if (n > 2)
        maxPrime = n;
    return maxPrime;
}
ll countDivisors(ll n)
{
    ll cnt = 0;
    for ( i = 1; i <= sqrt(n); i++) {
        if (n % i == 0) {
            if (n / i == i)
                cnt++;

            else
                cnt = cnt + 2;
        }
    }
    return cnt;
}
//Merging two sets in cpp: merge(a.begin(), a.end(), b.begin(), b.end(), inserter(m, m.end()));
int main()
{
    fast;
    ll tt=1;
    //cin>>tt;
    while(tt--)
    {
      ll n;
      cin>>n;
      ll a[n];
      map<ll,ll>mp;
      for(i=0;i<n;i++)
      {
          cin>>a[i];
          a[i]=a[i]%200;
          mp[a[i]]++;
      }
      map<ll,ll>:: iterator itr;
      ll sum=0;
      for(itr=mp.begin();itr!=mp.end();itr++)
      {
          if(itr->S>1)
          {
              sum+=(itr->S)*(itr->S-1)/2;
          }
      }
      cout<<sum<<"\n";

    }
}

//
//  main.cpp
//  1014 . 打地鼠
//
//  Created by Paul Liao on 2021/5/6.
//

#include <iostream>
#include<map>
#define ll long long
#define AC ios::sync_with_stdio(0);cin.tie(0)
#define endl "\n";
#define FOR(i,a,b) for(int i=a;i<b;i++)
using namespace std;
ll x[20],MOD=1e9+7,haha[2]={(ll)1e9+7,(ll)1e9+9};
ll fpow(ll x,ll y){
    ll now,r;
    r=1;
    now=x;
    while(y){
        if(y%2){
            r*=now;
            r%=MOD;
        }
        now*=now;
        now%=MOD;
        y/=2;
    }
    return r;
}
int main() {
    AC;
    ll n,a[200005],ans=0;
    map<int,int> num;
    cin>>n;
    FOR(i,0,n){
        cin>>a[i];
        ans+=num[a[i]%200];
        num[a[i]%200]++;
    }
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define fr(i, a, b) for (ll i = a; i < b; i++)
#define rf(i, a, b) for (ll i = a; i >= b; i--)
typedef std::vector<long long> vi;
#define F first
#define S second
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
#define mod 1000000007
#define PB push_back
#define MP make_pair
#define PI 3.14159265358979323846
#define all(a) a.begin(), a.end()
#define mx(a) *max_element(all(a))
#define mn(a) *min_element(all(a))
const ll INF = LLONG_MAX / 2;
const ll N = 2e5 + 1;
using namespace std;
void solve()
{
    ll n, i, j = 0, b, c, a, d;
    std::cin >> a >> b >> c >> d;
    ll e = d * c - b;
    if (e <= 0)
    {
        cout << "-1\n";
        return;
    }
    ll ans = (a + e - 1) / e;
    cout << ans << "\n";
}
int main()
{
    fast;
    ll _ = 1, counti = 0;
    // std::cin >> _;
    while (_--)
    {
        // counti++;
        // cout << "Case #" << counti << ": ";
        solve();
    }
}

#include <chrono>
#include <thread>
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define T top()
#define E end()
#define PS push
#define Q queue
#define PP pop()
#define L0 (LL)0
#define V vector
#define ST stack
#define FI first
#define MAX 4e18
#define MIN -MAX
#define DQ deque
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define SE second
#define DL double
#define G getline
#define IN insert
#define endl "\n"
#define EM empty()
#define cnn continue
#define MD 1000000007
#define PSB push_back
#define PI acos(-1.00)
#define PPB pop_back()
#define PSF push_front
#define ub upper_bound
#define lb lower_bound
#define PPF pop_front()
#define CF cout.flush()
#define line cout<<endl
#define LL long long int
#define one cout<<1<<endl
#define zer cout<<0<<endl
#define PQ priority_queue
#define kth find_by_order
#define nil cout<<-1<<endl
#define N cout<<"NO"<<endl
#define NN cout<<"No"<<endl
#define Y cout<<"YES"<<endl
#define fndidx order_of_key
#define YY cout<<"Yes"<<endl
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#define MAU cout<<"Case "<<mau<<": "
#define SP(pre) fixed<<setprecision(pre)
#pragma GCC optimization ("unroll-loops")
#define MMAU cout<<"Case "<<mau<<":"<<endl
#define __lcm(A1,A2) (A1/(__gcd(A1,A2)))*A2
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)
#define UOSMOY v.C;w.C;ww.C;uu.C;uo.C;vo.C;vu.C;ab.C;bc.C;cc.C;uuu.C;a.C;b.C;c.C;u.C
typedef tree<LL, null_type, less<LL>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define remembermeforcenturies using namespace std::chrono_literals;std::this_thread::sleep_for(-4611686018427387904ms);
V<LL>v,w,ab,bc;
set<LL>uo;
map<LL,LL>ww,cc,u;
V<pair<LL,LL> >uu,su;
map<LL,V<LL> >uuu;
map<pair<LL,LL>,LL> vo,vu;
map<LL,pair<LL,pair<LL,LL > > > vs;
priority_queue<LL,V<LL>,greater<LL> > moy;
LL dx[]= {-1,0,1,0,1,1,-1,-1};
LL dy[]= {0,1,0,-1,-1,1,1,-1};
LL dxx[]= {2,1,-1,-2,-2,-1,1,2};
LL dyy[]= {1,2,2,1,-1,-2,-2,-1};
LL dp[101][10001];
LL ar[10][10];
int main()
{
//  BRR;
//  file;
    FAST;
    char ch;
    string a,b,c;
    DL x,y,d,e,f,g,h;
    LL n,i,j,k,p,q,o,l,s,tt=1,m,t,z,aa,r=0;
//    cin>>tt;
    for(LL mau=1; mau<=tt; mau++)
    {
        UOSMOY;
        ordered_set os;
        remembermeforcenturies;
        cin>>n>>p>>q>>m;
        r=0;
        k=0;
        t=1000000;
        while(t--)
        {
            if(n<=r*m)break;
            n+=p;
            r+=q;
            k++;
        }
        if(n>r*m)k=-1;
        cout<<k<<endl;

    }
    return 0;
    //IN
    //AL
}


//#include<cstdio>
//#include<cassert>
//#include<iostream>
//#include<cstring>
//#include<algorithm>
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define MAX ((int)2e9 + 5)
#define MAXP ((int)1e5 + 5)
#define MAXL ((ll)1e18 + 5)
#define MAX_X ((int)2001)
#define MAX_Y ((int)2001)
#define pi acos(-1)
//#define MOD ((int)1e9 + 7)
#define MOD ((int)998244353 + 0)
#define BAS ((int)1e6 + 3)
//#define BAS ((int)2e5 + 3)
#define N ((int)4e5 + 9)
#define eps (1e-8)
#define fastio ios_base::sync_with_stdio(false),cin.tie(NULL)
#define logn 17
#define endl "\n"
#define mpp make_pair
#define BUCK 105
#define LEF (idx<<1)
#define RIG ((idx<<1)|1)
//#define int ll

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;

/*fast io
ios_base::sync_with_stdio(false);
cin.tie(NULL);
*/

typedef tree < int,  null_type,  less < int >,  rb_tree_tag,  tree_order_statistics_node_update > o_set;
typedef tree < pair < int, int >,  null_type,  less < pair < int, int > >,  rb_tree_tag,  tree_order_statistics_node_update > o_setp;
/// o_set s;
/// s.order_of_key(k) : Number of items strictly smaller than k .
/// *(s.find_by_order(k)) : K-th element in a set (counting from zero).

typedef long double ldd;

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

int my_rand(int l, int r)
{
    return uniform_int_distribution<int>(l,r) (rng);
}

int  tar[N] , vis[N] , L[N] , R[N];

pair < int , int > arr[N];

queue < int > que;

void remv(int a , int b)
{
    int pa = L[a] , pb = R[b];
    R[pa] = pb;
    L[pb] = pa;
    a = pa , b = pb;
    if(tar[a] && !vis[a] && !tar[b]) que.push(a);
    if(tar[b] && !vis[b] && !tar[a]) que.push(b);
}

int main()
{
    fastio;
    int n;
    cin>>n;
    n += n;
    string str;
    for(int i = 1 ; i<=n ; i++) cin>>arr[i].first , arr[i].second = i, str += "@";
    str += "@";
    sort(arr + 1 , arr + n + 1);
    for(int i = n ; i > n/2 ; i--){
        tar[arr[i].second] = 1;
    }

    tar[0] = tar[n+1] = 1;
    L[0] = 0;
    R[0] = 1;
    L[n+1] = n;
    R[n+1] = n+1;
    vis[0] = vis[n+1] = 1;
    for(int i = 1 ; i<=n ; i++){
        L[i] = i-1 , R[i] = i+1;
        if(tar[i] && (!tar[i-1] || !tar[i+1])) que.push(i);
    }
    while(!que.empty()){
        int a = que.front();
//        cout<<a<<" ";
        que.pop();
        if(vis[a]) continue;
//        cout<<a<<" ";

        if(L[a] > 0 && !tar[L[a]]){
            str[L[a]] = '(';
            str[a] = ')';
            remv(L[a] , a);
            vis[a] = 1;
        }
        else if(R[a] <= n && !tar[R[a]]){
            str[a] = '(';
            str[R[a]] = ')';
            remv(a,R[a]);
            vis[a] = 1;
        }
    }
    for(int i = 0 ; i<n ; i++) str[i] = str[i+1];
    str.pop_back();
    cout<<str<<endl;
    return 0;
}

#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N; cin>>N;
  vector<pair<int,int>> A(2*N);
  for(int i=0;i<2*N;i++){
    cin>>A[i].first; A[i].second=i;
  }
  sort(A.begin(),A.end());
  vector<int> B(2*N);
  for(int i=0;i<N;i++) B[A[i].second]=1;
  string C(2*N,'(');
  stack<pair<int,int>> st;
  for(int i=0;i<2*N;i++){
    if(st.size()==0 || st.top().first==B[i]) st.push({B[i],i});
    else st.pop(),C[i]=')';
  }
  cout<<C<<endl;
}


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

int main() {
  int N;
  cin >> N;
  vector<vector<pair<int, long long int>>> G(N);
  for (int i = 0; i < N - 1; i++) {
    int u, v;
    long long int w;
    cin >> u >> v >> w;
    u--;
    v--;
    pair<int, long long int> p = make_pair(v, w), q = make_pair(u, w);
    G.at(u).push_back(p);
    G.at(v).push_back(q);
  }
  vector<long long int> dist(N, -1);
  queue<int> que;
  que.push(0);
  dist.at(0) = 0;
  while (!que.empty()) {
    int u = que.front();
    que.pop();
    for (int i = 0; i < G.at(u).size(); i++) {
      int v = G.at(u).at(i).first;
      if (dist.at(v) >= 0) continue;
      long long int w = G.at(u).at(i).second;
      dist.at(v) = dist.at(u) ^ w;
      que.push(v);
    }
  }
  long long int ans = 0, MOD = 1000000007;
  for (int k = 0; k < 60; k++) {
    vector<long long int> cnt(2, 0);
    for (int i = 0; i < N; i++) cnt.at((dist.at(i) >> k) & 1)++;
    ans += ((long long int)1 << k) % MOD * cnt.at(0) % MOD * cnt.at(1) % MOD;
    ans %= MOD;
  }
  cout << ans << endl;
}

// execute g++ main.cpp -std=c++14 -I C:\Users\naoya\Desktop\code\Atcoder
#include<bits/stdc++.h>
//#include<atcoder/all>
typedef long long ll;
typedef long double ld;
using namespace std;
//using namespace atcoder;

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

//ordered_set 重複不可
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// use set_function + find_by_order(select itr-num)

#define REP(i, l, n) for(ll i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

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

char alpha[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'};
char Alpha[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'};

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

//cout << std::fixed << std::setprecision(15) << y << endl; //小数表示

const ll mod = 1e9 + 7;

int main(){
    int n; cin >> n;
    vector<vector<Pll> > tree(n);
    REP(i,0,n-1){
        ll a, b, c; cin >> a >> b >> c;
        a--; b--;
        tree[a].pb(Pll(b,c));
        tree[b].pb(Pll(a,c));
    }
    vector<ll> dist(n, -1);
    dist[0] = 0;
    queue<ll> que;
    que.push(0);
    while(!que.empty()){
        ll now = que.front();
        que.pop();
        REP(i,0,tree[now].size()){
            int next = tree[now][i].first;
            if(dist[next] == -1){
                que.push(next);
                dist[next] = dist[now] ^ tree[now][i].second;
            }
        }
    }
    ll ans = 0;
    vector<vector<ll>> bit(60, vector<ll>(2, 0));
    for(ll i = n-1; i >= 0; i--){
        REP(l,0,60){
            if((dist[i] & (1ll << l)) == 0){
                ans += (((1ll<<l) % mod) * (bit[l][1] % mod))%mod;
                ans %= mod;
                bit[l][0]++;
            }else{
                ans += (((1ll<<l) % mod) * (bit[l][0] % mod))%mod;
                ans %= mod;
                bit[l][1]++;
            }
        }
    }
    cout << ans << endl;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,K;
int T[10][10];

void solve() {
	int i,j,k,l,r,x,y; string s;

	cin>>N>>K;
	FOR(y,N) FOR(x,N) cin>>T[y][x];
	vector<int> V;
	FOR(x,N-1) V.push_back(x+1);
	int ret=0;
	do {
		int sum=T[0][V[0]]+T[V.back()][0];
		FOR(i,V.size()-1) sum+=T[V[i]][V[i+1]];
		if(sum==K) ret++;

	} while(next_permutation(ALL(V)));
	cout<<ret<<endl;
}

int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long int ;
using P = pair<ll,ll>;
using Graph= vector<vector<ll>>;
struct edge{ll to ; ll cost ;} ;
using graph =vector<vector<edge>> ;
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second
#define set20 cout<<fixed<<setprecision(20)  ;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
long double pi=acos(-1) ;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
ll dx[4] {1,0,-1,0} ;
ll dy[4] {0,1,0,-1} ;

// sum(x) x以下の和
// sum(a,b) a以上b以下の和
template<typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n=0):n(n),d(n+1) {}
  void add(int i, T x) {  //x=1ならsumは個数のカウント
    for (i++; i <= n; i += i&-i) {
      d[i] += x;
    }
  }
  T sum(int i) {
    T x = 0;
    for (i++; i; i -= i&-i) {
      x += d[i];
    }
    return x;
  }
  T sum(int i,int j) {
    if(i>0) return sum(j)-sum(i-1);
    else return sum(j) ; }
};

int main(){
  ios::sync_with_stdio(false) ;
  cin.tie(nullptr) ;
  ll n,m,q ; cin>>n>>m>>q ;
  vector<ll> A(n) ,B(m) ;
  ll sum=0 ;
  vector<pair<ll,pair<ll,ll>>> f(q) ;
  rep(i,q){
    cin>>f[i].fi>>f[i].se.fi>>f[i].se.se ;
  }

  vector<ll> ff(q+1) ;
  ff[0]=0ll ;
  rep(i,q) ff[i+1]=f[i].se.se ;
  vector<ll> ans(q+1) ; //圧縮後の配列
 vector<ll> za ;
 rep(i,q+1) za.pb(ff[i]) ;
 sort(za.begin(),za.end()) ;
 za.erase(unique(za.begin(),za.end()),za.end()) ;
 rep(i,q+1) ans[i] = lower_bound(za.begin(),za.end(),ff[i])-za.begin() ;
  //ans[i] //i+1
  map<ll,ll> mp ;
  rep(i,q+1){
    mp[ff[i]]=ans[i] ;
  }
  BIT<ll> bit(500000) ,cit(500000) ;
  BIT<ll> x(500000),y(500000) ;
  x.add(0,n) ;
  y.add(0,m) ;

  rep(i,q){
    if(f[i].fi==1){
      ll now= A[f[i].se.fi-1] ;
      ll next = f[i].se.se ;
      ll aa= mp[now] ;
      ll bb = mp[next] ;
      if(aa<bb){
        sum-= cit.sum(aa,bb)  ;
        sum+= y.sum(aa,bb)*next ;
        if(aa>0) sum-= y.sum(0,aa-1)*now ;
        if(aa>0) sum+= y.sum(0,aa-1)*next ;
      }
      else{
       sum-= y.sum(bb,aa)*now ;
       sum+=cit.sum(bb,aa) ;
       if(bb>0) sum-= y.sum(0,bb-1)*now ;
       if(bb>0) sum+= y.sum(0,bb-1)*next ;
      }

      A[f[i].se.fi-1]=next ;
      bit.add(aa,-now) ;
      bit.add(bb,next) ;
      x.add(bb,1) ;
      x.add(aa,-1) ;
    }
    else{
     ll now= B[f[i].se.fi-1] ;
      ll next = f[i].se.se ;
      ll aa= mp[now] ;
      ll bb = mp[next] ;
      if(aa<bb){
        sum-= bit.sum(aa,bb)  ;
        sum+= x.sum(aa,bb)*next ;
        if(aa>0) sum-= x.sum(0,aa-1)*now ;
        if(aa>0) sum+= x.sum(0,aa-1)*next ;
      }
      else{
       sum-= x.sum(bb,aa)*now ;
       sum+=bit.sum(bb,aa) ;
       if(bb>0) sum-= x.sum(0,bb-1)*now ;
       if(bb>0) sum+= x.sum(0,bb-1)*next ;
      }
      B[f[i].se.fi-1]=next ;
      cit.add(bb,next) ;
      cit.add(aa,-now) ;
      y.add(bb,1) ;
      y.add(aa,-1) ;
    }

    cout<<sum<<endl ;
  }

   return 0 ;
}


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

#define  quick  ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
#define s(x) sort(x.begin(),x.end())
#define sr(x) sort(x.begin(),x.end(),greater<ll>())
#define v1 vector<ll>
#define p1 pair<ll,ll>
#define m1 map<ll,ll>
#define ff first
#define ss second
#define ee '\n';
#define pb push_back
#define all(v) v.begin(),v.end()
#define f(i,x,y) for(i=x;i<y;i++)
#define mp make_pair
#define yes cout<<"YES"<<endl
#define no  cout<<"NO"<<endl

void solve()
{
       string s;
       cin>>s;
       cout<<s[1]<<s[2]<<s[0]<<ee;
}

 int32_t main()
 {
    quick;
    ll t=1;
    //cin>>t;
    while(t--)
    {
       solve();
    }
    return 0;
 }

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

#define sf scanf
#define pf printf

const int high=1e3+5;

int main()
{
    string s, ans="";

    while(cin >> s)
    {
        int len = s.length();

        for(int i=1; i<len; i++)
        {
            ans += s[i];
        }

        ans+=s[0];

        cout << ans << "\n";

        ans.clear();
    }

    return 0;
}


#include<iostream>
#include<string>
#include<stdio.h>
using namespace std;
int main()
{

	int h, w, x, y, c = 0;
	cin >> h >> w >> x >> y;
	x--;
	y--;
	string *a = new string[h];
	for (int i = 0; i < h; i++)
		cin >> a[i];

	if (a[x][y] == '.')
		c++;
	for (int j = x - 1; j >= 0; j--)
		if (a[j][y] == '.')
			c++;
		else
			break;
		for (int j = x + 1; j <= h - 1; j++)
			if (a[j][y] == '.')
				c++;
			else
				break;
		for (int j = y - 1; j >= 0; j--)
			if (a[x][j] == '.')
				c++;
			else
				break;
		for (int j = y + 1; j <= w-1; j++)
			if (a[x][j] == '.')
				c++;
			else
				break;
		cout << c;
}

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

int main() {
  int H, W, X, Y;
  cin >> H >> W >> X >> Y;
  vector<vector<char>> mas(H, vector<char>(W));
  for (int i=0;i<H;i++) {
    for (int j=0;j<W;j++) {
      cin >> mas.at(i).at(j);
    }
  }
  int ans = 0;
  for (int i=0;;i++) {
    if (X-1<0 || Y-1+i>=W) break;
    if (mas[X-1][Y-1+i]=='.') {
      ans++;
    } else {
      break;
    }
  }
  for (int i=0;;i++) {
    if (X-1<0 || Y-1-i<0) break;
    if (mas[X-1][Y-1-i]=='.') {
      if (i==0){
        continue;
      } else {
        ans++;
      }
    } else {
      break;
    }
  }
  for (int i=0;;i++) {
    if (X-1+i>=H || Y-1<0) break;
    if (mas[X-1+i][Y-1]=='.') {
      if (i==0){
        continue;
      } else {
        ans++;
      }
    } else {
      break;
    }
  }
  for (int i=0;;i++) {
    if (X-1-i<0 || Y-1<0) break;
    if (mas[X-1-i][Y-1]=='.') {
      if (i==0){
        continue;
      } else {
        ans++;
      }
    } else {
      break;
    }
  }
  cout << ans << endl;
}


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

int main(){
  ll n,k;
  cin >> n >> k;
  vector<P> a(n);
  rep(i,n) cin >> a[i].first >> a[i].second;
  sort(a.begin(),a.end());

  ll x=0,ans;
  rep(i,n){
    if(k<a[i].first-x){
      ans=x+k; break;
    }
    k-=a[i].first-x;
    k+=a[i].second;
    x=a[i].first;
    ans=a[i].first+k;
  }

  cout << ans << endl;

}

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

#define ll long long int
#define pb(a) push_back(a)
#define vll vector<ll>
#define loop(i, n) for(ll i=1;i<=n;i++)
#define loop0(i, n) for(ll i=0;i<n;i++)
#define in(i) scanf("%lld", &i);
#define out(i) printf("%lld", i)
#define pll pair<ll, ll>
#define vpll vector<pair<ll, ll>>
#define mp(i, j) make_pair(i, j)
#define google cout<<"Case #"<<tc-t<<": ";
const ll mod = 1000000007;
const ll big = 2999999999999999999;
const ll small = -2999999999999999999;
void in2(ll& a, ll& b) { in(a); in(b); }
void in3(ll& a, ll& b, ll& c) { in(a); in(b); in(c); }
void swap(ll& a, ll& b) { a = a+b; b = a-b; a = a-b; }
void arrayIn(vll& a, ll& n) { loop0(i, n) in(a[i]); }

ll n, dp[101][100001];
vll t;

ll solve(ll i, ll rem)
{
  if(rem < 0)
    return small;
  if(i == n)
    return 0;
  if(dp[i][rem] != -1)
    return dp[i][rem];
  return dp[i][rem] = max(solve(i+1, rem-t[i])+t[i], solve(i+1, rem));
}

void solve()
{
  memset(dp, -1, sizeof(dp));
  in(n);
  t.resize(n);
  ll tot = 0;
  loop0(i, n)
  {
    in(t[i]);
    tot += t[i];
  }
  sort(t.begin(), t.end(), greater<ll>());
  ll rem = (tot+1)/2;
  ll ans = solve(0, rem);
  cout<<max(ans, tot-ans)<<"\n";
}

int main()
{
    solve();
}


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

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

typedef double db;
typedef long long ll;

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

int arr[801][801];
int dp[801][801];
int n, k;

bool isPossible(int median) {

	//build prefix sum to calc size of each k*k submatrix in O(1)
	memset(dp, 0, sizeof(dp));

	//1 if element is smaller than or equal to median
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			dp[i][j] = (arr[i][j] <= median) ? 1 : 0;
		}
	}

	//build pref sum
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {

			if (i == 0 && j == 0) continue;
			else if (i == 0) {
				dp[i][j] += dp[i][j - 1];
			}
			else if (j == 0) {
				dp[i][j] += dp[i - 1][j];
			}
			else {
				dp[i][j] += (dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]);
			}
		}
	}

	//check if any subarray has cnt of 1s >= (k*k - 1)/2
	int limit = ((k * k) - 1) / 2;
	for (int i = k - 1; i < n; i++) {
		for (int j = k - 1; j < n; j++) {
			int cnt = dp[i][j];

			if ((i - k) >= 0) cnt -= dp[i - k][j];
			if ((j - k) >= 0) cnt -= dp[i][j - k];
			if ((i - k) >= 0 && (j - k) >= 0) cnt += dp[i - k][j - k];

			if (cnt > limit) return true;
		}
	}
	return false;
}

void solve() {

	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> arr[i][j];
		}
	}

	int s = 0, e = 1e9 + 5;
	int ans = e;

	while (s <= e) {

		int mid = (s + e) / 2;

		if (isPossible(mid)) {
			ans = mid;
			e = mid - 1;
		}
		else {
			s = mid + 1;
		}
	}

	cout << ans;
}

signed main() {

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

	fastIO

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

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

#include<bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(register int i=a;i<=b;++i)
#define ll long long
#define N 200005
#define se second
#define fi first
#define pb push_back
#define mp make_pair
inline ll read(){ll x;scanf("%lld",&x);return x;}
vector<ll>eg[N];
ll d[N],edge[N][3],deep[N];
void dfs(int s,int dad)
{
	deep[s]=deep[dad]+1;
	for(auto v:eg[s])if(v!=dad)
	{
		dfs(v,s);
	}
}
void dfs2(int s,int dad)
{
	for(auto v:eg[s])if(v!=dad)
	{
		d[v]+=d[s];
		dfs2(v,s);
	}
}
void solve()
{
	ll n=read();
	f(i,1,n-1)
	{
		edge[i][1]=read();
		edge[i][2]=read();
		eg[edge[i][1]].pb(edge[i][2]);
		eg[edge[i][2]].pb(edge[i][1]);
	}
	dfs(1,0);
	ll q=read();
	f(i,1,q)
	{
		ll op=read(),e=read(),x=read();
		if(op==1)
		{
			if(deep[edge[e][1]]>deep[edge[e][2]]) d[edge[e][1]]+=x;
			else d[1]+=x,d[edge[e][2]]-=x;
		}
		else
		{
			if(deep[edge[e][1]]>deep[edge[e][2]]) d[1]+=x,d[edge[e][1]]-=x;
			else d[edge[e][2]]+=x;
		}
	}
	dfs2(1,0);
	f(i,1,n) printf("%lld\n",d[i]);
}
int main()
{
	ll T=1;
	while(T--) solve();
	return 0;
}


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

#define int long long
#define ld long double
#define db double
#define endl "\n"
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()

using namespace __gnu_pbds;
using namespace std;
using namespace chrono;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void deb_out() {
    cout << endl;
}
template <typename Head, typename... Tail>
void deb_out(Head H, Tail... T) {
    cout << " " << H;
    deb_out(T...);
}
#ifdef LOCAL
    #define deb(...) cout << "[" << #__VA_ARGS__ << "]:", deb_out(__VA_ARGS__);
#else
    #define deb(...) ;
#endif

const long double PI = 3.14159265358979323846264338;
const long long INF = 1000000000000000000;
const long long INF1 = 1000000000;
const long long MOD = 1000000007;
// const long long MOD = 998244353;

inline int cl(int a, int b){
    if(a % b)
        return 1 + a / b;
    return a / b;
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int Tests = 1;
    // cin >> Tests;
    while (Tests--) {
        int n, x;
        cin >> n >> x;
        while (n--) {
            int X;
            cin >> X;
            if (X != x) {
                cout << X << " ";
            }
        }
    }
}

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

int main() {
  int a,b;
  cin >> a >> b;
  int array[a];
  for(int i = 0;i < a;i++){
    cin >> array[i];
  }
  for(int i = 0;i < a;i++){
    if(array[i] == b) continue;
    else cout << array[i] << " " ;
  }
}


// Problem : D - Takahashi Unevolved
// Contest : AtCoder - AtCoder Beginner Contest 180
// URL : https://atcoder.jp/contests/abc180/tasks/abc180_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll power(ll x,ll y,ll m){if(y==0)return 1;ll p=power(x,y/2,m)%m;p=(p*p)%m;return (y%2==0)?p:(x*p)%m;}
ll nCr(ll n,ll r,ll m){if(r>n)return 0;ll a=1,b=1,i;for(i=0;i<r;i++){a=(a*n)%m;--n;}while(r){b=(b*r)%m;--r;}return (a*power(b,m-2,m))%m;}
vector<ll> fac;
ll nCr2(ll n,ll r,ll m){if(r>n) return 0;return (((fac[n]*power(fac[r],m-2,m))%m)*power(fac[n-r],m-2,m))%m;}
ll gcd(ll a, ll b) {return (b ? gcd(b, a % b) : a);}
#define Test int t;cin>>t;while(t--)
#define endl '\n'
void solve()
{
	ll x,y,a,b;
	cin >> x >> y >> a >> b;
	ll t1=x,t2=0;
	int size3 = trunc(log10(y)) + 1;
	while(t1<y)
	{
		int size = trunc(log10(t1)) + 1;
		int size2 = trunc(log10(a)) + 1;
		if(size+size2>18 || size+size2>size3)
		{
			ll t3=(y-t1);
			t2+=(t3-1+b)/b;
			break;
		}
		if(t1+b<t1*a)
		{
			ll t3=(y-t1);
			t2+=(t3-1+b)/b;
			break;
		}
		else
		{
			t1*=a;
			t2++;
		}
	}
	cout << t2-1 << endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//Test
	solve();
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define ld long double
// g++ -std=c++17 -Wshadow -Wall -g -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -o

int main(){
 ll x,y,a,b;
 cin>>x>>y>>a>>b;
//  ll xd=x+b;
 ll exp=0;
 while(x*a<=x+b && (x*a>0)){
  x*=a;
  if(x>=y || x<=0){
   cout<<exp<<"\n";
   return 0;
  }
  exp++;
 }
//  cout<<exp<<"\n";
//  cout<<y-x<<"\n";
 exp+=((y-x-1)/b);
 cout<<exp<<"\n";
 return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,k;
long long s;
void solve(){
	cin>>n>>k;
	if(k<0)k=-k;
	for(int i=1;i<=2*n-k;++i){
		if(n<k+i){
			if(n>i){
				s+=1ll*(2*n-k-i)*i;
			}
			else{
				s+=1ll*(2*n-k-i)*(2*n-i);
			}
		}
		else{
			s+=1ll*(k+i)*(i);
		}
	}
	cout<<s<<"\n";
}
int main(){
	solve();
	return 0;
}

#include <algorithm>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <cassert>
#include <vector>
#include <random>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>

//#include <atcoder/all>

#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=998244353;
const int dx[8]={-1,0,1,0,1,1,-1,-1},dy[8]={0,1,0,-1,1,-1,1,-1};

//using namespace atcoder;

ll Pow(ll n,ll p){
	ll r=1;
	for(;p>0;p>>=1){
		if(p&1) r=(r*n)%mod;
		n=(n*n)%mod;
	}
	return r;
}

const int M=1000005;
ll F[M];

void Init(){
	F[0]=1;
	for(int i=1;i<M;i++) F[i]=F[i-1]*i%mod;
}

ll Div(ll n,ll m){
	return n*Pow(m,mod-2)%mod;
}

ll nCk(ll n,ll k){
	return Div(F[n],F[n-k]*F[k]%mod);
}

ll dp[21][5005],N;

ll Rec(int i,int n){
	if(n==0) return 1;
	if(i<0) return 0;
	if(dp[i][n]>=0) return dp[i][n];
	ll res=0,x=1<<i;
	for(int j=0;j*x<=n&&j<=N;j+=2){
		(res+=nCk(N,j)*Rec(i-1,n-j*x))%=mod;
	}
	return dp[i][n]=res;
}

int m;

int main(){
	for(int i=0;i<21;i++) for(int j=0;j<5005;j++) dp[i][j]=-1;
	Init();
	cin>>N>>m;
	cout<<Rec(20,m)<<endl;
}


#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++)

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

    rep(i, x.size()){
        if(x[i] != '.') cout << x[i] ;
        else break ;
    }
}

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

int main() {
    vector<char> c;
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++) {
        if (s.at(i) == '.') break;
        c.push_back(s.at(i));
    }
    for (int i = 0; i < c.size(); i++) {
        cout << c.at(i);
    }
    cout << endl;
    return 0;
}


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

int main() {

  int N,M,Q;
  cin >> N >> M >> Q;

  vector<pair<int, int>> vec;
  for (int i = 0; i < N; i++) {
    int w,v;
    cin >> w >> v;
    vec.push_back(make_pair(v , w));
  }

  vector<int> X;
  for (int i = 0; i < M; i++) {
    int a;
    cin >> a;
    X.push_back(a);
  }

  for (int i = 0; i < Q; i++) {
    int64_t sum = 0;
    vector<int> Y = X;
    vector<pair<int, int>> VW = vec;
    int qa,qb;
    cin >> qa >> qb;
    Y.erase(Y.begin() + qa-1, Y.begin() + qb);

    // Yの個数分グリーディーに価値が高い順に選ぶ
    // 箱の大きさが小さい順に選んでいく
    sort(Y.begin(), Y.end());
    // 価値が高い順に並べる
    sort(VW.rbegin(), VW.rend());

    // 箱の個数分繰り返す
    for (int j = 0; j < Y.size(); j++) {
      int num=0;
      // 箱の大きさ以下でもっとも価値が高いものを選び、潰す
      for (int k = 0; k < VW.size(); k++) {
        if(VW.at(k).second <= Y.at(j)){
          num = VW.at(k).first;
          VW.at(k).second = 1e9;
          break;
        }
      }
      sum += num;
    }

    cout << sum << endl;
  }

}

#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define P pair<ll,int>
#define PI 3.141592653589793
#define pb push_back
const int INF = 1001001001;
const ll MX = 1e18;
const int mod = 998244353;
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

int main() {
	int n, m, q;
	cin >> n >> m >> q;
	vector<P> a(n);
	vector<int> x(m);
	rep(i, n) {
		cin >> a[i].second >> a[i].first;
	}
	sort(a.rbegin(), a.rend());
	rep(i, m) cin >> x[i];

	rep(qi, q) {
		ll ans = 0;
		int l, r;
		cin >> l >> r;
		l--; r--;
		vector<int> xi;
		vector<int> c(n);
		rep(j, l) xi.pb(x[j]);
		for (int j = r + 1; j < m; j++) xi.pb(x[j]);
		if (xi.size() == 0) {
			cout << 0 << endl;
			continue;
		}
		sort(xi.begin(), xi.end());
		rep(i, xi.size()) {
			int now = xi[i];
			rep(j, a.size()) {
				if (now >= a[j].second) {
					if (c[j] != 0) continue;
					ans += a[j].first;
					c[j] = 1;
					break;
				}
			}
		}
		cout << ans << endl;
	}

}


#include <bits/stdc++.h>

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

using namespace std;

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

	int n; cin>>n;
	vector<ll> v(n), w(n+1);
	rep(i,n) cin>>v[i];
	w[0] = 0;
	rep(i,n)
		if (i % 2)
			w[i+1] = w[i] + v[i];
		else
			w[i+1] = w[i] - v[i];
	ll cnt = 0;
	map<ll, int> mp;
	mp[0]++;
	rep(i,n + 1)
	{
		if (!i) continue;
		cnt += mp[w[i]];
		mp[w[i]]++;
	}
	cout << cnt << "\n";
}

#include <bits/stdc++.h>

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

constexpr bool typetest = 0;
constexpr int N = 3e5 + 5;
int n;
ll a[N];

void Read()
{
    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> a[i],
            a[i] = a[i - 1] + ((i & 1) ? 1 : -1) * a[i];
}

void Solve()
{
    sort(a, a + n + 1);
    ll ans(0);
    for (int i = 0, j = 0; i <= n; ++i)
    {
        while (j <= n && a[i] == a[j])
            ++j;
        ans += 1ll * (j - i) * (j - i - 1) / 2;
        i = j - 1;
    }

    cout << ans;
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t(1);
    if (typetest)
        cin >> t;
    for (int _ = 1; _ <= t; ++_)
    {
        Read();
        Solve();
    }
}


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

int main (){
    int n;
    cin >> n;
    ll ans = -1;
    rep(i, n){
        ll a, p, x;
        cin >> a >> p >> x;

        if(x - a > 0){
            if(ans==-1)
                ans = p;
            else if(ans>p)
                ans=p;
        }
    }
    cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long
#define double long double
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define aint(a) (a).begin(), (a).end()
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007ll
#define PI 3.14159265359
#define INF 1000000005
#define LINF 1000000000000000005ll
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll a,b,c,d;
int32_t main(){
CODE_START;
cin>>a>>b>>c>>d;
cout<<b-c<<endl;
}


#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
const int maxN = 205;
bool can[maxN];
int n;
int a[maxN], b[maxN];
void bad() {
    cout << "No";
    exit(0);
}
bool was[maxN];
int par[maxN];
bool le[maxN], ri[maxN];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    cin >> n;
    memset(was, 0, sizeof was);
    for (int i = 1; i <= n; i++) {
        cin >> a[i] >> b[i];
        if (a[i] != -1 && b[i] != -1 && a[i] >= b[i]) {
            bad();
        }
        if (a[i] != -1 && was[a[i]]) bad();
        if (b[i] != -1 && was[b[i]]) bad();
        if (a[i] != -1) was[a[i]] = true;
        if (b[i] != -1) was[b[i]] = true;
        if (a[i] != -1) le[a[i]] = true;
        if (b[i] != -1) ri[b[i]] = true;
        if (a[i] != -1 && b[i] != -1) {
            par[a[i]] = b[i];
            par[b[i]] = a[i];
        }
    }
    memset(can, 0, sizeof can);
    can[0] = true;
    for (int r = 1; r <= 2 * n; r++) {
        for (int l = r - 1; l >= 1; l--) {
            if (!can[l - 1]) continue;
            if ((r - l + 1) % 2 != 0) continue;
            bool ok = true;
            int len = (r - l + 1) / 2;
            for (int j = l; j <= l + len - 1; j++) {
                if (par[j] != 0 && par[j] != j + len) ok = false;
                if (par[j + len] != 0 && par[j + len] != j) ok = false;
                if (ri[j]) ok = false;
                if (le[j + len]) ok = false;
                if (par[j] == 0 && le[j] && ri[j + len]) ok = false;
            }
            if (ok) can[r] = true;
        }
    }
    cout << (can[2 * n] ? "Yes" : "No");
    return 0;
}

#include <stdio.h>
#include <algorithm>
#include <set>
#include <tuple>
#include <queue>
#include <vector>
using namespace std;
using ll = unsigned long long;
using pii = pair<int, int>;

int n, m, a[10000], b[10000], c[200], d[10000], v[200];
vector<pii> e[200];
void dfs(int x, int p) {
	if (v[x])
		return;
	v[x] = 1;

	for (pii ed : e[x]) {
		int y, id;
		tie(y, id) = ed;
		if (y == p)
			continue;
		if (d[id])
			continue;

		d[id] = (a[id] == x ? 2 : 3);
		dfs(y, x);
	}
}
int main() {
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++)
		scanf("%d %d", a + i, b + i);
	for (int i = 1; i <= n; i++)
		scanf("%d", c + i);

	for (int i = 0; i < m; i++) {
		if (c[a[i]] != c[b[i]])
			d[i] = ((c[a[i]] > c[b[i]]) ? 2 : 3);
		else {
			e[a[i]].emplace_back(b[i], i);
			e[b[i]].emplace_back(a[i], i);
		}
	}
	for (int i = 1; i <= n; i++)
		dfs(i, 0);

	for (int i = 0; i < m; i++)
		printf((d[i] ^ 2) ? "<-\n" : "->\n");
}


#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#include <bits/stdc++.h>
using namespace std;

const double TL = 1.5 * CLOCKS_PER_SEC;
mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
#define clr(x, y) memset(x, y, sizeof(x))
#define forn(i, n) for (int i = 0; i < n; i++)
#define LL long long
const double pi = acos(-1.0);

int n;
int a[200005];

int main() {
#ifdef LOCAL
  auto start_clock = clock();
  freopen("in", "r", stdin);
#endif
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  bool flag = true;
  vector<int> ans;
  for (int i = 1; i <= n;) {
    if (a[i] == i) {
      i += 1;
      continue;
    }
    int j = i + 1;
    for (; j <= n && a[j] != i; j++);
    int k = j;
    while (j > i) {
      j -= 1;
      swap(a[j], a[j + 1]);
      ans.push_back(j);
    }
    for (int l = i + 1; l < k; l++) {
      if (a[l] != l) {
        flag = false;
        break;
      }
    }
    if (!flag) {
      break;
    }
  }

  if (flag && (int)ans.size() == (n - 1)) {
    for (auto w : ans) {
      printf("%d\n", w);
    }
  } else {
    puts("-1");
  }

#ifdef LOCAL
 auto end_clock = clock();
 cout << "Time:" << (end_clock - start_clock) * 1.0 / CLOCKS_PER_SEC << endl;
#endif
  return 0;
}

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

typedef long long ll;
const ll INF = (1LL << 62) - (1LL << 31); /*オーバーフローしない程度に大きい数*/
const ll MOD = 1000000007;
using namespace std;

int main() {
#ifdef LOCAL
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

    int n;
    cin >> n;
    vector<int> p(n + 1);
    vector<int> order(n + 1);
    vector<int> used(n + 1, false);
    vector<int> c_used(n + 1, false);  // 1〰nまで空いているのか？.

    typedef pair<int, int> pattern;
    vector<int> ans1;

    repi(i, 1, n + 1) {
        cin >> p[i];
        order[p[i]] = i;
    }

    bool is_ok = true;
    repi(i, 1, n + 1) {
        if (!is_ok) break;
        for (int pos = order[i]; pos != i; pos--) {
            if (pos == i) break;
            if (used[pos - 1]) {
                is_ok = false;
                break;
            } else {
                used[pos - 1] = true;
                int tmp = p[pos - 1];  // 1つ前のp[]
                p[pos - 1] = i;
                p[pos] = tmp;
                int tmp_order = order[tmp];
                order[tmp] = pos;
                order[i] = pos - 1;
                ans1.push_back(pos - 1);
            }
        }
    }

    if (is_ok && (ans1.size()==(n-1))) {
        rep(i, ans1.size()) cout << ans1[i] << endl;
    } else {
        cout << -1;
    }

    return 0;
}


#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll ,ll> pll;
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(X) (X).begin(), (X).end()
#define REP(i,x,y) for(ll i = x;i <= y;++i)
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
vector<string> vec_splitter(string s) {
    for(char& c: s) c = c == ','?  ' ': c;
    stringstream ss; ss << s;
    vector<string> res;
    for(string z; ss >> z; res.push_back(z))
        ;
    return res;
}
void debug_out(vector<string> args, int idx) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, Head H, Tail... T) {
    if(idx > 0) cerr << ", ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __VA_ARGS__)
void localTest() {
    #ifndef ONLINE_JUDGE
        freopen("inp", "r", stdin);
        freopen("out", "w", stdout);
    #endif
}
void solver() {
    string s;
    cin >> s;
    reverse(all(s));
    for(auto &c : s) {
        if(c == '6') {
            c = '9';
        } else if(c == '9') {
            c = '6';
        }
    }
    cout << s << "\n";
    return;
}
int main() {

    localTest();
    fastio;
    int t = 1;
    // cin >> t;
    while(t--) {
        solver();
    }

    return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

char fc(char x, char y){
  if(x == y) return x;
  if(x == 'R'){
    if(y == 'P') return y;
    else return x;
  }else if(x == 'P'){
    if(y == 'S') return y;
    else return x;
  }else{
    if(y == 'R') return y;
    else return x;
  }
}

char rc(int pos, int lv, string &s, int &nxpos){
  static vector<vector<char>> dp(lv+1, vector<char>(s.size(), 0));
  static vector<vector<int>> posdp(lv+1, vector<int>(s.size(), -1));
  int n = s.size();
  if(dp.at(lv).at(pos) != 0){
    nxpos = posdp.at(lv).at(pos);
    return dp.at(lv).at(pos);
  }
  if(lv == 0){
    nxpos = (pos+1) % n;
    return s.at(pos);
  }
  int rpos;
  char l = rc(pos, lv-1, s, rpos);
  char r = rc(rpos, lv-1, s, nxpos);
  posdp.at(lv).at(pos) = nxpos;
  return dp.at(lv).at(pos) = fc(l, r);
}

int main(){
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  int tmp;
  cout << rc(0, k, s, tmp) << endl;
  return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <utility>
using ll = long long;
//#define rep(i, n) for(int i = 0; i < (int)(n); i++)

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

ll n;
ll sum = 0;
ll m;
ll k;
ll minV;

int main() {
    vector<ll> v;
    cin >> n >> m;
    rep(i,m) {
    	cin >> k;
    	v.push_back(k);
    }
    if (m == 0) {
        cout << 1;

    	return 0;
    }

    sort(v.begin(), v.end());
    if(v[v.size()-1] != n) v.push_back(n+1);

    minV = 1000001000;
    if (v[0] - 1 < minV && v[0] != 1) minV = v[0] - 1;
    for (int i = 1; i < v.size(); i++)
    {
        if (v[i] - v[i-1] -1 < minV && (v[i] - v[i-1] -1) != 0) minV = v[i] - v[i-1] -1;
    }
    if (v[0] != 0){
        if ((v[0] - 1) % minV == 0){
        	sum += (v[0] - 1) / minV;
        }
        else{
        	sum += (v[0] - 1) / minV + 1;
        }
    }

    if (minV == 1000001000) {
        cout << 0;

    	return 0;
    }
    for (int i = 1; i < v.size(); i++)
    {
        if((v[i] - v[i-1]-1) % minV == 0){
        	sum += (v[i] - v[i-1] -1) / minV;
        }
        else{
        	sum += (v[i] - v[i-1]-1) / minV + 1;
        }
    }

    cout << sum;

	return 0;
}

// Problem: C - Many Segments
// Contest: AtCoder - AtCoder Beginner Contest 207
// URL: https://atcoder.jp/contests/abc207/tasks/abc207_c
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)

#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;
#define int long long int
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define vi vector <int>
#define ff first
#define ss second
#define vp vector <pair<int,int>>
#define vpp vector <pair<int,pair<int,int>>>
#define seti set<int>
#define setbit(x) __builtin_popcountll(x)
#define sov(v) accumulate(all(v),0)
#define fs(it,a) for(auto it=a.begin();it!=a.end();it++)
#define pb push_back
#define pob pop_back
#define mp make_pair
#define pqmax priority_queue <int,vector <int>>
#define pqmin priority_queue <int,vector <int>,greater<int>>
#define dq deque <int>
#define umi unordered_map<int,int>
#define ums unordered_map<string,int>
#define sp(x,y) fixed << setprecision(y) << x
#define out(r,x) cout<<"Case #"<<r<<": "<<x<<ee;
#define all(x) x.begin(),x.end()
#define f(x,y,z) for(x=y;x<z;x++)
#define si size()
#define countdigit(x) floor(log10(x) +1)
#define M 1000000007
#define Z 998244353
#define fill(arr,x) memset(arr,x,sizeof(arr))
//Use (k%M+m)%m always where k is any no
#define PI 3.1415926535
#define lcm(a,b)  a*b/(__gcd(a,b))
typedef tree<int, null_type, less<int>, rb_tree_tag,
 tree_order_statistics_node_update> pdbs;
// // null for set,mapped_type for map;
// //less for assending greater for descending
//ceil(a/b)=(a+b-1)/b
// v.si-1 can never be negative
#define ghadi() cerr<<"\nTime Taken : "<<(float)(clock()-time_p)/CLOCKS_PER_SEC<<"\n";
clock_t time_p=clock();
#define ee "\n"
#define re return

//Author Rahul Sannigrahi

vector<int> take(int n)
{
    int i,j;
    vi v;
    f(i,0,n)
    {
        cin>>j;
        v.pb(j);
    }
    return v;
}

int power(int x,int y)
{
    int res=1;

    while(y>0)
    {
       if(y&1)
       res=((res%M)*(x%M))%M;

       y=y>>1;
       x=((x%M)*(x%M))%M;
    }
    re res;
}

bool sortinrev(const pair<int,int> &a,  //desc of vp
               const pair<int,int> &b)
{
       return (a.first > b.first);
}

void show(vector<int>v)
{
    int i;
    for(i=0;i<v.si;i++)
    {
     cout<<v[i]<<" ";
    }
    cout<<ee;
}

int gk=1;
int ks=0;

int decode()
{
int i,j,n,k;
cin>>n;
double l,r;
vector<pair<double,double>> v;
f(i,0,n)
{
	cin>>k>>l>>r;
	if(k==1)
	v.pb({l,r});
	else if(k==2)
	v.pb({l,r-.01});
	else if(k==3)
	v.pb({l+.01,r});
	else
	v.pb({l+.01,r-.01});
}

int ans=0;
 sort(all(v));
 // f(i,0,n)
 // cout<<v[i].ff<<" "<<v[i].ss<<endl;
f(i,0,n)
{
	f(j,i+1,n)
	{
		if((v[j].ff>=v[i].ff and v[j].ff<=v[i].ss)||(v[j].ss>=v[i].ff and v[j].ss<=v[i].ss))
		{
		ans++;
		// cout<<v[j].ff<<ee;
		}
	}
}
cout<<ans<<endl;
   re 0;
}

int32_t main()
{
    IOS
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    //  freopen("output.txt","w",stdout);
    // #endif

    int t=1;
       // cin>>t;
    while(t--)
    {
      if (ks)
        {
            cout << "Case #" << gk << ": ";
         gk++;
        }
    decode();
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i, n) for (i = 0; i < n; i++)
#define Fo(i, k, n) for (i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
#define ll long long
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define PI 3.1415926535897932384626
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
//=======================
const int MOD = 1000000007;
const int N = 2e6 + 13, M = N;
//=======================
vi g[N];
int arr[N];
vi a;
int n, m, k;
//=======================

void solve()
{
  int i, j;
  cin >> n;
  string s;
  int q;
  cin >> s >> q;
  int beg = 0;
  fo(i, q)
  {
    int t, a, b;
    cin >> t >> a >> b;
    if (t == 1)
    {
      a--;
      b--;
      if (beg == 0)
      {
        swap(s[a], s[b]);
      }
      else
      {
        if (a >= n)
        {
          a -= n;
        }
        else
        {
          a += n;
        }
        if (b >= n)
        {
          b -= n;
        }
        else
        {
          b += n;
        }
        swap(s[a], s[b]);
      }
    }
    else
    {
      if (beg == 0)
      {
        beg = n;
      }
      else
      {
        beg = 0;
      }
    }
  }
  if(beg == 0) cout << s << endl;
  else {
  for(i = n; i < 2*n; i++) cout << s[i];
  for(i = 0; i < n; i++) cout << s[i];
  }
}

int main()
{
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int t = 1;
  while (t--)
  {
    solve();
  }

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF = 2000000000;
const int MOD = 1e9 + 7;
const int MAX = 30;
vector<vector<ll>> dp(MAX+1,vector<ll>(MAX+1));

string solve(int a,int b, ll k){
    if(a == 0) return string(b,'b');
    if(b == 0) return string(a,'a');
    if(k <= dp[a-1][b]) return string ("a") + solve(a-1,b,k);
    else return string("b") + solve(a,b - 1,k - dp[a-1][b]);
}

int main(){
    ll a,b,k;
    cin >> a >> b >> k;
    dp[0][0] = 1;
    rep(i,a+1){
        rep(j,b+1){
            if(i) dp[i][j] += dp[i-1][j];
            if(j) dp[i][j] += dp[i][j-1];
        }
    }
    cout << solve(a,b,k) << endl;
}


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

typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;

ll ans = 0;
ll get(map<ll, ll> &parent, ll a)
{
    return parent[a] = (parent[a] == a) ? a : get(parent, parent[a]);
}

void merge(map<ll, ll> &parent, map<ll, ll> &rank, ll a, ll b)
{
    a = get(parent, a);
    b = get(parent, b);

    if (a != b)
        ans++;

    if (rank[a] == rank[b])
        rank[a]++;
    if (rank[a] > rank[b])
        parent[b] = a;
    else
        parent[a] = b;
}

void solve()
{
    ll n;
    cin >> n;
    map<ll, ll> parent;
    map<ll, ll> rank;
    vector<ll> a(n);
    for (ll &i : a)
    {
        cin >> i;
        parent[i] = i;
        rank[i] = 1;
    }
    for (ll i = 0; i < n / 2; ++i)
    {
        merge(parent, rank, a[i], a[n - i - 1]);
    }
    cout << ans << endl;
}

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

    //   ll t;
    //   cin >> t;
    //   while (t--)
    //   {
    cout << setprecision(15) << fixed;
    solve();
    //   }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pii pair <int,int>
#define pll pair <ll,ll>
#define testcase() int t; cin>>t; while(t--)
#define forn(i,n) for(int i=0;i<n;i++)
#define forn1(i,n) for(int i=1;i<=n;i++)
#define vll vector <ll>
#define vi vector <int>
#define all(v) v.begin(),v.end()

ll M = 1e9 + 7;
double pi = acos(-1.0);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll powerm(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x)%M; y=y>>1; x=(x*x)%M;} return res%M; }
ll power(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x); y=y>>1; x=(x*x);} return res; }
ll gcd(ll a,ll b){if(b>a)return gcd(b,a); if(b==0)return a; return gcd(b,a%b);}

const int N = 2e5 + 5;
vi adj[N];
vector <bool> vis(N,false);
int cc = 0;

void dfs(int u,int par=-1)
{
    vis[u] = true;
    cc++;
    for(auto it:adj[u])
    {
        if( it == par || vis[it] ) continue;
        dfs(it,u);
    }

}

int main() {

	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

	int n; cin >> n;
    vi a(n);
    forn(i,n) cin >> a[i];
    set <pii> s;
    set <int> kk;
    for(int i=0;i<n/2;i++)
    {
        if( a[i] == a[n-i-1] ) continue;
        pii p = {a[i],a[n-i-1]};
        if( p.ff > p.ss ) swap(p.ff,p.ss);
        if( !s.count(p) )
        {
            adj[a[i]].pb(a[n-i-1]);
            adj[a[n-i-1]].pb(a[i]);
            kk.insert(a[i]);
            kk.insert(a[n-i-1]);
        }
    }

    int ans = 0;
    for(auto it:kk)
    {
        if( vis[it] ) continue;
        cc = 0;
        dfs(it);
        ans += (cc - 1);
    }
    cout << ans << endl;

	return 0;
}


//#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define DB double
#define LD long double
#define ST string
#define BS bitset
#define PA pair<LL,LL>
#define VE vector
#define VL VE<LL>
#define VP VE<PA>
#define VVL VE<VL>
#define VVVL VE<VVL>
#define PQ priority_queue
#define PQS priority_queue<LL,vector<LL>,greater<LL>>
#define FI first
#define SE second
#define PB push_back
#define POB pop_back
#define PF push_front
#define POF pop_front
#define MP make_pair
#define TS to_string
#define TU to_ullong
#define BPL __builtin_popcountll
#define FOR(i,a,n) for(i=a;i<n;++i)
#define FORR(i,a,n) for(i=n-1;i>=a;--i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) FORR(i,0,n)
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define UB(a,n) *upper_bound(ALL(a),n)
#define UBn(a,n) upper_bound(ALL(a),n)-a.begin()
#define LB(a,n) *lower_bound(ALL(a),n)
#define LBn(a,n) lower_bound(ALL(a),n)-a.begin()
#define INF 1000000000000000003
#define PI 3.14159265358979323846264338327950288
//#define MOD 1000000007
#define MOD 998244353
#define ERR 1e-10
#define coutl cout<<fixed<<setprecision(15)
#define FAST cin.tie(0);ios::sync_with_stdio(false)

void Yn(LL a){if(a)cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void YN(LL a){if(a)cout<<"YES"<<endl;else cout<<"NO"<<endl;}
LL pwmn(LL a,LL n){LL ans=1;while(ans<a)ans*=n;return ans;}
LL dig(LL n){LL ret=0;while(n)n/=10,++ret;return ret;}
LL GCD(LL a,LL b){LL c=1,tmp=max(a,b);b=min(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
LL LCM(LL a,LL b){return a*b/GCD(a,b);}
LL cmod(LL a,LL m){if(a%m<0)return a%m+abs(m);else return a%m;}
LL DIV(LL a,LL d,LL m){LL l=m,x=1,y=0,k;while(l){k=d/l;d-=k*l;swap(l,d);x-=k*y;swap(x,y);}return cmod(a*cmod(x,m),m);}
LL POW(LL a,LL n,LL m){LL ans=1;while(n>0){if(n&1)ans=ans*a%m;a=a*a%m;n>>=1;}return ans;}
VL fact,finv,inv;
void comi(LL n){LL i;fact.resize(max(2LL,n+1));finv.resize(max(2LL,n+1));inv.resize(max(2LL,n+1));fact[0]=fact[1]=1;finv[0]=finv[1]=1;inv[0]=inv[1]=1;FOR(i,2,n+1){fact[i]=fact[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
LL com(LL n,LL k){if(n<k||n<0||k<0)return 0;return fact[n]*(finv[k]*finv[n-k]%MOD)%MOD;}
bool cmps(PA a,PA b){if(a.SE!=b.SE)return a.SE<b.SE;return a.FI<b.FI;}
template<typename T>bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>void vout(VE<T> &v){LL i;rep(i,v.size()){cout<<v[i];if(i<v.size()-1)cout<<" ";}cout<<endl;}
template<typename T>void v2out(VE<VE<T>> &v){for(auto a:v)vout(a);}

int main(){
    FAST;
    LL i,ans=0,N,S,D,X,Y;
    cin>>N>>S>>D;
    rep(i,N){
        cin>>X>>Y;
        if(X<S&&Y>D){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;

    //cout<<ans<<endl;
}

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

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long ll;

class BAchieveTheGoal {
public:
	void solve(std::istream& cin, std::ostream& cout) {
		int n,k,m;cin >> n >> k >> m;
        vector<ll> a(n-1);for(int i = 0;i < n-1;i++)cin >> a[i];

        int sum = 0;
        for (int i = 0; i < n-1; ++i)
        {
        	sum += a[i];
        }
        if(sum >= n*m){
        	cout << 0 << endl;
        }else{
        	if(n*m - sum <= k){
        		cout << n*m - sum<< endl;
        	}else{
        		cout << -1 << endl;
        	}
        }
	}
};

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


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

#define REP(i,a,b) for(int i=a;i<=b;i++)
using LL = long long;

const int Nmax=109;
const LL INF=1e18+9;
int N,r;
LL X,A[Nmax],dp[Nmax][Nmax][Nmax],ans=INF;

int main() {
    ios_base::sync_with_stdio(0);    cin.tie(0);
    cin>>N>>X;
    REP(i,1,N) cin>>A[i];
    REP(MOD,1,N) {
        REP(i,0,N) {
            REP(j,0,N) {
                REP(k,0,N-1) dp[i][j][k]=-INF;
            }
        }
        dp[0][0][0]=0;
        REP(i,0,N-1) {
            REP(j,0,MOD) {
                REP(k,0,MOD-1) {
                    if (dp[i][j][k]<0) continue;
                    dp[i+1][j][k]=max(dp[i+1][j][k],dp[i][j][k]);
                    // cout<<i+1<<" "<<j<<" "<<k<<" -- "<<dp[i+1][j][k]<<endl;
                    r=(k+A[i+1])%MOD;
                    dp[i+1][j+1][r]=max(dp[i+1][j+1][r],dp[i][j][k]+A[i+1]);
                    // cout<<i+1<<" "<<j+1<<" "<<r<<" : "<<dp[i+1][j+1][r]<<endl;
                }
            }
        }
        r=X%MOD;
        if (dp[N][MOD][r]>0) ans=min(ans,(X-dp[N][MOD][r])/MOD);
        // cout<<MOD<<" "<<r<<" -> "<<(X-dp[N][MOD][r])/MOD<<endl;
    }
    cout<<ans;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 5;
typedef long long LL;
int n, m, k;
int st[N];
long double a[N], b[N], suma[N], sumb[N];
int main() {
    cin >> n >> m >> k;
    for (int i = 0; i < k; i++) {
        int x;
        cin >> x;
        st[x] = 1;
    }
    for (int i = n - 1; i >= 0; i--) {
        if (st[i]) {
            a[i] = 1;
            b[i] = 0;
        } else {
            a[i] = (suma[i + 1] - suma[i + 1 + m]) / (m * 1.0);
            b[i] = (sumb[i + 1] - sumb[i + 1 + m]) / (m * 1.0) + 1.0;
        }
        suma[i] = suma[i + 1] + a[i];
        sumb[i] = sumb[i + 1] + b[i];
    }
    if (fabs(a[0] - 1.0) < 1e-6)
        puts("-1");
    else
        printf("%.4Lf\n", b[0] / (long double)(1.0 - a[0]));
    return 0;
}


#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;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<(a)<<endl
#define dumparr(a,n) cerr<<#a<<"["<<(n)<<"]="<<(a[n])<<endl
#else
#define dump(a)
#define dumparr(a,n)
#endif
#define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

pll operator+(pll a,pll b){
  return pll(a.first+b.first,a.second+b.second);
}
pll operator-(pll a,pll b){
  return pll(a.first-b.first,a.second-b.second);
}
pll operator*(ll a,pll b){
  return pll(b.first*a,b.second*a);
}
const ll INF=(1LL<<60);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  a=abs(a);
  b=abs(b);
  if(a==0)return b;
  if(b==0)return a;
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif
template<class T>
bool chmax(T& a,const T& b){
  if(a<b){
    a=b;
    return true;
  }
  return false;
}
template<class T>
bool chmin(T& a,const T& b){
  if(a>b){
    a=b;
    return true;
  }
  return false;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}

void solve(long long R, long long C, std::vector<std::vector<long long>> A, std::vector<std::vector<long long>> B){
  vector<vector<pll>> graph(R*C);
  auto id2pair = [C](ll x){
    return pll(x/C,x%C);
  };
  auto pair2id = [C](pll x){
    return x.first*C+x.second;
  };
  For(ii,R*C){
    auto [x,y] = id2pair(ii);
    if(y>0){
      auto jj = pair2id(pll(x,y-1));
      graph[ii].push_back(pll(jj,A[x][y-1]));
      graph[jj].push_back(pll(ii,A[x][y-1]));
    }
    if(x<R-1){
      auto jj = pair2id(pll(x+1,y));
      graph[ii].push_back(pll(jj,B[x][y]));
      graph[jj].push_back(pll(ii,2));
    }
  }
  priority_queue<tuple<ll,ll,ll>,vector<tuple<ll,ll,ll>>,greater<tuple<ll,ll,ll>>> q;
  q.push(make_tuple(0LL,0LL,-INF));
  vector<ll> distances(R*C,INF);
  vector<bool> fromxp1(R*C,false);
  distances[0]=0;
  while(!q.empty()){
    auto [curdist,cur,pre] = q.top();q.pop();
    auto [curx,cury]=id2pair(cur);
    auto [prex,prey]=id2pair(pre);
    for (auto [next,dist] : graph[cur])
    {
      auto [nextx,nexty]=id2pair(next);
      if(curx+1==prex&&nextx+1==curx){
        --dist;
      }
      if(distances[next]>curdist+dist){
        distances[next]=curdist+dist;
        q.emplace(curdist+dist,next,cur);
      }
      if(distances[next]==curdist+dist&&nextx+1==curx&&fromxp1[next]==false){
        fromxp1[next]=true;
        q.emplace(curdist+dist,next,cur);
      }
    }
  }
  cout<<distances[R*C-1]<<endl;
}

int main(){
  cout<<setprecision(1000);
  long long R;
    scanf("%lld",&R);
    long long C;
    scanf("%lld",&C);
    std::vector<std::vector<long long>> A(R, std::vector<long long>(C-1));
    for(int i = 0 ; i < R ; i++){
        for(int j = 0 ; j < C-1 ; j++){
            scanf("%lld",&A[i][j]);
        }
    }
    std::vector<std::vector<long long>> B(R-1, std::vector<long long>(C));
    for(int i = 0 ; i < R-1 ; i++){
        for(int j = 0 ; j < C ; j++){
            scanf("%lld",&B[i][j]);
        }
    }
  solve(R, C, std::move(A), std::move(B));
  return 0;
}

#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
// #include <atcoder/all>

using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vii = V<int>;
using vvll = V<vll>;
using vvii = V< V<int> >;
using PII = P<int, int>;
using PLL = P<ll, ll>;
#define RevREP(i,n,a) for(ll i=n;i>a;i--)  // (a,n]
#define REP(i,a,n) for(ll i=a;i<n;i++)  // [a,n)
#define rep(i, n) REP(i,0,n)
#define ALL(v) v.begin(),v.end()
#define eb emplace_back
#define pb push_back
#define sz(v) int(v.size())

template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
template< class A, class B > ostream& operator <<(ostream& out, const P<A, B> &p) {
    return out << '(' << p.first << ", " << p.second << ')';
}
template< class A > ostream& operator <<(ostream& out, const V<A> &v) {
    out << '[';
    for (int i=0;i<int(v.size());i++) {
        if (i) out << ", ";
        out << v[i];
    }
    return out << ']';
}

template<class A, class B> istream& operator >>(istream& in, P<A, B> &p) {
    return in >> p.first >> p.second;
}
template<class A> istream& operator >>(istream& in, V<A> &v) {
    for (int i = 0; i < int(v.size()); i++) in >> v[i];
    return in;
}

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int t; cin >> t;
    while (t-->0) {
        int n; cin >> n;
        vii p(n);
        cin >> p;

        if (n == 2) {
            if (p[0] > p[1]) {
                cout << 1 << '\n';
                cout << 1 << '\n';
            } else {
                cout << 0 << '\n';
                cout << '\n';
            }
            continue;
        }

        vii ans;
        for (int tor = n; tor > 3; tor--) {
            int j = 1;
            for (; j <= n; j++) if (p[j - 1] == tor) break;
            if (j == tor) continue;
            if (sz(ans) & 1) {  // guusuu kaime
                if (j & 1) {
                    if (j == 1) {
                        ans.eb(j + 1), swap(p[j], p[j + 1]);
                    } else {
                        ans.eb(j - 1), swap(p[j - 2], p[j - 1]);
                        ans.eb(j), swap(p[j - 1], p[j]);
                        j--;
                    }
                }
                for (int k = j; k < tor; k++) {
                    ans.eb(k);
                    swap(p[k - 1], p[k]);
                }
            } else {  // kisuu kaime
                if (!(j & 1)) {
                    ans.eb(j - 1), swap(p[j - 2], p[j - 1]);
                    ans.eb(j), swap(p[j - 1], p[j]);
                    j--;
                }
                for (int k = j; k < tor; k++) {
                    ans.eb(k);
                    swap(p[k - 1], p[k]);
                }
            }
        }
        cerr << p << '\n';

        while (!(p[0] == 1 and p[1] == 2 and p[2] == 3)) {
            if (sz(ans) & 1) {
                ans.eb(2);
                swap(p[1], p[2]);
            } else {
                ans.eb(1);
                swap(p[0], p[1]);
            }
        }

        cout << sz(ans) << '\n';
        rep(i, sz(ans)) {
            if (i) cout << ' ';
            cout << ans[i];
        }
        cout << '\n';
    }
    return 0;
}


//#include <atcoder/all>
//using namespace atcoder;
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPR(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)
#define ALL(v) v.begin(), v.end()
#define bit(n) (1LL<<(n))
#define FIX(d) fixed << setprecision(d)
using P = pair<int, int>;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const ll LINF = (1LL<<60);

int MOD;

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

ll modinv(ll a) {
  ll b = MOD, u = 1, v = 0;
  while(b) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= MOD;
  if(u < 0) u += MOD;
  return u;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n,m; cin >> n >> m;
  MOD = m*m;
  ll ans = modpow(10, n);
  cout << ans/m << endl;

  return 0;
}

//c++ テンプレ
#include<bits/stdc++.h>
using namespace std;

typedef long long llint;
typedef long double ld;

#define inf 1e18
#define mod 1000000007
#define sort(v) sort(v.begin(),v.end())
#define reverse(v) reverse(v.begin(),v.end())
#define rep(i,a,n) for(int i=a;i<n;i++)

priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> Que;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

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

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


#include <iostream>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
#include <queue>
#include <unordered_map>
using namespace std;
#define int long long
#define pii pair<long long, long long>
const double pi = acos(-1);
const int maxn = 3e5 + 5;
const int mod = 1000000007;
int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int a,b,x,y;
  cin >> a >> b >> x >> y;
  y = min(y,x*2);
  if(a > b) a--;
  cout << abs(a-b) * y + x << endl;
  return 0;
}


#include <cstdio>
#include <algorithm>
#define N 200010
using namespace std;
long long n,k,cur=0;
struct node{
	long long a,b;
	bool operator<(const node x)const{
		return a<x.a;
	}
}c[N];
int main(){
	scanf("%lld%lld",&n,&k);
	for(int i=1;i<=n;i++)
		scanf("%lld%lld",&c[i].a,&c[i].b);
	sort(c+1,c+1+n);
	for(int i=1;i<=n;i++){
		if(cur+k<c[i].a){
			printf("%lld",cur+k);
			return 0;
		}
		k=c[i].b-c[i].a+cur+k;
		cur=c[i].a;
	}
	printf("%lld",cur+k);
	return 0;
}

//Radhe Radhe
#include<bits/stdc++.h>
#define FASTIO_  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mod 1000000007

#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define en '\n'
#define itr(i,n)    for(ll i=0; i<n; i++)
#define itr_ab(i,a,b)    for(ll i=a; i<=b; i++)
#define itrV(i,n)    for(ll i=0; i<v.size(); i++)
#define fixed cout.setf(ios::fixed);
#define precise cout.precision(2);
#define Dont_Quit int main(void)
#define Avada_Kedavra return 0;
#define yes cout<<"Yes"<<'\n'
#define no cout<<"No"<<'\n'
using namespace std;
bool cmp(const pair<ll,ll>&a,const pair<ll,ll>&b)
{
    if(a.fi<b.fi) return 1;
    return 0;
}
Dont_Quit
{
    FASTIO_
    ll t,n,i,j,k,ans;
    t=1;
    while(t--)
    {
        ll n,k,ans;
        cin>>n>>k;
        ans=k;
        ll a[n],b[n],cur=0;
        bool ok=1;
        vector<pair<ll,ll>>v;
        itr(i,n)
        {
            cin>>a[i]>>b[i];
            v.pb(mp(a[i],b[i]));
        }
        sort(v.begin(),v.end(),cmp);
        for(auto it:v)
        {
            if(ans>=it.fi) ans+=it.se;
            else break;
        }

        cout<<ans<<en;

    }

    Avada_Kedavra
}


//doit4von
//LLJW
//999
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
const long long mod=pow(10,9)+7;
typedef long long ll;
#define pb push_back
#define vi vector<int>
#define sz(x) (int)(x).size()
void google(int tc)
{
    cout<<"Case #"<<tc<<": ";
}
ll convert(string z)
{
      ll ans=0;
      int count=0;
      for(int i=z.length()-1;i>=0;i--)
      {
            ans=ans+(z[i]-'0')*pow(10,count);
            count++;
      }
      return ans;
}
bool palindrome(const string &s) {
    int n = s.length();
    for(int i = 0; i < n; i++) {
        if(s[i] != s[n - i - 1]) return false;
    }
    return true;
}
bool primecheck(long long int z)
{
      for(long long int i=2;i*i<=z;i++)
      {
            if(z%i==0)
            return false;
      }
      return true;
}
string boolean (int y)
{
      string ans="";
      while(y>0)
      {
            ans=(char)('0'+y%2)+ans;
            y=y/2;
      }
      return ans;
}
ll rem(ll x)
{
      ll ans=0;
      while(x>0)
      {
            if(x%10)
            ans=ans*10+x%10;
            x=x/10;
      }
      return ans;
}
/*ll total=0;
ll no=0;
bool visited[N];
vector  <int> v[N];
int n;
void dfs(int curr ,int level)// curr=current node level=number of nodes travelled to reach there
{
      if(visited[curr]==true)
      return;
      visited[curr]=true;
      for(auto y : v[curr])
      dfs(y,level+1);
      if(v[curr].size()==1 && curr!=1)
      {
            total=total+level;
            no++;
      }
}*/
int SieveOfEratosthenes(int n)
{
    bool prime[n + 1];
    memset(prime, true, sizeof(prime));
    for (int p = 2; p * p <= n; p++)
    {
        if (prime[p] == true)
        {
            for (int i = p * p; i <= n; i += p)
            prime[i] = false;
        }
    }
    int ans=0;
    for (int p = 2; p <= n; p++)
        ans+=prime[p];
    return ans;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin>>n;
map <int,int> a;
for(int i=0;i<n;i++)
{
    int ex;
    cin>>ex;
    a[ex]++;
}
int b[n+2];
for(int i=1;i<=n;i++)
cin>>b[i];
ll ans=0;
for(int j=0;j<n;j++)
{
    int ex;
    cin>>ex;
    ans=ans+a[b[ex]];
}
cout<<ans;
}

/* Vineeth Kada */

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

#define int long long
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define rep(i,a,b) for(int i=a; i<=b; i++)
#define rrep(i,a,b) for(int i=a; i>=b; i--)
#define inf(dtype) numeric_limits<dtype>::max()

int Solve(){
    int n; cin >> n;
    int a[n+1], b[n+1], c[n+1];
    rep(i, 1, n) cin>>a[i];
    rep(i, 1, n) cin>>b[i];
    rep(i, 1, n) cin>>c[i];
    map<int, int> hm;
    rep(i, 1, n) hm[c[i]]++;
    int ans[n+1];
    rep(i, 1, n){
        ans[i] = 0;

    }
    rep(i, 1, n){
        ans[b[i]] += hm[i];
    }
    int output = 0;
    rep(i, 1, n){
        output += ans[a[i]];
    }
    cout << output << endl;
    return 1;
}

int32_t main(){
    ios_base::sync_with_stdio(false), cin.tie(NULL);
    int t = 1;
    // cin >> t;
    while(t--) Solve();
    return 0;
}


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

typedef long long ll;
int n;
const int maxn = 1e5 + 233;
int c[maxn], d[maxn];

int main(){
	vector<int> a, b;
	scanf("%d", &n);
	ll res = 0;
	for(int i = 1; i <= n; i++){
		scanf("%d", &c[i]);
		res += c[i];
	}
	for(int i = 1; i <= n; i++){
		scanf("%d", &d[i]);
		if(i & 1) a.push_back(d[i] - c[i]);
		else b.push_back(d[i] - c[i]);
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end());
	while(!a.empty() && a.back() + b.back() > 0){
		res += a.back() + b.back();
		a.pop_back();
		b.pop_back();
	}
	printf("%lld\n", res);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair < int , int > pii;
#define mpr make_pair
#define FS first
#define SC second
#define PB push_back
template < typename T > void UMAX(T &a,T b){a=(a>b?a:b);}
template < typename T > void UMIN(T &a,T b){a=(a<b?a:b);}
LL readint(){
	char c=getchar();
	LL ret=0ll;
	bool neg=0;
	while(!(c>='0' && c<='9')){
		if(c=='-') neg=1;
		c=getchar();
	}
	while(c>='0' && c<='9'){
		ret=ret*10ll+(LL)(c-'0');
		c=getchar();
	}
	return neg?-ret:ret;
}
void putint(LL v){
	if(v<0){
		putchar('-');
		v=-v;
	}
	if(!v){
		putchar('0');
		return;
	}
	if(v>=10ll) putint(v/10ll);
	putchar('0'+(v%10ll));
}
int n,f[100005][2];
int main(){
	int i,j,k;
	n=readint();
	for(i=0;i<n;++i) f[i][i&1]=readint();
	for(i=0;i<n;++i) f[i][!(i&1)]=readint();
	LL sum=0;
	priority_queue < int > pq;
	for(i=0;i<n;++i){
		sum+=f[i][0];
		pq.push(f[i][1]-f[i][0]);
	}
	for(i=0;i<n/2;++i){
		sum+=pq.top();
		pq.pop();
	}
	printf("%lld\n",sum);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define ll long long

int main()
{
    int n,m,t;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        n+=m;
        if(n>=15&&m>=8)t=1;
        else if(n>=10&&m>=3)t=2;
        else if(n>=3)t=3;
        else t=4;
        printf("%d\n",t);
    }
}

#include <iostream>
using namespace std;
int a,b,c,d,e;
int main(void){
    cin>>a>>b>>c>>d;
    if((a+b+c+d)%2==1){cout<<"No"<<endl;return 0;}
    e=(a+b+c+d)/2;
    if(a+b==e)cout<<"Yes"<<endl;
    else if(a+c==e)cout<<"Yes"<<endl;
    else if(a+d==e)cout<<"Yes"<<endl;
    else if(b+c==e)cout<<"Yes"<<endl;
    else if(b+d==e)cout<<"Yes"<<endl;
    else if(d+c==e)cout<<"Yes"<<endl;
    else if(a==e)cout<<"Yes"<<endl;
    else if(b==e)cout<<"Yes"<<endl;
    else if(c==e)cout<<"Yes"<<endl;
    else if(d==e)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


#include <bits/stdc++.h>

#define rep(i, n) for (auto i = 0; i < n; ++i)
#define ALL(a) a.begin(), a.end()

using namespace std;

using ll = long long int;

const int MOD_NUM = 1e9 + 7;

int main() {
    // Input
    int N, Q;
    string S;
    cin >> N >> S >> Q;
    vector<int> T(Q), A(Q), B(Q);
    rep(i, Q) cin >> T[i] >> A[i] >> B[i];

    // Process
    string ans(S);
    int reverse = 0;
    rep(i, Q) {
        if (T[i] == 1) {
            int a = A[i] - 1;
            int b = B[i] - 1;
            if (reverse % 2 == 1) {
                a = (a + N) % (N * 2);
                b = (b + N) % (N * 2);
            }

            char tmp = ans[a];
            ans[a] = ans[b];
            ans[b] = tmp;
        } else
            reverse++;
    }
    if (reverse % 2 == 1) {
        string tmp1 = ans.substr(N);
        string tmp2 = ans.substr(0, N);
        ans = tmp1 + tmp2;
    }

    // Output
    cout << ans << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const ll inf = (1ll << 63) - 1;

array<ll, 3> egcd(ll a, ll b) {
    ll s0 = 1, t0 = 0, s1 = 0, t1 = 1;
    while (b) {
        ll d = a / b;
        tie(a, b) = make_pair(b, a % b);
        tie(s0, s1) = make_pair(s1, s0 - d * s1);
        tie(t0, t1) = make_pair(t1, t0 - d * t1);
    }
    return {a, s0, t0};
}

pair<ll, ll> crt(const vector<ll> &r, const vector<ll> &m) {
    ll r0 = 0, m0 = 1;
    for (int i = 0; i < int(r.size()); i++) {
        ll r1 = r[i] % m[i], m1 = m[i];
        auto [g, x, y] = egcd(m0, m1);
        if ((r1 - r0) % g) return {0, 0};

        r0 = (r0 + m0 * ((x * (r1 - r0) / g) % (m1 / g))) % (m0 * m1 / g);
        m0 *= m1 / g;
        if (r0 < 0) r0 += m0;
    }

    return {r0, m0};
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        ll x, y, p, q;
        cin >> x >> y >> p >> q;

        ll ans = inf;
        for (ll i = x; i < x + y; i++) {
            for (ll j = p; j < p + q; j++) {
                auto [r, n] = crt({i, j}, {2 * (x + y), p + q});
                if (n) ans = min(r, ans);
            }
        }

        if (ans == inf) cout << "infinity";
        else cout << ans;
        cout << '\n';
    }
}

#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
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; }

constexpr int MOD = 1'000'000'007;

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

void solve() {
    LL n,a,b;
    cin >> n >> a >> b;
    if (a + b > n) {
        cout << 0 << endl;
        return;
    }
    LL ap = n - a + 1, bp = n - b + 1, cp = n - a - b + 1;
    LL x4 = (cp * (cp + 1) / 2) % MOD;
    LL x3 = (x4 * 2) % MOD;
    LL x2 = (ap * bp - x3) % MOD;
    LL x1 = sqr(x2) % MOD;
    LL ans = ((sqr(ap)%MOD) * (sqr(bp)%MOD) - x1) % MOD;
    if (ans < 0) ans += MOD;
    cout << ans << endl;
}

signed main() {
    int t;
    cin >> t;
    REP(i,0,t) solve();

    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define pii pair<int,int>
#define piii pair<int,pii>
#define sp " "
#define nl "\n"
#define all(x) x.begin(),x.end()
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);
#define ll long long
#define int ll

using namespace std;

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

int fac[11],cnto,cnts,ans;
string s;

void factorial(){
    fac[0]=1;
    for(int i=1;i<=10;i++)
        fac[i]=fac[i-1]*i;
}

int comb(int n,int r){
    return fac[n]/(fac[r]*fac[n-r]);
}

signed main(){
    #ifndef ONLINE_JUDGE
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif
    fastio()
    factorial();
    cin >> s;
    for(int i=0;i<10;i++){
        cnto+=(s[i]=='o');
        cnts+=(s[i]=='?');
    }
    if(cnto>4){
        cout << 0 << nl;
        return 0;
    }
    for(int i=0;i<=cnts;i++){
        if(cnto+i==0)
            continue;
        else if(cnto+i==1){
            ans+=comb(cnts,i);
        }
        else if(cnto+i==2){
            ans+=comb(cnts,i)*(2*4+6);
        }
        else if(cnto+i==3){
            ans+=comb(cnts,i)*3*12;
        }
        else if(cnto+i==4){
            ans+=comb(cnts,i)*24;
        }
        else
            break;
    }
    cout << ans << nl;
}

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

#ifndef _LOCAL
int main() {
    string s;
    cin >> s;
    ll ans = 0ll;
    vector<bool> must(10, false);
    vector<bool> must_not(10, false);
    for(int i = 0; i < 10; i++) {
        if(s[i] == 'o') {
            must[i] = true;
        } else if(s[i] == 'x') {
            must_not[i] = true;
        }
    }

    for(int a = 0; a < 10; a++) {
        for(int b = 0; b < 10; b++) {
            for(int c = 0; c < 10; c++) {
                for(int d = 0; d < 10; d++) {
                    vector<bool> p_must(10, false);
                    p_must[a] = p_must[b] = p_must[c] = p_must[d] = true;
                    bool ok = true;
                    for(int i = 0; i < 10; i++) {
                        if(must[i] && !p_must[i]) {
                            ok = false;
                        }
                        if(must_not[i] &&
                           (a == i || b == i || c == i || d == i)) {
                            ok = false;
                        }
                    }
                    if(ok) {
                        ans++;
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}
#endif


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(long long i=(long long)(a);i<(long long)(b);i++)
#define ALL(a)  (a).begin(),(a).end()
typedef long long ll;
typedef pair<ll,ll> P;

ll a[5151],t[5155],c[5151],g[5151];

int main(){
    ll n;
    string s;
    cin>>n>>s;
    rep(i,0,n){
        if(s[i]=='A')a[i+1]++;
        a[i+1]+=a[i];
        if(s[i]=='T')t[i+1]++;
        t[i+1]+=t[i];
        if(s[i]=='C')c[i+1]++;
        c[i+1]+=c[i];
        if(s[i]=='G')g[i+1]++;
        g[i+1]+=g[i];
    }
    ll an=0;
    rep(i,0,n){
        rep(j,i+1,n+1){
            if(a[j]-a[i]==t[j]-t[i]&&c[j]-c[i]==g[j]-g[i])an++;
        }
    }
    cout<<an<<endl;
}

#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define pb push_back
#define f first
#define s second
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<piii> viii;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MAXN = 5000100, MAXK = 23;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e16;
const ld PI = asin(1) * 2;

void setIO () {
    FAST_IO;
}

void setIO (string s) {
    setIO();
    freopen((s+".in").c_str(),"r",stdin);
    freopen((s+".out").c_str(),"w",stdout);
}

int n, k;
int x;
vi adj[MAXN];
int dp[MAXN];
int cnt[MAXN];

void dfs (int v, int p = -1) {
    cnt[v] = 0;
    dp[v] = 0;
    int mn = 0, mx = 0;
    for (int u : adj[v]) {
        if (u == p) continue;
        dfs (u, v);
        cnt[v] += cnt[u];
        mn = min(mn, dp[u]+1);
        mx = max(mx, dp[u]+1);
    }
    //if (mx)
    if (mn+1 + mx <= 0) {
        dp[v] = mn;
    } else if (mx == x || v==1){
        dp[v] = -x-1;
        cnt[v]++;
    } else {
        dp[v] = mx;
    }

    //cout << "    v = " << v << " cnt = " << cnt[v] << " dp = " << dp[v] << endl;
}

int main() {
    setIO();

    cin >> n >> k;
    REP(n-1) {
        int u, v; cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
   /*
    if (k == n) {
        cout << "0\n";

    }*/

    int le = 1, ri = n;
    while (le < ri) {
        FOR(i, 1, n) cnt[i] = dp[i] = 0;
        x = (le+ri)/2;
       // cout << " x = " << x << endl;
        dfs (1);
        if (cnt[1] <= k) ri = x;
        else le = x+1;
    }

    cout << le << "\n";

    return 0;
}

/*

10 2
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
ans: 2

*/