/*
* source.cpp
*
*  Created on: Aug 4, 2016
*      Author: joseph darani
*/

#define _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_DEPRECATED

#include<iostream>
#include <fstream>
#include<string.h>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<bitset>
#include <numeric>
//#include <intrin.h>
using namespace std;

#define iOS ios_base::sync_with_stdio(false)
#define P(x) cout<<#x<<" = { "<<x<<" }\n"
#define All(a) (a).begin(), (a).end()
#define _2d(a,row,col,type) type**a=new type*[row]; for (int i=0;i<row;i++) a[i]=new type[col];
#define lp(i,n) for(int i=0;i<int(n);i++)
#define rep(i, j, n) for (int i=j, i<n; i++)
#define lpr(i,n) for(int i=n-1;i>=0;i--)
#define loopi(i,a,n) for(int i=int(a);i<int(n);i++)
#define clr(a, n) memset(a, n, sizeof(a));
#define scn(a,n) rep(i,n) cin>>a[i];
#define scn2(a,row,col) rep(i,row) rep(j,col) cin>>a[i][j];
#define prn(a,n) rep(i,n-1) cout<<a[i]<<" "; cout<<a[n-1]<<endl;
#define prn2(a,row,col) rep(i,row){rep(j,col-1) cout<<a[i][j]<<" "; cout<<a[i][col-1]<<endl;}
#define rdi(x) scanf("%d",&(x))
#define rdk(x,y) scanf("%d%d",&(x),&(y))
#define rdl(x) scanf("%I64d",&(x))
#define rdll(x,y) scanf("%I64d%I64d",&(x),&(y))
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define Odd(x) x&1
#define Even(x) !(x&1)
#define Pi 3.1415926535897932384626433832795
#define INF 2000000000 // 2 billion
#define OO 0x7fffffff
#define maxL (10000000>>5)+1
#define GET(x) (mark[x>>5]>>(x&31)&1)
#define SET(x) (mark[x>>5] |= 1<<(x&31))
#define mod 1000000007
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<string> vs;
typedef pair<int, int> ii;
typedef pair<int, string> is;
typedef vector<ii> vii;
typedef vector<vi> vvi;

//int dx[] = {1,-1,0,0} , dy[] = {0,0,1,-1}; // 4 Direction
//int dx[] = {1,-1,0,0,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1,1,-1};  // 8 Direction
int dx[] = { 1,-1,1,-1,2,2,-2,-2 }, dy[] = { 2,2,-2,-2,1,-1,1,-1 }; // Knight Direction
																	// int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1}; // Hexagonal Direction

//const int maX = 2000000000;
//binary search int

/*while(l!=r)
{
int mid=(l+r+1)/2;
if(s=="<")
r=mid-1;
else
l=mid;
}*/

//binary search double
/*double l = 0, r = 1e9 + 5;

double ans = 100000000000;
while (fabs(r-l)>0.0001)
{

double mid = (l + r) / 2.0;

int taken = ok(mid);
if (taken<=k)
{
ans = min(ans, mid/2.0);
r = mid;
}
else {
if (taken > k)
{
l = mid;
}
}
}*/

bool is_prime(long long x) {
	if (x <= 1)
		return false;
	for (int i = 2; i * i <= x; i++)
		if (x % i == 0)
			return false;
	return true;

}

bool is_palindrome(string s1) {
	int l = s1.length();
	for (int i = 0; i < l / 2; i++)
		if (s1[i] != s1[l - i - 1])
			return false;

	return true;
}

ull C(ll n, ll k) {
	if (k == 0) return 1;

	return (n * C(n - 1, k - 1)) / k;
}

ll modular_pow(ll base, ll exponent, int modulus) {
	ll result = 1;
	while (exponent > 0) {
		if (exponent % 2 == 1)
			result = (result * base) % modulus;
		exponent = exponent >> 1;
		base = (base * base) % modulus;
	}
	return result;
}

long long binaryToDec(string number) {
	long long result = 0, pow = 1;
	for (int i = number.length() - 1; i >= 0; --i, pow <<= 1)
		result = (result + (number[i] - '0') * pow) % 1000003;

	return result;
}

long long binaryToDec2(string number) {
	long long result = 0, pow = 1;
	int l = number.length();
	for (int i = 0; i <l; ++i, pow <<= 1)
		result = (result + (number[i] - '0') * pow) % 1000003;

	return result;
}

string decimalToBin(int number)
{
	if (number == 0) return "0";
	if (number == 1) return "1";

	if (number % 2 == 0)
		return decimalToBin(number / 2) + "0";
	else
		return decimalToBin(number / 2) + "1";
}
ull GCD(ull a, ull b) {
	return b == 0 ? a : GCD(b, a % b);
}

ull LCM(ull i, ull j)
{
	return (i*j) / GCD(i, j);
}

int cntMask(int mask) {
	int ret = 0;
	while (mask) {
		if (mask % 2)
			ret++;
		mask /= 2;
	}
	return ret;
}
int getBit(int mask, int i) {
	return ((mask >> i) & 1) == 1;
}
int setBit(int mask, int i, int value = 1) {
	return (value) ? mask | (1 << i) : (mask & ~(1 << i));
}

ull mystoi(string s) {
	ull ans = 0;
	ull po = 1;
	for (int i = s.length() - 1; i >= 0; i--) {
		ans += (s[i] - '0') * po;
		po *= 10;
	}

	return ans;

}

string conv(int i) {
	string t = "";
	while (i) {
		t += '0' + (i % 10);
		i /= 10;
	}
	//reverse(All(t));
	return t;
}

bool hasZero(int i) {
	if (i == 0)
		return true;
	while (i) {
		if (i % 10 == 0)
			return true;
		i /= 10;
	}
	return false;
}

bool isSortedAc(int a[], int n) {
	lp(i, n - 1)
		if (a[i] > a[i + 1])
			return false;

	return true;
}

bool isSortedDec(int a[], int n) {
	lp(i, n - 1)
		if (a[i] < a[i + 1])
			return false;

	return true;
}

bool cmp(ull i, ull j)
{
	return i>j;
}

/*
long long a[1<<18] = { 0 };
long long seg_tree[1 << 18] = { 0 };
int n, m;

void build_seg_tree(int low, int hi, int pos)
{
if (low == hi) {
seg_tree[pos] = a[low];

return;

}

int mid = (low + hi) / 2;

build_seg_tree(low, mid, 2 * pos + 1,level+1);
build_seg_tree(mid +1, hi, 2 * pos + 2,level+1);

seg_tree[pos] = max(seg_tree[2 * pos + 1] ,seg_tree[2 * pos + 2]);

return;

}

ll max_q(int low, int hi, int qlow, int qhi, int pos)
{
if (qlow > hi || qhi < low)return -1000000001;

if (low >= qlow && hi <= qhi)return seg_tree[pos];

int mid = (low + hi) / 2;
return max(max_q(low, mid, qlow, qhi, 2 * pos + 1), max_q(mid + 1, hi, qlow, qhi, 2 * pos + 2));
}

*/

ll range_sum(ll l, ll r)
{
	ll one = r*(r + 1) / 2;
	ll two = (l-1)*(l + 2) / 2;

	return one - two;
}

/*vvi adjlist;
int n, m;

bool GreySet[100000 + 5];
bool WhiteSet[100000 + 5] = { true };

bool Cycle = false;

void dfs(int u)
{
	if (GreySet[u]) { Cycle = true; return; }
	GreySet[u] = true;
	WhiteSet[u] = false;

	lp(i, adjlist[u].size())
	{
		int v = adjlist[u][i];
		dfs(v);
	}
	GreySet[u] = false;
}

vi topoSort;
bool topoVis[100000 + 5] = { false };

void topSortDfs(int u)
{
	topoVis[u] = true;

	lp(i, adjlist[u].size())
	{
		int temp = adjlist[u][i];
		if (!topoVis[temp])topSortDfs(temp);
	}
	topoSort.push_back(u);
}
*/

/*cin >> n >> m;
adjlist = vvi(n);

lp(i, m) {
int x, y;
cin >> x >> y;
x--;
y--;
adjlist[x].push_back(y);
}

lp(i, n)
{
if (WhiteSet[i])dfs(i);
if (Cycle) {
cout << "Sandro fails." << endl;
return 0;
}
}

lp(i, n)
{
if (!topoVis[i])topSortDfs(i);
}
lp(i, topoSort.size())
{
cout << topoSort[n-i-1] + 1;
if (i < topoSort.size() - 1)cout << " ";
}

cout << endl;
*/

void A()
{
	int n;
	scanf("%d", &n);

	int a[100000 + 5];
	lp(i, n)scanf("%d", &a[i]);

	sort(a, a + n);
	int ans = abs(a[0] - a[n - 1]);

	lp(i, n - 1)ans = min(ans, abs(a[i] - a[i + 1]));

	printf("%d ", ans);
	int total = 0;
	lp(i, n - 1)
	{
		if (abs(a[i] - a[i + 1]) == ans)total++;
	}
	printf("%d\n", total);
}
int main() {

	//iOS;
	A();

	return 0;
}


/*
* source.cpp
*
*  Created on: Aug 4, 2016
*      Author: joseph darani
*/

#define _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_DEPRECATED

#include<iostream>
#include <fstream>
#include<string.h>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<bitset>
#include <numeric>
//#include <intrin.h>
using namespace std;

#define iOS ios_base::sync_with_stdio(false)
#define P(x) cout<<#x<<" = { "<<x<<" }\n"
#define All(a) (a).begin(), (a).end()
#define _2d(a,row,col,type) type**a=new type*[row]; for (int i=0;i<row;i++) a[i]=new type[col];
#define lp(i,n) for(int i=0;i<int(n);i++)
#define rep(i, j, n) for (int i=j, i<n; i++)
#define lpr(i,n) for(int i=n-1;i>=0;i--)
#define loopi(i,a,n) for(int i=int(a);i<int(n);i++)
#define clr(a, n) memset(a, n, sizeof(a));
#define scn(a,n) rep(i,n) cin>>a[i];
#define scn2(a,row,col) rep(i,row) rep(j,col) cin>>a[i][j];
#define prn(a,n) rep(i,n-1) cout<<a[i]<<" "; cout<<a[n-1]<<endl;
#define prn2(a,row,col) rep(i,row){rep(j,col-1) cout<<a[i][j]<<" "; cout<<a[i][col-1]<<endl;}
#define rdi(x) scanf("%d",&(x))
#define rdk(x,y) scanf("%d%d",&(x),&(y))
#define rdl(x) scanf("%I64d",&(x))
#define rdll(x,y) scanf("%I64d%I64d",&(x),&(y))
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define Odd(x) x&1
#define Even(x) !(x&1)
#define Pi 3.1415926535897932384626433832795
#define INF 2000000000 // 2 billion
#define OO 0x7fffffff
#define maxL (10000000>>5)+1
#define GET(x) (mark[x>>5]>>(x&31)&1)
#define SET(x) (mark[x>>5] |= 1<<(x&31))
#define mod 1000000007
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<string> vs;
typedef pair<int, int> ii;
typedef pair<int, string> is;
typedef vector<ii> vii;
typedef vector<vi> vvi;

//int dx[] = {1,-1,0,0} , dy[] = {0,0,1,-1}; // 4 Direction
//int dx[] = {1,-1,0,0,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1,1,-1};  // 8 Direction
int dx[] = { 1,-1,1,-1,2,2,-2,-2 }, dy[] = { 2,2,-2,-2,1,-1,1,-1 }; // Knight Direction
																	// int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1}; // Hexagonal Direction

//const int maX = 2000000000;
//binary search int

/*while(l!=r)
{
int mid=(l+r+1)/2;
if(s=="<")
r=mid-1;
else
l=mid;
}*/

//binary search double
/*double l = 0, r = 1e9 + 5;

double ans = 100000000000;
while (fabs(r-l)>0.0001)
{

double mid = (l + r) / 2.0;

int taken = ok(mid);
if (taken<=k)
{
ans = min(ans, mid/2.0);
r = mid;
}
else {
if (taken > k)
{
l = mid;
}
}
}*/

bool is_prime(long long x) {
	if (x <= 1)
		return false;
	for (int i = 2; i * i <= x; i++)
		if (x % i == 0)
			return false;
	return true;

}

bool is_palindrome(string s1) {
	int l = s1.length();
	for (int i = 0; i < l / 2; i++)
		if (s1[i] != s1[l - i - 1])
			return false;

	return true;
}

ull C(ll n, ll k) {
	if (k == 0) return 1;

	return (n * C(n - 1, k - 1)) / k;
}

ll modular_pow(ll base, ll exponent, int modulus) {
	ll result = 1;
	while (exponent > 0) {
		if (exponent % 2 == 1)
			result = (result * base) % modulus;
		exponent = exponent >> 1;
		base = (base * base) % modulus;
	}
	return result;
}

long long binaryToDec(string number) {
	long long result = 0, pow = 1;
	for (int i = number.length() - 1; i >= 0; --i, pow <<= 1)
		result = (result + (number[i] - '0') * pow) % 1000003;

	return result;
}

long long binaryToDec2(string number) {
	long long result = 0, pow = 1;
	int l = number.length();
	for (int i = 0; i <l; ++i, pow <<= 1)
		result = (result + (number[i] - '0') * pow) % 1000003;

	return result;
}

string decimalToBin(int number)
{
	if (number == 0) return "0";
	if (number == 1) return "1";

	if (number % 2 == 0)
		return decimalToBin(number / 2) + "0";
	else
		return decimalToBin(number / 2) + "1";
}
ull GCD(ull a, ull b) {
	return b == 0 ? a : GCD(b, a % b);
}

ull LCM(ull i, ull j)
{
	return (i*j) / GCD(i, j);
}

int cntMask(int mask) {
	int ret = 0;
	while (mask) {
		if (mask % 2)
			ret++;
		mask /= 2;
	}
	return ret;
}
int getBit(int mask, int i) {
	return ((mask >> i) & 1) == 1;
}
int setBit(int mask, int i, int value = 1) {
	return (value) ? mask | (1 << i) : (mask & ~(1 << i));
}

ull mystoi(string s) {
	ull ans = 0;
	ull po = 1;
	for (int i = s.length() - 1; i >= 0; i--) {
		ans += (s[i] - '0') * po;
		po *= 10;
	}

	return ans;

}

string conv(int i) {
	string t = "";
	while (i) {
		t += '0' + (i % 10);
		i /= 10;
	}
	//reverse(All(t));
	return t;
}

bool hasZero(int i) {
	if (i == 0)
		return true;
	while (i) {
		if (i % 10 == 0)
			return true;
		i /= 10;
	}
	return false;
}

bool isSortedAc(int a[], int n) {
	lp(i, n - 1)
		if (a[i] > a[i + 1])
			return false;

	return true;
}

bool isSortedDec(int a[], int n) {
	lp(i, n - 1)
		if (a[i] < a[i + 1])
			return false;

	return true;
}

bool cmp(ull i, ull j)
{
	return i>j;
}

/*
long long a[1<<18] = { 0 };
long long seg_tree[1 << 18] = { 0 };
int n, m;

void build_seg_tree(int low, int hi, int pos)
{
if (low == hi) {
seg_tree[pos] = a[low];

return;

}

int mid = (low + hi) / 2;

build_seg_tree(low, mid, 2 * pos + 1,level+1);
build_seg_tree(mid +1, hi, 2 * pos + 2,level+1);

seg_tree[pos] = max(seg_tree[2 * pos + 1] ,seg_tree[2 * pos + 2]);

return;

}

ll max_q(int low, int hi, int qlow, int qhi, int pos)
{
if (qlow > hi || qhi < low)return -1000000001;

if (low >= qlow && hi <= qhi)return seg_tree[pos];

int mid = (low + hi) / 2;
return max(max_q(low, mid, qlow, qhi, 2 * pos + 1), max_q(mid + 1, hi, qlow, qhi, 2 * pos + 2));
}

*/

ll range_sum(ll l, ll r)
{
	ll one = r*(r + 1) / 2;
	ll two = (l-1)*(l + 2) / 2;

	return one - two;
}

/*vvi adjlist;
int n, m;

bool GreySet[100000 + 5];
bool WhiteSet[100000 + 5] = { true };

bool Cycle = false;

void dfs(int u)
{
	if (GreySet[u]) { Cycle = true; return; }
	GreySet[u] = true;
	WhiteSet[u] = false;

	lp(i, adjlist[u].size())
	{
		int v = adjlist[u][i];
		dfs(v);
	}
	GreySet[u] = false;
}

vi topoSort;
bool topoVis[100000 + 5] = { false };

void topSortDfs(int u)
{
	topoVis[u] = true;

	lp(i, adjlist[u].size())
	{
		int temp = adjlist[u][i];
		if (!topoVis[temp])topSortDfs(temp);
	}
	topoSort.push_back(u);
}
*/

/*cin >> n >> m;
adjlist = vvi(n);

lp(i, m) {
int x, y;
cin >> x >> y;
x--;
y--;
adjlist[x].push_back(y);
}

lp(i, n)
{
if (WhiteSet[i])dfs(i);
if (Cycle) {
cout << "Sandro fails." << endl;
return 0;
}
}

lp(i, n)
{
if (!topoVis[i])topSortDfs(i);
}
lp(i, topoSort.size())
{
cout << topoSort[n-i-1] + 1;
if (i < topoSort.size() - 1)cout << " ";
}

cout << endl;
*/

void A()
{
	int n;
	cin >> n;

	int a[100000 + 5];
	lp(i, n)cin >> a[i];

	sort(a, a + n);
	int ans = abs(a[0] - a[n - 1]);

	lp(i, n - 1)ans = min(ans, abs(a[i] - a[i + 1]));

	cout << ans << " ";
	int total = 0;
	lp(i, n - 1)
	{
		if (abs(a[i] - a[i + 1]) == ans)total++;
	}
	cout << total << endl;
}
int main() {

	iOS;
	A();

	return 0;
}


/*
* source.cpp
*
*  Created on: Aug 4, 2016
*      Author: joseph darani
*/

#define _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_DEPRECATED

#include<iostream>
#include <fstream>
#include<string.h>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<bitset>
#include <numeric>
//#include <intrin.h>
using namespace std;

#define iOS ios_base::sync_with_stdio(false)
#define P(x) cout<<#x<<" = { "<<x<<" }\n"
#define All(a) (a).begin(), (a).end()
#define _2d(a,row,col,type) type**a=new type*[row]; for (int i=0;i<row;i++) a[i]=new type[col];
#define lp(i,n) for(int i=0;i<int(n);i++)
#define rep(i, j, n) for (int i=j, i<n; i++)
#define lpr(i,n) for(int i=n-1;i>=0;i--)
#define loopi(i,a,n) for(int i=int(a);i<int(n);i++)
#define clr(a, n) memset(a, n, sizeof(a));
#define scn(a,n) rep(i,n) cin>>a[i];
#define scn2(a,row,col) rep(i,row) rep(j,col) cin>>a[i][j];
#define prn(a,n) rep(i,n-1) cout<<a[i]<<" "; cout<<a[n-1]<<endl;
#define prn2(a,row,col) rep(i,row){rep(j,col-1) cout<<a[i][j]<<" "; cout<<a[i][col-1]<<endl;}
#define rdi(x) scanf("%d",&(x))
#define rdk(x,y) scanf("%d%d",&(x),&(y))
#define rdl(x) scanf("%I64d",&(x))
#define rdll(x,y) scanf("%I64d%I64d",&(x),&(y))
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define Odd(x) x&1
#define Even(x) !(x&1)
#define Pi 3.1415926535897932384626433832795
#define INF 2000000000 // 2 billion
#define OO 0x7fffffff
#define maxL (10000000>>5)+1
#define GET(x) (mark[x>>5]>>(x&31)&1)
#define SET(x) (mark[x>>5] |= 1<<(x&31))
#define mod 1000000007
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<string> vs;
typedef pair<int, int> ii;
typedef pair<int, string> is;
typedef vector<ii> vii;
typedef vector<vi> vvi;

//int dx[] = {1,-1,0,0} , dy[] = {0,0,1,-1}; // 4 Direction
//int dx[] = {1,-1,0,0,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1,1,-1};  // 8 Direction
int dx[] = { 1,-1,1,-1,2,2,-2,-2 }, dy[] = { 2,2,-2,-2,1,-1,1,-1 }; // Knight Direction
																	// int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1}; // Hexagonal Direction

//const int maX = 2000000000;
//binary search int

/*while(l!=r)
{
int mid=(l+r+1)/2;
if(s=="<")
r=mid-1;
else
l=mid;
}*/

//binary search double
/*double l = 0, r = 1e9 + 5;

double ans = 100000000000;
while (fabs(r-l)>0.0001)
{

double mid = (l + r) / 2.0;

int taken = ok(mid);
if (taken<=k)
{
ans = min(ans, mid/2.0);
r = mid;
}
else {
if (taken > k)
{
l = mid;
}
}
}*/

bool is_prime(long long x) {
	if (x <= 1)
		return false;
	for (int i = 2; i * i <= x; i++)
		if (x % i == 0)
			return false;
	return true;

}

bool is_palindrome(string s1) {
	int l = s1.length();
	for (int i = 0; i < l / 2; i++)
		if (s1[i] != s1[l - i - 1])
			return false;

	return true;
}

ull C(ll n, ll k) {
	if (k == 0) return 1;

	return (n * C(n - 1, k - 1)) / k;
}

ll modular_pow(ll base, ll exponent, int modulus) {
	ll result = 1;
	while (exponent > 0) {
		if (exponent % 2 == 1)
			result = (result * base) % modulus;
		exponent = exponent >> 1;
		base = (base * base) % modulus;
	}
	return result;
}

long long binaryToDec(string number) {
	long long result = 0, pow = 1;
	for (int i = number.length() - 1; i >= 0; --i, pow <<= 1)
		result = (result + (number[i] - '0') * pow) % 1000003;

	return result;
}

long long binaryToDec2(string number) {
	long long result = 0, pow = 1;
	int l = number.length();
	for (int i = 0; i <l; ++i, pow <<= 1)
		result = (result + (number[i] - '0') * pow) % 1000003;

	return result;
}

string decimalToBin(int number)
{
	if (number == 0) return "0";
	if (number == 1) return "1";

	if (number % 2 == 0)
		return decimalToBin(number / 2) + "0";
	else
		return decimalToBin(number / 2) + "1";
}
ull GCD(ull a, ull b) {
	return b == 0 ? a : GCD(b, a % b);
}

ull LCM(ull i, ull j)
{
	return (i*j) / GCD(i, j);
}

int cntMask(int mask) {
	int ret = 0;
	while (mask) {
		if (mask % 2)
			ret++;
		mask /= 2;
	}
	return ret;
}
int getBit(int mask, int i) {
	return ((mask >> i) & 1) == 1;
}
int setBit(int mask, int i, int value = 1) {
	return (value) ? mask | (1 << i) : (mask & ~(1 << i));
}

ull mystoi(string s) {
	ull ans = 0;
	ull po = 1;
	for (int i = s.length() - 1; i >= 0; i--) {
		ans += (s[i] - '0') * po;
		po *= 10;
	}

	return ans;

}

string conv(int i) {
	string t = "";
	while (i) {
		t += '0' + (i % 10);
		i /= 10;
	}
	//reverse(All(t));
	return t;
}

bool hasZero(int i) {
	if (i == 0)
		return true;
	while (i) {
		if (i % 10 == 0)
			return true;
		i /= 10;
	}
	return false;
}

bool isSortedAc(int a[], int n) {
	lp(i, n - 1)
		if (a[i] > a[i + 1])
			return false;

	return true;
}

bool isSortedDec(int a[], int n) {
	lp(i, n - 1)
		if (a[i] < a[i + 1])
			return false;

	return true;
}

bool cmp(ull i, ull j)
{
	return i>j;
}

/*
long long a[1<<18] = { 0 };
long long seg_tree[1 << 18] = { 0 };
int n, m;

void build_seg_tree(int low, int hi, int pos)
{
if (low == hi) {
seg_tree[pos] = a[low];

return;

}

int mid = (low + hi) / 2;

build_seg_tree(low, mid, 2 * pos + 1,level+1);
build_seg_tree(mid +1, hi, 2 * pos + 2,level+1);

seg_tree[pos] = max(seg_tree[2 * pos + 1] ,seg_tree[2 * pos + 2]);

return;

}

ll max_q(int low, int hi, int qlow, int qhi, int pos)
{
if (qlow > hi || qhi < low)return -1000000001;

if (low >= qlow && hi <= qhi)return seg_tree[pos];

int mid = (low + hi) / 2;
return max(max_q(low, mid, qlow, qhi, 2 * pos + 1), max_q(mid + 1, hi, qlow, qhi, 2 * pos + 2));
}

*/

ll range_sum(ll l, ll r)
{
	ll one = r*(r + 1) / 2;
	ll two = (l-1)*(l + 2) / 2;

	return one - two;
}

/*vvi adjlist;
int n, m;

bool GreySet[100000 + 5];
bool WhiteSet[100000 + 5] = { true };

bool Cycle = false;

void dfs(int u)
{
	if (GreySet[u]) { Cycle = true; return; }
	GreySet[u] = true;
	WhiteSet[u] = false;

	lp(i, adjlist[u].size())
	{
		int v = adjlist[u][i];
		dfs(v);
	}
	GreySet[u] = false;
}

vi topoSort;
bool topoVis[100000 + 5] = { false };

void topSortDfs(int u)
{
	topoVis[u] = true;

	lp(i, adjlist[u].size())
	{
		int temp = adjlist[u][i];
		if (!topoVis[temp])topSortDfs(temp);
	}
	topoSort.push_back(u);
}
*/

void A()
{
	int n;
	cin >> n;

	int a[200000 + 5];
	lp(i, n)cin >> a[i];

	sort(a, a + n);
	int ans = abs(a[0] - a[n - 1]);

	lp(i, n - 1)ans = min(ans, abs(a[i] - a[i + 1]));

	cout << ans << " ";
	int total = 0;
	lp(i, n - 1)
	{
		if (abs(a[i] - a[i + 1]) == ans)total++;
	}
	cout << total << endl;
}
int main() {

	A();

	return 0;
}


#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
long long n,m,v[100001],x[100001],mn=1000000,c,s;
int main()
{
    int i,j;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>v[i];
    }

    sort(v+1,v+n+1);
    for(i=1;i<n;i++)
    {
        if(mn>abs(v[i+1]-v[i]))
        {
            mn=abs(v[i+1]-v[i]);
        }
    }

    for(i=1;i<n;i++)
    {
        if(mn==abs(v[i+1]-v[i]))
        {
            s++;
        }
    }
    cout<<mn<<" "<<s;
    return 0;
}


#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
long long n,m,v[100001],x[100001],mn=3000000000,c,s;
int main()
{
    int i,j;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>v[i];
    }

    sort(v+1,v+n+1);
    for(i=1;i<n;i++)
    {
        if(mn>abs(v[i+1]-v[i]))
        {
            mn=abs(v[i+1]-v[i]);
        }
    }

    for(i=1;i<n;i++)
    {
        if(mn==abs(v[i+1]-v[i]))
        {
            s++;
        }
    }
    cout<<mn<<" "<<s;
    return 0;
}


#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
long long n,m,v[300001],x[300001],mn=3000000000,c,s;
int main()
{
    int i,j;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>v[i];
    }

    sort(v+1,v+n+1);
    for(i=1;i<n;i++)
    {
        if(mn>abs(v[i+1]-v[i]))
        {
            mn=abs(v[i+1]-v[i]);
        }
    }

    for(i=1;i<n;i++)
    {
        if(mn==abs(v[i+1]-v[i]))
        {
            s++;
        }
    }
    cout<<mn<<" "<<s;
    return 0;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <cstdio>
#include <math.h>
#include <queue>
#include <deque>
#include <assert.h>
#include <stack>
#include <list>
#include <set>
#include <map>

using namespace std;

/****************************************************************\
|     		 _	   _	  _ _	  ___   _    _ ___				 |
|			|  \_/   |	 /  ||  ||   ) | |  | |	  )				 |
|			| |	   | | 	/ _ ||--||-- } | |__| |-- }				 |
|			|_|    |_| /	||  ||___) | ____ |___)				 |
|   	BANGLADESH UNIVERSITY OF BUSINESS & TECHNOLOGY(BUBT)	 |
|		 			Deptartment of  CSE							 |
|    uva:mahbub07||devskil: mahbub07||codefoces:MAHBUBUR_RAHMAN  |
|                mail:mahbubabid8@gmail.com				         |
\****************************************************************/

typedef long long ll;
typedef double ld;
typedef unsigned long long ull;
typedef  vector<int> vi;
typedef  vector<ll> vll;
typedef  vector<string> vs;
typedef  set<int> si;
typedef  set<string> ss;
typedef  map<int,int> mii;
typedef  map<ll,ll> mll;
typedef  map<string,int> msi;
typedef  map<char,int> mci;
//----------------defines-----------------------
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(),v.end()
#define ms(s, n) memset(s, n, sizeof(s))
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
#define For0(i,n) for(int i=0;i<(int)n;i++)
#define For1(i,n) for(int i=1;i<=(int)n;i++)
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define Case(no) printf("Case %d: ",++no)
#define pb(b) push_back(b)
#define mp make_pair
#define maxall(v) *max_element(all(v))
#define minall(v) *min_element(all(v))
#define sortArr(a,n) sort(a,a+n)
#define sortVec(a) sort(all(a))
#define endl '\n'
#define DIST(x1,y1, x2, y2) (((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)))
#define DIST3D(x1,x2, y1, y2, z1, z2) (((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)) + ((z1-z2)*(z1-z2)))
//----------------functions-----------------------
ll muliplyfast(ll a, ll b, ll c){ if(b==0) return 0;ll x = muliplyfast(a , b/2, c)%c; if(!(b&1)){ return (x%c+x%c)%c;}else return ((a%c + (x+x)%c))%c; }
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=muliplyfast(res,a,mod)%mod;a=muliplyfast(res,a,mod)%mod;}return res;}
ll modInverse(ll a, ll m){return powmod(a,m-2,m);}
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
//----------------constants-----------------------
const int MOD = (int) 1e9 + 7;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;

int main()
{
	ll city;
	cin >> city;
	ll minVal = 1e9+7;
	ll cur = 0;
	int cont = 0;
	vector<ll>v;
	For0(i, city){
		ll x;
		cin >> x;
		v.pb(x);

	}
	sortVec(v);
	int l = v.size();
	For0(i, l-1){
		cur = ((v[i+1] - v[i]));
		if(cur < minVal && cur > 0){
			minVal = cur;
			cont = 1;

		}else if(cur == minVal){
			cont++;
			//cout << cur << endl;
		}

	}
	cout << minVal <<" "<<cont<<endl;
	return 0;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <cstdio>
#include <math.h>
#include <queue>
#include <deque>
#include <assert.h>
#include <stack>
#include <list>
#include <set>
#include <map>

using namespace std;

/****************************************************************\
|     		 _	   _	  _ _	  ___   _    _ ___				 |
|			|  \_/   |	 /  ||  ||   ) | |  | |	  )				 |
|			| |	   | | 	/ _ ||--||-- } | |__| |-- }				 |
|			|_|    |_| /	||  ||___) | ____ |___)				 |
|   	BANGLADESH UNIVERSITY OF BUSINESS & TECHNOLOGY(BUBT)	 |
|		 			Deptartment of  CSE							 |
|    uva:mahbub07||devskil: mahbub07||codefoces:MAHBUBUR_RAHMAN  |
|                mail:mahbubabid8@gmail.com				         |
\****************************************************************/

typedef long long ll;
typedef double ld;
typedef unsigned long long ull;
typedef  vector<int> vi;
typedef  vector<ll> vll;
typedef  vector<string> vs;
typedef  set<int> si;
typedef  set<string> ss;
typedef  map<int,int> mii;
typedef  map<ll,ll> mll;
typedef  map<string,int> msi;
typedef  map<char,int> mci;
//----------------defines-----------------------
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(),v.end()
#define ms(s, n) memset(s, n, sizeof(s))
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
#define For0(i,n) for(int i=0;i<(int)n;i++)
#define For1(i,n) for(int i=1;i<=(int)n;i++)
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define Case(no) printf("Case %d: ",++no)
#define pb(b) push_back(b)
#define mp make_pair
#define maxall(v) *max_element(all(v))
#define minall(v) *min_element(all(v))
#define sortArr(a,n) sort(a,a+n)
#define sortVec(a) sort(all(a))
#define endl '\n'
#define DIST(x1,y1, x2, y2) (((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)))
#define DIST3D(x1,x2, y1, y2, z1, z2) (((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)) + ((z1-z2)*(z1-z2)))
//----------------functions-----------------------
ll muliplyfast(ll a, ll b, ll c){ if(b==0) return 0;ll x = muliplyfast(a , b/2, c)%c; if(!(b&1)){ return (x%c+x%c)%c;}else return ((a%c + (x+x)%c))%c; }
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=muliplyfast(res,a,mod)%mod;a=muliplyfast(res,a,mod)%mod;}return res;}
ll modInverse(ll a, ll m){return powmod(a,m-2,m);}
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
//----------------constants-----------------------
const int MOD = (int) 1e9 + 7;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;

int main()
{
	ll city;
	cin >> city;
	ll minVal = 1e9+7;
	ll cur = 0;
	int cont = 0;
	For0(i, city){
		ll x;
		cin >> x;
		//if(x < 0) continue;
		ll val = abs(x - cur);
		//cout << (x-cur)<<endl;
		if( val < minVal){
			minVal = val;
			cont = 1;
			cur = x < 0 ? min(x,cur): x ;
			//cout << minVal <<" "<<cur<<endl;
		}
		else if(val == minVal) {
			cont++;

		}else
		 	cur = max(x,cur);
		//cout << cur<<endl;

	}
	cout << minVal <<" "<<cont<<endl;
	return 0;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <cstdio>
#include <math.h>
#include <queue>
#include <deque>
#include <assert.h>
#include <stack>
#include <list>
#include <set>
#include <map>

using namespace std;

/****************************************************************\
|                       Md.Mahbubur Rahman                       |
|   	BANGLADESH UNIVERSITY OF BUSINESS & TECHNOLOGY(BUBT)	 |
|		 			Deptartment of  CSE							 |
|    uva:mahbub07||devskil: mahbub07||codefoces:MAHBUBUR_RAHMAN  |
|                mail:mahbubabid8@gmail.com				         |
\****************************************************************/

typedef long long ll;
typedef double ld;
typedef unsigned long long ull;
typedef  vector<int> vi;
typedef  vector<ll> vll;
typedef  vector<string> vs;
typedef  set<int> si;
typedef  set<string> ss;
typedef  map<int,int> mii;
typedef  map<ll,ll> mll;
typedef  map<string,int> msi;
typedef  map<char,int> mci;
//----------------defines-----------------------
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(),v.end()
#define ms(s, n) memset(s, n, sizeof(s))
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
#define For0(i,n) for(int i=0;i<(int)n;i++)
#define For1(i,n) for(int i=1;i<=(int)n;i++)
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define Case(no) printf("Case %d: ",++no)
#define pb(b) push_back(b)
#define mp make_pair
#define maxall(v) *max_element(all(v))
#define minall(v) *min_element(all(v))
#define sortArr(a,n) sort(a,a+n)
#define sortVec(a) sort(all(a))
#define endl '\n'
#define DIST(x1,y1, x2, y2) (((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)))
#define DIST3D(x1,x2, y1, y2, z1, z2) (((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)) + ((z1-z2)*(z1-z2)))
//----------------functions-----------------------
ll muliplyfast(ll a, ll b, ll c){ if(b==0) return 0;ll x = muliplyfast(a , b/2, c)%c; if(!(b&1)){ return (x%c+x%c)%c;}else return ((a%c + (x+x)%c))%c; }
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=muliplyfast(res,a,mod)%mod;a=muliplyfast(res,a,mod)%mod;}return res;}
ll modInverse(ll a, ll m){return powmod(a,m-2,m);}
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
//----------------constants-----------------------
const int MOD = (int) 1e9 + 7;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;

int main()
{
	ll city;
	cin >> city;
	ll minVal = 2e9+7;
	ll cur = 0;
	int cont = 1;
	vector<ll>v;
	For0(i, city){
		ll x;
		cin >> x;
		v.pb(x);

	}
	sortVec(v);
	int l = v.size();
	For0(i, l-1){
		cur = ((v[i+1] - v[i]));
		//cout << cur << endl;
		if(cur < minVal){
			minVal = cur;
			cont = 1;

		}else if(cur == minVal){
			cont++;
			//cout << cur << endl;
		}

	}
	cout << minVal <<" "<<cont<<endl;
	return 0;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <cstdio>
#include <math.h>
#include <queue>
#include <deque>
#include <assert.h>
#include <stack>
#include <list>
#include <set>
#include <map>

using namespace std;

/****************************************************************\
|     	 _	   _	  _ _	  ___   _    _ ___				 	 |
|		|  \_/   |	 /  ||  ||   ) | |  | |	  )				 	 |
|		| |	   | | 	/ _ ||--||-- } | |__| |-- }				 	 |
|		|_|    |_| /	||  ||___) | ____ |___)				 	 |
|   	BANGLADESH UNIVERSITY OF BUSINESS & TECHNOLOGY(BUBT)	 |
|		 			Deptartment of  CSE							 |
|    uva:mahbub07||devskil: mahbub07||codefoces:MAHBUBUR_RAHMAN  |
|                mail:mahbubabid8@gmail.com				         |
\****************************************************************/

typedef long long ll;
typedef double ld;
typedef unsigned long long ull;
typedef  vector<int> vi;
typedef  vector<ll> vll;
typedef  vector<string> vs;
typedef  set<int> si;
typedef  set<string> ss;
typedef  map<int,int> mii;
typedef  map<ll,ll> mll;
typedef  map<string,int> msi;
typedef  map<char,int> mci;
//----------------defines-----------------------
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(),v.end()
#define ms(s, n) memset(s, n, sizeof(s))
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
#define For0(i,n) for(int i=0;i<(int)n;i++)
#define For1(i,n) for(int i=1;i<=(int)n;i++)
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define Case(no) printf("Case %d: ",++no)
#define pb(b) push_back(b)
#define mp make_pair
#define maxall(v) *max_element(all(v))
#define minall(v) *min_element(all(v))
#define sortArr(a,n) sort(a,a+n)
#define sortVec(a) sort(all(a))
#define endl '\n'
#define DIST(x1,y1, x2, y2) (((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)))
#define DIST3D(x1,x2, y1, y2, z1, z2) (((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)) + ((z1-z2)*(z1-z2)))
//----------------functions-----------------------
ll muliplyfast(ll a, ll b, ll c){ if(b==0) return 0;ll x = muliplyfast(a , b/2, c)%c; if(!(b&1)){ return (x%c+x%c)%c;}else return ((a%c + (x+x)%c))%c; }
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=muliplyfast(res,a,mod)%mod;a=muliplyfast(res,a,mod)%mod;}return res;}
ll modInverse(ll a, ll m){return powmod(a,m-2,m);}
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
//----------------constants-----------------------
const int MOD = (int) 1e9 + 7;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;

int main()
{
	ll city;
	cin >> city;
	ll minVal = 2e9+7;
	ll cur = 0;
	int cont = 1;
	vector<ll>v;
	For0(i, city){
		ll x;
		cin >> x;
		v.pb(x);

	}
	sortVec(v);
	int l = v.size();
	For0(i, l-1){
		cur = ((v[i+1] - v[i]));
		//cout << cur << endl;
		if(cur < minVal){
			minVal = cur;
			cont = 1;

		}else if(cur == minVal){
			cont++;
			//cout << cur << endl;
		}

	}
	cout << minVal <<" "<<cont<<endl;
	return 0;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <cstdio>
#include <math.h>
#include <queue>
#include <deque>
#include <assert.h>
#include <stack>
#include <list>
#include <set>
#include <map>

using namespace std;

/****************************************************************\
|     		 _	   _	  _ _	  ___   _    _ ___				 |
|			|  \_/   |	 /  ||  ||   ) | |  | |	  )				 |
|			| |	   | | 	/ _ ||--||-- } | |__| |-- }				 |
|			|_|    |_| /	||  ||___) | ____ |___)				 |
|   	BANGLADESH UNIVERSITY OF BUSINESS & TECHNOLOGY(BUBT)	 |
|		 			Deptartment of  CSE							 |
|    uva:mahbub07||devskil: mahbub07||codefoces:MAHBUBUR_RAHMAN  |
|                mail:mahbubabid8@gmail.com				         |
\****************************************************************/

typedef long long ll;
typedef double ld;
typedef unsigned long long ull;
typedef  vector<int> vi;
typedef  vector<ll> vll;
typedef  vector<string> vs;
typedef  set<int> si;
typedef  set<string> ss;
typedef  map<int,int> mii;
typedef  map<ll,ll> mll;
typedef  map<string,int> msi;
typedef  map<char,int> mci;
//----------------defines-----------------------
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(),v.end()
#define ms(s, n) memset(s, n, sizeof(s))
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
#define For0(i,n) for(int i=0;i<(int)n;i++)
#define For1(i,n) for(int i=1;i<=(int)n;i++)
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define Case(no) printf("Case %d: ",++no)
#define pb(b) push_back(b)
#define mp make_pair
#define maxall(v) *max_element(all(v))
#define minall(v) *min_element(all(v))
#define sortArr(a,n) sort(a,a+n)
#define sortVec(a) sort(all(a))
#define endl '\n'
#define DIST(x1,y1, x2, y2) (((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)))
#define DIST3D(x1,x2, y1, y2, z1, z2) (((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)) + ((z1-z2)*(z1-z2)))
//----------------functions-----------------------
ll muliplyfast(ll a, ll b, ll c){ if(b==0) return 0;ll x = muliplyfast(a , b/2, c)%c; if(!(b&1)){ return (x%c+x%c)%c;}else return ((a%c + (x+x)%c))%c; }
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=muliplyfast(res,a,mod)%mod;a=muliplyfast(res,a,mod)%mod;}return res;}
ll modInverse(ll a, ll m){return powmod(a,m-2,m);}
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
//----------------constants-----------------------
const int MOD = (int) 1e9 + 7;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;

int main()
{
	ll city;
	cin >> city;
	ll minVal = 1e9+7;
	ll cur = 0;
	int cont = 0;
	vector<ll>v;
	For0(i, city){
		ll x;
		cin >> x;
		v.pb(x);

	}
	sortVec(v);
	int l = v.size();
	For0(i, l-1){
		cur = (abs(v[i] - v[i+1]));
		if(cur < minVal){
			minVal = cur;
			cont=1;
		}else if(cur == minVal)
			cont++;
	}
	cout << minVal <<" "<<cont<<endl;
	return 0;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <cstdio>
#include <math.h>
#include <queue>
#include <deque>
#include <assert.h>
#include <stack>
#include <list>
#include <set>
#include <map>

using namespace std;

/****************************************************************\
|     		 _	   _	  _ _	  ___   _    _ ___				 |
|			|  \_/   |	 /  ||  ||   ) | |  | |	  )				 |
|			| |	   | | 	/ _ ||--||-- } | |__| |-- }				 |
|			|_|    |_| /	||  ||___) | ____ |___)				 |
|   	BANGLADESH UNIVERSITY OF BUSINESS & TECHNOLOGY(BUBT)	 |
|		 			Deptartment of  CSE							 |
|    uva:mahbub07||devskil: mahbub07||codefoces:MAHBUBUR_RAHMAN  |
|                mail:mahbubabid8@gmail.com				         |
\****************************************************************/

typedef long long ll;
typedef double ld;
typedef unsigned long long ull;
typedef  vector<int> vi;
typedef  vector<ll> vll;
typedef  vector<string> vs;
typedef  set<int> si;
typedef  set<string> ss;
typedef  map<int,int> mii;
typedef  map<ll,ll> mll;
typedef  map<string,int> msi;
typedef  map<char,int> mci;
//----------------defines-----------------------
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(),v.end()
#define ms(s, n) memset(s, n, sizeof(s))
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
#define For0(i,n) for(int i=0;i<(int)n;i++)
#define For1(i,n) for(int i=1;i<=(int)n;i++)
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define Case(no) printf("Case %d: ",++no)
#define pb(b) push_back(b)
#define mp make_pair
#define maxall(v) *max_element(all(v))
#define minall(v) *min_element(all(v))
#define sortArr(a,n) sort(a,a+n)
#define sortVec(a) sort(all(a))
#define endl '\n'
#define DIST(x1,y1, x2, y2) (((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)))
#define DIST3D(x1,x2, y1, y2, z1, z2) (((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)) + ((z1-z2)*(z1-z2)))
//----------------functions-----------------------
ll muliplyfast(ll a, ll b, ll c){ if(b==0) return 0;ll x = muliplyfast(a , b/2, c)%c; if(!(b&1)){ return (x%c+x%c)%c;}else return ((a%c + (x+x)%c))%c; }
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=muliplyfast(res,a,mod)%mod;a=muliplyfast(res,a,mod)%mod;}return res;}
ll modInverse(ll a, ll m){return powmod(a,m-2,m);}
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
//----------------constants-----------------------
const int MOD = (int) 1e9 + 7;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;

int main()
{
	ll city;
	cin >> city;
	ll minVal = 1e9+7;
	ll cur = 0;
	int cont = 0;
	For0(i, city){
		ll x;
		cin >> x;
		//if(x < 0) continue;
		ll val = abs(x - cur);
		//cout << (x-cur)<<endl;
		if( val < minVal){
			minVal = val;
			cont = 1;
			cur = x;
			//cout << minVal <<" "<<cur<<endl;
		}
		else if(val == minVal) {
			cont++;

		}else
		 	cur = max(x,cur);
		//cout << cur<<endl;

	}
	cout << minVal <<" "<<cont<<endl;
	return 0;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <cstdio>
#include <math.h>
#include <queue>
#include <deque>
#include <assert.h>
#include <stack>
#include <list>
#include <set>
#include <map>

using namespace std;

/****************************************************************\
|     		 _	   _	  _ _	  ___   _    _ ___				 |
|			|  \_/   |	 /  ||  ||   ) | |  | |	  )				 |
|			| |	   | | 	/ _ ||--||-- } | |__| |-- }				 |
|			|_|    |_| /	||  ||___) | ____ |___)				 |
|   	BANGLADESH UNIVERSITY OF BUSINESS & TECHNOLOGY(BUBT)	 |
|		 			Deptartment of  CSE							 |
|    uva:mahbub07||devskil: mahbub07||codefoces:MAHBUBUR_RAHMAN  |
|                mail:mahbubabid8@gmail.com				         |
\****************************************************************/

typedef long long ll;
typedef double ld;
typedef unsigned long long ull;
typedef  vector<int> vi;
typedef  vector<ll> vll;
typedef  vector<string> vs;
typedef  set<int> si;
typedef  set<string> ss;
typedef  map<int,int> mii;
typedef  map<ll,ll> mll;
typedef  map<string,int> msi;
typedef  map<char,int> mci;
//----------------defines-----------------------
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(),v.end()
#define ms(s, n) memset(s, n, sizeof(s))
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
#define For0(i,n) for(int i=0;i<(int)n;i++)
#define For1(i,n) for(int i=1;i<=(int)n;i++)
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define Case(no) printf("Case %d: ",++no)
#define pb(b) push_back(b)
#define mp make_pair
#define maxall(v) *max_element(all(v))
#define minall(v) *min_element(all(v))
#define sortArr(a,n) sort(a,a+n)
#define sortVec(a) sort(all(a))
#define endl '\n'
#define DIST(x1,y1, x2, y2) (((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)))
#define DIST3D(x1,x2, y1, y2, z1, z2) (((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)) + ((z1-z2)*(z1-z2)))
//----------------functions-----------------------
ll muliplyfast(ll a, ll b, ll c){ if(b==0) return 0;ll x = muliplyfast(a , b/2, c)%c; if(!(b&1)){ return (x%c+x%c)%c;}else return ((a%c + (x+x)%c))%c; }
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=muliplyfast(res,a,mod)%mod;a=muliplyfast(res,a,mod)%mod;}return res;}
ll modInverse(ll a, ll m){return powmod(a,m-2,m);}
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
//----------------constants-----------------------
const int MOD = (int) 1e9 + 7;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;

int main()
{
	ll city;
	cin >> city;
	ll minVal = 1e9+7;
	ll cur = 0;
	int cont = 1;
	vector<ll>v;
	For0(i, city){
		ll x;
		cin >> x;
		v.pb(x);

	}
	sortVec(v);
	int l = v.size();
	For0(i, l-1){
		cur = (abs(v[i+1] - v[i]));
		if(cur < minVal){
			minVal = cur;
			cont = 1;

		}else if(cur == minVal){
			cont++;
			//cout << cur << endl;
		}

	}
	cout << minVal <<" "<<cont<<endl;
	return 0;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <cstdio>
#include <math.h>
#include <queue>
#include <deque>
#include <assert.h>
#include <stack>
#include <list>
#include <set>
#include <map>

using namespace std;

/****************************************************************\
|     		 _	   _	  _ _	  ___   _    _ ___				 |
|			|  \_/   |	 /  ||  ||   ) | |  | |	  )				 |
|			| |	   | | 	/ _ ||--||-- } | |__| |-- }				 |
|			|_|    |_| /	||  ||___) | ____ |___)				 |
|   	BANGLADESH UNIVERSITY OF BUSINESS & TECHNOLOGY(BUBT)	 |
|		 			Deptartment of  CSE							 |
|    uva:mahbub07||devskil: mahbub07||codefoces:MAHBUBUR_RAHMAN  |
|                mail:mahbubabid8@gmail.com				         |
\****************************************************************/

typedef long long ll;
typedef double ld;
typedef unsigned long long ull;
typedef  vector<int> vi;
typedef  vector<ll> vll;
typedef  vector<string> vs;
typedef  set<int> si;
typedef  set<string> ss;
typedef  map<int,int> mii;
typedef  map<ll,ll> mll;
typedef  map<string,int> msi;
typedef  map<char,int> mci;
//----------------defines-----------------------
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(),v.end()
#define ms(s, n) memset(s, n, sizeof(s))
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
#define For0(i,n) for(int i=0;i<(int)n;i++)
#define For1(i,n) for(int i=1;i<=(int)n;i++)
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define Case(no) printf("Case %d: ",++no)
#define pb(b) push_back(b)
#define mp make_pair
#define maxall(v) *max_element(all(v))
#define minall(v) *min_element(all(v))
#define sortArr(a,n) sort(a,a+n)
#define sortVec(a) sort(all(a))
#define endl '\n'
#define DIST(x1,y1, x2, y2) (((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)))
#define DIST3D(x1,x2, y1, y2, z1, z2) (((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)) + ((z1-z2)*(z1-z2)))
//----------------functions-----------------------
ll muliplyfast(ll a, ll b, ll c){ if(b==0) return 0;ll x = muliplyfast(a , b/2, c)%c; if(!(b&1)){ return (x%c+x%c)%c;}else return ((a%c + (x+x)%c))%c; }
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=muliplyfast(res,a,mod)%mod;a=muliplyfast(res,a,mod)%mod;}return res;}
ll modInverse(ll a, ll m){return powmod(a,m-2,m);}
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
//----------------constants-----------------------
const int MOD = (int) 1e9 + 7;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;

int main()
{
	ll city;
	cin >> city;
	ll minVal = 1e9+7;
	ll cur = 0;
	int cont = 1;
	vector<ll>v;
	For0(i, city){
		ll x;
		cin >> x;
		v.pb(x);

	}
	sortVec(v);
	int l = v.size();
	For0(i, l-1){
		cur = ((v[i+1] - v[i]));
		if(cur < minVal ){
			minVal = cur;
			cont = 1;

		}else if(cur == minVal){
			cont++;
			//cout << cur << endl;
		}

	}
	cout << minVal <<" "<<cont<<endl;
	return 0;
}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <cstdio>
#include <math.h>
#include <queue>
#include <deque>
#include <assert.h>
#include <stack>
#include <list>
#include <set>
#include <map>

using namespace std;

/****************************************************************\
|     		 _	   _	  _ _	  ___   _    _ ___				 |
|			|  \_/   |	 /  ||  ||   ) | |  | |	  )				 |
|			| |	   | | 	/ _ ||--||-- } | |__| |-- }				 |
|			|_|    |_| /	||  ||___) | ____ |___)				 |
|   	BANGLADESH UNIVERSITY OF BUSINESS & TECHNOLOGY(BUBT)	 |
|		 			Deptartment of  CSE							 |
|    uva:mahbub07||devskil: mahbub07||codefoces:MAHBUBUR_RAHMAN  |
|                mail:mahbubabid8@gmail.com				         |
\****************************************************************/

typedef long long ll;
typedef double ld;
typedef unsigned long long ull;
typedef  vector<int> vi;
typedef  vector<ll> vll;
typedef  vector<string> vs;
typedef  set<int> si;
typedef  set<string> ss;
typedef  map<int,int> mii;
typedef  map<ll,ll> mll;
typedef  map<string,int> msi;
typedef  map<char,int> mci;
//----------------defines-----------------------
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(),v.end()
#define ms(s, n) memset(s, n, sizeof(s))
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
#define For0(i,n) for(int i=0;i<(int)n;i++)
#define For1(i,n) for(int i=1;i<=(int)n;i++)
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define Case(no) printf("Case %d: ",++no)
#define pb(b) push_back(b)
#define mp make_pair
#define maxall(v) *max_element(all(v))
#define minall(v) *min_element(all(v))
#define sortArr(a,n) sort(a,a+n)
#define sortVec(a) sort(all(a))
#define endl '\n'
#define DIST(x1,y1, x2, y2) (((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)))
#define DIST3D(x1,x2, y1, y2, z1, z2) (((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2)) + ((z1-z2)*(z1-z2)))
//----------------functions-----------------------
ll muliplyfast(ll a, ll b, ll c){ if(b==0) return 0;ll x = muliplyfast(a , b/2, c)%c; if(!(b&1)){ return (x%c+x%c)%c;}else return ((a%c + (x+x)%c))%c; }
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=muliplyfast(res,a,mod)%mod;a=muliplyfast(res,a,mod)%mod;}return res;}
ll modInverse(ll a, ll m){return powmod(a,m-2,m);}
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
//----------------constants-----------------------
const int MOD = (int) 1e9 + 7;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;

int main()
{
	ll city;
	cin >> city;
	ll minVal = 1e9;
	ll cur = 0;
	int cont = 0;
	For0(i, city){
		ll x;
		cin >> x;

		if(abs(cur-x) < minVal){
			minVal = abs(cur-x);
			cont = 1;
			cur =x;
		}
		if(abs(x-cur) == minVal) cont++;
	}
	cout << minVal <<" "<<cont<<endl;
	return 0;
}


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

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

int main() {
	int a, b, cont = 1, md = 0;
	vector <int> v;
	cin >> a;

	f(i,a){
		cin >> b;
		v.push_back(b);
	}

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

	if(v[v.size()-1] > 0) { reverse(v.begin(),v.end()); }

	md = abs(v[0]-v[1]);

	for(int i= 1;i<v.size();i++){
		if((i+1) < v.size()){
			if(abs(v[i]-v[i+1]) < md){
				break;
			}
			if(abs(v[i]-v[i+1]) == md){
				cont++;
			}
		}
	}

	cout << md << " " << cont;
	return 0;
}


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

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

int main() {
	int a, b, cont = 1, md = 0;
	vector <int> v;
	cin >> a;

	f(i,a){
		cin >> b;
		v.push_back(b);
	}
	sort(v.begin(),v.end());
	reverse(v.begin(),v.end());

	md = v[0]-v[1];

	for(int i= 1;i<v.size();i++){
		if((i+1) < v.size()){
			if(v[i]-v[i+1] < md){
				break;
			}
			if(v[i]-v[i+1] == md){
				cont++;
			}
		}

	}

	cout << md << " " << cont;
	return 0;
}


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

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

int main() {
	int a, b, cont = 0, md = 999999999;
	vector <int> v;
	cin >> a;

	f(i,a){
		cin >> b;
		v.push_back(b);
	}

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

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

	for(int i= 0;i<v.size();i++){
		if(abs(v[i]-v[i+1]) < md){
			md = abs(v[i]-v[i+1]);
		}
	}

	for(int i= 0;i<v.size();i++){
		if((i+1) < v.size()){
			if(abs(v[i]-v[i+1]) == md){
				cont++;
			}
		}

	}

	cout << md << " " << cont;
	return 0;
}


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

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

int main() {
	long a, b, cont = 0, md = 9999999999;
	vector <int> v;
	cin >> a;

	f(i,a){
		cin >> b;
		v.push_back(b);
	}

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

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

	for(int i= 0;i<v.size();i++){
		if((i+1) < v.size()){
			if(abs(v[i]-v[i+1]) < md){
				md = abs(v[i]-v[i+1]);
			}
		}

	}

	for(int i= 0;i<v.size();i++){
		if((i+1) < v.size()){
			if(abs(v[i]-v[i+1]) == md){
				cont++;
			}
		}

	}

	cout << md << " " << cont;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<time.h>
#include<climits>
#include<cmath>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<iomanip>
#include<set>

//#define IONAME "cttf"
//#define E_DEBUG
//#define TIMECOMP

int n,t,a[111000];

std::vector<int> vv[111000];
std::set<int> se[111000];
std::queue<int> q;

void dfs(int u,int pre){
    se[u].erase(pre);
    for (auto v:vv[u]){
        if (v!=pre){
            dfs(v,u);
        }
    }
}

void marota(){
    std::cin>>n;
    for (int i=1;i<n;i++){
        int u,v;
        std::cin>>u>>v;
        vv[u].push_back(v);
        vv[v].push_back(u);
        se[u].insert(v);
        se[v].insert(u);
    }
    for (int i=1;i<=n;i++){
        std::cin>>a[i];
    }
    dfs(1,1);
    int cur=0;
    std::set<int> tmp;
    for (int i=1;i<=n;i++){
        q.push(a[i]);
        if (se[cur].empty()){
            if (q.empty()) break;
            cur=q.front();
            tmp.clear();
            continue;
        }
        tmp.insert(a[i]);
        if (tmp.size()==se[cur].size()){
            if (tmp!=se[cur]){
                std::cout<<"No\n";
                return;
            }
            else se[cur].clear();
        }
    }
    std::cout<<"Yes\n";
}

int main(){
    #ifdef TIMECOMP
    clock_t tStart = clock();
    #endif
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout.tie(0);
    #if defined(IONAME)
    freopen(IONAME".INP","r",stdin);
    freopen(IONAME".OUT","w",stdout);
    #endif
    marota();
    #ifdef TIMECOMP
    printf("Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
    #endif
    return 0;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<time.h>
#include<climits>
#include<cmath>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<iomanip>
#include<set>

//#define IONAME "cttf"
//#define E_DEBUG
//#define TIMECOMP

int n,t,a[222000];

std::vector<int> vv[222000],se[222000];
std::queue<int> q;

void dfs(int u,int pre){
    for (auto v:vv[u]){
        if (v!=pre){
            se[u].push_back(v);
            dfs(v,u);
        }
    }
}

void marota(){
    std::cin>>n;
    for (int i=1;i<n;i++){
        int u,v;
        std::cin>>u>>v;
        vv[u].push_back(v);
        vv[v].push_back(u);
    }
    for (int i=1;i<=n;i++){
        std::cin>>a[i];
    }
    if (a[1]!=1) {
        std::cout<<"No\n";
        return;
    }
    dfs(1,1);
    int cur=1;
    std::vector<int> tmp;
    for (int i=2;i<=n;i++){
        q.push(a[i]);
        while (se[cur].empty()){
            if (q.empty()) break;
            cur=q.front();
            q.pop();
            tmp.clear();
        }
        if (a[i]!=cur) tmp.push_back(a[i]);
        if (tmp.size()==se[cur].size()){
            std::sort(tmp.begin(),tmp.end());
            std::sort(se[cur].begin(),se[cur].end());
            if (tmp!=se[cur]){
                std::cout<<"No\n";
                return;
            }
            else se[cur].clear();
        }
    }
    std::cout<<"Yes\n";
}

int main(){
    #ifdef TIMECOMP
    clock_t tStart = clock();
    #endif
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout.tie(0);
    #if defined(IONAME)
    freopen(IONAME".INP","r",stdin);
    freopen(IONAME".OUT","w",stdout);
    #endif
    marota();
    #ifdef TIMECOMP
    printf("Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
    #endif
    return 0;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<time.h>
#include<climits>
#include<cmath>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<iomanip>
#include<set>

//#define IONAME "cttf"
//#define E_DEBUG
//#define TIMECOMP

int n,t,a[111000];

std::vector<int> vv[111000];
std::set<int> se[111000];
std::queue<int> q;

void dfs(int u,int pre){
    se[u].erase(pre);
    for (auto v:vv[u]){
        if (v!=pre){
            dfs(v,u);
        }
    }
}

void marota(){
    std::cin>>n;
    for (int i=1;i<n;i++){
        int u,v;
        std::cin>>u>>v;
        vv[u].push_back(v);
        vv[v].push_back(u);
        se[u].insert(v);
        se[v].insert(u);
    }
    for (int i=1;i<=n;i++){
        std::cin>>a[i];
    }
    dfs(1,1);
    int cur=0;
    std::set<int> tmp;
    for (int i=1;i<=n;i++){
        q.push(a[i]);
        if (se[cur].empty()){
            if (q.empty()) break;
            cur=q.front();
            q.pop();
            tmp.clear();
            continue;
        }
        tmp.insert(a[i]);
        if (tmp.size()==se[cur].size()){
            if (tmp!=se[cur]){
                std::cout<<"No\n";
                return;
            }
            else se[cur].clear();
        }
    }
    std::cout<<"Yes\n";
}

int main(){
    #ifdef TIMECOMP
    clock_t tStart = clock();
    #endif
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout.tie(0);
    #if defined(IONAME)
    freopen(IONAME".INP","r",stdin);
    freopen(IONAME".OUT","w",stdout);
    #endif
    marota();
    #ifdef TIMECOMP
    printf("Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
    #endif
    return 0;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<time.h>
#include<climits>
#include<cmath>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<iomanip>
#include<set>

//#define IONAME "cttf"
//#define E_DEBUG
//#define TIMECOMP

int n,t,a[222000];

std::vector<int> vv[222000],se[222000];
std::queue<int> q;

void dfs(int u,int pre){
    for (auto v:vv[u]){
        if (v!=pre){
            se[u].push_back(v);
            dfs(v,u);
        }
    }
}

void marota(){
    std::cin>>n;
    for (int i=1;i<n;i++){
        int u,v;
        std::cin>>u>>v;
        vv[u].push_back(v);
        vv[v].push_back(u);
    }
    for (int i=1;i<=n;i++){
        std::cin>>a[i];
    }
    if (a[1]!=1) {
        std::cout<<"No\n";
        return;
    }
    dfs(1,1);
    int cur=1;
    std::vector<int> tmp;
    for (int i=2;i<=n;i++){
        q.push(a[i]);
        if (se[cur].empty()){
            if (q.empty()) break;
            cur=q.front();
            q.pop();
            tmp.clear();
        }
        if (a[i]!=cur) tmp.push_back(a[i]);
        if (tmp.size()==se[cur].size()){
            std::sort(tmp.begin(),tmp.end());
            std::sort(se[cur].begin(),se[cur].end());
            if (tmp!=se[cur]){
                std::cout<<"No\n";
                return;
            }
            else se[cur].clear();
        }
    }
    std::cout<<"Yes\n";
}

int main(){
    #ifdef TIMECOMP
    clock_t tStart = clock();
    #endif
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout.tie(0);
    #if defined(IONAME)
    freopen(IONAME".INP","r",stdin);
    freopen(IONAME".OUT","w",stdout);
    #endif
    marota();
    #ifdef TIMECOMP
    printf("Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
    #endif
    return 0;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<time.h>
#include<climits>
#include<cmath>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<iomanip>
#include<set>

//#define IONAME "cttf"
//#define E_DEBUG
//#define TIMECOMP

int n,t,a[222000];

std::vector<int> vv[222000],se[222000];
std::queue<int> q;

void dfs(int u,int pre){
    for (auto v:vv[u]){
        if (v!=pre){
            se[u].push_back(v);
            dfs(v,u);
        }
    }
}

void marota(){
    std::cin>>n;
    for (int i=1;i<n;i++){
        int u,v;
        std::cin>>u>>v;
        vv[u].push_back(v);
        vv[v].push_back(u);
    }
    for (int i=1;i<=n;i++){
        std::cin>>a[i];
    }
    dfs(1,1);
    int cur=0;
    std::vector<int> tmp;
    for (int i=1;i<=n;i++){
        q.push(a[i]);
        if (se[cur].empty()){
            if (q.empty()) break;
            cur=q.front();
            q.pop();
            tmp.clear();
        }
        if (a[i]!=cur) tmp.push_back(a[i]);
        if (tmp.size()==se[cur].size()){
            std::sort(tmp.begin(),tmp.end());
            std::sort(se[cur].begin(),se[cur].end());
            if (tmp!=se[cur]){
                std::cout<<"No\n";
                return;
            }
            else se[cur].clear();
        }
    }
    std::cout<<"Yes\n";
}

int main(){
    #ifdef TIMECOMP
    clock_t tStart = clock();
    #endif
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout.tie(0);
    #if defined(IONAME)
    freopen(IONAME".INP","r",stdin);
    freopen(IONAME".OUT","w",stdout);
    #endif
    marota();
    #ifdef TIMECOMP
    printf("Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
    #endif
    return 0;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<time.h>
#include<climits>
#include<cmath>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<iomanip>
#include<set>

//#define IONAME "cttf"
//#define E_DEBUG
//#define TIMECOMP

int n,t,a[222000];

std::vector<int> vv[222000];
std::set<int> se[222000];
std::queue<int> q;

void dfs(int u,int pre){
    se[u].erase(pre);
    for (auto v:vv[u]){
        if (v!=pre){
            dfs(v,u);
        }
    }
}

void marota(){
    std::cin>>n;
    for (int i=1;i<n;i++){
        int u,v;
        std::cin>>u>>v;
        vv[u].push_back(v);
        vv[v].push_back(u);
        se[u].insert(v);
        se[v].insert(u);
    }
    for (int i=1;i<=n;i++){
        std::cin>>a[i];
    }
    dfs(1,1);
    int cur=0;
    std::set<int> tmp;
    for (int i=1;i<=n;i++){
        q.push(a[i]);
        if (se[cur].empty()){
            if (q.empty()) break;
            cur=q.front();
            q.pop();
            tmp.clear();
        }
        if (a[i]!=cur) tmp.insert(a[i]);
        if (tmp.size()==se[cur].size()){
            if (tmp!=se[cur]){
                std::cout<<"No\n";
                return;
            }
            else se[cur].clear();
        }
    }
    std::cout<<"Yes\n";
}

int main(){
    #ifdef TIMECOMP
    clock_t tStart = clock();
    #endif
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout.tie(0);
    #if defined(IONAME)
    freopen(IONAME".INP","r",stdin);
    freopen(IONAME".OUT","w",stdout);
    #endif
    marota();
    #ifdef TIMECOMP
    printf("Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
    #endif
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,x,y;
    cin>>n;
    vector <vector<ll>> adj(n+1);
    vector <ll> deg(n+1,0),lev(n+1),par(n+1),vis(n+1,0);
    par[1]=1;
    for(ll i=1;i<n;i++)
    {
        cin>>x>>y;
        adj[x].push_back(y);
        adj[y].push_back(x);
        deg[x]++;
        deg[y]++;
    }
    queue <ll> q;
    q.push(1);
    lev[1]=1;
    while(!q.empty())
    {
        ll v=q.front();
        q.pop();
        vis[v]=1;
        for(ll j=0;j<adj[v].size();j++)
        {
            if(!vis[adj[v][j]])
            {
                lev[adj[v][j]]=lev[v]+1;
                par[adj[v][j]]=v;
                q.push(adj[v][j]);
            }
        }
    }
    vector <ll> a(n+1),arr1(n+1),arr2;
    for(ll i=1;i<=n;i++)
    {
        cin>>a[i];
        arr1[i]=lev[a[i]];
    }
    bool flag=true;
    for(ll i=2;i<=n;i++)
    {
        if(arr1[i]<arr1[i-1])
        flag=false;
    }
    arr2.push_back(par[a[1]]);
    for(ll i=1;i<=n;i++)
    {
        if(arr2[arr2.size()-1]!=par[a[i]])
        arr2.push_back(par[a[i]]);
    }
    for(ll i=1;i<=n;i++)
    {
        if(deg[a[i]]==1)
        arr2.push_back(a[i]);
    }
    if(arr2.size()==n)
    {
        for(ll i=1;i<=n;i++)
        {
            if(a[i]!=arr2[i-1])
            flag=false;
        }
    }
    else
    flag=false;
    if(flag)
    cout<<"YES\n";
    else
    cout<<"NO\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,x,y;
    cin>>n;
    vector <vector<ll>> adj(n+1);
    vector <ll> deg(n+1,0),lev(n+1),par(n+1),vis(n+1,0);
    par[1]=1;
    for(ll i=1;i<n;i++)
    {
        cin>>x>>y;
        adj[x].push_back(y);
        adj[y].push_back(x);
        deg[x]++;
        deg[y]++;
    }
    queue <ll> q;
    q.push(1);
    lev[1]=1;
    while(!q.empty())
    {
        ll v=q.front();
        q.pop();
        vis[v]=1;
        for(ll j=0;j<adj[v].size();j++)
        {
            if(!vis[adj[v][j]])
            {
                lev[adj[v][j]]=lev[v]+1;
                par[adj[v][j]]=v;
                q.push(adj[v][j]);
            }
        }
    }
    vector <ll> a(n+1),arr1(n+1),arr2;
    for(ll i=1;i<=n;i++)
    {
        cin>>a[i];
        arr1[i]=lev[a[i]];
    }
    bool flag=true;
    for(ll i=2;i<=n;i++)
    {
        if(arr1[i]<arr1[i-1])
        flag=false;
    }
    arr2.push_back(par[a[1]]);
    for(ll i=1;i<=n;i++)
    {
        if(arr2[arr2.size()-1]!=par[a[i]])
        arr2.push_back(par[a[i]]);
    }
    for(ll i=n;i>=n;i--)
    {
        if(deg[a[i]]==1 && a[i]!=arr2[arr2.size()-1])
        arr2.push_back(a[i]);
        else
        break;
    }
    if(arr2.size()==n)
    {
        for(ll i=1;i<=n;i++)
        {
            if(a[i]!=arr2[i-1])
            flag=false;
        }
    }
    else
    flag=false;
    if(flag)
    cout<<"YES\n";
    else
    cout<<"NO\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,x,y;
    cin>>n;
    vector <vector<ll>> adj(n+1);
    vector <ll> deg(n+1,0),lev(n+1),par(n+1),vis(n+1,0);
    for(ll i=1;i<n;i++)
    {
        cin>>x>>y;
        adj[x].push_back(y);
        adj[y].push_back(x);
        deg[x]++;
        deg[y]++;
    }
    queue <ll> q;
    q.push(1);
    lev[1]=1;
    par[1]=1;
    while(!q.empty())
    {
        ll v=q.front();
        q.pop();
        vis[v]=1;
        for(ll j=0;j<adj[v].size();j++)
        {
            if(!vis[adj[v][j]])
            {
                lev[adj[v][j]]=lev[v]+1;
                par[adj[v][j]]=v;
                q.push(adj[v][j]);
            }
        }
    }
    vector <ll> a(n+1),arr1(n+1),arr2;
    for(ll i=1;i<=n;i++)
    {
        cin>>a[i];
        arr1[i]=lev[a[i]];
    }
    bool flag=true;
    for(ll i=2;i<=n;i++)
    {
        if(arr1[i-1]>arr1[i])
        flag=false;
    }
    arr2.push_back(par[a[1]]);
    for(ll i=2;i<=n;i++)
    {
        if(arr2[arr2.size()-1]!=par[a[i]])
        arr2.push_back(par[a[i]]);
    }
    for(ll i=0;i<arr2.size();i++)
    {
        if(a[i+1]!=arr2[i])
        flag=false;
    }
    if(flag && a[1]==1)
    cout<<"YES\n";
    else
    cout<<"NO\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,x,y;
    cin>>n;
    vector <vector<ll>> adj(n+1);
    vector <ll> lev(n+1),par(n+1),vis(n+1,0);
    for(ll i=1;i<n;i++)
    {
        cin>>x>>y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    queue <ll> q;
    q.push(1);
    lev[1]=1;
    par[1]=1;
    while(!q.empty())
    {
        ll v=q.front();
        q.pop();
        vis[v]=1;
        for(ll j=0;j<adj[v].size();j++)
        {
            if(!vis[adj[v][j]])
            {
                lev[adj[v][j]]=lev[v]+1;
                par[adj[v][j]]=v;
                q.push(adj[v][j]);
            }
        }
    }
    vector <ll> a(n+1),arr;
    arr.push_back(0);
    for(ll i=1;i<=n;i++)
    cin>>a[i];
    bool flag=true;
    for(ll i=2;i<=n;i++)
    {
        if(lev[a[i]]<lev[a[i-1]])//level order traversal
        flag=false;
    }
    arr.push_back(par[a[1]]);
    for(ll i=2;i<=n;i++)
    {
        if(arr[arr.size()-1]!=par[a[i]])
        arr.push_back(par[a[i]]);
    }
    for(ll i=1;i<arr.size();i++)
    {
        if(a[i]!=arr[i])
        flag=false;
    }
    if(flag && a[1]==1)
    cout<<"Yes\n";
    else
    cout<<"No\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,x,y;
    cin>>n;
    vector <vector<ll>> adj(n+1);
    vector <ll> deg(n+1,0),lev(n+1),par(n+1),vis(n+1,0);
    par[1]=1;
    for(ll i=1;i<n;i++)
    {
        cin>>x>>y;
        adj[x].push_back(y);
        adj[y].push_back(x);
        deg[x]++;
        deg[y]++;
    }
    queue <ll> q;
    q.push(1);
    lev[1]=1;
    while(!q.empty())
    {
        ll v=q.front();
        q.pop();
        vis[v]=1;
        for(ll j=0;j<adj[v].size();j++)
        {
            if(!vis[adj[v][j]])
            {
                lev[adj[v][j]]=lev[v]+1;
                par[adj[v][j]]=v;
                q.push(adj[v][j]);
            }
        }
    }
    vector <ll> a(n+1),arr1(n+1),arr2;
    for(ll i=1;i<=n;i++)
    {
        cin>>a[i];
        arr1[i]=lev[a[i]];
    }
    bool flag=true;
    for(ll i=2;i<=n;i++)
    {
        if(arr1[i]<arr1[i-1])
        flag=false;
    }
    arr2.push_back(par[a[1]]);
    for(ll i=1;i<=n;i++)
    {
        if(arr2[arr2.size()-1]!=par[a[i]])
        arr2.push_back(par[a[i]]);
    }
    for(ll i=1;i<=n;i++)
    {
        if(deg[a[i]]==1 && a[i]!=1)
        arr2.push_back(a[i]);
    }
    if(arr2.size()==n)
    {
        for(ll i=1;i<=n;i++)
        {
            if(a[i]!=arr2[i-1])
            flag=false;
        }
    }
    else
    flag=false;
    if(flag)
    cout<<"YES\n";
    else
    cout<<"NO\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector <int> ans,vis(200007,0),inputorder(200007),relorder(200007),adj[200007];
bool cmp(int a,int b)
{
    return relorder[a]<relorder[b];
}
int main(void)
{
    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    int n,x,a,b,i,j;
    for(i=0;i<n-1;i++)
    {
        cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    for(int i=0;i<n;i++)
    {
        cin>>inputorder[i];
        relorder[inputorder[i]]=i;
    }
    for(int i=1;i<=n;i++)
    sort(adj[i].begin(),adj[i].end(),cmp);
    queue<int> q;
	q.push(1);
    while(!q.empty())
    {
		queue<int> temp;
		while(!q.empty())
		{
			int x=q.front();
			q.pop();
			ans.push_back(x);
			vis[x]=1;
			for(j=0;j<adj[x].size();j++)
			{
			    if(!vis[adj[x][j]])
				temp.push(adj[x][j]);
			}
		}
		q=temp;
	}
	string ans="Yes";
	for(int i=0;i<n;i++)
	{
	    if(ans[i]!=inputorder[i])
	    ans="No";
	}
	cout<<ans<<"\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,x,y;
    cin>>n;
    vector <vector<ll>> adj(n+1);
    vector <ll> lev(n+1),par(n+1),vis(n+1,0);
    for(ll i=1;i<n;i++)
    {
        cin>>x>>y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    queue <ll> q;
    q.push(1);
    lev[1]=1;
    par[1]=1;
    while(!q.empty())
    {
        ll v=q.front();
        q.pop();
        vis[v]=1;
        for(ll j=0;j<adj[v].size();j++)
        {
            if(!vis[adj[v][j]])
            {
                lev[adj[v][j]]=lev[v]+1;
                par[adj[v][j]]=v;
                q.push(adj[v][j]);
            }
        }
    }
    vector <ll> a(n+1),arr;
    arr.push_back(0);
    for(ll i=1;i<=n;i++)
    cin>>a[i];
    bool flag=true;
    for(ll i=2;i<=n;i++)
    {
        if(lev[a[i]]<lev[a[i-1]])//level order traversal
        flag=false;
    }
    arr.push_back(par[a[1]]);
    for(ll i=2;i<=n;i++)
    {
        if(arr[arr.size()-1]!=par[a[i]])
        arr.push_back(par[a[i]]);
    }
    for(ll i=1;i<arr2.size();i++)
    {
        if(a[i]!=arr2[i])
        flag=false;
    }
    if(flag && a[0]==1)
    cout<<"Yes\n";
    else
    cout<<"No\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,x,y;
    cin>>n;
    vector <vector<ll>> adj(n+1);
    vector <ll> deg(n+1,0),lev(n+1),par(n+1),vis(n+1,0);
    par[1]=0;
    for(ll i=1;i<n;i++)
    {
        cin>>x>>y;
        adj[x].push_back(y);
        adj[y].push_back(x);
        deg[x]++;
        deg[y]++;
    }
    queue <ll> q;
    q.push(1);
    lev[1]=1;
    while(!q.empty())
    {
        ll v=q.front();
        q.pop();
        vis[v]=1;
        for(ll j=0;j<adj[v].size();j++)
        {
            if(!vis[adj[v][j]])
            {
                lev[adj[v][j]]=lev[v]+1;
                par[adj[v][j]]=v;
                q.push(adj[v][j]);
            }
        }
    }
    vector <ll> a(n+1),arr1(n+1),arr2;
    for(ll i=1;i<=n;i++)
    {
        cin>>a[i];
        arr1[i]=lev[a[i]];
    }
    bool flag=true;
    for(ll i=2;i<=n;i++)
    {
        if(arr1[i]<arr1[i-1])
        flag=false;
    }
    arr2.push_back(par[a[2]]);
    for(ll i=2;i<=n;i++)
    {
        if(arr2[arr2.size()-1]!=par[a[i]])
        arr2.push_back(par[a[i]]);
    }
    for(ll i=1;i<=n;i++)
    {
        if(deg[a[i]]==1)
        arr2.push_back(a[i]);
    }
    if(arr2.size()==n)
    {
        for(ll i=1;i<=n;i++)
        {
            if(a[i]!=arr2[i-1])
            flag=false;
        }
    }
    else
    flag=false;
    if(flag)
    cout<<"YES\n";
    else
    cout<<"NO\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector <int> ans,vis(200007,0),inputorder(200007),relorder(200007),adj[200007];
bool cmp(int a,int b)
{
    return relorder[a]<relorder[b];
}
int main(void)
{
    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>n;
    int n,x,a,b,i,j;
    for(i=0;i<n-1;i++)
    {
        cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    for(int i=0;i<n;i++)
    {
        cin>>inputorder[i];
        relorder[inputorder[i]]=i;
    }
    for(int i=1;i<=n;i++)
    sort(adj[i].begin(),adj[i].end(),cmp);
    queue<int> q;
	q.push(1);
    while(!q.empty())
    {
		queue<int> temp;
		while(!q.empty())
		{
			int x=q.front();
			q.pop();
			ans.push_back(x);
			vis[x]=1;
			for(j=0;j<adj[x].size();j++)
			{
			    if(!vis[adj[x][j]])
				temp.push(adj[x][j]);
			}
		}
		q=temp;
	}
	string ans="Yes";
	for(int i=0;i<n;i++)
	{
	    if(ans[i]!=inputorder[i])
	    ans="No";
	}
	cout<<ans<<"\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,x,y;
    cin>>n;
    vector <vector<ll>> adj(n+1);
    vector <ll> lev(n+1),par(n+1),vis(n+1,0);
    for(ll i=1;i<n;i++)
    {
        cin>>x>>y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    queue <ll> q;
    q.push(1);
    lev[1]=1;
    par[1]=1;
    while(!q.empty())
    {
        ll v=q.front();
        q.pop();
        vis[v]=1;
        for(ll j=0;j<adj[v].size();j++)
        {
            if(!vis[adj[v][j]])
            {
                lev[adj[v][j]]=lev[v]+1;
                par[adj[v][j]]=v;
                q.push(adj[v][j]);
            }
        }
    }
    vector <ll> a(n+1),arr;
    arr.push_back(0);
    for(ll i=1;i<=n;i++)
    cin>>a[i];
    bool flag=true;
    for(ll i=2;i<=n;i++)
    {
        if(lev[a[i]]<lev[a[i-1]])//level order traversal
        flag=false;
    }
    arr.push_back(par[a[1]]);
    for(ll i=2;i<=n;i++)
    {
        if(arr[arr.size()-1]!=par[a[i]])
        arr.push_back(par[a[i]]);
    }
    for(ll i=1;i<arr.size();i++)
    {
        if(a[i]!=arr2[i])
        flag=false;
    }
    if(flag && a[0]==1)
    cout<<"Yes\n";
    else
    cout<<"No\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector <int> ans,vis(200007,0),inputorder(200007),relorder(200007),adj[200007];
bool cmp(int a,int b)
{
    return relorder[a]<relorder[b];
}
int main(void)
{
    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    int n,x,a,b,i,j;
    cin>>n;
    for(i=0;i<n-1;i++)
    {
        cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    for(int i=0;i<n;i++)
    {
        cin>>inputorder[i];
        relorder[inputorder[i]]=i;
    }
    for(int i=1;i<=n;i++)
    sort(adj[i].begin(),adj[i].end(),cmp);
    queue<int> q;
	q.push(1);
    while(!q.empty())
    {
		queue<int> temp;
		while(!q.empty())
		{
			int x=q.front();
			q.pop();
			ans.push_back(x);
			vis[x]=1;
			for(j=0;j<adj[x].size();j++)
			{
			    if(!vis[adj[x][j]])
				temp.push(adj[x][j]);
			}
		}
		q=temp;
	}
	string ans="Yes";
	for(int i=0;i<n;i++)
	{
	    if(ans[i]!=inputorder[i])
	    ans="No";
	}
	cout<<ans<<"\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector <int> ans,vis(200007,0),inputorder(200007),relorder(200007),adj[200007];
bool cmp(int a,int b)
{
    return relorder[a]<relorder[b];
}
int main(void)
{
    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    int n,x,a,b,i,j;
    for(i=0;i<n-1;i++)
    {
        cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    for(int i=0;i<n;i++)
    {
        cin>>inputorder[i];
        relorder[inputorder[i]]=i;
    }
    for(int i=1;i<=n;i++)
    sort(adj[i].begin(),adj[i].end(),cmp);
    queue<int> q;
	q.push(1);
    while(!q.empty())
    {
		queue<int> temp;
		while(!q.empty())
		{
			int x=q.front();
			q.pop();
			ans.pb(x);
			vis[x]=1;
			for(j=0;j<adj[x].size();j++)
			{
			    if(!vis[adj[x][j]])
				temp.push(adj[x][j]);
			}
		}
		q=temp;
	}
	string ans="Yes";
	for(int i=0;i<n;i++)
	{
	    if(ans[i]!=inputorder[i])
	    ans="No";
	}
	cout<<ans<<"\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector <int> ans,vis(200007,0),inputorder(200007),relorder(200007),adj[200007];
bool cmp(int a,int b)
{
    return relorder[a]<relorder[b];
}
int main(void)
{
    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    int n,x,a,b,i,j;
    cin>>n;
    for(i=0;i<n-1;i++)
    {
        cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    for(int i=0;i<n;i++)
    {
        cin>>inputorder[i];
        relorder[inputorder[i]]=i;
    }
    for(int i=1;i<=n;i++)
    sort(adj[i].begin(),adj[i].end(),cmp);
    queue<int> q;
	q.push(1);
    while(!q.empty())
    {
		queue<int> temp;
		while(!q.empty())
		{
			int x=q.front();
			q.pop();
			ans.push_back(x);
			vis[x]=1;
			for(j=0;j<adj[x].size();j++)
			{
			    if(!vis[adj[x][j]])
				temp.push(adj[x][j]);
			}
		}
		q=temp;
	}
	for(int i=0;i<n;i++)
	{
	    if(ans[i]!=inputorder[i])
	    {
	        cout<<"No\n";
	        return 0;
	    }
	}
	cout<<"Yes\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> graph[200001];
int par[200001];
void dfs(int v,  int p){
    par[v]=p;
    for(int i:graph[v]){
        if(i==p){
            continue;
        }
        dfs(i, v);
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    for(int i=0; i<n-1; i++){
        int x,y;
        cin>>x>>y;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }
    int deg[n+1];
    for(int i=1; i<=n; i++){
        deg[i] = graph[i].size();
    }
    dfs(1, -1);
    int a[n],b[n];
    for(int i=0; i<n; i++){
        cin>>a[i];
        b[i] = par[a[i]];
    }
    if(a[0]!=1){
        cout<<"No\n";
        return 0;
    }
    set<int> track;
    int curr = -1;
    for(int i=1; i<n; i++){
        if(b[i]==b[i-1]){
            continue;
        }
        track.insert(curr);
        if(track.find(b[i])!=track.end()){
            cout<<"No\n";
            return 0;
        }
        curr = b[i];
    }
    vector<int> track1, track2;
    track1.push_back(1);
    for(int i=1; i<n; i++){
        if(deg[a[i]]>1){
            track1.push_back(a[i]);
        }
    }
    int curr1 = b[1];
    for(int i=2; i<n; i++){
        if(b[i]==b[i-1]){
            continue;
        }
        track2.push_back(curr1);
        curr1 = b[i];
    }
    track2.push_back(curr1);
    if(track1==track2){
        cout<<"Yes\n";
    }else{
        cout<<"No\n";
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> graph[200001];
int par[200001];
int level[200001];
void dfs(int v,  int p, int lev){
    par[v]=p;
    level[v] = lev;
    for(int i:graph[v]){
        if(i==p){
            continue;
        }
        dfs(i, v, lev+1);
    }
}
bool check1(vector<int>& track1, vector<int>& track2){
    if(track1.size()!=track2.size()){
        return false;
    }
    for(int i=0; i<track1.size(); i++){
        if(track1[i]!= track2[i]){
        	//cout<<"here\n";
            return false;
        }
    }
    return true;
}
bool check2(vector<int> track){
    sort(track.begin(), track.end());
    for(int i=1; i<track.size(); i++){
        if(track[i]==track[i-1]){
            return false;
        }
    }
    return true;
}
bool check3(vector<int> & track){
    for(int i=1; i<track.size(); i++){
        if(track[i]<track[i-1]){
        	//cout<<"here\n";
            return false;
        }
        //return true;
    }
    return true;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    for(int i=0; i<n-1; i++){
        int x,y;
        cin>>x>>y;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }
    int deg[n+1];
    for(int i=1; i<=n; i++){
        deg[i] = graph[i].size();
    }
    dfs(1, -1, 0);
    int a[n],b[n];
    for(int i=0; i<n; i++){
        cin>>a[i];
        b[i] = par[a[i]];
    }
    if(a[0]!=1){
        cout<<"No\n";
        return 0;
    }
    if(n==1){
    	cout<<"Yes\n";
        return 0;
    }
    vector<int> track1, track2;
    track1.push_back(1);
    for(int i=1; i<n; i++){
        if(deg[a[i]]>1){
            track1.push_back(a[i]);
        }
    }
    int curr1 = b[1];
    for(int i=2; i<n; i++){
        if(b[i]==b[i-1]){
            continue;
        }
        track2.push_back(curr1);
        curr1 = b[i];
    }
    vector<int> track3(n);
    for(int i=0; i<n; i++){
        track3[i] = level[a[i]];
    }
    track2.push_back(curr1);
    if(check1(track1, track2)){
        cout<<"Yes\n";
    }else{
        cout<<"No\n";
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> graph[200001];
int par[200001];
void dfs(int v,  int p){
    par[v]=p;
    for(int i:graph[v]){
        if(i==p){
            continue;
        }
        dfs(i, v);
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    for(int i=0; i<n-1; i++){
        int x,y;
        cin>>x>>y;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }
    dfs(1, -1);
    int a[n],b[n];
    for(int i=0; i<n; i++){
        cin>>a[i];
        b[i] = par[a[i]];
    }
    if(a[0]!=1){
        cout<<"No\n";
        return 0;
    }
    set<int> track;
    int curr = -1;
    for(int i=1; i<n; i++){
        if(b[i]==b[i-1]){
            continue;
        }
        track.insert(curr);
        if(track.find(b[i])!=track.end()){
            cout<<"No\n";
            return 0;
        }
        curr = b[i];
    }
    set<int> track1;
    track1.insert(-1);
    for(int i=0; i<n; i++){
        if(track1.find(b[i])==track1.end()){
            cout<<"No\n";
            return 0;
        }
        track1.insert(a[i]);
    }
    cout<<"Yes\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> graph[200001];
int par[200001];
int level[200001];
void dfs(int v,  int p, int lev){
    par[v]=p;
    level[v] = lev;
    for(int i:graph[v]){
        if(i==p){
            continue;
        }
        dfs(i, v, lev+1);
    }
}
bool check1(vector<int>& track1, vector<int>& track2){
    if(track1.size()!=track2.size()){
        return false;
    }
    for(int i=0; i<track1.size(); i++){
        if(track1[i]!= track2[i]){
        	//cout<<"here\n";
            return false;
        }
    }
    return true;
}
bool check2(vector<int> track){
    sort(track.begin(), track.end());
    for(int i=1; i<track.size(); i++){
        if(track[i]==track[i-1]){
            return false;
        }
    }
    return true;
}
bool check3(vector<int> & track){
    for(int i=1; i<track.size(); i++){
        if(track[i]<track[i-1]){
        	//cout<<"here\n";
            return false;
        }
        //return true;
    }
    return true;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    for(int i=0; i<n-1; i++){
        int x,y;
        cin>>x>>y;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }
    int deg[n+1];
    for(int i=1; i<=n; i++){
        deg[i] = graph[i].size();
    }
    dfs(1, -1, 0);
    int a[n],b[n];
    for(int i=0; i<n; i++){
        cin>>a[i];
        b[i] = par[a[i]];
    }
    if(a[0]!=1){
        cout<<"No\n";
        return 0;
    }
    if(n==1){
    	cout<<"Yes\n";
        return 0;
    }
    vector<int> track1, track2;
    track1.push_back(1);
    for(int i=1; i<n; i++){
        if(deg[a[i]]>1){
            track1.push_back(a[i]);
        }
    }
    int curr1 = b[1];
    for(int i=2; i<n; i++){
        if(b[i]==b[i-1]){
            continue;
        }
        track2.push_back(curr1);
        curr1 = b[i];
    }
    vector<int> track3(n);
    for(int i=0; i<n; i++){
        track3[i] = level[a[i]];
    }
    track2.push_back(curr1);
    if(check1(track1, track2) && check2(track2) && check3(track3)){
        cout<<"Yes\n";
    }else{
        cout<<"No\n";
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> graph[200001];
int par[200001];
int level[200001];
void dfs(int v,  int p, int lev){
    par[v]=p;
    level[v] = lev;
    for(int i:graph[v]){
        if(i==p){
            continue;
        }
        dfs(i, v, lev+1);
    }
}
bool check1(vector<int>& track1, vector<int>& track2){
    if(track1.size()!=track2.size()){
        return false;
    }
    for(int i=0; i<track1.size(); i++){
        if(track1[i]!= track2[i]){
            return false;
        }
    }
    return true;
}
bool check2(vector<int> track){
    sort(track.begin(), track.end());
    for(int i=1; i<track.size(); i++){
        if(track[i]==track[i-1]){
            return false;
        }
    }
    return true;
}
bool check3(vector<int> & track){
    for(int i=1; i<track.size(); i++){
        if(track[i]<track[i-1]){
            return false;
        }
        return true;
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    for(int i=0; i<n-1; i++){
        int x,y;
        cin>>x>>y;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }
    int deg[n+1];
    for(int i=1; i<=n; i++){
        deg[i] = graph[i].size();
    }
    dfs(1, -1, 0);
    int a[n],b[n];
    for(int i=0; i<n; i++){
        cin>>a[i];
        b[i] = par[a[i]];
    }
    if(a[0]!=1){
        cout<<"No\n";
        return 0;
    }
    vector<int> track1, track2;
    track1.push_back(1);
    for(int i=1; i<n; i++){
        if(deg[a[i]]>1){
            track1.push_back(a[i]);
        }
    }
    int curr1 = b[1];
    for(int i=2; i<n; i++){
        if(b[i]==b[i-1]){
            continue;
        }
        track2.push_back(curr1);
        curr1 = b[i];
    }
    vector<int> track3(n);
    for(int i=0; i<n; i++){
        track3[i] = level[a[i]];
    }
    track2.push_back(curr1);
    if(check1(track1, track2) && check2(track2) && check3(track3)){
        cout<<"Yes\n";
    }else{
        cout<<"No\n";
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> graph[200001];
int par[200001];
void dfs(int v,  int p){
    par[v]=p;
    for(int i:graph[v]){
        if(i==p){
            continue;
        }
        dfs(i, v);
    }
}
bool check1(vector<int>& track1, vector<int>& track2){
    if(track1.size()!=track2.size()){
        return false;
    }
    for(int i=0; i<track1.size(); i++){
        if(track1[i]!= track2[i]){
            return false;
        }
    }
    return true;
}
bool check2(vector<int> track){
    sort(track.begin(), track.end());
    for(int i=1; i<track.size(); i++){
        if(track[i]==track[i-1]){
            return false;
        }
    }
    return true;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    for(int i=0; i<n-1; i++){
        int x,y;
        cin>>x>>y;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }
    int deg[n+1];
    for(int i=1; i<=n; i++){
        deg[i] = graph[i].size();
    }
    dfs(1, -1);
    int a[n],b[n];
    for(int i=0; i<n; i++){
        cin>>a[i];
        b[i] = par[a[i]];
    }
    if(a[0]!=1){
        cout<<"No\n";
        return 0;
    }
    vector<int> track1, track2;
    track1.push_back(1);
    for(int i=1; i<n; i++){
        if(deg[a[i]]>1){
            track1.push_back(a[i]);
        }
    }
    int curr1 = b[1];
    for(int i=2; i<n; i++){
        if(b[i]==b[i-1]){
            continue;
        }
        track2.push_back(curr1);
        curr1 = b[i];
    }
    track2.push_back(curr1);
    if(check1(track1, track2)){
        cout<<"Yes\n";
    }else{
        cout<<"No\n";
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> graph[200001];
int par[200001];
void dfs(int v,  int p){
    par[v]=p;
    for(int i:graph[v]){
        if(i==p){
            continue;
        }
        dfs(i, v);
    }
}
bool check1(vector<int>& track1, vector<int>& track2){
    if(track1.size()!=track2.size()){
        return false;
    }
    for(int i=0; i<track1.size(); i++){
        if(track1[i]!= track2[i]){
            return false;
        }
    }
    return true;
}
bool check2(vector<int> track){
    sort(track.begin(), track.end());
    for(int i=1; i<track.size(); i++){
        if(track[i]==track[i-1]){
            return false;
        }
    }
    return true;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    for(int i=0; i<n-1; i++){
        int x,y;
        cin>>x>>y;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }
    int deg[n+1];
    for(int i=1; i<=n; i++){
        deg[i] = graph[i].size();
    }
    dfs(1, -1);
    int a[n],b[n];
    for(int i=0; i<n; i++){
        cin>>a[i];
        b[i] = par[a[i]];
    }
    if(a[0]!=1){
        cout<<"No\n";
        return 0;
    }
    //set<int> track;
    //int curr = -1;
    //for(int i=1; i<n; i++){
    //    if(b[i]==b[i-1]){
    //        continue;
    //    }
    //    track.insert(curr);
    //    if(track.find(b[i])!=track.end()){
    //        cout<<"No\n";
    //        return 0;
    //    }
    //    curr = b[i];
    //}
    vector<int> track1, track2;
    track1.push_back(1);
    for(int i=1; i<n; i++){
        if(deg[a[i]]>1){
            track1.push_back(a[i]);
        }
    }
    int curr1 = b[1];
    for(int i=2; i<n; i++){
        if(b[i]==b[i-1]){
            continue;
        }
        track2.push_back(curr1);
        curr1 = b[i];
    }
    track2.push_back(curr1);
    if(check1(track1, track2)&&check2(track2)){
        cout<<"Yes\n";
    }else{
        cout<<"No\n";
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> graph[200001];
int par[200001];
void dfs(int v,  int p){
    par[v]=p;
    for(int i:graph[v]){
        if(i==p){
            continue;
        }
        dfs(i, v);
    }
}
bool check1(vector<int>& track1, vector<int>& track2){
    if(track1.size()!=track2.size()){
        return false;
    }
    for(int i=0; i<track1.size(); i++){
        if(track1[i]!= track2[i]){
            return false;
        }
    }
    return true;
}
bool check2(vector<int> track){
    sort(track.begin(), track.end());
    for(int i=1; i<track.size(); i++){
        if(track[i]==track[i-1]){
            return false;
        }
    }
    return true;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    for(int i=0; i<n-1; i++){
        int x,y;
        cin>>x>>y;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }
    int deg[n+1];
    for(int i=1; i<=n; i++){
        deg[i] = graph[i].size();
    }
    dfs(1, -1);
    int a[n],b[n];
    for(int i=0; i<n; i++){
        cin>>a[i];
        b[i] = par[a[i]];
    }
    if(a[0]!=1){
        cout<<"No\n";
        return 0;
    }
    set<int> track;
    int curr = -1;
    for(int i=1; i<n; i++){
        if(b[i]==b[i-1]){
            continue;
        }
        track.insert(curr);
        if(track.find(b[i])!=track.end()){
            cout<<"No\n";
            return 0;
        }
        curr = b[i];
    }
    vector<int> track1, track2;
    track1.push_back(1);
    for(int i=1; i<n; i++){
        if(deg[a[i]]>1){
            track1.push_back(a[i]);
        }
    }
    int curr1 = b[1];
    for(int i=2; i<n; i++){
        if(b[i]==b[i-1]){
            continue;
        }
        track2.push_back(curr1);
        curr1 = b[i];
    }
    track2.push_back(curr1);
    if(check1(track1, track2)&&check2(track2)){
        cout<<"Yes\n";
    }else{
        cout<<"No\n";
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> graph[200001];
int par[200001];
int level[200001];
void dfs(int v,  int p, int lev){
    par[v]=p;
    level[v] = lev;
    for(int i:graph[v]){
        if(i==p){
            continue;
        }
        dfs(i, v, lev+1);
    }
}
bool check1(vector<int>& track1, vector<int>& track2){
    if(track1.size()!=track2.size()){
        return false;
    }
    for(int i=0; i<track1.size(); i++){
        if(track1[i]!= track2[i]){
            return false;
        }
    }
    return true;
}
bool check2(vector<int> track){
    sort(track.begin(), track.end());
    for(int i=1; i<track.size(); i++){
        if(track[i]==track[i-1]){
            return false;
        }
    }
    return true;
}
bool check3(vector<int> & track){
    for(int i=1; i<track.size(); i++){
        if(track[i]<track[i-1]){
            return false;
        }
        //return true;
    }
    return true;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    for(int i=0; i<n-1; i++){
        int x,y;
        cin>>x>>y;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }
    int deg[n+1];
    for(int i=1; i<=n; i++){
        deg[i] = graph[i].size();
    }
    dfs(1, -1, 0);
    int a[n],b[n];
    for(int i=0; i<n; i++){
        cin>>a[i];
        b[i] = par[a[i]];
    }
    if(a[0]!=1){
        cout<<"No\n";
        return 0;
    }
    vector<int> track1, track2;
    track1.push_back(1);
    for(int i=1; i<n; i++){
        if(deg[a[i]]>1){
            track1.push_back(a[i]);
        }
    }
    int curr1 = b[1];
    for(int i=2; i<n; i++){
        if(b[i]==b[i-1]){
            continue;
        }
        track2.push_back(curr1);
        curr1 = b[i];
    }
    vector<int> track3(n);
    for(int i=0; i<n; i++){
        track3[i] = level[a[i]];
    }
    track2.push_back(curr1);
    if(check1(track1, track2) && check2(track2) && check3(track3)){
        cout<<"Yes\n";
    }else{
        cout<<"No\n";
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> graph[200001];
int par[200001];
int level[200001];
void dfs(int v,  int p, int lev){
    par[v]=p;
    level[v] = lev;
    for(int i:graph[v]){
        if(i==p){
            continue;
        }
        dfs(i, v, lev+1);
    }
}
bool check1(vector<int>& track1, vector<int>& track2){
    if(track1.size()!=track2.size()){
        return false;
    }
    for(int i=0; i<track1.size(); i++){
        if(track1[i]!= track2[i]){
            return false;
        }
    }
    return true;
}
bool check2(vector<int> track){
    sort(track.begin(), track.end());
    for(int i=1; i<track.size(); i++){
        if(track[i]==track[i-1]){
            return false;
        }
    }
    return true;
}
bool check3(vector<int> & track){
    for(int i=1; i<track.size(); i++){
        if(track[i]<track[i-1]){
            return false;
        }
        //return true;
    }
    return true;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    for(int i=0; i<n-1; i++){
        int x,y;
        cin>>x>>y;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }
    int deg[n+1];
    for(int i=1; i<=n; i++){
        deg[i] = graph[i].size();
    }
    dfs(1, -1, 0);
    int a[n],b[n];
    for(int i=0; i<n; i++){
        cin>>a[i];
        b[i] = par[a[i]];
    }
    if(a[0]!=1){
        cout<<"No\n";
        return 0;
    }
    vector<int> track1, track2;
    track1.push_back(1);
    for(int i=1; i<n; i++){
        if(deg[a[i]]>1){
            track1.push_back(a[i]);
        }
    }
    int curr1 = b[1];
    for(int i=2; i<n; i++){
        if(b[i]==b[i-1]){
            continue;
        }
        track2.push_back(curr1);
        curr1 = b[i];
    }
    track2.push_back(curr1);
    vector<int> track3(n);
    for(int i=0; i<n; i++){
        track3[i] = level[a[i]];
    }
    track2.push_back(curr1);
    if(check1(track1, track2) && check2(track2) && check3(track3)){
        cout<<"Yes\n";
    }else{
        cout<<"No\n";
    }
    return 0;
}


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

const int MAX = 1e6;
const int OO = 0x3f3f3f3f;
const long double EPS = 1e-6;
const long long MOD = 1000000000;

#define bug(x) cout << #x << " = " << x << '\n'
#define FOR(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mt make_tuple
#define all(vetor) vetor.begin(), vetor.end()
#define X real()
#define Y imag()
//#define gc getchar_unlocked

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef complex<ll> Pll;
typedef complex<ld> Pld;

int n;
vector<int> G[MAX];
int or_bfs[MAX];
int pai[MAX];
bool cor[MAX];

void dfs(int v, int p)
{
	pai[v] = p;
	for(int &u : G[v])
		if(u != p)
			dfs(u, v);
}

bool bfs(int v)
{
	queue<int> q;
	q.push(v);
	cor[v] = true;
	int idx = 1;
	while(!q.empty())
	{
		if(idx >= n) return true;
		int u = q.front();
		q.pop();
		int sz = G[u].size();
		REP(i, sz)
		{
			if(idx >= n) return true;
			int w = or_bfs[idx];
			idx++;
			if(cor[w]) continue;
			if(pai[w] != u)
				return false;
			q.push(w);
			cor[w] = true;
		}
	}
	return true;
}

int main()
{
	int u, v;

	scanf(" %d", &n);
	REP(i, n - 1)
	{
		scanf(" %d %d", &u, &v); u--; v--;
		G[u].pb(v);
		G[v].pb(u);
	}
	REP(i, n) scanf(" %d", &or_bfs[i]), or_bfs[i]--;

	if(or_bfs[0]) return puts("No"), 0;

	dfs(0, -1);
	bool fl = bfs(0);

	cout << (fl ? "Yes\n" : "No\n");

	return 0;
}