Recording a tape 

The market offers several types of cassette tapes, with standard time durations. You have some of these types at home, and you want to record all songs from a given list. The songs you hope to record have their time durations expressed, as usual, in minutes and seconds. Given the list of songs, find the list per side in which they have to be recorded in order to use the shortest possible available cassette for recording them.

Input 

The first line in the input file informs the cassette durations available; each of the following lines contain the duration of one song. The input file contains several instances, that follow this same specification, which finish with a line containing only a % (percentage symbol).

Output 

The first line should contain the duration of the cassette. Next, ``Side A'' should be printed followed by lines with the song durations for this side. ``Side B'' follows in the same manner. The output file should have a % (percentage symbol) printed after the output of each of the several input instances.

Sample Input 

56 90 120
20m 44s
4m 36s
7m 18s
13m 8s
9m 6s
8m 12s
%
30 45
3m 11s
4m 45s
13m 45s
6m 8s
%

Sample Output 

90
Side A
20m 44s
4m 36s
7m 8s
Side B
13m 8s
9m 6s
8m 12s
%
30
Side A
3m 11s
4m 45s
6m 8s
Side B
13m 45s
%


Observations: No pair of songs have the same duration.



Miguel Revilla
2000-12-30