#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;

#define MOD 1000000007

#define sz(v) ((int)v.size())
#define sqr(x) ((x) * (x))

#define rep(i, n) for (int i = 0; i < n; ++i)

#define fi first
#define se second
#define mp make_pair

#define pb push_back
#define eb emplace_back
int main() {
	ios::sync_with_stdio(0);
	int n;
	cin >> n;
	int m1 = 200, m2 = 200;
	rep(i, n) {
		int v;
		cin >> v;
		if (v < m1) m2 = m1, m1 = v;
		else if (v < m2) m2 = v;
	}
	cout << m2 << "\n";
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;

#define MOD 1000000007

#define sz(v) ((int)v.size())
#define sqr(x) ((x) * (x))

#define rep(i, n) for (int i = 0; i < n; ++i)

#define fi first
#define se second
#define mp make_pair

#define pb push_back
#define eb emplace_back
bool a[211];
int main() {
	ios::sync_with_stdio(0);
	int n;
	cin >> n;
	rep(i, n) {
		int v;
		cin >> v;
		a[v + 100] = 1;
	}
	int ctr = 0;
	rep(i, 205) {
		ctr += a[i];
		if (ctr == 2) {
			cout << i - 100 << "\n";
			break;
		}
	}
	return 0;
}


#include <iostream>

using namespace std;
int main() {
    int size,i , input;
    int min, secmin;
    cin>>size;
    if(size==1){
           cout<<"NO";
           return 0;
    }
    for(i=0;i<size; i++)
    {
        cin>>input;
        input=input+100;
        if(i==0){
            min=input;
            secmin=input;
        }
        if(i==1){
              if(size==2&&min==input){
           cout<<"NO";
           return 0;
              }
            secmin=input;
        }
            if(input<secmin&&input>min){
                secmin=input;
            }
            else if(input<min){
            secmin=min;
            min=input;
            }

    }
    std::cout << secmin-100 << std::endl;
    return 0;
}


#include <iostream>

using namespace std;
int main() {
    int size,i , input , flag=0;
    int min, secmin;
    cin>>size;
    for(i=0;i<size; i++)
    {
        cin>>input;
        input=input+100;
        if(i==0){
            min=input;
            secmin=input;
        }
        if(i==1||flag){
              secmin=input;
              flag=0;
              if(input==min)
              flag=1;

        }
            if(input<secmin&&input>min){
                secmin=input;
            }
            else if(input<min){
            secmin=min;
            min=input;
            }

    }

    if(min==secmin){
           cout<<"NO";
           return 0;
    }
    std::cout << secmin-100 << std::endl;
    return 0;
}


#include <iostream>

using namespace std;
int main() {
    int size,i , input;
    int min, secmin;
    cin>>size;
    for(i=0;i<size; i++)
    {
        cin>>input;
        input=input+100;
        if(i==0){
            min=input;
            secmin=input;
        }
            if(input<secmin&&input>min){
                secmin=input;
            }
            else if(input<min){
            secmin=min;
            min=input;
            }

    }

    if(min==secmin){
           cout<<"NO";
           return 0;
    }
    std::cout << secmin-100 << std::endl;
    return 0;
}


#include <iostream>

using namespace std;
int main() {
    int size,i , input;
    int min, secmin;
    cin>>size;
    if(size==1){
           cout<<"NO";
           return 0;
    }
    for(i=0;i<size; i++)
    {
        cin>>input;
        input=input+100;
        if(i==0){
            min=input;
            secmin=input;
        }
        if(i==1){
            secmin=input;
        }
            if(input<secmin&&input>min){
                secmin=input;
            }
            else if(input<min){
            secmin=min;
            min=input;
            }

    }
    std::cout << secmin-100 << std::endl;
    return 0;
}


#include <iostream>

using namespace std;
int main() {
    int size,i , input;
    int min, secmin;
    cin>>size;
    for(i=0;i<size; i++)
    {
        cin>>input;
        input=input+100;
        if(i==0){
            min=input;
            secmin=input;
        }
        if(i>0&&input!=min){
              if(size==2&&min==input){
           cout<<"NO";
           return 0;
              }
            secmin=input;
        }
            if(input<secmin&&input>min){
                secmin=input;
            }
            else if(input<min){
            secmin=min;
            min=input;
            }

    }

    if(min==secmin){
           cout<<"NO";
           return 0;
    }
    std::cout << secmin-100 << std::endl;
    return 0;
}


#include <iostream>

using namespace std;
int main() {
    int size,i , input;
    int min, secmin;
    cin>>size;
    for(i=0;i<size; i++)
    {
        cin>>input;
        input=input+100;
        if(i==0){
            min=input;
            secmin=input;
        }
        if(i==1){
            secmin=input;
        }
            if(input<secmin&&input>min){
                secmin=input;
            }
            else if(input<min){
            secmin=min;
            min=input;
            }

    }
    std::cout << secmin-100 << std::endl;
    return 0;
}


#include <iostream>

using namespace std;
int main() {
    int size,i , input;
    int min, secmin;
    cin>>size;
    for(i=0;i<size; i++)
    {
        cin>>input;
        input=input+100;
        if(i==0){
            min=input;
            secmin=input;
        }
        if(i==1){
              if(size==2&&min==input){
           cout<<"NO";
           return 0;
              }
            secmin=input;
        }
            if(input<secmin&&input>min){
                secmin=input;
            }
            else if(input<min){
            secmin=min;
            min=input;
            }

    }

    if(min==secmin){
           cout<<"NO";
           return 0;
    }
    std::cout << secmin-100 << std::endl;
    return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#include <stack>
#include <queue>
#include <string>

using namespace std;
#define all(v)  v.begin(),v.end()
#define sz(v) int v.size()

int main()
{
    int size=0,counter=0;
    cin>>size;
    int arr[size];
    for(int i=0;i<size;i++)
        {
            cin>>arr[i];
            if(i>0)
            {
                if(arr[i]!=arr[i-1])
                    counter++;
            }
        }
    sort(arr,arr+size);
    if(size>1&&counter>0)
    {
        for(int i=0;i<size;i++)
        {
            if(arr[i]>arr[0])
            {
                cout<<arr[i]<<"\n";
                break;
            }
        }
    }
    else
    {
        cout<<"NO\n";
    }
	return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#include <stack>
#include <queue>
#include <string>

using namespace std;
#define all(v)  v.begin(),v.end()
#define sz(v) int v.size()

int main()
{
    int size=0;
    cin>>size;
    int arr[size];
    for(int i=0;i<size;i++)
        cin>>arr[i];
    sort(arr,arr+size);
    for(int i=0;i<size;i++)
    {
        if(arr[i]>arr[0])
        {
            cout<<arr[i]<<"\n";
            break;
        }
    }
	return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#include <stack>
#include <queue>
#include <string>

using namespace std;
#define all(v)  v.begin(),v.end()
#define sz(v) int v.size()

int main()
{
    int size=0,counter=0;
    cin>>size;
    int arr[size];
    for(int i=0;i<size;i++)
        {
            cin>>arr[i];
            if(arr[i]>arr[i-1])
                counter++;
        }
    sort(arr,arr+size);
    if(size>1&&counter>0)
    {
        for(int i=0;i<size;i++)
        {
            if(arr[i]>arr[0])
            {
                cout<<arr[i]<<"\n";
                break;
            }
        }
    }
    else
    {
        cout<<"NO\n";
    }
	return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#include <stack>
#include <queue>
#include <string>

using namespace std;
#define all(v)  v.begin(),v.end()
#define sz(v) int v.size()

int main()
{
    int size=0;
    cin>>size;
    int arr[size];
    for(int i=0;i<size;i++)
        cin>>arr[i];
    sort(arr,arr+size);
    for(int i=0;i<size;i++)
    {
        if(arr[i]>arr[0])
        {
            cout<<arr[i]<<"\n";
            break;
        }
        else
        {
            cout<<"No\n";
            break;
        }
    }
	return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#include <stack>
#include <queue>
#include <string>

using namespace std;
#define all(v)  v.begin(),v.end()
#define sz(v) int v.size()

int main()
{
    int size=0;
    cin>>size;
    int arr[size];
    for(int i=0;i<size;i++)
        cin>>arr[i];
    sort(arr,arr+size);
    if(size>1)
    {
        for(int i=0;i<size;i++)
        {
            if(arr[i]>arr[0])
            {
                cout<<arr[i]<<"\n";
                break;
            }
        }
    }
    else
    {
        cout<<"NO\n";
    }
	return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#include <stack>
#include <queue>
#include <string>

using namespace std;
#define all(v)  v.begin(),v.end()
#define sz(v) int v.size()

int main()
{
    int size=0,counter=0;
    cin>>size;
    int arr[size];
    for(int i=0;i<size;i++)
        {
            cin>>arr[i];
            if(arr[i]>arr[i-1]||arr[i]<arr[i-1])
                counter++;
        }
    sort(arr,arr+size);
    if(size>1&&counter>0)
    {
        for(int i=0;i<size;i++)
        {
            if(arr[i]>arr[0])
            {
                cout<<arr[i]<<"\n";
                break;
            }
        }
    }
    else
    {
        cout<<"NO\n";
    }
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int arr[n];
    for(int i=0; i<n; i++)
    {
        cin>>arr[i];
    }
    sort(arr,arr+n);
    bool ok=0;
    for(int i=0; i<n-1; i++)
    {
        if(arr[i]!=arr[i+1])
        {
            cout<<arr[i+1];
            ok=1;
            break;
        }
    }
    if(!ok)
    {
        cout<<"NO";
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin>>n;
    set<int>s;
    for(int i=0; i<n; i++){
        int x;
        cin>>x;
        s.insert(x);
    }
    if(s.size()==1){
        cout<<"NO";
    }
    else{
        int cnt=0,m=0;
        for(set<int>::iterator it=s.begin(); it!=s.end(); it++){
            m=*it;
            cnt++;
            if(cnt==2){
                cout<<m;
                break;
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin>>n;
    set<int>s;
    for(int i=0; i<n; i++){
        int x;
        cin>>x;
        s.insert(x);
    }
    if(s.size()==1){
        cout<<"No";
    }
    else{
        int cnt=0,m=0;
        for(set<int>::iterator it=s.begin(); it!=s.end(); it++){
            m=*it;
            cnt++;
            if(cnt==2){
                cout<<m;
                break;
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int arr[n];
    for(int i=0; i<n; i++)
    {
        cin>>arr[i];
    }
    sort(arr,arr+n);
    for(int i=0; i<n; i++)
    {
        if(arr[i]!=arr[i+1])
        {
            cout<<arr[i+1];
            break;
        }
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int arr[n];
    for(int i=0; i<n; i++)
    {
        cin>>arr[i];
    }
    sort(arr,arr+n);
    int cnt=0;
    for(int i=0; i<n; i++)
    {
        if(arr[i]==arr[i+1])
        {
            cnt++;
        }
    }
    cout<<cnt;
    return 0;
}


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

set<int>a;
set<int>::iterator it;
int main(){
	int n, l;
	cin>>n;
	int g[n];
	for(int k=0; k<n; k++){
		cin>>g[k];
		a.insert(g[k]);
	}
	if(n==1){
		cout<<"NO";
		return 0;
	}
	it=a.begin();
	it++;
	cout<<*it;

	return 0;
}


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

set<int>a;
set<int>::iterator it;
int main(){
	int n, l;
	cin>>n;
	int g[n];
	for(int k=0; k<n; k++){
		cin>>g[k];
		a.insert(g[k]);
	}
	for(it=a.begin(); it!=a.end(); it++){
		l++;
		if(l==2){
			cout<<*it;
		}
	}
	return 0;
}


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

set<int>a;
set<int>::iterator it;
int main(){
	int n, l;
	cin>>n;
	int g[n];
	for(int k=0; k<n; k++){
		cin>>g[k];
		a.insert(g[k]);
	}
	if(n==1){
		cout<"NO";
		return 0;
	}
	it=a.begin();
	it++;
	cout<<*it;

	return 0;
}


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

set<int>a;
set<int>::iterator it;
int main(){
	int n, l;
	cin>>n;
	int g[n];
	for(int k=0; k<n; k++){
		cin>>g[k];
		a.insert(g[k]);
	}
	if(a.size()==1){
		cout<<"NO";
		return 0;
	}
	it=a.begin();
	it++;
	cout<<*it;

	return 0;
}


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

set<int>a;
set<int>::iterator it;
int main(){
	int n, l;
	cin>>n;
	int g[n];
	for(int k=0; k<n; k++){
		cin>>g[k];
		a.insert(g[k]);
	}
	it=a.begin();
	it++;
	cout<<*it;

	return 0;
}


/*
ID: zhaowei10
TASK:
LANG: C++14
*/
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

using namespace __gnu_cxx;
using namespace __gnu_pbds;
using namespace std;

#ifdef LOCAL
#include <debug.h>
#else
#define debug(...) 0
#endif

#define eb emplace_back

using ll = long long;
using ld = long double;
using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
using vc = vector<char>;
using vb = vector<bool>;
using vll = vector<ll>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(9);

#ifdef LOCAL
  freopen("test.in", "r", stdin);
  freopen("test.out", "w", stdout);
#else
#endif

  int n;
  cin >> n;
  unordered_map<int, int> beauties;
  int cmin = INT_MAX, cmax = INT_MIN;
  vi flowers;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    flowers.eb(x);
    cmin = min(x, cmin);
    cmax = max(x, cmax);
  }

  ll ans = 0;
  int delta = cmax - cmin;
  for (int i = 0; i < n; ++i) {
    beauties[flowers[i]]++;
    ans += beauties[flowers[i] - delta];
  }
  cout << delta << ' ' << ans;
}


#include<bits/stdc++.h>

using namespace std;

const int MAX_n = 2e5+7;
long long int n , arr[MAX_n];
long long int Min = 0 , Max = 0 , a = 0 , b = 0;

int main(){

	cin >> n;

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

		cin >> arr[i];

	}

	Min = arr[0];

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

		if(arr[i] < Min)
			Min = arr[i];

		if(arr[i] == Min)
			a ++;

		if(arr[i] > Max)
			Max =arr[i];

		if(arr[i] == Max)
			b ++;

	}

	cout << Max - Min << " " << a*b << endl;

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int MAX_n = 2e5+7;
long long int n , arr[MAX_n];
long long int Min = 0 , Max = 0 , a = 0 , b = 0;

int main(){

	cin >> n;

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

		cin >> arr[i];

		if(arr[i] < Min)
			Min = arr[i];

		if(arr[i] == Min)
			a ++;

		if(arr[i] > Max)
			Max =arr[i];

		if(arr[i] == Max)
			b ++;

	}

	cout << Max - Min << " " << a*b << endl;

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int MAX_n = 2e5+7;
long long int n , arr[MAX_n];
long long int Min = 0 , Max = 0 , a = 0 , b = 0;

int main(){

	cin >> n;

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

		cin >> arr[i];

	}

	Min = arr[0];

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

		if(arr[i] < Min)
			Min = arr[i] , a = 0;

		if(arr[i] == Min)
			a ++;

		if(arr[i] > Max)
			Max = arr[i] , b = 0;

		if(arr[i] == Max)
			b ++;

	}

	if(Min == Max){

		cout << 0 << " " << n-1*n/2 << endl;
		return 0;

	}

	cout << Max - Min << " " << a*b << endl;

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int MAX_n = 2e5+7;
long long int n , arr[MAX_n];
long long int Min = 0 , Max = 0 , a = 0 , b = 0;

int main(){

	cin >> n;

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

		cin >> arr[i];

	}

	Min = arr[0];

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

		if(arr[i] < Min)
			Min = arr[i] , a = 0;

		if(arr[i] == Min)
			a ++;

		if(arr[i] > Max)
			Max = arr[i] , b = 0;

		if(arr[i] == Max)
			b ++;

	}

	if(Min == Max){

		cout << 0 << " " << n-1 << endl;
		return 0;

	}

	cout << Max - Min << " " << a*b << endl;

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int MAX_n = 2e5+7;
long long int n , arr[MAX_n];
long long int Min = 0 , Max = 0 , a = 0 , b = 0;

int main(){

	cin >> n;

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

		cin >> arr[i];

	}

	Min = arr[0];

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

		if(arr[i] < Min)
			Min = arr[i] , a = 0;

		if(arr[i] == Min)
			a ++;

		if(arr[i] > Max)
			Max = arr[i] , b = 0;

		if(arr[i] == Max)
			b ++;

	}

	cout << Max - Min << " " << a*b << endl;

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int MAX_n = 2e5+7;
long long int n , arrMAX_n];
long long int Min = 0 , Max = 0 , a = 0 , b = 0;

int main(){

	cin >> n;

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

		cin >> arr[i];

		if(arr[i] < Min)
			Min = arr[i];

		if(arr[i] == Min)
			a ++;

		if(arr[i] > Max)
			Max =arr[i];

		if(arr[i] == Max)
			b ++;

	}

	cout << Max - Min << " " << a*b << endl;

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int MAX_n = 2e5+7;
long long int n , arr[MAX_n];
long long int Min = 0 , Max = 0 , a = 0 , b = 0;

int main(){

	cin >> n;

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

		cin >> arr[i];

	}

	Min = arr[0];

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

		if(arr[i] < Min)
			Min = arr[i] , a = 0;

		if(arr[i] == Min)
			a ++;

		if(arr[i] > Max)
			Max = arr[i] , b = 0;

		if(arr[i] == Max)
			b ++;

	}

	if(Min == Max){

		cout << 0 << " " << (n-1)*n/2 << endl;
		return 0;

	}


#include<bits/stdc++.h>

using namespace std;

const int MAX_n = 2e5+7;
long long int n , arr[MAX_n];
long long int Min = 0 , Max = 0 , a = 0 , b = 0;

int main(){

	cin >> n;

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

		cin >> arr[i];

	}

	Min = arr[0];

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

		if(arr[i] < Min)
			Min = arr[i] , a = 1;

		if(arr[i] == Min)
			a ++;

		if(arr[i] > Max)
			Max = arr[i] , b = 1;

		if(arr[i] == Max)
			b ++;

	}

	cout << Max - Min << " " << a*b << endl;

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int MAX_n = 2e5+7;
long long int n , arr[MAX_n];
long long int Min = 0 , Max = 0 , a = 0 , b = 0;

int main(){

	cin >> n;

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

		cin >> arr[i];

	}

	if(n == 2 && arr[0] == arr[1]){

		cout << 0 << " " << 1;
		return 0;

	}

	Min = arr[0];

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

		if(arr[i] < Min)
			Min = arr[i] , a = 0;

		if(arr[i] == Min)
			a ++;

		if(arr[i] > Max)
			Max = arr[i] , b = 0;

		if(arr[i] == Max)
			b ++;

	}

	cout << Max - Min << " " << a*b << endl;

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int MAX_n = 2e5+7;
long long int n , arr[MAX_n];
long long int Min = 0 , Max = 0 , a = 0 , b = 0;

int main(){

	cin >> n;

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

		cin >> arr[i];

	}

	Min = arr[0];

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

		if(arr[i] < Min)
			Min = arr[i] , a = 0;

		if(arr[i] == Min)
			a ++;

		if(arr[i] > Max)
			Max = arr[i] , b = 0;

		if(arr[i] == Max)
			b ++;

	}

	if(Min == Max){

		cout << 0 << " " << (n-1)*n/2 << endl;
		return 0;

	}

	cout << Max - Min << " " << a*b << endl;

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

const int MAX_n = 2e5+7;
long long int n , arr[MAX_n];
long long int Min = 0 , Max = 0 , a = 0 , b = 0;

int main(){

	cin >> n;

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

		cin >> arr[i];

	}

	if(n == 2 && arr[0] == arr[1]){

		cout << 0 << " " << 1;
		return 0;

	}

	Min = arr[0];

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

		if(arr[i] < Min)
			Min = arr[i] , a = 1;

		if(arr[i] == Min)
			a ++;

		if(arr[i] > Max)
			Max = arr[i] , b = 1;

		if(arr[i] == Max)
			b ++;

	}

	cout << Max - Min << " " << a*b << endl;

	return 0;
}


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

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

    // get the max and min
    long long max = 0;
    long long min = INT_MAX;
    long long countMax = 0;
    long long countMin = 0;

    for (int i = 0; i < n; i++) {
        if (a[i] == max) countMax++;
        if (a[i] == min) countMin++;
        if (a[i] > max) {
            max = a[i];
            countMax = 1;
        }
        if (a[i] < min){
            min = a[i];
            countMin = 1;
        }
    }

    cout << max - min << " " << countMax * countMin;
    return 0;

}


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

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

    // get the max and min
    long long max = 0;
    long long min = INT_MAX;
    long long countMax = 0;
    long long countMin = 0;

    for (int i = 0; i < n; i++) {
        if (a[i] == max) countMax++;
        if (a[i] == min) countMin++;
        if (a[i] > max) {
            max = a[i];
            countMax = 1;
        }
        if (a[i] < min){
            min = a[i];
            countMin = 1;
        }
    }

    cout << max - min << " ";
    if (max == min) cout << n * (n-1) / 2;
    else cout << countMax * countMin;
    return 0;

}


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

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

    // get the max and min
    long max = 0;
    long min = INT_MAX;

    for (int i = 0; i < n; i++) {
        if (a[i] > max) max = a[i];
        if (a[i] < min) min = a[i];
    }

    long countMax = 0;
    long countMin = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] == max) countMax++;
        if (a[i] == min) countMin++;
    }

    cout << max - min << " " << countMax * countMin;

}


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

int main() {
    int n;
    long a[(int) 2e5];
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a [i];
    }

    // get the max and min
    long max = 0;
    long min = INT_MAX;

    for (int i = 0; i < n; i++) {
        if (a[i] > max) max = a[i];
        if (a[i] < min) min = a[i];
    }

    long countMax = 0;
    long countMin = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] == max) countMax++;
        if (a[i] == min) countMin++;
    }

    cout << max - min << " " << countMax * countMin;

}


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

int main() {
    int n;
    int a[(int) 2e5];
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a [i];
    }

    // get the max and min
    int max = 0;
    int min = INT_MAX;

    for (int i = 0; i < n; i++) {
        if (a[i] > max) max = a[i];
        if (a[i] < min) min = a[i];
    }

    int countMax = 0;
    int countMin = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] == max) countMax++;
        if (a[i] == min) countMin++;
    }

    cout << max - min << " " << countMax * countMin;

}


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

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

    // get the max and min
    long max = 0;
    long min = INT_MAX;
    long countMax = 0;
    long countMin = 0;

    for (int i = 0; i < n; i++) {
        if (a[i] == max) countMax++;
        if (a[i] == min) countMin++;
        if (a[i] > max) {
            max = a[i];
            countMax = 1;
        }
        if (a[i] < min){
            min = a[i];
            countMin = 1;
        }
    }

    cout << max - min << " " << countMax * countMin;

}


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

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

    // get the max and min
    long long max = 0;
    long long min = INT_MAX;
    long long countMax = 0;
    long long countMin = 0;

    for (int i = 0; i < n; i++) {
        if (a[i] == max) countMax++;
        if (a[i] == min) countMin++;
        if (a[i] > max) {
            max = a[i];
            countMax = 1;
        }
        if (a[i] < min){
            min = a[i];
            countMin = 1;
        }
    }

    cout << max - min << " ";
    if (max == min) cout << n * (n-1) / 2;
    else cout << countMax * countMin;
    return 0;

}


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

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

    // get the max and min
    long long max = 0;
    long long min = INT_MAX;
    long long countMax = 0;
    long long countMin = 0;

    for (int i = 0; i < n; i++) {
        if (a[i] == max) countMax++;
        if (a[i] == min) countMin++;
        if (a[i] > max) {
            max = a[i];
            countMax = 1;
        }
        if (a[i] < min){
            min = a[i];
            countMin = 1;
        }
    }

    cout << max - min << " ";
    if (max == min) cout << n * (n-1) / 2;
    else cout << countMax * countMin;
    return 0;

}


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

int main() {
    int n;
    long a[(int) 2e5];
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a [i];
    }

    // get the max and min
    long max = 0;
    long min = INT_MAX;

    for (int i = 0; i < n; i++) {
        if (a[i] > max) max = a[i];
        if (a[i] < min) min = a[i];
    }

    int countMax = 0;
    int countMin = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] == max) countMax++;
        if (a[i] == min) countMin++;
    }

    cout << max - min << " " << countMax * countMin;

}


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

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

    // get the max and min
    long long max = 0;
    long long min = INT_MAX;
    long long countMax = 0;
    long long countMin = 0;

    for (int i = 0; i < n; i++) {
        if (a[i] == max) countMax++;
        if (a[i] == min) countMin++;
        if (a[i] > max) {
            max = a[i];
            countMax = 1;
        }
        if (a[i] < min){
            min = a[i];
            countMin = 1;
        }
    }

    cout << max - min << " ";
    if (max == min) cout << n * (n-1) / 2;
    else cout << countMax * countMin;
    return 0;

}


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

int main() {
    long long n;
    int a[200005];
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a [i];
    }

    // get the max and min
    long long max = 0;
    long long min = INT_MAX;
    long long countMax = 0;
    long long countMin = 0;

    for (int i = 0; i < n; i++) {
        if (a[i] == max) countMax++;
        if (a[i] == min) countMin++;
        if (a[i] > max) {
            max = a[i];
            countMax = 1;
        }
        if (a[i] < min){
            min = a[i];
            countMin = 1;
        }
    }

    cout << max - min << " ";
    if (max == min) cout << n * (n-1) / 2;
    else cout << countMax * countMin;
    return 0;

}


#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    long int n,counnt=0;
    cin>>n;
    long int arr[100000];
    for(int long i=0;i<n;i++){
        cin>>arr[i];
    }
    sort(arr,arr+n);
    int Max = arr[n-1]-arr[0];
    int c1=1,c2=1;
    for(long int i=1;i<n-1;i++){
            if(arr[i]==arr[0]){
                c1++;
            }
            if(arr[i]==arr[n-1]){
                c2++;
            }

    }
    counnt = c1*c2;
    cout<<Max<<" "<<counnt;
    return 0;

}


#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int arr[100000];
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    sort(arr,arr+n);
    int Max = arr[n-1]-arr[0];
    int c1=1,c2=1;
    for(int i=1;i<n-1;i++){
            if(arr[i]!=arr[0]){
                c1 = c1+i-1;
                break;
            }
    }
    for(int i=n-2,j=1;i>0;i--,j++){
            if(arr[i]!=arr[n-1]){
                c2 = c2+j-1;
                break;
            }

    }

    cout<<Max<<" "<<c1*c2;
    return 0;

}


#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    long int n,counnt=0;
    cin>>n;
    long int arr[100000];
    for(int long i=0;i<n;i++){
        cin>>arr[i];
    }
    sort(arr,arr+n);
    int Max = arr[n-1]-arr[0];
    int c1=0,c2=0;
    for(long int i=1;i<n-1;i++){
            if(arr[i]!=arr[0]){
                c1 = c1+i;
                break;
            }
    }
    for(long int i=n-2;i>0;i--){
            if(arr[i]!=arr[n-1]){
                c2 = c2+i;
                break;
            }

    }

    counnt = c1*c2;
    cout<<Max<<" "<<counnt;
    return 0;

}


#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int arr[200000];
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    sort(arr,arr+n);
    int Max = arr[n-1]-arr[0];
    long long int i=1,j=n-2,k=1;
    while(arr[i]==arr[0]){
        i = i+1;
    }
    while(arr[j]==arr[n-1]){
            j=j-1;
            k=k+1;
        }
    long long int counnt = i*k;
    cout<<Max<<" "<<;
    return 0;

}


#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    long int n;
    cin>>n;
    long int arr[100000];
    for(int long i=0;i<n;i++){
        cin>>arr[i];
    }
    sort(arr,arr+n);
    int Max = arr[n-1]-arr[0];
    int c1=1,c2=1;
    for(long int i=1;i<n-1;i++){
            if(arr[i]!=arr[0]){
                c1 = c1+i-1;
                break;
            }
    }
    for(long int i=n-2,j=1;i>0;i--,j++){
            if(arr[i]!=arr[n-1]){
                c2 = c2+j-1;
                break;
            }

    }

    cout<<Max<<" "<<c1*c2;
    return 0;

}


#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int arr[100000];
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    sort(arr,arr+n);
    int Max = arr[n-1]-arr[0];
    int i=1,j=n-2,k=1;
    while(arr[i]==arr[0]){
        i = i+1;
    }
    while(arr[j]==arr[n-1]){
            j=j-1;
            k=k+1;
        }
    cout<<Max<<" "<<i*k;
    return 0;

}


#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    long int n,counnt=0;
    cin>>n;
    long int arr[100000];
    for(int long i=0;i<n;i++){
        cin>>arr[i];
    }
    sort(arr,arr+n);
    int Max = arr[n-1]-arr[0];
    int c1=1,c2=1;
    for(long int i=1;i<n-1;i++){
            if(arr[i]==arr[0]){
                c1++;
            }
            else{
                break;
            }

    }
    for(long int i=n-2;i>0;i--){
            if(arr[i]==arr[n-1]){
                c2++;
            }
            else{
                break;
            }

    }

    counnt = c1*c2;
    cout<<Max<<" "<<counnt;
    return 0;

}


#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    cin>>n;
    bool check = true;
    int arr[200000];
    for(int i=0;i<n;i++){
        cin>>arr[i];
        if(arr[i]!=arr[i-1] && i!=0){
            check =false;
        }
    }
    if(check){
        cout<<0<<" "<<(n*(n-1))/2;
        return 0;
    }
    sort(arr,arr+n);
    int Max = arr[n-1]-arr[0];
    long long int i=1,j=n-2,k=1;
    while(arr[i]==arr[0]){
        i = i+1;
    }
    while(arr[j]==arr[n-1]){
            j=j-1;
            k=k+1;
        }
    long long int counnt = i*k;
    cout<<Max<<" "<<counnt;
    return 0;

}


#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int arr[200000];
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    sort(arr,arr+n);
    int Max = arr[n-1]-arr[0];
    int i=1,j=n-2,k=1;
    while(arr[i]==arr[0]){
        i = i+1;
    }
    while(arr[j]==arr[n-1]){
            j=j-1;
            k=k+1;
        }
    cout<<Max<<" "<<i*k;
    return 0;

}


#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int n,counnt=0;
    cin>>n;
    int arr[10000];
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    sort(arr,arr+n);
    int Max = arr[n-1]-arr[0];
    int c1=1,c2=1;
    for(int i=1;i<n-1;i++){
            if(arr[i]==arr[0]){
                c1++;
            }
            if(arr[i]==arr[n-1]){
                c2++;
            }

    }
    counnt = c1*c2;
    cout<<Max<<" "<<counnt;
    return 0;

}


#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int n,counnt=0;
    cin>>n;
    int arr[10000];
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    sort(arr,arr+n);
    int Max = arr[n-1]-arr[0];
    for(int i=0,j=n-1;i<n;i++){
        while(arr[j]-arr[i]==Max){
            j=j-1;
            counnt = counnt+1;
            if(j==i){
                break;
            }
        }
        j=n-1;
    }
    cout<<Max<<" "<<counnt;
    return 0;

}


#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int arr[200000];
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    sort(arr,arr+n);
    int Max = arr[n-1]-arr[0];
    long long int i=1,j=n-2,k=1;
    while(arr[i]==arr[0]){
        i = i+1;
    }
    while(arr[j]==arr[n-1]){
            j=j-1;
            k=k+1;
        }
    long long int counnt = i*k;
    cout<<Max<<" "<<counnt;
    return 0;

}


#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    long long int n;
    cin>>n;
    bool check = true;
    int arr[200000];
    for(int i=0;i<n;i++){
        cin>>arr[i];
        if(arr[i]!=arr[i-1] && i!=0){
            check =false;
        }
    }
    if(check){
        cout<<0<<" "<<(n*(n-1))/2;
        return 0;
    }
    sort(arr,arr+n);
    int Max = arr[n-1]-arr[0];
    long long int i=1,j=n-2,k=1;
    while(arr[i]==arr[0]){
        i = i+1;
    }
    while(arr[j]==arr[n-1]){
            j=j-1;
            k=k+1;
        }
    long long int counnt = i*k;
    cout<<Max<<" "<<counnt;
    return 0;

}


#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    cin>>n;
    int arr[200000];
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    sort(arr,arr+n);
    int Max = arr[n-1]-arr[0];
    long int i=1,j=n-2,k=1;
    while(arr[i]==arr[0]){
        i = i+1;
    }
    while(arr[j]==arr[n-1]){
            j=j-1;
            k=k+1;
        }
    cout<<Max<<" "<<i*k;
    return 0;

}


#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int n,counnt;
    cin>>n;
    int arr[10000];
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    sort(arr,arr+n);
    int Max = arr[n-1]-arr[0];
    for(int i=0,j=n-1;i<n;i++){
        while(arr[j]-arr[i]==Max){
            j=j-1;
            counnt = counnt+1;
            if(j==i){
                break;
            }
        }
        j=n-1;
    }
    cout<<Max<<" "<<counnt;
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main(){

      int n,mn=INT_MAX,mx=INT_MIN;
      map<int,int>mp;
      cin >> n;
      int arr[200009];
      for(int i=0;i<n;i++){
        int x;
        cin >> x;
        arr[i] = x;
        mn = min(x,mn);
        mx = max(x,mx);
        //cout << mn  << " " << mx << endl;
      }
      sort(arr,arr+n);
      for(int i=0;i<n;i++)
        mp[arr[i]]++;

      int diff =  mx-mn;
      cout << diff  << " ";
      int cnt = 0;
      auto itr1 = mp.begin();
      auto itr =  mp.begin();
      itr++;
      auto itr2 = itr;

      while(itr1!=mp.end() && itr2 != mp.end()){

        //cout << itr1->first << " " << itr2->first << endl;
        if(itr2->first - itr1->first == diff)
            cnt = cnt +(itr1->second*itr2->second),itr1++,itr2++;
        else
            itr2++;

      }
      cout << cnt << endl;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){

      long long int n,mn=265555555555555,mx=-1;
      map<long long,int>mp;
      cin >> n;
      int arr[200009];
      for(int i=0;i<n;i++){
        long long x;
        cin >> x;
        arr[i] = x;
        mn = min(x,mn);
        mx = max(x,mx);
        //cout << mn  << " " << mx << endl;
      }
      sort(arr,arr+n);
      for(int i=0;i<n;i++)
        mp[arr[i]]++;

      //cout << mx << " " << mn << endl;
      int diff =  mx-mn;
      cout << diff  << " ";
      long long int cnt = 0;
      auto itr1 = mp.begin();

      long long int res1,res2;
      while(itr1!=mp.end() ){

        //cout << itr1->first << " " << itr2->first << endl;
        if(itr1->first == mx)
            res1 = itr1->second*1ll;;
        if(itr1->first == mn)
            res2 = itr1->second*1ll;

            itr1++;
      }
      cout << res1 << " " << res2 << endl;
      if(mp.size() == 1)
            cout << (n*n-1ll)/2ll << endl;
        else
            cout << res1*res2 << endl;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){

      long long int n,mn=INT_MAX,mx=INT_MIN;
      map<long long,int>mp;
      cin >> n;
      int arr[200009];
      for(int i=0;i<n;i++){
        long long x;
        cin >> x;
        arr[i] = x;
        mn = min(x,mn);
        mx = max(x,mx);
        //cout << mn  << " " << mx << endl;
      }
      sort(arr,arr+n);
      for(int i=0;i<n;i++)
        mp[arr[i]]++;

      //cout << mx << " " << mn << endl;
      int diff =  mx-mn;
      cout << diff  << " ";
      long long int cnt = 0;
      auto itr1 = mp.begin();

      long long int res1,res2;
      while(itr1!=mp.end() ){

        //cout << itr1->first << " " << itr2->first << endl;
        if(itr1->first == mx)
            res1 = itr1->second;
        if(itr1->first == mn)
            res2 = itr1->second;

            itr1++;
      }
      auto itr = mp.begin();
        cnt = res1*res2;
        //cout <<  res1*res2 << endl;
        cnt = max(cnt,itr->first);
        cout << cnt << endl;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){

      long long int n,mn=INT_MAX,mx=INT_MIN;
      map<long long,int>mp;
      cin >> n;
      int arr[200009];
      for(int i=0;i<n;i++){
        long long x;
        cin >> x;
        arr[i] = x;
        mn = min(x,mn);
        mx = max(x,mx);
        //cout << mn  << " " << mx << endl;
      }
      sort(arr,arr+n);
      for(int i=0;i<n;i++)
        mp[arr[i]]++;

      //cout << mx << " " << mn << endl;
      int diff =  mx-mn;
      cout << diff  << " ";
      long long int cnt = 0;
      auto itr1 = mp.begin();

      long long int res1,res2;
      while(itr1!=mp.end() ){

        //cout << itr1->first << " " << itr2->first << endl;
        if(itr1->first == mx)
            res1 = itr1->second;
        if(itr1->first == mn)
            res2 = itr1->second;

            itr1++;
      }
      if(mp.size() == 1)
            cout << (n*n-1)/2 << endl;
            else
                cout << res1*res2 << endl;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){

      long long int n,mn=INT_MAX,mx=INT_MIN;
      map<long long,int>mp;
      cin >> n;
      int arr[200009];
      for(int i=0;i<n;i++){
        long long x;
        cin >> x;
        arr[i] = x;
        mn = min(x,mn);
        mx = max(x,mx);
        //cout << mn  << " " << mx << endl;
      }
      sort(arr,arr+n);
      for(int i=0;i<n;i++)
        mp[arr[i]]++;

      //cout << mx << " " << mn << endl;
      int diff =  mx-mn;
      cout << diff  << " ";
      long long int cnt = 0;
      auto itr1 = mp.begin();

      long long int res1,res2;
      while(itr1!=mp.end() ){

        //cout << itr1->first << " " << itr2->first << endl;
        if(itr1->first == mx)
            res1 = itr1->second;
        if(itr1->first == mn)
            res2 = itr1->second;

            itr1++;
      }
      if(mp.size() == 1)
            cout << (n*n-1ll)/2ll << endl;
        else
            cout << res1*res2 << endl;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){

      int n,mn=INT_MAX,mx=INT_MIN;
      map<int,int>mp;
      cin >> n;
      int arr[200009];
      for(int i=0;i<n;i++){
        int x;
        cin >> x;
        arr[i] = x;
        mn = min(x,mn);
        mx = max(x,mx);
        //cout << mn  << " " << mx << endl;
      }
      sort(arr,arr+n);
      for(int i=0;i<n;i++)
        mp[arr[i]]++;

      int diff =  mx-mn;
      cout << diff  << " ";
      long long int cnt = 0;
      auto itr1 = mp.begin();
      auto itr =  mp.begin();
      itr++;
      auto itr2 = itr;

      while(itr1!=mp.end() && itr2 != mp.end()){

        //cout << itr1->first << " " << itr2->first << endl;
        if(itr2->first - itr1->first == diff)
            cnt = cnt +(itr1->second*itr2->second) * 1ll,itr1++,itr2++;
        else
            itr2++;

      }
      cout << cnt << endl;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){

      long long int n,mn=265555555555555,mx=-1,res1,res2;
      cin >> n;
      int arr[200009];
      for(int i=0;i<n;i++){
        long long x;
        cin >> x;
        arr[i] = x;
        mn = min(x,mn);
        mx = max(x,mx);
        //cout << mn  << " " << mx << endl;
      }
      sort(arr,arr+n);

      if(arr[0] == arr[n-1]){
            cout << (n*n-1ll)/2ll << endl;
            return 0;
      }
      res1=res2=0ll;
        for(int i=0;i<n;i++){
            if(arr[i] == mn)
                res2++;
                if(arr[i] == mx)
                res1++;
        }
        cout << res1 *res2 << endl;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){

      long long int n,mn=INT_MAX,mx=INT_MIN;
      map<long long,int>mp;
      cin >> n;
      int arr[200009];
      for(int i=0;i<n;i++){
        long long x;
        cin >> x;
        arr[i] = x;
        mn = min(x,mn);
        mx = max(x,mx);
        //cout << mn  << " " << mx << endl;
      }
      sort(arr,arr+n);
      for(int i=0;i<n;i++)
        mp[arr[i]]++;

      int diff =  mx-mn;
      cout << diff  << " ";
      long long int cnt = 0;
      auto itr1 = mp.begin();

      long long int res1,res2;
      while(itr1!=mp.end() ){

        //cout << itr1->first << " " << itr2->first << endl;
        if(itr1->first == mx)
            res1 = itr1->first;
            if(itr1->first == mn)
            res2 = itr1->first;
            itr1++;
      }
      auto itr = mp.begin();
        itr--;
      cnt = max(cnt,itr->first);
      cout << cnt << endl;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){

      long long int n,mn=265555555555555,mx=-1;
      map<long long,int>mp;
      cin >> n;
      int arr[200009];
      for(int i=0;i<n;i++){
        long long x;
        cin >> x;
        arr[i] = x;
        mn = min(x,mn);
        mx = max(x,mx);
        //cout << mn  << " " << mx << endl;
      }
      sort(arr,arr+n);
      for(int i=0;i<n;i++)
        mp[arr[i]]++;

      //cout << mx << " " << mn << endl;
      int diff =  mx-mn;
      cout << diff  << " ";
      long long int cnt = 0;
      auto itr1 = mp.begin();

      long long int res1,res2;
      while(itr1!=mp.end() ){

        //cout << itr1->first << " " << itr2->first << endl;
        if(itr1->first == mx)
            res1 = itr1->second;
        if(itr1->first == mn)
            res2 = itr1->second;

            itr1++;
      }
      if(mp.size() == 1)
            cout << (n*n-1ll)/2ll << endl;
        else
            cout << res1*res2 << endl;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){

      long long int n,mn=100000000000,mx=-1,res1,res2;
      cin >> n;
      int arr[200009];
      for(int i=0;i<n;i++){
        long long x;
        cin >> x;
        arr[i] = x;
        mn = min(x,mn);
        mx = max(x,mx);
        //cout << mn  << " " << mx << endl;
      }
      sort(arr,arr+n);
    cout << mx-mn << " ";

      if(arr[0] == arr[n-1]){
            cout << (n*(n-1ll))/2ll << endl;
            return 0;
      }
      res1=res2=0ll;
        for(int i=0;i<n;i++){
            if(arr[i] == mn)
                res2++;
                if(arr[i] == mx)
                res1++;
        }
        cout << res1 *res2 << endl;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){

      long long int n,mn=INT_MAX,mx=INT_MIN;
      map<long long,int>mp;
      cin >> n;
      int arr[200009];
      for(int i=0;i<n;i++){
        long long x;
        cin >> x;
        arr[i] = x;
        mn = min(x,mn);
        mx = max(x,mx);
        //cout << mn  << " " << mx << endl;
      }
      sort(arr,arr+n);
      for(int i=0;i<n;i++)
        mp[arr[i]]++;

      //cout << mx << " " << mn << endl;
      int diff =  mx-mn;
      cout << diff  << " ";
      long long int cnt = 0;
      auto itr1 = mp.begin();

      long long int res1,res2;
      while(itr1!=mp.end() ){

        //cout << itr1->first << " " << itr2->first << endl;
        if(itr1->first == mx)
            res1 = itr1->second;
        if(itr1->first == mn)
            res2 = itr1->second;

            itr1++;
      }
      if(mp.size() == 1)
            cout << (n*n-1ll)/2ll << endl;
            else
                cout << res1*res2 << endl;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){

      long long int n,mn=265555555555555,mx=-1;
      map<long long,int>mp;
      cin >> n;
      int arr[200009];
      for(int i=0;i<n;i++){
        long long x;
        cin >> x;
        arr[i] = x;
        mn = min(x,mn);
        mx = max(x,mx);
        //cout << mn  << " " << mx << endl;
      }
      sort(arr,arr+n);
      for(int i=0;i<n;i++)
        mp[arr[i]]++;

      //cout << mx << " " << mn << endl;
      int diff =  mx-mn;
      cout << diff  << " ";
      long long int cnt = 0;
      auto itr1 = mp.begin();

      long long int res1,res2;
      while(itr1!=mp.end() ){

        //cout << itr1->first << " " << itr2->first << endl;
        if(itr1->first == mx)
            res1 = itr1->second*1ll;;
        if(itr1->first == mn)
            res2 = itr1->second*1ll;

            itr1++;
      }
      //cout << res1 << " " << res2 << endl;
      if(mp.size() == 1)
            cout << (n*n-1ll)/2ll << endl;
        else
            cout << res1*res2 << endl;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){

      int n,mn=INT_MAX,mx=INT_MIN;
      map<int,int>mp;
      cin >> n;
      int arr[200009];
      for(int i=0;i<n;i++){
        int x;
        cin >> x;
        arr[i] = x;
        mn = min(x,mn);
        mx = max(x,mx);
        //cout << mn  << " " << mx << endl;
      }
      sort(arr,arr+n);
      for(int i=0;i<n;i++)
        mp[arr[i]]++;

      int diff =  mx-mn;
      cout << diff  << " ";
      long long int cnt = 0;
      auto itr1 = mp.begin();
      auto itr =  mp.begin();
      itr++;
      auto itr2 = itr;

      while(itr1!=mp.end() && itr2 != mp.end()){

        //cout << itr1->first << " " << itr2->first << endl;
        if(itr2->first - itr1->first == diff)
            cnt = cnt +( (long long )itr1->second*itr2->second * 1ll) ,itr1++,itr2++;
        else
            itr2++;

      }
      cout << cnt << endl;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){

      long long int n,mn=265555555555555,mx=-1,res1,res2;
      cin >> n;
      int arr[200009];
      for(int i=0;i<n;i++){
        long long x;
        cin >> x;
        arr[i] = x;
        mn = min(x,mn);
        mx = max(x,mx);
        //cout << mn  << " " << mx << endl;
      }
      sort(arr,arr+n);
    cout << mx-mn << " ";

      if(arr[0] == arr[n-1]){
            cout << (n*n-1ll)/2ll << endl;
            return 0;
      }
      res1=res2=0ll;
        for(int i=0;i<n;i++){
            if(arr[i] == mn)
                res2++;
                if(arr[i] == mx)
                res1++;
        }
        cout << res1 *res2 << endl;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){

      long long int n,mn=100000000000,mx=-1,res1,res2;
      cin >> n;
      int arr[200009];
      for(int i=0;i<n;i++){
        long long x;
        cin >> x;
        arr[i] = x;
        mn = min(x,mn);
        mx = max(x,mx);
        //cout << mn  << " " << mx << endl;
      }
      sort(arr,arr+n);
    cout << mx-mn << " ";

      if(arr[0] == arr[n-1]){
            cout << (n*n-1ll)/2ll << endl;
            return 0;
      }
      res1=res2=0ll;
        for(int i=0;i<n;i++){
            if(arr[i] == mn)
                res2++;
                if(arr[i] == mx)
                res1++;
        }
        cout << res1 *res2 << endl;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){

      long long int n,mn=INT_MAX,mx=INT_MIN;
      map<long long,int>mp;
      cin >> n;
      int arr[200009];
      for(int i=0;i<n;i++){
        long long x;
        cin >> x;
        arr[i] = x;
        mn = min(x,mn);
        mx = max(x,mx);
        //cout << mn  << " " << mx << endl;
      }
      sort(arr,arr+n);
      for(int i=0;i<n;i++)
        mp[arr[i]]++;

      int diff =  mx-mn;
      cout << diff  << " ";
      long long int cnt = 0;
      auto itr1 = mp.begin();
      auto itr =  mp.begin();
      itr++;
      auto itr2 = itr;

      while(itr1!=mp.end() && itr2 != mp.end()){

        //cout << itr1->first << " " << itr2->first << endl;
        if(itr2->first - itr1->first == diff)
            cnt = cnt +( (long long )itr1->second*itr2->second ) ,itr1++,itr2++;
        else
            itr2++;

      }
        itr--;
      cnt = max(cnt,itr->first);
      cout << cnt << endl;

return 0;
}


#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>

int main()
{
	using namespace std;
	unsigned long long  n, i;
	cin >> n;
	vector <unsigned long long> b(n);
	unsigned long long max = 0, min = 10e9 + 1;
	for (i = 0; i < n; i++)
	{
		cin >> b[i];
		if (max < b[i])
			max = b[i];
		if (min > b[i])
			min = b[i];
	}
	cout << max - min << ' ' << 1ll * count(b.begin(), b.end(), max) * count(b.begin(), b.end(), min);
	return 0;
}


#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>

unsigned long long fac(unsigned long long a)
{
	unsigned long long ans = 1;
	for (unsigned long long i = 2; i <= a; i++)
		ans *= i;
	return ans;
}
int main()
{
	using namespace std;
	unsigned long long  n, i;
	cin >> n;
	vector <unsigned long long> b(n);
	unsigned long long max = 0, min = 10e9 + 1;
	for (i = 0; i < n; i++)
	{
		cin >> b[i];
		if (max < b[i])
			max = b[i];
		if (min > b[i])
			min = b[i];
	}
	unsigned long long nn = 1ull * count(b.begin(), b.end(), max) * count(b.begin(), b.end(), min);
	if (max != min)
		cout << max - min << ' ' << 1ull * count(b.begin(), b.end(), max) * count(b.begin(), b.end(), min);
	else
		cout << max - min << ' ' << 1ull * fac(nn) / 2 / fac(nn - 2);
	return 0;
}


#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>

int main()
{
	using namespace std;
	unsigned long long  n, i;
	cin >> n;
	vector <unsigned> b(n);
	unsigned long long max = 0, min = 10e9 + 1;
	for (i = 0; i < n; i++)
	{
		cin >> b[i];
		if (max < b[i])
			max = b[i];
		if (min > b[i])
			min = b[i];
	}
	unsigned long long nn = 1ull * count(b.begin(), b.end(), max);
	if (max != min)
		cout << max - min << ' ' << 1ull * count(b.begin(), b.end(), max) * count(b.begin(), b.end(), min);
	else
		cout << max - min << ' ' << nn * (nn - 1) * 2;
	return 0;
}


#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>

int main()
{
	using namespace std;
	int n, i;
	cin >> n;
	vector <int> b(n);
	unsigned max = 0, min = 10e9 + 1;
	for (i = 0; i < n; i++)
	{
		cin >> b[i];
		if (max < b[i])
			max = b[i];
		if (min > b[i])
			min = b[i];
	}
	cout << max - min << ' ' << count(b.begin(), b.end(), max) * count(b.begin(), b.end(), min);
	return 0;
}


#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>

int main()
{
	using namespace std;
	unsigned long long  n, i;
	cin >> n;
	vector <unsigned long long> b(n);
	unsigned long long max = 0, min = 10e9 + 1;
	for (i = 0; i < n; i++)
	{
		cin >> b[i];
		if (max < b[i])
			max = b[i];
		if (min > b[i])
			min = b[i];
	}
	cout << max - min << ' ' << count(b.begin(), b.end(), max) * count(b.begin(), b.end(), min);
	return 0;
}


#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>

int main()
{
	using namespace std;
	unsigned long long  n, i;
	cin >> n;
	vector <int> b(n);
	unsigned long long max = 0, min = 10e9 + 1;
	for (i = 0; i < n; i++)
	{
		cin >> b[i];
		if (max < b[i])
			max = b[i];
		if (min > b[i])
			min = b[i];
	}
	cout << max - min << ' ' << count(b.begin(), b.end(), max) * count(b.begin(), b.end(), min);
	return 0;
}


#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>

int main()
{
	using namespace std;
	unsigned long long  n, i;
	cin >> n;
	vector <unsigned long long> b(n);
	unsigned long long max = 0, min = 10e9 + 1;
	for (i = 0; i < n; i++)
	{
		cin >> b[i];
		if (max < b[i])
			max = b[i];
		if (min > b[i])
			min = b[i];
	}
	if (max != min)
		cout << max - min << ' ' << 1ll * count(b.begin(), b.end(), max) * count(b.begin(), b.end(), min);
	else
		cout << max - min << ' ' << 1ll * count(b.begin(), b.end(), max) * count(b.begin(), b.end(), min) / 4;
	return 0;
}


#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>

unsigned long long fac(unsigned long long a)
{
	unsigned long long ans = 1;
	for (unsigned long long i = 2; i <= a; i++)
		ans *= i;
	return ans;
}
int main()
{
	using namespace std;
	unsigned long long  n, i;
	cin >> n;
	vector <unsigned long long> b(n);
	unsigned long long max = 0, min = 10e9 + 1;
	for (i = 0; i < n; i++)
	{
		cin >> b[i];
		if (max < b[i])
			max = b[i];
		if (min > b[i])
			min = b[i];
	}
	if (max != min)
		cout << max - min << ' ' << 1ull * count(b.begin(), b.end(), max) * count(b.begin(), b.end(), min);
	else
		cout << max - min << ' ' << 1ull * count(b.begin(), b.end(), max) * count(b.begin(), b.end(), min) / 4;
	return 0;
}


#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>

unsigned int Georgiy(const unsigned long long int n, const unsigned long long int k) // ������� ���������� ���������
{
	using namespace std;

	vector <vector<unsigned short>> B(n + 1, vector<unsigned short>(n + 1));      // ������� ������ B �� n+1 ������
	for (int i = 0; i <= n; ++i) // ��������� i-� ������ �������
	{
		B[i][0] = 1;         // �� ������ ������ ����� �������
		B[i][i] = 1;
		for (int j = 1; j < i; ++j)
		{   // ��������� ���������� �������� i-� ������
			B[i][j] = B[i - 1][j - 1] + B[i - 1][j];
		}
	}
	return B[n][k];
}

int main()
{
	using namespace std;
	unsigned long long  n, i;
	cin >> n;
	vector <unsigned> b(n);
	unsigned long long max = 0, min = 10e9 + 1;
	for (i = 0; i < n; i++)
	{
		cin >> b[i];
		if (max < b[i])
			max = b[i];
		if (min > b[i])
			min = b[i];
	}
	unsigned long long nn = 1ull * count(b.begin(), b.end(), max);
	if (max != min)
		cout << max - min << ' ' << 1ull * count(b.begin(), b.end(), max) * count(b.begin(), b.end(), min);
	else
		cout << max - min << ' ' << Georgiy(nn, 2);
	return 0;
}


#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>

unsigned int Georgiy(const unsigned long long int n, const unsigned long long int k) // ������� ���������� ���������
{
	using namespace std;

	vector <vector<unsigned int>> B(n + 1, vector<unsigned int>(n + 1));      // ������� ������ B �� n+1 ������
	for (int i = 0; i <= n; ++i) // ��������� i-� ������ �������
	{
		B[i][0] = 1;         // �� ������ ������ ����� �������
		B[i][i] = 1;
		for (int j = 1; j < i; ++j)
		{   // ��������� ���������� �������� i-� ������
			B[i][j] = B[i - 1][j - 1] + B[i - 1][j];
		}
	}
	return B[n][k];
}

int main()
{
	using namespace std;
	unsigned long long  n, i;
	cin >> n;
	vector <unsigned long long> b(n);
	unsigned long long max = 0, min = 10e9 + 1;
	for (i = 0; i < n; i++)
	{
		cin >> b[i];
		if (max < b[i])
			max = b[i];
		if (min > b[i])
			min = b[i];
	}
	unsigned long long nn = 1ull * count(b.begin(), b.end(), max);
	if (max != min)
		cout << max - min << ' ' << 1ull * count(b.begin(), b.end(), max) * count(b.begin(), b.end(), min);
	else
		cout << max - min << ' ' << Georgiy(nn, 2);
	return 0;
}


#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>

int main()
{
	using namespace std;
	unsigned long long  n, i;
	cin >> n;
	vector <unsigned> b(n);
	unsigned long long max = 0, min = 10e9 + 1;
	for (i = 0; i < n; i++)
	{
		cin >> b[i];
		if (max < b[i])
			max = b[i];
		if (min > b[i])
			min = b[i];
	}
	unsigned long long nn = 1ull * count(b.begin(), b.end(), max);
	if (max != min)
		cout << max - min << ' ' << 1ull * count(b.begin(), b.end(), max) * count(b.begin(), b.end(), min);
	else
		cout << max - min << ' ' << nn * (nn - 1) / 2;
	return 0;
}


#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>

unsigned long long fac(unsigned long long a)
{
	unsigned long long ans = 1;
	for (unsigned long long i = 2; i <= a; i++)
		ans *= i;
	return ans;
}
int main()
{
	using namespace std;
	unsigned long long  n, i;
	cin >> n;
	vector <unsigned long long> b(n);
	unsigned long long max = 0, min = 10e9 + 1;
	for (i = 0; i < n; i++)
	{
		cin >> b[i];
		if (max < b[i])
			max = b[i];
		if (min > b[i])
			min = b[i];
	}
	unsigned long long nn = 1ull * count(b.begin(), b.end(), max);
	if (max != min)
		cout << max - min << ' ' << 1ull * count(b.begin(), b.end(), max) * count(b.begin(), b.end(), min);
	else
		cout << max - min << ' ' << 1ull * fac(nn) / 2 / fac(nn - 2);
	return 0;
}


#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>

unsigned int Georgiy(const unsigned long long int n, const unsigned long long int k) // ������� ���������� ���������
{
	using namespace std;

	vector <vector<unsigned int>> B(n + 1, vector<unsigned int>(n + 1));      // ������� ������ B �� n+1 ������
	for (int i = 0; i <= n; ++i) // ��������� i-� ������ �������
	{
		B[i][0] = 1;         // �� ������ ������ ����� �������
		B[i][i] = 1;
		for (int j = 1; j < i; ++j)
		{   // ��������� ���������� �������� i-� ������
			B[i][j] = B[i - 1][j - 1] + B[i - 1][j];
		}
	}
	return B[n][k];
}

int main()
{
	using namespace std;
	unsigned long long  n, i;
	cin >> n;
	vector <unsigned> b(n);
	unsigned long long max = 0, min = 10e9 + 1;
	for (i = 0; i < n; i++)
	{
		cin >> b[i];
		if (max < b[i])
			max = b[i];
		if (min > b[i])
			min = b[i];
	}
	unsigned long long nn = 1ull * count(b.begin(), b.end(), max);
	if (max != min)
		cout << max - min << ' ' << 1ull * count(b.begin(), b.end(), max) * count(b.begin(), b.end(), min);
	else
		cout << max - min << ' ' << Georgiy(nn, 2);
	return 0;
}


#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>

unsigned long long fac(unsigned long long a)
{
	unsigned long long ans = 1;
	for (unsigned long long i = 2; i <= a; i++)
		ans *= i;
	return ans;
}
int main()
{
	using namespace std;
	unsigned long long  n, i;
	cin >> n;
	vector <unsigned long long> b(n);
	unsigned long long max = 0, min = 10e9 + 1;
	for (i = 0; i < n; i++)
	{
		cin >> b[i];
		if (max < b[i])
			max = b[i];
		if (min > b[i])
			min = b[i];
	}
	if (max != min)
		cout << max - min << ' ' << 1ull * count(b.begin(), b.end(), max) * count(b.begin(), b.end(), min);
	else
		cout << max - min << ' ' << 1ull * count(b.begin(), b.end(), max) / 4 * count(b.begin(), b.end(), min);
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define all(s) s.begin(),s.end()
#define sz(s) (int)s.size()
#define loop(i,n) for(ll i = 0;i < (n);i++)
#define pp push_back
#define pb pop_back
#define ull unsigned long long int
#define ll long long
#define pi 3.141592654
#define cons1 1e9+9
#define cons2 1e5+9
#define pus system("pause")
using namespace std;
int main() {

	int n, x;
	ll ans = 0;
	cin >> n;
	map<ll, ll, greater<ll>>m;
	for (size_t i = 0; i < n; i++)
	{
		cin >> x;
		m[x]++;
	}
	if (sz(m) == 1) {
		cout << "0"<<n*(n-1)/2;
		return 0;
	}
	x = m.begin()->first - m.rbegin()->first;
	cout << x << " ";
	map<ll, ll>::iterator it = m.begin();
	while (it != m.end() && it->first >= x + 1)
	{
		if (m.count(it->first - x)||) {
			ans += (m[it->first - x] * m[it->first]);
		}
		it++;
	}
	cout << ans << endl;

}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define all(s) s.begin(),s.end()
#define sz(s) (int)s.size()
#define loop(i,n) for(ll i = 0;i < (n);i++)
#define pp push_back
#define pb pop_back
#define ull unsigned long long int
#define ll long long
#define pi 3.141592654
#define cons1 1e9+9
#define cons2 1e5+9
#define pus system("pause")
using namespace std;
int main() {

	int n, x;
	ll ans = 0;
	cin >> n;
	map<int, int,greater<int>>m;
	for (size_t i = 0; i < n; i++)
	{
		cin >> x;
		m[x]++;
	}
	x = m.begin()->first - m.rbegin()->first;
	cout << x <<" ";
	map<int, int>::iterator it = m.begin();
	while (it != m.end()&&it->first >= x+1)
	{
		if (m.count(it->first - x)) {
			ans += (ll(m[it->first - x]) * ll(m[it->first]));
		}
		it++;
	}
	cout << ans << endl;

}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define all(s) s.begin(),s.end()
#define sz(s) (int)s.size()
#define loop(i,n) for(ll i = 0;i < (n);i++)
#define pp push_back
#define pb pop_back
#define ull unsigned long long int
#define ll long long
#define pi 3.141592654
#define cons1 1e9+9
#define cons2 1e5+9
#define pus system("pause")
using namespace std;
int main() {

	int  x, n,y;
	cin >> n;
	map<int,int>m;
	for (size_t i = 0; i < n; i++)
	{
		cin >> x;
		m[x]++;
	}
	x = m.rbegin()->first;
	y = m.begin()->first;
	if (sz(m) == 1)
		cout << "0 "<< 1LL*n*(n-1)/2;
	else
		cout << x-y << " " << 1LL * m[x]*m[y];

}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define all(s) s.begin(),s.end()
#define sz(s) (int)s.size()
#define loop(i,n) for(ll i = 0;i < (n);i++)
#define pp push_back
#define pb pop_back
#define ull unsigned long long int
#define ll long long
#define pi 3.141592654
#define cons1 1e9+9
#define cons2 1e5+9
#define pus system("pause")
using namespace std;
int main() {

	int  x, n;
	cin >> n;
	multiset<int>s;
	for (size_t i = 0; i < n; i++)
	{
		cin >> x;
		s.insert(x);
	}
	if (sz(s) == 1)
		cout << "0 "<< 1LL*n*(n-1)/2;
	else
		cout << *s.rbegin() - *s.begin() << " " << 1LL * s.count(*s.begin())*s.count(*s.rbegin());

}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define all(s) s.begin(),s.end()
#define sz(s) (int)s.size()
#define loop(i,n) for(ll i = 0;i < (n);i++)
#define pp push_back
#define pb pop_back
#define ull unsigned long long int
#define ll long long
#define pi 3.141592654
#define cons1 1e9+9
#define cons2 1e5+9
#define pus system("pause")
using namespace std;
int main() {

	int n, x;
	ll ans = 0;
	cin >> n;
	map<ll, ll, greater<ll>>m;
	for (size_t i = 0; i < n; i++)
	{
		cin >> x;
		m[x]++;
	}
	if (sz(m) == 1) {
		cout << "0"<<n*(n-1)/2;
		return 0;
	}
	x = m.begin()->first - m.rbegin()->first;
	cout << x << " ";
	map<ll, ll>::iterator it = m.begin();
	while (it != m.end() && it->first >= x + 1)
	{
		if (m.count(it->first - x)) {
			ans += (m[it->first - x] * m[it->first]);
		}
		it++;
	}
	cout << ans << endl;

}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define all(s) s.begin(),s.end()
#define sz(s) (int)s.size()
#define loop(i,n) for(ll i = 0;i < (n);i++)
#define pp push_back
#define pb pop_back
#define ull unsigned long long int
#define ll long long
#define pi 3.141592654
#define cons1 1e9+9
#define cons2 1e5+9
#define pus system("pause")
using namespace std;
int main() {

	int n, x, ans = 0;
	cin >> n;
	map<int, int,greater<int>>m;
	for (size_t i = 0; i < n; i++)
	{
		cin >> x;
		m[x]++;
	}
	x = m.begin()->first - m.rbegin()->first;
	cout << x <<" ";
	map<int, int>::iterator it = m.begin();
	while (it->first >= x+1&&it != m.end())
	{
		if (m.count(it->first - x)) {
			ans += (m[it->first - x] * m[it->first]);
		}
		it++;
	}
	cout << ans << endl;

}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define all(s) s.begin(),s.end()
#define sz(s) (int)s.size()
#define loop(i,n) for(ll i = 0;i < (n);i++)
#define pp push_back
#define pb pop_back
#define ull unsigned long long int
#define ll long long
#define pi 3.141592654
#define cons1 1e9+9
#define cons2 1e5+9
#define pus system("pause")
using namespace std;
int main() {

	int  x, n;
	cin >> n;
	multiset<int>s;
	for (size_t i = 0; i < n; i++)
	{
		cin >> x;
		s.insert(x);
	}
	if (sz(s) == 1) {
		cout << "0 "<< 1LL*n*(n-1)/2;
		return 0;
	}
	x = *s.begin()- *s.rbegin();
	cout << 1LL*x << " "<<1LL*s.count(*s.begin())*s.count(*s.begin());

}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define all(s) s.begin(),s.end()
#define sz(s) (int)s.size()
#define loop(i,n) for(ll i = 0;i < (n);i++)
#define pp push_back
#define pb pop_back
#define ull unsigned long long int
#define ll long long
#define pi 3.141592654
#define cons1 1e9+9
#define cons2 1e5+9
#define pus system("pause")
using namespace std;
int main() {

	int  x;
	ll ans = 0,n;
	cin >> n;
	map<ll, ll, greater<ll>>m;
	for (size_t i = 0; i < n; i++)
	{
		cin >> x;
		m[x]++;
	}
	if (sz(m) == 1) {
		cout << "0 "<<n*(n-1)/2;
		return 0;
	}
	x = m.begin()->first - m.rbegin()->first;
	cout << x << " ";
	ans += (m[m.begin()->first] * m[m.rbegin()->first]);
	cout << ans << endl;

}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define all(s) s.begin(),s.end()
#define sz(s) (int)s.size()
#define loop(i,n) for(ll i = 0;i < (n);i++)
#define pp push_back
#define pb pop_back
#define ull unsigned long long int
#define ll long long
#define pi 3.141592654
#define cons1 1e9+9
#define cons2 1e5+9
#define pus system("pause")
using namespace std;
int main() {
	int n, x;
	vector<ll>v;
	multiset<ll>s;
	cin >> n;
	for (size_t i = 0; i < n; i++)
	{
		cin >> x;
		v.pp(x);
		s.insert(x);

	}
	cout << *max_element(all(v)) - *min_element(all(v))<<" " ;
	cout << s.count(*max_element(all(v)))*s.count(*min_element(all(v))) << endl;
}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define all(s) s.begin(),s.end()
#define sz(s) (int)s.size()
#define loop(i,n) for(ll i = 0;i < (n);i++)
#define pp push_back
#define pb pop_back
#define ull unsigned long long int
#define ll long long
#define pi 3.141592654
#define cons1 1e9+9
#define cons2 1e5+9
#define pus system("pause")
using namespace std;
int main() {

	int n, x;
	ll ans = 0;
	cin >> n;
	map<ll, ll, greater<ll>>m;
	for (size_t i = 0; i < n; i++)
	{
		cin >> x;
		m[x]++;
	}
	x = m.begin()->first - m.rbegin()->first;
	cout << x << " ";
	map<ll, ll>::iterator it = m.begin();
	while (it != m.end() && it->first >= x + 1)
	{
		if (m.count(it->first - x)) {
			ans += (m[it->first - x] * m[it->first]);
		}
		it++;
	}
	cout << ans << endl;

}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define all(s) s.begin(),s.end()
#define sz(s) (int)s.size()
#define loop(i,n) for(ll i = 0;i < (n);i++)
#define pp push_back
#define pb pop_back
#define ull unsigned long long int
#define ll long long
#define pi 3.141592654
#define cons1 1e9+9
#define cons2 1e5+9
#define pus system("pause")
using namespace std;
int main() {

	int n, x;
	ll ans = 0;
	cin >> n;
	map<ll, ll, greater<ll>>m;
	for (size_t i = 0; i < n; i++)
	{
		cin >> x;
		m[x]++;
	}
	if (sz(m) == 1) {
		cout << "0 1";
		return 0;
	}
	x = m.begin()->first - m.rbegin()->first;
	cout << x << " ";
	map<ll, ll>::iterator it = m.begin();
	while (it != m.end() && it->first >= x + 1)
	{
		if (m.count(it->first - x)) {
			ans += (m[it->first - x] * m[it->first]);
		}
		it++;
	}
	cout << ans << endl;

}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define all(s) s.begin(),s.end()
#define sz(s) (int)s.size()
#define loop(i,n) for(ll i = 0;i < (n);i++)
#define pp push_back
#define pb pop_back
#define ull unsigned long long int
#define ll long long
#define pi 3.141592654
#define cons1 1e9+9
#define cons2 1e5+9
#define pus system("pause")
using namespace std;
int main() {

	int n, x;
	ll ans = 0;
	cin >> n;
	map<int, int,greater<int>>m;
	for (size_t i = 0; i < n; i++)
	{
		cin >> x;
		m[x]++;
	}
	x = m.begin()->first - m.rbegin()->first;
	cout << x <<" ";
	map<int, int>::iterator it = m.begin();
	while (it != m.end()&&it->first >= x+1)
	{
		if (m.count(it->first - x)) {
			ans += (m[it->first - x] * m[it->first]);
		}
		it++;
	}
	cout << ans << endl;
}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define all(s) s.begin(),s.end()
#define sz(s) (int)s.size()
#define loop(i,n) for(ll i = 0;i < (n);i++)
#define pp push_back
#define pb pop_back
#define ull unsigned long long int
#define ll long long
#define pi 3.141592654
#define cons1 1e9+9
#define cons2 1e5+9
#define pus system("pause")
using namespace std;
int main() {

	int  x, n;
	cin >> n;
	multiset<int>s;
	for (size_t i = 0; i < n; i++)
	{
		cin >> x;
		s.insert(x);
	}
	if (sz(s) == 1) {
		cout << "0 "<< 1LL*n*(n-1)/2;
		return 0;
	}
	x = *s.rbegin()- *s.begin();
	cout << 1LL*x << " "<<1LL*s.count(*s.begin())*s.count(*s.begin());

}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define all(s) s.begin(),s.end()
#define sz(s) (int)s.size()
#define loop(i,n) for(ll i = 0;i < (n);i++)
#define pp push_back
#define pb pop_back
#define ull unsigned long long int
#define ll long long
#define pi 3.141592654
#define cons1 1e9+9
#define cons2 1e5+9
#define pus system("pause")
using namespace std;
int main() {
	int n, x, y, ans = 0;
	vector<int>v;
	multiset<int>s;
	set<int>s1;
	cin >> n;
	for (size_t i = 0; i < n; i++)
	{
		cin >> x;
		v.pp(x);
		s.insert(x);
		s1.insert(x);

	}
	y = *max_element(all(v)) - *min_element(all(v));
	cout << y <<" " ;
	for (auto s1:s1)
	{
		ans += s.count(s1)*s.count(s1-y);
	}
	cout << ans << endl;
}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define all(s) s.begin(),s.end()
#define sz(s) (int)s.size()
#define loop(i,n) for(ll i = 0;i < (n);i++)
#define pp push_back
#define pb pop_back
#define ull unsigned long long int
#define ll long long
#define pi 3.141592654
#define cons1 1e9+9
#define cons2 1e5+9
#define pus system("pause")
using namespace std;
int main() {

	int n, x;
	cin >> n;
	multiset<ll>s;
	for (size_t i = 0; i < n; i++)
	{
		cin >> x;
		s.insert(x);
	}
	if (sz(s)==1) {
		cout << "0 1";
		return 0;
	}
	x = *s.rbegin() - *s.begin();
	cout << x << " ";
	ll ans = s.count(*s.rbegin()) * s.count(*s.rbegin());
	cout << ans << endl;

}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define all(s) s.begin(),s.end()
#define sz(s) (int)s.size()
#define loop(i,n) for(ll i = 0;i < (n);i++)
#define pp push_back
#define pb pop_back
#define ull unsigned long long int
#define ll long long
#define pi 3.141592654
#define cons1 1e9+9
#define cons2 1e5+9
#define pus system("pause")
using namespace std;
int main() {

	int n, x;
	ll ans = 0;
	cin >> n;
	map<ll, ll, greater<ll>>m;
	for (size_t i = 0; i < n; i++)
	{
		cin >> x;
		m[x]++;
	}
	if (sz(m) == 1) {
		cout << "0 "<<n*(n-1)/2;
		return 0;
	}
	x = m.begin()->first - m.rbegin()->first;
	cout << x << " ";
	map<ll, ll>::iterator it = m.begin();
	while (it != m.end() && it->first >= x + 1)
	{
		if (m.count(it->first - x)) {
			ans += (m[it->first - x] * m[it->first]);
		}
		it++;
	}
	cout << ans << endl;

}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define all(s) s.begin(),s.end()
#define sz(s) (int)s.size()
#define loop(i,n) for(ll i = 0;i < (n);i++)
#define pp push_back
#define pb pop_back
#define ull unsigned long long int
#define ll long long
#define pi 3.141592654
#define cons1 1e9+9
#define cons2 1e5+9
#define pus system("pause")
using namespace std;
int main() {

	int n, x;
	cin >> n;
	multiset<ll>s;
	for (size_t i = 0; i < n; i++)
	{
		cin >> x;
		s.insert(x);
	}
	if (sz(s)==1) {
		cout << "0 1";
		return 0;
	}
	x = *s.rbegin() - *s.begin();
	cout << x << " ";
	cout << s.count(*s.rbegin()) * s.count(*s.rbegin()) << endl;

}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define all(s) s.begin(),s.end()
#define sz(s) (int)s.size()
#define loop(i,n) for(ll i = 0;i < (n);i++)
#define pp push_back
#define pb pop_back
#define ull unsigned long long int
#define ll long long
#define pi 3.141592654
#define cons1 1e9+9
#define cons2 1e5+9
#define pus system("pause")
using namespace std;
int main() {
	ll n, x, y, ans = 0;
	vector<ll>v;
	multiset<ll>s;
	set<ll>s1;
	cin >> n;
	for (size_t i = 0; i < n; i++)
	{
		cin >> x;
		v.pp(x);
		s.insert(x);
		s1.insert(x);

	}
	y = *max_element(all(v)) - *min_element(all(v));
	cout << y <<" " ;
	for (auto s1:s1)
	{
		ans += s.count(s1)*s.count(s1-y);
	}
	cout << ans << endl;

}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define all(s) s.begin(),s.end()
#define sz(s) (int)s.size()
#define loop(i,n) for(ll i = 0;i < (n);i++)
#define pp push_back
#define pb pop_back
#define ull unsigned long long int
#define ll long long
#define pi 3.141592654
#define cons1 1e9+9
#define cons2 1e5+9
#define pus system("pause")
using namespace std;
int main() {
	int n, x;
	vector<int>v;
	multiset<int>s;
	cin >> n;
	for (size_t i = 0; i < n; i++)
	{
		cin >> x;
		v.pp(x);
		s.insert(x);

	}
	cout << *max_element(all(v)) - *min_element(all(v))<<" " ;
	cout << s.count(*max_element(all(v)))*s.count(*min_element(all(v))) << endl;
}


#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define all(s) s.begin(),s.end()
#define sz(s) (int)s.size()
#define loop(i,n) for(ll i = 0;i < (n);i++)
#define pp push_back
#define pb pop_back
#define ull unsigned long long int
#define ll long long
#define pi 3.141592654
#define cons1 1e9+9
#define cons2 1e5+9
#define pus system("pause")
using namespace std;
int main() {

	int  x;
	ll ans = 0,n;
	cin >> n;
	map<ll, ll, greater<ll>>m;
	for (size_t i = 0; i < n; i++)
	{
		cin >> x;
		m[x]++;
	}
	if (sz(m) == 1) {
		cout << "0 "<<n*(n-1)/2;
		return 0;
	}
	x = m.begin()->first - m.rbegin()->first;
	cout << x << " ";
	map<ll, ll>::iterator it = m.begin();
	while (it != m.end() && it->first >= x + 1)
	{
		if (m.count(it->first - x)) {
			ans += (m[it->first - x] * m[it->first]);
		}
		it++;
	}
	cout << ans << endl;

}


#include <bits/stdc++.h>

using namespace std;

int const N=2*1e5+1;
long long n,a[101010];
long long mn=1010101,mx;
long long ans,cnt;

int main () {
    cin>>n;
    for (int i=1;i<=n;i++){
        cin>>a[i];
        mx=max(mx,a[i]);
        mn=min(mn,a[i]);
    }
    cout<<mx-mn<<" ";
    for (int i=1;i<=n;i++){
        if (mx==a[i]){
            ans++;
        }
        if (mn==a[i]){
            cnt++;
        }
    }
    cout<<ans*cnt;
return 0;
}


#include <bits/stdc++.h>

using namespace std;

int const N=2*1e5+1;
long long n,a[N];
long long mn=N,mx;
map <long long,long long> cnt;

int main () {
    cin>>n;
    for (int i=1;i<=n;i++){
        cin>>a[i];
        mx=max(mx,a[i]);
        mn=min(mn,a[i]);
        cnt[a[i]]++;
    }
    cout<<mx-mn<<" ";
    if (mx==mn){
        cout<<n*(n-1)/2;
        return 0;
    }
    else {
        cout<<cnt[mn]*cnt[mx];
    }
return 0;
}


#include <bits/stdc++.h>

using namespace std;

long long const N=1e9+1;
long long n,x;
long long mn=N,mx;
map <long long,long long> cnt;

int main () {
    cin>>n;
    for (int i=1;i<=n;i++){
        cin>>x;
        mx=max(mx,x);
        mn=min(mn,x);
        cnt[x]++;
    }
    cout<<mx-mn<<" ";
    if (mx==mn){
        cout<<n*(n-1)/2;
        return 0;
    }
    else {
        cout<<cnt[mn]*cnt[mx];
    }
return 0;
}


#include <bits/stdc++.h>

using namespace std;

int const N=2*1e5+1;
long long n,a[101010];
long long mn=N,mx;
map <long long,long long> cnt;

int main () {
    cin>>n;
    for (int i=1;i<=n;i++){
        cin>>a[i];
        mx=max(mx,a[i]);
        mn=min(mn,a[i]);
        cnt[a[i]]++;
    }
    cout<<mx-mn<<" "<<cnt[mx]*cnt[mn];
return 0;a
}


#include <bits/stdc++.h>

using namespace std;

int const N=2*1e5+1;
long long n,a[N];
long long mn=N,mx;
map <long long,long long> cnt;

int main () {
    cin>>n;
    for (int i=1;i<=n;i++){
        cin>>a[i];
        mx=max(mx,a[i]);
        mn=min(mn,a[i]);
        cnt[a[i]]++;
    }
    cout<<mx-mn<<" ";
    if (mx==mn){
        cout<<n*(n-1)/2;;
    }
    else {
        cout<<cnt[mn]*cnt[mx];
    }
return 0;
}


#include <bits/stdc++.h>

using namespace std;

int const N=2*1e5+1;
long long n,a[101010];
long long mn=N,mx;
long long ans,cnt;

int main () {
    cin>>n;
    for (int i=1;i<=n;i++){
        cin>>a[i];
        if (mx<a[i]){
            ans=0;
            mx=a[i];
        }
        if (mn>a[i]){
            mn=a[i];
            cnt=0;
        }
        if (mn==a[i]){
            cnt++;
        }
        if (mx==a[i]){
            ans++;
        }
    }
    cout<<mx-mn<<" "<<ans*cnt;
return 0;
}


#include <bits/stdc++.h>

using namespace std;

int const N=2*1e5+1;
int n,a[101010];
int mn=1010101,mx;
int ans,cnt;

int main () {
    cin>>n;
    for (int i=1;i<=n;i++){
        cin>>a[i];
        mx=max(mx,a[i]);
        mn=min(mn,a[i]);
    }
    cout<<mx-mn<<" ";
    for (int i=1;i<=n;i++){
        if (mx==a[i]){
            ans++;
        }
        if (mn==a[i]){
            cnt++;
        }
    }
    cout<<ans*cnt;
return 0;
}


#include <bits/stdc++.h>

using namespace std;

int const N=2*1e5+1;
long long n,a[N];
long long mn=N,mx;
map <long long,long long> cnt;

int main () {
    cin>>n;
    for (int i=1;i<=n;i++){
        cin>>a[i];
        mx=max(mx,a[i]);
        mn=min(mn,a[i]);
        cnt[a[i]]++;
    }
    cout<<mx-mn<<" "<<cnt[mx]*cnt[mn];
return 0;
}


#include <bits/stdc++.h>

using namespace std;

int const N=2*1e5+1;
long long n,a[101010];
long long mn=N,mx;
map <long long,long long> cnt;

int main () {
    cin>>n;
    for (int i=1;i<=n;i++){
        cin>>a[i];
        mx=max(mx,a[i]);
        mn=min(mn,a[i]);
        cnt[a[i]]++;
    }
    cout<<mx-mn<<" "<<cnt[mx]*cnt[mn];
return 0;
}


#include <bits/stdc++.h>

using namespace std;

int const N=2*1e5+1;
long long n,a[101010];
long long mn=1010101,mx;
long long  asd[101010];

int main () {
    cin>>n;
    for (int i=1;i<=n;i++){
        cin>>a[i];
            asd[a[i]]++;
        mx=max(mx,a[i]);
        mn=min(mn,a[i]);
    }
    cout<<mx-mn<<" "<<asd[mx]*asd[mn];
return 0;
}


#include <bits/stdc++.h>

using namespace std;

long long const N=1e9+1;
long long n,x;
long long mn=N,mx;
map <long long,long long> cnt;

int main () {
    cin>>n;
    for (int i=1;i<=n;i++){
        cin>>x;
        mx=max(mx,a[i]);
        mn=min(mn,a[i]);
        cnt[a[i]]++;
    }
    cout<<mx-mn<<" ";
    if (mx==mn){
        cout<<n*(n-1)/2;
        return 0;
    }
    else {
        cout<<cnt[mn]*cnt[mx];
    }
return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define rush ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long int
#define FOR(a,x,n) for(ll a=x;a<n;a++)
#define ROF(a,x,n) for(ll a=x;a>=n;a--)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define MOD 1000000007

void solve() {
    ll n;
    cin >> n;

    vector<ll> v;
    set<ll> s;

    FOR(i,0,n) {
        ll x;
        cin >> x;
        v.pb(x);
        s.insert(x);
    }

    sort(v.begin(), v.end());

    ll ans1 = v[v.size()-1] - v[0];
    ll ans = 0;

    ll z = s.size();

    if(ans1 == 0) ans = (n*(n-1))/2;
    else {
         for(ll x: s) {
             auto it1 =lb(v.begin(),v.end(),x);
             auto it2 =ub(v.begin(),v.end(),x);

             auto it =s.find(abs(x+ans1));
             if(it!=s.end()) {
                auto it3 =lb(v.begin(),v.end(),abs(x+ans1));
                auto it4 =ub(v.begin(),v.end(),abs(x+ans1));
                ll a = abs((it1)-(it2));
                ll b = abs((it3)-(it4));
                ans += a*b;
                z -= 2;
             }

             else z -= 1;

             s.erase(abs(x+ans1));

             if(z <= 0) break;
         }
     }

     cout << ans1 <<" " << ans << "\n";
}

int main() {
      rush
      solve();
}


#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define int long long
//#define ll long long
#define pb push_back
#define x first
#define ld long double
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) a.begin(),a.end()

using namespace std;

using namespace __gnu_cxx;
using namespace __gnu_pbds;
template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
inline void solve () {
    int n, a, b;
    cin >> n >> a >> b;
    string s;
    cin >> s;
    vector <vector <int> > dp(n, vector <int> (2, 1e16));
    dp[0][0] = b + b + a;
    for (int i = 1; i < n; i++) {
        if (s[i] == '0') {
            dp[i][0] = min(dp[i - 1][0] + a + b, dp[i - 1][1] + 2 * a + b);
            dp[i][1] = min(dp[i - 1][0] + a + b + a + 2 * b, dp[i - 1][1] + 2 * b + a);
        }
        else {
            dp[i][1] = min(dp[i - 1][0] + a + b + a + 2 * b, dp[i - 1][1] + 2 * b + a);
        }
    }
//    for (auto &i : dp) {
//        cout << i[0] << ' ' << i[1] << '\n';
//    }
    cout << dp[n - 1][0] << '\n';
}
main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
}


#include<bits/stdc++.h>
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define popcnt(x) __builtin_popcount(x)
#define inf 0x3f3f3f3f
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rand() (rand() << 15 | rand())
using namespace std;
typedef long long  ll;
const int N = 2e5 + 4;
ll memo[N][2];
string s;
int n , a , b;
ll solve(int indx , int cur){
    if(indx == n)
        return (cur ? LLONG_MAX / 2 : 0);
    if(s[indx] == '1' && !cur)
        return LLONG_MAX / 2;
    ll &ret = memo[indx][cur];
    if(~ret)
        return ret;
    ret = LLONG_MAX / 2;
    if(s[indx] == '0'){
        if(cur)
            ret = min(ret , min(a + b + solve(indx + 1 , 1) , 2 * a + solve(indx + 1 , 0)));
        else ret = min(ret , min(2 * a + b + solve(indx + 1 , 1) , a + solve(indx + 1 , 0)));
    }
    else{
        ret = min(ret , a + b + solve(indx + 1 , 1));
    }
    return ret;
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("input.txt" , "r" , stdin);
#endif
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
    int t;
    cin >> t;
    while(t--){
        cin >> n >> a >> b;
        cin >> s;
        memset(memo , -1 , sizeof memo);
        cout << 1ll * (n + 1) * b + solve(0 , 0) << "\n";
    }
}


#include <bits/stdc++.h>
#define debug(x) #x << " = " << x << "; "
#define fore(i,a,b) for(int i=a,gon=b;i<gon;++i)
#define SZ(x) (x.size())
#define pb push_back
#define bg begin()
#define nd end()
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t, n;
    ll a, b;
    string s;
    cin >> t;
    while (t--) {
    	cin >> n >> a >> b >> s;
    	vector<ll> acum;
    	int cur = 0, cnt = 0;
    	fore(i,0,n) {
    		if (s[i]-'0' == cur) {
    			cnt++;
    		} else {
    			acum.pb(cnt);
    			cnt = 1;
    			cur ^= 1;
    		}
    	}
    	acum.pb(cnt);
    	ll ans = 0;
    	fore(i,0,SZ(acum)) {
    		if (i&1) {
    			ans += (acum[i]+1)*2*b + acum[i]*a;
    		} else {
    			ll x = (acum[i]-1)*b + acum[i]*a;
    			if (i+1 < SZ(acum)) x += a;
    			if (i-1 >= 0) x += a;
    			ll y = (1ll<<61);
    			if (i+1 < SZ(acum) && i-1 >= 0) {
    				y = (acum[i]-1)*2*b + acum[i]*a;
    			}
    			ans += min(x, y);
    		}
    	}
    	ans += 2*b;
    	cout << ans << '\n';
    }
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define el endl
#define INF LONG_LONG_MAX
#define NINF LONG_LONG_MIN
#define sz size()
#define nn " "
using namespace std;

int main()
{
    ll t;
    cin>>t;
    while(t>0)
    {
        ll n,a,b;
        cin>>n>>a>>b;
        string s;
        cin>>s;
        ll c=(a*n)+((n+1)*b),i,j;
        //cout<<c<<el;
        vector<ll> v;
        v.clear();
        if(n>2)
        {
        for(i=1;i<n-1;i++)
        {
            if(s[i]=='1')
            v.pb(i);
        }
        for(i=1;i<v.sz;i++)
        {
            if(v[i]-v[i-1]>2)
            {
                c=c+min(2*a,b*(v[i]-v[i-1]-2));
            }
        }
        //cout<<c<<el;
        for(i=0;i<v.sz-1;i++)
        {
            if(v[i+1]-v[i]==1)
                c=c+b;
            else
                c=c+(2*b);
        }
        c=c+(2*b);
        }
        if(v.sz>0)
            cout<<c+(2*a)<<el;
        else
            cout<<c<<el;
        t--;
    }
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define el endl
#define INF LONG_LONG_MAX
#define NINF LONG_LONG_MIN
#define sz size()
#define nn " "
using namespace std;

int main()
{
    ll t;
    cin>>t;
    while(t>0)
    {
        ll n,a,b;
        cin>>n>>a>>b;
        string s;
        cin>>s;
        ll c=(a*n)+((n+1)*b),i,j;
        vector<ll> v;
        v.clear();
        if(n>2)
        {
        for(i=1;i<n-1;i++)
        {
            if(s[i]=='1')
            v.pb(i);
        }
        for(i=1;i<v.sz;i++)
        {
            if(v[i]-v[i-1]>2)
            {
                c=c+min(2*a,b*(v[i]-v[i-1]-2));
            }
        }
        for(i=0;v.sz>0&&i<v.sz-1;i++)
        {
            if(v[i+1]-v[i]==1)
                c=c+b;
            else
                c=c+(2*b);
        }
        c=c+(2*b);
        }
        if(v.sz>0)
            cout<<c+(2*a)<<el;
        else
            cout<<c<<el;
        v.clear();
        t--;
    }
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define el endl
#define INF LONG_LONG_MAX
#define NINF LONG_LONG_MIN
#define sz size()
#define nn " "
using namespace std;

int main()
{
    ll t;
    cin>>t;
    while(t>0)
    {
        ll n,a,b;
        cin>>n>>a>>b;
        string s;
        cin>>s;
        ll c=(a*n)+((n+1)*b),i,j;
        //cout<<c<<el;
        vector<ll> v;
        if(n>2)
        {
        for(i=1;i<n-1;i++)
        {
            if(s[i]=='1')
            v.pb(i);
        }
        for(i=1;i<v.sz;i++)
        {
            if(v[i]-v[i-1]>2)
            {
                c=c+min(2*a,b*(v[i]-v[i-1]-2));
            }
        }
        //cout<<c<<el;
        for(i=0;i<v.sz-1;i++)
        {
            if(v[i+1]-v[i]==1)
                c=c+b;
            else
                c=c+(2*b);
        }
        c=c+(2*b);
        }
        if(v.sz>0)
            cout<<c+(2*a)<<el;
        else
            cout<<c<<el;
        t--;
    }
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define el endl
#define INF LONG_LONG_MAX
#define NINF LONG_LONG_MIN
#define sz size()
#define nn " "
using namespace std;

int main()
{
    ll t;
    cin>>t;
    while(t>0)
    {
        ll n,a,b;
        cin>>n>>a>>b;
        string s;
        cin>>s;
        ll c=(a*n)+((n+1)*b),i,j;
        vector<ll> v;
        v.clear();
        if(n>2)
        {
        for(i=1;i<n-1;i++)
        {
            if(s[i]=='1')
            v.pb(i);
        }
        for(i=1;i<v.sz;i++)
        {
            if(v[i]-v[i-1]>2)
            {
                c=c+min(2*a,b*(v[i]-v[i-1]-2));
            }
        }
        for(i=0;v.sz>0&&i<v.sz-1;i++)
        {
            if(v[i+1]-v[i]==1)
                c=c+b;
            else
                c=c+(2*b);
        }
        }
        if(v.sz>0)
            cout<<c+(2*a)<<el;
        else
            cout<<c<<el;
        v.clear();
        t--;
    }
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define el endl
#define INF LONG_LONG_MAX
#define NINF LONG_LONG_MIN
#define sz size()
#define nn " "
using namespace std;

int main()
{
    ll t;
    cin>>t;
    while(t>0)
    {
        ll n,a,b;
        cin>>n>>a>>b;
        string s;
        cin>>s;
        ll c=(a*n)+((n+1)*b),i,j;
        //cout<<c<<el;
        vector<ll> v;
        v.clear();
        if(n>2)
        {
        for(i=1;i<n-1;i++)
        {
            if(s[i]=='1')
            v.pb(i);
        }
        for(i=1;i<v.sz;i++)
        {
            if(v[i]-v[i-1]>2)
            {
                c=c+min(2*a,b*(v[i]-v[i-1]-2));
            }
        }
        //cout<<c<<el;
        for(i=0;v.sz>0&&i<v.sz-1;i++)
        {
            if(v[i+1]-v[i]==1)
                c=c+b;
            else
                c=c+(2*b);
        }
        c=c+(2*b);
        }
        if(v.sz>0)
            cout<<c+(2*a)<<el;
        else
            cout<<c<<el;
        v.clear();
        t--;
    }
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define el endl
#define INF LONG_LONG_MAX
#define NINF LONG_LONG_MIN
#define sz size()
#define nn " "
using namespace std;

int main()
{
    ll t;
    cin>>t;
    while(t>0)
    {
        ll n,a,b;
        cin>>n>>a>>b;
        string s;
        cin>>s;
        ll c=(a*n)+((n+1)*b),i,j;
        //cout<<c<<el;
        vector<ll> v;
        v.clear();
        if(n>2)
        {
        for(i=1;i<n-1;i++)
        {
            if(s[i]=='1')
            v.pb(i);
        }
        for(i=1;v.sz>0&&i<v.sz;i++)
        {
            if(v[i]-v[i-1]>2)
            {
                c=c+min(2*a,b*(v[i]-v[i-1]-2));
            }
        }
        //cout<<c<<el;
        for(i=0;i<v.sz-1;i++)
        {
            if(v[i+1]-v[i]==1)
                c=c+b;
            else
                c=c+(2*b);
        }
        c=c+(2*b);
        }
        if(v.sz>0)
            cout<<c+(2*a)<<el;
        else
            cout<<c<<el;
        v.clear();
        t--;
    }
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define el endl
#define INF LONG_LONG_MAX
#define NINF LONG_LONG_MIN
#define sz size()
#define nn " "
using namespace std;

int main()
{
    ll t;
    cin>>t;
    while(t>0)
    {
        ll n,a,b;
        cin>>n>>a>>b;
        string s;
        cin>>s;
        ll c=(a*n)+((n+1)*b),i,j;
        //cout<<c<<el;
        vector<ll> v;
        v.clear();
        if(n>2)
        {
        for(i=1;i<n-1;i++)
        {
            if(s[i]=='1')
            v.pb(i);
        }
        for(i=1;i<v.sz;i++)
        {
            if(v[i]-v[i-1]>2)
            {
                c=c+min(2*a,b*(v[i]-v[i-1]-2));
            }
        }
        //cout<<c<<el;
        for(i=0;i<v.sz-1;i++)
        {
            if(v[i+1]-v[i]==1)
                c=c+b;
            else
                c=c+(2*b);
        }
        c=c+(2*b);
        }
        if(v.sz>0)
            cout<<c+(2*a)<<el;
        else
            cout<<c<<el;
        v.clear();
        t--;
    }
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define el endl
#define INF LONG_LONG_MAX
#define NINF LONG_LONG_MIN
#define sz size()
#define nn " "
using namespace std;

int main()
{
    ll t;
    cin>>t;
    while(t>0)
    {
        ll n,a,b;
        cin>>n>>a>>b;
        string s;
        cin>>s;
        ll c=(a*n)+((n+1)*b),i,j;
        vector<ll> v;
        v.clear();
        if(n>2)
        {
        for(i=1;i<n-1;i++)
        {
            if(s[i]=='1')
            v.pb(i);
        }
        for(i=1;i<v.sz;i++)
        {
            if(v[i]-v[i-1]>2)
            {
                c=c+min(2*a,b*(v[i]-v[i-1]-2));
            }
        }
        for(i=0;v.sz>0&&i<v.sz-1;i++)
        {
            if(v[i+1]-v[i]==1)
                c=c+b;
            else
                c=c+(2*b);
        }
        }
        if(v.sz>0)
            cout<<c+(2*a)+(2*b)<<el;
        else
            cout<<c<<el;
        v.clear();
        t--;
    }
}


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

#define ll long long
#define R return
#define B break
#define C continue

int t,a,b,n;int x;
string s;
ll ak[110];
int main(){
  //  int m=t;
    cin>>t;
    int m=t;
 while  (t--){
     cin>>n>>a>>b>>s;
     for(int i=1;i<n;i++){
         if(s[i]!=s[i-1])ak[t]+=a;
         if(s[i]=='1' || (s[i-1]==0 && s[i]==1))x++;
	}

	ak[t]+=(n*a+b*(n+1));
     ak[t]+=(x*b);
 }

while(m--){

    cout<<ak[m]<<endl;
}
    return 0;}


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

#define ll long long
#define R return
#define B break
#define C continue

int n,m,x[55][55],k=0,z=1,coun;
bool  a[55][55],can;

int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>a[i][j];

		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(a[i][j]){
				if(a[i+1][j+1] && a[i][j+1] && a[i+1][j]){x[i][j]=1;k++;}

				else if(a[i+1][j] && a[i][j-1] && a[i+1][j-1]){x[i][j-1]=1;}

				else if(a[i-1][j-1] && a[i][j-1] && a[i-1][j]){	x[i-1][j-1]=1;}

				else if(a[i-1][j+1] && a[i][j+1] && a[i-1][j]){	x[i-1][j]=1;}

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

#define ll long long
#define R return
#define B break
#define C continue

int t,a,b,n;
string s;
ll ak[110];
int main(){
    int m=t;
 while  (t--){
     cin>>n>>a>>b;
     for(int i=1;i<n;i++){
         if(s[i]!=s[i-1])ak[t]+=a;
         if(s[i]=='1')ak[t]+=b;
	}
	ak[t]+=(n*a+b*(n+1));

 }

while(m--){

    cout<<ak[m]<<endl;
}
    return 0;}
	else{cout<<-1;return 0;}
			}
		}
	}
	cout<<k<<endl;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(x[i][j])cout<<i<<" "<<j<<endl;
		}}

    return 0;}

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

#define ll long long
#define R return
#define B break
#define C continue

int t,a,b,n;int x;
string s;
ll ak[110];
int main(){
  //  int m=t;
    cin>>t;
    int m=t;
 while  (t--){
     cin>>n>>a>>b>>s;
     for(int i=1;i<n;i++){
         if(s[i]!=s[i-1])ak[t]+=a;
         if(s[i]=='1' || (s[i-1]=='0' && s[i]=='1'))x++;
	}

	ak[t]+=(n*a+b*(n+1));
     ak[t]+=(x*b);
 }

while(m--){

    cout<<ak[m]<<endl;
}
    return 0;}


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

#define ll long long
#define R return
#define B break
#define C continue

int t,a,b,n;
string s;
ll ak[110];
int main(){
  //  int m=t;
    cin>>t;
    int m=t;
 while  (t--){
     cin>>n>>a>>b>>s;
     for(int i=1;i<n;i++){
         if(s[i]!=s[i-1])ak[t]+=a;
         if(s[i]=='1')ak[t]+=b;
	}
	ak[t]+=(n*a+b*(n+1));

 }

while(m--){

    cout<<ak[m]<<endl;
}
    return 0;}


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

#define ll long long
#define R return
#define B break
#define C continue

int t,a,b,n;
string s;
ll ak[110];
int main(){
  //  int m=t;
    cin>>t;
    int m=t;
 while  (t--){
     cin>>n>>a>>b;
     for(int i=1;i<n;i++){
         if(s[i]!=s[i-1])ak[t]+=a;
         if(s[i]=='1')ak[t]+=b;
	}
	ak[t]+=(n*a+b*(n+1));

 }

while(m--){

    cout<<ak[m]<<endl;
}
    return 0;}


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

#define ll long long
#define R return
#define B break
#define C continue

int t,a,b,n;
string s;
ll ak[110];
int main(){
    int m=t;
 while  (t--){
     cin>>n>>a>>b;
     for(int i=1;i<n;i++){
         if(s[i]!=s[i-1])ak[t]+=a;
         if(s[i]=='1')ak[t]+=b;
	}
	ak[t]+=(n*a+b*(n+1));

 }

while(m--){

    cout<<ak[m]<<endl;
}
    return 0;}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,x,y;
        cin>>n>>x>>y;
        char a[200005];
        int sum=0;
        for(int i=1;i<=n;i++)
            cin>>a[i],sum+=a[i]-'0';
        long long ans=0;
        ans=n*x+2*x;
        int l,r;
        for(int i=1;i<=n;i++)
            if(a[i]=='1')
                {l=i-1;break;}
        for(int i=n;i>=1;i--)
            if(a[i]=='1')
                {r=i+1;break;}
        if(sum==0)
        {
            ans=(n+1)*y+n*x;
            cout<<ans<<endl;
            continue;
        }
        ans+=y*l+(n-r+1)*y;
        for(int i=l+1;i<=r;)
        {
            if(a[i]=='1')
            {
                ans+=2*y;
                i++;
            }
            else
            {
                ans+=2*y;
                int len=i;
                while(a[len]=='0'&&len<=r)
                    len++;
                len=len-i;
                len--;
                if(2*y*len>2*x+len*y)
                    ans+=x*2+len*y;
                else
                    ans+=y*len*2;
                i=i+len+1;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,x,y;
        cin>>n>>x>>y;
        char a[200005];
        int num=0;
        int sum=0;
        for(int i=1;i<=n;i++)
            cin>>a[i],sum+=a[i]-'0';
        long long ans=0;
        int l,r;
        for(int i=1;i<=n;i++)
            if(a[i]=='1')
                {l=i-1;break;}
        for(int i=n;i>=1;i--)
            if(a[i]=='1')
                {r=i+1;break;}
        if(sum==0)
        {
            ans=(n+1)*y+2*x;
            cout<<ans<<endl;
            continue;
        }
        ans+=n*x+2*x;
        ans+=y*l+(n-r+1)*y;
        num+=(l+n-r+1);
        for(int i=l+1;i<=r&&num<n+1;)
        {
            if(a[i]=='1')
            {
                ans+=2*y;
                i++;
                num++;
            }
            else
            {
                ans+=2*y;
                num++;
                int len=i;
                while(a[len]=='0'&&len<=r)
                    len++;
                len=len-i;
                len--;
                num+=len;
                if(2*y*len>2*x+len*y)
                    ans+=x*2+len*y;
                else
                    ans+=y*len*2;
                i=i+len+1;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}