Branch Assignment

Partition b branches into s nonempty groups to minimize total round-trip courier distance, where a message from branch i to j costs dist(i,hq)+dist(hq,j).

Medium5GraphShortest pathSortingNo attempts yetTime limit5sMemory limit512 MB

Problem

The Innovative Consumer Products Company (ICPC) is starting a secret project. The project splits into ss subprojects. There are bb branch offices involved, with bsb \ge s, and the company gives each branch one of the subprojects. In other words, the branches are divided into ss disjoint groups, and each group takes one subproject. No group is empty.

At the end of every month, each branch sends a message to every other branch in its own group. The message differs for each recipient. The company uses a special protocol for this traffic. Branch ii has a secret key kik_i known only to that branch and to the headquarters. When branch ii wants to send a message to branch jj, branch ii first encrypts the message with kik_i. A courier carries the message from the branch to the headquarters. The headquarters decrypts the message with kik_i and encrypts it again with kjk_j. The courier then carries the newly encrypted message to branch jj, which holds kjk_j. For security reasons the courier can carry only one message at a time.

The distance for delivering one message is therefore the shortest distance from the sending branch to the headquarters plus the shortest distance from the headquarters to the receiving branch, and the distance the courier travels at the end of a month is the sum of the distances of all messages delivered that month.

You are given the road network and the positions of the branches and the headquarters. Consider every way of assigning the subprojects to the branches and find the minimum distance the courier has to travel at the end of a month.

Input

The first line holds four integers nn, bb, ss and rr. Here nn (2n50002 \le n \le 5000) is the number of intersections, bb (1bn11 \le b \le n-1) is the number of branches, ss (1sb1 \le s \le b) is the number of subprojects, and rr (1r500001 \le r \le 50000) is the number of roads. The intersections are numbered from 11 to nn. The branches sit at intersections 11 through bb, and the headquarters sits at intersection b+1b+1.

Each of the next rr lines holds three integers uu, vv and ll. It means there is a road from intersection uu to intersection vv and its length is ll (1u,vn1 \le u, v \le n, 0l100000 \le l \le 10000). A road can be used only in the given direction. A road from uu to vv is never given twice, and it is guaranteed that every intersection can reach every other intersection.

Output

Print the minimum distance the courier has to travel.