Language: C++

#include<iostream>
using namespace std;

int K;
int *A;
long long min, max;
long long p, j;

int main() {
	min = 0;
	max = 0;

	cin >> K;
	A = new int[K];

	for (int i = 0; i < K; i++) {
		cin >> A[i];
		if (A[i] > min) {
			min = A[i];
		}
		max += A[i] - 1;
	}

	j = min;
	while (1) {
		p = j;
		for (int i = 0; i < K; i++) {
			p = p - p % A[i];
		}
		if (p == 2) {
			cout << j << " ";
			break;
		}
		j++;
		if (j > max) {
			cout << -1 << endl;
			return 0;
		}
	}

	j = max;
	while (1) {
		p = j;
		for (int i = 0; i < K; i++) {
			p = p - p % A[i];
		}
		if (p == 2) {
			cout << j << endl;
			break;
		}
		j--;
	}
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:10:9: error: reference to 'min' is ambiguous
   10 |         min = 0;
      |         ^~~
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,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidates are: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:                 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
a.cc:6:11: note:                 'long long int min'
    6 | long long min, max;
      |           ^~~
a.cc:11:9: error: reference to 'max' is ambiguous
   11 |         max = 0;
      |         ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidates are: '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:257:5: note:                 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
a.cc:6:16: note:                 'long long int max'
    6 | long long min, max;
      |                ^~~
a.cc:18:28: error: reference to 'min' is ambiguous
   18 |                 if (A[i] > min) {
      |                            ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidates are: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:                 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
a.cc:6:11: note:                 'long long int min'
    6 | long long min, max;
      |           ^~~
a.cc:19:25: error: reference to 'min' is ambiguous
   19 |                         min = A[i];
      |                         ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidates are: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:                 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
a.cc:6:11: note:                 'long long int min'
    6 | long long min, max;
      |           ^~~
a.cc:21:17: error: reference to 'max' is ambiguous
   21 |                 max += A[i] - 1;
      |                 ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidates are: '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:257:5: note:                 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
a.cc:6:16: note:                 'long long int max'
    6 | long long min, max;
      |                ^~~
a.cc:24:13: error: reference to 'min' is ambiguous
   24 |         j = min;
      |             ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidates are: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:                 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
a.cc:6:11: note:                 'long long int min'
    6 | long long min, max;
      |           ^~~
a.cc:35:25: error: reference to 'max' is ambiguous
   35 |                 if (j > max) {
      |                         ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidates are: '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:257:5: note:                 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
a.cc:6:16: note:                 'long long int max'
    6 | long long min, max;
      |                ^~~
a.cc:41:13: error: reference to 'max' is ambiguous
   41 |         j = max;
      |             ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidates are: '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:257:5: note:                 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
a.cc:6:16: note:                 'long long int max'
    6 | long long min, max;
      |                ^~~