Language: C++

#pragma warning(disable: 4996)
//D - Good Grid
#include<stdio.h>
#include<iostream>

using namespace std;

int COLOR[30][30];
int PAN[500][500];
int PANLAW[500][500];
int N, C;
int min;

void PRINTSTATUS() {
	printf("i will print statu\n");
	printf("%d %d\n", N, C);
	for (int i = 0; i < C; i++) {
		for (int j = 0; j < C; j++) {
			printf("%d ", COLOR[i][j]);
		}
		printf("\n");
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			printf("%d ", PAN[i][j]);
		}
		printf("\n");
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			printf("%d ", PANLAW[i][j]);
		}
		printf("\n");
	}
	printf("\n");
}

int VALUE(int oricolor, int aftercolor) {
	return COLOR[oricolor-1][aftercolor-1];
}

int CALCUL(int A, int B, int C) {
	int count = 0; int temp;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			temp = (i + j) % 3;
			if (temp == 2) {
				count = count + VALUE(PAN[i][j], A);
			}
			if (temp == 0) {
				count = count + VALUE(PAN[i][j], B);
			}
			if (temp == 1) {
				count = count + VALUE(PAN[i][j], C);
			}
		}
	}
	return count;
}


void CALCULMIN() {
	int temp;
	for (int i = 1; i <= C; i++) {
		for (int j = 1; j <= C; j++) {
			for (int z = 1; z <= C; z++) {
				if (i == j || j == z) {
					continue;
				}
				if (z == i) {
					continue;
				}
				temp = CALCUL(i, j, z);
				if (min > temp) {
					min = temp;
				}
			}
		}
	}
}


int main() {
	int count[6] = { 0,0,0,0,0,0 };
	int temp;

	scanf("%d %d", &N, &C);
	for (int i = 0; i < C; i++) {
		for (int j = 0; j < C; j++) {
			scanf("%d", &COLOR[i][j]);
		}
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			scanf("%d", &PAN[i][j]);
		}
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			PANLAW[i][j] = (i + j) % 3+1;	// A=3 B=1 C=2
		}
	}

	//PRINTSTATUS();
	/*
	printf("VALUE(PAN[0][1], 1) = %d\n", VALUE(PAN[0][1], 1));
	printf("VALUE(PAN[0][1], 2) = %d\n", VALUE(PAN[0][1], 2));
	printf("VALUE(PAN[0][1], 3) = %d\n", VALUE(PAN[0][1], 3));
	*/
	
	min = CALCUL(1, 2, 3);
	CALCULMIN();

	printf("%d", min);
}

Compiler output:
a.cc: In function 'void CALCULMIN()':
a.cc:74:37: error: reference to 'min' is ambiguous
   74 |                                 if (min > temp) {
      |                                     ^~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:4:
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidates are: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:                 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
a.cc:12:5: note:                 'int min'
   12 | int min;
      |     ^~~
a.cc:75:41: error: reference to 'min' is ambiguous
   75 |                                         min = temp;
      |                                         ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidates are: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:                 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
a.cc:12:5: note:                 'int min'
   12 | int min;
      |     ^~~
a.cc: In function 'int main()':
a.cc:111:9: error: reference to 'min' is ambiguous
  111 |         min = CALCUL(1, 2, 3);
      |         ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidates are: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:                 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
a.cc:12:5: note:                 'int min'
   12 | int min;
      |     ^~~
a.cc:114:22: error: reference to 'min' is ambiguous
  114 |         printf("%d", min);
      |                      ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidates are: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:                 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
a.cc:12:5: note:                 'int min'
   12 | int min;
      |     ^~~