Blocks: Maximum Alternating Binary Value

Company: Infosys_1staug

Difficulty: medium

Problem Statement

Blocks: Maximum Alternating Binary Value You are given an integer N and two arrays A and B , each of length N . A[i] is the size of a block made of A[i] consecutive 1 bits. There are N such blocks. B[i] is the size of a block made of B[i] consecutive 0 bits. There are N such blocks. Arrange all 2N blocks in one row so that no two neighbouring blocks have the same bit value, then read the row as one binary number. Among all valid arrangements, find the largest such number and print it modulo 10^9 + 7 . Rules: Every block of A and every block of B is used exactly once. Blocks strictly alternate between a block of 1 bits and a block of 0 bits. The row may start with either kind of block. The arrangements are compared by their true values; the modulo is applied only to the printed answer. Implement the function ans(N, A, B) , which returns that value modulo 10^9 + 7 . Input Format The first line contains the integer N . Each of the next N lines contains one integer A[i] . Each of the next