Submission #51431238
Source Code Expand
#define FULL_LIB 1
#define CODETEST 0
#define OPTUNE 0
#define PERFORMANCE 0
#define EVAL 0
#define UNIT_TEST 0
#define TIME_LIMIT (1900)
#define NOT_SUBMIT 0
#define VALIDATION 0
#define IO_FILE 0
#define SELF_JUDGE 0
#define OUTPUT_INFO 0
#define OUTPUT_FINAL_INFO 0
#define OUTPUT_LOG 0
#define OUTPUT_VISUAL 0
#define OUTPUT_PERF 0
#define OUTPUT_COMMENT 0
#define FIX_RESULT 0
#define TIME_LIMIT_US (TIME_LIMIT * 1000)
#define MAKE_PATTERN 0
#define MAKE_ROUTE 0
#define NO_ROUTE 0
#ifdef __clang_version__
#pragma clang diagnostic ignored "-Wunknown-pragmas"
#pragma clang diagnostic ignored "-Wunknown-warning-option"
#pragma clang diagnostic ignored "-Wmissing-braces"
#endif
#ifndef _MSC_VER
#pragma GCC target ("avx2")
#pragma GCC optimize "O3,omit-frame-pointer,inline"
#pragma GCC optimize ("unroll-loops")
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wsign-compare"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-function"
#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
#endif
#define _USE_MATH_DEFINES
#ifdef __clang_version__
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cfenv>
#include <cinttypes>
#include <cstdint>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#else
#include <bits/stdc++.h>
#endif
using namespace std;
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define RFOR(i, s, e) for (int i = int(e) - 1; i >= int(s); --i)
#define REP(i, n) for (int i = 0, i##_size = int(n); i < i##_size; ++i)
#define RREP(i, n) for (int i = int(n) - 1; i >= 0; --i)
#define ALL(x) (x).begin(),(x).end()
template <class T, class U> inline void chmin(T& a, const U& b) { if (b < a) { a = b; } }
template <class T, class U> inline void chmax(T& a, const U& b) { if (a < b) { a = b; } }
template <class T, class U, class V> inline T clip(const T& v, U&& lower, V&& upper) {
if (v < lower) { return lower; }
else if (v > upper) { return upper; }
else { return v; }
}
template <class T, class U, class V> inline void chclip(T& v, const U& lower, const V& upper) {
if (v < lower) { v = lower; }
else if (v > upper) { v = upper; }
}
template <class T> inline constexpr T square(T v) { return v * v; }
template <class T, int SIZE>
constexpr int len(const T(&)[SIZE]) { return SIZE; }
#define cauto const auto
#include <cstdint>
using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using s8 = int8_t;
using s16 = int16_t;
using s32 = int32_t;
using s64 = int64_t;
using TimePoint = chrono::high_resolution_clock::time_point;
struct ChronoTimer {
private:
TimePoint startTime_;
TimePoint endTime_;
public:
inline void Init() {
startTime_ = chrono::high_resolution_clock::now();
endTime_ = startTime_;
}
inline void Start(int limit) {
endTime_ = startTime_ + chrono::milliseconds(limit);
}
inline void StartMs(int limit) {
endTime_ = startTime_ + chrono::milliseconds(limit);
}
inline void StartUs(int limit) {
endTime_ = startTime_ + chrono::microseconds(limit);
}
inline void Join() {
}
inline bool IsOver() const {
return chrono::high_resolution_clock::now() >= endTime_;
}
inline int ElapseTimeMs() const {
return (int)chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - startTime_).count();
}
inline int ElapseTimeUs() const {
return (int)chrono::duration_cast<chrono::microseconds>(chrono::high_resolution_clock::now() - startTime_).count();
}
void SetElapseTimeMs(int ms) {
auto now = chrono::high_resolution_clock::now();
auto limit = endTime_ - startTime_;
startTime_ = now - chrono::milliseconds(ms);
endTime_ = startTime_ + limit;
}
inline int LeftToUS(const TimePoint& limit) const {
return (int)chrono::duration_cast<chrono::microseconds>(limit - chrono::high_resolution_clock::now()).count();
}
inline double NowRate() const {
return (chrono::high_resolution_clock::now() - startTime_).count() / (double)(endTime_ - startTime_).count();
}
inline TimePoint Now() const {
return chrono::high_resolution_clock::now();
}
inline TimePoint StartTime() const {
return startTime_;
}
inline TimePoint EndTime() const {
return endTime_;
}
TimePoint GetLimitTimePointUs(int limit) const {
return startTime_ + chrono::microseconds(limit);
}
};
TimePoint Now() {
return chrono::high_resolution_clock::now();
}
ChronoTimer timer_;
template <class T>
void InstanceRun(int argc, const char* argv[]) {
timer_.Init();
T* m = new T;
m->Run(argc, argv);
quick_exit(0);
}
struct Main;
signed main(int argc, const char* argv[]) {
cin.tie(0);
ios::sync_with_stdio(0);
InstanceRun<Main>(argc, argv);
}
struct MemoryException {};
#define VALIDATE_ABORT()
#define VALIDATE_ASSERT(exp)
#define VABORT() VALIDATE_ABORT()
#define VASSERT(exp) VALIDATE_ASSERT(exp)
template <class A, class B>
struct pr {
union {
A a;
A x;
A first;
};
union {
B b;
B y;
B second;
};
bool operator == (pr const& r) const { return a == r.a && b == r.b; }
bool operator != (pr const& r) const { return !((*this) == r); }
bool operator < (pr const& r) const {
if (a == r.a) {
return b < r.b;
}
return a < r.a;
}
bool operator > (pr const& r) const {
return r < (*this);
}
pr& operator += (pr const& v) {
a += v.a;
b += v.b;
return *this;
}
pr& operator -= (pr const& v) {
a -= v.a;
b -= v.b;
return *this;
}
template <class C, class D>
auto operator + (pr<C, D> const& v) const {
return pr<decltype(a + v.a), decltype(b + v.b)>{ a + v.a, b + v.b };
}
template <class C, class D>
auto operator - (pr<C, D> const& v) const {
return pr<decltype(a - v.a), decltype(b - v.b)>{ a - v.a, b - v.b };
}
template <class C, class D>
explicit operator pr<C, D>() const {
return { C(a), D(b) };
}
template <class T>
auto operator * (T const& v) const -> pr<decltype(x * v), decltype(y * v)> {
return { x * v, y * v };
}
template <class T>
auto operator / (T const& v) const -> pr<decltype(x / v), decltype(y / v)> {
return { x / v, y / v };
}
template <class T>
pr& operator *= (T const& v) {
x *= v;
y *= v;
return *this;
}
template <class T>
pr& operator /= (T const& v) {
x /= v;
y /= v;
return *this;
}
pr operator -() const {
return pr{ -x, -y };
}
void flip() { swap(x, y); }
friend istream& operator>>(istream& is, pr& p) {
is >> p.a >> p.b;
return is;
}
friend ostream& operator<<(ostream& os, pr const& p) {
os << p.a << " " << p.b;
return os;
}
template <size_t I>
auto get() const {
if constexpr (I == 0) {
return x;
}
else if constexpr (I == 1) {
return y;
}
}
};
using pint = pr<int, int>;
using pdouble = pr<double, double>;
static_assert(is_trivially_copyable<pint>::value, "not trivially_copyable");
template <class A, class B>
struct tuple_size<pr<A, B>> : integral_constant<size_t, 2> {};
template <class A, class B>
struct tuple_element<0, pr<A, B>> { using type = A; };
template <class A, class B>
struct tuple_element<1, pr<A, B>> { using type = B; };
inline pdouble ToDouble(const pint& p) {
return pdouble{ double(p.x), double(p.y) };
}
inline pint round(const pdouble& d) {
return pint{ (int)round(d.x), (int)round(d.y) };
}
inline double norm(const pdouble& d) {
return sqrt((d.x * d.x) + (d.y * d.y));
}
inline double norm(const pint& d) {
return norm(ToDouble(d));
}
inline int norm2(const pint& d) {
return square(d.x) + square(d.y);
}
inline double norm2(const pdouble& d) {
return square(d.x) + square(d.y);
}
inline pdouble normalized(const pdouble& d) {
return d / norm(d);
}
inline double dot(const pdouble& a, const pdouble& b) {
return a.x * b.x + a.y * b.y;
}
inline double cross(const pdouble& a, const pdouble& b) {
return a.x * b.y - a.y * b.x;
}
template <class A, class B>
struct pr2 {
A a;
B b;
template <size_t I>
auto get() const {
if constexpr (I == 0) {
return a;
}
else if constexpr (I == 1) {
return b;
}
}
};
#include <cstdint>
struct Xor64 {
using result_type = uint32_t;
static constexpr result_type min() { return 0; }
static constexpr result_type max() { return UINT32_MAX; }
private:
Xor64(const Xor64& r) = delete;
Xor64& operator =(const Xor64& r) = delete;
public:
uint64_t x;
inline Xor64(uint64_t seed = 0) {
x = 88172645463325252ULL + seed;
}
inline uint64_t Get64() {
x ^= (x << 7);
return x ^= (x >> 9);
}
inline result_type operator()() {
return Get64() & 0xFFFFFFFF;
}
template <class T>
inline T operator()(T r) {
VASSERT(r <= 0xFFFFFFFF);
return ((Get64() & 0xFFFFFFFF) * r) >> 32;
}
inline double GetDouble() {
return Get64() / (double)UINT64_MAX;
}
inline bool GetProb(double E) {
return GetDouble() <= E;
}
};
template <class IT>
void Shuffle(IT&& begin, IT&& end, Xor64& rand) {
int size = int(end - begin);
if (size <= 1) {
return;
}
REP(i, size - 1) {
int j = i + rand(size - i);
swap(*(begin + i), *(begin + j));
}
}
template <class T, int CAP>
class CapArr {
private:
friend class CapArr;
static_assert(is_trivially_copyable<T>::value);
T array_[CAP];
int size_ = 0;
public:
CapArr() {
size_ = 0;
}
explicit CapArr(int size) {
resize(size);
}
CapArr(int size, const T& e) {
assign(size, e);
}
bool operator == (const CapArr<T, CAP>& r) const {
if (size_ != r.size_) {
return false;
}
REP(i, size_) {
if (!(array_[i] == r.array_[i])) {
return false;
}
}
return true;
}
template <class U, int U_CAP>
bool operator != (const CapArr<U, U_CAP>& r) const {
return !(*this == r);
}
bool MemEqual(const CapArr<T, CAP>& r) const {
if (size_ != r.size_) {
return false;
}
return memcmp(data(), r.data(), sizeof(T) * size_) == 0;
}
constexpr int capacity() const {
return CAP;
}
int size() const {
return size_;
}
bool empty() const {
return size_ == 0;
}
bool exist() const {
return size_ != 0;
}
void clear() {
size_ = 0;
}
void resize(int size) {
size_ = size;
}
void assign(int size, const T& e) {
size_ = size;
if constexpr (sizeof(T) == 1) {
if constexpr (is_enum<T>::value) {
memset(data(), underlying_type<T>::type(e), size);
}
else {
memset(data(), *reinterpret_cast<const unsigned char*>(&e), size);
}
}
else {
for (int i = 0; i < size; ++i) {
array_[i] = e;
}
}
}
void AssignIota(int size) {
resize(size);
iota(begin(), end(), 0);
}
void Iota(int size) {
resize(size);
iota(begin(), end(), 0);
}
void MemAssign(int size, int byte) {
size_ = size;
memset(data(), byte, sizeof(T) * size);
}
void MemCopy(const CapArr<T, CAP>& from) {
size_ = from.size_;
memcpy(data(), from.data(), sizeof(T) * from.size_);
}
template <int CAP2>
void MemCopy(const CapArr<T, CAP2>& from) {
static_assert(CAP2 <= CAP);
size_ = from.size();
memcpy(data(), from.data(), sizeof(T) * size_);
}
const T* data() const {
return &array_[0];
}
T* data() {
return &array_[0];
}
T& front() {
return array_[0];
}
const T& front() const {
return array_[0];
}
T& back() {
return array_[size_ - 1];
}
const T& back() const {
return array_[size_ - 1];
}
T& operator[](int index) {
return array_[index];
}
const T& operator[](int index) const {
return array_[index];
}
T* begin() {
return &array_[0];
}
T* end() {
return &array_[size_];
}
const T* begin() const {
return &array_[0];
}
const T* end() const {
return &array_[size_];
}
[[nodiscard]] T& push() {
auto& ref = array_[size_];
++size_;
return ref;
}
void push(const T& e) {
array_[size_] = e;
++size_;
}
void pop() {
--size_;
}
int find(const T& value) const {
REP(i, size_) {
if (array_[i] == value) {
return i;
}
}
return -1;
}
bool contains(const T& value) const {
for (const auto& v : *this) {
if (v == value) {
return true;
}
}
return false;
}
void insert(int index, const T& value) {
insert(index, &value, 1);
}
void insert(int index, const T* mem, int size) {
if (index == size_) {
memcpy(data() + index, mem, sizeof(T) * size);
size_ += size;
}
else {
memmove(data() + index + size, data() + index, sizeof(T) * (size_ - index));
memcpy(data() + index, mem, sizeof(T) * size);
size_ += size;
}
}
template <int RCAP>
void append(const CapArr<T, RCAP>& r) {
insert(size(), r.data(), r.size());
}
void remove(int index) {
remove(index, index + 1);
}
void remove(int start, int end) {
int size = end - start;
memmove(data() + start, data() + end, sizeof(T) * (size_ - end));
size_ -= size;
}
void RemoveSwap(int index) {
array_[index] = array_[size_ - 1];
--size_;
}
void RemoveWithKeeps(const CapArr<int, CAP>& idxs) {
int to = 0;
for (int idx : idxs) {
array_[to] = array_[idx];
++to;
}
size_ = idxs.size();
}
void RemoveInsert(int start, int end, const T* p, int size) {
int newEnd = start + size;
if (size_ - end > 0 && newEnd != end) {
memmove(data() + newEnd, data() + end, sizeof(T) * (size_ - end));
}
memcpy(data() + start, p, sizeof(T) * size);
size_ -= end - start;
size_ += size;
}
void sort() {
::sort(begin(), end());
}
void rsort() {
::sort(begin(), end(), greater<T>());
}
template <class LESS>
void sort(LESS&& less) {
::sort(begin(), end(), less);
}
void stable_sort() {
::stable_sort(begin(), end());
}
void stable_rsort() {
::stable_sort(begin(), end(), greater<T>());
}
template <class LESS>
void stable_sort(LESS&& less) {
::stable_sort(begin(), end(), less);
}
void idx_sort(CapArr<int, CAP>& idxs) {
idxs.Iota(size());
idxs.sort([&](int a, int b) {
return array_[a] < array_[b];
});
}
void idx_rsort(CapArr<int, CAP>& idxs) {
idxs.Iota(size());
idxs.sort([&](int a, int b) {
return array_[b] < array_[a];
});
}
void idx_stable_sort(CapArr<int, CAP>& idxs) {
idxs.Iota(size());
idxs.stable_sort([&](int a, int b) {
return array_[a] < array_[b];
});
}
void idx_stable_rsort(CapArr<int, CAP>& idxs) {
idxs.Iota(size());
idxs.stable_sort([&](int a, int b) {
return array_[b] < array_[a];
});
}
template <class LESS>
void nth_element(int n, LESS&& less) {
::nth_element(begin(), begin() + n, end(), less);
}
void reverse() {
::reverse(begin(), end());
}
template <class RAND>
void shuffle(RAND&& r) {
Shuffle(begin(), end(), r);
}
template <class RAND>
const T& choice(RAND&& r) const {
VASSERT(size_ > 0);
return array_[r(size_)];
}
};
template <class T, int CAPACITY>
struct CapacityQueue {
private:
array<T, CAPACITY> ar_ = {};
int start_ = 0;
int end_ = 0;
public:
inline void clear() {
start_ = 0;
end_ = 0;
}
inline void push(const T& v) {
ar_[end_] = v;
++end_;
}
inline T* push() {
T* ptr = &ar_[end_];
++end_;
return ptr;
}
inline const T& get() const {
return ar_[start_];
}
inline T pop() {
return ar_[start_++];
}
inline bool empty() const {
return start_ == end_;
}
inline bool exist() const {
return start_ != end_;
}
inline int size() const {
return end_ - start_;
}
inline int total_push_count() const {
return end_;
}
const T& operator[](int i) const{
return ar_[i];
}
int end_size() const {
return end_;
}
int direct_start() const {
return start_;
}
int direct_end() const {
return end_;
}
inline auto begin() -> decltype(ar_.begin()) {
return ar_.begin() + start_;
}
inline auto end() -> decltype(ar_.begin()) {
return ar_.begin() + end_;
}
inline auto begin() const -> decltype(ar_.begin()) {
return ar_.begin() + start_;
}
inline auto end() const -> decltype(ar_.begin()) {
return ar_.begin() + end_;
}
const T& front() const {
return ar_[start_];
}
const T& back() const {
return ar_[end_ - 1];
}
};
template <class T, int CAPACITY>
using CapQue = CapacityQueue<T, CAPACITY>;
template <int CAP>
struct CapSet {
private:
using Key = typename conditional<CAP <= 256, u8, u32>::type;
CapArr<Key, CAP> elemens;
array<Key, CAP> indexs;
public:
bool operator == (const CapSet<CAP>& r) const {
if (elemens.size() != r.elemens.size()) {
return false;
}
for (Key i : elemens) {
if (!r.contains(i)) {
return false;
}
}
return true;
}
constexpr int capacity() {
return CAP;
}
void fill(int n) {
elemens.resize(n);
iota(ALL(elemens), 0);
iota(indexs.begin(), indexs.begin() + n, 0);
}
void clear() {
elemens.clear();
}
void set(Key i, bool exist) {
if (exist) {
fadd(i);
}
else {
fremove(i);
}
}
void add(Key i) {
indexs[i] = elemens.size();
elemens.push(i);
}
void fadd(Key i) {
if (contains(i)) {
return;
}
indexs[i] = elemens.size();
elemens.push(i);
}
void remove(Key i) {
Key removeIndex = indexs[i];
Key lastIndex = elemens.size() - 1;
if (removeIndex != lastIndex) {
elemens[removeIndex] = elemens[lastIndex];
indexs[elemens[lastIndex]] = removeIndex;
}
elemens.pop();
}
void fremove(Key i) {
if (!contains(i)) {
return;
}
Key removeIndex = indexs[i];
Key lastIndex = elemens.size() - 1;
if (removeIndex != lastIndex) {
elemens[removeIndex] = elemens[lastIndex];
indexs[elemens[lastIndex]] = removeIndex;
}
elemens.pop();
}
bool contains(Key i) const {
return indexs[i] < (Key)elemens.size() && elemens[indexs[i]] == i;
}
int size() const {
return elemens.size();
}
bool empty() const {
return elemens.empty();
}
Key operator[](int index) const {
return elemens[index];
}
auto begin() -> decltype(elemens.begin()) {
return elemens.begin();
}
auto end() -> decltype(elemens.begin()) {
return elemens.end();
}
auto begin() const -> decltype(elemens.begin()) {
return elemens.begin();
}
auto end() const -> decltype(elemens.begin()) {
return elemens.end();
}
void extend(const CapSet<CAP>& r) {
for (int s : r) {
add(s);
}
}
void fextend(const CapSet<CAP>& r) {
for (int s : r) {
fadd(s);
}
}
template <class RAND>
const Key& choice(RAND&& r) const {
return elemens.choice(r);
}
};
template <class T, int CAP>
struct CapMap {
private:
using Key = typename conditional<CAP <= 256, u8, u32>::type;
CapArr<pr2<Key, T>, CAP> elemens;
array<Key, CAP> indexs;
public:
bool operator == (const CapMap<T, CAP>& r) const {
if (elemens.size() != r.elemens.size()) {
return false;
}
for (auto&& [k, v] : elemens) {
if (!r.contains(k)) {
return false;
}
if (v != r.get(k)) {
return false;
}
}
return true;
}
bool operator != (const CapMap<T, CAP>& r) const {
return !((*this) == r);
}
constexpr int capacity() {
return CAP;
}
void clear() {
elemens.clear();
}
void Clear() {
clear();
}
void set(Key i, const T& value) {
if (contains(i)) {
auto& e = elemens[indexs[i]];
e.b = value;
}
else {
indexs[i] = elemens.size();
auto& e = elemens.push();
e.a = i;
e.b = value;
}
}
const T& get(Key i) const {
return elemens[indexs[i]].b;
}
const T& get(Key i, const T& defaultValue) const {
if (contains(i)) {
return elemens[indexs[i]].b;
}
return defaultValue;
}
T& fref(Key i) {
if (contains(i)) {
return elemens[indexs[i]].b;
}
else {
indexs[i] = elemens.size();
auto& e = elemens.push();
e.a = i;
return e.b;
}
}
T& ref(Key i) {
return elemens[indexs[i]].b;
}
void AddValue(Key i, const T& addValue, const T& defaultValue) {
if (contains(i)) {
elemens[indexs[i]].b += addValue;
}
else {
indexs[i] = elemens.size();
auto& e = elemens.push();
e.a = i;
e.b = defaultValue + addValue;
}
}
void remove(Key i) {
Key removeIndex = indexs[i];
Key lastIndex = elemens.size() - 1;
if (removeIndex != lastIndex) {
elemens[removeIndex] = elemens[lastIndex];
indexs[elemens[lastIndex].a] = removeIndex;
}
elemens.pop();
}
bool contains(Key i) const {
return indexs[i] < (Key)elemens.size() && elemens[indexs[i]].a == i;
}
int size() const {
return elemens.size();
}
bool empty() const {
return elemens.empty();
}
Key AtIndex(int index) const {
return elemens[index].a;
}
auto begin() -> decltype(elemens.begin()) {
return elemens.begin();
}
auto end() -> decltype(elemens.begin()) {
return elemens.end();
}
auto begin() const -> decltype(elemens.begin()) {
return elemens.begin();
}
auto end() const -> decltype(elemens.begin()) {
return elemens.end();
}
};
template <class T, int CAP>
struct CapPriorityQueue {
CapArr<T, CAP> buf_;
constexpr int capacity() const {
return CAP;
}
void clear() {
buf_.clear();
}
bool empty() const {
return buf_.empty();
}
bool exist() const {
return !buf_.empty();
}
int size() const {
return buf_.size();
}
const T& top() {
return buf_.front();
}
template <class CMP>
void push(const T& v, CMP&& cmp) {
buf_.push(v);
push_heap(ALL(buf_), cmp);
}
template <class CMP>
T pop(CMP&& cmp) {
pop_heap(ALL(buf_), cmp);
T ret = buf_.back();
buf_.pop();
return ret;
}
struct Less {
bool operator()(const T& a, const T& b) const {
return a < b;
}
};
void PushNoHeap(const T& v) {
buf_.push(v);
}
void MakeHeap() {
make_heap(ALL(buf_));
}
};
template <class T, int CAPACITY>
struct CapacityRingDeque {
private:
array<T, CAPACITY> buf_;
int head_ = 0;
int tail_ = 0;
int count_ = 0;
public:
constexpr int capacity() const {
return CAPACITY;
}
inline void clear() {
head_ = 0;
tail_ = 0;
count_ = 0;
}
inline void push_back(const T& v) {
VASSERT(count_ < CAPACITY);
buf_[tail_] = v;
++tail_;
if (tail_ >= CAPACITY) {
tail_ = 0;
}
++count_;
}
inline void push_front(const T& v) {
VASSERT(count_ < CAPACITY);
--head_;
if (head_ < 0) {
head_ = CAPACITY - 1;
}
buf_[head_] = v;
++count_;
}
inline void pop_back() {
VASSERT(count_ > 0);
--tail_;
if (tail_ < 0) {
tail_ = CAPACITY - 1;
}
--count_;
}
inline void pop_front() {
VASSERT(count_ > 0);
++head_;
if (head_ >= CAPACITY) {
head_ = 0;
}
--count_;
}
inline int size() const {
return count_;
}
inline bool empty() const {
return count_ == 0;
}
inline const T& front() const {
return buf_[head_];
}
inline const T& back() const {
if (tail_ == 0) {
return buf_[CAPACITY - 1];
}
return buf_[tail_ - 1];
}
};
template<class T, class COMPARERE = less<T>>
struct PriorityQueue : public priority_queue<T, vector<T>, COMPARERE> {
template <class D>
void Cut(int size, D&& deleter) {
if ((int)this->c.size() > size) {
int orgSize = (int)this->c.size();
for (int i = size; i < orgSize; ++i) {
deleter(this->c[i]);
}
this->c.resize(size);
}
}
vector<T>& Container() {
return this->c;
}
void Cut(int size) {
if ((int)this->c.size() > size) {
this->c.resize(size);
}
}
void Clear() {
this->c.clear();
}
};
int patternT = 0;
int N = 0;
int NN = 0;
int K = 0;
enum class Dir : int8_t {
L = 0,
U,
R,
D,
N,
Invalid,
};
constexpr array<Dir, 4> Dir4 = {
Dir::L,
Dir::U,
Dir::R,
Dir::D,
};
constexpr array<pint, 4> Around4 = { pint{-1, 0}, pint{0, -1}, pint{1, 0}, pint{0, 1} };
constexpr array<pint, 5> Around5 = { pint{-1, 0}, pint{0, -1}, pint{1, 0}, pint{0, 1}, pint{0, 0} };
constexpr array<pint, 8> Around8 = { pint{-1, 0}, pint{-1, -1}, pint{0, -1}, pint{1, -1}, pint{1, 0}, pint{1, 1}, pint{0, 1}, pint{-1, 1} };
inline Dir RotateRight(Dir d) {
constexpr Dir nexts[4] = {
Dir::U,
Dir::R,
Dir::D,
Dir::L,
};
return nexts[(int8_t)d];
}
inline Dir RotateLeft(Dir d) {
constexpr Dir nexts[4] = {
Dir::D,
Dir::L,
Dir::U,
Dir::R,
};
return nexts[(int8_t)d];
}
inline Dir Back(Dir d) {
return Dir(s8(d) ^ 2);
}
bool IsHorizontal(Dir dir) {
return dir == Dir::L || dir == Dir::R;
}
bool IsVertical(Dir dir) {
return dir == Dir::U || dir == Dir::D;
}
inline Dir CalcDir(const pint& from, const pint& to) {
if (from.x > to.x) {
return Dir::L;
}
else if (from.y > to.y) {
return Dir::U;
}
else if (from.x < to.x) {
return Dir::R;
}
else if (from.y < to.y) {
return Dir::D;
}
else {
return Dir::N;
}
}
inline const string& DirString(Dir dir) {
static const string strs[6] = {
"LEFT",
"UP",
"RIGHT",
"DOWN",
"WAIT",
"INVALID",
};
return strs[(int)dir];
}
inline char DirToChar(Dir dir) {
static const char chars[6] = {
'L',
'U',
'R',
'D',
'N',
'*',
};
return chars[(int)dir];
}
inline Dir CharToDir(char c) {
if (c == 'L') {
return Dir::L;
}
else if (c == 'U') {
return Dir::U;
}
else if (c == 'R') {
return Dir::R;
}
else if (c == 'D') {
return Dir::D;
}
else if (c == 'N') {
return Dir::N;
}
VABORT();
return Dir::Invalid;
}
struct GridSystemD {
int W;
int H;
int WH;
private:
vector<pint> toPos_;
public:
void Init(int w, int h) {
W = w;
H = h;
WH = W * H;
toPos_.resize(WH);
REP(i, WH) {
toPos_[i].x = i % W;
toPos_[i].y = i / W;
}
}
inline int ToId(int x, int y) const {
VASSERT(x >= 0 && x < W);
VASSERT(y >= 0 && y < H);
return x + W * y;
}
inline int ToId(const pint& p) const {
VASSERT(p.x >= 0 && p.x < W);
VASSERT(p.y >= 0 && p.y < H);
return p.x + W * p.y;
}
inline const pint& ToPos(int id) const {
return toPos_[id];
}
inline int CalcL1Dist(const pint& a, const pint& b) const {
return abs(a.x - b.x) + abs(a.y - b.y);
}
inline int CalcL1Dist(int a, int b) const {
return CalcL1Dist(ToPos(a), ToPos(b));
}
inline int CalcL2Dist2(const pint& a, const pint& b) const {
return square(a.x - b.x) + square(a.y - b.y);
}
inline int CalcL2Dist2(int a, int b) const {
return CalcL2Dist2(ToPos(a), ToPos(b));
}
inline double CalcL2Dist(const pint& a, const pint& b) const {
return sqrt(CalcL2Dist2(a, b));
}
inline double CalcL2Dist(int a, int b) const {
return CalcL2Dist(ToPos(a), ToPos(b));
}
inline bool IsOut(int x, int y) const {
if (x < 0 || x >= W ||
y < 0 || y >= H) {
return true;
}
return false;
}
inline bool IsOut(const pint& p) const {
return IsOut(p.x, p.y);
}
inline bool IsIn(int x, int y) const {
return !IsOut(x, y);
}
inline bool IsIn(const pint& p) const {
return !IsOut(p.x, p.y);
}
inline bool IsBorder(int x, int y) const {
if (IsOut(x, y)) {
return false;
}
if (x == 0 || x == W - 1 ||
y == 0 || y == H - 1) {
return true;
}
return false;
}
inline bool IsBorder(const pint& p) const {
return IsBorder(p.x, p.y);
}
inline bool IsBorder(int cell) const {
return IsBorder(ToPos(cell));
}
inline int RotateRight90(int id) const {
pint p = ToPos(id);
return ToId(W - 1 - p.y, p.x);
}
inline Dir CalcDir1(int from, int to) const {
VASSERT(CalcL1Dist(from, to) <= 1);
if (from == to) {
return Dir::N;
}
else if (from - 1 == to) {
return Dir::L;
}
else if (from - W == to) {
return Dir::U;
}
else if (from + 1 == to) {
return Dir::R;
}
else if (from + W == to) {
return Dir::D;
}
else {
VABORT();
}
return Dir::Invalid;
}
inline Dir CalcDirM(int from, int to) const {
return CalcDir(ToPos(from), ToPos(to));
}
};
GridSystemD gs;
#define PARAM_CATEGORY(NAME, VALUE, ...) int NAME = VALUE;
#define PARAM_INT(NAME, VALUE, LOWER_VALUE, UPPER_VALUE) int NAME = VALUE;
#define PARAM_DOUBLE(NAME, VALUE, LOWER_VALUE, UPPER_VALUE) double NAME = VALUE;
#define PARAM_LOWER(v)
#define PARAM_UPPER(v)
#define START_TUNING
#define END_TUNING
#define PARAM_GROUP(NAME)
#define PARAM_GROUP_END
template <class T>
struct InputParam {
T minValue_;
T maxValue_;
T value_;
InputParam(T minValue, T maxValue) {
minValue_ = minValue;
maxValue_ = maxValue;
}
void SetValue(T value) {
value_ = value;
}
double GetRate(double strong) const {
double r = (value_ - minValue_) / (double)(maxValue_ - minValue_) * 2.0 - 1.0;
return r * strong;
}
};
static double BlendDoubleParam(double baseValue, double minValue, double maxValue, initializer_list<double> rates) {
double totalRate = 1;
for (double rate : rates) {
totalRate += rate;
}
double value = baseValue * totalRate;
chmax(value, minValue);
chmin(value, maxValue);
return value;
}
static int BlendIntParam(double baseValue, int minValue, int maxValue, initializer_list<double> rates) {
double totalRate = 1;
for (double rate : rates) {
totalRate += rate;
}
int value = (int)round(baseValue * totalRate);
chmax(value, minValue);
chmin(value, maxValue);
return value;
}
constexpr
struct {
START_TUNING;
PARAM_CATEGORY(TempType, 2, 0, 1, 2);
PARAM_DOUBLE(TempPow, 1.6001749503887086, 1.5, 2.5);PARAM_LOWER(0.0);
PARAM_DOUBLE(StartTemp, 0.000659398019771773, 0.0, 1.0);PARAM_LOWER(0.0);
PARAM_DOUBLE(EndTemp, 0.38434138240916293, 0.0, 1.0);PARAM_LOWER(0.0);
PARAM_INT(Trans1, 95, 0, 100);PARAM_LOWER(0);PARAM_UPPER(100);
PARAM_INT(Trans2, 43, 0, 100);PARAM_LOWER(0);PARAM_UPPER(100);
PARAM_INT(Trans2_Size, 15, 0, 16);PARAM_LOWER(0);
PARAM_INT(Trans3, 30, 0, 100);PARAM_LOWER(0);PARAM_UPPER(100);
PARAM_INT(Trans3_Size, 1, 0, 16);PARAM_LOWER(0);
PARAM_INT(BeamCandidate, 1, 1, 20);PARAM_LOWER(1);
PARAM_INT(BeamWidth, 18, 1, 20);PARAM_LOWER(1);
END_TUNING;
} HP;
struct IOCommand {
bool swap = false;
Dir da = Dir::N;
Dir db = Dir::N;
Dir GetDir(int i) const {
return i == 0 ? da : db;
}
void SetDir(int i, Dir dir) {
if (i == 0) {
da = dir;
}
else {
db = dir;
}
}
void Output(ostream& os) const {
if (swap) {
os << "1";
}
else {
os << "0";
}
if (da == Dir::N) {
os << " " << ".";
}
else {
os << " " << DirToChar(da);
}
if (db == Dir::N) {
os << " " << ".";
}
else {
os << " " << DirToChar(db);
}
}
};
struct IOResult {
int firstA_;
int firstB_;
vector<IOCommand> commands_;
void Init() {
firstA_ = 0;
firstB_ = 0;
commands_.assign(K, IOCommand{});
}
void Output(ostream& os) const {
pint pa = gs.ToPos(firstA_);
pint pb = gs.ToPos(firstB_);
os << pa.y << " " << pa.x << " " << pb.y << " " << pb.x << endl;
REP(i, commands_.size()) {
commands_[i].Output(os);
os << endl;
}
}
};
struct IOServer {
vector<vector<bool>> isRightWall;
vector<vector<bool>> isDownWall;
vector<int> A;
vector<int> numToPos;
s64 totalD;
void InitInput(ChronoTimer& timer) {
istream& is = cin;
is >> patternT;
timer.Init();
is >> N;
NN = N * N;
K = N * N * 4;
isRightWall.resize(N);
REP(y, N) {
isRightWall[y].resize(N - 1);
REP(x, N - 1) {
char v;
is >> v;
if (v == '1') {
isRightWall[y][x] = true;
}
}
}
isDownWall.resize(N - 1);
REP(y, N - 1) {
isDownWall[y].resize(N);
REP(x, N) {
char v;
is >> v;
if (v == '1') {
isDownWall[y][x] = true;
}
}
}
A.resize(NN);
REP(i, NN) {
is >> A[i];
--A[i];
}
gs.Init(N, N);
totalD = 0;
REP(i, NN) {
pint p = gs.ToPos(i);
{
pint n = p + pint{ 1, 0 };
if (gs.IsIn(n) && !isRightWall[p.y][p.x]) {
s64 diff = A[gs.ToId(p)] - A[gs.ToId(n)];
totalD += square(diff);
}
}
{
pint n = p + pint{ 0, 1 };
if (gs.IsIn(n) && !isDownWall[p.y][p.x]) {
s64 diff = A[gs.ToId(p)] - A[gs.ToId(n)];
totalD += square(diff);
}
}
}
numToPos.resize(NN);
REP(i, NN) {
numToPos[A[i]] = i;
}
}
void Input() {
istream& is = cin;
}
void Output(IOResult& result) {
ostream& os = cout;
result.Output(os);
}
void Finalize() {
}
};
IOServer server;
template <class T, int CAP>
struct CCA {
private:
T ar[CAP];
int s;
public:
inline constexpr void push(const T& v) {
ar[s++] = v;
}
inline constexpr void pop() {
--s;
}
inline constexpr const T* begin() const {
return &ar[0];
}
inline constexpr const T* end() const {
return &ar[s];
}
inline constexpr const T& operator ()(int i) const {
VASSERT(i >= 0 && i < CAP);
return ar[i];
}
inline constexpr const T& operator [](int i) const {
VASSERT(i >= 0 && i < CAP);
return ar[i];
}
inline constexpr int size() const {
return s;
}
};
struct AroundMap {
using CA = CCA<int, 5>;
vector<CA> table_;
vector<CA> tableRB_;
void Init() {
table_.resize(NN);
tableRB_.resize(NN);
REP(i, NN) {
pint p = { i % N, i / N };
REP(di, 4) {
const pint& a = Around4[di];
pint n = p + a;
bool hasNext = false;
if (n.a >= 0 && n.a < N &&
n.b >= 0 && n.b < N) {
if (di == 0) {
if (!server.isRightWall[n.y][n.x]) {
table_[i].push(n.a + n.b * N);
hasNext = true;
}
}
if (di == 2) {
if (!server.isRightWall[p.y][p.x]) {
table_[i].push(n.a + n.b * N);
tableRB_[i].push(n.a + n.b * N);
hasNext = true;
}
}
if (di == 1) {
if (!server.isDownWall[n.y][n.x]) {
table_[i].push(n.a + n.b * N);
hasNext = true;
}
}
if (di == 3) {
if (!server.isDownWall[p.y][p.x]) {
table_[i].push(n.a + n.b * N);
tableRB_[i].push(n.a + n.b * N);
hasNext = true;
}
}
}
}
}
}
inline const CA& operator[](int i) const {
return table_[i];
}
inline const CA& GetAroundRB(int i) const {
return tableRB_[i];
}
};
AroundMap aroundMap;
Xor64 rand_;
s64 CalcTotalD(const vector<int>& A) {
s64 totalD = 0;
REP(i, NN) {
pint p = gs.ToPos(i);
{
pint n = p + pint{ 1, 0 };
if (gs.IsIn(n) && !server.isRightWall[p.y][p.x]) {
s64 diff = A[gs.ToId(p)] - A[gs.ToId(n)];
totalD += square(diff);
}
}
{
pint n = p + pint{ 0, 1 };
if (gs.IsIn(n) && !server.isDownWall[p.y][p.x]) {
s64 diff = A[gs.ToId(p)] - A[gs.ToId(n)];
totalD += square(diff);
}
}
}
return totalD;
}
const vector<vector<int>> patterns_ = {
{46,45,44,43,99,98,97,95,92,96,47,48,49,50,79,80,83,85,88,94,58,55,52,53,75,77,81,84,86,93,59,56,54,57,72,74,78,82,87,91,42,41,40,62,67,71,73,76,89,90,39,38,37,60,63,66,69,70,1,0,36,35,34,51,61,64,65,68,3,2,32,31,30,33,22,18,15,10,6,4,29,28,26,24,20,17,14,11,8,5,27,25,23,21,19,16,13,12,9,7},
{90,88,87,84,4,5,6,7,8,9,91,89,86,85,3,2,1,16,11,10,93,92,65,83,82,81,0,17,12,13,95,94,66,75,79,80,19,18,15,14,99,96,67,71,78,77,28,21,20,22,98,97,64,72,74,76,29,25,24,23,62,63,61,70,73,39,34,35,33,32,60,59,58,69,68,38,37,36,31,30,55,56,57,54,51,48,40,42,44,27,49,50,52,53,47,46,43,41,45,26},
{77,79,81,83,86,89,88,85,76,75,74,72,70,68,35,78,80,82,84,87,91,92,90,73,71,69,67,66,64,36,150,147,146,100,98,95,94,93,65,63,62,61,60,59,37,149,145,143,104,102,99,97,96,58,57,56,55,54,53,38,148,142,140,110,107,105,103,101,49,50,52,51,48,45,40,151,136,130,120,113,109,108,106,41,42,46,47,44,43,39,153,133,131,129,115,114,112,111,32,29,21,18,19,27,34,154,135,134,132,119,118,117,116,22,20,17,15,13,31,33,155,137,139,138,124,123,122,121,16,14,12,10,8,28,30,156,152,144,141,128,127,126,125,11,9,6,4,2,25,26,158,157,159,162,182,181,177,176,7,5,3,1,0,23,24,160,161,163,166,183,185,189,193,197,201,205,209,213,223,224,164,165,167,172,180,186,190,194,198,202,206,210,214,221,222,169,168,170,174,179,187,191,195,199,203,207,211,215,218,220,171,173,175,178,184,188,192,196,200,204,208,212,216,217,219},
{0,3,8,17,31,47,62,77,109,124,129,134,137,140,145,149,1,4,10,18,32,46,59,65,125,128,132,136,139,144,150,154,2,6,12,20,33,45,56,61,133,135,138,142,147,152,156,159,5,7,13,22,34,44,54,60,141,143,148,153,157,161,164,165,9,11,16,25,35,43,52,58,151,155,158,162,167,171,174,176,14,15,19,27,36,42,50,55,160,163,168,172,177,181,182,185,24,21,23,29,37,41,49,53,166,169,175,180,184,186,188,191,39,28,26,30,38,40,48,51,170,173,179,183,187,189,192,198,57,63,66,68,72,76,82,85,204,207,215,217,225,229,227,216,64,67,69,71,75,80,86,89,202,206,214,218,226,232,234,231,70,73,74,78,83,87,92,95,200,205,213,219,228,236,240,241,79,81,84,88,93,97,100,104,197,203,212,220,230,239,244,246,90,91,94,98,102,107,112,114,195,201,211,221,233,242,248,250,96,99,103,108,113,117,120,122,194,199,210,222,235,243,249,253,101,105,111,116,119,123,127,130,190,196,209,223,237,245,251,254,106,110,115,118,121,126,131,146,178,193,208,224,238,247,252,255},
{250,251,254,278,287,292,294,299,308,314,319,330,335,338,341,349,355,359,360,237,248,255,266,272,277,286,301,304,311,318,326,331,339,342,347,352,357,358,235,240,249,258,267,271,280,289,298,307,313,320,327,337,340,345,348,351,356,228,233,243,246,244,256,270,284,290,297,303,310,316,317,334,344,343,353,354,219,230,236,234,231,239,257,260,279,283,296,300,306,315,329,332,333,350,346,196,169,176,189,206,217,207,242,253,273,275,285,293,302,328,321,324,325,336,172,166,168,186,197,200,199,227,232,276,263,268,274,269,282,309,312,322,323,157,159,164,171,180,187,190,210,213,209,241,247,262,261,281,295,291,288,305,146,150,145,158,161,177,182,191,201,205,216,222,221,229,223,224,265,264,259,131,123,127,137,149,148,167,181,183,195,194,204,211,212,218,226,238,245,252,122,112,113,125,115,120,140,139,153,156,170,178,179,192,208,215,220,225,214,73,90,87,124,110,103,136,130,141,147,154,160,165,184,193,185,198,202,203,54,50,58,55,65,80,85,104,133,138,143,144,142,134,163,173,174,175,188,44,43,45,48,60,70,71,96,121,132,135,129,128,126,155,152,151,162,100,35,34,33,36,30,42,59,66,63,78,92,111,118,117,108,109,119,107,102,27,26,24,31,25,28,16,46,64,67,89,105,114,116,97,99,106,101,98,23,20,15,11,13,18,19,29,38,61,69,57,62,74,84,91,94,95,93,4,6,9,5,8,12,17,22,39,49,40,52,53,76,77,81,86,82,88,3,0,1,2,7,10,14,21,32,37,41,47,51,56,68,72,75,79,83},
{182,192,193,206,213,222,234,247,261,271,279,286,294,302,309,314,312,308,305,303,180,190,191,204,212,221,233,245,259,269,280,287,296,304,313,320,334,352,359,362,179,188,189,200,208,218,230,243,258,267,282,289,299,307,316,322,329,363,365,366,177,185,187,194,205,216,228,240,253,260,288,293,301,310,318,323,328,372,371,370,175,178,181,184,209,215,225,238,248,256,291,297,306,315,321,327,331,380,376,377,171,172,174,176,207,214,224,237,246,254,292,300,311,319,326,332,336,390,397,399,166,167,169,170,203,210,223,236,244,251,290,298,317,325,333,339,342,393,396,398,160,162,164,165,199,201,229,235,242,252,283,285,330,335,340,345,347,392,394,395,156,159,161,163,197,198,226,232,241,257,272,278,338,341,346,349,353,387,389,391,146,143,139,137,148,149,220,227,239,255,266,274,337,344,348,356,364,378,385,388,140,138,136,135,151,152,211,217,231,250,263,273,324,343,351,358,367,375,382,386,133,132,130,131,154,155,195,202,219,249,264,277,295,350,355,360,368,374,381,384,124,123,122,125,153,157,173,186,196,262,268,276,284,354,357,361,369,373,379,383,115,114,112,120,147,150,158,168,183,265,270,275,281,0,1,3,8,6,4,2,109,108,107,118,141,142,144,145,134,65,61,56,54,37,33,26,16,10,7,5,105,104,103,116,129,128,127,126,121,66,62,57,53,40,35,29,21,14,11,9,102,101,100,117,119,113,111,110,106,69,64,58,52,42,38,32,25,18,13,12,73,77,81,85,90,98,99,97,91,76,67,59,50,45,41,34,28,23,17,15,72,75,80,84,88,95,96,92,86,78,68,60,51,47,43,36,31,27,22,19,71,74,79,83,87,93,94,89,82,70,63,55,49,48,46,44,39,30,24,20},
{399,397,392,384,374,359,342,322,299,271,249,226,207,188,172,157,143,130,120,112,398,395,390,382,370,356,338,318,295,268,245,224,205,186,169,153,139,126,116,108,396,394,388,379,367,353,335,313,289,263,241,220,201,182,165,148,133,119,107,99,393,391,385,376,364,349,330,309,284,259,237,216,197,178,160,142,125,109,97,91,389,387,381,373,361,346,327,304,278,254,232,210,191,171,151,134,115,98,88,82,386,383,377,368,355,339,320,297,270,247,225,203,183,163,144,123,104,89,79,73,380,378,371,362,348,332,312,288,261,238,217,195,175,155,135,113,94,80,70,65,375,372,365,354,341,324,303,277,252,230,208,187,166,147,124,102,85,71,62,56,369,366,358,347,333,315,293,267,243,221,200,179,158,138,114,92,76,63,54,49,363,360,351,340,325,306,281,258,235,213,192,170,149,127,103,83,68,55,47,42,357,352,344,331,316,296,272,250,227,206,184,162,140,118,93,74,60,48,39,36,350,345,336,323,307,285,262,240,219,198,176,154,131,106,84,66,52,41,33,30,343,337,328,314,298,275,253,233,211,190,167,145,121,96,75,58,45,34,27,24,334,329,319,305,287,264,244,223,202,181,159,136,110,87,67,51,37,28,21,19,326,321,310,294,276,255,236,215,194,173,150,128,100,78,59,44,31,22,16,13,317,311,301,282,265,248,229,209,189,168,146,122,95,72,53,38,26,18,12,10,308,302,290,274,257,239,222,204,185,164,141,117,90,69,50,35,23,14,8,6,300,292,280,266,251,234,218,199,180,161,137,111,86,64,46,32,20,11,5,3,291,283,273,260,246,231,214,196,177,156,132,105,81,61,43,29,17,9,4,1,286,279,269,256,242,228,212,193,174,152,129,101,77,57,40,25,15,7,2,0},
{57,50,49,22,23,25,28,30,29,17,18,20,15,8,7,3,2,1,388,386,56,52,65,69,70,26,34,33,32,31,27,19,16,9,6,5,4,0,387,385,55,54,59,71,73,75,37,36,43,35,24,21,14,12,336,337,399,398,395,383,47,51,60,58,72,76,38,40,44,39,10,11,13,326,334,333,396,397,393,382,46,48,62,61,78,77,74,63,53,113,111,110,325,327,329,331,394,391,392,380,45,42,64,66,79,82,81,89,99,114,112,109,323,324,330,332,390,389,384,379,105,41,97,67,68,83,80,106,107,116,115,108,319,315,322,338,340,339,381,377,104,100,96,95,88,85,84,124,125,127,318,316,314,313,321,320,341,345,370,369,103,101,98,94,91,86,121,122,169,138,151,317,280,304,328,335,342,346,352,359,153,102,92,93,90,87,173,172,170,168,164,163,279,295,284,343,344,347,351,356,154,156,159,162,167,171,176,175,212,178,177,185,278,286,285,283,358,350,349,355,152,155,160,161,187,184,179,180,211,210,202,193,268,364,365,362,357,353,348,354,118,117,192,188,186,183,181,200,228,218,248,249,258,363,366,367,371,373,376,299,119,120,191,190,174,182,189,199,227,226,233,240,239,361,360,368,372,374,378,300,126,123,141,165,166,195,194,198,201,235,238,241,237,264,265,312,311,375,302,301,128,129,142,140,158,157,196,197,203,234,232,243,236,262,261,260,309,306,303,305,130,145,144,146,150,149,209,208,206,207,231,246,250,263,267,266,281,296,298,307,131,134,139,143,148,147,213,204,205,229,230,254,255,259,273,277,282,294,297,308,132,136,137,223,222,217,216,215,242,252,251,253,271,272,274,275,287,292,293,310,133,135,225,224,221,220,219,214,244,245,247,256,257,270,269,276,288,289,290,291},
{43,39,34,30,26,21,15,7,2,0,240,245,250,257,263,271,280,292,299,303,45,41,37,32,28,23,17,10,4,1,238,242,247,254,262,270,279,291,298,301,48,46,40,35,31,25,19,13,6,3,234,237,243,251,259,268,276,287,296,300,51,50,47,42,36,29,22,16,9,5,227,230,236,246,255,264,273,282,293,297,54,53,52,49,44,33,24,18,12,8,220,223,229,239,249,260,269,278,288,294,56,57,58,59,55,38,27,20,14,11,209,215,222,233,244,256,267,275,284,290,60,61,63,69,79,107,130,152,173,187,198,205,216,226,235,252,265,274,281,286,62,64,68,77,90,112,133,154,174,186,194,201,208,218,224,308,310,314,320,324,65,66,73,81,95,117,138,158,178,188,193,200,206,214,219,307,311,317,322,326,67,70,76,84,100,121,142,163,180,189,196,203,211,213,217,306,312,319,325,328,71,74,78,87,104,124,145,166,181,190,199,212,231,261,285,304,313,323,330,333,72,75,80,91,109,131,150,169,182,191,202,221,241,266,289,305,316,327,334,335,105,111,119,126,135,143,156,172,183,192,204,225,248,272,295,309,321,332,337,339,101,108,116,125,137,147,161,177,185,195,207,228,253,277,302,318,329,336,340,341,96,103,113,123,136,148,162,176,184,197,210,232,258,283,315,331,338,342,343,344,93,98,110,122,134,146,159,171,179,392,388,383,378,367,347,345,346,348,349,350,89,94,106,120,132,144,155,168,175,394,390,385,380,373,362,357,354,353,352,351,85,92,102,118,129,141,153,164,170,397,393,387,382,376,370,366,363,359,356,355,83,88,99,115,128,140,151,160,167,398,395,389,384,379,375,372,369,365,360,358,82,86,97,114,127,139,149,157,165,399,396,391,386,381,377,374,371,368,364,361},
{2,1,0,3,11,14,22,31,40,48,56,65,77,88,95,106,114,123,133,145,154,164,168,171,172,4,5,6,7,13,20,24,30,44,51,59,68,79,90,99,108,118,126,134,146,153,176,178,180,177,8,9,10,12,17,21,28,35,46,55,64,72,86,97,107,122,129,130,136,150,162,190,194,195,184,15,16,19,18,23,25,32,43,53,62,75,89,98,111,127,135,144,202,206,204,189,207,218,227,243,26,27,29,33,34,41,47,58,63,73,82,96,109,124,137,152,167,199,213,217,232,231,239,246,253,39,38,37,36,42,45,57,67,76,85,93,110,117,142,148,173,182,219,229,244,247,248,260,264,266,52,50,49,54,60,71,70,84,87,102,112,120,139,155,161,188,208,228,236,254,262,261,275,279,282,69,66,61,74,78,81,83,103,121,125,138,157,165,185,209,216,230,245,252,286,285,300,299,302,306,91,92,94,80,101,100,105,104,140,141,159,174,183,215,226,234,256,265,269,289,297,315,320,325,331,115,116,113,132,128,119,131,149,163,181,186,198,214,233,240,257,276,291,303,307,316,324,342,352,354,143,147,158,156,160,170,151,191,187,197,211,224,241,263,283,280,304,317,312,318,334,370,372,379,380,166,169,175,179,193,205,220,203,201,212,238,242,258,292,311,336,343,363,392,411,415,405,404,409,412,192,196,200,210,222,235,251,272,287,293,284,348,346,335,333,356,368,395,402,421,429,431,434,438,441,223,225,221,237,249,259,270,277,298,308,323,347,355,369,378,388,401,425,445,439,452,459,465,468,471,250,255,271,268,274,281,294,313,321,330,339,361,375,396,410,420,428,460,472,486,483,484,492,496,498,267,273,288,290,295,301,310,326,341,351,377,383,390,433,451,453,464,479,491,500,502,507,513,518,522,278,296,305,309,314,319,322,338,364,385,397,406,414,454,470,476,490,497,511,514,515,525,533,537,541,340,328,327,329,332,337,381,384,386,399,424,430,440,457,493,501,510,517,526,530,551,550,549,555,557,353,349,344,345,350,360,382,389,400,427,446,456,458,475,505,519,527,532,543,566,565,568,578,575,574,365,362,358,357,359,373,398,393,469,461,478,488,509,536,531,538,544,542,562,569,580,583,586,588,589,376,374,367,366,371,387,422,455,474,482,495,508,523,539,546,553,559,571,572,582,590,593,596,599,601,391,394,407,437,442,444,450,467,481,494,506,520,534,545,556,563,570,581,592,595,598,600,605,608,610,403,408,418,432,443,449,463,477,487,504,512,524,548,554,558,573,579,587,597,602,606,613,614,616,615,413,416,423,435,447,462,473,485,499,516,528,535,547,560,564,576,584,591,604,607,611,617,618,620,623,417,419,426,436,448,466,480,489,503,521,529,540,552,561,567,577,585,594,603,609,612,619,621,622,624},
{0,1,3,6,10,13,18,22,25,80,82,88,92,95,100,106,110,113,244,245,251,255,258,262,264,270,272,2,4,5,8,12,16,21,27,31,81,84,89,94,99,102,108,114,118,243,246,252,256,261,263,269,274,277,7,9,11,14,19,24,30,34,37,83,87,93,98,103,109,117,122,126,242,247,254,260,265,271,276,281,283,15,17,20,23,29,33,39,43,47,85,90,97,104,111,119,125,132,139,240,250,259,267,275,282,284,287,289,26,28,32,35,40,42,48,54,63,86,96,105,112,121,128,134,144,166,229,253,266,278,286,291,293,295,296,36,38,41,45,49,52,57,61,66,101,107,116,123,131,136,138,146,154,257,268,280,290,297,300,301,302,303,44,46,50,56,60,62,65,68,69,115,120,127,135,140,143,145,148,149,279,285,294,304,310,311,309,308,307,51,53,59,67,72,70,71,73,74,124,129,137,147,159,156,153,151,150,292,298,306,318,328,324,319,315,313,55,58,64,75,91,79,76,77,78,130,133,141,160,194,169,158,155,152,299,305,314,333,363,338,325,320,316,167,164,162,157,142,161,173,181,185,330,327,322,312,288,321,340,348,352,494,493,490,479,455,487,504,511,514,171,170,168,165,163,172,179,187,192,334,332,329,326,323,336,347,353,357,496,497,495,491,489,500,510,515,520,174,175,176,177,178,183,190,198,203,335,337,339,342,344,349,356,362,368,498,501,503,505,507,512,517,521,524,180,182,184,186,189,195,201,209,220,331,341,346,350,355,359,367,374,383,492,502,509,513,518,522,526,529,531,188,191,193,196,200,205,212,222,248,317,343,351,358,364,370,376,385,411,480,506,516,523,528,532,535,537,540,197,199,202,206,210,215,219,226,236,345,354,361,369,373,378,382,387,397,508,519,527,533,539,542,544,546,548,204,207,211,216,221,223,225,227,230,360,366,372,379,384,386,389,391,393,525,530,538,545,550,551,552,553,554,208,213,218,228,239,237,233,231,232,371,375,381,392,405,402,399,396,394,536,541,549,556,565,563,560,558,557,214,217,224,241,273,249,238,235,234,377,380,388,407,440,416,406,401,398,543,547,555,567,586,571,566,564,561,412,408,403,390,365,395,414,423,429,576,573,570,559,534,568,587,595,598,650,651,652,649,637,653,664,670,673,415,413,409,404,400,410,422,430,436,578,577,575,572,569,580,591,599,604,654,655,657,658,656,661,669,675,677,421,420,419,417,418,424,434,443,449,579,581,583,585,588,593,601,608,613,659,660,663,666,668,672,678,682,684,425,426,427,428,431,438,448,460,471,574,582,590,592,597,605,612,621,627,662,667,671,676,679,683,687,690,692,432,433,435,437,442,450,462,475,499,562,584,594,600,607,616,623,632,642,665,674,680,686,688,693,696,700,702,439,441,444,446,453,461,469,478,488,589,596,603,609,617,624,631,638,643,681,685,689,695,699,704,708,711,713,445,447,452,457,463,467,474,481,486,602,606,611,619,625,630,635,641,645,691,694,698,705,709,714,717,719,721,451,454,459,465,468,472,476,482,485,610,614,620,626,629,634,639,644,647,697,701,707,712,716,720,723,724,726,456,458,464,466,470,473,477,483,484,615,618,622,628,633,636,640,646,648,703,706,710,715,718,722,725,727,728},
{781,782,783,784,786,787,788,777,770,768,759,756,751,744,739,632,628,620,612,608,604,598,590,584,580,899,898,896,894,892,810,806,805,800,796,792,790,778,771,767,761,755,749,742,737,630,626,618,611,606,601,594,587,581,577,897,895,893,890,888,815,812,807,804,798,794,791,779,772,766,760,753,745,738,734,627,622,614,607,602,595,588,582,575,570,891,889,887,885,883,819,817,814,808,803,797,793,780,774,765,758,750,741,733,729,625,619,610,600,591,585,579,574,569,567,886,884,882,880,877,824,822,820,816,809,802,795,785,776,764,757,747,736,728,723,624,616,603,589,578,572,568,566,564,563,881,879,875,872,866,829,828,826,823,818,811,801,789,775,763,754,743,731,721,710,629,613,593,571,562,561,560,559,558,557,878,874,869,861,851,833,835,834,831,827,821,813,799,769,762,752,740,727,713,688,644,615,586,546,537,550,553,554,552,551,876,873,864,850,825,845,843,842,841,837,832,830,836,380,382,386,391,396,399,403,410,422,448,485,491,478,477,486,505,549,719,724,732,748,773,849,848,847,846,844,840,838,839,379,381,385,390,394,395,400,407,416,432,454,465,467,470,475,483,592,716,720,726,735,746,852,853,854,855,857,863,867,870,355,357,362,368,373,383,392,401,409,420,433,445,452,458,464,468,634,708,714,718,725,730,856,858,859,860,862,865,868,871,354,353,359,365,370,375,384,393,402,411,421,429,439,447,453,457,672,694,705,712,717,722,246,248,251,255,260,265,271,274,335,343,349,360,367,372,377,387,397,406,413,418,426,435,442,449,684,692,700,707,711,715,243,245,249,253,257,263,273,278,325,333,340,351,361,366,371,378,388,398,408,414,419,427,434,441,685,691,697,703,706,709,238,241,244,247,252,258,280,291,311,324,332,344,352,358,363,369,376,389,404,412,417,425,431,437,686,690,695,698,702,704,230,234,237,240,242,239,298,302,307,316,321,341,345,347,350,356,364,374,405,415,423,430,438,440,687,689,693,696,699,701,223,227,229,232,235,236,297,300,305,310,314,336,337,338,339,342,346,348,424,428,436,443,450,456,671,674,678,680,682,683,214,222,225,228,231,233,295,299,303,306,309,334,331,328,326,327,329,330,444,446,451,455,460,462,666,668,673,677,679,681,201,197,196,198,199,210,213,215,220,219,217,322,323,319,317,315,313,312,459,461,463,466,469,472,658,661,665,670,675,676,190,188,189,192,195,208,212,216,226,221,218,320,318,308,304,301,296,293,471,473,474,476,479,482,645,649,655,663,667,669,182,183,184,187,191,206,209,211,250,259,262,289,290,294,292,288,281,275,480,481,484,487,490,494,631,635,642,656,662,664,178,179,181,186,194,202,205,207,261,264,267,285,286,287,284,276,268,256,488,489,492,496,501,510,609,617,621,657,659,660,176,177,180,185,193,200,203,204,266,269,272,279,283,282,277,270,254,224,493,495,498,506,517,536,576,596,605,652,653,654,175,173,168,160,150,142,134,128,34,37,43,54,75,88,99,113,132,164,497,499,504,514,525,542,565,583,597,648,650,651,174,171,166,158,147,140,131,125,36,39,44,55,74,86,97,108,120,133,500,502,509,518,527,541,556,573,599,643,646,647,172,169,163,153,143,136,127,122,40,42,46,57,73,83,93,102,110,115,503,507,513,520,528,538,548,555,623,636,638,640,170,167,159,148,139,129,121,118,47,48,51,59,71,81,89,96,104,107,508,512,516,521,529,535,543,547,633,637,639,641,165,162,154,144,135,123,116,112,63,61,60,62,69,76,82,90,98,105,511,515,519,523,530,534,540,545,0,2,4,6,161,156,149,141,130,119,111,103,85,78,72,66,64,65,70,77,91,95,522,524,526,531,532,533,539,544,1,3,5,7,157,152,146,138,126,117,109,101,92,84,79,67,58,53,52,50,38,33,30,28,26,24,22,20,18,16,14,12,10,8,155,151,145,137,124,114,106,100,94,87,80,68,56,49,45,41,35,32,31,29,27,25,23,21,19,17,15,13,11,9},
{899,896,893,890,887,884,881,878,875,872,869,866,863,860,857,854,851,848,845,842,839,836,833,830,827,824,821,818,816,815,898,895,892,889,886,883,880,877,874,871,868,865,862,859,856,853,850,847,844,841,838,835,832,829,826,823,820,817,814,812,897,894,891,888,885,882,879,876,873,870,867,864,861,858,855,852,849,846,843,840,837,834,831,828,825,822,819,813,811,810,581,578,576,573,570,567,564,561,558,555,552,549,546,545,542,539,536,533,530,527,524,521,518,515,512,510,509,809,808,807,582,580,577,574,571,568,565,562,559,556,553,550,547,544,541,538,535,532,529,526,523,520,517,514,511,507,506,804,805,806,584,583,579,575,572,569,566,563,560,557,554,551,548,543,540,537,534,531,528,525,522,519,516,513,508,505,504,801,802,803,587,586,585,327,326,324,321,318,317,314,311,308,305,302,299,296,293,290,287,284,281,278,276,275,503,502,501,798,799,800,590,589,588,330,328,325,322,319,316,313,310,307,304,301,298,295,292,289,286,283,280,277,273,272,500,499,498,795,796,797,593,592,591,332,331,329,323,320,315,312,309,306,303,300,297,294,291,288,285,282,279,274,271,270,497,496,495,792,793,794,596,595,594,335,334,333,149,146,144,141,138,135,132,129,126,123,122,119,116,114,113,269,268,267,494,493,492,789,790,791,599,598,597,338,337,336,150,147,145,142,139,136,133,130,127,124,121,118,115,112,110,266,265,264,491,490,489,786,787,788,602,601,600,341,340,339,152,151,148,143,140,137,134,131,128,125,120,117,111,109,108,263,262,261,486,487,488,783,784,785,605,604,603,344,343,342,155,154,153,41,38,36,33,32,29,26,24,23,107,106,105,260,259,258,483,484,485,780,781,782,606,607,608,347,346,345,158,157,156,42,39,37,34,31,28,25,22,20,104,103,102,257,256,255,480,481,482,777,778,779,609,610,611,350,349,348,161,160,159,44,43,40,35,30,27,21,19,18,101,100,99,254,253,252,477,478,479,774,775,776,612,613,614,353,352,351,164,163,162,47,46,45,2,5,8,14,16,17,98,97,96,251,250,249,474,475,476,771,772,773,615,616,617,356,355,354,167,166,165,50,49,48,1,4,7,10,13,15,93,94,95,248,247,246,471,472,473,768,769,770,618,619,620,359,358,357,170,169,168,51,52,53,0,3,6,9,11,12,90,91,92,243,244,245,468,469,470,765,766,767,621,622,623,362,361,360,173,172,171,54,55,58,63,66,69,72,77,80,84,88,89,240,241,242,465,466,467,762,763,764,624,625,626,363,364,365,176,175,174,56,59,61,64,67,70,73,76,79,82,85,87,237,238,239,462,463,464,759,760,761,627,628,629,366,367,368,177,178,179,57,60,62,65,68,71,74,75,78,81,83,86,234,235,236,459,460,461,756,757,758,630,631,632,369,370,371,180,181,183,189,192,195,198,201,206,209,212,215,218,221,224,229,232,233,456,457,458,753,754,755,633,634,635,372,373,374,182,184,187,190,193,196,199,202,205,208,211,214,217,220,223,226,230,231,453,454,455,750,751,752,636,637,638,375,376,377,185,186,188,191,194,197,200,203,204,207,210,213,216,219,222,225,227,228,450,451,452,747,748,749,639,640,641,378,379,382,387,390,393,396,399,402,405,408,411,414,417,420,423,426,429,434,437,440,444,448,449,744,745,746,642,643,644,380,383,385,388,391,394,397,400,403,406,409,412,415,418,421,424,427,430,433,436,439,442,445,447,741,742,743,645,646,647,381,384,386,389,392,395,398,401,404,407,410,413,416,419,422,425,428,431,432,435,438,441,443,446,738,739,740,648,649,651,657,660,663,666,669,672,675,678,681,684,687,692,695,698,701,704,707,710,713,716,719,722,725,728,733,736,737,650,652,655,658,661,664,667,670,673,676,679,682,685,688,691,694,697,700,703,706,709,712,715,718,721,724,727,730,734,735,653,654,656,659,662,665,668,671,674,677,680,683,686,689,690,693,696,699,702,705,708,711,714,717,720,723,726,729,731,732},
{826,827,829,832,703,701,699,693,690,689,688,684,680,677,623,624,644,646,321,318,315,314,240,237,236,234,231,229,228,225,823,825,828,831,704,702,698,692,687,685,686,683,679,676,625,626,643,647,320,316,311,308,241,239,238,235,230,227,226,224,820,821,710,709,707,706,697,694,678,675,671,665,659,656,630,633,641,649,657,661,304,300,292,287,243,242,223,222,218,216,818,819,711,712,713,714,696,695,674,672,670,664,653,648,634,637,645,651,658,662,301,299,288,284,252,251,221,219,217,214,814,815,813,812,716,717,718,719,601,602,669,666,639,638,635,636,650,652,312,309,305,303,280,274,262,260,266,268,271,272,808,809,810,811,723,722,721,720,600,603,668,667,628,629,631,632,654,655,313,310,307,306,276,270,263,261,267,269,273,275,805,804,803,802,725,724,596,597,599,604,608,615,619,621,344,347,349,353,356,362,368,371,259,257,256,253,247,245,277,278,799,798,800,801,727,726,593,594,598,605,609,614,617,618,345,348,350,354,357,363,372,374,258,255,254,250,246,244,282,283,791,790,794,795,591,589,588,586,579,577,610,613,401,403,406,409,411,412,408,399,386,381,378,373,369,365,360,358,286,285,787,786,792,793,590,587,585,584,576,573,611,612,402,404,407,410,413,415,414,405,391,385,380,375,370,367,361,359,290,289,785,784,762,763,766,767,769,773,568,565,557,553,555,558,454,452,444,435,425,418,419,420,382,379,333,332,331,330,294,293,783,782,760,761,764,765,768,772,566,561,552,551,556,559,455,453,445,437,431,426,422,421,384,383,336,334,329,326,297,295,779,778,755,756,757,758,519,521,526,531,542,544,560,562,459,457,440,438,434,432,424,423,340,339,338,335,328,319,302,296,777,775,752,751,750,749,518,520,522,527,539,543,563,564,461,460,441,439,436,433,428,427,341,342,343,337,327,317,298,291,774,770,759,753,747,746,745,744,515,513,503,490,480,471,463,458,451,442,429,417,400,387,376,364,352,346,325,322,281,279,776,771,754,748,741,740,742,743,512,511,502,489,479,470,462,456,450,443,430,416,398,388,377,366,355,351,324,323,265,264,781,780,739,738,737,736,733,731,517,516,507,506,492,495,499,501,449,446,397,395,393,389,190,191,207,205,202,199,248,249,788,789,729,728,734,735,732,730,525,524,508,505,493,494,498,500,448,447,396,394,392,390,186,189,206,204,201,200,232,233,796,797,715,708,691,682,534,533,532,530,509,504,497,491,486,483,477,475,174,175,178,180,184,188,193,196,198,203,215,220,806,807,705,700,681,673,536,537,540,538,514,510,496,488,485,481,476,474,172,173,177,179,183,187,192,195,194,197,208,213,816,817,846,847,663,660,546,547,545,541,528,523,487,482,473,469,467,465,169,170,84,85,96,97,165,171,182,185,209,212,822,824,843,844,642,640,548,550,554,549,535,529,484,478,472,468,466,464,167,168,86,88,98,100,162,166,176,181,210,211,830,833,840,842,627,622,607,592,574,567,569,570,70,68,66,63,62,67,74,82,87,92,99,101,154,155,164,161,159,158,834,836,841,845,620,616,606,595,582,575,572,571,71,69,65,61,60,64,73,83,89,95,102,107,145,147,163,160,157,156,835,837,848,850,854,857,855,852,581,578,80,78,75,72,53,56,59,58,51,49,90,94,110,117,133,141,146,149,152,153,838,839,849,851,858,859,856,853,583,580,81,79,77,76,52,54,57,55,50,48,91,93,113,119,132,138,144,148,150,151,886,883,882,876,866,862,861,860,879,880,10,11,13,14,16,18,20,21,47,46,45,44,111,112,134,135,131,125,123,122,887,885,884,881,871,865,864,863,877,878,8,9,12,15,17,19,22,23,40,41,42,43,108,109,137,136,130,124,121,120,898,896,889,888,891,894,867,868,873,875,7,6,3,1,24,26,27,29,34,35,38,39,105,106,140,139,129,126,118,116,899,897,892,890,893,895,869,870,872,874,5,4,2,0,25,28,30,31,32,33,36,37,103,104,143,142,128,127,115,114},
{1222,1221,1223,1224,87,88,89,91,90,70,69,68,67,66,65,43,42,40,31,32,34,20,21,0,1,2,5,4,3,330,327,323,315,314,313,1210,1220,1219,118,116,117,95,94,92,72,82,81,61,62,63,44,45,41,39,30,29,25,22,19,18,10,7,6,329,328,326,324,318,312,311,1209,1218,1213,1212,115,112,96,98,97,75,78,80,60,59,64,57,51,37,38,35,33,23,24,17,16,13,12,11,333,332,331,325,321,320,310,1207,1214,1215,1217,113,111,106,102,73,74,77,83,58,79,71,54,55,36,178,175,174,28,26,27,15,14,8,9,360,334,335,336,319,317,309,1208,1211,1216,1198,114,1182,104,103,105,107,76,84,85,86,53,52,56,185,177,176,171,166,167,165,163,381,379,378,359,358,339,337,349,316,308,1206,1205,1195,1197,1184,1183,1189,100,99,108,109,110,101,93,46,50,49,186,188,180,181,162,168,164,382,383,377,366,365,357,347,348,350,305,306,1204,1202,1194,1190,1185,1188,1187,1186,127,122,121,119,120,161,47,48,173,187,190,184,182,159,156,152,148,384,376,375,374,373,345,346,353,356,355,1203,1199,1196,1165,1178,1191,1192,1193,126,125,123,124,147,160,169,170,172,204,197,183,158,157,154,150,146,145,144,143,380,372,344,363,362,361,370,1201,1200,1163,1164,1172,194,196,198,195,191,131,130,137,138,179,189,199,210,228,246,264,155,153,151,149,396,398,399,385,390,342,341,340,364,369,1159,1160,1162,1158,200,201,203,202,193,192,128,129,136,139,141,296,295,293,289,285,281,304,303,392,391,394,395,400,403,397,343,494,497,367,368,1156,1153,1149,1150,1130,207,205,206,208,209,212,211,135,140,142,297,298,291,290,292,294,307,351,393,389,405,404,402,409,415,425,496,498,501,504,1155,1151,1147,1146,1132,1133,1135,1134,217,215,216,218,134,133,132,300,299,301,286,288,287,322,352,387,388,406,407,408,410,421,426,424,499,506,505,1154,1152,1148,1141,1136,1131,1137,1107,213,214,219,220,258,257,260,263,262,302,284,283,485,338,354,371,386,418,416,411,412,439,432,503,502,507,508,1161,1157,1145,1144,1143,1125,1138,1106,1061,1062,223,221,259,251,266,265,261,279,282,484,483,481,428,429,401,419,414,413,450,445,431,491,495,510,509,1166,1173,1142,1140,1139,1118,1112,1105,1065,1063,226,222,240,245,267,268,272,275,277,278,280,480,467,430,417,420,423,422,454,461,488,489,493,513,514,1171,1174,1177,1176,1175,1086,1087,1097,1066,1064,230,232,234,231,229,271,273,274,276,557,556,490,453,442,434,433,427,451,452,468,487,486,492,515,516,1170,1181,1179,1047,1051,1078,1077,1067,1069,1070,233,239,224,225,227,270,269,590,591,568,555,500,511,512,435,437,448,449,476,474,479,482,524,517,518,1168,1169,1180,1049,1050,1058,1059,1054,1071,1072,235,238,241,243,244,250,254,256,592,580,543,531,521,522,436,443,446,692,689,473,478,477,523,520,519,1167,1046,1045,1048,1052,1055,1056,1040,1073,1074,236,237,242,1085,247,249,253,255,593,594,617,530,441,440,438,444,447,691,690,471,472,475,525,526,527,1041,1043,1042,1036,1031,1030,1057,1027,1076,1079,1080,1081,1083,1084,889,248,252,604,605,606,618,633,646,665,681,680,684,687,688,470,469,466,465,529,528,1039,1038,1037,1026,1028,1029,1013,1012,993,974,954,934,879,887,888,600,601,603,704,693,682,671,660,663,678,679,683,685,686,459,460,464,463,462,1011,1101,1103,1035,1024,1022,1014,1015,1016,1017,1018,898,915,880,884,886,597,598,599,714,667,666,662,661,655,669,675,676,645,643,455,457,458,1005,1008,1010,1100,1102,1034,1019,1021,1023,1025,1020,779,778,897,896,877,883,881,770,596,736,724,668,658,659,656,657,664,677,644,642,640,639,456,624,1006,1007,1009,1098,1096,1092,1075,1068,1044,1033,773,780,785,786,854,856,882,782,771,761,749,537,670,650,652,654,653,647,641,627,634,636,631,628,626,625,1004,1003,1091,1089,1090,1082,1060,1053,1032,774,783,784,830,828,837,806,793,794,795,750,538,672,674,651,563,562,648,635,629,632,637,630,982,983,998,1001,1002,1115,1088,1095,1094,1093,767,768,775,787,796,807,817,827,818,791,792,532,751,540,673,558,559,564,565,649,621,623,619,638,610,986,985,995,994,1000,1114,1108,1099,763,764,765,777,776,781,809,808,803,821,822,789,790,533,542,541,544,549,560,567,566,585,620,622,616,613,611,981,987,992,991,999,1111,1109,1104,759,758,757,769,772,801,802,805,804,820,826,788,535,534,536,539,553,554,561,569,578,584,602,607,612,614,615,980,984,990,989,997,1110,1113,754,755,760,762,766,798,800,799,814,813,812,831,835,838,840,841,846,552,551,571,570,579,589,595,608,921,917,957,975,969,970,988,996,1117,1116,748,753,752,756,694,797,698,699,816,815,811,810,833,834,842,849,847,548,550,573,572,581,583,588,609,920,918,959,963,964,965,966,968,1120,1119,747,746,745,740,695,696,697,700,819,823,825,829,832,836,839,855,547,546,545,574,575,582,586,587,927,922,960,961,962,958,956,967,971,1121,1122,743,742,741,734,728,723,717,703,702,701,824,851,869,867,866,863,872,874,875,577,576,916,919,923,926,925,936,935,943,953,955,976,973,1126,1124,744,735,739,733,725,722,716,706,705,710,850,853,857,862,865,864,878,885,876,900,903,914,913,924,928,930,937,940,944,948,952,977,972,1127,1123,731,732,738,737,718,719,715,711,708,709,848,852,858,859,868,892,891,890,895,899,902,911,912,910,929,931,933,941,942,950,949,978,979,1128,1129,730,729,727,726,721,720,713,712,707,844,845,843,861,860,870,871,873,893,894,901,904,907,909,908,906,905,932,939,938,951,947,946,945},
{1599,1598,1597,1596,1595,1594,1593,1592,1591,1590,1589,1588,1587,1586,1585,1584,1583,1582,1581,1580,1579,1578,1577,1576,1575,1574,1573,1572,1571,1570,1569,1568,1567,1566,1565,1564,1563,1562,1561,1560,1520,1521,1522,1523,1524,1525,1526,1527,1528,1529,1530,1531,1532,1533,1534,1535,1536,1537,1538,1539,1540,1541,1542,1543,1544,1545,1546,1547,1548,1549,1550,1551,1552,1553,1554,1555,1556,1557,1558,1559,1519,1518,1517,1516,1515,1514,1513,1512,1511,1510,1509,1508,1507,1506,1505,1504,1503,1502,1501,1500,1499,1498,1497,1496,1495,1494,1493,1492,1491,1490,1489,1488,1487,1486,1485,1484,1483,1482,1481,1480,1440,1441,1442,1443,1444,1445,1446,1447,1448,1449,1450,1451,1452,1453,1454,1455,1456,1457,1458,1459,1460,1461,1462,1463,1464,1465,1466,1467,1468,1469,1470,1471,1472,1473,1474,1475,1476,1477,1478,1479,1439,1438,1437,1436,1435,1434,1433,1432,1431,1430,1429,1428,1427,1426,1425,1424,1423,1422,1421,1420,1419,1418,1417,1416,1415,1414,1413,1412,1411,1410,1409,1408,1407,1406,1405,1404,1403,1402,1401,1400,1360,1361,1362,1363,1364,1365,1366,1367,1368,1369,1370,1371,1372,1373,1374,1375,1376,1377,1378,1379,1380,1381,1382,1383,1384,1385,1386,1387,1388,1389,1390,1391,1392,1393,1394,1395,1396,1397,1398,1399,1359,1358,1357,1356,1355,1354,1353,1352,1351,1350,1349,1348,1347,1346,1345,1344,1343,1342,1341,1340,1339,1338,1337,1336,1335,1334,1333,1332,1331,1330,1329,1328,1327,1326,1325,1324,1323,1322,1321,1320,1280,1281,1282,1283,1284,1285,1286,1287,1288,1289,1290,1291,1292,1293,1294,1295,1296,1297,1298,1299,1300,1301,1302,1303,1304,1305,1306,1307,1308,1309,1310,1311,1312,1313,1314,1315,1316,1317,1318,1319,1279,1278,1277,1276,1275,1274,1273,1272,1271,1270,1269,1268,1267,1266,1265,1264,1263,1262,1261,1260,1259,1258,1257,1256,1255,1254,1253,1252,1251,1250,1249,1248,1247,1246,1245,1244,1243,1242,1241,1240,1200,1201,1202,1203,1204,1205,1206,1207,1208,1209,1210,1211,1212,1213,1214,1215,1216,1217,1218,1219,1220,1221,1222,1223,1224,1225,1226,1227,1228,1229,1230,1231,1232,1233,1234,1235,1236,1237,1238,1239,1199,1198,1197,1196,1195,1194,1193,1192,1191,1190,1189,1188,1187,1186,1185,1184,1183,1182,1181,1180,1179,1178,1177,1176,1175,1174,1173,1172,1171,1170,1169,1168,1167,1166,1165,1164,1163,1162,1161,1160,1120,1121,1122,1123,1124,1125,1126,1127,1128,1129,1130,1131,1132,1133,1134,1135,1136,1137,1138,1139,1140,1141,1142,1143,1144,1145,1146,1147,1148,1149,1150,1151,1152,1153,1154,1155,1156,1157,1158,1159,1119,1118,1117,1116,1115,1114,1113,1112,1111,1110,1109,1108,1107,1106,1105,1104,1103,1102,1101,1100,1099,1098,1097,1096,1095,1094,1093,1092,1091,1090,1089,1088,1087,1086,1085,1084,1083,1082,1081,1080,1040,1041,1042,1043,1044,1045,1046,1047,1048,1049,1050,1051,1052,1053,1054,1055,1056,1057,1058,1059,1060,1061,1062,1063,1064,1065,1066,1067,1068,1069,1070,1071,1072,1073,1074,1075,1076,1077,1078,1079,1039,1038,1037,1036,1035,1034,1033,1032,1031,1030,1029,1028,1027,1026,1025,1024,1023,1022,1021,1020,1019,1018,1017,1016,1015,1014,1013,1012,1011,1010,1009,1008,1007,1006,1005,1004,1003,1002,1001,1000,960,961,962,963,964,965,966,967,968,969,970,971,972,973,974,975,976,977,978,979,980,981,982,983,984,985,986,987,988,989,990,991,992,993,994,995,996,997,998,999,959,958,957,956,955,954,953,952,951,950,949,948,947,946,945,944,943,942,941,940,939,938,937,936,935,934,933,932,931,930,929,928,927,926,925,924,923,922,921,920,880,881,882,883,884,885,886,887,888,889,890,891,892,893,894,895,896,897,898,899,900,901,902,903,904,905,906,907,908,909,910,911,912,913,914,915,916,917,918,919,879,878,877,876,875,874,873,872,871,870,869,868,867,866,865,864,863,862,861,860,859,858,857,856,855,854,853,852,851,850,849,848,847,846,845,844,843,842,841,840,800,801,802,803,804,805,806,807,808,809,810,811,812,813,814,815,816,817,818,819,820,821,822,823,824,825,826,827,828,829,830,831,832,833,834,835,836,837,838,839,799,798,797,796,795,794,793,792,791,790,789,788,787,786,785,784,783,782,781,780,779,778,777,776,775,774,773,772,771,770,769,768,767,766,765,764,763,762,761,760,720,721,722,723,724,725,726,727,728,729,730,731,732,733,734,735,736,737,738,739,740,741,742,743,744,745,746,747,748,749,750,751,752,753,754,755,756,757,758,759,719,718,717,716,715,714,713,712,711,710,709,708,707,706,705,704,703,702,701,700,699,698,697,696,695,694,693,692,691,690,689,688,687,686,685,684,683,682,681,680,640,641,642,643,644,645,646,647,648,649,650,651,652,653,654,655,656,657,658,659,660,661,662,663,664,665,666,667,668,669,670,671,672,673,674,675,676,677,678,679,639,638,637,636,635,634,633,632,631,630,629,628,627,626,625,624,623,622,621,620,619,618,617,616,615,614,613,612,611,610,609,608,607,606,605,604,603,602,601,600,560,561,562,563,564,565,566,567,568,569,570,571,572,573,574,575,576,577,578,579,580,581,582,583,584,585,586,587,588,589,590,591,592,593,594,595,596,597,598,599,559,558,557,556,555,554,553,552,551,550,549,548,547,546,545,544,543,542,541,540,539,538,537,536,535,534,533,532,531,530,529,528,527,526,525,524,523,522,521,520,480,481,482,483,484,485,486,487,488,489,490,491,492,493,494,495,496,497,498,499,500,501,502,503,504,505,506,507,508,509,510,511,512,513,514,515,516,517,518,519,479,478,477,476,475,474,473,472,471,470,469,468,467,466,465,464,463,462,461,460,459,458,457,456,455,454,453,452,451,450,449,448,447,446,445,444,443,442,441,440,400,401,402,403,404,405,406,407,408,409,410,411,412,413,414,415,416,417,418,419,420,421,422,423,424,425,426,427,428,429,430,431,432,433,434,435,436,437,438,439,399,398,397,396,395,394,393,392,391,390,389,388,387,386,385,384,383,382,381,380,379,378,377,376,375,374,373,372,371,370,369,368,367,366,365,364,363,362,361,360,320,321,322,323,324,325,326,327,328,329,330,331,332,333,334,335,336,337,338,339,340,341,342,343,344,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,319,318,317,316,315,314,313,312,311,310,309,308,307,306,305,304,303,302,301,300,299,298,297,296,295,294,293,292,291,290,289,288,287,286,285,284,283,282,281,280,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274,275,276,277,278,279,239,238,237,236,235,234,233,232,231,230,229,228,227,226,225,224,223,222,221,220,219,218,217,216,215,214,213,212,211,210,209,208,207,206,205,204,203,202,201,200,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,159,158,157,156,155,154,153,152,151,150,149,148,147,146,145,144,143,142,141,140,139,138,137,136,135,134,133,132,131,130,129,128,127,126,125,124,123,122,121,120,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,79,78,77,76,75,74,73,72,71,70,69,68,67,66,65,64,63,62,61,60,59,58,57,56,55,54,53,52,51,50,49,48,47,46,45,44,43,42,41,40,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39},
{1492,1487,1484,1480,1476,1474,1464,1460,1451,1439,1427,1415,1397,1375,1343,1312,1282,1254,1226,1194,1169,1147,1128,1115,1107,1103,1105,1112,1125,1138,1153,1163,1174,1184,1193,1201,1207,1453,1454,1456,1493,1491,1486,1481,1477,1472,1467,1461,1452,1440,1428,1416,1399,1376,1347,1315,1283,1252,1223,1191,1165,1143,1124,1110,1102,1097,1100,1109,1121,1136,1152,1164,1176,1187,1197,1205,1211,1448,1449,1450,1497,1494,1490,1485,1479,1473,1468,1462,1455,1442,1430,1418,1400,1378,1351,1318,1285,1250,1218,1183,1155,1132,1113,1099,1091,1087,1092,1101,1114,1130,1148,1166,1180,1192,1204,1214,1221,1441,1443,1444,1501,1498,1495,1489,1483,1475,1469,1463,1457,1445,1433,1420,1403,1382,1357,1321,1288,1251,1213,1172,1141,1117,1098,1085,1080,1077,1081,1089,1104,1122,1144,1167,1185,1202,1217,1228,1234,1436,1437,1438,1504,1502,1500,1496,1488,1478,1470,1465,1458,1446,1434,1422,1407,1386,1361,1326,1294,1257,1215,1151,1118,1096,1082,1073,1068,1066,1069,1076,1088,1108,1137,1170,1195,1216,1232,1242,1247,1429,1431,1432,1507,1506,1505,1503,1499,1482,1471,1466,1459,1447,1435,1423,1409,1389,1364,1329,1297,1266,1240,1094,1083,1072,1061,1053,1046,1045,1050,1059,1070,1086,1120,1181,1212,1233,1248,1262,1269,1424,1425,1426,1508,1509,1510,1513,1520,1536,1545,1551,1556,1560,1564,1568,1572,1576,1580,1584,1588,1592,1596,1055,1048,1041,1033,1027,1022,1021,1026,1034,1043,1057,1071,1224,1237,1253,1268,1284,1299,1413,1419,1421,1511,1512,1516,1522,1531,1541,1548,1553,1557,1561,1565,1569,1573,1577,1581,1585,1589,1593,1597,1016,1014,1012,1008,1005,1002,1003,1006,1011,1015,1023,1030,1249,1260,1274,1290,1309,1339,1390,1410,1417,1514,1515,1519,1523,1543,1546,1550,1554,1558,1562,1566,1570,1574,1578,1582,1586,1590,1594,1598,988,986,984,981,979,978,980,985,989,992,996,998,1267,1278,1293,1308,1331,1359,1388,1406,1414,1518,1517,1521,1524,1547,1549,1552,1555,1559,1563,1567,1571,1575,1579,1583,1587,1591,1595,1599,964,962,959,956,955,957,961,965,968,970,971,972,1276,1291,1306,1324,1346,1369,1391,1405,1412,1525,1527,1533,1537,179,180,183,188,195,199,209,221,238,261,283,299,311,319,323,940,939,937,935,936,938,941,943,946,947,948,950,1271,1303,1320,1338,1360,1377,1394,1404,1411,1526,1529,1535,1539,176,177,184,189,196,200,210,224,240,264,287,305,318,326,329,920,921,922,923,924,925,926,927,928,929,930,931,1235,1327,1336,1352,1368,1381,1395,1402,1408,1528,1532,1538,1542,173,174,185,190,197,202,212,226,244,269,294,316,331,339,342,903,904,906,908,909,910,911,912,913,914,915,916,1196,1340,1350,1363,1373,1383,1392,1398,1401,1530,1534,1540,1544,170,171,186,191,198,203,213,227,247,274,302,337,351,358,361,879,880,881,883,885,887,889,890,892,894,896,897,1159,1345,1355,1365,1372,1380,1387,1393,1396,5,6,8,9,29,30,354,359,366,374,386,396,403,407,401,381,380,383,385,854,856,858,860,862,864,865,866,868,871,873,875,1123,1342,1349,1358,1366,1374,1379,1384,1385,10,11,12,13,33,34,350,357,365,375,389,400,410,415,413,406,405,408,411,824,828,831,834,837,841,843,845,848,853,855,857,1084,1333,1337,1344,1354,1362,1367,1370,1371,15,16,17,18,37,38,341,353,364,377,391,404,416,421,425,426,427,430,433,802,805,809,812,816,820,822,823,827,830,833,835,1044,1322,1325,1330,1335,1341,1348,1353,1356,19,20,22,23,42,43,324,352,367,382,397,412,422,431,438,442,445,450,455,773,778,785,792,798,803,806,810,813,815,818,819,1009,1311,1313,1317,1319,1323,1328,1332,1334,24,25,26,27,45,46,279,363,373,388,402,419,429,440,448,454,461,469,478,742,749,757,767,775,782,789,796,801,804,807,808,975,1301,1302,1304,1305,1307,1310,1314,1316,31,32,35,36,51,52,231,370,378,392,409,423,436,447,457,463,475,492,513,706,720,733,746,755,763,770,776,783,788,794,797,945,1286,1287,1289,1292,1295,1296,1298,1300,40,41,44,47,54,58,187,372,379,394,414,428,441,451,462,473,491,522,566,649,691,713,729,739,748,753,760,766,772,777,780,919,1270,1272,1273,1275,1277,1279,1280,1281,48,50,53,56,62,67,147,368,376,395,417,432,444,456,465,481,504,538,579,631,674,701,717,730,737,740,747,752,759,765,769,891,1255,1256,1258,1259,1261,1263,1264,1265,55,57,59,64,70,82,109,360,369,393,418,434,446,458,467,485,512,545,583,626,666,695,710,724,732,731,735,743,751,756,761,861,1236,1238,1239,1241,1243,1244,1245,1246,61,63,65,69,77,86,96,347,349,343,346,355,371,399,437,464,489,521,548,576,600,621,643,670,692,714,726,734,744,754,762,826,1219,1220,1222,1225,1227,1229,1230,1231,66,68,72,76,80,87,92,333,334,335,338,348,362,390,443,471,493,524,550,575,599,619,639,667,690,707,718,728,738,758,774,800,1198,1199,1200,1203,1206,1208,1209,1210,71,74,78,81,85,89,93,320,322,325,328,336,345,356,468,483,503,530,552,574,595,613,636,663,686,702,711,721,727,771,781,793,1178,1177,1179,1182,1186,1188,1189,1190,75,79,83,88,91,94,97,310,313,315,317,321,327,332,484,495,515,536,554,572,592,610,634,660,684,700,709,715,719,779,786,791,1160,1156,1157,1162,1168,1171,1173,1175,73,84,90,95,99,101,102,301,303,306,307,309,312,314,497,507,523,540,556,571,591,608,629,654,681,698,708,712,716,784,787,790,1145,1131,1134,1142,1149,1154,1158,1161,60,98,100,103,104,105,107,290,292,295,296,297,298,300,508,516,528,542,557,570,587,604,624,641,656,673,687,696,699,997,1001,1007,1067,1090,1106,1119,1129,1139,1146,1150,49,106,108,110,111,112,113,281,282,284,285,286,288,289,511,517,529,541,555,568,584,602,618,635,653,671,685,693,697,995,1000,1013,1040,1063,1079,1095,1111,1126,1135,1140,39,114,115,116,117,118,119,265,267,270,273,276,278,280,506,514,526,539,551,565,581,597,611,628,645,664,679,689,694,987,993,1004,1018,1035,1054,1078,1093,1116,1127,1133,28,120,121,122,123,124,125,248,250,253,257,262,266,268,496,505,519,535,547,562,577,593,606,623,638,657,672,683,688,977,982,990,999,1010,1017,1074,1075,1065,1060,1058,21,126,127,128,129,130,131,233,235,237,243,249,256,259,487,494,510,527,543,558,573,589,603,617,632,650,665,676,682,966,969,974,983,991,994,1064,1062,1056,1052,1049,14,132,133,134,135,136,137,223,225,228,234,242,251,255,480,486,498,518,537,553,569,585,601,612,627,642,658,669,675,949,952,958,967,973,976,1051,1047,1042,1039,1037,7,138,139,140,141,142,144,214,215,220,229,239,252,258,472,477,488,509,531,549,567,582,598,609,625,637,651,661,668,932,934,942,953,960,963,1038,1036,1032,1028,1025,4,143,145,146,148,151,153,208,211,218,230,245,260,271,459,466,479,499,525,546,564,580,596,607,622,633,644,655,662,918,917,933,944,951,954,1031,1029,1024,1020,1019,3,149,150,152,156,160,165,201,207,216,232,254,275,291,439,453,470,490,520,544,563,578,594,605,620,630,640,652,659,901,878,859,852,849,850,870,877,888,899,907,2,154,155,158,163,168,178,194,205,217,236,263,293,330,398,435,460,482,502,534,561,590,616,646,677,703,722,736,750,814,836,840,842,844,847,869,876,886,898,905,1,157,159,164,167,172,181,192,204,219,241,272,304,340,387,424,452,476,501,533,560,588,615,647,678,704,723,741,764,799,817,825,832,839,846,867,874,884,895,902,0,161,162,166,169,175,182,193,206,222,246,277,308,344,384,420,449,474,500,532,559,586,614,648,680,705,725,745,768,795,811,821,829,838,851,863,872,882,893,900},
{31,29,28,24,19,18,58,42,43,39,32,16,14,13,11,10,8,395,396,394,393,391,611,613,617,618,627,630,632,642,643,653,654,646,682,681,679,670,666,667,1506,1505,1513,1454,1453,1452,1438,1429,1427,1434,35,36,27,25,20,66,60,56,50,34,33,17,15,12,3,0,6,399,398,397,392,432,430,615,616,622,625,626,634,640,644,652,649,647,684,678,677,671,669,668,1507,1510,1512,1455,1456,1451,1436,1430,1432,1433,38,37,52,23,21,70,71,73,49,30,26,22,549,9,2,1,5,400,403,408,407,431,429,614,619,620,621,639,638,641,645,655,656,680,687,686,675,673,674,1504,1503,1511,1475,1469,1463,1442,1435,1428,1431,1424,40,55,53,64,72,75,69,74,101,538,541,545,548,7,4,523,526,528,406,409,405,404,426,425,414,415,410,727,637,650,651,657,665,672,699,1294,1292,1299,1302,1502,1498,1494,1479,1470,1472,1471,1391,1421,1422,1423,41,51,54,63,68,82,88,105,102,536,542,554,550,551,519,521,527,529,484,413,418,422,427,419,420,416,412,728,735,689,690,658,664,726,713,1296,1298,1300,1301,1501,1499,1490,1484,1489,1473,1474,1390,1413,1414,1417,44,48,57,62,67,95,96,104,103,535,558,557,547,543,517,520,518,496,483,482,480,421,433,428,424,417,719,729,733,732,691,688,663,738,740,741,1297,1303,1492,1493,1497,1482,1485,1487,1486,1389,1388,1403,1415,1416,46,47,59,61,65,129,119,111,109,534,561,562,546,544,533,522,510,497,485,474,462,452,443,464,715,716,720,724,734,694,693,685,683,748,749,750,777,1305,1307,1495,1496,1481,1480,1488,1355,1353,1387,1394,1392,1385,45,91,90,94,138,137,144,145,146,147,563,564,553,552,532,531,511,514,515,516,460,459,461,463,465,714,722,723,702,701,696,695,758,757,774,773,775,1304,1309,1312,1314,1315,1341,1342,1356,1350,1379,1382,1383,1384,78,80,89,92,150,151,152,160,168,175,184,565,569,559,560,530,512,513,579,453,454,455,456,457,708,711,712,707,703,700,698,697,764,766,767,770,771,772,1311,1313,1317,1316,1340,1343,1345,1348,1369,1370,1252,1253,79,81,86,85,149,296,153,297,304,305,191,566,568,567,572,576,581,580,578,577,447,451,450,458,709,710,718,717,759,760,761,762,763,776,765,768,778,779,1322,1323,1324,1329,1335,1347,1349,1346,1358,1320,1251,1255,77,84,87,98,99,295,294,298,303,306,199,206,207,590,589,588,584,583,442,444,445,441,437,434,730,731,725,752,756,951,961,960,783,784,793,795,794,780,782,781,1325,1328,1336,1337,1351,1331,1318,1319,1257,1258,76,83,93,97,100,288,289,299,308,307,212,213,211,245,248,586,587,438,440,439,446,636,436,659,660,736,739,751,754,952,955,958,836,835,802,796,792,789,786,1327,1326,1333,1334,1338,1352,1330,1306,1285,1262,1261,113,115,114,110,106,286,285,279,273,272,271,222,243,244,246,585,591,593,603,612,624,635,648,662,661,742,743,747,755,950,956,957,846,834,818,790,791,788,808,809,812,813,819,817,1354,1289,1293,1284,1264,1263,112,116,120,108,107,287,284,283,270,266,268,232,241,240,600,599,592,595,594,610,623,633,692,676,746,745,744,942,943,946,927,928,856,837,839,841,843,787,807,810,811,816,820,815,1188,1290,1291,1275,1265,1266,135,117,125,126,275,276,277,280,265,264,269,255,249,239,601,598,597,596,582,609,629,631,706,705,704,804,805,806,941,938,936,929,867,877,888,842,845,848,826,829,830,824,825,814,1189,1287,1288,1250,1256,1245,133,118,131,143,274,139,282,281,262,258,257,261,250,606,602,608,574,573,570,571,628,478,721,769,785,803,801,800,937,939,940,922,915,909,898,899,847,849,827,828,831,833,832,1191,1190,1192,1286,1249,1248,1246,132,134,136,142,141,140,254,256,259,260,263,267,278,605,604,607,575,556,555,509,494,479,737,753,823,822,840,799,798,945,944,921,911,912,913,900,855,851,868,869,870,844,838,1186,1187,1193,1217,1229,1240,1196,130,127,128,148,253,252,251,197,198,195,192,189,290,300,301,377,378,537,539,524,467,466,470,469,468,821,859,858,797,947,948,919,918,917,916,861,860,862,865,866,857,850,1182,1183,1195,1194,1206,1244,1243,1198,123,124,154,155,156,242,247,196,200,194,190,188,291,309,302,376,381,386,540,525,448,449,473,472,881,879,878,896,965,962,953,954,923,920,969,971,968,863,864,871,854,853,1177,1181,1180,1184,1205,1204,1203,1199,2020,122,121,163,238,237,236,205,204,208,187,186,292,317,316,375,385,384,382,383,423,435,475,471,882,930,931,914,964,963,959,924,925,926,973,972,970,874,875,876,880,852,1176,1175,1174,1173,1166,1167,1202,1201,2018,2016,2014,170,177,230,221,202,203,210,178,183,293,327,336,353,387,388,380,389,411,476,477,481,883,887,933,932,949,966,967,977,974,975,976,985,872,873,890,889,884,1179,1178,1081,1164,1163,1165,1168,1169,1170,2017,2007,2012,2010,185,229,215,216,217,214,179,180,176,328,344,352,360,368,379,390,401,402,487,486,885,886,934,935,1004,986,987,978,979,980,981,984,983,891,892,893,901,904,1083,1082,1098,1151,1141,1130,1129,1124,2006,2008,2011,2009,193,201,209,218,220,219,182,181,174,173,345,346,364,365,362,350,349,348,492,491,490,489,488,1381,1024,1043,1052,1051,990,991,993,989,982,895,894,897,902,903,1084,1085,1096,1097,1108,1122,1128,1125,2005,2019,2015,2025,2027,2028,228,227,226,231,233,161,172,171,372,371,367,361,359,354,351,508,493,495,500,1377,1378,1380,1026,1061,1053,1046,1039,999,1001,988,1002,910,908,907,905,906,1079,1086,1094,1101,1107,1114,1127,1126,2022,2021,2023,2024,2026,2029,223,224,225,234,235,162,165,169,373,369,366,363,358,357,347,507,506,498,499,1374,1375,1115,1116,1089,1049,1048,1030,1020,1010,1006,1003,997,996,994,992,1072,1075,1069,1095,1102,1103,1104,1106,1105,2051,2049,2048,2042,2034,2032,2031,2030,2037,157,158,159,166,167,374,370,2237,2236,356,340,343,505,504,501,1373,1372,1200,1171,1144,1088,1087,1008,1031,1019,1013,1012,1000,998,995,1064,1065,1068,1074,1071,1070,1210,1211,1216,1109,1111,2052,2053,2043,2044,2035,2036,2041,2040,2038,2191,2190,2189,164,2193,2226,2225,2221,2235,355,337,334,333,503,502,1368,1371,1228,1254,1276,1277,1278,1009,1011,1016,1017,1025,1027,1047,1050,1062,1063,1066,1076,1077,1212,1213,1214,1215,1110,1113,2057,2056,2064,2045,2047,2050,2046,2039,2072,2186,2185,2188,2192,2194,2198,2224,2223,2234,2233,332,331,330,312,311,1367,1339,1310,1282,1281,1280,1279,1007,1014,1015,1021,1023,1042,1045,1054,1057,1060,1067,1078,1092,1093,1219,1218,1222,1242,1241,2058,2059,2063,2062,2061,2060,2069,2070,2071,2187,2184,2183,2182,2181,2202,2220,2222,2227,2230,335,326,329,313,310,1393,1420,1477,1531,1532,1750,1751,1005,1743,1018,1022,1041,1040,1044,1056,1058,1059,1073,1080,1090,1091,1225,1226,1227,1233,1239,2482,2066,2065,2090,2089,2088,2075,2087,2073,2175,2176,2177,2179,2178,2207,2213,2218,2232,2231,338,321,318,315,1450,1449,1448,1478,1530,1533,1748,1747,1745,1744,1732,1028,1033,1038,1036,1055,1120,1121,1123,1112,1100,1099,1223,1224,1230,1232,1236,2481,2068,2067,2460,2461,2085,2082,2086,2100,2102,2101,2170,2180,2145,2205,2206,2137,2127,2128,339,319,320,314,1441,1443,1446,1508,1541,1534,1752,1749,1742,1741,1733,1029,1032,1037,1035,1138,1119,1118,1137,1149,1160,1172,1221,1235,1231,1238,1237,2480,2477,2466,2465,2463,2084,2093,2091,2092,2104,2103,2163,2162,2146,2141,2138,2136,2134,2129,341,323,322,1439,1440,1444,1445,1538,1539,1535,1753,1757,1740,1737,1734,1713,1712,1710,1034,1140,1117,1148,1139,1136,1135,1185,1220,1234,1247,1273,1274,2479,2478,2476,2467,2462,2083,2094,2095,2107,2106,2120,2157,2151,2147,2143,2139,2131,2132,2130,342,324,325,1653,1652,1650,1647,1566,1537,1536,1755,1756,1739,1736,1735,1714,1711,1709,1143,1142,1145,1147,1146,1150,1134,1197,1209,1208,1259,1272,1271,2471,2472,2473,2470,2457,2458,2098,2099,2108,2118,2119,2121,2148,2144,2150,2140,1974,1954,1892,1870,1848,1804,1654,1646,1648,1649,1594,1772,1771,1754,1746,1738,1730,1724,1719,1705,1708,1707,1706,1158,1159,1157,1154,1133,1132,1365,1207,1260,1283,1270,2486,2474,2475,2469,2464,2459,2097,2105,2109,2112,2117,2124,2133,2142,2149,2159,1993,1933,1913,1826,1827,1805,1783,1645,1679,1651,1623,1780,1769,1761,1777,1778,1729,1699,1698,1701,1696,1697,1693,1162,1161,1156,1155,1131,1363,1364,1360,1361,1295,1269,2485,2484,2483,2468,2455,2456,2453,2454,2113,2114,2115,2125,2123,2155,2156,2158,2013,2033,2055,2054,1758,1759,1760,1731,1704,1786,1782,1781,1774,1775,1776,1723,1726,1700,1702,1703,1690,1691,1692,1694,1695,1152,1153,1410,1362,1366,1357,1359,1308,1268,2491,2490,2489,2494,2496,2497,2450,2452,2451,2449,2111,2126,2122,2161,2160,2135,2116,2096,2077,2076,2074,1767,1766,1773,1779,1787,1788,1790,1791,1792,1793,1722,1725,1727,1728,1672,1685,1684,1689,1688,1682,1425,1412,1411,1386,1376,1344,1332,1321,1267,2492,2488,2487,2495,2498,2440,2445,2443,2444,2447,2110,2167,2166,2165,2164,2154,2153,2078,2079,1813,1770,1768,1765,1764,1784,1785,1846,1802,1811,1814,1815,1721,1720,1675,1674,1673,1681,1680,1687,1686,1683,1426,1418,1409,1397,1398,1396,1641,1644,1643,2493,2427,2425,2423,2499,2436,2446,2442,2441,2448,2174,2173,2171,2169,2168,2172,2152,2081,2080,1812,1810,1762,1763,1794,1789,1845,1844,1817,1818,1819,1820,1821,1718,1717,1676,1678,1677,1656,1657,1658,1447,1437,1419,1408,1400,1399,1395,1640,1639,1642,2430,2429,2426,2420,2421,2433,2434,2438,2439,2284,2269,2254,2243,2228,2212,2195,2196,2197,1800,1801,1806,1807,1803,1798,1823,1822,1842,1839,1825,1829,1828,1890,1889,1716,1715,1670,1671,1655,1659,1660,1458,1461,1462,1460,1401,1402,1407,1636,1638,1624,2432,2431,2415,2418,2422,2428,2435,2437,2306,2298,2308,2252,2245,2247,2204,2203,2209,2199,1799,1797,1796,1808,1809,1816,1824,1833,1834,1836,1832,1830,1831,1886,1887,2004,1667,1668,1669,1666,1661,1662,1468,1466,1464,1459,1405,1404,1406,1635,1637,1625,2407,2417,2416,2414,2419,2424,2316,2317,2313,2304,2307,2311,2246,2242,2219,2210,2211,2200,2201,1795,1894,1895,1893,1888,1843,1838,1835,1837,1840,1841,1869,1884,1874,2003,1998,1997,1996,1665,1664,1663,1476,1467,1465,1457,1627,1628,1630,1633,1629,1626,2406,2401,2402,2403,2383,2376,2318,2319,2320,2305,2309,2310,2315,2241,2229,2208,2214,2215,2216,2217,1902,1896,1897,1883,1847,1855,1861,1850,1849,1858,1868,1882,1875,2002,1999,1995,1994,1527,1526,1524,1483,1491,1500,1509,1516,1631,1632,1634,1621,1622,2405,2399,2397,2396,2389,2369,2368,2348,2328,2327,2332,2312,2314,2240,2238,2239,2250,2261,2263,2253,1903,1904,1901,1878,1852,1856,1860,1851,1871,1873,1876,1879,1877,2001,2000,1992,1991,1528,1525,1523,1522,1520,1519,1518,1517,1617,1616,1613,1612,1618,2404,2400,2398,2342,2341,2362,2356,2347,2337,2336,2334,2289,2290,2288,2244,2248,2251,2260,2257,2255,1908,1907,1900,1872,1867,1862,1859,1857,1854,1891,1885,1880,1881,1983,1979,1988,1989,1990,1559,1555,1521,1552,1540,1529,1515,1620,1619,1611,1610,1614,2408,2410,2412,2344,2354,2353,2359,2363,2374,2375,2335,2294,2293,2287,2283,2249,2256,2262,2258,2259,1909,1911,1899,1939,1938,1863,1865,1866,1853,1898,1905,1906,1981,1982,1980,1984,1987,1986,1558,1554,1553,1551,1549,1548,1514,1607,1608,1609,1606,1615,2409,2411,2413,2345,2350,2352,2360,2365,2373,2382,2385,2386,2285,2286,2282,2277,2274,2270,2273,2272,1910,1915,1914,1931,1937,1923,1864,1928,1927,1919,1912,1959,1964,1965,1975,1976,1977,1985,1560,1550,1547,1546,1556,1562,1561,1603,1602,1601,1604,1605,2321,2323,2331,2346,2349,2351,2361,2364,2372,2381,2384,2387,2292,2291,2295,2296,2301,2276,2275,2271,1917,1918,1926,1932,1935,1924,1925,1929,1934,1941,1953,1960,1963,1966,1970,1971,1978,1542,1543,1544,1545,1585,1557,1569,1577,1583,1590,1596,1597,1563,2322,2324,2330,2343,2340,2355,2358,2367,2371,2377,2380,2388,2390,2391,2297,2299,2300,2278,2279,2268,2264,1916,1945,1936,1940,1921,1922,1930,1948,1947,1952,1961,1969,1968,1967,1972,1600,1592,1593,1591,1587,1584,1581,1580,1579,1582,1572,1570,1571,1564,2325,2326,2329,2333,2338,2339,2357,2366,2370,2378,2379,2395,2394,2393,2392,2302,2303,2280,2281,2267,2266,2265,1944,1943,1942,1920,1951,1950,1949,1946,1955,1956,1957,1958,1962,1973,1599,1598,1595,1586,1588,1589,1578,1576,1575,1574,1573,1568,1567,1565},
{134,133,120,119,118,138,141,143,144,146,149,151,153,186,188,189,291,292,295,301,306,314,319,324,327,527,534,552,592,609,641,646,650,656,659,681,683,689,697,702,879,881,887,902,907,911,913,915,985,986,131,130,115,114,113,137,139,142,145,147,150,154,156,192,193,194,294,296,299,304,309,316,323,329,332,518,523,529,617,623,643,648,654,660,663,684,688,696,704,710,875,877,878,910,912,914,916,918,983,984,127,126,109,108,107,135,136,140,148,152,155,158,160,197,199,200,302,303,305,311,317,325,333,339,341,508,511,513,635,638,647,655,662,667,669,690,698,706,714,721,868,869,870,917,919,920,921,922,980,982,125,124,104,103,102,128,129,132,157,159,161,162,163,203,204,205,310,312,315,320,328,337,344,350,354,490,493,495,649,652,658,665,670,674,677,701,709,716,724,742,860,861,862,923,924,925,926,927,978,979,117,116,98,97,96,121,122,123,164,165,166,167,168,208,210,211,321,322,326,331,340,348,356,365,373,468,473,477,666,668,671,675,679,685,693,708,717,723,727,783,850,853,854,928,929,931,933,934,974,976,106,105,94,92,91,110,111,112,169,170,171,172,173,214,215,216,334,335,338,342,349,357,368,382,401,439,455,464,678,680,682,687,692,700,711,720,726,731,735,824,841,846,847,935,936,937,938,939,969,968,95,93,88,86,85,99,100,101,174,175,176,177,178,219,221,222,343,345,347,351,358,367,378,393,408,430,444,452,691,694,699,705,712,718,725,732,737,741,744,840,845,848,849,940,941,942,944,946,964,965,84,83,82,81,80,87,89,90,179,180,181,182,183,225,226,227,352,353,355,360,366,377,390,402,414,429,441,447,713,715,719,722,728,734,740,745,749,751,754,852,855,857,858,943,945,948,952,957,963,967,77,76,74,73,72,75,78,79,184,185,187,190,191,230,232,233,361,362,364,369,375,387,398,407,418,432,442,446,730,733,736,739,743,748,752,756,759,762,764,863,864,865,866,947,949,953,958,961,966,971,71,70,69,66,64,65,67,68,195,196,198,201,202,235,237,238,370,371,372,374,376,400,405,412,421,435,443,449,746,747,750,753,757,761,765,767,770,773,775,872,873,874,876,950,951,956,959,962,970,981,63,62,61,60,59,58,57,56,206,207,209,212,213,241,243,244,384,383,381,380,379,406,410,417,426,440,450,454,758,760,763,766,768,772,776,778,782,786,787,880,882,883,884,987,989,995,1004,1007,1008,1002,55,54,53,52,51,50,48,46,217,218,220,223,224,246,247,248,394,392,389,386,385,409,413,420,433,448,457,462,769,771,774,777,780,784,789,793,796,801,803,888,890,891,892,988,991,998,1005,1012,1015,1014,49,47,45,44,42,40,38,36,228,229,231,234,236,253,254,255,404,403,395,391,388,411,415,422,438,459,466,467,779,781,785,788,792,795,802,807,812,818,822,893,895,897,899,990,994,1003,1011,1018,1021,1022,43,41,39,35,32,29,27,25,239,240,242,245,250,258,262,263,416,423,445,463,469,514,512,506,494,478,474,471,790,791,794,799,804,809,815,821,827,832,838,894,898,901,903,992,997,1006,1017,1023,1027,1029,37,34,31,28,23,22,20,21,249,251,252,256,260,267,271,274,424,434,451,465,472,510,509,504,496,485,479,476,798,800,805,810,816,823,828,831,836,843,859,885,900,904,905,993,999,1010,1020,1028,1031,1035,33,30,26,24,18,17,15,19,257,259,261,265,270,277,284,287,425,437,453,470,483,500,505,502,497,489,484,480,806,808,814,820,826,830,834,837,842,851,867,886,906,930,954,975,996,1016,1026,1032,1036,1038,2444,2441,2439,2436,13,12,10,16,264,266,268,273,280,289,298,308,419,436,456,475,491,499,503,501,498,492,487,482,811,813,819,825,829,833,835,839,844,856,871,889,908,932,955,977,1000,1025,1034,1037,1040,1043,2442,2437,2435,2434,8,7,6,14,269,272,276,281,288,300,318,346,399,431,458,481,507,533,551,560,565,570,572,571,562,559,555,553,550,548,545,1142,1143,1145,1149,1152,1151,1144,1124,1100,1074,1048,1042,1041,1044,1047,2426,2429,2431,2432,5,4,3,11,275,278,283,286,293,307,330,359,396,428,460,486,515,541,557,566,574,578,579,575,567,563,558,554,549,546,544,1147,1148,1150,1153,1156,1160,1165,1180,1190,1202,1211,1218,1225,1233,1237,2422,2424,2427,2430,2,1,0,9,279,282,285,290,297,313,336,363,397,427,461,488,521,561,577,583,587,588,586,582,576,569,564,556,547,543,542,1154,1155,1157,1161,1164,1169,1175,1185,1195,1205,1215,1223,1232,1239,1243,2417,2418,2416,2415,2381,2380,2379,2232,2088,2084,2076,2067,2058,2049,2041,2036,2027,2019,2010,2007,629,608,604,602,600,598,595,590,585,580,573,568,540,539,538,1162,1163,1166,1168,1172,1178,1184,1193,1203,1212,1220,1230,1240,1246,1249,2409,2410,2411,2412,2386,2385,2383,2229,2091,2086,2078,2068,2059,2050,2042,2035,2026,2017,2008,2005,645,637,630,624,618,613,606,599,594,589,584,581,537,536,535,1167,1170,1173,1176,1181,1189,1196,1204,1213,1221,1231,1242,1250,1254,1255,2402,2403,2406,2407,2391,2390,2388,2225,2095,2089,2079,2069,2060,2051,2043,2034,2025,2015,2006,2002,672,664,651,640,632,625,619,611,603,596,593,591,532,531,530,1174,1177,1182,1186,1192,1200,1207,1216,1224,1234,1244,1252,1259,1264,1266,2400,2401,2405,2404,2397,2395,2393,2221,2099,2093,2081,2071,2061,2053,2044,2033,2024,2013,2003,1998,707,695,676,657,642,634,627,621,614,607,601,597,528,526,525,1183,1187,1194,1201,1206,1214,1219,1228,1238,1248,1256,1265,1272,1277,1279,2420,2419,2413,2408,2399,2396,2394,2216,2104,2096,2083,2072,2062,2054,2045,2032,2023,2009,1996,1992,755,738,703,673,653,639,633,628,622,616,610,605,524,520,519,1191,1198,1209,1217,1222,1229,1236,1245,1253,1262,1271,1280,1288,1294,1298,2423,2425,2421,2414,2398,2392,2389,2212,2116,2120,2119,2114,2106,2092,2065,2030,2004,1990,1986,1984,817,797,729,686,661,644,636,631,626,620,615,612,522,517,516,1199,1208,1227,1235,1241,1247,1251,1260,1268,1278,1289,1300,1306,1311,1313,2445,2438,2433,2428,2387,2384,2382,2205,2130,2129,2127,2121,2113,2101,2074,2022,1993,1980,1973,1970,896,909,973,1009,1030,1045,1050,1051,1055,1059,1063,1065,1138,1334,1333,1302,1287,1263,1257,1258,1261,1267,1276,1285,1296,1307,1315,1320,1322,1323,2448,2446,2443,2440,2378,2377,2376,2197,2147,2144,2140,2134,2126,2117,2107,1982,1971,1962,1955,1952,960,972,1001,1024,1039,1049,1053,1057,1060,1064,1068,1070,1137,1336,1335,1308,1299,1283,1274,1270,1273,1281,1291,1303,1312,1319,1325,1328,1330,1332,2451,2450,2449,2447,2375,2374,2373,2189,2171,2163,2155,2149,2143,2138,2133,1950,1947,1943,1939,1936,1013,1019,1033,1046,1052,1058,1062,1066,1069,1072,1075,1077,1135,1340,1339,1317,1309,1297,1286,1282,1284,1293,1304,1314,1321,1326,1331,1338,1341,1342,2455,2454,2453,2452,2372,2371,2370,2193,2186,2179,2174,2170,2164,2158,2154,1926,1924,1920,1914,1913,1054,1056,1061,1067,1071,1073,1076,1078,1079,1080,1081,1082,1134,1344,1343,1327,1316,1305,1295,1290,1292,1301,1310,1318,1324,1329,1337,1350,1354,1355,2459,2458,2457,2456,2369,2368,2367,2201,2198,2194,2191,2187,2183,2178,2177,1906,1902,1897,1890,1884,1098,1096,1094,1092,1090,1089,1088,1087,1086,1085,1084,1083,1132,1347,1346,1345,1357,1366,1375,1382,1389,1398,1408,1417,1416,1407,1394,1377,1372,1370,2463,2462,2461,2460,2366,2365,2364,2210,2208,2206,2204,2202,2199,2196,2195,1892,1885,1874,1858,1847,1141,1136,1127,1119,1111,1106,1103,1099,1097,1095,1093,1091,1131,1348,1349,1352,1361,1368,1376,1383,1391,1400,1410,1418,1419,1413,1401,1390,1384,1381,2467,2466,2465,2464,2363,2362,2361,2220,2219,2217,2215,2214,2213,2211,2209,1879,1868,1850,1824,1802,1197,1179,1158,1140,1128,1120,1114,1109,1105,1104,1102,1101,1130,1351,1353,1358,1364,1371,1378,1385,1393,1403,1415,1424,1425,1421,1412,1402,1396,1392,2471,2470,2469,2468,2360,2359,2358,2231,2230,2228,2227,2226,2224,2223,2222,1870,1856,1830,1786,1738,1269,1226,1188,1159,1139,1129,1122,1117,1112,1110,1108,1107,1126,1356,1359,1363,1367,1373,1379,1386,1395,1406,1420,1428,1430,1427,1422,1414,1405,1399,2475,2474,2473,2472,2357,2356,2355,2241,2240,2239,2237,2236,2235,2234,2233,1873,1859,1828,1747,1625,1388,1275,1210,1171,1146,1133,1125,1121,1118,1115,1113,1116,1123,1360,1362,1365,1369,1374,1380,1387,1397,1409,1426,1440,1438,1434,1429,1423,1411,1404,2479,2478,2477,2476,2354,2353,2352,2250,2248,2247,2246,2245,2244,2243,2242,1886,1881,1875,1893,1899,1900,1894,1889,1880,1866,1853,1842,1835,1827,1820,1813,1808,1807,1647,1639,1627,1614,1600,1586,1569,1549,1526,1497,1467,1453,1443,1436,1432,1433,1431,2483,2482,2481,2480,2351,2350,2349,2258,2257,2256,2253,2251,2252,2254,2255,1898,1896,1895,1901,1903,1905,1891,1887,1877,1863,1851,1841,1834,1825,1818,1811,1804,1800,1650,1643,1631,1617,1602,1587,1571,1552,1530,1505,1480,1464,1452,1444,1439,1437,1435,2487,2486,2485,2484,2343,2341,2339,2270,2268,2264,2260,2259,2262,2265,2266,1910,1908,1907,1909,1911,1912,1888,1883,1872,1860,1849,1839,1832,1822,1814,1806,1797,1792,1658,1651,1637,1623,1606,1590,1574,1556,1536,1514,1490,1473,1459,1450,1445,1442,1441,2491,2490,2489,2488,2334,2332,2329,2285,2280,2273,2269,2271,2274,2277,2279,1921,1919,1918,1917,1916,1915,1882,1878,1867,1855,1845,1837,1829,1819,1809,1798,1787,1775,1672,1662,1646,1629,1611,1594,1577,1560,1541,1521,1499,1482,1468,1457,1449,1447,1446,2495,2494,2493,2492,2326,2323,2316,2298,2287,2278,2276,2281,2286,2289,2290,1931,1929,1927,1925,1923,1922,1876,1871,1862,1852,1843,1836,1826,1816,1803,1790,1770,1745,1699,1674,1654,1634,1615,1599,1581,1564,1546,1528,1508,1489,1475,1463,1455,1451,1448,2499,2498,2497,2496,2322,2319,2312,2300,2288,2272,2275,2284,2291,2296,2297,1942,1941,1938,1934,1930,1928,1869,1864,1857,1848,1840,1833,1823,1812,1799,1784,1761,1736,1706,1682,1660,1638,1619,1601,1585,1568,1551,1533,1516,1496,1481,1470,1461,1456,1454,2348,2347,2346,2345,2185,2188,2192,2200,2218,2249,2267,2283,2294,2299,2303,1948,1949,1944,1940,1935,1933,1865,1861,1854,1846,1838,1831,1821,1810,1796,1780,1758,1734,1709,1686,1664,1641,1622,1604,1588,1572,1555,1539,1522,1504,1487,1476,1466,1460,1458,2344,2342,2340,2338,2181,2182,2184,2190,2203,2238,2261,2282,2295,2301,2305,1954,1968,1975,1972,1965,1961,1773,1768,1762,1755,1749,1741,1730,1722,1714,1704,1695,1687,1677,1667,1655,1640,1624,1607,1591,1575,1559,1543,1529,1512,1494,1483,1472,1465,1462,2337,2336,2335,2333,2175,2173,2172,2169,2161,2131,2111,2097,2077,2057,2038,2016,1991,1983,1976,1967,1960,1776,1771,1765,1757,1750,1742,1731,1723,1715,1705,1696,1688,1678,1668,1656,1642,1626,1610,1593,1578,1563,1548,1534,1519,1502,1488,1478,1471,1469,2331,2330,2328,2327,2168,2165,2159,2151,2141,2124,2108,2094,2075,2056,2040,2020,1999,1988,1978,1966,1958,1782,1777,1769,1760,1752,1743,1732,1724,1716,1707,1697,1689,1679,1669,1657,1644,1628,1612,1596,1580,1565,1553,1540,1525,1510,1495,1485,1477,1474,2325,2324,2321,2320,2162,2156,2150,2142,2132,2118,2105,2090,2073,2055,2039,2021,2001,1989,1977,1964,1956,1788,1783,1774,1764,1754,1744,1733,1725,1717,1708,1698,1690,1680,1670,1659,1645,1630,1613,1598,1582,1567,1557,1544,1532,1517,1503,1492,1484,1479,2318,2317,2315,2314,2160,2153,2146,2139,2128,2115,2103,2087,2070,2052,2037,2018,2000,1987,1974,1959,1951,1793,1789,1779,1767,1756,1746,1735,1726,1718,1710,1700,1691,1681,1671,1661,1648,1632,1616,1603,1589,1576,1562,1550,1538,1524,1513,1500,1491,1486,2313,2311,2309,2306,2167,2157,2145,2136,2125,2112,2102,2085,2066,2048,2031,2014,1997,1985,1969,1953,1945,1801,1794,1785,1772,1759,1748,1737,1727,1719,1711,1701,1692,1683,1673,1663,1649,1633,1618,1605,1592,1579,1566,1554,1542,1531,1520,1509,1498,1493,2310,2307,2302,2293,2180,2166,2148,2135,2123,2110,2100,2082,2064,2047,2029,2012,1995,1981,1963,1946,1932,1817,1805,1791,1778,1763,1751,1739,1728,1720,1712,1702,1693,1684,1675,1665,1652,1635,1620,1608,1595,1583,1570,1558,1545,1535,1523,1515,1506,1501,2308,2304,2292,2263,2207,2176,2152,2137,2122,2109,2098,2080,2063,2046,2028,2011,1994,1979,1957,1937,1904,1844,1815,1795,1781,1766,1753,1740,1729,1721,1713,1703,1694,1685,1676,1666,1653,1636,1621,1609,1597,1584,1573,1561,1547,1537,1527,1518,1511,1507},
{8734,8742,8763,8783,8801,8820,8836,8846,8860,8874,8885,8896,8912,8923,8938,8953,8969,8991,9013,9040,9078,9109,9135,9159,9177,9188,9198,9205,9210,9219,9226,9237,9244,9251,9256,9262,9268,9275,9280,9287,9294,9301,9308,9317,9325,9334,9343,9353,9363,9373,9383,9393,9403,9413,9423,9433,9443,9453,9463,9473,9483,9494,9506,9519,9531,9540,9543,9544,9548,9557,9571,9584,9597,9613,9626,9639,9652,9660,9663,9664,9667,9671,9676,9685,9697,9708,9715,9721,9871,9877,9888,9901,9916,9936,9955,9970,9982,9990,9996,9999,8736,8745,8764,8782,8800,8818,8834,8844,8859,8872,8884,8895,8909,8921,8936,8951,8968,8989,9010,9037,9072,9105,9132,9157,9176,9187,9197,9204,9209,9218,9225,9234,9241,9247,9254,9258,9264,9271,9277,9284,9291,9299,9307,9315,9323,9332,9342,9352,9362,9372,9382,9392,9402,9412,9422,9432,9442,9452,9462,9472,9482,9492,9504,9516,9529,9538,9542,9545,9550,9559,9572,9585,9598,9612,9624,9637,9650,9658,9662,9665,9668,9672,9679,9689,9700,9710,9718,9724,9866,9873,9884,9897,9913,9933,9952,9968,9980,9989,9995,9998,8739,8749,8765,8781,8798,8814,8830,8843,8856,8868,8881,8891,8905,8917,8931,8947,8964,8984,9004,9031,9061,9097,9128,9154,9171,9185,9196,9202,9208,9217,9224,9230,9238,9240,9245,9253,9260,9266,9273,9281,9288,9296,9305,9313,9321,9331,9341,9351,9361,9371,9381,9391,9401,9411,9421,9431,9441,9451,9461,9471,9481,9491,9502,9514,9526,9536,9541,9546,9552,9561,9574,9586,9599,9611,9622,9634,9648,9656,9661,9666,9669,9675,9681,9692,9704,9714,9723,9727,9858,9865,9876,9891,9907,9927,9947,9964,9977,9986,9993,9997,8743,8752,8767,8780,8795,8808,8824,8838,8849,8862,8875,8886,8898,8913,8927,8943,8959,8976,8997,9019,9049,9091,9124,9152,9169,9183,9194,9201,9207,9216,9222,9227,9232,9229,9235,9242,9252,9259,9267,9276,9285,9293,9302,9311,9320,9330,9340,9350,9360,9370,9380,9390,9400,9410,9420,9430,9440,9450,9460,9470,9480,9490,9500,9512,9525,9535,9539,9547,9553,9564,9577,9590,9601,9610,9620,9632,9646,9655,9659,9670,9673,9678,9686,9699,9711,9722,9730,9733,9847,9855,9869,9886,9902,9921,9943,9961,9975,9985,9991,9994,8750,8758,8769,8779,8792,8804,8819,8832,8841,8852,8863,8877,8890,8904,8919,8935,8950,8967,8987,9005,9023,9034,9054,9079,9102,9119,9136,9150,9162,9174,9182,9190,9199,9211,9220,9228,9239,9248,9257,9269,9279,9289,9298,9309,9319,9329,9339,9349,9359,9369,9379,9389,9399,9409,9419,9429,9439,9449,9459,9469,9479,9489,9499,9511,9523,9533,9537,9549,9555,9566,9578,9592,9603,9609,9619,9631,9644,9653,9657,9674,9677,9684,9694,9705,9717,9728,9737,9746,9834,9844,9860,9878,9896,9917,9939,9957,9971,9981,9988,9992,8753,8760,8770,8778,8791,8803,8816,8823,8828,8839,8851,8865,8880,8893,8910,8925,8940,8958,8975,8993,9009,9026,9048,9073,9095,9118,9133,9146,9160,9170,9179,9186,9191,9200,9206,9213,9221,9233,9246,9261,9272,9283,9295,9306,9318,9328,9338,9348,9358,9368,9378,9388,9398,9408,9418,9428,9438,9448,9458,9468,9478,9488,9498,9509,9520,9530,9534,9551,9556,9568,9579,9593,9602,9608,9618,9629,9640,9649,9654,9680,9682,9690,9702,9713,9726,9735,9752,9773,9812,9833,9852,9870,9890,9910,9931,9950,9965,9976,9984,9987,8757,8762,8771,8777,8790,8802,8812,8817,8810,8822,8837,8850,8866,8882,8897,8915,8930,8948,8965,8982,8999,9018,9038,9062,9089,9112,9129,9142,9156,9164,9172,9178,9181,9184,9189,9195,9203,9215,9231,9249,9263,9278,9292,9304,9316,9327,9337,9347,9357,9367,9377,9387,9397,9407,9417,9427,9437,9447,9457,9467,9477,9487,9497,9507,9517,9527,9532,9554,9560,9570,9580,9591,9600,9607,9617,9627,9636,9645,9651,9683,9687,9696,9707,9719,9731,9741,9760,9782,9806,9828,9845,9862,9883,9903,9924,9945,9959,9972,9979,9983,8660,8679,8695,8707,8716,8724,8730,8744,8776,8797,8815,8831,8847,8864,8883,8902,8918,8937,8956,8971,8990,9008,9030,9053,9081,9103,9123,9137,9149,9158,9163,9165,9166,9167,9168,9173,9180,9192,9212,9236,9255,9274,9290,9303,9314,9326,9336,9346,9356,9366,9376,9386,9396,9406,9416,9426,9436,9446,9456,9466,9476,9486,9496,9505,9513,9522,9528,9558,9563,9573,9581,9589,9596,9606,9616,9625,9633,9642,9647,9688,9693,9703,9712,9725,9734,9749,9768,9786,9804,9823,9841,9857,9879,9898,9918,9938,9953,9966,9974,9978,8644,8687,8696,8705,8713,8720,8727,8737,8756,8774,8793,8809,8826,8845,8867,8888,8906,8926,8944,8961,8979,9000,9021,9043,9069,9092,9116,9130,9141,9148,9153,9155,9151,9147,9144,9143,9145,9161,9193,9223,9250,9270,9286,9300,9312,9324,9335,9345,9355,9365,9375,9385,9395,9405,9415,9425,9435,9445,9455,9465,9475,9485,9495,9503,9510,9518,9524,9562,9567,9575,9582,9588,9595,9605,9615,9623,9630,9638,9643,9691,9698,9706,9716,9729,9739,9758,9775,9792,9808,9822,9838,9854,9874,9892,9911,9929,9946,9960,9969,9973,8623,8686,8690,8700,8708,8715,8723,8729,8740,8755,8772,8789,8806,8825,8848,8870,8892,8914,8932,8952,8970,8992,9012,9035,9057,9085,9107,9121,9131,9138,9140,9139,9134,9125,9117,9106,9098,9108,9175,9214,9243,9265,9282,9297,9310,9322,9333,9344,9354,9364,9374,9384,9394,9404,9414,9424,9434,9444,9454,9464,9474,9484,9493,9501,9508,9515,9521,9565,9569,9576,9583,9587,9594,9604,9614,9621,9628,9635,9641,9695,9701,9709,9720,9732,9743,9766,9783,9797,9811,9825,9837,9851,9868,9887,9905,9922,9940,9954,9963,9967,8601,8678,8681,8688,8698,8706,8714,8722,8728,8738,8751,8768,8787,8805,8829,8854,8879,8900,8920,8942,8962,8983,9003,9024,9047,9074,9093,9111,9120,9126,9127,9122,9114,9100,9082,9056,9029,8985,8876,8788,8712,8634,8560,8491,8418,8343,8271,8192,8119,8045,7964,7886,7802,7716,7619,7521,7429,7339,7253,7174,7094,7016,6942,6882,6839,6813,6800,6626,6633,6644,6660,6676,6693,6714,6732,6747,6764,6779,6787,9736,9742,9753,9763,9771,9777,9781,9790,9800,9813,9827,9836,9848,9863,9882,9899,9914,9932,9948,9958,9962,8581,8666,8670,8676,8684,8692,8702,8711,8717,8725,8733,8746,8766,8786,8807,8835,8861,8887,8911,8934,8955,8973,8995,9014,9036,9060,9083,9099,9110,9115,9113,9104,9090,9070,9046,9016,8978,8928,8855,8775,8704,8631,8558,8488,8416,8342,8269,8191,8118,8044,7963,7884,7799,7712,7614,7519,7425,7337,7250,7169,7087,7006,6931,6871,6826,6799,6788,6617,6624,6635,6651,6669,6687,6710,6729,6744,6760,6777,6786,9738,9745,9755,9764,9772,9780,9787,9795,9803,9814,9826,9835,9846,9859,9875,9893,9909,9925,9941,9951,9956,8561,8656,8659,8664,8669,8677,8685,8693,8701,8710,8718,8726,8741,8759,8784,8811,8842,8871,8899,8924,8946,8966,8988,9006,9028,9051,9071,9087,9096,9101,9094,9084,9064,9042,9017,8986,8945,8894,8833,8761,8694,8625,8554,8485,8414,8340,8266,8190,8116,8040,7962,7882,7796,7706,7609,7513,7421,7330,7243,7159,7072,6985,6908,6844,6797,6769,6755,6601,6606,6618,6636,6657,6679,6700,6722,6740,6757,6773,6781,9740,9747,9757,9765,9774,9784,9791,9798,9805,9815,9824,9832,9843,9856,9872,9889,9904,9919,9934,9944,9949,8544,8648,8650,8652,8655,8661,8667,8672,8680,8689,8697,8709,8719,8732,8754,8785,8821,8857,8889,8916,8939,8960,8981,9001,9020,9039,9058,9076,9086,9088,9080,9065,9045,9022,8996,8963,8922,8873,8813,8747,8683,8618,8551,8480,8409,8335,8263,8187,8113,8035,7956,7877,7791,7700,7604,7510,7420,7326,7238,7149,7057,6965,6878,6802,6749,6718,6706,6577,6581,6593,6613,6638,6663,6686,6713,6735,6753,6768,6776,9744,9750,9759,9767,9776,9785,9793,9799,9807,9816,9821,9831,9842,9853,9867,9885,9900,9912,9926,9937,9942,8519,8640,8642,8643,8646,8649,8653,8657,8663,8668,8673,8682,8691,8703,8721,8748,8796,8840,8878,8908,8933,8957,8977,8998,9015,9033,9050,9063,9075,9077,9067,9052,9032,9007,8980,8949,8907,8858,8799,8735,8674,8613,8548,8478,8405,8331,8259,8183,8110,8031,7950,7871,7784,7693,7599,7505,7416,7322,7231,7141,7047,6943,6837,6736,6675,6645,6634,6547,6554,6568,6589,6614,6643,6671,6703,6730,6748,6763,6772,9748,9754,9761,9769,9778,9788,9794,9801,9809,9817,9820,9830,9840,9850,9864,9881,9895,9908,9920,9928,9935,8493,8624,8626,8628,8632,8636,8641,8645,8647,8651,8654,8658,8662,8665,8675,8699,8773,8827,8869,8903,8929,8954,8974,8994,9011,9027,9041,9055,9066,9068,9059,9044,9025,9002,8972,8941,8901,8853,8794,8731,8671,8610,8547,8475,8404,8329,8258,8182,8108,8030,7949,7867,7781,7690,7596,7503,7412,7318,7226,7134,7036,6922,6794,6621,6567,6548,6544,6510,6521,6538,6560,6585,6615,6648,6691,6724,6743,6758,6766,9751,9756,9762,9770,9779,9789,9796,9802,9810,9818,9819,9829,9839,9849,9861,9880,9894,9906,9915,9923,9930,8460,8606,8608,8612,8616,8622,8627,8630,8633,8637,8639,8638,8635,8629,8619,8592,8505,8436,8375,8314,8254,8195,8139,8086,8028,7968,7901,7827,7745,7657,7558,7454,7336,7204,7064,6934,6828,6739,6662,6587,6519,6464,6406,6353,6303,6252,6201,6147,6102,6055,6011,5969,5940,5920,5912,5910,5916,5931,5956,5996,6047,6119,6225,6381,6425,6440,6449,6478,6485,6502,6527,6555,6583,6612,6631,6655,6677,6692,6704,8072,8075,8080,8087,8096,8109,8123,8137,8155,8169,8180,8184,8193,8202,8209,8211,8216,8218,8220,8224,8227,8430,8588,8589,8596,8600,8607,8611,8614,8617,8621,8620,8615,8609,8597,8577,8545,8487,8428,8369,8312,8253,8196,8140,8088,8032,7973,7904,7829,7748,7663,7566,7464,7350,7212,7048,6913,6811,6725,6650,6578,6512,6460,6403,6351,6301,6248,6195,6143,6095,6046,6001,5962,5934,5915,5905,5903,5909,5922,5945,5980,6027,6089,6167,6257,6310,6340,6354,6428,6441,6465,6490,6523,6558,6591,6623,6653,6678,6695,6708,8064,8067,8074,8083,8094,8106,8121,8134,8152,8167,8179,8185,8194,8204,8210,8213,8217,8221,8225,8229,8231,8394,8562,8566,8574,8585,8593,8599,8602,8604,8605,8603,8598,8587,8570,8549,8516,8468,8417,8361,8307,8252,8198,8145,8093,8036,7977,7908,7833,7755,7670,7581,7490,7387,7249,7004,6872,6780,6701,6629,6564,6504,6454,6398,6346,6296,6243,6188,6134,6081,6031,5985,5946,5919,5901,5890,5888,5894,5906,5926,5954,5993,6043,6103,6159,6211,6246,6274,6362,6385,6418,6455,6492,6533,6572,6611,6649,6680,6702,6715,8047,8052,8062,8073,8085,8099,8117,8131,8149,8164,8178,8186,8197,8208,8215,8219,8223,8228,8232,8235,8236,8360,8537,8546,8556,8567,8578,8586,8591,8595,8594,8590,8582,8568,8552,8529,8497,8453,8407,8355,8303,8250,8199,8150,8098,8043,7983,7914,7840,7763,7682,7601,7527,7456,7394,6842,6790,6726,6664,6602,6543,6489,6443,6392,6344,6293,6240,6184,6126,6068,6012,5960,5921,5895,5877,5866,5863,5870,5881,5897,5918,5949,5987,6032,6077,6120,6161,6210,6271,6316,6363,6412,6461,6507,6556,6604,6647,6682,6712,6727,8016,8024,8037,8055,8071,8090,8112,8128,8146,8162,8177,8188,8203,8214,8222,8230,8233,8237,8240,8242,8244,8327,8494,8518,8541,8555,8564,8572,8580,8584,8583,8579,8569,8557,8543,8517,8483,8443,8399,8350,8300,8248,8200,8153,8101,8049,7990,7921,7847,7772,7695,7622,7559,7511,7483,6737,6711,6668,6620,6569,6520,6477,6432,6386,6339,6290,6241,6186,6127,6061,5982,5925,5886,5859,5840,5829,5826,5831,5841,5856,5876,5900,5927,5964,6003,6039,6079,6125,6181,6239,6302,6364,6424,6483,6541,6598,6652,6696,6731,6750,7981,7991,8006,8027,8050,8076,8105,8126,8144,8161,8175,8189,8212,8226,8234,8241,8245,8247,8251,8255,8257,8299,8423,8492,8528,8550,8559,8565,8573,8576,8575,8571,8563,8553,8538,8509,8477,8439,8396,8348,8298,8246,8201,8154,8104,8053,7995,7927,7853,7779,7704,7634,7579,7546,7548,6658,6641,6610,6573,6534,6494,6457,6416,6373,6331,6288,6245,6196,6140,6066,5933,5871,5832,5809,5790,5780,5777,5781,5791,5806,5820,5842,5865,5893,5924,5958,5997,6040,6097,6157,6237,6315,6389,6462,6529,6594,6661,6716,6759,6789,7925,7941,7966,7997,8022,8054,8102,8125,8141,8159,8172,8181,8238,8243,8249,8256,8260,8262,8265,8267,8270,8272,8280,8207,8163,8133,8115,8097,8082,8070,8059,8039,8023,8011,8004,7996,7976,7953,7937,7923,7906,7892,7874,7857,7841,7825,7810,7789,7770,7750,7732,7710,7679,7649,7610,6590,6579,6557,6530,6498,6468,6434,6395,6360,6325,6287,6255,6215,6170,6135,5812,5787,5762,5745,5730,5722,5720,5723,5734,5748,5758,5775,5796,5818,5844,5873,5904,5943,5998,6069,6165,6267,6355,6439,6515,6592,6670,6742,6804,6845,7846,7879,7919,7955,7986,8005,8122,8130,8143,8157,8168,8174,8261,8264,8268,8273,8274,8275,8276,8277,8278,8239,8205,8176,8148,8124,8107,8091,8078,8065,8051,8034,8019,8010,8001,7989,7969,7948,7933,7918,7902,7887,7869,7852,7836,7820,7805,7785,7765,7747,7730,7707,7680,7658,7637,6536,6526,6509,6488,6466,6438,6407,6376,6345,6317,6286,6260,6228,6197,6174,5710,5698,5684,5667,5659,5655,5654,5658,5666,5679,5690,5703,5719,5738,5756,5776,5801,5834,5884,5961,6094,6220,6327,6423,6508,6595,6684,6778,6868,6949,7731,7803,7870,7920,7952,7972,8129,8136,8147,8158,8166,8171,8279,8281,8282,8285,8288,8287,8286,8284,8283,8206,8156,8142,8127,8111,8095,8081,8069,8058,8041,8025,8012,8003,7994,7979,7958,7940,7926,7909,7893,7876,7859,7844,7828,7812,7795,7775,7757,7738,7721,7698,7676,7660,7646,6487,6482,6472,6456,6436,6410,6383,6357,6330,6305,6282,6259,6232,6213,6198,5612,5607,5597,5587,5580,5578,5579,5586,5594,5606,5615,5626,5637,5650,5661,5670,5686,5702,5733,5800,6024,6183,6309,6413,6505,6599,6697,6805,6938,7142,7535,7727,7832,7896,7934,7951,8132,8138,8151,8160,8165,8170,8292,8293,8294,8296,8297,8295,8291,8290,8289,8173,8120,8114,8103,8092,8079,8066,8057,8042,8026,8013,8002,7992,7978,7960,7942,7929,7911,7895,7880,7862,7845,7830,7814,7797,7780,7762,7743,7726,7708,7687,7668,7652,7642,6450,6445,6435,6420,6402,6380,6358,6336,6313,6291,6273,6249,6229,6214,6204,5515,5511,5506,5500,5497,5498,5503,5510,5518,5526,5533,5543,5551,5559,5561,5563,5562,5557,5539,5479,5264,5120,5015,4929,4864,4798,4749,4718,4700,4680,4661,4637,4618,4607,4604,4603,8531,8532,8535,8539,8540,8542,8311,8310,8309,8308,8306,8305,8304,8302,8301,8135,8089,8084,8077,8068,8060,8046,8033,8020,8008,7998,7985,7970,7954,7938,7924,7907,7891,7875,7858,7842,7824,7811,7794,7776,7760,7742,7723,7705,7686,7669,7651,7636,7629,6408,6404,6394,6382,6369,6352,6333,6314,6295,6276,6256,6234,6217,6202,6191,5410,5409,5407,5406,5408,5414,5420,5426,5432,5440,5444,5451,5454,5457,5453,5446,5433,5411,5376,5308,5193,5082,4992,4917,4854,4789,4743,4713,4695,4675,4653,4629,4611,4602,4593,4590,8526,8527,8530,8533,8534,8536,8323,8321,8320,8319,8318,8317,8316,8315,8313,8100,8061,8056,8048,8038,8029,8018,8009,7999,7988,7975,7961,7944,7931,7915,7899,7883,7865,7851,7834,7818,7800,7783,7768,7751,7735,7718,7696,7677,7662,7644,7628,7618,7611,6372,6368,6359,6348,6338,6323,6306,6289,6272,6250,6230,6212,6193,6177,6171,5315,5316,5319,5321,5325,5331,5339,5343,5348,5351,5354,5358,5357,5353,5347,5336,5314,5285,5250,5192,5112,5027,4951,4889,4829,4772,4729,4703,4684,4664,4638,4613,4598,4587,4576,4568,8521,8520,8522,8523,8524,8525,8338,8336,8333,8330,8328,8326,8325,8324,8322,8063,8021,8017,8014,8007,8000,7993,7982,7971,7959,7945,7932,7917,7903,7888,7873,7855,7839,7822,7807,7788,7771,7753,7737,7722,7702,7683,7665,7647,7631,7616,7602,7593,7589,6337,6334,6326,6318,6307,6294,6278,6264,6242,6221,6203,6182,6166,6155,6150,5226,5228,5232,5238,5242,5245,5255,5258,5260,5261,5262,5263,5259,5253,5243,5230,5210,5183,5144,5095,5032,4966,4908,4853,4793,4746,4712,4689,4669,4644,4616,4595,4578,4566,4555,4548,8515,8514,8513,8512,8511,8510,8353,8352,8349,8344,8341,8339,8337,8334,8332,8015,7987,7984,7980,7974,7965,7957,7946,7936,7928,7913,7897,7885,7868,7854,7838,7821,7806,7787,7773,7756,7736,7720,7701,7684,7667,7648,7632,7615,7600,7586,7578,7572,7569,6304,6300,6292,6284,6275,6263,6244,6227,6208,6185,6168,6152,6142,6133,6130,5130,5132,5136,5143,5148,5151,5177,5176,5175,5171,5169,5168,5165,5155,5142,5126,5107,5080,5048,5006,4956,4907,4858,4803,4754,4719,4691,4667,4642,4614,4591,4569,4554,4543,4536,4530,8508,8507,8506,8504,8501,8499,8371,8368,8363,8359,8354,8351,8347,8346,8345,7967,7947,7943,7939,7935,7930,7922,7912,7900,7890,7878,7863,7848,7831,7816,7798,7782,7766,7749,7734,7719,7697,7678,7664,7645,7627,7612,7597,7584,7571,7562,7556,7551,7549,6270,6266,6258,6247,6235,6222,6205,6187,6169,6151,6138,6124,6116,6111,6109,5040,5043,5047,5052,5057,5060,5090,5088,5085,5079,5076,5071,5065,5058,5045,5029,5012,4986,4957,4924,4886,4846,4797,4753,4717,4690,4662,4636,4610,4588,4564,4545,4531,4522,4515,4511,8503,8502,8500,8496,8489,8481,8395,8387,8380,8374,8366,8362,8358,8357,8356,7916,7910,7905,7898,7894,7889,7881,7872,7861,7849,7837,7823,7809,7790,7774,7758,7740,7724,7709,7689,7672,7653,7633,7620,7603,7588,7575,7565,7555,7544,7537,7531,7525,7522,6226,6224,6218,6207,6194,6179,6164,6149,6136,6121,6110,6098,6090,6084,6078,4946,4949,4954,4959,4963,4964,5002,4999,4995,4989,4984,4977,4969,4961,4950,4937,4920,4898,4875,4848,4811,4775,4737,4707,4679,4651,4623,4600,4577,4556,4537,4520,4510,4500,4495,4492,8498,8495,8490,8482,8473,8457,8425,8408,8397,8386,8378,8372,8367,8365,8364,7866,7864,7860,7856,7850,7843,7835,7826,7815,7804,7792,7777,7761,7744,7729,7714,7691,7674,7659,7641,7625,7606,7590,7576,7564,7553,7543,7533,7524,7514,7508,7501,7497,7495,6180,6178,6173,6163,6153,6144,6131,6117,6106,6091,6075,6063,6058,6054,6049,4860,4862,4867,4871,4874,4876,4909,4905,4902,4897,4892,4887,4882,4873,4863,4850,4833,4810,4784,4759,4733,4708,4682,4657,4630,4605,4580,4558,4540,4523,4508,4496,4487,4480,4473,4469,8486,8484,8479,8472,8462,8450,8434,8422,8412,8401,8390,8382,8376,8373,8370,7819,7817,7813,7808,7801,7793,7786,7778,7767,7754,7741,7728,7713,7692,7675,7661,7640,7624,7608,7592,7577,7563,7550,7538,7526,7516,7507,7499,7493,7485,7481,7477,7472,7471,6146,6145,6141,6132,6122,6114,6101,6086,6070,6057,6042,6030,6022,6017,6014,4760,4762,4768,4773,4776,4777,4816,4812,4806,4800,4795,4788,4782,4778,4769,4756,4742,4723,4706,4687,4668,4645,4621,4599,4574,4552,4534,4516,4502,4490,4478,4468,4463,4457,4452,4450,8476,8474,8470,8463,8455,8447,8438,8429,8421,8413,8403,8392,8383,8379,8377,7769,7764,7759,7752,7746,7739,7733,7725,7715,7699,7685,7671,7656,7638,7621,7605,7587,7573,7560,7547,7534,7520,7506,7496,7487,7479,7473,7469,7465,7462,7459,7455,7451,7449,6118,6115,6113,6107,6096,6082,6067,6053,6036,6021,6007,5994,5983,5975,5971,4671,4673,4678,4681,4683,4685,4720,4716,4711,4709,4705,4701,4697,4693,4686,4677,4666,4649,4627,4609,4594,4575,4557,4538,4519,4503,4489,4475,4464,4455,4446,4440,4437,4434,4430,4428,8471,8469,8464,8458,8452,8446,8440,8433,8427,8420,8411,8400,8391,8384,8381,7717,7711,7703,7694,7688,7681,7673,7666,7654,7639,7626,7613,7598,7583,7568,7554,7541,7528,7512,7500,7488,7476,7466,7458,7452,7447,7443,7439,7437,7436,7434,7432,7427,7424,6093,6088,6085,6076,6064,6052,6034,6020,6004,5984,5966,5953,5942,5935,5930,4570,4573,4579,4583,4586,4589,4632,4628,4624,4620,4615,4612,4608,4606,4601,4592,4581,4565,4547,4532,4518,4505,4493,4479,4465,4454,4443,4432,4425,4422,4418,4417,4416,4415,4413,4412,8467,8465,8459,8454,8449,8445,8441,8435,8431,8424,8415,8406,8398,8389,8385,7655,7650,7643,7635,7630,7623,7617,7607,7595,7582,7570,7557,7545,7532,7518,7504,7494,7482,7470,7461,7446,7433,7423,7418,7413,7411,7407,7405,7406,7409,7410,7408,7403,7399,6065,6062,6059,6051,6037,6023,6008,5988,5967,5948,5928,5913,5902,5891,5887,4472,4476,4481,4483,4486,4488,4544,4542,4539,4535,4529,4525,4521,4517,4512,4506,4498,4485,4470,4460,4448,4436,4426,4419,4411,4404,4399,4395,4393,4391,4392,4401,4407,4408,4405,4402,8466,8461,8456,8451,8448,8444,8442,8437,8432,8426,8419,8410,8402,8393,8388,7594,7591,7585,7580,7574,7567,7561,7552,7540,7529,7515,7502,7491,7478,7467,7457,7448,7441,7431,7419,7400,7388,7378,7373,7370,7371,7372,7374,7377,7381,7384,7385,7383,7382,6045,6041,6035,6028,6016,5999,5979,5959,5937,5914,5892,5874,5857,5845,5839,4375,4378,4381,4384,4386,4389,4461,4458,4456,4453,4449,4444,4438,4433,4427,4423,4414,4406,4396,4388,4380,4373,4367,4365,4364,4363,4361,4360,4359,4358,4355,4344,4339,4340,4342,4345,5000,5003,5011,5021,5037,5055,5074,5098,5122,5149,5178,5202,5220,5234,5241,7542,7539,7536,7530,7523,7517,7509,7498,7486,7475,7463,7453,7442,7428,7417,7404,7397,7398,7392,7380,7358,7342,7331,7328,7329,7334,7340,7346,7351,7356,7361,7362,7363,7364,6029,6025,6019,6009,5992,5973,5952,5932,5908,5882,5852,5824,5802,5786,5778,4281,4282,4284,4287,4292,4295,4379,4377,4374,4371,4369,4366,4362,4356,4350,4346,4341,4334,4328,4320,4312,4307,4305,4306,4311,4316,4318,4319,4321,4323,4325,4324,4326,4329,4332,4333,4991,4996,5005,5017,5033,5053,5072,5097,5119,5146,5174,5199,5218,5231,5239,7492,7489,7484,7480,7474,7468,7460,7450,7438,7426,7415,7401,7389,7375,7365,7353,7348,7369,7368,7352,7304,7287,7283,7286,7292,7299,7307,7314,7321,7327,7333,7338,7343,7345,6018,6013,6005,5989,5970,5951,5929,5907,5879,5843,5805,5765,5736,5716,5707,4183,4184,4188,4190,4195,4201,4300,4299,4296,4293,4289,4285,4280,4274,4268,4262,4257,4250,4245,4241,4237,4238,4242,4247,4256,4261,4264,4267,4272,4276,4283,4290,4297,4303,4310,4314,4974,4981,4994,5008,5025,5046,5068,5093,5114,5137,5167,5194,5214,5227,5235,7445,7444,7440,7435,7430,7422,7414,7402,7391,7379,7366,7355,7341,7325,7311,7294,7269,7218,7195,7193,7222,7228,7235,7247,7260,7271,7279,7288,7296,7303,7310,7316,7320,7323,6010,6002,5990,5974,5955,5936,5911,5885,5849,5803,5750,5694,5653,5627,5618,4092,4094,4096,4100,4108,4113,4222,4218,4214,4210,4206,4204,4199,4191,4185,4178,4174,4171,4172,4173,4175,4180,4186,4192,4202,4207,4211,4216,4224,4229,4240,4253,4265,4277,4288,4294,4955,4962,4975,4993,5014,5036,5062,5083,5106,5131,5162,5188,5208,5221,5229,7396,7395,7393,7390,7386,7376,7367,7359,7347,7332,7319,7306,7293,7278,7264,7245,7223,7194,7173,7161,7164,7170,7182,7209,7233,7251,7262,7270,7276,7284,7291,7298,7305,7308,6000,5991,5977,5963,5944,5923,5899,5867,5821,5761,5687,5601,5552,5523,5513,4011,4014,4016,4021,4028,4032,4155,4151,4146,4139,4134,4128,4122,4115,4110,4104,4103,4105,4111,4116,4123,4132,4137,4147,4157,4164,4168,4177,4189,4198,4208,4220,4232,4251,4269,4279,4935,4942,4953,4972,4998,5022,5049,5073,5099,5125,5154,5181,5201,5215,5223,7360,7357,7354,7349,7344,7335,7324,7313,7302,7290,7277,7265,7254,7240,7224,7206,7183,7158,7136,7119,7108,7101,7107,7180,7217,7241,7256,7263,7268,7273,7281,7289,7297,7300,5995,5986,5972,5957,5939,5917,5889,5855,5807,5735,5631,5469,5417,5397,5389,3924,3927,3929,3936,3942,3947,4087,4086,4080,4072,4062,4055,4048,4040,4037,4036,4038,4044,4050,4057,4070,4081,4090,4099,4114,4126,4135,4149,4161,4169,4181,4196,4213,4233,4259,4271,4912,4919,4932,4952,4979,5007,5035,5063,5091,5118,5145,5173,5195,5209,5216,7317,7315,7312,7309,7301,7295,7285,7274,7266,7258,7244,7232,7219,7205,7187,7167,7144,7118,7096,7074,7050,7021,6969,6853,6767,6694,6630,6574,6525,6486,6459,6431,6411,6397,4824,4826,4827,4831,4842,4857,4872,4894,4926,4980,5069,5222,5256,5266,5269,3842,3846,3852,3861,3867,3872,4030,4025,4017,4006,3992,3981,3969,3959,3956,3958,3965,3976,3987,4001,4018,4034,4049,4063,4077,4088,4101,4118,4133,4148,4163,4179,4203,4228,4260,4278,4879,4890,4910,4931,4960,4990,5020,5051,5078,5109,5134,5164,5186,5203,5211,7282,7280,7275,7272,7267,7261,7255,7246,7239,7227,7216,7203,7191,7172,7151,7129,7105,7081,7054,7029,6994,6955,6900,6823,6751,6683,6622,6565,6516,6479,6451,6422,6399,6388,4818,4817,4815,4814,4821,4837,4856,4878,4904,4945,5010,5086,5123,5140,5150,3758,3764,3773,3783,3792,3798,3967,3963,3953,3938,3920,3904,3892,3881,3880,3884,3895,3906,3922,3940,3960,3984,4007,4029,4046,4058,4075,4091,4106,4125,4144,4167,4197,4230,4273,4301,4823,4849,4881,4911,4940,4973,5009,5041,5070,5103,5128,5156,5180,5198,5206,7259,7257,7252,7248,7242,7237,7229,7221,7211,7201,7190,7176,7157,7137,7114,7093,7068,7041,7009,6978,6941,6901,6850,6791,6728,6666,6605,6549,6501,6463,6430,6400,6379,6370,4808,4802,4794,4786,4787,4799,4820,4844,4868,4899,4939,4983,5013,5028,5038,3668,3679,3698,3718,3730,3736,3915,3909,3899,3878,3857,3831,3813,3801,3800,3806,3820,3841,3865,3887,3911,3935,3961,3989,4012,4033,4051,4067,4084,4102,4127,4158,4194,4243,4302,4349,4738,4783,4839,4884,4922,4958,4997,5031,5064,5096,5121,5147,5172,5190,5200,7236,7234,7230,7225,7220,7214,7208,7199,7188,7177,7160,7146,7126,7104,7084,7059,7033,7002,6967,6932,6895,6855,6808,6754,6698,6639,6580,6528,6480,6437,6401,6371,6350,6341,4801,4791,4779,4764,4757,4761,4774,4790,4813,4840,4869,4896,4915,4927,4934,3572,3589,3622,3651,3671,3682,3875,3870,3853,3826,3794,3761,3727,3713,3716,3728,3748,3776,3805,3834,3866,3897,3921,3951,3978,4004,4027,4047,4064,4083,4107,4141,4187,4255,4338,4439,4619,4721,4796,4861,4906,4944,4985,5023,5061,5092,5117,5139,5166,5185,5196,7215,7213,7210,7207,7202,7197,7189,7178,7163,7150,7133,7115,7097,7075,7052,7027,6996,6962,6927,6892,6856,6817,6774,6721,6667,6608,6550,6499,6453,6405,6365,6332,6308,6297,4809,4792,4770,4748,4732,4727,4731,4739,4751,4767,4785,4807,4822,4834,4841,3463,3490,3549,3598,3630,3647,3844,3835,3817,3787,3747,3688,3623,3602,3614,3640,3672,3714,3752,3786,3821,3860,3890,3917,3945,3973,3998,4022,4043,4061,4085,4117,4166,4249,4351,4459,4585,4688,4766,4843,4895,4936,4978,5019,5056,5087,5113,5135,5163,5182,5191,7200,7198,7196,7192,7185,7179,7166,7153,7140,7124,7109,7091,7069,7046,7020,6987,6956,6923,6891,6858,6822,6785,6738,6685,6632,6575,6518,6467,6417,6366,6321,6283,6253,6238,4828,4805,4771,4735,4714,4702,4698,4696,4699,4704,4710,4722,4728,4734,4740,3335,3362,3491,3565,3606,3626,3824,3816,3799,3767,3717,3628,3479,3465,3495,3542,3595,3649,3701,3745,3784,3823,3863,3894,3918,3946,3972,3997,4020,4039,4056,4078,4120,4235,4352,4462,4572,4672,4750,4830,4888,4930,4971,5016,5054,5084,5111,5133,5159,5179,5187,7186,7184,7181,7175,7165,7156,7145,7131,7117,7102,7086,7065,7040,7012,6982,6951,6919,6889,6860,6827,6793,6752,6707,6654,6597,6540,6484,6429,6374,6319,6269,6219,6176,6156,4859,4832,4781,4724,4692,4670,4656,4646,4641,4640,4643,4647,4650,4652,4655,3175,3142,3013,2939,2898,2881,2743,2755,2780,2823,2897,3016,3211,3298,3366,3442,3519,3590,3653,3711,3757,3796,3836,3874,3901,3925,3950,3975,3996,4013,4023,4024,4005,3914,3847,3790,3743,3699,3657,3618,3578,3536,3502,3473,3450,3429,3415,3402,3388,3378,3371,7171,7168,7162,7155,7147,7135,7123,7111,7098,7082,7063,7038,7010,6981,6950,6918,6890,6863,6832,6798,6762,6720,6673,6619,6563,6506,6452,6390,6328,6265,6200,6137,6087,6060,4900,4870,4804,4715,4658,4617,4596,4582,4571,4567,4563,4562,4561,4560,4559,3051,3021,2961,2911,2880,2865,2728,2740,2763,2797,2857,2944,3055,3141,3230,3351,3460,3547,3620,3681,3735,3779,3819,3858,3885,3908,3932,3955,3977,3990,3994,3983,3954,3900,3843,3788,3742,3697,3654,3616,3576,3535,3501,3472,3449,3430,3418,3403,3392,3380,3372,7154,7152,7148,7138,7128,7116,7106,7095,7079,7062,7039,7011,6983,6954,6924,6894,6867,6838,6807,6775,6734,6689,6640,6586,6532,6476,6415,6349,6281,6206,6123,6044,5978,5938,4968,4928,4852,4676,4597,4549,4524,4509,4499,4491,4484,4482,4477,4474,4471,2949,2930,2901,2871,2848,2838,2699,2709,2729,2758,2798,2853,2919,2981,3066,3285,3424,3520,3600,3667,3725,3770,3811,3848,3877,3902,3926,3948,3966,3980,3979,3962,3930,3889,3838,3785,3740,3695,3652,3615,3575,3534,3500,3471,3448,3431,3419,3404,3393,3381,3375,7143,7139,7132,7122,7112,7100,7090,7076,7061,7043,7018,6986,6958,6928,6902,6873,6843,6815,6783,6745,6705,6659,6607,6553,6500,6444,6378,6312,6236,6148,6050,5941,5848,5771,5081,5030,4987,4526,4497,4466,4445,4431,4421,4410,4403,4398,4394,4390,4385,2872,2862,2846,2829,2813,2805,2660,2669,2684,2704,2732,2764,2789,2802,2776,2603,2494,2411,2334,2259,2184,2110,2027,1946,1855,1759,1668,1578,1491,1410,1328,1243,1147,1037,951,890,842,803,768,746,727,711,696,682,665,649,628,603,573,559,554,7130,7127,7120,7110,7099,7088,7073,7058,7044,7024,6995,6964,6935,6906,6880,6851,6820,6792,6756,6717,6674,6627,6576,6524,6473,6414,6347,6279,6199,6105,5981,5827,5688,5529,5248,5127,5077,4409,4397,4382,4368,4357,4347,4337,4330,4322,4315,4309,4304,2810,2804,2795,2785,2778,2773,2619,2624,2638,2648,2661,2675,2681,2670,2631,2547,2472,2400,2329,2258,2182,2108,2026,1945,1854,1760,1670,1580,1496,1416,1336,1253,1158,1010,931,876,833,797,766,743,723,709,694,681,664,650,632,618,557,552,549,7125,7121,7113,7103,7092,7071,7056,7042,7025,6998,6968,6939,6912,6885,6859,6831,6801,6770,6733,6690,6646,6596,6546,6495,6446,6387,6322,6254,6172,6080,5947,5691,5542,5400,5254,5160,5116,4317,4308,4298,4286,4275,4263,4254,4244,4234,4227,4223,4217,2762,2759,2753,2747,2742,2735,2573,2576,2586,2592,2595,2596,2590,2569,2531,2480,2446,2389,2325,2256,2180,2105,2023,1941,1852,1761,1672,1586,1504,1423,1346,1277,1223,918,887,851,815,786,760,740,720,705,689,675,659,647,635,626,544,543,542,7089,7080,7070,7060,7053,7049,7037,7023,7000,6971,6945,6917,6893,6869,6840,6812,6782,6746,6709,6665,6616,6566,6517,6471,6419,6361,6299,6233,6162,6099,6038,5447,5377,5288,5204,5138,5108,4225,4219,4212,4205,4193,4182,4170,4165,4159,4152,4145,4140,2716,2713,2707,2701,2698,2694,2537,2539,2540,2541,2538,2529,2516,2492,2454,2392,2296,2217,2151,2091,2034,1977,1920,1868,1803,1737,1671,1595,1516,1433,1343,1278,1242,866,847,821,798,773,752,732,716,700,685,670,653,641,631,624,535,534,532,7085,7078,7067,7055,7045,7034,7019,6999,6972,6948,6925,6903,6879,6854,6825,6796,6761,6723,6681,6637,6588,6539,6493,6447,6391,6335,6277,6216,6154,6108,6071,5270,5236,5184,5129,5089,5067,4150,4143,4136,4131,4121,4109,4097,4089,4082,4076,4069,4065,2674,2672,2667,2659,2657,2655,2504,2502,2498,2496,2489,2478,2460,2433,2394,2343,2276,2209,2145,2085,2029,1975,1918,1867,1804,1740,1680,1608,1538,1454,1312,1250,1220,828,816,800,780,759,741,722,706,691,677,661,646,634,623,616,527,525,524,7083,7077,7066,7051,7031,7014,6997,6976,6953,6929,6909,6886,6865,6841,6814,6784,6741,6699,6656,6609,6561,6511,6470,6421,6367,6311,6251,6190,6139,6100,6073,5124,5105,5075,5044,5018,5004,4079,4074,4068,4059,4052,4041,4031,4019,4008,3999,3991,3988,2633,2630,2626,2621,2616,2614,2469,2467,2463,2456,2447,2432,2414,2386,2351,2304,2249,2190,2132,2076,2021,1969,1914,1865,1805,1746,1692,1630,1577,1537,1211,1187,1171,805,794,781,763,747,729,714,698,683,668,651,637,621,612,604,515,513,512,7035,7032,7026,7013,7008,6992,6975,6957,6936,6914,6898,6877,6857,6834,6806,6771,6719,6672,6628,6582,6537,6491,6448,6396,6343,6285,6223,6160,6112,6074,6056,5001,4988,4967,4947,4933,4925,4015,4009,4003,3993,3982,3970,3957,3944,3931,3919,3912,3907,2594,2591,2587,2584,2578,2574,2436,2435,2430,2421,2409,2391,2371,2348,2313,2271,2220,2170,2117,2063,2008,1959,1907,1858,1801,1749,1700,1652,1610,1585,1130,1119,1109,789,779,765,751,735,718,704,687,673,654,638,622,608,601,594,506,505,504,7030,7028,7017,7003,6989,6973,6959,6940,6920,6905,6887,6870,6852,6829,6803,6765,6688,6642,6600,6559,6514,6475,6427,6375,6320,6262,6192,6128,6072,6033,6015,4883,4877,4865,4855,4845,4838,3949,3943,3937,3928,3916,3903,3891,3876,3864,3849,3837,3830,2561,2559,2555,2553,2549,2548,2406,2402,2397,2387,2374,2359,2339,2314,2283,2239,2194,2148,2097,2047,1997,1950,1899,1850,1796,1751,1708,1667,1633,1614,1059,1053,1046,783,771,757,742,726,710,693,678,660,642,625,607,597,593,590,499,498,497,7022,7015,7005,6990,6974,6960,6944,6926,6911,6896,6881,6866,6849,6830,6810,6795,6625,6603,6571,6535,6496,6458,6409,6356,6298,6231,6158,6092,6026,5976,5950,4763,4758,4752,4745,4736,4730,3893,3886,3879,3873,3862,3845,3828,3812,3793,3777,3765,3756,2533,2530,2527,2523,2521,2520,2376,2372,2369,2361,2349,2330,2309,2285,2250,2212,2168,2125,2077,2031,1984,1937,1892,1841,1790,1748,1712,1679,1648,1632,987,980,966,788,769,753,734,717,701,684,667,648,629,610,595,589,585,580,492,491,490,7007,7001,6991,6977,6963,6946,6930,6915,6904,6888,6876,6864,6848,6833,6818,6809,6584,6570,6545,6513,6481,6442,6393,6342,6280,6209,6129,6048,5965,5898,5861,4663,4660,4654,4648,4639,4633,3839,3833,3825,3818,3807,3789,3772,3754,3729,3705,3684,3674,2511,2509,2507,2505,2501,2500,2354,2352,2346,2337,2322,2305,2284,2254,2219,2181,2142,2100,2056,2011,1966,1919,1877,1827,1780,1741,1709,1682,1655,1638,929,915,884,813,775,750,728,708,688,672,652,633,614,596,588,579,576,572,487,485,483,6993,6988,6979,6966,6952,6937,6921,6910,6899,6884,6875,6862,6847,6835,6821,6816,6562,6551,6531,6503,6474,6433,6384,6329,6268,6189,6104,6006,5896,5784,5732,4553,4550,4546,4541,4533,4527,3795,3791,3782,3774,3762,3744,3724,3696,3664,3629,3603,3588,2491,2488,2485,2484,2482,2481,2332,2328,2321,2311,2299,2282,2255,2224,2192,2155,2116,2073,2032,1990,1949,1903,1860,1812,1767,1731,1703,1675,1650,1635,889,874,848,807,772,745,719,697,676,656,636,615,600,587,577,568,562,560,481,480,479,6984,6980,6970,6961,6947,6933,6916,6907,6897,6883,6874,6861,6846,6836,6824,6819,6552,6542,6522,6497,6469,6426,6377,6324,6261,6175,6083,5968,5823,5604,5546,4451,4447,4441,4435,4429,4424,3766,3760,3751,3737,3723,3703,3678,3648,3605,3548,3514,3493,2474,2471,2468,2466,2464,2462,2312,2308,2302,2289,2274,2253,2228,2198,2164,2129,2090,2048,2005,1967,1926,1887,1840,1791,1753,1719,1693,1664,1641,1629,863,849,824,796,764,738,712,686,662,640,617,598,586,574,564,556,550,547,472,471,470,5883,5880,5872,5862,5850,5833,5816,5797,5774,5753,5729,5705,5682,5656,5636,5624,5251,5237,5205,5157,5100,5039,4982,4938,4913,4903,4918,4965,5066,5257,5295,4353,4348,4343,4336,4331,4327,3738,3732,3722,3704,3685,3666,3644,3611,3558,3453,3409,3387,2457,2455,2452,2448,2444,2442,2300,2294,2286,2268,2247,2226,2201,2171,2139,2102,2064,2022,1983,1944,1900,1861,1816,1769,1733,1702,1673,1647,1626,1617,845,832,812,787,758,730,702,674,645,620,599,582,569,558,548,539,533,529,458,457,456,5878,5875,5868,5858,5846,5830,5814,5794,5772,5752,5726,5700,5673,5649,5625,5609,5265,5246,5212,5161,5101,5034,4970,4923,4893,4880,4885,4916,4976,5059,5094,4252,4246,4236,4226,4215,4209,3721,3708,3691,3673,3656,3638,3617,3591,3568,3299,3282,3268,2440,2438,2434,2428,2422,2417,2288,2280,2263,2243,2222,2200,2173,2144,2113,2074,2036,1995,1956,1915,1874,1830,1786,1747,1713,1681,1649,1624,1606,1600,836,822,806,784,756,724,690,657,627,602,583,567,553,541,530,520,514,509,449,447,446,5869,5864,5860,5851,5838,5822,5808,5788,5766,5747,5721,5695,5663,5634,5602,5574,5298,5268,5225,5170,5104,5026,4948,4891,4851,4825,4819,4835,4866,4901,4921,4162,4156,4142,4129,4112,4098,3707,3690,3670,3650,3631,3612,3592,3573,3560,3152,3143,3135,2427,2424,2415,2405,2395,2388,2277,2264,2244,2223,2202,2177,2150,2120,2084,2046,2004,1968,1929,1890,1845,1798,1757,1722,1689,1654,1623,1602,1584,1576,838,823,809,790,761,725,679,639,605,584,565,551,536,523,510,501,494,488,440,438,437,5854,5853,5847,5837,5825,5813,5798,5779,5759,5739,5713,5685,5651,5616,5570,5502,5374,5301,5247,5189,5115,5024,4914,4836,4780,4744,4725,4726,4741,4755,4765,4073,4066,4053,4035,4010,3986,3712,3683,3655,3632,3607,3586,3567,3551,3539,3011,3006,3002,2416,2410,2396,2382,2368,2356,2270,2251,2229,2207,2179,2153,2124,2092,2058,2019,1979,1939,1897,1857,1811,1766,1728,1695,1656,1621,1594,1572,1559,1552,844,834,819,804,777,739,655,611,581,561,545,531,517,503,493,482,473,459,439,431,428,5836,5835,5828,5819,5810,5799,5785,5768,5751,5728,5701,5671,5638,5600,5554,5488,5398,5332,5272,5213,5141,5042,4847,4747,4694,4659,4635,4625,4626,4631,4634,3995,3985,3968,3941,3905,3851,3739,3680,3642,3610,3581,3561,3541,3528,3518,2874,2870,2863,2412,2398,2379,2363,2342,2316,2273,2240,2214,2188,2159,2130,2096,2065,2030,1993,1953,1909,1869,1823,1777,1735,1697,1657,1620,1588,1562,1542,1530,1524,857,852,839,825,810,795,592,575,555,537,522,508,496,484,474,463,452,441,430,422,419,5817,5815,5811,5804,5793,5782,5770,5757,5741,5717,5692,5662,5628,5590,5545,5485,5415,5352,5292,5244,5197,5153,4665,4622,4584,4551,4528,4514,4507,4504,4501,3923,3913,3896,3868,3827,3778,3715,3662,3621,3585,3555,3533,3516,3505,3497,2748,2738,2723,2419,2393,2367,2345,2319,2291,2257,2225,2196,2166,2137,2107,2071,2038,2000,1965,1924,1882,1835,1788,1744,1701,1660,1618,1583,1555,1531,1512,1499,1492,872,869,862,853,843,837,546,538,526,511,500,489,476,464,453,445,434,426,417,410,407,5795,5792,5789,5783,5773,5763,5755,5743,5725,5706,5683,5652,5621,5582,5540,5487,5425,5369,5317,5273,5240,5217,4513,4494,4467,4442,4420,4400,4387,4376,4370,3869,3856,3832,3804,3769,3726,3676,3634,3593,3557,3529,3510,3492,3483,3476,2629,2610,2564,2449,2390,2355,2326,2298,2269,2237,2208,2176,2147,2114,2081,2043,2006,1973,1935,1894,1849,1799,1754,1711,1666,1622,1582,1547,1521,1497,1481,1471,1464,891,888,882,875,870,868,507,502,495,486,477,466,454,443,433,425,415,408,400,394,392,5769,5767,5764,5760,5754,5749,5740,5727,5712,5693,5668,5642,5613,5576,5534,5486,5429,5380,5337,5293,5267,5252,4383,4372,4354,4335,4313,4291,4270,4248,4231,3822,3808,3781,3755,3720,3677,3636,3596,3559,3527,3503,3484,3468,3461,3455,2528,2513,2477,2418,2370,2336,2303,2275,2242,2213,2183,2152,2123,2088,2053,2016,1980,1943,1901,1862,1814,1764,1720,1677,1631,1589,1549,1515,1489,1468,1450,1438,1429,913,910,906,900,896,893,478,475,469,460,451,442,432,423,414,406,397,391,384,378,376,5746,5744,5742,5737,5731,5724,5718,5709,5697,5681,5657,5632,5605,5572,5531,5484,5434,5386,5349,5309,5282,5271,4266,4258,4239,4221,4200,4176,4154,4124,4093,3802,3775,3741,3706,3669,3633,3594,3556,3523,3496,3475,3459,3446,3438,3433,2451,2437,2413,2375,2340,2307,2278,2246,2215,2186,2158,2127,2094,2062,2024,1988,1952,1911,1870,1824,1776,1730,1688,1640,1599,1557,1517,1485,1457,1436,1415,1399,1390,944,939,933,923,916,914,450,448,444,436,429,421,412,404,396,389,381,375,367,359,356,5715,5714,5711,5708,5704,5699,5696,5689,5680,5664,5644,5623,5596,5566,5527,5482,5436,5391,5360,5323,5294,5279,4160,4153,4138,4119,4095,4071,4042,4000,3934,3814,3750,3702,3661,3624,3587,3552,3517,3488,3464,3447,3434,3425,3417,3412,2383,2373,2357,2333,2306,2279,2248,2218,2189,2161,2133,2101,2069,2035,1998,1962,1923,1883,1837,1789,1743,1699,1651,1605,1566,1525,1487,1455,1427,1401,1379,1361,1348,981,971,959,949,941,937,427,424,420,413,409,402,395,387,382,374,363,354,345,338,335,5675,5676,5678,5677,5674,5672,5669,5665,5660,5648,5630,5610,5585,5558,5519,5478,5435,5393,5364,5334,5305,5289,4060,4054,4045,4026,4002,3974,3939,3898,3840,3768,3710,3660,3619,3579,3543,3512,3480,3456,3436,3421,3407,3398,3390,3386,2331,2324,2310,2293,2272,2245,2216,2191,2163,2135,2106,2072,2041,2003,1972,1934,1895,1851,1802,1755,1710,1663,1616,1571,1534,1495,1458,1426,1395,1369,1341,1313,1292,1034,1011,989,974,963,958,403,401,398,393,390,386,379,372,365,357,347,336,321,310,305,5633,5635,5639,5641,5643,5646,5647,5645,5640,5629,5617,5598,5575,5549,5514,5473,5430,5392,5366,5340,5312,5297,3971,3964,3952,3933,3910,3883,3850,3810,3763,3709,3658,3613,3570,3532,3499,3470,3445,3426,3405,3389,3377,3369,3363,3359,2287,2281,2267,2252,2234,2211,2185,2162,2138,2112,2079,2045,2012,1978,1942,1902,1863,1817,1768,1724,1678,1628,1581,1539,1501,1467,1431,1398,1368,1338,1306,1268,1213,1106,1058,1025,1002,985,979,385,383,380,377,373,370,362,355,349,341,331,317,291,280,274,5584,5589,5595,5603,5608,5614,5620,5622,5619,5611,5599,5583,5564,5538,5504,5465,5427,5390,5368,5345,5320,5304,3888,3882,3871,3854,3829,3803,3771,3733,3689,3645,3601,3562,3521,3487,3458,3432,3410,3391,3373,3360,3349,3345,3341,3338,2238,2233,2221,2210,2195,2175,2154,2131,2109,2082,2050,2017,1985,1951,1912,1872,1828,1782,1736,1694,1644,1596,1548,1508,1473,1440,1406,1374,1340,1309,1276,1236,1185,1125,1081,1052,1026,1007,995,368,364,360,358,353,350,343,339,333,327,318,312,244,239,237,5530,5536,5548,5560,5568,5577,5588,5592,5593,5591,5581,5569,5553,5525,5494,5459,5421,5388,5367,5346,5322,5306,3815,3809,3797,3780,3759,3731,3700,3663,3625,3582,3545,3509,3474,3443,3420,3396,3374,3356,3344,3336,3328,3324,3321,3319,2193,2187,2178,2167,2156,2140,2122,2098,2075,2049,2020,1989,1957,1921,1886,1842,1794,1750,1705,1658,1609,1564,1520,1480,1446,1413,1382,1350,1315,1282,1246,1212,1169,1128,1092,1066,1041,1022,1009,348,346,342,340,337,332,328,322,316,308,302,300,197,194,193,5460,5472,5491,5508,5522,5541,5556,5565,5571,5573,5567,5555,5535,5512,5481,5449,5413,5383,5363,5341,5318,5303,3753,3746,3734,3719,3693,3665,3635,3599,3563,3524,3489,3457,3427,3400,3376,3357,3339,3325,3316,3307,3302,3296,3292,3289,2149,2143,2136,2128,2119,2104,2086,2066,2042,2018,1992,1961,1928,1893,1853,1810,1762,1718,1674,1625,1579,1536,1494,1456,1420,1388,1358,1326,1295,1261,1224,1191,1156,1120,1091,1071,1048,1030,1016,330,329,326,324,319,313,307,301,297,292,288,285,155,154,153,5387,5399,5423,5448,5471,5495,5517,5532,5544,5550,5547,5537,5520,5496,5468,5437,5403,5379,5359,5335,5310,5296,3694,3687,3675,3659,3637,3608,3577,3538,3504,3466,3435,3406,3379,3355,3337,3320,3305,3293,3284,3273,3265,3260,3254,3251,2103,2099,2093,2087,2078,2067,2051,2033,2010,1987,1963,1931,1898,1866,1822,1778,1734,1691,1643,1597,1551,1509,1472,1434,1397,1366,1333,1303,1273,1241,1207,1174,1141,1110,1085,1065,1045,1027,1013,311,309,306,303,299,294,289,282,278,273,269,266,122,121,120,5311,5328,5355,5384,5419,5450,5477,5499,5516,5524,5528,5521,5507,5483,5455,5424,5395,5373,5350,5324,5300,5287,3646,3641,3627,3609,3584,3554,3522,3486,3451,3416,3384,3354,3333,3313,3294,3278,3262,3250,3239,3233,3225,3221,3216,3214,2059,2057,2052,2044,2039,2028,2014,1999,1981,1960,1936,1905,1873,1836,1792,1752,1707,1661,1613,1568,1526,1486,1448,1411,1376,1344,1310,1280,1249,1217,1184,1155,1127,1099,1076,1055,1033,1015,1006,295,293,290,286,281,275,270,263,258,253,248,245,92,93,94,5224,5249,5284,5327,5370,5405,5439,5467,5489,5501,5509,5505,5493,5470,5442,5412,5385,5365,5342,5313,5291,5280,3604,3597,3583,3566,3540,3513,3478,3440,3401,3364,3332,3303,3281,3261,3243,3229,3215,3207,3199,3195,3189,3184,3181,3180,2015,2013,2007,2001,1996,1991,1982,1971,1954,1932,1908,1881,1847,1808,1765,1726,1684,1634,1587,1543,1500,1463,1424,1389,1355,1322,1290,1259,1225,1193,1162,1136,1108,1084,1062,1039,1017,1001,992,279,277,272,267,261,256,249,242,235,228,221,217,72,74,75,5110,5158,5219,5275,5326,5371,5404,5438,5462,5480,5492,5490,5476,5456,5428,5401,5381,5362,5338,5307,5286,5278,3569,3564,3550,3531,3507,3477,3441,3399,3352,3311,3275,3244,3222,3206,3192,3182,3172,3166,3161,3158,3154,3149,3145,3144,1976,1974,1970,1964,1958,1955,1948,1938,1925,1906,1888,1856,1819,1781,1742,1704,1659,1611,1567,1522,1479,1442,1405,1371,1334,1301,1269,1238,1206,1173,1144,1117,1093,1070,1044,1019,998,984,978,262,260,255,251,243,234,227,216,206,200,192,186,55,57,59,4943,5050,5152,5233,5290,5344,5382,5416,5443,5461,5474,5475,5463,5445,5422,5396,5378,5361,5333,5302,5283,5277,3544,3537,3526,3508,3482,3452,3413,3365,3310,3246,3204,3179,3164,3151,3140,3132,3125,3120,3119,3117,3116,3113,3111,3109,1933,1930,1927,1922,1917,1913,1910,1904,1896,1885,1864,1831,1793,1758,1723,1685,1636,1591,1546,1503,1462,1422,1387,1351,1311,1279,1245,1215,1182,1151,1124,1098,1075,1047,1020,996,977,964,960,250,246,238,232,220,208,199,187,179,172,167,163,38,41,43,4674,4941,5102,5207,5274,5330,5372,5402,5431,5452,5464,5466,5458,5441,5418,5394,5375,5356,5329,5299,5281,5276,3530,3525,3515,3494,3467,3437,3397,3342,3271,3159,3121,3103,3098,3095,3089,3082,3074,3071,3072,3075,3078,3079,3080,3081,1891,1889,1884,1879,1875,1876,1880,1878,1871,1859,1839,1809,1773,1739,1706,1665,1619,1575,1532,1488,1447,1407,1370,1330,1293,1258,1222,1190,1160,1132,1103,1078,1051,1021,994,973,956,946,942,236,230,218,209,198,184,173,164,157,150,145,141,25,27,30,4130,3855,3686,3571,3485,3423,3367,3323,3280,3236,3198,3168,3136,3112,3094,3070,3057,3041,3017,3003,2991,2985,2721,2725,2733,2744,2756,2772,2794,2835,2894,2993,3019,3026,3030,3033,3031,3028,3024,3025,3029,3035,3039,3042,3046,3047,1838,1834,1829,1825,1826,1832,1843,1848,1844,1833,1815,1787,1756,1727,1696,1653,1607,1563,1519,1477,1435,1392,1352,1308,1271,1235,1200,1166,1138,1107,1082,1056,1024,993,970,952,938,928,919,222,215,201,190,180,168,158,148,139,133,127,124,17,19,21,3859,3749,3639,3546,3469,3411,3358,3318,3276,3234,3197,3167,3134,3108,3091,3068,3054,3036,3014,2998,2987,2979,2714,2720,2727,2737,2751,2766,2784,2817,2859,2909,2938,2954,2962,2968,2971,2974,2975,2977,2982,2988,2992,2995,2999,3001,1784,1779,1775,1770,1772,1783,1806,1818,1820,1813,1795,1771,1745,1717,1687,1645,1603,1558,1511,1470,1425,1380,1332,1284,1244,1210,1177,1145,1116,1087,1061,1031,999,968,947,932,917,908,901,212,204,191,181,169,156,144,134,126,118,112,108,12,13,14,3692,3643,3574,3506,3444,3394,3346,3308,3267,3226,3193,3162,3131,3106,3087,3064,3050,3027,3007,2989,2976,2966,2703,2708,2715,2726,2741,2754,2770,2793,2821,2852,2878,2893,2904,2914,2921,2926,2927,2931,2937,2943,2948,2952,2955,2958,1732,1729,1725,1716,1715,1721,1774,1797,1807,1800,1785,1763,1738,1714,1683,1639,1598,1553,1507,1466,1419,1372,1318,1252,1216,1183,1152,1123,1096,1067,1035,1003,972,945,925,909,898,886,880,211,202,188,175,162,149,136,125,115,106,101,95,8,7,6,3580,3553,3511,3462,3414,3370,3334,3297,3255,3218,3186,3156,3127,3101,3083,3060,3044,3018,2997,2978,2963,2956,2692,2696,2702,2712,2724,2736,2752,2769,2786,2808,2828,2842,2854,2866,2875,2883,2887,2892,2899,2905,2910,2916,2920,2922,1690,1686,1676,1662,1646,1615,1535,1482,1444,1412,1385,1365,1347,1325,1307,1289,1275,1257,1240,1221,1208,1194,1189,1196,1180,1157,1129,1101,1074,1043,1008,976,948,924,903,885,871,860,854,223,213,196,177,161,146,130,117,105,96,91,86,4,1,0,3498,3481,3454,3422,3383,3347,3317,3283,3241,3208,3177,3147,3122,3097,3076,3056,3034,3008,2986,2965,2951,2946,2686,2688,2691,2697,2706,2717,2730,2746,2760,2775,2788,2801,2814,2826,2836,2843,2849,2858,2867,2873,2879,2886,2888,2890,1642,1637,1627,1612,1593,1561,1514,1474,1439,1408,1384,1363,1345,1323,1305,1288,1274,1256,1239,1219,1204,1188,1176,1167,1153,1133,1105,1079,1050,1014,983,954,927,902,879,859,841,826,817,241,231,210,185,166,147,129,114,102,90,83,77,5,3,2,3439,3428,3408,3382,3353,3326,3300,3264,3228,3196,3169,3138,3114,3092,3067,3048,3020,2994,2972,2953,2940,2934,2677,2678,2680,2683,2689,2695,2705,2719,2731,2745,2757,2768,2781,2792,2803,2811,2820,2831,2839,2845,2851,2856,2861,2864,1604,1601,1590,1574,1556,1528,1493,1461,1430,1403,1383,1362,1342,1321,1304,1286,1272,1254,1237,1218,1198,1179,1161,1148,1134,1111,1086,1060,1028,990,961,934,905,878,855,831,808,791,778,264,254,233,203,176,152,131,113,99,85,76,70,11,10,9,3395,3385,3368,3348,3330,3306,3279,3245,3213,3185,3160,3130,3104,3084,3059,3037,3009,2983,2959,2941,2928,2923,2664,2665,2666,2668,2673,2676,2682,2690,2700,2711,2722,2734,2749,2765,2779,2787,2796,2806,2816,2824,2832,2837,2841,2844,1573,1570,1560,1545,1529,1505,1478,1451,1421,1396,1378,1359,1339,1319,1302,1285,1270,1251,1234,1214,1192,1170,1150,1135,1115,1095,1072,1040,1004,969,940,912,883,856,827,799,770,749,731,298,283,257,224,189,160,137,116,97,81,69,62,18,16,15,3361,3350,3340,3327,3312,3287,3258,3227,3201,3174,3148,3123,3099,3073,3052,3023,2996,2969,2947,2929,2917,2912,2654,2653,2651,2650,2652,2656,2658,2663,2671,2679,2685,2693,2710,2739,2761,2774,2782,2790,2799,2807,2818,2825,2830,2834,1554,1550,1541,1527,1510,1490,1469,1443,1417,1394,1375,1357,1337,1316,1300,1283,1267,1247,1228,1209,1186,1163,1143,1122,1102,1080,1054,1018,982,950,921,895,865,835,801,767,733,699,669,351,323,287,247,207,171,143,119,98,79,65,52,31,22,20,3343,3329,3322,3309,3291,3266,3238,3212,3188,3165,3137,3115,3093,3065,3043,3012,2984,2957,2935,2918,2906,2900,2645,2643,2640,2637,2635,2634,2636,2639,2641,2644,2646,2649,2662,2718,2750,2767,2777,2783,2791,2800,2809,2819,2822,2827,1544,1540,1533,1518,1502,1483,1465,1441,1414,1391,1373,1354,1335,1314,1299,1281,1266,1248,1226,1205,1181,1159,1137,1112,1090,1068,1038,1000,965,935,907,877,846,811,774,737,695,643,571,435,366,315,268,226,183,151,123,100,78,63,49,34,26,23,3331,3314,3304,3290,3270,3248,3223,3200,3178,3155,3129,3107,3085,3058,3032,3000,2970,2945,2925,2907,2895,2889,2632,2628,2623,2618,2613,2611,2608,2607,2605,2604,2602,2597,2579,2526,2495,2473,2453,2431,2408,2385,2366,2353,2335,2318,2241,2227,2204,2174,2146,2118,2089,2068,2055,1459,1449,1428,1402,1377,1349,1317,1287,1255,1227,1203,1178,1154,1131,1104,1083,1057,1023,986,953,920,894,864,829,792,754,713,666,606,540,455,388,334,284,240,195,159,128,103,80,64,50,37,29,24,3315,3301,3288,3272,3252,3232,3210,3191,3170,3146,3124,3100,3077,3053,3022,2990,2960,2933,2913,2896,2885,2876,2622,2617,2609,2600,2593,2589,2585,2580,2575,2572,2568,2560,2543,2514,2490,2470,2450,2429,2407,2384,2365,2350,2327,2301,2260,2232,2206,2172,2141,2111,2080,2054,2040,1475,1460,1437,1409,1381,1353,1320,1291,1260,1230,1202,1175,1149,1126,1100,1077,1049,1012,975,943,911,881,850,814,776,736,692,644,591,528,461,399,344,296,252,205,165,132,104,82,66,54,42,33,28,3295,3286,3274,3256,3237,3219,3202,3183,3163,3139,3118,3096,3069,3049,3015,2980,2950,2924,2902,2884,2868,2860,2620,2612,2599,2588,2577,2571,2567,2562,2558,2552,2545,2534,2519,2503,2483,2465,2445,2426,2404,2381,2364,2347,2323,2297,2266,2236,2205,2169,2134,2095,2060,2025,2002,1506,1484,1453,1418,1386,1356,1324,1294,1262,1233,1201,1172,1146,1121,1097,1073,1042,1005,967,936,904,873,840,802,762,721,680,630,578,521,462,405,352,304,259,214,170,135,107,84,67,56,46,36,32,3277,3269,3259,3242,3224,3209,3194,3176,3157,3133,3110,3090,3063,3045,3010,2973,2942,2915,2891,2869,2850,2840,2627,2615,2598,2583,2570,2563,2556,2551,2544,2535,2525,2518,2508,2493,2479,2461,2443,2425,2403,2380,2362,2344,2320,2295,2265,2235,2203,2165,2126,2083,2037,1986,1947,1565,1523,1476,1432,1393,1360,1327,1296,1263,1232,1199,1168,1142,1118,1094,1069,1036,997,962,930,899,867,830,793,755,715,671,619,570,519,465,411,361,314,265,219,174,138,109,87,68,58,48,40,35,3263,3257,3247,3235,3220,3205,3190,3173,3153,3128,3105,3088,3062,3040,3005,2967,2936,2908,2882,2855,2833,2812,2647,2625,2601,2582,2566,2557,2550,2542,2532,2522,2515,2510,2499,2487,2476,2459,2441,2423,2401,2378,2360,2341,2317,2292,2262,2231,2199,2160,2121,2070,2009,1940,1846,1669,1569,1498,1445,1400,1364,1329,1297,1264,1231,1197,1165,1140,1114,1089,1064,1032,991,957,926,897,861,820,785,748,707,663,613,566,518,467,416,369,320,271,225,178,140,110,88,71,60,51,45,39,3253,3249,3240,3231,3217,3203,3187,3171,3150,3126,3102,3086,3061,3038,3004,2964,2932,2903,2877,2847,2815,2771,2687,2642,2606,2581,2565,2554,2546,2536,2524,2517,2512,2506,2497,2486,2475,2458,2439,2420,2399,2377,2358,2338,2315,2290,2261,2230,2197,2157,2115,2061,1994,1916,1821,1698,1592,1513,1452,1404,1367,1331,1298,1265,1229,1195,1164,1139,1113,1088,1063,1029,988,955,922,892,858,818,782,744,703,658,609,563,516,468,418,371,325,276,229,182,142,111,89,73,61,53,47,44},
};
struct TargetPattern {
vector<int> orgA_;
vector<int> A_;
vector<int> numToPos_;
bool flip_;
void Init() {
orgA_ = patterns_[patternT];
A_ = orgA_;
flip_ = false;
cauto& realA = server.A;
vector<int> revA(NN);
REP(i, NN) {
revA[i] = NN - 1 - A_[i];
}
s64 baseDiff = 0;
s64 revDiff = 0;
REP(i, NN) {
baseDiff += square(realA[i] - A_[i]);
revDiff += square(realA[i] - revA[i]);
}
if (revDiff < baseDiff) {
A_ = move(revA);
flip_ = true;
}
numToPos_.resize(NN);
REP(i, NN) {
numToPos_[A_[i]] = i;
}
}
} target_;
const vector<vector<vector<vector<int>>>> targetRoutes_ = {
{},
{},
{},
{},
{},
{},
{},
{{{56,57,77,76,96,97,58,78,98,117,116,118,138,139,18,38,19,39,59,79,99,119,159,158,179,239,219,199,178,238,218,198,177,157,176,297,277,258,278,257,276,256,275,253,273,274,234,233,254,255,235,216,236,237,217,197,195,196,156,137,135,136,175,174,154,155,134,153,171,150,151,152,55,54,74,75,115,95,114,94,73,93,92,113,112,132,133,173,193,213,215,194,214,212,172,192,232,252,251,250,271,379,359,339,319,298,299,279,259,295,296,316,317,318,358,338,337,357,378,377,396,397,399,398,376,336,356,355,374,395,375,373,394,393,372,354,335,334,313,294,293,314,315,333,353,351,371,391,392,390,388,368,389,369,370,352,332,331,311,290,309,330,350,349,310,289,291,272,312,292,270,269,248,268,249,229,208,228,230,},{37,17,16,15,35,36,34,14,13,33,53,52,70,71,72,32,12,31,9,10,11,51,50,30,29,28,49,69,68,3,4,25,5,6,8,7,26,27,66,46,47,67,48,88,87,86,121,101,100,60,80,81,61,40,0,20,21,1,2,41,62,63,82,83,102,103,123,124,42,22,24,23,43,64,44,45,65,104,84,85,106,126,120,140,160,141,181,161,162,143,142,122,182,183,163,184,164,144,146,165,185,145,125,105,107,108,128,127,129,131,111,91,90,110,89,109,130,149,166,167,147,148,169,170,190,231,211,209,210,191,189,188,168,187,186,207,206,220,180,200,221,201,202,223,222,203,204,205,226,227,246,245,242,262,263,243,224,244,225,265,382,383,363,364,384,385,386,387,367,365,366,346,326,327,329,348,347,328,308,288,267,247,287,306,307,285,286,266,264,284,283,304,305,324,345,344,325,323,303,282,302,321,322,343,342,362,361,360,380,381,341,340,320,300,301,280,281,261,260,240,241,},},{{231,211,209,210,170,191,190,189,168,188,186,187,207,206,180,220,200,221,201,202,223,222,203,204,205,226,227,246,245,242,262,263,243,224,244,225,265,264,283,304,305,325,324,344,345,343,342,362,361,341,340,320,301,300,280,281,261,260,240,241,381,380,360,323,322,321,302,282,303,284,266,285,286,307,306,287,267,247,288,308,329,328,348,347,327,326,346,387,367,365,366,386,385,384,364,363,383,382,},{169,166,167,147,148,149,130,131,111,91,90,110,109,89,129,127,128,108,107,126,106,120,140,160,141,181,161,162,143,142,122,182,183,163,184,164,144,146,165,185,145,125,105,3,4,25,5,6,8,7,26,27,47,46,66,67,48,68,69,49,28,29,30,51,70,71,72,34,35,15,16,17,37,36,14,13,33,53,52,32,12,31,11,9,10,50,88,87,86,84,104,85,65,45,44,64,43,24,23,22,42,124,123,103,102,83,82,63,62,41,0,20,40,2,1,21,61,81,80,60,100,101,121,},},{{212,172,192,215,194,214,213,193,173,153,150,171,151,152,55,54,74,75,115,95,114,94,73,93,92,113,112,132,133,154,134,155,174,175,297,277,258,278,257,276,256,275,253,273,274,234,233,254,255,235,216,236,237,217,197,196,195,176,156,137,135,136,157,177,218,238,198,178,239,219,199,179,159,158,19,39,18,38,59,79,99,119,139,138,118,116,117,98,58,78,97,96,76,77,57,56,},{230,208,228,229,249,269,268,248,270,349,350,330,310,309,289,290,311,331,332,315,314,293,294,313,395,375,394,393,373,372,374,354,398,399,397,396,376,377,337,358,338,296,295,316,317,318,319,339,359,379,298,299,259,279,357,378,356,336,355,335,334,333,353,352,351,392,391,371,370,369,390,389,368,388,291,272,312,292,271,251,250,252,232,},},{{56,57,77,76,96,97,58,78,98,117,116,118,138,139,18,38,19,39,59,79,99,119,159,158,179,239,219,199,178,238,218,198,177,157,176,137,135,136,156,196,195,197,217,237,236,216,235,255,275,274,273,234,233,253,254,256,276,257,278,258,277,297,},{212,215,194,214,193,173,171,150,151,152,153,133,132,113,112,73,93,115,55,54,74,75,95,94,114,92,134,155,154,174,175,213,192,172,},},{{232,252,250,251,312,292,272,368,388,389,390,369,370,391,392,371,351,353,333,293,294,315,314,313,352,332,331,311,291,289,310,349,350,330,309,290,271,270,268,248,269,249,208,228,229,230,},{334,335,355,336,356,378,357,337,338,358,379,359,339,319,318,295,296,316,317,298,299,279,259,377,376,396,398,399,397,354,374,395,375,373,372,393,394,},},{{284,305,304,323,342,362,361,341,340,320,301,300,280,281,261,260,240,241,381,360,380,343,321,322,302,303,282,324,325,344,345,283,},{231,211,209,210,191,190,189,168,188,186,187,207,262,242,263,243,224,244,225,245,264,266,286,306,307,285,287,308,329,326,346,365,366,386,385,384,364,363,383,382,367,387,327,328,347,348,288,267,247,265,246,227,226,206,205,204,223,222,203,202,201,180,220,200,221,170,},},{{169,166,167,147,148,149,130,131,111,91,90,110,109,89,129,127,128,108,107,106,120,140,160,141,181,161,162,143,142,122,182,183,163,184,164,144,145,146,165,185,125,105,126,86,84,104,65,45,44,64,43,24,23,22,2,1,21,40,0,20,121,101,100,80,60,81,61,41,42,62,63,82,83,102,103,123,124,85,},{87,88,48,68,3,4,25,5,6,8,7,26,27,66,46,47,67,69,49,28,29,30,50,51,11,9,10,31,12,32,52,71,70,72,53,33,13,14,34,35,36,15,16,17,37,},},{{87,88,48,68,47,26,27,8,7,25,3,4,5,6,66,46,67,69,49,29,28,30,},{37,17,16,15,35,36,34,14,13,33,53,52,70,71,72,32,12,31,9,10,11,51,50,},},{{45,64,44,43,24,23,22,2,1,21,40,0,20,121,101,100,80,60,81,61,41,42,62,63,82,83,102,103,123,124,},{86,104,84,65,85,126,106,125,146,144,184,164,182,183,162,141,161,160,140,120,181,163,143,142,122,145,185,165,105,107,108,128,127,129,131,111,91,90,110,89,109,130,149,166,167,147,148,169,},},{{283,284,304,305,324,345,344,325,323,342,343,322,321,302,282,303,},{362,361,341,340,320,301,300,280,281,261,260,240,241,381,380,360,},},{{266,285,247,267,288,308,328,327,346,382,383,363,364,384,385,386,366,365,387,367,326,329,348,347,287,286,306,307,},{264,265,225,242,262,263,243,224,244,245,246,227,226,206,220,180,200,221,201,202,203,222,223,204,205,207,186,187,188,168,189,190,191,170,209,210,211,231,},},{{230,229,228,208,249,269,248,268,270,271,232,252,250,251,312,292,272,291,349,350,330,310,309,289,290,311,},{331,332,351,368,388,389,390,370,369,371,392,391,352,353,333,313,294,293,314,315,},},{{334,335,395,375,394,393,373,372,374,354,355,356,336,376,378,377,396,397,398,399,},{357,337,338,358,379,359,339,319,318,295,296,316,317,298,299,279,259,},},{{92,114,94,95,75,74,54,55,115,93,73,112,113,132,},{172,192,212,213,215,194,214,193,173,153,171,150,151,152,133,154,134,155,174,175,},},{{237,216,236,235,278,258,297,277,257,256,276,255,275,254,234,233,253,273,274,217,197,196,195,176,156,136,135,137,},{177,157,238,218,198,178,239,219,199,179,158,159,139,138,117,56,57,77,76,96,97,98,58,78,116,118,119,99,79,59,39,19,38,18,},},},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
{},
};
struct Dister {
private:
vector<int> dists_;
vector<int> froms_;
public:
void Init() {
dists_.assign(NN * NN, -1);
froms_.assign(NN * NN, -1);
CapQue<int, 10000> que;
REP(start, NN) {
que.clear();
int* dists = dists_.data() + start * NN;
int* froms = froms_.data() + start * NN;
que.push(start);
dists[start] = 0;
froms[start] = -1;
while (!que.empty()) {
int c = que.front();
que.pop();
for (int n : aroundMap[c]) {
if (dists[n] >= 0) {
continue;
}
dists[n] = dists[c] + 1;
froms[n] = c;
que.push(n);
}
}
}
}
void GetRoute(int from, int to, vector<int>& route) const {
route.clear();
const int* froms = froms_.data() + to * NN;
int c = from;
while (true) {
c = froms[c];
if (c < 0) {
break;
}
route.emplace_back(c);
}
}
int GetDist(int a, int b) const {
return dists_[a * NN + b];
}
} dister_;
int CalcMoveDist(const array<int, 2>& from, const array<int, 2>& to) {
return min(
max(dister_.GetDist(from[0], to[0]), dister_.GetDist(from[1], to[1])),
max(dister_.GetDist(from[0], to[1]), dister_.GetDist(from[1], to[0]))
);
}
#define USE_SA_POINT_FILTER 0
#define USE_SA_ROLLBACK 0
#define USE_ACCEPT_SCORE 0
struct RandomTable {
vector<int> table_;
void clear() {
table_.clear();
}
void push(int value, int count) {
table_.reserve(table_.size() + count);
REP(i, count) {
table_.emplace_back(value);
}
}
int operator()(Xor64& r) {
return table_[r(table_.size())];
}
};
template <int CAP>
struct RandomTableS {
CapArr<int, CAP> table_;
void push(int value, int count) {
REP(i, count) {
table_.push(value);
}
}
template <class ENGINE>
int operator()(ENGINE& engine) {
return table_[engine() % table_.size()];
}
};
struct SAChecker {
Xor64* rand_ = nullptr;
double* totalMaxScore_ = nullptr;
double temp = 0;
double divTemp = 0;
double currentScore = 0;
double maxScore = 0;
int noMaxUpdateCount = 0;
int nextRollbackCheckCount = INT_MAX;
inline bool operator()(double newScore) {
++noMaxUpdateCount;
if (newScore > currentScore) {
currentScore = newScore;
if (newScore > maxScore) {
maxScore = newScore;
noMaxUpdateCount = 0;
if (newScore > *totalMaxScore_) {
*totalMaxScore_ = newScore;
}
}
return true;
}
else if (newScore == currentScore) {
return true;
}
else {
if (exp((newScore - currentScore) * divTemp) * UINT32_MAX > (*rand_)(UINT32_MAX)) {
currentScore = newScore;
return true;
}
else {
return false;
}
}
}
};
template <class F>
struct SATransition {
const char* name;
F func;
int weight;
};
template <class F>
auto MakeTransition(const char* name, F&& func, int weight) {
return SATransition<F>{ name, func, weight };
}
#define MAKE_TRANS(func, weight) MakeTransition(#func, [&](SAChecker& sac, State& state) { func(sa, sac, state); }, weight)
struct SimulatedAnnealing {
vector<SAChecker> checkers;
double totalMaxScore = 0;
double timeRate = 0;
double temp = 0;
double divTemp = 0;
Xor64 rand_;
double startTemp_ = 200;
double endTemp_ = 1;
int stepLoopCount = 1000;
int tempType_ = 0;
double tempPow_ = 1.5;
double rollbackStartRate_ = 999.0;
int rollbackCount_ = INT_MAX;
double rollbackNextMulti_ = 1.1;
int minRollbackCount_ = 1;
bool forceEnd_ = false;
public:
template <class STATE, class... TRANSITION>
void Run2(ChronoTimer& timer, vector<STATE>& states, tuple<SATransition<TRANSITION>...>& transitions) {
checkers.resize(states.size());
totalMaxScore = states[0].EvalScore();
REP(pi, checkers.size()) {
auto& checker = checkers[pi];
checker.rand_ = &rand_;
checker.totalMaxScore_ = &totalMaxScore;
checker.temp = 0;
checker.divTemp = 0;
checker.currentScore = states[pi].EvalScore();
checker.maxScore = checker.currentScore;
checker.noMaxUpdateCount = 0;
checker.nextRollbackCheckCount = rollbackCount_;
chmax(totalMaxScore, checker.maxScore);
}
RandomTable randTable;
TupleLoop(transitions, [&](auto&& e, size_t i) {
randTable.push((int)i, e.weight);
});
const auto startTime = timer.Now();
const auto endTime = timer.EndTime();
const double subTimeCountDiv = 1.0 / (double)(endTime - startTime).count();
vector<int> pis(states.size());
iota(ALL(pis), 0);
forceEnd_ = false;
while (!timer.IsOver()) {
timeRate = (timer.Now() - startTime).count() * subTimeCountDiv;
if (tempType_ == 0) {
temp = startTemp_ + (endTemp_ - startTemp_) * timeRate;
}
else if (tempType_ == 1) {
temp = startTemp_ * std::pow(endTemp_ / startTemp_, timeRate);
}
else {
temp = startTemp_ * std::pow(endTemp_ / startTemp_, pow(timeRate, tempPow_));
}
divTemp = 1.0 / temp;
for (auto& checker : checkers) {
checker.temp = temp;
checker.divTemp = divTemp;
}
for (int rp = 0; rp < stepLoopCount; ++rp) {
int ti = (int)randTable(rand_);
auto exec = [&](auto&& e, size_t i) {
for (int pi : pis) {
auto& checker = checkers[pi];
e.func(checker, states[pi]);
}
};
TupleAccess(transitions, ti, exec);
}
if (forceEnd_) {
break;
}
}
}
void ForceEnd() {
forceEnd_ = true;
}
private:
template <class Tuple, class Func>
void TupleLoop(Tuple & t, Func && f) {
TupleLoop2(t, forward<Func>(f), make_index_sequence<tuple_size<Tuple>::value>{});
}
template <class Tuple, class Func, size_t... Indics>
void TupleLoop2(Tuple & t, Func && f, index_sequence<Indics...>) {
using swallow = int[];
(void)swallow {
(TupleLoop3<Tuple, Func, Indics>(t, f), 0)...
};
}
template <class Tuple, class Func, size_t Index>
void TupleLoop3(Tuple & t, Func & f) {
f(get<Index>(t), Index);
}
template <class Tuple, class Func>
void TupleAccess(Tuple & t, int i, Func && f) {
TupleAccess2(t, i, forward<Func>(f), make_index_sequence<tuple_size<Tuple>::value>{});
}
template <class Tuple, class Func, size_t... Indics>
void TupleAccess2(Tuple & t, int i, Func && f, index_sequence<Indics...>) {
using swallow = int[];
(void)swallow {
(TupleAccess3<Tuple, Func, Indics>(t, i, f), 0)...
};
}
template <class Tuple, class Func, size_t Index>
void TupleAccess3(Tuple & t, int i, Func & f) {
if (i == Index) {
f(get<Index>(t), Index);
}
}
};
template <class OBJECT>
struct ObjectPool {
static_assert(is_trivially_copyable<OBJECT>::value, "not trivially copyable");
OBJECT* pool_ = nullptr;
OBJECT** reusable_ = nullptr;
int capacity_ = 0;
int usedTotalCount_ = 0;
int usedPoolCount_ = 0;
int reusableCount_ = 0;
int maxTotalCount_ = 0;
~ObjectPool() {
if (pool_) {
free(pool_);
}
if (reusable_) {
free(reusable_);
}
}
void Init(int capacity) {
if (capacity != capacity_) {
if (pool_) {
free(pool_);
}
if (reusable_) {
free(reusable_);
}
pool_ = (OBJECT*)malloc(capacity * sizeof(OBJECT));
reusable_ = (OBJECT**)malloc(capacity * sizeof(OBJECT*));
capacity_ = capacity;
}
usedTotalCount_ = 0;
usedPoolCount_ = 0;
reusableCount_ = 0;
}
void Clear() {
usedTotalCount_ = 0;
usedPoolCount_ = 0;
reusableCount_ = 0;
}
inline OBJECT* New() {
if (reusableCount_) {
++usedTotalCount_;
--reusableCount_;
chmax(maxTotalCount_, usedTotalCount_);
return reusable_[reusableCount_];
}
if (usedPoolCount_ >= capacity_) {
}
++usedTotalCount_;
chmax(maxTotalCount_, usedTotalCount_);
return &pool_[usedPoolCount_++];
}
inline void Delete(OBJECT* obj) {
reusable_[reusableCount_] = obj;
++reusableCount_;
--usedTotalCount_;
}
inline void Delete(OBJECT** start, int count) {
memcpy(&reusable_[reusableCount_], start, sizeof(OBJECT*) * count);
reusableCount_ += count;
usedTotalCount_ -= count;
}
inline int GetUsedCount() const {
return usedTotalCount_;
}
inline string Usage() const {
stringstream ss;
ss << usedTotalCount_ << " (" << (int)floor(usedTotalCount_ * 100 / (double)capacity_ + 0.5) << " %)";
return ss.str();
}
inline int UsedRate() const {
return (int)round(usedTotalCount_ * 100 / (double)capacity_);
}
inline int GetCapacity() const {
return capacity_;
}
inline int GetMaxUseCount() const {
return maxTotalCount_;
}
inline int GetMaxUsedRate() const {
return (int)round((double)GetMaxUseCount() * 100 / (double)capacity_);
}
inline string MaxUsage() const {
stringstream ss;
ss << maxTotalCount_ << " / " << capacity_ << " (" << (int)floor(maxTotalCount_ * 100 / (double)capacity_ + 0.5) << " %)";
return ss.str();
}
double GetMemoryRate() const {
return usedTotalCount_ / (double)capacity_;
}
};
#define USE_HISTOGRAM 0
#define USE_HISTOGRAM_RANGE 0
#define MULTI_BEAM_LOG 0
#define SINGLE_BEAM_LOG 0
template <class NODE, class STATE, class BACKUP>
struct DiffBeam {
public:
struct NodeEx : public NODE {
NodeEx* parent;
NodeEx* child;
NodeEx* prev;
NodeEx* next;
double evalScore;
};
private:
using NodePool = ObjectPool<NodeEx>;
NodePool nodePool_;
vector<NodeEx*> targets_;
vector<NodeEx*> dels_;
public:
int makeNextCount_ = 0;
public:
NODE* New() {
NodeEx* node = nodePool_.New();
return node;
}
void Delete(NODE* node) {
nodePool_.Delete((NodeEx*)node);
}
void GetBest(const NODE* bestNode, vector<const NODE*>& nodes) {
nodes.clear();
const NodeEx* node = (NodeEx*)bestNode;
while (node->parent) {
nodes.push_back(node);
node = node->parent;
}
reverse(ALL(nodes));
}
void ReleaseNode(NodeEx* node) {
VASSERT(node->child == nullptr);
while (true) {
NodeEx* next = nullptr;
if (node->parent) {
if (node->parent->child == node) {
VASSERT(node->prev == nullptr);
if (node->next) {
node->parent->child = node->next;
node->next->prev = nullptr;
}
else {
node->parent->child = nullptr;
next = node->parent;
}
}
else {
NodeEx* prev = node->prev;
NodeEx* next = node->next;
VASSERT(prev);
prev->next = next;
if (next) {
next->prev = prev;
}
}
}
nodePool_.Delete(node);
if (next) {
node = next;
}
else {
break;
}
}
}
void Initialize(int widthLimit, int maxExpandCount, int turnMax) {
targets_.reserve(widthLimit * maxExpandCount);
dels_.reserve(widthLimit * maxExpandCount);
nodePool_.Init(widthLimit * turnMax);
makeNextCount_ = 0;
}
template <class INIT_ROOT, class MAKE_NEXT_NODES, class UPDATE_STATE, class REVERT_STATE, class CALC_WIDTH, class IS_END>
void Run(int turnMax, INIT_ROOT&& initRoot, MAKE_NEXT_NODES&& makeNextNodes, UPDATE_STATE&& updateState, REVERT_STATE&& revertState, CALC_WIDTH&& calcWidth, IS_END&& isEnd, int realTurn) {
nodePool_.Clear();
targets_.clear();
dels_.clear();
static STATE state;
NodeEx* rootNode = nodePool_.New();
{
rootNode->parent = nullptr;
rootNode->child = nullptr;
rootNode->prev = nullptr;
rootNode->next = nullptr;
rootNode->evalScore = 0;
}
initRoot(state, rootNode);
int startDepth = 0;
NodeEx* startNode = rootNode;
REP(turn, turnMax) {
int targetWidth = calcWidth(turn, makeNextCount_);
auto dfs = [&](auto& dfs, int depth, NodeEx* node) -> void {
if (depth >= turn) {
static vector<pr<NODE*, double>> nexts;
nexts.clear();
makeNextNodes(depth, node, state, nexts);
++makeNextCount_;
NodeEx* prev = nullptr;
for (auto&& [nextTmp, evalScore] : nexts) {
NodeEx* next = (NodeEx*)nextTmp;
if (node->child == nullptr) {
node->child = next;
next->parent = node;
next->child = nullptr;
next->prev = nullptr;
next->next = nullptr;
}
else {
prev->next = next;
next->parent = node;
next->child = nullptr;
next->prev = prev;
next->next = nullptr;
}
next->evalScore = evalScore;
prev = next;
}
if (node->child) {
NodeEx* child = node->child;
while (child) {
targets_.push_back(child);
child = child->next;
}
}
else {
dels_.push_back(node);
}
}
else {
BACKUP backup;
NodeEx* child = node->child;
while (child) {
updateState(state, child, backup);
dfs(dfs, depth + 1, child);
revertState(state, child, backup);
child = child->next;
}
}
};
dfs(dfs, startDepth, startNode);
if (isEnd()) {
break;
}
if (targets_.size() > targetWidth) {
nth_element(targets_.begin(), targets_.begin() + targetWidth, targets_.end(), [&](NodeEx* a, NodeEx* b) {
return a->evalScore > b->evalScore;
});
FOR(i, targetWidth, targets_.size()) {
ReleaseNode(targets_[i]);
}
}
else {
}
for (NodeEx* d : dels_) {
ReleaseNode(d);
}
dels_.clear();
targets_.clear();
BACKUP backup;
while (startNode->child && startNode->child->next == nullptr) {
updateState(state, startNode->child, backup);
startNode = startNode->child;
++startDepth;
}
}
}
};
template <class ACTION>
struct ActionTree {
vector<pr<int, ACTION>> actions_;
void Init(int reserveSize) {
actions_.clear();
actions_.reserve(reserveSize);
}
int Push(int parent, const ACTION& action) {
int newIdx = (int)actions_.size();
actions_.emplace_back();
auto& a = actions_.back();
a.a = parent;
a.b = action;
return newIdx;
}
void GetActionList(int actionIdx, vector<ACTION>& dst) {
dst.clear();
int ai = actionIdx;
while (ai >= 0) {
dst.emplace_back(actions_[ai].b);
ai = actions_[ai].a;
}
reverse(ALL(dst));
}
};
inline int popcount(uint64_t bit) {
#if _MSC_VER
return (int)__popcnt64(bit);
#else
return __builtin_popcountll(bit);
#endif
}
int msb(uint64_t v) {
if (v == 0) return false;
v |= (v >> 1);
v |= (v >> 2);
v |= (v >> 4);
v |= (v >> 8);
v |= (v >> 16);
v |= (v >> 32);
return popcount(v) - 1;
}
inline uint64_t RotateLeft(uint64_t bit, uint64_t shift) {
return (bit << shift) | (bit >> (64ULL - shift));
}
inline uint64_t RotateRight(uint64_t bit, uint64_t shift) {
return (bit >> shift) | (bit << (64ULL - shift));
}
#if _MSC_VER
#include <intrin.h>
#endif
inline int FindBitRL(uint64_t bit) {
if (bit == 0) {
return -1;
}
#if _MSC_VER
unsigned long index = 0;
_BitScanForward64(&index, bit);
return (int)index;
#else
return __builtin_ctzll(bit);
#endif
}
inline int FindBitLR(uint64_t bit) {
if (bit == 0) {
return -1;
}
#if _MSC_VER
unsigned long index = 0;
_BitScanReverse64(&index, bit);
return 63 - (int)index;
#else
return __builtin_clzll(bit);
#endif
}
template <class K, class V>
struct CapHashMap {
size_t m_capacity = 0;
K* m_keys = nullptr;
V* m_values = nullptr;
uint8_t* m_states = nullptr;
size_t m_mask = 0;
int m_count = 0;
void init(size_t capacity) {
if (capacity <= m_capacity) {
clear();
return;
}
free(m_keys);
free(m_values);
free(m_states);
m_capacity = 1ULL << (msb(capacity - 1) + 1);
m_mask = m_capacity - 1;
m_keys = (K*)malloc(m_capacity * sizeof(K));
m_values = (V*)malloc(m_capacity * sizeof(V));
m_states = (uint8_t*)calloc(m_capacity, sizeof(uint8_t));
m_count = 0;
}
void clear() {
memset(m_states, 0, m_capacity * sizeof(uint8_t));
m_count = 0;
}
inline void set(K key, const V& v) {
VASSERT(m_count < m_capacity);
size_t i = key & m_mask;
REP(loop, m_capacity) {
if (m_states[i]) {
if (key == m_keys[i]) {
m_values[i] = v;
break;
}
}
else {
m_states[i] = 1;
m_keys[i] = key;
m_values[i] = v;
++m_count;
break;
}
(++i) &= m_mask;
}
}
inline V* try_get(K key) {
size_t i = key & m_mask;
REP(loop, m_capacity) {
if (m_states[i]) {
if (key == m_keys[i]) {
return &m_values[i];
}
}
else {
break;
}
(++i) &= m_mask;
}
return nullptr;
}
bool contains(K key) const {
size_t i = key & m_mask;
REP(loop, m_capacity) {
if (m_states[i]) {
if (key == m_keys[i]) {
return true;
}
}
else {
break;
}
(++i) &= m_mask;
}
return false;
}
V& operator[](K key) {
auto* p = try_get(key);
if (p) {
return *p;
}
set(key, {});
return *try_get(key);
}
int size() const {
return m_count;
}
int capacity() const {
return (int)m_capacity;
}
bool Direct(int i, K& k, V& v) const {
if (m_states[i]) {
k = m_keys[i];
v = m_values[i];
return true;
}
return false;
}
inline double GetUseRate() const {
return m_count / (double)m_capacity;
}
};
template <class K, class V>
struct CapHashMapD {
unique_ptr<CapHashMap<K, V>> org_ = make_unique<CapHashMap<K, V>>();
CapHashMapD() {}
CapHashMapD(const CapHashMapD& r) {
*org_ = *r.org_;
}
void rehash() {
double r = org_->size() / (double)org_->capacity();
if (r > 0.5) {
auto newOrg = make_unique<CapHashMap<K, V>>();
newOrg->init(org_->capacity() << 1);
K k;
V v;
REP(i, org_->capacity()) {
if (org_->Direct(i, k, v)) {
newOrg->set(k, v);
}
}
org_ = move(newOrg);
}
}
int size() const {
return org_->size();
}
void init(size_t capacity) {
org_->init(capacity);
}
void clear() {
org_->clear();
}
void set(const K& key, const V& v) {
org_->set(key, v);
rehash();
}
V* try_get(const K& key) const {
return org_->try_get(key);
}
V& operator[](const K& key) {
auto* p = try_get(key);
if (p) {
return *p;
}
set(key, {});
return *try_get(key);
}
int capacity() const {
return org_->capacity();
}
bool Direct(int i, K& k, V& v) const {
return org_->Direct(i, k, v);
}
bool enter_first(const K& key) {
if (try_get(key)) {
return false;
}
set(key, 1);
return true;
}
};
namespace sa {
namespace greedy {
struct State {
vector<int> numToPos_;
vector<int> A_;
array<int, 2> firstPos_;
array<int, 2> pos_;
int turn_;
void Init() {
A_ = server.A;
firstPos_[0] = -1;
firstPos_[1] = -1;
pos_[0] = -1;
pos_[1] = -1;
turn_ = 0;
numToPos_ = server.numToPos;
}
void Move(const array<int, 2>& pos) {
if (firstPos_[0] < 0) {
firstPos_ = pos;
pos_ = pos;
}
else {
turn_ += CalcMoveDist(pos_, pos);
pos_ = pos;
}
::swap(A_[pos_[0]], A_[pos_[1]]);
REP(i, 2) {
numToPos_[A_[pos_[i]]] = pos_[i];
}
}
void Move(const array<int, 2>& pos, IOResult& result) {
if (firstPos_[0] < 0) {
firstPos_ = pos;
pos_ = pos;
result.firstA_ = pos[0];
result.firstB_ = pos[1];
}
else {
array<vector<int>, 2> routes;
REP(i, 2) {
dister_.GetRoute(pos_[i], pos[i], routes[i]);
}
int moveTurn = (int)max(routes[0].size(), routes[1].size());
REP(t, moveTurn) {
REP(i, 2) {
if (t >= routes[i].size()) {
continue;
}
int next = routes[i][t];
Dir dir = gs.CalcDir1(pos_[i], next);
pos_[i] = next;
if (turn_ >= result.commands_.size()) {
result.commands_.resize(turn_ + 1);
}
result.commands_[turn_].SetDir(i, dir);
}
++turn_;
}
}
if (turn_ >= result.commands_.size()) {
result.commands_.resize(turn_ + 1);
}
result.commands_[turn_].swap = true;
::swap(A_[pos_[0]], A_[pos_[1]]);
REP(i, 2) {
numToPos_[A_[pos_[i]]] = pos_[i];
}
}
};
void Greedy(vector<int>& route) {
route.clear();
static State state;
state.Init();
vector<bool> completed(NN);
while (true) {
int bestFrom = -1;
int bestTo = -1;
int bestFlip = -1;
double bestScore = -1e100;
REP(num, NN) {
int from = state.numToPos_[num];
int to = target_.numToPos_[num];
if (from == to) {
continue;
}
int minDist = INT_MAX;
int minFlip = 0;
REP(i, 2) {
int d = 0;
if (state.pos_[i] >= 0) {
d = max(dister_.GetDist(state.pos_[i], from), dister_.GetDist(state.pos_[1 - i], to));
}
if (d < minDist) {
minDist = d;
minFlip = i;
}
}
double score = -minDist;
if (score > bestScore) {
bestScore = score;
bestFrom = from;
bestTo = to;
bestFlip = minFlip;
}
}
if (bestFrom < 0) {
break;
}
array<int, 2> pos = { bestFrom, bestTo };
if (bestFlip) {
swap(pos[0], pos[1]);
}
state.Move(pos);
route.emplace_back(bestTo);
completed[bestTo] = true;
}
REP(i, NN) {
if (!completed[i]) {
route.emplace_back(i);
}
}
}
}
namespace beam {
using Action = int;
ActionTree<Action> actionTree_;
vector<u64> completeCellHashs_;
vector<u64> possHashs_;
struct Backup {
array<int, 2> pos_;
int turn_;
u64 hash_;
};
struct State {
vector<int> A_;
vector<int> numToPos_;
array<int, 2> pos_;
int turn_;
u64 hash_;
void Init() {
A_ = server.A;
numToPos_ = server.numToPos;
pos_[0] = -1;
pos_[1] = -1;
turn_ = 0;
hash_ = 0;
}
void Move(int to, Backup& backup) {
int num = target_.A_[to];
int from = numToPos_[num];
VASSERT(from != to);
backup.pos_ = pos_;
backup.turn_ = turn_;
backup.hash_ = hash_;
if (pos_[0] >= 0) {
turn_ += CalcMoveDist(pos_, { from, to });
hash_ ^= possHashs_[pos_[0]];
hash_ ^= possHashs_[pos_[1]];
}
pos_ = { from, to };
hash_ ^= possHashs_[from];
hash_ ^= possHashs_[to];
hash_ ^= completeCellHashs_[to];
swap(A_[from], A_[to]);
numToPos_[A_[from]] = from;
numToPos_[A_[to]] = to;
}
void Revert(const Backup& backup) {
swap(A_[pos_[0]], A_[pos_[1]]);
numToPos_[A_[pos_[0]]] = pos_[0];
numToPos_[A_[pos_[1]]] = pos_[1];
pos_ = backup.pos_;
turn_ = backup.turn_;
hash_ = backup.hash_;
}
};
constexpr int StateSize = sizeof(State);
struct Node {
int to;
int ai;
};
constexpr int NodeSize = sizeof(Node);
struct Solver {
DiffBeam<Node, State, Backup> beam_;
void Run(vector<int>& route) {
actionTree_.Init(1000 * 1000);
completeCellHashs_.resize(NN);
possHashs_.resize(NN);
REP(i, NN) {
completeCellHashs_[i] = rand_.Get64();
possHashs_[i] = rand_.Get64();
}
int ExpandCountMax = HP.BeamCandidate;
int TurnMax = NN;
int widthLimit = HP.BeamWidth;
beam_.Initialize(widthLimit, ExpandCountMax, TurnMax);
auto initRoot = [&](State& state, Node* node) {
state.Init();
node->to = -1;
node->ai = -1;
};
int bestTurn = INT_MAX;
int bestAi = -1;
CapHashMapD<u64, int> hashMap;
hashMap.init(ExpandCountMax * widthLimit);
auto makeNextNodes = [&](int depth, Node* node, State& state, vector<pr<Node*, double>>& nexts) {
static Backup backup;
static vector<pr<int, int>> candidates;
candidates.clear();
bool hasNext = false;
if (state.pos_[0] < 0) {
REP(to, NN) {
if (state.A_[to] == target_.A_[to]) {
continue;
}
state.Move(to, backup);
int diff = -abs(state.A_[to] - target_.A_[to]);
state.Revert(backup);
candidates.emplace_back(pint{ diff, to });
hasNext = true;
}
}
else {
REP(to, NN) {
if (state.A_[to] == target_.A_[to]) {
continue;
}
state.Move(to, backup);
int turn = state.turn_;
u64 hash = state.hash_;
state.Revert(backup);
hasNext = true;
if (int* hashTurn = hashMap.try_get(hash)) {
if (turn >= *hashTurn) {
continue;
}
}
hashMap.set(hash, turn);
candidates.emplace_back(pint{turn, to});
}
}
if (!hasNext) {
if (state.turn_ < bestTurn) {
bestTurn = state.turn_;
bestAi = node->ai;
}
}
else {
sort(ALL(candidates));
REP(i, min((int)candidates.size(), depth == 0 ? widthLimit : ExpandCountMax)) {
double evalScore = -candidates[i].a;
Node* nextNode = beam_.New();
nextNode->to = candidates[i].b;
nextNode->ai = actionTree_.Push(node->ai, candidates[i].b);
nexts.push_back(pr<Node*, double>{ nextNode, evalScore });
}
}
};
auto updateState = [&](State& state, const Node* nextNode, Backup& backup) {
state.Move(nextNode->to, backup);
};
auto revertState = [&](State& state, const Node* nextNode, const Backup& backup) {
state.Revert(backup);
};
auto calcWidth = [&](int turn, int makeNextCount) {
hashMap.clear();
return widthLimit;
};
auto IsEnd = [&]() {
return timer_.IsOver();
};
beam_.Run(TurnMax, initRoot, makeNextNodes, updateState, revertState, calcWidth, IsEnd, 0);
if (bestAi < 0) {
route.resize(NN);
iota(ALL(route), 0);
}
else {
vector<Action> actions;
actionTree_.GetActionList(bestAi, actions);
vector<bool> used(NN, false);
route.clear();
route.reserve(actions.size());
REP(i, actions.size()) {
route.emplace_back(actions[i]);
used[actions[i]] = true;
}
REP(i, NN) {
if (!used[i]) {
route.emplace_back(i);
}
}
}
}
};
}
int CalcTurn(const vector<int>& route) {
static vector<int> numToPos_;
static vector<int> A_;
int prevFrom = -1;
int prevTo = -1;
int turn_ = 0;
A_ = server.A;
numToPos_ = server.numToPos;
REP(i, route.size()) {
int to = route[i];
int num = target_.A_[to];
int from = numToPos_[num];
if (from == to) {
continue;
}
if (prevFrom >= 0) {
int cost = min(max(dister_.GetDist(prevFrom, from), dister_.GetDist(prevTo, to)), max(dister_.GetDist(prevTo, from), dister_.GetDist(prevFrom, to)));
turn_ += cost;
}
prevFrom = from;
prevTo = to;
numToPos_[A_[from] = A_[to]] = from;
}
return turn_;
}
int CalcTurn(const vector<int>& route, IOResult& result) {
static greedy::State state;
state.Init();
result.Init();
REP(i, route.size()) {
int to = route[i];
int num = target_.A_[to];
int from = state.numToPos_[num];
if (from == to) {
continue;
}
array<int, 2> pos = { from, to };
if (state.pos_[0] >= 0) {
int base = max(dister_.GetDist(state.pos_[0], from), dister_.GetDist(state.pos_[1], to));
int flip = max(dister_.GetDist(state.pos_[1], from), dister_.GetDist(state.pos_[0], to));
if (base > flip) {
swap(pos[0], pos[1]);
}
}
state.Move(pos, result);
}
return state.turn_;
}
struct Backup {
vector<int> route_;
int turn_;
};
struct State {
vector<int> route_;
int turn_;
struct Cache {
u32 hash;
int cost;
};
vector<Cache> caches_;
double EvalScore() const {
return -turn_ * 1000 / (double)K;
}
void Init(const vector<int>& route) {
route_ = route;
caches_.assign(NN, Cache{ (u32) - 1});
UpdateTurn();
}
void UpdateTurn() {
static vector<int> numToPos_;
static vector<int> A_;
int prevFrom = -1;
int prevTo = -1;
turn_ = 0;
A_ = server.A;
numToPos_ = server.numToPos;
VASSERT(route_.size() == NN);
REP(i, NN) {
int to = route_[i];
int num = target_.A_[to];
int from = numToPos_[num];
if (from == to) {
continue;
}
if (prevFrom >= 0) {
u32 hash = (from << 20) | (prevFrom << 10) | (prevTo);
auto& cache = caches_[num];
if (hash == cache.hash) {
turn_ += cache.cost;
}
else {
int cost = min(max(dister_.GetDist(prevFrom, from), dister_.GetDist(prevTo, to)), max(dister_.GetDist(prevTo, from), dister_.GetDist(prevFrom, to)));
cache.hash = hash;
cache.cost = cost;
turn_ += cost;
}
}
prevFrom = from;
prevTo = to;
numToPos_[A_[from] = A_[to]] = from;
}
}
void Move(int remove, int insert, Backup& backup) {
backup.route_ = route_;
backup.turn_ = turn_;
int pos = route_[remove];
route_.erase(route_.begin() + remove);
route_.insert(route_.begin() + insert, pos);
UpdateTurn();
}
void Slide(int start, int size, int slide, Backup& backup) {
backup.route_ = route_;
backup.turn_ = turn_;
if (slide < 0) {
VASSERT(start + size <= route_.size());
VASSERT(start + slide >= 0);
memcpy(route_.data() + start + slide, backup.route_.data() + start, sizeof(route_[0]) * size);
memcpy(route_.data() + start + slide + size, backup.route_.data() + start + slide, sizeof(route_[0]) * (-slide));
}
else {
VASSERT(start + size + slide <= route_.size());
memcpy(route_.data() + start + slide, backup.route_.data() + start, sizeof(route_[0]) * size);
memcpy(route_.data() + start, backup.route_.data() + start + size, sizeof(route_[0]) * (slide));
}
UpdateTurn();
}
void Reverse(int a, int b, Backup& backup) {
backup.route_ = route_;
backup.turn_ = turn_;
reverse(route_.begin() + a, route_.begin() + b);
UpdateTurn();
}
void Revert(const Backup& backup) {
route_ = backup.route_;
turn_ = backup.turn_;
}
};
struct Solver {
State bestState_;
void CheckBestScore(const State& state) {
if (state.turn_ < bestState_.turn_) {
bestState_ = state;
}
}
void Run(ChronoTimer& timer) {
dister_.Init();
target_.Init();
vector<int> route;
{
static beam::Solver solver;
solver.Run(route);
}
vector<State> states;
{
states.resize(1);
states[0].Init(route);
}
bestState_ = states[0];
SimulatedAnnealing sa;
sa.startTemp_ = HP.StartTemp;
sa.endTemp_ = HP.EndTemp;
sa.stepLoopCount = 100;
sa.tempType_ = HP.TempType;
sa.tempPow_ = HP.TempPow;
auto transitions = make_tuple(
MAKE_TRANS(Transition_Update1, HP.Trans1)
, MAKE_TRANS(Transition_Update2, HP.Trans2)
, MAKE_TRANS(Transition_Update3, HP.Trans3)
);
sa.Run2(timer, states, transitions);
IOResult result;
int turn = CalcTurn(bestState_.route_, result);
server.Output(result);
}
void Transition_Update1(SimulatedAnnealing& sa, SAChecker& checker, State& state) {
int remove = rand_(NN);
int insert = rand_(NN);
static Backup backup;
state.Move(remove, insert, backup);
if (checker(state.EvalScore())) {
CheckBestScore(state);
if (bestState_.turn_ < K) {
sa.ForceEnd();
}
}
else {
state.Revert(backup);
}
}
void Transition_Update2(SimulatedAnnealing& sa, SAChecker& checker, State& state) {
int size = 2 + rand_((int)HP.Trans2_Size);
int start = rand_(NN - size + 1);
static Backup backup;
state.Reverse(start, start + size, backup);
if (checker(state.EvalScore())) {
CheckBestScore(state);
if (bestState_.turn_ < K) {
sa.ForceEnd();
}
}
else {
state.Revert(backup);
}
}
void Transition_Update3(SimulatedAnnealing& sa, SAChecker& checker, State& state) {
int size = 1 + rand_((int)HP.Trans3_Size);
int start = rand_(NN - size + 1);
int leftMax = -start;
int rightMax = NN - (start + size);
int slide = rand_(rightMax - leftMax + 1) + leftMax;
static Backup backup;
state.Slide(start, size, slide, backup);
if (checker(state.EvalScore())) {
CheckBestScore(state);
if (bestState_.turn_ < K) {
sa.ForceEnd();
}
}
else {
state.Revert(backup);
}
}
};
}
struct ChoiceTable {
private:
vector<int> table_;
int m_ = 0;
public:
void Init(int n) {
table_.resize(n);
iota(table_.begin(), table_.end(), 0);
m_ = 0;
}
void Choice(int m, Xor64& rand) {
VASSERT(m <= (int)table_.size());
REP(i, m) {
swap(table_[i], table_[i + rand(table_.size() - i)]);
}
m_ = m;
}
using iterator = vector<int>::iterator;
using const_iterator = vector<int>::const_iterator;
inline const_iterator begin() const {
return table_.begin();
}
inline const_iterator end() const {
return table_.begin() + m_;
}
inline iterator begin() {
return table_.begin();
}
inline iterator end() {
return table_.begin() + m_;
}
inline int operator [](int index) const {
return table_[index];
}
};
template <int CAP>
struct ChoiceTableS {
private:
CapArr<int, CAP> table_;
int m_ = 0;
public:
bool IsEmpty() const {
return table_.empty();
}
void Init(int n) {
table_.resize(n);
iota(table_.begin(), table_.end(), 0);
m_ = 0;
}
void Choice(int m, Xor64& rand) {
VASSERT(m <= (int)table_.size());
REP(i, m) {
swap(table_[i], table_[i + (int)rand(table_.size() - i)]);
}
m_ = m;
}
using iterator = vector<int>::iterator;
using const_iterator = vector<int>::const_iterator;
inline const_iterator begin() const {
return table_.begin();
}
inline const_iterator end() const {
return table_.begin() + m_;
}
inline iterator begin() {
return table_.begin();
}
inline iterator end() {
return table_.begin() + m_;
}
inline int operator [](int index) const {
return table_[index];
}
};
struct TSP {
struct State {
vector<int> ps;
int cost;
};
template <class CostFunc>
void Solve(const vector<int>& ps, vector<int>& dst, int iterCount, CostFunc&& costFunc) {
State state;
state.cost = 0;
state.ps = ps;
REP(i, ps.size() - 1) {
state.cost += costFunc(state.ps[i], state.ps[i + 1]);
}
while (Opt2(state, costFunc)) {}
REP(i, iterCount) {
State newState;
newState = state;
Kick(newState, costFunc);
while (Opt2(state, costFunc)) {}
if (newState.cost < state.cost) {
state = newState;
}
}
dst = state.ps;
}
template <class CostFunc>
bool Opt2(State& state, CostFunc&& costFunc) {
bool updated = false;
auto& ps = state.ps;
REP(a, ps.size() - 1) {
int b = a + 1;
FOR(c, b + 1, ps.size() - 1) {
int d = c + 1;
int newCost = state.cost - costFunc(ps[a], ps[b]) - costFunc(ps[c], ps[d]) + costFunc(ps[a], ps[c]) + costFunc(ps[b], ps[d]);
if (newCost < state.cost) {
state.cost = newCost;
reverse(ps.begin() + b, ps.begin() + d);
updated = true;
}
}
}
return updated;
}
template <class CostFunc>
void Kick(State& state, CostFunc&& costFunc) {
if (state.ps.size() <= 4) {
return;
}
static ChoiceTable tbl;
auto& ps = state.ps;
tbl.Init((int)ps.size() - 1);
tbl.Choice(4, rand_);
sort(ALL(tbl));
const auto& ct = tbl;
int a = ps[ct[0]];
int b = ps[ct[0] + 1];
int c = ps[ct[1]];
int d = ps[ct[1] + 1];
int e = ps[ct[2]];
int f = ps[ct[2] + 1];
int g = ps[ct[3]];
int h = ps[ct[3] + 1];
int before = costFunc(a, b) + costFunc(c, d) + costFunc(e, f) + costFunc(g, h);
int after = costFunc(a, f) + costFunc(g, d) + costFunc(e, b) + costFunc(c, h);
int newCost = state.cost - before + after;
state.cost = newCost;
auto src = state.ps;
auto& dst = state.ps;
constexpr int es = sizeof(*dst.data());
int offset = ct[0] + 1;
auto Append = [&](int s, int e) {
int size = ct[e] - ct[s];
memcpy(dst.data() + offset, src.data() + ct[s] + 1, es * size);
offset += size;
};
Append(2, 3);
Append(1, 2);
Append(0, 1);
}
template <class CostFunc>
void Solve(const vector<int>& ps, int start, int end, vector<int>& dst, int iterCount, CostFunc&& costFunc) {
State state;
state.cost = 0;
state.ps = ps;
REP(i, ps.size() - 1) {
state.cost += costFunc(state.ps[i], state.ps[i + 1]);
}
State bestState;
bestState.cost = INT_MAX;
REP(i, iterCount) {
while (Opt2(state, start, end, costFunc)) {
}
if (state.cost < bestState.cost) {
bestState = state;
}
if (i + 1 < iterCount) {
Kick(state, start, end, costFunc);
}
}
dst = bestState.ps;
}
template <class CostFunc>
bool Opt2(State& state, int start, int end, CostFunc&& costFunc) {
bool updated = false;
auto& ps = state.ps;
FOR(l, start, end) {
FOR(r, l + 2, end + 1) {
int a = l - 1;
int b = l;
int c = r - 1;
int d = r;
int newCost = state.cost;
if (a >= 0) {
newCost += -costFunc(ps[a], ps[b]) + costFunc(ps[a], ps[c]);
}
if (d < state.ps.size()) {
newCost += -costFunc(ps[c], ps[d]) + costFunc(ps[b], ps[d]);
}
if (newCost < state.cost) {
state.cost = newCost;
reverse(ps.begin() + b, ps.begin() + d);
updated = true;
}
}
}
return updated;
}
};
struct TSP2 {
struct State {
vector<int> route;
vector<int> order;
int dist;
};
static constexpr int StateSize = sizeof(State);
Xor64 rand_;
ChoiceTable choiceTable_;
vector<vector<int>> sortedTable_;
vector<vector<int>> dists_;
int N_;
template <class CostFunc>
void Solve(int start, const vector<int>& srcPs, int end, vector<int>& result, int iter, bool greedy, CostFunc&& costFunc) {
VASSERT(start >= 0);
VASSERT(end >= 0);
vector<int> pToSrcIdx;
{
if (start >= 0) {
pToSrcIdx.emplace_back(-1);
}
REP(i, srcPs.size()) {
pToSrcIdx.emplace_back(i);
}
if (end >= 0) {
pToSrcIdx.emplace_back(-2);
}
}
auto PToSrcP = [&](int p) {
int idx = pToSrcIdx[p];
if (idx < 0) {
if (idx == -1) {
return start;
}
else {
return end;
}
}
else {
return srcPs[idx];
}
};
N_ = (int)pToSrcIdx.size();
dists_.resize(N_);
REP(a, N_) {
dists_[a].resize(N_);
}
REP(a, N_) {
dists_[a][a] = 0;
FOR(b, a + 1, N_) {
dists_[a][b] = dists_[b][a] = costFunc(PToSrcP(a), PToSrcP(b));
}
}
choiceTable_.Init(N_ - 1);
sortedTable_.resize(N_);
REP(i, N_) {
sortedTable_[i].clear();
sortedTable_[i].reserve(N_ - 1);
REP(j, N_) {
if (i == j) {
continue;
}
sortedTable_[i].emplace_back(j);
}
cauto& dists = dists_[i];
sort(ALL(sortedTable_[i]), [&](int a, int b) {
return dists[a] < dists[b];
});
}
State state;
InitState(N_, greedy, state);
LocalSearch2opt(state);
REP(i, iter) {
UpdateState(state);
}
result.clear();
for (int p : state.route) {
int idx = pToSrcIdx[p];
if (idx < 0) {
}
else {
result.emplace_back(srcPs[idx]);
}
}
}
void InitState(int N_, bool greedy, State& state) {
if (greedy) {
state.route.resize(N_);
state.order.assign(N_, -1);
state.route[0] = 0;
state.order[0] = 0;
int last = 0;
FOR(r, 1, N_) {
for (int v : sortedTable_[last]) {
if (state.order[v] >= 0) {
continue;
}
state.route[r] = v;
state.order[v] = r;
last = v;
break;
}
}
}
else {
state.route.resize(N_);
state.order.resize(N_);
REP(i, N_) {
state.route[i] = i;
state.order[i] = i;
}
}
state.dist = CalcDist(state.route);
}
void UpdateState(State& state) {
State backupState = state;
Kick(state);
LocalSearch2opt(state);
if (backupState.dist < state.dist) {
state = backupState;
}
}
void LocalSearch2opt(State& state) {
auto Update = [&](int iA, int iC) {
int iB = iA + 1;
int iD = iC + 1;
if (iD >= N_) {
return false;
}
int A = state.route[iA];
int B = state.route[iB];
int C = state.route[iC];
int D = state.route[iD];
if (B == C || A == D || B == D) {
return false;
}
int newDist = state.dist - dists_[A][B] - dists_[C][D] + dists_[A][C] + dists_[B][D];
if (newDist < state.dist) {
state.dist = newDist;
if (iB > iD) {
swap(iB, iD);
}
reverse(state.route.begin() + iB, state.route.begin() + iD);
FOR(i, iB, iD) {
state.order[state.route[i]] = i;
}
return true;
}
return false;
};
while (true) {
bool update = false;
REP(iA, N_ - 1) {
int iB = iA + 1;
for (int C : sortedTable_[state.route[iA]]) {
int iC = state.order[C];
if (iC == iB) {
break;
}
if (Update(iA, iC)) {
update = true;
break;
}
}
if (update) {
break;
}
for (int D : sortedTable_[state.route[iB]]) {
int iD = state.order[D];
if (iD == iA) {
break;
}
if (iD == 0) {
continue;
}
int iC = iD - 1;
if (Update(iA, iC)) {
update = true;
break;
}
}
if (update) {
break;
}
}
if (!update) {
break;
}
}
}
void LocalSearch3opt(State& state) {
const auto& dists = dists_;
auto& route = state.route;
auto Dist = [&](int i, int j) {
return dists[route[i]][route[j]];
};
auto Reverse = [&](int i, int j) {
reverse(route.begin() + i, route.begin() + j);
};
static vector<int> backup;
backup.resize(N_);
auto Opt3 = [&]() {
REP(iA, N_ - 3) {
int iB = iA + 1;
FOR(iC, iA + 1, N_ - 2) {
int iD = iC + 1;
FOR(iE, iC + 1, N_ - 1) {
int iF = iE + 1;
int src = Dist(iA, iB) + Dist(iC, iD) + Dist(iE, iF);
int S0 = Dist(iA, iC) + Dist(iB, iE) + Dist(iD, iF);
int S1 = Dist(iA, iD) + Dist(iE, iB) + Dist(iC, iF);
int S2 = Dist(iA, iD) + Dist(iE, iC) + Dist(iB, iF);
int S3 = Dist(iA, iE) + Dist(iD, iB) + Dist(iC, iF);
int S4 = Dist(iA, iC) + Dist(iB, iD) + Dist(iE, iF);
int S5 = Dist(iA, iE) + Dist(iB, iF) + Dist(iC, iD);
int S6 = Dist(iC, iE) + Dist(iD, iF) + Dist(iA, iB);
int minValue = S0;
chmin(minValue, S1);
chmin(minValue, S2);
chmin(minValue, S3);
chmin(minValue, S4);
chmin(minValue, S5);
chmin(minValue, S6);
if (minValue >= src) {
continue;
}
if (minValue == S0) {
Reverse(iB, iD);
Reverse(iD, iF);
}
else if (minValue == S1) {
memcpy(backup.data() + iB, route.data() + iB, iD - iB);
memmove(route.data() + iB, route.data() + iD, iF - iD);
memcpy(route.data() + iB + iF - iD, backup.data() + iB, iD - iB);
}
else if (minValue == S2) {
memcpy(backup.data() + iB, route.data() + iB, iD - iB);
memmove(route.data() + iB, route.data() + iD, iF - iD);
reverse_copy(backup.data() + iB, backup.data() + iD, route.data() + iB + iF - iD);
}
else if (minValue == S3) {
memcpy(backup.data() + iB, route.data() + iB, iF - iB);
reverse_copy(backup.data() + iD, backup.data() + iF, route.data() + iB);
memcpy(route.data() + iB + iF - iD, backup.data() + iB, iD - iB);
}
else if (minValue == S4) {
Reverse(iB, iD);
}
else if (minValue == S5) {
Reverse(iB, iF);
}
else {
VASSERT(minValue == S6);
Reverse(iD, iF);
}
state.dist -= src;
state.dist += minValue;
FOR(i, iB, iF) {
state.order[state.route[i]] = i;
}
}
}
}
return false;
};
while (Opt3()) {
}
}
void Kick(State& state) {
if (N_ <= 4) {
return;
}
choiceTable_.Choice(4, rand_);
sort(ALL(choiceTable_));
const auto& ct = choiceTable_;
int a = state.route[ct[0]];
int b = state.route[ct[0] + 1];
int c = state.route[ct[1]];
int d = state.route[ct[1] + 1];
int e = state.route[ct[2]];
int f = state.route[ct[2] + 1];
int g = state.route[ct[3]];
int h = state.route[ct[3] + 1];
auto CalcCost = [&](int from, int to) {
return dists_[from][to];
};
int before = CalcCost(a, b) + CalcCost(c, d) + CalcCost(e, f) + CalcCost(g, h);
int after = CalcCost(a, f) + CalcCost(g, d) + CalcCost(e, b) + CalcCost(c, h);
int newDist = state.dist - before + after;
state.dist = newDist;
auto src = state.route;
auto& dst = state.route;
constexpr int es = sizeof(*dst.data());
int offset = ct[0] + 1;
auto Append = [&](int s, int e) {
int size = ct[e] - ct[s];
memcpy(dst.data() + offset, src.data() + ct[s] + 1, es * size);
offset += size;
};
Append(2, 3);
Append(1, 2);
Append(0, 1);
FOR(i, ct[0], N_) {
state.order[state.route[i]] = i;
}
}
int CalcDist(const vector<int>& route) {
int dist = 0;
REP(i, N_ - 1) {
int from = route[i];
int to = route[i + 1];
dist += dists_[from][to];
}
return dist;
}
};
namespace common_sa {
namespace greedy {
struct State {
array<int, 2> pos_;
int turn_;
void Init() {
pos_[0] = -1;
pos_[1] = -1;
turn_ = 0;
}
void Move(const array<int, 2>& pos, IOResult& result) {
if (pos_[0] < 0) {
pos_ = pos;
result.firstA_ = pos[0];
result.firstB_ = pos[1];
}
else {
array<vector<int>, 2> routes;
REP(i, 2) {
dister_.GetRoute(pos_[i], pos[i], routes[i]);
}
int moveTurn = (int)max(routes[0].size(), routes[1].size());
REP(t, moveTurn) {
REP(i, 2) {
if (t >= routes[i].size()) {
continue;
}
int next = routes[i][t];
Dir dir = gs.CalcDir1(pos_[i], next);
pos_[i] = next;
if (turn_ >= result.commands_.size()) {
result.commands_.resize(turn_ + 1);
}
result.commands_[turn_].SetDir(i, dir);
}
++turn_;
}
}
if (turn_ >= result.commands_.size()) {
result.commands_.resize(turn_ + 1);
}
result.commands_[turn_].swap = true;
}
};
int CalcTurn(const vector<array<int, 2>>& route, IOResult& result) {
static greedy::State state;
state.Init();
result.Init();
REP(i, route.size()) {
int to = route[i][0];
int from = route[i][1];
if (from == to) {
continue;
}
array<int, 2> pos = { from, to };
if (state.pos_[0] >= 0) {
int base = max(dister_.GetDist(state.pos_[0], from), dister_.GetDist(state.pos_[1], to));
int flip = max(dister_.GetDist(state.pos_[1], from), dister_.GetDist(state.pos_[0], to));
if (base > flip) {
swap(pos[0], pos[1]);
}
}
state.Move(pos, result);
}
return state.turn_;
}
}
struct NumRange {
int lower_;
int upper_;
};
void CalcRoute(int start, const vector<int>& srcPs, int end, vector<int>& route) {
auto costFunc = [&](int a, int b) {
return dister_.GetDist(a, b);
};
int iterCount = 0;
bool greedy = false;
if (patternT == 7) {
iterCount = 0;
}
else if (patternT == 14) {
iterCount = 0;
}
else if (patternT == 15) {
iterCount = 0;
}
else if (patternT == 17) {
iterCount = 0;
}
else if (patternT == 19) {
iterCount = 0;
greedy = true;
}
else if (patternT == 10) {
iterCount = 1000;
greedy = true;
}
else if (patternT == 11) {
iterCount = 1000;
}
else if (patternT == 12) {
iterCount = 3000;
}
else if (patternT == 13) {
iterCount = 3000;
}
else if (patternT == 16) {
iterCount = 300;
greedy = true;
}
else if (patternT == 18) {
iterCount = 200;
greedy = true;
}
else {
VABORT();
}
if (iterCount > 0 || patternT == 19) {
static TSP2 tsp;
tsp.Solve(start, srcPs, end, route, iterCount, greedy, costFunc);
}
else {
static TSP tsp;
static vector<int> ps;
ps.clear();
{
ps.emplace_back(start);
for (int p : srcPs) {
ps.emplace_back(p);
}
ps.emplace_back(end);
}
static vector<int> result;
tsp.Solve(ps, result, iterCount, costFunc);
route.clear();
FOR(i, 1, result.size() - 1) {
route.emplace_back(result[i]);
}
}
}
void CalcAreaRoute(const vector<vector<int>>& targetAreas, const vector<int>& A, const array<int, 2>& lastSwapPos, const vector<vector<int>>& nextAreas, array<vector<int>, 2>& routes, array<vector<int>, 2>& noRouteCells_) {
static array<vector<int>, 2> ngCells;
REP(pi, 2) {
ngCells[pi].clear();
noRouteCells_[pi].clear();
static vector<bool> require;
require.assign(NN, false);
for (int p : targetAreas[pi]) {
require[target_.A_[p]] = true;
}
for (int p : targetAreas[pi]) {
if (!require[A[p]]) {
ngCells[pi].emplace_back(p);
}
else {
noRouteCells_[pi].emplace_back(p);
}
}
}
VASSERT(ngCells[0].size() == ngCells[1].size());
if (ngCells[0].empty()) {
routes = ngCells;
return;
}
static queue<int> que;
static vector<int> dists;
REP(pi, 2) {
int start = lastSwapPos[pi];
if (start < 0) {
if (patternT == 14 || patternT == 17 || patternT == 18) {
dists.assign(NN, -1);
for (int p : nextAreas[pi]) {
que.push(p);
dists[p] = 0;
}
int lastP = -1;
while (!que.empty()) {
int p = que.front();
lastP = p;
que.pop();
for (int n : aroundMap[p]) {
if (dists[n] >= 0) {
continue;
}
dists[n] = dists[p] + 1;
que.push(n);
}
}
start = lastP;
}
else {
auto& cells = ngCells[pi];
start = cells[0];
}
}
int end = -1;
if (patternT == 12) {
if (nextAreas.empty()) {
int startV = target_.A_[start];
int maxDiff = 0;
for (int p : ngCells[pi]) {
int diff = abs(startV - target_.A_[p]);
if (diff > maxDiff) {
maxDiff = diff;
end = p;
}
}
}
else {
dists.assign(NN, -1);
for (int p : nextAreas[pi]) {
que.push(p);
dists[p] = 0;
}
int lastP = -1;
while (!que.empty()) {
int p = que.front();
lastP = p;
que.pop();
for (int n : aroundMap[p]) {
if (dists[n] >= 0) {
continue;
}
dists[n] = dists[p] + 1;
que.push(n);
}
}
end = ngCells[pi][0];
for (int p : ngCells[pi]) {
if (dists[p] < dists[end]) {
end = p;
}
}
}
}
else {
int startV = target_.A_[start];
int maxDiff = 0;
for (int p : ngCells[pi]) {
int diff = abs(startV - target_.A_[p]);
if (diff > maxDiff) {
maxDiff = diff;
end = p;
}
}
}
CalcRoute(start, ngCells[pi], end, routes[pi]);
}
}
void MakeTargetRoute(vector<vector<vector<int>>>& targetRoute) {
targetRoute = targetRoutes_[patternT];
int maxDepth = -1;
if (targetRoute.empty()) {
vector<common_sa::NumRange> allRanges;
if (patternT == 15) {
vector<int> ais;
ais.emplace_back(0);
ais.emplace_back(2);
ais.emplace_back(4);
ais.emplace_back(6);
ais.emplace_back(5);
ais.emplace_back(3);
ais.emplace_back(12);
ais.emplace_back(11);
ais.emplace_back(1);
ais.emplace_back(17);
ais.emplace_back(19);
ais.emplace_back(20);
ais.emplace_back(18);
ais.emplace_back(26);
ais.emplace_back(25);
ais.emplace_back(24);
vector<common_sa::NumRange> areas(1);
areas[0] = { 0, NN };
for (int ai : ais) {
auto area = areas[ai];
int mid = area.lower_ + (area.upper_ - area.lower_) / 2;
areas.push_back(common_sa::NumRange{ mid, area.upper_ });
areas.push_back(common_sa::NumRange{ area.lower_, mid });
}
for (int ai : ais) {
allRanges.emplace_back(areas[ai]);
}
}
else {
if (patternT == 7) {
maxDepth = 3;
}
else if (patternT == 10) {
maxDepth = 5;
}
else if (patternT == 11) {
maxDepth = 5;
}
else if (patternT == 12) {
maxDepth = 6;
}
else if (patternT == 13) {
maxDepth = 4;
}
else if (patternT == 14) {
maxDepth = 3;
}
else if (patternT == 16) {
maxDepth = 5;
}
else if (patternT == 17) {
maxDepth = 3;
}
else if (patternT == 18) {
maxDepth = 5;
}
else if (patternT == 19) {
maxDepth = 6;
}
else {
VABORT();
}
vector<int> range = { 0, NN };
allRanges.push_back(common_sa::NumRange{ 0, NN });
bool rev = true;
REP(depth, maxDepth) {
vector<int> nextRange;
REP(i, range.size() - 1) {
nextRange.push_back(range[i]);
nextRange.push_back(range[i] + (range[i + 1] - range[i]) / 2);
}
nextRange.push_back(range[range.size() - 1]);
range = move(nextRange);
rev = !rev;
if (rev) {
RREP(i, range.size() - 1) {
allRanges.push_back(common_sa::NumRange{ range[i], range[i + 1] });
}
}
else {
REP(i, range.size() - 1) {
allRanges.push_back(common_sa::NumRange{ range[i], range[i + 1] });
}
}
}
}
targetRoute.resize(allRanges.size());
REP(ai, allRanges.size()) {
cauto& range = allRanges[ai];
auto& route = targetRoute[ai];
route.resize(2);
int mid = range.lower_ + (range.upper_ - range.lower_) / 2;
REP(i, NN) {
int tn = target_.orgA_[i];
if (tn < range.lower_ || tn >= range.upper_) {
continue;
}
if (tn < mid) {
route[0].emplace_back(i);
}
else {
route[1].emplace_back(i);
}
}
}
if (patternT >= 12) {
if (patternT == 16 || patternT == 17) {
for (auto& route : targetRoute) {
REP(pi, 2) {
int baseP;
if (pi == 1) {
baseP = target_.numToPos_[NN - 1];
if (target_.flip_) {
baseP = target_.numToPos_[0];
}
}
else {
baseP = target_.numToPos_[0];
if (target_.flip_) {
baseP = target_.numToPos_[NN - 1];
}
}
sort(ALL(route[pi]), [&](int a, int b) {
return dister_.GetDist(baseP, a) < dister_.GetDist(baseP, b);
});
}
}
}
else {
for (auto& route : targetRoute) {
REP(pi, 2) {
int baseP = target_.numToPos_[NN - 1];
if (target_.flip_) {
baseP = target_.numToPos_[0];
}
sort(ALL(route[pi]), [&](int a, int b) {
return dister_.GetDist(baseP, a) < dister_.GetDist(baseP, b);
});
}
}
}
}
}
}
}
namespace route_sa {
struct Area {
array<vector<int>, 2> routes_;
array<vector<int>, 2> noRouteCells_;
int GetRouteSize() const {
return (int)routes_[0].size();
}
array<int, 2> GetRoutePos(int i) const {
return { routes_[0][i], routes_[1][i] };
}
void Swap(vector<int>& A) const {
REP(ri, routes_[0].size()) {
swap(A[routes_[0][ri]], A[routes_[1][ri]]);
}
}
};
vector<vector<vector<int>>> targetAreas_;
vector<array<vector<bool>, 2>> areaNums_;
vector<int> areaRandTbl_;
struct Cache {
u64 hash;
int cost;
};
vector<vector<Cache>> areasCostCaches_;
s64 CalcTotalD(const vector<Area>& areas) {
static vector<int> A;
array<int, 2> prevPos = { -1, -1 };
A = server.A;
int turn_ = 0;
bool end = false;
REP(ai, areas.size()) {
cauto& area = areas[ai];
auto& costCache = areasCostCaches_[ai];
REP(ri, area.GetRouteSize()) {
array<int, 2> pos = area.GetRoutePos(ri);
if (pos[0] == pos[1]) {
continue;
}
if (prevPos[0] >= 0) {
u64 hash = (u64(pos[0]) << 48LL) | (u64(pos[1]) << 32LL) | (prevPos[0] << 16LL) | (prevPos[1]);
int num0 = A[pos[0]];
auto& cache = costCache[num0];
int cost;
if (hash == cache.hash) {
cost = cache.cost;
}
else {
cost = CalcMoveDist(prevPos, pos);
cache.hash = hash;
cache.cost = cost;
}
if (turn_ + cost >= K) {
end = true;
break;
}
turn_ += cost;
}
swap(A[pos[0]], A[pos[1]]);
prevPos = pos;
}
if (end) {
break;
}
}
s64 totalD = 0;
REP(i, NN) {
for (int n : aroundMap.GetAroundRB(i)) {
totalD += square(A[i] - A[n]);
}
}
return totalD;
}
void UpdateRouteS(int targetAi, vector<Area>& areas) {
static vector<int> A;
A = server.A;
REP(ai, targetAi + 1) {
auto& area = areas[ai];
area.Swap(A);
}
FOR(ai, targetAi + 1, areas.size()) {
auto& area = areas[ai];
REP(pi, 2) {
auto& route = area.routes_[pi];
auto& noRouteCells = area.noRouteCells_[pi];
cauto& require = areaNums_[ai][pi];
static vector<int> cells;
cells.clear();
RREP(i, noRouteCells.size()) {
int p = noRouteCells[i];
int num = A[p];
if (!require[num]) {
cells.emplace_back(p);
if (i + 1 < noRouteCells.size()) {
noRouteCells[i] = noRouteCells.back();
}
noRouteCells.pop_back();
}
}
{
static vector<int> ris;
ris.clear();
REP(ri, route.size()) {
int p = route[ri];
int num = A[p];
if (require[num]) {
ris.emplace_back(ri);
}
}
if (!ris.empty()) {
int removedCount = 0;
REP(ri, route.size()) {
if (removedCount < ris.size() && ri == ris[removedCount]) {
++removedCount;
noRouteCells.emplace_back(route[ri]);
}
else {
route[ri - removedCount] = route[ri];
}
}
route.resize(route.size() - ris.size());
}
}
for (int cell : cells) {
int bestRi = -1;
int bestD = INT_MAX;
if (route.size() <= 1) {
bestRi = (int)route.size();
}
else {
FOR(ri, 1, route.size()) {
int prev = route[ri - 1];
int curr = route[ri];
int d = dister_.GetDist(prev, cell) + dister_.GetDist(cell, curr);
if (d < bestD) {
bestD = d;
bestRi = ri;
}
}
}
route.insert(route.begin() + bestRi, cell);
}
}
VASSERT(area.routes_[0].size() == area.routes_[1].size());
area.Swap(A);
}
}
double Eval(s64 totalD) {
return -(double)totalD * 1000 / (double)(N * N * N * N);
}
struct StateDiff {
vector<Area> areas_;
s64 totalD_;
double EvalScore() const {
return Eval(totalD_);
}
};
struct State {
vector<Area> areas_;
s64 totalD_;
double EvalScore() const {
return Eval(totalD_);
}
void Init(const vector<vector<vector<int>>>& targetAreas) {
static vector<int> A;
A = server.A;
targetAreas_ = targetAreas;
areas_.resize(targetAreas_.size());
areaNums_.resize(targetAreas_.size());
array<int, 2> lastSwapPos_ = { -1, -1 };
REP(ai, areas_.size()) {
auto& area = areas_[ai];
REP(pi, 2) {
areaNums_[ai][pi].assign(NN, false);
for (int p : targetAreas_[ai][pi]) {
int num = target_.A_[p];
areaNums_[ai][pi][num] = true;
}
}
REP(i, targetAreas[ai][0].size() + targetAreas[ai][1].size()) {
areaRandTbl_.emplace_back(ai);
}
static vector<vector<int>> dummy;
cauto& nextArea = (ai + 1 < areas_.size()) ? targetAreas[ai + 1] : dummy;
common_sa::CalcAreaRoute(targetAreas_[ai], A, lastSwapPos_, nextArea, area.routes_, area.noRouteCells_);
REP(i, area.GetRouteSize()) {
auto pos = area.GetRoutePos(i);
if (pos[0] != pos[1]) {
swap(A[pos[0]], A[pos[1]]);
lastSwapPos_ = pos;
}
}
}
areasCostCaches_.resize(targetAreas_.size());
REP(ai, areasCostCaches_.size()) {
areasCostCaches_[ai].assign(NN, Cache{ u64(-1), -1});
}
totalD_ = CalcTotalD(areas_);
}
void UpdateTurn(StateDiff& stateDiff) const {
stateDiff.totalD_ = CalcTotalD(stateDiff.areas_);
}
void UpdateRoute(int targetAi, StateDiff& stateDiff) const {
UpdateRouteS(targetAi, stateDiff.areas_);
}
void Opt2(int targetAi, int pi, StateDiff& stateDiff) const {
stateDiff.areas_ = areas_;
stateDiff.totalD_ = totalD_;
auto& area = stateDiff.areas_[targetAi];
auto& route = area.routes_[pi];
if (route.size() < 2) {
return;
}
int size = 2 + rand_(min((int)route.size() - 1, 8));
int start = rand_((int)route.size() + 1 - size);
reverse(area.routes_[pi].begin() + start, area.routes_[pi].begin() + start + size);
UpdateRoute(targetAi, stateDiff);
UpdateTurn(stateDiff);
}
void Insert(int targetAi, int pi, StateDiff& stateDiff) const {
stateDiff.areas_ = areas_;
stateDiff.totalD_ = totalD_;
auto& area = stateDiff.areas_[targetAi];
if (area.GetRouteSize() < 2) {
return;
}
auto& route = area.routes_[pi];
int remove = rand_((int)route.size());
int insert = remove - 4 + rand_(8);
chmin(insert, (int)route.size() - 2);
chmax(insert, 0);
if (insert >= remove) {
++insert;
}
int cell = route[remove];
route.erase(route.begin() + remove);
route.insert(route.begin() + insert, cell);
UpdateRoute(targetAi, stateDiff);
UpdateTurn(stateDiff);
}
void DoubleOpt2(int targetAi, StateDiff& stateDiff) const {
stateDiff.areas_ = areas_;
stateDiff.totalD_ = totalD_;
int routeSize = stateDiff.areas_[targetAi].GetRouteSize();
if (routeSize < 2) {
return;
}
int size = 2 + rand_((int)routeSize - 1);
int start = rand_((int)routeSize + 1 - size);
REP(pi, 2) {
auto& area = stateDiff.areas_[targetAi];
auto& route = area.routes_[pi];
reverse(area.routes_[pi].begin() + start, area.routes_[pi].begin() + start + size);
}
UpdateTurn(stateDiff);
}
void DoubleInsert(int targetAi, StateDiff& stateDiff) const {
stateDiff.areas_ = areas_;
stateDiff.totalD_ = totalD_;
auto& area = stateDiff.areas_[targetAi];
int routeSize = stateDiff.areas_[targetAi].GetRouteSize();
if (routeSize < 2) {
return;
}
int remove = rand_(routeSize);
int insert = rand_(routeSize - 1);
if (insert >= remove) {
++insert;
}
REP(pi, 2) {
auto& route = area.routes_[pi];
int cell = route[remove];
route.erase(route.begin() + remove);
route.insert(route.begin() + insert, cell);
}
UpdateTurn(stateDiff);
}
void Apply(StateDiff&& diff) {
swap(areas_, diff.areas_);
totalD_ = diff.totalD_;
}
void MakeResult(IOResult& result) {
vector<array<int, 2>> route;
REP(ai, areas_.size()) {
cauto& area = areas_[ai];
REP(ri, area.GetRouteSize()) {
auto pos = area.GetRoutePos(ri);
route.emplace_back(pos);
}
}
common_sa::greedy::CalcTurn(route, result);
}
};
struct Solver {
State bestState_;
void CheckBestScore(const State& state) {
if (state.totalD_ < bestState_.totalD_) {
bestState_ = state;
}
}
void Run(ChronoTimer& timer) {
dister_.Init();
target_.Init();
vector<vector<vector<int>>> targetRoute;
common_sa::MakeTargetRoute(targetRoute);
vector<State> states;
{
states.resize(1);
states[0].Init(targetRoute);
}
bestState_ = states[0];
SimulatedAnnealing sa;
sa.startTemp_ = 0.01;
sa.endTemp_ = 0;
sa.stepLoopCount = 10;
sa.tempType_ = 0;
sa.tempPow_ = 2;
if (patternT == 7) {
VABORT();
auto transitions = make_tuple(
MAKE_TRANS(Transition_Opt2, 10)
, MAKE_TRANS(Transition_Insert, 5)
, MAKE_TRANS(Transition_DoubleOpt2, 10)
);
sa.Run2(timer, states, transitions);
}
else {
auto transitions = make_tuple(
MAKE_TRANS(Transition_Opt2, 10)
, MAKE_TRANS(Transition_Insert, 5)
);
sa.Run2(timer, states, transitions);
}
IOResult result;
bestState_.MakeResult(result);
if (result.commands_.size() > K) {
result.commands_.resize(K);
}
else {
}
server.Output(result);
}
StateDiff diff_;
void Transition_Opt2(SimulatedAnnealing& sa, SAChecker& checker, State& state) {
int ai = areaRandTbl_[rand_(areaRandTbl_.size())];
int pi = rand_(2);
state.Opt2(ai, pi, diff_);
if (checker(diff_.EvalScore())) {
state.Apply(move(diff_));
CheckBestScore(state);
}
}
void Transition_Insert(SimulatedAnnealing& sa, SAChecker& checker, State& state) {
int ai = areaRandTbl_[rand_(areaRandTbl_.size())];
int pi = rand_(2);
state.Insert(ai, pi, diff_);
if (checker(diff_.EvalScore())) {
state.Apply(move(diff_));
CheckBestScore(state);
}
}
void Transition_DoubleOpt2(SimulatedAnnealing& sa, SAChecker& checker, State& state) {
int ai = areaRandTbl_[rand_(areaRandTbl_.size())];
state.DoubleOpt2(ai, diff_);
if (checker(diff_.EvalScore())) {
state.Apply(move(diff_));
CheckBestScore(state);
}
}
void Transition_DoubleInsert(SimulatedAnnealing& sa, SAChecker& checker, State& state) {
int ai = areaRandTbl_[rand_(areaRandTbl_.size())];
state.DoubleInsert(ai, diff_);
if (checker(diff_.EvalScore())) {
state.Apply(move(diff_));
CheckBestScore(state);
}
}
};
}
namespace num_sa {
struct Area {
array<vector<int>, 2> routes_;
array<vector<int>, 2> noRouteNum_;
int GetRouteSize() const {
return (int)routes_[0].size();
}
array<int, 2> GetRoutePos(const vector<int>& numToPos, int i) const {
return { numToPos[routes_[0][i]], numToPos[routes_[1][i]] };
}
array<int, 2> GetRouteNums(int i) const {
return { routes_[0][i], routes_[1][i] };
}
void Swap(vector<int>& numToPos) const {
REP(ri, routes_[0].size()) {
swap(numToPos[routes_[0][ri]], numToPos[routes_[1][ri]]);
}
}
};
vector<vector<vector<int>>> targetAreas_;
vector<array<vector<bool>, 2>> areaNums_;
vector<int> areaRandTbl_;
struct Cache {
u64 hash;
int cost;
};
vector<vector<Cache>> areasCostCaches_;
s64 CalcTotalD(const vector<Area>& areas) {
static vector<int> numToPos;
array<int, 2> prevPos = { -1, -1 };
numToPos = server.numToPos;
int turn_ = 0;
bool end = false;
REP(ai, areas.size()) {
cauto& area = areas[ai];
auto& costCache = areasCostCaches_[ai];
REP(ri, area.GetRouteSize()) {
auto nums = area.GetRouteNums(ri);
if (nums[0] == nums[1]) {
continue;
}
array<int, 2> pos = { numToPos[nums[0]], numToPos[nums[1]] };
if (prevPos[0] >= 0) {
u64 hash = (u64(pos[0]) << 48LL) | (u64(pos[1]) << 32LL) | (prevPos[0] << 16LL) | (prevPos[1]);
auto& cache = costCache[area.routes_[0][ri]];
int cost;
if (hash == cache.hash) {
cost = cache.cost;
}
else {
cost = CalcMoveDist(prevPos, pos);
cache.hash = hash;
cache.cost = cost;
}
if (turn_ + cost >= K) {
end = true;
break;
}
turn_ += cost;
}
swap(numToPos[nums[0]], numToPos[nums[1]]);
prevPos = pos;
}
if (end) {
break;
}
}
static vector<int> A;
A.resize(NN);
REP(num, NN) {
A[numToPos[num]] = num;
}
s64 totalD = 0;
REP(i, NN) {
for (int n : aroundMap.GetAroundRB(i)) {
totalD += square(A[i] - A[n]);
}
}
return totalD;
}
void UpdateRouteS(int targetAi, vector<Area>& areas) {
static vector<int> numToPos;
numToPos = server.numToPos;
REP(ai, targetAi + 1) {
auto& area = areas[ai];
area.Swap(numToPos);
}
FOR(ai, targetAi + 1, areas.size()) {
auto& area = areas[ai];
REP(pi, 2) {
auto& route = area.routes_[pi];
auto& noRouteNums = area.noRouteNum_[pi];
cauto& require = areaNums_[ai][pi];
static vector<int> appendNums;
appendNums.clear();
RREP(i, noRouteNums.size()) {
int num = noRouteNums[i];
if (!require[num]) {
appendNums.emplace_back(num);
if (i + 1 < noRouteNums.size()) {
noRouteNums[i] = noRouteNums.back();
}
noRouteNums.pop_back();
}
}
for (int num : appendNums) {
int bestRi = -1;
int bestD = INT_MAX;
if (route.size() <= 1) {
bestRi = (int)route.size();
}
else {
FOR(ri, 1, route.size()) {
int prev = route[ri - 1];
int curr = route[ri];
int d = dister_.GetDist(numToPos[prev], numToPos[num]) + dister_.GetDist(numToPos[num], numToPos[curr]);
if (d < bestD) {
bestD = d;
bestRi = ri;
}
}
}
route.insert(route.begin() + bestRi, num);
}
}
VASSERT(area.routes_[0].size() == area.routes_[1].size());
area.Swap(numToPos);
}
}
double Eval(s64 totalD) {
return -(double)totalD * 1000 / (double)(N * N * N * N);
}
struct StateDiff {
vector<Area> areas_;
s64 totalD_;
double EvalScore() const {
return Eval(totalD_);
}
};
struct State {
vector<Area> areas_;
s64 totalD_;
double EvalScore() const {
return Eval(totalD_);
}
void Init(const vector<vector<vector<int>>>& targetAreas) {
static vector<int> A;
static vector<int> numToPos;
A = server.A;
numToPos = server.numToPos;
targetAreas_ = targetAreas;
areas_.resize(targetAreas_.size());
areaNums_.resize(targetAreas_.size());
array<int, 2> lastSwapPos_ = { -1, -1 };
REP(ai, areas_.size()) {
auto& area = areas_[ai];
REP(pi, 2) {
areaNums_[ai][pi].assign(NN, false);
for (int p : targetAreas_[ai][pi]) {
int num = target_.A_[p];
areaNums_[ai][pi][num] = true;
}
}
REP(i, targetAreas[ai][0].size() + targetAreas[ai][1].size()) {
areaRandTbl_.emplace_back(ai);
}
static vector<vector<int>> dummy;
cauto& nextArea = (ai + 1 < areas_.size()) ? targetAreas[ai + 1] : dummy;
common_sa::CalcAreaRoute(targetAreas_[ai], A, lastSwapPos_, nextArea, area.routes_, area.noRouteNum_);
REP(pi, 2) {
for (int& c : area.routes_[pi]) {
c = A[c];
}
for (int& c : area.noRouteNum_[pi]) {
c = A[c];
}
}
REP(i, area.GetRouteSize()) {
auto pos = area.GetRoutePos(numToPos, i);
if (pos[0] != pos[1]) {
swap(A[pos[0]], A[pos[1]]);
swap(numToPos[A[pos[0]]], numToPos[A[pos[1]]]);
lastSwapPos_ = pos;
}
}
}
areasCostCaches_.resize(targetAreas_.size());
REP(ai, areasCostCaches_.size()) {
areasCostCaches_[ai].assign(NN, Cache{ u64(-1), -1});
}
totalD_ = CalcTotalD(areas_);
}
void UpdateTurn(StateDiff& stateDiff) const {
stateDiff.totalD_ = CalcTotalD(stateDiff.areas_);
}
void UpdateRoute(int targetAi, StateDiff& stateDiff) const {
UpdateRouteS(targetAi, stateDiff.areas_);
}
void Opt2(int targetAi, int pi, StateDiff& stateDiff) const {
stateDiff.areas_ = areas_;
stateDiff.totalD_ = totalD_;
auto& area = stateDiff.areas_[targetAi];
auto& route = area.routes_[pi];
if (route.size() < 2) {
return;
}
int size = 2 + rand_(min((int)route.size() - 1, 8));
int start = rand_((int)route.size() + 1 - size);
reverse(area.routes_[pi].begin() + start, area.routes_[pi].begin() + start + size);
UpdateRoute(targetAi, stateDiff);
UpdateTurn(stateDiff);
}
void Insert(int targetAi, int pi, StateDiff& stateDiff) const {
stateDiff.areas_ = areas_;
stateDiff.totalD_ = totalD_;
auto& area = stateDiff.areas_[targetAi];
if (area.GetRouteSize() < 2) {
return;
}
auto& route = area.routes_[pi];
int remove = rand_((int)route.size());
int insert = remove - 4 + rand_(8);
chmin(insert, (int)route.size() - 2);
chmax(insert, 0);
if (insert >= remove) {
++insert;
}
int cell = route[remove];
route.erase(route.begin() + remove);
route.insert(route.begin() + insert, cell);
UpdateRoute(targetAi, stateDiff);
UpdateTurn(stateDiff);
}
void DoubleOpt2(int targetAi, StateDiff& stateDiff) const {
stateDiff.areas_ = areas_;
stateDiff.totalD_ = totalD_;
int routeSize = stateDiff.areas_[targetAi].GetRouteSize();
if (routeSize < 2) {
return;
}
int size = 2 + rand_((int)routeSize - 1);
int start = rand_((int)routeSize + 1 - size);
REP(pi, 2) {
auto& area = stateDiff.areas_[targetAi];
auto& route = area.routes_[pi];
reverse(area.routes_[pi].begin() + start, area.routes_[pi].begin() + start + size);
}
UpdateTurn(stateDiff);
}
void DoubleInsert(int targetAi, StateDiff& stateDiff) const {
stateDiff.areas_ = areas_;
stateDiff.totalD_ = totalD_;
auto& area = stateDiff.areas_[targetAi];
int routeSize = stateDiff.areas_[targetAi].GetRouteSize();
if (routeSize < 2) {
return;
}
int remove = rand_(routeSize);
int insert = rand_(routeSize - 1);
if (insert >= remove) {
++insert;
}
REP(pi, 2) {
auto& route = area.routes_[pi];
int cell = route[remove];
route.erase(route.begin() + remove);
route.insert(route.begin() + insert, cell);
}
UpdateTurn(stateDiff);
}
void Apply(StateDiff&& diff) {
swap(areas_, diff.areas_);
totalD_ = diff.totalD_;
}
void MakeResult(IOResult& result) {
static vector<int> A;
static vector<int> numToPos;
A = server.A;
numToPos = server.numToPos;
vector<array<int, 2>> route;
REP(ai, areas_.size()) {
cauto& area = areas_[ai];
REP(ri, area.GetRouteSize()) {
auto pos = area.GetRoutePos(numToPos, ri);
swap(A[pos[0]], A[pos[1]]);
swap(numToPos[A[pos[0]]], numToPos[A[pos[1]]]);
route.emplace_back(pos);
}
}
common_sa::greedy::CalcTurn(route, result);
}
};
struct Solver {
State bestState_;
void CheckBestScore(const State& state) {
if (state.totalD_ < bestState_.totalD_) {
bestState_ = state;
}
}
void Run(ChronoTimer& timer) {
dister_.Init();
target_.Init();
vector<vector<vector<int>>> targetRoute;
common_sa::MakeTargetRoute(targetRoute);
vector<State> states;
{
states.resize(1);
states[0].Init(targetRoute);
}
bestState_ = states[0];
SimulatedAnnealing sa;
sa.startTemp_ = 0.01;
sa.endTemp_ = 0;
sa.stepLoopCount = 10;
sa.tempType_ = 0;
sa.tempPow_ = 2;
if (patternT == 7) {
auto transitions = make_tuple(
MAKE_TRANS(Transition_Opt2, 5)
, MAKE_TRANS(Transition_Insert, 5)
, MAKE_TRANS(Transition_DoubleOpt2, 15)
);
sa.Run2(timer, states, transitions);
}
else if (patternT == 11) {
auto transitions = make_tuple(
MAKE_TRANS(Transition_Opt2, 10)
, MAKE_TRANS(Transition_Insert, 5)
, MAKE_TRANS(Transition_DoubleOpt2, 5)
);
sa.Run2(timer, states, transitions);
}
else if (patternT == 14) {
auto transitions = make_tuple(
MAKE_TRANS(Transition_Opt2, 10)
, MAKE_TRANS(Transition_Insert, 10)
, MAKE_TRANS(Transition_DoubleOpt2, 10)
);
sa.Run2(timer, states, transitions);
}
else {
auto transitions = make_tuple(
MAKE_TRANS(Transition_Opt2, 10)
, MAKE_TRANS(Transition_Insert, 5)
);
sa.Run2(timer, states, transitions);
}
IOResult result;
bestState_.MakeResult(result);
if (result.commands_.size() > K) {
result.commands_.resize(K);
}
else {
}
server.Output(result);
}
StateDiff diff_;
void Transition_Opt2(SimulatedAnnealing& sa, SAChecker& checker, State& state) {
int ai = areaRandTbl_[rand_(areaRandTbl_.size())];
int pi = rand_(2);
state.Opt2(ai, pi, diff_);
if (checker(diff_.EvalScore())) {
state.Apply(move(diff_));
CheckBestScore(state);
}
}
void Transition_Insert(SimulatedAnnealing& sa, SAChecker& checker, State& state) {
int ai = areaRandTbl_[rand_(areaRandTbl_.size())];
int pi = rand_(2);
state.Insert(ai, pi, diff_);
if (checker(diff_.EvalScore())) {
state.Apply(move(diff_));
CheckBestScore(state);
}
}
void Transition_DoubleOpt2(SimulatedAnnealing& sa, SAChecker& checker, State& state) {
int ai = areaRandTbl_[rand_(areaRandTbl_.size())];
state.DoubleOpt2(ai, diff_);
if (checker(diff_.EvalScore())) {
state.Apply(move(diff_));
CheckBestScore(state);
}
}
void Transition_DoubleInsert(SimulatedAnnealing& sa, SAChecker& checker, State& state) {
int ai = areaRandTbl_[rand_(areaRandTbl_.size())];
state.DoubleInsert(ai, diff_);
if (checker(diff_.EvalScore())) {
state.Apply(move(diff_));
CheckBestScore(state);
}
}
};
}
struct Main {
void Run(int argc, const char* argv[]) {
server.InitInput(timer_);
aroundMap.Init();
timer_.StartMs(TIME_LIMIT);
if (patternT <= 9 && patternT != 7) {
static sa::Solver solver;
solver.Run(timer_);
}
else if (patternT == 7 || patternT == 11 || patternT == 14 || patternT == 17) {
static num_sa::Solver solver;
solver.Run(timer_);
}
else {
static route_sa::Solver solver;
solver.Run(timer_);
}
server.Finalize();
}
};
Submission Info
Submission Time
2024-03-19 08:10:15+0900
Task
A - Smoothing by Swaps
User
bowwowforeach
Language
C++ 20 (gcc 12.2)
Score
1758003047
Code Size
238680 Byte
Status
AC
Exec Time
1987 ms
Memory
836820 KiB
Compile Error
Main.cpp:501:22: warning: class ‘CapArr<T, CAP>’ is implicitly friends with itself
501 | friend class CapArr;
| ^~~~~~
Main.cpp: In member function ‘void sa::State::Init(const std::vector<int>&)’:
Main.cpp:3345:52: warning: missing initializer for member ‘sa::State::Cache::cost’ [-Wmissing-field-initializers]
3345 | caches_.assign(NN, Cache{ (u32) - 1});
| ^
Judge Result
Set Name
test_0
test_1
test_2
test_3
test_4
test_5
test_6
test_7
test_8
test_9
test_10
test_11
test_12
test_13
test_14
test_15
test_16
test_17
test_18
test_19
Score / Max Score
71078637 / 1000000000
87336131 / 1000000000
91789915 / 1000000000
79194468 / 1000000000
75912346 / 1000000000
90977433 / 1000000000
72478683 / 1000000000
74687388 / 1000000000
85069186 / 1000000000
81915749 / 1000000000
89440322 / 1000000000
95423975 / 1000000000
127931144 / 1000000000
92810133 / 1000000000
73606369 / 1000000000
82710729 / 1000000000
97065498 / 1000000000
71526359 / 1000000000
105941394 / 1000000000
111107188 / 1000000000
Status
Set Name
Test Cases
test_0
test_0_0000.txt, test_0_0020.txt, test_0_0040.txt, test_0_0060.txt, test_0_0080.txt, test_0_0100.txt, test_0_0120.txt, test_0_0140.txt, test_0_0160.txt, test_0_0180.txt
test_1
test_1_0001.txt, test_1_0021.txt, test_1_0041.txt, test_1_0061.txt, test_1_0081.txt, test_1_0101.txt, test_1_0121.txt, test_1_0141.txt, test_1_0161.txt, test_1_0181.txt
test_2
test_2_0002.txt, test_2_0022.txt, test_2_0042.txt, test_2_0062.txt, test_2_0082.txt, test_2_0102.txt, test_2_0122.txt, test_2_0142.txt, test_2_0162.txt, test_2_0182.txt
test_3
test_3_0003.txt, test_3_0023.txt, test_3_0043.txt, test_3_0063.txt, test_3_0083.txt, test_3_0103.txt, test_3_0123.txt, test_3_0143.txt, test_3_0163.txt, test_3_0183.txt
test_4
test_4_0004.txt, test_4_0024.txt, test_4_0044.txt, test_4_0064.txt, test_4_0084.txt, test_4_0104.txt, test_4_0124.txt, test_4_0144.txt, test_4_0164.txt, test_4_0184.txt
test_5
test_5_0005.txt, test_5_0025.txt, test_5_0045.txt, test_5_0065.txt, test_5_0085.txt, test_5_0105.txt, test_5_0125.txt, test_5_0145.txt, test_5_0165.txt, test_5_0185.txt
test_6
test_6_0006.txt, test_6_0026.txt, test_6_0046.txt, test_6_0066.txt, test_6_0086.txt, test_6_0106.txt, test_6_0126.txt, test_6_0146.txt, test_6_0166.txt, test_6_0186.txt
test_7
test_7_0007.txt, test_7_0027.txt, test_7_0047.txt, test_7_0067.txt, test_7_0087.txt, test_7_0107.txt, test_7_0127.txt, test_7_0147.txt, test_7_0167.txt, test_7_0187.txt
test_8
test_8_0008.txt, test_8_0028.txt, test_8_0048.txt, test_8_0068.txt, test_8_0088.txt, test_8_0108.txt, test_8_0128.txt, test_8_0148.txt, test_8_0168.txt, test_8_0188.txt
test_9
test_9_0009.txt, test_9_0029.txt, test_9_0049.txt, test_9_0069.txt, test_9_0089.txt, test_9_0109.txt, test_9_0129.txt, test_9_0149.txt, test_9_0169.txt, test_9_0189.txt
test_10
test_10_0010.txt, test_10_0030.txt, test_10_0050.txt, test_10_0070.txt, test_10_0090.txt, test_10_0110.txt, test_10_0130.txt, test_10_0150.txt, test_10_0170.txt, test_10_0190.txt
test_11
test_11_0011.txt, test_11_0031.txt, test_11_0051.txt, test_11_0071.txt, test_11_0091.txt, test_11_0111.txt, test_11_0131.txt, test_11_0151.txt, test_11_0171.txt, test_11_0191.txt
test_12
test_12_0012.txt, test_12_0032.txt, test_12_0052.txt, test_12_0072.txt, test_12_0092.txt, test_12_0112.txt, test_12_0132.txt, test_12_0152.txt, test_12_0172.txt, test_12_0192.txt
test_13
test_13_0013.txt, test_13_0033.txt, test_13_0053.txt, test_13_0073.txt, test_13_0093.txt, test_13_0113.txt, test_13_0133.txt, test_13_0153.txt, test_13_0173.txt, test_13_0193.txt
test_14
test_14_0014.txt, test_14_0034.txt, test_14_0054.txt, test_14_0074.txt, test_14_0094.txt, test_14_0114.txt, test_14_0134.txt, test_14_0154.txt, test_14_0174.txt, test_14_0194.txt
test_15
test_15_0015.txt, test_15_0035.txt, test_15_0055.txt, test_15_0075.txt, test_15_0095.txt, test_15_0115.txt, test_15_0135.txt, test_15_0155.txt, test_15_0175.txt, test_15_0195.txt
test_16
test_16_0016.txt, test_16_0036.txt, test_16_0056.txt, test_16_0076.txt, test_16_0096.txt, test_16_0116.txt, test_16_0136.txt, test_16_0156.txt, test_16_0176.txt, test_16_0196.txt
test_17
test_17_0017.txt, test_17_0037.txt, test_17_0057.txt, test_17_0077.txt, test_17_0097.txt, test_17_0117.txt, test_17_0137.txt, test_17_0157.txt, test_17_0177.txt, test_17_0197.txt
test_18
test_18_0018.txt, test_18_0038.txt, test_18_0058.txt, test_18_0078.txt, test_18_0098.txt, test_18_0118.txt, test_18_0138.txt, test_18_0158.txt, test_18_0178.txt, test_18_0198.txt
test_19
test_19_0019.txt, test_19_0039.txt, test_19_0059.txt, test_19_0079.txt, test_19_0099.txt, test_19_0119.txt, test_19_0139.txt, test_19_0159.txt, test_19_0179.txt, test_19_0199.txt
Case Name
Status
Exec Time
Memory
test_0_0000.txt
AC
14 ms
4596 KiB
test_0_0020.txt
AC
8 ms
4480 KiB
test_0_0040.txt
AC
8 ms
4440 KiB
test_0_0060.txt
AC
7 ms
4452 KiB
test_0_0080.txt
AC
7 ms
4472 KiB
test_0_0100.txt
AC
7 ms
4512 KiB
test_0_0120.txt
AC
8 ms
4588 KiB
test_0_0140.txt
AC
8 ms
4512 KiB
test_0_0160.txt
AC
8 ms
4584 KiB
test_0_0180.txt
AC
8 ms
4500 KiB
test_10_0010.txt
AC
1905 ms
9440 KiB
test_10_0030.txt
AC
1905 ms
9456 KiB
test_10_0050.txt
AC
1904 ms
9452 KiB
test_10_0070.txt
AC
1904 ms
9404 KiB
test_10_0090.txt
AC
1905 ms
9336 KiB
test_10_0110.txt
AC
1904 ms
9432 KiB
test_10_0130.txt
AC
1904 ms
9368 KiB
test_10_0150.txt
AC
1905 ms
9508 KiB
test_10_0170.txt
AC
1904 ms
9448 KiB
test_10_0190.txt
AC
1904 ms
9332 KiB
test_11_0011.txt
AC
1905 ms
11852 KiB
test_11_0031.txt
AC
1905 ms
11828 KiB
test_11_0051.txt
AC
1906 ms
11868 KiB
test_11_0071.txt
AC
1905 ms
11812 KiB
test_11_0091.txt
AC
1905 ms
11852 KiB
test_11_0111.txt
AC
1905 ms
11816 KiB
test_11_0131.txt
AC
1905 ms
11876 KiB
test_11_0151.txt
AC
1905 ms
11824 KiB
test_11_0171.txt
AC
1905 ms
11904 KiB
test_11_0191.txt
AC
1905 ms
11828 KiB
test_12_0012.txt
AC
1905 ms
12852 KiB
test_12_0032.txt
AC
1905 ms
12828 KiB
test_12_0052.txt
AC
1905 ms
12824 KiB
test_12_0072.txt
AC
1905 ms
12848 KiB
test_12_0092.txt
AC
1905 ms
12852 KiB
test_12_0112.txt
AC
1905 ms
12712 KiB
test_12_0132.txt
AC
1905 ms
12820 KiB
test_12_0152.txt
AC
1905 ms
12740 KiB
test_12_0172.txt
AC
1905 ms
12772 KiB
test_12_0192.txt
AC
1905 ms
12908 KiB
test_13_0013.txt
AC
1905 ms
11388 KiB
test_13_0033.txt
AC
1905 ms
11204 KiB
test_13_0053.txt
AC
1905 ms
11356 KiB
test_13_0073.txt
AC
1905 ms
11184 KiB
test_13_0093.txt
AC
1905 ms
11232 KiB
test_13_0113.txt
AC
1905 ms
11364 KiB
test_13_0133.txt
AC
1905 ms
11264 KiB
test_13_0153.txt
AC
1905 ms
11244 KiB
test_13_0173.txt
AC
1905 ms
11356 KiB
test_13_0193.txt
AC
1905 ms
11172 KiB
test_14_0014.txt
AC
1907 ms
16620 KiB
test_14_0034.txt
AC
1907 ms
16716 KiB
test_14_0054.txt
AC
1907 ms
16624 KiB
test_14_0074.txt
AC
1907 ms
16628 KiB
test_14_0094.txt
AC
1907 ms
16652 KiB
test_14_0114.txt
AC
1907 ms
16576 KiB
test_14_0134.txt
AC
1907 ms
16536 KiB
test_14_0154.txt
AC
1907 ms
16584 KiB
test_14_0174.txt
AC
1907 ms
16544 KiB
test_14_0194.txt
AC
1907 ms
16512 KiB
test_15_0015.txt
AC
1908 ms
24972 KiB
test_15_0035.txt
AC
1908 ms
25004 KiB
test_15_0055.txt
AC
1908 ms
25052 KiB
test_15_0075.txt
AC
1908 ms
24968 KiB
test_15_0095.txt
AC
1908 ms
25004 KiB
test_15_0115.txt
AC
1908 ms
25116 KiB
test_15_0135.txt
AC
1908 ms
24956 KiB
test_15_0155.txt
AC
1908 ms
25064 KiB
test_15_0175.txt
AC
1908 ms
25096 KiB
test_15_0195.txt
AC
1908 ms
25088 KiB
test_16_0016.txt
AC
1909 ms
26516 KiB
test_16_0036.txt
AC
1910 ms
26448 KiB
test_16_0056.txt
AC
1909 ms
26552 KiB
test_16_0076.txt
AC
1909 ms
26544 KiB
test_16_0096.txt
AC
1909 ms
26500 KiB
test_16_0116.txt
AC
1909 ms
26428 KiB
test_16_0136.txt
AC
1909 ms
26424 KiB
test_16_0156.txt
AC
1909 ms
26496 KiB
test_16_0176.txt
AC
1909 ms
26356 KiB
test_16_0196.txt
AC
1909 ms
26424 KiB
test_17_0017.txt
AC
1914 ms
54384 KiB
test_17_0037.txt
AC
1914 ms
54404 KiB
test_17_0057.txt
AC
1914 ms
54252 KiB
test_17_0077.txt
AC
1914 ms
54312 KiB
test_17_0097.txt
AC
1914 ms
54276 KiB
test_17_0117.txt
AC
1914 ms
54400 KiB
test_17_0137.txt
AC
1914 ms
54352 KiB
test_17_0157.txt
AC
1915 ms
54392 KiB
test_17_0177.txt
AC
1914 ms
54368 KiB
test_17_0197.txt
AC
1914 ms
54392 KiB
test_18_0018.txt
AC
1914 ms
56660 KiB
test_18_0038.txt
AC
1914 ms
56580 KiB
test_18_0058.txt
AC
1914 ms
56568 KiB
test_18_0078.txt
AC
1914 ms
56624 KiB
test_18_0098.txt
AC
1914 ms
56488 KiB
test_18_0118.txt
AC
1914 ms
56588 KiB
test_18_0138.txt
AC
1914 ms
56516 KiB
test_18_0158.txt
AC
1914 ms
56476 KiB
test_18_0178.txt
AC
1914 ms
56448 KiB
test_18_0198.txt
AC
1914 ms
56496 KiB
test_19_0019.txt
AC
1987 ms
836572 KiB
test_19_0039.txt
AC
1986 ms
835520 KiB
test_19_0059.txt
AC
1979 ms
835080 KiB
test_19_0079.txt
AC
1979 ms
836820 KiB
test_19_0099.txt
AC
1978 ms
836196 KiB
test_19_0119.txt
AC
1985 ms
835048 KiB
test_19_0139.txt
AC
1985 ms
835712 KiB
test_19_0159.txt
AC
1981 ms
835732 KiB
test_19_0179.txt
AC
1981 ms
835660 KiB
test_19_0199.txt
AC
1978 ms
835324 KiB
test_1_0001.txt
AC
8 ms
4536 KiB
test_1_0021.txt
AC
8 ms
4528 KiB
test_1_0041.txt
AC
8 ms
4596 KiB
test_1_0061.txt
AC
7 ms
4572 KiB
test_1_0081.txt
AC
11 ms
4520 KiB
test_1_0101.txt
AC
11 ms
4516 KiB
test_1_0121.txt
AC
11 ms
4400 KiB
test_1_0141.txt
AC
7 ms
4484 KiB
test_1_0161.txt
AC
7 ms
4392 KiB
test_1_0181.txt
AC
9 ms
4460 KiB
test_2_0002.txt
AC
37 ms
5136 KiB
test_2_0022.txt
AC
39 ms
5164 KiB
test_2_0042.txt
AC
38 ms
5124 KiB
test_2_0062.txt
AC
38 ms
5064 KiB
test_2_0082.txt
AC
40 ms
5128 KiB
test_2_0102.txt
AC
34 ms
5108 KiB
test_2_0122.txt
AC
41 ms
5096 KiB
test_2_0142.txt
AC
36 ms
5076 KiB
test_2_0162.txt
AC
37 ms
5112 KiB
test_2_0182.txt
AC
40 ms
5200 KiB
test_3_0003.txt
AC
50 ms
5476 KiB
test_3_0023.txt
AC
50 ms
5536 KiB
test_3_0043.txt
AC
48 ms
5436 KiB
test_3_0063.txt
AC
50 ms
5508 KiB
test_3_0083.txt
AC
51 ms
5572 KiB
test_3_0103.txt
AC
51 ms
5508 KiB
test_3_0123.txt
AC
51 ms
5512 KiB
test_3_0143.txt
AC
48 ms
5488 KiB
test_3_0163.txt
AC
50 ms
5524 KiB
test_3_0183.txt
AC
52 ms
5524 KiB
test_4_0004.txt
AC
105 ms
6140 KiB
test_4_0024.txt
AC
104 ms
6120 KiB
test_4_0044.txt
AC
104 ms
6084 KiB
test_4_0064.txt
AC
101 ms
6096 KiB
test_4_0084.txt
AC
99 ms
6112 KiB
test_4_0104.txt
AC
104 ms
6120 KiB
test_4_0124.txt
AC
106 ms
6144 KiB
test_4_0144.txt
AC
105 ms
6144 KiB
test_4_0164.txt
AC
104 ms
6112 KiB
test_4_0184.txt
AC
103 ms
6084 KiB
test_5_0005.txt
AC
227 ms
6484 KiB
test_5_0025.txt
AC
967 ms
6444 KiB
test_5_0045.txt
AC
209 ms
6408 KiB
test_5_0065.txt
AC
294 ms
6320 KiB
test_5_0085.txt
AC
358 ms
6432 KiB
test_5_0105.txt
AC
464 ms
6448 KiB
test_5_0125.txt
AC
813 ms
6424 KiB
test_5_0145.txt
AC
565 ms
6428 KiB
test_5_0165.txt
AC
175 ms
6428 KiB
test_5_0185.txt
AC
175 ms
6456 KiB
test_6_0006.txt
AC
129 ms
6424 KiB
test_6_0026.txt
AC
126 ms
6368 KiB
test_6_0046.txt
AC
131 ms
6428 KiB
test_6_0066.txt
AC
129 ms
6500 KiB
test_6_0086.txt
AC
128 ms
6464 KiB
test_6_0106.txt
AC
129 ms
6428 KiB
test_6_0126.txt
AC
127 ms
6376 KiB
test_6_0146.txt
AC
129 ms
6412 KiB
test_6_0166.txt
AC
130 ms
6428 KiB
test_6_0186.txt
AC
127 ms
6288 KiB
test_7_0007.txt
AC
1903 ms
5700 KiB
test_7_0027.txt
AC
1903 ms
5688 KiB
test_7_0047.txt
AC
1903 ms
5680 KiB
test_7_0067.txt
AC
1903 ms
5580 KiB
test_7_0087.txt
AC
1903 ms
5644 KiB
test_7_0107.txt
AC
1903 ms
5664 KiB
test_7_0127.txt
AC
1903 ms
5604 KiB
test_7_0147.txt
AC
1903 ms
5692 KiB
test_7_0167.txt
AC
1903 ms
5752 KiB
test_7_0187.txt
AC
1903 ms
5660 KiB
test_8_0008.txt
AC
121 ms
6400 KiB
test_8_0028.txt
AC
120 ms
6460 KiB
test_8_0048.txt
AC
127 ms
6348 KiB
test_8_0068.txt
AC
128 ms
6496 KiB
test_8_0088.txt
AC
123 ms
6396 KiB
test_8_0108.txt
AC
129 ms
6424 KiB
test_8_0128.txt
AC
130 ms
6384 KiB
test_8_0148.txt
AC
128 ms
6412 KiB
test_8_0168.txt
AC
128 ms
6428 KiB
test_8_0188.txt
AC
122 ms
6412 KiB
test_9_0009.txt
AC
333 ms
8944 KiB
test_9_0029.txt
AC
436 ms
8892 KiB
test_9_0049.txt
AC
336 ms
8944 KiB
test_9_0069.txt
AC
339 ms
8960 KiB
test_9_0089.txt
AC
331 ms
8912 KiB
test_9_0109.txt
AC
336 ms
8908 KiB
test_9_0129.txt
AC
483 ms
8936 KiB
test_9_0149.txt
AC
747 ms
8992 KiB
test_9_0169.txt
AC
337 ms
8976 KiB
test_9_0189.txt
AC
327 ms
8936 KiB