#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <cmath>
#include <cassert>
#include <stack>
#include <numeric>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, ss) for (int i = (ss);i < (int)( n ); i++)
#define all(l) l.begin(), l.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T>
inline bool chmax(T &l, const T b) {
    if (l < b) {
        l = b;
        return true;
    }
    return false;
}
template<typename T>
inline bool chmin(T &l, const T b) {
    if (l > b) {
        l = b;
        return true;
    }
    return false;
}

# ifdef LOCAL_DEBUG
template<typename T>
void vdeb(const std::vector<T> &bb) {
    for (unsigned int i = 0;i < bb.size();i++) {
        if (i == bb.size() - 1) std::cout << bb[i];
        else std::cout << bb[i] << ' ';
    }
    std::cout << '\n';
}
template<typename T>
void vdeb(const std::vector<std::vector<T>> &bb) {
    for (unsigned int i = 0;i < bb.size();i++) {
        std::cout << i << ' ';
        vdeb(bb[i]);
    }
    std::cout << '\n';
}
# endif

using namespace std;

void dfs1(vector<vector<int>> &da, vector<Pii> &ed, vector<ll> &score, int now, int depth) {
    if(score[now] != -1) return;
    score[now] = depth;
    rip(i,da[now].size(),0) {
        dfs1(da, ed, score, ed[da[now][i]].first^ed[da[now][i]].second^now, depth+1);
    }
}

void dfs2(vector<vector<int>> &da, vector<Pii> &ed, vector<ll> &ans, vector<ll> &weg, int now, ll depth) {
    if(ans[now] != -1) return;
    ans[now] = depth + weg[now];
    rip(i,da[now].size(),0) {
        dfs2(da, ed, ans, weg, ed[da[now][i]].first^ed[da[now][i]].second^now, ans[now]);
    }
}

int main() {
    int n; cin >> n;
    vector<Pii> ed(n-1);
    vector<vector<int>> da(n, vector<int>(0));
    vector<ll> score(n, -1);
    rip(i,n-1,0) {
        int a,b; cin >> a >> b;
        --a;--b;
        da[a].push_back(i);
        da[b].push_back(i);
        ed[i] = {a, b};
    }
    dfs1(da, ed, score, 0, 0);
    vector<ll> weg(n);
    vector<ll> ans(n, -1);
    // rip(i,n-1,0) {
    //     if(ed[i].first < ed[i].second) swap(ed[i].first, ed[i].second);
    // }
    int q; cin >> q;
    rip(i,q,0) {
        ll t, e, x; cin >> t >> e >> x;
        --e;
        if(t == 1) {
            if(score[ed[e].first] > score[ed[e].second]) {
                weg[ed[e].first] += x;
            }
            else {
                weg[ed[e].second] -= x;
                weg[0] += x;
            }
        }
        else {
            if(score[ed[e].first] < score[ed[e].second]) {
                weg[ed[e].second] += x;
            }
            else {
                weg[ed[e].first] -= x;
                weg[0] += x;
            }
        }
    }
    dfs2(da, ed, ans, weg, 0, 0);
    rip(i,n,0) {
        cout << ans[i] << '\n';
    }
}

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

#define R register
#define LL long long

inline int read() {
	int x = 0, f = 1; char a = getchar();
	for(; a > '9' || a < '0'; a = getchar()) if(a == '-') f = -1;
	for(; a <= '9' && a >= '0'; a = getchar()) x = x * 10 + a - '0';
	return x * f;
}

const int N = 4e5 + 10;

int n;
int a[N], b[N], uni[N], tot;
vector<int> e[N];
int vis[N];
int F = 0; int sz;
void dfs(int x, int las) {
	if(vis[x]) { F = 1; return ; }
	sz ++;
	vis[x] = 1;
	for(int y : e[x]) if(y != las) dfs(y, x);
}

signed main() {
	#ifdef IN
	freopen("a.in", "r", stdin);
	//freopen(".out", "w", stdout);
	#endif
	n = read();
	for(int i = 1; i <= n; i ++) a[i] = read(), b[i] = read(), uni[++ tot] = a[i], uni[++ tot] = b[i];
	sort(uni + 1, uni + 1 + tot);
	tot = unique(uni + 1, uni + 1 + tot) - uni - 1;
	for(int i = 1; i <= n; i ++) {
		a[i] = lower_bound(uni + 1, uni + 1 + tot, a[i]) - uni;
		b[i] = lower_bound(uni + 1, uni + 1 + tot, b[i]) - uni;
	}
	for(int i = 1; i <= n; i ++) {
		e[a[i]].push_back(b[i]);
		e[b[i]].push_back(a[i]);
	}
	int ans = 0;
	for(int i = 1; i <= tot; i ++)
		if(! vis[i]) {
			F = 0; sz = 0;dfs(i, 0);
			ans += sz - 1;
			if(F) ans ++;
		}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
#define N 21
#define M 101
#define popcnt __builtin_popcount
using namespace std;
using ll = long long;

int n, m;
vector<pair<int, int>> qs[M];
ll dp[1<<N];

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

	cin>>n>>m;
	for (int i=0; i<m; i++) {
		int x, y, z; cin>>x>>y>>z;
		qs[x].push_back({y, z});
	}

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

		int x = popcnt(i);
		for (auto [y, z] : qs[x]) {
			int smol = i & ((1<<y) - 1);
			if (popcnt(smol) > z) dp[i] = 0;
		}
	}

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

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll N = 1e5 + 5;
vector<tuple<int, ll, ll>> G[N];
int n, m, u, v, x, y, vis[N];
ll t, k, d[N];

void bfs() {
    priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<>> q;
    fill(d, d + N, 1e18);
    d[x] = 0;
    q.push({0, x});
    while (!q.empty()) {
        auto[t, a] = q.top();
        q.pop();
        if (a == y) break;
        if (t > d[a]) continue;
        for (auto[b, t, k]:G[a]) {
            t = (d[a] + k - 1) / k * k + t;
            if (d[b] > t) {
                d[b] = t;
                q.emplace(d[b], b);
            }
        }
    }
}

int main() {
    cin >> n >> m >> x >> y;
    while (m--) {
        cin >> u >> v >> t >> k;
        G[u].emplace_back(v, t, k);
        G[v].emplace_back(u, t, k);
    }
    bfs();
    if (d[y] == 1e18) cout << -1;
    else cout << d[y];
    return 0;
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

bool finish(LL r1, LL c1, LL r2, LL c2) {
  if (r1 + c1 == r2 + c2) return true;
  if (r1 - c1 == r2 - c2) return true;
  if (abs(r1 - r2) + abs(c1 - c2) <= 3) return true;
  return false;
}

int main() {
  LL r1, c1, r2, c2; cin >> r1 >> c1 >> r2 >> c2;
  LL r = abs(r2 - r1), c = abs(c2 - c1);

  if      (r == 0 && c == 0)  cout << 0 << endl;
  else if (r == c)            cout << 1 << endl;
  else if (r + c <= 3)        cout << 1 << endl;
  else if (r + c <= 6)        cout << 2 << endl;
  else if ((r + c) % 2 == 0)  cout << 2 << endl;
  else if (abs(r - c) <= 3)   cout << 2 << endl;
  else                        cout << 3 << endl;
}

#include<bits/stdc++.h>
#define ll long long
#define llu unsigned long long
#define pb push_back
#define f(n) for(ll i=0;i<n;i++)
#define ina for(ll i=0;i<n;i++)cin>>a[i];
#define all(v) v.begin(),v.end()
#define YES printf("YES\n")
#define NO printf("NO\n")
#define IsComp(n)  (_c[n>>6]&(1<<((n>>1)&31)))
#define SetComp(n) _c[n>>6]|=(1<<((n>>1)&31))
#define fastio std::ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define finout freopen("input.cpp","r",stdin); freopen("output.cpp","w",stdout);
#define pi acos(-1)
using namespace std;
//ll pow(ll a,ll b) { ll ret=1; for(ll i=0;i<b;i++) ret*=a; return ret;}
//long long bigmod/* (a^p)%m */ ( long long a, long long p, long long m ){long long res = 1;long long x = a;while ( p ){if ( p & 1 ){res = ( res * x ) % m;}x = ( x * x ) % m;p = p >> 1;}return res;}
//ll modInverse(ll a, ll m) { ll m0 = m; ll y = 0, x = 1; if (m == 1) return 0; while (a > 1) { ll q = a / m; ll t = m; m = a % m, a = t; t = y; y = x - q * y; x = t; } if (x < 0) x += m0; return x; }
//call manipulated_seive(N) and get prime in prime vector
//const long long MAX_SIZE = 1000001; vector<long long >isprime(MAX_SIZE , true); vector<long long >prime; vector<long long >SPF(MAX_SIZE); void manipulated_seive(int N) { isprime[0] = isprime[1] = false ; for (long long int i=2; i<N ; i++) { if (isprime[i]) { prime.push_back(i); SPF[i] = i; } for (long long int j=0; j < (int)prime.size() && i*prime[j] < N && prime[j] <= SPF[i]; j++) { isprime[i*prime[j]]=false; SPF[i*prime[j]] = prime[j] ; } } }
//bitwise sieve //size of prime array = sz
//const int MAX = 100000000;const int LMT = 10000;int _c[(MAX>>6)+1];ll  prime[5761482];ll sz=0;void bitwise_sieve(){for (int i = 3; i <= LMT; i += 2)if (!IsComp(i))for (int j = i*i; j <= MAX; j += i+i) SetComp(j);prime[sz++]=2;for (int i=3; i <= MAX; i += 2)if (!IsComp(i))prime[sz++]=i;}
//ll phi[5000001];bool mark[5000001];void sievephi(ll n){ll i,j;for(ll i=1;i<=n;i++) phi[i]=i;mark[1]=true;for(ll i=2;i<=n;i++)if(!mark[i]){for(ll j=i;j<=n;j+=i){mark[j]=true;phi[j]=phi[j]/i*(i-1);}}}

/*speedup
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/
// vule geli coilbi na dada cout << fixed << setprecision(6) << pi <<" "<<npi<<endl;
//Pattern? OEIS
// prime factorize?? think about 2

vector<int>v;
int a[200003];

void solve()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int ans=0;
    int k = a-c;
    int l= d-b;
    int n= a-b;
    int m= c-d;
    if(a==c && b==d) ans=0;
    else if(l==k || n == m || abs(a-c)+abs(b-d)<=3 ) ans=1;
    else if(abs(n-m)<=3) ans=2;
    else if(abs(l-k)%2)
    {
        if(abs(l-k)>3)
            ans=3;
        else ans=2;
    }
    else if(abs(l-k)%2==0) ans=2;
    cout<<ans<<endl;
}

int main()
{

         solve();

    return 0;
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
//#define mod 998244353
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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<class T> inline void out(T a){ cout << a << '\n'; }
void YN(bool ok){if(ok) cout << "Yes" << endl; else cout << "No" << endl;}
//void YN(bool ok){if(ok) cout << "YES" << endl; else cout << "NO" << endl;}

const ll INF=1e18;
const int mx=200005;
//zone

ll a[502][502];
ll b[502][502];

ll dp[502][502];
int main(){
    //オーバーフローは大丈夫ですか？？
    cin.tie(0);ios::sync_with_stdio(false);
    ll R,C;
    cin>>R>>C;
    rep(i,R)rep(j,C-1) cin>>a[i][j];
    rep(i,R-1)rep(j,C) cin>>b[i][j];
    rep(i,R)rep(j,C) dp[i][j]=INF;
    dp[0][0]=0;
    priority_queue<pair<ll,P>,V<pair<ll,P>>,greater<pair<ll,P>>> que;
    que.push({0,{0,0}});
    while(que.size()){
        pair<ll,P> p=que.top();
        que.pop();
        int i=p.sc.ft;
        int j=p.sc.sc;
        if(dp[i][j]<p.ft) continue;
        if(j+1<C){
            if(chmin(dp[i][j+1],dp[i][j]+a[i][j])){
                que.push({dp[i][j+1],{i,j+1}});
            }
        }
        if(j-1>=0){
            if(chmin(dp[i][j-1],dp[i][j]+a[i][j-1])){
                que.push({dp[i][j-1],{i,j-1}});
            }
        }
        if(i+1<R){
            if(chmin(dp[i+1][j],dp[i][j]+b[i][j])){
                que.push({dp[i+1][j],{i+1,j}});
            }
        }
        for(int k=0;k<i;k++){
            if(chmin(dp[k][j],dp[i][j]+(ll)i-k+1)){
                que.push({dp[k][j],{k,j}});
            }
        }
        //cout<<i<<' '<<j<<endl;
    }
    out(dp[R-1][C-1]);
}
//E
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！
//添字注意！！(特に多重ループのとき)

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

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
//#define int long long
#define INF 1e18
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<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;

Graph G;
int n, d[250010];

// <最短距離, 頂点の番号>
using P = pair<int, int>;

void dijkstra(int s)
{
    priority_queue<P, vector<P>, greater<P>> que;
    fill(d, d + n, INF);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty())
    {
        P p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] < p.first)
            continue;

        for (int i = 0; i < G[v].size(); ++i)
        {
            Edge e = G[v][i];
            if (d[e.first] > d[v] + e.second)
            {
                d[e.first] = d[v] + e.second;
                que.push(P(d[e.first], e.first));
            }
        }
    }
}

int a[510][510];
int b[510][510];
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int r,c;
    cin>>r>>c;
    n=r*c;
    G.assign(r*c , vector<Edge>());
    for (int i = 0; i < r; i++)
    {
        for (int j = 0; j < c-1; j++)
        {
            cin>>a[i][j];
        }

    }
    for (int i = 0; i < r-1; i++)
    {
        for (int j = 0; j < c; j++)
        {
            cin>>b[i][j];

        }

    }

    for (int i = 0; i < r; i++)
    {
        for (int j = 0; j < c; j++)
        {

            if(j<c-1) G[c*i + j].push_back({c*i+j+1, a[i][j]});
            if(j>=1) G[c*i + j].push_back({c*i+j-1, a[i][j-1]});
            if(i<r-1) G[c*i + j].push_back({c*(i+1)+j, b[i][j]});
        }

    }
    for (int i = 0; i < r; i++)
    {
        for (int j = 0; j < c; j++)
        {
            for (int k = 1; k < r; k++)
            {
                if(i - k < 0 ) continue;
                G[c*i+j].push_back({c*i+j - c*k , 1 + k});
            }

        }

    }
    dijkstra(0);
    cout<<d[r*c-1]<<endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll LINF = 1e18;
const int INF = 1e9;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).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;
}
// Union-Find
struct UnionFind
{
  vector<int> par, siz;

  UnionFind(int n) : par(n, -1), siz(n, 1) {}

  // �������
  int root(int x)
  {
    if (par[x] == -1)
      return x;
    else
      return par[x] = root(par[x]);
  }

  // x �� y ��Ʊ�����롼�פ�°���뤫�ɤ��� (�������פ��뤫�ɤ���)
  bool issame(int x, int y)
  {
    return root(x) == root(y);
  }

  // x ��ޤ॰�롼�פ� y ��ޤ॰�롼�פȤ�ʻ�礹��
  bool unite(int x, int y)
  {
    x = root(x), y = root(y);
    if (x == y)
      return false;
    if (siz[x] < siz[y])
      swap(x, y);
    par[y] = x;
    siz[x] += siz[y];
    return true;
  }

  // x ��ޤ॰�롼�פΥ�����
  int size(int x)
  {
    return siz[root(x)];
  }
};

int main()
{
  ll N;
  cin >> N;
  unordered_map<string, int> a(N);
  vector<string> b(N);
  for (int i = 0; i < N; i++)
  {
    string temp;
    cin >> temp;
    a[temp]=1;
    b[i] = temp;
  }
  for (int i = 0; i < N; i++)
  {
    if(a['!'+b[i]]!=0){
      cout << b[i] << endl;
      return 0;
    }
  }
  cout << "satisfiable" << endl;
}

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

//using namespace __gnu_pbds;
using namespace std;

//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_set;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ii pair<int, int>
#define fi first
#define se second
#define int long long
#define endl '\n'
#define mp make_pair
#define pb push_back
#define v1 v<<1
#define v2 (v<<1)|1
//__builtin_popcountll(x) : Number of 1-bit
//__builtin_ctzll(x) : Number of trailing 0
const int inf = (int)1e9;
const int mod = (int)1e9 + 7;
int dx[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int dy[30];
int cal(string s){
	int sum = 0LL;
	for (int i = 0; i < s.size(); i++){
		sum = sum * 10LL + dx[dy[s[i] - 'a']];
	}
	return sum;
}
bool ok(string s){
    return dx[dy[s[0]-'a']]!=0;
}

void print(string s){
    for(int i=0;s[i];i++)putchar(dx[dy[s[i]-'a']]+'0');
    putchar('\n');
}
clock_t t1,t2;

string s[4];
signed main()
{
	// freopen(".inp","r",stdin);
    // freopen(".out","w",stdout);
	fastio
	int cnt = 0, a[30], len[4], b[30];
	cin >> s[1] >> s[2] >> s[3];
	for (int i = 1; i <= 3; i++) len[i] = s[i].size();
	set<int> x;
	for (int i = 1; i <= 3; i++){
		for (int j = 0; j < len[i]; j++){
			x.insert(s[i][j]);
		}
	}
	if(x.size() > 10){
		cout << "UNSOLVABLE";
		return 0;
	}
	for (auto i : x){
		dy[i - 'a'] = cnt;
		cnt++;
	}
//	cout << cal(s[1]) << cal(s[2]) << ok(s[1]) << ok(s[2]);
	do{
		int m = cal(s[1]), m1 = cal(s[2]), m2 = cal(s[3]);
		if(m + m1 == m2 && ok(s[1]) && ok(s[2]) && ok(s[3])){
			print(s[1]);
			print(s[2]);
			print(s[3]);
			return 0;
		}
	}
	while(next_permutation(dx, dx + 10));
	cout << "UNSOLVABLE";
	return 0;

}


#include<iostream>
#include<cstring>
#include<algorithm>
#include<map>
#include<cstring>
using namespace std;
const int N=1e6+10,mod=998244353;
typedef long long LL;
int a[20]={0,1,2,3,4,5,6,7,8,9};
map<char,int>mp;
long long get_num(char s[]){
	if(a[mp[s[1]]]==0)return -1;
	int len=strlen(s+1);
	long long ans=a[mp[s[1]]];
	for(int i=2;i<=len;i++){
		ans*=10;
		ans+=a[mp[s[i]]];
	}
	return ans;
}
char s1[N],s2[N],s3[N];
int check(){
	long long num1=get_num(s1);
	long long num2=get_num(s2);
	long long num3=get_num(s3);
	if(num1==-1||num2==-1||num3==-1)return 0;
	return (num1+num2==num3);
}
int tot=0;
int main(){
	scanf("%s%s%s",s1+1,s2+1,s3+1);
	for(int i=1;i<=strlen(s1+1);i++){
		if(!mp.count(s1[i])){
			mp[s1[i]]=tot++;
		}
	}
	for(int i=1;i<=strlen(s2+1);i++){
		if(!mp.count(s2[i])){
			mp[s2[i]]=tot++;
		}
	}
	for(int i=1;i<=strlen(s3+1);i++){
		if(!mp.count(s3[i])){
			mp[s3[i]]=tot++;
		}
	}
	if(mp.size()>10)puts("UNSOLVABLE");
	else{
		int flag=0;
	do{
		if(check()){
			flag=1;
			break;
		}
	}
	while(next_permutation(a,a+10));
	if(flag){
		cout<<get_num(s1)<<endl;
		cout<<get_num(s2)<<endl;
		cout<<get_num(s3);
	}else{
		puts("UNSOLVABLE");
	}
	}
	return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;
using LD = long double;

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; }
template <typename T> void coutall(T v) { for(auto i = v.begin(); i != --v.end(); i++){cout << *i << " ";} cout << *--v.end() << endl; }
void yes(bool ok = true){ cout << (ok ? "yes" : "no") << endl; }
void Yes(bool ok = true){ cout << (ok ? "Yes" : "No") << endl; }
void YES(bool ok = true){ cout << (ok ? "YES" : "NO") << endl; }
ll myceil(ll a, ll b) { return (a + (b - 1)) / b; }

void Main(){
    int n; cin >> n;
    vi x(n), y(n);
    rep(i, n) cin >> x[i] >> y[i];
    int cnt = 0;
    rep(i, n-1){
        rep3(j, i+1, n-1){
            // -1 <= y[j] - y[i] / x[j] - x[i] <= 1
            if(abs(y[j] - y[i]) <= abs(x[j] - x[i])) cnt++;
        }
    }

    cout << cnt << endl;
    return;
}

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


#include<bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define rep(i,n) for(int(i)=0;(i)<(int)(n);++(i))
#define v vector
#define r return
/*
	Do-while:do {
	} while();
	endif:#ifndef
	#endif
*/
using namespace std;
typedef long long ll;
string ss,st,tt,ts,s,t;
ll b,c,d,n,m,q,k;
struct pc{
	int ddd,ffg,eheu;
};
v<int> w;
const int maxn=1000005;
ll a[maxn];
double fd;
bool fl1,fl2,fl3,fl;
signed main(){
	cin>>n>>q;
	rep(i,n){
		cin>>a[i];
		a[i]-=i;
	}
	while(q--){
		cin>>k;
		cout<<k+upper_bound(a,a+n,k)-a<<"\n";
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define Rep(i,n) for(int i=0;i<=(int)n;i++)
const ll mod = 1e9+7 ;
const ll INF = 1e18 ;
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 ;}

int main(){
    ll n, q;
    cin >> n >> q;
    vector<ll> a(n);
    rep(i,n) cin >> a.at(i);
    vector<pair<ll,ll>> b(n + 1);
    ll pos = 0;
    rep(i,n) {
        b.at(i).second = pos;
        b.at(i).first = a.at(i) - pos - 1;
        pos = a.at(i);
    }
    b.at(n).second = a.at(n - 1);
    for(int i = 1; i < n + 1; i++) {
        b.at(i).first += b.at(i - 1).first;
    }
    rep(i,q) {
        ll k;
        cin >> k;
        ll l = -1;
        ll r = n + 1;
        ll mid;
        while(l + 1 < r) {
            mid = (l + r) / 2;
            if(b.at(mid).first >= k) r = mid;
            else l = mid;
        }
        if(r == 0) {
            cout << k << endl;
            continue;
        }
        if(r == n + 1) {
            cout << a.at(n - 1) + k - b.at(n).first << endl;;
            continue;
        }
        cout << b.at(r).second + k - b.at(r - 1).first << endl;
    }
}


#include<iostream>
#include<vector>
#include<string>
using namespace std;
using LL = long long;

int main(){
    int H, W;
    cin >> H >> W;
    vector<string> field;
    for (int i = 0; i < H; i++){
        string si;
        cin >> si;
        field.emplace_back(si);
    }

    vector<vector<int>> diag; //0:R, 1:B, 2:.
    for (int i = 0; i < H+W-1; i++){
        vector<int> a = {0,0,0};
        diag.emplace_back(a);
    }
    for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
        char s = field[i][j];
        if (s == 'R'){
            diag[i+j][0] += 1;
        } else if(s == 'B'){
            diag[i+j][1] += 1;
        } else {
            diag[i+j][2] += 1;
        }
    }}
    LL pat = 1;
    for (vector<int> v: diag){
        int rn = v[0], bn = v[1], dn = v[2];
        if (rn*bn != 0){
            cout << 0 << endl;
            return 0;
        } else if(rn == 0 && bn == 0 && dn != 0){
            pat = (pat*2)%998244353;
        }
    }
    cout << pat << endl;

}

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

int main()
{
    int N,M;
    int x,y;
    vector<string> A;
    char dna[20][20];

    cin >> N >> M;

    for(int i=0; i<M; i++) {
        string a;
        cin >> a;

        bool iscontain=false;
        for( int j=0; j<A.size(); j++)
            if(A[j].find(a)!=string::npos) {iscontain=true;break;}
        if(iscontain!=true) A.push_back(a);
    }

    bool convine=true;

    while(convine) {
        convine=false;
        for(int i=0; i<A.size(); i++) {
            if(A[i].size()>2){
                string b=A[i].substr(A[i].size()-2);
                for(int j=0; j<A.size(); j++) {
                    if( i==j ) continue;
                    if( A[j][0]==b[0] && A[j][1]==b[1] ){
                        if( A[i].size()+A[j].size()-2 <= N) {
                            A[i] = A[i] + A[j].substr(2);
                            A[j] ="";
                            convine=true;
                            break;
                        }
                    }
                }
            }
        }
    }

    convine=true;

    while(convine) {
        convine=false;
        for(int i=0; i<A.size(); i++) {
            if(A[i].size()>2 && A[i].size()<N){
                for(int j=0; j<A.size(); j++) {
                    if( i==j ) continue;
                    if( (A[j].size() > 2) && ((A[i].size()+A[j].size()) <= N) ){
                        A[i] = A[i] + A[j];
                        A[j] ="";
                        convine=true;
                        break;
                    }
                }
            }
        }
    }

    for(int i=0; i<N; i++){
        int max=A[i].size();
        int maxj=i;
        for(int j=i; j<A.size(); j++){
            if(A[j].size()>max) {
                max=A[j].size();
                maxj=j;
            }
        }
        if( i!=maxj){
            string tmp;
            tmp=A[maxj];
            A[maxj]=A[i];
            A[i]=tmp;
        }
    }

    for(int i=0; i<N; i++) {
        if(A[i].size() < 20) A[i]+="....................";
    }

    for(int i=0; i<N; i++) {
        cout << A[i].substr(0,20) << endl;
    }
};


#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_N = 100005;
vector<int> G[MAX_N];
int dp[MAX_N][2]; // 0:f(v) 1:size

void dfs(int n)
{
	if (G[n].size() == 0)
	{
		dp[n][0] = 1;
		dp[n][1] = 1;
		return;
	}
	vector<P> v1,v2,v3;
	int f = 1, s = 1;
	rep(i,G[n].size())
	{
		int c = G[n][i];
		dfs(c);
		if (dp[c][1] % 2 == 0 && dp[c][0] < 0)
		{
			f += dp[c][0];
			s += dp[c][1];
		}
		else if (dp[c][1] % 2 == 0)
		{
			v2.push_back(P(dp[c][0],dp[c][1]));
		}
		else
		{
			v3.push_back(P(dp[c][0],dp[c][1]));
		}
	}

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

	int sign = 1;
	rep(i,v3.size())
	{
		f += sign*v3[i].first;
		s += v3[i].second;
		sign *= -1;
	}

	rep(i,v2.size())
	{
		f += sign*v2[i].first;
		s += v2[i].second;
	}

	dp[n][0] = f;
	dp[n][1] = s;
	return;
}

int main()
{
	int N;
	cin >> N;
	rep(i,N-1)
	{
		int p;
		cin >> p;
		p--;
		G[p].push_back(i+1);
	}

	dfs(0);
	/*
	rep(i,N)
	{
		cout << dp[i][0] << " " << dp[i][1] << endl;
	}
	*/
	cout << (dp[0][0]+N)/2 << endl;
	return 0;
}

#include <bits/stdc++.h>
// #include <atcoder/modint>
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define INF 2000000000000000000
#define ll long long
#define ld long double
#define pll pair<ll, ll>
using namespace std;
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 d{ll f, s, t;};//first, second, turn

bool comp(d a, d b) {
  if (a.t == 0 || b.t == 0) {
    return a.t > b.t;
  }
  return (a.s - a.f) > (b.s - b.f);
}

ll N;
vector<ll> p;
vector<vector<ll>> child;
d dfs(ll now, ll turn) {
  vector<ll> FS(2, 0);
  FS.at(0) += 1;
  turn = (turn + 1) % 2;
  vector<d> ds;
  for (ll i = 0; i < child.at(now).size(); ++i) {
    d temp = {1, 0, 1};
    if (child.at(child.at(now).at(i)).size() != 0) {
      temp = dfs(child.at(now).at(i), 0);
    }
    if (temp.f <= temp.s && temp.t == 0) {
      FS.at(turn) += temp.s;
      FS.at((turn + 1) % 2) += temp.f;
    }
    else {
      ds.push_back(temp);
    }
  }
  sort(rng(ds), comp);
  for (ll i = 0; i < ds.size(); ++i) {
    d temp = ds.at(i);
    FS.at(turn) += temp.s;
    FS.at((turn + 1) % 2) += temp.f;
    turn = (turn + temp.t) % 2;
  }
  // cout << "now" << now + 1 << "\n";
  // cout << FS.at(0) << ' ' << FS.at(1) << ' ' << turn << "\n";
  return {FS.at(0), FS.at(1), turn};
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> N;
  p = vector<ll>(N, -1);
  child = vector<vector<ll>>(N);
  for (ll i = 1; i < N; ++i) {
    cin >> p.at(i);
    p.at(i) -= 1;
    child.at(p.at(i)).push_back(i);
  }
  cout << dfs(0, 0).f << "\n";
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define debug(a,n) for(ll i = 0;i<n;i++) cout<<a[i]<<" ";
#define sum(a,n,s) for(ll i = 0;i<n;i++) s+=a[i];
#define scan(a,n) for(ll i = 0;i<n;i++) cin>>a[i];
ll counter=0;
vector <ll>  SieveOfEratosthenes(ll n)
{
    vector <ll> ans;
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {

            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }

    // Print all prime numbers
    for (int p=2; p<=n; p++)
       if (prime[p])
            ans.push_back(p);
    return ans;
}
vector <ll> sievo(ll N)
{
    ll lp[N+1];
    vector<ll> pr;
    memset(lp,0,sizeof lp);
    for (ll i=2; i<=N; ++i) {
        if (lp[i] == 0) {
            lp[i] = i;
            pr.push_back (i);
        }
        for (ll j=0; j<(ll)pr.size() && pr[j]<=lp[i] && i*pr[j]<=N; ++j)
            lp[i * pr[j]] = pr[j];
    }

    return pr;
}
long long compute_hash(string s) {
    const int p = 31;
    const int m = 1e9 + 9;
    long long hash_value = 0;
    long long p_pow = 1;
    for (char c : s) {
        hash_value = (hash_value + (c - 'a' + 1) * p_pow) % m;
        p_pow = (p_pow * p) % m;
    }
    return hash_value;
}
ll power(ll x, unsigned ll y, ll p)
{
    ll res = 1;     // Initialize result

    x = x % p; // Update x if it is more than or
                // equal to p

    if (x == 0) return 0; // In case x is divisible by p;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}
vector<int> rabin_karp(string const& s, string const& t) {
    const int p = 31;
    const int m = 1e9 + 9;
    int S = s.size(), T = t.size();

    vector<long long> p_pow(max(S, T));
    p_pow[0] = 1;
    for (int i = 1; i < (int)p_pow.size(); i++)
        p_pow[i] = (p_pow[i-1] * p) % m;

    vector<long long> h(T + 1, 0);
    for (int i = 0; i < T; i++)
        h[i+1] = (h[i] + (t[i] - 'a' + 1) * p_pow[i]) % m;
    long long h_s = 0;
    for (int i = 0; i < S; i++)
        h_s = (h_s + (s[i] - 'a' + 1) * p_pow[i]) % m;

    vector<int> occurences;
    for (int i = 0; i + S - 1 < T; i++) {
        long long cur_h = (h[i+S] + m - h[i]) % m;
        if (cur_h == h_s * p_pow[i] % m)
            occurences.push_back(i);
    }
    return occurences;
}
ll check(vector <ll> &arr,ll l, ll n)
{

    if(arr[0]<0||arr[n-1]<0)
    {
        return 0;
    }
    if(n==1)
    {
        return arr[l]==0;
    }
    arr[l+1]-= arr[l];
    if(arr[l+1]<0)
    {
        arr[l+1]+=arr[l];
        return 0;
    }

    ll ans = check(arr,l+1,n-1);
    arr[l+1]+=arr[l];
    return ans;
}
vector <ll> precompute(vector <ll> arr,ll n)
{
    vector <ll> ans(n);
    ans[0] = arr[0];
    for(ll i = 1;i<n;i++)
    {
        ans[i] = arr[i]-ans[i-1];
    }
    ll i=0;
    for(i =0;i<n;i++)
    {
        if(ans[i]<0)
        {
            ans[i]=-1;
            break;
        }
    }
    while(i<n)
    {
        ans[i++]=-1;
    }
    return ans;
}
void solve()
{
    ll k;cin>>k;
    ll arr[k+10];
    memset(arr,0,sizeof arr);
    for(ll i = 1;i<=k;i++)
    {
        for(ll j = i;j<=k;j+=i)
        {
            arr[j]++;
            // arr[]
        }
    }
    ll count = 0;
    for(ll i = 1;i<=k;i++)
    {
        count+= arr[i]*(k/i);
    }
    cout<<count<<endl;
    return;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t =1;
    // cin>>t;
    while(t--)
    {

        solve();
    }
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b)  for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n)    FOR(i,0,n)
#define ALL(a)      a.begin(),a.end()
#define vi          vector<int>
#define vvi         vector<vi>
#define P           pair<int,int>
#define vP          vector<P>
#define vvP         vector<vP>

using ll = long long int;

int main(){
    int K;cin>>K;
    ll res=0;
    FOR(i,1,K+1){
        FOR(j,1,K+1){
            if(i*j>K)break;
            res += K/i/j;
        }
    }
    cout<<res<<endl;
    return 0;
}


// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<random>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
typedef vector<vt>vvt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const long double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

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

	int n,m;
	cin>>n>>m;
	vvi G(n,vi(n));
	rep(i,m){
		int a,b;
		cin>>a>>b;
		a--;b--;
		G[a][b]=G[b][a]=1;
	}
	int N=1<<n;
	vi dp(N,inf);
	dp[0]=0;
	rep(i,N){
		for(int j=i;j>0;j=(j-1)&i){
			cmin(dp[i],dp[j]+dp[i-j]);
		}
		bool h=true;
		rep(j,n)rep(k,n)if(k-j&&(i&1<<j)&&(i&1<<k)&&G[j][k]==0)
			h=false;
		if(h)dp[i]=1;
	}
	cout<<dp.back()<<endl;
}

#include <bits/stdc++.h>
//#include "debugger.h"
#define int long long
#define pb push_back
#define pp pop_back
#define f first
#define s second
#define all(x) x.begin(),x.end()
using namespace std;

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

	int n;
	cin >> n;

	string s;
	cin >> s;

	int q;
	cin >> q;

	int flag = 0;
	while (q--) {
		int t, a, b;
		cin >> t >> a >> b;

		if (t == 1) {
			if (flag) {
				a -= 1;
				b -= 1;
				if (a >= n)	a = a - n;
				else 		a = a + n;

				if (b >= n)	b = b - n;
				else 		b = b + n;

				swap(s[a], s[b]);
			}
			else {
				swap(s[a - 1], s[b - 1]);
			}
		}
		else {
			flag = 1 - flag;
		}
		// cout << s << "\n";
	}

	if (flag)
		s = s.substr(n) + s.substr(0, n);

	cout << s;

	return 0;
}


#include<bits/stdc++.h>
#define MOD 1000000007
#define MAX 1000
using namespace std;
int a[MAX+10],b[MAX+10],dp[MAX+10][MAX+10];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;++i)
		cin>>a[i];
	for(int i=1;i<=m;++i)
		cin>>b[i];
	for(int i=0;i<=n;++i)
	{
		for(int j=0;j<=m;++j)
		{
			if(i==0)
				dp[i][j] = j;
			else if(j==0)
				dp[i][j] = i;
			else dp[i][j] = min({dp[i-1][j-1]+(int)(a[i]!=b[j]),dp[i-1][j]+1,dp[i][j-1]+1});
		}
	}
	cout<<dp[n][m]<<endl;
	return 0;
}

/*/ Author: _Math.man /*/

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

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

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

template<typename T, typename... Args>
inline void __trace(vector<string>::iterator it, T a, Args... args) {
    cerr << it->substr((*it)[0] == ' ', it->length()) << "=";
    __trace_out_var(a);
    cerr << "; ";
    __trace(++it, args...);
}
/*/-----------------------------Code begins----------------------------------/*/
int ar[N],br[N];
int dp[N][N];
int n,m;
int solve(int i,int j){
    if(i==n){
        return m-j;
    }
    if(j==m){
        return n-i;
    }
    if(dp[i][j]!=-1)return dp[i][j];
    int ans = INF;
    ans=min(ans,(ar[i]!=br[j]?1:0) + solve(i+1,j+1));
    ans=min(ans,1+solve(i+1,j+1));
    ans=min(ans,1+min(solve(i+1,j),solve(i,j+1)));
    return dp[i][j]=ans;
}
signed main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    IOS;
    int T=1;
    // cin >> T;
    while(T--){
        cin >> n >> m;
        fn{
            cin >> ar[i];
        }
        fm{
            cin >>br[j];
        }
        memset(dp,-1,sizeof(dp));
        cout << solve(0,0);

    }
    return 0;
}


#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using tii = tuple<int,int,int>;
template<typename T>bool chmin(T&x,const T&y) {if(x>y){x=y;return 1;} else return 0;}
template<typename T>bool chmax(T&x,const T&y) {if(x<y){x=y;return 1;} else return 0;}

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

vector<int> makeDivisors(int n) {
    vector<int> ret;
    for(int i = 1; i * i <= n; i++) {
        if(n%i == 0) {
            ret.push_back(i);
            if(i*i != n) ret.push_back(n/i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    unordered_map<int, int> mp;
    auto add = [&](int a, int b) {
        int p = mp[b];
        mp[b] = gcd(p, a);
    };
    int l = INT_MAX;
    rep(i, N) {
        vector<int> B = makeDivisors(A[i]);
        for (int b : B) {
            add(A[i], b);
        }
        chmin(l, A[i]);
    }
    ll ans = 0;
    for (auto [k, v] : mp) {
        if (k <= l && k == v) ans++;
    }
    cout << ans << '\n';
    return 0;
    // get dp together, ll, paraphrase, debug
}

//

#include<iostream>
using namespace std;

long int max(long int a,long int b)
{
 if(a>=b) return a;
 else return b;
}

long int min(long int a,long int b)
{
 if(a>=b) return b;
 else return a;
}

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

int main()
{
 int N;
 cin >> N;
 long int ans;
 for(int i=0;i<N;i++){
     long int a_i;
     cin >> a_i;
     if(i==0){
         ans = a_i;
     }
     else{
         ans = gcd(max(a_i,ans),min(a_i,ans));
     }
 }

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


#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
#include<cstring>
#include<map>
#include<set>
#include<cstdlib>
#include<bitset>
using namespace std;
#define FAST ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
typedef long long ll;
#define N 200005
ll p=1e9+7;
ll n,m,f[N][17][17]={0},v[22]={0},sm;
char a[N];
int main()
{
	ll i,j,k,a1,a2,an=0;
	scanf("%s",a+1);
	n=strlen(a+1);
	for(ll i=1;i<=n;i++)
		if(a[i]>='0'&&a[i]<='9')
			a[i]-='0';
		else
			a[i]-='A'-10;
	scanf("%lld",&m);
	for(ll i=0;i<=m;i++)
		f[0][i][i]=1;
	for(ll i=1;i<=n;i++)
		for(ll j=1;j<=m;j++)
			for(ll k=j;k<=m;k++)
				f[i][j][k]=((ll)f[i-1][j][k-1]*(17ll-k)+(ll)f[i-1][j][k]*k)%p;
	for(ll i=1;i<=n;i++)
		an=(an+15ll*f[i-1][1][m])%p;
	// for(ll i=1;i<=n;i++)
	// {
	// 	for(ll j=1;j<=m;j++)
	// 		for(ll k=j;k<=m;k++)printf("%lld\n",f[i][j][1]);
	// }
	for(ll i=1;i<=n;i++)
	{
		for(ll j=a[i]+1;j<=15;j++)
			an=(an-f[n-i][sm+(!v[j])][m]+p)%p;
		//printf("%lld\n",an);
		sm+=!v[a[i]];
		v[a[i]]=1;
	}
	printf("%lld",an);
}

#include <iostream>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
using namespace std;

using VLL = vector <long long>;
using VVLL = vector <VLL>;

int main() {
    int N;
    int K;
    long long M;
    cin >> N >> K >> M;

    VVLL dp(N+1, VLL(N*N*K));
    dp[0][0] = 1;
    int theMax = 0;

    for (int n = 1; n <= N; ++n) {
        theMax += K*n;

        for (int k = 0; k <= theMax; ++k) {
            // dp[i][val] = Sigma i = 0 ... K dp[i-1][val-i*n] = dp[i-1][val] + dp[i][val-n] - dp[i-1][val-n*(K+1)];
            dp[n][k] = dp[n-1][k];

            if (k-n >= 0) {
                dp[n][k] += dp[n][k-n];
            }

            if (k-n*(K+1) >= 0) {
                dp[n][k] -= dp[n-1][k-n*(K+1)];
            }

            dp[n][k] %= M;
        }
    }

    for (int n = 1; n <= N; ++n) {
        int left = n-1;
        int right = N-n;

        long long ans = K;

        if (left != 0 && right != 0) {
            for (int v = 1; v <= theMax; ++v) {
                ans += dp[left][v] * dp[right][v] % M * (K+1) % M;
            }
        }

        ans = (ans%M + M) % M;

        cout << ans << endl;
    }

    return 0;
}


/* Problem name : A - i Scream
Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 100 points

Problem Statement
In Japan, there are four major categories of ice cream type products:

an ice cream type product with at least 15 percent milk solids and at least 8 percent milk fat is called an ice cream;
an ice cream type product with at least 10 percent milk solids and at least 3 percent milk fat that is not an ice cream is called an ice milk;
an ice cream type product with at least 3 percent milk solids that is not an ice cream or an ice milk is called a lacto ice;
an ice cream type product that is not an ice cream, an ice milk, or a lacto ice is called a flavored ice.
Here, milk solids consists of milk fat and milk solids-not-fat.

AtCoder's famous product Snuke Ice contains A percent milk solids-not-fat and B percent milk fat.

Which of the categories above does Snuke Ice fall into?

Print your answer as an integer according to the Output section.

Constraints
0≤A≤100
0≤B≤100
A+B≤100
A and B are integers.
*/
# include <cstdio>
using namespace std;
int a,b;
int main()
{
	scanf("%d %d",&a,&b);
	a += b;
	if (a >= 15 && b >= 8) printf("1");
	else if (a >= 10 && b >= 3) printf("2");
	else if (a >= 3) printf("3");
	else printf("4");
	return 0;
}

#include <bits/stdc++.h>

#define fi first
#define se second
#define pp pop_back
#define ll long long
#define pb push_back
#define ld long double
#define debug cout << "OK\n";
#define all(x) x.begin(), x.end()

using namespace std;

const int N = 5e5 + 200;
const int mod = 1e9 + 7;
const int mod2 = 998244353;

void usaco(string filename) {
  	freopen((filename + ".in").c_str(), "r", stdin);
	freopen((filename + ".out").c_str(), "w", stdout);
}
void data()
{
	#ifdef NURS
        freopen("main.in", "r", stdin);
        freopen("main.out", "w", stdout);
    #endif
}

main()
{
	data();
	int a, b;
	cin >> a >> b;
	cout << max(0, a * 2 + 100 - b);
}

/*
test
5
1 2 3 2 1
*/


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

using namespace std;

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
// change
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
// math
template <class T>
inline T sqr(T x) {
  return x * x;
}

template <class T>
inline T nCr(T n, T r) {
  T num = 1;
  for (int i = 1; i <= r; ++i) {
    num *= (n - i + 1) / i;
  }
  return num;
}
template <class T>
inline T nPr(T n, T r) {
  r = n - r;
  T sum = 1;
  int i;
  for (i = n; i >= r + 1; --i) sum *= i;
  return sum;
}

template <class T>
inline T facctorial(T k) {
  T sum = 1;
  for (int i = 1; i <= k; ++i) {
    sum *= i;
  }
  return sum;
}
// numeric
template <class T>
inline T gcd(T a, T b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }

  return b ? gcd(b, a % b) : a;
}

template <class T>
inline T lcm(T a, T b) {
  return a * b / gcd(a, b);
}
// typedef
using VI = vector<int>;
using VVI = vector<VI>;
using VS = vector<string>;
using PII = pair<int, int>;
using LL = int64_t;

// container util
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) static_cast<int>((a).size())
#define EACH(i, c) \
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())

// repetition
#define FOR(i, a, b) for (int i = (a); i <= static_cast<int>(b); ++i)
#define REP(i, n) FOR(i, 0, n)

// constant
constexpr double EPS = 1e-10;
const double PI = acos(-1.0);
constexpr LL INF = 1e10;

// clear memory
#define CLR(a) memset((a), 0, sizeof(a))

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

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, s, d;
  cin >> n >> s >> d;
  vector<PII> p(n);
  VI x(n), y(n);
  REP(i, n) { cin >> p[i].first >> p[i].second; }
  sort(ALL(p));
  REP(i, n) {
    if (p[i].first < s && p[i].second > d) {
      cout << "Yes"
           << "\n";
      return 0;
    }
  }
  cout << "No"
       << "\n";
  return 0;
}

#include <bits/stdc++.h>

using namespace std;
#define ll long long
typedef pair<ll,ll> ii;
const ll inf=1e15;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n,tot,nextVil=-1;
    priority_queue<ii,vector<ii>,greater<ii>> pq;
    cin>>n>>tot;
    ll a,b;
    for (int i=0;i<n;i++){
        cin>>a>>b;
        pq.push(make_pair(a,b));
    }
    ll y=0; // b is yen friend gives
    ll cnt=0;
    while (cnt<n && tot>=nextVil){
        tot+=y;
        nextVil=pq.top().first;
        y=pq.top().second;
        pq.pop();
        cnt++;
    }
    cout<<tot+((tot>=nextVil)?y:0);

    return 0;
}


#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
const int INF = 1e9;
const ll LINF = 1e18;
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;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    for (int i = 0; i < int(v.size()); i++) {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    for (int i = 0; i < int(v.size()); i++) {
        os << v[i];
        if (i < sz(v) - 1) os << ' ';
    }
    return os;
}

const int n = 50;
const vector<int> dy = {0, 0, -1, 1};
const vector<int> dx = {-1, 1, 0, 0};
int t[n][n], p[n][n];
string dirs = "LRUD";
struct P {
    int y, x;
    char dir;
    P() {
    }
    P(int _y, int _x) : y(_y), x(_x) {
    }
    P(int _y, int _x, char _dir) : y(_y), x(_x), dir(_dir) {
    }
    bool valid() {
        return 0 <= x and x < n and 0 <= y and y < n;
    }
    vector<P> nxt(bitset<2500>& used) {
        vector<P> ret;
        rep(d, 4) {
            int ny = y + dy[d];
            int nx = x + dx[d];
            if (P(ny, nx).valid() and !used[t[ny][nx]]) {
                ret.emplace_back(ny, nx, dirs[d]);
            }
        }
        return ret;
    }
};
int check(P pos, bitset<2500>& used, int dep, int limit = 4) {
    if (dep == limit) return dep;
    int ret = 0;
    used[t[pos.y][pos.x]] = 1;
    for (P nxt : pos.nxt(used)) {
        chmax(ret, check(nxt, used, dep + 1, limit));
    }
    used[t[pos.y][pos.x]] = 0;
    return ret;
}
random_device seed_gen;
mt19937_64 rnd(seed_gen());
int main() {
    clock_t start = clock();
    auto tm = [&]() {
        return static_cast<double>(double(clock() - start) / CLOCKS_PER_SEC *
                                   1000.0);
    };
    auto random_coice = [&](vector<P>& v) -> P {
        int idx = uniform_int_distribution<int>(0, sz(v) - 1)(rnd);
        return v[idx];
    };

    int sy, sx;
    cin >> sy >> sx;
    rep(i, n) rep(j, n) cin >> t[i][j];
    rep(i, n) rep(j, n) cin >> p[i][j];

    string ans;
    int score = 0;
    int try_cnt = 0;
    while (tm() < 1950 && ++try_cnt) {
        bitset<2500> used;
        P pos = {sy, sx};
        string cur;
        int cur_score = 0;

        while (1) {
            cur_score += p[pos.y][pos.x];
            used[t[pos.y][pos.x]] = 1;
            vector<P> nxts;
            int MAX = -1;
            // cerr << pos.y << ' ' << pos.x << '\n';
            for (auto nxt : pos.nxt(used)) {
                int tmp = check(nxt, used, 0);
                // cerr << nxt.dir << " : " << tmp << '\n';
                if (tmp == MAX) {
                    nxts.push_back(nxt);
                } else if (chmax(MAX, tmp)) {
                    nxts.clear();
                    nxts.push_back(nxt);
                }
            }
            if (nxts.empty()) break;
            pos = random_coice(nxts);
            cur += pos.dir;
        }

        if (chmax(score, cur_score)) {
            ans = cur;
        }
    }
    cout << ans << '\n';
    cerr << "score : " << score << '\n';
    cerr << "cnt   : " << try_cnt << '\n';
}

#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <ctime>
#include <numeric>
#include <vector>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <complex>
#include <deque>
#include <functional>
#include <list>
#include <map>
#include <string>
#include <sstream>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <forward_list>
#include <thread>
#include <random>
#include <array>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
void io()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}
int main()
{
    io();
    int si,sj; cin>>si>>sj;
    int pos[50][50];
    for(int i=0; i<50; i++){
      for(int j=0; j<50; j++){
        cin>>pos[i][j];
      }
    }
    bool chek[3000];
    memset(chek,false,sizeof(chek));
    int arr[50][50];
    for(int i=0; i<50; i++){
      for(int j=0; j<50; j++){
        cin>>arr[i][j];
      }
    }
    string str="";
    chek[pos[si][sj]]=true;
    while(true){
      if(si!=49 && !chek[pos[si+1][sj]]){
        chek[pos[si+1][sj]]=true;
        si++;
        str+='D';
      }
      else if(sj!=49 && !chek[pos[si][sj+1]]){
        chek[pos[si][sj+1]]=true;
        sj++;
        str+='R';
      }
      else if(si!=0 && !chek[pos[si-1][sj]]){
        chek[pos[si-1][sj]]=true;
        si--;
        str+='U';
      }
      else if(sj!=0 && !chek[pos[si][sj-1]]){
        chek[pos[si][sj-1]]=true;
        sj--;
        str+='L';
      }
      else{
        break;
      }
    }
    cout<<str<<endl;
}
//Aneegha Thithiesha Mahabaduge.


// #undef _GLIBCXX_DEBUG
// #define NDEBUG
#include <bits/extc++.h>
using i64 = int_fast64_t;
using namespace std;

int main() {
  i64 x, y;
  cin >> x >> y;
  unordered_set<i64> usd;
  priority_queue<pair<i64, i64>, vector<pair<i64, i64>>, greater<>> q;
  q.emplace(0, y);
  i64 ans = 1e18;
  while (!q.empty()) {
    auto [c, z] = q.top();
    q.pop();
    if (usd.count(z)) continue;
    usd.emplace(z);
    ans = min(ans, abs(z - x) + c);
    if (!(z % 2)) {
      q.emplace(c + 1, z / 2);
    } else if (z > 1) {
      q.emplace(c + 2, (z + 1) / 2);
      q.emplace(c + 2, (z - 1) / 2);
    }
  }
  cout << ans << "\n";
}

#include <iostream>
using namespace std;

typedef long long ll;

#define min(x,y) ((x)<(y)?(x):(y))
#define max(x,y) ((x)<(y)?(y):(x))

ll comb(ll n, ll k){
    if (k == 0 || k == n) return 1;
    if (k == 1 || k == n-1) return n;
    return comb(n-1,k)+comb(n-1,k-1);
}

int main(){
    ll n,k;cin >> n >> k;--k;
    for(ll xyz=3;xyz<=3*n;++xyz){
        if(xyz <= n+1){
            ll s = (xyz-1)*(xyz-2)/2;
            if(s <= k){
                k -= s;
                continue;
            }
            for(ll x=1;x<=xyz-2;++x){
                ll c = xyz-1-x;
                if(c <= k){
                    k -= c;
                    continue;
                }
                ll y=1+k;
                cout << x << " " << y << " " << (xyz-x-y) << "\n";
                return 0;
            }
        }else if(xyz < 2*n+1){
            ll s = (3*n-xyz+2)*(xyz-n-1)/2;
            if(s <= k){
                k -= s;
            }else{
                for(ll x=1;x<=xyz-n-1;++x){
                    ll c = 2*n-xyz+1+x;
                    if(c <= k){
                        k -= c;
                        continue;
                    }
                    ll y=xyz-n-x+k;
                    cout << x << " " << y << " " << (xyz-x-y) << "\n";
                    return 0;
                }
            }
            s = (xyz-2)*(2*n-xyz+1)/2;
            if(s <= k){
                k -= s;
                continue;
            }
            for(ll x=xyz-n;x<=n;++x){
                ll c = xyz-1-x;
                if(c <= k){
                    k -= c;
                    continue;
                }
                ll y=1+k;
                cout << x << " " << y << " " << (xyz-x-y) << "\n";
                return 0;
            }
        }else{
            ll s = (3*n-xyz+2)*(3*n-xyz+1)/2;
            if(s <= k){
                k -= s;
                continue;
            }
            for(ll x=xyz-2*n;x<=n;++x){
                ll c = 2*n-xyz+1+x;
                if(c <= k){
                    k -= c;
                    continue;
                }
                ll y=xyz-n-x+k;
                cout << x << " " << y << " " << (xyz-x-y) << "\n";
                return 0;
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

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

#define faster ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define read freopen("in.txt", "r", stdin)
#define write freopen("out.txt", "w", stdout)
#define var(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define mem(x, n) memset(x, n, sizeof(x))
#define all(x) x.begin(), x.end()
#define endl "\n"

const int N = 1e5 + 5;

struct station
{
	ll city, time, k;
};

vector<station> g[N];
ll dist[N];

int main()
{
	faster;

	mem(dist, -1);

	ll n, m, x, y;
	cin >> n >> m >> x >> y;

	for (int i = 0; i < m; i++)
	{
		int a, b, t, k;
		cin >> a >> b >> t >> k;
		station curr, curr1;
		curr.city = b, curr.time = t, curr.k = k;
		curr1 = curr;
		curr1.city = a;
		g[a].push_back(curr);
		g[b].push_back(curr1);
	}

	priority_queue<pll,  vector<pll>,greater<pll>> pq;
	dist[x] = 0;
	// first = from, second = time
	pq.emplace(x, 0);

	while (pq.size())
	{
		auto fr = pq.top();
		pq.pop();
		if (dist[fr.first] != -1 && dist[fr.first] < fr.second)
		{
			continue;
		}

		for (auto next : g[fr.first])
		{
			ll nextStartTime = ((fr.second + next.k - 1) / next.k) * next.k;
			if (dist[next.city] == -1 || nextStartTime + next.time < dist[next.city])
			{
				dist[next.city] = nextStartTime + next.time;
				pq.emplace(next.city, dist[next.city]);
			}
		}
	}

	cout << dist[y] << endl;

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define mp(a,b) make_pair(a,b)
#define vi vector<int>
#define mii map<int,int>
#define mpi map<pair<int,int>,int>
#define vp vector<pair<int,int> >
#define pb(a) push_back(a)
#define fr(i,n) for(i=0;i<n;i++)
#define rep(i,a,n) for(i=a;i<n;i++)
#define F first
#define S second
#define endl "\n"
#define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define dom 998244353
#define pi 3.14159265
#define sl(a) (int)a.length()
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define mini 2000000000000000000
#define time_taken 1.0 * clock() / CLOCKS_PER_SEC
//mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
//primes for hashing 937, 1013
template<typename T, typename U> static inline void amin(T &x, U y)
{
    if (y < x)
        x = y;
}
template<typename T, typename U> static inline void amax(T &x, U y)
{
    if (x < y)
        x = y;
}
void shikhar7s(int cas)
{
    int n,m,x,y;
    cin>>n>>m>>x>>y;
    vector<pair<pii,pii> > adj[n+5];
    int u,v,w[m],z,i;
    fr(i,m)
    {
        cin>>u>>v>>w[i]>>z;
        adj[u].pb(mp(mp(v,i+1),mp(w[i],z)));
        adj[v].pb(mp(mp(u,i+1),mp(w[i],z)));
    }
    mpi d;
    d[mp(x,0ll)]=0;
    set<pair<int,pii> > s;
    s.insert(mp(0ll,mp(x,0ll)));
    int ans=mini;
    while(sz(s))
    {
        auto it=s.begin();
        int dis=(*it).F;
        u=(*it).S.F;
        v=(*it).S.S;
        s.erase(it);
        if(u==y&&!v)
        {
            cout<<dis;
            return;
        }
        if(v>0)
        {
            if(!d.count(mp(u,0ll))||d[mp(u,0ll)]>dis+w[v-1])
            {
                if(s.find(mp(d[mp(u,0ll)],mp(u,0ll)))!=s.end())
                    s.erase(mp(d[mp(u,0ll)],mp(u,0ll)));
                d[mp(u,0ll)]=dis+w[v-1];
                s.insert(mp(d[mp(u,0ll)],mp(u,0ll)));
            }
        }
        else
        {
            fr(i,sz(adj[u]))
            {
                v=adj[u][i].F.F;
                z=adj[u][i].S.S;
                int j=adj[u][i].F.S;
                if(!d.count(mp(v,j))||d[mp(v,j)]>dis+((z-(dis%z))%z))
                {
                    if(s.find(mp(d[mp(v,j)],mp(v,j)))!=s.end())
                        s.erase(mp(d[mp(v,j)],mp(v,j)));
                    d[mp(v,j)]=dis+((z-(dis%z))%z);
                    s.insert(mp(d[mp(v,j)],mp(v,j)));
                }
            }
        }
    }
    cout<<-1;
}
signed main()
{
    fast;
    //freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
    int t=1;
    //cin>>t;
    int cas=1;
    while(cas<=t)
    {
    shikhar7s(cas);
    cas++;
    }
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define mp make_pair
#define pb(x) push_back(x)
#define vll vector<long long>
#define pll pair<long long, long long>
#define mll map<long long, long long>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define gcd __gcd
#define clr(x) memset(x, 0, sizeof(x))
#define mod 1000000007LL
#define mod2 998244353LL
#define INF 1e18

typedef long long ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> o_tree;

void solve()
{
    ll n,m,x,y;
    cin>>n>>m>>x>>y;
    vector<vector<array<ll,3>>> v(n);
    x--,y--;
    ll i,j;
    for(i=0;i<m;i++)
    {
        ll a,b,t,k;
        cin>>a>>b>>t>>k;
        a--,b--;
        v[a].push_back({b,t,k});
        v[b].push_back({a,t,k});
    }
    priority_queue<pll,vector<pll>,greater<pll>> q;
    vll time(n,INF);
    time[x]=0;
    vll vis(n,0);
    q.push(mp(time[x],x));
    while(!q.empty())
    {
        pll topp = q.top();
        q.pop();
        if(vis[topp.second])continue;
        if(time[topp.second]!=topp.first)continue;
        vis[topp.second]=1;
        ll node = topp.second;
        ll timenow = topp.first;
        for(auto nei:v[node])
        {
            ll nowk = nei[2];
            ll nxt = nei[0];
            ll timetravel = ((timenow+nowk-1)/nowk)*nowk + nei[1];

            if(timetravel<time[nxt])
            {
                time[nxt] = timetravel;
                q.push(mp(time[nxt],nxt));
            }
        }
    }
    if(time[y]==INF)
    {
        cout<<"-1\n";
        return;
    }
    cout<<time[y]<<"\n";
}

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

if (fopen("input.txt","r" ))
  {
     freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);
  }
cout<<setprecision(20);

ll t=1;

// cin>>t;

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

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;
const int M=505;
int n;
int C[M][M];
int A[M],B[M];
int main() {
	n=read();
	rep(i,1,n)rep(j,1,n)C[i][j]=read();
	rep(i,1,n)B[i]=C[1][i];
	rep(i,1,n)A[i]=C[i][1]-B[1];
	rep(i,1,n)rep(j,1,n)if(C[i][j]!=A[i]+B[j])return puts("No"),0;
	// 现在以构造出答案，需要使他们均为非负整数
	int mi=1e9;
	rep(i,1,n)mi=min(mi,A[i]);
	if(mi>=0){
		puts("Yes");
		rep(i,1,n)printf("%d ",A[i]);puts("");
		rep(i,1,n)printf("%d ",B[i]);puts("");
	}else {
		rep(i,1,n){
			B[i]+=mi;
			A[i]-=mi;
			if(B[i]<0)return puts("No"),0;
		}
		puts("Yes");
		rep(i,1,n)printf("%d ",A[i]);puts("");
		rep(i,1,n)printf("%d ",B[i]);puts("");
	}
	return 0;
}


// Problem: A - twiblr
// Contest: AtCoder - AtCoder Beginner Contest 182
// URL: https://atcoder.jp/contests/abc182/tasks/abc182_a
// 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=1e9+7,N=1e5+5;

int solve()
{
	int n,ans=0; cin>>n;
	vi a(n); rep(i,0,n) cin>>a[i];
	px(a);
	return ans;
}
int32_t main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	//Remove incase of Online Query

	int a,b;
	cin>>a>>b;
	cout<<abs(2*a+100-b)<<endl;
}

#include <bits/stdc++.h>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define mod 998244353
//#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define bs(yup,x) binary_search(yup.begin(),yup.end(),x) //it will return bollean value
#define lb(yup,x) lower_bound(yup.begin(),yup.end(),x)  //it will return the adress of the number which is equal to or just greater than x ,and if it is equal to yup.end() than their in no such number exist
#define ub(yup,x) upper_bound(yup.begin(),yup.end(),x)
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
using namespace std;
const long long N=1000, INF=2000000000000000000;
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }
vi prime;
bool isprime[N];
void pre()
{
    for(int i=2;i<N;i++)
    {
        if(isprime[i])
        {
            for(int j=i*i;j<N;j+=i)
            isprime[j]=false;
            prime.pb(i);
        }
    }
    return;
}

int32_t main()
{

    IOS;
    //fill(isprime, true);
    //pre();
    int t=1;
    //cin>>t;
    while(t--)
    {
        pii p[1001];
        rep(i,0,1001)
        {
            p[i].ff=0;
            p[i].ss=i;
        }
        int n;
        cin>>n;
        int a[n];
        rep(i,0,n)
        {
            cin>>a[i];
            rep(j,2,1001)
            {
                if(a[i]%j==0) p[j].ff++;
            }
        }
        sort(p,p+1001);
        cout<<p[1000].ss;

    }
}


#include<bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long bigmod(long long a, long long p){
    if(p == 0){
        return 1;
    }
    long long ans = bigmod(a, p/2);
    ans = (ans * ans) % mod;
    if(p % 2 == 1){
        ans = (ans * a) % mod;
    }
    return ans;
}
long long nCr(long long n, long long r){
    if(r > n){
        return 0;
    }
    long long lob = 1, hor = 1;
    for(long long i = 1; i <= r; i++){
        lob = (lob * (n - i + 1)) % mod;
        hor = (hor * i) % mod;
    }
    hor = bigmod(hor, mod - 2);
    return (hor * lob) % mod;
}
int main(){
    long long n, m;
    cin >> n >> m;
    long long sum = 0;
    for(long long i = 1; i <= n; i++){
        long long x;
        cin >> x;
        sum += x;
    }
    cout << nCr(m + n, sum + n);
    return 0;
}

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

typedef long long ll;

ll mod_pow(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;
}

int main() {
    ll N, M, MOD = 1e9 + 7, ans = 1;
    cin >> N >> M;
    ll S = 0;
    vector<ll> A(N);
    rep(i, N) {
        cin >> A[i];
        S += A[i];
    }
    if (S > M) {
        cout << "0\n";
        return 0;
    }
    rep(i, S + N) {
        ans *= M + N - i;
        ans %= MOD;
        ans *= mod_pow(i + 1, MOD - 2, MOD);
        ans %= MOD;
    }
    cout << ans << "\n";
}


    #include "bits/stdc++.h"

    using namespace std;

    using ll = long long;
    using vll = vector<ll>;
    using vvll = vector<vector<ll>>;
    using vvvll = vector<vector<vector<ll>>>;
    using vvvvll = vector<vector<vector<vector<ll>>>>;
    using pl4 = pair<ll,ll>;
    using str = string;
    using vpl4 = vector<pair<ll,ll>>;

    #define sz size()
    #define be begin()
    #define en end()
    #define fi first
    #define se second
    #define pb push_back
    #define mp make_pair

    #define llin(x) ll (x);cin >>(x);
    #define stin(x) str (x);cin >>(x);
    #define vllin(x,n) vll (x)(n);FOR(i,0,n-1){cin >>(x)[i];}
    #define vllin2(a,b,n) vll (a)(n);vll (b)(n);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i];}
    #define vllin3(a,b,c,n) vll (a)(n);vll (b)(n);vll (c)(n);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i]>>(c)[i];}
    #define vlling(x,n) (x).assign(n,0);FOR(i,0,n-1){cin >>(x)[i];}
    #define vlling2(a,b,n) (a).assign(n,0);(b).assign(n,0);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i];}
    #define vlling3(a,b,c,n) (a).assign(n,0);(b).assign(n,0);(c).assign(n,0);FOR(i,0,n-1){cin >>(a)[i]>>(b)[i]>>(c)[i];}
    #define vpl4in(x,n) vpl4 (x)((n),mp(0,0));FOR(i,0,n-1){cin >>x[i].fi>>x[i].se;}
    #define FOR(i,a,b) for(ll i = a ; i <= b ; i++)
    #define rFOR(i,b,a) for(ll i = a; i >= b ; i--)
    #define SORT(x) sort(x.be, x.en)
    #define rSORT(x) sort(x.rbegin(), x.rend())
    #define say(x) cout<<(x);
    #define sal(x) cout<<(x)<<endl;
    #define says(x) cout<<(x)<<(' ');
    #define sas cout<<(' ');
    #define sayR(x) cout<<fixed<<setprecision(10)<<(x);
    #define salR(x) cout<<fixed<<setprecision(10)<<(x)<<endl;
    #define yn(a) cout <<((a)?"yes":"no")<<endl;
    #define Yn(a) cout <<((a)?"Yes":"No")<<endl;
    #define YN(a) cout <<((a)?"YES":"NO")<<endl;
    #define Imp(a) cout <<((a)?"Possible":"Impossible")<<endl;
    #define IMP(a) cout <<((a)?"POSSIBLE":"IMPOSSIBLE")<<endl;
    #define pow(a,b) ll(pow(a,b))

    ll MOD=1000000007;
    ll INF=100000000000001;
    vector<ll> value; // ノードの値を持つ配列
    ll N;             // 葉の数

    void update(ll i, ll x) {
        // i 番目の葉の値を x に変える
        i += N - 1; // i 番目の葉のノード番号
        value[i] = x;
        while (i > 0) {
            i = (i - 1) / 2; // ノード i の親ノードの番号に変える
            value[i] = min(value[i * 2 + 1],
                        value[i * 2 + 2]); // 左右の子の min を計算しなおす
        }
    }

    ll query(ll a, ll b, ll k, ll l, ll r) {
        // [a, b) の区間に対するクエリについて
        // ノード k （区間 [l, r) 担当）が答える
        if (r <= a || b <= l) return INF; // 区間が被らない場合は INF を返す
        if (a <= l && r <= b)
            return value[k]; // ノード k の担当範囲がクエリ区間 [a, b)
                            // に完全に含まれる
        else {
            ll c1 = query(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子に値を聞く
            ll c2 = query(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子に値を聞く
            return min(c1, c2); // 左右の子の値の min を取る
        }
    }

    ll n;
    vvll d(200001,vll(2,0));
    vvll e(200001,vll(2,0));
    vvll a(200001,vll(2,0));
    vvll c(200001,vll(0));

long long mi(long long a) {
    ll m=MOD;
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

signed main(){
    stin(s);
    FOR(i,0,s.sz-1){
        if((i%2==0&&isupper(s[i]))||(i%2==1&&!isupper(s[i]))){
            sal("No")
            return 0;
        }
    }
    sal("Yes")
}

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

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

constexpr ll INF = (1ll << 60);
constexpr ll mod = 1000000007;
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
int main(){
    ll n,m,a,b;
    cin>>n>>m>>a>>b;
    if(m*n<=b&&a*n>=b) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}


#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, j, n) for (ll i = j; i < (n); i++)
#define repr(i, j, n) for (ll i = j; i >= (n); i--)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX
#define INFL LLONG_MAX
typedef long long ll;
using namespace std;
#define MOD 1000000007

int main(){
  int n; cin >> n;
  vector<int> x(n),y(n);
  rep(i,n) cin >> x.at(i) >> y.at(i);
  bool ans = false;
  Rep(i,0,n-2){
    Rep(j,i+1,n-1){
      Rep(k,j+1,n){
        int x1 = (x.at(i)-x.at(j));
        int y1 = (y.at(i)-y.at(j));
        int x2 = (x.at(j)-x.at(k));
        int y2 = (y.at(j)-y.at(k));

        if(x1*y2==x2*y1){
          ans = true;
        }
      }
    }
  }

  if(ans==true) puts("Yes");
  else puts("No");
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,int> pi;
typedef pair<lld,lld> pl;
typedef pair<int,lld> pil;
typedef pair<lld,int> pli;
typedef vector<int> vit;
typedef vector<vit> vitt;
typedef vector<lld> vlt;
typedef vector<vlt> vltt;
typedef vector<pi> vpit;
typedef vector<vpit> vpitt;
typedef long double ld;
#define x first
#define y second
#define pb push_back
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a,b) make_pair(a,b)
bool isrange(int y,int x,int n,int m){
	 if(0<=y&&y<n&&0<=x&&x<m) return true;
	 return false;
}
int dy[4] = {1,0,-1,0},dx[4]={0,1,0,-1},ddy[8] = {1,0,-1,0,1,1,-1,-1},ddx[8] = {0,1,0,-1,1,-1,1,-1};

void solve(int tc){
	int n;
	cin >> n;
	int p = 1;
	while(true){
		if(p*(p+1)>=2*n){
			cout << p << "\n";
			break;
		}
		p++;
	}
}

int main(void){
	/*
	ios_base :: sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	*/
	int tc = 1;
	/*
		cin >> tc;
	*/
	for(int test_number=1;test_number<=tc;test_number++){
		solve(test_number);
	}
	return 0;
}

#include "bits/stdc++.h"
using namespace std ;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
void solve()
{
    long long n ;
    cin >> n ;
    vector<long long> v ;
    for(int i=1; i<=sqrt(n); i++)
    {
        if(n % i == 0)
        {
            cout << i << "\n" ;
            if(n / i != i)
                v.emplace_back(n / i) ;
        }
    }
    for(int i=v.size()-1; i>=0; i--)
        cout << v[i] << "\n" ;
}

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


#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vd = vector<double>;
using vs = vector<string>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using mld = map<ll, double>;
using mls = map<ll, string>;
using mlb = map<ll, bool>;
using sl = set<ll>;
using sd = set<double>;
using ss = set<string>;
using pll = pair<ll, ll>;
using pls = pair<ll, string>;
using pld = pair<ll, double>;
using plb = pair<ll, bool>;
template <class T>
using pque = priority_queue<T>;
const ll INFTY = 1L << 62L;
template <typename T>
void print_list(T &array, string sep = "\n", ll begin = 0)
{
    string ans;
    for (ll i = begin; i < array.size(); i++)
    {
        ans += to_string(array[i]);
        if (i == array.size() - 1)
        {
            continue;
        }
        ans += sep;
    }
    printf("%s\n", ans.c_str());
}
void print_list(vs &array, string sep = "\n", ll begin = 0)
{
    string ans;

    for (ll i = begin; i < array.size(); i++)
    {
        ans += array[i];
        if (i == array.size() - 1)
        {
            continue;
        }
        ans += sep;
    }
    printf("%s\n", ans.c_str());
}
ll A, B, C;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> A >> B >> C;
    cout << A + B + C - min(A, min(B, C)) << endl;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define ll long long
#define F(type, i, a, b, incr) for (type i = a; i <= (type)(b); i += (type)(incr))
#define RF(type, i, a, b, decr) for (type i = a; i >= (type)(b); i -= (type)(decr))
#define sz(a) sizeof(a)
#define deb(a) cerr << " [" << #a << "->" << a << "] "
#define next_line cerr << '\n'
#define all(a) a.begin(), a.end()
#define iter(it, s) for (auto it = s.begin(); it != s.end(); it++)
#define setbits(x) __builtin_popcountll(x)
using namespace __gnu_pbds;
using namespace std;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

/*
1. If you cannot approach a problem
directly in the way it is proposed
then try to think from backwards
2. Have you checked the implementation
before starting to write the code?
3. Have you read the question carefully ?
4. Keep the names of variable descriptive.
5. Check the types and range of the values properly
6. Erase a iterator in the set or map only after using its value.
7. 1 bitset of 1e9 size only takes 256 mb.
8. Try to use global variables in case of recursion
9. Short and precise exectutes faster
*/

void solve()
{
    int n,k;
    cin >> n >> k;
    vector<int> count(n + 1, 0);
    F(int, i, 0, n -1, 1){
        int x;
        cin >> x;
        count[x] ++;
    }
    int prev = 0, ans = 0;
    F(int, i, 0, n,  1){
        int tk = (k - prev) - min(k - prev, count[i]);
        ans += (tk * i);
        prev += tk;
    }
    cout << ans << '\n';
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
        // freopen("input.txt", "r", stdin);
        // freopen("output.txt", "w", stdout);
        // freopen("Debug.txt", "w", stderr);
    #else
    #endif
    // cout << fixed << setprecision(10);
    // int _t;
    // cin>>_t;
    // while(_t --)
        solve();
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e6+10;
const double eps = 0.01;
const double pi = 3.1415926;
inline ll read()
{
    ll x=0,f=1;char ch=getchar();
    while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
    while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
    return x*f;
}
inline ll pt(ll ans,ll f){
    printf("%lld",ans);
    if(f==1) putchar(' ');
    else putchar('\n');
}
ll n,k,m,tot;
ll a[N],c[N],vis[N];
int main()
{
//    freopen("../in.in","r",stdin);
    ll _;
    cin>>n;
    double x1,x2,y1,y2;
    cin>>x1>>y1>>x2>>y2;
    double a1=(x1+x2)/2,a2=(y1+y2)/2;
    double ag=(2*pi/n);
    x1-=a1,y1-=a2;
//    cout<<cos(ag)<<endl;
    printf("%.6f %.6f\n",a1+x1*cos(ag)-y1*sin(ag),a2+y1*cos(ag)+x1*sin(ag));
    return 0;
}

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

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

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

typedef long long ll;

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

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

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

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

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

//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readint(n);
        readdouble(x0); readdouble(y0);
        readdouble(xhalf); readdouble(yhalf);

        pair<double, double> xaxis(x0-xhalf, y0-yhalf);
        double lll = 2;
        xaxis.first /= lll; xaxis.second /= lll;
        pair<double, double> origin(0.5*(x0+xhalf), 0.5*(y0+yhalf));
        pair<double, double> yaxis(-xaxis.second, xaxis.first  );

        double PI = 3.14159265359;

               // ans = or + xaxis * cos( 2*pi/n ) + yaxis * sin( 2*pi/n )
        double ansx = origin.first + xaxis.first * cos( 2.0*PI/static_cast<double>(n) ) + yaxis.first * sin( 2.0*PI/static_cast<double>(n) );
        double ansy = origin.second + xaxis.second * cos( 2.0*PI/static_cast<double>(n) ) + yaxis.second * sin( 2.0*PI/static_cast<double>(n) );

        cout << ansx << " " << ansy << endl;
    }

    return 0;
}


// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
#define ld long double
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

long long power(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a ;
        a = a * a ;
        b >>= 1;
    }
    return res;
}

const int mod=1e9+7;

int dp[2005][2005];
int pre1[2005][2005];
int pre2[2005][2005];
int pre3[2005][2005];

signed main()
{

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

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif

    int n,m;
    cin>>n>>m;
    string a[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        a[i]="#"+a[i];
    }
    dp[1][1]=1;
    pre1[1][1]=1;
    pre2[1][1]=1;
    pre3[1][1]=1;

    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(i==1 &&j==1)
                continue;
            if(a[i][j]=='#')
                continue;
            pre1[i][j]+=pre1[i-1][j];
            pre2[i][j]+=pre2[i][j-1];
            pre3[i][j]+=pre3[i-1][j-1];
            pre1[i][j]%=mod;
            pre2[i][j]%=mod;
            pre3[i][j]%=mod;
            dp[i][j]=(pre1[i][j]+pre2[i][j]+pre3[i][j])%mod;
            pre1[i][j]+=dp[i][j];
            pre2[i][j]+=dp[i][j];
            pre3[i][j]+=dp[i][j];
            pre1[i][j]%=mod;
            pre2[i][j]%=mod;
            pre3[i][j]%=mod;
        }
    }

    cout<<dp[n][m];

}

#include<stdio.h>
#include<bits/stdc++.h>
#define ll long long int
#define inf 1000000000000
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define sz(x) (int)x.size()
#define ps(x,y)   fixed<<setprecision(y)<<x
using namespace std;
const int N = 2005;
ll dp[N][N], H[N][N], V[N][N], D[N][N];
char mat[N][N];
ll add(ll x, ll y)
{
    x += y;
    if (x >= mod)
        return x - mod;
    return x;
}

int check(int i, int j) {

    if (i < 1 || j < 1 || mat[i][j] != '#')return 0;
    return 1;
}

int h, w;

void solve()
{
    cin >> h >> w;
    memset(dp, 0, sizeof(dp));
    memset(H, 0, sizeof(H));
    memset(V, 0, sizeof(V));
    memset(D, 0, sizeof(D));
    for (int i = 1; i <= h; i++)
    {
        for (int j = 1; j <= w; j++)
        {
            cin >> mat[i][j];
        }
    }
    dp[1][1] = 1;
    H[1][1] = V[1][1] = D[1][1] = 1;
    for (int i = 1; i <= h; i++)
    {
        for (int j = 1; j <= w; j++)
        {
            if (i == 1 && j == 1) {
                continue;
            }
            if (mat[i][j] == '#') {
                continue;
            }
            dp[i][j] = add(H[i - 1][j], add(V[i][j - 1], D[i - 1][j - 1]));
            H[i][j] = V[i][j] = D[i][j] = dp[i][j];

            if (!check(i - 1, j))H[i][j] = add(H[i][j], H[i - 1][j]);
            if (!check(i, j - 1))V[i][j] = add(V[i][j], V[i][j - 1]);
            if (!check(i - 1, j - 1))D[i][j] = add(D[i][j], D[i - 1][j - 1]);
        }
    }
    cout << dp[h][w] << endl;
}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t = 1;
    // scanf("%d", &t);
    while (t--) {
        solve();
    }

}


#include <iostream>
#include <vector>
#include <numeric>
using namespace std;
using ll = int64_t;

ll score(string S){
    vector<ll> cnt(10);
    iota(cnt.begin(), cnt.end(), 0);
    for(char c : S) cnt[c - '0'] *= 10;
    return accumulate(cnt.begin(), cnt.end(), 0);
}
int main(){
    ll K;
    string S, T;
    cin >> K >> S >> T;
    vector<ll> cnt(10, K);
    for(char c : S + T) cnt[c - '0']--;
    ll win = 0;
    for(ll x = 1; x <= 9; x++) for(ll y = 1; y <= 9; y++){
        S.back() = '0' + x;
        T.back() = '0' + y;
        if(score(S) <= score(T)) continue;
        win += cnt [x] * (cnt [y] - (x == y));
    }
    const ll rem = 9 * K - 8;
    cout << double (win) / rem / (rem - 1) << endl;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);}
ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*b);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}
#define num_l(a,v) POSL(a,v) //v未満の要素数
#define num_eql(a,v) POSU(a,v) //v以下の要素数
#define num_h(a,v) (a.size() - POSU(a,v)) //vより大きい要素数
#define num_eqh(a,v) (a.size() - POSL(a,v)) //v以上の要素数
// static_cast< long long ll >

//chrono::system_clock::time_point start, end;
clock_t start;

bool did[50*52];
int tile[51][51];
int point[51][51];
int N = 50;
int si,sj;

string now = "";
int len = 0;
string ans="";

int score = 0;
int best_s = 0;

string D = "DURL";
int di[] = {1,-1,0,0};
int dj[] = {0,0,1,-1};

void calc(int i,int j,char &x){
  if(i<0 || j<0 || i>=50 || j>=50)return;
  if(did[ tile[i][j] ])return;
  clock_t end = clock();
  double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
  if(time >= 1950)return;

  now[len] = x;
  len++;
  did[ tile[i][j] ] = true;
  score += point[i][j];

  if(score > best_s){
    best_s = score;
    ans = now.substr(0,len);
  }

  FOR(k,0,4){
    calc(i+di[k],j+dj[k],D[k]);
  }

  len--;
  did[ tile[i][j] ] = false;
  score -= point[i][j];
}

int main(){
  FOR(i,0,N*N) now += 'D';

  mt19937_64 mt(1);
  uniform_real_distribution<double> rnd(0.00,1.00);

  cin >> si >> sj;
  FOR(i,0,N)FOR(j,0,N){
    cin >> tile[i][j];
  }
  FOR(i,0,N)FOR(j,0,N){
    cin >> point[i][j];
  }

  start = clock();

  char a = 'U';
  calc(si,sj,a);

  if(ans.size() == 0) ans = "U";
  cout << ans.substr(1,ans.size()-1) << endl;

}


#include <bits/stdc++.h>

int main() {
  long long n; std::cin >> n;
  // 3で割って
  int digit = 0;
  int sum = 0;
  int n_zero = 0; // 余り0の倍数の数
  int n_one = 0; // 余り1の倍数の数
  int n_two = 0; // 余り2の倍数の数
  // std::cout << n << std::endl;
  // std::string s;
  while (n) {
    int d = n%10;
    ++digit;
    sum += d;
    n_zero += (d%3 == 0);
    n_one += (d%3 == 1);
    n_two += (d%3 == 2);
    // s += ('0' + n%10);
    n /= 10;
  }
  int ans = -1;
  // 全部3の倍数
  if (sum % 3 == 0) ans = 0;
  else if (sum % 3 == 1) {
    if (n_one >= 1 && digit >= 2) ans = 1;
    else if (n_two >= 2 && digit >= 3) ans = 2;
  }
  else if (sum % 3 == 2) {
    if (n_two >= 1 && digit >= 2) ans = 1;
    else if (n_one >= 2 && digit >= 3) ans = 2;
  }
  std::cout << ans << std::endl;
  // std::cout << s << std::endl;
  // std::cout << n_zero << std::endl;
  // std::cout << n_one << std::endl;
  // std::cout << n_two << std::endl;

}

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

void make(vector<int>& v,vector<int>v1,int index,int &cnt){
    if(v1.size()>4) return;
    if(v1.size()==4){
        map<int,int> m;
        for(auto i: v1){
            m[i]++;
            //cout<<i<<" ";
        }
        //cout<<"\n";
        int pro=1;
        for(auto i: m){
            if(i.second==2) pro*=2;
            else if(i.second==3) pro*=6;
            else if(i.second==4) pro*=24;
        }
        cnt+=(24/pro);
        return ;
    }
    for(int i=index;i<v.size();i++){
        v1.push_back(v[i]);
        make(v,v1,i,cnt);
        v1.pop_back();
    }
}

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

    string s;
    cin>>s;
    vector<int> v,v1;
    int cnt=0;
    for(int i=0;i<10;i++){
        if(s[i]=='o') v.push_back(i);
        else if(s[i]=='?') v1.push_back(i);
    }
    if(v.size()>4) cout<<"0";
    else if(v.size()==4) cout<<"24";
    else{
        vector<int> v2;
        //cout<<v.size()<<" "<<v1.size()<<" ";
        for(int i=0;i<v.size();i++){
            v2.push_back(v[i]);
            v1.push_back(v[i]);
        }
        make(v1,v2,0,cnt);
        cout<<cnt;
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
vector<pair<ll,ll>> cond[105];
void solve()
{
	ll n,m;
	cin>>n>>m;
	for(ll i=1;i<=m;i++)
	{
		ll x,y,z;
		cin>>x>>y>>z;
		cond[x].push_back({y,z});
	}

	vector<ll> dp((1LL<<n),0);

	dp[0]=1;
	for(ll i=1;i<(1LL<<n);i++)
	{
		ll c=0;
		for(ll j=0;j<n;j++)
		{
			if(i&(1LL<<j)) c++;
		}

		bool ok=true;
		ll fail=-1;
		for(ll b=c;b<=n-1;b++)
		{
			for(ll j=0;j<(ll)cond[b].size();j++)
			{
				ll cnt=0;
				ll y=cond[b][j].first,z=cond[b][j].second;
				for(ll k=0;k<n;k++)
				{
					if(i&(1LL<<k))
					{
						if(k+1<=y) cnt++;
					}
				}
				//if(i==3) cout<<cnt<<"\n";

				if(cnt>z)
				{
					fail=b;
					ok=false;
					break;
				}
			}
		}
		if(!ok)
		{
			//cout<<fail<<" "<<i<<"\n";
			continue;
		}
		for(ll j=0;j<n;j++)
		{
			if(i&(1LL<<j))
			{
				dp[i]+=(dp[i^(1LL<<j)]);
			}
		}
	}
	// for(ll i=0;i<(1LL<<n);i++)
	// {
	// 	cout<<dp[i]<<" ";
	// }
	// cout<<"\n";
	cout<<dp[(1LL<<n)-1]<<"\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll T=1,p=1;
	//cin>>T;
	while(T--)
	{
		//cout<<"Case #"<<p<<": ";
		solve();
		p++;
	}
	/*
	#ifndef ONLINE_JUDGE
		cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
	#endif
	*/
	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 <algorithm>
#include <iostream>
using ll = long long;
using namespace std;

int main() {
  int a[4];
  for (int i = 0; i < 4; i++) cin >> a[i];
  sort(a, a + 4);
  if (a[0] + a[3] == a[1] + a[2] || a[0] + a[1] + a[2] == a[3])
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int ans = 0;
	ans = max(ans, a + b);
	ans = max(ans, a + c);
	ans = max(ans, b + c);
	cout << ans << endl;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
//#include <atcoder/all>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
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; }
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(){
  ll N,X; cin >> N >> X;
  vector<ll> V(N);
  vector<ll> P(N);
  rep(i,N) cin >> V[i] >> P[i];
  ll now = 0;
  rep(i,N){
    now += V[i]*P[i];
    if(now>X*100){
      cout << i+1 << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools

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

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;

template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}

// doc: https://shibh308.github.io/library/library/lib/classes/unionfind.cpp.html
struct UnionFind{
    vector<int> par;
    int count;
    UnionFind(int n) : par(n, -1), count(0){}
    int Find(int x){return par[x] < 0 ? x : Find(par[x]);}
    int Size(int x){return par[x] < 0 ? -par[x] : Size(par[x]);}
    bool Unite(int x, int y){
        x = Find(x);
        y = Find(y);
        if(x == y)
            return false;
        if(par[x] > par[y])
            swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return ++count;
    }
};

signed main(){
    int n, m;
    cin >> n >> m;
    vector<vector<int>> edges(n);
    UnionFind uf(n);
    for(int i = 0; i < m; ++i){
        int x, y;
        cin >> x >> y;
        edges[--x].emplace_back(--y);
        edges[y].emplace_back(x);
        uf.Unite(x, y);
    }

    vector<vector<int>> fl(n);
    for(int i = 0; i < n; ++i){
        assert(uf.Find(i) < n);
        fl[uf.Find(i)].emplace_back(i);
    }

    vector<i64> cn(n, 0);
    vector<int> col(n);
    function<void(int,int)> f = [&](int k, int p){
        if(p == fl[k].size()){
            ++cn[k];
            return;
        }
        int x = fl[k][p];
        for(int j = 0; j < 3; ++j){
            bool fp = true;
            for(auto y : edges[x]){
                if(col[y] == j){
                    fp = false;
                    break;
                }
            }
            if(fp){
                col[x] = j;
                f(k, p + 1);
                col[x] = -1;
            }
        }
    };

    for(int i = 0; i < n; ++i){
        col.assign(n, -1);
        f(i, 0);
    }

    i64 ais = accumulate(cn.begin(), cn.end(), 1LL, [](auto x, auto y){return x * y;});
    cout << ais << endl;

    return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#pragma comment(linker, "/STACK:36777216")

#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <cstring>
#include <random>
#include <cassert>
#include <iterator>
using namespace std;

#define inf (ll)1e15
#define mod (ll)(1e9 + 7)
#define pi 3.14159265358979
#define e 2.71828
#define eps 1e-6
#define neutral 0;
typedef unsigned long long ull;
typedef long long ll;

int dp[301][301];

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

    int n;
    cin >> n;
    vector<int> a(n);
    int m = -1;

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

    int ans = 0, num = -1;

    for (int i = 2; i <= m; i++)
    {
        int t = 0;
        for (int j = 0; j < n; j++)
        {
            if (a[j] % i == 0)
                t++;
        }
        if (t > num)
        {
            num = t;
            ans = i;
        }
    }

    cout << ans;

    return 0;
}

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

int main()
{
    string s;
    cin >> s;

    ll ans = 0;

    // 1つ前の文字
    char c = s.at(0);

    // 直前の連続した文字
    char lc = '0';

    // 連続した文字列が何個あったか
    ll lcnt = 0;

    // 文字連続カウンター
    ll cnt = 0;

    for (int i = 0; i < s.size(); i++)
    {
        if (c == s.at(i))
        {
            cnt++;
        }
        else
        {
            if (cnt > 1)
            {
                // 直前の連続文字と異なる場合のみ変更回数が増えるのでカウントアップ
                if (lc != c)
                {
                    lcnt++;
                }
                lc = c;
            }

            cnt = 1;
            c = s.at(i);
        }

        // 直前の連続文字列と異なる場合、変更できる。
        if (lc != s.at(i))
        {
            ans += lcnt;
        }
        else
        {
            ans += lcnt - 1;
        }
    }

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