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 |
|---|---|---|---|---|---|---|---|
p03107 | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define ll long long
#define pp pair<int, int>
// int 2×10の9乗
int main() {
string s;
cin >> s;
int b = 0, r = 0;
rep(i, s.size()) {
if (s[i] == '0')
r++;
else
b++;
}
int ansk = min(b, r);
int ans = ansk * ansk;
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define ll long long
#define pp pair<int, int>
// int 2×10の9乗
int main() {
string s;
cin >> s;
int b = 0, r = 0;
rep(i, s.size()) {
if (s[i] == '0')
r++;
else
b++;
}
int ansk = min(b, r);
int ans = ansk * 2;
cout << ans << endl;
} | [
"identifier.replace.remove",
"literal.replace.add",
"expression.operation.binary.change"
] | 916,973 | 916,974 | u510383220 | cpp |
p03107 | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
cout << min(count(s.begin(), s.end(), '0'), count(s.begin(), s.end(), '1'));
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
cout << min(count(s.begin(), s.end(), '0'), count(s.begin(), s.end(), '1')) *
2;
} | [] | 916,975 | 916,976 | u047554023 | cpp |
p03107 | #include <bits/stdc++.h>
#include <cstdlib>
using namespace std;
int main() {
string S;
cin >> S;
int N = S.size();
int s[100010];
for (int i = 0; i < N; i++) {
if (S.at(i) == '0')
s[i] = 0;
if (S.at(i) == '1')
s[i] = 1;
}
int sum_0 = 0, sum_1 = 0;
for (int i = 0; i < N; i++) {
if (s[i] = 0)
sum_0++;
else
sum_1++;
}
cout << 2 * (min(sum_0, sum_1)) << endl;
} | #include <bits/stdc++.h>
#include <cstdlib>
using namespace std;
int main() {
string S;
cin >> S;
int N = S.size();
int s[100010];
for (int i = 0; i < N; i++) {
if (S.at(i) == '0')
s[i] = 0;
if (S.at(i) == '1')
s[i] = 1;
}
int sum_0 = 0, sum_1 = 0;
for (int i = 0; i < N; i++) {
if (s[i] == 0)
sum_0++;
else
sum_1++;
}
cout << 2 * (min(sum_0, sum_1)) << endl;
} | [
"expression.operation.compare.replace.add",
"assignment.replace.remove",
"misc.typo"
] | 916,987 | 916,988 | u508571192 | cpp |
p03107 | //#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const int INF = 1e9 + 5;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
const ll MOD = 1000000007LL;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main() {
string s;
ll one = 0, zero = 0;
rep(i, s.size()) {
if (s[i] = '0')
zero++;
else
one++;
}
cout << 2 * min(one, zero) << endl;
} | //#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const int INF = 1e9 + 5;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
const ll MOD = 1000000007LL;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main() {
string s;
cin >> s;
ll one = 0, zero = 0;
rep(i, s.size()) {
if (s[i] == '0')
zero++;
else
one++;
}
// cout<<one<<zero<<endl;
cout << 2 * min(one, zero) << endl;
} | [
"expression.operation.compare.replace.add",
"assignment.replace.remove",
"misc.typo"
] | 916,997 | 916,998 | u614128939 | cpp |
p03107 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template <class T> using vc = vector<T>;
template <class T> using vvc = vector<vector<T>>;
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
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;
}
void init() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
}
//--------------------------------------------------------------------------------//
int main() {
init();
ll cnt0 = 0, cnt1 = 0;
string S;
cin >> S;
rep(i, S.size()) {
if (S[i] == '0')
cnt0++;
else
cnt1++;
}
cout << min(cnt0, cnt1) << endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template <class T> using vc = vector<T>;
template <class T> using vvc = vector<vector<T>>;
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
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;
}
void init() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
}
//--------------------------------------------------------------------------------//
int main() {
init();
ll cnt0 = 0, cnt1 = 0;
string S;
cin >> S;
rep(i, S.size()) {
if (S[i] == '0')
cnt0++;
else
cnt1++;
}
cout << 2 * min(cnt0, cnt1) << endl;
} | [
"expression.operation.binary.add"
] | 916,999 | 917,000 | u722535636 | cpp |
p03107 | #include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int ans = 0;
stack<string> s;
string w, t;
cin >> w;
s.push(w.substr(0, 1));
for (int i = 0; i < w.length(); i++) {
if (!s.empty()) {
t = s.top();
}
s.push(w.substr(i, 1));
if (t != s.top() && s.size() >= 2) {
ans += 2;
s.pop();
s.pop();
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int ans = 0;
stack<string> s;
string w, t;
cin >> w;
s.push(w.substr(0, 1));
for (int i = 1; i < w.length(); i++) {
if (!s.empty()) {
t = s.top();
}
s.push(w.substr(i, 1));
if (t != s.top() && s.size() >= 2) {
ans += 2;
s.pop();
s.pop();
}
}
cout << ans << endl;
}
| [
"literal.number.change",
"variable_declaration.value.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one"
] | 917,005 | 917,006 | u573909039 | cpp |
p03107 | #include <bits/stdc++.h>
#define INF 1e9
using namespace std;
#define REPR(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
#define endl "\n"
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
typedef long long ll;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
void solve() {
string s;
cin >> s;
cout << min(count(ALL(s), '0'), count(ALL(s), '1')) << endl;
}
int main() {
solve();
return 0;
}
| #include <bits/stdc++.h>
#define INF 1e9
using namespace std;
#define REPR(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
#define endl "\n"
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
typedef long long ll;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
void solve() {
string s;
cin >> s;
cout << min(count(ALL(s), '0'), count(ALL(s), '1')) * 2 << endl;
}
int main() {
solve();
return 0;
}
| [
"expression.operation.binary.add"
] | 917,007 | 917,008 | u492030100 | cpp |
p03107 | #include <iostream>
#include <string>
using namespace std;
int main() {
string S;
cin >> S;
int N = S.length();
int count0, count1;
for (int i = 0; i < N; i++) {
if (S[i] == '0') {
count0 += 1;
} else {
count1 += 1;
}
}
if (count0 <= count1) {
cout << 2 * count0 << endl;
} else {
cout << 2 * count1 << endl;
}
return 0;
} | #include <iostream>
#include <string>
using namespace std;
int main() {
string S;
cin >> S;
int N = S.length();
int count0 = 0, count1 = 0;
for (int i = 0; i < N; i++) {
if (S[i] == '0') {
count0 += 1;
} else {
count1 += 1;
}
}
if (count0 <= count1) {
cout << 2 * count0 << endl;
} else {
cout << 2 * count1 << endl;
}
return 0;
} | [
"variable_declaration.value.change"
] | 917,016 | 917,017 | u280096880 | cpp |
p03107 | #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
int l = S.length();
int count0, count1 = 0;
for (int i = 0; i < l; i++) {
if (strncmp("0", &S.at(i), 1) == 0) {
count0++;
} else {
count1++;
}
}
cout << 2 * min(count0, count1) << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
int l = S.length();
int count0 = 0;
int count1 = 0;
for (int i = 0; i < l; i++) {
if (strncmp("0", &S.at(i), 1) == 0) {
count0++;
} else {
count1++;
}
}
cout << 2 * min(count0, count1) << endl;
} | [
"variable_declaration.add"
] | 917,023 | 917,024 | u537507471 | cpp |
p03107 | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1 << 29);
int main() {
string S;
cin >> S;
int n = S.size();
int cnt = 0;
for (int i = 0; i < S.size() - 1; i++) {
if (S[i] == '0')
cnt++;
}
cout << 2 * min(cnt, n - cnt) << endl;
return 0;
// int N = S.size();
// // cout << N << endl;
// bool flag = false;
// while (true) {
// // cout << "yeah!" << endl;
// if (S.empty()) {
// break;
// }
// bool flag2 = false;
// for(int i = 0; i < S.size()-1; i++) {
// // cout << S[i] << S[i+1] << endl;
// if (S[i] != S[i+1]) {
// // cout << "yeah!" << endl;
// S.erase(i, 2);
// break;
// }
// if (i == S.size()-2) {
// flag = true;
// }
// }
// // cout << S << endl;
// if (flag || N == S.size()) {
// break;
// }
// }
// cout << N - S.size()<< endl;
return 0;
} | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1 << 29);
int main() {
string S;
cin >> S;
int n = S.size();
int cnt = 0;
for (int i = 0; i < S.size(); i++) {
if (S[i] == '0')
cnt++;
}
cout << 2 * min(cnt, n - cnt) << endl;
return 0;
// int N = S.size();
// // cout << N << endl;
// bool flag = false;
// while (true) {
// // cout << "yeah!" << endl;
// if (S.empty()) {
// break;
// }
// bool flag2 = false;
// for(int i = 0; i < S.size()-1; i++) {
// // cout << S[i] << S[i+1] << endl;
// if (S[i] != S[i+1]) {
// // cout << "yeah!" << endl;
// S.erase(i, 2);
// break;
// }
// if (i == S.size()-2) {
// flag = true;
// }
// }
// // cout << S << endl;
// if (flag || N == S.size()) {
// break;
// }
// }
// cout << N - S.size()<< endl;
return 0;
} | [
"control_flow.loop.for.condition.change",
"expression.operation.binary.remove"
] | 917,029 | 917,030 | u538125576 | cpp |
p03107 | #include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second
#define debug(x) cout << x << endl;
#define repi(i, x, n) for (int i = x; i < n; i++)
#define rep(i, n) repi(i, 0, n)
#define lp(i, n) repi(i, 0, n)
#define repn(i, n) for (int i = n; i >= 0; i--)
#define int long long
#define endl "\n"
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
int ans;
int zero = 0, one = 0;
string s;
cin >> s;
rep(i, s.size()) {
if (s[i] == '0')
zero++;
else
one++;
}
cout << min(one, zero) << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second
#define debug(x) cout << x << endl;
#define repi(i, x, n) for (int i = x; i < n; i++)
#define rep(i, n) repi(i, 0, n)
#define lp(i, n) repi(i, 0, n)
#define repn(i, n) for (int i = n; i >= 0; i--)
#define int long long
#define endl "\n"
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
int ans;
int zero = 0, one = 0;
string s;
cin >> s;
rep(i, s.size()) {
if (s[i] == '0')
zero++;
else
one++;
}
cout << min(one, zero) * 2 << endl;
return 0;
} | [
"expression.operation.binary.add"
] | 917,041 | 917,042 | u386769326 | cpp |
p03107 | #include <bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(), (v).end()
#define REP(i, p, n) for (int i = p; i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int, int> P;
using ll = long long;
using VI = vector<int>;
int main() {
string s;
cin >> s;
int iti = 0;
int zero = 0;
if (s.size() == 1) {
cout << 0 << endl;
return 0;
}
for (auto &i : s) {
if (i == '1')
iti++;
else
zero++;
}
cout << min(iti, zero) << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(), (v).end()
#define REP(i, p, n) for (int i = p; i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int, int> P;
using ll = long long;
using VI = vector<int>;
int main() {
string s;
cin >> s;
int iti = 0;
int zero = 0;
if (s.size() == 1) {
cout << 0 << endl;
return 0;
}
for (auto &i : s) {
if (i == '1')
iti++;
else
zero++;
}
cout << min(iti, zero) * 2 << endl;
return 0;
}
| [
"expression.operation.binary.add"
] | 917,043 | 917,044 | u902149880 | cpp |
p03107 | #include <bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(), (v).end()
#define REP(i, p, n) for (int i = p; i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int, int> P;
using ll = long long;
using VI = vector<int>;
int main() {
string s;
cin >> s;
int iti = 0;
int zero = 0;
if (s.size() == 1) {
cout << 0 << endl;
return 0;
}
for (auto &i : s) {
if (s[i] == '1')
iti++;
else
zero++;
}
cout << min(iti, zero) << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(), (v).end()
#define REP(i, p, n) for (int i = p; i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int, int> P;
using ll = long long;
using VI = vector<int>;
int main() {
string s;
cin >> s;
int iti = 0;
int zero = 0;
if (s.size() == 1) {
cout << 0 << endl;
return 0;
}
for (auto &i : s) {
if (i == '1')
iti++;
else
zero++;
}
cout << min(iti, zero) * 2 << endl;
return 0;
}
| [
"control_flow.branch.if.condition.change"
] | 917,045 | 917,044 | u902149880 | cpp |
p03107 | #include <bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(), (v).end()
#define REP(i, p, n) for (int i = p; i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int, int> P;
using ll = long long;
using VI = vector<int>;
int main() {
string s;
cin >> s;
int iti = 0;
int zero = 0;
if (s.size() == 1) {
cout << 0 << endl;
return 0;
}
for (auto &i : s) {
if (s == "1")
iti++;
else
zero++;
}
cout << min(iti, zero) * 2 << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(), (v).end()
#define REP(i, p, n) for (int i = p; i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int, int> P;
using ll = long long;
using VI = vector<int>;
int main() {
string s;
cin >> s;
int iti = 0;
int zero = 0;
if (s.size() == 1) {
cout << 0 << endl;
return 0;
}
for (auto &i : s) {
if (i == '1')
iti++;
else
zero++;
}
cout << min(iti, zero) * 2 << endl;
return 0;
}
| [
"identifier.change",
"control_flow.branch.if.condition.change",
"literal.string.change"
] | 917,046 | 917,044 | u902149880 | cpp |
p03107 | #include <bits/stdc++.h>
#define Size 1e5
using namespace std;
//スタックでやってみる
int main() {
vector<char> sta(Size);
string s;
cin >> s;
int ans = 0, top = 0;
for (int i = 0; i < s.size(); i++) {
if (top == 0 || sta[top] == s[i])
s[++top];
else {
ans += 2;
top--;
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
#define Size 1e5
using namespace std;
//スタックでやってみる
int main() {
vector<char> sta(Size);
string s;
cin >> s;
int ans = 0, top = 0;
for (int i = 0; i < s.size(); i++) {
if (top == 0 || sta[top] == s[i])
sta[++top] = s[i];
else {
ans += 2;
top--;
}
}
cout << ans << endl;
}
| [
"assignment.variable.change",
"identifier.change",
"assignment.change"
] | 917,047 | 917,048 | u843292252 | cpp |
p03107 | #include <algorithm> //sort(all(変数),greater<型名>()) で降順に
#include <bits/stdc++.h>
#include <cmath> //切り上げceil(値)
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip> //setprecision(数字)
#include <iostream>
#include <list>
#include <map>
#include <numeric> //xとyの最大公約数は__gcd(x,y),xとyの最小公倍数は(x*y)/__gcd
#include <queue> //priority_queue<型名> 変数:優先度付きキュー 最大値の探索が早い
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define rep0(i, n) for (ll i = 0; i < n; i++)
#define rrep0(i, n) for (ll i = n - 1; 0 <= i; i--)
#define rep1(i, n) for (ll i = 1; i <= n; i++)
#define rrep1(i, n) for (ll i = n; 1 <= i; i--)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(), (x).end()
#define mod 1000000007
using ll = long long;
using namespace std;
int main() {
string s;
cin >> s;
deque<char> dq;
ll ans = 0;
rep0(i, s.size()) {
if (dq.empty()) {
dq.push_front(s[i]);
} else {
if (dq.front() != s[i]) {
ans += 2;
dq.pop_front();
} else {
dq.push_front(s[i]);
}
}
}
}
| #include <algorithm> //sort(all(変数),greater<型名>()) で降順に
#include <bits/stdc++.h>
#include <cmath> //切り上げceil(値)
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip> //setprecision(数字)
#include <iostream>
#include <list>
#include <map>
#include <numeric> //xとyの最大公約数は__gcd(x,y),xとyの最小公倍数は(x*y)/__gcd
#include <queue> //priority_queue<型名> 変数:優先度付きキュー 最大値の探索が早い
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define rep0(i, n) for (ll i = 0; i < n; i++)
#define rrep0(i, n) for (ll i = n - 1; 0 <= i; i--)
#define rep1(i, n) for (ll i = 1; i <= n; i++)
#define rrep1(i, n) for (ll i = n; 1 <= i; i--)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(), (x).end()
#define mod 1000000007
using ll = long long;
using namespace std;
int main() {
string s;
cin >> s;
deque<char> dq;
ll ans = 0;
rep0(i, s.size()) {
if (dq.empty()) {
dq.push_front(s[i]);
} else {
if (dq.front() != s[i]) {
ans += 2;
dq.pop_front();
} else {
dq.push_front(s[i]);
}
}
}
cout << ans;
}
| [] | 917,053 | 917,054 | u667375816 | cpp |
p03107 | #include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000000 + 7
#define INF 1000000000
#define rep(i, rept) for (ll i = 0; i < rept; i++)
typedef long long ll;
using namespace std;
int main() {
ll n = 0, k = 0, mini = 999999999;
ll grid[3][3];
bool flag = false;
string str;
cin >> str;
rep(i, str.size()) {
if (str[i] == '0')
n++;
else {
k++;
}
}
cout << min(n, k);
}
| #include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000000 + 7
#define INF 1000000000
#define rep(i, rept) for (ll i = 0; i < rept; i++)
typedef long long ll;
using namespace std;
int main() {
ll n = 0, k = 0, mini = 999999999;
ll grid[3][3];
bool flag = false;
string str;
cin >> str;
rep(i, str.size()) {
if (str[i] == '0')
n++;
else {
k++;
}
}
cout << min(n, k) * 2;
}
| [
"expression.operation.binary.add"
] | 917,055 | 917,056 | u635557235 | cpp |
p03107 | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
long long int a, b;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '0')
a++;
else
b++;
}
cout << 2 * min(a, b);
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
long long int a, b;
a = b = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '0')
a++;
else
b++;
}
cout << 2 * min(a, b);
}
| [
"assignment.add"
] | 917,057 | 917,058 | u825781600 | cpp |
p03107 | #include <iostream>
#include <string>
using namespace std;
int main() {
string s;
cin >> s;
int count_0 = 0, count_1 = 0;
for (int i = 0; i < s.length(); i++) {
if (s[i] == '0')
count_0++;
else
count_1++;
}
cout << min(count_1, count_0) << endl;
return 0;
} | #include <iostream>
#include <string>
using namespace std;
int main() {
string s;
cin >> s;
int count_0 = 0, count_1 = 0;
for (int i = 0; i < s.length(); i++) {
if (s[i] == '0')
count_0++;
else
count_1++;
}
cout << 2 * min(count_1, count_0) << endl;
return 0;
} | [
"expression.operation.binary.add"
] | 917,059 | 917,060 | u110383054 | cpp |
p03107 | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define MAX_N 10000000
#define ll int64_t
#define all(v) (v).begin(), (v).end()
#define P pair<int, int>
using namespace std;
int main() {
string s;
cin >> s;
int red = 0, blue = 0;
rep(i, s.size()) {
if (s[i] == '0')
red++;
else if (s[i] == '1')
blue++;
}
cout << min(red, blue) << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define MAX_N 10000000
#define ll int64_t
#define all(v) (v).begin(), (v).end()
#define P pair<int, int>
using namespace std;
int main() {
string s;
cin >> s;
int red = 0, blue = 0;
rep(i, s.size()) {
if (s[i] == '0')
red++;
else if (s[i] == '1')
blue++;
}
cout << min(red, blue) * 2 << endl;
return 0;
} | [
"expression.operation.binary.add"
] | 917,063 | 917,064 | u532401120 | cpp |
p03107 | #include <iostream>
using namespace std;
int main() {
string S;
cin >> S;
int r = 0, b = 0;
for (int i = 0; i < S.length() - 1; i++) {
if (S[i] == '0')
r++;
else
b++;
}
if (r < b)
cout << r << endl;
else
cout << b << endl;
return 0;
} | #include <iostream>
using namespace std;
int main() {
string S;
cin >> S;
int r = 0, b = 0;
for (int i = 0; i < S.length(); i++) {
if (S[i] == '0')
r++;
else
b++;
}
if (r < b)
cout << r * 2 << endl;
else
cout << b * 2 << endl;
return 0;
} | [
"control_flow.loop.for.condition.change",
"expression.operation.binary.remove"
] | 917,067 | 917,068 | u204523044 | cpp |
p03107 | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <sstream>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
int main() {
int N, M;
int ans = 0;
string S;
int zcnt = 0;
int ocnt = 0;
cin >> S;
for (int i = 0; i < S.size(); i++) {
if (S[i] == '0') {
zcnt++;
} else if (S[i] == '1') {
ocnt++;
}
}
cout << min(zcnt, ocnt) << endl;
}
| #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <sstream>
#include <string.h>
#include <string>
#include <vector>
using namespace std;
int main() {
int N, M;
int ans = 0;
string S;
int zcnt = 0;
int ocnt = 0;
cin >> S;
for (int i = 0; i < S.size(); i++) {
if (S[i] == '0') {
zcnt++;
} else if (S[i] == '1') {
ocnt++;
}
}
cout << min(zcnt, ocnt) * 2 << endl;
}
| [
"expression.operation.binary.add"
] | 917,071 | 917,072 | u699835930 | cpp |
p03107 | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int main() {
string s;
cin >> s;
int a = 0;
int b = 0;
rep(i, s.length()) {
if (s[i] == '0') {
a++;
} else {
b++;
}
}
int ans = min(a, b);
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int main() {
string s;
cin >> s;
int a = 0;
int b = 0;
rep(i, s.length()) {
if (s[i] == '0') {
a++;
} else {
b++;
}
}
int ans = min(a, b) * 2;
cout << ans << endl;
return 0;
}
| [
"assignment.change"
] | 917,073 | 917,074 | u905170328 | cpp |
p03107 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string s;
int j = 0;
int a = 0, b = 0;
cin >> s;
n = s.length();
for (int i = 0; i < n; i++) {
if (s[i] == '0') {
a++;
} else {
b++;
}
}
if (a == b) {
cout << a;
} else if (a < b) {
cout << a * 2;
} else {
cout << b * 2;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string s;
int j = 0;
int a = 0, b = 0;
cin >> s;
n = s.length();
for (int i = 0; i < n; i++) {
if (s[i] == '0') {
a++;
} else {
b++;
}
}
if (a == b) {
cout << a * 2;
} else if (a < b) {
cout << a * 2;
} else {
cout << b * 2;
}
return 0;
}
| [
"expression.operation.binary.add"
] | 917,075 | 917,076 | u503095551 | cpp |
p03107 | #include <iostream>
#include <vector>
using namespace std;
int main() {
string S;
cin >> S;
int x = 0, y = 0;
for (int i = 1; i < S.size(); i++) {
if (S[i] == '0') {
x++;
}
if (S[i] == '1') {
y++;
}
}
cout << 2 * (x > y ? y : x) << endl;
} | #include <iostream>
#include <vector>
using namespace std;
int main() {
string S;
cin >> S;
int x = 0, y = 0;
for (int i = 0; i < S.size(); i++) {
if (S[i] == '0') {
x++;
}
if (S[i] == '1') {
y++;
}
}
cout << 2 * (x > y ? y : x) << endl;
} | [
"literal.number.change",
"variable_declaration.value.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one"
] | 917,077 | 917,078 | u087313098 | cpp |
p03107 | #include <bits/stdc++.h>
using namespace std;
#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
ll mod = 1000000007ll;
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;
}
const ll inf = 1ll << 60;
int main() {
char s[100010];
scanf("%s", s);
int n = strlen(s);
int a = 0;
int b = 0;
rp(i, 0, n) {
if (s[i] == '0')
a++;
else
b++;
}
printf("%d", max(a, b));
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
ll mod = 1000000007ll;
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;
}
const ll inf = 1ll << 60;
int main() {
char s[100010];
scanf("%s", s);
int n = strlen(s);
int a = 0;
int b = 0;
rp(i, 0, n) {
if (s[i] == '0')
a++;
else
b++;
}
printf("%d", 2 * min(a, b));
return 0;
} | [
"identifier.replace.remove",
"literal.replace.add",
"call.arguments.change",
"io.output.change"
] | 917,079 | 917,080 | u575653048 | cpp |
p03107 | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int tmp = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '0') {
tmp++;
}
}
int ans;
if (tmp < s.size() / 2) {
ans = tmp * 2;
} else {
ans = (s.size() - tmp) * 2;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int tmp = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '0') {
tmp++;
}
}
int ans;
if (tmp <= s.size() / 2) {
ans = tmp * 2;
} else {
ans = (s.size() - tmp) * 2;
}
cout << ans << endl;
} | [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 917,081 | 917,082 | u593459816 | cpp |
p03107 | // #include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define irep(i, n) for (int i = n - 1; i >= 0; i--)
#define lrep(i, n) for (long long i = 0; i < n; i++)
typedef long long ll;
typedef vector<long long> llv;
typedef vector<vector<long long>> llvv;
int main() {
string s;
cin >> s;
ll ones = 0;
ll zeros = 0;
ll n = s.size();
rep(i, n) {
if (s[i] == 0)
zeros++;
else
ones++;
}
cout << 2 * min(ones, zeros) << endl;
} | // #include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define irep(i, n) for (int i = n - 1; i >= 0; i--)
#define lrep(i, n) for (long long i = 0; i < n; i++)
typedef long long ll;
typedef vector<long long> llv;
typedef vector<vector<long long>> llvv;
int main() {
string s;
cin >> s;
ll ones = 0;
ll zeros = 0;
ll n = s.size();
rep(i, n) {
if (s[i] == '0')
zeros++;
else
ones++;
}
cout << 2 * min(ones, zeros) << endl;
} | [
"control_flow.branch.if.condition.change"
] | 917,087 | 917,088 | u379440427 | cpp |
p03107 | #include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#define ll long long
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define vi vector<ll>
#define el printf("\n")
#define N 100001
using namespace std;
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
return (a.first < b.first);
}
int main() {
IOS;
cout.precision(30);
string ch;
cin >> ch;
ll res1 = 0, res0 = 0;
for (int i = 0; i < ch.size(); i++) {
if (ch[i] == '0')
res0++;
else
res1++;
}
cout << min(res1, res0);
return 0;
}
| #include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#define ll long long
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define vi vector<ll>
#define el printf("\n")
#define N 100001
using namespace std;
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
return (a.first < b.first);
}
int main() {
IOS;
cout.precision(30);
string ch;
cin >> ch;
ll res1 = 0, res0 = 0;
for (int i = 0; i < ch.size(); i++) {
if (ch[i] == '0')
res0++;
else
res1++;
}
cout << min(res1, res0) * 2;
return 0;
}
| [
"expression.operation.binary.add"
] | 917,091 | 917,092 | u266346465 | cpp |
p03107 | #include <iostream>
#include <string>
#include <vector>
int main() {
std::string S;
std::cin >> S;
int c = 0;
std::vector<char> B(S.length());
int ans = 0;
for (int i = 0; i < S.length(); i++) {
if (i != S.length() && S[i] != S[i + 1]) {
i++;
ans++;
continue;
}
if (c == 0 || B[c - 1] == S[i]) {
B[c++] = S[i];
} else {
c--;
ans++;
}
}
std::cout << (ans * 2) << std::endl;
return 0;
} | #include <iostream>
#include <string>
#include <vector>
int main() {
std::string S;
std::cin >> S;
int c = 0;
std::vector<char> B(S.length());
int ans = 0;
for (int i = 0; i < S.length(); i++) {
if (i != S.length() - 1 && S[i] != S[i + 1]) {
i++;
ans++;
continue;
}
if (c == 0 || B[c - 1] == S[i]) {
B[c++] = S[i];
} else {
c--;
ans++;
}
}
std::cout << (ans * 2) << std::endl;
return 0;
} | [
"control_flow.branch.if.condition.change",
"control_flow.loop.for.condition.change",
"misc.off_by_one"
] | 917,097 | 917,098 | u922974720 | cpp |
p03107 | #include <bits/stdc++.h>
using namespace std;
struct Fast {
Fast() {
std::cin.tie(0);
ios::sync_with_stdio(false);
}
} fast;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define MOD 1000000007
int main() {
string S;
int num = 0;
int N = S.size();
rep(i, N) {
if (S[i] == '0')
num++;
}
cout << 2 * min(num, N - num) << endl;
}
| #include <bits/stdc++.h>
using namespace std;
struct Fast {
Fast() {
std::cin.tie(0);
ios::sync_with_stdio(false);
}
} fast;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define MOD 1000000007
int main() {
string S;
cin >> S;
int num = 0;
int N = S.size();
rep(i, N) {
if (S[i] == '0')
num++;
}
cout << 2 * min(num, N - num) << endl;
}
| [] | 917,101 | 917,102 | u073486874 | cpp |
p03107 | #include <bits/stdc++.h>
using namespace std;
#define ELEM(array) (sizeof(array) / sizeof *(array))
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
string s;
cin >> s;
int a = 0, b = 0;
rep(i, s.size() - 1) { s[i] == '1' ? a++ : b++; }
cout << min(a, b) * 2;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ELEM(array) (sizeof(array) / sizeof *(array))
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
string s;
cin >> s;
int a = 0, b = 0;
rep(i, s.size()) { s[i] == '1' ? a++ : b++; }
cout << min(a, b) * 2;
return 0;
} | [
"expression.operation.binary.remove"
] | 917,105 | 917,106 | u342813305 | cpp |
p03107 | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#include <string>
using namespace std;
int main() {
string s;
cin >> s;
int zero = 0;
int one = 1;
for (int i = 0; i < s.size(); ++i) {
if (s[i] == '0')
++zero;
else
++one;
}
int ans = 2 * min(zero, one);
cout << ans << endl;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#include <string>
using namespace std;
int main() {
string s;
cin >> s;
int zero = 0;
int one = 0;
for (int i = 0; i < s.size(); ++i) {
if (s[i] == '0')
++zero;
else
++one;
}
int ans = 2 * min(zero, one);
cout << ans << endl;
} | [
"literal.number.change",
"variable_declaration.value.change"
] | 917,112 | 917,113 | u631558039 | cpp |
p03107 | #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
int a = 0;
int b = 0;
for (int i = 0; i < S.size(); i++) {
if (S[i] == '0') {
a++;
} else {
b++;
}
}
cout << min(a, b) << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
int a = 0;
int b = 0;
for (int i = 0; i < S.size(); i++) {
if (S[i] == '0') {
a++;
} else {
b++;
}
}
cout << 2 * min(a, b) << endl;
return 0;
} | [
"expression.operation.binary.add"
] | 917,114 | 917,115 | u426572476 | cpp |
p03097 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll> solve(ll n, ll a, ll b) {
if (n == 1)
return {a, b};
ll bit = 1 << (n - 1);
if ((a & bit) != (b & bit)) {
auto v1 = solve(n - 1, a, a ^ 1);
auto v2 = solve(n - 1, (a ^ 1) ^ bit, b);
v1.insert(v1.end(), v2.begin(), v2.end());
return v1;
} else {
auto v1 = solve(n - 1, a, b);
auto v2 = solve(n - 1, a ^ bit, v1[1] ^ bit);
v1.insert(v1.end(), v2.begin(), v2.end());
return v1;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll n, a, b;
cin >> n >> a >> b;
if (__builtin_parity(a) == __builtin_parity(b))
return cout << "NO", 0;
cout << "YES\n";
auto ans = solve(n, a, b);
for (auto &ele : ans)
cout << ele << " ";
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll> solve(ll n, ll a, ll b) {
if (n == 1)
return {a, b};
ll bit = 1 << (n - 1);
if ((a & bit) != (b & bit)) {
auto v1 = solve(n - 1, a, a ^ 1);
auto v2 = solve(n - 1, (a ^ 1) ^ bit, b);
v1.insert(v1.end(), v2.begin(), v2.end());
return v1;
} else {
auto v1 = solve(n - 1, a, b);
auto v2 = solve(n - 1, a ^ bit, v1[1] ^ bit);
v1.insert(v1.begin() + 1, v2.begin(), v2.end());
return v1;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll n, a, b;
cin >> n >> a >> b;
if (__builtin_parity(a) == __builtin_parity(b))
return cout << "NO", 0;
cout << "YES\n";
auto ans = solve(n, a, b);
for (auto &ele : ans)
cout << ele << " ";
}
| [
"call.function.change",
"call.arguments.change"
] | 917,122 | 917,123 | u740916051 | cpp |
p03097 | #include <algorithm>
#include <bitset>
#include <cassert>
#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;
#define int long long
bool check(vector<int> v) {
for (int i = 0; i + 1 < (int)v.size(); i++) {
if (__builtin_popcount(v[i] ^ v[i + 1]) != 1) {
return false;
}
}
return true;
}
vector<int> genka(int n, int a, int b) {
if (n == 1) {
return {a, b};
}
assert(__builtin_popcount(a ^ b) & 1);
int ca = (a >> (n - 1)) & 1;
int cb = (b >> (n - 1)) & 1;
if (ca != cb) {
int wb = 0;
if (ca) {
a ^= (1 << (n - 1));
b ^= (1 << (n - 1));
wb = 1;
}
for (int mid = 0; mid < (1 << (n - 1)); mid++) {
if (__builtin_popcount(mid ^ a) % 2 == 0)
continue;
if (__builtin_popcount((1 << (n - 1)) ^ mid ^ b) % 2 == 0)
continue;
{
vector<int> f = genka(n - 1, a, mid);
vector<int> s = genka(n - 1, mid, b ^ (1 << (n - 1)));
for (auto t : s) {
f.push_back(t ^ (1 << (n - 1)));
}
if (wb) {
for (auto &t : f) {
t ^= (1 << (n - 1));
}
}
return f;
}
}
} else {
int wb = 0;
if (ca) {
a ^= (1 << (n - 1));
b ^= (1 << (n - 1));
wb = 1;
}
vector<int> f = genka(n - 1, a, b);
{
int i = 0;
int x = f[i];
int y = f[i + 1];
vector<int> s = genka(n - 1, x, y);
vector<int> ans = {f[0]};
for (auto t : s) {
ans.push_back(t ^ (1 << (n - 1)));
}
for (int j = 1; j < (int)f.size(); j++) {
ans.push_back(f[j]);
}
if (wb) {
for (auto &t : ans) {
t ^= (1 << (n - 1));
}
}
return ans;
}
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, a, b;
cin >> n >> a >> b;
int dt = a ^ b;
if (!(__builtin_popcount(dt) & 1)) {
cout << "NO\n";
}
cout << "YES\n";
vector<int> ans = genka(n, a, b);
for (auto t : ans) {
cout << t << ' ';
}
cout << endl;
// for (int i = 0; i < (1 << n); i++) {
// for (int j = 0; j < (1 << n); j++) {
// if (__builtin_popcount(i ^ j) & 1) genka(n, i, j);
// }
// }
}
| #include <algorithm>
#include <bitset>
#include <cassert>
#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;
#define int long long
bool check(vector<int> v) {
for (int i = 0; i + 1 < (int)v.size(); i++) {
if (__builtin_popcount(v[i] ^ v[i + 1]) != 1) {
return false;
}
}
return true;
}
vector<int> genka(int n, int a, int b) {
if (n == 1) {
return {a, b};
}
assert(__builtin_popcount(a ^ b) & 1);
int ca = (a >> (n - 1)) & 1;
int cb = (b >> (n - 1)) & 1;
if (ca != cb) {
int wb = 0;
if (ca) {
a ^= (1 << (n - 1));
b ^= (1 << (n - 1));
wb = 1;
}
for (int mid = 0; mid < (1 << (n - 1)); mid++) {
if (__builtin_popcount(mid ^ a) % 2 == 0)
continue;
if (__builtin_popcount((1 << (n - 1)) ^ mid ^ b) % 2 == 0)
continue;
{
vector<int> f = genka(n - 1, a, mid);
vector<int> s = genka(n - 1, mid, b ^ (1 << (n - 1)));
for (auto t : s) {
f.push_back(t ^ (1 << (n - 1)));
}
if (wb) {
for (auto &t : f) {
t ^= (1 << (n - 1));
}
}
return f;
}
}
} else {
int wb = 0;
if (ca) {
a ^= (1 << (n - 1));
b ^= (1 << (n - 1));
wb = 1;
}
vector<int> f = genka(n - 1, a, b);
{
int i = 0;
int x = f[i];
int y = f[i + 1];
vector<int> s = genka(n - 1, x, y);
vector<int> ans = {f[0]};
for (auto t : s) {
ans.push_back(t ^ (1 << (n - 1)));
}
for (int j = 1; j < (int)f.size(); j++) {
ans.push_back(f[j]);
}
if (wb) {
for (auto &t : ans) {
t ^= (1 << (n - 1));
}
}
return ans;
}
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, a, b;
cin >> n >> a >> b;
int dt = a ^ b;
if (!(__builtin_popcount(dt) & 1)) {
cout << "NO\n";
exit(0);
}
cout << "YES\n";
vector<int> ans = genka(n, a, b);
for (auto t : ans) {
cout << t << ' ';
}
cout << endl;
// for (int i = 0; i < (1 << n); i++) {
// for (int j = 0; j < (1 << n); j++) {
// if (__builtin_popcount(i ^ j) & 1) genka(n, i, j);
// }
// }
}
| [
"call.add",
"call.exit0.add"
] | 917,131 | 917,132 | u293523151 | cpp |
p03097 | //#pragma GCC optimize ("-O3","unroll-loops")
#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 - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m - 1; i >= n; --i)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v, n) reverse(v, v + n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout << (x) << '\n'
#define pe(x) cout << (x) << " "
#define DEBUG(x) cout << #x << ": " << x << endl
#define lb(v, n) lower_bound(v.begin(), v.end(), n)
#define ub(v, n) upper_bound(v.begin(), v.end(), n)
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) \
REP(i, v.size()) cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
#define move(x) ans.push_back(x), c[x]--, now = x;
template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
if (a > b)
a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
if (a < b)
a = b;
}
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int MAX = 200020;
const double pi = acos(-1);
const double EPS = 1e-12;
const ll INF = 2e18;
vector<int> calc(int A, int B, int N) {
vector<int> ret;
if (N == 1) {
ret.push_back(A);
ret.push_back(B);
return ret;
}
int s = 0, t = B ^ A;
if (t < (1 << (N - 1))) {
vector<int> ret1 = calc(s, t, N - 1);
vector<int> ret2 = calc(s ^ (1 << (N - 1)), ret[1] ^ (1 << (N - 1)), N - 1);
ret.push_back(ret1[0]);
REP(i, ret2.size()) { ret.push_back(ret2[i]); }
FOR(i, 1, ret1.size()) ret.push_back(ret1[i]);
REP(i, ret.size()) { ret[i] ^= A; }
} else {
vector<int> ret1 = calc(0, 1, N - 1);
vector<int> ret2 = calc(1 ^ (1 << (N - 1)), t, N - 1);
REP(i, ret1.size()) ret.push_back(ret1[i]);
REP(i, ret2.size()) ret.push_back(ret2[i]);
REP(i, ret.size()) ret[i] ^= A;
}
return ret;
}
void solve() {
int N, A, B;
cin >> N >> A >> B;
if (__builtin_popcount(A) % 2 == __builtin_popcount(B) % 2) {
print("NO");
return;
} else {
print("YES");
vector<int> ans = calc(A, B, N);
REP(i, ans.size()) { pe(ans[i]); }
cout << endl;
}
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
solve();
} | //#pragma GCC optimize ("-O3","unroll-loops")
#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 - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m - 1; i >= n; --i)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v, n) reverse(v, v + n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout << (x) << '\n'
#define pe(x) cout << (x) << " "
#define DEBUG(x) cout << #x << ": " << x << endl
#define lb(v, n) lower_bound(v.begin(), v.end(), n)
#define ub(v, n) upper_bound(v.begin(), v.end(), n)
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) \
REP(i, v.size()) cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
#define move(x) ans.push_back(x), c[x]--, now = x;
template <typename T1, typename T2> inline void chmin(T1 &a, T2 b) {
if (a > b)
a = b;
}
template <typename T1, typename T2> inline void chmax(T1 &a, T2 b) {
if (a < b)
a = b;
}
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int MAX = 200020;
const double pi = acos(-1);
const double EPS = 1e-12;
const ll INF = 2e18;
vector<int> calc(int A, int B, int N) {
vector<int> ret;
if (N == 1) {
ret.push_back(A);
ret.push_back(B);
return ret;
}
int s = 0, t = B ^ A;
if (t < (1 << (N - 1))) {
vector<int> ret1 = calc(s, t, N - 1);
vector<int> ret2 =
calc(s ^ (1 << (N - 1)), ret1[1] ^ (1 << (N - 1)), N - 1);
ret.push_back(ret1[0]);
REP(i, ret2.size()) { ret.push_back(ret2[i]); }
FOR(i, 1, ret1.size()) ret.push_back(ret1[i]);
REP(i, ret.size()) { ret[i] ^= A; }
} else {
vector<int> ret1 = calc(0, 1, N - 1);
vector<int> ret2 = calc(1 ^ (1 << (N - 1)), t, N - 1);
REP(i, ret1.size()) ret.push_back(ret1[i]);
REP(i, ret2.size()) ret.push_back(ret2[i]);
REP(i, ret.size()) ret[i] ^= A;
}
return ret;
}
void solve() {
int N, A, B;
cin >> N >> A >> B;
if (__builtin_popcount(A) % 2 == __builtin_popcount(B) % 2) {
print("NO");
return;
} else {
print("YES");
vector<int> ans = calc(A, B, N);
REP(i, ans.size()) { pe(ans[i]); }
cout << endl;
}
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
solve();
} | [
"identifier.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 917,135 | 917,136 | u859396346 | cpp |
p03097 | #include <bits/stdc++.h>
using namespace std;
vector<int> gen1(int n) {
vector<int> bs1, bs2, bs3;
bs1 = {0, 1, 3, 2};
bs2 = {2, 0, 1, 3};
bs3 = {3, 1, 0, 2};
vector<int> res = {0, 1}, temp;
for (int x = 1; x < n; x += 2) {
temp.clear();
for (int high : bs1)
temp.push_back(high << x | res[0]);
for (int high : bs2)
temp.push_back(high << x | res[1]);
for (int i = 2; i < (int)res.size(); i += 2) {
for (int high : bs3)
temp.push_back(high << x | res[i]);
for (int high : bs2)
temp.push_back(high << x | res[i + 1]);
}
res = temp;
}
for (int i = 0; i < (int)res.size() - 1; i++)
assert(__builtin_popcount(res[i] ^ res[i + 1]) == 1);
assert(*res.begin() == 0 && *res.rbegin() == (1 << n) - 1);
return res;
}
vector<int> gen2(int n) {
vector<int> res = {0, 1}, temp;
if (n == 0)
return {0};
for (int x = 1; x <= n; x++) {
temp.clear();
for (int low : res)
temp.push_back(low);
reverse(res.begin(), res.end());
for (int low : res)
temp.push_back((1 << x) | low);
res = temp;
}
for (int i = 0; i < (int)res.size() - 1; i++)
assert(__builtin_popcount(res[i] ^ res[i + 1]) == 1);
assert(*res.begin() == 0);
return res;
}
vector<int> gen3(int cnt0, int cnt1) {
vector<int> part1 = gen1(cnt1);
vector<int> part0 = gen2(cnt0);
vector<int> res;
for (int low : part1) {
for (int high : part0)
res.push_back(high << cnt1 | low);
reverse(part0.begin(), part0.end());
}
for (int i = 0; i < (int)res.size() - 1; i++)
assert(__builtin_popcount(res[i] ^ res[i + 1]) == 1);
assert(*res.begin() == 0 && *res.rbegin() == (1 << cnt1) - 1);
return res;
}
int id[2][20], cnt0, cnt1;
int main() {
int n, A, B;
scanf("%d%d%d", &n, &A, &B);
B ^= A;
if (!(__builtin_popcount(B) & 1)) {
puts("NO");
return 0;
}
for (int i = 0; i < n; i++) {
if (B >> i & 1)
id[1][cnt1++] = i;
else
id[0][cnt0++] = i;
}
vector<int> temp = gen3(cnt0, cnt1);
puts("YES");
for (int x : temp) {
int res = 0;
for (int i = 0; i < cnt0; i++)
if (x >> (cnt1 + i) & 1)
res += (1 << id[0][i]);
for (int i = 0; i < cnt1; i++)
if (x >> i & 1)
res += (1 << id[1][i]);
printf("%d ", res ^ A);
}
puts("");
return 0;
} | #include <bits/stdc++.h>
using namespace std;
vector<int> gen1(int n) {
vector<int> bs1, bs2, bs3;
bs1 = {0, 1, 3, 2};
bs2 = {2, 0, 1, 3};
bs3 = {3, 1, 0, 2};
vector<int> res = {0, 1}, temp;
for (int x = 1; x < n; x += 2) {
temp.clear();
for (int high : bs1)
temp.push_back(high << x | res[0]);
for (int high : bs2)
temp.push_back(high << x | res[1]);
for (int i = 2; i < (int)res.size(); i += 2) {
for (int high : bs3)
temp.push_back(high << x | res[i]);
for (int high : bs2)
temp.push_back(high << x | res[i + 1]);
}
res = temp;
}
for (int i = 0; i < (int)res.size() - 1; i++)
assert(__builtin_popcount(res[i] ^ res[i + 1]) == 1);
assert(*res.begin() == 0 && *res.rbegin() == (1 << n) - 1);
return res;
}
vector<int> gen2(int n) {
vector<int> res = {0, 1}, temp;
if (n == 0)
return {0};
for (int x = 1; x < n; x++) {
temp.clear();
for (int low : res)
temp.push_back(low);
reverse(res.begin(), res.end());
for (int low : res)
temp.push_back((1 << x) | low);
res = temp;
}
for (int i = 0; i < (int)res.size() - 1; i++)
assert(__builtin_popcount(res[i] ^ res[i + 1]) == 1);
assert(*res.begin() == 0);
return res;
}
vector<int> gen3(int cnt0, int cnt1) {
vector<int> part1 = gen1(cnt1);
vector<int> part0 = gen2(cnt0);
vector<int> res;
for (int low : part1) {
for (int high : part0)
res.push_back(high << cnt1 | low);
reverse(part0.begin(), part0.end());
}
for (int i = 0; i < (int)res.size() - 1; i++)
assert(__builtin_popcount(res[i] ^ res[i + 1]) == 1);
assert(*res.begin() == 0 && *res.rbegin() == (1 << cnt1) - 1);
return res;
}
int id[2][20], cnt0, cnt1;
int main() {
int n, A, B;
scanf("%d%d%d", &n, &A, &B);
B ^= A;
if (!(__builtin_popcount(B) & 1)) {
puts("NO");
return 0;
}
for (int i = 0; i < n; i++) {
if (B >> i & 1)
id[1][cnt1++] = i;
else
id[0][cnt0++] = i;
}
vector<int> temp = gen3(cnt0, cnt1);
puts("YES");
for (int x : temp) {
int res = 0;
for (int i = 0; i < cnt0; i++)
if (x >> (cnt1 + i) & 1)
res += (1 << id[0][i]);
for (int i = 0; i < cnt1; i++)
if (x >> i & 1)
res += (1 << id[1][i]);
printf("%d ", res ^ A);
}
puts("");
return 0;
} | [
"expression.operator.compare.change",
"control_flow.loop.for.condition.change",
"expression.off_by_one",
"expression.operation.binary.change"
] | 917,137 | 917,138 | u366089652 | cpp |
p03097 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
// x の下から key 番目 (0-indexed) の bit を消す
int erase_bit(int x, int key) {
int mask = pow(2, key);
int low = x & (mask - 1);
x = (x / (mask * 2)) * mask;
return x + low;
}
// x の下から key 番目 (0-indexed) に bit を挿入
int insert_bit(int x, int key, int bit) {
int mask = pow(2, key);
int low = x & (mask - 1);
x = (x - low) * 2 + bit * mask;
return x + low;
}
vector<int> solve(int a, int b, int n) {
if (n == 1)
return {a, b};
int d = a ^ b;
int key = __builtin_ctz(d); // このbitを消す
int a_key = 0;
int b_key = 0;
if (a & (1 << key))
a_key = 1;
if (b & (1 << key))
b_key = 1;
// a_key != b_key
a = erase_bit(a, key);
b = erase_bit(b, key);
int c = a ^ 1;
auto ac = solve(a, c, n - 1);
for (int x : ac) {
x = insert_bit(x, key, a_key);
}
auto cb = solve(c, b, n - 1);
for (int x : cb) {
x = insert_bit(x, key, b_key);
ac.push_back(x);
}
return ac;
}
int main() {
int N, A, B;
cin >> N >> A >> B;
if (!__builtin_parity(A ^ B)) {
cout << " ";
return 0;
}
cout << "YES"
<< "\n";
auto ans = solve(A, B, N);
for (int x : ans) {
cout << x << " ";
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
// x の下から key 番目 (0-indexed) の bit を消す
int erase_bit(int x, int key) {
int mask = pow(2, key);
int low = x & (mask - 1);
x = (x / (mask * 2)) * mask;
return x + low;
}
// x の下から key 番目 (0-indexed) に bit を挿入
int insert_bit(int x, int key, int bit) {
int mask = pow(2, key);
int low = x & (mask - 1);
x = (x - low) * 2 + bit * mask;
return x + low;
}
vector<int> solve(int a, int b, int n) {
if (n == 1)
return {a, b};
int d = a ^ b;
int key = __builtin_ctz(d); // このbitを消す
int a_key = 0;
int b_key = 0;
if (a & (1 << key))
a_key = 1;
if (b & (1 << key))
b_key = 1;
// a_key != b_key
a = erase_bit(a, key);
b = erase_bit(b, key);
int c = a ^ 1;
auto ac = solve(a, c, n - 1);
for (int &x : ac) {
x = insert_bit(x, key, a_key);
}
auto cb = solve(c, b, n - 1);
for (int &x : cb) {
x = insert_bit(x, key, b_key);
ac.push_back(x);
}
return ac;
}
int main() {
int N, A, B;
cin >> N >> A >> B;
if (!__builtin_parity(A ^ B)) {
cout << "NO";
return 0;
}
cout << "YES"
<< "\n";
auto ans = solve(A, B, N);
for (int x : ans) {
cout << x << " ";
}
return 0;
} | [
"literal.string.change",
"io.output.change"
] | 917,141 | 917,142 | u590088474 | cpp |
p03097 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
// x の下から key 番目 (0-indexed) の bit を消す
int erase_bit(int x, int key) {
int mask = pow(2, key);
int low = x & (mask - 1);
x = (x / (mask * 2)) * mask;
return x + low;
}
// x の下から key 番目 (0-indexed) に bit を挿入
int insert_bit(int x, int key, int bit) {
int mask = pow(2, key);
int low = x & (mask - 1);
x = (x - low) * 2 + bit * mask;
return x + low;
}
vector<int> solve(int a, int b, int n) {
if (n == 1)
return {a, b};
int d = a ^ b;
int key = __builtin_ctz(d); // このbitを消す
int a_key = 0;
int b_key = 0;
if (a & (1 << key))
a_key = 1;
if (b & (1 << key))
b_key = 1;
// a_key != b_key
a = erase_bit(a, key);
b = erase_bit(b, key);
int c = a ^ 1;
auto ac = solve(a, c, n - 1);
for (int x : ac) {
x = insert_bit(x, key, a_key);
}
auto cb = solve(c, b, n - 1);
for (int x : cb) {
x = insert_bit(x, key, b_key);
ac.push_back(x);
}
return ac;
}
int main() {
int N, A, B;
cin >> N >> A >> B;
if (!__builtin_parity(A ^ B)) {
cout << "NO";
return 0;
}
cout << "YES"
<< "\n";
auto ans = solve(A, B, N);
for (int x : ans) {
cout << x << " ";
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
// x の下から key 番目 (0-indexed) の bit を消す
int erase_bit(int x, int key) {
int mask = pow(2, key);
int low = x & (mask - 1);
x = (x / (mask * 2)) * mask;
return x + low;
}
// x の下から key 番目 (0-indexed) に bit を挿入
int insert_bit(int x, int key, int bit) {
int mask = pow(2, key);
int low = x & (mask - 1);
x = (x - low) * 2 + bit * mask;
return x + low;
}
vector<int> solve(int a, int b, int n) {
if (n == 1)
return {a, b};
int d = a ^ b;
int key = __builtin_ctz(d); // このbitを消す
int a_key = 0;
int b_key = 0;
if (a & (1 << key))
a_key = 1;
if (b & (1 << key))
b_key = 1;
// a_key != b_key
a = erase_bit(a, key);
b = erase_bit(b, key);
int c = a ^ 1;
auto ac = solve(a, c, n - 1);
for (int &x : ac) {
x = insert_bit(x, key, a_key);
}
auto cb = solve(c, b, n - 1);
for (int &x : cb) {
x = insert_bit(x, key, b_key);
ac.push_back(x);
}
return ac;
}
int main() {
int N, A, B;
cin >> N >> A >> B;
if (!__builtin_parity(A ^ B)) {
cout << "NO";
return 0;
}
cout << "YES"
<< "\n";
auto ans = solve(A, B, N);
for (int x : ans) {
cout << x << " ";
}
return 0;
} | [] | 917,143 | 917,142 | u590088474 | cpp |
p03097 | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPP(i, n) for (int i = 1; i <= n; i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF = (long long)1E17;
#define i_7 (long long)(1E9 + 7)
long mod(long a) {
long long c = a % i_7;
if (c >= 0)
return c;
return c + i_7;
}
using namespace std;
bool prime_(int n) {
if (n == 1) {
return false;
} else if (n == 2) {
return true;
} else {
for (int i = 2; i <= sqrt(n); i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
}
long long gcd_(long long a, long long b) {
if (a < b) {
swap(a, b);
}
if (a % b == 0) {
return b;
} else {
return gcd_(b, a % b);
}
}
long long lcm_(long long x, long long y) { return (x / gcd_(x, y)) * y; }
class UnionFind {
public:
//各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
vector<int> Parent;
//クラスを作るときは、Parentの値を全て-1にする。
//以下のようにすると全てバラバラの頂点として解釈できる。
UnionFind(int N) { Parent = vector<int>(N, -1); }
// Aがどのグループに属しているか調べる
int root(int A) {
if (Parent[A] < 0)
return A;
return Parent[A] = root(Parent[A]);
}
//自分のいるグループの頂点数を調べる
int size(int A) {
return -Parent[root(A)]; //先祖をrootで取っておきたい。
}
// AとBをくっ付ける
bool connect(int A, int B) {
// AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
A = root(A);
B = root(B);
if (A == B) {
//すでにくっついてるからくっ付けない
return false;
}
//大きい方(A)に小さいほう(B)をくっ付けたい
//大小が逆だったらAとBをひっくり返す。
if (size(A) < size(B))
swap(A, B);
// Aのサイズを更新する
Parent[A] += Parent[B];
// Bの親をAに変更する
Parent[B] = A;
return true;
}
};
vector<int> p(1 << 17, -1);
// dfs(n,a,b,0,(1<<n)-1);として呼ぶ
void dfs(int n, int a, int b, int start_i, int end_i) {
if (n == 1) {
p[start_i] = a;
p[end_i] = b;
return;
}
int x;
REP(i, n) {
if ((a >> i) % 2 != (b >> i) % 2) { // 2^iの桁の値が異なる時
x = i;
break;
}
}
int fa = 0, fb = 0; // a,bからxビット目を除いた値
REP(i, n) {
if (i == x)
continue;
if (i < x) {
fa += ((a >> i) % 2) << i;
fb += ((b >> i) % 2) << i;
} else {
fa += ((a >> i) % 2) << (i - 1);
fb += ((b >> i) % 2) << (i - 1);
}
}
int c; // fa,fbと立っているビットの数の偶奇が異なるもの
int last_ = fa % 2;
c = (fa >> 1) << 1 + (last_ + 1) % 2;
dfs(n - 1, fa, c, start_i, start_i + (1 << (n - 1)) - 1);
dfs(n - 1, c, fb, start_i + (1 << (n - 1)), end_i);
int temp;
REP(i, 1 << (n - 1)) {
temp = 0;
REP(j, n) {
if (j < x) {
temp += ((p[start_i + i] >> j) % 2) << j;
} else if (j == x) {
temp += ((a >> x) % 2) << x;
} else {
temp += ((p[start_i + i] >> (j - 1)) % 2) << j;
}
}
p[start_i + i] = temp;
}
for (int i = start_i + (1 << (n - 1)); i <= end_i; i++) {
temp = 0;
REP(j, n) {
if (j < x) {
temp += ((p[i] >> j) % 2) << j;
} else if (j == x) {
temp += ((b >> x) % 2) << x;
} else {
temp += ((p[i] >> (j - 1)) % 2) << j;
}
}
p[i] = temp;
}
return;
}
int main() {
int n, a, b;
cin >> n >> a >> b;
int cnta = 0, cntb = 0;
// int x;
REP(i, n) {
cnta += (a >> i) % 2;
cntb += (b >> i) % 2;
}
if (cnta % 2 == cntb % 2) {
cout << "NO" << endl;
return 0;
}
dfs(n, a, b, 0, (1 << n) - 1);
cout << "YES" << endl;
REP(i, 1 << n) { cout << p[i] << ' '; }
cout << endl;
return 0;
} | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPP(i, n) for (int i = 1; i <= n; i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF = (long long)1E17;
#define i_7 (long long)(1E9 + 7)
long mod(long a) {
long long c = a % i_7;
if (c >= 0)
return c;
return c + i_7;
}
using namespace std;
bool prime_(int n) {
if (n == 1) {
return false;
} else if (n == 2) {
return true;
} else {
for (int i = 2; i <= sqrt(n); i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
}
long long gcd_(long long a, long long b) {
if (a < b) {
swap(a, b);
}
if (a % b == 0) {
return b;
} else {
return gcd_(b, a % b);
}
}
long long lcm_(long long x, long long y) { return (x / gcd_(x, y)) * y; }
class UnionFind {
public:
//各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
vector<int> Parent;
//クラスを作るときは、Parentの値を全て-1にする。
//以下のようにすると全てバラバラの頂点として解釈できる。
UnionFind(int N) { Parent = vector<int>(N, -1); }
// Aがどのグループに属しているか調べる
int root(int A) {
if (Parent[A] < 0)
return A;
return Parent[A] = root(Parent[A]);
}
//自分のいるグループの頂点数を調べる
int size(int A) {
return -Parent[root(A)]; //先祖をrootで取っておきたい。
}
// AとBをくっ付ける
bool connect(int A, int B) {
// AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
A = root(A);
B = root(B);
if (A == B) {
//すでにくっついてるからくっ付けない
return false;
}
//大きい方(A)に小さいほう(B)をくっ付けたい
//大小が逆だったらAとBをひっくり返す。
if (size(A) < size(B))
swap(A, B);
// Aのサイズを更新する
Parent[A] += Parent[B];
// Bの親をAに変更する
Parent[B] = A;
return true;
}
};
vector<int> p(1 << 17, -1);
// dfs(n,a,b,0,(1<<n)-1);として呼ぶ
void dfs(int n, int a, int b, int start_i, int end_i) {
if (n == 1) {
p[start_i] = a;
p[end_i] = b;
return;
}
int x;
REP(i, n) {
if ((a >> i) % 2 != (b >> i) % 2) { // 2^iの桁の値が異なる時
x = i;
break;
}
}
int fa = 0, fb = 0; // a,bからxビット目を除いた値
REP(i, n) {
if (i == x)
continue;
if (i < x) {
fa += ((a >> i) % 2) << i;
fb += ((b >> i) % 2) << i;
} else {
fa += ((a >> i) % 2) << (i - 1);
fb += ((b >> i) % 2) << (i - 1);
}
}
int c; // fa,fbと立っているビットの数の偶奇が異なるもの
int last_ = fa % 2;
c = ((fa >> 1) << 1) + (last_ + 1) % 2;
dfs(n - 1, fa, c, start_i, start_i + (1 << (n - 1)) - 1);
dfs(n - 1, c, fb, start_i + (1 << (n - 1)), end_i);
int temp;
REP(i, 1 << (n - 1)) {
temp = 0;
REP(j, n) {
if (j < x) {
temp += ((p[start_i + i] >> j) % 2) << j;
} else if (j == x) {
temp += ((a >> x) % 2) << x;
} else {
temp += ((p[start_i + i] >> (j - 1)) % 2) << j;
}
}
p[start_i + i] = temp;
}
for (int i = start_i + (1 << (n - 1)); i <= end_i; i++) {
temp = 0;
REP(j, n) {
if (j < x) {
temp += ((p[i] >> j) % 2) << j;
} else if (j == x) {
temp += ((b >> x) % 2) << x;
} else {
temp += ((p[i] >> (j - 1)) % 2) << j;
}
}
p[i] = temp;
}
return;
}
int main() {
int n, a, b;
cin >> n >> a >> b;
int cnta = 0, cntb = 0;
// int x;
REP(i, n) {
cnta += (a >> i) % 2;
cntb += (b >> i) % 2;
}
if (cnta % 2 == cntb % 2) {
cout << "NO" << endl;
return 0;
}
dfs(n, a, b, 0, (1 << n) - 1);
cout << "YES" << endl;
REP(i, 1 << n) { cout << p[i] << ' '; }
cout << endl;
return 0;
}
| [] | 917,144 | 917,145 | u222293734 | cpp |
p03097 | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define int long long
#define double long double
#define all(a) a.begin(), a.end()
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
using namespace std;
int N, A, B;
vector<int> answer;
vector<bool> used;
void dfs(int start, int goal, int bit) {
bit--;
if (bit == 0) {
answer.push_back(start);
answer.push_back(goal);
} else if ((start ^ goal) & (1 << bit)) {
int nst = start ^ 1;
dfs(start, nst, bit);
int ngo = nst ^ (1 << bit);
dfs(ngo, goal, bit);
} else {
dfs(start, goal, bit);
answer.pop_back();
int nst = answer.back() ^ (1 << bit);
int ngo = goal ^ (1 << bit);
dfs(nst, ngo, bit);
answer.push_back(goal);
}
}
signed main(void) {
cin >> N >> A >> B;
if (__builtin_popcount(A) == __builtin_popcount(B)) {
cout << "NO\n";
return 0;
}
cout << "YES\n";
dfs(A, B, N);
rep(i, answer.size()) {
if (i == answer.size() - 1)
cout << answer[i] << '\n';
else
cout << answer[i] << ' ';
}
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define int long long
#define double long double
#define all(a) a.begin(), a.end()
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
using namespace std;
int N, A, B;
vector<int> answer;
vector<bool> used;
void dfs(int start, int goal, int bit) {
bit--;
if (bit == 0) {
answer.push_back(start);
answer.push_back(goal);
} else if ((start ^ goal) & (1 << bit)) {
int nst = start ^ 1;
dfs(start, nst, bit);
int ngo = nst ^ (1 << bit);
dfs(ngo, goal, bit);
} else {
dfs(start, goal, bit);
answer.pop_back();
int nst = answer.back() ^ (1 << bit);
int ngo = goal ^ (1 << bit);
dfs(nst, ngo, bit);
answer.push_back(goal);
}
}
signed main(void) {
cin >> N >> A >> B;
if (__builtin_popcount(A) % 2 == __builtin_popcount(B) % 2) {
cout << "NO\n";
return 0;
}
cout << "YES\n";
dfs(A, B, N);
rep(i, answer.size()) {
if (i == answer.size() - 1)
cout << answer[i] << '\n';
else
cout << answer[i] << ' ';
}
} | [
"control_flow.branch.if.condition.change"
] | 917,146 | 917,147 | u807998890 | cpp |
p03097 | #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define fastIO \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
mt19937 rnd(chrono::steady_clock().now().time_since_epoch().count());
int popcount(int a) { return __builtin_popcount(a); }
vector<int> solve(int n, int a, int b) {
if (n == 1) {
return {a, b};
}
int bit = (1 << (n - 1));
if ((a & bit) != (b & bit)) {
vector<int> s1, s2;
s1 = solve(n - 1, a, a ^ 1);
s2 = solve(n - 1, (a ^ 1) ^ bit, b);
for (auto p : s2)
s1.push_back(p);
return s1;
} else {
vector<int> s1, s2;
s1 = solve(n - 1, a, b);
s2 = solve(n - 1, a ^ bit, (s1[1] ^ bit));
vector<int> vv = {s1[0]};
for (auto x : s2)
vv.push_back(x);
for (int i = 1; i < s1.size(); i++)
vv.push_back(s1[i]);
return s1;
}
}
int main() {
fastIO;
int n, a, b;
cin >> n >> a >> b;
if (popcount(a) % 2 == popcount(b) % 2) {
cout << "NO\n";
return 0;
}
cout << "YES\n";
vector<int> res = solve(n, a, b);
for (auto x : res)
cout << x << " ";
return 0;
} | #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define fastIO \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
mt19937 rnd(chrono::steady_clock().now().time_since_epoch().count());
int popcount(int a) { return __builtin_popcount(a); }
vector<int> solve(int n, int a, int b) {
if (n == 1) {
return {a, b};
}
int bit = (1 << (n - 1));
if ((a & bit) != (b & bit)) {
vector<int> s1, s2;
s1 = solve(n - 1, a, a ^ 1);
s2 = solve(n - 1, (a ^ 1) ^ bit, b);
for (auto p : s2)
s1.push_back(p);
return s1;
} else {
vector<int> s1, s2;
s1 = solve(n - 1, a, b);
s2 = solve(n - 1, a ^ bit, (s1[1] ^ bit));
vector<int> vv = {s1[0]};
for (auto x : s2)
vv.push_back(x);
for (int i = 1; i < s1.size(); i++)
vv.push_back(s1[i]);
return vv;
}
}
int main() {
fastIO;
int n, a, b;
cin >> n >> a >> b;
if (popcount(a) % 2 == popcount(b) % 2) {
cout << "NO\n";
return 0;
}
cout << "YES\n";
vector<int> res = solve(n, a, b);
for (auto x : res)
cout << x << " ";
return 0;
} | [
"identifier.change",
"function.return_value.change"
] | 917,148 | 917,149 | u722777218 | cpp |
p03097 | #define DEBUG 0
/**
* File : C2.cpp
* Author : Kazune Takahashi
* Created : 2019-5-29 17:31:56
* Powered by Visual Studio Code
*/
#include <algorithm>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
vector<int> ans;
void Yes() {
cout << "YES" << endl;
int M = ans.size();
for (auto i = 0; i < M; i++) {
cout << ans[i];
if (i < M - 1) {
cout << " ";
} else {
cout << endl;
}
}
exit(0);
}
void No() {
cout << "NO" << endl;
exit(0);
}
/*
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
*/
// const ll MOD = 1000000007;
int N;
int cnt(int x) {
int ans = 0;
for (auto i = 0; i < 30; i++) {
if (x >> i & 1) {
ans++;
}
}
return ans;
}
void dfs(int A, int B, int mask) {
if (cnt(mask) == N - 1) {
ans.push_back(A);
ans.push_back(B);
return;
}
int ind;
for (ind = 0; ind < N; ind++) {
if (mask >> ind & 1) {
continue;
}
if ((A >> ind & 1) != (B >> ind & 1)) {
break;
}
}
int new_mask = mask | 1 << ind;
int next;
for (next = 0; next < N; next++) {
if (mask >> next & 1) {
continue;
}
break;
}
int C = A ^ 1 << next;
int D = C ^ 1 << ind;
dfs(A, C, new_mask);
dfs(D, B, new_mask);
}
int main() {
int A, B;
cin >> N >> A >> B;
if (cnt(A ^ B) % 2 == 0) {
No();
} else {
dfs(A, B, 0);
Yes();
}
} | #define DEBUG 0
/**
* File : C2.cpp
* Author : Kazune Takahashi
* Created : 2019-5-29 17:31:56
* Powered by Visual Studio Code
*/
#include <algorithm>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
vector<int> ans;
void Yes() {
cout << "YES" << endl;
int M = ans.size();
for (auto i = 0; i < M; i++) {
cout << ans[i];
if (i < M - 1) {
cout << " ";
} else {
cout << endl;
}
}
exit(0);
}
void No() {
cout << "NO" << endl;
exit(0);
}
/*
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
*/
// const ll MOD = 1000000007;
int N;
int cnt(int x) {
int ans = 0;
for (auto i = 0; i < 30; i++) {
if (x >> i & 1) {
ans++;
}
}
return ans;
}
void dfs(int A, int B, int mask) {
if (cnt(mask) == N - 1) {
ans.push_back(A);
ans.push_back(B);
return;
}
int ind;
for (ind = 0; ind < N; ind++) {
if (mask >> ind & 1) {
continue;
}
if ((A >> ind & 1) != (B >> ind & 1)) {
break;
}
}
int new_mask = mask | 1 << ind;
int next;
for (next = 0; next < N; next++) {
if (new_mask >> next & 1) {
continue;
}
break;
}
int C = A ^ 1 << next;
int D = C ^ 1 << ind;
dfs(A, C, new_mask);
dfs(D, B, new_mask);
}
int main() {
int A, B;
cin >> N >> A >> B;
if (cnt(A ^ B) % 2 == 0) {
No();
} else {
dfs(A, B, 0);
Yes();
}
} | [
"identifier.change",
"control_flow.branch.if.condition.change"
] | 917,152 | 917,153 | u521272340 | cpp |
p03097 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
#define rep(i, j, k) for (int i = j; i < k; i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define mt make_tuple
#define iv inline void
#define ii inline int
#define ill inline ll
template <typename S, typename T> inline bool smin(S &l, T r) {
return r < l ? l = r, 1 : 0;
}
template <typename S, typename T> inline bool smax(S &l, T r) {
return l < r ? l = r, 1 : 0;
}
constexpr int MOD = 1e9 + 7; // 998244353;
template <typename S> inline S mod(S &l) { return l = (l % MOD + MOD) % MOD; }
template <typename S, typename T> inline S add(S &l, T r) {
return mod(l += r);
}
ill po(ll v, ll u) {
return u ? po(v * v % MOD, u >> 1) * (u & 1 ? v : 1) % MOD : 1;
}
void fileIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
constexpr int N = 1e6 + 10;
int n, A, B;
vi res;
void solve(int mask, int last, int VAL) {
if (__builtin_popcount(mask) == 1) {
res.pb(VAL);
res.pb(VAL ^ mask);
return;
}
int bit = 1 << __builtin_ctz(last);
int bit2 = 1 << __builtin_ctz(mask ^ bit);
solve(mask ^ bit, bit2, VAL);
solve(mask ^ bit, last ^ bit ^ bit2, VAL ^ bit2 ^ bit);
}
int main() {
#ifndef LOCAL
// fileIO("");
#endif
cin >> n >> A >> B;
if (__builtin_popcount(A ^ B) & 1 == 0)
return cout << "NO\n", 0;
cout << "YES\n";
solve((1 << n) - 1, B ^ A, A);
for (auto e : res)
cout << e << ' ';
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
#define rep(i, j, k) for (int i = j; i < k; i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define mt make_tuple
#define iv inline void
#define ii inline int
#define ill inline ll
template <typename S, typename T> inline bool smin(S &l, T r) {
return r < l ? l = r, 1 : 0;
}
template <typename S, typename T> inline bool smax(S &l, T r) {
return l < r ? l = r, 1 : 0;
}
constexpr int MOD = 1e9 + 7; // 998244353;
template <typename S> inline S mod(S &l) { return l = (l % MOD + MOD) % MOD; }
template <typename S, typename T> inline S add(S &l, T r) {
return mod(l += r);
}
ill po(ll v, ll u) {
return u ? po(v * v % MOD, u >> 1) * (u & 1 ? v : 1) % MOD : 1;
}
void fileIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
constexpr int N = 1e6 + 10;
int n, A, B;
vi res;
void solve(int mask, int last, int VAL) {
if (__builtin_popcount(mask) == 1) {
res.pb(VAL);
res.pb(VAL ^ mask);
return;
}
int bit = 1 << __builtin_ctz(last);
int bit2 = 1 << __builtin_ctz(mask ^ bit);
solve(mask ^ bit, bit2, VAL);
solve(mask ^ bit, last ^ bit ^ bit2, VAL ^ bit2 ^ bit);
}
int main() {
#ifndef LOCAL
// fileIO("");
#endif
cin >> n >> A >> B;
if ((__builtin_popcount(A ^ B) & 1) == 0)
return cout << "NO\n", 0;
cout << "YES\n";
solve((1 << n) - 1, B ^ A, A);
for (auto e : res)
cout << e << ' ';
return 0;
}
| [
"control_flow.branch.if.condition.change"
] | 917,154 | 917,155 | u542025675 | cpp |
p03097 | #include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define pb emplace_back
typedef long long ll;
typedef pair<int, int> pint;
int n, a, b;
vector<int> ret;
void dfs(int l, int r, int mask) {
if (mask & (mask - 1) == 0) {
ret.pb(l);
ret.pb(r);
return;
}
int x = l ^ r;
int tb = x & -x, tc = mask ^ tb;
int td = tc & -tc;
dfs(l, l ^ td, tc);
dfs(l ^ tb ^ td, r, tc);
}
int main() {
cin >> n >> a >> b;
if (__builtin_popcount(a) % 2 == __builtin_popcount(b) % 2) {
cout << "NO" << endl;
return 0;
}
dfs(a, b, (1 << n) - 1);
cout << "YES" << endl;
rep(i, ret.size()) { cout << ret[i] << " "; }
cout << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define pb emplace_back
typedef long long ll;
typedef pair<int, int> pint;
int n, a, b;
vector<int> ret;
void dfs(int l, int r, int mask) {
if ((mask & (mask - 1)) == 0) {
ret.pb(l);
ret.pb(r);
return;
}
int x = l ^ r;
int tb = x & -x, tc = mask ^ tb;
int td = tc & -tc;
dfs(l, l ^ td, tc);
dfs(l ^ tb ^ td, r, tc);
}
int main() {
cin >> n >> a >> b;
if (__builtin_popcount(a) % 2 == __builtin_popcount(b) % 2) {
cout << "NO" << endl;
return 0;
}
dfs(a, b, (1 << n) - 1);
cout << "YES" << endl;
rep(i, ret.size()) { cout << ret[i] << " "; }
cout << endl;
return 0;
}
| [
"control_flow.branch.if.condition.change"
] | 917,166 | 917,167 | u526367939 | cpp |
p03097 | //#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>
using namespace std;
//@起動時
struct initon {
initon() {
cin.tie(0);
ios::sync_with_stdio(false);
cout.setf(ios::fixed);
cout.precision(16);
srand((unsigned)clock() + (unsigned)time(NULL));
};
} __initon;
//衝突対策
#define ws ___ws
//@必須構造
struct T {
int f, s, t;
T() { f = -1, s = -1, t = -1; }
T(int f, int s, int t) : f(f), s(s), t(t) {}
bool operator<(const T &r) const {
return f != r.f ? f < r.f : s != r.s ? s < r.s : t < r.t;
// return f != r.f ? f > r.f : s != r.s ? s > r.s : t > r.t; 大きい順
}
bool operator>(const T &r) const {
return f != r.f ? f > r.f : s != r.s ? s > r.s : t > r.t;
// return f != r.f ? f > r.f : s != r.s ? s > r.s : t > r.t; 小さい順
}
bool operator==(const T &r) const { return f == r.f && s == r.s && t == r.t; }
bool operator!=(const T &r) const { return f != r.f || s != r.s || t != r.t; }
int operator[](int i) {
assert(i < 3);
return i == 0 ? f : i == 1 ? s : t;
}
};
struct F {
int a, b, c, d;
F() { a = -1, b = -1, c = -1, d = -1; }
F(int a, int b, int c, int d) : a(a), b(b), c(c), d(d) {}
bool operator<(const F &r) const {
return a != r.a ? a < r.a
: b != r.b ? b < r.b
: c != r.c ? c < r.c
: d < r.d;
// return a != r.a ? a > r.a : b != r.b ? b > r.b : c != r.c ? c >
// r.c : d > r.d;
}
bool operator>(const F &r) const {
return a != r.a ? a > r.a
: b != r.b ? b > r.b
: c != r.c ? c > r.c
: d > r.d;
// return a != r.a ? a < r.a : b != r.b ? b < r.b : c != r.c ? c <
// r.c : d < r.d;
}
bool operator==(const F &r) const {
return a == r.a && b == r.b && c == r.c && d == r.d;
}
bool operator!=(const F &r) const {
return a != r.a || b != r.b || c != r.c || d != r.d;
}
int operator[](int i) {
assert(i < 4);
return i == 0 ? a : i == 1 ? b : i == 2 ? c : d;
}
};
T mt(int a, int b, int c) { return T(a, b, c); }
//@マクロ省略系 型,構造
#define int long long
#define ll long long
#define double long double
#define ull unsigned long long
using dou = double;
using itn = int;
using str = string;
using bo = bool;
using P = pair<ll, ll>;
#define fi first
#define se second
#define vec vector
#define beg begin
#define rbeg rbegin
#define con continue
#define bre break
#define brk break
#define is ==
//マクロ省略系 コンテナ
using vi = vector<int>;
#define _overloadvvi(_1, _2, _3, _4, name, ...) name
#define vvi0() vec<vi>
#define vvi1(a) vec<vi> a
#define vvi2(a, b) vec<vi> a(b)
#define vvi3(a, b, c) vec<vi> a(b, vi(c))
#define vvi4(a, b, c, d) vec<vi> a(b, vi(c, d))
#define vvi(...) \
_overloadvvi(__VA_ARGS__, vvi4, vvi3, vvi2, vvi1, vvi0)(__VA_ARGS__)
using vl = vector<ll>;
#define _overloadvvl(_1, _2, _3, _4, name, ...) name
#define vvl1(a) vec<vl> a
#define vvl2(a, b) vec<vl> a(b)
#define vvl3(a, b, c) vec<vl> a(b, vl(c))
#define vvl4(a, b, c, d) vec<vl> a(b, vl(c, d))
#define vvl(...) _overloadvvl(__VA_ARGS__, vvl4, vvl3, vvl2, vvl1)(__VA_ARGS__)
using vb = vector<bool>;
#define _overloadvvb(_1, _2, _3, _4, name, ...) name
#define vvb1(a) vec<vb> a
#define vvb2(a, b) vec<vb> a(b)
#define vvb3(a, b, c) vec<vb> a(b, vb(c))
#define vvb4(a, b, c, d) vec<vb> a(b, vb(c, d))
#define vvb(...) _overloadvvb(__VA_ARGS__, vvb4, vvb3, vvb2, vvb1)(__VA_ARGS__)
using vs = vector<string>;
#define _overloadvvs(_1, _2, _3, _4, name, ...) name
#define vvs1(a) vec<vs> a
#define vvs2(a, b) vec<vs> a(b)
#define vvs3(a, b, c) vec<vs> a(b, vs(c))
#define vvs4(a, b, c, d) vec<vs> a(b, vs(c, d))
#define vvs(...) _overloadvvs(__VA_ARGS__, vvs4, vvs3, vvs2, vvs1)(__VA_ARGS__)
using vd = vector<double>;
#define _overloadvvd(_1, _2, _3, _4, name, ...) name
#define vvd1(a) vec<vd> a
#define vvd2(a, b) vec<vd> a(b)
#define vvd3(a, b, c) vec<vd> a(b, vd(c))
#define vvd4(a, b, c, d) vec<vd> a(b, vd(c, d))
#define vvd(...) _overloadvvd(__VA_ARGS__, vvd4, vvd3, vvd2, vvd1)(__VA_ARGS__)
using vc = vector<char>;
#define _overloadvvc(_1, _2, _3, _4, name, ...) name
#define vvc1(a) vec<vc> a
#define vvc2(a, b) vec<vc> a(b)
#define vvc3(a, b, c) vec<vc> a(b, vc(c))
#define vvc4(a, b, c, d) vec<vc> a(b, vc(c, d))
#define vvc(...) _overloadvvc(__VA_ARGS__, vvc4, vvc3, vvc2, vvc1)(__VA_ARGS__)
using vp = vector<P>;
#define _overloadvvp(_1, _2, _3, _4, name, ...) name
#define vvp1(a) vec<vp> a
#define vvp2(a, b) vec<vp> a(b)
#define vvp3(a, b, c) vec<vp> a(b, vp(c))
#define vvp4(a, b, c, d) vec<vp> a(b, vp(c, d))
using vt = vector<T>;
#define _overloadvvt(_1, _2, _3, _4, name, ...) name
#define vvt1(a) vec<vt> a
#define vvt2(a, b) vec<vt> a(b)
#define vvt3(a, b, c) vec<vt> a(b, vt(c))
#define vvt4(a, b, c, d) vec<vt> a(b, vt(c, d))
#define v3i(a, b, c, d) vector<vector<vi>> a(b, vector<vi>(c, vi(d)))
#define v3d(a, b, c, d) vector<vector<vd>> a(b, vector<vd>(c, vd(d)))
#define v3m(a, b, c, d) vector<vector<vm>> a(b, vector<vm>(c, vm(d)))
#define _vvi vector<vi>
#define _vvl vector<vl>
#define _vvb vector<vb>
#define _vvs vector<vs>
#define _vvd vector<vd>
#define _vvc vector<vc>
#define _vvp vector<vp>
#define PQ priority_queue<ll, vector<ll>, greater<ll>>
#define tos to_string
using mapi = map<int, int>;
using mapd = map<dou, int>;
using mapc = map<char, int>;
using maps = map<str, int>;
using seti = set<int>;
using setd = set<dou>;
using setc = set<char>;
using sets = set<str>;
using qui = queue<int>;
#define bset bitset
#define uset unordered_set
#define mset multiset
#define umap unordered_map
#define umapi unordered_map<int, int>
#define umapp unordered_map<P, int>
#define mmap multimap
//マクロ 繰り返し
#define _overloadrep(_1, _2, _3, _4, name, ...) name
#define _rep(i, n) for (int i = 0, _lim = n; i < _lim; i++)
#define repi(i, m, n) for (int i = m, _lim = n; i < _lim; i++)
#define repadd(i, m, n, ad) for (int i = m, _lim = n; i < _lim; i += ad)
#define rep(...) _overloadrep(__VA_ARGS__, repadd, repi, _rep, )(__VA_ARGS__)
#define _rer(i, n) for (int i = n; i >= 0; i--)
#define reri(i, m, n) for (int i = m, _lim = n; i >= _lim; i--)
#define rerdec(i, m, n, dec) for (int i = m, _lim = n; i >= _lim; i -= dec)
#define rer(...) _overloadrep(__VA_ARGS__, rerdec, reri, _rer, )(__VA_ARGS__)
#define fora(a, b) for (auto &&a : b)
#define forg(gi, ve) \
for (int gi = 0, f, t, c; gi < ve.size() && (f = ve[gi].from, t = ve[gi].to, \
c = ve[gi].cost, true); \
gi++)
#define fort(gi, ve) \
for (int gi = 0, f, t, c; \
gi < ve.size() && (gi += (ve[gi].to == p)) < ve.size() && \
(f = ve[gi].from, t = ve[gi].to, c = ve[gi].cost, true); \
gi++)
//マクロ 定数
#define k3 1010
#define k4 10101
#define k5 101010
#define k6 1010101
#define k7 10101010
const int inf = (int)1e9 + 100;
const ll linf = (ll)1e18 + 100;
const double eps = 1e-9;
const double PI = 3.1415926535897932384626433832795029L;
ll ma = numeric_limits<ll>::min();
ll mi = numeric_limits<ll>::max();
const int y4[] = {-1, 1, 0, 0};
const int x4[] = {0, 0, -1, 1};
const int y8[] = {0, 1, 0, -1, -1, 1, 1, -1};
const int x8[] = {1, 0, -1, 0, 1, -1, 1, -1};
//マクロ省略形 関数等
#define arsz(a) (sizeof(a) / sizeof(a[0]))
#define sz(a) ((int)(a).size())
#define rs resize
#define mp make_pair
#define pb push_back
#define pf push_front
#define eb emplace_back
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
//@拡張系 こう出来るべきというもの
//埋め込み 存在を意識せずに機能を増やされているもの
namespace std {
template <> class hash<std::pair<signed, signed>> {
public:
size_t operator()(const std::pair<signed, signed> &x) const {
return hash<ll>()(((ll)x.first << 32) + x.second);
}
};
template <> class hash<std::pair<ll, ll>> {
public:
//大きいllが渡されると、<<32でオーバーフローするがとりあえず問題ないと判断
size_t operator()(const std::pair<ll, ll> &x) const {
return hash<ll>()(((ll)x.first << 32) + x.second);
}
};
} // namespace std
istream &operator>>(istream &iss, P &a) {
iss >> a.first >> a.second;
return iss;
}
template <typename T> istream &operator>>(istream &iss, vector<T> &vec) {
for (T &x : vec)
iss >> x;
return iss;
}
ostream &operator<<(ostream &os, P p) {
os << p.fi << " " << p.se << endl;
return os;
}
ostream &operator<<(ostream &os, T p) {
os << p.f << " " << p.s << " " << p.t;
return os;
}
ostream &operator<<(ostream &os, F p) {
os << p.a << " " << p.b << " " << p.c << " " << p.d;
return os;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
for (int i = 0; i < vec.size(); i++)
os << vec[i] << (i + 1 == vec.size() ? "" : " ");
return os;
}
template <typename T> ostream &operator<<(ostream &os, vector<vector<T>> &vec) {
for (int i = 0; i < vec.size(); i++) {
for (int j = 0; j < vec[0].size(); j++) {
os << vec[i][j];
}
os << endl;
}
return os;
}
template <typename V, typename H> void resize(vector<V> &vec, const H head) {
vec.resize(head);
}
template <typename V, typename H, typename... T>
void resize(vector<V> &vec, const H &head, const T... tail) {
vec.resize(head);
for (auto &v : vec)
resize(v, tail...);
}
template <typename T, typename _Pr>
bool all_of(const vector<T> &vec, _Pr pred) {
return std::all_of(vec.begin(), vec.end(), pred);
}
template <typename T, typename _Pr>
bool any_of(const vector<T> &vec, _Pr pred) {
return std::any_of(vec.begin(), vec.end(), pred);
}
template <typename T, typename _Pr>
bool none_of(const vector<T> &vec, _Pr pred) {
return std::none_of(vec.begin(), vec.end(), pred);
}
template <typename T, typename _Pr>
const typename vector<T>::const_iterator find_if(const vector<T> &vec,
_Pr pred) {
return std::find_if(vec.begin(), vec.end(), pred);
}
template <typename T> bool contains(const vector<T> &vec, const T &val) {
return std::find(vec.begin(), vec.end(), val) != vec.end();
}
template <typename T, typename _Pr>
bool contains_if(const vector<T> &vec, _Pr pred) {
return std::find_if(vec.begin(), vec.end(), pred) != vec.end();
}
template <class T> void replace(vector<T> &a, T key, T v) {
replace(a.begin(), a.end(), key, v);
}
template <class T> bool includes(vector<T> &a, vector<T> &b) {
vi c = a;
vi d = b;
sort(all(c));
sort(all(d));
return includes(all(c), all(d));
}
template <class T> bool is_permutation(vector<T> &a, vector<T> &b) {
return is_permutation(all(a), all(b));
}
template <class T> bool next_permutation(vector<T> &a) {
return next_permutation(all(a));
}
template <class T> T pop(set<T> &set) {
T res = *set.begin();
set.erase(set.find(res));
return res;
}
template <class T> T pop(mset<T> &set) {
T res = *set.begin();
set.erase(set.find(res));
return res;
}
template <class T> T popBack(set<T> &set) {
T res = *set.rbegin();
set.erase(set.find(res));
return res;
}
template <class T> T popBack(mset<T> &set) {
T res = *set.rbegin();
set.erase(set.find(res));
return res;
}
inline void sort(string &a) { sort(a.begin(), a.end()); }
template <class T> inline void sort(vector<T> &a) { sort(a.begin(), a.end()); };
template <class T> inline void sort(vector<T> &a, int len) {
sort(a.begin(), a.begin() + len);
};
template <class T, class F> inline void sort(vector<T> &a, F f) {
sort(a.begin(), a.end(), [&](T l, T r) { return f(l) < f(r); });
};
enum ___pcomparator { fisi, fisd, fdsi, fdsd, sifi, sifd, sdfi, sdfd };
inline void sort(vector<P> &a, ___pcomparator type) {
switch (type) {
case fisi:
sort(all(a),
[&](P l, P r) { return l.fi != r.fi ? l.fi < r.fi : l.se < r.se; });
break;
case fisd:
sort(all(a),
[&](P l, P r) { return l.fi != r.fi ? l.fi < r.fi : l.se > r.se; });
break;
case fdsi:
sort(all(a),
[&](P l, P r) { return l.fi != r.fi ? l.fi > r.fi : l.se < r.se; });
break;
case fdsd:
sort(all(a),
[&](P l, P r) { return l.fi != r.fi ? l.fi > r.fi : l.se > r.se; });
break;
case sifi:
sort(all(a),
[&](P l, P r) { return l.se != r.se ? l.se < r.se : l.fi < r.fi; });
break;
case sifd:
sort(all(a),
[&](P l, P r) { return l.se != r.se ? l.se < r.se : l.fi > r.fi; });
break;
case sdfi:
sort(all(a),
[&](P l, P r) { return l.se != r.se ? l.se > r.se : l.fi < r.fi; });
break;
case sdfd:
sort(all(a),
[&](P l, P r) { return l.se != r.se ? l.se > r.se : l.fi > r.fi; });
break;
}
};
template <class T> inline void rsort(vector<T> &a) {
sort(a.begin(), a.end(), greater<T>());
};
template <class T> inline void rsort(vector<T> &a, int len) {
sort(a.begin(), a.begin() + len, greater<T>());
};
template <class U, class F> inline void rsort(vector<U> &a, F f) {
sort(a.begin(), a.end(), [&](U l, U r) { return f(l) > f(r); });
};
template <class U> inline void sortp(vector<U> &a, vector<U> &b) {
vp c;
int n = sz(a);
assert(n == sz(b));
rep(i, n) c.eb(a[i], b[i]);
sort(c);
rep(i, n) {
a[i] = c[i].first;
b[i] = c[i].second;
;
}
};
// F = T<T>
//例えばreturn p.fi + p.se;
template <class U, class F> inline void sortp(vector<U> &a, vector<U> &b, F f) {
vp c;
int n = sz(a);
assert(n == sz(b));
rep(i, n) c.eb(a[i], b[i]);
sort(c, f);
rep(i, n) {
a[i] = c[i].first;
b[i] = c[i].second;
}
};
template <class U, class F>
inline void sortp(vector<U> &a, vector<U> &b, char type) {
vp c;
int n = sz(a);
assert(n == sz(b));
rep(i, n) c.eb(a[i], b[i]);
sort(c, type);
rep(i, n) {
a[i] = c[i].first;
b[i] = c[i].second;
}
};
template <class U> inline void rsortp(vector<U> &a, vector<U> &b) {
vp c;
int n = sz(a);
assert(n == sz(b));
rep(i, n) c.eb(a[i], b[i]);
rsort(c);
rep(i, n) {
a[i] = c[i].first;
b[i] = c[i].second;
}
};
template <class U, class F>
inline void rsortp(vector<U> &a, vector<U> &b, F f) {
vp c;
int n = sz(a);
assert(n == sz(b));
rep(i, n) c.eb(a[i], b[i]);
rsort(c, f);
rep(i, n) {
a[i] = c[i].first;
b[i] = c[i].second;
}
};
template <class U> inline void sortt(vector<U> &a, vector<U> &b, vector<U> &c) {
vt r;
int n = sz(a);
assert(n == sz(b));
assert(n == sz(c));
rep(i, n) r.eb(a[i], b[i], c[i]);
sort(r);
rep(i, n) {
a[i] = r[i].f;
b[i] = r[i].s;
c[i] = r[i].t;
}
};
template <class U, class F>
inline void sortt(vector<U> &a, vector<U> &b, vector<U> &c, F f) {
vt r;
int n = sz(a);
assert(n == sz(b));
assert(n == sz(c));
rep(i, n) r.eb(a[i], b[i], c[i]);
sort(r, f);
rep(i, n) {
a[i] = r[i].f;
b[i] = r[i].s;
c[i] = r[i].t;
}
};
template <class U, class F>
inline void rsortt(vector<U> &a, vector<U> &b, vector<U> &c, F f) {
vt r;
int n = sz(a);
assert(n == sz(b));
assert(n == sz(c));
rep(i, n) r.eb(a[i], b[i], c[i]);
rsort(r, f);
rep(i, n) {
a[i] = r[i].f;
b[i] = r[i].s;
c[i] = r[i].t;
}
};
template <class T> inline void sort2(vector<vector<T>> &a) {
for (int i = 0, n = a.size(); i < n; i++)
sort(a[i]);
}
template <class T> inline void rsort2(vector<vector<T>> &a) {
for (int i = 0, n = a.size(); i < n; i++)
rsort(a[i]);
}
template <typename A, size_t N, typename T> void fill(A (&a)[N], const T &v) {
rep(i, N) a[i] = v;
}
template <typename A, size_t N, size_t O, typename T>
void fill(A (&a)[N][O], const T &v) {
rep(i, N) rep(j, O) a[i][j] = v;
}
template <typename A, size_t N, size_t O, size_t P, typename T>
void fill(A (&a)[N][O][P], const T &v) {
rep(i, N) rep(j, O) rep(k, P) a[i][j][k] = v;
}
template <typename A, size_t N, size_t O, size_t P, size_t Q, typename T>
void fill(A (&a)[N][O][P][Q], const T &v) {
rep(i, N) rep(j, O) rep(k, P) rep(l, Q) a[i][j][k][l] = v;
}
template <typename A, size_t N, size_t O, size_t P, size_t Q, size_t R,
typename T>
void fill(A (&a)[N][O][P][Q][R], const T &v) {
rep(i, N) rep(j, O) rep(k, P) rep(l, Q) rep(m, R) a[i][j][k][l][m] = v;
}
template <typename A, size_t N, size_t O, size_t P, size_t Q, size_t R,
size_t S, typename T>
void fill(A (&a)[N][O][P][Q][R][S], const T &v) {
rep(i, N) rep(j, O) rep(k, P) rep(l, Q) rep(m, R) rep(n, S)
a[i][j][k][l][m][n] = v;
}
template <typename V, typename T> void fill(V &xx, const T vall) { xx = vall; }
template <typename V, typename T> void fill(vector<V> &vecc, const T vall) {
for (auto &&vx : vecc)
fill(vx, vall);
}
//@汎用便利関数 入力
template <typename T = int> T _in() {
T x;
cin >> x;
return (x);
}
#define _overloadin(_1, _2, _3, _4, name, ...) name
#define in0() _in()
#define in1(a) cin >> a
#define in2(a, b) cin >> a >> b
#define in3(a, b, c) cin >> a >> b >> c
#define in4(a, b, c, d) cin >> a >> b >> c >> d
#define in(...) _overloadin(__VA_ARGS__, in4, in3, in2, in1, in0)(__VA_ARGS__)
string sin() { return _in<string>(); }
double din() { return _in<double>(); }
ll lin() { return _in<ll>(); }
#define na(a, n) \
a.resize(n); \
rep(i, n) cin >> a[i];
#define nao(a, n) \
a.resize(n + 1); \
rep(i, n) cin >> a[i + 1];
#define nad(a, n) \
a.resize(n); \
rep(i, n) cin >> a[i], a[i]--;
#define na2(a, b, n) \
a.resize(n), b.resize(n); \
rep(i, n) cin >> a[i] >> b[i];
#define na2d(a, b, n) \
a.resize(n), b.resize(n); \
rep(i, n) cin >> a[i] >> b[i], a[i]--, b[i]--;
#define na3(a, b, c, n) \
a.resize(n), b.resize(n), c.resize(n); \
rep(i, n) cin >> a[i] >> b[i] >> c[i];
#define na3d(a, b, c, n) \
a.resize(n), b.resize(n), c.resize(n); \
rep(i, n) cin >> a[i] >> b[i] >> c[i], a[i]--, b[i]--, c[i]--;
#define nt(a, h, w) \
resize(a, h, w); \
rep(hi, h) rep(wi, w) cin >> a[hi][wi];
#define ntd(a, h, w) \
rs(a, h, w); \
rep(hi, h) rep(wi, w) cin >> a[hi][wi], a[hi][wi]--;
#define ntp(a, h, w) \
fill(a, '#'); \
rep(hi, 1, h + 1) rep(wi, 1, w + 1) cin >> a[hi][wi];
//汎用便利関数 出力
template <class T> void out(T x) {
typeid(x) == typeid(double) ? cout << fixed << setprecision(10) << x << endl
: cout << x << endl;
}
template <class T> void out(vector<T> a) { fora(v, a) cout << v << endl; }
//デバッグ
#define sp << " " <<
#define debugName(VariableName) #VariableName
#define _deb1(x) cerr << debugName(x) << " = " << x << endl
#define _deb2(x, y) \
cerr << debugName(x) << " = " << x << ", " << debugName(y) << " = " << y \
<< endl
#define _deb3(x, y, z) \
cerr << debugName(x) << " = " << x << ", " << debugName(y) << " = " << y \
<< ", " debugName(z) << " = " << z << endl
#define _deb4(x, y, z, a) \
cerr << debugName(x) << " = " << x << ", " << debugName(y) << " = " << y \
<< ", " << debugName(z) << " = " << z << ", " << debugName(a) << " = " \
<< a << endl
#define _deb5(x, y, z, a, b) \
cerr << debugName(x) << " = " << x << ", " << debugName(y) << " = " << y \
<< ", " << debugName(z) << " = " << z << ", " << debugName(a) << " = " \
<< a << ", " << debugName(b) << " = " << b << endl
#define _overloadebug(_1, _2, _3, _4, _5, name, ...) name
#define debug(...) \
_overloadebug(__VA_ARGS__, _deb5, _deb4, _deb3, _deb2, _deb1)(__VA_ARGS__)
#define deb(...) \
_overloadebug(__VA_ARGS__, _deb5, _deb4, _deb3, _deb2, _deb1)(__VA_ARGS__)
#define debugline(x) \
cerr << x << " " \
<< "(L:" << __LINE__ << ")" << '\n'
//よく使うクラス、構造体
class UnionFind {
public:
vi par, rank, sizes;
int n, trees;
UnionFind(int n) : n(n), trees(n) {
par.resize(n), rank.resize(n), sizes.resize(n);
rep(i, n) par[i] = i, sizes[i] = 1;
}
int root(int x) {
if (par[x] == x)
return x;
else
return par[x] = root(par[x]);
}
int find(int x) { return root(x); }
void unite(int x, int y) {
x = root(x);
y = root(y);
if (x == y)
return;
if (rank[x] < rank[y])
swap(x, y);
trees--;
par[y] = x;
sizes[x] += sizes[y];
if (rank[x] == rank[y])
rank[x]++;
}
bool same(int x, int y) { return root(x) == root(y); }
int size(int x) { return sizes[root(x)]; }
//順不同 umapなので
vec<vi> sets() {
vec<vi> res(trees);
umap<int, vi> map;
rep(i, n) map[root(i)].push_back(i);
int i = 0;
for (auto &&p : map) {
int r = p.fi;
res[i].push_back(r);
for (auto &&v : p.se) {
if (r == v)
continue;
res[i].push_back(v);
}
i++;
}
return res;
}
};
// MOD関連
ll MOD = (int)1e9 + 7;
class mint {
public:
int x;
mint() : x(0) {}
mint(signed y) : x(y >= 0 ? y % MOD : MOD - (-y) % MOD) {}
mint(int y) : x(y >= 0 ? y % MOD : MOD - (-y) % MOD) {}
static int _mpow(int v, ll a) {
ll x = v, n = a, res = 1;
while (n) {
if (n & 1)
res = (res * x) % MOD;
x = (x * x) % MOD;
n >>= 1;
}
return res;
}
// Arithmetic Oprators
mint &operator+=(mint that) {
if ((x += that.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator-=(mint that) {
if ((x += MOD - that.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator*=(mint that) {
x = 1LL * x * that.x % MOD;
return *this;
}
mint &operator/=(const mint &that);
mint &operator^=(const mint &that) {
this->x = _mpow(x, that.x);
return *this;
}
mint &operator%=(mint that) {
x %= that.x;
return *this;
}
mint &operator+=(const int that) { return *this += mint(that); }
mint &operator-=(const int that) { return *this -= mint(that); }
mint &operator*=(const int that) { return *this *= mint(that); }
mint &operator/=(const int that);
mint &operator^=(const int that) {
this->x = _mpow(x, that);
return *this;
}
mint &operator%=(const int that) { return *this %= mint(that); }
mint &operator+=(const signed that) { return *this += mint(that); }
mint &operator-=(const signed that) { return *this -= mint(that); }
mint &operator*=(const signed that) { return *this *= mint(that); }
mint &operator/=(const signed that);
mint &operator^=(const signed that) {
this->x = _mpow(x, that);
return *this;
}
mint &operator%=(const signed that) { return *this %= mint(that); }
// Comparators
bool operator<(mint that) { return x < that.x; }
bool operator>(mint that) { return x > that.x; }
bool operator<=(mint that) { return x <= that.x; }
bool operator>=(mint that) { return x >= that.x; }
bool operator!=(mint that) { return x != that.x; }
bool operator==(mint that) { return x == that.x; }
bool operator!=(int that) { return x != that; }
bool operator==(int that) { return x == that; }
bool operator!=(signed that) { return x != that; }
bool operator==(signed that) { return x == that; }
// Utilities
unsigned getval() const { return x; }
operator int() { return x; }
mint operator+(mint that) const { return mint(*this) += that; }
mint operator-(mint that) const { return mint(*this) -= that; }
mint operator*(mint that) const { return mint(*this) *= that; }
mint operator%(mint that) const { return mint(*this) %= that; }
mint operator+(const int that) const { return mint(*this) += that; }
mint operator-(const int that) const { return mint(*this) -= that; }
mint operator*(const int that) const { return mint(*this) *= that; }
mint operator%(const int that) const { return mint(*this) %= that; }
mint operator=(const int that) { return *this = mint(that); }
mint operator+(const signed that) const { return mint(*this) += that; }
mint operator-(const signed that) const { return mint(*this) -= that; }
mint operator*(const signed that) const { return mint(*this) *= that; }
mint operator%(const signed that) const { return mint(*this) %= that; }
mint operator=(const signed that) { return *this = mint(that); }
mint operator++() {
x++;
return *this;
}
mint operator++(signed) {
auto ret = *this;
x++;
return ret;
}
friend void operator+=(ll &a, const mint &b) { a = mint(a % MOD + b.x); }
friend void operator-=(ll &a, const mint &b) { a = mint(a % MOD - b.x); }
friend void operator*=(ll &a, const mint &b) { a = mint(a % MOD * b.x); }
friend void operator/=(ll &a, const mint &b);
friend mint operator+(const ll a, const mint &b) {
return mint(a % MOD + b.x);
}
friend mint operator-(const ll a, const mint &b) {
return mint(a % MOD - b.x);
}
friend mint operator*(const ll a, const mint &b) {
return mint(a % MOD * b.x);
}
friend mint operator^(const ll a, const mint &b) { return _mpow(a, b.x); }
};
mint itom(int v) {
mint res;
res.x = v;
return res;
}
const int setModMax = 510000;
vector<mint> fac, finv, inv;
void setMod(int m = MOD) {
fac.resize(setModMax);
finv.resize(setModMax);
inv.resize(setModMax);
MOD = m;
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < setModMax; i++) {
fac[i] = fac[i - 1].x * i % MOD;
inv[i] = MOD - inv[MOD % i].x * (MOD / i) % MOD;
finv[i] = finv[i - 1].x * inv[i].x % MOD;
}
}
mint mpow(int v, ll a) { return mint::_mpow(v, a); }
mint com(ll n, ll r) {
if (n < r || n < 0 || r < 0)
return 0;
if (fac.size() == 0)
setMod();
return fac[n] * finv[r] * finv[n - r];
}
mint ncr(ll n, ll r) { return com(n, r); }
// n人にr個を配るとき、同じ人に何個配っても良い場合
mint nhr(ll n, ll r) { return com(n + r - 1, r); }
//拡張ユークリッドの互除法
mint minv(ll a) {
if (fac[0] == 0)
setMod();
if (a < setModMax)
return inv[a];
a %= MOD;
ll b = MOD, x = 1, y = 0;
while (b) {
ll t = a / b;
a -= t * b;
swap(a, b);
x -= t * y;
swap(x, y);
}
return x;
}
mint &mint::operator/=(const mint &that) { return *this *= minv(that.x); }
mint &mint::operator/=(const ll a) { return *this *= minv(a); }
mint &mint::operator/=(const signed a) { return *this *= minv(a); }
void operator/=(ll &a, const mint &b) { a = (a * minv(b.x)).x; }
using PM = pair<mint, mint>;
using vm = vector<mint>;
#define _overloadvvm(_1, _2, _3, _4, name, ...) name
#define vvm1(a) vec<vm> a
#define vvm2(a, b) vec<vm> a(b)
#define vvm3(a, b, c) vec<vm> a(b, vm(c))
#define vvm4(a, b, c, d) vec<vm> a(b, vm(c, d))
#define vvm(...) _overloadvvm(__VA_ARGS__, vvm4, vvm3, vvm2, vvm1)(__VA_ARGS__)
vb isPrime;
vi primes;
void setPrime() {
isPrime.resize(4010101);
fill(isPrime, true);
int len = sizeof(isPrime) / sizeof(isPrime[0]);
isPrime[0] = isPrime[1] = false;
for (int i = 2; i <= sqrt(len) + 5; ++i) {
if (!isPrime[i])
continue;
for (int j = 2; i * j < len; ++j) {
isPrime[i * j] = false;
}
}
rep(i, len) if (isPrime[i]) primes.pb(i);
}
//幾何 Pをcomplexとして扱う
bool eq(double a, double b) { return fabs(a - b) < eps; }
using C = complex<double>;
C rot(C &a, dou th) { return a * C(cos(th), sin(th)); }
dou inpro(C &a, C &b) { return real(a * conj(b)); }
// 90度回転させて内積が0なら平行
bool line(C a, C b, C c) {
C ab = b - a;
C ac = c - a;
//複素数の掛け算は回転
ab *= C(0, 1);
return eq(inpro(ab, ac), 0);
}
bool line(P a, P b, P c) {
return line(C(a.fi, a.se), C(b.fi, b.se), C(c.fi, c.se));
}
bool line(int xa, int ya, int xb, int yb, int xc, int yc) {
C a = C(xa, ya);
C b = C(xb, yb);
C c = C(xc, yc);
return line(a, b, c);
}
//便利関数
//テスト用
char ranc() { return (char)('a' + rand() % 26); }
int rand(int min, int max) {
assert(min <= max);
if (min >= 0 && max >= 0) {
return rand() % (max + 1 - min) + min;
} else if (max < 0) {
return -rand(-max, -min);
} else {
//+
if (rand() % 2) {
return rand(0, max);
//-
} else {
return -rand(0, -min);
}
}
}
vi ranv(int n, int min, int max) {
vi v(n);
rep(i, n) v[i] = rand(min, max);
return v;
}
//単調増加
vi ranvi(int n, int min, int max) {
vi v(n);
bool bad = 1;
while (bad) {
bad = 0;
v.resize(n);
rep(i, n) {
if (i && min > max - v[i - 1]) {
bad = 1;
break;
}
if (i)
v[i] = v[i - 1] + rand(min, max - v[i - 1]);
else
v[i] = rand(min, max);
}
}
return v;
}
void ranvlr(int n, int min, int max, vi &l, vi &r) {
l.resize(n);
r.resize(n);
rep(i, n) {
l[i] = rand(min, max);
r[i] = l[i] + rand(0, max - l[i]);
}
}
//便利 汎用
template <typename V, typename T> int find(vector<V> &a, const T key) {
rep(i, sz(a)) if (a[i] == key) return i;
return -1;
}
template <typename V, typename T> P find(vector<vector<V>> &a, const T key) {
rep(i, sz(a)) rep(j, sz(a[0])) if (a[i][j] == key) return mp(i, j);
return mp(-1, -1);
}
template <typename V, typename U>
T find(vector<vector<vector<V>>> &a, const U key) {
rep(i, sz(a)) rep(j, sz(a[0]))
rep(k, sz(a[0][0])) if (a[i][j][k] == key) return mt(i, j, k);
return mt(-1, -1, -1);
}
template <typename V, typename T> int count(V &a, const T k) { return a == k; }
template <typename V, typename T> int count(vector<V> &a, const T k) {
int ret = 0;
fora(v, a) ret += count(v, k);
return ret;
}
template <typename V> int count_odd(V &a) { return a % 2; }
template <typename V> int count_odd(vector<V> &a) {
int ret = 0;
fora(v, a) ret += count_odd(v);
return ret;
}
template <typename V> int count_even(V &a) { return a % 2 == 0; }
template <typename V> int count_even(vector<V> &a) {
int ret = 0;
fora(v, a) ret += count_even(v);
return ret;
}
// algorythm
void iota(vector<int> &ve, int s, int n) {
ve.resize(n);
iota(all(ve), s);
}
vi iota(int s, int n) {
vi ve(n);
iota(all(ve), s);
return ve;
}
//便利 数学
int mod(int a, int m) { return (a % m + m) % m; }
int pow(int a) { return a * a; };
ll fact(int v) { return v <= 1 ? 1 : v * fact(v - 1); }
ll comi(int n, int r) {
assert(n < 100);
static vvi(pas, 100, 100);
if (pas[0][0])
return pas[n][r];
pas[0][0] = 1;
rep(i, 1, 100) {
pas[i][0] = 1;
rep(j, 1, i + 1) pas[i][j] = pas[i - 1][j - 1] + pas[i - 1][j];
}
return pas[n][r];
}
void ole() {
#ifdef _DEBUG
debugline("ole");
exit(0);
#endif
string a = "a";
rep(i, 30) a += a;
rep(i, 1 << 17) cout << a << endl;
cout << "OLE 出力長制限超過" << endl;
exit(0);
}
void tle() {
while (inf)
cout << inf << endl;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll gcd(vi b) {
ll res = b[0];
for (auto &&v : b)
res = gcd(v, res);
return res;
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll rev(ll a) {
ll res = 0;
while (a) {
res *= 10;
res += a % 10;
a /= 10;
}
return res;
}
template <class T> vector<T> rev(vector<T> &a) {
vector<T> ret = a;
reverse(all(ret));
return ret;
}
ll ceil(ll a, ll b) {
if (b == 0) {
debugline("ceil");
deb(a, b);
ole();
return -1;
} else
return (a + b - 1) / b;
}
ll sqrt(ll a) {
if (a < 0) {
debugline("sqrt");
deb(a);
ole();
}
ll res = (ll)std::sqrt(a);
while (res * res < a)
res++;
return res;
}
double log(double e, double x) { return log(x) / log(e); }
ll sig(ll t) { return (1 + t) * t / 2; }
ll sig(ll s, ll t) { return (s + t) * (t - s + 1) / 2; }
vi divisors(int v) {
vi res;
for (int i = 1; i <= sqrt(v); ++i) {
if (v % i == 0) {
res.pb(i);
if (i != v / i)
res.pb(v / i);
}
}
return res;
}
vi factorization(int v) {
int tv = v;
vi res;
if (isPrime.size() == 0)
setPrime();
for (auto &&p : primes) {
if (v % p == 0)
res.push_back(p);
while (v % p == 0) {
v /= p;
}
if (v == 1 || p * p > tv)
break;
}
if (v > 1)
res.pb(v);
return res;
}
unordered_map<int, int> factorizationMap(int v) {
int tv = v;
unordered_map<int, int> res;
if (isPrime.size() == 0)
setPrime();
for (auto &&p : primes) {
while (v % p == 0) {
res[p]++;
v /= p;
}
if (v == 1 || p * p > tv)
break;
}
if (v > 1)
res[v]++;
return res;
}
int get(int a, int keta) { return (a / (int)pow(10, keta)) % 10; }
int keta(int v) {
int cou = 0;
while (v) {
cou++, v %= 10;
}
return cou;
}
int dsum(int v) {
int ret = 0;
for (; v; v /= 10)
ret += v % 10;
return ret;
}
int sumd(int v) { return dsum(v); }
//変換系
template <class T, class U> vector<T> keys(vector<pair<T, U>> a) {
vector<T> res;
for (auto &&k : a)
res.pb(k.fi);
return res;
}
template <class T, class U> vector<U> keys(map<T, U> a) {
vector<U> res;
for (auto &&k : a)
res.pb(k.fi);
return res;
}
template <class T, class U> vector<U> keys(umap<T, U> a) {
vector<U> res;
for (auto &&k : a)
res.pb(k.fi);
return res;
}
template <class T, class U> vector<U> values(vector<pair<T, U>> a) {
vector<U> res;
for (auto &&k : a)
res.pb(k.se);
return res;
}
template <class T, class U> vector<T> values(map<T, U> a) {
vector<T> res;
for (auto &&k : a)
res.pb(k.se);
return res;
}
template <class T, class U> vector<T> values(umap<T, U> a) {
vector<T> res;
for (auto &&k : a)
res.pb(k.se);
return res;
}
vi list(int a) {
vi res;
while (a) {
res.insert(res.begin(), a % 10);
a /= 10;
}
return res;
}
template <class T, class U> bool chmax(T &a, const U &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class U> bool chmax(const U &b) { return chmax(ma, b); }
template <class T, class U> bool chmin(T &a, const U &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template <class U> bool chmin(const U &b) { return chmin(mi, b); }
#define chmi chmin
#define chma chmax
template <class T> T min(T a, signed b) { return a < b ? a : b; }
template <class T> T max(T a, signed b) { return a < b ? b : a; }
template <class T> T min(T a, T b, T c) {
return a >= b ? b >= c ? c : b : a >= c ? c : a;
}
template <class T> T max(T a, T b, T c) {
return a <= b ? b <= c ? c : b : a <= c ? c : a;
}
template <class T> T min(vector<T> a) { return *min_element(all(a)); }
template <class T> T min(vector<T> a, int n) {
return *min_element(a.begin(), a.begin() + min(n, sz(a)));
}
template <class T> T min(vector<T> a, int s, int n) {
return *min_element(a.begin() + s, a.begin() + min(n, sz(a)));
}
template <class T> T max(vector<T> a) { return *max_element(all(a)); }
template <class T> T max(vector<T> a, int n) {
return *max_element(a.begin(), a.begin() + min(n, sz(a)));
}
template <class T> T max(vector<T> a, int s, int n) {
return *max_element(a.begin() + s, a.begin() + min(n, sz(a)));
}
template <typename A, size_t N> A max(A (&a)[N]) {
A res = a[0];
rep(i, N) res = max(res, a[i]);
return res;
}
template <typename A, size_t N, size_t O> A max(A (&a)[N][O]) {
A res = max(a[0]);
rep(i, N) res = max(res, max(a[i]));
return res;
}
template <typename A, size_t N, size_t O, size_t P> A max(A (&a)[N][O][P]) {
A res = max(a[0]);
rep(i, N) res = max(res, max(a[i]));
return res;
}
template <typename A, size_t N, size_t O, size_t P, size_t Q>
A max(A (&a)[N][O][P][Q], const T &v) {
A res = max(a[0]);
rep(i, N) res = max(res, max(a[i]));
return res;
}
template <typename A, size_t N, size_t O, size_t P, size_t Q, size_t R>
A max(A (&a)[N][O][P][Q][R]) {
A res = max(a[0]);
rep(i, N) res = max(res, max(a[i]));
return res;
}
template <typename A, size_t N, size_t O, size_t P, size_t Q, size_t R,
size_t S>
A max(A (&a)[N][O][P][Q][R][S]) {
A res = max(a[0]);
rep(i, N) res = max(res, max(a[i]));
return res;
}
template <typename A, size_t N> A min(A (&a)[N]) {
A res = a[0];
rep(i, N) res = min(res, a[i]);
return res;
}
template <typename A, size_t N, size_t O> A min(A (&a)[N][O]) {
A res = min(a[0]);
rep(i, N) res = min(res, max(a[i]));
return res;
}
template <typename A, size_t N, size_t O, size_t P> A min(A (&a)[N][O][P]) {
A res = min(a[0]);
rep(i, N) res = min(res, min(a[i]));
return res;
}
template <typename A, size_t N, size_t O, size_t P, size_t Q>
A min(A (&a)[N][O][P][Q], const T &v) {
A res = min(a[0]);
rep(i, N) res = min(res, min(a[i]));
return res;
}
template <typename A, size_t N, size_t O, size_t P, size_t Q, size_t R>
A min(A (&a)[N][O][P][Q][R]) {
A res = min(a[0]);
rep(i, N) res = min(res, min(a[i]));
return res;
}
template <typename A, size_t N, size_t O, size_t P, size_t Q, size_t R,
size_t S>
A min(A (&a)[N][O][P][Q][R][S]) {
A res = min(a[0]);
rep(i, N) res = min(res, min(a[i]));
return res;
}
template <class T> T sum(vector<T> v, int len = -1) {
if (len == -1)
len = v.size();
T res = 0;
chmin(len, v.size());
rep(i, len) res += v[i];
return res;
}
template <class T> T sum(vector<vector<T>> &v, int h = -1, int w = -1) {
if (h == -1)
h = v.size();
if (w == -1)
w = v[0].size();
T res = 0;
chmin(h, v.size());
chmin(w, v[0].size());
rep(i, h) rep(j, w) res += v[i][j];
return res;
}
P sump(vp &v, int len = -1) {
if (len == -1)
len = v.size();
P res = {0, 0};
chmin(len, v.size());
rep(i, len) {
res.fi += v[i].fi;
res.se += v[i].se;
}
return res;
}
///要素が0の時、返り値は0か1か
template <class T> T mul(vector<T> &v, int len = -1) {
if (len == -1)
len = v.size();
T res = 1;
chmin(len, v.size());
rep(i, len) res *= v[i];
return res;
}
void clear(PQ &q) {
while (q.size())
q.pop();
}
template <class T> void clear(queue<T> &q) {
while (q.size())
q.pop();
}
template <class T> T *negarr(int size) {
T *body = (T *)malloc((size * 2 + 1) * sizeof(T));
return body + size;
}
template <class T> T *negarr2(int h, int w) {
double **dummy1 = new double *[2 * h + 1];
double *dummy2 = new double[(2 * h + 1) * (2 * w + 1)];
dummy1[0] = dummy2 + w;
for (int i = 1; i <= 2 * h + 1; i++) {
dummy1[i] = dummy1[i - 1] + 2 * w + 1;
}
double **a = dummy1 + h;
}
// imoは0-indexed
// ruiは1-indexed
template <class T> vector<T> imo(vector<T> &v) {
vector<T> ret = v;
rep(i, sz(ret) - 1) ret[i + 1] += ret[i];
return ret;
}
template <class T> vector<T> imomi(vector<T> &v) {
vector<T> ret = v;
rep(i, sz(ret) - 1) chmin(ret[i + 1], ret[i]);
return ret;
}
template <class T> struct ruic {
const vector<T> rui;
ruic(vector<T> &ru) : rui(ru) {}
T operator()(int l, int r) {
assert(l <= r);
return rui[r] - rui[l];
}
T operator[](int i) { return rui[i]; }
};
template <class T> struct rruic {
const T *rrui;
rruic(T *ru) : rrui(ru) {}
// n-1から-1へ
T operator()(int l, int r) {
assert(l >= r);
return rrui[r] - rrui[l];
}
T operator[](int i) { return rrui[i]; }
};
// template<class T> vector<T> ruiv(vector<T> &a)
template <class T> ruic<T> ruiv(vector<T> &a) {
vector<T> res(a.size() + 1);
rep(i, a.size()) res[i + 1] = res[i] + a[i];
return ruic<T>(res);
}
template <class T> vector<T> ruim(vector<T> &a) {
vector<T> res(a.size() + 1, 1);
rep(i, a.size()) res[i + 1] = res[i] * a[i];
return res;
}
// template<class T> T *rrui(vector<T> &a) {
//右から左にかけての半開区間 (-1 n-1]
template <class T> rruic<T> rrui(vector<T> &a) {
int len = a.size();
T *body = (T *)malloc((len + 1) * sizeof(T));
T *res = body + 1;
rer(i, len - 1) res[i - 1] = res[i] + a[i];
return rruic<T>(res);
}
//掛け算
template <class T> T *rruim(vector<T> &a) {
int len = a.size();
T *body = (T *)malloc((len + 1) * sizeof(T));
T *res = body + 1;
res[len - 1] = 1;
rer(i, len - 1) res[i - 1] = res[i] * a[i];
return res;
}
template <class T, class U> void inc(T &a, U v = 1) { a += v; }
template <class T, class U> void inc(vector<T> &a, U v = 1) {
for (auto &u : a)
inc(u, v);
}
template <class T> void inc(vector<T> &a) {
for (auto &u : a)
inc(u, 1);
}
template <class T, class U> void dec(T &a, U v = 1) { a -= v; }
template <class T, class U> void dec(vector<T> &a, U v = 1) {
for (auto &u : a)
dec(u, v);
}
template <class T> void dec(vector<T> &a) {
for (auto &u : a)
dec(u, 1);
}
inline bool inside(int h, int w, int H, int W) {
return h >= 0 && w >= 0 && h < H && w < W;
}
ll u(ll a) { return a < 0 ? 0 : a; }
template <class T> vector<T> u(const vector<T> &a) {
vector<T> ret = a;
fora(v, ret) v = u(v);
return ret;
}
#define MIN(a) numeric_limits<a>::min()
#define MAX(a) numeric_limits<a>::max()
ll goldd(ll left, ll right, function<ll(ll)> calc) {
double GRATIO = 1.6180339887498948482045868343656;
ll lm = left + (ll)((right - left) / (GRATIO + 1.0));
ll rm = lm + (ll)((right - lm) / (GRATIO + 1.0));
ll fl = calc(lm);
ll fr = calc(rm);
while (right - left > 10) {
if (fl < fr) {
right = rm;
rm = lm;
fr = fl;
lm = left + (ll)((right - left) / (GRATIO + 1.0));
fl = calc(lm);
} else {
left = lm;
lm = rm;
fl = fr;
rm = lm + (ll)((right - lm) / (GRATIO + 1.0));
fr = calc(rm);
}
}
ll minScore = MAX(ll);
ll resIndex = left;
for (ll i = left; i < right + 1; i++) {
ll score = calc(i);
if (minScore > score) {
minScore = score;
resIndex = i;
}
}
return resIndex;
}
ll goldt(ll left, ll right, function<ll(ll)> calc) {
double GRATIO = 1.6180339887498948482045868343656;
ll lm = left + (ll)((right - left) / (GRATIO + 1.0));
ll rm = lm + (ll)((right - lm) / (GRATIO + 1.0));
ll fl = calc(lm);
ll fr = calc(rm);
while (right - left > 10) {
if (fl > fr) {
right = rm;
rm = lm;
fr = fl;
lm = left + (ll)((right - left) / (GRATIO + 1.0));
fl = calc(lm);
} else {
left = lm;
lm = rm;
fl = fr;
rm = lm + (ll)((right - lm) / (GRATIO + 1.0));
fr = calc(rm);
}
}
if (left > right) {
ll l = left;
left = right;
right = l;
}
ll maxScore = MIN(ll);
ll resIndex = left;
for (ll i = left; i < right + 1; i++) {
ll score = calc(i);
if (maxScore < score) {
maxScore = score;
resIndex = i;
}
}
return resIndex;
}
template <class T> T min(vector<vector<T>> &a) {
T res = MAX(T);
rep(i, a.size()) chmin(res, *min_element(all(a[i])));
return res;
}
template <class T> T max(vector<vector<T>> &a) {
T res = MIN(T);
rep(i, a.size()) chmax(res, *max_element(all(a[i])));
return res;
}
bool bget(ll m, int keta) { return (m >> keta) & 1; }
int bget(ll m, int keta, int sinsuu) {
m /= (ll)pow(sinsuu, keta);
return m % sinsuu;
}
inline ll bit(int n) { return (1LL << (n)); }
inline ll bit(int n, int sinsuu) { return (ll)pow(sinsuu, n); }
// int bcou(ll m) { return __builtin_popcount(m & 0xFFFFFFFF) +
// __builtin_popcount(m >> 32); } #define bcou __builtin_popcountll
//初期化は0を渡す
ll nextComb(ll &mask, int n, int r) {
if (!mask)
return mask = (1LL << r) - 1;
ll x = mask & -mask; //最下位の1
ll y = mask + x; //連続した下の1を繰り上がらせる
ll res = ((mask & ~y) / x >> 1) | y;
if (bget(res, n))
return mask = 0;
else
return mask = res;
}
// n桁以下でビットがr個立っているもののvectorを返す
vl bitCombList(int n, int r) {
vl res;
int m = 0;
while (nextComb(m, n, r)) {
res.pb(m);
}
return res;
}
//大文字小文字を区別する
int altoiaZ(char c) {
if ('A' <= c && c <= 'Z')
return c - 'A';
return c - 'a' + 26;
}
char itoalaZ(int i) {
if (i < 26)
return 'A' + i;
return 'a' + i - 26;
}
// aもAも0を返す 基本小文字
int altoi(char c) {
if ('A' <= c && c <= 'Z')
return c - 'A';
return c - 'a';
}
char itoal(int i) { return 'a' + i; }
int ctoi(char c) { return c - '0'; }
char itoc(int i) { return i + '0'; }
int vtoi(vi &v) {
int res = 0;
if (sz(v) > 18) {
debugline("vtoi");
deb(sz(v));
ole();
}
rep(i, sz(v)) {
res *= 10;
res += v[i];
}
return res;
}
vi itov(int i) {
vi res;
while (i) {
res.pb(i % 10);
i /= 10;
}
rev(res);
return res;
}
vector<vector<int>> ctoi(vector<vector<char>> s, char c) {
int n = sz(s), m = sz(s[0]);
vector<vector<int>> res(n, vector<int>(m));
rep(i, n) rep(j, m) res[i][j] = s[i][j] == c;
return res;
}
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
void compress(vi &a) {
vi b;
int len = a.size();
for (int i = 0; i < len; ++i) {
b.push_back(a[i]);
}
sort(b);
UNIQUE(b);
for (int i = 0; i < len; ++i) {
a[i] = lower_bound(all(b), a[i]) - b.begin();
}
}
void compress(int a[], int len) {
vi b;
for (int i = 0; i < len; ++i) {
b.push_back(a[i]);
}
sort(b);
UNIQUE(b);
for (int i = 0; i < len; ++i) {
a[i] = lower_bound(all(b), a[i]) - b.begin();
}
}
//要素が見つからなかったときに困る
#define binarySearch(a, v) (binary_search(all(a), v))
#define lowerIndex(a, v) (lower_bound(all(a), v) - a.begin())
#define lowerBound(a, v) (*lower_bound(all(a), v))
#define upperIndex(a, v) (upper_bound(all(a), v) - a.begin())
#define upperBound(a, v) (*upper_bound(all(a), v))
#define ans(a) \
cout << a << endl; \
continue;
#define poll(a) \
q.front(); \
q.pop()
#define dpoll(a) \
q.front(); \
q.pop_front()
#define pollLast(a) \
q.back(); \
q.pop_back()
#define pollBack(a) \
q.back(); \
q.pop_back()
template <class T> inline void fin(T s) { cout << s << endl, exit(0); }
template <class T> struct edge {
int from, to;
T cost;
int id;
int type;
edge(int f, int t, T c = 1, int id = -1, int ty = -1)
: from(f), to(t), cost(c), id(id), type(ty) {}
bool operator<(const edge &b) const { return cost < b.cost; }
bool operator>(const edge &b) const { return cost > b.cost; }
};
template <typename T> class graph {
protected:
vector<bool> _used;
public:
vector<vector<edge<T>>> g;
vector<edge<T>> edges;
int n;
graph(int n) : n(n) { g.resize(n), _used.resize(n); }
void clear() { g.clear(), edges.clear(); }
void resize(int n) {
this->n = n;
g.resize(n);
_used.resize(n);
}
int size() { return g.size(); }
vector<edge<T>> &operator[](int i) { return g[i]; }
virtual void add(int from, int to, T cost, int id, int ty) = 0;
virtual bool used(edge<T> &e) = 0;
virtual bool used(int id) = 0;
virtual void del(edge<T> &e) = 0;
virtual void del(int id) = 0;
};
template <typename T = ll> class digraph : public graph<T> {
public:
using graph<T>::g;
using graph<T>::n;
using graph<T>::edges;
using graph<T>::_used;
digraph(int n) : graph<T>(n) {}
void add(int f, int t, T cost = 1, int id = -1, int ty = -1) {
if (!(0 <= f && f < n && 0 <= t && t < n)) {
debugline("digraph add");
deb(f, t, cost, id, ty);
ole();
}
if (id == -1)
id = edges.size();
g[f].emplace_back(f, t, cost, id, ty);
edges.emplace_back(f, t, cost, id, ty);
}
bool used(edge<T> &e) { return _used[e.id]; }
bool used(int id) { return _used[id]; }
void del(edge<T> &e) { _used[e.id] = _used[e.id ^ 1] = 1; }
void del(int id) { _used[id] = _used[id ^ 1] = 1; }
};
template <class T = int> class undigraph : public graph<T> {
public:
using graph<T>::g;
using graph<T>::n;
using graph<T>::edges;
using graph<T>::_used;
undigraph(int n) : graph<T>(n) {}
void add(int f, int t, T cost = 1, int id = -1, int ty = -1) {
if (!(0 <= f && f < n && 0 <= t && t < n)) {
debugline("undigraph add");
deb(f, t, cost, id, ty);
ole();
}
if (id == -1)
id = edges.size();
g[f].emplace_back(f, t, cost, id, ty);
g[t].emplace_back(t, f, cost, id + 1, ty);
edges.emplace_back(f, t, cost, id, ty);
edges.emplace_back(t, f, cost, id + 1, ty);
}
void add(edge<T> &e) {
int f = e.from, t = e.to, ty = e.type;
T cost = e.cost;
add(f, t, cost, ty);
}
bool used(edge<T> &e) { return _used[e.id]; }
bool used(int id) { return _used[id]; }
void del(edge<T> &e) { _used[e.id] = _used[e.id ^ 1] = 1; }
void del(int id) { _used[id] = _used[id ^ 1] = 1; }
};
template <class T>
vector<T> dijkstra(const graph<T> &g, int s, int cant_arrive = -1) {
if (!(0 <= s && s < g.n)) {
debugline("dijkstra");
deb(s, g.n);
ole();
}
T initValue = MAX(T);
vector<T> dis(g.n, initValue);
priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> q;
dis[s] = 0;
q.emplace(0, s);
while (q.size()) {
T nowc = q.top().fi;
int i = q.top().se;
q.pop();
if (dis[i] != nowc)
continue;
for (auto &&e : g.g[i]) {
int to = e.to;
T cost = nowc + e.cost;
if (dis[to] > cost) {
dis[to] = cost;
q.emplace(dis[to], to);
}
}
}
//基本、たどり着かないなら-1
if (cant_arrive == -1)
for (auto &&d : dis)
if (d == initValue)
d = -1;
return dis;
}
template <class T>
vector<vector<T>> warshall(const graph<T> &g, int cant_arrive = -1) {
int n = g.n;
vector<vector<T>> dis(n, vector<T>(n, linf));
fora(e, g.edges) chmin(dis[e.from][e.to], e.cost);
rep(i, n) dis[i][i] = 0;
rep(k, n) rep(i, n) rep(j, n) chmin(dis[i][j], dis[i][k] + dis[k][j]);
//基本、たどり着かないなら-1
if (cant_arrive == -1)
rep(i, n) rep(j, n) if (dis[i][j] == linf) dis[i][j] = -1;
return dis;
}
template <class T = int> class tree : public undigraph<T> {
public:
using undigraph<T>::g;
using undigraph<T>::n;
using undigraph<T>::edges;
using undigraph<T>::_used;
vi dep;
vi disv;
private:
bool never = 1;
int root = -1;
vector<vector<int>> par;
bool costallone;
void dfs(int v, int p, int d) {
dep[v] = d;
par[0][v] = p;
int lim = (*this)[v].size();
for (int i = 0; i < lim; i++) {
int t = g[v][i].to;
if (t == p)
con;
dfs(t, v, d + 1);
}
}
void built() {
never = 0;
n = g.size();
par.assign(30, vi(n));
dep.resize(n);
costallone = 1;
fora(e, edges) if (e.cost != 1) costallone = 0;
dfs(root, -1, 0);
rep(k, par.size() - 1) {
rep(i, n) {
if (par[k][i] == -1)
par[k + 1][i] = -1;
else
par[k + 1][i] = par[k][par[k][i]];
}
}
if (costallone)
disv = dep;
else
disv = dijkstra(*this, root);
}
int _lca(int u, int v) {
if (dep[u] > dep[v])
swap(u, v);
rep(k, par.size()) {
if ((dep[u] - dep[v]) >> k & 1) {
v = par[k][v];
}
}
if (u == v)
return u;
rer(k, par.size() - 1) {
if (par[k][u] != par[k][v]) {
u = par[k][u];
v = par[k][v];
}
}
return par[0][u];
}
int _dis(int u, int v) {
int p = _lca(u, v);
return disv[u] + disv[v] - disv[p] * 2;
}
public:
tree(int n, int root = 0) : undigraph<T>(n), root(root) {}
bool leaf(int v) { return sz(g[v]) == 1 && v != root; }
int dis(int u, int v) {
if (never) {
built();
}
return _dis(u, v);
}
int lca(int u, int v) {
if (never) {
built();
}
return _lca(u, v);
}
};
//辺によりメモリを大量消費
// よってedgesを消している
//頂点10^6でメモリを190MB(制限の8割)使う
//軽量化のため、辺を持たないbig gridクラスがあってもいいかもしれない
//
template <class T = int> class grid_k6 : public undigraph<T> {
public:
using undigraph<T>::g;
using undigraph<T>::n;
using undigraph<T>::edges;
using undigraph<T>::_used;
int H, W;
int eid = 0;
void add(int f, int t, T cost = 1, int id = -1, int ty = -1) {
if (!(0 <= f && f < n && 0 <= t && t < n)) {
debugline("grid_k6 add");
deb(f, t, cost, id, ty);
ole();
}
g[f].emplace_back(f, t, cost, eid++, ty);
g[t].emplace_back(t, f, cost, eid++, ty);
}
int getid(int h, int w) {
if (!inside(h, w, H, W))
return -1;
return W * h + w;
}
P get2(int id) { return mp(id / W, id % W); }
P operator()(int id) { return get2(id); }
int operator()(int h, int w) { return getid(h, w); }
grid_k6(int H, int W) : H(H), W(W), undigraph<T>(H * W) {
rep(h, H) {
rep(w, W) {
int f = getid(h, w);
if (w + 1 < W)
add(f, getid(h, w + 1));
if (h + 1 < H)
add(f, getid(h + 1, w));
}
}
}
grid_k6(_vvc ba, char wall = '#')
: H(sz(ba)), W(sz(ba[0])), undigraph<T>(sz(ba) * sz(ba[0])) {
rep(h, H) {
rep(w, W) {
if (ba[h][w] == wall)
con;
int f = getid(h, w);
if (w + 1 < W && ba[h][w + 1] != wall) {
add(f, getid(h, w + 1));
}
if (h + 1 < H && ba[h + 1][w] != wall) {
add(f, getid(h + 1, w));
}
}
}
}
void add(int fh, int fw, int th, int tw) {
add(getid(fh, fw), getid(th, tw));
}
};
//左上から右下に移動できる
template <class T = int> class digrid_k6 : public digraph<T> {
public:
using digraph<T>::g;
using digraph<T>::n;
using digraph<T>::edges;
using digraph<T>::_used;
int H, W;
int eid = 0;
void add(int f, int t, T cost = 1, int id = -1, int ty = -1) {
if (!(0 <= f && f < n && 0 <= t && t < n)) {
debugline("digrid_k6 add");
deb(f, t, cost, id, ty);
ole();
}
g[f].emplace_back(f, t, cost, eid++, ty);
}
int getid(int h, int w) {
if (!inside(h, w, H, W))
return -1;
return W * h + w;
}
P get2(int id) { return mp(id / W, id % W); }
P operator()(int id) { return get2(id); }
int operator()(int h, int w) { return getid(h, w); }
digrid_k6(int H, int W) : H(H), W(W), digraph<T>(H * W) {
rep(h, H) {
rep(w, W) {
int f = getid(h, w);
if (w + 1 < W)
add(f, getid(h, w + 1));
if (h + 1 < H)
add(f, getid(h + 1, w));
}
}
}
digrid_k6(_vvc ba, char wall = '#')
: H(sz(ba)), W(sz(ba[0])), digraph<T>(sz(ba) * sz(ba[0])) {
rep(h, H) {
rep(w, W) {
if (ba[h][w] == wall)
con;
int f = getid(h, w);
if (w + 1 < W && ba[h][w + 1] != wall) {
add(f, getid(h, w + 1));
}
if (h + 1 < H && ba[h + 1][w] != wall) {
add(f, getid(h + 1, w));
}
}
}
}
void add(int fh, int fw, int th, int tw) {
add(getid(fh, fw), getid(th, tw));
}
};
template <class T> bool nibu(const graph<T> &g) {
if (g.edges.size() == 0)
return true;
UnionFind uf(g.n * 2);
for (auto &&e : g.edges)
uf.unite(e.from, e.to + g.n), uf.unite(e.from + g.n, e.to);
rep(i, g.n) if (uf.same(i, i + g.n)) return 0;
return 1;
}
//二部グラフを色分けした際の頂点数を返す
template <class T> vp nibug(graph<T> &g) {
vp cg;
if (!nibu(g)) {
debugline("nibu");
ole();
}
int _n = g.size();
vb _was(_n);
queue<P> q;
rep(i, _n) {
if (_was[i])
continue;
q.push(mp(i, 1));
_was[i] = 1;
int red = 0;
int coun = 0;
while (q.size()) {
int now = q.front().fi;
int col = q.front().se;
red += col;
coun++;
q.pop();
forg(gi, g[now]) {
if (_was[t])
continue;
q.push(mp(t, col ^ 1));
_was[t] = 1;
}
}
cg.push_back(mp(red, coun - red));
}
return cg;
}
//機能拡張
vp vtop(vi &a, vi &b) {
vp res(sz(a));
rep(i, sz(a)) res[i] = mp(a[i], b[i]);
return res;
}
void ptov(vp &p, vi &a, vi &b) {
a.resize(sz(p));
b.resize(sz(p));
rep(i, sz(p)) a[i] = p[i].fi, b[i] = p[i].se;
}
template <typename _CharT, typename _Traits, typename _Alloc>
basic_string<_CharT, _Traits, _Alloc>
operator+(const basic_string<_CharT, _Traits, _Alloc> &__lhs, const int __rv) {
basic_string<_CharT, _Traits, _Alloc> __str(__lhs);
__str.append(to_string(__rv));
return __str;
}
template <typename _CharT, typename _Traits, typename _Alloc>
void operator+=(basic_string<_CharT, _Traits, _Alloc> &__lhs, const int __rv) {
__lhs += to_string(__rv);
}
template <typename _CharT, typename _Traits, typename _Alloc>
basic_string<_CharT, _Traits, _Alloc>
operator+(const basic_string<_CharT, _Traits, _Alloc> &__lhs,
const signed __rv) {
basic_string<_CharT, _Traits, _Alloc> __str(__lhs);
__str.append(to_string(__rv));
return __str;
}
template <typename _CharT, typename _Traits, typename _Alloc>
void operator+=(basic_string<_CharT, _Traits, _Alloc> &__lhs,
const signed __rv) {
__lhs += to_string(__rv);
}
template <class T, class U> void operator+=(queue<T> &a, U v) { a.push(v); }
template <class T, class U>
priority_queue<T, vector<T>, greater<T>> &
operator+=(priority_queue<T, vector<T>, greater<T>> &a, U v) {
a.push(v);
return a;
}
template <class T, class U>
priority_queue<T> &operator+=(priority_queue<T> &a, U v) {
a.push(v);
return a;
}
template <class T, class U> set<T> &operator+=(set<T> &a, U v) {
a.insert(v);
return a;
}
template <class T, class U>
set<T, greater<T>> &operator+=(set<T, greater<T>> &a, U v) {
a.insert(v);
return a;
}
template <class T, class U> vector<T> &operator+=(vector<T> &a, U v) {
a.pb(v);
return a;
}
template <class T, class U> vector<T> operator+(const vector<T> &a, U v) {
vector<T> ret = a;
ret += v;
return ret;
}
template <class T, class U> vector<T> operator+(U v, const vector<T> &a) {
vector<T> ret = a;
ret.insert(ret.begin(), v);
return ret;
}
template <class T> vector<T> &operator+=(vector<T> &a, vector<T> &b) {
a.pb(b);
return a;
}
template <class T, class U>
vector<T> &operator+=(vector<T> &a, initializer_list<U> v) {
for (auto &&va : v)
a.pb(va);
return a;
}
template <class T> vector<T> &operator-=(vector<T> &a, vector<T> &b) {
if (sz(a) != sz(b)) {
debugline("vector<T> operator-=");
deb(a);
deb(b);
ole();
}
rep(i, sz(a)) a[i] -= b[i];
return a;
}
template <class T> vector<T> &operator-(vector<T> &a, vector<T> &b) {
if (sz(a) != sz(b)) {
debugline("vector<T> operator-");
deb(a);
deb(b);
ole();
}
vector<T> res;
rep(i, sz(a)) res[i] = a[i] - b[i];
return res;
}
template <typename T> void remove(vector<T> &v, unsigned int i) {
v.erase(v.begin() + i);
}
template <typename T>
void remove(vector<T> &v, unsigned int s, unsigned int e) {
v.erase(v.begin() + s, v.begin() + e);
}
template <typename T>
void removen(vector<T> &v, unsigned int s, unsigned int n) {
v.erase(v.begin() + s, v.begin() + s + n);
}
template <typename T> void erase(vector<T> &v, unsigned int i) {
v.erase(v.begin() + i);
}
template <typename T> void erase(vector<T> &v, unsigned int s, unsigned int e) {
v.erase(v.begin() + s, v.begin() + e);
}
template <typename T>
void erasen(vector<T> &v, unsigned int s, unsigned int n) {
v.erase(v.begin() + s, v.begin() + s + n);
}
template <typename T, typename U>
void insert(vector<T> &v, unsigned int i, U t) {
v.insert(v.begin() + i, t);
}
template <typename T, typename U> void push_front(vector<T> &v, U t) {
v.insert(v.begin(), t);
}
template <typename T, typename U>
void insert(vector<T> &v, unsigned int i, vector<T> list) {
for (auto &&va : list)
v.insert(v.begin() + i++, va);
}
template <typename T, typename U>
void insert(vector<T> &v, initializer_list<U> list) {
for (auto &&va : list)
v.pb(va);
}
template <typename T, typename U>
void insert(vector<T> &v, unsigned int i, initializer_list<U> list) {
for (auto &&va : list)
v.insert(v.begin() + i++, va);
}
template <typename T> void insert(set<T> &v, vector<T> list) {
for (auto &&va : list)
v.insert(va);
}
template <typename T> void insert(set<T> &v, initializer_list<T> list) {
for (auto &&va : list)
v.insert(va);
}
//閉路がなければtrue
bool topo(vi &res, digraph<int> &g) {
int n = g.g.size();
vi nyu(n);
rep(i, n) for (auto &&e : g[i]) nyu[e.to]++;
queue<int> st;
rep(i, n) if (nyu[i] == 0) st.push(i);
while (st.size()) {
int v = st.front();
st.pop();
res.pb(v);
fora(e, g[v]) if (--nyu[e.to] == 0) st.push(e.to);
}
return res.size() == n;
}
//辞書順最小トポロジカルソート
bool topos(vi &res, digraph<int> &g) {
int n = g.g.size();
vi nyu(n);
rep(i, n) for (auto &&e : g[i]) nyu[e.to]++;
//小さい順
priority_queue<int, vector<int>, greater<int>> q;
rep(i, n) if (nyu[i] == 0) q.push(i);
while (q.size()) {
int i = q.top();
q.pop();
res.pb(i);
fora(e, g[i]) if (--nyu[e.to] == 0) q.push(e.to);
}
return res.size() == n;
}
vector<string> split(const string a, const char deli) {
string b = a + deli;
int l = 0, r = 0, n = b.size();
vector<string> res;
rep(i, n) {
if (b[i] == deli) {
r = i;
if (l < r)
res.push_back(b.substr(l, r - l));
l = i + 1;
}
}
return res;
}
vector<string> split(const string a, const string deli) {
string b = a + deli;
int l = 0, r = 0, n = b.size(), dn = deli.size();
vector<string> res;
rep(i, n) {
if (i + dn <= n && b.substr(i, i + dn) == deli) {
r = i;
if (l < r)
res.push_back(b.substr(l, r - l));
i += dn - 1;
l = i + 1;
}
}
return res;
}
void yn(bool a) {
if (a)
cout << "yes" << endl;
else
cout << "no" << endl;
}
void Yn(bool a) {
if (a)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
void YN(bool a) {
if (a)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
void fyn(bool a) {
if (a)
cout << "yes" << endl;
else
cout << "no" << endl;
exit(0);
}
void fYn(bool a) {
if (a)
cout << "Yes" << endl;
else
cout << "No" << endl;
exit(0);
}
void fYN(bool a) {
if (a)
cout << "YES" << endl;
else
cout << "NO" << endl;
exit(0);
}
void Possible(bool a) {
if (a)
cout << "Possible" << endl;
else
cout << "Impossible" << endl;
exit(0);
}
int n, a, b;
vi res;
//最下位ビット
int lbit(int n) { return n & -n; }
//最上位ビット
int hbit(int n) {
n |= (n >> 1);
n |= (n >> 2);
n |= (n >> 4);
n |= (n >> 8);
n |= (n >> 16);
n |= (n >> 32);
return n - (n >> 1);
}
#define bcou __builtin_popcountll
void dfs(int s, int t, int cuts) {
// t以外に行ける場所がない
if (bcou(cuts) == n - 1) {
res.pb(s);
res.pb(t);
return;
}
// s -> t で使うことになる軸の集合
int need = s ^ t;
// needに含まれる軸ncutで切断すれば、sとtを分離できる
int ncut = lbit(need);
cuts |= ncut;
// sとtを分離した時、s側で使える軸の集合
int cand = ((1 << n) - 1) ^ cuts;
int mid = s ^ lbit(cand);
// t側のスタート地点がtになってはいけない
if ((mid ^ ncut) == t) {
mid = s ^ hbit(cand);
}
//二つの部分問題に帰着できた
dfs(s, mid, cuts);
// ncutでsとtを分離したため、mid^ncutでt側に移動できる
dfs(mid ^ ncut, t, cuts);
}
void solve() {
cin >> n >> a >> b;
if (bcou(a ^ b) == 0) {
cout << "NO" << endl;
return;
}
cout << "YES" << endl;
dfs(a, b, 0);
cout << res << endl;
}
int my(int n, vi a) { return 0; }
int sister(int n, vi a) { return 0; }
signed main() {
solve();
#define _arg n, a
// cin>>n;
// na(a,n);
// my(_arg);
// cout << my(_arg) << endl;
#ifdef _DEBUG
bool bad = 0;
for (int i = 0, ok = 1; i < k5 && ok; i++) {
int n = rand(1, 3);
vi a = ranv(n, 1, 10);
int myres = my(_arg);
int res = sister(_arg);
ok = myres == res;
if (!ok) {
cout << n << endl;
cout << a << endl;
cout << "正解 : " << res << endl;
cout << "出力 : " << myres << endl;
bad = 1;
break;
}
}
#endif
return 0;
};
| //#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>
using namespace std;
//@起動時
struct initon {
initon() {
cin.tie(0);
ios::sync_with_stdio(false);
cout.setf(ios::fixed);
cout.precision(16);
srand((unsigned)clock() + (unsigned)time(NULL));
};
} __initon;
//衝突対策
#define ws ___ws
//@必須構造
struct T {
int f, s, t;
T() { f = -1, s = -1, t = -1; }
T(int f, int s, int t) : f(f), s(s), t(t) {}
bool operator<(const T &r) const {
return f != r.f ? f < r.f : s != r.s ? s < r.s : t < r.t;
// return f != r.f ? f > r.f : s != r.s ? s > r.s : t > r.t; 大きい順
}
bool operator>(const T &r) const {
return f != r.f ? f > r.f : s != r.s ? s > r.s : t > r.t;
// return f != r.f ? f > r.f : s != r.s ? s > r.s : t > r.t; 小さい順
}
bool operator==(const T &r) const { return f == r.f && s == r.s && t == r.t; }
bool operator!=(const T &r) const { return f != r.f || s != r.s || t != r.t; }
int operator[](int i) {
assert(i < 3);
return i == 0 ? f : i == 1 ? s : t;
}
};
struct F {
int a, b, c, d;
F() { a = -1, b = -1, c = -1, d = -1; }
F(int a, int b, int c, int d) : a(a), b(b), c(c), d(d) {}
bool operator<(const F &r) const {
return a != r.a ? a < r.a
: b != r.b ? b < r.b
: c != r.c ? c < r.c
: d < r.d;
// return a != r.a ? a > r.a : b != r.b ? b > r.b : c != r.c ? c >
// r.c : d > r.d;
}
bool operator>(const F &r) const {
return a != r.a ? a > r.a
: b != r.b ? b > r.b
: c != r.c ? c > r.c
: d > r.d;
// return a != r.a ? a < r.a : b != r.b ? b < r.b : c != r.c ? c <
// r.c : d < r.d;
}
bool operator==(const F &r) const {
return a == r.a && b == r.b && c == r.c && d == r.d;
}
bool operator!=(const F &r) const {
return a != r.a || b != r.b || c != r.c || d != r.d;
}
int operator[](int i) {
assert(i < 4);
return i == 0 ? a : i == 1 ? b : i == 2 ? c : d;
}
};
T mt(int a, int b, int c) { return T(a, b, c); }
//@マクロ省略系 型,構造
#define int long long
#define ll long long
#define double long double
#define ull unsigned long long
using dou = double;
using itn = int;
using str = string;
using bo = bool;
using P = pair<ll, ll>;
#define fi first
#define se second
#define vec vector
#define beg begin
#define rbeg rbegin
#define con continue
#define bre break
#define brk break
#define is ==
//マクロ省略系 コンテナ
using vi = vector<int>;
#define _overloadvvi(_1, _2, _3, _4, name, ...) name
#define vvi0() vec<vi>
#define vvi1(a) vec<vi> a
#define vvi2(a, b) vec<vi> a(b)
#define vvi3(a, b, c) vec<vi> a(b, vi(c))
#define vvi4(a, b, c, d) vec<vi> a(b, vi(c, d))
#define vvi(...) \
_overloadvvi(__VA_ARGS__, vvi4, vvi3, vvi2, vvi1, vvi0)(__VA_ARGS__)
using vl = vector<ll>;
#define _overloadvvl(_1, _2, _3, _4, name, ...) name
#define vvl1(a) vec<vl> a
#define vvl2(a, b) vec<vl> a(b)
#define vvl3(a, b, c) vec<vl> a(b, vl(c))
#define vvl4(a, b, c, d) vec<vl> a(b, vl(c, d))
#define vvl(...) _overloadvvl(__VA_ARGS__, vvl4, vvl3, vvl2, vvl1)(__VA_ARGS__)
using vb = vector<bool>;
#define _overloadvvb(_1, _2, _3, _4, name, ...) name
#define vvb1(a) vec<vb> a
#define vvb2(a, b) vec<vb> a(b)
#define vvb3(a, b, c) vec<vb> a(b, vb(c))
#define vvb4(a, b, c, d) vec<vb> a(b, vb(c, d))
#define vvb(...) _overloadvvb(__VA_ARGS__, vvb4, vvb3, vvb2, vvb1)(__VA_ARGS__)
using vs = vector<string>;
#define _overloadvvs(_1, _2, _3, _4, name, ...) name
#define vvs1(a) vec<vs> a
#define vvs2(a, b) vec<vs> a(b)
#define vvs3(a, b, c) vec<vs> a(b, vs(c))
#define vvs4(a, b, c, d) vec<vs> a(b, vs(c, d))
#define vvs(...) _overloadvvs(__VA_ARGS__, vvs4, vvs3, vvs2, vvs1)(__VA_ARGS__)
using vd = vector<double>;
#define _overloadvvd(_1, _2, _3, _4, name, ...) name
#define vvd1(a) vec<vd> a
#define vvd2(a, b) vec<vd> a(b)
#define vvd3(a, b, c) vec<vd> a(b, vd(c))
#define vvd4(a, b, c, d) vec<vd> a(b, vd(c, d))
#define vvd(...) _overloadvvd(__VA_ARGS__, vvd4, vvd3, vvd2, vvd1)(__VA_ARGS__)
using vc = vector<char>;
#define _overloadvvc(_1, _2, _3, _4, name, ...) name
#define vvc1(a) vec<vc> a
#define vvc2(a, b) vec<vc> a(b)
#define vvc3(a, b, c) vec<vc> a(b, vc(c))
#define vvc4(a, b, c, d) vec<vc> a(b, vc(c, d))
#define vvc(...) _overloadvvc(__VA_ARGS__, vvc4, vvc3, vvc2, vvc1)(__VA_ARGS__)
using vp = vector<P>;
#define _overloadvvp(_1, _2, _3, _4, name, ...) name
#define vvp1(a) vec<vp> a
#define vvp2(a, b) vec<vp> a(b)
#define vvp3(a, b, c) vec<vp> a(b, vp(c))
#define vvp4(a, b, c, d) vec<vp> a(b, vp(c, d))
using vt = vector<T>;
#define _overloadvvt(_1, _2, _3, _4, name, ...) name
#define vvt1(a) vec<vt> a
#define vvt2(a, b) vec<vt> a(b)
#define vvt3(a, b, c) vec<vt> a(b, vt(c))
#define vvt4(a, b, c, d) vec<vt> a(b, vt(c, d))
#define v3i(a, b, c, d) vector<vector<vi>> a(b, vector<vi>(c, vi(d)))
#define v3d(a, b, c, d) vector<vector<vd>> a(b, vector<vd>(c, vd(d)))
#define v3m(a, b, c, d) vector<vector<vm>> a(b, vector<vm>(c, vm(d)))
#define _vvi vector<vi>
#define _vvl vector<vl>
#define _vvb vector<vb>
#define _vvs vector<vs>
#define _vvd vector<vd>
#define _vvc vector<vc>
#define _vvp vector<vp>
#define PQ priority_queue<ll, vector<ll>, greater<ll>>
#define tos to_string
using mapi = map<int, int>;
using mapd = map<dou, int>;
using mapc = map<char, int>;
using maps = map<str, int>;
using seti = set<int>;
using setd = set<dou>;
using setc = set<char>;
using sets = set<str>;
using qui = queue<int>;
#define bset bitset
#define uset unordered_set
#define mset multiset
#define umap unordered_map
#define umapi unordered_map<int, int>
#define umapp unordered_map<P, int>
#define mmap multimap
//マクロ 繰り返し
#define _overloadrep(_1, _2, _3, _4, name, ...) name
#define _rep(i, n) for (int i = 0, _lim = n; i < _lim; i++)
#define repi(i, m, n) for (int i = m, _lim = n; i < _lim; i++)
#define repadd(i, m, n, ad) for (int i = m, _lim = n; i < _lim; i += ad)
#define rep(...) _overloadrep(__VA_ARGS__, repadd, repi, _rep, )(__VA_ARGS__)
#define _rer(i, n) for (int i = n; i >= 0; i--)
#define reri(i, m, n) for (int i = m, _lim = n; i >= _lim; i--)
#define rerdec(i, m, n, dec) for (int i = m, _lim = n; i >= _lim; i -= dec)
#define rer(...) _overloadrep(__VA_ARGS__, rerdec, reri, _rer, )(__VA_ARGS__)
#define fora(a, b) for (auto &&a : b)
#define forg(gi, ve) \
for (int gi = 0, f, t, c; gi < ve.size() && (f = ve[gi].from, t = ve[gi].to, \
c = ve[gi].cost, true); \
gi++)
#define fort(gi, ve) \
for (int gi = 0, f, t, c; \
gi < ve.size() && (gi += (ve[gi].to == p)) < ve.size() && \
(f = ve[gi].from, t = ve[gi].to, c = ve[gi].cost, true); \
gi++)
//マクロ 定数
#define k3 1010
#define k4 10101
#define k5 101010
#define k6 1010101
#define k7 10101010
const int inf = (int)1e9 + 100;
const ll linf = (ll)1e18 + 100;
const double eps = 1e-9;
const double PI = 3.1415926535897932384626433832795029L;
ll ma = numeric_limits<ll>::min();
ll mi = numeric_limits<ll>::max();
const int y4[] = {-1, 1, 0, 0};
const int x4[] = {0, 0, -1, 1};
const int y8[] = {0, 1, 0, -1, -1, 1, 1, -1};
const int x8[] = {1, 0, -1, 0, 1, -1, 1, -1};
//マクロ省略形 関数等
#define arsz(a) (sizeof(a) / sizeof(a[0]))
#define sz(a) ((int)(a).size())
#define rs resize
#define mp make_pair
#define pb push_back
#define pf push_front
#define eb emplace_back
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
//@拡張系 こう出来るべきというもの
//埋め込み 存在を意識せずに機能を増やされているもの
namespace std {
template <> class hash<std::pair<signed, signed>> {
public:
size_t operator()(const std::pair<signed, signed> &x) const {
return hash<ll>()(((ll)x.first << 32) + x.second);
}
};
template <> class hash<std::pair<ll, ll>> {
public:
//大きいllが渡されると、<<32でオーバーフローするがとりあえず問題ないと判断
size_t operator()(const std::pair<ll, ll> &x) const {
return hash<ll>()(((ll)x.first << 32) + x.second);
}
};
} // namespace std
istream &operator>>(istream &iss, P &a) {
iss >> a.first >> a.second;
return iss;
}
template <typename T> istream &operator>>(istream &iss, vector<T> &vec) {
for (T &x : vec)
iss >> x;
return iss;
}
ostream &operator<<(ostream &os, P p) {
os << p.fi << " " << p.se << endl;
return os;
}
ostream &operator<<(ostream &os, T p) {
os << p.f << " " << p.s << " " << p.t;
return os;
}
ostream &operator<<(ostream &os, F p) {
os << p.a << " " << p.b << " " << p.c << " " << p.d;
return os;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
for (int i = 0; i < vec.size(); i++)
os << vec[i] << (i + 1 == vec.size() ? "" : " ");
return os;
}
template <typename T> ostream &operator<<(ostream &os, vector<vector<T>> &vec) {
for (int i = 0; i < vec.size(); i++) {
for (int j = 0; j < vec[0].size(); j++) {
os << vec[i][j];
}
os << endl;
}
return os;
}
template <typename V, typename H> void resize(vector<V> &vec, const H head) {
vec.resize(head);
}
template <typename V, typename H, typename... T>
void resize(vector<V> &vec, const H &head, const T... tail) {
vec.resize(head);
for (auto &v : vec)
resize(v, tail...);
}
template <typename T, typename _Pr>
bool all_of(const vector<T> &vec, _Pr pred) {
return std::all_of(vec.begin(), vec.end(), pred);
}
template <typename T, typename _Pr>
bool any_of(const vector<T> &vec, _Pr pred) {
return std::any_of(vec.begin(), vec.end(), pred);
}
template <typename T, typename _Pr>
bool none_of(const vector<T> &vec, _Pr pred) {
return std::none_of(vec.begin(), vec.end(), pred);
}
template <typename T, typename _Pr>
const typename vector<T>::const_iterator find_if(const vector<T> &vec,
_Pr pred) {
return std::find_if(vec.begin(), vec.end(), pred);
}
template <typename T> bool contains(const vector<T> &vec, const T &val) {
return std::find(vec.begin(), vec.end(), val) != vec.end();
}
template <typename T, typename _Pr>
bool contains_if(const vector<T> &vec, _Pr pred) {
return std::find_if(vec.begin(), vec.end(), pred) != vec.end();
}
template <class T> void replace(vector<T> &a, T key, T v) {
replace(a.begin(), a.end(), key, v);
}
template <class T> bool includes(vector<T> &a, vector<T> &b) {
vi c = a;
vi d = b;
sort(all(c));
sort(all(d));
return includes(all(c), all(d));
}
template <class T> bool is_permutation(vector<T> &a, vector<T> &b) {
return is_permutation(all(a), all(b));
}
template <class T> bool next_permutation(vector<T> &a) {
return next_permutation(all(a));
}
template <class T> T pop(set<T> &set) {
T res = *set.begin();
set.erase(set.find(res));
return res;
}
template <class T> T pop(mset<T> &set) {
T res = *set.begin();
set.erase(set.find(res));
return res;
}
template <class T> T popBack(set<T> &set) {
T res = *set.rbegin();
set.erase(set.find(res));
return res;
}
template <class T> T popBack(mset<T> &set) {
T res = *set.rbegin();
set.erase(set.find(res));
return res;
}
inline void sort(string &a) { sort(a.begin(), a.end()); }
template <class T> inline void sort(vector<T> &a) { sort(a.begin(), a.end()); };
template <class T> inline void sort(vector<T> &a, int len) {
sort(a.begin(), a.begin() + len);
};
template <class T, class F> inline void sort(vector<T> &a, F f) {
sort(a.begin(), a.end(), [&](T l, T r) { return f(l) < f(r); });
};
enum ___pcomparator { fisi, fisd, fdsi, fdsd, sifi, sifd, sdfi, sdfd };
inline void sort(vector<P> &a, ___pcomparator type) {
switch (type) {
case fisi:
sort(all(a),
[&](P l, P r) { return l.fi != r.fi ? l.fi < r.fi : l.se < r.se; });
break;
case fisd:
sort(all(a),
[&](P l, P r) { return l.fi != r.fi ? l.fi < r.fi : l.se > r.se; });
break;
case fdsi:
sort(all(a),
[&](P l, P r) { return l.fi != r.fi ? l.fi > r.fi : l.se < r.se; });
break;
case fdsd:
sort(all(a),
[&](P l, P r) { return l.fi != r.fi ? l.fi > r.fi : l.se > r.se; });
break;
case sifi:
sort(all(a),
[&](P l, P r) { return l.se != r.se ? l.se < r.se : l.fi < r.fi; });
break;
case sifd:
sort(all(a),
[&](P l, P r) { return l.se != r.se ? l.se < r.se : l.fi > r.fi; });
break;
case sdfi:
sort(all(a),
[&](P l, P r) { return l.se != r.se ? l.se > r.se : l.fi < r.fi; });
break;
case sdfd:
sort(all(a),
[&](P l, P r) { return l.se != r.se ? l.se > r.se : l.fi > r.fi; });
break;
}
};
template <class T> inline void rsort(vector<T> &a) {
sort(a.begin(), a.end(), greater<T>());
};
template <class T> inline void rsort(vector<T> &a, int len) {
sort(a.begin(), a.begin() + len, greater<T>());
};
template <class U, class F> inline void rsort(vector<U> &a, F f) {
sort(a.begin(), a.end(), [&](U l, U r) { return f(l) > f(r); });
};
template <class U> inline void sortp(vector<U> &a, vector<U> &b) {
vp c;
int n = sz(a);
assert(n == sz(b));
rep(i, n) c.eb(a[i], b[i]);
sort(c);
rep(i, n) {
a[i] = c[i].first;
b[i] = c[i].second;
;
}
};
// F = T<T>
//例えばreturn p.fi + p.se;
template <class U, class F> inline void sortp(vector<U> &a, vector<U> &b, F f) {
vp c;
int n = sz(a);
assert(n == sz(b));
rep(i, n) c.eb(a[i], b[i]);
sort(c, f);
rep(i, n) {
a[i] = c[i].first;
b[i] = c[i].second;
}
};
template <class U, class F>
inline void sortp(vector<U> &a, vector<U> &b, char type) {
vp c;
int n = sz(a);
assert(n == sz(b));
rep(i, n) c.eb(a[i], b[i]);
sort(c, type);
rep(i, n) {
a[i] = c[i].first;
b[i] = c[i].second;
}
};
template <class U> inline void rsortp(vector<U> &a, vector<U> &b) {
vp c;
int n = sz(a);
assert(n == sz(b));
rep(i, n) c.eb(a[i], b[i]);
rsort(c);
rep(i, n) {
a[i] = c[i].first;
b[i] = c[i].second;
}
};
template <class U, class F>
inline void rsortp(vector<U> &a, vector<U> &b, F f) {
vp c;
int n = sz(a);
assert(n == sz(b));
rep(i, n) c.eb(a[i], b[i]);
rsort(c, f);
rep(i, n) {
a[i] = c[i].first;
b[i] = c[i].second;
}
};
template <class U> inline void sortt(vector<U> &a, vector<U> &b, vector<U> &c) {
vt r;
int n = sz(a);
assert(n == sz(b));
assert(n == sz(c));
rep(i, n) r.eb(a[i], b[i], c[i]);
sort(r);
rep(i, n) {
a[i] = r[i].f;
b[i] = r[i].s;
c[i] = r[i].t;
}
};
template <class U, class F>
inline void sortt(vector<U> &a, vector<U> &b, vector<U> &c, F f) {
vt r;
int n = sz(a);
assert(n == sz(b));
assert(n == sz(c));
rep(i, n) r.eb(a[i], b[i], c[i]);
sort(r, f);
rep(i, n) {
a[i] = r[i].f;
b[i] = r[i].s;
c[i] = r[i].t;
}
};
template <class U, class F>
inline void rsortt(vector<U> &a, vector<U> &b, vector<U> &c, F f) {
vt r;
int n = sz(a);
assert(n == sz(b));
assert(n == sz(c));
rep(i, n) r.eb(a[i], b[i], c[i]);
rsort(r, f);
rep(i, n) {
a[i] = r[i].f;
b[i] = r[i].s;
c[i] = r[i].t;
}
};
template <class T> inline void sort2(vector<vector<T>> &a) {
for (int i = 0, n = a.size(); i < n; i++)
sort(a[i]);
}
template <class T> inline void rsort2(vector<vector<T>> &a) {
for (int i = 0, n = a.size(); i < n; i++)
rsort(a[i]);
}
template <typename A, size_t N, typename T> void fill(A (&a)[N], const T &v) {
rep(i, N) a[i] = v;
}
template <typename A, size_t N, size_t O, typename T>
void fill(A (&a)[N][O], const T &v) {
rep(i, N) rep(j, O) a[i][j] = v;
}
template <typename A, size_t N, size_t O, size_t P, typename T>
void fill(A (&a)[N][O][P], const T &v) {
rep(i, N) rep(j, O) rep(k, P) a[i][j][k] = v;
}
template <typename A, size_t N, size_t O, size_t P, size_t Q, typename T>
void fill(A (&a)[N][O][P][Q], const T &v) {
rep(i, N) rep(j, O) rep(k, P) rep(l, Q) a[i][j][k][l] = v;
}
template <typename A, size_t N, size_t O, size_t P, size_t Q, size_t R,
typename T>
void fill(A (&a)[N][O][P][Q][R], const T &v) {
rep(i, N) rep(j, O) rep(k, P) rep(l, Q) rep(m, R) a[i][j][k][l][m] = v;
}
template <typename A, size_t N, size_t O, size_t P, size_t Q, size_t R,
size_t S, typename T>
void fill(A (&a)[N][O][P][Q][R][S], const T &v) {
rep(i, N) rep(j, O) rep(k, P) rep(l, Q) rep(m, R) rep(n, S)
a[i][j][k][l][m][n] = v;
}
template <typename V, typename T> void fill(V &xx, const T vall) { xx = vall; }
template <typename V, typename T> void fill(vector<V> &vecc, const T vall) {
for (auto &&vx : vecc)
fill(vx, vall);
}
//@汎用便利関数 入力
template <typename T = int> T _in() {
T x;
cin >> x;
return (x);
}
#define _overloadin(_1, _2, _3, _4, name, ...) name
#define in0() _in()
#define in1(a) cin >> a
#define in2(a, b) cin >> a >> b
#define in3(a, b, c) cin >> a >> b >> c
#define in4(a, b, c, d) cin >> a >> b >> c >> d
#define in(...) _overloadin(__VA_ARGS__, in4, in3, in2, in1, in0)(__VA_ARGS__)
string sin() { return _in<string>(); }
double din() { return _in<double>(); }
ll lin() { return _in<ll>(); }
#define na(a, n) \
a.resize(n); \
rep(i, n) cin >> a[i];
#define nao(a, n) \
a.resize(n + 1); \
rep(i, n) cin >> a[i + 1];
#define nad(a, n) \
a.resize(n); \
rep(i, n) cin >> a[i], a[i]--;
#define na2(a, b, n) \
a.resize(n), b.resize(n); \
rep(i, n) cin >> a[i] >> b[i];
#define na2d(a, b, n) \
a.resize(n), b.resize(n); \
rep(i, n) cin >> a[i] >> b[i], a[i]--, b[i]--;
#define na3(a, b, c, n) \
a.resize(n), b.resize(n), c.resize(n); \
rep(i, n) cin >> a[i] >> b[i] >> c[i];
#define na3d(a, b, c, n) \
a.resize(n), b.resize(n), c.resize(n); \
rep(i, n) cin >> a[i] >> b[i] >> c[i], a[i]--, b[i]--, c[i]--;
#define nt(a, h, w) \
resize(a, h, w); \
rep(hi, h) rep(wi, w) cin >> a[hi][wi];
#define ntd(a, h, w) \
rs(a, h, w); \
rep(hi, h) rep(wi, w) cin >> a[hi][wi], a[hi][wi]--;
#define ntp(a, h, w) \
fill(a, '#'); \
rep(hi, 1, h + 1) rep(wi, 1, w + 1) cin >> a[hi][wi];
//汎用便利関数 出力
template <class T> void out(T x) {
typeid(x) == typeid(double) ? cout << fixed << setprecision(10) << x << endl
: cout << x << endl;
}
template <class T> void out(vector<T> a) { fora(v, a) cout << v << endl; }
//デバッグ
#define sp << " " <<
#define debugName(VariableName) #VariableName
#define _deb1(x) cerr << debugName(x) << " = " << x << endl
#define _deb2(x, y) \
cerr << debugName(x) << " = " << x << ", " << debugName(y) << " = " << y \
<< endl
#define _deb3(x, y, z) \
cerr << debugName(x) << " = " << x << ", " << debugName(y) << " = " << y \
<< ", " debugName(z) << " = " << z << endl
#define _deb4(x, y, z, a) \
cerr << debugName(x) << " = " << x << ", " << debugName(y) << " = " << y \
<< ", " << debugName(z) << " = " << z << ", " << debugName(a) << " = " \
<< a << endl
#define _deb5(x, y, z, a, b) \
cerr << debugName(x) << " = " << x << ", " << debugName(y) << " = " << y \
<< ", " << debugName(z) << " = " << z << ", " << debugName(a) << " = " \
<< a << ", " << debugName(b) << " = " << b << endl
#define _overloadebug(_1, _2, _3, _4, _5, name, ...) name
#define debug(...) \
_overloadebug(__VA_ARGS__, _deb5, _deb4, _deb3, _deb2, _deb1)(__VA_ARGS__)
#define deb(...) \
_overloadebug(__VA_ARGS__, _deb5, _deb4, _deb3, _deb2, _deb1)(__VA_ARGS__)
#define debugline(x) \
cerr << x << " " \
<< "(L:" << __LINE__ << ")" << '\n'
//よく使うクラス、構造体
class UnionFind {
public:
vi par, rank, sizes;
int n, trees;
UnionFind(int n) : n(n), trees(n) {
par.resize(n), rank.resize(n), sizes.resize(n);
rep(i, n) par[i] = i, sizes[i] = 1;
}
int root(int x) {
if (par[x] == x)
return x;
else
return par[x] = root(par[x]);
}
int find(int x) { return root(x); }
void unite(int x, int y) {
x = root(x);
y = root(y);
if (x == y)
return;
if (rank[x] < rank[y])
swap(x, y);
trees--;
par[y] = x;
sizes[x] += sizes[y];
if (rank[x] == rank[y])
rank[x]++;
}
bool same(int x, int y) { return root(x) == root(y); }
int size(int x) { return sizes[root(x)]; }
//順不同 umapなので
vec<vi> sets() {
vec<vi> res(trees);
umap<int, vi> map;
rep(i, n) map[root(i)].push_back(i);
int i = 0;
for (auto &&p : map) {
int r = p.fi;
res[i].push_back(r);
for (auto &&v : p.se) {
if (r == v)
continue;
res[i].push_back(v);
}
i++;
}
return res;
}
};
// MOD関連
ll MOD = (int)1e9 + 7;
class mint {
public:
int x;
mint() : x(0) {}
mint(signed y) : x(y >= 0 ? y % MOD : MOD - (-y) % MOD) {}
mint(int y) : x(y >= 0 ? y % MOD : MOD - (-y) % MOD) {}
static int _mpow(int v, ll a) {
ll x = v, n = a, res = 1;
while (n) {
if (n & 1)
res = (res * x) % MOD;
x = (x * x) % MOD;
n >>= 1;
}
return res;
}
// Arithmetic Oprators
mint &operator+=(mint that) {
if ((x += that.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator-=(mint that) {
if ((x += MOD - that.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator*=(mint that) {
x = 1LL * x * that.x % MOD;
return *this;
}
mint &operator/=(const mint &that);
mint &operator^=(const mint &that) {
this->x = _mpow(x, that.x);
return *this;
}
mint &operator%=(mint that) {
x %= that.x;
return *this;
}
mint &operator+=(const int that) { return *this += mint(that); }
mint &operator-=(const int that) { return *this -= mint(that); }
mint &operator*=(const int that) { return *this *= mint(that); }
mint &operator/=(const int that);
mint &operator^=(const int that) {
this->x = _mpow(x, that);
return *this;
}
mint &operator%=(const int that) { return *this %= mint(that); }
mint &operator+=(const signed that) { return *this += mint(that); }
mint &operator-=(const signed that) { return *this -= mint(that); }
mint &operator*=(const signed that) { return *this *= mint(that); }
mint &operator/=(const signed that);
mint &operator^=(const signed that) {
this->x = _mpow(x, that);
return *this;
}
mint &operator%=(const signed that) { return *this %= mint(that); }
// Comparators
bool operator<(mint that) { return x < that.x; }
bool operator>(mint that) { return x > that.x; }
bool operator<=(mint that) { return x <= that.x; }
bool operator>=(mint that) { return x >= that.x; }
bool operator!=(mint that) { return x != that.x; }
bool operator==(mint that) { return x == that.x; }
bool operator!=(int that) { return x != that; }
bool operator==(int that) { return x == that; }
bool operator!=(signed that) { return x != that; }
bool operator==(signed that) { return x == that; }
// Utilities
unsigned getval() const { return x; }
operator int() { return x; }
mint operator+(mint that) const { return mint(*this) += that; }
mint operator-(mint that) const { return mint(*this) -= that; }
mint operator*(mint that) const { return mint(*this) *= that; }
mint operator%(mint that) const { return mint(*this) %= that; }
mint operator+(const int that) const { return mint(*this) += that; }
mint operator-(const int that) const { return mint(*this) -= that; }
mint operator*(const int that) const { return mint(*this) *= that; }
mint operator%(const int that) const { return mint(*this) %= that; }
mint operator=(const int that) { return *this = mint(that); }
mint operator+(const signed that) const { return mint(*this) += that; }
mint operator-(const signed that) const { return mint(*this) -= that; }
mint operator*(const signed that) const { return mint(*this) *= that; }
mint operator%(const signed that) const { return mint(*this) %= that; }
mint operator=(const signed that) { return *this = mint(that); }
mint operator++() {
x++;
return *this;
}
mint operator++(signed) {
auto ret = *this;
x++;
return ret;
}
friend void operator+=(ll &a, const mint &b) { a = mint(a % MOD + b.x); }
friend void operator-=(ll &a, const mint &b) { a = mint(a % MOD - b.x); }
friend void operator*=(ll &a, const mint &b) { a = mint(a % MOD * b.x); }
friend void operator/=(ll &a, const mint &b);
friend mint operator+(const ll a, const mint &b) {
return mint(a % MOD + b.x);
}
friend mint operator-(const ll a, const mint &b) {
return mint(a % MOD - b.x);
}
friend mint operator*(const ll a, const mint &b) {
return mint(a % MOD * b.x);
}
friend mint operator^(const ll a, const mint &b) { return _mpow(a, b.x); }
};
mint itom(int v) {
mint res;
res.x = v;
return res;
}
const int setModMax = 510000;
vector<mint> fac, finv, inv;
void setMod(int m = MOD) {
fac.resize(setModMax);
finv.resize(setModMax);
inv.resize(setModMax);
MOD = m;
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < setModMax; i++) {
fac[i] = fac[i - 1].x * i % MOD;
inv[i] = MOD - inv[MOD % i].x * (MOD / i) % MOD;
finv[i] = finv[i - 1].x * inv[i].x % MOD;
}
}
mint mpow(int v, ll a) { return mint::_mpow(v, a); }
mint com(ll n, ll r) {
if (n < r || n < 0 || r < 0)
return 0;
if (fac.size() == 0)
setMod();
return fac[n] * finv[r] * finv[n - r];
}
mint ncr(ll n, ll r) { return com(n, r); }
// n人にr個を配るとき、同じ人に何個配っても良い場合
mint nhr(ll n, ll r) { return com(n + r - 1, r); }
//拡張ユークリッドの互除法
mint minv(ll a) {
if (fac[0] == 0)
setMod();
if (a < setModMax)
return inv[a];
a %= MOD;
ll b = MOD, x = 1, y = 0;
while (b) {
ll t = a / b;
a -= t * b;
swap(a, b);
x -= t * y;
swap(x, y);
}
return x;
}
mint &mint::operator/=(const mint &that) { return *this *= minv(that.x); }
mint &mint::operator/=(const ll a) { return *this *= minv(a); }
mint &mint::operator/=(const signed a) { return *this *= minv(a); }
void operator/=(ll &a, const mint &b) { a = (a * minv(b.x)).x; }
using PM = pair<mint, mint>;
using vm = vector<mint>;
#define _overloadvvm(_1, _2, _3, _4, name, ...) name
#define vvm1(a) vec<vm> a
#define vvm2(a, b) vec<vm> a(b)
#define vvm3(a, b, c) vec<vm> a(b, vm(c))
#define vvm4(a, b, c, d) vec<vm> a(b, vm(c, d))
#define vvm(...) _overloadvvm(__VA_ARGS__, vvm4, vvm3, vvm2, vvm1)(__VA_ARGS__)
vb isPrime;
vi primes;
void setPrime() {
isPrime.resize(4010101);
fill(isPrime, true);
int len = sizeof(isPrime) / sizeof(isPrime[0]);
isPrime[0] = isPrime[1] = false;
for (int i = 2; i <= sqrt(len) + 5; ++i) {
if (!isPrime[i])
continue;
for (int j = 2; i * j < len; ++j) {
isPrime[i * j] = false;
}
}
rep(i, len) if (isPrime[i]) primes.pb(i);
}
//幾何 Pをcomplexとして扱う
bool eq(double a, double b) { return fabs(a - b) < eps; }
using C = complex<double>;
C rot(C &a, dou th) { return a * C(cos(th), sin(th)); }
dou inpro(C &a, C &b) { return real(a * conj(b)); }
// 90度回転させて内積が0なら平行
bool line(C a, C b, C c) {
C ab = b - a;
C ac = c - a;
//複素数の掛け算は回転
ab *= C(0, 1);
return eq(inpro(ab, ac), 0);
}
bool line(P a, P b, P c) {
return line(C(a.fi, a.se), C(b.fi, b.se), C(c.fi, c.se));
}
bool line(int xa, int ya, int xb, int yb, int xc, int yc) {
C a = C(xa, ya);
C b = C(xb, yb);
C c = C(xc, yc);
return line(a, b, c);
}
//便利関数
//テスト用
char ranc() { return (char)('a' + rand() % 26); }
int rand(int min, int max) {
assert(min <= max);
if (min >= 0 && max >= 0) {
return rand() % (max + 1 - min) + min;
} else if (max < 0) {
return -rand(-max, -min);
} else {
//+
if (rand() % 2) {
return rand(0, max);
//-
} else {
return -rand(0, -min);
}
}
}
vi ranv(int n, int min, int max) {
vi v(n);
rep(i, n) v[i] = rand(min, max);
return v;
}
//単調増加
vi ranvi(int n, int min, int max) {
vi v(n);
bool bad = 1;
while (bad) {
bad = 0;
v.resize(n);
rep(i, n) {
if (i && min > max - v[i - 1]) {
bad = 1;
break;
}
if (i)
v[i] = v[i - 1] + rand(min, max - v[i - 1]);
else
v[i] = rand(min, max);
}
}
return v;
}
void ranvlr(int n, int min, int max, vi &l, vi &r) {
l.resize(n);
r.resize(n);
rep(i, n) {
l[i] = rand(min, max);
r[i] = l[i] + rand(0, max - l[i]);
}
}
//便利 汎用
template <typename V, typename T> int find(vector<V> &a, const T key) {
rep(i, sz(a)) if (a[i] == key) return i;
return -1;
}
template <typename V, typename T> P find(vector<vector<V>> &a, const T key) {
rep(i, sz(a)) rep(j, sz(a[0])) if (a[i][j] == key) return mp(i, j);
return mp(-1, -1);
}
template <typename V, typename U>
T find(vector<vector<vector<V>>> &a, const U key) {
rep(i, sz(a)) rep(j, sz(a[0]))
rep(k, sz(a[0][0])) if (a[i][j][k] == key) return mt(i, j, k);
return mt(-1, -1, -1);
}
template <typename V, typename T> int count(V &a, const T k) { return a == k; }
template <typename V, typename T> int count(vector<V> &a, const T k) {
int ret = 0;
fora(v, a) ret += count(v, k);
return ret;
}
template <typename V> int count_odd(V &a) { return a % 2; }
template <typename V> int count_odd(vector<V> &a) {
int ret = 0;
fora(v, a) ret += count_odd(v);
return ret;
}
template <typename V> int count_even(V &a) { return a % 2 == 0; }
template <typename V> int count_even(vector<V> &a) {
int ret = 0;
fora(v, a) ret += count_even(v);
return ret;
}
// algorythm
void iota(vector<int> &ve, int s, int n) {
ve.resize(n);
iota(all(ve), s);
}
vi iota(int s, int n) {
vi ve(n);
iota(all(ve), s);
return ve;
}
//便利 数学
int mod(int a, int m) { return (a % m + m) % m; }
int pow(int a) { return a * a; };
ll fact(int v) { return v <= 1 ? 1 : v * fact(v - 1); }
ll comi(int n, int r) {
assert(n < 100);
static vvi(pas, 100, 100);
if (pas[0][0])
return pas[n][r];
pas[0][0] = 1;
rep(i, 1, 100) {
pas[i][0] = 1;
rep(j, 1, i + 1) pas[i][j] = pas[i - 1][j - 1] + pas[i - 1][j];
}
return pas[n][r];
}
void ole() {
#ifdef _DEBUG
debugline("ole");
exit(0);
#endif
string a = "a";
rep(i, 30) a += a;
rep(i, 1 << 17) cout << a << endl;
cout << "OLE 出力長制限超過" << endl;
exit(0);
}
void tle() {
while (inf)
cout << inf << endl;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll gcd(vi b) {
ll res = b[0];
for (auto &&v : b)
res = gcd(v, res);
return res;
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll rev(ll a) {
ll res = 0;
while (a) {
res *= 10;
res += a % 10;
a /= 10;
}
return res;
}
template <class T> vector<T> rev(vector<T> &a) {
vector<T> ret = a;
reverse(all(ret));
return ret;
}
ll ceil(ll a, ll b) {
if (b == 0) {
debugline("ceil");
deb(a, b);
ole();
return -1;
} else
return (a + b - 1) / b;
}
ll sqrt(ll a) {
if (a < 0) {
debugline("sqrt");
deb(a);
ole();
}
ll res = (ll)std::sqrt(a);
while (res * res < a)
res++;
return res;
}
double log(double e, double x) { return log(x) / log(e); }
ll sig(ll t) { return (1 + t) * t / 2; }
ll sig(ll s, ll t) { return (s + t) * (t - s + 1) / 2; }
vi divisors(int v) {
vi res;
for (int i = 1; i <= sqrt(v); ++i) {
if (v % i == 0) {
res.pb(i);
if (i != v / i)
res.pb(v / i);
}
}
return res;
}
vi factorization(int v) {
int tv = v;
vi res;
if (isPrime.size() == 0)
setPrime();
for (auto &&p : primes) {
if (v % p == 0)
res.push_back(p);
while (v % p == 0) {
v /= p;
}
if (v == 1 || p * p > tv)
break;
}
if (v > 1)
res.pb(v);
return res;
}
unordered_map<int, int> factorizationMap(int v) {
int tv = v;
unordered_map<int, int> res;
if (isPrime.size() == 0)
setPrime();
for (auto &&p : primes) {
while (v % p == 0) {
res[p]++;
v /= p;
}
if (v == 1 || p * p > tv)
break;
}
if (v > 1)
res[v]++;
return res;
}
int get(int a, int keta) { return (a / (int)pow(10, keta)) % 10; }
int keta(int v) {
int cou = 0;
while (v) {
cou++, v %= 10;
}
return cou;
}
int dsum(int v) {
int ret = 0;
for (; v; v /= 10)
ret += v % 10;
return ret;
}
int sumd(int v) { return dsum(v); }
//変換系
template <class T, class U> vector<T> keys(vector<pair<T, U>> a) {
vector<T> res;
for (auto &&k : a)
res.pb(k.fi);
return res;
}
template <class T, class U> vector<U> keys(map<T, U> a) {
vector<U> res;
for (auto &&k : a)
res.pb(k.fi);
return res;
}
template <class T, class U> vector<U> keys(umap<T, U> a) {
vector<U> res;
for (auto &&k : a)
res.pb(k.fi);
return res;
}
template <class T, class U> vector<U> values(vector<pair<T, U>> a) {
vector<U> res;
for (auto &&k : a)
res.pb(k.se);
return res;
}
template <class T, class U> vector<T> values(map<T, U> a) {
vector<T> res;
for (auto &&k : a)
res.pb(k.se);
return res;
}
template <class T, class U> vector<T> values(umap<T, U> a) {
vector<T> res;
for (auto &&k : a)
res.pb(k.se);
return res;
}
vi list(int a) {
vi res;
while (a) {
res.insert(res.begin(), a % 10);
a /= 10;
}
return res;
}
template <class T, class U> bool chmax(T &a, const U &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class U> bool chmax(const U &b) { return chmax(ma, b); }
template <class T, class U> bool chmin(T &a, const U &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template <class U> bool chmin(const U &b) { return chmin(mi, b); }
#define chmi chmin
#define chma chmax
template <class T> T min(T a, signed b) { return a < b ? a : b; }
template <class T> T max(T a, signed b) { return a < b ? b : a; }
template <class T> T min(T a, T b, T c) {
return a >= b ? b >= c ? c : b : a >= c ? c : a;
}
template <class T> T max(T a, T b, T c) {
return a <= b ? b <= c ? c : b : a <= c ? c : a;
}
template <class T> T min(vector<T> a) { return *min_element(all(a)); }
template <class T> T min(vector<T> a, int n) {
return *min_element(a.begin(), a.begin() + min(n, sz(a)));
}
template <class T> T min(vector<T> a, int s, int n) {
return *min_element(a.begin() + s, a.begin() + min(n, sz(a)));
}
template <class T> T max(vector<T> a) { return *max_element(all(a)); }
template <class T> T max(vector<T> a, int n) {
return *max_element(a.begin(), a.begin() + min(n, sz(a)));
}
template <class T> T max(vector<T> a, int s, int n) {
return *max_element(a.begin() + s, a.begin() + min(n, sz(a)));
}
template <typename A, size_t N> A max(A (&a)[N]) {
A res = a[0];
rep(i, N) res = max(res, a[i]);
return res;
}
template <typename A, size_t N, size_t O> A max(A (&a)[N][O]) {
A res = max(a[0]);
rep(i, N) res = max(res, max(a[i]));
return res;
}
template <typename A, size_t N, size_t O, size_t P> A max(A (&a)[N][O][P]) {
A res = max(a[0]);
rep(i, N) res = max(res, max(a[i]));
return res;
}
template <typename A, size_t N, size_t O, size_t P, size_t Q>
A max(A (&a)[N][O][P][Q], const T &v) {
A res = max(a[0]);
rep(i, N) res = max(res, max(a[i]));
return res;
}
template <typename A, size_t N, size_t O, size_t P, size_t Q, size_t R>
A max(A (&a)[N][O][P][Q][R]) {
A res = max(a[0]);
rep(i, N) res = max(res, max(a[i]));
return res;
}
template <typename A, size_t N, size_t O, size_t P, size_t Q, size_t R,
size_t S>
A max(A (&a)[N][O][P][Q][R][S]) {
A res = max(a[0]);
rep(i, N) res = max(res, max(a[i]));
return res;
}
template <typename A, size_t N> A min(A (&a)[N]) {
A res = a[0];
rep(i, N) res = min(res, a[i]);
return res;
}
template <typename A, size_t N, size_t O> A min(A (&a)[N][O]) {
A res = min(a[0]);
rep(i, N) res = min(res, max(a[i]));
return res;
}
template <typename A, size_t N, size_t O, size_t P> A min(A (&a)[N][O][P]) {
A res = min(a[0]);
rep(i, N) res = min(res, min(a[i]));
return res;
}
template <typename A, size_t N, size_t O, size_t P, size_t Q>
A min(A (&a)[N][O][P][Q], const T &v) {
A res = min(a[0]);
rep(i, N) res = min(res, min(a[i]));
return res;
}
template <typename A, size_t N, size_t O, size_t P, size_t Q, size_t R>
A min(A (&a)[N][O][P][Q][R]) {
A res = min(a[0]);
rep(i, N) res = min(res, min(a[i]));
return res;
}
template <typename A, size_t N, size_t O, size_t P, size_t Q, size_t R,
size_t S>
A min(A (&a)[N][O][P][Q][R][S]) {
A res = min(a[0]);
rep(i, N) res = min(res, min(a[i]));
return res;
}
template <class T> T sum(vector<T> v, int len = -1) {
if (len == -1)
len = v.size();
T res = 0;
chmin(len, v.size());
rep(i, len) res += v[i];
return res;
}
template <class T> T sum(vector<vector<T>> &v, int h = -1, int w = -1) {
if (h == -1)
h = v.size();
if (w == -1)
w = v[0].size();
T res = 0;
chmin(h, v.size());
chmin(w, v[0].size());
rep(i, h) rep(j, w) res += v[i][j];
return res;
}
P sump(vp &v, int len = -1) {
if (len == -1)
len = v.size();
P res = {0, 0};
chmin(len, v.size());
rep(i, len) {
res.fi += v[i].fi;
res.se += v[i].se;
}
return res;
}
///要素が0の時、返り値は0か1か
template <class T> T mul(vector<T> &v, int len = -1) {
if (len == -1)
len = v.size();
T res = 1;
chmin(len, v.size());
rep(i, len) res *= v[i];
return res;
}
void clear(PQ &q) {
while (q.size())
q.pop();
}
template <class T> void clear(queue<T> &q) {
while (q.size())
q.pop();
}
template <class T> T *negarr(int size) {
T *body = (T *)malloc((size * 2 + 1) * sizeof(T));
return body + size;
}
template <class T> T *negarr2(int h, int w) {
double **dummy1 = new double *[2 * h + 1];
double *dummy2 = new double[(2 * h + 1) * (2 * w + 1)];
dummy1[0] = dummy2 + w;
for (int i = 1; i <= 2 * h + 1; i++) {
dummy1[i] = dummy1[i - 1] + 2 * w + 1;
}
double **a = dummy1 + h;
}
// imoは0-indexed
// ruiは1-indexed
template <class T> vector<T> imo(vector<T> &v) {
vector<T> ret = v;
rep(i, sz(ret) - 1) ret[i + 1] += ret[i];
return ret;
}
template <class T> vector<T> imomi(vector<T> &v) {
vector<T> ret = v;
rep(i, sz(ret) - 1) chmin(ret[i + 1], ret[i]);
return ret;
}
template <class T> struct ruic {
const vector<T> rui;
ruic(vector<T> &ru) : rui(ru) {}
T operator()(int l, int r) {
assert(l <= r);
return rui[r] - rui[l];
}
T operator[](int i) { return rui[i]; }
};
template <class T> struct rruic {
const T *rrui;
rruic(T *ru) : rrui(ru) {}
// n-1から-1へ
T operator()(int l, int r) {
assert(l >= r);
return rrui[r] - rrui[l];
}
T operator[](int i) { return rrui[i]; }
};
// template<class T> vector<T> ruiv(vector<T> &a)
template <class T> ruic<T> ruiv(vector<T> &a) {
vector<T> res(a.size() + 1);
rep(i, a.size()) res[i + 1] = res[i] + a[i];
return ruic<T>(res);
}
template <class T> vector<T> ruim(vector<T> &a) {
vector<T> res(a.size() + 1, 1);
rep(i, a.size()) res[i + 1] = res[i] * a[i];
return res;
}
// template<class T> T *rrui(vector<T> &a) {
//右から左にかけての半開区間 (-1 n-1]
template <class T> rruic<T> rrui(vector<T> &a) {
int len = a.size();
T *body = (T *)malloc((len + 1) * sizeof(T));
T *res = body + 1;
rer(i, len - 1) res[i - 1] = res[i] + a[i];
return rruic<T>(res);
}
//掛け算
template <class T> T *rruim(vector<T> &a) {
int len = a.size();
T *body = (T *)malloc((len + 1) * sizeof(T));
T *res = body + 1;
res[len - 1] = 1;
rer(i, len - 1) res[i - 1] = res[i] * a[i];
return res;
}
template <class T, class U> void inc(T &a, U v = 1) { a += v; }
template <class T, class U> void inc(vector<T> &a, U v = 1) {
for (auto &u : a)
inc(u, v);
}
template <class T> void inc(vector<T> &a) {
for (auto &u : a)
inc(u, 1);
}
template <class T, class U> void dec(T &a, U v = 1) { a -= v; }
template <class T, class U> void dec(vector<T> &a, U v = 1) {
for (auto &u : a)
dec(u, v);
}
template <class T> void dec(vector<T> &a) {
for (auto &u : a)
dec(u, 1);
}
inline bool inside(int h, int w, int H, int W) {
return h >= 0 && w >= 0 && h < H && w < W;
}
ll u(ll a) { return a < 0 ? 0 : a; }
template <class T> vector<T> u(const vector<T> &a) {
vector<T> ret = a;
fora(v, ret) v = u(v);
return ret;
}
#define MIN(a) numeric_limits<a>::min()
#define MAX(a) numeric_limits<a>::max()
ll goldd(ll left, ll right, function<ll(ll)> calc) {
double GRATIO = 1.6180339887498948482045868343656;
ll lm = left + (ll)((right - left) / (GRATIO + 1.0));
ll rm = lm + (ll)((right - lm) / (GRATIO + 1.0));
ll fl = calc(lm);
ll fr = calc(rm);
while (right - left > 10) {
if (fl < fr) {
right = rm;
rm = lm;
fr = fl;
lm = left + (ll)((right - left) / (GRATIO + 1.0));
fl = calc(lm);
} else {
left = lm;
lm = rm;
fl = fr;
rm = lm + (ll)((right - lm) / (GRATIO + 1.0));
fr = calc(rm);
}
}
ll minScore = MAX(ll);
ll resIndex = left;
for (ll i = left; i < right + 1; i++) {
ll score = calc(i);
if (minScore > score) {
minScore = score;
resIndex = i;
}
}
return resIndex;
}
ll goldt(ll left, ll right, function<ll(ll)> calc) {
double GRATIO = 1.6180339887498948482045868343656;
ll lm = left + (ll)((right - left) / (GRATIO + 1.0));
ll rm = lm + (ll)((right - lm) / (GRATIO + 1.0));
ll fl = calc(lm);
ll fr = calc(rm);
while (right - left > 10) {
if (fl > fr) {
right = rm;
rm = lm;
fr = fl;
lm = left + (ll)((right - left) / (GRATIO + 1.0));
fl = calc(lm);
} else {
left = lm;
lm = rm;
fl = fr;
rm = lm + (ll)((right - lm) / (GRATIO + 1.0));
fr = calc(rm);
}
}
if (left > right) {
ll l = left;
left = right;
right = l;
}
ll maxScore = MIN(ll);
ll resIndex = left;
for (ll i = left; i < right + 1; i++) {
ll score = calc(i);
if (maxScore < score) {
maxScore = score;
resIndex = i;
}
}
return resIndex;
}
template <class T> T min(vector<vector<T>> &a) {
T res = MAX(T);
rep(i, a.size()) chmin(res, *min_element(all(a[i])));
return res;
}
template <class T> T max(vector<vector<T>> &a) {
T res = MIN(T);
rep(i, a.size()) chmax(res, *max_element(all(a[i])));
return res;
}
bool bget(ll m, int keta) { return (m >> keta) & 1; }
int bget(ll m, int keta, int sinsuu) {
m /= (ll)pow(sinsuu, keta);
return m % sinsuu;
}
inline ll bit(int n) { return (1LL << (n)); }
inline ll bit(int n, int sinsuu) { return (ll)pow(sinsuu, n); }
// int bcou(ll m) { return __builtin_popcount(m & 0xFFFFFFFF) +
// __builtin_popcount(m >> 32); } #define bcou __builtin_popcountll
//初期化は0を渡す
ll nextComb(ll &mask, int n, int r) {
if (!mask)
return mask = (1LL << r) - 1;
ll x = mask & -mask; //最下位の1
ll y = mask + x; //連続した下の1を繰り上がらせる
ll res = ((mask & ~y) / x >> 1) | y;
if (bget(res, n))
return mask = 0;
else
return mask = res;
}
// n桁以下でビットがr個立っているもののvectorを返す
vl bitCombList(int n, int r) {
vl res;
int m = 0;
while (nextComb(m, n, r)) {
res.pb(m);
}
return res;
}
//大文字小文字を区別する
int altoiaZ(char c) {
if ('A' <= c && c <= 'Z')
return c - 'A';
return c - 'a' + 26;
}
char itoalaZ(int i) {
if (i < 26)
return 'A' + i;
return 'a' + i - 26;
}
// aもAも0を返す 基本小文字
int altoi(char c) {
if ('A' <= c && c <= 'Z')
return c - 'A';
return c - 'a';
}
char itoal(int i) { return 'a' + i; }
int ctoi(char c) { return c - '0'; }
char itoc(int i) { return i + '0'; }
int vtoi(vi &v) {
int res = 0;
if (sz(v) > 18) {
debugline("vtoi");
deb(sz(v));
ole();
}
rep(i, sz(v)) {
res *= 10;
res += v[i];
}
return res;
}
vi itov(int i) {
vi res;
while (i) {
res.pb(i % 10);
i /= 10;
}
rev(res);
return res;
}
vector<vector<int>> ctoi(vector<vector<char>> s, char c) {
int n = sz(s), m = sz(s[0]);
vector<vector<int>> res(n, vector<int>(m));
rep(i, n) rep(j, m) res[i][j] = s[i][j] == c;
return res;
}
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
void compress(vi &a) {
vi b;
int len = a.size();
for (int i = 0; i < len; ++i) {
b.push_back(a[i]);
}
sort(b);
UNIQUE(b);
for (int i = 0; i < len; ++i) {
a[i] = lower_bound(all(b), a[i]) - b.begin();
}
}
void compress(int a[], int len) {
vi b;
for (int i = 0; i < len; ++i) {
b.push_back(a[i]);
}
sort(b);
UNIQUE(b);
for (int i = 0; i < len; ++i) {
a[i] = lower_bound(all(b), a[i]) - b.begin();
}
}
//要素が見つからなかったときに困る
#define binarySearch(a, v) (binary_search(all(a), v))
#define lowerIndex(a, v) (lower_bound(all(a), v) - a.begin())
#define lowerBound(a, v) (*lower_bound(all(a), v))
#define upperIndex(a, v) (upper_bound(all(a), v) - a.begin())
#define upperBound(a, v) (*upper_bound(all(a), v))
#define ans(a) \
cout << a << endl; \
continue;
#define poll(a) \
q.front(); \
q.pop()
#define dpoll(a) \
q.front(); \
q.pop_front()
#define pollLast(a) \
q.back(); \
q.pop_back()
#define pollBack(a) \
q.back(); \
q.pop_back()
template <class T> inline void fin(T s) { cout << s << endl, exit(0); }
template <class T> struct edge {
int from, to;
T cost;
int id;
int type;
edge(int f, int t, T c = 1, int id = -1, int ty = -1)
: from(f), to(t), cost(c), id(id), type(ty) {}
bool operator<(const edge &b) const { return cost < b.cost; }
bool operator>(const edge &b) const { return cost > b.cost; }
};
template <typename T> class graph {
protected:
vector<bool> _used;
public:
vector<vector<edge<T>>> g;
vector<edge<T>> edges;
int n;
graph(int n) : n(n) { g.resize(n), _used.resize(n); }
void clear() { g.clear(), edges.clear(); }
void resize(int n) {
this->n = n;
g.resize(n);
_used.resize(n);
}
int size() { return g.size(); }
vector<edge<T>> &operator[](int i) { return g[i]; }
virtual void add(int from, int to, T cost, int id, int ty) = 0;
virtual bool used(edge<T> &e) = 0;
virtual bool used(int id) = 0;
virtual void del(edge<T> &e) = 0;
virtual void del(int id) = 0;
};
template <typename T = ll> class digraph : public graph<T> {
public:
using graph<T>::g;
using graph<T>::n;
using graph<T>::edges;
using graph<T>::_used;
digraph(int n) : graph<T>(n) {}
void add(int f, int t, T cost = 1, int id = -1, int ty = -1) {
if (!(0 <= f && f < n && 0 <= t && t < n)) {
debugline("digraph add");
deb(f, t, cost, id, ty);
ole();
}
if (id == -1)
id = edges.size();
g[f].emplace_back(f, t, cost, id, ty);
edges.emplace_back(f, t, cost, id, ty);
}
bool used(edge<T> &e) { return _used[e.id]; }
bool used(int id) { return _used[id]; }
void del(edge<T> &e) { _used[e.id] = _used[e.id ^ 1] = 1; }
void del(int id) { _used[id] = _used[id ^ 1] = 1; }
};
template <class T = int> class undigraph : public graph<T> {
public:
using graph<T>::g;
using graph<T>::n;
using graph<T>::edges;
using graph<T>::_used;
undigraph(int n) : graph<T>(n) {}
void add(int f, int t, T cost = 1, int id = -1, int ty = -1) {
if (!(0 <= f && f < n && 0 <= t && t < n)) {
debugline("undigraph add");
deb(f, t, cost, id, ty);
ole();
}
if (id == -1)
id = edges.size();
g[f].emplace_back(f, t, cost, id, ty);
g[t].emplace_back(t, f, cost, id + 1, ty);
edges.emplace_back(f, t, cost, id, ty);
edges.emplace_back(t, f, cost, id + 1, ty);
}
void add(edge<T> &e) {
int f = e.from, t = e.to, ty = e.type;
T cost = e.cost;
add(f, t, cost, ty);
}
bool used(edge<T> &e) { return _used[e.id]; }
bool used(int id) { return _used[id]; }
void del(edge<T> &e) { _used[e.id] = _used[e.id ^ 1] = 1; }
void del(int id) { _used[id] = _used[id ^ 1] = 1; }
};
template <class T>
vector<T> dijkstra(const graph<T> &g, int s, int cant_arrive = -1) {
if (!(0 <= s && s < g.n)) {
debugline("dijkstra");
deb(s, g.n);
ole();
}
T initValue = MAX(T);
vector<T> dis(g.n, initValue);
priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> q;
dis[s] = 0;
q.emplace(0, s);
while (q.size()) {
T nowc = q.top().fi;
int i = q.top().se;
q.pop();
if (dis[i] != nowc)
continue;
for (auto &&e : g.g[i]) {
int to = e.to;
T cost = nowc + e.cost;
if (dis[to] > cost) {
dis[to] = cost;
q.emplace(dis[to], to);
}
}
}
//基本、たどり着かないなら-1
if (cant_arrive == -1)
for (auto &&d : dis)
if (d == initValue)
d = -1;
return dis;
}
template <class T>
vector<vector<T>> warshall(const graph<T> &g, int cant_arrive = -1) {
int n = g.n;
vector<vector<T>> dis(n, vector<T>(n, linf));
fora(e, g.edges) chmin(dis[e.from][e.to], e.cost);
rep(i, n) dis[i][i] = 0;
rep(k, n) rep(i, n) rep(j, n) chmin(dis[i][j], dis[i][k] + dis[k][j]);
//基本、たどり着かないなら-1
if (cant_arrive == -1)
rep(i, n) rep(j, n) if (dis[i][j] == linf) dis[i][j] = -1;
return dis;
}
template <class T = int> class tree : public undigraph<T> {
public:
using undigraph<T>::g;
using undigraph<T>::n;
using undigraph<T>::edges;
using undigraph<T>::_used;
vi dep;
vi disv;
private:
bool never = 1;
int root = -1;
vector<vector<int>> par;
bool costallone;
void dfs(int v, int p, int d) {
dep[v] = d;
par[0][v] = p;
int lim = (*this)[v].size();
for (int i = 0; i < lim; i++) {
int t = g[v][i].to;
if (t == p)
con;
dfs(t, v, d + 1);
}
}
void built() {
never = 0;
n = g.size();
par.assign(30, vi(n));
dep.resize(n);
costallone = 1;
fora(e, edges) if (e.cost != 1) costallone = 0;
dfs(root, -1, 0);
rep(k, par.size() - 1) {
rep(i, n) {
if (par[k][i] == -1)
par[k + 1][i] = -1;
else
par[k + 1][i] = par[k][par[k][i]];
}
}
if (costallone)
disv = dep;
else
disv = dijkstra(*this, root);
}
int _lca(int u, int v) {
if (dep[u] > dep[v])
swap(u, v);
rep(k, par.size()) {
if ((dep[u] - dep[v]) >> k & 1) {
v = par[k][v];
}
}
if (u == v)
return u;
rer(k, par.size() - 1) {
if (par[k][u] != par[k][v]) {
u = par[k][u];
v = par[k][v];
}
}
return par[0][u];
}
int _dis(int u, int v) {
int p = _lca(u, v);
return disv[u] + disv[v] - disv[p] * 2;
}
public:
tree(int n, int root = 0) : undigraph<T>(n), root(root) {}
bool leaf(int v) { return sz(g[v]) == 1 && v != root; }
int dis(int u, int v) {
if (never) {
built();
}
return _dis(u, v);
}
int lca(int u, int v) {
if (never) {
built();
}
return _lca(u, v);
}
};
//辺によりメモリを大量消費
// よってedgesを消している
//頂点10^6でメモリを190MB(制限の8割)使う
//軽量化のため、辺を持たないbig gridクラスがあってもいいかもしれない
//
template <class T = int> class grid_k6 : public undigraph<T> {
public:
using undigraph<T>::g;
using undigraph<T>::n;
using undigraph<T>::edges;
using undigraph<T>::_used;
int H, W;
int eid = 0;
void add(int f, int t, T cost = 1, int id = -1, int ty = -1) {
if (!(0 <= f && f < n && 0 <= t && t < n)) {
debugline("grid_k6 add");
deb(f, t, cost, id, ty);
ole();
}
g[f].emplace_back(f, t, cost, eid++, ty);
g[t].emplace_back(t, f, cost, eid++, ty);
}
int getid(int h, int w) {
if (!inside(h, w, H, W))
return -1;
return W * h + w;
}
P get2(int id) { return mp(id / W, id % W); }
P operator()(int id) { return get2(id); }
int operator()(int h, int w) { return getid(h, w); }
grid_k6(int H, int W) : H(H), W(W), undigraph<T>(H * W) {
rep(h, H) {
rep(w, W) {
int f = getid(h, w);
if (w + 1 < W)
add(f, getid(h, w + 1));
if (h + 1 < H)
add(f, getid(h + 1, w));
}
}
}
grid_k6(_vvc ba, char wall = '#')
: H(sz(ba)), W(sz(ba[0])), undigraph<T>(sz(ba) * sz(ba[0])) {
rep(h, H) {
rep(w, W) {
if (ba[h][w] == wall)
con;
int f = getid(h, w);
if (w + 1 < W && ba[h][w + 1] != wall) {
add(f, getid(h, w + 1));
}
if (h + 1 < H && ba[h + 1][w] != wall) {
add(f, getid(h + 1, w));
}
}
}
}
void add(int fh, int fw, int th, int tw) {
add(getid(fh, fw), getid(th, tw));
}
};
//左上から右下に移動できる
template <class T = int> class digrid_k6 : public digraph<T> {
public:
using digraph<T>::g;
using digraph<T>::n;
using digraph<T>::edges;
using digraph<T>::_used;
int H, W;
int eid = 0;
void add(int f, int t, T cost = 1, int id = -1, int ty = -1) {
if (!(0 <= f && f < n && 0 <= t && t < n)) {
debugline("digrid_k6 add");
deb(f, t, cost, id, ty);
ole();
}
g[f].emplace_back(f, t, cost, eid++, ty);
}
int getid(int h, int w) {
if (!inside(h, w, H, W))
return -1;
return W * h + w;
}
P get2(int id) { return mp(id / W, id % W); }
P operator()(int id) { return get2(id); }
int operator()(int h, int w) { return getid(h, w); }
digrid_k6(int H, int W) : H(H), W(W), digraph<T>(H * W) {
rep(h, H) {
rep(w, W) {
int f = getid(h, w);
if (w + 1 < W)
add(f, getid(h, w + 1));
if (h + 1 < H)
add(f, getid(h + 1, w));
}
}
}
digrid_k6(_vvc ba, char wall = '#')
: H(sz(ba)), W(sz(ba[0])), digraph<T>(sz(ba) * sz(ba[0])) {
rep(h, H) {
rep(w, W) {
if (ba[h][w] == wall)
con;
int f = getid(h, w);
if (w + 1 < W && ba[h][w + 1] != wall) {
add(f, getid(h, w + 1));
}
if (h + 1 < H && ba[h + 1][w] != wall) {
add(f, getid(h + 1, w));
}
}
}
}
void add(int fh, int fw, int th, int tw) {
add(getid(fh, fw), getid(th, tw));
}
};
template <class T> bool nibu(const graph<T> &g) {
if (g.edges.size() == 0)
return true;
UnionFind uf(g.n * 2);
for (auto &&e : g.edges)
uf.unite(e.from, e.to + g.n), uf.unite(e.from + g.n, e.to);
rep(i, g.n) if (uf.same(i, i + g.n)) return 0;
return 1;
}
//二部グラフを色分けした際の頂点数を返す
template <class T> vp nibug(graph<T> &g) {
vp cg;
if (!nibu(g)) {
debugline("nibu");
ole();
}
int _n = g.size();
vb _was(_n);
queue<P> q;
rep(i, _n) {
if (_was[i])
continue;
q.push(mp(i, 1));
_was[i] = 1;
int red = 0;
int coun = 0;
while (q.size()) {
int now = q.front().fi;
int col = q.front().se;
red += col;
coun++;
q.pop();
forg(gi, g[now]) {
if (_was[t])
continue;
q.push(mp(t, col ^ 1));
_was[t] = 1;
}
}
cg.push_back(mp(red, coun - red));
}
return cg;
}
//機能拡張
vp vtop(vi &a, vi &b) {
vp res(sz(a));
rep(i, sz(a)) res[i] = mp(a[i], b[i]);
return res;
}
void ptov(vp &p, vi &a, vi &b) {
a.resize(sz(p));
b.resize(sz(p));
rep(i, sz(p)) a[i] = p[i].fi, b[i] = p[i].se;
}
template <typename _CharT, typename _Traits, typename _Alloc>
basic_string<_CharT, _Traits, _Alloc>
operator+(const basic_string<_CharT, _Traits, _Alloc> &__lhs, const int __rv) {
basic_string<_CharT, _Traits, _Alloc> __str(__lhs);
__str.append(to_string(__rv));
return __str;
}
template <typename _CharT, typename _Traits, typename _Alloc>
void operator+=(basic_string<_CharT, _Traits, _Alloc> &__lhs, const int __rv) {
__lhs += to_string(__rv);
}
template <typename _CharT, typename _Traits, typename _Alloc>
basic_string<_CharT, _Traits, _Alloc>
operator+(const basic_string<_CharT, _Traits, _Alloc> &__lhs,
const signed __rv) {
basic_string<_CharT, _Traits, _Alloc> __str(__lhs);
__str.append(to_string(__rv));
return __str;
}
template <typename _CharT, typename _Traits, typename _Alloc>
void operator+=(basic_string<_CharT, _Traits, _Alloc> &__lhs,
const signed __rv) {
__lhs += to_string(__rv);
}
template <class T, class U> void operator+=(queue<T> &a, U v) { a.push(v); }
template <class T, class U>
priority_queue<T, vector<T>, greater<T>> &
operator+=(priority_queue<T, vector<T>, greater<T>> &a, U v) {
a.push(v);
return a;
}
template <class T, class U>
priority_queue<T> &operator+=(priority_queue<T> &a, U v) {
a.push(v);
return a;
}
template <class T, class U> set<T> &operator+=(set<T> &a, U v) {
a.insert(v);
return a;
}
template <class T, class U>
set<T, greater<T>> &operator+=(set<T, greater<T>> &a, U v) {
a.insert(v);
return a;
}
template <class T, class U> vector<T> &operator+=(vector<T> &a, U v) {
a.pb(v);
return a;
}
template <class T, class U> vector<T> operator+(const vector<T> &a, U v) {
vector<T> ret = a;
ret += v;
return ret;
}
template <class T, class U> vector<T> operator+(U v, const vector<T> &a) {
vector<T> ret = a;
ret.insert(ret.begin(), v);
return ret;
}
template <class T> vector<T> &operator+=(vector<T> &a, vector<T> &b) {
a.pb(b);
return a;
}
template <class T, class U>
vector<T> &operator+=(vector<T> &a, initializer_list<U> v) {
for (auto &&va : v)
a.pb(va);
return a;
}
template <class T> vector<T> &operator-=(vector<T> &a, vector<T> &b) {
if (sz(a) != sz(b)) {
debugline("vector<T> operator-=");
deb(a);
deb(b);
ole();
}
rep(i, sz(a)) a[i] -= b[i];
return a;
}
template <class T> vector<T> &operator-(vector<T> &a, vector<T> &b) {
if (sz(a) != sz(b)) {
debugline("vector<T> operator-");
deb(a);
deb(b);
ole();
}
vector<T> res;
rep(i, sz(a)) res[i] = a[i] - b[i];
return res;
}
template <typename T> void remove(vector<T> &v, unsigned int i) {
v.erase(v.begin() + i);
}
template <typename T>
void remove(vector<T> &v, unsigned int s, unsigned int e) {
v.erase(v.begin() + s, v.begin() + e);
}
template <typename T>
void removen(vector<T> &v, unsigned int s, unsigned int n) {
v.erase(v.begin() + s, v.begin() + s + n);
}
template <typename T> void erase(vector<T> &v, unsigned int i) {
v.erase(v.begin() + i);
}
template <typename T> void erase(vector<T> &v, unsigned int s, unsigned int e) {
v.erase(v.begin() + s, v.begin() + e);
}
template <typename T>
void erasen(vector<T> &v, unsigned int s, unsigned int n) {
v.erase(v.begin() + s, v.begin() + s + n);
}
template <typename T, typename U>
void insert(vector<T> &v, unsigned int i, U t) {
v.insert(v.begin() + i, t);
}
template <typename T, typename U> void push_front(vector<T> &v, U t) {
v.insert(v.begin(), t);
}
template <typename T, typename U>
void insert(vector<T> &v, unsigned int i, vector<T> list) {
for (auto &&va : list)
v.insert(v.begin() + i++, va);
}
template <typename T, typename U>
void insert(vector<T> &v, initializer_list<U> list) {
for (auto &&va : list)
v.pb(va);
}
template <typename T, typename U>
void insert(vector<T> &v, unsigned int i, initializer_list<U> list) {
for (auto &&va : list)
v.insert(v.begin() + i++, va);
}
template <typename T> void insert(set<T> &v, vector<T> list) {
for (auto &&va : list)
v.insert(va);
}
template <typename T> void insert(set<T> &v, initializer_list<T> list) {
for (auto &&va : list)
v.insert(va);
}
//閉路がなければtrue
bool topo(vi &res, digraph<int> &g) {
int n = g.g.size();
vi nyu(n);
rep(i, n) for (auto &&e : g[i]) nyu[e.to]++;
queue<int> st;
rep(i, n) if (nyu[i] == 0) st.push(i);
while (st.size()) {
int v = st.front();
st.pop();
res.pb(v);
fora(e, g[v]) if (--nyu[e.to] == 0) st.push(e.to);
}
return res.size() == n;
}
//辞書順最小トポロジカルソート
bool topos(vi &res, digraph<int> &g) {
int n = g.g.size();
vi nyu(n);
rep(i, n) for (auto &&e : g[i]) nyu[e.to]++;
//小さい順
priority_queue<int, vector<int>, greater<int>> q;
rep(i, n) if (nyu[i] == 0) q.push(i);
while (q.size()) {
int i = q.top();
q.pop();
res.pb(i);
fora(e, g[i]) if (--nyu[e.to] == 0) q.push(e.to);
}
return res.size() == n;
}
vector<string> split(const string a, const char deli) {
string b = a + deli;
int l = 0, r = 0, n = b.size();
vector<string> res;
rep(i, n) {
if (b[i] == deli) {
r = i;
if (l < r)
res.push_back(b.substr(l, r - l));
l = i + 1;
}
}
return res;
}
vector<string> split(const string a, const string deli) {
string b = a + deli;
int l = 0, r = 0, n = b.size(), dn = deli.size();
vector<string> res;
rep(i, n) {
if (i + dn <= n && b.substr(i, i + dn) == deli) {
r = i;
if (l < r)
res.push_back(b.substr(l, r - l));
i += dn - 1;
l = i + 1;
}
}
return res;
}
void yn(bool a) {
if (a)
cout << "yes" << endl;
else
cout << "no" << endl;
}
void Yn(bool a) {
if (a)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
void YN(bool a) {
if (a)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
void fyn(bool a) {
if (a)
cout << "yes" << endl;
else
cout << "no" << endl;
exit(0);
}
void fYn(bool a) {
if (a)
cout << "Yes" << endl;
else
cout << "No" << endl;
exit(0);
}
void fYN(bool a) {
if (a)
cout << "YES" << endl;
else
cout << "NO" << endl;
exit(0);
}
void Possible(bool a) {
if (a)
cout << "Possible" << endl;
else
cout << "Impossible" << endl;
exit(0);
}
int n, a, b;
vi res;
//最下位ビット
int lbit(int n) { return n & -n; }
//最上位ビット
int hbit(int n) {
n |= (n >> 1);
n |= (n >> 2);
n |= (n >> 4);
n |= (n >> 8);
n |= (n >> 16);
n |= (n >> 32);
return n - (n >> 1);
}
#define bcou __builtin_popcountll
void dfs(int s, int t, int cuts) {
// t以外に行ける場所がない
if (bcou(cuts) == n - 1) {
res.pb(s);
res.pb(t);
return;
}
// s -> t で使うことになる軸の集合
int need = s ^ t;
// needに含まれる軸ncutで切断すれば、sとtを分離できる
int ncut = lbit(need);
cuts |= ncut;
// sとtを分離した時、s側で使える軸の集合
int cand = ((1 << n) - 1) ^ cuts;
int mid = s ^ lbit(cand);
// t側のスタート地点がtになってはいけない
if ((mid ^ ncut) == t) {
mid = s ^ hbit(cand);
}
//二つの部分問題に帰着できた
dfs(s, mid, cuts);
// ncutでsとtを分離したため、mid^ncutでt側に移動できる
dfs(mid ^ ncut, t, cuts);
}
void solve() {
cin >> n >> a >> b;
if (bcou(a ^ b) % 2 == 0) {
cout << "NO" << endl;
return;
}
cout << "YES" << endl;
dfs(a, b, 0);
cout << res << endl;
}
int my(int n, vi a) { return 0; }
int sister(int n, vi a) { return 0; }
signed main() {
solve();
#define _arg n, a
// cin>>n;
// na(a,n);
// my(_arg);
// cout << my(_arg) << endl;
#ifdef _DEBUG
bool bad = 0;
for (int i = 0, ok = 1; i < k5 && ok; i++) {
int n = rand(1, 3);
vi a = ranv(n, 1, 10);
int myres = my(_arg);
int res = sister(_arg);
ok = myres == res;
if (!ok) {
cout << n << endl;
cout << a << endl;
cout << "正解 : " << res << endl;
cout << "出力 : " << myres << endl;
bad = 1;
break;
}
}
#endif
return 0;
};
| [
"control_flow.branch.if.condition.change"
] | 917,168 | 917,169 | u986437843 | cpp |
p03097 | #include <algorithm>
#include <cstdio>
using namespace std;
int gi() {
int x = 0, w = 1;
char ch = getchar();
while ((ch < '0' || ch > '9') && ch != '-')
ch = getchar();
if (ch == '-')
w = 0, ch = getchar();
while (ch >= '0' && ch <= '9')
x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
return w ? x : -x;
}
#define pc(x) __builtin_popcount(x)
int n, A, B, all;
void dfs(int x, int y, int ban) {
if (pc(ban ^ all) == 1) {
printf("%d %d ", y, x ^ y);
return;
}
for (int i = 0; i < n; ++i)
if ((~ban >> i & 1) && (x >> i & 1))
for (int j = 0; j < i; ++j)
if ((~ban >> j & 1) && i != j) {
dfs(1 << j, y, ban | 1 << i);
dfs(x ^ (1 << i) ^ (1 << j), y ^ (1 << i) ^ (1 << j), ban | 1 << i);
return;
}
}
int main() {
n = gi(), A = gi(), B = gi(), all = (1 << n) - 1;
if (pc(A ^ B) & 1)
puts("YES"), dfs(A ^ B, A, 0);
else
puts("NO");
return 0;
} | #include <algorithm>
#include <cstdio>
using namespace std;
int gi() {
int x = 0, w = 1;
char ch = getchar();
while ((ch < '0' || ch > '9') && ch != '-')
ch = getchar();
if (ch == '-')
w = 0, ch = getchar();
while (ch >= '0' && ch <= '9')
x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
return w ? x : -x;
}
#define pc(x) __builtin_popcount(x)
int n, A, B, all;
void dfs(int x, int y, int ban) {
if (pc(ban ^ all) == 1) {
printf("%d %d ", y, x ^ y);
return;
}
for (int i = 0; i < n; ++i)
if ((~ban >> i & 1) && (x >> i & 1))
for (int j = 0; j < n; ++j)
if ((~ban >> j & 1) && i != j) {
dfs(1 << j, y, ban | 1 << i);
dfs(x ^ (1 << i) ^ (1 << j), y ^ (1 << i) ^ (1 << j), ban | 1 << i);
return;
}
}
int main() {
n = gi(), A = gi(), B = gi(), all = (1 << n) - 1;
if (pc(A ^ B) & 1)
puts("YES"), dfs(A ^ B, A, 0);
else
puts("NO");
return 0;
} | [
"identifier.change",
"control_flow.branch.if.condition.change"
] | 917,180 | 917,181 | u755542878 | cpp |
p03097 | #include <cstdio>
#include <ctime>
#include <random>
using namespace std;
void swap(int &l, int &r) {
int tmp = l;
l = r;
r = tmp;
}
int insert_at(int pos, int bit, int n) {
int mask = ((1 << (pos + 1)) - 1);
int n_ = (n << 1) ^ ((n << 1) & mask);
n_ |= bit << pos;
n_ |= n & (mask >> 1);
return n_;
}
int remove_at(int pos, int n) {
// if (n == 0) return pos >> 1;
int mask = ((1 << (pos + 1)) - 1);
int n_ = (n ^ (n & mask)) >> 1;
n_ |= n & (mask >> 1);
return n_;
}
int result[1 << 17];
void construct(int pos, int left, int right, int size) {
// printf("construct(%d, %d, %d, %d)\n", pos, left, right, size);
if (size == 1) {
result[pos] = left;
result[pos + 1] = right;
return;
}
int common = 0;
int l = left;
int r = right;
int left_distinct_ones = 0;
for (int i = 0; i < size; i++) {
int c = (l & 1) ^ (r & 1) ^ 1;
common |= c << i;
if (c != 1) {
left_distinct_ones += l & 1;
}
l >>= 1;
r >>= 1;
}
bool swapped = false;
// printf("left = %d, right = %d\n", left, right);
if ((left_distinct_ones & 1) == 0) {
swap(left, right);
swapped = true;
// printf("swapped; left = %d, right = %d\n", left, right);
}
int d = common;
// printf("common = %d\n", d);
int left_distinct = left & (((1 << size) - 1) ^ common);
// printf("left_distinct = %d\n", left_distinct);
int left_distinct_lsb = 0;
while ((left_distinct & 1) == 0) {
left_distinct >>= 1;
left_distinct_lsb++;
}
// int left_ =
// ((left>>1)&(~((1<<(left_distinct_lsb+1))-1)))|(left&((1<<(left_distinct_lsb+1))-1));
int left_ = remove_at(left_distinct_lsb, left);
int right_ = remove_at(left_distinct_lsb, right);
int middle;
int common_ = remove_at(left_distinct_lsb, common);
int b = common_;
// printf("common_ = %d\n", b);
if (common == 0) {
middle = left_ ^ right_;
// diff(middle, left_) = 0 (mod 2)
// diff(middle, right_) = 0 (mod 2)
middle &= middle - 1;
// printf("no common\n");
} else {
middle = left_ ^ right_;
middle |= left_ & common_;
middle ^= common_ ^ (common_ & (common_ - 1));
}
// printf("%d\n", common_^(common_&(common_-1)));
// printf("left_ = %d, right_ = %d, middle = %d\n", left_, right_, middle);
if (swapped) {
construct(pos, right_, middle, size - 1);
construct(pos + (1 << (size - 1)), middle, left_, size - 1);
for (int i = pos; i < pos + (1 << (size - 1)); i++) {
result[i] = insert_at(left_distinct_lsb, 0, result[i]);
result[i + (1 << (size - 1))] =
insert_at(left_distinct_lsb, 1, result[i + (1 << (size - 1))]);
}
} else {
construct(pos, left_, middle, size - 1);
construct(pos + (1 << (size - 1)), middle, right_, size - 1);
for (int i = pos; i < pos + (1 << (size - 1)); i++) {
result[i] = insert_at(left_distinct_lsb, 1, result[i]);
result[i + (1 << (size - 1))] =
insert_at(left_distinct_lsb, 0, result[i + (1 << (size - 1))]);
}
}
}
int main() {
int n, a, b;
scanf("%d %d %d", &n, &a, &b);
int distinct = a ^ b;
int diff = 0;
while (distinct) {
diff += distinct & 1;
distinct >>= 1;
}
if ((diff & 1) == 0) {
printf("NO\n");
return 0;
}
construct(0, a, b, n);
printf("YES\n");
int i;
for (i = 0; i < (1 << n) - 1; i++) {
printf("%d ", result[i]);
}
printf("%d", result[i + 1]);
return 0;
}
| #include <cstdio>
#include <ctime>
#include <random>
using namespace std;
void swap(int &l, int &r) {
int tmp = l;
l = r;
r = tmp;
}
int insert_at(int pos, int bit, int n) {
int mask = ((1 << (pos + 1)) - 1);
int n_ = (n << 1) ^ ((n << 1) & mask);
n_ |= bit << pos;
n_ |= n & (mask >> 1);
return n_;
}
int remove_at(int pos, int n) {
// if (n == 0) return pos >> 1;
int mask = ((1 << (pos + 1)) - 1);
int n_ = (n ^ (n & mask)) >> 1;
n_ |= n & (mask >> 1);
return n_;
}
int result[1 << 17];
void construct(int pos, int left, int right, int size) {
// printf("construct(%d, %d, %d, %d)\n", pos, left, right, size);
if (size == 1) {
result[pos] = left;
result[pos + 1] = right;
return;
}
int common = 0;
int l = left;
int r = right;
int left_distinct_ones = 0;
for (int i = 0; i < size; i++) {
int c = (l & 1) ^ (r & 1) ^ 1;
common |= c << i;
if (c != 1) {
left_distinct_ones += l & 1;
}
l >>= 1;
r >>= 1;
}
bool swapped = false;
// printf("left = %d, right = %d\n", left, right);
if ((left_distinct_ones & 1) == 0) {
swap(left, right);
swapped = true;
// printf("swapped; left = %d, right = %d\n", left, right);
}
int d = common;
// printf("common = %d\n", d);
int left_distinct = left & (((1 << size) - 1) ^ common);
// printf("left_distinct = %d\n", left_distinct);
int left_distinct_lsb = 0;
while ((left_distinct & 1) == 0) {
left_distinct >>= 1;
left_distinct_lsb++;
}
// int left_ =
// ((left>>1)&(~((1<<(left_distinct_lsb+1))-1)))|(left&((1<<(left_distinct_lsb+1))-1));
int left_ = remove_at(left_distinct_lsb, left);
int right_ = remove_at(left_distinct_lsb, right);
int middle;
int common_ = remove_at(left_distinct_lsb, common);
int b = common_;
// printf("common_ = %d\n", b);
if (common == 0) {
middle = left_ ^ right_;
// diff(middle, left_) = 0 (mod 2)
// diff(middle, right_) = 0 (mod 2)
middle &= middle - 1;
// printf("no common\n");
} else {
middle = left_ ^ right_;
middle |= left_ & common_;
middle ^= common_ ^ (common_ & (common_ - 1));
}
// printf("%d\n", common_^(common_&(common_-1)));
// printf("left_ = %d, right_ = %d, middle = %d\n", left_, right_, middle);
if (swapped) {
construct(pos, right_, middle, size - 1);
construct(pos + (1 << (size - 1)), middle, left_, size - 1);
for (int i = pos; i < pos + (1 << (size - 1)); i++) {
result[i] = insert_at(left_distinct_lsb, 0, result[i]);
result[i + (1 << (size - 1))] =
insert_at(left_distinct_lsb, 1, result[i + (1 << (size - 1))]);
}
} else {
construct(pos, left_, middle, size - 1);
construct(pos + (1 << (size - 1)), middle, right_, size - 1);
for (int i = pos; i < pos + (1 << (size - 1)); i++) {
result[i] = insert_at(left_distinct_lsb, 1, result[i]);
result[i + (1 << (size - 1))] =
insert_at(left_distinct_lsb, 0, result[i + (1 << (size - 1))]);
}
}
}
int main() {
int n, a, b;
scanf("%d %d %d", &n, &a, &b);
int distinct = a ^ b;
int diff = 0;
while (distinct) {
diff += distinct & 1;
distinct >>= 1;
}
if ((diff & 1) == 0) {
printf("NO\n");
return 0;
}
construct(0, a, b, n);
printf("YES\n");
int i;
for (i = 0; i < (1 << n) - 1; i++) {
printf("%d ", result[i]);
}
printf("%d", result[i]);
return 0;
}
| [
"expression.operation.binary.remove"
] | 917,182 | 917,183 | u146562833 | cpp |
p03097 | #include <iostream>
#include <vector>
using namespace std;
int N, A, B;
vector<int> ans;
vector<int> dfs(int start, int goal, int len) {
if (len == 1)
return (vector<int>){start, goal};
int x = 0;
for (int i = 0; i < len; i++) {
if ((start xor goal) & (1 << i)) {
x = i;
break;
}
}
int a = 0, b = 0;
for (int i = 0; i < len; i++) {
if (i < x) {
if (start & (1 << i))
a += (1 << i);
if (goal & (1 << i))
b += (1 << i);
}
if (i > x) {
if (start & (1 << i))
a += (1 << (i - 1));
if (goal & (1 << i))
b += (1 << (i - 1));
}
}
int c = a ^ 1;
vector<int> q = dfs(a, c, len - 1), r = dfs(c, b, len - 1), res;
for (auto n : q) {
int now = (start & (1 << x) ? (1 << x) : 0);
for (int i = 0; i < len - 1; i++) {
if (i < x && n & (1 << i))
now += (1 << i);
if (i >= x && n & (1 << i))
now += (1 << (i + 1));
}
res.push_back(now);
}
for (auto n : r) {
int now = (goal & (1 << x) ? (1 << x) : 0);
for (int i = 0; i < len - 1; i++) {
if (i < x && n & (1 << i))
now += (1 << i);
if (i >= x && n & (1 << i))
now += (1 << (i + 1));
}
res.push_back(now);
}
return res;
}
int main() {
cin >> N >> A >> B;
if (__builtin_popcount(A) % 2 == __builtin_popcount(B)) {
cout << "NO" << endl;
return 0;
}
vector<int> ans = dfs(A, B, N);
cout << "YES" << endl;
for (auto x : ans)
cout << x << " ";
cout << endl;
} | #include <iostream>
#include <vector>
using namespace std;
int N, A, B;
vector<int> ans;
vector<int> dfs(int start, int goal, int len) {
if (len == 1)
return (vector<int>){start, goal};
int x = 0;
for (int i = 0; i < len; i++) {
if ((start xor goal) & (1 << i)) {
x = i;
break;
}
}
int a = 0, b = 0;
for (int i = 0; i < len; i++) {
if (i < x) {
if (start & (1 << i))
a += (1 << i);
if (goal & (1 << i))
b += (1 << i);
}
if (i > x) {
if (start & (1 << i))
a += (1 << (i - 1));
if (goal & (1 << i))
b += (1 << (i - 1));
}
}
int c = a ^ 1;
vector<int> q = dfs(a, c, len - 1), r = dfs(c, b, len - 1), res;
for (auto n : q) {
int now = (start & (1 << x) ? (1 << x) : 0);
for (int i = 0; i < len - 1; i++) {
if (i < x && n & (1 << i))
now += (1 << i);
if (i >= x && n & (1 << i))
now += (1 << (i + 1));
}
res.push_back(now);
}
for (auto n : r) {
int now = (goal & (1 << x) ? (1 << x) : 0);
for (int i = 0; i < len - 1; i++) {
if (i < x && n & (1 << i))
now += (1 << i);
if (i >= x && n & (1 << i))
now += (1 << (i + 1));
}
res.push_back(now);
}
return res;
}
int main() {
cin >> N >> A >> B;
if (__builtin_popcount(A) % 2 == __builtin_popcount(B) % 2) {
cout << "NO" << endl;
return 0;
}
vector<int> ans = dfs(A, B, N);
cout << "YES" << endl;
for (auto x : ans)
cout << x << " ";
cout << endl;
}
| [
"control_flow.branch.if.condition.change"
] | 917,192 | 917,193 | u623954643 | cpp |
p03097 | #include <cassert>
#include <iostream>
#include <vector>
using namespace std;
int N, A, B;
vector<int> ans;
vector<int> dfs(int start, int goal, int len) {
if (len == 1)
return (vector<int>){start, goal};
int x = 0;
for (int i = 0; i < len; i++) {
if ((start ^ goal) & (1 << i)) {
x = i;
break;
}
}
int a = 0, b = 0;
for (int i = 0; i < len; i++) {
if (i < x) {
if (start & (1 << i))
a += (1 << i);
if (goal & (1 << i))
b += (1 << i);
}
if (i > x) {
if (start & (1 << i))
a += (1 << (i - 1));
if (goal & (1 << i))
b += (1 << (i - 1));
}
}
int c = -1;
for (int i = 0; i < len - 1; i++) {
if ((a ^ (1 << i)) != b) {
c = a ^ (1 << i);
break;
}
}
assert(c != -1);
vector<int> q = dfs(a, c, len - 1), r = dfs(c, b, len - 1), res;
for (auto n : q) {
int now = (start & (1 << x) ? (1 << x) : 0);
for (int i = 0; i < len - 1; i++) {
if (i < x && (n & (1 << i)))
now += (1 << i);
if (i >= x && (n & (1 << i)))
now += (1 << (i + 1));
}
res.push_back(now);
}
for (auto n : r) {
int now = (goal & (1 << x) ? (1 << x) : 0);
for (int i = 0; i < len - 1; i++) {
if (i < x && (n & (1 << i)))
now += (1 << i);
if (i >= x && (n & (1 << i)))
now += (1 << (i + 1));
}
res.push_back(now);
}
return res;
}
int main() {
cin >> N >> A >> B;
if (__builtin_popcount(A) % 2 == __builtin_popcount(B)) {
cout << "NO" << endl;
return 0;
}
vector<int> ans = dfs(A, B, N);
cout << "YES" << endl;
for (auto x : ans)
cout << x << " ";
cout << endl;
} | #include <cassert>
#include <iostream>
#include <vector>
using namespace std;
int N, A, B;
vector<int> ans;
vector<int> dfs(int start, int goal, int len) {
if (len == 1)
return (vector<int>){start, goal};
int x = 0;
for (int i = 0; i < len; i++) {
if ((start ^ goal) & (1 << i)) {
x = i;
break;
}
}
int a = 0, b = 0;
for (int i = 0; i < len; i++) {
if (i < x) {
if (start & (1 << i))
a += (1 << i);
if (goal & (1 << i))
b += (1 << i);
}
if (i > x) {
if (start & (1 << i))
a += (1 << (i - 1));
if (goal & (1 << i))
b += (1 << (i - 1));
}
}
int c = -1;
for (int i = 0; i < len - 1; i++) {
if ((a ^ (1 << i)) != b) {
c = a ^ (1 << i);
break;
}
}
assert(c != -1);
vector<int> q = dfs(a, c, len - 1), r = dfs(c, b, len - 1), res;
for (auto n : q) {
int now = (start & (1 << x) ? (1 << x) : 0);
for (int i = 0; i < len - 1; i++) {
if (i < x && (n & (1 << i)))
now += (1 << i);
if (i >= x && (n & (1 << i)))
now += (1 << (i + 1));
}
res.push_back(now);
}
for (auto n : r) {
int now = (goal & (1 << x) ? (1 << x) : 0);
for (int i = 0; i < len - 1; i++) {
if (i < x && (n & (1 << i)))
now += (1 << i);
if (i >= x && (n & (1 << i)))
now += (1 << (i + 1));
}
res.push_back(now);
}
return res;
}
int main() {
cin >> N >> A >> B;
if (__builtin_popcount(A) % 2 == __builtin_popcount(B) % 2) {
cout << "NO" << endl;
return 0;
}
vector<int> ans = dfs(A, B, N);
cout << "YES" << endl;
for (auto x : ans)
cout << x << " ";
cout << endl;
} | [
"control_flow.branch.if.condition.change"
] | 917,194 | 917,195 | u623954643 | cpp |
p03097 | #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
vector<int> solve(int n, int A, int B) {
if (n == 1) {
vector<int> ret;
ret.push_back(A);
ret.push_back(B);
return ret;
}
int k = 0;
while (k < n) {
if ((A ^ B) & (1 << k))
break;
k++;
}
int nxtA = 0, nxtB = 0;
for (int i = n - 1; i >= 0; i--) {
if (i == k)
continue;
nxtA <<= 1;
if (A & (1 << i))
nxtA |= 1;
nxtB <<= 1;
if (B & (1 << i))
nxtB |= 1;
}
int C = nxtA ^ 1;
vector<int> v1 = solve(n - 1, nxtA, C);
vector<int> v2 = solve(n - 1, C, nxtB);
vector<int> ret;
for (int i = 0; i < v1.size(); i++) {
int x = 0;
for (int j = 0; j < n; j++) {
if (j == k) {
if (A & (1 << k))
x |= (1 << j);
} else {
if (v1[i] & 1)
x |= (1 << j);
v1[i] >>= 1;
}
}
ret.push_back(x);
}
for (int i = 0; i < v2.size(); i++) {
int x = 0;
for (int j = 0; j < n; j++) {
if (j == k) {
if (B & (1 << k))
x |= (1 << j);
} else {
if (v2[i] & 1)
x |= (1 << j);
v2[i] >>= 1;
}
}
ret.push_back(x);
}
return ret;
}
int pop_count(int n) {
int ret = 0;
for (int i = 0; i < 17; i++) {
if (n & (1 << i))
ret++;
}
return ret;
}
int main() {
int N, A, B;
cin >> N >> A >> B;
if (pop_count(A) == pop_count(B)) {
cout << "NO" << endl;
return 0;
}
cout << "YES" << endl;
vector<int> ret = solve(N, A, B);
for (int i = 0; i < ret.size(); i++) {
cout << ret[i] << " ";
}
cout << endl;
} | #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
vector<int> solve(int n, int A, int B) {
if (n == 1) {
vector<int> ret;
ret.push_back(A);
ret.push_back(B);
return ret;
}
int k = 0;
while (k < n) {
if ((A ^ B) & (1 << k))
break;
k++;
}
int nxtA = 0, nxtB = 0;
for (int i = n - 1; i >= 0; i--) {
if (i == k)
continue;
nxtA <<= 1;
if (A & (1 << i))
nxtA |= 1;
nxtB <<= 1;
if (B & (1 << i))
nxtB |= 1;
}
int C = nxtA ^ 1;
vector<int> v1 = solve(n - 1, nxtA, C);
vector<int> v2 = solve(n - 1, C, nxtB);
vector<int> ret;
for (int i = 0; i < v1.size(); i++) {
int x = 0;
for (int j = 0; j < n; j++) {
if (j == k) {
if (A & (1 << k))
x |= (1 << j);
} else {
if (v1[i] & 1)
x |= (1 << j);
v1[i] >>= 1;
}
}
ret.push_back(x);
}
for (int i = 0; i < v2.size(); i++) {
int x = 0;
for (int j = 0; j < n; j++) {
if (j == k) {
if (B & (1 << k))
x |= (1 << j);
} else {
if (v2[i] & 1)
x |= (1 << j);
v2[i] >>= 1;
}
}
ret.push_back(x);
}
return ret;
}
int pop_count(int n) {
int ret = 0;
for (int i = 0; i < 17; i++) {
if (n & (1 << i))
ret++;
}
return ret;
}
int main() {
int N, A, B;
cin >> N >> A >> B;
if (pop_count(A) % 2 == pop_count(B) % 2) {
cout << "NO" << endl;
return 0;
}
cout << "YES" << endl;
vector<int> ret = solve(N, A, B);
for (int i = 0; i < ret.size(); i++) {
cout << ret[i] << " ";
}
cout << endl;
}
| [
"control_flow.branch.if.condition.change"
] | 917,196 | 917,197 | u243961437 | cpp |
p03097 | #include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 200005
#define eps 1e-12
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template <class T> void read(T &res) {
res = 0;
T f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-')
f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
res = res * 10 + c - '0';
c = getchar();
}
res *= f;
}
template <class T> void out(T x) {
if (x < 0) {
x = -x;
putchar('-');
}
if (x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int N, A, B;
int Delete(int x, int p) {
int d = x & (1 << p) - 1;
int u = x & (1 << 20) - (1 << p + 1);
return (u >> 1) + d;
}
int Insert(int x, int p, int v) {
int d = x & (1 << p) - 1;
int u = x & (1 << 20) - (1 << p);
return (u << 1) + v + d;
}
vector<int> Calc(int s, int t, int n) {
if (n == 1) {
vector<int> v;
v.pb(s);
v.pb(t);
return v;
}
int x = 1, p = 0;
while (1) {
if ((s & x) != (t & x))
break;
x <<= 1;
++p;
}
int a, b;
a = Delete(s, p);
b = Delete(p, t);
int c = a ^ 1;
vector<int> f = Calc(a, c, n - 1), h = Calc(c, b, n - 1);
for (int i = 0; i < (1 << n - 1); ++i) {
f[i] = Insert(f[i], p, (s & x));
h[i] = Insert(h[i], p, (t & x));
}
f.insert(f.end(), h.begin(), h.end());
return f;
}
int count(int x) {
int res = 0;
while (x) {
res += (x & 1);
x >>= 1;
}
return res;
}
void Solve() {
read(N);
read(A);
read(B);
if (!(count(A ^ B) & 1)) {
puts("NO");
return;
}
puts("YES");
vector<int> ans = Calc(A, B, N);
for (int i = 0; i < (1 << N); ++i) {
out(ans[i]);
space;
}
enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in", "r", stdin);
#endif
Solve();
}
| #include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 200005
#define eps 1e-12
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template <class T> void read(T &res) {
res = 0;
T f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-')
f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
res = res * 10 + c - '0';
c = getchar();
}
res *= f;
}
template <class T> void out(T x) {
if (x < 0) {
x = -x;
putchar('-');
}
if (x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int N, A, B;
int Delete(int x, int p) {
int d = x & (1 << p) - 1;
int u = x & (1 << 20) - (1 << p + 1);
return (u >> 1) + d;
}
int Insert(int x, int p, int v) {
int d = x & (1 << p) - 1;
int u = x & (1 << 20) - (1 << p);
return (u << 1) + v + d;
}
vector<int> Calc(int s, int t, int n) {
if (n == 1) {
vector<int> v;
v.pb(s);
v.pb(t);
return v;
}
int x = 1, p = 0;
while (1) {
if ((s & x) != (t & x))
break;
x <<= 1;
++p;
}
int a, b;
a = Delete(s, p);
b = Delete(t, p);
int c = a ^ 1;
vector<int> f = Calc(a, c, n - 1), h = Calc(c, b, n - 1);
for (int i = 0; i < (1 << n - 1); ++i) {
f[i] = Insert(f[i], p, (s & x));
h[i] = Insert(h[i], p, (t & x));
}
f.insert(f.end(), h.begin(), h.end());
return f;
}
int count(int x) {
int res = 0;
while (x) {
res += (x & 1);
x >>= 1;
}
return res;
}
void Solve() {
read(N);
read(A);
read(B);
if (!(count(A ^ B) & 1)) {
puts("NO");
return;
}
puts("YES");
vector<int> ans = Calc(A, B, N);
for (int i = 0; i < (1 << N); ++i) {
out(ans[i]);
space;
}
enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in", "r", stdin);
#endif
Solve();
}
| [
"call.arguments.change",
"call.arguments.add"
] | 917,200 | 917,201 | u845980916 | cpp |
p03097 | #include <bits/stdc++.h>
using namespace std;
int n;
int dfs(int pos, int cnt, int a, int bit, vector<int> &tmp) {
int keta = (pos + cnt) % n;
if (cnt == 0) {
if ((bit >> cnt) & 1)
return a;
else {
a ^= (1 << keta);
tmp.push_back(a);
return a;
}
} else {
if ((bit >> cnt) & 1)
return dfs(pos, cnt - 1, a, bit, tmp);
else {
a = dfs(pos, cnt - 1, a, bit, tmp);
a ^= (1 << keta);
tmp.push_back(a);
a = dfs(pos, cnt - 1, a, bit, tmp);
return a;
}
}
}
void solve(int a, int b, int bit, vector<int> &v) {
if (a == b) {
v.push_back(b);
return;
}
for (int i = 0; i < n; i++) {
if (((a ^ b) >> i) & 1) {
bit ^= (1 << i);
for (int j = 0; j < n; j++) {
vector<int> tmp;
tmp.push_back(a);
int x = dfs(j, 0, a, bit, tmp);
if (x != b) {
v.insert(v.end(), tmp.begin(), tmp.end());
solve(x ^ (1 << i), b, bit, v);
return;
}
}
}
}
}
int main() {
int a, b;
cin >> n >> a >> b;
if ((__builtin_popcount(a ^ b) & 1) == 0) {
cout << "NO" << endl;
return 0;
}
vector<int> v;
int bit = 0;
solve(a, b, bit, v);
cout << "YES" << endl;
for (int i = 0; i < (1 << n); i++) {
cout << v[i] << ((i + 1 == (1 << n)) ? "\n" : " ");
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int n;
int dfs(int pos, int cnt, int a, int bit, vector<int> &tmp) {
int keta = (pos + cnt) % n;
if (cnt == 0) {
if ((bit >> cnt) & 1)
return a;
else {
a ^= (1 << keta);
tmp.push_back(a);
return a;
}
} else {
if ((bit >> cnt) & 1)
return dfs(pos, cnt - 1, a, bit, tmp);
else {
a = dfs(pos, cnt - 1, a, bit, tmp);
a ^= (1 << keta);
tmp.push_back(a);
a = dfs(pos, cnt - 1, a, bit, tmp);
return a;
}
}
}
void solve(int a, int b, int bit, vector<int> &v) {
if (a == b) {
v.push_back(b);
return;
}
for (int i = 0; i < n; i++) {
if (((a ^ b) >> i) & 1) {
bit ^= (1 << i);
for (int j = 0; j < n; j++) {
vector<int> tmp;
tmp.push_back(a);
int x = dfs(j, n - 1, a, bit, tmp);
if (x != b) {
v.insert(v.end(), tmp.begin(), tmp.end());
solve(x ^ (1 << i), b, bit, v);
return;
}
}
}
}
}
int main() {
int a, b;
cin >> n >> a >> b;
if ((__builtin_popcount(a ^ b) & 1) == 0) {
cout << "NO" << endl;
return 0;
}
vector<int> v;
int bit = 0;
solve(a, b, bit, v);
cout << "YES" << endl;
for (int i = 0; i < (1 << n); i++) {
cout << v[i] << ((i + 1 == (1 << n)) ? "\n" : " ");
}
return 0;
} | [
"identifier.replace.add",
"literal.replace.remove",
"call.arguments.change"
] | 917,206 | 917,207 | u283229916 | cpp |
p03097 | #include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i, N) for (LL i = 0; i < N; ++i)
typedef long long int LL;
LL N;
LL erase_bit(LL n, LL m) {
LL upper = (n >> (m + 1)) << m, lower = n % (1LL << m);
return upper + lower;
}
LL push_bit(LL n, LL m, LL k) {
LL upper = (n - n % (1LL << m)) << 1, lower = n % (1LL << m);
return upper + k * (1LL << m) + lower;
}
std::vector<LL> f(LL a, LL b, LL c) {
if (c == 1)
return std::vector<LL>{a, b};
LL diff_bit;
std::vector<LL> res;
rep(i, N) {
if (((a ^ b) >> i) & 1) {
diff_bit = i;
break;
}
}
auto res1 = f(erase_bit(a, diff_bit), erase_bit(a, diff_bit) ^ 1, c - 1),
res2 = f(erase_bit(a, diff_bit) ^ 1, erase_bit(b, diff_bit), c - 1);
for (auto i : res1)
res.push_back(push_bit(i, diff_bit, (a >> diff_bit) & 1));
for (auto i : res2)
res.push_back(push_bit(i, diff_bit, (b >> diff_bit) & 1));
return res;
}
int main() {
LL A, B;
in >> N >> A >> B;
LL cnt1 = 0, cnt2 = 0;
rep(i, N) {
if ((A >> i) & 1)
++cnt1;
if ((B >> i) & 1)
++cnt2;
}
if (cnt1 == cnt2) {
out << "NO" << std::endl;
return 0;
}
out << "YES" << std::endl;
auto ans = f(A, B, N);
rep(i, (1LL << N)) out << ans[i] << (i < (1LL << N) - 1 ? " " : "\n");
}
| #include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i, N) for (LL i = 0; i < N; ++i)
typedef long long int LL;
LL N;
LL erase_bit(LL n, LL m) {
LL upper = (n >> (m + 1)) << m, lower = n % (1LL << m);
return upper + lower;
}
LL push_bit(LL n, LL m, LL k) {
LL upper = (n - n % (1LL << m)) << 1, lower = n % (1LL << m);
return upper + k * (1LL << m) + lower;
}
std::vector<LL> f(LL a, LL b, LL c) {
if (c == 1)
return std::vector<LL>{a, b};
LL diff_bit;
std::vector<LL> res;
rep(i, N) {
if (((a ^ b) >> i) & 1) {
diff_bit = i;
break;
}
}
auto res1 = f(erase_bit(a, diff_bit), erase_bit(a, diff_bit) ^ 1, c - 1),
res2 = f(erase_bit(a, diff_bit) ^ 1, erase_bit(b, diff_bit), c - 1);
for (auto i : res1)
res.push_back(push_bit(i, diff_bit, (a >> diff_bit) & 1));
for (auto i : res2)
res.push_back(push_bit(i, diff_bit, (b >> diff_bit) & 1));
return res;
}
int main() {
LL A, B;
in >> N >> A >> B;
LL cnt1 = 0, cnt2 = 0;
rep(i, N) {
if ((A >> i) & 1)
++cnt1;
if ((B >> i) & 1)
++cnt2;
}
if (cnt1 % 2 == cnt2 % 2) {
out << "NO" << std::endl;
return 0;
}
out << "YES" << std::endl;
auto ans = f(A, B, N);
rep(i, (1LL << N)) out << ans[i] << (i < (1LL << N) - 1 ? " " : "\n");
}
| [
"control_flow.branch.if.condition.change"
] | 917,208 | 917,211 | u660613376 | cpp |
p03097 | #include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif
#define int long long
#define ll long long
#define ll1 1ll
#define ONE 1ll
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
is >> p.first >> p.second;
return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
os << p.first << " " << p.second;
return os;
}
template <typename T> void printvv(const vector<vector<T>> &v) {
cerr << endl;
rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
cerr << "INF";
} else
cerr << v[i][j];
cerr << (j == v[i].size() - 1 ? '\n' : ' ');
}
cerr << endl;
}
/*
typedef __int128_t Int;
std::ostream &operator<<(std::ostream &dest, __int128_t value) {
std::ostream::sentry s(dest);
if (s) {
__uint128_t tmp = value < 0 ? -value : value;
char buffer[128];
char *d = std::end(buffer);
do {
--d;
*d = "0123456789"[tmp % 10];
tmp /= 10;
} while (tmp != 0);
if (value < 0) {
--d;
*d = '-';
}
int len = std::end(buffer) - d;
if (dest.rdbuf()->sputn(d, len) != len) {
dest.setstate(std::ios_base::badbit);
}
}
return dest;
}
__int128 parse(string &s) {
__int128 ret = 0;
for (int i = 0; i < s.length(); i++)
if ('0' <= s[i] && s[i] <= '9')
ret = 10 * ret + s[i] - '0';
return ret;
}
*/
#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
vector<int> f(int N, int A, int B) {
if (N == 1) {
vector<int> ret;
ret.eb(A);
ret.eb(B);
return ret;
}
int x;
int aa, bb;
rep(i, 0, N) {
if (((A >> i) & 1) != ((B >> i) & 1)) {
x = i;
int mask = (1ll << N) - (1ll << (i + 1));
aa = ((A & mask) >> 1) | (A & ((1ll << i) - 1));
bb = ((B & mask) >> 1) | (B & ((1ll << i) - 1));
break;
}
}
int c = aa ^ 1;
auto l = f(N - 1, aa, c);
auto r = f(N - 1, c, bb);
for (auto &y : l) {
int mask = (1ll << N) - (1ll << x);
y = ((y & mask) << 1) | (A & (1ll << x)) | y & ((1ll << x) - 1);
}
for (auto &y : r) {
int mask = (1ll << N) - (1ll << x);
y = ((y & mask) << 1) | (B & (1ll << x)) | y & ((1ll << x) - 1);
}
l.insert(l.end(), all(r));
return l;
}
signed main(signed argc, char *argv[]) {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(12);
int N;
cin >> N;
int A, B;
cin >> A >> B;
int a = 0, b = 0;
rep(i, 0, N) {
a += (A >> i) & 1;
b += (B >> i) & 1;
}
if (a == b) {
YES(0);
return 0;
} else {
YES(1);
auto ans = f(N, A, B);
rep(i, 0, ans.size()) cout << ans[i] << (i == ans.size() - 1 ? '\n' : ' ');
}
return 0;
}
| #include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif
#define int long long
#define ll long long
#define ll1 1ll
#define ONE 1ll
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
is >> p.first >> p.second;
return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
os << p.first << " " << p.second;
return os;
}
template <typename T> void printvv(const vector<vector<T>> &v) {
cerr << endl;
rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
cerr << "INF";
} else
cerr << v[i][j];
cerr << (j == v[i].size() - 1 ? '\n' : ' ');
}
cerr << endl;
}
/*
typedef __int128_t Int;
std::ostream &operator<<(std::ostream &dest, __int128_t value) {
std::ostream::sentry s(dest);
if (s) {
__uint128_t tmp = value < 0 ? -value : value;
char buffer[128];
char *d = std::end(buffer);
do {
--d;
*d = "0123456789"[tmp % 10];
tmp /= 10;
} while (tmp != 0);
if (value < 0) {
--d;
*d = '-';
}
int len = std::end(buffer) - d;
if (dest.rdbuf()->sputn(d, len) != len) {
dest.setstate(std::ios_base::badbit);
}
}
return dest;
}
__int128 parse(string &s) {
__int128 ret = 0;
for (int i = 0; i < s.length(); i++)
if ('0' <= s[i] && s[i] <= '9')
ret = 10 * ret + s[i] - '0';
return ret;
}
*/
#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
vector<int> f(int N, int A, int B) {
if (N == 1) {
vector<int> ret;
ret.eb(A);
ret.eb(B);
return ret;
}
int x;
int aa, bb;
rep(i, 0, N) {
if (((A >> i) & 1) != ((B >> i) & 1)) {
x = i;
int mask = (1ll << N) - (1ll << (i + 1));
aa = ((A & mask) >> 1) | (A & ((1ll << i) - 1));
bb = ((B & mask) >> 1) | (B & ((1ll << i) - 1));
break;
}
}
int c = aa ^ 1;
auto l = f(N - 1, aa, c);
auto r = f(N - 1, c, bb);
for (auto &y : l) {
int mask = (1ll << N) - (1ll << x);
y = ((y & mask) << 1) | (A & (1ll << x)) | y & ((1ll << x) - 1);
}
for (auto &y : r) {
int mask = (1ll << N) - (1ll << x);
y = ((y & mask) << 1) | (B & (1ll << x)) | y & ((1ll << x) - 1);
}
l.insert(l.end(), all(r));
return l;
}
signed main(signed argc, char *argv[]) {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(12);
int N;
cin >> N;
int A, B;
cin >> A >> B;
int a = 0, b = 0;
rep(i, 0, N) {
a += (A >> i) & 1;
b += (B >> i) & 1;
}
if (a % 2 == b % 2) {
YES(0);
return 0;
} else {
YES(1);
auto ans = f(N, A, B);
rep(i, 0, ans.size()) cout << ans[i] << (i == ans.size() - 1 ? '\n' : ' ');
}
return 0;
}
| [
"control_flow.branch.if.condition.change"
] | 917,219 | 917,220 | u570522509 | cpp |
p03097 | #include <bits/stdc++.h>
using namespace std;
#ifndef d
#define d(...)
#endif
#define st first
#define nd second
#define pb push_back
#define siz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
typedef long long LL;
typedef long double LD;
constexpr int INF = 1e9 + 7;
constexpr LL INFL = 1e18;
template <class L, class R> ostream &operator<<(ostream &os, pair<L, R> P) {
return os << "(" << P.st << "," << P.nd << ")";
}
vector<int> solve(int n, int A, int B) {
if (n == 1)
return {A, B};
auto x = A ^ B;
x = x & (-x);
auto l = __lg(x);
auto f = [&](int y) { return ((y >> (l + 1)) << l) ^ (y & (x - 1)); };
auto _A = f(A), _B = f(B);
auto &&p = solve(n - 1, _A, _A ^ 1), q = solve(n - 1, _A ^ 1, _B);
auto &change = (A & x ? p : q), &mv = (A & x ? q : p);
auto g = [&](int y) { return ((y >> l) << (l + 1)) ^ (y & (x - 1)); };
// cerr << "solving for: " << n << ", " << make_pair(A, B) << " converted to:
// " << make_pair(_A, _B) << " x, l = " << x << ", " << l << endl; cerr <<
// "received: "; for(auto x:p) cerr << x << " "; cerr << " and "; for(auto x:q)
// cerr << x << " "; cerr << endl;
for (auto &val : change) {
val = g(val);
val ^= x;
}
for (auto &val : mv)
val = g(val);
// cerr << "converted to: ";
// for(auto x:p) cerr << x << " ";
// cerr << " and ";
// for(auto x:q) cerr << x << " ";
// cerr << endl;
for (auto val : q)
p.push_back(val);
return p;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, A, B;
cin >> n >> A >> B;
if (__builtin_popcount(A) % 2 == __builtin_popcount(B))
return cout << "NO\n", 0;
cout << "YES\n";
auto &&path = solve(n, A, B);
for (auto x : path)
cout << x << " ";
cout << "\n";
}
| #include <bits/stdc++.h>
using namespace std;
#ifndef d
#define d(...)
#endif
#define st first
#define nd second
#define pb push_back
#define siz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
typedef long long LL;
typedef long double LD;
constexpr int INF = 1e9 + 7;
constexpr LL INFL = 1e18;
template <class L, class R> ostream &operator<<(ostream &os, pair<L, R> P) {
return os << "(" << P.st << "," << P.nd << ")";
}
vector<int> solve(int n, int A, int B) {
if (n == 1)
return {A, B};
auto x = A ^ B;
x = x & (-x);
auto l = __lg(x);
auto f = [&](int y) { return ((y >> (l + 1)) << l) ^ (y & (x - 1)); };
auto _A = f(A), _B = f(B);
auto &&p = solve(n - 1, _A, _A ^ 1), q = solve(n - 1, _A ^ 1, _B);
auto &change = (A & x ? p : q), &mv = (A & x ? q : p);
auto g = [&](int y) { return ((y >> l) << (l + 1)) ^ (y & (x - 1)); };
// cerr << "solving for: " << n << ", " << make_pair(A, B) << " converted to:
// " << make_pair(_A, _B) << " x, l = " << x << ", " << l << endl; cerr <<
// "received: "; for(auto x:p) cerr << x << " "; cerr << " and "; for(auto x:q)
// cerr << x << " "; cerr << endl;
for (auto &val : change) {
val = g(val);
val ^= x;
}
for (auto &val : mv)
val = g(val);
// cerr << "converted to: ";
// for(auto x:p) cerr << x << " ";
// cerr << " and ";
// for(auto x:q) cerr << x << " ";
// cerr << endl;
for (auto val : q)
p.push_back(val);
return p;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, A, B;
cin >> n >> A >> B;
if (__builtin_popcount(A) % 2 == __builtin_popcount(B) % 2)
return cout << "NO\n", 0;
cout << "YES\n";
auto &&path = solve(n, A, B);
for (auto x : path)
cout << x << " ";
cout << "\n";
}
| [
"control_flow.branch.if.condition.change"
] | 917,221 | 917,222 | u790287353 | cpp |
p03107 | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int n = s.length(), ans = 0;
int a = 0, b = 0;
for (int i = 0; i < n; i++) {
if (s[i] == '1')
a++;
else
b++;
}
ans = min(a, b);
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int n = s.length(), ans = 0;
int a = 0, b = 0;
for (int i = 0; i < n; i++) {
if (s[i] == '1')
a++;
else
b++;
}
ans = min(a, b) * 2;
cout << ans << endl;
}
| [
"assignment.change"
] | 917,234 | 917,235 | u198693633 | cpp |
p03107 | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define fo(a, b) for (int a = 0; a < b; a++)
#define Sort(a) sort(a.begin(), a.end())
#define rev(a) reverse(a.begin(), a.end())
#define fi first
#define se second
#define co(a) cout << a << endl
#define sz size()
#define bgn begin()
#define en end()
#define pb push_back
#define pp() pop_back()
#define V vector
#define P pair
#define V2(a, b, c) V<V<int>> a(b, V<int>(c))
#define V2a(a, b, c, d) V<V<int>> a(b, V<int>(c, d))
#define incin(a) \
int a; \
cin >> a
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(), a.end()), a.end())
#define Q queue
#define pri priority_queue
#define Pri priority_queue<int, vector<int>, greater<int>>
#define PriP \
priority_queue<P<int, int>, vector<P<int, int>>, greater<P<int, int>>>
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
#define all(a) (a).begin(), (a).end()
#define Pi P<int, int>
#define elif else if
int low(V<int> a, int b) {
decltype(a)::iterator c = lower_bound(a.begin(), a.end(), b);
int d = c - a.bgn;
return d;
}
int upp(V<int> a, int b) {
decltype(a)::iterator c = upper_bound(a.begin(), a.end(), b);
int d = c - a.bgn;
return d;
}
template <class T> void cou(vector<vector<T>> a) {
int b = a.size();
int c = a[0].size();
fo(i, b) {
fo(j, c) {
cout << a[i][j];
if (j == c - 1)
cout << endl;
else
cout << ' ';
}
}
}
int wari(int a, int b) {
if (a % b == 0)
return a / b;
else
return a / b + 1;
}
int keta(int a) {
double b = a;
b = log10(b);
int c = b;
return c + 1;
}
int souwa(int a) { return a * (a + 1) / 2; }
int gcm(int a, int b) {
if (a % b == 0)
return b;
return gcm(b, a % b);
}
bool prime(int a) {
if (a < 2)
return false;
else if (a == 2)
return true;
else if (a % 2 == 0)
return false;
double b = sqrt(a);
for (int i = 3; i <= b; i += 2) {
if (a % i == 0) {
return false;
}
}
return true;
}
struct Union {
vector<int> par;
Union(int a) { par = vector<int>(a, -1); }
int find(int a) {
if (par[a] < 0)
return a;
else
return par[a] = find(par[a]);
}
bool same(int a, int b) { return find(a) == find(b); }
int Size(int a) { return -par[find(a)]; }
void unite(int a, int b) {
a = find(a);
b = find(b);
if (a == b)
return;
if (Size(b) > Size(a))
swap<int>(a, b);
par[a] += par[b];
par[b] = a;
}
};
int ketas(int a) {
string b = to_string(a);
int c = 0;
fo(i, keta(a)) { c += b[i] - '0'; }
return c;
}
int lcm(int a, int b) { return a / gcm(a, b) * b; }
bool fe(int a, int b) {
a %= 10;
b %= 10;
if (a == 0)
a = 10;
if (b == 0)
b = 10;
if (a > b)
return true;
else
return false;
}
int INF = 1000000007;
struct edge {
int s, t, d;
};
V<int> mojisyu(string a) {
V<int> b(26, 0);
fo(i, a.sz) { b[a[i] - 'a']++; }
return b;
}
int wa2(int a) {
if (a % 2 == 1)
return a / 2;
return a / 2 - 1;
}
/*signed main(){
int a,b,c;
cin>>a>>b>>c;
V<V<edge>> d(a);
fo(i,b){
edge e;
cin>>e.s>>e.t>>e.d;
d[e.s].pb(e);
}
V<int> e(a,INF);
e[c]=0;
priority_queue<P<int,int>,V<P<int,int>>,greater<P<int,int>>> f;
f.push({0,c});
int h=INF;
while(!f.empty()){
P<int,int> g;
g=f.top();
f.pop();
int v = g.second, i = g.first;
for(edge l : d[v]){
if(e[l.t] > i + l.d){
e[l.t] = i + l.d;
f.push({i+l.d , l.t});
}
}
}
fo(i,a){
if(e[i]==INF)
cout<<"INF"<<endl;
else
cout<<e[i]<<endl;
}
}
?*/
int nCr(int n, int r) {
int a = 1;
r = min(r, n - r);
for (int i = n; i > n - r; i--) {
a *= i;
a /= n - i + 1;
}
return a;
}
/*void sea(int x,int y){
if(x<0||a<=x||y<0||b<=y||c[x][y]=='#')
return;
if(d[x][y])
return;
d[x][y]++;
sea(x+1,y);
sea(x-1,y);
sea(x,y+1);
sea(x,y-1);
}*/
int kaijou(int a) {
int b = 1;
fo(i, a) b *= i + 1;
return b;
}
int nPr(int a, int b) {
int c = 1;
for (int i = a; i >= b; i--)
c *= i;
return c;
}
int MOD = INF;
int fac[1000010], finv[1000010], inv[1000010];
// テーブルを作る前処理
//先にCOMinit()で前処理をする
// ABC145D
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < 1000010; 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;
}
}
// 二項係数計算
int 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;
}
bool naka(int a, int b, V<V<char>> c) {
return (a >= 0 && b >= 0 && a < c.sz && b < c[0].sz);
}
V<P<int, int>> mawari4 = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}};
V<P<int, int>> mawari8 = {{0, -1}, {0, 1}, {1, 0}, {-1, 0},
{-1, -1}, {1, 1}, {1, -1}, {-1, -1}};
// 最短距離の表:c
// スタート:sx,sy
// ゴール:gx,gy
/*int bfs(V<V<char>> a){
Q<P<int,int>> b;
fo(i,a.sz){
fo(j,a[0].sz){
c[i][j]==INF;
}
}
b.push({sx,sy});
c[sx][sy]=0;
while(b.sz){
P d=b.front();
b.pop();
if(d=={gx,gy})
break;
fo(i,4){
int e=d.fi+mawari4[i],f=d.se+mawari4[i];
if(naka(e,f,a)&&a[e][f]=='.'&&c[e][f]==INF){
b.push({e,f});
c[e][f]==c[d.fi][d.se]+1;
}
}
}
return c[gx][gy];
}*/
int inf = 1000000000000000007;
/*
signed main(){
int a,b,c;
cin>>a>>b>>c;
V<V<edge>> d(a);
fo(i,b){
edge e;
cin>>e.s>>e.t>>e.d;
d[e.s].pb(e);
}
V<int> e(a,INF);
e[c]=0;
priority_queue<P<int,int>,V<P<int,int>>,greater<P<int,int>>> f;
f.push({0,c});
int h=INF;
while(!f.empty()){
P<int,int> g;
g=f.top();
f.pop();
int v = g.second, i = g.first;
for(edge l : d[v]){
if(e[l.t] > i + l.d){
e[l.t] = i + l.d;
f.push({i+l.d , l.t});
}
}
}
fo(i,a){
if(e[i]==INF)
cout<<"INF"<<endl;
else
cout<<e[i]<<endl;
}
}*/
signed main() {
string s;
cin >> s;
int a = 0;
int b = 0;
fo(i, s.size()) { cin >> s[i]; }
fo(i, s.size()) {
if (s[i] == 0)
a++;
else
b++;
}
cout << min(a, b) * 2 << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define fo(a, b) for (int a = 0; a < b; a++)
#define Sort(a) sort(a.begin(), a.end())
#define rev(a) reverse(a.begin(), a.end())
#define fi first
#define se second
#define co(a) cout << a << endl
#define sz size()
#define bgn begin()
#define en end()
#define pb push_back
#define pp() pop_back()
#define V vector
#define P pair
#define V2(a, b, c) V<V<int>> a(b, V<int>(c))
#define V2a(a, b, c, d) V<V<int>> a(b, V<int>(c, d))
#define incin(a) \
int a; \
cin >> a
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(), a.end()), a.end())
#define Q queue
#define pri priority_queue
#define Pri priority_queue<int, vector<int>, greater<int>>
#define PriP \
priority_queue<P<int, int>, vector<P<int, int>>, greater<P<int, int>>>
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
#define all(a) (a).begin(), (a).end()
#define Pi P<int, int>
#define elif else if
int low(V<int> a, int b) {
decltype(a)::iterator c = lower_bound(a.begin(), a.end(), b);
int d = c - a.bgn;
return d;
}
int upp(V<int> a, int b) {
decltype(a)::iterator c = upper_bound(a.begin(), a.end(), b);
int d = c - a.bgn;
return d;
}
template <class T> void cou(vector<vector<T>> a) {
int b = a.size();
int c = a[0].size();
fo(i, b) {
fo(j, c) {
cout << a[i][j];
if (j == c - 1)
cout << endl;
else
cout << ' ';
}
}
}
int wari(int a, int b) {
if (a % b == 0)
return a / b;
else
return a / b + 1;
}
int keta(int a) {
double b = a;
b = log10(b);
int c = b;
return c + 1;
}
int souwa(int a) { return a * (a + 1) / 2; }
int gcm(int a, int b) {
if (a % b == 0)
return b;
return gcm(b, a % b);
}
bool prime(int a) {
if (a < 2)
return false;
else if (a == 2)
return true;
else if (a % 2 == 0)
return false;
double b = sqrt(a);
for (int i = 3; i <= b; i += 2) {
if (a % i == 0) {
return false;
}
}
return true;
}
struct Union {
vector<int> par;
Union(int a) { par = vector<int>(a, -1); }
int find(int a) {
if (par[a] < 0)
return a;
else
return par[a] = find(par[a]);
}
bool same(int a, int b) { return find(a) == find(b); }
int Size(int a) { return -par[find(a)]; }
void unite(int a, int b) {
a = find(a);
b = find(b);
if (a == b)
return;
if (Size(b) > Size(a))
swap<int>(a, b);
par[a] += par[b];
par[b] = a;
}
};
int ketas(int a) {
string b = to_string(a);
int c = 0;
fo(i, keta(a)) { c += b[i] - '0'; }
return c;
}
int lcm(int a, int b) { return a / gcm(a, b) * b; }
bool fe(int a, int b) {
a %= 10;
b %= 10;
if (a == 0)
a = 10;
if (b == 0)
b = 10;
if (a > b)
return true;
else
return false;
}
int INF = 1000000007;
struct edge {
int s, t, d;
};
V<int> mojisyu(string a) {
V<int> b(26, 0);
fo(i, a.sz) { b[a[i] - 'a']++; }
return b;
}
int wa2(int a) {
if (a % 2 == 1)
return a / 2;
return a / 2 - 1;
}
/*signed main(){
int a,b,c;
cin>>a>>b>>c;
V<V<edge>> d(a);
fo(i,b){
edge e;
cin>>e.s>>e.t>>e.d;
d[e.s].pb(e);
}
V<int> e(a,INF);
e[c]=0;
priority_queue<P<int,int>,V<P<int,int>>,greater<P<int,int>>> f;
f.push({0,c});
int h=INF;
while(!f.empty()){
P<int,int> g;
g=f.top();
f.pop();
int v = g.second, i = g.first;
for(edge l : d[v]){
if(e[l.t] > i + l.d){
e[l.t] = i + l.d;
f.push({i+l.d , l.t});
}
}
}
fo(i,a){
if(e[i]==INF)
cout<<"INF"<<endl;
else
cout<<e[i]<<endl;
}
}
?*/
int nCr(int n, int r) {
int a = 1;
r = min(r, n - r);
for (int i = n; i > n - r; i--) {
a *= i;
a /= n - i + 1;
}
return a;
}
/*void sea(int x,int y){
if(x<0||a<=x||y<0||b<=y||c[x][y]=='#')
return;
if(d[x][y])
return;
d[x][y]++;
sea(x+1,y);
sea(x-1,y);
sea(x,y+1);
sea(x,y-1);
}*/
int kaijou(int a) {
int b = 1;
fo(i, a) b *= i + 1;
return b;
}
int nPr(int a, int b) {
int c = 1;
for (int i = a; i >= b; i--)
c *= i;
return c;
}
int MOD = INF;
int fac[1000010], finv[1000010], inv[1000010];
// テーブルを作る前処理
//先にCOMinit()で前処理をする
// ABC145D
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < 1000010; 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;
}
}
// 二項係数計算
int 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;
}
bool naka(int a, int b, V<V<char>> c) {
return (a >= 0 && b >= 0 && a < c.sz && b < c[0].sz);
}
V<P<int, int>> mawari4 = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}};
V<P<int, int>> mawari8 = {{0, -1}, {0, 1}, {1, 0}, {-1, 0},
{-1, -1}, {1, 1}, {1, -1}, {-1, -1}};
// 最短距離の表:c
// スタート:sx,sy
// ゴール:gx,gy
/*int bfs(V<V<char>> a){
Q<P<int,int>> b;
fo(i,a.sz){
fo(j,a[0].sz){
c[i][j]==INF;
}
}
b.push({sx,sy});
c[sx][sy]=0;
while(b.sz){
P d=b.front();
b.pop();
if(d=={gx,gy})
break;
fo(i,4){
int e=d.fi+mawari4[i],f=d.se+mawari4[i];
if(naka(e,f,a)&&a[e][f]=='.'&&c[e][f]==INF){
b.push({e,f});
c[e][f]==c[d.fi][d.se]+1;
}
}
}
return c[gx][gy];
}*/
int inf = 1000000000000000007;
/*
signed main(){
int a,b,c;
cin>>a>>b>>c;
V<V<edge>> d(a);
fo(i,b){
edge e;
cin>>e.s>>e.t>>e.d;
d[e.s].pb(e);
}
V<int> e(a,INF);
e[c]=0;
priority_queue<P<int,int>,V<P<int,int>>,greater<P<int,int>>> f;
f.push({0,c});
int h=INF;
while(!f.empty()){
P<int,int> g;
g=f.top();
f.pop();
int v = g.second, i = g.first;
for(edge l : d[v]){
if(e[l.t] > i + l.d){
e[l.t] = i + l.d;
f.push({i+l.d , l.t});
}
}
}
fo(i,a){
if(e[i]==INF)
cout<<"INF"<<endl;
else
cout<<e[i]<<endl;
}
}*/
signed main() {
string s;
cin >> s;
int a = 0;
int b = 0;
fo(i, s.size()) { cin >> s[i]; }
fo(i, s.size()) {
if (s[i] == '0')
a++;
else
b++;
}
cout << min(a, b) * 2 << endl;
}
| [
"control_flow.branch.if.condition.change"
] | 917,244 | 917,245 | u790461875 | cpp |
p03107 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll(i) = 0; i < (n); ++(i))
#define print(a) cout << (a) << endl
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
string s;
cin >> s;
vector<ll> v(2, 0);
rep(i, s.size()) v[s[i]]++;
if (v[0] == 0 || v[1] == 0)
print(0);
else
print(2 * min(v[0], v[1]));
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll(i) = 0; i < (n); ++(i))
#define print(a) cout << (a) << endl
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
string s;
cin >> s;
vector<int> v(2, 0);
rep(i, s.size()) v[s[i] - '0']++;
if (v[0] == 0 || v[1] == 0)
print(0);
else
print(2 * min(v[0], v[1]));
return 0;
} | [
"expression.operation.binary.add"
] | 917,248 | 917,249 | u894339989 | cpp |
p03107 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll(i) = 0; i < (n); ++(i))
#define print(a) cout << (a) << endl
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
string s;
cin >> s;
vector<ll> v(2, 0);
rep(i, s.size()) v[s[i]]++;
if (v[0] == 0 || v[1] == 0)
print(0);
else
print(2 * max(v[0], v[1]));
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll(i) = 0; i < (n); ++(i))
#define print(a) cout << (a) << endl
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
string s;
cin >> s;
vector<int> v(2, 0);
rep(i, s.size()) v[s[i] - '0']++;
if (v[0] == 0 || v[1] == 0)
print(0);
else
print(2 * min(v[0], v[1]));
return 0;
} | [
"misc.opposites",
"identifier.change",
"call.function.change",
"call.arguments.change",
"expression.operation.binary.change",
"io.output.change"
] | 917,250 | 917,249 | u894339989 | cpp |
p03107 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define fs first
#define sc second
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<tuple<ll, ll>> vtl;
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
void solve() {
// abc120c
string s;
cin >> s;
ll ans, minr, mini;
rep(i, s.size()) {
if (s[i] == '0')
minr++;
else
mini++;
}
ans = min(minr, mini); // 0と1の個数のうち少ない方を2倍→01,10erase
cout << ans + ans;
}
int main() {
cout << std::fixed << std::setprecision(10);
ios::sync_with_stdio(false);
cin.tie(0);
solve();
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define fs first
#define sc second
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<tuple<ll, ll>> vtl;
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
void solve() {
// abc120c
string s;
cin >> s;
ll ans, minr = 0, mini = 0;
rep(i, s.size()) {
if (s[i] == '0')
minr++;
else
mini++;
}
ans = min(minr, mini); // 0と1の個数のうち少ない方を2倍→01,10erase
cout << ans + ans;
}
int main() {
cout << std::fixed << std::setprecision(10);
ios::sync_with_stdio(false);
cin.tie(0);
solve();
} | [
"variable_declaration.value.change"
] | 917,271 | 917,272 | u703214333 | cpp |
p03107 | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int maru = 0, bou = 0;
cin >> s;
for (int i = 0; i < s.size(); i++) {
if (s.at(i) == '0') {
maru++;
}
if (s.at(i) == '1') {
bou++;
}
}
cout << min(maru, bou) << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int maru = 0, bou = 0;
cin >> s;
for (int i = 0; i < s.size(); i++) {
if (s.at(i) == '0') {
maru++;
}
if (s.at(i) == '1') {
bou++;
}
}
cout << min(maru, bou) * 2 << endl;
} | [
"expression.operation.binary.add"
] | 917,282 | 917,283 | u442754977 | cpp |
p03107 | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int a = 0, b = 0;
for (int i = 0; i < s.length(); i++) {
a += s[i] == '1';
b += s[i] == '0';
}
cout << min(a, b) * 2;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int a = 0, b = 0;
cin >> s;
for (int i = 0; i < s.length(); i++) {
a += s[i] == '1';
b += s[i] == '0';
}
cout << min(a, b) * 2;
return 0;
} | [] | 917,284 | 917,285 | u541786453 | cpp |
p03107 | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int c0 = 0, c1 = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '0')
c0++;
c1++;
}
cout << 2 * min(c0, c1) << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int c0 = 0, c1 = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '0') {
c0++;
} else {
c1++;
}
}
cout << 2 * min(c0, c1) << endl;
} | [
"control_flow.branch.else.add"
] | 917,286 | 917,287 | u091665287 | cpp |
p03107 | #include <algorithm>
#include <iostream>
#include <string>
using namespace std;
// double speed(double a);
int main(void) {
int x = 0, y = 0;
string str;
cin >> str;
for (int i = 0; i < str.length(); i++) {
if (str[i] == '0')
x++;
else if (str[i] == '1')
y++;
}
printf("%d", min(x, y));
return 0;
} | #include <algorithm>
#include <iostream>
#include <string>
using namespace std;
// double speed(double a);
int main(void) {
int x = 0, y = 0;
string str;
cin >> str;
for (int i = 0; i < str.length(); i++) {
if (str[i] == '0')
x++;
else if (str[i] == '1')
y++;
}
printf("%d", 2 * min(x, y));
return 0;
} | [
"expression.operation.binary.add"
] | 917,288 | 917,289 | u337845373 | cpp |
p03107 | #include <iostream>
#include <stack>
using namespace std;
int main() {
string S;
cin >> S;
stack<char> st;
int res = 0;
for (int i = 0; i < S.size(); i++) {
if (st.empty())
st.push(S[i]);
if ((st.top() == '0' && S[i] == '1') || (st.top() == '1' && S[i] == '0')) {
st.pop();
res += 2;
} else {
st.push(S[i]);
}
}
cout << res << endl;
return 0;
} | #include <iostream>
#include <stack>
using namespace std;
int main() {
string S;
cin >> S;
stack<char> st;
int res = 0;
for (int i = 0; i < S.size(); i++) {
if (st.empty()) {
st.push(S[i]);
} else {
if ((st.top() == '0' && S[i] == '1') ||
(st.top() == '1' && S[i] == '0')) {
st.pop();
res += 2;
} else {
st.push(S[i]);
}
}
}
cout << res << endl;
return 0;
} | [
"control_flow.branch.else.add"
] | 917,292 | 917,293 | u188117876 | cpp |
p03107 | #include <iostream>
int A[] = {0, 0};
int main(void) {
while (true) {
char c = getchar();
if (c == EOF)
break;
A[c - '0']++;
}
printf("%d\n", (A[0] > A[1] ? A[1] : A[0]) << 1);
return 0;
} | #include <iostream>
int A[] = {0, 0};
int main(void) {
while (true) {
char c = getchar();
if (c == '\n')
break;
A[c - '0']++;
}
printf("%d\n", (A[0] > A[1] ? A[1] : A[0]) << 1);
return 0;
}
| [
"control_flow.branch.if.condition.change"
] | 917,310 | 917,311 | u394853232 | cpp |
p03107 | #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
int cou0 = 0, cou1 = 0;
for (int i = 0; i < S.size(); i++) {
if (S[i] == '0')
cou0++;
else
cou1++;
}
cout << min(cou0, cou1) << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
int cou0 = 0, cou1 = 0;
for (int i = 0; i < S.size(); i++) {
if (S[i] == '0')
cou0++;
else
cou1++;
}
cout << 2 * min(cou0, cou1) << endl;
} | [
"expression.operation.binary.add"
] | 917,320 | 917,321 | u415916075 | cpp |
p03107 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
int main() {
string s;
cin >> s;
stack<char> amari;
char prev = 'n';
int ans = 0;
rep(i, s.size()) {
if (prev == 'n') {
prev = s[i];
continue;
}
if (prev != s[i]) {
ans += 2;
prev = 'n';
} else {
if (!amari.empty() && amari.top() != prev) {
ans += 2;
prev = s[i];
amari.pop();
} else {
amari.push(prev);
prev = s[i];
}
}
}
if (!amari.empty()) {
if (prev != amari.top())
ans += 2;
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
int main() {
string s;
cin >> s;
stack<char> amari;
char prev = 'n';
int ans = 0;
rep(i, s.size()) {
if (prev == 'n') {
prev = s[i];
continue;
}
if (prev != s[i]) {
ans += 2;
prev = 'n';
} else {
if (!amari.empty() && amari.top() != prev) {
ans += 2;
prev = s[i];
amari.pop();
} else {
amari.push(prev);
prev = s[i];
}
}
}
if (!amari.empty() && prev != 'n') {
if (prev != amari.top())
ans += 2;
}
cout << ans << endl;
return 0;
} | [
"control_flow.branch.if.condition.change"
] | 917,331 | 917,332 | u200509145 | cpp |
p03107 | #include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(a) a.begin(), a.end()
#define P pair<long long, long long>
#define double long double
using namespace std;
signed main() {
string a;
cin >> a;
int b, c;
rep(i, a.size()) {
if (a.at(i) == '0')
c++;
else
b++;
}
cout << min(c, b) * 2;
}
| #include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(a) a.begin(), a.end()
#define P pair<long long, long long>
#define double long double
using namespace std;
signed main() {
string a;
cin >> a;
int b = 0, c = 0;
rep(i, a.size()) {
if (a.at(i) == '0')
c++;
else
b++;
}
cout << min(c, b) * 2;
}
| [
"variable_declaration.value.change"
] | 917,333 | 917,334 | u341447450 | cpp |
p03107 | #include <cmath>
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
int main() {
int n, z = 0, o = 0;
cin >> n;
string s;
cin >> s;
for (int i = 0; i < s.length(); i++) {
if (s[i] == '0')
z++;
else
o++;
}
cout << 2 * min(z, o) << endl;
} | #include <cmath>
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
int main() {
int n, z = 0, o = 0;
string s;
cin >> s;
for (int i = 0; i < s.length(); i++) {
if (s[i] == '0')
z++;
else
o++;
}
cout << 2 * min(z, o) << endl;
} | [] | 917,339 | 917,340 | u476534289 | cpp |
p03107 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
// ABC120C - Unification
// https://atcoder.jp/contests/abc120/tasks/abc120_c
void ABC120C() {
string S;
cin >> S;
/*
消した時点で上からキューブが落ちて来る
→ 消したら一つだけ戻れば良い
落ちてきても消せない場合は、スタート地点がどんどん上になっていく
*/
int ans = 0;
int i = 0;
while (i < S.size()) {
// cout << "S.size() : " << S.size() << endl;
if (S.substr(i, 2) == "01" || S.substr(i, 2) == "10") {
// if (S.substr(i, 2) == "01") {
// 2文字消去
S = S.erase(i, 2);
// cout << S << endl;
//消した文字数をカウント
ans += 2;
//消したら上のキューブが落ちてくるので1個戻って判定をやり直す
if (i > 1) {
i--;
}
// cout << "i : " << i << endl;
continue;
}
//ヒットしないときは次へ進む
i++;
}
// cout << S << endl;
cout << ans << endl;
}
int main() {
ABC120C();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
// ABC120C - Unification
// https://atcoder.jp/contests/abc120/tasks/abc120_c
void ABC120C() {
string S;
cin >> S;
int ans = 0;
int i = 0;
while (i < S.size()) {
// cout << "S.size() : " << S.size() << endl;
// cout << "------" << endl;
if (S.substr(i, 2) == "01" || S.substr(i, 2) == "10") {
// if (S.substr(i, 2) == "01") {
// 2文字消去
S = S.erase(i, 2);
// cout << S << endl;
//消した文字数をカウント
ans += 2;
//消したら上のキューブが落ちてくるので1個戻って判定をやり直す
if (i >= 1) {
i--;
}
// cout << "i : " << i << endl;
continue;
}
//ヒットしないときは次へ進む
i++;
}
// cout << S << endl;
cout << ans << endl;
}
int main() {
ABC120C();
return 0;
} | [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 917,343 | 917,344 | u725069695 | cpp |
p03107 | #include <bits/stdc++.h>
using namespace std;
string s;
int one, zero;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> s;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '1')
one++;
else
zero++;
}
cout << min(one, zero) << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
string s;
int one, zero;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> s;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '1')
one++;
else
zero++;
}
cout << min(one, zero) * 2 << endl;
return 0;
} | [
"expression.operation.binary.add"
] | 917,345 | 917,346 | u961846252 | cpp |
p03107 | #include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) reps(i, 0, n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
ll N, M, H, W, K, A, B;
string S;
string alpha = "abcdefghijklmnopqrstuvwxyz";
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main() {
cin >> S;
ll ss = S.size();
ll n0 = 0, n1 = 0;
rep(i, ss) {
if (S[i] == '0')
++n0;
else
++n1;
}
cout << min(n0, n1) << endl;
} | #include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i, s, n) for (int i = s; i < n; i++)
#define rep(i, n) reps(i, 0, n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
ll N, M, H, W, K, A, B;
string S;
string alpha = "abcdefghijklmnopqrstuvwxyz";
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main() {
cin >> S;
ll ss = S.size();
ll n0 = 0, n1 = 0;
rep(i, ss) {
if (S[i] == '0')
++n0;
else
++n1;
}
cout << min(n0, n1) * 2 << endl;
} | [
"expression.operation.binary.add"
] | 917,349 | 917,350 | u016531517 | cpp |
p03107 | #include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <numeric>
#include <queue>
#include <stack>
#include <vector>
using namespace std;
int main() {
string s;
cin >> s;
int redcnt = 0;
int bluecnt = 0;
for (int i = 0; i < s.length(); i++) {
if (s[i] == '0')
redcnt++;
else
bluecnt++;
}
cout << min(redcnt, bluecnt) << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <numeric>
#include <queue>
#include <stack>
#include <vector>
using namespace std;
int main() {
string s;
cin >> s;
int redcnt = 0;
int bluecnt = 0;
for (int i = 0; i < s.length(); i++) {
if (s[i] == '0')
redcnt++;
else
bluecnt++;
}
cout << min(redcnt, bluecnt) * 2 << endl;
return 0;
} | [
"expression.operation.binary.add"
] | 917,353 | 917,354 | u947304300 | cpp |
p03107 | #define _USE_NATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, m, n) for (int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)
using ll = long long;
const int inf = 1e9 + 7;
#define EPS 1e-9
int main() {
string s;
cin >> s;
int n = s.size();
int res;
stack<char> st;
rep(i, n) {
if (st.empty() || st.top() == s[i]) {
st.push(s[i]);
} else {
res += 2;
st.pop();
}
}
cout << res << endl;
return 0;
} | #define _USE_NATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, m, n) for (int i = (int)m; i < (int)n; ++i)
#define rep(i, n) REP(i, 0, n)
using ll = long long;
const int inf = 1e9 + 7;
#define EPS 1e-9
int main() {
string s;
cin >> s;
int n = s.size();
int res = 0;
stack<char> st;
rep(i, n) {
if (st.empty() || st.top() == s[i]) {
st.push(s[i]);
} else {
res += 2;
st.pop();
}
}
cout << res << endl;
return 0;
} | [
"variable_declaration.value.change"
] | 917,363 | 917,364 | u419390395 | cpp |
p03107 | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
string S;
cin >> S;
int red;
int blue;
for (int i = 0; i < S.size(); ++i) {
if (S[i] == '0') {
++red;
} else {
++blue;
}
}
int ans = min(red, blue) * 2;
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
string S;
cin >> S;
int red = 0;
int blue = 0;
for (int i = 0; i < S.size(); ++i) {
if (S[i] == '0') {
++red;
} else {
++blue;
}
}
int ans = min(red, blue) * 2;
cout << ans << endl;
return 0;
} | [
"variable_declaration.value.change"
] | 917,367 | 917,368 | u894555185 | cpp |
p03107 | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
string S;
int N, cnt, c1, c0;
cnt = c1 = c0 = 0;
cin >> S;
N = S.size();
for (int i = 0; i < N - 1; ++i) {
if (S[i] == '1')
c1++;
else
c0++;
}
if (c1 >= c0)
cnt = 2 * c0;
else
cnt = 2 * c1;
cout << cnt << endl;
} | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
string S;
int N, cnt, c1, c0;
cnt = c1 = c0 = 0;
cin >> S;
N = S.size();
for (int i = 0; i < N; ++i) {
if (S[i] == '1')
c1++;
else
c0++;
}
if (c1 >= c0)
cnt = 2 * c0;
else
cnt = 2 * c1;
cout << cnt << endl;
} | [
"control_flow.loop.for.condition.change",
"expression.operation.binary.remove"
] | 917,371 | 917,372 | u954253447 | cpp |
p03107 | #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
int a = 0;
int b = 0;
for (auto &s : S) {
if (s == '0') {
a++;
} else {
b++;
}
cout << min(a, b) << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
int a = 0;
int b = 0;
for (auto &s : S) {
if (s == '0') {
a++;
} else {
b++;
}
}
cout << min(a, b) * 2 << endl;
return 0;
} | [
"expression.operation.binary.add"
] | 917,373 | 917,374 | u471342385 | cpp |
p03107 | #include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define REP(i, num, n) for (ll i = num, i##_len = (n); i < i##_len; ++i)
#define repprev(i, a, b) for (ll i = b - 1; i >= a; i--)
#define reprev(i, n) repprev(i, 0, n)
using namespace std;
#define sz(x) ((int)(x).size())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
template <class T> int former(const vector<T> &v, T x) {
return upper_bound(v.begin(), v.end(), x) - v.begin() - 1;
}
template <class T> int latter(const vector<T> &v, T x) {
return lower_bound(v.begin(), v.end(), x) - v.begin();
}
#define pb push_back
#define mp make_pair
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define BIT_FLAG_0 (1 << 0) // 0000 0000 0000 0001
#define BIT_FLAG_1 (1 << 1) // 0000 0000 0000 0010
#define BIT_FLAG_2 (1 << 2) // 0000 0000 0000 0100
#define BIT_FLAG_3 (1 << 3) // 0000 0000 0000 1000
#define BIT_FLAG_4 (1 << 4) // 0000 0000 0001 0000
#define BIT_FLAG_5 (1 << 5) // 0000 0000 0010 0000
#define BIT_FLAG_6 (1 << 6) // 0000 0000 0100 0000
#define BIT_FLAG_7 (1 << 7) // 0000 0000 1000 0000
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
const ll LLINF = 1LL << 60;
const int INTINF = 1 << 30;
const int MAX = 510000;
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;
}
struct UnionFind {
vector<ll> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2
UnionFind(ll n) : par(n, -1) {}
void init(ll n) { par.assign(n, -1); }
ll root(ll x) {
if (par[x] < 0)
return x;
else
return par[x] = root(par[x]);
}
bool issame(ll x, ll y) { return root(x) == root(y); }
bool merge(ll x, ll y) {
x = root(x);
y = root(y);
if (x == y)
return false;
if (par[x] > par[y])
swap(x, y); // merge technique
par[x] += par[y];
par[y] = x;
return true;
}
ll size(ll x) { return -par[root(x)]; }
};
template <typename T>
vector<T> dijkstra(int s, vector<vector<pair<int, T>>> &G) {
const T INF = numeric_limits<T>::max();
using P = pair<T, int>;
int n = G.size();
vector<T> d(n, INF);
vector<int> b(n, -1);
priority_queue<P, vector<P>, greater<P>> q;
d[s] = 0;
q.emplace(d[s], s);
while (!q.empty()) {
P p = q.top();
q.pop();
int v = p.second;
if (d[v] < p.first)
continue;
for (auto &e : G[v]) {
int u = e.first;
T c = e.second;
if (d[u] > d[v] + c) {
d[u] = d[v] + c;
b[u] = v;
q.emplace(d[u], u);
}
}
}
return d;
}
vector<vector<int>> bfs(vector<string> &s, int sy, int sx, char wall, int dir) {
int h = s.size(), w = s.front().size();
vector<vector<int>> dp(h, vector<int>(w, -1));
using P = pair<int, int>;
queue<P> q;
dp[sy][sx] = 0;
q.emplace(sy, sx);
int dy[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dx[] = {0, 0, 1, -1, 1, -1, 1, -1};
auto in = [&](int y, int x) { return 0 <= y && y < h && 0 <= x && x < w; };
while (!q.empty()) {
int y, x;
tie(y, x) = q.front();
q.pop();
for (int k = 0; k < dir; k++) {
int ny = y + dy[k], nx = x + dx[k];
if (!in(ny, nx) || s[ny][nx] == wall)
continue;
if (~dp[ny][nx])
continue;
dp[ny][nx] = dp[y][x] + 1;
q.emplace(ny, nx);
}
}
return dp;
}
int64_t power(int64_t x, int64_t n, int64_t mod) {
int64_t ret = 1;
while (n > 0) {
if (n & 1)
(ret *= x) %= mod;
(x *= x) %= mod;
n >>= 1;
}
return ret;
}
vector<int> sieve_of_eratosthenes(int n) {
vector<int> primes(n);
for (int i = 2; i < n; ++i)
primes[i] = i;
for (int i = 2; i * i < n; ++i)
if (primes[i])
for (int j = i * i; j < n; j += i)
primes[j] = 0;
return primes;
}
std::vector<ll> divisor(ll n) // nの約数を列挙
{
std::vector<ll> ret;
for (ll i = 1; i * i <= n; ++i) {
if (n % i == 0) {
ret.push_back(i);
if (i != 1 && i * i != n) {
ret.push_back(n / i);
}
}
}
return ret;
}
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
string s;
cin >> s;
ll count0 = 0;
ll count1 = 0;
rep(i, s.size()) {
if (s.size() == '0')
count0++;
else
count1++;
}
cout << min(count0, count1) * 2 << endl;
} | #include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define REP(i, num, n) for (ll i = num, i##_len = (n); i < i##_len; ++i)
#define repprev(i, a, b) for (ll i = b - 1; i >= a; i--)
#define reprev(i, n) repprev(i, 0, n)
using namespace std;
#define sz(x) ((int)(x).size())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
template <class T> int former(const vector<T> &v, T x) {
return upper_bound(v.begin(), v.end(), x) - v.begin() - 1;
}
template <class T> int latter(const vector<T> &v, T x) {
return lower_bound(v.begin(), v.end(), x) - v.begin();
}
#define pb push_back
#define mp make_pair
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define BIT_FLAG_0 (1 << 0) // 0000 0000 0000 0001
#define BIT_FLAG_1 (1 << 1) // 0000 0000 0000 0010
#define BIT_FLAG_2 (1 << 2) // 0000 0000 0000 0100
#define BIT_FLAG_3 (1 << 3) // 0000 0000 0000 1000
#define BIT_FLAG_4 (1 << 4) // 0000 0000 0001 0000
#define BIT_FLAG_5 (1 << 5) // 0000 0000 0010 0000
#define BIT_FLAG_6 (1 << 6) // 0000 0000 0100 0000
#define BIT_FLAG_7 (1 << 7) // 0000 0000 1000 0000
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
const ll LLINF = 1LL << 60;
const int INTINF = 1 << 30;
const int MAX = 510000;
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;
}
struct UnionFind {
vector<ll> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2
UnionFind(ll n) : par(n, -1) {}
void init(ll n) { par.assign(n, -1); }
ll root(ll x) {
if (par[x] < 0)
return x;
else
return par[x] = root(par[x]);
}
bool issame(ll x, ll y) { return root(x) == root(y); }
bool merge(ll x, ll y) {
x = root(x);
y = root(y);
if (x == y)
return false;
if (par[x] > par[y])
swap(x, y); // merge technique
par[x] += par[y];
par[y] = x;
return true;
}
ll size(ll x) { return -par[root(x)]; }
};
template <typename T>
vector<T> dijkstra(int s, vector<vector<pair<int, T>>> &G) {
const T INF = numeric_limits<T>::max();
using P = pair<T, int>;
int n = G.size();
vector<T> d(n, INF);
vector<int> b(n, -1);
priority_queue<P, vector<P>, greater<P>> q;
d[s] = 0;
q.emplace(d[s], s);
while (!q.empty()) {
P p = q.top();
q.pop();
int v = p.second;
if (d[v] < p.first)
continue;
for (auto &e : G[v]) {
int u = e.first;
T c = e.second;
if (d[u] > d[v] + c) {
d[u] = d[v] + c;
b[u] = v;
q.emplace(d[u], u);
}
}
}
return d;
}
vector<vector<int>> bfs(vector<string> &s, int sy, int sx, char wall, int dir) {
int h = s.size(), w = s.front().size();
vector<vector<int>> dp(h, vector<int>(w, -1));
using P = pair<int, int>;
queue<P> q;
dp[sy][sx] = 0;
q.emplace(sy, sx);
int dy[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dx[] = {0, 0, 1, -1, 1, -1, 1, -1};
auto in = [&](int y, int x) { return 0 <= y && y < h && 0 <= x && x < w; };
while (!q.empty()) {
int y, x;
tie(y, x) = q.front();
q.pop();
for (int k = 0; k < dir; k++) {
int ny = y + dy[k], nx = x + dx[k];
if (!in(ny, nx) || s[ny][nx] == wall)
continue;
if (~dp[ny][nx])
continue;
dp[ny][nx] = dp[y][x] + 1;
q.emplace(ny, nx);
}
}
return dp;
}
int64_t power(int64_t x, int64_t n, int64_t mod) {
int64_t ret = 1;
while (n > 0) {
if (n & 1)
(ret *= x) %= mod;
(x *= x) %= mod;
n >>= 1;
}
return ret;
}
vector<int> sieve_of_eratosthenes(int n) {
vector<int> primes(n);
for (int i = 2; i < n; ++i)
primes[i] = i;
for (int i = 2; i * i < n; ++i)
if (primes[i])
for (int j = i * i; j < n; j += i)
primes[j] = 0;
return primes;
}
std::vector<ll> divisor(ll n) // nの約数を列挙
{
std::vector<ll> ret;
for (ll i = 1; i * i <= n; ++i) {
if (n % i == 0) {
ret.push_back(i);
if (i != 1 && i * i != n) {
ret.push_back(n / i);
}
}
}
return ret;
}
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
string s;
cin >> s;
ll count0 = 0;
ll count1 = 0;
rep(i, s.size()) {
if (s[i] == '0')
count0++;
else
count1++;
}
cout << min(count0, count1) * 2 << endl;
}
| [
"control_flow.branch.if.condition.change"
] | 917,380 | 917,381 | u135572611 | cpp |
p03107 | #include <algorithm>
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <bits/stdc++.h>
#include <cstdint>
#include <limits>
#include <queue>
#include <type_traits>
using namespace std;
int main() {
string x;
cin >> x;
long long count_0 = 0;
long long count_1 = 1;
for (int i = 0; i < x.length(); i++) {
if (x[i] == '0') {
count_0 += 1;
} else if (x[i] == '1') {
count_1 += 1;
}
}
cout << min(count_0, count_1) * 2 << endl;
}
| #include <algorithm>
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <bits/stdc++.h>
#include <cstdint>
#include <limits>
#include <queue>
#include <type_traits>
using namespace std;
int main() {
string x;
cin >> x;
long long count_0 = 0;
long long count_1 = 0;
for (int i = 0; i < x.length(); i++) {
if (x[i] == '0') {
count_0 += 1;
} else if (x[i] == '1') {
count_1 += 1;
}
}
cout << min(count_0, count_1) * 2 << endl;
}
| [
"literal.number.change",
"variable_declaration.value.change"
] | 917,390 | 917,391 | u759162415 | cpp |
p03107 | #include <algorithm>
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <bits/stdc++.h>
#include <cstdint>
#include <limits>
#include <queue>
#include <type_traits>
using namespace std;
int main() {
string x;
cin >> x;
int count_0 = 0;
int count_1 = 1;
for (int i = 0; i < x.length(); i++) {
if (x[i] == '0') {
count_0 += 1;
} else if (x[i] == '1') {
count_1 += 1;
}
}
cout << min(count_0, count_1) * 2 << endl;
}
| #include <algorithm>
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <bits/stdc++.h>
#include <cstdint>
#include <limits>
#include <queue>
#include <type_traits>
using namespace std;
int main() {
string x;
cin >> x;
long long count_0 = 0;
long long count_1 = 0;
for (int i = 0; i < x.length(); i++) {
if (x[i] == '0') {
count_0 += 1;
} else if (x[i] == '1') {
count_1 += 1;
}
}
cout << min(count_0, count_1) * 2 << endl;
}
| [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change",
"literal.number.change",
"variable_declaration.value.change"
] | 917,392 | 917,391 | u759162415 | cpp |
p03107 | #include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <math.h>
#include <string>
#include <utility>
#include <vector>
#define INF 1000000009;
using namespace std;
int gcd(int a, int b) {
while (a % b != 0) {
int c = 0;
c = a % b;
a = b;
b = c;
}
return b;
}
string cube;
int main() {
cin >> cube;
int aka = 0, ao = 0;
for (int i = 0; i < cube.size(); i++) {
if (cube[i] == '0') {
aka++;
} else {
ao++;
}
}
cout << min(aka, ao) << endl;
return 0;
}
| #include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <math.h>
#include <string>
#include <utility>
#include <vector>
#define INF 1000000009;
using namespace std;
int gcd(int a, int b) {
while (a % b != 0) {
int c = 0;
c = a % b;
a = b;
b = c;
}
return b;
}
string cube;
int main() {
cin >> cube;
int aka = 0, ao = 0;
for (int i = 0; i < cube.size(); i++) {
if (cube[i] == '0') {
aka++;
} else {
ao++;
}
}
cout << min(aka, ao) * 2 << endl;
return 0;
}
| [
"expression.operation.binary.add"
] | 917,393 | 917,394 | u019465635 | cpp |
p03107 | #include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define MOD 1000000007;
int main() {
stack<char> st;
char c;
int ans = 0;
while (cin >> c) {
if (st.empty() || st.top() != c)
st.push(c);
else {
st.pop();
ans += 2;
}
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define MOD 1000000007;
int main() {
stack<char> st;
char c;
int ans = 0;
while (cin >> c) {
if (st.empty() || st.top() == c)
st.push(c);
else {
st.pop();
ans += 2;
}
}
cout << ans << endl;
return 0;
} | [
"misc.opposites",
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 917,397 | 917,398 | u608258653 | cpp |
p03107 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int main() {
string s;
cin >> s;
int c0 = 0, c1 = 1;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '0')
c0++;
else
c1++;
}
cout << 2 * min(c0, c1);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int main() {
string s;
cin >> s;
int c0 = 0, c1 = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '0')
c0++;
else
c1++;
}
cout << 2 * min(c0, c1);
return 0;
} | [
"literal.number.change",
"variable_declaration.value.change"
] | 917,401 | 917,402 | u129667379 | cpp |
p03107 | #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
int cnt1 = 0;
int cnt2 = 0;
for (int i = 0; i < S.size(); i++) {
if (S[i] == '0') {
cnt1++;
} else if (S[i] == '0') {
cnt2++;
}
}
cout << 2 * min(cnt1, cnt2) << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
int cnt1 = 0;
int cnt2 = 0;
for (int i = 0; i < S.size(); i++) {
if (S[i] == '0') {
cnt1++;
} else if (S[i] == '1') {
cnt2++;
}
}
cout << 2 * min(cnt1, cnt2) << endl;
return 0;
}
| [
"literal.string.change",
"control_flow.branch.if.condition.change"
] | 917,406 | 917,407 | u904123392 | cpp |
p03107 | #include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
char s[100002];
int len, i, count = 0;
len = strlen(s);
for (i = 0; i < len; i++) {
if (s[i] == '0')
count++;
}
cout << 2 * min(count, len - count);
return 0;
}
| #include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
char s[100002];
cin >> s;
int len, i, count = 0;
len = strlen(s);
for (i = 0; i < len; i++) {
if (s[i] == '0')
count++;
}
cout << 2 * min(count, len - count);
return 0;
} | [] | 917,414 | 917,415 | u340494803 | cpp |
p03107 | #include <algorithm>
#include <iostream>
#include <string>
using namespace std;
main() {
string S;
cin >> S;
int cnta = 0, cntb = 0;
for (int i = 0; i < S.size(); i++) {
if (S[i] == '0')
cnta++;
else
cntb++;
}
cout << S.size() - min(cnta, cntb) * 2 << endl;
} | #include <algorithm>
#include <iostream>
#include <string>
using namespace std;
main() {
string S;
cin >> S;
int cnta = 0, cntb = 0;
for (int i = 0; i < S.size(); i++) {
if (S[i] == '0')
cnta++;
else
cntb++;
}
cout << min(cnta, cntb) * 2 << endl;
}
| [
"expression.operation.binary.remove"
] | 917,416 | 917,417 | u157322125 | cpp |
p03107 | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <set>
#include <string>
#include <vector>
typedef long long ll;
const int mod = 1e9 + 7;
#define lol(i, n) for (int i = 0; i < n; i++)
#define tot(i, n) for (int i = 1; i <= n; i++)
using namespace std;
string s;
int main() {
cin >> s;
int a, b;
a = b = 0;
int k = s.length();
for (int i = 0; i < k - 1; i++) {
if (s[i] == '0')
a++;
if (s[i] == '1')
b++;
}
cout << min(a, b) * 2 << endl;
} | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <set>
#include <string>
#include <vector>
typedef long long ll;
const int mod = 1e9 + 7;
#define lol(i, n) for (int i = 0; i < n; i++)
#define tot(i, n) for (int i = 1; i <= n; i++)
using namespace std;
string s;
int main() {
cin >> s;
int a, b, k;
a = b = 0;
k = s.length();
for (int i = 0; i < k; i++) {
if (s[i] == '0')
a++;
if (s[i] == '1')
b++;
}
cout << min(a, b) * 2 << endl;
} | [
"variable_declaration.add",
"control_flow.loop.for.condition.change",
"expression.operation.binary.remove"
] | 917,422 | 917,423 | u190066528 | cpp |
p03107 | #include <iostream>
#include <string>
using namespace std;
int main() {
string s;
cin >> s;
int a, b;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '0') {
a++;
} else {
b++;
}
}
cout << min(a, b) * 2 << endl;
} | #include <iostream>
#include <string>
using namespace std;
int main() {
string s;
cin >> s;
int a = 0, b = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '0') {
a++;
} else {
b++;
}
}
cout << min(a, b) * 2 << endl;
} | [
"variable_declaration.value.change"
] | 917,426 | 917,427 | u130834452 | cpp |
p03107 | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int counta = 0, countb = 0;
for (int i = 0; i < s.size(); i++) {
if (s.at(i) == 'O') {
counta++;
}
}
for (int i = 0; i < s.size(); i++) {
if (s.at(i) == '1') {
countb++;
}
}
cout << min(counta, countb) * 2 << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int counta = 0, countb = 0;
for (int i = 0; i < s.size(); i++) {
if (s.at(i) == '0') {
counta++;
}
}
for (int i = 0; i < s.size(); i++) {
if (s.at(i) == '1') {
countb++;
}
}
cout << min(counta, countb) * 2 << endl;
} | [
"literal.string.change",
"control_flow.branch.if.condition.change"
] | 917,431 | 917,432 | u593555034 | cpp |
p03107 | #include <bits/stdc++.h>
using namespace std;
int main() {
string str;
cin >> str;
int ones = 0;
for (int i = 0; i < (int)str.size(); ++i) {
if (str[i] == '1') {
ones++;
}
}
int res = min(ones, (int)str.size() - ones);
cout << res << "\n";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string str;
cin >> str;
int ones = 0;
for (int i = 0; i < (int)str.size(); ++i) {
if (str[i] == '1') {
ones++;
}
}
int res = min(ones, (int)str.size() - ones) * 2;
cout << res << "\n";
return 0;
}
| [
"assignment.change"
] | 917,437 | 917,438 | u210162517 | cpp |
p03107 | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
string S;
cin >> S;
int C_0 = 0, C_1 = 0;
for (int i = 0; i < S.size(); i++) {
if (S[i] == '0')
C_0++;
if (S[i] == '1')
C_1++;
}
cout << min(C_0, C_1) << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
string S;
cin >> S;
int C_0 = 0, C_1 = 0;
for (int i = 0; i < S.size(); i++) {
if (S[i] == '0')
C_0++;
if (S[i] == '1')
C_1++;
}
cout << 2 * min(C_0, C_1) << endl;
return 0;
} | [
"expression.operation.binary.add"
] | 917,450 | 917,451 | u382176401 | cpp |
p03107 | #include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
int main(int argc, const char *argv[]) {
string s;
cin >> s;
int z = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '0') {
z++;
}
}
z = min(z, (int)s.size() / 2);
cout << z * 2 << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
int main(int argc, const char *argv[]) {
string s;
cin >> s;
int z = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '0') {
z++;
}
}
z = min(z, (int)s.size() - z);
cout << z * 2 << endl;
return 0;
} | [] | 917,452 | 917,453 | u769062455 | cpp |
p03107 | #include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
int main() {
string s;
cin >> s;
int count = 0, res = 0;
char now;
for (int i = 1; i < s.size() - 1; ++i) {
if (count == 0) {
now = s[i];
++count;
} else if (now == s[i]) {
++count;
} else {
++res;
--count;
}
}
cout << res * 2 << endl;
}
| #include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
int main() {
string s;
cin >> s;
int count = 0, res = 0;
char now;
for (int i = 0; i < s.size(); ++i) {
if (count == 0) {
now = s[i];
++count;
} else if (now == s[i]) {
++count;
} else {
++res;
--count;
}
}
cout << res * 2 << endl;
}
| [
"literal.number.change",
"variable_declaration.value.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one",
"control_flow.loop.for.condition.change",
"expression.operation.binary.remove"
] | 917,456 | 917,457 | u521389909 | cpp |
p03107 | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int a, b, ans = 0;
for (int i = 0; i < (int)s.length(); ++i) {
if (s[i] == '0')
a++;
else {
b++;
}
}
cout << 2 * min(a, b);
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int a = 0, b = 0, ans = 0;
for (int i = 0; i < (int)s.length(); ++i) {
if (s[i] == '0')
a++;
else {
b++;
}
}
cout << 2 * min(a, b);
} | [
"variable_declaration.value.change"
] | 917,458 | 917,459 | u709810602 | cpp |
p03107 | #include <iostream>
#include <string>
using namespace std;
int main() {
string s;
int n = 0;
cin >> s;
for (int i = 0; i < s.size();) {
if (s.substr(i, 2) == "01" || s.substr(i, 2) == "10") {
n += 2;
s.erase(i, 2);
if (i != 1)
i--;
} else {
i++;
}
}
cout << n << endl;
return 0;
} | #include <iostream>
#include <string>
using namespace std;
int main() {
string s;
int n = 0;
cin >> s;
for (int i = 0; i < s.size();) {
if (s.substr(i, 2) == "01" || s.substr(i, 2) == "10") {
n += 2;
s.erase(i, 2);
if (i != 0)
i--;
} else {
i++;
}
}
cout << n << endl;
return 0;
} | [
"literal.number.change",
"control_flow.branch.if.condition.change"
] | 917,460 | 917,461 | u493122449 | cpp |
p03107 | #include <iostream>
#include <string>
using namespace std;
int main() {
string s;
int n = 0;
cin >> s;
for (int i = 0; i < s.size();) {
if (s.substr(i, 2) == "01" || s.substr(i, 2) == "10") {
n += 2;
s.erase(i, 2);
if (i > 1)
i -= 2;
} else {
i++;
}
}
cout << n << endl;
return 0;
} | #include <iostream>
#include <string>
using namespace std;
int main() {
string s;
int n = 0;
cin >> s;
for (int i = 0; i < s.size();) {
if (s.substr(i, 2) == "01" || s.substr(i, 2) == "10") {
n += 2;
s.erase(i, 2);
if (i != 0)
i--;
} else {
i++;
}
}
cout << n << endl;
return 0;
} | [
"control_flow.loop.for.condition.change"
] | 917,462 | 917,461 | u493122449 | cpp |
p03107 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
const ll mod = ll(1e9) + 7;
const int INF = int(1e9);
int main() {
string S;
cin >> S;
int cnt0 = 0, cnt1 = 1;
rep(i, S.size()) {
if (S[i] == '0')
cnt0++;
else
cnt1++;
}
cout << min(cnt0, cnt1) * 2 << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
const ll mod = ll(1e9) + 7;
const int INF = int(1e9);
int main() {
string S;
cin >> S;
int cnt0 = 0, cnt1 = 0;
rep(i, S.size()) {
if (S[i] == '0')
cnt0++;
else
cnt1++;
}
cout << min(cnt0, cnt1) * 2 << endl;
return 0;
}
| [
"literal.number.change",
"variable_declaration.value.change"
] | 917,463 | 917,464 | u906880177 | cpp |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.