Under construction

Still being built. Things may change

Hexagonal Region

Time limit2sMemory limit1024 MB

Summary
Given a closed, simple hex-grid path of N moves, sum A + d*B over every cell in the enclosed region, where d is the distance from the start.
Level

Hard8 of 10

Topics
Geometry, Shortest path, Math
Solved
No attempts yet

Problem

Hexagonal tiles are laid out in an infinite grid of cells, and Jaehyeon stands on a cell called the "starting cell". Two cells are neighbors if they share an edge. As shown in the figure below, each move lets Jaehyeon step to a neighboring cell in one of six directions numbered 1 to 6.

The path formed by Jaehyeon's NN moves forms a region. On the ii-th move, he travels L[i]L[i] cells in direction D[i]D[i]. The path has the following properties.

  • The path is closed. The last cell reached is the starting cell.
  • The path is simple. Every cell except the starting cell is visited at most once. The starting cell is visited exactly twice, counting the first and last positions together.
  • The path is exposed. Every cell on the path has at least one neighbor that is not on the path and is not interior.
    • A cell not on the path is interior if the number of cells that can be visited from it without passing through any cell on the path is finite.

The following is one path Jaehyeon can take.

  • Cell 1 (pink) is the starting (and ending) cell.
  • Light blue cells are on the path, and the visit order is written inside each cell.
  • Dark blue cells marked with an x are interior cells.

The region consists of all cells on the path or in the interior. The distance of a cell cc in the region is the minimum number of moves needed to reach cc from the starting cell, moving only through cells in the region. The score of a cell in the region is A+d×BA + d \times B, where AA and BB are constants chosen in advance by Jaehyeon and dd is the distance of that cell.

The figure below shows the distance of each cell in the region formed by the path above.

Write a program that computes the sum of the scores of all cells in the region formed by Jaehyeon's NN moves. The total can be very large, so output it modulo 109+710^9 + 7.

Constraints

  • 3≤N≤200 0003 \le N \le 200\,000
  • 0≤A,B≤100 \le A, B \le 10
  • 1≤D[i]≤61 \le D[i] \le 6 (for all 0≤i≤N−10 \le i \le N - 1)
  • 1≤L[i]1 \le L[i] (for all 0≤i≤N−10 \le i \le N - 1)
  • The sum of all elements of LL does not exceed 10910^9.

Examples1

  1. Example 1

    Input
    3 1 1
    1 1
    3 1
    5 1
    
    Expected output
    5