This page is still under construction.

Parts of this page are still being built. What you see may change.

Think Small

Time limit10sMemory limit512 MB

Summary
Multiply two polynomials of degree up to one million and print the xor of all coefficients of the product.
Level

Medium7 of 10

Topics
Divide and conquer, Math
Solved
No attempts yet

Problem

Jeongmin has grown up, and his parents now make him work through a well known workbook series called Think Small. The unit he has to study this time is multiplication of polynomials. Jeongmin wants to play games instead, so he offers to share his points if you write the program that multiplies the polynomial f(x)f(x) by the polynomial g(x)g(x) for him.

Input

The first line contains the degree NN of the polynomial f(x)f(x) and the degree MM of the polynomial g(x)g(x), separated by a space. (1≤N≤1,000,0001 \le N \le 1{,}000{,}000, 1≤M≤1,000,0001 \le M \le 1{,}000{,}000)

The second line contains N+1N + 1 natural numbers a0,a1,…,aNa_0, a_1, \dots, a_N, the coefficients of f(x)f(x), so that f(x)=a0+a1x+a2x2+⋯+aNxNf(x) = a_0 + a_1 x + a_2 x^2 + \dots + a_N x^N. (1≤ai≤1,000,0001 \le a_i \le 1{,}000{,}000)

The third line contains M+1M + 1 natural numbers b0,b1,…,bMb_0, b_1, \dots, b_M, the coefficients of g(x)g(x), so that g(x)=b0+b1x+b2x2+⋯+bMxMg(x) = b_0 + b_1 x + b_2 x^2 + \dots + b_M x^M. (1≤bi≤1,000,0001 \le b_i \le 1{,}000{,}000)

Output

Let f(x)×g(x)=c0+c1x+c2x2+⋯+cLxLf(x) \times g(x) = c_0 + c_1 x + c_2 x^2 + \dots + c_L x^L.

Print the xor of every coefficient, c0⊕c1⊕⋯⊕cLc_0 \oplus c_1 \oplus \dots \oplus c_L, on the first line. In C or C++ you compute c[0] ^ c[1] ^ ... ^ c[L].

The xor is asked for because printing every cic_i would be far too much output. It does not change how the problem is solved.

Hint

If f(x)=1+2xf(x) = 1 + 2x and g(x)=3+2xg(x) = 3 + 2x, then f(x)×g(x)=3+8x+4x2f(x) \times g(x) = 3 + 8x + 4x^2.

Examples2

  1. Example 1

    Input
    1 1
    1 2
    3 2
    
    Expected output
    15
    
  2. Example 2

    Input
    1 1
    1 1
    1 1
    
    Expected output
    2