atcoder#ARC121B. [ARC121B] RGB Matching
[ARC121B] RGB Matching
Score : points
Problem Statement
Snuke has dogs, numbered through .
The cuteness of Dog is .
The color of Dog is , which is R
, G
, or B
; R
stands for red, G
stands for green, and B
stands for blue.
Snuke has kennels, and wants to put two dogs in each kennel. Note that this means each dog will be in exactly one kennel.
When he puts two dogs in the same kennel, it will cause some dissatisfaction in that kennel. The level of dissatisfaction is represented as an integer. When Dogs and are in the same kennel, the dissatisfaction will be if and otherwise.
Find the minimum possible total dissatisfaction when putting two dogs in each of the kennels.
Constraints
- is an integer.
- is
R
,G
, orB
.
Input
Input is given from Standard Input in the following format:
Output
Print the minimum possible total dissatisfaction when putting two dogs in each of the kennels.
1
1 R
2 G
1
- Dog has the cuteness of , and Dog has the cuteness of .
- Since , the dissatisfaction will be .
1
1 B
2 B
0
- Dog has the cuteness of , and Dog has the cuteness of .
- Since , the dissatisfaction will be .
10
585 B
293 B
788 B
222 B
772 G
841 B
115 R
603 G
450 B
325 R
851 B
205 G
134 G
651 R
565 R
548 B
391 G
19 G
808 B
475 B
0