Any subsequence will be divisible by 6, if it is divisible by 2 and 3 both.
For doing this... we have three variables
a0......number of subsequences divisible by 3.
a1......number of subsequences on dividing by 3 gives remainder 1.
a2......number of subsequences on dividing by 3 gives remainder 2.
If at any index a[i]%2==0 then all the subsequences ending at index i will be divisible by 2, So, we can add a0 to the answer, because these subsequences are divisible by both 2 and 3.
Here is the program.
ans+=a0-previous; // add a0-previous to answer because all these subsequences are divisible by both 2 and 3.
previous=a0; // store the previous value, because at next index we have to subtract this,to get number of subsequences ending at index i.