Datasets:

problem_id
stringlengths
6
6
buggy_code
stringlengths
8
526k
fixed_code
stringlengths
12
526k
labels
listlengths
0
15
buggy_submission_id
int64
1
1.54M
fixed_submission_id
int64
2
1.54M
user_id
stringlengths
10
10
language
stringclasses
9 values
p03141
#include <bits/stdc++.h> using namespace std; template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; template <class T> using VVV = V<VV<T>>; template <class S, class T> using P = pair<S, T>; template <class S, class T, class U> using TP = tuple<S, T, U>; using ll = long long; using ull = unsigned long long; using dbl = double; using str = string; using vll = V<ll>; using vvll = V<vll>; using vvvll = V<vvll>; using pl = P<ll, ll>; using tl = TP<ll, ll, ll>; using vpl = V<pl>; using vvpl = V<vpl>; using vtl = V<tl>; using vvtl = V<vtl>; using vs = V<str>; using vvs = V<vs>; using vd = V<dbl>; using vvd = V<vd>; using qll = queue<ll>; using qpl = queue<pl>; using stll = stack<ll>; using stpl = stack<pl>; using mapll = map<ll, ll>; using setll = set<ll>; using pqll = priority_queue<ll>; //#define int ll #define fi first #define se second #define mp make_pair #define mt make_tuple #define pb push_back #define pob pop_back() #define pf push_front #define pof pop_front() #define sz size() #define bgn begin() #define en end() #define asn assign #define emp empty() #define fr front() #define bk back() #define clr clear() #define ins insert #define ers erase #define res resize #define tp top() #define p_q priority_queue #define inv inverse() #define FOR(i, a, b) for (ll i = (a); i <= (ll)(b); i++) #define rFOR(i, a, b) for (ll i = (b); i >= (ll)(a); i--) #define REP(i, a) FOR((i), 0, (ll)(a)-1) #define REP0(i, a) FOR((i), 0, (ll)(a)) #define REP1(i, a) FOR((i), 1, (ll)(a)) #define rREP(i, a) rFOR((i), 0, (ll)(a)-1) #define rREP0(i, a) rFOR((i), 0, (ll)(a)) #define rREP1(i, a) rFOR((i), 1, (ll)(a)) #define ROR(v, i) for (auto &(i) : (v)) #define IOTA(a, n) iota((a).bgn, (a).en, (n)) #define SORT(a) sort((a).bgn, (a).en) #define rSORT(a) sort((a).rbegin(), (a).rend()) #define UNIQUE(a) (a).erase(unique((a).bgn, (a).en), (a).en) #define PREVP(a) prev_permutation((a).bgn, (a).en) #define NEXTP(a) next_permutation((a).bgn, (a).en) #define BINS(a, b) binary_search((a).bgn, (a).en, (b)) #define LOWB(a, b) (lower_bound((a).bgn, (a).en, (b)) - (a).bgn) #define UPB(a, b) (upper_bound((a).bgn, (a).en, (b)) - (a).bgn) #define CNT(a, b) count((a).bgn, (a).en, b) #define SUM(a) accumulate((a).bgn, (a).en, 0) #define REV(a) reverse((a).bgn, (a).en) #define REGS(a, b) regex_search((a), regex(b)) #define REGM(a, b) regex_match((a), regex(b)) #define yn(a) cout << ((a) ? "yes" : "no") << "\n"; #define Yn(a) cout << ((a) ? "Yes" : "No") << "\n"; #define YN(a) cout << ((a) ? "YES" : "NO") << "\n"; #define imp(a) cout << ((a) ? "possible" : "impossible") << "\n"; #define Imp(a) cout << ((a) ? "Possible" : "Impossible") << "\n"; #define IMP(a) cout << ((a) ? "POSSIBLE" : "IMPOSSIBLE") << "\n"; #define fs(a) cout << ((a) ? "second" : "first") << "\n"; #define Fs(a) cout << ((a) ? "Second" : "First") << "\n"; #define FS(a) cout << ((a) ? "SECOND" : "FIRST") << "\n"; //#define say(a) cout <<(a); //#define sal(a) cout <<(a)<<"\n"; #define sak cout << "\n"; #define sas cout << " "; #define sat cout << "\t"; #define dbg(a) cerr << (#a) << ": " << (a) << "\n"; #define dbgs(...) \ dal(#__VA_ARGS__); \ dal(__VA_ARGS__); #define c2l(a) ((ll)(a - 48)) #define a2l(a) ((ll)(a - 97)) #define A2l(a) ((ll)(a - 65)) #define l2c(a) ((char)(a + 48)) #define l2a(a) ((char)(a + 97)) #define l2A(a) ((char)(a + 65)) #define DigN2(a) ((llabs(a) == 0) ? (1) : ((ll)(log2(double(llabs(a)))) + 1)) #define DigN10(a) ((llabs(a) == 0) ? (1) : ((ll)(log10(double(llabs(a)))) + 1)) #define Dig2(a, b) (((a) >> (b)) & 1) #define Dig10(a, b) (ll)(((a) / ((ll)(pow(10.0, (double)(b))))) % 10) #define Pow2(a) ((ll)(1) << (a)) #define Pow10(a) ((ll)(pow(10.0, double(a)))) #define LSB(a) ((a) & (-(a))) /*#define llin(a) ll (a);cin >>(a); #define llin2(a,b) ll (a),(b);cin >>(a)>>(b); #define llin3(a,b,c) ll (a),(b),(c);cin >>(a)>>(b)>>(c); #define stin(a) string (a);cin >>(a);*/ #define vin(v) \ ROR((v), (i)) { cin >> (i); }; #define vllin(v, N) \ vll(v)((N)); \ vin(v); #define vllin2(a, b, N) \ vll(a)(N), (b)(N); \ REP(i, N) { cin >> (a)[i] >> (b)[i]; }; #define vsin(v, N) \ vs(v)((N)); \ vin(v); #define rdn(a, b) ((a) / (b)) #define rou(a, b) \ ((((double(a) / double(b)) - ((a) / (b))) < 0.5) ? ((a) / (b)) \ : (((a) / (b)) + 1)) #define rup(a, b) ((((a) % (b)) == 0) ? ((a) / (b)) : (((a) / (b)) + 1)) #define powll(a, b) (ll)(pow((double)(a), (double)(b))) #define Triangle(x1, y1, x2, y2, x3, y3) \ (((x1) - (x2)) * ((y1) - (y3)) - ((x1) - (x3)) * ((y1) - (y2))) #define lam(lr) ([](auto l, auto r) { lr }) #define elam(lr) ([=](auto l, auto r) { lr }) #define clam(lr) ([&](auto l, auto r) { lr }) #define min(...) Operation(MIN, __VA_ARGS__) #define max(...) Operation(MAX, __VA_ARGS__) #define gcd(...) Operation(GCD, __VA_ARGS__) #define lcm(...) Operation(LCM, __VA_ARGS__) #define vmin(...) VOperation(MIN, __VA_ARGS__) #define vmax(...) VOperation(MAX, __VA_ARGS__) #define vgcd(...) VOperation(GCD, __VA_ARGS__) #define vlcm(...) VOperation(LCM, __VA_ARGS__) #define vsum(...) VOperation(ADD, __VA_ARGS__) #define vpro(...) VOperation(MUL, __VA_ARGS__) #define emin(a, ...) ((a) = min((a), __VA_ARGS__)) #define emax(a, ...) ((a) = max((a), __VA_ARGS__)) #define egcd(a, ...) ((a) = gcd((a), __VA_ARGS__)) #define elcm(a, ...) ((a) = lcm((a), __VA_ARGS__)) #define ActPair(T) P<T, function<T(T, T)>> #define BoolPair(T) P<T, function<bool(T, T)>> #define ope Operation #define vope VOperation #define svll SumV<ll> #define svvll SumV2<ll> #define li(...) \ ll __VA_ARGS__; \ Input(__VA_ARGS__); #define si(...) \ str __VA_ARGS__; \ Input(__VA_ARGS__); //#define vli(size, ...) vll __VA_ARGS__;vInitInput(size,__VA_ARGS__); #define vlr(size, ...) \ vll __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vlc(size, ...) \ vll __VA_ARGS__; \ vInitInputC(size, __VA_ARGS__); #define vli(size, ...) \ vll __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vsr(size, ...) \ vs __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vsc(size, ...) \ vs __VA_ARGS__; \ vInitInputC(size, __VA_ARGS__); #define vsi(size, ...) \ vs __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vli2(rowSize, columnSize, ...) \ vvll __VA_ARGS__; \ vInitInput2(rowSize, columnSize, __VA_ARGS__); #define vplr(size, ...) \ vpl __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vplc(size, ...) \ vpl __VA_ARGS__; \ vInitInputC(size, __VA_ARGS__); #define vpli(size, ...) \ vpl __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); const ll MOD = 1e9 + 7; // const ll MOD = 998244353; // const ll MOD = 924844033; // const ll MOD = 9007199254740881; const ll INF = 1LL << 60; // 1.15e18 const double PI = acos(-1.0); const vll DX = {0, -1, 0, 1, 0, -1, 1, 1, -1}; const vll DY = {0, 0, -1, 0, 1, -1, -1, 1, 1}; const str alp = "abcdefghijklmnopqrstuvwxyz"; const str ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; template <class S, class T> istream &operator>>(istream &in, P<S, T> &p) { return in >> p.fi >> p.se; } template <class T> istream &operator>>(istream &in, V<T> &v) { REP(i, v.sz) in >> v[i]; return in; } void Input() {} template <class Var, class... Args> void Input(Var &var, Args &...args) { cin >> var; Input(args...); } void vInit(ll size) {} template <class T, class... Args> void vInit(ll size, V<T> &v, Args &...args) { v.res(size); vInit(size, args...); } void vInput(ll size) {} template <class T, class... Args> void vInput(ll size, V<T> &v, Args &...args) { REP(i, size) cin >> v[i]; vInput(size, args...); } void vInputR(ll size) {} template <class T, class... Args> void vInputR(ll size, V<T> &v, Args &...args) { REP(i, size) cin >> v[i]; vInputR(size, args...); } void vInputNumC(ll num) {} template <class T, class... Args> void vInputNumC(ll num, V<T> &v, Args &...args) { cin >> v[num]; vInputNumC(num, args...); } void vInputC(ll size) {} template <class... Args> void vInputC(ll size, Args &...args) { REP(i, size) vInputNumC(i, args...); } void vInitInputR(ll size) {} template <class... Args> void vInitInputR(ll size, Args &...args) { vInit(size, args...); vInputR(size, args...); } void vInitInputC(ll size) {} template <class... Args> void vInitInputC(ll size, Args &...args) { vInit(size, args...); vInputC(size, args...); } void vInit2(ll rowSize, ll columnSize) {} template <class T, class... Args> void vInit2(ll rowSize, ll columnSize, V<V<T>> &v, Args &...args) { v.asn(rowSize, V<T>(columnSize)); vInit2(rowSize, columnSize, args...); } void vInput2(ll rowSize, ll columnSize) {} template <class T, class... Args> void vInput2(ll rowSize, ll columnSize, V<V<T>> &v, Args &...args) { REP(r, rowSize) { REP(c, columnSize) { cin >> v[r][c]; } } vInput2(rowSize, columnSize, args...); } void vInitInput2(ll rowSize, ll columnSize) {} template <class... Args> void vInitInput2(ll rowSize, ll columnSize, Args &...args) { vInit2(rowSize, columnSize, args...); vInput2(rowSize, columnSize, args...); } template <class S, class T> ostream &operator<<(ostream &out, const P<S, T> &p) { return out << "[" << p.fi << ", " << p.se << "]"; } template <class T> ostream &operator<<(ostream &out, V<T> &v) { if (v.emp) return out << "{}"; else { auto itr = v.bgn; out << "{" << *itr; itr++; while (itr != v.en) { out << ", " << *itr; itr++; } out << "}"; return out; } } template <class S, class T> ostream &operator<<(ostream &out, const map<S, T> &m) { if (m.emp) return out << "<[]>"; else { auto itr = m.bgn; out << "< [" << (itr->fi) << ": " << (itr->se); itr++; while (itr != m.en) { out << "], [" << (itr->fi) << ": " << (itr->se); itr++; } out << "] >"; return out; } } template <class T> ostream &operator<<(ostream &out, const set<T> &s) { if (s.emp) return out << "<>"; else { auto itr = s.bgn; out << "<" << *itr; itr++; while (itr != s.en) { out << ", " << *itr; itr++; } out << ">"; return out; } } void say() {} template <class T> void say(T t) { cout << t; } template <class Head, class... Body> void say(Head head, Body... body) { cout << head << " "; say(body...); } void sal() { cout << "\n"; } template <class... Args> void sal(Args... args) { say(args...); cout << "\n"; } void day() {} template <class T> void day(T t) { cerr << t; } template <class Head, class... Body> void day(Head head, Body... body) { cerr << head << " "; day(body...); } void dal() { cerr << "\n"; } template <class... Args> void dal(Args... args) { day(args...); cerr << "\n"; } void salv() {} template <class T> void salv(V<T> v) { if (v.emp) sal(); else { auto itr = v.bgn; say(*itr); itr++; while (itr != v.en) { sas; say(*itr); itr++; } sak; } } template <class T> void salv(V<V<T>> v) { if (v.emp) sal(); else { ROR(v, i) salv(i); } } template <class T, class... Args> void salv(T v, Args... args) { salv(v); salv(args...); } template <class L, class R> auto Gcd(L l, R r) -> decltype(l + r) { if (l < r) swap(l, r); return r ? Gcd(r, l % r) : l; } template <class L, class R> auto Lcm(L l, R r) { if (!l || !r) return 0; return l / Gcd(l, r) * r; } auto LES = mp(INF, lam(return l < r;)); auto GRT = mp(-INF, lam(return l > r;)); auto EQ = mp(0, lam(return l == r;)); auto ADD = mp(0, lam(return l + r;)); auto SUB = mp(0, lam(return l - r;)); auto MUL = mp(1, lam(return l * r;)); auto DIV = mp(1, lam(return l / r;)); auto MDL = mp(1, lam(return l % r;)); auto XOR = mp(0, lam(return l ^ r;)); auto OR = mp(0, lam(return l | r;)); auto AND = mp(((ll)(1) << 63) - 1, lam(return l & r;)); auto MIN = mp(INF, lam(return (l < r) ? l : r;)); auto MAX = mp(-INF, lam(return (l > r) ? l : r;)); auto GCD = mp(0, lam(return Gcd(l, r);)); auto LCM = mp(1, lam(return Lcm(l, r);)); /* auto ADD = mp(0, [](auto l, auto r) { return l + r; }); auto SUB = mp(1, [](auto l, auto r) { return l - r; }); auto MUL = mp(1, [](auto l, auto r) { return l * r; }); auto DIV = mp(0, [](auto l, auto r) { return l / r; }); auto MDL = mp(0, [](auto l, auto r) { return l % r; }); auto XOR = mp(0, [](auto l, auto r) { return l ^ r; }); auto OR = mp(0, [](auto l, auto r) { return l | r; }); auto AND = mp(((ll)(1) << 63) - 1, [](auto l, auto r) { return l & r; }); auto MIN = mp(INF, [](auto l, auto r) { return (l < r) ? l : r; }); auto MAX = mp(-INF, [](auto l, auto r) { return (l > r) ? l : r; }); auto GCD = mp(0, [](auto l, auto r) { return gcd(l, r); }); auto LCM = mp(1, [](auto l, auto r) { return lcm(l, r); }); */ template <class OperationType> auto Operation(OperationType A) { return A.fi; } template <class OperationType, class T> auto Operation(OperationType A, T x) { return x; } template <class OperationType, class T, class... Args> auto Operation(OperationType A, T x, Args... args) { auto tmp = Operation(A, args...); return A.se(x, tmp); } template <class OperationType> auto VOperation(OperationType A) { return A.fi; } template <class OperationType, class T> auto VOperation(OperationType A, T x) { return x; } template <class OperationType, class T> auto VOperation(OperationType A, V<T> x) { T tmp = A.fi; ROR(x, i) tmp = A.se(tmp, i); return tmp; } template <class OperationType, class T> auto VOperation(OperationType A, V<V<T>> x) { T tmp = A.fi; ROR(x, i) ROR(i, j) tmp = A.se(tmp, j); return tmp; } template <class OperationType, class T> auto VOperation(OperationType A, V<V<V<T>>> x) { T tmp = A.fi; ROR(x, i) ROR(i, j) ROR(j, k) tmp = A.se(tmp, k); return tmp; } template <class OperationType, class T> auto VOperation(OperationType A, V<V<V<V<T>>>> x) { T tmp = A.fi; ROR(x, i) ROR(i, j) ROR(j, k) ROR(k, l) tmp = A.se(tmp, l); return tmp; } template <class OperationType, class T, class... Args> auto VOperation(OperationType A, T x, Args... args) { auto xResult = VOperation(A, x); auto tmp = VOperation(A, args...); return A.se(xResult, tmp); } ll Bset(ll a, ll b, ll c) { if (c) a |= b; else a &= ~b; return a; } struct UFT { public: ll tsize; ll mode; vll par; vll rank; UFT() {} UFT(const UFT &uft) {} UFT(ll tsizeget, ll modeget = 0) { tsize = tsizeget; mode = modeget; par.asn(tsize, -1); if (!mode) rank.res(tsize, 0); } ll root(ll x) { return par[x] < 0 ? x : par[x] = root(par[x]); } bool isRoot(ll x) { return x == root(x); } bool same(ll x, ll y) { return root(x) == root(y); } void merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) return; if (mode) { par[x] += par[y]; par[y] = x; } else { if (rank[x] < rank[y]) { par[y] += par[x]; par[x] = y; } else { par[x] += par[y]; par[y] = x; if (rank[x] == rank[y]) rank[x]++; } } } ll size(ll x) { return -par[root(x)]; } }; struct pUFT { public: ll tsize; ll now; vll par; vll rank; vll mtime; vvll sizepi; vvll sizepv; pUFT() {} pUFT(const pUFT &puft) {} pUFT(ll tsizeget) { tsize = tsizeget; now = 0; par.asn(tsize, -1); rank.asn(tsize, 0); mtime.asn(tsize, INF); sizepi.asn(tsize, {0}); sizepv.asn(tsize, {1}); } ll root(ll x, ll t) { return (mtime[x] > t) ? x : root(par[x], t); } bool same(ll x, ll y, ll t) { return root(x, t) == root(y, t); } ll merge(ll x, ll y) { now++; x = root(x, now); y = root(y, now); if (x != y) { if (rank[x] < rank[y]) { par[y] += par[x]; sizepi[y].pb(now); sizepv[y].pb(-par[y]); par[x] = y; mtime[x] = now; } else { par[x] += par[y]; sizepi[x].pb(now); sizepv[x].pb(-par[x]); par[y] = x; mtime[y] = now; if (rank[x] == rank[y]) rank[x]++; } } return now; } ll size(ll x, ll t) { x = root(x, t); return sizepv[x][UPB(sizepi[x], t) - 1]; } }; struct wUFT { public: ll tsize; ll mode; vll par; vll rank; vll dweight; wUFT() {} wUFT(const wUFT &wuft) {} wUFT(ll tsizeget, ll modeget = 0) { tsize = tsizeget; mode = modeget; par.asn(tsize, -1); if (!mode) rank.res(tsize, 0); dweight.asn(tsize, 0); } ll root(ll x) { if (par[x] < 0) return x; else { ll r = root(par[x]); dweight[x] += dweight[par[x]]; return par[x] = r; } } ll weight(ll x) { root(x); return dweight[x]; } ll diff(ll x, ll y) { return weight(y) - weight(x); } bool isRoot(ll x) { return x == root(x); } bool same(ll x, ll y) { return root(x) == root(y); } void merge(ll x, ll y, ll w) { w += weight(x); w -= weight(y); x = root(x); y = root(y); if (x == y) return; if (mode) { par[x] += par[y]; par[y] = x; } else { if (rank[x] < rank[y]) { par[y] += par[x]; par[x] = y; dweight[x] = -w; } else { par[x] += par[y]; par[y] = x; if (rank[x] == rank[y]) rank[x]++; dweight[y] = w; } } } ll size(ll x) { return -par[root(x)]; } }; template <typename valtype> class SegT { public: ll size; vector<valtype> v; valtype initv; function<valtype(valtype x, valtype y)> calc; SegT() {} SegT(const SegT &segt) {} SegT(ll sizeget, ll modeget = 0) { sizeset(sizeget); modeset(modeget); init(); } SegT(vector<valtype> cpyvec, ll modeget = 0) { sizeset(cpyvec.sz); modeset(modeget); init(); copy(cpyvec); } SegT(ll sizeget, valtype initvget, function<valtype(valtype x, valtype y)> calcget) { sizeset(sizeget); initv = initvget; calc = calcget; init(); } SegT(vector<valtype> cpyvec, valtype initvget, function<valtype(valtype x, valtype y)> calcget) { sizeset(cpyvec.sz); initv = initvget; calc = calcget; init(); copy(cpyvec); } void sizeset(ll rsize) { size = DigN2(rsize); if (rsize == Pow2(size - 1)) size--; return; } void modeset(ll mode) { switch (mode) { case 0: initv = 0; calc = [](valtype x, valtype y) { return x + y; }; break; case 1: initv = INF; calc = [](valtype x, valtype y) { return min(x, y); }; break; case 2: initv = -INF; calc = [](valtype x, valtype y) { return max(x, y); }; break; } return; } void init() { v.asn(Pow2(size + 1) - 1, initv); } void copy(vector<valtype> cpyvec) { REP(i, min(cpyvec.sz, Pow2(size))) set(i, cpyvec[i]); } ll i2v(ll i) const { if (i < 0 || i >= Pow2(size)) return -1; return Pow2(size) + i - 1; } ll top(ll i) const { if (i == 0) return -1; return (i - 1) / 2; } pl bot(ll i) const { if (i + 1 >= Pow2(size)) return mp(-1, -1); return mp(2 * i + 1, 2 * i + 2); } void set(ll i, valtype x) { i = i2v(i); v[i] = x; while (i > 0) { i = top(i); v[i] = calc(v[bot(i).fi], v[bot(i).se]); } return; } void add(ll i, valtype x) { set(i, v[i2v(i)] + x); return; } valtype operator[](const ll &i) const { return v[i2v(i)]; } // valtype que(ll a = 0, ll b = Pow2(size) - 1) { valtype que(ll a, ll b) { if (a == b) return v[i2v(a)]; if (a > b) return initv; // swap(a, b); valtype ans = initv; ll ai = i2v(a); ll bi = i2v(b); FOR(i, 1, size + 1) { if (a > b) break; if (a % Pow2(i)) { ans = calc(ans, v[ai]); a += Pow2(i - 1); ai = top(ai) + 1; } else { ai = top(ai); } if (a > b) break; if ((b + 1) % Pow2(i)) { ans = calc(ans, v[bi]); b -= Pow2(i - 1); bi = top(bi) - 1; } else { bi = top(bi); } if (a > b) break; } return ans; } valtype que(ll b) { return que(0, b); } valtype que() { return que(0, Pow2(size) - 1); } }; /*template <class Type> class DP { public: vector<Type> v; Type initv; vll size, block; DP() {} DP(const DP &dp) {} template<class... Args> DP(Args... args) { block.asn(1, 1); Initialize(args...); } void Initialize(Type initv_) { initv = initv_; v.asn(block.bk, initv); } template<class... Args> void Initialize(ll val, Args... args) { size.pb(val); block.pb(block.bk*val); Initialize(args...); } };*/ pl Bezout(ll a, ll b) { if (b != 0) { pl xy; xy = Bezout(b, a % b); return mp(xy.se, xy.fi - ((a / b) * xy.se)); } else { return mp(1, 0); } } pl Bez(ll a, ll b, ll c) { pl xy; ll x, y, z, gc; xy = Bezout(a, b); gc = gcd(a, b); if (c % gc != 0) return mp(-1, -1); x = xy.fi * (c / gc); y = xy.se * (c / gc); if (x < 0) z = rup(-x, (b / gc)); if (x >= 0) z = -x / (b / gc); x += z * (b / gc); y -= z * (a / gc); return mp(x, y); } ll DigS10(ll n) { ll ans = 0; while (1) { ans += n % 10; n /= 10; if (!n) break; } return ans; } ll isP(ll n) { if (n <= 1) return 0; FOR(i, 2, (ll)sqrt(n) + 1) { if (n % i == 0) return 0; } return 1; } ll Tot(ll n) { if (n <= 0) return 0; ll ans = n, x = 2; while (x * x <= n) { if (n % x == 0) { ans -= ans / x; while (n % x == 0) n /= x; } x++; } if (n > 1) ans -= ans / n; return ans; } template <class T> struct Graph { public: ll vSize; ll eMode; ll mapMode; ActPair(T) Add; BoolPair(T) Lesser; BoolPair(T) Equal; V<V<P<T, ll>>> adj; map<pl, T> len; Graph(ll vSize, ll eMode = 0, ll mapMode = 0, ActPair(T) Add = ADD, BoolPair(T) Lesser = LES, BoolPair(T) Equal = EQ) : vSize(vSize), eMode(eMode), mapMode(mapMode), Add(Add), Lesser(Lesser), Equal(Equal) { Init(); } void Init() { adj.asn(vSize, V<P<T, ll>>()); } void AddE(ll x, ll y, T cost) { iAddE(x, y, cost); if (!eMode) iAddE(y, x, cost); } void iAddE(ll x, ll y, T cost) { adj[x].pb(mp(cost, y)); if (mapMode) len[mp(x, y)] = cost; } P<bool, T> getE(ll x, ll y) { if (!len.count(mp(x, y))) return mp(false, Lesser.fi); return mp(true, len[mp(x, y)]); } V<T> Dijk(ll x) { V<T> ans(vSize, Lesser.fi); if (x < 0 || x >= vSize) return ans; SegT<P<T, ll>> segt(vSize, mp(Lesser.fi, -1), clam(if (l.se < 0) return r; if (r.se < 0) return l; return Lesser.se(l.fi, r.fi) ? l : r;)); segt.set(x, mp(Add.fi, x)); P<T, ll> now; while ((now = segt.que(0, vSize - 1)).se >= 0) { ans[now.se] = segt[now.se].fi; segt.set(now.se, mp(Lesser.fi, -2)); ROR(adj[now.se], i) { if (segt[i.se].se == -2) continue; if (segt[i.se].se == -1) { segt.set(i.se, mp(Add.se(ans[now.se], i.fi), i.se)); continue; } if (Lesser.se(Add.se(ans[now.se], i.fi), segt[i.se].fi)) { segt.set(i.se, mp(Add.se(ans[now.se], i.fi), i.se)); continue; } } } return ans; } V<P<T, vll>> rDijk(ll x) { V<P<T, vll>> ans(vSize, mp(Lesser.fi, vll())); if (x < 0 || x >= vSize) return ans; SegT<P<T, ll>> segt(vSize, mp(Lesser.fi, -1), clam(if (l.se < 0) return r; if (r.se < 0) return l; return Lesser.se(l.fi, r.fi) ? l : r;)); segt.set(x, mp(Add.fi, x)); P<T, ll> now; while ((now = segt.que(0, vSize - 1)).se >= 0) { ans[now.se].fi = segt[now.se].fi; segt.set(now.se, mp(Lesser.fi, -2)); ROR(adj[now.se], i) { if (segt[i.se].se == -2) continue; if (segt[i.se].se == -1) { segt.set(i.se, mp(Add.se(ans[now.se].fi, i.fi), i.se)); ans[i.se].se = {now.se}; continue; } if (Lesser.se(Add.se(ans[now.se].fi, i.fi), segt[i.se].fi)) { segt.set(i.se, mp(Add.se(ans[now.se].fi, i.fi), i.se)); ans[i.se].se = {now.se}; continue; } if (Equal.se(Add.se(ans[now.se].fi, i.fi), segt[i.se].fi)) { ans[i.se].se.pb(now.se); continue; } } } return ans; } T Prim(ll x = 0) { T ans = Add.fi; if (x < 0 || x >= vSize) return ans; SegT<P<T, ll>> segt(vSize, mp(Lesser.fi, -1), clam(if (l.se < 0) return r; if (r.se < 0) return l; return Lesser.se(l.fi, r.fi) ? l : r;)); segt.set(x, mp(Add.fi, x)); P<T, ll> now; while ((now = segt.que(0, vSize - 1)).se >= 0) { ans = Add.se(ans, segt[now.se].fi); segt.set(now.se, mp(Lesser.fi, -2)); ROR(adj[now.se], i) { if (segt[i.se].se == -2) continue; if (segt[i.se].se == -1) { segt.set(i.se, i); continue; } if (Lesser.se(i.fi, segt[i.se].fi)) { segt.set(i.se, i); continue; } } } return ans; } P<T, V<P<T, vll>>> rPrim(ll x = 0) { P<T, V<P<T, vll>>> ans = mp(Add.fi, V<P<T, vll>>(vSize, mp(Lesser.fi, vll()))); if (x < 0 || x >= vSize) return ans; SegT<P<T, ll>> segt(vSize, mp(Lesser.fi, -1), clam(if (l.se < 0) return r; if (r.se < 0) return l; return Lesser.se(l.fi, r.fi) ? l : r;)); segt.set(x, mp(Add.fi, x)); P<T, ll> now; while ((now = segt.que(0, vSize - 1)).se >= 0) { ans.se[now.se].fi = segt[now.se].fi; ans.fi = Add.se(ans.fi, ans.se[now.se].fi); segt.set(now.se, mp(Lesser.fi, -2)); ROR(adj[now.se], i) { if (segt[i.se].se == -2) continue; if (segt[i.se].se == -1) { segt.set(i.se, i); ans.se[i.se].se = {now.se}; continue; } if (Lesser.se(i.fi, segt[i.se].fi)) { segt.set(i.se, i); ans.se[i.se].se = {now.se}; continue; } if (Equal.se(i.fi, segt[i.se].fi)) { ans.se[i.se].se.pb(now.se); continue; } } } return ans; } }; template <class T> struct Sum { public: V<T> v, s; ll size; ActPair(T) Add; ActPair(T) Sub; Sum(V<T> v, ActPair(T) Add = ADD, ActPair(T) Sub = SUB) : v(v), size(v.sz), Add(Add), Sub(Sub) { Init(); Calc(); } void Init() { s.asn(size + 1, Add.fi); } void Calc() { REP(i, size) s[i + 1] = Add.se(s[i], v[i]); } T operator()(ll x) { if (x < -1) x = -1; if (x > size - 1) x = size - 1; return s[x + 1]; } T operator()(ll l, ll r) { if (l < 0) l = 0; if (r >= size) r = size - 1; if (l > r) return Add.fi; return Sub.se(s[r + 1], s[l]); } }; using sumll = Sum<ll>; template <class T> struct Sum2 { public: V<V<T>> v, s; ll RowSize, ColumnSize; ActPair(T) Add; ActPair(T) Sub; Sum2(V<V<T>> v, ActPair(T) Add = ADD, ActPair(T) Sub = SUB) : v(v), RowSize(v.sz), ColumnSize(v.sz ? v[0].sz : 0), Add(Add), Sub(Sub) { Init(); Calc(); } void Init() { s.asn(RowSize + 1, V<T>(ColumnSize + 1, Add.fi)); } void Calc() { REP1(r, RowSize) { REP1(c, ColumnSize) { // s[r][c] = Sub.se(Add.se(Add.se(v[r - 1][c - //1], operator()(r - 1, c - 2)), operator()(r - 2, c - 1)), operator()(r //- 2, c - 2)); s[r][c] = Add.se(s[r][c - 1], v[r - 1][c - 1]); } } REP1(r, RowSize) { REP1(c, ColumnSize) { s[r][c] = Add.se(s[r - 1][c], s[r][c]); } } } T operator()(ll r, ll c) { if (r < -1) r = -1; if (c < -1) c = -1; if (r > RowSize - 1) r = RowSize - 1; if (c > ColumnSize - 1) c = ColumnSize - 1; return s[r + 1][c + 1]; } T operator()(ll r1, ll c1, ll r2, ll c2) { if (r1 < 0) r1 = 0; if (c1 < 0) c1 = 0; if (r2 >= RowSize) r2 = RowSize - 1; if (c2 >= ColumnSize) c2 = ColumnSize - 1; if (r1 > r2) return Add.fi; if (c1 > c2) return Add.fi; return Sub.se(Add.se(s[r2 + 1][c2 + 1], s[r1][c1]), Add.se(s[r2 + 1][c1], s[r1][c2 + 1])); } }; using sumll2 = Sum2<ll>; template <class T> struct Point2 { public: V<V<T>> v; ll h, w; Point2() : h(0), w(0) {} Point2(ll h, ll w) : h(h), w(w) { asn(h, w); } Point2(ll h, ll w, T val) : h(h), w(w) { asn(h, w, val); } void assign(ll h, ll w) { v.asn(h, V<T>(w)); } void assign(ll h, ll w, ll val) { v.asn(h, V<T>(w, val)); } T &operator()(ll h, ll w) { return v[h][w]; } T &operator()(pl p) { return v[p.fi][p.se]; } }; template <class T> using P2 = Point2<T>; template <ll Mod> struct Modll { public: ll v; Modll() : v(0) {} Modll(ll _v) { set(_v % Mod + Mod); } Modll &set(ll _v) { v = (_v < Mod) ? _v : (_v - Mod); return *this; } Modll pow(ll n) const { Modll x = *this, ans = 1; while (n) { if (n & 1) ans *= x; x *= x; n >>= 1; } return ans; } Modll inverse() const { return (*this).pow(Mod - 2); } Modll operator+(const Modll &m) const { return Modll().set(v + m.v); } Modll operator-(const Modll &m) const { return Modll().set(Mod + v - m.v); } Modll operator*(const Modll &m) const { return Modll().set((ull(v) * m.v) % Mod); } Modll operator/(const Modll &m) const { return *this * m.inv; } Modll &operator+=(const Modll &m) { return *this = *this + m; } Modll &operator-=(const Modll &m) { return *this = *this - m; } Modll &operator*=(const Modll &m) { return *this = *this * m; } Modll &operator/=(const Modll &m) { return *this = *this / m; } Modll operator-() const { return Modll(0) - *this; } explicit operator bool() const { return v != 0; } friend istream &operator>>(istream &in, Modll &m) { return in >> m.v; } friend ostream &operator<<(ostream &out, const Modll &m) { return out << m.v; } }; using mll = Modll<MOD>; using vmll = V<mll>; using vvmll = V<vmll>; using vvvmll = V<vvmll>; vmll MFactMemo(2, 1); vmll MIFactMemo(2, 1); mll mFact(ll n) { if (MFactMemo.sz <= n) { ll oldsize = MFactMemo.sz; MFactMemo.res(n + 1, 1); FOR(i, oldsize, n) MFactMemo[i] = MFactMemo[i - 1] * i; } return MFactMemo[n]; } mll miFact(ll n) { if (MIFactMemo.sz <= n) { ll oldsize = MIFactMemo.sz; MIFactMemo.res(n + 1, 1); MIFactMemo.bk = mFact(n).inv; rFOR(i, oldsize + 1, n) MIFactMemo[i - 1] = MIFactMemo[i] * i; } return MIFactMemo[n]; } mll mComb(ll n, ll k) { if (n < 0 || k < 0 || n < k) return 0; return mFact(n) * miFact(k) * miFact(n - k); } ll LIS(vll v, ll m = 0) { if (v.sz > 0) { ll ans = 0; vll dp(v.sz, INF); FOR(i, 0, v.sz - 1) { dp[m ? UPB(dp, v[i]) : LOWB(dp, v[i])] = v[i]; } FOR(i, 0, v.sz - 1) { if (dp[i] == INF) break; ans++; } return ans; } else { return 0; } } ll Bsrch(function<bool(ll x)> f, ll mi, ll ma) { ll ng = mi - 1, ok = ma, mid; while (ok - ng > 1) { mid = (ng + ok) / 2; (f(mid) ? ok : ng) = mid; } return ok; } template <class T> V<V<T>> MultiMatrix(V<V<T>> A, V<V<T>> B, ActPair(T) Mul = MUL, ActPair(T) Add = ADD) { V<V<T>> ans; ll ii = A.sz; if (!ii) return ans; ll jj = A[0].sz; if (!jj) return ans; ll jj2 = B.sz; if (!jj2) return ans; if (jj != jj2) return ans; ll kk = B[0].sz; if (!kk) return ans; ans.asn(ii, V<T>(kk, 0)); REP(i, ii) { REP(k, kk) { REP(j, jj) { ans[i][k] = Add.se(ans[i][k], Mul.se(A[i][j], B[j][k])); } } } return ans; } vvll CombMemo(1000, vll(1000, -1)); ll Comb(ll n, ll k) { if ((n < 0) || (k < 0)) return 0; if (CombMemo[n][k] == -1) { if (n < k) CombMemo[n][k] = 0; else { if (n == 0) CombMemo[n][k] = 1; else if (k == 0) CombMemo[n][k] = 1; else if (n == k) CombMemo[n][k] = 1; else CombMemo[n][k] = Comb(n - 1, k - 1) + Comb(n - 1, k); } } return CombMemo[n][k]; } template <class T> map<T, ll> Dict(V<T> v) { map<T, ll> m; if (!v.sz) return m; SORT(v); UNIQUE(v); REP(i, v.sz) { m[v[i]] = i; } return m; } template <class T> vll Cmprs(V<T> v) { auto m = Dict(v); vll ans(v.sz); REP(i, v.sz) { ans[i] = m[v[i]]; } return ans; } template <class T> vll PCmprs(V<T> v) { if (v.sz == 0) return V<T>(); vll tmp(v.sz); vll ans(v.sz); IOTA(tmp, 0); IOTA(ans, 0); sort(tmp.bgn, tmp.en, clam(return v[l] < v[r];)); sort(ans.bgn, ans.en, clam(return tmp[l] < tmp[r];)); return ans; } ll BblCnt(vll rv) { vll v = PCmprs(rv); SegT<ll> b(v.sz, 0); ll ans = 0; REP(i, v.sz) { ans += (i - b.que(0, v[i])); b.add(v[i], 1); } return ans; } template <class T> auto ven(T val) { return val; } template <> auto ven<int>(int val) { return (ll)val; } template <class T, class... Args> auto ven(T val, Args... args) { auto tmp = ven(args...); return V<decltype(tmp)>(val, tmp); } template <class T> void zind(T &v) { v--; } template <class T> void zind(V<T> &v) { ROR(v, i) zind(i); } template <class T, class... Args> void zind(T &v, Args &...args) { zind(v); zind(args...); } void Solve(); signed main() { cin.tie(0); ios::sync_with_stdio(false); cout << setprecision(20) << fixed; Solve(); } void Solve() { li(n); vlc(n, a, b); vpl c(n); REP(i, n) c[i] = mp(a[i] + b[i], i); SORT(c); ll t = 0, u = 0, uu = 0; REP(i, n) { if (i % 2 == 0) u += a[c[t].se]; if (i % 2 == 1) uu += b[c[t].se]; } /* while (t < n) { u += a[c[t].se]; t++; if (t == n) break; u -= b[c[t].se]; t++; }*/ sal(u - uu); }
#include <bits/stdc++.h> using namespace std; template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; template <class T> using VVV = V<VV<T>>; template <class S, class T> using P = pair<S, T>; template <class S, class T, class U> using TP = tuple<S, T, U>; using ll = long long; using ull = unsigned long long; using dbl = double; using str = string; using vll = V<ll>; using vvll = V<vll>; using vvvll = V<vvll>; using pl = P<ll, ll>; using tl = TP<ll, ll, ll>; using vpl = V<pl>; using vvpl = V<vpl>; using vtl = V<tl>; using vvtl = V<vtl>; using vs = V<str>; using vvs = V<vs>; using vd = V<dbl>; using vvd = V<vd>; using qll = queue<ll>; using qpl = queue<pl>; using stll = stack<ll>; using stpl = stack<pl>; using mapll = map<ll, ll>; using setll = set<ll>; using pqll = priority_queue<ll>; //#define int ll #define fi first #define se second #define mp make_pair #define mt make_tuple #define pb push_back #define pob pop_back() #define pf push_front #define pof pop_front() #define sz size() #define bgn begin() #define en end() #define asn assign #define emp empty() #define fr front() #define bk back() #define clr clear() #define ins insert #define ers erase #define res resize #define tp top() #define p_q priority_queue #define inv inverse() #define FOR(i, a, b) for (ll i = (a); i <= (ll)(b); i++) #define rFOR(i, a, b) for (ll i = (b); i >= (ll)(a); i--) #define REP(i, a) FOR((i), 0, (ll)(a)-1) #define REP0(i, a) FOR((i), 0, (ll)(a)) #define REP1(i, a) FOR((i), 1, (ll)(a)) #define rREP(i, a) rFOR((i), 0, (ll)(a)-1) #define rREP0(i, a) rFOR((i), 0, (ll)(a)) #define rREP1(i, a) rFOR((i), 1, (ll)(a)) #define ROR(v, i) for (auto &(i) : (v)) #define IOTA(a, n) iota((a).bgn, (a).en, (n)) #define SORT(a) sort((a).bgn, (a).en) #define rSORT(a) sort((a).rbegin(), (a).rend()) #define UNIQUE(a) (a).erase(unique((a).bgn, (a).en), (a).en) #define PREVP(a) prev_permutation((a).bgn, (a).en) #define NEXTP(a) next_permutation((a).bgn, (a).en) #define BINS(a, b) binary_search((a).bgn, (a).en, (b)) #define LOWB(a, b) (lower_bound((a).bgn, (a).en, (b)) - (a).bgn) #define UPB(a, b) (upper_bound((a).bgn, (a).en, (b)) - (a).bgn) #define CNT(a, b) count((a).bgn, (a).en, b) #define SUM(a) accumulate((a).bgn, (a).en, 0) #define REV(a) reverse((a).bgn, (a).en) #define REGS(a, b) regex_search((a), regex(b)) #define REGM(a, b) regex_match((a), regex(b)) #define yn(a) cout << ((a) ? "yes" : "no") << "\n"; #define Yn(a) cout << ((a) ? "Yes" : "No") << "\n"; #define YN(a) cout << ((a) ? "YES" : "NO") << "\n"; #define imp(a) cout << ((a) ? "possible" : "impossible") << "\n"; #define Imp(a) cout << ((a) ? "Possible" : "Impossible") << "\n"; #define IMP(a) cout << ((a) ? "POSSIBLE" : "IMPOSSIBLE") << "\n"; #define fs(a) cout << ((a) ? "second" : "first") << "\n"; #define Fs(a) cout << ((a) ? "Second" : "First") << "\n"; #define FS(a) cout << ((a) ? "SECOND" : "FIRST") << "\n"; //#define say(a) cout <<(a); //#define sal(a) cout <<(a)<<"\n"; #define sak cout << "\n"; #define sas cout << " "; #define sat cout << "\t"; #define dbg(a) cerr << (#a) << ": " << (a) << "\n"; #define dbgs(...) \ dal(#__VA_ARGS__); \ dal(__VA_ARGS__); #define c2l(a) ((ll)(a - 48)) #define a2l(a) ((ll)(a - 97)) #define A2l(a) ((ll)(a - 65)) #define l2c(a) ((char)(a + 48)) #define l2a(a) ((char)(a + 97)) #define l2A(a) ((char)(a + 65)) #define DigN2(a) ((llabs(a) == 0) ? (1) : ((ll)(log2(double(llabs(a)))) + 1)) #define DigN10(a) ((llabs(a) == 0) ? (1) : ((ll)(log10(double(llabs(a)))) + 1)) #define Dig2(a, b) (((a) >> (b)) & 1) #define Dig10(a, b) (ll)(((a) / ((ll)(pow(10.0, (double)(b))))) % 10) #define Pow2(a) ((ll)(1) << (a)) #define Pow10(a) ((ll)(pow(10.0, double(a)))) #define LSB(a) ((a) & (-(a))) /*#define llin(a) ll (a);cin >>(a); #define llin2(a,b) ll (a),(b);cin >>(a)>>(b); #define llin3(a,b,c) ll (a),(b),(c);cin >>(a)>>(b)>>(c); #define stin(a) string (a);cin >>(a);*/ #define vin(v) \ ROR((v), (i)) { cin >> (i); }; #define vllin(v, N) \ vll(v)((N)); \ vin(v); #define vllin2(a, b, N) \ vll(a)(N), (b)(N); \ REP(i, N) { cin >> (a)[i] >> (b)[i]; }; #define vsin(v, N) \ vs(v)((N)); \ vin(v); #define rdn(a, b) ((a) / (b)) #define rou(a, b) \ ((((double(a) / double(b)) - ((a) / (b))) < 0.5) ? ((a) / (b)) \ : (((a) / (b)) + 1)) #define rup(a, b) ((((a) % (b)) == 0) ? ((a) / (b)) : (((a) / (b)) + 1)) #define powll(a, b) (ll)(pow((double)(a), (double)(b))) #define Triangle(x1, y1, x2, y2, x3, y3) \ (((x1) - (x2)) * ((y1) - (y3)) - ((x1) - (x3)) * ((y1) - (y2))) #define lam(lr) ([](auto l, auto r) { lr }) #define elam(lr) ([=](auto l, auto r) { lr }) #define clam(lr) ([&](auto l, auto r) { lr }) #define min(...) Operation(MIN, __VA_ARGS__) #define max(...) Operation(MAX, __VA_ARGS__) #define gcd(...) Operation(GCD, __VA_ARGS__) #define lcm(...) Operation(LCM, __VA_ARGS__) #define vmin(...) VOperation(MIN, __VA_ARGS__) #define vmax(...) VOperation(MAX, __VA_ARGS__) #define vgcd(...) VOperation(GCD, __VA_ARGS__) #define vlcm(...) VOperation(LCM, __VA_ARGS__) #define vsum(...) VOperation(ADD, __VA_ARGS__) #define vpro(...) VOperation(MUL, __VA_ARGS__) #define emin(a, ...) ((a) = min((a), __VA_ARGS__)) #define emax(a, ...) ((a) = max((a), __VA_ARGS__)) #define egcd(a, ...) ((a) = gcd((a), __VA_ARGS__)) #define elcm(a, ...) ((a) = lcm((a), __VA_ARGS__)) #define ActPair(T) P<T, function<T(T, T)>> #define BoolPair(T) P<T, function<bool(T, T)>> #define ope Operation #define vope VOperation #define svll SumV<ll> #define svvll SumV2<ll> #define li(...) \ ll __VA_ARGS__; \ Input(__VA_ARGS__); #define si(...) \ str __VA_ARGS__; \ Input(__VA_ARGS__); //#define vli(size, ...) vll __VA_ARGS__;vInitInput(size,__VA_ARGS__); #define vlr(size, ...) \ vll __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vlc(size, ...) \ vll __VA_ARGS__; \ vInitInputC(size, __VA_ARGS__); #define vli(size, ...) \ vll __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vsr(size, ...) \ vs __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vsc(size, ...) \ vs __VA_ARGS__; \ vInitInputC(size, __VA_ARGS__); #define vsi(size, ...) \ vs __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vli2(rowSize, columnSize, ...) \ vvll __VA_ARGS__; \ vInitInput2(rowSize, columnSize, __VA_ARGS__); #define vplr(size, ...) \ vpl __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vplc(size, ...) \ vpl __VA_ARGS__; \ vInitInputC(size, __VA_ARGS__); #define vpli(size, ...) \ vpl __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); const ll MOD = 1e9 + 7; // const ll MOD = 998244353; // const ll MOD = 924844033; // const ll MOD = 9007199254740881; const ll INF = 1LL << 60; // 1.15e18 const double PI = acos(-1.0); const vll DX = {0, -1, 0, 1, 0, -1, 1, 1, -1}; const vll DY = {0, 0, -1, 0, 1, -1, -1, 1, 1}; const str alp = "abcdefghijklmnopqrstuvwxyz"; const str ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; template <class S, class T> istream &operator>>(istream &in, P<S, T> &p) { return in >> p.fi >> p.se; } template <class T> istream &operator>>(istream &in, V<T> &v) { REP(i, v.sz) in >> v[i]; return in; } void Input() {} template <class Var, class... Args> void Input(Var &var, Args &...args) { cin >> var; Input(args...); } void vInit(ll size) {} template <class T, class... Args> void vInit(ll size, V<T> &v, Args &...args) { v.res(size); vInit(size, args...); } void vInput(ll size) {} template <class T, class... Args> void vInput(ll size, V<T> &v, Args &...args) { REP(i, size) cin >> v[i]; vInput(size, args...); } void vInputR(ll size) {} template <class T, class... Args> void vInputR(ll size, V<T> &v, Args &...args) { REP(i, size) cin >> v[i]; vInputR(size, args...); } void vInputNumC(ll num) {} template <class T, class... Args> void vInputNumC(ll num, V<T> &v, Args &...args) { cin >> v[num]; vInputNumC(num, args...); } void vInputC(ll size) {} template <class... Args> void vInputC(ll size, Args &...args) { REP(i, size) vInputNumC(i, args...); } void vInitInputR(ll size) {} template <class... Args> void vInitInputR(ll size, Args &...args) { vInit(size, args...); vInputR(size, args...); } void vInitInputC(ll size) {} template <class... Args> void vInitInputC(ll size, Args &...args) { vInit(size, args...); vInputC(size, args...); } void vInit2(ll rowSize, ll columnSize) {} template <class T, class... Args> void vInit2(ll rowSize, ll columnSize, V<V<T>> &v, Args &...args) { v.asn(rowSize, V<T>(columnSize)); vInit2(rowSize, columnSize, args...); } void vInput2(ll rowSize, ll columnSize) {} template <class T, class... Args> void vInput2(ll rowSize, ll columnSize, V<V<T>> &v, Args &...args) { REP(r, rowSize) { REP(c, columnSize) { cin >> v[r][c]; } } vInput2(rowSize, columnSize, args...); } void vInitInput2(ll rowSize, ll columnSize) {} template <class... Args> void vInitInput2(ll rowSize, ll columnSize, Args &...args) { vInit2(rowSize, columnSize, args...); vInput2(rowSize, columnSize, args...); } template <class S, class T> ostream &operator<<(ostream &out, const P<S, T> &p) { return out << "[" << p.fi << ", " << p.se << "]"; } template <class T> ostream &operator<<(ostream &out, V<T> &v) { if (v.emp) return out << "{}"; else { auto itr = v.bgn; out << "{" << *itr; itr++; while (itr != v.en) { out << ", " << *itr; itr++; } out << "}"; return out; } } template <class S, class T> ostream &operator<<(ostream &out, const map<S, T> &m) { if (m.emp) return out << "<[]>"; else { auto itr = m.bgn; out << "< [" << (itr->fi) << ": " << (itr->se); itr++; while (itr != m.en) { out << "], [" << (itr->fi) << ": " << (itr->se); itr++; } out << "] >"; return out; } } template <class T> ostream &operator<<(ostream &out, const set<T> &s) { if (s.emp) return out << "<>"; else { auto itr = s.bgn; out << "<" << *itr; itr++; while (itr != s.en) { out << ", " << *itr; itr++; } out << ">"; return out; } } void say() {} template <class T> void say(T t) { cout << t; } template <class Head, class... Body> void say(Head head, Body... body) { cout << head << " "; say(body...); } void sal() { cout << "\n"; } template <class... Args> void sal(Args... args) { say(args...); cout << "\n"; } void day() {} template <class T> void day(T t) { cerr << t; } template <class Head, class... Body> void day(Head head, Body... body) { cerr << head << " "; day(body...); } void dal() { cerr << "\n"; } template <class... Args> void dal(Args... args) { day(args...); cerr << "\n"; } void salv() {} template <class T> void salv(V<T> v) { if (v.emp) sal(); else { auto itr = v.bgn; say(*itr); itr++; while (itr != v.en) { sas; say(*itr); itr++; } sak; } } template <class T> void salv(V<V<T>> v) { if (v.emp) sal(); else { ROR(v, i) salv(i); } } template <class T, class... Args> void salv(T v, Args... args) { salv(v); salv(args...); } template <class L, class R> auto Gcd(L l, R r) -> decltype(l + r) { if (l < r) swap(l, r); return r ? Gcd(r, l % r) : l; } template <class L, class R> auto Lcm(L l, R r) { if (!l || !r) return 0; return l / Gcd(l, r) * r; } auto LES = mp(INF, lam(return l < r;)); auto GRT = mp(-INF, lam(return l > r;)); auto EQ = mp(0, lam(return l == r;)); auto ADD = mp(0, lam(return l + r;)); auto SUB = mp(0, lam(return l - r;)); auto MUL = mp(1, lam(return l * r;)); auto DIV = mp(1, lam(return l / r;)); auto MDL = mp(1, lam(return l % r;)); auto XOR = mp(0, lam(return l ^ r;)); auto OR = mp(0, lam(return l | r;)); auto AND = mp(((ll)(1) << 63) - 1, lam(return l & r;)); auto MIN = mp(INF, lam(return (l < r) ? l : r;)); auto MAX = mp(-INF, lam(return (l > r) ? l : r;)); auto GCD = mp(0, lam(return Gcd(l, r);)); auto LCM = mp(1, lam(return Lcm(l, r);)); /* auto ADD = mp(0, [](auto l, auto r) { return l + r; }); auto SUB = mp(1, [](auto l, auto r) { return l - r; }); auto MUL = mp(1, [](auto l, auto r) { return l * r; }); auto DIV = mp(0, [](auto l, auto r) { return l / r; }); auto MDL = mp(0, [](auto l, auto r) { return l % r; }); auto XOR = mp(0, [](auto l, auto r) { return l ^ r; }); auto OR = mp(0, [](auto l, auto r) { return l | r; }); auto AND = mp(((ll)(1) << 63) - 1, [](auto l, auto r) { return l & r; }); auto MIN = mp(INF, [](auto l, auto r) { return (l < r) ? l : r; }); auto MAX = mp(-INF, [](auto l, auto r) { return (l > r) ? l : r; }); auto GCD = mp(0, [](auto l, auto r) { return gcd(l, r); }); auto LCM = mp(1, [](auto l, auto r) { return lcm(l, r); }); */ template <class OperationType> auto Operation(OperationType A) { return A.fi; } template <class OperationType, class T> auto Operation(OperationType A, T x) { return x; } template <class OperationType, class T, class... Args> auto Operation(OperationType A, T x, Args... args) { auto tmp = Operation(A, args...); return A.se(x, tmp); } template <class OperationType> auto VOperation(OperationType A) { return A.fi; } template <class OperationType, class T> auto VOperation(OperationType A, T x) { return x; } template <class OperationType, class T> auto VOperation(OperationType A, V<T> x) { T tmp = A.fi; ROR(x, i) tmp = A.se(tmp, i); return tmp; } template <class OperationType, class T> auto VOperation(OperationType A, V<V<T>> x) { T tmp = A.fi; ROR(x, i) ROR(i, j) tmp = A.se(tmp, j); return tmp; } template <class OperationType, class T> auto VOperation(OperationType A, V<V<V<T>>> x) { T tmp = A.fi; ROR(x, i) ROR(i, j) ROR(j, k) tmp = A.se(tmp, k); return tmp; } template <class OperationType, class T> auto VOperation(OperationType A, V<V<V<V<T>>>> x) { T tmp = A.fi; ROR(x, i) ROR(i, j) ROR(j, k) ROR(k, l) tmp = A.se(tmp, l); return tmp; } template <class OperationType, class T, class... Args> auto VOperation(OperationType A, T x, Args... args) { auto xResult = VOperation(A, x); auto tmp = VOperation(A, args...); return A.se(xResult, tmp); } ll Bset(ll a, ll b, ll c) { if (c) a |= b; else a &= ~b; return a; } struct UFT { public: ll tsize; ll mode; vll par; vll rank; UFT() {} UFT(const UFT &uft) {} UFT(ll tsizeget, ll modeget = 0) { tsize = tsizeget; mode = modeget; par.asn(tsize, -1); if (!mode) rank.res(tsize, 0); } ll root(ll x) { return par[x] < 0 ? x : par[x] = root(par[x]); } bool isRoot(ll x) { return x == root(x); } bool same(ll x, ll y) { return root(x) == root(y); } void merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) return; if (mode) { par[x] += par[y]; par[y] = x; } else { if (rank[x] < rank[y]) { par[y] += par[x]; par[x] = y; } else { par[x] += par[y]; par[y] = x; if (rank[x] == rank[y]) rank[x]++; } } } ll size(ll x) { return -par[root(x)]; } }; struct pUFT { public: ll tsize; ll now; vll par; vll rank; vll mtime; vvll sizepi; vvll sizepv; pUFT() {} pUFT(const pUFT &puft) {} pUFT(ll tsizeget) { tsize = tsizeget; now = 0; par.asn(tsize, -1); rank.asn(tsize, 0); mtime.asn(tsize, INF); sizepi.asn(tsize, {0}); sizepv.asn(tsize, {1}); } ll root(ll x, ll t) { return (mtime[x] > t) ? x : root(par[x], t); } bool same(ll x, ll y, ll t) { return root(x, t) == root(y, t); } ll merge(ll x, ll y) { now++; x = root(x, now); y = root(y, now); if (x != y) { if (rank[x] < rank[y]) { par[y] += par[x]; sizepi[y].pb(now); sizepv[y].pb(-par[y]); par[x] = y; mtime[x] = now; } else { par[x] += par[y]; sizepi[x].pb(now); sizepv[x].pb(-par[x]); par[y] = x; mtime[y] = now; if (rank[x] == rank[y]) rank[x]++; } } return now; } ll size(ll x, ll t) { x = root(x, t); return sizepv[x][UPB(sizepi[x], t) - 1]; } }; struct wUFT { public: ll tsize; ll mode; vll par; vll rank; vll dweight; wUFT() {} wUFT(const wUFT &wuft) {} wUFT(ll tsizeget, ll modeget = 0) { tsize = tsizeget; mode = modeget; par.asn(tsize, -1); if (!mode) rank.res(tsize, 0); dweight.asn(tsize, 0); } ll root(ll x) { if (par[x] < 0) return x; else { ll r = root(par[x]); dweight[x] += dweight[par[x]]; return par[x] = r; } } ll weight(ll x) { root(x); return dweight[x]; } ll diff(ll x, ll y) { return weight(y) - weight(x); } bool isRoot(ll x) { return x == root(x); } bool same(ll x, ll y) { return root(x) == root(y); } void merge(ll x, ll y, ll w) { w += weight(x); w -= weight(y); x = root(x); y = root(y); if (x == y) return; if (mode) { par[x] += par[y]; par[y] = x; } else { if (rank[x] < rank[y]) { par[y] += par[x]; par[x] = y; dweight[x] = -w; } else { par[x] += par[y]; par[y] = x; if (rank[x] == rank[y]) rank[x]++; dweight[y] = w; } } } ll size(ll x) { return -par[root(x)]; } }; template <typename valtype> class SegT { public: ll size; vector<valtype> v; valtype initv; function<valtype(valtype x, valtype y)> calc; SegT() {} SegT(const SegT &segt) {} SegT(ll sizeget, ll modeget = 0) { sizeset(sizeget); modeset(modeget); init(); } SegT(vector<valtype> cpyvec, ll modeget = 0) { sizeset(cpyvec.sz); modeset(modeget); init(); copy(cpyvec); } SegT(ll sizeget, valtype initvget, function<valtype(valtype x, valtype y)> calcget) { sizeset(sizeget); initv = initvget; calc = calcget; init(); } SegT(vector<valtype> cpyvec, valtype initvget, function<valtype(valtype x, valtype y)> calcget) { sizeset(cpyvec.sz); initv = initvget; calc = calcget; init(); copy(cpyvec); } void sizeset(ll rsize) { size = DigN2(rsize); if (rsize == Pow2(size - 1)) size--; return; } void modeset(ll mode) { switch (mode) { case 0: initv = 0; calc = [](valtype x, valtype y) { return x + y; }; break; case 1: initv = INF; calc = [](valtype x, valtype y) { return min(x, y); }; break; case 2: initv = -INF; calc = [](valtype x, valtype y) { return max(x, y); }; break; } return; } void init() { v.asn(Pow2(size + 1) - 1, initv); } void copy(vector<valtype> cpyvec) { REP(i, min(cpyvec.sz, Pow2(size))) set(i, cpyvec[i]); } ll i2v(ll i) const { if (i < 0 || i >= Pow2(size)) return -1; return Pow2(size) + i - 1; } ll top(ll i) const { if (i == 0) return -1; return (i - 1) / 2; } pl bot(ll i) const { if (i + 1 >= Pow2(size)) return mp(-1, -1); return mp(2 * i + 1, 2 * i + 2); } void set(ll i, valtype x) { i = i2v(i); v[i] = x; while (i > 0) { i = top(i); v[i] = calc(v[bot(i).fi], v[bot(i).se]); } return; } void add(ll i, valtype x) { set(i, v[i2v(i)] + x); return; } valtype operator[](const ll &i) const { return v[i2v(i)]; } // valtype que(ll a = 0, ll b = Pow2(size) - 1) { valtype que(ll a, ll b) { if (a == b) return v[i2v(a)]; if (a > b) return initv; // swap(a, b); valtype ans = initv; ll ai = i2v(a); ll bi = i2v(b); FOR(i, 1, size + 1) { if (a > b) break; if (a % Pow2(i)) { ans = calc(ans, v[ai]); a += Pow2(i - 1); ai = top(ai) + 1; } else { ai = top(ai); } if (a > b) break; if ((b + 1) % Pow2(i)) { ans = calc(ans, v[bi]); b -= Pow2(i - 1); bi = top(bi) - 1; } else { bi = top(bi); } if (a > b) break; } return ans; } valtype que(ll b) { return que(0, b); } valtype que() { return que(0, Pow2(size) - 1); } }; /*template <class Type> class DP { public: vector<Type> v; Type initv; vll size, block; DP() {} DP(const DP &dp) {} template<class... Args> DP(Args... args) { block.asn(1, 1); Initialize(args...); } void Initialize(Type initv_) { initv = initv_; v.asn(block.bk, initv); } template<class... Args> void Initialize(ll val, Args... args) { size.pb(val); block.pb(block.bk*val); Initialize(args...); } };*/ pl Bezout(ll a, ll b) { if (b != 0) { pl xy; xy = Bezout(b, a % b); return mp(xy.se, xy.fi - ((a / b) * xy.se)); } else { return mp(1, 0); } } pl Bez(ll a, ll b, ll c) { pl xy; ll x, y, z, gc; xy = Bezout(a, b); gc = gcd(a, b); if (c % gc != 0) return mp(-1, -1); x = xy.fi * (c / gc); y = xy.se * (c / gc); if (x < 0) z = rup(-x, (b / gc)); if (x >= 0) z = -x / (b / gc); x += z * (b / gc); y -= z * (a / gc); return mp(x, y); } ll DigS10(ll n) { ll ans = 0; while (1) { ans += n % 10; n /= 10; if (!n) break; } return ans; } ll isP(ll n) { if (n <= 1) return 0; FOR(i, 2, (ll)sqrt(n) + 1) { if (n % i == 0) return 0; } return 1; } ll Tot(ll n) { if (n <= 0) return 0; ll ans = n, x = 2; while (x * x <= n) { if (n % x == 0) { ans -= ans / x; while (n % x == 0) n /= x; } x++; } if (n > 1) ans -= ans / n; return ans; } template <class T> struct Graph { public: ll vSize; ll eMode; ll mapMode; ActPair(T) Add; BoolPair(T) Lesser; BoolPair(T) Equal; V<V<P<T, ll>>> adj; map<pl, T> len; Graph(ll vSize, ll eMode = 0, ll mapMode = 0, ActPair(T) Add = ADD, BoolPair(T) Lesser = LES, BoolPair(T) Equal = EQ) : vSize(vSize), eMode(eMode), mapMode(mapMode), Add(Add), Lesser(Lesser), Equal(Equal) { Init(); } void Init() { adj.asn(vSize, V<P<T, ll>>()); } void AddE(ll x, ll y, T cost) { iAddE(x, y, cost); if (!eMode) iAddE(y, x, cost); } void iAddE(ll x, ll y, T cost) { adj[x].pb(mp(cost, y)); if (mapMode) len[mp(x, y)] = cost; } P<bool, T> getE(ll x, ll y) { if (!len.count(mp(x, y))) return mp(false, Lesser.fi); return mp(true, len[mp(x, y)]); } V<T> Dijk(ll x) { V<T> ans(vSize, Lesser.fi); if (x < 0 || x >= vSize) return ans; SegT<P<T, ll>> segt(vSize, mp(Lesser.fi, -1), clam(if (l.se < 0) return r; if (r.se < 0) return l; return Lesser.se(l.fi, r.fi) ? l : r;)); segt.set(x, mp(Add.fi, x)); P<T, ll> now; while ((now = segt.que(0, vSize - 1)).se >= 0) { ans[now.se] = segt[now.se].fi; segt.set(now.se, mp(Lesser.fi, -2)); ROR(adj[now.se], i) { if (segt[i.se].se == -2) continue; if (segt[i.se].se == -1) { segt.set(i.se, mp(Add.se(ans[now.se], i.fi), i.se)); continue; } if (Lesser.se(Add.se(ans[now.se], i.fi), segt[i.se].fi)) { segt.set(i.se, mp(Add.se(ans[now.se], i.fi), i.se)); continue; } } } return ans; } V<P<T, vll>> rDijk(ll x) { V<P<T, vll>> ans(vSize, mp(Lesser.fi, vll())); if (x < 0 || x >= vSize) return ans; SegT<P<T, ll>> segt(vSize, mp(Lesser.fi, -1), clam(if (l.se < 0) return r; if (r.se < 0) return l; return Lesser.se(l.fi, r.fi) ? l : r;)); segt.set(x, mp(Add.fi, x)); P<T, ll> now; while ((now = segt.que(0, vSize - 1)).se >= 0) { ans[now.se].fi = segt[now.se].fi; segt.set(now.se, mp(Lesser.fi, -2)); ROR(adj[now.se], i) { if (segt[i.se].se == -2) continue; if (segt[i.se].se == -1) { segt.set(i.se, mp(Add.se(ans[now.se].fi, i.fi), i.se)); ans[i.se].se = {now.se}; continue; } if (Lesser.se(Add.se(ans[now.se].fi, i.fi), segt[i.se].fi)) { segt.set(i.se, mp(Add.se(ans[now.se].fi, i.fi), i.se)); ans[i.se].se = {now.se}; continue; } if (Equal.se(Add.se(ans[now.se].fi, i.fi), segt[i.se].fi)) { ans[i.se].se.pb(now.se); continue; } } } return ans; } T Prim(ll x = 0) { T ans = Add.fi; if (x < 0 || x >= vSize) return ans; SegT<P<T, ll>> segt(vSize, mp(Lesser.fi, -1), clam(if (l.se < 0) return r; if (r.se < 0) return l; return Lesser.se(l.fi, r.fi) ? l : r;)); segt.set(x, mp(Add.fi, x)); P<T, ll> now; while ((now = segt.que(0, vSize - 1)).se >= 0) { ans = Add.se(ans, segt[now.se].fi); segt.set(now.se, mp(Lesser.fi, -2)); ROR(adj[now.se], i) { if (segt[i.se].se == -2) continue; if (segt[i.se].se == -1) { segt.set(i.se, i); continue; } if (Lesser.se(i.fi, segt[i.se].fi)) { segt.set(i.se, i); continue; } } } return ans; } P<T, V<P<T, vll>>> rPrim(ll x = 0) { P<T, V<P<T, vll>>> ans = mp(Add.fi, V<P<T, vll>>(vSize, mp(Lesser.fi, vll()))); if (x < 0 || x >= vSize) return ans; SegT<P<T, ll>> segt(vSize, mp(Lesser.fi, -1), clam(if (l.se < 0) return r; if (r.se < 0) return l; return Lesser.se(l.fi, r.fi) ? l : r;)); segt.set(x, mp(Add.fi, x)); P<T, ll> now; while ((now = segt.que(0, vSize - 1)).se >= 0) { ans.se[now.se].fi = segt[now.se].fi; ans.fi = Add.se(ans.fi, ans.se[now.se].fi); segt.set(now.se, mp(Lesser.fi, -2)); ROR(adj[now.se], i) { if (segt[i.se].se == -2) continue; if (segt[i.se].se == -1) { segt.set(i.se, i); ans.se[i.se].se = {now.se}; continue; } if (Lesser.se(i.fi, segt[i.se].fi)) { segt.set(i.se, i); ans.se[i.se].se = {now.se}; continue; } if (Equal.se(i.fi, segt[i.se].fi)) { ans.se[i.se].se.pb(now.se); continue; } } } return ans; } }; template <class T> struct Sum { public: V<T> v, s; ll size; ActPair(T) Add; ActPair(T) Sub; Sum(V<T> v, ActPair(T) Add = ADD, ActPair(T) Sub = SUB) : v(v), size(v.sz), Add(Add), Sub(Sub) { Init(); Calc(); } void Init() { s.asn(size + 1, Add.fi); } void Calc() { REP(i, size) s[i + 1] = Add.se(s[i], v[i]); } T operator()(ll x) { if (x < -1) x = -1; if (x > size - 1) x = size - 1; return s[x + 1]; } T operator()(ll l, ll r) { if (l < 0) l = 0; if (r >= size) r = size - 1; if (l > r) return Add.fi; return Sub.se(s[r + 1], s[l]); } }; using sumll = Sum<ll>; template <class T> struct Sum2 { public: V<V<T>> v, s; ll RowSize, ColumnSize; ActPair(T) Add; ActPair(T) Sub; Sum2(V<V<T>> v, ActPair(T) Add = ADD, ActPair(T) Sub = SUB) : v(v), RowSize(v.sz), ColumnSize(v.sz ? v[0].sz : 0), Add(Add), Sub(Sub) { Init(); Calc(); } void Init() { s.asn(RowSize + 1, V<T>(ColumnSize + 1, Add.fi)); } void Calc() { REP1(r, RowSize) { REP1(c, ColumnSize) { // s[r][c] = Sub.se(Add.se(Add.se(v[r - 1][c - //1], operator()(r - 1, c - 2)), operator()(r - 2, c - 1)), operator()(r //- 2, c - 2)); s[r][c] = Add.se(s[r][c - 1], v[r - 1][c - 1]); } } REP1(r, RowSize) { REP1(c, ColumnSize) { s[r][c] = Add.se(s[r - 1][c], s[r][c]); } } } T operator()(ll r, ll c) { if (r < -1) r = -1; if (c < -1) c = -1; if (r > RowSize - 1) r = RowSize - 1; if (c > ColumnSize - 1) c = ColumnSize - 1; return s[r + 1][c + 1]; } T operator()(ll r1, ll c1, ll r2, ll c2) { if (r1 < 0) r1 = 0; if (c1 < 0) c1 = 0; if (r2 >= RowSize) r2 = RowSize - 1; if (c2 >= ColumnSize) c2 = ColumnSize - 1; if (r1 > r2) return Add.fi; if (c1 > c2) return Add.fi; return Sub.se(Add.se(s[r2 + 1][c2 + 1], s[r1][c1]), Add.se(s[r2 + 1][c1], s[r1][c2 + 1])); } }; using sumll2 = Sum2<ll>; template <class T> struct Point2 { public: V<V<T>> v; ll h, w; Point2() : h(0), w(0) {} Point2(ll h, ll w) : h(h), w(w) { asn(h, w); } Point2(ll h, ll w, T val) : h(h), w(w) { asn(h, w, val); } void assign(ll h, ll w) { v.asn(h, V<T>(w)); } void assign(ll h, ll w, ll val) { v.asn(h, V<T>(w, val)); } T &operator()(ll h, ll w) { return v[h][w]; } T &operator()(pl p) { return v[p.fi][p.se]; } }; template <class T> using P2 = Point2<T>; template <ll Mod> struct Modll { public: ll v; Modll() : v(0) {} Modll(ll _v) { set(_v % Mod + Mod); } Modll &set(ll _v) { v = (_v < Mod) ? _v : (_v - Mod); return *this; } Modll pow(ll n) const { Modll x = *this, ans = 1; while (n) { if (n & 1) ans *= x; x *= x; n >>= 1; } return ans; } Modll inverse() const { return (*this).pow(Mod - 2); } Modll operator+(const Modll &m) const { return Modll().set(v + m.v); } Modll operator-(const Modll &m) const { return Modll().set(Mod + v - m.v); } Modll operator*(const Modll &m) const { return Modll().set((ull(v) * m.v) % Mod); } Modll operator/(const Modll &m) const { return *this * m.inv; } Modll &operator+=(const Modll &m) { return *this = *this + m; } Modll &operator-=(const Modll &m) { return *this = *this - m; } Modll &operator*=(const Modll &m) { return *this = *this * m; } Modll &operator/=(const Modll &m) { return *this = *this / m; } Modll operator-() const { return Modll(0) - *this; } explicit operator bool() const { return v != 0; } friend istream &operator>>(istream &in, Modll &m) { return in >> m.v; } friend ostream &operator<<(ostream &out, const Modll &m) { return out << m.v; } }; using mll = Modll<MOD>; using vmll = V<mll>; using vvmll = V<vmll>; using vvvmll = V<vvmll>; vmll MFactMemo(2, 1); vmll MIFactMemo(2, 1); mll mFact(ll n) { if (MFactMemo.sz <= n) { ll oldsize = MFactMemo.sz; MFactMemo.res(n + 1, 1); FOR(i, oldsize, n) MFactMemo[i] = MFactMemo[i - 1] * i; } return MFactMemo[n]; } mll miFact(ll n) { if (MIFactMemo.sz <= n) { ll oldsize = MIFactMemo.sz; MIFactMemo.res(n + 1, 1); MIFactMemo.bk = mFact(n).inv; rFOR(i, oldsize + 1, n) MIFactMemo[i - 1] = MIFactMemo[i] * i; } return MIFactMemo[n]; } mll mComb(ll n, ll k) { if (n < 0 || k < 0 || n < k) return 0; return mFact(n) * miFact(k) * miFact(n - k); } ll LIS(vll v, ll m = 0) { if (v.sz > 0) { ll ans = 0; vll dp(v.sz, INF); FOR(i, 0, v.sz - 1) { dp[m ? UPB(dp, v[i]) : LOWB(dp, v[i])] = v[i]; } FOR(i, 0, v.sz - 1) { if (dp[i] == INF) break; ans++; } return ans; } else { return 0; } } ll Bsrch(function<bool(ll x)> f, ll mi, ll ma) { ll ng = mi - 1, ok = ma, mid; while (ok - ng > 1) { mid = (ng + ok) / 2; (f(mid) ? ok : ng) = mid; } return ok; } template <class T> V<V<T>> MultiMatrix(V<V<T>> A, V<V<T>> B, ActPair(T) Mul = MUL, ActPair(T) Add = ADD) { V<V<T>> ans; ll ii = A.sz; if (!ii) return ans; ll jj = A[0].sz; if (!jj) return ans; ll jj2 = B.sz; if (!jj2) return ans; if (jj != jj2) return ans; ll kk = B[0].sz; if (!kk) return ans; ans.asn(ii, V<T>(kk, 0)); REP(i, ii) { REP(k, kk) { REP(j, jj) { ans[i][k] = Add.se(ans[i][k], Mul.se(A[i][j], B[j][k])); } } } return ans; } vvll CombMemo(1000, vll(1000, -1)); ll Comb(ll n, ll k) { if ((n < 0) || (k < 0)) return 0; if (CombMemo[n][k] == -1) { if (n < k) CombMemo[n][k] = 0; else { if (n == 0) CombMemo[n][k] = 1; else if (k == 0) CombMemo[n][k] = 1; else if (n == k) CombMemo[n][k] = 1; else CombMemo[n][k] = Comb(n - 1, k - 1) + Comb(n - 1, k); } } return CombMemo[n][k]; } template <class T> map<T, ll> Dict(V<T> v) { map<T, ll> m; if (!v.sz) return m; SORT(v); UNIQUE(v); REP(i, v.sz) { m[v[i]] = i; } return m; } template <class T> vll Cmprs(V<T> v) { auto m = Dict(v); vll ans(v.sz); REP(i, v.sz) { ans[i] = m[v[i]]; } return ans; } template <class T> vll PCmprs(V<T> v) { if (v.sz == 0) return V<T>(); vll tmp(v.sz); vll ans(v.sz); IOTA(tmp, 0); IOTA(ans, 0); sort(tmp.bgn, tmp.en, clam(return v[l] < v[r];)); sort(ans.bgn, ans.en, clam(return tmp[l] < tmp[r];)); return ans; } ll BblCnt(vll rv) { vll v = PCmprs(rv); SegT<ll> b(v.sz, 0); ll ans = 0; REP(i, v.sz) { ans += (i - b.que(0, v[i])); b.add(v[i], 1); } return ans; } template <class T> auto ven(T val) { return val; } template <> auto ven<int>(int val) { return (ll)val; } template <class T, class... Args> auto ven(T val, Args... args) { auto tmp = ven(args...); return V<decltype(tmp)>(val, tmp); } template <class T> void zind(T &v) { v--; } template <class T> void zind(V<T> &v) { ROR(v, i) zind(i); } template <class T, class... Args> void zind(T &v, Args &...args) { zind(v); zind(args...); } void Solve(); signed main() { cin.tie(0); ios::sync_with_stdio(false); cout << setprecision(20) << fixed; Solve(); } void Solve() { li(n); vlc(n, a, b); vpl c(n); REP(i, n) c[i] = mp(a[i] + b[i], i); rSORT(c); // sort(c.bgn, c.en, [](pl l, pl r) {return l.fi != r.fi ? l.fi > r.fi:l.se //< r.se; }); ll t = 0, u = 0, uu = 0; REP(i, n) { if (i % 2 == 0) u += a[c[i].se]; if (i % 2 == 1) uu += b[c[i].se]; } /* while (t < n) { u += a[c[t].se]; t++; if (t == n) break; u -= b[c[t].se]; t++; }*/ sal(u - uu); }
[ "identifier.change", "call.function.change", "assignment.value.change", "variable_access.subscript.index.change" ]
941,757
941,756
u211681714
cpp
p03141
#include <bits/stdc++.h> using namespace std; template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; template <class T> using VVV = V<VV<T>>; template <class S, class T> using P = pair<S, T>; template <class S, class T, class U> using TP = tuple<S, T, U>; using ll = long long; using ull = unsigned long long; using dbl = double; using str = string; using vll = V<ll>; using vvll = V<vll>; using vvvll = V<vvll>; using pl = P<ll, ll>; using tl = TP<ll, ll, ll>; using vpl = V<pl>; using vvpl = V<vpl>; using vtl = V<tl>; using vvtl = V<vtl>; using vs = V<str>; using vvs = V<vs>; using vd = V<dbl>; using vvd = V<vd>; using qll = queue<ll>; using qpl = queue<pl>; using stll = stack<ll>; using stpl = stack<pl>; using mapll = map<ll, ll>; using setll = set<ll>; using pqll = priority_queue<ll>; //#define int ll #define fi first #define se second #define mp make_pair #define mt make_tuple #define pb push_back #define pob pop_back() #define pf push_front #define pof pop_front() #define sz size() #define bgn begin() #define en end() #define asn assign #define emp empty() #define fr front() #define bk back() #define clr clear() #define ins insert #define ers erase #define res resize #define tp top() #define p_q priority_queue #define inv inverse() #define FOR(i, a, b) for (ll i = (a); i <= (ll)(b); i++) #define rFOR(i, a, b) for (ll i = (b); i >= (ll)(a); i--) #define REP(i, a) FOR((i), 0, (ll)(a)-1) #define REP0(i, a) FOR((i), 0, (ll)(a)) #define REP1(i, a) FOR((i), 1, (ll)(a)) #define rREP(i, a) rFOR((i), 0, (ll)(a)-1) #define rREP0(i, a) rFOR((i), 0, (ll)(a)) #define rREP1(i, a) rFOR((i), 1, (ll)(a)) #define ROR(v, i) for (auto &(i) : (v)) #define IOTA(a, n) iota((a).bgn, (a).en, (n)) #define SORT(a) sort((a).bgn, (a).en) #define rSORT(a) sort((a).rbegin(), (a).rend()) #define UNIQUE(a) (a).erase(unique((a).bgn, (a).en), (a).en) #define PREVP(a) prev_permutation((a).bgn, (a).en) #define NEXTP(a) next_permutation((a).bgn, (a).en) #define BINS(a, b) binary_search((a).bgn, (a).en, (b)) #define LOWB(a, b) (lower_bound((a).bgn, (a).en, (b)) - (a).bgn) #define UPB(a, b) (upper_bound((a).bgn, (a).en, (b)) - (a).bgn) #define CNT(a, b) count((a).bgn, (a).en, b) #define SUM(a) accumulate((a).bgn, (a).en, 0) #define REV(a) reverse((a).bgn, (a).en) #define REGS(a, b) regex_search((a), regex(b)) #define REGM(a, b) regex_match((a), regex(b)) #define yn(a) cout << ((a) ? "yes" : "no") << "\n"; #define Yn(a) cout << ((a) ? "Yes" : "No") << "\n"; #define YN(a) cout << ((a) ? "YES" : "NO") << "\n"; #define imp(a) cout << ((a) ? "possible" : "impossible") << "\n"; #define Imp(a) cout << ((a) ? "Possible" : "Impossible") << "\n"; #define IMP(a) cout << ((a) ? "POSSIBLE" : "IMPOSSIBLE") << "\n"; #define fs(a) cout << ((a) ? "second" : "first") << "\n"; #define Fs(a) cout << ((a) ? "Second" : "First") << "\n"; #define FS(a) cout << ((a) ? "SECOND" : "FIRST") << "\n"; //#define say(a) cout <<(a); //#define sal(a) cout <<(a)<<"\n"; #define sak cout << "\n"; #define sas cout << " "; #define sat cout << "\t"; #define dbg(a) cerr << (#a) << ": " << (a) << "\n"; #define dbgs(...) \ dal(#__VA_ARGS__); \ dal(__VA_ARGS__); #define c2l(a) ((ll)(a - 48)) #define a2l(a) ((ll)(a - 97)) #define A2l(a) ((ll)(a - 65)) #define l2c(a) ((char)(a + 48)) #define l2a(a) ((char)(a + 97)) #define l2A(a) ((char)(a + 65)) #define DigN2(a) ((llabs(a) == 0) ? (1) : ((ll)(log2(double(llabs(a)))) + 1)) #define DigN10(a) ((llabs(a) == 0) ? (1) : ((ll)(log10(double(llabs(a)))) + 1)) #define Dig2(a, b) (((a) >> (b)) & 1) #define Dig10(a, b) (ll)(((a) / ((ll)(pow(10.0, (double)(b))))) % 10) #define Pow2(a) ((ll)(1) << (a)) #define Pow10(a) ((ll)(pow(10.0, double(a)))) #define LSB(a) ((a) & (-(a))) /*#define llin(a) ll (a);cin >>(a); #define llin2(a,b) ll (a),(b);cin >>(a)>>(b); #define llin3(a,b,c) ll (a),(b),(c);cin >>(a)>>(b)>>(c); #define stin(a) string (a);cin >>(a);*/ #define vin(v) \ ROR((v), (i)) { cin >> (i); }; #define vllin(v, N) \ vll(v)((N)); \ vin(v); #define vllin2(a, b, N) \ vll(a)(N), (b)(N); \ REP(i, N) { cin >> (a)[i] >> (b)[i]; }; #define vsin(v, N) \ vs(v)((N)); \ vin(v); #define rdn(a, b) ((a) / (b)) #define rou(a, b) \ ((((double(a) / double(b)) - ((a) / (b))) < 0.5) ? ((a) / (b)) \ : (((a) / (b)) + 1)) #define rup(a, b) ((((a) % (b)) == 0) ? ((a) / (b)) : (((a) / (b)) + 1)) #define powll(a, b) (ll)(pow((double)(a), (double)(b))) #define Triangle(x1, y1, x2, y2, x3, y3) \ (((x1) - (x2)) * ((y1) - (y3)) - ((x1) - (x3)) * ((y1) - (y2))) #define lam(lr) ([](auto l, auto r) { lr }) #define elam(lr) ([=](auto l, auto r) { lr }) #define clam(lr) ([&](auto l, auto r) { lr }) #define min(...) Operation(MIN, __VA_ARGS__) #define max(...) Operation(MAX, __VA_ARGS__) #define gcd(...) Operation(GCD, __VA_ARGS__) #define lcm(...) Operation(LCM, __VA_ARGS__) #define vmin(...) VOperation(MIN, __VA_ARGS__) #define vmax(...) VOperation(MAX, __VA_ARGS__) #define vgcd(...) VOperation(GCD, __VA_ARGS__) #define vlcm(...) VOperation(LCM, __VA_ARGS__) #define vsum(...) VOperation(ADD, __VA_ARGS__) #define vpro(...) VOperation(MUL, __VA_ARGS__) #define emin(a, ...) ((a) = min((a), __VA_ARGS__)) #define emax(a, ...) ((a) = max((a), __VA_ARGS__)) #define egcd(a, ...) ((a) = gcd((a), __VA_ARGS__)) #define elcm(a, ...) ((a) = lcm((a), __VA_ARGS__)) #define ActPair(T) P<T, function<T(T, T)>> #define BoolPair(T) P<T, function<bool(T, T)>> #define ope Operation #define vope VOperation #define svll SumV<ll> #define svvll SumV2<ll> #define li(...) \ ll __VA_ARGS__; \ Input(__VA_ARGS__); #define si(...) \ str __VA_ARGS__; \ Input(__VA_ARGS__); //#define vli(size, ...) vll __VA_ARGS__;vInitInput(size,__VA_ARGS__); #define vlr(size, ...) \ vll __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vlc(size, ...) \ vll __VA_ARGS__; \ vInitInputC(size, __VA_ARGS__); #define vli(size, ...) \ vll __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vsr(size, ...) \ vs __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vsc(size, ...) \ vs __VA_ARGS__; \ vInitInputC(size, __VA_ARGS__); #define vsi(size, ...) \ vs __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vli2(rowSize, columnSize, ...) \ vvll __VA_ARGS__; \ vInitInput2(rowSize, columnSize, __VA_ARGS__); #define vplr(size, ...) \ vpl __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vplc(size, ...) \ vpl __VA_ARGS__; \ vInitInputC(size, __VA_ARGS__); #define vpli(size, ...) \ vpl __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); const ll MOD = 1e9 + 7; // const ll MOD = 998244353; // const ll MOD = 924844033; // const ll MOD = 9007199254740881; const ll INF = 1LL << 60; // 1.15e18 const double PI = acos(-1.0); const vll DX = {0, -1, 0, 1, 0, -1, 1, 1, -1}; const vll DY = {0, 0, -1, 0, 1, -1, -1, 1, 1}; const str alp = "abcdefghijklmnopqrstuvwxyz"; const str ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; template <class S, class T> istream &operator>>(istream &in, P<S, T> &p) { return in >> p.fi >> p.se; } template <class T> istream &operator>>(istream &in, V<T> &v) { REP(i, v.sz) in >> v[i]; return in; } void Input() {} template <class Var, class... Args> void Input(Var &var, Args &...args) { cin >> var; Input(args...); } void vInit(ll size) {} template <class T, class... Args> void vInit(ll size, V<T> &v, Args &...args) { v.res(size); vInit(size, args...); } void vInput(ll size) {} template <class T, class... Args> void vInput(ll size, V<T> &v, Args &...args) { REP(i, size) cin >> v[i]; vInput(size, args...); } void vInputR(ll size) {} template <class T, class... Args> void vInputR(ll size, V<T> &v, Args &...args) { REP(i, size) cin >> v[i]; vInputR(size, args...); } void vInputNumC(ll num) {} template <class T, class... Args> void vInputNumC(ll num, V<T> &v, Args &...args) { cin >> v[num]; vInputNumC(num, args...); } void vInputC(ll size) {} template <class... Args> void vInputC(ll size, Args &...args) { REP(i, size) vInputNumC(i, args...); } void vInitInputR(ll size) {} template <class... Args> void vInitInputR(ll size, Args &...args) { vInit(size, args...); vInputR(size, args...); } void vInitInputC(ll size) {} template <class... Args> void vInitInputC(ll size, Args &...args) { vInit(size, args...); vInputC(size, args...); } void vInit2(ll rowSize, ll columnSize) {} template <class T, class... Args> void vInit2(ll rowSize, ll columnSize, V<V<T>> &v, Args &...args) { v.asn(rowSize, V<T>(columnSize)); vInit2(rowSize, columnSize, args...); } void vInput2(ll rowSize, ll columnSize) {} template <class T, class... Args> void vInput2(ll rowSize, ll columnSize, V<V<T>> &v, Args &...args) { REP(r, rowSize) { REP(c, columnSize) { cin >> v[r][c]; } } vInput2(rowSize, columnSize, args...); } void vInitInput2(ll rowSize, ll columnSize) {} template <class... Args> void vInitInput2(ll rowSize, ll columnSize, Args &...args) { vInit2(rowSize, columnSize, args...); vInput2(rowSize, columnSize, args...); } template <class S, class T> ostream &operator<<(ostream &out, const P<S, T> &p) { return out << "[" << p.fi << ", " << p.se << "]"; } template <class T> ostream &operator<<(ostream &out, V<T> &v) { if (v.emp) return out << "{}"; else { auto itr = v.bgn; out << "{" << *itr; itr++; while (itr != v.en) { out << ", " << *itr; itr++; } out << "}"; return out; } } template <class S, class T> ostream &operator<<(ostream &out, const map<S, T> &m) { if (m.emp) return out << "<[]>"; else { auto itr = m.bgn; out << "< [" << (itr->fi) << ": " << (itr->se); itr++; while (itr != m.en) { out << "], [" << (itr->fi) << ": " << (itr->se); itr++; } out << "] >"; return out; } } template <class T> ostream &operator<<(ostream &out, const set<T> &s) { if (s.emp) return out << "<>"; else { auto itr = s.bgn; out << "<" << *itr; itr++; while (itr != s.en) { out << ", " << *itr; itr++; } out << ">"; return out; } } void say() {} template <class T> void say(T t) { cout << t; } template <class Head, class... Body> void say(Head head, Body... body) { cout << head << " "; say(body...); } void sal() { cout << "\n"; } template <class... Args> void sal(Args... args) { say(args...); cout << "\n"; } void day() {} template <class T> void day(T t) { cerr << t; } template <class Head, class... Body> void day(Head head, Body... body) { cerr << head << " "; day(body...); } void dal() { cerr << "\n"; } template <class... Args> void dal(Args... args) { day(args...); cerr << "\n"; } void salv() {} template <class T> void salv(V<T> v) { if (v.emp) sal(); else { auto itr = v.bgn; say(*itr); itr++; while (itr != v.en) { sas; say(*itr); itr++; } sak; } } template <class T> void salv(V<V<T>> v) { if (v.emp) sal(); else { ROR(v, i) salv(i); } } template <class T, class... Args> void salv(T v, Args... args) { salv(v); salv(args...); } template <class L, class R> auto Gcd(L l, R r) -> decltype(l + r) { if (l < r) swap(l, r); return r ? Gcd(r, l % r) : l; } template <class L, class R> auto Lcm(L l, R r) { if (!l || !r) return 0; return l / Gcd(l, r) * r; } auto LES = mp(INF, lam(return l < r;)); auto GRT = mp(-INF, lam(return l > r;)); auto EQ = mp(0, lam(return l == r;)); auto ADD = mp(0, lam(return l + r;)); auto SUB = mp(0, lam(return l - r;)); auto MUL = mp(1, lam(return l * r;)); auto DIV = mp(1, lam(return l / r;)); auto MDL = mp(1, lam(return l % r;)); auto XOR = mp(0, lam(return l ^ r;)); auto OR = mp(0, lam(return l | r;)); auto AND = mp(((ll)(1) << 63) - 1, lam(return l & r;)); auto MIN = mp(INF, lam(return (l < r) ? l : r;)); auto MAX = mp(-INF, lam(return (l > r) ? l : r;)); auto GCD = mp(0, lam(return Gcd(l, r);)); auto LCM = mp(1, lam(return Lcm(l, r);)); /* auto ADD = mp(0, [](auto l, auto r) { return l + r; }); auto SUB = mp(1, [](auto l, auto r) { return l - r; }); auto MUL = mp(1, [](auto l, auto r) { return l * r; }); auto DIV = mp(0, [](auto l, auto r) { return l / r; }); auto MDL = mp(0, [](auto l, auto r) { return l % r; }); auto XOR = mp(0, [](auto l, auto r) { return l ^ r; }); auto OR = mp(0, [](auto l, auto r) { return l | r; }); auto AND = mp(((ll)(1) << 63) - 1, [](auto l, auto r) { return l & r; }); auto MIN = mp(INF, [](auto l, auto r) { return (l < r) ? l : r; }); auto MAX = mp(-INF, [](auto l, auto r) { return (l > r) ? l : r; }); auto GCD = mp(0, [](auto l, auto r) { return gcd(l, r); }); auto LCM = mp(1, [](auto l, auto r) { return lcm(l, r); }); */ template <class OperationType> auto Operation(OperationType A) { return A.fi; } template <class OperationType, class T> auto Operation(OperationType A, T x) { return x; } template <class OperationType, class T, class... Args> auto Operation(OperationType A, T x, Args... args) { auto tmp = Operation(A, args...); return A.se(x, tmp); } template <class OperationType> auto VOperation(OperationType A) { return A.fi; } template <class OperationType, class T> auto VOperation(OperationType A, T x) { return x; } template <class OperationType, class T> auto VOperation(OperationType A, V<T> x) { T tmp = A.fi; ROR(x, i) tmp = A.se(tmp, i); return tmp; } template <class OperationType, class T> auto VOperation(OperationType A, V<V<T>> x) { T tmp = A.fi; ROR(x, i) ROR(i, j) tmp = A.se(tmp, j); return tmp; } template <class OperationType, class T> auto VOperation(OperationType A, V<V<V<T>>> x) { T tmp = A.fi; ROR(x, i) ROR(i, j) ROR(j, k) tmp = A.se(tmp, k); return tmp; } template <class OperationType, class T> auto VOperation(OperationType A, V<V<V<V<T>>>> x) { T tmp = A.fi; ROR(x, i) ROR(i, j) ROR(j, k) ROR(k, l) tmp = A.se(tmp, l); return tmp; } template <class OperationType, class T, class... Args> auto VOperation(OperationType A, T x, Args... args) { auto xResult = VOperation(A, x); auto tmp = VOperation(A, args...); return A.se(xResult, tmp); } ll Bset(ll a, ll b, ll c) { if (c) a |= b; else a &= ~b; return a; } struct UFT { public: ll tsize; ll mode; vll par; vll rank; UFT() {} UFT(const UFT &uft) {} UFT(ll tsizeget, ll modeget = 0) { tsize = tsizeget; mode = modeget; par.asn(tsize, -1); if (!mode) rank.res(tsize, 0); } ll root(ll x) { return par[x] < 0 ? x : par[x] = root(par[x]); } bool isRoot(ll x) { return x == root(x); } bool same(ll x, ll y) { return root(x) == root(y); } void merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) return; if (mode) { par[x] += par[y]; par[y] = x; } else { if (rank[x] < rank[y]) { par[y] += par[x]; par[x] = y; } else { par[x] += par[y]; par[y] = x; if (rank[x] == rank[y]) rank[x]++; } } } ll size(ll x) { return -par[root(x)]; } }; struct pUFT { public: ll tsize; ll now; vll par; vll rank; vll mtime; vvll sizepi; vvll sizepv; pUFT() {} pUFT(const pUFT &puft) {} pUFT(ll tsizeget) { tsize = tsizeget; now = 0; par.asn(tsize, -1); rank.asn(tsize, 0); mtime.asn(tsize, INF); sizepi.asn(tsize, {0}); sizepv.asn(tsize, {1}); } ll root(ll x, ll t) { return (mtime[x] > t) ? x : root(par[x], t); } bool same(ll x, ll y, ll t) { return root(x, t) == root(y, t); } ll merge(ll x, ll y) { now++; x = root(x, now); y = root(y, now); if (x != y) { if (rank[x] < rank[y]) { par[y] += par[x]; sizepi[y].pb(now); sizepv[y].pb(-par[y]); par[x] = y; mtime[x] = now; } else { par[x] += par[y]; sizepi[x].pb(now); sizepv[x].pb(-par[x]); par[y] = x; mtime[y] = now; if (rank[x] == rank[y]) rank[x]++; } } return now; } ll size(ll x, ll t) { x = root(x, t); return sizepv[x][UPB(sizepi[x], t) - 1]; } }; struct wUFT { public: ll tsize; ll mode; vll par; vll rank; vll dweight; wUFT() {} wUFT(const wUFT &wuft) {} wUFT(ll tsizeget, ll modeget = 0) { tsize = tsizeget; mode = modeget; par.asn(tsize, -1); if (!mode) rank.res(tsize, 0); dweight.asn(tsize, 0); } ll root(ll x) { if (par[x] < 0) return x; else { ll r = root(par[x]); dweight[x] += dweight[par[x]]; return par[x] = r; } } ll weight(ll x) { root(x); return dweight[x]; } ll diff(ll x, ll y) { return weight(y) - weight(x); } bool isRoot(ll x) { return x == root(x); } bool same(ll x, ll y) { return root(x) == root(y); } void merge(ll x, ll y, ll w) { w += weight(x); w -= weight(y); x = root(x); y = root(y); if (x == y) return; if (mode) { par[x] += par[y]; par[y] = x; } else { if (rank[x] < rank[y]) { par[y] += par[x]; par[x] = y; dweight[x] = -w; } else { par[x] += par[y]; par[y] = x; if (rank[x] == rank[y]) rank[x]++; dweight[y] = w; } } } ll size(ll x) { return -par[root(x)]; } }; template <typename valtype> class SegT { public: ll size; vector<valtype> v; valtype initv; function<valtype(valtype x, valtype y)> calc; SegT() {} SegT(const SegT &segt) {} SegT(ll sizeget, ll modeget = 0) { sizeset(sizeget); modeset(modeget); init(); } SegT(vector<valtype> cpyvec, ll modeget = 0) { sizeset(cpyvec.sz); modeset(modeget); init(); copy(cpyvec); } SegT(ll sizeget, valtype initvget, function<valtype(valtype x, valtype y)> calcget) { sizeset(sizeget); initv = initvget; calc = calcget; init(); } SegT(vector<valtype> cpyvec, valtype initvget, function<valtype(valtype x, valtype y)> calcget) { sizeset(cpyvec.sz); initv = initvget; calc = calcget; init(); copy(cpyvec); } void sizeset(ll rsize) { size = DigN2(rsize); if (rsize == Pow2(size - 1)) size--; return; } void modeset(ll mode) { switch (mode) { case 0: initv = 0; calc = [](valtype x, valtype y) { return x + y; }; break; case 1: initv = INF; calc = [](valtype x, valtype y) { return min(x, y); }; break; case 2: initv = -INF; calc = [](valtype x, valtype y) { return max(x, y); }; break; } return; } void init() { v.asn(Pow2(size + 1) - 1, initv); } void copy(vector<valtype> cpyvec) { REP(i, min(cpyvec.sz, Pow2(size))) set(i, cpyvec[i]); } ll i2v(ll i) const { if (i < 0 || i >= Pow2(size)) return -1; return Pow2(size) + i - 1; } ll top(ll i) const { if (i == 0) return -1; return (i - 1) / 2; } pl bot(ll i) const { if (i + 1 >= Pow2(size)) return mp(-1, -1); return mp(2 * i + 1, 2 * i + 2); } void set(ll i, valtype x) { i = i2v(i); v[i] = x; while (i > 0) { i = top(i); v[i] = calc(v[bot(i).fi], v[bot(i).se]); } return; } void add(ll i, valtype x) { set(i, v[i2v(i)] + x); return; } valtype operator[](const ll &i) const { return v[i2v(i)]; } // valtype que(ll a = 0, ll b = Pow2(size) - 1) { valtype que(ll a, ll b) { if (a == b) return v[i2v(a)]; if (a > b) return initv; // swap(a, b); valtype ans = initv; ll ai = i2v(a); ll bi = i2v(b); FOR(i, 1, size + 1) { if (a > b) break; if (a % Pow2(i)) { ans = calc(ans, v[ai]); a += Pow2(i - 1); ai = top(ai) + 1; } else { ai = top(ai); } if (a > b) break; if ((b + 1) % Pow2(i)) { ans = calc(ans, v[bi]); b -= Pow2(i - 1); bi = top(bi) - 1; } else { bi = top(bi); } if (a > b) break; } return ans; } valtype que(ll b) { return que(0, b); } valtype que() { return que(0, Pow2(size) - 1); } }; /*template <class Type> class DP { public: vector<Type> v; Type initv; vll size, block; DP() {} DP(const DP &dp) {} template<class... Args> DP(Args... args) { block.asn(1, 1); Initialize(args...); } void Initialize(Type initv_) { initv = initv_; v.asn(block.bk, initv); } template<class... Args> void Initialize(ll val, Args... args) { size.pb(val); block.pb(block.bk*val); Initialize(args...); } };*/ pl Bezout(ll a, ll b) { if (b != 0) { pl xy; xy = Bezout(b, a % b); return mp(xy.se, xy.fi - ((a / b) * xy.se)); } else { return mp(1, 0); } } pl Bez(ll a, ll b, ll c) { pl xy; ll x, y, z, gc; xy = Bezout(a, b); gc = gcd(a, b); if (c % gc != 0) return mp(-1, -1); x = xy.fi * (c / gc); y = xy.se * (c / gc); if (x < 0) z = rup(-x, (b / gc)); if (x >= 0) z = -x / (b / gc); x += z * (b / gc); y -= z * (a / gc); return mp(x, y); } ll DigS10(ll n) { ll ans = 0; while (1) { ans += n % 10; n /= 10; if (!n) break; } return ans; } ll isP(ll n) { if (n <= 1) return 0; FOR(i, 2, (ll)sqrt(n) + 1) { if (n % i == 0) return 0; } return 1; } ll Tot(ll n) { if (n <= 0) return 0; ll ans = n, x = 2; while (x * x <= n) { if (n % x == 0) { ans -= ans / x; while (n % x == 0) n /= x; } x++; } if (n > 1) ans -= ans / n; return ans; } template <class T> struct Graph { public: ll vSize; ll eMode; ll mapMode; ActPair(T) Add; BoolPair(T) Lesser; BoolPair(T) Equal; V<V<P<T, ll>>> adj; map<pl, T> len; Graph(ll vSize, ll eMode = 0, ll mapMode = 0, ActPair(T) Add = ADD, BoolPair(T) Lesser = LES, BoolPair(T) Equal = EQ) : vSize(vSize), eMode(eMode), mapMode(mapMode), Add(Add), Lesser(Lesser), Equal(Equal) { Init(); } void Init() { adj.asn(vSize, V<P<T, ll>>()); } void AddE(ll x, ll y, T cost) { iAddE(x, y, cost); if (!eMode) iAddE(y, x, cost); } void iAddE(ll x, ll y, T cost) { adj[x].pb(mp(cost, y)); if (mapMode) len[mp(x, y)] = cost; } P<bool, T> getE(ll x, ll y) { if (!len.count(mp(x, y))) return mp(false, Lesser.fi); return mp(true, len[mp(x, y)]); } V<T> Dijk(ll x) { V<T> ans(vSize, Lesser.fi); if (x < 0 || x >= vSize) return ans; SegT<P<T, ll>> segt(vSize, mp(Lesser.fi, -1), clam(if (l.se < 0) return r; if (r.se < 0) return l; return Lesser.se(l.fi, r.fi) ? l : r;)); segt.set(x, mp(Add.fi, x)); P<T, ll> now; while ((now = segt.que(0, vSize - 1)).se >= 0) { ans[now.se] = segt[now.se].fi; segt.set(now.se, mp(Lesser.fi, -2)); ROR(adj[now.se], i) { if (segt[i.se].se == -2) continue; if (segt[i.se].se == -1) { segt.set(i.se, mp(Add.se(ans[now.se], i.fi), i.se)); continue; } if (Lesser.se(Add.se(ans[now.se], i.fi), segt[i.se].fi)) { segt.set(i.se, mp(Add.se(ans[now.se], i.fi), i.se)); continue; } } } return ans; } V<P<T, vll>> rDijk(ll x) { V<P<T, vll>> ans(vSize, mp(Lesser.fi, vll())); if (x < 0 || x >= vSize) return ans; SegT<P<T, ll>> segt(vSize, mp(Lesser.fi, -1), clam(if (l.se < 0) return r; if (r.se < 0) return l; return Lesser.se(l.fi, r.fi) ? l : r;)); segt.set(x, mp(Add.fi, x)); P<T, ll> now; while ((now = segt.que(0, vSize - 1)).se >= 0) { ans[now.se].fi = segt[now.se].fi; segt.set(now.se, mp(Lesser.fi, -2)); ROR(adj[now.se], i) { if (segt[i.se].se == -2) continue; if (segt[i.se].se == -1) { segt.set(i.se, mp(Add.se(ans[now.se].fi, i.fi), i.se)); ans[i.se].se = {now.se}; continue; } if (Lesser.se(Add.se(ans[now.se].fi, i.fi), segt[i.se].fi)) { segt.set(i.se, mp(Add.se(ans[now.se].fi, i.fi), i.se)); ans[i.se].se = {now.se}; continue; } if (Equal.se(Add.se(ans[now.se].fi, i.fi), segt[i.se].fi)) { ans[i.se].se.pb(now.se); continue; } } } return ans; } T Prim(ll x = 0) { T ans = Add.fi; if (x < 0 || x >= vSize) return ans; SegT<P<T, ll>> segt(vSize, mp(Lesser.fi, -1), clam(if (l.se < 0) return r; if (r.se < 0) return l; return Lesser.se(l.fi, r.fi) ? l : r;)); segt.set(x, mp(Add.fi, x)); P<T, ll> now; while ((now = segt.que(0, vSize - 1)).se >= 0) { ans = Add.se(ans, segt[now.se].fi); segt.set(now.se, mp(Lesser.fi, -2)); ROR(adj[now.se], i) { if (segt[i.se].se == -2) continue; if (segt[i.se].se == -1) { segt.set(i.se, i); continue; } if (Lesser.se(i.fi, segt[i.se].fi)) { segt.set(i.se, i); continue; } } } return ans; } P<T, V<P<T, vll>>> rPrim(ll x = 0) { P<T, V<P<T, vll>>> ans = mp(Add.fi, V<P<T, vll>>(vSize, mp(Lesser.fi, vll()))); if (x < 0 || x >= vSize) return ans; SegT<P<T, ll>> segt(vSize, mp(Lesser.fi, -1), clam(if (l.se < 0) return r; if (r.se < 0) return l; return Lesser.se(l.fi, r.fi) ? l : r;)); segt.set(x, mp(Add.fi, x)); P<T, ll> now; while ((now = segt.que(0, vSize - 1)).se >= 0) { ans.se[now.se].fi = segt[now.se].fi; ans.fi = Add.se(ans.fi, ans.se[now.se].fi); segt.set(now.se, mp(Lesser.fi, -2)); ROR(adj[now.se], i) { if (segt[i.se].se == -2) continue; if (segt[i.se].se == -1) { segt.set(i.se, i); ans.se[i.se].se = {now.se}; continue; } if (Lesser.se(i.fi, segt[i.se].fi)) { segt.set(i.se, i); ans.se[i.se].se = {now.se}; continue; } if (Equal.se(i.fi, segt[i.se].fi)) { ans.se[i.se].se.pb(now.se); continue; } } } return ans; } }; template <class T> struct Sum { public: V<T> v, s; ll size; ActPair(T) Add; ActPair(T) Sub; Sum(V<T> v, ActPair(T) Add = ADD, ActPair(T) Sub = SUB) : v(v), size(v.sz), Add(Add), Sub(Sub) { Init(); Calc(); } void Init() { s.asn(size + 1, Add.fi); } void Calc() { REP(i, size) s[i + 1] = Add.se(s[i], v[i]); } T operator()(ll x) { if (x < -1) x = -1; if (x > size - 1) x = size - 1; return s[x + 1]; } T operator()(ll l, ll r) { if (l < 0) l = 0; if (r >= size) r = size - 1; if (l > r) return Add.fi; return Sub.se(s[r + 1], s[l]); } }; using sumll = Sum<ll>; template <class T> struct Sum2 { public: V<V<T>> v, s; ll RowSize, ColumnSize; ActPair(T) Add; ActPair(T) Sub; Sum2(V<V<T>> v, ActPair(T) Add = ADD, ActPair(T) Sub = SUB) : v(v), RowSize(v.sz), ColumnSize(v.sz ? v[0].sz : 0), Add(Add), Sub(Sub) { Init(); Calc(); } void Init() { s.asn(RowSize + 1, V<T>(ColumnSize + 1, Add.fi)); } void Calc() { REP1(r, RowSize) { REP1(c, ColumnSize) { // s[r][c] = Sub.se(Add.se(Add.se(v[r - 1][c - //1], operator()(r - 1, c - 2)), operator()(r - 2, c - 1)), operator()(r //- 2, c - 2)); s[r][c] = Add.se(s[r][c - 1], v[r - 1][c - 1]); } } REP1(r, RowSize) { REP1(c, ColumnSize) { s[r][c] = Add.se(s[r - 1][c], s[r][c]); } } } T operator()(ll r, ll c) { if (r < -1) r = -1; if (c < -1) c = -1; if (r > RowSize - 1) r = RowSize - 1; if (c > ColumnSize - 1) c = ColumnSize - 1; return s[r + 1][c + 1]; } T operator()(ll r1, ll c1, ll r2, ll c2) { if (r1 < 0) r1 = 0; if (c1 < 0) c1 = 0; if (r2 >= RowSize) r2 = RowSize - 1; if (c2 >= ColumnSize) c2 = ColumnSize - 1; if (r1 > r2) return Add.fi; if (c1 > c2) return Add.fi; return Sub.se(Add.se(s[r2 + 1][c2 + 1], s[r1][c1]), Add.se(s[r2 + 1][c1], s[r1][c2 + 1])); } }; using sumll2 = Sum2<ll>; template <class T> struct Point2 { public: V<V<T>> v; ll h, w; Point2() : h(0), w(0) {} Point2(ll h, ll w) : h(h), w(w) { asn(h, w); } Point2(ll h, ll w, T val) : h(h), w(w) { asn(h, w, val); } void assign(ll h, ll w) { v.asn(h, V<T>(w)); } void assign(ll h, ll w, ll val) { v.asn(h, V<T>(w, val)); } T &operator()(ll h, ll w) { return v[h][w]; } T &operator()(pl p) { return v[p.fi][p.se]; } }; template <class T> using P2 = Point2<T>; template <ll Mod> struct Modll { public: ll v; Modll() : v(0) {} Modll(ll _v) { set(_v % Mod + Mod); } Modll &set(ll _v) { v = (_v < Mod) ? _v : (_v - Mod); return *this; } Modll pow(ll n) const { Modll x = *this, ans = 1; while (n) { if (n & 1) ans *= x; x *= x; n >>= 1; } return ans; } Modll inverse() const { return (*this).pow(Mod - 2); } Modll operator+(const Modll &m) const { return Modll().set(v + m.v); } Modll operator-(const Modll &m) const { return Modll().set(Mod + v - m.v); } Modll operator*(const Modll &m) const { return Modll().set((ull(v) * m.v) % Mod); } Modll operator/(const Modll &m) const { return *this * m.inv; } Modll &operator+=(const Modll &m) { return *this = *this + m; } Modll &operator-=(const Modll &m) { return *this = *this - m; } Modll &operator*=(const Modll &m) { return *this = *this * m; } Modll &operator/=(const Modll &m) { return *this = *this / m; } Modll operator-() const { return Modll(0) - *this; } explicit operator bool() const { return v != 0; } friend istream &operator>>(istream &in, Modll &m) { return in >> m.v; } friend ostream &operator<<(ostream &out, const Modll &m) { return out << m.v; } }; using mll = Modll<MOD>; using vmll = V<mll>; using vvmll = V<vmll>; using vvvmll = V<vvmll>; vmll MFactMemo(2, 1); vmll MIFactMemo(2, 1); mll mFact(ll n) { if (MFactMemo.sz <= n) { ll oldsize = MFactMemo.sz; MFactMemo.res(n + 1, 1); FOR(i, oldsize, n) MFactMemo[i] = MFactMemo[i - 1] * i; } return MFactMemo[n]; } mll miFact(ll n) { if (MIFactMemo.sz <= n) { ll oldsize = MIFactMemo.sz; MIFactMemo.res(n + 1, 1); MIFactMemo.bk = mFact(n).inv; rFOR(i, oldsize + 1, n) MIFactMemo[i - 1] = MIFactMemo[i] * i; } return MIFactMemo[n]; } mll mComb(ll n, ll k) { if (n < 0 || k < 0 || n < k) return 0; return mFact(n) * miFact(k) * miFact(n - k); } ll LIS(vll v, ll m = 0) { if (v.sz > 0) { ll ans = 0; vll dp(v.sz, INF); FOR(i, 0, v.sz - 1) { dp[m ? UPB(dp, v[i]) : LOWB(dp, v[i])] = v[i]; } FOR(i, 0, v.sz - 1) { if (dp[i] == INF) break; ans++; } return ans; } else { return 0; } } ll Bsrch(function<bool(ll x)> f, ll mi, ll ma) { ll ng = mi - 1, ok = ma, mid; while (ok - ng > 1) { mid = (ng + ok) / 2; (f(mid) ? ok : ng) = mid; } return ok; } template <class T> V<V<T>> MultiMatrix(V<V<T>> A, V<V<T>> B, ActPair(T) Mul = MUL, ActPair(T) Add = ADD) { V<V<T>> ans; ll ii = A.sz; if (!ii) return ans; ll jj = A[0].sz; if (!jj) return ans; ll jj2 = B.sz; if (!jj2) return ans; if (jj != jj2) return ans; ll kk = B[0].sz; if (!kk) return ans; ans.asn(ii, V<T>(kk, 0)); REP(i, ii) { REP(k, kk) { REP(j, jj) { ans[i][k] = Add.se(ans[i][k], Mul.se(A[i][j], B[j][k])); } } } return ans; } vvll CombMemo(1000, vll(1000, -1)); ll Comb(ll n, ll k) { if ((n < 0) || (k < 0)) return 0; if (CombMemo[n][k] == -1) { if (n < k) CombMemo[n][k] = 0; else { if (n == 0) CombMemo[n][k] = 1; else if (k == 0) CombMemo[n][k] = 1; else if (n == k) CombMemo[n][k] = 1; else CombMemo[n][k] = Comb(n - 1, k - 1) + Comb(n - 1, k); } } return CombMemo[n][k]; } template <class T> map<T, ll> Dict(V<T> v) { map<T, ll> m; if (!v.sz) return m; SORT(v); UNIQUE(v); REP(i, v.sz) { m[v[i]] = i; } return m; } template <class T> vll Cmprs(V<T> v) { auto m = Dict(v); vll ans(v.sz); REP(i, v.sz) { ans[i] = m[v[i]]; } return ans; } template <class T> vll PCmprs(V<T> v) { if (v.sz == 0) return V<T>(); vll tmp(v.sz); vll ans(v.sz); IOTA(tmp, 0); IOTA(ans, 0); sort(tmp.bgn, tmp.en, clam(return v[l] < v[r];)); sort(ans.bgn, ans.en, clam(return tmp[l] < tmp[r];)); return ans; } ll BblCnt(vll rv) { vll v = PCmprs(rv); SegT<ll> b(v.sz, 0); ll ans = 0; REP(i, v.sz) { ans += (i - b.que(0, v[i])); b.add(v[i], 1); } return ans; } template <class T> auto ven(T val) { return val; } template <> auto ven<int>(int val) { return (ll)val; } template <class T, class... Args> auto ven(T val, Args... args) { auto tmp = ven(args...); return V<decltype(tmp)>(val, tmp); } template <class T> void zind(T &v) { v--; } template <class T> void zind(V<T> &v) { ROR(v, i) zind(i); } template <class T, class... Args> void zind(T &v, Args &...args) { zind(v); zind(args...); } void Solve(); signed main() { cin.tie(0); ios::sync_with_stdio(false); cout << setprecision(20) << fixed; Solve(); } void Solve() { li(n); vlc(n, a, b); vpl c(n); REP(i, n) c[i] = mp(a[i] + b[i], i); sort(c.bgn, c.en, lam(return l.fi > r.fi;)); sal(c); ll t = 0, u = 0, uu = 0; REP(i, n) { if (i % 2 == 0) u += a[c[i].se]; if (i % 2 == 1) uu += b[c[i].se]; } /* while (t < n) { u += a[c[t].se]; t++; if (t == n) break; u -= b[c[t].se]; t++; }*/ sal(u - uu); }
#include <bits/stdc++.h> using namespace std; template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; template <class T> using VVV = V<VV<T>>; template <class S, class T> using P = pair<S, T>; template <class S, class T, class U> using TP = tuple<S, T, U>; using ll = long long; using ull = unsigned long long; using dbl = double; using str = string; using vll = V<ll>; using vvll = V<vll>; using vvvll = V<vvll>; using pl = P<ll, ll>; using tl = TP<ll, ll, ll>; using vpl = V<pl>; using vvpl = V<vpl>; using vtl = V<tl>; using vvtl = V<vtl>; using vs = V<str>; using vvs = V<vs>; using vd = V<dbl>; using vvd = V<vd>; using qll = queue<ll>; using qpl = queue<pl>; using stll = stack<ll>; using stpl = stack<pl>; using mapll = map<ll, ll>; using setll = set<ll>; using pqll = priority_queue<ll>; //#define int ll #define fi first #define se second #define mp make_pair #define mt make_tuple #define pb push_back #define pob pop_back() #define pf push_front #define pof pop_front() #define sz size() #define bgn begin() #define en end() #define asn assign #define emp empty() #define fr front() #define bk back() #define clr clear() #define ins insert #define ers erase #define res resize #define tp top() #define p_q priority_queue #define inv inverse() #define FOR(i, a, b) for (ll i = (a); i <= (ll)(b); i++) #define rFOR(i, a, b) for (ll i = (b); i >= (ll)(a); i--) #define REP(i, a) FOR((i), 0, (ll)(a)-1) #define REP0(i, a) FOR((i), 0, (ll)(a)) #define REP1(i, a) FOR((i), 1, (ll)(a)) #define rREP(i, a) rFOR((i), 0, (ll)(a)-1) #define rREP0(i, a) rFOR((i), 0, (ll)(a)) #define rREP1(i, a) rFOR((i), 1, (ll)(a)) #define ROR(v, i) for (auto &(i) : (v)) #define IOTA(a, n) iota((a).bgn, (a).en, (n)) #define SORT(a) sort((a).bgn, (a).en) #define rSORT(a) sort((a).rbegin(), (a).rend()) #define UNIQUE(a) (a).erase(unique((a).bgn, (a).en), (a).en) #define PREVP(a) prev_permutation((a).bgn, (a).en) #define NEXTP(a) next_permutation((a).bgn, (a).en) #define BINS(a, b) binary_search((a).bgn, (a).en, (b)) #define LOWB(a, b) (lower_bound((a).bgn, (a).en, (b)) - (a).bgn) #define UPB(a, b) (upper_bound((a).bgn, (a).en, (b)) - (a).bgn) #define CNT(a, b) count((a).bgn, (a).en, b) #define SUM(a) accumulate((a).bgn, (a).en, 0) #define REV(a) reverse((a).bgn, (a).en) #define REGS(a, b) regex_search((a), regex(b)) #define REGM(a, b) regex_match((a), regex(b)) #define yn(a) cout << ((a) ? "yes" : "no") << "\n"; #define Yn(a) cout << ((a) ? "Yes" : "No") << "\n"; #define YN(a) cout << ((a) ? "YES" : "NO") << "\n"; #define imp(a) cout << ((a) ? "possible" : "impossible") << "\n"; #define Imp(a) cout << ((a) ? "Possible" : "Impossible") << "\n"; #define IMP(a) cout << ((a) ? "POSSIBLE" : "IMPOSSIBLE") << "\n"; #define fs(a) cout << ((a) ? "second" : "first") << "\n"; #define Fs(a) cout << ((a) ? "Second" : "First") << "\n"; #define FS(a) cout << ((a) ? "SECOND" : "FIRST") << "\n"; //#define say(a) cout <<(a); //#define sal(a) cout <<(a)<<"\n"; #define sak cout << "\n"; #define sas cout << " "; #define sat cout << "\t"; #define dbg(a) cerr << (#a) << ": " << (a) << "\n"; #define dbgs(...) \ dal(#__VA_ARGS__); \ dal(__VA_ARGS__); #define c2l(a) ((ll)(a - 48)) #define a2l(a) ((ll)(a - 97)) #define A2l(a) ((ll)(a - 65)) #define l2c(a) ((char)(a + 48)) #define l2a(a) ((char)(a + 97)) #define l2A(a) ((char)(a + 65)) #define DigN2(a) ((llabs(a) == 0) ? (1) : ((ll)(log2(double(llabs(a)))) + 1)) #define DigN10(a) ((llabs(a) == 0) ? (1) : ((ll)(log10(double(llabs(a)))) + 1)) #define Dig2(a, b) (((a) >> (b)) & 1) #define Dig10(a, b) (ll)(((a) / ((ll)(pow(10.0, (double)(b))))) % 10) #define Pow2(a) ((ll)(1) << (a)) #define Pow10(a) ((ll)(pow(10.0, double(a)))) #define LSB(a) ((a) & (-(a))) /*#define llin(a) ll (a);cin >>(a); #define llin2(a,b) ll (a),(b);cin >>(a)>>(b); #define llin3(a,b,c) ll (a),(b),(c);cin >>(a)>>(b)>>(c); #define stin(a) string (a);cin >>(a);*/ #define vin(v) \ ROR((v), (i)) { cin >> (i); }; #define vllin(v, N) \ vll(v)((N)); \ vin(v); #define vllin2(a, b, N) \ vll(a)(N), (b)(N); \ REP(i, N) { cin >> (a)[i] >> (b)[i]; }; #define vsin(v, N) \ vs(v)((N)); \ vin(v); #define rdn(a, b) ((a) / (b)) #define rou(a, b) \ ((((double(a) / double(b)) - ((a) / (b))) < 0.5) ? ((a) / (b)) \ : (((a) / (b)) + 1)) #define rup(a, b) ((((a) % (b)) == 0) ? ((a) / (b)) : (((a) / (b)) + 1)) #define powll(a, b) (ll)(pow((double)(a), (double)(b))) #define Triangle(x1, y1, x2, y2, x3, y3) \ (((x1) - (x2)) * ((y1) - (y3)) - ((x1) - (x3)) * ((y1) - (y2))) #define lam(lr) ([](auto l, auto r) { lr }) #define elam(lr) ([=](auto l, auto r) { lr }) #define clam(lr) ([&](auto l, auto r) { lr }) #define min(...) Operation(MIN, __VA_ARGS__) #define max(...) Operation(MAX, __VA_ARGS__) #define gcd(...) Operation(GCD, __VA_ARGS__) #define lcm(...) Operation(LCM, __VA_ARGS__) #define vmin(...) VOperation(MIN, __VA_ARGS__) #define vmax(...) VOperation(MAX, __VA_ARGS__) #define vgcd(...) VOperation(GCD, __VA_ARGS__) #define vlcm(...) VOperation(LCM, __VA_ARGS__) #define vsum(...) VOperation(ADD, __VA_ARGS__) #define vpro(...) VOperation(MUL, __VA_ARGS__) #define emin(a, ...) ((a) = min((a), __VA_ARGS__)) #define emax(a, ...) ((a) = max((a), __VA_ARGS__)) #define egcd(a, ...) ((a) = gcd((a), __VA_ARGS__)) #define elcm(a, ...) ((a) = lcm((a), __VA_ARGS__)) #define ActPair(T) P<T, function<T(T, T)>> #define BoolPair(T) P<T, function<bool(T, T)>> #define ope Operation #define vope VOperation #define svll SumV<ll> #define svvll SumV2<ll> #define li(...) \ ll __VA_ARGS__; \ Input(__VA_ARGS__); #define si(...) \ str __VA_ARGS__; \ Input(__VA_ARGS__); //#define vli(size, ...) vll __VA_ARGS__;vInitInput(size,__VA_ARGS__); #define vlr(size, ...) \ vll __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vlc(size, ...) \ vll __VA_ARGS__; \ vInitInputC(size, __VA_ARGS__); #define vli(size, ...) \ vll __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vsr(size, ...) \ vs __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vsc(size, ...) \ vs __VA_ARGS__; \ vInitInputC(size, __VA_ARGS__); #define vsi(size, ...) \ vs __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vli2(rowSize, columnSize, ...) \ vvll __VA_ARGS__; \ vInitInput2(rowSize, columnSize, __VA_ARGS__); #define vplr(size, ...) \ vpl __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vplc(size, ...) \ vpl __VA_ARGS__; \ vInitInputC(size, __VA_ARGS__); #define vpli(size, ...) \ vpl __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); const ll MOD = 1e9 + 7; // const ll MOD = 998244353; // const ll MOD = 924844033; // const ll MOD = 9007199254740881; const ll INF = 1LL << 60; // 1.15e18 const double PI = acos(-1.0); const vll DX = {0, -1, 0, 1, 0, -1, 1, 1, -1}; const vll DY = {0, 0, -1, 0, 1, -1, -1, 1, 1}; const str alp = "abcdefghijklmnopqrstuvwxyz"; const str ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; template <class S, class T> istream &operator>>(istream &in, P<S, T> &p) { return in >> p.fi >> p.se; } template <class T> istream &operator>>(istream &in, V<T> &v) { REP(i, v.sz) in >> v[i]; return in; } void Input() {} template <class Var, class... Args> void Input(Var &var, Args &...args) { cin >> var; Input(args...); } void vInit(ll size) {} template <class T, class... Args> void vInit(ll size, V<T> &v, Args &...args) { v.res(size); vInit(size, args...); } void vInput(ll size) {} template <class T, class... Args> void vInput(ll size, V<T> &v, Args &...args) { REP(i, size) cin >> v[i]; vInput(size, args...); } void vInputR(ll size) {} template <class T, class... Args> void vInputR(ll size, V<T> &v, Args &...args) { REP(i, size) cin >> v[i]; vInputR(size, args...); } void vInputNumC(ll num) {} template <class T, class... Args> void vInputNumC(ll num, V<T> &v, Args &...args) { cin >> v[num]; vInputNumC(num, args...); } void vInputC(ll size) {} template <class... Args> void vInputC(ll size, Args &...args) { REP(i, size) vInputNumC(i, args...); } void vInitInputR(ll size) {} template <class... Args> void vInitInputR(ll size, Args &...args) { vInit(size, args...); vInputR(size, args...); } void vInitInputC(ll size) {} template <class... Args> void vInitInputC(ll size, Args &...args) { vInit(size, args...); vInputC(size, args...); } void vInit2(ll rowSize, ll columnSize) {} template <class T, class... Args> void vInit2(ll rowSize, ll columnSize, V<V<T>> &v, Args &...args) { v.asn(rowSize, V<T>(columnSize)); vInit2(rowSize, columnSize, args...); } void vInput2(ll rowSize, ll columnSize) {} template <class T, class... Args> void vInput2(ll rowSize, ll columnSize, V<V<T>> &v, Args &...args) { REP(r, rowSize) { REP(c, columnSize) { cin >> v[r][c]; } } vInput2(rowSize, columnSize, args...); } void vInitInput2(ll rowSize, ll columnSize) {} template <class... Args> void vInitInput2(ll rowSize, ll columnSize, Args &...args) { vInit2(rowSize, columnSize, args...); vInput2(rowSize, columnSize, args...); } template <class S, class T> ostream &operator<<(ostream &out, const P<S, T> &p) { return out << "[" << p.fi << ", " << p.se << "]"; } template <class T> ostream &operator<<(ostream &out, V<T> &v) { if (v.emp) return out << "{}"; else { auto itr = v.bgn; out << "{" << *itr; itr++; while (itr != v.en) { out << ", " << *itr; itr++; } out << "}"; return out; } } template <class S, class T> ostream &operator<<(ostream &out, const map<S, T> &m) { if (m.emp) return out << "<[]>"; else { auto itr = m.bgn; out << "< [" << (itr->fi) << ": " << (itr->se); itr++; while (itr != m.en) { out << "], [" << (itr->fi) << ": " << (itr->se); itr++; } out << "] >"; return out; } } template <class T> ostream &operator<<(ostream &out, const set<T> &s) { if (s.emp) return out << "<>"; else { auto itr = s.bgn; out << "<" << *itr; itr++; while (itr != s.en) { out << ", " << *itr; itr++; } out << ">"; return out; } } void say() {} template <class T> void say(T t) { cout << t; } template <class Head, class... Body> void say(Head head, Body... body) { cout << head << " "; say(body...); } void sal() { cout << "\n"; } template <class... Args> void sal(Args... args) { say(args...); cout << "\n"; } void day() {} template <class T> void day(T t) { cerr << t; } template <class Head, class... Body> void day(Head head, Body... body) { cerr << head << " "; day(body...); } void dal() { cerr << "\n"; } template <class... Args> void dal(Args... args) { day(args...); cerr << "\n"; } void salv() {} template <class T> void salv(V<T> v) { if (v.emp) sal(); else { auto itr = v.bgn; say(*itr); itr++; while (itr != v.en) { sas; say(*itr); itr++; } sak; } } template <class T> void salv(V<V<T>> v) { if (v.emp) sal(); else { ROR(v, i) salv(i); } } template <class T, class... Args> void salv(T v, Args... args) { salv(v); salv(args...); } template <class L, class R> auto Gcd(L l, R r) -> decltype(l + r) { if (l < r) swap(l, r); return r ? Gcd(r, l % r) : l; } template <class L, class R> auto Lcm(L l, R r) { if (!l || !r) return 0; return l / Gcd(l, r) * r; } auto LES = mp(INF, lam(return l < r;)); auto GRT = mp(-INF, lam(return l > r;)); auto EQ = mp(0, lam(return l == r;)); auto ADD = mp(0, lam(return l + r;)); auto SUB = mp(0, lam(return l - r;)); auto MUL = mp(1, lam(return l * r;)); auto DIV = mp(1, lam(return l / r;)); auto MDL = mp(1, lam(return l % r;)); auto XOR = mp(0, lam(return l ^ r;)); auto OR = mp(0, lam(return l | r;)); auto AND = mp(((ll)(1) << 63) - 1, lam(return l & r;)); auto MIN = mp(INF, lam(return (l < r) ? l : r;)); auto MAX = mp(-INF, lam(return (l > r) ? l : r;)); auto GCD = mp(0, lam(return Gcd(l, r);)); auto LCM = mp(1, lam(return Lcm(l, r);)); /* auto ADD = mp(0, [](auto l, auto r) { return l + r; }); auto SUB = mp(1, [](auto l, auto r) { return l - r; }); auto MUL = mp(1, [](auto l, auto r) { return l * r; }); auto DIV = mp(0, [](auto l, auto r) { return l / r; }); auto MDL = mp(0, [](auto l, auto r) { return l % r; }); auto XOR = mp(0, [](auto l, auto r) { return l ^ r; }); auto OR = mp(0, [](auto l, auto r) { return l | r; }); auto AND = mp(((ll)(1) << 63) - 1, [](auto l, auto r) { return l & r; }); auto MIN = mp(INF, [](auto l, auto r) { return (l < r) ? l : r; }); auto MAX = mp(-INF, [](auto l, auto r) { return (l > r) ? l : r; }); auto GCD = mp(0, [](auto l, auto r) { return gcd(l, r); }); auto LCM = mp(1, [](auto l, auto r) { return lcm(l, r); }); */ template <class OperationType> auto Operation(OperationType A) { return A.fi; } template <class OperationType, class T> auto Operation(OperationType A, T x) { return x; } template <class OperationType, class T, class... Args> auto Operation(OperationType A, T x, Args... args) { auto tmp = Operation(A, args...); return A.se(x, tmp); } template <class OperationType> auto VOperation(OperationType A) { return A.fi; } template <class OperationType, class T> auto VOperation(OperationType A, T x) { return x; } template <class OperationType, class T> auto VOperation(OperationType A, V<T> x) { T tmp = A.fi; ROR(x, i) tmp = A.se(tmp, i); return tmp; } template <class OperationType, class T> auto VOperation(OperationType A, V<V<T>> x) { T tmp = A.fi; ROR(x, i) ROR(i, j) tmp = A.se(tmp, j); return tmp; } template <class OperationType, class T> auto VOperation(OperationType A, V<V<V<T>>> x) { T tmp = A.fi; ROR(x, i) ROR(i, j) ROR(j, k) tmp = A.se(tmp, k); return tmp; } template <class OperationType, class T> auto VOperation(OperationType A, V<V<V<V<T>>>> x) { T tmp = A.fi; ROR(x, i) ROR(i, j) ROR(j, k) ROR(k, l) tmp = A.se(tmp, l); return tmp; } template <class OperationType, class T, class... Args> auto VOperation(OperationType A, T x, Args... args) { auto xResult = VOperation(A, x); auto tmp = VOperation(A, args...); return A.se(xResult, tmp); } ll Bset(ll a, ll b, ll c) { if (c) a |= b; else a &= ~b; return a; } struct UFT { public: ll tsize; ll mode; vll par; vll rank; UFT() {} UFT(const UFT &uft) {} UFT(ll tsizeget, ll modeget = 0) { tsize = tsizeget; mode = modeget; par.asn(tsize, -1); if (!mode) rank.res(tsize, 0); } ll root(ll x) { return par[x] < 0 ? x : par[x] = root(par[x]); } bool isRoot(ll x) { return x == root(x); } bool same(ll x, ll y) { return root(x) == root(y); } void merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) return; if (mode) { par[x] += par[y]; par[y] = x; } else { if (rank[x] < rank[y]) { par[y] += par[x]; par[x] = y; } else { par[x] += par[y]; par[y] = x; if (rank[x] == rank[y]) rank[x]++; } } } ll size(ll x) { return -par[root(x)]; } }; struct pUFT { public: ll tsize; ll now; vll par; vll rank; vll mtime; vvll sizepi; vvll sizepv; pUFT() {} pUFT(const pUFT &puft) {} pUFT(ll tsizeget) { tsize = tsizeget; now = 0; par.asn(tsize, -1); rank.asn(tsize, 0); mtime.asn(tsize, INF); sizepi.asn(tsize, {0}); sizepv.asn(tsize, {1}); } ll root(ll x, ll t) { return (mtime[x] > t) ? x : root(par[x], t); } bool same(ll x, ll y, ll t) { return root(x, t) == root(y, t); } ll merge(ll x, ll y) { now++; x = root(x, now); y = root(y, now); if (x != y) { if (rank[x] < rank[y]) { par[y] += par[x]; sizepi[y].pb(now); sizepv[y].pb(-par[y]); par[x] = y; mtime[x] = now; } else { par[x] += par[y]; sizepi[x].pb(now); sizepv[x].pb(-par[x]); par[y] = x; mtime[y] = now; if (rank[x] == rank[y]) rank[x]++; } } return now; } ll size(ll x, ll t) { x = root(x, t); return sizepv[x][UPB(sizepi[x], t) - 1]; } }; struct wUFT { public: ll tsize; ll mode; vll par; vll rank; vll dweight; wUFT() {} wUFT(const wUFT &wuft) {} wUFT(ll tsizeget, ll modeget = 0) { tsize = tsizeget; mode = modeget; par.asn(tsize, -1); if (!mode) rank.res(tsize, 0); dweight.asn(tsize, 0); } ll root(ll x) { if (par[x] < 0) return x; else { ll r = root(par[x]); dweight[x] += dweight[par[x]]; return par[x] = r; } } ll weight(ll x) { root(x); return dweight[x]; } ll diff(ll x, ll y) { return weight(y) - weight(x); } bool isRoot(ll x) { return x == root(x); } bool same(ll x, ll y) { return root(x) == root(y); } void merge(ll x, ll y, ll w) { w += weight(x); w -= weight(y); x = root(x); y = root(y); if (x == y) return; if (mode) { par[x] += par[y]; par[y] = x; } else { if (rank[x] < rank[y]) { par[y] += par[x]; par[x] = y; dweight[x] = -w; } else { par[x] += par[y]; par[y] = x; if (rank[x] == rank[y]) rank[x]++; dweight[y] = w; } } } ll size(ll x) { return -par[root(x)]; } }; template <typename valtype> class SegT { public: ll size; vector<valtype> v; valtype initv; function<valtype(valtype x, valtype y)> calc; SegT() {} SegT(const SegT &segt) {} SegT(ll sizeget, ll modeget = 0) { sizeset(sizeget); modeset(modeget); init(); } SegT(vector<valtype> cpyvec, ll modeget = 0) { sizeset(cpyvec.sz); modeset(modeget); init(); copy(cpyvec); } SegT(ll sizeget, valtype initvget, function<valtype(valtype x, valtype y)> calcget) { sizeset(sizeget); initv = initvget; calc = calcget; init(); } SegT(vector<valtype> cpyvec, valtype initvget, function<valtype(valtype x, valtype y)> calcget) { sizeset(cpyvec.sz); initv = initvget; calc = calcget; init(); copy(cpyvec); } void sizeset(ll rsize) { size = DigN2(rsize); if (rsize == Pow2(size - 1)) size--; return; } void modeset(ll mode) { switch (mode) { case 0: initv = 0; calc = [](valtype x, valtype y) { return x + y; }; break; case 1: initv = INF; calc = [](valtype x, valtype y) { return min(x, y); }; break; case 2: initv = -INF; calc = [](valtype x, valtype y) { return max(x, y); }; break; } return; } void init() { v.asn(Pow2(size + 1) - 1, initv); } void copy(vector<valtype> cpyvec) { REP(i, min(cpyvec.sz, Pow2(size))) set(i, cpyvec[i]); } ll i2v(ll i) const { if (i < 0 || i >= Pow2(size)) return -1; return Pow2(size) + i - 1; } ll top(ll i) const { if (i == 0) return -1; return (i - 1) / 2; } pl bot(ll i) const { if (i + 1 >= Pow2(size)) return mp(-1, -1); return mp(2 * i + 1, 2 * i + 2); } void set(ll i, valtype x) { i = i2v(i); v[i] = x; while (i > 0) { i = top(i); v[i] = calc(v[bot(i).fi], v[bot(i).se]); } return; } void add(ll i, valtype x) { set(i, v[i2v(i)] + x); return; } valtype operator[](const ll &i) const { return v[i2v(i)]; } // valtype que(ll a = 0, ll b = Pow2(size) - 1) { valtype que(ll a, ll b) { if (a == b) return v[i2v(a)]; if (a > b) return initv; // swap(a, b); valtype ans = initv; ll ai = i2v(a); ll bi = i2v(b); FOR(i, 1, size + 1) { if (a > b) break; if (a % Pow2(i)) { ans = calc(ans, v[ai]); a += Pow2(i - 1); ai = top(ai) + 1; } else { ai = top(ai); } if (a > b) break; if ((b + 1) % Pow2(i)) { ans = calc(ans, v[bi]); b -= Pow2(i - 1); bi = top(bi) - 1; } else { bi = top(bi); } if (a > b) break; } return ans; } valtype que(ll b) { return que(0, b); } valtype que() { return que(0, Pow2(size) - 1); } }; /*template <class Type> class DP { public: vector<Type> v; Type initv; vll size, block; DP() {} DP(const DP &dp) {} template<class... Args> DP(Args... args) { block.asn(1, 1); Initialize(args...); } void Initialize(Type initv_) { initv = initv_; v.asn(block.bk, initv); } template<class... Args> void Initialize(ll val, Args... args) { size.pb(val); block.pb(block.bk*val); Initialize(args...); } };*/ pl Bezout(ll a, ll b) { if (b != 0) { pl xy; xy = Bezout(b, a % b); return mp(xy.se, xy.fi - ((a / b) * xy.se)); } else { return mp(1, 0); } } pl Bez(ll a, ll b, ll c) { pl xy; ll x, y, z, gc; xy = Bezout(a, b); gc = gcd(a, b); if (c % gc != 0) return mp(-1, -1); x = xy.fi * (c / gc); y = xy.se * (c / gc); if (x < 0) z = rup(-x, (b / gc)); if (x >= 0) z = -x / (b / gc); x += z * (b / gc); y -= z * (a / gc); return mp(x, y); } ll DigS10(ll n) { ll ans = 0; while (1) { ans += n % 10; n /= 10; if (!n) break; } return ans; } ll isP(ll n) { if (n <= 1) return 0; FOR(i, 2, (ll)sqrt(n) + 1) { if (n % i == 0) return 0; } return 1; } ll Tot(ll n) { if (n <= 0) return 0; ll ans = n, x = 2; while (x * x <= n) { if (n % x == 0) { ans -= ans / x; while (n % x == 0) n /= x; } x++; } if (n > 1) ans -= ans / n; return ans; } template <class T> struct Graph { public: ll vSize; ll eMode; ll mapMode; ActPair(T) Add; BoolPair(T) Lesser; BoolPair(T) Equal; V<V<P<T, ll>>> adj; map<pl, T> len; Graph(ll vSize, ll eMode = 0, ll mapMode = 0, ActPair(T) Add = ADD, BoolPair(T) Lesser = LES, BoolPair(T) Equal = EQ) : vSize(vSize), eMode(eMode), mapMode(mapMode), Add(Add), Lesser(Lesser), Equal(Equal) { Init(); } void Init() { adj.asn(vSize, V<P<T, ll>>()); } void AddE(ll x, ll y, T cost) { iAddE(x, y, cost); if (!eMode) iAddE(y, x, cost); } void iAddE(ll x, ll y, T cost) { adj[x].pb(mp(cost, y)); if (mapMode) len[mp(x, y)] = cost; } P<bool, T> getE(ll x, ll y) { if (!len.count(mp(x, y))) return mp(false, Lesser.fi); return mp(true, len[mp(x, y)]); } V<T> Dijk(ll x) { V<T> ans(vSize, Lesser.fi); if (x < 0 || x >= vSize) return ans; SegT<P<T, ll>> segt(vSize, mp(Lesser.fi, -1), clam(if (l.se < 0) return r; if (r.se < 0) return l; return Lesser.se(l.fi, r.fi) ? l : r;)); segt.set(x, mp(Add.fi, x)); P<T, ll> now; while ((now = segt.que(0, vSize - 1)).se >= 0) { ans[now.se] = segt[now.se].fi; segt.set(now.se, mp(Lesser.fi, -2)); ROR(adj[now.se], i) { if (segt[i.se].se == -2) continue; if (segt[i.se].se == -1) { segt.set(i.se, mp(Add.se(ans[now.se], i.fi), i.se)); continue; } if (Lesser.se(Add.se(ans[now.se], i.fi), segt[i.se].fi)) { segt.set(i.se, mp(Add.se(ans[now.se], i.fi), i.se)); continue; } } } return ans; } V<P<T, vll>> rDijk(ll x) { V<P<T, vll>> ans(vSize, mp(Lesser.fi, vll())); if (x < 0 || x >= vSize) return ans; SegT<P<T, ll>> segt(vSize, mp(Lesser.fi, -1), clam(if (l.se < 0) return r; if (r.se < 0) return l; return Lesser.se(l.fi, r.fi) ? l : r;)); segt.set(x, mp(Add.fi, x)); P<T, ll> now; while ((now = segt.que(0, vSize - 1)).se >= 0) { ans[now.se].fi = segt[now.se].fi; segt.set(now.se, mp(Lesser.fi, -2)); ROR(adj[now.se], i) { if (segt[i.se].se == -2) continue; if (segt[i.se].se == -1) { segt.set(i.se, mp(Add.se(ans[now.se].fi, i.fi), i.se)); ans[i.se].se = {now.se}; continue; } if (Lesser.se(Add.se(ans[now.se].fi, i.fi), segt[i.se].fi)) { segt.set(i.se, mp(Add.se(ans[now.se].fi, i.fi), i.se)); ans[i.se].se = {now.se}; continue; } if (Equal.se(Add.se(ans[now.se].fi, i.fi), segt[i.se].fi)) { ans[i.se].se.pb(now.se); continue; } } } return ans; } T Prim(ll x = 0) { T ans = Add.fi; if (x < 0 || x >= vSize) return ans; SegT<P<T, ll>> segt(vSize, mp(Lesser.fi, -1), clam(if (l.se < 0) return r; if (r.se < 0) return l; return Lesser.se(l.fi, r.fi) ? l : r;)); segt.set(x, mp(Add.fi, x)); P<T, ll> now; while ((now = segt.que(0, vSize - 1)).se >= 0) { ans = Add.se(ans, segt[now.se].fi); segt.set(now.se, mp(Lesser.fi, -2)); ROR(adj[now.se], i) { if (segt[i.se].se == -2) continue; if (segt[i.se].se == -1) { segt.set(i.se, i); continue; } if (Lesser.se(i.fi, segt[i.se].fi)) { segt.set(i.se, i); continue; } } } return ans; } P<T, V<P<T, vll>>> rPrim(ll x = 0) { P<T, V<P<T, vll>>> ans = mp(Add.fi, V<P<T, vll>>(vSize, mp(Lesser.fi, vll()))); if (x < 0 || x >= vSize) return ans; SegT<P<T, ll>> segt(vSize, mp(Lesser.fi, -1), clam(if (l.se < 0) return r; if (r.se < 0) return l; return Lesser.se(l.fi, r.fi) ? l : r;)); segt.set(x, mp(Add.fi, x)); P<T, ll> now; while ((now = segt.que(0, vSize - 1)).se >= 0) { ans.se[now.se].fi = segt[now.se].fi; ans.fi = Add.se(ans.fi, ans.se[now.se].fi); segt.set(now.se, mp(Lesser.fi, -2)); ROR(adj[now.se], i) { if (segt[i.se].se == -2) continue; if (segt[i.se].se == -1) { segt.set(i.se, i); ans.se[i.se].se = {now.se}; continue; } if (Lesser.se(i.fi, segt[i.se].fi)) { segt.set(i.se, i); ans.se[i.se].se = {now.se}; continue; } if (Equal.se(i.fi, segt[i.se].fi)) { ans.se[i.se].se.pb(now.se); continue; } } } return ans; } }; template <class T> struct Sum { public: V<T> v, s; ll size; ActPair(T) Add; ActPair(T) Sub; Sum(V<T> v, ActPair(T) Add = ADD, ActPair(T) Sub = SUB) : v(v), size(v.sz), Add(Add), Sub(Sub) { Init(); Calc(); } void Init() { s.asn(size + 1, Add.fi); } void Calc() { REP(i, size) s[i + 1] = Add.se(s[i], v[i]); } T operator()(ll x) { if (x < -1) x = -1; if (x > size - 1) x = size - 1; return s[x + 1]; } T operator()(ll l, ll r) { if (l < 0) l = 0; if (r >= size) r = size - 1; if (l > r) return Add.fi; return Sub.se(s[r + 1], s[l]); } }; using sumll = Sum<ll>; template <class T> struct Sum2 { public: V<V<T>> v, s; ll RowSize, ColumnSize; ActPair(T) Add; ActPair(T) Sub; Sum2(V<V<T>> v, ActPair(T) Add = ADD, ActPair(T) Sub = SUB) : v(v), RowSize(v.sz), ColumnSize(v.sz ? v[0].sz : 0), Add(Add), Sub(Sub) { Init(); Calc(); } void Init() { s.asn(RowSize + 1, V<T>(ColumnSize + 1, Add.fi)); } void Calc() { REP1(r, RowSize) { REP1(c, ColumnSize) { // s[r][c] = Sub.se(Add.se(Add.se(v[r - 1][c - //1], operator()(r - 1, c - 2)), operator()(r - 2, c - 1)), operator()(r //- 2, c - 2)); s[r][c] = Add.se(s[r][c - 1], v[r - 1][c - 1]); } } REP1(r, RowSize) { REP1(c, ColumnSize) { s[r][c] = Add.se(s[r - 1][c], s[r][c]); } } } T operator()(ll r, ll c) { if (r < -1) r = -1; if (c < -1) c = -1; if (r > RowSize - 1) r = RowSize - 1; if (c > ColumnSize - 1) c = ColumnSize - 1; return s[r + 1][c + 1]; } T operator()(ll r1, ll c1, ll r2, ll c2) { if (r1 < 0) r1 = 0; if (c1 < 0) c1 = 0; if (r2 >= RowSize) r2 = RowSize - 1; if (c2 >= ColumnSize) c2 = ColumnSize - 1; if (r1 > r2) return Add.fi; if (c1 > c2) return Add.fi; return Sub.se(Add.se(s[r2 + 1][c2 + 1], s[r1][c1]), Add.se(s[r2 + 1][c1], s[r1][c2 + 1])); } }; using sumll2 = Sum2<ll>; template <class T> struct Point2 { public: V<V<T>> v; ll h, w; Point2() : h(0), w(0) {} Point2(ll h, ll w) : h(h), w(w) { asn(h, w); } Point2(ll h, ll w, T val) : h(h), w(w) { asn(h, w, val); } void assign(ll h, ll w) { v.asn(h, V<T>(w)); } void assign(ll h, ll w, ll val) { v.asn(h, V<T>(w, val)); } T &operator()(ll h, ll w) { return v[h][w]; } T &operator()(pl p) { return v[p.fi][p.se]; } }; template <class T> using P2 = Point2<T>; template <ll Mod> struct Modll { public: ll v; Modll() : v(0) {} Modll(ll _v) { set(_v % Mod + Mod); } Modll &set(ll _v) { v = (_v < Mod) ? _v : (_v - Mod); return *this; } Modll pow(ll n) const { Modll x = *this, ans = 1; while (n) { if (n & 1) ans *= x; x *= x; n >>= 1; } return ans; } Modll inverse() const { return (*this).pow(Mod - 2); } Modll operator+(const Modll &m) const { return Modll().set(v + m.v); } Modll operator-(const Modll &m) const { return Modll().set(Mod + v - m.v); } Modll operator*(const Modll &m) const { return Modll().set((ull(v) * m.v) % Mod); } Modll operator/(const Modll &m) const { return *this * m.inv; } Modll &operator+=(const Modll &m) { return *this = *this + m; } Modll &operator-=(const Modll &m) { return *this = *this - m; } Modll &operator*=(const Modll &m) { return *this = *this * m; } Modll &operator/=(const Modll &m) { return *this = *this / m; } Modll operator-() const { return Modll(0) - *this; } explicit operator bool() const { return v != 0; } friend istream &operator>>(istream &in, Modll &m) { return in >> m.v; } friend ostream &operator<<(ostream &out, const Modll &m) { return out << m.v; } }; using mll = Modll<MOD>; using vmll = V<mll>; using vvmll = V<vmll>; using vvvmll = V<vvmll>; vmll MFactMemo(2, 1); vmll MIFactMemo(2, 1); mll mFact(ll n) { if (MFactMemo.sz <= n) { ll oldsize = MFactMemo.sz; MFactMemo.res(n + 1, 1); FOR(i, oldsize, n) MFactMemo[i] = MFactMemo[i - 1] * i; } return MFactMemo[n]; } mll miFact(ll n) { if (MIFactMemo.sz <= n) { ll oldsize = MIFactMemo.sz; MIFactMemo.res(n + 1, 1); MIFactMemo.bk = mFact(n).inv; rFOR(i, oldsize + 1, n) MIFactMemo[i - 1] = MIFactMemo[i] * i; } return MIFactMemo[n]; } mll mComb(ll n, ll k) { if (n < 0 || k < 0 || n < k) return 0; return mFact(n) * miFact(k) * miFact(n - k); } ll LIS(vll v, ll m = 0) { if (v.sz > 0) { ll ans = 0; vll dp(v.sz, INF); FOR(i, 0, v.sz - 1) { dp[m ? UPB(dp, v[i]) : LOWB(dp, v[i])] = v[i]; } FOR(i, 0, v.sz - 1) { if (dp[i] == INF) break; ans++; } return ans; } else { return 0; } } ll Bsrch(function<bool(ll x)> f, ll mi, ll ma) { ll ng = mi - 1, ok = ma, mid; while (ok - ng > 1) { mid = (ng + ok) / 2; (f(mid) ? ok : ng) = mid; } return ok; } template <class T> V<V<T>> MultiMatrix(V<V<T>> A, V<V<T>> B, ActPair(T) Mul = MUL, ActPair(T) Add = ADD) { V<V<T>> ans; ll ii = A.sz; if (!ii) return ans; ll jj = A[0].sz; if (!jj) return ans; ll jj2 = B.sz; if (!jj2) return ans; if (jj != jj2) return ans; ll kk = B[0].sz; if (!kk) return ans; ans.asn(ii, V<T>(kk, 0)); REP(i, ii) { REP(k, kk) { REP(j, jj) { ans[i][k] = Add.se(ans[i][k], Mul.se(A[i][j], B[j][k])); } } } return ans; } vvll CombMemo(1000, vll(1000, -1)); ll Comb(ll n, ll k) { if ((n < 0) || (k < 0)) return 0; if (CombMemo[n][k] == -1) { if (n < k) CombMemo[n][k] = 0; else { if (n == 0) CombMemo[n][k] = 1; else if (k == 0) CombMemo[n][k] = 1; else if (n == k) CombMemo[n][k] = 1; else CombMemo[n][k] = Comb(n - 1, k - 1) + Comb(n - 1, k); } } return CombMemo[n][k]; } template <class T> map<T, ll> Dict(V<T> v) { map<T, ll> m; if (!v.sz) return m; SORT(v); UNIQUE(v); REP(i, v.sz) { m[v[i]] = i; } return m; } template <class T> vll Cmprs(V<T> v) { auto m = Dict(v); vll ans(v.sz); REP(i, v.sz) { ans[i] = m[v[i]]; } return ans; } template <class T> vll PCmprs(V<T> v) { if (v.sz == 0) return V<T>(); vll tmp(v.sz); vll ans(v.sz); IOTA(tmp, 0); IOTA(ans, 0); sort(tmp.bgn, tmp.en, clam(return v[l] < v[r];)); sort(ans.bgn, ans.en, clam(return tmp[l] < tmp[r];)); return ans; } ll BblCnt(vll rv) { vll v = PCmprs(rv); SegT<ll> b(v.sz, 0); ll ans = 0; REP(i, v.sz) { ans += (i - b.que(0, v[i])); b.add(v[i], 1); } return ans; } template <class T> auto ven(T val) { return val; } template <> auto ven<int>(int val) { return (ll)val; } template <class T, class... Args> auto ven(T val, Args... args) { auto tmp = ven(args...); return V<decltype(tmp)>(val, tmp); } template <class T> void zind(T &v) { v--; } template <class T> void zind(V<T> &v) { ROR(v, i) zind(i); } template <class T, class... Args> void zind(T &v, Args &...args) { zind(v); zind(args...); } void Solve(); signed main() { cin.tie(0); ios::sync_with_stdio(false); cout << setprecision(20) << fixed; Solve(); } void Solve() { li(n); vlc(n, a, b); vpl c(n); REP(i, n) c[i] = mp(a[i] + b[i], i); // SORT(c); sort(c.bgn, c.en, lam(return l.fi > r.fi;)); ll t = 0, u = 0, uu = 0; REP(i, n) { if (i % 2 == 0) u += a[c[i].se]; if (i % 2 == 1) uu += b[c[i].se]; } /* while (t < n) { u += a[c[t].se]; t++; if (t == n) break; u -= b[c[t].se]; t++; }*/ sal(u - uu); }
[ "call.remove" ]
941,758
941,759
u211681714
cpp
p03141
#include <bits/stdc++.h> using namespace std; template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; template <class T> using VVV = V<VV<T>>; template <class S, class T> using P = pair<S, T>; template <class S, class T, class U> using TP = tuple<S, T, U>; using ll = long long; using ull = unsigned long long; using dbl = double; using str = string; using vll = V<ll>; using vvll = V<vll>; using vvvll = V<vvll>; using pl = P<ll, ll>; using tl = TP<ll, ll, ll>; using vpl = V<pl>; using vvpl = V<vpl>; using vtl = V<tl>; using vvtl = V<vtl>; using vs = V<str>; using vvs = V<vs>; using vd = V<dbl>; using vvd = V<vd>; using qll = queue<ll>; using qpl = queue<pl>; using stll = stack<ll>; using stpl = stack<pl>; using mapll = map<ll, ll>; using setll = set<ll>; using pqll = priority_queue<ll>; //#define int ll #define fi first #define se second #define mp make_pair #define mt make_tuple #define pb push_back #define pob pop_back() #define pf push_front #define pof pop_front() #define sz size() #define bgn begin() #define en end() #define asn assign #define emp empty() #define fr front() #define bk back() #define clr clear() #define ins insert #define ers erase #define res resize #define tp top() #define p_q priority_queue #define inv inverse() #define FOR(i, a, b) for (ll i = (a); i <= (ll)(b); i++) #define rFOR(i, a, b) for (ll i = (b); i >= (ll)(a); i--) #define REP(i, a) FOR((i), 0, (ll)(a)-1) #define REP0(i, a) FOR((i), 0, (ll)(a)) #define REP1(i, a) FOR((i), 1, (ll)(a)) #define rREP(i, a) rFOR((i), 0, (ll)(a)-1) #define rREP0(i, a) rFOR((i), 0, (ll)(a)) #define rREP1(i, a) rFOR((i), 1, (ll)(a)) #define ROR(v, i) for (auto &(i) : (v)) #define IOTA(a, n) iota((a).bgn, (a).en, (n)) #define SORT(a) sort((a).bgn, (a).en) #define rSORT(a) sort((a).rbegin(), (a).rend()) #define UNIQUE(a) (a).erase(unique((a).bgn, (a).en), (a).en) #define PREVP(a) prev_permutation((a).bgn, (a).en) #define NEXTP(a) next_permutation((a).bgn, (a).en) #define BINS(a, b) binary_search((a).bgn, (a).en, (b)) #define LOWB(a, b) (lower_bound((a).bgn, (a).en, (b)) - (a).bgn) #define UPB(a, b) (upper_bound((a).bgn, (a).en, (b)) - (a).bgn) #define CNT(a, b) count((a).bgn, (a).en, b) #define SUM(a) accumulate((a).bgn, (a).en, 0) #define REV(a) reverse((a).bgn, (a).en) #define REGS(a, b) regex_search((a), regex(b)) #define REGM(a, b) regex_match((a), regex(b)) #define yn(a) cout << ((a) ? "yes" : "no") << "\n"; #define Yn(a) cout << ((a) ? "Yes" : "No") << "\n"; #define YN(a) cout << ((a) ? "YES" : "NO") << "\n"; #define imp(a) cout << ((a) ? "possible" : "impossible") << "\n"; #define Imp(a) cout << ((a) ? "Possible" : "Impossible") << "\n"; #define IMP(a) cout << ((a) ? "POSSIBLE" : "IMPOSSIBLE") << "\n"; #define fs(a) cout << ((a) ? "second" : "first") << "\n"; #define Fs(a) cout << ((a) ? "Second" : "First") << "\n"; #define FS(a) cout << ((a) ? "SECOND" : "FIRST") << "\n"; //#define say(a) cout <<(a); //#define sal(a) cout <<(a)<<"\n"; #define sak cout << "\n"; #define sas cout << " "; #define sat cout << "\t"; #define dbg(a) cerr << (#a) << ": " << (a) << "\n"; #define dbgs(...) \ dal(#__VA_ARGS__); \ dal(__VA_ARGS__); #define c2l(a) ((ll)(a - 48)) #define a2l(a) ((ll)(a - 97)) #define A2l(a) ((ll)(a - 65)) #define l2c(a) ((char)(a + 48)) #define l2a(a) ((char)(a + 97)) #define l2A(a) ((char)(a + 65)) #define DigN2(a) ((llabs(a) == 0) ? (1) : ((ll)(log2(double(llabs(a)))) + 1)) #define DigN10(a) ((llabs(a) == 0) ? (1) : ((ll)(log10(double(llabs(a)))) + 1)) #define Dig2(a, b) (((a) >> (b)) & 1) #define Dig10(a, b) (ll)(((a) / ((ll)(pow(10.0, (double)(b))))) % 10) #define Pow2(a) ((ll)(1) << (a)) #define Pow10(a) ((ll)(pow(10.0, double(a)))) #define LSB(a) ((a) & (-(a))) /*#define llin(a) ll (a);cin >>(a); #define llin2(a,b) ll (a),(b);cin >>(a)>>(b); #define llin3(a,b,c) ll (a),(b),(c);cin >>(a)>>(b)>>(c); #define stin(a) string (a);cin >>(a);*/ #define vin(v) \ ROR((v), (i)) { cin >> (i); }; #define vllin(v, N) \ vll(v)((N)); \ vin(v); #define vllin2(a, b, N) \ vll(a)(N), (b)(N); \ REP(i, N) { cin >> (a)[i] >> (b)[i]; }; #define vsin(v, N) \ vs(v)((N)); \ vin(v); #define rdn(a, b) ((a) / (b)) #define rou(a, b) \ ((((double(a) / double(b)) - ((a) / (b))) < 0.5) ? ((a) / (b)) \ : (((a) / (b)) + 1)) #define rup(a, b) ((((a) % (b)) == 0) ? ((a) / (b)) : (((a) / (b)) + 1)) #define powll(a, b) (ll)(pow((double)(a), (double)(b))) #define Triangle(x1, y1, x2, y2, x3, y3) \ (((x1) - (x2)) * ((y1) - (y3)) - ((x1) - (x3)) * ((y1) - (y2))) #define lam(lr) ([](auto l, auto r) { lr }) #define elam(lr) ([=](auto l, auto r) { lr }) #define clam(lr) ([&](auto l, auto r) { lr }) #define min(...) Operation(MIN, __VA_ARGS__) #define max(...) Operation(MAX, __VA_ARGS__) #define gcd(...) Operation(GCD, __VA_ARGS__) #define lcm(...) Operation(LCM, __VA_ARGS__) #define vmin(...) VOperation(MIN, __VA_ARGS__) #define vmax(...) VOperation(MAX, __VA_ARGS__) #define vgcd(...) VOperation(GCD, __VA_ARGS__) #define vlcm(...) VOperation(LCM, __VA_ARGS__) #define vsum(...) VOperation(ADD, __VA_ARGS__) #define vpro(...) VOperation(MUL, __VA_ARGS__) #define emin(a, ...) ((a) = min((a), __VA_ARGS__)) #define emax(a, ...) ((a) = max((a), __VA_ARGS__)) #define egcd(a, ...) ((a) = gcd((a), __VA_ARGS__)) #define elcm(a, ...) ((a) = lcm((a), __VA_ARGS__)) #define ActPair(T) P<T, function<T(T, T)>> #define BoolPair(T) P<T, function<bool(T, T)>> #define ope Operation #define vope VOperation #define svll SumV<ll> #define svvll SumV2<ll> #define li(...) \ ll __VA_ARGS__; \ Input(__VA_ARGS__); #define si(...) \ str __VA_ARGS__; \ Input(__VA_ARGS__); //#define vli(size, ...) vll __VA_ARGS__;vInitInput(size,__VA_ARGS__); #define vlr(size, ...) \ vll __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vlc(size, ...) \ vll __VA_ARGS__; \ vInitInputC(size, __VA_ARGS__); #define vli(size, ...) \ vll __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vsr(size, ...) \ vs __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vsc(size, ...) \ vs __VA_ARGS__; \ vInitInputC(size, __VA_ARGS__); #define vsi(size, ...) \ vs __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vli2(rowSize, columnSize, ...) \ vvll __VA_ARGS__; \ vInitInput2(rowSize, columnSize, __VA_ARGS__); #define vplr(size, ...) \ vpl __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vplc(size, ...) \ vpl __VA_ARGS__; \ vInitInputC(size, __VA_ARGS__); #define vpli(size, ...) \ vpl __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); const ll MOD = 1e9 + 7; // const ll MOD = 998244353; // const ll MOD = 924844033; // const ll MOD = 9007199254740881; const ll INF = 1LL << 60; // 1.15e18 const double PI = acos(-1.0); const vll DX = {0, -1, 0, 1, 0, -1, 1, 1, -1}; const vll DY = {0, 0, -1, 0, 1, -1, -1, 1, 1}; const str alp = "abcdefghijklmnopqrstuvwxyz"; const str ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; template <class S, class T> istream &operator>>(istream &in, P<S, T> &p) { return in >> p.fi >> p.se; } template <class T> istream &operator>>(istream &in, V<T> &v) { REP(i, v.sz) in >> v[i]; return in; } void Input() {} template <class Var, class... Args> void Input(Var &var, Args &...args) { cin >> var; Input(args...); } void vInit(ll size) {} template <class T, class... Args> void vInit(ll size, V<T> &v, Args &...args) { v.res(size); vInit(size, args...); } void vInput(ll size) {} template <class T, class... Args> void vInput(ll size, V<T> &v, Args &...args) { REP(i, size) cin >> v[i]; vInput(size, args...); } void vInputR(ll size) {} template <class T, class... Args> void vInputR(ll size, V<T> &v, Args &...args) { REP(i, size) cin >> v[i]; vInputR(size, args...); } void vInputNumC(ll num) {} template <class T, class... Args> void vInputNumC(ll num, V<T> &v, Args &...args) { cin >> v[num]; vInputNumC(num, args...); } void vInputC(ll size) {} template <class... Args> void vInputC(ll size, Args &...args) { REP(i, size) vInputNumC(i, args...); } void vInitInputR(ll size) {} template <class... Args> void vInitInputR(ll size, Args &...args) { vInit(size, args...); vInputR(size, args...); } void vInitInputC(ll size) {} template <class... Args> void vInitInputC(ll size, Args &...args) { vInit(size, args...); vInputC(size, args...); } void vInit2(ll rowSize, ll columnSize) {} template <class T, class... Args> void vInit2(ll rowSize, ll columnSize, V<V<T>> &v, Args &...args) { v.asn(rowSize, V<T>(columnSize)); vInit2(rowSize, columnSize, args...); } void vInput2(ll rowSize, ll columnSize) {} template <class T, class... Args> void vInput2(ll rowSize, ll columnSize, V<V<T>> &v, Args &...args) { REP(r, rowSize) { REP(c, columnSize) { cin >> v[r][c]; } } vInput2(rowSize, columnSize, args...); } void vInitInput2(ll rowSize, ll columnSize) {} template <class... Args> void vInitInput2(ll rowSize, ll columnSize, Args &...args) { vInit2(rowSize, columnSize, args...); vInput2(rowSize, columnSize, args...); } template <class S, class T> ostream &operator<<(ostream &out, const P<S, T> &p) { return out << "[" << p.fi << ", " << p.se << "]"; } template <class T> ostream &operator<<(ostream &out, V<T> &v) { if (v.emp) return out << "{}"; else { auto itr = v.bgn; out << "{" << *itr; itr++; while (itr != v.en) { out << ", " << *itr; itr++; } out << "}"; return out; } } template <class S, class T> ostream &operator<<(ostream &out, const map<S, T> &m) { if (m.emp) return out << "<[]>"; else { auto itr = m.bgn; out << "< [" << (itr->fi) << ": " << (itr->se); itr++; while (itr != m.en) { out << "], [" << (itr->fi) << ": " << (itr->se); itr++; } out << "] >"; return out; } } template <class T> ostream &operator<<(ostream &out, const set<T> &s) { if (s.emp) return out << "<>"; else { auto itr = s.bgn; out << "<" << *itr; itr++; while (itr != s.en) { out << ", " << *itr; itr++; } out << ">"; return out; } } void say() {} template <class T> void say(T t) { cout << t; } template <class Head, class... Body> void say(Head head, Body... body) { cout << head << " "; say(body...); } void sal() { cout << "\n"; } template <class... Args> void sal(Args... args) { say(args...); cout << "\n"; } void day() {} template <class T> void day(T t) { cerr << t; } template <class Head, class... Body> void day(Head head, Body... body) { cerr << head << " "; day(body...); } void dal() { cerr << "\n"; } template <class... Args> void dal(Args... args) { day(args...); cerr << "\n"; } void salv() {} template <class T> void salv(V<T> v) { if (v.emp) sal(); else { auto itr = v.bgn; say(*itr); itr++; while (itr != v.en) { sas; say(*itr); itr++; } sak; } } template <class T> void salv(V<V<T>> v) { if (v.emp) sal(); else { ROR(v, i) salv(i); } } template <class T, class... Args> void salv(T v, Args... args) { salv(v); salv(args...); } template <class L, class R> auto Gcd(L l, R r) -> decltype(l + r) { if (l < r) swap(l, r); return r ? Gcd(r, l % r) : l; } template <class L, class R> auto Lcm(L l, R r) { if (!l || !r) return 0; return l / Gcd(l, r) * r; } auto LES = mp(INF, lam(return l < r;)); auto GRT = mp(-INF, lam(return l > r;)); auto EQ = mp(0, lam(return l == r;)); auto ADD = mp(0, lam(return l + r;)); auto SUB = mp(0, lam(return l - r;)); auto MUL = mp(1, lam(return l * r;)); auto DIV = mp(1, lam(return l / r;)); auto MDL = mp(1, lam(return l % r;)); auto XOR = mp(0, lam(return l ^ r;)); auto OR = mp(0, lam(return l | r;)); auto AND = mp(((ll)(1) << 63) - 1, lam(return l & r;)); auto MIN = mp(INF, lam(return (l < r) ? l : r;)); auto MAX = mp(-INF, lam(return (l > r) ? l : r;)); auto GCD = mp(0, lam(return Gcd(l, r);)); auto LCM = mp(1, lam(return Lcm(l, r);)); /* auto ADD = mp(0, [](auto l, auto r) { return l + r; }); auto SUB = mp(1, [](auto l, auto r) { return l - r; }); auto MUL = mp(1, [](auto l, auto r) { return l * r; }); auto DIV = mp(0, [](auto l, auto r) { return l / r; }); auto MDL = mp(0, [](auto l, auto r) { return l % r; }); auto XOR = mp(0, [](auto l, auto r) { return l ^ r; }); auto OR = mp(0, [](auto l, auto r) { return l | r; }); auto AND = mp(((ll)(1) << 63) - 1, [](auto l, auto r) { return l & r; }); auto MIN = mp(INF, [](auto l, auto r) { return (l < r) ? l : r; }); auto MAX = mp(-INF, [](auto l, auto r) { return (l > r) ? l : r; }); auto GCD = mp(0, [](auto l, auto r) { return gcd(l, r); }); auto LCM = mp(1, [](auto l, auto r) { return lcm(l, r); }); */ template <class OperationType> auto Operation(OperationType A) { return A.fi; } template <class OperationType, class T> auto Operation(OperationType A, T x) { return x; } template <class OperationType, class T, class... Args> auto Operation(OperationType A, T x, Args... args) { auto tmp = Operation(A, args...); return A.se(x, tmp); } template <class OperationType> auto VOperation(OperationType A) { return A.fi; } template <class OperationType, class T> auto VOperation(OperationType A, T x) { return x; } template <class OperationType, class T> auto VOperation(OperationType A, V<T> x) { T tmp = A.fi; ROR(x, i) tmp = A.se(tmp, i); return tmp; } template <class OperationType, class T> auto VOperation(OperationType A, V<V<T>> x) { T tmp = A.fi; ROR(x, i) ROR(i, j) tmp = A.se(tmp, j); return tmp; } template <class OperationType, class T> auto VOperation(OperationType A, V<V<V<T>>> x) { T tmp = A.fi; ROR(x, i) ROR(i, j) ROR(j, k) tmp = A.se(tmp, k); return tmp; } template <class OperationType, class T> auto VOperation(OperationType A, V<V<V<V<T>>>> x) { T tmp = A.fi; ROR(x, i) ROR(i, j) ROR(j, k) ROR(k, l) tmp = A.se(tmp, l); return tmp; } template <class OperationType, class T, class... Args> auto VOperation(OperationType A, T x, Args... args) { auto xResult = VOperation(A, x); auto tmp = VOperation(A, args...); return A.se(xResult, tmp); } ll Bset(ll a, ll b, ll c) { if (c) a |= b; else a &= ~b; return a; } struct UFT { public: ll tsize; ll mode; vll par; vll rank; UFT() {} UFT(const UFT &uft) {} UFT(ll tsizeget, ll modeget = 0) { tsize = tsizeget; mode = modeget; par.asn(tsize, -1); if (!mode) rank.res(tsize, 0); } ll root(ll x) { return par[x] < 0 ? x : par[x] = root(par[x]); } bool isRoot(ll x) { return x == root(x); } bool same(ll x, ll y) { return root(x) == root(y); } void merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) return; if (mode) { par[x] += par[y]; par[y] = x; } else { if (rank[x] < rank[y]) { par[y] += par[x]; par[x] = y; } else { par[x] += par[y]; par[y] = x; if (rank[x] == rank[y]) rank[x]++; } } } ll size(ll x) { return -par[root(x)]; } }; struct pUFT { public: ll tsize; ll now; vll par; vll rank; vll mtime; vvll sizepi; vvll sizepv; pUFT() {} pUFT(const pUFT &puft) {} pUFT(ll tsizeget) { tsize = tsizeget; now = 0; par.asn(tsize, -1); rank.asn(tsize, 0); mtime.asn(tsize, INF); sizepi.asn(tsize, {0}); sizepv.asn(tsize, {1}); } ll root(ll x, ll t) { return (mtime[x] > t) ? x : root(par[x], t); } bool same(ll x, ll y, ll t) { return root(x, t) == root(y, t); } ll merge(ll x, ll y) { now++; x = root(x, now); y = root(y, now); if (x != y) { if (rank[x] < rank[y]) { par[y] += par[x]; sizepi[y].pb(now); sizepv[y].pb(-par[y]); par[x] = y; mtime[x] = now; } else { par[x] += par[y]; sizepi[x].pb(now); sizepv[x].pb(-par[x]); par[y] = x; mtime[y] = now; if (rank[x] == rank[y]) rank[x]++; } } return now; } ll size(ll x, ll t) { x = root(x, t); return sizepv[x][UPB(sizepi[x], t) - 1]; } }; struct wUFT { public: ll tsize; ll mode; vll par; vll rank; vll dweight; wUFT() {} wUFT(const wUFT &wuft) {} wUFT(ll tsizeget, ll modeget = 0) { tsize = tsizeget; mode = modeget; par.asn(tsize, -1); if (!mode) rank.res(tsize, 0); dweight.asn(tsize, 0); } ll root(ll x) { if (par[x] < 0) return x; else { ll r = root(par[x]); dweight[x] += dweight[par[x]]; return par[x] = r; } } ll weight(ll x) { root(x); return dweight[x]; } ll diff(ll x, ll y) { return weight(y) - weight(x); } bool isRoot(ll x) { return x == root(x); } bool same(ll x, ll y) { return root(x) == root(y); } void merge(ll x, ll y, ll w) { w += weight(x); w -= weight(y); x = root(x); y = root(y); if (x == y) return; if (mode) { par[x] += par[y]; par[y] = x; } else { if (rank[x] < rank[y]) { par[y] += par[x]; par[x] = y; dweight[x] = -w; } else { par[x] += par[y]; par[y] = x; if (rank[x] == rank[y]) rank[x]++; dweight[y] = w; } } } ll size(ll x) { return -par[root(x)]; } }; template <typename valtype> class SegT { public: ll size; vector<valtype> v; valtype initv; function<valtype(valtype x, valtype y)> calc; SegT() {} SegT(const SegT &segt) {} SegT(ll sizeget, ll modeget = 0) { sizeset(sizeget); modeset(modeget); init(); } SegT(vector<valtype> cpyvec, ll modeget = 0) { sizeset(cpyvec.sz); modeset(modeget); init(); copy(cpyvec); } SegT(ll sizeget, valtype initvget, function<valtype(valtype x, valtype y)> calcget) { sizeset(sizeget); initv = initvget; calc = calcget; init(); } SegT(vector<valtype> cpyvec, valtype initvget, function<valtype(valtype x, valtype y)> calcget) { sizeset(cpyvec.sz); initv = initvget; calc = calcget; init(); copy(cpyvec); } void sizeset(ll rsize) { size = DigN2(rsize); if (rsize == Pow2(size - 1)) size--; return; } void modeset(ll mode) { switch (mode) { case 0: initv = 0; calc = [](valtype x, valtype y) { return x + y; }; break; case 1: initv = INF; calc = [](valtype x, valtype y) { return min(x, y); }; break; case 2: initv = -INF; calc = [](valtype x, valtype y) { return max(x, y); }; break; } return; } void init() { v.asn(Pow2(size + 1) - 1, initv); } void copy(vector<valtype> cpyvec) { REP(i, min(cpyvec.sz, Pow2(size))) set(i, cpyvec[i]); } ll i2v(ll i) const { if (i < 0 || i >= Pow2(size)) return -1; return Pow2(size) + i - 1; } ll top(ll i) const { if (i == 0) return -1; return (i - 1) / 2; } pl bot(ll i) const { if (i + 1 >= Pow2(size)) return mp(-1, -1); return mp(2 * i + 1, 2 * i + 2); } void set(ll i, valtype x) { i = i2v(i); v[i] = x; while (i > 0) { i = top(i); v[i] = calc(v[bot(i).fi], v[bot(i).se]); } return; } void add(ll i, valtype x) { set(i, v[i2v(i)] + x); return; } valtype operator[](const ll &i) const { return v[i2v(i)]; } // valtype que(ll a = 0, ll b = Pow2(size) - 1) { valtype que(ll a, ll b) { if (a == b) return v[i2v(a)]; if (a > b) return initv; // swap(a, b); valtype ans = initv; ll ai = i2v(a); ll bi = i2v(b); FOR(i, 1, size + 1) { if (a > b) break; if (a % Pow2(i)) { ans = calc(ans, v[ai]); a += Pow2(i - 1); ai = top(ai) + 1; } else { ai = top(ai); } if (a > b) break; if ((b + 1) % Pow2(i)) { ans = calc(ans, v[bi]); b -= Pow2(i - 1); bi = top(bi) - 1; } else { bi = top(bi); } if (a > b) break; } return ans; } valtype que(ll b) { return que(0, b); } valtype que() { return que(0, Pow2(size) - 1); } }; /*template <class Type> class DP { public: vector<Type> v; Type initv; vll size, block; DP() {} DP(const DP &dp) {} template<class... Args> DP(Args... args) { block.asn(1, 1); Initialize(args...); } void Initialize(Type initv_) { initv = initv_; v.asn(block.bk, initv); } template<class... Args> void Initialize(ll val, Args... args) { size.pb(val); block.pb(block.bk*val); Initialize(args...); } };*/ pl Bezout(ll a, ll b) { if (b != 0) { pl xy; xy = Bezout(b, a % b); return mp(xy.se, xy.fi - ((a / b) * xy.se)); } else { return mp(1, 0); } } pl Bez(ll a, ll b, ll c) { pl xy; ll x, y, z, gc; xy = Bezout(a, b); gc = gcd(a, b); if (c % gc != 0) return mp(-1, -1); x = xy.fi * (c / gc); y = xy.se * (c / gc); if (x < 0) z = rup(-x, (b / gc)); if (x >= 0) z = -x / (b / gc); x += z * (b / gc); y -= z * (a / gc); return mp(x, y); } ll DigS10(ll n) { ll ans = 0; while (1) { ans += n % 10; n /= 10; if (!n) break; } return ans; } ll isP(ll n) { if (n <= 1) return 0; FOR(i, 2, (ll)sqrt(n) + 1) { if (n % i == 0) return 0; } return 1; } ll Tot(ll n) { if (n <= 0) return 0; ll ans = n, x = 2; while (x * x <= n) { if (n % x == 0) { ans -= ans / x; while (n % x == 0) n /= x; } x++; } if (n > 1) ans -= ans / n; return ans; } template <class T> struct Graph { public: ll vSize; ll eMode; ll mapMode; ActPair(T) Add; BoolPair(T) Lesser; BoolPair(T) Equal; V<V<P<T, ll>>> adj; map<pl, T> len; Graph(ll vSize, ll eMode = 0, ll mapMode = 0, ActPair(T) Add = ADD, BoolPair(T) Lesser = LES, BoolPair(T) Equal = EQ) : vSize(vSize), eMode(eMode), mapMode(mapMode), Add(Add), Lesser(Lesser), Equal(Equal) { Init(); } void Init() { adj.asn(vSize, V<P<T, ll>>()); } void AddE(ll x, ll y, T cost) { iAddE(x, y, cost); if (!eMode) iAddE(y, x, cost); } void iAddE(ll x, ll y, T cost) { adj[x].pb(mp(cost, y)); if (mapMode) len[mp(x, y)] = cost; } P<bool, T> getE(ll x, ll y) { if (!len.count(mp(x, y))) return mp(false, Lesser.fi); return mp(true, len[mp(x, y)]); } V<T> Dijk(ll x) { V<T> ans(vSize, Lesser.fi); if (x < 0 || x >= vSize) return ans; SegT<P<T, ll>> segt(vSize, mp(Lesser.fi, -1), clam(if (l.se < 0) return r; if (r.se < 0) return l; return Lesser.se(l.fi, r.fi) ? l : r;)); segt.set(x, mp(Add.fi, x)); P<T, ll> now; while ((now = segt.que(0, vSize - 1)).se >= 0) { ans[now.se] = segt[now.se].fi; segt.set(now.se, mp(Lesser.fi, -2)); ROR(adj[now.se], i) { if (segt[i.se].se == -2) continue; if (segt[i.se].se == -1) { segt.set(i.se, mp(Add.se(ans[now.se], i.fi), i.se)); continue; } if (Lesser.se(Add.se(ans[now.se], i.fi), segt[i.se].fi)) { segt.set(i.se, mp(Add.se(ans[now.se], i.fi), i.se)); continue; } } } return ans; } V<P<T, vll>> rDijk(ll x) { V<P<T, vll>> ans(vSize, mp(Lesser.fi, vll())); if (x < 0 || x >= vSize) return ans; SegT<P<T, ll>> segt(vSize, mp(Lesser.fi, -1), clam(if (l.se < 0) return r; if (r.se < 0) return l; return Lesser.se(l.fi, r.fi) ? l : r;)); segt.set(x, mp(Add.fi, x)); P<T, ll> now; while ((now = segt.que(0, vSize - 1)).se >= 0) { ans[now.se].fi = segt[now.se].fi; segt.set(now.se, mp(Lesser.fi, -2)); ROR(adj[now.se], i) { if (segt[i.se].se == -2) continue; if (segt[i.se].se == -1) { segt.set(i.se, mp(Add.se(ans[now.se].fi, i.fi), i.se)); ans[i.se].se = {now.se}; continue; } if (Lesser.se(Add.se(ans[now.se].fi, i.fi), segt[i.se].fi)) { segt.set(i.se, mp(Add.se(ans[now.se].fi, i.fi), i.se)); ans[i.se].se = {now.se}; continue; } if (Equal.se(Add.se(ans[now.se].fi, i.fi), segt[i.se].fi)) { ans[i.se].se.pb(now.se); continue; } } } return ans; } T Prim(ll x = 0) { T ans = Add.fi; if (x < 0 || x >= vSize) return ans; SegT<P<T, ll>> segt(vSize, mp(Lesser.fi, -1), clam(if (l.se < 0) return r; if (r.se < 0) return l; return Lesser.se(l.fi, r.fi) ? l : r;)); segt.set(x, mp(Add.fi, x)); P<T, ll> now; while ((now = segt.que(0, vSize - 1)).se >= 0) { ans = Add.se(ans, segt[now.se].fi); segt.set(now.se, mp(Lesser.fi, -2)); ROR(adj[now.se], i) { if (segt[i.se].se == -2) continue; if (segt[i.se].se == -1) { segt.set(i.se, i); continue; } if (Lesser.se(i.fi, segt[i.se].fi)) { segt.set(i.se, i); continue; } } } return ans; } P<T, V<P<T, vll>>> rPrim(ll x = 0) { P<T, V<P<T, vll>>> ans = mp(Add.fi, V<P<T, vll>>(vSize, mp(Lesser.fi, vll()))); if (x < 0 || x >= vSize) return ans; SegT<P<T, ll>> segt(vSize, mp(Lesser.fi, -1), clam(if (l.se < 0) return r; if (r.se < 0) return l; return Lesser.se(l.fi, r.fi) ? l : r;)); segt.set(x, mp(Add.fi, x)); P<T, ll> now; while ((now = segt.que(0, vSize - 1)).se >= 0) { ans.se[now.se].fi = segt[now.se].fi; ans.fi = Add.se(ans.fi, ans.se[now.se].fi); segt.set(now.se, mp(Lesser.fi, -2)); ROR(adj[now.se], i) { if (segt[i.se].se == -2) continue; if (segt[i.se].se == -1) { segt.set(i.se, i); ans.se[i.se].se = {now.se}; continue; } if (Lesser.se(i.fi, segt[i.se].fi)) { segt.set(i.se, i); ans.se[i.se].se = {now.se}; continue; } if (Equal.se(i.fi, segt[i.se].fi)) { ans.se[i.se].se.pb(now.se); continue; } } } return ans; } }; template <class T> struct Sum { public: V<T> v, s; ll size; ActPair(T) Add; ActPair(T) Sub; Sum(V<T> v, ActPair(T) Add = ADD, ActPair(T) Sub = SUB) : v(v), size(v.sz), Add(Add), Sub(Sub) { Init(); Calc(); } void Init() { s.asn(size + 1, Add.fi); } void Calc() { REP(i, size) s[i + 1] = Add.se(s[i], v[i]); } T operator()(ll x) { if (x < -1) x = -1; if (x > size - 1) x = size - 1; return s[x + 1]; } T operator()(ll l, ll r) { if (l < 0) l = 0; if (r >= size) r = size - 1; if (l > r) return Add.fi; return Sub.se(s[r + 1], s[l]); } }; using sumll = Sum<ll>; template <class T> struct Sum2 { public: V<V<T>> v, s; ll RowSize, ColumnSize; ActPair(T) Add; ActPair(T) Sub; Sum2(V<V<T>> v, ActPair(T) Add = ADD, ActPair(T) Sub = SUB) : v(v), RowSize(v.sz), ColumnSize(v.sz ? v[0].sz : 0), Add(Add), Sub(Sub) { Init(); Calc(); } void Init() { s.asn(RowSize + 1, V<T>(ColumnSize + 1, Add.fi)); } void Calc() { REP1(r, RowSize) { REP1(c, ColumnSize) { // s[r][c] = Sub.se(Add.se(Add.se(v[r - 1][c - //1], operator()(r - 1, c - 2)), operator()(r - 2, c - 1)), operator()(r //- 2, c - 2)); s[r][c] = Add.se(s[r][c - 1], v[r - 1][c - 1]); } } REP1(r, RowSize) { REP1(c, ColumnSize) { s[r][c] = Add.se(s[r - 1][c], s[r][c]); } } } T operator()(ll r, ll c) { if (r < -1) r = -1; if (c < -1) c = -1; if (r > RowSize - 1) r = RowSize - 1; if (c > ColumnSize - 1) c = ColumnSize - 1; return s[r + 1][c + 1]; } T operator()(ll r1, ll c1, ll r2, ll c2) { if (r1 < 0) r1 = 0; if (c1 < 0) c1 = 0; if (r2 >= RowSize) r2 = RowSize - 1; if (c2 >= ColumnSize) c2 = ColumnSize - 1; if (r1 > r2) return Add.fi; if (c1 > c2) return Add.fi; return Sub.se(Add.se(s[r2 + 1][c2 + 1], s[r1][c1]), Add.se(s[r2 + 1][c1], s[r1][c2 + 1])); } }; using sumll2 = Sum2<ll>; template <class T> struct Point2 { public: V<V<T>> v; ll h, w; Point2() : h(0), w(0) {} Point2(ll h, ll w) : h(h), w(w) { asn(h, w); } Point2(ll h, ll w, T val) : h(h), w(w) { asn(h, w, val); } void assign(ll h, ll w) { v.asn(h, V<T>(w)); } void assign(ll h, ll w, ll val) { v.asn(h, V<T>(w, val)); } T &operator()(ll h, ll w) { return v[h][w]; } T &operator()(pl p) { return v[p.fi][p.se]; } }; template <class T> using P2 = Point2<T>; template <ll Mod> struct Modll { public: ll v; Modll() : v(0) {} Modll(ll _v) { set(_v % Mod + Mod); } Modll &set(ll _v) { v = (_v < Mod) ? _v : (_v - Mod); return *this; } Modll pow(ll n) const { Modll x = *this, ans = 1; while (n) { if (n & 1) ans *= x; x *= x; n >>= 1; } return ans; } Modll inverse() const { return (*this).pow(Mod - 2); } Modll operator+(const Modll &m) const { return Modll().set(v + m.v); } Modll operator-(const Modll &m) const { return Modll().set(Mod + v - m.v); } Modll operator*(const Modll &m) const { return Modll().set((ull(v) * m.v) % Mod); } Modll operator/(const Modll &m) const { return *this * m.inv; } Modll &operator+=(const Modll &m) { return *this = *this + m; } Modll &operator-=(const Modll &m) { return *this = *this - m; } Modll &operator*=(const Modll &m) { return *this = *this * m; } Modll &operator/=(const Modll &m) { return *this = *this / m; } Modll operator-() const { return Modll(0) - *this; } explicit operator bool() const { return v != 0; } friend istream &operator>>(istream &in, Modll &m) { return in >> m.v; } friend ostream &operator<<(ostream &out, const Modll &m) { return out << m.v; } }; using mll = Modll<MOD>; using vmll = V<mll>; using vvmll = V<vmll>; using vvvmll = V<vvmll>; vmll MFactMemo(2, 1); vmll MIFactMemo(2, 1); mll mFact(ll n) { if (MFactMemo.sz <= n) { ll oldsize = MFactMemo.sz; MFactMemo.res(n + 1, 1); FOR(i, oldsize, n) MFactMemo[i] = MFactMemo[i - 1] * i; } return MFactMemo[n]; } mll miFact(ll n) { if (MIFactMemo.sz <= n) { ll oldsize = MIFactMemo.sz; MIFactMemo.res(n + 1, 1); MIFactMemo.bk = mFact(n).inv; rFOR(i, oldsize + 1, n) MIFactMemo[i - 1] = MIFactMemo[i] * i; } return MIFactMemo[n]; } mll mComb(ll n, ll k) { if (n < 0 || k < 0 || n < k) return 0; return mFact(n) * miFact(k) * miFact(n - k); } ll LIS(vll v, ll m = 0) { if (v.sz > 0) { ll ans = 0; vll dp(v.sz, INF); FOR(i, 0, v.sz - 1) { dp[m ? UPB(dp, v[i]) : LOWB(dp, v[i])] = v[i]; } FOR(i, 0, v.sz - 1) { if (dp[i] == INF) break; ans++; } return ans; } else { return 0; } } ll Bsrch(function<bool(ll x)> f, ll mi, ll ma) { ll ng = mi - 1, ok = ma, mid; while (ok - ng > 1) { mid = (ng + ok) / 2; (f(mid) ? ok : ng) = mid; } return ok; } template <class T> V<V<T>> MultiMatrix(V<V<T>> A, V<V<T>> B, ActPair(T) Mul = MUL, ActPair(T) Add = ADD) { V<V<T>> ans; ll ii = A.sz; if (!ii) return ans; ll jj = A[0].sz; if (!jj) return ans; ll jj2 = B.sz; if (!jj2) return ans; if (jj != jj2) return ans; ll kk = B[0].sz; if (!kk) return ans; ans.asn(ii, V<T>(kk, 0)); REP(i, ii) { REP(k, kk) { REP(j, jj) { ans[i][k] = Add.se(ans[i][k], Mul.se(A[i][j], B[j][k])); } } } return ans; } vvll CombMemo(1000, vll(1000, -1)); ll Comb(ll n, ll k) { if ((n < 0) || (k < 0)) return 0; if (CombMemo[n][k] == -1) { if (n < k) CombMemo[n][k] = 0; else { if (n == 0) CombMemo[n][k] = 1; else if (k == 0) CombMemo[n][k] = 1; else if (n == k) CombMemo[n][k] = 1; else CombMemo[n][k] = Comb(n - 1, k - 1) + Comb(n - 1, k); } } return CombMemo[n][k]; } template <class T> map<T, ll> Dict(V<T> v) { map<T, ll> m; if (!v.sz) return m; SORT(v); UNIQUE(v); REP(i, v.sz) { m[v[i]] = i; } return m; } template <class T> vll Cmprs(V<T> v) { auto m = Dict(v); vll ans(v.sz); REP(i, v.sz) { ans[i] = m[v[i]]; } return ans; } template <class T> vll PCmprs(V<T> v) { if (v.sz == 0) return V<T>(); vll tmp(v.sz); vll ans(v.sz); IOTA(tmp, 0); IOTA(ans, 0); sort(tmp.bgn, tmp.en, clam(return v[l] < v[r];)); sort(ans.bgn, ans.en, clam(return tmp[l] < tmp[r];)); return ans; } ll BblCnt(vll rv) { vll v = PCmprs(rv); SegT<ll> b(v.sz, 0); ll ans = 0; REP(i, v.sz) { ans += (i - b.que(0, v[i])); b.add(v[i], 1); } return ans; } template <class T> auto ven(T val) { return val; } template <> auto ven<int>(int val) { return (ll)val; } template <class T, class... Args> auto ven(T val, Args... args) { auto tmp = ven(args...); return V<decltype(tmp)>(val, tmp); } template <class T> void zind(T &v) { v--; } template <class T> void zind(V<T> &v) { ROR(v, i) zind(i); } template <class T, class... Args> void zind(T &v, Args &...args) { zind(v); zind(args...); } void Solve(); signed main() { cin.tie(0); ios::sync_with_stdio(false); cout << setprecision(20) << fixed; Solve(); } void Solve() { li(n); vlc(n, a, b); vpl c(n); REP(i, n) c[i] = mp(a[i] + b[i], i); sort(c.bgn, c.en, lam(return l.fi > r.fi;)); ll t = 0, u = 0, uu = 0; REP(i, n) { if (i % 2 == 0) u += a[c[t].se]; if (i % 2 == 1) uu += b[c[t].se]; } /* while (t < n) { u += a[c[t].se]; t++; if (t == n) break; u -= b[c[t].se]; t++; }*/ sal(u - uu); }
#include <bits/stdc++.h> using namespace std; template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; template <class T> using VVV = V<VV<T>>; template <class S, class T> using P = pair<S, T>; template <class S, class T, class U> using TP = tuple<S, T, U>; using ll = long long; using ull = unsigned long long; using dbl = double; using str = string; using vll = V<ll>; using vvll = V<vll>; using vvvll = V<vvll>; using pl = P<ll, ll>; using tl = TP<ll, ll, ll>; using vpl = V<pl>; using vvpl = V<vpl>; using vtl = V<tl>; using vvtl = V<vtl>; using vs = V<str>; using vvs = V<vs>; using vd = V<dbl>; using vvd = V<vd>; using qll = queue<ll>; using qpl = queue<pl>; using stll = stack<ll>; using stpl = stack<pl>; using mapll = map<ll, ll>; using setll = set<ll>; using pqll = priority_queue<ll>; //#define int ll #define fi first #define se second #define mp make_pair #define mt make_tuple #define pb push_back #define pob pop_back() #define pf push_front #define pof pop_front() #define sz size() #define bgn begin() #define en end() #define asn assign #define emp empty() #define fr front() #define bk back() #define clr clear() #define ins insert #define ers erase #define res resize #define tp top() #define p_q priority_queue #define inv inverse() #define FOR(i, a, b) for (ll i = (a); i <= (ll)(b); i++) #define rFOR(i, a, b) for (ll i = (b); i >= (ll)(a); i--) #define REP(i, a) FOR((i), 0, (ll)(a)-1) #define REP0(i, a) FOR((i), 0, (ll)(a)) #define REP1(i, a) FOR((i), 1, (ll)(a)) #define rREP(i, a) rFOR((i), 0, (ll)(a)-1) #define rREP0(i, a) rFOR((i), 0, (ll)(a)) #define rREP1(i, a) rFOR((i), 1, (ll)(a)) #define ROR(v, i) for (auto &(i) : (v)) #define IOTA(a, n) iota((a).bgn, (a).en, (n)) #define SORT(a) sort((a).bgn, (a).en) #define rSORT(a) sort((a).rbegin(), (a).rend()) #define UNIQUE(a) (a).erase(unique((a).bgn, (a).en), (a).en) #define PREVP(a) prev_permutation((a).bgn, (a).en) #define NEXTP(a) next_permutation((a).bgn, (a).en) #define BINS(a, b) binary_search((a).bgn, (a).en, (b)) #define LOWB(a, b) (lower_bound((a).bgn, (a).en, (b)) - (a).bgn) #define UPB(a, b) (upper_bound((a).bgn, (a).en, (b)) - (a).bgn) #define CNT(a, b) count((a).bgn, (a).en, b) #define SUM(a) accumulate((a).bgn, (a).en, 0) #define REV(a) reverse((a).bgn, (a).en) #define REGS(a, b) regex_search((a), regex(b)) #define REGM(a, b) regex_match((a), regex(b)) #define yn(a) cout << ((a) ? "yes" : "no") << "\n"; #define Yn(a) cout << ((a) ? "Yes" : "No") << "\n"; #define YN(a) cout << ((a) ? "YES" : "NO") << "\n"; #define imp(a) cout << ((a) ? "possible" : "impossible") << "\n"; #define Imp(a) cout << ((a) ? "Possible" : "Impossible") << "\n"; #define IMP(a) cout << ((a) ? "POSSIBLE" : "IMPOSSIBLE") << "\n"; #define fs(a) cout << ((a) ? "second" : "first") << "\n"; #define Fs(a) cout << ((a) ? "Second" : "First") << "\n"; #define FS(a) cout << ((a) ? "SECOND" : "FIRST") << "\n"; //#define say(a) cout <<(a); //#define sal(a) cout <<(a)<<"\n"; #define sak cout << "\n"; #define sas cout << " "; #define sat cout << "\t"; #define dbg(a) cerr << (#a) << ": " << (a) << "\n"; #define dbgs(...) \ dal(#__VA_ARGS__); \ dal(__VA_ARGS__); #define c2l(a) ((ll)(a - 48)) #define a2l(a) ((ll)(a - 97)) #define A2l(a) ((ll)(a - 65)) #define l2c(a) ((char)(a + 48)) #define l2a(a) ((char)(a + 97)) #define l2A(a) ((char)(a + 65)) #define DigN2(a) ((llabs(a) == 0) ? (1) : ((ll)(log2(double(llabs(a)))) + 1)) #define DigN10(a) ((llabs(a) == 0) ? (1) : ((ll)(log10(double(llabs(a)))) + 1)) #define Dig2(a, b) (((a) >> (b)) & 1) #define Dig10(a, b) (ll)(((a) / ((ll)(pow(10.0, (double)(b))))) % 10) #define Pow2(a) ((ll)(1) << (a)) #define Pow10(a) ((ll)(pow(10.0, double(a)))) #define LSB(a) ((a) & (-(a))) /*#define llin(a) ll (a);cin >>(a); #define llin2(a,b) ll (a),(b);cin >>(a)>>(b); #define llin3(a,b,c) ll (a),(b),(c);cin >>(a)>>(b)>>(c); #define stin(a) string (a);cin >>(a);*/ #define vin(v) \ ROR((v), (i)) { cin >> (i); }; #define vllin(v, N) \ vll(v)((N)); \ vin(v); #define vllin2(a, b, N) \ vll(a)(N), (b)(N); \ REP(i, N) { cin >> (a)[i] >> (b)[i]; }; #define vsin(v, N) \ vs(v)((N)); \ vin(v); #define rdn(a, b) ((a) / (b)) #define rou(a, b) \ ((((double(a) / double(b)) - ((a) / (b))) < 0.5) ? ((a) / (b)) \ : (((a) / (b)) + 1)) #define rup(a, b) ((((a) % (b)) == 0) ? ((a) / (b)) : (((a) / (b)) + 1)) #define powll(a, b) (ll)(pow((double)(a), (double)(b))) #define Triangle(x1, y1, x2, y2, x3, y3) \ (((x1) - (x2)) * ((y1) - (y3)) - ((x1) - (x3)) * ((y1) - (y2))) #define lam(lr) ([](auto l, auto r) { lr }) #define elam(lr) ([=](auto l, auto r) { lr }) #define clam(lr) ([&](auto l, auto r) { lr }) #define min(...) Operation(MIN, __VA_ARGS__) #define max(...) Operation(MAX, __VA_ARGS__) #define gcd(...) Operation(GCD, __VA_ARGS__) #define lcm(...) Operation(LCM, __VA_ARGS__) #define vmin(...) VOperation(MIN, __VA_ARGS__) #define vmax(...) VOperation(MAX, __VA_ARGS__) #define vgcd(...) VOperation(GCD, __VA_ARGS__) #define vlcm(...) VOperation(LCM, __VA_ARGS__) #define vsum(...) VOperation(ADD, __VA_ARGS__) #define vpro(...) VOperation(MUL, __VA_ARGS__) #define emin(a, ...) ((a) = min((a), __VA_ARGS__)) #define emax(a, ...) ((a) = max((a), __VA_ARGS__)) #define egcd(a, ...) ((a) = gcd((a), __VA_ARGS__)) #define elcm(a, ...) ((a) = lcm((a), __VA_ARGS__)) #define ActPair(T) P<T, function<T(T, T)>> #define BoolPair(T) P<T, function<bool(T, T)>> #define ope Operation #define vope VOperation #define svll SumV<ll> #define svvll SumV2<ll> #define li(...) \ ll __VA_ARGS__; \ Input(__VA_ARGS__); #define si(...) \ str __VA_ARGS__; \ Input(__VA_ARGS__); //#define vli(size, ...) vll __VA_ARGS__;vInitInput(size,__VA_ARGS__); #define vlr(size, ...) \ vll __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vlc(size, ...) \ vll __VA_ARGS__; \ vInitInputC(size, __VA_ARGS__); #define vli(size, ...) \ vll __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vsr(size, ...) \ vs __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vsc(size, ...) \ vs __VA_ARGS__; \ vInitInputC(size, __VA_ARGS__); #define vsi(size, ...) \ vs __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vli2(rowSize, columnSize, ...) \ vvll __VA_ARGS__; \ vInitInput2(rowSize, columnSize, __VA_ARGS__); #define vplr(size, ...) \ vpl __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vplc(size, ...) \ vpl __VA_ARGS__; \ vInitInputC(size, __VA_ARGS__); #define vpli(size, ...) \ vpl __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); const ll MOD = 1e9 + 7; // const ll MOD = 998244353; // const ll MOD = 924844033; // const ll MOD = 9007199254740881; const ll INF = 1LL << 60; // 1.15e18 const double PI = acos(-1.0); const vll DX = {0, -1, 0, 1, 0, -1, 1, 1, -1}; const vll DY = {0, 0, -1, 0, 1, -1, -1, 1, 1}; const str alp = "abcdefghijklmnopqrstuvwxyz"; const str ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; template <class S, class T> istream &operator>>(istream &in, P<S, T> &p) { return in >> p.fi >> p.se; } template <class T> istream &operator>>(istream &in, V<T> &v) { REP(i, v.sz) in >> v[i]; return in; } void Input() {} template <class Var, class... Args> void Input(Var &var, Args &...args) { cin >> var; Input(args...); } void vInit(ll size) {} template <class T, class... Args> void vInit(ll size, V<T> &v, Args &...args) { v.res(size); vInit(size, args...); } void vInput(ll size) {} template <class T, class... Args> void vInput(ll size, V<T> &v, Args &...args) { REP(i, size) cin >> v[i]; vInput(size, args...); } void vInputR(ll size) {} template <class T, class... Args> void vInputR(ll size, V<T> &v, Args &...args) { REP(i, size) cin >> v[i]; vInputR(size, args...); } void vInputNumC(ll num) {} template <class T, class... Args> void vInputNumC(ll num, V<T> &v, Args &...args) { cin >> v[num]; vInputNumC(num, args...); } void vInputC(ll size) {} template <class... Args> void vInputC(ll size, Args &...args) { REP(i, size) vInputNumC(i, args...); } void vInitInputR(ll size) {} template <class... Args> void vInitInputR(ll size, Args &...args) { vInit(size, args...); vInputR(size, args...); } void vInitInputC(ll size) {} template <class... Args> void vInitInputC(ll size, Args &...args) { vInit(size, args...); vInputC(size, args...); } void vInit2(ll rowSize, ll columnSize) {} template <class T, class... Args> void vInit2(ll rowSize, ll columnSize, V<V<T>> &v, Args &...args) { v.asn(rowSize, V<T>(columnSize)); vInit2(rowSize, columnSize, args...); } void vInput2(ll rowSize, ll columnSize) {} template <class T, class... Args> void vInput2(ll rowSize, ll columnSize, V<V<T>> &v, Args &...args) { REP(r, rowSize) { REP(c, columnSize) { cin >> v[r][c]; } } vInput2(rowSize, columnSize, args...); } void vInitInput2(ll rowSize, ll columnSize) {} template <class... Args> void vInitInput2(ll rowSize, ll columnSize, Args &...args) { vInit2(rowSize, columnSize, args...); vInput2(rowSize, columnSize, args...); } template <class S, class T> ostream &operator<<(ostream &out, const P<S, T> &p) { return out << "[" << p.fi << ", " << p.se << "]"; } template <class T> ostream &operator<<(ostream &out, V<T> &v) { if (v.emp) return out << "{}"; else { auto itr = v.bgn; out << "{" << *itr; itr++; while (itr != v.en) { out << ", " << *itr; itr++; } out << "}"; return out; } } template <class S, class T> ostream &operator<<(ostream &out, const map<S, T> &m) { if (m.emp) return out << "<[]>"; else { auto itr = m.bgn; out << "< [" << (itr->fi) << ": " << (itr->se); itr++; while (itr != m.en) { out << "], [" << (itr->fi) << ": " << (itr->se); itr++; } out << "] >"; return out; } } template <class T> ostream &operator<<(ostream &out, const set<T> &s) { if (s.emp) return out << "<>"; else { auto itr = s.bgn; out << "<" << *itr; itr++; while (itr != s.en) { out << ", " << *itr; itr++; } out << ">"; return out; } } void say() {} template <class T> void say(T t) { cout << t; } template <class Head, class... Body> void say(Head head, Body... body) { cout << head << " "; say(body...); } void sal() { cout << "\n"; } template <class... Args> void sal(Args... args) { say(args...); cout << "\n"; } void day() {} template <class T> void day(T t) { cerr << t; } template <class Head, class... Body> void day(Head head, Body... body) { cerr << head << " "; day(body...); } void dal() { cerr << "\n"; } template <class... Args> void dal(Args... args) { day(args...); cerr << "\n"; } void salv() {} template <class T> void salv(V<T> v) { if (v.emp) sal(); else { auto itr = v.bgn; say(*itr); itr++; while (itr != v.en) { sas; say(*itr); itr++; } sak; } } template <class T> void salv(V<V<T>> v) { if (v.emp) sal(); else { ROR(v, i) salv(i); } } template <class T, class... Args> void salv(T v, Args... args) { salv(v); salv(args...); } template <class L, class R> auto Gcd(L l, R r) -> decltype(l + r) { if (l < r) swap(l, r); return r ? Gcd(r, l % r) : l; } template <class L, class R> auto Lcm(L l, R r) { if (!l || !r) return 0; return l / Gcd(l, r) * r; } auto LES = mp(INF, lam(return l < r;)); auto GRT = mp(-INF, lam(return l > r;)); auto EQ = mp(0, lam(return l == r;)); auto ADD = mp(0, lam(return l + r;)); auto SUB = mp(0, lam(return l - r;)); auto MUL = mp(1, lam(return l * r;)); auto DIV = mp(1, lam(return l / r;)); auto MDL = mp(1, lam(return l % r;)); auto XOR = mp(0, lam(return l ^ r;)); auto OR = mp(0, lam(return l | r;)); auto AND = mp(((ll)(1) << 63) - 1, lam(return l & r;)); auto MIN = mp(INF, lam(return (l < r) ? l : r;)); auto MAX = mp(-INF, lam(return (l > r) ? l : r;)); auto GCD = mp(0, lam(return Gcd(l, r);)); auto LCM = mp(1, lam(return Lcm(l, r);)); /* auto ADD = mp(0, [](auto l, auto r) { return l + r; }); auto SUB = mp(1, [](auto l, auto r) { return l - r; }); auto MUL = mp(1, [](auto l, auto r) { return l * r; }); auto DIV = mp(0, [](auto l, auto r) { return l / r; }); auto MDL = mp(0, [](auto l, auto r) { return l % r; }); auto XOR = mp(0, [](auto l, auto r) { return l ^ r; }); auto OR = mp(0, [](auto l, auto r) { return l | r; }); auto AND = mp(((ll)(1) << 63) - 1, [](auto l, auto r) { return l & r; }); auto MIN = mp(INF, [](auto l, auto r) { return (l < r) ? l : r; }); auto MAX = mp(-INF, [](auto l, auto r) { return (l > r) ? l : r; }); auto GCD = mp(0, [](auto l, auto r) { return gcd(l, r); }); auto LCM = mp(1, [](auto l, auto r) { return lcm(l, r); }); */ template <class OperationType> auto Operation(OperationType A) { return A.fi; } template <class OperationType, class T> auto Operation(OperationType A, T x) { return x; } template <class OperationType, class T, class... Args> auto Operation(OperationType A, T x, Args... args) { auto tmp = Operation(A, args...); return A.se(x, tmp); } template <class OperationType> auto VOperation(OperationType A) { return A.fi; } template <class OperationType, class T> auto VOperation(OperationType A, T x) { return x; } template <class OperationType, class T> auto VOperation(OperationType A, V<T> x) { T tmp = A.fi; ROR(x, i) tmp = A.se(tmp, i); return tmp; } template <class OperationType, class T> auto VOperation(OperationType A, V<V<T>> x) { T tmp = A.fi; ROR(x, i) ROR(i, j) tmp = A.se(tmp, j); return tmp; } template <class OperationType, class T> auto VOperation(OperationType A, V<V<V<T>>> x) { T tmp = A.fi; ROR(x, i) ROR(i, j) ROR(j, k) tmp = A.se(tmp, k); return tmp; } template <class OperationType, class T> auto VOperation(OperationType A, V<V<V<V<T>>>> x) { T tmp = A.fi; ROR(x, i) ROR(i, j) ROR(j, k) ROR(k, l) tmp = A.se(tmp, l); return tmp; } template <class OperationType, class T, class... Args> auto VOperation(OperationType A, T x, Args... args) { auto xResult = VOperation(A, x); auto tmp = VOperation(A, args...); return A.se(xResult, tmp); } ll Bset(ll a, ll b, ll c) { if (c) a |= b; else a &= ~b; return a; } struct UFT { public: ll tsize; ll mode; vll par; vll rank; UFT() {} UFT(const UFT &uft) {} UFT(ll tsizeget, ll modeget = 0) { tsize = tsizeget; mode = modeget; par.asn(tsize, -1); if (!mode) rank.res(tsize, 0); } ll root(ll x) { return par[x] < 0 ? x : par[x] = root(par[x]); } bool isRoot(ll x) { return x == root(x); } bool same(ll x, ll y) { return root(x) == root(y); } void merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) return; if (mode) { par[x] += par[y]; par[y] = x; } else { if (rank[x] < rank[y]) { par[y] += par[x]; par[x] = y; } else { par[x] += par[y]; par[y] = x; if (rank[x] == rank[y]) rank[x]++; } } } ll size(ll x) { return -par[root(x)]; } }; struct pUFT { public: ll tsize; ll now; vll par; vll rank; vll mtime; vvll sizepi; vvll sizepv; pUFT() {} pUFT(const pUFT &puft) {} pUFT(ll tsizeget) { tsize = tsizeget; now = 0; par.asn(tsize, -1); rank.asn(tsize, 0); mtime.asn(tsize, INF); sizepi.asn(tsize, {0}); sizepv.asn(tsize, {1}); } ll root(ll x, ll t) { return (mtime[x] > t) ? x : root(par[x], t); } bool same(ll x, ll y, ll t) { return root(x, t) == root(y, t); } ll merge(ll x, ll y) { now++; x = root(x, now); y = root(y, now); if (x != y) { if (rank[x] < rank[y]) { par[y] += par[x]; sizepi[y].pb(now); sizepv[y].pb(-par[y]); par[x] = y; mtime[x] = now; } else { par[x] += par[y]; sizepi[x].pb(now); sizepv[x].pb(-par[x]); par[y] = x; mtime[y] = now; if (rank[x] == rank[y]) rank[x]++; } } return now; } ll size(ll x, ll t) { x = root(x, t); return sizepv[x][UPB(sizepi[x], t) - 1]; } }; struct wUFT { public: ll tsize; ll mode; vll par; vll rank; vll dweight; wUFT() {} wUFT(const wUFT &wuft) {} wUFT(ll tsizeget, ll modeget = 0) { tsize = tsizeget; mode = modeget; par.asn(tsize, -1); if (!mode) rank.res(tsize, 0); dweight.asn(tsize, 0); } ll root(ll x) { if (par[x] < 0) return x; else { ll r = root(par[x]); dweight[x] += dweight[par[x]]; return par[x] = r; } } ll weight(ll x) { root(x); return dweight[x]; } ll diff(ll x, ll y) { return weight(y) - weight(x); } bool isRoot(ll x) { return x == root(x); } bool same(ll x, ll y) { return root(x) == root(y); } void merge(ll x, ll y, ll w) { w += weight(x); w -= weight(y); x = root(x); y = root(y); if (x == y) return; if (mode) { par[x] += par[y]; par[y] = x; } else { if (rank[x] < rank[y]) { par[y] += par[x]; par[x] = y; dweight[x] = -w; } else { par[x] += par[y]; par[y] = x; if (rank[x] == rank[y]) rank[x]++; dweight[y] = w; } } } ll size(ll x) { return -par[root(x)]; } }; template <typename valtype> class SegT { public: ll size; vector<valtype> v; valtype initv; function<valtype(valtype x, valtype y)> calc; SegT() {} SegT(const SegT &segt) {} SegT(ll sizeget, ll modeget = 0) { sizeset(sizeget); modeset(modeget); init(); } SegT(vector<valtype> cpyvec, ll modeget = 0) { sizeset(cpyvec.sz); modeset(modeget); init(); copy(cpyvec); } SegT(ll sizeget, valtype initvget, function<valtype(valtype x, valtype y)> calcget) { sizeset(sizeget); initv = initvget; calc = calcget; init(); } SegT(vector<valtype> cpyvec, valtype initvget, function<valtype(valtype x, valtype y)> calcget) { sizeset(cpyvec.sz); initv = initvget; calc = calcget; init(); copy(cpyvec); } void sizeset(ll rsize) { size = DigN2(rsize); if (rsize == Pow2(size - 1)) size--; return; } void modeset(ll mode) { switch (mode) { case 0: initv = 0; calc = [](valtype x, valtype y) { return x + y; }; break; case 1: initv = INF; calc = [](valtype x, valtype y) { return min(x, y); }; break; case 2: initv = -INF; calc = [](valtype x, valtype y) { return max(x, y); }; break; } return; } void init() { v.asn(Pow2(size + 1) - 1, initv); } void copy(vector<valtype> cpyvec) { REP(i, min(cpyvec.sz, Pow2(size))) set(i, cpyvec[i]); } ll i2v(ll i) const { if (i < 0 || i >= Pow2(size)) return -1; return Pow2(size) + i - 1; } ll top(ll i) const { if (i == 0) return -1; return (i - 1) / 2; } pl bot(ll i) const { if (i + 1 >= Pow2(size)) return mp(-1, -1); return mp(2 * i + 1, 2 * i + 2); } void set(ll i, valtype x) { i = i2v(i); v[i] = x; while (i > 0) { i = top(i); v[i] = calc(v[bot(i).fi], v[bot(i).se]); } return; } void add(ll i, valtype x) { set(i, v[i2v(i)] + x); return; } valtype operator[](const ll &i) const { return v[i2v(i)]; } // valtype que(ll a = 0, ll b = Pow2(size) - 1) { valtype que(ll a, ll b) { if (a == b) return v[i2v(a)]; if (a > b) return initv; // swap(a, b); valtype ans = initv; ll ai = i2v(a); ll bi = i2v(b); FOR(i, 1, size + 1) { if (a > b) break; if (a % Pow2(i)) { ans = calc(ans, v[ai]); a += Pow2(i - 1); ai = top(ai) + 1; } else { ai = top(ai); } if (a > b) break; if ((b + 1) % Pow2(i)) { ans = calc(ans, v[bi]); b -= Pow2(i - 1); bi = top(bi) - 1; } else { bi = top(bi); } if (a > b) break; } return ans; } valtype que(ll b) { return que(0, b); } valtype que() { return que(0, Pow2(size) - 1); } }; /*template <class Type> class DP { public: vector<Type> v; Type initv; vll size, block; DP() {} DP(const DP &dp) {} template<class... Args> DP(Args... args) { block.asn(1, 1); Initialize(args...); } void Initialize(Type initv_) { initv = initv_; v.asn(block.bk, initv); } template<class... Args> void Initialize(ll val, Args... args) { size.pb(val); block.pb(block.bk*val); Initialize(args...); } };*/ pl Bezout(ll a, ll b) { if (b != 0) { pl xy; xy = Bezout(b, a % b); return mp(xy.se, xy.fi - ((a / b) * xy.se)); } else { return mp(1, 0); } } pl Bez(ll a, ll b, ll c) { pl xy; ll x, y, z, gc; xy = Bezout(a, b); gc = gcd(a, b); if (c % gc != 0) return mp(-1, -1); x = xy.fi * (c / gc); y = xy.se * (c / gc); if (x < 0) z = rup(-x, (b / gc)); if (x >= 0) z = -x / (b / gc); x += z * (b / gc); y -= z * (a / gc); return mp(x, y); } ll DigS10(ll n) { ll ans = 0; while (1) { ans += n % 10; n /= 10; if (!n) break; } return ans; } ll isP(ll n) { if (n <= 1) return 0; FOR(i, 2, (ll)sqrt(n) + 1) { if (n % i == 0) return 0; } return 1; } ll Tot(ll n) { if (n <= 0) return 0; ll ans = n, x = 2; while (x * x <= n) { if (n % x == 0) { ans -= ans / x; while (n % x == 0) n /= x; } x++; } if (n > 1) ans -= ans / n; return ans; } template <class T> struct Graph { public: ll vSize; ll eMode; ll mapMode; ActPair(T) Add; BoolPair(T) Lesser; BoolPair(T) Equal; V<V<P<T, ll>>> adj; map<pl, T> len; Graph(ll vSize, ll eMode = 0, ll mapMode = 0, ActPair(T) Add = ADD, BoolPair(T) Lesser = LES, BoolPair(T) Equal = EQ) : vSize(vSize), eMode(eMode), mapMode(mapMode), Add(Add), Lesser(Lesser), Equal(Equal) { Init(); } void Init() { adj.asn(vSize, V<P<T, ll>>()); } void AddE(ll x, ll y, T cost) { iAddE(x, y, cost); if (!eMode) iAddE(y, x, cost); } void iAddE(ll x, ll y, T cost) { adj[x].pb(mp(cost, y)); if (mapMode) len[mp(x, y)] = cost; } P<bool, T> getE(ll x, ll y) { if (!len.count(mp(x, y))) return mp(false, Lesser.fi); return mp(true, len[mp(x, y)]); } V<T> Dijk(ll x) { V<T> ans(vSize, Lesser.fi); if (x < 0 || x >= vSize) return ans; SegT<P<T, ll>> segt(vSize, mp(Lesser.fi, -1), clam(if (l.se < 0) return r; if (r.se < 0) return l; return Lesser.se(l.fi, r.fi) ? l : r;)); segt.set(x, mp(Add.fi, x)); P<T, ll> now; while ((now = segt.que(0, vSize - 1)).se >= 0) { ans[now.se] = segt[now.se].fi; segt.set(now.se, mp(Lesser.fi, -2)); ROR(adj[now.se], i) { if (segt[i.se].se == -2) continue; if (segt[i.se].se == -1) { segt.set(i.se, mp(Add.se(ans[now.se], i.fi), i.se)); continue; } if (Lesser.se(Add.se(ans[now.se], i.fi), segt[i.se].fi)) { segt.set(i.se, mp(Add.se(ans[now.se], i.fi), i.se)); continue; } } } return ans; } V<P<T, vll>> rDijk(ll x) { V<P<T, vll>> ans(vSize, mp(Lesser.fi, vll())); if (x < 0 || x >= vSize) return ans; SegT<P<T, ll>> segt(vSize, mp(Lesser.fi, -1), clam(if (l.se < 0) return r; if (r.se < 0) return l; return Lesser.se(l.fi, r.fi) ? l : r;)); segt.set(x, mp(Add.fi, x)); P<T, ll> now; while ((now = segt.que(0, vSize - 1)).se >= 0) { ans[now.se].fi = segt[now.se].fi; segt.set(now.se, mp(Lesser.fi, -2)); ROR(adj[now.se], i) { if (segt[i.se].se == -2) continue; if (segt[i.se].se == -1) { segt.set(i.se, mp(Add.se(ans[now.se].fi, i.fi), i.se)); ans[i.se].se = {now.se}; continue; } if (Lesser.se(Add.se(ans[now.se].fi, i.fi), segt[i.se].fi)) { segt.set(i.se, mp(Add.se(ans[now.se].fi, i.fi), i.se)); ans[i.se].se = {now.se}; continue; } if (Equal.se(Add.se(ans[now.se].fi, i.fi), segt[i.se].fi)) { ans[i.se].se.pb(now.se); continue; } } } return ans; } T Prim(ll x = 0) { T ans = Add.fi; if (x < 0 || x >= vSize) return ans; SegT<P<T, ll>> segt(vSize, mp(Lesser.fi, -1), clam(if (l.se < 0) return r; if (r.se < 0) return l; return Lesser.se(l.fi, r.fi) ? l : r;)); segt.set(x, mp(Add.fi, x)); P<T, ll> now; while ((now = segt.que(0, vSize - 1)).se >= 0) { ans = Add.se(ans, segt[now.se].fi); segt.set(now.se, mp(Lesser.fi, -2)); ROR(adj[now.se], i) { if (segt[i.se].se == -2) continue; if (segt[i.se].se == -1) { segt.set(i.se, i); continue; } if (Lesser.se(i.fi, segt[i.se].fi)) { segt.set(i.se, i); continue; } } } return ans; } P<T, V<P<T, vll>>> rPrim(ll x = 0) { P<T, V<P<T, vll>>> ans = mp(Add.fi, V<P<T, vll>>(vSize, mp(Lesser.fi, vll()))); if (x < 0 || x >= vSize) return ans; SegT<P<T, ll>> segt(vSize, mp(Lesser.fi, -1), clam(if (l.se < 0) return r; if (r.se < 0) return l; return Lesser.se(l.fi, r.fi) ? l : r;)); segt.set(x, mp(Add.fi, x)); P<T, ll> now; while ((now = segt.que(0, vSize - 1)).se >= 0) { ans.se[now.se].fi = segt[now.se].fi; ans.fi = Add.se(ans.fi, ans.se[now.se].fi); segt.set(now.se, mp(Lesser.fi, -2)); ROR(adj[now.se], i) { if (segt[i.se].se == -2) continue; if (segt[i.se].se == -1) { segt.set(i.se, i); ans.se[i.se].se = {now.se}; continue; } if (Lesser.se(i.fi, segt[i.se].fi)) { segt.set(i.se, i); ans.se[i.se].se = {now.se}; continue; } if (Equal.se(i.fi, segt[i.se].fi)) { ans.se[i.se].se.pb(now.se); continue; } } } return ans; } }; template <class T> struct Sum { public: V<T> v, s; ll size; ActPair(T) Add; ActPair(T) Sub; Sum(V<T> v, ActPair(T) Add = ADD, ActPair(T) Sub = SUB) : v(v), size(v.sz), Add(Add), Sub(Sub) { Init(); Calc(); } void Init() { s.asn(size + 1, Add.fi); } void Calc() { REP(i, size) s[i + 1] = Add.se(s[i], v[i]); } T operator()(ll x) { if (x < -1) x = -1; if (x > size - 1) x = size - 1; return s[x + 1]; } T operator()(ll l, ll r) { if (l < 0) l = 0; if (r >= size) r = size - 1; if (l > r) return Add.fi; return Sub.se(s[r + 1], s[l]); } }; using sumll = Sum<ll>; template <class T> struct Sum2 { public: V<V<T>> v, s; ll RowSize, ColumnSize; ActPair(T) Add; ActPair(T) Sub; Sum2(V<V<T>> v, ActPair(T) Add = ADD, ActPair(T) Sub = SUB) : v(v), RowSize(v.sz), ColumnSize(v.sz ? v[0].sz : 0), Add(Add), Sub(Sub) { Init(); Calc(); } void Init() { s.asn(RowSize + 1, V<T>(ColumnSize + 1, Add.fi)); } void Calc() { REP1(r, RowSize) { REP1(c, ColumnSize) { // s[r][c] = Sub.se(Add.se(Add.se(v[r - 1][c - //1], operator()(r - 1, c - 2)), operator()(r - 2, c - 1)), operator()(r //- 2, c - 2)); s[r][c] = Add.se(s[r][c - 1], v[r - 1][c - 1]); } } REP1(r, RowSize) { REP1(c, ColumnSize) { s[r][c] = Add.se(s[r - 1][c], s[r][c]); } } } T operator()(ll r, ll c) { if (r < -1) r = -1; if (c < -1) c = -1; if (r > RowSize - 1) r = RowSize - 1; if (c > ColumnSize - 1) c = ColumnSize - 1; return s[r + 1][c + 1]; } T operator()(ll r1, ll c1, ll r2, ll c2) { if (r1 < 0) r1 = 0; if (c1 < 0) c1 = 0; if (r2 >= RowSize) r2 = RowSize - 1; if (c2 >= ColumnSize) c2 = ColumnSize - 1; if (r1 > r2) return Add.fi; if (c1 > c2) return Add.fi; return Sub.se(Add.se(s[r2 + 1][c2 + 1], s[r1][c1]), Add.se(s[r2 + 1][c1], s[r1][c2 + 1])); } }; using sumll2 = Sum2<ll>; template <class T> struct Point2 { public: V<V<T>> v; ll h, w; Point2() : h(0), w(0) {} Point2(ll h, ll w) : h(h), w(w) { asn(h, w); } Point2(ll h, ll w, T val) : h(h), w(w) { asn(h, w, val); } void assign(ll h, ll w) { v.asn(h, V<T>(w)); } void assign(ll h, ll w, ll val) { v.asn(h, V<T>(w, val)); } T &operator()(ll h, ll w) { return v[h][w]; } T &operator()(pl p) { return v[p.fi][p.se]; } }; template <class T> using P2 = Point2<T>; template <ll Mod> struct Modll { public: ll v; Modll() : v(0) {} Modll(ll _v) { set(_v % Mod + Mod); } Modll &set(ll _v) { v = (_v < Mod) ? _v : (_v - Mod); return *this; } Modll pow(ll n) const { Modll x = *this, ans = 1; while (n) { if (n & 1) ans *= x; x *= x; n >>= 1; } return ans; } Modll inverse() const { return (*this).pow(Mod - 2); } Modll operator+(const Modll &m) const { return Modll().set(v + m.v); } Modll operator-(const Modll &m) const { return Modll().set(Mod + v - m.v); } Modll operator*(const Modll &m) const { return Modll().set((ull(v) * m.v) % Mod); } Modll operator/(const Modll &m) const { return *this * m.inv; } Modll &operator+=(const Modll &m) { return *this = *this + m; } Modll &operator-=(const Modll &m) { return *this = *this - m; } Modll &operator*=(const Modll &m) { return *this = *this * m; } Modll &operator/=(const Modll &m) { return *this = *this / m; } Modll operator-() const { return Modll(0) - *this; } explicit operator bool() const { return v != 0; } friend istream &operator>>(istream &in, Modll &m) { return in >> m.v; } friend ostream &operator<<(ostream &out, const Modll &m) { return out << m.v; } }; using mll = Modll<MOD>; using vmll = V<mll>; using vvmll = V<vmll>; using vvvmll = V<vvmll>; vmll MFactMemo(2, 1); vmll MIFactMemo(2, 1); mll mFact(ll n) { if (MFactMemo.sz <= n) { ll oldsize = MFactMemo.sz; MFactMemo.res(n + 1, 1); FOR(i, oldsize, n) MFactMemo[i] = MFactMemo[i - 1] * i; } return MFactMemo[n]; } mll miFact(ll n) { if (MIFactMemo.sz <= n) { ll oldsize = MIFactMemo.sz; MIFactMemo.res(n + 1, 1); MIFactMemo.bk = mFact(n).inv; rFOR(i, oldsize + 1, n) MIFactMemo[i - 1] = MIFactMemo[i] * i; } return MIFactMemo[n]; } mll mComb(ll n, ll k) { if (n < 0 || k < 0 || n < k) return 0; return mFact(n) * miFact(k) * miFact(n - k); } ll LIS(vll v, ll m = 0) { if (v.sz > 0) { ll ans = 0; vll dp(v.sz, INF); FOR(i, 0, v.sz - 1) { dp[m ? UPB(dp, v[i]) : LOWB(dp, v[i])] = v[i]; } FOR(i, 0, v.sz - 1) { if (dp[i] == INF) break; ans++; } return ans; } else { return 0; } } ll Bsrch(function<bool(ll x)> f, ll mi, ll ma) { ll ng = mi - 1, ok = ma, mid; while (ok - ng > 1) { mid = (ng + ok) / 2; (f(mid) ? ok : ng) = mid; } return ok; } template <class T> V<V<T>> MultiMatrix(V<V<T>> A, V<V<T>> B, ActPair(T) Mul = MUL, ActPair(T) Add = ADD) { V<V<T>> ans; ll ii = A.sz; if (!ii) return ans; ll jj = A[0].sz; if (!jj) return ans; ll jj2 = B.sz; if (!jj2) return ans; if (jj != jj2) return ans; ll kk = B[0].sz; if (!kk) return ans; ans.asn(ii, V<T>(kk, 0)); REP(i, ii) { REP(k, kk) { REP(j, jj) { ans[i][k] = Add.se(ans[i][k], Mul.se(A[i][j], B[j][k])); } } } return ans; } vvll CombMemo(1000, vll(1000, -1)); ll Comb(ll n, ll k) { if ((n < 0) || (k < 0)) return 0; if (CombMemo[n][k] == -1) { if (n < k) CombMemo[n][k] = 0; else { if (n == 0) CombMemo[n][k] = 1; else if (k == 0) CombMemo[n][k] = 1; else if (n == k) CombMemo[n][k] = 1; else CombMemo[n][k] = Comb(n - 1, k - 1) + Comb(n - 1, k); } } return CombMemo[n][k]; } template <class T> map<T, ll> Dict(V<T> v) { map<T, ll> m; if (!v.sz) return m; SORT(v); UNIQUE(v); REP(i, v.sz) { m[v[i]] = i; } return m; } template <class T> vll Cmprs(V<T> v) { auto m = Dict(v); vll ans(v.sz); REP(i, v.sz) { ans[i] = m[v[i]]; } return ans; } template <class T> vll PCmprs(V<T> v) { if (v.sz == 0) return V<T>(); vll tmp(v.sz); vll ans(v.sz); IOTA(tmp, 0); IOTA(ans, 0); sort(tmp.bgn, tmp.en, clam(return v[l] < v[r];)); sort(ans.bgn, ans.en, clam(return tmp[l] < tmp[r];)); return ans; } ll BblCnt(vll rv) { vll v = PCmprs(rv); SegT<ll> b(v.sz, 0); ll ans = 0; REP(i, v.sz) { ans += (i - b.que(0, v[i])); b.add(v[i], 1); } return ans; } template <class T> auto ven(T val) { return val; } template <> auto ven<int>(int val) { return (ll)val; } template <class T, class... Args> auto ven(T val, Args... args) { auto tmp = ven(args...); return V<decltype(tmp)>(val, tmp); } template <class T> void zind(T &v) { v--; } template <class T> void zind(V<T> &v) { ROR(v, i) zind(i); } template <class T, class... Args> void zind(T &v, Args &...args) { zind(v); zind(args...); } void Solve(); signed main() { cin.tie(0); ios::sync_with_stdio(false); cout << setprecision(20) << fixed; Solve(); } void Solve() { li(n); vlc(n, a, b); vpl c(n); REP(i, n) c[i] = mp(a[i] + b[i], i); // SORT(c); sort(c.bgn, c.en, lam(return l.fi > r.fi;)); ll t = 0, u = 0, uu = 0; REP(i, n) { if (i % 2 == 0) u += a[c[i].se]; if (i % 2 == 1) uu += b[c[i].se]; } /* while (t < n) { u += a[c[t].se]; t++; if (t == n) break; u -= b[c[t].se]; t++; }*/ sal(u - uu); }
[ "assignment.value.change", "identifier.change", "variable_access.subscript.index.change" ]
941,760
941,759
u211681714
cpp
p03141
#include <bits/stdc++.h> using namespace std; template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; template <class T> using VVV = V<VV<T>>; template <class S, class T> using P = pair<S, T>; template <class S, class T, class U> using TP = tuple<S, T, U>; using ll = long long; using ull = unsigned long long; using dbl = double; using str = string; using vll = V<ll>; using vvll = V<vll>; using vvvll = V<vvll>; using pl = P<ll, ll>; using tl = TP<ll, ll, ll>; using vpl = V<pl>; using vvpl = V<vpl>; using vtl = V<tl>; using vvtl = V<vtl>; using vs = V<str>; using vvs = V<vs>; using vd = V<dbl>; using vvd = V<vd>; using qll = queue<ll>; using qpl = queue<pl>; using stll = stack<ll>; using stpl = stack<pl>; using mapll = map<ll, ll>; using setll = set<ll>; using pqll = priority_queue<ll>; //#define int ll #define fi first #define se second #define mp make_pair #define mt make_tuple #define pb push_back #define pob pop_back() #define pf push_front #define pof pop_front() #define sz size() #define bgn begin() #define en end() #define asn assign #define emp empty() #define fr front() #define bk back() #define clr clear() #define ins insert #define ers erase #define res resize #define tp top() #define p_q priority_queue #define inv inverse() #define FOR(i, a, b) for (ll i = (a); i <= (ll)(b); i++) #define rFOR(i, a, b) for (ll i = (b); i >= (ll)(a); i--) #define REP(i, a) FOR((i), 0, (ll)(a)-1) #define REP0(i, a) FOR((i), 0, (ll)(a)) #define REP1(i, a) FOR((i), 1, (ll)(a)) #define rREP(i, a) rFOR((i), 0, (ll)(a)-1) #define rREP0(i, a) rFOR((i), 0, (ll)(a)) #define rREP1(i, a) rFOR((i), 1, (ll)(a)) #define ROR(v, i) for (auto &(i) : (v)) #define IOTA(a, n) iota((a).bgn, (a).en, (n)) #define SORT(a) sort((a).bgn, (a).en) #define rSORT(a) sort((a).rbegin(), (a).rend()) #define UNIQUE(a) (a).erase(unique((a).bgn, (a).en), (a).en) #define PREVP(a) prev_permutation((a).bgn, (a).en) #define NEXTP(a) next_permutation((a).bgn, (a).en) #define BINS(a, b) binary_search((a).bgn, (a).en, (b)) #define LOWB(a, b) (lower_bound((a).bgn, (a).en, (b)) - (a).bgn) #define UPB(a, b) (upper_bound((a).bgn, (a).en, (b)) - (a).bgn) #define CNT(a, b) count((a).bgn, (a).en, b) #define SUM(a) accumulate((a).bgn, (a).en, 0) #define REV(a) reverse((a).bgn, (a).en) #define REGS(a, b) regex_search((a), regex(b)) #define REGM(a, b) regex_match((a), regex(b)) #define yn(a) cout << ((a) ? "yes" : "no") << "\n"; #define Yn(a) cout << ((a) ? "Yes" : "No") << "\n"; #define YN(a) cout << ((a) ? "YES" : "NO") << "\n"; #define imp(a) cout << ((a) ? "possible" : "impossible") << "\n"; #define Imp(a) cout << ((a) ? "Possible" : "Impossible") << "\n"; #define IMP(a) cout << ((a) ? "POSSIBLE" : "IMPOSSIBLE") << "\n"; #define fs(a) cout << ((a) ? "second" : "first") << "\n"; #define Fs(a) cout << ((a) ? "Second" : "First") << "\n"; #define FS(a) cout << ((a) ? "SECOND" : "FIRST") << "\n"; //#define say(a) cout <<(a); //#define sal(a) cout <<(a)<<"\n"; #define sak cout << "\n"; #define sas cout << " "; #define sat cout << "\t"; #define dbg(a) cerr << (#a) << ": " << (a) << "\n"; #define dbgs(...) \ dal(#__VA_ARGS__); \ dal(__VA_ARGS__); #define c2l(a) ((ll)(a - 48)) #define a2l(a) ((ll)(a - 97)) #define A2l(a) ((ll)(a - 65)) #define l2c(a) ((char)(a + 48)) #define l2a(a) ((char)(a + 97)) #define l2A(a) ((char)(a + 65)) #define DigN2(a) ((llabs(a) == 0) ? (1) : ((ll)(log2(double(llabs(a)))) + 1)) #define DigN10(a) ((llabs(a) == 0) ? (1) : ((ll)(log10(double(llabs(a)))) + 1)) #define Dig2(a, b) (((a) >> (b)) & 1) #define Dig10(a, b) (ll)(((a) / ((ll)(pow(10.0, (double)(b))))) % 10) #define Pow2(a) ((ll)(1) << (a)) #define Pow10(a) ((ll)(pow(10.0, double(a)))) #define LSB(a) ((a) & (-(a))) /*#define llin(a) ll (a);cin >>(a); #define llin2(a,b) ll (a),(b);cin >>(a)>>(b); #define llin3(a,b,c) ll (a),(b),(c);cin >>(a)>>(b)>>(c); #define stin(a) string (a);cin >>(a);*/ #define vin(v) \ ROR((v), (i)) { cin >> (i); }; #define vllin(v, N) \ vll(v)((N)); \ vin(v); #define vllin2(a, b, N) \ vll(a)(N), (b)(N); \ REP(i, N) { cin >> (a)[i] >> (b)[i]; }; #define vsin(v, N) \ vs(v)((N)); \ vin(v); #define rdn(a, b) ((a) / (b)) #define rou(a, b) \ ((((double(a) / double(b)) - ((a) / (b))) < 0.5) ? ((a) / (b)) \ : (((a) / (b)) + 1)) #define rup(a, b) ((((a) % (b)) == 0) ? ((a) / (b)) : (((a) / (b)) + 1)) #define powll(a, b) (ll)(pow((double)(a), (double)(b))) #define Triangle(x1, y1, x2, y2, x3, y3) \ (((x1) - (x2)) * ((y1) - (y3)) - ((x1) - (x3)) * ((y1) - (y2))) #define lam(lr) ([](auto l, auto r) { lr }) #define elam(lr) ([=](auto l, auto r) { lr }) #define clam(lr) ([&](auto l, auto r) { lr }) #define min(...) Operation(MIN, __VA_ARGS__) #define max(...) Operation(MAX, __VA_ARGS__) #define gcd(...) Operation(GCD, __VA_ARGS__) #define lcm(...) Operation(LCM, __VA_ARGS__) #define vmin(...) VOperation(MIN, __VA_ARGS__) #define vmax(...) VOperation(MAX, __VA_ARGS__) #define vgcd(...) VOperation(GCD, __VA_ARGS__) #define vlcm(...) VOperation(LCM, __VA_ARGS__) #define vsum(...) VOperation(ADD, __VA_ARGS__) #define vpro(...) VOperation(MUL, __VA_ARGS__) #define emin(a, ...) ((a) = min((a), __VA_ARGS__)) #define emax(a, ...) ((a) = max((a), __VA_ARGS__)) #define egcd(a, ...) ((a) = gcd((a), __VA_ARGS__)) #define elcm(a, ...) ((a) = lcm((a), __VA_ARGS__)) #define ActPair(T) P<T, function<T(T, T)>> #define BoolPair(T) P<T, function<bool(T, T)>> #define ope Operation #define vope VOperation #define svll SumV<ll> #define svvll SumV2<ll> #define li(...) \ ll __VA_ARGS__; \ Input(__VA_ARGS__); #define si(...) \ str __VA_ARGS__; \ Input(__VA_ARGS__); //#define vli(size, ...) vll __VA_ARGS__;vInitInput(size,__VA_ARGS__); #define vlr(size, ...) \ vll __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vlc(size, ...) \ vll __VA_ARGS__; \ vInitInputC(size, __VA_ARGS__); #define vli(size, ...) \ vll __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vsr(size, ...) \ vs __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vsc(size, ...) \ vs __VA_ARGS__; \ vInitInputC(size, __VA_ARGS__); #define vsi(size, ...) \ vs __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vli2(rowSize, columnSize, ...) \ vvll __VA_ARGS__; \ vInitInput2(rowSize, columnSize, __VA_ARGS__); #define vplr(size, ...) \ vpl __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vplc(size, ...) \ vpl __VA_ARGS__; \ vInitInputC(size, __VA_ARGS__); #define vpli(size, ...) \ vpl __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); const ll MOD = 1e9 + 7; // const ll MOD = 998244353; // const ll MOD = 924844033; // const ll MOD = 9007199254740881; const ll INF = 1LL << 60; // 1.15e18 const double PI = acos(-1.0); const vll DX = {0, -1, 0, 1, 0, -1, 1, 1, -1}; const vll DY = {0, 0, -1, 0, 1, -1, -1, 1, 1}; const str alp = "abcdefghijklmnopqrstuvwxyz"; const str ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; template <class S, class T> istream &operator>>(istream &in, P<S, T> &p) { return in >> p.fi >> p.se; } template <class T> istream &operator>>(istream &in, V<T> &v) { REP(i, v.sz) in >> v[i]; return in; } void Input() {} template <class Var, class... Args> void Input(Var &var, Args &...args) { cin >> var; Input(args...); } void vInit(ll size) {} template <class T, class... Args> void vInit(ll size, V<T> &v, Args &...args) { v.res(size); vInit(size, args...); } void vInput(ll size) {} template <class T, class... Args> void vInput(ll size, V<T> &v, Args &...args) { REP(i, size) cin >> v[i]; vInput(size, args...); } void vInputR(ll size) {} template <class T, class... Args> void vInputR(ll size, V<T> &v, Args &...args) { REP(i, size) cin >> v[i]; vInputR(size, args...); } void vInputNumC(ll num) {} template <class T, class... Args> void vInputNumC(ll num, V<T> &v, Args &...args) { cin >> v[num]; vInputNumC(num, args...); } void vInputC(ll size) {} template <class... Args> void vInputC(ll size, Args &...args) { REP(i, size) vInputNumC(i, args...); } void vInitInputR(ll size) {} template <class... Args> void vInitInputR(ll size, Args &...args) { vInit(size, args...); vInputR(size, args...); } void vInitInputC(ll size) {} template <class... Args> void vInitInputC(ll size, Args &...args) { vInit(size, args...); vInputC(size, args...); } void vInit2(ll rowSize, ll columnSize) {} template <class T, class... Args> void vInit2(ll rowSize, ll columnSize, V<V<T>> &v, Args &...args) { v.asn(rowSize, V<T>(columnSize)); vInit2(rowSize, columnSize, args...); } void vInput2(ll rowSize, ll columnSize) {} template <class T, class... Args> void vInput2(ll rowSize, ll columnSize, V<V<T>> &v, Args &...args) { REP(r, rowSize) { REP(c, columnSize) { cin >> v[r][c]; } } vInput2(rowSize, columnSize, args...); } void vInitInput2(ll rowSize, ll columnSize) {} template <class... Args> void vInitInput2(ll rowSize, ll columnSize, Args &...args) { vInit2(rowSize, columnSize, args...); vInput2(rowSize, columnSize, args...); } template <class S, class T> ostream &operator<<(ostream &out, const P<S, T> &p) { return out << "[" << p.fi << ", " << p.se << "]"; } template <class T> ostream &operator<<(ostream &out, V<T> &v) { if (v.emp) return out << "{}"; else { auto itr = v.bgn; out << "{" << *itr; itr++; while (itr != v.en) { out << ", " << *itr; itr++; } out << "}"; return out; } } template <class S, class T> ostream &operator<<(ostream &out, const map<S, T> &m) { if (m.emp) return out << "<[]>"; else { auto itr = m.bgn; out << "< [" << (itr->fi) << ": " << (itr->se); itr++; while (itr != m.en) { out << "], [" << (itr->fi) << ": " << (itr->se); itr++; } out << "] >"; return out; } } template <class T> ostream &operator<<(ostream &out, const set<T> &s) { if (s.emp) return out << "<>"; else { auto itr = s.bgn; out << "<" << *itr; itr++; while (itr != s.en) { out << ", " << *itr; itr++; } out << ">"; return out; } } void say() {} template <class T> void say(T t) { cout << t; } template <class Head, class... Body> void say(Head head, Body... body) { cout << head << " "; say(body...); } void sal() { cout << "\n"; } template <class... Args> void sal(Args... args) { say(args...); cout << "\n"; } void day() {} template <class T> void day(T t) { cerr << t; } template <class Head, class... Body> void day(Head head, Body... body) { cerr << head << " "; day(body...); } void dal() { cerr << "\n"; } template <class... Args> void dal(Args... args) { day(args...); cerr << "\n"; } void salv() {} template <class T> void salv(V<T> v) { if (v.emp) sal(); else { auto itr = v.bgn; say(*itr); itr++; while (itr != v.en) { sas; say(*itr); itr++; } sak; } } template <class T> void salv(V<V<T>> v) { if (v.emp) sal(); else { ROR(v, i) salv(i); } } template <class T, class... Args> void salv(T v, Args... args) { salv(v); salv(args...); } template <class L, class R> auto Gcd(L l, R r) -> decltype(l + r) { if (l < r) swap(l, r); return r ? Gcd(r, l % r) : l; } template <class L, class R> auto Lcm(L l, R r) { if (!l || !r) return 0; return l / Gcd(l, r) * r; } auto LES = mp(INF, lam(return l < r;)); auto GRT = mp(-INF, lam(return l > r;)); auto EQ = mp(0, lam(return l == r;)); auto ADD = mp(0, lam(return l + r;)); auto SUB = mp(0, lam(return l - r;)); auto MUL = mp(1, lam(return l * r;)); auto DIV = mp(1, lam(return l / r;)); auto MDL = mp(1, lam(return l % r;)); auto XOR = mp(0, lam(return l ^ r;)); auto OR = mp(0, lam(return l | r;)); auto AND = mp(((ll)(1) << 63) - 1, lam(return l & r;)); auto MIN = mp(INF, lam(return (l < r) ? l : r;)); auto MAX = mp(-INF, lam(return (l > r) ? l : r;)); auto GCD = mp(0, lam(return Gcd(l, r);)); auto LCM = mp(1, lam(return Lcm(l, r);)); /* auto ADD = mp(0, [](auto l, auto r) { return l + r; }); auto SUB = mp(1, [](auto l, auto r) { return l - r; }); auto MUL = mp(1, [](auto l, auto r) { return l * r; }); auto DIV = mp(0, [](auto l, auto r) { return l / r; }); auto MDL = mp(0, [](auto l, auto r) { return l % r; }); auto XOR = mp(0, [](auto l, auto r) { return l ^ r; }); auto OR = mp(0, [](auto l, auto r) { return l | r; }); auto AND = mp(((ll)(1) << 63) - 1, [](auto l, auto r) { return l & r; }); auto MIN = mp(INF, [](auto l, auto r) { return (l < r) ? l : r; }); auto MAX = mp(-INF, [](auto l, auto r) { return (l > r) ? l : r; }); auto GCD = mp(0, [](auto l, auto r) { return gcd(l, r); }); auto LCM = mp(1, [](auto l, auto r) { return lcm(l, r); }); */ template <class OperationType> auto Operation(OperationType A) { return A.fi; } template <class OperationType, class T> auto Operation(OperationType A, T x) { return x; } template <class OperationType, class T, class... Args> auto Operation(OperationType A, T x, Args... args) { auto tmp = Operation(A, args...); return A.se(x, tmp); } template <class OperationType> auto VOperation(OperationType A) { return A.fi; } template <class OperationType, class T> auto VOperation(OperationType A, T x) { return x; } template <class OperationType, class T> auto VOperation(OperationType A, V<T> x) { T tmp = A.fi; ROR(x, i) tmp = A.se(tmp, i); return tmp; } template <class OperationType, class T> auto VOperation(OperationType A, V<V<T>> x) { T tmp = A.fi; ROR(x, i) ROR(i, j) tmp = A.se(tmp, j); return tmp; } template <class OperationType, class T> auto VOperation(OperationType A, V<V<V<T>>> x) { T tmp = A.fi; ROR(x, i) ROR(i, j) ROR(j, k) tmp = A.se(tmp, k); return tmp; } template <class OperationType, class T> auto VOperation(OperationType A, V<V<V<V<T>>>> x) { T tmp = A.fi; ROR(x, i) ROR(i, j) ROR(j, k) ROR(k, l) tmp = A.se(tmp, l); return tmp; } template <class OperationType, class T, class... Args> auto VOperation(OperationType A, T x, Args... args) { auto xResult = VOperation(A, x); auto tmp = VOperation(A, args...); return A.se(xResult, tmp); } ll Bset(ll a, ll b, ll c) { if (c) a |= b; else a &= ~b; return a; } struct UFT { public: ll tsize; ll mode; vll par; vll rank; UFT() {} UFT(const UFT &uft) {} UFT(ll tsizeget, ll modeget = 0) { tsize = tsizeget; mode = modeget; par.asn(tsize, -1); if (!mode) rank.res(tsize, 0); } ll root(ll x) { return par[x] < 0 ? x : par[x] = root(par[x]); } bool isRoot(ll x) { return x == root(x); } bool same(ll x, ll y) { return root(x) == root(y); } void merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) return; if (mode) { par[x] += par[y]; par[y] = x; } else { if (rank[x] < rank[y]) { par[y] += par[x]; par[x] = y; } else { par[x] += par[y]; par[y] = x; if (rank[x] == rank[y]) rank[x]++; } } } ll size(ll x) { return -par[root(x)]; } }; struct pUFT { public: ll tsize; ll now; vll par; vll rank; vll mtime; vvll sizepi; vvll sizepv; pUFT() {} pUFT(const pUFT &puft) {} pUFT(ll tsizeget) { tsize = tsizeget; now = 0; par.asn(tsize, -1); rank.asn(tsize, 0); mtime.asn(tsize, INF); sizepi.asn(tsize, {0}); sizepv.asn(tsize, {1}); } ll root(ll x, ll t) { return (mtime[x] > t) ? x : root(par[x], t); } bool same(ll x, ll y, ll t) { return root(x, t) == root(y, t); } ll merge(ll x, ll y) { now++; x = root(x, now); y = root(y, now); if (x != y) { if (rank[x] < rank[y]) { par[y] += par[x]; sizepi[y].pb(now); sizepv[y].pb(-par[y]); par[x] = y; mtime[x] = now; } else { par[x] += par[y]; sizepi[x].pb(now); sizepv[x].pb(-par[x]); par[y] = x; mtime[y] = now; if (rank[x] == rank[y]) rank[x]++; } } return now; } ll size(ll x, ll t) { x = root(x, t); return sizepv[x][UPB(sizepi[x], t) - 1]; } }; struct wUFT { public: ll tsize; ll mode; vll par; vll rank; vll dweight; wUFT() {} wUFT(const wUFT &wuft) {} wUFT(ll tsizeget, ll modeget = 0) { tsize = tsizeget; mode = modeget; par.asn(tsize, -1); if (!mode) rank.res(tsize, 0); dweight.asn(tsize, 0); } ll root(ll x) { if (par[x] < 0) return x; else { ll r = root(par[x]); dweight[x] += dweight[par[x]]; return par[x] = r; } } ll weight(ll x) { root(x); return dweight[x]; } ll diff(ll x, ll y) { return weight(y) - weight(x); } bool isRoot(ll x) { return x == root(x); } bool same(ll x, ll y) { return root(x) == root(y); } void merge(ll x, ll y, ll w) { w += weight(x); w -= weight(y); x = root(x); y = root(y); if (x == y) return; if (mode) { par[x] += par[y]; par[y] = x; } else { if (rank[x] < rank[y]) { par[y] += par[x]; par[x] = y; dweight[x] = -w; } else { par[x] += par[y]; par[y] = x; if (rank[x] == rank[y]) rank[x]++; dweight[y] = w; } } } ll size(ll x) { return -par[root(x)]; } }; template <typename valtype> class SegT { public: ll size; vector<valtype> v; valtype initv; function<valtype(valtype x, valtype y)> calc; SegT() {} SegT(const SegT &segt) {} SegT(ll sizeget, ll modeget = 0) { sizeset(sizeget); modeset(modeget); init(); } SegT(vector<valtype> cpyvec, ll modeget = 0) { sizeset(cpyvec.sz); modeset(modeget); init(); copy(cpyvec); } SegT(ll sizeget, valtype initvget, function<valtype(valtype x, valtype y)> calcget) { sizeset(sizeget); initv = initvget; calc = calcget; init(); } SegT(vector<valtype> cpyvec, valtype initvget, function<valtype(valtype x, valtype y)> calcget) { sizeset(cpyvec.sz); initv = initvget; calc = calcget; init(); copy(cpyvec); } void sizeset(ll rsize) { size = DigN2(rsize); if (rsize == Pow2(size - 1)) size--; return; } void modeset(ll mode) { switch (mode) { case 0: initv = 0; calc = [](valtype x, valtype y) { return x + y; }; break; case 1: initv = INF; calc = [](valtype x, valtype y) { return min(x, y); }; break; case 2: initv = -INF; calc = [](valtype x, valtype y) { return max(x, y); }; break; } return; } void init() { v.asn(Pow2(size + 1) - 1, initv); } void copy(vector<valtype> cpyvec) { REP(i, min(cpyvec.sz, Pow2(size))) set(i, cpyvec[i]); } ll i2v(ll i) const { if (i < 0 || i >= Pow2(size)) return -1; return Pow2(size) + i - 1; } ll top(ll i) const { if (i == 0) return -1; return (i - 1) / 2; } pl bot(ll i) const { if (i + 1 >= Pow2(size)) return mp(-1, -1); return mp(2 * i + 1, 2 * i + 2); } void set(ll i, valtype x) { i = i2v(i); v[i] = x; while (i > 0) { i = top(i); v[i] = calc(v[bot(i).fi], v[bot(i).se]); } return; } void add(ll i, valtype x) { set(i, v[i2v(i)] + x); return; } valtype operator[](const ll &i) const { return v[i2v(i)]; } // valtype que(ll a = 0, ll b = Pow2(size) - 1) { valtype que(ll a, ll b) { if (a == b) return v[i2v(a)]; if (a > b) return initv; // swap(a, b); valtype ans = initv; ll ai = i2v(a); ll bi = i2v(b); FOR(i, 1, size + 1) { if (a > b) break; if (a % Pow2(i)) { ans = calc(ans, v[ai]); a += Pow2(i - 1); ai = top(ai) + 1; } else { ai = top(ai); } if (a > b) break; if ((b + 1) % Pow2(i)) { ans = calc(ans, v[bi]); b -= Pow2(i - 1); bi = top(bi) - 1; } else { bi = top(bi); } if (a > b) break; } return ans; } valtype que(ll b) { return que(0, b); } valtype que() { return que(0, Pow2(size) - 1); } }; /*template <class Type> class DP { public: vector<Type> v; Type initv; vll size, block; DP() {} DP(const DP &dp) {} template<class... Args> DP(Args... args) { block.asn(1, 1); Initialize(args...); } void Initialize(Type initv_) { initv = initv_; v.asn(block.bk, initv); } template<class... Args> void Initialize(ll val, Args... args) { size.pb(val); block.pb(block.bk*val); Initialize(args...); } };*/ pl Bezout(ll a, ll b) { if (b != 0) { pl xy; xy = Bezout(b, a % b); return mp(xy.se, xy.fi - ((a / b) * xy.se)); } else { return mp(1, 0); } } pl Bez(ll a, ll b, ll c) { pl xy; ll x, y, z, gc; xy = Bezout(a, b); gc = gcd(a, b); if (c % gc != 0) return mp(-1, -1); x = xy.fi * (c / gc); y = xy.se * (c / gc); if (x < 0) z = rup(-x, (b / gc)); if (x >= 0) z = -x / (b / gc); x += z * (b / gc); y -= z * (a / gc); return mp(x, y); } ll DigS10(ll n) { ll ans = 0; while (1) { ans += n % 10; n /= 10; if (!n) break; } return ans; } ll isP(ll n) { if (n <= 1) return 0; FOR(i, 2, (ll)sqrt(n) + 1) { if (n % i == 0) return 0; } return 1; } ll Tot(ll n) { if (n <= 0) return 0; ll ans = n, x = 2; while (x * x <= n) { if (n % x == 0) { ans -= ans / x; while (n % x == 0) n /= x; } x++; } if (n > 1) ans -= ans / n; return ans; } template <class T> struct Graph { public: ll vSize; ll eMode; ll mapMode; ActPair(T) Add; BoolPair(T) Lesser; BoolPair(T) Equal; V<V<P<T, ll>>> adj; map<pl, T> len; Graph(ll vSize, ll eMode = 0, ll mapMode = 0, ActPair(T) Add = ADD, BoolPair(T) Lesser = LES, BoolPair(T) Equal = EQ) : vSize(vSize), eMode(eMode), mapMode(mapMode), Add(Add), Lesser(Lesser), Equal(Equal) { Init(); } void Init() { adj.asn(vSize, V<P<T, ll>>()); } void AddE(ll x, ll y, T cost) { iAddE(x, y, cost); if (!eMode) iAddE(y, x, cost); } void iAddE(ll x, ll y, T cost) { adj[x].pb(mp(cost, y)); if (mapMode) len[mp(x, y)] = cost; } P<bool, T> getE(ll x, ll y) { if (!len.count(mp(x, y))) return mp(false, Lesser.fi); return mp(true, len[mp(x, y)]); } V<T> Dijk(ll x) { V<T> ans(vSize, Lesser.fi); if (x < 0 || x >= vSize) return ans; SegT<P<T, ll>> segt(vSize, mp(Lesser.fi, -1), clam(if (l.se < 0) return r; if (r.se < 0) return l; return Lesser.se(l.fi, r.fi) ? l : r;)); segt.set(x, mp(Add.fi, x)); P<T, ll> now; while ((now = segt.que(0, vSize - 1)).se >= 0) { ans[now.se] = segt[now.se].fi; segt.set(now.se, mp(Lesser.fi, -2)); ROR(adj[now.se], i) { if (segt[i.se].se == -2) continue; if (segt[i.se].se == -1) { segt.set(i.se, mp(Add.se(ans[now.se], i.fi), i.se)); continue; } if (Lesser.se(Add.se(ans[now.se], i.fi), segt[i.se].fi)) { segt.set(i.se, mp(Add.se(ans[now.se], i.fi), i.se)); continue; } } } return ans; } V<P<T, vll>> rDijk(ll x) { V<P<T, vll>> ans(vSize, mp(Lesser.fi, vll())); if (x < 0 || x >= vSize) return ans; SegT<P<T, ll>> segt(vSize, mp(Lesser.fi, -1), clam(if (l.se < 0) return r; if (r.se < 0) return l; return Lesser.se(l.fi, r.fi) ? l : r;)); segt.set(x, mp(Add.fi, x)); P<T, ll> now; while ((now = segt.que(0, vSize - 1)).se >= 0) { ans[now.se].fi = segt[now.se].fi; segt.set(now.se, mp(Lesser.fi, -2)); ROR(adj[now.se], i) { if (segt[i.se].se == -2) continue; if (segt[i.se].se == -1) { segt.set(i.se, mp(Add.se(ans[now.se].fi, i.fi), i.se)); ans[i.se].se = {now.se}; continue; } if (Lesser.se(Add.se(ans[now.se].fi, i.fi), segt[i.se].fi)) { segt.set(i.se, mp(Add.se(ans[now.se].fi, i.fi), i.se)); ans[i.se].se = {now.se}; continue; } if (Equal.se(Add.se(ans[now.se].fi, i.fi), segt[i.se].fi)) { ans[i.se].se.pb(now.se); continue; } } } return ans; } T Prim(ll x = 0) { T ans = Add.fi; if (x < 0 || x >= vSize) return ans; SegT<P<T, ll>> segt(vSize, mp(Lesser.fi, -1), clam(if (l.se < 0) return r; if (r.se < 0) return l; return Lesser.se(l.fi, r.fi) ? l : r;)); segt.set(x, mp(Add.fi, x)); P<T, ll> now; while ((now = segt.que(0, vSize - 1)).se >= 0) { ans = Add.se(ans, segt[now.se].fi); segt.set(now.se, mp(Lesser.fi, -2)); ROR(adj[now.se], i) { if (segt[i.se].se == -2) continue; if (segt[i.se].se == -1) { segt.set(i.se, i); continue; } if (Lesser.se(i.fi, segt[i.se].fi)) { segt.set(i.se, i); continue; } } } return ans; } P<T, V<P<T, vll>>> rPrim(ll x = 0) { P<T, V<P<T, vll>>> ans = mp(Add.fi, V<P<T, vll>>(vSize, mp(Lesser.fi, vll()))); if (x < 0 || x >= vSize) return ans; SegT<P<T, ll>> segt(vSize, mp(Lesser.fi, -1), clam(if (l.se < 0) return r; if (r.se < 0) return l; return Lesser.se(l.fi, r.fi) ? l : r;)); segt.set(x, mp(Add.fi, x)); P<T, ll> now; while ((now = segt.que(0, vSize - 1)).se >= 0) { ans.se[now.se].fi = segt[now.se].fi; ans.fi = Add.se(ans.fi, ans.se[now.se].fi); segt.set(now.se, mp(Lesser.fi, -2)); ROR(adj[now.se], i) { if (segt[i.se].se == -2) continue; if (segt[i.se].se == -1) { segt.set(i.se, i); ans.se[i.se].se = {now.se}; continue; } if (Lesser.se(i.fi, segt[i.se].fi)) { segt.set(i.se, i); ans.se[i.se].se = {now.se}; continue; } if (Equal.se(i.fi, segt[i.se].fi)) { ans.se[i.se].se.pb(now.se); continue; } } } return ans; } }; template <class T> struct Sum { public: V<T> v, s; ll size; ActPair(T) Add; ActPair(T) Sub; Sum(V<T> v, ActPair(T) Add = ADD, ActPair(T) Sub = SUB) : v(v), size(v.sz), Add(Add), Sub(Sub) { Init(); Calc(); } void Init() { s.asn(size + 1, Add.fi); } void Calc() { REP(i, size) s[i + 1] = Add.se(s[i], v[i]); } T operator()(ll x) { if (x < -1) x = -1; if (x > size - 1) x = size - 1; return s[x + 1]; } T operator()(ll l, ll r) { if (l < 0) l = 0; if (r >= size) r = size - 1; if (l > r) return Add.fi; return Sub.se(s[r + 1], s[l]); } }; using sumll = Sum<ll>; template <class T> struct Sum2 { public: V<V<T>> v, s; ll RowSize, ColumnSize; ActPair(T) Add; ActPair(T) Sub; Sum2(V<V<T>> v, ActPair(T) Add = ADD, ActPair(T) Sub = SUB) : v(v), RowSize(v.sz), ColumnSize(v.sz ? v[0].sz : 0), Add(Add), Sub(Sub) { Init(); Calc(); } void Init() { s.asn(RowSize + 1, V<T>(ColumnSize + 1, Add.fi)); } void Calc() { REP1(r, RowSize) { REP1(c, ColumnSize) { // s[r][c] = Sub.se(Add.se(Add.se(v[r - 1][c - //1], operator()(r - 1, c - 2)), operator()(r - 2, c - 1)), operator()(r //- 2, c - 2)); s[r][c] = Add.se(s[r][c - 1], v[r - 1][c - 1]); } } REP1(r, RowSize) { REP1(c, ColumnSize) { s[r][c] = Add.se(s[r - 1][c], s[r][c]); } } } T operator()(ll r, ll c) { if (r < -1) r = -1; if (c < -1) c = -1; if (r > RowSize - 1) r = RowSize - 1; if (c > ColumnSize - 1) c = ColumnSize - 1; return s[r + 1][c + 1]; } T operator()(ll r1, ll c1, ll r2, ll c2) { if (r1 < 0) r1 = 0; if (c1 < 0) c1 = 0; if (r2 >= RowSize) r2 = RowSize - 1; if (c2 >= ColumnSize) c2 = ColumnSize - 1; if (r1 > r2) return Add.fi; if (c1 > c2) return Add.fi; return Sub.se(Add.se(s[r2 + 1][c2 + 1], s[r1][c1]), Add.se(s[r2 + 1][c1], s[r1][c2 + 1])); } }; using sumll2 = Sum2<ll>; template <class T> struct Point2 { public: V<V<T>> v; ll h, w; Point2() : h(0), w(0) {} Point2(ll h, ll w) : h(h), w(w) { asn(h, w); } Point2(ll h, ll w, T val) : h(h), w(w) { asn(h, w, val); } void assign(ll h, ll w) { v.asn(h, V<T>(w)); } void assign(ll h, ll w, ll val) { v.asn(h, V<T>(w, val)); } T &operator()(ll h, ll w) { return v[h][w]; } T &operator()(pl p) { return v[p.fi][p.se]; } }; template <class T> using P2 = Point2<T>; template <ll Mod> struct Modll { public: ll v; Modll() : v(0) {} Modll(ll _v) { set(_v % Mod + Mod); } Modll &set(ll _v) { v = (_v < Mod) ? _v : (_v - Mod); return *this; } Modll pow(ll n) const { Modll x = *this, ans = 1; while (n) { if (n & 1) ans *= x; x *= x; n >>= 1; } return ans; } Modll inverse() const { return (*this).pow(Mod - 2); } Modll operator+(const Modll &m) const { return Modll().set(v + m.v); } Modll operator-(const Modll &m) const { return Modll().set(Mod + v - m.v); } Modll operator*(const Modll &m) const { return Modll().set((ull(v) * m.v) % Mod); } Modll operator/(const Modll &m) const { return *this * m.inv; } Modll &operator+=(const Modll &m) { return *this = *this + m; } Modll &operator-=(const Modll &m) { return *this = *this - m; } Modll &operator*=(const Modll &m) { return *this = *this * m; } Modll &operator/=(const Modll &m) { return *this = *this / m; } Modll operator-() const { return Modll(0) - *this; } explicit operator bool() const { return v != 0; } friend istream &operator>>(istream &in, Modll &m) { return in >> m.v; } friend ostream &operator<<(ostream &out, const Modll &m) { return out << m.v; } }; using mll = Modll<MOD>; using vmll = V<mll>; using vvmll = V<vmll>; using vvvmll = V<vvmll>; vmll MFactMemo(2, 1); vmll MIFactMemo(2, 1); mll mFact(ll n) { if (MFactMemo.sz <= n) { ll oldsize = MFactMemo.sz; MFactMemo.res(n + 1, 1); FOR(i, oldsize, n) MFactMemo[i] = MFactMemo[i - 1] * i; } return MFactMemo[n]; } mll miFact(ll n) { if (MIFactMemo.sz <= n) { ll oldsize = MIFactMemo.sz; MIFactMemo.res(n + 1, 1); MIFactMemo.bk = mFact(n).inv; rFOR(i, oldsize + 1, n) MIFactMemo[i - 1] = MIFactMemo[i] * i; } return MIFactMemo[n]; } mll mComb(ll n, ll k) { if (n < 0 || k < 0 || n < k) return 0; return mFact(n) * miFact(k) * miFact(n - k); } ll LIS(vll v, ll m = 0) { if (v.sz > 0) { ll ans = 0; vll dp(v.sz, INF); FOR(i, 0, v.sz - 1) { dp[m ? UPB(dp, v[i]) : LOWB(dp, v[i])] = v[i]; } FOR(i, 0, v.sz - 1) { if (dp[i] == INF) break; ans++; } return ans; } else { return 0; } } ll Bsrch(function<bool(ll x)> f, ll mi, ll ma) { ll ng = mi - 1, ok = ma, mid; while (ok - ng > 1) { mid = (ng + ok) / 2; (f(mid) ? ok : ng) = mid; } return ok; } template <class T> V<V<T>> MultiMatrix(V<V<T>> A, V<V<T>> B, ActPair(T) Mul = MUL, ActPair(T) Add = ADD) { V<V<T>> ans; ll ii = A.sz; if (!ii) return ans; ll jj = A[0].sz; if (!jj) return ans; ll jj2 = B.sz; if (!jj2) return ans; if (jj != jj2) return ans; ll kk = B[0].sz; if (!kk) return ans; ans.asn(ii, V<T>(kk, 0)); REP(i, ii) { REP(k, kk) { REP(j, jj) { ans[i][k] = Add.se(ans[i][k], Mul.se(A[i][j], B[j][k])); } } } return ans; } vvll CombMemo(1000, vll(1000, -1)); ll Comb(ll n, ll k) { if ((n < 0) || (k < 0)) return 0; if (CombMemo[n][k] == -1) { if (n < k) CombMemo[n][k] = 0; else { if (n == 0) CombMemo[n][k] = 1; else if (k == 0) CombMemo[n][k] = 1; else if (n == k) CombMemo[n][k] = 1; else CombMemo[n][k] = Comb(n - 1, k - 1) + Comb(n - 1, k); } } return CombMemo[n][k]; } template <class T> map<T, ll> Dict(V<T> v) { map<T, ll> m; if (!v.sz) return m; SORT(v); UNIQUE(v); REP(i, v.sz) { m[v[i]] = i; } return m; } template <class T> vll Cmprs(V<T> v) { auto m = Dict(v); vll ans(v.sz); REP(i, v.sz) { ans[i] = m[v[i]]; } return ans; } template <class T> vll PCmprs(V<T> v) { if (v.sz == 0) return V<T>(); vll tmp(v.sz); vll ans(v.sz); IOTA(tmp, 0); IOTA(ans, 0); sort(tmp.bgn, tmp.en, clam(return v[l] < v[r];)); sort(ans.bgn, ans.en, clam(return tmp[l] < tmp[r];)); return ans; } ll BblCnt(vll rv) { vll v = PCmprs(rv); SegT<ll> b(v.sz, 0); ll ans = 0; REP(i, v.sz) { ans += (i - b.que(0, v[i])); b.add(v[i], 1); } return ans; } template <class T> auto ven(T val) { return val; } template <> auto ven<int>(int val) { return (ll)val; } template <class T, class... Args> auto ven(T val, Args... args) { auto tmp = ven(args...); return V<decltype(tmp)>(val, tmp); } template <class T> void zind(T &v) { v--; } template <class T> void zind(V<T> &v) { ROR(v, i) zind(i); } template <class T, class... Args> void zind(T &v, Args &...args) { zind(v); zind(args...); } void Solve(); signed main() { cin.tie(0); ios::sync_with_stdio(false); cout << setprecision(20) << fixed; Solve(); } void Solve() { li(n); vlc(n, a, b); vpl c(n); REP(i, n) c[i] = mp(a[i] + b[i], i); sort(c.bgn, c.en, lam(return l.fi > r.fi;)); sal(c); ll t = 0, u = 0, uu = 0; REP(i, n) { if (i % 2 == 0) u += a[c[i].se]; if (i % 2 == 1) uu += b[c[i].se]; } /* while (t < n) { u += a[c[t].se]; t++; if (t == n) break; u -= b[c[t].se]; t++; }*/ sal(u - uu); }
#include <bits/stdc++.h> using namespace std; template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; template <class T> using VVV = V<VV<T>>; template <class S, class T> using P = pair<S, T>; template <class S, class T, class U> using TP = tuple<S, T, U>; using ll = long long; using ull = unsigned long long; using dbl = double; using str = string; using vll = V<ll>; using vvll = V<vll>; using vvvll = V<vvll>; using pl = P<ll, ll>; using tl = TP<ll, ll, ll>; using vpl = V<pl>; using vvpl = V<vpl>; using vtl = V<tl>; using vvtl = V<vtl>; using vs = V<str>; using vvs = V<vs>; using vd = V<dbl>; using vvd = V<vd>; using qll = queue<ll>; using qpl = queue<pl>; using stll = stack<ll>; using stpl = stack<pl>; using mapll = map<ll, ll>; using setll = set<ll>; using pqll = priority_queue<ll>; //#define int ll #define fi first #define se second #define mp make_pair #define mt make_tuple #define pb push_back #define pob pop_back() #define pf push_front #define pof pop_front() #define sz size() #define bgn begin() #define en end() #define asn assign #define emp empty() #define fr front() #define bk back() #define clr clear() #define ins insert #define ers erase #define res resize #define tp top() #define p_q priority_queue #define inv inverse() #define FOR(i, a, b) for (ll i = (a); i <= (ll)(b); i++) #define rFOR(i, a, b) for (ll i = (b); i >= (ll)(a); i--) #define REP(i, a) FOR((i), 0, (ll)(a)-1) #define REP0(i, a) FOR((i), 0, (ll)(a)) #define REP1(i, a) FOR((i), 1, (ll)(a)) #define rREP(i, a) rFOR((i), 0, (ll)(a)-1) #define rREP0(i, a) rFOR((i), 0, (ll)(a)) #define rREP1(i, a) rFOR((i), 1, (ll)(a)) #define ROR(v, i) for (auto &(i) : (v)) #define IOTA(a, n) iota((a).bgn, (a).en, (n)) #define SORT(a) sort((a).bgn, (a).en) #define rSORT(a) sort((a).rbegin(), (a).rend()) #define UNIQUE(a) (a).erase(unique((a).bgn, (a).en), (a).en) #define PREVP(a) prev_permutation((a).bgn, (a).en) #define NEXTP(a) next_permutation((a).bgn, (a).en) #define BINS(a, b) binary_search((a).bgn, (a).en, (b)) #define LOWB(a, b) (lower_bound((a).bgn, (a).en, (b)) - (a).bgn) #define UPB(a, b) (upper_bound((a).bgn, (a).en, (b)) - (a).bgn) #define CNT(a, b) count((a).bgn, (a).en, b) #define SUM(a) accumulate((a).bgn, (a).en, 0) #define REV(a) reverse((a).bgn, (a).en) #define REGS(a, b) regex_search((a), regex(b)) #define REGM(a, b) regex_match((a), regex(b)) #define yn(a) cout << ((a) ? "yes" : "no") << "\n"; #define Yn(a) cout << ((a) ? "Yes" : "No") << "\n"; #define YN(a) cout << ((a) ? "YES" : "NO") << "\n"; #define imp(a) cout << ((a) ? "possible" : "impossible") << "\n"; #define Imp(a) cout << ((a) ? "Possible" : "Impossible") << "\n"; #define IMP(a) cout << ((a) ? "POSSIBLE" : "IMPOSSIBLE") << "\n"; #define fs(a) cout << ((a) ? "second" : "first") << "\n"; #define Fs(a) cout << ((a) ? "Second" : "First") << "\n"; #define FS(a) cout << ((a) ? "SECOND" : "FIRST") << "\n"; //#define say(a) cout <<(a); //#define sal(a) cout <<(a)<<"\n"; #define sak cout << "\n"; #define sas cout << " "; #define sat cout << "\t"; #define dbg(a) cerr << (#a) << ": " << (a) << "\n"; #define dbgs(...) \ dal(#__VA_ARGS__); \ dal(__VA_ARGS__); #define c2l(a) ((ll)(a - 48)) #define a2l(a) ((ll)(a - 97)) #define A2l(a) ((ll)(a - 65)) #define l2c(a) ((char)(a + 48)) #define l2a(a) ((char)(a + 97)) #define l2A(a) ((char)(a + 65)) #define DigN2(a) ((llabs(a) == 0) ? (1) : ((ll)(log2(double(llabs(a)))) + 1)) #define DigN10(a) ((llabs(a) == 0) ? (1) : ((ll)(log10(double(llabs(a)))) + 1)) #define Dig2(a, b) (((a) >> (b)) & 1) #define Dig10(a, b) (ll)(((a) / ((ll)(pow(10.0, (double)(b))))) % 10) #define Pow2(a) ((ll)(1) << (a)) #define Pow10(a) ((ll)(pow(10.0, double(a)))) #define LSB(a) ((a) & (-(a))) /*#define llin(a) ll (a);cin >>(a); #define llin2(a,b) ll (a),(b);cin >>(a)>>(b); #define llin3(a,b,c) ll (a),(b),(c);cin >>(a)>>(b)>>(c); #define stin(a) string (a);cin >>(a);*/ #define vin(v) \ ROR((v), (i)) { cin >> (i); }; #define vllin(v, N) \ vll(v)((N)); \ vin(v); #define vllin2(a, b, N) \ vll(a)(N), (b)(N); \ REP(i, N) { cin >> (a)[i] >> (b)[i]; }; #define vsin(v, N) \ vs(v)((N)); \ vin(v); #define rdn(a, b) ((a) / (b)) #define rou(a, b) \ ((((double(a) / double(b)) - ((a) / (b))) < 0.5) ? ((a) / (b)) \ : (((a) / (b)) + 1)) #define rup(a, b) ((((a) % (b)) == 0) ? ((a) / (b)) : (((a) / (b)) + 1)) #define powll(a, b) (ll)(pow((double)(a), (double)(b))) #define Triangle(x1, y1, x2, y2, x3, y3) \ (((x1) - (x2)) * ((y1) - (y3)) - ((x1) - (x3)) * ((y1) - (y2))) #define lam(lr) ([](auto l, auto r) { lr }) #define elam(lr) ([=](auto l, auto r) { lr }) #define clam(lr) ([&](auto l, auto r) { lr }) #define min(...) Operation(MIN, __VA_ARGS__) #define max(...) Operation(MAX, __VA_ARGS__) #define gcd(...) Operation(GCD, __VA_ARGS__) #define lcm(...) Operation(LCM, __VA_ARGS__) #define vmin(...) VOperation(MIN, __VA_ARGS__) #define vmax(...) VOperation(MAX, __VA_ARGS__) #define vgcd(...) VOperation(GCD, __VA_ARGS__) #define vlcm(...) VOperation(LCM, __VA_ARGS__) #define vsum(...) VOperation(ADD, __VA_ARGS__) #define vpro(...) VOperation(MUL, __VA_ARGS__) #define emin(a, ...) ((a) = min((a), __VA_ARGS__)) #define emax(a, ...) ((a) = max((a), __VA_ARGS__)) #define egcd(a, ...) ((a) = gcd((a), __VA_ARGS__)) #define elcm(a, ...) ((a) = lcm((a), __VA_ARGS__)) #define ActPair(T) P<T, function<T(T, T)>> #define BoolPair(T) P<T, function<bool(T, T)>> #define ope Operation #define vope VOperation #define svll SumV<ll> #define svvll SumV2<ll> #define li(...) \ ll __VA_ARGS__; \ Input(__VA_ARGS__); #define si(...) \ str __VA_ARGS__; \ Input(__VA_ARGS__); //#define vli(size, ...) vll __VA_ARGS__;vInitInput(size,__VA_ARGS__); #define vlr(size, ...) \ vll __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vlc(size, ...) \ vll __VA_ARGS__; \ vInitInputC(size, __VA_ARGS__); #define vli(size, ...) \ vll __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vsr(size, ...) \ vs __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vsc(size, ...) \ vs __VA_ARGS__; \ vInitInputC(size, __VA_ARGS__); #define vsi(size, ...) \ vs __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vli2(rowSize, columnSize, ...) \ vvll __VA_ARGS__; \ vInitInput2(rowSize, columnSize, __VA_ARGS__); #define vplr(size, ...) \ vpl __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vplc(size, ...) \ vpl __VA_ARGS__; \ vInitInputC(size, __VA_ARGS__); #define vpli(size, ...) \ vpl __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); const ll MOD = 1e9 + 7; // const ll MOD = 998244353; // const ll MOD = 924844033; // const ll MOD = 9007199254740881; const ll INF = 1LL << 60; // 1.15e18 const double PI = acos(-1.0); const vll DX = {0, -1, 0, 1, 0, -1, 1, 1, -1}; const vll DY = {0, 0, -1, 0, 1, -1, -1, 1, 1}; const str alp = "abcdefghijklmnopqrstuvwxyz"; const str ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; template <class S, class T> istream &operator>>(istream &in, P<S, T> &p) { return in >> p.fi >> p.se; } template <class T> istream &operator>>(istream &in, V<T> &v) { REP(i, v.sz) in >> v[i]; return in; } void Input() {} template <class Var, class... Args> void Input(Var &var, Args &...args) { cin >> var; Input(args...); } void vInit(ll size) {} template <class T, class... Args> void vInit(ll size, V<T> &v, Args &...args) { v.res(size); vInit(size, args...); } void vInput(ll size) {} template <class T, class... Args> void vInput(ll size, V<T> &v, Args &...args) { REP(i, size) cin >> v[i]; vInput(size, args...); } void vInputR(ll size) {} template <class T, class... Args> void vInputR(ll size, V<T> &v, Args &...args) { REP(i, size) cin >> v[i]; vInputR(size, args...); } void vInputNumC(ll num) {} template <class T, class... Args> void vInputNumC(ll num, V<T> &v, Args &...args) { cin >> v[num]; vInputNumC(num, args...); } void vInputC(ll size) {} template <class... Args> void vInputC(ll size, Args &...args) { REP(i, size) vInputNumC(i, args...); } void vInitInputR(ll size) {} template <class... Args> void vInitInputR(ll size, Args &...args) { vInit(size, args...); vInputR(size, args...); } void vInitInputC(ll size) {} template <class... Args> void vInitInputC(ll size, Args &...args) { vInit(size, args...); vInputC(size, args...); } void vInit2(ll rowSize, ll columnSize) {} template <class T, class... Args> void vInit2(ll rowSize, ll columnSize, V<V<T>> &v, Args &...args) { v.asn(rowSize, V<T>(columnSize)); vInit2(rowSize, columnSize, args...); } void vInput2(ll rowSize, ll columnSize) {} template <class T, class... Args> void vInput2(ll rowSize, ll columnSize, V<V<T>> &v, Args &...args) { REP(r, rowSize) { REP(c, columnSize) { cin >> v[r][c]; } } vInput2(rowSize, columnSize, args...); } void vInitInput2(ll rowSize, ll columnSize) {} template <class... Args> void vInitInput2(ll rowSize, ll columnSize, Args &...args) { vInit2(rowSize, columnSize, args...); vInput2(rowSize, columnSize, args...); } template <class S, class T> ostream &operator<<(ostream &out, const P<S, T> &p) { return out << "[" << p.fi << ", " << p.se << "]"; } template <class T> ostream &operator<<(ostream &out, V<T> &v) { if (v.emp) return out << "{}"; else { auto itr = v.bgn; out << "{" << *itr; itr++; while (itr != v.en) { out << ", " << *itr; itr++; } out << "}"; return out; } } template <class S, class T> ostream &operator<<(ostream &out, const map<S, T> &m) { if (m.emp) return out << "<[]>"; else { auto itr = m.bgn; out << "< [" << (itr->fi) << ": " << (itr->se); itr++; while (itr != m.en) { out << "], [" << (itr->fi) << ": " << (itr->se); itr++; } out << "] >"; return out; } } template <class T> ostream &operator<<(ostream &out, const set<T> &s) { if (s.emp) return out << "<>"; else { auto itr = s.bgn; out << "<" << *itr; itr++; while (itr != s.en) { out << ", " << *itr; itr++; } out << ">"; return out; } } void say() {} template <class T> void say(T t) { cout << t; } template <class Head, class... Body> void say(Head head, Body... body) { cout << head << " "; say(body...); } void sal() { cout << "\n"; } template <class... Args> void sal(Args... args) { say(args...); cout << "\n"; } void day() {} template <class T> void day(T t) { cerr << t; } template <class Head, class... Body> void day(Head head, Body... body) { cerr << head << " "; day(body...); } void dal() { cerr << "\n"; } template <class... Args> void dal(Args... args) { day(args...); cerr << "\n"; } void salv() {} template <class T> void salv(V<T> v) { if (v.emp) sal(); else { auto itr = v.bgn; say(*itr); itr++; while (itr != v.en) { sas; say(*itr); itr++; } sak; } } template <class T> void salv(V<V<T>> v) { if (v.emp) sal(); else { ROR(v, i) salv(i); } } template <class T, class... Args> void salv(T v, Args... args) { salv(v); salv(args...); } template <class L, class R> auto Gcd(L l, R r) -> decltype(l + r) { if (l < r) swap(l, r); return r ? Gcd(r, l % r) : l; } template <class L, class R> auto Lcm(L l, R r) { if (!l || !r) return 0; return l / Gcd(l, r) * r; } auto LES = mp(INF, lam(return l < r;)); auto GRT = mp(-INF, lam(return l > r;)); auto EQ = mp(0, lam(return l == r;)); auto ADD = mp(0, lam(return l + r;)); auto SUB = mp(0, lam(return l - r;)); auto MUL = mp(1, lam(return l * r;)); auto DIV = mp(1, lam(return l / r;)); auto MDL = mp(1, lam(return l % r;)); auto XOR = mp(0, lam(return l ^ r;)); auto OR = mp(0, lam(return l | r;)); auto AND = mp(((ll)(1) << 63) - 1, lam(return l & r;)); auto MIN = mp(INF, lam(return (l < r) ? l : r;)); auto MAX = mp(-INF, lam(return (l > r) ? l : r;)); auto GCD = mp(0, lam(return Gcd(l, r);)); auto LCM = mp(1, lam(return Lcm(l, r);)); /* auto ADD = mp(0, [](auto l, auto r) { return l + r; }); auto SUB = mp(1, [](auto l, auto r) { return l - r; }); auto MUL = mp(1, [](auto l, auto r) { return l * r; }); auto DIV = mp(0, [](auto l, auto r) { return l / r; }); auto MDL = mp(0, [](auto l, auto r) { return l % r; }); auto XOR = mp(0, [](auto l, auto r) { return l ^ r; }); auto OR = mp(0, [](auto l, auto r) { return l | r; }); auto AND = mp(((ll)(1) << 63) - 1, [](auto l, auto r) { return l & r; }); auto MIN = mp(INF, [](auto l, auto r) { return (l < r) ? l : r; }); auto MAX = mp(-INF, [](auto l, auto r) { return (l > r) ? l : r; }); auto GCD = mp(0, [](auto l, auto r) { return gcd(l, r); }); auto LCM = mp(1, [](auto l, auto r) { return lcm(l, r); }); */ template <class OperationType> auto Operation(OperationType A) { return A.fi; } template <class OperationType, class T> auto Operation(OperationType A, T x) { return x; } template <class OperationType, class T, class... Args> auto Operation(OperationType A, T x, Args... args) { auto tmp = Operation(A, args...); return A.se(x, tmp); } template <class OperationType> auto VOperation(OperationType A) { return A.fi; } template <class OperationType, class T> auto VOperation(OperationType A, T x) { return x; } template <class OperationType, class T> auto VOperation(OperationType A, V<T> x) { T tmp = A.fi; ROR(x, i) tmp = A.se(tmp, i); return tmp; } template <class OperationType, class T> auto VOperation(OperationType A, V<V<T>> x) { T tmp = A.fi; ROR(x, i) ROR(i, j) tmp = A.se(tmp, j); return tmp; } template <class OperationType, class T> auto VOperation(OperationType A, V<V<V<T>>> x) { T tmp = A.fi; ROR(x, i) ROR(i, j) ROR(j, k) tmp = A.se(tmp, k); return tmp; } template <class OperationType, class T> auto VOperation(OperationType A, V<V<V<V<T>>>> x) { T tmp = A.fi; ROR(x, i) ROR(i, j) ROR(j, k) ROR(k, l) tmp = A.se(tmp, l); return tmp; } template <class OperationType, class T, class... Args> auto VOperation(OperationType A, T x, Args... args) { auto xResult = VOperation(A, x); auto tmp = VOperation(A, args...); return A.se(xResult, tmp); } ll Bset(ll a, ll b, ll c) { if (c) a |= b; else a &= ~b; return a; } struct UFT { public: ll tsize; ll mode; vll par; vll rank; UFT() {} UFT(const UFT &uft) {} UFT(ll tsizeget, ll modeget = 0) { tsize = tsizeget; mode = modeget; par.asn(tsize, -1); if (!mode) rank.res(tsize, 0); } ll root(ll x) { return par[x] < 0 ? x : par[x] = root(par[x]); } bool isRoot(ll x) { return x == root(x); } bool same(ll x, ll y) { return root(x) == root(y); } void merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) return; if (mode) { par[x] += par[y]; par[y] = x; } else { if (rank[x] < rank[y]) { par[y] += par[x]; par[x] = y; } else { par[x] += par[y]; par[y] = x; if (rank[x] == rank[y]) rank[x]++; } } } ll size(ll x) { return -par[root(x)]; } }; struct pUFT { public: ll tsize; ll now; vll par; vll rank; vll mtime; vvll sizepi; vvll sizepv; pUFT() {} pUFT(const pUFT &puft) {} pUFT(ll tsizeget) { tsize = tsizeget; now = 0; par.asn(tsize, -1); rank.asn(tsize, 0); mtime.asn(tsize, INF); sizepi.asn(tsize, {0}); sizepv.asn(tsize, {1}); } ll root(ll x, ll t) { return (mtime[x] > t) ? x : root(par[x], t); } bool same(ll x, ll y, ll t) { return root(x, t) == root(y, t); } ll merge(ll x, ll y) { now++; x = root(x, now); y = root(y, now); if (x != y) { if (rank[x] < rank[y]) { par[y] += par[x]; sizepi[y].pb(now); sizepv[y].pb(-par[y]); par[x] = y; mtime[x] = now; } else { par[x] += par[y]; sizepi[x].pb(now); sizepv[x].pb(-par[x]); par[y] = x; mtime[y] = now; if (rank[x] == rank[y]) rank[x]++; } } return now; } ll size(ll x, ll t) { x = root(x, t); return sizepv[x][UPB(sizepi[x], t) - 1]; } }; struct wUFT { public: ll tsize; ll mode; vll par; vll rank; vll dweight; wUFT() {} wUFT(const wUFT &wuft) {} wUFT(ll tsizeget, ll modeget = 0) { tsize = tsizeget; mode = modeget; par.asn(tsize, -1); if (!mode) rank.res(tsize, 0); dweight.asn(tsize, 0); } ll root(ll x) { if (par[x] < 0) return x; else { ll r = root(par[x]); dweight[x] += dweight[par[x]]; return par[x] = r; } } ll weight(ll x) { root(x); return dweight[x]; } ll diff(ll x, ll y) { return weight(y) - weight(x); } bool isRoot(ll x) { return x == root(x); } bool same(ll x, ll y) { return root(x) == root(y); } void merge(ll x, ll y, ll w) { w += weight(x); w -= weight(y); x = root(x); y = root(y); if (x == y) return; if (mode) { par[x] += par[y]; par[y] = x; } else { if (rank[x] < rank[y]) { par[y] += par[x]; par[x] = y; dweight[x] = -w; } else { par[x] += par[y]; par[y] = x; if (rank[x] == rank[y]) rank[x]++; dweight[y] = w; } } } ll size(ll x) { return -par[root(x)]; } }; template <typename valtype> class SegT { public: ll size; vector<valtype> v; valtype initv; function<valtype(valtype x, valtype y)> calc; SegT() {} SegT(const SegT &segt) {} SegT(ll sizeget, ll modeget = 0) { sizeset(sizeget); modeset(modeget); init(); } SegT(vector<valtype> cpyvec, ll modeget = 0) { sizeset(cpyvec.sz); modeset(modeget); init(); copy(cpyvec); } SegT(ll sizeget, valtype initvget, function<valtype(valtype x, valtype y)> calcget) { sizeset(sizeget); initv = initvget; calc = calcget; init(); } SegT(vector<valtype> cpyvec, valtype initvget, function<valtype(valtype x, valtype y)> calcget) { sizeset(cpyvec.sz); initv = initvget; calc = calcget; init(); copy(cpyvec); } void sizeset(ll rsize) { size = DigN2(rsize); if (rsize == Pow2(size - 1)) size--; return; } void modeset(ll mode) { switch (mode) { case 0: initv = 0; calc = [](valtype x, valtype y) { return x + y; }; break; case 1: initv = INF; calc = [](valtype x, valtype y) { return min(x, y); }; break; case 2: initv = -INF; calc = [](valtype x, valtype y) { return max(x, y); }; break; } return; } void init() { v.asn(Pow2(size + 1) - 1, initv); } void copy(vector<valtype> cpyvec) { REP(i, min(cpyvec.sz, Pow2(size))) set(i, cpyvec[i]); } ll i2v(ll i) const { if (i < 0 || i >= Pow2(size)) return -1; return Pow2(size) + i - 1; } ll top(ll i) const { if (i == 0) return -1; return (i - 1) / 2; } pl bot(ll i) const { if (i + 1 >= Pow2(size)) return mp(-1, -1); return mp(2 * i + 1, 2 * i + 2); } void set(ll i, valtype x) { i = i2v(i); v[i] = x; while (i > 0) { i = top(i); v[i] = calc(v[bot(i).fi], v[bot(i).se]); } return; } void add(ll i, valtype x) { set(i, v[i2v(i)] + x); return; } valtype operator[](const ll &i) const { return v[i2v(i)]; } // valtype que(ll a = 0, ll b = Pow2(size) - 1) { valtype que(ll a, ll b) { if (a == b) return v[i2v(a)]; if (a > b) return initv; // swap(a, b); valtype ans = initv; ll ai = i2v(a); ll bi = i2v(b); FOR(i, 1, size + 1) { if (a > b) break; if (a % Pow2(i)) { ans = calc(ans, v[ai]); a += Pow2(i - 1); ai = top(ai) + 1; } else { ai = top(ai); } if (a > b) break; if ((b + 1) % Pow2(i)) { ans = calc(ans, v[bi]); b -= Pow2(i - 1); bi = top(bi) - 1; } else { bi = top(bi); } if (a > b) break; } return ans; } valtype que(ll b) { return que(0, b); } valtype que() { return que(0, Pow2(size) - 1); } }; /*template <class Type> class DP { public: vector<Type> v; Type initv; vll size, block; DP() {} DP(const DP &dp) {} template<class... Args> DP(Args... args) { block.asn(1, 1); Initialize(args...); } void Initialize(Type initv_) { initv = initv_; v.asn(block.bk, initv); } template<class... Args> void Initialize(ll val, Args... args) { size.pb(val); block.pb(block.bk*val); Initialize(args...); } };*/ pl Bezout(ll a, ll b) { if (b != 0) { pl xy; xy = Bezout(b, a % b); return mp(xy.se, xy.fi - ((a / b) * xy.se)); } else { return mp(1, 0); } } pl Bez(ll a, ll b, ll c) { pl xy; ll x, y, z, gc; xy = Bezout(a, b); gc = gcd(a, b); if (c % gc != 0) return mp(-1, -1); x = xy.fi * (c / gc); y = xy.se * (c / gc); if (x < 0) z = rup(-x, (b / gc)); if (x >= 0) z = -x / (b / gc); x += z * (b / gc); y -= z * (a / gc); return mp(x, y); } ll DigS10(ll n) { ll ans = 0; while (1) { ans += n % 10; n /= 10; if (!n) break; } return ans; } ll isP(ll n) { if (n <= 1) return 0; FOR(i, 2, (ll)sqrt(n) + 1) { if (n % i == 0) return 0; } return 1; } ll Tot(ll n) { if (n <= 0) return 0; ll ans = n, x = 2; while (x * x <= n) { if (n % x == 0) { ans -= ans / x; while (n % x == 0) n /= x; } x++; } if (n > 1) ans -= ans / n; return ans; } template <class T> struct Graph { public: ll vSize; ll eMode; ll mapMode; ActPair(T) Add; BoolPair(T) Lesser; BoolPair(T) Equal; V<V<P<T, ll>>> adj; map<pl, T> len; Graph(ll vSize, ll eMode = 0, ll mapMode = 0, ActPair(T) Add = ADD, BoolPair(T) Lesser = LES, BoolPair(T) Equal = EQ) : vSize(vSize), eMode(eMode), mapMode(mapMode), Add(Add), Lesser(Lesser), Equal(Equal) { Init(); } void Init() { adj.asn(vSize, V<P<T, ll>>()); } void AddE(ll x, ll y, T cost) { iAddE(x, y, cost); if (!eMode) iAddE(y, x, cost); } void iAddE(ll x, ll y, T cost) { adj[x].pb(mp(cost, y)); if (mapMode) len[mp(x, y)] = cost; } P<bool, T> getE(ll x, ll y) { if (!len.count(mp(x, y))) return mp(false, Lesser.fi); return mp(true, len[mp(x, y)]); } V<T> Dijk(ll x) { V<T> ans(vSize, Lesser.fi); if (x < 0 || x >= vSize) return ans; SegT<P<T, ll>> segt(vSize, mp(Lesser.fi, -1), clam(if (l.se < 0) return r; if (r.se < 0) return l; return Lesser.se(l.fi, r.fi) ? l : r;)); segt.set(x, mp(Add.fi, x)); P<T, ll> now; while ((now = segt.que(0, vSize - 1)).se >= 0) { ans[now.se] = segt[now.se].fi; segt.set(now.se, mp(Lesser.fi, -2)); ROR(adj[now.se], i) { if (segt[i.se].se == -2) continue; if (segt[i.se].se == -1) { segt.set(i.se, mp(Add.se(ans[now.se], i.fi), i.se)); continue; } if (Lesser.se(Add.se(ans[now.se], i.fi), segt[i.se].fi)) { segt.set(i.se, mp(Add.se(ans[now.se], i.fi), i.se)); continue; } } } return ans; } V<P<T, vll>> rDijk(ll x) { V<P<T, vll>> ans(vSize, mp(Lesser.fi, vll())); if (x < 0 || x >= vSize) return ans; SegT<P<T, ll>> segt(vSize, mp(Lesser.fi, -1), clam(if (l.se < 0) return r; if (r.se < 0) return l; return Lesser.se(l.fi, r.fi) ? l : r;)); segt.set(x, mp(Add.fi, x)); P<T, ll> now; while ((now = segt.que(0, vSize - 1)).se >= 0) { ans[now.se].fi = segt[now.se].fi; segt.set(now.se, mp(Lesser.fi, -2)); ROR(adj[now.se], i) { if (segt[i.se].se == -2) continue; if (segt[i.se].se == -1) { segt.set(i.se, mp(Add.se(ans[now.se].fi, i.fi), i.se)); ans[i.se].se = {now.se}; continue; } if (Lesser.se(Add.se(ans[now.se].fi, i.fi), segt[i.se].fi)) { segt.set(i.se, mp(Add.se(ans[now.se].fi, i.fi), i.se)); ans[i.se].se = {now.se}; continue; } if (Equal.se(Add.se(ans[now.se].fi, i.fi), segt[i.se].fi)) { ans[i.se].se.pb(now.se); continue; } } } return ans; } T Prim(ll x = 0) { T ans = Add.fi; if (x < 0 || x >= vSize) return ans; SegT<P<T, ll>> segt(vSize, mp(Lesser.fi, -1), clam(if (l.se < 0) return r; if (r.se < 0) return l; return Lesser.se(l.fi, r.fi) ? l : r;)); segt.set(x, mp(Add.fi, x)); P<T, ll> now; while ((now = segt.que(0, vSize - 1)).se >= 0) { ans = Add.se(ans, segt[now.se].fi); segt.set(now.se, mp(Lesser.fi, -2)); ROR(adj[now.se], i) { if (segt[i.se].se == -2) continue; if (segt[i.se].se == -1) { segt.set(i.se, i); continue; } if (Lesser.se(i.fi, segt[i.se].fi)) { segt.set(i.se, i); continue; } } } return ans; } P<T, V<P<T, vll>>> rPrim(ll x = 0) { P<T, V<P<T, vll>>> ans = mp(Add.fi, V<P<T, vll>>(vSize, mp(Lesser.fi, vll()))); if (x < 0 || x >= vSize) return ans; SegT<P<T, ll>> segt(vSize, mp(Lesser.fi, -1), clam(if (l.se < 0) return r; if (r.se < 0) return l; return Lesser.se(l.fi, r.fi) ? l : r;)); segt.set(x, mp(Add.fi, x)); P<T, ll> now; while ((now = segt.que(0, vSize - 1)).se >= 0) { ans.se[now.se].fi = segt[now.se].fi; ans.fi = Add.se(ans.fi, ans.se[now.se].fi); segt.set(now.se, mp(Lesser.fi, -2)); ROR(adj[now.se], i) { if (segt[i.se].se == -2) continue; if (segt[i.se].se == -1) { segt.set(i.se, i); ans.se[i.se].se = {now.se}; continue; } if (Lesser.se(i.fi, segt[i.se].fi)) { segt.set(i.se, i); ans.se[i.se].se = {now.se}; continue; } if (Equal.se(i.fi, segt[i.se].fi)) { ans.se[i.se].se.pb(now.se); continue; } } } return ans; } }; template <class T> struct Sum { public: V<T> v, s; ll size; ActPair(T) Add; ActPair(T) Sub; Sum(V<T> v, ActPair(T) Add = ADD, ActPair(T) Sub = SUB) : v(v), size(v.sz), Add(Add), Sub(Sub) { Init(); Calc(); } void Init() { s.asn(size + 1, Add.fi); } void Calc() { REP(i, size) s[i + 1] = Add.se(s[i], v[i]); } T operator()(ll x) { if (x < -1) x = -1; if (x > size - 1) x = size - 1; return s[x + 1]; } T operator()(ll l, ll r) { if (l < 0) l = 0; if (r >= size) r = size - 1; if (l > r) return Add.fi; return Sub.se(s[r + 1], s[l]); } }; using sumll = Sum<ll>; template <class T> struct Sum2 { public: V<V<T>> v, s; ll RowSize, ColumnSize; ActPair(T) Add; ActPair(T) Sub; Sum2(V<V<T>> v, ActPair(T) Add = ADD, ActPair(T) Sub = SUB) : v(v), RowSize(v.sz), ColumnSize(v.sz ? v[0].sz : 0), Add(Add), Sub(Sub) { Init(); Calc(); } void Init() { s.asn(RowSize + 1, V<T>(ColumnSize + 1, Add.fi)); } void Calc() { REP1(r, RowSize) { REP1(c, ColumnSize) { // s[r][c] = Sub.se(Add.se(Add.se(v[r - 1][c - //1], operator()(r - 1, c - 2)), operator()(r - 2, c - 1)), operator()(r //- 2, c - 2)); s[r][c] = Add.se(s[r][c - 1], v[r - 1][c - 1]); } } REP1(r, RowSize) { REP1(c, ColumnSize) { s[r][c] = Add.se(s[r - 1][c], s[r][c]); } } } T operator()(ll r, ll c) { if (r < -1) r = -1; if (c < -1) c = -1; if (r > RowSize - 1) r = RowSize - 1; if (c > ColumnSize - 1) c = ColumnSize - 1; return s[r + 1][c + 1]; } T operator()(ll r1, ll c1, ll r2, ll c2) { if (r1 < 0) r1 = 0; if (c1 < 0) c1 = 0; if (r2 >= RowSize) r2 = RowSize - 1; if (c2 >= ColumnSize) c2 = ColumnSize - 1; if (r1 > r2) return Add.fi; if (c1 > c2) return Add.fi; return Sub.se(Add.se(s[r2 + 1][c2 + 1], s[r1][c1]), Add.se(s[r2 + 1][c1], s[r1][c2 + 1])); } }; using sumll2 = Sum2<ll>; template <class T> struct Point2 { public: V<V<T>> v; ll h, w; Point2() : h(0), w(0) {} Point2(ll h, ll w) : h(h), w(w) { asn(h, w); } Point2(ll h, ll w, T val) : h(h), w(w) { asn(h, w, val); } void assign(ll h, ll w) { v.asn(h, V<T>(w)); } void assign(ll h, ll w, ll val) { v.asn(h, V<T>(w, val)); } T &operator()(ll h, ll w) { return v[h][w]; } T &operator()(pl p) { return v[p.fi][p.se]; } }; template <class T> using P2 = Point2<T>; template <ll Mod> struct Modll { public: ll v; Modll() : v(0) {} Modll(ll _v) { set(_v % Mod + Mod); } Modll &set(ll _v) { v = (_v < Mod) ? _v : (_v - Mod); return *this; } Modll pow(ll n) const { Modll x = *this, ans = 1; while (n) { if (n & 1) ans *= x; x *= x; n >>= 1; } return ans; } Modll inverse() const { return (*this).pow(Mod - 2); } Modll operator+(const Modll &m) const { return Modll().set(v + m.v); } Modll operator-(const Modll &m) const { return Modll().set(Mod + v - m.v); } Modll operator*(const Modll &m) const { return Modll().set((ull(v) * m.v) % Mod); } Modll operator/(const Modll &m) const { return *this * m.inv; } Modll &operator+=(const Modll &m) { return *this = *this + m; } Modll &operator-=(const Modll &m) { return *this = *this - m; } Modll &operator*=(const Modll &m) { return *this = *this * m; } Modll &operator/=(const Modll &m) { return *this = *this / m; } Modll operator-() const { return Modll(0) - *this; } explicit operator bool() const { return v != 0; } friend istream &operator>>(istream &in, Modll &m) { return in >> m.v; } friend ostream &operator<<(ostream &out, const Modll &m) { return out << m.v; } }; using mll = Modll<MOD>; using vmll = V<mll>; using vvmll = V<vmll>; using vvvmll = V<vvmll>; vmll MFactMemo(2, 1); vmll MIFactMemo(2, 1); mll mFact(ll n) { if (MFactMemo.sz <= n) { ll oldsize = MFactMemo.sz; MFactMemo.res(n + 1, 1); FOR(i, oldsize, n) MFactMemo[i] = MFactMemo[i - 1] * i; } return MFactMemo[n]; } mll miFact(ll n) { if (MIFactMemo.sz <= n) { ll oldsize = MIFactMemo.sz; MIFactMemo.res(n + 1, 1); MIFactMemo.bk = mFact(n).inv; rFOR(i, oldsize + 1, n) MIFactMemo[i - 1] = MIFactMemo[i] * i; } return MIFactMemo[n]; } mll mComb(ll n, ll k) { if (n < 0 || k < 0 || n < k) return 0; return mFact(n) * miFact(k) * miFact(n - k); } ll LIS(vll v, ll m = 0) { if (v.sz > 0) { ll ans = 0; vll dp(v.sz, INF); FOR(i, 0, v.sz - 1) { dp[m ? UPB(dp, v[i]) : LOWB(dp, v[i])] = v[i]; } FOR(i, 0, v.sz - 1) { if (dp[i] == INF) break; ans++; } return ans; } else { return 0; } } ll Bsrch(function<bool(ll x)> f, ll mi, ll ma) { ll ng = mi - 1, ok = ma, mid; while (ok - ng > 1) { mid = (ng + ok) / 2; (f(mid) ? ok : ng) = mid; } return ok; } template <class T> V<V<T>> MultiMatrix(V<V<T>> A, V<V<T>> B, ActPair(T) Mul = MUL, ActPair(T) Add = ADD) { V<V<T>> ans; ll ii = A.sz; if (!ii) return ans; ll jj = A[0].sz; if (!jj) return ans; ll jj2 = B.sz; if (!jj2) return ans; if (jj != jj2) return ans; ll kk = B[0].sz; if (!kk) return ans; ans.asn(ii, V<T>(kk, 0)); REP(i, ii) { REP(k, kk) { REP(j, jj) { ans[i][k] = Add.se(ans[i][k], Mul.se(A[i][j], B[j][k])); } } } return ans; } vvll CombMemo(1000, vll(1000, -1)); ll Comb(ll n, ll k) { if ((n < 0) || (k < 0)) return 0; if (CombMemo[n][k] == -1) { if (n < k) CombMemo[n][k] = 0; else { if (n == 0) CombMemo[n][k] = 1; else if (k == 0) CombMemo[n][k] = 1; else if (n == k) CombMemo[n][k] = 1; else CombMemo[n][k] = Comb(n - 1, k - 1) + Comb(n - 1, k); } } return CombMemo[n][k]; } template <class T> map<T, ll> Dict(V<T> v) { map<T, ll> m; if (!v.sz) return m; SORT(v); UNIQUE(v); REP(i, v.sz) { m[v[i]] = i; } return m; } template <class T> vll Cmprs(V<T> v) { auto m = Dict(v); vll ans(v.sz); REP(i, v.sz) { ans[i] = m[v[i]]; } return ans; } template <class T> vll PCmprs(V<T> v) { if (v.sz == 0) return V<T>(); vll tmp(v.sz); vll ans(v.sz); IOTA(tmp, 0); IOTA(ans, 0); sort(tmp.bgn, tmp.en, clam(return v[l] < v[r];)); sort(ans.bgn, ans.en, clam(return tmp[l] < tmp[r];)); return ans; } ll BblCnt(vll rv) { vll v = PCmprs(rv); SegT<ll> b(v.sz, 0); ll ans = 0; REP(i, v.sz) { ans += (i - b.que(0, v[i])); b.add(v[i], 1); } return ans; } template <class T> auto ven(T val) { return val; } template <> auto ven<int>(int val) { return (ll)val; } template <class T, class... Args> auto ven(T val, Args... args) { auto tmp = ven(args...); return V<decltype(tmp)>(val, tmp); } template <class T> void zind(T &v) { v--; } template <class T> void zind(V<T> &v) { ROR(v, i) zind(i); } template <class T, class... Args> void zind(T &v, Args &...args) { zind(v); zind(args...); } void Solve(); signed main() { cin.tie(0); ios::sync_with_stdio(false); cout << setprecision(20) << fixed; Solve(); } void Solve() { li(n); vlc(n, a, b); vpl c(n); REP(i, n) c[i] = mp(a[i] + b[i], i); sort(c.bgn, c.en, lam(return l.fi > r.fi;)); ll t = 0, u = 0, uu = 0; REP(i, n) { if (i % 2 == 0) u += a[c[i].se]; if (i % 2 == 1) uu += b[c[i].se]; } /* while (t < n) { u += a[c[t].se]; t++; if (t == n) break; u -= b[c[t].se]; t++; }*/ sal(u - uu); }
[ "call.remove" ]
941,758
941,761
u211681714
cpp
p03141
#include <bits/stdc++.h> using namespace std; template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; template <class T> using VVV = V<VV<T>>; template <class S, class T> using P = pair<S, T>; template <class S, class T, class U> using TP = tuple<S, T, U>; using ll = long long; using ull = unsigned long long; using dbl = double; using str = string; using vll = V<ll>; using vvll = V<vll>; using vvvll = V<vvll>; using pl = P<ll, ll>; using tl = TP<ll, ll, ll>; using vpl = V<pl>; using vvpl = V<vpl>; using vtl = V<tl>; using vvtl = V<vtl>; using vs = V<str>; using vvs = V<vs>; using vd = V<dbl>; using vvd = V<vd>; using qll = queue<ll>; using qpl = queue<pl>; using stll = stack<ll>; using stpl = stack<pl>; using mapll = map<ll, ll>; using setll = set<ll>; using pqll = priority_queue<ll>; //#define int ll #define fi first #define se second #define mp make_pair #define mt make_tuple #define pb push_back #define pob pop_back() #define pf push_front #define pof pop_front() #define sz size() #define bgn begin() #define en end() #define asn assign #define emp empty() #define fr front() #define bk back() #define clr clear() #define ins insert #define ers erase #define res resize #define tp top() #define p_q priority_queue #define inv inverse() #define FOR(i, a, b) for (ll i = (a); i <= (ll)(b); i++) #define rFOR(i, a, b) for (ll i = (b); i >= (ll)(a); i--) #define REP(i, a) FOR((i), 0, (ll)(a)-1) #define REP0(i, a) FOR((i), 0, (ll)(a)) #define REP1(i, a) FOR((i), 1, (ll)(a)) #define rREP(i, a) rFOR((i), 0, (ll)(a)-1) #define rREP0(i, a) rFOR((i), 0, (ll)(a)) #define rREP1(i, a) rFOR((i), 1, (ll)(a)) #define ROR(v, i) for (auto &(i) : (v)) #define IOTA(a, n) iota((a).bgn, (a).en, (n)) #define SORT(a) sort((a).bgn, (a).en) #define rSORT(a) sort((a).rbegin(), (a).rend()) #define UNIQUE(a) (a).erase(unique((a).bgn, (a).en), (a).en) #define PREVP(a) prev_permutation((a).bgn, (a).en) #define NEXTP(a) next_permutation((a).bgn, (a).en) #define BINS(a, b) binary_search((a).bgn, (a).en, (b)) #define LOWB(a, b) (lower_bound((a).bgn, (a).en, (b)) - (a).bgn) #define UPB(a, b) (upper_bound((a).bgn, (a).en, (b)) - (a).bgn) #define CNT(a, b) count((a).bgn, (a).en, b) #define SUM(a) accumulate((a).bgn, (a).en, 0) #define REV(a) reverse((a).bgn, (a).en) #define REGS(a, b) regex_search((a), regex(b)) #define REGM(a, b) regex_match((a), regex(b)) #define yn(a) cout << ((a) ? "yes" : "no") << "\n"; #define Yn(a) cout << ((a) ? "Yes" : "No") << "\n"; #define YN(a) cout << ((a) ? "YES" : "NO") << "\n"; #define imp(a) cout << ((a) ? "possible" : "impossible") << "\n"; #define Imp(a) cout << ((a) ? "Possible" : "Impossible") << "\n"; #define IMP(a) cout << ((a) ? "POSSIBLE" : "IMPOSSIBLE") << "\n"; #define fs(a) cout << ((a) ? "second" : "first") << "\n"; #define Fs(a) cout << ((a) ? "Second" : "First") << "\n"; #define FS(a) cout << ((a) ? "SECOND" : "FIRST") << "\n"; //#define say(a) cout <<(a); //#define sal(a) cout <<(a)<<"\n"; #define sak cout << "\n"; #define sas cout << " "; #define sat cout << "\t"; #define dbg(a) cerr << (#a) << ": " << (a) << "\n"; #define dbgs(...) \ dal(#__VA_ARGS__); \ dal(__VA_ARGS__); #define c2l(a) ((ll)(a - 48)) #define a2l(a) ((ll)(a - 97)) #define A2l(a) ((ll)(a - 65)) #define l2c(a) ((char)(a + 48)) #define l2a(a) ((char)(a + 97)) #define l2A(a) ((char)(a + 65)) #define DigN2(a) ((llabs(a) == 0) ? (1) : ((ll)(log2(double(llabs(a)))) + 1)) #define DigN10(a) ((llabs(a) == 0) ? (1) : ((ll)(log10(double(llabs(a)))) + 1)) #define Dig2(a, b) (((a) >> (b)) & 1) #define Dig10(a, b) (ll)(((a) / ((ll)(pow(10.0, (double)(b))))) % 10) #define Pow2(a) ((ll)(1) << (a)) #define Pow10(a) ((ll)(pow(10.0, double(a)))) #define LSB(a) ((a) & (-(a))) /*#define llin(a) ll (a);cin >>(a); #define llin2(a,b) ll (a),(b);cin >>(a)>>(b); #define llin3(a,b,c) ll (a),(b),(c);cin >>(a)>>(b)>>(c); #define stin(a) string (a);cin >>(a);*/ #define vin(v) \ ROR((v), (i)) { cin >> (i); }; #define vllin(v, N) \ vll(v)((N)); \ vin(v); #define vllin2(a, b, N) \ vll(a)(N), (b)(N); \ REP(i, N) { cin >> (a)[i] >> (b)[i]; }; #define vsin(v, N) \ vs(v)((N)); \ vin(v); #define rdn(a, b) ((a) / (b)) #define rou(a, b) \ ((((double(a) / double(b)) - ((a) / (b))) < 0.5) ? ((a) / (b)) \ : (((a) / (b)) + 1)) #define rup(a, b) ((((a) % (b)) == 0) ? ((a) / (b)) : (((a) / (b)) + 1)) #define powll(a, b) (ll)(pow((double)(a), (double)(b))) #define Triangle(x1, y1, x2, y2, x3, y3) \ (((x1) - (x2)) * ((y1) - (y3)) - ((x1) - (x3)) * ((y1) - (y2))) #define lam(lr) ([](auto l, auto r) { lr }) #define elam(lr) ([=](auto l, auto r) { lr }) #define clam(lr) ([&](auto l, auto r) { lr }) #define min(...) Operation(MIN, __VA_ARGS__) #define max(...) Operation(MAX, __VA_ARGS__) #define gcd(...) Operation(GCD, __VA_ARGS__) #define lcm(...) Operation(LCM, __VA_ARGS__) #define vmin(...) VOperation(MIN, __VA_ARGS__) #define vmax(...) VOperation(MAX, __VA_ARGS__) #define vgcd(...) VOperation(GCD, __VA_ARGS__) #define vlcm(...) VOperation(LCM, __VA_ARGS__) #define vsum(...) VOperation(ADD, __VA_ARGS__) #define vpro(...) VOperation(MUL, __VA_ARGS__) #define emin(a, ...) ((a) = min((a), __VA_ARGS__)) #define emax(a, ...) ((a) = max((a), __VA_ARGS__)) #define egcd(a, ...) ((a) = gcd((a), __VA_ARGS__)) #define elcm(a, ...) ((a) = lcm((a), __VA_ARGS__)) #define ActPair(T) P<T, function<T(T, T)>> #define BoolPair(T) P<T, function<bool(T, T)>> #define ope Operation #define vope VOperation #define svll SumV<ll> #define svvll SumV2<ll> #define li(...) \ ll __VA_ARGS__; \ Input(__VA_ARGS__); #define si(...) \ str __VA_ARGS__; \ Input(__VA_ARGS__); //#define vli(size, ...) vll __VA_ARGS__;vInitInput(size,__VA_ARGS__); #define vlr(size, ...) \ vll __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vlc(size, ...) \ vll __VA_ARGS__; \ vInitInputC(size, __VA_ARGS__); #define vli(size, ...) \ vll __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vsr(size, ...) \ vs __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vsc(size, ...) \ vs __VA_ARGS__; \ vInitInputC(size, __VA_ARGS__); #define vsi(size, ...) \ vs __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vli2(rowSize, columnSize, ...) \ vvll __VA_ARGS__; \ vInitInput2(rowSize, columnSize, __VA_ARGS__); #define vplr(size, ...) \ vpl __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vplc(size, ...) \ vpl __VA_ARGS__; \ vInitInputC(size, __VA_ARGS__); #define vpli(size, ...) \ vpl __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); const ll MOD = 1e9 + 7; // const ll MOD = 998244353; // const ll MOD = 924844033; // const ll MOD = 9007199254740881; const ll INF = 1LL << 60; // 1.15e18 const double PI = acos(-1.0); const vll DX = {0, -1, 0, 1, 0, -1, 1, 1, -1}; const vll DY = {0, 0, -1, 0, 1, -1, -1, 1, 1}; const str alp = "abcdefghijklmnopqrstuvwxyz"; const str ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; template <class S, class T> istream &operator>>(istream &in, P<S, T> &p) { return in >> p.fi >> p.se; } template <class T> istream &operator>>(istream &in, V<T> &v) { REP(i, v.sz) in >> v[i]; return in; } void Input() {} template <class Var, class... Args> void Input(Var &var, Args &...args) { cin >> var; Input(args...); } void vInit(ll size) {} template <class T, class... Args> void vInit(ll size, V<T> &v, Args &...args) { v.res(size); vInit(size, args...); } void vInput(ll size) {} template <class T, class... Args> void vInput(ll size, V<T> &v, Args &...args) { REP(i, size) cin >> v[i]; vInput(size, args...); } void vInputR(ll size) {} template <class T, class... Args> void vInputR(ll size, V<T> &v, Args &...args) { REP(i, size) cin >> v[i]; vInputR(size, args...); } void vInputNumC(ll num) {} template <class T, class... Args> void vInputNumC(ll num, V<T> &v, Args &...args) { cin >> v[num]; vInputNumC(num, args...); } void vInputC(ll size) {} template <class... Args> void vInputC(ll size, Args &...args) { REP(i, size) vInputNumC(i, args...); } void vInitInputR(ll size) {} template <class... Args> void vInitInputR(ll size, Args &...args) { vInit(size, args...); vInputR(size, args...); } void vInitInputC(ll size) {} template <class... Args> void vInitInputC(ll size, Args &...args) { vInit(size, args...); vInputC(size, args...); } void vInit2(ll rowSize, ll columnSize) {} template <class T, class... Args> void vInit2(ll rowSize, ll columnSize, V<V<T>> &v, Args &...args) { v.asn(rowSize, V<T>(columnSize)); vInit2(rowSize, columnSize, args...); } void vInput2(ll rowSize, ll columnSize) {} template <class T, class... Args> void vInput2(ll rowSize, ll columnSize, V<V<T>> &v, Args &...args) { REP(r, rowSize) { REP(c, columnSize) { cin >> v[r][c]; } } vInput2(rowSize, columnSize, args...); } void vInitInput2(ll rowSize, ll columnSize) {} template <class... Args> void vInitInput2(ll rowSize, ll columnSize, Args &...args) { vInit2(rowSize, columnSize, args...); vInput2(rowSize, columnSize, args...); } template <class S, class T> ostream &operator<<(ostream &out, const P<S, T> &p) { return out << "[" << p.fi << ", " << p.se << "]"; } template <class T> ostream &operator<<(ostream &out, V<T> &v) { if (v.emp) return out << "{}"; else { auto itr = v.bgn; out << "{" << *itr; itr++; while (itr != v.en) { out << ", " << *itr; itr++; } out << "}"; return out; } } template <class S, class T> ostream &operator<<(ostream &out, const map<S, T> &m) { if (m.emp) return out << "<[]>"; else { auto itr = m.bgn; out << "< [" << (itr->fi) << ": " << (itr->se); itr++; while (itr != m.en) { out << "], [" << (itr->fi) << ": " << (itr->se); itr++; } out << "] >"; return out; } } template <class T> ostream &operator<<(ostream &out, const set<T> &s) { if (s.emp) return out << "<>"; else { auto itr = s.bgn; out << "<" << *itr; itr++; while (itr != s.en) { out << ", " << *itr; itr++; } out << ">"; return out; } } void say() {} template <class T> void say(T t) { cout << t; } template <class Head, class... Body> void say(Head head, Body... body) { cout << head << " "; say(body...); } void sal() { cout << "\n"; } template <class... Args> void sal(Args... args) { say(args...); cout << "\n"; } void day() {} template <class T> void day(T t) { cerr << t; } template <class Head, class... Body> void day(Head head, Body... body) { cerr << head << " "; day(body...); } void dal() { cerr << "\n"; } template <class... Args> void dal(Args... args) { day(args...); cerr << "\n"; } void salv() {} template <class T> void salv(V<T> v) { if (v.emp) sal(); else { auto itr = v.bgn; say(*itr); itr++; while (itr != v.en) { sas; say(*itr); itr++; } sak; } } template <class T> void salv(V<V<T>> v) { if (v.emp) sal(); else { ROR(v, i) salv(i); } } template <class T, class... Args> void salv(T v, Args... args) { salv(v); salv(args...); } template <class L, class R> auto Gcd(L l, R r) -> decltype(l + r) { if (l < r) swap(l, r); return r ? Gcd(r, l % r) : l; } template <class L, class R> auto Lcm(L l, R r) { if (!l || !r) return 0; return l / Gcd(l, r) * r; } auto LES = mp(INF, lam(return l < r;)); auto GRT = mp(-INF, lam(return l > r;)); auto EQ = mp(0, lam(return l == r;)); auto ADD = mp(0, lam(return l + r;)); auto SUB = mp(0, lam(return l - r;)); auto MUL = mp(1, lam(return l * r;)); auto DIV = mp(1, lam(return l / r;)); auto MDL = mp(1, lam(return l % r;)); auto XOR = mp(0, lam(return l ^ r;)); auto OR = mp(0, lam(return l | r;)); auto AND = mp(((ll)(1) << 63) - 1, lam(return l & r;)); auto MIN = mp(INF, lam(return (l < r) ? l : r;)); auto MAX = mp(-INF, lam(return (l > r) ? l : r;)); auto GCD = mp(0, lam(return Gcd(l, r);)); auto LCM = mp(1, lam(return Lcm(l, r);)); /* auto ADD = mp(0, [](auto l, auto r) { return l + r; }); auto SUB = mp(1, [](auto l, auto r) { return l - r; }); auto MUL = mp(1, [](auto l, auto r) { return l * r; }); auto DIV = mp(0, [](auto l, auto r) { return l / r; }); auto MDL = mp(0, [](auto l, auto r) { return l % r; }); auto XOR = mp(0, [](auto l, auto r) { return l ^ r; }); auto OR = mp(0, [](auto l, auto r) { return l | r; }); auto AND = mp(((ll)(1) << 63) - 1, [](auto l, auto r) { return l & r; }); auto MIN = mp(INF, [](auto l, auto r) { return (l < r) ? l : r; }); auto MAX = mp(-INF, [](auto l, auto r) { return (l > r) ? l : r; }); auto GCD = mp(0, [](auto l, auto r) { return gcd(l, r); }); auto LCM = mp(1, [](auto l, auto r) { return lcm(l, r); }); */ template <class OperationType> auto Operation(OperationType A) { return A.fi; } template <class OperationType, class T> auto Operation(OperationType A, T x) { return x; } template <class OperationType, class T, class... Args> auto Operation(OperationType A, T x, Args... args) { auto tmp = Operation(A, args...); return A.se(x, tmp); } template <class OperationType> auto VOperation(OperationType A) { return A.fi; } template <class OperationType, class T> auto VOperation(OperationType A, T x) { return x; } template <class OperationType, class T> auto VOperation(OperationType A, V<T> x) { T tmp = A.fi; ROR(x, i) tmp = A.se(tmp, i); return tmp; } template <class OperationType, class T> auto VOperation(OperationType A, V<V<T>> x) { T tmp = A.fi; ROR(x, i) ROR(i, j) tmp = A.se(tmp, j); return tmp; } template <class OperationType, class T> auto VOperation(OperationType A, V<V<V<T>>> x) { T tmp = A.fi; ROR(x, i) ROR(i, j) ROR(j, k) tmp = A.se(tmp, k); return tmp; } template <class OperationType, class T> auto VOperation(OperationType A, V<V<V<V<T>>>> x) { T tmp = A.fi; ROR(x, i) ROR(i, j) ROR(j, k) ROR(k, l) tmp = A.se(tmp, l); return tmp; } template <class OperationType, class T, class... Args> auto VOperation(OperationType A, T x, Args... args) { auto xResult = VOperation(A, x); auto tmp = VOperation(A, args...); return A.se(xResult, tmp); } ll Bset(ll a, ll b, ll c) { if (c) a |= b; else a &= ~b; return a; } struct UFT { public: ll tsize; ll mode; vll par; vll rank; UFT() {} UFT(const UFT &uft) {} UFT(ll tsizeget, ll modeget = 0) { tsize = tsizeget; mode = modeget; par.asn(tsize, -1); if (!mode) rank.res(tsize, 0); } ll root(ll x) { return par[x] < 0 ? x : par[x] = root(par[x]); } bool isRoot(ll x) { return x == root(x); } bool same(ll x, ll y) { return root(x) == root(y); } void merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) return; if (mode) { par[x] += par[y]; par[y] = x; } else { if (rank[x] < rank[y]) { par[y] += par[x]; par[x] = y; } else { par[x] += par[y]; par[y] = x; if (rank[x] == rank[y]) rank[x]++; } } } ll size(ll x) { return -par[root(x)]; } }; struct pUFT { public: ll tsize; ll now; vll par; vll rank; vll mtime; vvll sizepi; vvll sizepv; pUFT() {} pUFT(const pUFT &puft) {} pUFT(ll tsizeget) { tsize = tsizeget; now = 0; par.asn(tsize, -1); rank.asn(tsize, 0); mtime.asn(tsize, INF); sizepi.asn(tsize, {0}); sizepv.asn(tsize, {1}); } ll root(ll x, ll t) { return (mtime[x] > t) ? x : root(par[x], t); } bool same(ll x, ll y, ll t) { return root(x, t) == root(y, t); } ll merge(ll x, ll y) { now++; x = root(x, now); y = root(y, now); if (x != y) { if (rank[x] < rank[y]) { par[y] += par[x]; sizepi[y].pb(now); sizepv[y].pb(-par[y]); par[x] = y; mtime[x] = now; } else { par[x] += par[y]; sizepi[x].pb(now); sizepv[x].pb(-par[x]); par[y] = x; mtime[y] = now; if (rank[x] == rank[y]) rank[x]++; } } return now; } ll size(ll x, ll t) { x = root(x, t); return sizepv[x][UPB(sizepi[x], t) - 1]; } }; struct wUFT { public: ll tsize; ll mode; vll par; vll rank; vll dweight; wUFT() {} wUFT(const wUFT &wuft) {} wUFT(ll tsizeget, ll modeget = 0) { tsize = tsizeget; mode = modeget; par.asn(tsize, -1); if (!mode) rank.res(tsize, 0); dweight.asn(tsize, 0); } ll root(ll x) { if (par[x] < 0) return x; else { ll r = root(par[x]); dweight[x] += dweight[par[x]]; return par[x] = r; } } ll weight(ll x) { root(x); return dweight[x]; } ll diff(ll x, ll y) { return weight(y) - weight(x); } bool isRoot(ll x) { return x == root(x); } bool same(ll x, ll y) { return root(x) == root(y); } void merge(ll x, ll y, ll w) { w += weight(x); w -= weight(y); x = root(x); y = root(y); if (x == y) return; if (mode) { par[x] += par[y]; par[y] = x; } else { if (rank[x] < rank[y]) { par[y] += par[x]; par[x] = y; dweight[x] = -w; } else { par[x] += par[y]; par[y] = x; if (rank[x] == rank[y]) rank[x]++; dweight[y] = w; } } } ll size(ll x) { return -par[root(x)]; } }; template <typename valtype> class SegT { public: ll size; vector<valtype> v; valtype initv; function<valtype(valtype x, valtype y)> calc; SegT() {} SegT(const SegT &segt) {} SegT(ll sizeget, ll modeget = 0) { sizeset(sizeget); modeset(modeget); init(); } SegT(vector<valtype> cpyvec, ll modeget = 0) { sizeset(cpyvec.sz); modeset(modeget); init(); copy(cpyvec); } SegT(ll sizeget, valtype initvget, function<valtype(valtype x, valtype y)> calcget) { sizeset(sizeget); initv = initvget; calc = calcget; init(); } SegT(vector<valtype> cpyvec, valtype initvget, function<valtype(valtype x, valtype y)> calcget) { sizeset(cpyvec.sz); initv = initvget; calc = calcget; init(); copy(cpyvec); } void sizeset(ll rsize) { size = DigN2(rsize); if (rsize == Pow2(size - 1)) size--; return; } void modeset(ll mode) { switch (mode) { case 0: initv = 0; calc = [](valtype x, valtype y) { return x + y; }; break; case 1: initv = INF; calc = [](valtype x, valtype y) { return min(x, y); }; break; case 2: initv = -INF; calc = [](valtype x, valtype y) { return max(x, y); }; break; } return; } void init() { v.asn(Pow2(size + 1) - 1, initv); } void copy(vector<valtype> cpyvec) { REP(i, min(cpyvec.sz, Pow2(size))) set(i, cpyvec[i]); } ll i2v(ll i) const { if (i < 0 || i >= Pow2(size)) return -1; return Pow2(size) + i - 1; } ll top(ll i) const { if (i == 0) return -1; return (i - 1) / 2; } pl bot(ll i) const { if (i + 1 >= Pow2(size)) return mp(-1, -1); return mp(2 * i + 1, 2 * i + 2); } void set(ll i, valtype x) { i = i2v(i); v[i] = x; while (i > 0) { i = top(i); v[i] = calc(v[bot(i).fi], v[bot(i).se]); } return; } void add(ll i, valtype x) { set(i, v[i2v(i)] + x); return; } valtype operator[](const ll &i) const { return v[i2v(i)]; } // valtype que(ll a = 0, ll b = Pow2(size) - 1) { valtype que(ll a, ll b) { if (a == b) return v[i2v(a)]; if (a > b) return initv; // swap(a, b); valtype ans = initv; ll ai = i2v(a); ll bi = i2v(b); FOR(i, 1, size + 1) { if (a > b) break; if (a % Pow2(i)) { ans = calc(ans, v[ai]); a += Pow2(i - 1); ai = top(ai) + 1; } else { ai = top(ai); } if (a > b) break; if ((b + 1) % Pow2(i)) { ans = calc(ans, v[bi]); b -= Pow2(i - 1); bi = top(bi) - 1; } else { bi = top(bi); } if (a > b) break; } return ans; } valtype que(ll b) { return que(0, b); } valtype que() { return que(0, Pow2(size) - 1); } }; /*template <class Type> class DP { public: vector<Type> v; Type initv; vll size, block; DP() {} DP(const DP &dp) {} template<class... Args> DP(Args... args) { block.asn(1, 1); Initialize(args...); } void Initialize(Type initv_) { initv = initv_; v.asn(block.bk, initv); } template<class... Args> void Initialize(ll val, Args... args) { size.pb(val); block.pb(block.bk*val); Initialize(args...); } };*/ pl Bezout(ll a, ll b) { if (b != 0) { pl xy; xy = Bezout(b, a % b); return mp(xy.se, xy.fi - ((a / b) * xy.se)); } else { return mp(1, 0); } } pl Bez(ll a, ll b, ll c) { pl xy; ll x, y, z, gc; xy = Bezout(a, b); gc = gcd(a, b); if (c % gc != 0) return mp(-1, -1); x = xy.fi * (c / gc); y = xy.se * (c / gc); if (x < 0) z = rup(-x, (b / gc)); if (x >= 0) z = -x / (b / gc); x += z * (b / gc); y -= z * (a / gc); return mp(x, y); } ll DigS10(ll n) { ll ans = 0; while (1) { ans += n % 10; n /= 10; if (!n) break; } return ans; } ll isP(ll n) { if (n <= 1) return 0; FOR(i, 2, (ll)sqrt(n) + 1) { if (n % i == 0) return 0; } return 1; } ll Tot(ll n) { if (n <= 0) return 0; ll ans = n, x = 2; while (x * x <= n) { if (n % x == 0) { ans -= ans / x; while (n % x == 0) n /= x; } x++; } if (n > 1) ans -= ans / n; return ans; } template <class T> struct Graph { public: ll vSize; ll eMode; ll mapMode; ActPair(T) Add; BoolPair(T) Lesser; BoolPair(T) Equal; V<V<P<T, ll>>> adj; map<pl, T> len; Graph(ll vSize, ll eMode = 0, ll mapMode = 0, ActPair(T) Add = ADD, BoolPair(T) Lesser = LES, BoolPair(T) Equal = EQ) : vSize(vSize), eMode(eMode), mapMode(mapMode), Add(Add), Lesser(Lesser), Equal(Equal) { Init(); } void Init() { adj.asn(vSize, V<P<T, ll>>()); } void AddE(ll x, ll y, T cost) { iAddE(x, y, cost); if (!eMode) iAddE(y, x, cost); } void iAddE(ll x, ll y, T cost) { adj[x].pb(mp(cost, y)); if (mapMode) len[mp(x, y)] = cost; } P<bool, T> getE(ll x, ll y) { if (!len.count(mp(x, y))) return mp(false, Lesser.fi); return mp(true, len[mp(x, y)]); } V<T> Dijk(ll x) { V<T> ans(vSize, Lesser.fi); if (x < 0 || x >= vSize) return ans; SegT<P<T, ll>> segt(vSize, mp(Lesser.fi, -1), clam(if (l.se < 0) return r; if (r.se < 0) return l; return Lesser.se(l.fi, r.fi) ? l : r;)); segt.set(x, mp(Add.fi, x)); P<T, ll> now; while ((now = segt.que(0, vSize - 1)).se >= 0) { ans[now.se] = segt[now.se].fi; segt.set(now.se, mp(Lesser.fi, -2)); ROR(adj[now.se], i) { if (segt[i.se].se == -2) continue; if (segt[i.se].se == -1) { segt.set(i.se, mp(Add.se(ans[now.se], i.fi), i.se)); continue; } if (Lesser.se(Add.se(ans[now.se], i.fi), segt[i.se].fi)) { segt.set(i.se, mp(Add.se(ans[now.se], i.fi), i.se)); continue; } } } return ans; } V<P<T, vll>> rDijk(ll x) { V<P<T, vll>> ans(vSize, mp(Lesser.fi, vll())); if (x < 0 || x >= vSize) return ans; SegT<P<T, ll>> segt(vSize, mp(Lesser.fi, -1), clam(if (l.se < 0) return r; if (r.se < 0) return l; return Lesser.se(l.fi, r.fi) ? l : r;)); segt.set(x, mp(Add.fi, x)); P<T, ll> now; while ((now = segt.que(0, vSize - 1)).se >= 0) { ans[now.se].fi = segt[now.se].fi; segt.set(now.se, mp(Lesser.fi, -2)); ROR(adj[now.se], i) { if (segt[i.se].se == -2) continue; if (segt[i.se].se == -1) { segt.set(i.se, mp(Add.se(ans[now.se].fi, i.fi), i.se)); ans[i.se].se = {now.se}; continue; } if (Lesser.se(Add.se(ans[now.se].fi, i.fi), segt[i.se].fi)) { segt.set(i.se, mp(Add.se(ans[now.se].fi, i.fi), i.se)); ans[i.se].se = {now.se}; continue; } if (Equal.se(Add.se(ans[now.se].fi, i.fi), segt[i.se].fi)) { ans[i.se].se.pb(now.se); continue; } } } return ans; } T Prim(ll x = 0) { T ans = Add.fi; if (x < 0 || x >= vSize) return ans; SegT<P<T, ll>> segt(vSize, mp(Lesser.fi, -1), clam(if (l.se < 0) return r; if (r.se < 0) return l; return Lesser.se(l.fi, r.fi) ? l : r;)); segt.set(x, mp(Add.fi, x)); P<T, ll> now; while ((now = segt.que(0, vSize - 1)).se >= 0) { ans = Add.se(ans, segt[now.se].fi); segt.set(now.se, mp(Lesser.fi, -2)); ROR(adj[now.se], i) { if (segt[i.se].se == -2) continue; if (segt[i.se].se == -1) { segt.set(i.se, i); continue; } if (Lesser.se(i.fi, segt[i.se].fi)) { segt.set(i.se, i); continue; } } } return ans; } P<T, V<P<T, vll>>> rPrim(ll x = 0) { P<T, V<P<T, vll>>> ans = mp(Add.fi, V<P<T, vll>>(vSize, mp(Lesser.fi, vll()))); if (x < 0 || x >= vSize) return ans; SegT<P<T, ll>> segt(vSize, mp(Lesser.fi, -1), clam(if (l.se < 0) return r; if (r.se < 0) return l; return Lesser.se(l.fi, r.fi) ? l : r;)); segt.set(x, mp(Add.fi, x)); P<T, ll> now; while ((now = segt.que(0, vSize - 1)).se >= 0) { ans.se[now.se].fi = segt[now.se].fi; ans.fi = Add.se(ans.fi, ans.se[now.se].fi); segt.set(now.se, mp(Lesser.fi, -2)); ROR(adj[now.se], i) { if (segt[i.se].se == -2) continue; if (segt[i.se].se == -1) { segt.set(i.se, i); ans.se[i.se].se = {now.se}; continue; } if (Lesser.se(i.fi, segt[i.se].fi)) { segt.set(i.se, i); ans.se[i.se].se = {now.se}; continue; } if (Equal.se(i.fi, segt[i.se].fi)) { ans.se[i.se].se.pb(now.se); continue; } } } return ans; } }; template <class T> struct Sum { public: V<T> v, s; ll size; ActPair(T) Add; ActPair(T) Sub; Sum(V<T> v, ActPair(T) Add = ADD, ActPair(T) Sub = SUB) : v(v), size(v.sz), Add(Add), Sub(Sub) { Init(); Calc(); } void Init() { s.asn(size + 1, Add.fi); } void Calc() { REP(i, size) s[i + 1] = Add.se(s[i], v[i]); } T operator()(ll x) { if (x < -1) x = -1; if (x > size - 1) x = size - 1; return s[x + 1]; } T operator()(ll l, ll r) { if (l < 0) l = 0; if (r >= size) r = size - 1; if (l > r) return Add.fi; return Sub.se(s[r + 1], s[l]); } }; using sumll = Sum<ll>; template <class T> struct Sum2 { public: V<V<T>> v, s; ll RowSize, ColumnSize; ActPair(T) Add; ActPair(T) Sub; Sum2(V<V<T>> v, ActPair(T) Add = ADD, ActPair(T) Sub = SUB) : v(v), RowSize(v.sz), ColumnSize(v.sz ? v[0].sz : 0), Add(Add), Sub(Sub) { Init(); Calc(); } void Init() { s.asn(RowSize + 1, V<T>(ColumnSize + 1, Add.fi)); } void Calc() { REP1(r, RowSize) { REP1(c, ColumnSize) { // s[r][c] = Sub.se(Add.se(Add.se(v[r - 1][c - //1], operator()(r - 1, c - 2)), operator()(r - 2, c - 1)), operator()(r //- 2, c - 2)); s[r][c] = Add.se(s[r][c - 1], v[r - 1][c - 1]); } } REP1(r, RowSize) { REP1(c, ColumnSize) { s[r][c] = Add.se(s[r - 1][c], s[r][c]); } } } T operator()(ll r, ll c) { if (r < -1) r = -1; if (c < -1) c = -1; if (r > RowSize - 1) r = RowSize - 1; if (c > ColumnSize - 1) c = ColumnSize - 1; return s[r + 1][c + 1]; } T operator()(ll r1, ll c1, ll r2, ll c2) { if (r1 < 0) r1 = 0; if (c1 < 0) c1 = 0; if (r2 >= RowSize) r2 = RowSize - 1; if (c2 >= ColumnSize) c2 = ColumnSize - 1; if (r1 > r2) return Add.fi; if (c1 > c2) return Add.fi; return Sub.se(Add.se(s[r2 + 1][c2 + 1], s[r1][c1]), Add.se(s[r2 + 1][c1], s[r1][c2 + 1])); } }; using sumll2 = Sum2<ll>; template <class T> struct Point2 { public: V<V<T>> v; ll h, w; Point2() : h(0), w(0) {} Point2(ll h, ll w) : h(h), w(w) { asn(h, w); } Point2(ll h, ll w, T val) : h(h), w(w) { asn(h, w, val); } void assign(ll h, ll w) { v.asn(h, V<T>(w)); } void assign(ll h, ll w, ll val) { v.asn(h, V<T>(w, val)); } T &operator()(ll h, ll w) { return v[h][w]; } T &operator()(pl p) { return v[p.fi][p.se]; } }; template <class T> using P2 = Point2<T>; template <ll Mod> struct Modll { public: ll v; Modll() : v(0) {} Modll(ll _v) { set(_v % Mod + Mod); } Modll &set(ll _v) { v = (_v < Mod) ? _v : (_v - Mod); return *this; } Modll pow(ll n) const { Modll x = *this, ans = 1; while (n) { if (n & 1) ans *= x; x *= x; n >>= 1; } return ans; } Modll inverse() const { return (*this).pow(Mod - 2); } Modll operator+(const Modll &m) const { return Modll().set(v + m.v); } Modll operator-(const Modll &m) const { return Modll().set(Mod + v - m.v); } Modll operator*(const Modll &m) const { return Modll().set((ull(v) * m.v) % Mod); } Modll operator/(const Modll &m) const { return *this * m.inv; } Modll &operator+=(const Modll &m) { return *this = *this + m; } Modll &operator-=(const Modll &m) { return *this = *this - m; } Modll &operator*=(const Modll &m) { return *this = *this * m; } Modll &operator/=(const Modll &m) { return *this = *this / m; } Modll operator-() const { return Modll(0) - *this; } explicit operator bool() const { return v != 0; } friend istream &operator>>(istream &in, Modll &m) { return in >> m.v; } friend ostream &operator<<(ostream &out, const Modll &m) { return out << m.v; } }; using mll = Modll<MOD>; using vmll = V<mll>; using vvmll = V<vmll>; using vvvmll = V<vvmll>; vmll MFactMemo(2, 1); vmll MIFactMemo(2, 1); mll mFact(ll n) { if (MFactMemo.sz <= n) { ll oldsize = MFactMemo.sz; MFactMemo.res(n + 1, 1); FOR(i, oldsize, n) MFactMemo[i] = MFactMemo[i - 1] * i; } return MFactMemo[n]; } mll miFact(ll n) { if (MIFactMemo.sz <= n) { ll oldsize = MIFactMemo.sz; MIFactMemo.res(n + 1, 1); MIFactMemo.bk = mFact(n).inv; rFOR(i, oldsize + 1, n) MIFactMemo[i - 1] = MIFactMemo[i] * i; } return MIFactMemo[n]; } mll mComb(ll n, ll k) { if (n < 0 || k < 0 || n < k) return 0; return mFact(n) * miFact(k) * miFact(n - k); } ll LIS(vll v, ll m = 0) { if (v.sz > 0) { ll ans = 0; vll dp(v.sz, INF); FOR(i, 0, v.sz - 1) { dp[m ? UPB(dp, v[i]) : LOWB(dp, v[i])] = v[i]; } FOR(i, 0, v.sz - 1) { if (dp[i] == INF) break; ans++; } return ans; } else { return 0; } } ll Bsrch(function<bool(ll x)> f, ll mi, ll ma) { ll ng = mi - 1, ok = ma, mid; while (ok - ng > 1) { mid = (ng + ok) / 2; (f(mid) ? ok : ng) = mid; } return ok; } template <class T> V<V<T>> MultiMatrix(V<V<T>> A, V<V<T>> B, ActPair(T) Mul = MUL, ActPair(T) Add = ADD) { V<V<T>> ans; ll ii = A.sz; if (!ii) return ans; ll jj = A[0].sz; if (!jj) return ans; ll jj2 = B.sz; if (!jj2) return ans; if (jj != jj2) return ans; ll kk = B[0].sz; if (!kk) return ans; ans.asn(ii, V<T>(kk, 0)); REP(i, ii) { REP(k, kk) { REP(j, jj) { ans[i][k] = Add.se(ans[i][k], Mul.se(A[i][j], B[j][k])); } } } return ans; } vvll CombMemo(1000, vll(1000, -1)); ll Comb(ll n, ll k) { if ((n < 0) || (k < 0)) return 0; if (CombMemo[n][k] == -1) { if (n < k) CombMemo[n][k] = 0; else { if (n == 0) CombMemo[n][k] = 1; else if (k == 0) CombMemo[n][k] = 1; else if (n == k) CombMemo[n][k] = 1; else CombMemo[n][k] = Comb(n - 1, k - 1) + Comb(n - 1, k); } } return CombMemo[n][k]; } template <class T> map<T, ll> Dict(V<T> v) { map<T, ll> m; if (!v.sz) return m; SORT(v); UNIQUE(v); REP(i, v.sz) { m[v[i]] = i; } return m; } template <class T> vll Cmprs(V<T> v) { auto m = Dict(v); vll ans(v.sz); REP(i, v.sz) { ans[i] = m[v[i]]; } return ans; } template <class T> vll PCmprs(V<T> v) { if (v.sz == 0) return V<T>(); vll tmp(v.sz); vll ans(v.sz); IOTA(tmp, 0); IOTA(ans, 0); sort(tmp.bgn, tmp.en, clam(return v[l] < v[r];)); sort(ans.bgn, ans.en, clam(return tmp[l] < tmp[r];)); return ans; } ll BblCnt(vll rv) { vll v = PCmprs(rv); SegT<ll> b(v.sz, 0); ll ans = 0; REP(i, v.sz) { ans += (i - b.que(0, v[i])); b.add(v[i], 1); } return ans; } template <class T> auto ven(T val) { return val; } template <> auto ven<int>(int val) { return (ll)val; } template <class T, class... Args> auto ven(T val, Args... args) { auto tmp = ven(args...); return V<decltype(tmp)>(val, tmp); } template <class T> void zind(T &v) { v--; } template <class T> void zind(V<T> &v) { ROR(v, i) zind(i); } template <class T, class... Args> void zind(T &v, Args &...args) { zind(v); zind(args...); } void Solve(); signed main() { cin.tie(0); ios::sync_with_stdio(false); cout << setprecision(20) << fixed; Solve(); } void Solve() { li(n); vlc(n, a, b); vpl c(n); REP(i, n) c[i] = mp(a[i] + b[i], i); sort(c.bgn, c.en, lam(return l.fi > r.fi;)); ll t = 0, u = 0, uu = 0; REP(i, n) { if (i % 2 == 0) u += a[c[t].se]; if (i % 2 == 1) uu += b[c[t].se]; } /* while (t < n) { u += a[c[t].se]; t++; if (t == n) break; u -= b[c[t].se]; t++; }*/ sal(u - uu); }
#include <bits/stdc++.h> using namespace std; template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; template <class T> using VVV = V<VV<T>>; template <class S, class T> using P = pair<S, T>; template <class S, class T, class U> using TP = tuple<S, T, U>; using ll = long long; using ull = unsigned long long; using dbl = double; using str = string; using vll = V<ll>; using vvll = V<vll>; using vvvll = V<vvll>; using pl = P<ll, ll>; using tl = TP<ll, ll, ll>; using vpl = V<pl>; using vvpl = V<vpl>; using vtl = V<tl>; using vvtl = V<vtl>; using vs = V<str>; using vvs = V<vs>; using vd = V<dbl>; using vvd = V<vd>; using qll = queue<ll>; using qpl = queue<pl>; using stll = stack<ll>; using stpl = stack<pl>; using mapll = map<ll, ll>; using setll = set<ll>; using pqll = priority_queue<ll>; //#define int ll #define fi first #define se second #define mp make_pair #define mt make_tuple #define pb push_back #define pob pop_back() #define pf push_front #define pof pop_front() #define sz size() #define bgn begin() #define en end() #define asn assign #define emp empty() #define fr front() #define bk back() #define clr clear() #define ins insert #define ers erase #define res resize #define tp top() #define p_q priority_queue #define inv inverse() #define FOR(i, a, b) for (ll i = (a); i <= (ll)(b); i++) #define rFOR(i, a, b) for (ll i = (b); i >= (ll)(a); i--) #define REP(i, a) FOR((i), 0, (ll)(a)-1) #define REP0(i, a) FOR((i), 0, (ll)(a)) #define REP1(i, a) FOR((i), 1, (ll)(a)) #define rREP(i, a) rFOR((i), 0, (ll)(a)-1) #define rREP0(i, a) rFOR((i), 0, (ll)(a)) #define rREP1(i, a) rFOR((i), 1, (ll)(a)) #define ROR(v, i) for (auto &(i) : (v)) #define IOTA(a, n) iota((a).bgn, (a).en, (n)) #define SORT(a) sort((a).bgn, (a).en) #define rSORT(a) sort((a).rbegin(), (a).rend()) #define UNIQUE(a) (a).erase(unique((a).bgn, (a).en), (a).en) #define PREVP(a) prev_permutation((a).bgn, (a).en) #define NEXTP(a) next_permutation((a).bgn, (a).en) #define BINS(a, b) binary_search((a).bgn, (a).en, (b)) #define LOWB(a, b) (lower_bound((a).bgn, (a).en, (b)) - (a).bgn) #define UPB(a, b) (upper_bound((a).bgn, (a).en, (b)) - (a).bgn) #define CNT(a, b) count((a).bgn, (a).en, b) #define SUM(a) accumulate((a).bgn, (a).en, 0) #define REV(a) reverse((a).bgn, (a).en) #define REGS(a, b) regex_search((a), regex(b)) #define REGM(a, b) regex_match((a), regex(b)) #define yn(a) cout << ((a) ? "yes" : "no") << "\n"; #define Yn(a) cout << ((a) ? "Yes" : "No") << "\n"; #define YN(a) cout << ((a) ? "YES" : "NO") << "\n"; #define imp(a) cout << ((a) ? "possible" : "impossible") << "\n"; #define Imp(a) cout << ((a) ? "Possible" : "Impossible") << "\n"; #define IMP(a) cout << ((a) ? "POSSIBLE" : "IMPOSSIBLE") << "\n"; #define fs(a) cout << ((a) ? "second" : "first") << "\n"; #define Fs(a) cout << ((a) ? "Second" : "First") << "\n"; #define FS(a) cout << ((a) ? "SECOND" : "FIRST") << "\n"; //#define say(a) cout <<(a); //#define sal(a) cout <<(a)<<"\n"; #define sak cout << "\n"; #define sas cout << " "; #define sat cout << "\t"; #define dbg(a) cerr << (#a) << ": " << (a) << "\n"; #define dbgs(...) \ dal(#__VA_ARGS__); \ dal(__VA_ARGS__); #define c2l(a) ((ll)(a - 48)) #define a2l(a) ((ll)(a - 97)) #define A2l(a) ((ll)(a - 65)) #define l2c(a) ((char)(a + 48)) #define l2a(a) ((char)(a + 97)) #define l2A(a) ((char)(a + 65)) #define DigN2(a) ((llabs(a) == 0) ? (1) : ((ll)(log2(double(llabs(a)))) + 1)) #define DigN10(a) ((llabs(a) == 0) ? (1) : ((ll)(log10(double(llabs(a)))) + 1)) #define Dig2(a, b) (((a) >> (b)) & 1) #define Dig10(a, b) (ll)(((a) / ((ll)(pow(10.0, (double)(b))))) % 10) #define Pow2(a) ((ll)(1) << (a)) #define Pow10(a) ((ll)(pow(10.0, double(a)))) #define LSB(a) ((a) & (-(a))) /*#define llin(a) ll (a);cin >>(a); #define llin2(a,b) ll (a),(b);cin >>(a)>>(b); #define llin3(a,b,c) ll (a),(b),(c);cin >>(a)>>(b)>>(c); #define stin(a) string (a);cin >>(a);*/ #define vin(v) \ ROR((v), (i)) { cin >> (i); }; #define vllin(v, N) \ vll(v)((N)); \ vin(v); #define vllin2(a, b, N) \ vll(a)(N), (b)(N); \ REP(i, N) { cin >> (a)[i] >> (b)[i]; }; #define vsin(v, N) \ vs(v)((N)); \ vin(v); #define rdn(a, b) ((a) / (b)) #define rou(a, b) \ ((((double(a) / double(b)) - ((a) / (b))) < 0.5) ? ((a) / (b)) \ : (((a) / (b)) + 1)) #define rup(a, b) ((((a) % (b)) == 0) ? ((a) / (b)) : (((a) / (b)) + 1)) #define powll(a, b) (ll)(pow((double)(a), (double)(b))) #define Triangle(x1, y1, x2, y2, x3, y3) \ (((x1) - (x2)) * ((y1) - (y3)) - ((x1) - (x3)) * ((y1) - (y2))) #define lam(lr) ([](auto l, auto r) { lr }) #define elam(lr) ([=](auto l, auto r) { lr }) #define clam(lr) ([&](auto l, auto r) { lr }) #define min(...) Operation(MIN, __VA_ARGS__) #define max(...) Operation(MAX, __VA_ARGS__) #define gcd(...) Operation(GCD, __VA_ARGS__) #define lcm(...) Operation(LCM, __VA_ARGS__) #define vmin(...) VOperation(MIN, __VA_ARGS__) #define vmax(...) VOperation(MAX, __VA_ARGS__) #define vgcd(...) VOperation(GCD, __VA_ARGS__) #define vlcm(...) VOperation(LCM, __VA_ARGS__) #define vsum(...) VOperation(ADD, __VA_ARGS__) #define vpro(...) VOperation(MUL, __VA_ARGS__) #define emin(a, ...) ((a) = min((a), __VA_ARGS__)) #define emax(a, ...) ((a) = max((a), __VA_ARGS__)) #define egcd(a, ...) ((a) = gcd((a), __VA_ARGS__)) #define elcm(a, ...) ((a) = lcm((a), __VA_ARGS__)) #define ActPair(T) P<T, function<T(T, T)>> #define BoolPair(T) P<T, function<bool(T, T)>> #define ope Operation #define vope VOperation #define svll SumV<ll> #define svvll SumV2<ll> #define li(...) \ ll __VA_ARGS__; \ Input(__VA_ARGS__); #define si(...) \ str __VA_ARGS__; \ Input(__VA_ARGS__); //#define vli(size, ...) vll __VA_ARGS__;vInitInput(size,__VA_ARGS__); #define vlr(size, ...) \ vll __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vlc(size, ...) \ vll __VA_ARGS__; \ vInitInputC(size, __VA_ARGS__); #define vli(size, ...) \ vll __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vsr(size, ...) \ vs __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vsc(size, ...) \ vs __VA_ARGS__; \ vInitInputC(size, __VA_ARGS__); #define vsi(size, ...) \ vs __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vli2(rowSize, columnSize, ...) \ vvll __VA_ARGS__; \ vInitInput2(rowSize, columnSize, __VA_ARGS__); #define vplr(size, ...) \ vpl __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); #define vplc(size, ...) \ vpl __VA_ARGS__; \ vInitInputC(size, __VA_ARGS__); #define vpli(size, ...) \ vpl __VA_ARGS__; \ vInitInputR(size, __VA_ARGS__); const ll MOD = 1e9 + 7; // const ll MOD = 998244353; // const ll MOD = 924844033; // const ll MOD = 9007199254740881; const ll INF = 1LL << 60; // 1.15e18 const double PI = acos(-1.0); const vll DX = {0, -1, 0, 1, 0, -1, 1, 1, -1}; const vll DY = {0, 0, -1, 0, 1, -1, -1, 1, 1}; const str alp = "abcdefghijklmnopqrstuvwxyz"; const str ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; template <class S, class T> istream &operator>>(istream &in, P<S, T> &p) { return in >> p.fi >> p.se; } template <class T> istream &operator>>(istream &in, V<T> &v) { REP(i, v.sz) in >> v[i]; return in; } void Input() {} template <class Var, class... Args> void Input(Var &var, Args &...args) { cin >> var; Input(args...); } void vInit(ll size) {} template <class T, class... Args> void vInit(ll size, V<T> &v, Args &...args) { v.res(size); vInit(size, args...); } void vInput(ll size) {} template <class T, class... Args> void vInput(ll size, V<T> &v, Args &...args) { REP(i, size) cin >> v[i]; vInput(size, args...); } void vInputR(ll size) {} template <class T, class... Args> void vInputR(ll size, V<T> &v, Args &...args) { REP(i, size) cin >> v[i]; vInputR(size, args...); } void vInputNumC(ll num) {} template <class T, class... Args> void vInputNumC(ll num, V<T> &v, Args &...args) { cin >> v[num]; vInputNumC(num, args...); } void vInputC(ll size) {} template <class... Args> void vInputC(ll size, Args &...args) { REP(i, size) vInputNumC(i, args...); } void vInitInputR(ll size) {} template <class... Args> void vInitInputR(ll size, Args &...args) { vInit(size, args...); vInputR(size, args...); } void vInitInputC(ll size) {} template <class... Args> void vInitInputC(ll size, Args &...args) { vInit(size, args...); vInputC(size, args...); } void vInit2(ll rowSize, ll columnSize) {} template <class T, class... Args> void vInit2(ll rowSize, ll columnSize, V<V<T>> &v, Args &...args) { v.asn(rowSize, V<T>(columnSize)); vInit2(rowSize, columnSize, args...); } void vInput2(ll rowSize, ll columnSize) {} template <class T, class... Args> void vInput2(ll rowSize, ll columnSize, V<V<T>> &v, Args &...args) { REP(r, rowSize) { REP(c, columnSize) { cin >> v[r][c]; } } vInput2(rowSize, columnSize, args...); } void vInitInput2(ll rowSize, ll columnSize) {} template <class... Args> void vInitInput2(ll rowSize, ll columnSize, Args &...args) { vInit2(rowSize, columnSize, args...); vInput2(rowSize, columnSize, args...); } template <class S, class T> ostream &operator<<(ostream &out, const P<S, T> &p) { return out << "[" << p.fi << ", " << p.se << "]"; } template <class T> ostream &operator<<(ostream &out, V<T> &v) { if (v.emp) return out << "{}"; else { auto itr = v.bgn; out << "{" << *itr; itr++; while (itr != v.en) { out << ", " << *itr; itr++; } out << "}"; return out; } } template <class S, class T> ostream &operator<<(ostream &out, const map<S, T> &m) { if (m.emp) return out << "<[]>"; else { auto itr = m.bgn; out << "< [" << (itr->fi) << ": " << (itr->se); itr++; while (itr != m.en) { out << "], [" << (itr->fi) << ": " << (itr->se); itr++; } out << "] >"; return out; } } template <class T> ostream &operator<<(ostream &out, const set<T> &s) { if (s.emp) return out << "<>"; else { auto itr = s.bgn; out << "<" << *itr; itr++; while (itr != s.en) { out << ", " << *itr; itr++; } out << ">"; return out; } } void say() {} template <class T> void say(T t) { cout << t; } template <class Head, class... Body> void say(Head head, Body... body) { cout << head << " "; say(body...); } void sal() { cout << "\n"; } template <class... Args> void sal(Args... args) { say(args...); cout << "\n"; } void day() {} template <class T> void day(T t) { cerr << t; } template <class Head, class... Body> void day(Head head, Body... body) { cerr << head << " "; day(body...); } void dal() { cerr << "\n"; } template <class... Args> void dal(Args... args) { day(args...); cerr << "\n"; } void salv() {} template <class T> void salv(V<T> v) { if (v.emp) sal(); else { auto itr = v.bgn; say(*itr); itr++; while (itr != v.en) { sas; say(*itr); itr++; } sak; } } template <class T> void salv(V<V<T>> v) { if (v.emp) sal(); else { ROR(v, i) salv(i); } } template <class T, class... Args> void salv(T v, Args... args) { salv(v); salv(args...); } template <class L, class R> auto Gcd(L l, R r) -> decltype(l + r) { if (l < r) swap(l, r); return r ? Gcd(r, l % r) : l; } template <class L, class R> auto Lcm(L l, R r) { if (!l || !r) return 0; return l / Gcd(l, r) * r; } auto LES = mp(INF, lam(return l < r;)); auto GRT = mp(-INF, lam(return l > r;)); auto EQ = mp(0, lam(return l == r;)); auto ADD = mp(0, lam(return l + r;)); auto SUB = mp(0, lam(return l - r;)); auto MUL = mp(1, lam(return l * r;)); auto DIV = mp(1, lam(return l / r;)); auto MDL = mp(1, lam(return l % r;)); auto XOR = mp(0, lam(return l ^ r;)); auto OR = mp(0, lam(return l | r;)); auto AND = mp(((ll)(1) << 63) - 1, lam(return l & r;)); auto MIN = mp(INF, lam(return (l < r) ? l : r;)); auto MAX = mp(-INF, lam(return (l > r) ? l : r;)); auto GCD = mp(0, lam(return Gcd(l, r);)); auto LCM = mp(1, lam(return Lcm(l, r);)); /* auto ADD = mp(0, [](auto l, auto r) { return l + r; }); auto SUB = mp(1, [](auto l, auto r) { return l - r; }); auto MUL = mp(1, [](auto l, auto r) { return l * r; }); auto DIV = mp(0, [](auto l, auto r) { return l / r; }); auto MDL = mp(0, [](auto l, auto r) { return l % r; }); auto XOR = mp(0, [](auto l, auto r) { return l ^ r; }); auto OR = mp(0, [](auto l, auto r) { return l | r; }); auto AND = mp(((ll)(1) << 63) - 1, [](auto l, auto r) { return l & r; }); auto MIN = mp(INF, [](auto l, auto r) { return (l < r) ? l : r; }); auto MAX = mp(-INF, [](auto l, auto r) { return (l > r) ? l : r; }); auto GCD = mp(0, [](auto l, auto r) { return gcd(l, r); }); auto LCM = mp(1, [](auto l, auto r) { return lcm(l, r); }); */ template <class OperationType> auto Operation(OperationType A) { return A.fi; } template <class OperationType, class T> auto Operation(OperationType A, T x) { return x; } template <class OperationType, class T, class... Args> auto Operation(OperationType A, T x, Args... args) { auto tmp = Operation(A, args...); return A.se(x, tmp); } template <class OperationType> auto VOperation(OperationType A) { return A.fi; } template <class OperationType, class T> auto VOperation(OperationType A, T x) { return x; } template <class OperationType, class T> auto VOperation(OperationType A, V<T> x) { T tmp = A.fi; ROR(x, i) tmp = A.se(tmp, i); return tmp; } template <class OperationType, class T> auto VOperation(OperationType A, V<V<T>> x) { T tmp = A.fi; ROR(x, i) ROR(i, j) tmp = A.se(tmp, j); return tmp; } template <class OperationType, class T> auto VOperation(OperationType A, V<V<V<T>>> x) { T tmp = A.fi; ROR(x, i) ROR(i, j) ROR(j, k) tmp = A.se(tmp, k); return tmp; } template <class OperationType, class T> auto VOperation(OperationType A, V<V<V<V<T>>>> x) { T tmp = A.fi; ROR(x, i) ROR(i, j) ROR(j, k) ROR(k, l) tmp = A.se(tmp, l); return tmp; } template <class OperationType, class T, class... Args> auto VOperation(OperationType A, T x, Args... args) { auto xResult = VOperation(A, x); auto tmp = VOperation(A, args...); return A.se(xResult, tmp); } ll Bset(ll a, ll b, ll c) { if (c) a |= b; else a &= ~b; return a; } struct UFT { public: ll tsize; ll mode; vll par; vll rank; UFT() {} UFT(const UFT &uft) {} UFT(ll tsizeget, ll modeget = 0) { tsize = tsizeget; mode = modeget; par.asn(tsize, -1); if (!mode) rank.res(tsize, 0); } ll root(ll x) { return par[x] < 0 ? x : par[x] = root(par[x]); } bool isRoot(ll x) { return x == root(x); } bool same(ll x, ll y) { return root(x) == root(y); } void merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) return; if (mode) { par[x] += par[y]; par[y] = x; } else { if (rank[x] < rank[y]) { par[y] += par[x]; par[x] = y; } else { par[x] += par[y]; par[y] = x; if (rank[x] == rank[y]) rank[x]++; } } } ll size(ll x) { return -par[root(x)]; } }; struct pUFT { public: ll tsize; ll now; vll par; vll rank; vll mtime; vvll sizepi; vvll sizepv; pUFT() {} pUFT(const pUFT &puft) {} pUFT(ll tsizeget) { tsize = tsizeget; now = 0; par.asn(tsize, -1); rank.asn(tsize, 0); mtime.asn(tsize, INF); sizepi.asn(tsize, {0}); sizepv.asn(tsize, {1}); } ll root(ll x, ll t) { return (mtime[x] > t) ? x : root(par[x], t); } bool same(ll x, ll y, ll t) { return root(x, t) == root(y, t); } ll merge(ll x, ll y) { now++; x = root(x, now); y = root(y, now); if (x != y) { if (rank[x] < rank[y]) { par[y] += par[x]; sizepi[y].pb(now); sizepv[y].pb(-par[y]); par[x] = y; mtime[x] = now; } else { par[x] += par[y]; sizepi[x].pb(now); sizepv[x].pb(-par[x]); par[y] = x; mtime[y] = now; if (rank[x] == rank[y]) rank[x]++; } } return now; } ll size(ll x, ll t) { x = root(x, t); return sizepv[x][UPB(sizepi[x], t) - 1]; } }; struct wUFT { public: ll tsize; ll mode; vll par; vll rank; vll dweight; wUFT() {} wUFT(const wUFT &wuft) {} wUFT(ll tsizeget, ll modeget = 0) { tsize = tsizeget; mode = modeget; par.asn(tsize, -1); if (!mode) rank.res(tsize, 0); dweight.asn(tsize, 0); } ll root(ll x) { if (par[x] < 0) return x; else { ll r = root(par[x]); dweight[x] += dweight[par[x]]; return par[x] = r; } } ll weight(ll x) { root(x); return dweight[x]; } ll diff(ll x, ll y) { return weight(y) - weight(x); } bool isRoot(ll x) { return x == root(x); } bool same(ll x, ll y) { return root(x) == root(y); } void merge(ll x, ll y, ll w) { w += weight(x); w -= weight(y); x = root(x); y = root(y); if (x == y) return; if (mode) { par[x] += par[y]; par[y] = x; } else { if (rank[x] < rank[y]) { par[y] += par[x]; par[x] = y; dweight[x] = -w; } else { par[x] += par[y]; par[y] = x; if (rank[x] == rank[y]) rank[x]++; dweight[y] = w; } } } ll size(ll x) { return -par[root(x)]; } }; template <typename valtype> class SegT { public: ll size; vector<valtype> v; valtype initv; function<valtype(valtype x, valtype y)> calc; SegT() {} SegT(const SegT &segt) {} SegT(ll sizeget, ll modeget = 0) { sizeset(sizeget); modeset(modeget); init(); } SegT(vector<valtype> cpyvec, ll modeget = 0) { sizeset(cpyvec.sz); modeset(modeget); init(); copy(cpyvec); } SegT(ll sizeget, valtype initvget, function<valtype(valtype x, valtype y)> calcget) { sizeset(sizeget); initv = initvget; calc = calcget; init(); } SegT(vector<valtype> cpyvec, valtype initvget, function<valtype(valtype x, valtype y)> calcget) { sizeset(cpyvec.sz); initv = initvget; calc = calcget; init(); copy(cpyvec); } void sizeset(ll rsize) { size = DigN2(rsize); if (rsize == Pow2(size - 1)) size--; return; } void modeset(ll mode) { switch (mode) { case 0: initv = 0; calc = [](valtype x, valtype y) { return x + y; }; break; case 1: initv = INF; calc = [](valtype x, valtype y) { return min(x, y); }; break; case 2: initv = -INF; calc = [](valtype x, valtype y) { return max(x, y); }; break; } return; } void init() { v.asn(Pow2(size + 1) - 1, initv); } void copy(vector<valtype> cpyvec) { REP(i, min(cpyvec.sz, Pow2(size))) set(i, cpyvec[i]); } ll i2v(ll i) const { if (i < 0 || i >= Pow2(size)) return -1; return Pow2(size) + i - 1; } ll top(ll i) const { if (i == 0) return -1; return (i - 1) / 2; } pl bot(ll i) const { if (i + 1 >= Pow2(size)) return mp(-1, -1); return mp(2 * i + 1, 2 * i + 2); } void set(ll i, valtype x) { i = i2v(i); v[i] = x; while (i > 0) { i = top(i); v[i] = calc(v[bot(i).fi], v[bot(i).se]); } return; } void add(ll i, valtype x) { set(i, v[i2v(i)] + x); return; } valtype operator[](const ll &i) const { return v[i2v(i)]; } // valtype que(ll a = 0, ll b = Pow2(size) - 1) { valtype que(ll a, ll b) { if (a == b) return v[i2v(a)]; if (a > b) return initv; // swap(a, b); valtype ans = initv; ll ai = i2v(a); ll bi = i2v(b); FOR(i, 1, size + 1) { if (a > b) break; if (a % Pow2(i)) { ans = calc(ans, v[ai]); a += Pow2(i - 1); ai = top(ai) + 1; } else { ai = top(ai); } if (a > b) break; if ((b + 1) % Pow2(i)) { ans = calc(ans, v[bi]); b -= Pow2(i - 1); bi = top(bi) - 1; } else { bi = top(bi); } if (a > b) break; } return ans; } valtype que(ll b) { return que(0, b); } valtype que() { return que(0, Pow2(size) - 1); } }; /*template <class Type> class DP { public: vector<Type> v; Type initv; vll size, block; DP() {} DP(const DP &dp) {} template<class... Args> DP(Args... args) { block.asn(1, 1); Initialize(args...); } void Initialize(Type initv_) { initv = initv_; v.asn(block.bk, initv); } template<class... Args> void Initialize(ll val, Args... args) { size.pb(val); block.pb(block.bk*val); Initialize(args...); } };*/ pl Bezout(ll a, ll b) { if (b != 0) { pl xy; xy = Bezout(b, a % b); return mp(xy.se, xy.fi - ((a / b) * xy.se)); } else { return mp(1, 0); } } pl Bez(ll a, ll b, ll c) { pl xy; ll x, y, z, gc; xy = Bezout(a, b); gc = gcd(a, b); if (c % gc != 0) return mp(-1, -1); x = xy.fi * (c / gc); y = xy.se * (c / gc); if (x < 0) z = rup(-x, (b / gc)); if (x >= 0) z = -x / (b / gc); x += z * (b / gc); y -= z * (a / gc); return mp(x, y); } ll DigS10(ll n) { ll ans = 0; while (1) { ans += n % 10; n /= 10; if (!n) break; } return ans; } ll isP(ll n) { if (n <= 1) return 0; FOR(i, 2, (ll)sqrt(n) + 1) { if (n % i == 0) return 0; } return 1; } ll Tot(ll n) { if (n <= 0) return 0; ll ans = n, x = 2; while (x * x <= n) { if (n % x == 0) { ans -= ans / x; while (n % x == 0) n /= x; } x++; } if (n > 1) ans -= ans / n; return ans; } template <class T> struct Graph { public: ll vSize; ll eMode; ll mapMode; ActPair(T) Add; BoolPair(T) Lesser; BoolPair(T) Equal; V<V<P<T, ll>>> adj; map<pl, T> len; Graph(ll vSize, ll eMode = 0, ll mapMode = 0, ActPair(T) Add = ADD, BoolPair(T) Lesser = LES, BoolPair(T) Equal = EQ) : vSize(vSize), eMode(eMode), mapMode(mapMode), Add(Add), Lesser(Lesser), Equal(Equal) { Init(); } void Init() { adj.asn(vSize, V<P<T, ll>>()); } void AddE(ll x, ll y, T cost) { iAddE(x, y, cost); if (!eMode) iAddE(y, x, cost); } void iAddE(ll x, ll y, T cost) { adj[x].pb(mp(cost, y)); if (mapMode) len[mp(x, y)] = cost; } P<bool, T> getE(ll x, ll y) { if (!len.count(mp(x, y))) return mp(false, Lesser.fi); return mp(true, len[mp(x, y)]); } V<T> Dijk(ll x) { V<T> ans(vSize, Lesser.fi); if (x < 0 || x >= vSize) return ans; SegT<P<T, ll>> segt(vSize, mp(Lesser.fi, -1), clam(if (l.se < 0) return r; if (r.se < 0) return l; return Lesser.se(l.fi, r.fi) ? l : r;)); segt.set(x, mp(Add.fi, x)); P<T, ll> now; while ((now = segt.que(0, vSize - 1)).se >= 0) { ans[now.se] = segt[now.se].fi; segt.set(now.se, mp(Lesser.fi, -2)); ROR(adj[now.se], i) { if (segt[i.se].se == -2) continue; if (segt[i.se].se == -1) { segt.set(i.se, mp(Add.se(ans[now.se], i.fi), i.se)); continue; } if (Lesser.se(Add.se(ans[now.se], i.fi), segt[i.se].fi)) { segt.set(i.se, mp(Add.se(ans[now.se], i.fi), i.se)); continue; } } } return ans; } V<P<T, vll>> rDijk(ll x) { V<P<T, vll>> ans(vSize, mp(Lesser.fi, vll())); if (x < 0 || x >= vSize) return ans; SegT<P<T, ll>> segt(vSize, mp(Lesser.fi, -1), clam(if (l.se < 0) return r; if (r.se < 0) return l; return Lesser.se(l.fi, r.fi) ? l : r;)); segt.set(x, mp(Add.fi, x)); P<T, ll> now; while ((now = segt.que(0, vSize - 1)).se >= 0) { ans[now.se].fi = segt[now.se].fi; segt.set(now.se, mp(Lesser.fi, -2)); ROR(adj[now.se], i) { if (segt[i.se].se == -2) continue; if (segt[i.se].se == -1) { segt.set(i.se, mp(Add.se(ans[now.se].fi, i.fi), i.se)); ans[i.se].se = {now.se}; continue; } if (Lesser.se(Add.se(ans[now.se].fi, i.fi), segt[i.se].fi)) { segt.set(i.se, mp(Add.se(ans[now.se].fi, i.fi), i.se)); ans[i.se].se = {now.se}; continue; } if (Equal.se(Add.se(ans[now.se].fi, i.fi), segt[i.se].fi)) { ans[i.se].se.pb(now.se); continue; } } } return ans; } T Prim(ll x = 0) { T ans = Add.fi; if (x < 0 || x >= vSize) return ans; SegT<P<T, ll>> segt(vSize, mp(Lesser.fi, -1), clam(if (l.se < 0) return r; if (r.se < 0) return l; return Lesser.se(l.fi, r.fi) ? l : r;)); segt.set(x, mp(Add.fi, x)); P<T, ll> now; while ((now = segt.que(0, vSize - 1)).se >= 0) { ans = Add.se(ans, segt[now.se].fi); segt.set(now.se, mp(Lesser.fi, -2)); ROR(adj[now.se], i) { if (segt[i.se].se == -2) continue; if (segt[i.se].se == -1) { segt.set(i.se, i); continue; } if (Lesser.se(i.fi, segt[i.se].fi)) { segt.set(i.se, i); continue; } } } return ans; } P<T, V<P<T, vll>>> rPrim(ll x = 0) { P<T, V<P<T, vll>>> ans = mp(Add.fi, V<P<T, vll>>(vSize, mp(Lesser.fi, vll()))); if (x < 0 || x >= vSize) return ans; SegT<P<T, ll>> segt(vSize, mp(Lesser.fi, -1), clam(if (l.se < 0) return r; if (r.se < 0) return l; return Lesser.se(l.fi, r.fi) ? l : r;)); segt.set(x, mp(Add.fi, x)); P<T, ll> now; while ((now = segt.que(0, vSize - 1)).se >= 0) { ans.se[now.se].fi = segt[now.se].fi; ans.fi = Add.se(ans.fi, ans.se[now.se].fi); segt.set(now.se, mp(Lesser.fi, -2)); ROR(adj[now.se], i) { if (segt[i.se].se == -2) continue; if (segt[i.se].se == -1) { segt.set(i.se, i); ans.se[i.se].se = {now.se}; continue; } if (Lesser.se(i.fi, segt[i.se].fi)) { segt.set(i.se, i); ans.se[i.se].se = {now.se}; continue; } if (Equal.se(i.fi, segt[i.se].fi)) { ans.se[i.se].se.pb(now.se); continue; } } } return ans; } }; template <class T> struct Sum { public: V<T> v, s; ll size; ActPair(T) Add; ActPair(T) Sub; Sum(V<T> v, ActPair(T) Add = ADD, ActPair(T) Sub = SUB) : v(v), size(v.sz), Add(Add), Sub(Sub) { Init(); Calc(); } void Init() { s.asn(size + 1, Add.fi); } void Calc() { REP(i, size) s[i + 1] = Add.se(s[i], v[i]); } T operator()(ll x) { if (x < -1) x = -1; if (x > size - 1) x = size - 1; return s[x + 1]; } T operator()(ll l, ll r) { if (l < 0) l = 0; if (r >= size) r = size - 1; if (l > r) return Add.fi; return Sub.se(s[r + 1], s[l]); } }; using sumll = Sum<ll>; template <class T> struct Sum2 { public: V<V<T>> v, s; ll RowSize, ColumnSize; ActPair(T) Add; ActPair(T) Sub; Sum2(V<V<T>> v, ActPair(T) Add = ADD, ActPair(T) Sub = SUB) : v(v), RowSize(v.sz), ColumnSize(v.sz ? v[0].sz : 0), Add(Add), Sub(Sub) { Init(); Calc(); } void Init() { s.asn(RowSize + 1, V<T>(ColumnSize + 1, Add.fi)); } void Calc() { REP1(r, RowSize) { REP1(c, ColumnSize) { // s[r][c] = Sub.se(Add.se(Add.se(v[r - 1][c - //1], operator()(r - 1, c - 2)), operator()(r - 2, c - 1)), operator()(r //- 2, c - 2)); s[r][c] = Add.se(s[r][c - 1], v[r - 1][c - 1]); } } REP1(r, RowSize) { REP1(c, ColumnSize) { s[r][c] = Add.se(s[r - 1][c], s[r][c]); } } } T operator()(ll r, ll c) { if (r < -1) r = -1; if (c < -1) c = -1; if (r > RowSize - 1) r = RowSize - 1; if (c > ColumnSize - 1) c = ColumnSize - 1; return s[r + 1][c + 1]; } T operator()(ll r1, ll c1, ll r2, ll c2) { if (r1 < 0) r1 = 0; if (c1 < 0) c1 = 0; if (r2 >= RowSize) r2 = RowSize - 1; if (c2 >= ColumnSize) c2 = ColumnSize - 1; if (r1 > r2) return Add.fi; if (c1 > c2) return Add.fi; return Sub.se(Add.se(s[r2 + 1][c2 + 1], s[r1][c1]), Add.se(s[r2 + 1][c1], s[r1][c2 + 1])); } }; using sumll2 = Sum2<ll>; template <class T> struct Point2 { public: V<V<T>> v; ll h, w; Point2() : h(0), w(0) {} Point2(ll h, ll w) : h(h), w(w) { asn(h, w); } Point2(ll h, ll w, T val) : h(h), w(w) { asn(h, w, val); } void assign(ll h, ll w) { v.asn(h, V<T>(w)); } void assign(ll h, ll w, ll val) { v.asn(h, V<T>(w, val)); } T &operator()(ll h, ll w) { return v[h][w]; } T &operator()(pl p) { return v[p.fi][p.se]; } }; template <class T> using P2 = Point2<T>; template <ll Mod> struct Modll { public: ll v; Modll() : v(0) {} Modll(ll _v) { set(_v % Mod + Mod); } Modll &set(ll _v) { v = (_v < Mod) ? _v : (_v - Mod); return *this; } Modll pow(ll n) const { Modll x = *this, ans = 1; while (n) { if (n & 1) ans *= x; x *= x; n >>= 1; } return ans; } Modll inverse() const { return (*this).pow(Mod - 2); } Modll operator+(const Modll &m) const { return Modll().set(v + m.v); } Modll operator-(const Modll &m) const { return Modll().set(Mod + v - m.v); } Modll operator*(const Modll &m) const { return Modll().set((ull(v) * m.v) % Mod); } Modll operator/(const Modll &m) const { return *this * m.inv; } Modll &operator+=(const Modll &m) { return *this = *this + m; } Modll &operator-=(const Modll &m) { return *this = *this - m; } Modll &operator*=(const Modll &m) { return *this = *this * m; } Modll &operator/=(const Modll &m) { return *this = *this / m; } Modll operator-() const { return Modll(0) - *this; } explicit operator bool() const { return v != 0; } friend istream &operator>>(istream &in, Modll &m) { return in >> m.v; } friend ostream &operator<<(ostream &out, const Modll &m) { return out << m.v; } }; using mll = Modll<MOD>; using vmll = V<mll>; using vvmll = V<vmll>; using vvvmll = V<vvmll>; vmll MFactMemo(2, 1); vmll MIFactMemo(2, 1); mll mFact(ll n) { if (MFactMemo.sz <= n) { ll oldsize = MFactMemo.sz; MFactMemo.res(n + 1, 1); FOR(i, oldsize, n) MFactMemo[i] = MFactMemo[i - 1] * i; } return MFactMemo[n]; } mll miFact(ll n) { if (MIFactMemo.sz <= n) { ll oldsize = MIFactMemo.sz; MIFactMemo.res(n + 1, 1); MIFactMemo.bk = mFact(n).inv; rFOR(i, oldsize + 1, n) MIFactMemo[i - 1] = MIFactMemo[i] * i; } return MIFactMemo[n]; } mll mComb(ll n, ll k) { if (n < 0 || k < 0 || n < k) return 0; return mFact(n) * miFact(k) * miFact(n - k); } ll LIS(vll v, ll m = 0) { if (v.sz > 0) { ll ans = 0; vll dp(v.sz, INF); FOR(i, 0, v.sz - 1) { dp[m ? UPB(dp, v[i]) : LOWB(dp, v[i])] = v[i]; } FOR(i, 0, v.sz - 1) { if (dp[i] == INF) break; ans++; } return ans; } else { return 0; } } ll Bsrch(function<bool(ll x)> f, ll mi, ll ma) { ll ng = mi - 1, ok = ma, mid; while (ok - ng > 1) { mid = (ng + ok) / 2; (f(mid) ? ok : ng) = mid; } return ok; } template <class T> V<V<T>> MultiMatrix(V<V<T>> A, V<V<T>> B, ActPair(T) Mul = MUL, ActPair(T) Add = ADD) { V<V<T>> ans; ll ii = A.sz; if (!ii) return ans; ll jj = A[0].sz; if (!jj) return ans; ll jj2 = B.sz; if (!jj2) return ans; if (jj != jj2) return ans; ll kk = B[0].sz; if (!kk) return ans; ans.asn(ii, V<T>(kk, 0)); REP(i, ii) { REP(k, kk) { REP(j, jj) { ans[i][k] = Add.se(ans[i][k], Mul.se(A[i][j], B[j][k])); } } } return ans; } vvll CombMemo(1000, vll(1000, -1)); ll Comb(ll n, ll k) { if ((n < 0) || (k < 0)) return 0; if (CombMemo[n][k] == -1) { if (n < k) CombMemo[n][k] = 0; else { if (n == 0) CombMemo[n][k] = 1; else if (k == 0) CombMemo[n][k] = 1; else if (n == k) CombMemo[n][k] = 1; else CombMemo[n][k] = Comb(n - 1, k - 1) + Comb(n - 1, k); } } return CombMemo[n][k]; } template <class T> map<T, ll> Dict(V<T> v) { map<T, ll> m; if (!v.sz) return m; SORT(v); UNIQUE(v); REP(i, v.sz) { m[v[i]] = i; } return m; } template <class T> vll Cmprs(V<T> v) { auto m = Dict(v); vll ans(v.sz); REP(i, v.sz) { ans[i] = m[v[i]]; } return ans; } template <class T> vll PCmprs(V<T> v) { if (v.sz == 0) return V<T>(); vll tmp(v.sz); vll ans(v.sz); IOTA(tmp, 0); IOTA(ans, 0); sort(tmp.bgn, tmp.en, clam(return v[l] < v[r];)); sort(ans.bgn, ans.en, clam(return tmp[l] < tmp[r];)); return ans; } ll BblCnt(vll rv) { vll v = PCmprs(rv); SegT<ll> b(v.sz, 0); ll ans = 0; REP(i, v.sz) { ans += (i - b.que(0, v[i])); b.add(v[i], 1); } return ans; } template <class T> auto ven(T val) { return val; } template <> auto ven<int>(int val) { return (ll)val; } template <class T, class... Args> auto ven(T val, Args... args) { auto tmp = ven(args...); return V<decltype(tmp)>(val, tmp); } template <class T> void zind(T &v) { v--; } template <class T> void zind(V<T> &v) { ROR(v, i) zind(i); } template <class T, class... Args> void zind(T &v, Args &...args) { zind(v); zind(args...); } void Solve(); signed main() { cin.tie(0); ios::sync_with_stdio(false); cout << setprecision(20) << fixed; Solve(); } void Solve() { li(n); vlc(n, a, b); vpl c(n); REP(i, n) c[i] = mp(a[i] + b[i], i); sort(c.bgn, c.en, lam(return l.fi > r.fi;)); ll t = 0, u = 0, uu = 0; REP(i, n) { if (i % 2 == 0) u += a[c[i].se]; if (i % 2 == 1) uu += b[c[i].se]; } /* while (t < n) { u += a[c[t].se]; t++; if (t == n) break; u -= b[c[t].se]; t++; }*/ sal(u - uu); }
[ "assignment.value.change", "identifier.change", "variable_access.subscript.index.change" ]
941,760
941,761
u211681714
cpp
p03141
#include <bits/stdc++.h> #define all(c) c.begin(), c.end() #define rall(c) c.rbegin(), c.rend() #define debug(x) cerr << #x << ": " << x << endl using namespace std; typedef long long ll; typedef pair<ll, ll> Pll; typedef pair<int, int> Pii; const ll MOD = 1000000007; const long double EPS = 1e-10; const int dyx[4][2] = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}}; int main() { std::ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<Pll> happiness(n); for (int i = 0; i < n; ++i) { cin >> happiness[i].first >> happiness[i].second; } vector<pair<ll, int>> dishes; for (int i = 0; i < n; ++i) { dishes.emplace_back(happiness[i].second - happiness[i].first, i); } sort(rall(dishes)); ll ans[2] = {0, 0}; for (int i = 0; i < n; i += 2) { ans[0] += happiness[dishes[i].second].first; } for (int i = 1; i < n; i += 2) { ans[0] -= happiness[dishes[i].second].second; } for (int i = 0; i < n; i += 2) { ans[1] += happiness[dishes[n - 1 - i].second].first; } for (int i = 1; i < n; i += 2) { ans[1] -= happiness[dishes[n - 1 - i].second].second; } cout << max(ans[0], ans[1]) << endl; }
#include <bits/stdc++.h> #define all(c) c.begin(), c.end() #define rall(c) c.rbegin(), c.rend() #define debug(x) cerr << #x << ": " << x << endl using namespace std; typedef long long ll; typedef pair<ll, ll> Pll; typedef pair<int, int> Pii; const ll MOD = 1000000007; const long double EPS = 1e-10; const int dyx[4][2] = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}}; int main() { std::ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<Pll> happiness(n); for (int i = 0; i < n; ++i) { cin >> happiness[i].first >> happiness[i].second; } vector<pair<ll, int>> dishes; for (int i = 0; i < n; ++i) { dishes.emplace_back(happiness[i].second + happiness[i].first, i); } sort(rall(dishes)); ll ans[2] = {0, 0}; for (int i = 0; i < n; i += 2) { ans[0] += happiness[dishes[i].second].first; } for (int i = 1; i < n; i += 2) { ans[0] -= happiness[dishes[i].second].second; } for (int i = 0; i < n; i += 2) { ans[1] += happiness[dishes[n - 1 - i].second].first; } for (int i = 1; i < n; i += 2) { ans[1] -= happiness[dishes[n - 1 - i].second].second; } cout << max(ans[0], ans[1]) << endl; }
[ "misc.opposites", "expression.operator.arithmetic.change", "call.arguments.change", "expression.operation.binary.change" ]
941,762
941,763
u986399983
cpp
p03141
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int pre = 0; vector<int> line(n); for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; line.at(i) = a + b; pre -= b; } sort(line.begin(), line.end()); reverse(line.begin(), line.end()); int answer = 0; for (int i = 0; i < (n + 1) / 2; i++) { answer += line.at(2 * i); } cout << answer + pre << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long pre = 0; vector<int> line(n); for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; line.at(i) = a + b; pre -= b; } sort(line.begin(), line.end()); reverse(line.begin(), line.end()); long long answer = 0; for (int i = 0; i < (n + 1) / 2; i++) { answer += line.at(2 * i); } cout << answer + pre << endl; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
941,764
941,765
u361777955
cpp
p03141
#include <bits/stdc++.h> #include <iostream> using namespace std; // printf("%.12lf\n",mid); // const long long sze = 2*(2^(long long)(ceil(log(100000)/log(2)))); /* // get part of decimal double intpart; double thiss = modf((double)(n*m)/(double)k, &intpart); */ const long long mod = 1000000007; const double eps = .0000000001; inline void prep() { cin.tie(0); cin.sync_with_stdio(0); }; int main() { prep(); int n; cin >> n; int costs[n]; int costs2[n]; vector<pair<long long, int>> v; for (int i = 0; i < n; i++) { cin >> costs[i]; cin >> costs2[i]; v.push_back({costs[i] + costs2[i], i}); } sort(v.begin(), v.end()); bool turn = true; long long sum1 = 0; long long sum2 = 0; for (int i = 0; i < n; i++) { if (turn) { sum1 += costs[v[i].second]; } else { sum2 += costs2[v[i].second]; } turn = !turn; } cout << sum1 - sum2; return 0; }
#include <bits/stdc++.h> #include <iostream> using namespace std; // printf("%.12lf\n",mid); // const long long sze = 2*(2^(long long)(ceil(log(100000)/log(2)))); /* // get part of decimal double intpart; double thiss = modf((double)(n*m)/(double)k, &intpart); */ const long long mod = 1000000007; const double eps = .0000000001; inline void prep() { cin.tie(0); cin.sync_with_stdio(0); }; int main() { prep(); int n; cin >> n; int costs[n]; int costs2[n]; vector<pair<long long, int>> v; for (int i = 0; i < n; i++) { cin >> costs[i]; cin >> costs2[i]; v.push_back({costs[i] + costs2[i], i}); } sort(v.rbegin(), v.rend()); bool turn = true; long long sum1 = 0; long long sum2 = 0; for (int i = 0; i < n; i++) { if (turn) { sum1 += costs[v[i].second]; } else { sum2 += costs2[v[i].second]; } turn = !turn; } // cout << sum1 << " " << sum2 << endl; cout << sum1 - sum2; return 0; }
[ "call.function.change", "call.arguments.change" ]
941,770
941,771
u381394404
cpp
p03141
#include <algorithm> #include <iostream> #include <vector> using namespace std; #define rep(i, q) for (int i = 0; (q) > i; i++) #define pb push_back #define MAX 1000000000 #define MOD 1000000007 typedef pair<int, int> Paint; bool Pairfirst(const Paint &pf, Paint &ps) { // sortCompare return (pf.first + pf.second) < (ps.first + ps.second); } int main() { int n; cin >> n; int a[n], b[n]; vector<Paint> sa; rep(i, n) { cin >> a[i] >> b[i]; sa.push_back(Paint(a[i], b[i])); } sort(sa.begin(), sa.end(), Pairfirst); int turn = 0; long long kekka = 0; rep(i, n) { if (turn == 0) { kekka += sa[i].first; } else { kekka -= sa[i].second; } turn = (turn + 1) % 2; } cout << kekka << endl; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; #define rep(i, q) for (int i = 0; (q) > i; i++) #define pb push_back #define MAX 1000000000 #define MOD 1000000007 typedef pair<int, int> Paint; bool Pairfirst(const Paint &pf, Paint &ps) { // sortCompare return (pf.first + pf.second) > (ps.first + ps.second); } int main() { int n; cin >> n; int a[n], b[n]; vector<Paint> sa; rep(i, n) { cin >> a[i] >> b[i]; sa.push_back(Paint(a[i], b[i])); } sort(sa.begin(), sa.end(), Pairfirst); int turn = 0; long long kekka = 0; rep(i, n) { if (turn == 0) { kekka += sa[i].first; } else { kekka -= sa[i].second; } turn = (turn + 1) % 2; } cout << kekka << endl; }
[ "misc.opposites", "expression.operator.compare.change", "function.return_value.change", "expression.operation.binary.change" ]
941,779
941,780
u466161487
cpp
p03141
#include <algorithm> #include <array> #include <cmath> #include <cstring> #include <iostream> #include <list> #include <queue> #include <set> #include <string> #include <tuple> #include <vector> const int MOD = 1000000007; using namespace std; typedef long long ll; typedef tuple<ll, int, int> tup; typedef vector<int> vi; typedef vector<ll> vll; typedef pair<int, int> p; typedef vector<p> vp; const int INF = 1e9; ll n, ans = 0; bool visited[100005]; bool comp(const pair<ll, ll> &a, const pair<ll, ll> &b) { return a.first + a.second < b.first + b.second; } int main(int argc, char const *argv[]) { cin >> n; vector<pair<ll, ll>> sushi(n); memset(visited, false, sizeof(visited)); for (int i = 0; i < n; i++) { cin >> sushi[i].first >> sushi[i].second; } sort(sushi.begin(), sushi.end(), comp); for (int i = 0; i < n; i++) { if (i % 2 == 0) { ans += sushi[i].first; } else { ans -= sushi[i].second; } } cout << ans << endl; return 0; }
#include <algorithm> #include <array> #include <cmath> #include <cstring> #include <iostream> #include <list> #include <queue> #include <set> #include <string> #include <tuple> #include <vector> const int MOD = 1000000007; using namespace std; typedef long long ll; typedef tuple<ll, int, int> tup; typedef vector<int> vi; typedef vector<ll> vll; typedef pair<int, int> p; typedef vector<p> vp; const int INF = 1e9; ll n, ans = 0; bool visited[100005]; bool comp(const pair<ll, ll> &a, const pair<ll, ll> &b) { return a.first + a.second > b.first + b.second; } int main(int argc, char const *argv[]) { cin >> n; vector<pair<ll, ll>> sushi(n); memset(visited, false, sizeof(visited)); for (int i = 0; i < n; i++) { cin >> sushi[i].first >> sushi[i].second; } sort(sushi.begin(), sushi.end(), comp); /*for(int i=0;i<n;i++) { cout << sushi[i].first << ' ' << sushi[i].second << endl; }*/ for (int i = 0; i < n; i++) { if (i % 2 == 0) { ans += sushi[i].first; } else { ans -= sushi[i].second; } } cout << ans << endl; return 0; }
[ "misc.opposites", "expression.operator.compare.change", "function.return_value.change", "expression.operation.binary.change" ]
941,786
941,787
u945017646
cpp
p03141
#include <bits/stdc++.h> using namespace std; typedef long long int ll; main() { ll n, turn = 0, ans = 0; cin >> n; ll a[n], b[n]; pair<ll, ll> c[n]; for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; c[i].first = a[i] + b[i]; c[i].second = i; } sort(c, c + n, [](pair<int, int> p, pair<int, int> q) { return p.second < q.second; }); for (int i = 0; i < n; i++) { if (turn == 0) { ans += a[c[i].second]; turn = 1; } else { ans -= b[c[i].second]; turn = 0; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; main() { ll n, turn = 0, ans = 0; cin >> n; ll a[n], b[n]; pair<ll, ll> c[n]; for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; c[i].first = a[i] + b[i]; c[i].second = i; } sort(c, c + n, [](pair<int, int> p, pair<int, int> q) { return p.first > q.first; }); for (int i = 0; i < n; i++) { if (turn == 0) { ans += a[c[i].second]; turn = 1; } else { ans -= b[c[i].second]; turn = 0; } } cout << ans << endl; }
[ "call.arguments.change", "function.return_value.change", "expression.operation.binary.change" ]
941,793
941,794
u268571052
cpp
p03141
#include <bits/stdc++.h> using namespace std; using lli = long long int; using ulli = unsigned long long int; #define debug(x) cerr << #x << " : " << x << endl #define debugv(x) \ cerr << #x << " : {"; \ for (auto value_of_x : x) { \ cerr << value_of_x << ", "; \ } \ cerr << endl namespace atcoder { template <typename T> T ncr(T left, T right) { right = min(left - right, right); T ans = 1; for (T i = 1; i <= right; i++) { ans = ans * (left - right + i) / i; } return ans; } const int LIMIT = 1000000007; const int tenfive = 100000; } // namespace atcoder using namespace atcoder; using TY = array<lli, 3>; int main() { int N; cin >> N; vector<TY> A(N); for (int i = 0; i < N; i++) { cin >> A[i][0] >> A[i][1]; A[i][2] = A[i][0] + A[i][1]; } sort(A.begin(), A.end(), [](const TY &left, const TY &right) { return left[2] < right[2]; }); lli l = 0, r = 0; for (int i = 0; i < A.size(); i++) { if (i % 2 == 0) { l += A[i][0]; } else { r += A[i][1]; } } cout << l - r << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using lli = long long int; using ulli = unsigned long long int; #define debug(x) cerr << #x << " : " << x << endl #define debugv(x) \ cerr << #x << " : {"; \ for (auto value_of_x : x) { \ cerr << value_of_x << ", "; \ } \ cerr << endl namespace atcoder { template <typename T> T ncr(T left, T right) { right = min(left - right, right); T ans = 1; for (T i = 1; i <= right; i++) { ans = ans * (left - right + i) / i; } return ans; } const int LIMIT = 1000000007; const int tenfive = 100000; } // namespace atcoder using namespace atcoder; using TY = array<lli, 3>; int main() { int N; cin >> N; vector<TY> A(N); for (int i = 0; i < N; i++) { cin >> A[i][0] >> A[i][1]; A[i][2] = A[i][0] + A[i][1]; } sort(A.rbegin(), A.rend(), [](const TY &left, const TY &right) { return left[2] < right[2]; }); lli l = 0, r = 0; for (int i = 0; i < A.size(); i++) { if (i % 2 == 0) { l += A[i][0]; } else { r += A[i][1]; } } cout << l - r << endl; return 0; }
[ "call.function.change", "call.arguments.change" ]
941,800
941,801
u031593168
cpp
p03141
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < int(n); ++i) #define all(a) (a).begin(), (a).end() typedef long long ll; int main(void) { int n; cin >> n; vector<ll> a(n), b(n); using P = pair<ll, int>; vector<P> vp(n); rep(i, n) { cin >> a[i] >> b[i]; vp[i] = {max(a[i], b[i]), i}; } sort(all(vp), greater<P>()); ll res = 0; rep(i, n) { int id = vp[i].second; if (i % 2 == 0) { res += a[id]; } else { res -= b[id]; } } cout << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < int(n); ++i) #define all(a) (a).begin(), (a).end() typedef long long ll; int main(void) { int n; cin >> n; vector<int> a(n), b(n); using P = pair<int, int>; vector<P> vp(n); rep(i, n) { cin >> a[i] >> b[i]; vp[i] = {a[i] + b[i], i}; } sort(all(vp), greater<P>()); ll res = 0; rep(i, n) { int id = vp[i].second; if (i % 2 == 0) { res += a[id]; } else { res -= b[id]; } } cout << res << endl; return 0; }
[ "call.remove", "call.arguments.change" ]
941,802
941,803
u241615199
cpp
p03141
#include "bits/stdc++.h" using namespace std; using ll = long long; using pii = pair<int, int>; const int MOD = (int)1e9 + 7, INF = (1 << 27); const ll INFLL = (1LL << 55); #define FOR(i, a, b) for (int(i) = (a); (i) < (int)(b); (i)++) #define rep(i, n) FOR(i, 0, n) template <typename T, typename U> inline void chmax(T &x, U y) { if (x < y) x = y; } template <typename T, typename U> inline void chmin(T &x, U y) { if (x > y) x = y; } using P = pair<ll, ll>; int main() { int n; cin >> n; vector<P> ps; vector<ll> as, bs; rep(i, n) { ll a, b; scanf("%lld%lld", &a, &b); ps.emplace_back(a + b, i); as.emplace_back(a); bs.emplace_back(b); } sort(ps.begin(), ps.end()); ll ans = 0; rep(i, n) { if (~i & 1) ans += as[ps[i].second]; else ans -= bs[ps[i].second]; } cout << ans << endl; }
#include "bits/stdc++.h" using namespace std; using ll = long long; using pii = pair<int, int>; const int MOD = (int)1e9 + 7, INF = (1 << 27); const ll INFLL = (1LL << 55); #define FOR(i, a, b) for (int(i) = (a); (i) < (int)(b); (i)++) #define rep(i, n) FOR(i, 0, n) template <typename T, typename U> inline void chmax(T &x, U y) { if (x < y) x = y; } template <typename T, typename U> inline void chmin(T &x, U y) { if (x > y) x = y; } using P = pair<ll, ll>; int main() { int n; cin >> n; vector<P> ps; vector<ll> as, bs; rep(i, n) { ll a, b; scanf("%lld%lld", &a, &b); ps.emplace_back(a + b, i); as.emplace_back(a); bs.emplace_back(b); } sort(ps.rbegin(), ps.rend()); ll ans = 0; rep(i, n) { if (~i & 1) ans += as[ps[i].second]; else ans -= bs[ps[i].second]; } cout << ans << endl; }
[ "call.function.change", "call.arguments.change" ]
941,804
941,805
u258647915
cpp
p03141
#include <bits/stdc++.h> using namespace std; #include <algorithm> int main() { int N, A, B; cin >> N; vector<int> Sum(N); int ans = 0; for (int i = 0; i < N; i++) { cin >> A >> B; Sum[i] = A + B; ans -= B; } sort(Sum.begin(), Sum.end(), greater<int>()); for (int i = 0; i < N; i += 2) { ans += Sum[i]; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #include <algorithm> int main() { int N, A, B; cin >> N; vector<int> Sum(N); long long ans = 0; for (int i = 0; i < N; i++) { cin >> A >> B; Sum[i] = A + B; ans -= B; } sort(Sum.begin(), Sum.end(), greater<int>()); for (int i = 0; i < N; i += 2) { ans += Sum[i]; } cout << ans << endl; }
[ "variable_declaration.type.primitive.change", "variable_declaration.type.widen.change" ]
941,806
941,807
u030090262
cpp
p03141
#include <bits/stdc++.h> typedef long long ll; using namespace std; int main() { long long n; cin >> n; long long a[100000], b[100000]; vector<pair<long, long>> v; for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; v.push_back(make_pair(b[i] - a[i], a[i])); } sort(v.rbegin(), v.rend()); long long x = 0, y = 0; for (int i = 0; i < n; i++) { if (i % 2 == 0) x += v[i].second; else y += v[i].first + v[i].second; } cout << x - y << endl; }
#include <bits/stdc++.h> typedef long long ll; using namespace std; int main() { long long n; cin >> n; long long a[100000], b[100000]; vector<pair<long, long>> v; for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; v.push_back(make_pair(a[i] + b[i], a[i])); } sort(v.rbegin(), v.rend()); long long x = 0, y = 0; for (int i = 0; i < n; i++) { if (i % 2 == 0) x += v[i].second; else y += v[i].first - v[i].second; } cout << x - y << endl; }
[ "identifier.change", "call.arguments.change", "expression.operation.binary.change", "misc.opposites", "expression.operator.arithmetic.change", "assignment.value.change" ]
941,808
941,809
u546943614
cpp
p03141
#include <algorithm> #include <iostream> #include <string> #include <vector> #define REP(i, a, b) for (int i = int(a); i < int(b); i++) #ifdef _DEBUG_ #define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl #else #define dump(val) #endif using namespace std; typedef long long int ll; template <typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); } template <typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int N; cin >> N; vector<ll> A(N), B(N); REP(i, 0, N) { cin >> A[i] >> B[i]; } vector<int> indices(N); REP(i, 0, N) { indices[i] = i; } sort(begin(indices), end(indices), [&](int a, int b) { return A[a] + B[a] > A[b] + B[b]; }); ll ans = 0; REP(i, 0, N) { if (i % 2 == 0) { ans += A[i]; } else { ans -= B[i]; } } cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> #include <string> #include <vector> #define REP(i, a, b) for (int i = int(a); i < int(b); i++) #ifdef _DEBUG_ #define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl #else #define dump(val) #endif using namespace std; typedef long long int ll; template <typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); } template <typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int N; cin >> N; vector<ll> A(N), B(N); REP(i, 0, N) { cin >> A[i] >> B[i]; } vector<int> indices(N); REP(i, 0, N) { indices[i] = i; } sort(begin(indices), end(indices), [&](int a, int b) { return A[a] + B[a] > A[b] + B[b]; }); ll ans = 0; REP(i, 0, N) { if (i % 2 == 0) { ans += A[indices[i]]; } else { ans -= B[indices[i]]; } } cout << ans << endl; return 0; }
[]
941,810
941,811
u451748673
cpp
p03141
#include <bits/stdc++.h> #define ll long long using namespace std; int main() { int n; cin >> n; vector<tuple<int, int, int>> vt(n); for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; int c = abs(a - b); vt.at(i) = make_tuple(c, a, b); } sort(rbegin(vt), rend(vt)); ll taka = 0, aoki = 0; for (int i = 0; i < n; i++) { if (i % 2 == 0) { taka += get<1>(vt.at(i)); } else { aoki += get<2>(vt.at(i)); } } cout << taka - aoki << endl; }
#include <bits/stdc++.h> #define ll long long using namespace std; int main() { int n; cin >> n; vector<tuple<int, int, int>> vt(n); for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; int c = a + b; vt.at(i) = make_tuple(c, a, b); } sort(rbegin(vt), rend(vt)); ll taka = 0, aoki = 0; for (int i = 0; i < n; i++) { if (i % 2 == 0) { taka += get<1>(vt.at(i)); } else { aoki += get<2>(vt.at(i)); } } cout << taka - aoki << endl; }
[ "call.remove", "misc.opposites", "expression.operator.arithmetic.change", "call.arguments.change", "expression.operation.binary.change" ]
941,812
941,813
u479371430
cpp
p03141
#include <bits/stdc++.h> #define ll long long using namespace std; int main() { int n; cin >> n; vector<tuple<int, int, int>> vt(n); for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; int c = a - b; vt.at(i) = make_tuple(c, a, b); } sort(rbegin(vt), rend(vt)); ll taka = 0, aoki = 0; for (int i = 0; i < n; i++) { if (i % 2 == 0) { taka += get<1>(vt.at(n - 1 - i)); } else { aoki += get<2>(vt.at(i)); } } cout << taka - aoki << endl; }
#include <bits/stdc++.h> #define ll long long using namespace std; int main() { int n; cin >> n; vector<tuple<int, int, int>> vt(n); for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; int c = a + b; vt.at(i) = make_tuple(c, a, b); } sort(rbegin(vt), rend(vt)); ll taka = 0, aoki = 0; for (int i = 0; i < n; i++) { if (i % 2 == 0) { taka += get<1>(vt.at(i)); } else { aoki += get<2>(vt.at(i)); } } cout << taka - aoki << endl; }
[ "misc.opposites", "expression.operator.arithmetic.change", "expression.operation.binary.change", "expression.operation.binary.remove" ]
941,814
941,813
u479371430
cpp
p03141
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vint; typedef pair<int, int> pint; typedef vector<pint> vpint; #define rep(i, n) for (int i = 0; i < (n); i++) #define REP(i, n) for (int i = n - 1; i >= (0); i--) #define reps(i, f, n) for (int i = (f); i < (n); i++) #define each(it, v) \ for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++) #define all(v) (v).begin(), (v).end() #define eall(v) unique(all(v), v.end()) #define pb push_back #define mp make_pair #define fi first #define se second #define chmax(a, b) a = (((a) < (b)) ? (b) : (a)) #define chmin(a, b) a = (((a) > (b)) ? (b) : (a)) const int MOD = 1e9 + 7; const int INF = 1e9; const ll INFF = 1e18; int n; ll a[100010], b[100010]; int main(int argc, char const *argv[]) { cin >> n; rep(i, n) cin >> a[i] >> b[i]; vector<pair<int, int>> v; rep(i, n) v.pb(mp(a[i] + b[i], i)); sort(all(v)); reverse(all(v)); ll ans = 0; rep(i, n) { if (i % 2 == 0) ans += a[v[i].se]; else ans -= a[v[i].se]; } printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vint; typedef pair<int, int> pint; typedef vector<pint> vpint; #define rep(i, n) for (int i = 0; i < (n); i++) #define REP(i, n) for (int i = n - 1; i >= (0); i--) #define reps(i, f, n) for (int i = (f); i < (n); i++) #define each(it, v) \ for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++) #define all(v) (v).begin(), (v).end() #define eall(v) unique(all(v), v.end()) #define pb push_back #define mp make_pair #define fi first #define se second #define chmax(a, b) a = (((a) < (b)) ? (b) : (a)) #define chmin(a, b) a = (((a) > (b)) ? (b) : (a)) const int MOD = 1e9 + 7; const int INF = 1e9; const ll INFF = 1e18; int n; ll a[100010], b[100010]; int main(int argc, char const *argv[]) { cin >> n; rep(i, n) cin >> a[i] >> b[i]; vector<pair<ll, int>> v; rep(i, n) v.pb(mp(a[i] + b[i], i)); sort(all(v)); reverse(all(v)); ll ans = 0; rep(i, n) { if (i % 2 == 0) ans += a[v[i].se]; else ans -= b[v[i].se]; } printf("%lld\n", ans); return 0; }
[ "assignment.value.change", "identifier.change" ]
941,817
941,818
u029876051
cpp
p03141
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <queue> #include <string> #include <vector> #define pb push_back #define int long long int using namespace std; typedef pair<int, int> pii; int n; struct mypair1 { int x, y, z, index; mypair1(int a, int b, int c, int d) { x = a; y = b; z = c; index = d; } bool operator<(const mypair1 &another) const { if (x == another.x) return y < another.y; return x < another.x; } }; vector<mypair1> m1; int hako[111111]; signed main() { cin >> n; int a, b; for (int i = 0; i < n; i++) { cin >> a >> b; m1.pb(mypair1(a + b, a, b, i)); } sort(m1.begin(), m1.end()); int res = 0; for (int i = 0; i < n; i++) { if (i % 2 == 0) { res += m1[i].y; } else { res -= m1[i].z; } } cout << res << endl; return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <queue> #include <string> #include <vector> #define pb push_back #define int long long int using namespace std; typedef pair<int, int> pii; int n; struct mypair1 { int x, y, z, index; mypair1(int a, int b, int c, int d) { x = a; y = b; z = c; index = d; } bool operator<(const mypair1 &another) const { if (x == another.x) return y > another.y; return x > another.x; } }; vector<mypair1> m1; int hako[111111]; signed main() { cin >> n; int a, b; for (int i = 0; i < n; i++) { cin >> a >> b; m1.pb(mypair1(a + b, a, b, i)); } sort(m1.begin(), m1.end()); int res = 0; for (int i = 0; i < n; i++) { if (i % 2 == 0) { res += m1[i].y; } else { res -= m1[i].z; } } cout << res << endl; return 0; }
[ "misc.opposites", "expression.operator.compare.change", "function.return_value.change", "expression.operation.binary.change" ]
941,822
941,823
u733823138
cpp
p03141
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <queue> #include <string> #include <vector> #define pb push_back #define int long long int using namespace std; typedef pair<int, int> pii; int n; struct mypair1 { int x, y, z, index; mypair1(int a, int b, int c, int d) { x = a; y = b; z = c; index = d; } bool operator<(const mypair1 &another) const { if (x == another.x) return y > another.y; return x < another.x; } }; vector<mypair1> m1; int hako[111111]; signed main() { cin >> n; int a, b; for (int i = 0; i < n; i++) { cin >> a >> b; m1.pb(mypair1(a + b, a, b, i)); } sort(m1.begin(), m1.end()); int res = 0; for (int i = 0; i < n; i++) { if (i % 2 == 0) { res += m1[i].y; } else { res -= m1[i].z; } } cout << res << endl; return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <queue> #include <string> #include <vector> #define pb push_back #define int long long int using namespace std; typedef pair<int, int> pii; int n; struct mypair1 { int x, y, z, index; mypair1(int a, int b, int c, int d) { x = a; y = b; z = c; index = d; } bool operator<(const mypair1 &another) const { if (x == another.x) return y > another.y; return x > another.x; } }; vector<mypair1> m1; int hako[111111]; signed main() { cin >> n; int a, b; for (int i = 0; i < n; i++) { cin >> a >> b; m1.pb(mypair1(a + b, a, b, i)); } sort(m1.begin(), m1.end()); int res = 0; for (int i = 0; i < n; i++) { if (i % 2 == 0) { res += m1[i].y; } else { res -= m1[i].z; } } cout << res << endl; return 0; }
[ "misc.opposites", "expression.operator.compare.change", "function.return_value.change", "expression.operation.binary.change" ]
941,824
941,823
u733823138
cpp
p03141
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <queue> #include <string> #include <vector> #define pb push_back #define int long long int using namespace std; typedef pair<int, int> pii; int n; struct mypair1 { int x, y, z, index; mypair1(int a, int b, int c, int d) { x = a; y = b; z = c; index = d; } bool operator<(const mypair1 &another) const { if (x == another.x) return y > another.y; return x < another.x; } }; vector<mypair1> m1; int hako[111111]; signed main() { cin >> n; int a, b; for (int i = 0; i < n; i++) { cin >> a >> b; m1.pb(mypair1(a - b, a, b, i)); } sort(m1.begin(), m1.end()); int res = 0; for (int i = 0; i < n; i++) { if (i % 2 == 0) { res += m1[i].y; } else { res -= m1[i].z; } } cout << res << endl; return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <queue> #include <string> #include <vector> #define pb push_back #define int long long int using namespace std; typedef pair<int, int> pii; int n; struct mypair1 { int x, y, z, index; mypair1(int a, int b, int c, int d) { x = a; y = b; z = c; index = d; } bool operator<(const mypair1 &another) const { if (x == another.x) return y > another.y; return x > another.x; } }; vector<mypair1> m1; int hako[111111]; signed main() { cin >> n; int a, b; for (int i = 0; i < n; i++) { cin >> a >> b; m1.pb(mypair1(a + b, a, b, i)); } sort(m1.begin(), m1.end()); int res = 0; for (int i = 0; i < n; i++) { if (i % 2 == 0) { res += m1[i].y; } else { res -= m1[i].z; } } cout << res << endl; return 0; }
[ "misc.opposites", "expression.operator.compare.change", "function.return_value.change", "expression.operation.binary.change", "expression.operator.arithmetic.change", "call.arguments.change" ]
941,825
941,823
u733823138
cpp
p03141
#include <algorithm> #include <iostream> #include <tuple> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) #define ll long long using namespace std; typedef tuple<ll, ll, ll> ituple; int N; ll A[100005]; ll B[100005]; ll C[100005]; vector<ituple> y; int main() { cin >> N; rep(i, N) { cin >> A[i] >> B[i]; C[i] = A[i] + B[i]; } rep(i, N) { auto x = make_tuple(C[i], A[i], B[i]); y.push_back(x); } sort(y.begin(), y.end()); /*/ rep(i, N) { cout << get<0>(y[i]) <<" " <<get<1>(y[i]) <<" " <<get<2>(y[i]) ; cout << endl; } //*/ ll ans = 0; rep(i, N) { if (i % 2 == 0) ans += get<1>(y[i]); else ans -= get<2>(y[i]); } cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> #include <tuple> //#include <string> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) #define ll long long using namespace std; typedef tuple<ll, ll, ll> ituple; int N; ll A[100005]; ll B[100005]; ll C[100005]; vector<ituple> y; int main() { cin >> N; rep(i, N) { cin >> A[i] >> B[i]; C[i] = A[i] + B[i]; } rep(i, N) { auto x = make_tuple(C[i], A[i], B[i]); y.push_back(x); } sort(y.rbegin(), y.rend()); /*/ rep(i, N) { cout << get<0>(y[i]) <<" " <<get<1>(y[i]) <<" " <<get<2>(y[i]) ; cout << endl; } //*/ ll ans = 0; rep(i, N) { if (i % 2 == 0) ans += get<1>(y[i]); else ans -= get<2>(y[i]); } cout << ans << endl; return 0; }
[ "call.function.change", "call.arguments.change" ]
941,836
941,837
u180262908
cpp
p03141
#include <algorithm> #include <iostream> #include <tuple> //#include <string> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) #define ll long long using namespace std; typedef tuple<ll, ll, ll> ituple; int N; ll A[100005]; ll B[100005]; ll C[100005]; vector<ituple> y; int main() { cin >> N; rep(i, N) { cin >> A[i] >> B[i]; C[i] = A[i] - B[i]; } rep(i, N) { auto x = make_tuple(C[i], A[i], B[i]); y.push_back(x); } sort(y.begin(), y.end()); /*/ rep(i, N) { cout << get<0>(y[i]) <<" " <<get<1>(y[i]) <<" " <<get<2>(y[i]) ; cout << endl; } //*/ ll ans = 0; rep(i, N) { if (i % 2 == 0) ans += get<1>(y[i]); else ans -= get<2>(y[i]); } cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> #include <tuple> //#include <string> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) #define ll long long using namespace std; typedef tuple<ll, ll, ll> ituple; int N; ll A[100005]; ll B[100005]; ll C[100005]; vector<ituple> y; int main() { cin >> N; rep(i, N) { cin >> A[i] >> B[i]; C[i] = A[i] + B[i]; } rep(i, N) { auto x = make_tuple(C[i], A[i], B[i]); y.push_back(x); } sort(y.rbegin(), y.rend()); /*/ rep(i, N) { cout << get<0>(y[i]) <<" " <<get<1>(y[i]) <<" " <<get<2>(y[i]) ; cout << endl; } //*/ ll ans = 0; rep(i, N) { if (i % 2 == 0) ans += get<1>(y[i]); else ans -= get<2>(y[i]); } cout << ans << endl; return 0; }
[ "misc.opposites", "expression.operator.arithmetic.change", "assignment.value.change", "expression.operation.binary.change", "call.function.change", "call.arguments.change" ]
941,838
941,837
u180262908
cpp
p03141
#include <algorithm> #include <iostream> #include <tuple> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) #define ll long long using namespace std; typedef tuple<ll, ll, ll> ituple; int N; ll A[100005]; ll B[100005]; ll C[100005]; vector<ituple> y; int main() { cin >> N; rep(i, N) { cin >> A[i] >> B[i]; C[i] = abs(A[i] - B[i]); } rep(i, N) { auto x = make_tuple(C[i], A[i], B[i]); y.push_back(x); } sort(y.rbegin(), y.rend()); /*/ rep(i, N) { cout << get<0>(y[i]) <<" " <<get<1>(y[i]) <<" " <<get<2>(y[i]) ; cout << endl; } //*/ ll ans = 0; rep(i, N) { if (i % 2 == 0) ans += get<1>(y[i]); else ans -= get<2>(y[i]); } cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> #include <tuple> //#include <string> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) #define ll long long using namespace std; typedef tuple<ll, ll, ll> ituple; int N; ll A[100005]; ll B[100005]; ll C[100005]; vector<ituple> y; int main() { cin >> N; rep(i, N) { cin >> A[i] >> B[i]; C[i] = A[i] + B[i]; } rep(i, N) { auto x = make_tuple(C[i], A[i], B[i]); y.push_back(x); } sort(y.rbegin(), y.rend()); /*/ rep(i, N) { cout << get<0>(y[i]) <<" " <<get<1>(y[i]) <<" " <<get<2>(y[i]) ; cout << endl; } //*/ ll ans = 0; rep(i, N) { if (i % 2 == 0) ans += get<1>(y[i]); else ans -= get<2>(y[i]); } cout << ans << endl; return 0; }
[ "call.remove", "misc.opposites", "expression.operator.arithmetic.change", "assignment.value.change", "call.arguments.change", "expression.operation.binary.change" ]
941,839
941,837
u180262908
cpp
p03141
#include <bits/stdc++.h> using namespace std; #define lint long long #define P pair<int, int> #define LLP pair<long long, long long> #define REP(i, x, n) for (int i = (x), i##_len = (int)(n); i < i##_len; ++i) #define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; ++i) #define repr(i, n) for (int i = (int)(n)-1; i >= 0; --i) #define SORT(x) sort((x).begin(), (x).end()) #define SORT_INV(x) sort((x).rbegin(), (x).rend()) const int IINF = 1e9 + 10; const long long LLINF = (long long)1e18 + 10; const long long MOD = (long long)1e9 + 7; const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1}; const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1}; const double EPS = 1e-8; bool comp(LLP a, LLP b) { return a.first - a.second == b.first - b.second ? a.first > b.first : a.first - a.second < b.first - b.second; } int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector<LLP> v(n); rep(i, n) { cin >> v[i].first >> v[i].second; } sort(v.begin(), v.end(), comp); lint ans = 0; rep(i, n) { if (i % 2 == 0) { ans += v[i].first; } else { ans -= v[i].second; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define lint long long #define P pair<int, int> #define LLP pair<long long, long long> #define REP(i, x, n) for (int i = (x), i##_len = (int)(n); i < i##_len; ++i) #define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; ++i) #define repr(i, n) for (int i = (int)(n)-1; i >= 0; --i) #define SORT(x) sort((x).begin(), (x).end()) #define SORT_INV(x) sort((x).rbegin(), (x).rend()) const int IINF = 1e9 + 10; const long long LLINF = (long long)1e18 + 10; const long long MOD = (long long)1e9 + 7; const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1}; const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1}; const double EPS = 1e-8; bool comp(LLP a, LLP b) { return a.first + a.second == b.first + b.second ? a.first > b.first : a.first + a.second > b.first + b.second; } int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vector<LLP> v(n); rep(i, n) { cin >> v[i].first >> v[i].second; } sort(v.begin(), v.end(), comp); lint ans = 0; rep(i, n) { if (i % 2 == 0) { ans += v[i].first; } else { ans -= v[i].second; } } cout << ans << endl; return 0; }
[ "misc.opposites", "expression.operator.arithmetic.change", "control_flow.loop.for.condition.change", "function.return_value.change", "expression.operation.binary.change", "expression.operator.compare.change" ]
941,849
941,850
u895641117
cpp
p03141
#include <bits/stdc++.h> /**/ using namespace std; int main() { long long int N; cin >> N; map<pair<long long int, long long int>, long long int> count; vector<pair<long long int, pair<long long int, long long int>>> A, B; for (size_t i = 0; i < N; i++) { long long int a, b; cin >> a >> b; auto ab = make_pair(a, b); A.push_back(make_pair(a - b, ab)); B.push_back(make_pair(b - a, ab)); count[ab]++; } sort(A.rbegin(), A.rend()); sort(B.rbegin(), B.rend()); bool turn = true; auto ap = A.begin(), bp = B.begin(); long long int Asum = 0, Bsum = 0; while (ap < A.end() && bp < B.end()) { if (turn) { if (count[(*ap).second] == 0) { ap++; continue; } count[(*ap).second]--; Asum += (*ap).second.first; ap++; } else { if (count[(*bp).second] == 0) { bp++; continue; } count[(*bp).second]--; Bsum += (*bp).second.second; bp++; } turn = !turn; } cout << Asum - Bsum << endl; }
#include <bits/stdc++.h> /**/ using namespace std; int main() { long long int N; cin >> N; map<pair<long long int, long long int>, long long int> count; vector<pair<long long int, pair<long long int, long long int>>> A, B; for (size_t i = 0; i < N; i++) { long long int a, b; cin >> a >> b; auto ab = make_pair(a, b); A.push_back(make_pair(a + b, ab)); B.push_back(make_pair(b + a, ab)); count[ab]++; } sort(A.rbegin(), A.rend()); sort(B.rbegin(), B.rend()); bool turn = true; auto ap = A.begin(), bp = B.begin(); long long int Asum = 0, Bsum = 0; while (ap < A.end() && bp < B.end()) { if (turn) { if (count[(*ap).second] == 0) { ap++; continue; } count[(*ap).second]--; Asum += (*ap).second.first; ap++; } else { if (count[(*bp).second] == 0) { bp++; continue; } count[(*bp).second]--; Bsum += (*bp).second.second; bp++; } turn = !turn; } cout << Asum - Bsum << endl; }
[ "misc.opposites", "expression.operator.arithmetic.change", "call.arguments.change", "expression.operation.binary.change" ]
941,858
941,859
u779353743
cpp
p03141
#include <bits/stdc++.h> /**/ using namespace std; int main() { long long int N; cin >> N; map<pair<long long int, long long int>, long long int> count; vector<pair<long long int, pair<long long int, long long int>>> A, B; for (size_t i = 0; i < N; i++) { long long int a, b; cin >> a >> b; auto ab = make_pair(a, b); A.push_back(make_pair(a - b * 2, ab)); B.push_back(make_pair(b - a * 2, ab)); count[ab]++; } sort(A.rbegin(), A.rend()); sort(B.rbegin(), B.rend()); bool turn = true; auto ap = A.begin(), bp = B.begin(); long long int Asum = 0, Bsum = 0; while (ap < A.end() && bp < B.end()) { if (turn) { if (count[(*ap).second] == 0) { ap++; continue; } count[(*ap).second]--; Asum += (*ap).second.first; ap++; } else { if (count[(*bp).second] == 0) { bp++; continue; } count[(*bp).second]--; Bsum += (*bp).second.second; bp++; } turn = !turn; } cout << Asum - Bsum << endl; }
#include <bits/stdc++.h> /**/ using namespace std; int main() { long long int N; cin >> N; map<pair<long long int, long long int>, long long int> count; vector<pair<long long int, pair<long long int, long long int>>> A, B; for (size_t i = 0; i < N; i++) { long long int a, b; cin >> a >> b; auto ab = make_pair(a, b); A.push_back(make_pair(a + b, ab)); B.push_back(make_pair(b + a, ab)); count[ab]++; } sort(A.rbegin(), A.rend()); sort(B.rbegin(), B.rend()); bool turn = true; auto ap = A.begin(), bp = B.begin(); long long int Asum = 0, Bsum = 0; while (ap < A.end() && bp < B.end()) { if (turn) { if (count[(*ap).second] == 0) { ap++; continue; } count[(*ap).second]--; Asum += (*ap).second.first; ap++; } else { if (count[(*bp).second] == 0) { bp++; continue; } count[(*bp).second]--; Bsum += (*bp).second.second; bp++; } turn = !turn; } cout << Asum - Bsum << endl; }
[ "misc.opposites", "expression.operator.arithmetic.change", "call.arguments.change", "expression.operation.binary.change", "expression.operation.binary.remove" ]
941,860
941,859
u779353743
cpp
p03141
#include <bits/stdc++.h> /**/ using namespace std; int main() { long long int N; cin >> N; map<pair<long long int, long long int>, long long int> count; vector<pair<long long int, pair<long long int, long long int>>> A, B; for (size_t i = 0; i < N; i++) { long long int a, b; cin >> a >> b; auto ab = make_pair(a, b); A.push_back(make_pair(a * 2 - b, ab)); B.push_back(make_pair(b * 2 - a, ab)); count[ab]++; } sort(A.rbegin(), A.rend()); sort(B.rbegin(), B.rend()); bool turn = true; auto ap = A.begin(), bp = B.begin(); long long int Asum = 0, Bsum = 0; while (ap < A.end() && bp < B.end()) { if (turn) { if (count[(*ap).second] == 0) { ap++; continue; } count[(*ap).second]--; Asum += (*ap).second.first; ap++; } else { if (count[(*bp).second] == 0) { bp++; continue; } count[(*bp).second]--; Bsum += (*bp).second.second; bp++; } turn = !turn; } cout << Asum - Bsum << endl; }
#include <bits/stdc++.h> /**/ using namespace std; int main() { long long int N; cin >> N; map<pair<long long int, long long int>, long long int> count; vector<pair<long long int, pair<long long int, long long int>>> A, B; for (size_t i = 0; i < N; i++) { long long int a, b; cin >> a >> b; auto ab = make_pair(a, b); A.push_back(make_pair(a + b, ab)); B.push_back(make_pair(b + a, ab)); count[ab]++; } sort(A.rbegin(), A.rend()); sort(B.rbegin(), B.rend()); bool turn = true; auto ap = A.begin(), bp = B.begin(); long long int Asum = 0, Bsum = 0; while (ap < A.end() && bp < B.end()) { if (turn) { if (count[(*ap).second] == 0) { ap++; continue; } count[(*ap).second]--; Asum += (*ap).second.first; ap++; } else { if (count[(*bp).second] == 0) { bp++; continue; } count[(*bp).second]--; Bsum += (*bp).second.second; bp++; } turn = !turn; } cout << Asum - Bsum << endl; }
[ "expression.operator.arithmetic.change", "call.arguments.change", "expression.operation.binary.change", "expression.operation.binary.remove" ]
941,861
941,859
u779353743
cpp
p03141
#include <algorithm> #include <bitset> #include <chrono> #include <complex> #include <cstdio> #include <fstream> #include <iostream> #include <list> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define REP(i, x, y) for (ll i = x; i <= y; i++) #define SIZE(a) ll(a.size()) #define vll vector<ll> #define MEMSET(a, n, m) \ for (ll i = 0; i <= n; i++) \ a[i] = m #define BIT(n) (ll(1) << n) #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) #define UNIQUE_ARRAY(a, x) unique(a + 1, a + x + 1) - a - 1 #define SORT(a, n) sort(a + 1, a + n + 1) #define SORT_O(a, n, order) sort(a + 1, a + n + 1, order) #define PER(i, y, x) for (ll i = y; i >= x; i--) typedef long long ll; using namespace std; ll const MOD = 1e9 + 7; ll mod_p(ll x, ll y) { x %= MOD; y %= MOD; return (x + y + MOD) % MOD; } ll mod_m(ll x, ll y) { x %= MOD; y %= MOD; return x * y % MOD; } ll mod_pow(ll x, ll t) { x %= MOD; if (t == 0) { return 1; } else { ll v = mod_pow(x, t / 2); if (t % 2 == 0) { return v * v % MOD; } else { return v * v % MOD * x % MOD; } } } ll mod_inv(ll x) { return mod_pow(x, MOD - 2); } struct edge { long long to; long long len; bool operator<(const edge &rhs) const { return len > rhs.len; } }; ll const MAX = 1e5 + 5; ll a[MAX], b[MAX]; ll c[MAX]; bool ord(ll x, ll y) { return b[x] + a[x] > b[y] + a[x]; } int main() { ll n; cin >> n; REP(i, 1, n) { cin >> a[i] >> b[i]; } REP(i, 1, n) { c[i] = i; } SORT_O(c, n, ord); ll ans = 0; REP(i, 1, n) { if (i % 2 == 1) { ans += a[c[i]]; } else { ans -= b[c[i]]; } } cout << ans << endl; }
#include <algorithm> #include <bitset> #include <chrono> #include <complex> #include <cstdio> #include <fstream> #include <iostream> #include <list> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define REP(i, x, y) for (ll i = x; i <= y; i++) #define SIZE(a) ll(a.size()) #define vll vector<ll> #define MEMSET(a, n, m) \ for (ll i = 0; i <= n; i++) \ a[i] = m #define BIT(n) (ll(1) << n) #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) #define UNIQUE_ARRAY(a, x) unique(a + 1, a + x + 1) - a - 1 #define SORT(a, n) sort(a + 1, a + n + 1) #define SORT_O(a, n, order) sort(a + 1, a + n + 1, order) #define PER(i, y, x) for (ll i = y; i >= x; i--) typedef long long ll; using namespace std; ll const MOD = 1e9 + 7; ll mod_p(ll x, ll y) { x %= MOD; y %= MOD; return (x + y + MOD) % MOD; } ll mod_m(ll x, ll y) { x %= MOD; y %= MOD; return x * y % MOD; } ll mod_pow(ll x, ll t) { x %= MOD; if (t == 0) { return 1; } else { ll v = mod_pow(x, t / 2); if (t % 2 == 0) { return v * v % MOD; } else { return v * v % MOD * x % MOD; } } } ll mod_inv(ll x) { return mod_pow(x, MOD - 2); } struct edge { long long to; long long len; bool operator<(const edge &rhs) const { return len > rhs.len; } }; ll const MAX = 1e5 + 5; ll a[MAX], b[MAX]; ll c[MAX]; bool ord(ll x, ll y) { return b[x] + a[x] > b[y] + a[y]; } int main() { ll n; cin >> n; REP(i, 1, n) { cin >> a[i] >> b[i]; } REP(i, 1, n) { c[i] = i; } SORT_O(c, n, ord); ll ans = 0; REP(i, 1, n) { if (i % 2 == 1) { ans += a[c[i]]; } else { ans -= b[c[i]]; } } cout << ans << endl; }
[ "identifier.change", "variable_access.subscript.index.change", "function.return_value.change", "expression.operation.binary.change" ]
941,866
941,867
u834354741
cpp
p03141
#include <bits/stdc++.h> using namespace std; using ll = long long; const int INF = 1e9; const int MOD = 1e9 + 7; int main() { int n; cin >> n; vector<ll> a(n), b(n); for (int i = 0; i < n; ++i) cin >> a[i] >> b[i]; vector<pair<ll, int>> c; ll t = 0, k = 0; for (int i = 0; i < n; ++i) { c.emplace_back(b[i] - a[i], i); } sort(c.begin(), c.end(), greater<pair<ll, int>>()); for (int i = 0; i < n; ++i) { if (i % 2 == 0) { t += a[c[i].second]; } else { k += b[c[i].second]; } } cout << t - k << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const int INF = 1e9; const int MOD = 1e9 + 7; int main() { int n; cin >> n; vector<ll> a(n), b(n); for (int i = 0; i < n; ++i) cin >> a[i] >> b[i]; vector<pair<ll, int>> c; ll t = 0, k = 0; for (int i = 0; i < n; ++i) { c.emplace_back(b[i] + a[i], i); } sort(c.begin(), c.end(), greater<pair<ll, int>>()); for (int i = 0; i < n; ++i) { if (i % 2 == 0) { t += a[c[i].second]; } else { k += b[c[i].second]; } } cout << t - k << endl; return 0; }
[ "misc.opposites", "expression.operator.arithmetic.change", "call.arguments.change", "expression.operation.binary.change" ]
941,868
941,869
u054652697
cpp
p03142
#include <array> #include <bits/stdc++.h> using namespace std; using ULL = unsigned long long; using UL = unsigned; using LL = long long; #define rep(i, n) for (UL i = 0; i < (n); i++) struct Problem { void Solve() { UL N, M; cin >> N >> M; vector<vector<UL>> E(N); vector<UL> F(N); vector<UL> P(N, -1); rep(i, N + M - 1) { UL u, v; cin >> u >> v; u--; v--; E[u].push_back(v); F[v]++; } queue<UL> Q; rep(i, N) if (F[i] == 0) Q.push(i); while (Q.size()) { UL p = Q.front(); Q.pop(); for (UL e : E[p]) { F[e]--; if (F[e] == 0) P[e] = p; Q.push(e); } } rep(i, N) cout << (P[i] + 1) << endl; } Problem(); }; int main() { unique_ptr<Problem> p(new Problem()); p->Solve(); return 0; } Problem::Problem() { cout << fixed << setprecision(10); }
#include <array> #include <bits/stdc++.h> using namespace std; using ULL = unsigned long long; using UL = unsigned; using LL = long long; #define rep(i, n) for (UL i = 0; i < (n); i++) struct Problem { void Solve() { UL N, M; cin >> N >> M; vector<vector<UL>> E(N); vector<UL> F(N); vector<UL> P(N, -1); rep(i, N + M - 1) { UL u, v; cin >> u >> v; u--; v--; E[u].push_back(v); F[v]++; } queue<UL> Q; rep(i, N) if (F[i] == 0) Q.push(i); while (Q.size()) { UL p = Q.front(); Q.pop(); for (UL e : E[p]) { F[e]--; if (F[e] == 0) { P[e] = p; Q.push(e); } } } rep(i, N) cout << (P[i] + 1) << endl; } Problem(); }; int main() { unique_ptr<Problem> p(new Problem()); p->Solve(); return 0; } Problem::Problem() { cout << fixed << setprecision(10); }
[]
941,881
941,882
u331948661
cpp
p03142
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int N, M; cin >> N >> M; vector<vector<int>> G(N + 1); vector<int> PC(N + 1, 0); for (int i = 0; i < N + M - 1; i++) { int a, b; cin >> a >> b; G[a].emplace_back(b); PC[b]++; } vector<int> P(N); queue<int> que; for (int i = 1; i < N + 1; i++) { if (PC[i] == 0) { que.push(i); P[i] = 0; break; } } while (!que.empty()) { int u = que.front(); que.pop(); for (int v : G[u]) { if (PC[v] > 1) { PC[v]--; } else { P[v] = u; que.push(v); } } } for (int i = 1; i < N + 1; i++) { cout << P[i] << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int N, M; cin >> N >> M; vector<vector<int>> G(N + 1); vector<int> PC(N + 1, 0); for (int i = 0; i < N + M - 1; i++) { int a, b; cin >> a >> b; G[a].emplace_back(b); PC[b]++; } vector<int> P(N + 1); queue<int> que; for (int i = 1; i < N + 1; i++) { if (PC[i] == 0) { que.push(i); P[i] = 0; break; } } while (!que.empty()) { int u = que.front(); que.pop(); for (int v : G[u]) { if (PC[v] > 1) { PC[v]--; } else { P[v] = u; que.push(v); } } } for (int i = 1; i < N + 1; i++) { cout << P[i] << '\n'; } return 0; }
[ "assignment.change" ]
941,892
941,893
u782098901
cpp
p03142
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define all(x) (x).begin(), (x).end() // 昇順ソート #define rall(v) (v).rbegin(), (v).rend() // 降順ソート #define INF 1LL << 60 typedef long long int LL; typedef long long int ll; #define pll pair<ll, ll> #define F first #define S second const int MOD = 1000000007; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } // sort(all(x))とするとソートできるよ // 10^x は pow(10,(x)) // 任意のlogは 対数の底の変換を使う log(N) / log(任意の底) int main() { int N, M; cin >> N >> M; vector<vector<int>> G(N, vector<int>()); vector<int> h(N); rep(i, N) { int a, b; cin >> a >> b; a--; b--; G[a].push_back(b); h[b]++; } queue<int> zero; rep(i, N) if (h[i] == 0) zero.push(i); vector<int> dist( N); // dist[i]:=i番目の頂点を通るときの最長経路 // この問題では根っこが1つしかないはずなので、根っこからの最長距離にあたるはず int j = 0; while (zero.size()) { int v = zero.front(); zero.pop(); for (auto nv : G[v]) { h[nv]--; chmax(dist[nv], dist[v] + 1); if (h[nv] == 0) zero.push(nv); } } vector<int> ans(N, -1); rep(v, N) for (auto nv : G[v]) if (dist[nv] - dist[v] == 1) ans[nv] = v; // 距離の差が1のものが必然的に隣り合ったもので、これがもともとのグラフの経路のはず。※1 rep(i, N) cout << ans[i] + 1 << endl; // +1 // はグラフ作成時に0indexにしたやつをもとに戻すのと、根っこは0を出力なので、-1+1=0にするため。根は一つしかないから(至言) } // ※1 これに関しては、解説放送がわかりやすい。 // 端的に説明すると、距離差が2以上のとき、つまり頂点をジャンプして子孫につながるルートが正規ルートだと仮定すると、距離差1の経路は新たに頂点を生まないと生えてこないことになる。 // これは明らかにグラフ形成と有向辺の追加のルールに反しているので矛盾。
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define all(x) (x).begin(), (x).end() // 昇順ソート #define rall(v) (v).rbegin(), (v).rend() // 降順ソート #define INF 1LL << 60 typedef long long int LL; typedef long long int ll; #define pll pair<ll, ll> #define F first #define S second const int MOD = 1000000007; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } // sort(all(x))とするとソートできるよ // 10^x は pow(10,(x)) // 任意のlogは 対数の底の変換を使う log(N) / log(任意の底) int main() { int N, M; cin >> N >> M; vector<vector<int>> G(N, vector<int>()); vector<int> h(N); rep(i, N - 1 + M) { int a, b; cin >> a >> b; a--; b--; G[a].push_back(b); h[b]++; } queue<int> zero; rep(i, N) if (h[i] == 0) zero.push(i); vector<int> dist( N); // dist[i]:=i番目の頂点を通るときの最長経路 // この問題では根っこが1つしかないはずなので、根っこからの最長距離にあたるはず int j = 0; while (zero.size()) { int v = zero.front(); zero.pop(); for (auto nv : G[v]) { h[nv]--; chmax(dist[nv], dist[v] + 1); if (h[nv] == 0) zero.push(nv); } } vector<int> ans(N, -1); rep(v, N) for (auto nv : G[v]) if (dist[nv] - dist[v] == 1) ans[nv] = v; // 距離の差が1のものが必然的に隣り合ったもので、これがもともとのグラフの経路のはず。※1 rep(i, N) cout << ans[i] + 1 << endl; // +1 // はグラフ作成時に0indexにしたやつをもとに戻すのと、根っこは0を出力なので、-1+1=0にするため。根は一つしかないから(至言) } // ※1 これに関しては、解説放送がわかりやすい。 // 端的に説明すると、距離差が2以上のとき、つまり頂点をジャンプして子孫につながるルートが正規ルートだと仮定すると、距離差1の経路は新たに頂点を生まないと生えてこないことになる。 // これは明らかにグラフ形成と有向辺の追加のルールに反しているので矛盾。
[ "expression.operation.binary.add" ]
941,899
941,900
u587857074
cpp
p03142
#include <bits/stdc++.h> #define mx 100005 using namespace std; vector<int> ch[mx]; stack<int> st; int n, m, a, b, rt, nm[mx], pa[mx]; int main() { scanf("%d%d", &n, &m); for (int i = 0; i < n + m - 1; i++) { scanf("%d%d", &a, &b); ch[a].push_back(b); nm[b]++; } for (rt = 1; !nm[rt]; rt++) ; st.push(rt); while (!st.empty()) { int i = st.top(); st.pop(); for (int it : ch[i]) { if (!--nm[it]) { pa[it] = i; st.push(it); } } } for (int i = 1; i <= n; i++) printf("%d\n", pa[i]); }
#include <bits/stdc++.h> #define mx 100005 using namespace std; vector<int> ch[mx]; stack<int> st; int n, m, a, b, rt, nm[mx], pa[mx]; int main() { scanf("%d%d", &n, &m); for (int i = 0; i < n + m - 1; i++) { scanf("%d%d", &a, &b); ch[a].push_back(b); nm[b]++; } for (rt = 1; nm[rt]; rt++) ; st.push(rt); while (!st.empty()) { int i = st.top(); st.pop(); for (int it : ch[i]) { if (!--nm[it]) { pa[it] = i; st.push(it); } } } for (int i = 1; i <= n; i++) printf("%d\n", pa[i]); }
[ "expression.operation.unary.logical.remove" ]
941,903
941,904
u309985845
cpp
p03142
#include <bits/stdc++.h> using namespace std; struct edge { int to, dir; }; struct graph { int n; vector<vector<int>> g; vector<bool> used; vector<int> ts; vector<int> pr; graph(int _n) { n = _n; g.resize(n); used.resize(n, false); pr.resize(n, -1); }; void add_edge(int a, int b) { g[a].push_back(b); } void traverse(int i) { if (used[i]) return; used[i] = true; for (auto &&w : g[i]) { traverse(w); } ts.push_back(i); } void tsort() { for (int i = 0; i < n; i++) { traverse(i); } reverse(begin(ts), end(ts)); } void set_pr() { tsort(); pr[ts[0]] = -1; for (int i = 0; i < n; i++) { for (auto &&w : g[ts[i]]) pr[w] = i; } } }; int main() { int n, m; cin >> n >> m; graph gr(n); for (int i = 0; i < n + m - 1; i++) { int x, y; cin >> x >> y; x--; y--; gr.add_edge(x, y); } gr.set_pr(); for (auto &&w : gr.pr) cout << w + 1 << endl; }
#include <bits/stdc++.h> using namespace std; struct edge { int to, dir; }; struct graph { int n; vector<vector<int>> g; vector<bool> used; vector<int> ts; vector<int> pr; graph(int _n) { n = _n; g.resize(n); used.resize(n, false); pr.resize(n, -1); }; void add_edge(int a, int b) { g[a].push_back(b); } void traverse(int i) { if (used[i]) return; used[i] = true; for (auto &&w : g[i]) { traverse(w); } ts.push_back(i); } void tsort() { for (int i = 0; i < n; i++) { traverse(i); } reverse(begin(ts), end(ts)); // for(auto&& w:ts)cerr<<w<<endl; } void set_pr() { tsort(); pr[ts[0]] = -1; for (int i = 0; i < n; i++) { for (auto &&w : g[ts[i]]) pr[w] = ts[i]; } } }; int main() { int n, m; cin >> n >> m; graph gr(n); for (int i = 0; i < n + m - 1; i++) { int x, y; cin >> x >> y; x--; y--; gr.add_edge(x, y); } gr.set_pr(); for (auto &&w : gr.pr) cout << w + 1 << endl; }
[]
941,909
941,910
u731175398
cpp
p03142
#include <algorithm> #include <bitset> #include <ciso646> #include <cmath> #include <complex> #include <cstdio> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef unsigned int ui; const ll mod = 1000000007; typedef long double ld; const ll INF = 1e+14; typedef pair<int, int> P; #define stop \ char nyaa; \ cin >> nyaa; #define rep(i, n) for (int i = 0; i < n; i++) #define per(i, n) for (int i = n - 1; i >= 0; i--) #define Rep(i, sta, n) for (int i = sta; i < n; i++) #define rep1(i, n) for (int i = 1; i <= n; i++) #define per1(i, n) for (int i = n; i >= 1; i--) #define Rep1(i, sta, n) for (int i = sta; i <= n; i++) typedef complex<ld> Point; const ld eps = 1e-8; const ld pi = acos(-1.0); typedef pair<ld, ld> LDP; typedef pair<ll, ll> LP; #define fr first #define sc second vector<int> G[100100], H[100100]; int N, M; bool used[100100] = {false}; vector<int> topo; void dfs(int s) { if (used[s] == true) return; used[s] = true; for (int i = 0; i < G[s].size(); i++) dfs(i); topo.push_back(s); } void tpsort() { rep1(i, N) dfs(i); reverse(topo.begin(), topo.end()); } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> N >> M; rep(i, N + M - 1) { int s, t; cin >> s >> t; G[s].push_back(t); H[t].push_back(s); } tpsort(); map<int, int> tp; rep(i, N) { tp[topo[i]] = i; } rep1(i, N) { int k = -1; for (int j : H[i]) { k = max(k, tp[j]); } if (k == -1) { cout << 0 << "\n"; continue; } else { cout << topo[k] << "\n"; } } return 0; }
#include <algorithm> #include <bitset> #include <ciso646> #include <cmath> #include <complex> #include <cstdio> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef unsigned int ui; const ll mod = 1000000007; typedef long double ld; const ll INF = 1e+14; typedef pair<int, int> P; #define stop \ char nyaa; \ cin >> nyaa; #define rep(i, n) for (int i = 0; i < n; i++) #define per(i, n) for (int i = n - 1; i >= 0; i--) #define Rep(i, sta, n) for (int i = sta; i < n; i++) #define rep1(i, n) for (int i = 1; i <= n; i++) #define per1(i, n) for (int i = n; i >= 1; i--) #define Rep1(i, sta, n) for (int i = sta; i <= n; i++) typedef complex<ld> Point; const ld eps = 1e-8; const ld pi = acos(-1.0); typedef pair<ld, ld> LDP; typedef pair<ll, ll> LP; #define fr first #define sc second vector<int> G[100100], H[100100]; int N, M; bool used[100100] = {false}; vector<int> topo; void dfs(int s) { if (used[s] == true) return; used[s] = true; for (int i = 0; i < G[s].size(); i++) dfs(G[s][i]); topo.push_back(s); } void tpsort() { rep1(i, N) dfs(i); reverse(topo.begin(), topo.end()); } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> N >> M; rep(i, N + M - 1) { int s, t; cin >> s >> t; G[s].push_back(t); H[t].push_back(s); } tpsort(); map<int, int> tp; rep(i, N) { tp[topo[i]] = i; } rep1(i, N) { int k = -1; for (int j : H[i]) { k = max(k, tp[j]); } if (k == -1) { cout << 0 << "\n"; continue; } else { cout << topo[k] << "\n"; } } return 0; }
[ "call.arguments.change" ]
941,911
941,912
u508571192
cpp
p03142
#include <bits/stdc++.h> using namespace std; const int MAXn = 1e5 + 10; int indeg[MAXn], par[MAXn], n, m; vector<int> g[MAXn], vec; void del(int v) { for (int i = 0; i < g[v].size(); i++) { indeg[g[v][i]]--; if (!indeg[g[v][i]]) { par[g[v][i]] = v; vec.push_back(g[v][i]); } } } int main() { cin >> n >> m; for (int i = 0; i < n - 1 + m; i++) { int v, u; cin >> v >> u; v--; u--; g[v].push_back(u); indeg[u]++; } for (int i = 0; i < n; i++) if (!indeg[i]) { vec.push_back(i); break; } for (int i = 0; i < vec.size(); i++) del(vec[i]); for (int i = 0; i < n; i++) cout << par[i] << '\n'; }
#include <bits/stdc++.h> using namespace std; const int MAXn = 1e5 + 10; int indeg[MAXn], par[MAXn], n, m; vector<int> g[MAXn], vec; void del(int v) { for (int i = 0; i < g[v].size(); i++) { indeg[g[v][i]]--; if (!indeg[g[v][i]]) { par[g[v][i]] = v + 1; vec.push_back(g[v][i]); } } } int main() { cin >> n >> m; for (int i = 0; i < n - 1 + m; i++) { int v, u; cin >> v >> u; v--; u--; g[v].push_back(u); indeg[u]++; } for (int i = 0; i < n; i++) if (!indeg[i]) { vec.push_back(i); break; } for (int i = 0; i < vec.size(); i++) del(vec[i]); for (int i = 0; i < n; i++) cout << par[i] << '\n'; }
[ "assignment.change" ]
941,913
941,914
u138661009
cpp
p03145
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vec; typedef vector<vec> mat; typedef pair<ll, ll> pll; const ll mod = 1e9 + 7; // const ll mod=998244353; const ll inf = 5e18; int main() { ll a, b, c; cin >> a >> b >> c; cout << a * b << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vec; typedef vector<vec> mat; typedef pair<ll, ll> pll; const ll mod = 1e9 + 7; // const ll mod=998244353; const ll inf = 5e18; int main() { ll a, b, c; cin >> a >> b >> c; cout << a * b / 2 << endl; }
[ "expression.operation.binary.add" ]
941,977
941,978
u718758485
cpp
p03145
#include <bits/stdc++.h> #include <type_traits> using namespace std; using ll = int64_t; #define int ll #define FOR(i, a, b) for (int i = int(a); i < int(b); i++) #define REP(i, b) FOR(i, 0, b) #define MP make_pair #define PB push_back #define EB emplace_back #define ALL(x) x.begin(), x.end() auto &errStream = cerr; #ifdef LOCAL #define cerr (cerr << "-- line " << __LINE__ << " -- ") #else class CerrDummy { } cerrDummy; template <class T> CerrDummy &operator<<(CerrDummy &cd, const T &) { return cd; } using charTDummy = char; using traitsDummy = char_traits<charTDummy>; CerrDummy &operator<<(CerrDummy &cd, basic_ostream<charTDummy, traitsDummy> &( basic_ostream<charTDummy, traitsDummy> &)) { return cd; } #define cerr cerrDummy #endif #define REACH cerr << "reached" << endl #define DMP(x) cerr << #x << ":" << x << endl #define ZERO(x) memset(x, 0, sizeof(x)) #define ONE(x) memset(x, -1, sizeof(x)) using pi = pair<int, int>; using vi = vector<int>; using ld = long double; template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << "(" << p.first << "," << p.second << ")"; return os; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "{"; REP(i, (int)v.size()) { if (i) os << ","; os << v[i]; } os << "}"; return os; } ll read() { ll i; scanf("%" SCNd64, &i); return i; } void printSpace() { printf(" "); } void printEoln() { printf("¥n"); } void print(ll x, int suc = 1) { printf("%" PRId64, x); if (suc == 1) printEoln(); if (suc == 2) printSpace(); } string readString() { static char buf[3341000]; scanf("%s", buf); return string(buf); } char *readCharArray() { static char buf[3341000]; static int bufUsed = 0; char *ret = buf + bufUsed; scanf("%s", ret); bufUsed += strlen(ret) + 1; return ret; } template <class T, class U> void chmax(T &a, U b) { if (a < b) a = b; } template <class T, class U> void chmin(T &a, U b) { if (b < a) a = b; } template <class T> T Sq(const T &t) { return t * t; } #define CAPITAL void Yes(bool ex = true) { #ifdef CAPITAL cout << "YES" << endl; #else cout << "Yes" << endl; #endif if (ex) exit(0); } void No(bool ex = true) { #ifdef CAPITAL cout << "NO" << endl; #else cout << "No" << endl; #endif if (ex) exit(0); } const ll infLL = LLONG_MAX / 3; #ifdef int const int inf = infLL; #else const int inf = INT_MAX / 2 - 100; #endif signed main() { int ab = read(), bc = read(), ca = read(), ans; ans = (ab * bc) / 2; print(ans); return 0; }
#include <bits/stdc++.h> #include <type_traits> using namespace std; using ll = int64_t; #define int ll #define FOR(i, a, b) for (int i = int(a); i < int(b); i++) #define REP(i, b) FOR(i, 0, b) #define MP make_pair #define PB push_back #define EB emplace_back #define ALL(x) x.begin(), x.end() auto &errStream = cerr; #ifdef LOCAL #define cerr (cerr << "-- line " << __LINE__ << " -- ") #else class CerrDummy { } cerrDummy; template <class T> CerrDummy &operator<<(CerrDummy &cd, const T &) { return cd; } using charTDummy = char; using traitsDummy = char_traits<charTDummy>; CerrDummy &operator<<(CerrDummy &cd, basic_ostream<charTDummy, traitsDummy> &( basic_ostream<charTDummy, traitsDummy> &)) { return cd; } #define cerr cerrDummy #endif #define REACH cerr << "reached" << endl #define DMP(x) cerr << #x << ":" << x << endl #define ZERO(x) memset(x, 0, sizeof(x)) #define ONE(x) memset(x, -1, sizeof(x)) using pi = pair<int, int>; using vi = vector<int>; using ld = long double; template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << "(" << p.first << "," << p.second << ")"; return os; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "{"; REP(i, (int)v.size()) { if (i) os << ","; os << v[i]; } os << "}"; return os; } ll read() { ll i; scanf("%" SCNd64, &i); return i; } void printSpace() { printf(" "); } void printEoln() { printf("¥n"); } void print(ll x, int suc = 1) { printf("%" PRId64, x); if (suc == 1) printEoln(); if (suc == 2) printSpace(); } string readString() { static char buf[3341000]; scanf("%s", buf); return string(buf); } char *readCharArray() { static char buf[3341000]; static int bufUsed = 0; char *ret = buf + bufUsed; scanf("%s", ret); bufUsed += strlen(ret) + 1; return ret; } template <class T, class U> void chmax(T &a, U b) { if (a < b) a = b; } template <class T, class U> void chmin(T &a, U b) { if (b < a) a = b; } template <class T> T Sq(const T &t) { return t * t; } #define CAPITAL void Yes(bool ex = true) { #ifdef CAPITAL cout << "YES" << endl; #else cout << "Yes" << endl; #endif if (ex) exit(0); } void No(bool ex = true) { #ifdef CAPITAL cout << "NO" << endl; #else cout << "No" << endl; #endif if (ex) exit(0); } const ll infLL = LLONG_MAX / 3; #ifdef int const int inf = infLL; #else const int inf = INT_MAX / 2 - 100; #endif signed main() { int ab = read(), bc = read(), ca = read(), ans; ans = (ab * bc) / 2; print(ans, 0); return 0; }
[ "call.arguments.add" ]
941,983
941,984
u700484101
cpp
p03145
#include <iostream> using namespace std; int main(void) { int a, b, c, ans; cin >> a >> b >> c; ans = (a * b) / 2; cout << ans << '¥n'; return 0; }
#include <iostream> using namespace std; int main(void) { int a, b, c, ans; cin >> a >> b >> c; ans = (a * b) / 2; cout << ans; return 0; }
[ "expression.operation.binary.remove" ]
941,985
941,986
u700484101
cpp
p03145
#include <algorithm> #include <cstdio> #include <iostream> #include <vector> using namespace std; int main(void) { int l, m, n; scanf("%d%d%d", &l, &m, &n); printf("%d\n", (l + m) / 2); return 0; }
#include <algorithm> #include <cstdio> #include <iostream> #include <vector> using namespace std; int main(void) { int l, m, n; scanf("%d%d%d", &l, &m, &n); printf("%d\n", (l * m) / 2); return 0; }
[ "expression.operator.arithmetic.change", "call.arguments.change", "expression.operation.binary.change", "io.output.change" ]
942,078
942,079
u684448032
cpp
p03145
#include <iostream> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; cout << a * c / 2 << endl; }
#include <iostream> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; cout << a * b / 2 << endl; }
[ "identifier.change", "io.output.change" ]
942,083
942,084
u299863190
cpp
p03145
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) using ll = long long; int main() { int a, b, c; cin >> b >> c; cout << a * b / 2 << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) using ll = long long; int main() { int a, b, c; cin >> a >> b >> c; cout << a * b / 2 << endl; }
[ "expression.operation.binary.add" ]
942,104
942,105
u796273093
cpp
p03145
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> c; cout << (a * b) / 2 << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; cout << (a * b) / 2 << endl; }
[ "expression.operation.binary.add" ]
942,110
942,111
u006937669
cpp
p03145
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> c; cout << a * b / 2 << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; cout << (a * b) / 2 << endl; }
[ "expression.operation.binary.add" ]
942,112
942,111
u006937669
cpp
p03145
#include "bits/stdc++.h" using namespace std; // GNU C Compiler // template<class T> inline string toString(T x) { ostringstream sout; sout << // x; return sout.str(); } // type using ll = int_fast64_t; using ull = uint_fast64_t; using LL = long long; using ULL = unsigned long long; using PII = pair<int, int>; // using pair<T1, T2> = p12; // container #define PB emplace_back #define MP make_pair #define SZ(a) int((a).size()) #define ALL(v) v.begin(), v.end() // repetition #define REP(n) for (ll i = 0; i < (n); i++) #define REPj(n) for (ll j = 0; j < (n); j++) #define REPinit(i, a, n) for (ll i = (a); i < (n); i++) #define REPinitj(j, a, n) for (ll j = (a); j < (n); j++) // algorithm #define SORT(c) sort((c).begin(), (c).end()) #define CONTAINER_ALL(a) a.begin(), a.end() // constant // clear memory #define CLR(a) memset((a), 0, sizeof(a)) // Optimizer // #pragma GCC optimize("Ofast") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int a, b, c; cin >> a >> b >> c; cout << (int)(a * b * 2) << endl; return 0; }
#include "bits/stdc++.h" using namespace std; // GNU C Compiler // template<class T> inline string toString(T x) { ostringstream sout; sout << // x; return sout.str(); } // type using ll = int_fast64_t; using ull = uint_fast64_t; using LL = long long; using ULL = unsigned long long; using PII = pair<int, int>; // using pair<T1, T2> = p12; // container #define PB emplace_back #define MP make_pair #define SZ(a) int((a).size()) #define ALL(v) v.begin(), v.end() // repetition #define REP(n) for (ll i = 0; i < (n); i++) #define REPj(n) for (ll j = 0; j < (n); j++) #define REPinit(i, a, n) for (ll i = (a); i < (n); i++) #define REPinitj(j, a, n) for (ll j = (a); j < (n); j++) // algorithm #define SORT(c) sort((c).begin(), (c).end()) #define CONTAINER_ALL(a) a.begin(), a.end() // constant // clear memory #define CLR(a) memset((a), 0, sizeof(a)) // Optimizer // #pragma GCC optimize("Ofast") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int a, b, c; cin >> a >> b >> c; cout << (int)(a * b / 2) << endl; return 0; }
[ "expression.operator.arithmetic.change", "io.output.change" ]
942,127
942,128
u585586208
cpp
p03145
#include <bits/stdc++.h> using namespace std; int main() { int A, B, C; cin >> A >> B >> C; cout << (A + B) / 2 << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int A, B, C; cin >> A >> B >> C; cout << (A * B) / 2 << endl; }
[ "expression.operator.arithmetic.change", "io.output.change" ]
942,131
942,132
u602711435
cpp
p03145
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5, M = 1e6 + 6, OO = 0x3f3f3f3f; int a, b, c; int main() { cin >> a >> b >> c; cout << (b + 1) / 2 * a << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5, M = 1e6 + 6, OO = 0x3f3f3f3f; int a, b, c; int main() { cin >> a >> b >> c; cout << (b * a) / 2 << endl; return 0; }
[ "expression.operation.binary.remove" ]
942,149
942,150
u411546337
cpp
p03145
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5, M = 1e6 + 6, OO = 0x3f3f3f3f; int a, b, c; int main() { cin >> a >> b >> c; cout << b / 2 * a << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5, M = 1e6 + 6, OO = 0x3f3f3f3f; int a, b, c; int main() { cin >> a >> b >> c; cout << (b * a) / 2 << endl; return 0; }
[ "expression.operation.binary.remove" ]
942,151
942,150
u411546337
cpp
p03145
#include <bits/stdc++.h> using namespace std; #define rep(i, s, n) for (int i = (s); i < (int)(n); i++) #define all(v) v.begin(), v.end() template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } using ll = long long; const ll MOD = 1e9 + 7; ll LLINF = 1LL << 60; int INF = INT_MAX; // int main() { int a, b, c; cin >> a >> b >> c; cout << (a + b) / 2 << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, s, n) for (int i = (s); i < (int)(n); i++) #define all(v) v.begin(), v.end() template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } using ll = long long; const ll MOD = 1e9 + 7; ll LLINF = 1LL << 60; int INF = INT_MAX; // int main() { int a, b, c; cin >> a >> b >> c; cout << (a * b) / 2 << endl; }
[ "expression.operator.arithmetic.change", "io.output.change" ]
942,170
942,171
u646962247
cpp
p03145
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (ll i = 0; i < (n); ++i) #define fin(ans) cout << (ans) << endl; #define blank(ans) cout << (ans) << " "; #define mp(p, q) make_pair(p, q) #define pb(n) push_back(n) #define all(a) a.begin(), a.end() typedef long long ll; typedef long long lli; typedef unsigned long long ull; typedef long double ld; typedef string str; typedef vector<char> vc; typedef vector<bool> vb; typedef vector<ld> vd; typedef vector<str> vs; typedef vector<ll> vll; typedef vector<pair<ll, ll>> vpll; typedef vector<pair<ll, str>> vpls; typedef vector<tuple<str, ll, ll>> vtsl; typedef vector<vector<ll>> vvll; typedef vector<vector<char>> vvc; typedef vector<vector<str>> vvs; const ld PI = acos(-1.0); const ll MAX = 9000000000000000000; const ll MIN = -9000000000000000000; const ld DMAX = 4500; const ld DMIN = -4500; const ll MOD = 1000000007; //実行部 void Main() { ll a, b, c; cin >> a >> b >> c; fin(a * b / 2.) } //前処理 int main() { // ios::sync_with_stdio(false); // cin.tie(0); cout << fixed << setprecision(20); //高精度少数表示 Main(); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (ll i = 0; i < (n); ++i) #define fin(ans) cout << (ans) << endl; #define blank(ans) cout << (ans) << " "; #define mp(p, q) make_pair(p, q) #define pb(n) push_back(n) #define all(a) a.begin(), a.end() typedef long long ll; typedef long long lli; typedef unsigned long long ull; typedef long double ld; typedef string str; typedef vector<char> vc; typedef vector<bool> vb; typedef vector<ld> vd; typedef vector<str> vs; typedef vector<ll> vll; typedef vector<pair<ll, ll>> vpll; typedef vector<pair<ll, str>> vpls; typedef vector<tuple<str, ll, ll>> vtsl; typedef vector<vector<ll>> vvll; typedef vector<vector<char>> vvc; typedef vector<vector<str>> vvs; const ld PI = acos(-1.0); const ll MAX = 9000000000000000000; const ll MIN = -9000000000000000000; const ld DMAX = 4500; const ld DMIN = -4500; const ll MOD = 1000000007; //実行部 void Main() { ll a, b, c; cin >> a >> b >> c; fin(a * b / 2) } //前処理 int main() { // ios::sync_with_stdio(false); // cin.tie(0); cout << fixed << setprecision(20); //高精度少数表示 Main(); return 0; }
[ "call.arguments.change" ]
942,211
942,212
u743889070
cpp
p03145
// include // ------------------------------------------------ #include <algorithm> #include <bits/stdc++.h> #include <math.h> #include <vector> using namespace std; // func // ------------------------------------------------ int CalcSumOfDigit(int n); // 各桁の和を計算する。 string upper(string str); // 英字を大文字に変換する。 string lower(string str); // 英字を小文字に変換する。 // define // ------------------------------------------------ #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define pb push_back #define sz(a) int((a).size()) #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) #define repe(i, n) for (int(i) = 0; (i) <= (n); (i)++) #define vsort(v) sort((v).begin(), (v).end()) #define rvsort(v) sort(rall((v))) #define vi vector<int> #define GCD(a, b) __gcd((a), (b)) #define LCM(a, b) (a) / GCD((a), (b)) * (b) const int INF = 1e9; // code // ------------------------------------------------ int main() { int a, b, c; cin >> a >> b >> c; cout << a / 2 * b; return 0; } // funcの実体 // ------------------------------------------------ int CalcSumOfDigit(int n) { int s = 0; while (n) { s += n % 10; n = n / 10; } return s; } string upper(string str) { for (auto itr = str.begin(); itr != str.end(); itr++) { if (97 <= *itr && *itr <= 122) { *itr = *itr - 32; } } return str; } string lower(string str) { for (auto itr = str.begin(); itr != str.end(); itr++) { if (65 <= *itr && *itr <= 90) { *itr = *itr + 32; } } return str; }
// include // ------------------------------------------------ #include <algorithm> #include <bits/stdc++.h> #include <math.h> #include <vector> using namespace std; // func // ------------------------------------------------ int CalcSumOfDigit(int n); // 各桁の和を計算する。 string upper(string str); // 英字を大文字に変換する。 string lower(string str); // 英字を小文字に変換する。 // define // ------------------------------------------------ #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define pb push_back #define sz(a) int((a).size()) #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) #define repe(i, n) for (int(i) = 0; (i) <= (n); (i)++) #define vsort(v) sort((v).begin(), (v).end()) #define rvsort(v) sort(rall((v))) #define vi vector<int> #define GCD(a, b) __gcd((a), (b)) #define LCM(a, b) (a) / GCD((a), (b)) * (b) const int INF = 1e9; // code // ------------------------------------------------ int main() { int a, b, c; cin >> a >> b >> c; cout << a * b / 2; return 0; } // funcの実体 // ------------------------------------------------ int CalcSumOfDigit(int n) { int s = 0; while (n) { s += n % 10; n = n / 10; } return s; } string upper(string str) { for (auto itr = str.begin(); itr != str.end(); itr++) { if (97 <= *itr && *itr <= 122) { *itr = *itr - 32; } } return str; } string lower(string str) { for (auto itr = str.begin(); itr != str.end(); itr++) { if (65 <= *itr && *itr <= 90) { *itr = *itr + 32; } } return str; }
[ "expression.operation.binary.remove" ]
942,247
942,248
u610897920
cpp
p03145
#include <iostream> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; cout << a * b / c << endl; return 0; }
#include <iostream> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; cout << a * b / 2 << endl; return 0; }
[ "identifier.replace.remove", "literal.replace.add", "io.output.change" ]
942,259
942,260
u955202970
cpp
p03145
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; int ans = a * b; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; int ans = a * b / 2; cout << ans << endl; }
[ "assignment.change" ]
942,285
942,286
u578871832
cpp
p03145
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; cout << a * (b / 2) << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; cout << (a * b) / 2 << endl; }
[]
942,310
942,311
u654240084
cpp
p03145
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < (n); i++) #define REP2(i, x, n) for (int i = x; i < (n); i++) int main() { int a, b, c; cin >> a >> b >> c; cout << a * b << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < (n); i++) #define REP2(i, x, n) for (int i = x; i < (n); i++) int main() { int a, b, c; cin >> a >> b >> c; cout << a * b / 2 << endl; return 0; }
[ "expression.operation.binary.add" ]
942,312
942,313
u685800831
cpp
p03145
#include <bits/stdc++.h> using namespace std; int main() { int AB, BC, CA; cin >> AB >> BC >> CA; cout << AB * BC << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int AB, BC, CA; cin >> AB >> BC >> CA; cout << AB * BC / 2 << endl; }
[ "expression.operation.binary.add" ]
942,375
942,376
u629548179
cpp
p03145
#pragma gcc optimize("Ofast") #include <bits/stdc++.h> using namespace std; using ll = long long; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(V) (V).begin(), (V).end() #define SORT(V) sort(ALL(V)) //小さい方からソート #define REV(V) reverse(ALL(V)) //リバース #define RSORT(V) \ SORT(V); \ REV(V) //大きい方からソート #define NPN(V) next_permutation(ALL(V)) //順列 #define pb(n) push_back(n) #define endl '\n' #define Endl '\n' #define DUMP(x) cout << #x << " = " << (x) << endl #define YES(n) cout << ((n) ? "YES" : "NO") << endl #define Yes(n) cout << ((n) ? "Yes" : "No") << endl #define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl #define RAPID \ cin.tie(0); \ ios::sync_with_stdio(false) #define IN(n) cin >> n #define IN2(a, b) cin >> a >> b #define IN3(a, b, c) cin >> a >> b >> c #define VIN(V) \ for (int i = 0; i < (V).size(); i++) { \ cin >> (V).at(i); \ } #define OUT(n) cout << n << endl #define VOUT(V) \ REP(i, (V).size()) { cout << (V)[i] << endl; } #define VOUT2(V) \ REP(i, (V).size()) { cout << (V)[i] << " "; } \ cout << endl; // 型マクロ定義 #define int long long #define P pair<ll, ll> #define Vi vector<ll> #define Vd vector<double> #define Vs vector<string> #define Vc vector<char> #define M map<ll, ll> #define S set<ll> #define PQ priority_queue<ll> #define PQG priority_queue < ll, V, greater<ll> // const int MOD = 1000000007; const int INF = 1061109567; const double EPS = 1e-10; const double PI = acos(-1.0); int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } //最小公倍数 // デフォルト変数定義 int n, m, a, b, c, x, y, z; double d, e, f; string s, t; // signed main() { RAPID; IN3(x, y, z); OUT(a * b / 2); }
#pragma gcc optimize("Ofast") #include <bits/stdc++.h> using namespace std; using ll = long long; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(V) (V).begin(), (V).end() #define SORT(V) sort(ALL(V)) //小さい方からソート #define REV(V) reverse(ALL(V)) //リバース #define RSORT(V) \ SORT(V); \ REV(V) //大きい方からソート #define NPN(V) next_permutation(ALL(V)) //順列 #define pb(n) push_back(n) #define endl '\n' #define Endl '\n' #define DUMP(x) cout << #x << " = " << (x) << endl #define YES(n) cout << ((n) ? "YES" : "NO") << endl #define Yes(n) cout << ((n) ? "Yes" : "No") << endl #define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl #define RAPID \ cin.tie(0); \ ios::sync_with_stdio(false) #define IN(n) cin >> n #define IN2(a, b) cin >> a >> b #define IN3(a, b, c) cin >> a >> b >> c #define VIN(V) \ for (int i = 0; i < (V).size(); i++) { \ cin >> (V).at(i); \ } #define OUT(n) cout << n << endl #define VOUT(V) \ REP(i, (V).size()) { cout << (V)[i] << endl; } #define VOUT2(V) \ REP(i, (V).size()) { cout << (V)[i] << " "; } \ cout << endl; // 型マクロ定義 #define int long long #define P pair<ll, ll> #define Vi vector<ll> #define Vd vector<double> #define Vs vector<string> #define Vc vector<char> #define M map<ll, ll> #define S set<ll> #define PQ priority_queue<ll> #define PQG priority_queue < ll, V, greater<ll> // const int MOD = 1000000007; const int INF = 1061109567; const double EPS = 1e-10; const double PI = acos(-1.0); int gcd(int a, int b) { return b ? gcd(b, a % b) : a; } //最小公倍数 // デフォルト変数定義 int n, m, a, b, c, x, y, z; double d, e, f; string s, t; // signed main() { RAPID; IN3(x, y, z); OUT(x * y / 2); }
[ "identifier.change", "call.arguments.change", "expression.operation.binary.change" ]
942,403
942,404
u154645927
cpp
p03145
#include <bits/stdc++.h> using namespace std; int main() { int ab, bc, ca; cin >> ab, bc, ca; cout << ab * bc / 2 << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int ab, bc, ca; cin >> ab >> bc >> ca; cout << ab * bc / 2 << endl; }
[]
942,433
942,434
u071019032
cpp
p03145
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; typedef long long ll; int main() { int a, b, c; cin >> a >> b >> c; int res; res = a * b / 2; printf("%lf", res); return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; typedef long long ll; int main() { int a, b, c; cin >> a >> b >> c; int res; res = a * b / 2; printf("%d", res); return 0; }
[ "literal.string.change", "call.arguments.change", "io.output.change" ]
942,444
942,445
u405620865
cpp
p03145
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; typedef long long ll; int main() { double a, b, c; cin >> a >> b >> c; double res; res = a * b / 2.0; printf("%lf", res); return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; typedef long long ll; int main() { int a, b, c; cin >> a >> b >> c; int res; res = a * b / 2; printf("%d", res); return 0; }
[ "variable_declaration.type.primitive.change", "literal.number.change", "assignment.value.change", "expression.operation.binary.change", "literal.string.change", "call.arguments.change", "io.output.change" ]
942,446
942,445
u405620865
cpp
p03145
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; typedef long long ll; int main() { double a, b, c; cin >> a >> b >> c; double res; res = a * b / 2; printf("%lf", res); return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; typedef long long ll; int main() { int a, b, c; cin >> a >> b >> c; int res; res = a * b / 2; printf("%d", res); return 0; }
[ "variable_declaration.type.primitive.change", "literal.string.change", "call.arguments.change", "io.output.change" ]
942,447
942,445
u405620865
cpp
p03145
#include <bits/stdc++.h> #define rep(i, m, n) for (int i = m; i < n; i++) #define co(n) cout << n << endl using namespace std; int main() { int a, b; cin >> a, b; co(a * b / 2); return 0; }
#include <bits/stdc++.h> #define rep(i, m, n) for (int i = m; i < n; i++) #define co(n) cout << n << endl using namespace std; int main() { int a, b; cin >> a >> b; co(a * b / 2); return 0; }
[]
942,492
942,493
u558115145
cpp
p03145
#include <iostream> using namespace std; int main(void) { int AB, BC; cin >> AB >> BC; cout << AB * BC << endl; return 0; }
#include <iostream> using namespace std; int main(void) { int AB, BC; cin >> AB >> BC; cout << AB * BC / 2 << endl; return 0; }
[ "expression.operation.binary.add" ]
942,494
942,495
u976833038
cpp
p03145
#include <iostream> #include <string> using namespace std; int main() { int x, y, z; cin >> x >> y >> z; cout << (x + y) / 2 << endl; }
#include <iostream> #include <string> using namespace std; int main() { int x, y, z; cin >> x >> y >> z; cout << (x * y) / 2 << endl; }
[ "expression.operator.arithmetic.change", "io.output.change" ]
942,526
942,527
u902803949
cpp
p03142
#include <algorithm> #include <cassert> #include <cctype> #include <cmath> #include <cstdarg> #include <cstdio> #include <cstdlib> #include <cstring> #include <fstream> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <sys/time.h> #include <vector> //#include "cout.h" using namespace std; #define SZ(x) ((int)x.size()) #define MSET(x, a) memset(x, a, (int)sizeof(x)) #define PB push_back #define VI vector<int> #define PII pair<int, int> #define LL long long #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, n) FOR(i, 0, n) #define ALL(v) (v).begin(), (v).end() #define FIT(it, v) \ for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++) #define OUT(A) cout << #A << " = " << (A) << endl #define OUT2(A, B) \ cout << "(" << #A << ", " << #B << ") = (" << (A) << ", " << (B) << ")" \ << endl template <class T> void chmin(T &t, T f) { if (t > f) t = f; } template <class T> void chmax(T &t, T f) { if (t < f) t = f; } #define present(c, e) ((c).find((e)) != (c).end()) #define cpresent(c, e) (find(ALL(c), (e)) != (c).end()) int n, m; int r; vector<int> e[100010]; vector<int> topo; // bool used[100010]; int in[100010]; int parent[100010]; void init() {} // void dfs(int i) { // if (used[i]) return; // used[i] = true; // REP(j, SZ(e[i])) dfs(e[i][j]); // topo.push_back(i); // } // // void makeTopo() { // topo.clear(); // REP(i, n) dfs(i); // reverse(ALL(topo)); // } void input() { REP(i, 100010) { e[i].clear(); parent[i] = -1; in[i] = 0; } cin >> n >> m; REP(i, n + m - 1) { int a, b; cin >> a >> b; a--; b--; e[a].push_back(b); in[b]++; } queue<int> q; REP(i, n) if (in[i] == 0) q.push(i); while (!q.empty()) { int i = q.front(); // topo.push_back(i); q.pop(); REP(j, SZ(e[i])) { in[e[i][j]]--; if (in[e[i][j]] == 0) { q.push(e[i][j]); parent[e[i][j]] = i; } } } // REP(i, n) { // REP(j, SZ(e[topo[i]])) { // parent[e[topo[i]][j]] = topo[i]; // } // } REP(i, n) printf("%d\n", parent[i]); } void solve() {} int main() { init(); input(); solve(); return 0; }
#include <algorithm> #include <cassert> #include <cctype> #include <cmath> #include <cstdarg> #include <cstdio> #include <cstdlib> #include <cstring> #include <fstream> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <sys/time.h> #include <vector> //#include "cout.h" using namespace std; #define SZ(x) ((int)x.size()) #define MSET(x, a) memset(x, a, (int)sizeof(x)) #define PB push_back #define VI vector<int> #define PII pair<int, int> #define LL long long #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, n) FOR(i, 0, n) #define ALL(v) (v).begin(), (v).end() #define FIT(it, v) \ for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++) #define OUT(A) cout << #A << " = " << (A) << endl #define OUT2(A, B) \ cout << "(" << #A << ", " << #B << ") = (" << (A) << ", " << (B) << ")" \ << endl template <class T> void chmin(T &t, T f) { if (t > f) t = f; } template <class T> void chmax(T &t, T f) { if (t < f) t = f; } #define present(c, e) ((c).find((e)) != (c).end()) #define cpresent(c, e) (find(ALL(c), (e)) != (c).end()) int n, m; int r; vector<int> e[100010]; vector<int> topo; // bool used[100010]; int in[100010]; int parent[100010]; void init() {} // void dfs(int i) { // if (used[i]) return; // used[i] = true; // REP(j, SZ(e[i])) dfs(e[i][j]); // topo.push_back(i); // } // // void makeTopo() { // topo.clear(); // REP(i, n) dfs(i); // reverse(ALL(topo)); // } void input() { REP(i, 100010) { e[i].clear(); parent[i] = -1; in[i] = 0; } cin >> n >> m; REP(i, n + m - 1) { int a, b; cin >> a >> b; a--; b--; e[a].push_back(b); in[b]++; } queue<int> q; REP(i, n) if (in[i] == 0) q.push(i); while (!q.empty()) { int i = q.front(); // topo.push_back(i); q.pop(); REP(j, SZ(e[i])) { in[e[i][j]]--; if (in[e[i][j]] == 0) { q.push(e[i][j]); parent[e[i][j]] = i; } } } // REP(i, n) { // REP(j, SZ(e[topo[i]])) { // parent[e[topo[i]][j]] = topo[i]; // } // } REP(i, n) printf("%d\n", parent[i] + 1); } void solve() {} int main() { init(); input(); solve(); return 0; }
[ "expression.operation.binary.add" ]
942,560
942,561
u307578234
cpp
p03142
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <cstdio> #include <functional> #include <iostream> #include <list> #include <map> #include <math.h> #include <numeric> #include <queue> #include <regex> #include <set> #include <stack> #include <string> #include <time.h> #include <type_traits> #include <typeinfo> #include <unordered_map> #include <vector> //#include "boost/variant.hpp" // #include "bits/stdc++.h" using namespace std; #define rep(i, N, M) for (ll i = N, i##_len = (M); i < i##_len; ++i) #define rep_skip(i, N, M, ...) \ for (ll i = N, i##_len = (M); i < i##_len; i += (skip)) #define rrep(i, N, M) for (ll i = (M)-1, i##_len = (N - 1); i > i##_len; --i) #define pb push_back typedef pair<double, double> pd; typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll> pll; typedef tuple<ll, ll, ll> tll; typedef tuple<ll, ll, ll, ll> tll4; typedef tuple<ll, ll, ll, ll, ll> tll5; typedef tuple<ll, ll, ll, ll, ll, ll> tll6; typedef vector<ll> vll; typedef vector<vll> vvll; typedef vector<pll> vpll; typedef vector<bool> vb; typedef vector<vb> vvb; typedef vector<string> vs; template <typename T> using pq_greater = priority_queue<T, vector<T>, greater<T>>; #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define vec(a) vector<a> #define perm(c) \ sort(all(c)); \ for (bool c##perm = 1; c##perm; c##perm = next_permutation(all(c))) template <typename T1, typename T2> void chmin(T1 &a, T2 b) { if (a > b) a = b; } template <typename T1, typename T2> void chmax(T1 &a, T2 b) { if (a < b) a = b; } constexpr ll POW_(ll n, ll m) { ll res = 1; rep(i, 0, m) { res *= n; } return res; } template <int mod = 0> constexpr ll POW(ll x, ll n) { if (x == 2) { return (1LL << n) % mod; } if (n == 0) return 1; if (n == 1) return x % mod; if (n % 2 == 0) return POW_(POW<mod>(x, n / 2), 2LL) % mod; return ((POW_(POW<mod>(x, n / 2, mod), 2LL) % mod) * (x % mod)) % mod; } template <> constexpr ll POW<0>(ll x, ll n) { if (x == 2) { return 1LL << n; } if (n == 0) return 1; if (n == 1) return x; if (n % 2 == 0) return POW_(POW(x, n / 2), 2); return (POW_(POW(x, n / 2), 2)) * x; } template <ll bit> ll at_bit(ll n, ll i) { return n / POW(bit, i) % bit; } template <> ll at_bit<2>(ll n, ll i) { return (n >> i) % 2LL; } template <ll bit> ll get_bit(ll i) { return POW(bit, i); } template <> ll get_bit<2>(ll i) { return 1LL << i; } template <ll bit> ll get_max_bit(ll n) { ll tmp = bit; ll at = 0; while (tmp <= n) { at++; tmp *= bit; } return at; } template <> ll get_max_bit<2>(ll n) { ll tmp = 2; ll at = 0; while (tmp <= n) { at++; tmp <<= 1; } return at; } vll getDivisors(ll n) { vll res; ll i = 1; for (; i * i < n; i++) { if (n % i == 0) { res.push_back(i); res.push_back(n / i); } } if (i * i == n) res.push_back(i); sort(res.begin(), res.end()); return res; } vll getDivisors(ll n, ll m) { if (n > m) swap(n, m); vll res; ll i = 1; for (; i * i < n; i++) { if (n % i == 0) { if (m % i == 0) res.push_back(i); if (m % (n / i) == 0) res.push_back(n / i); } } if (i * i == n) if (m % i == 0) res.push_back(i); sort(res.begin(), res.end()); return res; } ll gcd(ll a, ll b) { if (a % b == 0) return b; else return gcd(b, a % b); } template <typename Inputs, typename Functor, typename T = typename Inputs::value_type> void sort_by(Inputs &inputs, Functor f) { std::sort(std::begin(inputs), std::end(inputs), [&f](const T &lhs, const T &rhs) { return f(lhs) < f(rhs); }); } template <typename Inputs, typename Functor, typename T = typename Inputs::value_type> void stable_sort_by(Inputs &inputs, Functor f) { std::stable_sort( std::begin(inputs), std::end(inputs), [&f](const T &lhs, const T &rhs) { return f(lhs) < f(rhs); }); } // Functor is expected to be functional<val ,bool> // This function returns the maximum iterator that stisfies f(*it) == f(* // inputs.begin()) template <typename Inputs, typename Functor, typename ValType = typename Inputs::value_type> pair<typename Inputs::iterator, typename Inputs::iterator> binary_solve(Inputs &inputs, Functor f) { auto left = inputs.begin(); auto right = inputs.end(); auto n = inputs.size(); auto left_val = f(*left); auto right_val = f(*(right - 1)); // check assert(n >= 2); assert(left_val != right_val); while (left + 1 != right) { auto mid = left + (right - left) / 2; if (f(*mid) == left_val) { left = mid; } else { right = mid; } } return {left, right}; } template <int I> vll proj(vpll v) { vll res(v.size()); rep(i, 0, v.size()) { if (!I) res[i] = v[i].first; else res[i] = v[i].second; } return res; } template <int I, class T> vll proj(T v) { vll res(v.size()); rep(i, 0, v.size()) { res[i] = get<I>(v[i]); } return res; } vector<pll> prime_factorize(ll n) { vector<pll> res; for (ll p = 2; p * p <= n; ++p) { if (n % p != 0) continue; ll num = 0; while (n % p == 0) { ++num; n /= p; } res.push_back({p, num}); } if (n != 1) res.push_back(make_pair(n, 1)); return res; } ll MOD = 1000000007; ll INF = 1LL << 60; ll n; template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T>>; template <typename Monoid> struct segment_tree { using underlying_type = typename Monoid::underlying_type; segment_tree(ll a_n) : size_original(a_n) { vector<underlying_type> initial_value = vector<underlying_type>(a_n, Monoid::unit()); segment_tree_impl(a_n, initial_value); } segment_tree(ll a_n, vector<underlying_type> &initial_value) : size_original(a_n) { segment_tree_impl(a_n, initial_value); } void update(int i, underlying_type z) { // 0-based assert(0 <= i && i < 2 * n - 1); a[i + n - 1] = z; for (i = (i + n) / 2; i > 0; i /= 2) { // 1-based a[i - 1] = Monoid::append(a[2 * i - 1], a[2 * i]); } } underlying_type query(ll l, ll r) { // 0-based, [l, r) underlying_type lacc = Monoid::unit(), racc = Monoid::unit(); assert(l <= r && r <= n); l += n; r += n; for (; l < r; l /= 2, r /= 2) { // 1-based loop, 2x faster than recursion if (l % 2 == 1) lacc = Monoid::append(lacc, a[(l++) - 1]); if (r % 2 == 1) racc = Monoid::append(a[(--r) - 1], racc); } return Monoid::append(lacc, racc); } ll size() { return size_original; } private: ll size_original; ll n; vector<underlying_type> a; void segment_tree_impl(ll a_n, vector<underlying_type> &initial_value) { assert(a_n == initial_value.size()); n = 1; while (n < a_n) n *= 2; a.resize(2 * n - 1, Monoid::unit()); rep(i, 0, initial_value.size()) { a[i + (n - 1)] = initial_value[i]; } rrep(i, 0, n - 1) a[i] = Monoid::append(a[2 * i + 1], a[2 * i + 2]); // propagate initial values } }; template <typename T> struct min_indexed_t { typedef pair<T, ll> underlying_type; static underlying_type make_indexed(vector<T> v) { underlying_type w(v.size()); rep(i, 0, v.size()) { w[i] = {v[i], i}; } return w; } static underlying_type unit() { return make_pair(numeric_limits<T>::max(), -1); } static underlying_type append(underlying_type a, underlying_type b) { return min(a, b); } }; template <typename T> struct min_t { typedef T underlying_type; static underlying_type unit() { return numeric_limits<T>::max(); } static underlying_type append(underlying_type a, underlying_type b) { return min(a, b); } }; struct linear_t { typedef pd underlying_type; static underlying_type unit() { return underlying_type{1., 0.}; } static underlying_type append(underlying_type a, underlying_type b) { return underlying_type{a.first * b.first, b.first * a.second + b.second}; } }; vll get_topologically_sorted_nodes(const vvll &graph) { // graph needs to be represented by adjacent list. ll nodeSize = graph.size(); // find root vll roots; vll inDegree(nodeSize); rep(i, 0, nodeSize) { for (ll sibling : graph[i]) { inDegree[sibling]++; } } rep(i, 0, nodeSize) { if (inDegree[i] == 0) { roots.push_back(i); } } stack<ll> parents; for (ll i : roots) parents.push(i); vll sortedNodes; while (!parents.empty()) { ll parent = parents.top(); parents.pop(); sortedNodes.push_back(parent); for (ll sibling : graph[parent]) { inDegree[sibling]--; if (inDegree[sibling] == 0) { parents.push(sibling); } } } return sortedNodes; } int main() { ll N, M; cin >> N >> M; ll edgeNum = N - 1 + M; vvll adjList(N); vll inDegree(N); vll A(edgeNum), B(edgeNum); rep(i, 0, edgeNum) { cin >> A[i] >> B[i]; adjList[--A[i]].push_back(--B[i]); inDegree[B[i]]++; } auto sorted = get_topologically_sorted_nodes(adjList); vll res(N); res[sorted[0]] = 0; rep(i, 0, N) { ll ind = sorted[i]; for (ll sib : adjList[ind]) { res[sib] = ind + 1; } } rep(i, 0, N - 1) { cout << res[i] << endl; } return 0; }
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <cstdio> #include <functional> #include <iostream> #include <list> #include <map> #include <math.h> #include <numeric> #include <queue> #include <regex> #include <set> #include <stack> #include <string> #include <time.h> #include <type_traits> #include <typeinfo> #include <unordered_map> #include <vector> //#include "boost/variant.hpp" // #include "bits/stdc++.h" using namespace std; #define rep(i, N, M) for (ll i = N, i##_len = (M); i < i##_len; ++i) #define rep_skip(i, N, M, ...) \ for (ll i = N, i##_len = (M); i < i##_len; i += (skip)) #define rrep(i, N, M) for (ll i = (M)-1, i##_len = (N - 1); i > i##_len; --i) #define pb push_back typedef pair<double, double> pd; typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll> pll; typedef tuple<ll, ll, ll> tll; typedef tuple<ll, ll, ll, ll> tll4; typedef tuple<ll, ll, ll, ll, ll> tll5; typedef tuple<ll, ll, ll, ll, ll, ll> tll6; typedef vector<ll> vll; typedef vector<vll> vvll; typedef vector<pll> vpll; typedef vector<bool> vb; typedef vector<vb> vvb; typedef vector<string> vs; template <typename T> using pq_greater = priority_queue<T, vector<T>, greater<T>>; #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() #define vec(a) vector<a> #define perm(c) \ sort(all(c)); \ for (bool c##perm = 1; c##perm; c##perm = next_permutation(all(c))) template <typename T1, typename T2> void chmin(T1 &a, T2 b) { if (a > b) a = b; } template <typename T1, typename T2> void chmax(T1 &a, T2 b) { if (a < b) a = b; } constexpr ll POW_(ll n, ll m) { ll res = 1; rep(i, 0, m) { res *= n; } return res; } template <int mod = 0> constexpr ll POW(ll x, ll n) { if (x == 2) { return (1LL << n) % mod; } if (n == 0) return 1; if (n == 1) return x % mod; if (n % 2 == 0) return POW_(POW<mod>(x, n / 2), 2LL) % mod; return ((POW_(POW<mod>(x, n / 2, mod), 2LL) % mod) * (x % mod)) % mod; } template <> constexpr ll POW<0>(ll x, ll n) { if (x == 2) { return 1LL << n; } if (n == 0) return 1; if (n == 1) return x; if (n % 2 == 0) return POW_(POW(x, n / 2), 2); return (POW_(POW(x, n / 2), 2)) * x; } template <ll bit> ll at_bit(ll n, ll i) { return n / POW(bit, i) % bit; } template <> ll at_bit<2>(ll n, ll i) { return (n >> i) % 2LL; } template <ll bit> ll get_bit(ll i) { return POW(bit, i); } template <> ll get_bit<2>(ll i) { return 1LL << i; } template <ll bit> ll get_max_bit(ll n) { ll tmp = bit; ll at = 0; while (tmp <= n) { at++; tmp *= bit; } return at; } template <> ll get_max_bit<2>(ll n) { ll tmp = 2; ll at = 0; while (tmp <= n) { at++; tmp <<= 1; } return at; } vll getDivisors(ll n) { vll res; ll i = 1; for (; i * i < n; i++) { if (n % i == 0) { res.push_back(i); res.push_back(n / i); } } if (i * i == n) res.push_back(i); sort(res.begin(), res.end()); return res; } vll getDivisors(ll n, ll m) { if (n > m) swap(n, m); vll res; ll i = 1; for (; i * i < n; i++) { if (n % i == 0) { if (m % i == 0) res.push_back(i); if (m % (n / i) == 0) res.push_back(n / i); } } if (i * i == n) if (m % i == 0) res.push_back(i); sort(res.begin(), res.end()); return res; } ll gcd(ll a, ll b) { if (a % b == 0) return b; else return gcd(b, a % b); } template <typename Inputs, typename Functor, typename T = typename Inputs::value_type> void sort_by(Inputs &inputs, Functor f) { std::sort(std::begin(inputs), std::end(inputs), [&f](const T &lhs, const T &rhs) { return f(lhs) < f(rhs); }); } template <typename Inputs, typename Functor, typename T = typename Inputs::value_type> void stable_sort_by(Inputs &inputs, Functor f) { std::stable_sort( std::begin(inputs), std::end(inputs), [&f](const T &lhs, const T &rhs) { return f(lhs) < f(rhs); }); } // Functor is expected to be functional<val ,bool> // This function returns the maximum iterator that stisfies f(*it) == f(* // inputs.begin()) template <typename Inputs, typename Functor, typename ValType = typename Inputs::value_type> pair<typename Inputs::iterator, typename Inputs::iterator> binary_solve(Inputs &inputs, Functor f) { auto left = inputs.begin(); auto right = inputs.end(); auto n = inputs.size(); auto left_val = f(*left); auto right_val = f(*(right - 1)); // check assert(n >= 2); assert(left_val != right_val); while (left + 1 != right) { auto mid = left + (right - left) / 2; if (f(*mid) == left_val) { left = mid; } else { right = mid; } } return {left, right}; } template <int I> vll proj(vpll v) { vll res(v.size()); rep(i, 0, v.size()) { if (!I) res[i] = v[i].first; else res[i] = v[i].second; } return res; } template <int I, class T> vll proj(T v) { vll res(v.size()); rep(i, 0, v.size()) { res[i] = get<I>(v[i]); } return res; } vector<pll> prime_factorize(ll n) { vector<pll> res; for (ll p = 2; p * p <= n; ++p) { if (n % p != 0) continue; ll num = 0; while (n % p == 0) { ++num; n /= p; } res.push_back({p, num}); } if (n != 1) res.push_back(make_pair(n, 1)); return res; } ll MOD = 1000000007; ll INF = 1LL << 60; ll n; template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T>>; template <typename Monoid> struct segment_tree { using underlying_type = typename Monoid::underlying_type; segment_tree(ll a_n) : size_original(a_n) { vector<underlying_type> initial_value = vector<underlying_type>(a_n, Monoid::unit()); segment_tree_impl(a_n, initial_value); } segment_tree(ll a_n, vector<underlying_type> &initial_value) : size_original(a_n) { segment_tree_impl(a_n, initial_value); } void update(int i, underlying_type z) { // 0-based assert(0 <= i && i < 2 * n - 1); a[i + n - 1] = z; for (i = (i + n) / 2; i > 0; i /= 2) { // 1-based a[i - 1] = Monoid::append(a[2 * i - 1], a[2 * i]); } } underlying_type query(ll l, ll r) { // 0-based, [l, r) underlying_type lacc = Monoid::unit(), racc = Monoid::unit(); assert(l <= r && r <= n); l += n; r += n; for (; l < r; l /= 2, r /= 2) { // 1-based loop, 2x faster than recursion if (l % 2 == 1) lacc = Monoid::append(lacc, a[(l++) - 1]); if (r % 2 == 1) racc = Monoid::append(a[(--r) - 1], racc); } return Monoid::append(lacc, racc); } ll size() { return size_original; } private: ll size_original; ll n; vector<underlying_type> a; void segment_tree_impl(ll a_n, vector<underlying_type> &initial_value) { assert(a_n == initial_value.size()); n = 1; while (n < a_n) n *= 2; a.resize(2 * n - 1, Monoid::unit()); rep(i, 0, initial_value.size()) { a[i + (n - 1)] = initial_value[i]; } rrep(i, 0, n - 1) a[i] = Monoid::append(a[2 * i + 1], a[2 * i + 2]); // propagate initial values } }; template <typename T> struct min_indexed_t { typedef pair<T, ll> underlying_type; static underlying_type make_indexed(vector<T> v) { underlying_type w(v.size()); rep(i, 0, v.size()) { w[i] = {v[i], i}; } return w; } static underlying_type unit() { return make_pair(numeric_limits<T>::max(), -1); } static underlying_type append(underlying_type a, underlying_type b) { return min(a, b); } }; template <typename T> struct min_t { typedef T underlying_type; static underlying_type unit() { return numeric_limits<T>::max(); } static underlying_type append(underlying_type a, underlying_type b) { return min(a, b); } }; struct linear_t { typedef pd underlying_type; static underlying_type unit() { return underlying_type{1., 0.}; } static underlying_type append(underlying_type a, underlying_type b) { return underlying_type{a.first * b.first, b.first * a.second + b.second}; } }; vll get_topologically_sorted_nodes(const vvll &graph) { // graph needs to be represented by adjacent list. ll nodeSize = graph.size(); // find root vll roots; vll inDegree(nodeSize); rep(i, 0, nodeSize) { for (ll sibling : graph[i]) { inDegree[sibling]++; } } rep(i, 0, nodeSize) { if (inDegree[i] == 0) { roots.push_back(i); } } stack<ll> parents; for (ll i : roots) parents.push(i); vll sortedNodes; while (!parents.empty()) { ll parent = parents.top(); parents.pop(); sortedNodes.push_back(parent); for (ll sibling : graph[parent]) { inDegree[sibling]--; if (inDegree[sibling] == 0) { parents.push(sibling); } } } return sortedNodes; } int main() { ll N, M; cin >> N >> M; ll edgeNum = N - 1 + M; vvll adjList(N); vll inDegree(N); vll A(edgeNum), B(edgeNum); rep(i, 0, edgeNum) { cin >> A[i] >> B[i]; adjList[--A[i]].push_back(--B[i]); inDegree[B[i]]++; } auto sorted = get_topologically_sorted_nodes(adjList); vll res(N); res[sorted[0]] = 0; rep(i, 0, N) { ll ind = sorted[i]; for (ll sib : adjList[ind]) { res[sib] = ind + 1; } } rep(i, 0, N) { cout << res[i] << endl; } return 0; }
[ "expression.operation.binary.remove" ]
942,562
942,563
u304121198
cpp
p03142
#include <algorithm> #include <iostream> #include <map> #include <queue> #include <string> #include <vector> using namespace std; vector<int> degrees; vector<int> fa; map<int, vector<int>> mp; int main() { int n, m; cin >> n >> m; degrees.resize(n, 0); fa.resize(n, 0); for (int i = 0; i < n + m - 1; i++) { int x, y; cin >> x >> y; mp[x].push_back(y); degrees[y]++; } queue<int> q; for (int i = 1; i <= n; i++) { if (degrees[i] == 0) { q.push(i); break; } } while (q.size()) { int top = q.front(); q.pop(); vector<int> &t = mp[top]; for (int k : t) { degrees[k]--; if (degrees[k] == 0) { fa[k] = top; q.push(k); } } } for (int i = 1; i <= n; i++) { cout << fa[i] << endl; } return 0; }
#include <algorithm> #include <iostream> #include <map> #include <queue> #include <string> #include <vector> using namespace std; vector<int> degrees; vector<int> fa; map<int, vector<int>> mp; int main() { int n, m; cin >> n >> m; degrees.resize(n + 1, 0); fa.resize(n + 1, 0); for (int i = 0; i < n + m - 1; i++) { int x, y; cin >> x >> y; mp[x].push_back(y); degrees[y]++; } queue<int> q; for (int i = 1; i <= n; i++) { if (degrees[i] == 0) { q.push(i); break; } } while (q.size()) { int top = q.front(); q.pop(); vector<int> &t = mp[top]; for (int k : t) { degrees[k]--; if (degrees[k] == 0) { fa[k] = top; q.push(k); } } } for (int i = 1; i <= n; i++) { cout << fa[i] << endl; } return 0; }
[ "expression.operation.binary.add" ]
942,568
942,569
u656732735
cpp
p03142
#include <algorithm> #include <iostream> #include <map> #include <queue> #include <string> #include <vector> using namespace std; vector<int> degrees; vector<int> fa; map<int, vector<int>> mp; int main() { int n, m; cin >> n >> m; degrees.resize(n, 0); fa.resize(n, -1); for (int i = 0; i < n + m - 1; i++) { int x, y; cin >> x >> y; mp[x].push_back(y); degrees[y]++; } queue<int> q; for (int i = 1; i <= n; i++) { if (degrees[i] == 0) { q.push(i); break; } } while (q.size()) { int top = q.front(); q.pop(); vector<int> &t = mp[top]; for (int k : t) { degrees[k]--; if (degrees[k] == 0) { fa[k] = top; q.push(k); } } } for (int i = 1; i <= n; i++) { cout << fa[i] << endl; } return 0; }
#include <algorithm> #include <iostream> #include <map> #include <queue> #include <string> #include <vector> using namespace std; vector<int> degrees; vector<int> fa; map<int, vector<int>> mp; int main() { int n, m; cin >> n >> m; degrees.resize(n + 1, 0); fa.resize(n + 1, 0); for (int i = 0; i < n + m - 1; i++) { int x, y; cin >> x >> y; mp[x].push_back(y); degrees[y]++; } queue<int> q; for (int i = 1; i <= n; i++) { if (degrees[i] == 0) { q.push(i); break; } } while (q.size()) { int top = q.front(); q.pop(); vector<int> &t = mp[top]; for (int k : t) { degrees[k]--; if (degrees[k] == 0) { fa[k] = top; q.push(k); } } } for (int i = 1; i <= n; i++) { cout << fa[i] << endl; } return 0; }
[ "call.arguments.change", "expression.operation.unary.arithmetic.remove", "call.arguments.add" ]
942,570
942,569
u656732735
cpp
p03142
/*********************** * Author: xuziyuan * ***********************/ #include <bits/stdc++.h> #define rt0 return 0 #define rep(i, n) for (int i = 0; i < n; i++) #define repn(i, n) for (int i = 1; i <= n; i++) #define replet(c) for (char c = 'a'; c <= 'z'; c++) #define LL long long #define pii pair<int, int> #define pb push_back #define fi first #define se second #define mpr make_pair #define sqr(a) ((a) * (a)) using namespace std; const LL MOD = 1e9 + 7; int n, m, x, y, in[100010], dist[100010], ans[100010]; vector<int> g[100010]; int dfs_init(int pos) { // cout<<pos<<endl; if (dist[pos] != -1) return 0; //作为vis数组 rep(i, g[pos].size()) dist[pos] = max(dist[pos], dfs_init(g[pos][i]) + 1); if (dist[pos] == -1) dist[pos] = 0; return dist[pos]; } bool cmp(pii a, pii b) { return a.fi > b.fi; } void dfs(int pos, int lst) { if (ans[pos] != -1) return; ans[pos] = lst; vector<pii> v; rep(i, g[pos].size()) v.pb({dist[g[pos][i]], g[pos][i]}); sort(v.begin(), v.end(), cmp); rep(i, v.size()) dfs(v[i].se, pos); } int main() { memset(dist, -1, sizeof(dist)); memset(ans, -1, sizeof(ans)); cin >> n >> m; rep(i, n + m - 1) { scanf("%d%d", &x, &y); g[x].pb(y); in[y]++; } repn(i, n) { if (in[i] == 0) { dfs_init(i); dfs(i, 0); repn(j, n) cout << ans[j] << endl; rt0; } } rt0; }
/*********************** * Author: xuziyuan * ***********************/ #include <bits/stdc++.h> #define rt0 return 0 #define rep(i, n) for (int i = 0; i < n; i++) #define repn(i, n) for (int i = 1; i <= n; i++) #define replet(c) for (char c = 'a'; c <= 'z'; c++) #define LL long long #define pii pair<int, int> #define pb push_back #define fi first #define se second #define mpr make_pair #define sqr(a) ((a) * (a)) using namespace std; const LL MOD = 1e9 + 7; int n, m, x, y, in[100010], dist[100010], ans[100010]; vector<int> g[100010]; int dfs_init(int pos) { // cout<<pos<<endl; if (dist[pos] != -1) return dist[pos]; //作为vis数组 rep(i, g[pos].size()) dist[pos] = max(dist[pos], dfs_init(g[pos][i]) + 1); if (dist[pos] == -1) dist[pos] = 0; return dist[pos]; } bool cmp(pii a, pii b) { return a.fi > b.fi; } void dfs(int pos, int lst) { if (ans[pos] != -1) return; ans[pos] = lst; vector<pii> v; rep(i, g[pos].size()) v.pb({dist[g[pos][i]], g[pos][i]}); sort(v.begin(), v.end(), cmp); rep(i, v.size()) dfs(v[i].se, pos); } int main() { memset(dist, -1, sizeof(dist)); memset(ans, -1, sizeof(ans)); cin >> n >> m; rep(i, n + m - 1) { scanf("%d%d", &x, &y); g[x].pb(y); in[y]++; } repn(i, n) { if (in[i] == 0) { dfs_init(i); dfs(i, 0); repn(j, n) cout << ans[j] << endl; rt0; } } rt0; }
[ "identifier.replace.add", "literal.replace.remove", "function.return_value.change" ]
942,571
942,572
u977365687
cpp
p03142
#include <bits/stdc++.h> using namespace std; int deep[100010], par[100010]; vector<int> v[100010]; int a, b, in[100010], n, m; int dfs(int x) { if (deep[x] != -1) return deep[x]; deep[x] = 0; for (int i = 0; i < v[x].size(); ++i) deep[x] = max(deep[x], deep[v[x][i]] + 1); return deep[x]; } void dfs2(int x, int p) { if (par[x] != -1) return; else par[x] = p; vector<pair<int, int>> c; for (int i = 0; i < v[x].size(); ++i) { c.push_back({deep[v[x][i]], v[x][i]}); } sort(c.begin(), c.end()); reverse(c.begin(), c.end()); for (int i = 0; i < c.size(); ++i) dfs2(c[i].second, x); } int main() { memset(deep, -1, sizeof deep); memset(par, -1, sizeof par); cin >> n >> m; for (int i = 1; i <= n - 1 + m; ++i) { scanf("%d%d", &a, &b); v[a].push_back(b); in[b]++; } int pp; for (int i = 1; i <= n; ++i) if (!in[i]) { pp = i; } dfs(pp); dfs2(pp, 0); for (int i = 1; i <= n; ++i) cout << par[i] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int deep[100010], par[100010]; vector<int> v[100010]; int a, b, in[100010], n, m; int dfs(int x) { if (deep[x] != -1) return deep[x]; deep[x] = 0; for (int i = 0; i < v[x].size(); ++i) deep[x] = max(deep[x], dfs(v[x][i]) + 1); return deep[x]; } void dfs2(int x, int p) { if (par[x] != -1) return; else par[x] = p; vector<pair<int, int>> c; for (int i = 0; i < v[x].size(); ++i) { c.push_back({deep[v[x][i]], v[x][i]}); } sort(c.begin(), c.end()); reverse(c.begin(), c.end()); for (int i = 0; i < c.size(); ++i) dfs2(c[i].second, x); } int main() { memset(deep, -1, sizeof deep); memset(par, -1, sizeof par); cin >> n >> m; for (int i = 1; i <= n - 1 + m; ++i) { scanf("%d%d", &a, &b); v[a].push_back(b); in[b]++; } int pp; for (int i = 1; i <= n; ++i) if (!in[i]) { pp = i; } dfs(pp); dfs2(pp, 0); for (int i = 1; i <= n; ++i) cout << par[i] << endl; return 0; }
[ "assignment.value.change", "call.arguments.change", "expression.operation.binary.change" ]
942,573
942,574
u989325410
cpp
p03142
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; #define INF (1 << (4 * 4 - 1)) #define MOD 1000000007 #define rng(a) a.begin(), a.end() #define rrng(a) a.rbegin(), a.rend() int main() { ios::sync_with_stdio(false); cin.tie(0); int N, M; cin >> N >> M; vector<vector<int>> E(N + 1); vector<vector<int>> EE(N + 1); vector<int> in(N + 1, 0), out(N + 1, 0); for (int i = 0; i < N - 1 + M; i++) { int A, B; cin >> A >> B; E[A].push_back(B); EE[B].push_back(A); out[A]++; in[B]++; } queue<int> S; for (int i = 1; i <= N; i++) if (in[i] == 0) S.push(i); vector<int> dag; while (S.size()) { int now = S.front(); S.pop(); dag.push_back(now); for (int i = 0; i < E[now].size(); i++) { int out = E[now][i]; --in[out]; if (in[out] == 0) { S.push(out); } } } vector<int> DAG(N + 1); for (int i = 0; i < N; i++) { DAG[dag[i]] = i; } vector<int> ans(N + 1, 1); ans[dag[0]] = 0; for (int i = 1; i < N; i++) { int Max = -1; for (int j = 0; j < EE[i].size(); j++) { Max = max(DAG[EE[i][j]], Max); } ans[dag[i]] = dag[Max]; } for (int i = 1; i <= N; i++) cout << ans[i] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; #define INF (1 << (4 * 4 - 1)) #define MOD 1000000007 #define rng(a) a.begin(), a.end() #define rrng(a) a.rbegin(), a.rend() int main() { ios::sync_with_stdio(false); cin.tie(0); int N, M; cin >> N >> M; vector<vector<int>> E(N + 1); vector<vector<int>> EE(N + 1); vector<int> in(N + 1, 0), out(N + 1, 0); for (int i = 0; i < N - 1 + M; i++) { int A, B; cin >> A >> B; E[A].push_back(B); EE[B].push_back(A); out[A]++; in[B]++; } queue<int> S; for (int i = 1; i <= N; i++) if (in[i] == 0) S.push(i); vector<int> dag; while (S.size()) { int now = S.front(); S.pop(); dag.push_back(now); for (int i = 0; i < E[now].size(); i++) { int out = E[now][i]; --in[out]; if (in[out] == 0) { S.push(out); } } } vector<int> DAG(N + 1); for (int i = 0; i < N; i++) { DAG[dag[i]] = i; } vector<int> ans(N + 1, 1); ans[dag[0]] = 0; for (int i = 1; i < N; i++) { int Max = -1; for (int j = 0; j < EE[dag[i]].size(); j++) { Max = max(DAG[EE[dag[i]][j]], Max); } ans[dag[i]] = dag[Max]; } for (int i = 1; i <= N; i++) cout << ans[i] << endl; return 0; }
[ "control_flow.loop.for.condition.change", "call.arguments.change" ]
942,585
942,586
u864171425
cpp
p03142
#include <algorithm> #include <assert.h> #include <bitset> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <vector> #define INF 0x3f3f3f3f // 3f3f3f3f #define ll long long #define ull unsigned long long #define lowbit(a) ((a) & (-(a))) using namespace std; int n, m; struct edge { int v, next; } e[200005]; int head[100005], du[100005], cnt; int tp[100005], tc, vis[100005], fa[100005]; void add(int u, int v) { e[cnt].v = v, e[cnt].next = head[u], head[u] = cnt++; } void init() { memset(head, -1, sizeof head); cnt = 0; memset(du, 0, sizeof du); memset(vis, 0, sizeof du); memset(fa, 0, sizeof du); tc = 0; } int main() { while (~scanf("%d%d", &n, &m)) { init(); for (int i = 1; i < n + m; i++) { int u, v; scanf("%d %d", &u, &v); add(u, v); du[v]++; } queue<int> que; for (int i = 1; i <= n; i++) { if (du[i] == 0) { tp[i] = ++tc; vis[i] = 1; que.push(i); break; } } while (que.size()) { int d = que.front(); que.pop(); for (int i = head[d]; ~i; i = e[i].next) { if (!vis[e[i].v]) { du[e[i].v]--; if (du[e[i].v] == 0) { que.push(e[i].v); vis[e[i].v] = 1; tp[e[i].v] = ++tc; } } } } tp[0] = n + 1; for (int i = 1; i <= n; i++) { for (int j = head[i]; ~j; j = e[j].next) { if (tp[i] < tp[fa[e[j].v]]) fa[e[j].v] = i; } } for (int i = 1; i <= n; i++) { printf("%d\n", fa[i]); } } return 0; }
#include <algorithm> #include <assert.h> #include <bitset> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <vector> #define INF 0x3f3f3f3f // 3f3f3f3f #define ll long long #define ull unsigned long long #define lowbit(a) ((a) & (-(a))) using namespace std; int n, m; struct edge { int v, next; } e[200005]; int head[100005], du[100005], cnt; int tp[100005], tc, vis[100005], fa[100005]; void add(int u, int v) { e[cnt].v = v, e[cnt].next = head[u], head[u] = cnt++; } void init() { memset(head, -1, sizeof head); cnt = 0; memset(du, 0, sizeof du); memset(vis, 0, sizeof du); memset(fa, 0, sizeof du); tc = 0; } int main() { while (~scanf("%d%d", &n, &m)) { init(); for (int i = 1; i < n + m; i++) { int u, v; scanf("%d %d", &u, &v); add(u, v); du[v]++; } queue<int> que; for (int i = 1; i <= n; i++) { if (du[i] == 0) { tp[i] = ++tc; vis[i] = 1; que.push(i); break; } } while (que.size()) { int d = que.front(); que.pop(); for (int i = head[d]; ~i; i = e[i].next) { if (!vis[e[i].v]) { du[e[i].v]--; if (du[e[i].v] == 0) { que.push(e[i].v); vis[e[i].v] = 1; tp[e[i].v] = ++tc; } } } } tp[0] = 0; for (int i = 1; i <= n; i++) { for (int j = head[i]; ~j; j = e[j].next) { if (tp[i] > tp[fa[e[j].v]]) fa[e[j].v] = i; } } for (int i = 1; i <= n; i++) { printf("%d\n", fa[i]); } } return 0; }
[ "assignment.value.change", "identifier.replace.remove", "literal.replace.add", "expression.operation.binary.change", "expression.operation.binary.remove", "misc.opposites", "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
942,589
942,590
u800506905
cpp
p03142
#include <algorithm> #include <cmath> #include <functional> #include <iostream> #include <set> #include <vector> #define REP(i, N) for (int i = 0; i < N; i++) using namespace std; using vi = vector<int>; int main() { int N, M, root; cin >> N >> M; vi A(N - 1 + M), B(N - 1 + M), visited(N), sorted, sortedinv(N); vector<set<int>> from(N), to(N); REP(i, N - 1 + M) { cin >> A[i] >> B[i]; A[i]--; B[i]--; from[A[i]].insert(B[i]); to[B[i]].insert(A[i]); } REP(i, N) { if (to[i].empty()) { root = i; break; } } function<void(int)> visit = [&](int n) { if (visited[n]) return; visited[n] = 1; for (int x : from[n]) { visit(x); } sorted.push_back(n); }; visit(root); REP(i, N) { sortedinv[sorted[i]] = i; } REP(i, N) { if (i == root) { cout << 0 << endl; } else { int par = 0; for (int x : to[i]) { par = max(sortedinv[x], par); } cout << sorted[par] + 1 << endl; } } return 0; }
#include <algorithm> #include <cmath> #include <functional> #include <iostream> #include <set> #include <vector> #define REP(i, N) for (int i = 0; i < N; i++) using namespace std; using vi = vector<int>; int main() { int N, M, root; cin >> N >> M; vi A(N - 1 + M), B(N - 1 + M), visited(N), sorted, sortedinv(N); vector<set<int>> from(N), to(N); REP(i, N - 1 + M) { cin >> A[i] >> B[i]; A[i]--; B[i]--; from[A[i]].insert(B[i]); to[B[i]].insert(A[i]); } REP(i, N) { if (to[i].empty()) { root = i; break; } } function<void(int)> visit = [&](int n) { if (visited[n]) return; visited[n] = 1; for (int x : from[n]) { visit(x); } sorted.push_back(n); }; visit(root); REP(i, N) { sortedinv[sorted[i]] = i; } REP(i, N) { if (i == root) { cout << 0 << endl; } else { int par = N; for (int x : to[i]) { par = min(sortedinv[x], par); } cout << sorted[par] + 1 << endl; } } return 0; }
[ "variable_declaration.value.change", "identifier.replace.add", "literal.replace.remove", "misc.opposites", "assignment.value.change", "identifier.change", "call.function.change" ]
942,591
942,592
u486021106
cpp
p03142
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; #define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME) #define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME) #define VEC(TYPE, A, NAME, INIT) vector<TYPE> NAME(A, INIT) #define VEC2(TYPE, A, B, NAME, INIT) \ vector<vector<TYPE>> NAME(A, vector<TYPE>(B, (INIT))) int main() { int n, m; cin >> n >> m; VEC(int, n, pa, -1); vector<vector<int>> edge(n); VEC(int, n, bb, 0); REP(i, n - 1 + m) { int a, b; cin >> a >> b; edge[a - 1].push_back(b - 1); bb[b - 1]++; } stack<int> st; REP(i, n) { if (bb[i] > 0) continue; st.push(i); break; } vector<int> top; while (!st.empty()) { int i = st.top(); st.pop(); top.push_back(i); for (const auto &v : edge[i]) { if (--bb[v] == 0) st.push(v); } } REP(i, n) { int t = top[i]; if (i == 0) { pa[t] = 0; } for (const auto &v : edge[t]) { pa[v] = t; } } REP(i, n) { cout << pa[i] + 1 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; #define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME) #define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME) #define VEC(TYPE, A, NAME, INIT) vector<TYPE> NAME(A, INIT) #define VEC2(TYPE, A, B, NAME, INIT) \ vector<vector<TYPE>> NAME(A, vector<TYPE>(B, (INIT))) int main() { int n, m; cin >> n >> m; VEC(int, n, pa, -1); vector<vector<int>> edge(n); VEC(int, n, bb, 0); REP(i, n - 1 + m) { int a, b; cin >> a >> b; edge[a - 1].push_back(b - 1); bb[b - 1]++; } stack<int> st; REP(i, n) { if (bb[i] > 0) continue; st.push(i); break; } vector<int> top; while (!st.empty()) { int i = st.top(); st.pop(); top.push_back(i); for (const auto &v : edge[i]) { if (--bb[v] == 0) st.push(v); } } REP(i, n) { int t = top[i]; if (i == 0) { pa[t] = -1; } for (const auto &v : edge[t]) { pa[v] = t; } } REP(i, n) { cout << pa[i] + 1 << endl; } return 0; }
[ "literal.number.change", "assignment.value.change" ]
942,598
942,599
u627427672
cpp
p03145
#include <bits/stdc++.h> using namespace std; int main() { int x, y, z; cin >> x >> y >> z; cout << x * (y / 2) << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int x, y, z; cin >> x >> y >> z; cout << (x * y) / 2 << endl; }
[]
942,604
942,605
u222613738
cpp
p03145
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, c; cin >> a >> b >> c; cout << 1 / 2 * a * b; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, c; cin >> a >> b >> c; cout << a * b / 2; return 0; }
[ "expression.operation.binary.remove" ]
942,632
942,633
u562321612
cpp
p03145
#include <algorithm> #include <iostream> #include <string> using namespace std; int b[100000]; signed main() { int a, b, c, d; cin >> a >> b >> c; cout << b * c / 2 << "\n"; return (0); }
#include <algorithm> #include <iostream> #include <string> using namespace std; int b[100000]; signed main() { int a, b, c, d; cin >> a >> b >> c; cout << a * b / 2 << "\n"; return (0); }
[ "identifier.change", "io.output.change" ]
942,675
942,676
u240895927
cpp
p03145
#include <iostream> using namespace std; int main() { int ab, bc, ca; cin >> ab >> bc >> ca; cout << double(bc * ca) / 2 << endl; return 0; }
#include <iostream> using namespace std; int main() { int ab, bc, ca; cin >> ab >> bc >> ca; cout << bc * ab / 2 << endl; return 0; }
[ "call.remove", "identifier.change", "io.output.change", "call.arguments.change" ]
942,700
942,701
u057810841
cpp
p03145
#include <algorithm> #define _USE_MATH_DEFINES #include <cmath> #include <iostream> #include <list> #include <map> #include <numeric> #include <set> #include <stdio.h> #include <string> #include <tuple> #include <utility> #include <vector> #define rep(i, n) for (int i = 0; i < (int)n; i++) #define all(a) a.begin(), a.end() using namespace std; int main() { int a, b, c; cin >> a >> b >> c; cout << a * c / 2 << endl; return 0; }
#include <algorithm> #define _USE_MATH_DEFINES #include <cmath> #include <iostream> #include <list> #include <map> #include <numeric> #include <set> #include <stdio.h> #include <string> #include <tuple> #include <utility> #include <vector> #define rep(i, n) for (int i = 0; i < (int)n; i++) #define all(a) a.begin(), a.end() using namespace std; int main() { int a, b, c; cin >> a >> b >> c; cout << a * b / 2 << endl; return 0; }
[ "identifier.change", "io.output.change" ]
942,704
942,705
u382102154
cpp
p03145
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; int d = a / 2; cout << d * b; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; int d = a * b; cout << d / 2; return 0; }
[]
942,719
942,720
u484351040
cpp
p03145
#include <bits/stdc++.h> using namespace std; int main() { int A, B, C; cin >> A >> B >> C; cout << A * B; }
#include <bits/stdc++.h> using namespace std; int main() { int A, B, C; cin >> A >> B >> C; cout << A * B / 2; }
[ "expression.operation.binary.add" ]
942,799
942,800
u383166010
cpp
p03145
#include <algorithm> #include <cmath> #include <iostream> #include <stdexcept> #include <string> using namespace std; int main() { int a, b, c, d, e; char g[20]; string h, i; cin >> a >> b >> c; cout << a * b; }
#include <algorithm> #include <cmath> #include <iostream> #include <stdexcept> #include <string> using namespace std; int main() { int a, b, c, d, e; char g[20]; string h, i; cin >> a >> b >> c; cout << a * b / 2; }
[ "expression.operation.binary.add" ]
942,827
942,828
u768204022
cpp
p03145
#include <algorithm> #include <cmath> #include <iostream> #include <stdexcept> #include <string> using namespace std; int main() { int a, b, c, d, e; char g[20]; string h, i; cin >> a, b, c; cout << a * b; }
#include <algorithm> #include <cmath> #include <iostream> #include <stdexcept> #include <string> using namespace std; int main() { int a, b, c, d, e; char g[20]; string h, i; cin >> a >> b >> c; cout << a * b / 2; }
[ "expression.operation.binary.add" ]
942,829
942,828
u768204022
cpp
p03145
#include <bits/stdc++.h> int main(void) { std::vector<int> len(3); for (int i = 0; i < 3; i++) { std::cin >> len.at(i); } std::cout << len.at(0) * len.at(1) << std::endl; return 0; }
#include <bits/stdc++.h> int main(void) { std::vector<int> len(3); for (int i = 0; i < 3; i++) { std::cin >> len.at(i); } std::cout << len.at(0) * len.at(1) / 2 << std::endl; return 0; }
[ "expression.operation.binary.add" ]
942,854
942,855
u801884816
cpp
p03145
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (n); i++) int main(int argc, char const *argv[]) { int a, b, c; cin >> a >> b >> c; cout << (a + b) / 2 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (n); i++) int main(int argc, char const *argv[]) { int a, b, c; cin >> a >> b >> c; cout << (a * b) / 2 << endl; return 0; }
[ "expression.operator.arithmetic.change", "io.output.change" ]
942,890
942,891
u029876051
cpp
p03145
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (n); i++) int main(int argc, char const *argv[]) { int a, b, c; cin >> a >> b >> c; cout << (double)(a + b) / 2 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (n); i++) int main(int argc, char const *argv[]) { int a, b, c; cin >> a >> b >> c; cout << (a * b) / 2 << endl; return 0; }
[ "expression.operator.arithmetic.change", "io.output.change" ]
942,892
942,891
u029876051
cpp
p03145
#include <bits/stdc++.h> using namespace std; int main() { int AB, BC, CA; cin >> AB >> BC >> CA; cout << (AB * CA) / 2 << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int AB, BC, CA; cin >> AB >> BC >> CA; cout << (AB * BC) / 2 << endl; }
[ "identifier.change", "io.output.change" ]
942,906
942,907
u983062344
cpp
p03145
#include <bits/stdc++.h> using namespace std; int main() { int AB, BC, CA; cin >> AB >> BC >> CA; cout << (AB + BC) / 2 << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int AB, BC, CA; cin >> AB >> BC >> CA; cout << (AB * BC) / 2 << endl; }
[ "expression.operator.arithmetic.change", "io.output.change" ]
942,908
942,907
u983062344
cpp
p03145
#include <bits/stdc++.h> using namespace std; int main() { int AB, BC, CA; cin >> AB >> BC >> CA; cout << (AB + CA) / 2 << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int AB, BC, CA; cin >> AB >> BC >> CA; cout << (AB * BC) / 2 << endl; }
[]
942,909
942,907
u983062344
cpp
p03145
// https://atcoder.jp/contests/abc116/tasks/abc116_a #include <bits/stdc++.h> #define rep(i, a, b) for (int i = a; i < b; i++) #define rrep(i, a, b) for (int i = a; i >= b; i--) #define fore(i, a) for (auto &i : a) #define all(x) (x).begin(), (x).end() //#pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } //--------------------------------------------------------------------------------------------------- /*---------------------------------------------------------------------------------------------------             ∧_∧       ∧_∧  (´<_` )  Welcome to My Coding Space!      ( ´_ゝ`) /  ⌒i     /   \    | |     /   / ̄ ̄ ̄ ̄/  |   __(__ニつ/  _/ .| .|____      \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ int A, B, C; //--------------------------------------------------------------------------------------------------- void _main() { cin >> A >> B >> C; cout << A / 2 << endl; }
// https://atcoder.jp/contests/abc116/tasks/abc116_a #include <bits/stdc++.h> #define rep(i, a, b) for (int i = a; i < b; i++) #define rrep(i, a, b) for (int i = a; i >= b; i--) #define fore(i, a) for (auto &i : a) #define all(x) (x).begin(), (x).end() //#pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } //--------------------------------------------------------------------------------------------------- /*---------------------------------------------------------------------------------------------------             ∧_∧       ∧_∧  (´<_` )  Welcome to My Coding Space!      ( ´_ゝ`) /  ⌒i     /   \    | |     /   / ̄ ̄ ̄ ̄/  |   __(__ニつ/  _/ .| .|____      \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ int A, B, C; //--------------------------------------------------------------------------------------------------- void _main() { cin >> A >> B >> C; cout << A * B / 2 << endl; }
[ "expression.operation.binary.add" ]
942,990
942,991
u141378465
cpp
p03145
#include <bits/stdc++.h> using namespace std; int main() { int ans = 1; int A, B, C; cin >> A >> B >> C; ans = A * C; // cout << ans <<endl; cout << ans / 2 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int ans = 1; int A, B, C; cin >> A >> B >> C; ans = A * B; // cout << ans <<endl; cout << ans / 2 << endl; return 0; }
[ "assignment.value.change", "identifier.change", "expression.operation.binary.change" ]
943,010
943,011
u355424600
cpp
p03145
#include <bits/stdc++.h> using namespace std; int main() { int ans = 1; int A, B, C; cin >> A >> B >> C; ans = A * C; // cout << ans <<endl; cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int ans = 1; int A, B, C; cin >> A >> B >> C; ans = A * B; // cout << ans <<endl; cout << ans / 2 << endl; return 0; }
[ "assignment.value.change", "identifier.change", "expression.operation.binary.change" ]
943,012
943,011
u355424600
cpp
p03145
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; int main() { int AB, BC, CA; cin >> AB >> BC >> CA; int ans = AB * BC; cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; int main() { int AB, BC, CA; cin >> AB >> BC >> CA; int ans = AB * BC / 2; cout << ans << endl; return 0; }
[ "assignment.change" ]
943,020
943,021
u791220701
cpp
p03145
#include <iostream> using namespace std; int main() { int AB, BC, CA; cin >> AB >> BC >> CA; cout << AB * BC << endl; }
#include <iostream> using namespace std; int main() { int AB, BC, CA; cin >> AB >> BC >> CA; cout << AB * BC / 2 << endl; }
[ "expression.operation.binary.add" ]
943,068
943,069
u096717230
cpp
p03145
#include <bits/stdc++.h> using namespace std; int main() { int ab, bc, ca, answer; cin >> ab >> bc; answer == ab *bc / 2; cout << answer << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int ab, bc, ca, answer; cin >> ab >> bc; answer = ab * bc / 2; cout << answer << endl; }
[ "expression.operation.compare.replace.remove", "assignment.replace.add", "misc.typo" ]
943,099
943,100
u003761219
cpp
p03145
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; cout << (a + b + c) / 2 << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; cout << a * b / 2 << endl; }
[ "expression.operator.arithmetic.change", "io.output.change" ]
943,117
943,118
u539675863
cpp
p03145
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; cout << a * b << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; cout << a * b / 2 << endl; }
[ "expression.operation.binary.add" ]
943,218
943,219
u535810324
cpp