#include<bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN=1000005;
int n,t,a[MAXN];
char op;
struct SegmentTree{
int l,r;
int sum;
int minn;
int add;
int dat;
int lmax;
int rmax;
}tree[MAXN*4];
void pushup(int p)
{
tree[p].sum=tree[p*2].sum+tree[p*2+1].sum;
tree[p].minn=min(tree[p*2].minn,tree[p*2+1].minn);
return;
}
void pushdown(int p)
{
if(tree[p].add)
{
tree[p*2].sum+=tree[p].add*(tree[p*2].r-tree[p*2].l+1);
tree[p*2+1].sum+=tree[p].add*(tree[p*2+1].r-tree[p*2+1].l+1);
tree[p*2].minn+=tree[p].add;
tree[p*2+1].minn+=tree[p].add;
tree[p*2].add+=tree[p].add;
tree[p*2+1].add+=tree[p].add;
tree[p].add=0;
}
}
void build(int p,int l,int r)
{
tree[p].l=l;
tree[p].r=r;
if(l==r)
{
tree[p].sum=a[l];
tree[p].minn=a[l];
return;
}
int mid=(l+r)/2;
build(p*2,l,mid);
build(p*2+1,mid+1,r);
pushup(p);
}
int query(int p,int l,int r) //区查
{
if(l<=tree[p].l&&r>=tree[p].r) return tree[p].sum;
pushdown(p);
int c,v,mid=(tree[p].l+tree[p].r)/2;
if(l<=mid)c=query(p*2,l,r);
if(r>mid)v=query(p*2+1,l,r);
return c+v;
}
void upque(int p,int l,int r,int d) //区修
{
if(l<=tree[p].l&&r>=tree[p].r)
{
tree[p].sum+=d*(tree[p].r-tree[p].l+1);
tree[p].add+=d;
tree[p].minn+=d;
return;
}
pushdown(p);
int mid=(tree[p].l+tree[p].r)/2;
if(l<=mid) upque(p*2,l,r,d);
if(r>mid) upque(p*2+1,l,r,d);
pushup(p);
}
int minque(int p,int l,int r)
{
if(l<=tree[p].l&&r>=tree[p].r) return tree[p].minn;
pushdown(p);
int c,v,mid=(tree[p].l+tree[p].r)/2;
if(l<=mid) c=minque(p*2,l,r);
if(r>mid) v=minque(p*2+1,l,r);
return min(c,v);
}
signed main()
{
scanf("%lld%lld",&n,&t);
for(int i=1;i<=n;i++)
scanf("%lld",&a[i]);
build(1,1,n);
while(t--){
cin>>op;
if(op=='M'){
int x,y;
scanf("%lld%lld",&x,&y);
printf("%lld\n",minque(1,x,y));
}
if(op=='P'){
int x,y,d;
scanf("%lld%lld%lld",&x,&y,&d);
upque(1,x,y,d);
}
if(op=='S'){
int x,y;
scanf("%dll%lld",&x,&y);
printf("%lld\n",query(1,x,y));
}
}
return 0;
}