I need help in solving SEGMENT THREE problem

include
using namespace std;

int main() {
// your code goes here
long long int t;
cin>>t;
while(t>0)
{
long long int n;
cin>>n;
long long int a[n];
for(long long int i=0;i<n;i++)
cin>>a[i];
long long int count=0;

       for(long long int i=0;i<n-2;i++)
       {
               long long int rem=(a[i]+a[i+1]+a[i+2])%3;
             
               if(rem!=0)
                {
                    a[i+2]=a[i+2]+3-rem;
                    count=count+3-rem;

               }

       }
       cout<<count<<endl;
        t--;
}
return 0;

}

i want to understand where am i making mistake
problem link Segment Three - Problems - CodeChef

@yuuotasaka
for test case
1
4
1 2 4 2
your output is 4
and correct output is : 2
u r making the array as :- 1 2 6 4
and the array should look like :- 2 3 4 2

1 Like

Ooh…got it … thank you for pointing it out !