## DMOPC '15 Contest 3 P5 - Total Annihilation

View as PDF

Points: 15 (partial)
Time limit: 0.6s
Memory limit: 64M

Author:
Problem types
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

quantum works part-time at CERN as a particle physicist, where he spends his days smashing particles together in the famous Large Hadron Collider. He has recently managed to isolate some samples of antimatter in the LHC and would like to play experiment with them. (Warning: do not try this at home.)

Everyone knows that when matter and antimatter collide, they disappear and release massive amounts of energy in a reaction known as annihilation. If the particles and antiparticles are present in equal amounts, all of them will disappear in the reaction. quantum calls this a total annihilation. Note that reacting particles with antiparticles does not count.

quantum has samples of matter and samples of antimatter, the -th sample of matter has particles , and the -th sample of antimatter has antiparticles . Handling particles is a serious matter, so quantum will not separate any of the particles from a sample. More formally, this means that he can only react a non-empty subset of matter samples with a non-empty subset of antimatter samples.

For fun science, quantum would like you to find out the number of different total annihilation reactions that he can produce with these samples. A reaction is different from another if at least one of the samples used in it is not used in the other.

#### Constraints

For all test cases, .

#### Input Specification

The first line of input will contain and , separated by a space.

The second line will contain space-separated integers, , indicating the number of particles in each matter sample.

The third line will contain space-separated integers, , indicating the number of antiparticles in each antimatter sample.

#### Output Specification

One integer, the number of different total annihilation reactions that quantum can produce.

#### Sample Input

2 3
1 3
4 4 3

#### Sample Output

3

#### Explanation for Sample Output

quantum has particles of matter in total from the two samples, which he can use to react with either the first or second sample of antimatter. He can also create a reaction involving the second sample of matter and the third sample of antimatter.