function main(input){
    var inp = input.trim();
    var inpArray=inp.split('\n');
    var n = parseInt(inpArray[0]);
    var numArray = inpArray[1].split(' ');
    var out = 1 / 1000000000;
    for(i=0;i<n;i++){
        out = out * parseInt(numArray[i]);
        if(out>1000000000){
            out=-1;
            break;
        }
    }
    for(i=0;i<n;i++){
        if(parseInt(numArray[i])==0){
            out=0;
            break;
        }
    }
    console.log(out);

}

    main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

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

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.


"use strict"
function main(arg) {
    let data = arg.trim().split("\n")[1].split(" ")
    .map(e => BigInt(e))
    let boundary = 10 ** 18
    let sum = 1n
    for (let i = 0; i < data.length; i++) {
        if (data[i] === 0n) {
            console.log(0)
            return
        }
    }
    for (let i = 0; i < data.length; i++) {
        sum = sum * BigInt(data[i])
        if (boundary < sum) {
            console.log(-1)
            return
        }

    }
    console.log(sum + "")
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = []
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', (line) => {
  lines.push(line);
});

reader.on('close', () => {
 var n = Number(lines[0]);
 var a = lines[1].split(' ');
 var sum = 1;
 if(a.indexOf('0') != -1){
   sum = 0;
 }else{
   for(i=0; i<n; i++){
     sum = BigInt(sum) * BigInt(a[i]);
     if(sum > 1000000000000000000){
       sum = -1;
       break;
     }
   }
 }

 console.log(Number(sum));

 // console.log(a * b);

});


function Main(input) {
	var str = input;
	var ans = 1n;
	var flg = true;
	var count = 1;
	var str = str.split("\n");
	var a = str[1].split(" ");
	for(var j = 0;j<a.length;j++){
		a[j]=BigInt(a[j]);
		if(a[j]===0n){
			ans = 0;
			break;
		}
	}
	if(ans !==0){
	for(var i = 0;i<a.length;i++){
		ans = ans*a[i];

		if(ans > 10**18){
			ans = -1;
          break;
			}
    	}
  	if(ans !== -1){
  	ans = ans.toString();
    }
	}
   console.log(ans);
   }
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


function main(input) {
    // 入力値の分離
    param = input.split("\n");
    const num = param[1].split(" ");
    var result = BigInt(num[0]);
    for(var i = 1; i < param[0]; i++){
      result = result * BigInt(num[i]);
      if(result == BigInt(0)){
		break;
	  }
    }
	if(result > Math.pow(10, 18)){
        result = -1;
      }
	console.log(parseInt(result));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


function main(input) {
  const num = Number(input.split("\n")[0]);
  const numbers = input.split("\n")[1].split(" ");
  let ans = 1;
  numbers.forEach(i => ans += Math.log(Number(i)) * Math.LOG10E);

  console.log(ans);

  if (ans > 18) {
    console.log(-1);
  } else {
  	console.log(ans);
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


"use strict";

function main(input) {
  input = input.trim().split("\n");
  const line_one = parseInt(input[0]);
  const line_two_array = input[1].split(" ");
  const limit = BigInt(String(Math.pow(10, 18)));

  let ans = BigInt("1");
  for (let i = 0; i < line_one; i++) {
    ans = ans * BigInt(line_two_array[i]);
    // console.log(parseInt(ans) > parseInt(limit));
    // console.log(ans > limit);
    // console.log(ans, limit);
    // console.log(line_two_array[i]);
  }
  if (ans > limit) {
    ans = -1;
  }
  console.log(parseInt(ans));
}

main(require("fs").readFileSync("/dev/stdin", "utf-8"));


function Main(arg) {
    var arg = arg.trim().split('\n');
    var n = Number(arg[0]);
    var aList = arg[1].split(' ');

    if(aList.includes('0')){
        console.log(0);
        return;
    }
    var ret = 0;
    for (key in aList) {
        a = BigInt(aList[key]);
        if(a > 1000000000000000000){
            console.log(-1);
            return;
        }
        if (ret == 0){
            ret = a;
        } else {
            ret = ret * a;
        }
        if(ret > 1000000000000000000){
            console.log(-1);
            return;
        }
    }
    console.log(ret.toString());
    return;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


const main = arg => {
    const input = arg.trim().split("\n");
    const n = parseInt(input[0]);
    const arr = input[1].split(" ").map(item => BigInt(item));

    let ret = BigInt(1)
    for(let item of arr){
        if(item == 0n){
            console.log(0)
            return
        }
        ret = ret*item
        if(ret > BigInt(1000000000000000000)){
            console.log(-1)
            return
        }
    }
    console.log(Number(ret))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = []
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', (line) => {
  lines.push(line);
});

reader.on('close', () => {
 var n = Number(lines[0]);
 var a = lines[1].split(' ');
 var sum = 1;
 var ans = '';
 for(i=0; i<n; i++){
   sum = BigInt(sum) * BigInt(a[i]);
 }
 if(sum > 1000000000000000000){
   sum = '-1';
 }

 console.log(Number(sum));

 // console.log(a * b);

});


function main(input) {
    // const input = "3 5 2"
    var AA = input.split('\n')[1].split(' ').map((n) => parseInt(n, 10));
    var reducer = (a, b) => a * b;
    var answer = AA.reduce(reducer);
    if(answer > 1000000000000000000){
        console.log("-1")
    }else{
        console.log(answer)
    }

}main(require('fs').readFileSync('/dev/stdin', 'utf8'));


function main(lines) {
  const input = lines.split('\n').slice(1).join(' ').split(' ').map(Number)
  const multipleTimes = input.length - 1

  let output = 1
  for(let i=0; i<input.length; i++){
      if(output.toString(10).length + input[i].toString(10).length  === 18) {
        if((output.split(' ')[output.length-1] * input[i].split(' ')[input[i].length-1])%10 != 0){
            console.log('-1')
            return
        }
      }

      if(output.toString(10).length + input[i].toString(10).length >= 19){
        console.log('-1')
        return
      }

      output *= input[i]
  }

    console.log(output)

}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));