#include "hexagon.h"
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ff first
#define sc second
#define pb push_back
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define ull unsigned long long
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
// #define int long long
// #define int unsigned long long
// #define ordered_set(T) tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
// #define ordered_multiset(T) tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>
void open_file(string filename) {
freopen((filename + ".in").c_str(), "r", stdin);
freopen((filename + ".out").c_str(), "w", stdout);
}
const ll mod = 1e9 + 7;
// const ll mod = 998244353;
const ll inf = 1e9;
const ll biginf = 1e18;
const int maxN = 2 * 1e5 + 25;
int dx[] = {-1, 1, 1, 0, -1, -1};
int dy[] = {0, -1, 0, 1, 0, -1};
int dist[4015][4015];
bool used[4015][4015][2];
int draw_territory(int n, int a, int b, vector<int> d, vector<int> l) {
int x = 2001, y = 2001;
used[x][y][0] = 1;
for (int i = 0; i < n; i++) {
--d[i];
while (l[i]--) {
x += dx[d[i]];
y += dy[d[i]];
used[x][y][0] = 1;
}
} queue<int> q;
q.push(0); q.push(0);
used[0][0][1] = 1;
while (!q.empty()) {
int x = q.front(); q.pop();
int y = q.front(); q.pop();
for (int i = 0; i < 6; i++) {
int ax = x + dx[i];
int ay = y + dy[i];
if (ax >= 0 && ay >= 0 && ax <= 4010 && ay <= 4010 && !used[ax][ay][0] && !used[ax][ay][1]) {
q.push(ax); q.push(ay); used[ax][ay][1] = 1;
}
}
} for (int i = 0; i <= 4010; i++) {
for (int j = 0; j <= 4010; j++) {
if (!used[i][j][1]) {
used[i][j][0] = 1;
}
}
} ll ans = a;
q.push(2001); q.push(2001);
used[2001][2001][0] = 0;
while (!q.empty()) {
int x = q.front(); q.pop();
int y = q.front(); q.pop();
for (int i = 0; i < 6; i++) {
int ax = x + dx[i];
int ay = y + dy[i];
if (used[ax][ay][0] == 1) {
used[ax][ay][0] = 0;
dist[ax][ay] = dist[x][y] + 1;
ans = (ans + a + 1LL * b * dist[ax][ay]) % mod;
q.push(ax); q.push(ay);
}
}
} return ans;
}
// int main() {
// int N;
// assert(1 == scanf("%d", &N));
// std::vector<int> U(N - 1), V(N - 1), W(N - 1);
// for (int i = 0; i < N - 1; ++i) {
// assert(3 == scanf("%d %d %d", &U[i], &V[i], &W[i]));
// }
// std::vector<long long> closure_costs = minimum_closure_costs(N, U, V, W);
// for (int i = 0; i < static_cast<int>(closure_costs.size()); ++i) {
// if (i > 0) {
// printf(" ");
// }
// printf("%lld",closure_costs[i]);
// }
// printf("\n");
// return 0;
// }