#include <bits/stdc++.h>

#define eprintf(args...) fprintf(stderr, args)
#define rep(i, n) for (int i = 0; i < (int)(n); ++ i)

const int mxn = 2e5 + 5;
int n, a[mxn], b[mxn];
std::map <int, std::vector <int> > oa, ob;

int s[mxn];

void update(int x, int v) {
	for (++ x; x < mxn; x += x & -x) s[x] += v;
}

int query(int x) {
	int ans = 0;
	for (++ x; x; x -= x & -x) ans += s[x];
	return ans;
}

int frm[mxn];

int main() {
	scanf("%d", &n);
	rep(i, n) scanf("%d", &a[i]), a[i] += i;
	rep(i, n) scanf("%d", &b[i]), b[i] += i;
	rep(i, n) oa[a[i]].push_back(i);
	rep(i, n) ob[b[i]].push_back(i);
	for (auto x : oa) {
		std::vector <int> va = x.second, vb = ob[x.first];
		if (va.size() != vb.size()) return printf("%d\n", -1), 0;
		rep(i, va.size()) frm[vb[i]] = va[i];
	}
	rep(i, n) update(i, 1);
	long long ans = 0;
	rep(i, n) ans += query(frm[i] - 1), update(frm[i], -1);
	printf("%lld\n", ans);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
void solve() {
    string s; cin >> s;
    deque<char> t;
    int n = s.size();
    int rev = 0;
    for (int i = 0; i < n; ++i) {
        if (s[i] == 'R')rev = 1 - rev;
        else {
            if (rev == 0) {
                if (t.size() > 0 && t.back() == s[i]) t.pop_back();
                else t.push_back(s[i]);
            }
            else if (rev == 1) {
                if (t.size() > 0 && t.front() == s[i]) t.pop_front();
                else t.push_front(s[i]);
            }
        }
    }
    if (rev == 0) {
        for (int i = 0; i < (int)t.size(); ++i)cout << t[i];
        cout << endl;
    }
    else {
        for (int i = t.size() - 1; i >= 0; --i) {
            cout << t[i];
        }
        cout << endl;
    }
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

#ifndef ONLINE_JUDGE
    freopen("input1.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
#endif
    int t = 1;
    // cin >> t;
    for (int i = 0; i < t; ++i)
    {
        solve();
    }
}


#include<bits/stdc++.h>
#include<string>
using namespace std;
const int N=1e3+10;
typedef   long long ll;

int n,k,q,m,h,w;
const ll mod=998244353;
int a[N];
int b[N];
map<int,map<int,int> > mp;
set<int> se;
string s;
stack <int> st;
int X[]={-1,-1,-1,0,0,1,1,1};
int Y[]={-1,0,1,-1,1,-1,0,1};

int main()
{
    int A,B,C,D;
    cin>>A>>B>>C>>D;
    cout<<A*D-B*C;

}

#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define mod 1000000007
#define pb push_back
#define endl "\n"
#define fi first
#define se second
#define ll long long
#define inf 9000000000000000000
#define PI 3.14159265359

int power(int a,int b,int m=mod)
{
     if(b==0)	return 1;
     if(b==1)	return a;
	 int res=power(a,b/2,m);
	 res=(res*res)%m;
     if(b&1)	res=(res*a)%m;
     return res;
}
int modinv(int a,int m=mod){ return power(a,m-2,m);}
int add(int a,int b,int m=mod){	int c=(a%m+b%m);	if(c>=m)	c-=m;	return c;}
int sub(int a,int b,int m=mod){	int c=(a%m-b%m);	if(c<0)		c+=m;	return c;}
int mul(int a,int b,int m=mod){	return (a*b)%m;}

int32_t main()
{
   IOS

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

   int p = max(0LL,n-a);
   cout<<p+b<<endl;

}


#include <bits/stdc++.h>
using namespace std;
/* ループ処理 0からnまで*/
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main()
{
  int N, M;
  cin >> N >> M;
  std::vector<int> v = {};
  rep(i, N)
  {
    int temp;
    cin >> temp;
    v.push_back(temp);
  }
  rep(j, M)
  {
    int temp;
    cin >> temp;
    auto itr = std::find(v.begin(), v.end(), temp);
    if (itr != v.end())
    {
      v.erase(itr);
    }
    else
    {
      v.push_back(temp);
    }
  }
  std::sort(v.begin(), v.end());
  std::size_t size = v.size();
  rep(k, (int)size)
  {
    cout << v[k];
    if (k != (int)size - 1)
    {
      cout << ' ';
    }
  }
  cout << endl;
}


#include <bits/stdc++.h>

#define Fast cin.tie(0), ios::sync_with_stdio(0)
#define All(x) x.begin(), x.end()
#define louisfghbvc int t; cin >> t; while(t--)
#define sz(x) (int)(x).size()
using namespace std;
typedef long long LL;
typedef pair<LL, LL> ii;
typedef vector<int> vi;

template<typename T> istream& operator>>(istream &is, vector<T> &v) { for(auto &it : v) is >> it; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep = ""; for(const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cerr << " end.\n"; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

const int N = 1e3+5;

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

    vi A(n), B(n);
    for(int i = 0; i < n; ++i) cin >> A[i] >> B[i];

    int next[205] = {};
    int prev[205] = {};
    bool dp[205] = {};

    for(int i = 0; i < n; ++i){
        if(B[i] > 0 && A[i] >= B[i]){
            puts("No");
            return;
        }
        if(A[i] >= 1){
            if(next[A[i]] || prev[A[i]]){
                puts("No");
                return;
            }
        }
        if(B[i] >= 1){
            if(next[B[i]] || prev[B[i]]){
                puts("No");
                return;
            }
        }
        if(A[i] >= 1){
            next[A[i]] = B[i];
        }
        if(B[i] >= 1){
            prev[B[i]] = A[i];
        }
    }

    auto canPair = [&](int a, int b){
        if((prev[a] || next[b]) || (next[a] > 0 && next[a] != b)
           || (prev[b] > 0 && prev[b] != a) || (next[a] < 0 && prev[b] < 0))
           return false;
        return true;
    };
    dp[0] = true;

    for(int i = 2; i <= 2*n; i+=2){
        if(next[i]) continue;
        for(int j = i/2; j < i; ++j){
            if(!canPair(j, i)) continue;
            if(!dp[2*j-i]) continue;

            int d = i-j;
            bool fail = false;
            for(int l = i-1; l > j; --l){
                if(!canPair(l-d, l)){
                    fail = true;
                    break;
                }
            }

            if(!fail){
                dp[i] = true;
                break;
            }
        }
    }

    puts(dp[2*n] ? "Yes" : "No");
}

int main()
{
    Fast;
    //louisfghbvc
        solve();
    return 0;
}

/*input
2
4 1
2 4

*/

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

// p[i][j] = (-1: do not pair, 0: ok, 1: fixed)
int p[205][205];

int main() {
  int n;
  cin >> n;
  int n2 = n*2;
  // type[i] = (0: either, -1: start, 1: end)
  vector<int> type(n2);
  bool ans = true;
  auto count = [&](int x, int t) {
    if (x == -2) return;
    if (type[x]) ans = false;
    // cout<<x <<" "<<t<<endl;
    type[x] = t;
  };
  auto exe = [&](int a, int b) {
    count(a, -1);
    count(b, 1);
    if (a == -2 || b == -2) return;
    // if (a >= b) {
    //   ans = false;
    //   return;
    // }
    p[a][b] = p[b][a] = 1;
    rep(i, n2) {
      if (i != a) p[i][b] = -1;
      if (i != b) p[a][i] = -1;
    }
  };
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    exe(--a, --b);
  }

  // dp[i+1] = whether possible to separate at i
  vector<int> dp(n2+1);
  dp[0] = 1;
  for (int si = 0; si < n2; si += 2) {
    if (!dp[si]) continue;

    for (int w = 1; si+w*2 <= n2; ++w) {
      bool ok = true;
      for (int i = si; i < si+w*2; ++i) {
        if (type[i] == 0) continue;
        if (type[i] == -1) {
          if (i+w >= si+w*2) { ok = false; break;}
          if (p[i][i+w] == -1) ok = false;
          if (!p[i][i+w] && type[i+w]) ok = false;
        }
        if (type[i] == 1) {
          if (i-w < si) { ok = false; break;}
          if (p[i][i-w] == -1) ok = false;
          if (!p[i][i-w] && type[i-w]) ok = false;
        }
      }
      // cout<<si+w*2<<" "<<ok<<endl;
      dp[si+w*2] |= ok;
    }
  }
  if (ans && dp.back()) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


// #pragma GCC optimize(2)
// #include <random>
// #include <windows.h>
// #include <ctime>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cctype>
#include <bitset>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#define IO                       \
    ios::sync_with_stdio(false); \
    // cout.tie(0);
#define lson(x) node << 1, start, mid
#define rson(x) node << 1 | 1, mid + 1, end
using namespace std;
// int dis[8][2] = {0, 1, 1, 0, 0, -1, -1, 0, 1, -1, 1, 1, -1, 1, -1, -1};
typedef unsigned long long ULL;
typedef long long LL;
typedef pair<int, int> P;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 10;
const int maxm = 5e5 + 10;
const LL mod = 998244353;
const double eps = 1e-8;
const double pi = acos(-1);
// int dis[4][2] = {1, 0, 0, -1, 0, 1, -1, 0};
// int m[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int a[maxn];
int main()
{
#ifdef WXY
    freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#endif
    IO;
    int n;
    cin >> n;
    for (int i = 1; i <= n;i++)
    {
        cin >> a[i];
    }
    int ans = 0;
    for (int i = 1; i <= n;i++)
    {
        int x = a[i];
        for (int j = i; j <= n;j++)
        {
            x = min(a[j], x);
            ans = max(ans, (j - i + 1) * x);
        }
    }
    cout << ans;
    return 0;
}

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

#define rep(i, a, b) for (int i = (a), i##end = (b); i < i##end; ++i)
#define per(i, a, b) for (int i = (a) - 1, i##end = (b); i >= i##end; --i)
#define REP(i, a) rep(i, 0, a)
#define PER(i, a) rep(i, a, 0)

namespace IO {
	const int MAXIOSIZE = 1 << 24 | 1;
	unsigned char buf[MAXIOSIZE], *p1, *p2;
	#define gc (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 24, stdin), p1 == p2) ? EOF : *p1++)
	template <typename T> void read(T& x) {
		x = 0; char ch = gc; bool flg = false;
		for (; ch < '0' || '9' < ch; ch = gc) if (ch == '-') flg |= true;
		for (; '0' <= ch && ch <= '9'; ch = gc) x = x * 10 + ch - '0';
		flg ? x = -x : 0;
	}
	template <typename T> void out(const T& x) { if (x > 9) out(x / 10); putchar(x % 10 + '0'); }
	template <typename T> inline void write(const T& x, const char& ed = ' ') { if (x < 0) putchar('-'), out(-x); else out(x); putchar(ed); }
}

typedef pair<int, int> pii;

const int MAXN = 2000 + 10;

int n, m;
vector<pair<int, int> > E[MAXN];

int vis[MAXN], dis[MAXN];
void solve(int S) {
	memset(dis, 0x3f, sizeof dis), memset(vis, 0, sizeof vis);
	priority_queue<pii, vector<pii>, greater<pii> > q;
	q.push(make_pair(0, S));
	while (!q.empty()) {
		pair<int, int> u = q.top(); q.pop();
		if (vis[u.second]) continue;
		vis[u.second] = true;
		for (pair<int, int> v : E[u.second]) {
			if (dis[v.first] > u.first + v.second) {
				dis[v.first] = u.first + v.second, q.push(make_pair(dis[v.first], v.first));
			}
		}
	}
	if (dis[S] < 1e9) IO::write(dis[S], '\n');
	else IO::write(-1, '\n');
}

int main() {
	#ifdef LOCAL
		freopen("in.txt", "r", stdin);
	#endif
	IO::read(n), IO::read(m);
	REP(i, m) {
		int u, v, w; IO::read(u), IO::read(v), IO::read(w); u--, v--;
		E[u].push_back(make_pair(v, w));
	}
	REP(i, n) solve(i);
	return 0;
}


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

	int N;
	vector<vector<int>> es;
	vector<int> A, B;

	vector<int> depth;
	vector<ll> dp;

	void DepthDFS(int a, int d) {
		depth[a] = d;
		for (int next : es[a]) {
			if (depth[next] == -1) {
				DepthDFS(next, d + 1);
			}
		}
	}

	void ImosDFS(int a, long now) {
		now += dp[a];
		dp[a] = now;
		for(int next : es[a]) {
			if (depth[next] > depth[a]) {
				ImosDFS(next, now);
			}
		}
	}

	int main() {
		cin >> N;
		es.resize(N);
		A.resize(N - 1);
		B.resize(N - 1);
		depth = vector<int>(N, -1);
		dp = vector<ll>(N, 0);

		rep(i, N - 1) {
			cin >> A[i] >> B[i];
			A[i]--; B[i]--;
			es[A[i]].push_back(B[i]);
			es[B[i]].push_back(A[i]);
		}

		DepthDFS(0, 0);

		int Q;
		cin >> Q;
		rep(i, Q) {
			int t, e, x;
			cin >> t >> e >> x;
			e--;

			int va, vb;
			if (t == 1) {
				va = A[e];
				vb = B[e];
			}
			else {
				va = B[e];
				vb = A[e];
			}

			if (depth[va] < depth[vb]) {
				dp[0] += x;
				dp[vb] -= x;
			}
			else {
				dp[va] += x;
			}
		}

		ImosDFS(0, 0);

		rep(i, N)cout << dp[i] << endl;

	}

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

template <class A, class B> bool cmin(A& a, B b) { return a > b && (a = b, true); }
template <class A, class B> bool cmax(A& a, B b) { return a < b && (a = b, true); }

template <typename T> class Dijkstra {
private:
  struct edge {
    int to;
    T cost;
  };
  vector<vector<edge>> G;
  vector<T> D;

public:
  Dijkstra(int n) : G(n), D(n, numeric_limits<T>::max()) {}
  void add(int from, int to, T cost) {
    G.at(from).push_back((edge){to, cost});
    G.at(to).push_back((edge){from, cost});
  }
  vector<T> solve(int start) {
    using pti = pair<T, int>;
    priority_queue<pti, vector<pti>, greater<pti>> Q;
    D.at(start) = 0;
    Q.push(pti(0, start));
    while (Q.size()) {
      auto [dist, now] = Q.top();
      Q.pop();
      if (D.at(now) < dist) continue;
      for (auto [next, cost] : G.at(now)) {
        if (D.at(next) > D.at(now) + cost) {
          D.at(next) = D.at(now) + cost;
          Q.push(pti(D.at(next), next));
        }
      }
    }
    return D;
  }
  void reset() { fill(D.begin(), D.end(), numeric_limits<T>::max()); }
};

signed main() {
  cin.tie(nullptr)->sync_with_stdio(false);

  int N;
  cin >> N;
  vector<pair<int, int>> V(N - 1);
  vector<vector<int>> G(N);
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b, a--, b--;
    V.at(i) = {a, b};
    G.at(a).push_back(b);
    G.at(b).push_back(a);
  }

  Dijkstra<int> D(N);
  for (const auto& [a, b] : V) D.add(a, b, 1);
  auto rank = D.solve(0);
  vector<long> cnt(N);

  int Q;
  cin >> Q;
  while (Q--) {
    int t, e, x;
    cin >> t >> e >> x, e--;
    auto [a, b] = V.at(e);
    if (t == 1) {
      if (rank.at(a) < rank.at(b)) {
        cnt.at(0) += x;
        cnt.at(b) -= x;
      } else {
        cnt.at(a) += x;
      }
    } else {
      if (rank.at(a) < rank.at(b)) {
        cnt.at(b) += x;
      } else {
        cnt.at(0) += x;
        cnt.at(a) -= x;
      }
    }
  }

  auto dfs = [&](auto&& dfs, int now, int pre) -> void {
    for (const auto& next : G.at(now)) {
      if (next == pre) continue;
      cnt.at(next) += cnt.at(now);
      dfs(dfs, next, now);
    }
  };

  dfs(dfs, 0, -1);

  for (const auto& a : cnt) cout << a << '\n';
}


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

#define DEBUG
#ifdef DEBUG
inline void debug_print() { cerr << endl; }
template <typename T1, typename... T2> void debug_print(const T1 a, const T2 &... b) { cerr << a << ' '; debug_print(b...); }
#define debug(...) cerr << __LINE__ << ": [" << #__VA_ARGS__ << "] = " , debug_print(__VA_ARGS__);
#else
#define debug(...) true
#endif

inline void print() { cout << '\n'; }
template <typename T1, typename... T2> void print(const T1 a, const T2 &... b) { cout << a << ' '; print(b...); }

template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto e : v) os << e << ' '; return os; }
template <typename T> ostream &operator<<(ostream &os, const set<T> &v) { for (auto e : v) os << e << ' ';  return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp) { for (auto e : mp) os << e << ' '; return os; }

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

//-------------------------- Libraries --------------------------//

//---------------------------- Solve ----------------------------//

string simulate(string s, int k) {

    s += s;
    string res;
    for (int i = 0; i < s.size(); i+=2) {
        if (s[i] == 'R') {
            if (s[i+1] == 'R') res += 'R';
            if (s[i+1] == 'S') res += 'R';
            if (s[i+1] == 'P') res += 'P';
        }
        if (s[i] == 'S') {
            if (s[i+1] == 'R') res += 'R';
            if (s[i+1] == 'S') res += 'S';
            if (s[i+1] == 'P') res += 'S';
        }
        if (s[i] == 'P') {
            if (s[i+1] == 'R') res += 'P';
            if (s[i+1] == 'S') res += 'S';
            if (s[i+1] == 'P') res += 'P';
        }
    }

    if (k < 7) {
        int tmp = 1;
        for (int i = 0; i < k; i++) {
            tmp *= 2;
        }
        if (tmp < res.size()) {
            string t;
            for (int i = 0; i < tmp; i++) {
                t += res[i];
            }
            res = t;
        }
    }

    return res;
}

void solve() {
    int n, k; cin >> n >> k;
    string s; cin >> s;

    int K = k;
    for (int i = 0; i < k; i++) {
        s = simulate(s, K-1);
        K--;
    }

    cout << s << '\n';
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

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

char not_loser(char a, char b){
	char w = a;
	if(a=='R' && b == 'P') w = b;
	if(a=='P' && b == 'S') w = b;
	if(a=='S' && b == 'R') w = b;
	return w;
}

int main(){
	int N, K; string S; cin>>N>>K>>S;
	while(K--){
		string t = S + S;
		rep(i, N) S[i] = not_loser(t[i*2], t[i*2+1]);
	}
	cout<< S[0] <<endl;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  for (int i = 0; i < N; i++){
    cout << i * 2 % N + 1 << ' ' << (i * 2 + 1) % N + 1 << endl;
  }
}

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

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        printf("%d %d\n", (i + 1) / 2, i + (n - i + 1) / 2);
    }
    return 0;
}


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

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef pair<int,int> Pair;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

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

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 998244353;

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

struct modint {
    long long x;
    modint(long long x=0):x((x%MOD+MOD)%MOD){}
    long long val(){
        return x;
    }
    modint operator-() const { return modint(-x);}
    modint& operator+=(const modint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    modint& operator-=(const modint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
    	return *this;
    }
    modint& operator*=(const modint a) {
    	(x *= a.x) %= MOD;
        return *this;
    }
    modint operator+(const modint a) const {
        modint res(*this);
        return res+=a;
    }
    modint operator-(const modint a) const {
        modint res(*this);
        return res-=a;
    }
    modint operator*(const modint a) const {
        modint res(*this);
        return res*=a;
    }
    modint pow(long long t) const {
        if (!t) return 1;
        modint a = pow(t>>1);
        a *= a;
    	if (t&1) a *= *this;
        return a;
    }

	// must be gcd(x,MOD)==1
    modint inv() const {
		// a^{-1} = 1/a MOD p (拡張Euclidの互除法)
		long long b = MOD, u = 1, v = 0, z = x;
		while(b){
			long long t = z / b;
			z -= t * b; swap(z, b);
			u -= t * v; swap(u, v);
		}
		u %= MOD;
		if (u < 0) u += MOD;
		return modint(u);
	}

    //modint inv() const {
    //    return pow(MOD-2);
    //}

    modint& operator/=(const modint a) {
    	return (*this) *= a.inv();
    }
    modint operator/(const modint a) const {
        modint res(*this);
        return res/=a;
    }
};
using mint = modint;

struct Factorial{

    vector<mint> fact, ifact;

    Factorial(int N): fact(N+1), ifact(N+1) {
        assert(N < MOD);

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

        ifact[N] = fact[N].inv();
        for(int i=N; i>0; i--) ifact[i-1] = ifact[i] * i;
    }

    mint C(int n, int k){
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }

    mint P(int n, int k){
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[n-k];
    }

    mint inv(int n){
        assert(n>0);
        return fact[n-1]*ifact[n];
    }
};

mint dp[101][101][10101];

void Main(){
    int N; cin >> N;
    int sum = 0;
    Factorial F(100);
    dp[0][0][0] = 1;
    REP(i,N){
        int w; cin >> w; sum += w;
        REP(j,i+1)REP(k,sum+1){
            dp[i+1][j+1][k+w] += dp[i][j][k];
            dp[i+1][j][k] += dp[i][j][k];
        }
    }
    if(sum&1){
        cout << 0 << en;
        return;
    }
    sum >>= 1;
    mint ans(0);
    REP(i,N+1){
        ans += dp[N][i][sum] * F.fact[i] * F.fact[N-i];
    }
    cout << ans.x << en;
    return;
}

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

/*
    Code written by Talant I.D.
*/

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

//~ using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
//~ typedef tree <ll, null_type, less_equal <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define precision(n) fixed << setprecision(n)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define eps (double)1e-9
#define PI 2*acos(0.0)
#define endl "\n"
#define sz(v) int((v).size())
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define OK cout << "OK" << endl;

const int mod = 998244353;

ll mode(ll a) {
    while (a < 0) {
        a += mod;
    }
    return a % mod;
}

ll subt(ll a, ll b) {
    return mode(mode(a)-mode(b));
}

ll add(ll a, ll b) {
    return mode(mode(a)+mode(b));
}

ll mult(ll a, ll b) {
    return mode(mode(a)*mode(b));
}

ll binpow(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b&1) res = mult(res, a);
        a = mult(a, a);
        b >>= 1;
    }
    return res;
}

ll dp[10003][103];
ll fact[10003];

int main() {
    do_not_disturb

    fact[0] = fact[1] = 1;
    for (ll i = 2; i < 10003; i++) {
        fact[i] = mult(fact[i-1], i);
    }
    dp[0][0] = 1;

    int n;
    cin >> n;
    vector <int> a(n);
    for (auto &to : a) cin >> to;

    for (auto to : a) {
        for (int i = 5000; i >= to; i--) {
            for (int j = 0; j < 100; j++) {
                dp[i][j+1] = add(dp[i][j+1], dp[i-to][j]);
            }
        }
    }

    ll ans = 0;
    ll sum = 0;
    for (auto to : a) sum += to;
    if (sum&1) {
        cout << 0;
        return 0;
    }
    sum /= 2;

    for (int i = 0; i <= 100; i++) {
        ans = add(ans, mult(dp[sum][i], mult(fact[i], fact[n-i])));
    }

    cout << ans;

    return 0;
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n) for (int i = n - 1; i >= 0; --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define pb push_back
#define em emplace_back
#define vi vector<int>
#define vl vector<long long>
#define vs vector<string>
#define vc vector<char>
#define vd vector<double>
#define vb vector<bool>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define fast  \
  cin.tie(0); \
  ios::sync_with_stdio(false);
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

vl a;
ll k, n, m;

// index が条件を満たすかどうか
bool isOK(ll index, ll key) {
  ll s = 0;
  rep(i, 0, k) {
    key -= (a[i] * m - index + n - 1) / n;
    if (key < 0) return false;
    s += (a[i] * m + index) / n - (a[i] * m - index + n - 1) / n;
  }
  if (key <= s) {
    return true;
  } else {
    return false;
  }
}

// 汎用的な二分探索のテンプレ
ll binary_search(ll key) {
  ll ng = -1;  //「index = 0」が条件を満たすこともあるので、初期値は -1
  ll ok = 10000000000000000;

  /* ok と ng のどちらが大きいかわからないことを考慮 */
  while (abs(ok - ng) > 1) {
    ll mid = (ok + ng) / 2;

    if (isOK(mid, key))
      ok = mid;
    else
      ng = mid;
  }
  return ok;
}

int main() {
  fast;
  cin >> k >> n >> m;
  a = vl(k);
  rep(i, 0, k) cin >> a[i];
  ll c = binary_search(m);
  vl ans(k), s(k);
  ll sum = 0;
  rep(i, 0, k) {
    ans[i] = (a[i] * m - c + n - 1) / n;
    sum += (a[i] * m - c + n - 1) / n;
    s[i] = (a[i] * m + c) / n - (a[i] * m - c + n - 1) / n;
  }
  rep(i, 0, k) {
    ans[i] += min(m - sum, s[i]);
    sum += min(m - sum, s[i]);
    if (sum == m) break;
  }
  for (auto i : ans) {
    cout << i << " ";
  }
  cout << endl;
  return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
//const ll INF = numeric_limits<ll>::max() / 4;
//const int INF = numeric_limits<int>::max() / 4;

int main() {
	// ll N;
	ll K, N, M;
	cin >> K >> N >> M;
	vector<ll> A(K,0);
	for(int i = 0; i < K; i++) cin >> A[i];
	vector<ll> x(K,0);
	vector<ll> y(K,0);
	vector<ll> B(K,0);
	multimap<ll,ll> P;
	ll L = M;
	for(int i = 0; i < K; i++){
		x[i] = M * A[i] / N;
		B[i] = x[i];
		y[i] = M * A[i] % N;
		L -= x[i];
		P.insert(make_pair(N - y[i], i));
	}
	for(auto it = P.begin(); it != P.end(); it++){
		if(0 < L){
			B[it->second]++;
			L--;
		}else{
			break;
		}
	}
	for(int i = 0; i < K; i++){
		cout << B[i] << " ";
	}
	cout << endl;
	return(0);
}


#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <utility>
#include <iostream>
#include <algorithm>

#define MAXN 100005
#define MOD 1000000007

using namespace std;

typedef long long int ll;
typedef pair<int, int> par;
#define mp make_pair

// variables

// functions

// main function
void solve(){
    int x;
    cin >> x;
    cout << (x >= 0 ? x : 0) << endl;
}

int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    //freopen("in.txt","r",stdin);

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

    //cout << setprecision(10) << sol << endl;

    return 0;
};

#include<bits/stdc++.h>

int main(){
    using namespace std;
    long x;
    cin >> x;
    cout << max(x, 0L) << endl;
    return 0;
}


#include <bits/stdc++.h>
//#include <atcoder/all>
//#include "Z:\2_Src\31_Luzhiles_s.git\template\template.cpp"
using namespace std; //using namespace atcoder;
template<typename T>  using ve=vector<T>;
using ll=long long; using ld=long double; using str=string; using pint=pair<ll,ll>;
using vll=ve<ll>; using vd=ve<ld>; using vs=ve<str>; using vll2=ve<ve<ll>>;
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define b2e(v) v.begin(),v.end()
#define p2a(v, p) v[p.first][p.second]
#define rep(i,n)  for(ll i=0;i<(n);i++)
#define repi(i,n) for(ll i=(n-1);i>=0;i--)
#define repe(e,v) for(auto e:v)
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
const int MOD=1000000007;
//const int MOD=998244353;

int main() {
    ll nn; cin >> nn;
    //vector<pair<ll,char>> vp1;
    ve<ve<ll>> vv1(3);

    rep(i,2*nn) {
        ll a; char b; cin>>a>>b;
        if(b=='R') vv1[0].push_back(a);
        if(b=='G') vv1[1].push_back(a);
        if(b=='B') vv1[2].push_back(a);
    }

    ll ct=0;
    vll odd1,odd2,even;
    // 1. 色ごとの配列を作り、サイズが全て偶数なら0を出力して終了する
    repe(v1,vv1) {
        if(!(v1.size()%2)) {
            even=v1;
        } else {
            ct++;
            if(ct==1) odd1=v1;
            if(ct==2) odd2=v1;
        }
    }
    if(!ct) {
        ll ans=0;
        cout << ans << endl;
        exit(0);
    }

    // 2. 各配列をソートする
    whole( sort, even );
    whole( sort, odd1 );
    whole( sort, odd2 );

    // 3. 2配列の最小絶対誤差を求める関数を使用する(誤差l-rが正ならrを進める、負ならlを進める、ただし配列サイズでクランプ)
    auto err = [&](vll &v1, vll &v2)->ll {
        ll l=0,r=0,mi=INFL;
        while(l<v1.size() && r<v2.size()) {
            ll dif=v1[l]-v2[r];
            mi=min(mi, abs(dif));
            if(l<v1.size() && dif<0) l++;
            else r++;
        }
        return mi;
    };

    // 4. odd1とodd2の最小絶対誤差、odd1,evenとodd2,evenの最小絶対誤差の和について小さい方を取る
    ll ans=min( err(odd1,odd2), err(odd1,even)+err(odd2,even) );
    cout << ans << endl;

}

//author: .rod.
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <chrono>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <random>
#include <cassert>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <cstring>
#include <unordered_map>
using namespace std;

#define ll int64_t
#define ld long double
#define ar array
#define vt vector
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()
#define for0(i,n) for(int i=0; i<n; i++)
#define for1(i,n) for(int i=1; i<n; i++)
#define for2(i,n) for(int i=2; i<=n; i++)
#define each(x, a) for (auto& x: a)
typedef double dl;

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)

template<class A> void read(vt<A>& v);
template<class A, size_t S> void read(ar<A, S>& a);
template<class T> void read(T& x) {
    cin >> x;
}
void read(double& d) {
    string t;
    read(t);
    d=stod(t);
}
void read(long double& d) {
    string t;
    read(t);
    d=stold(t);
}
template<class H, class... T> void read(H& h, T&... t) {
    read(h);
    read(t...);
}
template<class A> void read(vt<A>& x) {
    each(a, x)
        read(a);
}
template<class A, size_t S> void read(array<A, S>& x) {
    each(a, x)
        read(a);
}
string to_string(char c) {
    return string(1, c);
}
string to_string(bool b) {
    return b?"true":"false";
}
string to_string(const char* s) {
    return string(s);
}
string to_string(string s) {
    return s;
}
string to_string(vt<bool> v) {
    string res;
    FOR(sz(v))
        res+=char('0'+v[i]);
    return res;
}
template<size_t S> string to_string(bitset<S> b) {
    string res;
    FOR(S)
        res+=char('0'+b[i]);
    return res;
}
template<class T> string to_string(T v) {
    bool f=1;
    string res;
    each(x, v) {
        if(!f)
            res+=' ';
        f=0;
        res+=to_string(x);
    }
    return res;
}
template<class A> void write(A x) {
    cout << to_string(x);
}
template<class H, class... T> void write(const H& h, const T&... t) {
    write(h);
    write(t...);
}
void print() {
    write("\n");
}
template<class H, class... T> void print(const H& h, const T&... t) {
    write(h);
    if(sizeof...(t))
        write(' ');
    print(t...);
}
void DBG() {
    cerr << "]" << endl;
}
template<class H, class... T> void DBG(H h, T... t) {
    cerr << to_string(h);
    if(sizeof...(t))
        cerr << ", ";
    DBG(t...);
}
#ifdef _DEBUG
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

void solve() {
    int64_t n;
    read(n);
    set<int64_t>dt;
    for(int64_t i = 2; i*i<=n; i++){
        int64_t c = i*i;
        while(c<=n){
            dt.insert(c);
            c*=i;
        }
    }
    print(n-dt.size());
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    cerr << "time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
    return 0;
}


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

int main()
{
    int V, S, T, D;
    cin >> V >> S >> T >> D;

    if(V*S <= D && D <= V*T) cout << "No" << endl;
    else cout << "Yes" << endl;

    return 0;
}


#include <bits/stdc++.h>
#define i64 long long
#define sz(a) int((a).size())
#define all(a) (a).begin(), (a).end()
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define per(i, a, b) for (int i = (b) - 1; i >= (a); --i)
using namespace std;

const int N = 1e5 + 1;
int n, sp[N];
vector<int> prime;
bool vis[N];

void sieve() {
	vis[1] = true;
	rep(i, 2, n + 1) {
		if (not vis[i]) {
			sp[i] = 1;
			prime.push_back(i);
		}
		for (const int &p : prime) {
			if (i * p > n) {
				break;
			}
			vis[i * p] = true;
			sp[i * p] = sp[i] + 1;
			if (i % p == 0) {
				break;
			}
		}
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	sieve();
	rep(i, 1, n + 1) {
		cout << sp[i] + 1 << ' ';
	}
	cout << '\n';
	return 0;
}

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

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

    ll n;
    cin >> n;

    cout <<n-1;

    return 0;

}


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

#define INF  						1e15
#define EPS   						1e-9
#define MOD 						1000000007
#define Pi 							3.14159265358979323846264338327950288419716939937510

#define umap 						unordered_map
#define uset 						unordered_set
#define fi 							first
#define se 							second
#define ll 							long long
#define vi 							vector<int>
#define pii 						pair<int,int>
#define vll 						vector<ll>
#define pll							pair<ll,ll>
#define vvll						vector<vector<ll>>
#define pb 							push_back
#define pob 						pop_back
#define pf 							push_front
#define pof 						pop_front
#define maxE(a,n) 					*max_element(a,a+n);
#define minE(a,n) 					*min_element(a,a+n);
#define all(x) 						x.begin(), x.end()
#define rev(x)						reverse(all(x))
#define endl						"\n"

#define fast 						ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

#define rep(i,n)					for (ll  i=0;i<n;i++)
#define repd(i,n)					for (ll  i = n-1;i>=0;i--)
#define fori(i,a,n) 				for (ll  i=a;i<n;i++)
#define ford(i,a,n) 				for (ll  i=n-1;i>=a;i--)
#define trav(x,a)					for(auto x:a){cout<<x<<" ";}cout<<endl;

ll gcd(ll a, ll b) {	return __gcd(a, b);}
ll lcm(ll a, ll b) {return (a * b) / gcd(a, b);}
ll power(ll x, ll b, ll m) {ll p = 1; while (b > 0) {if (b & 1) {p = p * x; p %= m;} b >>= 1; x *= x; x %= m;} return p % m;}
void dbg(string s) {cout << s << endl;}

/*PBDS*/
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;

typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> PBDS;

// pbds.find_by_order(k) (return iterator to kth largest element(from 0))
// pbds.order_of_key(k) (return number of elements in set which are strictly less than k)

void solve() {

	ll n;
	cin >> n;

	vector<ll> a(n);
	rep(i, n) {
		cin >> a[i];

		a[i] = a[i] % 200;
	}

	ll ans = 0;
	umap<ll, ll> mp;
	rep(i, n) {
		ans += mp[a[i]];
		mp[a[i]]++;
	}

	cout << ans << endl;

}

int main() {

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

	fast;
	ll t = 1 ;
	while (t--) {
		solve();
	}
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
#define int long long
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define g0(a) get<0>(a)
#define g1(a) get<1>(a)
#define g2(a) get<2>(a)
#define g3(a) get<3>(a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef double db;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int N, ans, A[200005];
map<int, int> cnt;

main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> N;
	for (int i = 1; i <= N; i++) cin >> A[i];
	for (int i = 1; i <= N; i++) {
		// A[i] - A[j] = 0 (mod 200)
		// -A[j] = -A[i] (mod 200)
		// A[i] = A[j] (mod 200)
		cnt[A[i] % 200]++;
	}
	for (auto i : cnt)
		ans += i.second * (i.second - 1) / 2;
	cout << ans << '\n';
}


#include <bits/stdc++.h>
#define ll long long

using namespace std;

vector <int> vis;

void DFS(int x, vector <vector <int> > & g)
{
	vis[x] = 1;

	for (auto to: g[x])
		if (!vis[to])
			DFS(to, g);
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	map <int, vector <pair <int, int> > > mp;
	mp[n].push_back({0, 0});

	for (int i = 1; i <= m; i++)
	{
		int x, y;
		cin >> x >> y;
		mp[y].push_back({x, i});
	}

	for (auto & x: mp)
		sort(x.second.begin(), x.second.end());

	vector <vector <int> > g(m + 1);

	for (auto & x: mp)
	{
		int ptr = 0;

		for (int i = 0; i < x.second.size(); i++)
		{
			while (ptr < mp[x.first + 1].size() && mp[x.first + 1][ptr].first <= x.second[i].first)
				ptr++;

			int save_ptr = ptr, right_border = (i == x.second.size() - 1 ? 2 * n + 1 : x.second[i + 1].first);

			while (ptr < mp[x.first + 1].size() && mp[x.first + 1][ptr].first <= right_border)
				ptr++;

			for (int j = save_ptr; j < ptr; j++)
				g[x.second[i].second].push_back(mp[x.first + 1][j].second);
		}

		ptr = 0;

		for (int i = 0; i < x.second.size(); i++)
		{
			while (ptr < mp[x.first - 1].size() && mp[x.first - 1][ptr].first <= x.second[i].first)
				ptr++;

			int save_ptr = ptr, right_border = (i == x.second.size() - 1 ? 2 * n : x.second[i + 1].first);

			while (ptr < mp[x.first - 1].size() && mp[x.first - 1][ptr].first <= right_border)
				ptr++;

			for (int j = save_ptr; j < ptr; j++)
				g[x.second[i].second].push_back(mp[x.first - 1][j].second);
		}
	}

	vis.resize(m + 1);
	DFS(0, g);
	int ans = 0;

	for (auto & x: mp)
		if (x.second.size() && vis[x.second.back().second])
			ans++;

	cout << ans;
}

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

int main(){
    int n,m ;
    cin >> n >> m ;
    vll a(n) ;
    for(auto &i:a) cin >> i ;
    vector<pair<ll,ll>> b(m) ;
    for(auto &i:b) cin >> i.second >> i.first ;
    sort(b.begin(),b.end()) ;
    b.emplace_back(1e10,0ll) ;
    for(int i=1;i<m;i++) b[i].second = max(b[i].second,b[i-1].second) ;
    for(int i=0;i<n;i++) for(int j=0;j<m;j++){
        if(a[i]>b[j].first){
            cout << -1 << endl ;
            return 0 ;
        }
    }
    ll ans = 1e15 ;
    vector<int> c(n) ;
    for(int i=0;i<n;i++) c[i] = i ;
    do{
        vll d(n,0) ;
        for(int i=1;i<n;i++){
            ll sum = a[c[i]] ;
            for(int j=i-1;j>=0;j--){
                sum += a[c[j]] ;
                ll l=-1,r=m,mid ;
                while(l+1<r){
                    mid = (l+r)/2 ;
                    if(b[mid].first>=sum) r = mid ;
                    else l = mid ;
                }
                if(l<0) continue ;
                d[i] = max(d[i],d[j]+b[l].second) ;
            }
        }
        // cout << ans << endl ;
        ans = min(ans,d[n-1]) ;
    }while(next_permutation(c.begin(),c.end())) ;
    cout << ans << endl ;
}


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
#define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define fir first
#define sec second
#define mod 998244353
#define ll long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
typedef pair<int,int> pii;
void print(vector<int> x){for(int i=0;i<(int)x.size();i++) printf("%d%c",x[i]," \n"[i==(int)x.size()-1]);}
inline int add(int x,int y) {return x+y>=mod?x+y-mod:x+y;}
inline int add(int x,int y,int z) {return add(add(x,y),z);}
inline int sub(int x,int y) {return x-y<0?x-y+mod:x-y;}
inline int mul(int x,int y) {return 1LL*x*y%mod;}
inline int mul(int x,int y,int z) {return mul(mul(x,y),z);}
#define N 505
char s[N][N];
int n,m,ans=1;
signed main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++) scanf("%s",s[i]+1);
	for(int i=1;i<=n;i++)
	{
		int col=0;
		for(int j=1;j<=i;j++)
		{
			if(s[i-j+1][j]=='B')
			{
				if(!col) col=1;
				if(col==2) col=-1;
			}
			else if(s[i-j+1][j]=='R')
			{
				if(!col) col=2;
				if(col==1) col=-1;
			}
		}
		if(col==-1) ans=0;
		if(col==0) ans=add(ans,ans);
	}
	for(int i=2;i<=m;i++)
	{
		int col=0;
		for(int j=i;j<=m;j++)
		{
			if(n-(j-i)<=0) continue;
			char ch=s[n-(j-i)][j];
			if(ch=='B')
			{
				if(!col) col=1;
				if(col==2) col=-1;
			}
			else if(ch=='R')
			{
				if(!col) col=2;
				if(col==1) col=-1;
			}
		}
		if(col==-1) ans=0;
		if(col==0) ans=add(ans,ans);
	}
	cout<<ans<<endl;
	return 0;
}

/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author NikuKyabe
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define REV(i, a, b) for (int i = (b) - 1; i >= (a); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001l
#define MOD 1000000007
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class CMaxGCD2 {
public:
    /**
     * 約数全列挙
     * @param n 約数を求める数
     * @return 約数を昇順に並べたvector
     */
    vector<int> all_factor(int n){
        vector<int> ret;
        for(int i = 1; i * i <= n; i++){
            if(n % i == 0){
                ret.push_back(i);
                //iが約数の時，n/iも約数
                //i * i == nの時は重複する為加えない
                if(i * i != n) ret.push_back(n / i);
            }
        }
        sort(ret.begin(), ret.end());
        return ret;
    }
	void solve(std::istream& cin, std::ostream& cout) {
        int a,b;
        cin >> a >> b;
        map<int, int> memo;
        FOR(i, a, b+1){
            auto aa = all_factor(i);
            for(auto j : aa){
                memo[j]++;
            }
        }
        int ans = 1;
        for(auto itr = memo.begin(); itr != memo.end(); itr++){
            if(itr->second > 1){
                ans = max(ans, itr->first);
            }
        }
        cout << ans << endl;
	}
};

signed main() {
	CMaxGCD2 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

int main() {
	int n;
	cin>>n;
	long long a[200010];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	long long x=a[0];
	long long pow=1;
	for(int i=1;i<n;i++){
		x=(x+pow*a[i])%MOD;
		pow=(pow*2)%MOD;
	}
	cerr<<x<<endl;
	long long sum=(x*a[0])%MOD;
	for(int i=1;i<n;i++){
		long long y=x-a[i-1]-a[i];
		if(y%2==0){
			y=y/2;
		}
		else{
			y=(y+MOD)/2;
		}
		y=(y+a[i])%MOD;
		sum=(sum+y*a[i])%MOD;
		x=y;
	}
	cout<<sum<<endl;
	for(int i=0;i<n;i++){
		cerr<<a[i]<<endl;
	}
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define N 200000
#define mo 998244353

#define fo(i, x, y) for(int i = x; i <= y; i ++)
#define fd(i, x, y) for(int i = x; i >= y; i --)

void read(int &x) {
    char ch = getchar(); x = 0;
    while (ch < '0' || ch > '9') ch = getchar();
    while (ch >= '0' && ch <= '9') x = (x << 1) + (x << 3) + ch - 48, ch = getchar();
}

int a[N + 1], mi[N + 1];
int n;

int pw(int x, int k) {
    int res = 1;
    while (k) {
        if (k & 1) res = 1ll * x * res % mo;
        x = 1ll * x * x % mo;
        k >>= 1;
    }
    return res;
}

int main() {
    read(n);
    fo(i, 1, n) read(a[i]);
    int ans = 0, s = 0, inv = pw(2, mo - 2);
    mi[0] = 1;
    fo(i, 1, n) mi[i] = 1ll * mi[i - 1] * 2 % mo;
    sort(a + 1, a + 1 + n);
    fo(i, 2, n)
        s = (s + 1ll * a[i] * mi[i - 2] % mo) % mo;
    fo(i, 1, n - 1)
        ans = (ans + 1ll * a[i] * s % mo) % mo, s = 1ll * (s - a[i + 1] + mo) % mo * inv % mo;
    fo(i, 1, n) ans = (ans + 1ll * a[i] * a[i] % mo) % mo;
    printf("%d\n", ans);
    return 0;
}


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

#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

ll A[1000], B[1000];
ll C[1000], D[1000];

int main() {
    ll N, M, K;
    cin >> N >> M;
    rep(i, M){
        cin >> A[i] >> B[i];
        A[i]--;
        B[i]--;
    }
    cin >> K;
    rep(i, K){
        cin >> C[i] >> D[i];
        C[i]--;
        D[i]--;
    }

    int ans = 0;
    int X[1000];
    for (ll S = 0; S < 1 << K; S++){
        rep(i, N)X[i] = 0;

        rep(i, K){
            if (S >> i & 1){
                X[C[i]] = 1;
            } else {
                X[D[i]] = 1;
            }
        }
        int cnt = 0;
        rep (i, M){
            if (X[A[i]] && X[B[i]]){
                cnt++;
            }
        }
        chmax(ans, cnt);
    }
    cout << ans;
    return 0;
}

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

#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define run ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0);
#define mod 1000000007
#define decimal(k) cout<<fixed<<setprecision(k)<<endl
#define LL_MAX LLONG_MAX
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
int exp(int x,int y){int res=1;x=x%mod;while(y>0){if(y&1)res=(res*x)%mod;y=y>>1;x=(x*x)%mod;}return res;}
int modinv(int x){return exp(x,mod-2);}
int add(int a,int b){a%=mod,b%=mod;a=((a+b)%mod+mod)%mod;return a;}
int sub(int a,int b){a%=mod,b%=mod;a=((a-b)%mod+mod)%mod;return a;}
int mul(int a,int b){a%=mod,b%=mod;a=((a*b)%mod+mod)%mod;return a;}
int gcd(int a, int b){if (b == 0)return a; return gcd(b, a % b);}
int Log2n( int n){ return (n > 1) ? 1 + Log2n(n / 2) : 0;}
int fac[100009];int ncr_mod(int n,int k){int ans=fac[n];ans*=modinv(fac[k]);ans%=mod;ans*=modinv(fac[n-k]);ans%=mod;return ans;}
vector<int>v_prime;void Sieve(int n){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;}}for(int p = 2;p<= n;p++)if (prime[p])v_prime.pb(p);}
vector<int>v_factor;void factors(int n){ for (int i=1; i<=sqrt(n); i++) {if (n%i == 0) {if (n/i == i) v_factor.pb(i);else { v_factor.pb(i),v_factor.pb(n/i);};} } sort(all(v_factor)); }
void out(vector<int>&a){for(int i=0;i<a.size();i++) cout<<a[i]<<" ";  cout<<endl;}

int m,k,n,ans=0;
int a[1000009]={0},b[1000009],c[1000009],d[1000009];
vector<int>v;
// 0-->c
// 1-->d

void printTheArray(int arr[], int n)
{
    map<int,int>mp;
    int cnt=0;
    for (int i = 0; i < n; i++)
    {
         if(arr[i]==0)
         {
             mp[c[i]]++;
         }
         else
         {
             mp[d[i]]++;
         }
    }

    for(int i=0;i<m;i++)
    {
        if(mp[a[i]]*mp[b[i]]!=0)
              cnt++;
    }

   ans=max(ans,cnt);

}

void generateAllBinaryStrings(int n, int arr[], int i)
{
    if (i == n) {
        printTheArray(arr, n);
        return;
    }
    arr[i] = 0;
    generateAllBinaryStrings(n, arr, i + 1);

    arr[i] = 1;
    generateAllBinaryStrings(n, arr, i + 1);
}

signed main()
 {

       run;

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

             int  i;

                cin>>n>>m;

              for(i=0;i<m;i++)
              {
                 cin>>a[i];
                cin>>b[i];
              }

              cin>>k;

              int arr[k];

              for(i=0;i<k;i++)
              {
                 cin>>c[i];
                 cin>>d[i];
              }

        generateAllBinaryStrings(k,arr,0);
      cout<<ans<<endl;

}
}


#include <bits/stdc++.h>
using namespace std;
//using namespace atcoder;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define pb push_back
#define fi first
#define se second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void chOut(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using v_bool = vector<bool>;
using v_Pii = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;

struct edge{int to, cost, id;};

class Graph
{
public:
    int N;
    vector<vector<edge>> G;
    vec dp, dq;

    Graph(int N): N(N){
        G = vector<vector<edge>>(N, vector<edge>(0));
        dp.resize(N);
        dq.resize(N);
    }

    void add_Directed_edge(int from, int to, int cost = 1, int id = 0){
        G[from].push_back(edge({to, cost, id}));
    }

    void add_Undirected_edge(int v1, int v2, int cost = 1, int id = 0){
        add_Directed_edge(v1, v2, cost, id);
        add_Directed_edge(v2, v1, cost, id);
    }

    void dfs(int v, int T, int &num, int p = -1){
        dp[v] = T;
        dq[v] = -1;
        for(auto e: G[v]) if(e.to != p){
            dfs(e.to, T, num, v);
            if(dq[e.to] > 0){
                chmax(dq[v], dq[e.to] - 1);
            }else{
                chmin(dp[v], dp[e.to] - 1);
            }
        }
        if(dq[v] >= 0){
            if(dp[v] >= T - dq[v]) dp[v] = T + 1;
            else dq[v] = -1;
        }
        if(dp[v] == 0){
            num++;
            dq[v] = T;
        }
    }

};

signed main(){

    int K, N; cin >> N >> K;
    Graph G(N);
    REP(i, N - 1){
        int u, v; cin >> u >> v;
        u--; v--;
        G.add_Undirected_edge(u, v);
    }

    int T0 = 0, T1 = N;
    while(T1 - T0 > 1){
        int T = (T0 + T1) / 2;
        int num = 0;
        G.dfs(0, T, num);
        if(G.dq[0] == -1) num++;

        if(num <= K) T1 = T;
        else T0 = T;
    }
    Out(T1);

    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int N, M;
    cin >> N >> M;
    vector<vector<array<int, 2>>> A(N + 1);
    for (int i = 0; i < M; i++) {
        int X, Y, Z;
        cin >> X >> Y >> Z;
        A[X].push_back({Y, Z});
    }
    vector<int64_t> dp(1<<N);
    dp[0] = 1;
    for (int i = 0; i < (1 << N); i++) {
        int n = __builtin_popcount(i);
        int valid = 1;
        for (auto u : A[n]) {
            int m = __builtin_popcount(i & ((1 << u[0]) - 1));
            if (m > u[1]) {
                valid = 0;
                break;
            }
        }
        if (valid) {
            for (int j = 0; j < N; j++) {
                if ((i & (1 << j)) == 0) continue;
                dp[i] += dp[i^(1<<j)];
            }
        }
    }
    cout << dp[(1<<N) - 1];
}


#include "bits/stdc++.h"

using namespace std;

int main() {
    int a, b;

    cin >> a >> b;

    int c = 2 * a + 100;

    cout << ((c - b) > 0 ? c - b : 0) << endl;

    return 0;
}

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

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

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

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

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

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

void solve(vector <ll> &A, ll a) {
	ll p=2;
	while (p*p<=a) {
		if (a%p==0) {
			if (a%(p*p)==0) {return;}
			A[a]=-A[a/p];
			return;
			}
		p++;
		}
	A[a]=1;
	return;
	}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll l,r;
    cin>>l>>r;
    vector <ll> A(r+1,0);
    for (ll i=2;i<=r;i++) {
		solve(A,i);
		}
	ll ats=0;
	for (ll g=2;g<=r;g++) {
		ll k=r/g-(l-1)/g;
		ats+=A[g]*(k*(k-1))/2;
		//cout<<g<<" "<<k<<" "<<A[g]<<endl;
		}
	for (ll g=max(l,2LL);g<=r/2;g++) {
		ll k=r/g-(l-1)/g-1;
		ats-=k;
		}
	cout<<ats*2<<endl;
    return 0;
}


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

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

    ll N; cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    rep(i,N) if(i & 1) A[i] = -A[i];
    vector<ll> s(N + 1, 0);
    rep(i,N) s[i + 1] = s[i] + A[i];
    map<ll,ll> mp;
    rep(i,N+1) mp[s[i]]++;
    ll ans = 0;
    for(auto e : mp){
        ll num = e.first;
        ll cnt = e.second;
        ans += cnt * (cnt - 1) / 2;
    }
    cout << ans << endl;
}

#pragma GCC optimize ("O2")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
//#include<atcoder/all>
//using namespace atcoder;
#include<iostream>
#include<cstring>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	if ((tmp & ma0) ^ ma0) {
		int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
		tmp = tmp << dig & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += (72 - dig >> 3);
	}
	else {
		tmp = tmp & ma1;
		tmp = tmp * 10 + (tmp >> 8) & ma2;
		tmp = tmp * 100 + (tmp >> 16) & ma3;
		tmp = tmp * 10000 + (tmp >> 32) & ma4;
		ci += 8;
		if ((ct = *ci++) >= '0') {
			tmp = tmp * 10 + ct - '0';
			if (*ci++ == '0') {
				tmp = tmp * 10;
				ci++;
			}
		}
	}
	return tmp;
}
ll num[524310];
const ll dekai = 1ll << 60;
int kazu[524310];
const int ma = (1 << 19) - 1;
int query(ll n) {
	int n2 = (n & ma) | 1;
	while (num[n2]) {
		if (num[n2] == (n | dekai)) return kazu[n2];
		n2 = n2 * 2 % 524309;
	}
	return 0;
}
void add(ll n) {
	int n2 = (n & ma) | 1;
	while (num[n2]) {
		if (num[n2] == (n | dekai)) {
			kazu[n2]++;
			return;
		}
		n2 = n2 * 2 % 524309;
	}
	num[n2] = n | dekai;
	kazu[n2] = 1;
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N = getint();

	add(0);
	ll kotae = 0;
	ll ima = 0;
	int pn = 1;
	rep(i, N) {
		ima += pn * getint();
		kotae += query(ima);
		add(ima);
		pn = -pn;
	}

	co(kotae);

	Would you please return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define inf 0x7f7f7f7f
#define MAX_SIZE 1000001
#define debug(x) cout<<#x<<" "<<x<<"\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);freopen("error.txt","w",stderr);
#define vi(vec,n) vector<ll>vec(n)
#define vio(vec,n,a) vector<ll>vec(n,a)
#define FOR(i,a,b,c) for(ll i=a;(c)?i<(ll)b:i>=(ll)b;(c)?i+=1:i-=1)
#define eb emplace_back
#define mod (ll)(1e9+7)
#define all(a,b) memset(a,b,sizeof a)
#define whole(v) v.begin(),v.end()
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define x first
#define y second

int32_t main(){
    //clock_t tStart = clock();
    // file;
    fast;

    int n,m;
    cin >> n >> m;
    string ar[n];
    for(int i = 0;i < n;i++){
            cin >> ar[i];
    }
    int dp[n][m];
    for(int i = n-1;i >= 0;i--){
        for(int j = m-1;j >= 0;j--){
            dp[i][j] = -((int)1e18);
            if(i==n-1 and j==m-1){
                dp[i][j] = 0;
                continue;
            }
            if(j != m-1){
                dp[i][j] = max(dp[i][j],-dp[i][j+1]+((ar[i][j+1]=='+') ? 1 : -1));
            }
            if(i != n-1){
                dp[i][j] = max(dp[i][j],-dp[i+1][j]+((ar[i+1][j]=='+') ? 1 : -1));
            }
        }
    }
    if(dp[0][0] == 0) cout << "Draw";
    else if(dp[0][0] > 0) cout << "Takahashi";
    else if(dp[0][0] < 0) cout << "Aoki";

    //printf("Time taken: %.6fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
    return 0;
}

#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <array>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

int M[2001][2001];
int H, W;
vector<vector<int>> dp(2001,vector<int>(2001, -1));

int dfs(int i, int j)
{
  if(dp[i][j] != -1) return dp[i][j];

  int ret;
  if ((i + j) % 2 == 0) {
    ret = -1e9;
    if (i + 1 < H) ret = max(ret, dfs(i + 1, j) + M[i + 1][j]);
    if (j + 1 < W) ret = max(ret, dfs(i, j + 1) + M[i][j + 1]);
  } else {
    ret = 1e9;
    if (i + 1 < H) ret = min(ret, dfs(i + 1, j) - M[i + 1][j]);
    if (j + 1 < W) ret = min(ret, dfs(i, j + 1) - M[i][j + 1]);
  }
  return dp[i][j] = ret;
}

int main(){
  cin>> H >> W;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      char c;
      cin >> c;
      if (c == '+') {
        M[i][j] = 1;
      } else {
        M[i][j] = -1;
      }
    }
  }

  dp[H - 1][W - 1] = 0;

  int ans = dfs(0, 0);
  if (ans == 0) {
    cout << "Draw\n";
  } else if (ans > 0) {
    cout << "Takahashi\n";
  } else {
    cout << "Aoki\n";
  }

  return 0;
}


#include<cmath>
#include<cstdio>
#include<vector>
#include<cstring>
#include<utility>
#include<iostream>
#include<algorithm>
using namespace std;

typedef long long ll;
const int M=25,N=(1<<18)+10;

int n,m,a[M];
vector<pair<int,int> > e[M];
ll dp[N];

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		e[x].push_back(make_pair(y,z));
	}
	dp[0]=1;
	for(int st=1;st<(1<<n);st++)
	{
		int X=0;
		for(int i=0;i<n;i++)
			if(st&(1<<i))X++;
		bool ff=true;
		for(int i=0;i<e[X].size();i++)
		{
			int y=e[X][i].first,z=e[X][i].second;
			int Z=0;
			for(int j=0;j<y;j++)
				if(st&(1<<j))Z++;
			if(Z>z)
			{
				ff=false;
				break;
			}
		}
		if(ff)
			for(int i=0;i<n;i++)
				if(st&(1<<i))
					dp[st]+=dp[st^(1<<i)];
	}
	printf("%lld",dp[(1<<n)-1]);
	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;
}
int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> MAX(n + 1, vector<int>(n));
    rep(i, n + 1) rep(j, n) MAX[i][j] = INF;
    rep(i, m) {
        int x, y, z;
        cin >> x >> y >> z;
        chmin(MAX[x][--y], z);
        // for (int j = y - 1; j < n; j++) chmin(MAX[x][j], z);
    }
    // rep(i, n) cout << MAX[i] << '\n';

    vector<ll> dp(1 << n);
    dp[0] = 1;
    vector<int> bits(1 << n);
    rep(i, 1 << n) bits[i] = i;
    sort(all(bits), [](int i, int j) {
        return __builtin_popcount(i) < __builtin_popcount(j);
    });
    for (int bit : bits) {
        int c = __builtin_popcount(bit);

        rep(nxt, n) if (~bit >> nxt & 1) {
            bool ok = 1;
            rep(j, n) {
                int cnt = 0;
                if (nxt <= j) cnt++;
                rep(k, j + 1) cnt += bit >> k & 1;
                ok &= cnt <= MAX[c + 1][j];
            }
            if (ok) dp[bit | 1 << nxt] += dp[bit];
        }
    }
    cout << dp[(1 << n) - 1] << '\n';
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int n,x;
	scanf("%d %d",&n,&x);
	string s;
	cin>>s;
	for(int i = 0;i<s.size();i++){
		if(s[i] == 'o')x++;
		else if(s[i] == 'x'){
			if(x>0)x--;
		}
	}
	printf("%d",x);
	return 0;
}

#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define ins insert
#define len(s) s.length()
#define forp(i, a, b) for (int i = a; i <= b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define ren(i, n) for (int i = n - 1; i >= 0; i--)
#define forn(i, a, b) for (int i = a; i >= b; i--)
#define on cout << endl
#define all(v) v.begin(), v.end()
#define mem(n, m) memset(n, m, sizeof(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define sii set<int>
#define us unordered_set<int>
#define um unordered_map<int, int>
#define sll set<long long>
#define vii vector<int>
#define vll vector<long long>
#define mll map<long long, long long>
#define lob lower_bound
#define upb upper_bound
#define ret return 0

#define boost ios_base::sync_with_stdio(0)
#define MOD 1000000007
#define EPSILON 1e-9
#define PI 3.14159265358979323846
#define inf 999999999999999999
#define siz 100001
#define SIZ 1000001
#define SIZE 200001

typedef long long ll;
typedef long double ldo;
typedef double db;
using namespace std;
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)

#define setpre fixed << setprecision(10)
// ---->>|<<----Arise,Awake and stop not till the goal is reached... :) ---->>|<<----

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

    ll n, x;
    cin >> n >> x;
    string s;
    cin >> s;
    ll ans = x;
    for (ll i = 0; i < len(s); i++)
    {
        if (s[i] == 'x')
        {
            ans--;
            if (ans < 0)
            {
                ans = 0;
            }
        }
        else
        {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}
// author -> aditya kumar mishra


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed
#define endl '\n'

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

void solve(istream& cin, ostream& cout) {
  int k;
  cin >> k;
  ll ans = 0;
  FOR(i, 1, k) {
    int a = i;
    int b = 1;
    while(a * b <= k) {
      int c = k / (a * b);
      ans += c;
      b++;
    }
  }
  cout << ans << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
  return 0;
}
#endif

#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <queue>
#include <string>
#include <utility>
using namespace std;
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(){
    int K;
    cin >> K;
    ll ans = 0;
    for(int c=1;c<=K;c++){
        for(int b=1;b<=K/c;b++){
            ans += K/(b*c);
        }
    }
    cout << ans << endl;
}


//Codeforcesで128bit整数を使いたいとき
//→__int128_tを使う&GNU C++17 (64)で提出する

//インクルードなど
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

//イテレーション
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define FORA(i,I) for(const auto& i:I)
//x:コンテナ
#define ALL(x) x.begin(),x.end()
#define SIZE(x) ll(x.size())
//定数
#define INF32 2147483647 //2.147483647×10^{9}:32bit整数のinf
#define INF64 9223372036854775807 //9.223372036854775807×10^{18}:64bit整数のinf
#define MOD 1000000007 //問題による
//略記
#define F first
#define S second
//出力(空白区切りで昇順に)
#define coutALL(x) for(auto i=x.begin();i!=--x.end();i++)cout<<*i<< " "; cout<<*--x.end()<<endl;

//aをbで割る時の繰上げ,繰り下げ
ll myceil(ll a,ll b){return (a+(b-1))/b;}
ll myfloor(ll a,ll b){return a/b;}

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

using Graph = vector<vector<int>>;

// 深さ優先探索
vector<int> ans;
vector<int> C;
vector<int> cnt(100001, 0);
vector<bool> seen;
void dfs(const Graph &G, int v) {
    seen[v] = true; // v を訪問済にする

    // v から行ける各頂点 next_v について
    if(cnt[C.at(v)] == 0) ans.push_back(v+1);
    cnt[C.at(v)]++;
    for (auto next_v : G[v]) {
        if (seen[next_v]) continue; // next_v が探索済だったらスルー
        dfs(G, next_v); // 再帰的に探索
    }
    cnt[C.at(v)]--;
}

int main(){
   //小数の桁数の出力指定
   cout<<fixed<<setprecision(10);
   //入力の高速化用のコード
   ios::sync_with_stdio(false);
   cin.tie(nullptr);

   int N; cin >> N;
   C.assign(N, 0);
   for(int i = 0; i < N; ++i) {
       cin >> C.at(i);
       C.at(i)--;
   }

    // グラフ入力受取
    Graph G(N);
    for (int i = 0; i < N-1; ++i) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    seen.assign(N, false);
    dfs(G, 0);
    sort(ans.begin(), ans.end());
    for(auto a : ans) cout << a << endl;
}

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

    //                                 (POLICY BASED DS)
    // #include <ext/pb_ds/assoc_container.hpp>
    // #include <ext/pb_ds/tree_policy.hpp>
    // using namespace __gnu_pbds;
    // template<typename T>
    // using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
    // template<typename T>
    // using ordered_multiset=tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;
    //                      ( find_by_order( )  ,  order_of_key( ) )

    typedef long long ll;
    typedef long double ld;
    typedef unsigned long long ull;
    typedef vector<long long> vll;
    typedef pair<ll,ll> pll;

    const ll mod = 1e9 + 7;
    const ld PI = 3.1415926535897932384626;
    const ld eps = 1e-9;

    #define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
    #define sidha(i,a,b) for(ll i=(ll)(a);i<(ll)(b);++i)
    #define ulta(i,a,b) for(ll i=(ll)(a);i>=(ll)(b);--i)
    #define stl(container,itr) \
        for(auto itr = container.begin(); itr != container.end(); itr++)
    #define sab(v) v.begin(), v.end()
    #define rall(v) v.rbegin(), v.rend()
    #define test ll t;cin>>t;while(t--)
    #define sz size()
    #define pb push_back
    #define mp make_pair
    #define fi first
    #define se second
    #define LOG2(X) (63ll - __builtin_clzll(X))
    #define endl '\n'
    #define modinv(x) powermod(x, mod-2)
    #define mktree(x) ll a,b; sidha(i,0,x){cin>>a>>b; adj[a].pb(b); adj[b].pb(a);}
    #define ncr(n,r) ( (n) >= (r) ? ((((fact[n]*modinv(fact[r]))%mod)*modinv(fact[n-(r)]))%mod) : (ll)0)
    #define MAX 100005

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

    ll power(ll x, ll y) {
        ll ans=1;
        while(y>0) {
            if (y&1)
                ans=(ans*x);
            y=y>>1;
            x=(x*x);
        }
        return ans;
    }

    ll gcd(ll x,ll y){
       if(y==0) return x;
       return   gcd(y,x%y);
    }

    ll ceil(ll x,ll y){
        return ( (x/y)+(x%y!=0) );
    }

    // vector<ll> adj[MAX];
    // ll visit[MAX];
    // void dfs(ll node){
    //     visit[node]=1;
    //     for(auto i : adj[node]){
    //         if(!visit[i]) dfs(i);
    //     }
    // }

    // ll spf[MAX];
    // void sieve(){
    //     sidha(i,1,MAX)  spf[i]=i;
    //     for(ll i=4;i<MAX;i+=2)  spf[i]=2;
    //     for(ll i=3;i*i<=MAX;i++){
    //         if(spf[i]==i){
    //             for(ll j=i*i;j<MAX;j+=i){
    //                 if(spf[j]==j)   spf[j]=i;
    //             }
    //         }
    //     }
    // }

    //                 use pow , ceil , max , min with precaution :)
    int main()
    {
        boost;
        clock_t begin,end;
        begin=clock();

        char c1,c2,c3;
        cin>>c1>>c2>>c3;
        if(c1==c2 and c2==c3)   cout<<"Won";
        else    cout<<"Lost";

        end=clock();
        double tot_time=double(end-begin)/double(CLOCKS_PER_SEC);
        // cout<<"Time Taken: "<<fixed<<setprecision(3)<<tot_time;
        return 0;
    }


#include<bits/stdc++.h>
#define int long long
using namespace std;
int b,c,ans;
signed main()
{
	scanf("%lld%lld",&b,&c);
	int que=c/2,ko=(c-1)/2,ko2=(c-2)/2;
//	b=abs(b);
	int l1=b-que,r1=b+ko2;
	int l2=-b-ko,r2=-b+ko;
	if(l1<=r2) printf("%lld\n",max(r1,r2)-min(l1,l2)+1);
	else printf("%lld\n",r1-l1+1+r2-l2+1);

	return 0;
}

#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>
#include <random>

#define FOR_LT(i, beg, end) for (decltype(end) i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (decltype(end) i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (decltype(beg) i = beg; end <= i; i--)
#define REP(n)              for (decltype(n) repeat_index = 0; repeat_index < n; repeat_index++)

using namespace std;

template<typename T, size_t S>
T minval(const T(&vals)[S])
{
	T val = numeric_limits<T>::max();
	FOR_LT(i, 0, S) {
		val = min(val, vals[i]);
	}
	return val;
}

template<typename T, size_t S>
T maxval(const T(&vals)[S])
{
	T val = numeric_limits<T>::min();
	FOR_LT(i, 0, S) {
		val = max(val, vals[i]);
	}
	return val;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int n, k; cin >> n >> k;
	string s; cin >> s;
	if (s.size() & 1) {
		s = s + s;
	}

	REP(k) {
		FOR_LT(i, 0, s.size() / 2) {
			if (s[i * 2] == s[i * 2 + 1]) {
				s[i] = s[i * 2];
				continue;
			}

			bool hand[3] = {};
			FOR_LT(j, 0, 2) {
				switch(s[i * 2 + j]) {
				case 'R': hand[0] = true; break;
				case 'P': hand[1] = true; break;
				case 'S': hand[2] = true; break;
				}
			}
			FOR_LT(j, 0, 3) {
				if (!hand[j]) {
					switch (j) {
					case 0: s[i] = 'S'; break;
					case 1: s[i] = 'R'; break;
					case 2: s[i] = 'P'; break;
					}
				}
			}
		}
		FOR_LT(i, 0, s.size() / 2) {
			s[s.size() / 2 + i] = s[i];
		}
	}

	cout << s[0] << endl;

	return 0;
}


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

short M, H;

int main()
{
	cin>>M>>H;
	if(H%M) cout<<"No\n";
	else cout<<"Yes\n";

	return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
int main() {
  ll A, B;
  cin >> A >> B;
  if(B % A == 0) {
    cout << "Yes";
  }
  else {
    cout << "No";
  }
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long ;
int main(){
    int a;
    cin >> a;
    if(a >= 0) cout << a << endl;
    else cout << 0 << endl;
}

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

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

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define pb push_back
#define nl cout<<"\n"
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

const ll MOD = 1000000007;
ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; }

const int MAXN = 1e5+5;
const int LOGN = 21;
const ll INF = 1e14;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

template<class T1, class T2> void add( T1 &x, T2 y, ll m = MOD )
{
    x += y;
    if( x >= m )
        x -= m;
}

template<class T1, class T2> void sub( T1 &x, T2 y, ll m = MOD )
{
    x -= y;
    if( x < 0 )
        x += m;
}

int main()
{
    #ifdef gupta_samarth
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    fastio();

    int x;
    cin>>x;
    cout<<( x >= 0 ? x : 0 );

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MN LLONG_MIN
#define MX LLONG_MAX
#define UL ULLONG_MAX
#define pb push_back
#define e "\n"
#define iff(u,v)  if(abs(u-v)<1e-9)
#define vi vector<long long>v,v1,v2;
#define pi 3.1415926536
#define fix cout<<fixed; cout<<setprecision(10);
#define dc ll i,j,k,n,m,len,ans=0,mx=-1,mn,sum=0; string s,t; bool flag=false;

void solve()
{
	dc;  cin>>n; m=n; ++m; k=1;
	while(k<=m)
	{
		m-=k; ++k; sum++;
	}
	cout<<n-sum+1<<e;
}

int main()
{
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    //int t; cin>>t; while(t--)solve();
    solve();
}

#include<bits/stdc++.h>
using namespace std;
#define ff                first
#define brn                "\n"
#define ss                second
#define mk                make_pair
#define int               long long
#define pb                push_back
#define ps(x,y)           fixed<<setprecision(y)<<x
#define w(x)              int x; cin>>x; while(x--)
#define FOR(i,a,b)        for(int i=(a);i<(b);i++)
#define ROF(i,a,b)        for(int i=(a);i>=(b);i--)
#define so(a,n)           sort(a,a+n)
#define rso(a,n)          sort(a,a+n),reverse(a,a+n)
#define all(v)            (v).begin(),(v).end()
#define ps(x,y)           fixed<<setprecision(y)<<x
#define sz                size();
#define p_sieve           10000007
const int                 maxn = 1e3 + 5;
const int                 modulo=1000000007;
#define mod               1000000009;
const double              pi=3.14159;

void solve()
{

	int n;cin>>n;
	int i=1;
	while((i*(i+1))/2<=(n+1))i++;
	cout<<(n+1-i)+1;
}
//########################---------code ends here------------------########################################################
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  //prime_sieve();
   // w(t)
    solve();
}


#include <bits/stdc++.h>
#define task "triangles"
#define pb push_back
#define pll pair<ll, ll>
#define pii pair< pll, ll>
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;

const int N = 2e5+5;
const ll mod = 1e5;
const ll ex = 1e5;

ll n, m, t, k, tong, a[N][5], b[N], T, ans, c[N], d[32][3], h[N], lo;
vector<ll> adj[N], kq;
string s, res;

bool check(ll x)
{
    memset(d, 0, sizeof(d));
    for(int i = 1; i <= n; i ++)
    {
        k = 0;
        for(int j = 0; j <= 4; j ++)
        {
            if(a[i][j] >= x)k |= (1<<j);
        }
        b[i] = k;
        d[k][0] = 1;
        //cout << b[i] <<" ";
    }
    for(int i = (1<<5)-1; i >= 0; i --)
    {
        for(int j = 0; j < 5; j ++)
        {
            if((i >> j) & 1)d[(i^(1<<j))][0] |= d[i][0];
        }
    }
    for(int l = 1; l <= 2;l  ++)
    {
        for(int i = (1<<5) - 1; i >= 0; i --)
        {
            for(int j = 1; j <= n ; j ++)
            {
                k = i ^ b[j];
                k = i & k;
                d[i][l] |= d[k][l-1];
            }
            for(int j = 0; j < 5; j ++)
            {
                if((i >> j) & 1)d[(i^(1<<j))][l] |= d[i][l];
            }
        }
    }
    return d[(1<<5)-1][2] == 1;
}
void sol()
{
    deque<char> q;
    cin >> s;
    for(int i = 0; i < s.length(); i ++)
    {
        char c = s[i];
        if(c == 'R')k ^= 1;
        else
        {
            if(k == 0)
            {
                q.pb(c);
            }
            else
            {
                q.push_front(c);
            }
        }
    }
    string res;
    //cout << k << " ";
    if(k == 0)
    {
        while(!q.empty())
        {
            if(!res.empty() && q.front() == res.back())
            {
                q.pop_front();
                res.pop_back();
                continue;
            }
            res += q.front();
            q.pop_front();
        }
    }
    else
    {
        while(!q.empty())
        {
            if(!res.empty() && q.back() == res.back())
            {
                q.pop_back();
                res.pop_back();
                continue;
            }
            res += q.back();
            q.pop_back();
        }
    }
    cout << res;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    if (fopen(task".in", "r"))
        freopen(task".in", "r", stdin),
            freopen(task".out", "w", stdout);

    int ntest = 1;
    //cin >> ntest;
    while(ntest -- > 0)
    sol();
}
/*
3 4
1 (
3 )
2 )
3 )

-1 0 1 0 -1
*/

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repp(i, st, en) for (ll i = (ll)st; i < (ll)(en); i++)
#define repm(i, st, en) for (ll i = (ll)st; i >= (ll)(en); i--)
#define all(v) v.begin(), v.end()
void chmax(ll &x, ll y) {x = max(x,y);}
void chmin(ll &x, ll y) {x = min(x,y);}

void Yes() {cout << "Yes" << endl; exit(0);}
void No() {cout << "No" << endl; exit(0);}
void Cout(ll x) {cout << x << endl; exit(0);}

const ll inf = 1e18;

// 計算量(logN)
ll gcd(ll a, ll b) {
   if (a%b == 0) return b;
   else return gcd(b, a%b);
}

int main() {
    ll N; cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];

    ll L = inf;

    map<ll,ll> t;
    rep(i,N) {
        ll a = A[i];
        chmin(L,a);
        for (ll j=1; j*j<=a; j++) {
            if (a%j) continue;
            ll x = j, y = a/j;
            if (t[x]==0) t[x] = a;
            else t[x] = gcd(t[x],a);
            if (t[y]==0) t[y] = a;
            else t[y] = gcd(t[y],a);
        }
    }
    ll ans = 0;
    for (auto p : t) {
        ll x = p.first, y = p.second;
        if (x>L) break;
        if (x!=y) continue;
        ans++;
    }

    cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll           long long
#define rep(i,j,n)   for(ll i=j;i<n;i++)
#define scn(a)       scanf("%lld",&a)
#define scns(a,b)    scanf("%lld %lld",&a,&b)
#define print(a)     printf("%lld\n",a)
#define vec          vector<ll>
#define pb           push_back
#define pairs        pair<ll,ll>
#define f            first
#define s            second
#define all(v)       v.begin(),v.end()
#define mem(a,b)     memset(a,b,sizeof(a))
#define tc 			ll it;scanf("%lld",&it); while(it--)
#define inf          1e18
#define fast         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int mod = 1e9+7;
const int N = 2e5+5;
int main()
{
	ll n,ans=0;
	cin>>n;
	map<ll,ll> m;

	ll a[n];
	rep(i,0,n)
	{
		cin>>a[i];

		m[a[i]%200]++;
	}

	for(auto t:m)
	{
		if(t.s>1)
		ans+=((t.s-1)*t.s/2);
	}

	cout<<ans;
}

///====================== TEMPLATE STARTS HERE =====================///
#include <bits/stdc++.h>
using namespace std;

#define endl "\n"
#define pb push_back
#define MP make_pair
#define ff first
#define ss second
#define ABS(x) ((x)<0?-(x):(x))
#define FABS(x) ((x)+eps<0?-(x):(x))
#define LCM(x,y) (((x)/gcd((x),(y)))*(y))
#define POPCOUNT __builtin_popcountll
#define Set(N,p) ((N)|((1LL)<<(p)))
#define Reset(N,p) ((N)&(~((1LL)<<(p))))
#define Check(N,p) (!(((N)&((1LL)<<(p)))==(0)))
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL)

#define LL long long
#define LLU long long unsigned int
typedef pair < int, int > pii;
typedef pair < LL, LL > pll;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef vector<pll> vll;

#ifdef s_da_sailor
    #define line                    cout << "\n===================\n"
    #define trace(...)              __f( #__VA_ARGS__ , __VA_ARGS__ )
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cerr << name << " = " << arg1 << "\n";
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ',');
        cerr.write(names, comma - names) << " = " << arg1 << " , ";
    __f(comma + 1, args...);
    }
#else
    #define line
    #define trace(...)
#endif // s_da_sailor

inline LL gcd ( LL a, LL b ) {
    a = ABS ( a ); b = ABS ( b );
    while ( b ) { a = a % b; swap ( a, b ); } return a;
}

LL ext_gcd ( LL A, LL B, LL *X, LL *Y ){
    LL x2, y2, x1, y1, x, y, r2, r1, q, r;
    x2 = 1; y2 = 0;
    x1 = 0; y1 = 1;
    for (r2 = A, r1 = B; r1 != 0; r2 = r1, r1 = r, x2 = x1, y2 = y1, x1 = x, y1 = y ) {
        q = r2 / r1;
        r = r2 % r1;
        x = x2 - (q * x1);
        y = y2 - (q * y1);
    }
    *X = x2; *Y = y2;
    return r2;
}

inline LL modInv ( LL a, LL m ) {
    LL x, y;
    ext_gcd( a, m, &x, &y );
    x %= m;
    if ( x < 0 ) x += m;
    return x;
}

inline LL bigmod ( LL a, LL p, LL m ) {
    LL res = 1 % m, x = a % m;
    while ( p ) {
        if ( p & 1 ) res = ( res * x ) % m;
        x = ( x * x ) % m; p >>= 1; /// For bigmod2 multiply here using mulmod
    }
    return res;
}

//int knightDir[8][2] = { {-2,1},{-1,2},{1,2},{2,1},{2,-1},{-1,-2},{1,-2},{-2,-1} };
//int dir4[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};
//int dir8[8][2] = {{-1,0},{0,1},{1,0},{0,-1},{-1,-1},{1,1},{1,-1},{-1,1}};
const LL inf = 2147383647;
const LL mod = 1000000007;
const double pi = 2 * acos ( 0.0 );
const double eps = 1e-11;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); /// For generating random numbers

///======================  TEMPLATE ENDS HERE  =====================///

LL nod(LL n) {
    LL ret = 0;
    while(n>0) {
        n /= 10;
        ret++;
    }
    return ret;
}

void solve() {
    LL n;
    cin >> n;

    LL dig = nod(n);

    LL curr = 9LL, ret = 0, temp = 0;
    for(LL i=1; i<dig; i++) {
        ret += (curr * ((i-1LL)/3LL) );
        temp += curr;
        curr *= 10;
    }

    LL extra = n-temp;
    ret += ( extra * ((dig-1LL)/3LL) );

    cout << ret << endl;
}

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

    fast_cin;

    solve();

    return 0;
}


#include "iostream"
using namespace std;
#include "string"
#include "vector"
#include "unordered_set"
#include "map"
#include "stack"
#include "algorithm"
#include "queue"
#define int long long
#define pi pair<int,int>
#define ff first
#define ss second
#define boost ios::sync_with_stdio(false);cin.tie(nullptr)
#define endl '\n'
#define vi vector<int>

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

int32_t main() {
    boost;
    int n;
    cin >> n;
    vi a(n);
    for(int &i : a)
        cin >> i;
    int mini = *min_element(a.begin(), a.end());
    map<int, int> mp;
    for(int &i : a) {
        for(int j = 1; j * j <= i; j++) {
            if(i % j == 0) {
                mp[j] = Gcd(mp[j], i);
                mp[i / j] = Gcd(mp[i / j], i);
            }
        }
    }

    int ans = 0;
    for(auto x : mp) {
        if(x.ff <= mini && x.ff == x.ss)
            ans++;
    }
    cout << ans << endl;

}

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int GCD(int x, int y){
    if(x == 0 && y == 0) return 0;
    if(x>y){
        int swap = x;
        x = y;
        y = swap;
    }
    while(true){
        if(y%x==0){
            return x;
        }else{
            int amari = y%x;
            y = x;
            x = amari;
        }
    }
}

vector<ll> yakusuu_rekkyo(ll n){
    vector<ll> divisors;
    for(ll i = 1; i <= n; i++){
        if(i * i > n)break;
        if(i * i == n){
            divisors.push_back(i);
            break;
        }else if(n % i == 0){
            divisors.push_back(i);
            divisors.push_back(n/i);
        }
    }
    sort(divisors.begin(), divisors.end());
    return divisors;
}

int main() {
    int n; cin >> n;
    int a[n] = {};
    rep(i,n) cin >> a[i];
    sort(a,a+n);

    set<int> se;
    rep(i,n){
        vector<ll> v = yakusuu_rekkyo(a[i]);
        rep(j,v.size()) se.insert(v[j]);
    }

    int ans = 0;
    for(auto x: se){
        if(x > a[0]) continue;
        int now = -1;
        rep(i,n){
            if(a[i] % x == 0){
                if(now == -1){
                    now = a[i];
                }else{
                    now = GCD(now, a[i]);
                }
            }
        }
        if(now == x) ans++;
    }

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


#include <bits/stdc++.h>
#define MAX_N (200000 + 5)
#define LL long long
using namespace std;
const int mod = 998244353;
int n, m;
int inv[MAX_N];
int p[MAX_N], tot;
bool is[MAX_N];
int pw[MAX_N], f[MAX_N];
int main() {
	scanf("%d%d", &n, &m);
	inv[1] = 1;
	for (int i = 2; i <= m; ++i) inv[i] = (LL)(mod - mod / i) * inv[mod % i] % mod;
	for (int i = 2; i <= m; ++i) {
		if (!is[i]) p[++tot] = i, pw[i] = 1, f[i] = n;
		for (int j = 1; i * p[j] <= m; ++j) {
			is[i * p[j]] = 1;
			if (i % p[j]) {
				pw[i * p[j]] = 1;
				f[i * p[j]] = (LL)f[i] * n % mod;
			}
			else {
				pw[i * p[j]] = pw[i] + 1;
				f[i * p[j]] = (LL)f[i] * (n + pw[i]) % mod * inv[pw[i] + 1] % mod;
				break;
			}
		}
	}
	int ans = 1;
	for (int i = 2; i <= m; ++i) ans = (ans + f[i]) % mod;
	printf("%d", ans);
	return 0;
}

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

long long int MOD = 998244353;

long long int power(long long int b, long long int e) {
    if (e == 0)
        return 1;
    long long int temp = power(b, e / 2);
    if (e % 2 == 0)
        return temp * temp % MOD;
    return (temp * temp) % MOD * b % MOD;
}

long long int inv(long long int n) {
    return power(n, MOD - 2);
}

const int N = 200200;
long long int f[N], rf[N];

long long int choose(long long int n, long long int r) {
    if (r < 0 || r > n) return 0;
	return (f[n] * rf[r]) % MOD * rf[n - r] % MOD;
}

void solve() {
    int n,m; cin >> n >> m;
    if (n == 1) {
        cout << m;
        return;
    }

    f[0] = 1;
	for (int i = 1; i < N; i++)
		f[i] = f[i - 1] * i % MOD;
	rf[N - 1] = inv(f[N - 1]);
	for (int i = N - 1; i > 0; i--)
		rf[i - 1] = rf[i] * i % MOD;

    vector<vector<long long int>> dp(m + 1, vector<long long int>(20));
    dp[1][0] = 1;
    for (int k = 0; k < 19; k++) {
        for (int i = 1; i <= m; i++) {
            if (dp[i][k] == 0) continue;

            for (int j = 2 * i; j <= m; j += i) {
                dp[j][k + 1] += dp[i][k];
                dp[j][k + 1] %= MOD;
            }
        }
    }

    long long int ans = 0;
    for (int i = 0; i <= min(n, 19); i++) {
        long long int total = 0;
        for (int j = 1; j <= m; j++) {
            total += dp[j][i];
            total %= MOD;
        }
        ans += total * choose(n, i);
        ans %= MOD;
    }
    cout << ans;
}

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

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

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;
const double pi = acos(-1);

int n, xa, ya, xb, yb;

struct Point{
    double x, y;
    Point(double x = 0, double y = 0):x(x),y(y){}
};
typedef Point Vector;

Vector Rotate(Vector A, double rad){//rad为弧度 且为逆时针旋转的角
    return Vector(A.x*cos(rad)-A.y*sin(rad), A.x*sin(rad)+A.y*cos(rad));
}

int main()
{
    scanf("%d%d%d%d%d", &n, &xa, &ya, &xb, &yb);
    double xmid = (xa + xb) / 2.0;
    double ymid = (ya + yb) / 2.0;
    Vector v(xa - xmid, ya - ymid);
    Vector ans = Rotate(v, 2 * pi / n);
    printf("%.9lf %.9lf\n", ans.x + xmid, ans.y + ymid);
    return 0;
}

#include <bits/stdc++.h>
#define ull unsigned long long
#define int long long
#define ll long long
#define fr(i, n) for (int i = 0; i < n; i++)
#define frf(i, j, n) for (int i = j; i <= n; i++)
#define frd(i, n) for (int i = n; i >= 0; i--)
#define mp(i, j) make_pair(i, j)
#define pb(x) push_back(x)
#define INF 1e18
#define all(x) (x).begin(), x.end()
#define int64_t 64
using namespace std;
typedef pair<int, int> pi;
const int MAX = 1e6 + 1;
// typedef vector<vector<ll>> matrix;
const ll PRIME = 1e9 + 7;
#define PI 3.14159265
// typedef pair<int, pair<int, int>> ppi;
// const ll MAX = 1e6 + 1;
int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
int h,w,x,b;
int a[16][16],ans;
void go(int x,int b)
{
    if(x==0 && b==0)
    {
        ans++;
    }
    int I,J;
    bool flag=0;
    fr(i,h)
    {
        fr(j,w)
        {
            if(a[i][j]==-1)
            {
                I=i;
                J=j;
                flag=1;
                break;

            }
        }
        if(flag)break;
    }
    if(x>0 && a[I][J]==-1 && J+1<w &&a[I][J+1]==-1)
    {
        a[I][J+1]=1;
        a[I][J]=1;
        go(x-1,b);
        a[I][J+1]=-1;
         a[I][J]=-1;
    }
     if(x>0 && a[I][J]==-1 && I+1<h &&a[I+1][J]==-1)
    {
        a[I+1][J]=1;
         a[I][J]=1;
        go(x-1,b);
        a[I+1][J]=-1;
         a[I][J]=-1;
    }
    if(b>0 && a[I][J]==-1 )
    {
        a[I][J]=1;
        go(x,b-1);
        a[I][J]=-1;
    }
}
void solve()
{

    cin>>h>>w>>x>>b;
    memset(a,-1,sizeof(a));
     go(x,b);
     cout<<ans;
}

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

    // int k=1;
    while (t--)
    {
        // cout << "Case #" << k++ << ": ";
        solve();
    }
}


#include<stdio.h>
#include<string.h>

// helpful functions
#define fl(i,n) for(int i = 0; i < n; i++)
#define fls(i,a,b) for(int i = a; i <= b; i++) // flexible for loop
#define fls2(i,a,b) for(int i = a; i >= b; i--) // flexible for loop 2
#define afl(i,a,n) int a[n]; for(int i = 0; i < n; i++) scanf("%d", &a[i])

// printers
#define iprint(x) printf("%d\n", x)
#define lprint(x) printf("%lld\n", x)
#define fprint(x) printf("%.f\n", x)
#define dprint(x) printf("%.lf\n", x)
#define cprint(x) printf("%c\n", x)
#define sprint(x) printf("%s\n", x)

// scanners
#define iscan(x) scanf("%d", &x)
#define lscan(x) scanf("%lld", &x)
#define fscan(x) scanf("%f", &x)
#define dscan(x) scanf("%lf", &x)
#define cscan(x) scanf("%c\n", &x)
#define scan(x) scanf("%s", x)

// special scanners
#define escan(x) scanf("%[^\n]", x)

// quick scanners
#define qs(x) int x; scanf("%d", &x)
#define ls(x) long long x; scanf("%lld", &x)
#define fs(x) float x; scanf("%f", &x)
#define ds(x) double x; scanf("%lf", &x)
#define cs(x) char x; scanf("%lf", &x)
#define ss(x,n) char x[n]; scanf("%s", &x)
#define es(x,n) char x[n]; scanf("%[^\n]", &x)

typedef long long ll;
typedef double db;

int main()
{
	qs(a); qs(b); qs(c); qs(d);
	iprint(a*d - b*c);
}

#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
int a[20],b[110],n;bool bk[20];ll Ans=5e18;
void dfs(int k){
	if(k>15){
		bool PD=true;
		for(int i=1;i<=n;i++){
			bool pd=false;
			for(int j=1;j<=15;j++)
				if(bk[j]&&b[i]%a[j]==0) {pd=true;break;}
			if(!pd) {PD=false;break;}
		}
		if(PD){
			ll Sum=1;
			for(int i=1;i<=15;i++)
				if(bk[i]) Sum*=a[i];
			if(Ans>Sum) Ans=Sum;
		}
		return ;
	}
	bk[k]=true;dfs(k+1);
	bk[k]=false;dfs(k+1);
}
int main()
{
	a[1]=2;a[2]=3;a[3]=5;a[4]=7;a[5]=11;
	a[6]=13;a[7]=17;a[8]=19;a[9]=23;a[10]=29;
	a[11]=31;a[12]=37;a[13]=41;a[14]=43;a[15]=47;
	memset(bk,false,sizeof(bk));
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&b[i]);
	dfs(1);
	printf("%lld\n",Ans);
	return 0;
}


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

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

    ll M = floor(sqrt(N));

    vector<bool> isExp(M+1, true);
    ll cnt = 0;
    isExp[0] = false;
    for (ll i=2; i<=M; i++) {
        if (isExp[i]) {
            for (ll j=2; pow(i,j)<=N; j++) {
                cnt++;
                if (pow(i,j)<=M) {
                    isExp[pow(i,j)] = false;
                }
            }
        }
    }

    cout << N - cnt << endl;
}

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

int main() {
  ll n;
  cin >> n;
  set<ll> s;
  for (ll a = 2; a*a <= n; ++a){
    ll x = a*a;
    while (x <= n) {
      s.insert(x);
      x *= a;
    }
  }
  cout << n-s.size() << endl;
}