buggy_code
stringlengths
11
625k
fixed_code
stringlengths
17
625k
bug_type
stringlengths
2
4.45k
language
int64
0
8
token_count
int64
5
200k
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; string s; cin >> s; vector<int> x(n); rep(i, n) { x[i] ...
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; string s; cin >> s; vector<int> x(n); rep(i, n) { x[i] ...
[["-", 51, 16, 31, 16, 31, 69, 341, 342, 0, 13], ["+", 31, 16, 31, 69, 341, 342, 0, 16, 31, 22], ["+", 31, 16, 31, 69, 341, 342, 0, 16, 17, 33], ["+", 31, 16, 31, 69, 341, 342, 0, 16, 12, 13], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13], ["+", 15, 339, 51, 16, 12, 16, 12, 16, 31, 22], ["+", 15, 339, 51, 16, 12, 16, 1...
1
455
#include <algorithm> #include <iostream> using namespace std; typedef long long ll; const int N = 200010; int f[N], pop[N]; int a[N], n; ll qmi(ll a, ll b, ll p) { ll res = 1 % p; a %= p; while (b) { if (b & 1) res = res * a % p; b >>= 1; a = a * a % p; } return res; } int calc(ll x) { int...
#include <algorithm> #include <iostream> using namespace std; typedef long long ll; const int N = 200010; int f[N], pop[N]; int a[N], n; ll qmi(ll a, ll b, ll p) { ll res = 1 % p; a %= p; while (b) { if (b & 1) res = res * a % p; b >>= 1; a = a * a % p; } return res; } int calc(ll x) { int...
[["-", 0, 11, 12, 2, 3, 4, 0, 16, 17, 72], ["+", 0, 11, 12, 2, 3, 4, 0, 16, 17, 33]]
1
571
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define REP(i, n) for (int i = 1; i <= (n); i++) typedef long long ll; int func(int N) { int num = 0; int kaisuu = 0; int b = N; while (b > 0) { b = b / 2; kaisuu++; } rep(i, kaisuu + 1) { if ((N >> i)...
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define REP(i, n) for (int i = 1; i <= (n); i++) typedef long long ll; int func(int N) { int num = 0; int kaisuu = 0; int b = N; while (b > 0) { b = b / 2; kaisuu++; } rep(i, kaisuu + 1) { if ((N >> i)...
[["+", 8, 9, 0, 9, 0, 57, 64, 9, 0, 45], ["+", 8, 9, 0, 9, 0, 57, 64, 9, 0, 46], ["+", 75, 76, 0, 9, 0, 57, 64, 9, 0, 45], ["+", 75, 76, 0, 9, 0, 57, 64, 9, 0, 46]]
1
537
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def popcnt(n): return bin(n).count("1") def mod(n, cnt): if n == 0: return cnt n = n % popcnt(n) cnt += 1 return mod(n, cnt) n = int(readline()) x2 = list(readline().deco...
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def popcnt(n): return bin(n).count("1") def mod(n, cnt): if n == 0: return cnt n = n % popcnt(n) cnt += 1 return mod(n, cnt) n = int(readline()) x2 = list(readline().deco...
[["-", 75, 76, 8, 196, 0, 1, 0, 662, 31, 22], ["-", 75, 76, 8, 196, 0, 1, 0, 662, 0, 32], ["+", 75, 76, 8, 196, 0, 1, 0, 652, 63, 22], ["+", 8, 196, 0, 1, 0, 652, 3, 4, 0, 24], ["+", 8, 196, 0, 1, 0, 652, 3, 4, 0, 25], ["+", 0, 57, 75, 76, 8, 196, 0, 116, 0, 117]]
5
247
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define sz(v) ((int)(v).size()) #define all(v) ((v).begin()), ((v).end()) #define allr(v) ((v).rbegin()), ((v).rend()) #define pb push_back #define mp make_pair #define clr(v, val) memset(v, val, sizeof(v)) #define lc...
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define sz(v) ((int)(v).size()) #define all(v) ((v).begin()), ((v).end()) #define allr(v) ((v).rbegin()), ((v).rend()) #define pb push_back #define mp make_pair #define clr(v, val) memset(v, val, sizeof(v)) #define lc...
[["+", 0, 7, 15, 16, 12, 16, 31, 16, 17, 33], ["+", 0, 7, 15, 16, 12, 16, 31, 16, 12, 13]]
1
791
#include <bits/stdc++.h> using ll = long long; using ull = unsigned long long; using namespace std; constexpr int inf = 1 << 30; constexpr int mo = 1e9 + 7; constexpr ll infl = 1ll << 60; map<int, int> m; string s; int n; int culc(int num) { if (num == 0) return 0; if (num == 1) return 1; if (m.count(num...
#include <bits/stdc++.h> using ll = long long; using ull = unsigned long long; using namespace std; constexpr int inf = 1 << 30; constexpr int mo = 1e9 + 7; constexpr ll infl = 1ll << 60; map<int, int> m; string s; int n; int culc(int num) { if (num == 0) return 0; if (num == 1) return 1; if (m.count(num...
[["+", 8, 9, 0, 57, 64, 9, 0, 57, 0, 121], ["+", 0, 57, 64, 9, 0, 57, 15, 339, 0, 24], ["+", 64, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["+", 64, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 64, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 0, 57, 64, 9, 0, 57, 15, 339, 0, 25]]
1
548
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.HashMap; import java.util.Scanner; public class Main { public static void main(String[] args) { Main main = new Main(); main.solve(); } public void solve() { Scanner ...
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.HashMap; import java.util.Scanner; public class Main { public static void main(String[] args) { Main main = new Main(); main.solve(); } public void solve() { Scanner ...
[["-", 8, 196, 0, 57, 15, 15, 0, 16, 31, 499], ["+", 8, 196, 0, 57, 15, 15, 0, 16, 31, 499], ["-", 0, 57, 15, 15, 0, 16, 31, 16, 17, 33], ["-", 0, 57, 15, 15, 0, 16, 31, 16, 12, 499], ["-", 75, 196, 0, 57, 15, 15, 0, 16, 12, 499], ["+", 75, 196, 0, 57, 15, 15, 0, 16, 12, 499]]
3
659
#include <bits/stdc++.h> // #include <math.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; const int MOD = (int)1e9 + 7; const double PI = 3.14159265358979323846; int popCnt(int x) { return __builtin_popcount(x); } int f(int x) { if (x == 0) return 0; return f(x % ...
#include <bits/stdc++.h> // #include <math.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; const int MOD = (int)1e9 + 7; const double PI = 3.14159265358979323846; int popCnt(int x) { return __builtin_popcount(x); } int f(int x) { if (x == 0) return 0; return f(x % ...
[["+", 8, 9, 0, 9, 0, 43, 49, 50, 0, 32], ["+", 8, 9, 0, 9, 0, 43, 49, 50, 51, 13]]
1
333
#include <math.h> #include <stdio.h> #include <string.h> #define B_MAX 200001 char in_bit[200002]; int org_bit[200001]; //先頭が最下位bit long long int q_list[200001]; // 10進数 // int divid_list[200001];//q_listの余りから入れていく int a_list[200001]; // q_listの対 int main() { int n, org_b = 0; long long int x = 1, x_p_m = 1, x_...
#include <math.h> #include <stdio.h> #include <string.h> #define B_MAX 200001 char in_bit[200002]; int org_bit[200001]; //先頭が最下位bit long long int q_list[200001]; // 10進数 // int divid_list[200001];//q_listの余りから入れていく int a_list[200001]; // q_listの対 int main() { int n, org_b = 0; long long int x = 1, x_p_m = 1, x_...
[["-", 0, 7, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 7, 8, 9, 0, 43, 49, 50, 51, 13]]
0
472
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <numeric> #include <queue> #include <string> #include <vector> int main() { int n; std::cin >> n; std::vector<int> num(n); long long int sum = 0; for (int i = 0; i < n; i++) { int a; std::cin >> a; sum += a; num...
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <numeric> #include <queue> #include <string> #include <vector> int main() { int n; std::cin >> n; std::vector<int> num(100000); long long int sum = 0; for (int i = 0; i < n; i++) { int a; std::cin >> a; sum += a; ...
[["-", 0, 43, 49, 53, 54, 55, 0, 56, 39, 78], ["+", 8, 9, 0, 43, 49, 50, 51, 4, 0, 13]]
1
167
N = int(input()) A = list(map(int,input().split())) Q = int(input()) cnt_dict = {} s = sum(A) ans = 0 for item in A: if item not in cnt_dict: cnt_dict[item] = 0 cnt_dict[item] += 1 for _ in range(Q): X,Y = map(int,input().split()) if X not in cnt_dict: cnt_dict[X] = 0 if Y not...
N = int(input()) A = list(map(int,input().split())) Q = int(input()) cnt_dict = {} s = sum(A) ans = 0 for item in A: if item not in cnt_dict: cnt_dict[item] = 0 cnt_dict[item] += 1 for _ in range(Q): X,Y = map(int,input().split()) if X not in cnt_dict: cnt_dict[X] = 0 if Y not...
[["-", 0, 1, 0, 677, 12, 657, 31, 206, 206, 22], ["+", 0, 1, 0, 677, 12, 657, 31, 206, 206, 22], ["-", 8, 196, 0, 1, 0, 677, 31, 206, 206, 22], ["+", 8, 196, 0, 1, 0, 677, 31, 206, 206, 22], ["-", 8, 196, 0, 1, 0, 677, 12, 206, 206, 22], ["+", 8, 196, 0, 1, 0, 677, 12, 206, 206, 22], ["-", 8, 196, 0, 1, 0, 662, 31, 206...
5
155
import collections n = int(input()) arr = list(map(int,input().split())) cnt = collections.defaultdict(int) for val in arr: cnt[val] += 1 sums = sum(arr) q = int(input()) for _ in range(q): b, c = map(int,input().split()) diff = (c-b)*(cnt[b]) sums += diff print(sums) cnt[c] += nt[b] cnt[b] ...
import collections n = int(input()) arr = list(map(int,input().split())) cnt = collections.defaultdict(int) for val in arr: cnt[val] += 1 sums = sum(arr) q = int(input()) for _ in range(q): b, c = map(int,input().split()) diff = (c-b)*(cnt[b]) sums += diff print(sums) cnt[c] += cnt[b] cnt[b]...
[["-", 8, 196, 0, 1, 0, 677, 12, 206, 51, 22], ["+", 8, 196, 0, 1, 0, 677, 12, 206, 51, 22]]
5
120
N = int(input()) As = list(map(int, input().split())) Q = int(input()) sumAs = 0 dictAs = [0] * 100000 for i in range(len(As)): sumAs += As[i] dictAs[As[i] - 1] = 1 for _ in range(Q): b, c = map(int, input().split()) sumAs += dictAs[b - 1] * (c - b) dictAs[c - 1] += dictAs[b - 1] dictAs[b - 1] = 0 pri...
N = int(input()) As = list(map(int, input().split())) Q = int(input()) sumAs = 0 dictAs = [0] * 100000 for i in range(len(As)): sumAs += As[i] dictAs[As[i] - 1] += 1 for _ in range(Q): b, c = map(int, input().split()) sumAs += dictAs[b - 1] * (c - b) dictAs[c - 1] += dictAs[b - 1] dictAs[b - 1] = 0 pr...
[["-", 0, 7, 8, 196, 0, 1, 0, 662, 0, 32], ["+", 0, 7, 8, 196, 0, 1, 0, 677, 17, 107]]
5
134
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; int main() { ll n, q, b, c, w, ans = 0; cin >> n; vector<int> a(n); rep(i, n) { cin >> w; a[w]++; ans += w; } cin >> q; rep(i, q) { cin >> b >> c; ...
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; int main() { ll n, q, b, c, w, ans = 0; cin >> n; vector<int> a(500010); rep(i, n) { cin >> w; a[w]++; ans += w; } cin >> q; rep(i, q) { cin >> b >...
[["-", 0, 43, 49, 53, 54, 55, 0, 56, 39, 78], ["+", 8, 9, 0, 43, 49, 50, 51, 4, 0, 13]]
1
140
#include <bits/stdc++.h> using namespace std; #define MAX 1000000000005 #define ll long long int int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int m, sum = 0, k = 0, i, d = 0, j, sum1 = 0, sum2 = 0, sum3 = 0, l, kk, sum4 = 0, sum5 = 0, sum6 = 0, c = 0, x, y, q; l...
#include <bits/stdc++.h> using namespace std; #define MAX 1000000000005 #define ll long long int int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll t; long long int m, sum = 0, k = 0, i, d = 0, j, sum1 = 0, sum2 = 0, sum3 = 0, l, kk, sum4 = 0, sum5 = 0, sum6 = 0, c = 0, x, y,...
[["+", 0, 30, 0, 14, 8, 9, 0, 43, 39, 78], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 49, 22], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 0, 35], ["-", 0, 1, 0, 2, 3, 4, 0, 69, 28, 22], ["-", 0, 2, 3, 4, 0, 69, 341, 342, 0, 70], ["-", 0, 2, 3, 4, 0, 69, 341, 342, 0, 73]]
1
233
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <tuple> #include <utility> #include <vector> using namespace std; using ll = long long; const int INF = 100000000...
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <tuple> #include <utility> #include <vector> using namespace std; using ll = long long; const int INF = 100000000...
[["-", 0, 43, 49, 50, 51, 4, 0, 16, 31, 22], ["-", 0, 43, 49, 50, 51, 4, 0, 16, 17, 72], ["-", 0, 43, 49, 50, 51, 4, 0, 16, 12, 13], ["+", 8, 9, 0, 43, 49, 50, 51, 4, 0, 13]]
1
244
n = int(input()) a = list(map(int, input().split())) q = int(input()) sums = sum(a) d = {} for i in a: if i in d: d[i] += 1 else: d[i] = 1 for i in range(q): b,c = map(int, input().split()) if b in d: sums += d[b]*(c-b) if c in d: d[c] += d[b] else: d[c]...
n = int(input()) a = list(map(int, input().split())) q = int(input()) sums = sum(a) d = {} for i in a: if i in d: d[i] += 1 else: d[i] = 1 for i in range(q): b,c = map(int, input().split()) if b in d: sums += d[b]*(c-b) if c in d: d[c] += d[b] else: d[c]...
[["+", 64, 196, 0, 1, 0, 662, 31, 206, 51, 22], ["+", 64, 196, 0, 1, 0, 662, 31, 206, 0, 70], ["+", 64, 196, 0, 1, 0, 662, 31, 206, 206, 22], ["+", 64, 196, 0, 1, 0, 662, 31, 206, 0, 73], ["+", 0, 57, 64, 196, 0, 1, 0, 662, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 662, 12, 612]]
5
137
from collections import Counter n = int(input()) a = list(map(int,input().split())) q = int(input()) C = Counter(a) s = sum(a) for _ in range(q): b,c = map(int,input().split()) s = s - b*C[b] + c*C[c] C[c] += C[b] C[b] = 0 print(s)
from collections import Counter n = int(input()) a = list(map(int,input().split())) q = int(input()) C = Counter(a) s = sum(a) for _ in range(q): b,c = map(int,input().split()) s = s - b*C[b] + c*C[b] C[c] += C[b] C[b] = 0 print(s)
[["-", 0, 662, 12, 657, 12, 657, 12, 206, 206, 22], ["+", 0, 662, 12, 657, 12, 657, 12, 206, 206, 22]]
5
109
package main import ( "bufio" "fmt" "os" "strconv" ) func main() { scanInit() n := nextInt() m := map[int]int{} sum := 0 for i := 0; i < n; i++ { tmp := nextInt() m[tmp]++ sum += tmp } q := nextInt() for i := 0; i < q; i++ { from := nextInt() to := nextInt() fromcnt := m[from] m[to] += fr...
package main import ( "bufio" "fmt" "os" "strconv" ) func main() { scanInit() n := nextInt() m := map[int]int{} sum := 0 for i := 0; i < n; i++ { tmp := nextInt() m[tmp]++ sum += tmp } q := nextInt() for i := 0; i < q; i++ { from := nextInt() to := nextInt() fromcnt := m[from] delete(m, f...
[["+", 0, 7, 8, 196, 0, 1, 0, 2, 63, 22], ["+", 8, 196, 0, 1, 0, 2, 3, 4, 0, 24], ["+", 8, 196, 0, 1, 0, 2, 3, 4, 0, 21], ["+", 8, 196, 0, 1, 0, 2, 3, 4, 0, 22], ["+", 8, 196, 0, 1, 0, 2, 3, 4, 0, 25], ["+", 0, 435, 8, 196, 0, 7, 8, 196, 0, 165], ["+", 8, 196, 0, 436, 31, 432, 0, 437, 439, 22]]
7
262
#include <bits/stdc++.h> using namespace std; #define INF 1e9 #define rep(i, n) for (int i = 0; i < (n); ++i) #define ALL(x) (x).begin(), (x).end() typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int, int> pii; template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (...
#include <bits/stdc++.h> using namespace std; #define INF 1e9 #define rep(i, n) for (int i = 0; i < (n); ++i) #define ALL(x) (x).begin(), (x).end() typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int, int> pii; template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (...
[["-", 8, 9, 0, 57, 15, 339, 51, 91, 17, 111], ["-", 0, 14, 8, 9, 0, 57, 64, 116, 0, 117], ["-", 0, 14, 8, 9, 0, 57, 64, 116, 0, 35], ["-", 0, 14, 8, 9, 0, 57, 75, 76, 0, 95], ["+", 0, 14, 8, 9, 0, 57, 64, 9, 0, 46], ["-", 8, 9, 0, 57, 75, 76, 0, 9, 0, 46]]
1
313
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<ll, ll>; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define mod 1000000007 #define pi 3.141592653589793 typedef vector<ll> vcl; ll gcd(ll a, ll b) { if (b > a) swap(a, b); if (b == 0) return a; return gcd(b, a % b)...
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<ll, ll>; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define mod 1000000007 #define pi 3.141592653589793 typedef vector<ll> vcl; ll gcd(ll a, ll b) { if (b > a) swap(a, b); if (b == 0) return a; return gcd(b, a % b)...
[["-", 0, 1, 0, 11, 12, 16, 12, 16, 31, 22], ["-", 0, 1, 0, 11, 12, 16, 12, 16, 17, 48], ["-", 12, 16, 12, 16, 12, 69, 341, 342, 0, 22], ["+", 12, 16, 12, 16, 31, 69, 341, 342, 0, 22], ["+", 0, 1, 0, 11, 12, 16, 12, 16, 17, 48], ["+", 0, 1, 0, 11, 12, 16, 12, 16, 12, 22]]
1
324
N = int(input()) A = list(map(int, input().split())) Q = int(input()) sum_res = sum(A) counter = [0 for _ in range(10 ** 5 + 1)] for a in A: counter[a] += 1 for _ in range(Q): B, C = map(int, input().split()) sum_res = sum_res - (counter[B] * B) sum_res = sum_res + (counter[B] * C) counter[C] = co...
N = int(input()) A = list(map(int, input().split())) Q = int(input()) sum_res = sum(A) counter = [0 for _ in range(10 ** 5 + 1)] for a in A: counter[a] += 1 for _ in range(Q): B, C = map(int, input().split()) sum_res = sum_res - (counter[B] * B) sum_res = sum_res + (counter[B] * C) counter[C] += c...
[["-", 0, 7, 8, 196, 0, 1, 0, 662, 0, 32], ["+", 0, 7, 8, 196, 0, 1, 0, 677, 17, 107]]
5
133
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll a[214514], cnt[214514]; int main() { ll n; cin >> n; ll sum = 0; for (int i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; cnt[a[i]]++; } ll q; cin >> q; for (int i = 0; i < q; i++) { ll b, c; cin >> b >> c; sum...
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll a[214514], cnt[214514]; int main() { ll n; cin >> n; ll sum = 0; for (int i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; cnt[a[i]]++; } ll q; cin >> q; for (int i = 0; i < q; i++) { ll b, c; cin >> b >> c; sum...
[["+", 8, 9, 0, 1, 0, 11, 12, 69, 28, 22], ["+", 0, 1, 0, 11, 12, 69, 341, 342, 0, 70], ["+", 0, 1, 0, 11, 12, 69, 341, 342, 0, 73]]
1
149
#include <bits/stdc++.h> #define MEM 100006 #define sanic ios_base::sync_with_stdio(0) #define pb push_back using namespace std; typedef long long ll; typedef pair<ll, ll> pii; const ll MOD = 1e9 + 7; ll n, m, sum; ll c[MEM]; string s; int main() { sanic; cin.tie(0); cin >> n; for (int i = 0; i < n; i++) { ...
#include <bits/stdc++.h> #define MEM 100006 #define sanic ios_base::sync_with_stdio(0) #define pb push_back using namespace std; typedef long long ll; typedef pair<ll, ll> pii; const ll MOD = 1e9 + 7; ll n, m, sum; ll c[MEM]; string s; int main() { sanic; cin.tie(0); cin >> n; for (int i = 0; i < n; i++) { ...
[["-", 0, 11, 12, 16, 12, 69, 341, 342, 0, 22], ["+", 0, 11, 12, 16, 12, 69, 341, 342, 0, 22]]
1
170
def freq(my_list): count = {} for i in my_list: count[i] = count.get(i, 0) + 1 return count n = int(input()) l = list(map(int, input().split())) s,f = sum(l), freq(l) for _ in range(int(input())): x, y = map(int, input().split()) if x in f: v = f[x] if y in f: f[y]+=v ...
def freq(my_list): count = {} for i in my_list: count[i] = count.get(i, 0) + 1 return count n = int(input()) l = list(map(int, input().split())) s,f = sum(l), freq(l) for _ in range(int(input())): x, y = map(int, input().split()) if x in f: v = f[x] if y in f: ...
[["+", 64, 196, 0, 1, 0, 652, 63, 319, 500, 22], ["+", 64, 196, 0, 1, 0, 652, 63, 319, 0, 131], ["+", 64, 196, 0, 1, 0, 652, 63, 319, 319, 22], ["+", 64, 196, 0, 1, 0, 652, 3, 4, 0, 24], ["+", 64, 196, 0, 1, 0, 652, 3, 4, 0, 22], ["+", 64, 196, 0, 1, 0, 652, 3, 4, 0, 25]]
5
147
#include <bits/stdc++.h> #define FOR(i, a, b) for (int i = a; i <= b; i++) #define LL long long using namespace std; const int N = 1e5 + 10; int n, q; int a[N]; map<int, int> mp; LL sum = 0; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen("ch.inp","r",stdin) ; cin >> n; FOR(i, 1, n...
#include <bits/stdc++.h> #define FOR(i, a, b) for (int i = a; i <= b; i++) #define LL long long using namespace std; const int N = 1e5 + 10; int n, q; int a[N]; map<int, int> mp; LL sum = 0; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen("ch.inp","r",stdin) ; cin >> n; FOR(i, 1, n...
[["-", 8, 9, 0, 9, 0, 1, 0, 11, 17, 32], ["+", 8, 9, 0, 9, 0, 1, 0, 11, 17, 107]]
1
179
N = gets.to_i A = Arrey.new(100001, 0) sum = 0 line = gets.split(' ').map(&:to_i) for num in 0..N-1 do n = line[num] A[n] += 1 sum += n end Q = gets.to_i q_line = [] for num in 0..Q-1 do q_line = gets.chomp.split(' ').map(&:to_i) B = q_line[0] C = q_line[1] b = A[B].to_i A[B] = 0 ...
N = gets.to_i A = Array.new(100001, 0) sum = 0 line = gets.split(' ').map(&:to_i) for num in 0..N-1 do n = line[num] A[n] += 1 sum += n end Q = gets.to_i q_line = [] for num in 0..Q-1 do q_line = gets.chomp.split(' ').map(&:to_i) B = q_line[0] C = q_line[1] b = A[B].to_i A[B] = 0 ...
[["-", 36, 36, 0, 493, 0, 662, 12, 652, 486, 743], ["+", 36, 36, 0, 493, 0, 662, 12, 652, 486, 743]]
4
139
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> vec(n + 1); vec[0] = 0; vector<int> a(n + 1, 0); int sum = 0; for (int i = 1; i <= n; i++) { cin >> vec[i]; a[vec[i]]++; sum += vec[i]; } int q; cin >> q; for (int i = 1; i <= q; i++) { vector...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> vec(n + 1); vec[0] = 0; vector<int> a(100001, 0); long long sum = 0; for (int i = 1; i <= n; i++) { cin >> vec[i]; a[vec[i]]++; sum += vec[i]; } int q; cin >> q; for (int i = 1; i <= q; i++) { ...
[["-", 0, 43, 49, 50, 51, 4, 0, 16, 31, 22], ["-", 0, 43, 49, 50, 51, 4, 0, 16, 17, 72], ["-", 0, 43, 49, 50, 51, 4, 0, 16, 12, 13], ["+", 8, 9, 0, 43, 49, 50, 51, 4, 0, 13], ["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 14, 8, 9, 0, 43, 39, 86, 0, 96]]
1
194
class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = ...
class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = ...
[["+", 0, 57, 64, 196, 0, 1, 0, 652, 63, 22], ["+", 64, 196, 0, 1, 0, 652, 3, 4, 0, 24], ["+", 64, 196, 0, 1, 0, 652, 3, 4, 0, 22], ["+", 64, 196, 0, 1, 0, 652, 3, 4, 0, 25]]
5
506
n=int(input()) a = list(map(int,input().split())) q=int(input()) bc = [list(map(int, input().split())) for l in range(q)] cnt=[0]*100001 Sum=0 for i in range(n): cnt[a[i]]+=1 Sum+=a[i] for i in range(q): Sum+=(bc[i][1]-bc[i][0])*cnt[bc[i][1]] cnt[bc[i][1]]+=cnt[bc[i][0]] cnt[bc[i][0...
n=int(input()) a = list(map(int,input().split())) q=int(input()) bc = [list(map(int, input().split())) for l in range(q)] cnt=[0]*100001 Sum=0 for i in range(n): cnt[a[i]]+=1 Sum+=a[i] for i in range(q): Sum+=(bc[i][1]-bc[i][0])*cnt[bc[i][0]] cnt[bc[i][1]]+=cnt[bc[i][0]] cnt[bc[i][0...
[["-", 0, 677, 12, 657, 12, 206, 206, 206, 206, 612], ["+", 0, 677, 12, 657, 12, 206, 206, 206, 206, 612]]
5
167
import math import sys import collections import bisect readline = sys.stdin.readline def main(): n = int(readline().rstrip()) A = list(map(int, readline().rstrip().split())) counter = collections.Counter(A) q = int(readline().rstrip()) BCList = [list(map(int, readline().rstrip().split())) for _ i...
import math import sys import collections import bisect readline = sys.stdin.readline def main(): n = int(readline().rstrip()) A = list(map(int, readline().rstrip().split())) counter = collections.Counter(A) q = int(readline().rstrip()) BCList = [list(map(int, readline().rstrip().split())) for _ i...
[["+", 0, 57, 64, 196, 0, 1, 0, 652, 63, 22], ["+", 64, 196, 0, 1, 0, 652, 3, 4, 0, 24], ["+", 64, 196, 0, 1, 0, 652, 3, 4, 0, 22], ["+", 64, 196, 0, 1, 0, 652, 3, 4, 0, 25]]
5
228
from collections import Counter N = int(input()) A = list(map(int,input().split())) Q = int(input()) counter = Counter(A) sum_res = sum(A) for _ in range(Q): bf,af = map(int,input().split()) sum_res -= bf*counter[bf] sum_res += af*counter[af] counter[af] += counter[bf] counter[bf] = 0 ...
from collections import Counter N = int(input()) A = list(map(int,input().split())) Q = int(input()) counter = Counter(A) sum_res = sum(A) #print(sum_res,counter) for _ in range(Q): bf,af = map(int,input().split()) sum_res -= bf*counter[bf] sum_res += af*counter[bf] counter[af] += counter[bf] ...
[["-", 0, 1, 0, 677, 12, 657, 12, 206, 206, 22], ["+", 0, 1, 0, 677, 12, 657, 12, 206, 206, 22]]
5
108
n=int(input()) a=list(map(int,input().split())) q=int(input()) dic = {} ans = 0 for x in a: if x not in dic: dic[x] = 1 else: dic[x]+=1 ans += x for _ in range(q): b,c=map(int,input().split()) if b not in dic:continue ans += (c-b)*dic[b] if c not in dic: dic[c] = d...
n=int(input()) a=list(map(int,input().split())) q=int(input()) dic = {} ans = 0 for x in a: if x not in dic: dic[x] = 1 else: dic[x]+=1 ans += x for _ in range(q): b,c=map(int,input().split()) if b not in dic: print(ans) continue ans += (c-b)*dic[b] if c no...
[["+", 0, 57, 64, 196, 0, 1, 0, 652, 63, 22], ["+", 64, 196, 0, 1, 0, 652, 3, 4, 0, 24], ["+", 64, 196, 0, 1, 0, 652, 3, 4, 0, 22], ["+", 64, 196, 0, 1, 0, 652, 3, 4, 0, 25]]
5
147
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int64_t> vec(N); for (int i = 0; i < N; i++) { cin >> vec[i]; } int64_t sum = 0; for (int i = 2; i < N; i++) { sum ^= vec[i]; } int64_t two = vec[0] + vec[1]; bool flag = true; if (two < sum) { flag = ...
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int64_t> vec(N); for (int i = 0; i < N; i++) { cin >> vec[i]; } int64_t sum = 0; for (int i = 2; i < N; i++) { sum ^= vec[i]; } int64_t two = vec[0] + vec[1]; bool flag = true; if (two < sum) { flag = ...
[["-", 15, 339, 51, 2, 3, 4, 0, 16, 17, 72], ["+", 15, 339, 51, 2, 3, 4, 0, 16, 17, 33]]
1
325
#include <bits/stdc++.h> typedef long long ll; const int N = 305; inline void up(int &x, int y) { x < y ? x = y : 0; } inline void down(int &x, int y) { x > y ? x = y : 0; } inline int max(const int x, const int y) { return x > y ? x : y; } inline int min(const int x, const int y) { return x < y ? x : y; } int n; ll ...
#include <bits/stdc++.h> typedef long long ll; const int N = 305; inline void up(int &x, int y) { x < y ? x = y : 0; } inline void down(int &x, int y) { x > y ? x = y : 0; } inline int max(const int x, const int y) { return x > y ? x : y; } inline int min(const int x, const int y) { return x < y ? x : y; } int n; ll ...
[["+", 51, 91, 28, 23, 0, 16, 31, 16, 17, 20], ["+", 51, 91, 28, 23, 0, 16, 31, 16, 12, 13]]
1
373
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define SZ(x) (int)x.size() #define ll long long #define MP make_pair #define pb push_back #define pq priority_queue #define pii pair<int, int> #define mod 998244353 #define inf 0x3f3f3f3f #define debug(x) cerr << #x << "=" << x << '\n' #...
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define SZ(x) (int)x.size() #define ll long long #define MP make_pair #define pb push_back #define pq priority_queue #define pii pair<int, int> #define mod 998244353 #define inf 0x3f3f3f3f #define debug(x) cerr << #x << "=" << x << '\n' #...
[["-", 36, 36, 0, 30, 0, 43, 49, 80, 81, 13], ["+", 36, 36, 0, 30, 0, 43, 49, 80, 81, 13], ["-", 0, 11, 31, 69, 28, 2, 3, 4, 0, 13], ["+", 0, 11, 31, 69, 28, 2, 3, 4, 0, 13]]
1
573
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll n, a1, a2, ai, sum, x, half; int main() { cin >> n; cin >> a1 >> a2; sum = a1 + a2; for (ll i = 2; i < n; i++) scanf("%lld", &ai), x ^= ai; if ((sum - x) % 2 || sum < x) { // a+b=a^b+(a&b)*2 puts("-1"); return 0; } half =...
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll n, a1, a2, ai, sum, x, half; int main() { cin >> n; cin >> a1 >> a2; sum = a1 + a2; for (ll i = 2; i < n; i++) scanf("%lld", &ai), x ^= ai; if ((sum - x) % 2 || sum < x) { // a+b=a^b+(a&b)*2 puts("-1"); return 0; } half =...
[["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 106], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 67], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 22]]
1
207
#include <algorithm> #include <assert.h> #include <bitset> #include <cmath> #include <cstdlib> #include <fstream> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <vector> using namespace std; typedef long long ...
#include <algorithm> #include <assert.h> #include <bitset> #include <cmath> #include <cstdlib> #include <fstream> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <vector> using namespace std; typedef long long ...
[["-", 0, 57, 15, 339, 51, 16, 31, 16, 12, 22], ["-", 0, 9, 0, 57, 15, 339, 51, 16, 17, 98], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 31, 22], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 19]]
1
670
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; using PP = pair<int, P>; #define rep1(i, n) for (int i = 1; i <= n; i++) #define rep0(i, n) for (int i = 0; i < n; i++) #define chmin(a, b) \ if ((a) > (b)) { ...
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; using PP = pair<int, P>; #define rep1(i, n) for (int i = 1; i <= n; i++) #define rep0(i, n) for (int i = 0; i < n; i++) #define chmin(a, b) \ if ((a) > (b)) { ...
[["-", 0, 41, 15, 23, 0, 16, 31, 16, 17, 47], ["-", 0, 41, 15, 23, 0, 16, 31, 16, 12, 13], ["-", 12, 23, 0, 41, 15, 23, 0, 16, 17, 98], ["-", 0, 41, 15, 23, 0, 16, 12, 16, 31, 22]]
1
396
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll n; int main() { cin >> n; ll a[n + 1], kanan = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; if (i > 2) kanan = (kanan ^ a[i]); } ll x = a[1] + a[2] - kanan, awal = a[1]; if (x % 2 == 1 || x < 0) { cout << -1 << endl...
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll n; int main() { cin >> n; ll a[n + 1], kanan = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; if (i > 2) kanan = (kanan ^ a[i]); } ll x = a[1] + a[2] - kanan, awal = a[1]; if (x % 2 == 1 || x < 0) { cout << -1 << endl...
[["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 106], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 47], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 22]]
1
255
#include <bits/stdc++.h> using namespace std; ////////////////////////////// Begin Macros #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define in(x, a, b) (a <= x and x < b) #define rep(i, N) for (int i = 0; i < (int)(N); i++) #define reprev(i, N) for (int i = (int)(N)-1; i >= 0; i...
#include <bits/stdc++.h> using namespace std; ////////////////////////////// Begin Macros #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define in(x, a, b) (a <= x and x < b) #define rep(i, N) for (int i = 0; i < (int)(N); i++) #define reprev(i, N) for (int i = (int)(N)-1; i >= 0; i...
[["-", 0, 43, 49, 50, 51, 16, 12, 16, 31, 13], ["+", 0, 43, 49, 50, 51, 16, 12, 16, 31, 13]]
1
1,539
#include <algorithm> #include <iostream> #include <string> using namespace std; int N; long long A[330]; bool exist = true; int main(void) { cin >> N; for (int i = 1; i <= N; i++) cin >> A[i]; long long S = A[1] + A[2]; long long X = 0; for (int i = 1; i <= N; i++) { X = X ^ A[i]; } X = X ^ (A[...
#include <algorithm> #include <iostream> #include <string> using namespace std; int N; long long A[330]; bool exist = true; int main(void) { cin >> N; for (int i = 1; i <= N; i++) cin >> A[i]; long long S = A[1] + A[2]; long long X = 0; for (int i = 1; i <= N; i++) { X = X ^ A[i]; } X = X ^ (A[...
[["+", 15, 339, 51, 16, 31, 16, 31, 23, 0, 24], ["+", 15, 339, 51, 16, 31, 16, 31, 23, 0, 25], ["+", 15, 339, 51, 16, 12, 16, 31, 23, 0, 24], ["+", 15, 339, 51, 16, 12, 16, 31, 23, 0, 25]]
1
283
#pragma GCC target("avx2") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("O3") #include "bits/stdc++.h" #include <random> #include <unordered_map> #include <unordered_set> using namespace std; typedef long long ll; const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/ #define pb push_back #define mp make_pair ...
#pragma GCC target("avx2") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("O3") #include "bits/stdc++.h" #include <random> #include <unordered_map> #include <unordered_set> using namespace std; typedef long long ll; const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/ #define pb push_back #define mp make_pair ...
[["+", 0, 9, 0, 57, 15, 339, 51, 16, 17, 106], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 47], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 22]]
1
295
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <unordered_map> #include <vector> // #include <bits/stdc++.h> #define ALL(x) (x).begin(), (x).en...
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <unordered_map> #include <vector> // #include <bits/stdc++.h> #define ALL(x) (x).begin(), (x).en...
[["-", 0, 57, 15, 339, 51, 16, 31, 16, 17, 20], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 47]]
1
1,052
#include <bits/stdc++.h> #define int long long using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) typedef pair<int, int> pii; const int INF = 1l << 60; signed main() { int N; cin >> N; int A1max, a2, S, X = 0; cin >> A1max >> a2; S = A1max + a2; rep(i, N - 2) { int a; cin >> a; ...
#include <bits/stdc++.h> #define int long long using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) typedef pair<int, int> pii; const int INF = 1l << 60; signed main() { int N; cin >> N; int A1max, a2, S, X = 0; cin >> A1max >> a2; S = A1max + a2; rep(i, N - 2) { int a; cin >> a; ...
[["-", 0, 57, 15, 339, 51, 16, 12, 16, 31, 22], ["+", 15, 339, 51, 16, 12, 16, 31, 23, 0, 24], ["+", 51, 16, 12, 16, 31, 23, 0, 16, 31, 22], ["+", 51, 16, 12, 16, 31, 23, 0, 16, 17, 33], ["+", 51, 16, 12, 16, 31, 23, 0, 16, 12, 22], ["+", 15, 339, 51, 16, 12, 16, 31, 23, 0, 25]]
1
215
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll Xor, A[2], Ans; inline void pre() { ll N, Tmp; cin >> N >> A[0] >> A[1]; for (int i = 3; i <= N; i++) cin >> Tmp, Xor ^= Tmp; } inline bool alw() { if (A[0] + A[1] - Xor < 0 || (A[0] + A[1] - Xor & 1)) return 0; ll B[2] = {A[0] + A...
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll Xor, A[2], Ans; inline void pre() { ll N, Tmp; cin >> N >> A[0] >> A[1]; for (int i = 3; i <= N; i++) cin >> Tmp, Xor ^= Tmp; } inline bool alw() { if (A[0] + A[1] - Xor < 0 || (A[0] + A[1] - Xor & 1)) return 0; ll B[2] = {A[0] + A...
[["+", 0, 57, 15, 339, 51, 16, 31, 23, 0, 24], ["-", 15, 339, 51, 16, 12, 16, 31, 23, 0, 24]]
1
298
#include <iostream> using namespace std; int N; long A, B, X; main() { cin >> N >> A >> B; for (int i = 2; i < N; i++) { long x; cin >> x; X ^= x; } long S = A + B; if (S < X || (S - X) % 2 == 1) { cout << -1 << endl; return 0; } long D = (S - X) / 2; if (D > A || D & X) { cout <...
#include <iostream> using namespace std; int N; long A, B, X; main() { cin >> N >> A >> B; for (int i = 2; i < N; i++) { long x; cin >> x; X ^= x; } long S = A + B; if (S < X || (S - X) % 2 == 1) { cout << -1 << endl; return 0; } long D = (S - X) / 2; if (D > A || D & X) { cout <...
[["-", 12, 16, 31, 23, 0, 16, 12, 16, 31, 13], ["+", 12, 16, 31, 23, 0, 16, 12, 16, 31, 13], ["-", 0, 57, 64, 1, 0, 11, 12, 16, 31, 13], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 31, 13]]
1
178
#include <bits/stdc++.h> #define endl "\n" using namespace std; typedef long long int lli; const lli N = 41; lli tot[N], s, x, ans; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); lli n; cin >> n; lli i, a[n]; for (i = 0; i < n; i++) cin >> a[i]; s = a[0] + a[1]; for (i = 2; i < ...
#include <bits/stdc++.h> #define endl "\n" using namespace std; typedef long long int lli; const lli N = 61; lli tot[N], s, x, ans; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); lli n; cin >> n; lli i, a[n]; for (i = 0; i < n; i++) cin >> a[i]; s = a[0] + a[1]; for (i = 2; i < ...
[["-", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13], ["+", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 106], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 22]]
1
306
#include <algorithm> #include <iostream> #include <stdlib.h> #include <string> #define ll long long using namespace std; const ll N = 305; ll a[N]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; ll X = 0, D; cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i]; if (...
#include <algorithm> #include <iostream> #include <stdlib.h> #include <string> #define ll long long using namespace std; const ll N = 305; ll a[N]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; ll X = 0, D; cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i]; if (...
[["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 18], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 19], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 20], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 47]]
1
286
eval"X,Y,*A=#"+`tr ' ' ,` b=X+Y-a=A.inject(0,:^) r=b/2 50.downto(0){|i|r+2**i>X||r|=a[i]<<i} p r<1||b/2&a|b%2>0?-1:X-r
eval"X,Y,*A=#"+`tr ' ' ,` b=X+Y-a=A.inject(0,:^) r=b/2 50.downto(0){|i|r+2**i>X||r|=a[i]<<i} p r<1||r>X||b/2&a|b%2>0?-1:X-r
[["+", 0, 754, 15, 738, 31, 738, 12, 738, 31, 22], ["+", 0, 754, 15, 738, 31, 738, 12, 738, 17, 47], ["+", 0, 754, 15, 738, 31, 738, 12, 738, 12, 743], ["+", 0, 652, 3, 4, 0, 754, 15, 738, 17, 106]]
4
79
#include <bits/stdc++.h> #define LL long long #define PII pair<int, int> #define PIL pair<int, LL> #define PLI pair<LL, int> #define PIII pair<int, PII> #define PLL pair<LL, LL> #define PLII pair<LL, PII> #define VI vector<int> #define VVI vector<VI> #define VL vector<LL> #define VVL vector<VL> #define VPII vector<PII>...
#include <bits/stdc++.h> #define LL long long #define PII pair<int, int> #define PIL pair<int, LL> #define PLI pair<LL, int> #define PIII pair<int, PII> #define PLL pair<LL, LL> #define PLII pair<LL, PII> #define VI vector<int> #define VVI vector<VI> #define VL vector<LL> #define VVL vector<VL> #define VPII vector<PII>...
[["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 18], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 19]]
1
526
n = int(input()) l = list(map(int,input().split())) x = 0 s = l[0]+l[1] for i in l[2:]: x ^= i if x > s or (s-x)%2 or ((s-x)//2)&x: print(-1) exit() a = (s-x)//2 if a > l[0]: print(-1) for i in range(50,-1,-1): if 1<<i & x: if a+ (1<<i) <= l[0]: a += 1<<i if a == 0: print(-1...
n = int(input()) l = list(map(int,input().split())) x = 0 s = l[0]+l[1] for i in l[2:]: x ^= i if x > s or (s-x)%2 or ((s-x)//2)&x: print(-1) exit() a = (s-x)//2 if a > l[0]: print(-1) exit() for i in range(50,-1,-1): if 1<<i & x: if a+ (1<<i) <= l[0]: a += 1<<i if a == 0: ...
[["+", 0, 57, 64, 196, 0, 1, 0, 652, 63, 22], ["+", 64, 196, 0, 1, 0, 652, 3, 4, 0, 24], ["+", 64, 196, 0, 1, 0, 652, 3, 4, 0, 25]]
5
167
#include <bits/stdc++.h> using namespace std; #define FOR(i, n) for (int i = 0; i < (int)n; i++) #define PB push_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define F first #define S second typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pii; const int MOD = 1e9 ...
#include <bits/stdc++.h> using namespace std; #define FOR(i, n) for (int i = 0; i < (int)n; i++) #define PB push_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define F first #define S second typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pii; const int MOD = 1e9 ...
[["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 106], ["+", 0, 57, 15, 339, 51, 16, 12, 23, 0, 24], ["+", 15, 339, 51, 16, 12, 23, 0, 16, 31, 22], ["+", 15, 339, 51, 16, 12, 23, 0, 16, 17, 67], ["+", 15, 339, 51, 16, 12, 23, 0, 16, 12, 22], ["+", 0, 57, 15, 339, 51, 16, 12, 23, 0, 25]]
1
374
#include <bits/stdc++.h> #define ll long long #define pii_ pair<int, int> #define mp_ make_pair #define pb push_back #define fi first #define se second #define rep(i, a, b) for (int i = (a); i <= (b); i++) #define per(i, a, b) for (int i = (a); i >= (b); i--) #define show1(a) cout << #a << " = " << a << endl #define sh...
#include <bits/stdc++.h> #define ll long long #define pii_ pair<int, int> #define mp_ make_pair #define pb push_back #define fi first #define se second #define rep(i, a, b) for (int i = (a); i <= (b); i++) #define per(i, a, b) for (int i = (a); i >= (b); i--) #define show1(a) cout << #a << " = " << a << endl #define sh...
[["-", 0, 57, 15, 339, 51, 16, 12, 23, 0, 24], ["-", 0, 14, 8, 9, 0, 57, 15, 339, 0, 25], ["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 0, 7, 8, 9, 0, 57, 15, 339, 0, 24], ["+", 0, 57, 15, 339, 51, 16, 31, 23, 0, 25]]
1
311
//雪花飄飄北風嘯嘯 //天地一片蒼茫 #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/rope> using namespace std; using namespace __gnu_pbds; using namespace __gnu_cxx; #define ll long long #define ii pair<ll, ll> #define iii pair<ii, ll> #define fi first #define se se...
//雪花飄飄北風嘯嘯 //天地一片蒼茫 #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/rope> using namespace std; using namespace __gnu_pbds; using namespace __gnu_cxx; #define ll long long #define ii pair<ll, ll> #define iii pair<ii, ll> #define fi first #define se se...
[["-", 0, 57, 64, 9, 0, 1, 0, 16, 17, 72], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 17, 107]]
1
427
#include "algorithm" #include "bitset" #include "cassert" #include "climits" #include "cmath" #include "cstdio" #include "ctime" #include "functional" #include "iomanip" #include "iostream" #include "list" #include "map" #include "numeric" #include "queue" #include "random" #include "set" #include "stack" #include "str...
#include "algorithm" #include "bitset" #include "cassert" #include "climits" #include "cmath" #include "cstdio" #include "ctime" #include "functional" #include "iomanip" #include "iostream" #include "list" #include "map" #include "numeric" #include "queue" #include "random" #include "set" #include "stack" #include "str...
[["-", 64, 9, 0, 43, 49, 50, 51, 2, 63, 22], ["+", 64, 9, 0, 43, 49, 50, 51, 2, 63, 22]]
1
637
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) ll ans = 0; int main() { ll n; cin >> n; vector<ll> aa(n); ll c = 0; rep(i, n) { cin >> aa[i]; if (i > 1) c ^= aa[i]; } ll sum = aa[0] + aa[1] - c; ll a = 0, b = c; if ...
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) ll ans = 0; int main() { ll n; cin >> n; vector<ll> aa(n); ll c = 0; rep(i, n) { cin >> aa[i]; if (i > 1) c ^= aa[i]; } ll sum = aa[0] + aa[1] - c; ll a = 0, b = c; if ...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47]]
1
325
#include <bits/stdc++.h> using namespace std; using ll = long long; void solve() { int n; cin >> n; ll A, B, C = 0; cin >> A >> B; for (int i = 3; i <= n; i++) { ll x; cin >> x; C ^= x; } ll S = A + B; if (S < C || ((S - C) & 1)) { cout << -1; return; } ll D = (S - C) / 2; if...
#include <bits/stdc++.h> using namespace std; using ll = long long; void solve() { int n; cin >> n; ll A, B, C = 0; cin >> A >> B; for (int i = 3; i <= n; i++) { ll x; cin >> x; C ^= x; } ll S = A + B; if (S < C || ((S - C) & 1)) { cout << -1; return; } ll D = (S - C) / 2; if...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 22]]
1
242
import sys N, = map(int, input().split()) X = list(map(int, input().split())) S = X[0]+X[1] T = 0 for i in range(2, N): T ^= X[i] if S<T or (S-T)%2: print(-1) sys.exit() D = (S-T)//2 if D&T: print(-1) sys.exit() Y = D for i in range(T.bit_length()+1, -1, -1): if T&(1<<i)|Y <= X[0]: Y |...
import sys N, = map(int, input().split()) X = list(map(int, input().split())) S = X[0]+X[1] T = 0 for i in range(2, N): T ^= X[i] if S<T or (S-T)%2: print(-1) sys.exit() D = (S-T)//2 if D&T: print(-1) sys.exit() Y = D for i in range(T.bit_length()+1, -1, -1): if T&(1<<i)|Y <= X[0]: Y |...
[["+", 64, 196, 0, 1, 0, 677, 12, 657, 31, 22], ["+", 64, 196, 0, 1, 0, 677, 12, 657, 17, 67], ["+", 0, 1, 0, 677, 12, 657, 12, 23, 0, 24], ["+", 0, 1, 0, 677, 12, 657, 12, 23, 0, 25]]
5
181
N, = map(int, input().split()) X = list(map(int, input().split())) t = 0 for x in X: t = t^x inf = float('inf') d = dict() def it(x, y, z): if (x, y, z) in d: return d[(x, y, z)] xm, ym, zm = x%2, y%2, z%2 if xm ^ ym != zm: d[(x, y, z)] = inf return inf if x^y == z: d...
N, = map(int, input().split()) X = list(map(int, input().split())) t = 0 for x in X: t = t^x inf = float('inf') d = dict() def it(x, y, z): if (x, y, z) in d: return d[(x, y, z)] xm, ym, zm = x%2, y%2, z%2 if xm ^ ym != zm: d[(x, y, z)] = inf return inf if x^y == z: d...
[["-", 36, 36, 0, 656, 0, 57, 15, 666, 667, 18], ["+", 36, 36, 0, 656, 0, 57, 15, 666, 667, 19]]
5
270
#include <bits/stdc++.h> using namespace std; #define DEBUG(x) cerr << #x << ": " << x << endl; #define DEBUG_VEC(v) \ cerr << #v << ":"; \ for (int i = 0; i < v.size(); i++) ...
#include <bits/stdc++.h> using namespace std; #define DEBUG(x) cerr << #x << ": " << x << endl; #define DEBUG_VEC(v) \ cerr << #v << ":"; \ for (int i = 0; i < v.size(); i++) ...
[["-", 64, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["+", 64, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["-", 0, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["+", 0, 9, 0, 57, 15, 339, 51, 16, 31, 22]]
1
698
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; using ll = long long; using u64 = uint_fast64_t; using pii = pair<int, int>; using pll = pair<long long, long long>; #define rep(i, n) for...
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; using ll = long long; using u64 = uint_fast64_t; using pii = pair<int, int>; using pll = pair<long long, long long>; #define rep(i, n) for...
[["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 20], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 47], ["-", 64, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 64, 9, 0, 57, 15, 339, 51, 16, 17, 19]]
1
462
#include <bits/stdc++.h> #define ll long long #define ld long double #define mk make_pair #define fi first #define se second #define vll vector<ll> #define pii pair<ll, ll> #define vvll vector<vector<ll>> #define pb push_back #define sz(v) (ll)(v).size() #define inf 1e18 #define md 1000000007 #define all(v) (v).begin()...
#include <bits/stdc++.h> #define ll long long #define ld long double #define mk make_pair #define fi first #define se second #define vll vector<ll> #define pii pair<ll, ll> #define vvll vector<vector<ll>> #define pb push_back #define sz(v) (ll)(v).size() #define inf 1e18 #define md 1000000007 #define all(v) (v).begin()...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 20], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 354], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 18], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13]]
1
433
import sys readline = sys.stdin.readline readall = sys.stdin.read ns = lambda: readline().rstrip() ni = lambda: int(readline().rstrip()) nm = lambda: map(int, readline().split()) nl = lambda: list(map(int, readline().split())) prn = lambda x: print(*x, sep='\n') def solve(): n = ni() f, s, *a = nm() x = 0...
import sys readline = sys.stdin.readline readall = sys.stdin.read ns = lambda: readline().rstrip() ni = lambda: int(readline().rstrip()) nm = lambda: map(int, readline().split()) nl = lambda: list(map(int, readline().split())) prn = lambda x: print(*x, sep='\n') def solve(): n = ni() f, s, *a = nm() x = 0...
[["-", 8, 196, 0, 57, 15, 679, 12, 666, 667, 18], ["+", 8, 196, 0, 57, 15, 679, 12, 666, 667, 19], ["+", 0, 652, 3, 4, 0, 41, 0, 666, 0, 22], ["+", 0, 652, 3, 4, 0, 41, 0, 666, 667, 20]]
5
220
#include <algorithm> #include <cmath> #include <functional> #include <iostream> #include <map> #include <queue> #include <string> #include <vector> using namespace std; #pragma warning(disable : 4996) long long INF = (1LL << 60); long long N, A[1 << 18]; long long X, Y, Z; long long dp[55][2][2]; int main() { cin >...
#include <algorithm> #include <cmath> #include <functional> #include <iostream> #include <map> #include <queue> #include <string> #include <vector> using namespace std; #pragma warning(disable : 4996) long long INF = (1LL << 60); long long N, A[1 << 18]; long long X, Y, Z; long long dp[55][2][2]; int main() { cin >...
[["-", 3, 4, 0, 69, 28, 69, 341, 342, 0, 13], ["+", 3, 4, 0, 69, 28, 69, 341, 342, 0, 13], ["-", 51, 2, 3, 4, 0, 69, 341, 342, 0, 13], ["+", 51, 2, 3, 4, 0, 69, 341, 342, 0, 13]]
1
915
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define srep(i, s, t) for (int i = s; i < t; ++i) #define drep(i, n) for (int i = (n)-1; i >= 0; --i) using namespace std; typedef long long int ll; typedef pair<int, int> P; #define yn ...
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define srep(i, s, t) for (int i = s; i < t; ++i) #define drep(i, n) for (int i = (n)-1; i >= 0; --i) using namespace std; typedef long long int ll; typedef pair<int, int> P; #define yn ...
[["-", 64, 9, 0, 1, 0, 11, 12, 16, 31, 13], ["+", 64, 9, 0, 1, 0, 11, 12, 16, 31, 13]]
1
347
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define all(v) v.begin(), v.end() #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define Rep(n) for (ll _ = 0; _ < (ll)(n); _++) #define fs first #define sc second template <class S> S sum(vector<S> &...
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define all(v) v.begin(), v.end() #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define Rep(n) for (ll _ = 0; _ < (ll)(n); _++) #define fs first #define sc second template <class S> S sum(vector<S> &...
[["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 106], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 47], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 22], ["-", 64, 9, 0, 1, 0, 11, 12, 16, 17, 139], ["+", 64, 9, 0, 1, 0, 11, 12, 16, 17, 72]]
1
539
#include <bits/stdc++.h> using namespace std; const int N = 303; int n; long long a[N]; int solve() { scanf("%d", &n); for (int i = 0; i < n; ++i) scanf("%lld", &a[i]); long long sum = 0; for (int i = 2; i < n; ++i) sum ^= a[i]; long long t = ((a[0] + a[1]) - sum); if (t < 0 || (t & 1)) re...
#include <bits/stdc++.h> using namespace std; const int N = 303; int n; long long a[N]; int solve() { scanf("%d", &n); for (int i = 0; i < n; ++i) scanf("%lld", &a[i]); long long sum = 0; for (int i = 2; i < n; ++i) sum ^= a[i]; long long t = ((a[0] + a[1]) - sum); if (t < 0 || (t & 1)) re...
[["-", 64, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 64, 9, 0, 57, 15, 339, 51, 16, 12, 13]]
1
375
#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 = 1LL << 61; int main() { ll n; cin >> n; vec a(n); ll x = 0; for (ll i = 0; i < n; i++) { cin >> ...
#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 = 1LL << 61; int main() { ll n; cin >> n; vec a(n); ll x = 0; for (ll i = 0; i < n; i++) { cin >> ...
[["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 20], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 47], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19]]
1
245
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll, ll> P; typedef vector<ll> VI; typedef vector<VI> VVI; const ll MOD = 1000000007; const ll INF = 4611686018427387903; #define REP(i, n) for (int i = 0; i < n; i++) #define ALL(v) v.begin(), v.end() int main() { ll n; cin >> n; ...
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll, ll> P; typedef vector<ll> VI; typedef vector<VI> VVI; const ll MOD = 1000000007; const ll INF = 4611686018427387903; #define REP(i, n) for (int i = 0; i < n; i++) #define ALL(v) v.begin(), v.end() int main() { ll n; cin >> n; ...
[["+", 0, 9, 0, 57, 15, 339, 51, 16, 17, 106], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 47], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 22]]
1
304
#include <bits/stdc++.h> using namespace std; typedef long long ll; // int:2*10**9 typedef long double ld; typedef pair<ll, ll> P; #define REP(i, n) for (ll i = 0; i < (ll)(n); i++) #define REPS(i, n) for (ll i = 1; i <= (ll)(n); i++) #define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--) #define FOR(i, a, b) for (ll i...
#include <bits/stdc++.h> using namespace std; typedef long long ll; // int:2*10**9 typedef long double ld; typedef pair<ll, ll> P; #define REP(i, n) for (ll i = 0; i < (ll)(n); i++) #define REPS(i, n) for (ll i = 1; i <= (ll)(n); i++) #define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--) #define FOR(i, a, b) for (ll i...
[["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 79], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13]]
1
373
n = gets.chomp.to_i raw_as = gets.chomp.split.map(&:to_i) Q = gets.chomp.to_i bs = [] cs = [] ss = [] Q.times do b, c = gets.chomp.split.map(&:to_i) bs << b; cs << c end a_sum = raw_as.inject(:+) as = {} raw_as.each do |a| as[a] ||= 0 as[a] += 1 end bs.each_with_index do |bi, i| a_sum += as[bi].nil? ? 0 : (...
n = gets.chomp.to_i raw_as = gets.chomp.split.map(&:to_i) Q = gets.chomp.to_i bs = [] cs = [] ss = [] Q.times do b, c = gets.chomp.split.map(&:to_i) bs << b; cs << c end a_sum = raw_as.inject(:+) as = {} raw_as.each do |a| as[a] ||= 0 as[a] += 1 end bs.each_with_index do |bi, i| a_sum += as[bi].nil? ? 0 : ...
[["+", 196, 737, 8, 736, 0, 755, 12, 738, 17, 106], ["+", 196, 737, 8, 736, 0, 755, 12, 738, 12, 612]]
4
166
#include <iostream> #include <map> #include <vector> using namespace std; std::vector<long long> replacing(int n, int a[], int q, int b[], int c[]) { map<int, long long> counter; long long sum = 0; for (int i = 0; i < n; i++) { sum += a[i]; counter[a[i]] += 1; } vector<long long> ans; for (int i = ...
#include <iostream> #include <map> #include <vector> using namespace std; std::vector<long long> replacing(int n, int a[], int q, int b[], int c[]) { map<int, long long> counter; long long sum = 0; for (int i = 0; i < n; i++) { sum += a[i]; counter[a[i]] += 1; } vector<long long> ans; for (int i = ...
[["+", 0, 7, 8, 9, 0, 1, 0, 16, 17, 151], ["+", 0, 7, 8, 9, 0, 1, 0, 16, 12, 22]]
1
335
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.HashMap; import java.util.Map; import java.util.NoSuchElementException; public class Main { public static void main(String[] args) { new Main().solve(); pw.close(); } /** * ASCII * 0 48 * A 65 ...
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.HashMap; import java.util.Map; import java.util.NoSuchElementException; public class Main { public static void main(String[] args) { new Main().solve(); pw.close(); } /** * ASCII * 0 48 * A 65 ...
[["-", 8, 196, 0, 503, 49, 200, 51, 492, 141, 22], ["+", 8, 196, 0, 503, 49, 200, 51, 492, 141, 22]]
3
2,488
#include <algorithm> #include <chrono> #include <cstdio> #include <iostream> #include <set> #include <string> #include <unordered_map> #include <vector> using namespace std; int main() { int n, q, ans = 0; scanf("%d", &n); unordered_map<int, int> mp; vector<int> a(n); for (int i = 0; i < n; i++) { scanf...
#include <algorithm> #include <chrono> #include <cstdio> #include <iostream> #include <set> #include <string> #include <unordered_map> #include <vector> using namespace std; int main() { int n, q; long long ans = 0; scanf("%d", &n); unordered_map<int, int> mp; vector<int> a(n); for (int i = 0; i < n; i++)...
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 0, 21], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 0, 35], ["+", 0, 14, 8, 9, 0, 43, 39, 86, 0, 96], ["+", 0, 7, 8, 9, 0, 1, 0, 16, 17, 151], ["+", 0, 7, 8, 9, 0, 1, 0, 16, 12, 22]]
1
190
n = int(input()) a =list(map(int,input().split())) s =sum(a) x = [0]*100001 for i in a: x[i] += 1 q = int(input()) for i in range(q): b,c = map(int,input().split()) s -= b*x[b] s += c*x[c] x[c] += x[b] x[b] = 0 print(s)
n = int(input()) a =list(map(int,input().split())) s =sum(a) x = [0]*1000001 for i in a: x[i] += 1 q = int(input()) for i in range(q): b,c = map(int,input().split()) s -= b*x[b] s += c*x[b] x[c] += x[b] x[b] = 0 print(s)
[["-", 0, 656, 0, 1, 0, 662, 12, 657, 12, 612], ["+", 0, 656, 0, 1, 0, 662, 12, 657, 12, 612], ["-", 0, 1, 0, 677, 12, 657, 12, 206, 206, 22], ["+", 0, 1, 0, 677, 12, 657, 12, 206, 206, 22]]
5
116
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; vector<int> a(n, 0); map<int, int> m; long long int sum = 0; for (int i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; m[a[i]]++; } int q; cin >> q; while (q--) { int x, y; cin >> x >> y; sum ...
#include <bits/stdc++.h> using namespace std; int main() { long long int n; cin >> n; vector<int> a(n, 0); map<int, int> m; long long int sum = 0; for (int i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; m[a[i]]++; } int q; cin >> q; while (q--) { int x, y; cin >> x >> y; sum ...
[["-", 0, 16, 31, 23, 0, 69, 341, 342, 0, 22], ["+", 0, 16, 31, 23, 0, 69, 341, 342, 0, 22]]
1
161
import sys import time import math from collections import deque import heapq import itertools from decimal import Decimal import bisect from operator import itemgetter MAX_INT = int(10e18) MIN_INT = -MAX_INT mod = 1000000000+7 sys.setrecursionlimit(1000000) def IL(): return list(map(int,input().split())) def SL(): ret...
import sys import time import math from collections import deque import heapq import itertools from decimal import Decimal import bisect from operator import itemgetter MAX_INT = int(10e18) MIN_INT = -MAX_INT mod = 1000000000+7 sys.setrecursionlimit(1000000) def IL(): return list(map(int,input().split())) def SL(): ret...
[["-", 0, 656, 0, 1, 0, 662, 12, 657, 12, 612], ["+", 0, 656, 0, 1, 0, 662, 12, 657, 12, 612]]
5
228
N = int(input()) A = list(map(int, input().split(' '))) Q = int(input()) BC = [list(map(int, list(input().split(' ')))) for i in range(Q)] count = [0] * 10**5 + 5 for i in range(N): count[A[i]] += 1 s = sum(A) for i in range(Q): s = s - BC[i][0] * count[BC[i][0]] + BC[i][1] * count[BC[i][0]] count[BC[i][1...
N = int(input()) A = list(map(int, input().split(' '))) Q = int(input()) BC = [list(map(int, list(input().split(' ')))) for i in range(Q)] count = [0] * (10**5 + 5) for i in range(N): count[A[i]] += 1 s = sum(A) for i in range(Q): s = s - BC[i][0] * count[BC[i][0]] + BC[i][1] * count[BC[i][0]] count[BC[i]...
[["+", 0, 1, 0, 662, 12, 657, 12, 23, 0, 24], ["+", 0, 1, 0, 662, 12, 657, 12, 23, 0, 25]]
5
188
#include <bits/stdc++.h> #define fastio \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define fi first #define se second #de...
#include <bits/stdc++.h> #define fastio \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define fi first #define se second #de...
[["-", 8, 9, 0, 43, 49, 50, 51, 4, 0, 22], ["+", 8, 9, 0, 43, 49, 50, 51, 4, 0, 22]]
1
340
#include <bits/stdc++.h> using ll = long long; using namespace std; using Graph = vector<vector<ll>>; int main() { int n; cin >> n; map<int, int> mp; ll sum = 0; for (int i = 0; i < n; i++) { int a; cin >> a; sum += a; mp[a]++; } int q; cin >> q; for (int i = 0; i < q; i++) { int ...
#include <bits/stdc++.h> using ll = long long; using namespace std; using Graph = vector<vector<ll>>; int main() { int n; cin >> n; map<int, int> mp; ll sum = 0; for (int i = 0; i < n; i++) { int a; cin >> a; sum += a; mp[a]++; } int q; cin >> q; for (int i = 0; i < q; i++) { int ...
[["-", 0, 7, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 17, 107]]
1
160
#include <algorithm> #include <iostream> using namespace std; #define ll long long ll n, q, a[100000], s; int main() { cin >> n; for (int i = 0; i < n; i++) { int x; cin >> x; a[x]++; s += x; } cin >> q; for (int i = 0; i < q; i++) { int b, c; cin >> b >> c; s -= b * a[b]; ...
#include <algorithm> #include <iostream> using namespace std; #define ll long long ll n, q, a[100001], s; int main() { cin >> n; for (int i = 0; i < n; i++) { int x; cin >> x; a[x]++; s += x; } cin >> q; for (int i = 0; i < q; i++) { int b, c; cin >> b >> c; s -= b * a[b]; ...
[["-", 36, 36, 0, 30, 0, 43, 49, 80, 81, 13], ["+", 36, 36, 0, 30, 0, 43, 49, 80, 81, 13], ["-", 0, 11, 12, 16, 12, 69, 341, 342, 0, 22], ["+", 0, 11, 12, 16, 12, 69, 341, 342, 0, 22]]
1
138
import sys import time import math st = time.perf_counter() def inpl(): return list(map(int, input().split())) # ------------------------------ N = int(input()) nl = [0] * 10101 ls = inpl() ans = 0 for i in ls: nl[i] += 1 ans += i M = int(input()) for _ in range(M): a, b = map(int, input().split()) ans = ans -...
import sys import time import math st = time.perf_counter() def inpl(): return list(map(int, input().split())) # ------------------------------ N = int(input()) nl = [0] * 100100 ls = inpl() ans = 0 for i in ls: nl[i] += 1 ans += i M = int(input()) for _ in range(M): a, b = map(int, input().split()) ans = ans ...
[["-", 0, 656, 0, 1, 0, 662, 12, 657, 12, 612], ["+", 0, 656, 0, 1, 0, 662, 12, 657, 12, 612], ["+", 0, 662, 12, 657, 31, 657, 12, 23, 0, 24], ["+", 0, 662, 12, 657, 31, 657, 12, 23, 0, 25], ["+", 0, 1, 0, 662, 12, 657, 12, 23, 0, 24], ["-", 0, 662, 12, 657, 12, 657, 31, 206, 206, 22], ["+", 12, 657, 12, 23, 0, 657, 31...
5
164
import collections N = int(input()) A = list(map(int, input().split())) Q = int(input()) s = sum(A) c = collections.Counter(A) for _ in range(Q): B, C = map(int, input().split()) s += (C-B)*c[B] c[C] += c[B] c[B] += c[C] print(s)
import collections N = int(input()) A = list(map(int, input().split())) Q = int(input()) s = sum(A) c = collections.Counter(A) for _ in range(Q): B, C = map(int, input().split()) s += (C-B)*c[B] c[C] += c[B] c[B] = 0 print(s)
[["-", 0, 7, 8, 196, 0, 1, 0, 677, 17, 107], ["-", 8, 196, 0, 1, 0, 677, 12, 206, 51, 22], ["-", 8, 196, 0, 1, 0, 677, 12, 206, 0, 70], ["-", 8, 196, 0, 1, 0, 677, 12, 206, 206, 22], ["-", 8, 196, 0, 1, 0, 677, 12, 206, 0, 73], ["+", 0, 7, 8, 196, 0, 1, 0, 662, 0, 32], ["+", 0, 7, 8, 196, 0, 1, 0, 662, 12, 612]]
5
107
import sys input_data = [] input_pointer = 0 output_data = [] def input_scan(): global input_data input_data = sys.stdin.readlines() input_data = [x[:-1] for x in input_data] def next_line(): global input_pointer global input_data if input_pointer < len(input_data): input_pointer += ...
import sys input_data = [] input_pointer = 0 output_data = [] def input_scan(): global input_data input_data = sys.stdin.readlines() input_data = [x[:-1] for x in input_data] def next_line(): global input_pointer global input_data if input_pointer < len(input_data): input_pointer += ...
[["+", 8, 196, 0, 1, 0, 662, 31, 206, 51, 22], ["+", 8, 196, 0, 1, 0, 662, 31, 206, 0, 70], ["+", 8, 196, 0, 1, 0, 662, 31, 206, 206, 22], ["+", 8, 196, 0, 1, 0, 662, 31, 206, 0, 73], ["+", 0, 7, 8, 196, 0, 1, 0, 662, 0, 32], ["+", 0, 7, 8, 196, 0, 1, 0, 662, 12, 612]]
5
276
#include <iostream> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; int main() { ll n, q; ll a[100000], b[100000], c[100000]; ll ans[100001]; cin >> n; rep(i, n) { a[i] = 0; } ans[0] = 0; rep(i, n) { int k; cin >> k; a[k]++; ans[0] += k; }...
#include <iostream> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; int main() { ll n, q; ll a[100002], b[100000], c[100000]; ll ans[100002]; cin >> n; rep(i, n) { a[i] = 0; } ans[0] = 0; rep(i, n) { int k; cin >> k; a[k]++; ans[0] += k; }...
[["-", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13]]
1
226
from collections import Counter N = int(input()) A = list(map(int, input().split())) AC = Counter(A) S = sum(A) Q = int(input()) for _ in range(Q): B,C = map(int, input().split()) if B not in AC: pass else: count = AC[B] S = S + (C-B)*count if C in AC: AC[C] += count else: AC[C] = ...
from collections import Counter N = int(input()) A = list(map(int, input().split())) AC = Counter(A) S = sum(A) Q = int(input()) for _ in range(Q): B,C = map(int, input().split()) if B not in AC: pass else: count = AC[B] AC[B] = 0 S = S + (C-B)*count if C in AC: AC[C] += count else: ...
[["+", 8, 196, 0, 1, 0, 662, 31, 206, 51, 22], ["+", 8, 196, 0, 1, 0, 662, 31, 206, 0, 70], ["+", 8, 196, 0, 1, 0, 662, 31, 206, 206, 22], ["+", 8, 196, 0, 1, 0, 662, 31, 206, 0, 73], ["+", 75, 76, 8, 196, 0, 1, 0, 662, 0, 32], ["+", 75, 76, 8, 196, 0, 1, 0, 662, 12, 612]]
5
122
N = int(input()) numbers = list(map(int,input().split())) numOfOperation = int(input()) dic = {} for num in numbers: if num in dic : dic[num] += 1 else: dic[num] = 1 sums = sum(numbers) for i in range(numOfOperation): B,C = map(int,input().split()) if (B in dic) : cnt = dic[B] di...
N = int(input()) numbers = list(map(int,input().split())) numOfOperation = int(input()) dic = {} for num in numbers: if num in dic : dic[num] += 1 else: dic[num] = 1 sums = sum(numbers) for i in range(numOfOperation): B,C = map(int,input().split()) if (B in dic) : cnt = dic[B] di...
[["-", 0, 57, 64, 196, 0, 1, 0, 662, 12, 612], ["+", 0, 57, 64, 196, 0, 1, 0, 662, 12, 22]]
5
145
n = int(input()) m=list(map(int,input().split())) d={} k=0 for i in range(n): k+=m[i] if m[i] in d: d[m[i]]+=1 else: d[m[i]]=1 for x in range(int(input())): b,c=list(map(int,input().split())) k+=d[b]*(c-b) if c in d: d[c]+=d[b] else: d[c] = d[b] ...
n = int(input()) m=list(map(int,input().split())) d={} k=0 for i in range(n): k+=m[i] if m[i] in d: d[m[i]]+=1 else: d[m[i]]=1 for x in range(int(input())): b,c=list(map(int,input().split())) if b in d: k+=d[b]*(c-b) if c in d: d[c]+=d[b] ...
[["+", 0, 656, 0, 7, 8, 196, 0, 57, 0, 121], ["+", 0, 7, 8, 196, 0, 57, 15, 666, 0, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 666, 667, 267], ["+", 0, 656, 0, 7, 8, 196, 0, 57, 0, 102]]
5
152
# Problem D - Replacing # input N = int(input()) a_nums = list(map(int, input().split())) Q = int(input()) # initialization nums = [0] * (10**5 + 1) cur_sum = sum(a_nums) for a in a_nums: nums[a] += 1 # count for i in range(Q): b, c = map(int, input().split()) b_count = nums[b] cur_sum = cur_sum - b_...
# Problem D - Replacing # input N = int(input()) a_nums = list(map(int, input().split())) Q = int(input()) # initialization nums = [0] * (10**5 + 1) cur_sum = sum(a_nums) for a in a_nums: nums[a] += 1 # count for i in range(Q): b, c = map(int, input().split()) b_count = nums[b] cur_sum = cur_sum - b_...
[["+", 8, 196, 0, 1, 0, 662, 31, 206, 206, 22], ["+", 8, 196, 0, 1, 0, 662, 31, 206, 0, 73], ["+", 0, 7, 8, 196, 0, 1, 0, 662, 0, 32], ["+", 0, 7, 8, 196, 0, 1, 0, 662, 12, 612], ["+", 8, 196, 0, 1, 0, 677, 31, 206, 51, 22], ["+", 8, 196, 0, 1, 0, 677, 31, 206, 0, 70]]
5
118
#pragma GCC optimize("O3") #pragma GCC target("sse4") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef complex<ld> cd; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef pair<ld, ld> pd; typedef vector<int> vi; typedef vector<ld> vd; typedef vector<ll> vl...
#pragma GCC optimize("O3") #pragma GCC target("sse4") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef complex<ld> cd; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef pair<ld, ld> pd; typedef vector<int> vi; typedef vector<ld> vd; typedef vector<ll> vl...
[["-", 0, 11, 12, 16, 31, 69, 341, 342, 0, 22], ["+", 0, 11, 12, 16, 31, 69, 341, 342, 0, 22]]
1
415
input() arr = [int(num) for num in input().strip().split(' ')] q = int(input()) queries = [] for i in range(q): query = [ int(num) for num in input().strip().split(' ')] queries.append(query) nums = dict() summ = 0 for number in arr: summ += number if number not in nums: nums[number] = 1 ...
input() arr = [int(num) for num in input().strip().split(' ')] q = int(input()) queries = [] for i in range(q): query = [ int(num) for num in input().strip().split(' ')] queries.append(query) nums = dict() summ = 0 for number in arr: summ += number if number not in nums: nums[number] = 1 ...
[["+", 0, 57, 64, 196, 0, 1, 0, 652, 63, 22], ["+", 64, 196, 0, 1, 0, 652, 3, 4, 0, 24], ["+", 64, 196, 0, 1, 0, 652, 3, 4, 0, 22], ["+", 64, 196, 0, 1, 0, 652, 3, 4, 0, 25]]
5
179
from collections import Counter import numpy as np N = int(input()) A = list(map(int, input().split())) Q = int(input()) ans = sum(A) A = Counter(A) bc = [tuple(map(int, input().split())) for i in range(Q)] for b, c in bc: v = A.pop(b, None) if v: A[c] += v ans = ans+((c-b)*v) print(ans)
from collections import Counter N = int(input()) A = list(map(int, input().split())) Q = int(input()) ans = sum(A) A = Counter(A) bc = [tuple(map(int, input().split())) for i in range(Q)] for b, c in bc: v = A.pop(b, None) if v: A[c] += v ans = ans+((c-b)*v) print(ans)
[["-", 36, 36, 36, 36, 0, 656, 0, 596, 0, 487], ["-", 0, 656, 0, 596, 141, 704, 141, 673, 0, 22], ["-", 36, 36, 0, 656, 0, 596, 141, 704, 0, 272], ["-", 36, 36, 0, 656, 0, 596, 141, 704, 705, 22]]
5
122
n = int(input()) a = list(map(int,input().split())) ans = sum(a) #print(ans) q = int(input()) import collections cc = collections.Counter(a) #print(cc) for i in range(q): b,c = map(int,input().split()) tmp = cc[b] cc[b] = 0 s=s-b*tmp+c*tmp cc[c]+=tmp print(s)
n = int(input()) a = list(map(int,input().split())) s = sum(a) #print(ans) q = int(input()) import collections cc = collections.Counter(a) #print(cc) for i in range(q): b,c = map(int,input().split()) tmp = cc[b] cc[b] = 0 s=s-b*tmp+c*tmp cc[c]+=tmp print(s)
[["-", 36, 36, 0, 656, 0, 1, 0, 662, 31, 22], ["+", 36, 36, 0, 656, 0, 1, 0, 662, 31, 22]]
5
108
//#include<bits/stdc++.h> using namespace std; #include <iostream> using namespace std; #include <algorithm> #include <deque> #include <map> #include <queue> //priority_queue inside queue #include <set> #include <stack> #include <vector> #define fast \ ...
//#include<bits/stdc++.h> using namespace std; #include <iostream> using namespace std; #include <algorithm> #include <deque> #include <map> #include <queue> //priority_queue inside queue #include <set> #include <stack> #include <vector> #define fast \ ...
[["-", 0, 1, 0, 2, 3, 4, 0, 69, 28, 22], ["-", 0, 2, 3, 4, 0, 69, 341, 342, 0, 70], ["-", 0, 2, 3, 4, 0, 69, 341, 342, 0, 73]]
1
266
///...................SUBHASHIS MOLLICK.................../// ///.....DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING..../// ///.............ISLAMIC UNIVERSITY,BANGLADESH............./// ///....................SESSION-(14-15)..................../// #include <bits/stdc++.h> using namespace std; #define sf(a) scanf("%d", ...
///...................SUBHASHIS MOLLICK.................../// ///.....DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING..../// ///.............ISLAMIC UNIVERSITY,BANGLADESH............./// ///....................SESSION-(14-15)..................../// #include <bits/stdc++.h> using namespace std; #define sf(a) scanf("%d", ...
[["-", 0, 11, 12, 23, 0, 16, 31, 69, 28, 22], ["-", 12, 23, 0, 16, 31, 69, 341, 342, 0, 70], ["-", 12, 23, 0, 16, 31, 69, 341, 342, 0, 22], ["-", 12, 23, 0, 16, 31, 69, 341, 342, 0, 73], ["+", 0, 1, 0, 11, 12, 23, 0, 16, 31, 22]]
1
317
n=gets.to_i line=gets.split(' ').map(&:to_i) q=gets.to_i bc=[] q.times do bc << gets.chomp.split(" ").map { |e|e.to_i } end sum=line.sum table=line.tally bc.each do |i,j| sum+=table[i]*(j-i) table[j]+=table[i] table[i]=0 p sum end
n=gets.to_i line=gets.split(' ').map(&:to_i) q=gets.to_i bc=[] q.times do bc << gets.chomp.split(" ").map { |e|e.to_i } end sum=line.sum table=line.tally table.default = 0 bc.each do |i,j| sum+=table[i]*(j-i) table[j]+=table[i] table[i]=0 p sum end
[["+", 36, 36, 0, 493, 0, 662, 31, 652, 486, 22], ["+", 36, 36, 0, 493, 0, 662, 31, 652, 17, 131], ["+", 36, 36, 0, 493, 0, 662, 31, 652, 735, 22], ["+", 36, 36, 36, 36, 0, 493, 0, 662, 0, 32], ["+", 36, 36, 36, 36, 0, 493, 0, 662, 12, 612]]
4
106
import os import sys from collections import defaultdict, Counter from itertools import product, permutations,combinations, accumulate from operator import itemgetter from bisect import bisect_left,bisect from heapq import heappop,heappush,heapify from math import ceil, floor, sqrt from copy import deepcopy def main()...
import os import sys from collections import defaultdict, Counter from itertools import product, permutations,combinations, accumulate from operator import itemgetter from bisect import bisect_left,bisect from heapq import heappop,heappush,heapify from math import ceil, floor, sqrt from copy import deepcopy def main()...
[["+", 8, 196, 0, 1, 0, 662, 12, 657, 17, 578], ["+", 8, 196, 0, 1, 0, 662, 12, 657, 12, 612]]
5
194
import collections def main(): n = int(input()) a = list(map(int, input().split())) cnt = collections.defaultdict(int) for var in a: cnt[var] += 1 sum_a = sum[a] q = int(input()) for _ in range(q): b, c = list(map(int, input().split())) diff = (c-b) *...
import collections def main(): n = int(input()) a = list(map(int, input().split())) cnt = collections.defaultdict(int) for var in a: cnt[var] += 1 sum_a = sum(a) q = int(input()) for _ in range(q): b, c = list(map(int, input().split())) diff = (c-b) * ...
[["-", 8, 196, 0, 1, 0, 662, 12, 206, 0, 70], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 24], ["-", 8, 196, 0, 1, 0, 662, 12, 206, 0, 73], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 25]]
5
136
from collections import Counter def Replacing(): Num = int(input()) value_A = list(map(int,input().split())) Sum = sum(value_A) Counter_value = Counter(value_A) NumB = int(input()) for i in range(NumB): value_B = list(map(int,input().split())) Sum += (value_B[1] - value_B[...
from collections import Counter def Replacing(): Num = int(input()) value_A = list(map(int,input().split())) Sum = sum(value_A) Counter_value = Counter(value_A) NumB = int(input()) for i in range(NumB): value_B = list(map(int,input().split())) Sum += (value_B[1] - value_B[...
[["-", 0, 677, 12, 657, 12, 652, 3, 4, 0, 24], ["+", 0, 1, 0, 677, 12, 657, 12, 206, 0, 70], ["+", 0, 677, 12, 657, 12, 206, 206, 206, 0, 73], ["-", 0, 677, 12, 657, 12, 652, 3, 4, 0, 25]]
5
138