/*  -*- coding: utf-8 -*-
 *
 * f.cc: F - Max Matrix
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 200000;
const int MAX_E2 = 1 << 19; // = 524288
const int MAX_QN = 200000;

/* typedef */

typedef long long ll;

struct Qry {
  int t, x, y;
  Qry() {}
  Qry(int _t, int _x, int _y): t(_t), x(_x), y(_y) {}
  void read() { scanf("%d%d%d", &t, &x, &y); x--; }
  void print() { printf("Qry(%d,%d,%d)\n", t, x, y); }
};

template <typename T, const int MAX_E2>
struct SegTreeSum {
  int e2;
  T nodes[MAX_E2];
  SegTreeSum() {}

  void init(int n) {
    for (e2 = 1; e2 < n; e2 <<= 1);
    //fill(nodes, nodes + MAX_E2, 0);
  }

  T &geti(int i) { return nodes[e2 - 1 + i]; }

  void set(int i, T v) {
    int j = e2 - 1 + i;
    nodes[j] = v;
    while (j > 0) {
      j = (j - 1) / 2;
      nodes[j] = nodes[j * 2 + 1] + nodes[j * 2 + 2];
    }
  }
  void add(int i, T v) { set(i, geti(i) + v); }
  
  T sum_range(int r0, int r1, int k, int i0, int i1) {
    if (r1 <= i0 || i1 <= r0) return 0;
    if (r0 <= i0 && i1 <= r1) return nodes[k];

    int im = (i0 + i1) / 2;
    T v0 = sum_range(r0, r1, k * 2 + 1, i0, im);
    T v1 = sum_range(r0, r1, k * 2 + 2, im, i1);
    return v0 + v1;
  }
  T sum_range(int r0, int r1) { return sum_range(r0, r1, 0, 0, e2); }
};

/* global variables */

Qry qs[MAX_QN];
int as[MAX_N], bs[MAX_N], uas[MAX_N + 1], ubs[MAX_N + 1];
SegTreeSum<int,MAX_E2> asti, bsti;
SegTreeSum<ll,MAX_E2> astl, bstl;

/* subroutines */

inline int get_index(int un, int us[], int v) {
  return lower_bound(us, us + un, v) - us;
}

/* main */

int main() {
  int n, m, qn;
  scanf("%d%d%d", &n, &m, &qn);

  int uan = 0, ubn = 0;
  uas[uan++] = ubs[ubn++] = 0;

  for (int i = 0; i < qn; i++) {
    qs[i].read();
    if (qs[i].t == 1) uas[uan++] = qs[i].y;
    else ubs[ubn++] = qs[i].y;
  }

  sort(uas, uas + uan);
  sort(ubs, ubs + ubn);
  uan = unique(uas, uas + uan) - uas;
  ubn = unique(ubs, ubs + ubn) - ubs;

  asti.init(uan), astl.init(uan);
  asti.set(0, n);
  bsti.init(ubn), bstl.init(ubn);
  bsti.set(0, m);

  ll sum = 0;
  for (int i = 0; i < qn; i++) {
    Qry &qi = qs[i];
    //qi.print();

    if (qi.t == 1) {
      int pa = as[qi.x];
      if (pa != qi.y) {
	int i0 = get_index(ubn, ubs, pa);
	sum -= (ll)pa * bsti.sum_range(0, i0) + bstl.sum_range(i0, ubn);
	int j0 = get_index(uan, uas, pa);
	asti.add(j0, -1), astl.add(j0, -pa);

	int i1 = get_index(ubn, ubs, qi.y);
	sum += (ll)qi.y * bsti.sum_range(0, i1) + bstl.sum_range(i1, ubn);
	int j1 = get_index(uan, uas, qi.y);
	asti.add(j1, 1), astl.add(j1, qi.y);
	as[qi.x] = qi.y;
      }
    }
    else {
      int pb = bs[qi.x];
      if (pb != qi.y) {
	int i0 = get_index(uan, uas, pb);
	sum -= (ll)pb * asti.sum_range(0, i0) + astl.sum_range(i0, uan);
	int j0 = get_index(ubn, ubs, pb);
	bsti.add(j0, -1), bstl.add(j0, -pb);

	int i1 = get_index(uan, uas, qi.y);
	sum += (ll)qi.y * asti.sum_range(0, i1) + astl.sum_range(i1, uan);
	int j1 = get_index(ubn, ubs, qi.y);
	bsti.add(j1, 1), bstl.add(j1, qi.y);
	bs[qi.x] = qi.y;
      }
    }

    printf("%lld\n", sum);
  }
  return 0;
}

#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a),i##end=(b);i<i##end;i++)
#define REP(i,a,b) for(int i=(a),i##end=(b);i<=i##end;i++)
#define RFOR(i,a,b) for(int i=(a),i##end=(b);i>i##end;i--)
#define RREP(i,a,b) for(int i=(a),i##end=(b);i>=i##end;i--)
typedef long long LL;

const int maxn=100+5;
int n,A[maxn];
char s[maxn];
int main() {
	scanf("%d%s",&n,s);
	REP(i,0,n) scanf("%d",&A[i]);
	int k=std::abs(A[1]-A[0]);
	REP(i,1,n) k=std::min(k,std::abs(A[i]-A[i-1]));
	printf("%d\n",k);
	FOR(i,0,k) {
		REP(j,0,n) printf("%d ",(A[j]+i)/k);
		putchar('\n');
	}
	return 0;
}
