P27854 [洛谷] [Language Month Competition 202307] Enumeration Structure
普及-
题目描述

Problem Description

D-- is an emerging language in the year 2077. In the D-- language, an "enumeration structure" has been introduced. Specifically, this structure can be represented by the following expression:

X Y Z W

Here, $X$ and $Z$ are single lowercase letters representing variable names; $Y$ and $W$ are integers representing the start and end values of the enumeration. It signifies that the variable $X$ is enumerated from $Y$ to $W$.

Due to D--'s pursuit of ultimate security, for the enumeration of variable $X$ to be successful, $Z$ must be the same as $X$.

For example, a valid enumeration structure expression is as follows:

i 1 i 100

This means that the variable $i$ is enumerated from $1$ to $100$.


Now you have received a D-- enumeration structure expression X Y Z W. Please determine and calculate the following:

  1. The validity of the expression
    An enumeration structure expression is considered valid only if it meets all of the following conditions:
  • Both $X$ and $Z$ are lowercase letters.
  • $X$ and $Z$ are the same.
  • Both $Y$ and $W$ are integers. In the given expression, we guarantee that this condition is always met.
  1. The number of times the expression will enumerate
    For a valid enumeration expression, if $Y \leq W$, it will enumerate $W - Y + 1$ times; otherwise, it will enumerate $Y - W + 1$ times.

Input Format

Input consists of a single line containing an expression X Y Z W, where $X$ and $Z$ are single lowercase letters or digits, and $Y$ and $W$ are integers.

Output Format

Output consists of two lines.

The first line is a string. If the given expression is valid, output valid; otherwise, output Invalid.
The second line is an integer. If the given expression is not valid, output -1; otherwise, output the number of times the expression will enumerate.

Sample Input and Output

Sample Input #1

i 1 i 100

Sample Output #1

valid
100

Sample Input #2

I 1 j 100

Sample Output #2

Invalid
-1

Notes

Data Range and Constraints

For an expression X Y Z W, for $100\%$ of the data, $-2 \times 10^9 \leq Y, W \leq 2 \times 10^9$, and $X, Z$ are single lowercase letters, uppercase letters, or digits.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
i 1 i 100
样例输出
valid 100