You are given a valid XML document, and you have to print its score. The score is calculated by the sum of the score of each element. For any element, the score is equal to the number of attributes it has. 

Input Format

The first line contains $N$, the number of lines in the XML document.

The next $N$ lines follow containing the XML document.

Output Format

Output a single line, the integer score of the given XML document.

Sample Input  

6
<feed xml:lang='en'>
    <title>HackerRank</title>
    <subtitle lang='en'>Programming challenges</subtitle>
    <link rel='alternate' type='text/html' href='http://hackerrank.com/'/>
    <updated>2013-12-25T12:00:00</updated>
</feed>

Sample Output  

5

Explanation

The feed and subtitle tag have one attribute each - lang. 

The title and updated tags have no attributes. 

The link tag has three attributes - rel, type and href. 

So, the total score is $1+1+3=5$.

There may be any level of nesting in the XML document. To learn about XML parsing, refer here.

NOTE: In order to parse and generate an XML element tree, use the following code:

>> import xml.etree.ElementTree as etree
>> tree = etree.ElementTree(etree.fromstring(xml))

Here, XML is the variable containing the string.

Also, to find the number of keys in a dictionary, use the len function:

>> dicti = {'0': 'This is zero', '1': 'This is one'}
>> print (len(dicti))

2

Difficulty: EASY

Solutions:
from xml.etree.ElementTree import XMLParser
import sys
if sys.version_info[0] >= 3:
	raw_input = input

class Parser:
	score = 0

	def start(self, tag, attrib):
		self.score += len(attrib)

	def end(self, tag):
		pass

	def data(self, data):
		pass

	def close(self):
		return self.score
parser = XMLParser(target=Parser())
for i in range(int(raw_input())):
	parser.feed(raw_input())
print(parser.close())


xml = ''
for _ in range(int(input())):
	xml += input()
import xml.etree.ElementTree as etree
tree = etree.ElementTree(etree.fromstring(xml))
root = tree.getroot()
score = 0
stack = []
stack.append(root)
while len(stack) > 0:
	temp = stack.pop()
	score += len(temp.attrib)
	for i in range(len(temp)):
		stack.append(temp[i])
print(score)


import xml.etree.ElementTree as etree
n = int(input())
xml = ''
for i in range(n):
	xml += input()
tree = etree.ElementTree(etree.fromstring(xml))
s = 0
l = list(tree.getroot().iter())
for i in l:
	s += len(i.attrib)
print(s)


n = int(input())
xml = ''
for i in range(n):
	xml += input() + '\n'
import xml.etree.ElementTree as etree
tree = etree.ElementTree(etree.fromstring(xml))
root = tree.getroot()
count = len(root.attrib)
for i in root.findall('.//'):
	count += len(i.attrib)
print(count)


import xml.etree.ElementTree as etree

def ans(tree):
	res = len(tree.attrib)
	for child in tree:
		res += ans(child)
	return res
n = int(input())
s = ''
for i in range(n):
	s += input()
tree = etree.fromstring(s)
print(ans(tree))


import xml.etree.ElementTree as etree
lines = int(input())
xml = ''
for _ in range(lines):
	xml += '\n' + input()
tree = etree.ElementTree(etree.fromstring(xml))
root = tree.getroot()
attributeCount = 0
for elem in root.iter():
	attributeCount += len(elem.attrib)
print(attributeCount)


count = 0
n = int(input())
for i in range(0, n):
	y = input()
	for i in range(0, len(y) - 1):
		if y[i] == '=':
			count += 1
print(count)


import xml.etree.ElementTree as etree

def get_xml(func):
	return '\n'.join([func() for i in range(int(func()))])

def tree_cnt_attrib(tree):

	def recurse(tree, tally=0):
		if len(tree) > 0:
			for child in tree:
				tally += recurse(child)
		return len(tree.attrib) + tally
	return recurse(tree)
root = etree.fromstring(get_xml(input))
print(tree_cnt_attrib(root))


n = int(input())
c = 1
buffer = []
for i in range(n):
	line = input()
	buffer.append(line)
multiline_string = '\n'.join(buffer)
print(int(multiline_string.count("'") / 2))


import xml.etree.ElementTree as etree
xmltext = '\n'.join((input() for _ in range(int(input()))))
tree = etree.ElementTree(etree.fromstring(xmltext))
print(sum((len(i.attrib) for i in tree.getroot().iter())))


def countNodeScore(node):
	count = len(node.attrib)
	for n in node:
		count += countNodeScore(n)
	return count
xml = ''
for x in range(0, int(input())):
	xml += input()
import xml.etree.ElementTree as etree
tree = etree.ElementTree(etree.fromstring(xml))
print(countNodeScore(tree.getroot()))


import xml.etree.ElementTree as etree

def count_attrib(node):
	count = len(node.attrib)
	for child in node:
		count += count_attrib(child)
	return count
lines = int(input())
xml = ''
for l in range(lines):
	xml += input()
tree = etree.ElementTree(etree.fromstring(xml))
print(count_attrib(tree.getroot()))


stuff = [input() for x in range(int(input()))]
things = '\n'.join(stuff)
print(things.count("='"))


import xml.etree.ElementTree as etree, sys
from itertools import chain
_ = input()
tree = etree.parse(sys.stdin)
attribs = 0
for element in chain(tree.findall('.'), tree.findall('.//')):
	attribs += len(element.attrib)
print(attribs)


N = input()
count = 0
for i in range(0, int(N)):
	count += input().count('=')
print(count)


n = int(input())
s = ''
for _ in range(n):
	s += input()
print(s.count('='))


import xml.etree.ElementTree as etree
xml = []
N = int(input())
for n in range(N):
	xml.append(input())
xml = '\n'.join(xml)
tree = etree.ElementTree(etree.fromstring(xml))

def dfs(root):
	ans = len(root.attrib)
	for child in root:
		ans += dfs(child)
	return ans
print(dfs(tree.getroot()))


n = int(input())
import xml.etree.ElementTree as et
xml = ''
for i in range(n):
	xxml = input()
	xml = xml + xxml + '\n'
root = et.fromstring(xml)
ans = len(root.attrib)
for i in root:
	ans += len(i.attrib)
	for j in i:
		ans += len(j.attrib)
print(ans)


import re
num = int(input())
p = re.compile("\\w+\\='")
count = 0
for i in range(num):
	line = input()
	if p.search(line):
		count += len(p.findall(line))
print(count)


s = 0
n = int(input())
for i in range(n):
	l = input()
	s += l.count('=')
print(s)


import xml.etree.ElementTree as etree

def countAttributes(element):
	count = len(element.attrib)
	for child in element:
		count += countAttributes(child)
	return count
xml = ''
for _ in range(0, int(input())):
	xml = xml + input()
tree = etree.ElementTree(etree.fromstring(xml))
print(countAttributes(tree.getroot()))


i = int(input())
a = ' '
for y in range(i):
	a += input()
count = 0
for i in range(len(a)):
	if a[i] == '=':
		count += 1
print(count)


import xml.etree.ElementTree as etree

def score(node):
	res = len(node.attrib)
	for child in node:
		res += score(child)
	return res
xml = ''
for _ in range(int(input())):
	xml += input()
print(score(etree.fromstring(xml)))


a = int(input())
k = 0
while a > 0:
	b = input()
	for i in b:
		if i == '=':
			k += 1
	a -= 1
print(k)


num = int(input())
atr = 0
for i in range(num):
	s = str(input())
	tag = s[s.find('<') + 1:s.find('>')]
	atr += int(tag.count("'") / 2)
print(atr)


N = int(input())
xml = ''
for _ in range(N):
	xml += input()
import xml.etree.ElementTree as etree
tree = etree.ElementTree(etree.fromstring(xml))
score = 0
for e in tree.iter():
	score += len(e.attrib)
print(score)


import xml.etree.ElementTree as etree
line_count = int(input())
xml = ''
for i in range(0, line_count):
	xml += input()
tree = etree.ElementTree(etree.fromstring(xml)).getroot()

def attribute_count(element):
	if len(element) == 0:
		return len(element.attrib)
	else:
		return sum([attribute_count(i) for i in element]) + len(element.attrib)
print(attribute_count(tree))


import xml.etree.ElementTree as etree

def attribcount(tag):
	ct = len(tag.attrib)
	if len(tag) == 0:
		return ct
	else:
		for x in tag:
			ct += attribcount(x)
		return ct
n = int(input())
a = ''
for x in range(n):
	b = input()
	a = a + b + '\n'
tree = etree.fromstring(a)
count = attribcount(tree)
print(count)


import xml.etree.ElementTree as ET
N = int(input())
xml_string = ''
for i in range(N):
	xml_string += input()
root = ET.fromstring(xml_string)
score = sum((len(elem.attrib) for elem in root.iter()))
print(score)


import sys
import xml.etree.ElementTree as etree
next(sys.stdin)
tree = etree.ElementTree(etree.fromstring(sys.stdin.read()))
sum = 0
for e in tree.iter():
	sum += len(e.attrib)
print(sum)


l = int(input())
a = ''
count = 0
for i in range(l):
	a += input()
a = a.split('=')
count = len(a) - 1
print(count)


import xml.etree.ElementTree as etree

def score(elem):
	return len(elem.attrib) + sum((score(child) for child in elem))
n = int(input())
xml = '\n'.join((input() for i in range(n)))
tree = etree.ElementTree(etree.fromstring(xml))
print(score(tree.getroot()))


import xml.etree.ElementTree as etree

def countAttribs(elems):
	n = 0
	for x in elems:
		n += len(x.attrib) + countAttribs(list(x))
	return n
xml = '\n'.join([input() for _ in range(int(input()))])
tree = etree.ElementTree(etree.fromstring(xml))
print(countAttribs(tree.findall('.')))


n = int(input())
count = 0
for i in range(n):
	b = input()
	for j in range(0, len(b)):
		if "='" == b[j:j + 2]:
			count += 1
print(count)


lines = int(input())
cnt = 0
pat = '='
for i in range(0, lines):
	str1 = input()
	cnt += str1.count(pat, 0, len(str1))
print(cnt)


import xml.etree.ElementTree as etree
l = int(input())
s = ''
for i in range(l):
	s += input()
tree = etree.ElementTree(etree.fromstring(s))
es = tree.findall('.//')
rank = len(tree.getroot().attrib)
for e in es:
	rank += len(e.attrib)
print(rank)


from xml.dom.minidom import parseString
root = parseString(''.join((input() for i in range(int(input())))))

def score(node):
	s = node.attributes and len(node.attributes) or 0
	return s + sum(map(score, node.childNodes))
print(score(root))


import xml.etree.ElementTree as etree

def fun(root):
	if len(root) == 0:
		return 0
	sum = 0
	for child in root:
		sum += len(child.attrib) + fun(child)
	return sum
var = int(input())
string = ''
for i in range(0, var):
	string += input()
tree = etree.ElementTree(etree.fromstring(string))
root = tree.getroot()
sum = len(root.attrib) + fun(root)
print(sum)


import xml.etree.ElementTree as etree
c = int(input())
xml = ''
for i in range(c):
	xml = xml + '\n' + input().strip()
tree = etree.ElementTree(etree.fromstring(xml))
count = 0
for el in tree.iter():
	count = count + len(el.attrib)
print(count)


nLines = int(input())
myXml = ''
while nLines > 0:
	myXml += input()
	nLines -= 1
print(len(myXml.split('=')) - 1)


n = int(input())
countEq = 0
for i in range(n):
	countEq += input().count('=')
print(countEq)


ans = 0
for i in range(int(input())):
	s = input().strip()
	flag = False
	for c in s:
		if c == '<':
			flag = True
		if c == '>':
			flag = False
		if flag and c == '=':
			ans += 1
print(ans)


import xml.etree.ElementTree as et
n = int(input())
i = 0
xml = ''
while i < n:
	xml = xml + input() + '\n'
	i = i + 1
tree = et.fromstring(xml)
count = 0
for k in tree.iter():
	count = count + len(k.attrib)
print(count)


import xml.etree.ElementTree as etree
lines = int(input())
xml = ''
for line in range(lines):
	xml = ''.join([xml, input()])
tree = etree.fromstring(xml)

def dfs(tree):
	total = len(tree.attrib)
	for item in tree:
		total += dfs(item)
	return total
print(dfs(tree))


import re
tag_parse = re.compile('<[^/].*>')
attr_parse = re.compile("[^']+=['][^']+[']")
attr_count = 0
num_lines = int(input())
for idx in range(0, num_lines):
	xml_line = input()
	tags = tag_parse.findall(xml_line)
	for tag in tags:
		attributes = attr_parse.findall(tag[1:])
		attr_count += len(attributes)
print(attr_count)


import re
n = int(input())
c = 0
for i in range(n):
	l = input()
	c += len(re.findall('.+?=.+?', l))
print(c)


import xml.etree.ElementTree as etree
xmlstring = ''
lines = int(input())
for i in range(0, lines):
	xmlstring = xmlstring + input()
tree = etree.ElementTree(etree.fromstring(xmlstring))
root = tree.getroot()
finallist = [len(elem.attrib) for elem in tree.findall('.//')]
finallist.append(len(root.attrib))
count = 0
for i in range(0, len(finallist)):
	count = count + finallist[i]
print(count)


import xml.etree.ElementTree as etree

def get_input():
	buf = []
	num_lines = int(input())
	for i in range(num_lines):
		buf.append(str(input()).strip())
	input_block = '\n'.join(buf)
	tree = etree.ElementTree(etree.fromstring(input_block))
	root = tree.getroot()
	return root

def get_xml_score(root):
	cur_val = len(root.attrib)
	for child in root:
		if child.attrib:
			cur_val += len(child.attrib)
		else:
			cur_val += get_xml_score(child)
	return cur_val

def main():
	root = get_input()
	score = get_xml_score(root)
	print(score)
main()


l = int(input())
c = 0
for t in range(l):
	a = input()
	ot = 0
	for i in a:
		if i == '<':
			ot = 1
		elif i == '>':
			ot = 0
		elif i == '=' and ot == 1:
			c += 1
print(c)


import xml.etree.ElementTree as etree
n = int(input())
xml = ''.join([input() for i in range(n)])
tree = etree.ElementTree(etree.fromstring(xml))
count = 0
nodes = [tree.getroot()]
while len(nodes) > 0:
	node = nodes.pop()
	nodes.extend(list(node))
	count += len(node.attrib)
print(count)


import sys
import re
input()
text = sys.stdin.read()
print(len(re.findall('=', text)))


import xml.etree.ElementTree as etree
import io

def count_attribs_recursive(element):
	attribs_count = len(element.attrib)
	for child in element:
		attribs_count += count_attribs_recursive(child)
	return attribs_count

def main():
	n = int(input())
	strings = [str(input()) for i in range(n)]
	xml_file = io.StringIO(''.join(strings))
	tree = etree.parse(xml_file)
	print(count_attribs_recursive(tree.getroot()))
main()


import xml.etree.ElementTree as etree
lines = input()
xml = ''
for i in range(int(lines)):
	xml = xml + input()
tree = etree.ElementTree(etree.fromstring(xml))
root = tree.getroot()
count = 0
for child in root.iter():
	count = count + len(child.attrib)
print(count)


import xml.etree.ElementTree as etree
T = int(input())
xml = ''
for _ in range(T):
	xml += input().strip()
root = etree.fromstring(xml)

def dfs(root):
	res = len(root.attrib)
	for child in root:
		res += dfs(child)
	return res
print(dfs(root))


def dfs(root):
	sum = 0
	for child in root:
		sum = sum + dfs(child)
	sum = sum + len(root.attrib)
	return sum
import xml.etree.ElementTree as ET
N = int(input())
s = ''
for i in range(N):
	s = s + input()
tree = ET.ElementTree(ET.fromstring(s))
root = tree.getroot()
print(dfs(root))


import xml.etree.ElementTree as etree
xml = ' '.join((input() for _ in range(int(input()))))
tree = etree.ElementTree(etree.fromstring(xml))
print(sum([len(x.attrib) for x in tree.iter()]))


import xml.etree.ElementTree as etree
numLines = int(input())
s = ''
for i in range(numLines):
	s += input()
tree = etree.fromstring(s)
c = 0
for b in tree.iter():
	c += len(b.attrib)
print(c)


import xml.etree.ElementTree as etree

def calcscore(tag):
	ct = len(tag.attrib)
	for child in tag:
		ct += calcscore(child)
	return ct
n = int(input())
s = ''
for i in range(0, n):
	s = s + input()
	s += '\n'
root = etree.fromstring(s)
ct = calcscore(root)
print(ct)


import xml.etree.ElementTree as etree

def val(root):
	count = 0
	count += len(root.attrib)
	for child in root:
		count += val(child)
	return count
n = int(input())
xml = ''
for i in range(n):
	xml += input()
tree = etree.ElementTree(etree.fromstring(xml))
t = 0
root = tree.getroot()
t += val(root)
print(t)


import xml.etree.ElementTree as etree

def na(node):
	val = len(node.attrib)
	for ch in node:
		val += na(ch)
	return val
n = int(input())
xml = ''
for i in range(n):
	xml += input()
tree = etree.ElementTree(etree.fromstring(xml))
print(na(tree.getroot()))


t = int(input())
str = ''
score = 0
for i in range(t):
	str += input()
for i in str:
	if i == '=':
		score += 1
print(score)


import xml.etree.ElementTree as etree

def count_attrib(node):
	nb = len(node.attrib)
	for child in node:
		nb += count_attrib(child)
	return nb
n = int(input())
xml = '\n'.join([input() for _ in range(n)])
tree = etree.ElementTree(etree.fromstring(xml)).getroot()
print(count_attrib(tree))


import xml.etree.ElementTree as etree

def score(parent):
	anz = len(parent.attrib)
	for child in parent:
		anz += score(child)
	return anz
N = int(input())
xml = ''
for i in range(N):
	xml += input() + '\n'
tree = etree.ElementTree(etree.fromstring(xml))
print(score(tree.getroot()))


n = int(input())
st = ''
for i in range(n):
	st += input()
print(st.count('='))


import sys
import xml.etree.ElementTree as etree

def count_score(element):
	score = len(element.attrib)
	if len(element) == 0:
		return score
	return score + sum((count_score(child) for child in element))
lines_number = int(sys.stdin.readline().strip())
xml = []
for line in range(lines_number):
	xml.append(sys.stdin.readline())
tree = etree.ElementTree(etree.fromstring(' '.join(xml)))
root = tree.getroot()
score = count_score(root)
print(score)


import sys
import xml.etree.ElementTree as ET
_ = input()
print(sum((len(v.attrib) for v in ET.ElementTree(file=sys.stdin).iter())))


N = int(input())
s = 0
for i in range(N):
	line = input().split('>')[0].split()
	s = s + len(line) - 1
print(s)


import xml.etree.ElementTree as etree
N = int(input())
xml = ''
for i in range(N):
	xml += str(input())
tree = etree.ElementTree(etree.fromstring(xml))
count = 0
for element in tree.iter():
	count += len(element.attrib)
print(count)


import xml.etree.ElementTree as ET
N = int(input())
xmlstr = ''
for i in range(0, N):
	xmlstr = xmlstr + input()
root = ET.fromstring(xmlstr)
l = root.findall('.//')
output = 0
output = output + len(root.attrib)
for i in range(0, len(l)):
	output = output + len(l[i].attrib)
print(output)


import io
import xml.etree.ElementTree as etree
s = io.StringIO('\n'.join((input() for i in range(int(input())))))
score = 0
for (event, element) in etree.iterparse(s):
	score += len(element.attrib)
print(score)


import xml.etree.ElementTree as etree
n = int(input())
xml_string = ''.join([input() for _ in range(n)])
root = etree.ElementTree(etree.fromstring(xml_string)).getroot()
res = 0
stack = [root]
while len(stack) != 0:
	tag = stack.pop()
	res += len(tag.attrib)
	for child in tag:
		stack.append(child)
print(res)


import xml.etree.ElementTree as etree
n = int(input())
xml = ''.join([input() for i in range(n)])
root = etree.fromstring(xml)
counter = 0
for n in root.iter():
	counter += len(n.attrib)
print(str(counter))


import xml.etree.ElementTree as ET
xmlstring = ''
for i in range(int(input())):
	xmlstring += input()
tree = ET.ElementTree(ET.fromstring(xmlstring))
count = 0
for elem in tree.iter():
	count += len(elem.attrib)
print(count)


xml_str = ''
n = int(input())
for i in range(0, n):
	tmp_str = input()
	xml_str = xml_str + tmp_str
cnt = xml_str.count("='")
print(cnt)


import xml.etree.ElementTree as etree
count = int(input())
data = ''
for x in range(count):
	data = data + input()
tree = etree.ElementTree(etree.fromstring(data))
score = 0
for elem in tree.iter():
	score = score + len(elem.attrib)
print(score)


ans = 0
for t in range(int(input())):
	ans += input().count('=')
print(ans)


def CountAtt(node):
	count = len(node.keys())
	for child in node:
		count = count + CountAtt(child)
	return count
import xml.etree.ElementTree as etree
n = int(input())
xml = ''
for i in range(0, n):
	xml = xml + input()
tree = etree.ElementTree(etree.fromstring(xml))
root = tree.getroot()
print(CountAtt(root))


import xml.etree.ElementTree as etree
lines = int(input())
xml = ''
for i in range(lines):
	xml += input()
score = 0
tree = etree.ElementTree(etree.fromstring(xml))
for x in tree.iter():
	score += len(x.attrib)
print(score)


n = int(input())
s = 0
for i in range(n):
	line = input()
	s += line.count('=')
print(s)


n = eval(input())
j = 0
for i in range(n):
	k = input()
	for f in k:
		if f == '>':
			break
		if f == '=':
			j += 1
print(j)


import sys
import xml.etree.ElementTree as ET
(_, tree) = (input(), ET.parse(sys.stdin))
print(sum((len(element.attrib) for element in tree.iter())))


n = int(input())
xml = '\n'.join((input() for _ in range(n)))
import xml.etree.ElementTree as etree
tree = etree.ElementTree(etree.fromstring(xml))
root = tree.getroot()

def visit(node):
	count = len(node.attrib)
	for child in node:
		count += visit(child)
	return count
print(visit(root))


N = int(input())

def count_of_attr(root):
	count = len(root.attrib)
	for child in root:
		count += count_of_attr(child)
	return count
import xml.etree.ElementTree as etree
count = 0
xml = ''
for i in range(N):
	xml += input()
tree = etree.ElementTree(etree.fromstring(xml))
root = tree.getroot()
count = count_of_attr(root)
print(count)