#include <bits/stdc++.h>
using namespace std;
int f(long long int n) {
  if (n > 1) {
    long long int f = 1;
    for (long long int i = 2; i <= n; i++) f = f * i;
    return f;
  } else
    return 1;
}
bool isprime(long long int n) {
  if (n == 1)
    return false;
  else {
    for (long long int i = 2; i <= sqrt(n); i++)
      if (n % i == 0) return false;
    return true;
  }
}
vector<pair<long long int, long long int> > primefac(long long int n) {
  vector<pair<long long int, long long int> > a;
  long long int temp, test = 1, count;
  for (long long int i = 2; i <= sqrt(n); i++) {
    if (n % i == 0 && isprime(i)) {
      temp = n;
      count = 0;
      while (temp % i == 0) {
        count++;
        temp = temp / i;
      }
      a.push_back({i, count});
      test = pow(i, count) * test;
    }
  }
  if (test != n) a.push_back({n / test, 1});
  return a;
}
vector<long long int> fac(long long int n) {
  vector<long long int> a;
  for (long long int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (i != n / i) {
        a.push_back(i);
        a.push_back(n / i);
      } else
        a.push_back(i);
    }
  }
  return a;
}
bool sortbysec(const pair<long long int, long long int> &a,
               const pair<long long int, long long int> &b) {
  if (a.second != b.second)
    return (a.second > b.second);
  else
    return (a.first > b.first);
}
long long int gcd(long long int a, long long int b) {
  if (a == 0)
    return b;
  else if (b == 0)
    return a;
  else
    return gcd(b % a, a);
}
long long int ncr(long long int n, long long int r) {
  return (f(n) / (f(r) * f(n - r)));
}
vector<int> primev;
void SieveOfEratosthenes(int n) {
  bool prime[n + 1];
  memset(prime, true, sizeof(prime));
  for (int p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (int i = p * p; i <= n; i += p) prime[i] = false;
    }
  }
  for (int p = 2; p <= n; p++)
    if (prime[p]) primev.push_back(p);
}
long long int sum(long long int n) {
  long long int s = 0;
  while (n) {
    s += n % 10;
    n = n / 10;
  }
  return s;
}
long long int mx = 1e9 + 7;
bool func(long long int n) {
  long long int ans = 0;
  while (n) {
    if (n % 10 != 9) return false;
    n /= 10;
  }
  return true;
}
void solve() {
  long long int n, k = 0, c = 0, temp = 0, l = -1, r = -1, m = 1, s1 = 0,
                   s2 = 0;
  cin >> n;
  long long int a[n];
  for (long long int i = 0; i < n; i++) cin >> a[i];
  vector<long long int> v;
  for (long long int i = 1; i < n; i++) {
    if (a[i - 1] > a[i]) {
      l = a[i - 1];
      while (i < n && a[i - 1] > a[i]) i++;
      temp += l - a[i - 1];
    }
  }
  cout << temp;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}

### Prompt

Generate a cpp solution to the following problem:

The Little Elephant loves sortings.

He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of integers l and r (1 ≤ l ≤ r ≤ n) and increase ai by 1 for all i such that l ≤ i ≤ r.

Help the Little Elephant find the minimum number of moves he needs to convert array a to an arbitrary array sorted in the non-decreasing order. Array a, consisting of n elements, is sorted in the non-decreasing order if for any i (1 ≤ i < n) ai ≤ ai + 1 holds.

Input

The first line contains a single integer n (1 ≤ n ≤ 105) — the size of array a. The next line contains n integers, separated by single spaces — array a (1 ≤ ai ≤ 109). The array elements are listed in the line in the order of their index's increasing.

Output

In a single line print a single integer — the answer to the problem.

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

Examples

Input

3
1 2 3


Output

0


Input

3
3 2 1


Output

2


Input

4
7 4 1 47


Output

6

Note

In the first sample the array is already sorted in the non-decreasing order, so the answer is 0.

In the second sample you need to perform two operations: first increase numbers from second to third (after that the array will be: [3, 3, 2]), and second increase only the last element (the array will be: [3, 3, 3]).

In the third sample you should make at least 6 steps. The possible sequence of the operations is: (2; 3), (2; 3), (2; 3), (3; 3), (3; 3), (3; 3). After that the array converts to [7, 7, 7, 47].

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
int f(long long int n) {
  if (n > 1) {
    long long int f = 1;
    for (long long int i = 2; i <= n; i++) f = f * i;
    return f;
  } else
    return 1;
}
bool isprime(long long int n) {
  if (n == 1)
    return false;
  else {
    for (long long int i = 2; i <= sqrt(n); i++)
      if (n % i == 0) return false;
    return true;
  }
}
vector<pair<long long int, long long int> > primefac(long long int n) {
  vector<pair<long long int, long long int> > a;
  long long int temp, test = 1, count;
  for (long long int i = 2; i <= sqrt(n); i++) {
    if (n % i == 0 && isprime(i)) {
      temp = n;
      count = 0;
      while (temp % i == 0) {
        count++;
        temp = temp / i;
      }
      a.push_back({i, count});
      test = pow(i, count) * test;
    }
  }
  if (test != n) a.push_back({n / test, 1});
  return a;
}
vector<long long int> fac(long long int n) {
  vector<long long int> a;
  for (long long int i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (i != n / i) {
        a.push_back(i);
        a.push_back(n / i);
      } else
        a.push_back(i);
    }
  }
  return a;
}
bool sortbysec(const pair<long long int, long long int> &a,
               const pair<long long int, long long int> &b) {
  if (a.second != b.second)
    return (a.second > b.second);
  else
    return (a.first > b.first);
}
long long int gcd(long long int a, long long int b) {
  if (a == 0)
    return b;
  else if (b == 0)
    return a;
  else
    return gcd(b % a, a);
}
long long int ncr(long long int n, long long int r) {
  return (f(n) / (f(r) * f(n - r)));
}
vector<int> primev;
void SieveOfEratosthenes(int n) {
  bool prime[n + 1];
  memset(prime, true, sizeof(prime));
  for (int p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (int i = p * p; i <= n; i += p) prime[i] = false;
    }
  }
  for (int p = 2; p <= n; p++)
    if (prime[p]) primev.push_back(p);
}
long long int sum(long long int n) {
  long long int s = 0;
  while (n) {
    s += n % 10;
    n = n / 10;
  }
  return s;
}
long long int mx = 1e9 + 7;
bool func(long long int n) {
  long long int ans = 0;
  while (n) {
    if (n % 10 != 9) return false;
    n /= 10;
  }
  return true;
}
void solve() {
  long long int n, k = 0, c = 0, temp = 0, l = -1, r = -1, m = 1, s1 = 0,
                   s2 = 0;
  cin >> n;
  long long int a[n];
  for (long long int i = 0; i < n; i++) cin >> a[i];
  vector<long long int> v;
  for (long long int i = 1; i < n; i++) {
    if (a[i - 1] > a[i]) {
      l = a[i - 1];
      while (i < n && a[i - 1] > a[i]) i++;
      temp += l - a[i - 1];
    }
  }
  cout << temp;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}

```