#K84162. Flower Chains

    ID: 36359 Type: Default 1000ms 256MiB

Flower Chains

Flower Chains

You are given five non-negative integers P, Q, R, S and T representing the required number of occurrences of the triplets RRR, RRB, RRY, YYY and YYB respectively in a flower chain. A flower chain is a sequence formed from the characters 'R' (red), 'Y' (yellow) and 'B' (blue). The occurrences of a triplet are counted as every contiguous substring of length three (overlapping allowed) that exactly matches one of the specified patterns.

Your task is to count the number of distinct flower chains that satisfy exactly these triplet occurrence requirements. Output the answer modulo \(10^9+7\).

Note: If all input values are zero (i.e. there are no specific requirements), then the answer is defined to be 1.

inputFormat

The input consists of five space-separated integers on a single line:

P Q R S T

where:

  • P is the number of required occurrences of the triplet RRR.
  • Q is the number of required occurrences of the triplet RRB.
  • R is the number of required occurrences of the triplet RRY.
  • S is the number of required occurrences of the triplet YYY.
  • T is the number of required occurrences of the triplet YYB.

outputFormat

Output a single integer representing the number of valid flower chains that satisfy the given triplet count requirements, modulo \(10^9+7\>.

## sample
0 0 0 0 0
1