Triplet Sum Divisor - (HELP)

Given an array A of N integers. Find the numbers of good triplets (i,j,k), where i, j, k are all distinct indices such that 1 <= i, j, k <= N. A good triplet (i,j,k) is a triplet such that the sum, S = A[i] + A[j] + A[k], is divisible by exactly one of A[i] or A[j] or A[k].

Array values of a triplet (i,j,k) is (A[i],A[j],A[k]).

1 <= N <= 10^5
1 <= A[i] <= 100 for 1 < i < N

Sample Input:
N = 4
A = {1,2,2,1}


I am not able to solve this problem in given time constrain, i have tried preprocessing but am not getting correct answer.

Can anyone please help ???