import java.io.*;
import java.math.*;
import java.util.*;
import java.util.regex.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static long cnt=0;
	public static PrintWriter pw = new PrintWriter(System.out);
	public static void main(String[] args) throws Exception {
		solveD(args);
		if(in!=null){
			in.close();
		}
		pw.flush();
		pw.close();
	}

	public static void solveA(String[] args) throws Exception{
		int[] x = nextInts();
		boolean[] flg = new boolean[6];
		Arrays.fill(flg,true);
		for(int i=0;i<5;i++) {
			flg[x[i]]=false;
		}
		for(int i=1;i<6;i++) {
			if(flg[i]) {
				pw.println(i);
				return;
			}
		}
	}
	public static void solveB(String[] args) throws Exception{
		int X = nextInt();
		int Y = nextInt();

		for(int turu=0;turu<100;turu++) {
			for(int kame=0;kame<100;kame++) {
				if(turu+kame==X&&turu*2+kame*4==Y) {
					pw.println("Yes");
					return;
				}
			}
		}
		pw.println("No");
	}
	public static void solveC(String[] args) throws Exception{
		int X = nextInt();
		int N = nextInt();

		int[] p ;
		if(N!=0) {
			p=nextInts();
		}else {
			nextString();
			p=new int[0];
		}
		boolean[] g = new boolean[102];
		Arrays.fill(g,true);
		for(int i=0;i<N;i++) {
			g[p[i]]=false;
		}
		int ans = -1;
		for(int i=0;i<=101;i++) {
			if(g[i]&&Math.abs(X-i) < Math.abs(X-ans)) {
				ans=i;
			}
		}
		pw.println(ans);

	}
	public static void solveD(String[] args) throws Exception{
		int N = nextInt();

		HashMap<Integer,Integer> map = new HashMap<Integer, Integer>();
		for(int i=0;i<N;i++) {
			int x = nextInt();
			map.put(x,map.getOrDefault(x, 0)+1);
		}
		int num=0;
		ArrayList<Integer> list = new ArrayList<Integer>(map.size());
		for(int x:map.keySet()) {
			if(map.get(x)==1) {
				list.add(x);
			}
		}

		if(list.size()==0) {
			pw.println(0);
			return;
		}
		boolean[] x = new boolean[(int)1e6+1];
		Arrays.fill(x,false);
		int n=0;
		for(int i=0;i<N;i++) {
			x[list.get(i)]=true;
			n=Math.max(n,list.get(i));
		}

		for (int i = 0; i < N; i++) {
			if (!x[list.get(i)]) {
				continue;
			}
			for (int k = list.get(i) *2; k <= n; k += list.get(i)) {
				x[k] = false;
			}
		}
		int ans = 0;
		for(int i=1;i<=n;i++) {
			if(x[i]) {
				ans++;
			}
		}

		pw.println(ans);
	}
	public static void solveE(String[] args) throws Exception{

	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}

}


import java.util.*;

class Main {
    final Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Main().run();
    }

    private int n;
    private int[] a;

    private void run() {
        n = sc.nextInt();
        a = new int[n+1];
        a[n] = 200001;

        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        boolean[] check = new boolean[200001];
        Arrays.sort(a);
        Arrays.fill(check, true);

        int ans = 0;
        for (int i = 0; i < n; i++) {
            if (a[i + 1] != a[i] && check[a[i]]) {
                ans++;
            }

            for (int j = a[i]; j <= a[n - 1]; j += a[i]) {
                check[j] = false;
            }
        }

        System.out.println(ans);
    }
}

Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.

Score : 400 points

Problem Statement

Given is a number sequence A of length N.

Find the number of integers i \left(1 \leq i \leq N\right) with the following property:

For every integer j \left(1 \leq j \leq N\right) such that i \neq j , A_j does not divide A_i.

Constraints

All values in input are integers.

1 \leq N \leq 2 \times 10^5

1 \leq A_i \leq 10^6

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \cdots A_N

Output

Print the answer.

Sample Input 1

5
24 11 8 3 16

Sample Output 1

3

The integers with the property are 2, 3, and 4.

Sample Input 2

4
5 5 5 5

Sample Output 2

0

Note that there can be multiple equal numbers.

Sample Input 3

10
33 18 45 28 8 19 89 86 2 4

Sample Output 3

5

Submitted source-code file size, in bytes.

Execution CPU time reported by official Project CodeNet metadata, in milliseconds.

Peak memory usage reported by official Project CodeNet metadata, in kilobytes.


import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in);) {
			Prime prime = new Prime(1000000);
			int n = sc.nextInt();

			ArrayList<Integer> list = new ArrayList<>();
			int[] numCount = new int[1000001];
			for (int i = 0; i < n; i++) {
				int value = sc.nextInt();
				numCount[value]++;
				if (value == 1) {
					System.out.println(0);
					return;
				}
				list.add(value);
			}

			Collections.sort(list);
			Collections.reverse(list);

			int count = 0;
			for (int i = 0; i < n; i++) {

				if (numCount[list.get(i)] >1) {
					continue;
				}

				if(prime.isPrime(list.get(i))) {
					count++;
					continue;
				}

				boolean flag = true;
				for (int j = i + 1; j < n; j++) {

					if (list.get(i) % list.get(j) == 0) {
						flag = false;
						break;
					}
				}

				if (flag)
					count++;

			}

			System.out.println(count);

		} catch (Exception e) {
			e.printStackTrace();

		}
	}
}

class Prime {
	public ArrayList<Long> primes = new ArrayList<>();
	public long max;

	public Prime(long max) {
		this.max = max;
		primes.add(2l);
		for (long i = 3; i <= max; i += 2) {
			if (isPrime(i))
				primes.add(i);
		}
	}

	public boolean isPrime(long value) {
		if (value <= 1l) {
			return false;
		} else if (value == 2l) {
			return true;
		}

		boolean flag = true;
		for (long i = 3l; i * i <= value; i += 2l) {
			if (value % i == 0) {
				flag = false;
				break;
			}
		}

		return flag;
	}

	public HashMap<Long,Integer> primeFact(long value){
		HashMap<Long,Integer> returns = new HashMap<>();
		int i = 0;
		int count = 0;
		if(primes.contains(value)) {
			returns.put(value, 1);
			return returns;
		}

		while(true) {
			if(value % primes.get(i) == 0) {
				count++;
				value /= primes.get(i);
			}else {
				if(count !=0) {
					returns.put(primes.get(i), count);
				}

				i++;
				count = 0;
			}

			if(value == 1) {
				returns.put(primes.get(i), count);
				break;
			}
		}

		return returns;
	}
}


import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.List;
import java.util.NoSuchElementException;

public class Main {

    static int count = 0;

    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        int n = scanner.nextInt();
        Integer[] sequence = new Integer[n];
        for (int i = 0; i < n; i++) {
            sequence[i] = scanner.nextInt();
        }
        List<Integer> list = Arrays.asList(sequence);
        for (int i = 0; i < n; i++) {
            boolean isDivisible = true;
            if (isPrimeNumber(sequence[i]) && !list.contains(sequence[i])) {
                count++;
                continue;
            } else {
                for (int j = 0; j < n; j++) {
                    if (i != j) {
                        if (sequence[i] % sequence[j] != 0) {
                            isDivisible = false;
                        } else {
                            isDivisible = true;
                            break;
                        }
                    }
                }
                if (!isDivisible) {
                    count++;
                }
            }
        }
        System.out.println(count);
    }

    private static boolean isPrimeNumber(int number) {
        if (number < 2) return false;
        else if (number == 2) return true;
        else if (number % 2 == 0) return false;

        double sqrtNum = Math.sqrt(number);
        for (int i = 3; i <= sqrtNum; i += 2) {
            if (number % i == 0) {
                return false;
            }
        }
        return true;
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


import java.util.Arrays;
import java.util.Scanner;

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

        if(n == 1){
            System.out.println(0);
            return;
        }

        int a[] = new int[n];
        for(int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        Arrays.sort(a);
        int count = n;
        if(a[0] == a[1]){count--;}
        for(int i = n-1; i >= 0; i--){
            int half = a[i] / 2;
            for(int j = 0; j <= i-1; j++){
                if(a[i] == a[j]){
                    count--;
                    break;
                }
                if(a[j] > half){
                    break;
                }
                if(a[i] % a[j] == 0){
                    count--;
                    break;
                }
            }
        }
        System.out.println(count);
    }
}


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

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        List<Long> p = new ArrayList<>();
        // Set<Long> p = new HashSet<Long>();
        for (long i = 0; i < N; i++) {
            long pi = sc.nextLong();
            if (!p.contains(pi)) {
                p.add(pi);
            }
        }
        sc.close();
        if (p.size() == 1) {
            System.out.println(0);
            return;
        }

        Collections.sort(p);

        int count = 0;
        for (int i = 0; i < N; i++) {
            boolean flg = true;

            for (int j = 0; j < N; j++) {
                if (i == j) {
                    continue;
                }
                if (p.get(i) % p.get(j) == 0) {
                    flg = false;
                    break;
                }
            }

            if (flg) {
                count++;
            }
        }
        System.out.println(count);
    }
}


import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		List<Integer> list = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			list.add(sc.nextInt());
		}
		Collections.sort(list);
		boolean[] array = new boolean[list.get(list.size() - 1) * 2 + 100];
		for (int i = 0; i < n; i++) {
			int num = list.get(i);
			for (int j = num * 2; j < list.get(list.size() - 1) * 2 + 100; j += num) {
				array[j] = true;
			}
		}
		int count = 0;
		Set<Integer> delList = new HashSet<>();
		for (int i = 0; i < n - 1; i++) {
			if (list.get(i) == list.get(i + 1)) {
				delList.add(list.get(i));
			}
		}
		list.removeAll(delList);
		for (int num : list) {
			if (!array[num]) {
				++count;
			}
		}
		System.out.println(count);
	}
}


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.util.Map.Entry;
import java.util.TreeMap;

public class Main {
	//author: Nagabhushan S Baddi

	private static class Trie {
		private class Node {
			HashMap<Integer, Node> child;
			int end;

			public Node() {
				child = new HashMap<>();
				end = 0;
			}
		}

		private Node root;

		public Trie() {
			root = new Node();
		}

		public void add(TreeMap<Integer, Integer> map) {
			Node node = root;
			for(Entry<Integer, Integer> e: map.entrySet()) {
				for(int j=0; j<e.getValue(); j++) {
//					System.out.println("HE");
					if (node.child.containsKey(e.getKey())) {
						node = node.child.get(e.getKey());
					} else {
						node.child.put(e.getKey(), new Node());
						node = node.child.get(e.getKey());
					}
				}
			}
//			System.out.println(node==root);
			node.end++;
		}

		private int solve() {
			return solve(root, -1);
		}

		private int solve(Node node, int xx) {
			if (node==null) return 0;
			if (node.end==1) {
//				println(xx);
				return 1;
			} else if (node.end!=0) return 0;

//			System.out.println("L");

			int count = 0;

			for(Entry<Integer, Node> e: node.child.entrySet()) {
				count += solve(e.getValue(), e.getKey());
			}

			return count;
		}
	}

	private static int n;
	private static int[] a;
	private static int d;
	private static String s;
	private static HashMap<Integer, ArrayList<Integer>> g;

	public static void main(String[] args) {
		n = ini();
		a = ina(n);

		int MX = (int)1e6+10;
		boolean[] map = new boolean[MX];

		int[] count = new int[MX];

		for(int x: a) {
			map[x] = true;
			count[x]++;
		}

		for(int x: a) {
			for(int j=2*x; j<MX; j+=x) {
				map[j] = false;
			}
		}

		int ans = 0;

		for(int x: a) {
			if (count[x]==1 && map[x]) {
				ans++;
			}
		}
		println(ans);

//		HashMap<Integer, HashSet<int[]>> g = new HashMap<>(); //alpha,p
//
//		for(int x: a) {
//			g.put(x, new HashSet<>());
//		}
//		int MX = (int)1e6+5;
//		boolean[] isPrime = new boolean[MX];
//
//		Arrays.fill(isPrime, true);
//
//		isPrime[0] = isPrime[1] = false;
//
//		for(int i=2; i<MX; i++) {
//			if (isPrime[i] && 2*1L*i<MX) {
//				if (g.containsKey(i)) {
//					g.get(i).add(new int[] {i, 1});
//				}
//				for(int j=2*i; j<MX; j+=i) {
//					isPrime[j] = false;
//					if (g.containsKey(j)) {
//						int low = 1;
//						int high = 22;
//						int mid = 0;
//						int z = j;
//						while(z%i==0) {
//							z/=i;
//							mid++;
//						}
////						while(low<=high) {
////							mid = low+(high-low)/2;
////
////							if (Math.abs(Math.pow(i, mid)-j)<1e-7) {
////								break;
////							} else if (Math.pow(i, mid)>j) {
////								high=mid-1;
////							} else {
////								low=mid+1;
////							}
////						}
////						g.get(j).add(new int[] {i, mid});
//					}
//				}
//			}
//		}
//
//		Trie tree = new Trie();
//
//		for(int i=0; i<n; i++) {
//			TreeMap<Integer, Integer> mp = new TreeMap<>();
//			for(int[] u: g.get(a[i])) {
//				mp.put(u[0], u[1]);
//			}
//			tree.add(mp);
//		}
//
//		println(tree.solve());

//		int[] count = new int[MX];
//
//		for(int x: a) {
//			for(int v: g.get(x)) {
//				count[v]++;
//			}
//		}

//		int ans = 0;
//		out:
//		for(int i=0; i<n; i++) {
//			for(int v: g.get(a[i])) {
//				if (count[v]>1) {
//					continue out;
//				}
//			}
//			System.out.println(a[i]);
//			ans++;
//		}
//
//		println(ans);

		out.flush();
		out.close();

	}

	//CONSTANTS
	private static final int MOD = (int) 1e9 + 7;

	//NONPROBLEM CODE

	private static InputReader in = new InputReader(System.in);
	private static PrintWriter out = new PrintWriter(System.out);

	private static class InputReader {

		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;

		public InputReader(InputStream st) {
			this.stream = st;
		}

		public int read() {
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars) {
				curChar = 0;
				try {
					snumChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int nextInt() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public String readString() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

	}

	//SORT SHORTCUTS

	private static void sort(int[] a) {
		int n = a.length;
		Integer[] b = new Integer[n];
		for (int i = 0; i < n; i++) {
			b[i] = a[i];
		}

		Arrays.sort(b);

		for (int i = 0; i < n; i++) {
			a[i] = b[i];
		}
	}

	private static void sort(long[] a) {
		int n = a.length;
		Long[] b = new Long[n];
		for (int i = 0; i < n; i++) {
			b[i] = a[i];
		}

		Arrays.sort(b);

		for (int i = 0; i < n; i++) {
			a[i] = b[i];
		}
	}

	//INPUT SHORTCUTS

	private static int[] ina(int n) {
		int[] temp = new int[n];
		for (int i = 0; i < n; i++) {
			temp[i] = in.nextInt();
		}
		return temp;
	}

	private static int ini() {
		return in.nextInt();
	}

	private static long inl() {
		return in.nextLong();
	}

	private static String ins() {
		return in.readString();
	}

	//PRINT SHORTCUTS

	private static void println(Object... o) {
		for (Object x : o) {
			out.write(x + "");
		}
		out.write("\n");
	}

	private static void pd(Object... o) {
		for (Object x : o) {
			out.write(x + "");
		}
		out.flush();
		out.write("\n");
	}

	private static void print(Object... o) {
		for (Object x : o) {
			out.write(x + "");
		}
	}

	//GRAPH SHORTCUTS

	private static HashMap<Integer, ArrayList<Integer>> intree(int n) {

		HashMap<Integer, ArrayList<Integer>> g = new HashMap<>();
		for (int i = 0; i < n; i++) {
			g.put(i, new ArrayList<>());
		}

		for (int i = 0; i < n - 1; i++) {
			int u = ini() - 1;
			int v = ini() - 1;
			g.get(u).add(v);
			g.get(v).add(u);
		}

		return g;
	}

	private static HashMap<Integer, ArrayList<Integer>> ingraph(int n, int m) {
		HashMap<Integer, ArrayList<Integer>> g = new HashMap<>();

		for (int i = 0; i < n; i++) {
			g.put(i, new ArrayList<>());
		}

		for (int i = 0; i < m; i++) {
			int u = ini() - 1;
			int v = ini() - 1;
			g.get(u).add(v);
			g.get(v).add(u);
		}

		return g;

	}

	private static HashMap<Integer, ArrayList<Edge>> inweightedgraph(int n, int m) {
		HashMap<Integer, ArrayList<Edge>> g = new HashMap<>();

		for (int i = 0; i < n; i++) {
			g.put(i, new ArrayList<>());
		}

		for (int i = 0; i < m; i++) {
			int u = ini() - 1;
			int v = ini() - 1;
			int w = ini();
			Edge edge = new Edge(u, v, w);
			g.get(u).add(edge);
			g.get(v).add(edge);
		}

		return g;

	}

	private static class Edge implements Comparable<Edge> {
		private int u, v;
		private long w;

		public Edge(int a, int b, long c) {
			u = a;
			v = b;
			w = c;
		}

		public int other(int x) {
			return (x == u ? v : u);
		}

		public int compareTo(Edge edge) {
			return Long.compare(w, edge.w);
		}
	}

	private static class Pair {
		private int u, v;

		public Pair(int a, int b) {
			u = a;
			v = b;
		}

		public int hashCode() {
			return u + v + u * v;
		}

		public boolean equals(Object object) {
			Pair pair = (Pair) object;
			return u == pair.u && v == pair.v;
		}
	}

	private static class Node implements Comparable<Node> {
		private int u;
		private long dist;

		public Node(int a, long b) {
			u = a;
			dist = b;
		}

		public int compareTo(Node node) {
			return Long.compare(dist, node.dist);
		}
	}

	//MATHS AND NUMBER THEORY SHORTCUTS

	private static int gcd(int a, int b) {
		//O(log(min(a,b)))
		if (b == 0)
			return a;

		return gcd(b, a % b);
	}

	private static long modExp(long a, long b) {
		if (b == 0)
			return 1;

		a %= MOD;

		long exp = modExp(a, b / 2);

		if (b % 2 == 0) {
			return (exp * exp) % MOD;
		} else {
			return (a * ((exp * exp) % MOD)) % MOD;
		}
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Solution sol = new Solution();
		sol.solve(in, out);
		out.close();
	}

	private static class Solution {
		final int[] a = new int[2_00_000_0];
		private void solve(InputReader in, PrintWriter out) {
			int n = in.ni();
			for (int i = 0; i < n; i++) {
				a[i] = in.ni();
			}
			int total = 0;
			for (int i = 0; i < n; ++i) {
				int k=0;
				for (int j = i+1; j < n; ++j) {
					if (a[i]%a[j] != 0) ++k;
					if (k == i+1) ++total;
				}
			}
          if (total == 0) {
				out.println(0);
				return;
			}
			out.println(total-1);
		}
	}

	private static class InputReader {
		private BufferedReader reader;
		private StringTokenizer tokenizer;

		private InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		private String n() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		private int ni() {
			return Integer.parseInt(n());
		}
	}

}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.util.Random;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.BitSet;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author AnandOza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DNotDivisible solver = new DNotDivisible();
        solver.solve(1, in, out);
        out.close();
    }

    static class DNotDivisible {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = in.readIntArray(n);
            Util.safeSort(a);
            BitSet composite = new BitSet(n);
            int MAX = Util.max(a);

            int answer = 0;
            for (int i = 0; i < n; i++) {
                int p = a[i];
                if (composite.get(p)) {
                    continue;
                }

                if (!(i + 1 < n && a[i + 1] == a[i]))
                    answer++;

                if (p == 1) {
                    break;
                }

                for (int j = p; j <= MAX; j += p) {
                    composite.set(j);
                }
            }

            out.println(answer);
        }

    }

    static class Util {
        public static int max(int... x) {
            int max = Integer.MIN_VALUE;
            for (int i : x) {
                max = Math.max(i, max);
            }
            return max;
        }

        public static void safeSort(int[] x) {
            shuffle(x);
            Arrays.sort(x);
        }

        public static void shuffle(int[] x) {
            Random r = new Random();

            for (int i = 0; i <= x.length - 2; i++) {
                int j = i + r.nextInt(x.length - i);
                swap(x, i, j);
            }
        }

        public static void swap(int[] x, int i, int j) {
            int t = x[i];
            x[i] = x[j];
            x[j] = t;
        }

        private Util() {
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public int[] readIntArray(int n) {
            int[] x = new int[n];
            for (int i = 0; i < n; i++) {
                x[i] = nextInt();
            }
            return x;
        }

    }
}


import java.util.*;

public class Main {
    private static final int MOD = 1_000_000_007;
    private static final String YES = "Yes";
    private static final String NO = "No";

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

        int N = sc.nextInt();
        int[] A = new int[N];
        for (int i=0; i<N; i++) {
            A[i] = sc.nextInt();
        }

        System.out.println(solve(N, A));
    }

    private static int solve(int N, int[] A) {
        Arrays.sort(A);
        List<Integer> ans = new ArrayList();
        if (A[0] == A[N-1]) return 0;

        check: for (int i=0; i<N; i++) {
            for (int j=0; j<ans.size(); j++) {
                if (A[i]%ans.get(j) == 0) {
                    continue check;
                }
            }

            ans.add(A[i]);
        }

        return ans.size();
    }
}


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Comparator;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {

  private static PrintWriter out;

  public static void main(String[] args) {
    Main main = new Main();
    Runtime.getRuntime().addShutdownHook(new Thread(() -> out.close()));
    try {
      main.run(args);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  private void run(String[] arguments) throws Exception {
    MyScanner sc = new MyScanner();
    out = new PrintWriter(new BufferedOutputStream(System.out));

    int n = sc.nextInt();
    TreeSet<Integer> treeNumbers = new TreeSet<>(Comparator.reverseOrder());

    for (int i = 0; i < n; i++) {
      treeNumbers.add(sc.nextInt());
    }

    int ans = 0;
    while (!treeNumbers.isEmpty()) {

      if (treeNumbers.size() == 1) {
        break;
      }

      boolean isOK = true;
      int first = treeNumbers.first();

      for (Integer num : treeNumbers) {
        int rest = first % num;
        if (rest == 0) {
          isOK = false;
          treeNumbers.remove(first);
          break;
        }
      }
      if (!isOK) {
        ans++;
      }
    }
    out.println(ans);
    out.close();
  }

  /*
   * Form: http://codeforces.com/blog/entry/7018
   */
  private class MyScanner {

    BufferedReader br;
    StringTokenizer st;

    MyScanner() {
      br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
      while (st == null || !st.hasMoreElements()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

    int nextInt() {
      return Integer.parseInt(next());
    }

    long nextLong() {
      return Long.parseLong(next());
    }

    double nextDouble() {
      return Double.parseDouble(next());
    }

    String nextLine() {
      String str = "";
      try {
        str = br.readLine();
      } catch (IOException e) {
        e.printStackTrace();
      }
      return str;
    }
  }
}


import java.util.Scanner;
public class Main {
public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt(),p=0,ans=0;
	int [] a = new int [n];
	for (int  i=0;i<n;i++) {
		a[i]=sc.nextInt();
		if (a[i]==1) p++;
	}
	if (p>0) System.out.println(p);
	else {
		for (int i=0;i<n;i++) {
			boolean d = true;
			for (int j=0;j<n;j++) {
				if (i==j) continue;
				if (a[i]%a[j]==0) {
					d=false;
					break;
				}
			}
			if (d) ans++;
		}
		System.out.println(ans);
	}
	sc.close();}}


import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            int[] A = new int[N];
            for (int i = 0; i < N; i++) {
                A[i] = sc.nextInt();
            }

            Arrays.sort(A);

            int count = 0;
            boolean[] used = new boolean[(int) (1e6 + 1)];
            for (int i = 0; i < N; i++) {
                if (i + 1 < N && A[i] == A[i + 1]) {
                } else if (i - 1 >= 0 && A[i] == A[i - 1]) {
                } else if (used[A[i]]) {
                } else {
                    count++;
                }
                if (!used[A[i]]) {
                    for (int j = A[i]; j < used.length; j += A[i]) {
                        used[j] = true;
                    }
                }
            }

            System.out.println(count);
        }
    }
}


// created on : Sun Jun 14 2020

import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) throws IOException {
        int n = in.nextInt();
        HashMap<Integer, Integer> map = new HashMap<>();
        for(int i = 0; i < n; i++){
            int num = in.nextInt();
            map.put(num, map.getOrDefault(num, 0) + 1);
        }
        int ans = 0;
        outer:
        for(int num: map.keySet()){
            if(map.get(num) == 1){
                List<Integer> div = divisors(num);
                for(int d: div){
                    if(d != num){
                        if(map.containsKey(d)){
                            continue outer;
                        }
                    }
                }
                ans++;
            }
        }
        println(ans);
        in.close();
        out.close();
    }

    public static ArrayList<Integer> divisors(int n){
        ArrayList<Integer> A = new ArrayList<>();
        for(int i = 1; i*i <= n; i++){
            if(n % i == 0){
                if(i == n/i){
                    A.add(i);
                }
                else{
                    A.add(i);
                    A.add(n/i);
                }
            }
        }
        return A;
    }

    static int MIN = Integer.MIN_VALUE;
    static int MAX = Integer.MAX_VALUE;
    static Reader in = new Reader();
    static PrintWriter out = new PrintWriter(System.out);

    static int[] readInt(int N) throws IOException {
    	int arr[] = new int[N];
    	for(int i = 0; i < N; i++){
    		arr[i] = in.nextInt();
    	}
    	return arr;
    }

    static long[] readLong(int N) throws IOException {
    	long arr[] = new long[N];
    	for(int i = 0; i < N; i++){
    		arr[i] = in.nextLong();
    	}
    	return arr;
    }

    static void print(Object O) {
    	out.print(O);
    }

    static void println(Object O) {
    	out.println(O);
    }

    static void println(int arr[]) {
    	for(int i = 0; i < arr.length; i++){
    		print(arr[i] + " ");
    	}
    	println("");
    }

    static void displayRuntime(long startTime){
        long stopTime = System.currentTimeMillis();
        long elapsedTime = stopTime - startTime;
        System.out.println("Runtime: " + elapsedTime / 1000D);
    }
}

class Reader {
    BufferedReader reader;
    StringTokenizer tokenizer;

    Reader() {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
    }

    String next() throws IOException {
        while (!tokenizer.hasMoreTokens() ) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    String nextLine() throws IOException {
        return reader.readLine();
    }

    void close() throws IOException {
        reader.close();
    }
}


import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long ans = 1;
		long max = 1000000000000000000l;
		// System.out.println(max);
		List<Long> arr = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			arr.add(sc.nextLong());
		}
		Collections.sort(arr);
		for (int i = 0; i < n; i++) {
			if (arr.get(i) > max) {
				ans = -1;
				break;
			}
			ans *= arr.get(i);
			if (ans > max) {
				ans = -1;
				break;
			}
			if (ans == 0) {
				ans = 0;
				break;
			}
		}
		System.out.println(ans);
	}
}

Score : 200 points

Problem Statement

Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N.

However, if the result exceeds 10^{18}, print -1 instead.

Constraints

2 \leq N \leq 10^5

0 \leq A_i \leq 10^{18}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 ... A_N

Output

Print the value A_1 \times ... \times A_N as an integer, or -1 if the value exceeds 10^{18}.

Sample Input 1

2
1000000000 1000000000

Sample Output 1

1000000000000000000

We have 1000000000 \times 1000000000 = 1000000000000000000.

Sample Input 2

3
101 9901 999999000001

Sample Output 2

-1

We have 101 \times 9901 \times 999999000001 = 1000000000000000001, which exceeds 10^{18}, so we should print -1 instead.

Sample Input 3

31
4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5 0

Sample Output 3

0


import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if(n > 1 && n < 100000) {
			long total = 1;
			for(int i = 0;i < n;i++) {
				long y = sc.nextLong();
				total *= y;
			}
			if(total > 1000000000000000000l) {
				System.out.println(-1);
			}else if(total >= 0){
				System.out.println(total);
			}
		}
  }
}


import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();

        double product = 1;
        double limit = (double) Math.pow(10, 18);

        for (int i = 1; i <= N; i++) {
            double A_i = scan.nextDouble();
            product = product * A_i;
        }

        if (product > limit) {
            System.out.println("-1");
            return;
        }

        else {
            System.out.println(product);
        }

    }

}


import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] a = new long[n];
		long ans = 1;
		long max = (long)Math.pow(10,18);

		for(int i=0; i<n; i++){
		    a[i]=sc.nextLong();
		    if(a[i]==0){
		        System.out.println(0);
		        return;
		    }
		}

		if(ans != 0){
		    for(int i=0; i<n; i++){
		        if(max/ans <a[i]){
		            System.out.println(0);
		        return;
		        }else{
		            ans = ans*a[i];
		        }
		    }
		}

		System.out.println(ans);
	}
}


import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		long[] arr = new long[t];
		long product = 1; long upperLimit = 1000000000000000000L;
		while(t-- > 0) {
			arr[t] = sc.nextLong();
			product*=arr[t];
			if (arr[t] == 0) {
				product = 0;
				break;
			}
		}
		System.out.println(product <= upperLimit ? product : "-1" );
	}
}


import java.math.BigInteger;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner kb = new Scanner(System.in);
		BigInteger count = new BigInteger("1");
		boolean t = true;
		int n = kb.nextInt();
		for (int i = 0; i < n; i++) {
			if (t = true) {
				long j = kb.nextLong();
				count = count.multiply(BigInteger.valueOf(j));
				if (count.compareTo(new BigInteger("1000000000000000000")) == 1) {
					t = false;
				}
			}
		}
		int res = count.compareTo(new BigInteger("1000000000000000000"));
		if (res == 1) {
			System.out.println(-1);
		} else {
			System.out.println(count);
		}

		kb.close();
	}

}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        BMultiplication2 solver = new BMultiplication2();
        solver.solve(1, in, out);
        out.close();
    }

    static class BMultiplication2 {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int ntc = 1;
//        ntc = in.nextInt();
            while ((ntc--) > 0) {
                int n = in.nextInt();
                long[] arr = in.nextLongArray(n);
                long prod = 1;
                boolean ok = true;
                for (int i = 0; i < n; i++) {
                    prod *= arr[i];
                    if (prod > (long) 1e18) {
                        ok = false;
                    }
                    if (arr[i] == 0) {
                        out.println(0);
                        return;
                    }
                }
                if (!ok) {
                    out.println(-1);
                } else {
                    out.println(prod);
                }
            }
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public long[] nextLongArray(int n) {
            return nextLongArray(n, 0);
        }

        public long[] nextLongArray(int n, int startFrom) {
            long[] array = new long[n];
            for (int i = startFrom; i < n; ++i) array[i] = nextLong();
            return array;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void println(long i) {
            writer.println(i);
        }

    }
}


import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        //入力
      	int n = sc.nextInt();
        long a[] = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextLong();
        }
 		//0を見つけたいので昇順にソート
        Arrays.sort(a);
 		//10の18乗
        final long K = (long) Math.pow(10, 18);
 		//0があるとき
        if (a[0] == 0) {
            System.out.println(0);
            return;
        }

        long result = 1;
      	//取り出した値を格納する変数:順に取り出したい配列
        for (long l : a) {
            if (result > K / l) {
                System.out.println(-1);
                return;
            }
          //取り出した値を掛ける
            result *= l;
        }
        System.out.println(result);

    }
}


import java.util.*;
import java.math.BigInteger;

public class Main{

  public static void main(String[] args){

    Scanner sc = new Scanner(System.in);
    int num = sc.nextInt();

      BigInteger ans  = BigInteger.ONE;
      while(sc.hasNext()){
        long a = sc.nextLong();
        ans = ans.multiply(BigInteger.valueOf(a));
      }
      long l = (long)Math.pow(10,18);
      BigInteger L = BigInteger.valueOf(l);

      if(ans.compareTo(L) <= 0){
        System.out.println(ans);
      }else{
        System.out.println(-1);
      }
  }
}


import java.util.*;
import java.io.*;

public class Main {
    static StringTokenizer st;
    static BufferedReader br;
    static PrintWriter out;

    public static void main(String[] args) throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));

        int N = nextInt();
        long[] input = new long[N];

        for (int i=0; i<N; i++) {
            input[i] = nextLong();
            if(input[i]==0) {
                System.out.println(0);
                return;
            }
        }

        long ans =input[0];

        for (int i=1; i<N; i++) {
            // If you directly perform multiplication on 64-bit integers, it causes overflow
            // if((Math.log10(ans) + Math.log10(input[i]) >= 18) && ans * input[i] != 1e18){
            //if(ans> 1e18/ input[i]){
            // > not working, need use <=, because 1e18/ input[i] will lose 0.000001
            if(!(ans<= (long)(1e18)/ input[i])){
                System.out.println(-1);
                return;
            }
            ans = ans * input[i];
        }

        System.out.println(ans);

    }

    public static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }
    public static long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    public static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    static String next() throws IOException {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine().trim());
        return st.nextToken();
    }
}


import java.util.*;
import java.lang.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int a = scan.nextInt();

    long sum = 1;
    long [] c = new long[a];
    for (int i=0;i<a;i++){
      long b = scan.nextLong();
      if (b==0){
        System.out.println(0);
        return;
      }
      c[i] = b;
    }

    for (int j=0;j<a;j++){
      if (Math.log10(sum)+Math.log10(c[j])>18){
        System.out.println(-1);
        return;
      }
      sum*=c[j];
    }
    System.out.println(sum);
  }
}


import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long a = 1;

        for (int i = 0; i < n; i++) {
            a *= sc.nextInt();
        }

        if (a > 1000000000000000000L) a = -1;

        System.out.println(a);
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Scanner;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Multiplication2 solver = new Multiplication2();
        solver.solve(1, in, out);
        out.close();
    }

    static class Multiplication2 {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int num = in.nextInt();
            long ans = 1;

            long border = pow(10, 18);
            List<Long> lists = new ArrayList<>();

            for (int i = 0; i < num; i++) {
                long a = in.nextLong();
                lists.add(a);
            }
            if (lists.contains(0L)) {
                out.append("0\n");
                return;
            }
            for (Long a : lists) {
                ans *= a;
                if (ans > border) {
                    out.append("-1\n");
                    return;
                }
            }
            out.append(String.valueOf(ans));
        }

        static long pow(long x, long n) {

            if (n == 0) {
                return 1;
            }
            long result = pow(x, n / 2);

            if (n % 2 == 0) {
                return (result * result);
            }
            return ((result * result)) * x;
        }

    }
}


import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();

        long result = 1;

        long a = (long) Math.pow(10, 18);

        for (int i = 0; i < N; i++) {
            long A = scanner.nextLong();
            result = result * A;
            if(result==0){
                break;
            }

            if(result<0){
                result=-1;
            }
       }

       if(a>=result && result>=0){
           System.out.print(result);
       }
       if(a<result || result<0){
           System.out.print(-1);
       }

    }

}


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

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		// 整数の数
		int N = scan.nextInt();

		BigInteger ans = BigInteger.ONE;

		List<Long>  list = new ArrayList();

		for(int i = 0; i < N; i++) {
			list.add(scan.nextLong());
		}

		// ansに掛け算の結果
		for(int i = 0; i < list.size(); i++) {
			ans = ans.multiply(BigInteger.valueOf(list.get(i)));
		}

		//9223372036854775807

		//18446744073709551616
		System.out.println(ans.toString());
		System.out.println(ans.toString().length() );
		if(ans.toString().length() > 18 ) {
			System.out.println(-1);
		}else {
			System.out.println(ans);
		}

	}

}


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

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		// 整数の数
		int N = scan.nextInt();

		BigInteger ans = BigInteger.ONE;

		List<Long>  list = new ArrayList();

		for(int i = 0; i < N; i++) {
			list.add(scan.nextLong());
		}

		// ansに掛け算の結果
		for(int i = 0; i < list.size(); i++) {
			ans = ans.multiply(BigInteger.valueOf(list.get(i)));
		}

		//9223372036854775807

		//18446744073709551616
		System.out.println(ans.toString().length() );
		if(ans.toString().length() > 19 ) {
			System.out.println(-1);
		}else {
			System.out.println(ans.longValue());
		}

	}

}


import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		long num[]=new long[N];
		for(int i=0;i<N;i++) {
			num[i]=sc.nextLong();
		}
		sc.close();
		long border=1000000000000000000l;
		long result=1l;
		for(int i=0;i<N;i++) {
			if(num[i]==0) {
				System.out.println(0);
				System.exit(0);
			}
		}
		for(int i=0;i<N;i++) {
			if(result>border/num[i]) {
				System.out.println(-1);
				System.exit(0);
			}else {
				result*=num[i];
			}
		}
		System.out.println(result);
	}
}


import java.util.*;
import java.io.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		long[] arr = new long[t];
		for (int i=0; i<t; i++) {
		    arr[i] = sc.nextLong();
		}
		sc.close();

		long result=1;
		long max = (long) Math.pow (10, 18);
		for(long a: arr) {
		    result*=a;
		}
		if (result >= max)
		    result = -1;
		 System.out.println(result);
	}
}


import java.util.Scanner;

public class Main { //クラス名はMain
    public static void main(String[] args) {
        //コード
        Scanner sc = new Scanner(System.in);
        int cnt = Integer.parseInt(sc.next());
        int y = 0;
        try {
            for (int i = 0; i < cnt; i++){
                if (i == 0){
                    y = Integer.parseInt(sc.next());
                } else {
                    y *= Integer.parseInt(sc.next());
                }
            }
            System.out.println(y);
        } catch(Exception e){
            System.out.println(-1);
        }

        sc.close();
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task
    {
        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            int N = in.nextInt();
            long A[] = CPUtils.readLongArray(N, in);
            long answer = 1;

            for (long a : A)
            {
                if (a == 0)
                {
                    out.println(0);
                    return;
                }
            }
            for (long a : A)
            {
                answer *= a;
                if (answer < 0)
                {
                    out.println(-1);
                    return;
                }
            }
            if (answer > 1_000_000_000_000_000_000L)
            {
                out.println(-1);
                return;
            }
            out.println(answer);
        }

    }

    static class CPUtils
    {
        public static long[] readLongArray(int size, Scanner in)
        {
            long[] array = new long[size];
            for (int i = 0; i < size; i++)
            {
                array[i] = in.nextLong();
            }
            return array;
        }

    }
}


import java.util.*;
import java.lang.Math;
public class Main {
    public static void main (String [] args)
    {
        long max = (long)Math.pow(10,18);
        Scanner s = new Scanner(System.in);

        int len = s.nextInt();
        boolean isZero = false;
        boolean tooLong = false;
        int[] nums = new int[len];
        for(int i = 0; i < len; i++)
        {
            nums[i] = s.nextInt();
            if(nums[i] == 0)
            {
                isZero = true;
            }
        }
        int result = 1;

        for(int i = 0; i < len && !isZero; i++)
        {
            if(1000000000000000001L/result >= nums[i])
            {
                result *= nums[i];
            }
            else
            {
                tooLong = true;
                break;
            }
        }

        if(isZero)
        {
            System.out.println(0);
        }
        else if(tooLong)
        {
            System.out.println(-1);
        }
        else
        {
            System.out.println(result);
        }
    }
}


import java.util.*;
import java.math.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		final int N = sc.nextInt();
		BigInteger ans = new BigInteger("1");
		final BigInteger TEN_EIGHTEEN = new BigInteger("1000000000000000000");
		final BigInteger ZERO = new BigInteger("0");
		final BigInteger OVER = new BigInteger("-1");
		String[] s = new String[N];
		Boolean flag_z = false;
		for (int i = 0; i < N; ++i) {
			s[i] = sc.next();
			if (s[i].equals("0")) {
				flag_z = true;
			}
		}
		if (flag_z) {
			ans = ZERO;
		} else {
			for (int i = 0; i < N; ++i) {
				BigInteger A = new BigInteger(s[i]);
				if (A.compareTo(ZERO) != 0) {
					if (ans.multiply(A).compareTo(TEN_EIGHTEEN) <= 0) {
						ans = ans.multiply(A);
					} else {
						ans = OVER;
						break;
					}
				} else {
					ans = ZERO;
					break;
				}
			}
		}
		// System.out.println(" "+ans.toString());
		sc.close();
		if (ans.compareTo(ZERO) == -1) {
			System.out.println("-1");
		}else{
			System.out.println(ans.toString());
		}
	}
}


import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.FileInputStream;
import java.util.Arrays;
import java.math.BigInteger;
import java.io.InputStream;
import java.util.InputMismatchException;

public class Main {
    InputStream is;

    int __t__ = 1;
    int __f__ = 0;
    int __FILE_DEBUG_FLAG__ = __f__;
    String __DEBUG_FILE_NAME__ = "src/D3";

    FastScanner in;
    PrintWriter out;

    public void solve() {
        int n = in.nextInt();
        long[] a = in.nextLongArray(n);
        for (int i = 0; i < n; i++) {
            if (a[i] == 0) {
                System.out.println("0");
                return;
            }
        }

        long res = 1;
        for (int i = 0; i < n; i++) {
            if ((res * a[i]) / a[i] != res) {
                System.out.println("-1");
                return;
            }
            res *= a[i];
        }
        System.out.println(res > (long) 1e18 ? -1 : res);
    }

    public void run() {
        if (__FILE_DEBUG_FLAG__ == __t__) {
            try {
                is = new FileInputStream(__DEBUG_FILE_NAME__);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
            System.out.println("FILE_INPUT!");
        } else {
            is = System.in;
        }
        in = new FastScanner(is);
        out = new PrintWriter(System.out);

        solve();
    }

    public static void main(final String[] args) {
        new Main().run();
    }
}

class FastScanner {
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;

    public FastScanner(InputStream stream) {
        this.stream = stream;
        // stream = new FileInputStream(new File("dec.in"));
    }

    int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public boolean isSpaceChar(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public boolean isEndline(int c) {
        return c == '\n' || c == '\r' || c == -1;
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public int[] nextIntArray(int n) {
        int[] array = new int[n];
        for (int i = 0; i < n; i++)
            array[i] = nextInt();

        return array;
    }

    public int[][] nextIntMap(int n, int m) {
        int[][] map = new int[n][m];
        for (int i = 0; i < n; i++) {
            map[i] = nextIntArray(m);
        }
        return map;
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public long[] nextLongArray(int n) {
        long[] array = new long[n];
        for (int i = 0; i < n; i++)
            array[i] = nextLong();

        return array;
    }

    public long[][] nextLongMap(int n, int m) {
        long[][] map = new long[n][m];
        for (int i = 0; i < n; i++) {
            map[i] = nextLongArray(m);
        }
        return map;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }

    public double[] nextDoubleArray(int n) {
        double[] array = new double[n];
        for (int i = 0; i < n; i++)
            array[i] = nextDouble();

        return array;
    }

    public double[][] nextDoubleMap(int n, int m) {
        double[][] map = new double[n][m];
        for (int i = 0; i < n; i++) {
            map[i] = nextDoubleArray(m);
        }
        return map;
    }

    public String next() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }

    public String[] nextStringArray(int n) {
        String[] array = new String[n];
        for (int i = 0; i < n; i++)
            array[i] = next();

        return array;
    }

    public String nextLine() {
        int c = read();
        while (isEndline(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isEndline(c));
        return res.toString();
    }

    public int[][] nextPackedIntArrays(int packN, int size) {
        int[][] res = new int[packN][size];
        for (int i = 0; i < size; i++) {
            for (int j = 0; j < packN; j++) {
                res[j][i] = nextInt();
            }
        }
        return res;
    }
}


import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
	static final int MAX = 2_147_483_646; // intMax
	static final int INF = 1_000_000_000; // 10^9
	public static void main(String[] args) throws Exception{
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		long ans = 1L;
		long[] a = new long[n];
		for(int i = 0;i < n;i++){
			a[i] = saori.saorihayami();
			if(a[i] == 0){
				System.out.println(0);
				return;
			}
		}
		for(int i = 0;i < n;i++){
			if(ans > 1000000000000000000L/a[i]){
				System.out.println(-1);
				return;
			}
			ans *= a[i];
		}
		System.out.println(ans);
		saori.close();
	}
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() {
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) {
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() {
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }

}


import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long ans = 1;
    int n = sc.nextInt();

    for (int i = 0; i < n; i++) {
      long next = sc.nextLong();

      if (ans != -1) {
        if (1000000000000000000L / next < ans) {
          ans = -1;
        } else {
          ans *= next;
        }
      } else {
        if (next == 0) {
          ans = 0;
          break;
        }
      }
    }

    System.out.println(ans);
  }
}


import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        long prod = 1;
        for (int i = 0; i < N; ++i) {
            prod *= scanner.nextLong();
            if (prod>1000000000000000000L)
            {
                prod=-1;
                break;
            }
        }
        System.out.println(prod);
    }
}


import java.math.BigDecimal;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Long N = sc.nextLong();
        BigDecimal result = new BigDecimal(1);
        BigDecimal max = new BigDecimal(1000000000).multiply(new BigDecimal(1000000000));
        for(long i = 0; i<N; i++) {
            if (result.compareTo(max)==1) {
                if (sc.nextInt() == 0) {
                    System.out.println(0);
                    return;
                }
            }
            result = result.multiply(sc.nextBigDecimal());
        }
        if (result.compareTo(max)==1) {
            System.out.println(-1);
        } else {
            System.out.println(result);
        }
    }
}


import java.util.*;

public class Main {
	public static void main(String[] arags) {
      Scanner sc = new Scanner(System.in);
      int N=sc.nextInt();
      long[] B=new long[100000];
      long C=1L;

      for(int i=0;i<N;i++){
      	B[i]=sc.nextLong();
      }

      for(int i=0;i<N;i++){
      	C=C*B[i];
        if(C>1000000000000000000L){
        	C=-1;
        }
      }

      System.out.println(C);

    }
}


import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		long n = sc.nextLong(); sc.nextLine();
       long total=1;

for(int i=0;i<n;i++){

total*=sc.nextLong();
}
//計算
      if(total>(long) Math.pow(10, 18)){
System.out.println("-1");
      }else{
		// 出力
		System.out.println(total);

      }
	}
}


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

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		ArrayList<Long> receive = new ArrayList<>();

		for(int i = 0; i < N; i++) {
			receive.add(sc.nextLong());
		}

		sc.close();

		double b = Math.pow(10, 18);
		//System.out.println(b);
		long answer = -1;

		//超えるか超えないか
		for(int i = 0; i < receive.size(); i++) {
			if(receive.get(i) == 0) {
				answer = 0;
				break;
			}else {
				b = b/receive.get(i);
			}
		}

		if(b >= 1) {
			answer = 1;
			for(int i = 0; i < receive.size(); i++) {
				answer *= receive.get(i);
			}
		}

		System.out.println(answer);
	}
}


import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws FileNotFoundException {

//    	File file = new File("src/in.txt");

        //コード
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);

    	int N = sc.nextInt();

    	long[] A = new long[N];

    	long times = 1;
    	long K = (long) Math.pow(10,18);

    	boolean flg = true;
    	boolean haszero = false;

    	for(int i=0;i<N;i++) {
    		A[i]=sc.nextLong();
    	}

    	for(int i=0;i<N;i++) {
    		if(A[i]==0) {
    			haszero = true;
    			break;
    		}
    	}

    	if(haszero==false) {

        	for(int i=0;i<N;i++) {
        		times = times * A[i];

        		if(times>K) {
        			flg = false;
        			break;
        		}
        	}

        	if(flg) {
        		System.out.println(times);
        	} else {
        		System.out.println("-1");
        	}

    	} else {
    		System.out.println("0");
    	}
    }
}


import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
class Main{
  public static void main(String[] args) throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st;
        String str = br.readLine().trim();
    int n = Integer.parseInt(str);
     BigInteger b1 = new BigInteger("1");
      BigInteger b3 ;
      st = new StringTokenizer(br.readLine());
    while(n-->0){

        b3 = new BigInteger(st.nextToken());
        //System.out.println(b3);
        b1 = b1.multiply(b3);
    }
 //   BigInteger b2 = new BigInteger("1000000000000000000");
  //  System.out.println();
  //BigInteger n1 = b2.divide(b1);
  String s = String.valueOf(b1);
 // System.out.println(n1);
    if(b1.toString().length()>18 && s.charAt(s.length()-1)!='0')
        System.out.println("-1");
    else
        System.out.println(b1);

  }
}


import java.util.Scanner;
import java.math.BigDecimal;
public class Main {
	public static void main(String[] args) {
		Scanner sn = new Scanner(System.in);
		Integer cnt = Integer.parseInt(sn.next());
		BigDecimal sum = new BigDecimal(sn.next());
        for (int i=0; i < cnt -1; i++){
			sum = sum.multiply(new BigDecimal(sn.next()));
        }
        BigDecimal a = new BigDecimal(Math.pow(10, 18));
   		if (sum.compareTo(a) > 0) {
			System.out.print(-1);
		}else {
			System.out.print(sum);
		}
	}
}


import java.math.BigDecimal;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int length = sc.nextInt();
        BigDecimal ans = new BigDecimal("1");
        boolean isBreak = false;
        BigDecimal max = new BigDecimal("1000000000000000000");
        for (int i = 0; i < length; i++) {
            // 0確認
            BigDecimal tmp = new BigDecimal(sc.next());
            if (tmp.equals(BigDecimal.ZERO)) {
                System.out.println(0);
                isBreak = true;
                break;
            }

            ans = ans.multiply(tmp);
        }

        if (!isBreak) {
            // 上限超過
            if (ans.compareTo(max) > 1) {
                System.out.println(-1);
            } else {
                System.out.println(ans);
            }
        }
    }
}


import java.util.*;

public class Main {
  public static void main(String[] args ) throws Exception {
    Scanner sc = new Scanner(System.in);
    int num = sc.nextInt();
	double mul[] = new double[num];
	for (int i = 0; i < num; i++) {
      mul[i] = sc.nextInt();
    }
    double ans = 1;
    for (int j = 0; j < num; j++) {
      ans = ans * mul[j];
    }

    double b = Math.pow(10,18);
    if (ans <= b) {
      String ansStr = Double.toString(ans);
      int k = ansStr.length();
      System.out.println(ansStr.substring(0,k-2));
    }
}
}


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

public class Main
{
    public static void main(String[] args)
    {
        String[] lines = getStdin();

        int n = Integer.parseInt(lines[0]);
        String[] inputs = lines[1].split(" ");

        Long[] val = new Long[n];
        for (int i = 0;i<n;i++){
            val[i] = Long.parseLong(inputs[i]);
            if(val[i]==0){
                System.out.println(0);
                return;
            }
        }

        long mul = 1L;
        for (int i = 0; i < n; i++) {
            mul *= val[i];
            if(mul > (long)Math.pow(10, 18)){
                System.out.println(-1);
                return;
            }
        }
        System.out.println((long)mul);
    }

    private static String[] getStdin()
    {
        Scanner scanner = new Scanner(System.in);
        ArrayList<String> lines = new ArrayList<>();
        while (scanner.hasNext()) {
            lines.add(scanner.nextLine());
        }
        return lines.toArray(new String[lines.size()]);
    }
}


import java.math.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.*;
public class Main {
    public static long num[] = new long[1023];
    public static int k=0;
    public static void main(String args[])throws IOException
    {
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        in.nextToken();
        int n = (int)in.nval;
        long sum=1,temp=0;
        boolean dui = false;
        long m=1000000000;
        for(int i=0;i<n;i++)
        {
            in.nextToken();
            long a = (long)in.nval;
            temp = sum;
            if(a==0)
            {
                sum=0;
            }
            else
            {
                sum*=a;
            }
          if(temp*a!=sum)
            dui = true;
        }
            if(dui==true||sum>m*m)
                out.println(-1);
            else
                out.println(sum);
        out.flush();
    }
                  }


import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        BigDecimal[] nums = new BigDecimal[N];
        for (int i = 0; i < N; i++) {
            nums[i] = new BigDecimal(sc.next());
        }
        Arrays.sort(nums);
        BigDecimal ans = nums[0];
        if (ans.longValue() == 0) {
            System.out.println(0);
        } else {
            boolean over = false;
            for (int i = 1; i < N; i++) {
                ans = ans.multiply(nums[i]);
                if (1000000000000000000L < ans.longValue()) {
                    System.out.println(-1);
                    over = true;
                    break;
                }
            }
            if (!over) {
                System.out.println(ans.longValue());
            }
        }
    }
}


import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        List<Long> kazu = new ArrayList<>();

        long ans = 1;
        long max = 1000000000000000000l;
        for(int i = 0;i < N;i++){
            long temp = sc.nextLong();;
            kazu.add(temp);
        }
        for(int i = 0;i < N;i++){
            long temp2 = kazu.get(i);
            ans *= temp2;
            if(ans >= max){
            break;
            }
        }
        //System.out.println(kazu);
        if(kazu.contains(0l)){
            System.out.println(0);
        }
        else if(ans <= max){
            System.out.println(ans);
        }else{
            System.out.println(-1);
        }
    }
}


import java.util.*;

class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int n = sc.nextInt();
		int ans = 1;
		long ansl = 1;
		boolean f = true;
		try {
			for (int i = 0; i < n; i++) {
				int temp = sc.nextInt();
				if (temp == 0) {
                  	ansl=0;
                  	f=false;
					break;
				}
				ansl *= temp;
				ans = (int) ansl;
			}

		} catch (InputMismatchException e) {
			System.out.println(-1);
			f=false;
		}
		if (ansl <= (long) Math.pow(10, 18)&&f) {
			System.out.println(ansl);
		} else {
			if(f)
			System.out.println(-1);
		}

	}
}


import java.util.Scanner;

public class Main {
	private static final long MAX = 1000000000000000000L;
	public static void main(final String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		boolean over = false;
		long answer = 1L;
		for(int i = 0; i < N; i++) {
			long A = sc.nextLong();
			if((answer * A) < 0 || (answer * A) > MAX) {
				over = true;
			} else {
				over = false;
			}
			if(!over) answer *= A;
		}
		sc.close();
		prtln(over ? -1 : answer);
	}

	public static <T> void prtln(T t) { System.out.println(t); }
}


import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main{
    public static void main(String [] args) {
        Scanner sc = new Scanner(System.in);
     int a= sc.nextInt();
     long sum=1;
     while(a--!=0){
       long x=sc.nextLong();
         sum*=x;
    }

     if(sum>(long)1e18) System.out.print(-1);
     else System.out.print((long)sum);
        //System.out.println(101*9901*999999000001l);
    }
}


import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan =new Scanner(System.in);
		long N=scan.nextLong();
		long sum=1;
		int b=18;
		long bmax=1;
		for(int i=0;i<N;i++) {
			long a=scan.nextLong();
			sum*=a;
		}

		for(int i=0;i<b;i++) {
			bmax*=10;
		}
		if(sum<=bmax) {
			System.out.println(sum);
		}else {
			System.out.println("-1");
		}
		}
}


import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    try (Scanner sc = new Scanner(System.in)) {
      int kazu = Integer.parseInt(sc.next());
      long totalnum = 1;
      Boolean flg = true;
      for (int i = 0; i < kazu; i++) {
        totalnum *= Long.parseLong(sc.next());
        if (totalnum > new Double(
            10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10).longValue()) {
          System.out.println(-1);
          flg = false;
        }
      }
      if (flg) {
        System.out.println(totalnum);
      }
    }
  }
}


import java.util.*;
public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long[] A = new long[N];
		long ans = 1;
		int keta = 1;
		int ansKeta = 1;
		for(int i = 0;i < N;i++){
			A[i] = sc.nextLong();
			keta = (int)Math.floor(Math.log10((double)A[i]));
			if(A[i] == 0){
				ans = 0;
				break;
			}else if(ansKeta + keta < 19 && ansKeta + keta > -1){
				ans *= A[i];
				ansKeta = (int)Math.floor(Math.log10((double)ans));
			}else{
				ans = -1;
				break;
			}
		}
		if(ans > 1000000000000000000L){
			ans = -1;
		}
		System.out.println(ans);
	}
}


import java.math.BigInteger;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] numberList = new long[n];
		BigInteger answer = BigInteger.ONE;
		for(int i = 0;i < n;i++) {
			long number = sc.nextLong();
			if(number == 0) {
				System.out.println(0);
				return;
			}
			numberList[i] = number;

		}

		for(int i =0;i < n;i++) {

			answer = answer.multiply(new BigInteger(String.valueOf(numberList[i])));
			if(answer.compareTo(new BigInteger(String.valueOf((long)Math.pow(10, 18)))) >=1) {
				System.out.println(-1);
				return;
			}
		}

		System.out.println(answer);
	}

}


import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner scn = new Scanner(System.in)) {
			int N = scn.nextInt();
			long[] a = new long[N];

			for(int i = 0; i < N; i++) {
				a[i] = scn.nextLong();
				if(a[i] == 0) {
					System.out.println(0);
					System.exit(0);
				}
			}

			long max = (long) Math.pow(10, 18);
			long chk = (long) Math.pow(10, 12);

			long tmp = a[0];
			for(int i = 1; i < N; i++){
				if(tmp > chk && a[i] > chk) {
					System.out.println(-1);
					System.exit(0);
				}

				try {
					tmp = Math.multiplyExact(tmp, a[i]);
		        } catch (ArithmeticException e) {
		        	System.out.println(-1);
					System.exit(0);
		        }
			}
			System.out.println(tmp);
		}
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String args[]) throws IOException {

	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	long N = Long.parseLong(br.readLine());
	String array[] = br.readLine().split(" ");
	long result = 1;
	for (int i = 0; i < N; i++) {
	    result *= Long.parseLong(array[i]);
	    if (result > 1000000000000000000L) {
		result = -1;
	    }
	}

	System.out.println(result);

    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    private static final int MOD = (int) Math.pow(10, 9);
    private static final long EIGHT = (long) 1e18;
    private static final int[][] DIRS = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};

    public static void main(String[] args) {
        FastReader sc = new FastReader();
        int n = sc.nextInt();
        long res = 1;
        long[] nums = new long[n];
        for (int i = 0; i < n; i++) {
            long m = sc.nextLong();
            if (m == 0) {
                print("0");
                System.exit(0);
            }
            nums[i] = m;
        }

        for (int i = 0; i < n; i++) {
            if (res >= (EIGHT)) {
                res = -1;
                break;
            }
            res *= nums[i];
            if (res > (EIGHT)) {
                res = -1;
                break;
            }
        }

        print(""+res);
        System.exit(0);
    }

    static private void swap(int[] nums, int x, int y) {
        int tmp = nums[x];
        nums[x] = nums[y];
        nums[y] = tmp;
    }

    static  private void reverse(int[] nums, int left, int right) {
        while (left < right) {
            swap(nums, left, right);
            left++;
            right--;
        }
    }

    static private boolean findNextPermutation(int[] nums) {
        if (nums.length <= 1) {
            return false;
        }

        int last = nums.length - 2;

        while (last >= 0) {
            if (nums[last] < nums[last + 1]){
                break;
            }
            last--;
        }

        if (last < 0) { return false; }
        int nextGenerater = nums.length - 1;

        for (int i = nums.length - 1; i > last; i--) {
            if (nums[i] > nums[last]) {
                nextGenerater = i;
                break;
            }
        }

        swap(nums, nextGenerater, last);
        reverse(nums, last + 1, nums.length - 1);
        return true;
    }

    static private int[] generateNArray(int n) {
        int[] res = new int[n];

        for (int i = 0; i < n; i++) {
            res[i] = i + 1;
        }

        return res;
    }

    static  private void print(String s) {
        System.out.println(s);
    }

    static private void printArray(int[] e) {
        for (int s: e) {
            System.out.print(s + " ");
        }
        print("");
    }

    static private int log2(int x) {
        return (int)(Math.log(x) / Math.log(2));
    }

    static private long gcd(long m, long n) {
        if (m < n) { return gcd(n, m); }
        if (m % n == 0) { return n; }
        return gcd(n, m%n);
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try{
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


import java.util.Map.Entry;
import java.util.*;
import java.math.*;
import org.w3c.dom.css.Counter;

public class Main{
    public static void main(final String[] args){

        final Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        long An = 1;
        long temp =1;
        int flag=0;
        //final long answer=1;
        final long max = 1000000000000000000l;

        for(long i = 0; i < N; i++) {
            temp = sc.nextInt();
            if(temp == 0){
                System.out.println(0);
               return;
            }else{
                An = An * temp;
            }
            if(An >max){
                flag = 1;
                An =1;
            }
        }

        if(flag != 0){
            System.out.println(-1);
        }else{
            System.out.println(An);
        }

    }
}


import java.util.*;
import java.math.*;

public class Main {

  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    BigDecimal[] A = new BigDecimal[N+1];
    BigDecimal a = new BigDecimal(1);
    BigDecimal b = new BigDecimal(Math.pow(10,18));
    for (int i =1; i<=N; i++) {
      A[i] = sc.nextBigDecimal();
      a = a.multiply(A[i]);
      if (i == N) {
        if (a.compareTo(b) > 0) {
        a = new BigDecimal(-1);
        break;
        }
      }
    }
    System.out.println(a);
  }
}


import java.util.*;
public class Main{
  public static void main (String args[]){
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();

    long ans = 1;

    long max = 1000000000000000000L;

    for(int i = 0; i < n; i++){
      long l = sc.nextLong();
      ans = ans*l;
    }

    if (ans > max){
      ans = -1;
    }

    System.out.println(ans);
  }
}


// created on : Sun May 31 2020

import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Main{

    public static void main(String[] args) throws IOException {
        int N = in.nextInt();
        long A[] = new long[N];
        boolean zero = false;
        for(int i = 0; i < N; i++){
            A[i] = in.nextLong();
            if(A[i] == 0){
                zero = true;
            }
        }

        if(zero){
            println(0);
        }
        else{
            BigInteger limit = new BigInteger("1000000000000000000");
            BigInteger a = new BigInteger("1");
            boolean overflow = false;
            for(int i = 0; i < N; i++){
                a = a.multiply(BigInteger.valueOf(A[i]));
                if(a.compareTo(limit) > 0){
                    overflow = true;
                }
            }

            if(overflow){
                println(-1);
            }
            else{
                println(a);
            }
        }
        in.close();
        out.close();
    }

    static int MIN = Integer.MIN_VALUE;
    static int MAX = Integer.MAX_VALUE;
    static Reader in = new Reader();
    static PrintWriter out = new PrintWriter(System.out);

    static int[] readInt(int N) throws IOException {
    	int arr[] = new int[N];
    	for(int i = 0; i < N; i++){
    		arr[i] = in.nextInt();
    	}
    	return arr;
    }

    static long[] readLong(int N) throws IOException {
    	long arr[] = new long[N];
    	for(int i = 0; i < N; i++){
    		arr[i] = in.nextLong();
    	}
    	return arr;
    }

    static String[] readString(int N) throws IOException {
    	String arr[] = new String[N];
    	for(int i = 0; i < N; i++){
    		arr[i] = in.next();
    	}
    	return arr;
    }

    static void print(Object O) {
    	out.print(O);
    }

    static void println(Object O) {
    	out.println(O);
    }

    static void println(int arr[]) {
    	for(int i = 0; i < arr.length; i++){
    		print(arr[i] + " ");
    	}
    	println("");
    }

    static void debug(Object ... O) {
    	for(Object obj: O){
    		System.out.print(obj + " ");
    	}
    	System.out.println();
    }
}

class Reader {
    BufferedReader reader;
    StringTokenizer tokenizer;

    Reader() {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
    }

    String next() throws IOException {
        while (!tokenizer.hasMoreTokens() ) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    String nextLine() throws IOException {
        return reader.readLine();
    }

    void close() throws IOException {
        reader.close();
    }
}


import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        List<Long> kazu = new ArrayList<>();
        long ans = 1;
        for(int i = 0;i < N;i++){
            long temp = sc.nextLong();;
            ans *= temp;
        }
        long max = 1000000000000000000l;
        if(ans <= max){
            System.out.println(ans);
        }else{
            System.out.println(-1);
        }
    }
}


import java.math.BigInteger;
import java.util.Scanner;

public class Main {
    private static final int MOD = 1_000_000_007;
    private static final String YES = "Yes";
    private static final String NO = "No";

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

        int N = sc.nextInt();
        long[] A = new long[N];
        for (int i=0; i<N; i++) {
            A[i] = sc.nextLong();
        }

        System.out.println(solve(N, A));
    }

    private static String solve(int N, long[] A) {
        BigInteger b = BigInteger.ONE;
        BigInteger th = BigInteger.valueOf(1_000_000_000_000_000_000L);

        for (int i=0; i<N; i++) {
            if (A[i] == 0) return "0";
        }

        for (int i=0; i<N; i++) {
            b = b.multiply(BigInteger.valueOf(A[i]));

            if (b.compareTo(th) > 0) return "-1";
        }

        return b.toString();
    }
}


import java.util.*;

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

		int N = sc.nextInt();

		Long ans = (long) 1;
		Long limit = (long) Math.pow(10,18);
      	boolean flag = false;

		for(int i=0; i<N; i++){
          	Long tmp = sc.nextLong();
          	if(tmp==0){
              flag = false;
              ans = (long) 0;
              break;
			}
          	if(flag){
              continue;
			}
			ans *= tmp;
          	if(ans>limit){
              flag = true;
			}
		}
		if(flag){
			System.out.println("-1");
			return;
		}
		System.out.println(ans);
		return;
	}
}


// This template is based on Mr. tonymontaro's template (https://atcoder.jp/users/tonymontaro).
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

// For flatten() required Java8
import java.util.stream.Stream;
import java.util.stream.IntStream;

import java.util.Queue;
import java.util.ArrayDeque;

import java.util.ArrayList;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {
    static PrintWriter out;
    static CF_Reader in;

    static int INTMAX = 2147483647;

    // Start: 大きな数
    // 10^20くらいまで
    // long a = 0;
    // End: 大きな数
    public static void main(String[] args) throws IOException {
        out = new PrintWriter(new OutputStreamWriter(System.out));
        in = new CF_Reader();
        StringBuilder result = new StringBuilder();

        // Start: int型の整数N Mを取得する
        // // N M 形式
        long N = in.longNext();
        // int M = in.longNext();

        long res = 1L;
        for (int i = 0; i < N; i++) {
          res *= in.longNext();
        }
        String s = "1000000000000000000";
        long a = 1000000000000000000L;
        if (res != a && String.valueOf(res).length() >= 19) {
          res = -1;
        }

        result.append(res);

        //[補足]
        // N M
        // A B 形式だと
        // int N = in.intNext();
        // int M = in.intNext();
        // int A = in.intNext();
        // int B = in.intNext();
        // End: int型の整数N Mを取得する

        // Start: int型の整数Nと配列Aを取得する
        // // N
        // // A1 A2 A3... AN 形式
        // int n = in.intNext();
        // int[] A = in.nextIntArray(n);
        // End: int型の整数Nと配列Aを取得する

        // Start: Char型の文字をInt型に変換する
        // Integer.parseInt(String.valueOf(charText))
        // End: Char型の文字をInt型に変換する

        // Start: 文字列を1文字ずつ出力する
        // String text = in.next();
        // char[] work = new char[text.length()];
        // for(int i = 0; i < text.length(); i++){
        //   work[i] = text.charAt(i); // Char型の文字
        //   out.println(work[i]);
        // }
        // End: 文字列を1文字ずつ出力する

        // Start: 配列の定義
        // int[] a = new int[N];
        // int[][] b = new int[N][M];
        // End: 配列の定義

        // Start: キューの定義
        // Queue<int[]> queue = new ArrayDeque<int[]>();
        // Start: キューの定義

        // Start: リストのリスト
        // @SuppressWarnings("unchecked")
        // List<Integer>[] adjacents = new ArrayList[N];
        // Start: リストのリスト

        // Start: forEach文
        // for (int elem: elements) {
        // }
        // Start: forEach文

        out.println(result);

        out.close();
    }

    // 素数判定。
    public static boolean isPrime(int N) {
      if (N == 1) return false;
      for (int i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
      }
      return true;
    }

    // 使い方
    // List<String> list = new ArrayList<String>();
    // permutation(list, "abc", "");
    // for (String str : list) {
    //   out.print(str + " ");
    // }
    // >> abc acb bac bca cab cba
    public static List<String> permutation(List<String> list, String target, String ans){
      if(target.length() <= 1) {
        list.add(ans + target);
      } else {
        for (int i = 0; i < target.length(); i++) {
          permutation(
            list,
            target.substring(0, i) + target.substring(i + 1),
            ans + target.charAt(i));
        }
      }
      return list;
    }

    // 使い方
    // String[] list2 = { "A", "B", "C", "D"};
    // List<String[]> res = combination(list2, 3);
    // for (String[] arr : res) {
    //   out.print("[");
    //   for (String a : arr) {
    //     out.print(a + ", ");
    //   }
    //   out.print("], ");
    // }
    // >> [A, B, C], [A, B, D], [A, C, D], [B, C, D]
    static List<String[]> combination(String[] data, int k) {
        List<String[]> result = new ArrayList<String[]>();
        combination(data, 0, new String[k], 0, result);
        return result;
    }

    static void combination(String[] data, int di, String[] comb, int ci, List<String[]> result) {
        if (ci == comb.length) {
            result.add(comb.clone());
            return;
        }
        for ( ; di <= data.length - (comb.length - ci); di++) {
            comb[ci] = data[di];
            combination(data, di + 1, comb, ci + 1, result);
        }
    }

    public static int[] flatten(int[][] arr) {
       return Stream.of(arr)
          .flatMapToInt(row -> IntStream.of(row))
          .toArray();
    }

    public static int maxIntValueFromArray(int[] array) {

        int intMax = array[0];

        for (int i = 1; i < array.length; i++ ) {
            if(intMax < array[i]) {
                intMax = array[i];
            }
        }
        return intMax;
    }

    public static int minIntValueFromArray(int[] array) {

        int intMin = array[0];

        for (int i = 1; i < array.length; i++ ) {
            if(intMin > array[i]) {
                intMin = array[i];
            }
        }
        return intMin;
    }

    static class CF_Reader {
        BufferedReader br;
        StringTokenizer st;

        public CF_Reader() throws IOException {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine().trim());
            return st.nextToken();
        }

        long longNext() throws IOException {
            return Long.parseLong(next());
        }

        int intNext() throws IOException {
            return Integer.parseInt(next());
        }

        double doubleNext() throws IOException {
            return Double.parseDouble(next());
        }

        char charNext() throws IOException {
            return next().charAt(0);
        }

        public int[] nextIntArray(final int n) throws IOException {
            final int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = intNext();
            return a;
        }

        public long[] nextLongArray(final int n) throws IOException {
            final long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = longNext();
            return a;
        }

        String line() throws IOException {
            return br.readLine().trim();
        }
    }
}