QOJ.ac

QOJ

Time Limit: 7 s Memory Limit: 1024 MB Total points: 10

#213. Three balls [B]

Statistics

The Central Europe Regional Contest (CERC) is a competition famous for its interesting and well-prepared problems. One such problem* involved finding the volume of the union of three spheres, i.e., the set of points belonging to at least one of these spheres. This might have been a challenge 10 years ago, but nowadays, we should not bore contestants with something so easy and standard. Instead of a three-dimensional space, let us use an $n$-dimensional hypercube. This, of course, requires some definitions.

An $n$-dimensional hypercube has $2^n$ vertices, each described by a sequence of $n$ coordinates of 0 and 1. For example, a three-dimensional hypercube has 8 vertices: 000, 001, 010, 011, 100, 101, 110, 111.

A hyperball with radius $r$ and center $s$ is the set of vertices of the hypercube that are at a distance of at most $r$ from vertex $s$. We calculate the distance using the Manhattan metric; therefore, a vertex $p$ belongs to a hyperball with radius $r$ and center $s$ if and only if the coordinates of vertices $p$ and $s$ differ in at most $r$ positions.

Find the number of vertices that belong to the union of three given hyperballs, i.e., the number of vertices belonging to at least one of them. Output the result modulo $10^9 + 7$.

Input

The first line of input contains a single integer $n$ ($1 \le n \le 10\,000$), representing the number of dimensions.

The description of the hyperballs is provided in the next three lines: the $i$-th of these lines contains an integer $r_i$ ($0 \le r_i \le n$) and a binary string $s_i$ consisting of $n$ characters 0 and 1. These are the radius and center of the $i$-th hyperball, respectively.

Output

Output a single integer — the number of vertices belonging to the union of the three hyperballs, modulo $10^9 + 7$.

Examples

Input 1

3
1 000
1 100
0 111

Output 1

7

Input 2

5
2 10110
0 11010
1 00000

Output 2

19

Note

Explanation of the first example: A three-dimensional hypercube is simply a cube. The drawings below show the vertices that belong to the individual hyperballs. The gray circle denotes the center of the hyperball.

The first hyperball contains vertices 000, 100, 010, 001. The second contains vertices 100, 000, 110, 101. The third is the single vertex 111. The union of the hyperballs contains 7 vertices — all except 011.

Subtasks

There is at least one group of tests where $r_i \le 500$. There is also at least one group of tests where each contains at least two identical hyperballs (the same radius and center).

*CERC 2009, problem E: http://cepc09.ii.uni.wroc.pl/lost2.pdf

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.