#include #include using namespace std; using namespace atcoder; #define rep(i, n) REP(i, 0, n) #define REP(i, s, e) for (int i = (s); i < (int)(e); i++) #define repr(i, n) REPR(i, n, 0) #define REPR(i, s, e) for (int i = (int)(s - 1); i >= (int)(e); i--) #define all(r) r.begin(), r.end() #define rall(r) r.rbegin(), r.rend() typedef long long ll; typedef vector vi; typedef vector vl; template T chmax(T& a, const U& b) { if (a >= b) return false; a = b; return true; } template T chmin(T& a, const U& b) { if (a <= b) return false; a = b; return true; } void yes_no(bool f, string yes = "Yes", string no = "No") { cout << (f ? yes : no) << "\n"; } void solve() { const int n = 7; vi mi(n), ma(n); rep(i, n) cin >> mi[i] >> ma[i]; using mint = modint1000000007; mint ans = 0; vi id(n); rep(i, n) id[i] = i; const int sz = *max_element(all(ma)) + 10; do { vi rev(n); rep(i, n) rev[id[i]] = i; { int x = min({rev[1], rev[3], rev[5]}); int y = max({rev[1], rev[3], rev[5]}); int a = min({rev[0], rev[2], rev[4], rev[6]}); int b = max({rev[0], rev[2], rev[4], rev[6]}); if (x > b || y < a) { } else continue; } vector dp(sz); dp[0] = 1; for (auto&& i : id) { vector nxt(sz); rep(j, sz - 1) dp[j + 1] += dp[j]; REP(j, mi[i], ma[i] + 1) nxt[j] += dp[j - 1]; swap(dp, nxt); } ans += accumulate(all(dp), mint(0)); } while (next_permutation(all(id))); cout << ans.val() << "\n"; } int main() { cin.tie(0); ios::sync_with_stdio(false); int t = 1; // multi-testcase // cin >> t; rep(ti, t) solve(); return 0; }