//                        YATIN KWATRA

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize ("Ofast")

#define ll                      long long
#define ar                      array
#define sz(v)                   (int)(v.size())
#define inf                     1e18
#define int                     ll
#define FIO                     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ld                      long double
#define ull                     unsigned long long
#define endl                    "\n"
#define fo(i,a,b)               for(int i = a; i<=b ; i++)
#define rfo(i,a,b)              for(int i = a; i>=b ; i--)
#define vii                     vector<int>
#define pq                      priority_queue
#define uomii                   unordered_map<int,int,best_hash>
#define all(v)                  v.begin(),v.end()
#define mp                      make_pair
#define pb                      push_back
#define pob                     pop_back
#define ff                      first
#define ss                      second
#define pii                     pair<int,int>
#define mii                     map<int,int>
#define vvii                    vector<vii>
#define mod                     1000000007
#define MIN                     -1e9
#define pi                      3.1415926535897932384626433832795
#define cz(x)                   63 - __builtin_clzll(x)

using namespace std;
using namespace __gnu_pbds;
template<class T> using oset =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct best_hash {
	static uint64_t splitmix64(uint64_t x) {

		x += 0x9e3779b97f4a7c15;
		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
		return x ^ (x >> 31);
	}

	size_t operator()(uint64_t x) const {
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(x + FIXED_RANDOM);
	}
};

const int N = 3e3 + 1;

int dp[N][N];
int v[N];
vii has[N][N]; // pos for remainder j from after i
int n;

int ways(int pos, int k) {
	if (pos == n + 1) return 1;
	int &ans = dp[pos][k];
	if (ans != -1) return ans;
	ans = 0;

	// now go to next k+1 or k

	int rem = v[pos - 1] % k;

	int idx = lower_bound(all(has[k][rem]), pos) - has[k][rem].begin();
	if (idx < sz(has[k][rem])) {
		int to = has[k][rem][idx];
		if (to < n) ans = (ways(to + 1, k) + ways(to + 1, k + 1)) % mod;
		else ans = ways(to + 1, k);
	}
	return ans;
}

void solve()
{
	cin >> n;
	fo(i, 1, n) cin >> v[i];

	memset(dp, -1, sizeof(dp));

	fo(i, 1, n) {
		int sum = 0;
		fo(j, 1, n) {
			sum += v[j];
			has[i][sum % i].pb(j);
		}
	}

	fo(i, 1, n) v[i] += v[i - 1];
	cout << ways(1, 1);
}

signed main() {

	FIO
	int t;
	t = 1;
	//cin >> t;
	fo(i, 0, t - 1) {
		solve();
	}
	return 0;
}

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

#define M 1005
#define LL long long
const LL mod = 1000000007;

int n;
LL f[M];
char Caa, Cab, Cba, Cbb;

inline LL qkpow (LL x, LL y){
	LL res = 1;
	while (y){
		if (y & 1)
			res = res * x % mod;
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
signed main (){
	scanf ("%d\n%c\n%c\n%c\n%c", &n, &Caa, &Cab, &Cba, &Cbb);
	if (n == 3 || n == 2){
		printf ("1\n");
		return 0;
	}
	f[1] = 2, f[2] = 3;
	for (int i = 3; i <= n; i ++)
		f[i] = (f[i - 1] + f[i - 2]) % mod;
	if (Cab == 'B'){
		if (Cbb == 'B')
			printf ("1\n");
		else{
			if (Cba == 'A'){
				printf ("%lld\n", qkpow (2, n - 3));
			}
			else{
				printf ("%lld\n", f[n - 3]);
			}
		}
	}
	else{
		if (Caa == 'A')
			printf ("1\n");
		else{
			if (Cba == 'B'){
				printf ("%lld\n", qkpow (2, n - 3));
			}
			else{
				printf ("%lld\n", f[n - 3]);
			}
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define ll 				long long
#define pii             pair<ll,ll>
#define vi              vector<ll>
#define mii               map<ll,ll>
#define pqi             priority_queue<ll>			//max pq
#define pqd             priority_queue<ll,vi,greater<ll> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define MOD             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define pw(b,p)         pow(b,p) + 0.1
#define f(i,k,n)		for(ll i=k;i<n;i++)
#define fd(i,start,end)	for(ll i=start;i>=end;i--)

ll power(ll a, ll b, ll mod) {ll res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) {if (b & 1)res = res * a % mod; a = a * a % mod;} return res;}
ll power(ll a, ll b) {ll res = 1; assert(b >= 0); for (; b; b >>= 1) {if (b & 1)res = res * a ; a = a * a;} return res;}
ll min( ll a,  ll b) { return (a < b) ? a : b;}
ll max(ll a, ll b) {return (a > b) ? a : b;}
ll gcd (ll a, ll b) {if (a == 0) return  b; return gcd(b % a, a);}

void bwayne()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output2.txt", "w", stdout);
#endif
}
// ll n;
// cin >> n;
// vi a(n);
// f(i, 0, n) {
// 	cin >> a[i];
// }

// vector<vi> a(n,vector<vi>(m,0));
// f(i,0,n){
// 	f(j,0,m){
// 		cin>>a[i][j];
// 	}
// }

void printNcR(ll n, ll r)
{

	// p holds the value of n*(n-1)*(n-2)...,
	// k holds the value of r*(r-1)...
	long long p = 1, k = 1;

	// C(n, r) == C(n, n-r),
	// choosing the smaller value
	if (n - r < r)
		r = n - r;

	if (r != 0) {
		while (r) {
			p *= n;
			k *= r;

			// gcd of p, k
			long long m = gcd(p, k);

			// dividing by gcd, to simplify
			// product division by their gcd
			// saves from the overflow
			p /= m;
			k /= m;

			n--;
			r--;
		}

		// k should be simplified to 1
		// as C(n, r) is a natural number
		// (denominator should be 1 ) .
	}

	else
		p = 1;

	// if our approach is correct p = ans and k =1
	cout << p ;
}

void solve() {
	ll l;
	cin >> l;
	l -= 12;
	printNcR(l + 11, 11);
}
int main()
{
	bwayne();// remember
	ll t = 1;
	// cin >> t;

	for (ll tt = 1; tt <= t; tt++)
	{
		// cout << "Case #" << tt << ": ";
		solve();
	}

	return 0;
}

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>

using namespace std;
//using namespace atcoder;

#define REP(i, n) for (int i=0; i<(n); ++i)
#define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    return os << "(" << p.first << " " << p.second << ")";
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld eps = 1e-9;

// edit

void solve() {
    int N;
    cin >> N;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];

    vector<ll> S(N);
    map<ll, ll> ce, co;
    co[0]++;

    REP(i, N) {
        if (i == 0) S[i] = A[i];
        else S[i] = A[i] - S[i - 1];
//        else S[i] = S[i - 1] + A[i];
        if (i % 2 == 0) {
            ce[S[i]]++;
        } else {
            co[S[i]]++;
        }
    }

    ll ans = 0;
    set<ll> app_ce, app_co, app;
    for (auto e : ce) {
        app_ce.insert(e.first);
        app.insert(e.first);
    }
    for (auto e : co) {
        app_co.insert(e.first);
        app.insert(e.first);
    }

    for (auto e : app_ce) {
        ll val = ce[e];
        ll add = (val * val - val) / 2;
        ans += add;
    }

    for (auto e : app_co) {
        ll val = co[e];
        ll add = (val * val - val) / 2;
        ans += add;
    }

    for (auto e : app_ce) {
        if (ce.count(e) == 0 || co.count(-e) == 0) continue;
        ll add = ce[e] * co[-e];
        ans += add;
    }

    cout << ans << endl;

}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());

    solve();

    return 0;
}


#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
using namespace std;

const int maxn=2e5+10;
const int mod=998244353;

int n,ans=1,now,f[maxn],v[maxn];

int read(int x=0,bool f=0,char ch=getchar()){
	for(;ch<'0' || ch>'9';ch=getchar()) f=ch=='-';
	for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<3)+(x<<1)+(ch&15);
	return f?-x:x;
}

int main(){
	n=read();
	for(int i=1;i<=n;++i) f[i]=read();
	for(int i=1;i<=n;++i){
		if(!v[i]){
			++now;
			int x=i;
			while(!v[x]) v[x]=now,x=f[x];
			if(v[x]==now) ans=ans*2%mod;
		}
	}
	printf("%d\n",(ans+mod-1)%mod);
	return 0;
}

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

template <int MOD>
struct ModInt {
  int _v;

  ModInt(int64_t v = 0) {
    if (v < 0) v = v % MOD + MOD;
    if (v >= MOD) v %= MOD;
    _v = int(v);
  }

  ModInt(uint64_t v) {
    if (v >= MOD) v %= MOD;
    _v = int(v);
  }

  ModInt(int v) : ModInt(int64_t(v)) {}
  ModInt(unsigned v) : ModInt(uint64_t(v)) {}

  ModInt& operator++() {
    ++_v;
    if (_v == MOD) _v = 0;
    return *this;
  }

  ModInt& operator--() {
    if (_v == 0) _v = MOD;
    --_v;
    return *this;
  }

  ModInt& operator+=(const ModInt& rhs) {
    _v += rhs._v;
    if (_v >= MOD) _v -= MOD;
    return *this;
  }

  ModInt& operator-=(const ModInt& rhs) {
    _v -= rhs._v;
    if (_v < 0) _v += MOD;
    return *this;
  }

  ModInt& operator*=(const ModInt& rhs) {
    int64_t z = _v;
    z *= rhs._v;
    _v = z % MOD;
    return *this;
  }

  ModInt operator++(int) { ModInt before = *this; ++*this; return before; }
  ModInt operator--(int) { ModInt before = *this; --*this; return before; }

  friend ModInt operator*(const ModInt &a, const ModInt &b) { return ModInt(a) *= b; }
  friend ModInt operator+(const ModInt &a, const ModInt &b) { return ModInt(a) += b; }
  friend ModInt operator-(const ModInt &a, const ModInt &b) { return ModInt(a) -= b; }

  friend bool operator==(const ModInt &a, const ModInt &b) { return a.val == b.val; }
  friend bool operator!=(const ModInt &a, const ModInt &b) { return a.val != b.val; }
  friend bool operator<(const ModInt &a, const ModInt &b) { return a.val < b.val; }
  friend bool operator>(const ModInt &a, const ModInt &b) { return a.val > b.val; }
  friend bool operator<=(const ModInt &a, const ModInt &b) { return a.val <= b.val; }
  friend bool operator>=(const ModInt &a, const ModInt &b) { return a.val >= b.val; }

  friend ostream& operator<<(ostream &os, const ModInt& a) { return os << a._v; }
};

const int MOD = 998244353;
using mod_int = ModInt<MOD>;

int main() {
  int N;
  cin >> N;
  vector<vector<int>> g(N);
  for (int i = 0; i < N; ++i) {
    int x;
    cin >> x;
    --x;  // Convert to 0-based indexing.
    g[i].push_back(x);
    g[x].push_back(i);
  }

  function<void(int, vector<bool>&)> visitComponentDFS;
  visitComponentDFS = [&] (int u, vector<bool>& visited) {
    visited[u] = true;
    for (int v : g[u]) {
      if (!visited[v]) {
        visitComponentDFS(v, visited);
      }
    }
  };

  mod_int num = 1;
  vector<bool> visited(N, false);
  int num_cc = 0;
  for (int i = 0; i < N; ++i) {
    if (!visited[i]) {
      ++num_cc;
      visitComponentDFS(i, visited);
    }
  }

  while (num_cc > 0) {
    num *= 2;
    --num_cc;
  }

  num -= 1;
  cout << num << endl;
}


#include <bits/stdc++.h>
using namespace std;
int N, a[505];
void solve() {
	cin >> N;
	for (int i = 1; i <= N; i++) cin >> a[i];
	vector<int> ans;
	for (int stp = 1; stp <= N * N; stp++) {
		bool flg = 1;
		for (int i = 2; i <= N && flg; i++) flg &= a[i - 1] < a[i];
		if (flg) break;
		int cur = (stp & 1) ? 1 : 2;
		for (int i = cur; i < N; i += 2)
			if (a[i] > a[i + 1]) cur = i;
		swap(a[cur], a[cur + 1]);
		ans.push_back(cur);
	}
	printf("%lu\n", ans.size());
	for (int i : ans) printf("%d ", i);
	putchar('\n');
}
int main () {
#ifndef ONLINE_JUDGE
    freopen("cpp.in", "r", stdin);
#endif
	int T; cin >> T;
	while (T--) solve();
    return 0;
}

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

//#include <atcoder/convolution>
//#include <atcoder/modint>
//using Modint = atcoder::modint998244353;

using namespace std;
typedef long long ll;

void ex_gcd(ll a, ll b, ll &d, ll &x, ll &y) {
  if (!b) {
    d = a;
    x = 1;
    y = 0;
  } else {
    ex_gcd(b, a % b, d, y, x);
    y -= a / b * x;
  }
}
ll inv(ll a, ll n) {
  ll d, x, y;
  ex_gcd(a, n, d, x, y);
  return d == 1 ? (x % n + n) % (n / d) : -1;
}
ll gcd(ll x, ll y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}

const int maxn = 505;
const int mod = 998244353;

int a[maxn];
int pos[maxn];

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  int T;
  cin>>T;
  while(T--){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
      scanf("%d",&a[i]);
      pos[a[i]] = i;
    }
    int cur=1;
    vector<int>ans;
    for(int i=n;i>=4;i--){
      if(pos[i]==i)continue;
      if((pos[i]&1)!=cur){
        if(i==4&&pos[4]==3){
          int idx = pos[i];
          swap(a[idx-1], a[idx]);
          cur = 1-cur;
          ans.push_back(idx-1);
          pos[a[idx-1]] = idx-1;
          pos[a[idx]] = idx;
        }
        for(int j=1;j<i;j++){
          if(a[j]!=i&&a[j+1]!=i&&(j&1)==cur){
            swap(a[j], a[j+1]);
            cur = 1 - cur;
            ans.push_back(j);
            pos[a[j]] = j;
            pos[a[j+1]] = j+1;
            break;
          }
        }
      }
      for(int j=pos[i];j<i;j++){
        ans.push_back(j);
        cur = 1-cur;
        swap(a[j], a[j+1]);
        pos[a[j]] = j;
        pos[a[j+1]] = j+1;
      }
    }
    if(n==2){
      if(!(a[1]==1&&a[2]==2)){
        ans.push_back(1);
        cur = 1 - cur;
        swap(a[1], a[2]);
        pos[a[1]] = 1;
        pos[a[2]] = 2;
      }
    } else {
      while(!(a[1]==1&&a[2]==2&&a[3]==3)){
        int tmp = 2 - cur;
        ans.push_back(tmp);
        cur = 1-cur;
        swap(a[tmp], a[tmp+1]);
        pos[a[tmp]] = tmp;
        pos[a[tmp+1]] = tmp+1;
      }
    }
    cout<<ans.size()<<endl;
    for(int i=0;i<ans.size();i++){
      if(i)printf(" ");
      printf("%d", ans[i]);
    }
    cout<<endl;
  }
  return 0;
}


#ifdef __LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using PIL = pair<int,ll>;
using PLI = pair<ll,int>;
using PLL = pair<ll,ll>;
using Graph = vector<vector<int>>;
using Cost_Graph = vector<vector<PIL>>;

template<class T> bool chmin(T &a, T b) {if(a>b){a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b){a=b;return 1;}return 0;}
template<class T> void show_vec(T v) {for (int i=0;i<v.size();i++) cout<<v[i]<<endl;}
template<class T> void show_pair(T p) {cout<<p.first<<" "<<p.second<<endl;}
template<class T> bool judge_digit(T bit,T i) {return (((bit&(1LL<<i))!=0)?1:0);}
#define REP(i,n) for(int i=0;i<int(n);i++)
#define ROUNDUP(a,b) ((a+b-1)/b)
#define YESNO(T) cout<<(T?"YES":"NO")<<endl
#define yesno(T) cout<<(T?"yes":"no")<<endl
#define YesNo(T) cout<<(T?"Yes":"No")<<endl

const int INFint = 1 << 29;
const ll INFLL = 1LL << 60;
const ll MOD = 1000000007LL;
const vector<int> h_idx4 = {-1, 0,0,1};
const vector<int> w_idx4 = { 0,-1,1,0};
const vector<int> h_idx8 = {-1,-1,-1, 0,0, 1,1,1};
const vector<int> w_idx8 = {-1, 0, 1,-1,1,-1,0,1};

vector<ll> result;

struct Point {
    int pi,pj;
};

string calc_path(Point s,Point t){
    int di = t.pi - s.pi, dj = t.pj - s.pj;
    // cout << di << " " << dj << endl;
    string res;
    if (di > 0){
        for (int i = 0; i < di; i++){
            res.push_back('D');
        }
    }
    else{
        for (int i = 0; i < -di; i++){
            res.push_back('U');
        }
    }

    if (dj > 0){
        for (int i = 0; i < dj; i++){
            res.push_back('R');
        }
    }
    else{
        for (int i = 0; i < -dj; i++){
            res.push_back('L');
        }
    }

    return res;
}

void input_point(Point &s,Point &t){
    cin >> s.pi >> s.pj >> t.pi >> t.pj;
    return;
}

void input_score(){
    ll x;
    cin >> x;
    result.push_back(x);

    return;
}

void output_part(string s){
    cout << s << endl;
}

void solve_part(){
    Point s,t;
    input_point(s,t);

    string res = calc_path(s,t);

    output_part(res);

    input_score();
}

void solve(){
    for (int i = 0; i < 1000; i++){
        solve_part();
    }
}

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

    solve();

    return 0;
}

#include <iostream>
#include <vector>

int main()
{
    for (int query = 0; query < 1000; query++)
    {
        int si, sj, ti, tj;
        std::cin >> si >> sj >> ti >> tj;
        for (int i = 0; i < std::max(si - ti, 0); i++)
        {
            std::cout << 'U';
        }
        for (int i = 0; i < std::max(ti - si, 0); i++)
        {
            std::cout << 'D';
        }
        for (int i = 0; i < std::max(sj - tj, 0); i++)
        {
            std::cout << 'L';
        }
        for (int i = 0; i < std::max(tj - sj, 0); i++)
        {
            std::cout << 'R';
        }
        std::cout << std::endl;
        int response;
        std::cin >> response;
    }
    return 0;
}


#include <algorithm>
#include <array>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <vector>

using namespace std;

#define enviar {ios_base::sync_with_stdio(false);}
#define aiuda {cin.tie(NULL); cout.tie(NULL);}

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) ;F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)
#define exacto(v) cout << setprecision(v) << fixed;

#define ll long long
#define lld long double
#define eb emplace_back
#define em emplace
#define ef emplace_front
#define f first
#define s second
#define big greater<ll>()
#define bpc(x) __builtin_popcount(x)
#define bpc2(x) __builtin_clz(x)
#define DIE(args...) {print(args); return;}

#define ar(v)  array<int,v>
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x).size()
#define meminf(v) memset(v,  0x3f , sizeof(v))
#define mem(v,x) memset(v , x , sizeof v);
#define ai(a, n) for (int ele = 0; ele < n; ele++) cin >> a[ele];
#define ao(a, n) {for (int ele = 0; ele < (n); ele++) { if (ele) cout << " "; cout << a[ele]; } cout << '\n';}
#define readgraph(list, edges) for (int i = 0; i < edges; i++) {int n1, n2; cin >> n1 >> n2; n1--; n2--; list[n1].eb(n2); list[n2].eb(n1);}

template <typename T>
struct combinator {
    T t_;
    combinator(T&& t) : t_(std::forward<T>(t)) {}

    template <typename... Args>
    auto operator () (Args&&... args) const
    {
        return t_(*this, std::forward<Args>(args)...);
    }
};

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

string to_string(bool b) {return b?"true":"false"; }

string to_string(char c) { return string(1, c);}

string to_string(const char* s) { return string(s); }

string to_string(string s) { return s; }

template<class T> string to_string(T v) { bool f=1; string res; EACH(x, v) { if(!f) res+=' '; f=0; res+=to_string(x); } return res; }

template<class A> void write(A x) { cout << to_string(x); }

void print() { write("\n"); }

template<class H, class... T> void print(const H& h, const T&... t) {  write(h); if(sizeof...(t)) write(' '); print(t...); }

typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef map<ll, ll> mll;
typedef priority_queue<int, std::vector<int>, std::greater<int>> priomin;

const ll mod = 998244353;
const ll maxsize =3e5 + 10;
const ll inf = 0x3f3f3f3f3f3f3f3f ;
// size, caracter

ll c[maxsize];

bool sieve[100];
vll primes(100);

ll m;
void solve()
{

	for(ll i =2; i <= 72 ; i++)
	{
		if (sieve[i]) continue;
		primes[m++]  = i;
		for(ll j = i*i; j <= 72 ; j+=i)
		{
			sieve[j] = true;
		}
	}

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

	//m--;
	vll dp(1<<m , 0);
	dp[0] = 1;

	for( ll i = a; i <= b ; i++)
	{
		ll mask = 0;

		FOR(j , m)
		{
			if (i%primes[j] == 0 ) mask |= 1<<j;
		}

		FOR(k , 1<<m)
		{
			if ((k & mask) == 0)
			{
				dp[k | mask] += dp[k];
			}
		}

	}
//	FOR(i , m) print(primes[i]);

	ll ans = 0;
	FOR(i , 1<<20 ) ans += dp[i];

	print(ans);
}

int main(){

	enviar aiuda

	int tc = 1;
	//cin >> tc;

    while(tc--)  solve();

	return 0;
}

//Utkarsh.25dec
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
using namespace std;
typedef vector<vector<ll>> matrix;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=500023;
bool vis[N];
vector <int> adj[N];
int isprime[N];
ll dp[(1<<21)+10];
void solve()
{
    ll a,b;
    cin>>a>>b;
    vl primes;
    for(int i=2;i<=72;i++)
    {
        if(isprime[i]==i)
            primes.pb(i);
    }
    dp[0]=1;
    ll fun[100]={0};
    int cnt=0;
    for(ll x=a;x<=b;x++)
    {
        int mask=0;
        for(int i=0;i<primes.size();i++)
        {
            if(x%primes[i]==0)
            {
                mask+=(1<<i);
            }
        }
        fun[x-a]=mask;
        if(mask==0)
            cnt++;
    }
    dp[0]=(1ll<<cnt);
    ll ans=dp[0];
    for(int i=1;i<(1<<(primes.size()));i++)
    {
        int consider=0;
        for(ll j=0;j<60;j++)
        {
            if((i&(1ll<<j))!=0)
            {
                consider=j;
                break;
            }
        }
        for(ll k=a;k<=b;k++)
        {
            int mask=0;
            mask=fun[k-a];
            if((mask&i)==mask && (mask&(1<<consider))!=0)
            {
                dp[i]+=dp[i^mask];
            }
        }
        ans+=dp[i];
    }
    cout<<ans<<'\n';
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T=1;
    //cin>>T;
    for(int i=1;i<N;i++)
        isprime[i]=i;
    for(int i=2;i<N;i++)
    {
        if(isprime[i]!=i)
            continue;
        for(int j=i;j<N;j+=i)
            isprime[j]=i;
    }
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


/* � Ashiq Uddin Pranto
   Department of Computer Science and Engineering
   BATCH 27
   University Of Rajshahi,Bangladesh
*/
#include<bits/stdc++.h>

#define ll long long
#define ld long double
#define FOR(x,y) for(ll i=x;i<=y;i++)
#define pb(x) push_back(x)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define matrix(x) vector<vector<x>>
#define vss vector<string>
#define PI (2*acos(0.0))
#define sqr(x) ((x)*(x))
#define sf(a)   scanf("%d",&a)
#define sfl(a)  scanf("%lld",&a)
#define sff(a,b)    scanf("%d %d",&a,&b)
#define sffl(a,b)   scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define sfffl(a,b,c)    scanf("%lld %lld %lld",&a,&b,&c)
#define ms(a,b) memset(a, b, sizeof(a))
#define ff  first
#define ss  second
#define lcm(a, b)   ((a)*((b)/__gcd(a,b)))
#define all(a)  a.begin(),a.end()
#define readfile freopen("input.txt","r",stdin);
#define writefile freopen("output.txt","w",stdout);
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define gap " "
#define mx 104
#define inf (ll)1e9
#define WHITE 1
#define GRAY 2
#define BLACK 3
#define EMPTY_VALUE -1
#define mod 1000000007
#define MOD(a,b) (a%b + b)%b

using namespace std;

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

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

void eff()
{
    ll n,k;
    sffl(n,k);
    vll a(n);
    map<ll,ll>cnt;
    for(ll i=0;i<n;i++)
    {
        sfl(a[i]);
        cnt[a[i]]++;
    }
    // debug(cnt);
    ll boxmax;
    auto x = cnt.begin();
    if(x->first==0)
    {
        boxmax = min(k,x->second);
    }
    else
    {
        printf("0\n");
        return;
    }
    ll i=0;
    ll ans = 0;
    ll lastfirst = 0;
    for(auto x: cnt)
    {
        if(abs(lastfirst-x.first)>=2)
        {
            ans+=i*(boxmax);
            cout<<ans<<endl;
            return;
        }
        if(x.second <boxmax)
        {
            ans+=i*(boxmax-x.second);
            boxmax = x.second;
        }
        lastfirst = x.first;
        i++;
    }
    // auto last = cnt.rbegin();
    ans+=i*(boxmax);
    cout<<ans<<endl;

}

int main()
{
    // fastio
    // ll test ;
    // sfl(test);
    // for(ll i=0;i<test;i++)
    // {
        // printf("Case %lld: ",i+1);
        eff();
    // }
//    cout<<check(81);
    return 0;
}

//g++ t.cpp -o t && t < p.txt
//d>p.txt&&t<p.txt&&t2<p.txt

#include <iostream> //
#include <vector> //
#include <algorithm> //
#include <queue> //
#include <string> //
#include <functional> //
#include <set> //
#include <map> //
#include <random> //
#include <ctime> //
#include <bitset> //
#include <cassert>

// #include <atcoder/all>
// using namespace atcoder;
// g++ t.cpp -o t -I .

#define DB cerr<<"D"<<endl

using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
using P=pair<ll,ll>;
const ll M = 998244353;
ll mod_pow(ll x, ll a) { ll an = 1; while(a > 0) { if (a&1) an = an * x % M; x = x * x % M; a >>= 1;} return an;}
ll mod_pow(ll x, ll a, ll m) { ll an = 1; while(a > 0) { if (a&1) an = an * x % m; x = x * x % m; a >>= 1;} return an;}
void add(ll& x, ll y) {x+=y; x%=M;}; void mul(ll& x, ll y) {x*=y; x%=M;}; template<typename T, typename U> void chmax(T& x, U y) {if (x<y) x=y;}; template<typename T, typename U> void chmin(T& x, U y) {if (x>y) x=y;} bool vaild(int x, int y, int hh, int ww){return 0<=x&&x<hh&&0<=y&&y<ww;}
ll gcd(ll a, ll b) {if (b==0) return a; else return gcd(b, a%b);}
int keta(ll a) {int res=0; while(a>0) res+=a%10, a/=10; return res;}
const int up[]={1,-1,0,0}, lf[]={0,0,1,-1};

int main() {
  ll n,k; cin>>n>>k;
  ll a[n]; for(int i=0;i<n;i++) cin>>a[i];
  ll b[n+1]={}; for(int i=0;i<n;i++) b[a[i]]++;
  ll an=0;
  for(int i=0;i<k;i++) {
    //for(int j=0;j<=n;j++)cout<<b[i]<<" ";cout<<endl;
    for(int j=0;j<=n;j++) {
      if (b[j]==0) {
        an+=j; break;
      } else {
        b[j]--;
      }
    }
    //cout<<an<<endl;
  }
  cout<<an<<endl;
}

// ・配列の大きさok？　・priority_queueはgreater？　・debug消した？
// ・落ち着いて。提出まで4分待ってね……WJ……1/10……2/10……

// Thank you for making problems and running the contest


//abc185 b

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

int main() {
    int n,m,t;
    cin >> n >> m >> t;
    int last_time = 0;
    int max = n;
    string ans = "Yes";
    for(int i=0 ; i<m ; i++){
        int a,b;
        cin >> a >> b;
        n -= a-last_time;
        if(n < 1){
            ans = "No";
        }
        if(n + b - a <= max){
            n += b - a;
        }else{
            n = max;
        }
        last_time = b;
        if(i == m-1){
            n -= t - b;
            if(n < 1){
                ans = "No";
            }
        }
    }

    cout << ans << endl;
}

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

using P=pair<int64_t,int>;

int main(){
    int N,K;
    cin >> N >> K;
    vector<P> vp;
    for(int i=0;i<N;i++){
        int64_t A;
        int B;
        cin >> A >> B;
        vp.emplace_back(A,B);
    }
    sort(vp.begin(),vp.end());
    int64_t m=K;
    for(int i=0;i<N;i++){
        auto &p=vp.at(i);
        if(m>=p.first){
            m+=p.second;
        }else{
            break;
        }
    }
    cout << m << endl;
    return 0;
}


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

typedef long long ll;
const int maxn=2e5+5;
ll p[maxn];
bool cmp(ll a,ll b){
    return a>b;
}

int main(){
    int n;
    cin>>n;
    ll sum=0;
    for(int i=0;i<n;i++){
        ll a,b;
        cin>>a>>b;
        sum+=a;
        p[i]=2*a+b;
    }
    sort(p,p+n,cmp);
    int ans=0;
    ll sumb=0;
    for(int i=0;i<n;i++){
        sumb+=p[i];
        ans++;
        if(sum<sumb)
            break;
    }
    cout<<ans<<endl;
    return 0;
}

#include <bits/stdc++.h>
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define reprrev(i, a, b) for (int i = b - 1; i >= a; i--) // [a, b)
#define reprev(i, n) reprrev(i, 0, n)
#define _GLIBCXX_DEBUG

using ll = long long;
using ull = unsigned long long;
template <class T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
const ll mod = 1e9 + 7;
const ll INF = 1e18;
void chmod(ll &M)
{
  if (M >= mod)
    M %= mod;
  else if (M < 0)
  {
    M += (abs(M) / mod + 1) * mod;
    M %= mod;
  }
}
ll modpow(ll x, ll n)
{
  if (n == 0)
    return 1;
  ll res = modpow(x, n / 2);
  if (n % 2 == 0)
    return res * res % mod;
  else
    return res * res % mod * x % mod;
}

int getl(int i, int N) { return i == 0 ? N - 1 : i - 1; };
int getr(int i, int N) { return i == N - 1 ? 0 : i + 1; };
long long GCD(long long a, long long b)
{
  if (b == 0)
    return a;
  else
    return GCD(b, a % b);
}
using namespace std;

int main() {
  int N; cin >> N;
  ll A = 0;
  vector<pair<ll, ll>> P(N);
  vector<ll> sum(N);
  rep(i, N) {
   cin >> P[i].first >> P[i].second;
   A += P[i].first;
   ll s = 2*P[i].first + P[i].second;
   sum[i] = s;
}

sort(sum.rbegin(), sum.rend());

vector<ll> S(N+1, 0);
rep(i, N) {
  S[i+1] = S[i] + sum[i];
}

auto it = lower_bound(S.begin(), S.end(), A+1);

ll ans = it - S.begin();
cout << ans << endl;
}


/* What we know is a drop , but what we don't know is an ocean !*/

#include <bits/stdc++.h>
#define ll long long int
#define F(i,j,k,in) for(int i=j;i<k;i+=in)
#define DF(i,j,k,in) for(int i=j;i>=k;i-=in)
#define feach(it,l) for (auto it = l.begin(); it != l.end(); ++it)
#define fall(a) a.begin(),a.end()
#define sz(x) (int)x.size()
#define szs(x) (int)x.length()
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define fs first
#define ss second
#define mkp make_pair
#define endl "\n"
using namespace std;

typedef vector<ll> vll;
typedef vector<int> vin;
typedef vector<char> vch;
typedef vector<string> vst;
typedef set<ll> sll;
typedef set<int> sint;
typedef set<char> sch;
typedef set<string> sst;
typedef queue<ll> qll;
typedef queue<int> qin;
typedef queue<char> qch;
typedef deque<ll> dqll;
typedef deque<int> dqint;
typedef deque<char> dqch;
typedef priority_queue<ll> pqll;
typedef priority_queue<int> pqin;
typedef priority_queue<char> pqch;
typedef map<ll,ll> mpll;
typedef map<int,int> mpin;
typedef pair<ll,ll> pll;
typedef pair<int,int> pin;

const ll MOD=1000000007;
const long double PI=3.1415926535897932384626433832795;

ll pwr(ll b,ll p){ll res=1;while(p){if(p&1) {res*=b; p--;}else{b*=b; p>>=1;}}return res;}
ll mpwr(ll b,ll p){ll res=1;while(p){if(p&1) {res=(res*b)%MOD; p--;}else{b=(b*b)%MOD; p>>=1;}}return res;}

int msb (int n) {return 31-__builtin_clz(n);}
ll msbl (ll n) {return 63-__builtin_clzll(n);}
int lsb (int n) {return __builtin_ctz(n);}
ll  lsbl (ll n) {return __builtin_ctzll(n);}
int setbit (int n) {return __builtin_popcount(n);}
ll setbitl (ll n) {return __builtin_popcountll(n);}
const int maxn = 3005;
ll dp [maxn][maxn];

int main()
{
ios_base::sync_with_stdio(false) , cin.tie(NULL) , cout.tie(NULL);
ll n; cin>>n;
vll a (n);
F (i,0,n,1) cin>>a[i];

F (i,0,n,1) {
	F (j,0,n,1) dp[i][j]=0;
}

F (i,0,n,1) dp[i][1]=1;

F (j,2,n+1,1) {
	ll s=0;
	vll sum (n,0);
	F (i,0,n,1) {
		s=(s+a[i])%j;
		dp[i][j]=sum[s];
		sum[s]=(sum[s]+dp[i][j-1])%MOD;
	}
}
ll ans=0;
F (i,1,n+1,1) ans=(ans+dp[n-1][i])%MOD;
cout<<ans;
return 0;
}
/*Maybe you are searching among the branches for what only appears in the roots.*/

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

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

#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010000
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"
#define N 500010

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;

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

struct Node{
  vector<PII> edges;//first=cost,second=index

  bool visit;
  int cost;
};

vector<Node> mp(N);

void dijkstra(int st,int n){
  rep(i,n){
    mp[i].visit=false;
    mp[i].cost= INF;
  }
  priority_queue<PII>  q;
  mp[st].cost=0;
  rep(i,mp[st].edges.size() ){
    mp[mp[st].edges[i].S].cost=mp[st].edges[i].F;
    q.push({-mp[st].edges[i].F,mp[st].edges[i].S});
  }
  mp[st].visit=true;
  while(!q.empty() ){
    PII p=q.top();
    int u=p.S;
    q.pop();

    if(mp[u].cost < -p.F) continue;
    mp[u].visit=true;
    rep(i,mp[u].edges.size() ){
      int v=mp[u].edges[i].S;
      if(!mp[v].visit){
	if(mp[v].cost> mp[u].cost+mp[u].edges[i].F){
	  mp[v].cost=mp[u].cost+mp[u].edges[i].F;
	  q.push({-mp[v].cost,v});
	}
      }
    }
  }
}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int r,c;
  cin>>r>>c;
  int A[r][c-1],B[r-1][c];
  rep(i,r) rep(j,c-1) cin>>A[i][j];
  rep(i,r-1) rep(j,c) cin>>B[i][j];

  rep(i,r){
    rep(j,c){
      int mn=(i*c)+j,mx=250000+mn;
      if(j<c-1) mp[mn].edges.push_back({A[i][j],mn+1});
      if(j>0) mp[mn].edges.push_back({A[i][j-1],mn-1});
      if(i<r-1) mp[mn].edges.push_back({B[i][j],mn+c});
      mp[mn].edges.push_back({1,mx});
      if(mx-c >= 250000) mp[mx].edges.push_back({1,mx-c});
      mp[mx].edges.push_back({0,mn});
    }
  }

  dijkstra(0,250000+(r*c) );

  /*rep(i,r){
    rep(j,c){
      cout<<mp[(i*c)+j].cost<<" ";
    }
    cout<<endl;
    }*/
  cout<<mp[r*c-1].cost<<endl;
  return 0;
}


#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <complex>
using namespace std;
#define all(v) v.begin(),v.end()
#define GS std::greater<int>()
#define FOR(i,l,r) for(Int i=(l);i<(r);i++)
#define DCOUT cout<<fixed<<setprecision(15) //DCOUT<<d<<endl;
#define ROUNDUP(a,b) ((a)+((b)-1))/(b)
#define TDVEC(name,type,h,w) vector<vector<type>>name((h),vector<type>(w))
#define P pair<Int,Int>
#define MOD 1000000007
#define MOD2 998244353
#define INF (1<<29)
#define LINF (1LL<<60)
#define PI 3.1415926535897932384626433832795028
#define itn int
#define space ' '
typedef long long Int;
typedef unsigned long long uInt;
typedef long double ld;
Int gcd(Int a,Int b){return b?gcd(b,a%b):a;}
Int lcm(Int a,Int b){return a/gcd(a,b)*b;}

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

#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rrep(i,n) for(ll i=n-1; i>=0; i--)
#define fi first
#define se second
#define pcnt __builtin_popcountll
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> PlP;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
string zero_padding(int val, int nf){ ostringstream sout;sout << setfill('0') << setw(nf) << val; return sout.str();};
const ld eps = 1e-10;
ull mo = 1000000007;
ld PI=asin(1)*2;
//using namespace atcoder;

vector<vector<PlP>> G(100010);
int main(){
    ll N,M;
    cin >> N >> M;
    vector<ll> A(M), B(M), C(M), D(M);
    rep(i,M){
        cin >> A[i] >> B[i] >> C[i] >> D[i];
        A[i]--; B[i]--;
    }
    rep(i,M){
        G[A[i]].push_back({C[i],{D[i],B[i]}});
        G[B[i]].push_back({C[i],{D[i],A[i]}});
    }
    vector<ll> d1(N,1e18);
    priority_queue<Pll, vector<Pll>, greater<Pll>> que;
    que.push(Pll(0,0));
    while(!que.empty()){
        ll t = que.top().fi;
        ll v = que.top().se;
        que.pop();
        if(d1[v] <= t) continue;
        //if(d1[v] != 1e18) continue;
        d1[v] = t;
        for(auto& p:G[v]){
            ll c = p.fi;
            ll d = p.se.fi;
            ll u = p.se.se;
            ll rd1 = max(ll(sqrt(ld(d))-1),ll(t));
            ll rd2 = max(ll(sqrt(ld(d))),ll(t));
            ll tt1 = ll(rd1) + c + ll(d/(rd1+1));
            ll tt2 = ll(rd2) + c + ll(d/(rd2+1));
            // cout << L << " " << R << " " << r1 << " " << r2 << endl;

            que.push(Pll(min(tt1,tt2),u));
        }
    }
    if(d1[N-1] == 1e18){
        drop(-1);
    }
    cout << d1[N-1] << endl;
}


//デバッグ用オプション：-fsanitize=undefined,address

//コンパイラ最適化
#pragma GCC optimize("Ofast")

//インクルードなど
#include <bits/stdc++.h>
// #include <atcoder/all>

using namespace std;
// using namespace atcoder;

typedef long long ll;
using vint = vector<int>;
using vll = vector<ll>;
using vs = vector<string>;
using vbool = vector<bool>;
template <class T> using arr = vector<vector<T>>;

//マクロ
// forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
// Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
// FORAは範囲for文(使いにくかったら消す)
#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < ll(b); i++)
#define FORD(i, a, b) for (ll i = b - 1; i >= ll(a); i--)
#define FORA(i, I) for (const auto &i : I)
// xにはvectorなどのコンテナ
#define ALL(x) x.begin(), x.end()
#define SIZE(x) ll(x.size())
//定数
#define INF 1000000000000 // 10^12:∞
#define MOD 1000000007 // 10^9+7:合同式の法
#define MAXR 100000 // 10^5:配列の最大のrange

// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

template <class T> void pl(T x) { cout << x << " "; }

template <class T> void pr(T x) { cout << x << endl; }

template <class T> void prvec(const vector<T> &a) {
  REP(i, a.size() - 1) { cout << a[i] << " "; }
  pr(a[a.size() - 1]);
}

template <class T> void prarr(const arr<T> &a) {
  REP(i, a.size())
  if (a[i].empty())
    pr("");
  else
    prvec(a[i]);
}

using P = pair<ll, ll>;
void prp(const P &p) { cout << p.first << " " << p.second << endl; }

struct Constants {
  ll N;
  Constants() { cin >> N; }
} C;

struct Args {
  vll a, b, p;
  vll ids;
  Args() : a(C.N), b(C.N), p(C.N), ids(C.N) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    REP(i, C.N) cin >> a.at(i);
    REP(i, C.N) cin >> b.at(i);
    REP(i, C.N) {
      cin >> p.at(i);
      --p.at(i);
    }
    REP(i, C.N) ids.at(i) = i;
    sort(ALL(ids), [&](ll l, ll r) { return a.at(l) < a.at(r); });
  }
} args;

struct Solver {
  bool ok;
  vector<P> ans;
  Solver() : ok(true), ans() {}
  //
  void solve() {
    vll cur(C.N);
    REP(i, C.N) {
      cur.at(args.p.at(i)) = i;
    }
    FORA(id, args.ids) {
      ll target = cur.at(id);
      if (target == id) {
        continue;
      }
      if (args.a.at(id) <= args.b.at(args.p.at(id))) {
        ok = false;
        return;
      }
      if (args.a.at(target) <= args.b.at(args.p.at(target))) {
        ok = false;
        return;
      }
      ans.push_back({id + 1, target + 1});
      swap(args.p.at(id), args.p.at(target));
      cur.at(args.p.at(id)) = id;
      cur.at(args.p.at(target)) = target;
    }
  }

  void output() {
    if (!ok) {
      pr(-1);
      return;
    }
    pr(ans.size());
    FORA(p, ans) prp(p);
  }
} s;

int main() {
  s.solve();
  s.output();
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (ll i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#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 ld=long double;
using vin=vector<int>;
using vvin=vector<vin>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vst=vector<string>;
using P = pair<ll,ll>;
using vp=vector<P>;
using vvp=vector<vp>;
const int inf=1e9+7;
const ll INF=9e18/2;
const long double PI = acosl(-1.0);
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
bool pair_comp(const pair<long,long> &A,const pair<long,long> &B){if(A.first==B.first)return A.second>B.second;return A.first<B.first;}//F昇→S降
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

ll dp[1<<19];//dp[s]:=前からsの時、条件を満たす数

int main(){//cout<<fixed<<setprecision(20);
  ll n,m;
  cin>>n>>m;
  vll x(m),y(m),z(m);
  rep(i,0,m){
    cin>>x[i]>>y[i]>>z[i];
    y[i]--;
  }
  dp[0]=1;
  rep(i,1,1<<n){
    int t=__builtin_popcount(i);
    vin sum(n,0);//sum[j]:=j以下の総数
    rep(j,0,n)if(i&(1<<j))sum[j]++;
    rep(j,1,n)sum[j]+=sum[j-1];

    rep(j,0,n){
      if(!(i&(1<<j)))continue;
      bool ok=true;
      rep(k,0,m){
        if(x[k]<t)continue;
        if(sum[y[k]]>z[k]){
         ok=false;
          break;
        }
      }
      if(ok)dp[i]+=dp[i&(~(1<<j))];
    }
  }
  cout<<dp[(1<<n)-1]<<endl;
}


/*
@Author
   Sujeet Kushwaha
*/

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

#define ll long long int
#define fast ios_base::sync_with_stdio(false)
#define fast_input cin.tie(NULL)
#define fast_output cout.tie(NULL)
#define vi vector<long long int>
#define vp vector<pair<long long int ,long long int>>
#define pb push_back
#define mp make_pair
#define pp pop_back
#define iter vector<int>::iterator
#define pa pair<long long int ,long long int>
#define f(a,b) for(int a=0;a<b;a++)
#define mod 1000000007
#define F first
#define S second
#define sett set<long long int>
#define um unordered_map<ll,ll>
#define ordered_set tree<pa, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// ll mul(ll a,ll b)
// {
// 	return (a%mod*b%mod)%mod;
// }
// ll add(ll a,ll b)
// {
// 	ll res=a+b;
// 	if(res>=mod)
// 	{
//       res-=mod;
// 	}
// 	return res;
// }
// ll sub(ll a,ll b)
// {
// 	ll res=a-b;
// 	if(res<0)
// 	 res+=mod;
// 	return res;
// }
// ll powmod(ll a, ll b)
// {
//     ll res = 1;
//     while (b) {
//         if (b&1) {
//             res =mul(res,a);
//         }
//         b >>= 1;
//         a=mul(a,a);
//     }

//     return res;
// }

// ll modinv(ll a)
// {
//     return powmod(a, mod - 2);
// }
//  unordered_map<ll,ll>facti;
//  ll fact(ll n)
//  {
// 	if(n==0)return 1;
// 	if(n<=1)return 1;
// 	if(facti[n]!=0)return facti[n];
// 	return facti[n]=mul(n,fact(n-1));
//  }
//   ll ncr(ll n,ll r)
//   {
//         ll h=fact(n);
// 	ll v=fact(r);
// 	ll j=fact(n-r);
// 	v=mul(v,j);
// 	v=powmod(v,mod-2);
// 	return mul(h,v);
//  }
// int fastread(){
//     int x=0;
//     int c = getchar_unlocked();
//     while(c<48)
//         c = getchar_unlocked();
//     while(c>=48){
//         x = x*10 + (c - 48);
//         c = getchar_unlocked();
//     }
//     return x;
// }
// bool comp(pa a,pa b)
// {
//     if(a.F==b.F)
//     {
//         return v[a.S]<v[b.S];
//     }
//     returna.S<b.S;
// }

const int N = 2e5 + 10;
vector<pa>g[N];
ll dp[N];
void dfs(ll v,ll par=-1)
{
        for(pa d:g[v])
        {
                if(d.first-par)
                {
                      dp[d.first]=dp[v]^d.second;
                      dfs(d.first,v);
                }
        }
}
void solve()
{
    ll n;
    cin>>n;
    f(i,n-1)
    {
            ll x,y,w;
            cin>>x>>y>>w;
            x--,y--;
            g[x].pb({y,w});
            g[y].pb({x,w});
    }
    dfs(0);
    ll ans=0;
    f(j,60)
    {
            ll ones,zeros;
            ones=zeros=0;
            f(i,n)
            {
                    if(dp[i]&(1ll<<j))
                    {
                            ones++;
                    }
                    else
                    {
                            zeros++;
                    }
            }
            zeros*=ones;
            zeros%=mod;
            ans+=((1ll<<j)%mod*zeros%mod);
            ans%=mod;
    }
    cout<<ans<<endl;
}
int main() {
	fast;
	fast_input;
	fast_output;
	// ll t;
	// cin>>t;
	// while(t--)
	// {
	  solve();
	// }
	return 0;
}

#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include <stack>
#include <random>
#include <iomanip>

#include <fstream>

using namespace std;
typedef long long ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E18;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
dd EPS=1E-9;
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

struct Ni{
    ll w,v;
    ll flag;
};
bool comp(Ni x, Ni y){
    if(x.v>y.v){
        return true;
    }else if(x.v<y.v){
        return false;
    }
    return x.w<y.w;
}

int main(){fastio
    ll n,m,q;cin>>n>>m>>q;
    ll w[n+1],v[n+1];
    Ni ni[n+1];
    rep(i,1,n){
        cin>>w[i]>>v[i];
        ni[i].w=w[i];
        ni[i].v=v[i];
        ni[i].flag=i;
    }
    sort(ni+1,ni+(n+1),comp);
    ll x[m+1];
    rep(i,1,m){
        cin>>x[i];
    }
    rep(qi,1,q){
        ll l,r;cin>>l>>r;
        bool valid[m+1];rep(i,1,m)valid[i]=true;
        rep(i,l,r){
            valid[i]=false;
        }
        ll res=0;
        rep(i,1,n){
            ll now=0;
            rep(j,1,m){
                if(!valid[j])continue;
                if(x[j] < ni[i].w)continue;
                if(now!=0 && x[now] <= x[j])continue;
                now=j;
            }
            if(now==0)continue;
            res += ni[i].v;
            valid[now] = false;
        }
        cout<<res<<endl;

    }

    return 0;

}


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

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

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define forr(i,n) for(int i=0;i<n;i++)
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define pb push_back
//#define mp make_pair
#define endl '\n'
#define ce(ele) cout<<ele<<' '
#define CASE(t) ll t; cin>>t; while(t--)
#define sor(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define vi vector<ll>
#define cs(ele) cout<<ele<<'\n'
#define pii pair<ll,ll>
#define MAXN   100001
#define all(d) d.begin(),d.end()
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
const ll mod=1e9 +7;
//const ll mod=998244353;
//ll Mod(ll n){return ((n%mod)+mod)%mod;}
//ll power(ll x,ll y){ll res=1;x=x;while(y>0){if(y&1)res=mod(res*x);x=mod(x*x);y=mod(y>>1);}return mod(res);}

void fast(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

}
ll f[200005];
ll invfact[200005];
ll power(ll x,ll y){
     ll res=1;
     while(y>0){
         if(y&1){
             res=(res*x)%mod;
         }
         x=(x*x)%mod;
         y>>=1;
    }
    return res;
}
void precal(){
    f[0]=1;
    invfact[0]=1;
    for(int i=1;i<200005;i++){
        f[i]=(f[i-1]*i)%mod;
        invfact[i]=power(f[i],mod-2);
    }
}
ll ncr(ll n,ll k){
    if(n<k||n<0||k<0){
        return 0;
    }
    return ((f[n]*invfact[k])%mod*invfact[n-k])%mod;
}

bool prime[10000011];
void primenumbers(ll n)
{

    memset(prime, true, sizeof(prime));

    for (ll p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (ll i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }

}

ll modI(ll a, ll m)
{
    ll m0=m,y=0,x=1;
    if(m==1) return 0;
    while(a>1)
    {
        ll q=a/m;
        ll t=m;
        m=a%m;
        a=t;
        t=y;
        y=x-q*y;
        x=t;
    }
    if(x<0) x+=m0;
    return x;
}
int spf[MAXN];

void sieve()
{
    spf[1] = 1;
    for (int i=2; i<MAXN; i++)

        spf[i] = i;

    for (int i=4; i<MAXN; i+=2)
        spf[i] = 2;

    for (int i=3; i*i<MAXN; i++)
    {
        if (spf[i] == i)
        {
            for (int j=i*i; j<MAXN; j+=i)

                if (spf[j]==j)
                    spf[j] = i;
        }
    }
}
vector<int> getFactorization(int x)
{
    vector<int> ret;
    while (x != 1)
    {
        ret.push_back(spf[x]);
        x = x / spf[x];
    }
    return ret;
}
bool isSubsetSum(vi s, int n, int sum)
{
    bool subset[n + 1][sum + 1];

    for (int i = 0; i <= n; i++)
        subset[i][0] = true;

    for (int i = 1; i <= sum; i++)
        subset[0][i] = false;

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= sum; j++) {
            if (j < s[i - 1])
                subset[i][j] = subset[i - 1][j];
            if (j >= s[i - 1])
                subset[i][j] = subset[i - 1][j]
                               || subset[i - 1][j - s[i - 1]];
        }
    }

    return subset[n][sum];
}
//------------------------------------------------------------------------------------

void solve(){
  ll a,b,c;
  cin>>a>>b>>c;
  cout<<21-a-b-c;

}

int main() {
 fast();
   // CASE(t)
    solve();

}


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

int inf = 1001001001;
ll INF = 1001001001001001001;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define rep(i, n) FOR(i, 0, n)
#define all(x) x.begin(), x.end()
#define pb push_back
#define pf push_front
ll MOD = 1000000007;
using P = pair<ll, ll>;

struct UnionFind{
    vector<int> par;

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

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

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        par[x] = y;

    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

};

int main() {
    ll N, M;cin >> N >> M;
    vector<ll> A(N), B(N);
    UnionFind tree(N);
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];
    rep(i, M) {
        int c, d;cin >> c >> d;
        c--;d--;
        tree.unite(c, d);

    }
    ll count[N];
    rep(i, N) count[i] = 0;
    rep(i, N) {
        count[tree.find(i)] += B[i]-A[i];

    }
    bool can = true;
    rep(i, N) {
        if (count[i]!=0) {
            can = false;
            break;
        }
    }
    if (can) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=200005;
int n,m,k,a[N],b[N],c[N],sa[N],sb[N];
vector<int>e[N];
void dfs(int u)
{
	sa[c[u]]+=a[u];
	sb[c[u]]+=b[u];
	for(auto v:e[u])
	{
		if(!c[v])
		{
			c[v]=c[u];
			dfs(v);
		}
	}
}
signed main()
{
	ios::sync_with_stdio(false);
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++)
		cin>>b[i];
	for(int i=1;i<=m;i++)
	{
		int u,v;
		cin>>u>>v;
		e[u].push_back(v);
		e[v].push_back(u);
	}
	for(int i=1;i<=n;i++)
	{
		if(!c[i])
		{
			k++;
			c[i]=k;
			dfs(i);
			if(sa[k]!=sb[k])
			{
				cout<<"No"<<endl;
				return 0;
			}
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}


#include <math.h>
#include <assert.h>

#include <vector>
#include <numeric>
#include <iostream>
#include <algorithm>
#include <functional>

template <typename T1, typename T2>
std::istream& operator>>(std::istream& is, std::pair<T1, T2>& v) {
    return is >> v.first >> v.second;
}

template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& v) {
    for (T& i: v) {
        is >> i;
    }
    return is;
}

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& v) {
    return os << v.first << " " << v.second;
}

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

template <typename X>
void in(X& x) {
    std::cin >> x;
}

template <typename X, typename Y>
void in(X& x, Y& y) {
    in(x); in(y);
}

template <typename X, typename Y, typename Z>
void in(X& x, Y& y, Z& z) {
    in(x); in(y, z);
}

template <typename X, typename Y, typename Z, typename W>
void in(X& x, Y& y, Z& z, W& w) {
    in(x); in(y, z, w);
}

template <typename T>
void out(const T H) {
    std::cout << (H);
}

template <typename T1, typename... T2>
void out(const T1 H, const T2... T) {
    std::cout << (H) << " "; out(T...);
}

template <typename T>
void eout(const char *s, const T H) {
    std::cerr << s << "=" << H << "\n";
}

template <typename T1, typename... T2>
void eout(const char *s, const T1 H, const T2... T) {
    while (*s != ',') std::cerr << *s++;
    std::cerr << "=" << H << " | "; eout(++s, T...);
}

#define nl                std::cout << "\n"

#ifdef LOCAL
#define err(args...)      eout(#args, args)
#else
#define err(args...)      42
#endif

#define rep(i, n)         for (int i =  0 ; i < (n); ++i)
#define per(i, n)         for (int i = (n) - 1; i > -1; --i)
#define repr(i, l, r)     for (int i = (l); i < (r); ++i)

#define sz(v)             ((int) v.size())
#define all(v)            (v).begin(), (v).end()
#define lla(v)            (v).rbegin(), (v).rend()

#define no                std::cout << "NO\n"
#define yes               std::cout << "YES\n"

const int INF           = 2147483647;
const long long int LNF = 9223372036854775807LL;

using ll  = long long int;
using vl  = std::vector<ll>;
using vi  = std::vector<int>;
using vb  = std::vector<bool>;
using ii  = std::pair<int, int>;
using iii = std::pair< ii, int>;
using vii = std::vector<ii>;

const int N  = 505050;
const int MD = 998244353;

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

    //int t; in(t); repr(tc, 1, t + 1)
    solve();

    return 0;
}

int f(int a) {
    return (ll) a*(a+1)/2 % MD;
}

int solve() {
    int a, b, c;
    in(a, b, c);
    err(a, b, c);
    out(((ll) f(a)*f(b) % MD)*f(c) % MD);
    return 0;
}

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int MOD=998244353;
signed main() {
	int a,b,c;
	cin>>a>>b>>c;
	int A=a*(a+1)/2,B=b*(b+1)/2,C=c*(c+1)/2;
	A%=MOD,B%=MOD,C%=MOD;
	cout<<((A*B)%MOD*C)%MOD;

	return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
//#define int long long
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PI = pair<pair<int,int>,int>;
using PL = pair<long long, long long>;
using PLL = pair<pair<long long, long long>, long long>;
using Pxy = pair<double, double>;
using Tiib = tuple<int, int, bool>;
const int INF = 1001001007;
const long long mod = 1000000007LL;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

void yes(){
    cout << "Yes" << endl;
}

void no (){
    cout << "No" << endl;
}

ll cel (ll a, ll b){
    if (a % b == 0) return a / b;
    else return a / b + 1;
}

ll gcds(ll a, ll b){
    ll c = a % b;
    while (c != 0){
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}

int main(){
    int n, mm; cin >> n >> mm;
    int m = abs(mm);
    if (n == 1) {cout << 1 << " " << 2 << endl; return 0;}
    if (n - m <= 1 || mm < 0) {cout << -1 << endl; return 0;}
    vector<P> ans;
    if (mm > 0){
        ans.emplace_back(P(1,1 + 2 * (m+1)));
        rep(i,m){
            ans.emplace_back(P(2+i*2,3+i*2));
        }
        ans.emplace_back(P(2+m*2,4+m*2));
        rep(i,n-m-2){
            ans.emplace_back(P(3 + 2*(m+1) + i*2, 4 + 2*(m+1) + i*2));
        }
        rep(i,n) cout << ans[i].first << " " << ans[i].second << endl;
    }
    else {
        rep(i,n){
            cout << 1 + 2 * i << " " << 2 + 2 * i << endl;
        }
    }
}

#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define ch() getchar()
#define pc(x) putchar(x)
template<typename T>inline void read(T&x){
	int f;char c;
	for(f=1,c=ch();c<'0'||c>'9';c=ch())if(c=='-')f=-f;
	for(x=0;c<='9'&&c>='0';c=ch())x=x*10+(c&15);x*=f;
}
template<typename T>inline void write(T x){
	static char q[64];int cnt=0;
	if(!x)pc('0');if(x<0)pc('-'),x=-x;
	while(x)q[cnt++]=x%10+'0',x/=10;
	while(cnt--)pc(q[cnt]);
}
int main(){
	int n,m;read(n),read(m);
	if(n==1&&m==0)puts("1 2");
	else if(m>n-2||m<0)puts("-1");
	else if(m==0){
		for(int i=1;i<=n;++i)
			write(i),pc(' '),write(i+n),pc('\n');
	}
	else{
		const int Base=300000;
		for(int i=1;i<=m+1;++i)
			write(i*2-1+Base),pc(' '),write(i*2+Base),pc('\n');
		int l=0,r=(m+1)*2+1;
		for(int i=m+2;i<=n;++i)
			write((l--)+Base),pc(' '),write((r++)+Base),pc('\n');
	}
	return 0;
}


#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define eps (double)(1e-9)
#define pi (double) acos(-1)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

#define P pair<ll, ll>

random_device rnd;
mt19937 mt(rnd());
uniform_int_distribution<> rand100(0, mod);
int rand_int(int l, int u){
    return l + rand100(mt) % (u-l+1);
}

struct edge{
    ll to, cost, cnt;
};
using Graph = vector<vector<edge>>;
Graph G(30*30);
vector<ll> prv;
vector<ll> dis;

vector<string> anss;

void dijkstra(int s){
    int N = G.size();
    priority_queue<P, vector<P>, greater<P>> pq;
    dis.resize(N);
    prv.resize(N);
    rep(i, N)dis[i] = inf;
  	rep(i, N)prv[i] = -1;
  	dis[s] = 0;
    pq.emplace(dis[s], s);
    while(!pq.empty()){
        P p = pq.top();
        pq.pop();
        int v = p.second;
        if(dis[v] < p.first)continue;
        for(auto &e : G[v]){
            ll now = e.cost;
            if(e.cnt != -1)now = (e.cost + e.cnt - 1) / e.cnt;
            if(dis[e.to] > dis[v] + now){
                dis[e.to] = dis[v] + now;
                prv[e.to] = v;
                pq.emplace(dis[e.to], e.to);
            }
        }
    }
}

map<pair<int, int>, string> mp;
string get_path(int t) {
    vector<int> path;
    for (int cur = t; cur != -1; cur = prv[cur]) {
        path.push_back(cur);
    }
    reverse(path.begin(), path.end());
    string ret;
    REP(i, path.size()-1){
        if(path[i]-path[i-1] == 1)ret += "R";
        else if(path[i]-path[i-1] == -1)ret += "L";
        else if(path[i]-path[i-1] == 30)ret += "D";
        else if(path[i]-path[i-1] == -30)ret += "U";
        else ret += mp[{path[i-1], path[i]}];
    }
    return ret;
}

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

void solve(){
    rep(x, 30)rep(y, 30){
        rep(i, 4){
            int nx = x + dx[i];
            int ny = y + dy[i];
            if(nx < 0 || nx >= 30 || ny < 0 || ny >= 30)continue;
            G[x*30+y].push_back({nx*30+ny, 3000, -1});
        }
    }
    rep(_, 1000){
        int si, sj, ti, tj;
        cin >> si >> sj >> ti >> tj;
        dijkstra(si*30+sj);
        string path = get_path(ti*30+tj);
        cout << get_path(ti*30+tj) << endl;

        //anss.push_back(get_path(ti*30+tj));

        int ans;
        cin >> ans;

        //double now; cin >> now;

        int x = si, y = sj;
        int s = path.size();
        rep(i, path.size()){
            int nx = x, ny = y;
            if(path[i] == 'U')nx--;
            if(path[i] == 'D')nx++;
            if(path[i] == 'L')ny--;
            if(path[i] == 'R')ny++;
            int idx = -1;
            rep(j, G[x*30+y].size())if(G[x*30+y][j].to == nx*30+ny)idx = j;
            if(G[x*30+y][idx].cnt == -1){
                G[x*30+y][idx].cnt = 0;
                G[x*30+y][idx].cost = 0;
            }
            assert(s <= 60);
            G[x*30+y][idx].cnt += max(0, 3601 - s*s);
            G[x*30+y][idx].cost += ans/s * max(0, 3601 - s*s);
          	x = nx; y = ny;
        }
    }
}

int main(){
    solve();
    //for(auto s : anss)cout << s << endl;
}

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

//---------------- 定数 ----------------

// [X_MIN, X_MAX], [Y_MIN, Y_MAX]
#define X_MIN 0
#define X_MAX 29
#define Y_MIN 0
#define Y_MAX 29

#define QUERY 1000

// -------- util function --------

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

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

// 座標(y, x)を扱うクラス
struct Point{
	int x, y;

	//Point(int y, int x): x(x), y(y);
};

struct Query{
	Point start, end;
	string ans;

	// クエリを開始する処理
	void init(){
		cin >> start.y >> start.x >> end.y >> end.x;
	}

	// クエリの答えを出力する処理
	void submit(){
		int point;
		cout << ans << endl;
		cin >> point;
		return;
	}

	void solve(){
		Point now = start;

		int flag = -1;
		if(flag == -1) flag = rand_int() % 2;
		while(now.y != end.y || now.x != end.x){
			if(now.y == end.y) flag = 1;
			if(now.x == end.x) flag = 0;

			if(flag == 0){
				if(now.y < end.y){
					ans.push_back('D');
					now.y++;
				}else{
					ans.push_back('U');
					now.y--;
				}
			}else{
				if(now.x < end.x){
					ans.push_back('R');
					now.x++;
				}else{
					ans.push_back('L');
					now.x--;
				}
			}
		}
	}
};

int main(){
	for(int q = 0;q < QUERY;q++){
		Query query;
		query.init();
		query.solve();
		query.submit();
	}
	return 0;
}


#include <string>
#include <iostream>
#include <stack>
#include <queue> // priority_queue も入ってる
#include <set>   // 要素数は size() で取得 multisetもある
#include <map>
#include <array> // sizeはコンパイル時定数で固定
#include <vector>
#include <numeric>   // accumulate, gcd
#include <algorithm> // count_ifに必要
#include <iomanip>   // cout << setprecision(15) << x で小数の出力精度を指定
#include <tuple>
#include <utility> //pair
#include <cmath>
#include <random>

using namespace std;
using ll = long long;

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

int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> b(n);
    vector<ll> p(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    rep(i, n) cin >> p[i];
    rep(i, n) p[i]--;
    vector<ll> q(n);
    rep(i, n)
    {
        q[p[i]] = i;
    }
    vector<pair<ll, ll>> answer;
    vector<pair<ll, ll>> people;
    rep(i, n) people.push_back(pair<ll, ll>{a[i], i});
    sort(people.begin(), people.end());
    rep(i, n)
    {
        if (people[i].second != p[people[i].second])
        {
            // 注目してる人の番号(Aさん)
            ll person = people[i].second;
            // Aさんが持ってる荷物の番号
            ll nimotsu = p[person];
            // 「Aさんが持つべき荷物」を持ってる人(Bさん)の番号
            ll aite = q[person];
            // Bさんが持っている荷物の番号
            ll nimotsuB = p[aite];
            if (a[person] <= b[nimotsu])
            {
                cout << -1 << endl;
                return 0;
            }
            // AさんとBさんの荷物を入れ替える

            answer.push_back(pair<ll, ll>{person, aite});
            ll temp = p[person]; // ==nimotsu
            p[person] = p[aite]; // ==person
            p[aite] = temp;      // ==nimotsu
            ll temp2 = q[nimotsu];
            q[nimotsu] = q[nimotsuB];
            q[nimotsuB] = temp2;
        }
    }

    cout << answer.size() << endl;
    for (pair<ll, ll> z : answer)
    {
        cout << z.first + 1 << ' ' << z.second + 1 << endl;
    }
    return 0;
}

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

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

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

typedef long long ll;

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

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

ll binary_search(function<bool(ll)> func, ll start, ll end) {
    /*      func:int ->bool
            returns smallest int x where func(x) evaluates to true, searches in [start,end), it is assumed the values are false, .. , false, true ...
             */
    if (end <= start) {   return end;  }   // has to be here, otherwise func(end-1) in next line could be a problem
    if (!func(end-1)) {  return end;  }
    while (end-start>1) {
        ll mid = (start+end)/2;
        if (func(mid)) {  end = mid;  } else { start = mid;   }
    }
    if (func(start)) {  return start;  } else {  return end;   }
};

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

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

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

    cout.precision(12);

//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readll(a); readll(b); readll(c); readll(d);
        if (b>=c*d) {
            cout << -1 << endl;
            continue;
        }

        cout << binary_search([a,b,c,d](ll x) {
            return a+b*x<=d*c*x;
        }, 0, 10+a/(d*c-b)) << endl;

    }

    return 0;
}


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

vector<int>read_array(int n){
    vector<int>a(n);
    for(int i = 0; i < n; i++)cin >> a[i];
    return a;
}

void test_case(){
    int n;
    cin >> n;
    int tax = (double)1.08 * n;
    if(tax < 206){
        cout << "Yay!" << endl;
    }else if(tax == 206){
        cout << "so-so" << endl;
    }else{
        cout << ":(" << endl;
    }
}

int main(){
    test_case();
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
void solveA() {
	  int n;
        cin>>n;
        int tax=1.08*n;
        if(tax<206) cout<<"Yay!"<<endl;
        else if(tax==206) cout<<"so-so"<<endl;
        else cout<<":("<<endl;
}
ll Nat(ll n) {
	return (n*(n+1))/2;
}
void solveB() {
    ll n;
     cin>>n;
      ll z=n*2;
      ll sq=(ll)sqrt(z);
      while(Nat(sq)<n) {
      	  sq++;
      }
      cout<<sq<<endl;
}
void solveC() {
	int n;
	 cin>>n;
	 unordered_map<ll,ll> mp;
	 ll val,ans=0;
	 for(int i=1; i<=n; i++) {
	 	   cin>>val;
	 	   mp[val]++;
	 	   ans+=(i-mp[val]);
	 }
	 cout<<ans<<endl;
}
int main() {
    solveA();
    return 0;
}


#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>
#include <cassert>
#include <random>
#include <chrono>

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

void debug_out(){ cout << "\n"; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#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 IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
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 int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const ll MOD = 1000000007;
/* const ll MOD = 998244353; */
const ll INF = (1<<30)-1;
const ll INFLL = 1ll<<60;
const double PI = acos(-1);

struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

signed main() {
  int sx, sy, gx, gy;
  cin >> sx >> sy >> gx >> gy;

  if(sx == gx) cout << sx << "\n";
  else{
    int x = gx-sx;
    int y = sy+gy;

    ld t = (ld)x/y;
    cout << t*sy+sx << "\n";
  }

  return 0;
}

#include <stdio.h>
int main()
{
	double sx,sy,gx,gy;
	double a, b, ans;
	scanf("%lf %lf %lf %lf", &sx, &sy, &gx, &gy);

	a = -((gy + sy) / (gx - sx));
	b = sy - a * sx;
	ans = -b / a;

	printf("%lf", ans);
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define pll pair<ll,ll>
#define vll vector<long long>
#define f first
#define s second
long long mod = 1e9+7;
typedef vector<map<char,int>> vmci;

int diry[] = {-1,-1,-1,0,0,1,1,1};
int dirx[] = {-1,0,1,-1,1,-1,0,1};

ll pow(ll x, ll y, ll p) {
    ll res = 1;
    x %= p;
    if(x == 0) {
        return 0;
    }
    while(y > 0) {
        if(y & 1) {
            res = (res * x) % p;
        }
        y >>= 1;
        x = (x * x) % p;
    }
    return res;
}

long long int power(int base, int exp)
{
    if (exp == 0)
       return 1;
    else if (exp == 1)
       return base;
    else
    {
       long long int calc;
       if (exp % 2 == 0)
       {
         calc = power(base, exp/2);
         calc *= calc;
       }
       else
       {
         calc = base*power(base, exp-1);
       }
       return calc;
    }
}

void seg_sieve(ll max,ll arr[]){
    ll i,j;
    for(i=2;i*i<=max;i++){
        if(arr[i]==0){
            for(j=i*i;j<=max;j+=i)
                arr[j]=1;
        }
    }
}

float distance(int x,int y,int a,int b){
    return sqrt(pow(x-a,2) + pow(y-b,2));
}

struct noob{
    int l,r,ind;
    noob(){
        l=-1,r=-1,ind=-1;
    }
    noob(int a,int b,int c){
        l=a,r=b,ind=c;
    }
};

bool comp1(noob &a,noob &b){
    return a.l<b.l;
}
bool comp2(pll &a,pll &b){
    return a.first>b.first;
}
bool isPrime(ll n)
{
    // Corner cases
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;

    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (ll i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    // cin>>t;
    int ulti=1;
    while(t--){
        int n,x; cin>>n>>x;
        string arr; cin>>arr;
        for(int i=0;i<n;i++){
            if(arr[i]=='x' and x>0) x--;
            else if(arr[i]=='o') x++;
        }
        cout<<x;
    }

}

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

int main()
{
	int size, intial = 0;
	char s;
	cin >> size >> intial;
	for (int i = 0;i < size;i++)
	{
		cin >> s;
		if (s == 'o')
		{
			intial++;
		}
		else if (s == 'x')
		{
			if (intial != 0)
			{
				intial--;
			}
		}
	}
	cout << intial << endl;
	return 0;
}


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

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

VL dvsr(LL n){VL ret;for(LL i=1;i*i<=n;++i){if(n%i==0){ret.PB(i);if(i*i!=n)ret.PB(n/i);}}SORT(ret);return ret;}

int main(){
    FAST;
    LL i,ans=0,N;
    cin>>N;
    VL v=dvsr(N);
    for(LL z:v){
        if(z&1)ans+=2;
        //if(z%2==0&&)
    }
    cout<<ans<<endl;
}

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define _USE_MATH_DEFINES
#define _MATH_DEFINES_DEFINED
using namespace __gnu_pbds;
using namespace std;
template<class T> using oset =tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define ll long long int
#define pb push_back
#define eb emplace_back
#define rep(i , j , n) for(ll i = j ; i < n ; i++)
#define pre(i , j , n) for(ll i = j ; i >= n ; i--)
#define all(x) x.begin(), x.end()
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vll;
typedef vector<double>	vd;
typedef vector<bool>	vb;
typedef pair<ll,ll> 	pll;
typedef vector<vector<ll>> vvll;
#define M_PI       3.14159265358979323846
#define br "\n"
#define ff first
#define ss second
#define debug(a...) cout<<#a<<": ";for(auto it:a)cout<<it<<" ";cout<<endl;
#define working cout << "Working till here" << endl;
#define MAXIM 1000101
const ll MAX = 2e5 + 1;
ll mod = 1e9 + 7;

void solve(){
    ll a,b;
    cin >> a >> b;
    if(a > b){
        ll s = 0;
        rep(i,1,a + 1){
            cout << i <<  " ";
            s += i;
        }
        rep(i,1,b){
            cout << -1*i << " ";
            s -= i;
        }
        cout << -1*s << " ";
    }
    else{
        ll s = 0;
        rep(i,1,b + 1){
            cout << -1*i <<  " ";
            s -= i;
        }
        rep(i,1,a){
            cout << i << " ";
            s += i;
        }
        cout << -1*s << " ";
    }
}

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

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

    ll t = 1;
    // cin >> t;
    rep(i,0,t){
        // cout << "Case #" << i + 1 << ": ";
        solve();
        // test();
    }
}


#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;
      cin>>n;
      string s[n];
      set<string> d;
      string ans;int flag=0;
      f(i,n)
      {
        cin>>s[i];
        if(s[i][0]!='!')d.insert(s[i]);
      }
      f(i,n)
      {

         if(s[i][0]=='!')
         {
          string y=s[i].substr(1);
          auto it=d.find(y);
          if(it!=d.end())
          {
            ans=y;flag=1;
          }
         }
      }
      if(flag)
      cout<<ans<<endl;
    else
      cout<<"satisfiable"<<endl;
  return 0;
}

#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>
#include<map>
#include<cassert>

using namespace std;

#define ll long long
#define reps(i, a, b) for(int i = a; i < b; i++)
#define rreps(i, a, b) for(int i = a-1; i >= b; i--)
#define rep(i, n) reps(i, 0, n)
#define rrep(i, n) rreps(i, n, 0)
#define P pair<int, int>
#define vec vector<int>
#define mat vector<vector<int> >

const ll mod = 1000000007;
const int INF = 1001001001;

int main(){
    int n;
    cin >> n;
    vec a(100001);
    a[1] = 1;
    reps(i, 2, 100001){
        for (int j = 2; j * j <= i; j++){
            if(i % j == 0){
                a[i] = a[i/j] + 1;
                break;
            }
        }
        if(a[i] == 0){
            a[i] = 2;
        }
    }
    reps(i, 1, n+1){
        cout << a[i] << " ";
    }cout << endl;
}


#include <bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int A[N];
int main()
{
	int n;
	cin>>n;

	for(int i=0; i<n; i++)
		cin>>A[i];
	int ans = 1<<30;

	for(int bit=0; bit< (1<<(n-1)); bit++)
	{
		int o = 0, x = 0;
		for(int j=0; j<n; j++)
		{
			o |= A[j];
			if(bit>>j & 1 || j == n-1)
				x ^= o, o = 0;
		}
		ans = min(ans, x);
	}
	cout<< ans <<endl;
}

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

#define pb push_back
#define mp make_pair
#define f1 first
#define s2 second

#define fastio ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(x) cerr << "[" << #x << "]: " << x << "\n";

using ll = long long;
using ld = long double;
using ii = pair<int, int>;
using pl = pair<ll, ll>;

ld const PI = 4*atan((ld)1);

template<int MOD = 998'244'353>
struct Mint
{
	int val;

	Mint() : val(0) {}
	Mint(ll _val) : val((int)(_val % MOD)) { if (val < 0) val += MOD; }

	Mint& operator+= (const Mint &rhs) { val += rhs.val; if (val >= MOD) val -= MOD; return *this; }
	Mint& operator-= (const Mint &rhs) { val -= rhs.val; if (val < 0) val += MOD; return *this; }
	Mint& operator*= (const Mint &rhs) { val = (int)((ll) val * rhs.val % MOD); return *this; }

	friend Mint fpow(Mint x, ll y)
	{
		Mint res = 1;
		for (; y > 0; y >>= 1, x *= x)
		{
			if (y & 1)
				res *= x;
		}
		return res;
	}
	friend Mint inverse(Mint x) { return fpow(x, MOD-2); }
	Mint& operator/= (const Mint &rhs) { return *this *= inverse(rhs); }

	friend Mint operator+ (Mint a, const Mint &b) { return a += b; }
	friend Mint operator- (Mint a, const Mint &b) { return a -= b; }
	friend Mint operator- (Mint a) { return 0 - a; }
	friend Mint operator* (Mint a, const Mint &b) { return a *= b; }
	friend Mint operator/ (Mint a, const Mint &b) { return a /= b; }
	friend ostream& operator<< (ostream &os, const Mint &a) { return os << a.val; }
	friend bool operator== (const Mint &a, const Mint &b) { return a.val == b.val; }
	friend bool operator!= (const Mint &a, const Mint &b) { return a.val != b.val; }
};

const int MAX = 107;

int n;
int w[MAX];
Mint<> dp[MAX][MAX * MAX]; //dp[a][b], pick a items such that the weigh sum is exactly b
Mint<> fact[MAX];

int main()
{
	fastio;

	fact[0] = 1;
	for (int i = 1; i < MAX; ++i)
		fact[i] = i * fact[i-1];

	cin >> n;

	int sum = 0;
	for (int i = 0; i < n; ++i)
		cin >> w[i], sum += w[i];

	if (sum & 1)
	{
		cout << 0 << '\n';
		return 0;
	}

	dp[0][0] = 1;
	for (int i = 0; i < n; ++i)
	{
		for (int a = n-1; a >= 0; --a)
		{
			for (int b = 10000; b >= 0; --b)
			{
				dp[a+1][b + w[i]] += dp[a][b];
			}
		}
	}

	Mint<> res = 0;
	for (int i = 1; i <= n; ++i)
	{
		res += dp[i][sum/2] * fact[i] * fact[n-i];
	}
	cout << res << '\n';

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
main()
{
   int a[3];
   cin>>a[0]>>a[1]>>a[2];
   sort(a,a+3);
   cout<<(a[2]+a[1]);
}

#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL<<60;
const long long MOD = 1000000007;

int main() {
    int a, b, c; cin >> a >> b >> c;
    vector<int> v;
    v.push_back(a);
    v.push_back(b);
    v.push_back(c);
    sort(ALL(v));
    cout << v[1] + v[2] << endl;
    return 0;
}


#define rep(i, n) for (int i = 0; i < n; i++)
#define All(a) a.begin(), a.end()
#define us unordered_set
#define eb emplace_back
#define pb push_back
#define ll long long
#define vt vector
#define mod 1000000007

#include <bits/stdc++.h>

using namespace std;

int main() {
    int n;
    cin >> n;
    vt<vt<int>> c(n, vt<int>(n));
    rep(i, n) rep(j, n) cin >> c[i][j];
    string ans = "Yes";
    int min_c = mod, min_i = 0;
    rep(i, n) {
        if (c[i][0] < min_c) {
            min_i = i;
            min_c = c[i][0];
        }
    }
    for (int i = 1; i < n; i++) {
        int dif = c[i][0] - c[i - 1][0];
        for (int j = 1; j < n; j++)
            if (c[i][j] - c[i - 1][j] != dif) ans = "No";
    }
    cout << ans << endl;
    if (ans == "No") return 0;
    rep(i, n) cout << c[i][0] - min_c << ' ';
    cout << endl;
    rep(i, n) cout << c[min_i][i] << ' ';
    cout << endl;
    return 0;
}

#include <bits/stdc++.h>
//#include <chrono>
//#pragma GCC optimize("O3")
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()

using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

ll N,M,H,W,Q,K,A,B;
string S;
using P = pair<ll, ll>;
const ll INF = (1LL<<60);

template<class T> bool chmin(T &a, const T b){
    if(a > b) {a = b; return true;}
    else return false;
}
template<class T> bool chmax(T &a, const T b){
    if(a < b) {a = b; return true;}
    else return false;
}
template<class T> void my_printv(std::vector<T> v,bool endline = true){
    if(!v.empty()){
        for(std::size_t i{}; i<v.size()-1; ++i) std::cout<<v[i]<<" ";
        std::cout<<v.back();
    }
    if(endline) std::cout<<std::endl;
}

void no(){
    cout<<"No"<<endl;
    exit(0);
}

void yes(vec &a, vec &b){
    cout<<"Yes"<<endl;
    my_printv(a);
    my_printv(b);
    exit(0);
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin>>N;
    if(N == 1){
        cin>>A;
        vec a(1, A), b(1, 0);
        yes(a, b);
    }
    mat c(N, vec(N));
    rep(i, N) rep(j, N) cin>>c[i][j];
    vec a(N), b(N);
    rep(i, N) a[i] = c[i][0];
    b[0] = 0;
    reps(j, 1, N){
        b[j] = c[0][j] - c[0][0];
        rep(i, N) {
            if (b[j] != c[i][j] - c[i][0]) no();
        }
    }
    ll minus = *min_element(ALL(b));
    rep(j, N) b[j] -= minus;
    minus = *min_element(ALL(a));
    rep(i, N) a[i] -= minus;
    ll d = c[0][0] - (a[0] + b[0]);
    if(d < 0) no();
    else {
        rep(i, N) a[i] += d;
        yes(a, b);
    }
}


#include <iostream>
#include <cmath>
#include <vector>
#include <cstdio>
#include <iomanip>
#include <algorithm>
#include <algorithm>

using namespace std;

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

	vector<pair<int,int>> cargos_base;
	for(int i=0;i<n;i++){
		int buf_w,buf_v;
		cin>>buf_w>>buf_v;
		std::pair<int,int> p = std::make_pair(buf_v,buf_w);
		cargos_base.push_back(p);
	}
	sort(cargos_base.begin(),cargos_base.end());

	vector<int> allBoxes;
	for(int i=0;i<m;i++){
		int buf_x;
		cin>>buf_x;
		allBoxes.push_back(buf_x);
	}

	for(int iq=0;iq<q;iq++){
		int l,r;
		cin>>l>>r;

		vector<int> boxes;
		//cout<<"usable : ";
		for(int i=0;i<l-1;i++){
			boxes.push_back(allBoxes[i]);
			//cout<<allBoxes[i]<<" ";
		}
		for(int i=r;i<m;i++){
			boxes.push_back(allBoxes[i]);
			//cout<<allBoxes[i]<<" ";
		}
		sort(boxes.begin(),boxes.end());

		vector<pair<int,int>> cargos(cargos_base);
		int shipped = 0;
		while(!boxes.empty() && !cargos.empty()){
			pair<int,int> cargo = cargos.back();
			cargos.pop_back();

			int value = cargo.first;
			int weight = cargo.second;

			for(auto ibox=boxes.begin();ibox!=boxes.end();ibox++){
				int size = *ibox;
				if(weight<=size){
					shipped+=value;
					boxes.erase(ibox);
					break;
				}
			}

		}

		cout<<shipped<<endl;

	}

	return 0;

}

#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define pii pair<ll,ll>
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define autoitr(x,it) for(auto it = x.rbegin(); it != x.rend(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

int main()
{
  FAST/**/

  ll n,m,q;
  cin>>n>>m>>q;

  pii arr[n];
  rep(n)
        cin>>arr[i].ff>>arr[i].ss, swap(arr[i].ff, arr[i].ss);
  sort(arr, arr+n);
  ll lim[m];
  rep(m)
        cin>>lim[i];

  rep(q)
  {
      ll l,r;
      cin>>l>>r;
      ll m1 = m - (r-l+1);
      multiset<ll> box;
      for(ll i=0;i<m;i++)
            if(i<l-1 || i>=r)
                box.insert(lim[i]);
      ll ans = 0;
      for(ll i=n-1;i>-1;i--)
      {
          auto it = box.lower_bound(arr[i].ss);
          if(it == box.end())
                continue;
          ans+=arr[i].ff;
          box.erase(it);
      }
      cout<<ans<<'\n';

  }

  return 0;
}


#include <bits/stdc++.h>

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

    int t;
    std::cin >> t;
    while (t--) {
        int n;
        std::cin >> n;
        std::vector<int> a(n);
        for (int i = 0; i < n; ++i) std::cin >> a[i];
        if (n % 2 == 1) {
            std::cout << "Second\n";
        } else {
            std::sort(a.begin(), a.end());
            bool win = false;
            for (int i = 0; i < n; i += 2) win |= a[i] != a[i + 1];
            std::cout << (win ? "First" : "Second") << "\n";
        }
    }

    return 0;
}

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

const long long int MOD = 998244353;

void solve() {
	int n; cin >> n;
  	vector<int> a(n);
  	long long int sum = 0;
  	for (int i = 0; i < n; i++) {
    	cin >> a[i];
      	sum += a[i];
    }

  	if (sum % 2) {
    	cout << 0;
      	return;
    }

    vector<long long int> f(n + 1, 1);
  	vector<vector<long long int>> dp(sum + 1, vector<long long int>(n + 1, 0));
  	dp[0][0] = 1;
    for (int i = 1; i <= n; i++)
        f[i] = f[i - 1] * i % MOD;

    for (int i = 0; i < n; i++) {
        for (int j = n; j > 0; j--) {
            for (int k = sum; k >= a[i]; k--) {
                dp[k][j] += dp[k - a[i]][j - 1];
                dp[k][j] %= MOD;
            }
        }
    }

    long long int ans = 0;
    for (int i = 0; i <= n; i++) {
        ans += dp[sum / 2][i] * f[i] % MOD * f[n - i] % MOD;
        ans %= MOD;
    }
    cout << ans;
}

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

	int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}


#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

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

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

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

int main()
{

	int a[4] = {0};
	for(int i=0;i<3;i++) cin >> a[i];
	sort(a+0,a+3);

	cout << a[2] + a[1];
}