Possible groups
Submissions: 5807   Accuracy:

36.14%

  Difficulty: Medium   Marks: 4

Given an array of positive integers of size N, we can form a group of two or three only, the group should be such that the sum of all elements in that group is a multiple of 3. Count all possible number of groups that can be generated in this way.

Input:
The first line of input contains an integer T denoting the number of test cases. The first line of each test case is N, where N is the size of array. The second line of each test case contains N elements of array.

Output:
Print number of all possible group.

Constraints:
1 ≤ T ≤ 100
1 ≤ N ≤ 106
1 ≤ Ai,j ≤ 106

Example:
Input:
2
5
3 6 7 2 9
4
2 1 3 4

Output:
8
4

Explanation:
Testcase 1:
Groups of two are: {3,6}, {3,9}, {9,6},
{7,2}, {3, 6,9},
Groups of three are: {3, 7, 2}, {7, 2, 6}, {7, 2, 9}.

** For More Input/Output Examples Use 'Expected Output' option **

Author: rajatjha


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.