#pragma GCC optimize ("O2")#pragma comment(linker, "/STACK:16777216")#include <functional>#include <algorithm>#include <stdexcept>#include <iostream>#include <sstream>#include <fstream>#include <numeric>#include <iomanip>#include <cstdlib>#include <cstring>#include <utility>#include <cctype>#include <vector>#include <string>#include <bitset>#include <cmath>#include <queue>#include <stack>#include <ctime>#include <list>#include <map>#include <set>using namespace std;#define rep(i,a,b) for(int i=a;i<b;++i)#define repd(i,a,b) for(int i=a,_b=b;i>_b;--i)#define sz size()#define pb(x) push_back(x)#define TEST freopen("in","r",stdin);typedef long long ll;const int N = 255;int n, m;int nq, s;int ar[N];int ax1, ax2, ay1, ay2;int bx1, bx2, by1, by2;int cx1, cx2, cy1, cy2;int num[N];void deal() { int c, cnt = -1; memset(num, 0, sizeof (num)); rep(i, 1, s + 1) { ax1 = ay1 = i; ax2 = n + 1 - i; ay2 = m + 1 - i; cx1 = max(ax1, bx1); cy1 = max(ay1, by1); cx2 = min(ax2, bx2); cy2 = min(ay2, by2); if (cx1 > cx2 || cy1 > cy2) continue; int tn = 0, top = 0, left = 0, right = 0, bottom = 0; if (cx1 == ax1 || cx1 == ax2) { top = 1; tn += (cy2 - cy1) + 1; } if (cx2 != cx1 && (cx2 == ax1 || cx2 == ax2)) { bottom = 1; tn += (cy2 - cy1) + 1; } if (cy1 == ay1 || cy1 == ay2) { left = 1; tn += (cx2 - cx1) + 1; } if (cy2 != cy1 && (cy2 == ay1 || cy2 == ay2)) { right = 1; tn += (cx2 - cx1) + 1; } if (top) { if (left) -- tn; if (right) -- tn; } if (bottom) { if (left) -- tn; if (right) -- tn; } num[ar[i]] += tn; } int res = 0; for (int i = 1; i <= 250; ++i) { if (num[i]) ++ res; if (num[i] > cnt) { cnt = num[i]; c = i; } } printf("%d %d %dn", res, c, cnt);}int main() { while (cin >> n >> m) { s = min(n, m); s = (s + 1) / 2; rep(i, 1, s + 1) { scanf("%d", ar + i); } cin >> nq; rep(i, 0, nq) { scanf("%d%d%d%d", &bx1, &by1, &bx2, &by2); ++bx1; ++by1; ++bx2; ++by2; deal(); } }}


