Algorithm


D. Swords
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

There were n types of swords in the theater basement which had been used during the plays. Moreover there were exactly x swords of each type. y people have broken into the theater basement and each of them has taken exactly z swords of some single type. Note that different people might have taken different types of swords. Note that the values x,y�,� and z are unknown for you.

The next morning the director of the theater discovers the loss. He counts all swords — exactly ai�� swords of the i-th type are left untouched.

The director has no clue about the initial number of swords of each type in the basement, the number of people who have broken into the basement and how many swords each of them have taken.

For example, if n=3�=3a=[3,12,6]�=[3,12,6] then one of the possible situations is x=12�=12y=5�=5 and z=3�=3. Then the first three people took swords of the first type and the other two people took swords of the third type. Note that you don't know values x,y�,� and z beforehand but know values of n and a.

Thus he seeks for your help. Determine the minimum number of people y, which could have broken into the theater basement, and the number of swords z each of them has taken.

Input

The first line of the input contains one integer n (2n2105)(2≤�≤2⋅105) — the number of types of swords.

The second line of the input contains the sequence a1,a2,,an�1,�2,…,�� (0ai109)(0≤��≤109), where ai�� equals to the number of swords of the i-th type, which have remained in the basement after the theft. It is guaranteed that there exists at least one such pair of indices (j,k)(�,�) that ajak��≠��.

Output

Print two integers y and z — the minimum number of people which could have broken into the basement and the number of swords each of them has taken.

Examples
input
Copy
3
3 12 6
output
Copy
5 3
input
Copy
2
2 9
output
Copy
1 7
input
Copy
7
2 1000000000 4 6 8 4 2
output
Copy
2999999987 2
input
Copy
6
13 52 0 13 26 52
output
Copy
12 13
Note

In the first example the minimum value of y equals to 55, i.e. the minimum number of people who could have broken into the basement, is 55. Each of them has taken 33 swords: three of them have taken 33 swords of the first type, and two others have taken 33 swords of the third type.

In the second example the minimum value of y is 11, i.e. the minimum number of people who could have broken into the basement, equals to 11. He has taken 77 swords of the first type.

 



 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming

#include <bits/stdc++.h>

using namespace std;

int const N = 2e5 + 10;
int n, mx, a[N];
long long tot;

vector<long long> divisors(long long m) {
	vector<long long> ret;

	long long sqrtm = sqrt(m) + 1;
	for(long long i = 1; i < sqrtm; ++i) {
		if(m % i == 0) {
			ret.push_back(i);
			ret.push_back(m / i);
		}
	}

	return ret;
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("in", "r", stdin);
#endif

	scanf("%d", &n);
	for(int i = 0; i < n; ++i) {
		scanf("%d", a + i);
		mx = max(mx, a[i]);
	}

	for(int i = 0; i < n; ++i)
		tot += (mx - a[i]);

	vector<long long> d = divisors(tot);
	sort(d.begin(), d.end());

	for(int i = 0, j = d.size() - 1; i < d.size(); ++i, --j) {
		bool ok = true;
		for(int k = 0; k < n; ++k)
			if((mx - a[k]) % d[j] != 0) {
				ok = false;
				break;
			}
		if(ok) {
			printf("%lld %lld\n", d[i], d[j]);
			return 0;
		}
	}

	return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
3
3 12 6

Output

x
+
cmd
5 3
Advertisements

Demonstration


Codeforcess Solution D. Swords-Solution in C, C++, Java, Python ,Codeforcess Solution,Swords

Previous
Codeforces solution 1080-B-B. Margarite and the best present codeforces solution
Next
CodeChef solution DETSCORE - Determine the Score CodeChef solution C,C+