Problem: This problem is split into two tasks. In this task, you are required to find the maximum possible answer. In the task Village (Minimum) you are required to find the minimum possible answer. Each task is worth 50 points.

There are N houses in a certain village. A single villager lives in each of the houses. The houses are connected by roads. Each road connects two houses and is exactly 1 kilometer long. From each house it is possible to reach any other using one or several consecutive roads. In total there are N-1 roads in the village.

One day all villagers decided to move to different houses — that is, after moving each house should again have a single villager living in it, but no villager should be living in the same house as before. We would like to know the largest possible total length in kilometers of the shortest paths between the old and the new houses for all villagers.

<image>

Example village with seven houses 

For example, if there are seven houses connected by roads as shown on the figure, the largest total length is 18 km (this can be achieved by moving 1 → 7, 2 → 3, 3 → 4, 4 → 1, 5 → 2, 6 → 5, 7 → 6).

Write a program that finds the largest total length of the shortest paths in kilometers and an example assignment of the new houses to the villagers.

Input

The first line contains an integer N (1 < N ≤ 10^5). Houses are numbered by consecutive integers 1, 2, …, N.

Then N-1 lines follow that describe the roads. Each line contains two integers a and b (1 ≤ a, b ≤ N, a ≠ b) denoting that there is a road connecting houses a and b.

Output

In the first line output the largest total length of the shortest paths in kilometers.

In the second line describe one valid assignment of the new houses with the largest total length: N space-separated distinct integers v_1, v_2, …, v_N. For each i, v_i is the house number where villager from the house i should move (v_i ≠ i). If there are several valid assignments, output any of those.

Scoring

Subtasks: 

  1. (6 points) N ≤ 10 
  2. (19 points) N ≤ 1 000 
  3. (25 points) No further constraints 

Examples

Input


4
1 2
2 3
3 4


Output


8
4 3 2 1


Input


7
4 2
5 7
3 4
6 3
1 3
4 5


Output


18
2 7 4 1 3 5 6

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
#pragma GCC optimize("O3", "unroll-loops")
using namespace std;
namespace {
const int MOD107 = 1000000007;
const int MOD998 = 998244353;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <class T>
using minheap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
using maxheap = priority_queue<T, vector<T>, less<T>>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct Modular {
 private:
  long long MODVALUE = 0;
  long long val = 0;
  Modular initModular(long long val) const { return Modular(val, MODVALUE); }
  inline void validate() const {}
  inline void validate(const Modular& other) const {}

 public:
  explicit operator long long() const { return val; }
  template <class T>
  Modular& operator=(const T& other) {
    val = (other % MODVALUE + MODVALUE) % MODVALUE;
    return *this;
  }
  long long getMod() { return MODVALUE; }
  template <class T>
  void setMod(const T& MOD) {
    MODVALUE = MOD;
  }
  Modular& operator+=(const Modular& other) {
    validate(other);
    val += other.val;
    if (val >= MODVALUE) val -= MODVALUE;
    return *this;
  }
  Modular operator+(const Modular& other) const {
    Modular tmp = *this;
    return tmp += other;
  }
  template <class T>
  Modular& operator+=(const T& other) {
    return *this += initModular(other);
  }
  template <class T>
  Modular operator+(const T& other) const {
    return *this + initModular(other);
  }
  template <class T>
  friend Modular operator+(const T& other, const Modular& m) {
    return m.initModular(other) + m;
  }
  Modular& operator++() { return *this += 1; }
  Modular operator++(int) {
    Modular tmp = *this;
    ++*this;
    return tmp;
  }
  Modular operator-() const { return initModular(-val); }
  Modular& operator-=(const Modular& other) {
    validate(other);
    val -= other.val;
    if (val < 0) val += MODVALUE;
    return *this;
  }
  Modular operator-(const Modular& other) const {
    Modular tmp = *this;
    return tmp -= other;
  }
  template <class T>
  Modular& operator-=(const T& other) {
    return *this -= initModular(other);
  }
  template <class T>
  Modular operator-(const T& other) const {
    return *this - initModular(other);
  }
  template <class T>
  friend Modular operator-(const T& other, const Modular& m) {
    return m.initModular(other) - m;
  }
  Modular& operator--() { return *this -= 1; }
  Modular operator--(int) {
    Modular tmp = *this;
    --*this;
    return tmp;
  }
  Modular& operator*=(const Modular& other) {
    validate(other);
    val *= other.val;
    val %= MODVALUE;
    if (val < 0) val += MODVALUE;
    return *this;
  }
  Modular operator*(const Modular& other) const {
    Modular tmp = *this;
    return tmp *= other;
  }
  template <class T>
  Modular& operator*=(const T& other) {
    return *this *= initModular(other);
  }
  template <class T>
  Modular operator*(const T& other) const {
    return *this * initModular(other);
  }
  template <class T>
  friend Modular operator*(const T& other, const Modular& m) {
    return m.initModular(other) * m;
  }
  Modular pow(long long power) const {
    Modular m = *this, ans = initModular(1);
    while (power) {
      if (power & 1) ans *= m;
      m *= m;
      power >>= 1;
    }
    return ans;
  }
  Modular pow(const Modular& other) const { return pow(other.val); }
  Modular inv() const { return pow(MODVALUE - 2); }
  Modular& operator/=(const Modular& other) {
    val *= other.inv().val;
    val %= MODVALUE;
    if (val < 0) val += MODVALUE;
    return *this;
  }
  Modular operator/(const Modular& other) const {
    Modular tmp = *this;
    return tmp /= other;
  }
  template <class T>
  Modular& operator/=(const T& other) {
    return *this /= initModular(other);
  }
  template <class T>
  Modular operator/(const T& other) const {
    return *this / initModular(other);
  }
  template <class T>
  friend Modular operator/(const T& other, const Modular& m) {
    return m.initModular(other) / m;
  }
  friend istream& operator>>(istream& in, Modular& m) {
    in >> m.val;
    m.val %= m.MODVALUE;
    if (m.val < 0) m.val += m.MODVALUE;
    return in;
  }
  friend ostream& operator<<(ostream& out, const Modular& m) {
    return out << m.val;
  }
  Modular() {
    val = 0;
    MODVALUE = 0;
  }
  Modular(long long val, long long MOD)
      : MODVALUE(MOD), val((val % MOD + MOD) % MOD) {}
};
using Mint = Modular;
inline ll binpow(ll b, ll p, ll mod) {
  b %= mod;
  ll ans = 1;
  for (; p > 0; p >>= 1) {
    if (p & 1) {
      ans *= b;
      ans %= mod;
    }
    b *= b;
    b %= mod;
  }
  return ans;
}
inline ll max(ll a, int b) { return (a > b ? a : b); }
inline ll max(int a, ll b) { return (a > b ? a : b); }
inline ll min(ll a, int b) { return (a < b ? a : b); }
inline ll min(int a, ll b) { return (a < b ? a : b); }
template <class T>
inline bool chkmin(T& x, const T& y) {
  return y < x ? x = y, 1 : 0;
}
template <class T>
inline bool chkmax(T& x, const T& y) {
  return x < y ? x = y, 1 : 0;
}
}  // namespace
namespace IO {
struct InputWrapper {
 private:
  istream& in;

 public:
  template <class T>
  inline void _R(T& x) {
    in >> x;
  }
  template <class T1, class T2>
  inline void _R(pair<T1, T2>& x) {
    _R(x.first);
    _R(x.second);
  }
  template <class T>
  inline void _R(vector<T>& x) {
    for (auto& i : x) _R(i);
  }
  template <class T>
  inline void _R(deque<T>& x) {
    for (auto& i : x) _R(i);
  }
  inline void R() {}
  template <class T1, class... T2>
  inline void R(T1& x, T2&... y) {
    _R(x);
    R(y...);
  }
  template <class... T>
  inline void operator()(T&... x) {
    R(x...);
  }
  InputWrapper(istream& in) : in(in) {}
} R(cin);
struct OutputWrapper {
 private:
  ostream& out;

 public:
  template <class Container>
  inline void printContainer(const Container& x) {
    bool isFirst = 1;
    for (auto i : x) {
      if (!isFirst) out << ' ';
      isFirst = 0;
      _W(i);
    }
  }
  template <class T>
  inline void _W(const T& x) {
    out << x;
  }
  template <class T1, class T2>
  inline void _W(const pair<T1, T2>& p) {
    _W(p.first);
    _W(' ');
    _W(p.second);
  }
  template <class... T>
  inline void _W(const vector<T...>& x) {
    printContainer(x);
  }
  template <class... T>
  inline void _W(const deque<T...>& x) {
    printContainer(x);
  }
  template <class... T>
  inline void _W(const forward_list<T...>& x) {
    printContainer(x);
  }
  template <class... T>
  inline void _W(const list<T...>& x) {
    printContainer(x);
  }
  template <class... T>
  inline void _W(const set<T...>& x) {
    printContainer(x);
  }
  template <class... T>
  inline void _W(const multiset<T...>& x) {
    printContainer(x);
  }
  template <class... T>
  inline void _W(const unordered_set<T...>& x) {
    printContainer(x);
  }
  template <class... T>
  inline void _W(const unordered_multiset<T...>& x) {
    printContainer(x);
  }
  template <class... T>
  inline void _W(const map<T...>& x) {
    printContainer(x);
  }
  template <class... T>
  inline void _W(const multimap<T...>& x) {
    printContainer(x);
  }
  template <class... T>
  inline void _W(const unordered_map<T...>& x) {
    printContainer(x);
  }
  template <class... T>
  inline void _W(const unordered_multimap<T...>& x) {
    printContainer(x);
  }
  inline void W() { out << '\n'; }
  template <class T>
  inline void W(const T& x) {
    _W(x);
    W();
  }
  template <class T1, class... T2>
  inline void W(const T1& x, const T2&... y) {
    _W(x);
    _W(' ');
    W(y...);
  }
  template <class... T>
  inline void operator()(const T&... x) {
    W(x...);
  }
  OutputWrapper(ostream& out) : out(out) {}
} W(cout), D(cerr);
}  // namespace IO
using namespace IO;
namespace outputFormat {
inline string Case(int tc) { return "Case #" + to_string(tc) + ':'; }
inline string YN(bool b) { return b ? "Yes" : "No"; }
}  // namespace outputFormat
using namespace outputFormat;
namespace std {
template <class T1, class T2>
struct hash<pair<T1, T2>> {
  std::size_t operator()(pair<T1, T2> _) const {
    return hash<T1>{}(_.first) ^ hash<T2>{}(_.second);
  }
};
}  // namespace std
int main() {
  int n;
  R(n);
  vector<vector<int>> g(n + 1);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    R(u, v);
    g[u].emplace_back(v);
    g[v].emplace_back(u);
  }
  vector<int> order;
  vector<int> sz(n + 1, 1);
  function<void(int, int)> dfs = [&](int u, int p) {
    order.emplace_back(u);
    for (auto& v : g[u]) {
      if (v == p) continue;
      dfs(v, u);
      sz[u] += sz[v];
    }
  };
  dfs(1, -1);
  ll dist = 0;
  for (int u = 1; u <= n; u++) dist += 2 * min(sz[u], n - sz[u]);
  vector<int> ans(n + 1);
  for (int i = 0; i < n; i++) ans[order[i]] = order[(i + n / 2) % n];
  for (int u = 1; u <= n; u++) assert(ans[u] != u);
  W(dist);
  for (int u = 1; u <= n; u++) cout << ans[u] << " \n"[u == n];
  return 0;
}
static auto __init__ = []() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(10);
  return 42;
}();