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;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

// const int B = 20;
// const int SZ = 2;

const int B = 1000;
const int SZ = 100;

const int INF = 123456789;
const ll LINF = LLONG_MAX/3;

int X[2];

int x[2][B][SZ];
int ADD[2][B];

int MIN[2][B], MAX[2][B];
unordered_map<int,int> ct[2][B];

void update(int t, int bid){
    MIN[t][bid] = INF;
    MAX[t][bid] = -INF;
    ct[t][bid].clear();

    rep(i,SZ){
        int idx = bid*SZ+i;
        if(idx>=X[t]) break;

        MIN[t][bid] = min(MIN[t][bid], x[t][bid][i]);
        MAX[t][bid] = max(MAX[t][bid], x[t][bid][i]);
        ++ct[t][bid][x[t][bid][i]];
    }
}

void push(int t, int bid){
    if(ADD[t][bid]==0) return;

    rep(i,SZ){
        int idx = bid*SZ+i;
        if(idx>=X[t]) break;
        x[t][bid][i] += ADD[t][bid];
    }
    ADD[t][bid]=0;
}

void add(int t, int l, int r, int v){
    int lid = l/SZ, rid = r/SZ;
    push(t,lid);
    push(t,rid);
    if(lid==rid){
        for(int i=l; i<=r; ++i) x[t][lid][i%SZ] += v;
        update(t,lid);
    }
    else{
        for(int bid = lid+1; bid < rid; ++bid) ADD[t][bid] += v;

        for(int i=l; i<SZ*(lid+1); ++i) x[t][lid][i%SZ] += v;
        for(int i=SZ*rid; i<=r; ++i) x[t][rid][i%SZ] += v;
        update(t,lid);
        update(t,rid);
    }
}

ll QUERY(int t, int l, int r, int mm){
    int lid = l/SZ, rid = r/SZ;

    int ret = -INF;
    function<int(int,int)> fn = [](int lh, int rh){ return max(lh,rh); };
    int (*MM)[B];
    MM = MAX;
    if(mm == 1){
        fn = [](int lh, int rh){ return min(lh,rh); };
        ret = INF;
        MM = MIN;
    }

    if(lid==rid){
        for(int i=l; i<=r; ++i) ret = fn(ret, x[t][lid][i%SZ]+ADD[t][lid]);
    }
    else{
        for(int bid = lid+1; bid < rid; ++bid) ret = fn(ret, MM[t][bid]+ADD[t][bid]);

        for(int i=l; i<SZ*(lid+1); ++i) ret = fn(ret, x[t][lid][i%SZ]+ADD[t][lid]);
        for(int i=SZ*rid; i<=r; ++i) ret = fn(ret, x[t][rid][i%SZ]+ADD[t][rid]);
    }
    return (ll)ret;
}

ll cnt(int t, int l, int r, int v){
    int ret = 0;
    int lid = l/SZ, rid = r/SZ;

    if(lid==rid){
        for(int i=l; i<=r; ++i){
            if(x[t][lid][i%SZ]+ADD[t][lid] == v) ++ret;
        }
    }
    else{
        for(int bid = lid+1; bid < rid; ++bid){
            int focus = v-ADD[t][bid];
            if(ct[t][bid].count(focus)) ret += ct[t][bid][focus];
        }

        for(int i=l; i<SZ*(lid+1); ++i){
            if(x[t][lid][i%SZ]+ADD[t][lid] == v) ++ret;
        }
        for(int i=SZ*rid; i<=r; ++i){
            if(x[t][rid][i%SZ]+ADD[t][rid] == v) ++ret;
        }
    }

    return (ll)ret;
}

int main(){
    int q;
    scanf(" %d %d %d", &X[0], &X[1], &q);

    rep(i,2){
        rep(j,X[i]){
            int v;
            scanf(" %d", &v);
            x[i][j/SZ][j%SZ] = v;
        }
        rep(j,B) update(i,j);
    }

    while(q--){
        int t;
        scanf(" %d", &t);

        if(t<=2){
            int l,r,v;
            scanf(" %d %d %d", &l, &r, &v);
            --l; --r;
            add(t-1,l,r,v);
        }
        else{
            int l[2],r[2];
            rep(i,2){
                scanf(" %d %d", &l[i], &r[i]);
                --l[i]; --r[i];
            }

            ll C = LINF;
            if(t==4) C = -C;

            ll ans = 0;

            rep(i,2)rep(j,2){
                ll va = QUERY(0,l[0],r[0],i);
                ll vb = QUERY(1,l[1],r[1],j);

                if(t==3) C = min(C, va*vb);
                else C = max(C, va*vb);
            }

            if(C==0){
                ll a0 = cnt(0,l[0],r[0],0);
                ll b0 = cnt(1,l[1],r[1],0);

                ans += a0*(r[1]-l[1]+1);
                ans += b0*(r[0]-l[0]+1);
                ans -= a0*b0;
            }
            else{
                set<pair<ll,ll>> S;
                rep(i,2)rep(j,2){
                    ll va = QUERY(0,l[0],r[0],i);
                    ll vb = QUERY(1,l[1],r[1],j);

                    if(va*vb == C) S.insert({va,vb});
                }

                for(const auto &p:S){
                    int va = p.fi, vb = p.se;
                    ans += cnt(0,l[0],r[0],va) * cnt(1,l[1],r[1],vb);
                }
            }
            printf("%lld %lld\n", C, ans);
        }
    }
    return 0;
}