/*Shovkoplyas Grigory in the house*/
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<ctime>
#include<cassert>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<string>
#include<vector>
#include<set>
#include<map>
using namespace std;

#define name "hel"

const long long INF = (long long)1e18;


struct vertex{
  long long mn, mx, sm;
  vertex(){ mn = INF, mx = -INF, sm = 0;}
  vertex(int n){mn = n, mx = n, sm = n;} 
};

int n, x;
vector<vertex> t;



int step(int n)
{
  int i = 1;
  while(i < n)
    i <<= 1;
  return i;
}

void BuildTree()
{
  int i = x - 1;
  while(i > 0)
  {
    t[i].mx = max(t[2 * i].mx, t[2 * i + 1].mx);
    t[i].mn = min(t[2 * i].mn, t[2 * i + 1].mn);
    t[i].sm = t[2 * i].sm + t[2 * i + 1].sm;
    i--;
  }
   
}

void update(int a, int b)
{
  t[x + a - 1] = vertex(b);
  int i = x + a - 1;
  while(i > 1)
  {
    i /= 2;
    t[i].mx = max(t[2 * i].mx, t[2 * i + 1].mx);
    t[i].mn = min(t[2 * i].mn, t[2 * i + 1].mn);
    t[i].sm = t[2 * i].sm + t[2 * i + 1].sm;
  }
}

long long get_max(int v, int l, int r, int a, int b)
{
  if(a <= l && b >= r)
    return t[v].mx;
  if(b < l || a > r)
    return -INF;
  long long mx1 = get_max(2 * v, l, (l + r) / 2, a, b);
  long long mx2 = get_max(2 * v + 1, (l + r) / 2 + 1, r, a, b);
  return max(mx1, mx2);
}

long long get_min(int v, int l, int r, int a, int b)
{
  if(a <= l && b >= r)
    return t[v].mn;
  if(b < l || a > r)
    return INF;
  long long mn1 = get_min(2 * v, l, (l + r) / 2, a, b);
  long long mn2 = get_min(2 * v + 1, (l + r) / 2 + 1, r, a, b);
  return min(mn1, mn2);
}

long long get_sum(int v, int l, int r, int a, int b)
{
  if(a <= l && b >= r)
    return t[v].sm;
  if(b < l || a > r)
    return 0;
  long long s1 = get_sum(2 * v, l, (l + r) / 2, a, b);
  long long s2 = get_sum(2 * v + 1, (l + r) / 2 + 1, r, a, b);
  return s1 + s2;
}

int main()
{
  freopen(name".in", "r", stdin);
  freopen(name".out", "w", stdout);
  cin >> n;
  x = step(n);
  t.assign(2 * x + 1, vertex());
  for(int i = x; i < x + n; i++)
  {
    int a;
    cin >> a;
    t[i] = vertex(a);
  }
  BuildTree();
  cerr << t[1].mx << ' ' << t[1].mn << ' ' << t[1].sm << endl;
  int m;
  cin >> m; 
  for(int k = 0; k < m; k++)
  {
    string s;
    cin >> s;
    if(s == "assign")
    {
      int a, b;
      cin >> a >> b;
      update(a, b);
    }
    else
    {
      int a, b, c;
      cin >> a >> b >> c;
      long long mxx = get_max(1, 1, x, a, b);
      long long mnn = get_min(1, 1, x, a, b);
      long long sum = get_sum(1, 1, x, a, b);
      if(c > 0)
        cout << mxx * (c - 1) + sum << endl;
      else
        cout << mnn * (c - 1) + sum << endl;
    }
  }
  cerr << t[1].mx << ' ' << t[1].mn << ' ' << t[1].sm << endl;
  return 0;
}

                                    

