

Time Limit: 2 sec / Memory Limit: 1024 MiB
問題文
高橋君は銀行で N - 1 件の取引を行いました。
取引の内容は整数 A_1, A_2, \ldots, A_N によって表され、i 件目の取引は A_i < A_{i + 1} のとき A_{i + 1} - A_i 円の入金であり、A_i > A_{i + 1} のとき A_i - A_{i + 1} 円の出金です。ここで、与えられる入力は A_i \neq A_{i + 1} を満たします。
これらの取引における入金額の合計と出金額の合計をそれぞれ求めてください。
制約
- 2 \leq N \leq 100
- 0 \leq A_i \leq 10^7
- A_i \neq A_{i + 1}
- 入力される数値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
出力
入金額の合計を X 円、出金額の合計を Y 円として、X と Y をこの順に空白区切りで出力せよ。
入力例 1
4 2 9 5 8
出力例 1
10 4
-
1 件目の取引は、2 < 9 であるため 9 - 2 = 7 円の入金です。
-
2 件目の取引は、9 > 5 であるため 9 - 5 = 4 円の出金です。
-
3 件目の取引は、5 < 8 であるため 8 - 5 = 3 円の入金です。
したがって、入金額の合計は 10 円、出金額の合計は 4 円となります。
入力例 2
5 10 8 6 4 2
出力例 2
0 8
Problem Statement
Takahashi made (N - 1) transactions at a bank.
The transactions are described by integers A_1, A_2, \ldots, A_N. The i-th transaction is a deposit of (A_{i + 1} - A_i) yen if A_i < A_{i + 1}, and a withdrawal of (A_i - A_{i + 1}) yen if A_i > A_{i + 1}. (Yen is a currency of Japan.) Here, it is guaranteed that the given input satisfies A_i \neq A_{i + 1}.
Find the total amounts of money deposited and withdrawn through these transactions.
Constraints
- 2 \leq N \leq 100
- 0 \leq A_i \leq 10^7
- A_i \neq A_{i + 1}
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_1 A_2 \ldots A_N
Output
If a total of X yen was deposited and Y yen was withdrawn through the transactions, print X and Y in this order, separated by a space.
Sample Input 1
4 2 9 5 8
Sample Output 1
10 4
- The 1-st transaction is a 9 - 2 = 7 yen deposit, as 2 < 9.
- The 2-st transaction is a 9 - 5 = 4 yen withdrawal, as 9 > 5.
- The 3-st transaction is a 8 - 5 = 3 yen deposit, as 5 < 8.
Thus, a total of 10 yen was deposited, and 4 yen was withdrawn.
Sample Input 2
5 10 8 6 4 2
Sample Output 2
0 8