QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 512 MB 總分: 100

#5822. City Construction

统计

There are $N$ cities located at nodes $1, 2, \dots, N$. As the city manager, Xiao Ming wants to connect these $N$ cities with the minimum cost. The cost of connecting the cities is divided into the following two types:

Type 1: Constructing a road between city $a$ and city $b$ costs $|a - b|$.

Type 2: Setting up a management city. A city $X$ can be upgraded to a management city at a cost of $C$.

Given the constraints that every road must connect to at least one management city, and each non-management city can be connected to only one edge, Xiao Ming wants to know the minimum cost to connect all cities.

Input

The first line contains a positive integer $N$, representing the number of cities.

The second line contains an integer $C$, representing the cost of setting up a management city.

Output

A single integer representing the minimum cost for Xiao Ming to connect all cities.

Examples

Input 1

6
3

Output 1

12

Input 2

1000
1000

Output 2

32561

Input 3

100000
10000

Output 3

10099799

Note

The minimum cost is achieved by setting cities $2$ and $5$ as management cities and connecting the five edges $(1, 2), (2, 3), (2, 5), (4, 5), (5, 6)$.

Alternatively, setting city $3$ or $4$ as a management city and connecting all other points also achieves the minimum cost.

Constraints

For 20% of the data, $1 \le N \le 20$.

For 40% of the data, $1 \le N \le 10^3$.

For another 20% of the data, $1 \le N \le 10^5, 0 \le C \le 10^4$.

For 100% of the data, $1 \le N \le 10^9, 0 \le C \le 10^9$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.