409834: GYM103800 K Ginger's palindrome
Memory Limit:256 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
K. Ginger's palindrometime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output
Ginger has $$$n$$$ numbers $$$a_1, a_2, \dots, a_n$$$, the value of $$$a_i$$$ is $$$c_{i}$$$. Ginger will choose some of these numbers so that put together it is a palindrome, the same number can be chose multiple times.
Ginger wants to know the minimum value.
InputThe first line contain a integer $$$n$$$ $$$(1\le n \le 40)$$$ indicate number of numbers.
The next $$$n$$$ line, each line contains two integers $$$a_i, c_i$$$ $$$(0\le a_i, c_i \le10^{9})$$$
OutputPrint the minimum value.
ExampleInput5 12 21 21 13 13 111 45 19 331 12Output
34Note
If there is a number chose multiple times, the value is the value of the number $$$\times$$$ number of choices.