문제
There are a total of
At Farmer John's signal, some of the cows will form pairs such that
Every pair consists of a Holstein
h and a Guernseyg whose locations are withinK of each other (1≤K≤10^9 ); that is,|x_h−x_g|≤K .Every cow is either part of a single pair or not part of a pair.
The pairing is maximal; that is, no two unpaired cows can form a pair.
It's up to you to determine the range of possible sums of weights of the unpaired cows. Specifically,
If
T=1 , compute the minimum possible sum of weights of the unpaired cows.If
T=2 , compute the maximum possible sum of weights of the unpaired cows.
입력
The first input line contains
Following this are
출력
The minimum or maximum possible sum of weights of the unpaired cows.
예제1
2 5 4
G 1 1
H 3 4
G 4 2
H 6 6
H 8 9
16
Cows
예제2
1 5 4
G 1 1
H 3 4
G 4 2
H 6 6
H 8 9
6
Cows
예제3
2 10 76
H 1 18
H 18 465
H 25 278
H 30 291
H 36 202
G 45 96
G 60 375
G 93 941
G 96 870
G 98 540
1893