#C9342. Minimize Array Operations

    ID: 53425 Type: Default 1000ms 256MiB

Minimize Array Operations

Minimize Array Operations

You are given an array of integers. You can perform two operations: addition and multiplication. The objective is to "minimize" the array to a single integer by applying these operations optimally.

The twist is: if the array contains the number \(1\), then the minimum possible value is always \(1\) (since multiplying by \(1\) is beneficial). Otherwise, if there is no \(1\) in the array, the minimum value is obtained by summing all the elements.

Your task is to compute this minimum value. The decision is simply:

  • If the array contains \(1\), output \(1\).
  • Otherwise, output the sum of all the elements, i.e., \(\sum_{i=1}^{n} a_i\).
  • This problem tests your ability to process input and apply a conditional strategy based on the input values.

    inputFormat

    The input is read from stdin and has the following format:

    • The first line contains an integer \(n\) which is the number of elements in the array.
    • The second line contains \(n\) space-separated integers \(a_1, a_2, \dots, a_n\).

    outputFormat

    Output a single integer to stdout representing the minimum possible value after performing the operations as described.

    ## sample
    5
    1 2 3 4 5
    1