#include<bits/stdc++.h> usingnamespace std; template <typename T> inlinevoidread(T &a){ T w=1; a=0; char ch=getchar(); for(;ch < '0' || ch > '9';ch=getchar()) if(ch == '-') w=-1; for(;ch>='0'&&ch<='9';ch=getchar()) a=(a<<3)+(a<<1)+(ch^48); a*=w; } template <typename T> inlinevoidckmax(T &a, T b){a = a > b ? a : b;} template <typename T> inlinevoidckmin(T &a, T b){a = a < b ? a : b;} #define fi first #define se second #define pb push_back #define mp make_pair #define mii map<int, int> #define pii pair<int, int> #define vi vector<int> #define Debug(x) cout << #x << " = " << x << endl #define For(i,l,r) for (int i = l; i <= r; ++i) #define foR(i,l,r) for (int i = l; i >= r; --i) constint N = 2e5 + 10; constint Mod = 1e9 + 7; inlineintMul(int x, int y){ return (1ll * x * y >= Mod) ? (1ll * x * y % Mod) : (x * y); } inlineintAdd(int a, int b){ return (a + b >= Mod) ? (a + b - Mod) : (a + b); } inlineintSub(int a, int b){ return (a < b) ? (a + Mod - b) : (a - b); } intqpow(int a, int b){ int base = a, ans = 1; while (b) { if (b & 1) ans = Mul(ans, base); base = Mul(base, base); b >>= 1; } return ans; } structedge { int to, nxt; } e[N << 1]; int head[N], cnt, n; inlinevoidadd(int u, int v){ e[++cnt].to = v; e[cnt].nxt = head[u]; head[u] = cnt; } int dep1[N], dep2[N]; voiddfs(int u, int fa, int *dep){ for(int i = head[u]; i; i = e[i].nxt) { int v = e[i].to; if(v != fa) { dep[v] = dep[u] + 1; dfs(v, u, dep); }} } int dep[N], pw[N], pre[N], L, R; intmain(){ read(n); For (i, 1, n - 1) { int u, v; read(u); read(v); add(u, v), add(v, u); } dfs(1, 0, dep); L = std::max_element(dep + 1, dep + n + 1) - dep; dep[L] = 0; dfs(L, 0, dep); R = std::max_element(dep + 1, dep + n + 1) - dep; pw[0] = 1; for(int i = 1; i <= n; i++) pw[i] = (pw[i - 1] << 1) % Mod; dfs(R, 0, dep2); int lower = 0; for(int i = 1; i <= n; i++) { if(i == L || i == R) continue; lower = std::max(lower, std::min(dep[i], dep2[i])); pre[std::max(dep[i], dep2[i])]++; } for(int i = 1; i < n; i++) pre[i] += pre[i - 1]; int ans = 1ll * pw[pre[lower]] * lower % Mod; for(int i = lower + 1; i < n; i++) { ans = (ans + 1ll * i * (pw[pre[i]] - pw[pre[i - 1]] + Mod) % Mod) % Mod; } ans = (ans * 2 + 1ll * dep[R] * pw[n - 1]) % Mod; printf("%d\n", ans); }