cswork / OAOpen practice workspace

SnowflakeOA #9

Work Schedule — Fill Question Marks to Match Total

Estimated MediumJudge-ready

Topics (AI-labelled)Enumeration

Replace each question mark in the seven-digit pattern with a value in 0..day_hours so that the weekly total is exactly work_hours. Fixed digits stay unchanged. Return all schedules in ascending lexicographic order. At least one valid schedule is guaranteed.

Input

The first line contains work_hours day_hours, and the second line contains the 7-digit pattern. 1≤work_hours≤56, 1≤day_hours≤8; the pattern consists of 0..8 or ?, and fixed hours do not exceed the daily limit. The original constraints omitted ?, which is restored from the body text.

Output

First output the number of schedules R, then one 7-digit schedule per line; all schedules must be output in ascending lexicographic order.

Example 1

Input:

3 2
?1?0000

Output:

3
0120000
1110000
2100000

Example 2

Input:

1 1
???????

Output:

7
0000001
0000010
0000100
0001000
0010000
0100000
1000000

Example 3

Input:

56 8
???????

Output:

1
8888888

Example notes

The answers to the three public examples are, in order: 3 0120000 1110000 2100000; 7 0000001 0000010 0000100 0001000 0010000 0100000 1000000; 1 8888888. All examples have been verified by independent small-scale enumeration or state search.

Editorial

Loading solution…