Language: C++

/*
#include <iostream>
using namespace std;
#define ll long long
#define M 1000000007
#define tc int t; cin>>t; while(t--)
#include <cstring>
#include <vector>
void removeEle(int arr[], int n){
    vector<int> v;
    int i = 1;
while( i < n){
    if(arr[i] == arr[i+1]){
        v.push_back(arr[i]);
        i++;
    }
    else if(arr[i] > arr[i+1]){
        v.push_back(arr[i+1]);
        i++;
    }
    else{
        v.push_back(arr[i]);
        i++
    }
}
cout << v.size() << endl;
for(int i = 0; i < v.size(); i++){
    cout << v[i] << " ";
}
cout << endl;



}
int main(){
    tc{
        int n;
        cin>>n;
        int arr[n];
        for(int i = 1; i <= n; i++){
            cin>>arr[i];
        }
        removeEle(arr, n);
    }
    return 0;
}

*/

// atcoder 175

//A
/*
#include <iostream>
using namespace std;
#define ll  long long
#define M 1000000007
#define tc int t; cin>>t; while(t--)
#include <cstring>
int main(){
	string s;
	cin>>s;
	int l = 0, maxL = 0;
	for(int i = 0; i < s.size(); i++){
		if(s[i] == 'R' && maxL <= l){
			l++;
			maxL = l;
		}
		else if(s[i] == 'S'){
			l = 0;
		}
	}
	cout << maxL << endl;
	return 0;
}
*/
/*
// B
#include <iostream>
using namespace std;
#define ll  long long
#define M 1000000007
#define tc int t; cin>>t; while(t--)
#include <cstring>

ll triangle(ll arr[], int n){
	ll ans = 0;

	for(int  i = 1; i <= n-2; i++){
		for(int j = i+1; j <= n-1; j++){
			for(int k = j+1; k <= n; k++){
				bool a = arr[i] != arr[j] && arr[j] != arr[k] && arr[i] != arr[k];
				bool b = arr[i] + arr[j] > arr[k] && arr[j] + arr[k] > arr[i] && arr[i] + arr[k] > arr[j];
				if( a && b){
					ans++;
				}
			}
		}
	}
	return ans;
}
int main(){
	int n;
	cin>>n;
	ll arr[n];
	for(int i = 1; i <= n; i++){
		cin>>arr[i];
	}
	cout << triangle(arr , n) << endl;
}
*/
 // Time Taken :- 24 minites

// C


#include <iostream>
using namespace std;
#define ll unsigned long long
#define M 1000000007
#define tc int t; cin>>t; while(t--)
#include <cstring>
#include <cmath>

int main(){
	ll x , k , d;
	cin>>x>>k;
	cin>>d;
	x = abs(x);
	ll steps = (x - x%d)/d - k;
	if(steps > 0){
		cout << x%d + steps*d << endl;
	}
	else{
		cout << x%d << endl;
	}
	return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:129:16: error: call of overloaded 'abs(long long unsigned int&)' is ambiguous
  129 |         x = abs(x);
      |             ~~~^~~
In file included from /usr/include/c++/14/cstdlib:79,
                 from /usr/include/c++/14/ext/string_conversions.h:43,
                 from /usr/include/c++/14/bits/basic_string.h:4154,
                 from /usr/include/c++/14/string:54,
                 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,
                 from a.cc:117:
/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); }
      |   ^~~