private List<Gate> getLayeredGates(List<List<Gate>> gates, int inputSize) {
		List<Gate> res = new ArrayList<Gate>();

		// Init wireLayer map with input wires
		HashMap<Integer, Integer> wireLayers = new HashMap<Integer, Integer>();
		for (int i = 0; i < inputSize; i++) {
			wireLayers.put(i, 0);
		}

		for (List<Gate> list: gates) {
			for (Gate g: list) {
				int topologicalLayer = 0;
				if (g.isAND() || g.isXOR()) {
					int a = wireLayers.get(g.getLeftWireIndex());
					int b = wireLayers.get(g.getRightWireIndex());
					if (g.isAND()) {
						topologicalLayer = Math.max(a, b) + 1;
						g.setTopologicalLayer(topologicalLayer - 1);
					} else if (g.isXOR()) {
						topologicalLayer = Math.max(a, b);
						g.setTopologicalLayer(topologicalLayer);
					}
				} else if (g.isINV()) {
					topologicalLayer = wireLayers.get(g.getLeftWireIndex());
					g.setTopologicalLayer(topologicalLayer);
				} else {
					System.out.println("Input Circuit may only consist of XOR, INV, AND");
					System.out.println("Terminating without output");
					System.exit(-1);
				}
				wireLayers.put(g.getOutputWireIndex(), topologicalLayer);

				res.add(g);
			}
		}
		Collections.sort(res, new TopoTypeComparator());
		return res;
	}