You are given a valid XML document, and you have to print the maximum level of nesting in it. Take the depth of the root as $\mbox{0}$.

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 value of the maximum level of nesting in the 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  

1

Explanation

Here, the root is a feed tag, which has depth of $\mbox{0}$. 

The tags title, subtitle, link and updated all have a depth of $\mbox{1}$. 

Thus, the maximum depth is $\mbox{1}$.

Difficulty: EASY

Starter code:

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

def walk(root):
	children = [child for child in root]
	if len(children) == 0:
		return 0
	return 1 + max((walk(child) for child in root))
print(walk(tree.getroot()))


import re
num = int(input())
depth = 0
depths = [0]
open = 0
global flag

def find_depth(s):
	global flag
	if len(s) == 0:
		return 0
	if s.find('<') == -1:
		flag = 1
		return 0
	s = s[s.find('<'):]
	if s[0] == '<' and s[1] != '/':
		flag = 0
		if s[s.find('>') - 1] == '/':
			n = find_depth(s[s.find('>') + 1:])
			depths.append(n)
			return n
		else:
			n = find_depth(s[s.find('>') + 1:])
			depths.append(n)
			return 1 + n
	if s[0:2] == '</':
		n = find_depth(s[s.find('>') + 1:])
		depths.append(n)
		return -1 + n
flag = 0
for i in range(num):
	s = str(input()).strip()
	if len(s) < 2:
		continue
	n = find_depth(s)
	if n < 0:
		if flag:
			flag = 0
			depth -= 1
		depths.append(depth)
		depth = n
	elif n > 0:
		depth += n
print(max(depths))


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

def elemDepth(node):
	if node.childNodes:
		return max(map(depth, node.childNodes))
	else:
		return 0

def depth(node):
	if node.nodeType == node.ELEMENT_NODE:
		return 1 + elemDepth(node)
	elif node.nodeType == node.DOCUMENT_NODE:
		return elemDepth(node)
	else:
		return 0
print(depth(root) - 1)


N = int(input())
xml = ''
for _ in range(N):
	xml += input()
import xml.etree.ElementTree as etree
tree = etree.fromstring(xml)

def getMaxDepth(node, depth):
	return max([depth] + [getMaxDepth(e, depth + 1) for e in node])
print(getMaxDepth(tree, 0))


xml_str = ''
n = int(input())
for i in range(0, n):
	tmp_str = input()
	xml_str = xml_str + tmp_str
import xml.etree.ElementTree as etree
tree = etree.ElementTree(etree.fromstring(xml_str))
root = tree.getroot()
ar = []

def cnt_node(node):
	return max([0] + [cnt_node(child) + 1 for child in node])
cnt = cnt_node(root)
print(cnt)


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

def depth(node):
	if len(node) == 0:
		return 0
	max_depth = 0
	for child in node:
		cdepth = depth(child)
		if cdepth > max_depth:
			max_depth = cdepth
	return max_depth + 1
print(depth(root))


def countNodeScore(node):
	count = len(node.attrib)
	for n in node:
		count += countNodeScore(n)
	return count

def maxDepth(node):
	max = 0
	for n in node:
		m = maxDepth(n) + 1
		max = m if m > max else max
	return max
xml = ''
for x in range(0, int(input())):
	xml += input()
import xml.etree.ElementTree as etree
tree = etree.ElementTree(etree.fromstring(xml))
max = 0
print(maxDepth(tree.getroot()))


import xml.etree.ElementTree as etree

def d(node, cur):
	val = cur
	for ch in node:
		val = max(val, d(ch, cur + 1))
	return val
n = int(input())
xml = ''
for i in range(n):
	xml += input()
tree = etree.ElementTree(etree.fromstring(xml))
print(d(tree.getroot(), 0))


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

def maxdepth(node):
	return 0 if not list(node) else 1 + max((maxdepth(i) for i in list(node)))
print(maxdepth(tree.getroot()))


import xml.etree.ElementTree as etree
xml = ''
n = int(input())
for i in range(n):
	xml += input()
tree = etree.ElementTree(etree.fromstring(xml))
stack = [0]
height = 0
j = 0
a = []
for i in tree.iter():
	x = stack.pop()
	x -= 1
	if x >= 0:
		stack.append(x)
	o = len(i.getchildren())
	if o != 0:
		stack.append(o)
	height = max(height, len(stack))
print(height)


import xml.etree.ElementTree as etree

def depth(node):
	return max([0] + [depth(child) + 1 for child in node])
lines = int(input())
xml = ''
for i in range(lines):
	xml += input()
tree = etree.ElementTree(etree.fromstring(xml))
root = tree.getroot()
print(depth(root))


import xml.etree.ElementTree as etree

def depth(root):
	return max([0] + [depth(child) + 1 for child in root])
N = int(input())
xml = ''
for i in range(N):
	xml += input()
print(depth(etree.ElementTree(etree.fromstring(xml)).getroot()))


import xml.etree.ElementTree as etree

def get_root():
	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 find_max_depth(root):
	if not len(root):
		return 0
	else:
		cur_depth = []
		for child in root:
			cur_depth.append(find_max_depth(child))
		return max(cur_depth) + 1

def main():
	root = get_root()
	max_depth = find_max_depth(root)
	print(max_depth)
main()


import sys
input()
text = sys.stdin.read()
(depth, max_depth) = (-1, -1)
for (i, c) in enumerate(text):
	if c == '<':
		if text[i + 1] == '/':
			depth -= 1
		else:
			depth += 1
			if depth > max_depth:
				max_depth = depth
	if text[i:i + 2] == '/>':
		depth -= 1
print(max_depth)


def MaxDepth(node):
	mx = 0
	for child in node:
		d = 1 + MaxDepth(child)
		if d > mx:
			mx = d
	return mx
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(MaxDepth(root))


from xml.etree.ElementTree import XMLParser

class MaxDepth:
	maxDepth = 0
	depth = 0

	def start(self, tag, attrib):
		self.depth += 1
		if self.depth > self.maxDepth:
			self.maxDepth = self.depth

	def end(self, tag):
		self.depth -= 1

	def data(self, data):
		pass

	def close(self):
		return self.maxDepth
xmlstring = ''
lines = int(input())
for i in range(0, lines):
	xmlstring = xmlstring + input()
target = MaxDepth()
parser = XMLParser(target=target)
parser.feed(xmlstring)
parser.close()
print(target.maxDepth - 1)


import xml.etree.ElementTree as etree
n = int(input())
xml_string = ''.join([input() for _ in range(n)])
root = etree.fromstring(xml_string)
stack = [root]
max_depth = 0
depths = {root: 0}
while len(stack) != 0:
	parent = stack.pop()
	if len(parent) > 0:
		for child in parent:
			stack.append(child)
			depths[child] = depths[parent] + 1
	elif depths[parent] > max_depth:
		max_depth = depths[parent]
print(max_depth)


import xml.etree.ElementTree as etree

def depth(tree):
	lst = list(tree.iter())
	if len(lst) == 1:
		return 0
	else:
		lst.remove(lst[0])
		dpt = 0
		for et in lst:
			dpt = max(dpt, depth(et))
		return dpt + 1
N = input()
count = 0
xml = ''
for i in range(0, int(N)):
	xml += input()
tree = etree.ElementTree(etree.fromstring(xml))
print(depth(tree))


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, d):
	cd = d
	for child in node:
		cd = max(cd, visit(child, d + 1))
	return cd
print(visit(root, 0))


import xml.etree.ElementTree as etree
lines = input()
xml = ''
for i in range(int(lines)):
	xml = xml + input()
tree = etree.ElementTree(etree.fromstring(xml))
parent_map = {p.tag: c.tag for p in tree.iter() for c in p}
print(len(parent_map))


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

def dfs(root):
	res = 0
	for child in root:
		res = max(res, dfs(child) + 1)
	return res
print(dfs(root))


import xml.etree.ElementTree as etree

def fun(root):
	if not root:
		return 0
	depth = 0
	for child in root:
		temp = 1 + fun(child)
		if temp > depth:
			depth = temp
	return depth
var = int(input())
string = ''
for i in range(0, var):
	string += input()
tree = etree.ElementTree(etree.fromstring(string))
root = tree.getroot()
depth = fun(root)
print(depth)


import xml.etree.ElementTree as etree
n = int(input())
text = ''
for i in range(n):
	text += input()
xml_tree = etree.ElementTree(etree.fromstring(text))

def get_depth(element, depth=0):
	if len(element):
		cds = []
		for child in element:
			cds.append(get_depth(child, depth + 1))
		depth = sorted(cds)[-1]
	return depth
depth = get_depth(xml_tree.getroot())
print(depth)


import xml.etree.ElementTree as etree

def maxxmldepth(tag, depth):
	maxdepth = depth
	for child in tag:
		k = maxxmldepth(child, depth + 1)
		if k > maxdepth:
			maxdepth = k
	return maxdepth
n = int(input())
s = ''
for i in range(0, n):
	s = s + input()
	s += '\n'
root = etree.fromstring(s)
md = maxxmldepth(root, 0)
print(md)


import xml.etree.ElementTree as etree

def get_depth(root):
	a = 0
	if len(root) != 0:
		a = 1
		l = [get_depth(child) for child in root]
		a += max(l)
	return a
N = int(input())
s = str()
for i in range(N):
	s += input() + '\n'
root = etree.XML(s)
print(get_depth(root))


import sys
import xml.etree.ElementTree as ET
_ = int(input())
f = lambda v: max([0] + [f(u) + 1 for u in v])
print(f(ET.fromstring(sys.stdin.read())))


def parseXML(xml):
	p = ''
	c = '</>'
	for x in xml:
		if x in c:
			p += x
	return p
n = int(input())
d = -1
m = -1
xml = ''
for i in range(n):
	xml += input()
p = parseXML(xml)
for ind in range(len(p)):
	if p[ind:ind + 3] == '</>':
		d -= 1
	elif p[ind:ind + 2] == '<>':
		d += 1
		if d > m:
			m = d
print(max(m, 0))


import xml.etree.ElementTree as ET

def depth(node):
	res = 0
	for child in node:
		res = max(res, depth(child) + 1)
	return res
xml = ''
for _ in range(int(input())):
	xml += input()
root = ET.fromstring(xml)
print(depth(root))


class MaxDepth:
	maxDepth = 0
	depth = -1

	def start(self, tag, attrib):
		self.depth += 1
		if self.depth > self.maxDepth:
			self.maxDepth = self.depth

	def end(self, tag):
		self.depth -= 1

	def data(self, data):
		pass

	def close(self):
		return self.maxDepth
n = int(input())
xml = ''
for i in range(n):
	xml += input() + '\n'
from xml.etree.ElementTree import XMLParser
target = MaxDepth()
parser = XMLParser(target=target)
parser.feed(xml)
print(parser.close())


import xml.etree.ElementTree as etree

def depth(root):
	return max([0] + [depth(child) + 1 for child in root])
N = int(input())
xml = ''
for i in range(N):
	xml += str(input())
tree = etree.ElementTree(etree.fromstring(xml))
root = tree.getroot()
print(depth(root))


import sys
import xml.etree.ElementTree as etree
input()
tree = etree.parse(sys.stdin)
root = tree.getroot()
stack = []
max_depth = 0
for child in root:
	stack.append([1, child])
for (depth, element) in stack:
	max_depth = max(max_depth, depth)
	for child in element:
		stack.append([depth + 1, child])
print(max_depth)


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

def MaxDepth(e):
	d = -1
	l = list(e)
	for i in l:
		d = max(d, MaxDepth(i))
	return d + 1
print(MaxDepth(tree.getroot()))


from xml.etree.ElementTree import XMLParser

class MaxDepth:
	maxdepth = 0
	d = 0

	def start(self, tag, attribute):
		self.d += 1
		if self.d > self.maxdepth:
			self.maxdepth = self.d

	def end(self, tag):
		self.d -= 1

	def data(self, data):
		pass

	def close(self):
		return self.maxdepth
n = int(input())
i = 0
xml = ''
while i < n:
	xml = xml + input() + '\n'
	i = i + 1
xy = MaxDepth()
parser = XMLParser(target=xy)
parser.feed(xml)
print(parser.close() - 1)


import xml.etree.ElementTree as ET
N = int(input())
xml_string = ''
for i in range(N):
	xml_string += input()

def get_depth(node, n):
	result = n
	for elem in node:
		if len(list(node)) > 0:
			result = max(result, get_depth(elem, n + 1))
	return result
root = ET.fromstring(xml_string)
print(get_depth(root, 0))


n = input()
n = int(n)
i = 0
inn = 0
maxx = 0
count = 0
while i < n:
	m = input()
	j = 0
	while j < len(m):
		if m[j] == '<' and m[j + 1] != '/':
			count = count + 1
		elif m[j] == '<' and m[j + 1] == '/':
			count = count - 1
		elif m[j] == '/' and m[j + 1] == '>':
			count = count - 1
		if maxx < count:
			maxx = count
		j = j + 1
	i = i + 1
print(int(maxx) - 1)


import xml.etree.ElementTree as etree

def depth(parent):
	cur = 0
	for child in parent:
		cur = max(cur, depth(child))
	return 1 + cur
N = int(input())
xml = ''
for i in range(N):
	xml += input() + '\n'
tree = etree.ElementTree(etree.fromstring(xml))
print(depth(tree.getroot()) - 1)


import xml.etree.ElementTree as etree

def get_child_depth(el, n):
	if len(el) > 0:
		n += 1
		for child in el:
			n = get_child_depth(child, n)
	return n

def get_attr(tree):
	root = tree.getroot()
	n = 0
	D = []
	if len(root) > 0:
		n += 1
		for child in root:
			D.append(get_child_depth(child, n))
	else:
		return 0
	return max(D)
N = int(input())
xml = ''
for _ in range(N):
	xml += input()
tree = etree.ElementTree(etree.fromstring(xml))
print(get_attr(tree))


from xml.etree.ElementTree import XMLParser

class MaxDepth:
	depth = -1
	maxDepth = -1

	def start(self, tag, attrib):
		self.depth += 1
		if self.depth > self.maxDepth:
			self.maxDepth = self.depth

	def end(self, tag):
		self.depth -= 1

	def data(self, data):
		pass

	def close(self):
		return self.maxDepth
target = MaxDepth()
parser = XMLParser(target=target)
for i in range(int(input())):
	parser.feed(input())
print(str(parser.close()))


maxdepth = 0

def depth(elem, level):
	if level == -1:
		level = 0
	nonlocal maxdepth
	if level > maxdepth:
		maxdepth = level
	for el in elem:
		depth(el, level + 1)


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


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

def max_depth(el, i):
	return max([max_depth(child, i + 1) for child in el] + [i])
print(max_depth(tree.getroot(), 0))


n = int(input())
import xml.etree.ElementTree as et
ans = []

def perf(elem, level=0):
	for child in elem.getchildren():
		perf(child, level + 1)
	ans.append(level)
xml = ''
for i in range(n):
	xxml = input()
	xml = xml + xxml + '\n'
root = et.fromstring(xml)
perf(root, 0)
print(max(ans))


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, depth):
	maxdepth = depth
	for item in tree:
		temp = dfs(item, depth + 1)
		maxdepth = temp if temp > maxdepth else maxdepth
	return maxdepth
print(dfs(tree, 0))


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


import sys
from xml.etree.ElementTree import XMLParser
(_, xmlstring) = (input(), sys.stdin.read())

class DepthCounter:

	def __init__(self):
		self.maxDepth = 0
		self.depth = -1

	def start(self, tag, attrib):
		self.depth += 1
		self.maxDepth = max(self.depth, self.maxDepth)

	def end(self, tag):
		self.depth -= 1

	def data(self, data):
		pass

	def close(self):
		return self.maxDepth
target = DepthCounter()
parser = XMLParser(target=target)
parser.feed(xmlstring)
print(parser.close())


import xml.etree.ElementTree as etree

def maxDepth(element):
	childDepth = 0
	for child in element:
		childDepth = max(childDepth, maxDepth(child))
	return 1 + childDepth
xml = ''
for _ in range(0, int(input())):
	xml = xml + input()
tree = etree.ElementTree(etree.fromstring(xml))
print(maxDepth(tree.getroot()) - 1)


depth = -1
mdepth = -1
n = int(input())
for i in range(n):
	line = input()
	for j in range(len(line)):
		if line[j] == '<' and line[j + 1] != '/':
			depth += 1
			mdepth = max(mdepth, depth)
		elif line[j] == '<':
			depth -= 1
		elif line[j] == '/' and line[j + 1] == '>':
			depth -= 1
print(mdepth)


import xml.etree.ElementTree as etree

def count(root):
	if len(root) == 0:
		return 1
	else:
		lis = []
		for i in range(len(root)):
			lis.append(count(root[i]))
		return max(lis) + 1
no = int(input())
xml = ''
for i in range(no):
	xml = xml + input() + '\n'
tree = etree.ElementTree(etree.fromstring(xml))
root = tree.getroot()
print(count(root) - 1)


n = int(input())
xml = ''
for i in range(n):
	xml += input()

def maxDepth(elem):
	if len(elem) == 0:
		return 0
	else:
		best = 0
		for child in elem:
			child_depth = maxDepth(child)
			if child_depth > best:
				best = child_depth
		return best + 1
import xml.etree.ElementTree as etree
tree = etree.ElementTree(etree.fromstring(xml))
root = tree.getroot()
print(maxDepth(root))


from xml.etree.ElementTree import XMLParser

class MaxDepth:
	maxDepth = depth = 0

	def start(self, tag, attrib):
		self.depth += 1
		if self.depth > self.maxDepth:
			self.maxDepth = self.depth

	def end(self, tag):
		self.depth -= 1

	def data(self, data):
		pass

	def close(self):
		return self.maxDepth - 1
parser = XMLParser(target=MaxDepth())
for _ in range(int(input())):
	parser.feed(input())
print(parser.close())


import xml.etree.ElementTree as etree

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


def count_depth(parent):
	sub = 0
	for child in parent:
		sub = max(sub, count_depth(child))
	return sub + 1
import xml.etree.ElementTree as etree
N = int(input())
xml = [input() for n in range(N)]
tree = etree.ElementTree(etree.fromstring('\n'.join(xml)))
print(count_depth(tree.getroot()) - 1)


n = int(input())
xml = ''
for x in range(n):
	xml += input() + '\n'
import xml.etree.ElementTree as etree
tree = etree.ElementTree(etree.fromstring(xml))

def walk(node, r):
	mx = r
	for n in node:
		mx = max(mx, walk(n, r + 1))
	return mx
print(walk(tree.getroot(), 0))


def dfs(root):
	if len(root) == 0:
		return 0
	res = 0
	for child in root:
		res = max(res, dfs(child) + 1)
	return res
import xml.etree.ElementTree as ET
N = int(input())
s = ''
for i in range(N):
	s = s + input()
root = ET.fromstring(s)
print(dfs(root))


cur_max = 0
cur = 0
for i in range(int(input())):
	s = input().strip()
	flag = True
	for i in range(len(s)):
		if s[i] == '<':
			flag = True
			if s[i + 1] == '/':
				cur -= 1
				flag = False
			if flag and cur > cur_max:
				cur_max = cur
		if s[i] == '>':
			if flag and s[i - 1] != '/':
				cur += 1
print(cur_max)


import sys
import xml.etree.ElementTree as etree

def MaxDepth(element, depth):
	candidates = [MaxDepth(i, depth + 1) for i in element.getchildren()]
	candidates.append(depth)
	return max(candidates)
num = int(input())
xml = ''
for i in range(0, num):
	xml += input()
tree = etree.ElementTree(etree.fromstring(xml))
print(MaxDepth(tree.getroot(), 0))


import xml.etree.ElementTree as etree, sys

def max_depth(node):
	sub_depth = 0
	for child in node:
		sub_depth = max(sub_depth, max_depth(child))
	return sub_depth + 1
_ = input()
print(-1 + max_depth(etree.parse(sys.stdin).getroot()))


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 = -1
	for child in root:
		ans = max(ans, dfs(child))
	return ans + 1
print(dfs(tree.getroot()))


n = int(input())
count = 0
x = 0
c = int(n * 2)
a = []
for i in range(n):
	b = input()
	for j in range(0, len(b)):
		if '<' == b[j:j + 1] and '</' != b[j:j + 2]:
			a.append(1)
			count = sum(a)
			if count > x:
				x = count
		if '/>' == b[j:j + 2] or '</' == b[j:j + 2]:
			a.append(-1)
print(x - 1)


from sys import stdin
from xml.etree.ElementTree import XMLParser

class MaxDepth:
	maxDepth = -1
	depth = -1

	def start(self, tag, attrib):
		self.depth += 1
		if self.depth > self.maxDepth:
			self.maxDepth = self.depth

	def end(self, tag):
		self.depth -= 1

	def data(self, data):
		pass

	def close(self):
		return self.maxDepth

def main():
	num_lines = int(stdin.readline())
	lines = '\n'.join([stdin.readline() for i in range(num_lines)])
	parser = XMLParser(target=MaxDepth())
	parser.feed(lines)
	print(parser.close())
main()


import xml.etree.ElementTree as etree

def depth(elems):
	if elems:
		return 1 + max([depth(e) for e in elems])
	else:
		return 0
xml = '\n'.join([input() for _ in range(int(input()))])
tree = etree.ElementTree(etree.fromstring(xml))
print(max([depth(i) for i in tree.findall('.')]))


import xml.etree.ElementTree as etree
import io

def get_max_depth(element):
	if len(element):
		max_child_depth = 0
		for child in element:
			child_depth = get_max_depth(child)
			if child_depth > max_child_depth:
				max_child_depth = child_depth
		return max_child_depth + 1
	else:
		return 1

def main():
	n = int(input())
	strings = [str(input()) for i in range(n)]
	xml_file = io.StringIO(''.join(strings))
	tree = etree.parse(xml_file)
	max_depth = get_max_depth(tree.getroot()) - 1
	if max_depth < 0:
		max_depth = 0
	print(max_depth)
main()


import sys
import xml.etree.ElementTree as etree

def freopen(f, option, stream):
	import os
	oldf = open(f, option)
	oldfd = oldf.fileno()
	newfd = stream.fileno()
	os.close(newfd)
	os.dup2(oldfd, newfd)

def parseyuk(root):
	if len(root) == 0:
		return 0
	ans = 0
	for child in root:
		ans = max(ans, parseyuk(child) + 1)
	return ans
n = int(input())
xml = ''
for i in range(n):
	xml += input()
tree = etree.ElementTree(etree.fromstring(xml))
root = tree.getroot()
ans = parseyuk(root)
print(ans)


import xml.etree.ElementTree as ET
import sys
n = 0
document = ''
for line in sys.stdin:
	if n == 0:
		pass
	else:
		document += line
	n = +1
tree = ET.fromstring(document)
tree_iter = tree.iter()
parent_map = dict(((c, p) for p in tree.getiterator() for c in p))

def count_depth(elem):
	count = 0
	while True:
		if parent_map.get(elem) is None:
			break
		else:
			count += 1
			elem = parent_map.get(elem)
	return count
sys.stdout.write(str(max([count_depth(elem) for elem in tree_iter])))


import xml.etree.ElementTree as etree

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

def tree_get_depth(tree):

	def recurse(node):
		relative_depth = 0
		if len(node) > 0:
			child_depths = [recurse(child) for child in node]
			relative_depth += 1 + max(child_depths)
		return relative_depth
	return recurse(tree)
root = etree.fromstring(get_xml())
print(tree_get_depth(root))


import xml.etree.ElementTree as etree

def height(node):
	return max([0] + [height(child) + 1 for child in node])
lines = int(input())
xml = ''
for l in range(lines):
	xml += input()
tree = etree.ElementTree(etree.fromstring(xml))
print(height(tree.getroot()))


import xml.etree.ElementTree as etree

def getMaxDepth(root):
	maxDepth = 0
	queue = [{'root': root, 'depth': 0}]
	while len(queue) > 0:
		parent = queue.pop()
		if len(parent['root']) == 0:
			maxDepth = max(parent['depth'], maxDepth)
		else:
			for child in parent['root']:
				queue.append({'root': child, 'depth': parent['depth'] + 1})
	return maxDepth
xml = ''
for i in range(int(input())):
	xml += input()
tree = etree.ElementTree(etree.fromstring(xml))
root = tree.getroot()
print(getMaxDepth(root))


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 max_depth(element):
	if len(element) == 0:
		return 0
	else:
		return max([max_depth(i) for i in element]) + 1
print(max_depth(tree))


import xml.etree.ElementTree as etree

def ans(tree):
	res = 0
	for child in tree:
		res = max(res, ans(child))
	return res + 1
n = int(input())
s = ''
for i in range(n):
	s += input()
tree = etree.fromstring(s)
print(ans(tree) - 1)


import xml.etree.ElementTree as etree
parent_map = {}

def depth(node):
	depth = 0
	parent = parent_map.get(node)
	while parent is not None:
		depth += 1
		node = parent
		parent = parent_map.get(node)
	return depth
lines = int(input())
xml = ''
for _ in range(lines):
	xml += '\n' + input()
tree = etree.ElementTree(etree.fromstring(xml))
parent_map = dict(((c, p) for p in tree.iter() for c in p))
root = tree.getroot()
maxDepth = 0
for elem in root.iter():
	if maxDepth < depth(elem):
		maxDepth = depth(elem)
print(maxDepth)


import io
import xml.etree.ElementTree as etree
s = io.StringIO('\n'.join((input() for i in range(int(input())))))
(maxdepth, curdepth) = (0, -1)
for (event, element) in etree.iterparse(s, ('start', 'end')):
	if event == 'start':
		curdepth += 1
		if curdepth >= maxdepth:
			maxdepth = curdepth
	else:
		curdepth -= 1
print(maxdepth)


N = int(input())
xml = ''
for i in range(N):
	xml += input()
import xml.etree.ElementTree as ET
root = ET.fromstring(xml)

def DFS(root):
	depth = 0
	for node in root:
		depth = max(depth, DFS(node) + 1)
	return depth
print(DFS(root))


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

class Parser:
	max_depth = 0
	depth = -1

	def start(self, tag, attrib):
		self.depth += 1
		self.max_depth = max(self.depth, self.max_depth)

	def end(self, tag):
		self.depth -= 1

	def data(self, data):
		pass

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


try:
	import xml.etree.cElementTree as etree
except ImportError:
	import xml.etree.ElementTree as etree

def depth(root, l):
	for child in root:
		if child is not None:
			l.append(root.tag)
			depth(child, l)
	return l
n = int(input())
buffer = []
for i in range(n):
	line = input()
	buffer.append(line)
multiline_string = '\n'.join(buffer)
tree = etree.ElementTree(etree.fromstring(multiline_string))
root = tree.getroot()
l = []
k = depth(root, l)
print(len(set(k)))


__author__ = 'nolanemirot'
from xml.etree.ElementTree import XMLParser

class MaxDepth:
	maxDepth = 0
	depth = 0

	def start(self, tag, attrib):
		self.depth += 1
		if self.depth > self.maxDepth:
			self.maxDepth = self.depth

	def end(self, tag):
		self.depth -= 1

	def data(self, data):
		pass

	def close(self):
		return self.maxDepth

def find_depth(chaine):
	target = MaxDepth()
	parser = XMLParser(target=target)
	exampleXml = "<feed xml:lang='en'>\n        <title>HackerRank</title>\n        <subtitle lang='en'>Programming challenges</subtitle>\n        <link rel='alternate' type='text/html' href='http://hackerrank.com/'/>\n        <updated>2013-12-25T12:00:00</updated>\n    </feed>"
	parser.feed(chaine)
	print(parser.close() - 1)
xml = ''
nbAttrib = 0
nbTests = int(input())
for i in range(0, nbTests):
	xml += input()
find_depth(xml)


import xml.etree.ElementTree as etree

def deep(tp):
	ans = 0
	for ch in tp:
		ans = max(ans, deep(ch))
	return ans + 1
n = int(input())
xml = ''
for i in range(n):
	tp = str(input())
	xml = xml + tp
tree = etree.ElementTree(etree.fromstring(xml))
root = tree.getroot()
print(deep(root) - 1)