Problem: Problem

Given a sequence $ A $ of length $ H $ and a sequence $ B $ of length $ W $.

Define the matrix $ C $ consisting of $ H $ rows and $ W $ columns as follows.
$ C_ {i, j} = A_i \ times B_j (1 \ leq i \ leq H, 1 \ leq j \ leq W) $

Process the following four types of queries a total of $ Q $ times.

Query 1
$ 1 $ $ a $ $ b $ $ v $
$ A_i (a \ leq i \ leq b) Add $ v $ to $

Query 2
$ 2 $ $ c $ $ d $ $ v $
$ B_j (c \ leq j \ leq d) Add $ v $ to $

Query 3
$ 3 $ $ a $ $ b $ $ c $ $ d $
$ C_ {i, j} (a \ leq i \ leq b, c \ leq j \ leq d) Output the minimum value of $ and its number

Query 4
$ 4 $ $ a $ $ b $ $ c $ $ d $
$ C_ {i, j} (a \ leq i \ leq b, c \ leq j \ leq d) Output the maximum value of $ and its number

For details, refer to sample input / output.

Constraints

The input satisfies the following conditions.

* $ 1 \ leq H, W, Q \ leq 10 ^ 5 $
* $ -1000 \ leq A_i \ leq 1000 $
* $ -1000 \ leq B_j \ leq 1000 $



For each query, the input satisfies the following conditions.


* $ 1 \ leq a \ leq b \ leq H $
* $ 1 \ leq c \ leq d \ leq W $
* $ -1000 \ leq v \ leq 1000 $

Input

The input is given in the following format.


$ H $ $ W $ $ Q $
$ A_1 $ $ A_2 $ ... $ A_H $
$ B_1 $ $ B_2 $ ... $ B_W $
$ query_1 $
$ query_2 $
...
$ query_Q $


Each query is given in one of the following four formats.


$ 1 $ $ a $ $ b $ $ v $
$ 2 $ $ c $ $ d $ $ v $
$ 3 $ $ a $ $ b $ $ c $ $ d $
$ 4 $ $ a $ $ b $ $ c $ $ d $


All inputs are given as integers.
$ H $, $ W $, $ Q $ are given on the first line, separated by blanks.
In the second row, the element $ A_i $ ($ 1 \ leq i \ leq H $) of the sequence $ A $ is given, separated by blanks.
In the third row, the element $ B_j $ ($ 1 \ leq j \ leq W $) of the sequence $ B $ is given, separated by blanks.
Queries are given on the 4th and subsequent $ Q $ lines, separated by line breaks.
All numbers in each query are separated by blanks.

Output

For each query 3 and query 4, output the value and number on one line, separated by blanks.

Examples

Input

4 4 7
1 2 3 4
1 2 3 4
3 2 3 2 3
4 2 3 2 3
3 1 1 1 1
4 1 1 1 1
1 1 1 1
3 1 4 1 2
4 2 3 2 4


Output

4 1
9 1
1 1
1 1
2 2
12 1


Input

4 4 6
1 1 1 1
1 1 1 1
3 1 4 1 4
4 1 4 1 4
1 2 3 1
2 2 3 1
3 1 4 1 4
4 1 4 1 4


Output

1 16
1 16
1 4
4 4


Input

4 4 7
0 1 0 1
1 0 1 0
3 2 4 1 3
4 1 4 1 4
1 1 4 -1
3 1 3 1 3
1 3 3 2
2 3 3 -2
3 2 4 2 4


Output

0 5
1 4
-1 4
-1 1


Input

36 4 20
-523 -460 -536 -885 652 782 513 -558 -521 -808 124 -708 -943 52 -856 -755 -958 913 380 -767 373 -731 -492 213 538 392 -39 509 -840 135 78 -285 -241 522 -572 -915
-691 -16 812 -385
4 7 17 4 4
3 24 33 1 1
4 3 35 2 4
3 28 32 4 4
2 3 3 438
3 7 15 1 1
4 2 17 4 4
3 24 28 2 4
4 15 16 4 4
4 18 29 1 1
3 24 27 2 4
2 2 3 -828
3 18 23 3 3
1 27 31 -701
2 2 3 298
1 21 32 237
2 3 3 -71
1 14 29 772
4 13 19 3 3
3 19 34 1 2


Output

368830 1
-371758 1
741356 1
-195965 1
-354483 1
368830 1
-207130 1
329560 1
580440 1
-207130 1
-323674 1
1093565 1
-1068977 1

Solution (in CPP):

Solution:
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)

using ll = long long;
using Pll = pair<ll, ll>;
const ll inf = 1ll << 60;

template<class T, class E>
struct SegTree{
  typedef function<T(T,T)> F;
  typedef function<T(T,E)> G;
  typedef function<E(E,E)> H;
  typedef function<E(E,int)> P;
  int n;
  F f;
  G g;
  H h;
  P p;
  T d1;
  E d0;
  vector<T> dat;
  vector<E> lazy;
  SegTree(int n_, F f, G g, H h, T d1, E d0, P p=[](E a, int b){ return a; })
    : f(f), g(g), h(h), d1(d1), d0(d0), p(p) {
    n = 1;
    while (n < n_) n *= 2;
    dat.resize(2 * n - 1, d1);
    lazy.resize(2 * n - 1, d0);
  }
  void build(const vector<E>& a) {
    for (int i = 0; i < a.size(); i++) dat[i + n - 1] = Pll(a[i], 1);
    for (int i = n - 2; i >= 0; i--) dat[i] = f(dat[2 * i + 1], dat[2 * i + 2]);
  }
  void eval(int k, int l, int r) {
    if (lazy[k] == d0) return;
    dat[k] = g(dat[k], p(lazy[k], r - l));
    if (k < n - 1) {
      lazy[2 * k + 1] = h(lazy[2 * k + 1], lazy[k]);
      lazy[2 * k + 2] = h(lazy[2 * k + 2], lazy[k]);
    }
    lazy[k] = d0;
  }
  void update(int a, int b, E x, int k = 0, int l = 0, int r = -1) {
    if (r == -1) r = n;
    // cerr << "update: a = " << a << ", b = " << b << ", x = " << x << ", k = " << k << ", l = " << l << ", r = " << r << endl;
    eval(k, l, r);
    if (b <= l || r <= a) return;
    if (a <= l && r <= b) {
      lazy[k] = h(lazy[k], x);
      eval(k, l, r);
    }
    else {
      update(a, b, x, 2 * k + 1, l, (l + r) / 2);
      update(a, b, x, 2 * k + 2, (l + r) / 2, r);
      dat[k] = f(dat[2 * k + 1], dat[2 * k + 2]);
    }
  }
  // return op[a..b)
  // k: node id, [l, r): node interval
  T query(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r == -1) r = n;
    // cerr << "query: a = " << a << ", b = " << b << ", k = " << k << ", l = " << l << ", r = " << r << endl;
    eval(k, l, r);
    if (r <= a || b <= l) return d1;
    if (a <= l && r <= b) return dat[k];
    T vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
    T vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
    return f(vl, vr);
  }
  void print() {
   int j = 2;
   for (int i = 0; i < 2 * n - 1; i++) {
     cerr << "(" << "(" << dat[i].first << ", " << dat[i].second << ")" << ", " << lazy[i] << ")";
     if (i == j - 2) { cerr << endl; j *= 2;}
     else { cerr << " "; }
   }
 }
};

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  int h, w, q;
  cin >> h >> w >> q;
  vector<ll> a(h); rep(i, h) cin >> a[i];
  vector<ll> b(w); rep(i, w) cin >> b[i];

  SegTree<Pll, ll> segAm( // Pll = {min, #min}
    h,
    [](Pll a, Pll b) {
      if (a.first < b.first) return a;
      else if (a.first > b.first) return b;
      else return Pll(a.first, a.second + b.second);
    },
    [](Pll a, ll x) { return Pll(a.first + x, a.second); },
    [](ll x, ll y) { return x + y; },
    Pll(inf, 0),
    ll(0)
  );

  SegTree<Pll, ll> segAM( // Pll = {max, #max}
    h,
    [](Pll a, Pll b) {
      if (a.first > b.first) return a;
      else if (a.first < b.first) return b;
      else return Pll(a.first, a.second + b.second);
    },
    [](Pll a, ll x) { return Pll(a.first + x, a.second); },
    [](ll x, ll y) { return x + y; },
    Pll(-inf, 0),
    ll(0)
  );

  SegTree<Pll, ll> segBm(
    w,
    [](Pll a, Pll b) {
      if (a.first < b.first) return a;
      else if (a.first > b.first) return b;
      else return Pll(a.first, a.second + b.second);
    },
    [](Pll a, ll x) { return Pll(a.first + x, a.second); },
    [](ll x, ll y) { return x + y; },
    Pll(inf, 0),
    ll(0)
  );

  SegTree<Pll, ll> segBM(
    w,
    [](Pll a, Pll b) {
      if (a.first > b.first) return a;
      else if (a.first < b.first) return b;
      else return Pll(a.first, a.second + b.second);
    },
    [](Pll a, ll x) { return Pll(a.first + x, a.second); },
    [](ll x, ll y) { return x + y; },
    Pll(-inf, 0),
    ll(0)
  );

  segAm.build(a);
  segAM.build(a);
  segBm.build(b);
  segBM.build(b);

  rep(i, q) {
    int t;
    cin >> t;
    if (t == 1 || t == 2) {
      ll l, r, v;
      cin >> l >> r >> v;
      l--;
      if (t == 1) {
        segAm.update(l, r, v);
        segAM.update(l, r, v);
      }
      else {
        segBm.update(l, r, v);
        segBM.update(l, r, v);
      }
    }
    else {
      ll la, ra, lb, rb;
      cin >> la >> ra >> lb >> rb;
      la--; lb--;
      ll ma, Ma, mb, Mb, cma, cMa, cmb, cMb;
      tie(ma, cma) = segAm.query(la, ra);
      tie(Ma, cMa) = segAM.query(la, ra);
      tie(mb, cmb) = segBm.query(lb, rb);
      tie(Mb, cMb) = segBM.query(lb, rb);

      map<ll, ll> mpA;
      mpA[ma] = cma;
      mpA[Ma] = cMa;
      map<ll, ll> mpB;
      mpB[mb] = cmb;
      mpB[Mb] = cMb;

      map<ll, ll> mp;
      for (auto pa : mpA) {
        for (auto pb : mpB) {
          mp[pa.first * pb.first] += pa.second * pb.second;
        }
      }

      ll ans, cnt;
      if (t == 3) tie(ans, cnt) = *(mp.begin());
      else        tie(ans, cnt) = *(mp.rbegin());

      if (ans == 0) {
        ll cza = mpA[0], czb = mpB[0];

        // 0 = all - non_zero * non_zero
        ll len_a = ra - la;
        ll len_b = rb - lb;
        cnt = len_a * len_b - (len_a - cza) * (len_b - czb);
      }

      cout << ans << " " << cnt << endl;
    }
  }
}