Kotlin Heroes: Episode 11 |
---|
Finished |
You are given a string $$$s$$$ of the form <block of digits>+<block of digits>+...+<block of digits>. Every block of digits consists of at least $$$2$$$ and at most $$$13$$$ digits; every digit is from $$$1$$$ to $$$9$$$.
You have to split this string into expressions of the form <integer>+<integer>. Every expression must be a contiguous part of the given string, and every character of the given string must belong to exactly one expression. For example, if you have a string 123+456+789+555, then:
Among all allowed ways to split the string, find one which maximizes the sum of results of all expressions you get, and print this sum.
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases.
Each test case consists of one line containing the string $$$s$$$ ($$$5 \le |s| \le 1000$$$) of the form <block of digits>+<block of digits>+...+<block of digits>. The string contains at least one '+' sign. Every block of digits consists of at least $$$2$$$ and at most $$$13$$$ digits; every digit is from $$$1$$$ to $$$9$$$.
For each test case, print one integer — the maximum possible sum of results of all expressions you get after splitting the string.
3123+456+789+55513+379999999999999+1111111111111+9999999999999
834 50 20111111111110
In the first test case of the example, you should split the string into expressions 123+4, 56+7 and 89+555. The sum of results of these expressions is $$$834$$$.
In the second test case of the example, the given string is already a valid expression and cannot be split any further.
Name |
---|