Reorder Reverse


Problem Statement

You are give an initial string ss of length nn. You are also given qq queries, in order, each containing two integers ll and rr meaning you should reverse the substring from ll to rr (00-indexed and inclusive) of your current string (which was initially ss but may have undergone changes from the queries). Each query should be processed in order and you should be reversing the string after all the reverses before it had already been done.

Determine the string after all queries are done.

Input Format

Your first line will contain nn and qq. Your next line will contain ss. Your next qq lines will contain two integers each, representing ll and rr for that query.

Output Format

You should output the final string after all the reverse operations are performed.

Constraints

Subtask 1

  • 1n,q1031 \leq n, q \leq 10^3
  • 0lrn10 \leq l \leq r \leq n - 1

Subtask 2

  • 1n,q1051 \leq n, q \leq 10^5
  • 0lrn10 \leq l \leq r \leq n - 1

Sample Cases

Input 1
9 3
something
1 2
1 5
0 7
Output 1
nimoethsg
Input 2
10 3
hellohello
0 4
5 9
0 9
Output 2
hellohello

Comments0


No comments yet

Be the first to comment.

New comment


Log in to join the discussion.