#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
#include<map>
using namespace std;

#define N	200100
#define pb	push_back
#define ppb	pop_back
#define Mod	1000000007

typedef long long LL;
int n, m, size[N], stra[N];
LL dp[N];
vector<int> nxt[N];
map<pair<int, int>, LL> mp;

LL cal(int a){
	if(a == 1) return 2;return (2LL*(n*n-n+2))%Mod;
}

bool col[N];
void dfs(int p, int pr = -1){
	col[p] = 1;size[p] =1;
	int i=0;
	while(i<nxt[p].size()){
		int to = nxt[p][i];
		if(to == pr){
			swap(nxt[p][i], nxt[p].back());
			nxt[p].ppb();
			continue;
		}
		if(!col[to]){
			dfs(to, p);
			size[p]+=size[to];
			i++;
		}
	}
	if(nxt[p].size() == 0) stra[p]=true;
	if(nxt[p].size() == 1 && stra[nxt[p][0]]==true) stra[p]=true;
	col[p] = 0;
}

LL solve();
LL solve(int p);
LL solve(int p1, int p2);

inline bool judge(int v){
	return stra[v];
}
LL solve(int p){
	if(dp[p]>=0) return dp[p];
	if(size[p]%2 == 1) return dp[p]=0;

	LL ans = 0LL;
	if(nxt[p].size() == 1){
		int pi=p, dep=0;
		while(nxt[pi].size() == 1)
			pi = nxt[pi][0],dep++;
		if(nxt[pi].size() == 0) return dp[p] = size[p]/2;
		int v, av, sav;
		for(int i=0; i<2; i++){
			v = nxt[pi][i], av = nxt[pi][1-i];
			sav = nxt[av].size();
			if(sav == 0 && !dep) ans = (ans+solve(v))%Mod;
			if(sav == 1) {
				if(!dep) ans = (ans + solve(v, nxt[av][0]))%Mod;
				else if(size[av] == dep+1 && judge(av)) ans = (ans +solve(v))%Mod;
			}
			if(sav == 2){
				int p1=nxt[av][0], p2=nxt[av][1];
				if(size[p1] == dep && judge(p1)) ans = (ans + solve(p2, v))%Mod;
				if(size[p2] == dep && judge(p2)) ans = (ans + solve(p1, v))%Mod;
			}
		}
		for(int i=0; i<2; i++){
			v = nxt[pi][i], av = nxt[pi][1-i];
			sav = nxt[av].size();
			if(sav == 0 && dep == 2) ans = (ans + solve(v))%Mod;
			if(sav == 1 && judge(av) && dep == size[av]+1) ans = (ans + solve(v))%Mod;
		}
		int next=nxt[p][0];
		if(nxt[next].size() == 1)
		ans =(ans + solve(nxt[next][0]))%Mod;
		return dp[p]=ans;
	}

	for(int i=0; i<2; i++){
		int v= nxt[p][i], av=nxt[p][1-i];
		if(nxt[av].size() == 0) ans = (ans + solve(v))%Mod;
		if(nxt[av].size() == 1) ans = (ans + solve(v, nxt[av][0]))%Mod;
	}
	return dp[p] = ans;
}
LL solve(int a, int b){
	if(nxt[a].size()>nxt[b].size())	swap(a,b);
	if(nxt[b].size() == 2) return 0LL;
	if(nxt[b].size() == 0) return 1LL;
	if(nxt[a].size() == 0) return solve(nxt[b][0]);
	return solve(nxt[a][0], nxt[b][0]);
}
LL solve(){
	int rot = -1;
	int cnt = 0;
	for(int i=0; i<m; i++){
		if(nxt[i].size() >= 4) return 0LL;
		if(nxt[i].size() == 3) rot = i, cnt++;
	}
	if(rot == -1) return cal(n);
	dfs(rot);
	LL ans = 0LL;
	int ord[] = {0, 1, 2};
	int l, mi ,r;
	do{
			l = nxt[rot][ord[0]], mi = nxt[rot][ord[1]], r = nxt[rot][ord[2]];
			int sim = nxt[mi].size();
			if(sim == 0) ans = (ans + (solve(l) * solve(r)%Mod)) %Mod;
			if(sim == 1) {
				ans = (ans + (solve(l) * solve(r, nxt[mi][0]))%Mod)%Mod;
				ans = (ans + (solve(r) * solve(l, nxt[mi][0]))%Mod)%Mod;
			}
			if(sim == 2) {
				int sm1 = nxt[mi][0], sm2 = nxt[mi][1];
				ans = (ans + (solve(l, sm1) * solve(r, sm2))%Mod)%Mod;
				ans = (ans + (solve(r, sm1) * solve(l, sm2))%Mod)%Mod;
			}
	}while(next_permutation(ord, ord+3));
	return (2LL*ans)%Mod;
}
int main()
{
	scanf("%d", &n);
	m = 2*n;
	for(int i=0; i<m+10; i++)dp[i]=-1, stra[i] = 0;
	for(int i = 0; i<m-1; i++){
		int ad1 , ad2;
		scanf("%d%d", &ad1, &ad2); 	ad1--, ad2--;
		nxt[ad1].pb(ad2), nxt[ad2].pb(ad1);
	}

	LL ans = solve();

	cout<<ans<<endl;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
#include<map>
using namespace std;

#define N	200100
#define pb	push_back
#define ppb	pop_back
#define Mod	1000000007

typedef long long LL;
int n, m, size[N], stra[N];
LL dp[N];
vector<int> nxt[N];
map<pair<int, int>, LL> mp;

LL cal(int a){
	if(a == 1) return 2;return (2LL*(n*n-n+2))%Mod;
}

bool col[N];
void dfs(int p, int pr = -1){
	col[p] = 1;size[p] =1;
	int i=0;
	while(i<nxt[p].size()){
		int to = nxt[p][i];
		if(to == pr){
			swap(nxt[p][i], nxt[p].back());
			nxt[p].ppb();
			continue;
		}
		if(!col[to]){
			dfs(to, p);
			size[p]+=size[to];
			i++;
		}
	}col[p] = 0;
}

LL solve();
LL solve(int p);
LL solve(int p1, int p2);

inline bool judge(int v){
	if(stra[v]!=2) return stra[v];
	int pi=v, dep=0;
	while(nxt[pi].size() == 1)
		pi = nxt[pi][0], dep++;
///	if(nxt[pi].size() == 0) return stra[v]=true;
	bool ok=false;
	if(nxt[pi].size() ==0) ok = true;
	int i = v;
	while(i!=pi){
		stra[i]=ok;
		i=nxt[i][0];
	}stra[pi]=ok;
	return stra[v]=ok;
}
LL solve(int p){
	if(dp[p]>=0) return dp[p];
	if(size[p]%2 == 1) return dp[p]=0;

	LL ans = 0LL;
	if(nxt[p].size() == 1){
		int pi=p, dep=0;
		while(nxt[pi].size() == 1)
			pi = nxt[pi][0],dep++;
		if(nxt[pi].size() == 0) return dp[p] = size[p]/2;
		int v, av, sav;
		for(int i=0; i<2; i++){
			v = nxt[pi][i], av = nxt[pi][1-i];
			sav = nxt[av].size();
			if(sav == 0 && !dep) ans = (ans+solve(v))%Mod;
			if(sav == 1) {
				if(!dep) ans = (ans + solve(v, nxt[av][0]))%Mod;
				else if(size[av] == dep+1 && judge(av)) ans = (ans +solve(v))%Mod;
			}
			if(sav == 2){
				int p1=nxt[av][0], p2=nxt[av][1];
				if(size[p1] == dep && judge(p1)) ans = (ans + solve(p2, v))%Mod;
				if(size[p2] == dep && judge(p2)) ans = (ans + solve(p1, v))%Mod;
			}
		}
		for(int i=0; i<2; i++){
			v = nxt[pi][i], av = nxt[pi][1-i];
			sav = nxt[av].size();
			if(sav == 0 && dep == 2) ans = (ans + solve(v))%Mod;
			if(sav == 1 && judge(av) && dep == size[av]+1) ans = (ans + solve(v))%Mod;
		}
		int next=nxt[p][0];
		if(nxt[next].size() == 1)
		ans =(ans + solve(nxt[next][0]))%Mod;
		return dp[p]=ans;
	}

	for(int i=0; i<2; i++){
		int v= nxt[p][i], av=nxt[p][1-i];
		if(nxt[av].size() == 0) ans = (ans + solve(v))%Mod;
		if(nxt[av].size() == 1) ans = (ans + solve(v, nxt[av][0]))%Mod;
	}
	return dp[p] = ans;
}
LL solve(int a, int b){
	if(nxt[a].size()>nxt[b].size())	swap(a,b);
	pair<int, int> pp = make_pair(a, b);
	if(mp.find(pp)!=mp.end()) return mp[pp];
	if(nxt[b].size() == 2) return 0LL;
	if(nxt[b].size() == 0) return 1LL;
	if(nxt[a].size() == 0) return solve(nxt[b][0]);
	return mp[pp]=solve(nxt[a][0], nxt[b][0]);
}
LL solve(){
	int rot = -1;
	int cnt = 0;
	for(int i=0; i<m; i++){
		if(nxt[i].size() >= 4) return 0LL;
		if(nxt[i].size() == 3) rot = i, cnt++;
	}
	if(rot == -1) return cal(n);
	dfs(rot);
	LL ans = 0LL;
	int ord[] = {0, 1, 2};
	int l, mi ,r;
	do{
			l = nxt[rot][ord[0]], mi = nxt[rot][ord[1]], r = nxt[rot][ord[2]];
			int sim = nxt[mi].size();
			if(sim == 0) ans = (ans + (solve(l) * solve(r)%Mod)) %Mod;
			if(sim == 1) {
				ans = (ans + (solve(l) * solve(r, nxt[mi][0]))%Mod)%Mod;
				ans = (ans + (solve(r) * solve(l, nxt[mi][0]))%Mod)%Mod;
			}
			if(sim == 2) {
				int sm1 = nxt[mi][0], sm2 = nxt[mi][1];
				ans = (ans + (solve(l, sm1) * solve(r, sm2))%Mod)%Mod;
				ans = (ans + (solve(r, sm1) * solve(l, sm2))%Mod)%Mod;
			}
	}while(next_permutation(ord, ord+3));
	return (2LL*ans)%Mod;
}
int main()
{
	scanf("%d", &n);
	m = 2*n;
	for(int i=0; i<m+10; i++)dp[i]=-1, stra[i] = 2;
	for(int i = 0; i<m-1; i++){
		int ad1 , ad2;
		scanf("%d%d", &ad1, &ad2); 	ad1--, ad2--;
		nxt[ad1].pb(ad2), nxt[ad2].pb(ad1);
	}

	LL ans = solve();

	cout<<ans<<endl;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
#include<map>
using namespace std;

#define N	200100
#define pb	push_back
#define ppb	pop_back
#define Mod	1000000007

typedef long long LL;
int n, m, size[N], stra[N];
long long dp[N];
vector<int> nxt[N];
map<pair<int, int>, long long> mp;

LL cal(int a){
	if(a == 1) return 2;return (2*(n*n-n+2))%Mod;
}

bool col[N];
void dfs(int p, int pr = -1){
	col[p] = 1;size[p] =1;
	int i=0;
	while(i<nxt[p].size()){
		int to = nxt[p][i];
		if(to == pr){
			swap(nxt[p][i], nxt[p].back());
			nxt[p].ppb();
			continue;
		}
		if(!col[to]){
			dfs(to, p);
			size[p]+=size[to];
			i++;
		}
	}col[p] = 0;
}

LL solve();
LL solve(int p);
LL solve(int p1, int p2);

bool judge(int v){
	if(stra[v]!=2) return stra[v];
	int pi=v, dep=0;
	while(nxt[pi].size() == 1)
		pi = nxt[pi][0], dep++;
	if(nxt[pi].size() == 0) return stra[v]=true;
	return stra[v]=false;
}
LL solve(int p){
	if(dp[p]>=0) return dp[p];
	if(size[p]%2 == 1) return dp[p]=0;

	LL ans = 0LL;
	if(nxt[p].size() == 1){
		int pi=p, dep=0;
		while(nxt[pi].size() == 1)
			pi = nxt[pi][0],dep++;
		if(nxt[pi].size() == 0) return dp[p] = size[p]/2;
		int v, av, sav;
		for(int i=0; i<2; i++){
			v = nxt[pi][i], av = nxt[pi][1-i];
			sav = nxt[av].size();
			if(sav == 0 && !dep) ans = (ans+solve(v))%Mod;
			if(sav == 1) {
				if(!dep) ans = (ans + solve(v, nxt[av][0]))%Mod;
				else if(size[av] == dep+1 && judge(av)) ans = (ans +solve(v))%Mod;
			}
			if(sav == 2){
				int p1=nxt[av][0], p2=nxt[av][1];
				if(size[p1] == dep && judge(p1)) ans = (ans + solve(p2, v))%Mod;
				if(size[p2] == dep && judge(p2)) ans = (ans + solve(p1, v))%Mod;
			}
		}
		for(int i=0; i<2; i++){
			v = nxt[pi][i], av = nxt[pi][1-i];
			sav = nxt[av].size();
			if(sav == 0 && dep == 2) ans = (ans + solve(v))%Mod;
			if(sav == 1 && judge(av) && dep == size[av]+1) ans = (ans + solve(v))%Mod;
		}
		int next=nxt[p][0];
		if(nxt[next].size() == 1)
		ans =(ans + solve(nxt[next][0]))%Mod;
		return dp[p]=ans;
	}

	for(int i=0; i<2; i++){
		int v= nxt[p][i], av=nxt[p][1-i];
		if(nxt[av].size() == 0) ans = (ans + solve(v))%Mod;
		if(nxt[av].size() == 1) ans = (ans + solve(v, nxt[av][0]))%Mod;
	}
	return dp[p] = ans;
}
LL solve(int a, int b){
	if(nxt[a].size()>nxt[b].size())	swap(a,b);
	pair<int, int> pp = make_pair(a, b);
	if(mp.find(pp)!=mp.end()) return mp[pp];
	if(nxt[b].size() == 2) return 0LL;
	if(nxt[b].size() == 0) return 1LL;
	if(nxt[a].size() == 0) return solve(nxt[b][0]);
	return mp[pp]=solve(nxt[a][0], nxt[b][0]);
}
LL solve(){
	int rot = -1;
	int cnt = 0;
	for(int i=0; i<m; i++){
		if(nxt[i].size() >= 4) return 0LL;
		if(nxt[i].size() == 3) rot = i, cnt++;
	}
	if(rot == -1) return cal(n);
	dfs(rot);
	LL ans = 0LL;
	int ord[] = {0, 1, 2};
	int l, mi ,r;
	do{
			l = nxt[rot][ord[0]], mi = nxt[rot][ord[1]], r = nxt[rot][ord[2]];
			int sim = nxt[mi].size();
			if(sim == 0) ans = (ans + solve(l) * solve(r)) %Mod;
			if(sim == 1) {
				ans = (ans + solve(l) * solve(r, nxt[mi][0]))%Mod;
				ans = (ans + solve(r) * solve(l, nxt[mi][0]))%Mod;
			}
			if(sim == 2) {
				int sm1 = nxt[mi][0], sm2 = nxt[mi][1];
				ans = (ans + solve(l, sm1) * solve(r, sm2))%Mod;
				ans = (ans + solve(r, sm1) * solve(l, sm2))%Mod;
			}
	}while(next_permutation(ord, ord+3));
	return (2*ans)%Mod;
}
int main()
{
//	freopen("in.txt", "r" ,stdin);
//	freopen("out.txt", "w", stdout);
	cin>>n;m = 2*n;
	for(int i=0; i<m+10; i++)dp[i]=-1, stra[i] = 2;
	for(int i = 0; i<m-1; i++){
		int ad1 , ad2;
		cin>>ad1>>ad2; 	ad1--, ad2--;
		nxt[ad1].pb(ad2), nxt[ad2].pb(ad1);
	}

	LL ans = solve();
//	cout<<solve(5)<<endl;
//	cout<<solve(4)<<endl;
	cout<<ans<<endl;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
#include<map>
using namespace std;

#define N	200100
#define pb	push_back
#define ppb	pop_back
#define Mod	1000000007

typedef long long LL;
int n, m, size[N];
long long dp[N];
vector<int> nxt[N];
map<pair<int, int>, long long> mp;

LL cal(int a){
	if(a == 1) return 2;return (2*(n*n-n+2))%Mod;
}

bool col[N];
void dfs(int p, int pr = -1){
	col[p] = 1;size[p] =1;
	int i=0;
	while(i<nxt[p].size()){
		int to = nxt[p][i];
		if(to == pr){
			swap(nxt[p][i], nxt[p].back());
			nxt[p].ppb();
			continue;
		}
		if(!col[to]){
			dfs(to, p);
			size[p]+=size[to];
			i++;
		}
	}col[p] = 0;
}

LL solve();
LL solve(int p);
LL solve(int p1, int p2);

bool judge(int v){
	int pi=v, dep=0;
	while(nxt[pi].size() == 1)
		pi = nxt[pi][0], dep++;
	if(nxt[pi].size() == 0) return true;
	return false;
}
LL solve(int p){
	if(dp[p]>=0) return dp[p];
	if(size[p]%2 == 1) return dp[p]=0;
	int pi=p, dep=0;
	while(nxt[pi].size() == 1)
		pi = nxt[pi][0],dep++;
//	cout<<pi<<' '<<dep<<' '<<nxt[pi].size()<<' '<<size[p]<<endl;
	if(nxt[pi].size() == 0) return dp[p] = size[p]/2;
	int v, av, sav;
	LL ans = 0LL;
	for(int i=0; i<2; i++){
		v = nxt[pi][i], av = nxt[pi][1-i];
		sav = nxt[av].size();
		if(sav == 0 && !dep) ans = (ans+solve(v))%Mod;
		if(sav == 1) {
			if(!dep) ans = (ans + solve(v, nxt[av][0]))%Mod;
			else if(size[av] == dep+1 && judge(av)) ans = (ans +solve(v))%Mod;
		}
		if(sav == 2){
			int p1=nxt[av][0], p2=nxt[av][1];
			if(size[p1] == dep && judge(p1)) ans = (ans + solve(p2, v))%Mod;
			if(size[p2] == dep && judge(p2)) ans = (ans + solve(p1, v))%Mod;
		}
	}
	if(pi!=p){
		int next=nxt[p][0];
		if(nxt[next].size() == 1)
			ans =(ans + solve(nxt[next][0]))%Mod;
	}
	return dp[p]=ans;
}
LL solve(int a, int b){
	if(nxt[a].size()>nxt[b].size())	swap(a,b);
	pair<int, int> pp = make_pair(a, b);
	if(mp.find(pp)!=mp.end()) return mp[pp];
	if(nxt[b].size() == 2) return 0LL;
	if(nxt[b].size() == 0) return 1LL;
	if(nxt[a].size() == 0) return solve(nxt[b][0]);
	return mp[pp]=solve(nxt[a][0], nxt[b][0]);
}
LL solve(){
	int rot = -1;
	for(int i=0; i<m; i++){
		if(nxt[i].size() >= 4) return 0LL;
		if(nxt[i].size() == 3) rot = i;
	}
	if(rot == -1) return cal(n);
	dfs(rot);
	int ans = 0LL;
	int ord[] = {0, 1, 2};
	int l, mi ,r;
	do{
			l = nxt[rot][ord[0]], mi = nxt[rot][ord[1]], r = nxt[rot][ord[2]];
			int sim = nxt[mi].size();
			if(sim == 0) ans = (ans + solve(l) * solve(r)) %Mod;
			if(sim == 1) {
				ans = (ans + solve(l) * solve(r, nxt[mi][0]))%Mod;
				ans = (ans + solve(r) * solve(l, nxt[mi][0]))%Mod;
			}
			if(sim == 2) {
				int sm1 = nxt[mi][0], sm2 = nxt[mi][1];
				ans = (ans + solve(l, sm1) * solve(r, sm2))%Mod;
				ans = (ans + solve(r, sm1) * solve(l, sm2))%Mod;
			}
			if(n == 1000){
				cout<<l<<' '<<mi<<' '<<r<<' '<<nxt[mi].size()<<' '<<solve(l)<<' '<<solve(r)<<' '<<ans<<endl;
			}
	}while(next_permutation(ord, ord+3));
	return (2*ans)%Mod;
}
int main()
{
	cin>>n;m = 2*n;
	for(int i=0; i<m+10; i++)dp[i]=-1;
	for(int i = 0; i<m-1; i++){
		int ad1 , ad2;
		cin>>ad1>>ad2; 	ad1--, ad2--;
		nxt[ad1].pb(ad2), nxt[ad2].pb(ad1);
	}

	LL ans = solve();
	cout<<ans<<endl;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
#include<map>
using namespace std;

#define N	200100
#define pb	push_back
#define ppb	pop_back
#define Mod	1000000007

bool test = false;
typedef long long LL;
int n, m, size[N], stra[N];
LL dp[N];
vector<int> nxt[N];

LL cal(int a){
	if(a == 1) return 2;return (2LL*(n*n-n+2))%Mod;
}

bool col[N];
void dfs(int p, int pr = -1){
	col[p] = 1;size[p] =1;
	int i=0;
	while(i<nxt[p].size()){
		int to = nxt[p][i];
		if(to == pr){
			swap(nxt[p][i], nxt[p].back());
			nxt[p].ppb();
			continue;
		}
		if(!col[to]){
			dfs(to, p);
			size[p]+=size[to];
			i++;
		}
	}
	if(nxt[p].size() == 0) stra[p]=true;
	if(nxt[p].size() == 1 && stra[nxt[p][0]]==true) stra[p]=true;
	col[p] = 0;
}

LL solve();
LL solve(int p);
LL solve(int p1, int p2);

inline bool judge(int v){
	return stra[v];
}
LL solve(int p){
	if(dp[p]>=0) return dp[p];
	if(size[p]%2 == 1) return dp[p]=0;

	LL ans = 0LL;
	if(nxt[p].size() == 1){
		int pi=p, dep=0;
		while(nxt[pi].size() == 1)
			pi = nxt[pi][0],dep++;
		if(nxt[pi].size() == 0) return dp[p] = size[p]/2;
		int v, av, sav;
		for(int i=0; i<2; i++){
			v = nxt[pi][i], av = nxt[pi][1-i];
			sav = nxt[av].size();
			if(sav == 0 && !dep) ans = (ans+solve(v))%Mod;
			if(sav == 1) {
				if(!dep) ans = (ans + solve(v, nxt[av][0]))%Mod;
				else if(size[av] == dep+1 && judge(av)) ans = (ans +solve(v))%Mod;
			}
			if(sav == 2){
				int p1=nxt[av][0], p2=nxt[av][1];
				if(size[p1] == dep && judge(p1)) ans = (ans + solve(p2, v))%Mod;
				if(size[p2] == dep && judge(p2)) ans = (ans + solve(p1, v))%Mod;
			}
		}
		for(int i=0; i<2; i++){
			v = nxt[pi][i], av = nxt[pi][1-i];
			sav = nxt[av].size();
			if(sav == 0 && dep == 2) ans = (ans + solve(v))%Mod;
			if(sav == 1 && judge(av) && dep == size[av]+1) ans = (ans + solve(v))%Mod;
		}
		int next=nxt[p][0];
		if(nxt[next].size() == 1)
		ans =(ans + solve(nxt[next][0]))%Mod;
		return dp[p]=ans;
	}

	for(int i=0; i<2; i++){
		int v= nxt[p][i], av=nxt[p][1-i];
		if(nxt[av].size() == 0) ans = (ans + solve(v))%Mod;
		if(nxt[av].size() == 1) ans = (ans + solve(v, nxt[av][0]))%Mod;
	}
	return dp[p] = ans;
}
LL solve(int a, int b){
	if(nxt[a].size()>nxt[b].size())	swap(a,b);
	if(nxt[b].size() == 2) return 0LL;
	if(nxt[b].size() == 0) return 1LL;
	if(nxt[a].size() == 0) return solve(nxt[b][0]);
	return solve(nxt[a][0], nxt[b][0]);
}
LL solve(){
	int rot = -1;
	int cnt = 0;
	for(int i=0; i<m; i++){
		if(nxt[i].size() >= 4) return 0LL;
		if(nxt[i].size() == 3) rot = i, cnt++;
	}
	if(rot == -1) return cal(n);
	if(test)cout<<cnt<<endl;
	dfs(rot);
	LL ans = 0LL;
	int ord[] = {0, 1, 2};
	int l, mi ,r;
	do{
			l = nxt[rot][ord[0]], mi = nxt[rot][ord[1]], r = nxt[rot][ord[2]];
			int sim = nxt[mi].size();
			if(sim == 0) ans = (ans + solve(l) * solve(r)) %Mod;
			if(sim == 1) {
				ans = (ans + solve(l) * solve(r, nxt[mi][0]))%Mod;
				ans = (ans + solve(r) * solve(l, nxt[mi][0]))%Mod;
			}
			if(sim == 2) {
				int sm1 = nxt[mi][0], sm2 = nxt[mi][1];
				ans = (ans + solve(l, sm1) * solve(r, sm2))%Mod;
				ans = (ans + solve(r, sm1) * solve(l, sm2))%Mod;
			}
	}while(next_permutation(ord, ord+3));
	return (2LL*ans)%Mod;
}
int main()
{
	scanf("%d", &n);
	m = 2*n;
	for(int i=0; i<m+10; i++)dp[i]=-1, stra[i] = 0;
	for(int i = 0; i<m-1; i++){
		int ad1 , ad2;
		if(n == 100000 && i==0 && ad1==132495)test = true;
		scanf("%d%d", &ad1, &ad2); 	ad1--, ad2--;
		nxt[ad1].pb(ad2), nxt[ad2].pb(ad1);
	}

	LL ans = solve();

	cout<<ans<<endl;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;

#define N	200100
#define Mod	1000000007
#define pb	push_back
#define ppb	pop_back

typedef long long LL;
vector<int> nxt[N];
int size[N], n, m;

inline LL	cal(int a){
	if(a == 1) return 2;return ((n*n-n+2)*2)%Mod;
}
bool col[N];
void dfs(int v, int pr=-1){
	col[v] = 1;
	size[v] = 1;
	int i =0;
	while(i<nxt[v].size()){
		int to = nxt[v][i];
		if(to == pr){
			swap(nxt[v][i], nxt[v].back());
			nxt[v].ppb();
			continue;
		}
		if(!col[to]){
			dfs(to, v);
			size[v]+=size[to];
			i++;
		}
	}
	col[v] = 0;
}
bool judge(int v){
	int pi=v, dep=0;
	while(nxt[pi].size() == 1)pi = nxt[pi][0], dep++;
	if(nxt[pi].size() == 0) return true;
	return false;
}
LL solve(int p);//
LL solve(int p1, int p2);//

LL solve(int p){
	if(size[p]&1) return 0;

	int pi=p, dep=0;
	while(nxt[pi].size() == 1)
		pi = nxt[pi][0], dep++;
	int s = nxt[pi].size();
	if(s == 0) return size[p]/2;
	LL ans = 0LL;
	int v, av, sav;
	for(int i=0; i<2; i++){
		v = nxt[pi][i], av=nxt[pi][i^1];
		sav = nxt[av].size();
		if(sav == 0){
			if(!dep) ans = (ans + solve(v))%Mod;
		}else if(sav == 1){
			if(!dep) ans = (ans + solve(nxt[av][0], v))%Mod;
			else if(size[av] == dep+1) ans = (ans + solve(v))%Mod;
		}else if(sav == 2){
			int sav1=nxt[av][0], sav2 = nxt[av][1];
			if(size[sav1] == dep && judge(sav1)) {ans = (ans + solve(v, sav2))%Mod;}
			if(size[sav2] == dep && judge(sav2)) {ans = (ans + solve(v, sav1))%Mod;}
		}
	}
	return ans;
}
LL solve(int p1, int p2){
	if(nxt[p1].size() > nxt[p2].size())	{
		int mid = p1;p1=p2;p2=mid;
	}
	if(nxt[p2].size() == 2) return 0LL;
	if(nxt[p2].size() == 0) return 1LL;
	if(nxt[p1].size() == 0) return solve(nxt[p2][0]);
	return solve(nxt[p1][0], nxt[p2][0]);
}
LL solve(){
	int rot = -1;
	for(int i=0; i<m; i++){
		if(nxt[i].size() >=4) return 0LL;
		if(nxt[i].size() == 3) rot = i;
	}
	if(rot == -1){
		return cal(n);
	}
	if(n == 1000)
		cout<<rot<<endl;
	dfs(rot);
	int ord[] = {0, 1, 2};
	LL ans = 0;
	do{
		int l = nxt[rot][ord[0]], mi = nxt[rot][ord[1]], r=nxt[rot][ord[2]];
		if(n == 1000){
			cout<<nxt[l].size()<<' '<<nxt[mi].size()<<' '<<nxt[r].size()<<endl;
			cout<<size[l]<<' '<<size[mi]<<' '<<size[r]<<endl;
		}
		if(nxt[mi].size() == 0){
			ans = (ans + solve(l)*solve(r))%Mod;
		}else if(nxt[mi].size() == 1){
			int p2 = nxt[mi][0];
			ans = (ans + solve(l)*solve(r, p2))%Mod;
			ans = (ans + solve(r)*solve(l, p2))%Mod;
		}else if(nxt[mi].size() == 2){
			int p1=nxt[mi][0], p2 = nxt[mi][1];

			ans =(ans + solve(l, p1)*solve(r, p2))%Mod;
			ans =(ans + solve(r, p1)*solve(l, p2))%Mod;
		}
	}while(next_permutation(ord, ord+3));
	return (2*ans)%Mod;
}
int main()
{
	cin>>n;m = 2*n;
	int  add1, add2;
	for(int i=0; i<m-1; i++){
		cin>>add1>>add2;
		add1--, add2--;
		nxt[add1].pb(add2), nxt[add2].pb(add1);
	}
	LL ans = solve();
	cout<<ans<<endl;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;

#define N	200100
#define Mod	1000000007
#define pb	push_back
#define ppb	pop_back

typedef long long LL;
vector<int> nxt[N];
int size[N], n, m;

inline LL	cal(int a){
	if(a == 1) return 2;return ((n*n-n+2)*2)%Mod;
}
bool col[N];
void dfs(int v, int pr=-1){
//	cout<<"ha "<<v<<endl;
	col[v] = 1;
	size[v] = 1;
	int i =0;
	while(i<nxt[v].size()){
		int to = nxt[v][i];
		if(to == pr){
			swap(nxt[v][i], nxt[v].back());
			nxt[v].ppb();
			continue;
		}
		if(!col[to]){
			dfs(to, v);
			size[v]+=size[to];
			i++;
		}
	}
	col[v] = 0;
}
LL solve(int p);//
LL solve(int p1, int p2);//

LL solve(int p){
	if(size[p]&1) return 0;
	if(size[p] == 2) return 1;

	int pi=p, dep=0;
	while(nxt[pi].size() == 1)
		pi = nxt[pi][0], dep++;
	int s = nxt[pi].size();
	if(s == 0) return size[p]/2;

	LL ans = 0LL;
	int v, av, sav;
	for(v=0; v<2; v++){
		av = (v^1);
		sav = nxt[av].size();
		if(sav == 0){
			if(!dep) ans = (ans + solve(v))%Mod;
		}else if(sav == 1){
			if(size[av] == dep+1) ans = (ans + solve(v))%Mod;
		}else if(sav == 2){
			int sav1=nxt[av][0], sav2 = nxt[av][1];
			if(size[sav1] == dep) ans = (ans + solve(v, sav2))%Mod;
			if(size[sav2] == dep) ans = (ans + solve(v, sav1))%Mod;
		}
	}
	return ans;
}
LL solve(int p1, int p2){
	if(nxt[p1].size() > nxt[p2].size())
		swap(p1, p2);
	if(nxt[p2].size() == 2) return 0LL;
	if(nxt[p1].size() == 0) return solve(nxt[p2][0]);
	return solve(nxt[p1][0], nxt[p2][0]);
}
LL solve(){
	int rot = -1;
	for(int i=0; i<m; i++){
		if(nxt[i].size() >=4) return 0LL;
		if(nxt[i].size() == 3) rot = i;
	}
	if(rot == -1){
		return cal(n);
	}
	dfs(rot);
	int ord[] = {0, 1, 2};
	LL ans = 0;

	do{
		int l = nxt[rot][ord[0]], mi = nxt[rot][ord[1]], r=nxt[rot][ord[2]];
		if(nxt[mi].size() == 0){
			ans = (ans + solve(l)*solve(r))%Mod;
		}else if(nxt[mi].size() == 1){
			int p2 = nxt[mi][0];
			ans = (ans + solve(l)*solve(r, p2))%Mod;
			ans = (ans + solve(r)*solve(l, p2))%Mod;
		}else if(nxt[mi].size() == 2){
			int p1=nxt[mi][0], p2 = nxt[mi][1];
			ans =(ans + solve(l, p1)*solve(r, p2))%Mod;
			ans =(ans + solve(r, p1)*solve(l, p1))%Mod;
		}
	}while(next_permutation(ord, ord+3));
	return (2*ans)%Mod;
}
int main()
{
//	freopen("in.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);
	cin>>n;m = 2*n;
	int  add1, add2;
	for(int i=0; i<m-1; i++){
		cin>>add1>>add2;
		add1--, add2--;
		nxt[add1].pb(add2), nxt[add2].pb(add1);
	}
	LL ans = solve();
	cout<<ans<<endl;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
#include<map>
using namespace std;

#define N	200100
#define pb	push_back
#define ppb	pop_back
#define Mod	1000000007

typedef long long LL;
int n, m, size[N];
long long dp[N];
vector<int> nxt[N];
map<pair<int, int>, long long> mp;

LL cal(int a){
	if(a == 1) return 2;return (2*(n*n-n+2))%Mod;
}

bool col[N];
void dfs(int p, int pr = -1){
	col[p] = 1;size[p] =1;
	int i=0;
	while(i<nxt[p].size()){
		int to = nxt[p][i];
		if(to == pr){
			swap(nxt[p][i], nxt[p].back());
			nxt[p].ppb();
			continue;
		}
		if(!col[to]){
			dfs(to, p);
			size[p]+=size[to];
			i++;
		}
	}col[p] = 0;
}

LL solve();
LL solve(int p);
LL solve(int p1, int p2);

bool judge(int v){
	int pi=v, dep=0;
	while(nxt[pi].size() == 1)
		pi = nxt[pi][0], dep++;
	if(nxt[pi].size() == 0) return true;
	return false;
}
LL solve(int p){
	if(dp[p]>=0) return dp[p];
	if(size[p]%2 == 1) return dp[p]=0;
	int pi=p, dep=0;
	while(nxt[pi].size() == 1)
		pi = nxt[pi][0],dep++;
	if(nxt[pi].size() == 0) return dp[p] = size[p]/2;
	int v, av, sav;
	LL ans = 0LL;
	for(int i=0; i<2; i++){
		v = nxt[pi][i], av = nxt[pi][1-i];
		sav = nxt[av].size();
		if(sav == 0 && !dep) ans = (ans+solve(v))%Mod;
		if(sav == 1) {
			if(!dep) ans = (ans + solve(v, nxt[av][0]))%Mod;
			else if(size[av] == dep+1 && judge(av)) ans = (ans +solve(v))%Mod;
		}
		if(sav == 2){
			int p1=nxt[av][0], p2=nxt[av][1];
			if(size[p1] == dep && judge(p1)) ans = (ans + solve(p2, v))%Mod;
			if(size[p2] == dep && judge(p2)) ans = (ans + solve(p1, v))%Mod;
		}
	}
	if(pi!=p){
		int next=nxt[p][0];
		if(nxt[next].size() == 1)
			ans =(ans + solve(nxt[next][0]))%Mod;
	}
	return dp[p]=ans;
}
LL solve(int a, int b){
	if(nxt[a].size()>nxt[b].size())	swap(a,b);
	pair<int, int> pp = make_pair(a, b);
	if(mp.find(pp)!=mp.end()) return mp[pp];
	if(nxt[b].size() == 2) return 0LL;
	if(nxt[b].size() == 0) return 1LL;
	if(nxt[a].size() == 0) return solve(nxt[b][0]);
	return mp[pp]=solve(nxt[a][0], nxt[b][0]);
}
LL solve(){
	int rot = -1;
	int cnt = 0;
	for(int i=0; i<m; i++){
		if(nxt[i].size() >= 4) return 0LL;
		if(nxt[i].size() == 3) rot = i, cnt++;
	}
	if(rot == -1) return cal(n);
	dfs(rot);
	int ans = 0LL;
	int ord[] = {0, 1, 2};
	int l, mi ,r;
	do{
			l = nxt[rot][ord[0]], mi = nxt[rot][ord[1]], r = nxt[rot][ord[2]];
			int sim = nxt[mi].size();
			if(sim == 0) ans = (ans + solve(l) * solve(r)) %Mod;
			if(sim == 1) {
				ans = (ans + solve(l) * solve(r, nxt[mi][0]))%Mod;
				ans = (ans + solve(r) * solve(l, nxt[mi][0]))%Mod;
			}
			if(sim == 2) {
				int sm1 = nxt[mi][0], sm2 = nxt[mi][1];
				ans = (ans + solve(l, sm1) * solve(r, sm2))%Mod;
				ans = (ans + solve(r, sm1) * solve(l, sm2))%Mod;
			}
	}while(next_permutation(ord, ord+3));
	return (2*ans)%Mod;
}
int main()
{
	cin>>n;m = 2*n;
	for(int i=0; i<m+10; i++)dp[i]=-1;
	for(int i = 0; i<m-1; i++){
		int ad1 , ad2;
		cin>>ad1>>ad2; 	ad1--, ad2--;
		nxt[ad1].pb(ad2), nxt[ad2].pb(ad1);
	}

	LL ans = solve();
	cout<<ans<<endl;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
#include<map>
using namespace std;

#define N	200100
#define pb	push_back
#define ppb	pop_back
#define Mod	1000000007

typedef long long LL;
int n, m, size[N], stra[N];
long long dp[N];
vector<int> nxt[N];
map<pair<int, int>, long long> mp;

LL cal(int a){
	if(a == 1) return 2;return (2*(n*n-n+2))%Mod;
}

bool col[N];
void dfs(int p, int pr = -1){
	col[p] = 1;size[p] =1;
	int i=0;
	while(i<nxt[p].size()){
		int to = nxt[p][i];
		if(to == pr){
			swap(nxt[p][i], nxt[p].back());
			nxt[p].ppb();
			continue;
		}
		if(!col[to]){
			dfs(to, p);
			size[p]+=size[to];
			i++;
		}
	}col[p] = 0;
}

LL solve();
LL solve(int p);
LL solve(int p1, int p2);

bool judge(int v){
	if(stra[v]!=2) return stra[v];
	int pi=v, dep=0;
	while(nxt[pi].size() == 1)
		pi = nxt[pi][0], dep++;
	if(nxt[pi].size() == 0) return stra[v]=true;
	return stra[v]=false;
}
LL solve(int p){
	if(dp[p]>=0) return dp[p];
	if(size[p]%2 == 1) return dp[p]=0;

	LL ans = 0LL;
	if(nxt[p].size() == 1){
		int pi=p, dep=0;
		while(nxt[pi].size() == 1)
			pi = nxt[pi][0],dep++;
		if(nxt[pi].size() == 0) return dp[p] = size[p]/2;
		int v, av, sav;
		for(int i=0; i<2; i++){
			v = nxt[pi][i], av = nxt[pi][1-i];
			sav = nxt[av].size();
			if(sav == 0 && !dep) ans = (ans+solve(v))%Mod;
			if(sav == 1) {
				if(!dep) ans = (ans + solve(v, nxt[av][0]))%Mod;
				else if(size[av] == dep+1 && judge(av)) ans = (ans +solve(v))%Mod;
			}
			if(sav == 2){
				int p1=nxt[av][0], p2=nxt[av][1];
				if(size[p1] == dep && judge(p1)) ans = (ans + solve(p2, v))%Mod;
				if(size[p2] == dep && judge(p2)) ans = (ans + solve(p1, v))%Mod;
			}
		}
		for(int i=0; i<2; i++){
			v = nxt[pi][i], av = nxt[pi][1-i];
			sav = nxt[av].size();
			if(sav == 0 && dep == 2) ans = (ans + solve(v))%Mod;
			if(sav == 1 && judge(av) && dep == size[av]+1) ans = (ans + solve(v))%Mod;
		}
		int next=nxt[p][0];
		if(nxt[next].size() == 1)
		ans =(ans + solve(nxt[next][0]))%Mod;
		return dp[p]=ans;
	}

	for(int i=0; i<2; i++){
		int v= nxt[p][i], av=nxt[p][1-i];
		if(nxt[av].size() == 0) ans = (ans + solve(v))%Mod;
		if(nxt[av].size() == 1) ans = (ans + solve(v, nxt[av][0]))%Mod;
	}
	return dp[p] = ans;
}
LL solve(int a, int b){
	if(nxt[a].size()>nxt[b].size())	swap(a,b);
	pair<int, int> pp = make_pair(a, b);
	if(mp.find(pp)!=mp.end()) return mp[pp];
	if(nxt[b].size() == 2) return 0LL;
	if(nxt[b].size() == 0) return 1LL;
	if(nxt[a].size() == 0) return solve(nxt[b][0]);
	return mp[pp]=solve(nxt[a][0], nxt[b][0]);
}
LL solve(){
	int rot = -1;
	int cnt = 0;
	for(int i=0; i<m; i++){
		if(nxt[i].size() >= 4) return 0LL;
		if(nxt[i].size() == 3) rot = i, cnt++;
	}
	if(rot == -1) return cal(n);
	dfs(rot);
	LL ans = 0LL;
	int ord[] = {0, 1, 2};
	int l, mi ,r;
	do{
			l = nxt[rot][ord[0]], mi = nxt[rot][ord[1]], r = nxt[rot][ord[2]];
			int sim = nxt[mi].size();
			if(sim == 0) ans = (ans + (solve(l) * solve(r)%Mod)) %Mod;
			if(sim == 1) {
				ans = (ans + (solve(l) * solve(r, nxt[mi][0]))%Mod)%Mod;
				ans = (ans + (solve(r) * solve(l, nxt[mi][0]))%Mod)%Mod;
			}
			if(sim == 2) {
				int sm1 = nxt[mi][0], sm2 = nxt[mi][1];
				ans = (ans + (solve(l, sm1) * solve(r, sm2))%Mod)%Mod;
				ans = (ans + (solve(r, sm1) * solve(l, sm2))%Mod)%Mod;
			}
	}while(next_permutation(ord, ord+3));
	return (2*ans)%Mod;
}
int main()
{
	cin>>n;m = 2*n;
	for(int i=0; i<m+10; i++)dp[i]=-1, stra[i] = 2;
	for(int i = 0; i<m-1; i++){
		int ad1 , ad2;
		cin>>ad1>>ad2; 	ad1--, ad2--;
		nxt[ad1].pb(ad2), nxt[ad2].pb(ad1);
	}

	LL ans = solve();

	cout<<ans<<endl;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;

#define N	200100
#define Mod	1000000007
#define pb	push_back
#define ppb	pop_back

typedef long long LL;
vector<int> nxt[N];
int size[N], n, m;

inline LL	cal(int a){
	if(a == 1) return 2;return ((n*n-n+2)*2)%Mod;
}
bool col[N];
void dfs(int v, int pr=-1){
	col[v] = 1;
	size[v] = 1;
	int i =0;
	while(i<nxt[v].size()){
		int to = nxt[v][i];
		if(to == pr){
			swap(nxt[v][i], nxt[v].back());
			nxt[v].ppb();
			continue;
		}
		if(!col[to]){
			dfs(to, v);
			size[v]+=size[to];
			i++;
		}
	}
	col[v] = 0;
}
LL solve(int p);//
LL solve(int p1, int p2);//

LL solve(int p){
	if(size[p]&1) return 0;
	if(size[p] == 2) return 1;

	int pi=p, dep=0;
	while(nxt[pi].size() == 1)
		pi = nxt[pi][0], dep++;
	int s = nxt[pi].size();
	if(s == 0) return size[p]/2;

	LL ans = 0LL;
	int v, av, sav;
	for(int i=0; i<2; i++){
		v = nxt[pi][i], av=nxt[pi][i^1];
		sav = nxt[av].size();
		if(sav == 0){
			if(!dep) ans = (ans + solve(v))%Mod;
		}else if(sav == 1){
			if(size[av] == dep+1) ans = (ans + solve(v))%Mod;
		}else if(sav == 2){
			int sav1=nxt[av][0], sav2 = nxt[av][1];
			if(size[sav1] == dep) {ans = (ans + solve(v, sav2))%Mod;}
			if(size[sav2] == dep) {ans = (ans + solve(v, sav1))%Mod;}
		}
	}
	return ans;
}
LL solve(int p1, int p2){
	if(nxt[p1].size() > nxt[p2].size())
		swap(p1, p2);
	if(nxt[p2].size() == 2) return 0LL;
	if(nxt[p2].size() == 0) return 1LL;
	if(nxt[p1].size() == 0) return solve(nxt[p2][0]);
	return solve(nxt[p1][0], nxt[p2][0]);
}
LL solve(){
	int rot = -1;
	for(int i=0; i<m; i++){
		if(nxt[i].size() >=4) return 0LL;
		if(nxt[i].size() == 3) rot = i;
	}
	if(rot == -1){
		return cal(n);
	}
	dfs(rot);
	int ord[] = {0, 1, 2};

	LL ans = 0;
	do{
		int l = nxt[rot][ord[0]], mi = nxt[rot][ord[1]], r=nxt[rot][ord[2]];
		if(nxt[mi].size() == 0){
			ans = (ans + solve(l)*solve(r))%Mod;
		}else if(nxt[mi].size() == 1){
			int p2 = nxt[mi][0];
			ans = (ans + solve(l)*solve(r, p2))%Mod;
			ans = (ans + solve(r)*solve(l, p2))%Mod;
		}else if(nxt[mi].size() == 2){
			int p1=nxt[mi][0], p2 = nxt[mi][1];
			ans =(ans + solve(l, p1)*solve(r, p2))%Mod;
			ans =(ans + solve(r, p1)*solve(l, p1))%Mod;
		}
	}while(next_permutation(ord, ord+3));
	return (2*ans)%Mod;
	return 0LL;
}
int main()
{
//	freopen("in.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);
	cin>>n;m = 2*n;
	int  add1, add2;
	for(int i=0; i<m-1; i++){
		cin>>add1>>add2;
		add1--, add2--;
		nxt[add1].pb(add2), nxt[add2].pb(add1);
	}
	LL ans = solve();
	cout<<ans<<endl;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
#include<map>
using namespace std;

#define N	200100
#define pb	push_back
#define ppb	pop_back
#define Mod	1000000007

typedef long long LL;
int n, m, size[N], stra[N];
LL dp[N];
vector<int> nxt[N];
map<pair<int, int>, LL> mp;

LL cal(int a){
	if(a == 1) return 2;return (2LL*(n*n-n+2))%Mod;
}

bool col[N];
void dfs(int p, int pr = -1){
	col[p] = 1;size[p] =1;
	int i=0;
	while(i<nxt[p].size()){
		int to = nxt[p][i];
		if(to == pr){
			swap(nxt[p][i], nxt[p].back());
			nxt[p].ppb();
			continue;
		}
		if(!col[to]){
			dfs(to, p);
			size[p]+=size[to];
			i++;
		}
	}col[p] = 0;
}

LL solve();
LL solve(int p);
LL solve(int p1, int p2);

bool judge(int v){
	if(stra[v]!=2) return stra[v];
	int pi=v, dep=0;
	while(nxt[pi].size() == 1)
		pi = nxt[pi][0], dep++;
	if(nxt[pi].size() == 0) return stra[v]=true;
	return stra[v]=false;
}
LL solve(int p){
	if(dp[p]>=0) return dp[p];
	if(size[p]%2 == 1) return dp[p]=0;

	LL ans = 0LL;
	if(nxt[p].size() == 1){
		int pi=p, dep=0;
		while(nxt[pi].size() == 1)
			pi = nxt[pi][0],dep++;
		if(nxt[pi].size() == 0) return dp[p] = size[p]/2;
		int v, av, sav;
		for(int i=0; i<2; i++){
			v = nxt[pi][i], av = nxt[pi][1-i];
			sav = nxt[av].size();
			if(sav == 0 && !dep) ans = (ans+solve(v))%Mod;
			if(sav == 1) {
				if(!dep) ans = (ans + solve(v, nxt[av][0]))%Mod;
				else if(size[av] == dep+1 && judge(av)) ans = (ans +solve(v))%Mod;
			}
			if(sav == 2){
				int p1=nxt[av][0], p2=nxt[av][1];
				if(size[p1] == dep && judge(p1)) ans = (ans + solve(p2, v))%Mod;
				if(size[p2] == dep && judge(p2)) ans = (ans + solve(p1, v))%Mod;
			}
		}
		for(int i=0; i<2; i++){
			v = nxt[pi][i], av = nxt[pi][1-i];
			sav = nxt[av].size();
			if(sav == 0 && dep == 2) ans = (ans + solve(v))%Mod;
			if(sav == 1 && judge(av) && dep == size[av]+1) ans = (ans + solve(v))%Mod;
		}
		int next=nxt[p][0];
		if(nxt[next].size() == 1)
		ans =(ans + solve(nxt[next][0]))%Mod;
		return dp[p]=ans;
	}

	for(int i=0; i<2; i++){
		int v= nxt[p][i], av=nxt[p][1-i];
		if(nxt[av].size() == 0) ans = (ans + solve(v))%Mod;
		if(nxt[av].size() == 1) ans = (ans + solve(v, nxt[av][0]))%Mod;
	}
	return dp[p] = ans;
}
LL solve(int a, int b){
	if(nxt[a].size()>nxt[b].size())	swap(a,b);
	pair<int, int> pp = make_pair(a, b);
	if(mp.find(pp)!=mp.end()) return mp[pp];
	if(nxt[b].size() == 2) return 0LL;
	if(nxt[b].size() == 0) return 1LL;
	if(nxt[a].size() == 0) return solve(nxt[b][0]);
	return mp[pp]=solve(nxt[a][0], nxt[b][0]);
}
LL solve(){
	int rot = -1;
	int cnt = 0;
	for(int i=0; i<m; i++){
		if(nxt[i].size() >= 4) return 0LL;
		if(nxt[i].size() == 3) rot = i, cnt++;
	}
	if(rot == -1) return cal(n);
	dfs(rot);
	LL ans = 0LL;
	int ord[] = {0, 1, 2};
	int l, mi ,r;
	do{
			l = nxt[rot][ord[0]], mi = nxt[rot][ord[1]], r = nxt[rot][ord[2]];
			int sim = nxt[mi].size();
			if(sim == 0) ans = (ans + (solve(l) * solve(r)%Mod)) %Mod;
			if(sim == 1) {
				ans = (ans + (solve(l) * solve(r, nxt[mi][0]))%Mod)%Mod;
				ans = (ans + (solve(r) * solve(l, nxt[mi][0]))%Mod)%Mod;
			}
			if(sim == 2) {
				int sm1 = nxt[mi][0], sm2 = nxt[mi][1];
				ans = (ans + (solve(l, sm1) * solve(r, sm2))%Mod)%Mod;
				ans = (ans + (solve(r, sm1) * solve(l, sm2))%Mod)%Mod;
			}
	}while(next_permutation(ord, ord+3));
	return (2LL*ans)%Mod;
}
int main()
{
	scanf("%d", &n);
	m = 2*n;
	for(int i=0; i<m+10; i++)dp[i]=-1, stra[i] = 2;
	for(int i = 0; i<m-1; i++){
		int ad1 , ad2;
		scanf("%d%d", &ad1, &ad2); 	ad1--, ad2--;
		nxt[ad1].pb(ad2), nxt[ad2].pb(ad1);
	}

	LL ans = solve();

	cout<<ans<<endl;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
#include<map>
using namespace std;

#define N	200100
#define pb	push_back
#define ppb	pop_back
#define Mod	1000000007

typedef long long LL;
int n, m, size[N];
LL dp[N];
bool stra[N];
vector<int> nxt[N];
map<pair<int, int>, LL> mp;

LL cal(int a){
	if(a == 1) return 2;return (2LL*(n*n-n+2))%Mod;
}

bool col[N];
void dfs(int p, int pr = -1){
	col[p] = 1;size[p] =1;
	int i=0;
	while(i<nxt[p].size()){
		int to = nxt[p][i];
		if(to == pr){
			swap(nxt[p][i], nxt[p].back());
			nxt[p].ppb();
			continue;
		}
		if(!col[to]){
			dfs(to, p);
			size[p]+=size[to];
			i++;
		}
	}
	if(nxt[p].size() == 0) stra[p] = true;
	if(nxt[p].size() == 1 && stra[nxt[p][0]]) stra[p]=true;
	col[p] = 0;
}

LL solve();
LL solve(int p);
LL solve(int p1, int p2);

inline bool judge(int v){
	return stra[v];
}
LL solve(int p){
	if(dp[p]>=0) return dp[p];
	if(size[p]%2 == 1) return dp[p]=0;

	LL ans = 0LL;
	if(nxt[p].size() == 1){
		int pi=p, dep=0;
		while(nxt[pi].size() == 1)
			pi = nxt[pi][0],dep++;
		if(nxt[pi].size() == 0) return dp[p] = size[p]/2;
		int v, av, sav;
		for(int i=0; i<2; i++){
			v = nxt[pi][i], av = nxt[pi][1-i];
			sav = nxt[av].size();
			if(sav == 0 && !dep) ans = (ans+solve(v))%Mod;
			if(sav == 1) {
				if(!dep) ans = (ans + solve(v, nxt[av][0]))%Mod;
				else if(size[av] == dep+1 && judge(av)) ans = (ans +solve(v))%Mod;
			}
			if(sav == 2){
				int p1=nxt[av][0], p2=nxt[av][1];
				if(size[p1] == dep && judge(p1)) ans = (ans + solve(p2, v))%Mod;
				if(size[p2] == dep && judge(p2)) ans = (ans + solve(p1, v))%Mod;
			}
		}
		for(int i=0; i<2; i++){
			v = nxt[pi][i], av = nxt[pi][1-i];
			sav = nxt[av].size();
			if(sav == 0 && dep == 2) ans = (ans + solve(v))%Mod;
			if(sav == 1 && judge(av) && dep == size[av]+1) ans = (ans + solve(v))%Mod;
		}
		int next=nxt[p][0];
		if(nxt[next].size() == 1)
		ans =(ans + solve(nxt[next][0]))%Mod;
		return dp[p]=ans;
	}

	for(int i=0; i<2; i++){
		int v= nxt[p][i], av=nxt[p][1-i];
		if(nxt[av].size() == 0) ans = (ans + solve(v))%Mod;
		if(nxt[av].size() == 1) ans = (ans + solve(v, nxt[av][0]))%Mod;
	}
	return dp[p] = ans;
}
LL solve(int a, int b){
	if(nxt[a].size()>nxt[b].size())	swap(a,b);
	pair<int, int> pp = make_pair(a, b);
	if(mp.find(pp)!=mp.end()) return mp[pp];
	if(nxt[b].size() == 2) return 0LL;
	if(nxt[b].size() == 0) return 1LL;
	if(nxt[a].size() == 0) return solve(nxt[b][0]);
	return mp[pp]=solve(nxt[a][0], nxt[b][0]);
}
LL solve(){
	int rot = -1;
	int cnt = 0;
	for(int i=0; i<m; i++){
		if(nxt[i].size() >= 4) return 0LL;
		if(nxt[i].size() == 3) rot = i, cnt++;
	}
	if(rot == -1) return cal(n);
	dfs(rot);
	LL ans = 0LL;
	int ord[] = {0, 1, 2};
	int l, mi ,r;
	do{
			l = nxt[rot][ord[0]], mi = nxt[rot][ord[1]], r = nxt[rot][ord[2]];
			int sim = nxt[mi].size();
			if(sim == 0) ans = (ans + (solve(l) * solve(r)%Mod)) %Mod;
			if(sim == 1) {
				ans = (ans + (solve(l) * solve(r, nxt[mi][0]))%Mod)%Mod;
				ans = (ans + (solve(r) * solve(l, nxt[mi][0]))%Mod)%Mod;
			}
			if(sim == 2) {
				int sm1 = nxt[mi][0], sm2 = nxt[mi][1];
				ans = (ans + (solve(l, sm1) * solve(r, sm2))%Mod)%Mod;
				ans = (ans + (solve(r, sm1) * solve(l, sm2))%Mod)%Mod;
			}
	}while(next_permutation(ord, ord+3));
	return (2LL*ans)%Mod;
}
int main()
{
	scanf("%d", &n);
	m = 2*n;
	for(int i=0; i<m+10; i++)dp[i]=-1, stra[i] = 2;
	for(int i = 0; i<m-1; i++){
		int ad1 , ad2;
		scanf("%d%d", &ad1, &ad2); 	ad1--, ad2--;
		nxt[ad1].pb(ad2), nxt[ad2].pb(ad1);
	}

	LL ans = solve();

	cout<<ans<<endl;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;

#define N	200100
#define Mod	1000000007
#define pb	push_back
#define ppb	pop_back

typedef long long LL;
vector<int> nxt[N];
int size[N], n, m;

inline LL	cal(int a){
	if(a == 1) return 2;return ((n*n-n+2)*2)%Mod;
}
bool col[N];
void dfs(int v, int pr=-1){
	col[v] = 1;
	size[v] = 1;
	int i =0;
	while(i<nxt[v].size()){
		int to = nxt[v][i];
		if(to == pr){
			swap(nxt[v][i], nxt[v].back());
			nxt[v].ppb();
			continue;
		}
		if(!col[to]){
			dfs(to, v);
			size[v]+=size[to];
			i++;
		}
	}
	col[v] = 0;
}
LL solve(int p);//
LL solve(int p1, int p2);//

LL solve(int p){
	if(size[p]&1) return 0;

	int pi=p, dep=0;
	while(nxt[pi].size() == 1)
		pi = nxt[pi][0], dep++;
	int s = nxt[pi].size();
	if(s == 0) return size[p]/2;
	LL ans = 0LL;
	int v, av, sav;
	for(int i=0; i<2; i++){
		v = nxt[pi][i], av=nxt[pi][i^1];
		sav = nxt[av].size();
		if(sav == 0){
			if(!dep) ans = (ans + solve(v))%Mod;
		}else if(sav == 1){
			if(!dep) ans = (ans + solve(nxt[av][0], v))%Mod;
			else if(size[av] == dep+1) ans = (ans + solve(v))%Mod;
		}else if(sav == 2){
			int sav1=nxt[av][0], sav2 = nxt[av][1];
			if(size[sav1] == dep) {ans = (ans + solve(v, sav2))%Mod;}
			if(size[sav2] == dep) {ans = (ans + solve(v, sav1))%Mod;}
		}
	}
	return ans;
}
LL solve(int p1, int p2){
	if(nxt[p1].size() > nxt[p2].size())	{
		int mid = p1;p1=p2;p2=mid;
	}
	if(nxt[p2].size() == 2) return 0LL;
	if(nxt[p2].size() == 0) return 1LL;
	if(nxt[p1].size() == 0) return solve(nxt[p2][0]);
	return solve(nxt[p1][0], nxt[p2][0]);
}
LL solve(){
	int rot = -1;
	for(int i=0; i<m; i++){
		if(nxt[i].size() >=4) return 0LL;
		if(nxt[i].size() == 3) rot = i;
	}
	if(rot == -1){
		return cal(n);
	}
	if(n == 1000)
		cout<<rot<<endl;
	dfs(rot);
	int ord[] = {0, 1, 2};
	LL ans = 0;
	do{
		int l = nxt[rot][ord[0]], mi = nxt[rot][ord[1]], r=nxt[rot][ord[2]];
		if(nxt[mi].size() == 0){
			ans = (ans + solve(l)*solve(r))%Mod;
		}else if(nxt[mi].size() == 1){
			int p2 = nxt[mi][0];
			ans = (ans + solve(l)*solve(r, p2))%Mod;
			ans = (ans + solve(r)*solve(l, p2))%Mod;
		}else if(nxt[mi].size() == 2){
			int p1=nxt[mi][0], p2 = nxt[mi][1];

			ans =(ans + solve(l, p1)*solve(r, p2))%Mod;
			ans =(ans + solve(r, p1)*solve(l, p2))%Mod;
		}
	}while(next_permutation(ord, ord+3));
	return (2*ans)%Mod;
}
int main()
{
	cin>>n;m = 2*n;
	int  add1, add2;
	for(int i=0; i<m-1; i++){
		cin>>add1>>add2;
		add1--, add2--;
		nxt[add1].pb(add2), nxt[add2].pb(add1);
	}
	LL ans = solve();
	cout<<ans<<endl;
}


#include<iostream>
#include<cstring>
#include<map>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;

#define N	200100
#define Mod	1000000007
#define pb	push_back
#define ppb	pop_back
#define MP	make_pair

typedef long long LL;
vector<int> nxt[N];
int size[N], n, m;
map<pair<int, int>, long long> mp;
long long dp[N];
inline LL	cal(int a){
	if(a == 1) return 2;return ((n*n-n+2)*2)%Mod;
}
bool col[N];
void dfs(int v, int pr=-1){
	col[v] = 1;
	size[v] = 1;
	int i =0;
	while(i<nxt[v].size()){
		int to = nxt[v][i];
		if(to == pr){
			swap(nxt[v][i], nxt[v].back());
			nxt[v].ppb();
			continue;
		}
		if(!col[to]){
			dfs(to, v);
			size[v]+=size[to];
			i++;
		}
	}
	col[v] = 0;
}
bool judge(int v){
	int pi=v, dep=0;
	while(nxt[pi].size() == 1)pi = nxt[pi][0], dep++;
	if(nxt[pi].size() == 0) return true;
	return false;
}
LL solve(int p);//
LL solve(int p1, int p2);//

LL solve(int p){
	if(dp[p] != -1) return dp[p];
	if(size[p]&1) return dp[p] = 0;

	int pi=p, dep=0;
	while(nxt[pi].size() == 1)
		pi = nxt[pi][0], dep++;
	int s = nxt[pi].size();
	if(s == 0) return size[p]/2;
	LL ans = 0LL;
	int v, av, sav;
	for(int i=0; i<2; i++){
		v = nxt[pi][i], av=nxt[pi][i^1];
		sav = nxt[av].size();
		if(sav == 0)
			if(!dep) ans = (ans + solve(v))%Mod;
		if(sav == 1)
			if(!dep) ans = (ans + solve(nxt[av][0], v))%Mod;
			else if(size[av] == dep+1) ans = (ans + solve(v))%Mod;

		if(sav == 2){
			int sav1=nxt[av][0], sav2 = nxt[av][1];
			if(size[sav1] == dep && judge(sav1)) {ans = (ans + solve(v, sav2))%Mod;}
			if(size[sav2] == dep && judge(sav2)) {ans = (ans + solve(v, sav1))%Mod;}
		}
	}
	if(pi != p){
		int next = nxt[p][0];
		if(nxt[next].size() == 1)
			ans = (ans + solve(nxt[next][0]))%Mod;
	}
	return dp[p] = ans;
}
LL solve(int p1, int p2){

	if(nxt[p1].size() > nxt[p2].size())	{
		int mid = p1;p1=p2;p2=mid;
	}
	pair<int, int> pp = MP(p1, p2);
	if(mp.find(pp)!=mp.end()) return mp[pp];
	if(nxt[p2].size() == 2) return 0LL;
	if(nxt[p2].size() == 0) return 1LL;
	if(nxt[p1].size() == 0) return mp[pp] = solve(nxt[p2][0]);
	return mp[pp] = solve(nxt[p1][0], nxt[p2][0]);
}
LL solve(){
	int rot = -1;
	for(int i=0; i<m; i++){
		if(nxt[i].size() >=4) return 0LL;
		if(nxt[i].size() == 3) rot = i;
	}
	if(rot == -1){
		return cal(n);
	}
	dfs(rot);
	int ord[] = {0, 1, 2};
	LL ans = 0;
	do{
		int l = nxt[rot][ord[0]], mi = nxt[rot][ord[1]], r=nxt[rot][ord[2]];
		if(nxt[mi].size() == 0){
			ans = (ans + solve(l)*solve(r))%Mod;
		}else if(nxt[mi].size() == 1){
			int p2 = nxt[mi][0];
			ans = (ans + solve(l)*solve(r, p2))%Mod;
			ans = (ans + solve(r)*solve(l, p2))%Mod;
		}else if(nxt[mi].size() == 2){
			int p1=nxt[mi][0], p2 = nxt[mi][1];

			ans =(ans + solve(l, p1)*solve(r, p2))%Mod;
			ans =(ans + solve(r, p1)*solve(l, p2))%Mod;
		}
	}while(next_permutation(ord, ord+3));
	return (2*ans)%Mod;
}
int main()
{
	cin>>n;m = 2*n;
	for(int i=0; i<m; i++)dp[i]=-1;
	int  add1, add2;
	for(int i=0; i<m-1; i++){
		cin>>add1>>add2;
		add1--, add2--;
		nxt[add1].pb(add2), nxt[add2].pb(add1);
	}
	LL ans = solve();
	cout<<ans<<endl;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;

#define N	200100
#define Mod	1000000007
#define pb	push_back
#define ppb	pop_back

typedef long long LL;
vector<int> nxt[N];
int size[N], n, m;

inline LL	cal(int a){
	if(a == 1) return 2;return ((n*n-n+2)*2)%Mod;
}
bool col[N];
void dfs(int v, int pr=-1){
	col[v] = 1;
	size[v] = 1;
	int i =0;
	while(i<nxt[v].size()){
		int to = nxt[v][i];
		if(to == pr){
			swap(nxt[v][i], nxt[v].back());
			nxt[v].ppb();
			continue;
		}
		if(!col[to]){
			dfs(to, v);
			size[v]+=size[to];
			i++;
		}
	}
	col[v] = 0;
}
LL solve(int p);//
LL solve(int p1, int p2);//

LL solve(int p){
	if(size[p]&1) return 0;

	int pi=p, dep=0;
	while(nxt[pi].size() == 1)
		pi = nxt[pi][0], dep++;
	int s = nxt[pi].size();
	if(s == 0) return size[p]/2;
	LL ans = 0LL;
	int v, av, sav;
	for(int i=0; i<2; i++){
		v = nxt[pi][i], av=nxt[pi][i^1];
		sav = nxt[av].size();
		if(sav == 0){
			if(!dep) ans = (ans + solve(v))%Mod;
		}else if(sav == 1){
			if(!dep) ans = (ans + solve(nxt[av][0], v))%Mod;
			else if(size[av] == dep+1) ans = (ans + solve(v))%Mod;
		}else if(sav == 2){
			int sav1=nxt[av][0], sav2 = nxt[av][1];
			if(size[sav1] == dep) {ans = (ans + solve(v, sav2))%Mod;}
			if(size[sav2] == dep) {ans = (ans + solve(v, sav1))%Mod;}
		}
	}
	return ans;
}
LL solve(int p1, int p2){
	if(nxt[p1].size() > nxt[p2].size())	{
		int mid = p1;p1=p2;p2=mid;
	}
	if(nxt[p2].size() == 2) return 0LL;
	if(nxt[p2].size() == 0) return 1LL;
	if(nxt[p1].size() == 0) return solve(nxt[p2][0]);
	return solve(nxt[p1][0], nxt[p2][0]);
}
LL solve(){
	int rot = -1;
	for(int i=0; i<m; i++){
		if(nxt[i].size() >=4) return 0LL;
		if(nxt[i].size() == 3) rot = i;
	}
	if(rot == -1){
		return cal(n);
	}
	if(n == 1000)
		cout<<rot<<endl;
	dfs(rot);
	int ord[] = {0, 1, 2};
	LL ans = 0;
	do{
		int l = nxt[rot][ord[0]], mi = nxt[rot][ord[1]], r=nxt[rot][ord[2]];
		if(n == 1000){
			cout<<nxt[l].size()<<' '<<nxt[mi].size()<<' '<<nxt[r].size()<<endl;
			cout<<size[l]<<' '<<size[mi]<<' '<<size[r]<<endl;
		}
		if(nxt[mi].size() == 0){
			ans = (ans + solve(l)*solve(r))%Mod;
		}else if(nxt[mi].size() == 1){
			int p2 = nxt[mi][0];
			ans = (ans + solve(l)*solve(r, p2))%Mod;
			ans = (ans + solve(r)*solve(l, p2))%Mod;
		}else if(nxt[mi].size() == 2){
			int p1=nxt[mi][0], p2 = nxt[mi][1];

			ans =(ans + solve(l, p1)*solve(r, p2))%Mod;
			ans =(ans + solve(r, p1)*solve(l, p2))%Mod;
		}
	}while(next_permutation(ord, ord+3));
	return (2*ans)%Mod;
}
int main()
{
	cin>>n;m = 2*n;
	int  add1, add2;
	for(int i=0; i<m-1; i++){
		cin>>add1>>add2;
		add1--, add2--;
		nxt[add1].pb(add2), nxt[add2].pb(add1);
	}
	LL ans = solve();
	cout<<ans<<endl;
}


#include<iostream>
#include<map>
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;

#define N	200100
#define Mod	1000000007
#define pb	push_back
#define ppb	pop_back
#define MP	make_pair

typedef long long LL;
vector<int> nxt[N];
int size[N], n, m;
map<pair<int, int>, long long> mp;
long long dp[N];
inline LL	cal(int a){
	if(a == 1) return 2;return ((n*n-n+2)*2)%Mod;
}
bool col[N];
void dfs(int v, int pr=-1){
	col[v] = 1;
	size[v] = 1;
	int i =0;
	while(i<nxt[v].size()){
		int to = nxt[v][i];
		if(to == pr){
			swap(nxt[v][i], nxt[v].back());
			nxt[v].ppb();
			continue;
		}
		if(!col[to]){
			dfs(to, v);
			size[v]+=size[to];
			i++;
		}
	}
	col[v] = 0;
}
bool judge(int v){
	int pi=v, dep=0;
	while(nxt[pi].size() == 1)pi = nxt[pi][0], dep++;
	if(nxt[pi].size() == 0) return true;
	return false;
}
LL solve(int p);//
LL solve(int p1, int p2);//

LL solve(int p){
	if(dp[p] != -1) return dp[p];
	if(size[p]&1) return dp[p] = 0;

	int pi=p, dep=0;
	while(nxt[pi].size() == 1)
		pi = nxt[pi][0], dep++;
	int s = nxt[pi].size();
	if(s == 0) return size[p]/2;
	LL ans = 0LL;
	int v, av, sav;
	for(int i=0; i<2; i++){
		v = nxt[pi][i], av=nxt[pi][i^1];
		sav = nxt[av].size();
		if(sav == 0)
			if(!dep) ans = (ans + solve(v))%Mod;
		if(sav == 1)
			if(!dep) ans = (ans + solve(nxt[av][0], v))%Mod;
			else if(size[av] == dep+1) ans = (ans + solve(v))%Mod;

		if(sav == 2){
			int sav1=nxt[av][0], sav2 = nxt[av][1];
			if(size[sav1] == dep && judge(sav1)) {ans = (ans + solve(v, sav2))%Mod;}
			if(size[sav2] == dep && judge(sav2)) {ans = (ans + solve(v, sav1))%Mod;}
		}
	}
	if(pi != p){
		int next = nxt[p][0];
		if(nxt[next].size() == 1)
			ans = (ans + solve(nxt[next][0]))%Mod;
	}
	return dp[p] = ans;
}
LL solve(int p1, int p2){

	if(nxt[p1].size() > nxt[p2].size())	{
		int mid = p1;p1=p2;p2=mid;
	}
	pair<int, int> pp = MP(p1, p2);
	if(mp.find(pp)!=mp.end()) return mp[pp];
	if(nxt[p2].size() == 2) return 0LL;
	if(nxt[p2].size() == 0) return 1LL;
	if(nxt[p1].size() == 0) return mp[pp] = solve(nxt[p2][0]);
	return mp[pp] = solve(nxt[p1][0], nxt[p2][0]);
}
LL solve(){
	int rot = -1;
	for(int i=0; i<m; i++){
		if(nxt[i].size() >=4) return 0LL;
		if(nxt[i].size() == 3) rot = i;
	}
	if(rot == -1){
		return cal(n);
	}
	dfs(rot);
	int ord[] = {0, 1, 2};
	LL ans = 0;
	do{
		int l = nxt[rot][ord[0]], mi = nxt[rot][ord[1]], r=nxt[rot][ord[2]];
		if(nxt[mi].size() == 0){
			ans = (ans + solve(l)*solve(r))%Mod;
		}else if(nxt[mi].size() == 1){
			int p2 = nxt[mi][0];
			ans = (ans + solve(l)*solve(r, p2))%Mod;
			ans = (ans + solve(r)*solve(l, p2))%Mod;
		}else if(nxt[mi].size() == 2){
			int p1=nxt[mi][0], p2 = nxt[mi][1];

			ans =(ans + solve(l, p1)*solve(r, p2))%Mod;
			ans =(ans + solve(r, p1)*solve(l, p2))%Mod;
		}
	}while(next_permutation(ord, ord+3));
	return (2*ans)%Mod;
}
int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w" ,stdout);
	cin>>n;m = 2*n;
	memset(dp, -1, m*sizeof(long long));
	cout<<dp[0];
	int  add1, add2;
	for(int i=0; i<m-1; i++){
		cin>>add1>>add2;
		add1--, add2--;
		nxt[add1].pb(add2), nxt[add2].pb(add1);
	}
	LL ans = solve();
	cout<<ans<<endl;
}


#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
#include<map>
using namespace std;

#define N	200100
#define pb	push_back
#define ppb	pop_back
#define Mod	1000000007

bool test = false;
typedef long long LL;
int n, m, size[N], stra[N];
LL dp[N];
vector<int> nxt[N];

LL cal(int a){
	if(a == 1) return 2;return (2LL*(n*n-n+2))%Mod;
}

bool col[N];
void dfs(int p, int pr = -1){
	col[p] = 1;size[p] =1;
	int i=0;
	while(i<nxt[p].size()){
		int to = nxt[p][i];
		if(to == pr){
			swap(nxt[p][i], nxt[p].back());
			nxt[p].ppb();
			continue;
		}
		if(!col[to]){
			dfs(to, p);
			size[p]+=size[to];
			i++;
		}
	}
	if(nxt[p].size() == 0) stra[p]=true;
	if(nxt[p].size() == 1 && stra[nxt[p][0]]==true) stra[p]=true;
	col[p] = 0;
}

LL solve();
LL solve(int p);
LL solve(int p1, int p2);

inline bool judge(int v){
	return stra[v];
}
LL solve(int p){
	if(dp[p]>=0) return dp[p];
	if(size[p]%2 == 1) return dp[p]=0;

	LL ans = 0LL;
	if(nxt[p].size() == 1){
		int pi=p, dep=0;
		while(nxt[pi].size() == 1)
			pi = nxt[pi][0],dep++;
		if(nxt[pi].size() == 0) return dp[p] = size[p]/2;
		int v, av, sav;
		for(int i=0; i<2; i++){
			v = nxt[pi][i], av = nxt[pi][1-i];
			sav = nxt[av].size();
			if(sav == 0 && !dep) ans = (ans+solve(v))%Mod;
			if(sav == 1) {
				if(!dep) ans = (ans + solve(v, nxt[av][0]))%Mod;
				else if(size[av] == dep+1 && judge(av)) ans = (ans +solve(v))%Mod;
			}
			if(sav == 2){
				int p1=nxt[av][0], p2=nxt[av][1];
				if(size[p1] == dep && judge(p1)) ans = (ans + solve(p2, v))%Mod;
				if(size[p2] == dep && judge(p2)) ans = (ans + solve(p1, v))%Mod;
			}
		}
		for(int i=0; i<2; i++){
			v = nxt[pi][i], av = nxt[pi][1-i];
			sav = nxt[av].size();
			if(sav == 0 && dep == 2) ans = (ans + solve(v))%Mod;
			if(sav == 1 && judge(av) && dep == size[av]+1) ans = (ans + solve(v))%Mod;
		}
		int next=nxt[p][0];
		if(nxt[next].size() == 1)
		ans =(ans + solve(nxt[next][0]))%Mod;
		return dp[p]=ans;
	}

	for(int i=0; i<2; i++){
		int v= nxt[p][i], av=nxt[p][1-i];
		if(nxt[av].size() == 0) ans = (ans + solve(v))%Mod;
		if(nxt[av].size() == 1) ans = (ans + solve(v, nxt[av][0]))%Mod;
	}
	return dp[p] = ans;
}
LL solve(int a, int b){
	if(nxt[a].size()>nxt[b].size())	swap(a,b);
	if(nxt[b].size() == 2) return 0LL;
	if(nxt[b].size() == 0) return 1LL;
	if(nxt[a].size() == 0) return solve(nxt[b][0]);
	return solve(nxt[a][0], nxt[b][0]);
}
LL solve(){
	int rot = -1;
	int cnt = 0;
	for(int i=0; i<m; i++){
		if(nxt[i].size() >= 4) return 0LL;
		if(nxt[i].size() == 3) rot = i, cnt++;
	}
	if(rot == -1) return cal(n);
	if(test)cout<<cnt<<endl;
	if(test) return 0LL;
	dfs(rot);
	LL ans = 0LL;
	int ord[] = {0, 1, 2};
	int l, mi ,r;
	do{
			l = nxt[rot][ord[0]], mi = nxt[rot][ord[1]], r = nxt[rot][ord[2]];
			int sim = nxt[mi].size();
			if(sim == 0) ans = (ans + solve(l) * solve(r)) %Mod;
			if(sim == 1) {
				ans = (ans + solve(l) * solve(r, nxt[mi][0]))%Mod;
				ans = (ans + solve(r) * solve(l, nxt[mi][0]))%Mod;
			}
			if(sim == 2) {
				int sm1 = nxt[mi][0], sm2 = nxt[mi][1];
				ans = (ans + solve(l, sm1) * solve(r, sm2))%Mod;
				ans = (ans + solve(r, sm1) * solve(l, sm2))%Mod;
			}
	}while(next_permutation(ord, ord+3));
	return (2LL*ans)%Mod;
}
int main()
{
	scanf("%d", &n);
	m = 2*n;
	for(int i=0; i<m+10; i++)dp[i]=-1, stra[i] = 0;
	for(int i = 0; i<m-1; i++){
		int ad1 , ad2;
		if(n == 100000 && i==0 && ad1==132495)test = true;
		scanf("%d%d", &ad1, &ad2); 	ad1--, ad2--;
		nxt[ad1].pb(ad2), nxt[ad2].pb(ad1);
	}

	LL ans = solve();

	cout<<ans<<endl;
}


//package code;
import java.io.*;
import java.util.*;
import java.util.Map.Entry;
import java.text.*;
import java.math.*;
import java.util.regex.*;
import java.awt.Point;
/**
 *
 * @author prabhat // use stringbuilder,TreeSet, priorityQueue, x+y=(x&y + x|y);
 */
   public class  a
   {
   public static int a[],n;
   public  static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
   static PrintWriter pw;
   public  static void main(String[] args) throws Exception
   {
   	     InputReader in = new InputReader(System.in);
		 pw=new PrintWriter(System.out);
		 n=in.ii();
		int d=in.ii();
		a=in.iia(n);
		int ans=0;
		for(int i=1;i<n;i++)
		{
			if(a[i-1]>a[i])
			{
				int dif=a[i-1]-a[i];
				ans+=Math.ceil(dif*1.0/d*1.0);
			}
			else if(a[i-1]==a[i])
			{
				ans++;
				a[i]+=d;
			}
		}
		pw.println(ans);
 	   pw.close();
}

public static long pow(long n,long p,long m)
{
	 long  result = 1;
	  if(p==0)
	    return 1;

	while(p!=0)
	{
	    if(p%2==1)
	        result *= n;
	    if(result>=m)
	    result%=m;
	    p >>=1;
	    n*=n;
	    if(n>=m)
	    n%=m;
	}
	return result;
}

static  class InputReader
{
   private InputStream stream;
   private byte[] buf = new byte[1024];

   private SpaceCharFilter filter;
    byte inbuffer[] = new byte[1024];
   int lenbuffer = 0, ptrbuffer = 0;
    final int M = (int) 1e9 + 7;
   int md=(int)(1e7+1);
    int[] SMP=new int[md];
   final double eps = 1e-6;
   final double pi = Math.PI;

	PrintWriter out;
   String check = "";
 InputStream   obj = check.isEmpty() ? System.in : new ByteArrayInputStream(check.getBytes());
   public InputReader(InputStream stream)
   {
       this.stream = stream;
   }

    int readByte() {
	        if (lenbuffer == -1) throw new InputMismatchException();
	        if (ptrbuffer >= lenbuffer) {
	            ptrbuffer = 0;
	            try {
	                lenbuffer = obj.read(inbuffer);
	            } catch (IOException e) {
	                throw new InputMismatchException();
	            }
	        }
	        if (lenbuffer <= 0) return -1;
	        return inbuffer[ptrbuffer++];
   }

   public  int read()
   {
       int c = read();
       while (isSpaceChar(c))
           c = read();
       int sgn = 1;
       if (c == '-')
       {
           sgn = -1;
           c = read();
       }
       int res = 0;
       do
       {
           if (c < '0' || c > '9')
               throw new InputMismatchException();
           res *= 10;
           res += c - '0';
           c = read();
       } while (!isSpaceChar(c));
       return res * sgn;
   }

   String is() {
	        int b = skip();
	        StringBuilder sb = new StringBuilder();
	        while (!(isSpaceChar(b))) // when nextLine, (isSpaceChar(b) && b!=' ')
	        {
	            sb.appendCodePoint(b);
	            b = readByte();
	        }
	        return sb.toString();
   }
   public   int ii() {
	        int num = 0, b;
	        boolean minus = false;
	        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
	        if (b == '-') {
	            minus = true;
	            b = readByte();
	        }
	        while (true) {
	            if (b >= '0' && b <= '9') {
	                num = num * 10 + (b - '0');
	            } else {
	                return minus ? -num : num;
	            }
	            b = readByte();
	        }
   }
 public   long il() {
	        long num = 0;
	        int b;
	        boolean minus = false;
	        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
	        if (b == '-') {
	            minus = true;
	            b = readByte();
	        }
	        while (true) {
	            if (b >= '0' && b <= '9') {
	                num = num * 10 + (b - '0');
	            } else {
	                return minus ? -num : num;
	            }
	            b = readByte();
	        }
   }

	    boolean isSpaceChar(int c) {
	        return (!(c >= 33 && c <= 126));
	       }

	      int skip()
	        {
	        int b;
	        while ((b = readByte()) != -1 && isSpaceChar(b)) ;
	        return b;
	        }

	    float nf() {
	        return Float.parseFloat(is());
	    }

	    double id() {
	        return Double.parseDouble(is());
	    }

	    char ic() {
	        return (char) skip();
	    }

	    int[] iia(int n) {
	        int a[] = new int[n];
	        for (int i = 0; i<n; i++) a[i] = ii();
	        return a;
	    }

	    long[] ila(int n) {
	        long a[] = new long[n];
	        for (int i = 0; i <n; i++) a[i] = il();
	        return a;
	    }

	    String[] isa(int n) {
	        String a[] = new String[n];
	        for (int i = 0; i < n; i++) a[i] = is();
	        return a;
	    }

		 long mul(long a, long b) { return a * b % M; }

			long div(long a, long b)
				 {
					return mul(a, pow(b, M - 2,M));

		           }

	    double[][] idm(int n, int m) {
	        double a[][] = new double[n][m];
	        for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) a[i][j] = id();
	        return a;
	        }

	    int[][] iim(int n, int m) {
	        int a[][] = new int[n][m];
	        for (int i = 0; i < n; i++) for (int j = 0; j <m; j++) a[i][j] = ii();
	        return a;
          }

   public String readLine() {
       int c = read();
       while (isSpaceChar(c))
           c = read();
       StringBuilder res = new StringBuilder();
       do {
           res.appendCodePoint(c);
           c = read();
       } while (!isEndOfLine(c));
       return res.toString();
   }

   public interface SpaceCharFilter
   {
       public boolean isSpaceChar(int ch);
   }
   public boolean isEndOfLine(int c) {
       return c == '\n' || c == '\r' || c == -1;
   }
}

}


//package code;
import java.io.*;
import java.util.*;
import java.util.Map.Entry;
import java.text.*;
import java.math.*;
import java.util.regex.*;
import java.awt.Point;
/**
 *
 * @author prabhat // use stringbuilder,TreeSet, priorityQueue, x+y=(x&y + x|y);
 */
   public class  a
   {
   public static int a[],n;
   public  static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
   static PrintWriter pw;
   public  static void main(String[] args) throws Exception
   {
   	     InputReader in = new InputReader(System.in);
		 pw=new PrintWriter(System.out);
		 n=in.ii();
		int d=in.ii();
		a=in.iia(n);
		int ans=0;
		for(int i=1;i<n;i++)
		{
			if(a[i-1]>a[i])
			{
				int dif=a[i-1]-a[i];
                int t=(int)Math.ceil(dif*1.0/d*1.0);
                ans+=t;
                a[i]+=t*d;
			}
			else if(a[i-1]==a[i])
			{
				ans++;
				a[i]+=d;
			}
		}
		pw.println(ans);
 	   pw.close();
}

public static long pow(long n,long p,long m)
{
	 long  result = 1;
	  if(p==0)
	    return 1;

	while(p!=0)
	{
	    if(p%2==1)
	        result *= n;
	    if(result>=m)
	    result%=m;
	    p >>=1;
	    n*=n;
	    if(n>=m)
	    n%=m;
	}
	return result;
}

static  class InputReader
{
   private InputStream stream;
   private byte[] buf = new byte[1024];

   private SpaceCharFilter filter;
    byte inbuffer[] = new byte[1024];
   int lenbuffer = 0, ptrbuffer = 0;
    final int M = (int) 1e9 + 7;
   int md=(int)(1e7+1);
    int[] SMP=new int[md];
   final double eps = 1e-6;
   final double pi = Math.PI;

	PrintWriter out;
   String check = "";
 InputStream   obj = check.isEmpty() ? System.in : new ByteArrayInputStream(check.getBytes());
   public InputReader(InputStream stream)
   {
       this.stream = stream;
   }

    int readByte() {
	        if (lenbuffer == -1) throw new InputMismatchException();
	        if (ptrbuffer >= lenbuffer) {
	            ptrbuffer = 0;
	            try {
	                lenbuffer = obj.read(inbuffer);
	            } catch (IOException e) {
	                throw new InputMismatchException();
	            }
	        }
	        if (lenbuffer <= 0) return -1;
	        return inbuffer[ptrbuffer++];
   }

   public  int read()
   {
       int c = read();
       while (isSpaceChar(c))
           c = read();
       int sgn = 1;
       if (c == '-')
       {
           sgn = -1;
           c = read();
       }
       int res = 0;
       do
       {
           if (c < '0' || c > '9')
               throw new InputMismatchException();
           res *= 10;
           res += c - '0';
           c = read();
       } while (!isSpaceChar(c));
       return res * sgn;
   }

   String is() {
	        int b = skip();
	        StringBuilder sb = new StringBuilder();
	        while (!(isSpaceChar(b))) // when nextLine, (isSpaceChar(b) && b!=' ')
	        {
	            sb.appendCodePoint(b);
	            b = readByte();
	        }
	        return sb.toString();
   }
   public   int ii() {
	        int num = 0, b;
	        boolean minus = false;
	        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
	        if (b == '-') {
	            minus = true;
	            b = readByte();
	        }
	        while (true) {
	            if (b >= '0' && b <= '9') {
	                num = num * 10 + (b - '0');
	            } else {
	                return minus ? -num : num;
	            }
	            b = readByte();
	        }
   }
 public   long il() {
	        long num = 0;
	        int b;
	        boolean minus = false;
	        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
	        if (b == '-') {
	            minus = true;
	            b = readByte();
	        }
	        while (true) {
	            if (b >= '0' && b <= '9') {
	                num = num * 10 + (b - '0');
	            } else {
	                return minus ? -num : num;
	            }
	            b = readByte();
	        }
   }

	    boolean isSpaceChar(int c) {
	        return (!(c >= 33 && c <= 126));
	       }

	      int skip()
	        {
	        int b;
	        while ((b = readByte()) != -1 && isSpaceChar(b)) ;
	        return b;
	        }

	    float nf() {
	        return Float.parseFloat(is());
	    }

	    double id() {
	        return Double.parseDouble(is());
	    }

	    char ic() {
	        return (char) skip();
	    }

	    int[] iia(int n) {
	        int a[] = new int[n];
	        for (int i = 0; i<n; i++) a[i] = ii();
	        return a;
	    }

	    long[] ila(int n) {
	        long a[] = new long[n];
	        for (int i = 0; i <n; i++) a[i] = il();
	        return a;
	    }

	    String[] isa(int n) {
	        String a[] = new String[n];
	        for (int i = 0; i < n; i++) a[i] = is();
	        return a;
	    }

		 long mul(long a, long b) { return a * b % M; }

			long div(long a, long b)
				 {
					return mul(a, pow(b, M - 2,M));

		           }

	    double[][] idm(int n, int m) {
	        double a[][] = new double[n][m];
	        for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) a[i][j] = id();
	        return a;
	        }

	    int[][] iim(int n, int m) {
	        int a[][] = new int[n][m];
	        for (int i = 0; i < n; i++) for (int j = 0; j <m; j++) a[i][j] = ii();
	        return a;
          }

   public String readLine() {
       int c = read();
       while (isSpaceChar(c))
           c = read();
       StringBuilder res = new StringBuilder();
       do {
           res.appendCodePoint(c);
           c = read();
       } while (!isEndOfLine(c));
       return res.toString();
   }

   public interface SpaceCharFilter
   {
       public boolean isSpaceChar(int ch);
   }
   public boolean isEndOfLine(int c) {
       return c == '\n' || c == '\r' || c == -1;
   }
}

}


import java.util.*;
import java.util.Arrays;
import java.io.IOException;
import java.lang.*;
import java.math.BigDecimal;
import java.util.Scanner;
/* Name of the class has to be "Main" only if the class is public. */
public class Main {

	static Scanner input = new Scanner(System.in);

	public static void main(String [] args)
	{

		int n=0;
		int d=0;

		n = input.nextInt();
		d = input.nextInt();
		int count=0;

			int [] k = new int[n];

			int first = input.nextInt();

			for(int j=1; j<n;j++)
			{
				k[j] = input.nextInt();

					if(first >= k[j])
					{
						int t = (first + 1 - k[j]) / d + ((first + 1 - k[j]) % d == 0 ? 0 :1);

						count += t;
						first = k[j] + t * d;
					}
					else
					{
						first = k[j];
					}

			}
				System.out.println(count);

		//////////////////////////////////////////////
				//////////
	}
}


import java.util.*;
import java.util.Arrays;
import java.io.IOException;
import java.lang.*;
import java.math.BigDecimal;
import java.util.Scanner;
/* Name of the class has to be "Main" only if the class is public. */
public class Main {

	static Scanner input = new Scanner(System.in);

	public static void main(String [] args)
	{

		int n=0;
		int d=0;

		n = input.nextInt();
		d = input.nextInt();
		int count=0;
		int p = input.nextInt();
			int [] k = new int[n];

			for(int j=1; j<n;j++)
			{
				k[j] = input.nextInt();
			 if(j<n){
					if(p >= k[j+1])
					{
						//k[j+1] += d;
						int c =( p + 1 - k[j+1] ) / d + ((p + 1 - k[j+1])% d == 0 ? 0 : 1);
						count++;
						p = k[j+1] + c * d;
					}
					else {
						p = k[j+1];
					}
				}
			}

		System.out.println(count);

	}
}


import java.util.Scanner;

public class IncreasingSequence {
    public static void main(String [] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int d = input.nextInt();

        int [] arr = new int [n];
        for(int i = 0; i < n; i++)
            arr [i] = input.nextInt();

        int counter = 0;
        for(int i = 0; i < n - 1; i++){
            if(arr [i] > arr [i + 1]){
                int diff = arr [i] - arr [i + 1];
                int extra = 0;

                if(diff / d == 0){
                    counter ++;
                    extra = d;
                }
                else if(diff % d == 0){
                    counter += (diff / d);
                    extra = diff + d;
                }

                else{
                    counter += ((diff / d) + 1);
                    extra = diff + d + 1;
                }

                arr [i + 1] = extra;
            }
            else if(arr [i] == arr [i + 1]) {
                counter ++;
                arr [i + 1] += d;
            }
        }

        System.out.println(counter);
    }
}


import java.util.Arrays;
import java.util.Scanner;

public class IncreasingSequence {
    public static void main(String [] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int d = input.nextInt();

        int [] arr = new int [n];
        for(int i = 0; i < n; i++)
            arr [i] = input.nextInt();

        int counter = 0;
        for(int i = 0; i < n - 1; i++){
            if(arr [i] > arr [i + 1]){
                int diff = arr [i] - arr [i + 1];
                int extra = 0;

                if(diff / d == 0){
                    counter ++;
                    extra = d;
                }
                else if(diff % d == 0){
                    counter += (diff / d);
                    extra = diff + d;
                }

                else{
                    counter += ((diff / d) + 1);
                    extra = diff + d + 1;
                }

                arr [i + 1] += extra;
                System.err.println(Arrays.toString(arr));
            }
            else if(arr [i] == arr [i + 1]) {
                counter ++;
                arr [i + 1] += d;
                System.err.println(Arrays.toString(arr));
            }
        }

        System.out.println(counter);
    }
}


import java.util.*;

public class IncreasingSequence {
    public static void main(String [] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int d = input.nextInt();

        int [] arr = new int [n];
        for(int i = 0; i < n; i++)
            arr [i] = input.nextInt();

        int counter = 0;
        for(int i = 0; i < n - 1; i++){
            if(arr [i] == arr [i + 1]){
                counter ++;
                arr [i + 1] += d;
            }
            else if(arr [i] > arr [i + 1]){
                int diff = arr [i] - arr [i + 1];

                if(diff < d){
                    counter ++;
                    arr [i + 1] += d;
                }
                else if(diff == d){
                    counter += 2;
                    arr [i + 1] += (d * 2);
                }
                else{
                    counter += ((diff / d) + 1);
                    arr [i + 1] += (((diff / d) + 1) * d);
                }
            }
        }

        System.out.println(counter);
    }
}


import java.util.Scanner;

public class IncreasingSequence {
    public static void main(String [] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int d = input.nextInt();

        int [] arr = new int [n];
        for(int i = 0; i < n; i++)
            arr [i] = input.nextInt();

        int counter = 0;
        for(int i = 0; i < n - 1; i++){
            if(arr [i] > arr [i + 1]){
                int diff = arr [i] - arr [i + 1];
                int extra = 0;

                if(diff / d == 0){
                    counter ++;
                    extra = d;
                }
                else if(diff % d == 0){
                    counter += (diff / d);
                    extra = diff + d;
                }

                else{
                    counter += ((diff / d) + 1);
                    extra = diff + d + 1;
                }

                arr [i + 1] = extra;
            }
            else if(arr [i] == arr [i + 1])
                counter ++;
        }

        System.out.println(counter);
    }
}


import java.util.*;

public class IncreasingSequence {
    public static void main(String [] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int d = input.nextInt();

        int [] arr = new int [n];
        for(int i = 0; i < n; i++)
            arr [i] = input.nextInt();

        int counter = 0;
        for(int i = 0; i < n - 1; i++){
            if(arr [i] == arr [i + 1]){
                counter ++;
                arr [i + 1] += d;
            }
            else if(arr [i] > arr [i + 1]){
                int diff = arr [i] = arr [i + 1];

                if(diff < d){
                    counter ++;
                    arr [i + 1] += d;
                }
                else if(diff == d){
                    counter += 2;
                    arr [i + 1] += (d * 2);
                }
                else{
                    counter += ((diff / d) + 1);
                    arr [i + 1] += (((diff / d) + 1) * d);
                }
            }
        }

        System.out.println(counter);
    }
}


import java.util.Scanner;
public class Ishu
{
    	public static void main(String[] args)
    	{
	 Scanner scan=new Scanner(System.in);
	 int n,d,i,sum=0,diff,r;
	 int[] b=new int[2000];
	 n=scan.nextInt();
	 d=scan.nextInt();
	 for(i=0;i<n;++i)
		{
		 b[i]=scan.nextInt();
		 if(i>0)
			{
			 if(b[i]<=b[i-1])
				{
				 diff=b[i-1]+1-b[i];
				 r=diff/d;
				 if(diff%d>0)
					++r;
				 sum+=r;
				 b[i]+=r*d;
				}
			}
		}
	 System.out.println(sum);
 	}
}


import java.util.Scanner;
public class Ishu
{
    	public static void main(String[] args)
    	{
	 Scanner scan=new Scanner(System.in);
	 int n,d,i,sum=0;
	 int[] b=new int[2000];
	 n=scan.nextInt();
	 d=scan.nextInt();
	 for(i=0;i<n;++i)
		{
		 b[i]=scan.nextInt();
		 if(i>0)
			{
			 while(b[i]<=b[i-1])
				{
				 b[i]+=d;
			 	 ++sum;
				}
			}
		}
	 System.out.println(sum);
 	}
}


import java.util.Scanner;
public class Ishu
{
    	public static void main(String[] args)
    	{
	 Scanner scan=new Scanner(System.in);
	 int n,d,i,sum=0;
	 int[] b=new int[2000];
	 n=scan.nextInt();
	 d=scan.nextInt();
	 for(i=0;i<n;++i)
		b[i]=scan.nextInt();
	 for(i=1;i<n;++i)
		{
		 while(b[i]<=b[i-1])
			{
			 b[i]+=d;
			 ++sum;
			}
		}
	 System.out.println(sum);
 	}
}


import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int d = in.nextInt();
        int cur = in.nextInt();
        int moves = 0;
        for(int i = 1; i < n; i++){
            int next = in.nextInt();
            if(cur >= next){
                moves += (cur - next) / d + 1;
                cur = next + ((cur - next) / d + 1) * d;
            }
            else{
                cur = next;
            }
        }
        System.out.println(moves);
    }
}


import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int d = in.nextInt();
        int cur = in.nextInt();
        int moves = 0;
        for(int i = 1; i < n; i++){
            int next = in.nextInt();
            if(cur > next){
                moves += (cur - next) / d + 1;
                cur = next + (cur - next) * d;
            }
            else{
                cur = next;
            }

        }
        System.out.println(moves + d);
    }
}


import java.util.*;

public class Slotuin {
	static boolean isIncreasing(long[] A) {
		int c = 0;
		for(int i = 0;i < A.length - 1;i++) {
			if(A[i] < A[i + 1])
			{
				c++;
			}
		}
		if(A.length == c + 1)return true;
		return false;
	}
	public static void main(String[] args) {
		Scanner x = new Scanner(System.in);
		int n = x.nextInt();
		long d = x.nextLong();
		long[] A = new long[n];
		for(int i = 0;i < n;i++)
		{
			A[i] = x.nextLong();
		}
		int c = 0;
		while(!isIncreasing(A))
		{
			for(int i = 0;i < n-1;i++)
			{
				if(A[i] >= A[i + 1])
				{
					A[i + 1] = A[i + 1] + d;
					c++;
				}
			}
		}
		System.out.print(c);
		x.close();
	}

}


import java.util.*;

public class Slotuin {
	public static void main(String[] args) {
		Scanner x = new Scanner(System.in);
		int n = x.nextInt();
		long d = x.nextLong();
		long[] A = new long[n];
		int c = 0;
		for(int i = 0;i < n;i++)
		{
			A[i] = x.nextLong();
			if(i > 0)
			{
				while(A[i - 1] >= A[i])
				{
					A[i] = A[i] + d;
					c++;
				}
			}
		}
		System.out.print(c);
		x.close();
	}

}


import java.util.*;

public class Slotuin {
	public static void main(String[] args) {
		Scanner x = new Scanner(System.in);
		int n = x.nextInt();
		long d = x.nextLong();
		long[] A = new long[n];
		int c = 0;
		for(int i = 0;i < n;i++)
		{
			A[i] = x.nextLong();
			if(i > 1)
			{
				while(A[i - 1] >= A[i])
				{
					A[i] = A[i] + d;
					c++;
				}
			}
		}
		System.out.print(c);
		x.close();
	}

}


import java.util.*;

public class Slotuin {
	public static void main(String[] args) {
		Scanner x = new Scanner(System.in);
		int n = x.nextInt();
		long d = x.nextLong();
		long A0 = x.nextLong();
		long A = 0;
		long c = 0;
		for(int i = 1;i < n;i++)
		{
			A = x.nextLong();
			if(A0 >= A)
			{
				long z = (A0 - A)/d + 1;
				c = c + z;
				A0 = A + z * d;
			}
			else
			{
				A0 = A;
			}
		}
		System.out.print(c);
		x.close();
	}

}


import java.util.*;

public class Slotuin {
	static boolean isIncreasing(long[] A) {
		int c = 0;
		for(int i = 0;i < A.length - 1;i++) {
			if(A[i] < A[i + 1])
			{
				c++;
			}
		}
		if(A.length == c + 1)return true;
		return false;
	}
	public static void main(String[] args) {
		Scanner x = new Scanner(System.in);
		int n = x.nextInt();
		long d = x.nextInt();
		long[] A = new long[n];
		for(int i = 0;i < n;i++)
		{
			A[i] = x.nextInt();
		}
		int c = 0;
		while(!isIncreasing(A))
		{
			for(int i = 0;i < n-1;i++)
			{
				if(A[i] >= A[i + 1])
				{
					A[i + 1] = A[i + 1] + d;
					c++;
				}
			}
		}
		System.out.print(c);
		x.close();
	}

}


import java.util.*;

public class Slotuin {
	public static void main(String[] args) {
		Scanner x = new Scanner(System.in);
		int n = x.nextInt();
		long d = x.nextLong();
		long[] A = new long[n];
		for(int i = 0;i < n;i++)
		{
			A[i] = x.nextLong();
		}
		int c = 0;
		for(int i = 0;i < n-1;i++) {
			while(A[i] >= A[i + 1])
			{
				A[i + 1] = A[i + 1] + d;
				c++;
			}
		}
		System.out.print(c);
		x.close();
	}

}


import java.util.Scanner;

public class Test {

    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int d = in.nextInt();
        int move = 0;
        int a[] = new int[n];
        for(int i=0;i<n;i++){
            a[i] = in.nextInt();
        }
        int last = a[0];
        for(int i=1;i<n;i++){
            if(a[i]>last) {
                last = a[i];
                continue;
            }
            else{
                move = move+(last-a[i])/d;
                move++;
                last = a[i]+move*d;
            }
        }
        System.out.println(move);
    }
}


import java.util.Scanner;

public class Test {

    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int d = in.nextInt();
        int move = 0;
        int a[] = new int[n];
        for(int i=0;i<n;i++){
            a[i] = in.nextInt();
        }
        int last = a[0];
        for(int i=1;i<n;i++){
            if(a[i]>last) {
                last = a[i];
                continue;
            }
            else{
                int x = (last-a[i])/d;
                x++;
                last = a[i]+x*d;
                move+=x;
            }
        }
        System.out.println(move);
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author captainTurtle
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int d = in.nextInt();
            int dizi[] = new int[n];
            int check;
            int sayac = 0;
            for (int i = 0; i < n; i++) {
                dizi[i] = in.nextInt();
            }
            for (int i = 1; i < n; i++) {
                if (dizi[i] > dizi[i - 1]) {
                    continue;
                } else if (dizi[i] == dizi[i - 1]) {
                    dizi[i] += d;
                    sayac += 1;
                } else {
                    check = (int) Math.ceil((dizi[i - 1] - dizi[i]) / (d / 1.0));
                    dizi[i] += d * check;
                    if (dizi[i] == dizi[i - 1]) {
                        check += 1;
                        dizi[i] += d;
                    }
                    sayac += check;
                }
            }
            System.out.print(sayac);
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author captainTurtle
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int d = in.nextInt();
            int dizi[] = new int[n];
            int check;
            int sayac = 0;
            for (int i = 0; i < n; i++) {
                dizi[i] = in.nextInt();
            }
            for (int i = 1; i < n; i++) {
                if (dizi[i] > dizi[i - 1]) {
                    continue;
                } else if (dizi[i] == dizi[i - 1]) {
                    dizi[i] += d;
                    sayac += 1;
                } else {
                    check = (int) Math.ceil((dizi[i - 1] - dizi[i]) / (d / 1.0));
                    dizi[i] += d * check;
                    sayac += check;
                }
            }
            System.out.print(sayac);
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author captainTurtle
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int d = in.nextInt();
            int dizi[] = new int[n];
            int check = 1;
            int sayac = 0;
            for (int i = 0; i < n; i++) {
                dizi[i] = in.nextInt();
            }
            while (check < n) {
                if (dizi[check] > dizi[check - 1])
                    check += 1;
                else {
                    dizi[check] += d;
                    sayac += 1;
                }
            }
            System.out.print(sayac);
        }

    }
}


import java.util.Scanner;

public class Codeforces {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int a = in.nextInt();
        int result = 0;
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            int k = in.nextInt();
            arr[i] = k;
        }
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] <= arr[i - 1]) {
                    result+=((arr[i-1]-arr[i])/a)+1;
                    arr[i]+=(((arr[i-1]-arr[i])/a)+1)*a;
            }
        }
        System.out.println(result);
    }

}


import java.util.Scanner;

public class Codeforces {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int a = in.nextInt();
        int result = 0;
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            int k = in.nextInt();
            arr[i] = k;
        }
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] <= arr[i - 1]) {
                while (arr[i] <= arr[i - 1]) {
                    arr[i] += a;
                    result++;
                }
            }
        }
        System.out.println(result);
    }

}


import java.util.*;
import java.math.*;

public class Main{
    public static void main(String [] args)
    {
        Scanner scan=new Scanner(System.in);
        int n=scan.nextInt();
        int d=scan.nextInt();
        int a[]=new int[n];
        for(int i=0;i<n;i++)
        {
            a[i]=scan.nextInt();
        }

        int ans=0;
        for(int i=1;i<n;i++)
        {
            if(a[i]<=a[i-1])
            {
                int c =(int)(Math.ceil((a[i-1]-a[i]+1)/d*1.0));
                ans +=c;
                a[i] += d*c;
            }
        }
        System.out.println(ans);
    }
}


import java.util.*;
import java.math.*;

public class Main{
    public static void main(String [] args)
    {
        Scanner scan=new Scanner(System.in);
        int n=scan.nextInt();
        int d=scan.nextInt();
        int a[]=new int[n];
        for(int i=0;i<n;i++)
        {
            a[i]=scan.nextInt();
        }

        int ans=0;
        for(int i=2;i<=n;i++)
        {
            if(a[i]<=a[i-1])
            {
                int c =(int)(Math.ceil((a[i-1]-a[i]+1)/d*1.0));
                ans +=c;
                a[i] += d*c;
            }
        }
        System.out.println(ans);
    }
}


import java.util.*;
import java.math.*;

public class Main{
    public static void main(String [] args)
    {
        Scanner scan=new Scanner(System.in);
        int n=scan.nextInt();
        int d=scan.nextInt();
        int a[]=new int[n];
        for(int i=0;i<n;i++)
        {
            a[i]=scan.nextInt();
        }

        int ans=0;
        for(int i=1;i<n;i++)
        {
            if(a[i]<=a[i-1])
            {
                int c =(int)(Math.ceil((a[i-1]-a[i]+1)/(d*1.0)));
                ans +=c;
                a[i] += d*c;
            }
        }
        System.out.println(ans);
    }
}


import java.util.*;
//10:39
public class IncreasingSequence {

    public static void main(String s[])
    {
        int n,d;

        Scanner inp = new Scanner(System.in);
        int count=0;
        n= inp.nextInt();
        d= inp.nextInt();

        int arr[] = new int[n];

        for(int i=0;i<n;i++)
            arr[i]= inp.nextInt();

        for(int i=1;i<arr.length;i++)
        {
            while(arr[i]<=arr[i-1])
            {
                arr[i]+=d;
                count++;
            }

        }

        System.out.println(count);
    }

}


import java.util.*;
//10:39
public class IncreasingSequence {

    public static void main(String s[])
    {
        int nn,d;

        Scanner inp = new Scanner(System.in);
        int count=0;
        nn= inp.nextInt();
        d= inp.nextInt();

        int arr[] = new int[nn];

        for(int i=0;i<nn;i++)
            arr[i]= inp.nextInt();

        for(int i=1;i<arr.length;i++)
        {
            if(arr[i]>arr[i-1])
                continue;

            double  n= (arr[i-1]-arr[i])/(double)d;

            if( (n - (int)n) ==0)
                n = n+1;
            arr[i]+= Math.ceil(n)*d;

            count+=Math.ceil(n);

        }

        System.out.println(count);
    }

}


//package main;

import java.io.*;
import java.util.*;

public class Main{
    public static void main(String[] args) throws IOException {
        Reader.init(System.in);
        //StringBuffer outBuffer = new StringBuffer();

        int N = Reader.nextInt();
        int D = Reader.nextInt();
        int[] B = new int[N];
        int moves = 0;

        for(int i = 0; i < N; i++) {
            B[i] = Reader.nextInt();
        }
        for(int i = 0; i < N-1; i++) {
           while(B[i] >= B[i+1]) {
               B[i+1] += D;
               moves++;
           }
        }

        System.out.print(moves);
    }
}

// Class for buffered reading int and double values
// From: http://www.cpe.ku.ac.th/~jim/java-io.html
class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    //call this method to initialize reader for InputStream
    static void init(InputStream input) {
        reader = new BufferedReader(
                     new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }

    //get next word
    static String next() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                   reader.readLine() );
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt( next() );
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble( next() );
    }
}


//package main;

import java.io.*;
import java.util.*;

public class Main{
    public static void main(String[] args) throws IOException {
        Reader.init(System.in);
        //StringBuffer outBuffer = new StringBuffer();

        int N = Reader.nextInt();
        int D = Reader.nextInt();
        int[] B = new int[N];
        int moves = 0;
        int deltaM;
        int difference;

        for(int i = 0; i < N; i++) {
            B[i] = Reader.nextInt();
        }
        for(int i = 0; i < N-1; i++) {
           if(B[i] >= B[i+1]) {
               difference = (B[i]+1) - B[i+1];
               deltaM = (int)Math.ceil(((double)difference)/D);
               B[i+1] += deltaM*D;
               moves+=deltaM;
           }
        }

        System.out.print(moves);
    }
}

// Class for buffered reading int and double values
// From: http://www.cpe.ku.ac.th/~jim/java-io.html
class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    //call this method to initialize reader for InputStream
    static void init(InputStream input) {
        reader = new BufferedReader(
                     new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }

    //get next word
    static String next() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                   reader.readLine() );
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt( next() );
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble( next() );
    }
}


import java.util.Scanner;

public class A11 {

	public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int d=sc.nextInt();
		int [] a=new int [n];
		for(int i=0;i<n;i++)
			a[i]=sc.nextInt();
		int res=0;
		for(int i=0;i<n-1;i++){

			while(a[i+1]<=a[i]){
				a[i+1]+=d;
				res++;
			}
		}
		System.out.println(res);
	}
}


import java.util.Scanner;

public class A11 {

    public static void main(String[] args) {

        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int d=sc.nextInt();

        int res=0;
        int prev=sc.nextInt();
        for(int i=1; i < n; i++)
        {
            int next=sc.nextInt();
            if(next<=prev){
                res+=(prev-next)/d+1;
                prev=next+((prev-next)/d + 1)*d;
            }
            else
                prev=next;

        }
        System.out.println(res);
    }
}


import java.util.Scanner;

public class A11 {

	public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int d=sc.nextInt();

		int res=0;
		int i=0;
		int prev=sc.nextInt();
		while(i<n-1){
			int next=sc.nextInt();
			while(next<=prev){
				next+=d;
				res++;
			}
			prev=next;
			i++;
		}
		System.out.println(res);
	}
}


import java.util.Scanner;

public class A11 {

    public static void main(String[] args) {

        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int d=sc.nextInt();

        int res=0;
        int i=0;
        int prev=sc.nextInt();
        while(i<n-1){
            int next=sc.nextInt();
            if(next<=prev){
                res+=(prev-next)/d+1;
            }
            prev=next+((prev-next)/d + 1)*d;
            i++;
        }
        System.out.println(res);
    }
}


import java.util.Scanner;

public class A11 {

    public static void main(String[] args) {

        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int d=sc.nextInt();
        int [] a=new int [n];

        a[0]=sc.nextInt();
        int res=0;
        for(int i=1;i<n;i++){
            a[i]=sc.nextInt();
            while(a[i]<=a[i-1]){
                a[i]+=d;
                res++;
            }
        }
        System.out.println(res);
    }
}


import java.util.Scanner;

public class A11 {

	public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int d=sc.nextInt();

		int res=0;
		int prev=sc.nextInt();
		for(int i=1; i < n; i++)
        {
			int next=sc.nextInt();
			if(next<=prev){
				res+=(prev-next)/d+1;
				prev=next+((prev-next)/d + 1)*d;
			}

		}
		System.out.println(res);
	}
}


//http://codeforces.com/problemset/problem/11/A
import java.util.Scanner;

public class GrowingSequence {
    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = sc.nextInt(), d = Integer.parseInt(sc.nextLine().trim()), counter = 0;
        int[] elements = new int[n];
        for (int i = 0; i < n; i++){
            elements[i] = sc.nextInt();
            if (i > 0){
                if (elements[i] < elements[i-1]){
                    double temp = Math.ceil(((double) elements[i-1] - (double) elements[i])/d);
                    elements[i] += d*temp;
                    counter+=temp;
                }
                if (elements[i] == elements[i-1]) {
                    elements[i] += d;
                    counter++;
                }
            }
        }
        for (int i: elements){
            System.out.print(i + " ");
        }
        System.out.println(counter);
    }
}


//http://codeforces.com/problemset/problem/11/A
import java.util.Scanner;

public class GrowingSequence {
    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = sc.nextInt(), d = Integer.parseInt(sc.nextLine().trim()), counter = 0;
        int[] elements = new int[n];
        for (int i = 0; i < n; i++){
            elements[i] = sc.nextInt();
            if (i > 0){
                if (elements[i] < elements[i-1]){
                    double temp = Math.ceil(((double) elements[i-1] - (double) elements[i])/d);
                    elements[i] += d*temp;
                    counter+=temp;
                }
                if (elements[i] == elements[i-1]) {
                    elements[i] += d;
                    counter++;
                }
            }
        }
        System.out.println(counter);
    }
}


import java.io.*;

public class CF11A {
    static int n, d, count = 0;
    static String[] in;
    static int[] b = new int[2001];
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        in = br.readLine().split(" ");
        n = Integer.parseInt(in[0]);
        d = Integer.parseInt(in[1]);
        in = br.readLine().split(" ");
        for (int i = 0; i < n; i++) {
            b[i] = Integer.parseInt(in[i]);
        }
        for (int i = 1; i < n; i++) {
            if (b[i - 1] >= b[i]) {
                int t = b[i - 1] - b[i];
                int s = t / d + 1;
                b[i] += s * d;
                count += s;
            }
        }
        bw.write(count + "\n");
        bw.flush();bw.close();
    }
}


import java.io.*;

public class CF11A {
    static int n, d, count = 0;
    static String[] in;
    static int[] b = new int[2001];
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        in = br.readLine().split(" ");
        n = Integer.parseInt(in[0]);
        d = Integer.parseInt(in[1]);
        in = br.readLine().split(" ");
        for (int i = 0; i < n; i++) {
            b[i] = Integer.parseInt(in[i]);
        }
        for (int i = 1; i < n; i++) {
            if (b[i - 1] >= b[i]) {
                while (b[i - 1] >= b[i]) {
                    b[i] += d;count++;
                }
            }
        }
        bw.write(count + "\n");
        bw.flush();bw.close();
    }
}


//package kitsune;
import java.util.*;
public class increasingseq {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int d = s.nextInt();
		int[] num = new int[n];
		for(int i =0; i<n; i++){
			num[i] = s.nextInt();
		}
		int diff;
		int count = 0;
		for(int i=0;i<n-1;i++){
			int k =0;
			if(!(num[i]<num[i+1])){
				diff = num[i]-num[i+1];
				if(diff == 0){
					num[i+1] += d;
					count++;
				}
				else{
					int tmp = 0;
					tmp = diff/d+1;
					num[i+1] += tmp*d;
					count += tmp;
					//System.out.println(k);
				}
			}
		}
		//for(int x:num)
			//System.out.printf("%s ",x);
		System.out.println(count);
	}

}


//package kitsune;
import java.util.*;
public class increasingseq {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int d = s.nextInt();
		int[] num = new int[n];
		for(int i =0; i<n; i++){
			num[i] = s.nextInt();
		}
		int diff;
		int count = 0;
		for(int i=0;i<n-1;i++){
			int k =0;
			if(!(num[i]<num[i+1])){
				diff = num[i]-num[i+1];
				if(diff == 0){
					num[i+1] += d;
					count++;
				}
				else{
					int tmp = 0;
					while((tmp<diff)){
						tmp = d*k;
						if(tmp>=diff)
							break;
						k++;

					}
					num[i+1] += tmp;
					count += k;
					//System.out.println(k);
				}
			}
		}
		System.out.println(count);
	}

}