#include "Anna.h"
#include <bits/stdc++.h>
using i64 = long long;
namespace {
#ifdef DEBUG
#include "/home/ahmetalp/Desktop/Workplace/debug.h"
#else
#define debug(...) void(23)
#endif
constexpr int L = 60;
};
int Declare() {
return L * 3;
}
std::pair<std::vector<int>, std::vector<int>> Anna(i64 A) {
--A;
std::vector<int> a;
std::vector<int> b;
for (int i = 0; i < L; ++i) {
int x = A >> (L - 1 - i) & 1;
for (int j = 0; j < 3; ++j) {
a.emplace_back(x);
}
}
for (int i = 0; i < L / 2 * 3; ++i) {
b.emplace_back(0);
b.emplace_back(1);
}
debug(a);
debug(b);
return {a, b};
}
#include "Bruno.h"
#include <bits/stdc++.h>
using i64 = long long;
namespace {
#ifdef DEBUG
#include "/home/ahmetalp/Desktop/Workplace/debug.h"
#else
#define debug(...) void(23)
#endif
constexpr int L = 60;
};
i64 Bruno(std::vector<int> u) {
int n = L * 6;
std::vector<int> ps(n + 1);
for (int i = 0; i < n; ++i) {
ps[i + 1] = ps[i] + (2 * u[i] - 1);
}
i64 A = 0;
int p = 0;
int cnt = 0;
int lst = 0;
while (true) {
int q = p;
while (q <= n && ps[p] - 2 + (lst == 1) <= ps[q] && ps[q] <= ps[p] + 2 - (lst == 0)) {
q += 1;
}
if (q == n + 1) {
break;
}
auto vec = std::vector(u.begin() + p, u.begin() + q);
debug(vec);
debug(cnt, p, q, u[q - 1]);
A = A * 2 + u[q - 1];
lst = u[q - 1];
p = q;
cnt += 1;
}
return A + 1;
}