#P12378. Maximizing Coin Frequency

    ID: 14480 Type: Default 1000ms 256MiB

Maximizing Coin Frequency

Maximizing Coin Frequency

Blue has 2023 types of new coins. For each i (1 ≤ i ≤ 2023), he has i coins of value i. There is a coin exchange machine that accepts two new coins and returns one old coin whose value is equal to the sum of the two coins you provided. Formally, if you give the machine two new coins with values \(\text{coin}_1\) and \(\text{coin}_2\), you get an old coin with value \(\text{coin}_1 + \text{coin}_2\).

Blue can perform the exchange operation as many times as he likes (each exchange must use two new coins and produces one old coin). After performing a sequence of exchanges (possibly zero), assume that Blue ends up with K distinct coin denominations (new or old); denote the final count (frequency) of coins with the i-th value as \(sum_i\) (1 ≤ i ≤ K). He would like to maximize \(\max\{sum_1, sum_2, \cdots, sum_K\}\), and your task is to compute this maximum possible value.

Exchange rules:

  • The coin exchange machine only accepts new coins as input.
  • The coins produced by the machine are all old coins.

Note: The coins are distinguished only by their face values, regardless of whether they are new or old.

Mathematical formulation:
Initially, for each \(i=1,2,\dots,2023\), the number of coins of value \(i\) is \(i\). In an exchange operation, if two new coins of values \(a\) and \(b\) (with \(a+b=T\)) are used, they are removed and one old coin of value \(T\) is produced. The final count for a coin of value \(T\) is equal to the sum of the coins that were originally of value \(T\) (if \(T \le 2023\)) and the number of exchanges that produced a coin of value \(T\).

After analysis (and testing with small values of coin types), it turns out that the optimal strategy is to maximize the frequency of the coin with value \(T=2023\). With some combinatorial pairing arguments, one can show that the maximum achievable frequency is:

[ \text{Answer} = 2023 + \sum_{a=1}^{1011} a = 2023 + \frac{1011 \times 1012}{2} = 513589. ]

Your task is to output this maximum frequency.

inputFormat

This problem does not require any input.

outputFormat

Output a single number — the maximum possible value of \(\max\{sum_1, sum_2, \cdots, sum_K\}\).

sample

513589