Help me in solving SMILEY problem

My issue

My code

#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--){
	    long long int n,count=2,num=2,counta=0;
	    cin>>n;
	    long long int sum = 0;
	    string s;
	    cin>>s;
	    long long int m = -1e9;
	    long long int q = 1e7+7;
	    long long int arr[n];
	    for(long long int i = 0;i<n;i++){
	        if(s[i]==':') {
	            arr[i]=count;
	            count++;
	        }
	        else if(s[i]==')') arr[i]=1;
	        else arr[i]=m;
	    }
	    for(long long int i = 0;i<n;i++){
	        if(arr[i]==num){
               if(sum>0)
               {counta++; }
	            num++;
	            
	           sum=0;
	           
	        }
	        else{
	            sum=(sum+arr[i])%q;
	          
	        }
	    }
	  
	    
	    cout<<counta<<endl;
	}
	return 0;
}

Problem Link: SMILEY Problem - CodeChef

Why is this giving WA even after passing all test cases and being logically correct from my end? Am I missing any particular test case. Please help me with this