```
class Solution:
# @param A a list of integers
# @return an integer
def removeDuplicates(self, A):
j=0
l=len(A)
count=1
for i in range(1,l):
if A[i]==A[j]:
A[j+1]=A[i]
count=count+1
else:
if count>=2:
j=j+2
else:
j=j+1
A[j]=A[i]
count=1
if count>=2:
return j+2
else:
return j+1
```