389A.md (1206B)
1 Source: https://codeforces.com/problemset/problem/389/A 2 3 A. Fox and Number Game 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 stdin 16 17 output 18 19 stdout 20 21 Fox Ciel is playing a game with numbers now. 22 23 Ciel has *n* positive integers: *x*1, *x*2, ..., *x**n*. She can do the following operation as many times as needed: select two different indexes *i* and *j* such that *x**i* > *x**j* hold, and then apply assignment *x**i* = *x**i* - *x**j*. The goal is to make the sum of all numbers as small as possible. 24 25 Please help Ciel to find this minimal sum. 26 27 Input 28 29 The first line contains an integer *n* (2 ≤ *n* ≤ 100). Then the second line contains *n* integers: *x*1, *x*2, ..., *x**n* (1 ≤ *x**i* ≤ 100). 30 31 Output 32 33 Output a single integer — the required minimal sum. 34 35 Examples 36 37 Input 38 39 ``` 40 2 41 1 2 42 ``` 43 44 Output 45 46 ``` 47 2 48 ``` 49 50 Input 51 52 ``` 53 3 54 2 4 6 55 ``` 56 57 Output 58 59 ``` 60 6 61 ``` 62 63 Input 64 65 ``` 66 2 67 12 18 68 ``` 69 70 Output 71 72 ``` 73 12 74 ``` 75 76 Input 77 78 ``` 79 5 80 45 12 27 30 18 81 ``` 82 83 Output 84 85 ``` 86 15 87 ``` 88 89 Note 90 91 In the first example the optimal way is to do the assignment: *x*2 = *x*2 - *x*1. 92 93 In the second example the optimal sequence of operations is: *x*3 = *x*3 - *x*2, *x*2 = *x*2 - *x*1.