import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = getInt(sc);

		long sum = getLong(sc);
		boolean overflow = false;
		for (int i = 1; i < n; i++) {
			try {
				long next = Math.multiplyExact(sum, getLong(sc));
				sum = next;
			} catch (Exception e) {
				overflow = true;
			}

		}
		if (sum == 0) {
			System.out.println(0);
		} else if (isOver(sum) || overflow) {
			System.out.println(-1);
		} else {
			System.out.println(sum);
		}

	}

	private static boolean isOver(long sum) {
		if (sum > 1000000000000000000L) {
			return true;
		}
		return false;
	}

	/**
	 * *汎用メソッド<br>
	 * 入力した配列に対する順列を取得
	 *
	 * @param numArray
	 * @return
	 */
	private static List<Integer[]> getPermutation(int[] numArray) {
		List<Integer[]> permutation = new ArrayList<>();
		Integer[] ans = new Integer[numArray.length];
		boolean[] used = new boolean[numArray.length];

		return buildPermutaion(permutation, numArray, ans, used, 0);
	}

	/**
	 * *汎用メソッド(内部)<br>
	 * 入力した配列に対する順列を作成
	 *
	 * @param list
	 * @param numArray
	 * @param ans
	 * @param used
	 * @param depth
	 * @return
	 */
	private static List<Integer[]> buildPermutaion(List<Integer[]> list, int[] numArray, Integer[] ans, boolean[] used,
			int depth) {

		// 全部使い切った時=>できた順列を返す
		if (depth == numArray.length) {
			list.add(ans.clone());
			return list;
		}
		// 使い切っていない場合

		for (int i = 0; i < numArray.length; i++) {
			if (used[i]) {
				continue;
			}
			ans[depth] = numArray[i];
			used[i] = true;
			list = buildPermutaion(list, numArray, ans, used, depth + 1);

			used[i] = false;
		}

		return list;
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をlongで返却
	 *
	 * @return
	 */
	public static long getLong(Scanner sc) {

		return Long.parseLong(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をintで返却
	 *
	 * @return
	 */
	public static int getInt(Scanner sc) {

		return Integer.parseInt(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をStringで返却
	 *
	 * @return
	 */
	public static String getString(Scanner sc) {

		return sc.next();
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をint配列で返却
	 *
	 * @return
	 */
	public static int[] getIntArray(Scanner sc) {
		String line = "";
		// 直前にnext()を実行していると改行コードだけ取ってしまうのでその対策
		while (line.equals("")) {
			line = sc.nextLine();
		}

		String[] strArray = line.split(" ");
		int[] intArray = new int[strArray.length];
		for (int i = 0; i < strArray.length; i++) {
			intArray[i] = Integer.parseInt(strArray[i]);
		}
		return intArray;
	}

}

class Status {
	int row = 0;
	int col = 0;
	int candies = 0;

	public Status(int row, int col, int candies) {
		this.row = row;
		this.col = col;
		this.candies = candies;
	}
} import java.util.ArrayList; ArrayList java.util import java.util.List; List java.util import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = getInt(sc);

		long sum = getLong(sc);
		boolean overflow = false;
		for (int i = 1; i < n; i++) {
			try {
				long next = Math.multiplyExact(sum, getLong(sc));
				sum = next;
			} catch (Exception e) {
				overflow = true;
			}

		}
		if (sum == 0) {
			System.out.println(0);
		} else if (isOver(sum) || overflow) {
			System.out.println(-1);
		} else {
			System.out.println(sum);
		}

	}

	private static boolean isOver(long sum) {
		if (sum > 1000000000000000000L) {
			return true;
		}
		return false;
	}

	/**
	 * *汎用メソッド<br>
	 * 入力した配列に対する順列を取得
	 *
	 * @param numArray
	 * @return
	 */
	private static List<Integer[]> getPermutation(int[] numArray) {
		List<Integer[]> permutation = new ArrayList<>();
		Integer[] ans = new Integer[numArray.length];
		boolean[] used = new boolean[numArray.length];

		return buildPermutaion(permutation, numArray, ans, used, 0);
	}

	/**
	 * *汎用メソッド(内部)<br>
	 * 入力した配列に対する順列を作成
	 *
	 * @param list
	 * @param numArray
	 * @param ans
	 * @param used
	 * @param depth
	 * @return
	 */
	private static List<Integer[]> buildPermutaion(List<Integer[]> list, int[] numArray, Integer[] ans, boolean[] used,
			int depth) {

		// 全部使い切った時=>できた順列を返す
		if (depth == numArray.length) {
			list.add(ans.clone());
			return list;
		}
		// 使い切っていない場合

		for (int i = 0; i < numArray.length; i++) {
			if (used[i]) {
				continue;
			}
			ans[depth] = numArray[i];
			used[i] = true;
			list = buildPermutaion(list, numArray, ans, used, depth + 1);

			used[i] = false;
		}

		return list;
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をlongで返却
	 *
	 * @return
	 */
	public static long getLong(Scanner sc) {

		return Long.parseLong(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をintで返却
	 *
	 * @return
	 */
	public static int getInt(Scanner sc) {

		return Integer.parseInt(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をStringで返却
	 *
	 * @return
	 */
	public static String getString(Scanner sc) {

		return sc.next();
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をint配列で返却
	 *
	 * @return
	 */
	public static int[] getIntArray(Scanner sc) {
		String line = "";
		// 直前にnext()を実行していると改行コードだけ取ってしまうのでその対策
		while (line.equals("")) {
			line = sc.nextLine();
		}

		String[] strArray = line.split(" ");
		int[] intArray = new int[strArray.length];
		for (int i = 0; i < strArray.length; i++) {
			intArray[i] = Integer.parseInt(strArray[i]);
		}
		return intArray;
	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = getInt(sc);

		long sum = getLong(sc);
		boolean overflow = false;
		for (int i = 1; i < n; i++) {
			try {
				long next = Math.multiplyExact(sum, getLong(sc));
				sum = next;
			} catch (Exception e) {
				overflow = true;
			}

		}
		if (sum == 0) {
			System.out.println(0);
		} else if (isOver(sum) || overflow) {
			System.out.println(-1);
		} else {
			System.out.println(sum);
		}

	} main {
		Scanner sc = new Scanner(System.in);
		int n = getInt(sc);

		long sum = getLong(sc);
		boolean overflow = false;
		for (int i = 1; i < n; i++) {
			try {
				long next = Math.multiplyExact(sum, getLong(sc));
				sum = next;
			} catch (Exception e) {
				overflow = true;
			}

		}
		if (sum == 0) {
			System.out.println(0);
		} else if (isOver(sum) || overflow) {
			System.out.println(-1);
		} else {
			System.out.println(sum);
		}

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = getInt(sc); n getInt(sc) getInt sc long sum = getLong(sc); sum getLong(sc) getLong sc boolean overflow = false; overflow false for (int i = 1; i < n; i++) {
			try {
				long next = Math.multiplyExact(sum, getLong(sc));
				sum = next;
			} catch (Exception e) {
				overflow = true;
			}

		} int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
			try {
				long next = Math.multiplyExact(sum, getLong(sc));
				sum = next;
			} catch (Exception e) {
				overflow = true;
			}

		} {
			try {
				long next = Math.multiplyExact(sum, getLong(sc));
				sum = next;
			} catch (Exception e) {
				overflow = true;
			}

		} try {
				long next = Math.multiplyExact(sum, getLong(sc));
				sum = next;
			} catch (Exception e) {
				overflow = true;
			} catch (Exception e) {
				overflow = true;
			} Exception e {
				overflow = true;
			} overflow = true overflow true {
				long next = Math.multiplyExact(sum, getLong(sc));
				sum = next;
			} long next = Math.multiplyExact(sum, getLong(sc)); next Math.multiplyExact(sum, getLong(sc)) Math.multiplyExact Math sum getLong(sc) getLong sc sum = next sum next if (sum == 0) {
			System.out.println(0);
		} else if (isOver(sum) || overflow) {
			System.out.println(-1);
		} else {
			System.out.println(sum);
		} sum == 0 sum 0 {
			System.out.println(0);
		} System.out.println(0) System.out.println System.out System System.out 0 if (isOver(sum) || overflow) {
			System.out.println(-1);
		} else {
			System.out.println(sum);
		} isOver(sum) || overflow isOver(sum) isOver sum overflow {
			System.out.println(-1);
		} System.out.println(-1) System.out.println System.out System System.out -1 1 {
			System.out.println(sum);
		} System.out.println(sum) System.out.println System.out System System.out sum String[] args args private static boolean isOver(long sum) {
		if (sum > 1000000000000000000L) {
			return true;
		}
		return false;
	} isOver {
		if (sum > 1000000000000000000L) {
			return true;
		}
		return false;
	} if (sum > 1000000000000000000L) {
			return true;
		} sum > 1000000000000000000L sum 1000000000000000000L {
			return true;
		} return true; true return false; false long sum sum /**
	 * *汎用メソッド<br>
	 * 入力した配列に対する順列を取得
	 *
	 * @param numArray
	 * @return
	 */
	private static List<Integer[]> getPermutation(int[] numArray) {
		List<Integer[]> permutation = new ArrayList<>();
		Integer[] ans = new Integer[numArray.length];
		boolean[] used = new boolean[numArray.length];

		return buildPermutaion(permutation, numArray, ans, used, 0);
	} getPermutation {
		List<Integer[]> permutation = new ArrayList<>();
		Integer[] ans = new Integer[numArray.length];
		boolean[] used = new boolean[numArray.length];

		return buildPermutaion(permutation, numArray, ans, used, 0);
	} List<Integer[]> permutation = new ArrayList<>(); permutation new ArrayList<>() Integer[] ans = new Integer[numArray.length]; ans new Integer[numArray.length] numArray.length numArray numArray.length boolean[] used = new boolean[numArray.length]; used new boolean[numArray.length] numArray.length numArray numArray.length return buildPermutaion(permutation, numArray, ans, used, 0); buildPermutaion(permutation, numArray, ans, used, 0) buildPermutaion permutation numArray ans used 0 int[] numArray numArray /**
	 * *汎用メソッド(内部)<br>
	 * 入力した配列に対する順列を作成
	 *
	 * @param list
	 * @param numArray
	 * @param ans
	 * @param used
	 * @param depth
	 * @return
	 */
	private static List<Integer[]> buildPermutaion(List<Integer[]> list, int[] numArray, Integer[] ans, boolean[] used,
			int depth) {

		// 全部使い切った時=>できた順列を返す
		if (depth == numArray.length) {
			list.add(ans.clone());
			return list;
		}
		// 使い切っていない場合

		for (int i = 0; i < numArray.length; i++) {
			if (used[i]) {
				continue;
			}
			ans[depth] = numArray[i];
			used[i] = true;
			list = buildPermutaion(list, numArray, ans, used, depth + 1);

			used[i] = false;
		}

		return list;
	} buildPermutaion {

		// 全部使い切った時=>できた順列を返す
		if (depth == numArray.length) {
			list.add(ans.clone());
			return list;
		}
		// 使い切っていない場合

		for (int i = 0; i < numArray.length; i++) {
			if (used[i]) {
				continue;
			}
			ans[depth] = numArray[i];
			used[i] = true;
			list = buildPermutaion(list, numArray, ans, used, depth + 1);

			used[i] = false;
		}

		return list;
	} if (depth == numArray.length) {
			list.add(ans.clone());
			return list;
		} depth == numArray.length depth numArray.length numArray numArray.length {
			list.add(ans.clone());
			return list;
		} list.add(ans.clone()) list.add list ans.clone() ans.clone ans return list; list for (int i = 0; i < numArray.length; i++) {
			if (used[i]) {
				continue;
			}
			ans[depth] = numArray[i];
			used[i] = true;
			list = buildPermutaion(list, numArray, ans, used, depth + 1);

			used[i] = false;
		} int i = 0; int i = 0; i 0 i < numArray.length i numArray.length numArray numArray.length i++ i++ i {
			if (used[i]) {
				continue;
			}
			ans[depth] = numArray[i];
			used[i] = true;
			list = buildPermutaion(list, numArray, ans, used, depth + 1);

			used[i] = false;
		} {
			if (used[i]) {
				continue;
			}
			ans[depth] = numArray[i];
			used[i] = true;
			list = buildPermutaion(list, numArray, ans, used, depth + 1);

			used[i] = false;
		} if (used[i]) {
				continue;
			} used[i] used i {
				continue;
			} continue; ans[depth] = numArray[i] ans[depth] ans depth numArray[i] numArray i used[i] = true used[i] used i true list = buildPermutaion(list, numArray, ans, used, depth + 1) list buildPermutaion(list, numArray, ans, used, depth + 1) buildPermutaion list numArray ans used depth + 1 depth 1 used[i] = false used[i] used i false return list; list List<Integer[]> list list int[] numArray numArray Integer[] ans ans boolean[] used used int depth depth /**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をlongで返却
	 *
	 * @return
	 */
	public static long getLong(Scanner sc) {

		return Long.parseLong(sc.next());
	} getLong {

		return Long.parseLong(sc.next());
	} return Long.parseLong(sc.next()); Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc Scanner sc sc /**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をintで返却
	 *
	 * @return
	 */
	public static int getInt(Scanner sc) {

		return Integer.parseInt(sc.next());
	} getInt {

		return Integer.parseInt(sc.next());
	} return Integer.parseInt(sc.next()); Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc Scanner sc sc /**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をStringで返却
	 *
	 * @return
	 */
	public static String getString(Scanner sc) {

		return sc.next();
	} getString {

		return sc.next();
	} return sc.next(); sc.next() sc.next sc Scanner sc sc /**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をint配列で返却
	 *
	 * @return
	 */
	public static int[] getIntArray(Scanner sc) {
		String line = "";
		// 直前にnext()を実行していると改行コードだけ取ってしまうのでその対策
		while (line.equals("")) {
			line = sc.nextLine();
		}

		String[] strArray = line.split(" ");
		int[] intArray = new int[strArray.length];
		for (int i = 0; i < strArray.length; i++) {
			intArray[i] = Integer.parseInt(strArray[i]);
		}
		return intArray;
	} getIntArray {
		String line = "";
		// 直前にnext()を実行していると改行コードだけ取ってしまうのでその対策
		while (line.equals("")) {
			line = sc.nextLine();
		}

		String[] strArray = line.split(" ");
		int[] intArray = new int[strArray.length];
		for (int i = 0; i < strArray.length; i++) {
			intArray[i] = Integer.parseInt(strArray[i]);
		}
		return intArray;
	} String line = ""; line "" while (line.equals("")) {
			line = sc.nextLine();
		} line.equals("") line.equals line "" {
			line = sc.nextLine();
		} line = sc.nextLine() line sc.nextLine() sc.nextLine sc String[] strArray = line.split(" "); strArray line.split(" ") line.split line " " int[] intArray = new int[strArray.length]; intArray new int[strArray.length] strArray.length strArray strArray.length for (int i = 0; i < strArray.length; i++) {
			intArray[i] = Integer.parseInt(strArray[i]);
		} int i = 0; int i = 0; i 0 i < strArray.length i strArray.length strArray strArray.length i++ i++ i {
			intArray[i] = Integer.parseInt(strArray[i]);
		} {
			intArray[i] = Integer.parseInt(strArray[i]);
		} intArray[i] = Integer.parseInt(strArray[i]) intArray[i] intArray i Integer.parseInt(strArray[i]) Integer.parseInt Integer strArray[i] strArray i return intArray; intArray Scanner sc sc class Status {
	int row = 0;
	int col = 0;
	int candies = 0;

	public Status(int row, int col, int candies) {
		this.row = row;
		this.col = col;
		this.candies = candies;
	}
} Status int row = 0; row 0 int col = 0; col 0 int candies = 0; candies 0 public Status(int row, int col, int candies) {
		this.row = row;
		this.col = col;
		this.candies = candies;
	} Status {
		this.row = row;
		this.col = col;
		this.candies = candies;
	} this.row = row this.row this this.row row this.col = col this.col this this.col col this.candies = candies this.candies this this.candies candies int row row int col col int candies candies public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = getInt(sc);

		long sum = getLong(sc);
		boolean overflow = false;
		for (int i = 1; i < n; i++) {
			try {
				long next = Math.multiplyExact(sum, getLong(sc));
				sum = next;
			} catch (Exception e) {
				overflow = true;
			}

		}
		if (sum == 0) {
			System.out.println(0);
		} else if (isOver(sum) || overflow) {
			System.out.println(-1);
		} else {
			System.out.println(sum);
		}

	}

	private static boolean isOver(long sum) {
		if (sum > 1000000000000000000L) {
			return true;
		}
		return false;
	}

	/**
	 * *汎用メソッド<br>
	 * 入力した配列に対する順列を取得
	 *
	 * @param numArray
	 * @return
	 */
	private static List<Integer[]> getPermutation(int[] numArray) {
		List<Integer[]> permutation = new ArrayList<>();
		Integer[] ans = new Integer[numArray.length];
		boolean[] used = new boolean[numArray.length];

		return buildPermutaion(permutation, numArray, ans, used, 0);
	}

	/**
	 * *汎用メソッド(内部)<br>
	 * 入力した配列に対する順列を作成
	 *
	 * @param list
	 * @param numArray
	 * @param ans
	 * @param used
	 * @param depth
	 * @return
	 */
	private static List<Integer[]> buildPermutaion(List<Integer[]> list, int[] numArray, Integer[] ans, boolean[] used,
			int depth) {

		// 全部使い切った時=>できた順列を返す
		if (depth == numArray.length) {
			list.add(ans.clone());
			return list;
		}
		// 使い切っていない場合

		for (int i = 0; i < numArray.length; i++) {
			if (used[i]) {
				continue;
			}
			ans[depth] = numArray[i];
			used[i] = true;
			list = buildPermutaion(list, numArray, ans, used, depth + 1);

			used[i] = false;
		}

		return list;
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をlongで返却
	 *
	 * @return
	 */
	public static long getLong(Scanner sc) {

		return Long.parseLong(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をintで返却
	 *
	 * @return
	 */
	public static int getInt(Scanner sc) {

		return Integer.parseInt(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をStringで返却
	 *
	 * @return
	 */
	public static String getString(Scanner sc) {

		return sc.next();
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をint配列で返却
	 *
	 * @return
	 */
	public static int[] getIntArray(Scanner sc) {
		String line = "";
		// 直前にnext()を実行していると改行コードだけ取ってしまうのでその対策
		while (line.equals("")) {
			line = sc.nextLine();
		}

		String[] strArray = line.split(" ");
		int[] intArray = new int[strArray.length];
		for (int i = 0; i < strArray.length; i++) {
			intArray[i] = Integer.parseInt(strArray[i]);
		}
		return intArray;
	}

} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = getInt(sc);

		long sum = getLong(sc);
		boolean overflow = false;
		for (int i = 1; i < n; i++) {
			try {
				long next = Math.multiplyExact(sum, getLong(sc));
				sum = next;
			} catch (Exception e) {
				overflow = true;
			}

		}
		if (sum == 0) {
			System.out.println(0);
		} else if (isOver(sum) || overflow) {
			System.out.println(-1);
		} else {
			System.out.println(sum);
		}

	}

	private static boolean isOver(long sum) {
		if (sum > 1000000000000000000L) {
			return true;
		}
		return false;
	}

	/**
	 * *汎用メソッド<br>
	 * 入力した配列に対する順列を取得
	 *
	 * @param numArray
	 * @return
	 */
	private static List<Integer[]> getPermutation(int[] numArray) {
		List<Integer[]> permutation = new ArrayList<>();
		Integer[] ans = new Integer[numArray.length];
		boolean[] used = new boolean[numArray.length];

		return buildPermutaion(permutation, numArray, ans, used, 0);
	}

	/**
	 * *汎用メソッド(内部)<br>
	 * 入力した配列に対する順列を作成
	 *
	 * @param list
	 * @param numArray
	 * @param ans
	 * @param used
	 * @param depth
	 * @return
	 */
	private static List<Integer[]> buildPermutaion(List<Integer[]> list, int[] numArray, Integer[] ans, boolean[] used,
			int depth) {

		// 全部使い切った時=>できた順列を返す
		if (depth == numArray.length) {
			list.add(ans.clone());
			return list;
		}
		// 使い切っていない場合

		for (int i = 0; i < numArray.length; i++) {
			if (used[i]) {
				continue;
			}
			ans[depth] = numArray[i];
			used[i] = true;
			list = buildPermutaion(list, numArray, ans, used, depth + 1);

			used[i] = false;
		}

		return list;
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をlongで返却
	 *
	 * @return
	 */
	public static long getLong(Scanner sc) {

		return Long.parseLong(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をintで返却
	 *
	 * @return
	 */
	public static int getInt(Scanner sc) {

		return Integer.parseInt(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をStringで返却
	 *
	 * @return
	 */
	public static String getString(Scanner sc) {

		return sc.next();
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をint配列で返却
	 *
	 * @return
	 */
	public static int[] getIntArray(Scanner sc) {
		String line = "";
		// 直前にnext()を実行していると改行コードだけ取ってしまうのでその対策
		while (line.equals("")) {
			line = sc.nextLine();
		}

		String[] strArray = line.split(" ");
		int[] intArray = new int[strArray.length];
		for (int i = 0; i < strArray.length; i++) {
			intArray[i] = Integer.parseInt(strArray[i]);
		}
		return intArray;
	}

} Main
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = getInt(sc);

		long sum = getLong(sc);
		boolean overflow = false;
		for (int i = 1; i < n; i++) {
			try {
				long next = Math.multiplyExact(sum, getLong(sc));
				sum = next;
			} catch (Exception e) {
				overflow = true;
			}

		}
		if (sum == 0) {
			System.out.println(0);
		} else if (isOver(sum) || overflow) {
			System.out.println(-1);
		} else {
			System.out.println(sum);
		}

	}

	private static boolean isOver(long sum) {
		if (sum > 1000000000000000000L) {
			return true;
		}
		return false;
	}

	/**
	 * *汎用メソッド<br>
	 * 入力した配列に対する順列を取得
	 *
	 * @param numArray
	 * @return
	 */
	private static List<Integer[]> getPermutation(int[] numArray) {
		List<Integer[]> permutation = new ArrayList<>();
		Integer[] ans = new Integer[numArray.length];
		boolean[] used = new boolean[numArray.length];

		return buildPermutaion(permutation, numArray, ans, used, 0);
	}

	/**
	 * *汎用メソッド(内部)<br>
	 * 入力した配列に対する順列を作成
	 *
	 * @param list
	 * @param numArray
	 * @param ans
	 * @param used
	 * @param depth
	 * @return
	 */
	private static List<Integer[]> buildPermutaion(List<Integer[]> list, int[] numArray, Integer[] ans, boolean[] used,
			int depth) {

		// 全部使い切った時=>できた順列を返す
		if (depth == numArray.length) {
			list.add(ans.clone());
			return list;
		}
		// 使い切っていない場合

		for (int i = 0; i < numArray.length; i++) {
			if (used[i]) {
				continue;
			}
			ans[depth] = numArray[i];
			used[i] = true;
			list = buildPermutaion(list, numArray, ans, used, depth + 1);

			used[i] = false;
		}

		return list;
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をlongで返却
	 *
	 * @return
	 */
	public static long getLong(Scanner sc) {

		return Long.parseLong(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をintで返却
	 *
	 * @return
	 */
	public static int getInt(Scanner sc) {

		return Integer.parseInt(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をStringで返却
	 *
	 * @return
	 */
	public static String getString(Scanner sc) {

		return sc.next();
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をint配列で返却
	 *
	 * @return
	 */
	public static int[] getIntArray(Scanner sc) {
		String line = "";
		// 直前にnext()を実行していると改行コードだけ取ってしまうのでその対策
		while (line.equals("")) {
			line = sc.nextLine();
		}

		String[] strArray = line.split(" ");
		int[] intArray = new int[strArray.length];
		for (int i = 0; i < strArray.length; i++) {
			intArray[i] = Integer.parseInt(strArray[i]);
		}
		return intArray;
	}

}

class Status {
	int row = 0;
	int col = 0;
	int candies = 0;

	public Status(int row, int col, int candies) {
		this.row = row;
		this.col = col;
		this.candies = candies;
	}
}
