PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000037. Phép nối tốt nhất (Best Concatenation)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Phép nối tốt nhất (Best Concatenation)
Best Concatenation
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
There are strings consisting of digits 1 to 9 and X. Concatenate them in some order. The score is the sum, over every digit, of its value multiplied by the number of preceding X characters. Find the maximum score.
Input
The first line contains . Each of the next lines contains one string.
Output
Print the maximum score.
Constraints
- .
- và .
- Each character of is
Xor a digit from1through9..
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): Full constraints.
Examples
Input
3
1X3
59
XXX
Output
71
Explanation
The sample follows the ordering rule described in the Vietnamese explanation and produces the shown optimum.