PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#PS0000260. Dịch chuyển chữ cái II (Shifting Letters II)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Dịch chuyển chữ cái II (Shifting Letters II)

Shifting Letters II

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

Given a lowercase string SS of length NN, indexed from 0, each operation (l,r,d)(l,r,d) shifts every character in [l,r][l,r] by one alphabet position, forward for d=1d=1 and backward for d=0d=0, wrapping between a and z. Print the final string.

Input

First line: N,QN,Q. Second line: SS. Next QQ lines: l,r,dl,r,d.

Output

Print the resulting string.

Subtasks

  • Subtask 1 (20 points): 1≤N≤1001\le N\le 100; 1≤Q≤1001\le Q\le 100; 0≤l≤r<N0\le l\le r<N; d∈{0,1}d\in\{0,1\}; S consists of N lowercase letters a–z.
  • Subtask 2 (30 points): 1≤N≤500001\le N\le 50000; 1≤Q≤500001\le Q\le 50000; 0≤l≤r<N0\le l\le r<N; d∈{0,1}d\in\{0,1\}; S consists of N lowercase letters a–z; l=rl=r.
  • Subtask 3 (50 points): 1≤N≤500001\le N\le 50000; 1≤Q≤500001\le Q\le 50000; 0≤l≤r<N0\le l\le r<N; d∈{0,1}d\in\{0,1\}; S consists of N lowercase letters a–z.

Example 1

Input

3 3
abc
0 1 0
1 2 1
0 2 1

Output

ace

Explanation

abc → zac → zbd → ace.

Example 2

Input

4 2
dztz
0 0 0
1 1 1

Output

catz

Explanation

Shift d backward to c, then z forward to a.