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>
using namespace std;
using ll = int64_t;
using ull = uint64_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f64 = double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using ld = double;
namespace io {
const int BUFSIZE = 1 << 20;
int isize, osize;
char ibuf[BUFSIZE + 10], obuf[BUFSIZE + 10];
char *is, *it, *os = obuf, *ot = obuf + BUFSIZE;
char getchar() {
  if (is == it) {
    is = ibuf;
    it = ibuf + fread(ibuf, 1, BUFSIZE, stdin);
    if (is == it) return EOF;
  }
  return *is++;
}
char getalpha() {
  char c = getchar();
  while (!isalpha(c)) c = getchar();
  return c;
}
void putchar(char c) {
  *os++ = c;
  if (os == ot) {
    fwrite(obuf, 1, BUFSIZE, stdout);
    os = obuf;
  }
}
int inp() {
  int x = 0, f = 0;
  char ch;
  for (ch = getchar(); !isdigit(ch); ch = getchar()) {
    if (ch == EOF) return -1;
    if (ch == '-') f = 1;
  }
  for (; isdigit(ch); x = x * 10 + ch - '0', ch = getchar())
    ;
  return f ? -x : x;
}
ll inp_ll() {
  ll x = 0;
  int f = 0;
  char ch;
  for (ch = getchar(); !isdigit(ch); ch = getchar())
    if (ch == '-') f = 1;
  for (; isdigit(ch); x = x * 10 + ch - '0', ch = getchar())
    ;
  return f ? -x : x;
}
template <class T>
bool read(T& x) {
  x = 0;
  int f = 0;
  char ch;
  for (ch = getchar(); !isdigit(ch); ch = getchar()) {
    if (ch == EOF) return 0;
    if (ch == '-') f = 1;
  }
  for (; isdigit(ch); x = x * 10 + ch - '0', ch = getchar())
    ;
  if (f) x = -x;
  return 1;
}
bool read(char* s) {
  char* t = s;
  char ch = getchar();
  for (; ch == ' ' || ch == '\n'; ch = getchar())
    ;
  for (; ch != ' ' && ch != '\n' && ch != EOF; ch = getchar()) *t++ = ch;
  *t = 0;
  return s != t;
}
template <class T, class... Args>
bool read(T& x, Args&... args) {
  return read(x) && read(args...);
}
template <class T>
bool readln(T& x) {
  x = 0;
  int f = 0;
  char ch;
  for (ch = getchar(); !isdigit(ch); ch = getchar()) {
    if (ch == EOF) return 0;
    if (ch == '-') f = 1;
  }
  for (; isdigit(ch); x = x * 10 + ch - '0', ch = getchar())
    ;
  if (f) x = -x;
  for (; ch != '\n' && ch != EOF; ch = getchar())
    ;
  return 1;
}
bool readln(char* s) {
  char* t = s;
  while (1) {
    char ch = getchar();
    if (ch == '\n' || ch == EOF) break;
    *t++ = ch;
  }
  *t = 0;
  return s != t;
}
template <class T, class... Args>
bool readln(T& x, Args&... args) {
  return read(x) && readln(args...);
}
template <class T>
void write(T x) {
  static char s[22];
  static char* it = s + 20;
  static char* end = s + 20;
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  do {
    *--it = x % 10 + '0';
    x /= 10;
  } while (x);
  for (; it < end; ++it) putchar(*it);
}
void write(const char* s) {
  for (; *s; ++s) putchar(*s);
}
template <>
void write(char* s) {
  write((const char*)s);
}
template <>
void write(char c) {
  putchar(c);
}
template <class T, class... Args>
void write(T x, Args... args) {
  write(x);
  write(args...);
}
void writeln() { putchar('\n'); }
template <class T, class... Args>
void writeln(T x, Args... args) {
  write(x);
  writeln(args...);
}
template <class Iterator>
bool input(Iterator st, Iterator ed) {
  for (; st != ed; ++st) {
    if (!read(*st)) return false;
  }
  return true;
}
template <class T>
bool input(T& a) {
  return input(a.begin(), a.end());
}
template <class Iterator>
void print(Iterator st, Iterator ed, const char* c = " ") {
  int flag = 0;
  for (; st != ed; ++st) {
    if (flag) write(c);
    flag = 1;
    write(*st);
  }
  writeln();
}
template <class T>
void print(const T& a, const char* c = " ") {
  print(a.begin(), a.end(), c);
}
struct ender {
  ~ender() {
    if (os != obuf) fwrite(obuf, 1, os - obuf, stdout);
  }
} __ender;
}  // namespace io
int64_t power(int64_t a, int64_t b, int64_t p) {
  if (!b) return 1;
  int64_t t = power(a, b >> 1, p);
  t = t * t % p;
  if (b & 1) t = t * a % p;
  return t;
}
pll exgcd(ll a, ll b) {
  if (b == 0) return {1, 0};
  auto e = exgcd(b, a % b);
  ll x = e.first;
  ll y = e.second;
  return {y, x - a / b * y};
}
mt19937 rd(1);
using namespace io;
template <class T>
inline void freshmin(T& a, const T& b) {
  if (a > b) a = b;
}
template <class T>
inline void freshmax(T& a, const T& b) {
  if (a < b) a = b;
}
int dx[] = {-1, 1, 0, 0, -1, -1, 1, 1};
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
template <class T>
T det(T x1, T y1, T x2, T y2, T x3, T y3) {
  return x1 * y2 - x2 * y1 + x2 * y3 - x3 * y2 + x3 * y1 - x1 * y3;
}
template <class T>
T dis(T x1, T y1, T x2, T y2) {
  return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
const int INF = 1000000000;
void solve() {
  int n;
  read(n);
  vector<vector<int>> v(n);
  for (int i = 1; i < n; ++i) {
    int x, y;
    read(x, y);
    x -= 1;
    y -= 1;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  vector<int> sz(n);
  int root = -1, best = n;
  function<void(int, int)> dfs = [&](int x, int pre) {
    sz[x] = 1;
    int largest = 0;
    for (auto y : v[x]) {
      if (y == pre) continue;
      dfs(y, x);
      sz[x] += sz[y];
      freshmax(largest, sz[y]);
    }
    freshmax(largest, n - sz[x]);
    if (largest < best) {
      best = largest;
      root = x;
    }
  };
  dfs(0, -1);
  vector<int> dis(n);
  vector<int> w;
  function<void(int, int)> dfs2 = [&](int x, int pre) {
    w.push_back(x);
    for (auto y : v[x]) {
      if (y == pre) continue;
      dis[y] = dis[x] + 1;
      dfs2(y, x);
    }
  };
  dfs2(root, -1);
  int step = n / 2;
  ll ans = 0;
  vector<int> res(n);
  for (int i = 0; i < n; ++i) {
    res[w[i]] = w[(i + step) % n];
    ans += dis[w[i]] + dis[res[w[i]]];
  }
  writeln(ans);
  for (auto& x : res) x += 1;
  print(res);
}
int main() {
  int T = 1;
  for (int test = 1; test <= T; ++test) {
    solve();
  }
  return 0;
}