Language: C++

#include <bits/stdc++.h>
using namespace std;
int main(){
    long long x, k, d;
    long double y;
    cin >> x >> k >> d;
    y = (long double) abs(x) / (long double) d;
    if(y > k){
        cout << abs(abs(x) - k * d);
    }
    else if(y == k || ((long long)y == y && (k - (long long)y) % 2 == 0)){
        cout << 0;
        }
    else{
        if((k - (long long)y) % 2 == 0){
            cout << abs((abs)x - (long long)y * d);
        }
        else{
            cout << abs((abs)x - ((long long)y + 1) * d);
        }
    }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:16:30: error: expected ')' before 'x'
   16 |             cout << abs((abs)x - (long long)y * d);
      |                        ~     ^
      |                              )
a.cc:16:24: error: no matching function for call to 'abs(<unresolved overloaded function type>)'
   16 |             cout << abs((abs)x - (long long)y * d);
      |                     ~~~^~~~~~~
In file included from /usr/include/c++/14/valarray:605,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:166,
                 from a.cc:1:
/usr/include/c++/14/bits/valarray_after.h:445:5: note: candidate: 'template<class _Tp> std::_Expr<std::__detail::_UnClos<std::_Abs, std::_ValArray, _Tp>, _Tp> std::abs(const valarray<_Tp>&)'
  445 |     _DEFINE_EXPR_UNARY_FUNCTION(abs, struct std::_Abs)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:445:5: note:   template argument deduction/substitution failed:
a.cc:16:24: note:   mismatched types 'const std::valarray<_Tp>' and 'long int(long int)'
   16 |             cout << abs((abs)x - (long long)y * d);
      |                     ~~~^~~~~~~
a.cc:16:24: note:   mismatched types 'const std::valarray<_Tp>' and 'long long int(long long int)'
a.cc:16:24: note:   mismatched types 'const std::valarray<_Tp>' and 'double(double)'
a.cc:16:24: note:   mismatched types 'const std::valarray<_Tp>' and 'float(float)'
a.cc:16:24: note:   mismatched types 'const std::valarray<_Tp>' and 'long double(long double)'
a.cc:16:24: note:   mismatched types 'const std::valarray<_Tp>' and '__int128(__int128)'
a.cc:16:24: note:   mismatched types 'const std::valarray<_Tp>' and '__float128(__float128)'
a.cc:16:24: note:   mismatched types 'const std::valarray<_Tp>' and 'int(int) noexcept'
a.cc:16:24: note:   couldn't deduce template parameter '_Tp'
/usr/include/c++/14/bits/valarray_after.h:445:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_UnClos<std::_Abs, std::_Expr, _Dom>, typename _Dom::value_type> std::abs(const _Expr<_Dom1, typename _Dom1::value_type>&)'
  445 |     _DEFINE_EXPR_UNARY_FUNCTION(abs, struct std::_Abs)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:445:5: note:   template argument deduction/substitution failed:
a.cc:16:24: note:   mismatched types 'const std::_Expr<_Dom1, typename _Dom1::value_type>' and 'long int(long int)'
   16 |             cout << abs((abs)x - (long long)y * d);
      |                     ~~~^~~~~~~
a.cc:16:24: note:   mismatched types 'const std::_Expr<_Dom1, typename _Dom1::value_type>' and 'long long int(long long int)'
a.cc:16:24: note:   mismatched types 'const std::_Expr<_Dom1, typename _Dom1::value_type>' and 'double(double)'
a.cc:16:24: note:   mismatched types 'const std::_Expr<_Dom1, typename _Dom1::value_type>' and 'float(float)'
a.cc:16:24: note:   mismatched types 'const std::_Expr<_Dom1, typename _Dom1::value_type>' and 'long double(long double)'
a.cc:16:24: note:   mismatched types 'const std::_Expr<_Dom1, typename _Dom1::value_type>' and '__int128(__int128)'
a.cc:16:24: note:   mismatched types 'const std::_Expr<_Dom1, typename _Dom1::value_type>' and '__float128(__float128)'
a.cc:16:24: note:   mismatched types 'const std::_Expr<_Dom1, typename _Dom1::value_type>' and 'int(int) noexcept'
a.cc:16:24: note:   couldn't deduce template parameter '_Dom'
In file included from /usr/include/c++/14/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:127:
/usr/include/c++/14/complex:892:5: note: candidate: 'template<class _Tp> _Tp std::abs(const complex<_Tp>&)'
  892 |     abs(const complex<_Tp>& __z) { return __complex_abs(__z.__rep()); }
      |     ^~~
/usr/include/c++/14/complex:892:5: note:   template argument deduction/substitution failed:
a.cc:16:24: note:   mismatched types 'const std::complex<_Tp>' and 'long int(long int)'
   16 |             cout << abs((abs)x - (long long)y * d);
      |                     ~~~^~~~~~~
a.cc:16:24: note:   mismatched types 'const std::complex<_Tp>' and 'long long int(long long int)'
a.cc:16:24: note:   mismatched types 'const std::complex<_Tp>' and 'double(double)'
a.cc:16:24: note:   mismatched types 'const std::complex<_Tp>' and 'float(float)'
a.cc:16:24: note:   mismatched types 'const std::complex<_Tp>' and 'long double(long double)'
a.cc:16:24: note:   mismatched types 'const std::complex<_Tp>' and '__int128(__int128)'
a.cc:16:24: note:   mismatched types 'const std::complex<_Tp>' and '__float128(__float128)'
a.cc:16:24: note:   mismatched types 'const std::complex<_Tp>' and 'int(int) noexcept'
a.cc:16:24: note:   couldn't deduce template parameter '_Tp'
In file included from /usr/include/c++/14/cstdlib:79,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:42:
/usr/include/stdlib.h:980:12: note: candidate: 'int abs(int)'
  980 | extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
      |            ^~~
/usr/include/stdlib.h:980:21: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to '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:137:18: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to '__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:85:30: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to '__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:79:19: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to '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:75:13: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to '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:71:14: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to '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:61:17: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to '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); }
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:56:12: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'long int'
   56 |   abs(long __i) { return __builtin_labs(__i); }
      |       ~~~~~^~~
a.cc:19:30: error: expected ')' before 'x'
   19 |             cout << abs((abs)x - ((long long)y + 1) * d);
      |                        ~     ^
      |                              )
a.cc:19:24: error: no matching function for call to 'abs(<unresolved overloaded function type>)'
   19 |             cout << abs((abs)x - ((long long)y + 1) * d);
      |                     ~~~^~~~~~~
/usr/include/c++/14/bits/valarray_after.h:445:5: note: candidate: 'template<class _Tp> std::_Expr<std::__detail::_UnClos<std::_Abs, std::_ValArray, _Tp>, _Tp> std::abs(const valarray<_Tp>&)'
  445 |     _DEFINE_EXPR_UNARY_FUNCTION(abs, struct std::_Abs)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:445:5: note:   template argument deduction/substitution failed:
a.cc:19:24: note:   mismatched types 'const std::valarray<_Tp>' and 'long int(long int)'
   19 |             cout << abs((abs)x - ((long long)y + 1) * d);
      |                     ~~~^~~~~~~
a.cc:19:24: note:   mismatched types 'const std::valarray<_Tp>' and 'long long int(long long int)'
a.cc:19:24: note:   mismatched types 'const std::valarray<_Tp>' and 'double(double)'
a.cc:19:24: note:   mismatched types 'const std::valarray<_Tp>' and 'float(float)'
a.cc:19:24: note:   mismatched types 'const std::valarray<_Tp>' and 'long double(long double)'
a.cc:19:24: note:   mismatched types 'const std::valarray<_Tp>' and '__int128(__int128)'
a.cc:19:24: note:   mismatched types 'const std::valarray<_Tp>' and '__float128(__float128)'
a.cc:19:24: note:   mismatched types 'const std::valarray<_Tp>' and 'int(int) noexcept'
a.cc:19:24: note:   couldn't deduce template parameter '_Tp'
/usr/include/c++/14/bits/valarray_after.h:445:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_UnClos<std::_Abs, std::_Expr, _Dom>, typename _Dom::value_type> std::abs(const _Expr<_Dom1, typename _Dom1::value_type>&)'
  445 |     _DEFINE_EXPR_UNARY_FUNCTION(abs, struct std::_Abs)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:445:5: note:   template argument deduction/substitution failed:
a.cc:19:24: note:   mismatched types 'const std::_Expr<_Dom1, typename _Dom1::value_type>' and 'long int(long int)'
   19 |             cout << abs((abs)x - ((long long)y + 1) * d);
      |                     ~~~^~~~~~~
a.cc:19:24: no