Language: C++

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007

int binpow(int a, int b)
{
    int ans = 1;
    if (b == 0)
        return 1;
    while (b)
    {
        if (b & 1)
            ans = ans * a;
        a = a * a;
        b >>= 1;
    }
    return ans;
}

//read question carefully!

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    //cin >> t;
    while (t--)
    {
        int x, k, d;
        cin >> x >> k >> d;
        int temp = x;
        unsigned int qq = x;
        unsigned int ck = k * d;
        if (x >= 0)
        {
            if (qq - ck >= 0)
            {
                cout << qq - ck << "\n";
                return 0;
            }
        }
        else
        {
            if (qq + ck <= 0)
            {
                cout << abs(qq + ck) << "\n";
                return 0;
            }
        }

        if (x >= 0)
        {
            int ct = 0;
            bool f = 0;
            int k1 = k;
            while (k1--)
            {
                if (temp <= 0)
                {
                    f = 1;
                    break;
                }
                temp = temp - d;
                ct++;
            }
            if (f)
            {
                int rem = k - ct;
                if (rem % 2)
                {
                    temp += d;
                }
                cout << abs(temp) << "\n";
            }
            else
            {
                cout << abs(temp) << "\n";
            }
        }
        else
        {
            int ct = 0;
            bool f = 0;
            int k1 = k;
            while (k1--)
            {
                if (temp >= 0)
                {
                    f = 1;
                    break;
                }
                temp = temp + d;
                ct++;
            }
            if (f)
            {
                int rem = k - ct;
                if (rem % 2)
                {
                    temp -= d;
                }
                cout << abs(temp) << "\n";
            }
            else
            {
                cout << abs(temp) << "\n";
            }
        }
    }
}


Compiler output:
a.cc: In function 'int32_t main()':
a.cc:48:28: error: call of overloaded 'abs(long long unsigned int)' is ambiguous
   48 |                 cout << abs(qq + ck) << "\n";
      |                         ~~~^~~~~~~~~
In file included from /usr/include/c++/14/cstdlib:79,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:42,
                 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); }
      |   ^~~