Under construction

Still being built. Things may change

Last Word

Time limit1sMemory limit512 MB

Summary
Given a string and a sequence of substring(start, length) operations, output the characters that survive after all operations are applied in order.
Level

Medium4 of 10

Topics
String, Simulation, Implementation, Array
Solved
No attempts yet

Problem

The substring() function is a common operation on strings in most programming languages. It takes a start offset and a length, and builds a new string containing the characters in a sequence of that length beginning at the offset.

A certain string has had this function called on it a large number of times in a row. Using the standard library function substring(s, start, length) to chop it up repeatedly, what remains now is a possibly much shorter string.

Find the string that remains after all of these operations.

Input

  • The first line contains the string s (1 ≤ |s| ≤ 106).
  • The second line contains the number of operations n (1 ≤ n ≤ 106).
  • Each of the next n lines contains two integers starti and lengthi (0 ≤ starti < lengthi−1; 1 ≤ starti + lengthi ≤ lengthi−1).

Output

Output the string after all of the successive substring() operations.

Examples2

  1. Example 1

    Input
    helloworld
    2
    1 9
    0 5
    
    Expected output
    ellow
    
  2. Example 2

    Input
    abcdefghijklmnopqrstuvwxyz
    8
    1 24
    1 22
    1 20
    1 18
    1 16
    1 14
    1 12
    1 10
    
    Expected output
    ijklmnopqr