Three balls

아직 제출이 없습니다시간 제한5초메모리 제한1024 MB

문제

Central European Regional Contest (CERC) is a contest famous for its interesting and always well-prepared tasks. One of these tasks was about finding a volume of a sum of three balls. Maybe it was a challenge 10 years ago, but nowadays contestants should not be bothered with so easy and standard problems. Instead of using 3D space, we will use nn-dimensional hypercube. Obviously, it requires some definitions.

nn-dimensional hypercube has 2n2^n vertices, each of them is represented by a sequence of nn coordinates which are either 00 or 11. For example, 33-dimensional hypercube has 88 vertices: 000, 001, 010, 011, 100, 101, 110, 111.

Ball with radius rr and center ss is a subset of vertices of hypercube which have distance at most rr to the vertex ss. We compute the distance in Manhattan metric which means that vertex pp belongs to this ball if and only if coordinates of vertices pp and ss differ on at most rr positions.

Find the number of vertices which belong to the sum of three balls, i.e. number of vertices which belong to at least one of these balls. Print the result modulo 109+710^9+7.

입력

First line of input contains one integer nn (1n10,0001 \leq n \leq 10\\,000), denoting number of dimensions.

Description of three balls follow. Each description takes one line and ii-th line contains integer r_ir\_i (0r_in0 \leq r\_i \leq n) and binary word s_is\_i consisting of nn characters which are either 00 or 11. These are the radius and the center of the ball, respectively.

출력

You need to print one integer --- number of vertices belonging to sum of these three balls, modulo 109+710^9+7.

힌트

Explanation to first sample test: 33-dimensional hypercube is just a mere cube. Following pictures show which vertices belong to following balls. Grey circle denotes center of a ball.

First ball contains vertices 000, 100, 010, 001. Second ball contains vertices 100, 000, 110, 101. Third ball is just a single vertex 111. Sum of these balls contains 77 vertices --- all of them except 011.