#include <bits/stdc++.h>

#define ln                 '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

const int nsz = 3e5;
int n, a[nsz + 5];
num ans, sum[nsz + 5];
map<num, int> cnt;

int main() {
	scanf("%d", &n);
	cont (i, n) scanf("%d", &a[i]);
	for (int i = 2; i <= n; i += 2) a[i] = -a[i];
	cnt[0] = 1;
	cont (i, n) {
		sum[i] = sum[i - 1] + a[i];
		ans += cnt[sum[i]];
		cnt[sum[i]] += 1;
	}
	printf("%lld\n", ans);
}

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#pragma warning(disable : 4996)

//#define ATCODER
#ifdef ATCODER
#include<atcoder/all>
using namespace atcoder;
#endif

#include <algorithm>
#include <utility>
#include <vector>

#include <limits.h>
#include <math.h>
#include <time.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <cassert>
#include <numeric>
#include <type_traits>

using namespace std;

#ifdef _MSC_VER
#include"stdafx.h"
#include <intrin.h>
#define __builtin_popcount __popcnt
#define __builtin_popcountll __popcnt64
void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << (H);
	debug_out(T...);
}
#define DEBUG(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define DEBUG(...) 42
#endif

#define ll long long
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REPR(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = (m); i < (n); ++i)
#define VSORT(v) sort(v.begin(), v.end());
#define VREVERSE(v) reverse(v.begin(), v.end())

#define print(x) cout << (x) << '\n'
#define spa <<" "<<
#define lb(v, n) lower_bound(v.begin(), v.end(), (n))
#define ub(v, n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i, v.size()) cout << v[i] << " \n"[i==(int)v.size()-1]
template <typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template <typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 998244353;
constexpr int MAX = 300050;
const double pi = acos(-1);
constexpr double EPS = 1e-8;
constexpr ll LINF = 1e17 + 1;
constexpr int INF = 1e9 + 1;

struct UnionFind {
	int N;
	vector<int> siz;
	vector<int> par;
	vector<int> Rank;
	UnionFind(int n) : siz(n, 1), par(n), Rank(n, 0) {
		N = n;
		for (int i = 0; i < N; i++) par[i] = i;
	}
	int find(int x) {
		if (par[x] == x) {
			return x;
		}
		else {
			return par[x] = find(par[x]);
		}
	}
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;
		if (Rank[x] < Rank[y]) {
			par[x] = y;
			siz[x] += siz[y];
			siz[y] = siz[x];
		}
		else {
			siz[y] += siz[x];
			siz[x] = siz[y];
			par[y] = x;
			if (Rank[x] == Rank[y]) Rank[x]++;
		}
	}
	bool same(int x, int y) { return find(x) == find(y); }
};
typedef complex<double> point;
void solve() {
	int N; cin >> N;
	//UnionFind uf(N + 2);
	vector<point>ps;
	REP(i, N) {
		int x, y; cin >> x >> y;
		ps.emplace_back(x, y);
	}
	double ans = 0;
	double ok = 0, ng = 200;
	REP(_, 50) {
		double mid = (ok + ng) / 2;
		UnionFind uf(N + 2);
		REP(i, N)FOR(j, i + 1, N) {
			if (abs(ps[i] - ps[j]) < 2 * mid)uf.unite(i, j);
		}
		REP(i, N) {
			if (abs(100 - ps[i].imag()) < 2 * mid)uf.unite(i, N);
			if (abs(-100 - ps[i].imag()) < 2 * mid)uf.unite(i, N + 1);
		}
		if (uf.same(N, N + 1))ng = mid;
		else ok = mid;
	}
	cout << setprecision(10) << fixed << ok << endl;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q; while (q--)
	solve();
}


#include <iostream>
#include <math.h>
#include <vector>
#include <string>
#include <numeric>
#include <unordered_set>
using namespace std;

int main(){
    int h,w;    cin >> h >> w;
    vector<vector<int> > block(h,vector<int>(w));
    int min_block;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin >> block[i][j];
            min_block = min(min_block,block[i][j]);
        }
    }
    int ans=0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            ans += block[i][j]-min_block;
        }
    }
    cout << ans << endl;
}

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

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

int main()
{
    int h, w;
    cin >> h >> w;

    int ans = 0;
    int mx = 101;

    rep(_, h * w) {
        int a;
        cin >> a;
        chmin(mx, a);
        ans += a;
    }
    ans -= mx * h * w;

    cout << ans << "\n"s;

    return 0;
}


#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n";
#pragma GCC optimize "trapv"
#define sz(v) ((int)(v).size())
const int INF = 1e9;
const int mx =1e6+100;
const int mod =1e9+7;
#define MAX 100005
using namespace std;
typedef long long int ll;
// for policy based DS
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

// #define ordered_set tree<pair<int,int>, null_type,less<pair<int,int> >, rb_tree_tag,tree_order_statistics_node_update>
// #define os_find(k) find_by_order(k)
// #define os_order(k) order_of_key(k)
 // #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
vector<int>special;
unordered_map<int,int>ump;

int main()
{
    fast
    int n;
    cin>>n;
    map<int,int>mp;
    ll ans =0;
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        mp[x]++;
        ans += (i+1)-mp[x];
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(void) {
	int N;
	cin >> N;
	vector<string> S;
	for (int i = 0; i < N; i++) {
		string s;
		cin >> s;
		if (s[0] == '!') {
			s = s.substr(1, s.size() - 1) + '!';
		}
		S.push_back(s);
	}
	sort(S.begin(), S.end());
	for (int i = 1; i < N; i++) {
		if (S[i][S[i].size() - 1] == '!' && S[i].substr(0, S[i].size() - 1) == S[i - 1]) {
			cout << S[i - 1] << endl;
			return 0;
		}
	}
	cout << "satisfiable\n";
	return 0;
}


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

ll sum(ll mn, ll mx) {
	return (mx - mn + 1)*(mn + mx) / 2;
}

int main() {
	int t, l, r;
	cin >> t;
	rep(i, t) {
		cin >> l >> r;
		int mx;
		mx = r - l - l + 1;
		mx = max(mx, 0);

		cout << sum(1, mx) << endl;
	}
}

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

int main() {
    int t; cin>> t;
    for (int i=0; i<t; i++) {
        long long l, r;
        cin>> l >> r;
        if (r >= 2*l) {
            cout << (r + 2 - 2 * l) * (r + 1 - 2 * l) / 2 << endl;
        }
        else {
            cout << 0 << endl;
        }
    }
    return 0;
}


//****************************Template Begins****************************//

// Header Files
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<utility>
#include<set>
#include<unordered_set>
#include<list>
#include<iterator>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<bitset>
#include<random>
#include<map>
#include<unordered_map>
#include<stdio.h>
#include<complex>
#include<math.h>
#include<cstring>
#include<chrono>
#include<string>
// Header Files End

using namespace std;
#define HARI ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define umap unordered_map
#define uset unordered_set
#define lb lower_bound
#define ub upper_bound
#define fo(i,a,b) for(i=a;i<=b;i++)
#define all(v) (v).begin(),(v).end()
#define all1(v) (v).begin()+1,(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define allr1(v) (v).rbegin()+1,(v).rend()
#define sort0(v) sort(all(v))
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
#define max3(a,b,c) max(max((a),(b)),(c))
#define max4(a,b,c,d) max(max((a),(b)),max((c),(d)))
#define min3(a,b,c) min(min((a),(b)),(c))
#define min4(a,b,c,d) min(min((a),(b)),min((c),(d)))
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define inf 9999999999999
const ll mod = 1e9 + 7;

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

ll mod_mul(ll a, ll b) {a = a % mod; b = b % mod; return (((a * b) % mod) + mod) % mod;}

ll mod_add(ll a, ll b) {a = a % mod; b = b % mod; return (((a + b) % mod) + mod) % mod;}

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

ll ceil_div(ll a, ll b) {return a % b == 0 ? a / b : a / b + 1;}

ll pwr(ll a, ll b) {a %= mod; ll res = 1; while (b > 0) {if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1;} return res;}
//****************************Template Ends*******************************//

int main() {
    HARI;
#ifndef ONLINE_JUDGE
    freopen("input.txt" , "r" , stdin);
    freopen("output.txt", "w", stdout);
#endif
    ll t, n, i, j, ans, temp, sum;
    string sans;
    t = 1;
    // cin >> t;
    while (t--)
    {
        sans = "NO";
        ans = temp = sum = 0;
        cin >> n;
        vll a(n + 1, 0), b(n + 1, 0), c(n + 1, 0), freq(n + 1, 0);
        fo(i, 1, n)
        {
            cin >> a[i];
        }
        fo(i, 1, n)
        {
            cin >> b[i];
        }
        fo(i, 1, n)
        {
            cin >> c[i];
        }
        fo(i, 1, n)
        {
            freq[b[c[i]]]++;
        }
        fo(i, 1, n)ans += freq[a[i]];
        cout << ans;
    }
    return 0;
}

#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vpl = vector<pair<ll, ll>>;
using pll = pair<ll, ll>;
#define rep(i, k, n) for(ll i = k; i < n; i++)
#define pb push_back
#define mp make_pair

int main(){
    string s; cin >> s;
    vll v(10, 0);
    rep(i, 0, s.size()){
        v[s[i]-48]++;
    }

    if(s.size() < 2){
        if(stoll(s) == 8) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    else if(s.size() < 3){
        ll x = stoll(s);
        reverse(s.begin(), s.end());
        ll y = stoll(s);
        if(x % 8 == 0 || y % 8 == 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    else{
        bool f = false;
        rep(i, 1, 10){
            if(v[i] < 1) continue;
            v[i]--;
            rep(j, 1, 10){
                if(v[j] < 1) continue;
                v[j]--;
                rep(k, 1, 10){
                    if(v[k] < 1) continue;
                    v[k]--;

                    if((100*i+10*j+k) % 8 == 0) f = true;

                    v[k]++;
                }
                v[j]++;
            }
            v[i]++;
        }
        if(f) cout << "Yes" << endl;
        else cout << "No" << endl;
    }

    // rep(i, 1, 10){
    //     cout << i << " " << v[i] << endl;
    // }
}


#include <bits/stdc++.h>

using namespace std;

#define MS(a, b) memset(a, b, sizeof(a))
#define REP(a, b, c) for (register int a = b, _n = c; a <= _n; ++a)
#define DREP(a, b, c) for (register int a = b, _n = c; a >= _n; --a)
#define FOR(a, b, c) for (register int a = b, _n = c; a < _n; ++a)
#define EREP(a, b) for (register int a = head[b]; a; a = edge[a].nxt)
#define ll long long

inline int rd() {
    int x = 0; char c = getchar(); bool f = 0;
    while (c < '0' && c != '-') c = getchar();
    if (c == '-') f = 1, c = getchar();
    while (c >= '0') x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
    return f ? -x : x;
}

const int SIZE = 1e5 + 100;

int n, m, t[3];
char Co[10];
vector<ll> V[3];

ll dp[SIZE], pre[SIZE], suf[SIZE];

void _main () {
    n = rd();
    REP (i, 1, 2 * n) {
        ll x;
        scanf ("%lld%s", &x, Co);
        if (Co[0] == 'R') V[0].push_back(x);
        else if (Co[0] == 'G') V[1].push_back(x);
        else V[2].push_back(x);
    }
    FOR (i, 0, 3) sort(V[i].begin(), V[i].end());
    int WTF = 0;
    FOR (i, 0, 3) if (V[i].size() & 1)
        t[WTF++] = i;
    if (WTF == 0) puts("0");
    else {
        n = V[t[0]].size(), m = V[t[1]].size();
        ll ans = 1e18;
        int x = 0;
        FOR (i, 0, n) {
            if (x) ans = min(ans, llabs(V[t[0]][i] - V[t[1]][x - 1]));
            while (x + 1 < m && V[t[1]][x] <= V[t[0]][i]) {
                ans = min(ans, llabs(V[t[0]][i] - V[t[1]][x]));
                ++x;
            }
            ans = min(ans, llabs(V[t[0]][i] - V[t[1]][x]));
        }

        t[2] = 3 ^ t[0] ^ t[1];
        int T = V[t[2]].size();
        if (T) {
            x = 0;
            FOR (i, 0, T) {
                dp[i] = 1e18;
                if (x) dp[i] = min(dp[i], llabs(V[t[2]][i] - V[t[1]][x - 1]));
                while (x + 1 < m && V[t[1]][x] <= V[t[2]][i]) {
                    dp[i] = min(dp[i], llabs(V[t[2]][i] - V[t[1]][x]));
                    ++x;
                }
                dp[i] = min(dp[i], llabs(V[t[2]][i] - V[t[1]][x]));
            }
            pre[0] = dp[0];
            FOR (i, 1, T) pre[i] = min(pre[i - 1], dp[i]);
            suf[T - 1] = dp[T - 1];
            DREP (i, T - 2, 0) suf[i] = min(suf[i + 1], dp[i]);

            x = 0;
            FOR (i, 0, T) {
                dp[i] = 1e18;
                if (x) dp[i] = min(dp[i], llabs(V[t[2]][i] - V[t[0]][x - 1]));
                while (x + 1 < n && V[t[0]][x] <= V[t[2]][i]) {
                    dp[i] = min(dp[i], llabs(V[t[2]][i] - V[t[0]][x]));
                    ++x;
                }
                dp[i] = min(dp[i], llabs(V[t[2]][i] - V[t[0]][x]));
                if (i) ans = min(ans, dp[i] + pre[i - 1]);
                if (i != T - 1) ans = min(ans, dp[i] + suf[i + 1]);
            }
        }

        // 0 1 2;
        printf ("%lld\n", ans);
    }
}

int main () {
    _main();
    return 0;
}

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

#define rep(i, n) for(int i = 0, i##_len=(n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((int)(x).size())

void _cin() {} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail) { cin >> head; _cin(forward<Tail>(tail)...); }
#define cin(Type, ...) Type __VA_ARGS__; _cin(__VA_ARGS__)
#define cinv(Type, xs, n) vector<Type> xs(n); rep(i, n) cin >> xs[i]
#define cinv2(Type, xs, ys, n) vector<Type> xs(n), ys(n); rep(i, n) cin >> xs[i] >> ys[i]
#define cinv3(Type, xs, ys, zs, n) vector<Type> xs(n), ys(n), zs(n); rep(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define cinvv(Type, xs, h, w) vector<vector<Type>> xs(h, vector<Type>(w)); rep(i, h) rep(j, w) cin >> xs[i][j]

void print() { cout << endl; }
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { cout << head; if (sizeof...(tail) != 0) cout << " "; print(forward<Tail>(tail)...); }
template <class Type> void print(vector<Type> &vec) { for (auto& a : vec) { cout << a; if (&a != &vec.back()) cout << " "; } cout << endl; }
template <class Type> void print(vector<vector<Type>> &df) { for (auto& vec : df) { print(vec); } }

void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void yesno(bool b) { cout << (b ? "yes" : "no") << endl; }
template<class Integer>bool chmax(Integer &a, const Integer &b) { if (a < b) { a = b; return 1; } return 0; }
template<class Integer>bool chmin(Integer &a, const Integer &b) { if (b < a) { a = b; return 1; } return 0; }

using ll = long long;
using P = pair<int, int>;
int fs = 10000;
int n;
vector<int> x(200), y(200), r(200), a(200), b(200), c(200), d(200);
vector<int> id(200);

void show() {

}

void mset(int i, int _a, int _b, int _c, int _d) { a[i] = _a; b[i] = _b; c[i] = _c; d[i] = _d; }

int area(int i) { return (c[i] - a[i])*(d[i] - b[i]); }

bool check() {
	rep(i, n) {
		if (a[i] < 0 || fs < c[i] || b[i] < 0 || fs < d[i])return false;
		rep(j, n) {
			if (i == j)continue;
			if ((a[i] < c[j]) && (a[j] < c[i]) && (b[i] < d[j]) && (b[j] < d[i]))return false;
		}
	}
	return true;
}

void Main() {
	rep(i, n) {
		int pc = c[id[i]], pd = d[id[i]];
		int ok = 0, ng = fs;
		while (ng - ok > 1) {
			int wj = (ok + ng) / 2;
			c[id[i]] = pc + wj;
			d[id[i]] = pd + wj;
			if (check())ok = wj;
			else ng = wj;
		}
		c[id[i]] = pc + ok;
		d[id[i]] = pd + ok;
		if (r[id[i]] < area(id[i])) {
			int s = (int)sqrt(r[id[i]]);
			c[id[i]] = a[id[i]] + s;
			d[id[i]] = b[id[i]] + s;
		}

		int pa = a[id[i]], pb = b[id[i]];
		ok = 0, ng = fs;
		while (ng - ok > 1) {
			int wj = (ok + ng) / 2;
			a[id[i]] = pa - wj;
			b[id[i]] = pb - wj;
			if (check())ok = wj;
			else ng = wj;
		}
		a[id[i]] = pa - ok;
		b[id[i]] = pb - ok;
		if (r[id[i]] < area(id[i])) {
			int s = (int)sqrt(r[id[i]]);
			a[id[i]] = c[id[i]] - s;
			b[id[i]] = d[id[i]] - s;
		}
	}
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//cout << fixed << setprecision(16);
	//int t; cin >> t; while (t--)
	cin >> n;
	vector<P> ri(n);
	rep(i, n) cin >> x[i] >> y[i] >> ri[i].first;
	rep(i, n)r[i] = ri[i].first;
	rep(i, n) ri[i].second = i;
	sort(ri.rbegin(), ri.rend());
	rep(i, n)id[i] = ri[i].second;
	rep(i, n) mset(i, x[i], y[i], x[i] + 1, y[i] + 1);
	Main();
	rep(i, n) {
		print(a[i], b[i], c[i], d[i]);
	}
	show();
}


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF ((1<<30)-1)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()

struct TrieNode{
	int n = 0;
	long long sum = 0;
	TrieNode* l = nullptr, * r = nullptr;
};

class Trie {
public:
	Trie() { root = new TrieNode(); }

	void insert(int x) {
		TrieNode* t = root;
		for (int i = 30; i >= 0; i--) {
			t->n++;
			t->sum += x;
			if (x >> i &1) {
				if (t->r == nullptr) t->r = new TrieNode;
				t = t->r;
			}
			else {
				if (t->l == nullptr) t->l = new TrieNode;
				t = t->l;
			}
		}
		t->n++;
		t->sum += x;
	}

	void erase(int x) {
		TrieNode* t = root;
		for (int i = 30; i >= 0; i--) {
			t->n--;
			t->sum -= x;
			if (x >> i & 1) {
				t = t->r;
			}
			else {
				t = t->l;
			}
		}
		t->n--;
		t->sum -= x;
	}

	pair<int, long long> query(int x) const{
		pair<int, long long > ret(0, 0);
		TrieNode* t = root;
		for (int i = 30; i >= 0; i--) {
			if (t == nullptr)break;
			if (x >> i & 1) {
				if (t->l) {
					ret.first += t->l->n;
					ret.second += t->l->sum;
				}
				t = t->r;
			}
			else {
				t = t->l;
			}
		}
		return ret;
	}
private:
	TrieNode* root;
};

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

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

	vector<int> a(n, 0), b(m, 0);

	Trie ta, tb;
	rep(i, n) ta.insert(0);
	rep(i, m)tb.insert(0);

	long long ans = 0;
	rep(_, q) {
		int t, x, y;
		cin >> t >> x >> y;
		x--;

		if (t == 1) {
			auto p = tb.query(a[x]);
			ans -= (long long)p.first * a[x];
			ans += p.second;

			p = tb.query(y);
			ans += (long long)p.first * y;
			ans -= p.second;

			ta.erase(a[x]);
			ta.insert(y);
			a[x] = y;
		}
		else {
			auto p = ta.query(b[x]);
			ans -= (long long)p.first * b[x];
			ans += p.second;

			p = ta.query(y);
			ans += (long long)p.first * y;
			ans -= p.second;

			tb.erase(b[x]);
			tb.insert(y);
			b[x] = y;
		}
		cout << ans << endl;
	}

	return 0;
}

#include <vector>
#include <algorithm>
#include <map>
#include <cstdio>
#include <cstdlib>

template <class E> struct FenwickTree {
    int _n;
    std::vector<E> data;

    FenwickTree(int n) : _n(n), data(n) { }

    void add(int p, E x) {
        ++p;
        while (p <= _n) {
            data[p - 1] += x;
            p += p & -p;
        }
    }
    E sum(int r) const {
        E s = 0;
        while (r > 0) {
            s += data[r - 1];
            r -= r & -r;
        }
        return s;
    }
    E sum(int l, int r) const {
        return sum(r) - sum(l);
    }
};

long long proc(
    std::vector<int>             &cur,
    int                          x,
    int                          y,
    FenwickTree<int>             &ftcnt0,
    FenwickTree<long long>       &ftsum0,
    const FenwickTree<int>       &ftcnt1,
    const FenwickTree<long long> &ftsum1,
    const std::vector<int>       &arr)
{
    int v = cur[x];
    long long dem = (long long)ftcnt1.sum(0, v) * arr[v];
    long long cre = (long long)ftcnt1.sum(0, y) * arr[y];
    long long adj = (long long)ftsum1.sum(y, v);

    ftsum0.add(v, -arr[v]);
    ftcnt0.add(v, -1);
    cur[x] = y;
    ftsum0.add(y, arr[y]);
    ftcnt0.add(y, 1);

    return cre + adj - dem;
}

static char buf[2000000];
int ptr = 0;
int len = 0;

void init()
{
    len = fread(buf, 1, sizeof buf, stdin);
    ptr = 0;
}

int myread()
{
    int acc = 0;
    if (len <= ptr) init();
    while (buf[ptr] < '0' | buf[ptr] > '9') {
        ptr++;
        if (len <= ptr) init();
    }
    while (buf[ptr] >= '0' && buf[ptr] <= '9') {
        acc = acc * 10 + buf[ptr] - '0';
        ptr++;
        if (len <= ptr) init();
    }
    return acc;
}

int main(int argc, char **argv)
{
    int n = myread(), m = myread(), q = myread();

    std::vector<int> ta(q), xa(q), ya(q), arr(q + 1);

    for (int i = 0; i < q; i++) {
        ta[i] = myread();
        xa[i] = myread();
        ya[i] = myread();

        arr[i + 1] = ya[i];
        xa[i]--;
    }
    std::sort(arr.begin(), arr.end());
    std::map<int, int> map;
    int ll = 0;
    map.emplace(0, 0);
    for (int ii = 1; ii <= q; ii++) {
        if (arr[ii] != arr[ll]) {
            ++ll;
            arr[ll] = arr[ii];
            map.emplace(arr[ii], ll);
        }
    }
    ++ll;

    FenwickTree<long long> ftsuma(ll);
    FenwickTree<long long> ftsumb(ll);
    FenwickTree<int>       ftcnta(ll);
    FenwickTree<int>       ftcntb(ll);
    std::vector<int> cura(n);
    std::vector<int> curb(m);
    ftcnta.add(0, n);
    ftcntb.add(0, m);
    long long sum = 0;

    for (int i = 0; i < q; i++) {
        int cy = map[ya[i]];
        sum += (ta[i] == 1) ? proc(cura, xa[i], cy, ftcnta, ftsuma, ftcntb, ftsumb, arr)
                            : proc(curb, xa[i], cy, ftcntb, ftsumb, ftcnta, ftsuma, arr);
        printf("%lld\n", sum);
    }
    return 0;
}


#include<cstdio>
#include<algorithm>
const int Q=200005;
typedef long long ll;
#define rg register int
//char buf[1<<21],*p1=buf,*p2=buf;
//#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
#define gc() getchar()
inline bool ig(char c){return c>=48&&c<=57;}
inline void read(int &oi){char c;int f=1,res=0;while(c=gc(),(!ig(c))&&c^'-');c^'-'?res=(c^48):f=-1;while(c=gc(),ig(c))res=res*10+(c^48);oi=f*res;}
inline void print(int oi){if(oi<0)putchar('-'),oi=~oi+1;if(oi>9)print(oi/10);putchar(oi%10+48);}
inline void write(int oi,char c){print(oi);putchar(c);}
int n,m,col[Q],prt[Q],rt[Q];
namespace VSgt{
	struct sgt{int ls,rs,sze;}t[Q<<5];int tot;
	inline void update(int x){t[x].sze=t[t[x].ls].sze+t[t[x].rs].sze;}
	inline void modify(int l,int r,int q,int &x){
		if(q>r||l>q)return;if(!x)x=++tot;if(l==r)return void(++t[x].sze);int mid=l+r>>1;
		modify(l,mid,q,t[x].ls);modify(mid+1,r,q,t[x].rs);update(x);
	}
	inline int merge(int x,int y,int l,int r){
		if(!x||!y)return x|y;if(l==r){t[x].sze+=t[y].sze;return x;}
		int mid=l+r>>1;t[x].ls=merge(t[x].ls,t[y].ls,l,mid);
		t[x].rs=merge(t[x].rs,t[y].rs,mid+1,r);update(x);return x;
	}
	inline int query(int l,int r,int q,int x){
		if(q>r||l>q||!x)return 0;if(l==r)return t[x].sze;int mid=l+r>>1;
		return query(l,mid,q,t[x].ls)+query(mid+1,r,q,t[x].rs);
	}
}using namespace VSgt;
inline int gfa(int x){return x^prt[x]?prt[x]=gfa(prt[x]):x;}
inline void merge(int x,int y){
	x=gfa(x);y=gfa(y);if(x==y)return;prt[x]=y;rt[y]=merge(rt[y],rt[x],1,n);
}
inline int query(int x,int y){
	x=gfa(x);return query(1,n,y,rt[x]);
}
int main(){
	read(n);read(m);
	for(rg i=1;i<=n;++i)read(col[i]);
	for(rg i=1;i<=n;++i)prt[i]=i,modify(1,n,col[i],rt[i]);
	for(rg i=1;i<=m;++i){
		int opt,x,y;read(opt);read(x);read(y);
		if(opt==1)merge(x,y);else write(query(x,y),'\n');
	}
	return 0;
}

#line 2 "/home/defineprogram/Desktop/Library/template/template.cpp"
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,n) for(ll i=1;i<n;i++)
#define rev(i,n) for(ll i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<ll,ll>
#define len(s) (ll)s.size()

template<class T,class U> inline bool chmin(T &a, U b){
	if(a>b){a=b;return true;}
	return false;
}
template<class T,class U> inline bool chmax(T &a, U b){
	if(a<b){a=b;return true;}
	return false;
}
constexpr ll inf = 3e18;
#line 3 "/home/defineprogram/Desktop/Library/math/modint.cpp"

template<int MOD>
struct mint{
	int32_t n;
	mint():n(0){}
	mint(ll x):n(x>=0?x%MOD:(MOD-(-x)%MOD)%MOD){}

	mint &operator+=(const mint &p){
		if((n+=p.n)>=MOD)n-=MOD;
		return *this;
	}
	mint &operator-=(const mint &p){
		if((n+=MOD-p.n)>=MOD)n-=MOD;
		return *this;
	}
	mint &operator*=(const mint &p){
		n=1ll*n*p.n%MOD;
		return *this;
	}
	mint &operator/=(const mint &p){
		*this*=p.inverse();
		return *this;
	}
	mint operator-()const{return mint(-n);}
	mint operator+(const mint &p)const{return mint(*this)+=p;}
	mint operator-(const mint &p)const{return mint(*this)-=p;}
	mint operator*(const mint &p)const{return mint(*this)*=p;}
	mint operator/(const mint &p)const{return mint(*this)/=p;}
	bool operator==(const mint &p)const{return n==p.n;}
	bool operator!=(const mint &p)const{return n!=p.n;}

	friend ostream &operator<<(ostream &os,const mint &p){
		return os<<p.n;
	}
	friend istream &operator>>(istream &is,mint &p){
		int x;is>>x;
		p=mint(x);
		return is;
	}
	mint pow(int64_t x)const{
		mint res(1),mul(n);
		while(x>0){
			if(x&1)res*=mul;
			mul*=mul;
			x>>=1;
		}
		return res;
	}
	mint inverse()const{
		return pow(MOD-2);
	}
};
/*
@brief mod int
@docs docs/modint.md
*/
#line 3 "main.cpp"

int par[200005],siz[200005];
map<int,int>mp[200005];
int find(int x){
    if(par[x]==x)return x;
    return par[x]=find(par[x]);
}
void merge(int x,int y){
    x=find(x),y=find(y);
    if(x==y)return;
    if(siz[x]<siz[y])swap(x,y);
    for(auto i:mp[y])mp[x][i.first]+=i.second;
    siz[x]+=siz[y];par[y]=x;
}
int N,Q;
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    cin>>N>>Q;
    rep(i,N){
        int a;cin>>a;mp[i][a]++;par[i]=i;siz[i]=1;
    }
    while(Q--){
        int t;cin>>t;
        if(t==1){
            int a,b;cin>>a>>b;a--;b--;
            merge(a,b);
        }else {
            int a,b;cin>>a>>b;a--;
            cout<<mp[find(a)][b]<<"\n";
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans = 0;
void Main(){
    using P = pair<int, int>;
    int a, b, x, y;
    cin >> a >> b >> x >> y;
    a--;
    b--;
    vector<vector<P>> graph(200);
    For(i,0,100){
        graph[i].push_back({i + 100, x});
        graph[i + 100].push_back({i , x});
    }
    For(i,0,99){
        graph[i + 1].push_back({i + 100, x});
        graph[i + 100].push_back({i + 1 , x});
    }
    For(i,0,99){
        graph[i].push_back({i + 1, y});
        graph[i + 1].push_back({i, y});
        graph[i + 100].push_back({i + 101, y});
        graph[i + 101].push_back({i + 100, y});
    }
    vector<int> dist(200, 1e9);
    dist[a] = 0;
    stack<P> st;
    st.push({a , 0});
    while(!st.empty()){
        auto [now, d] = st.top();
        st.pop();
        for(auto to : graph[now]){
            if(dist[to.first] > d + to.second){
                dist[to.first] = d + to.second;
                st.push({to.first, dist[to.first]});
            }
        }
    }
    cout << dist[b + 100] << endl;
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(), (a).end()
#define mk make_pair
#define pp pair<int, int>
ll MOD = 1000000007;
ll mod = 998244353;
int inf = 2000001000;
ll INF = 1e18 + 5;

int main() {
    int n;
    cin >> n;
    vector<pair<ld,ld>> a(n);
    rep(i,n){
        ld f,g,h;
        cin >> f >> g >> h;
        if (f==1) a[i]=mk(g,h);
        if (f==2) a[i]=mk(g,h-0.1);
        if (f==3) a[i]=mk(g+0.1,h);
        if (f==4) a[i]=mk(g+0.1,h-0.1);
    }
    int ans=0;
    rep(i,n){
        for (int j=i+1;j<n;j++){
            if (!(a[i].first>a[j].second || a[i].second<a[j].first)) {ans++;}
        }
    }
    cout << ans << endl;
}


#pragma warning (disable:4996)
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>

#define ll long long

#define REP(i, n) for(ll i = 0; i < n; i++)
#define SET(a) ll a = 0; (void)scanf("%lld", &a);

/*
ll cutLog(ll);
ll sum(ll);
*/

ll cutLogNew(ll);

int main() {
	SET(n);
	if (n == 1 || n == 2)printf("1");
	else printf("%lld", n - cutLogNew(n) + 1);
	return 0;
}

/*
ll cutLog(ll n) {
	ll ans;
	REP(i, n + 1) {
		if (sum(i + 1) > n + 1) {
			ans = i;
			break;
		}
	}
	return ans;
}

ll sum(ll n) {
	ll sum = 0;
	REP(i, n) {
		sum += (i + 1);
	}
	return sum;
}
*/

ll cutLogNew(ll n) {
	ll ans = 0;
	ll m = n + 1;
	REP(i, n) {
		m -= (i + 1);
		if (m < 0) {
			ans = i;
			break;
		}
	}
	return ans;
}

#include <iostream>
#include <iomanip>
#include <vector>
#include <string>

#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const long double PI = (acos(-1));
const long long MOD = 1000000007;

static const int  MAX_INT  = std::numeric_limits<int>::max(); // 2147483647 = 2^31-1
static const long MAX_LONG = std::numeric_limits<long>::max();
static const ll   MAX_LL   = std::numeric_limits<long long>::max();
static const int  INF      = (1 << 28);

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

///////////////////////////////////////////////////
// ------------------- utils ------------------- //
///////////////////////////////////////////////////
// change min/max
template<class T> inline bool chMin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chMax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

ull sumN(const ull N) {
    ull ans;
    if (N % 2 == 0) {
        ans = N /2;
        ans *= (N+1);
    }
    else {
        ans = (N+1) /2;
        ans *= N;
    }
    return ans;
}

///////////////////////////////////////////////////
// ------------------- main -------------------- //
///////////////////////////////////////////////////
void Main() {
    ull N; cin >> N;

    ull ok = 0;
    ull ng = 10e10;

    while ((ng - ok) > 1) {
        ull mid = (ok+ng) / 2;
        ull sum = sumN(mid);
        if (sum > (N + 1) ) {
            ng = mid;
        }
        else
        {
            ok = mid;
        }
    }
    cout << N + 1 - ok << endl;

}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout << std::fixed << std::setprecision(15);
    Main();

    double tmp;
    cin >> tmp;

    return 0;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>
#include<map>

using namespace std;

#define rep(i,N) for(ll i=0;i<N;i++) //0から

typedef long long ll;

ll binary_search(vector<ll> a, ll n, ll key){
    ll right = n, left = -1;
    ll md = (right + left) / 2;

    while(right - left > 1){
        if(a[md] <= key){
            right = md;
        }else{
            left = md;
        }
        md = (right + left) / 2;
    }
    if(left == -1) return -1; //無い場合
    return right;
}

vector<ll> prime;
void Prime(ll n){ //線形篩,素数列挙
    vector<ll> p(n,0);
    p[0]=1;
    p[1]=1;
    for(ll i=2;i<n;i++){
        if(p[i]==0){
            prime.push_back(i);
            p[i]=i;
        }
        ll k=prime.size();
        for(ll j=0;j<k && i*prime[j]<n && prime[j]<=p[i];j++){
            p[i*prime[j]]=prime[j];
        }
    }
}

ll gcd(ll a,ll b){
    if(a<b){
        swap(a,b);
    }
    //a>=b
    ll r=a%b;
    while(r!=0){
        a=b;
        b=r;
        r=a%b;
    }
    return b;
}

ll modexp(ll x, ll a, ll m){ //x^a mod m
    ll ret = 1;
    while (a > 0) {
        if (a & 1) ret = ret * x % m;  // n の最下位bitが 1 ならば x^(2^i) をかける
        x = x * x % m;
        a >>= 1;  // n を1bit 左にずらす
    }
    return ret;
}

ll modinv(ll a, ll m){ //a^{-1} mod m
    ll b=m,u=1,v=0;
    while(b){
        ll t=a/b;
        a-=t*b; swap(a,b);
        u-=t*v; swap(u,v);
    }
    u=(u+m)%m;
    return u;
}

#define MOD ((ll)1e+9 + 7)

ll dp[100][10000];

//cout<<fixed<<setprecision(10);
int main(){
    int n,a,b;
    cin>>n>>a>>b;
    cout<<max(0,n-a+b)<<endl;

    return 0;
}

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

int main() {
int N,A,B;
cin>>N>>A>>B;
cout<<N-A+B<<endl;
}


// Problem: B - Special Subsets
// Contest: AtCoder - AtCoder Regular Contest 114
// URL: https://atcoder.jp/contests/arc114/tasks/arc114_b
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)

// By AmmarDab3an - Aleppo University

#include "bits/stdc++.h"

using namespace std;

//#define int int64_t
//#define lli int64_t

typedef unsigned int        uint;
typedef long long int       lli;
typedef unsigned long long  ull;
typedef pair<int, int>      pii;
typedef pair<lli, lli>      pll;
typedef pair<int, pii>      iii;
typedef pair<lli, pll>      lll;
typedef vector<int>         vi;
typedef vector<lli>         vl;
typedef vector<pii>         vpii;
typedef vector<pll>         vpll;

#define endl '\n'
#define fastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define freopenI freopen("input.txt", "r", stdin);
#define freopenO freopen("output.txt", "w", stdout);

const int INF = 0x3f3f3f3f;
const lli INFLL = 0x3f3f3f3f3f3f3f3f;
const int MOD = 998244353;
const double EPS = 1e-9;
const double  PI = acos(-1);

const int  MAX = 2e5 + 10;
const int NMAX = 2e5 + 10;
const int MMAX = 2e5 + 10;

inline int add(int a, int b){
    return ((lli) a + b + MOD + MOD) % MOD;
}

inline int mul(int a, int b){
    return ((lli) a * b) % MOD;
}

int fast_pow(int n, int p){
    if(!p) return 1;
    if(p&1) return mul(n, fast_pow(n, p-1));
    int tmp = fast_pow(n, p/2);
    return mul(tmp, tmp);
}

int32_t main(){

    fastIO;

#ifdef LOCAL
    freopenI;
    freopenO;
#endif

    int n;
    cin >> n;

    vi vec(n);
    for(auto &i : vec) cin >> i;
    for(auto &i : vec) i--;

    vi vis(n);
    int vid = 1;

    int cnt = 0;

    for(int i = 0; i < n; i++) if(!vis[i]){

        cnt++;
        vid++;

        int t = i;
        while(true){

            if(vis[t] == vid) break;

            if(vis[t]){
                cnt--;
                break;
            }

            vis[t] = vid;
            t = vec[t];
        }

    }

    cout << add(fast_pow(2, cnt), -1) << endl;
}

#pragma GCC optimize("O3")   //
#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, b, a) for(int i = b - 1; i >= a; i--)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;
typedef unsigned long long ull;

unsigned seed = chrono::system_clock::now().time_since_epoch().count();
mt19937 eng(seed);

ll random2(){
    return (1ll << 31ll)*eng()+eng();
}

ll n,m,k,q,T;

const ll big = 1000000007;
const ll big2 = 1000000009;
const ll mod =  998244353;

const int MAXN = 400001;

vector<int> prio = {0,1,2};
vector<vl> A(3, vl());

ll score(int i, int j){
    vector<pll> hej;
    trav(a, A[i]){
        hej.push_back({a, 0});
    }
    trav(a, A[j]){
        hej.push_back({a, 1});
    }
    sort(all(hej));
    ll ans = big*big;
    rep(c1,0,sz(hej)-1){
        if(hej[c1].second != hej[c1+1].second){
            ans = min(ans, hej[c1+1].first-hej[c1].first);
        }
    }
    return ans;
}

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

    //freopen("fhc.txt","r",stdin);
    //freopen("autput.txt","w",stdout);

    ll a,b,c,d,e;

    cin >> n;
    rep(c1,0,2*n){
        char ch;
        cin >> a >> ch;
        b = 0;
        if(ch == 'G')b = 1;
        if(ch == 'B')b = 2;
        A[b].push_back(a);
    }

    ll ans = big*big;

    rep(_,0,6){
        ll F[3] = {0,0,0};
        rep(c1,0,3){
            F[c1] = sz(A[prio[c1]]);
        }
        ll temp = 0;
        rep(c1,0,2){
            if(F[c1]%2 == 1){
                temp += score(prio[c1], prio[c1+1]);
                F[c1+1]--;
            }
        }
        ans = min(ans, temp);
        next_permutation(all(prio));
    }
    cout << ans << "\n";

    return 0;
}


#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)
#define ALL(x) x.begin(), x.end();
#define SIZE(x) ll(x.size())
#define CHMIN(x,y) x = min(x, (y))
#define CHMAX(x,y) x = max(x, (y))
#define YES(b) cout << ((b) ? "Yes" : "No") << endl

int main() {
    int n, i = 1, save = 0;
    cin >> n;
    while (save < n) {
        save +=i;
        i++;
    }
    cout << --i << endl;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main(){
    int n;
    int sum=0;
    cin >> n;
    for(int i=1; ;i++){
        if(((i*i+i)/2)>= n){
            cout << i<<endl;
            break;
        }
    }
}


#include <bits/stdc++.h>
using namespace std;
#define fori(i , a ,b) for (int  q = i ; q < a; q +=b )
#define vi vector<int>
typedef long long ll;
const int maxc = 1e9;
void solve() {
    //ifstream fin("breedflip.in");
    //ofstream fout("breedflip.out");
    int a=0, b=0;
    cin >> a >> b;
    int aa =0, bb=0;
    while (a>=10) {aa+=a%10;a/=10;}
    while (b>=10) {bb+=b%10;b/=10;}
    cout << max(aa+a,bb+b) << "\n";
}
int main() {
   ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    solve();

  return 0;
}

#include <bits/stdc++.h>

using namespace std;

inline int S(string n) {
  return (n[0] - '0') + (n[1] - '0') + (n[2] - '0');
}

int main() {
  string A, B;
  cin >> A >> B;

  cout << max(S(A), S(B)) << '\n';

  return 0;
}


#include<cstdio>
#include<algorithm>
#include<cctype>
#include<set>
using namespace std;
#define G getchar()
int read()
{
	int x=0; char ch=G;
	for (;!isdigit(ch);ch=G);
	for (;isdigit(ch);ch=G) x=(x<<3)+(x<<1)+(ch^48);
	return x;
}
#undef G
typedef long long ll;

int n,L;  //[0,L]
int w[100010],t[100010];
set<int> st;
int que[100010],hd,tl;
ll ans;
int dir[100010];
int main()
{
	n=read(),L=read()-n;
	for (int i=1;i<=n;i++) w[i]=read()-i;
	set<int>(w+1,w+n+1).swap(st);
	st.insert(0); st.insert(L);
	for (int i=1;i<=n;i++){
		int x=t[i]=read()-i;
		if (!st.count(x)) return puts("-1"),0;
	}
//	for (int i=1;i<=n;i++) printf("%d: %d %d\n",i,w[i],t[i]);
	for (int i=1;i<=n;i++)
		if (t[i]<w[i]) dir[i]=-1;
		else if (t[i]>w[i]) dir[i]=1;
	for (int i=1,j;i<=n;i=j+1){
		for (j=i;j<n&&dir[j+1]==dir[j];j++);
//		printf("solve %d %d: %d\n",i,j,dir[i]);
		if (dir[i]==0) continue;
		if (dir[i]==1){
			hd=tl=0;
			for (int u=i,v;u<=j;u=v+1){
				for (v=u;v<j&&w[v+1]==w[v];v++);
				for (int e=u;e<=v;e++) que[++tl]=e;
				bool flg=0;
				while (hd<tl&&t[que[hd+1]]==w[u]) flg=1,hd++;
				if (flg) ans+=tl-hd;
				else ans+=v-u+1;
			}
		}
		else{
			hd=tl=0;
			for (int u=j,v;u>=i;u=v-1){
				for (v=u;v>i&&w[v-1]==w[v];v--);
				for (int e=u;e>=v;e--) que[++tl]=e;
				bool flg=0;
				while (hd<tl&&t[que[hd+1]]==w[u]) flg=1,hd++;
				if (flg) ans+=tl-hd;
				else ans+=u-v+1;
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}

#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#define ll long long int
#define ld long double
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define vpll vector<pair<ll,ll>>
#define prqueue priority_queue<ll,vector<ll>,greater<ll>>// top=small
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define f0(i,n) for(i=0;i<n;i++)
#define f1(i,n) for(i=1;i<=n;i++)
#define fab(i,a,b) for(i=a;i<=b;i++)
#define f0r(i,n) for(i=n-1;i>=0;i--)
#define f1r(i,n) for(i=n;i>=1;i--)
#define fabr(i,a,b) for(i=b;i>=a;i--)
#define memo(a,b) memset(a,b,sizeof(a))
#define display(x) {for(auto dsp:x)cout<<dsp<<" ";cout<<"\n";}
#define hi cout<<"hi\n"
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
#define ln "\n"
using namespace std;
const ld pi=acos(-1);const ll mod=1e9+7;bool debug=false;

int main()
{FAST;ll t=1,n,i,j,k,len,x,y,z,c,f,flag,p,q,mx,mn,l,r,sum,ans,tmp,it,pos,avg,m,cnt;
    string s;char ch;vll v;vpll vec;unordered_map<ll,ll> mappu;pair<ll,ll> pr;
    // cin>>t;while(t--)
    {
    	n=3;//3
        f=0;sum=0;flag=0;ans=0;cnt=0;v.clear();mappu.clear();vec.clear();
        ll a[n];
        f0(i,n)
        {
            cin>>tmp;
            a[i]=tmp;
            // mappu[tmp]++;
        }

        sort(a,a+n);

        if(a[2]-a[1]==a[1]-a[0]) yes;
        else no;

        // cout<<ans<<ln;
    }
	return 0;
}
// Either be on top or leave this crap..


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

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<double> X(N), Y(N);
    rep(i, 0, N) {
        cin >> X[i] >> Y[i];
    }
    double l = 0, r = 101;
    rep(_, 0, 100) {
        double mid = (r + l) / 2;
        UnionFind uf(N + 2);
        rep(i, 0, N) {
            if (Y[i] + mid > 100 - mid) {
                uf.unite(i, N);
            }
            if (Y[i] - mid < -100 + mid) {
                uf.unite(i, N + 1);
            }
            rep(j, i + 1, N) {
                if (pow(X[i] - X[j], 2) + pow(Y[i] - Y[j], 2) < 4 * mid * mid) {
                    uf.unite(i, j);
                }
            }
        }
        if (uf.isSame(N, N + 1)) {
            r = mid;
        } else {
            l = mid;
        }
    }
    cout << fixed << setprecision(5) << l << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define LOCAL
#pragma region Macros
typedef long long ll;
#define ALL(x) (x).begin(),(x).end()
const long long MOD=1000000007;
// const long long MOD=998244353;
const int INF=1e9;
const long long IINF=1e18;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
const char dir[4]={'D','R','U','L'};

template<typename T>
istream &operator>>(istream &is,vector<T> &v){
    for (T &x:v) is >> x;
    return is;
}
template<typename T>
ostream &operator<<(ostream &os,const vector<T> &v){
    for (int i=0;i<v.size();++i){
        os << v[i] << (i+1==v.size()?"": " ");
    }
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const pair<T,U> &p){
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const map<T,U> &m){
    os << '{';
    for (auto itr=m.begin();itr!=m.end();++itr){
        os << '(' << itr->first << ',' << itr->second << ')';
        if (++itr!=m.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os,const set<T> &s){
    os << '{';
    for (auto itr=s.begin();itr!=s.end();++itr){
        os << *itr;
        if (++itr!=s.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}

void debug_out(){cerr << '\n';}
template<class Head,class... Tail>
void debug_out(Head&& head,Tail&&... tail){
    cerr << head;
    if (sizeof...(Tail)>0) cerr << ", ";
    debug_out(move(tail)...);
}
#ifdef LOCAL
#define debug(...) cerr << " ";\
cerr << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << '\n';\
cerr << " ";\
debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template<typename T> T gcd(T x,T y){return y!=0?gcd(y,x%y):x;}
template<typename T> T lcm(T x,T y){return x/gcd(x,y)*y;}

template<class T1,class T2> inline bool chmin(T1 &a,T2 b){
    if (a>b){a=b; return true;} return false;
}
template<class T1,class T2> inline bool chmax(T1 &a,T2 b){
    if (a<b){a=b; return true;} return false;
}
#pragma endregion

struct UnionFind{
    int num;
    vector<int> par,rank;
    UnionFind(int n):num(n),par(n),rank(n,1){
        iota(par.begin(),par.end(),0);
    }
    int root(int x){
        return (par[x]==x?x:par[x]=root(par[x]));
    }
    bool merge(int x, int y){
        x=root(x); y=root(y);
        if (x==y) return false;
        if (rank[x]<rank[y]) swap(x,y);
        par[y]=x;
        rank[x]+=rank[y];
        --num;
        return true;
    }
    bool same(int x, int y){return root(x)==root(y);}
    int size(int x){return rank[root(x)];}
    int count(){return num;}
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    int N; cin >> N;
    vector<pair<int,int>> pos;
    for (int i=0;i<N;++i){
        int x,y; cin >> x >> y;
        pos.emplace_back(x,y);
    }

    auto d=[&](int i,int j){
        return (pos[j].first-pos[i].first)*(pos[j].first-pos[i].first)+(pos[j].second-pos[i].second)*(pos[j].second-pos[i].second);
    };
    auto ud=[&](int i){
        return 100-pos[i].second;
    };
    auto dd=[&](int i){
        return pos[i].second+100;
    };

    auto check=[&](double r){
        r*=2;
        UnionFind UF(N+2);
        for (int i=0;i<N;++i){
            for (int j=i+1;j<N;++j){
                if (r*r>d(i,j)){
                    UF.merge(i,j);
                }
            }
            if (r>ud(i)) UF.merge(i,N);
            if (r>dd(i)) UF.merge(i,N+1);
        }
        return !UF.same(N,N+1);
    };
    double lb=0,ub=100;
    for (int _=0;_<300;++_){
        double mid=(lb+ub)/2;
        (check(mid)?lb:ub)=mid;
    }
    cout << lb << '\n';
}


//Bismillah Hir Rehmanir Rahim
//Allah knows best
#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;
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#define gap ' '
#include <bitset>
#define mini -10000000000000000
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl '\n'
#define f(i, a, n) for( i=a; i<n;i++)
#define ll long long
#define pi 3.141592653589793
#define vi              vector<ll>
#define si              set<ll>
#define pb              push_back
#define mp              make_pair
#define mod             1000000007
#define rr              return 0
#define ff              first
#define in              insert
#define ss              second
ll hash58 = 288230376151711717;
ll hash32 = 1610612741;
#define erase_unique(st)        st.erase(unique(st.begin(), st.end()),st.end())
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define all(a) a.begin(), a.end()
typedef pair<ll, ll> pii;
#define setbits(x)      __builtin_popcountll(x)
#define zrbits(x)       __builtin_ctzll(x)
#define unset_bit(x,inx) x = (x & ~(1ll<<(inx)))
#define deb(x)          cout << #x << " = " << x << endl
#define set_bit(x, idx) x = x|1LL<<idx
#define check_bit(x, idx) min(x&(1LL<<idx),1LL)
#define toggle_bit(x, idx) x = x^(1LL<<idx)
inline ll uceil(ll a,ll b) {return (a % b ? a / b + 1 : a / b);}
#define multi_ordered_set       tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<int, null_type, greater<int>, rb_tree_tag, tree_order_statistics_node_update> rordered_set;
#ifdef DEBUG
#define ok cerr << __LINE__ <<"is done "<<endl;
#else
#define ok
#endif
#define ld long double
ll prm[2000006];
int main()
{
   #ifndef DEBUG
   ios
   #endif
   int t=1;
   //cin>>t;
   int ct=0;
   while(t--)
   {
        ll l, r;
        cin >> l >> r;
        ll ans = 0;
        for(ll i = 2; i <= r; i++)
        {
            if(prm[i] == 0)
            {
               for(ll j = i ; j <= r; j += i)
               {
                  prm[j]++;
               }
               for(ll j = i*i ; j <= r; j += i*i)
               {
                  prm[j] = -1000000007;
               }
            }
        }
        for(ll i = 2; i <= r; i++)
        {

           if(prm[i] < 0)
           continue;
           ll cc = (r/i) - ((l - 1)/i);
           if(prm[i] % 2)
           ans += (cc * (cc - 1))/2;
           else
           ans -= (cc * (cc - 1))/2;
        }
        for(long long i=max(2ll,l);i<=r;i++){ans -= (r/i-1);}
        cout <<  2 * ans << endl;
   }
  rr;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
	long long i, n;
	cin>>i>>n;
	int d=0;
	int c=0;
	long long r=(n*100)/i;
	if((n*100)%i==0) r--;
	r+=n;
	cout<<r;
}


/**So..a**/
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define B_ begin()
#define E_ end()
#define all(a) a.begin(), a.end()
#define NL_ "\n"
#define F first
#define S second
#define FF first.first
#define FS first.second
#define SF second.first
#define SS second.second
#define __lcm(a, b) (a/__gcd(a, b)*b)

#define PI acos(-1)
#define EXP 10e-6
#define what_is(x) cerr << #x << " is " << x << endl;

template<typename item>
item abs(item i)
{
    if(i < 0) i= -i;
    return i;
}
ll mod = 1000000000+7;
template<class typea>
typea POW(typea b, typea p)
{
    typea res = 1;
    while(p)
    {
        if(p&1)
        {
            res*=b;
            res%=mod;
        }
        b*=b;
        b%=mod;

        p/=2;
    }
    return res;
}

int  tc =0;
#define ull unsigned long long int

#define maxn 2*100000+10
ll arr[maxn];
char a[maxn], b[maxn];
ll n, m, ans;
int main()
{
   string s;
   cin >> s;
   reverse(all(s));
   for(auto &x: s) if(x=='9') x = '6'; else if(x=='6') x = '9';
   cout <<s;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
#define PI 3.1415926535
#define maxn 100005
#define all(x) x.begin(),x.end()
#define speedUp ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

void _SSGJ_()
{
	string s;
	cin>>s;

	int n= s.length();
	int cnt[26]={0};

	int ans=0;
	for(int i=n - 1,j=0;i > 0;i--,j++)
	{
		if(i < n - 1 && i && s[i] == s[i - 1] && s[i] != s[i + 1])
		{
			ans+=j - cnt[s[i] - 'a'];

			for(int it=0;it<26;it++)
				cnt[it]=0;

			cnt[s[i] - 'a']=j;
		}

		cnt[s[i] - 'a']++;
	}

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

signed main()
{

    speedUp

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

   /* int t;
    cin>>t;
    while(t--)*/
    _SSGJ_();
    return 0;

}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

class Tarjan {
public:
  int n;
  vector<vector<int>> graph;

  stack<int> S;
  int clock;
  vector<int> timestamp;
  vector<int> low;
  vector<bool> on_stack;
  vector<vector<int>> blocks;
  vector<int> belongs;
  int n_blocks;
  vector<vector<int>> block_graph;

  void init(int n_) {
    n = n_;
    graph.resize(n);
    for (int i = 0; i < n; ++i) {
      graph[i].clear();
    }
  }

  void add_edge(int u, int v) { graph[u].push_back(v); }

  void dfs(int u) {
    timestamp[u] = clock;
    low[u] = clock;
    ++clock;

    S.push(u);
    on_stack[u] = true;

    for (int v : graph[u]) {
      if (timestamp[v] == -1) {
        dfs(v);
        low[u] = min(low[u], low[v]);
      } else if (on_stack[v]) {
        low[u] = min(low[u], timestamp[v]);
      }
    }

    if (low[u] == timestamp[u]) {
      vector<int> nodes;
      for (;;) {
        int w = S.top();
        S.pop();
        on_stack[w] = false;
        nodes.push_back(w);
        if (w == u) {
          break;
        }
      }
      blocks.push_back(nodes);
    }
  }

  void calc_blocks() {
    clock = 0;
    timestamp.resize(n, -1);
    low.resize(n, -1);
    on_stack.resize(n, false);
    blocks.clear();
    for (int i = 0; i < n; ++i) {
      if (timestamp[i] == -1) {
        dfs(i);
      }
    }
  }

  void build_block_graph() {
    n_blocks = blocks.size();
    belongs.resize(n, -1);
    for (int i = 0; i < n_blocks; ++i) {
      for (int u : blocks[i]) {
        belongs[u] = i;
      }
    }
    vector<unordered_set<int>> uniq_edge_graph(n_blocks);
    for (int u = 0; u < n; ++u) {
      for (int v : graph[u]) {
        if (belongs[u] != belongs[v]) {
          uniq_edge_graph[belongs[u]].insert(belongs[v]);
        }
      }
    }
    block_graph.resize(n_blocks);
    for (int i = 0; i < n_blocks; ++i) {
      block_graph[i].clear();
      for (int u : uniq_edge_graph[i]) {
        block_graph[i].push_back(u);
      }
    }
  }

  long double topological_sort() {
    vector<int> in_degree(n_blocks, 0);
    vector<int> size(n_blocks, 0);
    vector<bitset<100>> ancestors(n_blocks);

    for (int u = 0; u < n_blocks; ++u) {
      size[u] = blocks[u].size();
      ancestors[u].reset();
      for (int v : block_graph[u]) {
        in_degree[v]++;
      }
    }
    queue<int> Q;
    for (int i = 0; i < n_blocks; ++i) {
      if (in_degree[i] == 0) {
        Q.push(i);
      }
    }
    long double expected_val = 0;
    while (!Q.empty()) {
      int u = Q.front();
      Q.pop();
      int count = 0;
      for (int i = 0; i < n_blocks; ++i) {
        if (ancestors[u][i]) {
          count += size[i];
        }
      }
      expected_val += 1.0 * size[u] / (size[u] + count);
      for (int v : block_graph[u]) {
        ancestors[v] |= ancestors[u];
        ancestors[v].set(u);
        in_degree[v]--;
        if (in_degree[v] == 0) {
          Q.push(v);
        }
      }
    }
    return expected_val;
  }
};

Tarjan tarjan;

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20);

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

  tarjan.init(n);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (s[i][j] == '1') {
        tarjan.add_edge(i, j);
      }
    }
  }

  tarjan.calc_blocks();
  tarjan.build_block_graph();
  cout << tarjan.topological_sort() << endl;
  return 0;
}

#include <bits/stdc++.h>

using namespace std;

const int max_n = 111, inf = 1000111222;

int n, f[max_n][max_n];
string s;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> s;
        for (int j = 0; j < n; ++j) {
            f[i][j] = s[j] - '0';
        }
        f[i][i] = 1;
    }
    for (int k = 0; k < n; ++k) {
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                f[i][j] |= f[i][k] & f[k][j];
            }
        }
    }
    long double ans = 0;
    for (int i = 0; i < n; ++i) {
        int cnt = 0;
        for (int j = 0; j < n; ++j) {
            cnt += f[j][i];
        }
        ans += 1.0l / cnt;
    }
    cout << fixed << setprecision(20) << ans << endl;
    return 0;
}


/**
 *  created: 09/01/2021, 14:56:06
**/

#include <bits/stdc++.h>

using namespace std;

const int max_n = 111, inf = 1000111222;
const int max_m = max_n * max_n;

int n, m, a[max_n], from[max_m], to[max_m], ans[max_m];
vector<pair<int, int>> g[max_n];
int h[max_n];

void dfs(int v) {
    for (auto p : g[v]) {
        int id = p.first, tp = p.second;
        const int nxt = v ^ from[id] ^ to[id];
        if (h[nxt] == -1) {
            ans[id] = 0 ^ tp;
            h[nxt] = h[v] + 1;
            dfs(nxt);
        } else if (h[nxt] + 1 < h[v]) {
            ans[id] = tp;
        }
    }
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        cin >> from[i] >> to[i];
        --from[i];
        --to[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < m; ++i) {
        if (a[from[i]] != a[to[i]]) {
            ans[i] = a[from[i]] < a[to[i]];
        } else {
            g[from[i]].push_back({i, 0});
            g[to[i]].push_back({i, 1});
        }
    }
    memset(h, -1, sizeof(h));
    for (int i = 0; i < n; ++i) {
        if (h[i] == -1) {
            h[i] = 0;
            dfs(i);
        }
    }
    for (int i = 0; i < m; ++i) {
        if (ans[i] == 0) {
            cout << "->\n";
        } else {
            cout << "<-\n";
        }
    }
    return 0;
}

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC loop-opt(on)

#define rep(i, a, b) for(int i = a; i <= b; i++)
#define rrep(i, a, b) for(int i = b; i >= a; i--)
#define print(x) cout << #x <<" = " << x <<"\n"
#define pprint(x) cout << #x <<" = (" << x.first <<", " << x.second <<")\n"
#define all(x) x.begin(), x.end()
#define ceil(a, b) ((a + b - 1) / (b))

#define INF 1000000000000000000
#define MAXN 200
#define MOD 1000000007
#define eps (1e-9)

#define int long long int
#define lld long double
#define pii pair<int, int>
#define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count())

using namespace std;
int n, m, c[MAXN * MAXN], d[MAXN * MAXN];
int ans[MAXN*MAXN], v[MAXN*MAXN];
pii p[MAXN*MAXN];
int mp[MAXN][MAXN], timestamp, a, b;
void dfs(int x) {
	d[x] = ++timestamp;
	rep(i, 1, n) {
		if(c[i] == c[x] && !d[i] && mp[i][x]) {
			mp[x][i] = -1, mp[i][x] = -2;
			dfs(i);
		}
	}
	return;
}
void solve() {
	timestamp = 0;
	rep(i, 1, n) {
		if(!d[i]) d[i] = 1, dfs(i);
	}
	rep(i, 1, m) {
		tie(a, b) = p[i];
		if(c[a] > c[b]) ans[i] = -1;
		else if(c[b] > c[a]) ans[i] = -2;
		else if(mp[a][b] < 0) ans[i] = mp[a][b];
		else ans[i] = (d[a] > d[b] ? -1 : -2);
		mp[a][b] = ans[i];
		mp[b][a] = -3 - ans[i];
	}
	return ;
}
int dfs1(int x) {
	int cnt = 1; v[x] = 1;
	rep(i, 1, n) {
		if(!v[i] && mp[x][i] == -1) cnt += dfs1(i);
	}
	return cnt;
}
bool check() {
	rep(i, 1, n) {
		memset(v, 0, sizeof(v));
		if(dfs1(i) != c[i]) return false;
	}
	return true;
}
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> m;
	rep(i, 1, m) {
		cin >> a >> b;
		p[i] = {a, b};
		mp[a][b] = mp[b][a] = 1;
	}
	rep(i, 1, n) cin >> c[i];
	solve();
	assert(check());
	rep(i, 1, m) {
		if(ans[i] == -1) cout <<"->\n";
		else cout <<"<-\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
ll rand_int(ll l, ll r) //[l, r]
{
    static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
    return uniform_int_distribution<ll>(l, r)(gen);
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;
    cin>>n;
    ll t=1000;
    int cc=1;
    ll ans=0;
    while(t*1000<=n)
    {
        ans+=cc*(t*1000-t);
        t*=1000;
        cc++;
    }
    if(n>=t)
        ans+=(n-t+1)*cc;
    print(ans);
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(pow(2, n) / 2);
    vector<int> b(pow(2, n) / 2);
    for (int i = 0; i < pow(2, n) / 2; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < pow(2, n) / 2; i++) {
        cin >> b[i];
    }
    int maxElementA = *std::max_element(a.begin(), a.end());
    int maxElementB = *std::max_element(b.begin(), b.end());
    if(maxElementA > maxElementB) {
        cout << max_element(b.begin(),b.end()) - b.begin() + a.size() + 1 << endl;
    } else {
        cout << max_element(a.begin(),a.end()) - a.begin() + 1 << endl;
    }
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	int n;
	long a[22];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	long ans = 100000000007;
	for (int i = 0; i < (1 << (n - 1)); i++) {
		vector<long> vec;
		long o = 0;
		for (int j = 0; j < n; j++) {
			o |= a[j];
			if (i & (1 << j)) {
				vec.emplace_back(o);
				o = 0;
			}
		}
		vec.emplace_back(o);
		long co = 0;
		for (int j = 0; j < vec.size(); j++) {
			co ^= vec[j];
		}
		if (ans > co) {
			ans = co;
		}
	}
	cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
int n,a[210],dp[210][210],pi[210][210];
void output(int n,int m,int len)
{
    if(n==0)
    {
        cout<<len<<" ";
        return;
    }
    output(pi[n][m],((m-a[n])%200+200)%200,len+1);
    cout<<n<<" ";
}
bool check(int i)
{
    for(int j=1;j<n;j++)
		for(int k=j+1;k<=n;k++)
			if(dp[j][i]&&dp[k][i])
			{
				cout<<"Yes"<<endl;
				output(j,i,0);
				cout<<endl;
				output(k,i,0);
				return 1;
			}
	return 0;
}
bool flag;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		a[i]%=200;
	}
	dp[0][0]=1;
	for(int i=1;i<=n;i++)
		for(int j=0;j<200;j++)
		    for(int k=0;k<i;k++)
			    if(dp[k][((j-a[i])%200+200)%200])
			    	{
			    	    dp[i][j]=1;
			    	    pi[i][j]=k;
			    	    break;
			    	}
	for(int i=0;i<200;i++)
		if(check(i))
		{
		    flag=1;
		    break;
		}
	if(!flag)
	{
	    for(int i=1;i<n;i++)
        if(dp[i][0])
        {
            cout<<"Yes"<<endl;
			output(i,0,1);
			cout<<i+1<<endl;
			cout<<1<<" "<<i+1;
			flag=1;
        }
	}
	if(!flag)cout<<"No";
    return 0;
}


#include <bits/stdc++.h>

#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define reset(a,v) memset((a), v, sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

const int N = 3002;
const int MOD = 998244353;

int n, k;
int dp[N][N];

void fillDP() {
	dp[0][0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j = i; j > 0; j--) {
			dp[i][j] = (dp[i-1][j-1] + dp[i][min(N-1, 2*j)]) % MOD;
		}
	}
}

int main() {
	scanf("%d %d", &n, &k);
	fillDP();
	printf("%d\n", dp[n][k]);
	return 0;
}

#include "bits/stdc++.h"

#define MOD 998244353
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "
#define fi first
#define se second

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

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

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

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

ll N, K;
vector<llvec> m;

ll f(ll n, ll k){
  //cerr <<  n << " " << k << " ";
  if(k<=0)return 0;
  if(n<=0 or k<=0 or n<k){
    m[n][k] = 0;
    return 0;
  }
  if(n==k)m[n][k]=1;
  if(m[n][k]>=0)return m[n][k];
  ll tmp=0;
  tmp = mod(f(n-1, k-1) + f(n, 2*k), MOD);
  //cerr << tmp << endl;
  m[n][k]=tmp;
  return tmp;
}

/**************************************
** A main function starts from here  **
***************************************/
int main(){
  cin >> N >> K;
  m = vector<llvec>(N+1, llvec(2*(N+1), -1));
  cout << f(N, K);
  return 0;
}


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

#define int long long int
#define dbg(x) cerr << "[" << #x << " = " << x << "] ";
template<class T> auto vec( int r, int c, T v ){ return vector<vector<T>>( r, vector<T>( c, v ) ) ; }
template<class T> auto vec(int o1, int o2, int o3, T v){ return vector<vector<vector<T>>>(o1, vector<vector<T>>(o2, vector<T>(o3, v))); }
int power(int x, int n, int m = -1){
    if(m != -1) x %= m;
    int ans = 1;
    while(n > 0){
        if( n & 1 ) {
            ans *= x;
            if(m != -1) ans = ans % m;
        }
        x = x * x;
        if(m != -1) x = x % m;
        n >>= 1;
    }
    return ans;
}
const int mxx = (int)2e6;
// const int mxn = (int)1e5;
int nC2(int &x){
    if(x < 2) return 0;
    else return (x * (x - 1)) / 2;
}

signed main(){
    int L, R; cin >> L >> R;
    vector<int> a(R - L + 1);
    for(int i = L, k = 0; i <= R; i++) {
        a[k++] = i;
    }
    int n = a.size();
    vector<int> cnt(mxx + 1, 0);
    for(int i = 0; i < n; i++){
        cnt[a[i]] += 1;
    }
    vector<int> dp(mxx + 1, 0);
    for(int i = 1; i <= mxx; i++){
        for(int j = i; j <= mxx; j += i){
            dp[i] += cnt[j];
        }
    }
    for(int i = 1; i <= mxx; i++) dp[i] = nC2(dp[i]);
    for(int i = mxx; i >= 1; i--){
        for(int j = 2 * i; j <= mxx; j += i){
            dp[i] -= dp[j];
        }
    }
    int len = (R - L + 1);
    int tot = (len * (len - 1)) / 2;
    for(int i = max(2ll, L); i <= R; i++) {
        tot -= max(0ll, ((R / i) - 1));
        // dbg(R); dbg(i); dbg(R / i); cerr << endl;
    }
    // dbg(tot); cerr << endl;
    int res = (tot - dp[1]);
    // for(int i: a) cerr << i << " "; cerr << endl;
    // dbg(dp[1]); cerr << endl;
    cout << 2*res << "\n";
	return 0;
}

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

int main(){
	int t;
	int64_t N;
	cin >> t >> N;
	cout << (N*100+t-1)/t+(N-1) << endl;
	return 0;
}


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

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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cerr << #a << " = " << a << endl;

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}

template<typename T> void print(const T& a, ostream& out){
	for(auto i: a) out << i << ' ';
	out << endl;
}

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

namespace IntModulo
{
	const int mod = 998244353;

	inline int add(int x, int y, int m = mod)
	{
		if (x + y < m)
			return x + y;
		return x + y - m;
	}

	inline int sub(int x, int y, int m = mod)
	{
		if (x >= y)
			return x - y;
		return x - y + m;
	}

	inline int mult(int x, int y, int m = mod)
	{
		return x * (LL) y % m;
	}

	inline int power(int x, LL y, int m = mod)
	{
		int r = 1;
		while(y)
		{
			if (y & 1)
				r = mult(r, x, m);
			x = mult(x, x, m);
			y >>= 1;
		}

		return r;
	}

	inline int inverse(int x, int m = mod)
	{
		return power(x, m - 2, m);
	}

	inline void ADD(int& x, int y, int m = mod){
		x += y;
		if (x >= m) x -= m;
	}

	inline void SUB(int& x, int y, int m = mod){
		x -= y;
		if (x < 0) x += m;
	}

	inline void MULT(int& x, int y, int m = mod){
		x = (x * (LL) y) % m;
	}
};

using namespace IntModulo;

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

	int n = 3;
	int ans = 1;
	while(n--){
		LL x; cin >> x;
		MULT(ans, x * (x + 1) / 2 % mod);
	}

	cout << ans << endl;
    cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
    return 0;
}

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#define debug(x) cerr << __LINE__ << ' ' << #x << ':' << (x) << '\n'
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
template<class T> using prique = priority_queue<T, vector<T>, greater<T>>;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr int mod1e9 = 1000000007;
constexpr int mod998 = 998244353;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
constexpr ll ten(int n) { return n ? 10 * ten(n - 1) : 1; };
int dx[] = { 1,0,-1,0,1,1,-1,-1 }; int dy[] = { 0,1,0,-1,1,-1,1,-1 };
void fail() { cout << "-1\n"; exit(0); } void no() { cout << "No\n"; exit(0); }
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }
template<class T> istream &operator >> (istream &s, vector<T> &v) { for (auto &e : v) s >> e; return s; }
template<class T> ostream &operator << (ostream &s, const vector<T> &v) { for (auto &e : v) s << e << ' '; return s; }

struct fastio {
	fastio() {
		cin.tie(0); cout.tie(0);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(20);
		cerr << fixed << setprecision(20);
	}
}fastio_;

int main() {
	ll ans = 0;
	ll n;
	cin >> n;
	rep(_, n) {
		ll a, b;
		cin >> a >> b;
		ans += (a + b) * (b - a + 1) / 2;
	}
	cout << ans << '\n';
}


#include <bits/stdc++.h>

using namespace std;

#define ALL(x) x.begin(), x.end()
#define MP make_pair

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int main() {
#ifndef LOCAL
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#endif

    int n = 0;
    cin >> n;
    set<int> st;
    for (int i = 0; i < n; i++) {
        st.insert(i + 1);
    }
    for (int i = 0; i < n; i++) {
        int x = 0;
        cin >> x;
        st.erase(x);
    }
    if (st.size()) {
        cout << "No" << '\n';
    } else {
        cout << "Yes" << '\n';
    }

    return 0;
}
/**
 *  created: 2021/06/13  20:01:23
 *  compile: g++ sol.cpp -o sol.out -g -std=c++17 -Wall -Wextra -Wshadow -fsanitize=undefined -fsanitize=address -D_GLIBCXX_DEBUG -DLOCAL
**/

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

#define LETS_GET_SCHWIFTY ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ff              first
#define ss              second
#define int             long long
#define ll              long long
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)      __builtin_ctzll(x)
#define mod             998244353
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define vpii            vector<pair<int,int> >
#define all(x)          x.begin(),x.end()
#define matrixprint(arr,a,b,c,d) for(int i=a;i<=c;i++){for(int j=b;j<=d;j++){cout<<arr[i][j]<<" ";}cout<<"\n";}
#define show(arr,x,y)   for(int i=x;i<=y;i++){cout<<arr[i]<<" ";}cout<<"\n"
#define sz(x)           (int)x.size()
#define db(x)           cout<<x<<"\n";

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

//insert,find_by_order,order_of_key,lower_bound,upper_bound;

#define TRACE
#ifdef TRACE
#define deb(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#else
#define deb(...)
#endif

//////////////////////////////code//////////////////////////////

const int N = 200;

void solve()
{

      int n;
      cin >> n;

      vi cnt(n + 1);

      for(int i = 0;i < n; i++)
      {
            int d;
            cin >> d;
            cnt[d]++;
      }

      for(int i = 1;i <= n ;i++)
      {
            if(cnt[i] != 1)
            {
                db("No")
                return;
            }
      }

      db("Yes")

}

int32_t main()
{

    LETS_GET_SCHWIFTY;

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

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

    while (t--)
        solve();

}

// check out for following mistakes-
// if using pb operation on vector and then trying to access index..check if sizeof that vec could remain 0 only
// is using prime sieve make sure it fits
// when using factorial template or combinatorics make sure that you edit fillfac fun values and array values


#include <bits/stdc++.h>
#define s second
#define f first
#define pb push_back
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define read(x) for(auto& qw : (x)) cin >> qw;
#define print(x) for(auto& qw : (x)) cout << qw << " "; cout << endl;
using namespace std;

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

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;

const int MAX = 1e6 + 10;

ll DP[4][MAX * 3];

void test_case(){
	int N;
	ll K;
	cin >> N >> K;

	memset(DP, 0, sizeof DP);
	DP[0][0] = 1;

	for (int times : {0,1,2}) {
		for (int j = 0; j + 1 < MAX*3; j++) {
			DP[times + 1][j + 1] += DP[times][j];
			if (j + N + 1 < 3*MAX)
				DP[times + 1][j + N + 1] -= DP[times][j];
		}
		ll at = 0;
		for (int j = 0; j < 3*MAX; j++) {
			at += DP[times + 1][j];
			DP[times + 1][j] = at;
		}
	}

	int at = 1;
	for (int i = 0; i < 3 * MAX; i++) {
		if (DP[3][i] >= K) {
			at = i;
			break;
		}
		K -= DP[3][i];
	}

	for (int i = 1; i <= N; i++) {
		int mi = max(1, at - N - i);
		int ma = min(N, at - i - 1);

		if (mi > ma) continue;

		if ((ma - mi + 1) < K) {
			K -= (ma - mi + 1);
			continue;
		}

		cout << i << " " << mi + K - 1 << " " << at - i - mi - K + 1 << endl;
		break;
	}

}

int main(){ _

	int tt = 1;
//	cin >> tt;

	while(tt--){
		test_case();
	}

	return 0;
}

#include <bits/stdc++.h>

#define LL long long

#define ull unsigned long long

#define F(i, j, k) for(int i = j; i <= k; i++)

#define DF(i, j, k) for(int i = j; i >= k; i--)

using namespace std;

template <typename T> inline void read(T &n) {
	T w = 1;
	n = 0;
	char ch = getchar();
	while (!isdigit(ch) && ch != EOF) {
		if (ch == '-') w = -1;
		ch = getchar();
	}
	while (isdigit(ch) && ch != EOF) {
		n = (n << 3) + (n << 1) + (ch & 15);
		ch = getchar();
	}
	n *= w;
}

template <typename T> inline void write(T x) {
	T l = 0;
	ull y = 0;
	if (!x) {
		putchar(48);
		return;
	}
	if (x<0) {
		putchar('-');
		x = -x;
	}
	while (x) {
		y = y * 10 + x % 10;
		x /= 10;
		l++;
	}
	while (l) {
		putchar(y % 10 + 48);
		y /= 10;
		l--;
	}
}

template <typename T> inline void writes(T x) {
	write(x);
	putchar(' ');
}

template <typename T> inline void writeln(T x) {
	write(x);
	puts("");
}

template <typename T> inline void checkmax(T &a,T b) { a = a > b ? a : b; }

template <typename T> inline void checkmin(T &a,T b) { a = a < b ? a : b; }

const int N = 2e5 + 10;

bool chg[N];

struct wzy {
	LL x, c;
	wzy (LL X = 0,LL C = 0) {
		x = X;
		c = C;
	}
};

struct Point {
	LL x, y;
} p[N];

struct Opt {
	wzy x, y;
} opt[N];

int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	int n;
	read(n);
	F(i, 1, n) {
		read(p[i].x);
		read(p[i].y);
	}
	int m;
	read(m);
	opt[0].x.x = 1;
	opt[0].y.x = 1;
	chg[0] = 0;
	F(i, 1, m) {
		int op;
		LL k;
		read(op);
		if (op == 1 || op == 2) {
			opt[i].x = opt[i - 1].y;
			opt[i].y = opt[i - 1].x;
			chg[i] = chg[i - 1] ^ 1;
		}
		else {
			opt[i].x = opt[i - 1].x;
			opt[i].y = opt[i - 1].y;
			chg[i] = chg[i - 1];
			read(k);
		}
		if (op == 1) { opt[i].y.x = -opt[i].y.x; opt[i].y.c = -opt[i].y.c; }
		if (op == 2) { opt[i].x.x = -opt[i].x.x; opt[i].x.c = -opt[i].x.c;}
		if (op == 3) { opt[i].x.x = -opt[i].x.x; opt[i].x.c = 2 * k - opt[i].x.c; }
		if (op == 4) { opt[i].y.x = -opt[i].y.x; opt[i].y.c = 2 * k - opt[i].y.c; }
	}
	int q;
	read(q);
	F(i, 1, q) {
		int ti, pi;
		read(ti);
		read(pi);
		LL x = p[pi].x;
		LL y = p[pi].y;
		if (chg[ti]) swap(x, y);
		writes(x * opt[ti].x.x + opt[ti].x.c);
		writeln(y * opt[ti].y.x + opt[ti].y.c);
	}
	return 0;
}


#ifdef _LOCAL
    #include "local_include.hpp"
#else
    #include <bits/stdc++.h>
    using namespace std;
#endif
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;

#define fto(i, s, e) for (int i = (s); i <= (e); ++i)
#define fto1(i, s, e) for (int i = (s); i < (e); ++i)
#define fdto(i, s, e) for (int i = (s); i >= (e); --i)
#define fit(it, a) for (auto it = (a).begin(); it != (a).end(); ++it)
#define fat(i, a) for (auto i : (a))

#define ll long long
#define ii pair<int, int>
#define pll pair<ll, ll>
template<class T, class Cmp = less<T>> using oss = tree<T, null_type, Cmp, rb_tree_tag, tree_order_statistics_node_update>;

#define bc __builtin_popcountll
#define y1 ansdj
#define endl '\n'
#define ff first
#define ss second
#define sz(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define bug(...) _bug(cout, __VA_ARGS__)
#define buga(a, s, e) cout << '{'; if (e < s) cout << '}'; else fto (__i, s, e) cout << a[__i] << " }"[__i == e]; cout << endl

template<class T1, class T2> ostream& operator<<(ostream &os, pair<T1, T2> const &v) {
    return os << '(' << v.ff << ", " << v.ss << ')';
}

template<typename T>
void _bug(ostream &os, T const &var) { os << var << endl; }

template<typename T, typename... Args>
void _bug(ostream &os, T const &var, Args const &... args) {
    os << var << ' ';
    _bug(os, args...);
}

double const pi = acos(-1);
#define oo 1000000007
#define OO 1000000000000000003LL
int const maxn = 2e5+3;

int n, m, k;
int row[maxn], col[maxn];
bool check[maxn];
vector<int> store[maxn];

#define multi_test 0
void _main() {
    cin >> n >> m >> k;
    fto (i, 1, n) row[i] = m+1;
    fto (i, 1, m) col[i] = n+1;
    int u, v;
    fto (i, 1, k) {
        cin >> u >> v;
        row[u] = min(row[u], v);
        col[v] = min(col[v], u);
        store[v].push_back(u);
    }

    int mx = n+1;
    ll ans = 0;
    fto (i, 1, n) {
        if (row[i] == 1) {
            mx = i;
            break;
        }
        ans += row[i]-1;
    }

    oss<ii> s;
    fto (i, 1, m) {
        if (col[i] == 1) break;
        ans += s.order_of_key(ii(col[i], 0));
        if (col[i] > mx) ans += col[i] - mx;
        fat (u, store[i]) {
            if (u >= mx) continue;
            if (!check[u]) {
                check[u] = 1;
                s.insert(ii(u, i));
            }
        }
    }

    bug(ans);
}

int main() {
    #ifdef _LOCAL
        freopen("main.inp", "r", stdin);
        freopen("main.out", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    int t = 1;
    if (multi_test) cin >> t;
    while (t--) {
        _main();
    }

    #ifdef _LOCAL
        cerr << 0.001*clock() << endl;
    #endif
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long h , w , m , tree [800020] , ans , mn = 1e9 , num;
vector < int > v [200005];
void up ( int nod , int l , int r , int x )
{
    if ( x < l || r < x ) return;
    if ( l == r )
    {
        tree [nod] = 1;
        return;
    }
    int mid = ( l + r ) / 2;
    up ( nod * 2 , l , mid , x );
    up ( nod * 2 + 1 , mid + 1 , r , x );
    tree [nod] = tree [ nod * 2 ] + tree [ nod * 2 + 1 ];
}
long long qr ( int nod , int l , int r , int x , int y )
{
    if ( x <= l && r <= y ) return tree [nod];
    if ( y < l || r < x ) return 0;
    int mid = ( l + r ) / 2;
    return qr ( nod * 2 , l , mid , x , y ) + qr ( nod * 2 + 1 , mid + 1 , r , x , y );
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("milk.in","r",stdin);
    //freopen("milk.out","w",stdout);
    cin >> h >> w >> m;
    for ( int i = 0 ; i < m ; i ++ )
    {
        long long  x , y;
        cin >> x >> y;
        v [y] . push_back ( x );
        if ( y == 1 )
        {
            num ++;
            mn = min ( mn , x );
        }
    }
    for ( int i = mn ; i <= h ; i ++ )
    {
        ans ++;
        up ( 1 , 1 , h , i );
    }
    ans -= num;
    int f = 0;
    for ( int i = 2 ; i <= w ; i ++ )
    {
        if ( v [i] . size () == 0 )
        {
            if ( f ) ans += qr ( 1 , 1 , h , 1 , h );
            continue;
        }
        sort ( v [i] . begin () , v [i] . end () );
        int first = * v [i] . begin ();
        if ( first == 1 ) f = 1;
        if ( f == 0 ) ans += qr ( 1 , 1 , h , first , h );
        else ans += qr ( 1 , 1 , h , 1 , h );
        for ( int j = 0 ; j < v [i] . size () ; j ++ )
        {
            int x = v [i][j];
            if ( qr ( 1 , 1 , h , x , x ) ) ans --;
            up ( 1 , 1 , h , x );
        }
    }
    cout << h * w - m - ans;
}
/*
4 4 2
2 1
1 3
*/


/* by Natsu Kinmoe */
#include <bits/stdc++.h>
using namespace std;
#define SZ(x)               ((int)(x).size())
#define all(x)              (x).begin(), (x).end()
#define loop(i, n)          for(int i = 0; i < (n); ++i)
#define cont(i, n)          for(int i = 1; i <= (n); ++i)
#define circ(i, a, b)       for(int i = (a); i <= (b); ++i)
#define range(i, a, b, c)   for(int i = (a); ((c) > 0 ? i <= (b) : i >= (b)); i += (c))
#define foreach(it, v)      for(__typeof((v).begin()) it = (v).begin(); it != (v).end(); ++it)
#define y0          y0O0OO00OO0OO0OO0OOO00OO0OO0O0O000OO0
#define y1          y1II11II11III11I1III11II111IIII1II1I1
#define pub         push_back
#define pob         pop_back
#define mak         make_pair
typedef long long   ll;
typedef long double lf;
const int   Inf = 0x3f3f3f3f;
const ll    INF = 0x3f3f3f3f3f3f3f3fll;
/* Source code starts here */

template<int jt> struct ModInt {
	int x;
	ModInt(int v = 0) {x = v; if(x >= jt || x < 0) {x %= jt; if(x < 0) x += jt;}}
	ModInt(ll v) {x = v % jt; if(x < 0) x += jt;}
	operator int() const {return x;}
	friend inline ModInt &operator+=(ModInt &a, const ModInt &b) {a.x += b.x; if(a.x >= jt) a.x -= jt; return a;}
	friend inline ModInt operator+(ModInt a, const ModInt &b) {return a += b;}
	friend inline ModInt operator+(ModInt a, int b) {return a += ModInt(b);}
	friend inline ModInt operator+(int a, ModInt b) {return b += ModInt(a);}
	friend inline ModInt &operator++(ModInt &a) {return a += 1;}
	friend inline ModInt &operator-=(ModInt &a, const ModInt &b) {a.x -= b.x; if(a.x < 0) a.x += jt; return a;}
	friend inline ModInt operator-(ModInt a, const ModInt &b) {return a -= b;}
	friend inline ModInt operator-(ModInt a, int b) {return a -= ModInt(b);}
	friend inline ModInt operator-(int a, ModInt b) {return ModInt(a) - b;}
	friend inline ModInt &operator--(ModInt &a) {return a -= 1;}
	friend inline ModInt &operator*=(ModInt &a, const ModInt &b) {a.x = (ll)a.x * b.x % jt; return a;}
	friend inline ModInt operator*(ModInt a, const ModInt &b) {return a *= b;}
	friend inline ModInt operator*(ModInt a, int b) {return a *= ModInt(b);}
	friend inline ModInt operator*(int a, ModInt b) {return b *= ModInt(a);}
	static inline void exgcd(ll a, ll b, ll &x, ll &y) {b ? (exgcd(b, a % b, y, x), y -= a / b * x) : (x = 1, y = 0);}
	friend inline ModInt inv(const ModInt &a) {ll x, y; exgcd(a, jt, x, y); return x;}
	friend inline ModInt operator/(const ModInt &a, const ModInt &b) {return a * inv(b);}
	friend inline ModInt operator/(ModInt a, int b) {return a * inv(ModInt(b));}
	friend inline ModInt operator/(int a, ModInt b) {return ModInt(a) * inv(b);}
	friend inline ModInt operator/=(ModInt &a, const ModInt &b) {return a = a / b;}
};
const int jt = 998244353;
typedef ModInt<jt> mint;

int n, k;
mint dp[3005][3005];

int main() {
	scanf("%d%d", &n, &k);
	dp[0][0] = 1;
	cont(i, n) range(j, n, 1, -1) {
		if(j <= n / 2) dp[i][j] += dp[i][j * 2];
		if(j) dp[i][j] += dp[i - 1][j - 1];
	}
	printf("%d\n", dp[n][k]);
	return 0;
}

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

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

int H, W, A, B;
int dp[1 << 16][10][10];

int unit(int bit, int a, int b)
{
    if(bit == (1LL << H * W) - 1)return 1;
    if(dp[bit][a][b] != -1)return dp[bit][a][b];
    int n = 0;
    for(int i = 1;; n++)if(!(bit & (1LL << n)))break;
    int ret = 0;
    int _bit = bit | (1 << n);
    if(a)
    {
        if(n % W != W - 1 && !(bit & (1LL << (n + 1))))ret += unit(_bit | (1 << (n + 1)), a - 1, b);
        if(n + W < H * W)ret += unit(_bit | (1 << (n + W)), a - 1, b);
    }
    if(b)ret += unit(_bit, a, b - 1);

    return dp[bit][a][b] = ret;
}

signed main()
{
    cin >> H >> W >> A >> B;

    memset(dp, -1, sizeof(dp));
    cout << unit(0, A, B) << endl;

    return 0;
}


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

#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back
#define fi first
#define se second
#define sz(x) ((int)x.size())

using namespace std;
//using namespace atcoder;
using ld = long double;
using ll = long long;
using P = pair<ll, ll>;

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

const ll ZER = 0;
const ll MOD = 998244353;
const ll INF = 1e18;

int main(){
    ll n;
    cin >> n;
    int res = 0;
    REP(i, 1, 1e6){
        ll tmp = i;
        int cnt = 0;
        while(tmp){
            cnt++;
            tmp /= 10;
        }
        ll now = (ll)i * powl(10, cnt)  + (ll)i;
        if(n < now)break;
        res++;
    }
    cout << res << endl;
}

#include <iostream>
#include <vector>
#include <deque>
#include <cstring>
#include <map>
#include <cmath>
#include <algorithm>
#include <stdlib.h>
#include <set>
#include <climits>
#include <string.h>
#include <unordered_map>
#include <queue>
#include <list>
#define int long long int
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;

const int mod = 1e9 + 7;

const int N = 1e6 + 5;

bool valid(string s)
{
	for(int i = 0; i < s.size(); i++)
	{
		if(i != s.size()-1 &&  s[i] == '.')
		{
			return true;
		}
	}
	return false;
}

int32_t main()
{

	fastio;
	int n;
	cin >> n;
	int low = 0;
	int high = 10000000;
	while(low + 1 < high)
	{
		int mid = low + (high - low) / 2;
		int d = log10(mid) + 1;
		int add = pow(10, d);
		int val = mid * add + mid;
		if(val <= n)
		{
			low = mid;
		}
		else
		{
			high = mid;
		}
		// cout << val << '\n';
	}
	cout << low << '\n';
	return 0;
}


#include <iostream>
#include <cmath>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <iterator>
#include <unordered_map>
#include <unordered_set>
#include <sstream>
#include <fstream>
#include <numeric>
#include <tuple>
#include <ctime>
#include <random>
#include <array>
#include <cassert>

using namespace std;

#define fori(t) for(int i = 0; i < t; ++i)
#define forj(n) for(int j = 0; j < n; ++j)
#define fork(n) for(int k = 0; k < n; ++k)
#define forai(a) for(auto& i : a)
#define foraj(a) for(auto& j : a)
#define forak(a) for(auto& k : a)
#define forp(s, n, d) for(int p = s; p < n; p += d)
#define fast ios_base::sync_with_stdio(0); cin.tie(0);
#define pb(a) push_back(a);
#define pob(a) pop_back(a);
#define sorti(a) sort((a).begin(), (a).end());
#define sortm(a, n) sort(a, a + n);
#define reversi(a) reverse((a).begin(), (a).end());
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
#define yes cout << "YES\n";
#define no cout << "NO\n";
#define ans(a) cout << a << '\n';
#define endl '\n'
#define res(a, n) (a).resize(n);
#define read(a, n) (a).resize(n); fori(n) cin >> a[i];
#define print(a) for (auto hart : a) cout << hart << ' ';
#define clear(a) (a).clear();
//#define int long long
//#define double long double

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<long long, long long> llll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<int, int>> vii;
typedef vector<pair<int, pair<int, int>>> viii;
typedef pair<int, pair<int, int>> iii;
typedef vector<pair<long long, long long>> vllll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<bool> vb;
typedef pair<char, char> cc;
typedef pair<pair<char, char>, char> ccc;
typedef vector<char> vc;
typedef pair<int, char> ic;
typedef pair<ii, char> iic;
typedef vector<bool> vb;
typedef set<int> si;
typedef vector<vector<ii>> vvii;
typedef vector<vector<iii>> vviii;
typedef vector<vector<llll>> vvllll;

const int INF = 2147483647;
const ll LONGINF = 9223372036854775807;
const ll MOD = 1e9 + 7;

void solve()
{
    ll t, n;
    cin >> t >> n;
    ll l = 1, r = 1e12;
    while (l < r)
    {
        ll m = (l + r) >> 1ll;
        if (floorl((ld)(m * t) / 100.0) < n) l = m + 1;
        else r = m;
    }
    ans(l + n - 1)
}

signed main()
{
    fast
    bool mult = false;
    if (mult)
    {
        int t;
        cin >> t;
        while (t--) solve();
    }
    else solve();
    return 0;
}

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

int main() {
  ll t, N;
  cin >> t >> N;
  set<ll> hundred;
  vector<ll> hundred2;
  // for (int i = 1; i <= 1000000; i++) {
  //   hundred.insert(((100 + t) * i) / 100);
  // }
  // for (int i = 1; i <= 1000000; i++) {
  //   if (!(hundred.count(i))) {
  //     hundred2.push_back(i);
  //   }
  // }
  ll count = t;
  ll start = (N / count) * 100;
  ll nokori = N % count;
  // for (ll x : hundred2) {
  //   cout << x << endl;
  // }
  // cout << ((100 + t) * (start + hundred2.at(nokori))) / 100 << endl;
  // cout << start + hundred2.at(nokori) << endl;
  // cout << (((100 + t) * start)) - 1 / 100 << endl;
  set<ll> ans;
  vector<ll> ans2 = {0};
  for (ll i = start; i <= start + 1000000; i++) {
    ans.insert(((100 + t) * i) / 100);
  }
  for (ll i = ((100 + t) * start) / 100;
       i <= (((100 + t) * start) / 100) + 1000000; i++) {
    if (!(ans.count(i))) {
      ans2.push_back(i);
    }
  }
  // for (ll x : ans2) {
  //   cout << x << endl;
  // }
  // cout << nokori << endl;
  if (nokori != 0) {
    cout << ans2.at(nokori) << endl;
  } else {
    cout << (((100 + t) * start) / 100) - 1 << endl;
  }
  return 0;
}


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

#define int long long

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

  set <int> s1;

  int mi,ma;

  for(int i=0;i<n;i++)
  {
    int x;
    cin>>x;

    s1.insert(x);

    if(i==0)
    {
      mi=x;
      ma=x;
    }

    mi=min(mi,x);
    ma=max(ma,x);
  }

  if(s1.size()==n && mi==1 && ma==n)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}

int32_t main()
{
  // freopen("input1.txt","r",stdin);
  // freopen("output1.txt","w",stdout);

  int t;
  t=1;

  while(t--)
    solve();

return 0;
}

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

int main() {
  vector<int>A(3);
  for(auto&&x:A)cin>>x;
  sort(A.begin(),A.end());
  if(A[2]-A[1]==A[1]-A[0])cout <<"Yes"<<endl;
  else cout <<"No"<<endl;

  return 0;
}


#include <bits/stdc++.h>
#define INF 1e9
#define INFLL 1ull<<60u
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

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

using vi = vector<int>;
using vvi = vector<vi>;
using vpii = vector<pair<int,int>>;

void solve() {
    // 前計算
    vector<int> v((1e5)+1,0);
    auto haveSevenInEight = [](auto &&f,int val)-> bool {
        if(val%8 == 7) return true;
        if(val > 8) return f(f,val/8);
        return false;
    };
    auto haveSeven = [](int val) -> bool {
        auto s = to_string(val);
        if(any_of(ALL(s),[](char c) { return c == '7'; })) return true;
        return false;
    };
    v[1] = 1;
    FOR(i,2,(1e5)+1) {
        bool find = haveSeven(i) || haveSevenInEight(haveSevenInEight,i);
        v[i] = v[i-1] + !find;
    }
    int N; cin >> N;
    cout << v[N] << endl;
}

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

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

typedef long long LL;

const int N = 1e6;

int length(int x)
{
	int cnt = 0;
	while(x) cnt ++, x /= 10;
	return cnt;
}

int main()
{
	// freopen("1.in", "r", stdin);
	LL n;
	cin >> n;
	int res = 0;
	for(int i = 1; i < N; ++ i)
	{
		int j = length(i);
		if((LL)i * pow(10, j) + i > n) break;
		res ++;
	}
	cout << res << endl;
}