def read_data(): minmaxs = [] for i in range(7): min_i, max_i = map(int, input().split()) minmaxs.append((min_i, max_i)) return minmaxs def solve(minmaxs): mod = 10**9 + 7 minmaxs3 = (minmaxs[1], minmaxs[3], minmaxs[5]) minmaxs4 = (minmaxs[0], minmaxs[2], minmaxs[4], minmaxs[6]) count = 0 for i, minmax in enumerate(minmaxs4): minmaxs3b = minmaxs4[:i] + minmaxs4[i + 1:] count += count_top_mid_bottom(minmaxs3, minmax, minmaxs3b, mod) count += count_top_mid_bottom(minmaxs3b, minmax, minmaxs3, mod) return count % mod def count_top_mid_bottom(minmaxsA, minmax, minmaxsB, mod): count = 0 for mid in range(minmax[0], minmax[1] + 1): top = count_top(minmaxsA, mid + 1, mod) if top == 0: continue bottom = count_bottom(minmaxsB, mid - 1, mod) count += top * bottom return count % mod def count_top(minmaxs, lower, mod): for min_i, max_i in minmaxs: if max_i < lower: return 0 minmaxs = [(max(lower, min_i), max_i) for min_i, max_i in minmaxs] return count_pattern(minmaxs, mod) def count_bottom(minmaxs, upper, mod): for min_i, max_i in minmaxs: if min_i > upper: return 0 minmaxs = [(min_i, min(upper, max_i)) for min_i, max_i in minmaxs] return count_pattern(minmaxs, mod) def count_pattern(minmaxs, mod): widths = [max_i - min_i + 1 for min_i, max_i in minmaxs] count = widths[0] * widths[1] * widths[2] # 0, {1,2} lower = max(minmaxs[1][0], minmaxs[2][0]) upper = min(minmaxs[1][1], minmaxs[2][1]) if lower <= upper: count -= (upper - lower + 1) * widths[0] # 1, {0,2} lower = max(minmaxs[0][0], minmaxs[2][0]) upper = min(minmaxs[0][1], minmaxs[2][1]) if lower <= upper: count -= (upper - lower + 1) * widths[1] # 2, {0,1} lower = max(minmaxs[0][0], minmaxs[1][0]) upper = min(minmaxs[0][1], minmaxs[1][1]) if lower <= upper: count -= (upper - lower + 1) * widths[2] # {0,1,2} lower = max(lower, minmaxs[2][0]) upper = min(upper, minmaxs[2][1]) if lower <= upper: count += (upper - lower + 1) * 2 return count % mod minmaxs = read_data() print(solve(minmaxs))