#P10157. Construct a Rooted Tree with XOR Degree Zero

    ID: 12146 Type: Default 1000ms 256MiB

Construct a Rooted Tree with XOR Degree Zero

Construct a Rooted Tree with XOR Degree Zero

Given an integer n, construct a rooted tree with n nodes (node 1 is the root) such that the following conditions hold:

  • The bitwise XOR of the degrees of all nodes is zero, i.e., \[ \bigoplus_{i=1}^{n} \text{degree}(i)=0, \] where \(\oplus\) denotes the bitwise XOR and \(\text{degree}(i)\) is the number of nodes adjacent to node \(i\).
  • Among all trees satisfying the XOR condition, the sequence of parent nodes \(fa_2, fa_3, \ldots, fa_n\) is lexicographically smallest. For every node \(i\) \((2 \le i \le n)\), \(fa_i\) is its parent and we always have \(fa_i < i\).

Output the value of the following sum: \[ \sum_{i=2}^{n} i\times fa_i, \] and if no such tree exists, output \(-1\) instead.

inputFormat

The input consists of a single integer n (\(n \ge 1\)).

outputFormat

Output a single integer representing \(\sum_{i=2}^{n} i \times fa_i\) for the constructed tree, or \(-1\) if no valid tree exists.

sample

2
2