Vera and Love Triangles
Time limit2sMemory limit256 MB
For each pair of friends, a crush direction is set by the parity of the bit-count of a modular power expression; count cyclic triples.
- Level
Hard9 of 10
- Topics
- Combinatorics, Number theory, Math, Implementation
- Solved
- No attempts yet
Problem
Vera has friends numbered through . They all study software engineering, so none of them has spare time for a relationship, but they still have crushes on each other.
For a non-negative integer , let be the number of ones in the binary representation of . With integer constants , , , define .
For friends and with , friend has a crush on friend when is even, and friend has a crush on friend when is odd.
Vera finds love triangles funny. A love triangle is a set of three friends , , such that has a crush on , has a crush on , and has a crush on .
Given , , , , count the love triangles among Vera's friends. Two love triangles are different when their sets of three friends differ.
Input
The first line contains , , , separated by spaces.
Constraints:
- ,
- ,
- , , , are integers.
- is prime.
Output
Print the number of love triangles on one line.
Hint
Write when friend has a crush on friend .
In the first sample, , , and . So , , , and there is one love triangle.
In the second sample, , , and , so there is no love triangle.