#ACSL2021S1. ACSL2021S1

ACSL2021S1

PROBLEM: Construct a Numeral Hex Triangle according to the following rules. You will be given three positive integers: s, a starting number, d, a delta (the amount by which to increase each number in the triangle); and r the number of rows. The numbers s and d will be in hexadecimal.

  1. The first row contains the number s.
  2. Each of the next rows has one more number than the previous row.
  3. Each number in the triangle is d more than the previous number in the triangle Here are two examples of Numeral Hex Triangles:

image

INPUT: There are 5 lines of data. Each line has 3 positive integers, s, d, and r. The numbers are separated by spaces and each is less than 1,000,000. Recall that s and d are in hexadecimal.

OUTPUT: For each line of data, print the sum of all of the numbers on the r-th row of the Numeral HexTriangle, transformed into a single hexadecimal digit. To transform the sum, add the digits in base 16. Ifthat sum is more than one hex digit, continue this process until a single hex digit is reached. For example if the last row were 1A161A_{16}, 1F161F_{16} and 241624_{16} the sum is 211621_{16} ,. This is more than a single hex digit, so we add 216+116=3162_{16}+1_{16}=3_{16}

SAMPLE INPUT:

A 9 5
ABC F 4
BAD 50 10
FED ABC 25
184 231 35

SAMPLE OUTPUT:

5
C
A
F
5