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 3. Groups must be of size 2 or 3.
Task requirements (as a single cohesive program):
The program must read input from a JSON file located at /app/input.json.
The JSON should have the structure:
{
"arr": [int, int, ...],
"n": int
}
n should represent the length of arr (the program may rely on n, but should still use the provided value).
The program must write structured JSON output to a file at /app/output.json.
The output JSON should have the structure:
{
"count": int
}
The implementation must be in a single file: /app/solution.py.
The solution should expose the required function count_groups_divisible_by_three(arr, n) and include a main routine that:
Reads the input JSON from /app/input.json
Parses arr and n
Invokes count_groups_divisible_by_three(arr, n)
Writes the resulting count to /app/output.json
Notes:
Keep the original algorithmic requirement intact: count the number of 2-element and 3-element groups from arr whose sum is divisible by 3.
The input is assumed to be well-formed (valid JSON, arr is a list of integers, and n matches the length of arr). The task focuses on the three skills: algorithm, JSON parsing, and file I/O.