#!/usr/bin/env python
import fileinput

try:
	for line in fileinput.input():
		if fileinput.isfirstline():
			startOfDocument=1
			depth=0
		pos = line.find("<")
		while pos != -1:

			# "</..." means it's a closing tag
			if line[pos + 1] == '/':
				depth -= 1
			else:
				if depth == 0 and startOfDocument == 0:
					print "Found new root element in file " + fileinput.filename() + ", line " + str(fileinput.filelineno()) + ":"
					print line.rstrip()
					print " " * pos + "^"

				# Opening tags always look like "<...>", but not "<.../>"
				closingBracePos = line.find(">", pos + 1)
				if line[closingBracePos - 1] != '/' and line[closingBracePos - 2] != '/':
					depth += 1

				startOfDocument=0

			pos = line.find("<", pos + 1)

except IOError, e:
	print e
