#P8022. Partitioning a Number String

    ID: 21206 Type: Default 1000ms 256MiB

Partitioning a Number String

Partitioning a Number String

Given a numeric string (N) of length (k) and three prime numbers (p, q, r), partition (N) into three non-empty parts such that:

1. The first part is divisible by (p).
2. The second part is divisible by (q).
3. The third part is divisible by (r).

Each part must not contain any leading zeros (except when the part is exactly (0)).

inputFormat

The input consists of two lines:
1. The first line contains the numeric string (N).
2. The second line contains three space‐separated prime numbers (p, q, r).

outputFormat

If a valid partition exists, print the three parts separated by a single space. Otherwise, print (-1).

sample

1236
2 3 2
12 3 6