Three Balls
Time limit5sMemory limit1024 MB
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 -dimensional hypercube instead of 3D space, so some definitions come first.
An -dimensional hypercube has vertices. Each vertex is a sequence of coordinates, and each coordinate is either or . For example, the 3-dimensional hypercube has 8 vertices: 000, 001, 010, 011, 100, 101, 110, 111.
A ball with radius and center is a set of vertices at distance at most from the vertex . The distance is the Manhattan distance. A vertex belongs to the ball if and only if and differ in at most 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 .
Input
The first line contains an integer (), the number of dimensions.
Each of the next three lines describes one ball. Each line contains an integer (), the radius, and a binary string of length , the center.
Output
Print one integer, the number of vertices in the sum of the three balls, modulo .
Hint
The figure below shows the first sample. The 3-dimensional hypercube is a cube. The grey circle marks the center of each ball.
