Help me in solving TWTCLOSE problem

My issue

Please help me to solve this question.
My program is successfully executed but some test cases are failing.
Please anyone help me to resolve this problem…!

My code

def replace(a):
    if a == 1: return 0
    else: return 1

n,x = map(int,input().split())
tweets = []
for j in range(1,n+1):
    tweets.append(0)
for i in range(1,x+1):
    s = input()
    if s == 'CLOSEALL' or s == 'closeall':
        for j in range(len(tweets)): 
            tweets[j] = 0 
    else:
        if int(s[6]) in range(1,n+1):
            tweets[int(s[6])-1] = replace(tweets[int(s[6])-1])
    print(tweets.count(1))

Problem Link: TWTCLOSE Problem - CodeChef

@murali_barla
I don’t have good hands on python so unable to debug your code .
Plzz refer the following python solution for better understanding.

# cook your dish here
n,k=map(int,input().split())
c=0
lst=[]
for _ in range(k):
    s=input()
    if s[:3]=="CLI":
        s=int(s.split()[1])
        if s in lst:
            lst.remove(s)
            c-=1
        else:
            lst.append(s)
            c+=1
    else:
        lst=[]
        c=0
    print(c)