Language: C++

#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>

int main(){
    int64_t X, K, D;
    cin >> X >> K >> D;

    int i=0;
    int64_t p = INT64_MAX;
    int64_t m = INT64_MIN;
    bool flag1 = false;
    bool flag2 = false;
    for(i=0; i<K; i++){
        X = X - D;
        if(X>0){
            p = min(p, X);
            flag1 = true;
        }
        else if(X<=0){
            int64_t tmp = abs(X);
            m = max(m, tmp);
            flag2 = true;
            break;
        }
    }

    int64_t ret = 0;
    if(flag1==true && flag2 == true){
        ret = min(p, m);
    }
    else if(flag1==true && flag2 != true){
        ret  = p;
    }
    else if(flag1!=true && flag2 == true){
        ret = m;
    }
    else{
        ret = X;
    }
    

    cout << ret << endl;

    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:8:5: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
    8 |     cin >> X >> K >> D;
      |     ^~~
      |     std::cin
In file included from a.cc:1:
/usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here
   62 |   extern istream cin;           ///< Linked to standard input
      |                  ^~~
a.cc:11:17: error: 'INT64_MAX' was not declared in this scope
   11 |     int64_t p = INT64_MAX;
      |                 ^~~~~~~~~
a.cc:5:1: note: 'INT64_MAX' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
    4 | #include <cmath>
  +++ |+#include <cstdint>
    5 | 
a.cc:12:17: error: 'INT64_MIN' was not declared in this scope
   12 |     int64_t m = INT64_MIN;
      |                 ^~~~~~~~~
a.cc:18:17: error: 'min' was not declared in this scope; did you mean 'std::min'?
   18 |             p = min(p, X);
      |                 ^~~
      |                 std::min
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:
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: 'std::min' declared here
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
a.cc:23:17: error: 'max' was not declared in this scope; did you mean 'std::max'?
   23 |             m = max(m, tmp);
      |                 ^~~
      |                 std::max
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: 'std::max' declared here
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
a.cc:31:15: error: 'min' was not declared in this scope; did you mean 'std::min'?
   31 |         ret = min(p, m);
      |               ^~~
      |               std::min
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: 'std::min' declared here
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
a.cc:44:5: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   44 |     cout << ret << endl;
      |     ^~~~
      |     std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:44:20: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
   44 |     cout << ret << endl;
      |                    ^~~~
      |                    std::endl
/usr/include/c++/14/ostream:744:5: note: 'std::endl' declared here
  744 |     endl(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~