Cakewalk

3

5 votes
Problem

You are given a collection of words, say as in a dictionary.

You can represent it in the following compressed form:

The first word will be followed by a sequence of pair of a integer (x) and a word.

The number in the pair is the position till which the previous word's characters are included in the new word and the tail is the remaining trailing word which is the different than the previous word.

Example:

Suppose successive words in our dictionary are:

color

comma

commatose

dot

Then we can compress it in the following way:

color

2 mma (to denote that first two characters are same as that of 'color' and remaining string is 'mma')

5 tose (to denote that the first five characters are same as that of 'comma' and remaining string is 'tose')

0 dot (to denote that zero characters are same as that of 'commatose' and the remaining string is 'dot')

INPUT :

First line contains the integer 'N' denoting the number of words in the dictionary.

Second line would contain the first word.

It will be followed by 'N-1' lines each containing an integer (x) and a trailing string.

Note: The input is designed such that the integer (x) will always be <= size of previous word formed.

OUTPUT :

Output a single string that is the last resulting word of the given dictionary.

Constraints

1<=N<=1000

1<=Length of all string that will appear in input file <=50

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

The dictionary actually is: zebra zebu (3 first characters are common with zebra) zenith (2 first characters are common with zebu) zggurat (1 first character is common with zenith)

Editor Image

?