Take the Elevator
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

There is a tall building called Arasaka Tower in the center of the Night City. People go up and down in the Arasaka Tower every day.

Arasaka Tower has k floors. Today, there are n people going to take the elevator, the i-th person wants to go from the a_i-th floor to the b_i-th floor. The elevator may carry up to m people at a time, and it starts from the first floor. The elevator takes 1 unit of time to go up or down one floor. The time people enter and exit the elevator can be ignored.

However, there is something wrong with the elevator today. The running direction of the elevator can no longer be changed arbitrarily. When the elevator is going down, it can change its running direction if and only if it reaches the first floor.

What is the minimum time to carry all people to their destination and let the elevator back to the first floor?

输入描述:

The first line contains three integers n,m and k ().

The i-th of the next n lines contains two integers a_i and b_i. ()

输出描述:

Output the minimum time in a single line.
示例1

输入

复制
5 1 6
1 3
2 4
5 6
5 4
4 2

输出

复制
14
示例2

输入

复制
6 1 6
1 3
2 4
5 6
5 4
4 2
5 6

输出

复制
20
示例3

输入

复制
5 2 6
1 3
2 4
5 6
5 4
4 2

输出

复制
10

备注:

In the first test case, the taking-order can be:2,3,4,5,1. So the sum of time will be .