stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include<iostream>

#include<stdio.h>

#define MAX 500000

#define INFTY 2000000000



int L[MAX / 2 + 2], R[MAX / 2 + 2];

int cnt;



void merge(int A[], int left, int mid, int right){

	int n1 = mid - left;

	int n2 = right - mid;

	int i;

	int L[n1], R[n2];

	for (i = 0; i < n1; i++){

		L[i] = A[left + i];

	}

	for (i = 0; i < n2; i++){

		R[i] = A[mid + i];

	}

	L[n1] = INFTY;

	R[n2] = INFTY;

	i = 0;

	int j = 0;

	for (int k = left; k < right; k++){

		cnt++;

		if (L[i] <= R[j]){

			A[k] = L[i];

			i = i + 1;

		}

		else{

			A[k] = R[j];

			j = j + 1;

		}

	}

}



void mergeSort(int A[],int n, int left, int right){

	int mid;

	if (left + 1 < right){

		mid = (left + right) / 2;

		mergeSort(A, n, left, mid);

		mergeSort(A, n, mid, right);

		merge(A, left, mid, right);

	}

}



int main(){

	int A[MAX],n,i;

	cnt = 0;

	scanf("%d", &n);

	for (i = 0; i < n; i++){

		scanf("%d", &A[i]);

	}

	mergeSort(A, n, 0, n);

	for (int i = 0; i < n; i++){

		if (i)

			printf(" ");

		printf("%d", A[i]);

	}

	printf("\n");

	printf("%d\n", cnt);

	return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

#define MAX 500000

#define INFTY 2000000000



int L[MAX / 2 + 1], R[MAX / 2 + 1];

int A[MAX];

int cnt = 0;



void merge(int A[], int left, int mid, int right){

	int i,j;

	int n1 = mid - left;

	int n2 = right - mid;

	for (i = 0; i < n1; i++){

		L[i] = A[left+i];

	}

	for (i = 0; i < n2; i++){

		R[i] = A[mid+i];

	}

	L[n1] = R[n2] = INFTY;

        i=0;

        j=0;

	for (int k = left; k < right; k++){

		cnt++;

		if (L[i] <= R[j]){

			A[k] = L[i++];

		}

		else{

			A[k] = R[j++];

		}

	}

}



void mergeSort(int A[], int left, int right){

	if (left + 1 < right){

		int mid = (left + right) / 2;

		mergeSort(A, left, mid);

		mergeSort(A, mid, right);

		merge(A, left, mid, right);

	}

}



int main(){

	int n;

	scanf("%d", &n);

	for (int i = 0; i < n; i++){

		scanf("%d", &A[i]);

	}

	mergeSort(A, 0, n);

	for (int i = 0; i < n; i++){

		if (i)printf(" ");

		printf("%d", A[i]);

	}

	printf("\n");

        printf("%d\n",cnt);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

using namespace std;



#define INFTY 1 << 30;







int Merge(int A[],int left,int mid,int right){



  int k;

  int n1 = mid-left;

  int n2 = right-mid;



  int L[n1+1];

  int R[n2+1];



  for(int i=0;i<n1;i++){

    L[i] = A[left+i];

  }



  for(int i=0;i<n2;i++){

    R[i] = A[mid+i];

  }



  L[n1] = INFTY;

  R[n2] = INFTY;



  int i=0;

  int j=0;



  for(k=left;k<right;k++){

    if(L[i]<=R[j]){

      A[k] = L[i];

      i++;

    }else{

      A[k] = R[j];

      j++;

    }

  }

  return k - left;

}



int MergeSort(int A[],int left,int right){

  int count = 0;

  if(left+1 < right){

    int mid = (left+right)/2;

    count += MergeSort(A,left,mid);

    count += MergeSort(A,mid,right);

    count += Merge(A,left,mid,right);

  }

  return count;

}



int main(){

  int n,m;

  cin >> n;



  int S[500000];

  for(int i=0;i<n;i++){

    cin >> S[i];

  }



  m = MergeSort(S,0,n);



  for(int i=0;i<n-1;i++){

    cout << S[i];

    cout << " ";

  }

  cout << S[n-1];

  cout << endl;



  cout << m << endl;



  return 0;

}




// Optimized solution to the same problem (faster):
#include<stdio.h>



#define INFTY 1 << 30;







int Merge(int A[],int left,int mid,int right){



  int k;

  int n1 = mid-left;

  int n2 = right-mid;



  int L[n1+1];

  int R[n2+1];



  for(int i=0;i<n1;i++){

    L[i] = A[left+i];

  }



  for(int i=0;i<n2;i++){

    R[i] = A[mid+i];

  }



  L[n1] = INFTY;

  R[n2] = INFTY;



  int i=0;

  int j=0;



  for(k=left;k<right;k++){

    if(L[i]<=R[j]){

      A[k] = L[i];

      i++;

    }else{

      A[k] = R[j];

      j++;

    }

  }

  return k - left;

}



int MergeSort(int A[],int left,int right){

  int count = 0;

  if(left+1 < right){

    int mid = (left+right)/2;

    count += MergeSort(A,left,mid);

    count += MergeSort(A,mid,right);

    count += Merge(A,left,mid,right);

  }

  return count;

}



int main(){

  int n,m;

  scanf("%d",&n);



  int S[500000];

  for(int i=0;i<n;i++){

    scanf("%d",&S[i]);

  }



  m = MergeSort(S,0,n);



  for(int i=0;i<n-1;i++){

    printf("%d ",S[i]);

  }

  printf("%d\n%d\n",S[n-1],m);



  return 0;

}




// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<vector>

#define INF 1000000000

#define nmax 500005

using namespace std;



int n;

int cnt = 0;

int a[nmax];



void merge(int left, int mid, int right){

  int n1 = mid -left;

  int n2 = right - mid;

  int l[nmax];

  int r[nmax];



  int i, j;

  

  for(i = 0; i < n1; i++) l[i] = a[left + i];

  for(i = 0; i < n2; i++) r[i] = a[mid + i];



  l[n1] = INF;

  r[n2] = INF;



  i = 0;

  j = 0;



  for(int k = left; k < right; k++){

    if(l[i] <= r[j]) a[k] = l[i++];



    else a[k] = r[j++];



    cnt++;

    

  }

}



void mergeSort(int left, int right){

  if(left+1 < right){

    int mid = (left + right) / 2;



    mergeSort(left, mid);

    mergeSort(mid, right);

    merge(left, mid, right);

  }

}



int main()

{

  cin >> n;

  for(int i = 0; i < n; i++) cin >> a[i];



  mergeSort(0, n);



  for(int i = 0; i < n; i++){

    if(i) cout << " ";



    cout << a[i];

  }



  cout << endl;

  cout << cnt << endl;

  



  return 0;



}




// Optimized solution to the same problem (faster):
#include<iostream>

#include<vector>

#define INF 1000000000

#define nmax 500005

using namespace std;



int n;

int cnt = 0;

vector<int> a;



void merge(int left, int mid, int right){

  int n1 = mid -left;

  int n2 = right - mid;

  vector<int> l(n1+5);

  vector<int> r(n1+5);



  int i, j;

  

  for(i = 0; i < n1; i++) l[i] = a[left + i];

  for(i = 0; i < n2; i++) r[i] = a[mid + i];



  l[n1] = INF;

  r[n2] = INF;



  i = 0;

  j = 0;



  for(int k = left; k < right; k++){

    if(l[i] <= r[j]) a[k] = l[i++];



    else a[k] = r[j++];



    cnt++;

    

  }

}



void mergeSort(int left, int right){

  if(left+1 < right){

    int mid = (left + right) / 2;



    mergeSort(left, mid);

    mergeSort(mid, right);

    merge(left, mid, right);

  }

}



int main()

{

  cin >> n;

  a.resize(n);

  

  for(int i = 0; i < n; i++) cin >> a[i];



  mergeSort(0, n);



  for(int i = 0; i < n; i++){

    if(i) cout << " ";



    cout << a[i];

  }



  cout << endl;

  cout << cnt << endl;

  



  return 0;



}




// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <string>

#include <algorithm>

#include <cstdio>



using namespace std;



const int INF = 1000000001;

const int MAX = 500000;

int cnt;

int L[1 + MAX/2] = {0},R[1 + MAX/2] = {0};





void merge(int* A,int left,int mid,int right)

{

	int n1,n2,n,i,j;

	//int L[1 + MAX/2] = {0},R[1 + MAX/2] = {0};

	n1 = mid - left;

	n2 = right - mid;



	for(int i = 0; i < n1; i++)

	{

		L[i] = A[left + i];

	}

	for(int i = 0; i < n2; i++)

	{

		R[i] = A[mid + i];

	}



	L[n1] = INF;

	R[n2] = INF;



	i = 0;

	j = 0;



	//cout << "right=" << right << "left=" << left << endl;

	//cout << "right - left= " << right << " - " << left << " = " << right - left << endl;



	for(int k = 0; k < right - left; k++)

	{

		if (L[i] <= R[j] )

		{

			A[left + k] = L[i];

			i++;

		}else

		{

			A[left + k] = R[j];

			j++;

		}



		cnt++;

	}



	//return cnt;

}





void mergesort(int* A,int left,int right)

{

	int mid,sol, sol_left, sol_right;



	if(left + 1 < right)

	{

		mid = (left + right) / 2;

		//cout << "mid=" << mid << endl;

		//sol_left = mergesort(A,left,mid);

		//sol_right = mergesort(A,mid,right);

		//sol = merge(A,left,mid,right) + sol_right + sol_left;



		mergesort(A,left,mid);

		mergesort(A,mid,right);

		merge(A,left,mid,right);



		//cout << "sol= " << sol << endl;

	}



	//return sol;

}



int main()

{

	int N,S[MAX] = {0},solution;

	cnt = 0;



	cin >> N;



	for(int i = 0; i < N; i++)

	{

		cin >> S[i];

	}



	//solution = mergesort(S,0,N);

	mergesort(S,0,N);



	for(int i = 0; i < N; i++)

	{

		if (i == N-1)

		{

			cout << S[i] <<endl;

		}else

		{

			cout << S[i] << " ";

		}

	}



	cout << cnt << endl;



	return 0;

}

	

// Optimized solution to the same problem (faster):
#include <iostream>

#include <cstdio>





using namespace std;



const int INF = 1000000001;

const int MAX = 500000;

int cnt,N;

int S[MAX] = {0}, L[1 + MAX/2] = {0}, R[1 + MAX/2] = {0};





void merge(int* A,int left,int mid,int right)

{

	int n1,n2,i,j;

	n1 = mid - left;

	n2 = right - mid;



	for(int i = 0; i < n1; i++)

	{

		L[i] = A[left + i];

	}

	for(int i = 0; i < n2; i++)

	{

		R[i] = A[mid + i];

	}



	L[n1] = INF;

	R[n2] = INF;



	i = 0;

	j = 0;



	for(int k = 0; k < right - left; k++)

	{

		if (L[i] <= R[j] )

		{

			A[left + k] = L[i];

			i++;

		}else

		{

			A[left + k] = R[j];

			j++;

		}



		cnt++;

	}

}





void mergesort(int* A,int left,int right)

{

	int mid;



	if(left + 1 < right)

	{

		mid = (left + right) / 2;

		mergesort(A,left,mid);

		mergesort(A,mid,right);

		merge(A,left,mid,right);

	}

}



int main()

{

	cnt = 0;



	scanf("%d", &N);



	for(int i = 0; i < N; i++)

	{

		scanf("%d", &S[i]);

	}



	mergesort(S,0,N);



	for(int i = 0; i < N; i++)

	{

		if (i == N-1)

		{

			printf("%d\n", S[i]);

		}else

		{

			printf("%d ", S[i]);

		}

	}



	printf("%d\n", cnt);

	return 0;

}

	

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

using namespace std;



#define SIZE 500000

#define INFTY 1200000000

int count = 0;



void show(int* a, int size)

{

    int i;

    cout << a[0];

    for(i = 1; i < size; i++) cout << " " << a[i];

    cout << endl;

}



void Merge(int* A, int left, int mid, int right)

{

    int R[SIZE], L[SIZE];

    int i, j, k, n1, n2;

    n1 = mid - left;

    n2 = right - mid;

    for(i = 0; i < n1; i++) L[i] = A[i + left];

    for(j = 0; j < n2; j++) R[j] = A[j + mid];



    L[n1] = INFTY;

    R[n2] = INFTY;

    i = j = 0;



    for(k = left; k < right; k++){

        if(L[i] <= R[j]){

            A[k] = L[i];

            i++;

        }else{

            A[k] = R[j];

            j++;

        }

        count++;

    }

}



void MergeSort(int* A, int left, int right)

{

    int mid;

    if(left + 1 < right){

        mid = (left + right) / 2;

        MergeSort(A, left, mid);

        MergeSort(A, mid, right);

        Merge(A, left, mid, right);

    }

    return;

}



int main()

{

    int i, n, S[SIZE];

    cin >> n;

    for(i = 0; i < n; i++) cin >> S[i];



    MergeSort(S, 0, n);

    show(S, n);

    cout << count << endl;



    return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>



#define SIZE 500000

#define INFTY 1200000000

int count = 0;



void show(int* a, int size)

{

    int i;

    printf("%d", a[0]);

    for(i = 1; i < size; i++) printf(" %d", a[i]);

	printf("\n");

}



void Merge(int* A, int left, int mid, int right)

{

    int R[SIZE], L[SIZE];

    int i, j, k, n1, n2;

    n1 = mid - left;

    n2 = right - mid;

    for(i = 0; i < n1; i++) L[i] = A[i + left];

    for(j = 0; j < n2; j++) R[j] = A[j + mid];



    L[n1] = INFTY;

    R[n2] = INFTY;

    i = j = 0;



    for(k = left; k < right; k++){



		if(L[i] <= R[j]){ A[k] = L[i]; i++; }



        else{ A[k] = R[j]; j++; }



        count++;

    }

}



void MergeSort(int* A, int left, int right)

{

    int mid;

    if(left + 1 < right){

        mid = (left + right) / 2;

        MergeSort(A, left, mid);

        MergeSort(A, mid, right);

        Merge(A, left, mid, right);

    }

    return;

}



int main()

{

    int i, n, S[SIZE];

    scanf("%d", &n);

    for(i = 0; i < n; i++) scanf("%d", &S[i]);



    MergeSort(S, 0, n);

    show(S, n);

    printf("%d\n", count);



    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;



int n;

ll ara[100000 + 5];



ll check(ll k) {

    for(int i = 0; i < n; i++)

        k -= k % ara[i];

    return k;

}



int main() {

    cin >> n;

    for(int i = 0; i < n; i++) 

        cin >> ara[i];

    ll lo = 0, hi = 100000000000000, ans = -1;

    while(lo <= hi) {

        ll mid = (lo + hi) / 2;

        ll k = check(mid);

        if(k == 2) {

            ans = mid;

            hi = mid - 1;

        }

        else if(k > 2)

            hi = mid - 1;

        else

            lo = mid + 1;

    }

    

    if(ans != -1)

        cout << ans << " ";

    else {

        cout << -1 << endl;

        return 0;

    }

    

    lo = 0, hi = 100000000000000, ans = -1;

    while(lo <= hi) {

        ll mid = (lo + hi) / 2;

        ll k = check(mid);

        if(k == 2) {

            ans = mid;

            lo = mid + 1;

        }

        else if(k > 2)

            hi = mid - 1;

        else

            lo = mid + 1;

    }

    

    if(ans != -1)

        cout << ans << " ";

    else {

        cout << -1 << endl;

        return 0;

    }

    return 0;

}

// Optimized solution to the same problem (faster):
#include<stdio.h>

int main()

{

	int K,A[100010];

	scanf("%d", &K);

	for (int i = 1; i <= K; i++)

	{

		scanf("%d", &A[i]);

	}

	long long left = 2, right = 2;

	for (int i = K; i > 0; i--)

	{

		left = ((left-1) / A[i] + 1)*A[i];

		right = (right / A[i] + 1)*A[i] - 1;

	}

	if (left > right)

		printf("-1\n");

	else

		printf("%lld %lld\n", left, right);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
    #include<bits/stdc++.h>

    using namespace std;

    const int mxn = 1e5+10;

    int n;

    long long ar[mxn];

     

    int main()

    {

        cin>>n;

        for(int i = 0; i < n; i++)

            cin>>ar[i];

        long long prev = ar[n-1];

        if(prev!=2)

        {

            cout<<"-1"<<endl;

            return 0;

        }

        long long left = 2;

        long long right = 2;

        for(int i = n-1; i >= 0; i--)

        {

    		left = ((left-1)/ar[i] + 1)*ar[i];

    		right = ((right/ar[i])*ar[i]+ar[i]-1);

    		long long tmp = (right/ar[i])*ar[i];

    		

    		if(left > tmp) { cout<<"-1"<<endl; return 0;}

    	}

    	cout<<left<<" "<<right<<endl;

        return 0;

    }

// Optimized solution to the same problem (faster):
#include<stdio.h>

int main()

{

	int K,A[100010];

	scanf("%d", &K);

	for (int i = 1; i <= K; i++)

	{

		scanf("%d", &A[i]);

	}

	long long left = 2, right = 2;

	for (int i = K; i > 0; i--)

	{

		left = ((left-1) / A[i] + 1)*A[i];

		right = (right / A[i] + 1)*A[i] - 1;

	}

	if (left > right)

		printf("-1\n");

	else

		printf("%lld %lld\n", left, right);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

typedef pair<ll, ll> pll;

const int INF = 1e9;

const ll LINF = 1e18;



/*

<url:https://agc020.contest.atcoder.jp/tasks/agc020_b>

問題文============================================================

 スケートリンクで、一人の大人の司会と N 人の子供がゲームを行います。

 ゲームは K ラウンドからなり、ラウンド i では司会が次のように言います。

 

 Ai 人組を作って！

 

 すると、まだ脱落していない子供たちは Ai 人からなるグループをできるだけ多く組みます。

 一人につき一つのグループにしか入れません。

 グループに入れなかった子供たちは脱落し、その他は次のラウンドに進みます。 ラウンドで誰も脱落しないこともありえます。

 

 最後まで、つまりラウンド K のあとまで残ったのは 2 人で、彼らが勝者となりました。

 

 あなたは A1, A2, ..., AK の値を聞き、N の値は知りませんが、推定してみたくなりました。

 

 ゲームの開始前にいた子供たちの人数として考えられる最小の値と、最大の値を求めてください。

 もしくは、考えられる N の値は存在しないと判定してください。

 



=================================================================



解説=============================================================



 後ろから考える

 

 後ろから考えた時、その時点での最小値と最大値を l,r とすると

 ここで A[i] を見た時 , l と　r の間に A[i]の倍数がなければ -1

 あれば

  l = (l + A[i] - 1)/A[i] * A[i]

  r = (r/A[i] + 1)*A[i] - 1

 となる

 

================================================================

*/

void solve(){

    ll K; cin >> K;

    vector<ll> A(K);

    for(auto &in:A) cin >> in;

    if(A[K-1] != 2){ cout << -1 << endl; return; }

    ll l = 2, r = 2;

    for(ll i = K - 1; i >= 0; i--){

        ll t = (l + A[i] - 1)/A[i] * A[i];

        if(t < l || t > r){

            cout << -1 << endl; return;

        }

        l = t;

        r = (r/A[i] + 1)*A[i] - 1;

    }

    cout << l << " " << r << endl;

}

int main(void) {

	cin.tie(0); ios::sync_with_stdio(false);

    solve();

	return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

long long a[100001],k,cnt,now=2,max=2,min=2;

int main()

{

	scanf("%lld",&k);

	for(int i=1;i<=k;++i)scanf("%lld",a+i);

	for(int i=k;i>=1;--i){

		max=(max/a[i]+1)*a[i]-1;

		min=((min-1)/a[i]+1)*a[i];

		if(max<min){puts("-1");return 0;}

	}

	printf("%lld %lld\n",min,max);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



using VS = vector<string>;    using LL = long long;

using VI = vector<int>;       using VVI = vector<VI>;

using PII = pair<int, int>;   using PLL = pair<LL, LL>;

using VL = vector<LL>;        using VVL = vector<VL>;



#define ALL(a)  begin((a)),end((a))

#define RALL(a) (a).rbegin(), (a).rend()

#define PB push_back

#define EB emplace_back

#define MP make_pair

#define SZ(a) int((a).size())

#define SORT(c) sort(ALL((c)))

#define RSORT(c) sort(RALL((c)))

#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)

#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)

#define debug(x) cerr << #x << ": " << x << endl

const int INF = 1e9;                          const LL LINF = 1e16;

const LL MOD = 1000000007;                    const double PI = acos(-1.0);

int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };



/* -----  2018/03/03  Problem: 020_agc_b / Link: https://agc020.contest.atcoder.jp/tasks/agc020_b?lang=en  ----- */

/* ------問題------



スケートリンクで、一人の大人の司会と N 人の子供がゲームを行います。 ゲームは K ラウンドからなり、ラウンド i では司会が次のように言います。

Ai 人組を作って！

すると、まだ脱落していない子供たちは Ai 人からなるグループをできるだけ多く組みます。 一人につき一つのグループにしか入れません。 グループに入れなかった子供たちは脱落し、その他は次のラウンドに進みます。 ラウンドで誰も脱落しないこともありえます。

最後まで、つまりラウンド K のあとまで残ったのは 2 人で、彼らが勝者となりました。

あなたは A1, A2, ..., AK の値を聞き、N の値は知りませんが、推定してみたくなりました。

ゲームの開始前にいた子供たちの人数として考えられる最小の値と、最大の値を求めてください。もしくは、考えられる N の値は存在しないと判定してください。



-----問題ここまで----- */

/* -----解説等-----



逆から実際の値の範囲を復元していく。

下限は次の条件を満たさないといけないので(a[i]での下限)

上限は条件を満たしていれば少し多くても大丈夫なので(上限 + (a[i]-1))



----解説ここまで---- */



LL N;



LL ans = 0LL;



int main() {

	cin.tie(0);

	ios_base::sync_with_stdio(false);



	cin >> N;

	VI a(N);

	FOR(i, 0, N) {

		cin >> a[i];

	}

	reverse(ALL(a));

	ans = 1;

	if (a.front() != 2)ans = 0;



	LL L = 2, R = 2;



	FOR(i, 0, N) {

		LL x = (L + a[i] - 1) / a[i] * a[i];

		if (x < L || R < x)ans = 0;

		L = x;

		R = (R / a[i])* a[i] + (a[i] - 1); // 上げる

	}

	if (!ans) {

		cout << -1 << endl;

	}

	else {

		cout << L << " " << R << "\n";

	}

	return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

long long a[100001],k,cnt,now=2,max=2,min=2;

int main()

{

	scanf("%lld",&k);

	for(int i=1;i<=k;++i)scanf("%lld",a+i);

	for(int i=k;i>=1;--i){

		max=(max/a[i]+1)*a[i]-1;

		min=((min-1)/a[i]+1)*a[i];

		if(max<min){puts("-1");return 0;}

	}

	printf("%lld %lld\n",min,max);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
    #include <iostream>

#include<cstdio>

    using namespace std;

    long long NMAX,NMIN;

    int K;

    int A[100005];

    long long eval(long long N){

        for(int i = 1;i <= K;i++){

            N =N - N % A[i];}

        return N;

    }

    int main()

    {

        cin >> K;

        for(int i = 1;i <= K;i++){

            cin >> A[i];

        }

        long long st = 0,dr = 1e18;

        while(dr - st >= 1){

            long long mid = (st + dr) / 2;

            if(eval(mid) >= 2){

                dr = mid;

            }

            else {

                st = mid + 1;

            }

        }

      long long L = dr;

        st = 0,dr = 1e18;

        while(dr - st >= 1){

            long long mid = (st + dr) / 2;

            if(eval(mid) <= 2){

                st = mid + 1;

            }

            else {

                dr = mid;

            }

        }



    long long R = st - 1;

//    cout << L << ' '<< R << endl;

    if(L > R) puts("-1");

    else cout << L << ' '<< R << endl;

        return 0;

    }


// Optimized solution to the same problem (faster):


#include<cstdio>

int n, a[100005];

long long ok(long long x){

    for(int i = 1; i <= n; ++i) x = x - x % a[i];

    return x;

}

int main(){

    scanf("%d", &n);

    for(int i = 1; i <= n; ++i) scanf("%d", &a[i]);

    long long l = 0, r = 1e18;

    while(l <= r){

        long long mid = (l + r) / 2;

        if(ok(mid) >= 2) r = mid - 1;

        else l = mid + 1;

    }

    long long down = l;

    l = 0, r = 1e18;

    while(l <= r){

        long long mid = (l + r) / 2;

        if(ok(mid) <= 2) l = mid + 1;

        else r = mid - 1;

    }

    long long up = r;

    if(up < down) puts("-1");

    else printf("%lld %lld\n", down, up);

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include<cstdio>

using namespace std;

int K, A[100005];

long long eval(long long N){

    for(int i = 1;i <= K;i++) N =N - N % A[i];

    return N;

}

int main(){

    cin >> K;

    for(int i = 1;i <= K;i++) cin >> A[i];

    long long  l = 0, r = 1e18;

    while(l <= r){

        long long  mid = (l + r) / 2;

        if(eval(mid) >= 2) r = mid - 1;

        else l = mid + 1;

    }

    long long L = l;

    l = 0, r = 1e18;

    while(l <= r){

        long long  mid = (l + r) / 2;

        if(eval(mid) <= 2) l = mid + 1;

        else r = mid - 1;

    }

    long long R = r;

    if(L > R) puts("-1");

    else cout << L << ' '<< R << endl;

    return 0;

}

// Optimized solution to the same problem (faster):


#include<cstdio>

int n, a[100005];

long long ok(long long x){

    for(int i = 1; i <= n; ++i) x = x - x % a[i];

    return x;

}

int main(){

    scanf("%d", &n);

    for(int i = 1; i <= n; ++i) scanf("%d", &a[i]);

    long long l = 0, r = 1e18;

    while(l <= r){

        long long mid = (l + r) / 2;

        if(ok(mid) >= 2) r = mid - 1;

        else l = mid + 1;

    }

    long long down = l;

    l = 0, r = 1e18;

    while(l <= r){

        long long mid = (l + r) / 2;

        if(ok(mid) <= 2) l = mid + 1;

        else r = mid - 1;

    }

    long long up = r;

    if(up < down) puts("-1");

    else printf("%lld %lld\n", down, up);

    return 0;

}


// Fastest known solution for this problem: