#K44877. Valid Arithmetic Expression Checker

    ID: 27629 Type: Default 1000ms 256MiB

Valid Arithmetic Expression Checker

Valid Arithmetic Expression Checker

This problem requires you to determine if a given string is a valid arithmetic expression. The expression may only contain digits (from \(0\) to \(9\)) and the operators plus (+) and minus (-). The expression is considered valid if it meets the following conditions:

  • The expression begins with one or more digits.
  • If an operator appears, it must be immediately followed by one or more digits.
  • There are no consecutive operators and no operator appears at the end of the expression.
  • No other characters (including spaces) are allowed.

For example, the expression "3+5-2" is valid, but "+4-2+3" or "7-+3" are invalid.

inputFormat

The input consists of a single line containing the arithmetic expression to be validated.

outputFormat

Output a single line: "valid" if the expression is valid, otherwise "invalid".## sample

3+5-2
valid

</p>