pattern = ['X', 'Y', 'Z']
counter = 0
next_string = ''
sizes = []
filepath = r'text.txt'
with open(filepath, 'r') as file:
file = file.read()
for element in file:
if element == pattern[counter]:
if counter < 2:
counter += 1
else:
counter = 0
next_string += element
else:
sizes.append(len(next_string))
next_string = ''
counter = 0
print(max(sizes))
:)