Under construction

Still being built. Things may change

Sherlock Holmes

Time limit1sMemory limit1024 MB

Summary
For each month, count five-digit numbers formed by N1 = month + 10, the digit s, and a valid N3 <= N, where the concatenation is divisible by the sum of some two of the three volumes; also output the triple with smallest N3 for the given month.
Level

Medium6 of 10

Topics
Brute force, Number theory, Implementation, Math
Solved
No attempts yet

Problem

Racho is a collector. He owns exactly one volume of each book in the Sherlock Holmes series. There are N volumes, numbered with the integers from 1 to N.

Every month Racho wants to read 3 different volumes of the series. To choose them he follows this rule. At the start of the year Racho picks a single-digit number s (from 1 to 9 inclusive) at random and arranges the volumes side by side so that

  • the number N1 of the first volume is chosen by adding 10 to the number of the current month (1, 2, …, 12);
  • the number N2 of the second volume is the number s Racho picked;
  • for the third volume Racho takes one of the remaining volumes, but one whose number N3 is not a single-digit number and cannot be obtained by adding 10 to the number of any month;
  • the five-digit number obtained by writing the digits of N1, N2, N3 one after another must be divisible by at least one sum of some two of the numbers N1, N2, N3.

Write a program sherlok that, for each month of the year, finds the number of different five-digit numbers that can be obtained by the rule described. The program must also output the values of N1, N2 and N3 for the current month, so that Racho knows which volumes to read. If there is more than one such triple of values, output the triple in which N3 is smallest. If no such triple can be found, output three zeros separated by one space each.

Input

The first line of the standard input contains 3 integers: N, the number of volumes; s, the number Racho picked; and M, the number of the current month.

Output

On the first twelve lines of the standard output, print in order for each month of the year the corresponding number of possibilities, one number per line. On the last line print three integers equal to the numbers of the three volumes Racho will read in the current month. These numbers must be separated by one space each.

Constraints

  • 23 ≤ N ≤ 9999
  • 1 ≤ s ≤ 9
  • 1 ≤ M ≤ 12

Examples2

  1. Example 1

    Input
    99 3 3
    
    Expected output
    10
    8
    7
    6
    4
    8
    4
    5
    3
    8
    5
    5
    13 3 28
    
  2. Example 2

    Input
    99 7 5
    
    Expected output
    4
    6
    3
    3
    4
    6
    3
    6
    4
    8
    3
    4
    15 7 30