#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#include<stack>
#include<iomanip>
#include<cmath>
#include<complex>
#include<math.h>
using namespace std;
#define pb push_back
#define ll long long int
# define pii pair<int ,int>
# define pll pair<ll,ll>
# define fio ios_base::sync_with_stdio(false); cin.tie(NULL)
# define ft first
# define sec second
//expected values is a*e0+b.
double a[100009]={0},b[100009]={0};
int h[100009];
int main()
{   cout<<fixed<<setprecision(9);
    int n,m,k;
    cin >>n >>m >>k;
    for(int i = 1 ; i <= k ; i++) {cin >>h[i]; a[h[i]]=1;b[h[i]]=0;}
    sort(h+1,h+k+1);
    a[n]=0;b[n]=0;
    for(int i = n-1; i>=0 ; i--)
    {
       if(a[i] != 1)
       {
           a[i] = (a[i+1]-a[min(i+m+1,n+1)])/m;
           b[i] = 1 + (b[i+1]-b[min(i+m+1,n+1)])/m;
       }
        a[i]+=a[i+1];
        b[i]+=b[i+1];
    }
    for(int i = 0 ; i <= n ; i++) {a[i]=a[i]-a[i+1]; b[i]=b[i]-b[i+1];}
    if( abs(a[0]-1) <= 0.000000001) cout<<"-1";
   else cout << b[0]/(1-a[0]);
}

/*
#pragma GCC optimize(2)
#pragma GCC optimize(3,"Ofast","inline")
*/
#include<bits/stdc++.h>
#define ALL(x) (x).begin(),(x).end()
#define ll long long
#define db long double
#define ull unsigned long long
#define pii_ pair<int,int>
#define mp_ make_pair
#define pb push_back
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define show1(a) cout<<#a<<" = "<<a<<endl
#define show2(a,b) cout<<#a<<" = "<<a<<"; "<<#b<<" = "<<b<<endl
using namespace std;
const ll INF = 1LL<<60;
const int inf = 1<<30;
const int maxn = 2e5+5;
inline void fastio() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}

int flag[maxn];
db f1[maxn],f2[maxn],suf1[maxn],suf2[maxn];

int main()
{
    //fastio();
    int n,m,k; scanf("%d%d%d",&n,&m,&k);

    rep(i,1,k){
        int x; scanf("%d",&x);
        flag[x] = 1;
    }
    per(i,n-1,0){
        if(flag[i]){
            f1[i] = 0;f2[i] = 1;
        }else{
            f1[i] = 1.0 + (suf1[i+1] - suf1[i+m+1]) / m;
            f2[i] = (suf2[i+1] - suf2[i+m+1]) / m;
        }//show2(f1[i],f2[i]);
        suf1[i] = f1[i] + suf1[i+1];
        suf2[i] = f2[i] + suf2[i+1];
    }
    db ans = f1[0] / (1 - f2[0]);
    //printf("%.4Lf\n",ans);
    if(ans > 1e13) cout << -1 << endl;
    else cout << fixed << setprecision(4) << ans << endl;
    return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int n, m;
vector<int> y[18], z[18];
int dp[19][1 << 18];
int bitCnt[1 << 18];

signed main() {
	int i, j, k;

	cin >> n >> m;

	rep(i, (1 << n)) {
		rep(j, n) {
			if ((i >> j) % 2) bitCnt[i]++;
		}
	}

	rep(i, m) {
		int x, cy, cz;
		cin >> x >> cy >> cz;
		y[x].push_back(cy);
		z[x].push_back(cz);
	}

	dp[0][0] = 1;
	rep(i, n) {
		rep(j, (1 << n)) {
			if (dp[i][j] == 0) continue;

			//判定
			rep(k, y[i].size()) {
				int bcnt = bitCnt[j & ((1 << y[i][k]) - 1)];
				if (bcnt > z[i][k]) break;
			}
			if (k < y[i].size()) continue;

			//遷移
			rep(k, n) {
				if ((j >> k) % 2) continue;
				dp[i + 1][j + (1 << k)] += dp[i][j];
			}
		}
	}

	cout << dp[n][(1 << n) - 1] << endl;
	return 0;
}

//12252024832524
#include <cstdio>
#include <cstring>
#include <algorithm>
#define TT template<typename T>
using namespace std;

typedef long long LL;
const int MAXN = 18;
const int MAXM = 105;
int n,m;
LL dp[1 << MAXN],pre[MAXN];

LL Read()
{
	LL x = 0,f = 1;char c = getchar();
	while(c > '9' || c < '0'){if(c == '-')f = -1;c = getchar();}
	while(c >= '0' && c <= '9'){x = (x*10) + (c^48);c = getchar();}
	return x * f;
}
TT void Put1(T x)
{
	if(x > 9) Put1(x/10);
	putchar(x%10^48);
}
TT void Put(T x,char c = -1)
{
	if(x < 0) putchar('-'),x = -x;
	Put1(x); if(c >= 0) putchar(c);
}
TT T Max(T x,T y){return x > y ? x : y;}
TT T Min(T x,T y){return x < y ? x : y;}
TT T Abs(T x){return x < 0 ? -x : x;}

struct node
{
    int x,y,z;
    bool operator < (const node &px)const{
        return x < px.x;
    }
}s[MAXM];

int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
    n = Read(); m = Read();
    int S = (1 << n) - 1;
    for(int i = 0;i < m;++ i) s[i].x = Read(),s[i].y = Read(),s[i].z = Read();
    for(int i = 1;i <= S;++ i)
    {
        int cnt = 0,dz = i;
        while(dz)
        {
            if(dz & 1) cnt++;
            dz >>= 1;
        }
        for(int j = 0;j < n;++ j) pre[j] = 0;
        for(int j = 0;j < n;++ j)
            if((i >> j) & 1) pre[j]++;
        for(int j = 1;j < n;++ j) pre[j] += pre[j-1];
        for(int j = 0;j < m;++ j)
        {
            if(s[j].x == cnt && pre[s[j].y-1] > s[j].z)
            {
                dp[i] = -1;
                break;
            }
        }
    }
    dp[0] = 1;
    for(int i = 1;i <= S;++ i)
    {
        if(dp[i] == -1) continue;
        for(int j = 0;j < n;++ j)
            if((i >> j) & 1)
                if(dp[i^(1<<j)] != -1)
                    dp[i] += dp[i^(1<<j)];
    }
    Put(Max(dp[S],0ll));
	return 0;
}


#include"bits/stdc++.h"

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<LL> PQ_DESC;
typedef priority_queue<LL, VL, greater<LL>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef priority_queue<VL> PQ_DESC_VL;
typedef priority_queue<VL, vector<VL>, greater<VL>> PQ_ASC_VL;
typedef priority_queue<PLL> PQ_DESC_PLL;
typedef priority_queue<PLL, vector<PLL>, greater<PLL>> PQ_ASC_PLL;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF*(LL)INF;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

void Main()
{
    LL n;cin>>n;
    string s;cin>>s;
    s = "X"+s;

    VL a(n+1);
    VL t(n+1);
    VL c(n+1);
    VL g(n+1);

    FOR(i,1,n+1){
        if(s[i] == 'A'){
            a[i]=1;
        }
        if(s[i] == 'T'){
            t[i]=1;
        }
        if(s[i] == 'C'){
            c[i]=1;
        }
        if(s[i] == 'G'){
            g[i]=1;
        }
        a[i] += a[i-1];
        t[i] += t[i-1];
        c[i] += c[i-1];
        g[i] += g[i-1];
    }

    LL result = 0;
    FOR(i,0,n){
        FOR(j,i+1,n+1){
            LL na = a[j]-a[i];
            LL nt = t[j]-t[i];
            LL nc = c[j]-c[i];
            LL ng = g[j]-g[i];
            if(na==nt && nc==ng){
                result ++;
                //cerr<<i<<" "<<j<<endl;
            }
        }
    }

    cout<<result<<endl;

	return;
}

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

/*
                    author         : TAPAN SAVANI
                    codeforces     : savanitapan2001
                    codechef       : savanitapan17
*/

/*
------------------------------------------------------------------------

░██╗░░░░░░░██╗░█████╗░██████╗░██╗░░██╗  ██╗░░██╗░█████╗░██████╗░██████╗░
░██║░░██╗░░██║██╔══██╗██╔══██╗██║░██╔╝  ██║░░██║██╔══██╗██╔══██╗██╔══██╗
░╚██╗████╗██╔╝██║░░██║██████╔╝█████═╝░  ███████║███████║██████╔╝██║░░██║
░░████╔═████║░██║░░██║██╔══██╗██╔═██╗░  ██╔══██║██╔══██║██╔══██╗██║░░██║
░░╚██╔╝░╚██╔╝░╚█████╔╝██║░░██║██║░╚██╗  ██║░░██║██║░░██║██║░░██║██████╔╝
░░░╚═╝░░░╚═╝░░░╚════╝░╚═╝░░╚═╝╚═╝░░╚═╝  ╚═╝░░╚═╝╚═╝░░╚═╝╚═╝░░╚═╝╚═════╝░

------------------------------------------------------------------------
*/

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

#define HAPPY_CODING              \
    ios_base::sync_with_stdio(0); \
    cin.tie(NULL);                \
    cout.tie(NULL);
#define pb push_back
#define mp make_pair
#define Debug(x) cout << #x " = " << (x) << endl
#define SORT(a) sort(a.begin(), a.end())
#define SORTR(a) sort(a.rbegin(), a.rend())
#define mod 1000000007
#define pi 3.141592653589793238
#define ll long long int
#define ull unsigned long long
#define be begin()
#define en end()
#define FOR(i, a, b) for (long long int i = a; i < b; i++)
#define FORI(i, a, b) for (int i = a; i >= b; i--)

typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
typedef pair<ll, ll> PL;
typedef vector<PI> VPI;

int main()
{
    HAPPY_CODING;

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

    cout << (a+b)/2 << " " << (a-b)/2 << "\n";

    return 0;
}


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

int digit_sum(int n) {
  if (n < 10) return n;
  return digit_sum(n/10) + n%10;
}

int main() {
  int a, b;
  cin >> a >> b;

  int sum_a = digit_sum(a), sum_b = digit_sum(b);
  if (sum_b <= sum_a) {
    cout << sum_a << endl;
  } else {
    cout << sum_b << endl;
  }

  return 0;
}

#define LOCAL

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

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

#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define LLINF 0x3f3f3f3f3f3f3f3f
#define INF 0x3f3f3f3f
#define uniq(x) sort(all(x)); x.resize(unique(all(x))-x.begin());
#define sz(x) (int)x.size()

// Copied from Gennady-Korotkevich's template

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
	return '"' + s + '"';
}

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

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

string to_string(vector<bool> v) {
	bool first = true;
	string res = "{";
	for (int i = 0; i < static_cast<int>(v.size()); i++) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(v[i]);
	}
	res += "}\n";
	return res;
}

template <size_t N>
string to_string(bitset<N> v) {
	string res = "";
	for (size_t i = 0; i < N; i++) {
		res += static_cast<char>('0' + v[i]);
	}
	return res;
}

template <typename A>
string to_string(A v) {
	bool first = true;
	string res = "{";
	for (const auto& x : v) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(x);
	}
	res += "}\n";
	return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
	return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

template <typename A, typename B, typename C, typename D, typename E>
string to_string(tuple<A, B, C, D, E> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + "," + to_string(get<4>(p)) + ")";
}

void debug_out() {
	cerr << endl;
}

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

#ifdef LOCAL
#define debug(...) cerr << "\n[" << #__VA_ARGS__ << "]:\n", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

// End of Gennady-Korotkevich's template

using pii = pair<int, int>;
using ll = long long;
const ll MOD = 1e9 + 7;
const long double PI = acos(-1.0);

void solve() {
	string a, b; cin >> a >> b;
	int sum1 = 0, sum2 = 0;
	for(char c : a)
		sum1 += c-'0';
	for(char c : b)
		sum2 += c-'0';
	cout << max(sum1,sum2);
}

int main() {
	IOS;
	int t = 1;
	while(t--)
		solve();
}


//#define _GLIBCXX_DEBUG
//#include "atcoder/all"
//using namespace atcoder;
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
#define Dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) (((n) >> (k)) & 1) /*nのk bit目*/
namespace mydef {
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
bool dbg = true;
}  // namespace mydef
using namespace mydef;
#define pb push_back
//#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define asn ans

void solve() {
}

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

    string A, B;
    cin >> A >> B;
    auto f = [](string s) {
        int ret = 0;
        for (int i = 0; i < 3; i++) {
            ret += s[i] - '0';
        }
        return ret;
    };
    cout << max(f(A), f(B)) << endl;

    solve();
    return 0;
}

#include <iostream>
#include <cmath>
using namespace std;
typedef unsigned long long ll;

ll check(string ip, ll base, ll m){
    ll ans =0;
    ll curr = 0;
    for(int i =ip.length()-1;i>=0;i--){
		if(ans<0 || pow(base,curr)>m) return m+1;

        ans+= (ll)((int)ip[i]-'0')*pow(base,curr);
        curr++;
        if(ans>m){
        	//cout<<"ans"<<ans<<endl;
        	return m+1;

        }
    }
    return ans;
}

int main ()
{
  string X;
  cin>>X;
  ll M;
  cin>>M;
  if(X.length()==1){
  	if(stoi(X)<=M) cout<<"1";
  	else cout<<"0";
  	return 0;
  }
  int mx =-1;
  for(char a: X){
      mx = max(mx,(int)a-'0');
  }
  ll low = mx+1, high = M;
  ll ans=mx;
  while(low<=high){
      ll mid = low + (high-low)/2;
      //cout<<"low:"<<low<<" mid:"<<mid<<" high:"<<high<<endl;
      //cout<<"check:"<<check(X,mid,M)<<endl;

      if(check(X,mid,M)<=M){
          low = mid+1;
          ans = max(ans,mid);
      }
      else{
          high = mid-1;
      }
  }
  //cout<<"ans:"<<ans<<" mx:"<<mx<<endl;
  cout<<max((ll)0,ans-mx);
  return 0;
}


/*/ Author: _Math.man /*/

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

/*/---------------------------Defines-----------------------------------------/*/

#pragma GCC optimize("Ofast")
#define int long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n; i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define endl '\n'
#define PI  3.14159265358979323846
#define MOD 1000000007
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
const int N = 2e6+5;
const int INF = 1e18L;
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
/*/-----------------------------Debug begins----------------------------------/*/
vector<string> split(const string& s, char c) {
    vector<string> v; stringstream ss(s); string x;
    while (getline(ss, x, c)) v.emplace_back(x); return move(v);
}
template<typename T, typename... Args>
inline string arrStr(T arr, int n) {
    stringstream s; s << "[";
    for(int i = 0; i < n - 1; i++) s << arr[i] << ",";
    if(n>0)
    s << arr[n - 1] ;
    s<< "]";
    return s.str();
}
#define trace(args...) {__trace_begin(__LINE__); __trace(split(#args, ',').begin(), args);}
inline void __trace_begin(int line) { cerr << "#" << line << ": "; }
template<typename T> inline void __trace_out_var(vector<T> val) { cerr << arrStr(val, val.size()); }
template<typename T> inline void __trace_out_var(T* val) { cerr << arrStr(val, 10); }
template<typename T> inline void __trace_out_var(T val) { cerr << val; }
inline void __trace(vector<string>::iterator it) { cerr << endl; }

template<typename T, typename... Args>
inline void __trace(vector<string>::iterator it, T a, Args... args) {
    cerr << it->substr((*it)[0] == ' ', it->length()) << "=";
    __trace_out_var(a);
    cerr << "; ";
    __trace(++it, args...);
}
/*/-----------------------------Code begins----------------------------------/*/
int ar[N];
int dp[N];
signed main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    IOS;
    int T=1;
    // cin >> T;
    while(T--){
    	int a,b,c,d;
    	cin >> a>>b>>c>>d;
    	cout << a*d -b*c;

    }
    return 0;
}

//Bismillahir Rahmanir Rahim
// Rabbana Afrig Alayna Sabrao Wa Taffaiyana Muslimin

#include<bits/stdc++.h>
using namespace std;
#define int long long int
int i,j,k;
 main()
 {

     int a,b,c,d;
     cin>>a>>b>>c>>d;
     cout<<a*d-b*c<<endl;

 }


#include <bits/stdc++.h>
using namespace std;
#define all(a)a.begin(),a.end()
#define rall(a)a.rbegin(),a.rend()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
const int mod2=998244353;
using P = pair<int,int>;
using Pl= pair<ll,ll>;
using ld=long double;
using V=vector<int>;
using Vl=vector<ll>;
using Vd=vector<ld>;
using VV=vector<vector<int>>;
using VVl=vector<vector<ll>>;
using VVd=vector<vector<ld>>;

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

//return (x,y,gcd(a,b)) s.t. ax+by=gcd(a,b)
pair<Pl,ll> extgcd(ll a,ll b){
    if(b==0)return {{1,0},a};
    else{
        auto res=extgcd(b,a%b);
        ll X=res.first.first;
        ll Y=res.first.second;
        ll g=res.second;
        //bX+(a%b)Y=g
        //a=a/b*b+a%b
        //bX+(-a/b*b+a)Y=g
        //aY+b(X-a/b*Y)=g
        return {{Y,X-a/b*Y},g};
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;cin  >>t;
//    int b=13;
//    for (int a = 1; a <= b; ++a) {
//        int ex=extgcd(a,b).first.first;
//        ex%=b;
//        if(ex<0)ex+=b;
//        if(a*ex%b!=1){
//            puts("NG");
//            cout <<a<<" "<<ex<<"\n";
//            return 0;
//        }
//    }
    while(t--){
        ll n,s,k;cin >>n>>s>>k;
        ll g=gcd(k,n);
        if(s%g!=0){
            cout <<-1<<"\n";
        }
        else{
            s/=g;
            k/=g;
            n/=g;
            ll x=extgcd(k,n).first.first;//k^-1(mod n)
//            cout <<x<<"\n";
            ll ans=-s*x;
            ans%=n;
            if(ans<0)ans+=n;
            cout <<ans<<"\n";
        }
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n;
  R n;
  ll x=1.08*n;
  if(x<206) pr("Yay!");
  else if(x>206) pr(":(");
  else pr("so-so");
}

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


#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

using namespace std;

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T> inline bool chmin(T &x, const T &y){ if(y < x){ x = y; return true; } return false; }
template <class T> inline bool chmax(T &x, const T &y){ if(x < y){ x = y; return true; } return false; }
template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}
template <class Con>
string concat(const Con &c, const string &spr){
	stringstream ss;
	typename Con::const_iterator it = c.begin(), en = c.end();
	bool fst = true;
	for(; it != en; ++it){
		if(!fst){ ss << spr; }
		fst = false;
		ss << *it;
	}
	return ss.str();
}

template <class Con, class Fun>
vector<typename Con::value_type> cfilter(const Con &c, Fun f) {
	vector<typename Con::value_type> ret;
	typename Con::const_iterator it = c.begin(), en = c.end();
	for(; it != en; ++it){
		if(f(*it)){
			ret.emplace_back(*it);
		}
	}
	return ret;
}
#if __cplusplus >= 201103L
template <class Con, class Fun>
auto cmap(const Con &c, Fun f) -> vector<decltype(f(*c.begin()))> {
	vector<decltype(f(*c.begin()))> ret;
	ret.reserve(c.size());
	for(const auto &x: c){
		ret.emplace_back(f(x));
	}
	return ret;
}
#endif

#if __cplusplus >= 201402L
#define lambda(e) ([&](const auto &_){ return (e); })
#define lambda2(e) ([&](const auto &_a, const auto &_b){ return (e); })
#endif

#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()
#define tget(t,i) get<i>(t)

#define MOD 1000000007LL
#define EPS 1e-8

VV(int) G;
VV(pii) qs;
vint ans;

deque<int> dfs(int u, int d){
	deque<int> ret = {1};
	for(int v : G[u]){
		auto r = dfs(v, d + 1);
		r.push_front(0);
		if(ret.size() < r.size()){ ret.swap(r); }
		for(size_t i = 0; i < r.size(); ++i){
			ret[i] += r[i];
		}
	}
	for(cauto p : qs[u]){
		int k = p.second - d;
		if(k < 0 || k >= (int)ret.size()){
			ans[p.first] = 0;
		}
		else{
			ans[p.first] = ret[k];
		}
	}
	return ret;
}

void mainmain(){
	int n;
	cin >> n;
	G.resize(n);
	for(int i = 1; i < n; ++i){
		int p;
		cin >> p;
		G[p - 1].push_back(i);
	}
	int q;
	cin >> q;
	ans.assign(q, -1);
	qs.resize(n);
	REP(i, q){
		int u, d;
		cin >> u >> d;
		qs[u - 1].emplace_back(i, d);
	}
	dfs(0, 0);
	for(int x : ans){ cout << x << '\n'; }
}

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

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()

const int MAX = 200000;

int N, Q;
vector<int> G[MAX + 1], qs[MAX + 1];
int depth[MAX + 1], in[MAX + 1], out[MAX + 1];

void dfs(int u, int p, int d, int& k) {
    in[u] = k++;
    depth[u] = d;
    qs[d].push_back(in[u]);
    for(int v : G[u]) {
        if(v == p) continue;
        dfs(v, u, d+1, k);
    }
    out[u] = k++;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N;
    REP(i, N-1) {
        int p;
        cin >> p; p--;
        G[p].push_back(i+1);
        G[i+1].push_back(p);
    }
    {
        int k = 0;
        dfs(0, -1, 0, k);
    }
    cin >> Q;
    while(Q--) {
        int u, d;
        cin >> u >> d;
        u--;
        int res = upper_bound(ALL(qs[d]), out[u]) - lower_bound(ALL(qs[d]), in[u]);
        cout << res << "\n";
    }
}


//红太阳zhouakngyang txdy!
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include<bits/stdc++.h>
#define Macesuted cout<<"kawaii"<<endl
#define MatrixCascade cout<<"npsl"<<endl
#define Karry5307 cout<<"nmsl"<<endl
using namespace std;
#define int long long
inline int read()
{
	int sum=0,nega=1;char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')nega=-1;ch=getchar();}
	while(ch<='9'&&ch>='0')sum=sum*10+ch-'0',ch=getchar();
	return sum*nega;
}
const int N=1e5+9,M=1e4;
int vis[N],n;
signed main()
{
	for(int i=6;i<=M;i+=6)vis[i]=1;
	for(int i=10;i<=M;i+=10)vis[i]=1;
	for(int i=14;i<=M;i+=14)vis[i]=1;
	n=read();cout<<105<<" ";n--;
	int now=1;
	while(n!=0)
	{
		if(vis[now])
		{
			printf("%d ",now);n--;
		}
		now++;
	}
	return 0;
}


// Created at 2021/02/06 20:47
// {TODO}WA, {TODO}min, {TODO}diff
// goal: {TODO}min
#include <bits/stdc++.h>
//#include <atcoder/all>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i, n) for (lint i = 0, i##_len = n; i < i##_len; i++)
#define rep2(i, n) for (lint i = 1, i##_len = n; i <= i##_len; i++)
#define rep3(i, s, e) for (lint i = s, i##_len = e; i < i##_len; i++)
#define all(i) (i).begin(), (i).end()
#define print(s) cout << s << '\n';
#define print2(s1, s2) cout << s1 << ' ' << s2 << '\n';
#define mk_p make_pair
using namespace std;
//using namespace atcoder;
using lint = long long;
using pi = pair<int, int>;
using pl = pair<lint, lint>;
using vi = vector<int>;
using vl = vector<lint>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using qi = queue<int>;
using ql = queue<lint>;
constexpr int INF = 1 << 30;
constexpr lint INFl = 1LL << 62;

template<class T, class U>
istream &operator>>(istream &is, pair <T, U> &pair) {
    is >> pair.first >> pair.second;
    return is;
}

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

template<class T>
istream &operator>>(istream &is, vector <T> &vec) {
    for (auto &v : vec) is >> v;
    return is;
}

template<class T>
ostream &operator<<(ostream &os, const vector <T> &vec) {
    os << '[';
    for (auto v : vec) os << v << ',';
    os << ']';
    return os;
}

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    // cout << fixed << setprecision(15);
    /*----------------------------------------------------*/
    int v, t, s, d; cin >> v >> t >> s >> d;
    if (v * t <= d && d <= v * s) {
        print("No")
    } else {
        print("Yes")
    }
}
// break? continue?
// 時間? メモリ?
// map->bucket?
// あまり->非負か確認
// set? multiset?
// オーバーフロー確認(最大値を求める)
// 入力確認
// 型確認
// ループ回数確認(TLE)
// 小数の計算は避けよう(割り算)(0割りだめ！絶対！)
// Python を使っては?
// 擬似コードを作っては?
// 汚くてもok

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

#define pb push_back
#define ll long long

void solve()
{
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << a*d-b*c << "\n";

}

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

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


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

int main(){
  int N,K,M;
  cin >> N >> K >> M;
  vector<int> A(N-1);
  int sum=0;
  for(int i=0;i<N-1;i++){
    cin >> A.at(i);
    sum += A.at(i);
  }
  if(N*M-sum <= K && N*M-sum >=0) cout << N*M-sum << endl;
  else if(sum >= N*M) cout << 0 << endl;
  else cout << -1 << endl;
}

#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define all(v) v.begin(), v.end()
#define sz size()
#define mp make_pair
#define pb push_back
#define rep(p, a, b) for (ll p = a; p < b; p++)
#define F first
#define S second
using namespace std;

typedef vector<ll> vll;
typedef vector<ld> vld;
typedef pair<ll, ll> pll;

int main()
{
    ll t, i, j, k, ans, n, m, sum = 0;

    //cin>>t;
    t = 1;
    while (t--)
    {
        cin >> n >> k >> m;
        rep(p, 0, n - 1)
        {
            cin >> i;
            sum += i;
        }

        ll mi = m * n - sum;
        if (mi > k)
            cout << "-1";
        else
            cout << max(0LL, mi);
    }

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cctype>
#define N 201000
template<typename T> inline void read(T &x) {
	x = 0; char c = getchar(); bool flag = false;
	while (!isdigit(c)) { if (c == '-') flag = true; c = getchar(); }
	while (isdigit(c)) x = x * 10 + (c ^ 48), c = getchar();
	if (flag)	x = -x;
}
using namespace std;
int n;
char A[N], B[N], C[N];
inline void work() {
	read(n);
	scanf("%s", A + 1);
	scanf("%s", B + 1);
	scanf("%s", C + 1);
	int cnt = (A[1] == '1') + (B[1] == '1') + (C[1] == '1');
	if (cnt == 0) {
		putchar('0');
		for (int i = 1; i <= n + n; ++i)	putchar('1');
		puts("");
	} else if (cnt == 3) {
		putchar('1');
		for (int i = 1; i <= n + n; ++i)	putchar('0');
		puts("");
	} else if (cnt == 1) {
		putchar('0');
		for (int i= 1; i <= n; ++i)	putchar('1');
		for (int i = 1; i <= n; ++i)	putchar('0');
		puts("");
	} else {
		putchar('1');
		for (int i = 1; i <= n; ++i)	putchar('0');
		for (int i = 1; i <= n; ++i)	putchar('1');
		puts("");
	}
}
int main() {
	int _; read(_);
	while (_--)	work();
	return 0;
}

#include<bits/stdc++.h>
//Ctrl + B
using namespace std;
#define endl '\n'
#define nitro {std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);}
#define pi 3.141592653589793
#define mod 1000000007
#define lb lower_bound
#define ub upper_bound
#define all(v) v.begin(), v.end()
#define dbg(x) cout << x << '\n';
#define case_g(x) cout<<"Case "<<x<<": ";
#define fi first
#define se second
#define pb push_back
#define INF (ll)(1e5+10)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef unsigned long ul;
typedef std::vector<int> vi;
typedef std::vector<ll> vl;
typedef std::vector<bool> vb;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, bool> pib;
typedef std::vector<pii> vii;
typedef std::vector<pll> vll;
typedef std::vector<pib> vib;
typedef std::unordered_map<int, int> umapii;
typedef std::unordered_map<ll, ll> umapll;
typedef std::unordered_map<int , bool> umapib;
typedef std::map<int, int> mapii;
typedef std::map<ll, ll> mapll;
typedef std::map<int, bool> mapib;

ll ncr(ll n, ll r){//ncr formula
    ll m=min(r,n-r);
    ll ans=1;
    for(int i=1;i<=m;i++){
        ans=ans*(n-i+1)/i;
    }
    return ans;
}

ll modpow(ll a, ll b) { //modulo power
    ll result = 1, M=mod;
    while(b!=0) {
        if(b&1) {
            result = ((result%M)*(a%M))%M;
        }
        a = ((a%M)*(a%M))%M;
        b >>= 1;
    }
    return result;
}

ll modinv(ll a) { //modulo inverse
    ll m = mod, y = 0, x = 1;
    while (a > 1) {
        ll q = a / m, t = m;
        m = a % m;
        a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    return x < 0 ? x + mod : x;
}

void solve()
{
    string s;
    cin>>s;
    ll n= s.length();
    for(int i=1;i<n;i++)
    {
        cout<<s[i];
    }
    cout<<s[0];
}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    nitro
    int tc;
    tc =1;
    //cin >> tc;
    for(int i=1; i<=tc; ++i)
    {
        //case_g(i);
        solve();
    }
}


#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using pint = pair<int,int>;
using p = complex<double>;

void f(vector<p>& B) {
	int N = B.size();
	double x = 0, y = 0;
	for(auto u : B)x += u.real(), y += u.imag();
	x /= N, y /= N;

	for(auto&u : B) {
		u = {u.real() - x, u.imag() - y};
	}
	sort(B.begin(), B.end(), [&](p a, p b){return (a.real() == b.real() ? a.imag() < b.imag() : a.real() < b.real()) ;});
}

void g(vector<p>& B, double b) {
	for(auto &i : B) {
		i *= p{cos(b), sin(b)};
	}
	sort(B.begin(), B.end(), [&](p a, p b){return (a.real() == b.real() ? a.imag() < b.imag() : a.real() < b.real()) ;});
}

// #include"debug.hpp"

int main()
{
	std::random_device seed_gen;
	std::default_random_engine engine(seed_gen());
	std::uniform_real_distribution<> dist(0.0, 2 * acos(-1));
	int N; cin >> N;
	vector<p> A(N), B(N);
	for(auto &u : A) {
		double a, b; cin >> a >> b;
		u = {a, b};
	}
	for(auto &u : B) {
		double a, b; cin >> a >> b;
		u = {a, b};
	}

	f(A);
	f(B);

	// print(A);

	// print(B);
	const double eps = 1e-2;

	for(int i = 0; i < 100000; i++) {
		g(B, dist(engine));

		bool ok = true;
		for(int i = 0; i < N; i++) {
			auto v = A[i] - B[i];
			if(abs(v) > eps) {
				ok = false;
			}
		}

		if(ok) {
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;

}

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

int n,t,half1,half2;
ll a[45];
ll f[1<<21];

ll nibutan(ll former){
  ll latter=t-former;
  int ok=0; int ng=(1<<half1);
  while(ng-ok>1){
    int mid=(ok+ng)/2;
    if(f[mid]<=latter) ok=mid;
    else ng=mid;
  }
  return former+f[ok];
}

int main(){
  cin>>n>>t;
  rep(i,n) cin>>a[i];
  half1=n/2,half2=(n+1)/2;
  rep(i,1<<half1){
    ll res=0;
    rep(j,half1){
      if(i>>j & 1) res+=a[j];
    }
    f[i]=res;
  }
  sort(f,f+(1<<(half1)));
  ll ans=0;
  rep(i,1<<half2){
    ll res=0;
    rep(j,half2){
      if(i>>j & 1) res+=a[j+half1];
    }
    if(res>t) continue;
    res = nibutan(res);
    ans=max(ans,res);
  }
  cout<<ans<<endl;
}


#include <bits/stdc++.h>
#define ll long long
#define lll long long
#define mp make_pair
#define pb push_back
ll inf = 1000000000000000000;
#define deci(n) fixed << setprecision(n)
#define vll vector<ll>
#define vpll vector<pair<ll, ll>>
#define umll unordered_map<ll, ll>
#define mll map<ll, ll>
//#define f first
//#define s second
#define mt make_tuple
#define g(i, name) get<i>(name)

using namespace std;

struct custom_hash
{
    static uint64_t splitmix64(uint64_t x)
    {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

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

ll p = 1e9 + 7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// uniform_int_distribution<ll>(l, r)(rng);
//*****************CODE STARTS **************************************

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

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

    ll n; cin >> n;
    ll a[n];
    for(ll i=0; i<n; i++)cin >> a[i];

    ll dp[n+1][n]; // seq num and start

    for(ll i=n; i>0; i--){
        unordered_map <ll, ll> m;
        m[0]=1;
        ll sum=0;
        for(ll j=n-1; j>=0; j--){
            sum+=a[j]; sum%=i;
            dp[i][j] = m[sum];
            if(i!=n)m[sum]+=dp[i+1][j];
            else m[sum]++;
            m[sum]%=p;
        }
    }

    cout << dp[1][0];
}

///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           nd(a,b,c)                   mp(mp(a,b),c)
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=2e18;
const int mod=1e9+7;
const int M=3005;

inline ll bigmod(ll B,ll P){ll R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}
inline ll ad(ll x,ll y){ll ret=(x%mod+y%mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline ll sub(ll x,ll y){ll ret=((x%mod)-(y%mod)+mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline ll gun(ll x,ll y){ll ret=((x%mod)*(y%mod))%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}

int n;
int a[M],pre[M];

int dp[M][M];

int sum[M],nxt[M];

 main()

{
    fast
    cin>>n;
    f(i,1,n)cin>>a[i],pre[i]=a[i]+pre[i-1];

    rf(k,n,1)
    {
        f(pos,1,n)
        {
            int val=pre[pos-1]%k;

            sum[val]=sub(sum[val],dp[pos][k+1]);

            dp[pos][k]=sum[val];

            int z=pre[n]-pre[pos-1];
            z=z%k;

            if(z==0)dp[pos][k]=(dp[pos][k]+1)%mod;

            if(k!=1){

            val=pre[pos-1]%(k-1);
            nxt[val]=ad(nxt[val],dp[pos][k]);

            }
        }

        f(j,0,k+1)
        {
            sum[j]=nxt[j];
            nxt[j]=0;
        }
    }

    cout<<dp[1][1]<<"\n";
    return 0;

}


#include <bits/stdc++.h>

using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define Rrep(i,n) for (ll i = n - 1; i >= 0;i--)
#define ll long long int
#define INF 1000000007
#define llINF 1000000000000000007
#define v(i) vector<i>
#define vv(i) vector<vector<i>>
// int num = atoi(string.c_str()); 文字列の整数変換
// sort(a,a+n,greater<int>()); 昇順ソートif(ans>llINF/a&&a !=0)return 0;
int digit(ll n){int ans=0;while(n>0){n /= 10; ans++;}return ans;}//桁数
ll _pow(ll a,ll b){ll ans = 1;rep(i,b){ans = a * ans;}return ans;}//階乗
ll _modpow(ll a, ll n, ll mod) {ll res = 1;while (n > 0) {if (n & 1){ res = res * a % mod;}a = a * a % mod;n >>= 1;}return res;}
ll gcd(ll a, ll b){if (a%b == 0){return(b);}else{return(gcd(b, a%b));}}//最大公約数
ll lcm(ll a, ll b){return a * b / gcd(a, b);} //最小公倍数
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);//経路圧縮
    }

    void unite(int x, int y) { // xをyの木に併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }};
ll cmb(ll n, ll r){ll X = 1;for(int i = n; i >= n - r + 1;i--){X = X * i % INF;}ll Y = 1;for(int i = r;i > 0 ;i--){Y = Y * i % INF;}Y = _modpow(Y,(ll)INF-2,(ll)INF);return X * Y % INF;}

  int main(){
      ll n;cin>>n;
      ll c[n][n];
      ll tmp = 0;
      ll m = INF;
      rep(i,n){
          rep(j,n){
              cin>>c[i][j];
              if(c[i][j] < m){
                  m = c[i][j];
                  tmp = i;
              }
          }
      }
      v(ll)a,b;
      rep(i,n){
          b.push_back(c[tmp][i]);
      }
      rep(i,n){
          ll now = c[i][0] - b[0];
          rep(j,n){
              if(c[i][j] - b[j] != now){
                  cout<<"No"<<endl;
                  return 0;
              }
          }
          a.push_back(now);
      }
      cout<<"Yes"<<endl;
      rep(i,n){
          cout<<a[i]<<" ";
      }cout<<endl;
      rep(i,n){
          cout<<b[i]<<" ";
      }cout<<endl;
      return 0;
  }

/*
Author: Zcus
Blog: cnblogs.com/Zcus
*/

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

#define fi first
#define se second
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define debug(x) cout << #x << " = " << x << endl
#define For(i, x, y) for (int i = x; i <= y; i++)
#define Rep(i, x, y) for (int i = x; i >= y; i--)
#define file(FILE_NAME) freopen(FILE_NAME".in", "r", stdin), freopen(FILE_NAME".out", "w", stdout)
#define filein(FILE_NAME) freopen(FILE_NAME".in", "r", stdin);
#define fileout(FILE_NAME) freopen(FILE_NAME".out", "w", stdout);

template<class T> inline bool Chkmax(T& x, const T& y) { return x < y ? x = y, true : false; }
template<class T> inline bool Chkmin(T& x, const T& y) { return x > y ? x = y, true : false; }

#define I int
inline I ri() {
	I s = 0, w = 1;
	char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') w = -1; c = getchar();}
	while (c >= '0' && c <= '9') { s = (s << 1) + (s << 3) + (c ^ 48); c = getchar();}
	return s * w;
}
#undef I

#define int long long
const int maxn = 510;

int n;
int c[maxn][maxn];

int x, y;
int ss = 0;

int bb[maxn], aa[maxn];
signed main() {
	ios :: sync_with_stdio(0); cin.tie(0);
	cin >> n;

	For (i, 1, n) For (j, 1, n) cin >> c[i][j];
	For (i, 2, n) bb[i] = c[1][i] - c[1][i - 1];
	For (i, 2, n) aa[i] = c[i][1] - c[i - 1][1];
	//a[2] + b[2] =
	//x + aa[2] + y + bb[2] = a[2][2];
	aa[1] = 0, bb[1] = c[1][1];
	for (int i = 1; i <= n; i++) bb[i] = bb[i - 1] + bb[i];
	for (int i = 1; i <= n; i++) aa[i] = aa[i - 1] + aa[i];
	int pos1 = -1, minn = 0;
	for (int i = 1; i <= n; i++) {
		if (aa[i] < 0) {
			pos1 = 1;
			Chkmin(minn, aa[i]);
		}
		if (bb[i] < 0) {
			pos1 = 2;
			Chkmin(minn, bb[i]);
		}
	}
	minn = -minn;
	if (pos1 == 1) {
		for (int i = 1; i <= n; i++) aa[i] += minn, bb[i] -= minn;
	}
	if (pos1 == 2) for (int i = 1; i <= n; i++) bb[i] += minn, aa[i] -= minn;
	for (int i = 1; i <= n; i++) {
		if (aa[i] < 0 || bb[i] < 0) {
			puts("No"); return 0;
		}
	}
	int ok = 1;
	For (i, 1, n) For (j, 1, n) if (c[i][j] != aa[i] + bb[j]) ok = 0;
	if (ok == 1) {
		puts("Yes");
		for (int i = 1; i <= n; i++) printf("%lld ", aa[i]);
		puts("");
		for (int i = 1; i <= n; i++) printf("%lld ", bb[i]);
		return 0;
	}
	else {
		printf("No");
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define pp pair<ll,ll>
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
int inf=1000001000;
ll INF=2e18;
ll mod=1000000007;
ll MOD=998244353;

int main() {
   vector<int> a(4);
   rep(i,4) cin >> a[i];
   bool t=false;
   rep(j,16){
    int b=0,c=0;
     int f=j;
     rep(i,4){
       if (f%2==0) b+=a[i];
       else c+=a[i];
       f/=2;
     }
     if (b==c) t=true;
   }
   if (t) cout << "Yes" << endl;
   else cout << "No" << endl;
}

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define ll long long int

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

int main(){
    int n, k, m ;
    scanf("%d %d %d", &n, &k, &m);
    vi v(n-1);
    int sum = 0;
    for(int i = 0; i < n-1; i++){
        scanf("%d", &v[i]);
        sum += v[i];
    }
    int r = -1;
    for(int i = 0; i <= k; i++){
        if((sum+i)/n >= m){
            r = i;
            break;
        }
    }
    printf("%d\n", r);
    return 0;
}


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

int main() {
    long N; cin >> N;
    vector<long> used(200000);
    for(long i = 0; i < N; i++){
        used[i] = 0;
    }

    long now_min = 0;
    for(long i = 0; i < N; i++){
        long p; cin >> p;
        used[p] = 1;

        if(p == now_min){
            while(true){
                now_min ++;
                if(used[now_min] == 0) break;
            }
        }

        cout << now_min << endl;
    }
}

#include<bits/stdc++.h>
using namespace std;
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
#define sz(a) ll(a.size())
void solve(){
	ll n;
	cin>>n;
	set<ll> s;
	for(ll i=0;i<n+10;i++)
		s.insert(i);
	for(ll i=0;i<n;i++){
		ll x;
		cin>>x;
		s.erase(x);
		cout<<(*s.begin())<<"\n";
	}
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w", stdout);
    #endif
    clock_t z=clock();
    ll qc=1;
    //cin>>qc;
    for(ll i=1;i<=qc;i++){
        solve();
    }
    debug("Total Time:%.4Lf\n",(ld)(clock()-z)/CLOCKS_PER_SEC);
}


#include <cstdlib>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define vc vector<char>
#define vs vector<string>
#define vd vector<double>
#define vll vector<ll>
#define vvi vector<vi>
#define vvii vector<vii>
#define vvc vector<vc>
#define vvs vector<vs>
#define vvll vector<vll>
#define vvd vector<vd>
#define FOR(x,n) for(int x=0;x<n;x++)
#define FORS(x,n) for(int x=1;x<=n;x++)
#define FORE(x,a) for(auto &x: a)
#define ALL(x) x.begin(),x.end()
#define REP(n) for(int _ = 0; _ < n; _++)
#define MT make_tuple
#define pb push_back
#define endl '\n'
#define F first
#define S second

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

typedef tree<ii,
null_type,
less<ii>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

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

  int h,w,m;
  cin >> h >> w >> m;
  vi mw(w,h),mh(h,w);
  FOR(i,m) {
    int x,y;
    cin >> x >> y;
    x--;y--;
    mh[x] = min(y,mh[x]);
    mw[y] = min(x,mw[y]);
  }
  ll sm = 0;
  FOR(i,mh[0]) {
    sm += mw[i];
  }
  FOR(i,mw[0]) {
    sm += mh[i];
  }

  //cout << " ! " << sm << endl;
  // subtract:

  ordered_set s;
  vii t;

  FOR(i,mw[0]) {
    t.pb({mh[i],i});
  }
  sort(ALL(t));
  int hp = 0;
  FOR(i,mw[0]) {
    while(t[i].F > hp && mh[0] > hp){
      s.insert({mw[hp],hp});
      hp++;
    }
    int lt = s.order_of_key({t[i].S,1e9});
    int gt = s.size() - lt;
    sm -= gt;
    //cout << " " << gt << " " << lt  << " " << t[i].F << " " << t[i].S << endl;
  }

  cout << sm << endl;
}

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

#define M1 1000000007
#define M2 998244353
#define INF 1e18
#define ll long long
#define pll pair<ll,ll>
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define REPR(i,a,b) for(ll i=b-1;i>=a;i--)
#define forr(i,n) for(ll i=0;i<n;i++)
#define F first
#define S second
#define pb push_back
#define DB pop_back
#define mp make_pair
#define MT make_tuple
#define V(a) vector<a>
#define vi vector<int>
#define vlli vector <long long>
#define endl '\n'
#define ce(ele) cout<<ele<<' '
#define cs(ele) cout<<ele<<'\n'
#define CASE(t) ll t; cin>>t; while(t--)

/********************************************************************/
const double pi = 3.1415926535;
/********************************************************************/
//FAST IO//
void FAST() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

/********************************************************************/
int main()
{
  FAST();
  int n; cin>>n;
  string s,t; cin>>s>>t;
  int ans=0, ct1=0, ct2=0;
  for (int i=0; i<n; i++)
  {
    if (s[i]=='0' && t[i]=='0')
    {
      if (ct1==ct2){continue; }
      ct1++; ct2++; ans++;
    }
    else if (s[i]=='0')
    {
      ct1++; ans++;
    }
    else if (t[i]=='0')
    {
      ct2++;
    }
  }
  if (ct1!=ct2){cout<<-1<<endl; return 0;}
  else {cout<<ans<<endl ;}
}


#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define endl "\n"
#define REP(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
#define CHECK(a) cout << #a << " " << a << endl;
#define CHECK_VEC(V) REP (i, 0, V.size()) cout << i << " " << V[i] << endl;
const int INF = 1e9;
const ll MOD = (ll)1e9 + 7LL;
const vector<int> dx = {0, 1, 0, -1, 0, 1, -1, 1, -1};
const vector<int> dy = {0, 0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool CHMIN(T& a, T b){ if (a > b){ a = b; return true; } return false; }
template<class T> bool CHMAX(T& a, T b){ if (a < b){ a = b; return true; } return false; }

bool comp (pair<string, int> a, pair<string, int> b) {
    if (a.second != b.second) return a.second > b.second;
    else return a.first > b.first;
}

void Main () {
    int N;
    cin >> N;
    vector<pair<string, int>> M (N);
    REP (i, 0, N) cin >> M[i].first >> M[i].second;
    sort(ALL(M), comp);
    cout << M[1].first << endl;
}

int main () {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    //int n; cin >> n; while(n--)
    Main();
}

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;++i)

int main(){
  long long n,a,s=0,ans=0;
  cin>>n;
  rep(i,n){
    cin>>a;
    ans+=a*a*n;
    s+=a;
  }
  ans-=s*s;
  cout<<ans<<endl;
  return 0;
}


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

int n;

inline bool check(int x) {
    int u=x;
    while(u) {
        if(u%10==7) return false;
        u/=10;
    }
    u=x;
    while(u) {
        if(u%8==7) return false;
        u/=8;
    }
    return true;
}

int main() {
    cin>>n;
    int sum=0;
    for(int i=1;i<=n;++i)sum+=check(i);cout<<sum;return 0;
}

// Author: Vinay Khilwani
// Language: C++

// @vok8: Codeforces, AtCoder, LeetCode, HackerEarth, TopCoder, Google, FB, CSES, Spoj, GitHub
// @vok_8: CodeChef, GFG
// @vok8_khilwani: HackerRank

// Never Stop Trying.
// Trying to be Better than Myself.

// while(true)
// {
//     if(AC)
//     {
//         break;
//     }
//     else if(Contest Over)
//     {
//         Try.
//         Check out Editorial.
//         Understand.
//         Find out your Mistake.
//         Learn the topic (if new).
//         Solve Problems on that topic (if new).
//         Upsolve that problem.
//         break;
//     }
//     else
//     {
//         Try.
//         Use Pen-Paper.
//         Find errors, edge cases, etc.
//         continue;
//     }
// }

// Optimizations
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx2")
#pragma GCC optimize("Os")

// Libraries
#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;

// Debugging
#define dbg(a) cerr<<a<<"\n";
#define debug_a(a) for(auto x:a) {cerr<<x<<" ";} cerr<<"\n";
#define debug_b(a) for(auto x:a) {cerr<<"["<<x.first<<", "<<x.second<<"]"<<"\n";} cerr<<"\n";
#define debug_c(a) for(auto x:a) {debug_a(x)} cerr<<"\n";
#define debug_d(a) for(auto x:a) {debug_b(x)} cerr<<"\n";
#define debug_e(a) cerr<<"["<<a.first<<", "<<a.second<<"]"<<"\n";

// Defines
#define fast ios_base::sync_with_stdio(false); cout.tie(NULL); cin.tie(NULL);
#define loop(i,a,n) for(int i=a; i<n; i++)
#define rloop(i,a,n) for(int i=a; i>=n; i--)
#define fr(i,a,n,b) for(int i=a; i<n; i+=b)
#define rfr(i,a,n,b) for(int i=a; i>=n; i-=b)
#define IN cin>>
#define OUT cout<<
#define nl "\n"
#define sz(a) int(a.size())
#define all(a) (a).begin(),(a).end()
#define each(a,b) for(auto &a:b)
#define pb push_back
#define set_bits(a) __builtin_popcountll(a)
#define ar array
#define write(a) for(auto x:a) {OUT x<<" ";} OUT endl;
#define read(a) for(auto &x:a) {IN x;}
// #define oset tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
using ll=long long int;
using ld=long double;
using pll=pair<ll,ll>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vi=vector<int>;
const ll mod=(ll)(1e9)+7LL;
const ll M=998244353LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const ld pi=acos(-1);

// General Functions
ll gcd(ll a, ll b)
{
    return (b?gcd(b,a%b):a);
}
ll P(ll B, ll power, ll modulo) //Fast Power
{
    ll ans=1LL;
    while(power>0LL)
    {
        if(power%2LL==1LL)
        {
            ans=(ans*B)%modulo;
        }
        B=(B*B)%modulo;
        power/=2LL;
    }
    return ans;
}
bool isPrime(ll n)
{
    if(n<=1LL)
    {
        return false;
    }
    if(n<=3LL)
    {
        return true;
    }
    if(n%2==0LL || n%3==0LL)
    {
        return false;
    }
    for(ll i=5LL; (i*i)<=n; i+=6LL)
    {
        if(n%i==0LL || n%(i+2LL)==0LL)
        {
            return false;
        }
    }
    return true;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll get_rand(ll l, ll r)
{
    uniform_int_distribution<ll> uid(l,r);
    return uid(rng);
}
void vok()
{
    fast
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
        freopen("error.txt","w",stderr);
    #endif
}

// Global Variables
const int mxN=int(1e5)+100;

// Solver Function(s)
void solve()
{
    int a,b;
    IN a>>b;
    int ans=a%10+((a/10)%10)+((a/100)%10);
    ans=max(ans,b%10+((b/10)%10)+((b/100)%10));
    OUT ans<<nl;
}

// Main Function
int main()
{
    vok();
    int t=1;
    // IN t;
    while(t--)
    {
        solve();
    }
    return 0;
}


#include <bits/stdc++.h>
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int a, b;
    cin >> a >> b;
    cout << (a + b) / 2 << " " << (a - b) / 2 << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a,b;
    // 3 1
    cin>>a>>b;
    int i,j;
    for (i=-100;i<=100;i++){
        for( j=-100;j<=100;j++){
            if(i+j == a && i-j==b){
                cout<<i<<" "<<j<<endl;
                return 0;
            }
        }
    }
    return 0;
}


#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#define endl '\n'
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
const ll INF=1e10+1;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    //freopen("input.txt","r",stdin);
    ll n;
    cin>>n;
		ll ans=0;
    if(n>=1e3) ans+=n-(1e3-1);
		if(n>=1e6) ans+=n-(1e6-1);
		if(n>=1e9) ans+=n-(1e9-1);
		if(n>=1e12) ans+=n-(1e12-1);
		if(n>=1e15) ans+=n-(1e15-1);
    cout<<ans<<endl;

    return 0;
}

#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#include<bitset>
#include<functional>
#include <fstream>
//#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i, x) for(ll i = 0; i < x; i++)
#define rep2(i, x) for(ll i = 1; i <= x; i++)
#define all(a) (a).begin(),(a).end()
#define puts(x) cout << (x) << "\n"
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const int intINF = 1000000000;
const ll mod = 1000000007;
const ll MOD = 998244353;
const ld pi = 3.141592653589793238;
//const ld EPS = 1e-9;

bool isprime(int p) {
	if (p == 1) return false;
	for (int i = 2; i < p; i++) {
		if (p % i == 0) return false;
	}
	return true;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
//main関数内に extGCD(a, b, x, y); でx, yに解が格納
ll extGCD(ll a, ll b, ll& x, ll& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	ll d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll keta(ll n) {
	ll res = 0;
	while (n >= 1) {
		res += n % 10; n /= 10;
	}
	return res;
}
ll modpow(ll x, ll y) {
	ll res = 1;
	while (y) {
		if (y % 2) { res *= x; res %= mod; }
		x = x * x % mod; y /= 2;
	}
	return res;
}
ll nCk(ll n, ll k) {
	ll a = 1, b = 1;
	for (int h = n - k + 1; h <= n; h++) { a *= h; a %= mod; }
	for (int h = 1; h <= k; h++) { b *= h; b %= mod; }
	return a * modpow(b, mod - 2) % mod;
}
//printf("%.10f\n", n);
typedef pair <ll, ll> P;
typedef pair <ld, ll> pp;
ll dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
//struct edge { ll to, cost; };
struct status {
	ll to;
	ll cost;
	ll bai;

	bool operator<(const status& rhs) const { return cost < rhs.cost; };
	bool operator>(const status& rhs) const { return cost > rhs.cost; };
};

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

	//input
	ll n; cin >> n;
	ll ans = 0;
	if (n >= 1000) {
		ans += min(n, (ll)999999) - 999;
	}
	if (n >= 1000000) {
		ans += 2 * (min(n, (ll)999999999) - 999999);
	}
	if (n >= 1000000000) {
		ans += 3 * (min(n, (ll)999999999999) - 999999999);
	}
	if (n >= 1000000000000) {
		ans += 4 * (min(n, (ll)999999999999999) - 999999999999);
	}
	if (n >= 1000000000000000) {
		ans += 5 * (n - 999999999999999);
	}
	cout << ans << endl;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <random>
#include <queue>
#include <stack>
#include <bitset>
#include <cassert>
#include <unordered_map>
#include <iomanip>
typedef long long ll;
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define pi 3.141592653589793
#define prique priority_queue
constexpr auto mod=1000000007;
constexpr auto MOD=1000000000000000;//10^15
using namespace std;
int gcd(int a,int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a*b/gcd(a,b);
}
bool prime(int n){
    int cnt=0;
    for(int i=1;i<=sqrt(n);i++){
        if(n%1==0)cnt++;
    }
    if(cnt!=1) return false;
    else return n!=1;
}
void syou(int a,double b){
    cout<<setprecision(a)<<b<<endl;
}
struct UnionFind{
    vector<int> r;
    UnionFind(int N){
        r=vector<int>(N,-1);
    }
    int root(int x){
        if(r[x]<0) return x;
        return r[x]=root(r[x]);
    }
    bool unite(int x,int y){
        x=root(x);
        y=root(y);
        if(x==y) return false;
        if(r[x]>r[y]) swap(x,y);
        r[x]+=r[y];
        r[y]=x;
        return true;
    }
    int size(int x){
        return -r[root(x)];
    }
};
struct Edge{
    int to;
    int weight;
};
struct fenwick_tree {
    typedef int T;
    T n;
    vector<T> bit;
    fenwick_tree(T num) : bit(num+1, 0) { n = num; }
    void add(T i, T w) {
        for (T x = i; x <= n; x += x & -x) {
            bit[x] += w;
        }
    }
    T sum(T i) {
        T ret = 0;
        for (T x = i; x > 0; x -= x & -x) {
            ret += bit[x];
        }
        return ret;
    }
    T sum(T left, T right) {
        return sum(right) - sum(left);
    }
};
bool flag;
ll n,m,cnt=0,ans=0,aa[220000];
pair<ll,ll> pp[220000];
string s,ss[110000];
queue<ll> que;
signed main(){
    cin>>n;
    cout<<n-1;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	cout<<n-1;
}


#include <bits/stdc++.h>

using namespace std;
int main()
{
    long long int a,b,c;
    cin>>a>>b>>c;

    if(c%2==0)
    {
        if(abs(a)==abs(b))
        cout<<"=";
        else if(abs(a)>abs(b))
        cout<<">";
        else
        cout<<"<";
    }
    else
    {
        if(a>b)
        cout<<">";
        else if(a<b)
        cout<<"<";
        else
        cout<<"=";
    }

}

#include <bits/stdc++.h>

#define int long long

#define f first
#define s second
#define rep(i,a,b)for(int i=a;i<b;i++)
#define pb push_back

const int mod = 1e9 + 7;
const int INF = 1e18;
const int SIZE = 1e6 * 5 + 5;
using namespace std;

void solve() {

    int a[3];
    cin >> a[0];
    cin >> a[1];
    cin >> a[2];

    sort(a, a + 3);

    int diff1 = a[1] - a[0];
    int diff2 = a[2] - a[1];

    if (diff2 == diff1) {
        cout << "Yes\n";
    }
    else {
        cout << "No\n";
    }

}

signed main()
{
    ios::sync_with_stdio(0);

    cin.tie(0);
    cout.tie(0);

    int T = 1;

    // cin >> T;
    // sieve();

    // op();

    while (T--)
    {

        solve();

    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define repx(i, x, n) for (ll i = (ll)(x); i < (ll)(n); i++)

const double PI = 3.1415926535897932;

#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int,int>;
int main(){

 int a,b;
 cin >> a >> b ;
 if(a+b >=15 && b >= 8){

     cout << '1'  << endl;

 }else if (a+b>=10 && b>=3) {
cout << '2' << endl;
 }else if(a+b>=3) {
     cout << '3' << endl;
 }else {
     cout << '4' << endl;
 }

return 0;
}

/*
	Auth: Loxilante
	Time: 2020/10/03
	Prog: ARC104-A
	Lang: cpp
*/
#include <bits/extc++.h>
#define rep(i, l, r) for(int i = l; i < r; i++)
#define hrp(i, l, r) for(int i = l; i <= r; i++)
#define rev(i, r, l) for(int i = r; i >= l; i--)
#define ms(n, t) memset(n, t, sizeof(n))
#define pb push_back
#define int ll
#ifndef JOEON
#define D(...) 97
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
template<typename tn = int> inline tn next(void) { tn k; cin>>k; return k; }
signed main(void)
{
	clock_t Begin = clock();

	#ifdef JOEON
//		freopen("C:\\Users\\Joeon\\Desktop\\IN.txt", "r", stdin);
//		freopen("C:\\Users\\Joeon\\Desktop\\OUT.txt", "w", stdout);
	#endif

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

	int a, b;
	cin>>a>>b;
	cout<<(a+b)/2<<' '<<(a-b)/2<<endl;

	clock_t InputFinished = clock();

	clock_t End = clock();

	D((double)(End-Begin)/CLOCKS_PER_SEC);
	D((double)(End-InputFinished)/CLOCKS_PER_SEC);

#ifdef JOEON
	system("pause");
#endif
	return 0;
}
/*

 */


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define deb(x) cout<< #x << " " << x << "\n";
#define MAX 9223372036854775807
#define MIN -9223372036854775807
#define PI 3.141592653589
#define setbits(n) __builtin_popcountll(n)
#define mkunique(a) a.resize(unique(a.begin(),a.end())-a.begin());
const ll mod=1e9+7;

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll T=clock();

    ll n;
    cin>>n;
    vector<ll> a(n), b(n), p(n);
    set<pair<ll,pair<ll,ll>>> s;
    for(ll i=0;i<n;i++)
        cin>>a[i];
    for(ll i=0;i<n;i++)
        cin>>b[i];
    for(ll i=0;i<n;i++){
        cin>>p[i]; p[i]--;
        if(i!=p[i])
            s.insert({b[p[i]],{i,p[i]}});
    }
    vector<pair<ll,ll>> ans;
    while(s.size()>0){
        ll val=s.rbegin()->first;
        ll c=s.rbegin()->second.first;
        ll to=s.rbegin()->second.second;
        //cout<<val<<" "<<c<<" "<<to<<":   ";
        if(val>=a[c])
            break;
        s.erase(--s.end());
        ll bagpos=p[to];
        ll bagwt=b[bagpos];
        //cout<<bagwt<<" "<<to<<" "<<bagpos<<endl;
        if(bagwt>=a[to])
            break;
        ans.pb({c,to});
        assert(s.find({bagwt,{to,bagpos}})!=s.end());
        p[c]=p[to];
        p[to]=to;
        s.erase({bagwt,{to,bagpos}});
        if(c!=bagpos)
            s.insert({bagwt,{c,bagpos}});
    }
    if(s.size()!=0)
        cout<<-1;
    else{
        cout<<ans.size()<<"\n";
        for(ll i=0;i<ans.size();i++)
            cout<<ans[i].first+1<<" "<<ans[i].second+1<<"\n";
    }

    cerr<<"\n\nTIME: "<<(double)(clock()-T)/CLOCKS_PER_SEC<<" sec\n";
    T = clock();
    return 0;
}

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define N 2114514
const ll mod = 998244353;
const ll inf = 1000000000000000000;
bool used[N];
void jk(ll s, ll d[], vector<vector<pair<ll, P>>>& v, ll n) {
    priority_queue<P, vector<P>, greater<P>> que;
    for (int i = 1; i <= n; i++) d[i] = inf;
    d[s] = 0;
    que.push(P(0, s));
    while (!que.empty()) {
        ll x;
        x = que.top().second;
        que.pop();
        if (used[x]) continue;
        used[x] = 1;
        for (auto p : v[x]) {
            ll nv, nt, nc;
            nv = p.first;
            nt = p.second.first;
            nc = p.second.second;
            ll cos = (d[x] + nc - 1) / nc * nc + nt;
            if (cos < d[nv]) {
                d[nv] = cos;
                que.push(P(d[nv], nv));
            }
        }
    }
}
ll dis[N];
int main() {
    ll n, m, x, y;
    cin >> n >> m >> x >> y;
    vector<vector<pair<ll, P>>> v(n + 1);
    for (int i = 0; i < m; i++) {
        ll a, b, t, k;
        cin >> a >> b >> t >> k;
        v[a].push_back({b, {t, k}});
        v[b].push_back({a, {t, k}});
    }
    jk(x, dis, v, n);
    cout << (dis[y] == inf ? -1 : dis[y]) << endl;
    return 0;
}


#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define ALL(x) x.begin(), x.end()
typedef long long ll;

template <typename T>
void print_vec(vector<T> v) {
  cout << "[ ";
  for (auto const &x : v) {
    cout << x;
    if (&x != &v.back()) {
      cout << " : ";
    }
  }
  cout << " ]" << endl;
}

template <typename T>
void print_vec(vector<vector<T>> v) {
  cout << "[" << endl;
  for (auto const &x : v) {
    cout << " ";
    print_vec(x);
  }
  cout << "]" << endl;
}

template <typename T, typename U, typename Comp = less<>>
bool chmax(T &xmax, const U &x, Comp comp = {}) {
  if (comp(xmax, x)) {
    xmax = x;
    return true;
  }
  return false;
}

template <typename T, typename U, typename Comp = less<>>
bool chmin(T &xmin, const U &x, Comp comp = {}) {
  if (comp(x, xmin)) {
    xmin = x;
    return true;
  }
  return false;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N, a;
  cin >> N;
  vector<ll> alist(N, 0);
  vector<ll> anslist(N, 0);

  REP(i, N) { cin >> alist[i]; }

  REP(i, N) {
    a = alist[i];

    ll up = N, down = -1;
    for (ll j = i - 1; j >= 0; j--) {
      if (a > alist[j]) {
        down = j;
        break;
      }
    }
    for (ll j = i + 1; j < N; j++) {
      if (a > alist[j]) {
        up = j;
        break;
      }
    }

    // cout << i << " " << up << " " << down << endl;

    anslist[i] = (up - down - 1) * a;
  }

  // print_vec(anslist);

  ll ans = 0;
  REP(i, N) { chmax(ans, anslist[i]); }

  // print_vec(anslist);

  cout << ans << endl;
}

//
// Created by K R, Siva Kumar on 23/01/21 at 6:24 PM.
//
#include <bits/stdc++.h>

using namespace std;

const double pi = 2 * acos(0.0);
const int mod = 1e9 + 7;

class Solver {
  int n;
  vector<int> a;
public:
  void solve() {
    cin >> n;
    a.assign(n, 0);

    map<int, int> mp;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      mp[a[i]]++;
    }

    int res = 0;
    for (int i = 0; i < n; i++) {
      int mn = INT_MAX;
      for (int j = i; j < n; j++) {
        mn = min(mn, a[j]);
        res = max(res, (j - i + 1) * mn);
      }
    }

    cout << res;
  }
};

int main() {
#ifndef ONLINE_JUDGE
  freopen("/Users/sivkr/Workspace/CompetitiveProgramming/HackerEarth/1.txt",
          "r", stdin);
  freopen("/Users/sivkr/Workspace/CompetitiveProgramming/HackerEarth/2.txt",
          "w", stdout);
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);

  Solver s;
  s.solve();
}


#pragma GCC optimize("Ofast", "unroll-loops")
#pragma GCC terget("avx2")

#include <bits/stdc++.h>

struct UnionFind{
    std::vector<int> data;
    /* constructor */
    UnionFind() : data(0) {}
    UnionFind(int sz){ data.assign(sz, -1); }
    /* merge the set to which x belongs and the set to which y belongs */
    bool unite(int x, int y){
        x = find(x); y = find(y);
        if (x == y) return false;
        if (data[x] > data[y]) std::swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return true;
    }
    /* find the root of k */
    int find(int k){
        if (data[k] < 0) return k;
        return data[k] = find(data[k]);
    }
    /* calculate the size of the set to which k belongs */
    int size(int k){ return -data[find(k)]; }
};

using edge = std::pair<int, int>;
using graph = std::vector<edge>;

int N, M;
std::vector<int> a, b;
graph g;

void input(void){
    std::cin >> N >> M;
    a.resize(N);
    for (int& ai : a)
        std::cin >> ai;
    b.resize(N);
    for (int& bi : b)
        std::cin >> bi;
    g.resize(M);
    for (edge& e : g){
        std::cin >> e.first >> e.second;
    	--e.first, --e.second;
    }
}

bool solve(void){
    UnionFind uf(N);
    for (edge& e : g)
        (void)uf.unite(e.first, e.second);
    std::vector<long long> connectedSum_a(N, 0LL), connectedSum_b(N, 0LL);
    for (int i = 0; i < N; ++i){
        int idx = uf.find(i);
        connectedSum_a[idx] += a[i];
        connectedSum_b[idx] += b[i];
    }
    return connectedSum_a == connectedSum_b;
}

int main(void){
    input();
    std::cout << (solve() ? "Yes" : "No") << std::endl;
    return 0;
}

#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

class union_find {
    private:
        vector<int> par;
        vector<int> ran;
        vector<ll> size;
    public:
        union_find(int n);
        int find(int x);
        void unite(int x, int y);
        bool same(int x, int y);
        ll show_size(int x);
};

union_find::union_find(int n){
    par.resize(n);
    ran.resize(n);
    size.resize(n);
    rep(i,n) par[i] = i;
    rep(i,n) ran[i] = 0;
    rep(i,n) size[i] = 1;
};

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

void union_find::unite(int x, int y) {
    x = find(x);
    y = find(y);
    if(x == y) return;
    ll t = show_size(x)+show_size(y);
    size[x] = size[y] = t;
    if(ran[x] < ran[y]){
        par[x] = y;
        //size[y] += size[x];
    }
    else{
        par[y] = x;
        //size[x] += size[y];
        if(ran[x] == ran[y]) ran[x]++;
    }
};

ll union_find::show_size(int x) {
    if(par[x] == x) return size[x];
    return show_size(par[x] = find(par[x]));
}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<ll> a(n), b(n);
	rep(i,n) cin >> a[i];
	rep(i,n) cin >> b[i];
	union_find uf(n);
	rep(i,m){
		int c, d;
		cin >> c >> d;
		--c; --d;
		uf.unite(c, d);
	}
	vector<ll> sumA(n, 0), sumB(n, 0);
	rep(i,n){
		int p = uf.find(i);
		sumA[p] += a[i];
		sumB[p] += b[i];
	}
	rep(i,n){
		if(sumA[i] != sumB[i]){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
typedef long long ll;
using namespace std;
using P=pair<int,int>;
vector<vector<bool>> dp(101,vector<bool>(100001,false));
int main()
{
    int n;
    cin>>n;
    vector<int> t(n);
    rep(i,n) cin>>t[i];
    int sum=0;
    rep(i,n) sum+=t[i];
    dp[0][0]=true;
    for(int i=0;i<n;i++){
        for(int j=0;j<=sum;j++){
            if(dp[i][j]){
            dp[i+1][j+t[i]]=true;
            dp[i+1][j]=true;
        }
        }
    }
    int ans=sum;
    for(int j=0;j<=sum;j++){
       if(dp[n][j]) ans=min(ans,max(j,sum-j));
    }
    cout<<ans<<endl;
    return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <functional> // for less
#include <iostream>
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define mod 1000000007

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
    ordered_set;
typedef tree<int, null_type,
             less_equal<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_multiset;

int ans;
int gosolve(int p,vector<int> &v)
{
//cout<<p<<" p\n";
int ors=0;
int xors=0;
ors=v[0];
vector<int> d;
d.push_back(v[0]);
for(int i=1;i<v.size();i++)
{
if(p&1)
{//cout<<" a\n";
int f=d.back();
  f=f|v[i];
  d[d.size()-1]=f;
}
else
{d.push_back(v[i]);
//cout<<" b\n";
}
//cout<<i<<"  "<<d.size()<<"  pi\n";
p=p>>1;
}

for(auto i: d)
{//cout<<i<<"  ";
xors=(xors^i);}
//cout<<xors<<"  xors\n";
return xors;

}
void go(vector<int> &v)
{
ans=-1;

int d=v.size()-1;
int k=1;
for(int i=1;i<=d;i++)
k=k*2;
//cout<<k<<"  k\n";
for(int i=0;i<k;i++)
{

int f=gosolve(i,v);
if(i==0)
  ans=f;
else
ans=min(ans,f);

}

cout<<ans<<endl;
return;
}

void solve()
{//ans=INT_MAX;
int n;
cin>>n;
vector<int> v;
for(int i=0;i<n;i++)
{int d;
  cin>>d;
  v.push_back(d);
}
if(n==1)
  {cout<<v.back()<<endl;
return;}

go(v);

//cout<<ans<<endl;
return;

}

int32_t main() {

ios_base::sync_with_stdio(0); cin.tie(0);
#ifndef ONLINE_JUDGE
    freopen("inp.txt",  "r",  stdin);
    freopen("m3.txt", "w", stdout);
#endif

int t;
t=1;
for(int i=1;i<=t;i++)
{
  solve();
//cout<<endl;
}

    return (int)(0);
}


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

struct R {
  double x, y;
  R(double _x, double _y) {
    x = _x;
    y = _y;
  }
  R() {}
};

struct Line {
  double A, B, C;
  Line (R a, R b) {
    A = b.y - a.y;
    B = a.x - b.x;
    C = a.y * b.x-a.x * b.y;
  }
  Line (double _A, double _B, double _C) {
    A = _A;
    B = _B;
    C = _C;
  }
  double slope() {
    assert(B != 0);
    return -A/B;
  }
};

signed main() {
  ios::sync_with_stdio(0);cin.tie(0);
  int n;
  cin >> n;
  vector<R> p(n);
  int answer = 0;
  for (int i = 0; i < n; ++i) cin >> p[i].x >> p[i].y;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      Line cur(p[i], p[j]);
      if (abs(cur.slope()) <= 1) ++answer;
    }
  }
  cout << answer;
}

#include<bits/stdc++.h>

#define IMAX 1<<29
#define PI 3.14159265359

using namespace std;

template <class T>
using Graph = vector<vector<T>>;

/******** Utility ***************/

int bsize(int bits, int _max){
  int c = 0;
  for(int ix=0; ix!=_max; ++ix)
    if((bits&(1<<ix)) !=0){
      ++c;
    }
  return c;
}

long factrial(long n){
  assert(n >= 0);
  if(n <= 1)
    return 1;
  long _sum = 1;
  for(int ix=0; ix!=(n-1); ++ix)
    _sum *= n-ix;
  return _sum;
}

template<typename T>
void show(vector<T> v)
{
  for(auto _v: v)
    cout << _v << " ";
  cout << endl;
}

template<typename T>
void show(vector<T> v, int maxrow)    // 適度に改行入れるver
{
  for(int ix=0; ix!=v.size(); ++ix){
    if(ix!=0 && ix%maxrow==0)
      cout << endl;
    cout << v[ix] << " ";
  }
  cout << endl;
}

template<typename T>
void show2(vector<vector<T>> v)
{
  int ix = 0;
  for(auto __v: v){
    cout << "[" << ix++ << "] (";
    for(auto _v: __v){
      cout << _v << ", ";
    }
    cout << ")" << endl;
  }
}

// G: Graph
// v: 次に訪れる頂点
// d: 最初に頂点を見つけたタイムスタンプ(行きがけ順)
//    -1で初期化されている必要がある
// f: ある頂点の隣接リストを探索し終えた時刻のタイムスタンプ(帰りがけ順)
//    -1で初期化されている必要がある
// timestamp: タイムスタンプ
// @return: vの隣接頂点の探索に要した時間
template<typename T>
void dfs(const Graph<T> &G, int v, vector<T> &d, vector<T> &f, T &timestamp)
{
  d[v] = timestamp++;
  for(auto next_v: G[v]){   // 隣接する頂点を探索
    if(d[next_v] != -1){  // 既に探索済み
      continue;
    }else{
      dfs(G, next_v, d, f, timestamp); // 次の頂点をDFS
    }
  }
  f[v] = timestamp++;
}

// G: Graph
// dist: startからの最小距離
// start: start地点
template<typename T>
void bfs(const Graph<T> &G, vector<int> &dist, const int start)
{
  // init
  queue<int> que;
  dist.assign(dist.size(), -1);
  dist[start] = 0;
  que.push(start);

  // BFS
  while(!que.empty()){
    int v = que.front();
    que.pop();
    for(auto next_v: G[v]){
      if(dist[next_v] != -1)  // 訪問済み
        continue;
      dist[next_v] = dist[v] + 1;
      que.push(next_v);
    }
  }
}

// グラフの周りに余白をつけていること前提
void genGraph(Graph<int> &G, vector<string> &board, int R, int C)
{
  for(int row=1; row!=R-1; ++row){
    for(int col=1; col!=C-1; ++col){
      if(board[row][col] == '#')
        continue;
      if(board[row-1][col] == '.')
        G[(row-1)*C + col].push_back(row*C + col);
      if(board[row][col-1] == '.')
        G[(row)*C + col-1].push_back(row*C + col);
      if(board[row][col+1] == '.')
        G[(row)*C + col+1].push_back(row*C + col);
      if(board[row+1][col] == '.')
        G[(row+1)*C + col].push_back(row*C + col);
    }
  }
}

/******** end of Utility ***************/

int main(void)
{
  // input
  int N;
  cin >> N;
  vector<double> x = vector<double>(N);
  vector<double> y = vector<double>(N);
  for(int ix=0; ix!=N; ++ix){
    cin >> x[ix] >> y[ix];
  }
  // main
  long count = 0;
  for(int ix=0; ix<N-1; ++ix){
    for(int jx=ix+1; jx<N; ++jx){
      if(abs((y[jx]-y[ix])/(x[jx]-x[ix])) <= 1){
        ++count;
      }
    }
  }

  // print
  cout << count << endl;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include <functional>
#include <iomanip>
#include<cmath>
#include<deque>
#include <math.h>
#include <queue>
#include <sstream>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265359
using namespace std;
using ll = long long;

int GetDigit(ll num) {

	int a = 0;
	while (num) {
		num /= 10;
		a++;
	}
	return a;
}

ll Get_keta_num(ll num) {
	ll z = 0;
	while (num) {
		z += num % 10;
		num /= 10;
	}
	return z;
}

void print(set<int> s) {
	for (set<int>::iterator it = s.begin(); it != s.end(); it++) {
		cout << *it << " ";
	}
	cout << endl;
}

ll count_num_2(ll num) {
	ll data = 0;
	while (true) {
		ll m = num % 1000;
		ll k = num % 100;
		if ((m % 8) == 0) {
			data += 3;
			num /= 8;
			continue;
		}
		else if ((k % 4) == 0) {
			data += 2;
			num /= 4;
			continue;
		}
		else if ((k % 2) == 0) {
			data++;
			num /= 2;
			continue;
		}
		break;
	}
	return data;
}
ll facctorialMethod(int k) {
	ll sum = 1;
	for (int i = 1; i <= k; ++i)
	{
		sum *= i;

	}
	return sum;
}

//" "

ll Get_num_in_string(string s) {
	int n = s.length(), z;
	ll sur = 0;
	for (int i = 0; i < n; i++) {
		z = int(s[i] - '0');
		if (z < 10) {
			sur *= 10;
			sur += z;
		}
	}
	return sur;
}

ll ll_pow(int num, int zyousuu) {
	ll ans = 1;
	for (int i = 0; i < zyousuu; i++) {
		ans *= num;
	}

	return ans;
}
string substrBack(std::string str, size_t pos, size_t len) {
	const size_t strLen = str.length();

	return str.substr(strLen - pos, len);
}

ll ll_gcd(ll x, ll y) {
	if (x < y) {
		ll a = x;
		x = y;
		y = a;
	}

	while (y > 0) {
		ll r = x % y;
		x = y;
		y = r;
	}
	return x;
}

using Graph = vector<vector<int>>;

ll ll_lcm(ll a, ll b) {
	return a * b / ll_gcd(a, b);
}

string get_words_from_end(string word, int num) {
	return word.substr(word.size() - num, num);
}

string binary(ll bina) {
	string ans = "";
	if (bina == 0) {
		ans = "0";
		return ans;
	}
	if (bina == 1) {
		ans = "1";
		return ans;
	}
	while (bina != 0) {
		int a = bina % 2;
		char c = '0' + a;
		ans += c;
		bina -= a;
		bina /= 2;
	}
	reverse(ans.begin(), ans.end());
	return ans;
}

void YES() {
	cout << "YES" << endl;
}
void NO() {
	cout << "NO" << endl;
}
void Yes() {
	cout << "Yes" << endl;
}
void No() {
	cout << "No" << endl;
}

ll comb(ll N, ll i) {
	vector<vector<long long int> > v(N + 1, vector<long long int>(N + 1, 0));
	for (int i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
		}
	}
	return v[N][i];
}

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

bool divisor(long long n) {
	vector<long long> ret;
	for (long long i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	sort(ret.begin(), ret.end()); // 昇順に並べる
	bool x = false;
	if (ret.size() == 8)x = true;
	return x;
}

vector<bool> seen(100005, false);
vector<int> ans;
int count = 0;

void dfs(const Graph& G, int v) {
	seen[v] = true; // v を訪問済にする
	ans.push_back(v + 1);
	// v から行ける各頂点 next_v について
	for (auto next_v : G[v]) {
		if (seen[next_v]) continue; // next_v が探索済だったらスルー
		dfs(G, next_v); // 再帰的に探索
	}
}

void cout_data(ll x) {
	cout << x << endl;
}

int main() {
	int A, B; cin >> A >> B;
	int ans = 1;
	for (int i = 2; i <= B;i++) {
		int a_1 = (A + i - 1) / i;
		int b_1 = B / i;
		if (a_1 > b_1)continue;
		if ((a_1 == 0) || (b_1 == 0))continue;
		if (a_1 != b_1) {
			if ((a_1 * i >= A) && (b_1 * i <= B)) {
				if (a_1 * i < b_1 * i)ans = i;
			}
		}

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

//std::cout << std::setprecision(2) << 3.141; // "3.1"

//#define _GLIBCXX_DEBUG
//#include "atcoder/all"
//using namespace atcoder;
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
#define Dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) (((n) >> (k)) & 1) /*nのk bit目*/
namespace mydef {
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
bool dbg = true;
}  // namespace mydef
using namespace mydef;
#define pb push_back
//#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define asn ans

int A, B;

void solve() {
    int ans = 1;
    for (int x = 1; x <= 200020; x++) {
        if (((A - 1) / x + 2 <= B / x))
            chmax(ans, x);
    }
    cout << ans << endl;
}

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

    cin >> A >> B;

    solve();
    return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define chmin(x,y) x = min((x),(y))
#define chmax(x,y) x = max((x),(y))
#define popcount(x) __builtin_popcount(x)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
const int INF = 1e9;
const long long LINF = 1e17;
const int MOD = 1000000007;
//const int MOD = 998244353;
const double PI = 3.14159265358979323846;

struct Unionfind{
    int n;
    vector<int> parents;
    Unionfind(int n):n(n),parents(n,-1){ }

    int find(int x){
        if(parents[x] < 0) return x;
        return parents[x] = find(parents[x]);
    }

    void unite(int x,int y){
        x = find(x);
        y = find(y);

        if(x==y) return;
        if(parents[x] > parents[y]) swap(x,y);
        parents[x] += parents[y];
        parents[y] = x;
    }

    int size(int x){
        return -parents[find(x)];
    }

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

    vector<int> members(int x){
        int root = find(x);
        vector<int> member;
        for(int i=0;i<n;i++){
            if(find(i)==root ){
                member.push_back(i);
            }
        }
        return member;
    }

    int group_cnt(){
        int c = 0;
        for(int i=0;i<n;i++){
            if(parents[i] < 0) ++c;
        }
        return c;
    }
};

int main(){
    int n,m;
    cin >> n >> m;
    vector<vector<int>> G(n);
    Unionfind uf(n);
    rep(i,m){
        int a,b;
        cin >> a >> b;
        --a;--b;
        G[a].push_back(b);
        G[b].push_back(a);
        uf.unite(a,b);
    }
    vector<int> seen(n,-1);
    auto dfs = [&](auto&& dfs,int i,vector<int>& v) -> void {
        v.push_back(i);
        seen[i] = 1;
        for(int j:G[i]){
            if(seen[j] >= 0) continue;
            dfs(dfs,j,v);
        }
        return;
    };
    auto dfs2 = [&](auto&& dfs2,vector<int>& v,vector<int>& color) -> ll {
        for(int j:v){
            if(color[j] == -1){
                ll res = 0;
                vector<int> use(3,0);
                for(int k:G[j]){
                    if(color[k] == -1) continue;
                    use[color[k]] ++;
                }
                rep(p,3){
                    if(use[p]==0){
                        color[j] = p;
                        res += dfs2(dfs2,v,color);
                    }
                }
                color[j] = -1;
                return res;
            }
        }
        return 1;
    };
    ll res = 1;
    rep(i,n){
        if(uf.find(i) == i){
            vector<int> v;
            dfs(dfs,i,v);
            vector<int> color(n,-1);
            color[v[0]] = 0;
            res *= 3*dfs2(dfs2,v,color);
        }
    }
    cout << res << endl;

    return 0;
}

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

int n, m;
vector<vector<int>> adj;

long long ans=1;
long long comp_ans[25];

int color[100];

vector<vector<int>> component;
int visited[25] = {};

void discover(int vertex, int cid=-1) {
    if (cid==-1) {
        cid = component.size();
        component.push_back(vector<int>(0));
    }

    visited[vertex] = true;
    component[cid].push_back(vertex);
    for (int nxt : adj[vertex]) {
        if (not visited[nxt]) {
            discover(nxt, cid);
        }
    }
}

void tryColor(int vid, const int& cid) {
    if (vid >= component[cid].size()) {
        comp_ans[cid]++;
        // for (int i=0; i<n; i++) cout << color[i] << ' ';
        return;
    }

    int vertex = component[cid][vid];
    for (int cl=1; cl<4; cl++) {
        int flag = 1;

        for (int neighbor : adj[vertex]) {
            if (color[neighbor]==cl) flag = 0;
        }

        if (flag) {
            color[vertex] = cl;
            tryColor(vid+1, cid);
            color[vertex] = 0;
        }
    }
}

int main() {
    cin >> n >> m;
    adj.resize(n);
    for (int i=0; i<m; i++) {
        int x, y;
        cin >> x >> y;
        x--; y--;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }

    for (int i=0; i<n; i++) {
        if (visited[i] == 0) discover(i);
    }

    for (int cid=0; cid<component.size(); cid++) {
        tryColor(0, cid);
        ans *= comp_ans[cid];
    }

    cout << ans << endl;
}


#include <bits/stdc++.h>
#define int long long
#define ri register int
using namespace std;
int n,m,ans,s[2];
char ch[25];
template <typename T> inline void read(T &x) {
	register T f=0,c=getchar();
	for (; c<48||57<c; c=getchar()) if (c=='-') f=1;
	for (x=0; 48<=c&&c<=57; c=getchar()) x=(x<<3)+(x<<1)+(c&15);
	if (f) x=~(--x);
}
template <typename T> inline void print(T x) {
	if (x<0) putchar('-'),x=~(--x);
	if (x>9) print(x/10);
	putchar(x%10|48);
}
signed main() {
	read(n),read(m);
	for (ri i=1,cnt; i<=n; ++i) {
		scanf("%s",ch),cnt=0;
		for (ri j=0; j<m; ++j)
			if (ch[j]=='1') ++cnt;
		ans+=s[cnt&1^1],++s[cnt&1];
	}
	print(ans);
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

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

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

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

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

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

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

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

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

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

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

using namespace debug;

const char nl = '\n';

void solve() {
    int n, m;
    cin >> n >> m;
    vll cnt(2);
    for(int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        ++cnt[count(all(s), '1')%2];
    }
    cout << cnt[0] * cnt[1] << nl;
}

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

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

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

}


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

int ceil(int x, int d) {
    return (x+d-1) / d;
}

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> A;
    A.push_back(0);
    rep(i,m) {
        int a;
        cin >> a;
        A.push_back(a);
    }
    A.push_back(n+1);
    sort(A.begin(), A.end());

    int hanko = n;
    vector<int> haba;
    rep(i,A.size()-1) {
        int w = A[i+1] - A[i] - 1;
        if (w == 0) continue;
        else {
            hanko = min(hanko, w);
            haba.push_back(w);
        }
    }

    int ans = 0;
    for (int x : haba) {
        ans += ceil(x, hanko);
    }
    cout << ans << endl;

}

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

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
const ll inf=pow(2,31)-1;
int main()
{
	int n,m;cin>>n>>m;
	int k=99999999,ans=0,a[m+5];a[0]=0;
	for(int i=1;i<=m;i++) cin>>a[i];
	sort(a+1,a+1+m);
	a[m+1]=n+1;
	for(int i=1;i<=m+1;i++)
	{
		if(a[i]-a[i-1]>1)
		{
			k=min(k,a[i]-a[i-1]-1);
		}
	}
	//cout<<k<<endl;
	for(int i=1;i<=m+1;i++)
	{
		int t=a[i]-a[i-1]-1;
		ans+=t/k;
		if(t%k) ans++;
	}
	if(m==0)
	{
		cout<<1<<endl;
		return 0;
	}
	cout<<ans<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#ifdef _DEBUG
#define show(x)          \
	cerr << #x << " : "; \
	showVal(x)
template <typename T>
void showVal(const T &a) { cerr << a << endl; }
template <typename T>
void showVal(const vector<T> &a) {
	for (const T &v : a) cerr << v << " ";
	cerr << endl;
}
template <typename T>
void showVal(const vector<vector<T>> &a) {
	cerr << endl;
	for (const vector<T> &v : a) showVal(v);
}
#else
#define show(x)
#endif
int main() {
	int n, m;
	cin >> n >> m;
	vector<int> x(m), y(m), z(m);
	for (int i = 0; i < m; i++) {
		cin >> x[i] >> y[i] >> z[i];
	}
	vector<ll> dp(1 << n, 0);
	// 左から見てすでにbit決まっている
	dp[0] = 1;
	for (int bit = 0; bit < 1 << n; bit++) {
		vector<bool> isEx(n, false);
		for (int i = 0; i < n; i++) {
			if ((bit >> i) & 1) isEx[i] = true;
		}
		for (int i = 0; i < n; i++) {
			if (!isEx[i]) {
				vector<int> now;
				for (int j = n - 1; j >= 0; j--) {
					if (isEx[j] || j == i) now.push_back(j + 1);
				}
				bool isOK = true;
				for (int j = 0; j < m; j++) {
					int cnt = 0;
					for (int k = 0; k < min(x[j], (int)now.size()); k++) {
						if (now[k] <= y[j]) cnt++;
					}
					if (cnt > z[j]) {
						isOK = false;
						break;
					}
				}
				if (isOK) {
					dp[bit | (1 << i)] += dp[bit];
				}
			}
		}
	}
	show(dp);
	cout << dp[(1 << n) - 1] << endl;
	return 0;
}

#include<bits/stdc++.h>
    #define ll long long
    #define ld long double
    #define ff first
    #define ss second
    #define eb emplace_back
    #define pb push_back
    #define mp make_pair
    #define all(x) begin(x), end(x)
    #define endl "\n"
    int dx[4] = {1, -1, 0, 0};
    int dy[4] = {0, 0, -1, 1};
    ll dp[100005];
    ll mod = 998244353;
    bool vis[100000];
    using namespace std;
    bool isPrime(ll n) {
      ll j;
      for ( j = 2; j <= sqrt(n); j++) {
        if (n % j == 0) {
          break;
        }
      }
      if (j > sqrt(n)) {
        return 1;
      }
      else {
        return 0;
      }
    }
    ll modexpo(ll a, ll b) {
      ll ans = 1;
      a = a % mod;
      while (b > 0) {
        if ((b & 1) == 1) {
          ans = ((ans % mod) * (a % mod)) % mod;
        }
        b = b >> 1;
        a = ((a % mod) * (a % mod)) % mod;
      }
      return ans;
    }
    ll invmod(ll n) {
      return modexpo(n, mod - 2);
    }

    ll comb(ll n, ll r) {
      if (r == 0) {
        return 1;
      }
      ll fact[n + 1];
      fact[0] = 1;
      for (ll i = 1; i <= n; i++) {
        fact[i] = (fact[i - 1] * i) % mod;
      }
      return (fact[n] * invmod(fact[r]) % mod * invmod(fact[n - r]) % mod) % mod;
    }
    ll gcd(ll a, ll b) {
      if (a == 0) {
        return b;
      }
      return gcd(b % a, a);
    }
    ll lcm(ll a, ll b) {
      return (a * b) / gcd(a, b);
    }
    void dfs(ll i, vector<ll>adj[], bool visited[]) {
      visited[i] = 1;
      for (auto j : adj[i]) {
        if (visited[j] == 0) {
          dfs(j, adj, visited);
        }
      }
    }
    bool sortbysecdesc(const pair<int, int> &a, const pair<int, int> &b)
    {
      return a.second > b.second;
    }
    void solve(ll k) {
    ll n,m,ti;
    cin>>n>>m>>ti;
    ll n1=n;
    bool ok=0;
    ll pr=0;
    while(m--){
        ll a,b;
        cin>>a>>b;
        n-=(a-pr);
        if(n<=0){
            ok=1;
        }
        n+=b-a;
        n=min(n,n1);
        pr=b;
    }
    n-=(ti-pr);
    if(n<=0){
        ok=1;
    }
    if(ok==0){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
    }

    int main() {
    #ifndef ONLINE_JUDGE
      // for getting input from input.txt
      freopen("input.txt", "r", stdin);
      // for writing output to output.txt
      freopen("output.txt", "w", stdout);
    #endif

      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      ll t = 1;
     // cin >> t;
      ll k = 1;
      while (k <= t) {
        solve(k);
        k++;
      }
      return 0;
    }