문제
Farmer John is trying to hire contractors to help rearrange his farm, but so far all of them have quit when they saw the complicated sequence of instructions FJ wanted them to follow. Left to complete the project by himself, he realizes that indeed, he has made the project perhaps more complicated than necessary. Please help him follow his instructions to complete the farm upgrade.
FJ's farm consists of
1) Given a contiguous interval of fields, add a new haybale to each field.
2) Given a contiguous interval of fields, determine the minimum number of haybales in a field within that interval.
3) Given a contiguous interval of fields, count the total number of haybales inside that interval.
SAMPLE INPUT:
4 5
3 1 2 4
M 3 4
S 1 3
P 2 3 1
M 3 4
S 1 3
SAMPLE OUTPUT:
2
6
3
8
Problem credits: Nick Wu
입력
The first line contains two positive integers,
The next line contains
Each of the next
If the letter is M, print the minimum number of haybales in the interval of fields from
If the letter is P, put
If the letter is S, print the total number of haybales found within interval of fields from
출력
A line in the output should appear in response to every 'M' or 'S' entry in FJ's instructions.
예제1
4 5
3 1 2 4
M 3 4
S 1 3
P 2 3 1
M 3 4
S 1 3
2
6
3
8