Implement a function count_groups_divisible_by_three(arr, n) that counts the number of groups of elements from the input array arr that can form sums divisible by three.
Functionality:
The function should take an array of integers arr and an integer n (the length of the array).
It should calculate the number of ways to choose groups of 2 or 3 elements from arr such that their sum is divisible by 3.
The groups can be composed of:
Pairs of elements where both elements can be of any remainder category when divided by 3.
Triples of elements from any combination of the remainder categories when divided by 3.
Input/Output Requirements:
Input:
arr: A list of integers where 1 <= len(arr) <= 1000 and each element can be any integer.
n: An integer representing the length of arr.
Output:
The function should return an integer representing the total count of valid groups.
Implementation:
Write the implementation in a file called /app/solution.py.
Example:
python
# Example input
arr = [1, 2, 3, 4, 5]
n = len(arr)
# Example output
count_groups_divisible_by_three(arr, n) # Should return the number of valid groups