#B3806. D-- Enumeration Structure Validator and Counter
D-- Enumeration Structure Validator and Counter
D-- Enumeration Structure Validator and Counter
D-- is a futuristic language from the year 2077. It introduces an "enumeration structure" which is represented by the following expression:
X Y Z W
In this expression:
- X and Z are single lowercase letters representing variable names.
- Y and W are integers representing the start and end values for enumeration.
For safety purposes, to successfully enumerate the variable X, it is required that Z is identical to X.
For example, a valid enumeration structure is:
i 1 i 100
This represents enumerating variable i from 1 to 100.
Your task is to process a given D-- enumeration expression X Y Z W
and perform the following:
- Check Validity: The expression is considered valid only if:
- X and Z are lowercase letters.
- X is equal to Z.
- Y and W are integers. (You may assume this always holds in the given input.)
- Count Enumeration Steps: If the expression is valid, compute the number of enumeration steps. If Y ≤ W, then the number of steps is W − Y + 1, otherwise it is Y − W + 1.
If the expression is invalid, output error
.
inputFormat
The input consists of a single line containing four space-separated items: X Y Z W
, where X and Z are letters and Y and W are integers.
outputFormat
If the expression is valid, output the number of steps the variable is enumerated across. Otherwise, output error
.
sample
i 1 i 100
100