Question 2 Counting Crows

Finding blackbirds, three in a row, all in the snow

The University of Waterloo's Ornithology Center has data they need analysed. They have collected data on the grouping habits of different bird species, using computers to snatch poor quality images of birds sitting on hydro wires. The birds collect in long `strings' along the wires. Your job is to count the birds in the strings and produce a report of that counting in a form desired for the Journal of Ornithological Grouping Counts.

Due to the poor quality of the data, the ornithologists believe that the computer often mistakes one type of bird with another, but believe they can correct for this by ignoring data inconsistent with known grouping patters of birds.

A `string' of birds is a group of at least three birds, each separated by no more than two other birds. `AooAooAoeeAoe' would be a string of seven `A' birds and a string of six `e' birds, and `aBBaBcBBaaBaBacCd' would be a string of twelve `B' birds. The ornithologists appear unconcerned with the longest string of birds it is possible to produce, preferring to deal with the data on a first come, first served basis.

The output must be in a specific order, so that the pecking order of the different bird species is made clear. Each species prefers a particular position on the wires, the most important bird near the center of that preference, and the less important birds surrounding it. In order to preserve this information, the following format is desired.

First, a printed numberline, in the format shown in the sample below. Under this line, print the string of birds with the lowest starting number. Other strings should follow on the same line, if it is possible to print them without overlap. Strings that would overlap should be printed on the next line, again following the rule of lowest start gets printed first. If the start of two strings is the same, the string with the lowest ending gets printed first. If the start of two strings is the same, the string with the lowest ending gets printed first. There will be no strings with the same start and end numbers.

Input:

abcbcbdsabadfsaassddswsrwads
eereweejeeweejkjejjkwjkejek
andenadenadqenaembps
azsxdcfvazsxdcfvazsxdcfvazsxdcfvazsxdcfvazsxdcfvaasdadsaweadaweaas
lkljbvkklsfaswiijsjwajasdkh

Output:

0123456789 1234567890123456789 1234567890123456789 1234567890123456789
eeeeeeeeeeeeessssssssss                         aaaaaaaaaaaaaaaaa
 bbbbb       jjjjjjjjjjjj
		jjjjjj

Limits:

No line of input will be longer than 70 characters long. There will be no two strings that will have starting and ending numbers that both match. The number of input lines will not exceed 1000. The number of bird species strings will not exceed 500. The number of different bird species shall not exceed 64 (upper and lowercase letters, 0-9 and -+).