Triplets

All submissions for this problem are available.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Given a triplet of integers (X , Y , Z), such that X ≤ Y and Y ≥ Z, we define f(X , Y , Z) to be (X + Y) * (Y + Z). If either X > Y or Y < Z, or both, then f(X , Y , Z) is defined to be 0.
You are provided three arrays A , B and C of any length (their lengths may or may not be equal).
Your task is to find the sum of f(X , Y , Z) over all triplets (X, Y , Z) where X, Y and Z belong to A, B and C respectively.
Output your sum for each test case modulo 1000000007.
Input
 The first line contains a single integer, T, which is the number of test cases. The description of each testcase follows:
 The first line of each testcase contains 3 integers: p, q and r. These denote the lengths of A,B and C respectively.
 The second line contains p integers, which are the elements of A
 The third line contains q integers, which are the elements of B
 The fourth line contains r integers, which are the elements of C
Output
Output the required sum modulo 1000000007 for each test case in a new line.
Constraints
 1 ≤ T ≤ 10
 1 ≤ p, q, r ≤ 100000
 1 ≤ every array element ≤ 1000000000
Subtasks
 Subtask #1 (30 points): 1 ≤ p,q,r ≤ 100
 Subtask #2 (70 points): 1 ≤ p,q,r ≤ 100000
Example :
Input: 1 3 1 3 1 2 3 5 4 5 6 Output: 399
Explanation:
As there is only one choice for Y which equals to 5, to get a nonzero function value,we can choose any element for X from the set { 1 , 2 , 3 } and for Z from the set { 4 , 5 }
So triplets which give nonzero function values are:
{ 1 , 5 , 4 } : ( 1 + 5 ) * ( 5 + 4 ) = 54
{ 1 , 5 , 5 } : ( 1 + 5 ) * ( 5 + 5 ) = 60
{ 2 , 5 , 4 } : ( 2 + 5 ) * ( 5 + 4 ) = 63
{ 2 , 5 , 5 } : ( 2 + 5 ) * ( 5 + 5 ) = 70
{ 3 , 5 , 4 } : ( 3 + 5 ) * ( 5 + 4 ) = 72
{ 3 , 5 , 5 } : ( 3 + 5 ) * ( 5 + 5 ) = 80
Final answer : 54 + 60 + 63 + 70 + 72 + 80 = 399
Author:  vipsharmavip 
Editorial  https://discuss.codechef.com/problems/SUMQ 
Tags  june17, medium, vipsharmavip 
Date Added:  17052017 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions