Bank Card Verifier

Each test case gives a 16-digit card number as four 4-digit groups; apply the Luhn checksum rule and print Yes if the total is a multiple of 10, otherwise No.

Easy3ImplementationStringMathSimulationInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

A payment card number is 16 digits long. The leftmost 6 digits identify the bank that issued the card. The next 2 digits give the card type, for example debit, credit, or gift. Digits 9 to 15 are the serial number of the card, and the last digit is a control digit that says whether the whole number is valid. A payment program can therefore catch most mistyped numbers on the spot.

In a valid card number the last digit is chosen so that this procedure succeeds:

  1. Label the digits from left to right with 1 to 16.
  2. Multiply every odd-labeled digit by 2.
  3. If a result of step 2 is greater than 9, subtract 9 from it.
  4. Add up the results of step 3, then add the sum of all even-labeled digits.
  5. If the total is a multiple of 10, the card number is valid. Otherwise it is invalid.

Read several card numbers and decide for each one whether it is valid.

Input

The input holds several test cases. Each test case is one line with four 4-digit strings separated by single spaces. The leftmost digit of a card number is never zero. The input ends with a line reading 0000 0000 0000 0000, which is not a test case.

Output

For each test case print one line: Yes if the card number is valid, No if it is not.