#K62827. Credit Card Validator Using the Luhn Algorithm

    ID: 31618 Type: Default 1000ms 256MiB

Credit Card Validator Using the Luhn Algorithm

Credit Card Validator Using the Luhn Algorithm

Your task is to implement a credit card validation program that checks whether a given credit card number is valid based on the Luhn algorithm. The algorithm works by processing the digits of the card number from right to left, doubling every second digit and subtracting 9 if the result is greater than 9. The card is considered valid if the total sum of all digits is divisible by 10, i.e., $$\sum_{i=1}^{n} d_i\ \bmod\ 10 = 0.$$

The input number can contain spaces or hyphens as delimiters. Before processing, remove any non-digit characters. Also note that valid credit card numbers must have a length between 13 and 19 digits after stripping these characters.

inputFormat

Input is provided on standard input (stdin) as a single line containing the credit card number as a string. The number may include spaces or hyphens.

outputFormat

Output a single line to standard output (stdout): print "VALID" if the card number is valid according to the Luhn algorithm, otherwise print "INVALID".## sample

4539 3195 0343 6467
VALID