//git pull --rebase origin master
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define wi(t) int t;cin>>t;while(t--)
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
    uniform_int_distribution<int> uid(0,lim-1);
    return uid(rang);
}
int mpow(int base, int exp);
void ipgraph(int n, int m);
void dfs(int u, int par);

const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vi adj[N];
vi vis(N);
ll int gcd(ll int a, ll int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
int tc=1;
void solve()
    {
        ll int n,m;
        cin>>n>>m;
        vl ar(m);
        fo(i,m) cin>>ar[i];
        sortall(ar);
        ll int ans=LONG_MAX;
        ll int bck=0;

        for(int i=0;i<m;i++)
        {
            if((ar[i]-bck-1)>0)
            ans=min(ans,ar[i]-bck-1);
            bck=ar[i];
        }
            if((n-bck)>0)
            ans=min(ans,n-bck);
        ll int ok=0;
        bck=0;
        //  deb(ans);
        for(int i=0;i<m;i++)
        {
            if((ar[i]-bck-1)>0)
            {
                ll int gg=ar[i]-bck-1;
                ok+=gg/ans;
                if(gg%ans!=0) ok++;
            }
            bck=ar[i];
        }
            if((n-bck)>0)
            {
                ll int gg=n-bck;
                ok+=gg/ans;
                if(gg%ans!=0) ok++;
            }
        cout<<ok<<"\n";

    }

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

    // wi(t)
    {
      solve();
    }

    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(int n, int m){
    int i, u, v;
    while(m--){
        cin>>u>>v;
    u--, v--;
        adj[u].pb(v);
        adj[v].pb(u);
    }
}

void dfs(int u, int par){
    for(int v:adj[u]){
        if (v == par) continue;
        dfs(v, u);
    }
}

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

using ll = long long int;
using ull = unsigned long long int;
using P = pair<int, int>;
using P3 = pair<int,P>;
using PP = pair<P, P>;
constexpr ll INF = 1LL << 60;
constexpr ll MOD = ll(1e9+7);
constexpr int di[] = {0, 1, 0, -1};
constexpr int dj[] = {1, 0, -1, 0};
constexpr int di8[] = {0, 1, 1, 1, 0, -1, -1, -1};
constexpr int dj8[] = {1, 1, 0, -1, -1, -1, 0, 1};
constexpr double EPS = 1e-10;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<int> > pos(n+1);
    for(int i=0;i<n;i++){
        int a;
        cin >> a;
        pos[a].push_back(i);
    }
    for(int i=0;i<=n;i++){
        pos[i].push_back(-1);
        pos[i].push_back(n);
        sort(pos[i].begin(), pos[i].end());
    }
    for(int i=0;i<=n;i++){
        int k = pos[i].size();
        for(int j=0;j<k-1;j++){
            if(pos[i][j+1]-pos[i][j] > m){
                cout << i << endl;
                return 0;
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
typedef pair<int, long long> P;

long long n;
long long qq[200001];
vector<P> vc[200001];

void dfs(int pt, int par){
	for(auto i : vc[pt]){
		if(i.first==par) continue;
		qq[i.first]=qq[pt]^i.second;
		dfs(i.first, pt);
	}
}

int main(){
	long long a, b ,w;
	cin >> n;
	for(int i=1;i<n;i++){
		cin >> a >> b >> w;
		vc[a].push_back(make_pair(b, w));
		vc[b].push_back(make_pair(a, w));
	}
	dfs(1, 0);
	__int128 cnt[61]={0}, temp;
	for(int i=1;i<=n;i++){
		int ptr=0;
		temp=qq[i];
		while(temp>0){
			if(temp%2==1) cnt[ptr]++;
			temp/=2;
			ptr++;
		}
	}
	__int128 ans=0, mul=1;
	for(int i=1;i<n;i++){
		int ptr=0;
		temp=qq[i];
		for(int j=0;j<=60;j++){
			if(temp%2==1){
				cnt[ptr]--;
				ans+=(mul%mod)*(n-i-cnt[ptr])%mod;
			}
			else{
				ans+=(mul%mod)*(cnt[ptr])%mod;
			}
			temp/=2;
			ptr++;
			mul*=2;
			ans%=mod;
		}
		mul=1;
	}
	long long print=ans;
	cout<<print<<'\n';
}

//Bismillahirrahmanirrahim

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;

#define fi first
#define se second
#define mp make_pair
#define endl "\n"
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo inf = 1000000000000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;

int n,m,b[li],a[li],k,flag,t,say,vis[li];
int cev;
string s;
vector<int> v[li];

inline void dfs(int node,int ata){
	if(vis[node]){flag=1;return ;}
	vis[node]=1;
	say++;
	for(auto go:v[node]){
		if(go==ata)continue;
		dfs(go,node);
	}
}

int main(void){
	scanf("%d",&n);
	FOR{
		int x,y;
		scanf("%d %d",&x,&y);
		v[x].pb(y);
		v[y].pb(x);
	}
	cev=0;
	for(int i=1;i<=400000;i++){
		if(vis[i])continue;
		flag=0;
		say=0;
		dfs(i,0);
		if(flag==0)cev+=say-1;
		else cev+=say;
	}
	printf("%d\n",cev);
	return 0;
}


#include <iostream>

using namespace std;

int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); }

int main() {
  int n;
  cin >> n;
  int x = 0;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    x = gcd(x, a);
  }
  cout << x;
}

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

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define ppb pop_back()
#define ppf pop_front()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for (int i = (a), _b = (b); i < _b; i++)
#define loop(i,a,b) for (int i = (a), _b = (b); i >= _b; i--)
#define forr(x,arr) for(auto &x : arr)
#define mod 1000000007
#define INF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-7
#define sz(x) ((lli)(x).size())

template <class my>
using   vo      =   vector<my>;
using   lli     =   long long;
using   lld     =   long double;
using   ulli    =   unsigned long long int;
using   pll     =   pair<lli, lli>;
using   ttt     =   pair<lli, pll>;
using   vttt    =   vector<ttt>;
using   vll     =   vector<pll>;
using   vl      =   vector<lli>;
using   vi      =   vector<int>;
using   vvi     =   vector<vector<int>>;
using   cd      =   complex<lld>;
const double PI = acos(-1);

#ifndef tejasp
#define trace(...) {}
#define cotra(...) {}
#define end_routine() {}
#define localsys 0
#define endl '\n'
#endif

int white_horseman()
{
    lli n, m, k, q, u, v, temp = 0, ans = 0;
    cin >> n;
    int arr[n], val = 0;
    fol(i,0,n) cin >> arr[i];
    fol(i,0,n) val = __gcd(val, arr[i]);
    cout << val << endl;
    return 0;
}

signed main()
{
    #ifdef tejasp
            freopen("input.txt", "rt", stdin);
            freopen("output.txt", "wt", stdout);
    #endif
    ios_base::sync_with_stdio(false);   cin.tie(NULL);
    cout << fixed << setprecision(10);
    int t = 1;
    //cin >> t;
    fol(i,0,t) {
        //cout << "Case #" << i + 1 << ": ";
        white_horseman();
    }
    //end_routine(); if(localsys) system("pause");
}


#pragma region head
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
template <class T>
using vv = vector<vector<T>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rrepi(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define bit(n) (1LL << (n))
template <class T>
inline bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
const int INF = 1002003004;
const ll LINF = 1002003004005006007ll;
struct preprocess {
    preprocess() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} ____;
#pragma endregion head

#pragma region library
const int MOD = 998244353;
struct mint {
    ll x;  // typedef long long ll;
    mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD - 2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
    bool operator==(const mint a) const {
        return x == a.x;
    }
    bool operator!=(const mint a) const {
        return x != a.x;
    }
    friend ostream& operator<<(ostream& os, const mint& value) {
        os << value.x;
        return os;
    }
    friend istream& operator>>(istream& is, mint& value) {
        ll t;
        is >> t;
        value = mint(t);
        return is;
    }
};
struct combination {
    vector<mint> fact, ifact;
    combination(int n) : fact(n + 1), ifact(n + 1) {
        assert(n < MOD);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }
};

#pragma endregion library

int main() {
    int n, k;
    cin >> n >> k;
    vector<mint> a(n);
    rep(i, n) cin >> a[i];
    combination cb(310);
    vector<mint> ak(k + 1);
    vector<mint> power(k + 1);
    vector<mint> anow(n, 1);
    rep(i, k + 1) {
        rep(j, n) {
            ak[i] += anow[j] * cb.ifact[i];
        }
        rep(j, n) {
            anow[j] *= a[j];
        }

    }
    rep(i, n) {
        mint now = a[i] * 2;
        repi(j, 1, k + 1) {
            power[j] += now;
            now *= a[i] * 2;
        }
    }
    mint div2 = (mint)1 / 2;
    repi(x, 1, k + 1) {
        mint ans = 0;
        rep(j, x + 1) {
            ans += ak[j] * ak[x - j];
        }
        ans *= cb.fact[x];
        ans -= power[x];
        ans *= div2;
        cout << ans << '\n';
    }
}

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

const int N=100005;
const long long MOD=998244353;
const long long INV=499122177;
int n,k;
long long p[N],s[N],f[N],inv[N];

long long ksm(long long a,int b)
{
	long long res=1;
	while(b)
	{
		if(b&1) res=res*a%MOD;
		a=a*a%MOD,b/=2;
	}
	return res;
}

long long C(int a,int b)
{
	return f[a]*inv[b]%MOD*inv[a-b]%MOD;
}

int main()
{
	scanf("%d%d",&n,&k);
	f[0]=p[0]=inv[0]=1,s[0]=n;
	for(int i=1;i<=n;i++)
	{
		long long a,p;
		scanf("%d",&a),s[1]=(s[1]+(p=a))%MOD;
		for(int j=2;j<=k;j++) s[j]=(s[j]+(p=p*a%MOD))%MOD;
	}
//	for(int i=1;i<=k;i++) cout<<i<<' '<<s[i]<<endl;
	for(int i=1;i<=k;i++) f[i]=f[i-1]*i%MOD,p[i]=p[i-1]*2%MOD;
	inv[k]=ksm(f[k],MOD-2);
	for(int i=k;i>=1;i--) inv[i-1]=inv[i]*i%MOD;
	for(int i=1;i<=k;i++)
	{
		long long ans=0;
//		cout<<i<<endl;
		for(int j=0;j<=i;j++)
		{
			ans=(ans+s[j]*s[i-j]%MOD*C(i,j)%MOD);
//			cout<<i<<' '<<j<<' '<<C(i,j)<<endl;
		}
		ans=(ans-s[i]*p[i]%MOD+MOD)%MOD;
		ans=ans*INV%MOD;
		printf("%lld\n",ans);
	}
}


//#define _GLIBCXX_DEBUG
#include <iostream>
#include <time.h>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <algorithm>
#include <functional>
#include <random>
#include <string>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bits/stdc++.h>
#include <deque>
#include <queue>
#include <list>

/*
vector<int> a(N);
vector<vector<int>> a(N, vector<int>(N));
auto itr = a.begin();
for (auto itr = a.begin(); itr != a.end(); itr++)
{
    cout << itr - a.begin() << endl; = 0,1,...,N-1
}
sort(a.begin(), a.end());
reverse(a.begin(), a.end());
*/

/*
list<int> lst;
lst.push_front(i);
lst.push_back(i);
lst.pop_front();
lst.pop_back();
for(auto itr = lst.begin(); itr != lst.end(); ++itr) {
    std::cout << *itr << "\n";
}
*/

/*
bool cmp(const std::pair<int, int> &a, const std::pair<int, int> &b)
{
    return a.first < b.first;
}
vector<pair<int, int>> p(N);
for (int i = 0; i < N; i++)
{
    p[i].first = a[i];
    p[i].second = b[i];
}
sort(p.begin(), p.end(), cmp);
for (int i = 0; i < N; i++)
{
    a[i] = p[i].first;
    b[i] = p[i].second;
}

struct Hara
{
    int A, B;
};

bool cmp(const Hara &a, const Hara &b)
{
    return a.A < b.A;
}

sort(h.begin(), h.end(), cmp);
*/

/*
std::unordered_set<int> hash;
*/

/*
struct Edge
{
    int to;
    long long w;
    Edge(int to, long long w) : to(to), w(w) {}
};
using Graph = vector<vector<Edge>>;
Graph G(N);
    for (int i = 0; i < M; ++i) {
        int a, b;
        long long w;
        cin >> a >> b >> w;
        G[a].push_back(Edge(b, w));
    }
*/

/*
struct Hara
{
    long long a, b;
};
bool operator<(const Hara &hara_1, const Hara &hara_2)
{
    return hara_1.b < hara_2.b;
}
*/

using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;
const int INF = 1000000000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long GCD(long long m, long long n)
{
    if (m < n)
    {
        swap(m, n);
    }
    // ベースケース
    if (n == 0)
    {
        return m;
    }

    // 再帰呼び出し
    return GCD(n, m % n);
}

struct Hara
{
    string str;
    int len;
};

bool operator<(const Hara &hara_1, const Hara &hara_2)
{
    return hara_1.len < hara_2.len;
}

int main()
{
    int N, M;
    cin >> N >> M;
    vector<Hara> h(M);
    for (int i = 0; i < M; i++)
    {
        cin >> h[i].str;
        h[i].len = h[i].str.length();
    }

    sort(h.begin(), h.end());

    /*
    for (int i = 0; i < M; i++)
    {
        cout << h[i].str << endl;
    }
    */

    int p = 0;
    for (int i = 0; i < N; i++)
    {
        int len = 0;
        while (len < N)
        {
            if (len + h[p].len <= N)
            {
                cout << h[p].str;
                len += h[p].len;
                p++;
            }
            else
            {
                len++;
                cout << '.';
            }
        }
        cout << endl;
    }
}

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

std::vector<std::vector<int>> scc_decompose(
		std::vector<std::vector<int>> &links,
		std::vector<std::vector<int>> &rlinks
	){
	int n = links.size();
	int cnt = 0;
	std::vector<int> order;
	std::vector<bool> visited(n, false);
	std::function<void(int)> dfs = [&](int x){
		visited[x] = true;
		for(auto to: links[x]) if(!visited[to]) dfs(to);
		order.push_back(x);
	};

	for(int i=0; i<n; i++) if(!visited[i]) dfs(i);
	std::reverse(order.begin(), order.end());

	cnt = 0;
	std::vector<std::vector<int>> scc;
	std::fill(visited.begin(), visited.end(), false);
	dfs = [&](int x){
		visited[x] = true;
		for(auto to: rlinks[x]) if(!visited[to]) dfs(to);
		scc[cnt].push_back(x);
	};

	for(auto i: order) if(!visited[i]){
		scc.push_back(std::vector<int>());
		dfs(i);
		cnt++;
	}

	return scc;
}

std::vector<int> topological_sort(
		std::vector<std::vector<int>> &links,
		std::vector<std::vector<int>> &scc
	){
	int n = links.size();
	std::vector<int> scc_num(n);
	for(int i=0; i<scc.size(); i++){
		for(int &v: scc[i]) scc_num[v] = i;
	}

	std::vector<int> in_cnt(scc.size());
	std::vector<std::vector<int>> scc_links(scc.size());
	for(int i=0; i<links.size(); i++){
		for(int j: links[i]){
			if(scc_num[i]!=scc_num[j]){
				scc_links[scc_num[i]].push_back(scc_num[j]);
				in_cnt[scc_num[j]]++;
			}
		}
	}

	std::queue<int> que;
	for(int i=0; i<scc.size(); i++) if(in_cnt[i]==0) que.push(i);
	std::vector<int> ret;
	while(!que.empty()){
		int now = que.front();
		que.pop();
		ret.push_back(now);
		for(auto to: scc_links[now]){
			if(--in_cnt[to]==0) que.push(to);
		}
	}
	return ret;
}

int main(){
	int n, m;
	std::cin >> n >> m;
	std::string st[m];
	REP(i, 0, m) std::cin >> st[i];

	std::vector<std::vector<int>> links(m, std::vector<int>());
	std::vector<std::vector<int>> rlinks(m, std::vector<int>());
	REP(i, 0, m) REP(j, 0, m) {
		bool ok = false;
		REP(k, 0, st[i].size()){
			std::string s1 = st[i].substr(k);
			std::string s2 = st[j].substr(0, st[i].size()-k);
			if(s1 == s2) ok = true;
		}
		if(ok){
			links[i].push_back(j);
			rlinks[j].push_back(i);
		}
	}
	std::vector<std::vector<int>> scc = scc_decompose(links, rlinks);
	std::vector<int> order = topological_sort(links, scc);

	std::vector<std::string> ss;
	for(auto x: order) for(auto v: scc[x]) {
		ss.push_back(st[v]);
	}

	std::string ans[n];
	bool used[m] = {};

	REP(si, 0, m){

		int minrow = 0, crost = 50, min_add_len = ss[si].size();
		REP(i, 0, n){
			REP(j, 0, ans[i].size()){
				std::string s1 = ans[i].substr(j);
				std::string s2 = ss[si].substr(0, ans[i].size()-j);
				if(s1 != s2) continue;

				int pushlen = ss[si].size() - ans[i].size() + j;
				if(ans[i].size() + pushlen < n && min_add_len > pushlen){
					min_add_len = pushlen;
					minrow = i;
					crost = j;
				}
			}
		}

		crost = std::min<int>(crost, ans[minrow].size());
		std::string pushs = ss[si].substr(ans[minrow].size() - crost);
		while(minrow < n && ans[minrow].size() + pushs.size() > n) minrow++;
		if(minrow == n) continue;
		ans[minrow] += pushs;
		used[si] = true;

		//for(auto &s: ans) std::cout << s << '\n'; puts("");
	}

	REP(si, 0, m) if(!used[si]) {

		std::sort(ans, ans+n, [](std::string x, std::string y){
			return x.size() > y.size();
		});

		REP(j, 0, n){
			int ok_cnt = 0;
			REP(i, 0, n){
				if(ans[i].size() <= j) ok_cnt++;
			}
			if(ok_cnt < ss[si].size()) continue;

			int idx = 0;
			REP(i, 0, n){
				if(idx >= ss[si].size()) break;
				if(ans[i].size() <= j){
					ans[i] += std::string(j - ans[i].size(), '.');
					ans[i] += ss[si][idx];
					idx++;
				}
			}
			used[si] = true;
			break;
		}
	}

	for(auto &s: ans){
		if(s.size() < n){
			 s += std::string(n-s.size(), '.');
		}
	}

	for(auto &s: ans){
		std::cout << s << '\n';
	}
	return 0;
}


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

int cnt[100001];//色の有無を表す配列
int C[100001];
bool check[100001];
vector<vector<int> > E(100001);

void dfs(int n, int bef){
    if(cnt[C[n]]==0){
        check[n]=true;
    }
    cnt[C[n]]++;
    for(int i=0; i<E[n].size(); i++){
        if(E[n][i] != bef){
            dfs(E[n][i], n);
        }
    }
    cnt[C[n]]--;//ここ凄い大事、これがないと反対方向の色がカウントされっぱなしになる。
}

int main(){
    int N;
    cin>>N;
    int a, b;
    for(int i=0; i<N; i++){
        cin>>C[i];
    }
    for(int i=0; i<N-1; i++){
        cin>>a>>b;
        E[a-1].push_back(b-1);
        E[b-1].push_back(a-1);
    }
    dfs(0, -1);
    for(int i=0; i<N; i++){
        if(check[i]==true){
            cout<<i+1<<endl;
        }
    }
    return 0;
}

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

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;

constexpr ll INF = (1LL << 60);

struct func{
	ll base, m, M;
	func() : base(0), m(-INF), M(INF) {}
	ll value(ll x){
		ll tmp = x + base;
		tmp = max(m, tmp);
		tmp = min(M, tmp);
		return tmp;
	}
};

void merge(func& f, int type, ll a){
	if (type == 1){
		f.base += a;
		f.m += a;
		f.M += a;
	}
	else if (type == 2){
		if (f.M <= a){
			f.base = 0;
			f.m = a;
			f.M = a;
			return;
		}
		f.m = max(f.m, a);
	}
	else{
		if (f.m >= a){
			f.base = 0;
			f.m = a;
			f.M = a;
			return;
		}
		f.M = min(f.M, a);
	}
}

int main(void){
	int N; cin >> N;
	func f;
	for (int i = 0; i < N; ++i){
		int t; ll a;
		cin >> a >> t;
		merge(f, t, a);
	}
	int Q; cin >> Q;
	while(Q--){
		ll x; cin >> x;
		cout << f.value(x) << endl;
	}
	return 0;
}


//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include <algorithm>
#include <array>
#include <cassert>
//#include <chrono>
#include <cmath>
//#include <cstring>
//#include <functional>
//#include <iomanip>
#include <iostream>
#include <map>
//#include <numeric>
//#include <queue>
//#include <random>
#include <set>
#include <vector>
using namespace std;
#define FAST  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
#define int long long
#define ll int
#define all(a) a.begin(),a.end()
#define rev(a) a.rbegin(),a.rend()
//typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; //less_equal for multiset
#define ar array
#define pb push_back
#define fi(a,b) for(int i=a;i<(b);i++)
#define fj(a,b) for(int j=a;j<(b);j++)
#define fk(a,b) for(int k=a;k<(b);k++)
const double pi=acosl(-1);

void solve()
{
	int n;
	cin>>n;
    vector<vector<int>> same(n+2);
    vector<int> x(n),c(n);
    fi(0,n)
    {
    	cin>>x[i]>>c[i];
    	same[c[i]].pb(x[i]);
    }
    same[n+1]={0,0};
    fi(1,n+1)
    {
    	if(same[i].size()==0) continue;
    	sort(all(same[i]));
    }
    ar<int,2> dp,prev;

    prev[0]=prev[1]=dp[0]=dp[1]=0;
    fk(1,n+2)
    {
    	if(same[k].size()==0) continue;
    	ar<int,2> ndp;
    	ndp[0]=ndp[1]=1e15;
    	fi(0,2)
    	{
	    	if(prev[i]<=same[k][0])
	    	{
	    		// ndp[0]=min(ndp[0],dp[i]+2*(same[k].back()-same[k][0])+same[k][0]-prev[i]);
	    	}
	    	else if(prev[i]>same[k][0]&&prev[i]<=same[k].back())
	    	{
	    		ndp[0]=min(ndp[0],dp[i]+(same[k].back()-same[k][0])+same[k].back()-prev[i]);
	    	}
	    	else
	    	{
	    		ndp[0]=min(ndp[0],dp[i]+(same[k].back()-same[k][0])+prev[i]-same[k].back());
	    	}
	    }
	    fi(0,2)
    	{
	    	if(prev[i]<=same[k][0])
	    	{
	    		ndp[1]=min(ndp[1],dp[i]+(same[k].back()-same[k][0])+same[k][0]-prev[i]);
	    	}
	    	else if(prev[i]>same[k][0]&&prev[i]<=same[k].back())
	    	{
	    		ndp[1]=min(ndp[1],dp[i]+(same[k].back()-same[k][0])+prev[i]-same[k][0]);
	    	}
	    	else
	    	{
	    		// ndp[1]=min(ndp[1],dp[i]+2*(same[k].back()-same[k][0])+prev[i]-same[k].back());
	    	}
	    }
	    // if(same[k].size()==1)
	    // {
	    // 	assert(ndp[0]==ndp[1]);
	    // }
    	dp=ndp;
    	prev[0]=same[k][0];
    	prev[1]=same[k].back();
    }
    cout<<min(dp[0],dp[1])<<'\n';

}

signed main()
{
    FAST;
    int tt=1;
    //cin>>tt;
    while(tt--)
    {
        solve();
    }
}

//int dx[] = {+1,-1,+0,+0,-1,-1,+1,+1}; // Eight Directions
//int dy[] = {+0,+0,+1,-1,+1,-1,-1,+1}; // Eight Directions
//int dx[]= {-2,-2,-1,1,-1,1,2,2}; // Knight moves
//int dy[]= {1,-1,-2,-2,2,2,-1,1}; // Knight moves
// For (a^b)%mod, where b is large, replace b by b%(mod-1).
// a+b = (a|b)+(a&b)
// a+b = 2*(a&b)+(a^b)

//#pragma GCC optimize ("Ofast")
//#pragma GCC target("avx2")
//#pragma GCC optimize("unroll-loops")
//#include <x86intrin.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>

#define PI 3.141592653589793L
#define FAST ios::sync_with_stdio(false); cin.tie(NULL);
// Use for file I/O;
#define FIN string _fname = "input"; \
			string _is = _fname + ".in", _os = _fname + ".out"; \
			freopen(_is.c_str(), "r", stdin); \
			freopen(_os.c_str(), "w", stdout);

#define FIN2 freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define RINIT mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define gsize(x) (int)((x).size())

using namespace std;
//using namespace __gnu_pbds;
//typedef gp_hash_table<int, int, hash<int>> ht;

const char nl = '\n';
const char Nl = '\n';

typedef long long ll;
typedef long double ld;
// typedef unsigned int uint;
typedef unsigned long long ull;

const ll inf = 1e9 + 10;
const ll inf2 = 1e18 + 99LL;
const ld inf3 = 1e14;
const ll mod = 1e9+7, mod2 = 998244353;
const ld eps = 1e-2;
const bool local = false;

const int logn = 8, maxn = 400005, maxm = 10001, maxn2 = 3;

int main() {
    FAST; //RINIT;

    int n;
    cin >> n;
    vector<ll> p(n + 1);
    for (int i = 0; i < n; i++) {
		ll a;
		cin >> a;
		p[i + 1] = p[i];
		if (i&1) p[i + 1] += a;
		else p[i + 1] -= a;
	}

	map<ll, int> ct;

	ll ans = 0;
	for (int i = 1; i <= n; i++) {
		ct[p[i - 1]]++;
		ans += ct[p[i]];
	}
	cout << ans << nl;
}

// © Benq
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
*/


#include <bits/stdc++.h>
#define FOR(i, m, n) for (ll i = m; i < (n); i++)
#define RFOR(i, m, n) for (ll i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
//#define print(ele) cout << (ele) << "\n"
#define print10(ele) cout << fixed << setprecision(10) << (ele) << "\n"

using namespace std;
typedef long long ll;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

void print() { cout << endl; }

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}

int main() {
  int n;
  cin >> n;
  print(n%2==0 ? "White" : "Black");
  return 0;
}

#include<iostream>
using namespace std;
int main()
{
	int N;
	while(cin>>N)
	{
		if(N%2==0)cout<<"White"<<endl;
		else if(N%2==1) cout<<"Black"<<endl;
	}
	return 0;
}


/*
 *Team hhu_6814
 *Author big_yellow_doge
 */
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <string.h>
#include <queue>
#include <map>
#include <stack>
#include <vector>
#include <set>
#include <list>
using namespace std;
//ios::sync_with_stdio(false);
const int MINF = 0x7fffffff;
const int INF = 0x3f3f3f3f;
const int Maxn = 1e5+5;
typedef long long ll;

int main()
{
    int a,mi = 1e9;
    for(int i = 0;i < 4;i++){
        cin >> a;
        mi = min(a,mi);
    }
    cout << mi << endl;
    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 main() {
    int n;
    cin >> n;
    int a = floor(1.08 * n);
    if (a < 206) cout << "Yay!" << endl;
    if (a == 206) cout << "so-so" << endl;
    if (a > 206) cout << ":(" << endl;
}


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

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

	lld n,ans=0;
	cin>>n;
	lld a[n];
	map<lld,lld>m;
	for(int i=0;i<n;i++){
		cin>>a[i];
		m[a[i]%200]++;
	}
	for(auto i:m)
		ans+=((i.second)*(i.second-1))/2;
	cout<<ans<<endl;

	return 0;
}

#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

#define MOD 1000000007

int mpow(int a, int b) {
	int res = 1;
	for (; b; b >>= 1) {
		if (b & 1) res = (int64_t) res * a % MOD;
		a = (int64_t) a * a % MOD;
	}
	return res;
}

#ifdef WIN32
#define getchar_fast getchar
#else
#define getchar_fast getchar_unlocked
#endif

int main() {
	int h = ri();
	int w = ri();
	std::vector<bool> a[h];
	getchar_fast();
	for (auto &i : a) {
		i.resize(w);
		for (int j = 0; j < w; j++) i[j] = getchar_fast() == '.';
		getchar_fast();
	}

	int16_t free[h][w];
	memset(free, 0, sizeof(free));
	for (int i = 0; i < h; i++) {
		int start = 0;
		for (int j = 0; j <= w; j++) if (j == w || !a[i][j]) {
			for (int k = start; k < j; k++) free[i][k] += j - start;
			start = j + 1;
		}
	}
	for (int i = 0; i < w; i++) {
		int start = 0;
		for (int j = 0; j <= h; j++) if (j == h || !a[j][i]) {
			for (int k = start; k < j; k++) free[k][i] += j - start;
			start = j + 1;
		}
	}

	int k = 0;
	for (auto &i : a) k += std::accumulate(i.begin(), i.end(), 0);
	int b2[h + w];
	b2[0] = 1;
	int b2_rev[h + w];
	b2_rev[0] = mpow(2, k);
	for (int i = 1; i < h + w; i++) {
		b2[i] = b2[i - 1] + b2[i - 1];
		if (b2[i] >= MOD) b2[i] -= MOD;
		b2_rev[i] = (int64_t) b2_rev[i - 1] * 500000004 % MOD;
	}

	int res = 0;
	for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) {
		if (!a[i][j]) continue;
		// std::cerr << free[i][j] - 1 << std::endl;
		res = (res + (int64_t) (b2[free[i][j] - 1] - 1 + MOD) * b2_rev[free[i][j] - 1]) % MOD;
	}
	std::cout << res << std::endl;

	return 0;
}


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

const int MAX_N = 1e2, MOD = 1e9 + 7, INF = 1e9;
int n, x[MAX_N], y[MAX_N];

int main() {
    ci(n);
    rep(i, n) ci2(x[i], y[i]);
    bool ans = false;
    for (int i = 2; i < n; i++) {
        for (int j = 1; j < i; j++) {
            for (int k = 0; k < j; k++) {
                if ((x[i] - x[k]) * (y[j] - y[k]) ==
                    (y[i] - y[k]) * (x[j] - x[k])) ans = true;
            }
        }
    }
    if (ans) co("Yes");
    else co("No");
    return 0;
}

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

using namespace std;

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

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

int main(){
    int a[4];
    rep(i, 4) cin >> a[i];
    int s = 0;
    rep(i, 4) s += a[i];
    rep(i, 1<<4){
        int d = 0;
        rep(j, 4){
            if(((i>>j)&1)) d += a[j];
        }
        if(s - d == d){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


#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 main() {
    vector<int> v(4);
    rep(i, 4) cin >> v[i];

    ll total = 0;
    rep(i, 4) total += v[i];
    for (int bit = 0; bit < (1 << 4); ++bit) {
        ll sum_bit = 0;
        for (int i = 0; i < 4; ++i) {
            if (bit & (1 << i)) {
                sum_bit += v[i];
            }
        }

        if (sum_bit * 2 == total) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
}

#include<bits/stdc++.h>
#define fast  ios::sync_with_stdio(false); cin.tie(NULL);
#define int  long long
#define f first
#define s second
#define endl  "\n"
//#define m 1000000007
#define out(v,n) for(int i=0;i<n;i++) cout<<v[i]<<" "; cout<<endl;
using namespace std;
signed main(){
  //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
  fast
 	//int n,ans=LLONG_MAX; cin>>n;
	vector<int> v(4);
	for(int i=0;i<4;i++) cin>>v[i];
	sort(v.begin(),v.end());
	if(v[0]+v[1]+v[2]==v[3] || v[0]+v[2]==v[1]+v[3] || v[1]+v[2]==v[0]+v[3]) cout<<"Yes";
	else cout<<"No";
}


#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const ll INF = ll(1e18) + 5;
string atcoder = "atcoder";

void solve() {
    string S;
    cin >> S;
    if (S > atcoder) {
        cout << 0 << endl;
        return;
    }
    string revS = S;
    sort(revS.rbegin(), revS.rend());
    if (atcoder >= revS) {
        cout << -1 << endl;
        return;
    }
    int n = S.size();
    ll ans = n;
    // Sの中でaより大きな最初のindexを求める.
    rep(i, n) {
        if (S[i] > 'a') {
            ans = i;
            break;
        }
    }
    // Sの中でtより大きな最初のindexを求める.
    for (int i = 2; i < n; i++) {
        if (S[i] > 't') {
            ans = min(ans, i - 1ll);
            break;
        }
        if (S[i] == 't') {
            ans = min(ans, (ll)i);
        }
    }
    cout << ans << endl;
}

int main() {
    int T;
    cin >> T;
    rep(i, T) {
        solve();
    }

    return 0;
}

#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll n,low,high,mid,x,z,a;
void solve(ll the)
{
    ll i,j,k,b,c,d,m,l,r,sum=0,ans=0,temp,t;
    scanf("%lld",&n);a=n+1;
    low=0;high=sqrt((8*a)+1)-1;high/=2;
    while(low<=high){
    	mid=low+(high-low)/2;
    	x=1;
    	if(mid&1){
    		x=(mid+1)/2;x*=mid;
    	}
    	else{
    		x=mid/2;x*=(mid+1);
    	}
    	if(x<=a){
    		z=mid;
    		low=mid+1;
    	}
    	else{
    		high=mid-1;
    	}
	   // printf("%lld\n",x);
    }
    ans=1+(n-z);
    //printf("%lld\n",z);
    //cout << "Hello" << endl;
    cout << ans;

}
int main()
{
	long long int t=1,c=1;
	// scanf("%lld",&t);
	while(t--){
		solve(c);
		c++;
	}
	return 0;
}


#include<iostream>
#include<vector>
#include<string>
#include<set>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

class UnionFind {
private:
    vector<int> parent_;
    vector<int> node_rank_;
    vector<int> sizes_;
public:
    UnionFind(int node_num):
        parent_(vector<int>(node_num)), node_rank_(vector<int>(node_num)), sizes_(vector<int>(node_num)) {
        for (int i = 0; i < node_num; ++i) {
            parent_[i] = i;
            node_rank_[i] = 0;
            sizes_[i] = 1;
        }
    }
    int getRoot(int u) {
        return parent_[u] == u ? u : parent_[u] = getRoot(parent_[u]);
    }
    bool isSame(int u, int v) {
        return getRoot(u) == getRoot(v);
    }
    void unite(int u, int v) {
        u = getRoot(u);
        v = getRoot(v);
        if (u == v) return;
        if (node_rank_[u] < node_rank_[v]) {
            parent_[u] = v;
            sizes_[v] += sizes_[u];
        }
        else {
            parent_[v] = u;
            sizes_[u] += sizes_[v];
            if (node_rank_[u] == node_rank_[v]) {
                node_rank_[u]++;
            }
        }
    }
    int getSize(int u) {
        return sizes_[getRoot(u)];
    }
};

using P = pair<ll, int>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> A(N), T(N);
    rep(i, 0, N) {
        cin >> A[i] >> T[i];
    }
    int Q;
    cin >> Q;
    vector<ll> X(Q);
    rep(i, 0, Q) {
        cin >> X[i];
    }
    set<P> S;
    rep(i, 0, Q) {
        S.emplace(X[i], i);
    }
    UnionFind uf(Q);
    ll diff = 0;
    rep(i, 0, N) {
        if (T[i] == 1) {
            diff -= A[i];
        } else if (T[i] == 2) {
            // A[i]+diff以下をマージ
            int idx = -1;
            while (!S.empty() && (*S.begin()).first <= A[i] + diff) {
                P now = *S.begin();
                if (idx < 0) {
                    idx = now.second;
                }
                uf.unite(idx, now.second);
                S.erase(now);
            }
            if (idx >= 0) {
                X[idx] = A[i] + diff;
                S.emplace(X[idx], idx);
            }
        } else {
            // A[i]+diff以上をマージ
            int idx = -1;
            while (!S.empty() && (*S.rbegin()).first >= A[i] + diff) {
                P now = *S.rbegin();
                if (idx < 0) {
                    idx = now.second;
                }
                uf.unite(idx, now.second);
                S.erase(now);
            }
            if (idx >= 0) {
                X[idx] = A[i] + diff;
                S.emplace(X[idx], idx);
            }
        }
    }
    rep(i, 0, Q) {
        cout << X[uf.getRoot(i)] - diff << endl;
    }
    return 0;
}

#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>

using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = (1LL << 61);
ll mod = 1000000007;
// 約数列挙
vector<long long> 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()); // 昇順に並べる
	return ret;
}

// 変数
int n;
int x[210], y[210];
ll r[210];

// スコア計算
ll f(vector<ll>a, vector <ll> b, vector<ll>c, vector<ll>d) {
	long double sum = 0;
	for (int i = 0; i < n; i++) {
		if ((a[i] <= x[i] && x[i] < c[i]) && (b[i] <= y[i] && y[i] <= d[i])) {
			ll now = (c[i] - a[i])*(d[i] - b[i]);
			sum += 1.0 - (1.0 - ((long double)min(now, r[i]) / (long double)max(now, r[i])) * ((long double)min(now, r[i]) / (long double)max(now, r[i])));
		}
	}
	sum /= n;
	sum *= 1e9;
	ll ans = (ll)sum;
	return ans;
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	// 入力
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i] >> r[i];
	}

	vector<pair<pair<int, int>, pair<ll, int>>>p;
	for (int i = 0; i < n; i++) {
		p.push_back({ {x[i],y[i]}, {r[i], i} });
	}
	sort(p.begin(), p.end());
	vector<int>ansa(n), ansb(n), ansc(n), ansd(n);
	vector<vector<pair<int, pair<ll, int>>>>G(10010);
	for (int i = 0; i < n; i++) {
		G[p[i].first.first].push_back({ p[i].first.second, p[i].second });
	}
	int bx = 0;
	for (int i = 0; i < 10010; i++) {
		int s = G[i].size();
		if (s == 0)continue;
		if (s >= 2) {
			int by = 0;
			for (int j = 0; j < s; j++) {
				int idx = G[i][j].second.second;
				ansa[idx] = bx; ansb[idx] = by;
				ansc[idx] = i + 1; ansd[idx] = G[i][j].first + 1;
				by = G[i][j].first + 1;
			}
		}
		else {
			int idx = G[i][0].second.second;
			int nowr = G[i][0].second.first;
			int tmpy = min(10000, nowr / (i + 1 - bx));
			if (tmpy < G[i][0].first + 1)tmpy = G[i][0].first + 1;
			int now = (i + 1 - bx) * tmpy;
			int K = 0;
			if (now > nowr) {
				int sy = nowr / (i + 1 - bx);
				K = tmpy - sy;
			}
			ansa[idx] = bx; ansb[idx] = K;
			ansc[idx] = i + 1; ansd[idx] = tmpy;
		}
		bx = i + 1;
	}
	for (int i = 0; i < n; i++) {
		cout << ansa[i] << " " << ansb[i] << " " << ansc[i] << " " << ansd[i] << endl;
	}
	return 0;
}


//GIVE ME AC!!!!!!!!!!!!!!!!!
//#pragma GCC target("avx")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define floatset() fixed<<setprecision(15)
#define all(n) n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
#define rep(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define pb push_back
#define eb emplace_back
#define INT(...) int __VA_ARGS__;scan(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;scan(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;scan(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;scan(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;scan(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;scan(__VA_ARGS__)
using namespace std;
using vl=vector<ll>;
using vi=vector<int>;
using vs=vector<string>;
using vc=vector<char>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using vvc=vector<vc>;
using vd=vector<double>;
using vp=vector<P>;
using vb=vector<bool>;
using P=pair<ll,ll>;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const ll inf =1e18;
const ll MOD=1000000007;
const ll mod=998244353;
const double pi=acos(-1);
template<typename T1,typename T2 >
ostream &operator<<(ostream&os,const pair<T1,T2>&p) {
  os<<p.first<<" "<<p.second;
  return os;
}
template<typename T1,typename T2>
istream &operator>>(istream&is,pair<T1,T2>&p) {
  is>>p.first>>p.second;
  return is;
}
template<typename T>
ostream &operator<<(ostream&os,const vector<T>&v) {
  for(int i=0;i<(int)v.size();i++) {
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  return os;
}
template<typename T>
istream &operator>>(istream&is,vector<T>&v) {
  for(T &in:v)is>>in;
  return is;
}
void scan(){}
template<class Head,class... Tail>
void scan(Head&head,Tail&... tail) {
  cin>>head;
  scan(tail...);
}
template<class T>
void print(const T &t) { cout << t << '\n'; }
template<class Head, class... Tail>
void print(const Head &head, const Tail &... tail) {
  cout << head << ' ';
  print(tail...);
}
template<class... T>
void fin(const T &... a) {
  print(a...);
  exit(0);
}
template<typename T1,typename T2>
inline bool chmax(T1&a,T2 b){return a<b&&(a=b,true);}
template<typename T1,typename T2>
inline bool chmin(T1&a,T2 b){return a>b&&(a=b,true);}
random_device seed_gen;
mt19937 engine(seed_gen());
int main(){
  LL(n,m);
  vs a(m);
  cin>>a;
  shuffle(all(a),engine);
  ll now=0;
  rep(i,0,n){
    ll cnt=0;
    string ans="";
    while(cnt+(ll)(a[now].size())<=n){
      cnt+=a[now].size();
      ans+=a[now];
      now++;
    }
    rep(i,0,n-cnt){
      ll x=engine();
      x%=8;
      cout<<(char)('A'+x);
    }
    cout<<ans<<endl;
  }
}

#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<tuple>
#include<array>
#include<map>
#include<memory>

int main()
{
    int64_t N;
    std::cin >> N;
    std::vector<int64_t> A(N);
    for (int64_t n = 0; n < N; ++n)
    {
        int64_t a;
        std::cin >> a;
        A[n] = a;
    }
    std::sort(A.begin(), A.end());

    int64_t c = 0;
    int64_t s = 1;
    for (size_t i = 0; i < A.size(); ++i)
    {
        s *= ((A[i] - c) + 1);
        s %= 1000000007;
        c = A[i];
    }

    std::cout << s << std::endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define pb push_back
#define int long long int
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define F first
#define S second
#define mod 1000000007
#define MOD 998244353
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define deb(x) cout<< ">" << #x << '=' << x << endl;
#define read(v) for(auto &it:v) cin>>it;
const int  N = 2e5 + 5;
void solve() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << min({a, b, c, d}) << endl;

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

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

int main(){
    vector<int> A(4);
    for(int i=0;i<4;i++) cin >> A[i];
    int ans = 99999;

    for(int i=0;i<4;i++){
        ans = min(ans,A[i]);
    }

    cout << ans << endl;

    return 0;
}


#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2")
#pragma comment(linker, "/stack:200000000")

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

using namespace std;
using namespace __gnu_pbds;

#define int long long
#define pb push_back
#define pf push_front
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define f first
#define s second
#define sz(x) (int)x.size()
#define endl "\n"
#define forn(i,n) for(int i=0;i<n;++i)
#define fore(i,l,r) for(int i=int(l);i<=int(r);++i)
#define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++)
#define fill(a,value) memset(a,value,sizeof(a));
#define gcd(a,b) __gcd((a),(b))
#define watch1(x) cout<<(x)<<endl
#define watch2(x,y) cout<<(x)<<" "<<(y)<<endl
#define watch3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;

const int INF = 9e18;
const int mod = 998244353;
const int N = 2e5 + 5;

int i, n, a[N], b[N], p[N], vis[N];

void solve() {
    cin >> n;
    vpii w, ans;
    for (i = 1; i <= n; i++) {
        cin >> a[i];
        w.pb({a[i], i});
    }
    for (i = 1; i <= n; i++) {
        cin >> b[i];
    }
    map<int, int> have, mp;
    for (i = 1; i <= n; i++) {
        cin >> p[i];
        have[p[i]] = i;
        mp[i] = p[i];
    }
    for (i = 1; i <= n; i++) {
        if (i != p[i] && a[i] <= b[p[i]]) {
            cout << -1 << endl;
            return;
        }
    }
    int cnt = 0;
    for (i = 1; i <= n; i++) {
        if (!vis[i]) {
            int v = i;
            cnt++;
            while (!vis[v]) {
                vis[v] = 1;
                v = p[v];
            }
        }
    }
    cout << n - cnt << endl;
    sort(all(w));
    for (i = 1; i <= n; i++) {
        if (mp[w[i - 1].s] == w[i - 1].s) {
            continue;
        }
        int give = mp[w[i - 1].s], get = have[w[i - 1].s];
        ans.pb({w[i - 1].s, get});
        have[give] = get;
        mp[get] = give;
    }
    for (auto &i : ans) {
        cout << i.f << " " << i.s << endl;
    }
}

signed main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fastio;
    int t;
    //cin >> t;
    t = 1;
    while (t--) {
        solve();
    }
    return 0;
}

#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("trapv")
#pragma GCC target("sse4")

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

typedef pair<int, int> pi;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef long long int ll;
typedef unsigned long long int  ull;
typedef priority_queue<ll> mxhpl;
typedef priority_queue<int> mxhpi;
typedef priority_queue<ll, vector<ll>, greater<ll>> mnhpl;
typedef priority_queue<int, vector<int>, greater<int>> mnhpi;

#define rep(i,start,end) for(ll i = start; i <= end; ++i)
#define rrep(i,end,start) for(ll i = end; i >= start; --i)
#define parr(a,n) rep(i,0,n-1){cout << a[i] << " ";}cout<<"\n"
#define sarr(a,n) rep(i,0,n-1)cin >> a[i]
#define pb push_back
#define F first
#define S second
#define all(a) a.begin(),a.end()
#define mset(a,x) memset(a, x, sizeof(a))
#define ps(x,y) fixed<<setprecision(y)<<x //cout << ps(ans, decimal places);
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)

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

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

// Fast IO
void IO() {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
#endif
}

#define MOD 1000000007

//CODE
/*******************************************************/
#define MX 200001

ll n;

void solve() {
  cin >> n;
  vl a(n), b(n), c(n), whoHasMyBag(n);

  sarr(a, n);
  sarr(b, n);
  sarr(c, n);
  vector<pll> wp;
  rep(i, 0, n - 1) {
    if (c[i] - 1 != i && a[i] <= b[c[i] - 1]) {
      cout << "-1\n";
      return;
    }
    c[i]--;
    wp.pb({ a[i],i });
    whoHasMyBag[c[i]] = i;
  }

  sort(all(wp));
  vector<pll> ans;
  for (auto p : wp) {
    if (c[p.S] == p.S) continue;
    ans.pb({ p.S + 1,whoHasMyBag[p.S] + 1 });

    c[whoHasMyBag[p.S]] = c[p.S];
    whoHasMyBag[c[whoHasMyBag[p.S]]] = whoHasMyBag[p.S];
  }

  // debug("TEST");
  cout << ans.size() << "\n";
  for (auto p : ans) {
    cout << p.F << " " << p.S << "\n";
  }
  // debug(ans, c);
}

int main() {
  IO();
  int t = 1;

  // cin >> t;

  while (t--) {
    solve();
  }
  return 0;
}

/*******************************************************/


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

int main(){

 //input
 int N;
 cin >> N;

 string name[N];
 int height[N];
 vector<int> height_checker(N);

 for(int i = 0; i < N; i++){
   cin >> name[i] >> height[i];
   height_checker.at(i) = height[i];
 }

 //高さをsort
 sort(height_checker.begin(), height_checker.end());

 //N-1番目の山の高さを聞き、それと合う山を探す。
 int SecondMountain = height_checker.at(N-2);
  for(int j = 0; j < N; j++){
   if(height[j] == SecondMountain){cout << name[j] << endl; break;}
  }

  return 0;
}

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

#define fastio                  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define input_output            freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

template <typename Arg1>
void prn(Arg1&& arg1) { cout<<arg1<<"\n";}
template <typename Arg1, typename... Args>
void prn(Arg1&& arg1, Args&&... args) { cout<<arg1<<" "; prn(args...); }

template <typename Arg1>
void prs(Arg1&& arg1) { cout<<arg1<<" ";}
template <typename Arg1, typename... Args>
void prs(Arg1&& arg1, Args&&... args) { cout<<arg1<<" "; prs(args...); }

template <typename Arg1>
void read(Arg1&& arg1) { cin>>arg1; }
template <typename Arg1, typename... Args>
void read(Arg1&& arg1, Args&&... args) { cin>>arg1; read(args...); }

#define int                     long long
#define all(ds)                 ds.begin(), ds.end()
#define uniq(v)                 (v).erase(unique(all(v)),(v).end())
#define gcd(x,y)                __gcd(x,y)
#define rep(i,a,b)              for(int i=a;i<b;i++)
#define precise(x)              cout<<fixed<<setprecision(x)
#define endl                    "\n"

const long long INF = 1e18;
const int32_t MOD = 1e9+7;
const int N = 2e5+5;

int n, m, k, q, r, l, x, y, z;
int a[N], b[N], c[N];
string s, t;
// int ans = 0;
vector<int>edges[N];
vector<int>mn(N, INF); // min cost of gold among all the cities which lead to the current node

void solve(){
    read(n,m);
    rep(i,1,n+1)read(a[i]);
    rep(i,0,m){
        read(x,y);
        edges[x].push_back(y);
    }
    int ans = -INF;
    for(int i = 1; i <= n; ++i){
        for(int j: edges[i]){
            mn[j] = min(mn[j], min(mn[i], a[i]));
        }
        if(mn[i] != INF){
            ans = max(ans, a[i]-mn[i]);
        }
    }
    prn(ans);
}

signed main()
{
#ifndef ONLINE_JUDGE
    input_output
#else
    fastio
#endif

#ifdef SIEVE
    sieve();
#endif

#ifdef NCR
    init();
#endif

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

    return 0;
}


#include <cstdio>
typedef long long ll;
inline void in(ll &x) {
	x=0;
	ll f=1;
	char ch=getchar();
	while (ch<'0'||ch>'9') {
		if (ch=='-') f=-1;
		ch=getchar();
	}
	while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	x*=f;
}
inline void out(ll x) {
	if (x<0) putchar('-'),x=-x;
	if (x>9) out(x/10);
	putchar(x%10+'0');
}
ll n;
bool ok[10005];
int main() {
	in(n);
	for (ll i=1; i<=n; ++i) {
		ll x;
		in(x);
		if (x<1||x>n||ok[x]) {
			puts("No");
			return 0;
		}
		ok[x]=1;
	}
	puts("Yes");
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
 int N;
  cin >> N;
  if(N>=0)cout<<N;
  else cout<<0;
  return 0;
}


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

#define int             long long
#define w(x)            int x; cin>>x; while(x--)
#define endl            ("\n")
#define f(i, a, n)      for(int i=a; i<n; i++)
#define cc(r)           cout<<r<<" "
#define ce(r)           cout<<r<<endl

void inout()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

}
int nCrModpDP(int n, int r, int p)
{
    int C[r + 1];
    memset(C, 0, sizeof(C));

    C[0] = 1;
    for (int i = 1; i <= n; i++)
    {
        for (int j = min(i, r); j > 0; j--)
            C[j] = (C[j] + C[j - 1]) % p;
    }
    return C[r];
}

int nCrModpLucas(int n, int r, int p)
{
    if (r == 0)
        return 1;
    int ni = n % p, ri = r % p;
    return (nCrModpLucas(n / p, r / p, p) * nCrModpDP(ni, ri, p)) % p;
}
int32_t main()
{
    inout();
    int n;
    cin >> n;
    int r[n], a[n], ans = 0;
    f(i, 0, n) {
        r[i] = nCrModpLucas(n - 1, i, 3);
    }
    char k;
    f(i, 0, n) {
        cin >> k;
        if (k == 'B')
            a[i] = 0;
        else if (k == 'W')
            a[i] = 1;
        else
            a[i] = 2;
    }
    f(i, 0, n) {
        ans = (ans + (a[i] * r[i]) % 3) % 3;
    }
    if ((n & 1) == 0) {
        ans = (-ans + 3) % 3;
    }
    if (ans == 0)
        ce('B');
    else if (ans == 1)
        ce('W');
    else
        ce('R');

}


#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <list>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template<typename T = int> using V = vector<T>;
template<typename T = int> using VV = vector<vector<T>>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}

int solve(int n,vector<int>L, vector<int>R){
    vector<pii>a(n);
    rep(i,n){
        a[i] = pii(L[i], R[i]);
    }
    sort(a.begin(), a.end(), [](pii x, pii y){
        return x.second < y.second;
    });
    int pre = -1;
    int ans = 0;
    for(auto x: a){
        if(pre < x.first){
            ans++;
            pre = x.second;
        }
    }
    return ans;
}
int solve2(int n, vector<int>L, vector<int>R){
    vector<pii>a(n);
    rep(i,n){
        a[i] = pii(L[i], R[i]);
    }
    sort(a.begin(), a.end(), [](pii x, pii y){
        return x.first < y.first;
    });
    int pre = -1;
    int ans = 0;
    for(auto x: a){
        if(pre < x.first){
            ans++;
            pre = x.second;
        }
    }
    return ans;
}
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    if(m < 0){
        cout << -1 << endl;
        return 0;
    }
    vector<int>a(n), b(n);
    int t = 4;
    //[0,1], 2[3,4], 5[
    //[1,2] 3 [4,5]
    rep(i,n-1){
        a[i+1] = t++;
        b[i+1] = t++;
        t++;
    }
    a[0] = 1;
    b[0] = 3;
    rep(i,m+1)b[0] += 3;
    if(solve(n,a,b)-solve2(n,a,b)!=m){
        cout << -1 << endl;
        return 0;
    }
    rep(i,n){
        cout << a[i] << " " << b[i] << "\n";
    }
}


#define _USE_MA_DEFINES
#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
#include <random>
#include <cassert>
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define REPE(i, n) for (int (i)=0; (i) <= (n); (i)++)
#define CONTAINS_MAP(m, a) ((m).find((a)) != m.end())
#define CONTAINS_SET(m, a) ((m).find((a)) != m.end())
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; exit(0); }
void Yes() { cout << "Yes" << endl; exit(0); }
void No() { cout << "No" << endl; exit(0); }

int N;
int X[200001];
int Y[200001];
int M;
int Q;

const int PLUS_X = 1;
const int MINUS_X = -1;
const int PLUS_Y = 2;
const int MINUS_Y = -2;

struct Op
{
	int p;
	int f;
};

Op _op_x[200001];
Op _op_y[200001];

int func(Op op, int x, int y)
{
	int ret = 0;

	if (op.f == PLUS_X)
	{
		ret = x;
	}
	if (op.f == MINUS_X)
	{
		ret = -x;
	}
	if (op.f == PLUS_Y)
	{
		ret = y;
	}
	if (op.f == MINUS_Y)
	{
		ret = -y;
	}

	ret += op.p;
	return ret;
}

signed main()
{
	cin >> N;
	REP(i, N) cin >> X[i] >> Y[i];

	_op_x[0].p = 0;
	_op_x[0].f = PLUS_X;
	_op_y[0].p = 0;
	_op_y[0].f = PLUS_Y;

	cin >> M;
	for (int i = 1; i <= M; i++)
	{
		int o;
		cin >> o;
		if (o == 1)
		{
			_op_x[i].p = _op_y[i - 1].p;
			_op_x[i].f = _op_y[i - 1].f;
			_op_y[i].p = -_op_x[i - 1].p;
			_op_y[i].f = -_op_x[i - 1].f;
		}
		else if (o == 2)
		{
			_op_x[i].p = -_op_y[i - 1].p;
			_op_x[i].f = -_op_y[i - 1].f;
			_op_y[i].p = _op_x[i - 1].p;
			_op_y[i].f = _op_x[i - 1].f;
		}
		else if (o == 3)
		{
			int p;
			cin >> p;
			_op_x[i].p = 2 * p - _op_x[i - 1].p;
			_op_x[i].f = -_op_x[i - 1].f;
			_op_y[i].p = _op_y[i - 1].p;
			_op_y[i].f = _op_y[i - 1].f;
		}
		else if (o == 4)
		{
			int p;
			cin >> p;
			_op_x[i].p = _op_x[i - 1].p;
			_op_x[i].f = _op_x[i - 1].f;
			_op_y[i].p = 2 * p - _op_y[i - 1].p;
			_op_y[i].f = -_op_y[i - 1].f;
		}
	}

	cin >> Q;
	REP(i, Q)
	{
		int a, b;
		cin >> a >> b;

		Op opx = _op_x[a];
		Op opy = _op_y[a];
		int x = X[b - 1];
		int y = Y[b - 1];

		int nx = func(opx, x, y);
		int ny = func(opy, x, y);

		cout << nx << " " << ny << endl;
	}
}

#include<bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
using namespace std;
inline int read(){
	int X=0;bool flag=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')flag=0;ch=getchar();}
	while(ch>='0'&&ch<='9'){X=(X<<1)+(X<<3)+ch-'0'; ch=getchar();}
	if(flag)return X;
	return ~(X-1);
}
int n,a[510][510],ansa[510],ansb[510],minn=1e9+7,minnn=1e9+7;
inline bool check(){
	for(int i=2;i<=n;i++){
		ansa[i]=a[i][1]-ansb[1],ansb[i]=a[1][i]-ansa[1];
		if(ansa[i]<0||ansb[i]<0)return 0;
	}
	for(int i=2;i<=n;i++)
	for(int j=2;j<=n;j++)
	if(ansa[i]+ansb[j]!=a[i][j])return 0;
	return 1;
}
int main(){
	n=read();
	for(int i=1;i<=n;i++)
	for(int j=1;j<=n;j++){
		a[i][j]=read();
		if(i>1&&j>1)
		if((a[i][j]+a[i-1][j]+a[i][j-1]+a[i-1][j-1])&1){
			puts("No");
			return 0;
		}
	}
	for(int i=1;i<=n;i++)minn=min(minn,a[1][i]),minnn=min(minnn,a[i][1]);
	for(int k=minn;k>=0;k--){
		if(a[1][1]-k<minnn)continue;
		ansa[1]=k,ansb[1]=a[1][1]-k;
		if(check()){
			puts("Yes");
			for(int i=1;i<=n;i++)printf("%d ",ansa[i]);
			puts("");
			for(int i=1;i<=n;i++)printf("%d ",ansb[i]);
			return 0;
		}
		ansa[1]=a[1][1]-k,ansb[1]=k;
		if(check()){
			puts("Yes");
			for(int i=1;i<=n;i++)printf("%d ",ansa[i]);
			puts("");
			for(int i=1;i<=n;i++)printf("%d ",ansb[i]);
			return 0;
		}
	}
	puts("No");
	return 0;
}


#include <bits/stdc++.h>

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

using namespace std;
using lint=long long;

template<class T> struct edge{
	int to;
	T wt;
	edge(int to,const T& wt):to(to),wt(wt){}
};
template<class T> using weighted_graph=vector<vector<edge<T>>>;

template<class T>
void add_directed_edge(weighted_graph<T>& G,int u,int v,const T& wt){
	G[u].emplace_back(v,wt);
}

template<class T>
pair<vector<T>,bool> Bellman_Ford(const weighted_graph<T>& G,int s){
	const T INF=numeric_limits<T>::max();

	int n=G.size();
	vector<T> d(n,INF);
	d[s]=0;
//	rep(_,n-1){
	rep(_,n){
		bool upd=false;
		rep(u,n) if(d[u]<INF) for(const auto& e:G[u]) {
			int v=e.to;
			if(d[v]>d[u]+e.wt) d[v]=d[u]+e.wt, upd=true;
		}
		if(!upd) return {d,true};
		if(_==n-1 && upd) return {d,false};
	}

	queue<int> Q;
	rep(u,n) if(d[u]<INF) Q.emplace(u);
	while(!Q.empty()){
		int u=Q.front(); Q.pop();
		for(const auto& e:G[u]){
			int v=e.to;
			if(d[v]>-INF && (d[u]==-INF || d[v]>d[u]+e.wt)) d[v]=-INF, Q.emplace(v);
		}
	}
	return {d,true};
}

/*
template<class T>
bool find_negative_cycle(const weighted_graph<T>& G){
	int n=G.size();
	vector<T> d(n);
	rep(t,n){
		bool relaxed=false;
		rep(u,n) for(const auto& e:G[u]) {
			if(d[e.to]<d[u]+e.wt){
				d[e.to]=d[u]+e.wt;
				relaxed=true;
				if(t==n-1) return true;
			}
		}
		if(!relaxed) break;
	}
	return false;
}
*/

int main(){
	int n,m; scanf("%d%d",&n,&m);
	vector<lint> w(n),l(m),v(m);
	rep(i,n) scanf("%lld",&w[i]);
	rep(j,m) scanf("%lld%lld",&l[j],&v[j]);

	if(*max_element(w.begin(),w.end())>*min_element(v.begin(),v.end())){
		puts("-1");
		return 0;
	}

	{
		vector<int> p(m);
		iota(p.begin(),p.end(),0);
		sort(p.begin(),p.end(),[&](int i,int j){
			return make_pair(v[i],-l[i])<make_pair(v[j],-l[j]);
		});

		vector<lint> v2,l2;
		rep(j,m){
			if(v2.empty() || l2.back()<l[p[j]]){
				v2.emplace_back(v[p[j]]);
				l2.emplace_back(l[p[j]]);
			}
		}
		v=v2;
		l=l2;
		m=v.size();
	}

	lint lo=-1,hi=1e9;
	while(hi-lo>1){
		lint mi=(lo+hi)/2;

		bool ok=false;
		vector<int> p(n);
		iota(p.begin(),p.end(),0);
		do{
			vector<lint> wsum(n+1);
			rep(i,n) wsum[i+1]=wsum[i]+w[p[i]];

			weighted_graph<lint> G(n);
			add_directed_edge(G,0,n-1,mi);
			rep(i,n-1){
				add_directed_edge(G,i+1,i,0LL);
			}
			rep(i,n) for(int j=i+1;j<n;j++) {
				int idx=lower_bound(v.begin(),v.end(),wsum[j+1]-wsum[i])-v.begin()-1;
				if(idx>=0){
					add_directed_edge(G,j,i,-l[idx]);
				}
			}

			if(Bellman_Ford(G,0).second){
				ok=true;
				break;
			}
		}while(next_permutation(p.begin(),p.end()));

		if(ok) hi=mi;
		else   lo=mi;
	}
	printf("%lld\n",hi);

	return 0;
}

#include <bits/stdc++.h>
#pragma GCC optimize(2)
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<cstring>
#include<bitset>
#include<stack>
#include<time.h>

#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define ALL(x) x.begin(),x.end()
#define sz(a) ((int)a.size())
#define getmid ((l+r)>>1)
#define mst(var,val) memset(var,val,sizeof(var))
#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define lowbit(x) x&(-x)
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ls rt<<1
#define rs rt<<1|1
using namespace std;
#ifdef local
#define dbg(args...) cout << #args << " -> ", err(args);
void err(){ cout << endl; }
template<typename T, typename... Args>
void err(T a, Args... args){ cout << a << ' '; err(args...); }
#else
#define dbg(args...)
#endif // local

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <int, ll> pil;
typedef pair <double, double> pdd;
const int inf=0x3f3f3f3f;
const long long INF=0x3f3f3f3f3f3f3f3fLL;
const double PI=acos(-1.0);
const long double eps=1e-8;
const int mod=1e9+7;
const int maxn=2e5+100;
const int N=2e5+100;
const int M=(1<<20)+10;
const ll mm=(1LL<<32);

template <class T>
inline void read(T &x)
{
    x = 0;
    char c = getchar();
    bool f = 0;
    for (; !isdigit(c); c = getchar())
        f ^= c == '-';
    for (; isdigit(c); c = getchar())
        x = x * 10 + (c ^ 48);
    x = f ? -x : x;
}

template <class T>
inline void write(T x)
{
    if (x < 0)
    {
        putchar('-');
        x = -x;
    }
    T y = 1;
    int len = 1;
    for (; y <= x / 10; y *= 10)
        ++len;
    for (; len; --len, x %= y, y /= 10)
        putchar(x / y + 48);
}
ll qpow(ll a,ll b,ll mod)
{
    ll ans=1;
    while(b)
    {
        if(b&1)
            ans=(ans*a)%mod;
        b>>=1;
        a=(a*a)%mod;
    }
    return ans;
}

int main()
{
#ifdef local
    freopen("in.txt","r",stdin);
#endif // local
    IOS;cout.tie(0);
    int n,m;cin>>n>>m;
    if(m==0)
    {
        int tag=1;
        for(int i=1;i<=n;++i)
        {
            cout<<tag<<" "<<tag+1<<"\n";
            tag+=2;
        }
        return 0;
    }
    if(m<0||(m>n-2)){
        cout<<-1<<"\n";return 0;
    }
        int mx=2+2*m+2;
        cout<<1<<" "<<mx<<"\n";
        int tag=2;
        for(int i=1;i<=m+1;++i)
        {
            cout<<tag<<" "<<tag+1<<"\n";tag+=2;
        }
        mx++;
        for(int i=1;i<=n-m-2;++i){
            cout<<mx<<" "<<mx+1<<"\n";mx+=2;
        }

    return 0;
}


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

#define ll long long
#define ld long double
#define u unsigned
#define endl '\n'
#define mod 1000000007
#define quick ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

void solve(){
  ll n,k;
  cin>>n>>k;
  string str="";
  while(k--){
      if(n%200==0){
          n/=200;
      }
      else{
           str = to_string(n);
          string s = to_string(200);
          str+=s;
          n = stod(str);
      }
  }
  cout<<n<<endl;
}

int main() {

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

  while(t--){

      solve();
  }

}

#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

void mainmain(){
	LL n, k;
	cin >> n >> k;
	REP(i, k){
		if(n % 200){ n = n * 1000 + 200; }
		else{ n /= 200; }
	}
	cout << n << endl;
}

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


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <typeinfo>
#include <unordered_set>

using namespace std;
typedef long long ll;

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

	for (int i = c;;i++) {
		if (a == 0 && b == 0) {
			if (c == 1) {
				cout << "Takahashi";
				break;
			}
			else if (c == 0) {
				cout << "Aoki";
				break;
			}
		}

		if (a <= 0) {
			cout << "Aoki";
			break;
		}
		else if (b <= 0) {
			cout << "Takahashi";
			break;
		}
		if (i % 2 == 0)a--;
		if (i % 2 == 1)b--;
	}

}

#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
   if(a==b){
      if(c==0){
        cout<<"Aoki";
      }
      else{
       cout<<"Takahashi";
      }
   }
   else if(a>b){
    cout<<"Takahashi";
   }
   else{
    cout<<"Aoki";
   }
  return 0;
}


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

int main(){
    int H , W ;
    cin >> H >> W  ;
    vector<vector<int > > A(H , vector<int> (W)) ;
    for(int i= 0 ; i < H ; i++){
        for(int j = 0 ; j < W ; j++){
            cin >> A.at(i).at(j) ;
        }
    }
    int cnt = A.at(0).at(0) ;
    for(int i= 0 ; i < H ; i++){
        for(int j = 0 ; j < W ; j++){
            cnt = min(cnt , A.at(i).at(j));
        }
    }
    long long ans = 0 ;
    for(int i= 0 ; i < H ; i++){
        for(int j = 0 ; j < W ; j++){
              ans += A.at(i).at(j)-cnt ;
        }
    }
    cout << ans << endl;
}

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

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

ll gcd(ll a, ll b) {
    if (a % b == 0) return (b);
    return (gcd(b, a % b));
}
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

template <class T>
void chmin(T& a, T b) {  // choose minimum.
    if (a > b) {
        a = b;
    }
}
template <class T>
void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

const int mod = 1e9 + 7;
struct mint {
    ll x;  // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return (*this) *= a.inv(); }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

// MODのときの計算に使うのでmintになっている.
mint choose(int n, int a) {
    mint x = 1, y = 1;
    rep(i, a) {
        x *= n - i;
        y *= i + 1;
    }
    return x / y;
}

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

    int h, w;
    cin >> h >> w;
    int a[101][101];

    int m = 100000;
    rep(i, h) rep(j, w) {
        cin >> a[i][j];
        chmin(m, a[i][j]);
    }

    int ans = 0;
    rep(i, h) rep(j, w) { ans += max(0, a[i][j] - m); }

    cout << ans;

    return 0;
}


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

int main()
{
    int N;
    cin >> N;
    unordered_set<string> st;
    bool ok = false;
    string ans;
    for (int i = 0; i < N; i++) {
        string s;
        cin >> s;
        if (st.count(s)) {
            ok = true;
            if (ans == "") ans = s;
        }
        if (s[0] == '!') {
            s.erase(0, 1);
        } else {
            s = "!" + s;
        }
        st.insert(s);
    }
    if (ans[0] == '!') ans.erase(0, 1);
    if (ok) cout << ans << endl;
    else cout << "satisfiable" << endl;
}

/* Author : Aaryan Srivastava ^__^ */
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i,n) for(int i = 0 ; i < (n) ; i++)
#define repA(i,x,y) for(int i = (x) ; i <= (y) ; i++)
#define repD(i,x,y) for(int i = (x) ; i >= (y) ; i--)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define setval(a,val) memset(a,val,sizeof(a))
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define trav(x , a) for(auto &x : a)
#define sz(a) ((int)a.size())
typedef long long ll ;

#define int ll

using namespace std;

const int N = 3e5 +5 ;
const int mod = 1e9 + 7 ;
const ll inf = 1e18 ;
const int SZ = 101 ;
const double eps = 1e-9 ;
using namespace __gnu_pbds;
using ordered_set =  tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ;

typedef pair<int, int> pii;
typedef pair<int , pii> ipii ;
typedef pair<pii , int> piii ;
typedef unsigned long long ull ;
typedef long double ld;

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

void solve()
{
    int n ;
    cin >> n;
    map<string , int> m, m2;
    rep(i , n){
        string s;
        cin >> s;
        if(s[0] == '!')
            m2[string(s.begin() + 1 , s.end())]++;
        else
            m[s]++;
    }

    for(auto& it : m){
        string tmp = it.ff;
        if(m2.find(tmp) != m2.end()){
            cout << tmp;
            return;
        }
    }
    cout << "satisfiable";
}

int32_t main(int32_t argc, char *argv[])
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int TC = 1, t = 0;
    //cin >> TC ;
    while(t++ < TC)
    {
        //cout << "Case #" << t << ": " ;
        solve();
        cout << "\n" ;
    }
    return 0;
}


#include <iomanip>
#include <iostream>
using namespace std;
double dp[100][100][100];
double rec(int i, int j, int k) {
  if (i == 100 || j == 100 || k == 100) return 0.0;
  if (dp[i][j][k] > 0.0) return dp[i][j][k];
  double n = double(i + j + k);
  return dp[i][j][k] = ((rec(i + 1, j, k)) * i + (rec(i, j + 1, k)) * j + (rec(i, j, k + 1)) * k) / n + 1;
}
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << fixed << setprecision(10) << rec(a, b, c);
  return 0;
}

#include<bits/stdc++.h>
#include<iostream>
#include<set>
#include<map>
#include<iterator>
#define ll              long long
#define lli             long long int
#define pb              push_back
#define RIP(i,n)        for(int i=0; i<n; i++)
#define RIP1(i,n)       for(int i=n-1; i>=0; i--)
#define FOR(i,a,b)      for(int i=a;i<(b); i++)
#define FOR1(i,a,b)     for(int i=a; i>=(b); i--)
#define sc(a)           scanf("%lld",&a)
#define SC(a)           scanf("%d",&a)
#define cin(a)          cin >> a
#define cout(a)         cout << a
#define pi              acos(-1)
#define pr(a)           printf("%lld\n",a)
#define PR(a)           printf("%lld ",a)
#define s(a,b)          sort(a,b)
#define sz(x)           (int)(x).size()
#define nl              '\n'
#define Max             110
using namespace std;
void c_p_c()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    /*#ifdef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif*/
}
double dp[Max][Max][Max];
double solve(int a,int b,int c)
{
    double ret = dp[a][b][c];
    if(ret>0)
    {
        return ret;
    }
    if(a>=100 || b>=100 || c>=100)
    {
        return 0;
    }

    ret = 0;
    double sum = a+b+c;
    ret = a*(solve(a+1,b,c)+1)/sum + b*(solve(a,b+1,c)+1)/sum + c*(solve(a,b,c+1)+1)/sum;
    dp[a][b][c]=ret;
    return ret;
}
int main()
{
    //c_p_c();
    int a,b,c;
    SC(a);SC(b);SC(c);
    /*double sum = a+b+c;
    double p = (100-a)*(a/sum);
    double q = (100-b)*(b/sum);
    double r = (100-c)*(c/sum);
    double ans = p+q+r;*/
    //memset(dp,255,sizeof(dp));
    /*RIP(i,Max)
    {
        RIP(j,Max)
        {
            RIP(k,Max)
            {
                dp[i][j][k]=255;
            }
        }
    }*/
    double ans = solve(a,b,c);
    cout << fixed << setprecision(9) << ans << nl;
}


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

void solve() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> G(n);
  while (m--) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
  }

  uint32_t ans{};
  for (int s = 0; s < 1 << n; s++) {
    uint32_t tmp{1};

    queue<int> q;
    vector<int> checked(n);
    vector<int> group(n);
    for (int v = 0; v < n; v++) {
      if (s >> v & 1) {
        checked[v] = 1;
        for (auto &&to : G[v]) {
          if (checked[to]) {
            tmp = 0;
          }
        }
      }
    }

    for (int v = 0; v < n; v++)
      if (!checked[v]) {
        bool fail = 0;
        q.push(v);

        while (!q.empty()) {
          auto now = q.front();
          q.pop();
          for (auto &&to : G[now]) {
            if (checked[to]) {
              if (s >> to & 1) continue;
              if (group[to] == group[now]) {
                fail = 1;
              }
            } else {
              q.push(to);
              checked[to] = 1;
              group[to] = !group[now];
            }
          }
        }

        if (fail) {
          tmp = 0;
        } else {
          tmp *= 2;
        }
      }

    ans += tmp;
  }

  cout << ans << "\n";
}

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

  solve();
}

#include <bits/stdc++.h>

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

#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define per(i, a, b) for (auto i = (b); i-- > (a); )
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) int((x).size())
#define lb(x...) lower_bound(x)
#define ub(x...) upper_bound(x)

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

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

const int N = 21;
vector<int> g[N];
bool vis[N];

vector<int> cc;
void dfs(int u) {
	cc.push_back(u);
	vis[u] = 1;
	for (int v : g[u]) if (!vis[v]) dfs(v);
}

int nxt(int x, int b) {
	x += b + 1;
	if (x > 3) x -= 3;
	return x;
}

short col[N];

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

	int n, m; cin >> n >> m;
	rep(e, 0, m) {
		int u, v; cin >> u >> v;
		--u; --v;
		g[u].push_back(v);
		g[v].push_back(u);
	}

	ll res = 1;
	rep(u, 0, n) {
		if (vis[u]) continue;
		cc.clear(); dfs(u);
		int mx = sz(cc) - 1;
		mx = 1 << mx;

		ll tmp = 0;

		rep(S, 0, mx) {
			for (auto u : cc) col[u] = 0;

			col[u] = 1;
			bool valid = 1;
			int T = S;
			int cur = 0;
			for (auto u : cc)
				for (auto v : g[u])
					if (col[v]) valid &= col[u] != col[v];
					else col[v] = nxt(col[u], T >> cur++ & 1);
			tmp += valid;
		}

		res *= 3 * tmp;
	}
	cout << res << '\n';
}


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

#pragma GCC optimize("O3")
#ifdef LOCAL
#include "/Users/lbjlc/Desktop/coding/debug_utils.h"
#else
#define print(...) ;
#define printn(...) ;
#define printg(...) ;
#define fprint(...) ;
#define fprintn(...) ;
#endif

#define rep(i, a, b) for(auto i = (a); i < (b); i++)
#define rrep(i, a, b) for(auto i = (a); i > (b); i--)
#define all(v) (v).begin(), (v).end()
#define pb push_back
// #define mp make_pair
#define fi first
#define se second
#define maxi(x, y) x = max(x, y)
#define mini(x, y) x = min(x, y)
// long long fact(long long n) { if(!n) return 1; return n*fact(n-1); }
// #define endl '\n'
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int get_random() {
    static uniform_int_distribution<int> dist(0, 1e9 + 6);
    return dist(rng);
}
#define solve_testcase int T;cin>>T;for(int t=1;t<=T;t++){solve(t);}

typedef unsigned long long ull;
typedef long long ll;

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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pdd> vpdd;
typedef vector<long long> vll;
#define bd(type,op,val) bind(op<type>(), std::placeholders::_1, val)

template<class T>
void make_unique(T & v) {
    sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());
}
int geti() { int x; cin >> x; return x; }
long long getll() { long long x; cin >> x; return x; }
double getd() { double x; cin >> x; return x; }
// pair<int, int> a(geti(), geti()) does not work
// pair<int, int> a({geti(), geti()}) works, since it uses initializer.

const int MAXN = 3e5 + 100;

void solve(int tt) {
    // cout<<"Case #"<<tt<<": ";
}

int main(int argc, char * argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    // solve_testcase;

    int n;
    cin>>n;

    string s;
    cin>>s;
    const string s110="110";

    ll tot=1e10;
    if(n==1) {
    	if(s[0]=='0') cout<<tot<<endl;
    	else cout<<2*tot<<endl;
    	return 0;
    }

    if(s[0]=='0') s = "11"+s;
    else if(s[1]=='0') s = "1"+s;

    n=s.size();
    if(s[n-1]=='1') {
    	if(s[n-2]=='1') s+='0';
    	else s += "10";
    }

    print(s);

    if(s.size()%3) {
    	cout<<0<<endl;
    	return 0;
    }

    int ok=1;
    rep(i,0,n) {
    	if(s[i]!=(i%3==2?'0':'1'))
    		ok=0;
    }
    if(!ok) {
    	cout<<0<<endl;
    	return 0;
    }

    cout<<tot-ll(s.size())/3+1<<endl;

    return 0;
}

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <vector>

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> II;
typedef pair<LL, II> III;
typedef priority_queue<III, vector<III>, greater<>> Queue;
static const LL INF = 1LL << 60;

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

void solve(long long N, long long M, long long K, std::vector<long long> &A) {
	vector<LD> e(N + M + 2);
	vector<LD> pz(N + M + 2);
	vector<LL> z(N + 2);
	LD esum = 0;
	LD zsum = 0;
	for (int i = 0; i < K; i++) {
		z[A[i]] = 1;
	}
	for (LL i = N - 1; i >= 0; --i) {
		e[i] = 1.0 + esum / M;
		if (z[i]) {
			e[i] = 0;
			pz[i] = 1.0;
		} else {
			pz[i] = zsum / M;
		}
		esum -= e[i + M];
		esum += e[i];
		zsum -= pz[i + M];
		zsum += pz[i];
	}
	LD ans = e[0];
	if (pz[0] > 0) {
		if (pz[0] >= (1.0 - 1e-10)) {
			cout << -1 << endl;
			return;
		}
		LD a = 1.0 - pz[0];
		ans /= a;
	}
	cout << ans << endl;
}

int main() {
	cout.precision(10);
    long long N;
	std::cin >> N;
	long long M;
	std::cin >> M;
	long long K;
	std::cin >> K;
	std::vector<long long> A(K);
	for (int i = 0; i < K; i++) {
		std::cin >> A[i]; // A[i]--;
	}
	solve(N, M, K, A);
	return 0;
}


#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <climits>

#define rep(i, n) for(int i = 0; i < n; i++)
#define per(i, n) for(int i = n - 1; i >= 0; i--)
using ll = long long;
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define mod 998244353
using namespace std;
template<class T, class U>
T &chmax(T &a, const U &b){ if(a < b) a = b; return a; }
template<class T, class U>
T &chmin(T &a, const U &b){ if(a > b) a = b; return a; }
int main(){
  int h,w;
  cin >> h >> w;
  vector<string> board(h);
  rep(i, h) cin >> board[i];
  ll ans = 1;
  rep(i, w){
    int y = 0, x = i;
    int b = 0, r = 0, n = 0;
    while(y < h && x >= 0){
      if(board[y][x] == 'B') b++;
      if(board[y][x] == 'R') r++;
      if(board[y][x] == '.') n++;
      y++; x--;
    }
    if(b && r){
      cout << "0\n";
      return 0;
    }else if(!b && !r) (ans *= 2) %= mod;
  }
  for(int i = 1; i < h; i++){
    int y = i, x = w - 1;
    int b = 0, r = 0, n = 0;
    while(y < h && x >= 0){
      if(board[y][x] == 'B') b++;
      if(board[y][x] == 'R') r++;
      if(board[y][x] == '.') n++;
      y++; x--;
    }
    if(b && r){
      cout << "0\n";
      return 0;
    }else if(!b && !r) (ans *= 2) %= mod;
  }
  cout << ans << "\n";
}

#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 998244353LL
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,k,x,y;

//moddivとnCkとgarner
//c剰余下でaをbで割った値
ll moddiv(ll a,ll b,ll c){
	ll x0=c,x1=b,x2,n0=0LL,n1=1LL,n2,t=a%b,m,ans;
	if (t==0LL) return a/b;
		for(int i=0;i<900;i++){
      m=x0/x1;
      x2=x0-x1*m;
      n2=(n0-m*n1)%c;
      if (x2==1LL){
        ans=(n2+c)%c;
        break;
      }
      x0=x1;x1=x2;
      n0=n1;n1=n2;
    }
	return (a+((t*ans)%c)*b-t)/b;
}

//nCk
vi mulmod(301);//0!,1!,2!,3!,4!,,,,
void first_nCk(){
  mulmod[0]=1LL;
  for(ll i=1;i<301;i++){
    mulmod[i]=mulmod[i-1]*i%MOD;
  }
}

ll nCk(ll nn,ll kk){
  return moddiv(mulmod[nn],mulmod[kk]*mulmod[nn-kk]%MOD,MOD);
}

ll modinv(ll a,ll b){
  return moddiv(1,a,b);
}

int main(){
  ll ans=0;
  first_nCk();
  cin >> n >> k;
  k++;
  vi a(n);
  REP(i,n) cin>>a[i];

  vvi data(n, vi(k));
  vi tmsum(k);
  for(ll i=0;i<n;i++){
    ll gege=1;
    ll ggg=1;
    for(ll j=0;j<k;j++){
      data[i][j]=gege;
      gege=a[i]*gege%MOD;
      tmsum[j]+=ggg;
      ggg=ggg*a[i]*2%MOD;
    }
  }

  for(ll j=0;j<k;j++)
    tmsum[j]%=MOD;

  vi datasum(k);
  for(ll i=0;i<n;i++){
    for(ll j=0;j<k;j++){
      datasum[j]+=data[i][j];
      datasum[j]%=MOD;
    }
  }

  for(ll i=1;i<k;i++){
    ans=0;
    ll tmp=MOD;
    for(ll j=0;j<i+1;j++){
      tmp=tmp+datasum[i-j]*datasum[j]%MOD*nCk(i,j)%MOD;
    }
    tmp=(tmp-tmsum[i])%MOD;
    cout<<(moddiv(tmp,2,MOD))<<endl;
  }
  return 0;
}


/*
power code taken from geeks for geeks

*/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;

// THINGS TO REMEMBER
// ENDL is slow, '\n' is fast
// Clear everything (including graphs) between test cases
// use anti-anti-hash: https://codeforces.com/blog/entry/62393
// pb-ds: https://codeforces.com/blog/entry/11080
// check when to use LLONG_MAX/LLONG_MIN vs INT_MAX or INT_MIN
// You frequently suffer from confirmation bias - you trust your initial solution and miss simple things.
// When you hit a roadblock, remember to rethink the solution ground up, not just try hacky fixes

#define flush fflush(stdout);
#define PLL pair<ll,ll>
const ll INF = 1e18 + 5;
const ll MAX_N = 2e5 + 5;
const ll MODD = 1e9 + 7;
const ll MAX_M = 5e3 + 5;

ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
double max(double a,double b){return a>b?a:b;}
double min(double a,double b){return a<b?a:b;}
ld max(ld a,ld b){return a>b?a:b;}
ld min(ld a,ld b){return a<b?a:b;}

ll modd(ll a){if(a<0LL) return a*-1LL;return a;}
double modd(double a){if(a<0.0) return a*-1.0;return a;}

ll modulo(ll a){
    ll ans = a;
    while(ans < 0LL) {
        ans += MODD;
    }
    return (a + MODD) % MODD;
}

ll power(ll k, ll p){
    if (p == 0)
        return 1LL;

    ll P = power(k, p/2LL);
    P = modulo((P * P));

    if (p % 2 == 1)
        P = modulo((P * k));

    return P;
}
int iii = 0;void _debug() {cout << "here " << (iii++) << endl;}

void solve() {
    ll n, w;
    cin >> n >> w;
    cout << n / w << endl;
}

int main() {

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

    ll t = 1;

    // cin >> t;

    while(t--){
        solve();
    }

    return 0;
}

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
const int mod=1e9+7;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int a,b;
	cin>>a>>b;
	cout<<2*a+100-b<<"\n";
	return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define f(i,b) for(int i=0;i<b;i++)
#define int long long
using namespace std;

void solve()
{
   int n;
   cin>>n;
    int a[n];

    for(int i=0;i<n;i++)
        cin>>a[i],a[i]%=200;

    int ans=0;
    map<int,int> mp;

    for(auto z:a)
    {
        ans+=mp[z];
        mp[z]++;
    }
   cout<<ans<<"\n";
    return;
}

signed main()
{
    int t=1;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //cin>>t;

    while(t--)
    {
        solve();
    }
        return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define deb(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;

typedef long long int ll;
typedef string str;

ll power(ll x, ll y, ll p)
{
    ll res = 1;

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

ll nCrModP(ll n, ll r, ll p)
{
    if (!r)
      return 1;

	ll fac[n+1];
   	fac[0] = 1;
    for (ll i=1 ; i<=n; i++)
        fac[i] = fac[i-1]*i%p;

    return (fac[n]* power(fac[r], p-2,p) % p * power(fac[n-r], p-2,p) % p) % p;
}

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

void fast(){
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main ()
{

	ll t,n,m,k,i,j,a,b;
	// cin >> t;
    str st,s;
    cin >> n;
    ll h[201]={0};
    for(i=0;i<n;i++)
    {
        cin >> a;
        a%=200;
        h[a]++;
    }
    b = 0;
    for(i=0;i<200;i++)
    {
        a = h[i];
        b += (a*(a-1))/2;
    }
    cout << b << "\n";
    return 0;
}


#include<iostream>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,b,a) for(int i=b;i>=a;i--)
#define N 2021
using namespace std;
string map[N];
int fa[N];
int tf1[N],tf2[N];
int find(int x){
    if(fa[x]==x)return x;
    return fa[x]=find(fa[x]);
}
int main(){
    ios::sync_with_stdio(false);
    int h,w;
    cin>>h>>w;
    rep(i,0,h+w)fa[i]=i;
    rep(i,0,h-1)cin>>map[i];
    map[0][0]=map[h-1][0]=map[0][w-1]=map[h-1][w-1]='#';
    rep(i,0,h-1)rep(j,0,w-1)
        if(map[i][j]=='#'){
            int x=find(i),y=find(j+h);
            if(x!=y)fa[x]=y;
        }
    int cnt1=0,cnt2=0;
    rep(i,0,h-1){
        int x=find(i);
        if(!tf1[x])tf1[x]=true,cnt1++;
    }
    rep(j,h,h+w-1){
        int y=find(j);
        if(!tf2[y])tf2[y]=true,cnt2++;
    }
    cout<<min(cnt1,cnt2)-1<<endl;
    return 0;
}

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

using namespace std;

long power_mod(long a, long b, long m)
{
    int k = 0;
    long c = b;
    long n = 1L;
    while (c >= 1)
    {
        c >>= 1;
        ++k;
    }
    for (int i = k; i >= 0; --i)
    {
        n = ((b >> i) & 1) ? (n * n * a) % m : (n * n) % m;
    }
    return n;
}

int main()
{
    const long P = 1000000007;
    int H, W;
    cin >> H >> W;
    //string *S = new string[H];
    bool **S = new bool *[H];
    string Str;
    int K = 0;
    int **illuminate = new int *[H];
    for (int i = 0; i < H; ++i)
    {
        cin >> Str;
        S[i] = new bool[W];
        illuminate[i] = new int[W];
        for (int j = 0; j < W; j++)
        {
            S[i][j] = (Str.at(j) == '.');
            K += (S[i][j] ? 1 : 0);
            illuminate[i][j] = 0;
        }
    }

    //horizontal
    for (int i = 0; i < H; i++)
    {
        int j = 0;
        while (j < W)
        {
            int len = 0;
            while (j < W && !S[i][j])
            {
                j++;
            }
            while (j + len < W && S[i][j + len])
            {
                len++;
            }
            for (int k = 0; k < len; ++k)
            {
                illuminate[i][j + k] += len;
            }
            j = j + len;
        }
    }

    //vertical
    for (int j = 0; j < W; j++)
    {
        int i = 0;
        while (i < H)
        {
            int len = 0;
            while (i < H && !S[i][j])
            {
                i++;
            }
            while (i + len < H && S[i + len][j])
            {
                len++;
            }
            for (int k = 0; k < len; ++k)
            {
                illuminate[i + k][j] += len;
            }
            i = i + len;
        }
    }

    long sum = 0;
    long C = power_mod(2, K, P);

    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            if (illuminate[i][j] > 0)
            {
                sum += C - power_mod(2, K - illuminate[i][j] + 1, P);
            }
        }
    }

    cout << (sum % P + P) % P;

    return 0;
}