#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#pragma GCC optimize(2)
#include<set>
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<random>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_map>
#include<unordered_set>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int main()
{
    IO;
    int T=1;
    //cin>>T;
    while(T--)
    {
        double x,y,a,b;
        cin>>x>>y>>a>>b;
        double res=x+(y/(y+b))*(a-x);
        printf("%.8lf\n",res);
    }

    return 0;
}

#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
void read(int &x){
	static char c;
	while(!isdigit(c=getchar())); x=c^48;
	while(isdigit(c=getchar()))x=(x*10)+(c^48);
}
void read(ll &x){
	static char c;
	while(!isdigit(c=getchar())); x=c^48;
	while(isdigit(c=getchar()))x=(x*10)+(c^48);
}
void chkmax(int &x,int y){if(y>x)x=y;}
void chkmin(int &x,int y){if(y<x)x=y;}
void chkmax(ll &x,ll y){if(y>x)x=y;}
void chkmin(ll &x,ll y){if(y<x)x=y;}

int A,B;

void Work(){
	read(A),read(B);
	for(int i=B;i;--i){
		int d=(A-1)/i+1;
		if(1ll*i*(d+1)<=B) return printf("%d\n",i),void();
	}
}

int main(){Work();}


#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define pb push_back
#define __ ios_base::sync_with_stdio(false);cin.tie(NULL);

#define bs 97
#define mx 4000007

int main() {
    __

    ll s , p ;
    cin >> s >> p ;
    ll i ;
    ll ans = 0 ;

    for (i = 1 ; i * i <= p ; i++) {
        if (p%i == 0) {
            ll x = p/i , y = i ;
            if (x + y == s) return cout << "Yes\n", 0 ;
        }
    }

    cout << "No\n" ;

    return 0 ;
}

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
#include <climits>
#include <iomanip>
#include <queue>
#include <stack>
#include <ctype.h>

using namespace std;

typedef long long ll;

const int INF = (1<<30)-1;
const ll LINF = 1e18;

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

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

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

ll mod_pow(ll a, ll n, ll p) {
    ll  ans = 1, tmp = a % p;
    while (n > 0) {
        if (n % 2)
            ans = ans * tmp % p;
        tmp = tmp * tmp % p;
        n /= 2;
    }
    return ans;
}

int main() {
    ll n, m;    cin >> n >> m;
    cout << mod_pow(10, n, m*m) / m << endl;
    return 0;
}

//小数点精度
//cout << fixed << std::setprecision(15) << y << endl;


#include <iostream>
using namespace std;

using ll = long long;

int main() {
  ll K; cin >> K;

  ll res = 0;
  for (int a=1; a<=K; ++a) {
    for (int b=1; b<=K/a; ++b) {
      ll prod = a*b;
      res += K/(a*b);
    }
  }

  cout << res << endl;
}

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

template <typename T, typename U> bool cmin(T &a, U b) { return a > b && (a = b, true); }
template <typename T, typename U> bool cmax(T &a, U b) { return a < b && (a = b, true); }

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

  string S;
  cin >> S;
  int N = S.size();

  int mx = INT_MIN;
  for (int bit = 0; bit < 1 << N; bit++) {
    int tmp = 0;
    for (int i = 0; i < N; i++) {
      if (bit >> i & 1) tmp += S.at(i) - '0';
    }
    if (tmp % 3 == 0) cmax(mx, __builtin_popcount(bit));
  }
  cout << ((mx == 0) ? -1 : N - mx) << "\n";
}


#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define REP(i, n) for(int i = 0;i < (n);i++)
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=1000000007;
const llint inf=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-10;
template <class T,class U>bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	cout<<fixed<<setprecision(20);
	cin.tie(0);ios::sync_with_stdio(false);
	llint i,n;cin>>n;
	//x円保険すると、 失うのはmax(x,A-x)
	//失うのの中央値/2保険する
	vector<double>A(n);
	for(i=0;i<n;i++){cin>>A[i];}
	SO(A);
	double x=A[n/2]/2;
	double ans=0;
	for(i=0;i<n;i++){ans+=max(x,A[i]-x);}
	cout<<ans/n<<endl;
	return 0;
}

#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define f(x, m) for(auto x : m)
#define cpu() ios::sync_with_stdio(false); cin.tie(nullptr)
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pair<int ,int>>
#define vll vector<pair<ll ,ll>>
#define all(v) v.begin(),v.end()
#define sor(a) sort( a.begin(), a.end() )
#define ros(a) sort( a.rbegin(), a.rend())
#define prec(n) fixed << setprecision(n)
#define ff first
#define ss second
#define print(x) for(auto it : x) cout << it << " ";
#define debug(x) cerr << #x << " is " << x << endl;

typedef long long ll;
using namespace std;
// using namespace __gnu_pbds;
#define dbg(args...){ string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> ) {cout << "NEXT\n"; }
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << ", ";
err(++it, args...);
}
template<typename... T>
void rd(T& ... args){
   (( cin >> args), ...);
}
template<typename... T>
void ps(T ... args){
   ((cout << args << ' '), ...);
   cout << '\n';
}
//  mp.max_load_factor(0.25);
// using ordered_set = tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update>;
const int MOD = 998244353;
const char nl = '\n';
const int INF = 1e9 + 5;
int n;
void add(int& x, int y){
   x += y;
   if(x >= MOD){
      x -= MOD;
   }
}

void res(int& x, int y){
   x -= y;
   if(x < 0){
      x += MOD;
   }
}
ll pot(ll x, ll y){
   if(y == 0) return 1;
   if(y & 1) return (pot(x, y - 1) * x) % MOD;
   ll k = pot(x, y / 2);
   return (k * k) % MOD;
}
ll inv(ll x){
   return pot(x, MOD - 2);
}
void solve(){
   cin >> n;
   vi a(n);
   for(int& it : a){
      cin >> it;
   }
   sor(a);
   int cur = 0, ans = 0;
   ll id = 1;
   for(int i = 0; i < n; i++){
      cur = int((id * a[i] + cur) % MOD);
      id = (id * 2) % MOD;
      add(ans, int((ll(a[i]) * a[i]) % MOD));
   }
   // dbg(cur);
   for(int i = 0; i < n; i++){
      res(cur, a[i]);
      cur = int((499122177LL * cur) % MOD);
      add(ans, int((ll(a[i]) * cur) % MOD));
   }
   cout << ans << "\n";
}
int main(){
   cpu();
   solve();

   return 0;
}


#include<bits/stdc++.h>
#include <iterator>
#include <iostream>
#include <numeric>
#include <math.h>
#define ll long long
#define ull long
#define mpa make_pair
#define pb push_back
#define ff first
#define pii pair<ll,ll>
#define dd double
#define trace(x) cerr << #x << " : " << x << endl
#define ss second
#define boost ios_base::sync_with_stdio(0)
#define forp(i,a,b) for(ll i=a;i<=b;i++)
#define rep(i,n)    for(ll i=0;i<n;++i)
#define ren(i,n)    for(ll i=n-1;i>=0;i--)
#define forn(i,a,b) for(ll i=a;i>=b;i--)
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end();
#define sc(x) scanf("%lld",&x)
#define clr(x,val) memset(x,val,sizeof(x))
#define pr(x) printf("%lld\n",x)
#define gc getchar
#define pdd pair<dd,dd>
#define read_arr(a,n) for(ll i=1;i<=n;i++)cin>>a[i];
#define init_arr(a,n) for(ll i=1;i<=n;i++)a[i]=n-i+1;
#define prec(x) cout<<fixed<<setprecision(x)
#define fre freopen("input.txt","r",stdin),freopen("output.txt","w",stdout)
#define arr array
using namespace std;

int main(){

	ll n;
	cin>>n;
	cout<<max(0ll,n)<<endl;

}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pll = pair<ll, ll>;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, m, n) for(ll i = m; i > n; i--)
#define Rep(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define lmax(x, y) max<ll>(x, y)
#define lmin(x, y) min<ll>(x, y)
#define tmax(x, y, z) lmax((x), lmax((y), (z)))
#define tmin(x, y, z) lmin((x), lmin((y), (z)))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define ZERO(a) memset(a, 0, sizeof(a))
const ll INF = 1LL << 60;
const ll MM = 1000000000; const ll MOD = MM + 7; const ll MMM=9223372036854775807;//2^63 -1
#define ADD(a,b) a = (a + ll(b)) % MOD
#define MUL(a,b) a = (a * ll(b)) % MOD
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
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;}
template<typename A, size_t N, typename T> void FILL(A (&array)[N], const T &val){ fill( (T*)array, (T*)(array+N), val );}
// struct edge{ ll from, to, cost; };
// struct edge{ ll to, cost; };
// using Graph = vector<vector<ll>>;  // 重み無し
// using Graph = vector<edge>;  // 辺
// using Graph = vector<vector<edge>>;  // 重み付き
ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

ll table[1010];

map<ll, ll> prime_factor(ll n){
    map<ll, ll> res;
    for(ll i=2; i*i<=n; i++){
        while(n%i == 0){
            ++res[i];
            n /= i;
        }
    }
    if(n != 1) res[n] = 1;
    return res;
}

int main(){
    FILL(table, 0);
    ll n; cin >> n;
    rep(i, n){
        ll a; cin >> a;
        auto mp = prime_factor(a);
        for(auto p: mp){
            table[p.first] += 1;
        }
    }
    ll res, ans = -1;
    rep(i, 1002){
        if(chmax(ans, table[i])) res = i;
    }
    cout << res << endl;
}


#include<bits/stdc++.h>
using namespace std;
using P=pair<int,int>;
using ll=long long;
template<class T> using heapq = priority_queue<T,vector<T>,greater<T>>;
template<class T> bool chmax(T &a,const T b) {if (a<b) {a=b;return true;} else return false;}
template<class T> bool chmin(T &a,const T b) {if (a>b) {a=b;return true;} else return false;}
#define rep(i,n) for(int i=0; i<(n); i++)
#define srep(i,a,b) for(int i=(a); i<(b); i++)
#define rrep(i,n) for(int i=(n)-1;i>=0; i--)
#define srrep(i,a,b) for(int i=(b)-1; i>=(a); i--)
int main(){
  string s; cin >> s;
  for(char &c:s){
  	if (c=='6') c='9';
    else if (c=='9') c='6';
  }
  reverse(s.begin(),s.end());
  cout << s << endl;
}

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

int main()
{
	string str,s;
	cin>>str;
	for(int i=str.size()-1;i>=0;i--)
	{
		if(str[i]=='0')	cout<<"0";
		if(str[i]=='6')	cout<<"9";
		if(str[i]=='8')	cout<<"8";
		if(str[i]=='9')	cout<<"6";
		if(str[i]=='1')	cout<<"1";
	}
	return 0;
}


#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;i++)
#define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;i--)
inline int read() {
	int x=0,f=1;char c=getchar();
	while(c<48||c>57){if(c=='-')f=-1;c=getchar();}
	while(c>=48&&c<=57)x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
using namespace std;
typedef long long ll;
const int M=1000;
ll C[M][M];
void solve() {
	int A=read(),B=read();long long k;scanf("%lld",&k);
	rep(i,0,M-1){
		C[i][0]=1;
		rep(j,1,i)C[i][j]=C[i-1][j]+C[i-1][j-1];
	}
	int a=A,b=B;
	rep(i,1,A+B){
		if(a==0){
			putchar('b');
			continue;
		}
		if(b==0){
			putchar('a');
			continue;
		}
		ll cnt=C[a+b-1][a-1];
		if(cnt>=k)putchar('a'),a--;
		else k-=cnt,putchar('b'),b--;
	}
}
int main() {
	int T=1;
	while(T--)solve();
	return 0;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> a(M), b(M), c(N);
  rep(i, M) {
    cin >> a[i] >> b[i];
    a[i]--, b[i]--;
  }
  for (int &x: c) cin >> x;

  vector<vector<int>> e(N);
  rep(i, M) {
    if (c[a[i]] >= c[b[i]]) e[a[i]].emplace_back(i);
    if (c[a[i]] <= c[b[i]]) e[b[i]].emplace_back(i);
  }
  vector<string> ans(M);
  function<void(int)> dfs = [&](int x) {
    for (int i: e[x]) if (ans[i] == "") {
      bool d = a[i] == x;
      ans[i] = d ? "->" : "<-";
      dfs(d ? b[i] : a[i]);
    }
  };
  rep(i, N) dfs(i);
  for (string x: ans) cout << x << endl;
}


/**
 *    author:  otera
**/
#include<bits/stdc++.h>
using namespace std;

#define int long long
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60;
#define rep(i, n) for(int i = 0; i < n; ++ i)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
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; }

void solve() {
    int n, m; cin >> n >> m;
    vector<int> c(n);
    vector<vector<int>> g(n, vector<int>());
    vector<int> a(m), b(m);
    vector<int> ans(m, -1);
    map<P, P> mp;
    rep(i, m) {
        cin >> a[i] >> b[i]; -- a[i], -- b[i];
        g[a[i]].push_back(b[i]);
        g[b[i]].push_back(a[i]);
        mp[{a[i], b[i]}] = {i, 1}, mp[{b[i], a[i]}] = {i, 0};
    }
    rep(i, n) {
        cin >> c[i];
    }
    vector<bool> used(m, 0);
    rep(i, m) {
        if(c[a[i]] < c[b[i]]) {
            // <-
            ans[i] = 0;
            used[i] = 1;
        } else if(c[a[i]] > c[b[i]]) {
            // ->
            ans[i] = 1;
            used[i] = 1;
        }
    }
    auto rec = [&](auto && self, int p, int v) -> void {
        for(int nv: g[v]) {
            if(nv == p) continue;
            if(c[v] == c[nv]) {
                // v -> nv
                if(mp.count({v, nv})) {
                    P p = mp[{v, nv}];
                    int i = p.fr, val = p.sc;
                    if(used[i]) continue;
                    used[i] = 1;
                    ans[i] = val;
                    self(self, v, nv);
                }
            }
        }
    };
    rep(i, m) {
        if(!used[i]) {
            assert(c[a[i]] == c[b[i]]);
            used[i] = 1;
            ans[i] = 1;
            rec(rec, a[i], b[i]);
        }
    }
    rep(i, m) {
        assert(ans[i] != -1);
        if(ans[i] == 1) cout << "->" << "\n";
        else cout << "<-" << "\n";
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(20);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

//#pragma GCC optimize("Ofast", "unroll-loops")
//#pragma GCC target("sse", "sse2", "sse3", "ssse3", "sse4", "avx")

#ifdef __APPLE__
# include <iostream>
# include <cmath>
# include <algorithm>
# include <stdio.h>
# include <cstdint>
# include <cstring>
# include <string>
# include <cstdlib>
# include <vector>
# include <bitset>
# include <map>
# include <queue>
# include <ctime>
# include <stack>
# include <set>
# include <list>
# include <random>
# include <deque>
# include <functional>
# include <iomanip>
# include <sstream>
# include <fstream>
# include <complex>
# include <numeric>
# include <immintrin.h>
# include <cassert>
# include <array>
# include <tuple>
# include <unordered_map>
# include <unordered_set>
# include <thread>
#else
# include <bits/stdc++.h>
#endif

#define F first
#define S second
#define MP make_pair
#define PB push_back

#define all(a) a.begin(),a.end()
#define len(a) (int)(a.size())
#define mp make_pair
#define pb push_back
#define fir first
#define sec second

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;

const int max_n = 100+10, inf = 1000111222;

vector<int> reb[max_n];
int c[max_n];
bool use[max_n];

bool ans[max_n][max_n];

void dfs(int now)
{
    use[now]=1;
    for (auto wh:reb[now]){
        if (c[now]==c[wh]){
            if (!ans[now][wh] && !ans[wh][now]){
                ans[now][wh]=1;
            }
            if (!use[wh]){
                dfs(wh);
            }
        }
    }
}

int main() {
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    int n,m;
    cin>>n>>m;
    vector<pii> edges;
    for (int i=1;i<=m;i++){
        int a,b;
        cin>>a>>b;
        reb[a].pb(b);
        reb[b].pb(a);
        edges.pb(mp(a,b));
    }
    for (int i=1;i<=n;i++){
        cin>>c[i];
    }
    for (auto& i:edges){
        if (c[i.fir]>c[i.sec]){
            ans[i.fir][i.sec]=1;
        }
        swap(i.fir,i.sec);
        if (c[i.fir]>c[i.sec]){
            ans[i.fir][i.sec]=1;
        }
        swap(i.fir,i.sec);
    }
    for (int i=1;i<=n;i++){
        if (!use[i]){
            dfs(i);
        }
    }
    for (auto i:edges){
        if (ans[i.fir][i.sec]){
            cout<<"->"<<"\n";
        }
        else{
            cout<<"<-"<<"\n";
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define deb(...)
#endif
#define int long long int
void solve() {

    int n;
    cin >> n;
    vector<int>v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    vector<int>pref(n);
    int sum = 0;
    for (int i = 0; i < n; i++) {
        sum += v[i];
        pref[i] = sum;
    }
    vector<int>pref1(n);
    sum = 0;
    for (int i = 0; i < n; i++) {
        if (i == 0) {
            pref1[i] = sum;
            sum += v[i];
            continue;
        }
        pref1[i] = pref1[i - 1] + sum;
        sum += v[i];
    }
    vector<int>ans(n);
    int maxi = 0;
    for (int i = 0; i < n; i++) {
        maxi = max(maxi, v[i]);
        ans[i] = pref[i] + pref1[i] + (i + 1) * maxi;
    }
    for (auto it : ans) {
        cout << it << endl;
    }

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

#pragma GCC optimize ("trapv")
#include <bits/stdc++.h>
#include<algorithm>
#include <vector>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string.h>
using namespace std;
#define pb push_back
#define all(v) v. begin(),v. end()
#define  rep(i,n,v) for(i=n;i<v;i++)
#define per(i,n,v) for(i=n;i>v;i--)
#define ff first
#define ss second
#define pp pair<ll,ll>
#define ll  long long
#define endl '\n'
vector<vector<ll>>v;
void dfs(vector<vector<ll>>&a, ll i,ll j, ll n)
{
  if(v[i][j]==0 && a[i][j]==1)
  {
    v[i][j]=3;
    if(i+1<n) dfs(a, i+1,j,n);
    if(i+1<n && j+1<n) dfs(a, i+1,j+1,n);
    if(i+1<n && j-1>=0) dfs(a, i+1,j-1,n);
  }
}
void solve()
{
  ll n,m=INT_MIN,b=0, c=0,k=0, i, j, l=1e9+7;
  string s, r, y;
  ll hit=0;
  cin>>n;
  ll ar[n];
  vector<ll>vec;
  rep(i, 0,n) cin>>ar[i];
  vec.pb(0);
  rep(i, 0,n)
  {
    vec.pb(ar[i]+vec[i]);
  }
  //rep(i, 0,vec.size()) cout<<vec[i]<<" ";
  rep(i,0,n)
  {
    m=max(m,ar[i]);
    k+=vec[i+1];
    cout<<m*(i+1)+k<<endl;
  }
}
int main()
{
  ll i, j, b=0, c=1,yog=0,hit=1;
 ios_base::sync_with_stdio(false);
  cin. tie(0);cout. tie(0);
    ll t=1;
//cin>>t;
    while(t--)
    {
      solve();
    }
    return 0;
}


#include <bits/stdc++.h>
#define lowbit(x) ((x)&(-(x)))
#define mkp make_pair
#define pb push_back

using namespace std;

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

int main()
{
	int n,s,d;
	scanf("%d%d%d",&n,&s,&d);
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		if(x<s && y>d) ans|=1;
	}
	puts(ans==1 ? "Yes" : "No");

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, start, n) for (ll i = (ll)(start); i < (ll)(n); ++i)
static const ll INFTY = 1L << 62L;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, s, d;
    cin >> n >> s >> d;
    ll x[n], y[n];
    rep(i, 0, n)
    {
        cin >> x[i] >> y[i];
    }
    rep(i, 0, n)
    {
        if (x[i] < s && y[i] > d)
        {
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
}


#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <functional>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <bitset>
#include <math.h>
#include <random>
#include <chrono>
using namespace std ;
using ll = long long ;
using ld = long double ;
template<class T> using V = vector<T> ;
template<class T> using VV = V<V<T>> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
ll mod = 1000000007 ;
long double pie = acos(-1) ;
ll INF = 1000000000000 ;

void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
void fix_cout(){cout << fixed << setprecision(20) ;}
template<class T> void chmax(T &a,T &b){if(a<b) a = b ;}
template<class T> void chmin(T &a,T &b){if(a>b) a = b ;}

int main(){
    int n ;
    string s ;
    cin >> n >> s ;
    s = "###"+s+"###" ;
    string t = "fox" ;
    string cur = "###" ;
    if(n<3){
        cout << n << endl ;
        return 0 ;
    }
    set<int> st ;
    for(int i=0;i<s.size();i++) st.insert(i) ;
    int ans = 0 ;
    int p1=-1,p2=-1,p3=-1 ;
    p1 = 3 ;
    p2 = 4 ;
    p3 = 5 ;
    while(p3<n+3){
        cur[0] = s[p1] ;
        cur[1] = s[p2] ;
        cur[2] = s[p3] ;
        if(cur==t){
            ans++ ;
            st.erase(p1) ;
            st.erase(p2) ;
            st.erase(p3) ;
            auto itr = st.lower_bound(p1) ;
            itr-- ;
            p3 = *itr ;
            itr-- ;
            p2 = *itr ;
            itr-- ;
            p1 = *itr ;
        }else{
            auto itr = st.upper_bound(p3) ;
            p3 = *itr ;
            itr-- ;
            p2 = *itr ;
            itr-- ;
            p1 = *itr ;
        }
    }
    cout << n-ans*3 << endl ;
}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	int t; cin >> t;
	rep(i,t){
		int n; cin >> n;
		map<int,int> mp;
		rep(i,n){
			int a; cin >> a;
			mp[a] ^= 1;
		}
		bool even = true;
		for(auto [a,v]: mp) if(v) even = false;
		puts(n&1 || even ? "Second" : "First");
	}
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vc = vector<T>;
template<class T> using vvc = vc<vc<T>>;
template<class T> using vvvc = vc<vvc<T>>;
template<class T> using vvvvc = vvc<vvc<T>>;
template<class T> using PQ = priority_queue<T>;
template<class T> using invPQ = priority_queue<T, vector<T>, greater<T>>;
using IP = pair<int, int>;
using LP = pair<ll, ll>;
#define all(x) begin(x), end(x)
#define rep(i, n) for (int i = 0; (i) < (int)(n); i++)
#define rep3(i, m, n) for (int i = (m); (i) < (int)(n); i++)
#define repr(i, n) for (int i = (n) - 1; (i) >= 0; i--)
#define rep3r(i, m, n) for (int i = (n) - 1; (i) >= (int)(m); i--)
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; }

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

    ll K, N, M;
    cin >> K >> N >> M;
    vc<ll> A(K);
    rep (i, K) cin >> A[i];

    vc<tuple<long double, ll, ll>> cond;
    int cnt = 0;
    rep (i, K) {
        int b = M*A[i]/N;
        cnt += b;
        cond.push_back({ (long double)b/M - (long double)A[i]/N, i, M*A[i]/N });
    }
    sort(cond.begin(), cond.end());
    rep (i, K) {
        if (cnt >= M) break;
        get<2>(cond[i])++;
        get<0>(cond[i]) = (long double)get<2>(cond[i])/M;
        cnt++;
    }

    vc<int> B(K);
    rep (i, K) {
        B[get<1>(cond[i])] = get<2>(cond[i]);
    }
    rep (i, K) {
        if (i != 0) cout << " ";
        cout << B[i];
    }
    cout << endl;

}

#include <bits/stdc++.h>
// #define x first
// #define y second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
const int N = 1e5 + 20;

int n, m, k;
LL a[N], b[N], c[N], mi[N], mx[N];

bool check(LL mid)
{
	for(int i = 1; i <= k; ++ i)
	{
		mx[i] = min((a[i] + mid) / n, (LL)m) + mx[i - 1];
		mi[i] = max(0ll, (a[i] - mid + n - 1) / n) + mi[i - 1];
	}
	return mi[k] <= m && mx[k] >= m;
}

int main()
{
	IOS; cin >> k >> n >> m;
	for(int i = 1; i <= k; ++ i) cin >> a[i], a[i] *= m;

	LL l = 0, r = 1e18;
	while(l <= r)
	{
		LL mid = l + r >> 1;
		if(check(mid))
		{
			memcpy(b, mx, sizeof b), memcpy(c, mi, sizeof c);
			r = mid - 1;
		}
		else l = mid + 1;
	}
	for(int i = k; i >= 1; -- i)
	{
		a[i] = min(m - c[i - 1], b[i] - b[i - 1]);
		m -= a[i];
	}
	for(int i = 1; i <= k; ++ i) cout << a[i] << " ";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m,cnt;
struct Obstacle {
	int x,y;
	bool operator<(const Obstacle rhs) const {
		if(x==rhs.x) {
			return y<rhs.y;
		}
		return x<rhs.x;
	}
}a[200005];
int lenn[200005];//Maximum x you can go with y=i
int lenm[200005];//Maximum y you can go with x=i
int tr[200005];
bool vis[200005];
ll ans;

int lowbit(int x) {
	return x&-x;
}

void add(int pos,int num) {
	for(int i=pos;i<=m;i+=lowbit(i)) {
		tr[i]+=num;
	}
}

int sum(int pos) {
	int res=0;
	for(int i=pos;i>=1;i-=lowbit(i)) {
		res+=tr[i];
	}
	return res;
}

vector<int> ob[200005];

int main() {
	scanf("%d %d %d",&n,&m,&cnt);
	for(int i=1;i<=n;i++) {
		lenm[i]=m;
	}
	for(int i=1;i<=m;i++) {
		lenn[i]=n;
	}
	for(int i=1;i<=cnt;i++) {
		scanf("%d %d",&a[i].x,&a[i].y);
		ob[a[i].x].push_back(a[i].y);
		lenm[a[i].x]=min(lenm[a[i].x],a[i].y-1);
		lenn[a[i].y]=min(lenn[a[i].y],a[i].x-1);
	}
	for(int i=1;i<=lenm[1];i++) {
		ans+=lenn[i];
	}
	for(int i=lenm[1]+1;i<=m;i++) {
		vis[i]=1;
		add(i,1);
	}
	for(int i=2;i<=lenn[1];i++) {
		ans+=sum(lenm[i]);
		for(int j=0;j<ob[i].size();j++) {
			if(!vis[ob[i][j]]) {
				vis[ob[i][j]]=1;
				add(ob[i][j],1);
			}
		}
	}
	printf("%lld",ans);
	return 0;
}


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

typedef pair<int,int>  pint;
typedef pair<ll,ll>    pll;
typedef vector<int>    vint;
typedef vector<ll>     vll;
typedef vector<string> vstr;
typedef vector<pint>   vpint;
typedef vector<pll>    vpll;

#define vint2(v,n,m,init) vector<vector<int>> v(n, vector<int>(m, init))
#define vll2(v,n,m,init)  vector<vector<ll>>  v(n, vector<ll>(m, init))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vint var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vstr var(n); rep(i,n){cin >> var[i];}
#define ALL(var)         (var).begin(), (var).end()
#define sortall(var)     sort(ALL(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());

#define prt(var)         cout << (var) << "\n"
#define prt2(v1, v2)     cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << (var);
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
template <typename T>
bool chmax(T &a, const T& b){if(a<b){a=b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a>b){a=b; return true;} return false;}
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;}
//----------------------------------------------------------------------------

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

    prt(n-a+b);
}

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

int main() {

    // cinを高速にするためのおまじない
    cin.tie(0);
    ios::sync_with_stdio(false);
    /////////////////////
    // Write code below
    long long int N,A,B,ans;
    cin >> N >> A >> B;
    ans = N - A + B;
    cout << ans << endl;
    /////////////////////
    return 0;
}


//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")

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

#define ll long long
#define ld long double
#define mod 1000000007
#define pb push_back
#define inf 1000000000000000000
#define ff first
#define ss second
#define deb(x) cout<<#x<<" "<<x<<"\n"
#define Clear(x) memset(x,0,sizeof(x))
#define all(x) (x).begin(),(x).end()

void checkpoint1()
{
	/******think more code less******/
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		freopen("Error.txt", "w", stderr);
	#endif
}

bool comp(pair< ll,ll > &a,pair< ll,ll > &b)
{
	if(a.ff!=b.ff)
		return a.ff<b.ff;
	else
	{
		if(a.ss>b.ss)
			return b.ss<a.ss;
		else if(a.ss<b.ss)
			return a.ss<b.ss;
	}
	return a.ff>b.ff;
}

ll powe(ll a,ll b)
{
	ll res=1;
	while(b>0)
	{
		if(b&1)
		{
			res*=a;
			res%=mod;
		}
		a*=a;
		a%=mod;
		b>>=1;
	}
	return res;
}
void upd(ll st[],ll v,ll stl,ll str,ll pos,ll val)
{
	if(stl==str)
		st[v]=1;
	else
	{
		ll stm=(stl+str)/2;
		if(pos<=stm)
			upd(st,2*v,stl,stm,pos,val);
		else
			upd(st,2*v+1,stm+1,str,pos,val);
		st[v]=st[2*v]+st[2*v+1];
	}
}
ll ans(ll st[],ll v,ll stl,ll str,ll l,ll r)
{
	if(l>r)
		return 0LL;
	if(stl==l && r==str)
		return st[v];
	else
	{
		ll stm=(stl+str)/2;
		return ans(st,2*v,stl,stm,l,min(r,stm))+ans(st,2*v+1,stm+1,str,max(stm+1,l),r);
	}
}
void terminAtor()
{
	ll n;
	cin>>n;
	ll a[n+1];
	for(ll i=1;i<=n;i++)
		cin>>a[i];
	ll st[4*(n+1)];
	for(ll i=0;i<4*n+1;i++)
		st[i]=0;
	ll tot=0,temp=0;
	vector< ll > pos;
	for(ll i=1;i<=n;i++)
	{
		tot+=(ans(st,1,1,n,a[i]+1,n));
		if(temp!=tot)
		{
			temp=tot;
			pos.pb(i);
		}
		upd(st,1,1,n,a[i],1);
	}
	if(tot!=n-1){
		cout<<-1;
		return;
	}
	ll k=0;
	for(ll i=0;i<pos.size();i++)
	{
		ll tt=pos[i]-1;
		pos[i]--;
		while(pos[i]>k)
		{
			cout<<pos[i]<<"\n";
			pos[i]--;
		}
		k=tt;
	}

}

int main()
{
	checkpoint1();
/********************************************************/
	auto startrrr = high_resolution_clock::now();
	cout << setprecision(20);
/*******************************************************/

	terminAtor();

/*******************************************************/
	auto stoprrr = high_resolution_clock::now();
	auto duration = duration_cast<microseconds>(stoprrr - startrrr);
	#ifndef ONLINE_JUDGE
		cerr << "Time: " << duration.count()/1000.0<<"\n";
	#endif
/*******************************************************/
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int a[2000005], b[2000005],c[2000005];
int main()
{
    int n;
    cin >> n;
    for(int i=1;i<=n;i++) {
        cin >> a[i];
        b[a[i]]=i;
        c[i] = a[i];
    }

    unordered_map<int,int> mp;
    vector<int>v;
    for(int i=1;i<=n;i++)
    {
        for(int j = b[i]-1;j>=i;j--)
        {
            if(mp[j]==0){
            b[a[j]]++;
            a[j+1]= a[j];
            v.push_back(j);
            mp[j]=1;
            }

            else
            {
                cout << -1 << endl;
                return 0;
            }
        }
        b[i]=i;
        a[i]=i;

    }

    if(mp.size()==n-1)
    {
        for(auto it: v) cout << it << " ";
        cout << endl;
    }
    else cout << -1 << endl;
}


#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

ll dp[202][15];

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

  int L;
  cin>>L;

  dp[0][0]=1;
  for(int i=0;i<L;i++){
    for(int j=0;j<=11;j++){
        dp[i+1][j]+=dp[i][j];
        if(j+1<=11){
          if(j+1==11&&i+1==L) continue;
          dp[i+1][j+1]+=dp[i][j];
        }
    }
  }

  cout<<dp[L][11]<<endl;

  return 0;
}

#include <bits/stdc++.h>

#define endl "\n"
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;

constexpr int N = 1e5 + 5;
constexpr int mod = 1e9 + 7;
constexpr int LOG = 18;

template<typename T> void dout(const T& x) { cout << x << ' '; } // change separator!
template<typename T, typename ...Ts> void dout(const T& v, const Ts&... args) { dout(v); dout(args...); }
template<typename ...Ts> void vout(const Ts&... args) { dout(args...); cout << endl; exit(0); }

bitset<N> dp;
int n, v, s = 0;

void solve() {
  cin >> n;
  dp[0] = 1;
  while(n--) {
    cin >> v;
    s += v;
    dp |= (dp << v);
  }
  int ans = N;
  for (int i = 0; i <= s; i++)
    if (dp[i])
    ans = min(ans, max(i, s - i));
  cout << ans << endl;
}

int main() {
  //freopen("zhopa.txt", "r", stdin);
  //freopen("logins.txt", "w", stdout);
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  // int tests;
  // cin >> tests;
  // while(tests--)
  // auto start = chrono::high_resolution_clock::now();
    solve();
  // auto end = chrono::high_resolution_clock::now();
  // cout << endl << (chrono::duration_cast<chrono::duration<double>>(end - start)).count();
  return 0;
}


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

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef pair<int, int> pii;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;

#define FOR(i, a, b) for (int i = a; i <= (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b); i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto &a : x)

#define sz(x) (int)(x).size()
#define popcnt(x) __builtin_popcount(x)
#define low_bo(a, x) (lower_bound(a.begin(), a.end(), x) - a.begin())
#define up_bo(a, x) (upper_bound(a.begin(), a.end(), x) - a.begin())
#define unique(a) a.resize(unique(a.begin(), a.end()) - a.begin())
#define shuffle(a) shuffle(a.begin(), a.end(), rnd)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

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

const int MOD = 1000000007;
const char nl = '\n';
const int MX = 150001; //check the limits, dummy
set<pii> visited;
void solve(int t) {
  int n, m;
  cin>>n >> m;
  map<int, map<int, char>> adj;
  F0R(i,m) {
    int u,v;
    char c;
    cin>>u>>v>>c;
    u--, v--;
    adj[u][v]=c;
    adj[v][u]=c;
  }
  // negative length of string
  priority_queue<pair<ll, pii>> pq;
  pq.push(mp(0,mp(0,n-1)));
  int u,v;
  set<int> pos;
  while(!pq.empty()) {
    auto cur = pq.top();
    pq.pop();
    ll l = -cur.f;
    tie(u,v) = cur.s;
    // cout << l <<" "<<st<<" "<<u<<" "<<v<<nl;
    if(visited.find({u,v})!=visited.end()) {
      // cout << "hi\n";
      continue;
    }
    visited.ins({u,v});
    if(u==v) {
      pos.ins(2*l);
      // cout << 2*l<<nl;
      // return;
    }
    if(adj[u].find(v)!=adj[u].end()) {
      pos.ins(2*l+1);
      // cout << 2*l+1<<nl;
      // return;
    }
    for(auto au : adj[u]) {
      for(auto av : adj[v]) {
        if(au.s==av.s) {
          pq.push(mp(-l-1,mp(au.f,av.f)));
        }
      }
    }
  }
  if(!pos.empty()) cout << *(pos.begin())<<nl;
  else
  cout << "-1\n";
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout.precision(20);
  cout << fixed;

  int T = 1;
  F0R(i,T) {
    solve(i+1);
  }
}

// read the question correctly (ll vs int)
// template by bqi343

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++(i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++(i))
#define REP_R(i, n) for (int i = (int)(n)-1; (i) >= 0; --(i))
#define REP3R(i, m, n) for (int i = (int)(n)-1; (i) >= (int)(m); --(i))
#define ALL(x) ::std::begin(x), ::std::end(x)
using namespace std;

template <typename T>
void print_vector(T& vec) {
    stringstream ss;
    ss << "{";
    for (auto v : vec) ss << v << " ";
    ss << "}" << endl;
    cout << ss.str() << endl;
}

template <typename T>
void print_pairs(T& vec) {
    stringstream ss;
    ss << "{";
    for (auto v : vec) ss << v.first << "," << v.second << " ";
    ss << "}" << endl;
    cout << ss.str() << endl;
}

template <typename T>
string string_vector(vector<T>& vec) {
    stringstream ss;
    ss << "{";
    for (auto v : vec) ss << v << " ";
    ss << "}\n";
    return ss.str();
}

template <typename T>
string string_vector(vector<vector<T>>& vec) {
    stringstream ss;
    ss << "{";
    for (auto v : vec) {
        ss << "{";
        for (auto vv : v) ss << vv << " ";
        ss << "}";
    }
    ss << "}\n";
    return ss.str();
}

using ll = long long;
class Solution {
   public:
    vector<int> dp;
    vector<int> dp2;
    vector<int> bad;

    bool is_good(int s, int N, int M, const vector<int>& A, const vector<int>& B) {
        for(int i = 0; i < N; ++i) {
            if(!(s & (1<<i))) continue;
            if(s & bad[i]) return false;
        }
        return true;
    }

    ll fix(int s, int N, int M, const vector<int>& A, const vector<int>& B) {
        if(s == 0) return 0;
        if(dp[s]) return dp[s]-1;

        //if(!is_good(s, N, M, A, B)) return N;

        ll min_cc = N;
        int b = 0;
        do {
            //res = fix(s & ~b, N, M, A, B);
            //if(b!=0 and is_good(s,N,M,A,B)) min_cc = min(min_cc, 1 + fix(s & ~b, N, M, A, B));
            bool good = false;
            if(!dp2[b]) dp2[b] = is_good(b, N, M, A, B) + 1;
            if(b!= 0 and dp2[b] - 1) {
                 min_cc = min(min_cc, 1 + fix(s & ~b, N, M, A, B));
            }

        } while((b = (b - s) & s));
        dp[s] = min_cc + 1;
        return min_cc;
    }

    ll solve(int N, int M, const vector<int>& A, const vector<int>& B) {
        dp.resize(1<<N);
        dp2.resize(1<<N);
        bad.resize(N, (1<<N) - 1);
        for(int i = 0; i < M; ++i) {
            bad[A[i]] ^= (1<<B[i]);
            bad[B[i]] ^= (1<<A[i]);
        }

        for(int i = 0; i < N; ++i) {
            bad[i] = bad[i] & ( ((1<<N) - 1) - ((1<<i)));
        }

        int min_cc = fix((1<<N) - 1, N, M, A, B);
        return min_cc;
    }
};

// generated by online-judge-template-generator v4.7.1 (https://github.com/online-judge-tools/template-generator)
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    Solution sol;
    int N, M;
    cin >> N >> M;
    vector<int> A(M), B(M);
    REP (i, M) { cin >> A[i] >> B[i];
        A[i]--, B[i]--;}
    auto ans = sol.solve(N, M, A, B);
    cout << ans << endl;
    return 0;
}


#include <iomanip>
#include <iostream>
#include <unordered_map>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
unordered_map<int64_t, double> memo;

double dfs(int a, int b, int c) {
  if (a == 100 || b == 100 || c == 100) {
    return 0.0;
  }
  int64_t key = 10000 * a + 100 * b + c;
  if (memo.count(key)) return memo[key];

  double ret = 0.0;
  if (a < 100) {
    ret += (dfs(a + 1, b, c) + 1) * (double)a / (double)(a + b + c);
  }
  if (b < 100) {
    ret += (dfs(a, b + 1, c) + 1) * (double)b / (double)(a + b + c);
  }
  if (c < 100) {
    ret += (dfs(a, b, c + 1) + 1) * (double)c / (double)(a + b + c);
  }
  return memo[key] = ret;
}

int main(void) {
  ios::sync_with_stdio(false);
  int A, B, C;
  cin >> A >> B >> C;
  double answer = dfs(A, B, C);
  cout << setprecision(20) << answer << endl;
  return 0;
}

#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define all(v) v.begin(),v.end()
#pragma gcc optimize("O3")
#pragma gcc optimize("Ofast")
#pragma gcc optimize("unroll-loops")
using namespace std;
const int INF = 1e9;
const int TMX = 1 << 18;
const long long llINF = 1e16;
const long long mod = 998244353;
const long long hashmod = 100003;
const int MAXN = 100000;
const int MAXM = 1000000;
typedef long long ll;
typedef long double ld;
typedef pair <int,int> pi;
typedef pair <ll,ll> pl;
typedef vector <int> vec;
typedef vector <pi> vecpi;
typedef long long ll;

ll mpow(ll x,ll M) {
	if(!M) return 1;
	ll tmp = mpow(x,M/2);
	tmp = tmp*tmp%mod;
	if(M % 2) return tmp*x%mod;
	return tmp;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n,m,k;
	cin >> n >> m >> k;
	ll ans = 0;
	if(n > m) swap(n,m);
	if(n == 1) {
		for(int X = 1;X <= k;X++) {
			ans += (mpow(X,m)-mpow(X-1,m)+mod)%mod;
			ans %= mod;
		}
		cout << ans;
		return 0;
	}
	for(int X = 1;X <= k;X++) {
		ans += ((mpow(X,n)-mpow(X-1,n)+mod)%mod)*mpow(k-X+1,m)%mod;
		ans %= mod;
	}
	cout << ans;
}


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

int main(){
  double R, X, Y;
  cin >> R >> X >> Y;
  double distance = sqrt(X*X+Y*Y);
  int count = ceil(distance / R);
  if(count == 1 && distance != R) count++;
  cout << count << endl;
}

//khodaya khodet komak kon
# include <bits/stdc++.h>

/*
// ordered_set
# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
# define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
*/

using namespace std;

typedef long long                                        ll;
typedef long double                                      ld;
typedef pair <int, int>                                  pii;
typedef pair <pii, int>                                  ppi;
typedef pair <int, pii>                                  pip;
typedef pair <pii, pii>                                  ppp;
typedef pair <ll, ll>                                    pll;

# define A                                               first
# define B                                               second
# define endl                                            '\n'
# define sep                                             ' '
# define all(x)                                          x.begin(), x.end()
# define kill(x)                                         return cout << x << endl, 0
# define SZ(x)                                           int(x.size())
# define InTheNameOfGod                                  ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);

ll power(ll a, ll b, ll md) {return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md));}

const int xn = 5e5 + 10;
const int xm = - 20 + 10;
const int sq = 320;
const int inf = 1e9 + 10;
const ll INF = 1e18 + 10;
const int mod = 998244353;
const int base = 257;

ll n, ans, res;
string s, t;

int main(){
	InTheNameOfGod;

	cin >> n >> s >> t;
	s = '.' + s, t = '.' + t;
	for (int i = 1; i <= n; ++ i){
		ans += res;
		if (s[i] == t[i])
			continue;
		if (s[i] == '0' || !res)
			++ res;
		else
			-- res;
	}
	if (res)
		kill(- 1);
	kill(ans);

	return 0;
}


#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <cmath>
#include <algorithm>
#include <iomanip>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll MOD = 1000000007;
//cout << std::fixed << std::setprecision(15) << res << endl;
//int di[] = {-1,0,1,0};
//int dj[] = {0,-1,0,1};
//printf("%.10f %.10f\n), ans.real(), ans.imag());

int main(){
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<ll> A(N);
  rep (i, N) cin >> A[i];

  if (N == 1) {
    cout << A[0] << endl;
    return 0;
  } else if (N == 2) {
    cout << 2 * A[0] % MOD << endl;
    return 0;
  }

  vector<ll> X(N+1);
  X[0] = 1;
  X[1] = 1;
  ll psum = 0;
  vector<ll> pow2(N,0);
  pow2[0] = 1;
  for (ll k = 1; k < N; k++) {
    pow2[k] = (2 * pow2[k-1]) % MOD;
    if (k - 2 >= 0) {
      psum *= 2;
      psum %= MOD;
      psum += X[k-2];
      psum %= MOD;
    }
    X[k+1] = pow2[k] - psum;
    if (X[k+1] < 0 ) X[k+1] += MOD;
  }

  ll res = 0;
  res += (A[0] * X[N]);
  res %= MOD;

  res += A[1] * ((X[N] - X[N-2]) - X[N-2]);
  //if (res < 0) res += MOD;
  res %= MOD;

  for (ll k = 2; k < N - 1; k++) {
    ll tmp = (X[N-k-1] * X[k-1]) % MOD;
    res += A[k] * (X[N] - tmp - tmp);
    //if (res < 0) res += MOD;
    res %= MOD;
  }

  res += A[N-1] * ((X[N] - X[N-2]) - X[N-2]);
  res %= MOD;
  if (res < 0) res += MOD;

  cout << res << endl;

  return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323
#define ll long long int
#define vi vector <int>
#define vl vector <ll>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007

const ll mod = 1e9 + 7;

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

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

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 n;
	cin >> n;
	vl v(n);
	for (auto &i : v)
		cin >> i;
	vector <vl> dp(n, vl (2, 0));
	dp[0][0] = 1;
	dp[0][1] = 1;
	for (ll i = 1; i < n; i++) {
		dp[i][0] = (dp[i - 1][0] + dp[i - 1][1]) % mod;
		dp[i][1] = dp[i - 1][0];
	}
	ll ans = 0;
	for (ll i = 0; i < n; i++) {
		ll l, r;
		l = i;
		r = n - i - 1;
		if (l == 0)
			l = 1;
		else if (l == 1)
			l = 1;
		else
			l = (dp[l - 2][0] + dp[l - 2][1]) % mod;
		if (r == 0)
			r = 1;
		else
			r = (dp[r - 1][0] + dp[r - 1][1]) % mod;
		ans = (ans + ((l * r) % mod * v[i]) % mod) % mod;
		if (i == 0)
			continue;
		l = i;
		r = n - i - 1;
		if (l == 1)
			l = 1;
		else
			l = (dp[l - 2][0]) % mod;
		if (r == 0)
			r = 1;
		else
			r = (dp[r - 1][0]) % mod;
		ans = (ans - ((l * r) % mod * v[i]) % mod + mod) % mod;
		//cout << ans << "\n";
	}
	cout << ans;
}


//#pragma GCC optimize(2)
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<cmath>
#include<cctype>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<sstream>
#include<ctime>
#include<cstdlib>
#define X first
#define Y second
#define L (u<<1)
#define R (u<<1|1)
#define pb push_back
#define mk make_pair
#define Mid (tr[u].l+tr[u].r>>1)
#define Len(u) (tr[u].r-tr[u].l+1)
#define random(a,b) ((a)+rand()%((b)-(a)+1))
#define db puts("---")
using namespace std;

//void rd_cre() { freopen("d://dp//data.txt","w",stdout); srand(time(NULL)); }
//void rd_ac() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//AC.txt","w",stdout); }
//void rd_wa() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//WA.txt","w",stdout); }

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;

const int N=1000010,mod=1e9+7,INF=0x3f3f3f3f;
const double eps=1e-6;

int n,m,s,t;
int e[N],ne[N],w[N],k[N],h[N],idx;
LL dis[N];
bool st[N];
struct Node
{
    int u;
    LL d;
    bool operator < (const Node &W) const
    {
        return d>W.d;
    }
};

void add(int a,int b,int c,int d)
{
    e[idx]=b,w[idx]=c,k[idx]=d,ne[idx]=h[a],h[a]=idx++;
}

void dijkstra()
{
    priority_queue<Node>q;
    q.push({s,0});
    memset(dis,INF,sizeof(dis));
    dis[s]=0;
    while(q.size())
    {
        Node cur=q.top(); q.pop();
        int u=cur.u; LL d=cur.d;
        if(st[u]) continue;
        st[u]=true;
        for(int i=h[u];~i;i=ne[i])
        {
            int ver=e[i];
            LL now=d;
            if(d%k[i]!=0&&d!=0) now/=k[i],now++,now=now*k[i];
            if(dis[ver]>now+w[i])
            {
                dis[ver]=now+w[i];
                q.push({ver,dis[ver]});
            }
        }
    }
}

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

    memset(h,-1,sizeof(h)); idx=0;
    scanf("%d%d%d%d",&n,&m,&s,&t);
    for(int i=1;i<=m;i++)
    {
        int a,b,c,d; scanf("%d%d%d%d",&a,&b,&c,&d);
        add(a,b,c,d); add(b,a,c,d);
    }
    dijkstra();
    printf("%lld\n",dis[t]==0x3f3f3f3f3f3f3f3f? -1:dis[t]);

	return 0;
}
/*

*/

#include <bits/stdc++.h>
#define F first
#define S second
#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define bck(i, a, b) if ((i) >= (a) && (i) < (b))
#define trav(x, a) for (auto &x : (a))
#define sz(a) (int)(a).size()
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef string str;
template<typename T> using vec = vector<T>;
template<typename T> using pq = priority_queue<T, vector<T>, std::greater<T>>;
template<typename T> using mxpq = priority_queue<T>;
typedef pair<int,int> pii;
typedef vec<int> vi;
typedef vec<pii> vii;
typedef vec<vi> vvi;
typedef pair<ll,ll> pll;
typedef vec<ll> vl;
typedef vec<pll> vll;
typedef vec<vl> vvl;
template<typename A, typename B>
istream& operator>>(istream& s, pair<A,B>& p) { return s>>p.first>>p.second; }
template<typename T>
istream& operator>>(istream& s, vec<T>& p) {
    for (T& t : p) s >> t;
    return s;
}

ll dijk(vec<vec<pair<int, pll>>> &g, int s, int e) {
    pq<pll> q;
    q.push({0, s});
    vec<bool> v(sz(g));
    while (q.size()) {
        auto [d, i] = q.top(); q.pop();
        if (v[i]) continue;
        v[i] = true;
        if (i == e) return d;
        trav(ch, g[i]) {
            int next_city = ch.F;
            ll k = ch.S.S;
            ll t = ch.S.F;
            if (!v[ch.F]) {
                ll next_train = (d + k-1) / k * k; // ceil(d / k) * k
                q.push({next_train + t, next_city});
            }
        }
    }
    return -1;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n, m, s, e;
    cin >> n >> m >> s >> e;

    vec<vec<pair<int, pll>>> g(n);
    rep(i, 0, m) {
        int a, b, t, k;
        cin >> a >> b >> t >> k;
        g[a-1].pb({b-1, {t, k}});
        g[b-1].pb({a-1, {t, k}});
    }
    cout<<dijk(g, s-1, e-1)<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) (int)(a.size())
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(998244353)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
int main()
{
	int x;
    cin>>x;
  x = max(x,0);
  cout<<x;
}

// Problem : A - ReLU
// Contest : AtCoder - AtCoder Beginner Contest 183
// URL : https://atcoder.jp/contests/abc183/tasks/abc183_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

// Problem : E. Tree Queries
// Contest : Codeforces - Codeforces Round #629 (Div. 3)
// URL : https://codeforces.com/contest/1328/problem/E
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include<bits/stdc++.h>
using namespace std;
#define _rep(i, x, y) for(int i = (int)x; i < (int)y; ++i)
#define _dep(i,x,y) for(int i = (int)x; i > (int)y; i--)
#define PII pair<int,int>
#define eb emplace_back
#define pb push_back
#define fi first
#define se second
#define PQ priority_queue
#define lb lower_bound
#define ub upper_bound
typedef long long ll;
typedef vector<int> VI;
constexpr int mod = 1e9 + 7;
constexpr int KINF = 0x3f3f3f3f;
constexpr double eps = 1e-7;
int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	int x;
	cin >> x;
	if(x >= 0) cout << x << endl;
	else cout << 0 << endl;
	return 0;
}


#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=998244353;
//const ll mod=1000000007;
const vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T>void debag(const vector<T> &a){cerr<<"debag :";for(auto v:a)cerr<<v<<" ";cerr<<"\n";}
template<class T>void print(const vector<T> &a){for(auto v:a)cout<<v<<" ";cout<<"\n";}
struct mint{
using ull=unsigned long long int;
ull v;
mint(ll vv=0){s(vv%mod+mod);}
mint& s(ull vv){
v=vv<mod?vv:vv-mod;
return *this;
}
//オーバーロード
mint operator-()const{return mint()-*this;}//mint型にキャスト
mint&operator+=(const mint&val){return s(v+val.v);}
mint&operator-=(const mint&val){return s(v+mod-val.v);}
mint&operator*=(const mint&val){
v=ull(v)*val.v%mod;
return *this;
}
mint&operator/=(const mint&val){return *this*=val.inv();}
mint operator+(const mint&val){return mint(*this)+=val;}
mint operator-(const mint&val){return mint(*this)-=val;}
mint operator*(const mint&val){return mint(*this)*=val;}
mint operator/(const mint&val){return mint(*this)/=val;}
mint pow(ll n)const{
mint res(1),x(*this);
while(n){
if(n&1)res*=x;
x*=x;
n>>=1ll;
}
return res;
}
mint inv()const{return pow(mod-2);}
//拡張ユークリッドの互除法
/* mint inv()const{
int x,y;
int g=extgcd(v,mod,x,y);
assert(g==1);
if(x<0)x+=mod;
return mint(x);
}*/
friend ostream& operator<<(ostream&os,const mint&val){
return os<<val.v;
}//出力
bool operator<(const mint&val)const{return v<val.v;}
bool operator==(const mint&val)const{return v==val.v;}
bool operator>(const mint&val)const{return v>val.v;}
};
const ll MAX = 2000010;//設定
mint fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void init(){
fac[0] = fac[1] = 1;
for(int i=1;i<MAX;i++)fac[i]=fac[i-1]*i;
finv[MAX-1]=fac[MAX-1].inv();
for(int i=MAX-2;i>=0;i--)finv[i]=finv[i+1]*(i+1);
for(int i=MAX-2;i>=1;i--)inv[i]=finv[i]+fac[i-1];
}
//階乗
mint factor(ll n,ll k){
if (n<k) return 0;
if (n<0 || k<0) return 0;
return fac[n]*finv[k];
}
// 二項係数計算
mint COM(int n, int k){
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * finv[k] * finv[n - k];
}
class UF{
public:
	vector<int> par,num;
	int find(int v){
		return (par[v]==v)? v: (par[v]=find(par[v]));
	}
	explicit UF(int N):par(N),num(N,1){
		iota(all(par),0);
	}
	void unite(int u,int v){
		u=find(u),v=find(v);
		if(u==v)return;
		if(num[u]<num[v])swap(u,v);
		num[u]+=num[v];
		par[v]=u;
	}
	bool same(int u,int v){
		return find(u)==find(v);
	}
	bool ispar(int v){
		return v=find(v);
	}
	int size(int v){
		return num[find(v)];
	}
};
int main(){
    init();
    int n,K;
    cin>>n>>K;
    V<V<int>> a(n,V<int>(n));
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++)cin>>a[i][j];
    }
    UF l(n);
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            bool ok=true;
            for(int k=0;k<n;k++){
                  if(a[i][k]+a[j][k]>K)ok=false;
            }
            if(ok)l.unite(i,j);
        }
    }
    mint ans=mint(1);
    for(int i=0;i<n;i++){
         if(l.find(i)!=i)continue;
         ans*=fac[l.size(i)];
    }
    UF r(n);
        for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            bool ok=true;
            for(int k=0;k<n;k++){
                  if(a[k][i]+a[k][j]>K)ok=false;
            }
            if(ok)r.unite(i,j);
        }
    }
        for(int i=0;i<n;i++){
         if(r.find(i)!=i)continue;
         ans*=fac[r.size(i)];
    }
    cout<<ans<<"\n";
}

// Problem: C - Shuffle Permutation
// Contest: AtCoder - AtCoder Regular Contest 107
// URL: https://atcoder.jp/contests/arc107/tasks/arc107_c
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define ff         first
#define ss         second
#define endl       '\n'
#define pb         push_back
#define int        long long
#define vi         vector<int>
#define mii        map<int, int>
#define pii        pair<int, int>
#define all(x)     (x).begin(), (x).end()
#define fill(a,b)  memset(a, b, sizeof(a))
#define setbits(x) __builtin_popcountll(x)
#define rep(i,x,y) for(int i=(int)x; i<y; i++)
#define px(a)      for(auto x: a) cout<<x<<" "; cout<<'\n';
#define pxy(a,n)   rep(i,0,n) {px(a[i])};

const long long MOD=998244353,N=1e5+5;
int power(int x, unsigned int y)
{
    int res = 1;
    x = x % MOD;
    if (x == 0) return 0;

    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % MOD;
        y = y>>1;
        x = (x*x) % MOD;
    }
    return res;
}
int fact[N];
void factorial(int n){
	fact[0]=1;
	for(int i=1;i<=n;i++){
		fact[i]=fact[i-1]*i;
		if(fact[i]>=MOD)
			fact[i]%=MOD;
	}
}
class dsu {
 public:
  vector<int> p;
  int n;

  dsu(int _n) : n(_n) {
    p.resize(n);
    iota(p.begin(), p.end(), 0);
  }

  inline int get(int x) {
    return (x == p[x] ? x : (p[x] = get(p[x])));
  }

  inline bool unite(int x, int y) {
    x = get(x);
    y = get(y);
    if (x != y) {
      p[x] = y;
      return true;
    }
    return false;
  }
};
int32_t main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	//Remove incase of Online Query

	factorial(55);
	int n,kk,ans=1; cin>>n>>kk;
	int a[n][n];
	rep(i,0,n) rep(j,0,n) cin>>a[i][j];
	dsu r(n),c(n);
	rep(i,0,n) rep(j,i+1,n){
		rep(k,0,n){
			if(a[i][k]+a[j][k]>kk) goto end;
		}
		r.unite(i,j);
		end:;
	}
	rep(i,0,n) rep(j,i+1,n){
		rep(k,0,n){
			if(a[k][i]+a[k][j]>kk) goto end1;
		}
		c.unite(i,j);
		end1:;
	}
	int r_val[n]={0};
	int c_val[n]={0};
	rep(i,0,n){
		r_val[r.get(i)]++;
		c_val[c.get(i)]++;
	}
	// px(r_val);
	// px(c_val);
	rep(i,0,n){
		ans*=fact[r_val[i]];
		ans%=MOD;
		ans*=fact[c_val[i]];
		ans%=MOD;
	}
	cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define mt              make_tuple
#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 mod             1000000007
#define hell 100000000000000007 //10e18+7
#define mod 1000000007//10e9+7
#define pi  3.141592653589793238
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define range(a,b)    substr(a,b-a+1)
#define w(x)            int x; cin>>x; while(x--)
#define trace(x)    cerr<<#x<<": "<<x<<" "<<endl;
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
int arr[300002];
int segtree[4 * 300002 + 1];
// int mod_exp(int x, int y, int mm)
// {
//   x %= mm;
//   if (y == 0)
//     return (1);
//   else if (y % 2 == 0)
//     return (mod_exp((x * x) % mm, y / 2, mm));
//   else
//     return ((x * mod_exp((x * x) % mm, (y - 1) / 2, mm)) % mm);
// }
// int modInverse(int n, int p)
// {
//   return mod_exp(n, p - 2, p);
// }
//remember the approach of suming up the element
// and when it exceeds from our radar
// try removing from the staring part
//priority queue max heap imp!!
void buildSegtree(int s1, int e1, int p1)
{
  if (s1 == e1)
  {
    segtree[p1] = (arr[s1]);
    return;
  }
  int mid = ((s1 + e1) / 2);
  buildSegtree(s1, mid, 2 * p1 + 1);
  buildSegtree(mid + 1, e1, 2 * p1 + 2);
  segtree[p1] = ((segtree[2 * p1 + 1])^segtree[2 * p1 + 2]) ;
}

int rangeQuery(int q1, int q2, int s1, int e1, int p1)
{
  if (q1 <= s1 && q2 >= e1)
    return (segtree[p1]);
  if (q2 < s1 || q1 > e1)
    return (0);//it varies BE CAREFUint!!
  int mid = (s1 + e1) / 2;
  int l1 = rangeQuery(q1, q2, s1, mid, 2 * p1 + 1);
  int l2 = rangeQuery(q1, q2, mid + 1, e1, 2 * p1 + 2);
  return ((l1 ^ l2));
}
void updateQuery(int q1, int q2, int id, int p1, int val)
{
  if (q1 == q2)
  {
    segtree[p1] = segtree[p1] ^ val;
    return;
  }
  int mid = (q1 + q2) / 2;
  if (id > mid)
    updateQuery(mid + 1, q2, id, 2 * p1 + 2, val);
  else
    updateQuery(q1, mid, id, 2 * p1 + 1, val);
  segtree[p1] = (segtree[2 * p1 + 1] ^ segtree[2 * p1 + 2]);
}
// int binpow(int a, int b, int m)
// {
//   a %= m;
//   int res = 1;
//   while (b > 0) {
//     if (b & 1)
//       res = res * a % m;
//     a = a * a % m;
//     b >>= 1;
//   }
//   return res;
// }
// int inv(int a) {
//   a %= mod;
//   if (a < 0) a += mod;
//   int b = mod, u = 0, v = 1;
//   while (a) {
//     int t = b / a;
//     b -= t * a; swap(a, b);
//     u -= t * v; swap(u, v);
//   }
//   if (u < 0) u += mod;
//   return u;
// }

int32_t main()
{
#ifndef ONLINE_JUDGE
  freopen("i1.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  buildSegtree(0, n - 1, 0);
  while (m--)
  {
    int a, b, c;
    cin >> a >> b >> c;

    if (a == 1)
    {
      b--;
      updateQuery(0, n - 1, b, 0, c);
    }
    else if (a == 2)
    {
      b--;
      c--;
      int ans = rangeQuery(b, c, 0, n - 1, 0);
      cout << ans << endl;
    }
  }

}

/*author @dhanush*/

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define boost                       \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL)
#define pb push_back
#define all(x) x.begin(), x.end()
#define se second
#define fi first
ll MOD = 1e9 + 7;
const ll N = 200000 + 10;
vector<ll>adj[N];
ll sz[N];
ll dp[N];
void dfs(ll n,ll p)
{
  for(auto x:adj[n])
  {
    if(x!=p)
    {
      sz[x]+=sz[n];
      dfs(x,n);

    }
  }
}
void dfsdp(ll n,ll p)
{
  for(auto x:adj[n])
  {
    if(x!=p)
    {
      dp[x]=dp[n]+1;
      dfsdp(x,n);
    }
  }
}
void peace()
{
 ll n;
 cin>>n;
 vector<pair<ll,ll>>v;
 for(int i=1;i<n;i++)
 {
   ll a,b;
   cin>>a>>b;
   v.pb({a,b});
   adj[a].pb(b);
   adj[b].pb(a);
 }
 dfsdp(1,-1);
 ll q;
 cin>>q;
 while(q--)
 {
   ll t,e,x;
   cin>>t>>e>>x;
   ll nxt=v[e-1].se;
   ll par=v[e-1].fi;
   if(dp[par]>dp[nxt])
   {
     swap(par,nxt);
     t^=3;
   }
   if(t==1)
   {
     sz[1]+=x;
      sz[nxt]-=x;
   }
   else
   {
     //de
     sz[nxt]+=x;
   }

 }
 dfs(1,-1);
 for(int i=1;i<=n;i++)
 {
   cout<<sz[i]<<endl;
 }
}
int main()
{
  boost;
  ll t;
  t = 1;
  //----------
  // cin >> t;
  //----------
  while (t--)
    peace();
}


#include<bits/stdc++.h>
using namespace std;
using LL=long long;
using P=pair<int,int>;
using T=tuple<int,int,int>;
constexpr int mod=1000000007;
constexpr int inf=1e9;
int in(){
    int x;
    scanf("%d",&x);
    return x;
}
struct graph{
    vector<vector<int>>e;
    vector<int>used;
    int cnt=0;
    graph(int n){
        e.resize(n);
        used.resize(n);
    }
    void add_edge(int v,int u){
        e[v].emplace_back(u);
    }
    void dfs(int v){
        cnt++;
        for(int u:e[v])if(used[u]==0)used[u]=1,dfs(u);
    }
    int solve(int s){
        fill(used.begin(),used.end(),0);
        used[s]=1;
        cnt=0;
        dfs(s);
        return cnt;
    }
};
int main(){
    int n=in();
    graph g(n);
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            char c;
            cin>>c;
            if(c=='1')g.add_edge(j,i);
        }
    }
    double ans=0.0;
    for(int i=0;i<n;i++)ans+=1.0/double(g.solve(i));
    printf("%.10lf",ans);
    return 0;
}

#include <bits/stdc++.h>
using Int = long long;  // clang-format off
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define RREP_(i, a_, b_, a, b, ...) for (Int i = Int(b) - 1, low##i = (a); i >= low##i; i--)
#define RREP(i, ...) RREP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define ALL(v) std::begin(v), std::end(v)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on
struct in {
    template <class T> operator T() {
        T t;
        std::cin >> t;
        return t;
    }
};
void out() { std::cout << "\n"; }
template <class Head, class... Tail> void out(Head&& h, Tail&&... t) {
    std::cout << h << (sizeof...(Tail) == 0 ? "" : " "), out(std::forward<Tail>(t)...);
}
template <class T> bool chmin(T& a, const T& b) { return a > b ? a = b, true : false; }
template <class T> bool chmax(T& a, const T& b) { return a < b ? a = b, true : false; }
template <class T> using V = std::vector<T>;

/**
 *    author:  knshnb
 *    created: Sun Feb 28 00:29:14 JST 2021
 **/

V<V<Int>> solve(Int n) {
    V<V<Int>> ret(1);
    REP(i, 1 << n) ret[0].push_back(i < (1 << (n - 1)));
    if (n == 1) return ret;
    auto sub = solve(n - 1);
    REP(t, 2) {
        for (auto& v : sub) {
            ret.push_back({});
            for (Int x : v) ret.back().push_back(x);
            for (Int x : v) ret.back().push_back(t ? !x : x);
        }
    }
    return ret;
}
signed main() {
    Int n = in();
    auto res = solve(n);
    out(res.size());
    for (auto& v : res) {
        for (Int x : v) std::cout << char('A' + x);
        out();
    }
}


#include<bits/stdc++.h>
#define LL long long
using namespace std;
LL n,ans;
int main()
{
	cin>>n;
	n*=2;
	for(LL i=1;i*i<=n;i++)
	{
		if(n%i==0)
		{
			LL a=i,b=n/i;
			if(a%2!=b%2)ans+=2;
		}
	}
	cout<<ans;
	return 0;
}

#include<iostream>
#include<iterator>
#include<algorithm>
#include<climits>
#include<map>
#include<set>
#include<cmath>
#include<numeric>
#include<string>
#include<sstream>
#include<cstdio>
#include<vector>
#include<bitset>
// #include <atcoder/segtree>
#define ll long long
using namespace std;

int main()
{
    ll n,s,c=0;
    cin >> n;
    s = (ll)sqrt(n);
    for(ll i = 1; i <= s; ++i){
        ll cp = n/i;
        if(n%i==0){
            if(i%2==1){
                c++;
            }
            if (cp%2==1){
                if (cp!=i)c++;
            }
        }
    }
    cout<<(2*c)<<endl;
}


#include <iostream>
#include <queue>
using namespace std;
using ll = long long;

int n;
priority_queue<ll> q;

void solve()
{
    q.push(0);
    ll res = 1, before = q.top(), now;
    q.pop();
    while (q.size() > 0)
    {
        now = q.top();
        q.pop();
        if (before > now)
        {
            res = res * (before - now + 1) % (1000000007);
            before = now;
        }
    }
    cout << res << '\n';
}

int main()
{
    ll qtemp;
    cin >> n;
    for (int i=0; i<n; i++)
    {
        cin >> qtemp;
        q.push(qtemp);
    }

    solve();

    return 0;
}

#pragma warning(disable: 4996)
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <sstream>
#include <fstream>
#include <math.h>
#include <algorithm>
#include <map>
#include <bitset>
#include <queue>

using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)

int main() {
    ll n;
    cin >> n;
    ll tmp = 0, s = 0;
    while (s <= n + 1) {
        tmp++;
        s += tmp;
        if (s > n + 1)tmp -= 1;
    }

    ll ans = n - tmp + 1;
    cout << ans << endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll b,c;
	scanf("%lld%lld",&b,&c);
	ll cnt=0;
	if(b<=0){
		cnt=c+1;
		c--;
		if(b==0)cnt--;
		if(c>0&&b<0)cnt+=min(-2*b-1,c-1);
	}else {
		cnt=c+(c==1?1:0);
		cnt+=min(2*b-1,c-1);
	}printf("%lld\n",cnt);
}

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

ll INF = 1e18;

int main() {

  int n;
  cin >> n;
  vector<ll> a(n);
  ll m = 0;
  rep(i,n){
    ll x, y;
    cin >> x >> y;
    a[i] = 2 * x + y;
    m += x;
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  ll count = 0;
  rep(i,n){
    count += a[i];
    if(count > m){
      cout << i+1 << endl;
      break;
    }
  }

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ALL(obj) obj.begin(),obj.end()
#define SORT(obj) sort(obj.begin(),obj.end())
#define pb(obj) push_back(obj)
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;
ll const MOD=1e9+7;
const ll INF = 9000000000000000000;
vector<bool> seen;//グラフ用の配列
long long pow(long long x, long long n) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * x % MOD;  // n の最下位bitが 1 ならば x^(2^i) をかける
        x = x * x % MOD;
        n >>= 1;  // n を1bit 左にずらす
    }
    return ret;
}
int ctoi(const char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return -1;
  }
}
int kakuketa(int n){
    int ans = 0;
    while(n>0){
        ans += n%10;
        n /= 10;
    }
    return ans;
}
void dfs2(int y,int x,vector<vector<bool>> &flags,Graph &G){//二次元dfs
    if(G[y][x] == 0) return;
    if(flags[y][x] == true) return;
    else{
        flags[y][x] = true;
    }
    dfs2(y+1,x,flags,G);
    dfs2(y+1,x+1,flags,G);
    dfs2(y+1,x-1,flags,G);
    dfs2(y,x+1,flags,G);
    dfs2(y,x-1,flags,G);
    dfs2(y-1,x+1,flags,G);
    dfs2(y-1,x,flags,G);
    dfs2(y-1,x-1,flags,G);
}

int main(){
    ll r,x,y;
    cin>>r>>x>>y;
    long double kyori0 = sqrt(x*x+y*y);
    ll kyori;
    if(floor(kyori0) == ceil(kyori0)){
        kyori = floor(kyori0);
        if(kyori < r){
            cout<<2<<endl;
            return 0;
        }
        if(kyori%r==0){
            cout<<kyori/r<<endl;
            return 0;
        }
        else{
            cout<<kyori/r+1<<endl;
            return 0;
        }
    }
    else{
        kyori = floor(kyori0)+1;
        if(kyori-1 < r){
            cout<<2<<endl;
            return 0;
        }
        if(kyori%r==0){
            cout<<kyori/r<<endl;
            return 0;
        }
        else{
            cout<<kyori/r+1<<endl;
            return 0;
        }
    }
}

#include <iostream>
#include <bits/stdc++.h>
#define ll long long int
#define max_value 0x3f3f3f

/*freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);*/
using namespace std;
const int  inf=1e9+7;

void solve(){
  double r,x,y;
  cin>>r>>x>>y;
  double z=sqrt(x*x+y*y);
  if(z==r)
    cout<<"1"<<endl;
  else if(z<=2*r)
    cout<<"2"<<endl;
  else {
  int ans=ceil(z/r);
  cout<<ans<<endl;}

}

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


#include <bits/stdc++.h>
using namespace std;
int main(){
int n,m;
cin>>n>>m;
vector<vector<tuple<int,long,long>>>g(n+1);
for(int i=0;i<m;i++){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    g[a].emplace_back(b,c,d);
    g[b].emplace_back(a,c,d);
}
auto w=[](long t,long d){
    int l=sqrt(d)-t-10;
    l=max(l,0);
    int m=l;
    for(int i=l;i<20+l;i++)
    if(i+d/(t+i+1)<m+d/(t+m+1))
    m=i;
    return m;
};
priority_queue<pair<long,int>,vector<pair<long,int>>,greater<>>q;
vector<long>D(n+1,1e18);
q.emplace(D[1]=0,1);
while(!q.empty()){
    auto[t,u]=q.top();
    q.pop();
    if(u==n)break;
    if(t>D[u])continue;
    for(auto[v,c,d]:g[u]){
        auto T=t+w(t,d);
        auto x=T+c+d/(T+1);
        if(D[v]>x)q.emplace(D[v]=x,v);
    }
}
cout<<(D[n]<1e18?D[n]:-1)<<endl;
}

//#define MULTICASES
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(i=(a);i<=(b);++i)
#define per(i,a,b) for(i=(a);i>=(b);--i)
#define REP(i,a,b) for(i=(a);i< (b);++i)
#define PER(i,a,b) for(i=(a);i> (b);--i)
#define ERR(...) fprintf(stderr,__VA_ARGS__)
inline void ac();
int main(){
#ifdef MULTICASES
	int t;scanf("%d",&t);while(t--)ac();
#else
	ac();
#endif
	return 0;
}
const int MAXN=200005;
int d,Ans;
vector<int>E[MAXN];
inline int dfs(const int &v=1,const int &f=0){
	int a=-1,b=0,t,u;
	vector<int>::iterator e,ee;
	for(e=E[v].begin(),ee=E[v].end();e!=ee;++e)if((u=*e)!=f){
		t=dfs(u,v);
		if(t<0){if(t<b)b=t;}
		else   {if(t>a)a=t;}
	}
	//ERR("v=%d a=%d b=%d\n",v,a,b);
	//if(a>-b){ERR("I. %d\n",a-1);}
	//else{if(b-1<-d){ERR("II. %d (Ans=%d)\n",d,Ans+1);}else{ERR("III. %d\n",b-1);}}
	if(a>-b)return a-1;
	else{if((--b)<-d){++Ans;return d;}else return b;}
}
inline void ac(){
	int n,k,i,v,u,l,r;
	scanf("%d%d",&n,&k);
	rep(i,2,n){
		scanf("%d%d",&v,&u);
		E[v].push_back(u);
		E[u].push_back(v);
	}
	i=n-1;l=1;r=n-2;
	while(l<=r){
		d=(l+r)>>1;Ans=0;
		if(dfs()<0)++Ans;
		//ERR("\nd=%d Ans=%d\n\n\n\n",d,Ans);
		if(Ans>k)l=d+1;
		else r=(i=d)-1;
	}
	printf("%d\n",i);
}
/*
0. int overflow, array bounds
1. special cases (n=1? n=0?)
2. do smth instead of nothing and stay organized
3. WRITE STUFF DOWN
4. DON'T GET STUCK ON ONE APPROACH
5. STAY CALM AND DON'T GET EXPLODED
*/


#include <bits/stdc++.h>
#define ls (rt<<1)
#define rs (rt<<1|1)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=4e5+10;
const int INF=0x3f3f3f3f;
int a[N],n;
pii pa[N];
int mx[N<<2],lazy[N<<2];
int main() {
    auto push_down=[&](int rt){
        if(lazy[rt]){
            lazy[ls]+=lazy[rt];
            lazy[rs]+=lazy[rt];
            mx[ls]-=lazy[rt];
            mx[rs]-=lazy[rt];
            lazy[rt]=0;
        }
    };
    function<void(int,int,int)>build=[&](int l,int r,int rt){
        if(l==r){mx[rt]=l;return ;}
        int mid=l+r>>1;
        build(l,mid,ls);
        build(mid+1,r,rs);
    };
    function<int(int,int,int,int)>query=[&](int l,int r,int x,int rt){
        if(l==r)return mx[rt];
        push_down(rt);int mid=l+r>>1;
        if(x<=mid)return query(l,mid,x,ls);else return query(mid+1,r,x,rs);
    };
    function<void(int,int,int,int,int,int)>update=[&](int l,int r,int L,int R,int val,int rt){
        if(L<=l&&r<=R){mx[rt]-=val;lazy[rt]+=val;return ;}
        push_down(rt);int mid=l+r>>1;
        if(L<=mid)update(l,mid,L,R,val,ls);
        if(mid<R)update(mid+1,r,L,R,val,rs);
        mx[rt]=max(mx[ls],mx[rs]);
    };
    cin>>n;
    vector<pair<int,int>>pa;
    for(int i=1;i<=2*n;i++){
		cin>>a[i],pa.emplace_back(a[i],i>n?i-n:n-i+1);
	}
	sort(pa.rbegin(),pa.rend());
    ll ans=0;
    build(1,n,1);
    for(auto& i:pa){
        int x=i.second;
        int val=query(1,n,x,1);
        if(val==0)continue;
        ans+=i.first;
        int l=1,r=n,res=-1;
        while (l<=r){
            int mid=l+r>>1;
            if(query(1,n,mid,1)>=val){
                res=mid;
                r=mid-1;
            }else l=mid+1;
        }
        update(1,n,res,n,1,1);
    }
    cout<<ans;
    return 0;
}

#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<queue>
#include<stack>
#include<utility>
#include<cstdlib>
#include<cstdio>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<list>
#include<tuple>
using namespace std;

typedef long long ll;
typedef long double ld;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

#define FOR(i, a, b) for(ll i=(a); i<(b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define NREP(i, n) FOR(i, 1, n+1)

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

struct IOSetup{
	IOSetup(){
		cin.tie(0);
		ios::sync_with_stdio(0);
		cout<<fixed<<setprecision(12);
	}
} iosetup;

struct Edge{
    ll to, cost;
    Edge(ll t, ll c) : to(t), cost(c) { }
};
using Graph = vector<vector<Edge>>;

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

const ll MOD=1e9+7;
const ll nmax=200000+10;

ll N;
Graph G(nmax);

ll solve(){
	vvl color(nmax,vl(60,-1));
	vl cnt1(60,0);
	vl seen(nmax,0);
    queue<ll> q;
    q.push(0);
	REP(i,60) color[0][i]=0;

    while(!q.empty()){
        ll v=q.front();
        q.pop();
        seen[v]=1;

        for(auto e:G[v]){
            if(seen[e.to]) continue;

			ll et=e.to, ec=e.cost;
			q.push(e.to);
			REP(i,60){
				bool eci=ec&1;
				ec>>=1;
				color[et][i]=color[v][i]^eci;
				if(color[et][i]) cnt1[i]++;
			}
        }
    }

	ll res=0,rec=1;
	REP(i,60){
		ll mid1=rec;
		rec=rec*2%MOD;
		ll mid2=(N-cnt1[i])*cnt1[i]%MOD;
		ll mid=mid1*mid2%MOD;
		res+=mid;
		res%=MOD;
	}

    return res;
}

int main(void){
	scanf(" %ld",&N);
    REP(i,N-1){
        ll u,v,w; scanf(" %ld%ld%ld",&u,&v,&w);
        u--,v--;
        G[u].push_back(Edge{v,w});
        G[v].push_back(Edge{u,w});
    }

    ll res=solve();
    printf("%ld\n",res);

    return 0;
}


#include <iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<iomanip>
#include<map>
#include<random>
#include<complex>
#include<math.h>
#include<functional>
#include<stack>
#include<queue>
#include<unordered_map>
#include<set>
#include<numeric>
#include <cassert>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define req(i,n) for(int i = 1;i <=  n; i++)
#define rrep(i,n) for(ll i = n-1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
#define RALL(a) rbegin(a),rend(a)
typedef long long ll;
typedef long double ld;
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 = 0x3fffffff;
const ll INF = 1e18;
int n, m; vector<vector<pair<int, int>>> p;
bool check(int msk) {
	int cnt = 0; vector<int> tp(20,0);
	rep(i, n) {
		if (msk & (1 << i)) cnt++,tp[i]++;
	}rep(i, n) tp[i + 1] += tp[i];
	for (pair<int, int> i : p[cnt]) {
		if (tp[i.first] > i.second) return false;
	}return true;
}
int main() {
	cin >> n >> m; p.resize(n + 1); vector<ll> dp(1 << n,0);
	dp[0] = 1;
	rep(i, m) {
		int x, y, z; cin >> x >> y >> z; y--;
		p[x].push_back({ y,z });
	}rep(i, 1 << n) {
		rep(j, n) if (!(i & (1 << j)) && check(i)) dp[(1<<j)| i] += dp[i];
	}cout << dp[(1 << n)-1] << endl;
}

#include<bits/stdc++.h>
//#include<atcoder/all>
using namespace std;
//using namespace atcoder;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<double,double> 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; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const ll mod=998244353;
const ll LINF=1ll<<60;
const int INF=1<<28;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};

int main(){
    int n,m;cin >> n >> m;
    vector<int> x(m), y(m), z(m);
    for (int i = 0; i < m; i++) {
        cin >> x[i] >> y[i] >> z[i];
    }
    vector<ll> dp(1 << (n + 1), 0);
    dp[0] = 1;
    for (int bit = 0; bit < 1<<n; bit++) {
        int C = __builtin_popcount(bit);
        for (int i = 0; i < m; i++) {
            if(C == x[i]){
                int cnt = 0;
                for (int j = 0; j < n; j++) {
                    if((bit >> j) & 1){
                        if(j < y[i]){
                            cnt++;
                        }
                    }
                }
                if(cnt > z[i]){
                    dp[bit] = 0;
                }
            }
        }
        if(dp[bit] < 0) continue;
        for (int i = 0; i < n; i++) {
            if((bit >> i) & 1) continue;
            int nbit = bit | (1 << i);
            dp[nbit] += dp[bit];
        }
    }
    cout << max(0ll, dp[(1 << n) - 1]) << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

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

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

    int64_t maxA = 0;
    int64_t lastC = 0;
    for (int i = 0; i < n; i++) {
        int64_t b;
        cin >> b;

        maxA = max(a[i], maxA);
        lastC = max(b * maxA, lastC);

        cout << lastC << endl;
    }

    return 0;
}

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

int main()
{
    int T;
    cin>>T;
    for (int i=0; i<T; i++)
    {
        int N;
        cin>>N;
        string S[3];
        for (string &s: S)
        {
            cin>>s;
            s = s+s;
        }

        auto check = [&](string t)
        {
            for (int i=0; i<3; i++)
            {
                int p = 0;
                for (int j=0; j<4*N && p<2*N+1; j++)
                    if (S[i][j]==t[p])
                        p++;
                if (p<2*N+1)
                    return false;
            }
            return true;
        };

        bool ok = false;
        for (int j=0; j<2 && !ok; j++)
            for (int k=0; k<2 && !ok; k++)
                for (int l=0; l<2 && !ok; l++)
                    for (int k=0; k<3 && !ok; k++)
                    {
                        string s1 = string(N, j==0 ? '0' : '1');
                        string s2 = string(N, k==0 ? '0' : '1');
                        string s3 = string(1, l==0 ? '0' : '1');
                        string s;
                        if (k==0)
                            s = s3+s1+s2;
                        if (k==1)
                            s = s1+s3+s2;
                        if (k==2)
                            s = s1+s2+s3;
                        if (check(s))
                        {
                            cout<<s<<endl;
                            ok = true;
                        }
                    }
    }
}


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

bool comp(pair<int, int>& a, pair<int, int>& b) {
    if (a.s != b.s) return a.s > b.s;
    else return a.f > b.f;
}

void solve() {
    int n, m, q; cin >> n >> m >> q;
    vi x(m);
    vector<pair<int, int>> wv(n);
    forn(i, n) cin >> wv[i].f >> wv[i].s;
    forn(i, m) cin >> x[i];
    sort(all(wv), comp);
    while (q--) {
        int l, r; cin >> l >> r; l--; r--;
        vi cur;
        forn(i, m) {
            if (i == l) i = r;
            else cur.eb(x[i]);
        }
        sort(rall(cur));
        int res = 0;
        for (int i = 0; i < n; i++) {
            int j = 0;
            if (j >= (int)cur.size() || cur[j] < wv[i].f) continue;
            while (j < (int)cur.size() && cur[j] >= wv[i].f) j++;
            j--;
            res += wv[i].s;
            cur[j] = -INF;
            sort(rall(cur));
        }
        cout << res << 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 <atcoder/maxflow.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#include <memory>
#include <iostream>
#include <map>
#include <list>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>
#include <complex>
#include <thread>
#include <bitset>
#include <assert.h>

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

typedef long long ll;

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

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

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

ll coprimesets(const vector<ll>& nos) {
    vector<ll> a;
    ll ret = 0;
    forr(i,0,1<<nos.size()) {
        int pp = i;
        int ct = 0;
        a.resize(0);
        while (pp>0) {
            if (pp%2==1) { a.push_back(nos[ct]);  }
            pp/=2;
            ++ct;
        }
        bool is_ok = true;
        forr(j,0,a.size()) {
            for(int k = j+1; k < a.size(); ++k) {
                is_ok &= (gcd(a[j], a[k])==1);
            }
        }
        ret += is_ok;
    }
    return ret;
}

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

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

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

//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {

        readint(n); readint(m); readint(q);
        vector<pair<int,int>> bagg;
        forr(i,0,n) {
            readint(ww); readint(vv);
            bagg.push_back(make_pair(vv,ww));
        }
        sort(bagg.begin(), bagg.end());
        reverse(bagg.begin(), bagg.end());

        vector<int> box;
        forr(i,0,m) {
            readint(bb);
            box.push_back(bb);
        }

        forr(i,0,q) {
            readint(l); readint(r); --l; --r;
            multiset<int> box_av;
            forr(i,0,m) {
                if ((i<l) || (i>r)) { box_av.insert(box[i]); }
            }
            int ret = 0;
            for(auto x : bagg) {
                auto it = box_av.lower_bound(x.second);
                if (it!=box_av.end()) {
                    ret += x.first;
                    box_av.erase(it);
                }
            }
            cout << ret << endl;
        }

    }

    return 0;
}


#include "bits/stdc++.h"

using namespace std;

#define ll long long

#define       forn(i,n)              for(int i=0;i<n;i++)
#define          all(v)              v.begin(), v.end()
#define         rall(v)              v.rbegin(),v.rend()

#define            pb                push_back
#define          sz(a)               (int)a.size()
#define         fastio               ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define      GR(a,n,m)               vector<vector<int>> a(n, vector<int>(m, 0));

struct Point
{
    double x;
    double y;
};
bool onSegment(Point p, Point q, Point r)
{
    if (q.x <= max(p.x, r.x) && q.x >= min(p.x, r.x) &&
        q.y <= max(p.y, r.y) && q.y >= min(p.y, r.y))
       return true;

    return false;
}
int orientation(Point p, Point q, Point r)
{
    double val = (q.y - p.y) * (r.x - q.x) -
              (q.x - p.x) * (r.y - q.y);

    if (val == 0) return 0;

    return (val > 0)? 1: 2;
}
bool doIntersect(Point p1, Point q1, Point p2, Point q2)
{
    int o1 = orientation(p1, q1, p2);
    int o2 = orientation(p1, q1, q2);
    int o3 = orientation(p2, q2, p1);
    int o4 = orientation(p2, q2, q1);
    if (o1 != o2 && o3 != o4)
        return true;
    if (o1 == 0 && onSegment(p1, p2, q1)) return true;
    if (o2 == 0 && onSegment(p1, q2, q1)) return true;
    if (o3 == 0 && onSegment(p2, p1, q2)) return true;
    if (o4 == 0 && onSegment(p2, q1, q2)) return true;
    return false;
}
void solve()
{
	ll n, d, h;
	cin >> n >> d >> h;
	vector<int> a(n),b(n);
	for(int i = 0;i < n;i++)
		cin >> a[i] >> b[i];

	double l = 0, r = 1000;
	double ans = r;
	for(int p = 0;p < 100;p++)
	{
		double mid = (double)(l + r) / 2.0;
		bool ok = true;

		Point A1 = {0, mid};
		Point A2 = {d,h};

		for(int i = 0;i < n;i++)
		{
			Point B1 = {a[i], 0};
			Point B2 = {a[i], b[i]};

			if(doIntersect(A1,A2,B1,B2)){
				ok=false;
			}
		}
		if(ok){
			ans = mid;
			r = mid;
		}else{
			l=mid;
		}
	}
	cout << fixed << setprecision(16) << ans << "\n";
}

int32_t main()
{
	fastio;
	int t = 1;
	//cin >> t;
	for(int tt = 0;tt < t;tt++)
	{
		solve();
	}
}

#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;
using ll=long long;
using ld=long double;
using pll=pair<ll, ll>;
//using mint = modint1000000007;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
#define PI acos(-1)
#define oo 2e18
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
//priority_queue<ll, vector<ll>, greater<ll>> Q;
/*

*/
int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  ll N;
  ld D, H;
  cin >> N >> D >> H;
  ld ans=0.0;
  rep(i, N){
    ld d, h;
    cin >> d >> h;
    // 下半分
    ld tmp = h;
    // 比率をひく
    tmp -= (H-h)/(D-d) * d;
    chmax(ans, tmp);
  }
  cout << ans << endl;
}


#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
#include <cfloat>
#include <iomanip>
using namespace std;
int a[50][50];
const long long MOD = 998244353;
vector <int> edges[50];
long long fact[51];
bool done[50];
long long dfs(int cur){
  done[cur] = true;
  int ret = 1;
  for(int i = 0; i < edges[cur].size(); i++){
    if(!done[edges[cur][i]]){
      ret += dfs(edges[cur][i]);
    }
  }
  return ret;
}

int main(){
  int N;
  int K;
  cin >> N >> K;
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      cin >> a[i][j];
    }
  }

  fact[0] = 1;
  for(int i = 0; i < N; i++){
    fact[i + 1] = (fact[i] * (i + 1)) % MOD;
  }

  if(N == 1){
    cout << 1 << endl;
    return 0;
  }

  for(int i = 0; i < N - 1; i++){
    for(int j = i + 1; j < N; j++){
      bool swappable = true;
      for(int k = 0; k < N; k++){
        if(a[i][k] + a[j][k] > K){
          swappable = false;
          break;
        }
      }

      if(swappable){
        edges[i].push_back(j);
        edges[j].push_back(i);
      }
    }
  }

  long long ans = 1;
  for(int i = 0; i < N; i++){
    if(!done[i]){
      ans = (ans * fact[dfs(i)]) % MOD;
    }
  }

  for(int i = 0; i < N; i++){
    edges[i].clear();
    done[i] = false;
  }

  for(int i = 0; i < N - 1; i++){
    for(int j = i + 1; j < N; j++){
      bool swappable = true;
      for(int k = 0; k < N; k++){
        if(a[k][i] + a[k][j] > K){
          swappable = false;
          break;
        }
      }

      if(swappable){
        edges[i].push_back(j);
        edges[j].push_back(i);
      }
    }
  }

  for(int i = 0; i < N; i++){
    if(!done[i]){
      ans = (ans * fact[dfs(i)]) % MOD;
    }
  }

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

#include<bits/stdc++.h>
//#include<atcoder/all>

using namespace std;
//using namespace atcoder;

using ll = long long;
using Graph = vector<vector<int>>;

#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rrep(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)

constexpr ll INF = (ll)1e9;
constexpr ll mod = 998244353;
constexpr double PI = 3.1415926535897932;

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;
}
inline void init() {
    cin.tie(nullptr); cout.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
}

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

    // for prime mod
    mint inv() const {
        return pow(mod - 2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};
struct UnionFind {
	vector<int>d;

	UnionFind(int N) :d(N, -1) {}

	int find(int x) {
		if (d[x] < 0)return x;
		return d[x] = find(d[x]);
	}
	bool unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return false;
		if (d[x] > d[y])swap(x, y);
		d[x] += d[y];
		d[y] = x;
		return true;
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	int size(int x) {
		return -d[find(x)];
	}
};

mint func(int a) {
    if (a == 0)return 1;
    return (mint)a * func(a - 1);
}

int main() {
    init();

	int N, K; cin >> N >> K;
	vector<vector<int>>mat(N, vector<int>(N));
	rep(i, 0, N)rep(j, 0, N)cin >> mat[i][j];
    UnionFind uf1(N), uf2(N);
	rep(i, 0, N) {
        rep(j, i + 1, N) {
            bool a = true, b = true;
			rep(k, 0, N) {
                if (mat[k][i] + mat[k][j] > K)a = false;
                if (mat[i][k] + mat[j][k] > K)b = false;
			}
            if (a)uf1.unite(i, j);
            if (b)uf2.unite(i, j);
		}
	}
    mint a = 1, b = 1;
    rep(i, 0, N) {
        if (uf1.d[i] < 0)a *= func(-uf1.d[i]);
        if (uf2.d[i] < 0)b *= func(-uf2.d[i]);
    }
    mint ans = a * b;
    cout << ans.x << "\n";

    return 0;
}