CF802K Send the Fool Further! (medium)

Description

Thank you for helping Heidi! It is now the second of April, but she has been summoned by Jenny again. The pranks do not seem to end... In the meantime, Heidi has decided that she does not trust her friends anymore. Not too much, anyway. Her relative lack of trust is manifested as follows: whereas previously she would not be made to visit the same person twice, now she can only be sure that she will not be made to visit the same person more than $ k $ times. (In the case of Jenny, this includes her first visit in the beginning. The situation from the easy version corresponds to setting $ k=1 $ .) This is not as bad as it looks, since a single ticket for a route between two friends allows Heidi to travel between this pair of friends the whole day (in both directions). In other words, once she pays for travel between a pair of friends, all further travels between that pair are free. How much money will Heidi waste now, in a worst-case scenario?

Input Format

The first line contains two space-separated integers – the number of friends $ n $ (![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF802K/61a469a4155af38f62f367d5c4fb45b1ec2c115c.png)) and the parameter $ k $ ( $ 1

Output Format

Again, output a single integer – the maximum sum of costs of tickets.

Explanation/Hint

In the first example, the worst-case scenario for Heidi is to visit the friends in the following order: $ 0,1,5,1,3,1,0,2,6,2,7,2,8 $ . Observe that no friend is visited more than $ 3 $ times.