Under construction

Still being built. Things may change

Three Balls

Time limit5sMemory limit1024 MB

Summary
Given n-dimensional hypercube and three balls with radii and binary centers under Manhattan distance, count vertices covered by at least one ball modulo 1e9+7.
Level

Medium7 of 10

Topics
Combinatorics, Math, Intervals
Solved
No attempts yet

Problem

The Central European Regional Contest (CERC) is known for its interesting and well-prepared tasks. One of these tasks asked for the volume of a sum of three balls. That may have been a challenge ten years ago, but contestants today should not spend time on such easy, standard problems. This problem uses an nn-dimensional hypercube instead of 3D space, so some definitions come first.

An nn-dimensional hypercube has 2n2^n vertices. Each vertex is a sequence of nn coordinates, and each coordinate is either 00 or 11. For example, the 3-dimensional hypercube has 8 vertices: 000, 001, 010, 011, 100, 101, 110, 111.

A ball with radius rr and center ss is a set of vertices at distance at most rr from the vertex ss. The distance is the Manhattan distance. A vertex pp belongs to the ball if and only if pp and ss differ in at most rr positions.

Find the number of vertices that belong to the sum of the three balls, that is, the vertices that belong to at least one of them. Print the result modulo 109+710^9+7.

Input

The first line contains an integer nn (1≤n≤10 0001 \leq n \leq 10\,000), the number of dimensions.

Each of the next three lines describes one ball. Each line contains an integer rir_i (0≤ri≤n0 \leq r_i \leq n), the radius, and a binary string sis_i of length nn, the center.

Output

Print one integer, the number of vertices in the sum of the three balls, modulo 109+710^9+7.

Hint

The figure below shows the first sample. The 3-dimensional hypercube is a cube. The grey circle marks the center of each ball.

Examples2

  1. Example 1

    Input
    3
    1 000
    1 100
    0 111
    
    Expected output
    7
    
  2. Example 2

    Input
    5
    2 10110
    0 11010
    1 00000
    
    Expected output
    19