AlgoUniversity
  • Go Back
Discussion
String Substitution :

Author

Gigaliths

Difficulty Level : Medium

Submissions : 623

Asked In : Google

Marks :10

: 12 | : 4

You are given a string $$$S$$$ , and a list of strings which needs to be substituted in the input string $$$S$$$.

A substitution is a tuple $$$( L_i , R_i , subs_i ) $$$ which denotes that we need to substitute the substring $$$S[ L_i ... R_i ]$$$ with $$$subs_i$$$.

It is guaranteed that all the intervals are non-overlapping.

You must find out the modified string $$$S_m$$$ after incurring all substitutions.

Input

First line contains a string corresponding to $$$S$$$

Second line contains a single integer N corresponding to the total number of substitutions

N lines are followed containing each tuple $$$( L_i , R_i , subs_i )$$$

Contraints

$$$ 1 \le |S| \le 1000000 $$$

$$$ 1 \le L_i \le R_i \le 1000000 $$$

Output

A single string $$$ S_m $$$ which corresponds to the modified string after all substitutions.

Example

Input
Alice_saw_a_tiger
2
0 4 Bob
12 18 Cat
Output
Bob_saw_a_Cat

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.