# Xor and Sum

### Problem Statement :

```You are given two positive integers a and b in binary representation. You should find the following sum modulo 10^9 + 7:

where operation xor means exclusive OR operation, operation shl means binary shift to the left.

Please note, that we consider ideal model of binary integers. That is there is infinite number of bits in each number, and there are no disappearings (or cyclic shifts) of bits.

Input Format

The first line contains number a (1 <= a <2^10^5)  in binary representation. The second line contains number b (1 < = b < 2^10^5)  in the same format. All the numbers do not contain leading zeros.

Output Format

Output a single integer - the required sum modulo 10^9 + 7.```

### Solution :

```                            ```Solution in C :

In C++ :

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

#define long long long
#define mod 1000000007ll
#define M 500500
#define N 13001000

const int T = 314159;

string a, b;
long p[M], x[M], s[N];

void pre() {
p[0] = 1;
for (int i = 1; i < M; ++i)
p[i] = (2 * p[i - 1]) % mod;
}

cin >> a >> b;

for (int i = 0; i < (int) a.length(); ++i)
x[a.length() - 1 - i] = a[i] == '1' ? 1 : 0;

for (int i = 0; i < (int) b.length(); ++i)
s[b.length() - 1 - i + M] = b[i] == '1' ? 1 : 0;

for (int i = 1; i < N; ++i)
s[i] += s[i - 1];
}

long sum(int l, int r) {
return s[r + M] - s[l + M];
}

void kill() {
long ans = 0;
for (int i = 0; i < M; ++i)
if (x[i] == 0)
ans = (ans + p[i] * sum(i - T - 1, i)) % mod;
else
ans = (ans + p[i] * (T + 1 - sum(i - T - 1, i))) % mod;

cout << ans << "\n";
}

int main() {
#ifdef TROLL
freopen("test.in", "r", stdin);
freopen("test.out", "w", stdout);
#else
ios_base::sync_with_stdio(0);
#endif

pre();
kill();

return 0;
}

In Java :

import java.util.Scanner;

public class Solution {
public static void main(String[] args) {
final int n = 314159;
final int maxlen = 1000000;
final int mod = 1000000007;
Scanner in = new Scanner(System.in);
char a[] = in.nextLine().toCharArray();
char b[] = in.nextLine().toCharArray();
int bina[] = new int[maxlen];
int binb[] = new int[maxlen];
int bone[] = new int[maxlen];
for(int i=0;i<a.length;i++){
bina[i]=a[a.length-1-i]-'0';
}
for(int i=a.length;i<maxlen;i++){
bina[i]=0;
}
for(int i=0;i<b.length;i++){
binb[i]=b[b.length-1-i]-'0';
}
for(int i=b.length;i<maxlen;i++){
binb[i]=0;
}
bone[0]=binb[0];
for(int i = 1;i <= n;i++){
bone[i]=bone[i-1]+binb[i];
}
for(int i=n+1;i<1000000;i++){
bone[i]=bone[i-1]+binb[i]-binb[i-n-1];
}
long sum = 0;
long mul = 1;
for(int i=0;i<maxlen;i++){
if(bina[i]==1){
sum = (sum + (mul*(n+1-bone[i]))%mod)%mod;
} else if(bina[i]==0){
sum = (sum + (mul*(bone[i]))%mod)%mod;
}
mul=(mul*2)%mod;
}
System.out.println(sum);
}
}

In C :

#include <stdio.h>
#include <stdlib.h>
#define MOD 1000000007
#define s(k) scanf("%d",&k);
#define sll(k) scanf("%lld",&k);
#define p(k) printf("%d\n",k);
#define pll(k) printf("%lld\n",k);
#define f(i,N) for(i=0;i<N;i++)
#define f1(i,N) for(i=0;i<=N;i++)
#define f2(i,N) for(i=1;i<=N;i++)
#define lim 314160
typedef long long ll;
void rev(char* in){
int start=0,end=strlen(in)-1,i,l=strlen(in);
char t;
while(start<end){
t=in[start];
in[start]=in[end];
in[end]=t;
start++;
end--;
}
for(i=strlen(in);i<lim+l;i++)
in[i]='0';
}
int main(){
char A[414160],B[414160];
int i,num,len;
ll X,sum,pos;
scanf("%s",A);
scanf("%s",B);
len=strlen(B);
rev(A);
rev(B);
num=0;
pos=1;
sum=0;
for(i=0;i<lim-1;i++){
if(B[i]=='1')
num++;
X=num;
if(A[i]=='1')
X=lim-X;
sum=(sum+X*pos)%MOD;
pos=(pos<<1)%MOD;
}
for(i=0;i<len;i++){
X=num;
sum=(sum+X*pos)%MOD;
pos=(pos<<1)%MOD;
if(B[i]=='1')
num--;
}

pll(sum);
/*    printf("%s\n",A);
printf("%s\n",B);*/
return 0;

}

In Python3 :

a = int( input( ), 2 )
b = int( input( ), 2 )
r = 0

for i in range( 314160 ):
r += a ^ b
b *= 2

print( (r % (10**9+7)) )```
```

## Mr. X and His Shots

A cricket match is going to be held. The field is represented by a 1D plane. A cricketer, Mr. X has N favorite shots. Each shot has a particular range. The range of the ith shot is from Ai to Bi. That means his favorite shot can be anywhere in this range. Each player on the opposite team can field only in a particular range. Player i can field from Ci to Di. You are given the N favorite shots of M

## Jim and the Skyscrapers

Jim has invented a new flying object called HZ42. HZ42 is like a broom and can only fly horizontally, independent of the environment. One day, Jim started his flight from Dubai's highest skyscraper, traveled some distance and landed on another skyscraper of same height! So much fun! But unfortunately, new skyscrapers have been built recently. Let us describe the problem in one dimensional space

## Palindromic Subsets

Consider a lowercase English alphabetic letter character denoted by c. A shift operation on some c turns it into the next letter in the alphabet. For example, and ,shift(a) = b , shift(e) = f, shift(z) = a . Given a zero-indexed string, s, of n lowercase letters, perform q queries on s where each query takes one of the following two forms: 1 i j t: All letters in the inclusive range from i t

## Counting On a Tree

Taylor loves trees, and this new challenge has him stumped! Consider a tree, t, consisting of n nodes. Each node is numbered from 1 to n, and each node i has an integer, ci, attached to it. A query on tree t takes the form w x y z. To process a query, you must print the count of ordered pairs of integers ( i , j ) such that the following four conditions are all satisfied: the path from n

## Polynomial Division

Consider a sequence, c0, c1, . . . , cn-1 , and a polynomial of degree 1 defined as Q(x ) = a * x + b. You must perform q queries on the sequence, where each query is one of the following two types: 1 i x: Replace ci with x. 2 l r: Consider the polynomial and determine whether is divisible by over the field , where . In other words, check if there exists a polynomial with integer coefficie

## Costly Intervals

Given an array, your goal is to find, for each element, the largest subarray containing it whose cost is at least k. Specifically, let A = [A1, A2, . . . , An ] be an array of length n, and let be the subarray from index l to index r. Also, Let MAX( l, r ) be the largest number in Al. . . r. Let MIN( l, r ) be the smallest number in Al . . .r . Let OR( l , r ) be the bitwise OR of the