Language: C++

#include <iostream>
#include <algorithm>

using namespace std;

long long d[40][40],z[510][510],a[40][3];
int main(){
	int n,c,i,j,k,ans;
	cin >> n >> c;
	for(i=1;i<=c;i++){
		for(j=1;j<=c;j++){
			cin >> d[i][j];
		}
	}
	
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			cin >> z[i][j];
		}
	}
	
	ans = 9000000000000;
	
	for(k=1;k<=c;k++){
		a[k][0]=0;
		a[k][1]=0;
		a[k][2]=0;
		for(i=1;i<=n;i++){
			for(j=1;j<=n;j++){
				if((i+j)%3==0){
					a[k][0] += d[z[i][j]][k];
				}
				if((i+j)%3==1){
					a[k][1] += d[z[i][j]][k];
				}
				if((i+j)%3==2){
					a[k][2] += d[z[i][j]][k];
				}
			}
		}
	}
	
	for(i=1;i<=c;i++){
			for(j=1;j<=c;j++){
				if(i!=j){
					for(k=1;k<=c;k++){
						if(i!=k && j!=k){
							ans = min(ans,a[i][0]+a[j][1]+a[k][2]);
						}
					}
				}
			}
	}
	cout << ans << endl;
}
						
		

Compiler output:
a.cc: In function 'int main()':
a.cc:22:15: warning: overflow in conversion from 'long int' to 'int' changes value from '9000000000000' to '2043514880' [-Woverflow]
   22 |         ans = 9000000000000;
      |               ^~~~~~~~~~~~~
a.cc:48:66: error: no matching function for call to 'min(int&, long long int)'
   48 |                                                         ans = min(ans,a[i][0]+a[j][1]+a[k][2]);
      |                                                               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:48:66: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   48 |                                                         ans = min(ans,a[i][0]+a[j][1]+a[k][2]);
      |                                                               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: '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:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:48:66: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   48 |                                                         ans = min(ans,a[i][0]+a[j][1]+a[k][2]);
      |                                                               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~