AROPE - Alphabetic Rope

no tags 

The Alphabetic Rope is now available in the market. The Alphabetic Rope consists of alphabetic characters in each stripe which looks like string. You are given an Alphabetic Rope consisting of lowercase alphabetic characters only. You have to perform some operations on rope and answers some queries on it.

Queries are of 3 types:

  • 1 X Y: Cut the rope segment from X to Y and join at the front of rope.
  • 2 X Y: Cut the rope segment from X to Y and join at the back of rope.
  • 3 Y: Print on a new line the character at Yth position of current rope.

Input

There is only one input. Input begins with single line giving Alphabetic Rope as a string S. Next line contains Q, following Q lines give Queries as mentioned above. (Index used are 0-based.)

Output

For each query of type 3, print a single character in a new line.

Constraints

1 <= |S| <= 100000. (Length of string)

1 <= Q <= 100000. (Number of queries)

Example

Input:
gautambishal
3
3 1
2 0 5
3 0

Output:
a
b

hide comments
zhouyexuan: 2022-10-18 07:43:26

Why RE?

DOT: 2018-09-09 09:37:48

Easy question if you know a data structure(I used Treap) that can handle dynamic position changes.

robbin: 2018-03-06 16:08:49

"#include <ext/rope>" built-in rope data structure can be used in C++ to solve this problem.

anonymous: 2017-03-24 22:17:54

Note that ranges are inclusive, i.e., 1 X Y describes a range [X..Y].

s/Alphabet/letter/

entcat: 2017-01-24 22:48:54

pretty easy with "known" STL

razor_sony: 2016-12-29 09:21:14

what's the problem in this code!

[code snipped]

Last edit: 2016-12-29 12:20:10
darpanjbora: 2016-12-16 17:01:18

GETTING NZEC ERROR !!

Last edit: 2016-12-16 18:25:27
venky1001: 2016-12-11 20:21:54

TLE with fast i/o in java :/

♥☻♥ David ♥☻♥: 2016-11-26 20:29:28

Time limit for C# language should be relaxed a bit to get AC.


Added by:BISHAL GAUTAM
Date:2016-11-24
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64 GOSU
Resource:MySelf