Read problem statements in [Mandarin], [Bengali], [Russian], and [Vietnamese] as well.

In addition to Competitive Programming, Chef recently developed an interest in Web Dev and started learning HTML. Now he wants to create his own HTML Code Editor. As a subproblem, he wants to check if a typed HTML closing tag has correct syntax or not.

A closing HTML tag must:
Start with ""
Have only lower-case alpha-numeric characters as its body (between ""). That is, each character of the body should either be a digit or a lower-case English letter.
Have a non-empty body.

Help Chef by printing "Success" if the tag is fine. If not, print "Error".

------ Input Format ------ 

- The first line contains an integer T, the number of test cases. Then T test cases follow. 
- Each test case is a single line of input, a string describing the tag.

------ Output Format ------ 

For each test case, output in a single line, "Success" if it is a valid closing tag and "Error" otherwise (without quotes).

You may print each character of the string in uppercase or lowercase (for example, the strings "SuccEss", "success", "Success", "SUCCESS" etc. will all be treated as identical).

------ Constraints ------ 

$1 ≤ T ≤ 1000$
$1 ≤$ $\mathrm{length}(\mathrm{Tag})$ $≤ 1000$
- The characters of the string belong to the ASCII range $[33, 126]$ (note that this excludes space.)

----- Sample Input 1 ------ 
5 
  
Clearly_{Invalid}  
  
----- Sample Output 1 ------ 
Success  
Error  
Success
Success
Error
----- explanation 1 ------ 
Test Cases $1, 3, 4$: The tags follow all mentioned constraints.

Test Case $2$: The tag doesn't contain opening and closing symbols and also includes characters other than lower-case alpha-numeric characters in its body.

Test Case $5$: The tag also includes an upper-case alpha-numeric character "A" and a non alpha-numeric character "/" in its body.

Source: codechef | Difficulty: MEDIUM
Tags: Complete search

Implementation

Ad-hoc


Solutions:
for _ in range(int(input())):
	s = input().strip()
	n = len(s)
	flag = 1
	if s[0] == '<' and s[-1] == '>' and (s[1] == '/') and len(s[2:-1]):
		for i in s[2:-1]:
			if i >= '0' and i <= '9' or (i >= 'a' and i <= 'z'):
				pass
			else:
				flag = 0
				break
	else:
		print('Error')
		continue
	if flag:
		print('Success')
	else:
		print('Error')


def check_char(char):
	if char.islower() or char.isdigit():
		return True
	return False

def solve(s):
	if s[:2] != '</' or s[-1] != '>' or len(s) < 4:
		return 'Error'
	s = s[2:-1]
	for i in s:
		if not check_char(i):
			return 'Error'
	return 'Success'
for _ in range(int(input())):
	s = input().strip()
	print(solve(s))


for _ in range(int(input())):
	inp = input()
	x = 'abcdefghijklmnopqrstuvwxyz0123456789'
	start = '</'
	end = '>'
	inp = inp.strip(' ')
	if inp[:2] == start and inp[-1] == end:
		inp = inp[2:-1]
		flag = 1
		if len(inp) == 0:
			flag = 0
		for i in inp:
			if i not in x:
				flag = 0
				break
		if flag:
			print('Success')
		else:
			print('Error')
	else:
		print('Error')


for _ in range(int(input())):
	s = input().strip()
	if s[0] == '<' and s[1] == '/' and (s[-1] == '>'):
		c = 0
		for i in range(len(s)):
			if s[i] >= 'a' and s[i] <= 'z' or s[i].isdigit():
				c += 1
		if len(s) <= 3:
			print('Error')
		elif c + 3 == len(s):
			print('Success')
		else:
			print('Error')
	else:
		print('Error')


for _ in range(int(input())):
	n = input().strip()
	if n[0] == '<' and n[1] == '/' and (n[-1] == '>'):
		f = True
	else:
		f = False
	if len(n) <= 3:
		f = False
	for i in range(2, len(n) - 1):
		if f and (n[i] >= 'a' and n[i] <= 'z' or 47 <= ord(n[i]) <= 57):
			continue
		else:
			f = False
			break
	if f == True:
		print('Success')
	else:
		print('Error')


t = int(input())
for i in range(t):
	string = input().strip()
	flag = True
	if string[0] == '<' and string[1] == '/' and (string[len(string) - 1] == '>') and (len(string) > 3):
		for x in range(2, len(string) - 1):
			if string[x].islower() or string[x].isdigit():
				flag = True
			else:
				flag = False
				break
	else:
		flag = False
	if flag == False:
		print('Error')
	else:
		print('Success')


for _ in range(int(input())):
	a = input().strip()
	valid = True
	if len(a) <= 3:
		print('Error')
	else:
		if a[0:2] != '</':
			valid = False
		if a[-1] != '>':
			valid = False
		for i in range(2, len(a) - 1):
			if a[i].islower() == False and a[i].isdigit() == False:
				valid = False
				break
		if valid:
			print('Success')
		else:
			print('Error')


t = int(input())
for i in range(t):
	s = input().strip()
	if s[0:2] == '</' and s[-1] == '>':
		for i in range(2, len(s) - 1):
			if s[i].islower() or s[i].isdigit():
				res = 'Success'
			else:
				res = 'Error'
				break
	else:
		res = 'Error'
	print(res)


for _ in range(int(input())):
	x = input().strip()
	y = len(x)
	if x[0] == '<' and x[1] == '/' and (x[-1] == '>') and (not x[2:-1] == ''):
		for i in x[2:y - 1]:
			if not (i.isdigit() == True or i.islower() == True):
				print('Error')
				break
		else:
			print('Success')
	else:
		print('Error')


for _ in range(int(input())):
	t = input()
	t = list(t)
	j = 0
	for i in t:
		if i == ' ':
			j += 1
	for i in range(j):
		t.remove(' ')
	a = '0123456789abcdefghijklmnopqrstuvwxyz'
	s = 0
	if t[0] == '<' and t[1] == '/' and (t[-1] == '>'):
		t.remove('<')
		t.remove('/')
		t.remove('>')
		for i in t:
			if i in a:
				s = 1
			else:
				s = 0
				break
	if s != 0:
		print('Success')
	else:
		print('Error')


for _ in range(int(input())):
	I = input().strip()
	b = len(I)
	flag = 1
	if I[0] == '<' and I[-1] == '>' and (I[1] == '/') and (not I[2:-1] == ''):
		for each in I[2:b - 1]:
			if not (each.isdigit() == True or each.islower() == True):
				print('Error')
				flag = 0
				break
		if flag == 1:
			print('Success')
	else:
		print('Error')


t = int(input())
for _ in range(t):
	a = input().strip()
	b = len(a)
	if a[0] == '<' and a[1] == '/' and (a[-1] == '>') and (not a[2:-1] == ''):
		for i in a[2:b - 1]:
			if not (i.isdigit() == True or i.islower() == True):
				print('Error')
				break
		else:
			print('Success')
	else:
		print('Error')


for _ in range(int(input())):
	tag = input().strip()
	ans = 'Error'
	if len(tag) < 4:
		print(ans)
		continue
	if tag[0] == '<' and tag[1] == '/' and (tag[-1] == '>'):
		tag = tag[2:-1]
		if tag.isalnum():
			dup_tag = tag.lower()
			if tag == dup_tag:
				ans = 'Success'
	print(ans)


T = int(input())
for i in range(T):
	s = input().strip()
	a = True
	if s[:2] != '</' or s[-1] != '>' or s[2:-1] == '':
		a = False
	for i in s[2:-1]:
		if not (97 <= ord(i) <= 122 or 48 <= ord(i) <= 57):
			a = False
			break
	if a:
		print('Success')
	else:
		print('Error')


tests = int(input())
for i in range(tests):
	string = input().strip()
	ans = 'Success'
	if string[:2] != '</' or string[-1] != '>' or string[2:-1] == '':
		ans = 'Error'
	for j in string[2:-1]:
		if not (97 <= ord(j) <= 122 or 48 <= ord(j) <= 57):
			ans = 'Error'
			break
	print(ans)


for _ in range(int(input())):
	a = input()
	b = '0123456789abcdefghijklmnopqrstuvwxyz'
	l = list(a)
	i = 0
	for e in l:
		if e == ' ':
			i += 1
	for e in range(i):
		l.remove(' ')
	n = len(l)
	if l[0] == '<' and l[1] == '/' and (l[n - 1] == '>'):
		l.remove('>')
		l.remove('/')
		l.remove('<')
		s = ''.join(l)
		for e in s:
			if e in b:
				i = 1
			else:
				i = 0
				break
		if i != 0:
			print('Success')
		else:
			print('Error')
	else:
		print('Error')


t = int(input())
for i in range(t):
	s = input()
	s = s.strip()
	a = 0
	if s[0] == '<' and s[-1] == '>' and (s[1] == '/') and (s[2] != '/') and (len(s) > 3):
		for j in s[2:len(s) - 1]:
			if j.isalpha() == True and j.islower() == True:
				continue
			elif j.isdigit() == True:
				continue
			else:
				a += 1
				break
		if a == 0:
			print('Success')
		else:
			print('Error')
	else:
		print('Error')


def HtmlTags(tag):
	l = len(tag)
	c = 0
	if tag[0] == '<' and tag[1] == '/' and (tag[l - 1] == '>'):
		for i in tag[2:l - 1]:
			if i in '0123456789abcdefghijklmnopqrstuvwxyz':
				c += 1
			else:
				c = 0
				break
	if c != 0:
		print('Success')
	else:
		print('Error')
for _ in range(int(input())):
	string = input().strip()
	HtmlTags(string)


for _ in range(int(input())):
	s = input()
	s = s.replace(' ', '')
	n = len(s)
	if s[0] == '<' and s[1] == '/' and (s[-1] == '>'):
		flag = 0
		s = s[2:n - 1]
		string = s
		up = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
		for i in s:
			if i in up:
				flag = 1
				break
		if flag == 0:
			if s.isalnum() or s.isalpha() or s.isdigit():
				print('Success')
			else:
				print('Error')
		else:
			print('Error')
	else:
		print('Error')


t = int(input(''))
for i in range(t):
	s = input().strip()
	uc = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
	s1 = s[2:len(s) - 1]
	status = True
	if s[0] == '<' and s[-1] == '>' and (s[1] == '/'):
		for i in s1:
			if i in uc:
				status = False
		if status == True:
			if s1.isalnum() or s1.isdigit() or s1.isalpha():
				print('Success')
			else:
				print('Error')
		else:
			print('Error')
	else:
		print('Error')


T = int(input())
for _ in range(T):
	string = input().strip()
	if string[0] == '<' and string[1] == '/' and (string[-1] == '>') and (len(string) > 3):
		c = 0
		for r in string[2:-1]:
			if r not in '1234567890qwertyuiopasdfghjklzxcvbnm':
				print('Error')
				c = 1
				break
		if c == 0:
			print('Success')
	else:
		print('Error')


def check_tag(n, s):
	if s[0] == '<' and s[1] == '/' and (s[-1] == '>') and (n > 3):
		for i in range(2, n - 1):
			ch = ord(s[i])
			if not (ch >= 48 and ch <= 57 or (ch >= 97 and ch <= 122)):
				return 'Error'
		return 'Success'
	else:
		return 'Error'
t = int(input())
for _ in range(t):
	s = input().strip()
	n = len(s)
	print(check_tag(n, s))


for _ in range(int(input())):
	s = str(input())
	s = s.strip()
	ans = True
	smap = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}
	if s[0:2] == '</' and s[-1] == '>' and (len(s) > 3):
		for i in range(2, len(s) - 1):
			if s[i] not in smap:
				ans = False
				break
	else:
		ans = False
	if ans:
		print('Success')
	else:
		print('Error')


for i in range(int(input())):
	flag = 0
	tag = input()
	tag = tag.rstrip()
	tag = tag.lstrip()
	l = len(tag)
	if l <= 3:
		print('Error')
		continue
	if tag[0] == '<' and tag[1] == '/' and (tag[l - 1] == '>'):
		for i in range(2, l - 1):
			if not (tag[i].islower() or tag[i].isnumeric()):
				flag = 1
				break
	else:
		flag = 1
	if flag == 1:
		print('Error')
	else:
		print('Success')


for x in range(int(input())):
	s = input().strip()
	if s[0] == '<' and s[1] == '/' and (s[-1] == '>') and (len(s) > 3):
		for r in s[2:-1]:
			if r not in '1234567890qwertyuiopasdfghjklzxcvbnm':
				print('Error')
				break
		else:
			print('Success')
	else:
		print('Error')


t = int(input())
an = '1234567890qwertyuiopasdfghjklzxcvbnm'
for _ in range(t):
	s = input().strip()
	temp = s[2:len(s) - 1]
	flag = False
	if s[0:2] == '</' and s[-1] == '>' and len(temp):
		for c in temp:
			if c not in an:
				print('Error')
				flag = True
				break
		if not flag:
			print('Success')
	else:
		print('Error')


import re
q = int(input())
while q > 0:
	s = input()
	q -= 1
	flag = re.search('</[0-9a-z]+>', s)
	if flag:
		print('Success')
	else:
		print('Error')


import re
t = int(input())
special_char = re.compile('[@_!#$%^&*()<>?/\\|}{~:]')
for i in range(t):
	a = input()
	a = a.strip()
	n = len(a)
	if a[0] == '<' and a[1] == '/' and (a[n - 1] == '>') and (n > 3):
		ans = 'Success'
		b = a.replace(a[0], 'a')
		c = b.replace(a[1], 'a')
		d = c.replace(a[n - 1], 'a')
		for j in range(n):
			if d[j] != d[j].lower():
				ans = 'Error'
				break
			if special_char.search(d) != None:
				ans = 'Error'
				break
			if d[j] == ' ':
				ans = 'Error'
				break
		print(ans)
	else:
		print('Error')


for _ in range(int(input())):
	s = input().strip()
	n = len(s)
	if n > 3 and s[0] == '<' and (s[1] == '/'):
		if s[-1] == '>':
			for i in range(2, n - 1):
				if not (s[i] >= 'a' and s[i] <= 'z' or (s[i] >= '0' and s[i] <= '9')):
					print('Error')
					break
			else:
				print('Success')
		else:
			print('Error')
	else:
		print('Error')


for _ in range(int(input())):
	tag = input().strip()
	if len(tag) < 4:
		print('Error')
		continue
	for (i, ch) in enumerate(tag):
		if i == 0 and ch == '<':
			continue
		if i == 1 and ch == '/':
			continue
		if i > 1 and i < len(tag) - 1 and (ord(ch) in range(48, 58) or ord(ch) in range(97, 123)):
			continue
		if i == len(tag) - 1 and ch == '>':
			print('Success')
			break
		else:
			print('Error')
			break