cswork / OAOpen practice workspace

eBayOA #7

Max Valid Expression in Puzzle Matrix

Estimated MediumJudge-ready

Topics (AI-labelled)StringsSimulation

An expression starts at any digit cell and can only go straight right or straight down, without turning. The characters must alternate as digit, +/-, digit; a single digit is also a valid expression. Find the maximum value of a valid path expression.

Input

h,w (1..100, hw≤10000); the character matrix contains only digits, +, and −, with at least one digit. The size limits are site supplements.

Output

Output the maximum value.

Example 1

Input:

1 5
9-1+8

Output:

16

Example 2

Input:

5 1
8
+
9
+
9

Output:

26

Example 3

Input:

2 3
1+2
3-4

Output:

4

Editorial

Loading solution…