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 |
|---|---|---|---|---|---|---|---|
p03137 | #include <bits/stdc++.h>
using namespace std;
#define step(i, s, n, d) for (int i = s; i < n; i += d)
#define FOR(i, s, n) step(i, s, n, 1)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
typedef pair<int, int> P;
int main() {
ll N, M;
cin >> N >> M;
ll x[M], sa[M], res = 0;
rep(i, M) { cin >> x[i]; }
if (N >= M) {
cout << res << endl;
exit(0);
}
sort(x, x + M);
rep(i, M - 1) { sa[i] = x[i + 1] - x[i]; }
sort(sa, sa + M);
rep(i, M - N) { res += sa[i]; }
cout << res << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define step(i, s, n, d) for (int i = s; i < n; i += d)
#define FOR(i, s, n) step(i, s, n, 1)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
typedef pair<int, int> P;
int main() {
ll N, M;
cin >> N >> M;
ll x[M], sa[M], res = 0;
rep(i, M) { cin >> x[i]; }
if (N >= M) {
cout << res << endl;
exit(0);
}
sort(x, x + M);
rep(i, M - 1) { sa[i] = x[i + 1] - x[i]; }
sort(sa, sa + M - 1);
rep(i, M - N) { res += sa[i]; }
cout << res << endl;
}
| [
"expression.operation.binary.add"
] | 938,119 | 938,120 | u136468939 | cpp |
p03137 | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
vector<int> X, dis_X;
for (int i = 0; i < M; i++) {
int element;
cin >> element;
X.push_back(element);
}
if (M == 1) {
cout << 0 << endl;
} else if (N > M) {
cout << 0 << endl;
} else {
sort(X.begin(), X.end());
int first, last;
first = X[0];
last = X[X.size() - 1];
int distance = last - first;
for (int i = 1; i < M; i++) {
int dis = X[i] - X[i - 1];
dis_X.push_back(dis);
}
sort(dis_X.begin(), dis_X.end());
int count = 0;
for (int i = 0; i <= dis_X.size() - N; i++) {
count += dis_X[i];
}
cout << count << endl;
}
return 0;
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
vector<int> X, dis_X;
for (int i = 0; i < M; i++) {
int element;
cin >> element;
X.push_back(element);
}
if (M == 1) {
cout << 0 << endl;
} else if (N >= M) {
cout << 0 << endl;
} else {
sort(X.begin(), X.end());
int first, last;
first = X[0];
last = X[X.size() - 1];
int distance = last - first;
for (int i = 1; i < M; i++) {
int dis = X[i] - X[i - 1];
dis_X.push_back(dis);
}
sort(dis_X.begin(), dis_X.end());
int count = 0;
for (int i = 0; i <= dis_X.size() - N; i++) {
count += dis_X[i];
}
cout << count << endl;
}
return 0;
} | [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 938,145 | 938,146 | u168139048 | cpp |
p03137 | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define LARGE 1000000000
#define MOD 100000
int N, M, sum;
int aim[100009], dis[100009];
int main() {
dis[0] = 0;
cin >> N >> M;
if (N == M)
sum = 0;
else {
for (int i = 0; i < M; i++)
cin >> aim[i];
sort(aim, aim + M);
for (int i = 1; i < M; i++)
dis[i] = aim[i] - aim[i - 1];
sort(dis, dis + M);
sum = aim[M - 1] - aim[0];
for (int i = 0; i < N - 1; i++)
sum -= dis[M - 1 - i];
}
cout << sum << endl;
return 0;
}
//チーズ
/*
int H, W, N, ans, tag, si, sj;
char MAP[1009][1009];
int dp[1009][1009];
bool inmap(int i, int j) {
return ((i >= 0 && i <= H - 1) && (j >= 0 && j <= W - 1));
}
bool pass(int i, int j) {
return (MAP[i][j] != 'X');
}
int DFS(int i, int j) {
if (dp[i][j] != LARGE)return dp[i][j];
if (MAP[i][j] - '0' == tag) {
si = i; sj = j;
return 0;
}
if (inmap(i + 1, j) && pass(i + 1, j)) dp[i][j] = min(dp[i][j], DFS(i + 1, j) +
1); if (inmap(i - 1, j) && pass(i - 1, j)) dp[i][j] = min(dp[i][j], DFS(i - 1,
j) + 1); if (inmap(i, j + 1) && pass(i, j + 1)) dp[i][j] = min(dp[i][j], DFS(i,
j + 1) + 1); if (inmap(i, j - 1) && pass(i, j - 1)) dp[i][j] = min(dp[i][j],
DFS(i, j - 1) + 1); cout << i << " " << j << " " << dp[i][j] << endl; return
dp[i][j];
}
int main() {
cin >> H >> W >> N;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
cin >> MAP[i][j];
if (MAP[i][j] == 'S') {
si = i; sj = j;
}
}
}
for (int i = 1; i <= N; i++) {
cout << i << " " << si << " " << sj << endl << endl;
for (int j = 0; j < H; j++) {
for (int k = 0; k < W; k++) {
dp[j][k] = LARGE;
}
}
tag = i;
ans += DFS(si, sj);
}
cout << ans << endl;
return 0;
}
*/
| #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define LARGE 1000000000
#define MOD 100000
int N, M, sum;
int aim[100009], dis[100009];
int main() {
dis[0] = 0;
cin >> N >> M;
if (N >= M)
sum = 0;
else {
for (int i = 0; i < M; i++)
cin >> aim[i];
sort(aim, aim + M);
for (int i = 1; i < M; i++)
dis[i] = aim[i] - aim[i - 1];
sort(dis, dis + M);
sum = aim[M - 1] - aim[0];
for (int i = 0; i < N - 1; i++)
sum -= dis[M - 1 - i];
}
cout << sum << endl;
return 0;
}
//チーズ
/*
int H, W, N, ans, tag, si, sj;
char MAP[1009][1009];
int dp[1009][1009];
bool inmap(int i, int j) {
return ((i >= 0 && i <= H - 1) && (j >= 0 && j <= W - 1));
}
bool pass(int i, int j) {
return (MAP[i][j] != 'X');
}
int DFS(int i, int j) {
if (dp[i][j] != LARGE)return dp[i][j];
if (MAP[i][j] - '0' == tag) {
si = i; sj = j;
return 0;
}
if (inmap(i + 1, j) && pass(i + 1, j)) dp[i][j] = min(dp[i][j], DFS(i + 1, j) +
1); if (inmap(i - 1, j) && pass(i - 1, j)) dp[i][j] = min(dp[i][j], DFS(i - 1,
j) + 1); if (inmap(i, j + 1) && pass(i, j + 1)) dp[i][j] = min(dp[i][j], DFS(i,
j + 1) + 1); if (inmap(i, j - 1) && pass(i, j - 1)) dp[i][j] = min(dp[i][j],
DFS(i, j - 1) + 1); cout << i << " " << j << " " << dp[i][j] << endl; return
dp[i][j];
}
int main() {
cin >> H >> W >> N;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
cin >> MAP[i][j];
if (MAP[i][j] == 'S') {
si = i; sj = j;
}
}
}
for (int i = 1; i <= N; i++) {
cout << i << " " << si << " " << sj << endl << endl;
for (int j = 0; j < H; j++) {
for (int k = 0; k < W; k++) {
dp[j][k] = LARGE;
}
}
tag = i;
ans += DFS(si, sj);
}
cout << ans << endl;
return 0;
}
*/
| [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 938,155 | 938,156 | u657512990 | cpp |
p03137 | #include <algorithm>
#include <cmath>
#include <iostream>
#include <string.h>
#include <string>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int x[110000];
int sa[110000];
int min = 0;
for (int i = 0; i < m; i++) {
cin >> x[i];
}
if (n >= m)
cout << 0 << endl;
else {
sort(x, x + m);
for (int i = 1; i < m; i++) {
sa[i - 1] = x[i] - x[i - 1];
}
sort(sa, sa + m - 1);
}
for (int i = 0; i < m - n; i++) {
min += sa[i];
}
cout << min << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <string.h>
#include <string>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int x[110000];
int sa[110000];
int min = 0;
for (int i = 0; i < m; i++) {
cin >> x[i];
}
if (n >= m)
cout << 0 << endl;
else {
sort(x, x + m);
for (int i = 1; i < m; i++) {
sa[i - 1] = x[i] - x[i - 1];
}
sort(sa, sa + m - 1);
for (int i = 0; i < m - n; i++) {
min += sa[i];
}
cout << min << endl;
}
return 0;
} | [] | 938,174 | 938,175 | u850894780 | cpp |
p03137 | #include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <limits>
#include <numeric>
#include <queue>
#include <regex>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define INF 2000000000
#define REP(i, b, n) for (int i = (b); i < n; i++)
#define rREP(i, b, n) for (int i = n; i >= b; i--)
using namespace std;
using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
const string lowercase = "abcdefghijklmnopqrstuvwxyz";
const string uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int main() {
int n, m;
vi x;
vi d;
cin >> n >> m;
REP(i, 0, m) {
int xi;
cin >> xi;
x.push_back(xi);
}
if (m == 1) {
cout << 0 << endl;
return 0;
}
sort(x.begin(), x.end());
int ans = x[m - 1] - x[0];
REP(i, 1, m) { d.push_back(x[i] - x[i - 1]); }
sort(d.begin(), d.end(), greater<int>());
REP(i, 0, n - 1) { ans -= d[i]; }
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <limits>
#include <numeric>
#include <queue>
#include <regex>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define INF 2000000000
#define REP(i, b, n) for (int i = (b); i < n; i++)
#define rREP(i, b, n) for (int i = n; i >= b; i--)
using namespace std;
using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
const string lowercase = "abcdefghijklmnopqrstuvwxyz";
const string uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int main() {
int n, m;
vi x, d;
cin >> n >> m;
REP(i, 0, m) {
int xi;
cin >> xi;
x.push_back(xi);
}
if (n >= m) {
cout << 0 << endl;
return 0;
}
sort(x.begin(), x.end());
int ans = x[m - 1] - x[0];
REP(i, 1, m) { d.push_back(x[i] - x[i - 1]); }
sort(d.begin(), d.end(), greater<int>());
REP(i, 0, n - 1) { ans -= d[i]; }
cout << ans << endl;
return 0;
}
| [
"control_flow.branch.if.condition.change",
"expression.operation.binary.remove"
] | 938,186 | 938,185 | u576712004 | cpp |
p03137 | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
int M;
int X[100000];
int d[100000];
int res = 0;
cin >> N;
cin >> M;
if (N >= M) {
cout << 0;
return 0;
}
for (int i = 0; i < M; i++) {
cin >> X[i];
}
sort(X, X + M - 1);
for (int i = 0; i < M - 1; i++) {
d[i] = X[i + 1] - X[i];
}
sort(d, d + M - 1);
for (int i = 0; i < M - N; i++) {
res += d[i];
}
cout << res;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
int M;
int X[100000];
int d[100000];
int res = 0;
cin >> N;
cin >> M;
if (N >= M) {
cout << 0;
return 0;
}
for (int i = 0; i < M; i++) {
cin >> X[i];
}
sort(X, X + M);
for (int i = 0; i < M - 1; i++) {
d[i] = X[i + 1] - X[i];
}
sort(d, d + M - 1);
for (int i = 0; i < M - N; i++) {
res += d[i];
}
cout << res;
return 0;
} | [
"expression.operation.binary.remove"
] | 938,207 | 938,208 | u173749724 | cpp |
p03137 | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
if (N >= M) {
cout << 0 << endl;
return 0;
}
vector<int> X(M);
for (int i = 0; i < M; i++) {
cin >> X[i];
}
sort(X.begin(), X.end());
vector<int> dist(M - 1);
for (int i = 0; i < M - 1; i++) {
dist[i] = X[i + 1] - X[i];
}
sort(dist.begin(), dist.end());
int travel = X[M - 1] - X[0];
for (int i = M - 1; i >= M - N; i--) {
travel -= dist[i];
}
cout << travel << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
if (N >= M) {
cout << 0 << endl;
return 0;
}
vector<int> X(M);
for (int i = 0; i < M; i++) {
cin >> X[i];
}
sort(X.begin(), X.end());
vector<int> dist(M - 1);
for (int i = 0; i < M - 1; i++) {
dist[i] = X[i + 1] - X[i];
}
sort(dist.begin(), dist.end());
int travel = X[M - 1] - X[0];
for (int i = M - 2; i >= M - N; i--) {
travel -= dist[i];
}
cout << travel << endl;
return 0;
} | [
"literal.number.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one",
"expression.operation.binary.change"
] | 938,217 | 938,218 | u727099903 | cpp |
p03137 | #include <bits/stdc++.h>
using namespace std;
//#define READ_NUMBER(i) scanf("%d",i)
int main() {
int N, M;
cin >> N >> M;
int array[M];
int array_d[M - 1];
int Ans = 0;
if (N >= M) {
cout << "0" << endl;
} else {
for (int i = 0; i < M; i++) {
cin >> array[i];
}
std::sort(array, array + M);
for (int i = 0; i < M - 1; i++) {
array_d[i] = array[i + 1] - array[i];
}
std::sort(array_d, array_d + M - 1);
for (int i = 0; i < N + 1; i++) {
Ans += array_d[i];
}
// cout << array[0] << " " << array[1] << " " << array[2] << " " << array[3]
// << " " << array[4] << endl;
cout << Ans << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
//#define READ_NUMBER(i) scanf("%d",i)
int main() {
int N, M;
cin >> N >> M;
int array[M];
int array_d[M - 1];
int Ans = 0;
if (N >= M) {
cout << "0" << endl;
} else {
for (int i = 0; i < M; i++) {
cin >> array[i];
}
std::sort(array, array + M);
for (int i = 0; i < M - 1; i++) {
array_d[i] = array[i + 1] - array[i];
}
std::sort(array_d, array_d + M - 1);
for (int i = 0; i < M - N; i++) {
Ans += array_d[i];
}
cout << Ans << endl;
}
} | [
"control_flow.branch.if.condition.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.remove"
] | 938,221 | 938,222 | u796853866 | cpp |
p03137 | #include <algorithm>
#include <cstdint>
#include <iostream>
#include <memory>
#include <sstream>
#include <string>
#include <vector>
#include <limits.h>
using namespace std;
class Hoge {
public:
int add(int a, int b);
static void ABC117B();
static void ABC117C();
static int ABC117C_sub_ans1(int n, int m, int idx, std::vector<int> &x);
static int ABC117C_sub_ans2(int n, int m, int idx, std::vector<int> &x);
};
int Hoge::add(int a, int b) { return a + b; }
void Hoge::ABC117B() {
int n;
cin >> n;
int j;
int max = 0;
int sum = 0;
for (int i = 0; i < n; i++) {
cin >> j;
max = max < j ? j : max;
sum += j;
}
sum = sum - max;
if (max < sum) {
cout << "Yes";
} else {
cout << "No";
}
return;
}
void Hoge::ABC117C() {
int n, m, t;
std::vector<int> x;
cin >> n;
cin >> m;
for (int i = 0; i < m; i++) {
cin >> t;
x.push_back(t);
}
std::sort(x.begin(), x.end());
int result = ABC117C_sub_ans2(n, m, 0, x);
cout << result;
return;
}
int Hoge::ABC117C_sub_ans1(int n, int m, int idx, std::vector<int> &x) {
if (m <= n) {
return 0;
} else {
int minSteps = 1000000;
for (int i = 0; i < m - 1; i++) {
int stepsLeft = std::abs(x[idx + i] - x[idx]);
if (stepsLeft >= minSteps) {
break;
}
int stepsRight = 0;
if (n > 1) {
stepsRight = ABC117C_sub_ans1(n - 1, m, idx + i + 1, x);
} else {
stepsRight = std::abs(x[m - 1] - x[idx + i]);
}
int steps = stepsLeft + stepsRight;
minSteps = std::min(minSteps, steps);
// cerr << "n: " << n << ", m: " << m << ", idx: " << idx;
// cerr << ", minSteps: " << minSteps << ", left:" << stepsLeft << ",
// right: " << stepsRight << endl;
}
return minSteps;
}
}
int Hoge::ABC117C_sub_ans2(int n, int m, int idx, std::vector<int> &x) {
if (m <= n) {
return 0;
}
if (n == 1) {
return x[m - 1] - x[0];
}
// find (n-1) biggest intervals of x[i]..x[i+1]
vector<int> intervals(m - 1);
for (int i = 0; i < m - 1; i++) {
// cerr << "diff x[" << i << "]=" << x[i + 1] - x[i] << endl;
intervals.push_back(abs(x[i + 1] - x[i]));
}
sort(intervals.begin(), intervals.end(), std::greater<int>());
int exclude = 0;
int sum = 0;
for (int i = 0; i < m - 1 - n - 1; i++) {
exclude += intervals[i];
}
for (int i = 0; i < m; i++) {
sum += intervals[i];
}
// cerr << "sum: " << sum << ", exclude: " << exclude << endl;
return sum - exclude;
}
int main(int argc, char const *argv[]) {
Hoge::ABC117C();
return 0;
}
| #include <algorithm>
#include <cstdint>
#include <iostream>
#include <memory>
#include <sstream>
#include <string>
#include <vector>
#include <limits.h>
using namespace std;
class Hoge {
public:
int add(int a, int b);
static void ABC117B();
static void ABC117C();
static int ABC117C_sub_ans1(int n, int m, int idx, std::vector<int> &x);
static int ABC117C_sub_ans2(int n, int m, int idx, std::vector<int> &x);
};
int Hoge::add(int a, int b) { return a + b; }
void Hoge::ABC117B() {
int n;
cin >> n;
int j;
int max = 0;
int sum = 0;
for (int i = 0; i < n; i++) {
cin >> j;
max = max < j ? j : max;
sum += j;
}
sum = sum - max;
if (max < sum) {
cout << "Yes";
} else {
cout << "No";
}
return;
}
void Hoge::ABC117C() {
int n, m, t;
std::vector<int> x;
cin >> n;
cin >> m;
for (int i = 0; i < m; i++) {
cin >> t;
x.push_back(t);
}
std::sort(x.begin(), x.end());
int result = ABC117C_sub_ans2(n, m, 0, x);
cout << result;
return;
}
int Hoge::ABC117C_sub_ans1(int n, int m, int idx, std::vector<int> &x) {
if (m <= n) {
return 0;
} else {
int minSteps = 1000000;
for (int i = 0; i < m - 1; i++) {
int stepsLeft = std::abs(x[idx + i] - x[idx]);
if (stepsLeft >= minSteps) {
break;
}
int stepsRight = 0;
if (n > 1) {
stepsRight = ABC117C_sub_ans1(n - 1, m, idx + i + 1, x);
} else {
stepsRight = std::abs(x[m - 1] - x[idx + i]);
}
int steps = stepsLeft + stepsRight;
minSteps = std::min(minSteps, steps);
// cerr << "n: " << n << ", m: " << m << ", idx: " << idx;
// cerr << ", minSteps: " << minSteps << ", left:" << stepsLeft << ",
// right: " << stepsRight << endl;
}
return minSteps;
}
}
int Hoge::ABC117C_sub_ans2(int n, int m, int idx, std::vector<int> &x) {
if (m <= n) {
return 0;
}
if (n == 1) {
return x[m - 1] - x[0];
}
// find (n-1) biggest intervals of x[i]..x[i+1]
vector<int> intervals(m - 1);
for (int i = 0; i < m - 1; i++) {
// cerr << "diff x[" << i << "]=" << x[i + 1] - x[i] << endl;
intervals.push_back(abs(x[i + 1] - x[i]));
}
sort(intervals.begin(), intervals.end(), std::greater<int>());
int exclude = 0;
int sum = 0;
for (int i = 0; i < n - 1; i++) {
exclude += intervals[i];
}
for (int i = 0; i < m; i++) {
sum += intervals[i];
}
// cerr << "sum: " << sum << ", exclude: " << exclude << endl;
return sum - exclude;
}
int main(int argc, char const *argv[]) {
Hoge::ABC117C();
return 0;
}
| [
"control_flow.loop.for.condition.change",
"expression.operation.binary.remove"
] | 938,248 | 938,249 | u864329440 | cpp |
p03137 | #include <algorithm>
#include <functional>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
if (N <= M) {
cout << 0 << endl;
} else {
int X[M];
for (int i = 0; i < M; i++) {
cin >> X[i];
}
sort(X, X + M);
int L[M];
L[0] = 0;
for (int i = 1; i < M; i++) {
L[i] = X[i] - X[i - 1];
}
sort(L, L + M);
int sum = 0;
for (int i = 0; i < N - 1; i++) {
sum = sum + L[M - i - 1];
}
cout << X[M - 1] - X[0] - sum << endl;
}
}
| #include <algorithm>
#include <functional>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
if (N >= M) {
cout << 0 << endl;
} else {
int X[M];
for (int i = 0; i < M; i++) {
cin >> X[i];
}
sort(X, X + M);
int L[M];
L[0] = 0;
for (int i = 1; i < M; i++) {
L[i] = X[i] - X[i - 1];
}
sort(L, L + M);
int sum = 0;
for (int i = 0; i < N - 1; i++) {
sum = sum + L[M - i - 1];
}
cout << X[M - 1] - X[0] - sum << endl;
}
}
| [
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 938,276 | 938,277 | u650243369 | cpp |
p03137 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int a[m];
for (int i = 0; i < m; i++) {
cin >> a[i];
}
if (n >= m) {
cout << 0;
return 0;
}
sort(a, a + n);
int b[m - 1];
for (int i = 0; i < m - 1; i++) {
b[i] = abs(a[i + 1] - a[i]);
}
sort(b, b + m - 1);
int res = 0;
for (int i = 0; i < m - n - 1; i++) {
res += b[i];
}
cout << res;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int a[m];
for (int i = 0; i < m; i++) {
cin >> a[i];
}
if (n >= m) {
cout << 0;
return 0;
}
sort(a, a + m);
int b[m - 1];
for (int i = 0; i < m - 1; i++) {
b[i] = abs(a[i + 1] - a[i]);
}
sort(b, b + m - 1);
int res = 0;
for (int i = 0; i < m - n; i++) {
res += b[i];
}
cout << res;
return 0;
}
| [
"identifier.change",
"call.arguments.change",
"expression.operation.binary.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.remove"
] | 938,322 | 938,323 | u586143466 | cpp |
p03137 | #include <bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9 + 7)
#define P pair<int, int>
#define PLL pair<ll, ll>
#define FOR(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define RFOR(i, m, n) for (int i = (int)m; i >= (int)n; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define all(a) a.begin(), a.end()
#define IN(a, n) \
rep(i, n) { cin >> a[i]; }
const int vx[4] = {0, 1, 0, -1};
const int vy[4] = {1, 0, -1, 0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define int ll
int n, m;
int a[1000000];
int l[1000000];
int ans;
signed main() {
cin >> n >> m;
rep(i, m) { cin >> a[i]; }
if (n <= m) {
cout << 0 << endl;
return 0;
}
sort(a, a + m);
ans = a[m - 1] - a[0];
rep(i, m - 1) { l[i] = a[i + 1] - a[i]; }
sort(l, l + m - 1);
rep(i, n) { ans -= l[m - 1 - i]; }
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9 + 7)
#define P pair<int, int>
#define PLL pair<ll, ll>
#define FOR(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define RFOR(i, m, n) for (int i = (int)m; i >= (int)n; i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define all(a) a.begin(), a.end()
#define IN(a, n) \
rep(i, n) { cin >> a[i]; }
const int vx[4] = {0, 1, 0, -1};
const int vy[4] = {1, 0, -1, 0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define int ll
int n, m;
int a[1000000];
int l[1000000];
int ans;
signed main() {
cin >> n >> m;
rep(i, m) { cin >> a[i]; }
if (n >= m) {
cout << 0 << endl;
return 0;
}
sort(a, a + m);
ans = a[m - 1] - a[0];
rep(i, m - 1) { l[i] = a[i + 1] - a[i]; }
sort(l, l + m - 1);
rep(i, n) { ans -= l[m - 1 - i]; }
cout << ans << endl;
}
| [
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 938,332 | 938,333 | u229842440 | cpp |
p03137 | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
int N;
cin >> N;
int M;
cin >> M;
if (M <= N) {
cout << 0 << endl;
return 0;
}
int *X = new int[M];
int *diff = new int[M - 1];
int sum = 0;
for (int i = 0; i < M; i++) {
cin >> X[i];
}
sort(X, X + M);
for (int i = 0; i < M - 1; i++) {
diff[i] = X[i + 1] - X[i];
sum += diff[i];
}
sort(diff, diff + M - 1);
for (int j = M - 2; j > N; j--) {
sum -= diff[j];
}
cout << sum << endl;
return 0;
} | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
int N;
cin >> N;
int M;
cin >> M;
if (M <= N) {
cout << 0 << endl;
return 0;
}
int *X = new int[M];
int *diff = new int[M - 1];
int sum = 0;
for (int i = 0; i < M; i++) {
cin >> X[i];
}
sort(X, X + M);
for (int i = 0; i < M - 1; i++) {
diff[i] = X[i + 1] - X[i];
sum += diff[i];
}
sort(diff, diff + M - 1);
for (int j = M - 2; j > M - 2 - N + 1; j--) {
sum -= diff[j];
}
cout << sum << endl;
return 0;
} | [
"control_flow.loop.for.condition.change",
"misc.off_by_one"
] | 938,334 | 938,335 | u007462477 | cpp |
p03137 | /* Accepted. */
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
#define MAXN 100006
int n, m;
int X[MAXN], d[MAXN], S;
int main() {
// freopen( "input","r",stdin );
cin >> m >> n;
if (m <= n)
return puts("0"), 0;
for (int i = 1; i <= n; ++i)
scanf("%d", &X[i]);
sort(X + 1, X + 1 + n);
for (int i = 1; i <= n; ++i)
d[i] = i != 1 ? X[i] - X[i - 1] : -0x3f3f3f3f;
S = X[n] - X[1];
sort(d + 1, d + 1 + n);
for (int i = 0; i < m - 1; ++i)
S -= d[n - i];
cout << S;
} // qwq
| /* Accepted. */
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
#define MAXN 100006
int n, m;
int X[MAXN], d[MAXN], S;
int main() {
// freopen( "input","r",stdin );
cin >> m >> n;
if (n <= m)
return puts("0"), 0;
for (int i = 1; i <= n; ++i)
scanf("%d", &X[i]);
sort(X + 1, X + 1 + n);
for (int i = 1; i <= n; ++i)
d[i] = i != 1 ? X[i] - X[i - 1] : -0x3f3f3f3f;
S = X[n] - X[1];
sort(d + 1, d + 1 + n);
for (int i = 0; i < m - 1; ++i)
S -= d[n - i];
cout << S;
} // qwq
| [
"expression.operation.binary.remove",
"control_flow.branch.if.condition.change"
] | 938,340 | 938,341 | u390140944 | cpp |
p03137 | #include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
if (M == 1) {
cout << 1 << endl;
return 0;
}
vector<int> X(M);
for (int i = 0; i < M; i++) {
cin >> X[i];
}
sort(X.begin(), X.end());
vector<int> sub;
for (int i = 1; i < X.size(); i++) {
sub.push_back(abs(X[i] - X[i - 1]));
// cout << abs(X[i] - X[i - 1]) << endl;
}
sort(sub.begin(), sub.end());
cout << accumulate(sub.begin(), sub.end() - (N - 1), 0LL);
return 0;
} | #include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
if (M <= N) {
cout << 0 << endl;
return 0;
}
vector<int> X(M);
for (int i = 0; i < M; i++) {
cin >> X[i];
}
sort(X.begin(), X.end());
vector<int> sub;
for (int i = 1; i < X.size(); i++) {
sub.push_back(abs(X[i] - X[i - 1]));
// cout << abs(X[i] - X[i - 1]) << endl;
}
sort(sub.begin(), sub.end());
cout << accumulate(sub.begin(), sub.end() - (N - 1), 0LL);
return 0;
} | [
"literal.number.change",
"io.output.change"
] | 938,354 | 938,355 | u341347211 | cpp |
p03136 | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; ++i)
cin >> a[i];
sort(a, a + n);
int sum = 0;
for (int i = 0; i < n - 1; ++i)
sum += a[i];
if (sum < a[n - 1])
cout << "No" << endl;
else
cout << "Yes" << endl;
return 0;
} | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; ++i)
cin >> a[i];
sort(a, a + n);
int sum = 0;
for (int i = 0; i < n - 1; ++i)
sum += a[i];
if (sum > a[n - 1])
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
} | [
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change",
"literal.string.change",
"io.output.change"
] | 938,423 | 938,424 | u146240825 | cpp |
p03136 | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; ++i)
cin >> a[i];
sort(a, a + n);
int sum = 0;
for (int i = 0; i < n - 1; ++i)
sum += a[i];
if (sum < a[n - 1])
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
} | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; ++i)
cin >> a[i];
sort(a, a + n);
int sum = 0;
for (int i = 0; i < n - 1; ++i)
sum += a[i];
if (sum > a[n - 1])
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
} | [
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 938,425 | 938,424 | u146240825 | cpp |
p03136 | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
long long a[n];
for (int i = 0; i < n; ++i)
cin >> a[i];
sort(a, a + n);
long long sum = 0;
for (int i = 0; i < n - 1; ++i)
sum += a[i];
if (sum < a[n - 1])
cout << "No" << endl;
else
cout << "Yes" << endl;
return 0;
} | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
long long a[n];
for (int i = 0; i < n; ++i)
cin >> a[i];
sort(a, a + n);
long long sum = 0;
for (int i = 0; i < n - 1; ++i)
sum += a[i];
if (sum <= a[n - 1])
cout << "No" << endl;
else
cout << "Yes" << endl;
return 0;
} | [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 938,426 | 938,427 | u146240825 | cpp |
p03136 | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; ++i)
cin >> a[i];
sort(a, a + n);
int sum = 0;
for (int i = 0; i < n - 1; ++i)
sum += a[i];
if (sum < a[n - 1])
cout << "No" << endl;
else
cout << "Yes" << endl;
return 0;
} | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
long long a[n];
for (int i = 0; i < n; ++i)
cin >> a[i];
sort(a, a + n);
long long sum = 0;
for (int i = 0; i < n - 1; ++i)
sum += a[i];
if (sum <= a[n - 1])
cout << "No" << endl;
else
cout << "Yes" << endl;
return 0;
} | [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 938,423 | 938,427 | u146240825 | cpp |
p03136 | #include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef long long LL;
typedef pair<int, int> P;
const LL mod = 1000000007;
const LL LINF = 1LL << 62;
const LL INF = 1 << 17;
int main() {
int N;
cin >> N;
int sum = 0;
vector<int> l(N);
int m = 1000;
for (int i = 0; i < N; i++) {
cin >> l[i];
sum += l[i];
m = min(m, l[i]);
}
if (2 * m < sum)
puts("Yes");
else
puts("No");
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef long long LL;
typedef pair<int, int> P;
const LL mod = 1000000007;
const LL LINF = 1LL << 62;
const LL INF = 1 << 17;
int main() {
int N;
cin >> N;
int sum = 0;
vector<int> l(N);
int m = 0;
for (int i = 0; i < N; i++) {
cin >> l[i];
sum += l[i];
m = max(m, l[i]);
}
if (2 * m < sum)
puts("Yes");
else
puts("No");
return 0;
}
| [
"literal.number.change",
"variable_declaration.value.change",
"misc.opposites",
"assignment.value.change",
"identifier.change",
"call.function.change"
] | 938,428 | 938,429 | u640323045 | cpp |
p03136 | #include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef long long LL;
typedef pair<int, int> P;
const LL mod = 1000000007;
const LL LINF = 1LL << 62;
const LL INF = 1 << 17;
int main() {
int N;
cin >> N;
int sum = 0;
vector<int> l(N);
int m = 1000;
for (int i = 0; i < N; i++) {
cin >> l[i];
sum += l[i];
m = min(m, l[i]);
}
if (m < sum)
puts("Yes");
else
puts("No");
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(), A.end()
#define RALL(A) A.rbegin(), A.rend()
typedef long long LL;
typedef pair<int, int> P;
const LL mod = 1000000007;
const LL LINF = 1LL << 62;
const LL INF = 1 << 17;
int main() {
int N;
cin >> N;
int sum = 0;
vector<int> l(N);
int m = 0;
for (int i = 0; i < N; i++) {
cin >> l[i];
sum += l[i];
m = max(m, l[i]);
}
if (2 * m < sum)
puts("Yes");
else
puts("No");
return 0;
}
| [
"literal.number.change",
"variable_declaration.value.change",
"misc.opposites",
"assignment.value.change",
"identifier.change",
"call.function.change",
"control_flow.branch.if.condition.change"
] | 938,430 | 938,429 | u640323045 | cpp |
p03136 | #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <string.h>
using namespace std;
int main() {
int n;
cin >> n;
int sum = 0;
int maxx = 0;
while (n--) {
int x;
cin >> x;
sum += x;
maxx = max(maxx, x);
}
if (sum - maxx < maxx) {
cout << "Yes";
} else {
cout << "No";
}
return 0;
}
| #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <string.h>
using namespace std;
int main() {
int n;
cin >> n;
int sum = 0;
int maxx = 0;
while (n--) {
int x;
cin >> x;
sum += x;
maxx = max(maxx, x);
}
if (sum - maxx > maxx) {
cout << "Yes";
} else {
cout << "No";
}
return 0;
}
| [
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 938,431 | 938,432 | u428618452 | cpp |
p03136 | #include <iostream>
int main() {
int N;
std::cin >> N;
int maxL = 0;
int sum = 0;
for (int i = 0; i < N; ++i) {
int L;
std::cin >> L;
maxL = std::max(maxL, L);
sum += L;
}
std::cout << ((sum - maxL > maxL) ? "YES" : "NO") << std::endl;
} | #include <iostream>
int main() {
int N;
std::cin >> N;
int maxL = 0;
int sum = 0;
for (int i = 0; i < N; ++i) {
int L;
std::cin >> L;
maxL = std::max(maxL, L);
sum += L;
}
std::cout << ((sum - maxL > maxL) ? "Yes" : "No") << std::endl;
} | [
"literal.string.change",
"literal.string.case.change",
"expression.operation.binary.change"
] | 938,442 | 938,443 | u264304509 | cpp |
p03136 | #define _USE_NATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main() {
int n, len = 0, num, big;
int s[11];
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s[i];
len += s[i];
}
/* 1個目の整数を big に代入 */
big = s[0];
for (int i = 1; i <= n; ++i) {
/* n個目の整数を入力 */
num = s[i];
/* 入力した整数を big と比較 */
if (num > big)
big = num;
}
len = len - big;
if (big < len) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
/*cin >> n >> s;
for (int i = 0; i < n-1; i++) {
for (int j = 0; j < n-1; j++) {
for (int k = 0; k < n-1; k++) {
len = s[i] + s[j] + s[k];
ma = max(s[i], max(s[j], s[k]));
rest = len - ma;
}
}
}
if (ma < rest)
{
cout << "Yes" << endl;
}
else
{
cout << "No" << endl;
}*/
} | #define _USE_NATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int main() {
int n, len = 0, num, big;
int s[11];
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s[i];
len += s[i];
}
/* 1個目の整数を big に代入 */
big = s[0];
for (int i = 1; i < n; ++i) {
/* n個目の整数を入力 */
num = s[i];
/* 入力した整数を big と比較 */
if (num > big)
big = num;
}
len = len - big;
if (big < len) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
/*cin >> n >> s;
for (int i = 0; i < n-1; i++) {
for (int j = 0; j < n-1; j++) {
for (int k = 0; k < n-1; k++) {
len = s[i] + s[j] + s[k];
ma = max(s[i], max(s[j], s[k]));
rest = len - ma;
}
}
}
if (ma < rest)
{
cout << "Yes" << endl;
}
else
{
cout << "No" << endl;
}*/
} | [
"expression.operator.compare.change",
"control_flow.loop.for.condition.change",
"expression.off_by_one",
"expression.operation.binary.change"
] | 938,448 | 938,449 | u419390395 | cpp |
p03136 | #define __USE_MINGW_ANSI_STDIO 0
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <limits.h>
#include <map>
#include <numeric>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
/// 各桁の和
int sumdigit(int x) {
int sum = 0;
while (x != 0) {
sum += x % 10;
x /= 10;
}
return sum;
}
/// 最小公倍数
int gcd(int x, int y) {
if (x < y) {
int temp = x;
x = y;
y = temp;
}
int r = x % y;
while (r != 0) {
x = y;
y = r;
r = x % y;
}
return y;
}
int main() {
int N;
cin >> N;
vector<int> L(N);
for (int i = 0; i < N; i++) {
cin >> L[i];
}
sort(L.begin(), L.end());
if (accumulate(L.begin(), L.end(), 0) - L[N] > L[N])
cout << "Yes" << endl;
else
cout << "No" << endl;
} | #define __USE_MINGW_ANSI_STDIO 0
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <limits.h>
#include <map>
#include <numeric>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
/// 各桁の和
int sumdigit(int x) {
int sum = 0;
while (x != 0) {
sum += x % 10;
x /= 10;
}
return sum;
}
/// 最小公倍数
int gcd(int x, int y) {
if (x < y) {
int temp = x;
x = y;
y = temp;
}
int r = x % y;
while (r != 0) {
x = y;
y = r;
r = x % y;
}
return y;
}
int main() {
int N;
cin >> N;
vector<int> L(N);
for (int i = 0; i < N; i++) {
cin >> L[i];
}
sort(L.begin(), L.end());
if (accumulate(L.begin(), L.end(), 0) - L[N - 1] > L[N - 1])
cout << "Yes" << endl;
else
cout << "No" << endl;
}
| [
"control_flow.branch.if.condition.change"
] | 938,457 | 938,458 | u403848488 | cpp |
p03136 | #include <cstdlib>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#define rep for (int i = 0; i < n; i++)
using namespace std;
int main() {
int n, t = 0, z = 0;
int l[10];
cin >> n;
if (n >= 3) {
rep {
cin >> l[i];
if (l[i] >= l[i - 1] && i > 0)
t = i;
}
rep {
if (i != t) {
z += l[i];
}
}
if (z > l[t]) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
return 0;
} | #include <cstdlib>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#define rep for (int i = 0; i < n; i++)
using namespace std;
int main() {
int n, t = 0, z = 0;
int l[10];
cin >> n;
if (n >= 3) {
rep {
cin >> l[i];
if (l[i] >= l[t] && i > 0)
t = i;
}
rep {
if (i != t) {
z += l[i];
}
}
if (z > l[t]) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
return 0;
} | [
"variable_access.subscript.index.change",
"control_flow.branch.if.condition.change",
"expression.operation.binary.remove"
] | 938,463 | 938,464 | u767622317 | cpp |
p03136 | #include <algorithm>
#include <cstdio>
using namespace std;
int a[10 + 5];
int main() {
int n;
scanf("%d", &n);
int sum = 0;
int maxn = -1;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
sum += a[i];
maxn = max(a[i], maxn);
}
if (sum > 2 * maxn)
puts("YES");
else
puts("NO");
return 0;
} | #include <algorithm>
#include <cstdio>
using namespace std;
int a[10 + 5];
int main() {
int n;
scanf("%d", &n);
int sum = 0;
int maxn = -1;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
sum += a[i];
maxn = max(a[i], maxn);
}
if (sum > 2 * maxn)
printf("Yes");
else
printf("No");
return 0;
} | [
"identifier.change",
"call.function.change",
"io.output.change",
"literal.string.change",
"literal.string.case.change",
"call.arguments.change"
] | 938,467 | 938,468 | u855248478 | cpp |
p03136 | #include <iostream>
using namespace std;
int main() {
int n, l, maxl, all;
int i;
cin >> n;
maxl = 0;
all = 0;
for (i = 0; i < n; i++) {
cin >> l;
if (maxl < l) {
maxl = l;
} else {
all += l;
}
}
if (maxl < all) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
} | #include <iostream>
using namespace std;
int main() {
int n, l, maxl, all;
int i;
cin >> n;
maxl = 0;
all = 0;
for (i = 0; i < n; i++) {
cin >> l;
if (maxl < l) {
all += maxl;
maxl = l;
} else {
all += l;
}
}
if (maxl < all) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
} | [
"assignment.add"
] | 938,469 | 938,470 | u275747032 | cpp |
p03136 | #include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
using namespace std;
int main() {
int n;
cin >> n;
int l[10];
for (int i = 0; i < n; i++) {
cin >> l[i];
}
int max = l[0];
int sumx = l[0];
for (int i = 1; i < n; i++) {
if (l[i] > max) {
max = l[i];
}
sumx += l[i];
}
sumx -= max;
if (max > sumx) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
using namespace std;
int main() {
int n;
cin >> n;
int l[10];
for (int i = 0; i < n; i++) {
cin >> l[i];
}
int max = l[0];
int sumx = l[0];
for (int i = 1; i < n; i++) {
if (l[i] > max) {
max = l[i];
}
sumx += l[i];
}
sumx -= max;
if (max < sumx) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
| [
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 938,475 | 938,476 | u209767598 | cpp |
p03136 | #include <stdio.h>
int main() {
int n = 0;
int l[100] = {0};
int i;
int a = 0;
int sum = 0;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &l[i]);
if (a > l[i]) {
a = l[i];
}
sum += l[i];
}
sum = sum - a;
if (a < sum) {
printf("Yes");
} else if (a >= sum) {
printf("No");
}
return 0;
} | #include <stdio.h>
int main() {
int n = 0;
int l[100] = {0};
int i;
int a = 0;
int sum = 0;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &l[i]);
if (a < l[i]) {
a = l[i];
}
sum += l[i];
}
sum = sum - a;
if (a < sum) {
printf("Yes");
} else if (a >= sum) {
printf("No");
}
return 0;
} | [
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 938,481 | 938,482 | u824293895 | cpp |
p03136 | #include <iostream>
using namespace std;
int main() {
int n, l[10], max = 0, p, sum = 0;
cin >> n;
for (int i = 0; i < n; i++)
cin >> l[i];
for (int i = 0; i < n; i++) {
if (l[i] > max) {
max = l[i];
p = i;
}
}
l[p] = 0;
for (int i = 0; i < n; i++)
sum += l[i];
if (max > sum)
cout << "No" << endl;
else
cout << "Yes" << endl;
return 0;
}
| #include <iostream>
using namespace std;
int main() {
int n, l[10], max = 0, p, sum = 0;
cin >> n;
for (int i = 0; i < n; i++)
cin >> l[i];
for (int i = 0; i < n; i++) {
if (l[i] > max) {
max = l[i];
p = i;
}
}
l[p] = 0;
for (int i = 0; i < n; i++)
sum += l[i];
if (max >= sum)
cout << "No" << endl;
else
cout << "Yes" << endl;
return 0;
}
| [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 938,483 | 938,484 | u717982428 | cpp |
p03136 | #include <iostream>
using namespace std;
int main(void) {
int N, L, M, S;
cin >> N >> L;
M = L;
S = L;
for (int i = 1; i <= N; i++) {
cin >> L;
S = S + L;
if (L > M) {
M = L;
}
}
S = S - M;
if (S > M) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
} | #include <iostream>
using namespace std;
int main(void) {
int N, L, M, S;
cin >> N >> L;
M = L;
S = L;
for (int i = 1; i < N; i++) {
cin >> L;
S = S + L;
if (L > M) {
M = L;
}
}
S = S - M;
if (S > M) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
}
| [
"expression.operator.compare.change",
"control_flow.loop.for.condition.change",
"expression.off_by_one",
"expression.operation.binary.change"
] | 938,488 | 938,489 | u813840685 | cpp |
p03136 | #include <iostream>
#include <stdio.h>
using namespace std;
int main() {
int a, b, sum = 0, maxa;
int s[10];
cin >> a;
for (int i = 0; i < a; i++)
cin >> s[i];
maxa = 0;
for (int i = 0; i < a; i++)
if (s[i] > s[maxa])
maxa = i;
for (int i = 0; i < a; i++)
if (i != maxa)
sum += s[i];
if (maxa >= sum)
cout << "No" << endl;
else
cout << "Yes" << endl;
return 0;
}
| #include <iostream>
#include <stdio.h>
using namespace std;
int main() {
int a, b, sum = 0, maxa;
int s[10];
cin >> a;
for (int i = 0; i < a; i++)
cin >> s[i];
maxa = 0;
for (int i = 0; i < a; i++)
if (s[i] > s[maxa])
maxa = i;
for (int i = 0; i < a; i++)
if (i != maxa)
sum += s[i];
if (s[maxa] >= sum)
cout << "No" << endl;
else
cout << "Yes" << endl;
return 0;
}
| [
"control_flow.branch.if.condition.change"
] | 938,490 | 938,491 | u587326496 | cpp |
p03136 | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> vec(N);
for (int i = 0; i < N; i++) {
cin >> vec.at(i);
}
int sum = 0;
for (int i = 0; i < N; i++) {
sum += vec.at(i);
}
sort(vec.begin(), vec.end());
if (vec.at(N) * 2 < sum) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> vec(N);
for (int i = 0; i < N; i++) {
cin >> vec.at(i);
}
int sum = 0;
for (int i = 0; i < N; i++) {
sum += vec.at(i);
}
sort(vec.begin(), vec.end());
if (vec.at(N - 1) * 2 < sum) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | [
"control_flow.branch.if.condition.change"
] | 938,494 | 938,495 | u068896454 | cpp |
p03136 | #include <algorithm>
#include <iostream>
using namespace std;
int main(void) {
int n;
cin >> n;
int a[n - 1];
int x;
x = 0;
int s;
for (int i = 0; i <= n - 1; ++i) {
cin >> a[i];
}
for (int i = 0; i <= n - 1; ++i) {
x = max(a[i], x);
s = s + a[i];
}
if (s > 2 * x) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
}
| #include <algorithm>
#include <iostream>
using namespace std;
int main(void) {
int n;
cin >> n;
int a[n - 1];
int x;
x = 0;
int s;
s = 0;
for (int i = 0; i <= n - 1; ++i) {
cin >> a[i];
}
for (int i = 0; i <= n - 1; ++i) {
x = max(a[i], x);
s = s + a[i];
}
if (s > 2 * x) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
}
| [
"assignment.add"
] | 938,498 | 938,499 | u229603190 | cpp |
p03136 | #include <algorithm>
#include <iostream>
#include <iterator>
#include <vector>
using namespace std;
int main(void) {
int N = 0;
int a[11];
cin >> N;
for (int i = 0; i < N; i++) {
cin >> a[i];
}
vector<int> v(begin(a), end(a));
sort(v.begin(), v.end());
int sum = 0;
int Longest = v[N - 1];
for (int i = 0; i < N - 1; i++) {
sum += v[i]; // if(v[i] != Longest)
}
if (sum > Longest) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | #include <algorithm>
#include <iostream>
#include <iterator>
#include <vector>
using namespace std;
int main(void) {
int N = 0;
int a[11];
cin >> N;
for (int i = 0; i < N; i++) {
cin >> a[i];
}
vector<int> v(begin(a), a + N);
sort(v.begin(), v.end());
int sum = 0;
int Longest = v[N - 1];
for (int i = 0; i < N - 1; i++) {
sum += v[i]; // if(v[i] != Longest)
}
if (sum > Longest) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | [
"call.arguments.change"
] | 938,502 | 938,503 | u969108099 | cpp |
p03136 | #include <bits/stdc++.h>
using namespace std;
int main() {
int t, a[100], i = 0;
cin >> t;
while (i < t) {
cin >> a[i];
i++;
}
int m = 0, s = 0, f = 0;
for (i = 0; i < t; i++) {
s = 0;
for (m = 0; m < i; m++) {
s = s + a[m];
}
for (m = (i + 1); m < t; m++) {
s = s + a[m];
}
if (s >= a[i]) {
f = 1;
break;
}
}
if (f == 0)
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int t, a[100], i = 0;
cin >> t;
while (i < t) {
cin >> a[i];
i++;
}
int m = 0, s = 0, f = 0;
for (i = 0; i < t; i++) {
s = 0;
for (m = 0; m < i; m++) {
s = s + a[m];
}
for (m = (i + 1); m < t; m++) {
s = s + a[m];
}
if (s <= a[i]) {
f = 1;
break;
}
}
if (f == 0)
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
}
| [
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 938,504 | 938,505 | u114412537 | cpp |
p03136 | #include <bits/stdc++.h>
using namespace std;
int main() {
int t, a[100], i = 0;
cin >> t;
while (i < t) {
cin >> a[t];
i++;
}
int m = 0, s = 0, f = 0;
for (i = 0; i < t; i++) {
s = 0;
for (m = 0; m < i; m++) {
s = s + a[m];
}
for (m = (i + 1); m < t; m++) {
s = s + a[m];
}
if (s >= a[i]) {
f = 1;
break;
}
}
if (f == 0)
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int t, a[100], i = 0;
cin >> t;
while (i < t) {
cin >> a[i];
i++;
}
int m = 0, s = 0, f = 0;
for (i = 0; i < t; i++) {
s = 0;
for (m = 0; m < i; m++) {
s = s + a[m];
}
for (m = (i + 1); m < t; m++) {
s = s + a[m];
}
if (s <= a[i]) {
f = 1;
break;
}
}
if (f == 0)
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
}
| [
"identifier.change",
"variable_access.subscript.index.change",
"expression.operation.binary.change",
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 938,506 | 938,505 | u114412537 | cpp |
p03136 | #include <bits/stdc++.h>
using namespace std;
int main() {
int t, a[100], i = 0;
cin >> t;
while (i < t) {
cin >> a[t];
i++;
}
int m = 0, s = 0, f = 0;
for (i = 0; i < t; i++) {
s = 0;
for (m = 0; m < i; m++) {
s = s + a[i];
}
for (m = (i + 1); m < t; m++) {
s = s + a[i];
}
if (s >= a[i]) {
f = 1;
break;
}
}
if (f == 0)
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int t, a[100], i = 0;
cin >> t;
while (i < t) {
cin >> a[i];
i++;
}
int m = 0, s = 0, f = 0;
for (i = 0; i < t; i++) {
s = 0;
for (m = 0; m < i; m++) {
s = s + a[m];
}
for (m = (i + 1); m < t; m++) {
s = s + a[m];
}
if (s <= a[i]) {
f = 1;
break;
}
}
if (f == 0)
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
}
| [
"identifier.change",
"variable_access.subscript.index.change",
"expression.operation.binary.change",
"assignment.value.change",
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 938,507 | 938,505 | u114412537 | cpp |
p03136 | #include <bits/stdc++.h>
using namespace std;
int main() {
int a = 0, b = 0, N = 0;
string res = "NO";
cin >> N;
vector<int> C(N);
for (int i = 0; i < N; i++) {
cin >> C.at(i);
}
sort(C.begin(), C.end());
a = C.at(N - 1);
for (int i = 0; i < N - 1; i++) {
b = b + C.at(i);
}
if (a < b) {
res = "YES";
}
cout << res << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int a = 0, b = 0, N = 0;
string res = "No";
cin >> N;
vector<int> C(N);
for (int i = 0; i < N; i++) {
cin >> C.at(i);
}
sort(C.begin(), C.end());
a = C.at(N - 1);
for (int i = 0; i < N - 1; i++) {
b = b + C.at(i);
}
if (a < b) {
res = "Yes";
}
cout << res << endl;
}
| [
"literal.string.change",
"literal.string.case.change",
"variable_declaration.value.change",
"assignment.value.change"
] | 938,512 | 938,513 | u228108760 | cpp |
p03136 | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> vec(N);
for (int i = 0; i < N; i++) {
cin >> vec.at(i);
}
sort(vec.begin(), vec.end());
int result = 0;
for (int i = 0; i < N - 2; i++) {
result += vec.at(i);
}
if (result > vec.at(N - 1)) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> vec(N);
for (int i = 0; i < N; i++) {
cin >> vec.at(i);
}
sort(vec.begin(), vec.end());
int result = 0;
for (int i = 0; i < N - 1; i++) {
result += vec.at(i);
}
if (result > vec.at(N - 1)) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | [
"literal.number.change",
"control_flow.loop.for.condition.change",
"expression.off_by_one",
"expression.operation.binary.change"
] | 938,520 | 938,521 | u705362558 | cpp |
p03136 | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> vec(N);
for (int i = 0; i < N; i++) {
cin >> vec.at(i);
}
sort(vec.begin(), vec.end());
int result = 0;
for (int i = 0; i < N - 1; i++) {
result += vec.at(i);
}
if (result > vec.at(N)) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> vec(N);
for (int i = 0; i < N; i++) {
cin >> vec.at(i);
}
sort(vec.begin(), vec.end());
int result = 0;
for (int i = 0; i < N - 1; i++) {
result += vec.at(i);
}
if (result > vec.at(N - 1)) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | [
"control_flow.branch.if.condition.change"
] | 938,522 | 938,521 | u705362558 | cpp |
p03136 | #include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define INF 1e9
#define MOD 1000000007
#define ll long long
using namespace std;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
typedef unsigned long long ull;
typedef pair<ll, int> pr;
ll a[100001];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> l(n);
int x = 0;
for (int i = 0; i < n; i++) {
cin >> l[i];
x += l[i];
}
int ma = *max_element(l.begin(), l.end());
if (ma < x - ma) {
cout << "Yes" << endl;
} else {
cout << "N0" << endl;
}
return 0;
} | #include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define INF 1e9
#define MOD 1000000007
#define ll long long
using namespace std;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
typedef unsigned long long ull;
typedef pair<ll, int> pr;
ll a[100001];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> l(n);
int x = 0;
for (int i = 0; i < n; i++) {
cin >> l[i];
x += l[i];
}
int ma = *max_element(l.begin(), l.end());
if (ma < x - ma) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
} | [
"literal.string.change",
"io.output.change"
] | 938,523 | 938,524 | u388552482 | cpp |
p03136 | #include <iostream>
#include <numeric>
#include <vector>
using namespace std;
int main() {
int N;
vector<int> L;
cin >> N;
for (int i = 0; i < N; i++) {
int x;
cin >> x;
L.push_back(x);
}
int max = 0;
for (int i = 0; i < N; i++) {
if (L[i] > max) {
max = L[i];
}
}
int sum = std::accumulate(L.begin(), L.end(), 0);
if (max < sum - max) {
cout << "Yes" << endl;
} else {
cout << "NO" << endl;
}
return 0;
}
|
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
int main() {
int N;
vector<int> L;
cin >> N;
for (int i = 0; i < N; i++) {
int x;
cin >> x;
L.push_back(x);
}
int max = 0;
for (int i = 0; i < N; i++) {
if (L[i] > max) {
max = L[i];
}
}
int sum = std::accumulate(L.begin(), L.end(), 0);
if (max < sum - max) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
}
| [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 938,525 | 938,526 | u679866004 | cpp |
p03136 | #include <stdio.h>
int main(void) {
int n;
scanf("%d", &n);
int L[n], i;
for (i = 0; i < n; i++) {
scanf("%d", &L[i]);
}
int j, k = 0, l;
j = L[0];
for (i = 0; i < n; i++) {
if (j < L[i]) {
j = L[i];
}
}
for (i = 0; i < n; i++) {
k = k + L[i];
}
if (j < k - j) {
puts("YES");
} else {
puts("NO");
}
return 0;
} | #include <stdio.h>
int main(void) {
int n;
scanf("%d", &n);
int L[n], i;
for (i = 0; i < n; i++) {
scanf("%d", &L[i]);
}
int j, k = 0, l;
j = L[0];
for (i = 0; i < n; i++) {
if (j < L[i]) {
j = L[i];
}
}
for (i = 0; i < n; i++) {
k = k + L[i];
}
if (j < k - j) {
puts("Yes");
} else {
puts("No");
}
return 0;
} | [
"literal.string.change",
"literal.string.case.change",
"call.arguments.change",
"io.output.change"
] | 938,532 | 938,533 | u368279380 | cpp |
p03136 | #include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
int main() {
int n;
int l[101];
cin >> n;
for (int i = 0; i < n; i++)
cin >> l[i];
int max = 0;
int sum = 0;
for (int i = 0; i < n; i++) {
if (max < l[i])
max = l[i];
sum += l[i];
}
if (sum >= max) {
cout << "Yes";
} else {
cout << "No";
}
return 0;
}
| #include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
int main() {
int n;
int l[101];
cin >> n;
for (int i = 0; i < n; i++)
cin >> l[i];
int max = 0;
int sum = 0;
for (int i = 0; i < n; i++) {
if (max < l[i])
max = l[i];
sum += l[i];
}
if ((sum - max) > max) {
cout << "Yes";
} else {
cout << "No";
}
return 0;
}
| [
"control_flow.branch.if.condition.change"
] | 938,534 | 938,535 | u477651929 | cpp |
p03136 | #include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
int main() {
int n;
int l[101];
cin >> n;
for (int i = 0; i < n; i++)
cin >> l[i];
int max = 0;
int sum = 0;
for (int i = 0; i < n; i++) {
if (max < l[i])
max = l[i];
sum += l[i];
}
if (sum > max) {
cout << "Yes";
} else {
cout << "No";
}
return 0;
}
| #include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
int main() {
int n;
int l[101];
cin >> n;
for (int i = 0; i < n; i++)
cin >> l[i];
int max = 0;
int sum = 0;
for (int i = 0; i < n; i++) {
if (max < l[i])
max = l[i];
sum += l[i];
}
if ((sum - max) > max) {
cout << "Yes";
} else {
cout << "No";
}
return 0;
}
| [
"control_flow.branch.if.condition.change"
] | 938,536 | 938,535 | u477651929 | cpp |
p03136 | #include <iostream>
using namespace std;
int main() {
int N;
cin >> N;
int l[N];
for (int i = 0; i < N; i++) {
cin >> l[i];
}
int max = l[0];
int sum = 0;
for (int i = 0; i < N; i++) {
if (max < l[i]) {
max = l[i];
}
sum += l[i];
}
sum -= max;
if (max < sum) {
cout << "YES";
} else {
cout << "NO";
}
return 0;
} | #include <iostream>
using namespace std;
int main() {
int N;
cin >> N;
int l[N];
for (int i = 0; i < N; i++) {
cin >> l[i];
}
int max = l[0];
int sum = 0;
for (int i = 0; i < N; i++) {
if (max < l[i]) {
max = l[i];
}
sum += l[i];
}
sum -= max;
if (max < sum) {
cout << "Yes";
} else {
cout << "No";
}
return 0;
} | [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 938,539 | 938,540 | u227379863 | cpp |
p03136 | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define ld long double
using namespace std;
ll a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;
ll ans = 0, mx = 0, mn = 1e9, sum = 0, cnt = 0, avr = 0, index = 0;
// map<int, int>freq;
vector<int> vec;
vector<int> res;
vector<int> freq(10000 + 5, 0);
vector<int> cFreq(150, -1);
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x;
vec.push_back(x);
mx = max(mx, x);
sum += vec[i];
}
ll sub = sum - mx;
if (sub > mx)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define ld long double
using namespace std;
ll a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;
ll ans = 0, mx = 0, mn = 1e9, sum = 0, cnt = 0, avr = 0, index = 0;
// map<int, int>freq;
vector<int> vec;
vector<int> res;
vector<int> freq(10000 + 5, 0);
vector<int> cFreq(150, -1);
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x;
vec.push_back(x);
mx = max(mx, x);
sum += vec[i];
}
ll sub = sum - mx;
if (sub > mx)
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
} | [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 938,541 | 938,542 | u261607462 | cpp |
p03136 | #include <bits/stdc++.h>
#define int long long
#define f(i, n) for (int i = 0; i < n; i++)
#define F first
#define S second
#define mod 1000000007
#define P pair<int, int>
using namespace std;
signed main() {
int n, a = 0, b, ma = 0;
cin >> n;
f(i, n) {
cin >> b;
a += b;
ma = max(ma, b);
}
if (a >= ma * 2)
puts("Yes");
else
puts("No");
return 0;
}
| #include <bits/stdc++.h>
#define int long long
#define f(i, n) for (int i = 0; i < n; i++)
#define F first
#define S second
#define mod 1000000007
#define P pair<int, int>
using namespace std;
signed main() {
int n, a = 0, b, ma = 0;
cin >> n;
f(i, n) {
cin >> b;
a += b;
ma = max(ma, b);
}
if (a > ma * 2)
puts("Yes");
else
puts("No");
return 0;
}
| [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 938,545 | 938,546 | u259210975 | cpp |
p03136 | #include <bits/stdc++.h>
using namespace std;
int n, l[15];
int a, b, sum;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> l[i];
sum += l[i];
if (a < l[i]) {
a = l[i];
b = i;
}
}
sum -= a;
if (a < sum) {
cout << "YES";
} else
cout << "NO";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int n, l[15];
int a, b, sum;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> l[i];
sum += l[i];
if (a < l[i]) {
a = l[i];
b = i;
}
}
sum -= a;
if (a < sum) {
cout << "Yes";
} else
cout << "No";
return 0;
} | [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 938,551 | 938,552 | u030226344 | cpp |
p03136 | #include <bits/stdc++.h>
using namespace std;
int n, l[15];
int a, b, sum;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> l[i];
sum += l[i];
if (a < l[i]) {
a = l[i];
b = i;
}
}
sum -= a;
if (a < sum) {
cout << "YES\n";
} else
cout << "NO\n";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int n, l[15];
int a, b, sum;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> l[i];
sum += l[i];
if (a < l[i]) {
a = l[i];
b = i;
}
}
sum -= a;
if (a < sum) {
cout << "Yes";
} else
cout << "No";
return 0;
} | [
"literal.string.change",
"io.output.change"
] | 938,553 | 938,552 | u030226344 | cpp |
p03136 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
int L[10];
int goukei = 0;
rep(i, N) {
cin >> L[i];
goukei += L[i];
}
int saidai = *max_element(L, L + N);
goukei -= saidai;
ce(goukei);
ce(saidai);
if (saidai < goukei)
co("YES");
else
co("NO");
Would you please return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
int L[10];
int goukei = 0;
rep(i, N) {
cin >> L[i];
goukei += L[i];
}
int saidai = *max_element(L, L + N);
goukei -= saidai;
ce(goukei);
ce(saidai);
if (saidai < goukei)
co("Yes");
else
co("No");
Would you please return 0;
} | [
"literal.string.change",
"literal.string.case.change",
"call.arguments.change"
] | 938,554 | 938,555 | u096883693 | cpp |
p03136 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, i, ma, sum;
cin >> n;
ma = -1;
for (i = 0; i < n; i++) {
cin >> x;
ma = max(ma, x);
sum += (x);
}
if (ma < sum - ma)
cout << "Yes";
else
cout << "No";
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, i, ma, sum = 0;
cin >> n;
ma = -1;
for (i = 0; i < n; i++) {
cin >> x;
ma = max(ma, x);
sum += (x);
}
if (ma < sum - ma)
cout << "Yes";
else
cout << "No";
}
| [
"variable_declaration.value.change"
] | 938,562 | 938,563 | u960410816 | cpp |
p03136 | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
const int Max = 1e6 + 5;
typedef long long ll;
ll sum;
int a[Max];
int main() {
int n, m;
while (~scanf("%d", &n)) {
sum = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
sum += a[i];
}
sort(a, a + n, greater<int>());
sum -= a[0];
if (a[0] < sum)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
const int Max = 1e6 + 5;
typedef long long ll;
ll sum;
int a[Max];
int main() {
int n, m;
while (~scanf("%d", &n)) {
sum = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
sum += a[i];
}
sort(a, a + n, greater<int>());
sum -= a[0];
if (a[0] < sum)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
} | [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 938,566 | 938,567 | u560140313 | cpp |
p03136 | #include <bits/stdc++.h>
using namespace std;
const int N = 110;
int a[N], n;
int main() {
cin >> n;
int sum = 0;
for (int i = 1; i <= n; ++i)
cin >> a[i], sum += a[i];
for (int i = 1; i <= n; ++i)
if (a[i] > sum - a[i]) {
puts("No");
return 0;
}
puts("Yes");
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int N = 110;
int a[N], n;
int main() {
cin >> n;
int sum = 0;
for (int i = 1; i <= n; ++i)
cin >> a[i], sum += a[i];
for (int i = 1; i <= n; ++i)
if (a[i] >= sum - a[i]) {
puts("No");
return 0;
}
puts("Yes");
return 0;
} | [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 938,568 | 938,569 | u424683247 | cpp |
p03136 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int l[n];
for (int i = 0; i < n; i++) {
cin >> l[i];
}
sort(l, l + n);
int sum = 0;
for (int i = 0; i < n - 1; i++) {
sum += l[i];
}
if (l[n] < sum) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int l[n];
for (int i = 0; i < n; i++) {
cin >> l[i];
}
sort(l, l + n);
int sum = 0;
for (int i = 0; i < n - 1; i++) {
sum += l[i];
}
if (l[n - 1] < sum) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
| [
"control_flow.branch.if.condition.change"
] | 938,583 | 938,584 | u911147723 | cpp |
p03136 | #include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define mod ((ull)1e9 + 7)
#define MAX ((ull)1e9)
int main() {
int n;
cin >> n;
int l[n], max = 0, sum = 0;
for (int i = 0; i < n; i++) {
cin >> l[i];
sum += l[i];
if (max < l[i])
;
max = l[i];
}
if (2 * max <= sum)
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define mod ((ull)1e9 + 7)
#define MAX ((ull)1e9)
int main() {
int n;
cin >> n;
int l[n], max = 0, sum = 0;
for (int i = 0; i < n; i++) {
cin >> l[i];
sum += l[i];
if (max < l[i])
max = l[i];
}
if (2 * max < sum)
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
} | [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 938,585 | 938,586 | u348670055 | cpp |
p03136 | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
typedef long long llong;
int main() {
int N, L[11], max_index = 0;
cin >> N;
for (int i = 0; i < N; ++i) {
cin >> L[i];
if (L[max_index] < L[i]) {
max_index = i;
}
}
int smaller_sum = 0;
for (int k = 0; k < N; ++k) {
if (k != max_index) {
smaller_sum += L[k];
}
}
if (smaller_sum > L[max_index]) {
cout << "Yes" << endl;
} else {
cout << "NO" << endl;
}
return 0;
}
| #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
typedef long long llong;
int main() {
int N, L[11], max_index = 0;
cin >> N;
for (int i = 0; i < N; ++i) {
cin >> L[i];
if (L[max_index] < L[i]) {
max_index = i;
}
}
int smaller_sum = 0;
for (int k = 0; k < N; ++k) {
if (k != max_index) {
smaller_sum += L[k];
}
}
if (smaller_sum > L[max_index]) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
}
| [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 938,591 | 938,592 | u571053945 | cpp |
p03136 | #include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
int main(void) {
int n;
vector<int> p;
cin >> n;
for (int i = 0; i < n; i++) {
int tmp;
cin >> tmp;
p.push_back(tmp);
}
auto hoge = min_element(p.begin(), p.end());
int sum = accumulate(p.begin(), p.end(), 0);
if (sum - *hoge > *hoge) {
cout << "Yes";
} else {
cout << "No";
}
} | #include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
int main(void) {
int n;
vector<int> p;
cin >> n;
for (int i = 0; i < n; i++) {
int tmp;
cin >> tmp;
p.push_back(tmp);
}
auto hoge = max_element(p.begin(), p.end());
int sum = accumulate(p.begin(), p.end(), 0);
if (sum - *hoge > *hoge) {
cout << "Yes";
} else {
cout << "No";
}
} | [
"identifier.change",
"call.function.change"
] | 938,593 | 938,594 | u229579906 | cpp |
p03136 | #include <iostream>
using namespace std;
int main() {
int n;
int maxnum = 0;
int sum = 0;
cin >> n;
for (int i = 1; i <= n; i++) {
int tmp;
cin >> tmp;
maxnum = max(maxnum, tmp);
sum += tmp;
}
if (sum - maxnum >= maxnum)
cout << "Yes";
else
cout << "No";
return 0;
} | #include <iostream>
using namespace std;
int main() {
int n;
int maxnum = 0;
int sum = 0;
cin >> n;
for (int i = 1; i <= n; i++) {
int tmp;
cin >> tmp;
maxnum = max(maxnum, tmp);
sum += tmp;
}
if (sum - maxnum > maxnum)
cout << "Yes";
else
cout << "No";
return 0;
} | [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 938,595 | 938,596 | u536406706 | cpp |
p03136 | #include <iostream>
using namespace std;
int main() {
int a, b[100], c = 0, d;
cin >> a;
for (int i = 0; i < a; i++) {
cin >> b[i];
d += b[i];
if (c < b[i]) {
c = b[i];
}
}
if (c < d - c) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
} | #include <iostream>
using namespace std;
int main() {
int a, b[10], c = 0, d = 0;
cin >> a;
for (int i = 0; i < a; i++) {
cin >> b[i];
d += b[i];
if (c < b[i]) {
c = b[i];
}
}
if (c < d - c) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | [
"literal.number.change",
"variable_declaration.array_dimensions.change",
"variable_declaration.value.change",
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 938,599 | 938,598 | u805131136 | cpp |
p03136 | #include <stdio.h>
using namespace std;
int main() {
int n, l[100];
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &l[i]);
}
int max = 0, sum = 0;
for (int i = 0; i < n; i++) {
if (max < l[i])
max = l[i];
sum += l[i];
}
// printf("%d",sum);
printf("%s\n", (sum - max < max) ? "Yes" : "No");
return 0;
}
| #include <stdio.h>
using namespace std;
int main() {
int n, l[100];
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &l[i]);
}
int max = 0, sum = 0;
for (int i = 0; i < n; i++) {
if (max < l[i])
max = l[i];
sum += l[i];
}
// printf("%d",sum);
printf("%s\n", (sum - max > max) ? "Yes" : "No");
return 0;
}
| [
"misc.opposites",
"expression.operator.compare.change",
"control_flow.loop.for.condition.change",
"call.arguments.change",
"expression.operation.binary.change",
"io.output.change"
] | 938,603 | 938,604 | u906738968 | cpp |
p03136 | #include <iostream>
using namespace std;
int main() {
int N;
cin >> N;
int sum;
int longest = 0;
for (int i = 0; i < N; ++i) {
int tmp;
cin >> tmp;
sum += tmp;
if (tmp > longest)
longest = tmp;
}
sum -= longest;
if (longest < sum)
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
} | #include <iostream>
using namespace std;
int main() {
int N;
cin >> N;
int sum = 0;
int longest = 0;
for (int i = 0; i < N; ++i) {
int tmp;
cin >> tmp;
sum += tmp;
if (tmp > longest)
longest = tmp;
}
sum -= longest;
if (longest < sum)
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
} | [
"variable_declaration.value.change"
] | 938,605 | 938,606 | u067267922 | cpp |
p03136 | #include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <vector>
using namespace std;
using ll = long long;
int main() {
ll n, sum = 0;
cin >> n;
vector<ll> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a.begin(), a.end());
for (int i = 1; i < n; i++) {
sum += a[n - i];
}
if (sum > a[n - 1])
cout << "Yes\n";
else
cout << "No\n";
} | #include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <vector>
using namespace std;
using ll = long long;
int main() {
ll n, sum = 0;
cin >> n;
vector<ll> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a.begin(), a.end());
for (int i = 1; i < n; i++) {
sum += a[n - i - 1];
}
if (sum > a[n - 1])
cout << "Yes\n";
else
cout << "No\n";
}
| [
"assignment.change"
] | 938,613 | 938,614 | u327242197 | cpp |
p03136 | #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb emplace_back
#define INF (1e9 + 1)
int main() {
int n;
cin >> n;
vector<int> v(n);
rep(i, n) cin >> v[i];
sort(all(v));
int sum = 0;
rep(i, n - 1) sum += v[i];
if (v.back() > sum)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
| #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb emplace_back
#define INF (1e9 + 1)
int main() {
int n;
cin >> n;
vector<int> v(n);
rep(i, n) cin >> v[i];
sort(all(v));
int sum = 0;
rep(i, n - 1) sum += v[i];
if (v.back() < sum)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
| [
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 938,622 | 938,623 | u864550097 | cpp |
p03137 | #include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define mod 1000000007
#define INF2 9999999999
#define INF (1 << 30)
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define P pair<int, int>
using namespace std;
using ll = int64_t;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int DX[] = {1, 1, 0, -1, -1, -1, 0, 1};
int DY[] = {0, -1, -1, -1, 0, 1, 1, 1};
void solve() {
int n, m, res = 0;
vector<int> x, cost;
cin >> n >> m;
rep(i, m) {
int temp;
cin >> temp;
x.push_back(temp);
}
sort(x.begin(), x.end());
for (auto i = x.begin(); i != x.end(); i++) {
if (i == x.end() - 1)
break;
int c = (*(i + 1)) - (*i);
// cout << "cost: " << c << endl;
cost.push_back(c);
res += c;
}
// cout << "res: " << res << endl;
sort(cost.begin(), cost.end());
reverse(cost.begin(), cost.end());
if (m == 1) {
cout << 0 << endl;
return;
} else {
for (int i = 0; i < n - 1; i++) {
res -= cost[i];
}
}
cout << res << endl;
}
int main() {
solve();
return 0;
} | #include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define mod 1000000007
#define INF2 9999999999
#define INF (1 << 30)
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define P pair<int, int>
using namespace std;
using ll = int64_t;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int DX[] = {1, 1, 0, -1, -1, -1, 0, 1};
int DY[] = {0, -1, -1, -1, 0, 1, 1, 1};
void solve() {
int n, m, res = 0;
vector<int> x, cost;
cin >> n >> m;
rep(i, m) {
int temp;
cin >> temp;
x.push_back(temp);
}
sort(x.begin(), x.end());
for (auto i = x.begin(); i != x.end(); i++) {
if (i == x.end() - 1)
break;
int c = (*(i + 1)) - (*i);
// cout << "cost: " << c << endl;
cost.push_back(c);
res += c;
}
// cout << "res: " << res << endl;
sort(cost.begin(), cost.end());
reverse(cost.begin(), cost.end());
if (n >= m) {
cout << 0 << endl;
return;
} else {
for (int i = 0; i < n - 1; i++) {
res -= cost[i];
}
}
cout << res << endl;
}
int main() {
solve();
return 0;
} | [
"control_flow.branch.if.condition.change",
"expression.operation.binary.remove"
] | 938,647 | 938,648 | u679071005 | cpp |
p03137 | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
int X[M];
for (int i = 0; i < M; i++) {
cin >> X[i];
}
if (N >= M) {
cout << 0;
} else {
sort(X, X + M);
/*
int flag=1;
int tmp=0;
while(flag==1){
flag=0;
for(int i=0;i<M-1;i++){
if(X[i]>X[i+1]){
tmp = X[i+1];
X[i+1] = X[i];
X[i] = tmp;
flag=1;
}
}
}
*/
//差分取得
int dif[M - 1];
for (int i = 0; i < M - 1; i++) {
dif[i] = X[i + 1] - X[i];
// cout << dif[i];
}
/*
flag=1;
tmp=0;
//Xソート
while(flag==1){
flag=0;
for(int i=0;i<M-2;i++){
if(dif[i]>dif[i+1]){
tmp = dif[i+1];
dif[i+1] = dif[i];
dif[i] = tmp;
flag=1;
}
}
}
*/
sort(dif, dif + M - 2);
int answer = 0;
for (int i = 0; i < M - N; i++) {
answer += dif[i];
}
cout << answer;
}
return 0;
}
| #include <algorithm>
#include <iostream>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
int X[M];
for (int i = 0; i < M; i++) {
cin >> X[i];
}
if (N >= M) {
cout << 0;
} else {
sort(X, X + M);
/*
int flag=1;
int tmp=0;
while(flag==1){
flag=0;
for(int i=0;i<M-1;i++){
if(X[i]>X[i+1]){
tmp = X[i+1];
X[i+1] = X[i];
X[i] = tmp;
flag=1;
}
}
}
*/
//差分取得
int dif[M - 1];
for (int i = 0; i < M - 1; i++) {
dif[i] = X[i + 1] - X[i];
// cout << dif[i];
}
/*
flag=1;
tmp=0;
//Xソート
while(flag==1){
flag=0;
for(int i=0;i<M-2;i++){
if(dif[i]>dif[i+1]){
tmp = dif[i+1];
dif[i+1] = dif[i];
dif[i] = tmp;
flag=1;
}
}
}
*/
sort(dif, dif + M - 1);
int answer = 0;
for (int i = 0; i < M - N; i++) {
answer += dif[i];
}
cout << answer;
}
return 0;
}
| [
"literal.number.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 938,649 | 938,650 | u842388336 | cpp |
p03137 | #include <stdio.h>
int N, M;
int X[100000], D[99999];
void merge_sort(int *a, int n) {
if (n == 1)
return;
int m = n / 2;
merge_sort(a, m);
merge_sort(a + m, n - m);
static int a_[100000];
for (int i = 0; i < n; i++) {
a_[i] = a[i];
}
int i = 0;
int j = m;
int k = 0;
while (i < m || j < n) {
if (j == n || (i < m && a_[i] <= a_[j])) {
a[k++] = a_[i++];
} else {
a[k++] = a_[j++];
}
}
}
int main() {
scanf("%d %d", &N, &M);
for (int i = 0; i < M; i++) {
scanf("%d", &X[i]);
}
merge_sort(X, M);
int ans = 0;
for (int i = 0; i + 1 < M; i++) {
D[i] = X[i + 1] - X[i];
ans += D[i];
}
merge_sort(D, M - 1);
int k = M - 2;
while (k >= 0 && N >= 2) {
ans -= D[k--];
N--;
}
printf("%d\n", ans);
return 0;
}
| #include <stdio.h>
int N, M;
int X[100000], D[99999];
void merge_sort(int *a, int n) {
if (n <= 1)
return;
int m = n / 2;
merge_sort(a, m);
merge_sort(a + m, n - m);
static int a_[100000];
for (int i = 0; i < n; i++) {
a_[i] = a[i];
}
int i = 0;
int j = m;
int k = 0;
while (i < m || j < n) {
if (j == n || (i < m && a_[i] <= a_[j])) {
a[k++] = a_[i++];
} else {
a[k++] = a_[j++];
}
}
}
int main() {
scanf("%d %d", &N, &M);
for (int i = 0; i < M; i++) {
scanf("%d", &X[i]);
}
merge_sort(X, M);
int ans = 0;
for (int i = 0; i + 1 < M; i++) {
D[i] = X[i + 1] - X[i];
ans += D[i];
}
merge_sort(D, M - 1);
int k = M - 2;
while (k >= 0 && N >= 2) {
ans -= D[k--];
N--;
}
printf("%d\n", ans);
return 0;
}
| [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 938,692 | 938,693 | u006493569 | cpp |
p03137 | #include "bits/stdc++.h"
using namespace std;
void solve() {
int N, M;
cin >> N >> M;
if (M == 1) {
cout << 0 << endl;
return;
}
vector<int> xs(M), ds(M - 1);
for (int i = 0; i < M; i++) {
cin >> xs[i];
}
sort(xs.begin(), xs.end());
for (int i = 0; i < M - 1; i++) {
ds[i] = xs[i + 1] - xs[i];
}
sort(ds.rbegin(), ds.rend());
int ans = xs.back() - xs.front();
for (int i = 0; i < N - 1; i++) {
ans -= ds[i];
}
cout << ans << endl;
}
int main(void) {
solve();
// cout << "yui(*-v・)yui" << endl;
return 0;
}
| #include "bits/stdc++.h"
using namespace std;
void solve() {
int N, M;
cin >> N >> M;
if (N >= M) {
cout << 0 << endl;
return;
}
vector<long> xs(M), ds(M - 1);
for (int i = 0; i < M; i++) {
cin >> xs[i];
}
sort(xs.begin(), xs.end());
for (int i = 0; i < M - 1; i++) {
ds[i] = xs[i + 1] - xs[i];
}
sort(ds.rbegin(), ds.rend());
long ans = xs.back() - xs.front();
for (int i = 0; i < N - 1; i++) {
ans -= ds[i];
}
cout << ans << endl;
}
int main(void) {
solve();
// cout << "yui(*-v・)yui" << endl;
return 0;
}
| [
"control_flow.branch.if.condition.change",
"expression.operation.binary.remove",
"variable_declaration.type.primitive.change"
] | 938,722 | 938,723 | u344412812 | cpp |
p03137 | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> diff;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll N, M;
cin >> N >> M;
if (N >= M) {
cout << '0' << "\n";
return 0;
}
vector<int> points;
REP(i, M) {
int p;
cin >> p;
points.push_back(p);
}
sort(points.begin(), points.end());
vector<ll> D;
REP(i, (int)(points.size() - 1)) {
ll d = points[i + 1] - points[i]; // 差分
D.push_back(d);
}
sort(D.begin(), D.end());
ll result = 0;
REP(i, N + 1) { result += D[i]; }
cout << result << "\n";
} | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> diff;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll N, M;
cin >> N >> M;
if (N >= M) {
cout << '0' << "\n";
return 0;
}
vector<int> points;
REP(i, M) {
int p;
cin >> p;
points.push_back(p);
}
sort(points.begin(), points.end());
vector<ll> D;
REP(i, (int)(points.size() - 1)) {
ll d = points[i + 1] - points[i]; // 差分
D.push_back(d);
}
sort(D.begin(), D.end());
int result = 0;
REP(i, M - N) { result += D[i]; };
cout << result << "\n";
} | [
"variable_declaration.type.change",
"expression.operation.binary.remove"
] | 938,762 | 938,763 | u269981094 | cpp |
p03137 | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string.h>
#include <string>
#include <type_traits>
#include <vector>
#define int long long
#define ll long long
#define mod 1000000007
#define MOD 1000000007
#define inf 1e17
#define rep(i, j, n) for (int i = j; i < n; i++)
#define P pair<int, int>
#define ps push_back
#define all(x) x.begin(), x.end()
double pi = 3.141592653589793;
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
//ここから始めよう
signed main() {
int n, m;
cin >> n >> m;
vector<int> v;
if (m == 1) {
cout << 0 << endl;
return 0;
}
rep(i, 0, m) {
int a;
cin >> a;
a += 114514;
v.ps(a);
}
sort(all(v));
vector<int> key;
int sum = v[m - 1] - v[0];
rep(i, 1, m) { key.ps(v[i] - v[i - 1]); }
sort(all(key));
reverse(all(key));
rep(i, 0, n - 1) { sum -= key[i]; }
cout << sum << endl;
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string.h>
#include <string>
#include <type_traits>
#include <vector>
#define int long long
#define ll long long
#define mod 1000000007
#define MOD 1000000007
#define inf 1e17
#define rep(i, j, n) for (int i = j; i < n; i++)
#define P pair<int, int>
#define ps push_back
#define all(x) x.begin(), x.end()
double pi = 3.141592653589793;
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
//ここから始めよう
signed main() {
int n, m;
cin >> n >> m;
vector<int> v;
if (n >= m) {
cout << 0 << endl;
return 0;
}
rep(i, 0, m) {
int a;
cin >> a;
a += 114514;
v.ps(a);
}
sort(all(v));
vector<int> key;
int sum = v[m - 1] - v[0];
rep(i, 1, m) { key.ps(v[i] - v[i - 1]); }
sort(all(key));
reverse(all(key));
rep(i, 0, n - 1) { sum -= key[i]; }
cout << sum << endl;
return 0;
}
| [
"control_flow.branch.if.condition.change",
"expression.operation.binary.remove"
] | 938,781 | 938,782 | u318857467 | cpp |
p03137 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const int MOD = 1e9 + 7;
// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
int main() {
// 入力
int N, M;
cin >> N >> M;
ll x[M];
for (int i = 0; i < M; i++)
scanf("%lld", x + i);
if (M == 1) {
cout << 0 << endl;
return 0;
}
sort(x, x + M);
ll d[M - 1];
for (int i = 0; i < M - 1; i++) {
d[i] = x[i + 1] - x[i];
}
sort(d, d + (M - 1));
cout << accumulate(d, d + (M - N), 0) << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const int MOD = 1e9 + 7;
// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
int main() {
// 入力
int N, M;
cin >> N >> M;
ll x[M];
for (int i = 0; i < M; i++)
scanf("%lld", x + i);
if (N >= M) {
cout << 0 << endl;
return 0;
}
sort(x, x + M);
ll d[M - 1];
for (int i = 0; i < M - 1; i++) {
d[i] = x[i + 1] - x[i];
}
sort(d, d + (M - 1));
cout << accumulate(d, d + (M - N), 0) << endl;
return 0;
}
| [
"control_flow.branch.if.condition.change",
"expression.operation.binary.remove"
] | 938,795 | 938,796 | u063020782 | cpp |
p03137 | #pragma GCC optimize("O3")
#include "bits/stdc++.h"
using namespace std;
using ll = long long int;
#define debugos cout
#define debug(v) \
{ \
printf("L%d %s > ", __LINE__, #v); \
debugos << (v) << endl; \
}
#define debugv(v) \
{ \
printf("L%d %s > ", __LINE__, #v); \
for (auto e : (v)) { \
debugos << e << " "; \
} \
debugos << endl; \
}
#define debuga(m, w) \
{ \
printf("L%d %s > ", __LINE__, #m); \
for (int x = 0; x < (w); x++) { \
debugos << (m)[x] << " "; \
} \
debugos << endl; \
}
#define debugaa(m, h, w) \
{ \
printf("L%d %s >\n", __LINE__, #m); \
for (int y = 0; y < (h); y++) { \
for (int x = 0; x < (w); x++) { \
debugos << (m)[y][x] << " "; \
} \
debugos << endl; \
} \
}
#define ALL(v) (v).begin(), (v).end()
#define repeat(cnt, l) \
for (remove_reference<remove_const<decltype(l)>::type>::type cnt = 0; \
(cnt) < (l); ++(cnt))
#define rrepeat(cnt, l) for (auto cnt = (l)-1; 0 <= (cnt); --(cnt))
#define iterate(cnt, b, e) for (auto cnt = (b); (cnt) != (e); ++(cnt))
#define diterate(cnt, b, e) for (auto cnt = (b); (cnt) != (e); --(cnt))
const ll MD = 1000000007ll;
const long double PI = 3.1415926535897932384626433832795L;
inline void assert_call(bool assertion, function<void()> f) {
if (!assertion) {
cerr << "assertion fault:" << endl;
f();
abort();
}
}
template <typename T1, typename T2>
inline ostream &operator<<(ostream &o, const pair<T1, T2> p) {
o << '(' << p.first << ':' << p.second << ')';
return o;
}
template <typename Vec>
inline ostream &_ostream_vecprint(ostream &os, const Vec &a) {
os << '[';
for (const auto &e : a)
os << ' ' << e << ' ';
os << ']';
return os;
}
template <typename T>
inline ostream &operator<<(ostream &o, const vector<T> &v) {
return _ostream_vecprint(o, v);
}
template <typename T, size_t S>
inline ostream &operator<<(ostream &o, const array<T, S> &v) {
return _ostream_vecprint(o, v);
}
template <typename T> inline T &chmax(T &to, const T &val) {
return to = max(to, val);
}
template <typename T> inline T &chmin(T &to, const T &val) {
return to = min(to, val);
}
void bye(string s, int code = 0) {
cout << s << endl;
exit(code);
}
mt19937_64 randdev(8901016);
template <typename T> inline T rand(T l, T h) {
return uniform_int_distribution<T>(l, h)(randdev);
}
template <> inline double rand<double>(double l, double h) {
return uniform_real_distribution<double>(l, h)(randdev);
}
template <> inline float rand<float>(float l, float h) {
return uniform_real_distribution<float>(l, h)(randdev);
}
#if defined(_WIN32) || defined(_WIN64)
#define getchar_unlocked _getchar_nolock
#define putchar_unlocked _putchar_nolock
#elif defined(__GNUC__)
#else
#define getchar_unlocked getchar
#define putchar_unlocked putchar
#endif
namespace {
#define isvisiblechar(c) (0x21 <= (c) && (c) <= 0x7E)
class MaiScanner {
public:
template <typename T> void input_integer(T &var) {
var = 0;
T sign = 1;
int cc = getchar_unlocked();
for (; cc < '0' || '9' < cc; cc = getchar_unlocked())
if (cc == '-')
sign = -1;
for (; '0' <= cc && cc <= '9'; cc = getchar_unlocked())
var = (var << 3) + (var << 1) + cc - '0';
var = var * sign;
}
inline int c() { return getchar_unlocked(); }
inline MaiScanner &operator>>(int &var) {
input_integer<int>(var);
return *this;
}
inline MaiScanner &operator>>(long long &var) {
input_integer<long long>(var);
return *this;
}
inline MaiScanner &operator>>(string &var) {
int cc = getchar_unlocked();
for (; !isvisiblechar(cc); cc = getchar_unlocked())
;
for (; isvisiblechar(cc); cc = getchar_unlocked())
var.push_back(cc);
return *this;
}
template <typename IT> void in(IT begin, IT end) {
for (auto it = begin; it != end; ++it)
*this >> *it;
}
};
class MaiPrinter {
public:
template <typename T> void output_integer(T var) {
if (var == 0) {
putchar_unlocked('0');
return;
}
if (var < 0)
putchar_unlocked('-'), var = -var;
char stack[32];
int stack_p = 0;
while (var)
stack[stack_p++] = '0' + (var % 10), var /= 10;
while (stack_p)
putchar_unlocked(stack[--stack_p]);
}
inline MaiPrinter &operator<<(char c) {
putchar_unlocked(c);
return *this;
}
inline MaiPrinter &operator<<(int var) {
output_integer<int>(var);
return *this;
}
inline MaiPrinter &operator<<(long long var) {
output_integer<long long>(var);
return *this;
}
inline MaiPrinter &operator<<(char *str_p) {
while (*str_p)
putchar_unlocked(*(str_p++));
return *this;
}
inline MaiPrinter &operator<<(const string &str) {
const char *p = str.c_str();
const char *l = p + str.size();
while (p < l)
putchar_unlocked(*p++);
return *this;
}
template <typename IT> void join(IT begin, IT end, char sep = ' ') {
for (bool b = 0; begin != end; ++begin, b = 1)
b ? *this << sep << *begin : *this << *begin;
}
};
} // namespace
MaiScanner scanner;
MaiPrinter printer;
//
int N, M;
int X[100010];
int main() {
scanner >> N >> M;
if (N >= M)
bye("0");
scanner.in(X, X + M);
sort(X, X + M);
iterate(i, 1, M) { X[i - 1] = X[i] - X[i - 1]; }
sort(X, X + M);
ll ans = 0;
int c = M - N;
while (c--) {
ans += X[c];
}
printer << ans << '\n';
return 0;
} | #pragma GCC optimize("O3")
#include "bits/stdc++.h"
using namespace std;
using ll = long long int;
#define debugos cout
#define debug(v) \
{ \
printf("L%d %s > ", __LINE__, #v); \
debugos << (v) << endl; \
}
#define debugv(v) \
{ \
printf("L%d %s > ", __LINE__, #v); \
for (auto e : (v)) { \
debugos << e << " "; \
} \
debugos << endl; \
}
#define debuga(m, w) \
{ \
printf("L%d %s > ", __LINE__, #m); \
for (int x = 0; x < (w); x++) { \
debugos << (m)[x] << " "; \
} \
debugos << endl; \
}
#define debugaa(m, h, w) \
{ \
printf("L%d %s >\n", __LINE__, #m); \
for (int y = 0; y < (h); y++) { \
for (int x = 0; x < (w); x++) { \
debugos << (m)[y][x] << " "; \
} \
debugos << endl; \
} \
}
#define ALL(v) (v).begin(), (v).end()
#define repeat(cnt, l) \
for (remove_reference<remove_const<decltype(l)>::type>::type cnt = 0; \
(cnt) < (l); ++(cnt))
#define rrepeat(cnt, l) for (auto cnt = (l)-1; 0 <= (cnt); --(cnt))
#define iterate(cnt, b, e) for (auto cnt = (b); (cnt) != (e); ++(cnt))
#define diterate(cnt, b, e) for (auto cnt = (b); (cnt) != (e); --(cnt))
const ll MD = 1000000007ll;
const long double PI = 3.1415926535897932384626433832795L;
inline void assert_call(bool assertion, function<void()> f) {
if (!assertion) {
cerr << "assertion fault:" << endl;
f();
abort();
}
}
template <typename T1, typename T2>
inline ostream &operator<<(ostream &o, const pair<T1, T2> p) {
o << '(' << p.first << ':' << p.second << ')';
return o;
}
template <typename Vec>
inline ostream &_ostream_vecprint(ostream &os, const Vec &a) {
os << '[';
for (const auto &e : a)
os << ' ' << e << ' ';
os << ']';
return os;
}
template <typename T>
inline ostream &operator<<(ostream &o, const vector<T> &v) {
return _ostream_vecprint(o, v);
}
template <typename T, size_t S>
inline ostream &operator<<(ostream &o, const array<T, S> &v) {
return _ostream_vecprint(o, v);
}
template <typename T> inline T &chmax(T &to, const T &val) {
return to = max(to, val);
}
template <typename T> inline T &chmin(T &to, const T &val) {
return to = min(to, val);
}
void bye(string s, int code = 0) {
cout << s << endl;
exit(code);
}
mt19937_64 randdev(8901016);
template <typename T> inline T rand(T l, T h) {
return uniform_int_distribution<T>(l, h)(randdev);
}
template <> inline double rand<double>(double l, double h) {
return uniform_real_distribution<double>(l, h)(randdev);
}
template <> inline float rand<float>(float l, float h) {
return uniform_real_distribution<float>(l, h)(randdev);
}
#if defined(_WIN32) || defined(_WIN64)
#define getchar_unlocked _getchar_nolock
#define putchar_unlocked _putchar_nolock
#elif defined(__GNUC__)
#else
#define getchar_unlocked getchar
#define putchar_unlocked putchar
#endif
namespace {
#define isvisiblechar(c) (0x21 <= (c) && (c) <= 0x7E)
class MaiScanner {
public:
template <typename T> void input_integer(T &var) {
var = 0;
T sign = 1;
int cc = getchar_unlocked();
for (; cc < '0' || '9' < cc; cc = getchar_unlocked())
if (cc == '-')
sign = -1;
for (; '0' <= cc && cc <= '9'; cc = getchar_unlocked())
var = (var << 3) + (var << 1) + cc - '0';
var = var * sign;
}
inline int c() { return getchar_unlocked(); }
inline MaiScanner &operator>>(int &var) {
input_integer<int>(var);
return *this;
}
inline MaiScanner &operator>>(long long &var) {
input_integer<long long>(var);
return *this;
}
inline MaiScanner &operator>>(string &var) {
int cc = getchar_unlocked();
for (; !isvisiblechar(cc); cc = getchar_unlocked())
;
for (; isvisiblechar(cc); cc = getchar_unlocked())
var.push_back(cc);
return *this;
}
template <typename IT> void in(IT begin, IT end) {
for (auto it = begin; it != end; ++it)
*this >> *it;
}
};
class MaiPrinter {
public:
template <typename T> void output_integer(T var) {
if (var == 0) {
putchar_unlocked('0');
return;
}
if (var < 0)
putchar_unlocked('-'), var = -var;
char stack[32];
int stack_p = 0;
while (var)
stack[stack_p++] = '0' + (var % 10), var /= 10;
while (stack_p)
putchar_unlocked(stack[--stack_p]);
}
inline MaiPrinter &operator<<(char c) {
putchar_unlocked(c);
return *this;
}
inline MaiPrinter &operator<<(int var) {
output_integer<int>(var);
return *this;
}
inline MaiPrinter &operator<<(long long var) {
output_integer<long long>(var);
return *this;
}
inline MaiPrinter &operator<<(char *str_p) {
while (*str_p)
putchar_unlocked(*(str_p++));
return *this;
}
inline MaiPrinter &operator<<(const string &str) {
const char *p = str.c_str();
const char *l = p + str.size();
while (p < l)
putchar_unlocked(*p++);
return *this;
}
template <typename IT> void join(IT begin, IT end, char sep = ' ') {
for (bool b = 0; begin != end; ++begin, b = 1)
b ? *this << sep << *begin : *this << *begin;
}
};
} // namespace
MaiScanner scanner;
MaiPrinter printer;
//
int N, M;
int X[100010];
int main() {
scanner >> N >> M;
if (N >= M)
bye("0");
scanner.in(X, X + M);
sort(X, X + M);
iterate(i, 1, M) { X[i - 1] = X[i] - X[i - 1]; }
sort(X, X + M - 1);
ll ans = 0;
int c = M - N;
while (c--) {
ans += X[c];
}
printer << ans << '\n';
return 0;
} | [
"expression.operation.binary.add"
] | 938,799 | 938,800 | u079330987 | cpp |
p03138 | #pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define all(x) x.begin(), x.end()
#define trav(i, a) for (auto &i : a)
inline int in() {
int x;
scanf("%lld", &x);
return x;
}
int dp[60][2];
const int mxd = 50;
// dp[i][0] answer for ms i bits if ith is 0
int32_t main() {
int n = in();
int k = in();
vector<int> a(n);
for (int &i : a)
i = in();
memset(dp, -1, sizeof dp);
dp[0][0] = 0;
for (int d = 0; d < mxd; d++) {
int mask = 1LL << (mxd - d - 1);
int ct = 0; // ct of ones at this bit
for (int i : a)
if (i & mask)
ct++;
int x1 = mask * (n - ct);
int x0 = mask * ct;
if (dp[d][1] != -1)
dp[d + 1][1] = max(dp[d + 1][1], dp[d][1] + max(x0, x1));
if (dp[d][0] != -1) {
if (k & mask) {
dp[d + 1][1] = max(dp[d][0] + x1, dp[d + 1][1]);
dp[d + 1][0] = max(dp[d + 1][0], dp[d][0] + x1);
} else
dp[d + 1][0] = max(dp[d + 1][0], dp[d][0] + x0);
}
}
cout << max(dp[mxd][0], dp[mxd][1]);
}
| #pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define all(x) x.begin(), x.end()
#define trav(i, a) for (auto &i : a)
inline int in() {
int x;
scanf("%lld", &x);
return x;
}
int dp[60][2];
const int mxd = 50;
// dp[i][0] answer for ms i bits if ith is 0
int32_t main() {
int n = in();
int k = in();
vector<int> a(n);
for (int &i : a)
i = in();
memset(dp, -1, sizeof dp);
dp[0][0] = 0;
for (int d = 0; d < mxd; d++) {
int mask = 1LL << (mxd - d - 1);
int ct = 0; // ct of ones at this bit
for (int i : a)
if (i & mask)
ct++;
int x1 = mask * (n - ct);
int x0 = mask * ct;
if (dp[d][1] != -1)
dp[d + 1][1] = max(dp[d + 1][1], dp[d][1] + max(x0, x1));
if (dp[d][0] != -1) {
if (k & mask) {
dp[d + 1][1] = max(dp[d][0] + x0, dp[d + 1][1]);
dp[d + 1][0] = max(dp[d + 1][0], dp[d][0] + x1);
} else
dp[d + 1][0] = max(dp[d + 1][0], dp[d][0] + x0);
}
}
cout << max(dp[mxd][0], dp[mxd][1]);
}
| [
"assignment.value.change",
"identifier.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 938,813 | 938,814 | u875407613 | cpp |
p03138 | #include <algorithm>
#include <array>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctype.h>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <unordered_map>
#include <utility>
#include <vector>
#define _USE_MATH_DEFINES
#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, double> pld;
typedef pair<double, double> pdd;
typedef pair<double, ll> pdl;
typedef pair<int, char> pic;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef priority_queue<ll, vector<ll>, greater<ll>> llgreaterq;
typedef priority_queue<pll, vector<pll>, greater<pll>> pllgreaterq;
typedef priority_queue<pair<ll, pll>, vector<pair<ll, pll>>,
greater<pair<ll, pll>>>
plpllgreaterq;
typedef priority_queue<vi, vector<vi>, greater<vi>> vigreaterq;
typedef priority_queue<vl, vector<vl>, greater<vl>> vlgreaterq;
template <class o, class p, class q>
using tuple3q = priority_queue<tuple<o, p, q>, vector<tuple<o, p, q>>,
greater<tuple<o, p, q>>>;
template <class o, class p, class q, class r>
using tuple4q = priority_queue<tuple<o, p, q, r>, vector<tuple<o, p, q, r>>,
greater<tuple<o, p, q, r>>>;
template <class o, class p, class q, class r, class s>
using tuple5q =
priority_queue<tuple<o, p, q, r, s>, vector<tuple<o, p, q, r, s>>,
greater<tuple<o, p, q, r, s>>>;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
#define bit(x, v) ((ll)x << v)
#define rep(x, n) for (ll x = 0; x < n; x++)
#define rep2(x, f, v) for (ll x = f; x < v; x++)
#define repe(v, x) for (auto v : x)
// 許容する誤差ε
#define EPS (1e-10)
// 2つのスカラーが等しいかどうか
#define EQ(a, b) (std::abs(a - b) < EPS)
// 2つのベクトルが等しいかどうか
#define EQV(a, b) (EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()))
#define all(a) a.begin(), a.end()
#define all0(a) memset(a, 0, sizeof(a))
#define allm1(a) memset(a, -1, sizeof(a))
#define put_float(v) \
cout << fixed << setprecision(10); \
cout << v << endl
#define put(v) cout << v << endl
#define vinsert(v, p, x) v.insert(v.begin() + p, x)
#define vsort(v) sort(all(v));
#define dup(v) v.erase(unique(all(v)), v.end())
#define ion(i, j) ((i & (1LL << j)) > 0)
#define next(i) \
i++; \
i %= 2
#define Len size()
#define ull unsignd long long
#define psp(a, b) push_back(make_pair(a, b))
#define psp2(a, b) push(make_pair(a, b))
#define cini(a) \
a; \
cin >> a
#define infa(a, b) (a + b) % INF
#define infm(a, b) (a * b) % INF
#define infd(a, b) (a * modinv(b)) % INF
#define infs(a, b) (a + INF - b) % INF
#define inf(a) (a) %= INF
#define inff(a) ((a) % INF)
#define No cout << "No" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define YES cout << "YES" << endl
#define smal -INF *INF
#define big INF *INF
const ll INF = 1000000007;
const int MAX = 2000010;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll getpow(ll b, ll x, ll md) {
ll t = b;
ll res = 1;
while (x > 0) {
if (x & 1) {
res *= t;
res %= md;
}
x >>= 1;
t *= t;
t %= md;
}
return res;
}
ll getpow(ll b, ll x) { return getpow(b, x, INF); }
ll modinv(ll x) { return getpow(x, INF - 2); }
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
class mint {
int md = 1000000007;
public:
long long x;
mint(ll x, ll md) {
this->md = md;
this->x = (x % md + md) % md;
}
mint(long long x = 0) : x((x % md + md) % md) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint &a) {
if ((x += a.x) >= md)
x -= md;
return *this;
}
mint &operator-=(const mint &a) {
if ((x += md - a.x) >= md)
x -= md;
return *this;
}
mint &operator*=(const mint &a) {
(x *= a.x) %= md;
return *this;
}
mint operator+(const mint &a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint &a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint &a) const {
mint res(*this);
return res *= a;
}
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(md - 2); }
mint &operator/=(const mint &a) { return (*this) *= a.inv(); }
mint operator/(const mint &a) const {
mint res(*this);
return res /= a;
}
friend ostream &operator<<(ostream &os, const mint &m) {
os << m.x;
return os;
}
};
int pr[100010];
int lank[100010];
void uini(int n) {
for (size_t i = 0; i <= n; i++) {
pr[i] = i;
lank[i] = 1;
}
}
int parent(int x) {
if (x == pr[x])
return x;
return pr[x] = parent(pr[x]);
}
int same(int x, int y) { return parent(x) == parent(y); }
bool unit(int x, int y) {
int px = parent(x);
int py = parent(y);
if (px == py)
return false;
if (lank[py] < lank[px]) {
pr[py] = px;
lank[px] += lank[py];
} else {
pr[px] = py;
lank[py] += lank[px];
}
return true;
}
ll n;
int ci = 0;
struct Node {
int key;
int priority;
Node *parent, *left, *right;
Node(int key, int priority);
Node() {}
};
Node NIL;
Node::Node(int key, int priority) : key(key), priority(priority) {
left = &NIL;
right = &NIL;
}
Node *root = new Node();
void cenrec(Node *k) {
if (k->key == NIL.key)
return;
cenrec(k->left);
cout << " " << k->key;
cenrec(k->right);
}
void fastrec(Node *k) {
if (k->key == NIL.key)
return;
cout << " " << k->key;
fastrec(k->left);
fastrec(k->right);
}
void insert(Node *v) {
Node *y = &NIL;
Node *x = root;
while (x->key != NIL.key) {
y = x;
if (v->key < x->key) {
x = x->left;
} else {
x = x->right;
}
}
v->parent = y;
if (y->key == NIL.key) {
root = v;
} else if (v->key < y->key) {
y->left = v;
} else {
y->right = v;
}
}
Node *find(Node *k, ll v) {
if (k->key == NIL.key)
return &NIL;
if (k->key == v)
return k;
if (v < k->key)
return find(k->left, v);
return find(k->right, v);
}
void delp12(Node *x) {
if (x->key == NIL.key)
return;
Node *l = x->left;
Node *r = x->right;
Node *pr = x->parent;
if (l->key == NIL.key && r->key == NIL.key) {
if (pr->left == x) {
pr->left = &NIL;
} else
pr->right = &NIL;
} else if (l->key != NIL.key) {
if (pr->left == x) {
pr->left = l;
} else
pr->right = l;
l->parent = pr;
} else if (r->key != NIL.key) {
if (pr->left == x) {
pr->left = r;
} else
pr->right = r;
r->parent = pr;
}
}
Node *get_next(Node *k) {
if (k->key == NIL.key)
return &NIL;
Node *res = get_next(k->left);
if (res->key != NIL.key)
return res;
return k;
}
void del(Node *x) {
if (x->key == NIL.key)
return;
Node *l = x->left;
Node *r = x->right;
Node *pr = x->parent;
if (l->key != NIL.key && r->key != NIL.key) {
Node *nex = get_next(r);
x->key = nex->key;
delp12(nex);
} else {
delp12(x);
}
}
Node *rightRotate(Node *t) {
Node *s = t->left;
t->left = s->right;
s->right = t;
return s;
}
Node *leftRotate(Node *t) {
Node *s = t->right;
t->right = s->left;
s->left = t;
return s;
}
Node *_insert(Node *t, int key, int priority) {
if (t->key == NIL.key) {
return new Node(key, priority);
}
if (key == t->key) {
return t;
}
if (key < t->key) {
t->left = _insert(t->left, key, priority);
if (t->priority < t->left->priority) {
t = rightRotate(t);
}
} else {
t->right = _insert(t->right, key, priority);
if (t->priority < t->right->priority) {
t = leftRotate(t);
}
}
return t;
}
Node *delete1(Node *t, int key);
Node *_delete(Node *t, int key) {
if (t->left->key == NIL.key && t->right->key == NIL.key) {
return &NIL;
} else if (t->left->key == NIL.key) {
t = leftRotate(t);
} else if (t->right->key == NIL.key) {
t = rightRotate(t);
} else {
if (t->left->priority > t->right->priority) {
t = rightRotate(t);
} else
t = leftRotate(t);
}
return delete1(t, key);
}
Node *delete1(Node *t, int key) {
if (t->key == NIL.key) {
return &NIL;
}
if (key < t->key) {
t->left = delete1(t->left, key);
} else if (key > t->key) {
t->right = delete1(t->right, key);
} else
return _delete(t, key);
return t;
}
int H;
int left(int i) { return i * 2 + 1; }
int right(int i) { return i * 2 + 2; }
class edge {
public:
int from, to, i;
ll val;
edge() {}
edge(ll to) : to(to) {}
edge(ll to, ll i) : to(to), i(i) {}
edge(ll from, ll to, ll val) : from(from), to(to), val(val) {}
};
class LCA {
private:
vector<vector<edge>> v;
vector<vector<int>> parent;
vector<int> depth;
void dfs(int n, int m, int d) {
parent[0][n] = m;
depth[n] = d;
for (auto x : v[n]) {
if (x.to != m)
dfs(x.to, n, d + 1);
}
}
public:
LCA(ll N, ll root, vector<vector<edge>> &tree) {
v = tree;
parent = vector<vector<int>>(21, vector<int>(N + 1, 0));
depth = vector<int>(N + 1, 0);
dfs(root, -1, 0);
for (int j = 0; j + 1 < 20; j++) {
for (int i = 1; i <= N; i++) {
if (parent[j][i] < 0)
parent[j + 1][i] = -1;
else
parent[j + 1][i] = parent[j][parent[j][i]];
}
}
}
int lca(int n, int m) {
if (depth[n] > depth[m])
swap(n, m);
for (int j = 0; j < 20; j++) {
if ((depth[m] - depth[n]) >> j & 1)
m = parent[j][m];
}
if (n == m)
return n;
for (int j = 19; j >= 0; j--) {
if (parent[j][n] != parent[j][m]) {
n = parent[j][n];
m = parent[j][m];
}
}
return parent[0][n];
}
int dep(int n) { return depth[n]; }
};
ll k;
int _rank[1010];
int temp[1010];
bool compare_sa(int i, int j) {
if (_rank[i] != _rank[j])
return _rank[i] < _rank[j];
else {
int ri = i + k <= n ? _rank[i + k] : -1;
int rj = j + k <= n ? _rank[j + k] : -1;
return ri < rj;
}
}
void construct_sa(string S, int *sa) {
n = S.length();
for (size_t i = 0; i <= n; i++) {
sa[i] = i;
_rank[i] = i < n ? S[i] : -1;
}
for (k = 1; k <= n; k *= 2) {
sort(sa, sa + n + 1, compare_sa);
// saはソート後の接尾辞の並びになっている、rankは元の位置のindexを保持したまま、更新されている。
// ピンとこなかった部分
temp[sa[0]] = 0;
for (size_t i = 1; i <= n; i++) {
temp[sa[i]] = temp[sa[i - 1]] + (compare_sa(sa[i - 1], sa[i]) ? 1 : 0);
}
for (size_t i = 0; i <= n; i++) {
_rank[i] = temp[i];
}
}
}
bool contain(string S, int *sa, string T) {
int a = 0, b = S.length();
// sa は 接尾辞が辞書順に並んでいる、入っているのはその位置のインデックス
while (b - a > 1) {
int c = (a + b) / 2;
if (S.compare(sa[c], T.length(), T) < 0)
a = c;
else
b = c;
}
return S.compare(sa[b], T.length(), T) == 0;
}
#define bit(x, v) ((ll)x << v)
class BIT {
static const int MAX_N = 500010;
public:
BIT() { memset(bit, 0, sizeof(bit)); }
ll bit[MAX_N + 1], n;
ll sum(int i) {
ll s = 0;
while (i > 0) {
s += bit[i];
i -= i & -i;
}
return s;
}
void add(int i, int x) {
while (i <= n) {
bit[i] += x;
i += i & -i;
}
}
};
struct UnionFind {
vector<int> A;
UnionFind(int n) : A(n, -1) {}
int find(int x) {
if (A[x] < 0)
return x;
return A[x] = find(A[x]);
}
void unite(int x, int y) {
x = find(x), y = find(y);
if (x == y)
return;
if (A[x] > A[y])
swap(x, y);
A[x] += A[y];
A[y] = x;
}
int ngroups() {
int ans = 0;
for (auto a : A)
if (a < 0)
ans++;
return ans;
}
};
vector<ll> getp(ll n) {
vector<ll> res;
ll a = 2;
if (n % 2 == 0) {
res.push_back(2);
while (n % 2 == 0)
n /= 2;
}
for (ll i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
res.push_back(i);
while (n % i == 0)
n /= i;
}
}
if (n != 1)
res.push_back(n);
return res;
}
vector<ll> getp2(ll n) {
vector<ll> res;
ll a = 2;
if (n % 2 == 0) {
while (n % 2 == 0) {
n /= 2;
res.push_back(2);
}
}
for (ll i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
while (n % i == 0) {
n /= i;
res.push_back(i);
}
}
}
if (n != 1)
res.push_back(n);
return res;
}
vector<pll> getp3(ll n) {
vector<pll> res;
ll a = 2;
int si = 0;
if (n % 2 == 0) {
res.push_back(make_pair(2, 0));
while (n % 2 == 0) {
n /= 2;
res[si].second++;
}
si++;
}
for (ll i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
res.push_back(make_pair(i, 0));
while (n % i == 0) {
n /= i;
res[si].second++;
}
si++;
}
}
if (n != 1) {
res.push_back(make_pair(n, 1));
}
return res;
}
vector<ll> getDivisors(ll n) {
vector<ll> res;
ll a = 2;
res.push_back(1);
for (ll i = 2; i * i <= n; i++) {
if (n % i == 0) {
res.push_back(i);
if (n / i != i)
res.push_back(n / i);
}
}
return res;
}
struct ve {
public:
vector<ve> child;
int _t = INF;
ve(int t) : _t(t) {}
ve(ve _left, ve _right) {
_t = _left._t + _right._t;
child.push_back(_left);
child.push_back(_right);
}
bool operator<(const ve &t) const { return _t > t._t; }
};
vector<bool> elas(ll n) {
vector<bool> r(n);
fill(r.begin(), r.end(), 1);
r[0] = 0;
r[1] = 0;
for (ll i = 2; i * i < n; i++) {
if (!r[i])
continue;
ll ti = i * 2;
while (ti < n) {
r[ti] = false;
ti += i;
}
}
return r;
}
bool isPrime(ll v) {
for (ll i = 2; i * i <= v; i++) {
if (v % i == 0)
return false;
}
return true;
}
class SegTree {
public:
const static int MAX_N = 100010;
const static int DAT_SIZE = (1 << 18) - 1;
int N, Q;
int A[MAX_N];
ll data[DAT_SIZE], datb[DAT_SIZE];
void init(int _n) {
N = 1;
while (N < _n)
N <<= 1;
memset(data, 0, sizeof(data));
memset(datb, 0, sizeof(datb));
}
void init(int _n, ll iv) {
N = 1;
while (N < _n)
N <<= 1;
rep(i, DAT_SIZE) {
data[i] = iv;
datb[i] = iv;
}
}
void add(int a, int b, int x) { add(a, b + 1, x, 0, 0, N); }
void add(int a, int b, int x, int k, int l, int r) {
if (a <= l && r <= b) {
data[k] += x;
} else if (l < b && a < r) {
datb[k] += (min(b, r) - max(a, l)) * x;
add(a, b, x, k * 2 + 1, l, (l + r) / 2);
add(a, b, x, k * 2 + 2, (l + r) / 2, r);
}
}
void change(int a, int b, int x) { change(a, b + 1, x, 0, 0, N); }
void change(int a, int b, int x, int k, int l, int r) {
if (a <= l && r <= b) {
data[k] = x;
} else if (l < b && a < r) {
datb[k] = x;
change(a, b, x, k * 2 + 1, l, (l + r) / 2);
change(a, b, x, k * 2 + 2, (l + r) / 2, r);
}
}
ll sum(int a, int b) { return sum(a, b + 1, 0, 0, N); }
ll sum(int a, int b, int k, int l, int r) {
if (b <= l || r <= a) {
return 0;
}
if (a <= l && r <= b) {
return data[k] * (r - l) + datb[k];
}
ll res = (min(b, r) - max(a, l)) * data[k];
res += sum(a, b, k * 2 + 1, l, (l + r) / 2);
res += sum(a, b, k * 2 + 2, (l + r) / 2, r);
return res;
}
};
class Segment;
class Circle;
class Point {
public:
double x, y;
Point(double x = 0, double y = 0) : x(x), y(y) {}
Point operator+(Point p) { return Point(x + p.x, y + p.y); }
Point operator-(Point p) { return Point(x - p.x, y - p.y); }
Point operator*(double a) { return Point(a * x, a * y); }
Point operator/(double a) { return Point(x / a, y / a); }
double abs() { return sqrt(norm()); }
double norm() { return x * x + y * y; }
bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; }
bool operator==(const Point &p) const {
return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
}
static double dot(Point a, Point b) { return a.x * b.x + a.y * b.y; }
static double cross(Point a, Point b) { return a.x * b.y - a.y * b.x; }
static bool isOrthogonal(Point a, Point b) { return EQ(dot(a, b), 0.0); }
static bool isOrthogonal(Point a1, Point a2, Point b1, Point b2) {
return isOrthogonal(a1 - a2, b1 - b2);
}
static bool isOrthogonal(Segment s1, Segment s2);
static bool isPalallel(Point a, Point b) { return EQ(cross(a, b), 0.0); }
static bool isPalallel(Point a1, Point a2, Point b1, Point b2) {
return isPalallel(a1 - a2, b1 - b2);
}
static bool isPalallel(Segment s1, Segment s2);
static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;
static int ccw(Point p0, Point p1, Point p2) {
// 線分はp0とp1でp2がどこにあるかを探る
Point a = p1 - p0;
Point b = p2 - p0;
if (cross(a, b) > EPS)
return COUNTER_CLOCKWISE;
if (cross(a, b) < -EPS)
return CLOCKWISE;
if (dot(a, b) < -EPS)
return ONLINE_BACK;
if (a.norm() < b.norm())
return ONLINE_FRONT;
return ON_SEGMENT;
}
static bool intersect(Point p1, Point p2, Point p3, Point p4) {
return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 &&
ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0);
}
static bool intersect(Segment s1, Segment s2);
static Point project(Segment s, Point p);
static Point reflect(Segment s, Point p);
static Point getDistance(Point a, Point b) { return (a - b).abs(); }
static double getDistanceLP(Segment s, Point p);
static double getDistanceSP(Segment s, Point p);
static double getDistance(Segment s1, Segment s2);
static Point getIntersection(Segment s1, Segment s2);
static pair<Point, Point> crossPoints(Circle c, Segment s);
static int contains(vector<Point> g, Point p) {
int n = g.size();
bool x = false;
rep(i, n) {
Point a = g[i] - p, b = g[(i + 1) % n] - p;
// 線の上に載っているか
if (std::abs(cross(a, b)) < EPS && dot(a, b) < EPS)
return 1;
// pを基準として上下にあるか
// または外積が正か?(→にあるか)
if (a.y > b.y)
swap(a, b);
if (a.y < EPS && EPS < b.y && cross(a, b) > EPS)
x = !x;
}
return x ? 2 : 0;
}
static vector<Point> andrewScan(vector<Point> s) {
vector<Point> u, l;
if (s.size() < 3)
return s;
sort(all(s));
u.push_back(s[0]);
u.push_back(s[1]);
l.push_back(s[s.size() - 1]);
l.push_back(s[s.size() - 2]);
for (int i = 2; i < s.size(); i++) {
for (int _n = u.size();
_n >= 2 && ccw(u[_n - 2], u[_n - 1], s[i]) > CLOCKWISE; _n--) {
u.pop_back();
}
u.push_back(s[i]);
}
for (int i = s.size() - 3; i >= 0; i--) {
for (int _n = l.size();
_n >= 2 && ccw(l[_n - 2], l[_n - 1], s[i]) > CLOCKWISE; _n--) {
l.pop_back();
}
l.push_back(s[i]);
}
reverse(all(l));
for (int i = u.size() - 2; i >= 1; i--) {
l.push_back(u[i]);
}
return l;
}
void get_cin() { cin >> x >> y; }
};
class Segment {
public:
Point p1, p2;
Segment() {}
Segment(Point p1, Point p2) : p1(p1), p2(p2) {}
void get_cin() { cin >> p1.x >> p1.y >> p2.x >> p2.y; }
Point p1tp2() { return p2 - p1; }
Point p2tp1() { return p1 - p2; }
double abs() { return std::abs(norm()); }
double norm() { return (p2 - p1).norm(); }
};
bool Point::isOrthogonal(Segment s1, Segment s2) {
return EQ(dot(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
bool Point::isPalallel(Segment s1, Segment s2) {
return EQ(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
bool Point::intersect(Segment s1, Segment s2) {
return intersect(s1.p1, s1.p2, s2.p1, s2.p2);
}
Point Point::project(Segment s, Point p) {
Point base = s.p2 - s.p1;
double r = Point::dot(p - s.p1, base) / base.norm();
return s.p1 + base * r;
}
Point Point::reflect(Segment s, Point p) { return (project(s, p) * 2) - p; }
double Point::getDistanceLP(Segment s, Point p) {
return std::abs(cross(s.p2 - s.p1, p - s.p1) / (s.p2 - s.p1).abs());
}
double Point::getDistanceSP(Segment s, Point p) {
if (dot(s.p2 - s.p1, p - s.p1) < 0.0)
return (p - s.p1).abs();
if (dot(s.p1 - s.p2, p - s.p2) < 0.0)
return (p - s.p2).abs();
return getDistanceLP(s, p);
}
double Point::getDistance(Segment s1, Segment s2) {
if (intersect(s1, s2))
return 0.0;
return min({getDistanceSP(s1, s2.p1), getDistanceSP(s1, s2.p2),
getDistanceSP(s2, s1.p1), getDistanceSP(s2, s1.p2)});
}
Point Point::getIntersection(Segment s1, Segment s2) {
// (s1.p1 - s2.p1).norm()
auto bs = s1.p2 - s1.p1;
auto n1 = s2.p1 - s1.p1;
auto n2 = s2.p2 - s1.p1;
auto c1 = std::abs(cross(n1, bs)) / bs.norm();
auto c2 = std::abs(cross(n2, bs)) / bs.norm();
return s2.p1 + (s2.p2 - s2.p1) * (c1 / (c1 + c2));
// c1:c2=t:1-t
// c2t=(1-t)c1
// t/(1-t)=c1/(c1+c2)
//
}
double arg(Point p) { return atan2(p.y, p.x); }
Point polar(double a, double r) { return Point(cos(r) * a, sin(r) * a); }
class Circle {
public:
Point c;
double r;
Circle(Point c = Point(), double r = 0.0) : c(c), r(r) {}
void get_cin() { cin >> c.x >> c.y >> r; }
static pair<Point, Point> getCrossPoints(Circle c1, Circle c2) {
double d = (c1.c - c2.c).abs(); // 中心点どうしの距離
double a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d));
double t = arg(c2.c - c1.c);
return make_pair(c1.c + polar(c1.r, t + a), c1.c + polar(c1.r, t - a));
}
};
pair<Point, Point> Point::crossPoints(Circle c, Segment s) {
auto pp = project(s, c.c);
auto f = (pp - c.c).norm();
auto mu = sqrt(c.r * c.r - f);
auto e = s.p1tp2() / s.p1tp2().abs();
return make_pair(pp + e * mu, pp - e * mu);
}
ll divRm(string s, ll x) {
ll r = 0;
for (ll i = 0; i < s.size(); i++) {
r *= 10;
r += s[i] - '0';
r %= x;
}
return r;
}
ll cmbi(ll x, ll b) {
ll res = 1;
for (size_t i = 0; i < b; i++) {
res *= x - i;
res %= INF;
res *= inv[b - i];
res %= INF;
}
return res;
}
double digsum(ll x) {
ll res = 0;
while (x > 0) {
res += x % 10;
x /= 10;
}
return res;
}
bool check_parindrome(string s) {
int n = s.size();
rep(i, n / 2) {
if (s[i] != s[n - i - 1]) {
return false;
}
}
return true;
}
ll npr(ll n, ll r) {
if (r == 0)
return 1;
return inff(fac[n] * modinv(fac[n - r]));
}
vl zalgo(string s) {
ll c = 0;
vl a(s.size());
ll si = s.size();
rep2(i, 1, s.size()) {
if (i + a[i - c] < c + a[c]) {
a[i] = a[i - c];
} else {
ll j = max(0LL, a[c] - (i - c));
while (i + j < si && s[j] == s[i + j]) {
j++;
}
a[i] = j;
c = i;
}
}
a[0] = s.size();
return a;
}
string decStrNum(string s) {
ll si = s.size();
for (int i = si - 1; i >= 0; i--) {
if (s[i] == '0') {
s[i] = '9';
continue;
}
s[i] = s[i] - 1;
break;
}
return s;
}
// ここまでライブラリ
// ここからコード
ll a[100010];
ll dp[63][2];
ll rec(ll x, bool tite) {
if (x < 0)
return 0;
if (~dp[x][tite])
return dp[x][tite];
ll v = 1LL << x;
ll cnt = 0;
rep(i, n) {
if (a[i] & v) {
cnt++;
}
}
ll res = 0;
if (tite) {
ll p = k & v;
if (p > 0) {
res = rec(x - 1, tite) + (n - cnt) * p;
res = max(res, rec(x - 1, false) + cnt * p);
} else {
res = rec(x - 1, tite) + cnt * p;
}
} else {
res = rec(x - 1, false) + max(cnt, n - cnt) * v;
}
return dp[x][tite] = res;
}
void solv() {
cin >> n >> k;
rep(i, n) { cin >> a[i]; }
allm1(dp);
cout << rec(62, true) << endl;
}
int main() {
COMinit();
solv();
return 0;
}
| #include <algorithm>
#include <array>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctype.h>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <unordered_map>
#include <utility>
#include <vector>
#define _USE_MATH_DEFINES
#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, double> pld;
typedef pair<double, double> pdd;
typedef pair<double, ll> pdl;
typedef pair<int, char> pic;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef priority_queue<ll, vector<ll>, greater<ll>> llgreaterq;
typedef priority_queue<pll, vector<pll>, greater<pll>> pllgreaterq;
typedef priority_queue<pair<ll, pll>, vector<pair<ll, pll>>,
greater<pair<ll, pll>>>
plpllgreaterq;
typedef priority_queue<vi, vector<vi>, greater<vi>> vigreaterq;
typedef priority_queue<vl, vector<vl>, greater<vl>> vlgreaterq;
template <class o, class p, class q>
using tuple3q = priority_queue<tuple<o, p, q>, vector<tuple<o, p, q>>,
greater<tuple<o, p, q>>>;
template <class o, class p, class q, class r>
using tuple4q = priority_queue<tuple<o, p, q, r>, vector<tuple<o, p, q, r>>,
greater<tuple<o, p, q, r>>>;
template <class o, class p, class q, class r, class s>
using tuple5q =
priority_queue<tuple<o, p, q, r, s>, vector<tuple<o, p, q, r, s>>,
greater<tuple<o, p, q, r, s>>>;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
#define bit(x, v) ((ll)x << v)
#define rep(x, n) for (ll x = 0; x < n; x++)
#define rep2(x, f, v) for (ll x = f; x < v; x++)
#define repe(v, x) for (auto v : x)
// 許容する誤差ε
#define EPS (1e-10)
// 2つのスカラーが等しいかどうか
#define EQ(a, b) (std::abs(a - b) < EPS)
// 2つのベクトルが等しいかどうか
#define EQV(a, b) (EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()))
#define all(a) a.begin(), a.end()
#define all0(a) memset(a, 0, sizeof(a))
#define allm1(a) memset(a, -1, sizeof(a))
#define put_float(v) \
cout << fixed << setprecision(10); \
cout << v << endl
#define put(v) cout << v << endl
#define vinsert(v, p, x) v.insert(v.begin() + p, x)
#define vsort(v) sort(all(v));
#define dup(v) v.erase(unique(all(v)), v.end())
#define ion(i, j) ((i & (1LL << j)) > 0)
#define next(i) \
i++; \
i %= 2
#define Len size()
#define ull unsignd long long
#define psp(a, b) push_back(make_pair(a, b))
#define psp2(a, b) push(make_pair(a, b))
#define cini(a) \
a; \
cin >> a
#define infa(a, b) (a + b) % INF
#define infm(a, b) (a * b) % INF
#define infd(a, b) (a * modinv(b)) % INF
#define infs(a, b) (a + INF - b) % INF
#define inf(a) (a) %= INF
#define inff(a) ((a) % INF)
#define No cout << "No" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define YES cout << "YES" << endl
#define smal -INF *INF
#define big INF *INF
const ll INF = 1000000007;
const int MAX = 2000010;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll getpow(ll b, ll x, ll md) {
ll t = b;
ll res = 1;
while (x > 0) {
if (x & 1) {
res *= t;
res %= md;
}
x >>= 1;
t *= t;
t %= md;
}
return res;
}
ll getpow(ll b, ll x) { return getpow(b, x, INF); }
ll modinv(ll x) { return getpow(x, INF - 2); }
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
class mint {
int md = 1000000007;
public:
long long x;
mint(ll x, ll md) {
this->md = md;
this->x = (x % md + md) % md;
}
mint(long long x = 0) : x((x % md + md) % md) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint &a) {
if ((x += a.x) >= md)
x -= md;
return *this;
}
mint &operator-=(const mint &a) {
if ((x += md - a.x) >= md)
x -= md;
return *this;
}
mint &operator*=(const mint &a) {
(x *= a.x) %= md;
return *this;
}
mint operator+(const mint &a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint &a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint &a) const {
mint res(*this);
return res *= a;
}
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(md - 2); }
mint &operator/=(const mint &a) { return (*this) *= a.inv(); }
mint operator/(const mint &a) const {
mint res(*this);
return res /= a;
}
friend ostream &operator<<(ostream &os, const mint &m) {
os << m.x;
return os;
}
};
int pr[100010];
int lank[100010];
void uini(int n) {
for (size_t i = 0; i <= n; i++) {
pr[i] = i;
lank[i] = 1;
}
}
int parent(int x) {
if (x == pr[x])
return x;
return pr[x] = parent(pr[x]);
}
int same(int x, int y) { return parent(x) == parent(y); }
bool unit(int x, int y) {
int px = parent(x);
int py = parent(y);
if (px == py)
return false;
if (lank[py] < lank[px]) {
pr[py] = px;
lank[px] += lank[py];
} else {
pr[px] = py;
lank[py] += lank[px];
}
return true;
}
ll n;
int ci = 0;
struct Node {
int key;
int priority;
Node *parent, *left, *right;
Node(int key, int priority);
Node() {}
};
Node NIL;
Node::Node(int key, int priority) : key(key), priority(priority) {
left = &NIL;
right = &NIL;
}
Node *root = new Node();
void cenrec(Node *k) {
if (k->key == NIL.key)
return;
cenrec(k->left);
cout << " " << k->key;
cenrec(k->right);
}
void fastrec(Node *k) {
if (k->key == NIL.key)
return;
cout << " " << k->key;
fastrec(k->left);
fastrec(k->right);
}
void insert(Node *v) {
Node *y = &NIL;
Node *x = root;
while (x->key != NIL.key) {
y = x;
if (v->key < x->key) {
x = x->left;
} else {
x = x->right;
}
}
v->parent = y;
if (y->key == NIL.key) {
root = v;
} else if (v->key < y->key) {
y->left = v;
} else {
y->right = v;
}
}
Node *find(Node *k, ll v) {
if (k->key == NIL.key)
return &NIL;
if (k->key == v)
return k;
if (v < k->key)
return find(k->left, v);
return find(k->right, v);
}
void delp12(Node *x) {
if (x->key == NIL.key)
return;
Node *l = x->left;
Node *r = x->right;
Node *pr = x->parent;
if (l->key == NIL.key && r->key == NIL.key) {
if (pr->left == x) {
pr->left = &NIL;
} else
pr->right = &NIL;
} else if (l->key != NIL.key) {
if (pr->left == x) {
pr->left = l;
} else
pr->right = l;
l->parent = pr;
} else if (r->key != NIL.key) {
if (pr->left == x) {
pr->left = r;
} else
pr->right = r;
r->parent = pr;
}
}
Node *get_next(Node *k) {
if (k->key == NIL.key)
return &NIL;
Node *res = get_next(k->left);
if (res->key != NIL.key)
return res;
return k;
}
void del(Node *x) {
if (x->key == NIL.key)
return;
Node *l = x->left;
Node *r = x->right;
Node *pr = x->parent;
if (l->key != NIL.key && r->key != NIL.key) {
Node *nex = get_next(r);
x->key = nex->key;
delp12(nex);
} else {
delp12(x);
}
}
Node *rightRotate(Node *t) {
Node *s = t->left;
t->left = s->right;
s->right = t;
return s;
}
Node *leftRotate(Node *t) {
Node *s = t->right;
t->right = s->left;
s->left = t;
return s;
}
Node *_insert(Node *t, int key, int priority) {
if (t->key == NIL.key) {
return new Node(key, priority);
}
if (key == t->key) {
return t;
}
if (key < t->key) {
t->left = _insert(t->left, key, priority);
if (t->priority < t->left->priority) {
t = rightRotate(t);
}
} else {
t->right = _insert(t->right, key, priority);
if (t->priority < t->right->priority) {
t = leftRotate(t);
}
}
return t;
}
Node *delete1(Node *t, int key);
Node *_delete(Node *t, int key) {
if (t->left->key == NIL.key && t->right->key == NIL.key) {
return &NIL;
} else if (t->left->key == NIL.key) {
t = leftRotate(t);
} else if (t->right->key == NIL.key) {
t = rightRotate(t);
} else {
if (t->left->priority > t->right->priority) {
t = rightRotate(t);
} else
t = leftRotate(t);
}
return delete1(t, key);
}
Node *delete1(Node *t, int key) {
if (t->key == NIL.key) {
return &NIL;
}
if (key < t->key) {
t->left = delete1(t->left, key);
} else if (key > t->key) {
t->right = delete1(t->right, key);
} else
return _delete(t, key);
return t;
}
int H;
int left(int i) { return i * 2 + 1; }
int right(int i) { return i * 2 + 2; }
class edge {
public:
int from, to, i;
ll val;
edge() {}
edge(ll to) : to(to) {}
edge(ll to, ll i) : to(to), i(i) {}
edge(ll from, ll to, ll val) : from(from), to(to), val(val) {}
};
class LCA {
private:
vector<vector<edge>> v;
vector<vector<int>> parent;
vector<int> depth;
void dfs(int n, int m, int d) {
parent[0][n] = m;
depth[n] = d;
for (auto x : v[n]) {
if (x.to != m)
dfs(x.to, n, d + 1);
}
}
public:
LCA(ll N, ll root, vector<vector<edge>> &tree) {
v = tree;
parent = vector<vector<int>>(21, vector<int>(N + 1, 0));
depth = vector<int>(N + 1, 0);
dfs(root, -1, 0);
for (int j = 0; j + 1 < 20; j++) {
for (int i = 1; i <= N; i++) {
if (parent[j][i] < 0)
parent[j + 1][i] = -1;
else
parent[j + 1][i] = parent[j][parent[j][i]];
}
}
}
int lca(int n, int m) {
if (depth[n] > depth[m])
swap(n, m);
for (int j = 0; j < 20; j++) {
if ((depth[m] - depth[n]) >> j & 1)
m = parent[j][m];
}
if (n == m)
return n;
for (int j = 19; j >= 0; j--) {
if (parent[j][n] != parent[j][m]) {
n = parent[j][n];
m = parent[j][m];
}
}
return parent[0][n];
}
int dep(int n) { return depth[n]; }
};
ll k;
int _rank[1010];
int temp[1010];
bool compare_sa(int i, int j) {
if (_rank[i] != _rank[j])
return _rank[i] < _rank[j];
else {
int ri = i + k <= n ? _rank[i + k] : -1;
int rj = j + k <= n ? _rank[j + k] : -1;
return ri < rj;
}
}
void construct_sa(string S, int *sa) {
n = S.length();
for (size_t i = 0; i <= n; i++) {
sa[i] = i;
_rank[i] = i < n ? S[i] : -1;
}
for (k = 1; k <= n; k *= 2) {
sort(sa, sa + n + 1, compare_sa);
// saはソート後の接尾辞の並びになっている、rankは元の位置のindexを保持したまま、更新されている。
// ピンとこなかった部分
temp[sa[0]] = 0;
for (size_t i = 1; i <= n; i++) {
temp[sa[i]] = temp[sa[i - 1]] + (compare_sa(sa[i - 1], sa[i]) ? 1 : 0);
}
for (size_t i = 0; i <= n; i++) {
_rank[i] = temp[i];
}
}
}
bool contain(string S, int *sa, string T) {
int a = 0, b = S.length();
// sa は 接尾辞が辞書順に並んでいる、入っているのはその位置のインデックス
while (b - a > 1) {
int c = (a + b) / 2;
if (S.compare(sa[c], T.length(), T) < 0)
a = c;
else
b = c;
}
return S.compare(sa[b], T.length(), T) == 0;
}
#define bit(x, v) ((ll)x << v)
class BIT {
static const int MAX_N = 500010;
public:
BIT() { memset(bit, 0, sizeof(bit)); }
ll bit[MAX_N + 1], n;
ll sum(int i) {
ll s = 0;
while (i > 0) {
s += bit[i];
i -= i & -i;
}
return s;
}
void add(int i, int x) {
while (i <= n) {
bit[i] += x;
i += i & -i;
}
}
};
struct UnionFind {
vector<int> A;
UnionFind(int n) : A(n, -1) {}
int find(int x) {
if (A[x] < 0)
return x;
return A[x] = find(A[x]);
}
void unite(int x, int y) {
x = find(x), y = find(y);
if (x == y)
return;
if (A[x] > A[y])
swap(x, y);
A[x] += A[y];
A[y] = x;
}
int ngroups() {
int ans = 0;
for (auto a : A)
if (a < 0)
ans++;
return ans;
}
};
vector<ll> getp(ll n) {
vector<ll> res;
ll a = 2;
if (n % 2 == 0) {
res.push_back(2);
while (n % 2 == 0)
n /= 2;
}
for (ll i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
res.push_back(i);
while (n % i == 0)
n /= i;
}
}
if (n != 1)
res.push_back(n);
return res;
}
vector<ll> getp2(ll n) {
vector<ll> res;
ll a = 2;
if (n % 2 == 0) {
while (n % 2 == 0) {
n /= 2;
res.push_back(2);
}
}
for (ll i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
while (n % i == 0) {
n /= i;
res.push_back(i);
}
}
}
if (n != 1)
res.push_back(n);
return res;
}
vector<pll> getp3(ll n) {
vector<pll> res;
ll a = 2;
int si = 0;
if (n % 2 == 0) {
res.push_back(make_pair(2, 0));
while (n % 2 == 0) {
n /= 2;
res[si].second++;
}
si++;
}
for (ll i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
res.push_back(make_pair(i, 0));
while (n % i == 0) {
n /= i;
res[si].second++;
}
si++;
}
}
if (n != 1) {
res.push_back(make_pair(n, 1));
}
return res;
}
vector<ll> getDivisors(ll n) {
vector<ll> res;
ll a = 2;
res.push_back(1);
for (ll i = 2; i * i <= n; i++) {
if (n % i == 0) {
res.push_back(i);
if (n / i != i)
res.push_back(n / i);
}
}
return res;
}
struct ve {
public:
vector<ve> child;
int _t = INF;
ve(int t) : _t(t) {}
ve(ve _left, ve _right) {
_t = _left._t + _right._t;
child.push_back(_left);
child.push_back(_right);
}
bool operator<(const ve &t) const { return _t > t._t; }
};
vector<bool> elas(ll n) {
vector<bool> r(n);
fill(r.begin(), r.end(), 1);
r[0] = 0;
r[1] = 0;
for (ll i = 2; i * i < n; i++) {
if (!r[i])
continue;
ll ti = i * 2;
while (ti < n) {
r[ti] = false;
ti += i;
}
}
return r;
}
bool isPrime(ll v) {
for (ll i = 2; i * i <= v; i++) {
if (v % i == 0)
return false;
}
return true;
}
class SegTree {
public:
const static int MAX_N = 100010;
const static int DAT_SIZE = (1 << 18) - 1;
int N, Q;
int A[MAX_N];
ll data[DAT_SIZE], datb[DAT_SIZE];
void init(int _n) {
N = 1;
while (N < _n)
N <<= 1;
memset(data, 0, sizeof(data));
memset(datb, 0, sizeof(datb));
}
void init(int _n, ll iv) {
N = 1;
while (N < _n)
N <<= 1;
rep(i, DAT_SIZE) {
data[i] = iv;
datb[i] = iv;
}
}
void add(int a, int b, int x) { add(a, b + 1, x, 0, 0, N); }
void add(int a, int b, int x, int k, int l, int r) {
if (a <= l && r <= b) {
data[k] += x;
} else if (l < b && a < r) {
datb[k] += (min(b, r) - max(a, l)) * x;
add(a, b, x, k * 2 + 1, l, (l + r) / 2);
add(a, b, x, k * 2 + 2, (l + r) / 2, r);
}
}
void change(int a, int b, int x) { change(a, b + 1, x, 0, 0, N); }
void change(int a, int b, int x, int k, int l, int r) {
if (a <= l && r <= b) {
data[k] = x;
} else if (l < b && a < r) {
datb[k] = x;
change(a, b, x, k * 2 + 1, l, (l + r) / 2);
change(a, b, x, k * 2 + 2, (l + r) / 2, r);
}
}
ll sum(int a, int b) { return sum(a, b + 1, 0, 0, N); }
ll sum(int a, int b, int k, int l, int r) {
if (b <= l || r <= a) {
return 0;
}
if (a <= l && r <= b) {
return data[k] * (r - l) + datb[k];
}
ll res = (min(b, r) - max(a, l)) * data[k];
res += sum(a, b, k * 2 + 1, l, (l + r) / 2);
res += sum(a, b, k * 2 + 2, (l + r) / 2, r);
return res;
}
};
class Segment;
class Circle;
class Point {
public:
double x, y;
Point(double x = 0, double y = 0) : x(x), y(y) {}
Point operator+(Point p) { return Point(x + p.x, y + p.y); }
Point operator-(Point p) { return Point(x - p.x, y - p.y); }
Point operator*(double a) { return Point(a * x, a * y); }
Point operator/(double a) { return Point(x / a, y / a); }
double abs() { return sqrt(norm()); }
double norm() { return x * x + y * y; }
bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; }
bool operator==(const Point &p) const {
return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
}
static double dot(Point a, Point b) { return a.x * b.x + a.y * b.y; }
static double cross(Point a, Point b) { return a.x * b.y - a.y * b.x; }
static bool isOrthogonal(Point a, Point b) { return EQ(dot(a, b), 0.0); }
static bool isOrthogonal(Point a1, Point a2, Point b1, Point b2) {
return isOrthogonal(a1 - a2, b1 - b2);
}
static bool isOrthogonal(Segment s1, Segment s2);
static bool isPalallel(Point a, Point b) { return EQ(cross(a, b), 0.0); }
static bool isPalallel(Point a1, Point a2, Point b1, Point b2) {
return isPalallel(a1 - a2, b1 - b2);
}
static bool isPalallel(Segment s1, Segment s2);
static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;
static int ccw(Point p0, Point p1, Point p2) {
// 線分はp0とp1でp2がどこにあるかを探る
Point a = p1 - p0;
Point b = p2 - p0;
if (cross(a, b) > EPS)
return COUNTER_CLOCKWISE;
if (cross(a, b) < -EPS)
return CLOCKWISE;
if (dot(a, b) < -EPS)
return ONLINE_BACK;
if (a.norm() < b.norm())
return ONLINE_FRONT;
return ON_SEGMENT;
}
static bool intersect(Point p1, Point p2, Point p3, Point p4) {
return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 &&
ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0);
}
static bool intersect(Segment s1, Segment s2);
static Point project(Segment s, Point p);
static Point reflect(Segment s, Point p);
static Point getDistance(Point a, Point b) { return (a - b).abs(); }
static double getDistanceLP(Segment s, Point p);
static double getDistanceSP(Segment s, Point p);
static double getDistance(Segment s1, Segment s2);
static Point getIntersection(Segment s1, Segment s2);
static pair<Point, Point> crossPoints(Circle c, Segment s);
static int contains(vector<Point> g, Point p) {
int n = g.size();
bool x = false;
rep(i, n) {
Point a = g[i] - p, b = g[(i + 1) % n] - p;
// 線の上に載っているか
if (std::abs(cross(a, b)) < EPS && dot(a, b) < EPS)
return 1;
// pを基準として上下にあるか
// または外積が正か?(→にあるか)
if (a.y > b.y)
swap(a, b);
if (a.y < EPS && EPS < b.y && cross(a, b) > EPS)
x = !x;
}
return x ? 2 : 0;
}
static vector<Point> andrewScan(vector<Point> s) {
vector<Point> u, l;
if (s.size() < 3)
return s;
sort(all(s));
u.push_back(s[0]);
u.push_back(s[1]);
l.push_back(s[s.size() - 1]);
l.push_back(s[s.size() - 2]);
for (int i = 2; i < s.size(); i++) {
for (int _n = u.size();
_n >= 2 && ccw(u[_n - 2], u[_n - 1], s[i]) > CLOCKWISE; _n--) {
u.pop_back();
}
u.push_back(s[i]);
}
for (int i = s.size() - 3; i >= 0; i--) {
for (int _n = l.size();
_n >= 2 && ccw(l[_n - 2], l[_n - 1], s[i]) > CLOCKWISE; _n--) {
l.pop_back();
}
l.push_back(s[i]);
}
reverse(all(l));
for (int i = u.size() - 2; i >= 1; i--) {
l.push_back(u[i]);
}
return l;
}
void get_cin() { cin >> x >> y; }
};
class Segment {
public:
Point p1, p2;
Segment() {}
Segment(Point p1, Point p2) : p1(p1), p2(p2) {}
void get_cin() { cin >> p1.x >> p1.y >> p2.x >> p2.y; }
Point p1tp2() { return p2 - p1; }
Point p2tp1() { return p1 - p2; }
double abs() { return std::abs(norm()); }
double norm() { return (p2 - p1).norm(); }
};
bool Point::isOrthogonal(Segment s1, Segment s2) {
return EQ(dot(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
bool Point::isPalallel(Segment s1, Segment s2) {
return EQ(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
bool Point::intersect(Segment s1, Segment s2) {
return intersect(s1.p1, s1.p2, s2.p1, s2.p2);
}
Point Point::project(Segment s, Point p) {
Point base = s.p2 - s.p1;
double r = Point::dot(p - s.p1, base) / base.norm();
return s.p1 + base * r;
}
Point Point::reflect(Segment s, Point p) { return (project(s, p) * 2) - p; }
double Point::getDistanceLP(Segment s, Point p) {
return std::abs(cross(s.p2 - s.p1, p - s.p1) / (s.p2 - s.p1).abs());
}
double Point::getDistanceSP(Segment s, Point p) {
if (dot(s.p2 - s.p1, p - s.p1) < 0.0)
return (p - s.p1).abs();
if (dot(s.p1 - s.p2, p - s.p2) < 0.0)
return (p - s.p2).abs();
return getDistanceLP(s, p);
}
double Point::getDistance(Segment s1, Segment s2) {
if (intersect(s1, s2))
return 0.0;
return min({getDistanceSP(s1, s2.p1), getDistanceSP(s1, s2.p2),
getDistanceSP(s2, s1.p1), getDistanceSP(s2, s1.p2)});
}
Point Point::getIntersection(Segment s1, Segment s2) {
// (s1.p1 - s2.p1).norm()
auto bs = s1.p2 - s1.p1;
auto n1 = s2.p1 - s1.p1;
auto n2 = s2.p2 - s1.p1;
auto c1 = std::abs(cross(n1, bs)) / bs.norm();
auto c2 = std::abs(cross(n2, bs)) / bs.norm();
return s2.p1 + (s2.p2 - s2.p1) * (c1 / (c1 + c2));
// c1:c2=t:1-t
// c2t=(1-t)c1
// t/(1-t)=c1/(c1+c2)
//
}
double arg(Point p) { return atan2(p.y, p.x); }
Point polar(double a, double r) { return Point(cos(r) * a, sin(r) * a); }
class Circle {
public:
Point c;
double r;
Circle(Point c = Point(), double r = 0.0) : c(c), r(r) {}
void get_cin() { cin >> c.x >> c.y >> r; }
static pair<Point, Point> getCrossPoints(Circle c1, Circle c2) {
double d = (c1.c - c2.c).abs(); // 中心点どうしの距離
double a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d));
double t = arg(c2.c - c1.c);
return make_pair(c1.c + polar(c1.r, t + a), c1.c + polar(c1.r, t - a));
}
};
pair<Point, Point> Point::crossPoints(Circle c, Segment s) {
auto pp = project(s, c.c);
auto f = (pp - c.c).norm();
auto mu = sqrt(c.r * c.r - f);
auto e = s.p1tp2() / s.p1tp2().abs();
return make_pair(pp + e * mu, pp - e * mu);
}
ll divRm(string s, ll x) {
ll r = 0;
for (ll i = 0; i < s.size(); i++) {
r *= 10;
r += s[i] - '0';
r %= x;
}
return r;
}
ll cmbi(ll x, ll b) {
ll res = 1;
for (size_t i = 0; i < b; i++) {
res *= x - i;
res %= INF;
res *= inv[b - i];
res %= INF;
}
return res;
}
double digsum(ll x) {
ll res = 0;
while (x > 0) {
res += x % 10;
x /= 10;
}
return res;
}
bool check_parindrome(string s) {
int n = s.size();
rep(i, n / 2) {
if (s[i] != s[n - i - 1]) {
return false;
}
}
return true;
}
ll npr(ll n, ll r) {
if (r == 0)
return 1;
return inff(fac[n] * modinv(fac[n - r]));
}
vl zalgo(string s) {
ll c = 0;
vl a(s.size());
ll si = s.size();
rep2(i, 1, s.size()) {
if (i + a[i - c] < c + a[c]) {
a[i] = a[i - c];
} else {
ll j = max(0LL, a[c] - (i - c));
while (i + j < si && s[j] == s[i + j]) {
j++;
}
a[i] = j;
c = i;
}
}
a[0] = s.size();
return a;
}
string decStrNum(string s) {
ll si = s.size();
for (int i = si - 1; i >= 0; i--) {
if (s[i] == '0') {
s[i] = '9';
continue;
}
s[i] = s[i] - 1;
break;
}
return s;
}
// ここまでライブラリ
// ここからコード
ll a[100010];
ll dp[63][2];
ll rec(ll x, bool tite) {
if (x < 0)
return 0;
if (~dp[x][tite])
return dp[x][tite];
ll v = 1LL << x;
ll cnt = 0;
rep(i, n) {
if (a[i] & v) {
cnt++;
}
}
ll res = 0;
if (tite) {
ll p = k & v;
if (p > 0) {
res = rec(x - 1, tite) + (n - cnt) * v;
res = max(res, rec(x - 1, false) + cnt * v);
} else {
res = rec(x - 1, tite) + cnt * v;
}
} else {
res = rec(x - 1, false) + max(cnt, n - cnt) * v;
}
return dp[x][tite] = res;
}
void solv() {
cin >> n >> k;
rep(i, n) { cin >> a[i]; }
allm1(dp);
cout << rec(62, true) << endl;
}
int main() {
COMinit();
solv();
return 0;
}
| [
"assignment.value.change",
"identifier.change",
"expression.operation.binary.change",
"call.arguments.change"
] | 938,815 | 938,816 | u224756887 | cpp |
p03138 | #include <algorithm>
#include <array>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctype.h>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <unordered_map>
#include <utility>
#include <vector>
#define _USE_MATH_DEFINES
#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, double> pld;
typedef pair<double, double> pdd;
typedef pair<double, ll> pdl;
typedef pair<int, char> pic;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef priority_queue<ll, vector<ll>, greater<ll>> llgreaterq;
typedef priority_queue<pll, vector<pll>, greater<pll>> pllgreaterq;
typedef priority_queue<pair<ll, pll>, vector<pair<ll, pll>>,
greater<pair<ll, pll>>>
plpllgreaterq;
typedef priority_queue<vi, vector<vi>, greater<vi>> vigreaterq;
typedef priority_queue<vl, vector<vl>, greater<vl>> vlgreaterq;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
#define bit(x, v) ((ll)x << v)
#define rep(x, n) for (ll x = 0; x < n; x++)
#define rep2(x, f, v) for (ll x = f; x < v; x++)
#define repe(v, x) for (auto v : x)
// 許容する誤差ε
#define EPS (1e-10)
// 2つのスカラーが等しいかどうか
#define EQ(a, b) (std::abs(a - b) < EPS)
// 2つのベクトルが等しいかどうか
#define EQV(a, b) (EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()))
#define all(a) a.begin(), a.end()
#define all0(a) memset(a, 0, sizeof(a))
#define allm1(a) memset(a, -1, sizeof(a))
#define put_float(v) \
cout << fixed << setprecision(10); \
cout << v << endl
#define vinsert(v, p, x) v.insert(v.begin() + p, x)
#define vsort(v) sort(all(v));
#define dup(v) v.erase(unique(all(v)), v.end())
#define ion(i, j) ((i & (1LL << j)) > 0)
#define next(i) \
i++; \
i %= 2
#define Len size()
#define ull unsignd long long
#define psp(a, b) push_back(make_pair(a, b))
const ll INF = 1000000007;
const int MAX = 2000010;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll getpow(ll b, ll x, ll md) {
ll t = b;
ll res = 1;
while (x > 0) {
if (x & 1) {
res *= t;
res %= md;
}
x >>= 1;
t *= t;
t %= md;
}
return res;
}
ll getpow(ll b, ll x) { return getpow(b, x, INF); }
ll modinv(ll x) { return getpow(x, INF - 2); }
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
int pr[100010];
int lank[100010];
void uini(int n) {
for (size_t i = 0; i <= n; i++) {
pr[i] = i;
lank[i] = 1;
}
}
int parent(int x) {
if (x == pr[x])
return x;
return pr[x] = parent(pr[x]);
}
int same(int x, int y) { return parent(x) == parent(y); }
bool unit(int x, int y) {
int px = parent(x);
int py = parent(y);
if (px == py)
return false;
if (lank[py] < lank[px]) {
pr[py] = px;
lank[px] += lank[py];
} else {
pr[px] = py;
lank[py] += lank[px];
}
return true;
}
ll merge(ll *a, int left, int mid, int right) {
ll n1 = mid - left;
ll n2 = right - mid;
vector<int> L(n1 + 1);
vector<int> R(n2 + 1);
for (size_t i = 0; i < n1; i++) {
L[i] = a[left + i];
}
for (size_t i = 0; i < n2; i++) {
R[i] = a[mid + i];
}
L[n1] = INF;
R[n2] = INF;
ll i = 0;
ll j = 0;
ll r = 0;
for (size_t k = left; k < right; k++) {
if (L[i] <= R[j]) {
a[k] = L[i];
i++;
} else {
a[k] = R[j];
r += n1 - i;
j++;
}
}
return r;
}
ll merge2(pair<int, char> *a, int left, int mid, int right) {
ll n1 = mid - left;
ll n2 = right - mid;
vector<pair<int, char>> L(n1 + 1);
vector<pair<int, char>> R(n2 + 1);
for (size_t i = 0; i < n1; i++) {
L[i] = a[left + i];
}
for (size_t i = 0; i < n2; i++) {
R[i] = a[mid + i];
}
L[n1] = make_pair(INF, ' ');
R[n2] = make_pair(INF, ' ');
ll i = 0;
ll j = 0;
ll r = 0;
for (size_t k = left; k < right; k++) {
if (L[i].first <= R[j].first) {
a[k] = L[i];
i++;
} else {
a[k] = R[j];
r += n1 - i;
j++;
}
}
return r;
}
ll mergeSort2(pair<int, char> *a, int left, int right) {
ll res = 0;
if (left + 1 < right) {
int mid = (left + right) / 2;
res = mergeSort2(a, left, mid);
res += mergeSort2(a, mid, right);
res += merge2(a, left, mid, right);
}
return res;
}
ll mergeSort(ll *a, int left, int right) {
ll res = 0;
if (left + 1 < right) {
int mid = (left + right) / 2;
res = mergeSort(a, left, mid);
res += mergeSort(a, mid, right);
res += merge(a, left, mid, right);
}
return res;
}
int partition(pair<int, char> *a, int p, int r) {
pair<int, char> x = a[r];
int i = p - 1;
for (size_t j = p; j < r; j++) {
if (a[j].first <= x.first) {
i++;
swap(a[i], a[j]);
}
}
swap(a[i + 1], a[r]);
return i + 1;
}
void quick(pair<int, char> *a, int p, int r) {
if (p < r) {
int q = partition(a, p, r);
quick(a, p, q - 1);
quick(a, q + 1, r);
}
}
ll n;
int ci = 0;
ll P[1000010];
struct Node {
int key;
int priority;
Node *parent, *left, *right;
Node(int key, int priority);
Node() {}
};
Node NIL;
Node::Node(int key, int priority) : key(key), priority(priority) {
left = &NIL;
right = &NIL;
}
Node *root = new Node();
void cenrec(Node *k) {
if (k->key == NIL.key)
return;
cenrec(k->left);
cout << " " << k->key;
cenrec(k->right);
}
void fastrec(Node *k) {
if (k->key == NIL.key)
return;
cout << " " << k->key;
fastrec(k->left);
fastrec(k->right);
}
void insert(Node *v) {
Node *y = &NIL;
Node *x = root;
while (x->key != NIL.key) {
y = x;
if (v->key < x->key) {
x = x->left;
} else {
x = x->right;
}
}
v->parent = y;
if (y->key == NIL.key) {
root = v;
} else if (v->key < y->key) {
y->left = v;
} else {
y->right = v;
}
}
Node *find(Node *k, ll v) {
if (k->key == NIL.key)
return &NIL;
if (k->key == v)
return k;
if (v < k->key)
return find(k->left, v);
return find(k->right, v);
}
void delp12(Node *x) {
if (x->key == NIL.key)
return;
Node *l = x->left;
Node *r = x->right;
Node *pr = x->parent;
if (l->key == NIL.key && r->key == NIL.key) {
if (pr->left == x) {
pr->left = &NIL;
} else
pr->right = &NIL;
} else if (l->key != NIL.key) {
if (pr->left == x) {
pr->left = l;
} else
pr->right = l;
l->parent = pr;
} else if (r->key != NIL.key) {
if (pr->left == x) {
pr->left = r;
} else
pr->right = r;
r->parent = pr;
}
}
Node *get_next(Node *k) {
if (k->key == NIL.key)
return &NIL;
Node *res = get_next(k->left);
if (res->key != NIL.key)
return res;
return k;
}
void del(Node *x) {
if (x->key == NIL.key)
return;
Node *l = x->left;
Node *r = x->right;
Node *pr = x->parent;
if (l->key != NIL.key && r->key != NIL.key) {
Node *nex = get_next(r);
x->key = nex->key;
delp12(nex);
} else {
delp12(x);
}
}
Node *rightRotate(Node *t) {
Node *s = t->left;
t->left = s->right;
s->right = t;
return s;
}
Node *leftRotate(Node *t) {
Node *s = t->right;
t->right = s->left;
s->left = t;
return s;
}
Node *_insert(Node *t, int key, int priority) {
if (t->key == NIL.key) {
return new Node(key, priority);
}
if (key == t->key) {
return t;
}
if (key < t->key) {
t->left = _insert(t->left, key, priority);
if (t->priority < t->left->priority) {
t = rightRotate(t);
}
} else {
t->right = _insert(t->right, key, priority);
if (t->priority < t->right->priority) {
t = leftRotate(t);
}
}
return t;
}
Node *delete1(Node *t, int key);
Node *_delete(Node *t, int key) {
if (t->left->key == NIL.key && t->right->key == NIL.key) {
return &NIL;
} else if (t->left->key == NIL.key) {
t = leftRotate(t);
} else if (t->right->key == NIL.key) {
t = rightRotate(t);
} else {
if (t->left->priority > t->right->priority) {
t = rightRotate(t);
} else
t = leftRotate(t);
}
return delete1(t, key);
}
Node *delete1(Node *t, int key) {
if (t->key == NIL.key) {
return &NIL;
}
if (key < t->key) {
t->left = delete1(t->left, key);
} else if (key > t->key) {
t->right = delete1(t->right, key);
} else
return _delete(t, key);
return t;
}
int H;
int left(int i) { return i * 2 + 1; }
int right(int i) { return i * 2 + 2; }
struct edge {
int from, to;
ll val;
edge(int from, int to, ll val) : from(from), to(to), val(val) {}
};
ll k;
int _rank[1010];
int temp[1010];
bool compare_sa(int i, int j) {
if (_rank[i] != _rank[j])
return _rank[i] < _rank[j];
else {
int ri = i + k <= n ? _rank[i + k] : -1;
int rj = j + k <= n ? _rank[j + k] : -1;
return ri < rj;
}
}
void construct_sa(string S, int *sa) {
n = S.length();
for (size_t i = 0; i <= n; i++) {
sa[i] = i;
_rank[i] = i < n ? S[i] : -1;
}
for (k = 1; k <= n; k *= 2) {
sort(sa, sa + n + 1, compare_sa);
// saはソート後の接尾辞の並びになっている、rankは元の位置のindexを保持したまま、更新されている。
// ピンとこなかった部分
temp[sa[0]] = 0;
for (size_t i = 1; i <= n; i++) {
temp[sa[i]] = temp[sa[i - 1]] + (compare_sa(sa[i - 1], sa[i]) ? 1 : 0);
}
for (size_t i = 0; i <= n; i++) {
_rank[i] = temp[i];
}
}
}
bool contain(string S, int *sa, string T) {
int a = 0, b = S.length();
// sa は 接尾辞が辞書順に並んでいる、入っているのはその位置のインデックス
while (b - a > 1) {
int c = (a + b) / 2;
if (S.compare(sa[c], T.length(), T) < 0)
a = c;
else
b = c;
}
return S.compare(sa[b], T.length(), T) == 0;
}
#define bit(x, v) ((ll)x << v)
class BIT {
static const int MAX_N = 500010;
public:
BIT() { memset(bit, 0, sizeof(bit)); }
ll bit[MAX_N + 1], n;
ll sum(int i) {
ll s = 0;
while (i > 0) {
s += bit[i];
i -= i & -i;
}
return s;
}
void add(int i, int x) {
while (i <= n) {
bit[i] += x;
i += i & -i;
}
}
};
struct UnionFind {
vector<int> A;
UnionFind(int n) : A(n, -1) {}
int find(int x) {
if (A[x] < 0)
return x;
return A[x] = find(A[x]);
}
void unite(int x, int y) {
x = find(x), y = find(y);
if (x == y)
return;
if (A[x] > A[y])
swap(x, y);
A[x] += A[y];
A[y] = x;
}
int ngroups() {
int ans = 0;
for (auto a : A)
if (a < 0)
ans++;
return ans;
}
};
void yes() {
cout << "Yes\n";
exit(0);
}
void no() {
cout << "No\n";
exit(0);
}
vector<ll> getp(ll n) {
vector<ll> res;
ll a = 2;
if (n % 2 == 0) {
res.push_back(2);
while (n % 2 == 0)
n /= 2;
}
for (ll i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
res.push_back(i);
while (n % i == 0)
n /= i;
}
}
if (n != 1)
res.push_back(n);
return res;
}
vector<ll> getp2(ll n) {
vector<ll> res;
ll a = 2;
if (n % 2 == 0) {
while (n % 2 == 0) {
n /= 2;
res.push_back(2);
}
}
for (ll i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
while (n % i == 0) {
n /= i;
res.push_back(i);
}
}
}
if (n != 1)
res.push_back(n);
return res;
}
vector<pll> getp3(ll n) {
vector<pll> res;
ll a = 2;
int si = 0;
if (n % 2 == 0) {
res.push_back(make_pair(2, 0));
while (n % 2 == 0) {
n /= 2;
res[si].second++;
}
si++;
}
for (ll i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
res.push_back(make_pair(i, 0));
while (n % i == 0) {
n /= i;
res[si].second++;
}
si++;
}
}
if (n != 1) {
res.push_back(make_pair(n, 1));
}
return res;
}
vector<ll> getDivisors(ll n) {
vector<ll> res;
ll a = 2;
res.push_back(1);
for (ll i = 2; i * i <= n; i++) {
if (n % i == 0) {
res.push_back(i);
if (n / i != i)
res.push_back(n / i);
}
}
return res;
}
struct ve {
public:
vector<ve> child;
int _t = INF;
ve(int t) : _t(t) {}
ve(ve _left, ve _right) {
_t = _left._t + _right._t;
child.push_back(_left);
child.push_back(_right);
}
bool operator<(const ve &t) const { return _t > t._t; }
};
vector<bool> elas(ll n) {
vector<bool> r(n);
fill(r.begin(), r.end(), 1);
r[0] = 0;
r[1] = 0;
for (ll i = 2; i * i < n; i++) {
if (!r[i])
continue;
ll ti = i * 2;
while (ti < n) {
r[ti] = false;
ti += i;
}
}
return r;
}
bool isPrime(ll v) {
for (ll i = 2; i * i <= v; i++) {
if (v % i == 0)
return false;
}
return true;
}
class SegTree {
public:
const static int MAX_N = 100010;
const static int DAT_SIZE = (1 << 18) - 1;
int N, Q;
int A[MAX_N];
ll data[DAT_SIZE], datb[DAT_SIZE];
void init(int _n) {
N = 1;
while (N < _n)
N <<= 1;
memset(data, 0, sizeof(data));
memset(datb, 0, sizeof(datb));
}
void init(int _n, ll iv) {
N = 1;
while (N < _n)
N <<= 1;
rep(i, DAT_SIZE) {
data[i] = iv;
datb[i] = iv;
}
}
void add(int a, int b, int x) { add(a, b + 1, x, 0, 0, N); }
void add(int a, int b, int x, int k, int l, int r) {
if (a <= l && r <= b) {
data[k] += x;
} else if (l < b && a < r) {
datb[k] += (min(b, r) - max(a, l)) * x;
add(a, b, x, k * 2 + 1, l, (l + r) / 2);
add(a, b, x, k * 2 + 2, (l + r) / 2, r);
}
}
void change(int a, int b, int x) { change(a, b + 1, x, 0, 0, N); }
void change(int a, int b, int x, int k, int l, int r) {
if (a <= l && r <= b) {
data[k] = x;
} else if (l < b && a < r) {
datb[k] = x;
change(a, b, x, k * 2 + 1, l, (l + r) / 2);
change(a, b, x, k * 2 + 2, (l + r) / 2, r);
}
}
ll sum(int a, int b) { return sum(a, b + 1, 0, 0, N); }
ll sum(int a, int b, int k, int l, int r) {
if (b <= l || r <= a) {
return 0;
}
if (a <= l && r <= b) {
return data[k] * (r - l) + datb[k];
}
ll res = (min(b, r) - max(a, l)) * data[k];
res += sum(a, b, k * 2 + 1, l, (l + r) / 2);
res += sum(a, b, k * 2 + 2, (l + r) / 2, r);
return res;
}
};
class Segment;
class Circle;
class Point {
public:
double x, y;
Point(double x = 0, double y = 0) : x(x), y(y) {}
Point operator+(Point p) { return Point(x + p.x, y + p.y); }
Point operator-(Point p) { return Point(x - p.x, y - p.y); }
Point operator*(double a) { return Point(a * x, a * y); }
Point operator/(double a) { return Point(x / a, y / a); }
double abs() { return sqrt(norm()); }
double norm() { return x * x + y * y; }
bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; }
bool operator==(const Point &p) const {
return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
}
static double dot(Point a, Point b) { return a.x * b.x + a.y * b.y; }
static double cross(Point a, Point b) { return a.x * b.y - a.y * b.x; }
static bool isOrthogonal(Point a, Point b) { return EQ(dot(a, b), 0.0); }
static bool isOrthogonal(Point a1, Point a2, Point b1, Point b2) {
return isOrthogonal(a1 - a2, b1 - b2);
}
static bool isOrthogonal(Segment s1, Segment s2);
static bool isPalallel(Point a, Point b) { return EQ(cross(a, b), 0.0); }
static bool isPalallel(Point a1, Point a2, Point b1, Point b2) {
return isPalallel(a1 - a2, b1 - b2);
}
static bool isPalallel(Segment s1, Segment s2);
static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;
static int ccw(Point p0, Point p1, Point p2) {
Point a = p1 - p0;
Point b = p2 - p0;
if (cross(a, b) > EPS)
return COUNTER_CLOCKWISE;
if (cross(a, b) < -EPS)
return CLOCKWISE;
if (dot(a, b) < -EPS)
return ONLINE_BACK;
if (a.norm() < b.norm())
return ONLINE_FRONT;
return ON_SEGMENT;
}
static bool intersect(Point p1, Point p2, Point p3, Point p4) {
return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 &&
ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0);
}
static bool intersect(Segment s1, Segment s2);
static Point project(Segment s, Point p);
static Point reflect(Segment s, Point p);
static Point getDistance(Point a, Point b) { return (a - b).abs(); }
static double getDistanceLP(Segment s, Point p);
static double getDistanceSP(Segment s, Point p);
static double getDistance(Segment s1, Segment s2);
static Point getIntersection(Segment s1, Segment s2);
static pair<Point, Point> crossPoints(Circle c, Segment s);
static int contains(vector<Point> g, Point p) {
int n = g.size();
bool x = false;
rep(i, n) {
Point a = g[i] - p, b = g[(i + 1) % n] - p;
// 線の上に載っているか
if (std::abs(cross(a, b)) < EPS && dot(a, b) < EPS)
return 1;
// pを基準として上下にあるか
// または外積が正か?(→にあるか)
if (a.y > b.y)
swap(a, b);
if (a.y < EPS && EPS < b.y && cross(a, b) > EPS)
x = !x;
}
return x ? 2 : 0;
}
static vector<Point> andrewScan(vector<Point> s) {
vector<Point> u, l;
if (s.size() < 3)
return s;
sort(all(s));
u.push_back(s[0]);
u.push_back(s[1]);
l.push_back(s[s.size() - 1]);
l.push_back(s[s.size() - 2]);
for (int i = 2; i < s.size(); i++) {
for (int _n = u.size();
_n >= 2 && ccw(u[_n - 2], u[_n - 1], s[i]) > CLOCKWISE; _n--) {
u.pop_back();
}
u.push_back(s[i]);
}
for (int i = s.size() - 3; i >= 0; i--) {
for (int _n = l.size();
_n >= 2 && ccw(l[_n - 2], l[_n - 1], s[i]) > CLOCKWISE; _n--) {
l.pop_back();
}
l.push_back(s[i]);
}
reverse(all(l));
for (int i = u.size() - 2; i >= 1; i--) {
l.push_back(u[i]);
}
return l;
}
void get_cin() { cin >> x >> y; }
};
class Segment {
public:
Point p1, p2;
Segment() {}
Segment(Point p1, Point p2) : p1(p1), p2(p2) {}
void get_cin() { cin >> p1.x >> p1.y >> p2.x >> p2.y; }
Point p1tp2() { return p2 - p1; }
Point p2tp1() { return p1 - p2; }
double abs() { return std::abs(norm()); }
double norm() { return (p2 - p1).norm(); }
};
bool Point::isOrthogonal(Segment s1, Segment s2) {
return EQ(dot(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
bool Point::isPalallel(Segment s1, Segment s2) {
return EQ(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
bool Point::intersect(Segment s1, Segment s2) {
return intersect(s1.p1, s1.p2, s2.p1, s2.p2);
}
Point Point::project(Segment s, Point p) {
Point base = s.p2 - s.p1;
double r = Point::dot(p - s.p1, base) / base.norm();
return s.p1 + base * r;
}
Point Point::reflect(Segment s, Point p) { return (project(s, p) * 2) - p; }
double Point::getDistanceLP(Segment s, Point p) {
return std::abs(cross(s.p2 - s.p1, p - s.p1) / (s.p2 - s.p1).abs());
}
double Point::getDistanceSP(Segment s, Point p) {
if (dot(s.p2 - s.p1, p - s.p1) < 0.0)
return (p - s.p1).abs();
if (dot(s.p1 - s.p2, p - s.p2) < 0.0)
return (p - s.p2).abs();
return getDistanceLP(s, p);
}
double Point::getDistance(Segment s1, Segment s2) {
if (intersect(s1, s2))
return 0.0;
return min({getDistanceSP(s1, s2.p1), getDistanceSP(s1, s2.p2),
getDistanceSP(s2, s1.p1), getDistanceSP(s2, s1.p2)});
}
Point Point::getIntersection(Segment s1, Segment s2) {
// (s1.p1 - s2.p1).norm()
auto bs = s1.p2 - s1.p1;
auto n1 = s2.p1 - s1.p1;
auto n2 = s2.p2 - s1.p1;
auto c1 = std::abs(cross(n1, bs)) / bs.norm();
auto c2 = std::abs(cross(n2, bs)) / bs.norm();
return s2.p1 + (s2.p2 - s2.p1) * (c1 / (c1 + c2));
// c1:c2=t:1-t
// c2t=(1-t)c1
// t/(1-t)=c1/(c1+c2)
//
}
double arg(Point p) { return atan2(p.y, p.x); }
Point polar(double a, double r) { return Point(cos(r) * a, sin(r) * a); }
class Circle {
public:
Point c;
double r;
Circle(Point c = Point(), double r = 0.0) : c(c), r(r) {}
void get_cin() { cin >> c.x >> c.y >> r; }
static pair<Point, Point> getCrossPoints(Circle c1, Circle c2) {
double d = (c1.c - c2.c).abs(); // 中心点どうしの距離
double a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d));
double t = arg(c2.c - c1.c);
return make_pair(c1.c + polar(c1.r, t + a), c1.c + polar(c1.r, t - a));
}
};
pair<Point, Point> Point::crossPoints(Circle c, Segment s) {
auto pp = project(s, c.c);
auto f = (pp - c.c).norm();
auto mu = sqrt(c.r * c.r - f);
auto e = s.p1tp2() / s.p1tp2().abs();
return make_pair(pp + e * mu, pp - e * mu);
}
ll divRm(string s, ll x) {
ll r = 0;
for (ll i = 0; i < s.size(); i++) {
r *= 10;
r += s[i] - '0';
r %= x;
}
return r;
}
ll cmbi(ll x, ll b) {
ll res = 1;
for (size_t i = 0; i < b; i++) {
res *= x - i;
res %= INF;
res *= inv[b - i];
res %= INF;
}
return res;
}
double digsum(ll x) {
ll res = 0;
while (x > 0) {
res += x % 10;
x /= 10;
}
return res;
}
bool check_parindrome(string s) {
int n = s.size();
rep(i, n / 2) {
if (s[i] != s[n - i - 1]) {
return false;
}
}
return true;
}
ll memo[65][2];
ll a[100010];
ll rec(ll x, bool tite) {
if (x < 0)
return 0;
if (~memo[x][tite])
return memo[x][tite];
ll v = 1LL << x;
ll cnt = 0;
rep(i, n) {
if (a[i] & v) {
cnt++;
}
}
ll res = 0;
if (tite) {
if ((k & v) == 0) {
res = rec(x - 1, tite) + cnt * v;
} else {
res = rec(x - 1, tite) + (n - cnt) * v;
res = max(res, rec(x - 1, tite) + cnt * v);
}
} else {
res = rec(x - 1, tite) + v * max(cnt, n - cnt);
}
return memo[x][tite] = res;
}
void solv() {
cin >> n >> k;
rep(i, n) cin >> a[i];
allm1(memo);
cout << rec(62, true) << endl;
}
int main() {
COMinit();
solv();
return 0;
} | #include <algorithm>
#include <array>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctype.h>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <unordered_map>
#include <utility>
#include <vector>
#define _USE_MATH_DEFINES
#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, double> pld;
typedef pair<double, double> pdd;
typedef pair<double, ll> pdl;
typedef pair<int, char> pic;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef priority_queue<ll, vector<ll>, greater<ll>> llgreaterq;
typedef priority_queue<pll, vector<pll>, greater<pll>> pllgreaterq;
typedef priority_queue<pair<ll, pll>, vector<pair<ll, pll>>,
greater<pair<ll, pll>>>
plpllgreaterq;
typedef priority_queue<vi, vector<vi>, greater<vi>> vigreaterq;
typedef priority_queue<vl, vector<vl>, greater<vl>> vlgreaterq;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
#define bit(x, v) ((ll)x << v)
#define rep(x, n) for (ll x = 0; x < n; x++)
#define rep2(x, f, v) for (ll x = f; x < v; x++)
#define repe(v, x) for (auto v : x)
// 許容する誤差ε
#define EPS (1e-10)
// 2つのスカラーが等しいかどうか
#define EQ(a, b) (std::abs(a - b) < EPS)
// 2つのベクトルが等しいかどうか
#define EQV(a, b) (EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()))
#define all(a) a.begin(), a.end()
#define all0(a) memset(a, 0, sizeof(a))
#define allm1(a) memset(a, -1, sizeof(a))
#define put_float(v) \
cout << fixed << setprecision(10); \
cout << v << endl
#define vinsert(v, p, x) v.insert(v.begin() + p, x)
#define vsort(v) sort(all(v));
#define dup(v) v.erase(unique(all(v)), v.end())
#define ion(i, j) ((i & (1LL << j)) > 0)
#define next(i) \
i++; \
i %= 2
#define Len size()
#define ull unsignd long long
#define psp(a, b) push_back(make_pair(a, b))
const ll INF = 1000000007;
const int MAX = 2000010;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll getpow(ll b, ll x, ll md) {
ll t = b;
ll res = 1;
while (x > 0) {
if (x & 1) {
res *= t;
res %= md;
}
x >>= 1;
t *= t;
t %= md;
}
return res;
}
ll getpow(ll b, ll x) { return getpow(b, x, INF); }
ll modinv(ll x) { return getpow(x, INF - 2); }
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
int pr[100010];
int lank[100010];
void uini(int n) {
for (size_t i = 0; i <= n; i++) {
pr[i] = i;
lank[i] = 1;
}
}
int parent(int x) {
if (x == pr[x])
return x;
return pr[x] = parent(pr[x]);
}
int same(int x, int y) { return parent(x) == parent(y); }
bool unit(int x, int y) {
int px = parent(x);
int py = parent(y);
if (px == py)
return false;
if (lank[py] < lank[px]) {
pr[py] = px;
lank[px] += lank[py];
} else {
pr[px] = py;
lank[py] += lank[px];
}
return true;
}
ll merge(ll *a, int left, int mid, int right) {
ll n1 = mid - left;
ll n2 = right - mid;
vector<int> L(n1 + 1);
vector<int> R(n2 + 1);
for (size_t i = 0; i < n1; i++) {
L[i] = a[left + i];
}
for (size_t i = 0; i < n2; i++) {
R[i] = a[mid + i];
}
L[n1] = INF;
R[n2] = INF;
ll i = 0;
ll j = 0;
ll r = 0;
for (size_t k = left; k < right; k++) {
if (L[i] <= R[j]) {
a[k] = L[i];
i++;
} else {
a[k] = R[j];
r += n1 - i;
j++;
}
}
return r;
}
ll merge2(pair<int, char> *a, int left, int mid, int right) {
ll n1 = mid - left;
ll n2 = right - mid;
vector<pair<int, char>> L(n1 + 1);
vector<pair<int, char>> R(n2 + 1);
for (size_t i = 0; i < n1; i++) {
L[i] = a[left + i];
}
for (size_t i = 0; i < n2; i++) {
R[i] = a[mid + i];
}
L[n1] = make_pair(INF, ' ');
R[n2] = make_pair(INF, ' ');
ll i = 0;
ll j = 0;
ll r = 0;
for (size_t k = left; k < right; k++) {
if (L[i].first <= R[j].first) {
a[k] = L[i];
i++;
} else {
a[k] = R[j];
r += n1 - i;
j++;
}
}
return r;
}
ll mergeSort2(pair<int, char> *a, int left, int right) {
ll res = 0;
if (left + 1 < right) {
int mid = (left + right) / 2;
res = mergeSort2(a, left, mid);
res += mergeSort2(a, mid, right);
res += merge2(a, left, mid, right);
}
return res;
}
ll mergeSort(ll *a, int left, int right) {
ll res = 0;
if (left + 1 < right) {
int mid = (left + right) / 2;
res = mergeSort(a, left, mid);
res += mergeSort(a, mid, right);
res += merge(a, left, mid, right);
}
return res;
}
int partition(pair<int, char> *a, int p, int r) {
pair<int, char> x = a[r];
int i = p - 1;
for (size_t j = p; j < r; j++) {
if (a[j].first <= x.first) {
i++;
swap(a[i], a[j]);
}
}
swap(a[i + 1], a[r]);
return i + 1;
}
void quick(pair<int, char> *a, int p, int r) {
if (p < r) {
int q = partition(a, p, r);
quick(a, p, q - 1);
quick(a, q + 1, r);
}
}
ll n;
int ci = 0;
ll P[1000010];
struct Node {
int key;
int priority;
Node *parent, *left, *right;
Node(int key, int priority);
Node() {}
};
Node NIL;
Node::Node(int key, int priority) : key(key), priority(priority) {
left = &NIL;
right = &NIL;
}
Node *root = new Node();
void cenrec(Node *k) {
if (k->key == NIL.key)
return;
cenrec(k->left);
cout << " " << k->key;
cenrec(k->right);
}
void fastrec(Node *k) {
if (k->key == NIL.key)
return;
cout << " " << k->key;
fastrec(k->left);
fastrec(k->right);
}
void insert(Node *v) {
Node *y = &NIL;
Node *x = root;
while (x->key != NIL.key) {
y = x;
if (v->key < x->key) {
x = x->left;
} else {
x = x->right;
}
}
v->parent = y;
if (y->key == NIL.key) {
root = v;
} else if (v->key < y->key) {
y->left = v;
} else {
y->right = v;
}
}
Node *find(Node *k, ll v) {
if (k->key == NIL.key)
return &NIL;
if (k->key == v)
return k;
if (v < k->key)
return find(k->left, v);
return find(k->right, v);
}
void delp12(Node *x) {
if (x->key == NIL.key)
return;
Node *l = x->left;
Node *r = x->right;
Node *pr = x->parent;
if (l->key == NIL.key && r->key == NIL.key) {
if (pr->left == x) {
pr->left = &NIL;
} else
pr->right = &NIL;
} else if (l->key != NIL.key) {
if (pr->left == x) {
pr->left = l;
} else
pr->right = l;
l->parent = pr;
} else if (r->key != NIL.key) {
if (pr->left == x) {
pr->left = r;
} else
pr->right = r;
r->parent = pr;
}
}
Node *get_next(Node *k) {
if (k->key == NIL.key)
return &NIL;
Node *res = get_next(k->left);
if (res->key != NIL.key)
return res;
return k;
}
void del(Node *x) {
if (x->key == NIL.key)
return;
Node *l = x->left;
Node *r = x->right;
Node *pr = x->parent;
if (l->key != NIL.key && r->key != NIL.key) {
Node *nex = get_next(r);
x->key = nex->key;
delp12(nex);
} else {
delp12(x);
}
}
Node *rightRotate(Node *t) {
Node *s = t->left;
t->left = s->right;
s->right = t;
return s;
}
Node *leftRotate(Node *t) {
Node *s = t->right;
t->right = s->left;
s->left = t;
return s;
}
Node *_insert(Node *t, int key, int priority) {
if (t->key == NIL.key) {
return new Node(key, priority);
}
if (key == t->key) {
return t;
}
if (key < t->key) {
t->left = _insert(t->left, key, priority);
if (t->priority < t->left->priority) {
t = rightRotate(t);
}
} else {
t->right = _insert(t->right, key, priority);
if (t->priority < t->right->priority) {
t = leftRotate(t);
}
}
return t;
}
Node *delete1(Node *t, int key);
Node *_delete(Node *t, int key) {
if (t->left->key == NIL.key && t->right->key == NIL.key) {
return &NIL;
} else if (t->left->key == NIL.key) {
t = leftRotate(t);
} else if (t->right->key == NIL.key) {
t = rightRotate(t);
} else {
if (t->left->priority > t->right->priority) {
t = rightRotate(t);
} else
t = leftRotate(t);
}
return delete1(t, key);
}
Node *delete1(Node *t, int key) {
if (t->key == NIL.key) {
return &NIL;
}
if (key < t->key) {
t->left = delete1(t->left, key);
} else if (key > t->key) {
t->right = delete1(t->right, key);
} else
return _delete(t, key);
return t;
}
int H;
int left(int i) { return i * 2 + 1; }
int right(int i) { return i * 2 + 2; }
struct edge {
int from, to;
ll val;
edge(int from, int to, ll val) : from(from), to(to), val(val) {}
};
ll k;
int _rank[1010];
int temp[1010];
bool compare_sa(int i, int j) {
if (_rank[i] != _rank[j])
return _rank[i] < _rank[j];
else {
int ri = i + k <= n ? _rank[i + k] : -1;
int rj = j + k <= n ? _rank[j + k] : -1;
return ri < rj;
}
}
void construct_sa(string S, int *sa) {
n = S.length();
for (size_t i = 0; i <= n; i++) {
sa[i] = i;
_rank[i] = i < n ? S[i] : -1;
}
for (k = 1; k <= n; k *= 2) {
sort(sa, sa + n + 1, compare_sa);
// saはソート後の接尾辞の並びになっている、rankは元の位置のindexを保持したまま、更新されている。
// ピンとこなかった部分
temp[sa[0]] = 0;
for (size_t i = 1; i <= n; i++) {
temp[sa[i]] = temp[sa[i - 1]] + (compare_sa(sa[i - 1], sa[i]) ? 1 : 0);
}
for (size_t i = 0; i <= n; i++) {
_rank[i] = temp[i];
}
}
}
bool contain(string S, int *sa, string T) {
int a = 0, b = S.length();
// sa は 接尾辞が辞書順に並んでいる、入っているのはその位置のインデックス
while (b - a > 1) {
int c = (a + b) / 2;
if (S.compare(sa[c], T.length(), T) < 0)
a = c;
else
b = c;
}
return S.compare(sa[b], T.length(), T) == 0;
}
#define bit(x, v) ((ll)x << v)
class BIT {
static const int MAX_N = 500010;
public:
BIT() { memset(bit, 0, sizeof(bit)); }
ll bit[MAX_N + 1], n;
ll sum(int i) {
ll s = 0;
while (i > 0) {
s += bit[i];
i -= i & -i;
}
return s;
}
void add(int i, int x) {
while (i <= n) {
bit[i] += x;
i += i & -i;
}
}
};
struct UnionFind {
vector<int> A;
UnionFind(int n) : A(n, -1) {}
int find(int x) {
if (A[x] < 0)
return x;
return A[x] = find(A[x]);
}
void unite(int x, int y) {
x = find(x), y = find(y);
if (x == y)
return;
if (A[x] > A[y])
swap(x, y);
A[x] += A[y];
A[y] = x;
}
int ngroups() {
int ans = 0;
for (auto a : A)
if (a < 0)
ans++;
return ans;
}
};
void yes() {
cout << "Yes\n";
exit(0);
}
void no() {
cout << "No\n";
exit(0);
}
vector<ll> getp(ll n) {
vector<ll> res;
ll a = 2;
if (n % 2 == 0) {
res.push_back(2);
while (n % 2 == 0)
n /= 2;
}
for (ll i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
res.push_back(i);
while (n % i == 0)
n /= i;
}
}
if (n != 1)
res.push_back(n);
return res;
}
vector<ll> getp2(ll n) {
vector<ll> res;
ll a = 2;
if (n % 2 == 0) {
while (n % 2 == 0) {
n /= 2;
res.push_back(2);
}
}
for (ll i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
while (n % i == 0) {
n /= i;
res.push_back(i);
}
}
}
if (n != 1)
res.push_back(n);
return res;
}
vector<pll> getp3(ll n) {
vector<pll> res;
ll a = 2;
int si = 0;
if (n % 2 == 0) {
res.push_back(make_pair(2, 0));
while (n % 2 == 0) {
n /= 2;
res[si].second++;
}
si++;
}
for (ll i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
res.push_back(make_pair(i, 0));
while (n % i == 0) {
n /= i;
res[si].second++;
}
si++;
}
}
if (n != 1) {
res.push_back(make_pair(n, 1));
}
return res;
}
vector<ll> getDivisors(ll n) {
vector<ll> res;
ll a = 2;
res.push_back(1);
for (ll i = 2; i * i <= n; i++) {
if (n % i == 0) {
res.push_back(i);
if (n / i != i)
res.push_back(n / i);
}
}
return res;
}
struct ve {
public:
vector<ve> child;
int _t = INF;
ve(int t) : _t(t) {}
ve(ve _left, ve _right) {
_t = _left._t + _right._t;
child.push_back(_left);
child.push_back(_right);
}
bool operator<(const ve &t) const { return _t > t._t; }
};
vector<bool> elas(ll n) {
vector<bool> r(n);
fill(r.begin(), r.end(), 1);
r[0] = 0;
r[1] = 0;
for (ll i = 2; i * i < n; i++) {
if (!r[i])
continue;
ll ti = i * 2;
while (ti < n) {
r[ti] = false;
ti += i;
}
}
return r;
}
bool isPrime(ll v) {
for (ll i = 2; i * i <= v; i++) {
if (v % i == 0)
return false;
}
return true;
}
class SegTree {
public:
const static int MAX_N = 100010;
const static int DAT_SIZE = (1 << 18) - 1;
int N, Q;
int A[MAX_N];
ll data[DAT_SIZE], datb[DAT_SIZE];
void init(int _n) {
N = 1;
while (N < _n)
N <<= 1;
memset(data, 0, sizeof(data));
memset(datb, 0, sizeof(datb));
}
void init(int _n, ll iv) {
N = 1;
while (N < _n)
N <<= 1;
rep(i, DAT_SIZE) {
data[i] = iv;
datb[i] = iv;
}
}
void add(int a, int b, int x) { add(a, b + 1, x, 0, 0, N); }
void add(int a, int b, int x, int k, int l, int r) {
if (a <= l && r <= b) {
data[k] += x;
} else if (l < b && a < r) {
datb[k] += (min(b, r) - max(a, l)) * x;
add(a, b, x, k * 2 + 1, l, (l + r) / 2);
add(a, b, x, k * 2 + 2, (l + r) / 2, r);
}
}
void change(int a, int b, int x) { change(a, b + 1, x, 0, 0, N); }
void change(int a, int b, int x, int k, int l, int r) {
if (a <= l && r <= b) {
data[k] = x;
} else if (l < b && a < r) {
datb[k] = x;
change(a, b, x, k * 2 + 1, l, (l + r) / 2);
change(a, b, x, k * 2 + 2, (l + r) / 2, r);
}
}
ll sum(int a, int b) { return sum(a, b + 1, 0, 0, N); }
ll sum(int a, int b, int k, int l, int r) {
if (b <= l || r <= a) {
return 0;
}
if (a <= l && r <= b) {
return data[k] * (r - l) + datb[k];
}
ll res = (min(b, r) - max(a, l)) * data[k];
res += sum(a, b, k * 2 + 1, l, (l + r) / 2);
res += sum(a, b, k * 2 + 2, (l + r) / 2, r);
return res;
}
};
class Segment;
class Circle;
class Point {
public:
double x, y;
Point(double x = 0, double y = 0) : x(x), y(y) {}
Point operator+(Point p) { return Point(x + p.x, y + p.y); }
Point operator-(Point p) { return Point(x - p.x, y - p.y); }
Point operator*(double a) { return Point(a * x, a * y); }
Point operator/(double a) { return Point(x / a, y / a); }
double abs() { return sqrt(norm()); }
double norm() { return x * x + y * y; }
bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; }
bool operator==(const Point &p) const {
return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
}
static double dot(Point a, Point b) { return a.x * b.x + a.y * b.y; }
static double cross(Point a, Point b) { return a.x * b.y - a.y * b.x; }
static bool isOrthogonal(Point a, Point b) { return EQ(dot(a, b), 0.0); }
static bool isOrthogonal(Point a1, Point a2, Point b1, Point b2) {
return isOrthogonal(a1 - a2, b1 - b2);
}
static bool isOrthogonal(Segment s1, Segment s2);
static bool isPalallel(Point a, Point b) { return EQ(cross(a, b), 0.0); }
static bool isPalallel(Point a1, Point a2, Point b1, Point b2) {
return isPalallel(a1 - a2, b1 - b2);
}
static bool isPalallel(Segment s1, Segment s2);
static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;
static int ccw(Point p0, Point p1, Point p2) {
Point a = p1 - p0;
Point b = p2 - p0;
if (cross(a, b) > EPS)
return COUNTER_CLOCKWISE;
if (cross(a, b) < -EPS)
return CLOCKWISE;
if (dot(a, b) < -EPS)
return ONLINE_BACK;
if (a.norm() < b.norm())
return ONLINE_FRONT;
return ON_SEGMENT;
}
static bool intersect(Point p1, Point p2, Point p3, Point p4) {
return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 &&
ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0);
}
static bool intersect(Segment s1, Segment s2);
static Point project(Segment s, Point p);
static Point reflect(Segment s, Point p);
static Point getDistance(Point a, Point b) { return (a - b).abs(); }
static double getDistanceLP(Segment s, Point p);
static double getDistanceSP(Segment s, Point p);
static double getDistance(Segment s1, Segment s2);
static Point getIntersection(Segment s1, Segment s2);
static pair<Point, Point> crossPoints(Circle c, Segment s);
static int contains(vector<Point> g, Point p) {
int n = g.size();
bool x = false;
rep(i, n) {
Point a = g[i] - p, b = g[(i + 1) % n] - p;
// 線の上に載っているか
if (std::abs(cross(a, b)) < EPS && dot(a, b) < EPS)
return 1;
// pを基準として上下にあるか
// または外積が正か?(→にあるか)
if (a.y > b.y)
swap(a, b);
if (a.y < EPS && EPS < b.y && cross(a, b) > EPS)
x = !x;
}
return x ? 2 : 0;
}
static vector<Point> andrewScan(vector<Point> s) {
vector<Point> u, l;
if (s.size() < 3)
return s;
sort(all(s));
u.push_back(s[0]);
u.push_back(s[1]);
l.push_back(s[s.size() - 1]);
l.push_back(s[s.size() - 2]);
for (int i = 2; i < s.size(); i++) {
for (int _n = u.size();
_n >= 2 && ccw(u[_n - 2], u[_n - 1], s[i]) > CLOCKWISE; _n--) {
u.pop_back();
}
u.push_back(s[i]);
}
for (int i = s.size() - 3; i >= 0; i--) {
for (int _n = l.size();
_n >= 2 && ccw(l[_n - 2], l[_n - 1], s[i]) > CLOCKWISE; _n--) {
l.pop_back();
}
l.push_back(s[i]);
}
reverse(all(l));
for (int i = u.size() - 2; i >= 1; i--) {
l.push_back(u[i]);
}
return l;
}
void get_cin() { cin >> x >> y; }
};
class Segment {
public:
Point p1, p2;
Segment() {}
Segment(Point p1, Point p2) : p1(p1), p2(p2) {}
void get_cin() { cin >> p1.x >> p1.y >> p2.x >> p2.y; }
Point p1tp2() { return p2 - p1; }
Point p2tp1() { return p1 - p2; }
double abs() { return std::abs(norm()); }
double norm() { return (p2 - p1).norm(); }
};
bool Point::isOrthogonal(Segment s1, Segment s2) {
return EQ(dot(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
bool Point::isPalallel(Segment s1, Segment s2) {
return EQ(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
bool Point::intersect(Segment s1, Segment s2) {
return intersect(s1.p1, s1.p2, s2.p1, s2.p2);
}
Point Point::project(Segment s, Point p) {
Point base = s.p2 - s.p1;
double r = Point::dot(p - s.p1, base) / base.norm();
return s.p1 + base * r;
}
Point Point::reflect(Segment s, Point p) { return (project(s, p) * 2) - p; }
double Point::getDistanceLP(Segment s, Point p) {
return std::abs(cross(s.p2 - s.p1, p - s.p1) / (s.p2 - s.p1).abs());
}
double Point::getDistanceSP(Segment s, Point p) {
if (dot(s.p2 - s.p1, p - s.p1) < 0.0)
return (p - s.p1).abs();
if (dot(s.p1 - s.p2, p - s.p2) < 0.0)
return (p - s.p2).abs();
return getDistanceLP(s, p);
}
double Point::getDistance(Segment s1, Segment s2) {
if (intersect(s1, s2))
return 0.0;
return min({getDistanceSP(s1, s2.p1), getDistanceSP(s1, s2.p2),
getDistanceSP(s2, s1.p1), getDistanceSP(s2, s1.p2)});
}
Point Point::getIntersection(Segment s1, Segment s2) {
// (s1.p1 - s2.p1).norm()
auto bs = s1.p2 - s1.p1;
auto n1 = s2.p1 - s1.p1;
auto n2 = s2.p2 - s1.p1;
auto c1 = std::abs(cross(n1, bs)) / bs.norm();
auto c2 = std::abs(cross(n2, bs)) / bs.norm();
return s2.p1 + (s2.p2 - s2.p1) * (c1 / (c1 + c2));
// c1:c2=t:1-t
// c2t=(1-t)c1
// t/(1-t)=c1/(c1+c2)
//
}
double arg(Point p) { return atan2(p.y, p.x); }
Point polar(double a, double r) { return Point(cos(r) * a, sin(r) * a); }
class Circle {
public:
Point c;
double r;
Circle(Point c = Point(), double r = 0.0) : c(c), r(r) {}
void get_cin() { cin >> c.x >> c.y >> r; }
static pair<Point, Point> getCrossPoints(Circle c1, Circle c2) {
double d = (c1.c - c2.c).abs(); // 中心点どうしの距離
double a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d));
double t = arg(c2.c - c1.c);
return make_pair(c1.c + polar(c1.r, t + a), c1.c + polar(c1.r, t - a));
}
};
pair<Point, Point> Point::crossPoints(Circle c, Segment s) {
auto pp = project(s, c.c);
auto f = (pp - c.c).norm();
auto mu = sqrt(c.r * c.r - f);
auto e = s.p1tp2() / s.p1tp2().abs();
return make_pair(pp + e * mu, pp - e * mu);
}
ll divRm(string s, ll x) {
ll r = 0;
for (ll i = 0; i < s.size(); i++) {
r *= 10;
r += s[i] - '0';
r %= x;
}
return r;
}
ll cmbi(ll x, ll b) {
ll res = 1;
for (size_t i = 0; i < b; i++) {
res *= x - i;
res %= INF;
res *= inv[b - i];
res %= INF;
}
return res;
}
double digsum(ll x) {
ll res = 0;
while (x > 0) {
res += x % 10;
x /= 10;
}
return res;
}
bool check_parindrome(string s) {
int n = s.size();
rep(i, n / 2) {
if (s[i] != s[n - i - 1]) {
return false;
}
}
return true;
}
ll memo[65][2];
ll a[100010];
ll rec(ll x, bool tite) {
if (x < 0)
return 0;
if (~memo[x][tite])
return memo[x][tite];
ll v = 1LL << x;
ll cnt = 0;
rep(i, n) {
if (a[i] & v) {
cnt++;
}
}
ll res = 0;
if (tite) {
if ((k & v) == 0) {
res = rec(x - 1, tite) + cnt * v;
} else {
res = rec(x - 1, tite) + (n - cnt) * v;
res = max(res, rec(x - 1, false) + cnt * v);
}
} else {
res = rec(x - 1, tite) + v * max(cnt, n - cnt);
}
return memo[x][tite] = res;
}
void solv() {
cin >> n >> k;
rep(i, n) cin >> a[i];
allm1(memo);
cout << rec(62, true) << endl;
}
int main() {
COMinit();
solv();
return 0;
} | [
"assignment.value.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 938,817 | 938,818 | u224756887 | cpp |
p03138 | #include <algorithm>
#include <array>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctype.h>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <unordered_map>
#include <utility>
#include <vector>
#define _USE_MATH_DEFINES
#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, double> pld;
typedef pair<double, double> pdd;
typedef pair<double, ll> pdl;
typedef pair<int, char> pic;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef priority_queue<ll, vector<ll>, greater<ll>> llgreaterq;
typedef priority_queue<pll, vector<pll>, greater<pll>> pllgreaterq;
typedef priority_queue<pair<ll, pll>, vector<pair<ll, pll>>,
greater<pair<ll, pll>>>
plpllgreaterq;
typedef priority_queue<vi, vector<vi>, greater<vi>> vigreaterq;
typedef priority_queue<vl, vector<vl>, greater<vl>> vlgreaterq;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
#define bit(x, v) ((ll)x << v)
#define rep(x, n) for (int x = 0; x < n; x++)
#define rep2(x, f, v) for (int x = f; x < v; x++)
// 許容する誤差ε
#define EPS (1e-10)
// 2つのスカラーが等しいかどうか
#define EQ(a, b) (std::abs(a - b) < EPS)
// 2つのベクトルが等しいかどうか
#define EQV(a, b) (EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()))
#define all(a) a.begin(), a.end()
#define all0(a) memset(a, 0, sizeof(a))
#define alm1(a) memset(a, -1, sizeof(a))
const ll INF = 1000000007;
const int MAX = 2000010;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
int pr[100010];
int lank[100010];
void uini(int n) {
for (size_t i = 0; i <= n; i++) {
pr[i] = i;
lank[i] = 1;
}
}
int parent(int x) {
if (x == pr[x])
return x;
return pr[x] = parent(pr[x]);
}
int same(int x, int y) { return parent(x) == parent(y); }
bool unit(int x, int y) {
int px = parent(x);
int py = parent(y);
if (px == py)
return false;
if (lank[py] < lank[px]) {
pr[py] = px;
lank[px] += lank[py];
} else {
pr[px] = py;
lank[py] += lank[px];
}
return true;
}
ll bit[200010];
int max_n = 200000;
int pm = 0;
void add(int x) {
while (max_n >= x) {
bit[x]++;
x += x & -x;
}
}
void sub(int x) {
while (max_n >= x) {
bit[x]--;
x += x & -x;
}
}
ll merge(ll *a, int left, int mid, int right) {
ll n1 = mid - left;
ll n2 = right - mid;
vector<int> L(n1 + 1);
vector<int> R(n2 + 1);
for (size_t i = 0; i < n1; i++) {
L[i] = a[left + i];
}
for (size_t i = 0; i < n2; i++) {
R[i] = a[mid + i];
}
L[n1] = INF;
R[n2] = INF;
ll i = 0;
ll j = 0;
ll r = 0;
for (size_t k = left; k < right; k++) {
if (L[i] <= R[j]) {
a[k] = L[i];
i++;
} else {
a[k] = R[j];
r += n1 - i;
j++;
}
}
return r;
}
ll merge2(pair<int, char> *a, int left, int mid, int right) {
ll n1 = mid - left;
ll n2 = right - mid;
vector<pair<int, char>> L(n1 + 1);
vector<pair<int, char>> R(n2 + 1);
for (size_t i = 0; i < n1; i++) {
L[i] = a[left + i];
}
for (size_t i = 0; i < n2; i++) {
R[i] = a[mid + i];
}
L[n1] = make_pair(INF, ' ');
R[n2] = make_pair(INF, ' ');
ll i = 0;
ll j = 0;
ll r = 0;
for (size_t k = left; k < right; k++) {
if (L[i].first <= R[j].first) {
a[k] = L[i];
i++;
} else {
a[k] = R[j];
r += n1 - i;
j++;
}
}
return r;
}
ll mergeSort2(pair<int, char> *a, int left, int right) {
ll res = 0;
if (left + 1 < right) {
int mid = (left + right) / 2;
res = mergeSort2(a, left, mid);
res += mergeSort2(a, mid, right);
res += merge2(a, left, mid, right);
}
return res;
}
ll mergeSort(ll *a, int left, int right) {
ll res = 0;
if (left + 1 < right) {
int mid = (left + right) / 2;
res = mergeSort(a, left, mid);
res += mergeSort(a, mid, right);
res += merge(a, left, mid, right);
}
return res;
}
int partition(pair<int, char> *a, int p, int r) {
pair<int, char> x = a[r];
int i = p - 1;
for (size_t j = p; j < r; j++) {
if (a[j].first <= x.first) {
i++;
swap(a[i], a[j]);
}
}
swap(a[i + 1], a[r]);
return i + 1;
}
void quick(pair<int, char> *a, int p, int r) {
if (p < r) {
int q = partition(a, p, r);
quick(a, p, q - 1);
quick(a, q + 1, r);
}
}
ll n;
int ci = 0;
ll P[1000010];
struct Node {
int key;
int priority;
Node *parent, *left, *right;
Node(int key, int priority);
Node() {}
};
Node NIL;
Node::Node(int key, int priority) : key(key), priority(priority) {
left = &NIL;
right = &NIL;
}
Node *root = new Node();
void cenrec(Node *k) {
if (k->key == NIL.key)
return;
cenrec(k->left);
cout << " " << k->key;
cenrec(k->right);
}
void fastrec(Node *k) {
if (k->key == NIL.key)
return;
cout << " " << k->key;
fastrec(k->left);
fastrec(k->right);
}
void insert(Node *v) {
Node *y = &NIL;
Node *x = root;
while (x->key != NIL.key) {
y = x;
if (v->key < x->key) {
x = x->left;
} else {
x = x->right;
}
}
v->parent = y;
if (y->key == NIL.key) {
root = v;
} else if (v->key < y->key) {
y->left = v;
} else {
y->right = v;
}
}
Node *find(Node *k, ll v) {
if (k->key == NIL.key)
return &NIL;
if (k->key == v)
return k;
if (v < k->key)
return find(k->left, v);
return find(k->right, v);
}
void delp12(Node *x) {
if (x->key == NIL.key)
return;
Node *l = x->left;
Node *r = x->right;
Node *pr = x->parent;
if (l->key == NIL.key && r->key == NIL.key) {
if (pr->left == x) {
pr->left = &NIL;
} else
pr->right = &NIL;
} else if (l->key != NIL.key) {
if (pr->left == x) {
pr->left = l;
} else
pr->right = l;
l->parent = pr;
} else if (r->key != NIL.key) {
if (pr->left == x) {
pr->left = r;
} else
pr->right = r;
r->parent = pr;
}
}
Node *get_next(Node *k) {
if (k->key == NIL.key)
return &NIL;
Node *res = get_next(k->left);
if (res->key != NIL.key)
return res;
return k;
}
void del(Node *x) {
if (x->key == NIL.key)
return;
Node *l = x->left;
Node *r = x->right;
Node *pr = x->parent;
if (l->key != NIL.key && r->key != NIL.key) {
Node *nex = get_next(r);
x->key = nex->key;
delp12(nex);
} else {
delp12(x);
}
}
Node *rightRotate(Node *t) {
Node *s = t->left;
t->left = s->right;
s->right = t;
return s;
}
Node *leftRotate(Node *t) {
Node *s = t->right;
t->right = s->left;
s->left = t;
return s;
}
Node *_insert(Node *t, int key, int priority) {
if (t->key == NIL.key) {
return new Node(key, priority);
}
if (key == t->key) {
return t;
}
if (key < t->key) {
t->left = _insert(t->left, key, priority);
if (t->priority < t->left->priority) {
t = rightRotate(t);
}
} else {
t->right = _insert(t->right, key, priority);
if (t->priority < t->right->priority) {
t = leftRotate(t);
}
}
return t;
}
Node *delete1(Node *t, int key);
Node *_delete(Node *t, int key) {
if (t->left->key == NIL.key && t->right->key == NIL.key) {
return &NIL;
} else if (t->left->key == NIL.key) {
t = leftRotate(t);
} else if (t->right->key == NIL.key) {
t = rightRotate(t);
} else {
if (t->left->priority > t->right->priority) {
t = rightRotate(t);
} else
t = leftRotate(t);
}
return delete1(t, key);
}
Node *delete1(Node *t, int key) {
if (t->key == NIL.key) {
return &NIL;
}
if (key < t->key) {
t->left = delete1(t->left, key);
} else if (key > t->key) {
t->right = delete1(t->right, key);
} else
return _delete(t, key);
return t;
}
int H;
int left(int i) { return i * 2 + 1; }
int right(int i) { return i * 2 + 2; }
struct edge {
int from, to;
ll val;
edge(int from, int to, ll val) : from(from), to(to), val(val) {}
};
int k;
int _rank[1010];
int temp[1010];
bool compare_sa(int i, int j) {
if (_rank[i] != _rank[j])
return _rank[i] < _rank[j];
else {
int ri = i + k <= n ? _rank[i + k] : -1;
int rj = j + k <= n ? _rank[j + k] : -1;
return ri < rj;
}
}
void construct_sa(string S, int *sa) {
n = S.length();
for (size_t i = 0; i <= n; i++) {
sa[i] = i;
_rank[i] = i < n ? S[i] : -1;
}
for (k = 1; k <= n; k *= 2) {
sort(sa, sa + n + 1, compare_sa);
// saはソート後の接尾辞の並びになっている、rankは元の位置のindexを保持したまま、更新されている。
// ピンとこなかった部分
temp[sa[0]] = 0;
for (size_t i = 1; i <= n; i++) {
temp[sa[i]] = temp[sa[i - 1]] + (compare_sa(sa[i - 1], sa[i]) ? 1 : 0);
}
for (size_t i = 0; i <= n; i++) {
_rank[i] = temp[i];
}
}
}
bool contain(string S, int *sa, string T) {
int a = 0, b = S.length();
// sa は 接尾辞が辞書順に並んでいる、入っているのはその位置のインデックス
while (b - a > 1) {
int c = (a + b) / 2;
if (S.compare(sa[c], T.length(), T) < 0)
a = c;
else
b = c;
}
return S.compare(sa[b], T.length(), T) == 0;
}
#define bit(x, v) ((ll)x << v)
class BIT {
static const int MAX_N = 500010;
public:
BIT() { memset(bit, 0, sizeof(bit)); }
ll bit[MAX_N + 1], n;
ll sum(int i) {
ll s = 0;
while (i > 0) {
s += bit[i];
i -= i & -i;
}
return s;
}
void add(int i, int x) {
while (i <= n) {
bit[i] += x;
i += i & -i;
}
}
};
struct UnionFind {
vector<int> A;
UnionFind(int n) : A(n, -1) {}
int find(int x) {
if (A[x] < 0)
return x;
return A[x] = find(A[x]);
}
void unite(int x, int y) {
x = find(x), y = find(y);
if (x == y)
return;
if (A[x] > A[y])
swap(x, y);
A[x] += A[y];
A[y] = x;
}
int ngroups() {
int ans = 0;
for (auto a : A)
if (a < 0)
ans++;
return ans;
}
};
void yes() {
cout << "Yes\n";
exit(0);
}
void no() {
cout << "No\n";
exit(0);
}
vector<ll> getp(ll n) {
vector<ll> res;
ll a = 2;
if (n % 2 == 0) {
res.push_back(2);
while (n % 2 == 0)
n /= 2;
}
for (ll i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
res.push_back(i);
while (n % i == 0)
n /= i;
}
}
if (n != 1)
res.push_back(n);
return res;
}
vector<ll> getp2(ll n) {
vector<ll> res;
ll a = 2;
if (n % 2 == 0) {
while (n % 2 == 0) {
n /= 2;
res.push_back(2);
}
}
for (ll i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
while (n % i == 0) {
n /= i;
res.push_back(i);
}
}
}
if (n != 1)
res.push_back(n);
return res;
}
vector<pll> getp3(ll n) {
vector<pll> res;
ll a = 2;
int si = 0;
if (n % 2 == 0) {
res.push_back(make_pair(2, 0));
while (n % 2 == 0) {
n /= 2;
res[si].second++;
}
si++;
}
for (ll i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
res.push_back(make_pair(i, 0));
while (n % i == 0) {
n /= i;
res[si].second++;
}
si++;
}
}
if (n != 1) {
res.push_back(make_pair(n, 1));
}
return res;
}
vector<ll> getDivisors(ll n) {
vector<ll> res;
ll a = 2;
res.push_back(1);
for (ll i = 2; i * i <= n; i++) {
if (n % i == 0) {
res.push_back(i);
if (n / i != i)
res.push_back(n / i);
}
}
return res;
}
struct ve {
public:
vector<ve> child;
int _t = INF;
ve(int t) : _t(t) {}
ve(ve _left, ve _right) {
_t = _left._t + _right._t;
child.push_back(_left);
child.push_back(_right);
}
bool operator<(const ve &t) const { return _t > t._t; }
};
vector<bool> elas(ll n) {
vector<bool> r(n);
fill(r.begin(), r.end(), 1);
r[0] = 0;
r[1] = 0;
for (ll i = 2; i * i < n; i++) {
if (!r[i])
continue;
ll ti = i * 2;
while (ti < n) {
r[ti] = false;
ti += i;
}
}
return r;
}
bool isPrime(ll v) {
for (ll i = 2; i * i <= v; i++) {
if (v % i == 0)
return false;
}
return true;
}
ll getpow(ll b, ll x, ll md) {
ll t = b;
ll res = 1;
while (x > 0) {
if (x & 1) {
res *= t;
res %= md;
}
x >>= 1;
t *= t;
t %= md;
}
return res;
}
ll getpow(ll b, ll x) { return getpow(b, x, INF); }
class SegTree {
public:
const static int MAX_N = 100010;
const static int DAT_SIZE = (1 << 18) - 1;
int N, Q;
int A[MAX_N];
ll data[DAT_SIZE], datb[DAT_SIZE];
void init(int _n) {
N = 1;
while (N < _n)
N <<= 1;
memset(data, 0, sizeof(data));
memset(datb, 0, sizeof(datb));
}
void init(int _n, ll iv) {
N = 1;
while (N < _n)
N <<= 1;
rep(i, DAT_SIZE) {
data[i] = iv;
datb[i] = iv;
}
}
void add(int a, int b, int x) { add(a, b + 1, x, 0, 0, N); }
void add(int a, int b, int x, int k, int l, int r) {
if (a <= l && r <= b) {
data[k] += x;
} else if (l < b && a < r) {
datb[k] += (min(b, r) - max(a, l)) * x;
add(a, b, x, k * 2 + 1, l, (l + r) / 2);
add(a, b, x, k * 2 + 2, (l + r) / 2, r);
}
}
void change(int a, int b, int x) { change(a, b + 1, x, 0, 0, N); }
void change(int a, int b, int x, int k, int l, int r) {
if (a <= l && r <= b) {
data[k] = x;
} else if (l < b && a < r) {
datb[k] = x;
change(a, b, x, k * 2 + 1, l, (l + r) / 2);
change(a, b, x, k * 2 + 2, (l + r) / 2, r);
}
}
ll sum(int a, int b) { return sum(a, b + 1, 0, 0, N); }
ll sum(int a, int b, int k, int l, int r) {
if (b <= l || r <= a) {
return 0;
}
if (a <= l && r <= b) {
return data[k] * (r - l) + datb[k];
}
ll res = (min(b, r) - max(a, l)) * data[k];
res += sum(a, b, k * 2 + 1, l, (l + r) / 2);
res += sum(a, b, k * 2 + 2, (l + r) / 2, r);
return res;
}
};
class Segment;
class Circle;
class Point {
public:
double x, y;
Point(double x = 0, double y = 0) : x(x), y(y) {}
Point operator+(Point p) { return Point(x + p.x, y + p.y); }
Point operator-(Point p) { return Point(x - p.x, y - p.y); }
Point operator*(double a) { return Point(a * x, a * y); }
Point operator/(double a) { return Point(x / a, y / a); }
double abs() { return sqrt(norm()); }
double norm() { return x * x + y * y; }
bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; }
bool operator==(const Point &p) const {
return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
}
static double dot(Point a, Point b) { return a.x * b.x + a.y * b.y; }
static double cross(Point a, Point b) { return a.x * b.y - a.y * b.x; }
static bool isOrthogonal(Point a, Point b) { return EQ(dot(a, b), 0.0); }
static bool isOrthogonal(Point a1, Point a2, Point b1, Point b2) {
return isOrthogonal(a1 - a2, b1 - b2);
}
static bool isOrthogonal(Segment s1, Segment s2);
static bool isPalallel(Point a, Point b) { return EQ(cross(a, b), 0.0); }
static bool isPalallel(Point a1, Point a2, Point b1, Point b2) {
return isPalallel(a1 - a2, b1 - b2);
}
static bool isPalallel(Segment s1, Segment s2);
static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;
static int ccw(Point p0, Point p1, Point p2) {
Point a = p1 - p0;
Point b = p2 - p0;
if (cross(a, b) > EPS)
return COUNTER_CLOCKWISE;
if (cross(a, b) < -EPS)
return CLOCKWISE;
if (dot(a, b) < -EPS)
return ONLINE_BACK;
if (a.norm() < b.norm())
return ONLINE_FRONT;
return ON_SEGMENT;
}
static bool intersect(Point p1, Point p2, Point p3, Point p4) {
return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 &&
ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0);
}
static bool intersect(Segment s1, Segment s2);
static Point project(Segment s, Point p);
static Point reflect(Segment s, Point p);
static Point getDistance(Point a, Point b) { return (a - b).abs(); }
static double getDistanceLP(Segment s, Point p);
static double getDistanceSP(Segment s, Point p);
static double getDistance(Segment s1, Segment s2);
static Point getIntersection(Segment s1, Segment s2);
static pair<Point, Point> crossPoints(Circle c, Segment s);
};
class Segment {
public:
Point p1, p2;
Segment() {}
Segment(Point p1, Point p2) : p1(p1), p2(p2) {}
Point p1tp2() { return p2 - p1; }
Point p2tp1() { return p1 - p2; }
double abs() { return std::abs(norm()); }
double norm() { return (p2 - p1).norm(); }
};
bool Point::isOrthogonal(Segment s1, Segment s2) {
return EQ(dot(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
bool Point::isPalallel(Segment s1, Segment s2) {
return EQ(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
bool Point::intersect(Segment s1, Segment s2) {
return intersect(s1.p1, s1.p2, s2.p1, s2.p2);
}
Point Point::project(Segment s, Point p) {
Point base = s.p2 - s.p1;
double r = Point::dot(p - s.p1, base) / base.norm();
return s.p1 + base * r;
}
Point Point::reflect(Segment s, Point p) { return (project(s, p) * 2) - p; }
double Point::getDistanceLP(Segment s, Point p) {
return std::abs(cross(s.p2 - s.p1, p - s.p1) / (s.p2 - s.p1).abs());
}
double Point::getDistanceSP(Segment s, Point p) {
if (dot(s.p2 - s.p1, p - s.p1) < 0.0)
return (p - s.p1).abs();
if (dot(s.p1 - s.p2, p - s.p2) < 0.0)
return (p - s.p2).abs();
return getDistanceLP(s, p);
}
double Point::getDistance(Segment s1, Segment s2) {
if (intersect(s1, s2))
return 0.0;
return min({getDistanceSP(s1, s2.p1), getDistanceSP(s1, s2.p2),
getDistanceSP(s2, s1.p1), getDistanceSP(s2, s1.p2)});
}
Point Point::getIntersection(Segment s1, Segment s2) {
// (s1.p1 - s2.p1).norm()
auto bs = s1.p2 - s1.p1;
auto n1 = s2.p1 - s1.p1;
auto n2 = s2.p2 - s1.p1;
auto c1 = std::abs(cross(n1, bs)) / bs.norm();
auto c2 = std::abs(cross(n2, bs)) / bs.norm();
return s2.p1 + (s2.p2 - s2.p1) * (c1 / (c1 + c2));
// c1:c2=t:1-t
// c2t=(1-t)c1
// t/(1-t)=c1/(c1+c2)
//
}
double arg(Point p) { return atan2(p.y, p.x); }
Point polar(double a, double r) { return Point(cos(r) * a, sin(r) * a); }
class Circle {
public:
Point c;
double r;
Circle(Point c = Point(), double r = 0.0) : c(c), r(r) {}
static pair<Point, Point> getCrossPoints(Circle c1, Circle c2) {
double d = (c1.c - c2.c).abs(); // 中心点どうしの距離
double a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d));
double t = arg(c2.c - c1.c);
return make_pair(c1.c + polar(c1.r, t + a), c1.c + polar(c1.r, t - a));
}
};
pair<Point, Point> Point::crossPoints(Circle c, Segment s) {
auto pp = project(s, c.c);
auto f = (pp - c.c).norm();
auto mu = sqrt(c.r * c.r - f);
auto e = s.p1tp2() / s.p1tp2().abs();
return make_pair(pp + e * mu, pp - e * mu);
}
ll divRm(string s, ll x) {
ll r = 0;
for (size_t i = 0; i < s.size(); i++) {
r *= 10;
r += s[i] - '0';
r %= x;
}
return r;
}
ll cmbi(ll x, ll b) {
ll res = 1;
for (size_t i = 0; i < b; i++) {
res *= x - i;
res %= INF;
res *= inv[b - i];
res %= INF;
}
return res;
}
void dfs(string s, char a) {
if (s.size() == n) {
cout << s << endl;
return;
}
for (char b = 'a'; b <= a; b++) {
dfs(s + b, (b == a) ? (char)(a + 1) : a);
}
}
string combine(string s, string t) {
string res = s + t;
for (int i = s.size() - 1; i >= 0; i--) {
int p = s.size() - i;
bool ok = true;
for (int j = 0; j < p && ok; j++) {
if (!(s[i + j] == t[j] || s[i + j] == '?' || t[j] == '?')) {
ok = false;
}
}
if (!ok)
continue;
string v = "";
for (int j = 0; j < i; j++) {
v += s[j];
}
for (int j = 0; j < t.size(); j++) {
if (j < p) {
if (s[i + j] == '?' && t[j] != '?') {
v += t[j];
} else if (s[i + j] != '?' && t[j] == '?') {
v += s[i + j];
} else {
v += t[j];
}
} else
v += t[j];
}
res = v;
}
return res;
}
string cmc(string a, string b, string c) {
string a1 = combine(a, b);
return combine(a1, c);
}
bool match(char a, char b) { return a == '?' || b == '?' || a == b; }
bool between(ll x, ll y1, ll y2) {
if (y1 > y2)
swap(y1, y2);
y1++;
y2--;
if (!(y1 <= y2))
return false;
while (x > 0) {
if (x % 3 == 1) {
if (y2 - y1 > 3)
return true;
for (ll y = y1; y <= y2; y++)
if (y % 3 == 1)
return true;
}
x /= 3;
y1 /= 3;
y2 /= 3;
}
return false;
}
ll get_extra(ll x1, ll y1, ll x2, ll y2) {
ll ans = 0;
int i;
ll three = 1;
rep(i, 36) {
if (x1 / three == x2 / three &&
between(x1 / three, y1 / three, y2 / three)) {
ll tmp = min(min(x1 % three, x2 % three) + 1,
three - max(x1 % three, x2 % three));
ans = max(ans, tmp);
}
three *= 3;
}
return ans;
}
ll get_dist(ll x1, ll y1, ll x2, ll y2) {
return abs(x1 - x2) + abs(y1 - y2) +
2 * max(get_extra(x1, y1, x2, y2), get_extra(y1, x1, y2, x2));
}
ll memo[62][2];
ll ar[100010];
ll m = 60;
ll bdp(int i, bool tite) {
if (~memo[i][tite])
return memo[i][tite];
if (i > m)
return 0;
ll res = 0;
ll cn = 0;
ll base = (1LL << (m - i));
rep(j, n) { cn += (ar[j] & base) > 0; }
if (tite) {
ll p = (k & base);
if (p == 0) {
res = bdp(i + 1, tite) + cn * base;
} else {
res = bdp(i + 1, true) + (n - cn) * base;
res = max(res, bdp(i + 1, false) + n * base);
}
} else {
res = bdp(i + 1, false) + max(cn, (n - cn)) * base;
}
return memo[i][tite] = res;
}
void solv() {
cin >> n >> k;
rep(i, n) { cin >> ar[i]; }
memset(memo, -1, sizeof(memo));
cout << bdp(0, true) << endl;
}
int main() {
// COMinit();
solv();
return 0;
} | #include <algorithm>
#include <array>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctype.h>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <unordered_map>
#include <utility>
#include <vector>
#define _USE_MATH_DEFINES
#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, double> pld;
typedef pair<double, double> pdd;
typedef pair<double, ll> pdl;
typedef pair<int, char> pic;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef priority_queue<ll, vector<ll>, greater<ll>> llgreaterq;
typedef priority_queue<pll, vector<pll>, greater<pll>> pllgreaterq;
typedef priority_queue<pair<ll, pll>, vector<pair<ll, pll>>,
greater<pair<ll, pll>>>
plpllgreaterq;
typedef priority_queue<vi, vector<vi>, greater<vi>> vigreaterq;
typedef priority_queue<vl, vector<vl>, greater<vl>> vlgreaterq;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
#define bit(x, v) ((ll)x << v)
#define rep(x, n) for (int x = 0; x < n; x++)
#define rep2(x, f, v) for (int x = f; x < v; x++)
// 許容する誤差ε
#define EPS (1e-10)
// 2つのスカラーが等しいかどうか
#define EQ(a, b) (std::abs(a - b) < EPS)
// 2つのベクトルが等しいかどうか
#define EQV(a, b) (EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()))
#define all(a) a.begin(), a.end()
#define all0(a) memset(a, 0, sizeof(a))
#define alm1(a) memset(a, -1, sizeof(a))
const ll INF = 1000000007;
const int MAX = 2000010;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
int pr[100010];
int lank[100010];
void uini(int n) {
for (size_t i = 0; i <= n; i++) {
pr[i] = i;
lank[i] = 1;
}
}
int parent(int x) {
if (x == pr[x])
return x;
return pr[x] = parent(pr[x]);
}
int same(int x, int y) { return parent(x) == parent(y); }
bool unit(int x, int y) {
int px = parent(x);
int py = parent(y);
if (px == py)
return false;
if (lank[py] < lank[px]) {
pr[py] = px;
lank[px] += lank[py];
} else {
pr[px] = py;
lank[py] += lank[px];
}
return true;
}
ll bit[200010];
int max_n = 200000;
int pm = 0;
void add(int x) {
while (max_n >= x) {
bit[x]++;
x += x & -x;
}
}
void sub(int x) {
while (max_n >= x) {
bit[x]--;
x += x & -x;
}
}
ll merge(ll *a, int left, int mid, int right) {
ll n1 = mid - left;
ll n2 = right - mid;
vector<int> L(n1 + 1);
vector<int> R(n2 + 1);
for (size_t i = 0; i < n1; i++) {
L[i] = a[left + i];
}
for (size_t i = 0; i < n2; i++) {
R[i] = a[mid + i];
}
L[n1] = INF;
R[n2] = INF;
ll i = 0;
ll j = 0;
ll r = 0;
for (size_t k = left; k < right; k++) {
if (L[i] <= R[j]) {
a[k] = L[i];
i++;
} else {
a[k] = R[j];
r += n1 - i;
j++;
}
}
return r;
}
ll merge2(pair<int, char> *a, int left, int mid, int right) {
ll n1 = mid - left;
ll n2 = right - mid;
vector<pair<int, char>> L(n1 + 1);
vector<pair<int, char>> R(n2 + 1);
for (size_t i = 0; i < n1; i++) {
L[i] = a[left + i];
}
for (size_t i = 0; i < n2; i++) {
R[i] = a[mid + i];
}
L[n1] = make_pair(INF, ' ');
R[n2] = make_pair(INF, ' ');
ll i = 0;
ll j = 0;
ll r = 0;
for (size_t k = left; k < right; k++) {
if (L[i].first <= R[j].first) {
a[k] = L[i];
i++;
} else {
a[k] = R[j];
r += n1 - i;
j++;
}
}
return r;
}
ll mergeSort2(pair<int, char> *a, int left, int right) {
ll res = 0;
if (left + 1 < right) {
int mid = (left + right) / 2;
res = mergeSort2(a, left, mid);
res += mergeSort2(a, mid, right);
res += merge2(a, left, mid, right);
}
return res;
}
ll mergeSort(ll *a, int left, int right) {
ll res = 0;
if (left + 1 < right) {
int mid = (left + right) / 2;
res = mergeSort(a, left, mid);
res += mergeSort(a, mid, right);
res += merge(a, left, mid, right);
}
return res;
}
int partition(pair<int, char> *a, int p, int r) {
pair<int, char> x = a[r];
int i = p - 1;
for (size_t j = p; j < r; j++) {
if (a[j].first <= x.first) {
i++;
swap(a[i], a[j]);
}
}
swap(a[i + 1], a[r]);
return i + 1;
}
void quick(pair<int, char> *a, int p, int r) {
if (p < r) {
int q = partition(a, p, r);
quick(a, p, q - 1);
quick(a, q + 1, r);
}
}
ll n;
int ci = 0;
ll P[1000010];
struct Node {
int key;
int priority;
Node *parent, *left, *right;
Node(int key, int priority);
Node() {}
};
Node NIL;
Node::Node(int key, int priority) : key(key), priority(priority) {
left = &NIL;
right = &NIL;
}
Node *root = new Node();
void cenrec(Node *k) {
if (k->key == NIL.key)
return;
cenrec(k->left);
cout << " " << k->key;
cenrec(k->right);
}
void fastrec(Node *k) {
if (k->key == NIL.key)
return;
cout << " " << k->key;
fastrec(k->left);
fastrec(k->right);
}
void insert(Node *v) {
Node *y = &NIL;
Node *x = root;
while (x->key != NIL.key) {
y = x;
if (v->key < x->key) {
x = x->left;
} else {
x = x->right;
}
}
v->parent = y;
if (y->key == NIL.key) {
root = v;
} else if (v->key < y->key) {
y->left = v;
} else {
y->right = v;
}
}
Node *find(Node *k, ll v) {
if (k->key == NIL.key)
return &NIL;
if (k->key == v)
return k;
if (v < k->key)
return find(k->left, v);
return find(k->right, v);
}
void delp12(Node *x) {
if (x->key == NIL.key)
return;
Node *l = x->left;
Node *r = x->right;
Node *pr = x->parent;
if (l->key == NIL.key && r->key == NIL.key) {
if (pr->left == x) {
pr->left = &NIL;
} else
pr->right = &NIL;
} else if (l->key != NIL.key) {
if (pr->left == x) {
pr->left = l;
} else
pr->right = l;
l->parent = pr;
} else if (r->key != NIL.key) {
if (pr->left == x) {
pr->left = r;
} else
pr->right = r;
r->parent = pr;
}
}
Node *get_next(Node *k) {
if (k->key == NIL.key)
return &NIL;
Node *res = get_next(k->left);
if (res->key != NIL.key)
return res;
return k;
}
void del(Node *x) {
if (x->key == NIL.key)
return;
Node *l = x->left;
Node *r = x->right;
Node *pr = x->parent;
if (l->key != NIL.key && r->key != NIL.key) {
Node *nex = get_next(r);
x->key = nex->key;
delp12(nex);
} else {
delp12(x);
}
}
Node *rightRotate(Node *t) {
Node *s = t->left;
t->left = s->right;
s->right = t;
return s;
}
Node *leftRotate(Node *t) {
Node *s = t->right;
t->right = s->left;
s->left = t;
return s;
}
Node *_insert(Node *t, int key, int priority) {
if (t->key == NIL.key) {
return new Node(key, priority);
}
if (key == t->key) {
return t;
}
if (key < t->key) {
t->left = _insert(t->left, key, priority);
if (t->priority < t->left->priority) {
t = rightRotate(t);
}
} else {
t->right = _insert(t->right, key, priority);
if (t->priority < t->right->priority) {
t = leftRotate(t);
}
}
return t;
}
Node *delete1(Node *t, int key);
Node *_delete(Node *t, int key) {
if (t->left->key == NIL.key && t->right->key == NIL.key) {
return &NIL;
} else if (t->left->key == NIL.key) {
t = leftRotate(t);
} else if (t->right->key == NIL.key) {
t = rightRotate(t);
} else {
if (t->left->priority > t->right->priority) {
t = rightRotate(t);
} else
t = leftRotate(t);
}
return delete1(t, key);
}
Node *delete1(Node *t, int key) {
if (t->key == NIL.key) {
return &NIL;
}
if (key < t->key) {
t->left = delete1(t->left, key);
} else if (key > t->key) {
t->right = delete1(t->right, key);
} else
return _delete(t, key);
return t;
}
int H;
int left(int i) { return i * 2 + 1; }
int right(int i) { return i * 2 + 2; }
struct edge {
int from, to;
ll val;
edge(int from, int to, ll val) : from(from), to(to), val(val) {}
};
ll k;
int _rank[1010];
int temp[1010];
bool compare_sa(int i, int j) {
if (_rank[i] != _rank[j])
return _rank[i] < _rank[j];
else {
int ri = i + k <= n ? _rank[i + k] : -1;
int rj = j + k <= n ? _rank[j + k] : -1;
return ri < rj;
}
}
void construct_sa(string S, int *sa) {
n = S.length();
for (size_t i = 0; i <= n; i++) {
sa[i] = i;
_rank[i] = i < n ? S[i] : -1;
}
for (k = 1; k <= n; k *= 2) {
sort(sa, sa + n + 1, compare_sa);
// saはソート後の接尾辞の並びになっている、rankは元の位置のindexを保持したまま、更新されている。
// ピンとこなかった部分
temp[sa[0]] = 0;
for (size_t i = 1; i <= n; i++) {
temp[sa[i]] = temp[sa[i - 1]] + (compare_sa(sa[i - 1], sa[i]) ? 1 : 0);
}
for (size_t i = 0; i <= n; i++) {
_rank[i] = temp[i];
}
}
}
bool contain(string S, int *sa, string T) {
int a = 0, b = S.length();
// sa は 接尾辞が辞書順に並んでいる、入っているのはその位置のインデックス
while (b - a > 1) {
int c = (a + b) / 2;
if (S.compare(sa[c], T.length(), T) < 0)
a = c;
else
b = c;
}
return S.compare(sa[b], T.length(), T) == 0;
}
#define bit(x, v) ((ll)x << v)
class BIT {
static const int MAX_N = 500010;
public:
BIT() { memset(bit, 0, sizeof(bit)); }
ll bit[MAX_N + 1], n;
ll sum(int i) {
ll s = 0;
while (i > 0) {
s += bit[i];
i -= i & -i;
}
return s;
}
void add(int i, int x) {
while (i <= n) {
bit[i] += x;
i += i & -i;
}
}
};
struct UnionFind {
vector<int> A;
UnionFind(int n) : A(n, -1) {}
int find(int x) {
if (A[x] < 0)
return x;
return A[x] = find(A[x]);
}
void unite(int x, int y) {
x = find(x), y = find(y);
if (x == y)
return;
if (A[x] > A[y])
swap(x, y);
A[x] += A[y];
A[y] = x;
}
int ngroups() {
int ans = 0;
for (auto a : A)
if (a < 0)
ans++;
return ans;
}
};
void yes() {
cout << "Yes\n";
exit(0);
}
void no() {
cout << "No\n";
exit(0);
}
vector<ll> getp(ll n) {
vector<ll> res;
ll a = 2;
if (n % 2 == 0) {
res.push_back(2);
while (n % 2 == 0)
n /= 2;
}
for (ll i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
res.push_back(i);
while (n % i == 0)
n /= i;
}
}
if (n != 1)
res.push_back(n);
return res;
}
vector<ll> getp2(ll n) {
vector<ll> res;
ll a = 2;
if (n % 2 == 0) {
while (n % 2 == 0) {
n /= 2;
res.push_back(2);
}
}
for (ll i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
while (n % i == 0) {
n /= i;
res.push_back(i);
}
}
}
if (n != 1)
res.push_back(n);
return res;
}
vector<pll> getp3(ll n) {
vector<pll> res;
ll a = 2;
int si = 0;
if (n % 2 == 0) {
res.push_back(make_pair(2, 0));
while (n % 2 == 0) {
n /= 2;
res[si].second++;
}
si++;
}
for (ll i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
res.push_back(make_pair(i, 0));
while (n % i == 0) {
n /= i;
res[si].second++;
}
si++;
}
}
if (n != 1) {
res.push_back(make_pair(n, 1));
}
return res;
}
vector<ll> getDivisors(ll n) {
vector<ll> res;
ll a = 2;
res.push_back(1);
for (ll i = 2; i * i <= n; i++) {
if (n % i == 0) {
res.push_back(i);
if (n / i != i)
res.push_back(n / i);
}
}
return res;
}
struct ve {
public:
vector<ve> child;
int _t = INF;
ve(int t) : _t(t) {}
ve(ve _left, ve _right) {
_t = _left._t + _right._t;
child.push_back(_left);
child.push_back(_right);
}
bool operator<(const ve &t) const { return _t > t._t; }
};
vector<bool> elas(ll n) {
vector<bool> r(n);
fill(r.begin(), r.end(), 1);
r[0] = 0;
r[1] = 0;
for (ll i = 2; i * i < n; i++) {
if (!r[i])
continue;
ll ti = i * 2;
while (ti < n) {
r[ti] = false;
ti += i;
}
}
return r;
}
bool isPrime(ll v) {
for (ll i = 2; i * i <= v; i++) {
if (v % i == 0)
return false;
}
return true;
}
ll getpow(ll b, ll x, ll md) {
ll t = b;
ll res = 1;
while (x > 0) {
if (x & 1) {
res *= t;
res %= md;
}
x >>= 1;
t *= t;
t %= md;
}
return res;
}
ll getpow(ll b, ll x) { return getpow(b, x, INF); }
class SegTree {
public:
const static int MAX_N = 100010;
const static int DAT_SIZE = (1 << 18) - 1;
int N, Q;
int A[MAX_N];
ll data[DAT_SIZE], datb[DAT_SIZE];
void init(int _n) {
N = 1;
while (N < _n)
N <<= 1;
memset(data, 0, sizeof(data));
memset(datb, 0, sizeof(datb));
}
void init(int _n, ll iv) {
N = 1;
while (N < _n)
N <<= 1;
rep(i, DAT_SIZE) {
data[i] = iv;
datb[i] = iv;
}
}
void add(int a, int b, int x) { add(a, b + 1, x, 0, 0, N); }
void add(int a, int b, int x, int k, int l, int r) {
if (a <= l && r <= b) {
data[k] += x;
} else if (l < b && a < r) {
datb[k] += (min(b, r) - max(a, l)) * x;
add(a, b, x, k * 2 + 1, l, (l + r) / 2);
add(a, b, x, k * 2 + 2, (l + r) / 2, r);
}
}
void change(int a, int b, int x) { change(a, b + 1, x, 0, 0, N); }
void change(int a, int b, int x, int k, int l, int r) {
if (a <= l && r <= b) {
data[k] = x;
} else if (l < b && a < r) {
datb[k] = x;
change(a, b, x, k * 2 + 1, l, (l + r) / 2);
change(a, b, x, k * 2 + 2, (l + r) / 2, r);
}
}
ll sum(int a, int b) { return sum(a, b + 1, 0, 0, N); }
ll sum(int a, int b, int k, int l, int r) {
if (b <= l || r <= a) {
return 0;
}
if (a <= l && r <= b) {
return data[k] * (r - l) + datb[k];
}
ll res = (min(b, r) - max(a, l)) * data[k];
res += sum(a, b, k * 2 + 1, l, (l + r) / 2);
res += sum(a, b, k * 2 + 2, (l + r) / 2, r);
return res;
}
};
class Segment;
class Circle;
class Point {
public:
double x, y;
Point(double x = 0, double y = 0) : x(x), y(y) {}
Point operator+(Point p) { return Point(x + p.x, y + p.y); }
Point operator-(Point p) { return Point(x - p.x, y - p.y); }
Point operator*(double a) { return Point(a * x, a * y); }
Point operator/(double a) { return Point(x / a, y / a); }
double abs() { return sqrt(norm()); }
double norm() { return x * x + y * y; }
bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; }
bool operator==(const Point &p) const {
return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
}
static double dot(Point a, Point b) { return a.x * b.x + a.y * b.y; }
static double cross(Point a, Point b) { return a.x * b.y - a.y * b.x; }
static bool isOrthogonal(Point a, Point b) { return EQ(dot(a, b), 0.0); }
static bool isOrthogonal(Point a1, Point a2, Point b1, Point b2) {
return isOrthogonal(a1 - a2, b1 - b2);
}
static bool isOrthogonal(Segment s1, Segment s2);
static bool isPalallel(Point a, Point b) { return EQ(cross(a, b), 0.0); }
static bool isPalallel(Point a1, Point a2, Point b1, Point b2) {
return isPalallel(a1 - a2, b1 - b2);
}
static bool isPalallel(Segment s1, Segment s2);
static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;
static int ccw(Point p0, Point p1, Point p2) {
Point a = p1 - p0;
Point b = p2 - p0;
if (cross(a, b) > EPS)
return COUNTER_CLOCKWISE;
if (cross(a, b) < -EPS)
return CLOCKWISE;
if (dot(a, b) < -EPS)
return ONLINE_BACK;
if (a.norm() < b.norm())
return ONLINE_FRONT;
return ON_SEGMENT;
}
static bool intersect(Point p1, Point p2, Point p3, Point p4) {
return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 &&
ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0);
}
static bool intersect(Segment s1, Segment s2);
static Point project(Segment s, Point p);
static Point reflect(Segment s, Point p);
static Point getDistance(Point a, Point b) { return (a - b).abs(); }
static double getDistanceLP(Segment s, Point p);
static double getDistanceSP(Segment s, Point p);
static double getDistance(Segment s1, Segment s2);
static Point getIntersection(Segment s1, Segment s2);
static pair<Point, Point> crossPoints(Circle c, Segment s);
};
class Segment {
public:
Point p1, p2;
Segment() {}
Segment(Point p1, Point p2) : p1(p1), p2(p2) {}
Point p1tp2() { return p2 - p1; }
Point p2tp1() { return p1 - p2; }
double abs() { return std::abs(norm()); }
double norm() { return (p2 - p1).norm(); }
};
bool Point::isOrthogonal(Segment s1, Segment s2) {
return EQ(dot(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
bool Point::isPalallel(Segment s1, Segment s2) {
return EQ(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
bool Point::intersect(Segment s1, Segment s2) {
return intersect(s1.p1, s1.p2, s2.p1, s2.p2);
}
Point Point::project(Segment s, Point p) {
Point base = s.p2 - s.p1;
double r = Point::dot(p - s.p1, base) / base.norm();
return s.p1 + base * r;
}
Point Point::reflect(Segment s, Point p) { return (project(s, p) * 2) - p; }
double Point::getDistanceLP(Segment s, Point p) {
return std::abs(cross(s.p2 - s.p1, p - s.p1) / (s.p2 - s.p1).abs());
}
double Point::getDistanceSP(Segment s, Point p) {
if (dot(s.p2 - s.p1, p - s.p1) < 0.0)
return (p - s.p1).abs();
if (dot(s.p1 - s.p2, p - s.p2) < 0.0)
return (p - s.p2).abs();
return getDistanceLP(s, p);
}
double Point::getDistance(Segment s1, Segment s2) {
if (intersect(s1, s2))
return 0.0;
return min({getDistanceSP(s1, s2.p1), getDistanceSP(s1, s2.p2),
getDistanceSP(s2, s1.p1), getDistanceSP(s2, s1.p2)});
}
Point Point::getIntersection(Segment s1, Segment s2) {
// (s1.p1 - s2.p1).norm()
auto bs = s1.p2 - s1.p1;
auto n1 = s2.p1 - s1.p1;
auto n2 = s2.p2 - s1.p1;
auto c1 = std::abs(cross(n1, bs)) / bs.norm();
auto c2 = std::abs(cross(n2, bs)) / bs.norm();
return s2.p1 + (s2.p2 - s2.p1) * (c1 / (c1 + c2));
// c1:c2=t:1-t
// c2t=(1-t)c1
// t/(1-t)=c1/(c1+c2)
//
}
double arg(Point p) { return atan2(p.y, p.x); }
Point polar(double a, double r) { return Point(cos(r) * a, sin(r) * a); }
class Circle {
public:
Point c;
double r;
Circle(Point c = Point(), double r = 0.0) : c(c), r(r) {}
static pair<Point, Point> getCrossPoints(Circle c1, Circle c2) {
double d = (c1.c - c2.c).abs(); // 中心点どうしの距離
double a = acos((c1.r * c1.r + d * d - c2.r * c2.r) / (2 * c1.r * d));
double t = arg(c2.c - c1.c);
return make_pair(c1.c + polar(c1.r, t + a), c1.c + polar(c1.r, t - a));
}
};
pair<Point, Point> Point::crossPoints(Circle c, Segment s) {
auto pp = project(s, c.c);
auto f = (pp - c.c).norm();
auto mu = sqrt(c.r * c.r - f);
auto e = s.p1tp2() / s.p1tp2().abs();
return make_pair(pp + e * mu, pp - e * mu);
}
ll divRm(string s, ll x) {
ll r = 0;
for (size_t i = 0; i < s.size(); i++) {
r *= 10;
r += s[i] - '0';
r %= x;
}
return r;
}
ll cmbi(ll x, ll b) {
ll res = 1;
for (size_t i = 0; i < b; i++) {
res *= x - i;
res %= INF;
res *= inv[b - i];
res %= INF;
}
return res;
}
void dfs(string s, char a) {
if (s.size() == n) {
cout << s << endl;
return;
}
for (char b = 'a'; b <= a; b++) {
dfs(s + b, (b == a) ? (char)(a + 1) : a);
}
}
string combine(string s, string t) {
string res = s + t;
for (int i = s.size() - 1; i >= 0; i--) {
int p = s.size() - i;
bool ok = true;
for (int j = 0; j < p && ok; j++) {
if (!(s[i + j] == t[j] || s[i + j] == '?' || t[j] == '?')) {
ok = false;
}
}
if (!ok)
continue;
string v = "";
for (int j = 0; j < i; j++) {
v += s[j];
}
for (int j = 0; j < t.size(); j++) {
if (j < p) {
if (s[i + j] == '?' && t[j] != '?') {
v += t[j];
} else if (s[i + j] != '?' && t[j] == '?') {
v += s[i + j];
} else {
v += t[j];
}
} else
v += t[j];
}
res = v;
}
return res;
}
string cmc(string a, string b, string c) {
string a1 = combine(a, b);
return combine(a1, c);
}
bool match(char a, char b) { return a == '?' || b == '?' || a == b; }
bool between(ll x, ll y1, ll y2) {
if (y1 > y2)
swap(y1, y2);
y1++;
y2--;
if (!(y1 <= y2))
return false;
while (x > 0) {
if (x % 3 == 1) {
if (y2 - y1 > 3)
return true;
for (ll y = y1; y <= y2; y++)
if (y % 3 == 1)
return true;
}
x /= 3;
y1 /= 3;
y2 /= 3;
}
return false;
}
ll get_extra(ll x1, ll y1, ll x2, ll y2) {
ll ans = 0;
int i;
ll three = 1;
rep(i, 36) {
if (x1 / three == x2 / three &&
between(x1 / three, y1 / three, y2 / three)) {
ll tmp = min(min(x1 % three, x2 % three) + 1,
three - max(x1 % three, x2 % three));
ans = max(ans, tmp);
}
three *= 3;
}
return ans;
}
ll get_dist(ll x1, ll y1, ll x2, ll y2) {
return abs(x1 - x2) + abs(y1 - y2) +
2 * max(get_extra(x1, y1, x2, y2), get_extra(y1, x1, y2, x2));
}
ll memo[62][2];
ll ar[100010];
ll m = 60;
ll bdp(int i, bool tite) {
if (~memo[i][tite])
return memo[i][tite];
if (i > m)
return 0;
ll res = 0;
ll cn = 0;
ll base = (1LL << (m - i));
rep(j, n) { cn += (ar[j] & base) > 0; }
if (tite) {
ll p = (k & base);
if (p == 0) {
res = bdp(i + 1, tite) + cn * base;
} else {
// titeでbitが立っている時
// 立てる時は(n-cn)*baseが加算され
// 立てないときはcn*baseが加算される
// その大きい方を返したい
res = bdp(i + 1, true) + (n - cn) * base;
res = max(res, bdp(i + 1, false) + cn * base);
}
} else {
res = bdp(i + 1, false) + max(cn, (n - cn)) * base;
}
return memo[i][tite] = res;
}
void solv() {
cin >> n >> k;
rep(i, n) { cin >> ar[i]; }
memset(memo, -1, sizeof(memo));
cout << bdp(0, true) << endl;
}
int main() {
// COMinit();
solv();
return 0;
} | [
"variable_declaration.type.change",
"assignment.value.change",
"identifier.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 938,821 | 938,820 | u224756887 | cpp |
p03138 | #include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
ll mod = 1e9 + 7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
int main() {
int n;
ll k;
cin >> n >> k;
vector<ll> a(n);
rep(i, n) cin >> a[i];
vector<vector<ll>> dp(45, vector<ll>(2, -1));
dp[44][0] = 0;
for (int i = 43; i >= 0; --i) {
ll cnt1 = 0;
rep(j, n) {
if (a[j] & (1LL << i))
++cnt1;
}
// cout << cnt1 << endl;
if (dp[i + 1][0] >= 0) {
if ((k & (1LL << i))) {
dp[i][0] = max(dp[i][1], dp[i + 1][0] + (n - cnt1) * (1LL << i));
dp[i][1] = max(dp[i][0], dp[i + 1][0] + cnt1 * (1LL << i));
} else {
dp[i][0] = max(dp[i][0], dp[i + 1][0] + cnt1 * (1LL << i));
}
}
if (dp[i + 1][1] >= 0) {
dp[i][1] = max(dp[i][1], dp[i + 1][1] + max(cnt1, n - cnt1) * (1LL << i));
}
}
// for (int i = 44; i >= 0; --i) {
// for (auto v: dp[i]) {
// cout << v << " ";
// }
// cout << endl;
//}
cout << max(dp[0][0], dp[0][1]) << endl;
return 0;
}
| #include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
ll mod = 1e9 + 7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
int main() {
ll n;
ll k;
cin >> n >> k;
vector<ll> a(n);
rep(i, n) cin >> a[i];
vector<vector<ll>> dp(45, vector<ll>(2, -1));
dp[44][0] = 0;
for (int i = 43; i >= 0; --i) {
ll cnt1 = 0;
rep(j, n) {
if (a[j] & (1LL << i))
++cnt1;
}
// cout << cnt1 << endl;
if (dp[i + 1][0] >= 0) {
if ((k & (1LL << i))) {
dp[i][0] = max(dp[i][0], dp[i + 1][0] + (n - cnt1) * (1LL << i));
dp[i][1] = max(dp[i][1], dp[i + 1][0] + cnt1 * (1LL << i));
} else {
dp[i][0] = max(dp[i][0], dp[i + 1][0] + cnt1 * (1LL << i));
}
}
if (dp[i + 1][1] >= 0) {
dp[i][1] = max(dp[i][1], dp[i + 1][1] + max(cnt1, n - cnt1) * (1LL << i));
}
}
// for (int i = 44; i >= 0; --i) {
// for (auto v: dp[i]) {
// cout << v << " ";
// }
// cout << endl;
//}
cout << max(dp[0][0], dp[0][1]) << endl;
return 0;
}
| [
"variable_declaration.type.change",
"literal.number.change",
"assignment.value.change",
"variable_access.subscript.index.change",
"call.arguments.change"
] | 938,826 | 938,827 | u596311864 | cpp |
p03138 | #include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
ll mod = 1e9 + 7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
int main() {
int n;
ll k;
cin >> n >> k;
vector<ll> a(n);
rep(i, n) cin >> a[i];
vector<vector<ll>> dp(45, vector<ll>(2, -1));
dp[44][0] = 0;
for (int i = 43; i >= 0; --i) {
ll cnt1 = 0;
rep(j, n) {
if (a[j] & (1LL << i))
++cnt1;
}
// cout << cnt1 << endl;
if (dp[i + 1][0] >= 0) {
if ((k & (1LL << i))) {
dp[i][1] = max(dp[i][1], dp[i + 1][0] + (n - cnt1) * (1LL << i));
dp[i][0] = max(dp[i][0], dp[i + 1][0] + cnt1 * (1LL << i));
} else {
dp[i][0] = max(dp[i][0], dp[i + 1][0] + cnt1 * (1LL << i));
}
}
if (dp[i + 1][1] >= 0) {
dp[i][1] = max(dp[i][1], dp[i + 1][1] + max(cnt1, n - cnt1) * (1LL << i));
}
}
// for (int i = 44; i >= 0; --i) {
// for (auto v: dp[i]) {
// cout << v << " ";
// }
// cout << endl;
//}
cout << max(dp[0][0], dp[0][1]) << endl;
return 0;
}
| #include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
ll mod = 1e9 + 7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
int main() {
ll n;
ll k;
cin >> n >> k;
vector<ll> a(n);
rep(i, n) cin >> a[i];
vector<vector<ll>> dp(45, vector<ll>(2, -1));
dp[44][0] = 0;
for (int i = 43; i >= 0; --i) {
ll cnt1 = 0;
rep(j, n) {
if (a[j] & (1LL << i))
++cnt1;
}
// cout << cnt1 << endl;
if (dp[i + 1][0] >= 0) {
if ((k & (1LL << i))) {
dp[i][0] = max(dp[i][0], dp[i + 1][0] + (n - cnt1) * (1LL << i));
dp[i][1] = max(dp[i][1], dp[i + 1][0] + cnt1 * (1LL << i));
} else {
dp[i][0] = max(dp[i][0], dp[i + 1][0] + cnt1 * (1LL << i));
}
}
if (dp[i + 1][1] >= 0) {
dp[i][1] = max(dp[i][1], dp[i + 1][1] + max(cnt1, n - cnt1) * (1LL << i));
}
}
// for (int i = 44; i >= 0; --i) {
// for (auto v: dp[i]) {
// cout << v << " ";
// }
// cout << endl;
//}
cout << max(dp[0][0], dp[0][1]) << endl;
return 0;
}
| [
"variable_declaration.type.change",
"literal.number.change",
"assignment.variable.change",
"variable_access.subscript.index.change",
"assignment.value.change",
"call.arguments.change"
] | 938,828 | 938,827 | u596311864 | cpp |
p03138 | #include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <numeric>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main() {
long long N, K;
cin >> N >> K;
vector<long long> A(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
}
vector<int> cnt0(40, 0);
vector<int> cnt1(40, 0);
for (long long temp : A) {
for (int i = 0; i < 40; i++) {
if (temp & (1LL << i)) {
cnt1[i]++;
} else {
cnt0[i]++;
}
}
}
vector<long long> bestSum(40);
bestSum[0] = 0;
for (int i = 1; i < 40; i++) {
long long plus;
if (cnt1[i] > cnt0[i]) {
plus = cnt1[i - 1] * (1LL << (i - 1));
} else {
plus = cnt0[i - 1] * (1LL << (i - 1));
}
bestSum[i] = bestSum[i - 1] + plus;
}
long long tempSum = 0;
long long ans = 0;
for (int i = 39; i >= 0; i--) {
if (K & (1LL << i)) {
// 0, K未満確定
long long temp = tempSum + cnt1[i] * (1LL << i) + bestSum[i];
ans = max(ans, temp);
// 1
tempSum += cnt0[i] * (1LL << i);
} else {
// 0
tempSum += cnt1[i] * (1LL << i);
}
}
ans = max(ans, tempSum);
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <numeric>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main() {
long long N, K;
cin >> N >> K;
vector<long long> A(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
}
vector<int> cnt0(40, 0);
vector<int> cnt1(40, 0);
for (long long temp : A) {
for (int i = 0; i < 40; i++) {
if (temp & (1LL << i)) {
cnt1[i]++;
} else {
cnt0[i]++;
}
}
}
vector<long long> bestSum(40);
bestSum[0] = 0;
for (int i = 1; i < 40; i++) {
long long plus;
if (cnt1[i - 1] > cnt0[i - 1]) {
plus = cnt1[i - 1] * (1LL << (i - 1));
} else {
plus = cnt0[i - 1] * (1LL << (i - 1));
}
bestSum[i] = bestSum[i - 1] + plus;
}
long long tempSum = 0;
long long ans = 0;
for (int i = 39; i >= 0; i--) {
if (K & (1LL << i)) {
// 0, K未満確定
long long temp = tempSum + cnt1[i] * (1LL << i) + bestSum[i];
ans = max(ans, temp);
// 1
tempSum += cnt0[i] * (1LL << i);
} else {
// 0
tempSum += cnt1[i] * (1LL << i);
}
}
ans = max(ans, tempSum);
cout << ans << endl;
return 0;
} | [
"control_flow.branch.if.condition.change",
"control_flow.loop.for.condition.change",
"misc.off_by_one"
] | 938,848 | 938,849 | u048945791 | cpp |
p03138 | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define ll int64_t
#define _GLIBCXX_DEBUG
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
//拡張ユークリッドの互除法
template <typename T> T extgcd(T a, T b, T &x, T &y) {
T d = a;
if (b != 0) {
d = extgcd(b, a % b, y, x);
y -= (a / b) * x;
} else {
x = 1;
y = 0;
}
return d;
}
//約数列挙(√N)
vector<int64_t> divisor(int64_t n) {
vector<int64_t> ret;
for (int64_t i = 1; i * i <= n; i++) {
if (n % i == 0) {
ret.push_back(i);
if (i * i != n)
ret.push_back(n / i);
}
}
sort(begin(ret), end(ret));
return (ret);
}
//素因数分解(√N)
map<int, int> prime_factor(int n) {
map<int, int> ret;
for (int i = 2; i * i <= n; i++) {
while (n % i == 0) {
ret[i]++;
n /= i;
}
}
if (n != 1)
ret[n] = 1;
return ret;
}
//素数テーブル(NloglogN)
vector<bool> prime_table(int n) {
vector<bool> prime(n + 1, true);
if (n >= 0)
prime[0] = false;
if (n >= 1)
prime[1] = false;
for (int i = 2; i * i <= n; i++) {
if (!prime[i])
continue;
for (int j = i + i; j <= n; j += i) {
prime[j] = false;
}
}
return prime;
}
//二項係数(K)
template <typename T> T binomial(int64_t N, int64_t K) {
if (K < 0 || N < K)
return 0;
T ret = 1;
for (T i = 1; i <= K; ++i) {
ret *= N--;
ret /= i;
}
return ret;
}
//二項係数テーブル(N^2)
template <typename T> vector<vector<T>> binomial_table(int N) {
vector<vector<T>> mat(N + 1, vector<T>(N + 1));
for (int i = 0; i <= N; i++) {
for (int j = 0; j <= i; j++) {
if (j == 0 || j == i)
mat[i][j] = 1;
else
mat[i][j] = mat[i - 1][j - 1] + mat[i - 1][j];
}
}
return mat;
}
// Gragh template
template <typename T> struct edge {
int src, to;
T cost;
edge(int to, T cost) : src(-1), to(to), cost(cost) {}
edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
edge &operator=(const int &x) {
to = x;
return *this;
}
operator int() const { return to; }
};
template <typename T> using Edges = vector<edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template <typename T> using Matrix = vector<vector<T>>;
// unionfind
struct UnionFind {
vector<int> data;
UnionFind(int sz) { data.assign(sz, -1); }
bool unite(int x, int y) {
x = find(x), y = find(y);
if (x == y)
return (false);
if (data[x] > data[y])
swap(x, y);
data[x] += data[y];
data[y] = x;
return (true);
}
int find(int k) {
if (data[k] < 0)
return (k);
return (data[k] = find(data[k]));
}
int size(int k) { return (-data[find(k)]); }
};
// DIJKSTRA(ElogV)最短路
template <typename T> vector<T> dijkstra(WeightedGraph<T> &g, int s) {
const auto INF = numeric_limits<T>::max();
vector<T> dist(g.size(), INF);
using Pi = pair<T, int>;
priority_queue<Pi, vector<Pi>, greater<Pi>> que;
dist[s] = 0;
que.emplace(dist[s], s);
while (!que.empty()) {
T cost;
int idx;
tie(cost, idx) = que.top();
que.pop();
if (dist[idx] < cost)
continue;
for (auto &e : g[idx]) {
auto next_cost = cost + e.cost;
if (dist[e.to] <= next_cost)
continue;
dist[e.to] = next_cost;
que.emplace(dist[e.to], e.to);
}
}
return dist;
}
// prim最小全域木
template <typename T> T prim(WeightedGraph<T> &g) {
using Pi = pair<T, int>;
T total = 0;
vector<bool> used(g.size(), false);
priority_queue<Pi, vector<Pi>, greater<Pi>> que;
que.emplace(0, 0);
while (!que.empty()) {
auto p = que.top();
que.pop();
if (used[p.second])
continue;
used[p.second] = true;
total += p.first;
for (auto &e : g[p.second]) {
que.emplace(e.cost, e.to);
}
}
return total;
}
// bellman_ford(VE)単一始点最短路
template <typename T> vector<T> bellman_ford(Edges<T> &edges, int V, int s) {
const auto INF = numeric_limits<T>::max();
vector<T> dist(V, INF);
dist[s] = 0;
for (int i = 0; i < V - 1; i++) {
for (auto &e : edges) {
if (dist[e.src] == INF)
continue;
dist[e.to] = min(dist[e.to], dist[e.src] + e.cost);
}
}
for (auto &e : edges) {
if (dist[e.src] == INF)
continue;
if (dist[e.src] + e.cost < dist[e.to])
return vector<T>();
}
return dist;
}
void dp(vector<ll> &ansset, int keta, bitset<40> ke, bitset<40> ans) {
if (keta == -1) {
ansset.push_back(0);
return;
}
if (keta == 0) {
if ((!ke.test(0)) && ans.test(0)) {
ansset.push_back(ke.to_ullong());
return;
} else {
ansset.push_back(ans.to_ullong());
return;
}
}
if ((!ans.test(keta)) && ke.test(keta)) {
ansset.push_back(ans.to_ullong());
return;
}
if (ans.test(keta) && ke.test(keta)) {
dp(ansset, keta - 1, ke, ans);
bitset<40> b = ans;
b.set(keta, 0);
ansset.push_back(b.to_ullong());
return;
}
if (!ke.test(keta)) {
ke.set(keta, 0);
dp(ansset, keta - 1, ke, ans);
return;
}
}
// memo cout << fixed << setprecision(桁数);//
int main() {
int n;
cin >> n;
ll k;
cin >> k;
bitset<40> ke(k);
int sz = 0;
rep(i, 40) {
if (ke.test(39 - i)) {
sz = 40 - i;
break;
}
}
vector<ll> a(n);
rep(i, n) cin >> a.at(i);
vector<int> counting(sz);
rep(i, n) {
bitset<40> now(a.at(i));
rep(j, sz) {
if (now.test(j))
counting.at(j)++;
else
counting.at(j)--;
}
}
bitset<40> ans(0);
rep(i, sz) if (counting.at(i) < 0) ans.set(i, 1);
vector<ll> ansset;
dp(ansset, sz - 1, ke, ans);
ll answer = 0;
rep(i, ansset.size()) {
ll nowa = 0;
rep(j, n) {
ll ba = a.at(j) ^ ansset.at(i);
nowa += ba;
}
answer = max(answer, nowa);
}
cout << answer << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define ll int64_t
#define _GLIBCXX_DEBUG
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
//拡張ユークリッドの互除法
template <typename T> T extgcd(T a, T b, T &x, T &y) {
T d = a;
if (b != 0) {
d = extgcd(b, a % b, y, x);
y -= (a / b) * x;
} else {
x = 1;
y = 0;
}
return d;
}
//約数列挙(√N)
vector<int64_t> divisor(int64_t n) {
vector<int64_t> ret;
for (int64_t i = 1; i * i <= n; i++) {
if (n % i == 0) {
ret.push_back(i);
if (i * i != n)
ret.push_back(n / i);
}
}
sort(begin(ret), end(ret));
return (ret);
}
//素因数分解(√N)
map<int, int> prime_factor(int n) {
map<int, int> ret;
for (int i = 2; i * i <= n; i++) {
while (n % i == 0) {
ret[i]++;
n /= i;
}
}
if (n != 1)
ret[n] = 1;
return ret;
}
//素数テーブル(NloglogN)
vector<bool> prime_table(int n) {
vector<bool> prime(n + 1, true);
if (n >= 0)
prime[0] = false;
if (n >= 1)
prime[1] = false;
for (int i = 2; i * i <= n; i++) {
if (!prime[i])
continue;
for (int j = i + i; j <= n; j += i) {
prime[j] = false;
}
}
return prime;
}
//二項係数(K)
template <typename T> T binomial(int64_t N, int64_t K) {
if (K < 0 || N < K)
return 0;
T ret = 1;
for (T i = 1; i <= K; ++i) {
ret *= N--;
ret /= i;
}
return ret;
}
//二項係数テーブル(N^2)
template <typename T> vector<vector<T>> binomial_table(int N) {
vector<vector<T>> mat(N + 1, vector<T>(N + 1));
for (int i = 0; i <= N; i++) {
for (int j = 0; j <= i; j++) {
if (j == 0 || j == i)
mat[i][j] = 1;
else
mat[i][j] = mat[i - 1][j - 1] + mat[i - 1][j];
}
}
return mat;
}
// Gragh template
template <typename T> struct edge {
int src, to;
T cost;
edge(int to, T cost) : src(-1), to(to), cost(cost) {}
edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
edge &operator=(const int &x) {
to = x;
return *this;
}
operator int() const { return to; }
};
template <typename T> using Edges = vector<edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template <typename T> using Matrix = vector<vector<T>>;
// unionfind
struct UnionFind {
vector<int> data;
UnionFind(int sz) { data.assign(sz, -1); }
bool unite(int x, int y) {
x = find(x), y = find(y);
if (x == y)
return (false);
if (data[x] > data[y])
swap(x, y);
data[x] += data[y];
data[y] = x;
return (true);
}
int find(int k) {
if (data[k] < 0)
return (k);
return (data[k] = find(data[k]));
}
int size(int k) { return (-data[find(k)]); }
};
// DIJKSTRA(ElogV)最短路
template <typename T> vector<T> dijkstra(WeightedGraph<T> &g, int s) {
const auto INF = numeric_limits<T>::max();
vector<T> dist(g.size(), INF);
using Pi = pair<T, int>;
priority_queue<Pi, vector<Pi>, greater<Pi>> que;
dist[s] = 0;
que.emplace(dist[s], s);
while (!que.empty()) {
T cost;
int idx;
tie(cost, idx) = que.top();
que.pop();
if (dist[idx] < cost)
continue;
for (auto &e : g[idx]) {
auto next_cost = cost + e.cost;
if (dist[e.to] <= next_cost)
continue;
dist[e.to] = next_cost;
que.emplace(dist[e.to], e.to);
}
}
return dist;
}
// prim最小全域木
template <typename T> T prim(WeightedGraph<T> &g) {
using Pi = pair<T, int>;
T total = 0;
vector<bool> used(g.size(), false);
priority_queue<Pi, vector<Pi>, greater<Pi>> que;
que.emplace(0, 0);
while (!que.empty()) {
auto p = que.top();
que.pop();
if (used[p.second])
continue;
used[p.second] = true;
total += p.first;
for (auto &e : g[p.second]) {
que.emplace(e.cost, e.to);
}
}
return total;
}
// bellman_ford(VE)単一始点最短路
template <typename T> vector<T> bellman_ford(Edges<T> &edges, int V, int s) {
const auto INF = numeric_limits<T>::max();
vector<T> dist(V, INF);
dist[s] = 0;
for (int i = 0; i < V - 1; i++) {
for (auto &e : edges) {
if (dist[e.src] == INF)
continue;
dist[e.to] = min(dist[e.to], dist[e.src] + e.cost);
}
}
for (auto &e : edges) {
if (dist[e.src] == INF)
continue;
if (dist[e.src] + e.cost < dist[e.to])
return vector<T>();
}
return dist;
}
void dp(vector<ll> &ansset, int keta, bitset<40> ke, bitset<40> ans) {
if (keta == -1) {
ansset.push_back(0);
return;
}
if (keta == 0) {
if ((!ke.test(0)) && ans.test(0)) {
ansset.push_back(ke.to_ullong());
return;
} else {
ansset.push_back(ans.to_ullong());
return;
}
}
if ((!ans.test(keta)) && ke.test(keta)) {
ansset.push_back(ans.to_ullong());
return;
}
if (ans.test(keta) && ke.test(keta)) {
dp(ansset, keta - 1, ke, ans);
bitset<40> b = ans;
b.set(keta, 0);
ansset.push_back(b.to_ullong());
return;
}
if (!ke.test(keta)) {
ans.set(keta, 0);
dp(ansset, keta - 1, ke, ans);
return;
}
}
// memo cout << fixed << setprecision(桁数);//
int main() {
int n;
cin >> n;
ll k;
cin >> k;
bitset<40> ke(k);
int sz = 0;
rep(i, 40) {
if (ke.test(39 - i)) {
sz = 40 - i;
break;
}
}
vector<ll> a(n);
rep(i, n) cin >> a.at(i);
vector<int> counting(sz);
rep(i, n) {
bitset<40> now(a.at(i));
rep(j, sz) {
if (now.test(j))
counting.at(j)++;
else
counting.at(j)--;
}
}
bitset<40> ans(0);
rep(i, sz) if (counting.at(i) < 0) ans.set(i, 1);
vector<ll> ansset;
dp(ansset, sz - 1, ke, ans);
ll answer = 0;
rep(i, ansset.size()) {
ll nowa = 0;
rep(j, n) {
ll ba = a.at(j) ^ ansset.at(i);
nowa += ba;
}
answer = max(answer, nowa);
}
cout << answer << endl;
} | [
"identifier.change"
] | 938,850 | 938,851 | u579165340 | cpp |
p03138 | #include <bits/stdc++.h>
using namespace std;
using ll = int_fast64_t;
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define repr(i, n) for (int i{n}; i-- > 0;)
signed main() {
ll n, k;
cin >> n >> k;
vector<ll> a(n);
rep(i, n) cin >> a[i];
vector bitcnt(60, 0);
rep(i, n) rep(j, 60) if (a[i] >> j & 1) bitcnt[j]++;
ll x = 0;
repr(j, 60) if (bitcnt[j] * 2 <= n and x | (1LL << j) <= k) x |= 1LL << j;
ll ans = 0;
rep(i, n) ans += x ^ a[i];
cout << (ans) << endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = int_fast64_t;
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define repr(i, n) for (int i{n}; i-- > 0;)
signed main() {
ll n, k;
cin >> n >> k;
vector<ll> a(n);
rep(i, n) cin >> a[i];
vector bitcnt(60, 0);
rep(i, n) rep(j, 60) if (a[i] >> j & 1) bitcnt[j]++;
ll x = 0;
repr(j, 60) if (bitcnt[j] * 2 <= n and (x | (1LL << j)) <= k) x |= 1LL << j;
ll ans = 0;
rep(i, n) ans += x ^ a[i];
cout << (ans) << endl;
} | [
"call.arguments.change"
] | 938,852 | 938,853 | u423624748 | cpp |
p03138 | #include <bits/stdc++.h>
using namespace std;
using ll = int_fast64_t;
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define repr(i, n) for (int i{n}; i-- > 0;)
signed main() {
ll n, k;
cin >> n >> k;
vector<ll> a(n);
rep(i, n) cin >> a[i];
vector bitcnt(60, 0);
rep(i, n) rep(j, 60) if (a[i] >> j & 1) bitcnt[j]++;
ll x = 0;
repr(j, 60) if (bitcnt[j] * 2 < n and x | (1LL << j) <= k) x |= 1LL << j;
ll ans = 0;
rep(i, n) ans += x ^ a[i];
cout << (ans) << endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = int_fast64_t;
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define repr(i, n) for (int i{n}; i-- > 0;)
signed main() {
ll n, k;
cin >> n >> k;
vector<ll> a(n);
rep(i, n) cin >> a[i];
vector bitcnt(60, 0);
rep(i, n) rep(j, 60) if (a[i] >> j & 1) bitcnt[j]++;
ll x = 0;
repr(j, 60) if (bitcnt[j] * 2 <= n and (x | (1LL << j)) <= k) x |= 1LL << j;
ll ans = 0;
rep(i, n) ans += x ^ a[i];
cout << (ans) << endl;
} | [
"expression.operator.compare.change",
"assignment.variable.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 938,854 | 938,853 | u423624748 | cpp |
p03138 | #include <bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
signed main() {
i64 n, k;
cin >> n >> k;
vector<i64> a(n);
for (auto &ai : a)
cin >> ai;
i64 res = 0;
for (int i = 62; i >= 0; --i) {
if (res | (1LL << i) > k)
continue;
int cnt = 0;
for (auto &ai : a)
cnt += (ai >> i & 1);
if (cnt <= n / 2)
res |= (1LL << i);
}
i64 ans = 0;
for (auto &ai : a)
ans += ai ^ res;
cout << (ans) << endl;
} | #include <bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
signed main() {
i64 n, k;
cin >> n >> k;
vector<i64> a(n);
for (auto &ai : a)
cin >> ai;
i64 res = 0;
for (int i = 62; i >= 0; --i) {
if ((res | (1LL << i)) > k)
continue;
int cnt = 0;
for (auto &ai : a)
cnt += ((ai >> i) & 1);
if (cnt <= n / 2)
res |= (1LL << i);
}
i64 ans = 0;
for (auto &ai : a)
ans += ai ^ res;
cout << (ans) << endl;
} | [
"control_flow.branch.if.condition.change"
] | 938,855 | 938,856 | u423624748 | cpp |
p03138 | #include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;
template <class T> inline bool chmax(T &x, T y) {
if (x < y) {
x = y;
return true;
}
return false;
}
template <class T> inline bool chmin(T &x, T y) {
if (x > y) {
x = y;
return true;
}
return false;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
ll k;
cin >> n >> k;
vector<ll> a(n);
for (int i = 0; i < n; ++i)
cin >> a[i];
ll x = 0;
for (int d = 40; d >= 0; --d) {
int zero = 0, one = 0;
for (int i = 0; i < n; ++i) {
if ((a[i] >> d) & 1)
++one;
else
++zero;
}
if (zero > one) {
if (x + (1LL << d) < k) {
x += 1LL << d;
}
}
}
ll ans = 0;
for (int i = 0; i < n; ++i)
ans += a[i] ^ x;
cout << ans << endl;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;
template <class T> inline bool chmax(T &x, T y) {
if (x < y) {
x = y;
return true;
}
return false;
}
template <class T> inline bool chmin(T &x, T y) {
if (x > y) {
x = y;
return true;
}
return false;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
ll k;
cin >> n >> k;
vector<ll> a(n);
for (int i = 0; i < n; ++i)
cin >> a[i];
ll x = 0;
for (int d = 40; d >= 0; --d) {
int zero = 0, one = 0;
for (int i = 0; i < n; ++i) {
if ((a[i] >> d) & 1)
++one;
else
++zero;
}
if (zero > one) {
if (x + (1LL << d) <= k) {
x += 1LL << d;
}
}
}
ll ans = 0;
for (int i = 0; i < n; ++i)
ans += a[i] ^ x;
cout << ans << endl;
} | [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 938,865 | 938,866 | u190018920 | cpp |
p03138 | // 嘘解法
// 4 8
// 0 0 8 8
// とかで嘘の答え出す
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <stack>
#include <vector>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int INF = pow(2, 29);
const int MOD = 1000000007;
int main() {
ll N, K;
cin >> N >> K;
ll A[N];
rep(i, N) cin >> A[i];
ll t_bit[50] = {};
rep(i, N) rep(j, 50) t_bit[j] += ((A[i] >> j) & 1);
bool bit[50];
rep(i, 50) bit[i] = !(t_bit[i] >= N / 2);
ll X = 0;
for (int i = 50; i >= 0; i--) {
if (bit[i]) {
ll tmp = X | ((ll)1 << i);
if (tmp <= K)
X = tmp;
}
}
ll result = 0;
rep(i, N) result += X ^ A[i];
cout << result << endl;
return 0;
} | // 嘘解法
// 4 8
// 0 0 8 8
// とかで嘘の答え出す
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <stack>
#include <vector>
#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int INF = pow(2, 29);
const int MOD = 1000000007;
int main() {
ll N, K;
cin >> N >> K;
ll A[N];
rep(i, N) cin >> A[i];
ll t_bit[50] = {};
rep(i, N) rep(j, 50) t_bit[j] += ((A[i] >> j) & 1);
bool bit[50];
rep(i, 50) bit[i] = !(t_bit[i] > (N - 1) / 2);
ll X = 0;
for (int i = 50; i >= 0; i--) {
if (bit[i]) {
ll tmp = X | ((ll)1 << i);
if (tmp <= K)
X = tmp;
}
}
ll result = 0;
rep(i, N) result += X ^ A[i];
cout << result << endl;
return 0;
} | [
"expression.operator.compare.change",
"assignment.value.change",
"expression.operation.binary.change"
] | 938,870 | 938,871 | u680707192 | cpp |
p03138 | #include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repr(i, s, e) for (ll i = s; i >= e; i--)
#define reps(i, s, e) for (ll i = s; i <= e; i++)
#define inf 1e18
#define all(v) v.begin(), v.end()
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define sz(x) x.size()
#define ceil(a, b) (a + b - 1) / b
#define ok cout << "ok" << endl;
#define sp << " " <<
using namespace std;
template <typename T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T> inline bool chmin(T &a, T b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template <typename T> T gcd(T a, T b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
template <typename T> T lcm(T a, T b) { return a * (b / gcd(a, b)); }
template <typename T> void vdebug(vector<T> v) {
for (auto vv : v) {
cout << vv << " ";
}
cout << endl;
}
template <typename T> void adebug(T arr[], ll n) {
rep(i, n) { cout << arr[i] << " "; }
cout << endl;
}
void ans(bool b) {
if (b)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
void ans2(bool b) {
if (b)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
ll keta(ll num) {
ll k = 0;
while (num > 0) {
num /= 10;
k++;
}
return k;
}
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll n, k;
ll a[100010];
cin >> n >> k;
rep(i, n) { cin >> a[i]; }
ll x = 0;
reps(j, 0, 50) {
ll sum = 0;
rep(i, n) {
if (a[i] & (1LL << j))
sum++;
}
if (sum * 2 < n)
x |= (1LL << j);
if (x > k)
x &= ~(1LL << j);
}
ll res = 0;
rep(i, n) { res += x ^ a[i]; }
cout << res << endl;
return 0;
}
| #include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repr(i, s, e) for (ll i = s; i >= e; i--)
#define reps(i, s, e) for (ll i = s; i <= e; i++)
#define inf 1e18
#define all(v) v.begin(), v.end()
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define sz(x) x.size()
#define ceil(a, b) (a + b - 1) / b
#define ok cout << "ok" << endl;
#define sp << " " <<
using namespace std;
template <typename T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T> inline bool chmin(T &a, T b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template <typename T> T gcd(T a, T b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
template <typename T> T lcm(T a, T b) { return a * (b / gcd(a, b)); }
template <typename T> void vdebug(vector<T> v) {
for (auto vv : v) {
cout << vv << " ";
}
cout << endl;
}
template <typename T> void adebug(T arr[], ll n) {
rep(i, n) { cout << arr[i] << " "; }
cout << endl;
}
void ans(bool b) {
if (b)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
void ans2(bool b) {
if (b)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
ll keta(ll num) {
ll k = 0;
while (num > 0) {
num /= 10;
k++;
}
return k;
}
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll n, k;
ll a[100010];
cin >> n >> k;
rep(i, n) { cin >> a[i]; }
ll x = 0;
repr(j, 50, 0) {
ll sum = 0;
rep(i, n) {
if (a[i] & (1LL << j))
sum++;
}
if (sum * 2 < n)
x |= (1LL << j);
if (x > k)
x &= ~(1LL << j);
}
ll res = 0;
rep(i, n) { res += x ^ a[i]; }
cout << res << endl;
return 0;
}
| [
"identifier.change",
"call.function.change",
"call.arguments.change",
"call.arguments.add"
] | 938,879 | 938,880 | u026620445 | cpp |
p03138 | /*
vrrtll==???>;::::~~~~~~......`.`````````````````````...-?777!_.._?7u,~~~::::;>>??=lllttrrzu
rtll==??>>;::::~~~~......`.``````````````````
..J77!`````````...`..._T,~~~~:::;;>??==lttrrv
tll=??>>;:::~~~~......``````````````````..J7^ ` `` ` ``
.,```````...._4,.~~~::;;>>?===lttr l=???>;;::~~~......`````HTSu,.`` `..J7! `
`` .J"~N```````````..?&.~~~~::;;>>?==llt
=??>;;::~~~~.....``````.@????7SJ.?= ` ` `` .J=....J;
``````````..h..~~~~::;;>??=ll
?>>;::~~~~.....````````.D?>>?>?>?8+.`` `.J"_......_b`
````````.S_.~~~~::;;>??=l
>;;::~~~~....``````````.C>??>>>?>>>?8J.` ```..Y~..........J; ` ` ```````
G...~~~~::;>??=
;;::~~~....```````` `..W1>>?>>>>?>>>>>?S,.`.7^.............-N`` `
``````` 6...~~~~::;>??
;:~~~~....``````` ..7` d??>>?>?>>?>>?>>1udMgggNNNNggJ.......([
`````.L...~~~~::;>?
:~~~.....`````` .7` `K>?>?>>>>>>+ugNMMMB""7<!~~<?7TWMNNa,..w.` ` ` `
`````,)....~~:::;>
~~~....``````.J^ ` #>>?>>>?jgMMM9=_................-?TMMa,b` ` ` `
````(,...~~~~:;;
~~~....``` .7`` ` @?>>?1uMM#=.........................(TMNa...... `
``````4....~~~::;
~~~...`` .=`` ` `
.b>>jgNH".................`.............?HNmx??17TYY9SA+(..L....~~~::
~....` ,^`` ` `
.b+dN#^............6..-(,-...`............(HMm+>>>>>?>>????zOM_.~~~::
.... .=``` `` `
...JNMM^..........`..._n.(MMN,....`..`.........?MNe<>>?>??>????d^...~~~:
~...v```` `
..-Z""!_..(M@_........`........?7MMMMp.................-TNN+?>>>????1d4-..-(Jk9
..(^`...zY"!_........(MD..............`......JMMMMp....`..`..`......./MNx>??>>?1d!.h7=~(??=
(v_`,R_.............(NF..(/..(&,...`..........?MMMM;..................(MMs>>?1&T"!``....(1=
t..``
4,...........(N@....?,(NMNR_.....`..`....(WMM$..`....`..`..`....._HMe7=```````....~_1
...````.4,........-dM:.....(7MMMNR-.....................`............(.?^ ``
``````....~~~
...``````,4,....`.(NF........(MMMMb..`....--................`....(.7! `
````....~~:
..````` ` `.5J_...JMt.........?NMMM[...`.HH5._(J7[...`...`...--?^` `
`````....~~~:
...````` ` ` 7a,.dM{....`...../MMMN......(J=` .>......._(/= ` `
`````...~~~:
....```` `` (4MN{..........._7"^...(/^ `.C....-(J=` ` `
```....~~~:
....````` ` JdM[...`...`........`_3.. ..?!..(-7! ` `
``````....~~~:: r...`````` ` ``(CJMb..............`......__..-(?^ ` `
`````....~~::; J/...````` ` `,3>+MN-.`..`...`..........._(J=`` ` `
```````....~~~::; _j,..`.```` ``.5>>?dNb...`......`......_-?'` `
`````....~~~::;;
~~j,..```````.D??>>>MM/....`........(-=` ` ` `
```````...~~~:::;>
~~~j,...````.E??>??>?MN-.........(J= ` ` `
``````....~~~~::;??
:~~~?,...``.@>?>?>>??dMN_....-(?^ ` ` ` `
````````...~~~~:;;>??
::~~~?/....K??????>>?>dMN-_(7! ` ` `
````````....~~~:::>>??l
;:::~~/e.(K==?????????<dM"! ` ` ` ` ``
``````...~~~~:::;>??=l
*/
#include "bits/stdc++.h"
using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, s, n) for (int i = (s); i < (n); ++i)
#define repr(i, n) for (int i = n - 1; i >= 0; --i)
#define REPR(i, s, n) for (int i = (s); i >= (n); --(i))
#define all(a) (a).begin(), (a).end()
#define reall(a) (a).rbegin(), (a).rend()
#define pb emplace_back // emplace_backの方が速いが使い慣れてないため
#define pf push_front
#define MIN(a, b) a = min((a), (b))
#define MAX(a, b) a = max((a), (b))
#define SIZE(v) (int)v.size()
#define DOUBLE fixed << setprecision(15)
#define fi first
#define se second
#define mp make_pair
#define BIT(n, m) (((n) >> (m)) & 1)
const double pi = acos(-1.0);
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
typedef vector<P> vP;
const ll mod = 1e9 + 7;
// const ll mod = 998244353;
ll dy[4] = {1, 0, -1, 0};
ll dx[4] = {0, 1, 0, -1};
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T> struct edge {
int src, to;
T cost;
edge(int to, T cost) : src(-1), to(to), cost(cost) {}
edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
edge &operator=(const int &x) {
to = x;
return *this;
}
operator int() const { return to; }
};
template <typename T> using Edges = vector<edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template <typename T> using Matrix = vector<vector<T>>;
bool out_check(ll a, ll b) {
if (0 <= a && a < b)
return true;
else
return false;
}
void addmod(ll &a, ll &b) { a = (a + b) % mod; }
void Pvll(vll v) {
puts("vll------------------------------------------------");
rep(i, v.size()) cout << v[i] << " ";
puts("");
puts("------------------------------------------------");
}
void Pvvll(vvll v) {
puts("vvll------------------------------------------------");
rep(i, v.size()) {
rep(j, v[i].size()) { cout << v[i][j] << " "; }
cout << endl;
}
puts("------------------------------------------------");
}
void Pvs(vs s) {
puts("vs------------------------------------------------");
rep(i, s.size()) {
rep(j, s[i].size()) { cout << s[i][j] << " "; }
cout << endl;
}
puts("------------------------------------------------");
}
void Yes(bool x) {
if (x)
cout << "Yes\n";
else
cout << "No\n";
}
void YES(bool x) {
if (x)
cout << "YES\n";
else
cout << "NO\n";
}
void yes(bool x) {
if (x)
cout << "yes\n";
else
cout << "no\n";
}
void Yay(bool x) {
if (x)
cout << "Yay!\n";
else
cout << ":(\n";
}
ll n, m, d, r, l, k, h, ans, ret = M;
bool flag = false, flag2 = false, flag3 = false;
string s, t, u;
void INIT() {
cin.tie(0);
ios::sync_with_stdio(false);
}
int main() {
INIT(); // not intaractive
cin >> n >> k;
vll bit(60, 0), v(n);
rep(i, n) {
ll x;
cin >> x;
v[i] = x;
rep(j, 60) bit[j] += BIT(x, j);
}
repr(i, 60) {
if (d ^ (1LL << i) <= k) {
if (bit[i] < n - bit[i]) {
bit[i] = n - bit[i];
d ^= 1LL << i;
}
}
}
for (auto p : v)
ans += d ^ p;
cout << ans << endl;
return 0;
} | /*
vrrtll==???>;::::~~~~~~......`.`````````````````````...-?777!_.._?7u,~~~::::;>>??=lllttrrzu
rtll==??>>;::::~~~~......`.``````````````````
..J77!`````````...`..._T,~~~~:::;;>??==lttrrv
tll=??>>;:::~~~~......``````````````````..J7^ ` `` ` ``
.,```````...._4,.~~~::;;>>?===lttr l=???>;;::~~~......`````HTSu,.`` `..J7! `
`` .J"~N```````````..?&.~~~~::;;>>?==llt
=??>;;::~~~~.....``````.@????7SJ.?= ` ` `` .J=....J;
``````````..h..~~~~::;;>??=ll
?>>;::~~~~.....````````.D?>>?>?>?8+.`` `.J"_......_b`
````````.S_.~~~~::;;>??=l
>;;::~~~~....``````````.C>??>>>?>>>?8J.` ```..Y~..........J; ` ` ```````
G...~~~~::;>??=
;;::~~~....```````` `..W1>>?>>>>?>>>>>?S,.`.7^.............-N`` `
``````` 6...~~~~::;>??
;:~~~~....``````` ..7` d??>>?>?>>?>>?>>1udMgggNNNNggJ.......([
`````.L...~~~~::;>?
:~~~.....`````` .7` `K>?>?>>>>>>+ugNMMMB""7<!~~<?7TWMNNa,..w.` ` ` `
`````,)....~~:::;>
~~~....``````.J^ ` #>>?>>>?jgMMM9=_................-?TMMa,b` ` ` `
````(,...~~~~:;;
~~~....``` .7`` ` @?>>?1uMM#=.........................(TMNa...... `
``````4....~~~::;
~~~...`` .=`` ` `
.b>>jgNH".................`.............?HNmx??17TYY9SA+(..L....~~~::
~....` ,^`` ` `
.b+dN#^............6..-(,-...`............(HMm+>>>>>?>>????zOM_.~~~::
.... .=``` `` `
...JNMM^..........`..._n.(MMN,....`..`.........?MNe<>>?>??>????d^...~~~:
~...v```` `
..-Z""!_..(M@_........`........?7MMMMp.................-TNN+?>>>????1d4-..-(Jk9
..(^`...zY"!_........(MD..............`......JMMMMp....`..`..`......./MNx>??>>?1d!.h7=~(??=
(v_`,R_.............(NF..(/..(&,...`..........?MMMM;..................(MMs>>?1&T"!``....(1=
t..``
4,...........(N@....?,(NMNR_.....`..`....(WMM$..`....`..`..`....._HMe7=```````....~_1
...````.4,........-dM:.....(7MMMNR-.....................`............(.?^ ``
``````....~~~
...``````,4,....`.(NF........(MMMMb..`....--................`....(.7! `
````....~~:
..````` ` `.5J_...JMt.........?NMMM[...`.HH5._(J7[...`...`...--?^` `
`````....~~~:
...````` ` ` 7a,.dM{....`...../MMMN......(J=` .>......._(/= ` `
`````...~~~:
....```` `` (4MN{..........._7"^...(/^ `.C....-(J=` ` `
```....~~~:
....````` ` JdM[...`...`........`_3.. ..?!..(-7! ` `
``````....~~~:: r...`````` ` ``(CJMb..............`......__..-(?^ ` `
`````....~~::; J/...````` ` `,3>+MN-.`..`...`..........._(J=`` ` `
```````....~~~::; _j,..`.```` ``.5>>?dNb...`......`......_-?'` `
`````....~~~::;;
~~j,..```````.D??>>>MM/....`........(-=` ` ` `
```````...~~~:::;>
~~~j,...````.E??>??>?MN-.........(J= ` ` `
``````....~~~~::;??
:~~~?,...``.@>?>?>>??dMN_....-(?^ ` ` ` `
````````...~~~~:;;>??
::~~~?/....K??????>>?>dMN-_(7! ` ` `
````````....~~~:::>>??l
;:::~~/e.(K==?????????<dM"! ` ` ` ` ``
``````...~~~~:::;>??=l
*/
#include "bits/stdc++.h"
using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, s, n) for (int i = (s); i < (n); ++i)
#define repr(i, n) for (int i = n - 1; i >= 0; --i)
#define REPR(i, s, n) for (int i = (s); i >= (n); --(i))
#define all(a) (a).begin(), (a).end()
#define reall(a) (a).rbegin(), (a).rend()
#define pb emplace_back // emplace_backの方が速いが使い慣れてないため
#define pf push_front
#define MIN(a, b) a = min((a), (b))
#define MAX(a, b) a = max((a), (b))
#define SIZE(v) (int)v.size()
#define DOUBLE fixed << setprecision(15)
#define fi first
#define se second
#define mp make_pair
#define BIT(n, m) (((n) >> (m)) & 1)
const double pi = acos(-1.0);
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
typedef vector<P> vP;
const ll mod = 1e9 + 7;
// const ll mod = 998244353;
ll dy[4] = {1, 0, -1, 0};
ll dx[4] = {0, 1, 0, -1};
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T> struct edge {
int src, to;
T cost;
edge(int to, T cost) : src(-1), to(to), cost(cost) {}
edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
edge &operator=(const int &x) {
to = x;
return *this;
}
operator int() const { return to; }
};
template <typename T> using Edges = vector<edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template <typename T> using Matrix = vector<vector<T>>;
bool out_check(ll a, ll b) {
if (0 <= a && a < b)
return true;
else
return false;
}
void addmod(ll &a, ll &b) { a = (a + b) % mod; }
void Pvll(vll v) {
puts("vll------------------------------------------------");
rep(i, v.size()) cout << v[i] << " ";
puts("");
puts("------------------------------------------------");
}
void Pvvll(vvll v) {
puts("vvll------------------------------------------------");
rep(i, v.size()) {
rep(j, v[i].size()) { cout << v[i][j] << " "; }
cout << endl;
}
puts("------------------------------------------------");
}
void Pvs(vs s) {
puts("vs------------------------------------------------");
rep(i, s.size()) {
rep(j, s[i].size()) { cout << s[i][j] << " "; }
cout << endl;
}
puts("------------------------------------------------");
}
void Yes(bool x) {
if (x)
cout << "Yes\n";
else
cout << "No\n";
}
void YES(bool x) {
if (x)
cout << "YES\n";
else
cout << "NO\n";
}
void yes(bool x) {
if (x)
cout << "yes\n";
else
cout << "no\n";
}
void Yay(bool x) {
if (x)
cout << "Yay!\n";
else
cout << ":(\n";
}
ll n, m, d, r, l, k, h, ans, ret = M;
bool flag = false, flag2 = false, flag3 = false;
string s, t, u;
void INIT() {
cin.tie(0);
ios::sync_with_stdio(false);
}
int main() {
INIT(); // not intaractive
cin >> n >> k;
vll bit(60, 0), v(n);
rep(i, n) {
ll x;
cin >> x;
v[i] = x;
rep(j, 60) bit[j] += BIT(x, j);
// rep(j,60)if (x & (1ll << j)) bit[j]++;
}
// Pvll(bit);
repr(i, 60) {
if ((d ^ (1LL << i)) <= k) {
if (bit[i] < n - bit[i]) {
bit[i] = n - bit[i];
d ^= (1LL << i);
}
}
}
for (auto p : v)
ans += d ^ p;
cout << ans << endl;
return 0;
} | [
"control_flow.branch.if.condition.change"
] | 938,886 | 938,887 | u373958718 | cpp |
p03138 | #include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for (ll i = m, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define clr(ar, val) memset(ar, val, sizeof(ar))
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef long double ld;
int f(ll k) {
if (k == 0)
return 0;
int a = 1;
while (k >>= 1)
a++;
return a;
}
int main(void) {
ll n, k, num[64] = {};
cin >> n >> k;
rep(i, n) {
ll a;
cin >> a;
rep(j, 64) num[j] += (int)((a & (1LL << j)) != 0);
}
ll ans = 0, tmp = 0;
for (int i = f(k) - 1; i >= 0; i--) {
tmp = 0;
if ((k & (1LL << i)) == 0)
continue;
// cout << i << " ";
for (int j = 63; j >= 0; j--) {
if (i < j) {
if ((k & (1LL << j)) != 0)
tmp += (n - num[j]) << j;
else
tmp += num[j] << j;
} else if (i == j) {
tmp += num[j] << j;
} else {
tmp += max(num[j], n - num[j]) << j;
}
/* if (i < j) {
cout << ((k & (1LL << j)) != 0);
// if (k & (1LL << j) != 0) cout << (n -
num[j]);
// else cout << num[j];
} else if (i == j) {
cout << 0;
// cout << num[j];
} else {
cout << "x";
// cout << max(num[j], n - num[j]);
} */
}
// cout << endl;
chmax(ans, tmp);
// cout << endl << i << " " << tmp << endl;
// cout << endl;
}
tmp = 0;
for (int j = 63; j >= 0; j--) {
if (k & (1 << j) != 0)
tmp += (n - num[j]) << j;
else
tmp += num[j] << j;
}
chmax(ans, tmp);
cout << ans << endl;
// rep(j,64)cout<<num[63-j];cout<<endl;
return 0;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for (ll i = m, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define clr(ar, val) memset(ar, val, sizeof(ar))
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef long double ld;
int f(ll k) {
if (k == 0)
return 0;
int a = 1;
while (k >>= 1)
a++;
return a;
}
int main(void) {
ll n, k, num[64] = {};
cin >> n >> k;
rep(i, n) {
ll a;
cin >> a;
rep(j, 64) num[j] += (int)((a & (1LL << j)) != 0);
}
ll ans = 0, tmp = 0;
for (int i = f(k) - 1; i >= 0; i--) {
tmp = 0;
if ((k & (1LL << i)) == 0)
continue;
// cout << i << " ";
for (int j = 63; j >= 0; j--) {
if (i < j) {
if ((k & (1LL << j)) != 0)
tmp += (n - num[j]) << j;
else
tmp += num[j] << j;
} else if (i == j) {
tmp += num[j] << j;
} else {
tmp += max(num[j], n - num[j]) << j;
}
/* if (i < j) {
if ((k & (1LL << j)) != 0) cout << (n -
num[j]); else cout << num[j]; } else if (i == j) { cout << num[j]; }
else { cout << max(num[j], n - num[j]);
} */
}
// cout << endl;
// cout << tmp << endl;
chmax(ans, tmp);
// cout << endl << i << " " << tmp << endl;
// cout << endl;
}
tmp = 0;
for (int j = 63; j >= 0; j--) {
if ((k & (1LL << j)) != 0)
tmp += (n - num[j]) << j;
else
tmp += num[j] << j;
// if ((k & (1LL << j)) != 0) cout << n - num[j];
// else cout << num[j];
}
// cout << endl;
// cout << tmp << endl;
chmax(ans, tmp);
cout << ans << endl;
// rep(j,64)cout<<num[63-j];cout<<endl;
return 0;
} | [
"control_flow.branch.if.condition.change"
] | 938,890 | 938,891 | u617380180 | cpp |
p03138 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
ll xorsum(ll x, vector<ll> &a) {
ll sum = 0;
for (ll i : a) {
sum += x ^ i;
}
return sum;
}
ll countBits(ll bit, vector<ll> &a) {
ll count = 0;
for (ll i : a)
if ((1ll << bit) & i)
count++;
return count;
}
int main() {
ll n, k;
cin >> n >> k;
vector<ll> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
ll shift = 62;
ll x = 0;
while (1ll << shift > k)
shift--;
while (shift >= 0) {
ll onBits = countBits(shift, a);
if (onBits * 2 <= a.size())
if (x + (1ll << shift) < k)
x += (1ll << shift);
shift--;
}
cout << xorsum(x, a) << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
ll xorsum(ll x, vector<ll> &a) {
ll sum = 0;
// cout << x << '\t' << bitset<8>(x) << endl;
for (ll i : a) {
sum += x ^ i;
// cout << i << '\t' << bitset<8>(i) << endl;
}
// cout << "---" << endl;
// cout << sum << '\t' << bitset<8>(sum) << endl << endl;
return sum;
}
ll countBits(ll bit, vector<ll> &a) {
ll count = 0;
for (ll i : a)
if ((1ll << bit) & i)
count++;
return count;
}
int main() {
ll n, k;
cin >> n >> k;
vector<ll> a(n);
for (ll i = 0; i < n; i++)
cin >> a[i];
ll shift = 62;
ll x = 0;
while (1ll << shift > k)
shift--;
while (shift >= 0) {
ll onBits = countBits(shift, a);
if (onBits * 2 <= a.size())
if (x + (1ll << shift) <= k)
x += (1ll << shift);
shift--;
}
cout << xorsum(x, a) << endl;
return 0;
} | [
"control_flow.loop.for.initializer.change",
"variable_declaration.type.change",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 938,892 | 938,893 | u777068250 | cpp |
p03138 | #include <algorithm>
#include <bitset>
#include <cassert>
#include <ciso646>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#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 long long ul;
typedef unsigned int ui;
typedef long double ld;
const ll mod = 1000000007;
const ll INF = mod * mod;
#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<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;
#define fr first
#define sc second
#define all(c) c.begin(), c.end()
#define pb push_back
//#define int long long
void solve() {
int N;
cin >> N;
ll K;
cin >> K;
ll A[100100];
rep(i, N) { cin >> A[i]; }
ll res = 0;
per(k, 50) {
//大きいものから優先すべし
//小さいものからとってもしょうがない
int cnt = 0;
rep(i, N) {
if (A[i] & (1 << k))
cnt++;
}
if (cnt <= N / 2 && res + (1 << k) <= K) {
res += (1 << k);
}
}
ll ans = 0;
rep(i, N) { ans += (res ^ A[i]); }
cout << ans << endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
// cout << fixed << setprecision(10);
// init();
solve();
// cout << "finish" << endl;
return 0;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <ciso646>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#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 long long ul;
typedef unsigned int ui;
typedef long double ld;
const ll mod = 1000000007;
const ll INF = mod * mod;
#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<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;
#define fr first
#define sc second
#define all(c) c.begin(), c.end()
#define pb push_back
//#define int long long
void solve() {
int N;
cin >> N;
ll K;
cin >> K;
ll A[100100];
rep(i, N) { cin >> A[i]; }
ll res = 0;
per(k, 50) {
//大きいものから優先すべし
//小さいものからとってもしょうがない
int cnt = 0;
rep(i, N) {
if ((ll)A[i] & (1LL << k))
cnt++;
}
if (cnt <= N / 2 && res + (1LL << k) <= K) {
res += (1LL << k);
}
}
ll ans = 0;
rep(i, N) { ans += (res ^ A[i]); }
cout << ans << endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
// cout << fixed << setprecision(10);
// init();
solve();
// cout << "finish" << endl;
return 0;
} | [
"control_flow.branch.if.condition.change",
"literal.number.type.widen.change"
] | 938,896 | 938,897 | u508571192 | cpp |
p03138 | #include <bits/stdc++.h>
#ifndef ONLINE_JUDGE
#define W(x, y) cerr << "\033[31m" << #x << " = " << x << "\033[0m" << y;
#else
#define W(x, y)
#endif
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vii vector<pii>
#define vl vector<ll>
#define vll vector<pll>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pi acos(-1)
#define ld long double
#define prime 1000000007
using namespace std;
#define INF 1000000000
ll f(ll n) {
ll res = 0;
for (int i = 0; i < n; ++i) {
if (n & (1 << i)) {
res = i;
}
}
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll n, k;
cin >> n >> k;
vl vet1(n);
for (int i = 0; i < n; ++i) {
cin >> vet1[i];
}
vl vet2(62);
for (int i = 0; i < n; ++i) {
for (ll j = 0, l = 1; j < 60; ++j, l <<= 1) {
vet2[j] += ((vet1[i] & l) != 0);
}
}
ll pres = 0, state = 0, uBit = f(k);
for (ll i = uBit, j = 1 << uBit; i >= 0; --i, j >>= 1) {
if (vet2[i] * 2 < n && (pres | j) < k) {
pres |= j;
}
}
W(pres, endl)
ll res = 0;
for (int i = 0; i < n; ++i) {
res += (vet1[i] ^ pres);
}
cout << res << endl;
return 0;
} | #include <bits/stdc++.h>
#ifndef ONLINE_JUDGE
#define W(x, y) cerr << "\033[31m" << #x << " = " << x << "\033[0m" << y;
#else
#define W(x, y)
#endif
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vii vector<pii>
#define vl vector<ll>
#define vll vector<pll>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pi acos(-1)
#define ld long double
#define prime 1000000007
using namespace std;
#define INF 1000000000
ll f(ll n) {
ll res = 0;
for (int i = 0; i < n; ++i) {
if (n & (1 << i)) {
res = i;
}
}
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll n, k;
cin >> n >> k;
vl vet1(n);
for (int i = 0; i < n; ++i) {
cin >> vet1[i];
}
vl vet2(62);
for (int i = 0; i < n; ++i) {
for (ll j = 0, l = 1; j < 60; ++j, l <<= 1) {
vet2[j] += ((vet1[i] & l) != 0);
}
}
ll pres = 0, state = 0, uBit = f(k);
for (ll i = 60, j = 1LL << 60; i >= 0; --i, j >>= 1) {
if (vet2[i] * 2 < n && (pres | j) <= k) {
pres |= j;
}
}
W(pres, endl)
ll res = 0;
for (int i = 0; i < n; ++i) {
res += (vet1[i] ^ pres);
}
cout << res << endl;
return 0;
} | [
"variable_declaration.value.change",
"identifier.replace.remove",
"literal.replace.add",
"control_flow.loop.for.initializer.change",
"literal.number.type.widen.change",
"expression.operation.binary.change",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 938,898 | 938,899 | u218547786 | cpp |
p03138 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i, a, n) for (int(i) = (a); (i) < (n); (i)++)
#define eFOR(i, a, n) for (int(i) = (a); (i) <= (n); (i)++)
#define rFOR(i, a, n) for (int(i) = (n)-1; (i) >= (a); (i)--)
#define erFOR(i, a, n) for (int(i) = (n); (i) >= (a); (i)--)
#define SORT(i) sort((i).begin(), (i).end())
#define rSORT(i, a) sort((i).begin(), (i).end(), (a))
#define all(i) (i).begin(), (i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
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;
}
inline void init() {
cin.tie(nullptr);
cout.tie(nullptr);
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
}
template <class T> inline istream &operator>>(istream &input, vector<T> &v) {
for (auto &elemnt : v)
input >> elemnt;
return input;
}
int main() {
init();
int n;
ll K;
cin >> n >> K;
VL a(n);
cin >> a;
string k = "";
while (K) {
k += to_string(K % 2);
K /= 2;
}
while (k.length() < 40)
k += '0';
reverse(all(k));
int len = k.length();
VI bit(40, 0);
FOR(i, 0, n) {
ll b = a[i];
for (int j = 0; b; j++) {
bit[j] += b % 2;
b /= 2;
}
}
reverse(all(bit));
vector<VL> dp(41, VL(2, -1));
dp[0][0] = 0;
FOR(i, 0, 40) FOR(small, 0, 2) {
if (dp[i][small] == -1)
continue;
eFOR(x, 0, k[i] - '0') {
ll num = (1LL << (40 - i - 1)) * (ll)(x ? n - bit[i] : bit[i]);
chmax(dp[i + 1][small || x < k[i] - '0'], dp[i][small] + num);
}
}
cout << max(dp[40][0], dp[40][1]) << "\n";
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i, a, n) for (int(i) = (a); (i) < (n); (i)++)
#define eFOR(i, a, n) for (int(i) = (a); (i) <= (n); (i)++)
#define rFOR(i, a, n) for (int(i) = (n)-1; (i) >= (a); (i)--)
#define erFOR(i, a, n) for (int(i) = (n); (i) >= (a); (i)--)
#define SORT(i) sort((i).begin(), (i).end())
#define rSORT(i, a) sort((i).begin(), (i).end(), (a))
#define all(i) (i).begin(), (i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
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;
}
inline void init() {
cin.tie(nullptr);
cout.tie(nullptr);
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
}
template <class T> inline istream &operator>>(istream &input, vector<T> &v) {
for (auto &elemnt : v)
input >> elemnt;
return input;
}
int main() {
init();
int n;
ll K;
cin >> n >> K;
VL a(n);
cin >> a;
string k = "";
while (K) {
k += to_string(K % 2);
K /= 2;
}
while (k.length() < 40)
k += '0';
reverse(all(k));
int len = k.length();
VI bit(40, 0);
FOR(i, 0, n) {
ll b = a[i];
for (int j = 0; b; j++) {
bit[j] += b % 2;
b /= 2;
}
}
reverse(all(bit));
vector<VL> dp(41, VL(2, -1));
dp[0][0] = 0;
FOR(i, 0, 40) FOR(small, 0, 2) {
if (dp[i][small] == -1)
continue;
eFOR(x, 0, (small ? 1 : k[i] - '0')) {
ll num = (1LL << (40 - i - 1)) * (ll)(x ? n - bit[i] : bit[i]);
chmax(dp[i + 1][small || x < k[i] - '0'], dp[i][small] + num);
}
}
cout << max(dp[40][0], dp[40][1]) << "\n";
}
| [
"call.arguments.change"
] | 938,900 | 938,901 | u863044225 | cpp |
p03138 | #include <bits/stdc++.h>
#define err(args...) \
{}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream &operator>>(istream &is, vector<T> &a) {
for (T &x : a) {
is >> x;
}
return is;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
ll k;
cin >> n >> k;
vector<ll> a(n);
cin >> a;
ll x = 0;
for (int i = 40; i >= 0; i--) {
int count0 = 0, count1 = 0;
for (ll ai : a) {
count0 += not bool(ai & (1ll << i));
count1 += bool(ai & (1ll << i));
}
ll y = x | (ll(count0 > count1) << i);
if (y < k) {
x = y;
}
}
ll ans = 0;
for (ll ai : a) {
ans += x ^ ai;
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define err(args...) \
{}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream &operator>>(istream &is, vector<T> &a) {
for (T &x : a) {
is >> x;
}
return is;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
ll k;
cin >> n >> k;
vector<ll> a(n);
cin >> a;
ll x = 0;
for (int i = 40; i >= 0; i--) {
int count0 = 0, count1 = 0;
for (ll ai : a) {
count0 += not bool(ai & (1ll << i));
count1 += bool(ai & (1ll << i));
}
ll y = x | (ll(count0 > count1) << i);
if (y <= k) {
x = y;
}
}
ll ans = 0;
for (ll ai : a) {
ans += x ^ ai;
}
cout << ans << endl;
return 0;
}
| [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 938,904 | 938,905 | u957513998 | cpp |
p03138 | #include <algorithm>
#include <cmath>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define MOD 1000000007
#define INF 1 << 30
#define LINF (ll)1 << 62
#define MAX 510000
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define REP(i, a, b) for (ll i = (a); i < (b); i++)
#define all(x) (x).begin(), (x).end()
#define uni(q) unique(all(q)), q.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;
vl bit(40, 0), fun(40), sum(41, 0);
ll n, k;
ll rec(ll K, ll kbit) {
if (K <= 0)
return 0;
kbit--;
if (K >= (1LL << kbit))
return max(fun[kbit] + rec(K - (1LL << kbit), kbit), sum[kbit]);
return rec(K, kbit);
}
int main() {
cin >> n >> k;
ll mxbit = 0;
ll s = 0;
rep(i, n) {
ll a;
cin >> a;
s += a;
ll keta = 0;
while (a > 0) {
if (a % 2 == 1)
bit[keta]++;
a /= 2;
keta++;
mxbit = max(mxbit, keta);
}
}
if (k == 0) {
cout << s << endl;
return 0;
}
ll kbit = 0;
while (k > (1LL << kbit)) {
kbit++;
}
mxbit = max(mxbit, kbit);
rep(i, mxbit) fun[i] = (n - 2 * bit[i]) * 1 << i;
// rep(i,mxbit) cout << fun[i] << " ";
rep(i, mxbit) sum[i + 1] = sum[i] + max(0LL, fun[i]);
// rep(i,mxbit+1) cout << sum[i] << " ";
// cout << kbit << endl;
cout << rec(k, kbit) + s << endl;
}
| #include <algorithm>
#include <cmath>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define MOD 1000000007
#define INF 1 << 30
#define LINF (ll)1 << 62
#define MAX 510000
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define REP(i, a, b) for (ll i = (a); i < (b); i++)
#define all(x) (x).begin(), (x).end()
#define uni(q) unique(all(q)), q.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;
vl bit(40, 0), fun(40), sum(41, 0);
ll n, k;
ll rec(ll K, ll kbit) {
if (K <= 0)
return 0;
kbit--;
if (K >= (1LL << kbit))
return max(fun[kbit] + rec(K - (1LL << kbit), kbit), sum[kbit]);
return rec(K, kbit);
}
int main() {
cin >> n >> k;
ll mxbit = 0;
ll s = 0;
rep(i, n) {
ll a;
cin >> a;
s += a;
ll keta = 0;
while (a > 0) {
if (a % 2 == 1)
bit[keta]++;
a /= 2;
keta++;
mxbit = max(mxbit, keta);
}
}
if (k == 0) {
cout << s << endl;
return 0;
}
ll kbit = 0;
while (k >= (1LL << kbit)) {
kbit++;
}
mxbit = max(mxbit, kbit);
rep(i, mxbit) fun[i] = (n - 2 * bit[i]) * 1 << i;
// rep(i,mxbit) cout << fun[i] << " ";
rep(i, mxbit) sum[i + 1] = sum[i] + max(0LL, fun[i]);
// rep(i,mxbit+1) cout << sum[i] << " ";
// cout << kbit << endl;
cout << rec(k, kbit) + s << endl;
}
| [
"expression.operator.compare.change",
"control_flow.loop.condition.change"
] | 938,914 | 938,915 | u242679311 | cpp |
p03138 | #include <algorithm> // sort
#include <cstring>
#include <fstream>
#include <iostream>
#include <vector>
#define REP(i, n) for (long long i = 0; i < (n); i++)
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;
int main() {
// std::ifstream in("input.txt");
// std::cin.rdbuf(in.rdbuf());
// ios::sync_with_stdio(false);
// cin.tie(0);
ll n, k;
cin >> n >> k;
ll a[n];
// 10^12が最高なので、
ll b[42] = {};
REP(i, n) { cin >> a[i]; }
REP(i, n) {
ll j = 0;
while (a[i] >= (1ull << j)) {
// bit立ってるなら
if (a[i] & (1ull << j)) {
++b[j];
}
++j;
}
}
ll num = 0;
for (int i = 41; i >= 0; --i) {
ll tmp = 1;
for (int j = 0; j < i; ++j)
tmp *= 2;
if (tmp > k)
continue;
// 1のが少ないならnumのbitを1にしたほうがよい
if (n - 2 * b[i] > 0) {
num += tmp;
}
}
ll res = 0;
REP(i, n) {
// xorを求める
ll tmp;
tmp = num ^ a[i];
res += tmp;
}
cout << res << endl;
return 0;
}
| #include <algorithm> // sort
#include <cstring>
#include <fstream>
#include <iostream>
#include <vector>
#define REP(i, n) for (long long i = 0; i < (n); i++)
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;
int main() {
// std::ifstream in("input.txt");
// std::cin.rdbuf(in.rdbuf());
// ios::sync_with_stdio(false);
// cin.tie(0);
ll n, k;
cin >> n >> k;
ll a[n];
// 10^12が最高なので、
ll b[42] = {};
REP(i, n) { cin >> a[i]; }
REP(i, n) {
ll j = 0;
while (a[i] >= (1ull << j)) {
// bit立ってるなら
if (a[i] & (1ull << j)) {
++b[j];
}
++j;
}
}
ll num = 0;
for (int i = 41; i >= 0; --i) {
ll tmp = 1;
for (int j = 0; j < i; ++j)
tmp *= 2;
if (tmp + num > k)
continue;
// 1のが少ないならnumのbitを1にしたほうがよい
if (n - 2 * b[i] > 0) {
num += tmp;
}
}
ll res = 0;
REP(i, n) {
// xorを求める
ll tmp;
tmp = num ^ a[i];
res += tmp;
}
cout << res << endl;
return 0;
}
| [
"control_flow.branch.if.condition.change",
"control_flow.loop.for.condition.change"
] | 938,916 | 938,917 | u485731913 | cpp |
p03138 | #include <bits/stdc++.h>
using namespace std;
#define IOS \
ios::sync_with_stdio(false); \
cin.tie(0);
#define FOR(i, s, n) for (int i = s; i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ((n) ? "Yes" : "No") << endl;
#define CFYN(n) cout << ((n) ? "YES" : "NO") << endl;
using ll = long long;
using ull = unsigned long long;
int main(void) {
IOS constexpr int N = 100000;
constexpr int K = 50;
ll n, k;
cin >> n >> k;
vector<bitset<N + 10>> v(K, bitset<N + 10>(0));
REP(i, n) {
ll x;
cin >> x;
int j = 0;
while (x > 0) {
v[j][i] = x % 2;
x /= 2;
j++;
}
}
ll f = 0;
ll ans = 0;
for (auto i = K - 1; i >= 0; i--) {
ll x = 1LL << i;
ll cnt = v[i].count();
if (f + x < k) {
if (cnt < (n + 1) / 2) {
cnt = n - cnt;
f += x;
}
}
ans += cnt * x;
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define IOS \
ios::sync_with_stdio(false); \
cin.tie(0);
#define FOR(i, s, n) for (int i = s; i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ((n) ? "Yes" : "No") << endl;
#define CFYN(n) cout << ((n) ? "YES" : "NO") << endl;
using ll = long long;
using ull = unsigned long long;
int main(void) {
IOS constexpr int N = 100000;
constexpr int K = 50;
ll n, k;
cin >> n >> k;
vector<bitset<N + 10>> v(K, bitset<N + 10>(0));
REP(i, n) {
ll x;
cin >> x;
int j = 0;
while (x > 0) {
v[j][i] = x % 2;
x /= 2;
j++;
}
}
ll f = 0;
ll ans = 0;
for (auto i = K - 1; i >= 0; i--) {
ll x = 1LL << i;
ll cnt = v[i].count();
if (f + x <= k) {
if (cnt < (n + 1) / 2) {
cnt = n - cnt;
f += x;
}
}
ans += cnt * x;
}
cout << ans << endl;
return 0;
} | [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 938,920 | 938,921 | u330661451 | cpp |
p03138 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please
//なんか嘘解法っぽかったので
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll N, K;
cin >> N >> K;
int B[41] = {};
rep(i, N) {
ll A;
cin >> A;
rep(j, 41) {
B[j] += A & 1ll;
A /= 2;
}
}
int K2[41] = {};
rep(i, 41) {
K2[i] = K & 1ll;
K /= 2;
}
int OK = 0;
ll dp[41][2] = {};
rep(i, 41) dp[i][1] = -1;
for (int i = 40; i >= 0; i--) {
int kari = N - B[i];
ll k = (1ll << i);
if (dp[i + 1][1] != -1)
dp[i][1] = max(dp[i][1], dp[i + 1][1] + k * max(B[i], kari));
if (K2[i]) {
dp[i][1] = max(dp[i][1], dp[i + 1][0] + k * B[i]);
dp[i][0] = max(dp[i][0], dp[i + 1][0] + k * kari);
} else {
dp[i][0] = max(dp[i][0], dp[i + 1][0] + k * B[i]);
}
}
co(max(dp[0][0], dp[0][1]));
Would you please return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please
//なんか嘘解法っぽかったので
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll N, K;
cin >> N >> K;
int B[41] = {};
rep(i, N) {
ll A;
cin >> A;
rep(j, 41) {
B[j] += A & 1ll;
A /= 2;
}
}
int K2[41] = {};
rep(i, 41) {
K2[i] = K & 1ll;
K /= 2;
}
int OK = 0;
ll dp[45][2] = {};
rep(i, 45) dp[i][1] = -1;
for (int i = 40; i >= 0; i--) {
int kari = N - B[i];
ll k = (1ll << i);
if (dp[i + 1][1] != -1)
dp[i][1] = max(dp[i][1], dp[i + 1][1] + k * max(B[i], kari));
if (K2[i]) {
dp[i][1] = max(dp[i][1], dp[i + 1][0] + k * B[i]);
dp[i][0] = max(dp[i][0], dp[i + 1][0] + k * kari);
} else {
dp[i][0] = max(dp[i][0], dp[i + 1][0] + k * B[i]);
}
}
co(max(dp[0][0], dp[0][1]));
Would you please return 0;
} | [
"literal.number.change",
"variable_declaration.array_dimensions.change",
"assignment.variable.change",
"call.arguments.change"
] | 938,922 | 938,923 | u096883693 | cpp |
p03138 | #include <bits/stdc++.h>
using namespace std;
// #undef LOCAL
#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif
typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const ll MAX = 1e12;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
// freopen("temp.1", "r", stdin);
int N;
cin >> N;
ll K;
cin >> K;
vector<ll> a(N);
for (int i = 0; i < N; i++) {
cin >> a[i];
}
int B = 40;
dumpv(N, K, B, a);
vector<int> c0(B), c1(B);
for (int i = 0; i < B; i++) {
ll bit = 1LL << i;
for (int j = 0; j < N; j++) {
if (a[j] & bit)
c1[i]++;
else
c0[i]++;
}
}
dumpv(c0);
dumpv(c1);
ll x = 0;
for (int i = B - 1; 0 <= i; i--) {
ll bit = 1LL << i;
if (bit <= K) {
if (c1[i] < c0[i])
x |= bit;
K -= bit;
}
}
dump(x);
ll ans = 0;
for (int i = 0; i < N; i++) {
ans += (a[i] ^ x);
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
// #undef LOCAL
#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif
typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const ll MAX = 1e12;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
// freopen("temp.1", "r", stdin);
int N;
cin >> N;
ll K;
cin >> K;
vector<ll> a(N);
for (int i = 0; i < N; i++) {
cin >> a[i];
}
int B = 40;
dumpv(N, K, B, a);
vector<int> c0(B), c1(B);
for (int i = 0; i < B; i++) {
ll bit = 1LL << i;
for (int j = 0; j < N; j++) {
if (a[j] & bit)
c1[i]++;
else
c0[i]++;
}
}
dumpv(c0);
dumpv(c1);
ll x = 0;
for (int i = B - 1; 0 <= i; i--) {
ll bit = 1LL << i;
if (bit <= K) {
if (c1[i] < c0[i]) {
x |= bit;
K -= bit;
}
}
}
dump(x);
ll ans = 0;
for (int i = 0; i < N; i++) {
ans += (a[i] ^ x);
}
cout << ans << endl;
return 0;
} | [] | 938,924 | 938,925 | u147305315 | cpp |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.