n, m, q = input().split()
n, m, q = int(n), int(m), int(q)
if not(1 <= q <= 10 ** 5) or not(1 <= n * m <= 10 ** 6):
exit(0)
class DataCenter:
def __init__(self, n_servers):
self.R = 0
self.A = n_servers
self.servers = [Server(False) for _ in range(n_servers)]
class Server:
def __init__(self, disable=False):
self.disable = disable
def set_dis(self, b: bool):
self.disable = b
arr = [DataCenter(m) for _ in range(n)]
for i in range(q):
inp = input().split()
if inp[0] == "RESET" and 1 <= int(inp[1]) <= n:
arr[int(inp[1]) - 1].A = len(arr[int(inp[1]) - 1].servers)
[u.set_dis(False) for u in arr[int(inp[1]) - 1].servers]
arr[int(inp[1]) - 1].R += 1
elif inp[0] == "DISABLE" and 1 <= int(inp[1]) <= n and 1 <= int(inp[2]) <= m:
if not arr[int(inp[1]) - 1].servers[int(inp[2]) - 1].disable:
arr[int(inp[1]) - 1].servers[int(inp[2]) - 1].disable = True
arr[int(inp[1]) - 1].A -= 1
elif inp[0] == "GETMAX":
arr1 = [t.R * t.A for t in arr]
print(arr1.index(max(arr1)) + 1)
elif inp[0] == "GETMIN":
arr1 = [t.R * t.A for t in arr]
print(arr1.index(min(arr1)) + 1)
Вот мой код. Тестирующая система просит не более 4сек Как оптимизировать?