#C14486. ISBN-10 Validation

    ID: 44140 Type: Default 1000ms 256MiB

ISBN-10 Validation

ISBN-10 Validation

You are given a string representing an ISBN-10 number which may include extra spaces and hyphen characters. Your task is to determine whether the ISBN is valid.

An ISBN-10 is valid if, after removing all spaces and hyphens, the resulting string has exactly 10 characters, the first 9 of which are digits and the last character is either a digit or the letter X (which represents 10). The validity is determined by the following checksum formula:

\[ \text{checksum} = \sum_{i=1}^{10} i \times d_i \]

where \(d_i\) is the value of the \(i\)-th digit (with \(d_{10}=10\) if the character is X). The ISBN is valid if \(\text{checksum} \equiv 0 \pmod{11}\).

For example:

  • "0-306-40615-2" is valid.
  • "123456789X" is valid.
  • "12345 67892X" is invalid.

inputFormat

The input consists of a single line containing the ISBN-10 string, which may include spaces or hyphens.

outputFormat

Output a single line: True if the given ISBN-10 is valid, or False otherwise.

## sample
0-306-40615-2
True