Language: C++

#include <fstream>
#include <algorithm>
#include <cmath>
#include <cstdint>

using namespace std;

#define MAX_N 100002
#define MAX_M 10001

uint64_t D,N,M,d[MAX_N],k[MAX_M];

uint64_t gd(uint64_t a,uint64_t b)
{
	return min(abs(a - b),abs(abs(a - b) - 8));
}

int main(void)
{
	cin >> D >> N >> M;
	for(int i = 2;i <= N;i++)
	{
		cin >> d[i];
	}
	for(int i = 1;i <= M;i++)
	{
		cin >> k[i];
	}
	uint64_t res = 0;
	for(int i = 1;i <= M;i++)
	{
		uint64_t sts = D;
		for(int ii = 2;ii <= N;ii++)
		{
			sts = min(sts,gd(k[i],d[ii]));
		}
		res += sts;
	}
	cout << res << endl;
	return 0;
}

Compiler output:
a.cc: In function 'uint64_t gd(uint64_t, uint64_t)':
a.cc:15:23: error: call of overloaded 'abs(uint64_t)' is ambiguous
   15 |         return min(abs(a - b),abs(abs(a - b) - 8));
      |                    ~~~^~~~~~~
In file included from /usr/include/c++/14/cstdlib:79,
                 from /usr/include/c++/14/ext/string_conversions.h:43,
                 from /usr/include/c++/14/bits/basic_string.h:4154,
                 from /usr/include/c++/14/string:54,
                 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/istream:40,
                 from /usr/include/c++/14/fstream:40,
                 from a.cc:1:
/usr/include/stdlib.h:980:12: note: candidate: 'int abs(int)'
  980 | extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
      |            ^~~
In file included from /usr/include/c++/14/cstdlib:81:
/usr/include/c++/14/bits/std_abs.h:137:3: note: candidate: 'constexpr __float128 std::abs(__float128)'
  137 |   abs(__float128 __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:85:3: note: candidate: 'constexpr __int128 std::abs(__int128)'
   85 |   abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:79:3: note: candidate: 'constexpr long double std::abs(long double)'
   79 |   abs(long double __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:75:3: note: candidate: 'constexpr float std::abs(float)'
   75 |   abs(float __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:71:3: note: candidate: 'constexpr double std::abs(double)'
   71 |   abs(double __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:61:3: note: candidate: 'long long int std::abs(long long int)'
   61 |   abs(long long __x) { return __builtin_llabs (__x); }
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:56:3: note: candidate: 'long int std::abs(long int)'
   56 |   abs(long __i) { return __builtin_labs(__i); }
      |   ^~~
a.cc:15:38: error: call of overloaded 'abs(uint64_t)' is ambiguous
   15 |         return min(abs(a - b),abs(abs(a - b) - 8));
      |                                   ~~~^~~~~~~
/usr/include/stdlib.h:980:12: note: candidate: 'int abs(int)'
  980 | extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
      |            ^~~
/usr/include/c++/14/bits/std_abs.h:137:3: note: candidate: 'constexpr __float128 std::abs(__float128)'
  137 |   abs(__float128 __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:85:3: note: candidate: 'constexpr __int128 std::abs(__int128)'
   85 |   abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:79:3: note: candidate: 'constexpr long double std::abs(long double)'
   79 |   abs(long double __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:75:3: note: candidate: 'constexpr float std::abs(float)'
   75 |   abs(float __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:71:3: note: candidate: 'constexpr double std::abs(double)'
   71 |   abs(double __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:61:3: note: candidate: 'long long int std::abs(long long int)'
   61 |   abs(long long __x) { return __builtin_llabs (__x); }
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:56:3: note: candidate: 'long int std::abs(long int)'
   56 |   abs(long __i) { return __builtin_labs(__i); }
      |   ^~~
a.cc: In function 'int main()':
a.cc:20:9: error: 'cin' was not declared in this scope
   20 |         cin >> D >> N >> M;
      |         ^~~
a.cc:5:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
    4 | #include <cstdint>
  +++ |+#include <iostream>
    5 | 
a.cc:39:9: error: 'cout' was not declared in this scope
   39 |         cout << res << endl;
      |         ^~~~
a.cc:39:9: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'