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 |
|---|---|---|---|---|---|---|---|
p03148 | //#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;
//---
template <typename T> inline void print(const T &rhs) {
std::cout << " = " << rhs << std::endl;
}
template <typename T> inline void print(const std::vector<T> &rhs) {
std::cout << " = [ ";
for (uint i = 0; i < rhs.size(); ++i) {
std::cout << rhs[i] << ' ';
}
std::cout << "]" << std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>> &rhs) {
std::cout << " = " << std::endl;
std::cout << "[[ ";
for (uint p = 0; p < rhs.size(); ++p) {
if (p != 0) {
std::cout << " [ ";
}
for (uint q = 0; q < rhs[p].size(); ++q) {
std::cout << rhs[p][q] << ' ';
}
if (p != rhs.size() - 1) {
std::cout << "]" << std::endl;
}
}
std::cout << "]]" << std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR, TL>> &rhs) {
std::cout << " = [";
uint i = 0;
for (; i < rhs.size() - 1; ++i) {
std::cout << "[f: " << rhs[i].first << ", s: " << rhs[i].second << "], ";
}
std::cout << "[f: " << rhs[i].first << ", s: " << rhs[i].second << "]]"
<< endl;
}
#define printn(var) \
{ \
printf("%s", #var); \
print(var); \
}
#define printn_all(var) \
{ \
printf("%s(%d): ", __func__, __LINE__); \
printf("%s", #var); \
print(var); \
}
//---
struct td {
int t;
int d;
};
bool cmp_d(struct td &lhs, struct td &rhs) { return lhs.d < rhs.d; }
bool cmp_gr_d(struct td &lhs, struct td &rhs) { return lhs.d > rhs.d; }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
uint N, K;
cin >> N >> K;
vector<struct td> vTD(N);
for (uint i = 0; i < N; ++i) {
cin >> vTD[i].t >> vTD[i].d;
}
sort(vTD.begin(), vTD.end(), cmp_gr_d);
unordered_map<int, int>
htUN; // a hash table for counting number of used types
vector<struct td> vTD_rm; // for remove
vector<struct td> vTD_add; // for add
int64 sum = 0ll;
for (uint i = 0; i < K; ++i) {
sum += vTD[i].d;
++htUN[vTD[i].t];
if (htUN[vTD[i].t] >= 2) {
vTD_rm.push_back(vTD[i]);
}
}
// sort(vTD_rm.begin(), vTD_rm.end(), cmp_d); // dont need to sort. By
// reversing the iteration to vTD_rm.
for (uint i = K; i < N; ++i) {
if (htUN[vTD[i].t] != 0) {
continue;
}
vTD_add.push_back(vTD[i]);
}
// sort(vTD_add.begin(), vTD_add.end(), cmp_gr_d); // dont need to sort.
// Because of the vTD is already sorted.
int64 numT = K - vTD_rm.size(); // num of type
int64 point = sum + numT * numT;
uint ri = vTD_rm.size() - 1;
uint ai = 0;
while (ri >= 0 && ai < vTD_add.size()) {
if (htUN[vTD_rm[ri].t] == 1) {
--ri;
continue;
}
if (htUN[vTD_add[ai].t] >= 1) {
++ai;
continue;
}
sum -= vTD_rm[ri].d;
--htUN[vTD_rm[ri].t];
--ri;
sum += vTD_add[ai].d;
++htUN[vTD_add[ai].t];
++ai;
++numT;
int64 tmp = sum + numT * numT;
point = max(point, tmp);
}
cout << point << endl;
return 0;
}
| //#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;
//---
template <typename T> inline void print(const T &rhs) {
std::cout << " = " << rhs << std::endl;
}
template <typename T> inline void print(const std::vector<T> &rhs) {
std::cout << " = [ ";
for (uint i = 0; i < rhs.size(); ++i) {
std::cout << rhs[i] << ' ';
}
std::cout << "]" << std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>> &rhs) {
std::cout << " = " << std::endl;
std::cout << "[[ ";
for (uint p = 0; p < rhs.size(); ++p) {
if (p != 0) {
std::cout << " [ ";
}
for (uint q = 0; q < rhs[p].size(); ++q) {
std::cout << rhs[p][q] << ' ';
}
if (p != rhs.size() - 1) {
std::cout << "]" << std::endl;
}
}
std::cout << "]]" << std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR, TL>> &rhs) {
std::cout << " = [";
uint i = 0;
for (; i < rhs.size() - 1; ++i) {
std::cout << "[f: " << rhs[i].first << ", s: " << rhs[i].second << "], ";
}
std::cout << "[f: " << rhs[i].first << ", s: " << rhs[i].second << "]]"
<< endl;
}
#define printn(var) \
{ \
printf("%s", #var); \
print(var); \
}
#define printn_all(var) \
{ \
printf("%s(%d): ", __func__, __LINE__); \
printf("%s", #var); \
print(var); \
}
//---
struct td {
int t;
int d;
};
bool cmp_d(struct td &lhs, struct td &rhs) { return lhs.d < rhs.d; }
bool cmp_gr_d(struct td &lhs, struct td &rhs) { return lhs.d > rhs.d; }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
uint N, K;
cin >> N >> K;
vector<struct td> vTD(N);
for (uint i = 0; i < N; ++i) {
cin >> vTD[i].t >> vTD[i].d;
}
sort(vTD.begin(), vTD.end(), cmp_gr_d);
unordered_map<int, int>
htUN; // a hash table for counting number of used types
vector<struct td> vTD_rm; // for remove
vector<struct td> vTD_add; // for add
int64 sum = 0ll;
for (uint i = 0; i < K; ++i) {
sum += vTD[i].d;
++htUN[vTD[i].t];
if (htUN[vTD[i].t] >= 2) {
vTD_rm.push_back(vTD[i]);
}
}
// sort(vTD_rm.begin(), vTD_rm.end(), cmp_d); // dont need to sort. By
// reversing the iteration to vTD_rm.
for (uint i = K; i < N; ++i) {
if (htUN[vTD[i].t] != 0) {
continue;
}
vTD_add.push_back(vTD[i]);
}
// sort(vTD_add.begin(), vTD_add.end(), cmp_gr_d); // dont need to sort.
// Because of the vTD is already sorted.
int64 numT = K - vTD_rm.size(); // num of type
int64 point = sum + numT * numT;
int ri = vTD_rm.size() - 1;
int ai = 0;
while (ri >= 0 && ai < vTD_add.size()) {
if (htUN[vTD_rm[ri].t] == 1) {
--ri;
continue;
}
if (htUN[vTD_add[ai].t] >= 1) {
++ai;
continue;
}
sum -= vTD_rm[ri].d;
--htUN[vTD_rm[ri].t];
--ri;
sum += vTD_add[ai].d;
++htUN[vTD_add[ai].t];
++ai;
++numT;
int64 tmp = sum + numT * numT;
point = max(point, tmp);
}
cout << point << endl;
return 0;
}
| [
"variable_declaration.type.change"
] | 946,524 | 946,525 | u456420540 | cpp |
p03148 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, int> Pli;
constexpr ll INF = 1e18;
int main() {
int N, K;
cin >> N >> K;
vector<Pli> sushi(N);
for (int i = 0; i < N; i++) {
cin >> sushi[i].second >> sushi[i].first;
}
map<int, int> types;
vector<ll> base_points(N + 1, -INF);
ll temp = 0;
sort(sushi.begin(), sushi.end(), greater<Pli>());
for (int i = 0; i < K; i++) {
types[sushi[i].second]++;
temp += sushi[i].first;
}
int a = types.size();
base_points[a] = temp;
int j = K;
for (int i = K - 1; 0 <= i; i--) {
if (types[sushi[i].second] != 1) {
while (j < N) {
if (types[sushi[j].second] == 0) {
temp = temp - sushi[i].first + sushi[j].first;
base_points[++a] = temp;
types[sushi[i].second]--;
types[sushi[j].second]++;
break;
} else {
j++;
}
}
if (j == N)
break;
}
}
ll ans = base_points[0];
for (int i = 0; i < N; i++) {
ans = max(ans, base_points[i] + (ll)i * i);
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, int> Pli;
constexpr ll INF = 1e18;
int main() {
int N, K;
cin >> N >> K;
vector<Pli> sushi(N);
for (int i = 0; i < N; i++) {
cin >> sushi[i].second >> sushi[i].first;
}
map<int, int> types;
vector<ll> base_points(N + 1, -INF);
ll temp = 0;
sort(sushi.begin(), sushi.end(), greater<Pli>());
for (int i = 0; i < K; i++) {
types[sushi[i].second]++;
temp += sushi[i].first;
}
int a = types.size();
base_points[a] = temp;
int j = K;
for (int i = K - 1; 0 <= i; i--) {
if (types[sushi[i].second] != 1) {
while (j < N) {
if (types[sushi[j].second] == 0) {
temp = temp - sushi[i].first + sushi[j].first;
base_points[++a] = temp;
types[sushi[i].second]--;
types[sushi[j].second]++;
break;
} else {
j++;
}
}
if (j == N)
break;
}
}
ll ans = base_points[0];
for (int i = 0; i <= N; i++) {
ans = max(ans, base_points[i] + (ll)i * i);
}
cout << ans << endl;
}
| [
"expression.operator.compare.change",
"control_flow.loop.for.condition.change",
"expression.off_by_one",
"expression.operation.binary.change"
] | 946,526 | 946,527 | u858575800 | cpp |
p03148 | #include <bits/stdc++.h>
using namespace std;
int count_and_compress(vector<long long> &a) {
vector<long long> b = a;
sort(b.begin(), b.end());
b.erase(unique(b.begin(), b.end()));
for (auto &e : a) {
e = (lower_bound(b.begin(), b.end(), e) - b.begin());
}
return b.size();
}
int main() {
int n, k;
cin >> n >> k;
vector<long long> t(n), d(n);
for (int i = 0; i < n; i++) {
cin >> t[i] >> d[i];
}
int sz = count_and_compress(t);
vector<vector<long long>> g(sz);
for (int i = 0; i < n; i++) {
g[t[i]].emplace_back(d[i]);
}
for (auto &v : g) {
sort(v.begin(), v.end(), greater<long long>());
}
vector<long long> f(1, 0), s(1, 0);
for (int i = 0; i < sz; i++) {
for (int j = 0; j < (int)g[i].size(); j++) {
if (j == 0)
f.emplace_back(g[i][j]);
else
s.emplace_back(g[i][j]);
}
}
sort(f.begin() + 1, f.end(), greater<long long>());
sort(s.begin() + 1, s.end(), greater<long long>());
for (long long i = 1; i < (int)f.size(); i++) {
f[i] += (2 * i - 1);
}
for (int i = 0; i + 1 < (int)f.size(); i++) {
f[i + 1] += f[i];
}
for (int i = 0; i + 1 < (int)s.size(); i++) {
s[i + 1] += s[i];
}
long long ans = 0;
for (int i = 1; i <= k; i++) {
int j = k - i;
if (i < f.size() and j < s.size()) {
long long res = f[i] + s[j];
ans = max(ans, res);
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int count_and_compress(vector<long long> &a) {
vector<long long> b = a;
sort(b.begin(), b.end());
b.erase(unique(b.begin(), b.end()), b.end());
for (auto &e : a) {
e = (lower_bound(b.begin(), b.end(), e) - b.begin());
}
return b.size();
}
int main() {
int n, k;
cin >> n >> k;
vector<long long> t(n), d(n);
for (int i = 0; i < n; i++) {
cin >> t[i] >> d[i];
}
int sz = count_and_compress(t);
vector<vector<long long>> g(sz);
for (int i = 0; i < n; i++) {
g[t[i]].emplace_back(d[i]);
}
for (auto &v : g) {
sort(v.begin(), v.end(), greater<long long>());
}
vector<long long> f(1, 0), s(1, 0);
for (int i = 0; i < sz; i++) {
for (int j = 0; j < (int)g[i].size(); j++) {
if (j == 0)
f.emplace_back(g[i][j]);
else
s.emplace_back(g[i][j]);
}
}
sort(f.begin() + 1, f.end(), greater<long long>());
sort(s.begin() + 1, s.end(), greater<long long>());
for (long long i = 1; i < (int)f.size(); i++) {
f[i] += (2 * i - 1);
}
for (int i = 0; i + 1 < (int)f.size(); i++) {
f[i + 1] += f[i];
}
for (int i = 0; i + 1 < (int)s.size(); i++) {
s[i + 1] += s[i];
}
long long ans = 0;
for (int i = 1; i <= k; i++) {
int j = k - i;
if (i < f.size() and j < s.size()) {
long long res = f[i] + s[j];
ans = max(ans, res);
}
}
cout << ans << endl;
return 0;
} | [
"call.arguments.add"
] | 946,565 | 946,566 | u615258936 | cpp |
p03148 | #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) x.begin(), x.end()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
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;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N, K;
cin >> N >> K;
vector<pll> A(N);
rep(i, N) {
ll t, d;
cin >> t >> d;
A[i] = {d, t};
}
sort(all(A));
reverse(all(A));
vector<ll> B = {0}, C = {0};
set<ll> dic;
ll type = 0;
ll ans = 0;
rep(i, N) {
ll t, d;
tie(d, t) = A[i];
if (i < K) {
if (dic.count(t)) {
B.emplace_back(d);
} else {
ans += d;
dic.emplace(t);
type++;
}
} else {
if (!dic.count(t)) {
C.emplace_back(d);
dic.emplace(t);
}
}
}
ll S = B.size() - 1;
ll T = C.size() - 1;
rep(i, S) { B[i + 1] += B[i]; }
rep(i, T) { C[i + 1] += C[i]; }
ll val = 0;
int k = min(K - type, T);
for (ll i = 0; i <= k; i++) {
ll qwe = 0;
qwe += C[i];
qwe += B[k - i];
chmax(val, qwe + (type + i) * (type + i));
}
cout << ans + val << endl;
}
| #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) x.begin(), x.end()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
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;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N, K;
cin >> N >> K;
vector<pll> A(N);
rep(i, N) {
ll t, d;
cin >> t >> d;
A[i] = {d, t};
}
sort(all(A));
reverse(all(A));
vector<ll> B = {0}, C = {0};
set<ll> dic;
ll type = 0;
ll ans = 0;
rep(i, N) {
ll t, d;
tie(d, t) = A[i];
if (i < K) {
if (dic.count(t)) {
B.emplace_back(d);
} else {
ans += d;
dic.emplace(t);
type++;
}
} else {
if (!dic.count(t)) {
C.emplace_back(d);
dic.emplace(t);
}
}
}
ll S = B.size() - 1;
ll T = C.size() - 1;
rep(i, S) { B[i + 1] += B[i]; }
rep(i, T) { C[i + 1] += C[i]; }
ll val = 0;
int k = min(K - type, T);
for (ll i = 0; i <= k; i++) {
ll qwe = 0;
qwe += C[i];
qwe += B[S - i];
chmax(val, qwe + (type + i) * (type + i));
}
cout << ans + val << endl;
}
| [
"assignment.value.change",
"identifier.change",
"variable_access.subscript.index.change",
"expression.operation.binary.change"
] | 946,593 | 946,594 | u842939260 | cpp |
p03148 | /*{{{*/
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) \
(sort(c.begin(), c.end()), \
c.resize(distance(c.begin(), unique(c.begin(), c.end()))))
#define GET_POS(c, x) (lower_bound(c.begin(), c.end(), x) - c.begin())
#define CASET \
int ___T; \
scanf("%d", &___T); \
for (int cs = 1; cs <= ___T; cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
template <class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template <class T, class... U> void R(T &head, U &...tail) {
_R(head);
R(tail...);
}
template <class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template <class T, class U> void _W(const pair<T, U> &x) {
_W(x.F);
putchar(' ');
_W(x.S);
}
template <class T> void _W(const vector<T> &x) {
for (auto i = x.begin(); i != x.end(); _W(*i++))
if (i != x.cbegin())
putchar(' ');
}
void W() {}
template <class T, class... U> void W(const T &head, const U &...tail) {
_W(head);
putchar(sizeof...(tail) ? ' ' : '\n');
W(tail...);
}
#ifdef HOME
#define DEBUG(...) \
{ \
printf("# "); \
printf(__VA_ARGS__); \
puts(""); \
}
#else
#define DEBUG(...)
#endif
int MOD = 1e9 + 7;
void ADD(LL &x, LL v) {
x = (x + v) % MOD;
if (x < 0)
x += MOD;
}
/*}}}*/
const int SIZE = 1e6 + 10;
int u[SIZE];
PII AA[SIZE];
int main() {
int N, K;
R(N, K);
REP(i, N) R(AA[i].S, AA[i].F);
sort(AA, AA + N, greater<PII>());
int cnt = 0;
LL v = 0;
REP(i, K) {
u[AA[i].S]++;
if (u[AA[i].S] == 1)
cnt++;
v += AA[i].F;
}
int it = K - 1;
LL an = v + (LL)cnt * cnt;
REPP(i, K, N) {
if (!u[AA[i].S]) {
while (it >= 0 && u[AA[it].S] == 1)
it--;
if (it < 0)
break;
u[AA[it].S]--;
v -= AA[it].F;
u[AA[i].S]++;
v += AA[i].F;
cnt++;
an = max(an, v + cnt * (LL)cnt);
}
}
W(an);
return 0;
}
| /*{{{*/
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) \
(sort(c.begin(), c.end()), \
c.resize(distance(c.begin(), unique(c.begin(), c.end()))))
#define GET_POS(c, x) (lower_bound(c.begin(), c.end(), x) - c.begin())
#define CASET \
int ___T; \
scanf("%d", &___T); \
for (int cs = 1; cs <= ___T; cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
template <class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template <class T, class... U> void R(T &head, U &...tail) {
_R(head);
R(tail...);
}
template <class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template <class T, class U> void _W(const pair<T, U> &x) {
_W(x.F);
putchar(' ');
_W(x.S);
}
template <class T> void _W(const vector<T> &x) {
for (auto i = x.begin(); i != x.end(); _W(*i++))
if (i != x.cbegin())
putchar(' ');
}
void W() {}
template <class T, class... U> void W(const T &head, const U &...tail) {
_W(head);
putchar(sizeof...(tail) ? ' ' : '\n');
W(tail...);
}
#ifdef HOME
#define DEBUG(...) \
{ \
printf("# "); \
printf(__VA_ARGS__); \
puts(""); \
}
#else
#define DEBUG(...)
#endif
int MOD = 1e9 + 7;
void ADD(LL &x, LL v) {
x = (x + v) % MOD;
if (x < 0)
x += MOD;
}
/*}}}*/
const int SIZE = 1e6 + 10;
int u[SIZE];
PII AA[SIZE];
int main() {
int N, K;
R(N, K);
REP(i, N) R(AA[i].S, AA[i].F);
sort(AA, AA + N, greater<PII>());
int cnt = 0;
LL v = 0;
REP(i, K) {
u[AA[i].S]++;
if (u[AA[i].S] == 1)
cnt++;
v += AA[i].F;
}
int it = K - 1;
LL an = v + (LL)cnt * cnt;
REPP(i, K, N) {
if (!u[AA[i].S]) {
while (it >= 0 && u[AA[it].S] == 1)
it--;
if (it < 0)
break;
u[AA[it].S]--;
v -= AA[it].F;
it--;
u[AA[i].S]++;
v += AA[i].F;
cnt++;
an = max(an, v + cnt * (LL)cnt);
}
}
W(an);
return 0;
}
| [
"expression.unary.arithmetic.add"
] | 946,630 | 946,631 | u284124505 | cpp |
p03148 | #include <algorithm>
#include <iostream>
#include <queue>
using namespace std;
typedef pair<int, int> P;
int main() {
int N, K;
cin >> N >> K;
P p[100000];
long s = 0;
int cnt[100001] = {0};
long ans = 0;
for (int i = 0; i < N; i++) {
int t, d;
cin >> t >> d;
p[i] = P(d, t);
}
sort(p, p + N, greater<P>());
for (int i = 0; i < K; i++) {
if (cnt[p[i].second] == 0)
s++;
cnt[p[i].second]++;
ans += p[i].first;
}
ans += s * s;
long ans_m = ans;
int l = K - 1;
int r = K;
while (l >= 0 && K <= N - 1) {
if (/*2*s+1 >= (p[l].first - p[r].first) && */ cnt[p[l].second] >= 2 &&
cnt[p[r].second] == 0) {
ans += 2 * s + 1 - (p[l].first - p[r].first);
cnt[p[l].second]--;
cnt[p[r].second]++;
l--;
r++;
s++;
} else if (cnt[p[l].second] <= 1) {
l--;
} else if (cnt[p[r].second] > 0) {
r++;
} /*else if(2*s+1 < (p[l].first - p[r].first)){
//l--;
}*/
ans_m = max(ans, ans_m);
}
cout << ans_m << endl;
} | #include <algorithm>
#include <iostream>
#include <queue>
using namespace std;
typedef pair<int, int> P;
int main() {
int N, K;
cin >> N >> K;
P p[100000];
long s = 0;
int cnt[100001] = {0};
long ans = 0;
for (int i = 0; i < N; i++) {
int t, d;
cin >> t >> d;
p[i] = P(d, t);
}
sort(p, p + N, greater<P>());
for (int i = 0; i < K; i++) {
if (cnt[p[i].second] == 0)
s++;
cnt[p[i].second]++;
ans += p[i].first;
}
ans += s * s;
long ans_m = ans;
int l = K - 1;
int r = K;
while (l >= 0 && r <= N - 1) {
if (/*2*s+1 >= (p[l].first - p[r].first) && */ cnt[p[l].second] >= 2 &&
cnt[p[r].second] == 0) {
ans += 2 * s + 1 - (p[l].first - p[r].first);
cnt[p[l].second]--;
cnt[p[r].second]++;
l--;
r++;
s++;
} else if (cnt[p[l].second] <= 1) {
l--;
} else if (cnt[p[r].second] > 0) {
r++;
} /*else if(2*s+1 < (p[l].first - p[r].first)){
//l--;
}*/
ans_m = max(ans, ans_m);
}
cout << ans_m << endl;
} | [
"identifier.change",
"control_flow.loop.condition.change"
] | 946,638 | 946,639 | u693133807 | cpp |
p03148 | #include <algorithm>
#include <iostream>
#include <queue>
using namespace std;
typedef pair<int, int> P;
int main() {
int N, K;
cin >> N >> K;
P p[100000];
int s = 0;
int cnt[100001] = {0};
long ans = 0;
for (int i = 0; i < N; i++) {
int t, d;
cin >> t >> d;
p[i] = P(d, t);
}
sort(p, p + N, greater<P>());
for (int i = 0; i < K; i++) {
if (cnt[p[i].second] == 0)
s++;
cnt[p[i].second]++;
ans += p[i].first;
}
ans += s * s;
long ans_m = ans;
int l = K - 1;
int r = K;
while (l >= 0 && K <= N - 1) {
if (/*2*s+1 >= (p[l].first - p[r].first) && */ cnt[p[l].second] >= 2 &&
cnt[p[r].second] == 0) {
ans += 2 * s + 1 - (p[l].first - p[r].first);
cnt[p[l].second]--;
cnt[p[r].second]++;
l--;
r++;
s++;
} else if (cnt[p[l].second] <= 1) {
l--;
} else if (cnt[p[r].second] > 0) {
r++;
} /*else if(2*s+1 < (p[l].first - p[r].first)){
//l--;
}*/
ans_m = max(ans, ans_m);
}
cout << ans_m << endl;
} | #include <algorithm>
#include <iostream>
#include <queue>
using namespace std;
typedef pair<int, int> P;
int main() {
int N, K;
cin >> N >> K;
P p[100000];
long s = 0;
int cnt[100001] = {0};
long ans = 0;
for (int i = 0; i < N; i++) {
int t, d;
cin >> t >> d;
p[i] = P(d, t);
}
sort(p, p + N, greater<P>());
for (int i = 0; i < K; i++) {
if (cnt[p[i].second] == 0)
s++;
cnt[p[i].second]++;
ans += p[i].first;
}
ans += s * s;
long ans_m = ans;
int l = K - 1;
int r = K;
while (l >= 0 && r <= N - 1) {
if (/*2*s+1 >= (p[l].first - p[r].first) && */ cnt[p[l].second] >= 2 &&
cnt[p[r].second] == 0) {
ans += 2 * s + 1 - (p[l].first - p[r].first);
cnt[p[l].second]--;
cnt[p[r].second]++;
l--;
r++;
s++;
} else if (cnt[p[l].second] <= 1) {
l--;
} else if (cnt[p[r].second] > 0) {
r++;
} /*else if(2*s+1 < (p[l].first - p[r].first)){
//l--;
}*/
ans_m = max(ans, ans_m);
}
cout << ans_m << endl;
} | [
"variable_declaration.type.primitive.change",
"identifier.change",
"control_flow.loop.condition.change"
] | 946,640 | 946,639 | u693133807 | cpp |
p03148 | #include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;
typedef std::pair<int64_t, int64_t> ii;
using namespace std;
int main() {
cout << std::fixed << std::setprecision(16);
cin.tie(nullptr);
std::ios::sync_with_stdio(false);
int n, k;
cin >> n >> k;
std::vector<ii> vec;
for (int i = 0; i < n; i++) {
int t, d;
cin >> t >> d;
vec.push_back(std::make_pair(d, t));
}
sort(vec.begin(), vec.end(), std::greater<>());
unordered_map<int, int> count;
int64_t result = 0, point = 0;
for (int i = 0; i < k; i++) {
point += vec[i].first;
if (count.find(vec[i].second) == count.end()) {
count[vec[i].second] = 1;
} else {
count[vec[i].second]++;
}
}
int64_t species = count.size();
point += species * species;
result = point;
int removeitr = k - 1;
for (int i = k; i < n; i++) {
if (count.find(vec[i].second) == count.end()) {
bool canremove = false;
for (; removeitr >= 0; removeitr--) {
if (count[vec[removeitr].second] >= 2) {
canremove = true;
break;
}
}
if (canremove) {
count[vec[removeitr].second]--;
point -= vec[removeitr].first;
count[vec[i].second]++;
point += vec[i].first;
point -= species * species;
species++;
point += species * species;
result = std::max(result, point);
}
}
}
cout << result << endl;
return 0;
} | #include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;
typedef std::pair<int64_t, int64_t> ii;
using namespace std;
int main() {
cout << std::fixed << std::setprecision(16);
cin.tie(nullptr);
std::ios::sync_with_stdio(false);
int n, k;
cin >> n >> k;
std::vector<ii> vec;
for (int i = 0; i < n; i++) {
int t, d;
cin >> t >> d;
vec.push_back(std::make_pair(d, t));
}
sort(vec.begin(), vec.end(), std::greater<>());
unordered_map<int, int> count;
int64_t result = 0, point = 0;
for (int i = 0; i < k; i++) {
point += vec[i].first;
if (count.find(vec[i].second) == count.end()) {
count[vec[i].second] = 1;
} else {
count[vec[i].second]++;
}
}
int64_t species = count.size();
point += species * species;
result = point;
int removeitr = k - 1;
for (int i = k; i < n; i++) {
if (count.find(vec[i].second) == count.end()) {
bool canremove = false;
for (; removeitr >= 0; removeitr--) {
if (count[vec[removeitr].second] >= 2) {
canremove = true;
break;
}
}
if (canremove) {
count[vec[removeitr].second]--;
point -= vec[removeitr].first;
count[vec[i].second]++;
point += vec[i].first;
point -= species * species;
species++;
point += species * species;
result = std::max(result, point);
removeitr--;
}
}
}
cout << result << endl;
return 0;
}
| [
"expression.unary.arithmetic.add"
] | 946,661 | 946,662 | u844133200 | cpp |
p03148 | #include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, a, b) for (ll i = ll(a); i < ll(b); i++)
#define all(x) (x).begin(), (x).end()
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;
}
typedef long long ll;
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll n, k;
cin >> n >> k;
vector<pair<ll, ll>> su(n);
rep(i, n) {
ll a, b;
cin >> a >> b;
su[i] = {b, a};
}
// su[n]={0,1e9+7};
sort(all(su), greater<pair<ll, ll>>());
set<ll> used;
vector<ll> id;
rep(i, n) {
if (!used.count(su[i].second)) {
used.insert(su[i].second);
id.push_back(i);
}
}
// cout<<"su"<<endl;
// for(auto t:su)//cout<<t.first<<" "<<t.second<<endl;
// for(auto t:id)//cout<<t<<endl;
////cout<<"idsize"<<id.size()<<endl;
vector<ll> sum1(n + 1), sum2(id.size() + 1);
rep(i, n) sum1[i + 1] = su[i].first + sum1[i];
rep(i, id.size()) sum2[i + 1] = su[id[i]].first + sum2[i];
ll syurui = used.size();
ll res = 0LL;
ll inid = upper_bound(all(id), k - 1) - id.begin();
res = (ll)inid * inid + sum1[k];
inid--;
ll idx = k - 1;
repi(i, inid + 1, 1 + min(k, syurui)) {
ll tres = i * i;
while (idx == id[inid]) {
inid--;
idx--;
}
idx--;
// cout<<"inid"<<inid<<endl;
tres -= sum2[inid + 1];
tres += sum2[i];
tres += sum1[idx + 1];
chmax(res, tres);
// cout<<res<<endl;
}
cout << res << endl;
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, a, b) for (ll i = ll(a); i < ll(b); i++)
#define all(x) (x).begin(), (x).end()
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;
}
typedef long long ll;
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll n, k;
cin >> n >> k;
vector<pair<ll, ll>> su(n);
rep(i, n) {
ll a, b;
cin >> a >> b;
su[i] = {b, a};
}
// su[n]={0,1e9+7};
sort(all(su), greater<pair<ll, ll>>());
set<ll> used;
vector<ll> id;
rep(i, n) {
if (!used.count(su[i].second)) {
used.insert(su[i].second);
id.push_back(i);
}
}
// cout<<"su"<<endl;
// for(auto t:su)//cout<<t.first<<" "<<t.second<<endl;
// for(auto t:id)//cout<<t<<endl;
////cout<<"idsize"<<id.size()<<endl;
vector<ll> sum1(n + 1), sum2(id.size() + 1);
rep(i, n) sum1[i + 1] = su[i].first + sum1[i];
rep(i, id.size()) sum2[i + 1] = su[id[i]].first + sum2[i];
ll syurui = used.size();
ll res = 0LL;
ll inid = upper_bound(all(id), k - 1) - id.begin();
res = (ll)inid * inid + sum1[k];
inid--;
ll idx = k - 1;
repi(i, inid + 2, 1 + min(k, syurui)) {
ll tres = i * i;
while (idx == id[inid]) {
inid--;
idx--;
}
idx--;
// cout<<"inid"<<inid<<endl;
tres -= sum2[inid + 1];
tres += sum2[i];
tres += sum1[idx + 1];
chmax(res, tres);
// cout<<res<<endl;
}
cout << res << endl;
return 0;
}
| [
"literal.number.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 946,694 | 946,695 | u834415466 | cpp |
p03148 | #include <bits/stdc++.h>
using namespace std;
#define REP(i, b, e) for (int i = (b); i < (e); ++i)
#define RREP(i, b, e) for (int i = (b)-1; i >= e; --i)
#define rep(i, e) for (int i = 0; i < (e); ++i)
inline void print(void) { cout << '\n'; }
template <class T> inline void print(const T &x) { cout << x << '\n'; }
template <class T, class... U> inline void print(const T &x, const U &...y) {
cout << x << " ";
print(y...);
}
int main() {
int n, k;
cin >> n >> k;
vector<pair<int, int>> td(n);
rep(i, n) cin >> td[i].first >> td[i].second;
sort(td.begin(), td.end(),
[](auto x, auto y) { return x.second > y.second; });
long long ans = 0, cur = 0;
set<int> s;
queue<int> q;
rep(i, k) {
if (s.count(td[i].first))
q.push(td[i].second);
s.emplace(td[i].first);
cur += td[i].second;
}
ans = cur + s.size() * s.size();
REP(i, k, n) {
if (q.empty())
break;
if (s.count(td[i].first))
continue;
cur -= q.front();
q.pop();
cur += td[i].second;
s.emplace(td[i].first);
ans = max(ans, cur + (long long)(s.size() * s.size()));
}
print(ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define REP(i, b, e) for (int i = (b); i < (e); ++i)
#define RREP(i, b, e) for (int i = (b)-1; i >= e; --i)
#define rep(i, e) for (int i = 0; i < (e); ++i)
inline void print(void) { cout << '\n'; }
template <class T> inline void print(const T &x) { cout << x << '\n'; }
template <class T, class... U> inline void print(const T &x, const U &...y) {
cout << x << " ";
print(y...);
}
int main() {
int n, k;
cin >> n >> k;
vector<pair<int, int>> td(n);
rep(i, n) cin >> td[i].first >> td[i].second;
sort(td.begin(), td.end(),
[](auto x, auto y) { return x.second > y.second; });
long long ans = 0, cur = 0;
set<int> s;
stack<int> q;
rep(i, k) {
if (s.count(td[i].first))
q.push(td[i].second);
s.emplace(td[i].first);
cur += td[i].second;
}
ans = cur + s.size() * s.size();
REP(i, k, n) {
if (q.empty())
break;
if (s.count(td[i].first))
continue;
cur -= q.top();
q.pop();
cur += td[i].second;
s.emplace(td[i].first);
ans = max(ans, cur + (long long)(s.size() * s.size()));
}
print(ans);
return 0;
} | [
"variable_declaration.type.change",
"assignment.value.change",
"call.function.change"
] | 946,697 | 946,698 | u403301154 | cpp |
p03148 | #include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
//#define endl "\n"
#define ciosup \
cin.tie(0); \
ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e18 + 7LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (int i = 0; i < v.size(); ++i) {
is >> v[i];
}
return is;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
for (int i = 0; i < v.size() - 1; ++i) {
os << v[i] << " ";
}
if (v.size() > 0) {
os << v[v.size() - 1] << endl;
}
return os;
}
int main() {
int n, k;
cin >> n >> k;
vector<pint> sushi(n);
REP(i, n) { cin >> sushi[i].SE >> sushi[i].FI; }
sort(sushi.begin(), sushi.end());
reverse(sushi.begin(), sushi.end());
ll ans = 0;
unordered_map<int, int> kind;
priority_queue<int> pque;
priority_queue<int, vint, greater<int>> pque2;
int kindval = 0;
REP(i, k) {
ans += sushi[i].FI;
++kind[sushi[i].SE];
if (kind[sushi[i].SE] > 1) {
pque.push(sushi[i].FI);
} else {
++kindval;
}
}
FOR(i, k, n) {
++kind[sushi[i].SE];
if (kind[sushi[i].SE] == 1) {
pque2.push(sushi[i].FI);
}
}
ans += kindval * kindval;
ll now = ans;
while (pque.size() > 0 && pque2.size() > 0) {
now -= pque.top();
pque.pop();
now += pque2.top();
pque2.pop();
++kindval;
now += kindval * kindval - (kindval - 1) * (kindval - 1);
ans = max(now, ans);
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
//#define endl "\n"
#define ciosup \
cin.tie(0); \
ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e18 + 7LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (int i = 0; i < v.size(); ++i) {
is >> v[i];
}
return is;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
for (int i = 0; i < v.size() - 1; ++i) {
os << v[i] << " ";
}
if (v.size() > 0) {
os << v[v.size() - 1] << endl;
}
return os;
}
int main() {
int n, k;
cin >> n >> k;
vector<pll> sushi(n);
REP(i, n) { cin >> sushi[i].SE >> sushi[i].FI; }
sort(sushi.begin(), sushi.end());
reverse(sushi.begin(), sushi.end());
ll ans = 0;
unordered_map<int, int> kind;
priority_queue<int> pque2;
priority_queue<int, vint, greater<int>> pque;
ll kindval = 0;
REP(i, k) {
ans += sushi[i].FI;
++kind[sushi[i].SE];
if (kind[sushi[i].SE] > 1) {
pque.push(sushi[i].FI);
} else {
++kindval;
}
}
FOR(i, k, n) {
++kind[sushi[i].SE];
if (kind[sushi[i].SE] == 1) {
pque2.push(sushi[i].FI);
}
}
ans += kindval * kindval;
ll now = ans;
while (pque.size() > 0 && pque2.size() > 0) {
now -= pque.top();
pque.pop();
now += pque2.top();
pque2.pop();
++kindval;
now += kindval * kindval - (kindval - 1) * (kindval - 1);
ans = max(now, ans);
}
cout << ans << endl;
} | [
"identifier.change",
"variable_declaration.type.change"
] | 946,701 | 946,700 | u337054478 | cpp |
p03148 | #include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, m, n) for (int i = m; i < n; i++)
#define repr(i, m, n) for (int i = m; i >= n; i--)
#define db(x) cout << #x << "=" << x << endl
template <class T> bool maxi(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool mini(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
#define y0 y3487465 // y1 j0 j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
#define EPS 1e(-9);
using namespace std;
typedef long long ll;
void Main() {
ll N, K;
cin >> N >> K;
vector<pair<ll, ll>> ve;
rep(i, N) {
ll t, d;
cin >> t >> d;
ve.emplace_back(d, t);
}
bool nonFirstNeta[N + 1] = {};
sort(ALL(ve), greater<pair<ll, ll>>());
ll netakind = 0;
// 種類の異なるもの
// 上からKことって、種類を増やしていく
bool check[N] = {};
rep(i, N) {
if (!nonFirstNeta[ve[i].second]) {
nonFirstNeta[ve[i].second] = true;
check[i] = true;
netakind++;
// ve[i].first+=(netakind*netakind)-(netakind-1)*(netakind-1);
}
}
ll ans = 0;
ll nowneta = 0;
rep(i, K) {
if (check[i]) {
ans += nowneta * 2 + 1;
nowneta++;
}
ans += ve[i].first;
}
ll left = K;
ll right = K - 1;
ll tmp = ans;
while ((left--) > 0 and nowneta <= netakind) {
if (check[left])
continue;
tmp -= ve[left].first;
while (true) {
++right;
if (check[right])
break;
}
tmp += ve[right].first;
tmp += nowneta * 2 + 1;
// cout<< tmp <<" "<< nowneta<<"\n";
maxi(ans, tmp);
nowneta++;
}
cout << ans << "\n";
}
//-----------------------------------
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(15);
Main();
}
//-----------------------------------
| #include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, m, n) for (int i = m; i < n; i++)
#define repr(i, m, n) for (int i = m; i >= n; i--)
#define db(x) cout << #x << "=" << x << endl
template <class T> bool maxi(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool mini(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
#define y0 y3487465 // y1 j0 j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
#define EPS 1e(-9);
using namespace std;
typedef long long ll;
void Main() {
ll N, K;
cin >> N >> K;
vector<pair<ll, ll>> ve;
rep(i, N) {
ll t, d;
cin >> t >> d;
ve.emplace_back(d, t);
}
bool nonFirstNeta[N + 1] = {};
sort(ALL(ve), greater<pair<ll, ll>>());
ll netakind = 0;
// 種類の異なるもの
// 上からKことって、種類を増やしていく
bool check[N] = {};
rep(i, N) {
if (!nonFirstNeta[ve[i].second]) {
nonFirstNeta[ve[i].second] = true;
check[i] = true;
netakind++;
// ve[i].first+=(netakind*netakind)-(netakind-1)*(netakind-1);
}
}
ll ans = 0;
ll nowneta = 0;
rep(i, K) {
if (check[i]) {
ans += nowneta * 2 + 1;
nowneta++;
}
ans += ve[i].first;
}
ll left = K;
ll right = K - 1;
ll tmp = ans;
while (--left >= 0 and nowneta < netakind) {
if (check[left])
continue;
tmp -= ve[left].first;
while (true) {
++right;
if (check[right])
break;
}
tmp += ve[right].first;
tmp += nowneta * 2 + 1;
// cout<< tmp <<" "<< nowneta<<"\n";
maxi(ans, tmp);
nowneta++;
}
cout << ans << "\n";
}
//-----------------------------------
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(15);
Main();
}
//-----------------------------------
| [
"expression.operator.compare.change",
"control_flow.loop.condition.change"
] | 946,702 | 946,703 | u556276145 | cpp |
p03148 | #include <bits/stdc++.h>
using namespace std;
#define sz(v) ((int)((v).size()))
#define clr(v, d) memset(v, d, sizeof(v))
#define rep(i, v) for (int i = 0; i < sz(v); ++i)
#define lp(i, n) for (int i = 0; i < (int)(n); ++i)
#define lpi(i, j, n) for (int i = (j); i < (int)(n); ++i)
#define lpd(i, j, n) for (int i = (j); i >= (int)(n); --i)
#define INF 1000000000
//#define DEBUG
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
const int N = 1e5 + 5;
priority_queue<pair<int, int>> all;
priority_queue<pair<int, int>> rep;
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>>
sol;
int vis[N];
int main() {
std::ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, k, uniq = 0;
cin >> n >> k;
lp(i, n) {
pair<int, int> in;
cin >> in.second >> in.first;
all.push(in);
}
lp(i, n) {
pair<int, int> in = all.top();
all.pop();
if (vis[in.second] > 0 || uniq == k)
rep.push(in);
else {
sol.push(in);
++vis[in.second];
++uniq;
}
}
lpi(i, uniq, k) {
sol.push(rep.top());
++vis[rep.top().second];
rep.pop();
}
while (true) {
ll op1 = 0ll + (uniq - 1) * (uniq - 1) + rep.top().first;
ll op2 = 0ll + (uniq) * (uniq) + sol.top().first;
if (op1 > op2) {
sol.pop();
sol.push(rep.top());
rep.pop();
--uniq;
} else
break;
}
ll ans = 0;
ans = 1ll * uniq * uniq;
while (!sol.empty()) {
ans += 0ll + sol.top().first;
sol.pop();
}
cout << ans;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define sz(v) ((int)((v).size()))
#define clr(v, d) memset(v, d, sizeof(v))
#define rep(i, v) for (int i = 0; i < sz(v); ++i)
#define lp(i, n) for (int i = 0; i < (int)(n); ++i)
#define lpi(i, j, n) for (int i = (j); i < (int)(n); ++i)
#define lpd(i, j, n) for (int i = (j); i >= (int)(n); --i)
#define INF 1000000000
//#define DEBUG
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
const int N = 1e5 + 5;
priority_queue<pair<int, int>> all;
priority_queue<pair<int, int>> rep;
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>>
sol;
int vis[N];
int main() {
std::ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, k, uniq = 0;
cin >> n >> k;
lp(i, n) {
pair<int, int> in;
cin >> in.second >> in.first;
all.push(in);
}
lp(i, n) {
pair<int, int> in = all.top();
all.pop();
if (vis[in.second] > 0 || uniq == k)
rep.push(in);
else {
sol.push(in);
++vis[in.second];
++uniq;
}
}
lpi(i, uniq, k) {
sol.push(rep.top());
++vis[rep.top().second];
rep.pop();
}
while (!rep.empty()) {
ll op1 = 0ll + (uniq - 1) * (uniq - 1) + rep.top().first;
ll op2 = 0ll + (uniq) * (uniq) + sol.top().first;
if (op1 > op2) {
sol.pop();
sol.push(rep.top());
rep.pop();
--uniq;
} else
break;
}
ll ans = 0;
ans = 1ll * uniq * uniq;
while (!sol.empty()) {
ans += 0ll + sol.top().first;
sol.pop();
}
cout << ans;
return 0;
}
| [
"control_flow.loop.condition.change",
"call.add"
] | 946,710 | 946,711 | u028760718 | cpp |
p03148 | #include <bits/stdc++.h>
using namespace std;
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define rep(i, n) repl(i, 0, n)
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18 + 10;
const int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
int main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
int n, k;
cin >> n >> k;
pair<int, int> p[n];
rep(i, n) cin >> p[i].second >> p[i].first;
sort(p, p + n, greater<pair<int, int>>());
ll now = 0;
set<int> s;
priority_queue<int, vector<int>, greater<int>> que;
rep(i, k) {
now += p[i].first;
if (s.count(p[i].second))
que.push(p[i].first);
s.insert(p[i].second);
}
ll S = s.size();
now += S * S;
priority_queue<int> Que;
repl(i, k, n) {
if (s.count(p[i].second) == 0) {
Que.push(p[i].first);
s.insert(p[i].second);
}
}
ll ans = now;
while (true) {
if (Que.empty() or que.empty())
break;
now += Que.top() - que.top();
Que.pop(), que.pop();
now -= S * S++ - S * S;
ans = max(ans, now);
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define rep(i, n) repl(i, 0, n)
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18 + 10;
const int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
int main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
int n, k;
cin >> n >> k;
pair<int, int> p[n];
rep(i, n) cin >> p[i].second >> p[i].first;
sort(p, p + n, greater<pair<int, int>>());
ll now = 0;
set<int> s;
priority_queue<int, vector<int>, greater<int>> que;
rep(i, k) {
now += p[i].first;
if (s.count(p[i].second))
que.push(p[i].first);
s.insert(p[i].second);
}
ll S = s.size();
now += S * S;
priority_queue<int> Que;
repl(i, k, n) {
if (s.count(p[i].second) == 0) {
Que.push(p[i].first);
s.insert(p[i].second);
}
}
ll ans = now;
while (true) {
if (Que.empty() or que.empty())
break;
now += Que.top() - que.top();
Que.pop(), que.pop();
now -= S * S;
S++;
now += S * S;
ans = max(ans, now);
}
cout << ans << endl;
return 0;
}
| [
"expression.operation.binary.change",
"assignment.change"
] | 946,721 | 946,722 | u936602931 | cpp |
p03148 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
bool cmp(pair<ll, ll> a, pair<ll, ll> b) {
if (a.first != b.first)
return a.first < b.first;
return a.second > b.second;
}
int main() {
int n, k;
cin >> n >> k;
vector<pair<ll, ll>> cmt, a, b;
map<ll, ll> mp;
for (int i = 0; i < n; i++)
{
ll x, y;
cin >> x >> y;
cmt.emplace_back(y, x);
}
sort(cmt.begin(), cmt.end(), cmp);
for (int i = 0; i < n; i++) {
ll x;
x = cmt[i].second;
ll y;
y = cmt[i].first;
if (mp[x] == 0) {
a.emplace_back(y, x);
mp[x] = true;
} else {
b.emplace_back(y, x);
}
}
set<int> st;
sort(a.begin(), a.end(), cmp);
sort(b.begin(), b.end(), cmp);
vector<ll> asum(a.size() + 1), bsum(b.size() + 1);
for (int i = 0; i < a.size(); i++) {
asum[i + 1] += a[i].first + asum[i];
}
for (int i = 0; i < b.size(); i++) {
bsum[i + 1] += b[i].first + bsum[i];
}
ll ans = 0;
set<ll> A, B;
for (int i = 1; i <= k; i++) {
ll now = 0;
if (i < asum.size()) {
now += asum[i];
A.insert(a[i - 1].second);
if (B.find(a[i - 1].second) != B.end()) {
B.erase(B.find(a[i - 1].second));
}
} else
continue;
if (k - i < bsum.size()) {
now += bsum[k - i];
if (A.find(a[i - 1].second) == A.end())
B.insert(b[i - 1].second);
} else
continue;
ll x = A.size() + B.size();
now += x * x;
ans = max(ans, now);
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
bool cmp(pair<ll, ll> a, pair<ll, ll> b) {
if (a.first != b.first)
return a.first > b.first;
return a.second < b.second;
}
int main() {
int n, k;
cin >> n >> k;
vector<pair<ll, ll>> cmt, a, b;
map<ll, ll> mp;
for (int i = 0; i < n; i++)
{
ll x, y;
cin >> x >> y;
cmt.emplace_back(y, x);
}
sort(cmt.begin(), cmt.end(), cmp);
for (int i = 0; i < n; i++) {
ll x;
x = cmt[i].second;
ll y;
y = cmt[i].first;
if (mp[x] == 0) {
a.emplace_back(y, x);
mp[x] = true;
} else {
b.emplace_back(y, x);
}
}
set<int> st;
sort(a.begin(), a.end(), cmp);
sort(b.begin(), b.end(), cmp);
vector<ll> asum(a.size() + 1), bsum(b.size() + 1);
for (int i = 0; i < a.size(); i++) {
asum[i + 1] += a[i].first + asum[i];
}
for (int i = 0; i < b.size(); i++) {
bsum[i + 1] += b[i].first + bsum[i];
}
ll ans = 0;
set<ll> A, B;
for (int i = 1; i <= k; i++) {
ll now = 0;
if (i < asum.size()) {
now += asum[i];
A.insert(a[i - 1].second);
if (B.find(a[i - 1].second) != B.end()) {
B.erase(B.find(a[i - 1].second));
}
} else
continue;
if (k - i < bsum.size()) {
now += bsum[k - i];
if (A.find(a[i - 1].second) == A.end())
B.insert(b[i - 1].second);
} else
continue;
ll x = A.size() + B.size();
now += x * x;
ans = max(ans, now);
}
cout << ans << endl;
} | [
"misc.opposites",
"expression.operator.compare.change",
"function.return_value.change",
"expression.operation.binary.change"
] | 946,735 | 946,736 | u184929210 | cpp |
p03148 | #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 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 ion(i, j) ((i & (1LL << j)) > 0)
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;
}
map<pair<string, string>, ll> getmp(string s) {
map<pair<string, string>, ll> mp;
for (ll i = 0; i < (1LL << n); i++) {
string s1 = "";
string s2 = "";
for (ll j = 0; j < n; j++) {
if (ion(i, j))
s1 += s[j];
else
s2 += s[j];
}
mp[make_pair(s1, s2)]++;
}
return mp;
}
void solv() {
ll k;
cin >> n >> k;
ll t[100010], d[100010];
ll kind = 0;
ll p[100010];
all0(p);
ll sum = 0;
rep(i, n) {
cin >> t[i] >> d[i];
p[t[i]]++;
sum += d[i];
if (p[t[i]] == 1)
kind++;
}
sum += kind * kind;
pllgreaterq q;
priority_queue<ll, vector<ll>, greater<ll>> q2;
rep(i, n) {
if (p[t[i]] == 1) {
q2.push(d[i]);
} else {
q.push(make_pair(d[i], i));
}
}
rep(i, n - k) {
ll v1 = INF * INF;
while (!q.empty()) {
auto a = q.top();
if (p[t[a.second]] == 1) {
q2.push(a.first);
q.pop();
continue;
}
v1 = a.first;
break;
}
ll v2 = INF * INF;
if (!q2.empty()) {
v2 = q2.top() + (kind * kind) - (kind - 1) * (kind - 1);
}
sum -= min(v1, v2);
if (v1 < v2) {
auto a = q.top();
t[a.second]--;
q.pop();
} else {
kind--;
q2.pop();
}
}
cout << sum << 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 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 ion(i, j) ((i & (1LL << j)) > 0)
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;
}
map<pair<string, string>, ll> getmp(string s) {
map<pair<string, string>, ll> mp;
for (ll i = 0; i < (1LL << n); i++) {
string s1 = "";
string s2 = "";
for (ll j = 0; j < n; j++) {
if (ion(i, j))
s1 += s[j];
else
s2 += s[j];
}
mp[make_pair(s1, s2)]++;
}
return mp;
}
void solv() {
ll k;
cin >> n >> k;
ll t[100010], d[100010];
ll kind = 0;
ll p[100010];
all0(p);
ll sum = 0;
rep(i, n) {
cin >> t[i] >> d[i];
p[t[i]]++;
sum += d[i];
if (p[t[i]] == 1)
kind++;
}
sum += kind * kind;
pllgreaterq q;
priority_queue<ll, vector<ll>, greater<ll>> q2;
rep(i, n) {
if (p[t[i]] == 1) {
q2.push(d[i]);
} else {
q.push(make_pair(d[i], i));
}
}
rep(i, n - k) {
ll v1 = INF * INF;
while (!q.empty()) {
auto a = q.top();
if (p[t[a.second]] == 1) {
q2.push(a.first);
q.pop();
continue;
}
v1 = a.first;
break;
}
ll v2 = INF * INF;
if (!q2.empty()) {
v2 = q2.top() + ((kind * kind) - (kind - 1) * (kind - 1));
}
sum -= min(v1, v2);
if (v1 < v2) {
auto a = q.top();
p[t[a.second]]--;
q.pop();
} else {
kind--;
q2.pop();
}
}
cout << sum << endl;
}
int main() {
// COMinit();
solv();
return 0;
} | [] | 946,757 | 946,758 | u224756887 | cpp |
p03148 | #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);
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;
}
};
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;
}
double digsum(ll x) {
ll res = 0;
while (x > 0) {
res += x % 10;
x /= 10;
}
return res;
}
bool maching(char a, char b) { return (a == b || a == '?' || b == '?'); }
int getArea(ll x, ll v) {
for (size_t i = 1; i <= 3; i++) {
if (x < v * i)
return i - 1;
}
}
void solv() {
ll k;
cin >> n >> k;
ll t[100010], d[100010];
ll ki[100010];
all0(ki);
ll x = 0;
ll su = 0;
rep(i, n) {
cin >> t[i] >> d[i];
su += d[i];
ki[t[i]]++;
if (ki[t[i]] == 1)
x++;
}
su += x * x;
pllgreaterq q;
priority_queue<ll, vector<ll>, greater<ll>> qq;
rep(i, n) {
if (ki[t[i]] == 1) {
qq.push(d[i]);
} else {
q.push(make_pair(d[i], i));
}
}
for (ll i = n; i > k; i--) {
ll v = INF * INF;
int bt = -1;
ll v1 = INF * INF;
while (!q.empty()) {
auto p = q.top();
if (ki[t[p.second]] == 1) {
q.pop();
qq.push(p.first);
} else {
bt = p.second;
v = p.first;
break;
}
}
if (!qq.empty()) {
auto p = qq.top();
v1 = p + (x * x - (x - 1) * (x - 1));
}
su -= min(v, v1);
if (v <= v1) {
ki[t[bt]]--;
q.pop();
} else {
qq.pop();
}
}
cout << su << 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);
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;
}
};
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;
}
double digsum(ll x) {
ll res = 0;
while (x > 0) {
res += x % 10;
x /= 10;
}
return res;
}
bool maching(char a, char b) { return (a == b || a == '?' || b == '?'); }
int getArea(ll x, ll v) {
for (size_t i = 1; i <= 3; i++) {
if (x < v * i)
return i - 1;
}
}
void solv() {
ll k;
cin >> n >> k;
ll t[100010], d[100010];
ll ki[100010];
all0(ki);
ll x = 0;
ll su = 0;
rep(i, n) {
cin >> t[i] >> d[i];
su += d[i];
ki[t[i]]++;
if (ki[t[i]] == 1)
x++;
}
su += x * x;
pllgreaterq q;
priority_queue<ll, vector<ll>, greater<ll>> qq;
rep(i, n) {
if (ki[t[i]] == 1) {
qq.push(d[i]);
} else {
q.push(make_pair(d[i], i));
}
}
for (ll i = n; i > k; i--) {
ll v = INF * INF;
int bt = -1;
ll v1 = INF * INF;
while (!q.empty()) {
auto p = q.top();
if (ki[t[p.second]] == 1) {
q.pop();
qq.push(p.first);
} else {
bt = p.second;
v = p.first;
break;
}
}
if (!qq.empty()) {
auto p = qq.top();
v1 = p + (x * x - (x - 1) * (x - 1));
}
su -= min(v, v1);
if (v <= v1) {
ki[t[bt]]--;
q.pop();
} else {
x--;
qq.pop();
}
}
cout << su << endl;
}
int main() {
// COMinit();
solv();
return 0;
} | [
"expression.unary.arithmetic.add"
] | 946,759 | 946,760 | u224756887 | cpp |
p03148 | #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);
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;
}
};
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;
}
double digsum(ll x) {
ll res = 0;
while (x > 0) {
res += x % 10;
x /= 10;
}
return res;
}
bool maching(char a, char b) { return (a == b || a == '?' || b == '?'); }
int getArea(ll x, ll v) {
for (size_t i = 1; i <= 3; i++) {
if (x < v * i)
return i - 1;
}
}
void solv() {
ll k;
cin >> n >> k;
ll t[100010], d[100010];
ll ki[100010];
all0(ki);
ll x = 0;
ll su = 0;
rep(i, n) {
cin >> t[i] >> d[i];
su += d[i];
ki[t[i]]++;
if (ki[t[i]] == 1)
x++;
}
su += x * x;
pllgreaterq q;
priority_queue<ll, vector<ll>, greater<ll>> qq;
rep(i, n) {
if (ki[t[i]] == 1) {
qq.push(d[i]);
} else {
q.push(make_pair(d[i], i));
}
}
for (ll i = n; i > k; i--) {
ll v = INF * INF;
int bt = -1;
ll v1 = INF * INF;
while (!q.empty()) {
auto p = q.top();
if (ki[t[p.second]] == 1) {
q.pop();
qq.push(p.first);
} else {
bt = p.second;
v = p.first;
break;
}
}
if (!qq.empty()) {
auto p = qq.top();
v1 = p + (x * x - (x - 1) * (x - 1));
}
su -= min(v, v1);
if (v < v1) {
ki[t[bt]]--;
q.pop();
} else {
qq.pop();
}
}
cout << su << 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);
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;
}
};
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;
}
double digsum(ll x) {
ll res = 0;
while (x > 0) {
res += x % 10;
x /= 10;
}
return res;
}
bool maching(char a, char b) { return (a == b || a == '?' || b == '?'); }
int getArea(ll x, ll v) {
for (size_t i = 1; i <= 3; i++) {
if (x < v * i)
return i - 1;
}
}
void solv() {
ll k;
cin >> n >> k;
ll t[100010], d[100010];
ll ki[100010];
all0(ki);
ll x = 0;
ll su = 0;
rep(i, n) {
cin >> t[i] >> d[i];
su += d[i];
ki[t[i]]++;
if (ki[t[i]] == 1)
x++;
}
su += x * x;
pllgreaterq q;
priority_queue<ll, vector<ll>, greater<ll>> qq;
rep(i, n) {
if (ki[t[i]] == 1) {
qq.push(d[i]);
} else {
q.push(make_pair(d[i], i));
}
}
for (ll i = n; i > k; i--) {
ll v = INF * INF;
int bt = -1;
ll v1 = INF * INF;
while (!q.empty()) {
auto p = q.top();
if (ki[t[p.second]] == 1) {
q.pop();
qq.push(p.first);
} else {
bt = p.second;
v = p.first;
break;
}
}
if (!qq.empty()) {
auto p = qq.top();
v1 = p + (x * x - (x - 1) * (x - 1));
}
su -= min(v, v1);
if (v <= v1) {
ki[t[bt]]--;
q.pop();
} else {
x--;
qq.pop();
}
}
cout << su << endl;
}
int main() {
// COMinit();
solv();
return 0;
} | [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change",
"expression.unary.arithmetic.add"
] | 946,761 | 946,760 | u224756887 | cpp |
p03148 | #include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define mn(x) *min_element((x).begin(), (x).end())
#define mx(x) *max_element((x).begin(), (x).end())
#define acc(x) accumulate((x).begin(), (x).end(), 0ll)
#define eb emplace_back
#define el '\n'
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<string> vs;
const ld pi = acos(-1);
const ll inf = (ll)1e12 + 1;
// const int mod=1000000007;
const int mod = 998244353;
int n, m, k;
const int N = 3e5 + 10;
struct Set_with_sum {
struct node {
int no;
ll sum;
node *l, *r;
node() : no(0), sum(0ll), l(NULL), r(NULL) {}
};
node *root;
int lo = 0, hi;
Set_with_sum(int hii) : root(new node), hi(hii){};
void insert(node *p, int l, int r, int id) {
if (l == r) {
p->sum += id;
p->no++;
return;
}
int mid = (l + r) >> 1;
if (p->l == NULL)
p->l = new node;
if (p->r == NULL)
p->r = new node;
if (id > mid) {
insert(p->r, mid + 1, r, id);
} else {
insert(p->l, l, mid, id);
}
p->sum = p->l->sum + p->r->sum;
p->no = p->l->no + p->r->no;
}
void erase(node *p, int l, int r, int id) {
if (l == r) {
p->sum -= id;
p->no--;
return;
}
int mid = (l + r) >> 1;
if (id > mid) {
erase(p->r, mid + 1, r, id);
} else {
erase(p->l, l, mid, id);
}
p->sum = p->l->sum + p->r->sum;
p->no = p->l->no + p->r->no;
}
ll query(node *p, int l, int r, int k) {
if (!k)
return 0;
if (l == r)
return (ll)k * l;
if (p->l == NULL)
p->l = new node;
if (p->r == NULL)
p->r = new node;
int m = (l + r) >> 1;
if (p->r->no > k) {
return query(p->r, m + 1, r, k);
} else {
return p->r->sum + query(p->l, l, m, k - p->r->no);
}
}
ll query(int k) { return query(root, 0, hi, k); }
void insert(int no) { insert(root, 0, hi, no); }
void erase(int no) { erase(root, 0, hi, no); }
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> k >> n;
Set_with_sum s(1e9 + 1);
priority_queue<pii, vpi> pq;
for (int i = 0, u, v; i < n; i++) {
cin >> u >> v;
s.insert(v);
pq.emplace(v, u);
}
vb mark(n + 1);
ll diff = 0;
ll a = 0, already = 0;
while (!pq.empty()) {
auto f = pq.top();
pq.pop();
if (!mark[f.se]) {
mark[f.se] = true;
already += f.fi;
diff++;
s.erase(f.fi);
a = max(a, already + s.query(k - (int)diff) + diff * diff);
if (diff == k)
break;
}
}
cout << a << el;
return 0;
}
| #include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define mn(x) *min_element((x).begin(), (x).end())
#define mx(x) *max_element((x).begin(), (x).end())
#define acc(x) accumulate((x).begin(), (x).end(), 0ll)
#define eb emplace_back
#define el '\n'
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<string> vs;
const ld pi = acos(-1);
const ll inf = (ll)1e12 + 1;
// const int mod=1000000007;
const int mod = 998244353;
int n, m, k;
const int N = 3e5 + 10;
struct Set_with_sum {
struct node {
int no;
ll sum;
node *l, *r;
node() : no(0), sum(0ll), l(NULL), r(NULL) {}
};
node *root;
int lo = 0, hi;
Set_with_sum(int hii) : root(new node), hi(hii){};
void insert(node *p, int l, int r, int id) {
if (l == r) {
p->sum += id;
p->no++;
return;
}
int mid = (l + r) >> 1;
if (p->l == NULL)
p->l = new node;
if (p->r == NULL)
p->r = new node;
if (id > mid) {
insert(p->r, mid + 1, r, id);
} else {
insert(p->l, l, mid, id);
}
p->sum = p->l->sum + p->r->sum;
p->no = p->l->no + p->r->no;
}
void erase(node *p, int l, int r, int id) {
if (l == r) {
p->sum -= id;
p->no--;
return;
}
int mid = (l + r) >> 1;
if (id > mid) {
erase(p->r, mid + 1, r, id);
} else {
erase(p->l, l, mid, id);
}
p->sum = p->l->sum + p->r->sum;
p->no = p->l->no + p->r->no;
}
ll query(node *p, int l, int r, int k) {
if (!k)
return 0;
if (l == r)
return (ll)k * l;
if (p->l == NULL)
p->l = new node;
if (p->r == NULL)
p->r = new node;
int m = (l + r) >> 1;
if (p->r->no > k) {
return query(p->r, m + 1, r, k);
} else {
return p->r->sum + query(p->l, l, m, k - p->r->no);
}
}
ll query(int k) { return query(root, 0, hi, k); }
void insert(int no) { insert(root, 0, hi, no); }
void erase(int no) { erase(root, 0, hi, no); }
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> k;
Set_with_sum s(1e9 + 1);
priority_queue<pii, vpi> pq;
for (int i = 0, u, v; i < n; i++) {
cin >> u >> v;
s.insert(v);
pq.emplace(v, u);
}
vb mark(n + 1);
ll diff = 0;
ll a = 0, already = 0;
while (!pq.empty()) {
auto f = pq.top();
pq.pop();
if (!mark[f.se]) {
mark[f.se] = true;
already += f.fi;
diff++;
s.erase(f.fi);
a = max(a, already + s.query(k - (int)diff) + diff * diff);
if (diff == k)
break;
}
}
cout << a << el;
return 0;
}
| [
"expression.operation.binary.remove"
] | 946,762 | 946,763 | u829147556 | cpp |
p03148 | #include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b - 1); i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n - 1); i >= 0; i--)
#define REP1(i, n) for (int i = 1; i <= (n); i++)
#define RREP1(i, n) for (int i = (n); i >= 1; i--)
#define ALL(a) (a).begin(), (a).end()
#define UNIQUE_SORT(l) \
sort(ALL(l)); \
l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define out(...) printf(__VA_ARGS__)
#if DEBUG
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...) /* ... */
#endif
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
void _OUT(){};
template <class H, class... T> void _OUT(H &h, T &...t) {
cout << ' ' << h;
_OUT(t...);
};
template <class H, class... T> void _P(H &h, T &...t) {
cout << h;
_OUT(t...);
};
#define _PN(...) \
_P(__VA_ARGS__); \
cout << endl;
void solve();
signed main() {
#if DEBUG
std::ifstream in("input.txt");
std::cin.rdbuf(in.rdbuf());
#endif
cin.tie(0);
ios::sync_with_stdio(false);
solve();
return 0;
}
/*================================*/
#if DEBUG
#define SIZE 100
#else
#define SIZE 223450
#endif
int N, K;
vector<int> C(SIZE), Q;
void solve() {
cin >> N >> K;
int t, d;
priority_queue<pair<int, int>> que;
REP(i, N) {
cin >> t >> d;
que.push({d, t});
}
int ans = 0, cur = 0, s = 0;
while (K--) {
auto [d, t] = que.top();
que.pop();
cur += d;
if (!C[t])
s++;
else
Q.push_back(d);
C[t] = 1;
}
chmax(ans, cur + s * s);
while (que.size()) {
auto [d, t] = que.top();
que.pop();
if (!C[t]) {
s++;
cur -= Q.back();
cur += d;
Q.pop_back();
C[t] = 1;
chmax(ans, cur + s * s);
}
}
_PN(ans);
}
| #include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b - 1); i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n - 1); i >= 0; i--)
#define REP1(i, n) for (int i = 1; i <= (n); i++)
#define RREP1(i, n) for (int i = (n); i >= 1; i--)
#define ALL(a) (a).begin(), (a).end()
#define UNIQUE_SORT(l) \
sort(ALL(l)); \
l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define out(...) printf(__VA_ARGS__)
#if DEBUG
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...) /* ... */
#endif
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
void _OUT(){};
template <class H, class... T> void _OUT(H &h, T &...t) {
cout << ' ' << h;
_OUT(t...);
};
template <class H, class... T> void _P(H &h, T &...t) {
cout << h;
_OUT(t...);
};
#define _PN(...) \
_P(__VA_ARGS__); \
cout << endl;
void solve();
signed main() {
#if DEBUG
std::ifstream in("input.txt");
std::cin.rdbuf(in.rdbuf());
#endif
cin.tie(0);
ios::sync_with_stdio(false);
solve();
return 0;
}
/*================================*/
#if DEBUG
#define SIZE 100
#else
#define SIZE 223450
#endif
int N, K;
vector<int> C(SIZE), Q;
void solve() {
cin >> N >> K;
int t, d;
priority_queue<pair<int, int>> que;
REP(i, N) {
cin >> t >> d;
que.push({d, t});
}
int ans = 0, cur = 0, s = 0;
while (K--) {
auto [d, t] = que.top();
que.pop();
cur += d;
if (!C[t])
s++;
else
Q.push_back(d);
C[t] = 1;
}
chmax(ans, cur + s * s);
while (que.size() && Q.size()) {
auto [d, t] = que.top();
que.pop();
if (!C[t]) {
s++;
cur -= Q.back();
cur += d;
Q.pop_back();
C[t] = 1;
chmax(ans, cur + s * s);
}
}
_PN(ans);
}
| [
"control_flow.loop.condition.change"
] | 946,781 | 946,782 | u113166790 | cpp |
p03148 | #include <bits/stdc++.h>
using namespace std;
#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 ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;
int main() {
ll N, K;
cin >> N >> K;
vector<pair<ll, ll>> sushi(N);
REP(i, N) {
ll t, d;
cin >> t >> d;
sushi[i] = make_pair(d, t - 1);
}
sort(ALL(sushi), greater<pair<ll, ll>>());
map<ll, ll> num;
priority_queue<pair<ll, ll>> S;
ll ans = 0;
FOR(i, K, N) { S.push(sushi[i]); }
REP(i, K) {
num[sushi[i].second]++;
ans += sushi[i].first;
}
ll f = ans;
ans += (ll)num.size() * (ll)num.size();
REPR(i, K - 1) {
if (S.empty())
break;
if (sushi[i].second > 1) { // 1種のみのやつならパス
while (!S.empty()) {
auto top_sushi = S.top();
S.pop();
if (!num.count(top_sushi.second)) { //交換対象なら
f = f - sushi[i].first + top_sushi.first;
num[top_sushi.second]++;
num[sushi[i].second]--;
ll next_ans = f + (ll)num.size() * (ll)num.size();
sushi[i] = top_sushi;
ans = max(ans, next_ans);
break;
}
}
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#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 ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;
int main() {
ll N, K;
cin >> N >> K;
vector<pair<ll, ll>> sushi(N);
REP(i, N) {
ll t, d;
cin >> t >> d;
sushi[i] = make_pair(d, t - 1);
}
sort(ALL(sushi), greater<pair<ll, ll>>());
map<ll, ll> num;
priority_queue<pair<ll, ll>> S;
ll ans = 0;
FOR(i, K, N) { S.push(sushi[i]); }
REP(i, K) {
num[sushi[i].second]++;
ans += sushi[i].first;
}
ll f = ans;
ans += (ll)num.size() * (ll)num.size();
REPR(i, K - 1) {
if (S.empty())
break;
if (num[sushi[i].second] > 1) { // 2種のやつなら
while (!S.empty()) {
auto top_sushi = S.top();
S.pop();
if (!num.count(top_sushi.second)) { //交換対象なら
f = f - sushi[i].first + top_sushi.first;
num[top_sushi.second]++;
num[sushi[i].second]--;
ll next_ans = f + (ll)num.size() * (ll)num.size();
sushi[i] = top_sushi;
ans = max(ans, next_ans);
break;
}
}
}
}
cout << ans << endl;
return 0;
} | [
"control_flow.branch.if.condition.change"
] | 946,785 | 946,786 | u116774833 | cpp |
p03148 | #include <bits/stdc++.h>
using namespace std;
#define debug(n) cerr << #n << ':' << n << endl;
#define dline cerr << __LINE__ << endl;
using ll = long long;
template <class T, class U> using P = pair<T, U>;
template <class T> using Heap = priority_queue<T>;
template <class T> using heaP = priority_queue<T, vector<T>, greater<T>>;
template <class T, class U> using umap = unordered_map<T, U>;
template <class T> using uset = unordered_set<T>;
template <class T> bool ChangeMax(T &a, const T &b) {
if (a >= b)
return false;
a = b;
return true;
}
template <class T> bool ChangeMin(T &a, const T &b) {
if (a <= b)
return false;
a = b;
return true;
}
template <class T, size_t N, class U> void Fill(T (&a)[N], const U &v) {
fill((U *)a, (U *)(a + N), v);
}
template <class T> istream &operator>>(istream &is, vector<T> &v) {
for (auto &e : v)
is >> e;
return is;
}
int main() {
ll n, k;
cin >> n >> k;
vector<P<ll, ll>> v(n);
vector<ll> vm(100001);
for (auto &e : v)
cin >> e.second >> e.first;
sort(v.rbegin(), v.rend());
ll ans = 0;
ll cnt = 0;
for (ll i = 0; i < k; ++i) {
ans += v[i].first;
vm[v[i].second]++;
if (vm[v[i].second] == 1)
cnt++;
}
ll idx = k - 1;
ll fans = ans + cnt * cnt;
for (ll i = k; i < n; ++i) {
if (vm[v[i].second] > 0)
continue;
while (idx >= 0 && vm[v[idx].second] == 1)
idx--;
if (idx < 0)
break;
ans -= v[idx].first;
ans += v[i].first;
vm[v[i].second]++;
vm[v[idx].second]--;
cnt++;
ChangeMax(fans, ans + cnt * cnt);
}
cout << fans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define debug(n) cerr << #n << ':' << n << endl;
#define dline cerr << __LINE__ << endl;
using ll = long long;
template <class T, class U> using P = pair<T, U>;
template <class T> using Heap = priority_queue<T>;
template <class T> using heaP = priority_queue<T, vector<T>, greater<T>>;
template <class T, class U> using umap = unordered_map<T, U>;
template <class T> using uset = unordered_set<T>;
template <class T> bool ChangeMax(T &a, const T &b) {
if (a >= b)
return false;
a = b;
return true;
}
template <class T> bool ChangeMin(T &a, const T &b) {
if (a <= b)
return false;
a = b;
return true;
}
template <class T, size_t N, class U> void Fill(T (&a)[N], const U &v) {
fill((U *)a, (U *)(a + N), v);
}
template <class T> istream &operator>>(istream &is, vector<T> &v) {
for (auto &e : v)
is >> e;
return is;
}
int main() {
ll n, k;
cin >> n >> k;
vector<P<ll, ll>> v(n);
vector<ll> vm(100001);
for (auto &e : v)
cin >> e.second >> e.first;
sort(v.rbegin(), v.rend());
ll ans = 0;
ll cnt = 0;
for (ll i = 0; i < k; ++i) {
ans += v[i].first;
vm[v[i].second]++;
if (vm[v[i].second] == 1)
cnt++;
}
ll idx = k - 1;
ll fans = ans + cnt * cnt;
for (ll i = k; i < n; ++i) {
if (vm[v[i].second] > 0)
continue;
while (idx >= 0 && vm[v[idx].second] == 1)
idx--;
if (idx < 0)
break;
ans -= v[idx].first;
ans += v[i].first;
vm[v[i].second]++;
vm[v[idx].second]--;
cnt++;
ChangeMax(fans, ans + cnt * cnt);
idx--;
}
cout << fans << endl;
return 0;
}
| [
"expression.unary.arithmetic.add"
] | 946,792 | 946,793 | u691380397 | cpp |
p03148 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define bg begin()
#define ed end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep1(i, n) for (ll i = 1; i <= n; i++)
#define mp(x, y) make_pair(x, y)
int main() {
ll N, K;
cin >> N >> K;
vector<P> sushi(N); //おいしさ、種類
rep(i, N) {
ll A, B;
cin >> A >> B;
sushi[i] = mp(B, A);
}
sort(sushi.bg, sushi.ed, greater<P>());
set<ll> se; //種類
priority_queue<ll, vector<ll>, greater<ll>> que;
ll point = 0;
rep(i, K) {
point += sushi[i].a;
ll S = sz(se);
se.insert(sushi[i].b);
if (sz(se) == S)
que.push(sushi[i].a);
}
ll ans = point + sz(se) * sz(se);
ll i = K;
while (i < N) {
while (i < N && se.find(sushi[i].b) != se.ed) {
i++;
}
if (que.empty())
break;
point -= que.top();
que.pop();
point += sushi[i].a;
se.insert(sushi[i].b);
ans = max(ans, point + sz(se) * sz(se));
}
cout << ans;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define bg begin()
#define ed end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep1(i, n) for (ll i = 1; i <= n; i++)
#define mp(x, y) make_pair(x, y)
int main() {
ll N, K;
cin >> N >> K;
vector<P> sushi(N); //おいしさ、種類
rep(i, N) {
ll A, B;
cin >> A >> B;
sushi[i] = mp(B, A);
}
sort(sushi.bg, sushi.ed, greater<P>());
set<ll> se; //種類
priority_queue<ll, vector<ll>, greater<ll>> que;
ll point = 0;
rep(i, K) {
point += sushi[i].a;
ll S = sz(se);
se.insert(sushi[i].b);
if (sz(se) == S)
que.push(sushi[i].a);
}
ll ans = point + sz(se) * sz(se);
ll i = K;
while (i < N) {
while (i < N && se.find(sushi[i].b) != se.ed) {
i++;
}
if (que.empty() || i == N)
break;
point -= que.top();
que.pop();
point += sushi[i].a;
se.insert(sushi[i].b);
ans = max(ans, point + sz(se) * sz(se));
}
cout << ans;
}
| [
"control_flow.branch.if.condition.change"
] | 946,811 | 946,812 | u527058497 | cpp |
p03148 | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, a, b) for (int i = (a); i < (b); ++i)
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using tl = tuple<ll, ll, ll>;
template <typename T> inline istream &operator>>(istream &i, v(T) & v) {
rep(j, sz(v)) i >> v[j];
return i;
}
template <typename T1, typename T2>
inline istream &operator>>(istream &i, pair<T1, T2> &v) {
return i >> v.fi >> v.se;
}
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;
}
ll INF = 1001001001;
ll LINF = 1001001001001001001ll;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n, k;
cin >> n >> k;
vector<LP> dt(n);
cin >> dt;
rep(i, n) swap(dt[i].fi, dt[i].se);
sort(rrng(dt));
vector<bool> used(n + 1);
vl dub;
ll kind = 0;
ll deli = 0;
rep(i, k) {
if (used[dt[i].se])
dub.push_back(dt[i].fi);
else
kind++;
used[dt[i].se] = true;
deli += dt[i].fi;
}
ll cur = deli + kind * kind;
ll ans = cur;
rrep(i, k, n) {
if (used[dt[i].se])
continue;
used[dt[i].se] = true;
deli = deli - dub.back() + dt[i].fi;
dub.pop_back();
kind++;
cur = deli + kind * kind;
chmax(ans, cur);
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, a, b) for (int i = (a); i < (b); ++i)
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using tl = tuple<ll, ll, ll>;
template <typename T> inline istream &operator>>(istream &i, v(T) & v) {
rep(j, sz(v)) i >> v[j];
return i;
}
template <typename T1, typename T2>
inline istream &operator>>(istream &i, pair<T1, T2> &v) {
return i >> v.fi >> v.se;
}
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;
}
ll INF = 1001001001;
ll LINF = 1001001001001001001ll;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n, k;
cin >> n >> k;
vector<LP> dt(n);
cin >> dt;
rep(i, n) swap(dt[i].fi, dt[i].se);
sort(rrng(dt));
vector<bool> used(n + 1);
vl dub;
ll kind = 0;
ll deli = 0;
rep(i, k) {
if (used[dt[i].se])
dub.push_back(dt[i].fi);
else
kind++;
used[dt[i].se] = true;
deli += dt[i].fi;
}
ll cur = deli + kind * kind;
ll ans = cur;
rrep(i, k, n) {
if (used[dt[i].se] || dub.empty())
continue;
used[dt[i].se] = true;
deli = deli - dub.back() + dt[i].fi;
dub.pop_back();
kind++;
cur = deli + kind * kind;
chmax(ans, cur);
}
cout << ans << endl;
} | [
"control_flow.branch.if.condition.change"
] | 946,845 | 946,846 | u482770395 | cpp |
p03148 | #include <bits/stdc++.h>
using namespace std;
#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
#define repp(i, start, to) for (li i = (li)(start); i < ((li)(to)); i++)
#define pb push_back
#define sz(v) ((li)(v).size())
#define bgn(v) ((v).begin())
#define eend(v) ((v).end())
#define allof(v) (v).begin(), (v).end()
#define dodp(v, n) memset(v, (li)n, sizeof(v))
#define bit(n) (1ll << (li)(n))
#define mp(a, b) make_pair(a, b)
#define rin rep(i, n)
#define EPS 1e-12
#define ETOL 1e-8
typedef pair<li, li> PI;
#define INF bit(60)
#define DBGP 1
#define idp if (DBGP)
#define F first
#define S second
#define p2(a, b) idp cout << a << "\t" << b << endl
#define p3(a, b, c) idp cout << a << "\t" << b << "\t" << c << endl
#define p4(a, b, c, d) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << endl
#define p5(a, b, c, d, e) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << endl
#define p6(a, b, c, d, e, f) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \
<< f << endl
#define p7(a, b, c, d, e, f, g) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \
<< f << "\t" << g << endl
#define p8(a, b, c, d, e, f, g, h) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \
<< f << "\t" << g << "\t" << h << endl
#define p9(a, b, c, d, e, f, g, h, i) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \
<< f << "\t" << g << "\t" << h << "\t" << i << endl
#define p10(a, b, c, d, e, f, g, h, i, j) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \
<< f << "\t" << g << "\t" << h << "\t" << i << "\t" << j << endl
#define foreach(it, v) \
for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); ++it)
#define p2p(x) idp p2((x).F, (x).S)
#define dump(x, n) \
idp { \
rep(i, n) { cout << x[i] << " "; } \
puts(""); \
}
#define dump2(x, n) \
idp { \
rep(i, n) { cout << "[" << x[i].F << " , " << x[i].S << "] "; } \
puts(""); \
}
#define dumpi(x) \
idp { \
foreach (it, x) { cout << (*it) << " "; } \
puts(""); \
}
#define dumpi2(x) \
idp { \
foreach (it, x) { cout << "[" << (it)->F << " , " << (it)->S << "] "; } \
puts(""); \
}
#define read2d(a, w, h) rep(i, h) rep(j, w) cin >> a[i][j]
#define dump2d(a, w, h) \
rep(i, h) { \
rep(j, w) cout << a[i][j] << " "; \
puts(""); \
}
typedef pair<li, li> PI;
li n, k;
// {おいしさ, 種類}
PI val[100100];
int main() {
cin >> n >> k;
rin { cin >> val[i].S >> val[i].F; }
sort(val, val + n);
reverse(val, val + n);
li now = 0;
set<li> st;
priority_queue<li> pq;
rep(i, k) {
now += val[i].F;
if (st.count(val[i].S) > 0) {
pq.push(-val[i].F);
}
st.insert(val[i].S);
}
li res = now + sz(st) * sz(st);
repp(i, k, n) {
if (st.count(val[i].S) > 0) {
continue;
}
if (pq.empty()) {
break;
}
now = now - (-pq.top()) + val[i].F;
st.insert(val[i].S);
res = max(res, now + sz(st) * sz(st));
}
cout << res << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
#define repp(i, start, to) for (li i = (li)(start); i < ((li)(to)); i++)
#define pb push_back
#define sz(v) ((li)(v).size())
#define bgn(v) ((v).begin())
#define eend(v) ((v).end())
#define allof(v) (v).begin(), (v).end()
#define dodp(v, n) memset(v, (li)n, sizeof(v))
#define bit(n) (1ll << (li)(n))
#define mp(a, b) make_pair(a, b)
#define rin rep(i, n)
#define EPS 1e-12
#define ETOL 1e-8
typedef pair<li, li> PI;
#define INF bit(60)
#define DBGP 1
#define idp if (DBGP)
#define F first
#define S second
#define p2(a, b) idp cout << a << "\t" << b << endl
#define p3(a, b, c) idp cout << a << "\t" << b << "\t" << c << endl
#define p4(a, b, c, d) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << endl
#define p5(a, b, c, d, e) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << endl
#define p6(a, b, c, d, e, f) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \
<< f << endl
#define p7(a, b, c, d, e, f, g) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \
<< f << "\t" << g << endl
#define p8(a, b, c, d, e, f, g, h) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \
<< f << "\t" << g << "\t" << h << endl
#define p9(a, b, c, d, e, f, g, h, i) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \
<< f << "\t" << g << "\t" << h << "\t" << i << endl
#define p10(a, b, c, d, e, f, g, h, i, j) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \
<< f << "\t" << g << "\t" << h << "\t" << i << "\t" << j << endl
#define foreach(it, v) \
for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); ++it)
#define p2p(x) idp p2((x).F, (x).S)
#define dump(x, n) \
idp { \
rep(i, n) { cout << x[i] << " "; } \
puts(""); \
}
#define dump2(x, n) \
idp { \
rep(i, n) { cout << "[" << x[i].F << " , " << x[i].S << "] "; } \
puts(""); \
}
#define dumpi(x) \
idp { \
foreach (it, x) { cout << (*it) << " "; } \
puts(""); \
}
#define dumpi2(x) \
idp { \
foreach (it, x) { cout << "[" << (it)->F << " , " << (it)->S << "] "; } \
puts(""); \
}
#define read2d(a, w, h) rep(i, h) rep(j, w) cin >> a[i][j]
#define dump2d(a, w, h) \
rep(i, h) { \
rep(j, w) cout << a[i][j] << " "; \
puts(""); \
}
typedef pair<li, li> PI;
li n, k;
// {おいしさ, 種類}
PI val[100100];
int main() {
cin >> n >> k;
rin { cin >> val[i].S >> val[i].F; }
sort(val, val + n);
reverse(val, val + n);
li now = 0;
set<li> st;
priority_queue<li> pq;
rep(i, k) {
now += val[i].F;
if (st.count(val[i].S) > 0) {
pq.push(-val[i].F);
}
st.insert(val[i].S);
}
li res = now + sz(st) * sz(st);
repp(i, k, n) {
if (st.count(val[i].S) > 0) {
continue;
}
if (pq.empty()) {
break;
}
now = now - (-pq.top()) + val[i].F;
pq.pop();
st.insert(val[i].S);
res = max(res, now + sz(st) * sz(st));
}
cout << res << endl;
return 0;
} | [
"call.add"
] | 946,849 | 946,850 | u962966398 | cpp |
p03148 | #include <bits/stdc++.h>
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL << 60;
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
ll modpow(ll a, ll n, ll mod) {
ll res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, k;
cin >> n >> k;
vector<pair<ll, int>> sushi(n);
rep(i, n) {
int t;
ll d;
cin >> t >> d;
sushi[i] = make_pair(d, t);
}
sort(sushi.rbegin(), sushi.rend());
map<int, int> mp;
auto c = [](pair<ll, int> a, pair<ll, int> b) { return a.first > b.first; };
priority_queue<pair<ll, int>, vector<pair<ll, int>>, decltype(c)> que(c);
ll point = 0;
rep(i, k) {
point += sushi[i].first;
que.push(sushi[i]);
mp[sushi[i].second]++;
}
point += (mp.size() * mp.size());
ll V = mp.size();
ll ans = point;
rep(i, k, n) {
ll val = sushi[i].first;
ll t = sushi[i].second;
if (mp[t] > 0)
continue;
while (mp[que.top().second] == 1) {
if (que.empty())
break;
que.pop();
}
if (que.empty())
break;
auto p = que.top();
mp[p.second]--;
point -= p.first;
point += val;
point += 2 * V + 1;
V++;
chmax(ans, point);
mp[t]++;
que.push(sushi[i]);
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL << 60;
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
ll modpow(ll a, ll n, ll mod) {
ll res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, k;
cin >> n >> k;
vector<pair<ll, int>> sushi(n);
rep(i, n) {
int t;
ll d;
cin >> t >> d;
sushi[i] = make_pair(d, t);
}
sort(sushi.rbegin(), sushi.rend());
map<int, int> mp;
auto c = [](pair<ll, int> a, pair<ll, int> b) { return a.first > b.first; };
priority_queue<pair<ll, int>, vector<pair<ll, int>>, decltype(c)> que(c);
ll point = 0;
rep(i, k) {
point += sushi[i].first;
que.push(sushi[i]);
mp[sushi[i].second]++;
}
point += (mp.size() * mp.size());
ll V = mp.size();
ll ans = point;
rep(i, k, n) {
ll val = sushi[i].first;
ll t = sushi[i].second;
if (mp[t] > 0)
continue;
while (mp[que.top().second] == 1) {
if (que.empty())
break;
que.pop();
}
if (que.empty())
break;
auto p = que.top();
mp[p.second]--;
que.pop();
point -= p.first;
point += val;
point += 2 * V + 1;
V++;
chmax(ans, point);
mp[t]++;
que.push(sushi[i]);
}
cout << ans << endl;
return 0;
}
| [
"call.add"
] | 946,869 | 946,870 | u187878098 | cpp |
p03148 | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)
const ll MOD = 1000000007;
const ll INF = (ll)1e15;
pll A[100005];
ll U[100005];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll K, N;
cin >> K >> N;
REP(i, N) { cin >> A[i].first >> A[i].second; }
sort(A, A + N, [](pll a, pll b) { return a.second > b.second; });
memset(U, 0, sizeof(U));
ll ans = 0;
priority_queue<pll, vector<pll>, function<bool(pll, pll)>> q(
[](pll a, pll b) { return a.second < b.second; });
ll k = 0;
ll x = 0;
ll sum = 0;
REP(i, N) {
k++;
if (k <= K) {
sum += A[i].second;
U[A[i].first]++;
if (U[A[i].first] > 1) {
q.push(A[i]);
} else {
x++;
}
ans = std::max(ans, sum + x * x);
continue;
}
if (U[A[i].first] > 0)
continue;
if (!q.empty()) {
pll t = q.top();
q.pop();
sum = sum - t.second + A[i].second;
U[A[i].first]++;
x++;
ans = std::max(ans, sum + x * x);
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)
const ll MOD = 1000000007;
const ll INF = (ll)1e15;
pll A[100005];
ll U[100005];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll K, N;
cin >> N >> K;
REP(i, N) { cin >> A[i].first >> A[i].second; }
sort(A, A + N, [](pll a, pll b) { return a.second > b.second; });
memset(U, 0, sizeof(U));
ll ans = 0;
priority_queue<pll, vector<pll>, function<bool(pll, pll)>> q(
[](pll a, pll b) { return a.second > b.second; });
ll k = 0;
ll x = 0;
ll sum = 0;
REP(i, N) {
k++;
if (k <= K) {
sum += A[i].second;
U[A[i].first]++;
if (U[A[i].first] > 1) {
q.push(A[i]);
} else {
x++;
}
ans = std::max(ans, sum + x * x);
continue;
}
if (U[A[i].first] > 0)
continue;
if (!q.empty()) {
pll t = q.top();
q.pop();
sum = sum - t.second + A[i].second;
U[A[i].first]++;
x++;
ans = std::max(ans, sum + x * x);
}
}
cout << ans << endl;
return 0;
} | [
"expression.operation.binary.remove",
"misc.opposites",
"expression.operator.compare.change",
"call.arguments.change",
"function.return_value.change",
"expression.operation.binary.change"
] | 946,878 | 946,879 | u340980616 | cpp |
p03148 | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)
const ll MOD = 1000000007;
const ll INF = (ll)1e15;
pll A[100005];
ll U[100005];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll K, N;
cin >> K >> N;
REP(i, N) { cin >> A[i].first >> A[i].second; }
sort(A, A + N, [](pll a, pll b) { return a.second > b.second; });
memset(U, 0, sizeof(U));
ll ans = 0;
priority_queue<pll, vector<pll>, function<bool(pll, pll)>> q(
[](pll a, pll b) { return a.second > b.second; });
ll k = 0;
ll x = 0;
ll sum = 0;
REP(i, N) {
k++;
if (k <= K) {
sum += A[i].second;
U[A[i].first]++;
if (U[A[i].first] > 1) {
q.push(A[i]);
} else {
x++;
}
ans = std::max(ans, sum + x * x);
continue;
}
if (U[A[i].first] > 0)
continue;
if (!q.empty()) {
pll t = q.top();
q.pop();
sum = sum - t.second + A[i].second;
U[A[i].first]++;
x++;
ans = std::max(ans, sum + x * x);
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)
const ll MOD = 1000000007;
const ll INF = (ll)1e15;
pll A[100005];
ll U[100005];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll K, N;
cin >> N >> K;
REP(i, N) { cin >> A[i].first >> A[i].second; }
sort(A, A + N, [](pll a, pll b) { return a.second > b.second; });
memset(U, 0, sizeof(U));
ll ans = 0;
priority_queue<pll, vector<pll>, function<bool(pll, pll)>> q(
[](pll a, pll b) { return a.second > b.second; });
ll k = 0;
ll x = 0;
ll sum = 0;
REP(i, N) {
k++;
if (k <= K) {
sum += A[i].second;
U[A[i].first]++;
if (U[A[i].first] > 1) {
q.push(A[i]);
} else {
x++;
}
ans = std::max(ans, sum + x * x);
continue;
}
if (U[A[i].first] > 0)
continue;
if (!q.empty()) {
pll t = q.top();
q.pop();
sum = sum - t.second + A[i].second;
U[A[i].first]++;
x++;
ans = std::max(ans, sum + x * x);
}
}
cout << ans << endl;
return 0;
} | [
"expression.operation.binary.remove"
] | 946,880 | 946,879 | u340980616 | cpp |
p03148 | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
int main() {
ll n, k;
scanf("%lld %lld", &n, &k);
vector<pll> a(n);
ll f, s;
for (int i = 0; i < n; i++) {
scanf("%lld %lld", &f, &s);
a[i].second = f;
a[i].first = s;
}
// 美味しさ降順にソート
sort(a.begin(), a.end(), greater<pll>());
ll ans = 0;
ll sum = 0; // 美味しさ sum
ll kind = 0; // 何種類食べたか
// 降順に並べるpriority queue
priority_queue<ll, vector<ll>, greater<ll>> PQ;
// 食べた種類を格納する
set<ll> S;
for (int i = 0; i < k; i++) {
sum += a[i].first;
if (S.count(a[i].second) == 0) {
kind++;
S.insert(a[i].second);
} else {
PQ.push(a[i].first);
}
}
ans = sum + kind * kind;
// 美味しさがk番目に大きいやつ以降を調べる
for (ll i = k; i < n; i++) {
if (PQ.empty())
break;
// i 番目のやつがまだ食べてない種類なら
if (S.count(a[i].second == 0)) {
kind++;
sum -= PQ.top();
PQ.pop();
sum += a[i].first;
S.insert(a[i].second);
ans = max(ans, sum + kind * kind);
}
}
printf("%lld\n", ans);
}
| #include <algorithm>
#include <cmath>
#include <cstdio>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
int main() {
ll n, k;
scanf("%lld %lld", &n, &k);
vector<pll> a(n);
ll f, s;
for (int i = 0; i < n; i++) {
scanf("%lld %lld", &f, &s);
a[i].second = f;
a[i].first = s;
}
// 美味しさ降順にソート
sort(a.begin(), a.end(), greater<pll>());
ll ans = 0;
ll sum = 0; // 美味しさ sum
ll kind = 0; // 何種類食べたか
// 降順に並べるpriority queue
priority_queue<ll, vector<ll>, greater<ll>> PQ;
// 食べた種類を格納する
set<ll> S;
for (int i = 0; i < k; i++) {
sum += a[i].first;
if (S.count(a[i].second) == 0) {
kind++;
S.insert(a[i].second);
} else {
PQ.push(a[i].first);
}
}
ans = sum + kind * kind;
// 美味しさがk番目に大きいやつ以降を調べる
for (ll i = k; i < n; i++) {
if (PQ.empty())
break;
// i 番目のやつがまだ食べてない種類なら
if (S.count(a[i].second) == 0) {
kind++;
sum -= PQ.top();
PQ.pop();
sum += a[i].first;
S.insert(a[i].second);
ans = max(ans, sum + kind * kind);
}
}
printf("%lld\n", ans);
}
| [
"control_flow.branch.if.condition.change"
] | 946,897 | 946,898 | u603234915 | cpp |
p03148 | #include <bits/stdc++.h>
using namespace std;
using ll = int_fast64_t;
using ld = long double;
using pll = pair<ll, ll>;
constexpr ll INF = 1LL << 60, MOD = 1e9 + 7; // 998244353;
void solve();
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
solve();
return 0;
}
#define SELECTOR(_1, _2, _3, _4, SELECT, ...) SELECT
#define rep(...) SELECTOR(__VA_ARGS__, _rep2, _rep1, _rep0)(__VA_ARGS__)
#define _rep0(i, n) for (ll i = 0; i < n; ++i)
#define _rep1(i, k, n) for (ll i = k; i < n; ++i)
#define _rep2(i, k, n, d) for (ll i = k; d > 0 ? i < n : i > n; i += d)
#define foreach(a, A) for (auto &a : A)
#define endl "\n"
#ifdef __LOCAL
#include "ostreams.h"
#endif
template <class T> inline bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T> vector<T> make_vector(size_t a, T b) {
return vector<T>(a, b);
}
template <class... Ts> auto make_vector(size_t a, Ts... ts) {
return vector<decltype(make_vector(ts...))>(a, make_vector(ts...));
}
void print() { cerr << endl; }
template <class T, class... Ts> void print(const T &a, const Ts &...ts) {
cerr << a << ' ';
print(ts...);
}
void solve() {
ll n, k;
cin >> n >> k;
ll max_kind = 0;
priority_queue<pll> heap;
rep(_, n) {
ll t, d;
cin >> t >> d;
t--;
heap.emplace(d, t);
chmax(max_kind, t + 1);
}
auto counter = make_vector(max_kind, (ll)0);
ll score = 0;
priority_queue<pll, vector<pll>, greater<pll>> candidate;
rep(_, k) {
ll t, d;
tie(d, t) = heap.top();
heap.pop();
counter[t]++;
score += d;
candidate.emplace(d, t);
}
ll kind = 0;
foreach (cnt, counter) { kind += (cnt > 0); }
score += kind * kind;
ll res = score;
while (!heap.empty() and !candidate.empty()) {
bool flag = false;
while (!candidate.empty()) {
ll tmp_t, tmp_d;
tie(tmp_d, tmp_t) = candidate.top();
candidate.pop();
if (counter[tmp_t] <= 1)
continue;
counter[tmp_t]--;
score -= tmp_d;
flag = true;
break;
}
if (!flag)
break;
flag = true;
while (!heap.empty()) {
ll tmp_t, tmp_d;
tie(tmp_d, tmp_t) = heap.top();
heap.pop();
if (counter[tmp_t])
continue;
counter[tmp_t]++;
kind++;
score += tmp_d;
flag = true;
break;
}
if (flag) {
score -= (kind - 1) * (kind - 1);
score += kind * kind;
chmax(res, score);
}
}
cout << res << endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = int_fast64_t;
using ld = long double;
using pll = pair<ll, ll>;
constexpr ll INF = 1LL << 60, MOD = 1e9 + 7; // 998244353;
void solve();
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
solve();
return 0;
}
#define SELECTOR(_1, _2, _3, _4, SELECT, ...) SELECT
#define rep(...) SELECTOR(__VA_ARGS__, _rep2, _rep1, _rep0)(__VA_ARGS__)
#define _rep0(i, n) for (ll i = 0; i < n; ++i)
#define _rep1(i, k, n) for (ll i = k; i < n; ++i)
#define _rep2(i, k, n, d) for (ll i = k; d > 0 ? i < n : i > n; i += d)
#define foreach(a, A) for (auto &a : A)
#define endl "\n"
#ifdef __LOCAL
#include "ostreams.h"
#endif
template <class T> inline bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T> vector<T> make_vector(size_t a, T b) {
return vector<T>(a, b);
}
template <class... Ts> auto make_vector(size_t a, Ts... ts) {
return vector<decltype(make_vector(ts...))>(a, make_vector(ts...));
}
void print() { cerr << endl; }
template <class T, class... Ts> void print(const T &a, const Ts &...ts) {
cerr << a << ' ';
print(ts...);
}
void solve() {
ll n, k;
cin >> n >> k;
ll max_kind = 0;
priority_queue<pll> heap;
rep(_, n) {
ll t, d;
cin >> t >> d;
t--;
heap.emplace(d, t);
chmax(max_kind, t + 1);
}
auto counter = make_vector(max_kind, (ll)0);
ll score = 0;
priority_queue<pll, vector<pll>, greater<pll>> candidate;
rep(_, k) {
ll t, d;
tie(d, t) = heap.top();
heap.pop();
counter[t]++;
score += d;
candidate.emplace(d, t);
}
ll kind = 0;
foreach (cnt, counter) { kind += (cnt > 0); }
score += kind * kind;
ll res = score;
while (!heap.empty() and !candidate.empty()) {
bool flag = false;
while (!candidate.empty()) {
ll tmp_t, tmp_d;
tie(tmp_d, tmp_t) = candidate.top();
candidate.pop();
if (counter[tmp_t] <= 1)
continue;
counter[tmp_t]--;
score -= tmp_d;
flag = true;
break;
}
if (!flag)
break;
flag = false;
while (!heap.empty()) {
ll tmp_t, tmp_d;
tie(tmp_d, tmp_t) = heap.top();
heap.pop();
if (counter[tmp_t])
continue;
counter[tmp_t]++;
kind++;
score += tmp_d;
flag = true;
break;
}
if (flag) {
score -= (kind - 1) * (kind - 1);
score += kind * kind;
chmax(res, score);
}
}
cout << res << endl;
} | [
"misc.opposites",
"assignment.value.change"
] | 946,901 | 946,902 | u440566786 | cpp |
p03148 | #include <bits/stdc++.h>
using namespace std;
using ll = long long int;
int main(void) {
constexpr ll MOD = 1e9 + 7;
cout << fixed << setprecision(16);
ll n, k;
cin >> n >> k;
vector<pair<ll, ll>> v(n);
for (auto &e : v)
cin >> e.second >> e.first;
sort(v.begin(), v.end(), greater<>());
ll kiso = 0;
map<ll, ll> cnt;
for (ll i = 0; i < k; i++)
kiso += v[i].first, cnt[v[i].second]++;
ll kind = cnt.size();
ll res = kiso + kind * kind;
ll i = k, j = k - 1;
while (1) {
while (i < n && cnt.count(v[i].second))
i++;
if (i >= n)
break;
while (j >= 0 && cnt[v[j].second] > 1)
j--;
if (j < 0)
break;
kiso += v[i].first - v[j].first;
kind++;
res = max(res, kiso + kind * kind);
cnt[v[j].second]--;
cnt[v[i].second]++;
i++, j--;
}
cout << res << endl;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long int;
int main(void) {
constexpr ll MOD = 1e9 + 7;
cout << fixed << setprecision(16);
ll n, k;
cin >> n >> k;
vector<pair<ll, ll>> v(n);
for (auto &e : v)
cin >> e.second >> e.first;
sort(v.begin(), v.end(), greater<>());
ll kiso = 0;
map<ll, ll> cnt;
for (ll i = 0; i < k; i++)
kiso += v[i].first, cnt[v[i].second]++;
ll kind = cnt.size();
ll res = kiso + kind * kind;
ll i = k, j = k - 1;
while (1) {
while (i < n && cnt.count(v[i].second))
i++;
if (i >= n)
break;
while (j >= 0 && cnt[v[j].second] <= 1)
j--;
if (j < 0)
break;
kiso += v[i].first - v[j].first;
kind++;
res = max(res, kiso + kind * kind);
cnt[v[j].second]--;
cnt[v[i].second]++;
i++, j--;
}
cout << res << endl;
}
| [
"expression.operator.compare.change",
"control_flow.loop.condition.change"
] | 946,911 | 946,912 | u056944756 | cpp |
p03149 | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
for (int i = 0; i < 4; i++) {
cin >> s.at(i);
}
sort(s.begin(), s.end());
string k = "NO";
if (s == "1479") {
k = "YES";
}
cout << k << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
string s = " ";
for (int i = 0; i < 4; i++) {
cin >> s.at(i);
}
sort(s.begin(), s.end());
string k = "NO";
if (s == "1479") {
k = "YES";
}
cout << k << endl;
return 0;
}
| [
"variable_declaration.value.change"
] | 946,913 | 946,914 | u323864528 | cpp |
p03149 | #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
//#define int long long
#define ll long long
//#define int unsigned long long
#define pb push_back
#define double long double
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
const int N = 300000;
const int K = 19;
int a[N];
main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
// freopen("input.txt", "r", stdin);
cin >> a[0] >> a[1] >> a[2] >> a[3];
sort(a, a + 3);
if (a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9) {
cout << "YES";
return 0;
}
cout << "NO";
}
| #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
//#define int long long
#define ll long long
//#define int unsigned long long
#define pb push_back
#define double long double
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
const int N = 300000;
const int K = 19;
int a[N];
main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
// freopen("input.txt", "r", stdin);
cin >> a[0] >> a[1] >> a[2] >> a[3];
sort(a, a + 4);
if (a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9) {
cout << "YES";
return 0;
}
cout << "NO";
}
| [
"literal.number.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 946,917 | 946,918 | u373008269 | cpp |
p03149 | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1000000007, INF = 1e9;
int main() {
set<int> s;
rep(i, 4) {
int a;
cin >> a;
s.insert(a);
}
if (s.count(1) && s.count(4) && s.count(7) && s.count(9)) {
cout << "Yes" << endl;
} else
cout << "No" << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1000000007, INF = 1e9;
int main() {
set<int> s;
rep(i, 4) {
int a;
cin >> a;
s.insert(a);
}
if (s.count(1) && s.count(4) && s.count(7) && s.count(9)) {
cout << "YES" << endl;
} else
cout << "NO" << endl;
} | [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 946,919 | 946,920 | u506765399 | cpp |
p03149 | #include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
int main(void) {
int a, b, c, d;
cin >> a >> b >> c >> d;
if ((a - 1) * (b - 1) * (c - 1) * (d - 1) == 0 &&
(a - 4) * (b - 4) * (c - 4) * (d - 4) == 0 &&
(a - 7) * (b - 7) * (c - 7) * (d - 7) == 0 &&
(a - 9) * (b - 9) * (c - 9) * (d - 9) == 0) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
} | #include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
int main(void) {
int a, b, c, d;
cin >> a >> b >> c >> d;
if ((a - 1) * (b - 1) * (c - 1) * (d - 1) == 0 &&
(a - 4) * (b - 4) * (c - 4) * (d - 4) == 0 &&
(a - 7) * (b - 7) * (c - 7) * (d - 7) == 0 &&
(a - 9) * (b - 9) * (c - 9) * (d - 9) == 0) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
} | [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 946,921 | 946,922 | u757373026 | cpp |
p03149 | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < n; i++)
#define REPR(i, n) for (int64_t i = n; i >= 0; i--)
#define FOR(i, m, n) for (int64_t i = m; i < n; i++)
#define FORR(i, m, n) for (int64_t i = m; i >= n; i--)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
fill((T *)array, (T *)(array + N), val);
}
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;
}
const ll INF = 1ll << 60;
const ll MOD = 1000000007;
double EPS = 1e-10;
//----------------------------------------------------------
char C;
bool n[10];
int main() {
int N[4];
cin >> N[0] >> N[1] >> N[2] >> N[3];
REP(i, 4) { n[N[i]] = true; }
if (n[1] && n[9] && n[7] && n[4])
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < n; i++)
#define REPR(i, n) for (int64_t i = n; i >= 0; i--)
#define FOR(i, m, n) for (int64_t i = m; i < n; i++)
#define FORR(i, m, n) for (int64_t i = m; i >= n; i--)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
fill((T *)array, (T *)(array + N), val);
}
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;
}
const ll INF = 1ll << 60;
const ll MOD = 1000000007;
double EPS = 1e-10;
//----------------------------------------------------------
char C;
bool n[10];
int main() {
int N[4];
cin >> N[0] >> N[1] >> N[2] >> N[3];
REP(i, 4) { n[N[i]] = true; }
if (n[1] && n[9] && n[7] && n[4])
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
} | [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 946,923 | 946,924 | u567406270 | cpp |
p03149 | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
int main() {
vector<int> N(4);
rep(i, 4) { cin >> N[i]; }
sort(N.begin(), N.end());
int x[4] = {1, 4, 7, 9};
rep(i, 4) {
if (N[i] != x[i]) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
int main() {
vector<int> N(4);
rep(i, 4) { cin >> N[i]; }
sort(N.begin(), N.end());
int x[4] = {1, 4, 7, 9};
rep(i, 4) {
if (N[i] != x[i]) {
cout << "NO" << endl;
return 0;
}
}
cout << "YES" << endl;
return 0;
} | [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 946,929 | 946,930 | u828388155 | cpp |
p03149 | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
int main() {
vector<int> N(4);
rep(i, 4) { cin >> N[i]; }
sort(N.begin(), N.end());
int x[4] = {1, 4, 7, 9};
rep(i, 4) {
if (N[i] != x[i]) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
int main() {
vector<int> N(4);
rep(i, 4) { cin >> N[i]; }
sort(N.begin(), N.end());
int x[4] = {1, 4, 7, 9};
rep(i, 4) {
if (N[i] != x[i]) {
cout << "NO" << endl;
return 0;
}
}
cout << "YES" << endl;
return 0;
} | [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 946,931 | 946,930 | u828388155 | cpp |
p03149 | #include <bits/stdc++.h>
using namespace std;
int main(void) {
int a;
string s = "";
for (int i = 0; i < 4; i++) {
cin >> a;
s.at(i) = '0' + a;
}
sort(s.begin(), s.end());
if (s == "1479") {
cout << "YES";
} else {
cout << "NO";
}
} | #include <bits/stdc++.h>
using namespace std;
int main(void) {
int a;
string s = "9999";
for (int i = 0; i < 4; i++) {
cin >> a;
s.at(i) = '0' + a;
}
sort(s.begin(), s.end());
if (s == "1479") {
cout << "YES";
} else {
cout << "NO";
}
} | [
"literal.string.change",
"variable_declaration.value.change"
] | 946,966 | 946,967 | u259356079 | cpp |
p03149 | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s.at(0) >> s.at(1) >> s.at(2) >> s.at(3);
sort(s.begin(), s.end());
if (s == "1479")
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string s = "0000";
cin >> s.at(0) >> s.at(1) >> s.at(2) >> s.at(3);
sort(s.begin(), s.end());
if (s == "1479")
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
} | [
"variable_declaration.value.change"
] | 946,968 | 946,969 | u091552241 | cpp |
p03149 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
int main() {
vector<int> A(4);
cin >> A[0];
cin >> A[1];
cin >> A[2];
cin >> A[3];
sort(A.begin(), A.end());
int temp = A[0] * 1000 + A[1] * 100 + A[2] * 10 + A[3];
if (temp == 1974) {
cout << "YES";
} else {
cout << "NO";
}
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
int main() {
vector<int> A(4);
cin >> A[0];
cin >> A[1];
cin >> A[2];
cin >> A[3];
sort(A.begin(), A.end());
int temp = A[0] * 1000 + A[1] * 100 + A[2] * 10 + A[3];
if (temp == 1479) {
cout << "YES";
} else {
cout << "NO";
}
} | [
"literal.number.change",
"control_flow.branch.if.condition.change"
] | 946,975 | 946,976 | u653388379 | cpp |
p03149 | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> N(4);
for (int i = 0; i < 4; ++i) {
cin >> N[i];
}
sort(N.begin(), N.end());
if (N[0] == 1 && N[1] == 9 && N[2] == 7 && N[3] == 4) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> N(4);
for (int i = 0; i < 4; ++i) {
cin >> N[i];
}
sort(N.begin(), N.end());
if (N[0] == 1 && N[1] == 4 && N[2] == 7 && N[3] == 9) {
cout << "YES" << endl;
}
else {
cout << "NO" << endl;
}
}
| [
"literal.number.change",
"control_flow.branch.if.condition.change"
] | 946,977 | 946,978 | u091026689 | cpp |
p03149 | #include <bits/stdc++.h>
using namespace std;
int main() {
map<string, int> mp = {{"1", 0}, {"9", 0}, {"7", 0}, {"4", 0}};
string N;
bool ans = true;
for (int i = 0; i < 4; i++) {
cin >> N;
auto itr = mp.find(N);
if (itr != mp.end())
mp.at(N)++;
}
map<string, int>::iterator it;
for (it = mp.begin(); it != mp.end(); it++) {
if (it->second != 1) {
ans = false;
break;
}
}
if (ans)
cout << "Yes" << endl;
else
cout << "No" << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
map<string, int> mp = {{"1", 0}, {"9", 0}, {"7", 0}, {"4", 0}};
string N;
bool ans = true;
for (int i = 0; i < 4; i++) {
cin >> N;
auto itr = mp.find(N);
if (itr != mp.end())
mp.at(N)++;
}
map<string, int>::iterator it;
for (it = mp.begin(); it != mp.end(); it++) {
if (it->second != 1) {
ans = false;
break;
}
}
if (ans)
cout << "YES" << endl;
else
cout << "NO" << endl;
} | [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 946,979 | 946,980 | u941353562 | cpp |
p03149 | #include <iostream>
using namespace std;
int main() {
int a = 0, b = 0, c = 0, d = 0;
for (int i = 0; i < 4; i++) {
int s;
cin >> s;
if (s == 1)
a++;
else if (s == 9)
b++;
else if (s == 7)
c++;
else if (s == 4)
d++;
}
if (a == 1 && b == 1 && c == 1 && d == 1)
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
} | #include <iostream>
using namespace std;
int main() {
int a = 0, b = 0, c = 0, d = 0;
for (int i = 0; i < 4; i++) {
int s;
cin >> s;
if (s == 1)
a++;
else if (s == 9)
b++;
else if (s == 7)
c++;
else if (s == 4)
d++;
}
if (a == 1 && b == 1 && c == 1 && d == 1)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
} | [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 946,989 | 946,990 | u513736711 | cpp |
p03149 | #include <bits/stdc++.h>
using namespace std;
class Main {
private:
public:
int n;
};
int main() {
// cout << n <<endl;
vector<int> list(4);
for (int i = 0; i < 4; i++) {
cin >> list.at(i);
}
bool b;
b = (count(list.begin(), list.end(), 1) == 1 &&
count(list.begin(), list.end(), 7) == 1 &&
count(list.begin(), list.end(), 9) == 1 &&
count(list.begin(), list.end(), 2) == 1);
string s;
s = b ? "YES" : "NO";
cout << s;
} | #include <bits/stdc++.h>
using namespace std;
class Main {
private:
public:
int n;
};
int main() {
// cout << n <<endl;
vector<int> list(4);
for (int i = 0; i < 4; i++) {
cin >> list.at(i);
}
bool b;
b = (count(list.begin(), list.end(), 1) == 1 &&
count(list.begin(), list.end(), 7) == 1 &&
count(list.begin(), list.end(), 9) == 1 &&
count(list.begin(), list.end(), 4) == 1);
string s;
s = b ? "YES" : "NO";
cout << s;
} | [
"literal.number.change",
"assignment.value.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 946,991 | 946,992 | u982152304 | cpp |
p03149 | #include <iostream>
using namespace std;
int main() {
char a[4];
cin >> a[0] >> a[1] >> a[2] >> a[3];
int p = 0;
int q = 0;
int r = 0;
int s = 0;
for (int i = 0; i < 4; i++) {
switch (a[i]) {
case '1':
p++;
break;
case '2':
q++;
break;
case '3':
r++;
break;
case '4':
s++;
break;
}
}
if (p == 1 && q == 1 && r == 1 && s == 1)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
| #include <iostream>
using namespace std;
int main() {
char a[4];
cin >> a[0] >> a[1] >> a[2] >> a[3];
int p = 0;
int q = 0;
int r = 0;
int s = 0;
for (int i = 0; i < 4; i++) {
switch (a[i]) {
case '1':
p++;
break;
case '9':
q++;
break;
case '7':
r++;
break;
case '4':
s++;
break;
}
}
if (p == 1 && q == 1 && r == 1 && s == 1)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
| [
"literal.string.change"
] | 946,993 | 946,994 | u058186113 | cpp |
p03149 | #include <iostream>
using namespace std;
int main() {
int d[4];
cin >> d[0] >> d[1] >> d[2] >> d[3];
int a[] = {1, 9, 7, 4};
int can = 0;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
if (d[i] = a[j]) {
can++;
a[j] = 10;
}
}
}
if (can == 4)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
| #include <iostream>
using namespace std;
int main() {
int d[4];
cin >> d[0] >> d[1] >> d[2] >> d[3];
int a[] = {1, 9, 7, 4};
int can = 0;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
if (d[i] == a[j]) {
can++;
a[j] = 10;
}
}
}
if (can == 4)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
| [
"expression.operation.compare.replace.add",
"assignment.replace.remove",
"misc.typo"
] | 946,995 | 946,996 | u058186113 | cpp |
p03149 | #include <iostream>
using namespace std;
int main() {
bool a = false, b = false, c = false, d = false;
for (int i = 0; i < 4; i++) {
int x;
cin >> x;
switch (x) {
case 1:
a = true;
break;
case 9:
b = true;
break;
case 7:
c = true;
break;
case 4:
d = true;
break;
}
}
if (a && b && c && d) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | #include <iostream>
using namespace std;
int main() {
bool a = false, b = false, c = false, d = false;
for (int i = 0; i < 4; i++) {
int x;
cin >> x;
switch (x) {
case 1:
a = true;
break;
case 9:
b = true;
break;
case 7:
c = true;
break;
case 4:
d = true;
break;
}
}
if (a && b && c && d) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
} | [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 947,056 | 947,057 | u528388170 | cpp |
p03149 | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> a = {1, 4, 7, 9};
vector<int> b;
for (int &i : b)
scanf("%d", &i);
sort(b.begin(), b.end());
if (a == b)
puts("YES");
else
puts("NO");
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> a = {1, 4, 7, 9};
vector<int> b(4);
for (int &i : b)
scanf("%d", &i);
sort(b.begin(), b.end());
if (a == b)
puts("YES");
else
puts("NO");
}
| [
"call.arguments.add"
] | 947,060 | 947,061 | u144432905 | cpp |
p03149 | #include <algorithm>
#include <cmath>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>
typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;
template <class T> T maximum(T head, T tail) { return std::max(head, tail); }
template <class H, class... T> H maximum(H head, T... tail) {
return std::max(head, maximum(tail...));
}
template <class T> T minimum(T head, T tail) { return std::min(head, tail); }
template <class H, class... T> H minimum(H head, T... tail) {
return std::min(head, minimum(tail...));
}
template <class T>
std::ostream &operator<<(std::ostream &os, std::vector<T> v) {
ll i = 0;
for (auto x : v) {
os << " [" << i++ << "]" << x;
if (i % 10 == 0)
os << std::endl;
}
return os;
}
template <class T, class S>
std::ostream &operator<<(std::ostream &os, std::vector<std::pair<T, S>> vp) {
ll i = 0;
for (auto p : vp) {
os << " [" << i++ << "]" << p.first << " " << p.second;
if (i % 10 == 0)
os << std::endl;
}
return os;
}
void print() { std::cout << std::endl; }
template <typename H> void print(H head) { std::cout << head << std::endl; }
template <typename H, typename... T> void print(H head, T... tail) {
std::cout << head << " ", print(tail...);
}
int main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
ll N = 4;
std::string vc;
for (ll i = 0; i < N; i++) {
char c;
std::cin >> c;
vc += c;
}
std::sort(vc.begin(), vc.end());
bool judge = (vc == "1479");
if (judge)
print("Yes");
else
print("No");
return 0;
}
| #include <algorithm>
#include <cmath>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>
typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;
template <class T> T maximum(T head, T tail) { return std::max(head, tail); }
template <class H, class... T> H maximum(H head, T... tail) {
return std::max(head, maximum(tail...));
}
template <class T> T minimum(T head, T tail) { return std::min(head, tail); }
template <class H, class... T> H minimum(H head, T... tail) {
return std::min(head, minimum(tail...));
}
template <class T>
std::ostream &operator<<(std::ostream &os, std::vector<T> v) {
ll i = 0;
for (auto x : v) {
os << " [" << i++ << "]" << x;
if (i % 10 == 0)
os << std::endl;
}
return os;
}
template <class T, class S>
std::ostream &operator<<(std::ostream &os, std::vector<std::pair<T, S>> vp) {
ll i = 0;
for (auto p : vp) {
os << " [" << i++ << "]" << p.first << " " << p.second;
if (i % 10 == 0)
os << std::endl;
}
return os;
}
void print() { std::cout << std::endl; }
template <typename H> void print(H head) { std::cout << head << std::endl; }
template <typename H, typename... T> void print(H head, T... tail) {
std::cout << head << " ", print(tail...);
}
int main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
ll N = 4;
std::string vc;
for (ll i = 0; i < N; i++) {
char c;
std::cin >> c;
vc += c;
}
std::sort(vc.begin(), vc.end());
bool judge = (vc == "1479");
if (judge)
print("YES");
else
print("NO");
return 0;
}
| [
"literal.string.change",
"literal.string.case.change",
"call.arguments.change",
"io.output.change"
] | 947,069 | 947,070 | u343930666 | cpp |
p03149 | #include <bits/stdc++.h>
using namespace std;
const long long mod = pow(10, 9) + 7;
const long long INF = 1LL << 60;
template <class T> bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int divCeil(int A, int B) { return (A + (B - 1)) / B; }
long long divCeil(long long A, int B) { return (A + (B - 1)) / B; }
long long divCeil(int A, long long B) { return (A + (B - 1)) / B; }
long long divCeil(long long A, long long B) { return (A + (B - 1)) / B; }
int main() {
vector<int> N(4);
for (int i = 0; i < 4; i++)
cin >> N.at(i);
int a = 0, b = 0, c = 0, d = 0;
for (int i = 0; i < 4; i++) {
if (N.at(i) == 1)
a++;
else if (N.at(i) == 9)
b++;
else if (N.at(i) == 7)
c++;
else if (N.at(i) == 4)
d++;
}
string ans = "No";
if (a == b && b == c && c == d && d == 1)
ans = "Yes";
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
const long long mod = pow(10, 9) + 7;
const long long INF = 1LL << 60;
template <class T> bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int divCeil(int A, int B) { return (A + (B - 1)) / B; }
long long divCeil(long long A, int B) { return (A + (B - 1)) / B; }
long long divCeil(int A, long long B) { return (A + (B - 1)) / B; }
long long divCeil(long long A, long long B) { return (A + (B - 1)) / B; }
int main() {
vector<int> N(4);
for (int i = 0; i < 4; i++)
cin >> N.at(i);
int a = 0, b = 0, c = 0, d = 0;
for (int i = 0; i < 4; i++) {
if (N.at(i) == 1)
a++;
else if (N.at(i) == 9)
b++;
else if (N.at(i) == 7)
c++;
else if (N.at(i) == 4)
d++;
}
string ans = "NO";
if (a == b && b == c && c == d && d == 1)
ans = "YES";
cout << ans << endl;
}
| [
"literal.string.change",
"literal.string.case.change",
"variable_declaration.value.change",
"assignment.value.change"
] | 947,077 | 947,078 | u811472478 | cpp |
p03149 | #include <bits/stdc++.h>
using namespace std;
int main() {
int A[4];
cin >> A[0] >> A[1] >> A[2] >> A[3];
sort(A, A + 4);
if (A[0] == 1 and A[0] == 4 and A[0] == 7 and A[0] == 9) {
cout << "YES";
} else {
cout << "NO";
}
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int A[4];
cin >> A[0] >> A[1] >> A[2] >> A[3];
sort(A, A + 4);
if (A[0] == 1 and A[1] == 4 and A[2] == 7 and A[3] == 9) {
cout << "YES";
} else {
cout << "NO";
}
}
| [
"literal.number.change",
"variable_access.subscript.index.change",
"control_flow.branch.if.condition.change"
] | 947,079 | 947,080 | u944316525 | cpp |
p03149 | #include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
const ll MOD = 1000000007;
const long double EPS = 1e-10;
const int dyx[4][2] = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}};
int main() {
std::ios::sync_with_stdio(0);
cin.tie(0);
int a;
set<int> st;
for (int i = 0; i < 4; ++i) {
cin >> a;
st.insert(a);
}
set<int> st2({1, 7, 9, 4});
cout << ((st == st2) ? "Yes" : "No") << endl;
}
| #include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define debug(x) cerr << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
const ll MOD = 1000000007;
const long double EPS = 1e-10;
const int dyx[4][2] = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}};
int main() {
std::ios::sync_with_stdio(0);
cin.tie(0);
int a;
set<int> st;
for (int i = 0; i < 4; ++i) {
cin >> a;
st.insert(a);
}
set<int> st2({1, 7, 9, 4});
cout << ((st == st2) ? "YES" : "NO") << endl;
}
| [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 947,081 | 947,082 | u986399983 | cpp |
p03149 | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> nos(4);
for (int i = 0; i < 4; i++)
cin >> nos[i];
sort(nos.begin(), nos.end());
if (nos[0] == 1 && nos[1] == 9 && nos[2] == 7 && nos[3] == 4)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> nos(4);
for (int i = 0; i < 4; i++)
cin >> nos[i];
sort(nos.begin(), nos.end());
if (nos[0] == 1 && nos[1] == 4 && nos[2] == 7 && nos[3] == 9)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
} | [
"literal.number.change",
"control_flow.branch.if.condition.change"
] | 947,087 | 947,088 | u137724047 | cpp |
p03149 | #include <bits/stdc++.h>
#define syosu(x) fixed << setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int, P> pip;
typedef vector<pip> vip;
const int inf = 1 << 30;
const ll INF = 1ll << 60;
const double pi = acos(-1);
const double eps = 1e-9;
const ll mod = 1e9 + 7;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
int a[4], b[4] = {1, 4, 7, 9};
int main() {
for (auto &i : a)
cin >> i;
sort(a, a + 4);
bool B = 1;
for (int i = 0; i < 4; i++)
if (a[i] != b[i])
B = 0;
cout << (B ? "Yes" : "No") << endl;
} | #include <bits/stdc++.h>
#define syosu(x) fixed << setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int, P> pip;
typedef vector<pip> vip;
const int inf = 1 << 30;
const ll INF = 1ll << 60;
const double pi = acos(-1);
const double eps = 1e-9;
const ll mod = 1e9 + 7;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
int a[4], b[4] = {1, 4, 7, 9};
int main() {
for (auto &i : a)
cin >> i;
sort(a, a + 4);
bool B = 1;
for (int i = 0; i < 4; i++)
if (a[i] != b[i])
B = 0;
cout << (B ? "YES" : "NO") << endl;
} | [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 947,091 | 947,092 | u434747175 | cpp |
p03149 | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
int main(void) {
int number[10];
for (int i = 0; i < 4; i++) {
int a;
std::cin >> a;
number[a]++;
}
if (number[1] == 1 && number[9] == 1 && number[7] == 1 && number[4] == 1) {
std::cout << "YES" << std::endl;
} else {
std::cout << "NO" << std::endl;
}
return 0;
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
int main(void) {
int number[10] = {0};
for (int i = 0; i < 4; i++) {
int a;
std::cin >> a;
number[a]++;
}
if (number[1] == 1 && number[9] == 1 && number[7] == 1 && number[4] == 1) {
std::cout << "YES" << std::endl;
} else {
std::cout << "NO" << std::endl;
}
return 0;
} | [
"variable_declaration.value.change"
] | 947,102 | 947,103 | u914739916 | cpp |
p03149 | #include <cstdio>
#include <algorithm>
using namespace std;
int a[4];
int main() {
for (int i = 0; i < 4; ++i)
scanf("%d", &a[i]);
sort(a, a + 4);
puts(a[0] == 1 && a[1] == 4 && a[2] == 7 && a[4] == 9 ? "YES" : "NO");
return 0;
}
| #include <cstdio>
#include <algorithm>
using namespace std;
int a[4];
int main() {
for (int i = 0; i < 4; ++i)
scanf("%d", &a[i]);
sort(a, a + 4);
puts(a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9 ? "YES" : "NO");
return 0;
}
| [
"literal.number.change",
"variable_access.subscript.index.change",
"control_flow.loop.for.condition.change",
"expression.off_by_one",
"call.arguments.change",
"expression.operation.binary.change",
"io.output.change"
] | 947,113 | 947,114 | u895067736 | cpp |
p03149 | #include <bits/stdc++.h>
using namespace std;
int main() {
int arr[5];
for (int i = 0; i < 5; i++) {
cin >> arr[i];
}
sort(arr, arr + 5);
if (arr[0] == 1 && arr[1] == 4 && arr[1] == 7 && arr[1] == 4) {
cout << "YES" << endl;
} else
cout << "NO" << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int arr[4];
for (int i = 0; i < 4; i++) {
cin >> arr[i];
}
sort(arr, arr + 4);
if (arr[0] == 1 && arr[1] == 4 && arr[2] == 7 && arr[3] == 9) {
cout << "YES" << endl;
} else
cout << "NO" << endl;
} | [
"literal.number.change",
"variable_declaration.array_dimensions.change",
"control_flow.loop.for.condition.change",
"expression.off_by_one",
"expression.operation.binary.change",
"call.arguments.change",
"variable_access.subscript.index.change",
"control_flow.branch.if.condition.change"
] | 947,117 | 947,118 | u739300051 | cpp |
p03149 | #include <iostream>
#include <set>
using namespace std;
int main() {
set<int> cmp({1, 4, 7, 9});
int n;
for (int i = 0; i < 4; i++) {
cin >> n;
if (cmp.find(n) == cmp.end()) {
cout << "YES" << endl;
return 0;
}
cmp.erase(n);
}
cout << "NO" << endl;
return 0;
} | #include <iostream>
#include <set>
using namespace std;
int main() {
set<int> cmp({1, 4, 7, 9});
int n;
for (int i = 0; i < 4; i++) {
cin >> n;
if (cmp.find(n) == cmp.end()) {
cout << "NO" << endl;
return 0;
}
cmp.erase(n);
}
cout << "YES" << endl;
return 0;
} | [
"literal.string.change",
"io.output.change"
] | 947,119 | 947,120 | u905802918 | cpp |
p03149 | #include <iostream>
using namespace std;
int suretu(int x, int y, int z, int w);
int main() {
int N1, N2, N3, N4;
cin >> N1 >> N2 >> N3 >> N4;
suretu(N1, N2, N3, N4);
return 0;
}
int suretu(int x, int y, int z, int w) {
int sum[4] = {x, y, z, w};
int ans[4] = {0};
int j;
int a = 0;
for (j = 0; j < 4; j++) {
if (sum[j] == 1) {
ans[0] = sum[j];
sum[j] = 0;
a += 1;
break;
}
}
for (j = 0; j < 4; j++) {
if (sum[j] == 9) {
ans[1] = sum[j];
sum[j] = 0;
a += 1;
break;
}
}
for (j = 0; j < 4; j++) {
if (sum[j] == 7) {
ans[2] = sum[j];
sum[j] = 0;
a += 1;
break;
}
}
for (j = 0; j < 4; j++) {
if (sum[j] == 4) {
ans[3] = sum[j];
sum[j] = 0;
a += 1;
break;
}
}
if (a == 4) {
cout << "yes" << endl;
} else {
cout << "no" << endl;
}
} | #include <iostream>
using namespace std;
int suretu(int x, int y, int z, int w);
int main() {
int N1, N2, N3, N4;
cin >> N1 >> N2 >> N3 >> N4;
suretu(N1, N2, N3, N4);
return 0;
}
int suretu(int x, int y, int z, int w) {
int sum[4] = {x, y, z, w};
int ans[4] = {0};
int j;
int a = 0;
for (j = 0; j < 4; j++) {
if (sum[j] == 1) {
ans[0] = sum[j];
sum[j] = 0;
a += 1;
break;
}
}
for (j = 0; j < 4; j++) {
if (sum[j] == 9) {
ans[1] = sum[j];
sum[j] = 0;
a += 1;
break;
}
}
for (j = 0; j < 4; j++) {
if (sum[j] == 7) {
ans[2] = sum[j];
sum[j] = 0;
a += 1;
break;
}
}
for (j = 0; j < 4; j++) {
if (sum[j] == 4) {
ans[3] = sum[j];
sum[j] = 0;
a += 1;
break;
}
}
if (a == 4) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
} | [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 947,146 | 947,147 | u481856377 | cpp |
p03149 | #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
if (a + b + c + d == 21 && a * b * c * d == 252)
cout << "Yes" << endl;
else
cout << "No" << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
if (a + b + c + d == 21 && a * b * c * d == 252)
cout << "YES" << endl;
else
cout << "NO" << endl;
} | [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 947,154 | 947,155 | u693953100 | cpp |
p03149 | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
#define REP(i, n) for (long long i = 0; i < (n); i++)
#define FOR(i, m, n) for (long long i = (m); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
template <class T> using V = vector<T>;
template <class T, class U> using P = pair<T, U>;
const ll MOD = (ll)1e9 + 7;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;
template <class T> void corner(bool flg, T hoge) {
if (flg) {
cout << hoge << endl;
exit(0);
}
}
template <class T, class U>
ostream &operator<<(ostream &o, const map<T, U> &obj) {
o << "{";
for (auto &x : obj)
o << " {" << x.first << " : " << x.second << "}"
<< ",";
o << " }";
return o;
}
template <class T> ostream &operator<<(ostream &o, const set<T> &obj) {
o << "{";
for (auto itr = obj.begin(); itr != obj.end(); ++itr)
o << (itr != obj.begin() ? ", " : "") << *itr;
o << "}";
return o;
}
template <class T> ostream &operator<<(ostream &o, const vector<T> &obj) {
o << "{";
for (int i = 0; i < (int)obj.size(); ++i)
o << (i > 0 ? ", " : "") << obj[i];
o << "}";
return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U> &obj) {
o << "{" << obj.first << ", " << obj.second << "}";
return o;
}
template <template <class tmp> class T, class U>
ostream &operator<<(ostream &o, const T<U> &obj) {
o << "{";
for (auto itr = obj.begin(); itr != obj.end(); ++itr)
o << (itr != obj.begin() ? ", " : "") << *itr;
o << "}";
return o;
}
void print(void) { cout << endl; }
template <class Head> void print(Head &&head) {
cout << head;
print();
}
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
cout << head << " ";
print(forward<Tail>(tail)...);
}
void YN(bool flg) { cout << ((flg) ? "YES" : "NO") << endl; }
void Yn(bool flg) { cout << ((flg) ? "Yes" : "No") << endl; }
void yn(bool flg) { cout << ((flg) ? "yes" : "no") << endl; }
int main() {
V<int> a(4);
REP(i, 4) cin >> a[i];
sort(ALL(a));
YN(a[0] == 1 && a[1] == 7 && a[2] == 9 && a[3] == 4);
return 0;
} | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
#define REP(i, n) for (long long i = 0; i < (n); i++)
#define FOR(i, m, n) for (long long i = (m); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
template <class T> using V = vector<T>;
template <class T, class U> using P = pair<T, U>;
const ll MOD = (ll)1e9 + 7;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;
template <class T> void corner(bool flg, T hoge) {
if (flg) {
cout << hoge << endl;
exit(0);
}
}
template <class T, class U>
ostream &operator<<(ostream &o, const map<T, U> &obj) {
o << "{";
for (auto &x : obj)
o << " {" << x.first << " : " << x.second << "}"
<< ",";
o << " }";
return o;
}
template <class T> ostream &operator<<(ostream &o, const set<T> &obj) {
o << "{";
for (auto itr = obj.begin(); itr != obj.end(); ++itr)
o << (itr != obj.begin() ? ", " : "") << *itr;
o << "}";
return o;
}
template <class T> ostream &operator<<(ostream &o, const vector<T> &obj) {
o << "{";
for (int i = 0; i < (int)obj.size(); ++i)
o << (i > 0 ? ", " : "") << obj[i];
o << "}";
return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U> &obj) {
o << "{" << obj.first << ", " << obj.second << "}";
return o;
}
template <template <class tmp> class T, class U>
ostream &operator<<(ostream &o, const T<U> &obj) {
o << "{";
for (auto itr = obj.begin(); itr != obj.end(); ++itr)
o << (itr != obj.begin() ? ", " : "") << *itr;
o << "}";
return o;
}
void print(void) { cout << endl; }
template <class Head> void print(Head &&head) {
cout << head;
print();
}
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
cout << head << " ";
print(forward<Tail>(tail)...);
}
void YN(bool flg) { cout << ((flg) ? "YES" : "NO") << endl; }
void Yn(bool flg) { cout << ((flg) ? "Yes" : "No") << endl; }
void yn(bool flg) { cout << ((flg) ? "yes" : "no") << endl; }
int main() {
V<int> a(4);
REP(i, 4) cin >> a[i];
sort(ALL(a));
YN(a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9);
return 0;
} | [
"literal.number.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 947,156 | 947,157 | u898651494 | cpp |
p03149 | #include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using lli = long long int;
template <class T, class U> void init_n(vector<T> &v, size_t n, U x) {
v = vector<T>(n, x);
}
template <class T> void init_n(vector<T> &v, size_t n) { init_n(v, n, T()); }
template <class T> void read_n(vector<T> &v, size_t n) {
v = vector<T>(n);
for (lli i = 0; i < n; ++i)
cin >> v[i];
}
template <class T, class U> void read_n(vector<pair<T, U>> &v, size_t n) {
v = vector<pair<T, U>>(n);
for (lli i = 0; i < n; ++i)
cin >> v[i].first >> v[i].second;
}
template <class T> T gabs(const T &x) { return max(x, -x); }
#define abs gabs
lli n[4];
lli ptn[4] = {1, 4, 7, 9};
int main() {
for (lli i = 0; i < 4; ++i)
cin >> n[i];
sort(begin(n), end(n));
bool res = equal(begin(n), end(n), begin(ptn));
cout << (res ? "Yes" : "No") << endl;
return 0;
}
| #include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using lli = long long int;
template <class T, class U> void init_n(vector<T> &v, size_t n, U x) {
v = vector<T>(n, x);
}
template <class T> void init_n(vector<T> &v, size_t n) { init_n(v, n, T()); }
template <class T> void read_n(vector<T> &v, size_t n) {
v = vector<T>(n);
for (lli i = 0; i < n; ++i)
cin >> v[i];
}
template <class T, class U> void read_n(vector<pair<T, U>> &v, size_t n) {
v = vector<pair<T, U>>(n);
for (lli i = 0; i < n; ++i)
cin >> v[i].first >> v[i].second;
}
template <class T> T gabs(const T &x) { return max(x, -x); }
#define abs gabs
lli n[4];
lli ptn[4] = {1, 4, 7, 9};
int main() {
for (lli i = 0; i < 4; ++i)
cin >> n[i];
sort(begin(n), end(n));
bool res = equal(begin(n), end(n), begin(ptn));
cout << (res ? "YES" : "NO") << endl;
return 0;
}
| [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 947,158 | 947,159 | u090994275 | cpp |
p03149 | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (ll(i) = (0); (i) < (n); ++i)
#define REV(i, n) for (ll(i) = (n)-1; (i) >= 0; --i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v, n) \
{ \
REP(WW, n) cerr << v[WW] << ' '; \
cerr << endl << endl; \
}
#define SHOW2d(v, WW, HH) \
{ \
REP(W_, WW) { \
REP(H_, HH) cerr << v[W_][H_] << ' '; \
cerr << endl; \
} \
cerr << endl; \
}
#define ALL(v) v.begin(), v.end()
#define Decimal fixed << setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
typedef long long ll;
typedef pair<ll, ll> P;
int main() {
vector<int> v(4);
REP(i, 4) cin >> v[i];
sort(ALL(v));
if (v[0] == 1 && v[1] == 4 && v[2] == 7 && v[3] == 9) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (ll(i) = (0); (i) < (n); ++i)
#define REV(i, n) for (ll(i) = (n)-1; (i) >= 0; --i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v, n) \
{ \
REP(WW, n) cerr << v[WW] << ' '; \
cerr << endl << endl; \
}
#define SHOW2d(v, WW, HH) \
{ \
REP(W_, WW) { \
REP(H_, HH) cerr << v[W_][H_] << ' '; \
cerr << endl; \
} \
cerr << endl; \
}
#define ALL(v) v.begin(), v.end()
#define Decimal fixed << setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
typedef long long ll;
typedef pair<ll, ll> P;
int main() {
vector<int> v(4);
REP(i, 4) cin >> v[i];
sort(ALL(v));
if (v[0] == 1 && v[1] == 4 && v[2] == 7 && v[3] == 9) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
}
| [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 947,162 | 947,163 | u382880969 | cpp |
p03149 | #include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
const vector<int> need = {1, 4, 7, 9};
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
vector<int> v(4);
for (auto &t : v) {
cin >> t;
}
sort(v.begin(), v.end());
if (v == need) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
| #include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
const vector<int> need = {1, 4, 7, 9};
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
vector<int> v(4);
for (auto &t : v) {
cin >> t;
}
sort(v.begin(), v.end());
if (v == need) {
cout << "YES\n";
} else {
cout << "NO\n";
}
}
| [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 947,005 | 947,006 | u293523151 | cpp |
p03149 | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
int main() {
string a, b, c, d;
cin >> a >> b >> c >> d;
string s = a + b + c + d;
sort(all(s));
if (s == "1479")
cout << "Yes" << endl;
else
cout << "No" << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
int main() {
string a, b, c, d;
cin >> a >> b >> c >> d;
string s = a + b + c + d;
sort(all(s));
if (s == "1479")
cout << "YES" << endl;
else
cout << "NO" << endl;
} | [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 947,009 | 947,010 | u739489568 | cpp |
p03149 | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
int main() {
string ans = "No";
vector<int> N(4);
rep(i, 4) cin >> N.at(i);
sort(N.begin(), N.end());
if (N[0] == 1 and N[1] == 4 and N[2] == 7 and N[3] == 9) {
ans = "YES";
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
int main() {
string ans = "NO";
vector<int> N(4);
rep(i, 4) cin >> N.at(i);
sort(N.begin(), N.end());
if (N[0] == 1 and N[1] == 4 and N[2] == 7 and N[3] == 9) {
ans = "YES";
}
cout << ans << endl;
} | [
"literal.string.change",
"literal.string.case.change",
"variable_declaration.value.change"
] | 947,025 | 947,026 | u106297876 | cpp |
p03149 | #include <bits/stdc++.h>
using namespace std;
vector<int> v(4, 0);
int main() {
for (auto &p : v)
cin >> p;
sort(v.begin(), v.end());
if (v[0] == 1 && v[2] == 4 && v[3] == 7 && v[4] == 9)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
vector<int> v(4, 0);
int main() {
for (auto &p : v)
cin >> p;
sort(v.begin(), v.end());
if (v[0] == 1 && v[1] == 4 && v[2] == 7 && v[3] == 9)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
| [
"literal.number.change",
"variable_access.subscript.index.change",
"control_flow.branch.if.condition.change"
] | 947,033 | 947,034 | u269963329 | cpp |
p03149 | #include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
//#include<bits/stdc++.h>
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
const ld pi = 3.141592653589793238;
// printf("%.10f\n", n);
ll gcd(ll a, ll b) {
if (a < b)
swap(a, b);
if (a % b == 0)
return b;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll modpow(ll x, ll y) {
ll res = 1;
while (y) {
if (y % 2) {
res *= x;
res %= mod;
}
x = x * x % mod;
y /= 2;
}
return res;
}
ll test[1234];
signed main() {
ll n, x, l, q, a = 0, b = 0, c = 0, d = 0, ans = 0;
for (int h = 0; h < 4; h++) {
cin >> test[h];
}
sort(test, test + 4);
if (test[0] == 1 && test[1] == 4 && test[2] == 7 && test[4] == 9) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
} | #include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
//#include<bits/stdc++.h>
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
const ld pi = 3.141592653589793238;
// printf("%.10f\n", n);
ll gcd(ll a, ll b) {
if (a < b)
swap(a, b);
if (a % b == 0)
return b;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll modpow(ll x, ll y) {
ll res = 1;
while (y) {
if (y % 2) {
res *= x;
res %= mod;
}
x = x * x % mod;
y /= 2;
}
return res;
}
ll test[1234];
signed main() {
ll n, x, l, q, a = 0, b = 0, c = 0, d = 0, ans = 0;
for (int h = 0; h < 4; h++) {
cin >> test[h];
}
sort(test, test + 4);
if (test[0] == 1 && test[1] == 4 && test[2] == 7 && test[3] == 9) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
}
| [
"literal.number.change",
"variable_access.subscript.index.change",
"control_flow.branch.if.condition.change"
] | 947,035 | 947,036 | u986568278 | cpp |
p03149 | const int LG = 21;
const int FN = 400005;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define forn(i, n) for (int(i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define pb push_back
#define uniq(x) \
sort(all(x)); \
(x).resize(unique(all(x)) - (x).begin())
#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL
int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};
string Yes[2] = {"No", "Yes"};
string YES[2] = {"NO", "YES"};
ll inq(ll x, ll y) {
if (!y)
re 1 % MOD;
ll l = inq(x, y / 2);
if (y % 2)
re l *l % MOD *x % MOD;
re l *l % MOD;
}
ll rev(ll x) { return inq(x, MOD - 2); }
bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;
void __precompute_combinatorics() {
__precomputed_combinatorics = 1;
__fact.resize(FN);
__ufact.resize(FN);
__rev.resize(FN);
__rev[1] = 1;
for (int i = 2; i < FN; i++)
__rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
__fact[0] = 1, __ufact[0] = 1;
for (int i = 1; i < FN; i++)
__fact[i] = __fact[i - 1] * i % MOD,
__ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}
ll fact(int x) {
if (!__precomputed_combinatorics)
__precompute_combinatorics();
return __fact[x];
}
ll cnk(int n, int k) {
if (k < 0 || k > n)
return 0;
if (!__precomputed_combinatorics)
__precompute_combinatorics();
return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}
int Root(int x, vector<int> &root) {
if (x == root[x])
return x;
return root[x] = Root(root[x], root);
}
void Merge(int v, int u, vector<int> &root, vector<int> &sz) {
v = Root(v, root), u = Root(u, root);
if (v == u)
return;
if (sz[v] < sz[u]) {
sz[u] += sz[v];
root[v] = u;
} else {
sz[v] += sz[u];
root[u] = v;
}
}
int ok(int x, int n) { return 0 <= x && x < n; }
void bfs(int v, vi &dist, vector<vi> &graph) {
fill(all(dist), -1);
dist[v] = 0;
vi q = {v};
for (int i = 0; i < q.size(); i++) {
for (auto u : graph[q[i]]) {
if (dist[u] == -1) {
dist[u] = dist[q[i]] + 1;
q.push_back(u);
}
}
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
vi a(4);
forn(i, 4) cin >> a[i];
sort(all(a));
cout << Yes[a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9];
}
/* Note:
Check constants at the beginning of the code.
N is set to 4e5 but be careful in problems with large constant factor.
Setting N in every problem is more effective.
Check corner cases.
N = 1
No def int long long for now.
Add something here.
*/
| const int LG = 21;
const int FN = 400005;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define forn(i, n) for (int(i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define pb push_back
#define uniq(x) \
sort(all(x)); \
(x).resize(unique(all(x)) - (x).begin())
#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL
int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};
string Yes[2] = {"No", "Yes"};
string YES[2] = {"NO", "YES"};
ll inq(ll x, ll y) {
if (!y)
re 1 % MOD;
ll l = inq(x, y / 2);
if (y % 2)
re l *l % MOD *x % MOD;
re l *l % MOD;
}
ll rev(ll x) { return inq(x, MOD - 2); }
bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;
void __precompute_combinatorics() {
__precomputed_combinatorics = 1;
__fact.resize(FN);
__ufact.resize(FN);
__rev.resize(FN);
__rev[1] = 1;
for (int i = 2; i < FN; i++)
__rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
__fact[0] = 1, __ufact[0] = 1;
for (int i = 1; i < FN; i++)
__fact[i] = __fact[i - 1] * i % MOD,
__ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}
ll fact(int x) {
if (!__precomputed_combinatorics)
__precompute_combinatorics();
return __fact[x];
}
ll cnk(int n, int k) {
if (k < 0 || k > n)
return 0;
if (!__precomputed_combinatorics)
__precompute_combinatorics();
return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}
int Root(int x, vector<int> &root) {
if (x == root[x])
return x;
return root[x] = Root(root[x], root);
}
void Merge(int v, int u, vector<int> &root, vector<int> &sz) {
v = Root(v, root), u = Root(u, root);
if (v == u)
return;
if (sz[v] < sz[u]) {
sz[u] += sz[v];
root[v] = u;
} else {
sz[v] += sz[u];
root[u] = v;
}
}
int ok(int x, int n) { return 0 <= x && x < n; }
void bfs(int v, vi &dist, vector<vi> &graph) {
fill(all(dist), -1);
dist[v] = 0;
vi q = {v};
for (int i = 0; i < q.size(); i++) {
for (auto u : graph[q[i]]) {
if (dist[u] == -1) {
dist[u] = dist[q[i]] + 1;
q.push_back(u);
}
}
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
vi a(4);
forn(i, 4) cin >> a[i];
sort(all(a));
cout << YES[a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9];
}
/* Note:
Check constants at the beginning of the code.
N is set to 4e5 but be careful in problems with large constant factor.
Setting N in every problem is more effective.
Check corner cases.
N = 1
No def int long long for now.
Add something here.
*/
| [
"identifier.change",
"io.output.change"
] | 947,167 | 947,168 | u798339690 | cpp |
p03149 | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> a(4); // 4は要素数
for (int i = 0; i < 4; i++) {
cin >> a.at(i);
}
sort(a.begin(), a.end());
if (a.at(0) == 1 && a.at(1) == 4 && a.at(2) == 7 && a.at(2) == 9) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> a(4); // 4は要素数
for (int i = 0; i < 4; i++) {
cin >> a.at(i);
}
sort(a.begin(), a.end());
if (a.at(0) == 1 && a.at(1) == 4 && a.at(2) == 7 && a.at(3) == 9) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
} | [
"literal.number.change",
"control_flow.branch.if.condition.change"
] | 947,181 | 947,182 | u089142196 | cpp |
p03149 |
#include <bits/stdc++.h>
#define rep(i, N) for (int i = 0; i < (N); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9 + 7;
typedef long long ll;
typedef pair<ll, int> P;
typedef set<int> S;
int main() {
bool ok[4] = {0};
rep(i, 4) {
int x;
cin >> x;
if (x == 1)
ok[0] = 1;
if (x == 9)
ok[1] = 1;
if (x == 7)
ok[2] = 1;
if (x == 4)
ok[3] = 1;
}
bool ans = 1;
rep(i, 4) {
if (ok[i] == 0)
ans = 0;
}
if (ans)
cout << "YES" << endl;
else
cout << "No" << endl;
return 0;
} |
#include <bits/stdc++.h>
#define rep(i, N) for (int i = 0; i < (N); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9 + 7;
typedef long long ll;
typedef pair<ll, int> P;
typedef set<int> S;
int main() {
bool ok[4] = {0};
rep(i, 4) {
int x;
cin >> x;
if (x == 1)
ok[0] = 1;
if (x == 9)
ok[1] = 1;
if (x == 7)
ok[2] = 1;
if (x == 4)
ok[3] = 1;
}
bool ans = 1;
rep(i, 4) {
if (ok[i] == 0)
ans = 0;
}
if (ans)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
} | [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 947,183 | 947,184 | u418810472 | cpp |
p03149 | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
int main() {
vector<int> vec(4);
rep(i, 4) cin >> vec[i];
sort(vec.begin(), vec.end());
if (vec[0] == 1 && vec[1] == 4 && vec[2] == 7 && vec[2] == 9)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
int main() {
vector<int> vec(4);
rep(i, 4) cin >> vec[i];
sort(vec.begin(), vec.end());
if (vec[0] == 1 && vec[1] == 4 && vec[2] == 7 && vec[3] == 9)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
| [
"literal.number.change",
"variable_access.subscript.index.change",
"control_flow.branch.if.condition.change"
] | 947,191 | 947,192 | u552357043 | cpp |
p03149 | #include <cstdio>
#include <iostream>
using namespace std;
int n = 4, a, v[10];
int main() {
while (n--)
cin >> a, v[a] = 1;
puts(v[1] && v[9] && v[7] && v[4] ? "Yes" : "No");
return 0;
} | #include <cstdio>
#include <iostream>
using namespace std;
int n = 4, a, v[10];
int main() {
while (n--)
cin >> a, v[a] = 1;
puts(v[1] && v[9] && v[7] && v[4] ? "YES" : "NO");
return 0;
} | [
"literal.string.change",
"literal.string.case.change",
"call.arguments.change",
"io.output.change"
] | 947,195 | 947,196 | u093170535 | cpp |
p03149 | #include <cstdio>
#include <iostream>
using namespace std;
int n = 4, a, v[10];
int main() {
while (n--)
cin >> a, v[a] = 1;
cout << (v[1] && v[9] && v[7] && v[4] ? "Yes" : "No");
return 0;
} | #include <cstdio>
#include <iostream>
using namespace std;
int n = 4, a, v[10];
int main() {
while (n--)
cin >> a, v[a] = 1;
puts(v[1] && v[9] && v[7] && v[4] ? "YES" : "NO");
return 0;
} | [
"expression.operation.binary.change",
"literal.string.change",
"literal.string.case.change"
] | 947,197 | 947,196 | u093170535 | cpp |
p03149 | #include <bits/stdc++.h>
using namespace std;
int main() {
int a[4];
cin >> a[0] >> a[1] >> a[2] >> a[3];
sort(a, a + 4);
if (a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9)
cout << "Yes";
else
cout << "No";
/*
int n;
cin >> n;
int a[n],r[n],b[n],p=0,q=0;
char s[n];
for(int i=0;i<n;i++){
r[i]=99999999;
b[i]=99999999;
}
for(int i=0;i<n;i++){
cin >> a[i] >> s[i];
if(s[i]=='R'){
r[p]=a[i];
p++;
}
else{
b[q]=a[i];
q++;
}
}
sort(r,r+n);
sort(b,b+n);
for(int i=0;i<n;i++){
if(r[i]==99999999)break;
cout << r[i] << endl;
}
for(int i=0;i<n;i++){
if(b[i]==99999999)break;
cout << b[i] << endl;
}
*/
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int a[4];
cin >> a[0] >> a[1] >> a[2] >> a[3];
sort(a, a + 4);
if (a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9)
cout << "YES";
else
cout << "NO";
/*
int n;
cin >> n;
int a[n],r[n],b[n],p=0,q=0;
char s[n];
for(int i=0;i<n;i++){
r[i]=99999999;
b[i]=99999999;
}
for(int i=0;i<n;i++){
cin >> a[i] >> s[i];
if(s[i]=='R'){
r[p]=a[i];
p++;
}
else{
b[q]=a[i];
q++;
}
}
sort(r,r+n);
sort(b,b+n);
for(int i=0;i<n;i++){
if(r[i]==99999999)break;
cout << r[i] << endl;
}
for(int i=0;i<n;i++){
if(b[i]==99999999)break;
cout << b[i] << endl;
}
*/
}
| [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 947,199 | 947,200 | u222643545 | cpp |
p03149 | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
if (a + b + c + d == 1 + 9 + 7 + 4 && a * b * c * d == 1 * 9 * 7 * 4) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
}
| #include <algorithm>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
if (a + b + c + d == 1 + 9 + 7 + 4 && a * b * c * d == 1 * 9 * 7 * 4) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
}
| [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 947,201 | 947,202 | u198469037 | cpp |
p03149 | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int main() {
int a[4];
rep(i, 4) scanf("%d", &a[i]);
sort(a, a + 4);
puts(a[0] == 1 && a[1] == 9 && a[2] == 7 && a[3] == 4 ? "YES" : "NO");
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int main() {
int a[4];
rep(i, 4) scanf("%d", &a[i]);
sort(a, a + 4);
puts(a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9 ? "YES" : "NO");
return 0;
}
| [
"literal.number.change",
"control_flow.loop.for.condition.change",
"call.arguments.change",
"expression.operation.binary.change",
"io.output.change"
] | 947,211 | 947,212 | u781095600 | cpp |
p03149 | #include <bits/stdc++.h>
using namespace std;
#define pp pair<int, int>
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(), (a).end()
#define mk make_pair
ll MOD = 1000000007;
ll mod = 998244353;
int inf = 1000001000;
ll INF = 1e18 + 5;
int main() {
vector<int> a(4);
rep(i, 4) cin >> a[i];
sort(all(a));
if (a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define pp pair<int, int>
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(), (a).end()
#define mk make_pair
ll MOD = 1000000007;
ll mod = 998244353;
int inf = 1000001000;
ll INF = 1e18 + 5;
int main() {
vector<int> a(4);
rep(i, 4) cin >> a[i];
sort(all(a));
if (a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
| [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 947,213 | 947,214 | u112775098 | cpp |
p03149 | #include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define per(i, n) for (int i = n - 1; i >= 0; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
#define per1(i, n) for (int i = n; i >= 1; ++i)
#define debug cout << "line : " << __LINE__ << " debug" << endl
#define Dcout(N) cout << setprecision(20) << N << endl
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //被り削除
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define INF 1e9
#define MOD 1000000007
typedef long long ll;
//------------------------------------------------------------------------
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int a[10];
rep(i, 4) {
int n;
cin >> n;
a[n]++;
}
if (a[1] == 1 && a[9] == 1 && a[7] == 1 && a[4] == 1)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define per(i, n) for (int i = n - 1; i >= 0; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
#define per1(i, n) for (int i = n; i >= 1; ++i)
#define debug cout << "line : " << __LINE__ << " debug" << endl
#define Dcout(N) cout << setprecision(20) << N << endl
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //被り削除
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define INF 1e9
#define MOD 1000000007
typedef long long ll;
//------------------------------------------------------------------------
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
vector<int> a(10);
rep(i, 4) {
int n;
cin >> n;
a[n]++;
}
if (a[1] == 1 && a[9] == 1 && a[7] == 1 && a[4] == 1)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
| [] | 947,215 | 947,216 | u502312544 | cpp |
p03149 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = (ll)1e18;
int main() {
int cnt[10];
for (int i = 0; i < 4; i++) {
int n;
cin >> n;
cnt[n]++;
}
if (cnt[1] && cnt[9] && cnt[7] && cnt[4]) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = (ll)1e18;
int main() {
int cnt[10] = {};
for (int i = 0; i < 4; i++) {
int n;
cin >> n;
cnt[n]++;
}
if (cnt[1] && cnt[9] && cnt[7] && cnt[4]) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
| [
"variable_declaration.value.change"
] | 947,217 | 947,218 | u708258059 | cpp |
p03149 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 7;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int a[10], b;
for (int i = 0; i < 4; i++) {
cin >> b;
a[b]++;
}
if (a[1] && a[9] && a[7] && a[4])
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 7;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int a[10] = {0}, b;
for (int i = 0; i < 4; i++) {
cin >> b;
a[b]++;
}
if (a[1] && a[9] && a[7] && a[4])
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
| [
"variable_declaration.value.change"
] | 947,225 | 947,226 | u634923505 | cpp |
p03149 | #include "algorithm"
#include "cstring"
#include "iostream"
#include "math.h"
#include "string"
#include "vector"
using namespace std;
typedef long long ll;
int main() {
int a[4];
for (int i = 0; i < 4; i++) {
cin >> a[i];
}
sort(a, a + 4);
if (a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9) {
cout << "Yes"
<< "\n";
} else {
cout << "NO"
<< "\n";
}
} | #include "algorithm"
#include "cstring"
#include "iostream"
#include "math.h"
#include "string"
#include "vector"
using namespace std;
typedef long long ll;
int main() {
int a[4];
for (int i = 0; i < 4; i++) {
cin >> a[i];
}
sort(a, a + 4);
if (a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9) {
cout << "YES"
<< "\n";
} else {
cout << "NO"
<< "\n";
}
} | [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 947,227 | 947,228 | u346193734 | cpp |
p03149 | #include <algorithm>
#include <iostream>
#define ll long long
using namespace std;
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
if (a + b + c + d == 21 && a * b * c * d == 252)
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
}
| #include <algorithm>
#include <iostream>
#define ll long long
using namespace std;
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
if (a + b + c + d == 21 && a * b * c * d == 252)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
| [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 947,231 | 947,232 | u425007056 | cpp |
p03149 | //#pragma GCC optimize(2)
// Happy TLE and WA every day!
// by: zxb the vegetable chicken
#include <bits/stdc++.h>
#define mp make_pair
#define rep(i, n) for (int i = 0; i < n; i++)
#define foreach(i, c) for (VAR(i, (c).begin()); i != (c).end(); ++i)
#define BINF 0x7fffffff
#define INF 0x3f3f3f3f
#define LINF 4557430888798830399
#define END(s) \
{ \
cout << s; \
return 0; \
}
#define CON(s) \
{ \
cout << s; \
continue; \
}
#define BRE(s) \
{ \
cout << s; \
break; \
}
#define pb push_back
#define All(a) a.begin(), a.end() // with A in CAPITAL!!!
#define sz(a) (int)a.size()
#define F first
#define S second
#define Time clock() / CLOCKS_PER_SEC
//#define usingFiles
using namespace std;
typedef unsigned int ui;
typedef pair<int, int> pii;
typedef long long ll;
inline bool Read(int &x) {
x = 0;
int c;
int sign = 1;
while ((c = getchar()) < '0' || c > '9')
if (c == '-')
sign = -1;
x = c ^ '0';
while ((c = getchar()) >= '0' && c <= '9')
x = (x << 3) + (x << 1) + (c ^ '0');
x *= sign;
return 1;
}
inline bool Write(int x) {
if (x >= 10)
Write(x / 10);
putchar(x % 10 + '0');
return 1;
}
const int rp = 666666;
const bool debug = 1;
const bool I_good_vegetable_a = 1;
int a[4];
signed main() {
ios::sync_with_stdio(false);
#ifdef usingFiles
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
rep(i, 4) cin >> a[i];
sort(a, a + 4);
if (a[0] == 1 && a[1] == 9 && a[2] == 7 && a[3] == 4)
cout << "YES\n";
else
cout << "NO\n";
return 0;
} | //#pragma GCC optimize(2)
// Happy TLE and WA every day!
// by: zxb the vegetable chicken
#include <bits/stdc++.h>
#define mp make_pair
#define rep(i, n) for (int i = 0; i < n; i++)
#define foreach(i, c) for (VAR(i, (c).begin()); i != (c).end(); ++i)
#define BINF 0x7fffffff
#define INF 0x3f3f3f3f
#define LINF 4557430888798830399
#define END(s) \
{ \
cout << s; \
return 0; \
}
#define CON(s) \
{ \
cout << s; \
continue; \
}
#define BRE(s) \
{ \
cout << s; \
break; \
}
#define pb push_back
#define All(a) a.begin(), a.end() // with A in CAPITAL!!!
#define sz(a) (int)a.size()
#define F first
#define S second
#define Time clock() / CLOCKS_PER_SEC
//#define usingFiles
using namespace std;
typedef unsigned int ui;
typedef pair<int, int> pii;
typedef long long ll;
inline bool Read(int &x) {
x = 0;
int c;
int sign = 1;
while ((c = getchar()) < '0' || c > '9')
if (c == '-')
sign = -1;
x = c ^ '0';
while ((c = getchar()) >= '0' && c <= '9')
x = (x << 3) + (x << 1) + (c ^ '0');
x *= sign;
return 1;
}
inline bool Write(int x) {
if (x >= 10)
Write(x / 10);
putchar(x % 10 + '0');
return 1;
}
const int rp = 666666;
const bool debug = 1;
const bool I_good_vegetable_a = 1;
int a[4];
signed main() {
ios::sync_with_stdio(false);
#ifdef usingFiles
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
rep(i, 4) cin >> a[i];
sort(a, a + 4);
if (a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9)
cout << "YES\n";
else
cout << "NO\n";
return 0;
} | [
"literal.number.change",
"control_flow.branch.if.condition.change"
] | 947,235 | 947,236 | u083800325 | cpp |
p03149 | #include <iostream>
#include <set>
using namespace std;
#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define MAX(x, y) ((x) > (y) ? (x) : (y))
#define ABS(x, y) ((x) > (y) ? ((x) - (y)) : ((y) - (x)))
#define DIVUP(x, y) (((x) + ((y)-1)) / (y))
#define DIVOFF(x, y) (((x) + ((y) / 2)) / (y))
#define REMAINDER(x, y) ((x) % (y))
int main() {
set<int> N;
int n;
for (int i{}; i < 4; ++i) {
scanf("%d", &n);
N.insert(n);
}
printf(N.find(1) != N.end() && N.find(9) != N.end() && N.find(7) != N.end() &&
N.find(4) != N.end()
? "Yes\n"
: "No\n");
return 0;
}
| #include <iostream>
#include <set>
using namespace std;
#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define MAX(x, y) ((x) > (y) ? (x) : (y))
#define ABS(x, y) ((x) > (y) ? ((x) - (y)) : ((y) - (x)))
#define DIVUP(x, y) (((x) + ((y)-1)) / (y))
#define DIVOFF(x, y) (((x) + ((y) / 2)) / (y))
#define REMAINDER(x, y) ((x) % (y))
int main() {
set<int> N;
int n;
for (int i{}; i < 4; ++i) {
scanf("%d", &n);
N.insert(n);
}
printf(N.find(1) != N.end() && N.find(9) != N.end() && N.find(7) != N.end() &&
N.find(4) != N.end()
? "YES\n"
: "NO\n");
return 0;
}
| [
"literal.string.change",
"literal.string.case.change",
"call.arguments.change",
"io.output.change"
] | 947,240 | 947,241 | u154289649 | cpp |
p03149 | #include <algorithm>
#include <iostream>
#include <math.h>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
// typedef
struct t {
int param;
int yet;
};
int main() {
struct t target[4];
target[0].yet = 0;
target[1].yet = 0;
target[2].yet = 0;
target[3].yet = 0;
target[0].param = 1;
target[1].param = 9;
target[2].param = 7;
target[3].param = 4;
/*Q1*/
int ret = 0;
int in[4] = {0};
cin >> in[0] >> in[1] >> in[2] >> in[3];
// roop
for (int i = 0; i < 4; ++i) {
//探索
for (int j = 0; j < 4; ++j)
if (target[j].param == in[i]) {
target[j].yet = 1;
}
}
if (target[0].yet == 1 && target[1].yet == 1 && target[2].yet == 1 &&
target[3].yet == 1) {
cout << "yes" << endl;
} else {
cout << "yes" << endl;
}
/*Q2*/
/*Q3*/
/*Q4*/
return 0;
}
| #include <algorithm>
#include <iostream>
#include <math.h>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
// typedef
struct t {
int param;
int yet;
};
int main() {
struct t target[4];
target[0].yet = 0;
target[1].yet = 0;
target[2].yet = 0;
target[3].yet = 0;
target[0].param = 1;
target[1].param = 9;
target[2].param = 7;
target[3].param = 4;
/*Q1*/
int ret = 0;
int in[4] = {0};
cin >> in[0] >> in[1] >> in[2] >> in[3];
// roop
for (int i = 0; i < 4; ++i) {
//探索
for (int j = 0; j < 4; ++j)
if (target[j].param == in[i]) {
target[j].yet = 1;
}
}
if (target[0].yet == 1 && target[1].yet == 1 && target[2].yet == 1 &&
target[3].yet == 1) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
/*Q2*/
/*Q3*/
/*Q4*/
return 0;
}
| [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 947,244 | 947,245 | u335678282 | cpp |
p03149 | #include <algorithm>
#include <iostream>
#include <math.h>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef struct t {
int param;
int yet;
};
int main() {
t target[4];
target[0].yet = 0;
target[1].yet = 0;
target[2].yet = 0;
target[3].yet = 0;
target[0].param = 1;
target[1].param = 9;
target[2].param = 7;
target[3].param = 4;
/*Q1*/
int ret = 0;
int in[4] = {0};
cin >> in[0] >> in[1] >> in[2] >> in[3];
// roop
for (int i = 0; i < 4; ++i) {
//探索
for (int j = 0; j < 4; ++j)
if (target[j].param == in[i]) {
target[j].yet = 1;
}
}
if (target[0].yet == 1 && target[1].yet == 1 && target[2].yet == 1 &&
target[3].yet == 1) {
cout << "yes" << endl;
} else {
cout << "yes" << endl;
}
/*Q2*/
/*Q3*/
/*Q4*/
return 0;
}
| #include <algorithm>
#include <iostream>
#include <math.h>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
// typedef
struct t {
int param;
int yet;
};
int main() {
struct t target[4];
target[0].yet = 0;
target[1].yet = 0;
target[2].yet = 0;
target[3].yet = 0;
target[0].param = 1;
target[1].param = 9;
target[2].param = 7;
target[3].param = 4;
/*Q1*/
int ret = 0;
int in[4] = {0};
cin >> in[0] >> in[1] >> in[2] >> in[3];
// roop
for (int i = 0; i < 4; ++i) {
//探索
for (int j = 0; j < 4; ++j)
if (target[j].param == in[i]) {
target[j].yet = 1;
}
}
if (target[0].yet == 1 && target[1].yet == 1 && target[2].yet == 1 &&
target[3].yet == 1) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
/*Q2*/
/*Q3*/
/*Q4*/
return 0;
}
| [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 947,246 | 947,245 | u335678282 | cpp |
p03149 | #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> Pll;
typedef pair<P, P> PP;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define LINF (ll)1e17
#define INF 1e9
#define MOD 1e9 + 7
#define sMOD 1e5
#define fs first
#define sc second
signed main() {
ll a[4] = {1, 4, 7, 9};
ll b[4];
rep(i, 0, 4) cin >> b[i];
sort(b, b + 4);
rep(i, 0, 4) {
if (a[i] != b[i]) {
cout << "No" << endl;
break;
} else if (i == 3) {
cout << "Yes" << endl;
}
}
return 0;
} | #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> Pll;
typedef pair<P, P> PP;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define LINF (ll)1e17
#define INF 1e9
#define MOD 1e9 + 7
#define sMOD 1e5
#define fs first
#define sc second
signed main() {
ll a[4] = {1, 4, 7, 9};
ll b[4];
rep(i, 0, 4) cin >> b[i];
sort(b, b + 4);
rep(i, 0, 4) {
if (a[i] != b[i]) {
cout << "NO" << endl;
break;
} else if (i == 3) {
cout << "YES" << endl;
}
}
return 0;
}
| [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 947,260 | 947,261 | u129134470 | cpp |
p03149 | #include <iostream>
using namespace std;
int main() {
int n[4];
int i;
bool flg = true;
// std::cout << "Hello, World!" << std::endl;
cin >> n[0] >> n[1] >> n[2] >> n[3];
for (i = 0; i < 4; i++) {
if (n[i] == 1) {
break;
}
if (i == 3) {
flg = false;
}
}
for (i = 0; i < 4; i++) {
if (n[i] == 9) {
break;
}
if (i == 3) {
flg = false;
}
}
for (i = 0; i < 4; i++) {
if (n[i] == 7) {
break;
}
if (i == 3) {
flg = false;
}
}
for (i = 0; i < 4; i++) {
if (n[i] == 4) {
break;
}
if (i == 3) {
flg = false;
}
}
if (flg) {
cout << "Yes" << endl;
} else {
cout << "no" << endl;
}
return 0;
} | #include <iostream>
using namespace std;
int main() {
int n[4];
int i;
bool flg = true;
// std::cout << "Hello, World!" << std::endl;
cin >> n[0] >> n[1] >> n[2] >> n[3];
for (i = 0; i < 4; i++) {
if (n[i] == 1) {
break;
}
if (i == 3) {
flg = false;
}
}
for (i = 0; i < 4; i++) {
if (n[i] == 9) {
break;
}
if (i == 3) {
flg = false;
}
}
for (i = 0; i < 4; i++) {
if (n[i] == 7) {
break;
}
if (i == 3) {
flg = false;
}
}
for (i = 0; i < 4; i++) {
if (n[i] == 4) {
break;
}
if (i == 3) {
flg = false;
}
}
if (flg) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
} | [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 947,271 | 947,272 | u980494541 | cpp |
p03149 | #include <iostream>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
template <typename T> void show(T a) {
for (auto i : a) {
cout << i << " ";
}
cout << endl;
}
int main(int argc, char *argv[]) {
ios::sync_with_stdio(false);
cin.tie(NULL);
unordered_map<int, int> map;
map[1] = 0;
map[7] = 0;
map[4] = 0;
map[9] = 0;
vector<int> a(4);
for (int &i : a) {
cin >> i;
}
for (int &i : a) {
if (map.count(i) <= 0) {
cout << "NO" << endl;
return 0;
}
map[i] = map[i] + 1;
}
for (int &i : a) {
if (map[i] != 1) {
cout << "NO" << endl;
return 0;
}
cout << "YES" << endl;
}
} | #include <iostream>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
template <typename T> void show(T a) {
for (auto i : a) {
cout << i << " ";
}
cout << endl;
}
int main(int argc, char *argv[]) {
ios::sync_with_stdio(false);
cin.tie(NULL);
unordered_map<int, int> map;
map[1] = 0;
map[7] = 0;
map[4] = 0;
map[9] = 0;
vector<int> a(4);
for (int &i : a) {
cin >> i;
}
for (int &i : a) {
if (map.count(i) <= 0) {
cout << "NO" << endl;
return 0;
}
map[i] = map[i] + 1;
}
for (int &i : a) {
if (map[i] != 1) {
cout << "NO" << endl;
return 0;
}
}
cout << "YES" << endl;
}
| [] | 947,278 | 947,279 | u367592430 | cpp |
p03149 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; i++)
int main() {
// int n[4];
vector<int> v(4, 0);
rep(i, 4) { cin >> v[i]; }
sort(v.begin(), v.end());
if (v[0] == 1 && v[1] == 4 && v[2] == 7 && v[3] == 9) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; i++)
int main() {
// int n[4];
vector<int> v(4, 0);
rep(i, 4) { cin >> v[i]; }
sort(v.begin(), v.end());
if (v[0] == 1 && v[1] == 4 && v[2] == 7 && v[3] == 9) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
} | [
"literal.string.change",
"literal.string.case.change",
"io.output.change"
] | 947,287 | 947,288 | u263654061 | cpp |
p03149 | #include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
int list[3];
for (int i = 0; i != 4; i++)
cin >> list[i];
sort(list, list + 3);
if (list[0] == 1) {
if (list[1] == 4) {
if (list[2] == 7) {
if (list[3] == 9) {
cout << "YES" << endl;
return 0;
}
}
}
}
cout << "NO" << endl;
return 0;
}
| #include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
int list[4];
for (int i = 0; i != 4; i++)
cin >> list[i];
sort(list, list + 4);
if (list[0] == 1) {
if (list[1] == 4) {
if (list[2] == 7) {
if (list[3] == 9) {
cout << "YES" << endl;
return 0;
}
}
}
}
cout << "NO" << endl;
return 0;
}
| [
"literal.number.change",
"variable_declaration.array_dimensions.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 947,291 | 947,292 | u912162189 | cpp |
p03149 | #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
if (a == 1 || b == 1 || c == 1 || d == 1) {
if (a == 7 || b == 7 || c == 7 || d == 7) {
if (a == 4 || b == 4 || c == 4 || d == 4) {
if (a == 9 || b == 9 || c == 9 || d == 9) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
} else {
cout << "NO" << endl;
}
} else {
cout << "NO" << endl;
}
} else {
cout << "YES" << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
if (a == 1 || b == 1 || c == 1 || d == 1) {
if (a == 7 || b == 7 || c == 7 || d == 7) {
if (a == 4 || b == 4 || c == 4 || d == 4) {
if (a == 9 || b == 9 || c == 9 || d == 9) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
} else {
cout << "NO" << endl;
}
} else {
cout << "NO" << endl;
}
} else {
cout << "NO" << endl;
}
}
| [
"literal.string.change",
"io.output.change"
] | 947,295 | 947,296 | u020296964 | cpp |
p03149 | #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
if (a == 1 || b == 1 || c == 1 || d == 1) {
if (a == 7 || b == 7 || c == 7 || d == 7) {
if (a == 4 || b == 4 || c == 4 || d == 4) {
if (a == 3 || b == 3 || c == 3 || d == 3) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
} else {
cout << "NO" << endl;
}
} else {
cout << "NO" << endl;
}
} else {
cout << "YES" << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
if (a == 1 || b == 1 || c == 1 || d == 1) {
if (a == 7 || b == 7 || c == 7 || d == 7) {
if (a == 4 || b == 4 || c == 4 || d == 4) {
if (a == 9 || b == 9 || c == 9 || d == 9) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
} else {
cout << "NO" << endl;
}
} else {
cout << "NO" << endl;
}
} else {
cout << "NO" << endl;
}
}
| [
"literal.number.change",
"control_flow.branch.if.condition.change",
"literal.string.change",
"io.output.change"
] | 947,297 | 947,296 | u020296964 | cpp |
p03149 | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int a[4];
int d;
cin >> a[0] >> a[1] >> a[2] >> a[3];
sort(a, a + 4);
d = 1000 * a[0] + 100 * a[1] + 10 * a[2] + a[3];
if (d == 1974)
cout << "YES";
else
cout << "NO";
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int a[4];
int d;
cin >> a[0] >> a[1] >> a[2] >> a[3];
sort(a, a + 4);
d = 1000 * a[0] + 100 * a[1] + 10 * a[2] + a[3];
if (d == 1479)
cout << "YES";
else
cout << "NO";
}
| [
"literal.number.change",
"control_flow.branch.if.condition.change"
] | 947,298 | 947,299 | u995107278 | cpp |
p03149 | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char *argv[]) {
vector<int> N(4);
for (int i = 0; i < 4; i++) {
cin >> N.at(i);
}
auto result1 = find(N.begin(), N.end(), 1);
auto result9 = find(N.begin(), N.end(), 9);
auto result7 = find(N.begin(), N.end(), 7);
auto result4 = find(N.begin(), N.end(), 4);
if (result1 == N.end() || result9 == N.end() || result7 == N.end() ||
result4 == N.end()) {
cout << "No" << std::endl;
} else {
cout << "Yes" << std::endl;
}
return 0;
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char *argv[]) {
vector<int> N(4);
for (int i = 0; i < 4; i++) {
cin >> N.at(i);
}
auto result1 = find(N.begin(), N.end(), 1);
auto result9 = find(N.begin(), N.end(), 9);
auto result7 = find(N.begin(), N.end(), 7);
auto result4 = find(N.begin(), N.end(), 4);
if (result1 == N.end() || result9 == N.end() || result7 == N.end() ||
result4 == N.end()) {
std::cout << "NO" << std::endl;
} else {
std::cout << "YES" << std::endl;
}
return 0;
}
| [
"literal.string.change",
"literal.string.case.change",
"expression.operation.binary.change"
] | 947,309 | 947,310 | u180077477 | cpp |
p03149 | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char *argv[]) {
vector<int> N(4);
for (int i = 0; i < 4; i++) {
cin >> N.at(i);
}
auto result1 = find(N.begin(), N.end(), 1);
auto result9 = find(N.begin(), N.end(), 9);
auto result7 = find(N.begin(), N.end(), 7);
auto result4 = find(N.begin(), N.end(), 4);
if (result1 == N.end() || result9 == N.end() || result7 == N.end() ||
result4 == N.end()) {
std::cout << "No" << std::endl;
} else {
std::cout << "Yes" << std::endl;
}
return 0;
}
| #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char *argv[]) {
vector<int> N(4);
for (int i = 0; i < 4; i++) {
cin >> N.at(i);
}
auto result1 = find(N.begin(), N.end(), 1);
auto result9 = find(N.begin(), N.end(), 9);
auto result7 = find(N.begin(), N.end(), 7);
auto result4 = find(N.begin(), N.end(), 4);
if (result1 == N.end() || result9 == N.end() || result7 == N.end() ||
result4 == N.end()) {
std::cout << "NO" << std::endl;
} else {
std::cout << "YES" << std::endl;
}
return 0;
}
| [
"literal.string.change",
"literal.string.case.change",
"expression.operation.binary.change"
] | 947,311 | 947,310 | u180077477 | cpp |
p03149 | #include <stdio.h>
int main() {
int n[4];
int i;
scanf("%d%d%d%d", &n[0], &n[1], &n[2], &n[3]);
for (i = 0; i < 4; i++) {
if (n[i] == 1)
break;
}
if (i >= 4) {
printf("NO\n");
return 0;
}
for (i = 0; i < 4; i++) {
if (n[i] == 9)
break;
}
if (i >= 4) {
printf("NO\n");
return 0;
}
for (i = 0; i < 4; i++) {
if (n[i] == 7)
break;
}
if (i >= 4) {
printf("NO\n");
return 0;
}
for (i = 0; i < 4; i++) {
if (n[i] == 3)
break;
}
if (i >= 4) {
printf("NO\n");
return 0;
}
printf("YES\n");
return 0;
}
| #include <stdio.h>
int main() {
int n[4];
int i;
scanf("%d%d%d%d", &n[0], &n[1], &n[2], &n[3]);
for (i = 0; i < 4; i++) {
if (n[i] == 1)
break;
}
if (i >= 4) {
printf("NO\n");
return 0;
}
for (i = 0; i < 4; i++) {
if (n[i] == 9)
break;
}
if (i >= 4) {
printf("NO\n");
return 0;
}
for (i = 0; i < 4; i++) {
if (n[i] == 7)
break;
}
if (i >= 4) {
printf("NO\n");
return 0;
}
for (i = 0; i < 4; i++) {
if (n[i] == 4)
break;
}
if (i >= 4) {
printf("NO\n");
return 0;
}
printf("YES\n");
return 0;
}
| [
"literal.number.change",
"control_flow.branch.if.condition.change"
] | 947,312 | 947,313 | u687259738 | cpp |
p03149 | #include <stdio.h>
int main() {
int n[4];
int i;
scanf("%d%d%d%d", &n[0], &n[1], &n[2], &n[3]);
for (i = 0; i < 4; i++) {
if (n[i] == 1)
break;
}
if (i >= 4) {
printf("NO\n");
return 0;
}
for (i = 0; i < 4; i++) {
if (n[i] == 9)
break;
}
if (i >= 4) {
printf("NO\n");
return 0;
}
for (i = 0; i < 4; i++) {
if (n[i] == 4)
break;
}
if (i >= 4) {
printf("NO\n");
return 0;
}
for (i = 0; i < 4; i++) {
if (n[i] == 3)
break;
}
if (i >= 4) {
printf("NO\n");
return 0;
}
printf("YES\n");
return 0;
}
| #include <stdio.h>
int main() {
int n[4];
int i;
scanf("%d%d%d%d", &n[0], &n[1], &n[2], &n[3]);
for (i = 0; i < 4; i++) {
if (n[i] == 1)
break;
}
if (i >= 4) {
printf("NO\n");
return 0;
}
for (i = 0; i < 4; i++) {
if (n[i] == 9)
break;
}
if (i >= 4) {
printf("NO\n");
return 0;
}
for (i = 0; i < 4; i++) {
if (n[i] == 7)
break;
}
if (i >= 4) {
printf("NO\n");
return 0;
}
for (i = 0; i < 4; i++) {
if (n[i] == 4)
break;
}
if (i >= 4) {
printf("NO\n");
return 0;
}
printf("YES\n");
return 0;
}
| [
"literal.number.change",
"control_flow.branch.if.condition.change"
] | 947,314 | 947,313 | u687259738 | cpp |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.