def reduce(self, debug=False, inputFilename=None, secondInputFilename=None, outputFilename=None):
		output = None
		if debug:
			inputList = [open(inputFilename, 'r'), open(secondInputFilename, 'r')]
			output = open(outputFilename, 'w')
		else:
			inputList = [sys.stdin]

		symbols = set()
		for input in inputList:
			for equation in input:
				splits = equation.strip().split('\t')
				if splits[0] == '-1':
					symbols = decodeExpression(splits[1])
				else:
					equationIndex = splits[0]
					equation = expand(splits[1])
					if output is not None:
						output.write("{0}\t{1}\n".format(equationIndex, encodeExpression((equation, symbols))))
					else:
						print("{0}\t{1}".format(equationIndex, encodeExpression((equation, symbols))))
		if debug:
			input.close()
		if output is not None:
			output.close()
	def reduce(self, debug=False, inputFilename=None, outputFilename=None):
		previousLeftBlockRegion = -1
		previousRightBlockRegion = -1
		equationCount = 0
		partIndex = 0
		equationInPartIndex = 0

		output = None
		if debug:
			input = open(inputFilename, 'r')
			output = open(outputFilename, 'w')
		else:
			input = sys.stdin

		for strEquation in input:
			equationCount += 1
			index, strEquation = strEquation.strip().split('\t')
			equation, symbols = decodeExpression(strEquation)
			equation = Poly(equation, symbols)
			equationCoefficients = [0] * len(symbols)
			for monom, coeff in equation.terms():
				try:
					i = list(monom).index(1)
					equationCoefficients[i] = 1 if coeff != 0 else 0
				except ValueError:
					continue

			equationLen = len(equationCoefficients)
			rightColumnIndex = equationLen - 1
			leftColumnIndex = 0

			while leftColumnIndex < equationLen and equationCoefficients[leftColumnIndex] != 1:
				leftColumnIndex += 1
			while rightColumnIndex > 0 and equationCoefficients[rightColumnIndex] != 1:
				rightColumnIndex -= 1

			if previousLeftBlockRegion != leftColumnIndex or previousRightBlockRegion != rightColumnIndex:
				if equationInPartIndex > 0:
					partIndex += 1
					equationInPartIndex = 0
				previousLeftBlockRegion = leftColumnIndex
				previousRightBlockRegion = rightColumnIndex
			if output is not None:
				output.write('{0}\t{1}\t{2}\n'.format(str(partIndex), index, strEquation))
			else:
				print('{0}\t{1}\t{2}'.format(str(partIndex), index, strEquation))
			equationInPartIndex += 1
		if debug:
			input.close()
		if output is not None:
			output.close()