#include <bits/stdc++.h>
using namespace std;
using gg = long long;
// MAX
// constexpr gg MAX = 25;
constexpr gg MAX = 1e6 + 5;
constexpr gg mod = 998244353;
constexpr gg INF = 2e18;
constexpr double thre = 1e-7;
gg ti, ni, mi, ki, di, pi, xi, yi;
//返回a^b%m
gg powMod(gg a, gg b, gg m) {
    if (m == 1) {
        return 0;
    }
    a %= m;
    gg ans = 1;
    while (b > 0) {
        if (b & 1)
            ans = ans * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return ans;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> ni >> mi >> ki;
    if (ni == 1 or mi == 1) {
        cout << powMod(ki, max(ni, mi), mod) << "\n";
        return 0;
    }
    gg ans = 0;
    for (gg x = 1; x <= ki; ++x) {
        ans = (ans + (powMod(x, ni, mod) - powMod(x - 1, ni, mod) + mod) % mod *
                         powMod(ki - x + 1, mi, mod) % mod) %
              mod;
    }
    cout << ans;
    return 0;
}

#include <bits/stdc++.h>
#define ll long long
#define V vector<long long>
#define VV vector<vector<long long>>
#define VVV vector<vector<vector<long long>>>
#define P pair<ll,ll>
#define rep(i,n) for(ll (i)=0;(i)<(n);++(i))
#define per(i,n) for(ll (i)=(n)-1;(i)>=0;--(i))
#define inf 9223372036854775807
#ifdef LOCAL
#define debug(x) cerr<<__LINE__<<": "<<#x<<"="<<x<<endl;
#define debugALL(x) cerr<<__LINE__<<": "<<#x<<"=";for(auto i=(x).begin();i!=--(x).end();i++)cerr<<*i<<" ";cerr<<*--(x).end()<<endl;
#else
#define debug(x) true
#define debugALL(x) true
#endif
using namespace std;

inline long long mod(long long a, long long m) {
    return (a % m + m) % m;
}

// 拡張 Euclid の互除法
// ap + bq = gcd(a, b) となる (p, q) を求め、d = gcd(a, b) をリターンします
long long extGcd(long long a, long long b, long long &p, long long &q) {
    if (b == 0) { p = 1; q = 0; return a; }
    long long d = extGcd(b, a%b, q, p);
    q -= a/b * p;
    return d;
}

// 中国剰余定理
// リターン値を (r, m) とすると解は x ≡ r (mod. m)
// 解なしの場合は (0, -1) をリターン
pair<long long, long long> ChineseRem(long long b1, long long m1, long long b2, long long m2) {
  long long p, q;
  long long d = extGcd(m1, m2, p, q); // p is inv of m1/d (mod. m2/d)
  if ((b2 - b1) % d != 0) return make_pair(0, -1);
  long long m = m1 * (m2/d); // lcm of (m1, m2)
  long long tmp = (b2 - b1) / d * p % (m2/d);
  long long r = mod(b1 + m1 * tmp, m);
  return make_pair(r, m);
}

int main(){
    ll t;
    cin>>t;
    rep(i,t){
        ll x,y,p,q;
        cin>>x>>y>>p>>q;
        ll c=2*x+2*y;
        ll d=p+q;
        ll ans=inf;
        rep(i,y){
            rep(j,q){
                ll a=x+i;
                ll b=p+j;
                auto p=ChineseRem(a,c,b,d);
                if(p.second!=-1)ans=min(ans,p.first);
            }
        }
        if(ans==inf)cout<<"infinity"<<endl;
        else cout<<ans<<endl;
    }
}


#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main(){
    ll n;
    cin>>n;
    set<ll> s;
    for(ll i=2; i*i<=n; i++){
        ll x=i*i;
        while(x<=n){
            s.insert(x);
            x*=i;
        }
    }
    cout<<n-s.size()<<endl;
}

#include <bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include <atcoder/all>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

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

//using lll=boost::multiprecision::cpp_int;
template <class T>
inline bool chmin(T &a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}

template <typename T>
T mypow(T x, T n, const T &p = -1)
{ //x^nをmodで割った余り
	T ret = 1;
	while (n > 0)
	{
		if (n & 1)
		{
			if (p != -1)
				ret = (ret * x) % p;
			else
				ret *= x;
		}
		if (p != -1)
			x = (x * x) % p;
		else
			x *= x;
		n >>= 1;
	}
	return ret;
}

using namespace std;
// using namespace atcoder;

template<int mod>
struct Modint{
    int x;
    Modint():x(0){}
    Modint(int64_t y):x((y%mod+mod)%mod){}

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

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

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

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

		Modint operator-() const { return Modint(-x); }
		Modint operator+(const Modint &p) const{
			return Modint(*this) += p;
		}
		Modint operator-(const Modint &p) const{
			return Modint(*this) -= p;
		}
		Modint operator*(const Modint &p) const{
			return Modint(*this) *= p;
		}
		Modint operator/(const Modint &p) const{
			return Modint(*this) /= p;
		}

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

		Modint inverse() const{//非再帰拡張ユークリッド
			int a = x, b = mod, u = 1, v = 0;
			while(b>0){
				int t = a / b;
				swap(a -= t * b, b);
				swap(u -= t * v, v);
			}
			return Modint(u);
		}

		Modint pow(int64_t n) const{//繰り返し二乗法
			Modint ret(1), mul(x);
			while(n>0){
				if(n&1)
					ret *= mul;
				mul *= mul;
				n >>= 1;
			}
			return ret;
		}

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

using modint = Modint<mod>;

vector< bool > prime_table(int n) {
  vector< bool > prime(n + 1, true);
  if(n >= 0) prime[0] = false;
  if(n >= 1) prime[1] = false;
  for(int i = 2; i * i <= n; i++) {
    if(!prime[i]) continue;
    for(int j = i + i; j <= n; j += i) {
      prime[j] = false;
    }
  }
  return prime;
}

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

	ll ans=n;
	map<ll,ll>mp;
	for(ll i=2;i*i<=n;++i){
		if(mp.count(i))continue;
		for(ll j=i*i;j<=n;j*=i){
			ans--;
			mp[j]=true;
		}
	}
	cout<<ans;
}

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


#include <iostream>
#include <vector>
#include <set>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> p(n + 1), pos(n + 1), ans;
    set<int> s;
    for (int i = 1; i <= n; ++i) {
        cin >> p.at(i), pos.at(p.at(i)) = i;
        if (i != n) s.insert(i);
    }
    for (int i = 1; i <= n; ++i) {
        while (pos.at(i) > i) {
            if (s.count(pos.at(i) - 1)) ans.push_back(pos.at(i) - 1), s.erase(pos.at(i) - 1), --pos.at(i), ++pos.at(p.at(pos.at(i))), swap(p.at(pos.at(i)), p.at(pos.at(i) + 1));
            else {
                cout << "-1\n";
                return 0;
            }
        }
        while (pos.at(i) < i) {
            if (s.count(pos.at(i) + 1)) ans.push_back(pos.at(i) + 1), s.erase(pos.at(i) + 1), ++pos.at(i), --pos.at(p.at(pos.at(i))), swap(p.at(pos.at(i)), p.at(pos.at(i) - 1));
            else {
                cout << "-1\n";
                return 0;
            }
        }
    }
    if (s.size()) cout << "-1\n";
    else for (const auto& i : ans) cout << i << '\n';
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int sz = 2e5+5;

int n, a[sz], w[sz], bit[sz];

void add(int x) {
   while(x <= n) {
      bit[x]++;
      x += x & (-x);
   }
}

int quer(int x) {
   int ans = 0;
   while(x) {
      ans += bit[x];
      x -= x & (-x);
   }
   return ans;
}

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

   int tot = 0;
   vector <int> res;
   for(int i=n; i; i--) {
      int x = quer(w[i]);
      if(x) tot += x, res.push_back(x);
      add(w[i]);
   }
   if(tot == n-1) {
      reverse(res.begin(), res.end());
      int s = 0;
      for(int x : res) {
         for(int i=s+x; i>s; i--) printf("%d\n", i);
         s += x;
      }
   }
   else puts("-1");
}


#include <bits/stdc++.h>
using namespace std;
int main(){
  string n;
  cin >> n;
  long long sum = 0;
  for(long long i=0;i<n.length();++i){
    sum += n[i] - '0';
  }
  if(sum%3 == 0){
    cout << 0 << endl;
    return 0;
  }

  if(n.length() == 1){
    cout << -1 << endl;
    return 0;
  }

  for(long long i=0;i<n.length();++i){
    if(sum%3 == (n[i] - '0')%3) {
      cout << 1 << endl;
      return 0;
    }
  }
  if(n.length() == 2){
    cout << -1 << endl;
    return 0;
  }

  cout << 2 << endl;
  return 0;
}

#include<iostream>
using namespace std;
typedef long long li;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }

int ceil2(int a){
  int ret=a,i=1;
  while((ret>>i)!=0){
    ret|=ret>>i;
    i<<=1;
  }
  ret++;
  if(a==(ret>>1)) return a;
  return ret;
}

int main(){
  int n;  cin >>n;
  int t=ceil2(n+1);

  auto f=[&](int a){
           return (a-1)%t+1;
         };
  auto g=[&](int a){
           return f(a)-((f(a)>n)?(t/2):0);
         };

  rep(_i,n){
    int i=_i+1;
    print(g(2*i),g(2*i+1));
  }

}


#include <bits/stdc++.h>

#define ms(a,b) memset(a, b, sizeof(a))
#define rep(a,b,c) for(int a = (int)(b); a < (int)(c); a++)
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define m_p(a,b) make_pair(a, b)
#define lson l,mid,o << 1
#define rson mid + 1,r,o << 1 | 1
#define ls o << 1
#define rs o << 1 | 1
#define inf 0x3f3f3f3f

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int,int> pii;

inline bool isdigit(char& ch) {
    return ch >= '0' && ch <= '9';
}
template<class T>
void read(T &x) {
    x = 0;
    ll f = 1;char ch = getchar();
    for (;!isdigit(ch);ch = getchar())
        if (ch == '-') f = -1;
    for (; isdigit(ch);ch = getchar())
        x = (x << 1) + (x << 3) + ch - '0';
    x *= f;
}
template<class T>
inline void write(T x) {
    if (x == 0) {putchar('0');return ;}
    if (x < 0) {putchar('-');x = -x;}
    int _stk[65],_top = 0;
    for (;x;x /= 10) _stk[++_top] = x % 10 + 48;
    for (;_top;_top--)putchar(_stk[_top]);
}

const int MAXN = 2e5 + 100;

int f[MAXN][7];
int n;
string S, X;

bool dp(int i, int j) {
    if (i == n + 1)
        return (j == 0);
    if (~f[i][j])
        return f[i][j];
    if (X[i] == 'T')
        f[i][j] = (dp(i + 1, j * 10 % 7) | dp(i + 1,(j * 10 + S[i] - '0') % 7));
    else
        f[i][j] = (dp(i + 1, j * 10 % 7) & dp(i + 1,(j * 10 + S[i] - '0') % 7));
    return f[i][j];
}

int main () {
    cin >> n >> S >> X;
    S = ' ' + S;
    X = ' ' + X;
    ms(f, -1);
    if (dp(1, 0))
        cout << "Takahashi";
    else
        cout << "Aoki";
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = false;
//---------------------------------//

int main() {
	int N, M, K;
	cin >> N >> M >> K;
	vector<int> A(K);
	REP(i, K) cin >> A[i];
	vector<bool> inA(N);
	for (int a : A) inA[a] = true;

	{
		int p = 0;
		while (p < N) {
			bool update = false;
			for (int i = M; i >= 1; --i) {
				if (p + i < N && inA[p + i]) continue;
				update = true;
				p += i;
				break;
			}
			if (!update) { puts("-1"); return 0; }
		}
	}

	vector<double> dp0(N + 1), dp(N + 1);
	double s0 = 0, s = 0;
	for (int i = N - 1; i >= 0; --i) {
		if (i + M + 1 <= N) { s0 -= dp0[i + M + 1] / M; s -= dp[i + M + 1] / M; }

		if (inA[i]) { dp0[i] = 1; dp[i] = 0; }
		else { dp0[i] = s0; dp[i] = s + 1; }

		s0 += dp0[i] / M;
		s += dp[i] / M;
	}

	double ans = dp[0] / (1 - dp0[0]);
	printf("%.16f\n", ans);
}


#include<bits/stdc++.h>

using namespace std;

#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD 1000000007
#define MOD1 998244353
#define INF 1e18

typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
// typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update > pbds; // find_by_order, order_of_key
#define pii pair<int,int>

void solve(){
    int n;
    cin>>n;
    vector<int> w(n);
    ll sum=0;
    for (int i = 0; i < n; ++i) {
        cin>>w[i];
        sum += w[i];
    }
    if(sum&1){
        cout<<0<<"\n";
        return;
    }
    ll req = sum/2;
    vector<vector<int>> dp(n+1,vector<int>(req+1,0)); // dp[i][j] gives the no of ways to get sum j with i elements

    ll fact[104];
    fact[0]=1;
    for(int i=1;i<104;i++){
        fact[i] = fact[i-1]*i;
        fact[i]%=MOD1;
    }
    dp[0][0]=1;
    for (int i = 0; i < n; ++i) {
        for (int j = i; j >= 0; --j) {
            for (int k = 0; k <= j*100; ++k) {
                if(k+w[i] <=req){
                    dp[j+1][k+w[i]] += dp[j][k];
                    dp[j+1][k+w[i]] %=MOD1;
                }
            }
        }
    }
    ll ans=0;
    for(int i=1;i<n;i++){
        ll curr = ((fact[n-i]*fact[i])%MOD1)*dp[i][req];
        curr %=MOD1;
        ans += curr;
        ans %= MOD1;
    }
    cout<<ans%MOD1<<"\n";
}

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

#include<map>
#include<set>
#include<list>
#include<ctime>
#include<cmath>
#include<deque>
#include<queue>
#include<stack>
#include<string>
#include<vector>
#include<bitset>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<complex>
#include<iostream>
#include<algorithm>
#define rep(i,s,t) for(register int i=s;i<=t;++i)
#define _rep(i,s,t) for(register int i=s;i>=t;--i)
#define Rep(i,s,t) for(register int i=s;i<t;++i)
#define go(x) for(register int e=las[x];e;e=nxt[e])
#define re register
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define is insert
#define es erase
#define pii pair<int,int>
#define ms(f,x) memset(f,x,sizeof f)
#define mc(f,x) memcpy(f,x,sizeof f)
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
#define gi(x) read(x)
#define gii(x,y) read(x),read(y)
#define giii(x,y,z) read(x),read(y),read(z)
namespace IO{
    #define gc getchar()
    #define pc(x) putchar(x)
    template<typename T>inline void read(T &x){
        x=0;int f=1;char ch=gc;while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=gc;}
        while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=gc;x*=f;return;
    }
    template<typename T>inline void write(T x=0){
        T wr[51];wr[0]=0;if(x<0)pc('-'),x=-x;if(!x)pc(48);
        while(x)wr[++wr[0]]=x%10,x/=10;while(wr[0])pc(48+wr[wr[0]--]);
		putchar('\n');return;
    }
}
using IO::read;
using IO::write;
typedef long long ll;
typedef double db;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;
const int N=111,mod=998244353;
int f[N][N*N];
int n,x,sum,fac[N];
void inc(int &x,int y){
	x+=y;
	if(x>=mod)
		x-=mod;
}
int main(){
	gi(n);
	f[0][0]=1;
	fac[0]=1;
	rep(i,1,n)
		fac[i]=1ll*fac[i-1]*i%mod;
	rep(i,1,n){
		gi(x);
		sum+=x;
		_rep(k,i,1)
			_rep(j,sum,x)
				inc(f[k][j],f[k-1][j-x]);
	}
	if(sum&1){
		puts("0");
	}
	else{
		int ans=0;
		rep(i,0,n)
			ans=(ans+1ll*f[i][sum/2]*fac[i]%mod*fac[n-i])%mod;
		cout<<ans<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
#define all(i) (i).begin(), (i).end()
#define debug(x) cerr << "Line(" << __LINE__ << ") -> " << #x << " is " << x << endl
using namespace std;
template<typename T1, typename T2>
ostream& operator << (ostream &i, pair<T1, T2> j) {
    return i << j.first << ' ' << j.second;
}
template<typename T>
ostream& operator << (ostream &i, vector<T> j) {
    i << '{' << j.size() << ':';
    for (T ii : j) i << ' ' << ii;
    return i << '}';
}
template<typename T>
ostream& operator << (ostream &i, set<T> j) {
    i << '{' << j.size() << ':';
    for (T ii : j) i << ' ' << ii;
    return i << '}';
}
typedef long long ll;
typedef pair<int, int> pi;
const int inf = 1e9;
const ll mod = 1e9 + 7;
vector<vector<int>> g;
vector<int> v;
int v1, v2;
void dfs(int i, int p) {
    v[i] = ~p ? v[p] + 1 : 0;
    v2 = v[i] > v[v2] ? i : v2;
    for (int j : g[i]) if (j != p) dfs(j, i);
}
bool dfs2(int i, int p) {
    if (i == v2) return true;
    for (int j = 0; j < g[i].size(); ++j) if (g[i][j] != p) {
        if (dfs2(g[i][j], i)) {
            swap(g[i][j], g[i].back());
            return true;
        }
    }
    return false;
}
int _t = 1;
void dfs3(int i, int p) {
    v[i] = _t++;
    for (int j : g[i]) if (j != p)
        dfs3(j, i), _t++;
}
signed main() {
    ios::sync_with_stdio(0), cin.tie(0);
    int n;
    cin >> n;
    g.resize(n), v.resize(n);
    for (int i = 0; i < n - 1; ++i) {
        int x, y;
        cin >> x >> y;
        --x, --y;
        g[x].push_back(y), g[y].push_back(x);
    }
    dfs(0, -1);
    dfs(v1 = v2, -1);
    dfs2(v1, -1);
    dfs3(v1, -1);
    for (int i : v) cout << i << ' ';
}

#include <bits/stdc++.h>

using namespace std;

typedef long long i64;
typedef unsigned long long ui64;
typedef vector<i64> vi;
typedef vector<vi> vvi;
typedef pair<i64, i64> pi;

#define pb push_back
#define sz(a) i64((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)
inline void RI(i64 &i) {scanf("%lld", &(i));}
inline void RVI(vi &v) { for(i64 i=0;i<sz(v);++i) { RI(v[i]); } }
inline void RVVI(vvi &vv) { for(i64 i=0;i<sz(vv);++i) { RVI(vv[i]); } }
inline void WI(const i64 &i) {printf("%lld\n", i);}
inline void WVI(const vi &v, char sep=' ') { for(i64 i=0;i<sz(v);++i) { if(i != 0){ printf("%c", sep); } printf("%lld", v[i]);} printf("\n"); }
inline void WS(const string &s) { printf("%s\n", s.c_str()); }
inline void WB(bool b, const string &yes, const string &no) { if(b){ WS(yes);} else { WS(no);} }
inline void YESNO(bool b) { WB(b, "YES", "NO"); }
inline void YesNo(bool b) { WB(b, "Yes", "No"); }
#define BUF_LENGTH 1000000
inline void RS(string &s) {static char buf[BUF_LENGTH]; scanf("%s", buf); s = buf;}
template<typename T> inline bool IN(T &S, const typename T::key_type &key) {
  return S.find(key) != S.end();
}
template<typename T> inline bool ON(const T &b, i64 idx) {
  return ((T(1) << idx) & b) != 0;
}

i64 dfs(const vvi &edges, i64 cur, i64 prev, i64 n, const vi &to, vi &ans, bool f) {
  // start from v
  //cerr << "dfs " << cur << " " << prev << " " << n << endl;
  ans[cur] = n;
  for(auto &e: edges[cur]) {
    if(e != prev && e != to[cur]) {
      n += 1;
      n = dfs(edges, e, cur, n, to, ans, false);
      n += 1;
    }
  }
  if(f && to[cur] != -1) {
    n += 1;
    n = dfs(edges, to[cur], cur, n, to, ans, true);
  }
  return n;
}

int main(int argc, char *argv[]) {
  i64 i, j, k;
  i64 t, T;
  i64 N; cin >> N;
  vvi edges(N);
  REP(0, N-1, i) {
    i64 a, b; RI(a); RI(b);
    --a; --b;
    edges[a].pb(b);
    edges[b].pb(a);
  }

  const i64 INF = N * 2;

  auto bfs = [&](i64 s) {
    vi dists(N, INF);
    vi from(N, -1);
    dists[s] = 0;
    queue<i64> q;
    q.push(s);
    while(!q.empty()) {
      i64 cur = q.front(); q.pop();
      for(auto &e: edges[cur]) {
        if(dists[e] == INF) {
          dists[e] = dists[cur] + 1;
          from[e] = cur;
          q.push(e);
        }
      }
    }
    /*
    for(auto &d: dists) {
      cerr << d << " ";
    }
    cerr << endl;
    for(auto &d: from) {
      cerr << d << " ";
    }
    cerr << endl;
    */
    return pair<vi, vi> {dists, from};
  };

  auto res_0 = bfs(0);
  vi &d0 = res_0.first;
  i64 u = -1;
  REP(0, N, i) {
    if(u == -1 || d0[u] < d0[i]) {
      u = i;
    }
  }
  assert(u != -1);
  auto res_u = bfs(u);
  vi &du = res_u.first;
  vi &fu = res_u.second;
  i64 v = -1;
  REP(0, N, i) {
    if(v == -1 || du[v] < du[i]) {
      v = i;
    }
  }
  assert(v != -1);
  //cerr << "diameter " << du[v] << " " << u << " -> " << v << endl;

  vi ans(N, -1);
  dfs(edges, v, -1, 1, fu, ans, true);
  WVI(ans);

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=4e5+7;
typedef long long LL;
int a[N],id[N];
bool cmp(int x,int y){
	return a[x]>a[y];
}
bool vis[N];
priority_queue<int> Q;
int n;
int tr(int i){
	return i<=n?n-i+1:i-n;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=2*n;i++)scanf("%d",&a[i]),id[i]=i;
	int tot=2*n;
	sort(id+1,id+tot+1,cmp);
	LL ans=0;
	for(int i=1;i<=n;i++)vis[id[i]]=1,ans+=a[id[i]];
	int s=n,j=n;
	for(int i=n;i>=1;i--){
		if(s>i){
			while(tr(id[j])>i)j--;
			vis[id[j]]=0;
			ans-=a[id[j]]; s--;     //printf("-%d\n",a[id[j]]);
			ans+=Q.top();   //printf("%d\n",Q.top());
			Q.pop(); j--;
		}
		if(!vis[i+n])Q.push(a[i+n]);
		if(!vis[n-i+1])Q.push(a[n-i+1]);
		s-=vis[i+n]+vis[n-i+1];
	}
	printf("%lld\n",ans);
	return 0;
}

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    lint n;cin >> n;
    vector<lint> a(n);
    REP(i, n) cin >> a[i];
    map<lint, lint> mp;
    REP(i,n){
        if(mp.count(a[i])==0){
            mp[a[i]] = 1;
        }else{
            mp[a[i]] = mp[a[i]] += 1;
        }
    }
    lint ans = n*(n-1)/2;
    for(auto &e:mp){
        ans -=e.second*(e.second-1)/2;
    }
    cout << ans << "\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 LP = pair<ll, ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
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);

unsigned int xor128(){
  static unsigned int x=123456789,y=362436069,z=521288629,w=88675123;
  unsigned int t = (x^(x<<11));
  x=y; y=z; z=w;
  return( w=(w^(w>>19))^(t^(t>>8)) );
}

int n,m,cnt;
vector<string> genome(40, string(40, 'A')), fact(800);

void init(){
  REP(i,n) REP(j,n){
    char c = 'A' + (xor128() % 8);
    genome[i][j] = c;
    genome[i+n][j] = c;
    genome[i][j+n] = c;
  }
}

int countStr(){
  int ret = 0;
  REP(k,m){
    bool found = false;
    REP(i,n){
      if(found) break;
      REP(j,n){
        if(genome[i].substr(j, fact[k].size()) == fact[k]){
          ret++;
          found = true;
          break;
        }
      }
    }

    if(found) continue;
    REP(j,n){
      if(found) break;
      REP(i,n){
        string tmp;
        FOR(d,i,i+fact[k].size()) tmp.push_back(genome[d][j]);
        if(tmp == fact[k]){
          ret++;
          found = true;
          break;
        }
      }
    }
  }
  return ret;
}

void update1(){
  int ni = xor128() % n;
  int nj = xor128() % n;
  char nc = 'A' + (xor128() % 8);
  char pc = genome[ni][nj];

  genome[ni][nj] = genome[ni+n][nj] = genome[ni][nj+n] = nc;
  int cur_cnt = countStr();
  if(!chmax(cnt, cur_cnt)){
    genome[ni][nj] = genome[ni+n][nj] = genome[ni][nj+n] = pc;
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> m;
  REP(i,m) cin >> fact[i];
  init();
  cnt = countStr();

  int ti = clock();
  while(clock() - ti < 290 * CLOCKS_PER_SEC / 100){ // 2.9秒で打ち切り
    if(cnt==n) break;
    REP(tk, 100){

    }
  }

  REP(i,n) cout << genome[i].substr(n) << '\n';
  return 0;
}


#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define ROF(i,a,b) for(int i=(a); i>=(b); --i)
#define pb push_back
#define eb emplace_back
#define SZ(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define make_unique(a) sort(all((a))), (a).erase(unique(all((a))),(a).end())
#define x first
#define y second
#define MP make_pair
#define MT make_tuple
#define debug(x) cout << #x << " = " << x << endl
#define debug2(x,y) FOR(i,1,y) cout << "##"; cout << #x << " = " << x << endl
#define mset(x,y) memset((x), (y), sizeof(x))

using namespace std;

typedef long long i64;
typedef long double ld;
typedef tuple<int,int,int> iii;
typedef pair<int,int> pii;
typedef pair<i64,i64> pll;
typedef vector<int> vi;
typedef vector<i64> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<i64>> vvl;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<i64,i64>> vpll;

int readInt(){ int a; scanf("%d",&a); return a; }
i64 readLong(){ i64 a; scanf("%lld",&a); return a;}
void readString(char *s){ scanf(" %s",s); }

const int mod = 998244353;
int add(int a, int b){ return ((a+=b)>=mod)?a-mod:a; }
int mul(int a, int b){ return a*1ll*b%mod; }
void adding(int &a, int b){ a = add(a, b); }
int pw(int a, int b){
	if(a==0) return 0;
	int ans = 1, res = a;
	for(int i = 1; i <= b; i<<=1, res=mul(res,res)){
		if(i&b) ans = mul(ans,res);
	}
	return ans;
}

int play(vi w){
	int n = SZ(w);
	vi p(n);
	iota(all(p),0);
	int cnt = 0;
	do{
		int sum = 0;
		FOR(i,0,n-1){
			if(sum <= 0) sum += w[p[i]];
			else sum -= w[p[i]];
		}
		if(sum == 0) ++cnt;
		else{
			printf("{ ");
			FOR(i,0,n-1) printf("%d ",w[p[i]]);
			printf("}\n");
		}
	}while(next_permutation(all(p)));
	return cnt;
}

const int N = 105;
int fac[N];
const int zero = 5000;
int dp[N][N*N];
int sav[N][N*N];

int main(){
	//printf("%d\n",play({1,2,3,4}));
	fac[0] = 1;
	FOR(i, 1, 100) fac[i] = mul(fac[i-1],i);
	int n = readInt();

	dp[0][zero] = 1;

	int mx = N*N;
	FOR(i, 1, n){
		int a = readInt();
		FOR(j, 0, i-1){
			FOR(k, 0, mx-1){
				if(k >= a) adding(sav[j][k-a], dp[j][k]);
				if(k+a < mx) adding(sav[j+1][k+a], dp[j][k]);
			}
		}
		FOR(j, 0, i){
			FOR(k, 0, mx-1){
				dp[j][k] = sav[j][k];
				sav[j][k] = 0;
			}
		}
	}
	int ans = 0;
	FOR(i, 1, n-1){
		//printf("%d\n",dp[i][zero]);
		adding(ans, mul(mul(fac[i],fac[n-i]),dp[i][zero]));
	}
	printf("%d",ans);
	return 0;
}
/*
5
3 3 3 3 6
(96)

*/

#include<stdio.h>
#include<math.h>
#include<string.h>

#define ni(n) ((n) * (n))
#define rep(i,n) for(i=0;i<n;i++)
#define N 100

int main(void){
	int n;
	int i,ans = 0;
	rep(i,3){
		scanf("%d",&n);
		ans += (7 - n);
	}
	printf("%d",ans);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cout << setprecision(10) << fixed;

	long long n, m;
	cin >> n >> m;
	vector<long long> a(n);
	vector<vector<long long>> g(n);
	for (long long i = 0; i < n; ++i)
		cin >> a[i];

	for (long long i = 0; i < m; ++i)
	{
		long long x, y;
		cin >> x >> y;
		--x, --y;
		g[x].emplace_back(y);
	}
	vector<pair<long long, long long>> p(n, make_pair(-1e15, 1e15));
	long long ans = -1e15;
	for (long long i = 0; i < n; ++i)
	{
		p[i].second = min(a[i], p[i].second);
		for (long long u : g[i])
		{
			ans = max(ans, a[u] - p[i].second);
			p[u].second = min(p[u].second, p[i].second);
			// p[u].first = max(a[u], p[i].first);
			// p[i].second =
		}
	}
	cout << ans << '\n';
}

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

#define forn(i,m,n) for(int i=m;i<n;i++)
#define vv vector
#define vi vv<int>
#define ii pair<int,int>
#define vii vv<ii>
#define mp make_pair
#define pb push_back
#define PI 3.141592653589
#define ll long long
#define pll pair<ll,ll>
#define vl vv<ll>
#define ff first
#define ss second
#define MOD 1000000007

bool is_prime[1000001];
vi prime;
void sieve(int n)
{
    memset(is_prime,true,sizeof(is_prime));
    for(int i=2;i*i<=n;i++)
    {
        if(is_prime[i])
        {
            for(int j=i*i;j<=n;j+=i)
            {
                is_prime[j]=false;
            }
        }
    }
    forn(i,2,n+1)
    {
        if(is_prime[i])
            prime.pb(i);
    }
}

ll ex(ll a,ll b)
{
    ll res=1;
    a=a%MOD;
    while(b)
    {
        if(b%2){res=(res*a)%MOD;b--;}
        b/=2;
        a=(a*a)%MOD;
    }
    return res;
}

ll fermat_inv(ll a){ return ex(a,MOD-2); }
ll max(ll a,ll b){ return a>b?a:b; }
ll min(ll a,ll b){ return a<b?a:b; }

int gcd(int a,int b) { return (a%b==0)?b:gcd(b,a%b); }

ll fact[200005];
ll finv[200005];
void factorial(int n){
    fact[0]=1;
    finv[0]=1;
    for(ll i=1;i<=n;i++)
        fact[i]=fact[i-1]*i,fact[i]%=MOD,finv[i]=fermat_inv(fact[i]);
}
ll ncr(ll n,ll r)
{
    if(n<r)
        return -1;
    else{
        ll x=finv[r]*finv[n-r]%MOD;
        return fact[n]*x%MOD;
    }
}

vv<vi> adj(200005);
vi mn(200005,INT_MAX);
vi val(200005);
int ans;

void dfs(int v)
{
    mn[v]=min(mn[v],val[v]);
    for(int x:adj[v])
    {
        ans=max(ans,val[x]-mn[v]);
        mn[x]=min(mn[x],mn[v]);
    }
    //cout<<"mn["<<v<<"]: "<<mn[v]<<"\n";
}

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

    int te=1;
    //cin>>te;
    while(te--)
    {
        ll n,m,a,b;
        cin>>n>>m;
        //cout<<n<<m<<"\n";
        forn(i,1,n+1)
            cin>>val[i];
        //int st=INT_MAX;
        forn(i,0,m)
        {
            cin>>a>>b;
            if(a>b)
                swap(a,b);
            //cout<<a<<b;
            adj[a].pb(b);
            //adj[b].pb(a);
        }

        ans=INT_MIN;
        forn(i,1,n+1)
            dfs(i);
        cout<<ans;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define _rep(i, x, y) for(int i = (int)x; i < (int)y; ++i)
#define _dep(i,x,y) for(int i = (int)x; i > (int)y; i--)
#define PII pair<int,int>
#define eb emplace_back
#define pb push_back
#define fi first
#define se second
#define PQ priority_queue
#define lb lower_bound
#define ub upper_bound
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VII;
typedef vector<ll> VL;
typedef vector<vector<ll>> VLL;
constexpr int mod = 1e9 + 7;
constexpr int KINF = 0x3f3f3f3f;
constexpr double eps = 1e-7;
int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	ll k;
	cin >> k;
	string s, t;
	cin >> s >> t;
	VI cnt(10, k);
	_rep(i, 0, 4) cnt[s[i] - '0'] --;
	_rep(i, 0, 4) cnt[t[i] - '0'] --;
	auto get = [&](string S){
		VL c(10);
		iota(all(c), 0ll);
		_rep(i, 0, 5) c[S[i] - '0'] *= 10;
		return accumulate(all(c), 0);
	};
	ll win = 0;
	_rep(i, 1, 10){
		s.back() = '0' + i;
		int sc = get(s);
		_rep(j, 1, 10){
			t.back() = '0' + j;
			if(sc <= get(t)) continue;
			win += 1ll * cnt[i] * (cnt[j] - (i == j));
		}
	}
	int rem = 9 * k - 8;
	cout <<  (double)(win) / (rem) / (rem - 1) << endl;
	return 0;
}
// 小心左移运算符导致的int溢出
// dp记得处理非法状态
// resize并不会初始化数组
// 全局函数一定要记得inline
// 带空格字符串不能直接cin,要用getline

#include <bits/stdc++.h>
#define int             long long
#define trace(x) 		cerr<<#x<<": "<<x<<" "<<endl;
#define w(x)            int x; cin>>x; while(x--)
#define fr(i,a,b)       for(int i = a; (int)i < b; i++)
#define frr(i,a,b)      for(int i = a; (int)i >= b; i--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
int32_t main()
{
	FIO;
	int a, b, c;
	cin >> a >> b >> c;
	if ((a * a) + (b * b) < (c * c)) {
		cout << "Yes";

	}
	else cout << "No";
	return 0;
}


#include<bits/stdc++.h>

typedef long long ll;
typedef long double ld;
using namespace std;
//mt19937_64 mrand(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 mrand(42);
#define ii for(int i=1;i<=n;++i)
#define ji for(int j=1;j<=n;++j)
#define jj for(int j=1;j<=m;++j)
#define ij for(int i=1;i<=m;++i)
#define sz(x) ((ll)x.size())
#define all(x) x.begin(),x.end()
#define al(x) x+1,x+1+n
#define asd cout<<"ok"<<endl;
#define asdd cout<<"okok"<<endl;
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define pr(v) for(auto i:v) cout<<i<<" ";cout<<endl;
#define prt(a, l, r) for(auto i=l;i<=r;++i) cout<<a[i]<<" ";cout<<endl;
#define pc(x) __builtin_popcount(x)
#define pb push_back
#define PS string qqwwee;cin>>qqwwee;
typedef pair<int,int> pii;

const int mod = 1e9+7;
ll get(ll a1,ll d1,ll n) {
    a1%=mod;d1%=mod;n%=mod;
    return ((a1+(n-1)*d1%mod-(n-1)*(n-2)%mod)%mod+mod)%mod;
}
ll solve(ll n,ll a,ll b) {
    ll a1=get(n,n-2,a),d1=b;
    return get(a1,n-2-a+1,b);
}
int main() {
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;
    cin>>t;
    while(t--) {
        ll n,a,b;
        cin>>n>>a>>b;
        if(a+b>n) {cout<<0<<endl;continue;}
        ll ans=solve(n,a,b);
        ans=ans*ans%mod;
        ll tot=(n-a+1)*(n-a+1)%mod*(n-b+1)%mod*(n-b+1)%mod;
        ans=(tot-ans+mod)%mod;
        cout<<ans<<endl;
    }
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //int:2*10**9
typedef long double ld;
typedef pair<ll,ll> P;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define vec2(name,i,j,k) vector<vector<ll>> name(i,vector<ll>(j,k))
#define vec3(name,i,j,k,l) vector<vector<vector<ll>>> name(i,vector<vector<ll>>(j,vector<ll>(k,l)))
#define pb push_back
#define MOD 1000000007
#define PI 3.141592653
#define INF 100000000000000 //14
//cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);

void solve() {
  ll n, a, b; cin >> n >> a >> b;
  if (a<b) swap(a,b);
  if (n<a+b){
    cout << 0 << endl;
    return;
  }
  ll x = ((n-a-b+1)*(n-a-b+2)/2)%MOD;
  ll z;
  if (n-a>=b) {
    z=(((b-1)*b/2)%MOD+((n-a-b+1)*(b-1))%MOD)%MOD;
  }
  else {
    z=((n-a)*(n-a+1)/2)%MOD;
  }
  ll y = (((a-b+1)*(n-a+1))%MOD+(2*z%MOD))%MOD;
  ll ans = (((4*x)%MOD)*((x+y)%MOD))%MOD;
  cout << ans << endl;
}

int main(){
  ll t; cin >> t;
  REP(i,t) {
    solve();
  }
  return 0;
}


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

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

void dfs(ll p, vector<vector<ll>> &v, vector<bool> &visited)
{
    for (ll i : v[p])
    {
        if (!visited[i])
        {
            // cout << "( " << p << " , " << i << " ) ";
            ans++;
            visited[i] = 1;
            dfs(i, v, visited);
        }
    }
}

void solve()
{
    ll n, m;
    cin >> n >> m;
    vector<vector<ll>> v(n + 1);
    for (ll i = 0; i < m; ++i)
    {
        ll a, b;
        cin >> a >> b;
        v[a].push_back(b);
    }

    for (ll i = 1; i <= n; ++i)
    {
        ans++;
        if (v[i].size() == 0)
            continue;
        vector<bool> visited(n, 0);
        visited[i] = 1;
        dfs(i, v, visited);
        cout << endl;
    }
    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>
#define rep(i,l,r) for(int i = (l); i <= (r); ++i)
#define per(i,r,l) for(int i = (r); i >= (l); --i)
using namespace std;
typedef long long ll;
inline int gi() {
	int f = 1, x = 0; char ch = getchar();
	while (ch < '0' || ch > '9') {if (ch == '-') f = -f;ch = getchar();}
	while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
	return f * x;
}
const int N = 2010;
int n, m;
vector<int> g[N];
int vis[N];
void dfs(int u) {
	vis[u] = 1;
	for(auto& v: g[u]) if (!vis[v]) dfs (v);
}
int main(){
	n = gi(), m = gi();
	rep (i, 1, m) {
		int u = gi(), v = gi();
		g[u].push_back(v);
	}
	int ans = 0;
	rep (i, 1, n) {
		memset(vis, 0, sizeof (vis));
		dfs (i);
		ans += count(vis + 1, vis + 1 + n, 1);
	}

	cout << ans;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
// #define LOCAL // 提出時はコメントアウト
#define DEBUG_

typedef long long ll;
const double EPS = 1e-9;
const ll INF = ((1LL<<62)-(1LL<<31));
typedef vector<ll> vecl;
typedef pair<ll, ll> pairl;
template<typename T> using uset = unordered_set<T>;
template<typename T, typename U> using mapv = map<T,vector<U>>;
template<typename T, typename U> using umap = unordered_map<T,U>;

#define ALL(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define sz(x) (ll)x.size()
ll llceil(ll a,ll b) { return (a+b-1)/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; }
template<class T> vector<vector<T>> genarr(ll n, ll m, T init) { return vector<vector<T>>(n,vector<T>(m,init)); }

///// DEBUG
#define DUMPOUT cerr
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
template<typename T>istream&operator>>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<typename T,typename U>ostream&operator<<(ostream&os,pair<T,U>&pair_var){os<<"("<<pair_var.first<<", "<<pair_var.second<<")";return os;}
template<typename T>ostream&operator<<(ostream&os,const vector<T>&vec){os<<"{";for(int i=0;i<vec.size();i++){os<<vec[i]<<(i+1==vec.size()?"":", ");}
os<<"}";return os;}
template<typename T,typename U>ostream&operator<<(ostream&os,map<T,U>&map_var){os<<"{";repi(itr,map_var){os<<*itr;itr++;if(itr!=map_var.end())os<<", ";itr--;}
os<<"}";return os;}
template<typename T>ostream&operator<<(ostream&os,set<T>&set_var){os<<"{";repi(itr,set_var){os<<*itr;itr++;if(itr!=set_var.end())os<<", ";itr--;}
os<<"}";return os;}
void dump_func(){DUMPOUT<<endl;}
template<class Head,class...Tail>void dump_func(Head&&head,Tail&&...tail){DUMPOUT<<head;if(sizeof...(Tail)>0){DUMPOUT<<", ";}
dump_func(std::move(tail)...);}
#ifndef LOCAL
#undef DEBUG_
#endif
#ifdef DEBUG_
#define DEB
#define dump(...)                                                          \
DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
        << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
        << endl                                                            \
        << "    ",                                                         \
    dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif

//////////

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

int solve(ostringstream &cout) {
    #ifdef LOCAL
    ifstream in("../../Atcoder/input.txt");
    cin.rdbuf(in.rdbuf());
    #endif

    ll a,b;
    cin>>a>>b;

    ll x = a + b, y = b;
    ll ans = 4;
    if (x >= 15 && y >= 8) ans = 1;
    else if (x >= 10 && y >= 3) ans = 2;
    else if (x >= 3) ans = 3;

    cout << ans << endl;

    return 0;
}

int main() {
    ostringstream oss;
    int res = solve(oss);

    cout << oss.str();
    return res;
}

#include "bits/stdc++.h"
using namespace std;
using LLI = long long;
#define INF 999999999
#define MOD 1000000007
#define FOR(i, s, e) for(LLI i = s, i##_lim = (e); i < i##_lim; i++)
#define FORR(i, s, e) for(LLI i = s-1, i##_lim = (e); i##_lim<=i; i--)
#define REP(i, n) FOR(i,0,n)
#define REPR(i, n) FORR(i,n,0)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a)?1:-1)
#define SORT(v) sort(v.begin(),v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define Mat2(type,name,h,w,def) vector<vector<type>> name(h,vector<type>(w, def))
#define Mat3(type,name,h,w,d,def) vector<vector<vector<type>>> name(h,vector<vector<type>>(w, vector<int>(d,def)))
// int 2.14E±9    LLIi 9.2E±18    double 1.7E±380

int main()
{
	cout << fixed << setprecision(10);

	int a, b, c, d;
	cin >> a >> b >> c >> d;

	cout << b - c;

	return 0;
}


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

typedef long long int ll;
#define endl "\n"
#define pll pair<ll,ll>
#define pii pair<int ,int>
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define vpii vector<pair<int, int>>
#define mems(x,y) memset(x,y,sizeof(x))
#define all(x) (x).begin(),(x).end()
#define forn(i,s,e) for(int i = s; i < (e); ++i)
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FILEIO                          \
freopen("./input.txt", "r", stdin); \
freopen("./output.txt", "w", stdout);
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d)                                                   \
for (                                                                   \
auto blockTime = make_pair(chrono::high_resolution_clock::now(), true); \
        blockTime.second;                                               \
debug("%s : %lld ms\n ", d, chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - blockTime.first).count()), blockTime.second = false)
const int M = 1e9 + 7;

template <class T> T ABS(const T &x) {return x>0? x:-x;}
ll gcd(ll n1, ll n2) {return n2==0? ABS(n1) : gcd(n2,n1%n2);}
ll lcm(ll n1, ll n2) {return n1==0 && n2==0? 0 : ABS(n1*n2)/gcd(n1,n2);}
ll ceil2(ll a, ll b) {return (a + b - 1) / b;}

void bad(){
    cout << "UNSOLVABLE\n";
    exit(0);
}

int main()
{
FASTIO
#ifdef LOCAL
FILEIO
#endif
    vector<string> s(3);
    for(auto &x: s) cin >> x;

    vector<char> dict;
    for(auto &v: s) for(auto &c: v) dict.push_back(c);
    sort(dict.begin(),dict.end());
    dict.erase(unique(dict.begin(), dict.end()), dict.end());
    if(dict.size() > 10) bad();

    for(auto &v: s) for(auto &c: v) c = 'a' + lower_bound(dict.begin(),dict.end(),c) - dict.begin();

    vi index(10);
    iota(index.begin(),index.end(),0);
    do{
        auto U = s;
        for(auto &v: U) for(auto &c: v) c = '0' + index[c - 'a'];
        ll a = stoll(U[0]), b = stoll(U[1]), c = stoll(U[2]);
        if(U[0][0] != '0' && U[1][0] != '0' && U[2][0] != '0'  && a +b == c){
            cout << a << '\n' << b << '\n' << c << '\n';
            return 0;
        }

    } while(next_permutation(index.begin(),index.end()));
    bad();

    return 0;
}

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5+100;
int dp[N][7], a[N], n;
string s, t;
int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n >> s >> t;
	s = "@" + s;
	t = "@" + t + "T";
	int p = 1;
	for(int i = n; i >= 1; --i) {
		a[i] = p * (s[i] - '0') % 7;
		p = p * 10 % 7;
	}
	dp[n+1][0] = 1;
	for(int i = n; i >= 0; --i) {
		for(int mod = 0; mod < 7; ++mod) {
			if(t[i+1] == 'T') {
				dp[i][mod] = dp[i+1][mod] | dp[i+1][(mod + a[i+1]) % 7];
			} else {
				dp[i][mod] = dp[i+1][mod] & dp[i+1][(mod + a[i+1]) % 7];
			}
		}
	}
	if(dp[0][0]) {
		cout << "Takahashi\n";
	} else {
		cout << "Aoki\n";
	}
}


#include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <climits>
#include <bitset>
#include <cassert>
#include <time.h>
#include <numeric>

using namespace std;

#define int long long
#define pb push_back
#define in insert
#define F first
#define S second
#define mod 1000000007
#define endl '\n'
#define test(x) int x;cin>>x; while(x-->0)
#define debug(x) cout << "[ " << #x  << " : " << x << " ]" << endl;
void fast_io()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("error.txt", "w", stderr);
	freopen("output.txt", "w", stdout);
#endif
}
void sol()
{
    int n; cin>>n;
    int arr[n],brr[n],amin=100001,bmin=100001;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i]>>brr[i];
        amin=min(amin,arr[i]);
        bmin=min(bmin,brr[i]);
    }
    //cout<<amin<<" "<<bmin<<" ";
    int f=0;
    for(int i=0;i<n;i++)
    {
        if(arr[i]==amin and brr[i]==bmin)
            f=1;
    }
    if(f==1)
    {
       sort(arr,arr+n);
       sort(brr,brr+n);
       int ans1=amin+bmin;
       int ans2=min(max(arr[0],brr[1]),max(arr[1],brr[0]));
       cout<<min(ans1,ans2);
    }
    else
        cout<<max(amin,bmin);

}

int32_t main()
{
	fast_io();
	//test(t)
	sol();
	//cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
	//cerr << sizeof(dp)*(1e-6) << " megabytes\n";
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
//const int MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const double pi = acos(-1.0);
const double EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int T;
    cin >> T;
    while(T--){
        string S;
        cin >> S;
        if(S > "atcoder") {cout << 0 << endl; continue;}
        int ptr = 0;
        int N = sz(S);
        while(ptr < N && S[ptr] == 'a') ptr++;
        if(ptr == N) {cout << -1 << endl; continue;}
        int cnt = 0;
        while(S <= "atcoder"){
            swap(S[ptr-1], S[ptr]);
            ptr--, cnt++;
        }
        cout << cnt << endl;
    }
}


//コンパイラ最適化用
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<chrono>//実行時間計測
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm,accumulate
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//順序保持しないmap
#include<unordered_set>//順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
#include<bits/stdc++.h>

//#include<atcoder/all>
//using namespace atcoder;

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;
typedef pair<ll, ld> pld;
typedef pair<pii, int> ppiii;
typedef pair<pii, ll> ppiill;
typedef pair<pll, ll> ppllll;
typedef pair<pli, int> pplii;
typedef map<int, int> mii;
typedef deque<ll> dll;
typedef queue<ll> qll;
typedef priority_queue<ll> pqll;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqrll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<int>> vvint;
typedef vector<vector<pll>> vvpll;

//マクロ
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end()
#define SIZE(x) ll(x.size())
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange
//最大化問題最小化問題
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

signed main(){
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    //入力
    ll N;
    string S;
    cin >> N >> S;
    ll Acount=0,Tcount=0,Gcount=0,Ccount=0;

    vvll stc(N+5,vll(5,0));
    //vvll stcsum(N,vll(5,0));

    FOR(i,1,N){
        REP(j,5){
        stc[i][j]=stc[i-1][j];
        }
        if(S[i-1]=='A'){
            Acount++;
            stc[i][1]=stc[i-1][1]+1;
        }
        if(S[i-1]=='T'){
            Tcount++;
            stc[i][2]=stc[i-1][2]+1;}
        if(S[i-1]=='G'){Gcount++;
        stc[i][3]=stc[i-1][3]+1;}
        if(S[i-1]=='C'){Ccount++;
        stc[i][4]=stc[i-1][4]+1;}

    }

    ll X = min(Acount,Tcount);
    ll Y = min(Gcount,Ccount);

    vvll dp(N+10,vll(N+10,0));

    FOR(i,1,N){
        FOR(j,i,N){
            ll a,t,g,c;
                a = stc[j][1]-stc[i-1][1];
                t = stc[j][2]-stc[i-1][2];
                g = stc[j][3]-stc[i-1][3];
                c = stc[j][4]-stc[i-1][4];
                if(a==t&&c==g){
                    dp[i][j] = 1;
                }
                else{continue;}
        }
    }

    ll ans = 0;
    FOR(i,1,N){
        FOR(j,i,N){
            ans += dp[i][j];
        }
    }

    //本文
    //出力
    cout << ans << endl;
    //REP(i,N) cout << ans.at(i) <<endl;
  return 0;
}

#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast")
#define ll long long
#define ull unsigned long long
#define pll pair<long long,long long>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define forn(i, n) for(int i=0; i<int(n); i++)
#define Forn(i, n) for(int i=1; i<=int(n); i++)

using namespace std;

int n;
double a[100010];

int main()
{
    cin.tie(0); ios_base::sync_with_stdio(false);
    cin >> n;
    forn(i, n) cin >> a[i];
    sort(a, a+n);
    double opt = a[(n-1)/2]/2;
    double ans = 0;
    forn(i, n)
    {
        ans += a[i]/2 + abs(opt - a[i]/2);
    }
    cout << fixed << setprecision(8) << ans/(double)n << endl;
}


#include <bits/stdc++.h>

#define INF 1000000007
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i < b; i++)

using namespace std;

typedef long long ll;
typedef long long int  lli;
typedef long double ld;
typedef vector<int> vi;
typedef unordered_map<int,int> umi ;
typedef unordered_set<int> usi ;
typedef pair<int,int> pi;

struct custom_hash {
    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);
    }
};

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

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

//declare here -------------------------------------------------------------------------------
const int N =1e5 ;
ll numways[2*N +1 ] ;
ll n , k ;
void gen(){
    REP(i,2,n+2){
        numways[i]=numways[i-1]+1 ;
    }
    REP(i,n+2 , 2*n +1) numways[i]=numways[i-1]-1 ;
}

// solve here ---------------------------------------------------------------------------------
void solve(){
   cin>>n>>k ;
   gen() ;
   ll ans=0 ;
   REP(B ,2 , 2*n +1 ){
    int A =k+B ;
    if(A<2 || A>2*n ) continue ;
    ans+=numways[A]*numways[B] ;
   }
   cout<<ans ;
}

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

int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    long long test =1 ;
    //cin>>test ;
    while(test--){
        debug(test) ;
        solve() ;
        cout<<"\n" ;
    }
    return 0 ;
}

#include<bits/stdc++.h>
using ll = int_fast64_t;
#define REP(i,b,e) for(ll i=b; i<e; i++)

int main(){
	ll n, k;
	scanf("%ld %ld", &n, &k);

	ll ans = 0;
	REP(i, 2, 2*n+1){
		if(i-k < 2) continue;
		ll j = i-k;
		if(i > 2*n || j > 2*n) continue;
		ll tmp = 1;
		if(i < n+2) tmp *= i-1;
		else tmp *= i - 1 - 2*(i-n-1);
		if(j < n+2) tmp *= j-1;
		else tmp *= j - 1 - 2*(j-n-1);
		ans += tmp;
	}
	printf("%ld\n", ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,k;
long long get(int x)
{
    //x-r>=1 r<=x-1 x-l<=n l>=x-n
    return min(n,x-1)-max(1,x-n)+1;
}
int main()
{
    scanf("%d%d",&n,&k);
    long long res=0;
    for(int i=2;i<=2*n;i++)
    {
        int t=i-k;
        if(t>=2&&t<=2*n)
        {
            res+=get(i)*get(t);
        }
    }
    cout<<res;
}

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

#define FOR(index, start, end) for(int index = start; index < end; ++index)
#define F0R(index, end) for(int index = 0; index < end; ++index)
#define RFOR(index, start, end) for(int index = start; index > end; --index)
#define FOREACH(itr, b) for(auto itr = b.begin(); itr != b.end(); ++itr)
#define RFOREACH(itr, b)  qfor(auto itr = b.rbegin(); itr != b.rend(); ++itr)

#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << #x << " = " << x << ", " << #y << " = " << y << endl
#define db3(x, y, z) cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl

#define ri(x) scanf("%d", &x)
#define ri2(x, y) scanf("%d%d", &x, &y)
#define ri3(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define rll(x) scanf("%lld", &x)

#define mp make_pair
#define sz(x) (int)x.size()
#define pf push_front
#define pb push_back

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld ,ld>;
using vi = vector<int>;
using vld = vector<ld>;
using vll = vector<ll>;

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

#define INF 1000000000
#define P 257
#define M 1000000007
#define MAXN 200005

int n, k;

int cnt(int x){
    if (x <= n) return x - 1;
    return min(x - 1, abs(x - n - n) + 1);
}

void solve(){
    ll ans = 0;
    FOR(i, 2, 2 * n + 1){
        int j = i - k;
        if (1 <= j && j <= 2 * n){
            ans += (ll)cnt(i) * cnt(j);
        }
    }
    cout << ans << endl;
}

void read(){
    ri2(n, k);
}

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

    read();
    solve();

    /*
    int tests;
    ri(tests);
    FOR(t, 0, tests){
        read();
        solve();
    }
    */

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORC(i,a,b,c) for(ll i=(a);i<(b);i+=(c))
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define ff first
#define ss second
#define dd long double
#define all(x) x.begin(),x.end()

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s1,s2;
    cin>>s1>>s2;
    ll a1=0,a2=0;
    REP(i,3){
        a1+=(s1[i]-'0');
        a2+=(s2[i]-'0');
    }
    cout<<max(a1,a2)<<endl;
}


#include<bits/stdc++.h>
#define mod 998244353
#define ll long long
#define N 400010
using namespace std;
inline int read(){
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-')f*=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=x*10+int(ch-48);
		ch=getchar();
	}
	return x*f;
}
int n,m;
int tr[N];
int low(int x){
	return x&-x;
}
void add(int x,int val){
	for(int i=x;i<=n;i+=low(i))tr[i]+=val;
}
int query(int x){
	int sum=0;
	for(int i=x;i;i-=low(i))sum+=tr[i];
	return sum;
}
struct hh{
	int id,x;
}edge[N];
bool operator<(hh a,hh b){
	return a.x<b.x;
}
int a[N],b[N],val[N],cnt,vis[N];
queue<int>q[N];
char c[N];
void solve(){
//	freopen("a.in","r",stdin);
	cin>>n;
	n*=2;
	for(int i=1;i<=n;i++)a[i]=read(),edge[i]=(hh){i,a[i]};
	sort(edge+1,edge+1+n);
	for(int i=1;i<=n;i++)a[edge[i].id]=i;
	int lastB=0,lastS=0;
	for(int i=1;i<=n;i++){
		if(a[i]>n/2){
			if(lastB||(!lastS))c[i]='(',lastB++;
			else c[i]=')',lastS--;
		}
		else{
			if(lastB)c[i]=')',lastB--;
			else c[i]='(',lastS++;
		}
	}
	for(int i=1;i<=n;i++)putchar(c[i]);
}
int T;
int main(){
	if(0)cin>>T;
	else T=1;
	while(T--)solve();
}

#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < (t); ++i)
#define dsrep(i,t,s) for(int i = (t)-1; i >= (s); --i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cerr<<#x<<" = "<<x<<endl;
#define bn(x) ((1<<(x))-1)
#define newline puts("")
using namespace std;
template<typename T> using vc = vector<T>;
template<typename T> using vv = vc<vc<T>>;
template<typename T> using PQ = priority_queue<T,vc<T>,greater<T> >;
using ll = long long;
using uint = unsigned;
using ull = unsigned long long;
using P = pair<int,int>;
using T3 = tuple<int,int,int>;
using vi = vc<int>;
using vvi = vv<int>;
using vl = vc<ll>;
using vp = vc<P>;
using vt = vc<T3>;
int getInt(){int x;scanf("%d",&x);return x;}
vi pm(int n, int s=0) { vi a(n); iota(rng(a),s); return a;}
template<typename T>istream& operator>>(istream&i,vc<T>&v){rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const T&v,const string& d=""){stringstream s;rep(i,sz(v))(i?s<<d:s)<<v[i];return s.str();}
template<typename T>ostream& operator<<(ostream&o,const vc<T>&v){if(sz(v))o<<join(v," ");return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v){return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v){return o<<v.fi<<","<<v.se;}
vc<string> split(const string& s,char d=' '){vc<string> r(1);for(char c:s)if(c==d)r.pb("");else r.back()+=c;return r;}
string operator*(const string& s,int t){return join(vc<string>(t,s));}
template<typename T1,typename T2>bool mins(T1& x,const T2&y){if(x>y){x=y;return true;}else return false;}
template<typename T1,typename T2>bool maxs(T1& x,const T2&y){if(x<y){x=y;return true;}else return false;}
template<typename T>T dup(T x, T y){return (x+y-1)/y;}
template<typename T>ll suma(const vc<T>&a){ll res(0);for(auto&&x:a)res+=x;return res;}
template<typename T>void uni(T& a){sort(rng(a));a.erase(unique(rng(a)),a.end());}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

struct Solver {
  void solve() {
    int n;
    scanf("%d",&n);
    n *= 2;
    vi a(n);
    cin>>a;
    vp p(n);
    rep(i,n) p[i] = P(a[i],i);
    sort(rng(p));
    vi s(n,1);
    rep(i,n/2) s[p[i].se] = -1;
    string ans;
    int cnt = 0;
    rep(i,n) {
      if (cnt*s[i] >= 0) ans += '(';
      else ans += ')';
      cnt += s[i];
    }
    cout<<ans<<endl;
  }
};

int main() {
  int ts = 1;
  // scanf("%d",&ts);
  rrep(ti,ts) {
    Solver solver;
    solver.solve();
  }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long           ll;
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << '\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " = " << arg1 << " | "; __f(comma + 1, args...);
}

ll max(ll a, ll b) {return (a > b ? a : b);}
ll min(ll a, ll b) {return (a < b ? a : b);}
ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, 1, 0, -1};
void yes_or_no(ll x) {
  if (x) cout << "YES\n"; else cout << "NO\n";
}
void solve_test() {
  ll ans = 0;
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ans = a * d - b * c;
  cout << ans << "\n";
}
int main()
{
  cin.sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve_test();
  return 0;
}

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

int main(){
    long double x, y, r;
    cin >> x >> y >> r;

  	r = nextafter(r, INFINITY);
    long long ans = 0;
    for (long long i = ceil(x - r); i <= floor(x + r); i++){
        long double p = sqrt(r * r - (x - i) * (x - i));
        ans += floor(y + p) - ceil(y - p) + 1;
    }

    cout << ans << endl;

    return 0;
}


// 2021-03-06 21:04:00
// clang-format off
#include <bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

// clang-format on
const int inf = 1e9;
void answer() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];
  int ans = inf;
  rep(i, n) rep(j, n) {
    if (i == j) {
      chmin(ans, a[i] + b[i]);
    } else {
      chmin(ans, max(a[i], b[j]));
    }
  }
  cout << ans << '\n';
}

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

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

int n, k;

int main()
{
	cin >> n >> k;

	for (int i = 0; i < k; i++) {
		vector<int> g;

		while (n > 0) {
			g.push_back(n % 10);
			n /= 10;
		}

		sort(g.begin(), g.end());
		int u = 0;

		for (int j : g) {
			u *= 10;
			u += j;
		}

		reverse(g.begin(), g.end());

		int v = 0;

		for (int j : g) {
			v *= 10;
			v += j;
		}

		n = v - u;
	}

	cout << n << endl;
}


#include <algorithm>
#include <iostream>
#include <string>
#include <functional>
#include <vector>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cmath>
#include <climits>
#include <queue>
#include <bitset>
#include <set>
#include <assert.h>
using namespace std;
typedef vector<vector<long> > dim2veclo;
typedef vector<vector<int> > dim2vecin;
typedef vector<vector<double> > dim2vecdo;
typedef vector<vector<long long> > dim2vecll;
typedef vector<int> vecin;
typedef vector<long> veclo;
typedef vector<double> vecdo;
typedef vector<long long> vecll;
typedef vector<bool> vecbo;
typedef vector<vector<bool> > dim2vecbo;
typedef long long ll;
typedef vector < pair<ll, ll> > vecpa;
typedef vector<string> vecst;
typedef pair<ll, ll> pail;

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

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

const ll INF = 100000000000000;

int main() {
    int x, y, z;
    cin >> x >> y >> z;
    if (y * z % x == 0) cout << y * z / x - 1;
    else cout << y * z / x;
    cout << endl;

    return 0;
}

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

ll pow_mod(ll a, ll n, ll mod) {
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n/=2;
  }
  return res;
}

int main() {
  ll N,M,K; cin>>N>>M>>K;
  ll ans = 0;

  if(N==1 || M==1) ans=pow_mod(K,M+N-1,MOD);
  else {
    for(int i=1; i<=K; ++i) {
      ll result1=(pow_mod(i,N,MOD)-pow_mod(i-1,N,MOD)+MOD)%MOD;
      ll result2=pow_mod(K-i+1,M,MOD);
      ans=(ans+result1*result2)%MOD;
    }
  }
  cout << ans << endl;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll ;
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define pb push_back

vector<vector<int> > adj ;
vector<ll> val,m ;
vector<bool> vis ;
ll ans ;

ll dfs(int x)
{
	if(vis[x]) return m[x] ;
	ll ma=-1e9 ;
	vis[x]=1 ;
	rep(i,0,adj[x].size())
	{
		ma=max(ma,dfs(adj[x][i])) ;
	}
	ans=max(ans,ma-val[x]) ;
	ma=max(ma,val[x]) ;
	m[x]=ma ;
	return m[x] ;
}

int main()
{
	int T=1;
	// cin >> T ;

	while(T--)
	{
		int n,me ;
		cin>>n>>me ;
		adj.resize(0) ;
		adj.resize(n) ;
		val.resize(n) ;
		rep(i,0,n) cin>>val[i] ;
		m.resize(n) ;
		rep(i,0,n) m[i]=val[i] ;
		int x,y ;
		rep(i,0,me)
		{
			cin>>x>>y ; x-- ; y-- ;
			adj[x].pb(y) ;
		}
		vis.resize(0) ;
		vis.resize(n) ;
		rep(i,0,n) vis[i]=0 ;
		ans=-1e9 ;
		rep(i,0,n)
		{
			if(!vis[i])
			{
				dfs(i) ;

			}
		}

		cout<<ans<<endl ;
	}
	return 0;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> adj(N);
  vector<int> A(N);
  for (auto &i : A) cin >> i;
  for (int i = 0; i < M; i++) {
    int u, v;
    cin >> u >> v;
    adj[--u].emplace_back(--v);
  }
  vector<lint> dp(N, -1e18);
  lint ans = -1e18;
  for (int i = N - 1; i >= 0; i--) {
    for (auto j : adj[i]) {
      ans = max(ans, -A[i] + dp[j]);
    }
    dp[i] = max(dp[i], 1ll * A[i]);
    for (auto j : adj[i]) {
      dp[i] = max(dp[i], dp[j]);
    }
  }
  cout << ans << '\n';
  return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> A(N),B(N);
  int ans=1e9;
  for(int i=0;i<N;i++){
    cin >> A.at(i) >> B.at(i);
  }
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      if(i==j){
        ans=min(ans,A.at(i)+B.at(j));
      }else{
        ans=min(ans,max(A.at(i),B.at(j)));
      }
    }
  }
  cout << ans << endl;
  return 0;
}

#include <bits/stdc++.h>
// #include <atcoder/all>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
// #define MOD 998'244'353
// #define MOD 1'000'000'007
// #define INF 1'000'000'000'000'000'000
using namespace std;
// using namespace atcoder;
typedef long long ll;

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

    vector<pair<int, int> > A(N);
    vector<pair<int, int> > B(N);
    // vector<int> A(N);
    // vector<int> B(N);
    rep(i, N){
        cin >> A[i].first >> B[i].first;
        A[i].second = i;
        B[i].second = i;
    }
    // rep(i, N) cin >> A[i] >> B[i];

    sort(A.begin(), A.end());
    sort(B.begin(), B.end());

    int ans;

    if (A[0].second != B[0].second){
        ans = max(A[0].first, B[0].first);
    }else{
        ans = A[0].first + B[0].first;
        ans = min(ans, max(A[1].first, B[0].first));
        ans = min(ans, max(A[0].first, B[1].first));
    }
    cout << ans << endl;

    return 0;
}


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

long long N;

vector<long long> divisor(long long n) {
  vector<long long> res;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      if (i != n / i) {
        res.push_back(n / i);
      }
    }
  }
  return res;
}

bool check(long long l) {
  long long v = 2 * N / l - l + 1;
  if (abs(v) % 2 == 0) {
    return true;
  } else {
    return false;
  }
}

int main() {

  cin >> N;

  int ans = 0;
  vector<long long> L = divisor(N);

  for (long long i = 0; i < int(L.size()); ++i) {
    if (check(L[i])) {
      ans++;
    }
    long long l2 = N * 2 / L[i];
    if (i != l2) {
      if (check(l2)) {
        ans++;
      }
    }
  }

  cout << ans << endl;

  return 0;

}

#include<iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
using namespace std;

//int N=1;
int P[11] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
int binary(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
int rev(int original)
{
	int reversed = 0;

	while (original > 0) {
		reversed = original % 10 + reversed * 10;
		original = original / 10;
	}
	return reversed;
}

int main() {
	int n, cou = 0;
	cin >> n;
	for (int i = 0;i < 10;i++) {
		if (n % 10 == 0) {
			n /= 10;
		}
		else {
			break;
		}
	}
	if (n == rev(n)) cout << "Yes";
	else cout << "No";

}


#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string(string(s)); }
string to_string(bool b) { return to_string(int(b)); }
string to_string(vector<bool>::reference b) { return to_string(int(b)); }
string to_string(char b) { return "'" + string(1, b) + "'"; }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A>
string to_string(A v) {
	string res = "{";
	for (const auto& x : v) res += (res == "{" ? "" : ", ") + to_string(x);
	return res + "}";
}
void debug() { cerr << endl; }
template <typename Head, typename... Tail>
void debug(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug(T...);
}
#define db(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define db(...) 42
#endif
typedef long long ll;
typedef long double ld;
int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	vector<pair<int, int>> H(n);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &H[i].first);
	}
	for (int i = 0; i < m; ++i) {
		int w;
		scanf("%d", &w);
		H.push_back({w, 1});
	}
	sort(H.begin(), H.end());
	int las = 0;
	ll s = 0;
	vector<pair<ll, int>> suf(H.size() + 1);
	for (int i = (int)H.size() - 1; i >= 0; --i) {
		if (H[i].second == 0) {
			if (las == 0) las = H[i].first;
			else {
				s += las - H[i].first;
				las = 0;
			}
			suf[i] = {s, las};
		} else suf[i] = suf[i + 1];
	}
	las = s = 0;
	ll ans = LLONG_MAX;
	for (int i = 0; i < H.size(); ++i) {
		int v = H[i].first;
		int t = H[i].second;
		if (t == 1) {
			ll sum = suf[i + 1].first + s;
			if (suf[i + 1].second) {
				sum += suf[i + 1].second - v;
			} else {
				sum += v - las;
			}
			ans = min(ans, sum);
		} else {
			if (las == 0) las = v;
			else {
				s += v - las;
				las = 0;
			}
		}
	}
	printf("%lld\n", ans);
}


#include <vector>
#include <array>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);

    int n;
    cin >> n;
    vector<long long> A(n);

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

    long long sum = 0;
    long long pre = 0;
    long long res = 0;
    long long mx = 0;
    for (int i = 0; i < n; ++i) {
        mx = max(mx, A[i]);
        res = mx * (i + 1);
        pre += A[i];
        sum += pre;
        res += sum;
        cout << res << '\n';
    }

    return 0;
}

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

int charToInt(char c){
    char zero_num = '0';
    return (int)c - (int)zero_num;
}

void cout_line(vector<int> &a){
    for(int i=0;i<a.size();i++){
        if(i<a.size()-1){
            cout<<a.at(i)<<" ";
        }else{
            cout<<a.at(i)<<endl;
        }
    }
}

signed main(){
    int N; cin>>N;
    vec_int A(N); rep(i,N)cin>>A.at(i);

    vec_int cumul(N+1, 0);
    vec_int max_val(N+1, 0);
    rep(i,N){
        cumul.at(i+1) = cumul.at(i)+ A.at(i);
        max_val.at(i+1) = max(A.at(i), max_val.at(i));
    }

    int prev_ans = 0;

    for(int i=0;i<N;i++){
        int tot_sum = cumul.at(i+1);
        tot_sum += prev_ans;
        tot_sum += (i+1)*max_val.at(i+1);

        cout<<tot_sum<<endl;
        prev_ans = tot_sum-(i+1)*max_val.at(i+1);
    }

    return 0;
}


// Problem: A - Rock-paper-scissors
// Contest: AtCoder - AtCoder Beginner Contest 204
// URL: https://atcoder.jp/contests/abc204/tasks/abc204_a
// Memory Limit: 1024 MB
// Time Limit: 2000 ms

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

int main() {
	int x, y;
	cin >> x >> y;
	if (x == y) cout << x;
	else cout << 3 - x - y;
	return 0;
}


#pragma region
#ifdef LOCAL
#include "pch.h"
#else
#include <bits/stdc++.h>
#endif

// debug
template<typename ... Types>
void __read(Types& ... args) {
  ((std::cin >> args), ...);
}
#define read(type, ...) type  __VA_ARGS__; __read(__VA_ARGS__)

template <typename Type, typename... Types>
auto print(Type const &arg, Types const &... args) {
  std::cout << arg, ((std::cout << " " << args), ...), std::cout << std::endl;
}
template <typename Type, typename... Types>
auto print_debug(Type const &arg, Types const &... args) {
  std::cout << arg, ((std::cout << " | " << args), ...), std::cout << std::endl;
}
#ifdef LOCAL
#define debug(...) do{std::cout <<  __LINE__ << ": [" << #__VA_ARGS__ << "]: ", print_debug(__VA_ARGS__);}while(0)
#else
#define debug(...) 1
#endif

#define __DEF_PRINTER(container)                                          \
template<typename T>                                                      \
std::ostream& operator<<(std::ostream& out, container<T> const& a)        \
{                                                                         \
  size_t len = a.size();                                                  \
  for(auto x : a) out << x << " \n"[len--==0];                            \
  return out;                                                             \
}

__DEF_PRINTER(std::vector)
__DEF_PRINTER(std::set)
__DEF_PRINTER(std::unordered_set)
// end debug

#define ALL(container) std::begin(container), std::end(container)
#define RANGE(container, lo, hi) std::begin(container)+(lo), std::begin(container)+(hi)

const char nl = '\n';
using std::cout;
using std::cin;

template <typename T>
void minmax(T k1, T k2, T& min, T& max) {
  min = std::min(k1, k2);
  max = std::max(k1, k2);
}

std::vector<int> iota(int size) {
  std::vector<int> res(size);
  std::iota(res.begin(), res.end(), 0);
  return res;
}

template <typename Iter>
auto counter(Iter from, Iter to) {
  std::map<typename Iter::value_type, int> res;
  while(from != to) res[*from++]++;
  return res;
}

const long long mod = 1e9+7;
long long reduce_mod(long long a) {
  return (a % mod + mod) % mod;
}
long long add(long long a, long long b) {
  return reduce_mod(a + b);
}
long long mult(long long a, long long b) {
  return reduce_mod(a * b);
}

std::string yn(bool yes) {
  return yes ? "yes" : "no";
}

#pragma endregion

int main() {
  read(int, n);
  int min = -1;
  int max = -1;
  for (int i = 0; i < n; i++) {
    read(int, b);
    // debug(b);
    max = max == -1 ? b : std::max(max, b);
  }
  for (int i = 0; i < n; i++) {
    read(int, a);
    // debug(a);
    min = min == -1 ? a : std::min(min, a);
  }
  // debug(min, max);
  if (min < max) {
    print(0);
  } else {
    print(min-max+1);
  }
}

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

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
#define all(v) begin(v), end(v)
#define sz(v) (int)(v).size()
#define fi first
#define se second

const int md = 998244353;

namespace modular {
  inline int mul() { return 1; }
  template <typename... V>
  inline int mul(int a, V... v) {
  #if !defined(_WIN32) || defined(_WIN64)
    return (int) ((long long) a * mul(v...) % md);
  #endif
    unsigned long long x = (long long) a * mul(v...);
    unsigned xh = (unsigned) (x >> 32), xl = (unsigned) x, d, m;
    asm(
      "divl %4; \n\t"
      : "=a" (d), "=d" (m)
      : "d" (xh), "a" (xl), "r" (md)
    );
    return m;
  }
  template<typename... V>
  inline void mulby(int &a, V... v) {
    a = mul(a, v...);
  }
  inline int add() { return 0; }
  template<typename... V>
  inline int add(int x, V... v) {
    x += add(v...); if(x >= md) x -= md; return x;
  }
  template<typename... V>
  inline void addto(int &a, V... v) {
    a = add(a, v...);
  }
  inline int sub(int a, int b) {
    if((a -= b) < 0) a += md;
    return a;
  }
  inline void subfrom(int &a, int b) {
    if((a -= b) < 0) a += md;
  }
  inline int qpow(int b, int p) {
    if(p < 0) {
      return qpow(qpow(b, -p), md-2);
    } int ret = 1;
    while(p) {
      if(p & 1) mulby(ret, b);
      mulby(b, b); p >>= 1;
    } return ret;
  }
} using namespace modular;

int main(int argc, char const *argv[])
{
  cin.sync_with_stdio(0); cin.tie(0);
  cin.exceptions(cin.failbit);
#ifdef LOCAL
  freopen("in", "r", stdin);
#endif
  int n, m;
  cin >> n >> m;
  vector<vi> pw(m+1, vi(n+1, 1));
  for(int i = 0; i <= m; ++i) {
    for(int j = 1; j <= n; ++j) {
      pw[i][j] = mul(pw[i][j-1], i);
    }
  }
  vi sum(n, 0);
  for(int i = 0; i < n; ++i) {
    for(int x = 1; x <= m; ++x) {
      addto(sum[i], pw[m-x][i]);
    }
  }
  int ans = 0;
  for(int i = 1; i <= n; ++i) {
    for(int j = i+1; j <= n; ++j) {
      addto(ans, mul(sum[j-i-1], pw[m][n-(j-i)-1]));
    }
  }
  cout << sub(mul(n, pw[m][n]), ans) << endl;
  return 0;
}
/*
* use std::array instead of std::vector, if u can
* overflow?
* array bounds
*/


#include <bits/stdc++.h>
#define ll long long
#define maxn 100005
#define mod 1000000007
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
ll a[maxn], b[maxn];
priority_queue<pii,vector<pii>, less<pii> > pq;
int main() {
	io
	ll k, n,  m;
	cin >> k >> n >> m;
	for (int i = 0;i < k;i++) cin >> a[i], a[i] *= m;
	ll tot = 0;
	for (int i = 0;i < k;i++) {
		b[i] = a[i] - a[i] % n;
		tot += b[i];
		pq.push(make_pair(a[i] - b[i], i));
	}
	while (tot < n * m) {
		pii cur = pq.top();
		pq.pop();
		tot += n;
		b[cur.ss] += n;
	}
	for (int i = 0;i < k;i++) cout << b[i] / n << " ";
	cout << endl;
}
/*
*/

#include <algorithm>
#include <iomanip>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <numeric>
#include <vector>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i, n) _rep2(i, 0, n)
#define _rep2(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using i64 = long long;
template<class T, class U>
bool chmin(T& a, const U& b) { return (b < a) ? (a = b, true) : false; }
template<class T, class U>
bool chmax(T& a, const U& b) { return (b > a) ? (a = b, true) : false; }

template<typename T>istream& operator>>(istream&i,vector<T>&v){rep(j,v.size())i>>v[j];return i;}
template<typename T>string join(vector<T>&v){stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,vector<T>&v){if(v.size())o<<join(v);return o;}
template<typename T>string join(vector<vector<T>>&vv){string s="\n";rep(i,vv.size())s+=join(vv[i])+"\n";return s;}
template<typename T>ostream& operator<<(ostream&o,vector<vector<T>>&vv){if(vv.size())o<<join(vv);return o;}
template<class T> using pq = priority_queue<T, vector<T>, greater<T>>;

int main()
{
    int k, n, m;
    cin >> k >> n >> m;

    vector<long double> a(k);
    vector<int> b(k);
    vector<pair<long double, int>> p(k);

    cin >> a;

    rep(i, k) b[i] = (a[i] * m) / n + 0.001;

    int r = m - accumulate(all(b), 0);

    rep(i, k)
    {
        p[i].first = b[i] - (a[i] * m) / n;
        p[i].second = i;
    }
    sort(all(p));

    rep(i, r)
    {
        b[p[i].second]++;
    }

    cout << b << endl;

    return 0;
}


#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
#include<cstring>
#include<map>
#include<set>
#include<cstdlib>
#include<bitset>
using namespace std;
#define FAST ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
typedef long long ll;
int main(void)
{
	ll n;
	cin>>n;
	double ans=0;
	for(ll i=1;i<n;i++)
	{
		ans+=(double)(n)/(double)(i);
	}
	printf("%.10lf",ans);
}


#include <iostream>
#include <vector>
#include <string>
#include <math.h>
using namespace std;

int main()
{
    int H, W, X, Y, count = 0;
    cin >> H >> W >> X >> Y;
    vector<string> S(H);
    for (int i = 0; i < H; i++) cin >> S.at(i);
    if (S.at(X - 1).at(Y - 1) == '#') goto finish;
    else count++;
    for (int i = X - 2; i >= 0; i--) {
        if (S.at(i).at(Y - 1) == '#') break;
        else count++;
    }
    for (int i = X; i < H; i++) {
        if (S.at(i).at(Y - 1) == '#') break;
        else count++;
    }
    for (int j = Y - 2; j >= 0; j--) {
        if (S.at(X - 1).at(j) == '#') break;
        else count++;
    }
    for (int j = Y; j < W; j++) {
        if (S.at(X - 1).at(j) == '#') break;
        else count++;
    }
    finish: cout << count << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int h, w, n, m; cin >> h >> w >> n >> m;
  vector<string> board(h, string(w, ' '));
  vector<int> A(n), B(n), C(m), D(m);
  rep(i, n) {
    cin >> A[i] >> B[i];
    A[i]--; B[i]--;
    board[A[i]][B[i]] = '.';
  }
  rep(i, m) {
    cin >> C[i] >> D[i];
    C[i]--; D[i]--;
    board[C[i]][D[i]] = '#';
  }
  set<pair<int, int>> st;
  rep(i, h) {
    int l = 0, r = 0;
    while(l < w) {
      while(l < w && board[i][l] == '#') l++;
      bool ok = false;
      r = l;
      while(r < w && board[i][r] != '#') {
        if(board[i][r] == '.') ok = true;
        r++;
      }
      if(ok) {
        for(int j=l; j<r; j++) {
          st.insert({i, j});
        }
      }
      l = r;
    }
  }
  rep(i, w) {
    int l = 0, r = 0;
    while(l < h) {
      while(l < h && board[l][i] == '#') l++;
      bool ok = false;
      r = l;
      while(r < h && board[r][i] != '#') {
        if(board[r][i] == '.') ok = true;
        r++;
      }
      if(ok) {
        for(int j=l; j<r; j++) {
          st.insert({j, i});
        }
      }
      l = r;
    }
  }
  cout << st.size() << endk;
  return 0;
}


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

using namespace std;

int main()
{
    int n;
    int64_t x, c;
    cin >> n;
    vector<vector<int64_t>> balls(n + 1, vector<int64_t>(0));
    for (size_t i = 0; i < n; i++)
    {
        cin >> x >> c;
        balls[c].push_back(x);
    }
    for (int i = 1; i <= n; i++)
    {
        sort(balls[i].begin(), balls[i].end());
    }

    const int64_t INF = 1LL << 60;
    vector<vector<int64_t>> dp(n + 1, vector<int64_t>(2, INF));

    int64_t l = 0, r = 0, cost_l = 0, cost_r = 0;
    for (int64_t i = 1; i <= n; i++)
    {
        if (balls[i].empty())
            continue;
        auto l2 = balls[i][0];
        auto r2 = balls[i][balls[i].size() - 1];

        int64_t cost_l2 = INF, cost_r2 = INF;

        // l->r2->l2
        cost_l2 = min(cost_l2, cost_l + abs(r2 - l2) + abs(l - r2));
        // r->r2->l2
        cost_l2 = min(cost_l2, cost_r + abs(r - r2) + abs(r2 - l2));

        // l->l2->r2
        cost_r2 = min(cost_r2, cost_l + abs(l - l2) + abs(r2 - l2));
        // r->l2->r2
        cost_r2 = min(cost_r2, cost_r + abs(r - l2) + abs(r2 - l2));

        l = l2;
        r = r2;
        cost_l = cost_l2;
        cost_r = cost_r2;
    }

    int64_t ans = min(cost_l + abs(l), cost_r + abs(r));

    cout << ans << endl;
}

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

#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) sort((a).rbegin(),(a).rend())
#define ll long long
#define pb(a) push_back(a)

#define PRINTV(v) {for(ll deB=0; deB<(v).size(); deB++){cout << (v)[deB] << " ";}cout << endl;}

int main(){
	ll N;
	cin >> N;
	vector<ll> X(N), C(N);
	REP(i,N){
		cin >> X[i] >> C[i];
	}

	vector<ll> cnum(N, 0);
	vector<ll> cmin(N, INT64_MAX);
	vector<ll> cmax(N, INT64_MIN);
	REP(i,N){
		cnum[C[i]-1] ++;
		if(X[i] < cmin[C[i]-1]) cmin[C[i]-1] = X[i];
		if(X[i] > cmax[C[i]-1]) cmax[C[i]-1] = X[i];
	}

	ll hi_dis = 0;
	ll hi_pos = 0;
	ll low_dis = 0;
	ll low_pos = 0;
	REP(i, N){
		if(cnum[i] == 0) continue;
		ll hi2low = hi_dis + ((hi_pos > cmax[i])?(hi_pos - cmax[i]):(cmax[i] - hi_pos)) + (cmax[i] - cmin[i]);
		ll low2low = low_dis + ((low_pos > cmax[i])?(low_pos - cmax[i]):(cmax[i] - low_pos)) + (cmax[i] - cmin[i]);
		ll hi2hi = hi_dis + ((hi_pos > cmin[i])?(hi_pos - cmin[i]):(cmin[i] - hi_pos)) + (cmax[i] - cmin[i]);
		ll low2hi = low_dis + ((low_pos > cmin[i])?(low_pos - cmin[i]):(cmin[i] - low_pos)) + (cmax[i] - cmin[i]);

		hi_dis = (hi2hi < low2hi) ? hi2hi : low2hi;
		low_dis = (hi2low < low2low) ? hi2low : low2low;

		hi_pos = cmax[i];
		low_pos = cmin[i];
	}
	hi_dis += ((hi_pos > 0)?hi_pos:-hi_pos);
	low_dis += ((low_pos > 0)?low_pos:-low_pos);

	ll ans = (hi_dis < low_dis) ? hi_dis : low_dis;

	cout << ans << endl;

	return 0;
}


//#include <bits/stdc++.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <string.h>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <queue>
#include <math.h>
#include <assert.h>
#define ff first
#define ss second
#define ll long long
#define mod 1000000007
using namespace std;
ll v, l, r, x;
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>v>>l>>r>>x;
    ll lx = v * l, rx = v * r;
    if(x >= lx && x <= rx)
        cout<<"No";
    else
        cout<<"Yes";
}

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

// clang-format off
#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx")
#define int long long
using namespace std;
#define stoi stoll
#define fi first
#define se second
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; i++)
#define rep2(i, a, b) for (int i = (int)(a), i##_len=(b); i < i##_len; i++)
#define rep3(i, a, b) for (int i = (int)(a), i##_len=(b); i >= i##_len; i--)
#define FOR(i, a) for (auto &i: a)
#define ALL(obj) begin(obj), end(obj)
#define _max(x) *max_element(ALL(x))
#define _min(x) *min_element(ALL(x))
#define _sum(x) accumulate(ALL(x), 0LL)

const int MOD   = 1000000007;
// const int MOD    = 998244353;
const int INF    = 10000000000007; // 1e13 + 7
const int INF2    = LLONG_MAX; // 9.2e18
const double EPS = 1e-8;
const double PI  = 3.14159265358979;
template <class T> using V = vector<T>;
template <class T> using VV = vector<vector<T>>;
template <class T> using VVV = vector<vector<vector<T>>>;
template <class T, class S>  using P = pair<T, S>;
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b;return true;}return false;}
template<class T> bool chmin(T &a, const T &b) {if (b < a) {a = b;return true;}return false;}
int _ceil(int a, int b) { return (a >= 0 ? (a + (b - 1)) / b : (a - (b - 1)) / b); }
template<class T> T chmod(T &a, T mod=MOD) {a =  a >= 0 ? a % mod : a - (mod * _ceil(a, mod)); return a;};
int _mod(int a, int mod=MOD) {return a >= 0 ? a % mod : a - (mod * _ceil(a, mod));}
int _pow(int a, int b) {int res = 1;for (a %= MOD; b; a = a * a % MOD, b >>= 1)if (b & 1) res = res * a % MOD;return res;}
struct mint {long long x;mint(long long x = 0) : x((x % MOD + MOD) % MOD) {}mint operator-() const { return mint(-x); }mint &operator+=(const mint a) {if ((x += a.x) >= MOD) x -= MOD;return *this;}mint &operator-=(const mint a) {if ((x += MOD - a.x) >= MOD) x -= MOD;return *this;}mint &operator*=(const mint a) { (x *= a.x) %= MOD;return *this; }mint operator+(const mint a) const { return mint(*this) += a; }mint operator-(const mint a) const { return mint(*this) -= a; } mint operator*(const mint a) const { return mint(*this) *= a; }mint pow(long long t) const {if (!t) return 1;mint a = pow(t >> 1);a *= a;if (t & 1) a *= *this;return a;}mint inv() const { return pow(MOD - 2); }mint &operator/=(const mint a) { return *this *= a.inv(); }mint operator/(const mint a) const { return mint(*this) /= a; }};istream &operator>>(istream &is, mint &a) { return is >> a.x; }ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
// clang-format on

class AVanishingPitch {
public:
  static void solve(istream &cin, ostream &cout) {
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    int v, t, s, d;
    cin >> v >> t >> s >> d;
    if (t * v <= d and d <= v * s) {
      cout << "No" << endl;
    } else {
      cout << "Yes" << endl;
    }
  }
};

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


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

int main() {
	int N;
	long long X;
	cin >> N >> X;
	vector<long long>A(N + 1);
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
	A[N] = A[N - 1] * 1000;
	vector<vector<long long>> dp(N + 1, vector<long long>(2, 0));
	dp[0][0] = 1;
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < 2; ++j) {
			long long d = (X / A[i] + j)% (A[i + 1] / A[i]);
			if (0 == d) {
				dp[i + 1][j] += dp[i][j];
			}
			else {
				dp[i + 1][0] += dp[i][j];
				dp[i + 1][1] += dp[i][j];
			}
		}
	}
	cout << dp[N][0] << endl;
	return 0;
}

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

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

const ll mod = 1000000007;

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

  int n;
  ll x;
  cin >> n >> x;
  vector<ll> a(n);
  for (auto &y: a) cin >> y;

  reverse(a.begin(), a.end());

  if (x % a[0] == 0) {
    cout << 1 << endl;
    return 0;
  }
  ll pos = 1;
  ll neg = 1;
  ll rem_pos = x % a[0];
  ll rem_neg = -(x % a[0] - a[0]);
  for (int i = 1; i < n; i++) {
    if (rem_pos % a[i] == 0) break;
    ll next_pos = 0;
    ll next_neg = 0;
    if (a[i] * (rem_pos / a[i] + 1) == a[i-1]) next_pos += pos;
    else {
      next_pos += pos;
      next_neg += pos;
    }
    if (a[i] * (rem_neg / a[i] + 1) == a[i-1]) next_neg += neg;
    else {
      next_neg += neg;
      next_pos += neg;
    }
    rem_pos = rem_pos % a[i];
    rem_neg = -(rem_pos % a[i] - a[i]);
    pos = next_pos;
    neg = next_neg;
  }

  ll ans = pos + neg;

  cout << ans << endl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll a,b;
    cin>>a>>b;
    vector<int>primes={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71};
    vector<ll>dp(1<<20);
    dp[0]=1;
    for(ll i=a;i<=b;i++){
        int s=0,t=0;
        rep(k,20){
            if(i%primes[k])s|=(1<<k);
            else t|=(1<<k);
        }
        for(int j=s-1;j>=0;j=(j-1)&s){
            //choose i
            dp[j|t]+=dp[j];
            if(j==0)break;
        }
    }
    ll ans=0;
    for(ll i:dp)ans+=i;
    cout<<ans<<endl;
    return 0;
}

#include <bits/stdc++.h>
// #include <atcoder/all>
// #include "icld.cpp"
using namespace std;
using ll = long long int;
using vi = vector<int>;
using si = set<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using ss = string;
using db = double;
template<typename T> using minpq = priority_queue <T,vector<T>,greater<T>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
#define V vector
#define pii pair<int,int>
#define pll pair<ll,ll>
#define rep(i,s,n) for(int i=(s);i<(int)(n);i++)
#define rev(i,s,n) for(int i=(s);i>=(int)(n);i--)
#define reciv(v,n) vll (v)((n)); rep(i,0,(n))cin>>v[i]
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define ci(x) cin >> x
#define cii(x) ll x;cin >> x
#define cci(x,y) ll x,y;cin >> x >> y
#define co(x) cout << x << endl
#define pb push_back
#define eb emplace_back
#define rz resize
#define pu push
#define sz(x) int(x.size())
#define vij v[i][j]
// ll P = 1e9+7;
// ll P = 998244353;
// n do -> n*pi/180
#define yn cout<<"Yes"<<endl;else cout<<"No"<<endl
#define YN cout<<"YES"<<endl;else cout<<"NO"<<endl
template<class T>void chmax(T &x,T y){x=max(x,y);}
template<class T>void chmin(T &x,T y){x=min(x,y);}

int main(){
  db x1,a,x2,b;
  cin>>x1>>a>>x2>>b;

  db ans=(a*x2+b*x1)/(a+b);
  printf("%.9lf\n",ans);
}


#include<bits/stdc++.h>
#define pi 3.141592653589793238
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define MOD 1000000007
#define INF 999999999999999999
#define pb push_back
#define ff first
#define ss second

#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;

typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const int N = 3e5 + 1;
ll t[4 * N], arr[N];
void build(ll v, ll tl, ll tr){
    if(tl == tr){
        t[v] = arr[tl];
        return;
    }
    ll tm = (tl + tr) /2;
    build(2 * v, tl, tm);
    build(2 * v + 1, tm + 1, tr);
    t[v] = t[2 * v] ^ t[2 * v + 1];
}
void update(ll v, ll tl, ll tr, ll idx, ll y){
    if(tl == tr){
        t[v] ^= y;
        return;
    }
    ll tm = (tl + tr) / 2;
    if(idx <= tm){
        update(2 * v, tl, tm, idx, y);
    }
    else{
        update(2 * v + 1, tm + 1, tr, idx, y);
    }
    t[v] = t[2 * v] ^ t[2 * v + 1];
}
ll query(ll v, ll tl, ll tr, ll l, ll r){
    if(l > r){
        return 0;
    }
    if(tl == l && tr == r){
        return t[v];
    }
    ll tm = (tl + tr) / 2;
    ll lef, rig;
    lef = query(2 * v, tl, tm, l, min(r, tm));
    rig = query(2 * v + 1, tm + 1, tr, max(l, tm + 1), r);
    return (lef ^ rig);
}
int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    ll T = 1, i, j;

    //cin >> T;
    while (T--) {
        ll n, q;
        cin >> n >> q;
        for(i = 1; i <= n; i++){
            cin >> arr[i];
        }
        build(1, 1, n);
        while(q--){
            ll t;
            cin >> t;
            ll x, y;
            cin >> x >> y;
            if(t == 1){
                update(1, 1, n, x, y);
            }
            else{
                cout << query(1, 1, n, x, y) << "\n";
            }
        }
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<ll>
#define rep(i,a,b) for(int i=a; i<b; ++i)
#define pb push_back
#define endl '\n'
#define sa(x) sort((x).begin(), (x).end());
#define int long long

template<typename T, typename U> static inline void amin(T &x, U y){ if(y<x) x=y; }
template<typename T, typename U> static inline void amax(T &x, U y){ if(x<y) x=y; }
template<typename T> static inline void sd(vector<T> &x) {sort((x).begin(), (x).end(), greater<T>()) ; }

int n, m;
const int N=1e5+5;
vector<pair<int, pair<int, int>>> g[N];
#define ii pair<ll, ll>
#define vii vector<ii>
#define x first
#define y second
const int inf=LLONG_MAX;
void solve(){
	cin>>n>>m;
    rep(i,0,m)
    {
        int e, f, c, d;
        cin>>e>>f>>c>>d;
        g[e].pb({f, {c, d}});
        g[f].pb({e, {c, d}});
    }

    set<ii> se;
    se.insert({0, 1});
    vi dis(n+1, inf);
    while(!se.empty())
    {
        auto top = *(se.begin());
        se.erase(se.begin());

        int v=top.y;
        dis[v] = top.x;
        for(auto ch : g[v])
        {
            int D=ch.y.y, X=dis[v], C=ch.y.x, tar=ch.x;
            // cout<<v<<" to "<<tar<<endl;
            // cout<<C<<" and "<<D<<" "<<X<<endl;
            int t = sqrt(D) - X - 1;
            vector<int> ts = {max(t-1, 0ll), max(t, 0ll), max(t+1, 0ll)};

            int ans=dis[tar];

            for(int tt : ts)
            {
                // cout<<tt<<" "<<1<<" "<<X<<endl;
                int tmp = C + D/(tt+1+X) + X + tt;
                // cout<<"wait "<<tt<<" get"<<tmp<<endl;
                if(tmp < ans)
                {
                    ans=tmp;
                }
            }

            if(ans < dis[tar])
            {
                if(dis[tar] != inf)
                {
                    se.erase({dis[tar], tar});
                }
                dis[tar] = ans;
                se.insert({dis[tar], tar});
            }

        }
    }

    // rep(i, 1, n+1)
    // {
    //     if(dis[i]!=inf) cout<<dis[i]<<" ";
    //     else cout<<"x ";
    // }

    if(dis[n] != inf)
        cout<<dis[n];
    else cout<<-1;
}

signed main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int testcases=1;
	//cin>>testcases;
	while(testcases--){
		solve();
	}
	return 0;
}