Language: C++

#include <bits/stdc++.h>
using namespace std;

long long n, x, ans, prev, cur;

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

	cin >> n >> x;

	x = min(x, n - x);

	ans += x;
	ans += n - x;

	prev = n - x;
	cur = x;

	while(cur > 0) {
		ans += 2 * (prev / cur) * cur;
		prev %= cur;
		swap(prev, cur);
	}

	cout << ans - prev << '\n';
	
	return 0;

}


Compiler output:
a.cc: In function 'int main()':
a.cc:18:9: error: reference to 'prev' is ambiguous
   18 |         prev = n - x;
      |         ^~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:66,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:4:22: note:                 'long long int prev'
    4 | long long n, x, ans, prev, cur;
      |                      ^~~~
a.cc:22:29: error: reference to 'prev' is ambiguous
   22 |                 ans += 2 * (prev / cur) * cur;
      |                             ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:4:22: note:                 'long long int prev'
    4 | long long n, x, ans, prev, cur;
      |                      ^~~~
a.cc:23:17: error: reference to 'prev' is ambiguous
   23 |                 prev %= cur;
      |                 ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:4:22: note:                 'long long int prev'
    4 | long long n, x, ans, prev, cur;
      |                      ^~~~
a.cc:24:22: error: reference to 'prev' is ambiguous
   24 |                 swap(prev, cur);
      |                      ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:4:22: note:                 'long long int prev'
    4 | long long n, x, ans, prev, cur;
      |                      ^~~~
a.cc:27:23: error: reference to 'prev' is ambiguous
   27 |         cout << ans - prev << '\n';
      |                       ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)'
  244 |     prev(_BidirectionalIterator __x, typename
      |     ^~~~
a.cc:4:22: note:                 'long long int prev'
    4 | long long n, x, ans, prev, cur;
      |                      ^~~~