Language: C++

///////////////////////////////////
//            ___				 //
//      _..--"\  `|`""--.._		 //
//   .-'       \  |        `'-.  //
//  /           \_|___...----'`\ //
// |__,,..--""``(_)--..__      | //
// '\     _.--'`.I._     ''--..' //
//   `''"`,#JGS/_|_\###,---'`    //
//     ,#'  _.:`___`:-._ '#,     //
//    #'  ,~'-;(oIo);-'~, '#     //
//    #   `~-(  |    )=~`  #     //
//    #       | |_  |      #     //
//    #       ; ._. ;      #     //
//    #  _..-;|\ - /|;-._  #     //
//    #-'   /_ \\_// _\  '-#     //
//  /`#    ; /__\-'__\;    #`\   //
// ;  #\.--|  |O  O   |'-./#  ;  //
// |__#/   \ _;O__O___/   \#__|  //
//  | #\    [I_[_]__I]    /# |   //
//  \_(#   /  |O  O   \   #)_/   //
//        /   |        \         //
//       /    |         \        //
//      /    /\          \       //
//     /     | `\         ;      //
//    ;      \   '.       |      //
//     \-._.__\     \_..-'/      //
//      '.\  \-.._.-/  /'`       //
//         \_.\    /._/          //
//          \_.;  ;._/           //
//        .-'-./  \.-'-.         //
//       (___.'    '.___)        //
///////////////////////////////////
#include <bits/stdc++.h>
using namespace std;

#define all(x) begin(x), end(x)
#define cina(s, n, a) for(int quer = s; quer < n; quer++) cin >> a[quer]
#define mod(a, b) (abs(b) + (a % abs(b))) % abs(b)
#define setp(x) fixed << setprecision(x)

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
ll MOD = 1e9 + 7;
void mul(ll &x, ll y){
	x *= y;
	if(x >= MOD) x %= MOD;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= MOD) x -= MOD;
	if(x < 0) x += MOD;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
	return r;
}
/////////////////////////////////////////////////////////////////////////////////////
void solve(){
	ll x, y;
	cin >> x >> y;
	if(x < y) cout << x;
	else{
		ll k = (x - y) / (y + 1);
		ll x1 = x - k * y;
		ll x2 = x1 - k;
		cout << max(min(abs(x1 - y), abs(x2 - y)), 0);
	}
}

int main(){
    ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int q = 1;
    //cin >> q;
    for (int i = 1; i <= q; i++) {
		//cout << "Case #" << i << ": ";
        solve();
    }
}


Compiler output:
a.cc: In function 'void solve()':
a.cc:77:28: error: no matching function for call to 'max(const long long int&, int)'
   77 |                 cout << max(min(abs(x1 - y), abs(x2 - y)), 0);
      |                         ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:33:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:77:28: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   77 |                 cout << max(min(abs(x1 - y), abs(x2 - y)), 0);
      |                         ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:77:28: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   77 |                 cout << max(min(abs(x1 - y), abs(x2 - y)), 0);
      |                         ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~