#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

struct edge{
  ll to, c, d;
};

int main(){
  int n, m;
  cin >> n >> m;
  vector<vector<edge>> G(n);
  for(int i = 0; i < m; i++){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    a--; b--;
    G[a].push_back((edge){b, c, d});
    G[b].push_back((edge){a, c, d});
  }
  priority_queue<P, vector<P>, greater<P>> todo;
  todo.push(P(0, 0));
  vector<ll> dist(n, 1e16);
  dist[0] = 0;
  while(!todo.empty()){
    P now = todo.top(); todo.pop();
    ll pos = now.second;
    if(pos == n - 1) break;
    ll t = now.first;
    if(t > dist[pos]) continue;
    for(int i = 0; i < G[pos].size(); i++){
      edge e = G[pos][i];
      ll nxt = e.to;
      ll c = e.c;
      ll d = e.d;
      ll time = sqrt(d);
      if(t >= time) time = t;
      ll arrive = c + time + d / (time + 1);
      if(dist[nxt] > arrive){
        dist[nxt] = arrive;
        todo.push(P(arrive, nxt));
      }
    }
  }
  if(dist[n - 1] == 1e16) cout << -1 << endl;
  else cout << dist[n - 1] << endl;
  return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define pqueue priority_queue
#define umap unordered_map
#define uset unordered_set
#define bit(s, i) ((1 << i) & s ? 1 : 0)
#define bits(x) __builtin_popcount((x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x) / gcd(x, y) * (y))
#define inf 4557430888798830399LL
#define mst(dp, val) memset(dp, val, sizeof(dp))
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define repd(i, a, b, d) for (int i = a; i <= b; i += d)
#define rep_(i, a, b) for (int i = a; i >= b; --i)
#define repd_(i, a, b) for (int i = a; i >= b; i -= d)
#define mxm(a, b) a = max(a, b)
#define mnm(a, b) a = min(a, b)
#define pb push_back
#define X first
#define Y second
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << "=" << x << endl
#define readArr(a, n) for (int i = 1; i <= n; i++) cin >> a[i];
#define printArr(a, n) for (int i = 1; i <= n; i++) cout << a[i] << " "; cout << endl;
#define print(e) cout << (e) << endl
const int mod = 1e9 + 7;
#define Add(x, val) x = (x + (val)) % mod
// #define MULTI_CASES
// #define PRE

const int N = 1e5 + 5;
struct Edge {
    int v, c, d;
};
using Node = pii; //距离，节点编号
vector<Edge> g[N];

void solve() {
    int n, m;
    cin >> n >> m;
    rep(i, 1, m) {
        int u, v, c, d;
        cin >> u >> v >> c >> d;
        g[u].pb({v, c, d});
        g[v].pb({u, c, d});
    }
    vi dist(n+1, inf);
    vi vis(n+1);
    pqueue<Node, vector<Node>, greater<Node>> q;
    q.push({0, 1});
    dist[1] = 0;
    while (!q.empty()) {
        int u = q.top().Y, t = q.top().X;
        q.pop();
        if (vis[u]) continue;
        vis[u] = 1;
        for (auto e : g[u]) {
            int v = e.v, c = e.c, d = e.d;

            if (t + c + d / (t + 1) < dist[v]) {
                dist[v] = t + c + d / (t + 1);
                q.push({dist[v], v});
            }

            rep(x, -2, 2) {
                int nt = sqrt(d) + x; //出发时间
                if (nt < t) continue;
                if (nt + c + d / (nt + 1) < dist[v]) {
                    dist[v] = nt + c + d / (nt + 1);
                    q.push({dist[v], v});
                }
            }
        }
    }
    print(dist[n] == inf ? -1 : dist[n]);
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    #ifdef PRE
        pre();
    #endif
    #ifdef MULTI_CASES
        int t; cin >> t;
        while (t--) solve();
    #else
        solve();
    #endif
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fst ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endk cout<<"\n";
typedef long long int ll;
typedef long int l;
#define l(i,a,b) for(i=a;i<b;i++)
#define lo(i,a,b) for(i=a;i>=b;i--)
#define s(v) sort(v.begin(),v.end());
#define pb push_back;
#define vll vector<ll>
#define vint vector<int>
#define test() ll t;cin>>t;while(t--){solve();};
#define test1() int t=1;while(t--){solve();};
bool isprime(ll x)
{
    if(x==1) return false;
    if(x==2 || x==3) return true;
    if(x%2==0 || x%3==0) return false;
    for(ll i=5;i*i<=x;i+=6)
    {
        if(x%i==0 || x%(i+2)==0) return false;
    }
    return true;
}
ll power(ll x,ll y)
{
	ll ans=1;
	while(y>0)
	{
		if(y&1) ans=ans*x;
		x=x*x;
		y=y>>1;
	}
	return ans;
}
int solve()
{
    ll n,i,ans=0;
    cin>>n;
    vector<ll> a(n),b(n),c(n);
    map<ll,ll> m;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(i=0;i<n;i++)
    {
        cin>>b[i];
    }
    for(i=0;i<n;i++)
    {
        cin>>c[i];
        c[i]=b[c[i]-1];
        m[c[i]]++;
    }
    for(i=0;i<n;i++)
    {
        ans+=m[a[i]];
    }
    cout<<ans;
    return 0;
}
int main()
{
    fst;
    test1();
    return 0;
}

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

//take care of long long

//fast I/O
auto optimizer = []() {  // makes I/O fast
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  return 0;
}();

int main() {
	ll t=1;
	//cin>>t;
	while(t--)
	{
	    ll n;
	    cin>>n;
	    vector<ll> vc(n);
	    ll sum=0;
	    for(ll i=0;i<n;i++)
	    {
	        cin>>vc[i];
	        sum+=vc[i];
	    }
	    vector<vector<ll>> dp(sum+1, vector<ll>(n,0));
	    sort(vc.begin(),vc.end());
	    ll ans=INT_MAX;
	    for(ll sm=1;sm<=dp.size()-1;sm++)
	    {
	        for(ll i=0;i<n;i++)
	        {
	            if(i>0&&dp[sm][i-1])
	            {
	                dp[sm][i]=1;
	            }
	            else
	            {
	                if(sm<vc[i])
	                {
	                    dp[sm][i]=0;
	                }
	                else if(sm==vc[i] || (i>=1 && dp[sm-vc[i]][i-1]) )
	                {
	                    dp[sm][i]=1;
	                }
	                else
	                {
	                    dp[sm][i]=0;
	                }
	            }
	        }
	        if(dp[sm][n-1])
	        {
	            //cout<<sm<<endl;
	            ans=min(ans,max(sm,sum-sm));
	        }
	    }
	    cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
struct Edge {
    int to, cost;
    Edge(){};
    Edge(int to, int cost): to(to), cost(cost){};
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

int main() {
    cin.tie(0);
    cin.sync_with_stdio(0);

    ll n, k;
    cin >> n >> k;

    ll ans = 0;
    ll a, b;
    for (ll i = 2; i <= 2*n; i++) {
        if (i - k < 2 || 2*n < i - k) continue;

        if (i > n) a = 2*n - i + 1; // n - (i - n) + 1
        else a = i-2+1;

        if (i - k > n) b = 2*n -(i - k) + 1;
        else b = i-k-1;

        ans += a * b;
    }
    cout << ans << endl;
}

// Template begins
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <math.h>
#include <iomanip>
#include <queue>
#include <string.h>
#include <string>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define fo(i,a,b) for(i=a;i<=b;i++)
#define all(v) (v).begin(),(v).end()
#define sort0(v) sort(all(v))
#define lbb(a,b,arr,x) lower_bound(arr+a,arr+b+1,x)-arr
#define ubb(a,b,arr,x) upper_bound(arr+a,arr+b+1,x)-arr
#define freq(a,b,arr,x) upper_bound(arr+a,arr+b+1,x)-lower_bound(arr+a,arr+b+1,x)
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define d0(x) cout<<(x)<<" "
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define d5(a,b,c,d,e) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<endl
#define d6(a,b,c,d,e,f) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<" "<<(f)<<endl
#define max3(a,b,c) max(max((a),(b)),(c))
#define max4(a,b,c,d) max(max((a),(b)),max((c),(d)))
#define ss second
#define ff first
#define pb push_back
#define mp make_pair
#define printp(x) cout << x.ff << " " << x.ss << endl

const ll mod=998244353;
#define inf 9999999999999
#define MAXN   100001

// stores smallest prime factor for every number

ll inv(ll i){if(i==1) return 1;return (mod-((mod/i)*inv(mod%i))%mod)%mod;}

ll gcd(ll a,ll b){if(a==0) return b;return gcd(b,b%a);}
inline void fastio(){ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
// Template ends'
ll factorial[1000002];
const int MN = 2e5+7;
ll val(ll a){
    return ((a*(a+1))/2)%mod;
}
void solve(){

    ll n,k; cin>>n>>k;
    ll a,b;
    k=abs(k);
    ll ans=0;
    for(int i=2;i<=2*n;i++){
        a=i;
        b=a-k;
        if( b>=2)
            ans= ans+min(a-1,2*n + 1 - a)*min(b-1,2*n + 1 - b);

    }
    cout<<ans<<endl;
}
int main(){
    fastio();
    //write code
    int t=1;
    while(t--){
        solve();
    }
    return 0;
}


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

#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
#define vvvll vector<vector<vector<ll>>>
#define vvll vector<vector<ll>>
#define vll vector<ll>
#define pqll priority_queue<ll>

constexpr ll INF = (1ll << 60);
constexpr ll mod = 1000000007;  // 998244353;
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

void pt_vvll(vvll v) {
    rep(i, v.size()) {
        rep(j, v[0].size()) {
            cout << v[i][j];
            if (j != v[0].size() - 1)
                cout << " ";
            else
                cout << "\n";
        }
    }
}
void pt_vll(vll v) {
    rep(i, v.size()) {
        cout << v[i];
        if (i == v.size() - 1)
            cout << "\n";
        else
            cout << " ";
    }
}

vector<ll> sum, ans;
void pre_process(vector<ll> &a, vector<ll> &s) {  //累積和のvector
    ll n = (ll)a.size();
    s.assign(n + 1, 0);
    for (ll i = 0; i < n; i++) {
        s[i + 1] = s[i] + a[i];
    }
}
ll query(ll i, ll j, vector<ll> &s) {  //区間[i,j]の和
    return (s[j] - s[i]);
}

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

    ll N;
    cin >> N;
    vll A(N);
    rep(i, N) cin >> A[i];

    pre_process(A, sum);
    reverse(sum.begin(), sum.end());
    sum.pop_back();
    reverse(sum.begin(), sum.end());

    pre_process(sum, ans);

    // pt_vll(ans);

    vll MAX_A(N + 1);
    ll ma = 0;
    rep(i, N + 1) {
        chmax(ma, sum[i]);
        MAX_A[i] = ma;
    }

    ll pt = 0;
    rep(i, ans.size()) {
        ll plus = (i < N ? MAX_A[i + 1] : 0ll);
        chmax(pt, ans[i] + max(0ll, plus));
        // cout << pt << "\n";
    }

    // pt_vll(ans);

    cout << pt << "\n";
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
//↓AC-library使うなら

//型関係
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> pll;
typedef priority_queue<int, vector<int>, greater<int>> PQ;//昇順priority_queue
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<P > vpii;
typedef vector<pll > vpll;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
//repマクロ
#define rep(i, n) for (int i = 0; i < (ll)(n); i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < (ll)(b); i++)
#define FORD(i, a, b) for (int i = a; i >= (ll)(b); i--)
//範囲関係
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define all(x) (x).begin(), (x).end()
#define len(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
//定数
#define inf 1000000000000
#define mod 1000000007
#define MAXR 100000
#define MATHPI acos(-1)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
//操作
#define pb push_back
#define pf push_front
#define mp make_pair
#define F first
#define S second
//数学関係, a<=x<=b
bool updown(ll x, ll a, ll b) { return x >= a && x <= b; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
#define SUM(x) accumulate(all(x), 0)
#define bit(n) (1LL<<(n))
//chmin, chmax
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
//小数出力(f...出力したい小数, n...小数点以下の桁数)
void printd(double f, int n) { cout << fixed << setprecision(n) << f << endl; } //指定した桁で小数を出力
//YES/NO, Yes/No, yes/no出力
void YES(bool c = true) { cout << (c ? "YES" : "NO") << endl; } //YES(条件式)で記述
void Yes(bool c = true) { cout << (c ? "Yes" : "No") << endl; } //Yes(条件式)で記述
void yes(bool c = true) { cout << (c ? "yes" : "no") << endl; } //yes(条件式)で記述
//除外用
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
//if use atcoder library:g++ main.cpp -std=c++17 -I /home/k0gane/kyopro/ac-library
//累積和
//https://qiita.com/drken/items/56a6b68edef8fc605821
//point...n+1の容量のリストを作る
//
//深さ優先...push_front
//幅優先...push_backP

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;cin >> n;
  vpii p(n); rep(i, n) cin >> p[i].F >> p[i].S;

  rep(i, n-2){
    FOR(j, i+1, n-1){
      FOR(k, j+1, n){
         if((p[j].F - p[k].F) * (p[i].S - p[j].S)  == (p[i].F - p[j].F) * (p[j].S - p[k].S)){cout << "Yes" << endl; exit(0);}
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


#ifdef MYDEBUG
#include "pch.h"
#else
#include <bits/stdc++.h>
#define debug(...)
#endif
using namespace std;

#define int long long
#define endl '\n'

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

typedef vector<int> vi;
typedef map<int, int> mii;
typedef pair<int, int> pii;

template<typename T1, typename T2>istream& operator>>(istream& in, pair<T1, T2>& a) { return in >> a.first >> a.second; }
template<typename T1, typename T2>ostream& operator<<(ostream& out, pair<T1, T2> a) { return out << a.first << " " << a.second;}

template<typename T>void print(T t) { cout << t; }
template<typename T, typename... Args>void print(T t, Args... args) { cout << t << " "; print(args...); }
template<typename... Args>void printl(Args... args) { print(args...); cout << endl; }
template<typename T>void printa(T& a, bool ln = 0) { for (auto& e : a) print(e, ln?"\n":""); if (!ln) cout << endl; }

#define printr(...) { printl(__VA_ARGS__); return; }
#define inputa(a) for (auto& e : a) cin >> e

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int RAND(int lo = 0, int hi = LLONG_MAX) { return uniform_int_distribution<int>(lo, hi)(rng); }

void google() { static int __gtest__ = 1; cout << "Case #" << __gtest__++ << ": "; }

const double pi = 3.141592653589793;

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cout << setprecision(15) << fixed;
	int t = 1;
	//cin >> t;
	void code();
	while (t--) code();
}

const int mod = 1e9 + 7;
const int mod1 = 998244353;
const int maxn = 1e6 + 1;

void  code()
{
	int n;
	cin >> n;

	int sum = 0;
	for (size_t i = 1; i < maxn; i++)
	{
		sum += i;
		if (sum >= n)
			printr(i);
	}
}

#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
using namespace std;
using ll = long long;

const int N = 2e5+5;
int bit[N];
int a[N], b[N], c[N];
pair<int,int> pa[N], pb[N];

void add(int p, int v)
{
    while(p < N)
    {
        bit[p] += v;
        p += p&-p;
    }
}

int ask(int p)
{
    int ret = 0;
    while(p)
    {
        ret += bit[p];
        p -= p&-p;
    }
    return ret;
}

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

    for(int i = 1; i <= n; ++i)
    {
        cin >> a[i];
        a[i] += i;
        pa[i] = {a[i], i};
    }

    for(int i = 1; i <= n; ++i)
    {
        cin >> b[i];
        b[i] += i;
        pb[i] = {b[i], i};
    }

    sort(pa + 1, pa + n + 1);
    sort(pb + 1, pb + n + 1);
    for(int i = 1; i <= n; ++i)
    {
        if(pa[i].first != pb[i].first)
        {
            cout << -1 << endl;
            return 0;
        }
        c[pa[i].second] = pb[i].second;
    }

    ll res = 0;
    for(int i = 1; i <= n; ++i)
    {
        res += i - ask(c[i]) - 1;
        add(c[i], 1);
    }
    cout << res << endl;
    return 0;
}


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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
//#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
const int N = 1e6;
void rohan_algo()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int32_t main()
{
	rohan_algo();
	int n, x;
	string s;
	cin >> n >> x; cin >> s;
	int k = 0;
	for (int i = 0; i < n; ++i)
	{
		if (s[i] == 'x' && x != 0) {
			x--;
		} else if (s[i] == 'o')
			x++;

	}
	cout << x << endl;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,x;
	scanf("%d %d",&n,&x);
	char S[n+1];
	scanf("%s",S);
	for(int i=0;i<n;i++){
		if(S[i]=='o')x++;
		else x--;
		x=max(0,x);
	}
	printf("%d\n",x);
	return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<62) - 1;

template <typename Monoid>
struct SegTree {
    using F = function<Monoid(Monoid, Monoid)>;
    const F f;
    const Monoid unit;

    int n;
    vector<Monoid> dat;

    SegTree(int n_, const F f_, const Monoid unit_) : f(f_), unit(unit_) {
        n = 1;
        while (n < n_) n *= 2;
        // 1-indexed
        dat.assign(2 * n, unit);
    }

    void set(int i, const Monoid &x) {
        dat[i + n] = x;
    }
    void build() {
        for (int i = n - 1; i >= 0; --i) {
            dat[i] = f(dat[2 * i], dat[2 * i + 1]);
        }
    }

    void update(int i, const Monoid &x){
        i += n;
        dat[i] = x;
        while (i >>= 1){
            dat[i] = f(dat[2 * i], dat[2 * i + 1]);
        }
    }

    // [a, b) 非再帰
    Monoid query(int a, int b) {
        Monoid l = unit, r = unit;
        for (a += n, b += n; a < b; a >>= 1, b >>= 1) {
            if (a & 1) l = f(l, dat[a++]);
            if (b & 1) r = f(dat[--b], r);
        }
        return f(l, r);
    }

    inline Monoid operator[] (int i){
        return dat[i + n];
    }
};
// set(i, v)した後にbuild()でO(n)
// 区間和 : SegTree<int> seg(n, [](int a, int b){ return a + b; }, 0);
// 区間min : SegTree<int> seg(n, [](int a, int b) {return min(a, b); }, INF);

int main(){
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> a(k);
    int modoru[100010] = {};
    for (int i = 0; i < k; ++i) {
        cin >> a[i];
        modoru[a[i]] = 1;
    }

    int cnt = 0;
    for (int i = 0; i <= n; ++i) {
        if (modoru[i]) cnt++;
        else cnt = 0;
        if (cnt >= m) {
            cout << -1 << endl;
            return 0;
        }
    }

    SegTree<double> seg(n + m + 10, [](double a, double b){ return a + b; }, 0);
    SegTree<double> seg2(n + m + 10, [](double a, double b){ return a + b; }, 0);
    for (int i = n-1; i >= 0; --i) {
        double a = seg.query(i + 1, i + m + 1) / m + 1.0;
        double b = seg2.query(i + 1, i + m + 1) / m;

        if (modoru[i]) {
            seg2.update(i, 1.0);
        } else {
            seg.update(i, a);
            seg2.update(i, b);
        }
    }

    // x = seg[0] + seg2[0] * x
    cout << fixed << setprecision(15) << seg[0] / (1 - seg2[0]) << endl;
}

#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
// typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
#define inf INT_MAX
#define linf LLONG_MAX
#define lninf LLONG_MIN
const int mod = 1e9 + 7;
const int N = 1e5 + 4;
typedef long double ld;

int solve()
{
	int n, m, k; scn(n); scn(m); scn(k);

	pair<ld, ld> p = {0.0, 0.0};

	vector<int> mark(n + 1, 0);

	rep(i, 0, k)
	{
		int val; scn(val);

		mark[val]++;
	}

	int cnt = 0;

	rep(i, 1, n)
	{
		if(mark[i])
		cnt++;
		else
		{
			if(cnt >= m)
			{
				pri(-1); return 0;
			}

			cnt = 0;
		}
	}

	if(cnt >= m)
	{
		pri(-1); return 0;
	}

	vector<pair<ld, ld>> v(n + m + 1, {0.0, 0.0});

	for(int i = n - 1; i >= 0; i--)
	{
		p.F -= v[i + m + 1].F; p.S -= v[i + m + 1].S;

		if(mark[i])
		{
			v[i].F = 1.0;
		}
		else
		{
			v[i].F = p.F / (ld)m; v[i].S = p.S / (ld)m;

			v[i].S += 1.0;
		}

		// cout << v[i].F << " " << v[i].S << endl;

		if(i == 0)
		cout << fixed << setprecision(10) << v[i].S / (1.0 - v[i].F);

		p.F += v[i].F; p.S += v[i].S;
	}

	return 0;
}

int main()
{
	int t = 1; //scn(t);

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

    return 0;
}


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

#define FOR(i,a,b)  for(ll i=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll i=a;(i)>=(b);--(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 UNIQ(v)     sort(ALL(v)); v.erase(unique(ALL(v)), v.end())
#define BIT(n)      (1LL<<(n))
#define DEBUG(a)    cerr << #a << " = " << a << endl

const double PI = acos(-1);
const int inf = 1001001001;
const int mod = (int)1e9+7;
//const ll inf = 1e15;
//const ll mod = 1e9+7;

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

int t2 = 0;

void swp(int q, vector<int>& t, vector<int>& a, vector<int>& b, string& s) {
    if (t[q] == 1) {
        if (t2%2 == 1) {
            if (a[q] )
            a[q] = (a[q] + s.size() / 2) % s.size();
            if (a[q] == 0) a[q] = s.size();
            b[q] = (b[q] + s.size() / 2) % s.size();
            if (b[q] == 0) b[q] = s.size();
        }
        swap(s[a[q]-1], s[b[q]-1]);
    } else {
        t2++;
    }
}

int main() {
    int n;
    string s;
    cin >> n >> s;
    int q;
    cin >> q;
    vector<int> t(q), a(q), b(q);
    REP(i, q) {
        cin >> t[i] >> a[i] >> b[i];
    }

    REP(i, q) {
        swp(i, t, a, b, s);
    }
    if (t2%2 == 1) {
        REP(i, s.size() / 2) {
            swap(s[i], s[i+s.size()/2]);
        }
    }
    cout << s << endl;
}

#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdio>
#include<stdio.h>
#include<cmath>
#include<math.h>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<sstream>
#include<iomanip>
#define forn(i,n) for(int (i)=0;i<(n);i++)
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int>pii;
typedef long long ll;
typedef pair<ll,ll> pll;
const int MAXN=100005;
const int INF=2147483647;
const ll LINF=9223372036854775807;
const int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
int n,x,cnt;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>x;
	x*=100;
	forn(i,n)
	{
		int a,b;
		cin>>a>>b;
		cnt+=a*b;
		if(cnt>x)
		{
			cout<<i+1;
			return 0;
		}
	}
	cout<<-1;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

long long k, res;

int main()
{
    cin>>k;
    for(int i=1; i<=k; i++)
    {
        for(int j=1; j<=k/i; j++)
        {
            if(i*j>k) break;
            res+=k/(i*j);
        }
    }
    cout<<res;
    return 0;
}

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

#define int long long int
typedef pair<int, int> pii;
#define f(i,a,b) for(int i=a;i<b;i++)
#define fo(i,a,b) for(int i = a; i<=b;i+=1)
#define rf(i,a,b)  for(int i=a;i>=b;i--)
#define vll vector<int>
#define sz(a) int(a.size())
#define all(v) v.begin(), v.end()
#define pb push_back
#define pf push_front
#define MAXN 100010
#define MOD 1000000007
#define mod 998244353
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define debug(x) cout << '>' << #x << ':' << x << " ";
#define nl '\n'
#define MS(x,y) fill_n(*x, sizeof x / sizeof **x, y);
#define mem(x,y) memset(x,y,sizeof(x));
#define INF 1000000000000000000
#define IO                 \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \

void solve(){
    int k;
    cin >> k;
    int ans = 0;
    fo(i, 1, k){
        if(i*i*i <= k){
            ans++;
        }
        else {
            break;
        }
    }
    fo(i, 1, k){
        if(i*i > k)break;
        fo(j, i+1, k){
            if(i*i*j <= k){
                ans+=3;
            }
            else {
                break;
            }
        }
    }

    fo(i, 1, k){
        fo(j, i+1, k){
            if(i*j*j <= k){
                ans+=3;
            }
            else {
                break;
            }
        }
    }
    fo(i, 1, k){
        f(j, i+1, k){
            if(i*j > k)break;
            fo(x, j+1, k){
                if(i*j*x <= k){
                    ans += 6;
                }
                else break;
            }
        }
    }

    cout << ans << nl;
    return ;
}
main()
{
    IO;
    int T = 1;
    // cin >> T;
    for(int c=1; c <= T; c++){
        solve();
        // cout<<"Case #"<<c<<": ";
    }
    return 0;
}


#include <sys/time.h>

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <utility>
#include <cctype>
#include <cstdlib>
#include <typeinfo>

using namespace std;

using ll = long long;
using i_i = pair<int, int>;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)

#define MOD 1000000007LL
#define INF 1e9

int x[17], y[17], z[17];
int dp[1 << 17][17];
int distance(int from, int to) {
	return abs(x[to] - x[from]) + abs(y[to] - y[from]) + max(0,z[to] - z[from]);
}

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

	rep(i, n) {
		cin >> x[i] >> y[i] >> z[i];
	}
	int max_bit = 1 << n;

	//cout << "max_bit:" << max_bit << endl;

	//cout << "rep start" << endl;

	rep(i, max_bit) {
		rep(j , n) {
			dp[i][j] = INF;
		}
	}
	//cout << "rep end" << endl;
	// v, dp
	queue< i_i > que;

	for(int i = 1; i < n; i++) {
		int bit = 1 << i;
		que.push(mkp(i,bit));
		dp[bit][i] = distance(0, i);
	}

	while(!que.empty()) {
		int from = que.front().first;
		int bit = que.front().second;
		que.pop();
		rep(i,n) {
			if ((bit | (1 << i)) == 1) continue;
			int cur_bit = bit | (1 << i);
			int nd = dp[bit][from] + distance(from, i);
			if(dp[cur_bit][i] > nd) {
				dp[cur_bit][i] = nd;
				que.push(mkp(i,cur_bit));
			}
		}
	}

	cout << dp[max_bit - 1] [0] << endl;

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

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

    ll n; cin >> n;
    ll a[n]; zep(i, 0, n)cin >> a[i];
    ll b[n]; zep(i, 0, n)cin >> b[i];

    ll ans = 0;
    zep(i, 0, n){
        ans += a[i] * b[i];
    }

    print((ans == 0)? "Yes" : "No")

    return 0;
}


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

#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pb push_back
#define ff first
#define ss second
#define YES printf("YES\n")
#define NO printf("NO\n")
#define sci(x) scanf("%d", &x)
#define LL_INF (1LL << 62)
#define INF (1 << 30)
#define SetBit(x, k) (x |= (1LL << k))
#define ClearBit(x, k) (x &= ~(1LL << k))
#define CheckBit(x, k) (x & (1LL << k))
#define mod 1000000007
#define N 200005

int main(){
	int t;
	cin >> t;
	while(t--){
		string s;
		cin >> s;

		int f = 0;
		string ss = "atcoder";

		for(int i = 0; i < 7; i++){
			if(i>=s.size()) break;
			if(s[i]<ss[i]) break;
			if(s[i]==ss[i]){
				if(i==6 && s.size()>ss.size()) f = 1;
				continue;
			}
			if(s[i]>ss[i]){
				f = 1;
				break;
			}
		}

		if(f){
			cout << 0 << "\n";
			continue;
		}

		for(int i = 0; i < s.size(); i++){
			if(s[i]!='a'){
				if(s[i]>'t') cout << i-1 << "\n";
				else cout << i << "\n";
				f = 1;
				break;
			}
		}

		if(!f) cout << -1 << "\n";
	}

	return 0;
}

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

struct fast_io {
    fast_io() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
    }
} __fast_io;

inline int64_t trisum(int32_t n) {
    if (n < 0)
        return 0;
    int64_t nll = n;
    return (nll * (nll + 1)) / 2;
}

int main() {
    int32_t T, L, R;
    cin >> T;

    while (T--) {
        cin >> L >> R;
        cout << trisum(R - 2 * L + 1) << '\n';
    }
}


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

ll dfs(ll n) {
  if(n == x) return 0;
  else if(n < x) return x - n;
  else if(mp[n] != 0) return mp[n];
  ll res = n - x;
  ll mod[1] = {n % 2};
  ll div[1] = {2};
  ll nex;
  rep(i,1) {
    nex = (n - mod[i])/div[i];
    res = min(res,dfs(nex)+1+mod[i]);
    nex++;
    if(mod[i] != 0) res = min(res,dfs(nex)+1+(div[i]-mod[i]));
  }
  return mp[n] = res;
}

int main(){
  cin >> x >> y;
  if(x >= y) {
    cout << x-y << endl;
    return 0;
  }
  cout << dfs(y) << endl;
  return 0;
}

#ifdef ONLINE_JUDGE
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#else
#define _GLIBCXX_DEBUG
#endif

#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <cmath>
#include <functional>
#include <set>
#include <numeric>
#include <bitset>
#include <cassert>

using std::cerr;
using std::cin;
using std::cout;
using std::pair;
using std::string;
using std::vector;
//region
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (b); i >= (b); --i)
#define rep(i, n) for (unsigned i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
#define repr(i, n) for (int i = (n)-1; i >= 0; --i)
#define repr1(i, n) for (int i = (n); i > 0; --i)
#define all(vec) (vec).begin(), (vec).end()
#define mset(v, n) std::memset((v), n, sizeof(v))
#define BIT(n) (1LL << (n))
#define each(i, v) for (auto&& i : (v))
#define unless(f) if(!(f))
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
using vint = vector<int>;
using vlong = vector<ll>;
using vstr = vector<string>;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pll = pair<ll, ll>;
using vpii = vector<pii>;
using vpil = vector<pil>;
using vpll = vector<pll>;
using vvi = vector<vint>;
using vvl = vector<vlong>;
template<typename T> using VV = vector<vector<T>>;

vector<string> split(const string &s, const string &delim) {
  vector<string> res;
  uint pos = 0;
  while (true) {
    const size_t found = s.find(delim, pos);
    if (found < 0) {
      res.push_back(s.substr(pos));
      break;
    }
    res.push_back(s.substr(pos, found - pos));
    pos = found + delim.size();
  }
  return res;
}

template<typename T>
string join(vector<T> &vec, const string &sep) {
  size_t size = vec.size();
  if (!size) return "";
  std::stringstream ss;
  for (int i = 0; i < size - 1; i++)
    ss << vec[i] << sep;
  ss << vec[size - 1];
  return ss.str();
}

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

template<typename Iter>
inline void print(const Iter &first, const Iter &last, const std::string &d = " ", bool endline = true) {
  cout << *first;
  for (Iter iter = first + 1; iter < last; ++iter) {
    cout << d << *iter;
  }
  if (endline) cout << "\n";
}

constexpr ll powmod(ll a, ull b, uint p) {
  ll res = 1;
  while (b > 0) {
    if (b % 2) res = res * a % p;
    a = a * a % p;
    b >>= 1u;
  }
  return res;
}

constexpr ll pow(ll a, ll b) {
  ll res = 1;
  while (b > 0) {
    if (b % 2) res = res * a;
    a = a * a;
    b >>= 1u;
  }
  return res;
}

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

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

template<typename T>
void bsort(vector<T> &v) { std::sort(v.begin(), v.end()); }

template<typename T>
void rsort(vector<T> &v) { std::sort(v.begin(), v.end(), std::greater<T>()); }

struct iii {
    iii() {
      cin.tie(nullptr);
      cout.tie(nullptr);
      std::ios::sync_with_stdio(false);
      cout << std::fixed << std::setprecision(16);
    }
} init;
//endregion

void solve();

int main() {
  int t = 1;
  // scanf("%d", &t);
  // cin >> t;
  rep(i, t) solve();
  return 0;
}

ll X, Y;
std::map<ll, ll> memo;

ll calc(ll n) {
  if (memo[n]) return memo[n];
  if (n <= X) return X - n;
  if (n - X == 1) return 1;

  ll res = n - X;

  ll l = n / 2 * 2, r = (n + 1) / 2 * 2;

  chmin(res, std::abs(l - n) + calc(l / 2) + 1);
  chmin(res, std::abs(r - n) + calc(r / 2) + 1);

  return memo[n] = res;
}

void solve() {
  cin >> X >> Y;
  cout << calc(Y) << std::endl;
}


//author : ainunsy1
#include <bits/stdc++.h>
#define forn(i,a,b) for(int i=a; i<=b; i++)
#define ford(i,a,b) for(int i=a; i>=b; i--)
#define fi first
#define se second
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
//before solving problems, please read line 15-25
//jgn lupa dicomment line 17-28 nya
const int MX=2e5+5;
void solve(){
	int n,a,b=0;
	cin>>n;
	forn(i,1,n){
		cin>>a;
		a-=10;
		b+=max(a,0);
	}
	cout<<b<<"\n";
	/*
		pikirin baik baik soalnya, dibuat santai aja
		kalo ngestuck, coba cari approach lain
		ngestucknya sampe bikin depresi? ingat! Allah itu dekat
		mintalah pertolongan kepada-Nya
		kamu cuma manusia biasa
		kamu lemah, ga usah sok jago
		yg buat km bs AC-in soal itu ya karena bantuan Allah
		Allah itu powerful, apapun bisa Dia lakukan
		minta pertolongan kepada-Nya ya
		semangat terus :)
	*/
}
int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	int t=1;
	// cin>>t;
	forn(i,1,t){
		solve();
	}
}

#include <bits/stdc++.h>
using namespace std;
int zh(string s)
{
	int ans=0;
	for (int i=0; i<s.size(); i++)
	{
	    ans = ans*10+(s[i]-'0');
	}
	return ans;
}
int main()
{
	string str;
	int a[10]={0};
	cin >> str;
	for(int i=0; i<str.size(); i++)
	{
		a[str[i]-'0']++;
	}
	if(str.size() == 1)
	{
	    if (str == "8")
		{
	        cout << "Yes";
        }
        else
		{
       	    cout << "No";
        }
        return 0;
    }
    if(str.size() == 2)
	{
        if(zh(str)%8==0)
		{
        	cout<<"Yes";
        	return 0;
        }
        else
		{
        	swap(str[0],str[1]);
        	if(zh(str)%8==0)
			{
        		cout << "Yes";
        		return 0;
        	}
        	else
			{
        		cout << "No";
        		return 0;
        	}
        }
    }
	for (int i=112; i<=992; i+=8)
	{
		int b, s, g;
		b = i/100;
		s = i/10%10;
		g = i%10;
		a[b]--; a[s]--; a[g]--;
		if (a[b]>=0 && a[s]>=0 && a[g]>=0)
		{
		   cout << "Yes";
		   return 0;
	    }
		else
		{
		   	a[b]++; a[s]++; a[g]++;
		}
	}
	cout << "No";
	return 0;
}


#include <bits/stdc++.h>
//#include <atcoder/all>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const long long INF = 1e18;
//const ll mod = 1000000007;

vector<string> f(ll N) {
    if(N == 1) {
        return {"AB"};
    }
    auto v = f(N - 1);
    vector<string> ret;
    for(int i = 0; i < v.size(); i++) {
        auto tmp = v[i] + v[i];
        ret.push_back(tmp);
    }
    for(int i = 0; i < v.size(); i++) {
        auto tmp = v[i];
        for(auto &c: tmp) {
            if(c == 'A') c = 'B';
            else c = 'A';
        }
        tmp += v[i];
        ret.push_back(tmp);
    }
    string S;
    for(int i = 0; i < (1 << N) / 2; i++) S.push_back('A');
    for(int i = 0; i < (1 << N) / 2; i++) S.push_back('B');
    ret.push_back(S);
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    auto ans = f(N);
    cout << ans.size() << endl;
    for(auto s : ans) cout << s << endl;
    return 0;
}

#include <iostream>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <map>

using namespace std;
typedef long long int ll;
typedef pair <int,int> pii;
typedef pair<ll,ll> pll;

/*bool compare_function(const pair<int, int> a, const pair<int, int> b)
{
    return a.first < b.first;
}*/
// use case
//sort(V.begin(), V.end(), compare_function);

/*struct compare
{
    bool operator ()(const pair<int, int> &a, const pair<int, int> &b) {
    if (a.second-a.first==b.second-b.first)
    {
        return a.first>b.first;
    }
    return a.second-a.first < b.second-b.first;}
};
priority_queue <pair<int,int>, vector <pair<int,int>>, compare> Q;*/

/*void print1(vector <int> X)
{
    for (int i=0; i<X.size(); i++)
    {
        cout<<X[i]<<" ";
    }
    cout<<endl;
    return;
}

void print2(vector <vector <int>> X)
{
    for (int i=0; i<X.size(); i++)
    {
    for (int j=0;j<X[i].size();j++) {
        cout<<X[i][j]<<" ";}
    cout<<endl;}
    return;
}*/

int sk(int x) {
	int a=0;
	while (x>0) {
		a+=x%2;
		x=x/2;
		}
	return a;
	}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    int k=1;
    for (int i=0;i<n;i++) {k*=2;}
    cout<<k-1<<endl;
    string s="A";
    for (int i=0;i<k-1;i++) {s+='A';}
    vector <string> A(k-1,s);
    for (int i=1;i<k;i++) {
		for (int j=0;j<k;j++) {
			int x=i&j;
			int v=sk(x);
			//cout<<i<<" "<<j<<" "<<x<<" "<<v<<endl;
			if (v%2==0) {A[i-1][j]='B';}
			}
		}
	for (int i=0;i<k-1;i++) {cout<<A[i]<<endl;}
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define flush cout.flush

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pl = pair<ll, ll>;
const ll INF = 1e9 + 7;
const ll mod = 1e9 + 7;
const ll mod2 = 998244353;
const ld eps = 1e-9;
const ld PI = acos(-1);

ll cur = -1;

ll calc(vector<ll> &a, vector<ll> &b) {
    ll res = INF * INF;
    vector<pl> z;
    for (ll i = 0; i < a.size(); ++i) {
        if (a[i] == cur) {
            cur = -1;
            continue;
        }
        z.push_back({a[i], 0});
    }
    for (ll i = 0; i < b.size(); ++i) {
        z.push_back({b[i], 1});
    }
    ll last0 = -1, last1 = -1;
    sort(z.begin(), z.end());
    for (ll i = 0; i < z.size(); ++i) {
        if (z[i].second == 0) {
            if (last1 != -1 && abs(z[i].first - last1) < res) {
                res = min(res, abs(z[i].first - last1));
            }
            last0 = z[i].first;
        } else {
            if (last0 != -1) {
                res = min(res, abs(z[i].first - last0));
            }
            last1 = z[i].first;
        }
    }
    cur = last0;
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin >> n;
    vector<ll> r, g, b;

    for (ll i = 0; i < 2 * n; ++i) {
        ll a;
        cin >> a;
        char c;
        cin >> c;
        if (c == 'R')r.push_back(a);
        if (c == 'B')b.push_back(a);
        if (c == 'G')g.push_back(a);
    }
    if (r.size() % 2 == 0 && b.size() % 2 == 0) {
        cout << "0\n";
        return 0;
    }
    ll res;
    if (r.size() % 2 == 0) {
        res = calc(g, b);
        ll tmp = calc(r, g);
        res = min(res, tmp + calc(r, b));
        cur = -1;
        tmp = calc(r, b);
        res = min(res, tmp + calc(r, g));
        cur = -1;
    } else if (b.size() % 2 == 0) {
        res = calc(r, g);
        ll tmp = calc(b, g);
        res = min(res, tmp + calc(b, r));
        cur = -1;
        tmp = calc(b, r);
        res = min(res, tmp + calc(b, g));
        cur = -1;
    } else {
        res = calc(r, b);
        ll tmp = calc(g, r);
        res = min(res, tmp + calc(g, b));
        cur = -1;
        tmp = calc(g, b);
        res = min(res, tmp + calc(g, r));
        cur = -1;
    }
    cout << res << "\n";
    return 0;
}


#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<iomanip>
#include<regex>
using namespace std;
#define int long long
const int mod=1e9+7;
bool pri[1000001],squf[1000001],even[1000001];
signed main(){
	int l,r;
	cin>>l>>r;
	for(int i=2;i<=r;i++)
		pri[i]=squf[i]=even[i]=1;
	for(int i=2;i<=r;i++){
		if(!pri[i])
			continue;
		for(int j=i;j<=r;j+=i){
			if(j!=i)
				pri[j]=0;
			even[j]=!even[j];
		}
		for(int j=i*i;j<=r;j+=i*i)
			squf[j]=0;
	}
	int ans1=0,ans2=0;
	for(int g=2;g<=r;g++){
		if(!squf[g])
			continue;
		int a=r/g-(l-1)/g;
		a=a*(a-1)/2;
		if(even[g])
			ans1-=a;
		else
			ans1+=a;
	}
	for(int g=max(2ll,l);g<=r;g++)
		ans2+=r/g-1;
	cout<<(ans1-ans2)*2<<endl;
}

#include <bits/stdc++.h>

#define loop(s, e, i) for (int i = s; i < e; ++i)
#define print(s) cout << s << endl;
#define DIV 1000000007
#define ll long long
using namespace std;

/*
浮動小数点の入力
cout << fixed << setprecision(9) << endl;
*/

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

  int N;
  string S;
  cin >> N >> S;

  int A=0, T=0, C=0, G = 0;
  vector<int> AV(N+1), TV(N+1), CV(N+1), GV(N+1);
  loop(0, S.size(), i) {
    switch(S[i]) {
      case 'A':
        A += 1;
        break;
      case 'T':
        T += 1;
        break;
      case 'C':
        C += 1;
        break;
      case 'G':
        G += 1;
        break;
    }
    AV[i+1] = A;
    TV[i+1] = T;
    CV[i+1] = C;
    GV[i+1] = G;
  }

  int count = 0;
  loop(0, S.size()+1, i) {
    loop(i+2, S.size()+1, j) {
      int ad = AV[j] - AV[i];
      int td = TV[j] - TV[i];
      int cd = CV[j] - CV[i];
      int gd = GV[j] - GV[i];
      if (ad == td && cd == gd){
        count++;
      }
    }
  }
  print(count);
}


#include <bits/stdc++.h>

using namespace std;

struct point {
  long long x, y, z;
  long long dist(const point &other) {
    return abs(x - other.x) + abs(y - other.y) + max(0LL, other.z - z);
  }
};

const long long LLINF = (long long) 1e18;
long long dp[22][1 << 22];

int main() {
  int N;
  cin >> N;
  vector<point> p(N);
  for (int i = 0; i < N; i++) {
    cin >> p[i].x >> p[i].y >> p[i].z;
  }

  for (int i = 0; i < 22; i++) for (int j = 0; j < (1 << 22); j++) {
    dp[i][j] = LLINF;
  }

  dp[0][0] = 0;
  for (int b = 0; b < (1 << N); b++) {
    for (int cur = 0; cur < N; cur++) {
      if (dp[cur][b] == LLINF) continue;

      for (int nxt = 0; nxt < N; nxt++) {
        if (b & (1 << nxt)) continue;

        const auto nxt_bit = b | (1 << nxt);
        dp[nxt][nxt_bit] = min(dp[nxt][nxt_bit], dp[cur][b] + p[cur].dist(p[nxt]));
      }
    }
  }

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

/*  Jai Shree Ram 🚩🚩🚩 */
#include "bits/stdc++.h"
#define ll long long int
#define oo 1000000000000000000
#define forr(i,n) for(int i=0;i<n;i++)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define all(x) x.begin(),x.end()
#define unique(v) sort(all(v)); v.resize(distance(v.begin(),unique(all(v))))
#define eb emplace_back
#define FF first
#define SS second
#define mem(a,v) memset(a,v,sizeof(a))
#define pb push_back
#define popcount(x) __builtin_popcount(x)

using namespace std;

template<typename T>
ostream &operator<<(ostream &output,const vector<T> &v){
    if(v.empty()) return output;
    for(int i=0;i<v.size()-1;i++) output << v[i] <<" ";
    output << v.back();
    return output;
}
template<typename T>
istream &operator>>(istream &input,vector<T> &v){
    for(auto &i: v) cin >> i;
    return input;
}
const int N = 3005 , mod = 1e9 + 7;
int best[N][N];
int n;
ll dp[N][N];

ll get(int i,int k){
    if( i > n) return 0;
    else if(best[i][k] == n+1) return 1;
    else if(best[i][k] == n+2) return 0;
    else if(dp[i][k]!=-1) return dp[i][k];
    else{
        ll ans = 0;
        ans += get(best[i][k] , k + 1);
        ans %= mod;
        ans += get(best[i][k] , k);
        ans %= mod;
        return dp[i][k] = ans;
    }
}

void __sol(){
    cin >> n;
    vector<ll> v(n); cin >> v;
    forr(i,n+3) forr(j,n+3) best[i][j] = n+2;
    mem(dp,-1);
    for(int k=1;k<=n;k++){
        vector<int> seen(k,-1);
        ll sum = 0;
        seen[0] = n + 1;
        for(int j=n;j>=1;j--){
            sum += v[j-1]%k;
            sum %= k;
            if(seen[sum]!=-1) best[j][k] = seen[sum];
            seen[sum] = j;
        }
    }
    cout << get(1,1)<<"\n";
    return;
}

int main(){
    fastio;
    int tc=1;  // cin >> tc;
    while(tc--) __sol();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()

ll comb_count(ll n, ll r) {
    if (r > n) return 0;
    if (r * 2 > n) r = n - r;
    if (r == 0) return 1;

    ll result = n;
    for (ll i = 2; i <= r; ++i) {
        result *= (n - i + 1);
        result /= i;
    }
    return result;
}

void solve(long long A, long long B, long long K) {
    K--;
    string ans;
    rep(i, A + B) {
        if (0 < A) {
            if (K < comb_count(A + B - 1, B)) {
                ans += "a";
                A--;
            } else {
                ans += "b";
                K -= comb_count(A + B - 1, B);
                B--;
            }
        } else {
            ans += "b";
            B--;
        }
    }
    cout << ans << endl;
}

int main() {
    long long A;
    std::scanf("%lld", &A);
    long long B;
    std::scanf("%lld", &B);
    long long K;
    std::scanf("%lld", &K);
    solve(A, B, K);
    return 0;
}

#include <iostream>
#include <math.h>
#include <iomanip>
#include <vector>
#include <unordered_map>
#include <algorithm>
#include <string>
#include <set>
#include <numeric>
#include <queue>
#include <map>

using namespace std;

int main(){

    int n,k,m;
    int total = 0;
    cin >> n >> k >> m;
    for(int i = 0;i<n-1;i++){
        int x;
        cin >> x;
        total += x;
    }
    for(int i = 0;i<=k;i++){
        //cout << ((double)total+i)/n<< endl;
        if(((double)total+i)/n >=m){
            cout << i;
            return 0;
        }
    }
    cout << -1;

}


/*
{
######################
#       Author       #
#        Gary        #
#        2021        #
######################
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define check_min(a,b) a=min(a,b)
#define check_max(a,b) a=max(a,b)
using namespace std;
//inline int read(){
//    int x=0;
//    char ch=getchar();
//    while(ch<'0'||ch>'9'){
//        ch=getchar();
//    }
//    while(ch>='0'&&ch<='9'){
//        x=(x<<1)+(x<<3)+(ch^48);
//        ch=getchar();
//    }
//    return x;
//}
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
/*}
*/
int fa[1000+12];
int h,w;
char maze[1001][1001];
char maze2[1001][1001];
int root(int now){
	return fa[now]=(fa[now]==now? now:root(fa[now]));
}
int solve(){
	rb(i,1,h) fa[i]=i;
	maze[1][1]=maze[1][w]=maze[h][1]=maze[h][w]='#';
	rb(j,1,w){
		vector<int> have;
		rb(i,1,h){
			if(maze[i][j]=='#'){
				have.PB(i);
			}
		}
		rep(i,have.size()){
			if(i>0){
				fa[root(have[i])]=root(have[i-1]);
			}
		}
	}
	int cnt=0;
	rb(i,1,h){
		cnt+=(root(i)==i);
	}
	return cnt-1;
}
int main(){
	cin>>h>>w;
	if(min(h,w)<=2){
		cout<<0<<endl;
		return 0;
	}
	rb(i,1,h)
		rb(j,1,w)
			cin>>maze[i][j];
	int rest=solve();
	swap(h,w);
	rb(i,1,h)
		rb(j,1,w)
			maze2[i][j]=maze[j][i];
	rb(i,1,h)
		rb(j,1,w)
			maze[i][j]=maze2[i][j];
	check_min(rest,solve());
	cout<<rest<<endl;
	return 0;
}


#include <bits/stdc++.h>
#include <unistd.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define int long long int
#define Sort(a) sort(a.begin(),a.end())
#define FOR(i,a) for(int i=0;i<a;i++)
#define print(arr,n) for(int i=0;i<n;i++)cout<<arr[i]<<" "
#define scan(arr,n) for(int i=0;i<n;i++)cin>>arr[i]
#define MOD(x) x%1000000007
#define MAX 1e9
#define MIN -1e9
#define ff first
#define ss second
#define vi vector<int>
#define minimum(a) *min_element(a.begin(), a.end())
#define maximum(a) *max_element(a.begin(), a.end())
#define mem(x,val) memset((x),(val),sizeof(x))
#define sqr(x) x*x
#define sp <<" "
#define nl cout<<"\n"
#define pii pair<int,int>
#define startTime clock_t start, end; start = clock();
#define endTime end = clock(); double time_taken = double(end - start) / double(CLOCKS_PER_SEC); cout << "Time taken by program is : " << fixed  << time_taken << setprecision(5);cout << " sec " << endl;
#define all(a) a.begin(),a.end()

int check(int n,int m,vector<pii> a,vector<pii> c,int k,int pos,vi ans){

    // cout<<pos sp;
    if(pos>=k){
        int c=0;
        vi dp(n+1,0);
        for(auto i:ans){
            dp[i]=1;
            // cout<<i sp;
        }
        // nl;
        for(int i=0;i<m;i++){
            if(dp[a[i].ff]!=0 && dp[a[i].ss]!=0)c++;
        }
        return c;
    }
    vi temp1,temp2;
    for(auto i:ans)temp1.pb(i);
    for(auto i:ans)temp2.pb(i);
    temp1.pb(c[pos].ff);
    temp2.pb(c[pos].ss);

    // print(temp1,temp1.size());
    // nl;
    // print(temp2,temp2.size());
    // nl;
    return max(check(n,m,a,c,k,pos+1,temp1),check(n,m,a,c,k,pos+1,temp2));

}

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

    int n,m;
    cin>>n>>m;

    vector<pii> a(m);
    FOR(i,m){
        cin>>a[i].ff>>a[i].ss;
    }
    int k;
    cin>>k;

    vector<pii> c(k);
    FOR(i,k){
        cin>>c[i].ff>>c[i].ss;
    }

    int ans=check(n,m,a,c,k,0,{});
    cout<<ans;
    // endTime
    return 0;
}

#include<iostream>
#include<string>
#include<cmath>
#include<algorithm> //max,min
#include<iomanip> //setprecision,tuple
#include<vector>  //vector
#include<numeric> //iota
#include<map> //map
#include<set> //set
#include<sstream> //stringstream(hex 16,dec 10,oct 8,bilset 2)
#include<list> //list
using namespace std;
using lint = long long;
#define INF 2147483647
#define PI acos(-1)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int main(){
    int n,m;cin>>n>>m;
    vector<pair<int,int>> pa;
    rep(i,m){
        int a,b;cin>>a>>b;
        a--;b--;
        pa.push_back(make_pair(a,b));
    }
    int k;cin>>k;
    vector<pair<int,int>> p;
    rep(i,k){
        int c,d;cin>>c>>d;
        c--;d--;
        p.push_back(make_pair(c,d));
    }
    int ans=0;
    rep(s,1<<k){
        set<int> tmp;
        rep(i,k){
            if(s>>i&1)tmp.insert(p[i].first);
            else tmp.insert(p[i].second);
        }
        int cnt=0;
        for(auto x:pa){
            int tmpa=x.first,tmpb=x.second;
            if(tmp.count(tmpa)&&tmp.count(tmpb))cnt++;
        }
        ans=max(cnt,ans);
    }
    cout<<ans<<endl;
    return 0;
}


#include<iostream>
#include<algorithm>
#include<map>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
#include<set>
#define ll long long
#define pb push_back
#define forn(i,x,n) for(int i=x;i<=n;++i)
#define forr(i,x,n) for(int i=n;i>=x;--i)
#define lson (rt<< 1)
#define rson (rt<< 1 | 1)
#define gmid ((l+r)>> 1 )
using namespace std;

const int maxn=20000050;
int a[maxn];
int main()
{
	int n;
	cin>>n;
	forn(i,1,n)
	  cin>>a[i];
	sort(a+1,a+n+1);
	bool f=true;
	forn(i,1,n)
	  if(a[i]==a[i-1]||a[i]<1||a[i]>n)
	    f=false;
	if(f) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define Vi vector<int>
#define for_(i, a, b) for(int i = (a);i < (b);++i)
#define ford_(i, a, b) for(int i = (b)-1;i >= (a);--i)
#define rep(i, n) for_(i, 0, n)
#define repd(i, n) rfor_(i, 0, n)

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

  vector<ll> A(N);
  rep(i,N){
    cin >> A.at(i);
  }
  vector<ll> low(N); //C
  rep(i,N){
    low.at(i) = A.at(i) - (i+1);
  }

  while(Q--){
    ll K;
    cin >> K;
    const int idx = lower_bound(low.begin(), low.end(), K) - low.begin();
    if(idx == N){
      cout << A[N-1] + (K - low[N-1]) << '\n';
    } else {
      cout << A[idx] - (low[idx] - K+1) << '\n';
    }
  }

}


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

#define UKWN_RTO 0.9
#define SMPL_EXEC_CNT 150

int si, sj, ti, tj, ch[29][30]={0}, cw[30][29]={0}, len, tc=0;
double lh[29][30]={0}, lw[30][29]={0}, pl[30][30], tmp, tl=0;
string pp[30][30];

bool gl(int pi, int pj)
{
	return pj > tj;
}

double ll(int pi, int pj)
{
	if (tc == 0)
		return 1;

	if (cw[pi][pj-1] == 0)
		return tl / tc * UKWN_RTO;

	return lw[pi][pj-1] / cw[pi][pj-1];
}

bool gr(int pi, int pj)
{
	return pj < tj;
}

double lr(int pi, int pj)
{
	if (tc == 0)
		return 1;

	if (cw[pi][pj] == 0)
		return tl / tc * UKWN_RTO;

	return lw[pi][pj] / cw[pi][pj];
}

bool gu(int pi, int pj)
{
	return pi > ti;
}

double lu(int pi, int pj)
{
	if (tc == 0)
		return 1;

	if (ch[pi-1][pj] == 0)
		return tl / tc * UKWN_RTO;

	return lh[pi-1][pj] / ch[pi-1][pj];
}

bool gd(int pi, int pj)
{
	return pi < ti;
}

double ld(int pi, int pj)
{
	if (tc == 0)
		return 1;

	if (ch[pi][pj] == 0)
		return tl / tc * UKWN_RTO;

	return lh[pi][pj] / ch[pi][pj];
}

void calc2(int pi, int pj)
{
	while (true)
	{
		while(true)
		{
			if (gu(pi, pj))
			{
				tmp = pl[pi][pj] + lu(pi, pj);
				if (tmp < pl[pi-1][pj])
				{
					pl[pi-1][pj] = tmp;
					pp[pi-1][pj] = pp[pi][pj];
					pp[pi-1][pj] += 'U';
				}
			}

			else if (gd(pi, pj))
			{
				tmp = pl[pi][pj] + ld(pi, pj);
				if (tmp < pl[pi+1][pj])
				{
					pl[pi+1][pj] = tmp;
					pp[pi+1][pj] = pp[pi][pj];
					pp[pi+1][pj] += 'D';
				}
			}

			if (gl(pi, pj))
			{
				tmp = pl[pi][pj] + ll(pi, pj);
				pj--;
				if (tmp < pl[pi][pj])
				{
					pl[pi][pj] = tmp;
					pp[pi][pj] = pp[pi][pj+1];
					pp[pi][pj] += 'L';
				}
			}

			else if (gr(pi, pj))
			{
				tmp = pl[pi][pj] + lr(pi, pj);
				pj++;
				if (tmp < pl[pi][pj])
				{
					pl[pi][pj] = tmp;
					pp[pi][pj] = pp[pi][pj-1];
					pp[pi][pj] += 'R';
				}
			}

			else
				break;
		}

		pj = sj;
		if (gu(pi, pj))
			pi--;
		else if (gd(pi, pj))
			pi++;
		else
			break;
	}
}

void calc3()
{
	bool f[30][30];
	for (int j=0; j<30; j++)
		for (int k=0; k<30; k++)
			f[j][k] = true;

	for (int i=0; i<900; i++)
	{
		int pi, pj;
		double d = 1e100;
		for (int j=0; j<30; j++)
			for (int k=0; k<30; k++)
				if (f[j][k] && pl[j][k] < d)
				{
					pi = j;
					pj = k;
					d = pl[j][k];
				}

		f[pi][pj] = false;

		if (pi > 0)
		{
			tmp = pl[pi][pj] + lu(pi, pj);
			if (tmp < pl[pi-1][pj])
			{
				pl[pi-1][pj] = tmp;
				pp[pi-1][pj] = pp[pi][pj];
				pp[pi-1][pj] += 'U';
			}
		}

		if (pi < 29)
		{
			tmp = pl[pi][pj] + ld(pi, pj);
			if (tmp < pl[pi+1][pj])
			{
				pl[pi+1][pj] = tmp;
				pp[pi+1][pj] = pp[pi][pj];
				pp[pi+1][pj] += 'D';
			}
		}

		if (pj > 0)
		{
			tmp = pl[pi][pj] + ll(pi, pj);
			if (tmp < pl[pi][pj-1])
			{
				pl[pi][pj-1] = tmp;
				pp[pi][pj-1] = pp[pi][pj];
				pp[pi][pj-1] += 'L';
			}
		}

		if (pj < 29)
		{
			tmp = pl[pi][pj] + lr(pi, pj);
			if (tmp < pl[pi][pj+1])
			{
				pl[pi][pj+1] = tmp;
				pp[pi][pj+1] = pp[pi][pj];
				pp[pi][pj+1] += 'R';
			}
		}
	}
}

int main()
{
	for (int i=0; i<1000; i++)
	{
		cin >> si >> sj >> ti >> tj;
		for (int j=0; j<30; j++)
			for (int k=0; k<30; k++)
			{
				pp[j][k] = "X";
				pl[j][k] = 1e100;
			}
		pl[si][sj] = 0;
		pp[si][sj] = "";
		if (i < SMPL_EXEC_CNT)
			calc2(si, sj);
		else
			calc3();

		string path = pp[ti][tj];
		cout << path << endl;
		cin >> len;
		len /= path.length();
		tc++;
		tl += len;
		for (int j=0; j<path.length(); j++)
			switch (path[j])
			{
				case 'U':
					si--;
					ch[si][sj]++;
					lh[si][sj] += len;
					break;
				case 'D':
					ch[si][sj]++;
					lh[si][sj] += len;
					si++;
					break;
				case 'L':
					sj--;
					cw[si][sj]++;
					lw[si][sj] += len;
					break;
				case 'R':
					cw[si][sj]++;
					lw[si][sj] += len;
					sj++;
					break;
			}
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(nullptr);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

const int HW = 30;
const int Q = 1000;

void out(string s) {
    cout << s << '\n';
    cout.flush();
}

struct route {
    pii xy;
    string r;
};

int main(void)
{
    REP(i,Q) {
        pii s,t;
        cin >> s.first >> s.second >> t.first >> t.second;
        cin.ignore();

        string ans = "";
        if (s.first < t.first) ans += string(t.first-s.first,'D');
        else ans += string(s.first-t.first,'U');
        if (s.second < t.second) ans += string(t.second-s.second,'R');
        else ans += string(s.second-t.second,'L');

        out(ans);
        int score;
        cin >> score;
        cin.ignore();
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ll long long
template <typename T>
bool PN(T x){ if (x <= 1) return false; if (x == 2) return true; for (int i = 2; i < sqrt(x) + 1; i++) if (x % i == 0) return false; return true;}
const ll MOD = 1e9+7;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
long long Comb(int n, int i){long long ans = 1; if(i>n || i < 0) return 0; if(i == 0 || i == n) return 1; else {for(int j = 1; j <= i; ++j){ans *=(n+1-j); ans /= j; ans %= MOD;} }return ans;}
template<typename T> T gcd(T a, T b){if(b == 0) return a;else return gcd(b, a%b);}
template<typename T> T lcm(T a, T b){if(b > a) swap(a, b); T g = gcd(a, b);return a / g * b;}

void solve(){
  int n; cin >> n;
  int a[n];
  int sum = 0;
  for(int i = 0; i < n; ++i) {
    cin >> a[i];
    sum += a[i];
  }
  int dp[n + 1][sum + 1] = {};
  for(int i = 1; i <= n; ++i) {
    for(int j = 0; j <= sum; j++) {
      if(j-a[i-1] >= 0) dp[i][j] = max(dp[i-1][j-a[i-1]] + a[i-1], dp[i][j]);
      dp[i][j] = max(dp[i-1][j], dp[i][j]);
    }
  }
  //cout << dp[n][sum/2] << endl;
  cout << sum-dp[n][sum/2] << endl;
}

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

#include <bits/stdc++.h>
using namespace std;
//const long nPrime = 1000000007;
//const long nPrime = 998244353;

class BIT{
    public:
    BIT(int n){
        m_n = 1;
        while(m_n < n){
            m_n *= 2;
        }
        m_vi.resize(m_n, 0);
    }
    ~BIT(){
    }

    void Add(const int i, long x){
        if(i >= m_n || i < 0){
            return;
        }
        m_vi[i] += x;  //FIXME
        int iTmp = i;
        while(iTmp != 0){
            iTmp -= (iTmp & (-iTmp));
            m_vi[iTmp] += x;  //FIXME
        }
    }

    long GetNum(const int i){
        if(i >= m_n || i < 0){
            return -1;  //error
        }
        long nBase = m_vi[i];
        int iFin = i & (-i);
        int iTmp = 1;
        long nSum = 0;
        while(iTmp < m_n){
            if(iTmp == iFin){
                break;
            }
            nSum += m_vi[i+iTmp];  //FIXME
            iTmp *= 2;
        }
        return (nBase - nSum);
    }

    //[i,j)のsum
    //i>jの処理を考えること
    long GetSum(int i, int j){
        if(i > m_n || j > m_n){
            return -1;  //error
        }
        if(i != 0){
            return (GetSum(0, j) - GetSum(0, i));
        }
        int iTmp = j;
        long nSum = 0;
        while(iTmp < m_n){
            nSum += m_vi[iTmp];  //FIXME
            if(iTmp == 0){
                break;
            }
            iTmp += (iTmp & (-iTmp));
        }
        return m_vi[0] - nSum;
    }
    private:
    int m_n;
    vector<long> m_vi;
};

//正数列の反転数  値が大きいときor負の値を含むときは座圧とかしておくこと
long GetInversion(const vector<int> &viNum){
    int n = viNum.size();
    int nMax = 0;
    for(int i = 0; i < n; i++){
        nMax = max(viNum[i], nMax);
    }
    BIT zBit(nMax+1);
    long nReturn = 0;
    for(int i = n-1; i >= 0; i--){
        nReturn += zBit.GetSum(0,viNum[i]);
        zBit.Add(viNum[i], 1);
    }
    return nReturn;
}

int main() {
    long n;
    cin >> n;
    map<long, vector<long>> miA, miB;
    for(long i = 0; i < n; i++){
        long a;
        cin >> a;
        auto itr = miA.find(a+i);
        if(itr == miA.end()){
            vector<long> viTmp(1,i);
            miA.insert(make_pair(a+i, viTmp));
        }
        else {
            itr->second.push_back(i);
        }
    }
    for(long i = 0; i < n; i++){
        long a;
        cin >> a;
        auto itr = miB.find(a+i);
        if(itr == miB.end()){
            vector<long> viTmp(1,i);
            miB.insert(make_pair(a+i, viTmp));
        }
        else {
            itr->second.push_back(i);
        }
    }

    vector<int> viNum(n);
    for(auto itrA = miA.begin(); itrA != miA.end(); itrA++){
        auto itrB = miB.find(itrA->first);
        if(itrB == miB.end()){
            cout << -1 << endl;
            return 0;
        }
        if(itrA->second.size() != itrB->second.size()){
            cout << -1 << endl;
            return 0;
        }
        for(int i = 0; i < itrA->second.size(); i++){
            viNum[itrA->second[i]] = itrB->second[i];
        }
    }

    cout << GetInversion(viNum) << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long LL;

const int MAXN = 2E5 + 5;
const int MOD = 998244353;
int n, k;
LL sum[301], C[301][301], a[MAXN];

template <class T>
void read(T& x) {
    x = 0;
    T f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') f = (ch == '-' ? -1 : 1), ch = getchar();
    while (ch >= '0' && ch <= '9') x = x * 10 + ch - 48, ch = getchar();
    x *= f;
}

template <class T, class... Args>
void read(T& x, Args&... args) {
    read(x), read(args...);
}

LL qpow(LL a, LL b, LL MOD) {
    LL ans = 1, base = a;
    while (b) {
        if (b & 1) ans = ans * base % MOD;
        b >>= 1, base = base * base % MOD;
    }
    return ans;
}

void add(LL& a, LL b) { a = ((a + b) % MOD + MOD) % MOD; }

void init() {
    for (int i = 0; i <= 300; i++) C[i][0] = 1;
    for (int i = 1; i <= 300; i++)
        for (int j = 1; j <= 300; j++)
            C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % MOD;
    sum[0] = n;
    for (int i = 1; i <= n; i++) {
        LL tmp = 1;
        for (int x = 1; x <= k; x++) {
            tmp = tmp * a[i] % MOD;
            add(sum[x], tmp);
        }
    }
}

signed main() {
    read(n, k);
    for (int i = 1; i <= n; i++) read(a[i]);
    init();
    for (int x = 1; x <= k; x++) {
        LL ans = 0;
        for (int i = 0; i <= x; i++)
            add(ans, C[x][i] * (sum[i] * sum[x - i] % MOD - sum[x]) % MOD);
        printf("%lld\n", ans * qpow(2, MOD - 2, MOD) % MOD);
    }
    return 0;
}

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
static inline void PUT(char c)
{
  static char buf[1<<15],*ptr=buf;
  if(ptr==buf+strlen(buf)||c==0){fwrite(buf,1,ptr-buf,stdout),ptr=buf;}*ptr++=c;
}
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void OUT(long a)
{
  if(a<0)PUT('-'),a=-a;
  int d[40],i=0;do{d[i++]=a%10;}while(a/=10);
  while(i--){PUT(d[i]+48);}PUT('\n');
}
const int MOD=998244353,inv2=(MOD+1)/2;
int fact[301],inv[301];
static inline int MPow(int a,int b){return b?1l*MPow(1l*a*a%MOD,b>>1)*(b&1?a:1)%MOD:1;}
static inline int comb(const int n,const int k)
{
  if(k<0||n<k){return 0;}return 1l*fact[n]*inv[n-k]%MOD*inv[k]%MOD;
}
int main(void)
{
  int N=IN(),K=IN(),A,sum[301]={0},temp=1,total=0;
  fact[0]=1;rep(i,K)fact[i+1]=1l*fact[i]*(i+1)%MOD;
  inv[K]=MPow(fact[K],MOD-2);
  rep(i,K)inv[K-1-i]=1l*inv[K-i]*(K-i)%MOD;
  rep(i,N){A=IN();temp=1;rep(j,K+1){sum[j]=(sum[j]+temp)%MOD;temp=1l*temp*A%MOD;}}
  rep(i,K)
  {
    total=0;
    rep(j,i+2){total=(1l*total+1l*comb(i+1,j)*(1l*sum[j]*sum[i+1-j]%MOD)%MOD)%MOD;}
    total=(1l*total-1l*sum[i+1]*MPow(2,i+1)%MOD)%MOD;
    OUT(1l*((1l*total+MOD)%MOD)*inv2%MOD);
  }
}


#include <iostream>
#include <vector>
#include <cstdlib>
#include <set>
#include <iostream>
#include <iomanip>
#include<stdio.h>
#include<climits>
#include<vector>
#include<algorithm>
#include <cmath>
#include<map>
#include<deque>
#include<set>
#include<queue>
#include<cassert>
#include<functional>
#include<numeric>
#include<regex>

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

// 入力

int main() {
long long n,m,t,b;
  cin >> n >> m >> t;
bool flag = true;
long long d[m][2];
  for(int i=0;i<m;i++){
  cin >> d[i][0] >> d[i][1];
  }

b=n-d[0][0];
  //cout << b << endl;
if(b<=0) flag=false;
b+=d[0][1]-d[0][0];
if(b>=n)b=n;
  //cout << b << endl;
for(int i=1;i<m;i++){
b-=d[i][0]-d[i-1][1];
if(b<=0){
flag=false;
break;
}    //cout << b << endl;

b+=d[i][1]-d[i][0];
if(b>=n)b=n;
}
  //cout << b << endl;
b-=t-d[m-1][1];
if(b<=0){
flag=false;
}
  //cout << b << endl;
if(flag==false){
  cout << "No" << endl;
}
else cout << "Yes" << endl;
}

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

#include<bits/stdc++.h>
#define itn int
#define ll long long
#define pir pair<ll,ll>
#define yes {puts("Yes");}
#define no {puts("No");}
using namespace std;

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

int n,m;
struct edge{
	int v,nx;
	ll c,d;
}e[200005];
int cnt,hd[100005];

ll dis[100005];
bool vis[100005];

struct node{
	int i;
	ll w;
};
bool operator<(node a,node b){
	return a.w>b.w;
}

ll clac(ll t,ll c,ll d){
	if(!d)return c;
	ll sq=sqrt(d+2),ans=c+d/(t+1);
	for(ll st=t;st<=t+3;st++){
		ans=min(ans,d/(st+1)+st-t+c);
	}
	if(t+1<sq){
		for(ll st=t;st<=t+30;st++){
			ans=min(ans,d/(st+1)+st-t+c);
		}
		for(ll st=max(t,sq-30);st<=sq+5;st++){
			ans=min(ans,d/(st+1)+st-t+c);
		}
	}
	return ans;
}

void dij(){
	memset(dis,0x3f,sizeof dis);
	dis[1]=0;
	priority_queue<node>q;
	q.push(node{1,0});
	while(!q.empty()){
		node t=q.top();q.pop();
		if(vis[t.i])continue;
		vis[t.i]=1;
		for(int i=hd[t.i];i;i=e[i].nx){
			int v=e[i].v;
			ll w=clac(dis[t.i],e[i].c,e[i].d);
			if(dis[v]>dis[t.i]+w){
				dis[v]=dis[t.i]+w;
				q.push(node{v,dis[v]});
			}
		}
	}
}

int main(){
	n=read(),m=read();
	while(m--){
		int a=read(),b=read(),c=read(),d=read();
		e[++cnt]=edge{b,hd[a],c,d},hd[a]=cnt;
		e[++cnt]=edge{a,hd[b],c,d},hd[b]=cnt;
	}
	dij();
	if(dis[n]>1e18)cout<<-1;
	else cout<<dis[n]<<'\n';
	return 0;
}


//BY: YASH JAIN, CF: BitSane
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#define May_the_fork_be_with_you ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define rall(v) v.rbegin(),v.rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define deb(x) cout<<#x<<": "<<x<<endl;
#define debn(x) cout<<#x<<": "<<x<<"  ";
#define MOD 1000000007
#define mod 998244353
#define INF 1e18
#define ll long long
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define endl "\n"
#define int long long
#define N 100005
#define sq(x) ((x)*(x))
typedef vector<int> vi;
ll gcd(ll a, ll b) {if (!b)return a; return gcd(b, a % b);}
ll power(ll x, ll y, ll p = INF) {ll res = 1; x %= p; while (y > 0) {if (y & 1)res = (res * x) % p; y = y >> 1; x = (x * x) % p;} return res;}
// Do Not use power when calculating powers of 2 (its inefficient)

vector<vi> adj;
vi c, res;

void dfs(int u, int p, set<int>& st) {
    bool foo = false;
    if (st.find(c[u]) == st.end()) {
        foo = true;
        res.eb(u);
    }
    st.insert(c[u]);
    for (auto x : adj[u]) {
        if (x == p) continue;
        dfs(x, u, st);
    }
    if (foo) st.erase(c[u]);
}

void solve() {
    int n; cin >> n;
    adj.resize(n + 1);
    c.resize(n + 1);
    for1(i, n) cin >> c[i];
    forn(i, n - 1) {
        int u, v; cin >> u >> v;
        adj[u].eb(v);
        adj[v].eb(u);
    }
    set<int> st;
    dfs(1, -1, st);
    sort(all(res));
    for (int x : res) cout << x << endl;
}

int32_t main() {

#ifndef ONLINE_JUDGE
    // for geting input form input.txt
    freopen("input.txt", "r", stdin);
    // for wrting output to output.txt
    freopen("output.txt", "w", stdout);
#endif

    May_the_fork_be_with_you
    int t = 1;
    int x = 1;
    // cin >> t;
    cout << fixed << setprecision(12);
    while (t--) {
        // cout << "Case #" << x << ": ";
        solve();
        x++;
    }

#ifndef ONLINE_JUDGE
    cerr << "Time Taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
#endif
}

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

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

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

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

#define REP(i,n) for(int i=0;i<(n);++i)
#define COUT(x) cout<<(x)<<"\n"
#define COUT16(x) cout << fixed << setprecision(16) << (x) << "\n";
ll a[100010];
int main(){
    //input
    ll n;cin >> n;
    vector<ll>b(n),c(n);
    ll t,p;
    REP(i,n){
        cin >> t;
        a[t]++;
    }
    REP(i,n){
        cin >> b[i];
    }
    REP(i,n){
        cin >> p;
        --p;
        c[i] = p;
    }
    //計算
    ll count = 0;
    for(int i=0;i<n;i++){
        count += a[b[c[i]]];
    }
    COUT(count);
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using P = pair<ll, ll>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, -1, 0, 1};
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
char inverse_char(char c) {
  if(isupper(c)) return tolower(c);
  else return toupper(c);
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
struct edge {
  ll to, cost;
};

const int INF = 1001001001;

int main() {
  int H, W; cin >> H >> W;
  vector<string> a(H);
  REP(i, H) cin >> a[i];
  // ワープ使う時、Sから最も近いワープマスからワープするのが最善。
  // BFS中に最初にたどり着いたマスから全部のワープマスへワープするようにすると計算量が落ちる
  vector<vector<int>> dist(H, vector<int>(W, INF));
  queue<P> q;
  REP(i, H) {
    REP(j, W) {
      // Sを探す
      if(a[i][j] == 'S') {
        q.emplace(i, j); //push_backでpairを使ってpushする代わりに、pair型の値をpushしてくれる関数
        dist[i][j] = 0;
      }
    }
  }

  vector<vector<P>> warps(256);
  REP(i, H) {
    REP(j, W) {
      warps[a[i][j]].emplace_back(i, j);
    }
  }

  while(!q.empty()) {
    // 今から見る座標を取得する
    int i = q.front().first; int j = q.front().second;
    // queueから先頭を取り除く
    q.pop();
    // ゴールなら今いる位置の数字を出力する
    if(a[i][j] == 'G') {
      cout << dist[i][j] << endl;
      return 0;
    }
    //上下4方向を探索する
    REP(v, 4) {
      int ni = i + dx[v]; int nj = j + dy[v];
      if(ni < 0 || ni >= H || nj < 0 || nj >= W) continue; // 範囲外ならループをスキップ
      if(a[ni][nj] == '#') continue; // 壁ならループをスキップ
      if(dist[ni][nj] != INF) continue;
      dist[ni][nj] = dist[i][j] + 1;
      q.emplace(ni, nj);
    }

    if(islower(a[i][j])) { // 英字小文字なら...
      for(P p: warps[a[i][j]]) { // warpできる文字の位置を全探索する
        int ni = p.first; int nj = p.second;
        if(dist[ni][nj] != INF) continue;
        dist[ni][nj] = dist[i][j] + 1;
        q.emplace(ni, nj);
      }
      warps[a[i][j]].clear(); // 一度使ったワープ先は空にする
    }
  }
  cout << -1 << endl;
}

//BELIEVE IN YOURSELF
//next_permutation

#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define pob pop_back
#define vi vector<ll>
#define mp make_pair
#define sz size()
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define rep(i,n) for(ll i=0;i<n;i++)
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define maxx 100005
#define sec second
#define fi first
#define be begin()
#define en end()
#define sortv(v) sort(v.begin(),v.end());
#define sortr(v) sort(v.rbegin(),v.rend());
#define w() ll _;cin>>_;while(_--)
#define edge pair<ll,ll>
#define pq priority_queue<ll>
#define mod 1000000007
#define Endl "\n"
#define cy cout<<"YES"<<endl;
#define cn cout<<"NO"<<endl;
#define lb(v,x) std::lower_bound(v.begin(),v.end(),x)
#define ub(v,x) std::upper_bound(v.begin(),v.end(),x)

using namespace std;

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

ll n,m;

bool isvalid(ll x,ll y)
{
	if(x>=0 && y>=0 && x<n && y<m)
	{
		return true;
	}
	return false;
}

int main()
{
		fast;

		cin>>n>>m;
		ll i,j;
		string s;
		vector<string>g;

		for(i=0;i<n;i++)
		{
			cin>>s;
			g.pb(s);
		}

		ll a[n+1][m+1];
//		ll vis[n+1][m+1];

		ll inf=1e17;
		ll sx=0,sy=0,ex=0,ey=0;

		vector<vector<pair<ll,ll> > >tp(26);

		for(i=0;i<n;i++)
		{
			for(j=0;j<m;j++)
			{
				a[i][j]=inf;
				if(g[i][j]=='S')
				{
					a[i][j]=0;
					sx=i;
					sy=j;
				}
				if(g[i][j]=='G')
				{
					ex=i;
					ey=j;
				}
				if(g[i][j]>='a' && g[i][j]<='z')
				{
					char c=g[i][j];
					tp[c-'a'].pb(mp(i,j));
				}
			}
		}

		queue<pair<ll,ll> >q;

		q.push(mp(sx,sy));

		while(!q.empty())
		{
			ll x,y;
			pair<ll,ll>now =q.front();
			q.pop();

			x=now.fi;
			y=now.sec;

			for(i=0;i<4;i++)
			{
				ll nx,ny;
				pair<ll,ll>next = mp(x+dx[i],y+dy[i]);

				nx=next.fi;
				ny=next.sec;

				if(isvalid(nx,ny))
				{
					if(g[nx][ny]!='#' && a[nx][ny]==inf)
					{
						a[nx][ny]=a[x][y]+1;
						q.push(mp(nx,ny));
					}
				}

			}

			char c=g[x][y];

			if(islower(c))
			{
				for(auto next:tp[c-'a'])
				{
					ll nx,ny;
					nx=next.fi;
					ny=next.sec;

					if(a[nx][ny]==inf)
					{
						a[nx][ny]=a[x][y]+1;
						q.push(mp(nx,ny));
					}
				}

				tp[c-'a'].clear();

			}

		}

		ll ans=a[ex][ey];

		if(ans==inf)
		{
			cout<<-1<<Endl;
		}
		else
		{
			cout<<ans<<endl;
		}

	return 0;
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,s,n) for (int i = (s); i < (n); ++i)
#define rrep(i,n,g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define len(x) (int)(x).size()
#define dup(x,y) (((x)+(y)-1)/(y))
#define pb push_back
#define eb emplace_back
#define Field(T) vector<vector<T>>
#define pq(T) priority_queue<T,vector<T>,greater<T>>
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n;
  cin >> n;
  double ans = 1;
  rep(i,1,n) {
    ans *= i+1;
    ans /= i;
    if (i != n-1) ans += 1;
  }
  printf("%.10lf\n", ans);
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(i = 0; i < n; i++)
bool dfs(vector<int> &p, int swapFlag, int dep, vector<int> &ans) {
	int n = min(4, (int)p.size());
	int i;

	rep(i, n) if (p[i] != i) break;
	if (i == n) return true;
	if (dep >= n * n) return false;

	rep(i, n - 1) {
		if (i % 2 != swapFlag % 2) { continue; }
		swap(p[i], p[i + 1]);
		ans.push_back(i);
		bool res = dfs(p, !swapFlag, dep + 1, ans);
		if (res) return true;
		swap(p[i], p[i + 1]);
		ans.pop_back();
	}
	return false;
}

vector<int> solve(vector<int> p) {
	int n = p.size();
	int i, j;
	int cnt = 0;
	vector<int> ret;

	for (i = n; i >= 5; i--) {
		rep(j, i) if (p[j] == i - 1) break;
		int pos = j;
		if (pos == i - 1) continue;
		if (pos % 2 != cnt % 2) {
			rep(j, i - 1) {
				if (j != pos && j + 1 != pos && j % 2 == cnt % 2) {
					break;
				}
			}
			swap(p[j], p[j + 1]);
			cnt++;
			ret.push_back(j);
		}
		for (j = pos; j + 1 < i; j++) {
			swap(p[j], p[j + 1]);
			cnt++;
			ret.push_back(j);
		}
	}
	dfs(p, cnt % 2, 0, ret);
	return ret;
}

int main() {
	int T, i;

	cin >> T;
	while (T--) {
		int n;
		cin >> n;
		vector<int> p(n);
		rep(i, n) { cin >> p[i]; p[i]--; }

		vector<int> ans = solve(p);

		cout << ans.size() << endl;
		rep(i, ans.size()) {
			cout << ans[i] + 1;
			if (i + 1 < ans.size()) cout << " ";
		}
		cout << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})
#define rep(i, a, b) for(int i = (a); (i) < (b); ++(i))
#define trav(a, x) for(auto& a : x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) static_cast<int>(x.size())
#define mp make_pair
#define fi first
#define se second

using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

void buff() { ios::sync_with_stdio(false); cin.tie(nullptr); }

constexpr ll MOD = 1e9 + 7;

inline ll pow_mod(ll a, ll b, ll mod = MOD) {
    ll res = 1; a %= mod; assert(b >= 0);
    for(;b;b>>=1) {
        if(b & 1) res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}

template<typename T> inline void remin(T& x, const T& y) { x = min(x, y); }
template<typename T> inline void remax(T& x, const T& y) { x = max(x, y); }

template<typename T> ostream& operator<<(ostream &os, const vector<T>& v) {
    os << "{"; string sep; for(const auto& x : v) os << sep << x, sep = ", "; return os << "}";
}

template<typename T, size_t size> ostream& operator<<(ostream& os, const array<T, size>& arr) {
    os << "{"; string sep; for(const auto& x : arr) os << sep << x, sep = ", "; return os << "}";
}

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) {
    return os << '(' << p.first << ", " << p.second << ')';
}

int main() {
    buff();
    long long n;
    cin >> n;
    long long ans = n;
    long long cur_pot = 2;
    long long cur_exp = 1;
    while(cur_pot <= n)
    {
        long long res = (n / cur_pot) + cur_exp + (n % cur_pot);
        ans = min(res, ans);
        cur_pot <<= 1ll;
        cur_exp++;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  ll N;
  cin >> N;
  vector<ll> diff(N,0);
  ll sumA = 0;

  REP(i,N) {
    ll a,b;
    cin>>a>>b;
    sumA += a;
    diff[i] = (a+b)+a;
  }

  sort(diff.begin(),diff.end(),[](ll a,ll b){
    return a>b;
  });

  REP(i,N) {
    sumA -= diff[i];
    if(sumA<0){
      cout<<i+1<<endl;
      return 0;
    }
  }

  return 0;
}


//Let's join Kaede Takagaki Fan Club !!
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//#define int long long
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define a first
#define b second
#define fi first
#define sc second
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define all(x) x.begin(),x.end()
#define si(x) int(x.size())

#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif

template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b;return true;}else return false;}
template<class t,class u> bool chmin(t&a,u b){if(b<a){a=b;return true;}else return false;}

template<class t> using vc=vector<t>;

template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
	return os<<"{"<<p.fi<<","<<p.sc<<"}";
}

template<class t> ostream& operator<<(ostream& os,const vc<t>& v){
	os<<"{";
	for(auto e:v)os<<e<<",";
	return os<<"}";
}

template<class T>
void g(T &a){
	cin >> a;
}
template<class T>
void o(const T &a,bool space=false){
	cout << a << (space?' ':'\n');
}
//ios::sync_with_stdio(false);
const ll mod = 1000000007;//998244353
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
template<class T>
void add(T&a,T b){
	a+=b;
	if(a >= mod) a-=mod;
}
ll modpow(ll x,ll n){
	ll res=1;
	while(n>0){
		if(n&1) res=res*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return res;
}

#define sz (1<<19)
int par[sz],ran[sz];
void init(){ for(int i=0;i<sz;i++) par[i] = i, ran[i] = 0; }
int find(int x){ if(x == par[x]) return x; else return par[x] = find(par[x]); }
void unite(int x,int y){
	x = find(x); y = find(y); if(x==y) return;
	if(ran[x] < ran[y]) par[x] = y;
	else{
		par[y] = x;
		if(ran[x] == ran[y]) ran[x]++;
	}
}
bool same(int x,int y){ return find(x)==find(y); }

typedef __int128 L;
void solve(){
	map<int,int>M;
	int n; cin>>n;
	rep(i,n){
	    int a;cin>>a;M[a%200]++;
	}
	ll ans =0;
	for(auto a:M) ans += 1LL*a.b*(a.b-1)/2;o(ans);
}
signed main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);
	int t; t = 1; //cin >> t;
	while(t--) solve();
}

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

int main()
{
    int num;
    cin >> num;
    array<ll, 200> v;
    for(auto &i : v){
        i = 0;
    }
    for(int i=0;i<num;i++){
        int current;;
        cin >> current;
        v[current%200] ++;
    }
    ll ans = 0;
    for(auto &i : v){
        ans += (i * (i-1)) / 2;
    }
    cout << ans << endl;
    return 0;
}


#include <stdio.h>
int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int main() {
	int a = ri();
	int b = ri();
	int c = a + b;

	if (c >= 15 && b >= 8) puts("1");
	else if (c >= 10 && b >= 3) puts("2");
	else if (c >= 3) puts("3");
	else puts("4");

	return 0;
}

#include <bits/stdc++.h>
using namespace std;using ll=long long;
using vl=vector<ll>;using vi=vector<int>;
using vs=vector<string>;using vc=vector<char>;
using vvl=vector<vl>;using pl=pair<ll,ll>;
using vvc=vector<vc>;using vd=vector<double>;
using vpl=vector<pl>;using vb=vector<bool>;
#define rep(i,r) for(ll i=0;i<(r);i++)
#define Rep(i,l,r) for(ll i=(l);i<(r);i++)
#define print(n) cout<<(n)<<endl
#define all(a)  (a).begin(),(a).end()
#define sortp(d) sort(all(d)) //1234
#define sortm(d) sort(d.rbegin(),d.rend()) //4321
/*-----------順列生成-----------------
do
{
}while(next_permutation(all(A)));
*/
//'A'65,'a'97
//cout<<fixed<<setprecision(9)<<;
ll gcd(ll a,ll b) {if(b==0)return a;else return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll modpow(ll a,ll n,ll mod) {ll res=1;while(n>0)
{if(n&1)res=res*a%mod;a=a*a%mod;n >>= 1;}return res;}
ll modinv(ll a,ll mod){return modpow(a, mod - 2, mod);}

ll p=0,q=0,r=0;
ll dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
ll dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll inf=1000000000000; //10^12:∞
ll mod=1000000007; //10^9+7:合同式の法
struct edge{ll to,cost;};
const double pi = acos(-1);

int main(){
    ll a,b;cin>>a>>b;
    if(b>=8&&a+b>=15)print(1);
    else if(b>=3&&a+b>=10)print(2);
    else if(a+b>=3)print(3);
    else print(4);
}


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

typedef long long ll;
typedef long double ld;

const int N = 1e5 + 5;
const int M = 2000 + 5;
const int OO = 1e9;
const int mod = 1e9 + 7;

string s[3];
set<char> st;

int main() {

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

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

    for (auto & i : s) {
        cin >> i;
        for(auto & c : i) {
            st.insert(c);
        }
    }
    if(st.size() > 10) {
        cout << "UNSOLVABLE\n";
    } else {
        char dummy = 0;
        bool found = false;
        while(st.size() < 10) {
            st.insert(dummy++);
        }
        vector<char> v;
        v.reserve(st.size());
        for(auto & i : st) {
            v.push_back(i);
        }
        do {
            map<char, int> val;
            for (int i = 0; i < v.size(); ++i) {
                val[v[i]] = i;
            }
            string n[3];
            bool hasLeadingZeros = false;
            for (int i = 0; i < 3; ++i) {
                n[i].reserve(s[i].size());
                for(auto & c : s[i]) {
                    n[i].push_back(val[c] + '0');
                }
                hasLeadingZeros |= (n[i].front() == '0');
            }
            if(!hasLeadingZeros) {
                ll a = stoll(n[0]);
                ll b = stoll(n[1]);
                ll c = stoll(n[2]);
                if(a + b == c) {
                    for(auto & i : n) {
                        cout << i << '\n';
                    }
                    found = true;
                    break;
                }
            }

        } while(next_permutation(v.begin(), v.end()));
        if(!found) {
            cout << "UNSOLVABLE\n";
        }
    }
    return 0;
}

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

#ifdef LOCAL
#include "../debug.h"
#else
#define debug(x...) 141
#endif
#define forn(i,x,n) for(int i = x; i < n; ++i)
#define forit(it, m) for(auto it = m.begin(); it!=m.end(); ++it)
typedef long long ll;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,mm,x,y,ans=1e9;
    char c;

    cin>>n>>mm;
    map<char,vector<pair<int,int>>> m;
    set<pair<int,int>> edges;
    map<pair<int,int>,int> dist;

    forn(i,0,mm){
    	cin>>x>>y>>c;
    	edges.insert({x-1,y-1});
    	edges.insert({y-1,x-1});
    	m[c].push_back({x-1,y-1});
    	m[c].push_back({y-1,x-1});
    }

    map<pair<int,int>,vector<pair<int,int>>> adj;

    for(auto x:m)
    	for(auto [a,b]:x.second)
    		for(auto [c,d]:x.second)
    			adj[{a,c}].push_back({b,d});

    queue<pair<int,int>> q;
    q.push({0,n-1});
    dist[{0,n-1}]=0;
    while(q.size()){
    	auto [u,v]=q.front();
    	q.pop();
    	if(edges.count({u,v}))
    		ans=min(ans,1+dist[{u,v}]);
    	if(u==v)
    		ans=min(ans,dist[{u,v}]);
    	for(auto [a,b]:adj[{u,v}])
    		if(!dist.count({a,b}))
    			q.push({a,b}), dist[{a,b}]=dist[{u,v}]+2;
    }

    cout<<(ans==1e9?-1:ans)<<'\n';

    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

#define F first
#define S second
#define ALL(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORN(i,a,b) for(int i=a;i<=b;i++)
#define FORB(i,a,b) for(int i=a;i>=b;i--)
#define INT_MAXI 2147483647
#define INT_MINI -2147483648
#define REV(a) reverse(a.begin(),a.end())
#define NP(a) next_permutation(a.begin(),a.end())

typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll s,p; cin>>s>>p;
    for(ll i=1;i*i<=p;i++){
        ll temp=p/i;
        if(temp+i==s){
            cout<<"Yes\n";
            return 0;
        }
    }
    cout<<"No\n";
    return 0;
}

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

#define int long long
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define fr(i,j,k) for(i = j; i < (k); i++)
#define all(x) x.begin(), x.end()
#define el '\n'
#define remax(a,b) a = max(a, b)
#define remin(a,b) a = min(a, b)
#define sz(x) int32_t(x.size())

typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpi;
// --------------------------------------------------------------------

const pii dxy[] = { {-1, 0}, {1, 0}, {0, 1}, {0, -1} };
const int mod = 1e9 + 7;
const int INF = 2e18;
const ld EPS = 1e-9;
const int NN = 1e5 + 2;

string to_string(string s) {
      return '"' + s + '"';
}
string to_string(const char* s) {
      return to_string((string) s);
}
string to_string(bool b) {
      return (b ? "true" : "false");
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
      return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
      bool first = true;  string res = "{";
      for (const auto &x : v) {
            if (!first) { res += ", "; }
            first = false; res += to_string(x);
      }
      res += "}";	  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
      cerr << " " << to_string(H);
      debug_out(T...);
}

// #define TRACE

#ifdef TRACE
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
//============================================================================

void solve() {
      int i = 0, j = 0, k = 0, n = 0, m = 0;
      cin>>n>>m;
      vi a(n), ops(m);
      fr(i, 0, n) cin >> a[i];
      fr(i, 0, m) cin >> ops[i];

      sort(all(a));
      vi fwd(n, -INF); vi rev(n, -INF);
      for(i = 1; i<n; i += 2){
            fwd[i] = a[i]-a[i-1];
            if(i>1) fwd[i] += fwd[i - 2];
      }

      for(i = n-2; i >= 0; i -= 2) {
            rev[i] = a[i+1]-a[i];
            if(i<n-2) rev[i] += rev[i + 2];
      }
      debug(fwd);
      debug(rev);

      int ans = INF;
      fr(j, 0, m) {
            i = upper_bound(all(a), ops[j]) - a.begin();
            // insert ops at i-1
            if(i % 2 == 0) {
                  int t = i > 0 ? fwd[i - 1] : 0;
                  int g = a[i]-ops[j] + (i < n-1 ? rev[i+1] : 0);
                  g += t;
                  remin(ans, g);
                              debug(ans, i, ops[j]);

            }
            else {
                  int t = i > 1 ? fwd[i-2] : 0;
                  int g = abs(ops[j] - a[i-1]) + (i < n ? rev[i] : 0);
                  g += t;
                  remin(ans, g);
                              debug(ans, i, ops[j]);
            }
      }
      cout << ans << el;
}

int32_t main() {
      ios::sync_with_stdio(false); cin.tie(0);
      int T = 1;
      // cin >> T;
      for(int tc = 1; tc <= T; tc++) {
            solve();
       }
      return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<math.h>
#include<unordered_set>
#include<unordered_map>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define rrep(i,l,r) for(int i=l;i<=r;i++)
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define all(x) x.begin(),x.end()
#define unq(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define mod 1000000007
//#define mod 998244353
#define ad(a,b) a=(a+b)%mod;
#define mul(a,b) a=a*b%mod;
void readv(vector<ll> &a,ll n){
	rep(i,n){
		ll x;
		cin>>x;
		a.push_back(x);
	}
}
void outv(vector<ll> &a,ll n){
	rep(i,n){
		if(i>0)cout<<" ";
		cout<<a[i];
	}
	cout<<"\n";
}
ll po(ll x,ll y){
	ll res=1;
	for(;y;y>>=1){
		if(y&1)res=res*x%mod;
		x=x*x%mod;
	}
	return res;
}
ll gcd(ll a,ll b){
	return (b?gcd(b,a%b):a);
}
#define FACMAX 200010
ll fac[FACMAX],inv[FACMAX],ivf[FACMAX];
void initfac(){
	fac[0]=ivf[0]=inv[1]=1;
	for(ll i=1;i<FACMAX;i++)fac[i]=fac[i-1]*i%mod;
	for(ll i=1;i<FACMAX;i++){
		if(i>1)inv[i]=(mod-mod/i*inv[mod%i]%mod)%mod;
		ivf[i]=po(fac[i],mod-2);
	}
}
ll P(ll n,ll k){
	if(n<0||n<k)return 0;
	return fac[n]*ivf[n-k]%mod;
}
ll C(ll n,ll k){
	if(k<0||n<k)return 0;
	return fac[n]*ivf[n-k]%mod*ivf[k]%mod;
}
ll H(ll n,ll k){
	return C(n+k-1,k);
}

#define N 110
#define M 100010
ll n,m,a[M],b[M],c[N];
vector<ll> g[N];
ll d[N];
void dfs(ll x,ll dep){
	if(d[x]>=0)return;
	d[x]=dep;
	for(auto y:g[x]){
		dfs(y,dep+1);
	}
}
int main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cin>>n>>m;
	rep(i,m){
		cin>>a[i]>>b[i];
		a[i]--,b[i]--;
	}
	rep(i,n)cin>>c[i];
	rep(i,m){
		if(c[a[i]]==c[b[i]]){
			g[a[i]].pb(b[i]);
			g[b[i]].pb(a[i]);
		}
	}
	rep(i,n)d[i]=-1;
	rep(i,n){
		dfs(i,0);
	}
	rep(i,m){
		bool ans;
		if(c[a[i]]>c[b[i]])ans=0;
		else if(c[a[i]]<c[b[i]])ans=1;
		else if(d[a[i]]+1==d[b[i]])ans=0;
		else if(d[a[i]]==d[b[i]]+1)ans=1;
		else if(d[a[i]]>d[b[i]])ans=0;
		else ans=1;
		cout<<(ans==0?"->":"<-")<<"\n";

	}
}

#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll>
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++)
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1000000007;
const ll N=998244353;
ll power(ll x,ll n){ll res=1;while(n>0){if(n&1) res=res*x%MOD;x=x*x%MOD;n>>=1;}return res;}
ll modinverse(ll a){return power(a, MOD-2);}
vl val, depth;
ll n;
vector<vl> adj;
void dfs(ll node, ll parent, ll current)
{
	val[node]+=current;
	current=val[node];
	//cout<<node+1<<' '<<1+parent<<' '<<val[node]<<endl;
	for(auto x: adj[node])
	{
		if(x!=parent)
		{
			dfs(x, node, current);
		}
	}
}
void dfs2(ll node, ll parent, ll cur_depth)
{
	depth[node]=cur_depth;
	for(auto x: adj[node])
	{
		if(x!=parent)
		{
			dfs2(x, node, cur_depth+1);
		}
	}
}
void solve()
{
    cin>>n;
    adj.resize(n);
    depth.resize(n, 0);
    map<ll, pl> mp1;
    val.resize(n, 0);
    forr(i, n-1)
    {
    	ll u, v;
    	cin>>u>>v;
    	--u, --v;
    	mp1[i+1]={u, v};
    	adj[u].pb(v), adj[v].pb(u);
    }
    ll q;
    cin>>q;
    dfs2(0, -1, 0);
    while(q--)
    {
    	ll t, e, x;
    	cin>>t>>e>>x;
    	ll st, en;
    	if(t==1)
    	{
    		st=mp1[e].first;
    		en=mp1[e].second;
    	}
    	else
    	{
    		st=mp1[e].second;
    		en=mp1[e].first;
    	}
    	if(depth[st]>depth[en])
    	{
    		val[st]+=x;
    	}
    	else
    	{
    		//cout<<st+1<<' '<<en+1<<endl;
    		val[0]+=x;
    		val[en]-=x;
    	}
    }
    dfs(0, -1, 0);
    forr(i, n)
    {
    	cout<<val[i]<<endl;
    }
}
int main()
{
	#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll test=1;
    // cin>>test;
    while(test--)
    {
        solve();
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}