Help me in solving CARDSWIPE problem

My issue

My code is correct all tests cases. But showing Tle. can anyone help in optimize the code?

My code

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner sc= new Scanner(System.in);
		int T= sc.nextInt();
		  
		while(T-->0){
		    int si = sc.nextInt();
		    ArrayList<Integer> lis = new ArrayList<>();
		   
		     
		    int count=0;int max =0;
		    for(int k =0;k<si;k++){
		        int a = sc.nextInt();
		        if(lis.contains(a)){
		            lis.removeIf(element->element==a);
		            count--;
		        }
		         
		        else if(!lis.contains(a)){
		            lis.add(a);
		            count++;
		            if(count>max){
		                max = count;
		            }
		           
		        }
		    }
		    System.out.println(max);
		}
	}
}

Problem Link: CARDSWIPE Problem - CodeChef

@heavycoder17
instead of adding and removing it into the list u can maintain the frequency of the element then if the frequency is odd then it should be present and count will increase else it would decrease .