You You See What?
InterviewTime limit10sMemory limit1024 MB
Remove the repeated machine hops from a UUCP bang path so the mail reaches the same recipient through a shorter route.
Problem
Forty-some years ago, email was sent with a protocol called UUCP (UNIX-to-UNIX Copy Program). The sender had to know every machine name on the path to the recipient and write those machine names (hops) into the recipient's UUCP address. Such an address was called a bang path. A bang path is a list of machine names separated by exclamation points, ending with the recipient's account name on the last machine. For example:
texasam!rice!baylor!csdept!bresearch!bpoucher
This address tells the sender's system to send the mail to the "texasam" machine. Texasam sends it to "rice", rice sends it to "baylor", baylor sends it to "csdept", and csdept sends it to "bresearch". At the last machine, bresearch, the mail is delivered to user "bpoucher". Any error along the way (unknown machine, machine down, and so on) was supposed to send an email back to the sender describing the problem. Bang paths of eight or ten machines were common. The sender was responsible for routing, so they had to know how to reach the recipient's machine in as many hops as needed. Machines often exchanged mail over dial-up modems once or twice a day, since there was no internet yet, so an email could take days to arrive.
While several machines on the UUCP network could share the same name, two machines with the same name were not allowed to talk to a common machine. In the example above, baylor could not directly communicate with two different machines named csdept.
Sometimes inexperienced users put loops in their bang path:
texasam!rice!baylor!csdept!baylor!rice!dev!bresearch!bpoucher
This still works, but it is inefficient and delays the mail. Rice sends to baylor, baylor sends to csdept, csdept sends back to baylor, baylor sends back to rice, and rice finally sends to dev. Removing the steps csdept!baylor!rice gives the same result, and the mail arrives sooner. A machine may also forward mail to itself:
texasam!Rice!rice!rice!rice!rice!bpoucher
Here all but one of the rice hops can be removed, giving texasam!Rice!bpoucher.
Read a bang path, remove the unnecessary hops, and output the new, possibly shorter, bang path.
Input
The single line of input contains a valid bang path. The string is at least one character long and at most 256 characters. Each component of the bang path, including the user name at the end, is between 1 and 10 alphanumeric characters. Components are separated by a single exclamation point (!). Machine names and user names are case-insensitive but case-preserving. If the bang path has no exclamation points, the single component is a user name on the sender's machine.
Output
Output a single line containing the possibly shorter bang path. Machine names are compared case-insensitively, but the output keeps the original case of each name. When several spellings of the same machine appear, you may keep any one of them.