#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define clr(a) memset(a, 0, sizeof(a))
#define sz(x) x.size()
#define rep(n) for (ll i = 0; i < n; i++)
#define repc(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, x, y) for (ll i = x; i < y; i++)
#define DEC(i, x, y) for (ll i = x; i >= y; i--)
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define alla(a, n) a, a + n

using namespace std;

// Some typedef's
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

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

// Some constants
const int inf = 1e9 + 7;
const double eps = 1e-6;
const double pi = 1.00 * acos(-1.00);
#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(ll t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << t;}
template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
void solve()
{
    int n;
    cin>>n;
    map<int,int> mp;
    rep(n)
    {
        int x;
        cin>>x;
        mp[x]++;
    }

for(int i=1;i<=n;i++)
{
    if(mp[i]==0)
    {
        cout<<"No\n";
        return;
    }
}
cout<<"Yes\n";
}
signed main()
{

    #ifndef ONLINE_JUDGE
    freopen("Error.txt", "w", stderr);
    freopen("Input.txt","r",stdin);
    freopen("Output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }

    return 0;
}

#include <algorithm>
#include <array>
#include <bitset>
#include <deque>
#include <forward_list>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <math.h>
#include <ostream>
#include <queue>
#include <regex>
#include <set>
#include <string>
#include <string_view>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define int long long
#define si(v) size(v)
#define all(v) begin(v), end(v)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, n, m) for (int i = (n); i <= (m); ++i)
#define rep3(i, n, m) for (int i = (n); i >= (m); --i)

#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define pb push_back

template <class S, class T> inline bool chmax(S &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <class S, class T> inline bool chmin(S &a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> using pq  = priority_queue<T>;
template <class T> using pqg = priority_queue<T,vector<T>,greater<T>>;

using ll  = long long;
using ld  = long double;
using vi  = vector<int>;
using pii = pair<int,int>;
using vpi = vector<pii>;

constexpr ll INF   = 2000000000;
constexpr ll INFLL = 2000000000000000000;
constexpr ll MAX   = 500005;
constexpr ll MOD   = 1000000007;

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

  int n; cin >> n;
  vi a(n);

  rep(i, n) cin >> a[i];

  vi s(n+1, 0);
  rep(i, n) s[i+1] += s[i] + a[i];

  vi mx(n+1, 0);
  rep(i, n) chmax(mx[i+1], max(s[i+1], mx[i]));

  int now = 0, ans = 0;
  rep(i, n) {
    int ma = now + mx[i+1];
    now += s[i+1];

    chmax(ans, ma);
  }

  cout << ans << endl;

  return (0);
}


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

double eps = 1e-9;
double pi = acos(-1);

int fx[8] = {1, -1, 0, 0, 1, -1, -1, 1};
int fy[8] = {0, 0, 1, -1, 1, -1, 1, -1};

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

#define fast_io ios_base::sync_with_stdio(false); cin.tie(0);
#define ll long long
#define ull unsigned long long
#define en "\n"
#define ff first
#define ss second
#define sp(x) fixed << setprecision(x)
#define VECT(v)  vector<int>v
#define SCAN(v)  int temp; for(int i=0; i<n; i++) {cin>>temp; v.push_back(temp);}
#define PRINT(v) for(int i = 0; i < v.size(); i++) cout << v[i] << " "; cout << en;
#define SORT(v)  sort(v.begin(), v.end());
#define RSORT(v) sort(v.begin(), v.end(), greater<int>())
#define CASEP(v) cout<<"Case "<<tc<<": "<<v<<"\n"
#define DEBUG(v) cout << v << " "; cout << en;
#define MIN(a, b) a < b ? a : b
#define MAX(a, b) a > b ? a : b
#define mem(a, b) memset(a, b, sizeof(a))
#define valid(nx, ny, row, col) nx >= 0 && nx < row && ny >= 0 && ny < col
#define pii pair <int, int>
#define inf (int)2e9
#define mod (int)1e9 + 7

int main(void)
{
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif

    fast_io

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

	if(a * a + b * b < c * c)
		cout << "Yes\n";
	else
		cout << "No\n";

    return 0;
}

#include <iostream>
using namespace std;

int main(){

int a,b,c; cin>>a>>b>>c;
a*=a;
b*=b;
c*=c;
if(c>a+b)cout<<"Yes";
else cout<<"No";

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ALL(n) begin(n),end(n)
#define IN(a, x, b) (a<=x && x<b)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
template<class T> inline T CHMAX(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T & a, const T b) { return a = (a > b) ? b : a; }

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);

int main(){
    int N;
    cin >> N;
    vector<ll> A(N);
    map<ll,ll> mp;
    ll a;
    ll po = 1;
    ll tmp = 0;
    REP(i,N){
        cin >> a;
        A[i] = po * a;
        po *= -1;
        tmp += A[i];
        if(mp.count(tmp)) mp[tmp] ++;
        else mp[tmp] = 1;
    }

    ll ans = 0;
    tmp = 0;
    REP(i,N-1){
        if(mp.count(tmp)) ans += mp[tmp];
        tmp += A[i];
        mp[tmp] --;
    }

    cout << ans << endl;

    return 0;
}

#include<iostream>
#include<cstdio>
#include<map>
#include<bitset>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<ctime>
using namespace std;
#define M 300005
#define N 1000005
#define MP make_pair
#define debug() cerr<<"Why So Serious?"<<endl
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
template<class T>void Rd(T &x){
	x=0;static char c;
	while(c=getchar(),c<48);
	do x=(x<<1)+(x<<3)+(c^48);
	while(c=getchar(),c>47);
}
int n;
int A[M];
int Sum[2][M];
map<ll,int>S;
int main(){
	Rd(n);
	int a=0;
	ll sum0=0,sum1=0;
	ll ans=0;
	S[0]=1;
	for(int i=1;i<=n;++i){
		Rd(a);
		if(i&1)sum1+=a;
		else sum0+=a;
		ll res=sum1-sum0;
		if(S.find(res)!=S.end())ans+=S[res];
		else if(S.find(res)==S.end())S[res]=0;
		S[res]++;
	}
	printf("%lld\n",ans);
	return 0;
}


#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
const int INF = 1e9;
const ll LINF = 1e18;
template <class T>
void get_unique(vector<T>& x) {
    x.erase(unique(x.begin(), x.end()), x.end());
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    for (int i = 0; i < int(v.size()); i++) {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    for (int i = 0; i < int(v.size()); i++) {
        os << v[i];
        if (i < sz(v) - 1) os << ' ';
    }
    return os;
}

int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n), p(n), invp(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    rep(i, n) {
        cin >> p[i];
        p[i]--;
        invp[p[i]] = i;
    }
    vector<pair<int, int>> ans;
    vector<int> idx(n);
    rep(i, n) idx[i] = i;
    sort(all(idx), [&](int i, int j) { return a[i] < a[j]; });
    for (int i : idx) {
        if (p[i] == i) continue;
        if (a[i] <= b[p[i]]) {
            cout << -1 << '\n';
            return 0;
        }
        ans.emplace_back(i, invp[i]);
        swap(p[invp[i]], p[i]);
        swap(invp[p[i]], invp[p[invp[i]]]);
    }
    cout << sz(ans) << '\n';
    for (auto [i, j] : ans) {
        cout << ++i << ' ' << ++j << '\n';
    }
}

#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>
#include <bitset>
//#include <atcoder/all>

using namespace std;
//using namespace atcoder;

/* template */

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

void debug_out() { std::cout << std::endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

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

struct Edge{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    ll weight;
    edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};

using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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;
}

constexpr ll LNF = 1LL<<50;

constexpr int INF = 1e9+7;

const long double PI=acos(-1);

vector<int> dx = {1,0,-1,0};
vector<int> dy = {0,1,0,-1};

/* template */

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    vector<ll> a(4);
    rep(i,0,4){
        cin >> a[i];
    }
    sort(all(a));
    if(a[3]==a[1]+a[0]+a[2] || a[3]+a[0]==a[1]+a[2] || a[3]+a[1]==a[0]+a[2] || a[3]+a[2]==a[1]+a[0]){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#pragma GCC optimize("Ofast,fast-math,unroll-loops")
#define int long long
#define pb push_back
#define MP make_pair
#define pii pair<int,int>
#define F first
#define S second
#define SZ(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define LINE cout << "\n---------------\n";
#define endl cout << '\n';
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define debug(x) cerr << #x << " = "  << x << '\n';
using namespace std;
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
int dp[(1<<19)];
struct T
{
	int X,Y,Z;
	T(int _x , int _y , int _z):X(_x) , Y(_y) , Z(_z){}
	T(){}
};
vector<T> limit;
signed main(){
	IOS;
	int n , m ;
	cin >> n >> m ;
	for(int i=0 ; i<m ; ++i){
		int x,y,z;
		cin >> x >> y >> z;
		limit.push_back({x,y,z});
	}
	//basic
	dp[0]=1;
	//dp
	for(int i=1 ; i<(1<<n) ; ++i){
		int bits=0;
		for(int j=0 ; j<n ; ++j){
			bits += (i >> j & 1);
		}
		bool ok = 1;
		for(int j=0 ; j<m ; ++j){
			int x = limit[j].X , y = limit[j].Y , z = limit[j].Z;
			if(bits <= x){
				int cnt=0;
				for(int k=0 ; k<y ; ++k) cnt += (i >> k & 1);
				if(cnt > z) ok = 0;
			}
		}
		if(ok){
			for(int j=0 ; j<n ; ++j){
				if(i >> j & 1){
					dp[i] += dp[i ^ (1<<j)];
				}
			}
		}
		// cout << dp[i] << '\n';
	}
	cout << dp[(1<<n)-1] << '\n';

}

#include<iostream>
#include<vector>
using namespace std;
#define popcount __builtin_popcount

int main(){
	int n,m;
	cin>>n>>m;
	int xyz[110][3];
	for(int i=0;i<m;i++)for(int j=0;j<3;j++)cin>>xyz[i][j];
	int n2=1<<n;
	long long mask[110]={0};
	vector<long long> dp(n2);
	for(int i=0;i<n;i++)mask[i+1]=mask[i]<<1|1;
	dp[0]=1;
	for(int s=0;s<n2;s++){
		int x=popcount(s);
		for(int i=0;i<m;i++){
			if(x==xyz[i][0])
			if(popcount(s&mask[xyz[i][1]])>xyz[i][2])dp[s]=0;
		}
		for(int i=0;i<n;i++){
			if(~s>>i&1){
				dp[s|1<<i]+=dp[s];
			}
		}
	}cout<<dp.back()<<endl;
	return 0;
}


#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) for(auto x:obj)cout<<x<<' ';cout<<endl;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> lp;
typedef pair<double, double> FP;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

ll x, y;

map<ll, ll> costs;
ll A,D;

ll solve(ll N){
	if(N == 0)return abs(x);
        if(N == x)return 0;
	if(costs.count(N) != 0)return costs[N];
	ll res = INF;
	if(N < INF/D)res = abs(N-x)*D;

	//div2
	{
		ll to = N/2*2;
		ll tou = to + 2;
		res = min(res, solve(to/2)+ A + abs(N-to)*D);
		if(tou/2 < N)res = min(res, solve(tou/2) + A + abs(N-tou)*D);
	}

	return costs[N] = res;
}

int main(){
    cin >> x >> y;
    if(x >= y){
        cout << x-y << endl;
        return 0;
    }
    A = 1; D = 1;
    cout << solve(y) << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ff                first
#define brn                "\n"
#define ss                second
#define mk                make_pair
#define int               long long
#define pb                push_back
#define pf                push_front
#define ps(x,y)           fixed<<setprecision(y)<<x
#define w(x)              int x; cin>>x; while(x--)
#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 so(a,n)           sort(a,a+n)
#define rso(a,n)          sort(a,a+n),reverse(a,a+n)
#define all(v)            (v).begin(),(v).end()
#define ps(x,y)           fixed<<setprecision(y)<<x
#define sz                size();
#define p_sieve           10000007
const int                 maxn = 1e3 + 5;
const int                 modulo = 1000000007;
#define mod               1000000009;
const double              pi = 3.14159;
#define INF               1000001000
#define imx                9999999999999999
#define imi               -9999999999999999

//check n==1 and base cases//
//********************************---------always check array boundness-----------****************
// factorial ncr
// int printNcR(int n, int r)
// {
// 	if (n < r)return 0;
// 	long long p = 1, k = 1;
// 	if (n - r < r)
// 		r = n - r;
// 	if (r != 0) {
// 		while (r) {
// 			p *= n;
// 			k *= r;
// 			long long m = __gcd(p, k);
// 			p /= m;
// 			k /= m;

// 			n--;
// 			r--;
// 		}
// 	}
// 	else p = 1;
// 	return p;
// }

// int power(int x, unsigned int y)
// {
// 	int res = 1;
// 	//x = x % modulo;
// 	if (x == 0) return 0;
// 	while (y > 0)
// 	{
// 		if (y & 1) res = (res * x);
// 		y = y >> 1;
// 		x = (x * x);
// 	}

// 	return res;
// }
// const int N = 1e4 + 5;
// int dp[N];
// bool prime[N];
// std::vector<int> v;

// bool prime[N];
// void precompute()
// {
// 	memset(prime , 1, sizeof(prime));
// 	prime[0] = 0;
// 	prime[1] = 0;
// 	for (int i = 2; i * i <= N; i++)
// 	{
// 		if (prime[i] == 1)
// 			for (int j = i * i; j <= N; j += i )prime[j] = 0;
// 	}
// }

// generating subsets..
// for ( int i = 0 ; i < ( 1 << m ) ; ++ i )
// {
// 	for ( int j = 0; j < m ; ++ j )
// 	{
// 		if ( ( i & ( 1 << j ) ) != 0)
// 		{

// 		}
// 	}
// }
// int msb(unsigned a) {
// 	return __lg(a ^ (a & (a - 1)));
// }
// int mceil(int a, int b)
// {
// 	if (a % b == 0)return a / b;
// 	else return a / b + 1;
// }
const int N = 2e5 + 5;
std::vector<int> v[N];
void solve()
{
	int n; cin >> n;
	int mini = 1e18;
	int ok = -1;
	FOR(i, 0, n)
	{
		int x, y, z; cin >> x >> y >> z;
		z -= x;
		if (z > 0)mini = min(mini, y), ok = 1;
	}
	if (ok == 1)cout << mini;
	else cout << "-1";
}
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//precompute();
	//w(t)
	solve();
}


#include<cstdio>
using namespace std;
int n,a,b;
int main(){
    scanf("%d%d%d",&n,&a,&b);
    printf("%d\n",n-a+b);
	return 0;
}

// Created by ...
#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define repA(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)

using namespace std;
using ll = long long;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n, a, b;
    cin >> n >> a >> b;
    cout << n - a + b;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define DIV 1000000007 //10^9+7
#define INF 1000000007 //10^9+7

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

vector<pair<ll, ll> > to[1005];
ll memo[1005][1005];

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

	rep(i, M) {
		char ch;
		ll a, b, c;
		cin >> a >> b >> ch;
		c = ch-'a';
		a--;b--;
		to[a].push_back(make_pair(b, c));
		to[b].push_back(make_pair(a, c));
	}

	ll ret = INF;
	rep(i, N) rep(j, N) memo[i][j] = -1;

	//cost, s, e
	priority_queue<tuple<ll, ll, ll>, vector<tuple<ll, ll, ll> >, greater<tuple<ll,ll,ll>>>Q;

	Q.push({0, 0, N-1});

	while(!Q.empty()) {
		ll cost, s, e;
		tie(cost, s, e) = Q.top();
		Q.pop();
		if(memo[s][e] != -1) continue;
		memo[s][e] = cost;

		if(s == e) {
			chmin(ret, cost);
			continue;
		}

		for(auto item0: to[s]) if(item0.first == e) {
			chmin(ret, cost + 1);
			continue;
		}

		for(auto item0: to[s]) for(auto item1: to[e]) {
			if(item0.second == item1.second) {
				Q.push({cost + 2, item0.first, item1.first});
			}
		}
	}
	if(ret != INF) {
		cout << ret << endl;
		return 0;
	}

	cout << -1 << endl;
}

// atcoder/abc197/F/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

const int N = 1000 + 3;
vec<pair<int, char>> g[N];

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.setf(ios_base::fixed);
  cout.precision(15);

  int n, m;
  while (cin >> n >> m) {
    fill(g, g + N, vec<pair<int, char>>());
    for (int i = 0; i < m; ++i) {
      int a, b;
      char c;
      cin >> a >> b >> c;
      --a;
      --b;
      g[a].push_back(make_pair(b, c));
      g[b].push_back(make_pair(a, c));
    }

    const int inf = 1 << 29;
    static int cost[N][N];
    fill(&cost[0][0], &cost[N - 1][N - 1] + 1, inf);
    cost[0][n - 1] = 0;
    priority_queue<pair<int, pair<int, int>>> q;
    q.push(make_pair(0, make_pair(0, n - 1)));
    while (q.size()) {
      auto p = q.top();
      q.pop();
      int c = abs(p.first);
      int a = p.second.first;
      int b = p.second.second;
      map<char, vec<int>> x, y;
      each (i, g[a]) x[i.second].push_back(i.first);
      each (i, g[b]) y[i.second].push_back(i.first);
      for (char d = 'a'; d <= 'z'; ++d) {
        each (i, x[d]) {
          each (j, y[d]) {
            int nc = c + 2;
            if (cost[i][j] > nc) {
              cost[i][j] = nc;
              q.push(make_pair(-nc, make_pair(i, j)));
            }
          }
        }
      }
    }
    int mn = inf;
    for (int i = 0; i < N; ++i) {
      setmin(mn, cost[i][i]);
    }
    for (int i = 0; i < n; ++i) {
      each (e, g[i]) {
        int j = e.first;
        setmin(mn, cost[i][j] + 1);
      }
    }
    cout << (mn == inf ? -1 : mn) << endl;
  }

  return 0;
}


#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <type_traits>
#include <cmath>
#include <cassert>
#include <cstdio>

using namespace std;
using namespace placeholders;

using LL = long long;
using ULL = unsigned long long;
using VI = vector< int >;
using VVI = vector< vector< int > >;
using VS = vector< string >;
using ISS = istringstream;
using OSS = ostringstream;
using PII = pair< int, int >;
using VPII = vector< pair< int, int > >;
template < typename T = int > using VT = vector< T >;
template < typename T = int > using VVT = vector< vector< T > >;
template < typename T = int > using LIM = numeric_limits< T >;
template < typename T = int > using OSI = ostream_iterator< T >;

template < typename T > inline istream& operator>>( istream &s, vector< T > &v ){ for ( T &t : v ) { s >> t; } return s; }
template < typename T > inline ostream& operator<<( ostream &s, const vector< T > &v ){ for ( int i = 0; i < int( v.size() ); ++i ){ s << ( " " + !i ) << v[i]; } return s; }

void in_impl(){};
template < typename T, typename... TS > void in_impl( T &head, TS &... tail ){ cin >> head; in_impl( tail ... ); }
#define IN( T, ... ) T __VA_ARGS__; in_impl( __VA_ARGS__ );

template < typename T > inline T fromString( const string &s ) { T res; istringstream iss( s ); iss >> res; return res; }
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); }

#define NUMBERED( name, number ) NUMBERED2( name, number )
#define NUMBERED2( name, number ) name ## _ ## number
#define REP1( n ) REP2( NUMBERED( REP_COUNTER, __LINE__ ), n )
#define REP2( i, n ) REP3( i, 0, n )
#define REP3( i, m, n ) for ( int i = ( int )( m ); i < ( int )( n ); ++i )
#define GET_REP( a, b, c, F, ... ) F
#define REP( ... ) GET_REP( __VA_ARGS__, REP3, REP2, REP1 )( __VA_ARGS__ )
#define FOR( e, c ) for ( auto &&e : c )
#define ALL( c ) begin( c ), end( c )
#define AALL( a ) ( remove_all_extents< decltype( a ) >::type * )a, ( remove_all_extents< decltype( a ) >::type * )a + sizeof( a ) / sizeof( remove_all_extents< decltype( a ) >::type )

#define SZ( v ) ( (int)( v ).size() )
#define EXISTS( c, e ) ( ( c ).find( e ) != ( c ).end() )

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

#define PB push_back
#define EM emplace
#define EB emplace_back
#define BI back_inserter

#define MP make_pair
#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

//     Λ   Λ＿_
//  ／(*ﾟーﾟ)／＼
// ／| ￣U U￣|＼／
//   |      |／

constexpr auto INF = LIM< LL >::max() / 2;

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

	IN( int, N, T );
	VI A( N );
	cin >> A;

	const int n = N / 2;
	const int m = N - n;
	VT< LL > after_half( 1, -INF );
	REP( s, 1 << m )
	{
		LL r = 0;
		REP( i, m )
		{
			if ( s & 1 << i )
			{
				r += A[ n + i ];
			}
		}
		after_half.PB( r );
	}
	sort( ALL( after_half ) );

	VT< LL > befor_half;
	REP( s, 1 << n )
	{
		LL r = 0;
		REP( i, n )
		{
			if ( s & 1 << i )
			{
				r += A[i];
			}
		}
		befor_half.PB( r );
	}
	sort( ALL( befor_half ) );

	auto pos = end( after_half ) - 1;
	LL res = 0;
	FOR( r, befor_half )
	{
		for ( ; T - r < *pos; --pos );
		chmax( res, r + *pos );
	}
	cout << res << endl;

	return 0;
}

#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
const long long MOD = 1000000007;

ll N, T, A[100];

signed main(){
    cin >> N >> T;
    REP(i, N) cin >> A[i];
    vector<ll> v, w;
    REP(i, 1 << (N / 2)){
        ll t = 0;
        REP(j, N / 2){
            if(i & (1 << j)) t += A[j];
        }
        v.push_back(t);
    }
    REP(i, 1 << (N - (N / 2))){
        ll t = 0;
        REP(j, N - N / 2){
            if(i & (1 << j)) t += A[j + N / 2];
        }
        w.push_back(t);
    }
    sort(ALL(w));
    /*
    for(auto t : v) cerr << t << " ";
    cerr << endl;
    for(auto t : w) cerr << t << " ";
    cerr << endl;
    */
    ll ans = 0;
    for(auto t : v){
        if(t > T) continue;
        ll d = upper_bound(ALL(w), T - t) - w.begin();
        if(d == 0) ans = max(ans, t);
        else ans = max(ans, t + w[d - 1]);
    }
    PRINT(ans);
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
//#include <atcoder/all>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;

#define n50 250000

int f(int r,int c){
  return r*500+c;
}

int main(){
  int R,C; cin >> R >> C;
  vvi g(n50);
  vvi co(n50);
  rep(r,R) rep(c,C-1){
    int in; cin >> in;
    int ff=f(r,c);
    g[ff].pb(ff+1);
    g[ff+1].pb(ff);
    co[ff].pb(in);
    co[ff+1].pb(in);
  }
  rep(r,R-1) rep(c,C){
    int in; cin >> in;
    int ff=f(r,c);
    g[ff].pb(ff+500);
    co[ff].pb(in);
  }
  rep(c,C){
    rep(r,R){
      rep(s,r){
        int ff=f(r,c);
        g[ff].pb(f(s,c));
        co[ff].pb(r-s+1);
      }
    }
  }
  vector<int> D(n50, 1e9);
  vector<bool> used(n50, false);
  priority_queue<pair<int,int>,
                 vector<pair<int,int>>,
                 greater<pair<int,int>>> q;
  q.push({0,0});
  while(!q.empty()){
    int d = q.top().first; int to = q.top().second; q.pop();
    if(used[to]) continue;
    used[to] = true; D[to] = d;
    rep(i,sz(g[to])){
      int nxt=g[to][i];
      int nd = D[to] + co[to][i];
      if(D[nxt] <= nd) continue;
      D[nxt] = nd;
      q.push({nd, nxt});
    }
  }

  int ans = D[f(R-1,C-1)];
  cout << ans << endl;
  return 0;
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	int r, c;
	cin >> r >> c;

	vector <vector<int>> a(r + 1, vector <int> (c + 1, 0));
	for(int i = 1; i <= r; i++) {
		for(int j = 1; j < c; j++) {
			cin >> a[i][j];
		}
	}

	vector <vector<int>> b(r + 1, vector <int> (c + 1, 0));
	for(int i = 1; i < r; i++) {
		for(int j = 1; j <= c; j++) {
			cin >> b[i][j];
		}
	}

	auto Dijkstra = [&] (pair <int, int> src, pair<int, int> dst) -> int {
		vector <vector<int>> dist(r + 1, vector <int> (c + 1, 1e9));

		using tup = tuple <int, int, int>;
		priority_queue <tup, vector<tup>, greater<tup>> pq;

		dist[src.first][src.second] = 0;
		pq.emplace(0, src.first, src.second);

		while(!pq.empty()) {
			auto [cost, x, y] = pq.top();
			pq.pop();

			if(dist[x][y] < cost) continue;

			{
				int nx = x, ny = y + 1;
				if(nx >= 1 && nx <= r && ny >= 1 && ny <= c && dist[nx][ny] > dist[x][y] + a[x][y]) {
					dist[nx][ny] = dist[x][y] + a[x][y];
					pq.emplace(dist[nx][ny], nx, ny);
				}
			}

			{
				int nx = x, ny = y - 1;
				if(nx >= 1 && nx <= r && ny >= 1 && ny <= c && dist[nx][ny] > dist[x][y] + a[x][y - 1]) {
					dist[nx][ny] = dist[x][y] + a[x][y - 1];
					pq.emplace(dist[nx][ny], nx, ny);
				}
			}

			{
				int nx = x + 1, ny = y;
				if(nx >= 1 && nx <= r && ny >= 1 && ny <= c && dist[nx][ny] > dist[x][y] + b[x][y]) {
					dist[nx][ny] = dist[x][y] + b[x][y];
					pq.emplace(dist[nx][ny], nx, ny);
				}
			}

			{
				for(int i = 1; i < x; i++) {
					int nx = x - i, ny = y;
					if(nx >= 1 && nx <= r && ny >= 1 && ny <= c && dist[nx][ny] > dist[x][y] + 1 + i) {
						dist[nx][ny] = dist[x][y] + 1 + i;
						pq.emplace(dist[nx][ny], nx, ny);
					}
				}
			}
		}
		return dist[dst.first][dst.second];
	};

	pair <int, int> src = make_pair(1, 1);
	pair <int, int> dst = make_pair(r, c);
	cout << Dijkstra(src, dst);
}


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

using namespace std;
using ll = long long;

int main(){
    ll n, q;
    cin >> n >> q;
    vector<ll> a(n);
    for(ll&v:a) cin >> v;
    while(q--) {
        ll k;
        cin >> k;
        ll ok = 2e18;
        ll ng = 0;
        while(ok-ng > 1) {
            ll m = (ok+ng)/2;
            ll d = upper_bound(a.begin(), a.end(), m) - a.begin();
            ll nth = m - d;
            if(nth >= k) {
                ok = m;
            } else {
                ng = m;
            }
        }
        cout << ok << endl;
    }
}

#include<iostream>
#include<bits/stdc++.h>
#define m_p make_pair
#define fi first
#define se second
#define pb push_back
typedef long long ll;
#define f(i,n) for(ll i=0;i<n;i++)
#define f1(i,n) for(ll i=1;i<=n;i++)
#define   crap ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0)
using namespace std;
#define INF 1000000
#define vll vector<ll>
const int M = 1e9+7;
ll fastpower(ll x,ll n,ll M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return fastpower((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*fastpower((x*x)%M,(n-1)/2,M))%M;
}
ll GCD(ll A, ll B) {
    if(B==0)
        return A;
    else
        return GCD(B, A % B);
}
bool vowl(char c)
{
  return c=='a'||c=='e'||c=='i'||c=='o'||c=='u';
}
ll modInverse(ll A,ll M)// when M is prime
{
    return fastpower(A,M-2,M);
}
void sieve(ll N) {
        bool isPrime[N+1];
        for(ll i = 0; i <= N;++i) {
            isPrime[i] = true;
        }
        isPrime[0] = false;
        isPrime[1] = false;
        for(ll i = 2; i * i <= N; ++i) {
             if(isPrime[i] == true) {                    //Mark all the multiples of i as composite numbers
                 for(ll j = i * i; j <= N ;j += i)
                     isPrime[j] = false;
            }
        }
    }
vector<ll> factorize(ll n) {
    vector<ll> res;
    for (ll i = 2; i * i <= n; ++i) {
        while (n % i == 0) {
            res.push_back(i);
            n /= i;
        }
    }
    if (n != 1) {
        res.push_back(n);
    }
    return res;
}

int main()
{
    crap;
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
        #endif
        ll n,q;
        cin>>n>>q;
        ll arr[n];
        f(i,n)cin>>arr[i];
        map<ll,ll> mp;
        ll p=1;
        for(int i=0;i<n;i++)
        {
            mp[arr[i]]=p++;
        }
        while(q--)
        {
            ll x;
            cin>>x;
            ll a=1,b=1e18+1e6;
            ll ans;
            while(a<=b)
            {
                unsigned long long int  mid=(b+a)/(ll)2;
                auto it=mp.upper_bound(mid);
                ll l;
                if(it==mp.end())l=n;
                else
                    l=it->second-1;
                ll y=x+l;
                if(y>mid)
                {

                    a=mid+1;
                }
                else
                {
                    if(mp.find(mid)==mp.end()&&(x+l)==mid)ans=mid;
                    b=mid-1;
                }
            }
            cout<<ans<<"\n";
        }
    return 0;
}


#include<iostream>

int main(){
	int i,j,bit;
	int n,a,b;
	int num[8]={};
	int can[200]={};
	int count=0;
	std::cin>>n;
	if(n>8)n=8;
	for(i=0;i<n;i++){
		std::cin>>a;
		num[i]=a%200;
	}
	for(bit=1;bit<(1<<n);++bit){
		b=0;
		for(i=0;i<n;i++){
			if(bit&(1<<i)){
				b+=num[i];
			}
		}
		b=b%200;
		if(can[b])break;
		else can[b]=bit;
	}
	if(bit==(1<<n))std::cout<<"No"<<std::endl;
	else{
	std::cout<<"Yes"<<std::endl;
	count=0;
	for(i=0;i<n;i++){
		if(bit&(1<<i))count++;
	}
	std::cout<<count<<" ";
	for(i=0;i<n;i++){
		if(bit&(1<<i))std::cout<<i+1<<" ";
	}
	std::cout<<std::endl;
	count=0;
	for(i=0;i<n;i++){
		if(can[b]&(1<<i))count++;
	}
	std::cout<<count<<" ";
	for(i=0;i<n;i++){
		if(can[b]&(1<<i))std::cout<<i+1<<" ";
	}
	std::cout<<std::endl;
	}
}

//雪花飄飄北風嘯嘯
//天地一片蒼茫

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl

#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define lb lower_bound
#define ub upper_bound

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
//change less to less_equal for non distinct pbds, but erase will bug

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

int n;
int arr[205];

bool memo[205][205];

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin.exceptions(ios::badbit | ios::failbit);

	cin>>n;
	rep(x,0,n){
		cin>>arr[x];
		arr[x]%=200;
	}

	memo[0][0]=true;

	rep(x,0,n){
		rep(y,0,200) if (memo[x][y]){
			memo[x+1][(y+arr[x])%200]=true;
			memo[x+1][y]=true;
			memo[x+1][(y-arr[x]+200)%200]=true;
		}
	}

	vector<int> add;
	vector<int> minus;

	int py=0;
	rep(x,n,0){
		if (sz(add) && memo[x][(py+arr[x])%200]){
			minus.pub(x);
			py=(py+arr[x])%200;
		}
		else if (sz(minus) && memo[x][(py-arr[x]+200)%200]){
			add.pub(x);
			py=(py-arr[x]+200)%200;
		}
		else if (memo[x][(py+arr[x])%200]){
			minus.pub(x);
			py=(py+arr[x])%200;
		}
		else if (memo[x][(py-arr[x]+200)%200]){
			add.pub(x);
			py=(py-arr[x]+200)%200;
		}
	}

	if (sz(add)==0 && sz(minus)==0){
		cout<<"No"<<endl;
		return 0;
	}
	if (sz(add)==n && sz(minus)==0){
		cout<<"No"<<endl;
		return 0;
	}
	if (sz(add)==0 && sz(minus)==n){
		cout<<"No"<<endl;
		return 0;
	}

	set<int> s;
	rep(x,0,n) s.insert(x);
	for (auto &it:add) s.erase(it);
	for (auto &it:minus) s.erase(it);

	if (!s.empty()) add.pub(*s.begin()),minus.pub(*s.begin());

	cout<<"Yes"<<endl;

	sort(all(add));
	sort(all(minus));

	cout<<sz(add)<<" "; for (auto &it:add) cout<<it+1<<" "; cout<<endl;
	cout<<sz(minus)<<" "; for (auto &it:minus) cout<<it+1<<" "; cout<<endl;
}


#include <bits/stdc++.h>
using namespace std;
int main () {
  int n;
  cin >> n;
  vector<int> x(n),y(n);
  for(int i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
  }
  int ans = 0;
  for(int i = 0; i < n; i++) {
    for(int j = i+1; j < n; j++) {
    double k = (double)(y[j]-y[i])/(x[j]-x[i]);
    if(k>=-1&&k<=1) ans++;
    }
  }
  cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
#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 FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()

using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const ll MOD = 1e9 + 7;
const ll INF = 1e18;

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

    ll n;
    cin >> n;

    vll x(n), y(n);
    REP(i, n) cin >> x[i] >> y[i];

    ll res = 0;
    REP(i, n) {
        REP(j, n) {
            if (j <= i) continue;
            if (abs(x[j] - x[i]) >= abs(y[j] - y[i])) res++;
        }
    }
    cout << res << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int x;
	scanf("%d",&x);
	int now=x;
	while(1){
	now++;
		if(now%100==0){
			cout<<now-x;
			return 0;
		}

	}
}

#include<bits/stdc++.h>
using namespace std;
int main(){
	int x;
	cin>>x;
	x%100==0 ? cout<<(100) : cout<<(100 - x%100);
}


#include<bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#define endl "\n"
#define pb push_back
#define ll long long
#define d1(x)  cerr << #x << "--> " << x << endl
#define d2(x,y)  cerr << #x << "--> " << x << " | " << #y << "--> " << y <<endl
#define d3(x,y,z)  cerr << #x << "--> " << x << " | " << #y << "--> " << y <<" | " << #z << "--> "<< z<< endl
#define d4(x,y,z,w)  cerr << #x << "--> " << x << " | " << #y << "--> " << y <<" | " << #z << "--> "<< z << " | "<< #w << "--> " << w <<endl
#define vpll vector<pair<ll,ll>>
#define F first
#define S second
using namespace std;
ll mode = 1e9 + 7;
const ll maxn = 2*1e5 + 5;
const ll inf = 1e18;
ll __lcm(ll a, ll b){ return (a*b)/__gcd(a,b); }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll getRand(ll l, ll r){ uniform_int_distribution<int> uid(l, r); return uid(rng); }
template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) { return out << "(" << a.F << ", " << a.S << ")"; }
template <class A> ostream& operator << (ostream& out, const vector<A> &v) {
out << "["; for (int i=0;i<v.size();i++) { if(i) out << ", "; out << v[i]; } return out << "]"; }

void solve(){

	ll n;
	cin>>n;
	map<int,vector<int>> b;
	map<int,int> ma, mb, mc;
	for (int i=1;i<=n;i++){
		int x;
		cin>>x;
		ma[x]++;
	}
	for (int i=1;i<=n;i++){
		ll x;
		cin>>x;
		b[x].pb(i);
		mb[x]++;
	}
	for (int i=1;i<=n;i++){
		ll x;
		cin>>x;
		mc[x]++;
	}

	ll ans = 0;
	for (int i=1;i<=n;i++){
		if (mb.count(i)==0) continue;
		vector<int> bb = b[i];
		for (auto j:bb){
			ans = ans + ma[i]*mc[j];
		}
	}
	cout<<ans<<endl;

}

int main(){

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

    ios::sync_with_stdio(0);
    cin.tie(0);

	ll test_case = 1;
	//cin>>test_case;
	for (int i=1;i<=test_case;i++){
		solve();
	}

	return 0;
}

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

int main()
{
 int n,x;
 cin >> n;
 int arr1[n+2]= {0};
 memset(arr1,0,sizeof(arr1));

 for(int i=1; i<=n; i++)
 {
   cin>>x;
   arr1[x]++;
 }

 int arr2[n+1];
 for(int j=1;j<=n; j++)
 {
   cin >> arr2[j];
 }

 unsigned long long int cnt=0;
 while(n--)
 {
   cin >> x;
   int k=arr2[x];
   cnt=cnt+arr1[k];
 }
 cout<<cnt<<endl;

}


// clang-format off
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <cctype>
using namespace std;
#define PI 3.14159265358979323846264338327950L
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define rep2(i,s,n) for (int i=(s); i<(int)(n); ++i)
#define noflush ios::sync_with_stdio(false);cin.tie(nullptr);constexpr char endl='\n'
#define prec(i) fixed << setprecision(i)
#define put(expr) cout<<expr<<'\n'
#define putV(A) cout << '['; rep(i, A.size()) { cout << A[i]; if (i != A.size() - 1) cout << ' '; else cout << "]\n"; }
typedef int8_t i8; typedef int16_t i16; typedef int32_t i32; typedef int64_t i64; typedef uint8_t u8; typedef uint16_t u16; typedef uint32_t u32; typedef uint64_t u64; typedef float f32; typedef double f64; typedef long double f80;
typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef map<int, int> mii;
typedef __int128_t i128; i128 parse(string &s) { i128 ret = 0; for (int i = 0; i < s.length(); i++) if ('0' <= s[i] && s[i] <= '9') ret = 10 * ret + s[i] - '0'; return ret; } istream &operator>>(istream &is, i128 &v) { string s; is >> s; v = parse(s); return is; } ostream &operator<<(ostream &os, const i128 &v) { if (v == 0) return (os << "0"); i128 num = v; if (v < 0) { os << '-'; num = -num; } string s; for (; num > 0; num /= 10) s.push_back('0' + (char)(num % 10)); reverse(s.begin(), s.end()); return (os << s); }
template <typename T> bool chmax(T &now, const T &cand) { if (now < cand) { now = cand; return true; } return false; } template <typename T> bool chmin(T &now, const T &cand) { if (now > cand) { now = cand; return true; } return false; }
template <typename T> T gcd(const T &a, const T &b) { if (a % b == 0) return b; return gcd(b, a % b); } template <typename T> T lcm(const T &a, const T &b) { return a * b / gcd(a, b); }
template <typename T> T nCr(const T &n, T k) { if (k > n) return 0; if (k * 2 > n) k = n - k; if (k == 0) return 1; int result = n; for (int i = 2; i <= k; ++i) { result *= (n - i + 1); result /= i; } return result; }
const int INF = 1<<30; /* INF > 10^9 */ const i64 INFLL = 1LL<<60; /* INFLL > 10^18 */ const string YES = "Yes", NO = "No";
// clang-format on

int main() {
  noflush;

  int N;
  cin >> N;

  vector<bool> B(N);
  rep(i, N) {
    string s;
    cin >> s;
    if (s == "AND")
      B[i] = true;
    else
      B[i] = false;
  }

  i128 ans = 1;
  for (int i = B.size() - 1; i >= 0; i--) {
    if (B[i]) {
      // AND
      ans *= 2;
      --ans;
    } else {
      // OR
      ans *= 2;
    }
  }
  ans *= 2;
  --ans;

  put(ans);
}


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

int main()
{
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i, 0, n) cin >> s[i];
    set<string> st;
    rep(i, 0, n) st.insert(s[i]);
    for(string s : st){
        if(s[0] != '!'){
            string t = "!" + s;
            decltype(st)::iterator it = st.find(t);
            if(it != st.end()){
                cout << s << endl;
                return 0;
            }
        }
    }
    cout << "satisfiable" << endl;
    return 0;
}

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e6+10;
int p[N];
int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	int x,y;
	cin >> x >> y;
	int c = min(x,y);
	int d = max(x,y);
	if((d-c)<3)cout << "Yes";
	else cout << "No";
}


#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
//    ifstream cin("input.txt");
//    ofstream cout("output.txt");
    ll tst = 1;
    while(tst--){
        ull res,n,i,j,k,lim;
        cin>>n;
        set<ull> st;
        res = n;
        lim = pow(n , 0.5);
        for(i =2;i<=lim;i++){
            k = 2;
            j= pow(i,k);
            for(;j<=n;){
                if(st.find(j)==st.end()){
                    //cout<<j<<endl;
                    res--;
                }
                st.insert(j);

                k++;
                j = pow(i,k);
            }
        }
        cout<<res<<endl;
    }
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main() {
	long long n;
	cin >> n;
	unordered_set<long long> us;
	long long counter = 0;
	for (long long i = 2; i <= sqrt(n); i++) {
		long long tmp = i * i;
		while (tmp <= n) {
			us.insert(tmp);
			tmp *= i;
		}
	}
	cout << n - us.size() << endl;
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:256000000")
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<algorithm>
#include<cmath>
#include<set>
#include<queue>
#include<sstream>
#include<utility>
#include<map>
#include<ctime>
#include<cstdio>
#include<cassert>
#include<functional>
#include<unordered_map>
#include<deque>
#include<cmath>
//#include<atcoder/dsu>

//using namespace atcoder;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;
typedef pair<double, double> pdd;

#define show(x) cerr << x
#define debug(x) show(#x << ": " << (x) << endl)

const long double PI = 3.14159265358979323846;
const long double eps = 1e-5;
const ll INF = numeric_limits<int>::max();
const ll LINF = numeric_limits<ll>::max();
const ll mod = 998244353;

void solve() {
    int n, m;
    cin >> n >> m;
    if (m == 0) {
        for (int i = 0; i < n; ++i) {
            cout << 2 * i + 1 << " " << 2 * i + 2 << "\n";
        }
        return;
    }
    if ((m < 0) || (m >= n - 1)) {
        cout << -1 << endl;
        return;
    }
    for (int i = 0; i < m + 1; ++i) {
        cout << 2 * i + 2 << " " << 2 * i + 3 << "\n";
    }
    cout << 1 << " " << 2 * m + 4 << "\n";
    int x = 2 * m + 4;
    for (int i = m + 2; i < n; ++i) {
        int j = i - m - 2;
        cout << x + 2 * j + 1 << " " << x + 2 * j + 2 << "\n";
    }

}

//#define LOCAL

int main() {
    ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    solve();

#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}

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

typedef long long int ll;
using ii= pair<ll,ll>;
#define fr(i,a,b) for(ll i=a;i<b;i++)
#define all(o) (o).begin(),(o).end()
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ld long double
#define eps 0.00000000001
#define mod 1000000007

class prioritize{
    public: bool operator() (ii &p1,ii &p2){
        return p1.F<p2.F;
    }
};

auto start_time= high_resolution_clock::now();
void time()
{
    #ifndef ONLINE_JUDGE
        auto stop_time= high_resolution_clock::now();
        auto duration= duration_cast<milliseconds>(stop_time-start_time);
        cout<<"run time: "<<duration.count()<<" ms"<<"\n";
    #endif
    return;
}

void ojudge()
{
	#ifndef ONLINE_JUDGE
        freopen("input1.txt","r", stdin);
        freopen("output1.txt","w",stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    return;
}

vector<ll> le,ri;
ll t=0;

void all_poss_subset_sum(vector<ll> & brr,vector<ll> &sum_vec)
{
	ll n = brr.size();
	ll no_of_subsets = (1<<n);

	fr(i,0,no_of_subsets){
		ll ans=0;
		fr(j,0,n){
			if(i & (1<<j)) ans += brr[j];
		}
		sum_vec.PB(ans);
	}
}

void meet_in_the_middle(ll arr[],ll n)
{

    vector<ll> left,right;

    fr(i,0,n/2) left.PB(arr[i]);
    fr(i,n/2,n) right.PB(arr[i]);

	all_poss_subset_sum(left,le);
	all_poss_subset_sum(right,ri);

	//return ans;
}

int main()
{
    ojudge();

    ll n;
    cin>>n>>t;

    ll arr[n];
    fr(i,0,n) cin>>arr[i];

    meet_in_the_middle(arr,n);

    sort(all(ri));
	ll ans=0;

	for(auto it:le)
	{
		if(it>t) continue;
        ll tgt = t-it;
		ll ind =   upper_bound( ri.begin(),ri.end(),tgt)-ri.begin()-1;

		ans = max(ans,it + ri[ind]);
	}

	cout<<ans<<"\n";

    time();
    return 0;
}


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

using i64 = long long;
using P   = pair<i64, i64>;

#define overload3(_1, _2, _3, name, ...) name
#define rep1(i, n) for(i64 i = 0LL; i < (n); ++i)
#define rep2(i, a, b) for(i64 i = (a); i < (b); ++i)
#define rep(...) overload3(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define all(v) v.begin(), v.end()

void solve(long long L) {
    vector<vector<i64>> dp(L, vector<i64>(12));
    dp[0][0] = 1;
    for(int i = 0; i < L; ++i) {
        dp[i][0] = 1;
        for(int j = 1; j < 12; ++j) {
            for(int k = 0; k < i; ++k) {
                dp[i][j] += dp[k][j - 1];
            }
        }
    }
    cout << dp[L - 1][11] << endl;
}

struct IoSetup {
    IoSetup() {
        // cin.tie(nullptr);
        // ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

int main() {
    long long L;
    scanf("%lld", &L);
    solve(L);
    return 0;
}

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

// clang-format off
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
#define Endl endl
#define itn int
#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)
#define LOWER_BOUND(A, key) distance(begin(A), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(begin(A), upper_bound(ALL(A), key))

const int MOD   = 1000000007;
// const int MOD    = 998244353;
const int INF    = (int)(1e13 + 7);
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); }
int _mod(int &a) {a = a >= 0 ? a % MOD : a - (MOD * _ceil(a, MOD));return a;}
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 CDuodecimFerra {
public:
  static void solve(istream &cin, ostream &cout) {
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    int L;
    cin >> L;
    int ans = 1;
    V<int> temp(10);
    rep(i, 10) temp[i] = i + 2;
    rep2(i, L - 11, L) {
      ans *= i;
      FOR(j, temp) {
        if (j != 1 and ans % j == 0) {
          ans /= j;
          j = 1;
        }
      }
    }
    cout << ans << endl;
  }
};

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


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

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

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

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

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

struct doublepair{
  int a, b;
};

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

  ull n;
  cin >> n;
  std::vector<ull> three;
  std::vector<ull> five;
  for (ull i=3;i < n;i *=3) {
    three.push_back(i);
  }
  for (ull i=5;i < n;i *=5) {
    five.push_back(i);
  }

  bool is_find {false};
  doublepair ans;
  for (int i = 0;i < three.size();++i) {
    for (int j = 0;j < five.size();++j) {
      if (three[i] + five[j] > n) {
        break;
      } else if (three[i] + five[j] == n) {
        ans.a = i+1;
        ans.b = j+1;
        is_find = true;
        break;
      }
    }
    if (is_find == true) break;
  }
  if (is_find) cout << ans.a << ' ' << ans.b << '\n';
  else cout << -1 << '\n';
}

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

#define Swap(a, b) do { typeof(a) T = (a); a = b; b = T; } while(0)

static inline int
input() {
    int x = 0, f = 0, c = getchar();
    while(c < '0' || c > '9') { f ^= (c == '-'), c = getchar(); }
    while(c > 47 && c < 58) { x = x * 10 + c - '0', c = getchar(); }
    return f ? -x : x;
}

static inline void
Asc64(long long *a, const int sz) {
    int shift = 0, elem[256];
    long long x = 0, *aux = (long long*)malloc(sizeof(long long)*sz);

    if(aux == nullptr) { exit(EXIT_FAILURE); }

    while(shift < 64) {
        int bucket[256] = {0};
        for(int i = 0; i < sz; ++i) {
            x = (a[i] >> shift) & 255;
            ++bucket[x];
            aux[i] = a[i];
        }

        elem[0] = 0;

        for(int i = 0; i < 255; ++i) {
            elem[i + 1] = elem[i] + bucket[i];
        }

        for(int i = 0; i < sz; ++i) {
            x = (aux[i] >> shift) & 255; a[elem[x]] = aux[i];
            ++elem[x];
        }

        shift += 8;
    }

    free(aux);
}

int main() {
    int n = input();
    int len = 0, sizeS = 0, sizeT = 0;
    long long S[n], T[n];
    char temp[11];

    for(int i = 0; i < n; ++i) {
        if(!scanf("%s", temp)) {
            exit(EXIT_FAILURE);
        }

        len = (int)strlen(temp);
        S[i] = T[i] = 0;

        if(temp[0] == '!') {
            --len;
            for(int j = 0; j < len; ++j) {
                T[sizeT] = T[sizeT] * 27 + (temp[j + 1] - 'a' + 1);
            }
            ++sizeT;
        }
        else {
            for(int j = 0; j < len; ++j) {
                S[sizeS] = S[sizeS] * 27 + (temp[j] - 'a' + 1);
            }
            ++sizeS;
        }
    }

    Asc64(S, sizeS);
    Asc64(T, sizeT);

    int idxS = 0, idxT = 0;
    long long check = 0;
    while(idxS < sizeS && idxT < sizeT) {
        check = S[idxS] - T[idxT];
        if(!check) {
        memset(temp, '\n', 11);
            len = 0;
            while(S[idxS]) {
                temp[len++] = 'a' + S[idxS] % 27 - 1;
                S[idxS] /= 27;
            }
            for(int i = 0; i < len/2; ++i) {
                Swap(temp[i], temp[len - 1 - i]);
            }
            return !puts(temp);
        }
        else if(check < 0) {
            ++idxS;
        }
        else {
            ++idxT;
        }
    }

    return !puts("satisfiable");
}


#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops")
using namespace std;
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define flc(x) __builtin_popcountll(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define vec vector<lint>
#define nep(x) next_permutation(all(x))
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=3e5+5;
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
//vector<int> bucket[MAX_N/1000];
constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
/*#include<atcoder/all>
using namespace atcoder;
typedef __int128_t llint;*/

int main(void){
    int N;
    cin >> N;
    lint A[N];
    rep(i,N) cin >> A[i];
    lint sum[N+1]={};
    rep(i,N) sum[i+1]=sum[i]+A[i];
    int modsum[N+1][N+1]={};
    rep(i,N+1) rep(j,N+1) if(j!=0) modsum[i][j]=sum[i]%j;
    lint dp[N+1][N+1]={};
    dp[0][0]=1;
    int x[N+1][N+1]={};
    for(int j=1;j<=N;j++){
        int last[N+1]={};
        rep(i,N+1) last[i]=-1;
        for(int i=1;i<=N;i++){
            x[i][j]=last[modsum[i][j]];
            last[modsum[i][j]]=i-1;
        }
    }
    for(int i=1;i<=N;i++) for(int j=1;j<=i;j++){
        dp[i][j]=((dp[x[i][j]+1][j])+dp[x[i][j]+1][j-1])%MOD;
    }
    lint ans=0;
    for(int i=1;i<=N;i++) ans=(ans+dp[N][i])%MOD;
    cout << ans << endl;
}

#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#define rep(i,n) for(ll i=0;i<(n);++i)
#define rep2(i,n) for(ll i=1;i<=(n);++i)
#define rep3(i,i0,n) for(ll i=i0;i<(n);++i)
#define rrep(i,n) for(ll i=((n)-1); i>=0; --i)
#define rrep2(i,n) for(ll i=(n); i>0; --i)
#define pb push_back
#define mod 1000000007
#define fi first
#define se second
#define len(x) ((ll)(x).size())
using namespace std;
using ll = long long;
using ld = long double;
using Pi = pair< ll, ll >;
using vl = vector<ll>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vp = vector<Pi>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

const ll INF = 1LL << 60;
const ld PI = 3.1415926535897932385;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define mp make_pair
void printb(ll N,ll d=16){
    rep(i,d){
        cout<<(N/(1<<(d-i-1)))%2;
    }
    cout<<endl;

}
void printv(vector<ll>a){
    rep(i,a.size()){
        if(i==a.size()-1){
            cout<<a[i]<<endl;
        }else{
            cout<<a[i]<<" ";
        }
    }
}
bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;

    }else{
        return a.second < b.second;
    }
}

//const vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1};
//const vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1};
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};

int main() {
    ll N,K;
    cin>>N>>K;
    vl a(N);
    rep(i,N){
        cin>>a[i];
    }

    sort(all(a));
    ll ans=0;
    map<ll,ll>m;
    m[0]=K;

    rep(i,N){
        if(m[a[i]]>0){
            ans++;
            m[a[i]]--;
            m[a[i]+1]++;
        }
    }

    cout<<ans<<endl;
    return 0;

}


#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0, length = n; i < length; i++)
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define ep emplace
#define epb emplace_back
#define scll static_cast<long long>
#define sz(x) static_cast<int>((x).size())
#define pfll(x) printf("%lld\n", x)
#define ci(x) cin >> x
#define ci2(x, y) cin >> x >> y
#define ci3(x, y, z) cin >> x >> y >> z
#define ci4(w, x, y, z) cin >> w >> x >> y >> z
#define co(x) cout << x << endl
#define co2(x, y) cout << x << " " << y << endl
#define co3(x, y, z) cout << x << " " << y << " " << z << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> PQ;
typedef priority_queue<int, vector<int>, greater<int>> PQG;
typedef priority_queue<P> PQP;
typedef priority_queue<P, vector<P>, greater<P>> PQPG;

const int MAX_N = 2e5, MOD = 1e9 + 7, INF = 1e9;
int n, v[2 * MAX_N];

int main() {
    ci(n);
    ll sum = 0, aoki = 0;
    rep(i, 2 * n) {
        ci(v[i]);
        sum += v[i];
    }
    PQG q;
    rep(i, n) {
        q.ep(v[n - i - 1]);
        q.ep(v[n + i]);
        aoki += q.top(); q.pop();
    }
    co(sum - aoki);
    return 0;
}

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

int main(){
    ll N; cin >> N;
    ll v[2*N]; ll sum = 0,loss = 0;
    rep(i,2*N){
        cin >> v[i]; sum += v[i];
    }
    ll k1 = N-1; ll k2 = N;
    multiset<ll> mean;
    rep(i,N){
        mean.insert(v[k1]); mean.insert(v[k2]);
        auto itr = mean.begin();
        loss += *itr; mean.erase(itr);
        k1--; k2++;
    }
    cout << sum-loss << endl;
}


// < Rahil Malhotra / ViciousCoder >
#include "bits/stdc++.h"
using namespace std;

template <typename T> void print(T t) { cout<<t<<endl; }
template<typename T, typename... Args> void print(T t, Args... args) { cout<<t<<" "; print(args...); }

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define int long long
#define double long double

int n,k;
int tree[2000005];
int lazy[2000005];
void propogate(int i,int l,int r)
{
    tree[i]+=(r-l+1)*lazy[i];
    if(l!=r)
        lazy[i*2]+=lazy[i],lazy[i*2+1]+=lazy[i];
    lazy[i]=0;
}
void update(int i,int l,int r,int l1,int r1,int val)
{
    if(lazy[i])
        propogate(i,l,r);
    if(l1>r1 || l>r1 || l1>r)
        return;
    if(l1<=l && r<=r1)
    {
        tree[i]+=(r-l+1)*val;
        if(l!=r)
            lazy[i*2]+=val,lazy[i*2+1]+=val;
        return;
    }
    int mid=(l+r)/2;
    update(i*2,l,mid,l1,r1,val);
    update(i*2+1,mid+1,r,l1,r1,val);
    tree[i]=tree[i*2]+tree[i*2+1];
}
int query(int i,int l,int r,int l1,int r1)
{
    if(l1>r1 || l>r1 || l1>r)
        return 0;
    if(lazy[i])
        propogate(i,l,r);
    if(l1<=l && r<=r1)
        return tree[i];
    int mid=(l+r)/2;
    return query(i*2,l,mid,l1,r1)+query(i*2+1,mid+1,r,l1,r1);
}
int32_t main()
{
    IOS;
    cin>>n>>k;
    int ans=0;
    for(int i=1;i<=n;i++)
        update(1,1,2*n+2,i+1,i+n,1);
    for(int i=2;i<=2*n;i++)
    {
        int left=i-k;
        if(left<2 || left>2*n)
            continue;
        // int ways=abs(left)-1;
        // int ways2=abs(i)-1;
        // ans+=ways*ways2;
        // print(i,ways,ways2,left,ways*ways2);
        ans+=query(1,1,2*n+2,i,i)*query(1,1,2*n+2,left,left);
    }
    cout<<ans;
}

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,n,a) for (int i=n;i>=a;i--)
#define mst(a,i) memset(a,i,sizeof a)
#define ll long long
#define pb push_back
#define eps 1e-10
#define fi first
#define se second
#define pii pair<int,int>
#define inf 0x3f3f3f3f
const int mod = 1000000007;
const int N = 2e5+6;
	ll n,k,tot;

ll g(ll e)
{
	if(e>=2&&e<=n+1)return e-1;
	return 2*n-e+1;
}

int main()
{
	std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin>>n>>k;
	ll x,y;
	if(k>=0)
	{
		x=k+2;y=2*n;
	}
	else
	{
		x=2;
		y=2*n+k;
	}
	rep(i,x,y)
	{
		ll e1=i;
		ll e2=i-k;
		tot+=g(e1)*g(e2);
	}
	cout<<tot;
}


#include<bits/stdc++.h>
using namespace std;
#define lll __int128_t
#define ll long long
#define int long long
#define FOR(i,a,b) for(ll i=a;i<(ll)b;i++)
#define FORr(i,a,b) for(ll i =a;i>=(ll)b;i--)
#define rep(i,n) FOR(i,0,n)
#define rep1(i,n) FOR(i,1,n)
#define print(arr)  for(auto a: arr) cout << a<< " "; cout << endl;
#define case(i) cout << "Case " << i << ": ";
#define in(a) ll a; cin >> a;
#define inp(arr,n) vector<ll>arr(n); for(auto &a: arr) cin >> a;
#define pb emplace_back
#define all(a) a.begin(), a.end()
#define mp make_pair
#define f first
#define vll vector<ll>
#define s second
ll mod = 1e9 + 7;
#define pll pair<ll, ll>
#define set_bit(x, idx) x = x|(1LL<<idx)
ll dx[8] = {0,1,0,-1,1,-1,1,-1};
ll dy[8] = {-1,0,1,0,1,1,-1,-1};
#define toggle_bit(x, idx) x = x^(1LL<<idx)
#define check_bit(x, idx) min(x&(1LL<<idx),1LL)
#define endl "\n"
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rng(x,y) uniform_int_distribution<int>(x,y)(rng)
template<typename T> ostream& operator<<(ostream &os, const multiset<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T> ostream& operator<<(ostream &os, const set<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define db long double
ll hash58 = 288230376151711717;
ll hash32 = 1610612741;
#ifdef DEBUG
#define ios
#define dbg(...) cerr << __LINE__ << " : " ;cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__);
#define ok cerr << __LINE__ << " is done " << endl;
#else
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define dbg(...)
#define ok
#endif

string one;
ll fact[5];
ll dp[12][6][30];

ll solve(ll idx, ll cnt, ll div){
    if(dp[idx][cnt][div] != -1) return dp[idx][cnt][div];
    if(idx == 10 ) {
        if(cnt) return 0;
        ll now = fact[4]/div;
        return dp[idx][cnt][div] = now;
    }
    ll ans = 0;
    if(one[idx] == 'o'){
        for(int i = 1; i <= cnt; i++){
            ans += solve(idx+1, cnt-i, div*fact[i]);
        }
    }
    else if(one[idx] == '?'){
        for(int i = 0; i <= cnt; i++){
            ans += solve(idx+1, cnt-i, div*fact[i]);
        }
    }
    else{
        ans = solve(idx+1, cnt, div);
    }
    return dp[idx][cnt][div] = ans;
}

void solvetc(ll tt){
    memset(dp, -1LL, sizeof dp);
    cin >> one;
    fact[0] = 1;
    rep1(i, 5) fact[i] = i*fact[i-1];
    cout << solve(0, 4, 1) << endl;
}

int32_t main()
{
    ios ;
    //freopen("in", "r", stdin);
    ll nn = 1;
    //cin >> nn;
    rep(i, nn) solvetc(i+1);
}

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

int main(){
  int N;
  cin >> N;
  long long s = 0;
  vector<long long> A(N), B(N);
  for(int i = 0; i < N; ++i){
    cin >> A[i];
    s += A[i];
  }
  for(int i = 0; i < N; ++i){
    cin >> B[i];
  }
  vector<long long> O, E;
  for(int i = 0; i < N; ++i){
    long long d = B[i]-A[i];
    if(i%2) O.emplace_back(d);
    else E.emplace_back(d);
  }
  sort(O.rbegin(), O.rend());
  sort(E.rbegin(), E.rend());
  long long ans = s;
  for(int i = 0; i < N/2; ++i){
    s += O[i]+E[i];
    ans = max(ans,s);
  }
  cout << ans << endl;
}


#include<bits/stdc++.h>

int main() {
	using namespace std;
	ios_base::sync_with_stdio(false), cin.tie(nullptr);
	int N; cin >> N;
	// you can attain 0..L-N
	int L; cin >> L; L -= N;

	vector<int> A; A.reserve(N+2);
	A.push_back(0);
	for (int i = 0; i < N; i++) {
		int a; cin >> a; a--;
		A.push_back(a-i);
	}
	A.push_back(L);

	vector<int> B; B.reserve(N+2);
	B.push_back(0);
	for (int i = 0; i < N; i++) {
		int a; cin >> a; a--;
		B.push_back(a-i);
	}
	B.push_back(L);

	N += 2;

	map<int, int> minA;
	map<int, int> maxA;
	map<int, int> minB;
	map<int, int> maxB;

	for (int i = 0; i < N; i++) {
		maxA[A[i]] = i;
		maxB[B[i]] = i;
	}
	for (int i = N-1; i >= 0; i--) {
		minA[A[i]] = i;
		minB[B[i]] = i;
	}

	int64_t ans = 0;
	for (auto it : minB) {
		int v = it.first;
		if (minA.count(v)) {
			minB[v] = min(minB[v], minA[v]);
			maxB[v] = max(maxB[v], maxA[v]);
			ans += (maxB[v] - minB[v]) - (maxA[v] - minA[v]);
		} else {
			cout << -1 << '\n';
			exit(0);
		}
	}

	cout << ans << '\n';

	return 0;
}

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
template<class T>bool chmax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;}

int n,l;
int a[100010],b[100010];
int d[100010];
map<int,bool> ext;
map<int,int> L,R;
map<int,vector<int>> V;

void solve(){
    cin >> n >> l;
    rep(i,n) cin >> a[i+1];
    rep(i,n) cin >> b[i];
    a[n+1]=l+1;
    rep(i,n+2){
        if(!ext[a[i]-i]){
            L[a[i]-i]=i;
            R[a[i]-i]=i;
        }
        else{
            chmax(R[a[i]-i],i);
        }
        ext[a[i]-i]=true;
    }
    ll ans=0;
    // for(auto p:ext){
    //     cout << p.first << " " << L[p.first] << " " << R[p.first] << endl;
    // }
    rep(i,n){
        if(!ext[b[i]-i-1]){
            cout << -1 << endl;
            return;
        }
        V[b[i]-i-1].push_back(i+1);
    }
    for(auto p:V){
        int t=p.first;
        // cout << t << endl;
        // for(int i:p.second) cout << i << " ";
        //cout << "" << endl;
        if(L[t]>p.second.back()){
            ans+=L[t]-p.second[0];
        }
        else if(R[t]<p.second[0]){
            ans+=p.second.back()-R[t];
        }
        else{
            ans+=max(0,L[t]-p.second[0])+max(0,p.second.back()-R[t]);
        }
    }
    cout << ans << endl;
}

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


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

int main(){
   int A,B;
   int X;  //???????
   cin >> A >> B;
   X = (2 * A +100 ) - B;
   cout << X << endl;
}

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

int main() {
  ll a,b;
  cin>>a>>b;
  vector<ll>vec(1000);
  vector<ll>veco(1000);
  for(ll i=0;i<a;i++){
    ll c;
    cin>>c;
    vec.at(c-1)=1;
  }
  for(ll i=0;i<b;i++){
    ll c;
    cin>>c;
    veco.at(c-1)=1;
  }
  for(ll i=0;i<1000;i++){
    if(veco.at(i)*veco.at(i)+vec.at(i)*vec.at(i)==1){
      cout<<i+1<<' ';
    }
  }
}


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

#define ll long long
#define forin(in ,n) for(ll i=0; i<n; i++) cin>>in[i]
#define forout(out) for(ll i=0; i<(ll)out.size(); i++) cout<<out[i]<<endl
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep_up(i, a, n) for (ll i = a; i < n; ++i)
#define rep_down(i, a, n) for (ll i = a; i >= n; --i)
#define P pair<ll, ll>

#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define vvvll vector<vector<vector<ll>>>
#define vvll vector<vector<ll>>
#define vll vector<ll>
#define pqll priority_queue<ll>
#define pqllg priority_queue<ll, vector<ll>, greater<ll>>

constexpr ll INF = (1ll << 60);
// constexpr ll mod = 1000000007;
constexpr ll mod = 998244353;
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
void pt(T val) {
    cout << val << "\n";
}
template <typename T>
void pt_vll(vector<T> &v) {
    ll vs = v.size();
    rep(i, vs) {
        cout << v[i];

        if (i == vs - 1)
            cout << "\n";
        else
            cout << " ";
    }
}
ll mypow(ll a, ll n) {
    ll ret = 1;
    if(n==0) return 1;
    if(a==0) return 0;
    rep(i, n) {
        if (ret > (ll)(1e18 + 10) / a) return -1;
        ret *= a;
    }
    return ret;
}
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main() {
    ll r,x,y,z,st,ed,left,right,ans=0;
    double X,Y,R;
    cin>>X>>Y>>R;
    X*=10000.00000001;
    Y*=10000.00000001;
    R*=10000.00000001;
    x=X;
    y=Y;
    r=R;
    if(y+r>=0) st=(y+r)/10000;
    else st=(y+r-9999)/10000;
    if(y-r>=0) ed=(y-r+9999)/10000;
    else ed=(y-r)/10000;
    rep_up(i,ed,st+1){
        ll yy=y-10000*i;
        ll k=sqrt(r*r-yy*yy)+1;
        while(k*k+yy*yy>r*r){
            k--;
        }
        if(x+k>=0) right=(x+k)/10000;
        else right=(x+k-9999)/10000;
        if(x-k>=0) left=(x-k+9999)/10000;
        else left=(x-k)/10000;
        ans+=right-left+1;
    }
    cout<<ans<<endl;
}

#include <bits/stdc++.h>

using namespace std;

long long int MOD=1000000007;

long long power(long long a,long long b)
{
    a %= MOD;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}

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

/*_______________________________________________*/

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long double x,y,r,i;
    long long ans=0;
    cin>>x>>y>>r;
    r+=1e-14;
    for(i=floor(x-r);i<=ceil(x+r);i++)
    {
        long double temp1=(r*r)-((i-x)*(i-x));
        if(temp1<0)
        continue;
        temp1=sqrt(temp1);
        ans+=floor(temp1+y)-ceil(-temp1+y)+1;
    }
    cout<<ans;
}


#include<bits/stdc++.h>

#define  all(v)            v.begin(), v.end()
#define  sz(x)             (int)x.size()
#define  debug(x)          cout << #x << ':' << x << endl;
#define  rep(i,n)          for(long long i = 0; i <  n ; i++)
#define  reps(i,n)         for(long long i = 1; i <= n ; i++)
#define  make_unique(v)    sort(all(v));v.erase(unique(all(v)), v.end());
#define  REMOVE(v,a)       v.erase(remove(v.begin(),v.end(), a), v.end());
#define  pb                push_back
#define  mp                make_pair
#define  endl              '\n'
#define  fi                first
#define  se                second

using namespace std;
typedef long long          ll;
typedef vector<long long>  vll;
typedef pair<ll,ll>        pll;
const ll MOD = 1e9+7;
bool cmp(int X, int Y) {return X > Y;}

ll gcd(ll a, ll b) {return !b ? a : gcd(b, a % b);}
ll lcm(ll a, ll b) {return (a / gcd(a, b)) * b;}
ll modpow(ll a, ll b, ll m=MOD){a %= m; ll res = 1; while (b) {if (b & 1)res = (res * a) % m; a = (a * a) % m; b >>= 1;} return res;}
ll bpow(ll a, ll b){if(b<0){return 0;}ll res = 1; while (b) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;}
ll modinv(ll a, ll m = MOD) {return modpow(a, m - 2, m);}

const int N = 100005;
const int dx4[4] = {0, 1, 0, -1};
const int dy4[4] = {-1, 0, 1, 0};

ll vis[N];

ll fact(ll x){
  ll res = 1;
  for(ll i = 1; i<=x ; i++){
    res*=i;
    res = (res+MOD)%MOD;
  }
  return res;
}

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

	ll n,w;cin>>n>>w;
	ll k = n/w;
	cout<<k<<endl;

}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<bool>> graph(N, vector<bool>(N, false));
  for (int i = 0; i < M; ++i) {
    int from, to;
    cin >> from >> to;
    --from; --to;  // Convert to 0-based.
    graph[from][to] = true;
    graph[to][from] = true;
  }

  const int INFTY = N + 1;
  // dpv[mask] = min number of cliques you need
  // to include all of the nodes that are set in the mask
  vector<int> dpv(1 << N, INFTY);
  dpv[0] = 0;
  // O(N ^ 2 * 2 ^ N + 3 ^ N)
  for (int mask = 1; mask < (1 << N); ++mask) {
    // Check whether this mask can form one clique.
    bool valid = true;
    // Loop over every pair of set bits.
    for (int bit1 = 0; bit1 < N; ++bit1) {
      if (mask & (1 << bit1)) {
        for (int bit2 = bit1 + 1; bit2 < N; ++bit2) {
          if (mask & (1 << bit2)) {
            if (!graph[bit1][bit2]) {
              valid = false;
            }
          }
        }
      }
    }

    if (valid) {
      dpv[mask] = 1;
    } else {
      // Transition: consider all submasks.
      for (int submask = mask; submask > 0; submask = (submask - 1) & mask) {
        dpv[mask] = min(dpv[mask], dpv[submask] + dpv[mask - submask]);
      }
    }
  }
  cout << dpv.back() << endl;
}


# include <cstdio>
# include <cctype>
template <class code>inline code read (const code &a)
{
	code x=0;short w=0;char ch=0;
	while (!isdigit (ch)) {w|=ch=='-';ch=getchar ();}
	while (isdigit (ch)) {x=(x<<3)+(x<<1)+(ch^48);ch=getchar ();}
	return w?-x:x;
}
int main ()
{
	int a=read (a),b=read (b),c=read (c);
	printf ("%d\n",a-b+c);
	return 0;
}

#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(c) (c).begin(), (c).end()
#define pb push_back
#define eb emplace_back
using namespace std;
const long long INF = 1LL<<60; // 仮想的な無限大の値;
using ll = long long;
using P  = pair<int, int>;
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main()
{
    int h, w;
    cin >> h >> w;
    vs s(h);
    rep(i, h) cin >> s[i];
    int ans = 0;
    rep(i, h)rep(j, w){
        if(s[i][j] == '#') continue;
        if(i+1 < h && s[i+1][j] == '.') ++ans;
        if(j+1 < w && s[i][j+1] == '.') ++ans;
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;typedef long long ll;
void swa(int &x, int &y){int temp = x;x = y;y = temp;}
void IO() {freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);}
bool jj(int g,int h,int k){
    if(g<=k&&k<=h){
        return true;
    }
    return false;
}
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int x;cin>>x;
    int a[2][x];
    for(int i=0;i<2;i++){
        for(int j=0;j<x;j++){
            int f;cin>>f;
            a[i][j]=f;
        }
    }

    int ans=0;
    for(int i=1;i<=1000;i++){
        bool ff=true;

        for(int j=0;j<x;j++){
            if(!jj(a[0][j],a[1][j],i)){

                 ff=false;
                 break;
            }
        }

        if(ff==true){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

#pragma GCC optimize("Ofast")
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h>
#include <functional>
#include <cassert>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
constexpr ll INF = 1e18;
constexpr ll LLMAX = 9223372036854775807;
constexpr int inf = 1e9;
constexpr ll mod = 1'000'000'007;
// constexpr ll mod = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
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; }
#define eol endl
// ---------------------------------------------------------------------------

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<int> A(N),B(N);
  int mn = inf;
  int mx = 0;
  for(int i=0; i<N; i++){
    cin >> A[i];
    chmax(mx,A[i]);
  }
  for(int i=0; i<N; i++){
    cin >> B[i];
    chmin(mn,B[i]);
  }
  cout << max(0,mn-mx+1) << eol;
  return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;

int read()
{
	int a = 0,x = 1;
	char ch = getchar();
	while(ch > '9' || ch < '0'){
		if(ch == '-') x = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9'){
		a = a*10 + ch-'0';
		ch = getchar();
	}
	return a*x;
}
char a,b;

char js(char c)
{
	if(c >= 'a' && c <= 'z') return c-'a'+'A';
	else return c;
}

int main()
{
	scanf(" \n%c",&a);
	scanf(" \n%c",&b);
	if(a == 'Y') {
		printf("%c",js(b));
	} else printf("%c",b);
}

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
/* start */

const int N = 2e5 + 9; // MUDAR ISSO

signed main(){
   IOS;
   int n; cin >> n;
   string s; cin >> s;
   vector<char> r;
   int cnt = 0;
   for(int i = 0; i < n; i++) {
      r.push_back(s[i]);
      if(r.size() >= 3) {
         int N = r.size() - 1;
         if(r[N-2] == 'f' and r[N-1] == 'o' and r[N] == 'x') {
            cnt+=3;
            r.pop_back();
            r.pop_back();
            r.pop_back();
         }
      }
   }
   cout << n - cnt << "\n";
}

/*
   Coisas pra se lembrar:
      * Overflow, tamanho do N
      * Casos especiais (e.g. n = 1)
      * Nao ficar parado e fazer alguma coisa
      * Escrever coisas no papel
      * NAO FICAR TRAVADO EM UMA IDEIA
*/


/********include********/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#define popcount __builtin_popcount
using namespace std;
//#include <atcoder/all>

/***/
//#include <iomanip>
//#include <cmath>
#include <bits/stdc++.h>

/********define********/
const int MAX = 510000;
const int MOD = 1000000007;

#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define rrep(i,x) for(long long i=x-1;i>=0;i--)
#define rrepn(i,x) for(long long i=x;i>1;i--)
#define REP(i,n,x) for(long long i=n;i<x;i++)
#define REPN(i,n,x) for(long long i=n+1;i<x;i++)

#define pr printf
#define re return
#define mod 1000000007
//#define mod 998244353
#define inf  INT_MAX//19桁
#define INF 1e18+5//19桁
const double PI=3.14159265358979323846;
#define fi first
#define se second
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define all(x) (x).begin(),(x).end()

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

/********変数宣言********/
//vector<long long> g[200020];
vector<pair<long long,long long>> g[200020];
ll s[200020];
bool used[200020];
//bool dp[100005];

ll A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,Q,R,S,T,U,V,W,X,Y,Z;
double dA,dB,dC,dD,dE,dF,dG,dH,dI,dJ,dK,dL,dM,dN,dO,dP,dQ,dR,dS,dT,dU,dV,dW,dX,dY,dZ;

string sa,sb,sc,sd,se,sf,sg,sh,si,sj,sk,sl,sm,sn,so,sp,sq,sr,ss, su,sv,sw,sx,sy,sz;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin>>N;cin>>M;

	vector<string>v(M);

	vector<pair<long long, string> > p(M);
	//sort(p.begin(), p.end());
	//sort(p.begin(), p.end(),greater<pair<long long,long long> >());

	rep(j,M){
		cin>>v[j];
	}
	rep(i,M){
		p[i].fi=v[i].size();
		p[i].se=v[i];
	}
	sort(p.begin(), p.end());
	ll check;
	check=0;
	ll i;
	i=0;
	ll flg;
	while(check<N*N && i<M){

		if(check%N!=0){
			if(p[i-1].se[p[i-1].se.size()-1]==p[i].se[0]){
				rep(j,p[i].se.size()-1){
					p[i].se[j]=p[i].se[j+1];
				}
				p[i].se.resize(p[i].se.size()-1);
			}
		}

		if(check%N+p[i].se.size()<=N){
			cout<<p[i].se;
			check+=p[i].se.size();
			if(check%N==0){
				cout<<"\n";
			}
		}
		else{
			while(check%N!=0){
				cout<<".";
				check++;
			}
			cout<<"\n";
		}
		i++;
	}
	re 0;
}

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int num[8];
int main(){
  int n,m;
  cin>>n>>m;
  vector<string>t(m);
  vector<string>s;

  rep(i,m){
    cin>>t[i];
  }
  for(int k=2;k<=12;k++){
    rep(i,m){
      if(t[i].length()==k){
        s.push_back(t[i]);
      }
    }
  }

  int cur=0;
  rep(i,20){
    string temp="";
    while(1){
      string pretemp=temp;
      temp+=s[cur];
      if(temp.size()>20){
        temp=pretemp;
        break;
      }
      cur++;
    }
    int rest=20-temp.length();
    cout<<temp;
    rep(j,rest) cout<<".";
    cout<<endl;
  }

  /*rep(i,m){
    cout<<s[i]<<endl;
  }*/
  return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int N;
    cin>>N;
    int c;
    if(N<=1){
        c=0;
    }
    else {
        c=N-1;
    }

    cout<<c;
    return 0;
}

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

int main() {
	const auto ans = [](int p) { return p > 1? "Even": p < 1? "Odd": "Same"; };
	int T; ios_base::sync_with_stdio(false), cin.tie(nullptr), cin >> T;
	for (long long N; T--; 	cout << ans(__builtin_ctzll(N)) << '\n')
		cin >> N; }


//winners never quit//
//never give up//
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fast() ios_base::sync_with_stdio(0);cin.tie(nullptr);
const double PI = acos(-1);
#define MOD 1000000007
#define endl '\n'
const ll inf=1e9+10;
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
	return os << "(" << p.first << ", " << p.second << ")";
}

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

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
	os << "[";
	for (auto it = v.begin(); it != v.end(); ++it) {
		if ( it != v.begin() ) os << ", ";
		os << *it;
	}
	return os << "]";
}

template < typename T >
ostream &operator << ( ostream & os, const multiset< T > &v ) {
	os << "[";
	for (auto it = v.begin(); it != v.end(); ++it) {
		if ( it != v.begin() ) os << ", ";
		os << *it;
	}
	return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
	os << "[";
	for (auto it = v.begin(); it != v.end(); ++it) {
		if ( it != v.begin() ) os << ", ";
		os << it -> first << " = " << it -> second ;
	}
	return os << "]";
}

#define debug(args...) do {cerr << #args << " : "; faltu(args); } while(0)

void faltu () {
	cerr << endl;
}

template <typename T>
void faltu( T a[], int n ) {
	for (int i = 0; i < n; ++i) cerr << a[i] << ' ';
	cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) {
	cerr << arg << ' ';
	faltu(rest...);
}
void solve()
{
   ll m,h; cin>>m>>h;
   if(h%m==0) cout<<"Yes"<<"\n";
   else cout<<"No"<<"\n";
}
int main()
{
	solve();
}
//Author:_mehedi_

#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define ld long double
#define rep(i,n) for (ll i = 0;i<(n);++i)
#define all(v) v.begin(),v.end()

template <typename T>bool chmax(T &a, const T& b) {if (a < b) {a = b;return true;}return false;}
template <typename T>bool chmin(T &a, const T& b) {if (a > b) {a = b;return true;}return false;}
vector<long long> divisor(long long n){vector<long long> res;long long i = 1;while (i*i<=n){if(n%i==0){res.push_back(i);}i++;}if(res.size()==0)return res;for(long long i = res.size()-1-(res.back()*res.back()==n);i>=0;--i){res.push_back(n/res[i]);}return res;}
long long safe_mod(long long x,long long m){x%=m;if(x<0){x+=m;}return x;}
long long modpow(long long x,long long n,long long mod){long long ans=1;while(n>0){if(n&1){ans*=x;ans%=mod;}n>>=1;x*=x;x%=mod;}return ans;}
long long intpow(long long x,long long n){long long ans=1;while(n>0){if(n&1){ans*=x;}n>>=1;x*=x;}return ans;}
template<typename T>T intpow(T x,T n){T ans=1;while(n>0){if(n&1){ans*=x;}n>>=1;x*=x;}return ans;}
vector<pair<long long,long long>> factor_lst(long long n){vector<pair<long long,long long>> factor_lst;long long d=2;while(d*d<=n){if(n%d==0){long long num=0;while(n%d==0){num+=1;n/=d;}factor_lst.push_back({d,num});}d+=1;}if(n!=1){factor_lst.push_back({n,1});}return factor_lst;}
#define Uniq(a) sort(all(a));a.erase(unique(all(a)),end(a))

int msb(int x){return x==0 ? -1:32-__builtin_clz(x);}//1-indexed
int lsb(int x){return x==0 ? 32:__builtin_ctz(x)+1;}//1-indexed
int popcnt(int x){return __builtin_popcount(x);}
int popcnt(long long x){return __builtin_popcount(x);}

bool ingrid(int i,int j,int H,int W){
    return 0<=i&&i<H&&0<=j&&j<W;
}

const int dx[]={1,0,-1,0};
const int dy[]={0,1,0,-1};
template<typename T> void print(vector<T> &v){for(int i=0;i<v.size();++i){if(i)cout<<" ";cout<<v[i];}cout<<endl;}
template<typename T> void print(T* v,int size){for(int i=0;i<size;++i){if(i)cout<<" ";cout<<v[i];}cout<<endl;}
template<typename T,typename S>void print(pair<T,S>&p){cout<<p.first<<" "<<p.second<<endl;}
const ll LINF=4*1e18;
const ll MINF=5*1e15;
const int INF=2*1e9;
const ld PI=acosl(-1);

void Main();
int main(){cout<<fixed<<setprecision(15);Main();}

void Main(){

ll t,N;cin>>t>>N;
ll pos=100*N,ng=0;
while(pos-ng>1){
  ll mid=(pos+ng)/2;
  if((100+t)*mid/100-mid>=N)pos=mid;
  else ng=mid;
}
cout<<(100+t)*pos/100-1<<endl;

}


#include<bits/stdc++.h>

using namespace std;
#define int long long int

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

    int n;
    cin>>n;

    int arr[n];

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

    int cnt=0;

    for(int i=0;i<n;i++)
    {
        if(arr[i]>10)
        {
            cnt+=(arr[i]-10);
        }
    }

    cout<<cnt<<endl;

    return 0;
}

#include <bits/stdc++.h>
#define LOCAL

using namespace std;

using ll = long long;
// const int MOD = 1e9 + 7;

#define mem(a, b) memset(a, b, sizeof(a))
#define REP(i, a) for (int i = 0; i < a; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(a) a.begin(), a.end()

#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
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...);
}

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout << fixed << setprecision(10);
}

inline void print_vector(vector<int> &A){
    for (auto&& x : A){
        cout << x << " ";
    }
    cout << endl;
}

inline void print_vector(vector<ll> &A){
    for (auto&& x : A){
        cout << x << " ";
    }
    cout << endl;
}

inline void print_array(const int A[], int n) {
    REP(i, n) {
        if (i < n - 1) {
            cout << A[i] << " ";
        } else {
            cout << A[i] << endl;
        }
    }
}

ll gcd(ll a, ll b) {
    if (a < b) swap(a, b);
    while (b) {
        ll r = a % b; a = b; b = r;
    }
    return a;
}

inline void solve() {
    int n;
    cin >> n;

    vector<int> a(n);

    REP(i, n) cin >> a[i];

    ll res = 0;

    for (auto x : a) {
        res += max(x - 10, 0);
    }

    cout << res << endl;
}

int main() {
    quickread();
    int t = 1;
    // cin >> t;

    for (int _ = 0; _ < t; _++) {
        solve();
    }

    return 0;
}