public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String line = "";
		StringBuilder out = new StringBuilder();
		do {
			line = in.readLine();
			if (line == null || line.length() == 0)
				break;
			String[] d = line.trim().split(" ");
			if(d[0].trim().equals("0"))
				break;
			v = new long[d.length];
			v[0] = Long.MAX_VALUE;
			st = new SegTree(1, d.length-1);
			for (int i = 1; i < d.length; i++) {
				v[i] = Long.parseLong(d[i].trim());
				st.set(i, v[i]);
			}
			out.append(st.getMaxArea(1, d.length-1)+"\n");
		} while (line != null && line.length() != 0);
		System.out.print(out);
	}