#include<bits/stdc++.h>
#include "artclass.h"
using namespace std;
#define ll long long
const vector<pair<ll, ll>> bsf_direction = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
int style(int H, int W, int R[500][500], int G[500][500], int B[500][500]) {
srand(98485232);
auto Cal_diff = [&](pair<ll, ll> a, pair<ll, ll> b){
return abs(R[a.first][a.second] - R[b.first][b.second]) +
abs(G[a.first][a.second] - G[b.first][b.second]) +
abs(B[a.first][a.second] - B[b.first][b.second]);
};
auto find_avg_bfs = [&](ll MAX_diff, ll bsf_interation){
vector<vector<ll>> bsf_check(H, vector<ll>(W, -1));
ll sum_bsf = 0;
for(ll i = 0; i < bsf_interation; i++){
queue<pair<ll, ll>> bsf_q;
pair<ll, ll> FirstPostion = {rand() % H, rand() % W};
bsf_q.emplace(FirstPostion);
bsf_check[FirstPostion.first][FirstPostion.second] = i;
sum_bsf++;
while(!bsf_q.empty()){
pair<ll, ll> position = bsf_q.front();
bsf_q.pop();
for(pair<ll, ll> dir : bsf_direction){
pair<ll, ll> NextPosition = {position.first + dir.first, position.second + dir.second};
if(NextPosition.first < 0 || NextPosition.first >= H ||
NextPosition.second < 0 || NextPosition.second >= W){
break;
}
else if(bsf_check[NextPosition.first][NextPosition.second] == i){
break;
}
else if(Cal_diff(NextPosition, FirstPostion) > MAX_diff){
break;
}
bsf_q.emplace(NextPosition);
bsf_check[NextPosition.first][NextPosition.second] = i;
sum_bsf++;
}
}
}
long double avg_bsf = sum_bsf;
avg_bsf /= bsf_interation;
return avg_bsf;
};
long double avg = find_avg_bfs(42, 53);
if(avg < 6){
return 3;
}
else if(avg < 46){
return 2;
}
// cout << "avg_bsf = " << avg_bsf << endl;
/*if(avg < 50){
ll sum_green = 0;
for(ll i = 0; i < H; i++){
for(ll j = 0; j < W; j++){
sum_green += G[i][j] - max(R[i][j], B[i][j]);
}
}
ll avg_green = sum_green/(H*W);
cout << avg_green << endl;
if(avg_green > 150){
return 2;
}
else{
return 3;
}
}*/
//avg = find_avg_bfs(150, 100);
// cout << "avg_bsf_2 = " << avg << endl;
{
ll max_diff = 0;
for(ll i = 0; i < H-2; i++){
for(ll j = 0; j < W-2; j++){
max_diff = max(max_diff, (ll)Cal_diff(make_pair(i, j), make_pair(i+2, j+2)));
}
}
if(max_diff > 509){
return 1;
}
else{
return 4;
}
}
/*if(avg > 600){
return 4;
}
else{
return 1;
}*/
}