Language: C++

#include <bits/stdc++.h>
using namespace std;
#define INF 0x7fffffff
typedef long long ll;
typedef long double ld;

typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<ld> vld;

#define fastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define beg(x) x.begin()
#define en(x) x.end()

#define llabs(x) (x) >= 0? (x) : -(x);

int main()
{
	fastIO;
	ll x, k, d; cin >> x >> k >> d;
	ll d1, d2, d3, cnt;

	cnt = x/d;
	if(cnt >= k) cout << x - k*d << endl;
	else
	{
		ll t1 = x - cnt*d, t2 = x - (cnt + 1)*d;
		d1 = llabs(t1) < llabs(t2)? t1 : t2;
		d2 = d1 - d; d3 = d1 + d;

		k -= cnt;
		if(k & 1) 
		{
			d = llabs(d2) < llabs(d3)? llabs(d2) : llabs(d3);
			cout << d << endl;
		}
		else cout << llabs(d1) << endl;
	}

	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:38:32: error: expected primary-expression before '<' token
   38 |                 d1 = llabs(t1) < llabs(t2)? t1 : t2;
      |                                ^
a.cc:38:43: error: expected primary-expression before '?' token
   38 |                 d1 = llabs(t1) < llabs(t2)? t1 : t2;
      |                                           ^
a.cc:44:39: error: expected primary-expression before '<' token
   44 |                         d = llabs(d2) < llabs(d3)? llabs(d2) : llabs(d3);
      |                                       ^
a.cc:44:50: error: expected primary-expression before '?' token
   44 |                         d = llabs(d2) < llabs(d3)? llabs(d2) : llabs(d3);
      |                                                  ^
a.cc:25:38: error: expected ':' before ';' token
   25 | #define llabs(x) (x) >= 0? (x) : -(x);
      |                                      ^
a.cc:44:52: note: in expansion of macro 'llabs'
   44 |                         d = llabs(d2) < llabs(d3)? llabs(d2) : llabs(d3);
      |                                                    ^~~~~
a.cc:25:38: error: expected primary-expression before ';' token
   25 | #define llabs(x) (x) >= 0? (x) : -(x);
      |                                      ^
a.cc:44:52: note: in expansion of macro 'llabs'
   44 |                         d = llabs(d2) < llabs(d3)? llabs(d2) : llabs(d3);
      |                                                    ^~~~~
a.cc:44:62: error: expected primary-expression before ':' token
   44 |                         d = llabs(d2) < llabs(d3)? llabs(d2) : llabs(d3);
      |                                                              ^
a.cc:25:22: error: no match for 'operator>=' (operand types are 'std::basic_ostream<char>::__ostream_type' {aka 'std::basic_ostream<char>'} and 'int')
   25 | #define llabs(x) (x) >= 0? (x) : -(x);
      |                      ^~ ~
      |                         |
      |                         int
a.cc:47:30: note: in expansion of macro 'llabs'
   47 |                 else cout << llabs(d1) << endl;
      |                              ^~~~~
a.cc:25:22: note: candidate: 'operator>=(int, int)' (built-in)
   25 | #define llabs(x) (x) >= 0? (x) : -(x);
      |                      ^
a.cc:47:30: note: in expansion of macro 'llabs'
   47 |                 else cout << llabs(d1) << endl;
      |                              ^~~~~
a.cc:25:22: note:   no known conversion for argument 1 from 'std::basic_ostream<char>::__ostream_type' {aka 'std::basic_ostream<char>'} to 'int'
   25 | #define llabs(x) (x) >= 0? (x) : -(x);
      |                      ^
a.cc:47:30: note: in expansion of macro 'llabs'
   47 |                 else cout << llabs(d1) << endl;
      |                              ^~~~~
In file included from /usr/include/c++/14/regex:68,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:181,
                 from a.cc:1:
/usr/include/c++/14/bits/regex.h:1165:5: note: candidate: 'template<class _BiIter> bool std::__cxx11::operator>=(const sub_match<_BiIter>&, const sub_match<_BiIter>&)'
 1165 |     operator>=(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1165:5: note:   template argument deduction/substitution failed:
a.cc:25:25: note:   'std::basic_ostream<char>::__ostream_type' {aka 'std::basic_ostream<char>'} is not derived from 'const std::__cxx11::sub_match<_BiIter>'
   25 | #define llabs(x) (x) >= 0? (x) : -(x);
      |                         ^
a.cc:47:30: note: in expansion of macro 'llabs'
   47 |                 else cout << llabs(d1) << endl;
      |                              ^~~~~
/usr/include/c++/14/bits/regex.h:1248:5: note: candidate: 'template<class _Bi_iter, class _Ch_traits, class _Ch_alloc> bool std::__cxx11::operator>=(__sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>&, const sub_match<_BiIter>&)'
 1248 |     operator>=(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1248:5: note:   template argument deduction/substitution failed:
a.cc:25:25: note:   'std::basic_ostream<char>::__ostream_type' {aka 'std::basic_ostream<char>'} is not derived from 'std::__cxx11::__sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>'
   25 | #define llabs(x) (x) >= 0? (x) : -(x);
      |                         ^
a.cc:47:30: note: in expansion of macro 'llabs'
   47 |                 else cout << llabs(d1) << endl;
      |                              ^~~~~
/usr/include/c++/14/bits/regex.h:1341:5: note: candidate: 'template<class _Bi_iter, class _Ch_traits, class _Ch_alloc> bool std::__cxx11::operator>=(const sub_match<_BiIter>&, __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>&)'
 1341 |     operator>=(const sub_match<_Bi_iter>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1341:5: note:   template argument deduction/substitution failed:
a.cc:25:25: note:   'std::basic_ostream<char>::__ostream_type' {aka 'std::basic_ostream<char>'} is not derived from 'const std::__cxx11::sub_match<_BiIter>'
   25 | #define llabs(x) (x) >= 0? (x) : -(x);
      |                         ^
a.cc:47:30: note: in expansion of macro 'llabs'
   47 |                 else cout << llabs(d1) << endl;
      |                              ^~~~~
/usr/include/c++/14/bits/regex.h:1415:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator>=(const typename std::iterator_traits<_Iter>::value_type*, const sub_match<_BiIter>&)'
 1415 |     operator>=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1415:5: note:   template argument deduction/substitution failed:
a.cc:25:25: note:   mismatched types 'const std::__cxx11::sub_match<_BiIter>' and 'int'
   25 | #define llabs(x) (x) >= 0? (x) : -(x);
      |                         ^
a.cc:47:30: note: in expansion of macro 'llabs'
   47 |                 else cout << llabs(d1) << endl;
      |                              ^~~~~
/usr/include/c++/14/bits/regex.h:1509:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator>=(const sub_match<_BiIter>&, const typename std::iterator_traits<_Iter>::value_type*)'
 1509 |     operator>=(const sub_match<_Bi_iter>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1509:5: note:   template argument deduction/substitution failed:
a.cc:25:25: note:   'std::basic_ostream<char>::__ostream_type' {aka 'std::basic_ostream<char>'} is not derived from 'const std::__cxx11::sub_match<_BiIter>'
   25 | #define llabs(x) (x) >= 0? (x) : -(x);
      |                         ^
a.cc:47:30: note: in expansion of macro 'llabs'
   47 |                 else cout << llabs(d1) << endl;
      |                              ^~~~~
/usr/include/c++/14/bits/regex.h:1586:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator>=(const typename std::iterator_traits<_Iter>::value_type&, const sub_match<_BiIter>&)'
 1586 |     operator>=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1586:5: note:   template argument deduction/substitution failed:
a.cc:25:25: note:   mismatched types 'const std::__cxx11::sub_match<_BiIter>' and 'int'
   25 | #define llabs(x) (x) >= 0? (x) : -(x);
      |                         ^
a.cc:47:30: note: in expansion of macro 'llabs'
   47 |                 else cout << llabs(d1) << endl;
      |                              ^~~~~
/usr/include/c++/14/bits/regex.h:1686:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator>=(const sub_match<_BiIter>&, const typename std::iterator_traits<_Iter>::value_type&)'
 1686 |     operator>=(const sub_match<_Bi_iter>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/14/bits/regex.h:1686:5: note:   template argument deduction/substitution failed:
a.cc:25:25: note:   'std::basic_ostream<char>::__ostream_type' {aka 'std::basic_ostream<char>'} is not derived from 'const std::__cxx11::sub_match<_BiIter>'
   25 | #define llabs(x) (x) >= 0? (x) : -(x);
      |                         ^
a.cc:47:30: note: in expansion of macro 'llabs'
   47 |                 else cout << llabs(d1) << endl;
      |                              ^~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51:
/usr/include/c++/14/bits/stl_pair.h:1070:5: note: candidate: 'template<class _T1, class _T2> constexpr bool std::operator>=(const pair<_T1, _T2>&, const pair<_T1, _T2>&)'
 1070 |     operator>=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_pair.h:1070:5: note:   template argument deduction/substitution failed:
a.cc:25:25: note:   'std::basic_ostream<char>::__ostream_type' {aka 'std::basic_ostream<char>'} is not derived from 'const std::pair<_T1, _T2>'
   25 | #define llabs(x) (x) >= 0? (x) : -(x);
      |                         ^
a.cc:47:30: note: in expansion of macro 'llabs'
   47 |                 else cout << llabs(d1) << endl;
      |                              ^~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:67:
/usr/include/c++/14/bits/stl_iterator.h:476:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator>=(const reverse_iterator<_Iterator>&, const reverse_iterator<_Iterator>&)'
  476 |     operator>=(const reverse_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:476:5: note:   template argument deduction/substitution failed:
a.cc:25:25: note:   'std::basic_ostream<char>::__ostream_type' {aka 'std::basic_ostream<char>'} is not derived from 'const std::reverse_iterator<_Iterator>'
   25 | #define llabs(x) (x) >= 0? (x) : -(x);
      |                         ^
a.cc:47:30: note: in expansion of macro 'llabs'
   47 |                 else cout << llabs(d1) << endl;
      |                              ^~~~~
/usr/include/c++/14/bits/stl_iterator.h:520:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator>=(const reverse_it