#P12190. Maximum Chapters in a Mystery Novel

    ID: 14295 Type: Default 1000ms 256MiB

Maximum Chapters in a Mystery Novel

Maximum Chapters in a Mystery Novel

Xiao Lan is a popular online novelist who is currently drafting a new mystery novel. The novel features n distinct characters and each chapter follows one of the three plot types:

  1. Type 1: Character A discovers that Character B does not know the truth.
  2. Type 2: Character A discovers that Character B does know the truth.
  3. Type 3: Character A comes to know the truth.

However, to ensure coherence and novelty, the following constraints must be met:

  • For any two characters A and B, an event of the form "B discovers A does not know the truth" must occur before the chapter in which A comes to know the truth.
  • An event of the form "B discovers A knows the truth" must occur after the chapter in which A comes to know the truth.
  • For a given pair (A, B), if both types of discovery occur then the chapter where "B discovers A does not know the truth" must come before the chapter where "B discovers A knows the truth".
  • Consecutive chapters cannot be of the same plot type. For example, if the first chapter is of Type 1 then the second chapter cannot be of Type 1 (even if different characters are involved).
  • Identical chapters (with the exact same plot details) cannot appear more than once.

Each chapter is constructed from an event, and every potential event can be used at most once. Notice that for every character A:

  • There is exactly one Type 3 event: "A comes to know the truth".
  • For every other character B (where B ≠ A), there is a potential Type 1 event: "B discovers A does not know the truth", and a potential Type 2 event: "B discovers A knows the truth".

Thus, the total number of potential events is 2n(n-1) + n (where n is the number of characters). It turns out that, under a careful interleaving which respects the above constraints (including the restriction that adjacent chapters must have different types), Xiao Lan can indeed use

[ \text{Maximum Chapters} = 2n^2 - n ]

Your task is to compute this maximum number of chapters given n.

inputFormat

The input consists of a single integer n (1 ≤ n ≤ 109), which represents the number of distinct characters in the novel.

outputFormat

Output a single integer: the maximum number of chapters Xiao Lan can write, computed using the formula:

[ 2n^2 - n ]

sample

1
1