A mail order company is in great trouble. It maintains a file containing records of address of its customers. Due to mishandling the file is corrupted and there is no back up of the file. The company needs a program to recover the addresses. You are required to develop a program for the company. The company provides you with the following information:
1. Generally a record in the file contains five fields: Id-no, Name, Location, Post-office, and Area. However the field named Area may or may not be present in an address. Hence the total number of fields in a record is either 4 or 5. Initially the fields are arranged in the order, called the normal order, in which they are mentioned above. But due to mishandling, the order of the fields (but not the contents) might have changed.
2. Each record begins with the begin-record-line containing the character @ followed by an integer representing the record number. The file ends with the end-file-line containing the character $ followed by an integer representing the total number of records in the file.
3. A field has one or more lines. Id-no, Name and Post-office contain only one line each while Location has at least one line and Area, if present, may have one or more lines.
4. A line is a sequence of words terminated by a semi-colon. The blank character is used freely to separate words in a line. Sometimes a comma may also be used to separate words in Name, Location and Area. Likewise a hyphen may be present between two words in Id-no and Post-office.
5. A word may be alphabetic (string of letters a-z, A-Z), numeric (string of digits 0-9) or alphanumeric (string of letters a-z, A-Z and/or digits 0-9).
6. Id-no may contain any type of word. In addition to the blank character, at least one hyphen is used to separate words in Id-no.
7. Words in Name are alphabetic. A Name has two parts: a name-part and a surname-part. Normally the surname-part appears at the end. However if it appears at the beginning then a comma separates it from the name-part.
8. Like Id-no, Location may contain any type of words. However hyphen is never used in Location.
9. Post-office contains a pin-code represented by a six-digit numeric word. The pin-code is preceded by one or more alphabetic words identifying the name of the post-office. In addition to the blank character a hyphen may also be used to separate the pin-code from the name of the post office.
10. Area, when present, contains only alphabetic words. However each word in Area begins with a capital letter and may end up with a comma.
Due to imprecise information stated above, a line of the corrupted file may appear to belong to more than one field. As a result it may not be always possible to recover a record uniquely or recover it at all. In case more than one option is available, all possible options for recovering the record should be identified and reported. In each recovered record the contents of the fields should be reserved exactly as they appeared in the input, only the order of fields need to be changed.