/**
 * Author: Sergey Kopeliovich (Burunduk30@gmail.com)
 */

#include <cstdio>
#include <cassert>
#include <cstring>
#include <algorithm>

using namespace std;

#ifdef _WIN32
#  define I64 "%I64d"
#else
#  define I64 "%Ld"
#endif

#define forn(i, n) for (int i = 0; i < (int)(n); i++)

typedef long long ll;

#define NAME "reverse"

const int maxn = (int)2e5 + 10;

int k, n, a[maxn];
ll sum[maxn];
int bn, b[maxn];

struct List
{
  int l, r;
  List *next;
  int rev;

  List() { l = r = -1, next = 0, rev = 0; }
  List( int _l, int _r, List *_next, int _rev ) : l(_l), r(_r), next(_next), rev(_rev) { }

  int len() { return r - l; }
  ll getSum() { return sum[r] - sum[l]; }
};

int tn;
List *root = new List(), *tmp[maxn];

void Build()
{
  bn = 0;
  for (List *v = root->next; v != 0; v = v->next)
    if (v->rev)
      for (int i = v->r - 1; i >= v->l; i--)
        b[bn++] = a[i];
    else
      for (int i = v->l; i < v->r; i++)
        b[bn++] = a[i];
  memcpy(a, b, sizeof(b[0]) * n);
  root->next = new List(0, n, 0, 0);
  forn(i, n)
    sum[i + 1] = sum[i] + a[i];

}

List *Split( int k )
{
  List *x = root;
  int tmp;
  while ((tmp = x->next->len()) <= k)
    k -= tmp, x = x->next;
  if (k > 0)
  {
    List *v = x->next;
    if (v->rev)
      swap(v->l, v->r), k = -k;
    List *a = new List(v->l, v->l + k, 0, v->rev);
    List *b = new List(v->l + k, v->r, 0, v->rev);
    if (v->rev)
      swap(a->l, a->r), swap(b->l, b->r);
    x->next = a, a->next = b, b->next = v->next;
    x = a;
  }
  return x;
}

int main()
{
  assert(freopen(NAME ".in", "r", stdin));
  assert(freopen(NAME ".out", "w", stdout));

  scanf("%d%d", &n, &k);
  forn(i, n)
    scanf("%d", &a[i]);
  n++;

  root->next = new List(0, n, 0, 0);
  Build();

  int cnt = 0;
  while (k--)
  {
    if (cnt++ == 440)
      Build(), cnt = 0;

    int type, l, r;
    scanf("%d%d%d", &type, &l, &r), l--;

    if (type) 
    {
      List *begin = Split(l), *end = Split(r);
      tn = 0;
      while (begin != end)
        tmp[tn++] = begin, begin = begin->next, begin->rev ^= 1;
      tmp[tn] = begin;
      tmp[1]->next = tmp[tn]->next;
      tmp[0]->next = tmp[tn];
      for (int i = tn; i > 1; i--)
        tmp[i]->next = tmp[i - 1];
    }
    else
    {
      List *begin = Split(l), *end = Split(r);
      ll res = 0;
      while (begin != end)
        begin = begin->next, res += begin->getSum();
      printf(I64 "\n", res);
    } 
  }
  return 0;
}